import{i as e}from"./rolldown-runtime-B1FJdls4.js";import{m as t}from"./vendor-dnd-C1cICjTT.js";import{T as n,g as r,j as i}from"./vendor-misc-D1uXP2P6.js";import{s as a}from"./vendor-markdown-Db1-9wH7.js";var o=e(t(),1),s=a();async function c(e){return new Promise((t,n)=>{let r=new FileReader;r.onerror=()=>n(Error(`Could not read that image.`)),r.onload=()=>t(String(r.result??``)),r.readAsDataURL(e)})}async function l(e,t){let n=await fetch(e,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(t)}),r=await n.json().catch(()=>({}));if(!n.ok||r.ok===!1)throw Error(r.error||`Request failed (${n.status})`);return r}function u({kind:e,name:t,description:a,preview:u,hasCustomIcon:d=!1,available:f=!0,modelLabel:p,layout:m=`panel`,onApply:h,onReset:g,generate:_,upload:v}){let[y,b]=(0,o.useState)(``),[x,S]=(0,o.useState)(null),[C,w]=(0,o.useState)(null),T=(0,o.useRef)(null),E=(0,o.useCallback)(async()=>{S(`generate`),w(null);try{await h(_?await _(y):await l(`/api/icons/generate`,{kind:e,name:t,description:a,direction:y}))}catch(e){w(e instanceof Error?e.message:String(e))}finally{S(null)}},[a,y,_,e,t,h]),D=(0,o.useCallback)(async e=>{S(`upload`),w(null);try{let t=await c(e);await h(v?await v(t):await l(`/api/icons/upload`,{dataUrl:t}))}catch(e){w(e instanceof Error?e.message:String(e))}finally{S(null)}},[h,v]),O=(0,o.useCallback)(async()=>{if(g){S(`reset`),w(null);try{await g()}catch(e){w(e instanceof Error?e.message:String(e))}finally{S(null)}}},[g]),k=(0,s.jsxs)(`div`,{className:`min-w-0`,children:[(0,s.jsxs)(`label`,{className:`text-[11px] font-semibold text-slate-700 dark:text-terminal-text`,htmlFor:`icon-studio-direction-${e}-${t}`,children:[`Creative direction `,(0,s.jsx)(`span`,{className:`font-normal text-slate-400`,children:`· optional`})]}),(0,s.jsx)(`textarea`,{id:`icon-studio-direction-${e}-${t}`,value:y,onChange:e=>b(e.target.value),rows:2,maxLength:1200,placeholder:`Example: a compass finding a clear path through scattered notes`,className:`mt-1.5 w-full resize-none rounded-xl border border-slate-200 bg-white px-3 py-2.5 text-[12.5px] leading-relaxed text-slate-800 outline-none transition-colors placeholder:text-slate-400 focus:border-slate-400 dark:border-terminal-border dark:bg-terminal-bg dark:text-terminal-text dark:placeholder:text-terminal-muted/60`}),(0,s.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-2`,children:[(0,s.jsxs)(`button`,{type:`button`,onClick:()=>void E(),disabled:!!x||!f,className:`inline-flex items-center gap-1.5 rounded-full bg-slate-950 px-3.5 py-2 text-[12px] font-semibold text-white transition-colors hover:bg-slate-800 disabled:cursor-not-allowed disabled:opacity-40 dark:bg-terminal-text dark:text-terminal-bg dark:hover:opacity-90`,children:[(0,s.jsx)(n,{className:`h-3.5 w-3.5`}),x===`generate`?`Creating icon…`:`Generate with AI`]}),(0,s.jsx)(`input`,{ref:T,type:`file`,accept:`image/png,image/jpeg,image/webp`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&D(t),e.target.value=``}}),(0,s.jsxs)(`button`,{type:`button`,onClick:()=>T.current?.click(),disabled:!!x,className:`inline-flex items-center gap-1.5 rounded-full border border-slate-200 bg-white px-3.5 py-2 text-[12px] font-medium text-slate-700 transition-colors hover:bg-slate-100 disabled:opacity-40 dark:border-terminal-border dark:bg-terminal-bg dark:text-terminal-text dark:hover:bg-terminal-surface`,children:[(0,s.jsx)(r,{className:`h-3.5 w-3.5`}),x===`upload`?`Uploading…`:`Upload image`]}),d&&g?(0,s.jsxs)(`button`,{type:`button`,onClick:()=>void O(),disabled:!!x,className:`inline-flex items-center gap-1.5 rounded-full px-2.5 py-2 text-[12px] text-slate-500 transition-colors hover:bg-slate-100 hover:text-slate-800 disabled:opacity-40 dark:text-terminal-muted dark:hover:bg-terminal-surface dark:hover:text-terminal-text`,children:[(0,s.jsx)(i,{className:`h-3.5 w-3.5`}),`Use fallback`]}):null]}),(0,s.jsx)(`p`,{className:`mt-2 text-[10.5px] leading-relaxed text-slate-400 dark:text-terminal-muted/70`,children:f?`${p??`gpt-image-1-mini`} · low quality · one call only when you click · result saved across devices`:`AI generation is unavailable until OPENAI_API_KEY is configured. Uploads still work.`}),C?(0,s.jsx)(`p`,{className:`mt-2 text-[11px] text-rose-500 dark:text-rose-300`,children:C}):null]});return m===`inline`?(0,s.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,s.jsx)(`div`,{className:`shrink-0`,children:u}),k]}):(0,s.jsxs)(`div`,{className:`grid gap-5 rounded-2xl border border-slate-200 bg-slate-50/60 p-4 sm:grid-cols-[104px_1fr] dark:border-terminal-border/60 dark:bg-terminal-surface/25`,children:[u,k]})}export{u as t};