import 'package:flutter/material.dart';

class AppColors {
  /// Global dark-mode flag — toggled by ProfileSettingsViewModel.
  /// When true, every getter below returns the dark palette value.
  static bool isDarkMode = false;

  static const transparent = Colors.transparent;

  // ── Scaffold / Background ─────────────────────────────────────────────────
  static Color get scaffoldBgColor => isDarkMode ? dark.scaffoldBgColor : const Color(0xFFF8F8F8);
  static Color get bottomSheetBgColor => isDarkMode ? dark.bottomSheetBgColor : const Color(0xFFF8F8FA);
  static Color get lightGreyEFColor => isDarkMode ? dark.lightGreyEFColor : const Color(0xffeaeaff);
  static Color get greyF7Color => isDarkMode ? dark.greyF7Color : const Color(0xffF7F7F7);
  static Color get greyInfoTextColor => isDarkMode ? dark.greyInfoTextColor : const Color(0xff777777);
  static Color get lightGrayColor => isDarkMode ? dark.lightGrayColor : const Color(0xff808080);
  static Color get greyTextColorLight => isDarkMode ? dark.greyTextColorLight : const Color(0xFFA2A2A2);
  static Color get mainPurple => isDarkMode ? dark.mainPurple : const Color(0xFF7954F7);

  // ── Core Colors ───────────────────────────────────────────────────────────
  static Color get whiteColor => isDarkMode ? dark.whiteColor : const Color(0xFFffffff);
  // static const Color primaryRedColor = Color(0xFFED1C2B);
  static Color get primaryRedColor => isDarkMode ? dark.primaryRedColor : Color(0xFFED1C2B);
  static Color get secondaryLightRedColor => isDarkMode ? dark.secondaryLightRedColor : const Color(0xFFFEE9EA);
  static const Color successColor = Color(0xFF18C273);
  static Color get successLightBgColor => isDarkMode ? dark.successLightBgColor : const Color(0xffDDF6EA);
  static Color get greyColor => isDarkMode ? dark.greyColor : const Color(0xFFEFEFF0);
  static Color get chipBgColor => isDarkMode ? dark.chipBgColor : const Color(0xFFEFEFF0);
  static Color get textColor => isDarkMode ? dark.textColor : const Color(0xFF2E3039);
  static Color get iconColor => isDarkMode ? dark.iconColor : const Color(0xFF2E3039);
  static Color get borderGrayColor => isDarkMode ? dark.borderGrayColor : const Color(0x332E3039);
  static Color get textColorLight => isDarkMode ? dark.textColorLight : const Color(0xFF5E5E5E);
  static Color get dividerColor => isDarkMode ? dark.dividerColor : const Color(0x40D2D2D2);
  static Color get warningColorYellow => isDarkMode ? dark.warningColorYellow : const Color(0xFFF4A308);
  static Color get inputLabelTextColor => isDarkMode ? dark.inputLabelTextColor : const Color(0xff898A8D);
  static Color get greyTextColor => isDarkMode ? dark.greyTextColor : const Color(0xFF8F9AA3);
  static Color get lightGrayBGColor => isDarkMode ? dark.lightGrayBGColor : const Color(0x142E3039);
  static Color get checkBoxBorderColor => isDarkMode ? dark.checkBoxBorderColor : const Color(0xffD2D2D2);
  static Color get pharmacyBGColor => isDarkMode ? dark.pharmacyBGColor : const Color(0xFF359846);
  static Color get lightGreenColor => isDarkMode ? dark.lightGreenColor : const Color(0xFF0ccedde);
  static Color get ratingColorYellow => isDarkMode ? dark.ratingColorYellow : const Color(0xFFFFAF15);
  static Color get spacerLineColor => isDarkMode ? dark.spacerLineColor : const Color(0x2E30391A);
  static Color get habibPharmacyColor => const Color(0xFF2d9137);

