"use client" import * as React from "react" import { useEffect, useState } from "react" import { Copy } from "lucide-react" import { Badge } from "@/components/ui/badge" import { Button } from "@/components/ui/button" import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle } from "@/components/ui/sheet" import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table" import { Card, CardContent, CardDescription, CardHeader, CardTitle, CardFooter } from "@/components/ui/card" import { Separator } from "@/components/ui/separator" import { ViewTagSubfields } from "@/db/schema/vendorData" import { fetchTagSubfieldOptions } from "../service" interface TagOption { id: number attributesId: string code: string label: string createdAt?: Date updatedAt?: Date } interface ViewTagOptionsProps { open: boolean onOpenChange: (open: boolean) => void tagSubfield: ViewTagSubfields | null } export function ViewTagOptions({ open, onOpenChange, tagSubfield }: ViewTagOptionsProps) { const [options, setOptions] = useState([]) const [loading, setLoading] = useState(false) const [copied, setCopied] = useState(null) // 옵션 데이터 가져오기 useEffect(() => { async function fetchOptions() { if (!tagSubfield || !open) return setLoading(true) try { // 서버 액션 호출 - attributesId와 일치하는 모든 옵션 가져오기 const optionsData = await fetchTagSubfieldOptions(tagSubfield.attributesId) setOptions(optionsData || []) } catch (error) { console.error("Error fetching tag options:", error) setOptions([]) } finally { setLoading(false) } } fetchOptions() }, [tagSubfield, open]) // 코드 복사 기능 const copyToClipboard = (text: string, type: string) => { navigator.clipboard.writeText(text).then(() => { setCopied(type) setTimeout(() => setCopied(null), 2000) }) } if (!tagSubfield) return null return ( Field Options {options.length} options Field information and available options
Attributes ID:
{tagSubfield.attributesId} {copied === 'attributesId' && ( Copied )}
Tag Type: {tagSubfield.tagTypeCode}
Description: {tagSubfield.attributesDescription}
Expression: {tagSubfield.expression || 'N/A'}
{tagSubfield.tagTypeDescription && (
Type Description: {tagSubfield.tagTypeDescription}
)}
{loading ? (
) : options.length > 0 ? ( Available Options All available options for field {tagSubfield.attributesId} Code Label Actions {options.map((option) => ( {option.code} {option.label} ))}
{options.length} options found for {tagSubfield.attributesId}
{tagSubfield.delimiter && (
Delimiter: {tagSubfield.delimiter}
)}
) : (
No options found

This field ({tagSubfield.attributesId}) has no defined options.

)}
) }