import 'package:flutter/material.dart';
import 'package:starting_template/core/extensions/build_context_extension.dart';
import 'package:starting_template/domain/repositories/counter_repository.dart';
import 'package:starting_template/domain/usecases/counter/decrement.dart';
import 'package:starting_template/domain/usecases/counter/get_current.dart';
import 'package:starting_template/domain/usecases/counter/increment.dart';
import 'package:starting_template/domain/usecases/counter/reset.dart';
import 'package:starting_template/presentation/features/counter/blocs/counter_cubit/counter_cubit.dart';
import 'package:starting_template/presentation/features/counter/screens/widgets/counter_consumer_widget.dart';
import 'package:starting_template/presentation/shared/layouts/wyatt_app_template_scaffold.dart';
import 'package:wyatt_bloc_helper/wyatt_bloc_helper.dart';

/// {@template counter_provider}
/// CounterProvider provides bloc to his children.
/// {@endtemplate}
class CounterProvider extends CubitProviderScreen<CounterCubit, CounterState> {
  /// {@macro counter_provider}
  const CounterProvider({super.key});

  @override
  CounterCubit create(BuildContext context) => CounterCubit(
        decrement: Decrement(
          counterRepository: repo<CounterRepository>(context),
        ),
        increment: Increment(
          counterRepository: repo<CounterRepository>(context),
        ),
        getCurrent: GetCurrent(
          counterRepository: repo<CounterRepository>(context),
        ),
        reset: Reset(
          counterRepository: repo<CounterRepository>(context),
        ),
      );

  @override
  CounterCubit init(BuildContext context, CounterCubit bloc) =>
      bloc..getCurrent();

  @override
  Widget builder(BuildContext context) => WyattAppTemplateScaffold(
        title: Text(context.l10n.counterAppBarTitle),
        body: const CounterConsumerWidget(),
        fabChildren: [
          FloatingActionButton(
            heroTag: 'increment_tag',
            onPressed: () => bloc(context).increment(),
            child: const Icon(Icons.add),
          ),
          const SizedBox(height: 8),
          FloatingActionButton(
            heroTag: 'increment_10_tag',
            onPressed: () => bloc(context).increment(10),
            child: const Text('+10'),
          ),
          const SizedBox(height: 8),
          FloatingActionButton(
            heroTag: 'decrement_tag',
            onPressed: () => bloc(context).decrement(),
            child: const Icon(Icons.remove),
          ),
          const SizedBox(height: 8),
          FloatingActionButton(
            heroTag: 'decrement_10_tag',
            onPressed: () => bloc(context).decrement(10),
            child: const Text('-10'),
          ),
          const SizedBox(height: 8),
          FloatingActionButton(
            heroTag: 'reset_tag',
            onPressed: () => bloc(context).reset(),
            child: const Icon(Icons.refresh),
          ),
        ],
      );
}
