import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:krezus/domains/charts/chart_bloc.dart';

class YearSelector extends StatelessWidget {
  const YearSelector({super.key});

  @override
  Widget build(BuildContext context) {
    return BlocBuilder<ChartBloc, ChartState>(
      builder: (context, state) => Container(
        margin: const EdgeInsets.fromLTRB(20, 0, 0, 0),
        padding: const EdgeInsets.fromLTRB(5, 0, 5, 0),
        decoration: BoxDecoration(
          color: Theme.of(context).colorScheme.primaryContainer,
          borderRadius: BorderRadius.circular(5),
        ),
        child: Row(
          children: [
            IconButton(
              onPressed: () => context.read<ChartBloc>().add(ChartPreviousYear()),
              icon: const Icon(Icons.skip_previous)
            ),
            Text(state.currentYear.toString()),
            IconButton(
              onPressed: () => context.read<ChartBloc>().add(ChartNextYear()),
              icon: const Icon(Icons.skip_next)
            ),
          ],
        )
      )
    );
  }
}