"use client" import * as React from "react" import { useRouter } from "next/navigation" import { useTransition } from "react" import { Button } from "@/components/ui/button" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" import { RefreshCw, RotateCw } from "lucide-react" import { increaseRoundOrRebid } from "@/lib/bidding/service" import { useToast } from "@/hooks/use-toast" import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "@/components/ui/alert-dialog" import { useSession } from "next-auth/react" interface BiddingRoundActionsProps { biddingId: number biddingStatus?: string } export function BiddingRoundActions({ biddingId, biddingStatus }: BiddingRoundActionsProps) { const router = useRouter() const { toast } = useToast() const [isPending, startTransition] = useTransition() const [showRoundDialog, setShowRoundDialog] = React.useState(false) const [showRebidDialog, setShowRebidDialog] = React.useState(false) const { data: session } = useSession() const userId = session?.user?.id // 차수증가는 유찰 상태에서만 가능 const canIncreaseRound = biddingStatus === 'bidding_disposal' // 재입찰도 유찰 상태에서만 가능 const canRebid = biddingStatus === 'bidding_disposal' const handleRoundIncrease = () => { startTransition(async () => { try { const result = await increaseRoundOrRebid(biddingId, userId, 'round_increase') if (result.success) { toast({ title: "성공", description: result.message, variant: "default", }) setShowRoundDialog(false) // 새로 생성된 입찰 페이지로 이동 if (result.biddingId) { router.push(`/evcp/bid/${result.biddingId}`) router.refresh() } } else { toast({ title: "오류", description: result.error || "차수증가 중 오류가 발생했습니다.", variant: "destructive", }) } } catch (error) { console.error('차수증가 실패:', error) toast({ title: "오류", description: "차수증가 중 오류가 발생했습니다.", variant: "destructive", }) } }) } const handleRebid = () => { startTransition(async () => { try { const result = await increaseRoundOrRebid(biddingId, userId, 'rebidding') if (result.success) { toast({ title: "성공", description: result.message, variant: "default", }) setShowRebidDialog(false) // 새로 생성된 입찰 페이지로 이동 if (result.biddingId) { router.push(`/evcp/bid/${result.biddingId}`) router.refresh() } } else { toast({ title: "오류", description: result.error || "재입찰 중 오류가 발생했습니다.", variant: "destructive", }) } } catch (error) { console.error('재입찰 실패:', error) toast({ title: "오류", description: "재입찰 중 오류가 발생했습니다.", variant: "destructive", }) } }) } // 유찰 상태가 아니면 컴포넌트를 렌더링하지 않음 if (!canIncreaseRound && !canRebid) { return null } return ( <> 입찰 차수 관리

유찰 상태에서 차수증가 또는 재입찰을 진행할 수 있습니다.

{/* 차수증가 확인 다이얼로그 */} 차수증가 현재 입찰의 정보를 복제하여 새로운 차수의 입찰을 생성합니다.
기존 입찰 조건, 아이템, 벤더 정보가 복제되며, 벤더 제출 정보는 초기화됩니다.

계속하시겠습니까?
취소 {isPending ? "처리중..." : "확인"}
{/* 재입찰 확인 다이얼로그 */} 재입찰 현재 입찰의 정보를 복제하여 재입찰을 생성합니다.
기존 입찰 조건, 아이템, 벤더 정보가 복제되며, 벤더 제출 정보는 초기화됩니다.

계속하시겠습니까?
취소 {isPending ? "처리중..." : "확인"}
) }