'use client';

import {
  AlertDialog,
  AlertDialogAction,
  AlertDialogCancel,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogTitle,
} from '@/components/ui/overlays/AlertDialog';
import { Label } from '@/components/ui/primitives/Label';
import { Textarea } from '@/components/ui/primitives/Textarea';
import type { UserRow } from './UsersMgmt';

interface QuickFreezeDialogProps {
  t: (key: string) => string;
  tCommon: (key: string) => string;
  quickFreezeUser: UserRow | null;
  setQuickFreezeUser: (user: UserRow | null) => void;
  quickFreezeReason: string;
  setQuickFreezeReason: (value: string) => void;
  actionLoading: string | null;
  onConfirm: () => void | Promise<void>;
}

export function QuickFreezeDialog({
  t,
  tCommon,
  quickFreezeUser,
  setQuickFreezeUser,
  quickFreezeReason,
  setQuickFreezeReason,
  actionLoading,
  onConfirm,
}: QuickFreezeDialogProps) {
  return (
    <AlertDialog
      open={quickFreezeUser !== null}
      onOpenChange={(open) => {
        if (!open) {
          setQuickFreezeUser(null);
          setQuickFreezeReason('');
        }
      }}
    >
      <AlertDialogContent>
        <AlertDialogHeader>
          <AlertDialogTitle>{t('freeze_dialog_title')}</AlertDialogTitle>
          <AlertDialogDescription>{t('freeze_dialog_description')}</AlertDialogDescription>
        </AlertDialogHeader>
        <div className="flex flex-col gap-1 py-2">
          <Label htmlFor="quick-freeze-reason">{t('reason_label')}</Label>
          <Textarea
            id="quick-freeze-reason"
            rows={3}
            value={quickFreezeReason}
            onChange={(e) => setQuickFreezeReason(e.target.value)}
            placeholder={t('freeze_reason_placeholder')}
          />
        </div>
        <AlertDialogFooter>
          <AlertDialogCancel>{tCommon('cancel')}</AlertDialogCancel>
          <AlertDialogAction
            disabled={!quickFreezeReason.trim() || actionLoading === 'freeze'}
            onClick={() => void onConfirm()}
          >
            {t('confirm_freeze')}
          </AlertDialogAction>
        </AlertDialogFooter>
      </AlertDialogContent>
    </AlertDialog>
  );
}
