import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:marco/controller/task_planning/daily_task_controller.dart';
import 'package:marco/controller/permission_controller.dart';
import 'package:marco/helpers/utils/base_bottom_sheet.dart';
import 'package:marco/helpers/widgets/my_text.dart';

class DailyProgressReportFilter extends StatelessWidget {
  final DailyTaskController controller;
  final PermissionController permissionController;

  const DailyProgressReportFilter({
    super.key,
    required this.controller,
    required this.permissionController,
  });

  String getLabelText() {
    final startDate = controller.startDateTask;
    final endDate = controller.endDateTask;
    if (startDate != null && endDate != null) {
      final start = DateFormat('dd MM yyyy').format(startDate);
      final end = DateFormat('dd MM yyyy').format(endDate);
      return "$start - $end";
    }
    return "Select Date Range";
  }

  @override
  Widget build(BuildContext context) {
    return BaseBottomSheet(
      title: "Filter Tasks",
      onCancel: () => Navigator.pop(context),
      
      onSubmit: () {
        Navigator.pop(context, {
          'startDate': controller.startDateTask,
          'endDate': controller.endDateTask,
        });
      },
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          MyText.titleSmall("Select Date Range", fontWeight: 600),
          const SizedBox(height: 8),
          InkWell(
            borderRadius: BorderRadius.circular(10),
            onTap: () => controller.selectDateRangeForTaskData(
              context,
              controller,
            ),
            child: Ink(
              decoration: BoxDecoration(
                color: Colors.grey.shade100,
                border: Border.all(color: Colors.grey.shade400),
                borderRadius: BorderRadius.circular(10),
              ),
              padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
              child: Row(
                children: [
                  Icon(Icons.date_range, color: Colors.blue.shade600),
                  const SizedBox(width: 12),
                  Expanded(
                    child: Text(
                      getLabelText(),
                      style: const TextStyle(
                        fontSize: 16,
                        color: Colors.black87,
                        fontWeight: FontWeight.w500,
                      ),
                      overflow: TextOverflow.ellipsis,
                    ),
                  ),
                  const Icon(Icons.arrow_drop_down, color: Colors.grey),
                ],
              ),
            ),
          ),
        ],
      ),
    );
  }
}
