import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.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/app_state.dart';
import 'package:hmg_patient_app_new/core/dependencies.dart';
import 'package:hmg_patient_app_new/core/enums.dart';
import 'package:hmg_patient_app_new/core/utils/utils.dart';
import 'package:hmg_patient_app_new/extensions/route_extensions.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/generated/locale_keys.g.dart';
import 'package:hmg_patient_app_new/theme/colors.dart';
import 'package:hmg_patient_app_new/widgets/appbar/collapsing_list_view.dart';

class HealthTrackersPage extends StatefulWidget {
  const HealthTrackersPage({super.key});

  @override
  State<HealthTrackersPage> createState() => _HealthTrackersPageState();
}

Widget buildHealthTrackerCard({
  required String icon,
  required String title,
  required String description,
  required Color iconBgColor,
  required VoidCallback onTap,
}) {
  return Container(
    decoration: RoundedRectangleBorder().toSmoothCornerDecoration(color: AppColors.whiteColor, borderRadius: 20.r),
    child: Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Container(
          decoration: RoundedRectangleBorder().toSmoothCornerDecoration(color: iconBgColor, borderRadius: 10.r),
          height: 40.w,
          width: 40.w,
          child: Utils.buildSvgWithAssets(
            icon: icon,
            fit: BoxFit.none,
            height: 22.w,
            width: 22.w,
          ),
        ),
        SizedBox(width: 12.w),
        Flexible(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              title.toText16(isBold: true),
              description.toText12(
                isBold: true,
                color: Color(0xFF8F9AA3),
              ),
            ],
          ),
        ),
        SizedBox(width: 12.w),
        Transform.flip(
          flipX: getIt.get<AppState>().isArabic(),
          child: Utils.buildSvgWithAssets(
            icon: AppAssets.arrowRight,
            width: 24.w,
            height: 24.h,
            fit: BoxFit.contain,
            iconColor: AppColors.textColor,
          ),
        ),
      ],
    ).paddingAll(16.w),
  ).onPress(onTap);
}

class _HealthTrackersPageState extends State<HealthTrackersPage> {
  @override
  Widget build(BuildContext context) {
    return CollapsingListView(
      title: LocaleKeys.healthTrackers.tr(context: context),
      child: Column(
        children: [
          buildHealthTrackerCard(
            iconBgColor: AppColors.primaryRedColor,
            icon: AppAssets.bloodSugarOnlyIcon,
            title: LocaleKeys.bloodSugar.tr(context: context),
            description: LocaleKeys.trackYourGlucoseLevels.tr(context: context),
            onTap: () {
              context.navigateWithName(
                AppRoutes.healthTrackerDetailPage,
                arguments: HealthTrackerTypeEnum.bloodSugar,
              );
            },
          ),
          SizedBox(height: 16.h),
          buildHealthTrackerCard(
            iconBgColor: AppColors.infoColor,
            icon: AppAssets.bloodPressureIcon,
            title: LocaleKeys.bloodPressure.tr(context: context),
            description: LocaleKeys.monitorBloodPressureLevels.tr(context: context),
            onTap: () {
              context.navigateWithName(
                AppRoutes.healthTrackerDetailPage,
                arguments: HealthTrackerTypeEnum.bloodPressure,
              );
            },
          ),
          SizedBox(height: 16.h),
          buildHealthTrackerCard(
            iconBgColor: AppColors.successColor,
            icon: AppAssets.weightIcon,
            title: LocaleKeys.weight.tr(context: context),
            description: LocaleKeys.trackWeightProgress.tr(context: context),
            onTap: () {
              context.navigateWithName(
                AppRoutes.healthTrackerDetailPage,
                arguments: HealthTrackerTypeEnum.weightTracker,
              );
            },
          ),
        ],
      ).paddingSymmetrical(20.w, 24.h),
    );
  }
}