  // ── Doctor Rating Colors ──────────────────────────────────────────────────
  static const Color ratingStarIconColor = Color(0xFFFFA726); // Orange-amber for star icons
  static const Color ratingFiveStarColor = Color(0xFF18C273); // Green for 5 stars
  static const Color ratingFourStarColor = Color(0xFF8BC34A); // Light green for 4 stars
  static const Color ratingThreeStarColor = Color(0xFFC0A000); // Dark yellow/olive for 3 stars
  static const Color ratingTwoStarColor = Color(0xFFD84315); // Dark orange-red for 2 stars
  static const Color ratingOneStarColor = Color(0xFFD32F2F); // Red for 1 star
  static const Color ratingBadgeFiveStarColor = Color(0xFF5BBD8E); // Green badge for ≥4.0
  static const Color ratingPercentageTextColor = Color(0xFF4A4A4A); // Dark grey for percentage text


  // ── Semantic / Status Colors ──────────────────────────────────────────────
  static Color get errorColor => isDarkMode ? dark.errorColor : const Color(0xFFED1C2B);
  static Color get alertColor => isDarkMode ? dark.alertColor : const Color(0xFFD48D05);
  static Color get infoColor => isDarkMode ? dark.infoColor : const Color(0xFF0B85F7);
  static Color get warningColor => isDarkMode ? dark.warningColor : const Color(0xFFFFCC00);
  static Color get switchBackgroundColor => isDarkMode ? dark.switchBackgroundColor : const Color(0x2618C273);
  static Color get bottomNAVBorder => isDarkMode ? dark.bottomNAVBorder : const Color(0xFFEEEEEE);
  static Color get quickLoginColor => isDarkMode ? dark.quickLoginColor : const Color(0xFF666666);
  static Color get tooltipTextColor => isDarkMode ? dark.tooltipTextColor : const Color(0xFF414D55);
  static Color get graphGridColor => isDarkMode ? dark.graphGridColor : const Color(0x4D18C273);
  static Color get highAndLow => isDarkMode ? dark.highAndLow : const Color(0xFFFFAF15);
  static Color get labelTextColor => isDarkMode ? dark.labelTextColor : const Color(0xFF838383);
  static Color get calenderTextColor => isDarkMode ? dark.calenderTextColor : const Color(0xFFD0D0D0);
  static Color get lightGreenButtonColor => isDarkMode ? dark.lightGreenButtonColor : const Color(0x2618C273);
  static Color get lightRedButtonColor => isDarkMode ? dark.lightRedButtonColor : const Color(0x1AED1C2B);

  // ── Status Colors ─────────────────────────────────────────────────────────
  static Color get statusPendingColor => isDarkMode ? dark.statusPendingColor : const Color(0xffCC9B14);
  static Color get statusProcessingColor => isDarkMode ? dark.statusProcessingColor : const Color(0xff2E303A);
  static Color get statusCompletedColor => isDarkMode ? dark.statusCompletedColor : const Color(0xff359846);
  static Color get statusRejectedColor => isDarkMode ? dark.statusRejectedColor : const Color(0xffD02127);

  // ── Info Banner Colors ────────────────────────────────────────────────────
  static Color get infoBannerBgColor => isDarkMode ? dark.infoBannerBgColor : const Color(0xFFFFF4E6);
  static Color get infoBannerBorderColor => isDarkMode ? dark.infoBannerBorderColor : const Color(0xFFFFE5B4);
  static Color get infoBannerIconColor => isDarkMode ? dark.infoBannerIconColor : const Color(0xFFCC9B14);
  static Color get infoBannerTextColor => isDarkMode ? dark.infoBannerTextColor : const Color(0xFF856404);

  // ── Symptoms Checker ─────────────────────────────────────────────��────────
  static Color get chipColorSeekMedicalAdvice => isDarkMode ? dark.chipColorSeekMedicalAdvice : const Color(0xFFFFAF15);
  static Color get chipTextColorSeekMedicalAdvice => isDarkMode ? dark.chipTextColorSeekMedicalAdvice : const Color(0xFFD48D05);

  // ── Services Page Colors ──────────────────────────────────────────────────
  static Color get eReferralCardColor => isDarkMode ? dark.eReferralCardColor : const Color(0xFFFF8012);
  static Color get bloodDonationCardColor => isDarkMode ? dark.bloodDonationCardColor : const Color(0xFFFF5662);
  static Color get myChildVaccineCardColor => isDarkMode ? dark.myChildVaccineCardColor : const Color(0xFFFF2D78);
  static Color get bookAppointment => isDarkMode ? dark.bookAppointment : const Color(0xFF415364);

