import 'package:flutter/material.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';
import '../../core/i18n/app_localizations.dart';
import '../../core/theme/app_colors_extension.dart';

class ApprovalActions extends StatelessWidget {
  final int queryId;
  final bool isSubmitting;
  final VoidCallback onApprove;
  final VoidCallback onReject;
  final VoidCallback onReverseAudit;

  const ApprovalActions({
    super.key,
    required this.queryId,
    this.isSubmitting = false,
    required this.onApprove,
    required this.onReject,
    required this.onReverseAudit,
  });

  @override
  Widget build(BuildContext context) {
    if (isSubmitting) {
      return const SafeArea(
        child: Padding(
          padding: EdgeInsets.all(12),
          child: Center(child: TDLoading(size: TDLoadingSize.large, icon: TDLoadingIcon.activity)),
        ),
      );
    }

    // queryId 1/2/3: 审核（通过+驳回）
    // queryId 4/5: 反审核
    // 其他: 无按钮
    if (queryId < 1 || queryId > 5) return const SizedBox.shrink();

    final l10n = AppLocalizations.of(context);
    final colors = Theme.of(context).extension<AppColorsExtension>()!;

    return ColoredBox(
      color: colors.bgCard,
      child: SafeArea(
        top: false,
        child: Padding(
          padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
          child: queryId >= 1 && queryId <= 3
              ? Row(children: [
                  Expanded(child: TDButton(text: l10n.get('reject'), size: TDButtonSize.large, theme: TDButtonTheme.danger, type: TDButtonType.outline, onTap: onReject)),
                  const SizedBox(width: 12),
                  Expanded(child: TDButton(text: l10n.get('approve'), size: TDButtonSize.large, theme: TDButtonTheme.primary, onTap: onApprove)),
                ])
              : SizedBox(
                  width: double.infinity,
                  child: TDButton(text: l10n.get('withdrawApplication'), size: TDButtonSize.large, theme: TDButtonTheme.danger, type: TDButtonType.outline, onTap: onReverseAudit),
                ),
        ),
      ),
    );
  }
}
