import{A as e,_t as t,lt as a,n as r,yt as i}from"./render-cqdoDfd9.js";import{c as l}from"./Paper-DtiadJnq.js";import{t as n}from"./Button-D-nJohaT.js";import{t as o}from"./utils-C0ZHLGh_.js";var s=a(),p=l((0,s.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"}),"CloudUpload"),m=i(t(),1),c=({onUploadSuccess:t,onUploadError:a,initialUrl:i})=>{const[l,c]=(0,m.useState)(null),[d,f]=(0,m.useState)(i),{localeMessages:g,direction:u,apiBaseUrl:h}=r();(0,m.useEffect)(()=>{f(i)},[i]);(0,m.useEffect)(()=>{l&&fetch(`${h}/organizations/1/file/`,{method:"POST",headers:{"X-CSRFToken":o("csrftoken")},body:(()=>{const e=new FormData;return e.append("file",l),e})()}).then(e=>{if(!e.ok)throw new Error("File upload failed");return e.json()}).then(e=>{t(e),f(e.file_url)}).catch(e=>{a(e)})},[l]);const x=e("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(0,s.jsx)(s.Fragment,{children:d?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("img",{src:d,alt:g.uploaded_image_alt,style:{marginTop:"10px",maxHeight:"100px"}}),(0,s.jsx)("br",{}),(0,s.jsx)(n,{variant:"text",color:"primary",onClick:()=>{f(null),c(null),t({file_url:null,file_path:null})},children:g.remove_image})]}):(0,s.jsxs)(n,{component:"label",role:void 0,variant:"contained",tabIndex:-1,startIcon:(0,s.jsx)(p,{sx:{marginLeft:"rtl"===u?1:0}}),sx:{textAlign:"rtl"===u?"right":"left",mt:2,mb:2},dir:u,children:[g.upload_button_label,(0,s.jsx)(x,{type:"file",accept:"image/png,image/jpeg,image/gif,image/bmp,image/svg+xml,image/tiff,image/avif",onChange:e=>{const t=e.target.files?.[0];if(!t)return;const r=t.type.startsWith("image/"),i="image/webp"===t.type||t.name.toLowerCase().endsWith(".webp");if(!r||i)return e.target.value="",void(a&&a(new Error("Only non-WebP image files are allowed.")));c(t)}})]})})};export{c as t};