import 'package:flutter/material.dart';
import 'package:hmg_qline/constants/app_constants.dart';
import 'package:hmg_qline/views/common_widgets/app_texts_widget.dart';
import 'package:hmg_qline/views/view_helpers/size_config.dart';

class SimpleDateDisplay extends StatelessWidget {
  final bool isForArabic;

  SimpleDateDisplay({super.key, required this.isForArabic});

  final List<String> _englishWeekdays = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];

  final List<String> _englishMonths = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];

  // Note: For Arabic, the full month names are commonly used in this context.
  final List<String> _arabicWeekdays = ['الاثنين', 'الثلاثاء', 'الأربعاء', 'الخميس', 'الجمعة', 'السبت', 'الأحد'];

  final List<String> _arabicMonths = ['يناير', 'فبراير', 'مارس', 'أبريل', 'مايو', 'يونيو', 'يوليو', 'أغسطس', 'سبتمبر', 'أكتوبر', 'نوفمبر', 'ديسمبر'];

  String _toArabicDigits(int number) {
    const Map<String, String> arabicDigits = {
      '0': '٠',
      '1': '١',
      '2': '٢',
      '3': '٣',
      '4': '٤',
      '5': '٥',
      '6': '٦',
      '7': '٧',
      '8': '٨',
      '9': '٩',
    };
    return number.toString().split('').map((char) => arabicDigits[char] ?? char).join();
  }

  @override
  Widget build(BuildContext context) {
    final DateTime now = DateTime.now();

    // English formatting
    final String englishDayOfWeek = _englishWeekdays[now.weekday - 1];
    final String englishMonthAbbr = _englishMonths[now.month - 1];
    final String englishDateString = '$englishDayOfWeek | ${now.day} $englishMonthAbbr';

    // Arabic formatting
    final String arabicDayOfWeek = _arabicWeekdays[now.weekday - 1];
    final String arabicDayDigits = _toArabicDigits(now.day);
    final String arabicMonthName = _arabicMonths[now.month - 1];
    final String arabicDateString = '$arabicDayOfWeek | $arabicDayDigits $arabicMonthName';

    return isForArabic // Use widget.isForArabic to access the property
        ? AppText(
            arabicDateString.toString(),
            fontSize: SizeConfig.getWidthMultiplier()! * 1.5,
            fontFamily: AppStrings.fontNameGesTwo,
            fontWeight: FontWeight.bold,
          )
        : AppText(
            englishDateString.toString(),
            fontSize: SizeConfig.getWidthMultiplier()! * 1.5,
            fontFamily: AppStrings.fontNamePoppins,
            fontWeight: FontWeight.bold,
          );
  }
}
