// ignore_for_file: must_be_immutable

import 'package:flutter/material.dart';
import 'package:general_package/constants/constants.dart';
import 'package:general_package/responsive/responsive.dart';
import 'package:general_package/themes/themes.dart';
import 'package:get/get_rx/src/rx_typedefs/rx_typedefs.dart';

import 'f_datetimerangepicker.dart';

class DynamicFormDateTimeRange extends StatefulWidget {
  DynamicFormDateTimeRange({
    super.key,
    this.title,
    required this.onChanged,
    this.padding,
  });
  String? title;
  EdgeInsetsGeometry? padding;
  final void Function(String) onChanged;
  @override
  State<DynamicFormDateTimeRange> createState() =>
      _DynamicFormDateTimeRangeState();
}

class _DynamicFormDateTimeRangeState extends State<DynamicFormDateTimeRange> {
  @override
  Widget build(BuildContext context) {
    return Container(
      padding: widget.padding,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisAlignment: MainAxisAlignment.start,
        children: [
          if(widget.title!=null)Text(widget.title!, style: Theme.of(context).textTheme.bodyText1),
          GeneralConstants.instance.sizedBoxHeight10,
          InkWell(
              onTap: () {
                DateTimeRangePicker(
                    startText: "From",
                    endText: "To",
                    doneText: "Yes",
                    cancelText: "Cancel",
                    // interval: 1,
                    // initialStartTime: DateTime.now(),
                    // initialEndTime: DateTime.now().add(Duration(days: 20)),
                    mode: DateTimeRangePickerMode.dateAndTime,
                    minimumTime: DateTime.now(),
                    maximumTime: DateTime.now().add(Duration(days: 25)),
                    use24hFormat: false,
                    onConfirm: (start, end) {
                      print(start);
                      print(end);
                      widget.onChanged("$start - $end");
                    }).showPicker(context);
              },
              child: Container(
                child: Text("Date Time Range"),
              ))
        ],
      ),
    );
  }
}
