import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:gap/gap.dart';
import 'package:krow/core/presentation/gen/assets.gen.dart';
import 'package:krow/core/presentation/styles/kw_box_decorations.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/invoice/presentation/screens/invoice_details/dialogs/invoice_reason_dropdown.dart';

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

  static Future<Map<String, dynamic>?> showCustomDialog(
      BuildContext context) async {
    return await showDialog<Map<String, dynamic>>(
      context: context,
      builder: (context) => const ShiftDeclineDialog(),
    );
  }

  @override
  State<ShiftDeclineDialog> createState() => _ShiftDeclineDialogState();
}

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.transparent,
      body: Center(
        child: AnimatedSize(
          duration: const Duration(milliseconds: 300),
          child: Container(
            margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
            decoration: KwBoxDecorations.white24,
            child: SingleChildScrollView(
              padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 56),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.center,
                mainAxisSize: MainAxisSize.min,
                children: [
                  Container(
                    height: 64,
                    width: 64,
                    decoration: BoxDecoration(
                      color: AppColors.tintRed,
                      shape: BoxShape.circle,
                    ),
                    child: Center(
                      child: Assets.images.icons.receiptSearch.svg(
                        width: 32,
                        height: 32,
                        colorFilter: ColorFilter.mode(
                            AppColors.statusError, BlendMode.srcIn),
                      ),
                    ),
                  ),
                  Gap(32),
                  Text(
                    'Dispute Invoice',
                    style: AppTextStyles.headingH1.copyWith(height: 1),
                    textAlign: TextAlign.center,
                  ),
                  const Gap(8),
                  Text(
                    'If there’s an issue with this invoice, please select a reason below and provide any additional details. We’ll review your dispute and get back to you as soon as possible.',
                    style: AppTextStyles.bodyMediumReg
                        .copyWith(color: AppColors.blackGray),
                    textAlign: TextAlign.center,
                  ),
                  const Gap(8),
                  InvoiceReasonDropdown(
                    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',
                    hintText: 'Enter your main text here...',
                    onChanged: (String value) {
                      setState(() {});
                    },
                  ),
                  const Gap(24),
                  _buttonGroup(context),
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }

  Widget _buttonGroup(
    BuildContext context,
  ) {
    return Column(
      children: [
        KwButton.primary(
          disabled: selectedReason.isEmpty || (_textEditingController.text.isEmpty),
          label: 'Submit Request',
          onPressed: () {
            context.pop({
              'reason': selectedReason,
              'comment': _textEditingController.text,
            });
          },
        ),
        const Gap(8),
        KwButton.outlinedPrimary(
          label: 'Cancel',
          onPressed: () {
            context.pop();
          },
        ),
      ],
    );
  }
}
