import 'package:flutter/material.dart';
import 'package:rasadyar_core/core.dart';

import 'logic.dart';

class ProfilePage extends GetView<ProfileLogic> {
  const ProfilePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Column(
      spacing: 30,
      children: [
        SizedBox(
          height: Get.height * 0.3,
          child: Stack(
            fit: StackFit.expand,
            alignment: Alignment.center,
            clipBehavior: Clip.none,
            children: [
              Assets.vec.bgHeaderUserProfileSvg.svg(),
              Positioned(
                bottom: -20,
                left: 0,
                right: 0,
                child: SizedBox(
                  width: 110,
                  height: 110,
                  child: CircleAvatar(
                    backgroundColor: AppColor.blueLightHover,
                    child: FaIcon(
                      FontAwesomeIcons.user,
                      size: 45,
                      color: Colors.white,
                    ),
                  ),
                ),
              ),
            ],
          ),
        ),
        Expanded(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            spacing: 16,
            children: [
              SizedBox(
                height: 75,
                child: ListView.separated(
                  shrinkWrap: true,
                  padding: EdgeInsets.all(16),
                  scrollDirection: Axis.horizontal,
                  itemBuilder:
                      (context, index) => ObxValue((data) {
                        return ChoiceChip(
                          onSelected: (value) {
                            data.value = index;
                          },
                          selectedColor: AppColor.blueNormal,
                          labelStyle:
                              data.value == index
                                  ? AppFonts.yekan13.copyWith(
                                    color: AppColor.whiteLight,
                                  )
                                  : AppFonts.yekan12.copyWith(
                                    color: AppColor.darkGreyNormalActive,
                                  ),
                          checkmarkColor: Colors.white,
                          label: Text(controller.roles[index]),
                          selected: index == data.value,
                        );
                      }, controller.selectedRole),

                  separatorBuilder: (context, index) => SizedBox(width: 8),
                  itemCount: controller.roles.length,
                ),
              ),
              Expanded(
                child: Padding(
                  padding: const EdgeInsets.symmetric(
                    horizontal: 30,
                    vertical: 10,
                  ),
                  child: ObxValue((data) {
                    return switch (data.value) {
                      0 => userProfileInformation(),
                      1 => bankInformationWidget(),
                      2 => invoiceIssuanceInformation(),
                      int() => Placeholder(),
                    };
                  }, controller.selectedInformationType),
                ),
              ),

              ObxValue((data) {
                return Padding(
                  padding: const EdgeInsets.symmetric(horizontal: 20),
                  child: Wrap(
                    spacing: 20,
                    runSpacing: 10,
                    children: [
                      cardActionWidget(
                        title: 'اطلاعات کاربری',
                        onPressed: () {
                          data.value = 0;
                        },
                        icon: Assets.vec.profileUserSvg.path,
                        selected: data.value == 0,
                      ),
                      cardActionWidget(
                        title: 'اطلاعات بانکی',
                        onPressed: () {
                          data.value = 1;
                        },
                        icon: Assets.vec.informationSvg.path,
                        selected: data.value == 1,
                      ),
                      cardActionWidget(
                        title: 'اطلاعات \nصدور فاکتور',
                        onPressed: () {
                          data.value = 2;
                        },
                        icon: Assets.vec.receiptDiscountSvg.path,
                        selected: data.value == 2,
                      ),
                    ],
                  ),
                );
              }, controller.selectedInformationType),

              SizedBox(height: 100),
            ],
          ),
        ),
      ],
    );
  }

  Container invoiceIssuanceInformation() => Container();

  Widget bankInformationWidget() => Column(
    spacing: 16,
    children: [
      itemList(title: 'نام بانک', content: 'سامان'),
      itemList(title: 'نام صاحب حساب', content: 'رضا رضایی'),
      itemList(title: 'شماره کارت ', content: '54154545415'),
      itemList(title: 'شماره حساب', content: '62565263263652'),
      itemList(title: 'شماره شبا', content: '62565263263652'),
    ],
  );

  Column userProfileInformation() {
    return Column(
      spacing: 10,
      children: [
        itemList(
          title: 'نام و نام خانوادگی',
          content: 'آیدا گل محمدی',
          icon: Assets.vec.userSvg.path,
        ),
        itemList(
          title: 'موبایل',
          content: '09302654896',
          icon: Assets.vec.callSvg.path,
        ),
        itemList(
          title: 'کدملی',
          content: 'نا مشخص',
          icon: Assets.vec.tagUserSvg.path,
        ),
        itemList(
          title: 'شماره شناسنامه',
          content: 'نا مشخص',
          icon: Assets.vec.userSquareSvg.path,
        ),
        itemList(
          title: 'تاریخ تولد',
          content: '1404/10/12',
          icon: Assets.vec.calendarSvg.path,
        ),
        itemList(
          title: 'استان',
          content: 'لرستان',
          icon: Assets.vec.pictureFrameSvg.path,
        ),
        itemList(
          title: 'شهر',
          content: 'خرم آباد',
          icon: Assets.vec.mapSvg.path,
        ),
      ],
    );
  }

  Widget itemList({
    required String title,
    required String content,
    String? icon,
  }) => Row(
    spacing: 4,
    children: [
      if (icon != null)
        Padding(
          padding: const EdgeInsets.only(left: 8.0),
          child: SvgGenImage.vec(icon).svg(
            width: 20,
            height: 20,
            colorFilter: ColorFilter.mode(AppColor.blueNormal, BlendMode.srcIn),
          ),
        ),
      Text(title, style: AppFonts.yekan12.copyWith(color: AppColor.blueNormal)),
      Spacer(),
      Text(
        content,
        style: AppFonts.yekan13.copyWith(color: AppColor.darkGreyNormalHover),
      ),
    ],
  );

  Widget cardActionWidget({
    required String title,
    required VoidCallback onPressed,
    required String icon,
    bool selected = false,
  }) {
    return GestureDetector(
      onTap: onPressed,
      child: Column(
        spacing: 4,
        children: [
          Container(
            width: 52,
            height: 52,
            padding: EdgeInsets.all(8),
            decoration: ShapeDecoration(
              color: selected ? AppColor.blueLightActive : AppColor.blueLight,
              shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(8),
              ),
            ),
            child: SvgGenImage.vec(icon).svg(
              width: 40,
              height: 40,
              colorFilter: ColorFilter.mode(
                selected ? AppColor.whiteLight : AppColor.blueNormal,
                BlendMode.srcIn,
              ),
            ),
          ),
          SizedBox(height: 2),
          Text(
            title,
            style: AppFonts.yekan10.copyWith(
              color: selected ? AppColor.blueNormal : AppColor.blueLightActive,
            ),
            textAlign: TextAlign.center,
          ),
        ],
      ),
    );
  }
}
