1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[7563],{67563:function(e,l,i){i.d(l,{Z:function(){return A}});var t=i(57437),n=i(2265),o=i(2069),r=i(46387),d=i(19643),a=i(98527),u=i(84955),s=i(9871),c=i(7261),f=i(67136),v=i(35341),p=i(58371),m=i(54755),y=i(13435),h=i(4604),g=i(17162),x=i(99518),b=i(56617),I=i(77713),k=i(68380),w=i(3173);function S(e){let{expanded:l}=e;return(0,t.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",xmlns:"http://www.w3.org/2000/svg",style:{transform:l?"rotate(180deg)":"rotate(0deg)",transition:"transform 0.2s"},children:(0,t.jsx)("path",{d:"M3 5L7 9L11 5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}function F(e){var l;let{deliverable:i,onUnlink:d,onDownload:a,onRename:u,onUploadFiles:s,onUnlinkFile:c,uploadingFiles:f=[],onRemoveUpload:v,onRetryUpload:p}=e,m=null==i?void 0:i.collection,F=(null==m?void 0:m.files)||[],[C,D]=(0,n.useState)(!1),[j,E]=(0,n.useState)(null),[R,A]=(0,n.useState)(!1),[L,U]=(0,n.useState)((null==m?void 0:m.name)||""),Z=(0,n.useRef)(null);(0,n.useEffect)(()=>{if(!C||!(null==m?void 0:m.id)||F.length>0||j)return;let e=!1;return(0,w.M7)(m.id).then(l=>{var i;if(e)return;let t=(null===(i=l.data)||void 0===i?void 0:i.data)||l.data;E((null==t?void 0:t.files)||[])}).catch(()=>{}),()=>{e=!0}},[C,null==m?void 0:m.id,F.length,j]);let _=F.length>0?F:j||[],T=(0,n.useRef)(f.length);(0,n.useEffect)(()=>{T.current>0&&0===f.length&&N(),T.current=f.length},[f.length]);let N=()=>{(null==m?void 0:m.id)&&(0,w.M7)(m.id).then(e=>{var l;let i=(null===(l=e.data)||void 0===l?void 0:l.data)||e.data;E((null==i?void 0:i.files)||[])}).catch(()=>{})};(0,n.useEffect)(()=>{U((null==m?void 0:m.name)||"")},[null==m?void 0:m.name]),(0,n.useEffect)(()=>{var e;R&&(null===(e=Z.current)||void 0===e||e.focus())},[R]);let P=null!==(l=null==m?void 0:m.fileCount)&&void 0!==l?l:_.length,B=null==m?void 0:m.totalSizeBytes,O=[null!=P?"".concat(P," Files"):null,null!=B?(0,k.td)(B):null].filter(Boolean).join(" ⢠");return(0,t.jsxs)(o.Z,{sx:{background:"var(--lv-bg-card)",borderRadius:"22px",outline:"1px var(--lv-border-default) solid",overflow:"hidden"},children:[(0,t.jsxs)(o.Z,{sx:{display:"flex",alignItems:"center",gap:"10px",px:"20px",py:"12px"},children:[(0,t.jsx)(o.Z,{sx:{flexShrink:0},children:(0,t.jsx)(b.Z,{isCollection:!0,mode:"digital",collectionCoverUrl:null==m?void 0:m.coverThumbnailUrl})}),(0,t.jsxs)(o.Z,{sx:{flex:1,minWidth:0},children:[R?(0,t.jsx)("input",{ref:Z,value:L,onChange:e=>U(e.target.value),onBlur:()=>{A(!1);let e=L.trim();e&&e!==(null==m?void 0:m.name)?null==u||u(null==m?void 0:m.id,e):U((null==m?void 0:m.name)||"")},onKeyDown:e=>{var l;"Enter"===e.key&&(null===(l=Z.current)||void 0===l||l.blur()),"Escape"===e.key&&(U((null==m?void 0:m.name)||""),A(!1))},style:{fontSize:"14px",fontWeight:500,color:"var(--lv-text-primary)",background:"var(--lv-bg-elevated)",border:"1px solid var(--lv-border-strong)",borderRadius:"8px",padding:"2px 8px",outline:"none",width:"100%",maxWidth:"240px"}}):(0,t.jsx)(o.Z,{onClick:()=>A(!0),sx:{display:"inline-flex",alignItems:"center",px:"10px",py:"3px",bgcolor:"var(--lv-bg-elevated)",borderRadius:"10px",cursor:"text",maxWidth:"100%","&:hover":{bgcolor:"var(--lv-bg-hover)"}},children:(0,t.jsx)(r.Z,{noWrap:!0,sx:{fontSize:"14px",fontWeight:500,color:"var(--lv-text-primary)"},children:L||"Collection"})}),(0,t.jsx)(o.Z,{sx:{display:"flex",alignItems:"center",gap:"6px",mt:"3px"},children:O&&(0,t.jsx)(r.Z,{sx:{fontSize:"12px",color:"var(--lv-text-tertiary)"},children:O})})]}),(0,t.jsxs)(o.Z,{sx:{display:"flex",alignItems:"center",gap:"8px",flexShrink:0},onClick:e=>e.stopPropagation(),children:[(0,t.jsx)(I.Z,{onDelete:()=>null==d?void 0:d(null==i?void 0:i.id),onDownload:()=>null==a?void 0:a(null==m?void 0:m.id),deleteTooltip:"Remove collection",downloadTooltip:"Download collection"}),(0,t.jsx)(o.Z,{component:"button",onClick:()=>D(e=>!e),sx:{border:"none",bgcolor:"transparent",cursor:"pointer",display:"flex",alignItems:"center",p:"4px",borderRadius:"6px","&:hover":{bgcolor:"var(--lv-bg-hover)"}},children:(0,t.jsx)(S,{expanded:C})})]})]}),(0,t.jsx)(g.Z,{in:C,children:(0,t.jsxs)(o.Z,{sx:{px:"16px",pb:"16px",display:"flex",flexDirection:"column",gap:"8px"},children:[(0,t.jsx)(y.Z,{onFilesSelected:e=>null==s?void 0:s(e,null==m?void 0:m.id)}),(0,t.jsx)(h.Z,{uploadingFiles:f,onRemove:v,onRetry:p}),_.map(e=>(0,t.jsx)(x.Z,{file:e,mode:"digital",showInfoTooltip:!1,onDelete:()=>{null==c||c(null==m?void 0:m.id,e.id),E(l=>l?l.filter(l=>l.id!==e.id):l)},hideDownload:!0},e.id))]})})]})}var C=i(18660),D=i(67326);function j(e){let{deliverable:l,onDelete:i}=e;return(0,t.jsx)(x.Z,{isLink:!0,link:l,mode:"digital",onDelete:i})}var E=i(1974),R=i(21328);function A(e){var l;let{listingId:i,onFilesChanged:g,onPayloadGetterReady:b,onResetReady:I,onRetireOpsReady:k,onReplaceReady:w,onHasPendingChanged:S,onPendingDeliverablesChanged:A,onPendingEtsyRemovalsChanged:L,onRefreshPreview:U,onEtsyOnlyFilesChanged:Z,onPresetSnapshotReady:_,initialParentFolder:T=null,initialDeliverables:N=null,initialDigitalDesignFiles:P=[],onDigitalDesignFilesChanged:B,onUploadingChange:O}=e,W=(0,n.useRef)(null),z=(0,n.useRef)(null),M=(0,n.useRef)(new Set),J=(0,n.useCallback)(e=>{var l,i;null===(l=z.current)||void 0===l||l.call(z),c.Am.info("Your selected folder no longer exists â uploading to your library root instead."),null===(i=W.current)||void 0===i||i.call(W,[e],null)},[]),{collections:q,standaloneFiles:K,standaloneLinks:G,digitalFiles:Q,uploadingFiles:Y,isLoading:H,isFetching:V,refetch:X,resetPendingOps:$,retirePublishedOps:ee,markAllForRemoval:el,uploadAndLink:ei,uploadToCollection:et,removeUploadingFile:en,retryUpload:eo,unlinkDeliverable:er,unlinkFileFromCollection:ed,deleteEtsyFile:ea,renameCollection:eu,downloadCollection:es,downloadFile:ec,addPendingDeliverable:ef,getDigitalFilesPayload:ev,getDeliverablesSnapshot:ep,hasPendingChanges:em,pendingDeliverables:ey,pendingEtsyRemovals:eh}=(0,v.eo)(i,g,{onParentUploadFailed:J,initialDeliverables:N});W.current=ei,(0,n.useEffect)(()=>{null==b||b(ev)},[ev]),(0,n.useEffect)(()=>{null==I||I(()=>{$(),X()})},[I,$,X]),(0,n.useEffect)(()=>{null==k||k(e=>ee(e))},[k,ee]),(0,n.useEffect)(()=>{null==w||w(()=>el())},[w,el]),(0,n.useEffect)(()=>{null==S||S(em)},[em]),(0,n.useEffect)(()=>{null==A||A(ey)},[ey]),(0,n.useEffect)(()=>{null==L||L(eh)},[eh]);let eg=Y.some(e=>"uploading"===e.status||"retrying"===e.status);(0,n.useEffect)(()=>{null==O||O(eg)},[eg]),(0,n.useEffect)(()=>{null==Z||Z(Q)},[Q]);
1let[ex,eb]=(0,n.useState)([]),eI=(0,n.useRef)(0);(0,n.useEffect)(()=>{let e=Array.isArray(P)?P:[],l=[...new Set(e.map(e=>{var l;return null!==(l=e.asset_file_id)&&void 0!==l?l:e.assetFileId}).filter(Boolean))];if(!l.length){eI.current+=1,eb(e=>e.length?[]:e);return}let i=eI.current+=1;Promise.allSettled(l.map(e=>(0,a.hn)(e))).then(t=>{if(i!==eI.current)return;let n=[];t.forEach((i,t)=>{var o,r,d,u,s,c,f,v,p,m,y,h;if("fulfilled"!==i.status)return;let g=l[t],x=null!==(s=null!==(u=null===(r=i.value)||void 0===r?void 0:null===(o=r.data)||void 0===o?void 0:o.data)&&void 0!==u?u:null===(d=i.value)||void 0===d?void 0:d.data)&&void 0!==s?s:null;if(!x)return;let b=e.find(e=>{var l;return(null!==(l=e.asset_file_id)&&void 0!==l?l:e.assetFileId)===g}),I=null==b?void 0:b.file_name,k=(0,a.G_)(x);n.push({id:"preset-digital-".concat(g),assetFileId:g,file:{...k,id:null!==(c=k.id)&&void 0!==c?c:g,originalFilename:null!==(p=null!==(v=null!==(f=k.originalFilename)&&void 0!==f?f:k.fileName)&&void 0!==v?v:I)&&void 0!==p?p:"File",fileName:null!==(h=null!==(y=null!==(m=k.fileName)&&void 0!==m?m:k.originalFilename)&&void 0!==y?y:I)&&void 0!==h?h:"File"}})}),eb(n)})},[i,P]);let ek=e=>{eb(l=>l.filter(l=>l.assetFileId!==e));let l=(Array.isArray(P)?P:[]).filter(l=>{var i;return(null!==(i=l.asset_file_id)&&void 0!==i?i:l.assetFileId)!==e});null==B||B(l)},ew=new Set(K.map(e=>{var l,i;return null!==(i=e.fileId)&&void 0!==i?i:null===(l=e.file)||void 0===l?void 0:l.id}).filter(Boolean)),eS=i?ex.filter(e=>!ew.has(e.assetFileId)):[],[eF,eC]=(0,n.useState)(0),eD=e=>{if(!e.length)return;let l=Array.isArray(P)?P:[],i=[...l];for(let l of e){var t;(null==l?void 0:l.asset_file_id)&&(i.some(e=>{var i;return(null!==(i=e.asset_file_id)&&void 0!==i?i:e.assetFileId)===l.asset_file_id})||i.push({asset_file_id:l.asset_file_id,is_enabled:!0,file_name:null!==(t=l.file_name)&&void 0!==t?t:"File"}))}i.length!==l.length&&(null==B||B(i))},ej=async e=>{let l=Array.from(e||[]);if(!l.length)return;eC(e=>e+l.length);let{items:i}=(0,u.SP)(l,{transport:"asset",surface:"digital-files"});eD((await Promise.all(i.map(async e=>{let{file:l,promise:i}=e;try{var t,n,o;let e=await i,r=null!==(t=null==e?void 0:e.row)&&void 0!==t?t:null;if(null==r?void 0:r.id)return{asset_file_id:r.id,file_name:null!==(o=null!==(n=r.originalFilename)&&void 0!==n?n:r.fileName)&&void 0!==o?o:l.name};if(null==e?void 0:e.cancelled)return null;if((null==e?void 0:e.errorReason)==="unconfirmed")return c.Am.warn('"'.concat(l.name,'": ').concat(e.error)),null;return c.Am.error((null==e?void 0:e.error)?'Failed to upload "'.concat(l.name,'": ').concat(e.error):'Upload of "'.concat(l.name,'" did not return a file id.')),null}catch(e){return c.Am.error('Failed to upload "'.concat(l.name,'".')),null}finally{eC(e=>Math.max(0,e-1))}}))).filter(Boolean))},eE=e=>{var l,i,t,n,o,r,d,a,u,s,f,v;let p=null!==(s=null!==(u=null==e?void 0:null===(l=e.payload)||void 0===l?void 0:l.fileId)&&void 0!==u?u:null==e?void 0:null===(t=e.tempDeliverable)||void 0===t?void 0:null===(i=t.file)||void 0===i?void 0:i.id)&&void 0!==s?s:null==e?void 0:null===(n=e.tempDeliverable)||void 0===n?void 0:n.fileId;if(!p){c.Am.info("Only files can be added as preset design files.");return}eD([{asset_file_id:p,file_name:null!==(v=null!==(f=null==e?void 0:null===(r=e.tempDeliverable)||void 0===r?void 0:null===(o=r.file)||void 0===o?void 0:o.originalFilename)&&void 0!==f?f:null==e?void 0:null===(a=e.tempDeliverable)||void 0===a?void 0:null===(d=a.file)||void 0===d?void 0:d.fileName)&&void 0!==v?v:"File"}])},eR=e=>{var l,i,t,n,o,r;let d=null==e?void 0:e.type;if("addCollection"===d){let r=null!==(o=null!==(n=null==e?void 0:null===(l=e.payload)||void 0===l?void 0:l.collectionId)&&void 0!==n?n:null==e?void 0:null===(t=e.tempDeliverable)||void 0===t?void 0:null===(i=t.collection)||void 0===i?void 0:i.id)&&void 0!==o?o:null;if(null==r||q.some(e=>{var l,i;return(null!==(i=null===(l=e.collection)||void 0===l?void 0:l.id)&&void 0!==i?i:e.collectionId)===r}))return}else if("addLink"===d){let l=null==e?void 0:null===(r=e.tempDeliverable)||void 0===r?void 0:r.id;if(l&&G.some(e=>e.id===l))return}ef({type:d,...e.payload},e.tempDeliverable)}
1,[eA,eL]=(0,n.useState)(!1),[eU,eZ]=(0,n.useState)(!1),[e_,eT]=(0,n.useState)(""),[eN,eP]=(0,n.useState)(!1),[eB,eO]=(0,n.useState)(!1),[eW,ez]=(0,n.useState)(""),[eM,eJ]=(0,n.useState)(""),[eq,eK]=(0,n.useState)(T),eG=null!==(l=null==eq?void 0:eq.id)&&void 0!==l?l:null;z.current=()=>eK(null),(0,n.useEffect)(()=>{eK(T||null)},[null==T?void 0:T.id]);let eQ=(0,n.useRef)({getDeliverablesSnapshot:ep,parentFolder:eq});eQ.current={getDeliverablesSnapshot:ep,parentFolder:eq},(0,n.useEffect)(()=>{_&&_(()=>{var e,l,i,t;return{parentCollectionId:null!==(i=null===(e=eQ.current.parentFolder)||void 0===e?void 0:e.id)&&void 0!==i?i:null,parentCollectionName:null!==(t=null===(l=eQ.current.parentFolder)||void 0===l?void 0:l.name)&&void 0!==t?t:null,deliverables:eQ.current.getDeliverablesSnapshot()}})},[_]);let eY=()=>{let e=eW.trim();if(!e)return;let l=eM.trim(),i={id:"pending-url-".concat(Date.now()),type:"link",url:e,label:l||e,linkUrl:e,linkLabel:l,_isPending:!0};ef({type:"addUrl",linkUrl:e,linkLabel:l},i),eO(!1),ez(""),eJ("")},[eH,eV]=(0,n.useState)(null),eX=function(e){let l=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"This will permanently remove the file.";return eV({action:e,message:l})},e$=async(e,l)=>{try{return await (0,p.Qy)(e,null!=l?l:null)}catch(t){var i;if(null!=l&&(null==t?void 0:null===(i=t.response)||void 0===i?void 0:i.status)===404)return eK(null),c.Am.info("Your selected folder no longer exists â creating in your library root instead."),await (0,p.Qy)(e,null);throw t}},e0=async e=>{let l=0;for(let[i,t]of e.entries()){if(null===i){ei(t,eG);continue}let{valid:e,skippedCount:n}=(0,m.dn)(t,null,262144e3);if(l+=n,0===e.length){c.Am.error('Folder "'.concat(i,'" contained no supported files â skipped.'));continue}try{let{id:l,created:t}=await e$(i,eG);if(!l){c.Am.error('Failed to create collection for "'.concat(i,'".'));continue}if(!q.some(e=>{var i,t;return(null!==(t=null===(i=e.collection)||void 0===i?void 0:i.id)&&void 0!==t?t:e.collectionId)===l})){let e={id:"pending-coll-".concat(l),type:"collection",collection:{id:l,name:i,files:[]},_isPending:!0};ef({type:"addCollection",collectionId:l,_sessionCreated:t},e)}M.current.has(l)||(M.current.add(l),et(e,l))}catch(e){c.Am.error('Failed to create collection for "'.concat(i,'".'))}}l>0&&c.Am.info("".concat(l," file").concat(1!==l?"s":""," skipped (too large)."))},e1=async()=>{let e=e_.trim();if(e){eP(!0);try{let{id:l,created:i}=await e$(e,eG);l&&!q.some(e=>{var i,t;return(null!==(t=null===(i=e.collection)||void 0===i?void 0:i.id)&&void 0!==t?t:e.collectionId)===l})&&ef({type:"addCollection",collectionId:l,_sessionCreated:i},{id:"pending-coll-".concat(l),type:"collection",collection:{id:l,name:e,files:[]},_isPending:!0}),eZ(!1),eT("")}catch(e){}finally{eP(!1)}}};return H?(0,t.jsx)(o.Z,{sx:{display:"flex",justifyContent:"center",py:4},children:(0,t.jsx)(s.D8,{size:28,sx:{color:"var(--lv-brand)"}})}):(0,t.jsxs)(o.Z,{sx:{position:"relative",display:"flex",flexDirection:"column",gap:"8px"},children:[(0,t.jsx)(R.Z,{}),V&&(0,t.jsx)(o.Z,{sx:{position:"absolute",inset:0,zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",bgcolor:"var(--lv-backdrop)",borderRadius:"22px"},children:(0,t.jsx)(s.D8,{size:28,sx:{color:"var(--lv-brand)"}})}),(0,t.jsx)(y.Z,{onFilesSelected:i?e=>ei(e,eG):ej,onFolderDrop:e0,onBrowseLibrary:()=>eL(!0),onAddCollection:()=>{eT(""),eZ(!0)},onAddUrl:()=>{ez(""),eJ(""),eO(!0)},destinationSlot:(0,t.jsx)(D.Z,{parentFolder:eq,onSelect:e=>eK(e),onClear:()=>eK(null),tooltipTitle:eq?'Files uploaded to this listing are automatically added to the "'.concat(eq.name,'" collection.'):"Choose a collection to automatically add uploaded files to. By default they're added to your library root."})}),(0,t.jsx)(h.Z,{uploadingFiles:Y.filter(e=>{var l;return null!==(l=e.linkAsDeliverable)&&void 0!==l?l:!e.collectionId}),onRemove:en,onRetry:eo}),!i&&eF>0&&(0,t.jsxs)(o.Z,{sx:{display:"flex",alignItems:"center",gap:1,px:"14px",py:"10px"},children:[(0,t.jsx)(s.D8,{size:18,sx:{color:"var(--lv-brand)"}}),(0,t.jsxs)(o.Z,{component:"span",sx:{fontSize:"0.8rem",color:"var(--lv-text-secondary)"},children:["Uploading ",eF," file",1===eF?"":"s","â¦"]})]}),q.map(e=>(0,t.jsx)(F,{deliverable:e,onUnlink:e=>eX(()=>er(e),"This will remove the collection from this listing."),onDownload:es,onRename:eu,onUploadFiles:et,onUnlinkFile:(e,l)=>eX(()=>ed(e,l),"This will remove the file from the collection."),uploadingFiles:Y.filter(l=>{var i,t;return l.collectionId===(null===(i=e.collection)||void 0===i?void 0:i.id)&&!(null!==(t=l.linkAsDeliverable)&&void 0!==t?t:!l.collectionId)}),onRemoveUpload:en,onRetryUpload:eo},e.id)),(i?K:ex).map(e=>(0,t.jsx)(x.Z,{file:e.file,mode:"digital",showInfoTooltip:!1,onDelete:()=>i?eX(()=>er(e.id),"This will remove the file from this listing."):eX(()=>ek(e.assetFileId),"This will remove the design file from this preset."),onDownload:i?()=>{var l;return ec(null===(l=e.file)||void 0===l?void 0:l.id)}:void 0},e.id)),i&&eS.map(e=>(0,t.jsxs)(o.Z,{sx:{position:"relative"},children:[(0,t.jsx)(x.Z,{file:e.file,mode:"digital",showInfoTooltip:!1,onDelete:()=>eX(()=>ek(e.assetFileId),"This will remove the design from this listing's preset selection.")}),(0,t.jsx)(r.Z,{component:"span",sx:{position:"absolute",top:6,right:10,fontSize:10,fontWeight:600,color:"var(--lv-text-tertiary)",border:"1px solid var(--lv-border-default)",borderRadius:"6px",px:.75,py:"1px",bgcolor:"var(--lv-bg-elevated)",pointerEvents:"none"},children:"From preset"})]},"preset-".concat(e.assetFileId))),G.map(e=>(0,t.jsx)(j,{deliverable:e,onDelete:()=>eX(()=>er(e.id),"This will remove the link from this listing.")},e.id)),Q.map(e=>(0,t.jsx)(x.Z,{file:e,mode:"digital",showInfoTooltip:!1,isEtsyOnly:!e.hostedByListingView,onDelete:()=>eX(()=>{ea(e.id)},"This will remove the file from this listing.")},e.id)),(0,t.jsx)(E.Z,{open:!!eH,onClose:()=>eV(null),onConfirm:()=>{null==eH||eH.action(),eV(null)},title:"Remove",message:null==eH?void 0:eH.message,confirmText:"Remove",cancelText:"Cancel"}),(0,t.jsx)(C.Z,{open:eA,onClose:()=>eL(!1),listingId:i,alreadyLinkedFileIds:i?[...K.map(e=>{var l,i;return null!==(i=e.fileId)&&void 0!==i?i:null===(l=e.file)||void 0===l?void 0:l.id}),...ex.map(e=>
1e.assetFileId)].filter(Boolean):ex.map(e=>e.assetFileId).filter(Boolean),alreadyLinkedCollectionIds:q.map(e=>{var l,i;return null!==(i=e.collectionId)&&void 0!==i?i:null===(l=e.collection)||void 0===l?void 0:l.id}).filter(Boolean),alreadyLinkedLinkIds:G.map(e=>{var l,i;return null!==(i=e.linkId)&&void 0!==i?i:null===(l=e.link)||void 0===l?void 0:l.id}).filter(Boolean),onLinked:e=>{i?ef({type:e.type,...e.payload},e.tempDeliverable):(null==e?void 0:e.type)==="addFile"?eE(e):eR(e)}}),(0,t.jsx)(E.Z,{open:eU,onClose:()=>eZ(!1),onConfirm:e1,title:"Add a Collection",confirmText:"Create",loading:eN,confirmDisabled:!e_.trim(),fullWidth:!0,maxWidth:"xs",children:(0,t.jsx)(f.Z,{label:"Collection name",value:e_,onChange:eT,fullWidth:!0,sx:{mt:1},inputProps:{autoFocus:!0,onKeyDown:e=>{"Enter"===e.key&&e1()}}})}),(0,t.jsx)(E.Z,{open:eB,onClose:()=>eO(!1),onConfirm:eY,title:"Add URL",confirmText:"Add",confirmDisabled:!eW.trim(),fullWidth:!0,maxWidth:"xs",children:(0,t.jsxs)(d.Z,{spacing:2,sx:{mt:1},children:[(0,t.jsx)(f.Z,{label:"URL",placeholder:"https://example.com/file",value:eW,onChange:ez,fullWidth:!0,inputProps:{autoFocus:!0,onKeyDown:e=>{"Enter"===e.key&&eW.trim()&&eY()}}}),(0,t.jsx)(f.Z,{label:"Label (optional)",placeholder:"e.g. Download Guide",value:eM,onChange:eJ,fullWidth:!0,inputProps:{onKeyDown:e=>{"Enter"===e.key&&eW.trim()&&eY()}}})]})})]})}},35341:function(e,l,i){i.d(l,{eo:function(){return g},w8:function(){return h}});var t=i(2265),n=i(7261),o=i(4385),r=i(84955),d=i(3173),a=i(58371),u=i(98527),s=i(14206);let c="https://backend.listingview.io",f=0;function v(e){if(!e)return null;let l=null;return("addFile"===e.type&&e.fileId?l={fileId:e.fileId}:"addCollection"===e.type&&e.collectionId?l={collectionId:e.collectionId}:"addUrl"===e.type?l={linkUrl:e.linkUrl,...e.linkLabel?{linkLabel:e.linkLabel}:{}}:"addLink"===e.type&&e.linkId&&(l={linkId:e.linkId}),l)?{addEntry:l,identity:JSON.stringify(l)}:"removeDeliverable"===e.type&&null!=e.deliverableId?{removeDeliverableId:e.deliverableId,identity:JSON.stringify({removeDeliverable:e.deliverableId}),idempotent:!0}:"removeEtsyFile"===e.type&&null!=e.fileId?{removeEtsyFileId:e.fileId,identity:JSON.stringify({removeEtsyFile:e.fileId}),idempotent:!0}:null}let p=new Set(["queued","uploading","retrying"]),m=e=>p.has(null==e?void 0:e.status);function y(e){var l,i,t,n,o,r,d,a,u,s,c,f;if("collection"===e.type){let t=null!==(i=e.collectionId)&&void 0!==i?i:null===(l=e.collection)||void 0===l?void 0:l.id;return null!=t?{collectionId:t}:null}if("file"===e.type){let l=null!==(n=e.fileId)&&void 0!==n?n:null===(t=e.file)||void 0===t?void 0:t.id;return null!=l?{fileId:l}:null}if("link"===e.type){let l=null!==(u=null!==(a=e.linkUrl)&&void 0!==a?a:e.url)&&void 0!==u?u:null===(o=e.link)||void 0===o?void 0:o.url,i=null!==(c=null!==(s=e.linkLabel)&&void 0!==s?s:e.label)&&void 0!==c?c:null===(r=e.link)||void 0===r?void 0:r.label,t=null!==(f=e.linkId)&&void 0!==f?f:null===(d=e.link)||void 0===d?void 0:d.id;if(l)return{linkUrl:l,...i?{linkLabel:i}:{},...null!=t?{linkId:t}:{}};if(null!=t)return{linkId:t}}return null}function h(e){if(!e)return[];let l=[];for(let i of e.deliverablesAdd||[])l.push(JSON.stringify(i));for(let i of e.deliverablesRemove||[])l.push(JSON.stringify({removeDeliverable:i}));for(let i of e.etsyFilesRemove||[])l.push(JSON.stringify({removeEtsyFile:i}));return l}function g(e,l){let{assetCategory:i=null,onParentUploadFailed:p=null,initialDeliverables:h=null}=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},[g,x]=(0,t.useState)(!e&&Array.isArray(h)?h:[]),[b,I]=(0,t.useState)([]),[k,w]=(0,t.useState)([]),[S,F]=(0,t.useState)(!!e),[C,D]=(0,t.useState)(!1),[j,E]=(0,t.useState)(!1),[R,A]=(0,t.useState)([]),L=(0,t.useRef)([]);L.current=R;let U=(0,t.useRef)([]);U.current=k;let Z=(0,t.useRef)(new Set),_=(0,t.useRef)(!1),T=(0,t.useRef)(g);(0,t.useEffect)(()=>{T.current=g},[g]);let N=(0,t.useCallback)(async()=>{if(!e){F(!1);return}D(!0),_.current||F(!0);try{var i;let t=await o.default.get("".concat(c,"/api/digital-files/listing/").concat(e)),n=(null===(i=t.data)||void 0===i?void 0:i.data)||{};x(n.deliverables||[]),I(n.digitalFiles||[]),null==l||l(n.deliverables||[]),_.current=!0,E(!0)}catch(e){}finally{F(!1),D(!1)}},[e]);(0,t.useEffect)(()=>{N()},[N]),(0,t.useEffect)(()=>{let e=Z.current;if(0===e.size)return;let l=[];for(let i of Array.from(e)){if(L.current.some(e=>"addCollection"===e.type&&String(e.collectionId)===i)){e.delete(i);continue}k.some(e=>String(e.collectionId)===i&&m(e))||(e.delete(i),l.push(i),(0,a.P4)(Number(i),{recursive:!0}
1).catch(()=>{}))}l.length&&w(e=>e.filter(e=>!l.includes(String(e.collectionId))))},[k]);let P=!e&&Array.isArray(h)?JSON.stringify(h):null;(0,t.useEffect)(()=>{e||(x(Array.isArray(h)?h:[]),A([]))},[P]);let B=(0,t.useMemo)(()=>{let e=new Set(R.filter(e=>"removeDeliverable"===e.type).map(e=>e.deliverableId)),l=R.filter(e=>["addFile","addCollection","addUrl","addLink"].includes(e.type)).map(e=>e.tempDeliverable);return[...g.filter(l=>!e.has(l.id)),...l]},[g,R]),O=(0,t.useRef)(B);O.current=B;let W=B.filter(e=>"collection"===e.type),z=B.filter(e=>"file"===e.type),M=B.filter(e=>"link"===e.type),J=r.$H,q=(0,t.useRef)(new Set),K=(0,t.useRef)(!1);(0,t.useEffect)(()=>(K.current=!1,()=>{for(let e of(K.current=!0,q.current))clearTimeout(e);q.current.clear()}),[]);let G=function(e,l){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,t=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null;if(K.current||i>=20)return;let n=setTimeout(async()=>{if(q.current.delete(n),!K.current)try{var r,d;let n=await o.default.get("".concat(c,"/api/files/").concat(e));if(K.current)return;let a=null!==(d=null===(r=n.data)||void 0===r?void 0:r.data)&&void 0!==d?d:n.data;if(!a)return;if("processing"===a.uploadStatus)G(e,l,i+1,t);else{let e={...a,thumbnailUrl:a.thumbnailUrl||a.s3Url||null};if(A(i=>i.map(i=>i.id===l?{...i,tempDeliverable:{...i.tempDeliverable,file:e}}:i)),"function"==typeof t)try{t(a)}catch(e){}}}catch(n){if(K.current)return;G(e,l,i+1,t)}},2e3);q.current.add(n)},Q=async function(e,l,t){let o,d=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0,a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:!t;w(l=>l.map(l=>l.tempId===e?{...l,progress:0,status:d>0?"retrying":"queued",errorMessage:null,retryCount:d}:l));let s=function(i){let{retryable:n=!0}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(n&&a&&t&&p){w(l=>l.filter(l=>l.tempId!==e)),p(l,{tempId:e});return}w(l=>l.map(l=>l.tempId===e?{...l,status:"error",errorMessage:i,retryCount:d,maxRetries:J}:l))};try{let{items:n}=(0,r.SP)([l],{transport:"asset",surface:"digital-files",...t?{collectionId:t}:{},...i?{assetCategory:i}:{},onItem:l=>{w(i=>i.map(i=>i.tempId===e?{...i,progress:l.pct,status:"error"===i.status?i.status:"queued"===l.status?"queued":l.attempt>1?"retrying":"uploading",retryCount:Math.max(0,(l.attempt||1)-1)}:i))}});o=await n[0].promise}catch(e){s("Network error. Please try again.");return}if(null==o?void 0:o.cancelled){w(l=>l.filter(l=>l.tempId!==e));return}if(null==o?void 0:o.failed)s((0,u.Od)(null==o?void 0:o.warnings,0)||(null==o?void 0:o.error)||"Upload failed. Please try again.",{retryable:(null==o?void 0:o.errorReason)!=="unconfirmed"});else{try{let l=(null==o?void 0:o.row)||null,i=null==o?void 0:o.warnings,t=(0,u.Od)(i,(null==l?void 0:l.id)?1:0);if(t&&n.Am.warn(t),Array.isArray(i)&&i.some(e=>(null==e?void 0:e.code)==="COLLECTION_MISSING")&&N(),a&&(null==l?void 0:l.id)){let i={...l,thumbnailUrl:l.thumbnailUrl||l.s3Url||null},t="pending-file-".concat(l.id,"-").concat(Date.now()),n={id:t,type:"addFile",fileId:l.id,tempDeliverable:{id:t,type:"file",file:i,_isPending:!0,_uploadTempId:e}};A(e=>[...e,n]),"processing"===l.uploadStatus?G(l.id,t,0,()=>{$(n,t)}):$(n,t)}}catch(e){}w(l=>l.filter(l=>l.tempId!==e))}},Y=function(e){let l=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:!l,t=[];return e.forEach(e=>{let n="temp-".concat(++f,"-").concat(Date.now());t.push(n),w(t=>[...t,{tempId:n,file:e,progress:0,status:"queued",collectionId:l,linkAsDeliverable:i,retryCount:0}]),Q(n,e,l,0,i)}),t},H=async l=>{if(String(l).startsWith("pending-")){A(e=>e.filter(e=>e.id!==l));return}if(e)try{await (0,s.Ly)(e,l),x(e=>e.filter(e=>e.id!==l)),A(e=>e.filter(e=>!("removeDeliverable"===e.type&&e.deliverableId===l)))}catch(e){}},V=async(e,l)=>{try{await (0,d.cd)(e,l),await N()}catch(e){}},X=async(e,l)=>{try{await (0,d.Rm)(e,{name:l}),await N()}catch(e){}},$=async(l,i)=>{if(!e)return!1;let t=null;if("addFile"===l.type&&l.fileId?t={fileId:l.fileId}:"addCollection"===l.type&&l.collectionId?t={collectionId:l.collectionId}:"addUrl"===l.type?t={linkUrl:l.linkUrl,...l.linkLabel?{linkLabel:l.linkLabel}:{}}:"addLink"===l.type&&l.linkId&&(t={linkId:l.linkId}),!t)return!1;try{return await (0,s.FZ)(e,t),A(e=>e.filter(e=>e.id!==i)),await N(),!0}catch(e){return A(e=>e.filter(e=>e.id!==i)),n.Am.error("Couldn't attach file to listing â please try again."),!1}},ee=async(l,i)=>{if(!e)return!1;let t=l.id||(null==i?void 0:i.id);return A(e=>[...e,{...l,id:t,tempDeliverable:i}]),$(l,t)},el=(0,t.useCallback)(()=>{let l=L.current,i=[],t=[],n=new Set;for(let e of l){let l=v(e);l&&(l.addEntry?i.push(l.addEntry):null!=l.removeDeliverableId?t.push(l.removeDeliverableId):null!=l.removeEtsyFileId&&n.add(l.removeEtsyFileId))}
1return e||(i=O.current.map(y).filter(Boolean)),{deliverablesAdd:i,deliverablesRemove:t,etsyFilesKeep:b.filter(e=>!n.has(e.id)).map(e=>e.id),etsyFilesRemove:Array.from(n)}},[b,e,B]),ei=(0,t.useCallback)(()=>B.map(y).filter(Boolean),[B]),et=(0,t.useMemo)(()=>R.filter(e=>["addFile","addCollection","addUrl","addLink"].includes(e.type)).map(e=>"addFile"===e.type?{fileId:e.fileId}:"addCollection"===e.type?{collectionId:e.collectionId}:"addUrl"===e.type?{linkUrl:e.linkUrl,...e.linkLabel?{linkLabel:e.linkLabel}:{}}:"addLink"===e.type?{linkId:e.linkId}:null).filter(Boolean),[R]),en=(0,t.useMemo)(()=>R.filter(e=>"removeEtsyFile"===e.type).map(e=>e.fileId),[R]),eo=async e=>{try{let l=await (0,d.X5)(e),i=URL.createObjectURL(l.data),t=document.createElement("a");t.href=i,t.download="collection-".concat(e,".zip"),document.body.appendChild(t),t.click(),document.body.removeChild(t),URL.revokeObjectURL(i),n.Am.success("Download started.")}catch(e){n.Am.error("Download failed.")}},er=async e=>{try{let l=await (0,u.yS)([e]),i=URL.createObjectURL(l.data),t=document.createElement("a");t.href=i,t.download="download.zip",document.body.appendChild(t),t.click(),document.body.removeChild(t),URL.revokeObjectURL(i),n.Am.success("Download started.")}catch(e){n.Am.error("Download failed.")}},ed=(0,t.useCallback)(()=>{A([]),L.current=[]},[]),ea=(0,t.useCallback)(e=>{let l=function(e,l){let i=new Map;for(let e of l||[])i.set(e,(i.get(e)||0)+1);return 0===i.size?Array.isArray(e)?[...e]:[]:(Array.isArray(e)?e:[]).filter(e=>{let l=v(e);if(!l)return!0;if(l.idempotent)return!i.has(l.identity);let t=i.get(l.identity)||0;return t<=0||(i.set(l.identity,t-1),!1)})}(L.current,e);
1return l.length===L.current.length||(L.current=l,A(l)),l.length},[]),eu=(0,t.useCallback)(()=>{A(e=>{let l=new Set(e.filter(e=>"removeDeliverable"===e.type).map(e=>e.deliverableId)),i=new Set(e.filter(e=>"removeEtsyFile"===e.type).map(e=>e.fileId)),t=[];for(let e of g)(null==e?void 0:e.id)==null||l.has(e.id)||t.push({id:"rm-".concat(e.id),type:"removeDeliverable",deliverableId:e.id});for(let e of b)(null==e?void 0:e.id)==null||i.has(e.id)||t.push({id:"del-etsy-".concat(e.id),type:"removeEtsyFile",fileId:e.id});return t.length?[...e,...t]:e})},[g,b]);return{collections:W,standaloneFiles:z,standaloneLinks:M,digitalFiles:b,uploadingFiles:k,isLoading:S,isFetching:C,fetchSucceeded:j,refetch:N,resetPendingOps:ed,retirePublishedOps:ea,markAllForRemoval:eu,uploadAndLink:function(e){let l=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return Y(e,l||null,!0)},uploadToCollection:(e,l)=>Y(e,l,!1),removeUploadingFile:e=>{w(l=>l.filter(l=>l.tempId!==e))},retryUpload:e=>{var l;let i=k.find(l=>l.tempId===e);i&&Q(e,i.file,i.collectionId,0,null!==(l=i.linkAsDeliverable)&&void 0!==l?l:!i.collectionId)},unlinkDeliverable:e=>{if(String(e).startsWith("pending-")){let l=L.current.find(l=>l.id===e);if((null==l?void 0:l.type)==="addCollection"&&l._sessionCreated&&null!=l.collectionId){let i=L.current.some(i=>i.id!==e&&"addCollection"===i.type&&i.collectionId===l.collectionId),t=U.current.some(e=>String(e.collectionId)===String(l.collectionId)&&m(e));i||(t?Z.current.add(String(l.collectionId)):(w(e=>e.filter(e=>String(e.collectionId)!==String(l.collectionId))),(0,a.P4)(l.collectionId,{recursive:!0}).catch(()=>{})))}A(l=>l.filter(l=>l.id!==e))}else A(l=>[...l,{id:"rm-".concat(e),type:"removeDeliverable",deliverableId:e}])},deleteDeliverableNow:H,addDeliverableNow:ee,unlinkFileFromCollection:V,deleteEtsyFile:e=>{I(l=>l.filter(l=>l.id!==e)),A(l=>[...l,{id:"del-etsy-".concat(e),type:"removeEtsyFile",fileId:e}])},renameCollection:X,downloadCollection:eo,downloadFile:er,addPendingDeliverable:(e,l)=>{"addCollection"===e.type&&null!=e.collectionId&&Z.current.delete(String(e.collectionId)),A(i=>[...i,{...e,id:e.id||l.id,tempDeliverable:l}])},getDigitalFilesPayload:el,getDeliverablesSnapshot:ei,hasPendingChanges:R.length>0,pendingDeliverables:et,pendingEtsyRemovals:en}}},14206:function(e,l,i){i.d(l,{FZ:function(){return o},Ly:function(){return r},ae:function(){return n}});var t=i(4385);let n=e=>t.default.get("".concat("https://backend.listingview.io","/api/listings/").concat(e,"/deliverables")),o=(e,l)=>t.default.post("".concat("https://backend.listingview.io","/api/listings/").concat(e,"/deliverables"),l),r=(e,l)=>t.default.delete("".concat("https://backend.listingview.io","/api/listings/").concat(e,"/deliverables/").concat(l))}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.