import{jsxs as l,jsx as t}from"react/jsx-runtime";import{useState as c,useCallback as h,useEffect as u}from"react";import{S as g,a as S,b as x,c as T,f as m}from"./select-DfhewM4T.js";import{L as C}from"./label-DMnntKPk.js";import"@radix-ui/react-select";import"lucide-react";import"./utils-CMbmcP35.js";import"clsx";import"tailwind-merge";import"@radix-ui/react-label";function E({onSelect:n,className:d}){const[i,p]=c([]),[o,r]=c(!1),s=h(async()=>{r(!0);try{const e=await fetch("/admin/manage/item-template/all");if(e.ok){const a=await e.json();p(a)}}catch{}finally{r(!1)}},[]);return u(()=>{s()},[s]),l("div",{className:d,children:[t(C,{children:"Use Template (Optional)"}),l(g,{onValueChange:e=>{if(e==="none"){n(null);return}const a=i.find(f=>f.id===parseInt(e));a&&n(a)},disabled:o,children:[t(S,{children:t(x,{placeholder:o?"Loading...":"Select a template"})}),l(T,{children:[t(m,{value:"none",children:"-- No Template --"}),i.map(e=>l(m,{value:String(e.id),children:[e.name," (ID: ",e.item_id,")"]},e.id))]})]}),t("p",{className:"text-xs text-muted-foreground mt-1",children:"Select a template to auto-fill item data"})]})}export{E as TemplateSelect};
