import 'package:flutter/material.dart';

import '../../../core.dart';

GestureDetector dateFilterWidget({
  bool isFrom = true,
  required Rx<Jalali> date,
  required Function(Jalali jalali) onChanged,
}) {
  return GestureDetector(
    onTap: () {
      Get.bottomSheet(
        modalDatePicker(
          initialDate: date.value,
          onDateSelected: (value) {
            date.value = value;
            onChanged(value);
          },
        ),
      );
    },
    child: Container(
      height: 35,
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(8),
        border: Border.all(width: 1, color: AppColor.blueNormal),
      ),
      padding: EdgeInsets.symmetric(horizontal: 11, vertical: 4),
      child: Row(
        spacing: 8,
        children: [
          Assets.vec.calendarSvg.svg(
            width: 24,
            height: 24,
            colorFilter: const ColorFilter.mode(AppColor.blueNormal, BlendMode.srcIn),
          ),
          Text(isFrom ? 'از' : 'تا', style: AppFonts.yekan16.copyWith(color: AppColor.blueNormal)),
          Expanded(
            child: ObxValue((data) {
              return Text(
                date.value.formatCompactDate(),
                textAlign: TextAlign.center,
                style: AppFonts.yekan16.copyWith(color: AppColor.lightGreyNormalActive),
              );
            }, date),
          ),
        ],
      ),
    ),
  );
}

Container modalDatePicker({required ValueChanged<Jalali> onDateSelected, Jalali? initialDate}) {
  return Container(
    height: 250,
    color: Colors.white,
    child: Column(
      mainAxisSize: MainAxisSize.min,
      children: <Widget>[
        Row(
          children: [
            SizedBox(width: 20),
            RElevated(
              height: 35,
              width: 70,
              textStyle: AppFonts.yekan14.copyWith(color: Colors.white),
              onPressed: () {
                onDateSelected(initialDate ?? Jalali.now());
                Get.back();
              },
              text: 'تایید',
            ),
            Spacer(),
            RElevated(
              height: 35,
              width: 70,
              backgroundColor: AppColor.error,
              textStyle: AppFonts.yekan14.copyWith(color: Colors.white),
              onPressed: () {
                onDateSelected(initialDate ?? Jalali.now());
                Get.back();
              },
              text: 'لغو',
            ),
            SizedBox(width: 20),
          ],
        ),
        Divider(height: 0, thickness: 1),
        Expanded(
          child: PersianCupertinoDatePicker(
            initialDateTime: initialDate ?? Jalali.now(),
            mode: PersianCupertinoDatePickerMode.date,
            onDateTimeChanged: (dateTime) {
              initialDate = dateTime;
            },
          ),
        ),
      ],
    ),
  );
}