  // ── Health Calculators Colors ─────────────────────────────────────────────
  static Color get bmiCalculatorColor => isDarkMode ? dark.bmiCalculatorColor : const Color(0xFFF43333);
  static Color get caloriesCalculatorColor => isDarkMode ? dark.caloriesCalculatorColor : const Color(0xFF0B85F7);
  static Color get bmrCalculatorColor => isDarkMode ? dark.bmrCalculatorColor : const Color(0xFF18C273);
  static Color get idealBodyWeightColor => isDarkMode ? dark.idealBodyWeightColor : const Color(0xFFFF8012);
  static Color get bodyFatCalculatorColor => isDarkMode ? dark.bodyFatCalculatorColor : const Color(0xFFFF5662);
  static Color get carbsProteinFatColor => isDarkMode ? dark.carbsProteinFatColor : const Color(0xFF18C273);
  static Color get ovulationPeriodColor => isDarkMode ? dark.ovulationPeriodColor : const Color(0xFFFF47A9);
  static Color get deliveryDueDateColor => isDarkMode ? dark.deliveryDueDateColor : const Color(0xFFFF2D78);

  // ── Water Monitor ─────────────────────────────────────────────────────────
  static Color get blueColor => isDarkMode ? dark.blueColor : const Color(0xFF4EB5FF);
  static Color get blueGradientColorOne => isDarkMode ? dark.blueGradientColorOne : const Color(0xFFF1F7FD);
  static Color get blueGradientColorTwo => isDarkMode ? dark.blueGradientColorTwo : const Color(0xFFD9EFFF);

  // ── Shimmer ───────────────────────────────────────────────────────────────
  static Color get shimmerBaseColor => isDarkMode ? dark.shimmerBaseColor : const Color(0xFFE0E0E0);
  static Color get shimmerHighlightColor => isDarkMode ? dark.shimmerHighlightColor : const Color(0xFFF5F5F5);
  static Color get covid29Color => isDarkMode ? dark.covid29Color : const Color(0xff2563EB);
  static Color get lightGreyTextColor => isDarkMode ? dark.lightGreyTextColor : const Color(0xFF959595);
  static Color get labelColorYellow => isDarkMode ? dark.labelColorYellow : const Color(0xFFFBCB6E);

  static const LinearGradient aiLinearGradient =
  LinearGradient(colors: [Color(0xFF8A38F5), Color(0xFFE20BBB)], begin: Alignment.topLeft, end: Alignment.bottomRight);

  // ── Aliases ───────────────────────────────────────────────────────────────
  static Color get bgScaffoldColor => scaffoldBgColor;
  static Color get primaryRedBorderColor => primaryRedColor;
  static Color get chipPrimaryRedBorderColor => primaryRedColor;
  static Color get criticalLowAndHigh => primaryRedColor;
  static Color get chipColorEmergency => primaryRedColor;
  static Color get errorLightColor => primaryRedColor;
  static Color get secondaryLightRedBorderColor => secondaryLightRedColor;
  static Color get bgRedLightColor => secondaryLightRedColor;
  static Color get chipSecondaryLightRedColor => secondaryLightRedColor;
  static Color get blackBgColor => textColor;
  static Color get blackColor => textColor;
  static Color get borderOnlyColor => textColor;
  static Color get chipBorderColorOpacity20 => borderGrayColor;
  static Color get bgGreenColor => successColor;
  static Color get textGreenColor => successColor;
  static Color get successLightColor => successColor;
  static Color get thumbColor => successColor;
  static Color get chipColorMonitor => successColor;
  static Color get greyLightColor => greyColor;
  static Color get alertLightColor => alertColor;
  static Color get infoLightColor => infoColor;
  static Color get warningLightColor => warningColor;

  // ── Dark Mode Palette ─────────────────────────────────────────────────────
  static const AppColorsDark dark = AppColorsDark();
}

