import{k as _,C as a,l as n,t as d,x as c,n as s,A as w,u as m,z as v,D as V,g as b,a as C,e as x}from"./Button-1eZ2gOMK.js";import{X as U}from"./x-hWAaOc6e.js";import{L as N}from"./loader-circle-DBKQX_Iw.js";import{U as R}from"./upload-CyA7CNXl.js";const P=_("save",[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",key:"1c8476"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7",key:"1ydtos"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7",key:"t51u73"}]]),T={class:"space-y-2"},X={key:0,class:"flex flex-col gap-0.5"},E={key:0,class:"block text-sm font-medium text-zinc-700 dark:text-zinc-300"},F={key:1,class:"text-xs text-zinc-500 dark:text-zinc-400"},I={class:"flex flex-col items-stretch gap-2 rounded-xl border-2 border-dashed border-zinc-200 bg-zinc-50/50 p-4 dark:border-zinc-600 dark:bg-zinc-800/50"},M={key:0,class:"relative inline-block self-start"},B=["src"],D={class:"flex flex-wrap items-center gap-2"},L=["id","accept","disabled"],j=["for"],q={key:1,class:"text-sm font-medium text-red-600 dark:text-red-400"},W={__name:"ImageUpload",props:{modelValue:{type:String,default:""},uploadUrl:{type:String,required:!0},label:{type:String,default:"Imagem"},accept:{type:String,default:"image/*"},recommendedSize:{type:String,default:""}},emits:["update:modelValue"],setup(e,{emit:k}){const p=e,h=k,i=x(!1),l=x(""),g=b(()=>p.modelValue||null);function y(){const o=document.cookie.match(/XSRF-TOKEN=([^;]+)/);if(o)try{return decodeURIComponent(o[1])}catch{}return""}async function z(o){const r=o.target?.files?.[0];if(r){l.value="",i.value=!0;try{const t=new FormData;t.append("image",r);const{data:u}=await C.post(p.uploadUrl,t,{headers:{"X-XSRF-TOKEN":y(),Accept:"application/json","X-Requested-With":"XMLHttpRequest"},withCredentials:!0});h("update:modelValue",u.url||"")}catch(t){const u=t.response?.data?.message||t.response?.data?.errors?.image?.[0]||"Falha no envio. Tente outra imagem.";l.value=u}finally{i.value=!1,o.target.value=""}}}function S(){h("update:modelValue",""),l.value=""}const f=b(()=>`img-upload-${Math.random().toString(36).slice(2)}`);return(o,r)=>(a(),n("div",T,[e.label||e.recommendedSize?(a(),n("div",X,[e.label?(a(),n("label",E,d(e.label),1)):c("",!0),e.recommendedSize?(a(),n("p",F," Tamanho ideal: "+d(e.recommendedSize),1)):c("",!0)])):c("",!0),s("div",I,[g.value?(a(),n("div",M,[s("img",{src:g.value,alt:"Preview",class:"max-h-32 rounded-lg object-contain",onError:r[0]||(r[0]=t=>t?.target&&(t.target.style.display="none"))},null,40,B),s("button",{type:"button",class:"absolute -right-2 -top-2 flex h-6 w-6 items-center justify-center rounded-full bg-red-500 text-white shadow transition hover:bg-red-600","aria-label":"Remover imagem",onClick:S},[w(m(U),{class:"h-3.5 w-3.5"})])])):c("",!0),s("div",D,[s("input",{id:f.value,type:"file",accept:e.accept,class:"hidden",disabled:i.value,onChange:z},null,40,L),s("label",{for:f.value,class:"inline-flex cursor-pointer items-center gap-2 rounded-xl border-2 border-zinc-200 bg-white px-4 py-2.5 text-sm font-medium text-zinc-700 transition hover:border-zinc-300 hover:bg-zinc-50 dark:border-zinc-600 dark:bg-zinc-800 dark:text-zinc-300 dark:hover:border-zinc-500 dark:hover:bg-zinc-700"},[i.value?(a(),v(m(N),{key:0,class:"h-4 w-4 animate-spin"})):(a(),v(m(R),{key:1,class:"h-4 w-4"})),V(" "+d(i.value?"Enviando…":"Subir imagem"),1)],8,j)]),l.value?(a(),n("p",q,d(l.value),1)):c("",!0)])]))}};export{P as S,W as _};
