import{l as v,H as S,o as n,c as u,a as t,g as I,h as B,n as _,d as C,t as T,i as D,m as h}from"./BKiFavna.js";import{u as E}from"./BZ7f31ti.js";import{u as N}from"./DKzHUNYh.js";import{_ as R}from"./DlAUqK2U.js";const j={class:"img-uploader"},z={class:"url-row"},A=["placeholder"],H=["accept","disabled"],L={key:0,class:"preview"},$=["src"],F={key:1,class:"preview-error"},M={__name:"ImageUploader",props:{modelValue:{type:String,default:""},endpoint:{type:String,default:"/admin/upload/post-image"},accept:{type:String,default:"image/*"},placeholder:{type:String,default:"Image URL or upload below"}},emits:["update:modelValue"],setup(i,{emit:y}){const d=i,b=y,{baseURL:f,token:U}=E(),c=N(),e=v(d.modelValue||""),l=v(!1),r=v(!1);S(()=>d.modelValue,s=>{e.value=s||"",r.value=!1});const w=h(()=>f.replace("/api","")),V=h(()=>e.value?/^(https?:)?\/\//i.test(e.value)||e.value.startsWith("data:")?e.value:w.value+e.value:""),p=()=>{b("update:modelValue",e.value),r.value=!1},k=()=>{e.value="",p()},x=async s=>{const a=s.target.files?.[0];if(!a)return;l.value=!0;const o=new FormData;o.append("file",a);try{const m=await(await fetch(f+d.endpoint,{method:"POST",headers:{Authorization:`Bearer ${U.value}`},body:o})).json();m.success?(e.value=m.data.url,p(),c.success("Image uploaded")):c.error(m.message||"Upload failed")}catch(g){c.error("Upload failed: "+g.message)}finally{l.value=!1,s.target.value=""}};return(s,a)=>(n(),u("div",j,[t("div",z,[I(t("input",{"onUpdate:modelValue":a[0]||(a[0]=o=>e.value=o),type:"text",placeholder:i.placeholder,onInput:p},null,40,A),[[B,e.value]]),t("label",{class:_(["upload-btn",{uploading:l.value}])},[t("i",{class:_(l.value?"fas fa-spinner fa-spin":"fas fa-upload")},null,2),C(" "+T(l.value?"Uploading...":"Upload")+" ",1),t("input",{type:"file",onChange:x,accept:i.accept,disabled:l.value,style:{display:"none"}},null,40,H)],2)]),e.value?(n(),u("div",L,[r.value?(n(),u("div",F,"Image not found")):(n(),u("img",{key:0,src:V.value,onError:a[1]||(a[1]=o=>r.value=!0)},null,40,$)),t("button",{onClick:k,class:"clear-btn",title:"Remove"},[...a[2]||(a[2]=[t("i",{class:"fas fa-times"},null,-1)])])])):D("",!0)]))}},G=R(M,[["__scopeId","data-v-85bdc862"]]);export{G as _};
