"use client" import * as React from "react" import { Building, Globe, Mail, MapPin, Phone, RefreshCw, Search } from "lucide-react" import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogFooter, } from "@/components/ui/dialog" import { Button } from "@/components/ui/button" import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs" import { ScrollArea } from "@/components/ui/scroll-area" import { Skeleton } from "@/components/ui/skeleton" import { Badge } from "@/components/ui/badge" import { Separator } from "@/components/ui/separator" import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" import { useToast } from "@/hooks/use-toast" // Import vendor service import { getVendorById, getVendorItemsByVendorId } from "@/lib/vendor-investigation/service" import { useRouter } from "next/navigation" interface VendorDetailsDialogProps { open: boolean onOpenChange: (open: boolean) => void vendorId: number | null } export function VendorDetailsDialog({ open, onOpenChange, vendorId, }: VendorDetailsDialogProps) { const { toast } = useToast() const router = useRouter() const [loading, setLoading] = React.useState(false) const [vendorData, setVendorData] = React.useState(null) const [vendorItems, setVendorItems] = React.useState([]) const [activeTab, setActiveTab] = React.useState("details") // Fetch vendor details when the dialog opens React.useEffect(() => { if (open && vendorId) { setLoading(true) // Fetch vendor details Promise.all([ getVendorById(vendorId), getVendorItemsByVendorId(vendorId) ]) .then(([vendorDetails, items]) => { setVendorData(vendorDetails) setVendorItems(items || []) }) .catch((error) => { console.error("Error fetching vendor data:", error) toast({ title: "Error", description: "Failed to load vendor details. Please try again.", variant: "destructive", }) }) .finally(() => { setLoading(false) }) } else { // Reset state when the dialog closes setVendorData(null) setVendorItems([]) } }, [open, vendorId, toast]) // Handle refresh button click const handleRefresh = () => { if (!vendorId) return setLoading(true) Promise.all([ getVendorById(vendorId), getVendorItemsByVendorId(vendorId) ]) .then(([vendorDetails, items]) => { setVendorData(vendorDetails) setVendorItems(items || []) toast({ title: "Refreshed", description: "Vendor information has been refreshed.", }) }) .catch((error) => { console.error("Error refreshing vendor data:", error) toast({ title: "Error", description: "Failed to refresh vendor details.", variant: "destructive", }) }) .finally(() => { setLoading(false) }) } // Get vendor status badge variant const getStatusVariant = (status: string) => { switch (status?.toUpperCase()) { case "ACTIVE": return "default" case "PENDING": return "secondary" case "SUSPENDED": return "destructive" case "APPROVED": return "outline" default: return "secondary" } } // Navigate to full vendor profile page const navigateToVendorProfile = () => { if (!vendorId) return // Close dialog onOpenChange(false) // Navigate to vendor profile page with router router.push(`/evcp/vendors/${vendorId}/info`) } return (
협력업체 상세정보
협력업체 정보 상세보기
{loading ? (
) : vendorData ? (
{/* Vendor header with main info */}

{vendorData.name}

업체코드: {vendorData.code} {vendorData.taxId && ( <> 사업자등록번호: {vendorData.taxId} )}
{vendorData.status && ( {vendorData.status} )}
상세 공급품목({vendorItems.length}) {/* Details Tab */} {/* Contact Information Card */} 연락처 정보
{/* Email */}
{vendorData.email || "No email provided"}
{/* Phone */}
{vendorData.phone || "No phone provided"}
{/* Website */} {vendorData.website && ( )} {/* Address */} {vendorData.address && (
{vendorData.address}
)} {/* Country */} {vendorData.country && (
{vendorData.country}
)}
{/* Additional Information */} {vendorData.description && ( 협력업체 설명

{vendorData.description}

)} {/* Registration Information */} 등록 정보

협력업체 생성일

{vendorData.createdAt ? new Date(vendorData.createdAt).toLocaleDateString() : "Unknown" }

협력업체 정보 업데이트일

{vendorData.updatedAt ? new Date(vendorData.updatedAt).toLocaleDateString() : "Unknown" }

{/* Items Tab */} {vendorItems.length > 0 ? (
{vendorItems.map((item) => ( {item.itemName} Code: {item.itemCode} {item.description && (

{item.description}

)}
))}
) : (

No items found

해당 업체는 아직 공급품목이 등록되지 않았습니다.

)}
) : (

No vendor information available

)} {vendorData && ( )}
) }