/**
 * 단가 수정 이력 생성 다이얼로그
 */

'use client';

import { useState } from 'react';
import {
  Dialog,
  DialogContent,
  DialogDescription,
  DialogFooter,
  DialogHeader,
  DialogTitle,
} from '@/components/ui/dialog';
import { Button } from '@/components/ui/button';
import { Label } from '@/components/ui/label';
import { Textarea } from '@/components/ui/textarea';
import { Edit2, Save } from 'lucide-react';
import { toast } from 'sonner';

interface PricingRevisionDialogProps {
  open: boolean;
  onOpenChange: (open: boolean) => void;
  onConfirm: (reason: string) => void;
}

export function PricingRevisionDialog({
  open,
  onOpenChange,
  onConfirm,
}: PricingRevisionDialogProps) {
  const [revisionReason, setRevisionReason] = useState('');

  const handleConfirm = () => {
    if (!revisionReason.trim()) {
      toast.error('수정 사유를 입력해주세요.');
      return;
    }
    onConfirm(revisionReason);
    setRevisionReason('');
    onOpenChange(false);
  };

  const handleCancel = () => {
    setRevisionReason('');
    onOpenChange(false);
  };

  return (
    <Dialog open={open} onOpenChange={onOpenChange}>
      <DialogContent>
        <DialogHeader>
          <DialogTitle className="flex items-center gap-2">
            <Edit2 className="h-5 w-5" />
            수정 이력 생성
          </DialogTitle>
          <DialogDescription>
            단가 정보를 수정하시겠습니까? 수정 사유를 입력해주세요.
          </DialogDescription>
        </DialogHeader>

        <div className="space-y-4 py-4">
          <div>
            <Label>
              수정 사유 <span className="text-red-500">*</span>
            </Label>
            <Textarea
              value={revisionReason}
              onChange={(e) => setRevisionReason(e.target.value)}
              placeholder="예: 공급업체 단가 인상으로 인한 조정"
              rows={3}
            />
          </div>
        </div>

        <DialogFooter>
          <Button variant="outline" onClick={handleCancel}>
            취소
          </Button>
          <Button
            onClick={handleConfirm}
            className="bg-blue-600 hover:bg-blue-700"
          >
            <Save className="h-4 w-4 mr-2" />
            수정 이력 저장
          </Button>
        </DialogFooter>
      </DialogContent>
    </Dialog>
  );
}

export default PricingRevisionDialog;
