import 'package:design_system/design_system.dart';
import 'package:flutter/material.dart';
import 'package:flutter_modular/flutter_modular.dart';
import 'package:krow_domain/krow_domain.dart';
import 'package:core_localization/core_localization.dart';
import 'package:krow_core/core.dart';

/// A bottom action bar containing contextual buttons based on shift status.
class ShiftDetailsBottomBar extends StatelessWidget {
  /// The current shift.
  final Shift shift;
  
  /// Callback for applying/booking a shift.
  final VoidCallback onApply;
  
  /// Callback for declining a shift.
  final VoidCallback onDecline;
  
  /// Callback for accepting a shift.
  final VoidCallback onAccept;

  /// Creates a [ShiftDetailsBottomBar].
  const ShiftDetailsBottomBar({
    super.key,
    required this.shift,
    required this.onApply,
    required this.onDecline,
    required this.onAccept,
  });

  @override
  Widget build(BuildContext context) {
    final String status = shift.status ?? 'open';
    final i18n = Translations.of(context).staff_shifts.shift_details;

    return Container(
      padding: EdgeInsets.fromLTRB(
        UiConstants.space5,
        UiConstants.space4,
        UiConstants.space5,
        MediaQuery.of(context).padding.bottom + UiConstants.space4,
      ),
      decoration: BoxDecoration(
        color: UiColors.white,
        border: Border(top: BorderSide(color: UiColors.border)),
        boxShadow: [
          BoxShadow(
            color: UiColors.popupShadow.withValues(alpha: 0.05),
            blurRadius: 10,
            offset: const Offset(0, -4),
          ),
        ],
      ),
      child: _buildButtons(status, i18n, context),
    );
  }

  Widget _buildButtons(String status, dynamic i18n, BuildContext context) {
    if (status == 'confirmed') {
      return SizedBox(
        width: double.infinity,
        child: ElevatedButton(
          onPressed: () => Modular.to.toClockIn(),
          style: ElevatedButton.styleFrom(
            backgroundColor: UiColors.success,
            foregroundColor: UiColors.white,
            padding: const EdgeInsets.symmetric(vertical: UiConstants.space4),
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(UiConstants.radiusBase),
            ),
            elevation: 0,
          ),
          child: Text(i18n.clock_in, style: UiTypography.body2b.white),
        ),
      );
    }

    if (status == 'pending') {
      return Row(
        children: [
          Expanded(
            child: OutlinedButton(
              onPressed: onDecline,
              style: OutlinedButton.styleFrom(
                foregroundColor: UiColors.destructive,
                padding: const EdgeInsets.symmetric(
                  vertical: UiConstants.space4,
                ),
                side: const BorderSide(color: UiColors.destructive),
                shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(UiConstants.radiusBase),
                ),
              ),
              child: Text(i18n.decline, style: UiTypography.body2b.textError),
            ),
          ),
          const SizedBox(width: UiConstants.space4),
          Expanded(
            child: ElevatedButton(
              onPressed: onAccept,
              style: ElevatedButton.styleFrom(
                backgroundColor: UiColors.primary,
                foregroundColor: UiColors.white,
                padding: const EdgeInsets.symmetric(
                  vertical: UiConstants.space4,
                ),
                shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(UiConstants.radiusBase),
                ),
                elevation: 0,
              ),
              child: Text(i18n.accept_shift, style: UiTypography.body2b.white),
            ),
          ),
        ],
      );
    }

    if (status == 'open' || status == 'available') {
      return ElevatedButton(
        onPressed: onApply,
        style: ElevatedButton.styleFrom(
          backgroundColor: UiColors.primary,
          foregroundColor: UiColors.white,
          padding: const EdgeInsets.symmetric(vertical: UiConstants.space4),
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(UiConstants.radiusBase),
          ),
          elevation: 0,
        ),
        child: Text(i18n.apply_now, style: UiTypography.body2b.white),
      );
    }

    return const SizedBox.shrink();
  }
}