// ---------------------------------------------------------------------------
// Dark palette — mirrors every color in AppColors with a dark-friendly value.
// ---------------------------------------------------------------------------
class AppColorsDark {
  const AppColorsDark();

  // Scaffold / Background
  Color get scaffoldBgColor => const Color(0xFF191919);
  Color get bottomSheetBgColor => const Color(0xFF1C1C1E);
  Color get lightGreyEFColor => const Color(0xFF2A2A3A);
  Color get greyF7Color => const Color(0xFF1E1E1E);
  Color get greyInfoTextColor => const Color(0xFF9E9E9E);
  Color get lightGrayColor => const Color(0xFF9E9E9E);
  Color get greyTextColorLight => const Color(0xFF757575);

  // ⚠️ NEW — was missing from AppColorsDark
  Color get mainPurple => const Color(0xFF9B7AFF); // brighter purple for dark surfaces

  // Core
  Color get baseColor => const Color(0xFF1E1E1E);
  // ⚠️ NEW — maps whiteColor → dark surface color
  Color get whiteColor => const Color(0xFF1E1E1E); // surface replacement for white
  Color get primaryRedColor => const Color(0xFFDE5C5D);
  Color get secondaryLightRedColor => const Color(0xFF3A1015);
  Color get successColor => const Color(0xFF18C273);
  Color get successLightBgColor => const Color(0xFF0D2E1F);
  Color get textColor => const Color(0xFFFFFFFF);
  Color get iconColor => const Color(0xFFFFFFFF);
  Color get borderGrayColor => const Color(0x55ECECEC);
  Color get textColorLight => const Color(0xFFB0B0B0);
  Color get dividerColor => const Color(0x33FFFFFF);
  Color get warningColorYellow => const Color(0xFFF4A308);
  Color get inputLabelTextColor => const Color(0xFF9E9E9E);
  Color get greyTextColor => const Color(0xFF8F9AA3);
  Color get lightGrayBGColor => const Color(0x22FFFFFF);
  Color get checkBoxBorderColor => const Color(0xFF555555);
  Color get pharmacyBGColor => const Color(0xFF359846);
  // ⚠️ NEW — was missing from AppColorsDark
  Color get lightGreenColor => const Color(0xFF0ccedde); // same teal accent — works on dark
  Color get ratingColorYellow => const Color(0xFFFFAF15);
  Color get spacerLineColor => const Color(0x22FFFFFF);

  // Semantic / Status
  Color get errorColor => const Color(0xFFD63D48);
  Color get alertColor => const Color(0xFFD48D05);
  Color get infoColor => const Color(0xFF4DA6FF);
  Color get warningColor => const Color(0xFFFFCC00);
  Color get greyColor => const Color(0xFF2C2C2E);
  Color get chipBgColor => const Color(0xFF3E3E3E);
  Color get cardDarkBorderColor => const Color(0x0DEAEAEA);
  Color get serviceCardButtonColor => const Color(0xFF3E3E3E);
  Color get switchBackgroundColor => const Color(0x2618C273);
  Color get bottomNAVBorder => const Color(0xFF2C2C2E);
  Color get quickLoginColor => const Color(0xFF9E9E9E);
  Color get tooltipTextColor => const Color(0xFFCFD8DC);
  Color get graphGridColor => const Color(0x4D18C273);
  Color get highAndLow => const Color(0xFFFFAF15);
  Color get labelTextColor => const Color(0xFF9E9E9E);
  Color get calenderTextColor => const Color(0xFF555555);
  Color get lightGreenButtonColor => const Color(0x2618C273);
  Color get lightRedButtonColor => const Color(0x1AED1C2B);

  // Status
  Color get statusPendingColor => const Color(0xFFCC9B14);
  Color get statusProcessingColor => const Color(0xFFECECEC);
  Color get statusCompletedColor => const Color(0xFF359846);
  Color get statusRejectedColor => const Color(0xFFD02127);

  // Info Banner
  Color get infoBannerBgColor => const Color(0xFF2A1F0A);
  Color get infoBannerBorderColor => const Color(0xFF5A3D0A);
  Color get infoBannerIconColor => const Color(0xFFCC9B14);
  Color get infoBannerTextColor => const Color(0xFFFFCB6B);

