import{b as E}from"./chunk-3LGFOM34.js";import{c as U}from"react/compiler-runtime";import{jsx as D}from"react/jsx-runtime";import{Drawer as V,EditDepthProvider as B,useModal as q}from"@payloadcms/ui";import"react";import{jsx as I,jsxs as j}from"react/jsx-runtime";import{Form as v,FormSubmit as M,RenderFields as O,useDocumentInfo as T,useServerFunctions as $,useTranslation as N}from"@payloadcms/ui";import{abortAndIgnore as x}from"@payloadcms/ui/shared";import{useCallback as W,useEffect as y,useRef as k,useState as H}from"react";import{v4 as L}from"uuid";var F=({data:a,featureKey:e,fieldMapOverride:n,handleDrawerSubmit:s,schemaFieldsPathOverride:t,schemaPath:d,schemaPathSuffix:m})=>{let{t:p}=N(),{id:l,collectionSlug:c,getDocPreferences:u,globalSlug:i}=T(),o=k(new AbortController),[f,r]=H(!1),{fieldProps:{featureClientSchemaMap:h,permissions:A}}=E(),{getFormState:S}=$(),g=t??`${d}.lexical_internal_feature.${e}${m?`.${m}`:""}`,b=n??h[e]?.[g];y(()=>{let C=new AbortController;return(async()=>{let{state:_}=await S({id:l,collectionSlug:c,data:a??{},docPermissions:{fields:!0},docPreferences:await u(),globalSlug:i,operation:"update",renderAllFields:!0,schemaPath:g,signal:C.signal});r(_)})(),()=>{x(C)}},[g,l,a,S,c,i,u]);let R=W(async({formState:C})=>{x(o.current);let P=new AbortController;o.current=P;let{state:_}=await S({id:l,collectionSlug:c,docPermissions:{fields:!0},docPreferences:await u(),formState:C,globalSlug:i,operation:"update",schemaPath:g,signal:P.signal});return _||C},[S,l,c,u,i,g]);return y(()=>()=>{x(o.current)},[]),f===!1?null:j(v,{beforeSubmit:[R],disableValidationOnSubmit:!0,fields:Array.isArray(b)?b:[],initialState:f,onChange:[R],onSubmit:s,uuid:L(),children:[I(O,{fields:Array.isArray(b)?b:[],forceRender:!0,parentIndexPath:"",parentPath:"",parentSchemaPath:g,permissions:A,readOnly:!1}),I(M,{children:p("fields:saveChanges")})]})};var pe=a=>{let e=U(15),{className:n,data:s,drawerSlug:t,drawerTitle:d,featureKey:m,fieldMapOverride:p,handleDrawerSubmit:l,schemaFieldsPathOverride:c,schemaPath:u,schemaPathSuffix:i}=a,{closeModal:o}=q(),f=d??"",r;e[0]!==o||e[1]!==t||e[2]!==l?(r=(A,S)=>{o(t),setTimeout(()=>{l(A,S)},1)},e[0]=o,e[1]=t,e[2]=l,e[3]=r):r=e[3];let h;return e[4]!==n||e[5]!==s||e[6]!==t||e[7]!==m||e[8]!==p||e[9]!==c||e[10]!==u||e[11]!==i||e[12]!==f||e[13]!==r?(h=D(B,{children:D(V,{className:n,slug:t,title:f,children:D(F,{data:s,featureKey:m,fieldMapOverride:p,handleDrawerSubmit:r,schemaFieldsPathOverride:c,schemaPath:u,schemaPathSuffix:i})})}),e[4]=n,e[5]=s,e[6]=t,e[7]=m,e[8]=p,e[9]=c,e[10]=u,e[11]=i,e[12]=f,e[13]=r,e[14]=h):h=e[14],h};import{c as z}from"react/compiler-runtime";import{jsx as G}from"react/jsx-runtime";import{useAuth as J,useConfig as K,useEntityVisibility as Q}from"@payloadcms/ui";import*as w from"react";var X=(a,e)=>a.filter(({slug:n,admin:{enableRichTextRelationship:s},upload:t})=>e?.visibleEntities.collections.includes(n)?e?.uploads?s&&!!t:t?!1:s:!1),be=a=>{let e=z(20),n,s,t,d;e[0]!==a?({children:s,FallbackComponent:n,uploads:d,...t}=a,e[0]=a,e[1]=n,e[2]=s,e[3]=t,e[4]=d):(n=e[1],s=e[2],t=e[3],d=e[4]);let m=d===void 0?!1:d,{config:p}=K(),{collections:l}=p,{user:c}=J(),{visibleEntities:u}=Q(),i;e[5]!==l||e[6]!==m||e[7]!==c||e[8]!==u?(i=()=>X(l,{uploads:m,user:c,visibleEntities:u}).map(Y),e[5]=l,e[6]=m,e[7]=c,e[8]=u,e[9]=i):i=e[9];let[o]=w.useState(i);if(!o.length){let r;return e[10]!==n||e[11]!==t?(r=n?G(n,{...t}):null,e[10]=n,e[11]=t,e[12]=r):r=e[12],r}let f;if(e[13]!==s||e[14]!==o||e[15]!==t){let r;e[17]!==o||e[18]!==t?(r={...t,enabledCollectionSlugs:o},e[17]=o,e[18]=t,e[19]=r):r=e[19],f=w.cloneElement(s,r),e[13]=s,e[14]=o,e[15]=t,e[16]=f}else f=e[16];return f};function Y(a){let{slug:e}=a;return e}import{createCommand as Z}from"lexical";var Ae=Z("INSERT_UPLOAD_WITH_DRAWER_COMMAND");export{pe as a,be as b,Ae as c};
//# sourceMappingURL=chunk-QP2NYEWJ.js.map
