import{i as w,j as t,r as o,u as I,s as v}from"./render-D1ZqzUbP.js";import{g as y}from"./utils-VIUIl18e.js";import{B as f}from"./Button-DJ_uYab0.js";const F=w(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"})),E=({onUploadSuccess:m,onUploadError:l,initialUrl:i})=>{console.log("Rendering ImageUpload component with initialUrl:",i);const[n,g]=o.useState(null),[p,s]=o.useState(i),{localeMessages:r,direction:c,apiBaseUrl:u}=I();o.useEffect(()=>{s(i)},[i]);const d=()=>{s(null),g(null),m({file_url:null,file_path:null})};o.useEffect(()=>{n&&fetch(`${u}/organizations/1/file/`,{method:"POST",headers:{"X-CSRFToken":y("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),m(e),s(e.file_url)}).catch(e=>{console.error("Error uploading file:",e),l(e)})},[n]);const h=e=>{const a=e.target.files?.[0];if(!a)return;const b=a.type.startsWith("image/"),j=a.type==="image/webp"||a.name.toLowerCase().endsWith(".webp");if(!b||j){e.target.value="",l&&l(new Error("Only non-WebP image files are allowed."));return}g(a)},x=v("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:p?t.jsxs(t.Fragment,{children:[t.jsx("img",{src:p,alt:r.uploaded_image_alt,style:{marginTop:"10px",maxHeight:"100px"}}),t.jsx("br",{}),t.jsx(f,{variant:"text",color:"primary",onClick:d,children:r.remove_image})]}):t.jsxs(f,{component:"label",role:void 0,variant:"contained",tabIndex:-1,startIcon:t.jsx(F,{sx:{marginLeft:c==="rtl"?1:0}}),sx:{textAlign:c==="rtl"?"right":"left",mt:2,mb:2},dir:c,children:[r.upload_button_label,t.jsx(x,{type:"file",accept:"image/png,image/jpeg,image/gif,image/bmp,image/svg+xml,image/tiff,image/avif",onChange:h})]})})};export{E as I};
//# sourceMappingURL=ImageUpload-IdvFym3o.js.map
