import 'package:auto_route/auto_route.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:gap/gap.dart';
import 'package:krow/core/presentation/styles/kw_text_styles.dart';
import 'package:krow/core/presentation/styles/theme.dart';
import 'package:krow/core/presentation/widgets/ui_kit/kw_button.dart';
import 'package:krow/core/presentation/widgets/ui_kit/kw_input.dart';
import 'package:krow/features/shifts/presentation/dialogs/cancel_dialog/cancel_reason_dropdown.dart';

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

  @override
  State<CancelDialogView> createState() => _CancelDialogViewState();
}

class _CancelDialogViewState extends State<CancelDialogView> {
  String selectedReason = '';
  final _textEditingController = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return Center(
      child: AnimatedSize(
        duration: const Duration(milliseconds: 300),
        child: Container(
          margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
          decoration: BoxDecoration(
            color: AppColors.grayWhite,
            borderRadius: BorderRadius.circular(24),
          ),
          child: SingleChildScrollView(
            padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 56),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.center,
              mainAxisSize: MainAxisSize.min,
              children: [
                Text(
                  'cancel_shift'.tr(),
                  style: AppTextStyles.headingH1.copyWith(height: 1),
                  textAlign: TextAlign.center,
                ),
                const Gap(8),
                Text(
                  'please_select_reason'.tr(),
                  style: AppTextStyles.bodyMediumReg
                      .copyWith(color: AppColors.blackGray),
                  textAlign: TextAlign.center,
                ),
                const Gap(8),
                CancelReasonDropdown(
                  selectedReason: selectedReason,
                  onReasonSelected: (String reason) {
                    setState(() {
                      selectedReason = reason;
                    });
                  },
                ),
                const Gap(8),
                KwTextInput(
                  controller: _textEditingController,
                  minHeight: 144,
                  maxLength: 300,
                  showCounter: true,
                  radius: 12,
                  title: 'additional_reasons'.tr(),
                  hintText: 'enter_main_text'.tr(),
                ),
                const Gap(24),
                _buttonGroup(context),
              ],
            ),
          ),
        ),
      ),
    );
  }

  Widget _buttonGroup(
    BuildContext context,
  ) {
    return Column(
      children: [
        KwButton.primary(
          disabled: selectedReason.isEmpty,
          label: 'submit_reason'.tr(),
          onPressed:  () {
            context.maybePop({
              'reason': selectedReason,
              'additionalReason': _textEditingController.text,
            });
          },
        ),
        const Gap(8),
        KwButton.outlinedPrimary(
            label: 'cancel'.tr(),
            onPressed: () {
              context.maybePop();
            }),
      ],
    );
  }
}
