"use client"; import { useState, useEffect, useMemo } from "react"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { ScrollArea } from "@/components/ui/scroll-area"; import { Loader2, Search } from "lucide-react"; import { useBarcodeDesigner } from "@/contexts/BarcodeDesignerContext"; import { barcodeApi, BarcodeLabelTemplate } from "@/lib/api/barcodeApi"; type Category = "all" | "basic" | "zebra"; export function BarcodeTemplatePalette() { const { applyTemplate } = useBarcodeDesigner(); const [templates, setTemplates] = useState([]); const [loading, setLoading] = useState(true); const [category, setCategory] = useState("all"); const [searchText, setSearchText] = useState(""); useEffect(() => { (async () => { try { const res = await barcodeApi.getTemplates(); if (res.success && res.data) setTemplates(res.data); } catch { setTemplates([]); } finally { setLoading(false); } })(); }, []); const filtered = useMemo(() => { let list = templates; if (category === "basic") { list = list.filter((t) => t.template_id.startsWith("TMPL_")); } else if (category === "zebra") { list = list.filter((t) => t.template_id.startsWith("ZJ")); } const q = searchText.trim().toLowerCase(); if (q) { list = list.filter( (t) => t.template_id.toLowerCase().includes(q) || (t.template_name_kor && t.template_name_kor.toLowerCase().includes(q)) || (t.template_name_eng && t.template_name_eng.toLowerCase().includes(q)) ); } return list; }, [templates, category, searchText]); if (loading) { return ( 라벨 규격 ); } return ( 라벨 규격
setSearchText(e.target.value)} className="h-8 pl-8 text-xs" />
{filtered.length === 0 ? (

검색 결과 없음

) : ( filtered.map((t) => ( )) )}
); }