"use client";import{a as R,b as S,c as E}from"./chunk-QP2NYEWJ.js";import{a as N}from"./chunk-INBEEENE.js";import{a as $}from"./chunk-F26IQ5RE.js";import{b as p}from"./chunk-3LGFOM34.js";import{jsx as e,jsxs as i}from"react/jsx-runtime";import{useLexicalComposerContext as X}from"@lexical/react/LexicalComposerContext.js";import{getTranslation as y}from"@payloadcms/translations";import{Button as h,File as Y,formatDrawerSlug as Z,useConfig as ee,useEditDepth as te,usePayloadAPI as oe,useTranslation as ae}from"@payloadcms/ui";import{$getNodeByKey as P}from"lexical";import{useCallback as f,useId as le,useReducer as se,useRef as re,useState as ie}from"react";var t="lexical-upload",U={depth:0},ne=n=>{let{data:{fields:L,relationTo:g,value:l},nodeKey:s}=n;if(typeof l=="object")throw new Error("Upload value should be a string or number. The Lexical Upload component should not receive the populated value object.");let{config:{routes:{api:F},serverURL:T},getEntityConfig:j}=ee(),B=re(null),{uuid:I}=p(),k=te(),[o]=X(),{editorConfig:A,fieldProps:{readOnly:u,schemaPath:K}}=p(),{i18n:b,t:d}=ae(),[_,M]=se(r=>r+1,0),[a]=ie(()=>j({collectionSlug:g})),O=le(),w=Z({slug:"lexical-upload-drawer-"+I+O,depth:k}),{toggleDrawer:W}=N(w,!0),{closeDocumentDrawer:D,DocumentDrawer:z,DocumentDrawerToggler:H}=$({id:l,collectionSlug:a.slug}),[{data:c},{setParams:x}]=oe(`${T}${F}/${a.slug}/${l}`,{initialParams:U}),C=c?.thumbnailURL||c?.url,q=f(()=>{o.update(()=>{P(s)?.remove()})},[o,s]),G=f(r=>{x({...U,cacheBust:_}),M(),D()},[x,_,D]),v=A?.resolvedFeatureMap?.get("upload")?.sanitizedClientFeatureProps.collections?.[a.slug]?.hasExtraFields,J=f((r,Q)=>{o.update(()=>{let m=P(s);if(m){let V={...m.getData(),fields:Q};m.setData(V)}})},[o,s]);return i("div",{className:t,contentEditable:!1,ref:B,children:[i("div",{className:`${t}__card`,children:[i("div",{className:`${t}__topRow`,children:[e("div",{className:`${t}__thumbnail`,children:C?e("img",{alt:c?.filename,"data-lexical-upload-id":l,"data-lexical-upload-relation-to":g,src:C}):e(Y,{})}),i("div",{className:`${t}__topRowRightPanel`,children:[e("div",{className:`${t}__collectionLabel`,children:y(a.labels.singular,b)}),o.isEditable()&&i("div",{className:`${t}__actions`,children:[v?e(h,{buttonStyle:"icon-label",className:`${t}__upload-drawer-toggler`,disabled:u,el:"button",icon:"edit",onClick:()=>{W()},round:!0,tooltip:d("fields:editRelationship")}):null,e(h,{buttonStyle:"icon-label",className:`${t}__swap-drawer-toggler`,disabled:u,el:"button",icon:"swap",onClick:()=>{o.dispatchCommand(E,{replace:{nodeKey:s}})},round:!0,tooltip:d("fields:swapUpload")}),e(h,{buttonStyle:"icon-label",className:`${t}__removeButton`,disabled:u,icon:"x",onClick:r=>{r.preventDefault(),q()},round:!0,tooltip:d("fields:removeUpload")})]})]})]}),e("div",{className:`${t}__bottomRow`,children:e(H,{className:`${t}__doc-drawer-toggler`,children:e("strong",{children:c?.filename})})})]}),l?e(z,{onSave:G}):null,v?e(R,{data:L,drawerSlug:w,drawerTitle:d("general:editLabel",{label:y(a.labels.singular,b)}),featureKey:"upload",handleDrawerSubmit:J,schemaPath:K,schemaPathSuffix:a.slug}):null]})},Ce=n=>e(S,{...n,uploads:!0,children:e(ne,{...n})});export{Ce as UploadComponent};
//# sourceMappingURL=component-VJVZFYZJ.js.map
