// 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';

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

  @override
  State<FlatButtons> createState() => _FlatButtonsState();
}

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

  @override
  Widget build(BuildContext context) => Column(
        children: [
          Text(
            'Flat Buttons',
            style: Theme.of(context).textTheme.titleMedium,
          ),
          const Gap(20),
          // Default
          const Center(
            /// You can overwrite global textstyle of the label with [label],
            /// but if you only want to override the color/gradient of the text
            /// in a particular case you can override the style that will
            /// be merge during the build.
            child: FlatButton(
              label: TextWrapper(
                'Voir notre savoir faire',
              ),
            ),
          ),
          const Gap(20),
          Center(
            child: BlocProvider(
              create: (context) => ButtonCubit()..freeze(),
              child: const FlatButton(
                label: TextWrapper('Enabled'),
              ),
            ),
          ),
          const Gap(20),
          // Disabled with ValueNotifier
          Center(
            child: FlatButton(
              label: const TextWrapper('Disabled'),
              disabled: _disabled,
            ),
          ),
          const Gap(20),
          Center(
            child: BlocProvider(
              create: (context) => ButtonCubit()..hover(),
              child: const FlatButton(
                label: TextWrapper('Hovered'),
              ),
            ),
          ),
          const Gap(20),
          Center(
            child: BlocProvider(
              create: (context) => ButtonCubit()..focus(),
              child: const FlatButton(
                label: TextWrapper('Focused'),
              ),
            ),
          ),
          const Gap(20),
          Center(
            child: BlocProvider(
              create: (context) => ButtonCubit()..tap(),
              child: const FlatButton(
                label: TextWrapper('Tapped'),
              ),
            ),
          ),
          const Gap(20),
          // 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;
                  });
                },
              ),
              FlatButton(
                label: const TextWrapper('Dynamic'),
                disabled: _dynamic,
              ),
            ],
          ),
          const Gap(20),
        ],
      );
}
