import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:hum/core/constants/app_text.dart';
import 'package:hum/core/constants/app_theme.dart';
import 'package:hum/widgets/widget_buttons.dart';
import 'package:hum/widgets/widget_text_fields.dart';

class HomeFilters extends StatefulWidget {
  const HomeFilters({super.key});

  @override
  State<HomeFilters> createState() => _HomeFiltersState();
}

String locationFriendly = 'San Francisco';
TextEditingController ctrlLocation = TextEditingController();
final UniqueKey keyCtrlLocation = UniqueKey();
String filterDateStartFriendly = 'May 22nd, 2027';
String filterDateEndFriendly = 'June 3rd, 2027';

class _HomeFiltersState extends State<HomeFilters> {
  @override
  Widget build(BuildContext context) {
    return CupertinoPageScaffold(
      backgroundColor: CupertinoDynamicColor.resolve(colorBarBackground, context),
      navigationBar: CupertinoNavigationBar(
        automaticallyImplyLeading: false,
        // leading: CupertinoButton(
        //   padding: EdgeInsets.zero,
        //   onPressed: () => Navigator.of(
        //     context,
        //   ).maybePop(),
        //   child: Text(
        //     'Close',
        //   ),
        // ),
        // middle: Text(
        //   'Filters',
        // ),
        trailing: CupertinoButton(
          padding: EdgeInsets.all(0),
          child: Text('Done'),
          onPressed: () => Navigator.of(context).maybePop(),
        ),
      ),
      child: SafeArea(
        child: Padding(
          padding: const EdgeInsets.symmetric(horizontal: 16.0),
          child: Column(
            spacing: 16,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              // LOCATION
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  LBLFilter(label: filterLocation),
                  Opacity(
                    opacity: 0.7,
                    child: Row(
                      spacing: 4,
                      children: [
                        Icon(CupertinoIcons.globe, color: CupertinoColors.lightBackgroundGray, size: 18),
                        Text(locationFriendly, style: TextStyle(fontSize: 15)),
                      ],
                    ),
                  ),
                ],
              ),

              TXTFieldInput(
                key: keyCtrlLocation,
                controller: ctrlLocation,
                placeholder: filterLocationPlaceholder,
                inputType: TextInputType.text,
              ),

              BTNFilledIcon(
                text: 'Current Location',
                color: colorBarButton,
                icon: CupertinoIcons.location_fill,
                action: () {},
              ),

              // SizedBox(
              //   width: double.infinity,
              //   child: CupertinoSlider(
              //     value: 30,
              //     min: 1,
              //     max: 100,
              //     onChanged:
              //         (
              //           value,
              //         ) => {},
              //   ),
              // ),
              Divider(),

              // DATES
              LBLFilter(label: filterDates),

              Column(
                spacing: 6,
                children: [
                  BTNComplex(
                    label: filterLabelStartDate,
                    text: filterDateStartFriendly,
                    iconLeading: CupertinoIcons.calendar,
                    color: CupertinoDynamicColor.resolve(colorBarButton, context),
                    textColor: CupertinoDynamicColor.resolve(colorAccentSecondary, context),
                    action: () {},
                  ),

                  Center(
                    child: Opacity(opacity: .5, child: Icon(CupertinoIcons.arrow_down, color: Colors.white)),
                  ),

                  BTNComplex(
                    label: filterLabelEndDate,
                    text: filterDateEndFriendly,
                    iconLeading: CupertinoIcons.calendar,
                    color: CupertinoDynamicColor.resolve(colorBarButton, context),
                    textColor: CupertinoDynamicColor.resolve(colorAccentPrimary, context),
                    action: () {},
                  ),
                ],
              ),

              Divider(),

              // PRICING
              LBLFilter(label: filterPricing),
            ],
          ),
        ),
      ),
    );
  }
}

class LBLFilter extends StatelessWidget {
  const LBLFilter({super.key, required this.label});

  final String label;

  @override
  Widget build(BuildContext context) {
    return Opacity(
      opacity: .5,
      child: Text(label, style: TextStyle(fontSize: 16, fontWeight: FontWeight.w300)),
    );
  }
}
