import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:tanami_app/core/styles/app_color.dart';

import 'bloc/checkbox/checkbox_bloc.dart';
import 'bloc/checkbox/checkbox_event.dart';
import 'bloc/checkbox/checkbox_state.dart';

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

  @override
  Widget build(BuildContext context) {
    return BlocBuilder<CheckboxBloc, CheckBoxState>(
      builder: (context, state) {
        return Checkbox(
          activeColor: AppColor.checkBoxActiveColor,
          checkColor: Colors.white,
          side: MaterialStateBorderSide.resolveWith(
            (states) {
              if (states.contains(MaterialState.selected)) {
                return const BorderSide(
                    color: AppColor.checkBoxActiveColor, width: 2);
              }
              return const BorderSide(
                color: AppColor.strokeColor,
                width: 2,
              );
            },
          ),
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(6),
          ),
          value: state is CheckboxChecked,
          onChanged: (value) {
            context.read<CheckboxBloc>().add(ToggleCheckbox());
          },
        );
      },
    );
  }
}
