import{r as e,t}from"./jsx-runtime-DGeXAQPT.js";import{H as n}from"./link-BEigRx5R.js";import{t as r}from"./loader-circle-CnOnp3Jr.js";import{d as i,u as a,v as o}from"./index-BFZg1haX.js";var s=o(`cloud-upload`,[[`path`,{d:`M12 13v8`,key:`1l5pq0`}],[`path`,{d:`M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242`,key:`1pljnt`}],[`path`,{d:`m8 17 4-4 4 4`,key:`1quai1`}]]),c=e(n(),1),l=t(),u=c.forwardRef(({className:e,...t},n)=>(0,l.jsx)(`textarea`,{className:i(`flex min-h-[60px] w-full rounded-md border border-input bg-transparent px-3 py-2 text-base shadow-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm`,e),ref:n,...t}));u.displayName=`Textarea`;function d({value:e,onChange:t,className:n}){let[i,o]=(0,c.useState)(!1),u=(0,c.useRef)(null);return(0,l.jsxs)(`div`,{className:`flex items-center gap-3 ${n||``}`,children:[(0,l.jsx)(`input`,{type:`file`,accept:`image/jpeg, image/png, image/webp, image/gif`,className:`hidden`,ref:u,onChange:async e=>{let n=e.target.files?.[0];if(!n)return;o(!0);let r=new FormData;r.append(`file`,n);try{let e=await(await fetch(`/api/upload.php`,{method:`POST`,body:r})).json();e.success&&e.url?t(e.url):alert(e.error||`Upload failed`)}catch(e){console.error(e),alert(`An error occurred during upload.`)}finally{o(!1),u.current&&(u.current.value=``)}}}),(0,l.jsxs)(a,{type:`button`,variant:`outline`,size:`sm`,disabled:i,onClick:()=>u.current?.click(),className:`text-xs h-8`,children:[i?(0,l.jsx)(r,{className:`w-4 h-4 mr-1.5 animate-spin`}):(0,l.jsx)(s,{className:`w-4 h-4 mr-1.5`}),e?`Change Image`:`Upload Image`]})]})}export{u as n,d as t};