import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:gap/gap.dart';
import 'package:krow/core/presentation/styles/theme.dart';
import 'package:krow/core/presentation/widgets/ui_kit/kw_button.dart';
import 'package:krow/features/shifts/data/models/staff_shift.dart';
import 'package:krow/features/shifts/domain/blocs/shift_deteils_bloc/shift_details_bloc.dart';
import 'package:krow/features/shifts/presentation/dialogs/cancel_dialog/shift_cancel_dialog.dart';
import 'package:krow/features/shifts/presentation/dialogs/decline_dialog/shift_decline_dialog.dart';

class ShiftButtonsWidget extends StatelessWidget {
  final EventShiftRoleStaffStatus status;

  const ShiftButtonsWidget(this.status, {super.key});

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.all(16),
      decoration: BoxDecoration(
        gradient: LinearGradient(
          begin: Alignment.bottomCenter,
          end: const Alignment(0, -0.5),
          colors: [
            AppColors.grayWhite,
            AppColors.grayWhite.withAlpha(0),
          ],
        ),
      ),
      child: SafeArea(
        child: Column(
          children: status == EventShiftRoleStaffStatus.assigned
              ? [
                  KwButton.primary(
                    label: 'accept_shift'.tr(),
                    onPressed: () {
                      BlocProvider.of<ShiftDetailsBloc>(context).add(
                        const ShiftConfirmEvent(),
                      );
                    },
                    fit: KwButtonFit.expanded,
                  ),
                  const Gap(12),
                  KwButton.outlinedPrimary(
                      label: 'decline_shift'.tr(),
                      onPressed: () async {
                        var result =
                            await ShiftDeclineDialog.showCustomDialog(context);
                        if (result != null && context.mounted) {
                          BlocProvider.of<ShiftDetailsBloc>(context).add(
                            ShiftDeclineEvent(
                                result['reason'], result['additionalReason']),
                          );
                        }
                      }).copyWith(color: AppColors.statusError)
                ]
              : [
                  KwButton.outlinedPrimary(
                      label: 'cancel_shift'.tr(),
                      onPressed: () async {
                        var result =
                            await ShiftCancelDialog.showCustomDialog(context);
                        if (result != null && context.mounted) {
                          BlocProvider.of<ShiftDetailsBloc>(context).add(
                            ShiftCancelEvent(
                                result['reason'], result['additionalReason']),
                          );
                        }
                      }).copyWith(color: AppColors.statusError)
                ],
        ),
      ),
    );
  }
}
