

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';

class CirculateWidget extends StatelessWidget {
  final bool isStartEndTime;
  final DateTime startTime;
  final DateTime endTime;
  final List<Map<String, String>> days;
  final List<String> selectedDays;

  // Callback functions to handle user interactions
  final Function(bool) onToggleStartEndTime;
  final Function(DateTime, bool) onTimeChanged;
  final Function(String) onDaySelected;
  final Function()? endDuration;
  final Function()? startDuration;
  const CirculateWidget({
    Key? key,
    required this.isStartEndTime,
    required this.startTime,
    required this.endTime,
    required this.days,
    required this.selectedDays,
    required this.onToggleStartEndTime,
    required this.onTimeChanged,
    required this.onDaySelected,
    required this.endDuration,
    required this.startDuration,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(

      padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 5),
      child: Column(
        children: <Widget>[
          // Start/End time toggle buttons
          Padding(
            padding: const EdgeInsets.all(8.0),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                InkWell(
                  onTap: () {
                    onToggleStartEndTime(true); // Toggle to Start Time
                  },
                  child: BodyMedium(
                    text: 'Start',
                    fontColor: !isStartEndTime ? Colors.black : Colors.blue,
                    fontSize: 18,
                  ),
                ),
                InkWell(
                  onTap: () {
                    onToggleStartEndTime(false); // Toggle to End Time
                  },
                  child: BodyMedium(
                    text: 'End',
                    fontColor: isStartEndTime ? Colors.black : Colors.blue,
                    fontSize: 18,
                  ),
                ),
              ],
            ),
          ),
          const Divider(
            color: ColorsManager.graysColor,
          ),
          // Time picker based on start/end toggle
          SizedBox(
            height: 110,
            child: CupertinoDatePicker(
              mode: CupertinoDatePickerMode.time,
              initialDateTime: isStartEndTime ? startTime : endTime,
              onDateTimeChanged: (selectedTime) {
                onTimeChanged(selectedTime, isStartEndTime); // Notify parent of time change
              },
            ),
          ),
          const Divider(
            color: ColorsManager.graysColor,
          ),
          const SizedBox(height: 20),
          Text('Select days to use Smart Mode'),
          const SizedBox(height: 20),
          // Days selection as horizontal list
          SizedBox(
            height: MediaQuery.of(context).size.height * 0.10,
            child: ListView(
              scrollDirection: Axis.horizontal,
              children: days.map((day) {
                bool isSelected = selectedDays.contains(day['key']);
                return Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: InkWell(
                    onTap: () {
                      onDaySelected(day['key']!); // Notify parent of day selection
                    },
                    child: Container(
                      width: 70,
                      padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 8),
                      decoration: BoxDecoration(
                        border: Border.all(
                          color: isSelected ? Colors.black : ColorsManager.grayColor,
                        ),
                        color: Colors.transparent,
                        borderRadius: BorderRadius.circular(55),
                      ),
                      child: Center(
                        child: Text(
                          day['day']!,
                          style: TextStyle(
                            fontSize: 18,
                            color: isSelected ? Colors.black : ColorsManager.grayColor,
                          ),
                        ),
                      ),
                    ),
                  ),
                );
              }).toList(),
            ),
          ),
          const SizedBox(height: 20),
           DefaultContainer(child:
            Column(
            children: [
              InkWell(
                onTap: startDuration,
                child: const Padding(
                  padding:  EdgeInsets.all(8.0),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                    Text('Start Duration'),
                    Row(
                      children: [
                        Text('0h 0m'),
                        Icon(Icons.arrow_forward_ios_sharp,color:ColorsManager.graysColor,)
                      ],
                    ),
                  ],),
                ),
              ),
              const Divider(color: ColorsManager.graysColor,),
              InkWell(
                onTap: endDuration,
                child: const Padding(
                  padding:  EdgeInsets.all(8.0),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text('End Duration'),
                      Row(
                        children: [
                          Text('0h 0m'),
                          Icon(Icons.arrow_forward_ios_sharp,color:ColorsManager.graysColor,)
                        ],
                      ),
                    ],),
                ),
              ),
            ],
          )
          )
        ],
      ),
    );
  }
}

