import 'package:flutter/material.dart';
import 'package:flutter_swiper_view/flutter_swiper_view.dart';
import 'package:hmg_patient_app_new/core/app_assets.dart';
import 'package:hmg_patient_app_new/core/app_export.dart';
import 'package:hmg_patient_app_new/core/utils/utils.dart';
import 'package:hmg_patient_app_new/extensions/string_extensions.dart';
import 'package:hmg_patient_app_new/extensions/widget_extensions.dart';
import 'package:hmg_patient_app_new/features/profile_settings/profile_settings_view_model.dart';
import 'package:hmg_patient_app_new/presentation/lab/collapsing_list_view.dart';
import 'package:hmg_patient_app_new/theme/colors.dart';
import 'package:hmg_patient_app_new/widgets/buttons/custom_button.dart';
import 'package:hmg_patient_app_new/widgets/chip/app_custom_chip_widget.dart';
import 'package:provider/provider.dart';

class ProfileSettings extends StatefulWidget {
  ProfileSettings({Key? key}) : super(key: key);

  @override
  _ProfileSettingsState createState() {
    return _ProfileSettingsState();
  }
}

class _ProfileSettingsState extends State<ProfileSettings> {
  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  int length = 3;
  final SwiperController _controller = SwiperController();

  int _index = 0;

  @override
  Widget build(BuildContext context) {
    return CollapsingListView(
      title: "Profile & Settings".needTranslation,
      logout: () {},
      isClose: true,
      child: SingleChildScrollView(
        padding: EdgeInsets.only(top: 24, bottom: 24),
        physics: NeverScrollableScrollPhysics(),
        child: Consumer<ProfileSettingsViewModel>(
          builder: (context, model, child) {
            return Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Swiper(
                  itemCount: length,
                  layout: SwiperLayout.STACK,
                  loop: true,
                  itemWidth: MediaQuery.of(context).size.width - 42,
                  indicatorLayout: PageIndicatorLayout.COLOR,
                  axisDirection: AxisDirection.right,
                  controller: _controller,
                  itemHeight: 210 + 16,
                  pagination: const SwiperPagination(
                    alignment: Alignment.bottomCenter,
                    margin: EdgeInsets.only(top: 210 + 8 + 24),
                    builder: DotSwiperPaginationBuilder(color: Color(0xffD9D9D9), activeColor: AppColors.blackBgColor),
                  ),
                  itemBuilder: (BuildContext context, int index) {
                    return FamilyCardWidget().paddingOnly(right: 16);
                  },
                ),
                GridView(
                  gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2, childAspectRatio: 105 / 105, crossAxisSpacing: 9, mainAxisSpacing: 9),
                  physics: const NeverScrollableScrollPhysics(),
                  padding: const EdgeInsets.all(24),
                  shrinkWrap: true,
                  children: [
                    Container(
                      padding: EdgeInsets.all(16),
                      decoration: RoundedRectangleBorder().toSmoothCornerDecoration(
                        color: AppColors.whiteColor,
                        borderRadius: 20.h,
                        hasShadow: true,
                      ),
                      child: Column(
                        children: [
                          Row(
                            children: [
                              Utils.buildSvgWithAssets(icon: AppAssets.wallet, width: 40.h, height: 40.h),
                            ],
                          )
                        ],
                      ),
                    )
                  ],
                )
              ],
            );
          },
        ),
      ),
    );
  }
}

class FamilyCardWidget extends StatelessWidget {
  FamilyCardWidget();

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: RoundedRectangleBorder().toSmoothCornerDecoration(
        color: AppColors.whiteColor,
        borderRadius: 20.h,
        hasShadow: true,
      ),
      child: Column(
        children: [
          Column(
            spacing: 8.h,
            children: [
              Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                spacing: 8.h,
                children: [
                  Image.asset(true ? AppAssets.male_img : AppAssets.femaleImg, width: 56.h, height: 56.h),
                  Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    spacing: 0.h,
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      "Mahmoud Shrouf Shrouf".toText18(isBold: true, weight: FontWeight.w600, textOverflow: TextOverflow.ellipsis, maxlines: 1),
                      AppCustomChipWidget(
                        icon: AppAssets.file_icon,
                        labelText: "File no: 3423443",
                        iconSize: 14,
                      ),
                    ],
                  ).expanded,
                  Icon(Icons.qr_code, size: 56)
                ],
              ).expanded,
              SizedBox(
                width: double.infinity,
                child: Wrap(
                  alignment: WrapAlignment.start,
                  spacing: 8.h,
                  children: [
                    AppCustomChipWidget(labelText: "35 Years Old"),
                    AppCustomChipWidget(labelText: "Blood: A+"),
                    AppCustomChipWidget(
                      icon: AppAssets.insurance_active_icon,
                      labelText: "Insurance Active",
                      iconColor: AppColors.bgGreenColor,
                      iconSize: 14,
                      backgroundColor: AppColors.bgGreenColor.withValues(alpha: 0.15),
                    ),
                  ],
                ),
              ),
            ],
          ).paddingOnly(top: 16, right: 16, left: 16, bottom: 12).expanded,
          Divider(
            height: 1,
            thickness: 1,
            color: Color(0x30D2D2D2),
          ),
          CustomButton(icon: AppAssets.add_family, text: "Add a new family member", onPressed: () {}).paddingOnly(top: 12, right: 16, left: 16, bottom: 16),
        ],
      ),
    );
  }
}
