import{bq as L,br as W,a9 as q,r as g,a as H,j as r,B as o,b as t,s as l,ar as R,o as D,cG as $,H as j,C as G,cc as O}from"./index-BiWH3VAt.js";import{u as K,A as J,d as Q,I as V,a as X}from"./useLightbox-C5pWGmOD.js";import{b as Y}from"./motionPrimitives-BbwRYaF9.js";import{u as Z,a as ee}from"./FileUploadApi-CnXxWhfT.js";var b={},te=L;Object.defineProperty(b,"__esModule",{value:!0});var S=b.default=void 0,ae=te(W()),re=q;S=b.default=(0,ae.default)((0,re.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.96M19 18H6c-2.21 0-4-1.79-4-4 0-2.05 1.53-3.76 3.56-3.97l1.07-.11.5-.95C8.08 7.14 9.94 6 12 6c2.62 0 4.88 1.86 5.39 4.43l.3 1.5 1.53.11c1.56.1 2.78 1.41 2.78 2.96 0 1.65-1.35 3-3 3M8 13h2.55v3h2.9v-3H16l-4-4z"}),"CloudUploadOutlined");function pe({productName:p,variantSummary:d,images:u,artDesignId:x,productId:oe,readOnly:f=!1,onChange:h,onRemove:y}){const v=g.useRef(null),[s,U]=g.useState(!1),[n,m]=g.useState(!1),[N]=Z(),[T]=ee(),{openSnackbar:w}=H(),{lightboxProps:z,openAt:A}=K(),E=x?`art-design/${x}`:"art-design/temp",C=async e=>{if(!(!e||e.length===0)){U(!0);try{const a=[];for(const i of Array.from(e)){const P=i.type||"application/octet-stream",k=await N({filename:i.name,keyPrefix:E,contentType:P});if("error"in k)throw new Error("Failed to get upload URL");const{s3Key:F,uploadUrl:I,contentType:B}=k.data;if(I&&!(await fetch(I,{method:"PUT",body:i,headers:{"Content-Type":B||P}})).ok)throw new Error("File upload failed");const c=await T({s3Key:F,fileName:i.name,contentType:i.type||"application/octet-stream"});if("error"in c)throw new Error("Failed to register uploaded file");a.push({imagePathId:c.data.id,publicUrl:c.data.publicUrl,fileName:c.data.fileName,status:"PENDING"})}h==null||h([...u,...a]),w(`${a.length} image(s) uploaded`,"success")}catch(a){w((a==null?void 0:a.message)||"Upload failed","error")}finally{U(!1)}}},_=e=>{e.preventDefault(),m(!1),!(f||s)&&C(e.dataTransfer.files)},M=u.filter(e=>e.previewUrl||e.publicUrl).map(e=>({src:e.previewUrl||e.publicUrl,fileName:e.fileName,status:e.status}));return r(o,{sx:{mb:p?2:0},children:[p&&t(l,{variant:"subtitle2",fontWeight:700,mb:d?.25:1,children:p}),d&&t(l,{variant:"caption",color:"text.secondary",display:"block",mb:1,children:d}),r(o,{sx:{display:"flex",flexWrap:"wrap",gap:1.25,alignItems:"flex-start"},children:[t(J,{initial:!1,children:u.map((e,a)=>r(Y,{layout:!0,initial:{opacity:0,scale:.8},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.8},transition:{duration:.18},sx:{position:"relative",width:116,borderRadius:2,overflow:"hidden",bgcolor:"background.paper",border:"1px solid",borderColor:"divider",boxShadow:"0 1px 4px rgba(0,0,0,0.06)","&:hover .overlay":{opacity:1}},children:[r(o,{sx:{position:"relative",height:90,bgcolor:"#f4f6f8"},children:[t(o,{component:"img",src:e.previewUrl||e.publicUrl,alt:e.fileName,sx:{width:"100%",height:"100%",objectFit:"cover",display:"block"},onError:i=>{i.target.style.visibility="hidden"}}),r(o,{className:"overlay",sx:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",gap:.5,bgcolor:"rgba(15,20,28,0.45)",opacity:0,transition:"opacity .18s"},children:[t(R,{title:"Preview",children:t(D,{size:"small",onClick:()=>A(M,a),sx:{bgcolor:"rgba(255,255,255,0.9)","&:hover":{bgcolor:"#fff"}},children:t(Q,{fontSize:"small"})})}),!f&&y&&t(R,{title:"Remove",children:t(D,{size:"small",onClick:()=>y(a),sx:{bgcolor:"rgba(255,255,255,0.9)",color:"#c62828","&:hover":{bgcolor:"#ffebee"}},children:t($,{fontSize:"small"})})})]})]}),r(o,{sx:{p:.75},children:[t(l,{variant:"caption",noWrap:!0,display:"block",title:e.fileName,sx:{fontWeight:500},children:e.fileName}),e.status&&t(o,{mt:.5,children:t(V,{status:e.status,compact:!0})})]})]},e.id??e.imagePathId??a))}),!f&&t(o,{onClick:()=>{var e;return!s&&((e=v.current)==null?void 0:e.click())},onDragOver:e=>{e.preventDefault(),n||m(!0)},onDragLeave:e=>{e.preventDefault(),m(!1)},onDrop:_,sx:{width:116,minHeight:122,px:1,borderRadius:2,border:"2px dashed",borderColor:n?"primary.main":"#c3ccd6",bgcolor:n?"rgba(21,101,192,0.06)":"transparent",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",textAlign:"center",cursor:s?"default":"pointer",color:n?"primary.main":"text.secondary",transition:"all .18s","&:hover":{borderColor:"primary.main",color:"primary.main"}},children:s?r(j,{children:[t(G,{size:26}),t(l,{variant:"caption",mt:1,children:"Uploading…"})]}):r(j,{children:[t(S,{sx:{fontSize:30,color:"primary.main",mb:.5}}),t(l,{variant:"caption",fontWeight:600,children:"Drop or click"}),t(l,{variant:"caption",sx:{fontSize:10,opacity:.75},children:"to add images"})]})})]}),s&&t(O,{sx:{mt:1,borderRadius:1}}),t("input",{ref:v,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:e=>C(e.target.files)}),t(X,{...z})]})}export{pe as P};
