// 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_components/wyatt_ui_components.dart';
import 'package:wyatt_ui_kit/wyatt_ui_kit.dart';
import 'package:wyatt_ui_kit_example/theme/constants.dart';

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

  @override
  State<SymbolButtons> createState() => _SymbolButtonsState();
}

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

  Icon _icon(BuildContext context) => Icon(
        Icons.android,
        size: 25,
        color: (Theme.of(context).colorScheme.brightness == Brightness.light)
            ? Constants.dark
            : Constants.white,
      );

  @override
  Widget build(BuildContext context) => Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            'Symbol Buttons',
            style: Theme.of(context).textTheme.titleMedium,
          ),
          const Gap(20),
          SymbolButton(
            label: const TextWrapper('Text'),
            icon: _icon(context),
          ),
          const Gap(20),
          BlocProvider(
            create: (context) => SelectableButtonCubit()..freeze(),
            child: SymbolButton(
              label: const TextWrapper('Enabled'),
              icon: _icon(context),
            ),
          ),
          const Gap(20),
          // Disabled
          SymbolButton(
            label: const TextWrapper('Disabled'),
            icon: _icon(context),
            disabled: _disabled,
          ),
          const Gap(20),
          BlocProvider(
            create: (context) => SelectableButtonCubit()..hover(),
            child: SymbolButton(
              label: const TextWrapper('Hovered'),
              icon: _icon(context),
            ),
          ),
          const Gap(20),
          BlocProvider(
            create: (context) => SelectableButtonCubit()..focus(),
            child: SymbolButton(
              label: const TextWrapper('Focused'),
              icon: _icon(context),
            ),
          ),
          const Gap(20),
          BlocProvider(
            create: (context) => SelectableButtonCubit()..tap(),
            child: SymbolButton(
              label: const TextWrapper('Tapped'),
              icon: _icon(context),
            ),
          ),
          const Gap(20),
          BlocProvider(
            create: (context) => SelectableButtonCubit()..select(),
            child: SymbolButton(
              label: const TextWrapper('Selected'),
              icon: _icon(context),
            ),
          ),
          const Gap(20),
          Row(
            children: [
              Checkbox(
                value: !_dynamic.value,
                onChanged: (value) {
                  setState(() {
                    _dynamic.value = !_dynamic.value;
                  });
                },
              ),
              SymbolButton(
                label: const TextWrapper('Dynamic'),
                icon: _icon(context),
                disabled: _dynamic,
              ),
            ],
          ),
          const Gap(20),
          DecoratedBox(
            decoration: BoxDecoration(
              border: Border.all(color: Constants.red1),
            ),
            child: SymbolButton(
              label: const TextWrapper('Trigger zone'),
              icon: _icon(context),
            ),
          ),
          const Gap(20),
        ],
      );
}
