// Copyright (C) 2023 WYATT GROUP
// Please see the AUTHORS file for details.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:gap/gap.dart';
import 'package:wyatt_ui_kit/wyatt_ui_kit.dart';

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

  @override
  State<SimpleIconButtons> createState() => _SimpleIconButtonsState();
}

class _SimpleIconButtonsState extends State<SimpleIconButtons> {
  final _disabled = ValueNotifier(true);
  final _dynamic = ValueNotifier(false);

  @override
  Widget build(BuildContext context) => Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            'SimpleIcon Buttons',
            style: Theme.of(context).textTheme.titleMedium,
          ),
          const Gap(20),
          // Default
          const SimpleIconButton(
            icon: Icon(
              Icons.storm_outlined,
              size: 17,
            ),
          ),
          const Gap(20),
          Text(
            'Enabled',
            style: Theme.of(context).textTheme.labelMedium,
          ),
          const Gap(10),
          BlocProvider(
            create: (context) => ButtonCubit()..freeze(),
            child: const SimpleIconButton(
              icon: Icon(
                Icons.storm_outlined,
                size: 17,
              ),
            ),
          ),
          const Gap(20),
          Text(
            'Disabled',
            style: Theme.of(context).textTheme.labelMedium,
          ),
          const Gap(10),
          // Disabled using ValueNotifier
          SimpleIconButton(
            icon: const Icon(
              Icons.storm_outlined,
              size: 17,
            ),
            disabled: _disabled,
          ),
          const Gap(20),
          Text(
            'Hovered',
            style: Theme.of(context).textTheme.labelMedium,
          ),
          const Gap(10),
          BlocProvider(
            create: (context) => ButtonCubit()..hover(),
            child: const SimpleIconButton(
              icon: Icon(
                Icons.storm_outlined,
                size: 17,
              ),
            ),
          ),
          const Gap(20),
          Text(
            'Focused',
            style: Theme.of(context).textTheme.labelMedium,
          ),
          const Gap(10),
          BlocProvider(
            create: (context) => ButtonCubit()..focus(),
            child: const SimpleIconButton(
              icon: Icon(
                Icons.storm_outlined,
                size: 17,
              ),
            ),
          ),
          const Gap(20),
          Text(
            'Tapped',
            style: Theme.of(context).textTheme.labelMedium,
          ),
          const Gap(10),
          BlocProvider(
            create: (context) => ButtonCubit()..tap(),
            child: const SimpleIconButton(
              icon: Icon(
                Icons.storm_outlined,
                size: 17,
              ),
            ),
          ),
          const Gap(20),
          Text(
            'Dynamic',
            style: Theme.of(context).textTheme.labelMedium,
          ),
          const Gap(10),
          // Dynamic, disabled with ValueNotifier and
          // keep the state when the button is disabled
          Row(
            children: [
              Checkbox(
                value: !_dynamic.value,
                onChanged: (value) {
                  setState(() {
                    _dynamic.value = !_dynamic.value;
                  });
                },
              ),
              SimpleIconButton(
                icon: const Icon(
                  Icons.storm_outlined,
                  size: 17,
                ),
                disabled: _dynamic,
              ),
            ],
          ),
        ],
      );
}
