import 'package:ambito/src/extensions/extensions.dart';
import 'package:ambito/src/widgets/form/form_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart';

class FieldDaterangepicker extends FormWidgetField {
  FieldDaterangepicker(
      {required this.name,
      required this.label,
      required this.filterValue,
      required this.onClear,
      required this.onSelected,
      required this.entries});

  final String name;
  final String label;
  final String? filterValue;
  final VoidCallback onClear;
  final void Function(String?) onSelected;
  final List<String> entries;

  FormBuilderField get() {
    DateTime now = DateTime.now();

    return FormBuilderDateRangePicker(
        name: name,
        firstDate: now.firstDayOfYear(),
        lastDate: now.lastDayOfYear());

    return FormBuilderDropdown<String>(
      name: name,
      initialValue: filterValue,
      decoration: InputDecoration(
        labelText: label,
        prefix: IconButton(
          icon: const Icon(Icons.cancel_outlined),
          onPressed: onClear,
        ),
        hintText: label,
      ),
      onReset: onClear,
      onChanged: onSelected,
      items: entries
          .map(
            (entry) => DropdownMenuItem(
              value: entry,
              alignment: Alignment.centerLeft,
              child: Text(entry),
            ),
          )
          .toList(),
    );
  }
}
