
import React from 'react';
import { Button } from '@/components/ui/button';
import { Trash2, Loader2 } from 'lucide-react';
import {
  AlertDialog,
  AlertDialogAction,
  AlertDialogCancel,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogTitle,
  AlertDialogTrigger
} from '@/components/ui/alert-dialog';
import { useDeleteAlert } from '@/hooks/transactions/useDeleteAlert';

interface TransactionDeleteAlertProps {
  onDelete: () => Promise<boolean> | boolean;
}

/**
 * 트랜잭션 삭제 확인 다이얼로그 - 리팩토링된 버전
 * 삭제 로직을 useDeleteAlert 훅으로 분리하여 컴포넌트 간소화
 */
const TransactionDeleteAlert: React.FC<TransactionDeleteAlertProps> = ({ onDelete }) => {
  // 삭제 관련 로직을 커스텀 훅으로 분리
  const { isOpen, isDeleting, handleDelete, handleOpenChange } = useDeleteAlert(onDelete);
  
  return (
    <AlertDialog open={isOpen} onOpenChange={handleOpenChange}>
      <AlertDialogTrigger asChild>
        <Button 
          type="button" 
          variant="outline"
          className="border-red-200 text-red-500 hover:bg-red-50"
        >
          <Trash2 size={16} className="mr-1" />
          삭제
        </Button>
      </AlertDialogTrigger>
      <AlertDialogContent>
        <AlertDialogHeader>
          <AlertDialogTitle>지출 삭제</AlertDialogTitle>
          <AlertDialogDescription>
            정말로 이 지출 항목을 삭제하시겠습니까? 이 작업은 취소할 수 없습니다.
          </AlertDialogDescription>
        </AlertDialogHeader>
        <AlertDialogFooter>
          <AlertDialogCancel disabled={isDeleting}>취소</AlertDialogCancel>
          <Button 
            className="bg-red-500 hover:bg-red-600"
            onClick={handleDelete}
            disabled={isDeleting}
          >
            {isDeleting ? (
              <>
                <Loader2 size={16} className="mr-1 animate-spin" />
                처리 중...
              </>
            ) : (
              <>
                <Trash2 size={16} className="mr-1" />
                삭제
              </>
            )}
          </Button>
        </AlertDialogFooter>
      </AlertDialogContent>
    </AlertDialog>
  );
};

export default TransactionDeleteAlert;
