import{d as h,j as t,r as l,n as x,s as j}from"./render-BEL5IN7j.js";import{g as I}from"./utils-MPtJ5ynp.js";import{B as m}from"./Button-CGPZXh3G.js";const b=h(t.jsx("path",{d:"M19.35 10.04C18.67 6.59 15.64 4 12 4 9.11 4 6.6 5.64 5.35 8.04 2.34 8.36 0 10.91 0 14c0 3.31 2.69 6 6 6h13c2.76 0 5-2.24 5-5 0-2.64-2.05-4.78-4.65-4.96M14 13v4h-4v-4H7l5-5 5 5z"})),_=({onUploadSuccess:i,onUploadError:p,initialUrl:o})=>{console.log("Rendering ImageUpload component with initialUrl:",o);const[n,c]=l.useState(null),[d,a]=l.useState(o),{localeMessages:r,direction:s,apiBaseUrl:g}=x();l.useEffect(()=>{a(o)},[o]);const u=()=>{a(null),c(null),i({file_url:null,file_path:null})};l.useEffect(()=>{n&&fetch(`${g}/organizations/1/file/`,{method:"POST",headers:{"X-CSRFToken":I("csrftoken")},body:(()=>{const e=new FormData;return e.append("file",n),e})()}).then(e=>{if(!e.ok)throw new Error("File upload failed");return e.json()}).then(e=>{console.log("File uploaded successfully:",e),i(e),a(e.file_url)}).catch(e=>{console.error("Error uploading file:",e),p(e)})},[n]);const f=j("input")({clip:"rect(0 0 0 0)",clipPath:"inset(50%)",height:1,overflow:"hidden",position:"absolute",bottom:0,left:0,whiteSpace:"nowrap",width:1});return t.jsx(t.Fragment,{children:d?t.jsxs(t.Fragment,{children:[t.jsx("img",{src:d,alt:r.uploaded_image_alt,style:{marginTop:"10px",maxHeight:"100px"}}),t.jsx("br",{}),t.jsx(m,{variant:"text",color:"secondary",onClick:u,children:r.remove_image})]}):t.jsxs(m,{component:"label",role:void 0,variant:"contained",tabIndex:-1,startIcon:t.jsx(b,{sx:{marginLeft:s==="rtl"?1:0}}),sx:{textAlign:s==="rtl"?"right":"left",mt:2,mb:2},dir:s,children:[r.upload_button_label,t.jsx(f,{type:"file",onChange:e=>c(e.target.files[0])})]})})};export{_ as I};
//# sourceMappingURL=ImageUpload-D-S9cmVu.js.map