  // Symptoms Checker
  Color get chipColorSeekMedicalAdvice => const Color(0xFFFFAF15);
  Color get chipTextColorSeekMedicalAdvice => const Color(0xFFD48D05);

  // Services Page
  Color get eReferralCardColor => const Color(0xFFFF8012);
  Color get bloodDonationCardColor => const Color(0xFFFF5662);
  Color get myChildVaccineCardColor => const Color(0xFFFF2D78);
  Color get bookAppointment => const Color(0xFF415364);

  // Health Calculators
  Color get bmiCalculatorColor => const Color(0xFFF43333);
  Color get caloriesCalculatorColor => const Color(0xFF0B85F7);
  Color get bmrCalculatorColor => const Color(0xFF18C273);
  Color get idealBodyWeightColor => const Color(0xFFFF8012);
  Color get bodyFatCalculatorColor => const Color(0xFFFF5662);
  Color get carbsProteinFatColor => const Color(0xFF18C273);
  Color get ovulationPeriodColor => const Color(0xFFFF47A9);
  Color get deliveryDueDateColor => const Color(0xFFFF2D78);

  // Water Monitor
  Color get blueColor => const Color(0xFF4EB5FF);
  Color get blueGradientColorOne => const Color(0xFF101C2A);
  Color get blueGradientColorTwo => const Color(0xFF0D2235);

  // Shimmer
  Color get shimmerBaseColor => const Color(0xFF2C2C2C);
  Color get shimmerHighlightColor => const Color(0xFF3D3D3D);
  Color get covid29Color => const Color(0xFF2563EB);
  Color get lightGreyTextColor => const Color(0xFF757575);
  Color get labelColorYellow => const Color(0xFFFBCB6E);

  // Aliases
  Color get bgScaffoldColor => scaffoldBgColor;
  Color get primaryRedBorderColor => primaryRedColor;
  Color get chipPrimaryRedBorderColor => primaryRedColor;
  Color get criticalLowAndHigh => primaryRedColor;
  Color get chipColorEmergency => primaryRedColor;
  Color get errorLightColor => primaryRedColor;
  Color get secondaryLightRedBorderColor => secondaryLightRedColor;
  Color get bgRedLightColor => secondaryLightRedColor;
  Color get chipSecondaryLightRedColor => secondaryLightRedColor;
  Color get blackBgColor => textColor;
  Color get blackColor => textColor;
  Color get borderOnlyColor => textColor;
  Color get chipBorderColorOpacity20 => borderGrayColor;
  Color get bgGreenColor => successColor;
  Color get textGreenColor => successColor;
  Color get successLightColor => successColor;
  Color get thumbColor => successColor;
  Color get chipColorMonitor => successColor;
  Color get greyLightColor => greyColor;
  Color get alertLightColor => alertColor;
  Color get infoLightColor => infoColor;
  Color get warningLightColor => warningColor;
}

// ---------------------------------------------------------------------------
// BuildContext extension — resolves the right palette based on theme brightness
// ---------------------------------------------------------------------------
extension AppColorsContext on BuildContext {
  bool get _isDark => Theme.of(this).brightness == Brightness.dark;

  // Scaffold / Background
  Color get scaffoldBgColor => _isDark ? AppColors.dark.scaffoldBgColor : const Color(0xFFF8F8F8);
  Color get bottomSheetBgColor => _isDark ? AppColors.dark.bottomSheetBgColor : const Color(0xFFF8F8FA);
  Color get greyF7Color => _isDark ? AppColors.dark.greyF7Color : const Color(0xffF7F7F7);
  Color get greyInfoTextColor => _isDark ? AppColors.dark.greyInfoTextColor : const Color(0xff777777);
  Color get lightGrayColor => _isDark ? AppColors.dark.lightGrayColor : const Color(0xff808080);

