import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:gap/gap.dart';
import 'package:tanami_app/core/styles/app_text.dart';
import 'package:tanami_app/shared/components/text_widget.dart';

import '../../../../../Globalconst.dart';
import '../../../../../core/utils/language/localizations_delegate.dart';

class UserAccountSection extends StatelessWidget {
  const UserAccountSection({super.key});

  @override
  Widget build(BuildContext context) {
    String getInitials(String name) {
      List<String> words = name.split(' ');
      String initials = '';
      for (var word in words) {
        if (word.isNotEmpty) {
          initials += word[0].toUpperCase();
        }
      }
      return initials;
    }

    var localizations = AppLocalizations.of(context);
    return Padding(
      padding: const EdgeInsets.symmetric(
        horizontal: 16,
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            width: 1.sw,
            padding: const EdgeInsets.only(
              left: 12,
              top: 12,
              bottom: 12,
              right: 12,
            ),
            decoration: ShapeDecoration(
              color: const Color(0xFFF6F6F6),
              shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(22),
              ),
            ),
            child: Row(
              mainAxisSize: MainAxisSize.min,
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Expanded(
                  child: SizedBox(
                    height: 61,
                    child: Row(
                      mainAxisSize: MainAxisSize.min,
                      mainAxisAlignment: MainAxisAlignment.start,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        Container(
                          width: 41,
                          height: 41,
                          padding: const EdgeInsets.all(8),
                          decoration: ShapeDecoration(
                            color: const Color(0xFFDAEEE0),
                            shape: RoundedRectangleBorder(
                              side: const BorderSide(
                                  width: 1, color: Color(0xFF709C81)),
                              borderRadius: BorderRadius.circular(22),
                            ),
                          ),
                          child: Row(
                            mainAxisSize: MainAxisSize.min,
                            mainAxisAlignment: MainAxisAlignment.center,
                            crossAxisAlignment: CrossAxisAlignment.center,
                            children: [
                              TextWidget().text15W500(
                                getInitials(
                                    "${Globalconst.firstName} ${Globalconst.lastName}"),
                                clr: const Color(0xFF066123),
                              )
                            ],
                          ),
                        ),
                        const Gap(12),
                        Column(
                          mainAxisSize: MainAxisSize.min,
                          mainAxisAlignment: MainAxisAlignment.start,
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            TextWidget().text14W500(
                              Globalconst.firstName.isEmpty
                                  ? "User"
                                  : "${Globalconst.firstName} ${Globalconst.lastName}",
                              clr: const Color(0xFF191B1E),
                            ),
                            const Gap(4),
                            TextWidget().text11W500(
                              localizations
                                  .translate(AppText.yourAccountDetails),
                              clr: const Color(0xFF8D8D8D),
                            ),
                          ],
                        ),
                        const Spacer(),
                        const Icon(
                          Icons.arrow_forward_ios_outlined,
                          color: Color(0xFF363636),
                        )
                      ],
                    ),
                  ),
                ),
              ],
            ),
          )
        ],
      ),
    );
  }
}