  // Core
  Color get cardBaseColor => _isDark ? AppColors.dark.baseColor : const Color(0xFFFFFFFF);
  Color get primaryRedColor => _isDark ? AppColors.dark.primaryRedColor : AppColors.primaryRedColor;
  Color get secondaryLightRedColor => _isDark ? AppColors.dark.serviceCardButtonColor : const Color(0xFFFEE9EA);
  Color get secondaryLightRedForegroundColor => _isDark ? const Color(0xFFFFFFFF) : AppColors.primaryRedColor;
  Color get successColor => AppColors.successColor;
  Color get successLightBgColor => _isDark ? AppColors.dark.successLightBgColor : const Color(0xffDDF6EA);
  Color get textColor => _isDark ? AppColors.dark.textColor : const Color(0xFF2E3039);
  Color get iconColor => _isDark ? AppColors.dark.iconColor : const Color(0xFF2E3039);
  Color get borderGrayColor => _isDark ? AppColors.dark.borderGrayColor : const Color(0x332E3039);
  Color get textColorLight => _isDark ? AppColors.dark.textColorLight : const Color(0xFF5E5E5E);
  Color get dividerColor => _isDark ? AppColors.dark.dividerColor : const Color(0x40D2D2D2);
  Color get inputLabelTextColor => _isDark ? AppColors.dark.inputLabelTextColor : const Color(0xff898A8D);
  Color get greyTextColor => AppColors.greyTextColor;
  Color get lightGrayBGColor => _isDark ? AppColors.dark.lightGrayBGColor : const Color(0x142E3039);
  Color get checkBoxBorderColor => _isDark ? AppColors.dark.checkBoxBorderColor : const Color(0xffD2D2D2);

  // Status / Semantic
  Color get errorColor => _isDark ? AppColors.dark.errorColor : const Color(0xFFED1C2B);
  Color get alertColor => AppColors.alertColor;
  Color get infoColor => _isDark ? AppColors.dark.infoColor : const Color(0xFF0B85F7);
  Color get warningColor => AppColors.warningColor;
  Color get greyColor => _isDark ? AppColors.dark.greyColor : const Color(0xFFEFEFF0);
  Color get chipBgColor => _isDark ? AppColors.dark.chipBgColor : const Color(0xFFEFEFF0);
  Color get cardDarkBorderColor => _isDark ? AppColors.dark.cardDarkBorderColor : Colors.transparent;
  Color get serviceCardButtonColor => _isDark ? AppColors.dark.serviceCardButtonColor : const Color(0xFF2E3039);
  Color get bottomNAVBorder => _isDark ? AppColors.dark.bottomNAVBorder : const Color(0xFFEEEEEE);
  Color get labelTextColor => _isDark ? AppColors.dark.labelTextColor : const Color(0xFF838383);
  Color get lightGreyTextColor => _isDark ? AppColors.dark.lightGreyTextColor : const Color(0xFF959595);

  // Info Banner
  Color get infoBannerBgColor => _isDark ? AppColors.dark.infoBannerBgColor : const Color(0xFFFFF4E6);
  Color get infoBannerBorderColor => _isDark ? AppColors.dark.infoBannerBorderColor : const Color(0xFFFFE5B4);
  Color get infoBannerIconColor => AppColors.infoBannerIconColor;
  Color get infoBannerTextColor => _isDark ? AppColors.dark.infoBannerTextColor : const Color(0xFF856404);

  // Water Monitor
  Color get blueColor => AppColors.blueColor;
  Color get blueGradientColorOne => _isDark ? AppColors.dark.blueGradientColorOne : const Color(0xFFF1F7FD);
  Color get blueGradientColorTwo => _isDark ? AppColors.dark.blueGradientColorTwo : const Color(0xFFD9EFFF);

  // Shimmer
  Color get shimmerBaseColor => _isDark ? AppColors.dark.shimmerBaseColor : const Color(0xFFE0E0E0);
  Color get shimmerHighlightColor => _isDark ? AppColors.dark.shimmerHighlightColor : const Color(0xFFF5F5F5);
  static const Color tooltipColor = Color(0xFF1AACACAC);

  // Aliases
  Color get bgScaffoldColor => scaffoldBgColor;
  Color get bgGreenColor => successColor;
  Color get bgRedLightColor => secondaryLightRedColor;
  Color get blackColor => textColor;
  Color get blackBgColor => textColor;
}
