@firecms/core 3.0.0-canary.49 → 3.0.0-canary.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.es.js +8 -6
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +2 -2
- package/dist/index.umd.js.map +1 -1
- package/dist/util/resolutions.d.ts +0 -1
- package/package.json +4 -4
- package/src/components/EntityCollectionView/EntityCollectionView.tsx +5 -3
- package/src/form/components/StorageUploadProgress.tsx +1 -1
- package/src/util/resolutions.ts +2 -3
package/dist/index.umd.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
`;function Oi(e,t){d.useEffect(()=>{if(document){document.title=`${e} - FireCMS`;let o=document.querySelector("link[rel~='icon']");o||(o=document.createElement("link"),o.rel="icon",document.getElementsByTagName("head")[0].appendChild(o)),o.href=t??Mi}},[e,t])}function Aa(e){const{path:t,collections:o=[],currentFullPath:a}=e,n=me(t).split("/"),i=Ot(n),s=[];for(let l=0;l<i.length;l++){const c=i[l],u=o&&o.find(m=>m.id===c||m.path===c);if(u){const m=u.id??u.path,g=a&&a.length>0?a+"/"+m:m,f=me(me(t).replace(c,"")),h=f.length>0?f.split("/"):[];if(h.length>0){const b=h[0],y=g+"/"+b;if(s.push(new gr(b,g)),h.length>1){const A=h.slice(1).join("/");if(!u)throw Error("collection not found resolving path: "+u);u.subcollections&&s.push(...Aa({path:A,collections:u.subcollections,currentFullPath:y}))}}break}}return s}const zi="/",Vi="/c";function Gi(e){const{basePath:t=zi,baseCollectionPath:o=Vi,authController:a,collections:n,collectionPermissions:i,views:s,adminViews:l,viewsOrder:c,userConfigPersistence:u,dataSourceDelegate:m,injectCollections:g}=e,f=d.useRef(),h=d.useRef(),b=d.useRef(),[y,A]=d.useState(!1),[k,v]=d.useState(void 0),[_,E]=d.useState(!0),[C,B]=d.useState(void 0),x=me(t),S=me(o),I=x?`/${x}`:"/",D=x?`/${x}/${S}`:`/${S}`,P=d.useCallback(Q=>x?`/${x}/${Rt(Q)}`:`/${Rt(Q)}`,[x]),T=d.useCallback(Q=>`${me(o)}/${Rt(Q)}`,[o]),V=d.useCallback((Q,K,Z,M)=>{let Y=[...(Q??[]).map(F=>F.hideFromNavigation?void 0:{url:T(F.id??F.path),type:"collection",name:F.name.trim(),path:F.id??F.path,collection:F,description:F.description?.trim(),group:wa(F)}).filter(Boolean),...(K??[]).map(F=>F.hideFromNavigation?void 0:{url:P(Array.isArray(F.path)?F.path[0]:F.path),name:F.name.trim(),type:"view",path:F.path,view:F,description:F.description?.trim(),group:wa(F)}).filter(Boolean),...(Z??[]).map(F=>F.hideFromNavigation?void 0:{url:P(Array.isArray(F.path)?F.path[0]:F.path),name:F.name.trim(),type:"admin",path:F.path,view:F,description:F.description?.trim(),group:"Admin"}).filter(Boolean)];Y=Y.sort((F,N)=>F.group!=="Views"&&F.group!=="Admin"&&(N.group==="Views"||N.group==="Admin")?-1:N.group!=="Views"&&N.group!=="Admin"&&(F.group==="Views"||F.group==="Admin")||F.group==="Admin"&&N.group!=="Admin"?1:F.group!=="Admin"&&N.group==="Admin"||F.group==="Views"&&N.group!=="Views"?-1:F.group!=="Views"&&N.group==="Views"?1:0),M&&(Y=Y.sort((F,N)=>{const le=M.indexOf(F.path),xe=M.indexOf(N.path);return le===-1&&xe===-1?0:le===-1?1:xe===-1?-1:le-xe}));const q=Object.values(Y).map(F=>F.group).filter(Boolean).filter((F,N,le)=>le.indexOf(F)===N);return{navigationEntries:Y,groups:q}},[P,T]),re=d.useCallback(async()=>{if(!a.initialLoading){console.debug("Refreshing navigation");try{const[Q=[],K,Z=[]]=await Promise.all([ji(n,i,a,m,g),ya(s,a,m),ya(l,a,m)]);let M=!1;va(f.current??[],Q)||(f.current=Q,M=!0),L(h.current,K)||(h.current=K,M=!0),L(b.current,Z)||(b.current=Z,M=!0);const Y=V(Q,K,Z,c);M&&!L(k,Y)&&v(Y)}catch(Q){console.error(Q),B(Q)}E(!1),A(!0)}},[n,i,a.user,a.initialLoading,s,l,V,g]);d.useEffect(()=>{re()},[re]);const R=d.useCallback((Q,K,Z=!1)=>{const M=f.current;if(!M)return;const Y=Mt(me(Q),M),q=Z?u?.getCollectionConfig(Q):void 0,F=Y?De(Y,q):void 0;let N=F;if(F){const le=F.subcollections,xe=F.callbacks,te=F.permissions;N={...N,subcollections:N?.subcollections??le,callbacks:N?.callbacks??xe,permissions:N?.permissions??te}}if(N)return{...F,...N}},[u]),$=d.useCallback(Q=>{const K=f.current;if(K===void 0)throw Error("getCollectionFromPaths: Collections have not been initialised yet");let Z=[...K??[]];for(let M=0;M<Q.length;M++){const Y=Q[M],q=Z.find(F=>F.id===Y||F.path===Y);if(!q)return;if(Z=q.subcollections,M===Q.length-1)return q}},[]),G=d.useCallback(Q=>{const K=f.current;if(K===void 0)throw Error("getCollectionFromIds: Collections have not been initialised yet");let Z=[...K??[]];for(let M=0;M<Q.length;M++){const Y=Q[M],q=Z.find(F=>F.id===Y);if(!q)return;if(Z=q.subcollections,M===Q.length-1)return q}},[]),z=d.useCallback(Q=>me(Q+"/").startsWith(me(D)+"/"),[D]),H=d.useCallback(Q=>{if(Q.startsWith(D))return Q.replace(D,"");throw Error("Expected path starting with "+D)},[D]),J=d.useCallback(({path:Q})=>`s/edit/${Rt(Q)}`,[]),ee=d.useCallback(Q=>{const K=f.current??[];return hr(Q,K)},[]),ne=d.useCallback(Q=>{const K=f.current??[];return Aa({path:Q,collections:K})},[]),U=d.useCallback(Q=>{const Z=Q.split("/").filter((Y,q)=>q%2===0);Z.pop();const M=[];for(let Y=1;Y<=Z.length;Y++)M.push(Z.slice(0,Y));return M.map(Y=>$(Y)?.id).filter(Boolean)},[ne]),X=d.useCallback(Q=>{let Z=f.current;const M=[];for(let Y=0;Y<Q.length;Y++){const q=Q[Y],F=Z.find(N=>N.id===q);if(!F)throw Error(`Collection with id ${q} not found`);M.push(F.path),Z=F.subcollections}return M},[G]);return{collections:f.current,views:h.current,adminViews:b.current,loading:!y||_,navigationLoadingError:C,homeUrl:I,basePath:t,baseCollectionPath:o,initialised:y,getCollection:R,getCollectionFromPaths:$,getCollectionFromIds:G,isUrlCollectionPath:z,urlPathToDataPath:H,buildUrlCollectionPath:T,buildUrlEditCollectionPath:J,buildCMSUrlPath:P,resolveAliasesFrom:ee,topLevelNavigation:k,refreshNavigation:re,getParentReferencesFromPath:ne,getParentCollectionIds:U,convertIdsToPaths:X}}function Yi(e,t){return t?`${me(e)}/${me(t)}`:me(e)}function Rt(e){return encodeURIComponent(me(e)).replaceAll("%2F","/").replaceAll("%23","#")}function ba(e,t){return e.filter(o=>o.permissions?_t(o,t,o.path,null)?.read!==!1:!0).map(o=>o.subcollections?{...o,subcollections:ba(o.subcollections,t)}:o)}async function ji(e,t,o,a,n){let i=[];return typeof e=="function"?i=await e({user:o.user,authController:o,dataSource:a}):Array.isArray(e)&&(i=e),n&&(i=n(i??[])),i=Yo(i,t),i=ba(i,o),i}async function ya(e,t,o){let a=[];return typeof e=="function"?a=await e({user:t.user,authController:t,dataSource:o}):Array.isArray(e)&&(a=e),a}function wa(e){const t=e.group?.trim();return!t||t===""?"Views":t??"Views"}function va(e,t){if(e.length!==t.length)return!1;const o=[...e],a=[...t],n=o.sort((s,l)=>s.id.localeCompare(l.id)),i=a.sort((s,l)=>s.id.localeCompare(l.id));return n.every((s,l)=>Li(s,i[l]))}function Li(e,t){const{subcollections:o,...a}=e,{subcollections:n,...i}=t;return va(o??[],n??[])?L(a,i):!1}function Ui(){const e=d.useRef({}),t=d.useCallback(h=>{const b=localStorage.getItem(h);return b?JSON.parse(b):{}},[]),o=d.useCallback(h=>{const b=`collection_config::${Er(h)}`;return e.current[b]?e.current[b]:t(b)},[t]),a=d.useCallback((h,b)=>{const y=`collection_config::${Er(h)}`;localStorage.setItem(y,JSON.stringify(b));const A=e.current,k=A[y],v=De(k??t(h),b);e.current=De(A,v)},[t]),[n,i]=d.useState([]),[s,l]=d.useState([]),[c,u]=d.useState([]);d.useEffect(()=>{i(localStorage.getItem("recently_visited_paths")?JSON.parse(localStorage.getItem("recently_visited_paths")):[]),l(localStorage.getItem("favourite_paths")?JSON.parse(localStorage.getItem("favourite_paths")):[]),u(localStorage.getItem("collapsed_groups")?JSON.parse(localStorage.getItem("collapsed_groups")):[])},[]);const m=d.useCallback(h=>{localStorage.setItem("recently_visited_paths",JSON.stringify(h)),i(h)},[]),g=d.useCallback(h=>{localStorage.setItem("favourite_paths",JSON.stringify(h)),l(h)},[]),f=d.useCallback(h=>{localStorage.setItem("collapsed_groups",JSON.stringify(h)),u(h)},[]);return{onCollectionModified:a,getCollectionConfig:o,recentlyVisitedPaths:n,setRecentlyVisitedPaths:m,favouritePaths:s,setFavouritePaths:g,collapsedGroups:c,setCollapsedGroups:f}}function $i(){const e=d.useCallback(()=>typeof window>"u"?!1:window.matchMedia("(prefers-color-scheme: dark)").matches,[]),o=(localStorage.getItem("prefers-dark-mode")!=null?localStorage.getItem("prefers-dark-mode")==="true":null)??e,[a,n]=d.useState(o?"dark":"light");d.useEffect(()=>{n(o?"dark":"light"),l(o?"dark":"light")},[o]);const i=d.useCallback(()=>{n("dark"),l("dark")},[]),s=d.useCallback(()=>{n("light"),l("light")},[]),l=u=>{document.body.style.setProperty("color-scheme",u),document.documentElement.dataset.theme=u},c=d.useCallback(()=>{const u=e();a==="light"?(u?localStorage.removeItem("prefers-dark-mode"):localStorage.setItem("prefers-dark-mode","true"),i()):(u?localStorage.setItem("prefers-dark-mode","false"):localStorage.removeItem("prefers-dark-mode"),s())},[a,e]);return{mode:a,setMode:n,toggleMode:c}}function qi({disabled:e,authController:t,authenticator:o,storageSource:a,dataSourceDelegate:n}){const i=!!o,[s,l]=d.useState(i),[c,u]=d.useState(!1),[m,g]=d.useState(!i||!!t.loginSkipped),f=m&&(!i||!!t.user||!!t.loginSkipped)&&!c;d.useEffect(()=>{t.loginSkipped&&g(!0)},[t.loginSkipped]);const h=d.useRef(),b=d.useCallback(async()=>{if(e||t.initialLoading)return;if(!t.user&&!t.loginSkipped){h.current=void 0,l(!1),g(!1);return}const y=t.user;if(console.debug("Checking authentication for user",y),o instanceof Function&&y&&!L(h.current?.uid,y.uid)){l(!0);try{await o({user:y,authController:t,dataSourceDelegate:n,storageSource:a})||(t.signOut(),u(!0))}catch(A){u(A),t.signOut()}l(!1),g(!0),h.current=y}else l(!1);!t.initialLoading&&!y&&g(!0)},[e,t,o,n,a]);return d.useEffect(()=>{b()},[b]),{canAccessMainView:f,authLoading:i&&s,notAllowedError:c,authVerified:m}}function et(){return r.jsx("div",{className:"rounded-full bg-gray-200 bg-opacity-30 dark:bg-opacity-20 w-5 h-2 inline-block"})}const Wi=40,Ji=100,Hi=200;function ft(e){if(e==="tiny")return Wi;if(e==="small")return Ji;if(e==="medium")return Hi;throw Error("Thumbnail size not mapped")}function Ze(e){switch(e){case"xs":case"s":return"tiny";case"m":return"small";case"l":case"xl":return"medium";default:throw Error("Missing mapping value in getPreviewSizeFrom: "+e)}}function ka({size:e,url:t}){const[o,a]=d.useState(!1),n=d.useMemo(()=>ft(e),[e]);if(e==="tiny")return r.jsx("img",{src:t,className:"rounded-md",style:{position:"relative",objectFit:"cover",width:n,height:n,maxHeight:"100%"}},"tiny_image_preview_"+t);const i={maxWidth:"100%",maxHeight:"100%"};return r.jsxs("div",{className:"relative flex items-center justify-center max-w-full max-h-full",style:{width:n,height:n},onMouseEnter:()=>a(!0),onMouseMove:()=>a(!0),onMouseLeave:()=>a(!1),children:[r.jsx("img",{src:t,className:"rounded-md",style:i}),o&&r.jsxs(r.Fragment,{children:[navigator&&r.jsx(p.Tooltip,{title:"Copy url to clipboard",children:r.jsx("div",{className:"rounded-full absolute bottom-[-4px] right-8",children:r.jsx(p.IconButton,{variant:"filled",size:"small",onClick:s=>(s.stopPropagation(),s.preventDefault(),navigator.clipboard.writeText(t)),children:r.jsx(p.ContentCopyIcon,{className:"text-gray-500",size:"small"})})})}),r.jsx(p.Tooltip,{title:"Open image in new tab",children:r.jsx(p.IconButton,{variant:"filled",component:"a",style:{position:"absolute",bottom:-4,right:-4},href:t,rel:"noopener noreferrer",target:"_blank",size:"small",onClick:s=>s.stopPropagation(),children:r.jsx(p.OpenInNewIcon,{className:"text-gray-500",size:"small"})})})]})]},"image_preview_"+t)}function Et({url:e,previewType:t,size:o,hint:a}){return t?t==="image"?r.jsx(ka,{url:e,size:o}):t==="audio"?r.jsxs("audio",{controls:!0,src:e,children:["Your browser does not support the",r.jsx("code",{children:"audio"})," element."]}):t==="video"?r.jsx("video",{className:`max-w-${o==="small"?"sm":"md"}`,controls:!0,children:r.jsx("source",{src:e})}):r.jsxs("a",{href:e,rel:"noopener noreferrer",target:"_blank",onClick:n=>n.stopPropagation(),className:"flex flex-col items-center justify-center",style:{width:ft(o),height:ft(o)},children:[r.jsx(p.DescriptionIcon,{className:"flex-grow"}),a&&r.jsx(p.Tooltip,{title:a,children:r.jsx(p.Typography,{className:"max-w-full truncate rtl text-left",variant:"caption",children:a})})]}):!e||!e.trim()?r.jsx(et,{}):r.jsxs("a",{className:"flex gap-4 break-words items-center font-medium text-primary visited:text-primary dark:visited:text-primary dark:text-primary",href:e,rel:"noopener noreferrer",onMouseDown:n=>{n.preventDefault()},target:"_blank",children:[r.jsx(p.OpenInNewIcon,{size:"small"}),e]})}function tt({property:e,size:t}){e||console.error("No property assigned for skeleton component",e,t);let o;if(e.dataType==="string"){const a=e;a.url?o=ts(a,t):a.storage?o=Vr(t):o=Le()}else if(e.dataType==="array"){const a=e;a.of&&(Array.isArray(a.of)?o=r.jsxs(r.Fragment,{children:[a.of.map((n,i)=>zr(n,i))," "]}):a.of.dataType==="map"&&a.of.properties?o=Xi(a.of.properties,t,a.of.previewProperties):a.of.dataType==="string"?a.of.enumValues?o=Ri():a.of.storage?o=zr(a.of):o=Ki():o=zr(a.of))}else e.dataType==="map"?o=Zi(e,t):e.dataType==="date"?o=Le():e.dataType==="reference"?o=es():(e.dataType,o=Le());return o||null}function Zi(e,t){if(!e.properties)return r.jsx(r.Fragment,{});let o;return t==="medium"?o=Object.keys(e.properties):(o=e.previewProperties||Object.keys(e.properties),t==="small"?o=o.slice(0,3):t==="tiny"&&(o=o.slice(0,1))),t!=="medium"?r.jsx("div",{className:"w-full flex flex-col space-y-4",children:o.map((a,n)=>r.jsx("div",{children:e.properties&&e.properties[a]&&r.jsx(tt,{property:e.properties[a],size:"small"})},`map_${a}`))}):r.jsx("table",{className:"table-auto",children:r.jsx("tbody",{children:o&&o.map((a,n)=>r.jsxs("tr",{className:"border-b last:border-b-0",children:[r.jsx("th",{className:"align-top",style:{width:"30%"},children:r.jsx("p",{className:"text-xs text-secondary",children:e.properties[a].name})},`table-cell-title--${a}`),r.jsx("th",{style:{width:"70%"},children:e.properties&&e.properties[a]&&r.jsx(tt,{property:e.properties[a],size:"small"})},`table-cell-${a}`)]},`map_preview_table__${n}`))})})}function Xi(e,t,o){let a=o;return(!a||!a.length)&&(a=Object.keys(e),t&&(a=a.slice(0,3))),r.jsx("table",{className:"table-auto",children:r.jsx("tbody",{children:[0,1,2].map((n,i)=>r.jsx("tr",{children:a&&a.map(s=>r.jsx("th",{children:r.jsx(tt,{property:e[s],size:"small"})},`table-cell-${s}`))},`table_${n}_${i}`))})})}function Ki(){return r.jsx("div",{className:"flex flex-col gap-2",children:[0,1].map((e,t)=>Le(t))})}function Ri(){return r.jsx("div",{className:"flex flex-col gap-2",children:[0,1].map((e,t)=>r.jsx(r.Fragment,{children:Le(t)}))})}function zr(e,t=0){return r.jsx("div",{className:"flex flex-col gap-2",children:[0,1].map((o,a)=>r.jsx(r.Fragment,{children:r.jsx(tt,{property:e,size:"small"},`i_${a}`)}))},"array_index_"+t)}function Vr(e){const t=e==="tiny"?40:e==="small"?100:200;return r.jsx(p.Skeleton,{width:t,height:t})}function es(){return r.jsx(p.Skeleton,{width:200,height:100})}function ts(e,t="medium"){return typeof e.url=="boolean"?r.jsxs("div",{style:{display:"flex"},children:[Gr(),Le()]}):rs(t)}function rs(e){return r.jsx("div",{className:`w-${ft(e)} h-${ft(e)}`,children:Gr()})}function Le(e,t=120){return r.jsx(p.Skeleton,{width:t},`skeleton_${e}`)}function os(e){return r.jsx(p.Skeleton,{height:20})}function Gr(){return r.jsx(p.Skeleton,{width:24,height:24})}const _a=d.memo(Ca,as);function as(e,t){return e.size===t.size&&e.storagePathOrDownloadUrl===t.storagePathOrDownloadUrl&&e.storeUrl===t.storeUrl}const xa={};function Ca({storeUrl:e,storagePathOrDownloadUrl:t,size:o}){const[a,n]=d.useState(void 0),i=dt(),[s,l]=d.useState(xa[t]);if(d.useEffect(()=>{if(!t)return;let m=!1;return i.getDownloadURL(t).then(function(g){m||(l(g),xa[t]=g)}).catch(n),()=>{m=!0}},[t]),!t)return null;const c=s?.metadata?ns(s?.metadata.contentType):void 0,u=c?.startsWith("image")?"image":c?.startsWith("video")?"video":c?.startsWith("audio")?"audio":"file";return s?.fileNotFound?r.jsx(ye,{error:"File not found"}):s?.url?r.jsx(Et,{previewType:u,url:s.url,size:o,hint:t}):Vr(o)}function ns(e){return e.startsWith("image")?"image/*":e.startsWith("video")?"video/*":e.startsWith("audio")?"audio/*":e.startsWith("application")?"application/*":e.startsWith("text")?"text/*":e.startsWith("font")?"font/*":e}function Ie({enumValues:e,enumKey:t,size:o,className:a,children:n}){if(!e)return null;const i=qe(e),s=t!==void 0?jt(i,t):void 0,l=Vo(s),c=zo(i,t);return r.jsxs(p.Chip,{className:a,colorScheme:c,error:!l,outlined:!1,size:o,children:[n,!n&&(l!==void 0?l:String(t))]})}function Yr({propertyKey:e,value:t,property:o,size:a}){if(o.enumValues){const n=t,i=vo(o);return r.jsx(Ie,{enumKey:n,enumValues:i.enumValues,size:a})}else if(o.previewAsTag){const n=p.getColorSchemeForSeed(e??"");return r.jsx(ae,{children:r.jsx(p.Chip,{colorScheme:n,size:a,children:t})})}else{if(o.url)return r.jsx(Et,{size:a,url:t,previewType:typeof o.url=="string"?o.url:void 0});{if(!t)return r.jsx(r.Fragment,{});const n=t.split(`
|
|
3
3
|
`);return t&&t.includes(`
|
|
4
4
|
`)?r.jsx("div",{className:p.cn("overflow-x-scroll",a==="tiny"?"text-sm":""),children:n.map((i,s)=>r.jsxs(d.Fragment,{children:[r.jsx("span",{children:i}),s!==n.length-1&&r.jsx("br",{})]},`string_preview_${s}`))}):a==="tiny"?r.jsx("span",{className:"text-sm",children:t}):r.jsx(r.Fragment,{children:t})}}}function jr({propertyKey:e,value:t,property:o,size:a}){const n=oe(),i=Xe({propertyKey:e,property:o,fields:n.propertyConfigs});if(!i.of)throw Error(`You need to specify an 'of' prop (or specify a custom field) in your array property ${e}`);if(i.dataType!=="array")throw Error("Picked wrong preview component ArrayPreview");const s=t;if(!s)return null;const l=a==="medium"?"small":"tiny";return r.jsx("div",{className:"flex flex-col gap-2",children:s&&s.map((c,u)=>{const m=i.resolvedProperties[u]??i.resolvedProperties[u]??(Array.isArray(i.of)?i.of[u]:i.of);return m?r.jsx(d.Fragment,{children:r.jsx("div",{className:p.cn(p.defaultBorderMixin,"m-1 border-b last:border-b-0"),children:r.jsx(ae,{children:r.jsx(we,{propertyKey:e,value:c,property:m,size:l})})})},"preview_array_"+u):null})})}function is({actions:e,disabled:t,hover:o,collection:a,previewProperties:n,onClick:i,size:s,includeEntityNavigation:l,entity:c}){const u=ut(),m=Je(),g=oe(),f=pe(),h=a??f.getCollection(c.path);if(!h)throw Error(`Couldn't find the corresponding collection view for the path: ${c.path}`);const b=it.useMemo(()=>Ne({collection:h,path:c.path,values:c.values,fields:g.propertyConfigs}),[h]),y=d.useMemo(()=>Ho(b,g.propertyConfigs,n,s==="small"||s==="medium"?3:1),[n,b,s]),A=Fr(b,g.propertyConfigs),k=Zo(b),v=k?b.properties[k]:void 0,_=y.filter(E=>E!==A&&E!==k);return r.jsxs(ht,{onClick:t?void 0:i,hover:t?void 0:o,size:s,children:[v&&r.jsx("div",{className:p.cn("w-10 h-10 mr-2 shrink-0 grow-0",s==="tiny"?"my-0.5":"m-2 self-start"),children:r.jsx(we,{property:v,propertyKey:k,size:"tiny",value:Ye(c.values,k)})}),r.jsxs("div",{className:"flex flex-col flex-grow w-full m-1",children:[s!=="tiny"&&(c?r.jsx("div",{className:`${s!=="medium"?"block whitespace-nowrap overflow-hidden truncate":""}`,children:r.jsx(p.Typography,{variant:"caption",color:"disabled",className:"font-mono",children:c.id})}):r.jsx(p.Skeleton,{})),A&&r.jsx("div",{className:"my-0.5 text-sm font-medium",children:c?r.jsx(we,{propertyKey:A,value:Ye(c.values,A),property:b.properties[A],size:"medium"}):r.jsx(tt,{property:b.properties[A],size:"medium"})}),_&&_.map(E=>{const C=b.properties[E];return C?r.jsx("div",{className:_.length>1?"my-0.5":"my-0",children:c?r.jsx(we,{propertyKey:E,value:Ye(c.values,E),property:C,size:"tiny"}):r.jsx(tt,{property:C,size:"tiny"})},"ref_prev_"+E):null})]}),c&&l&&r.jsx(p.Tooltip,{title:`See details for ${c.id}`,className:s!=="tiny"?"self-start":"",children:r.jsx(p.IconButton,{color:"inherit",size:"small",onClick:E=>{E.stopPropagation(),u.onAnalyticsEvent?.("entity_click_from_reference",{path:c.path,entityId:c.id}),m.open({entityId:c.id,path:c.path,collection:h,updateUrl:!0})},children:r.jsx(p.KeyboardTabIcon,{size:"small"})})}),e]})}const Ea=it.forwardRef(({children:e,hover:t,onClick:o,size:a,style:n,className:i,fullwidth:s=!0,...l},c)=>r.jsx("div",{ref:c,style:{...n,tabindex:0},className:p.cn("bg-white dark:bg-gray-900",s?"w-full":"","items-center",t?"hover:bg-slate-50 dark:hover:bg-gray-800 group-hover:bg-slate-50 dark:group-hover:bg-gray-800":"",a==="tiny"?"p-1":"p-2","flex border rounded-lg",o?"cursor-pointer":"",p.defaultBorderMixin,i),onClick:u=>{o&&(u.preventDefault(),o(u))},...l,children:e}));Ea.displayName="EntityPreviewContainer";const ht=it.memo(Ea),Oe=it.memo(function(t){const o=t.reference;return typeof o=="object"&&"isEntityReference"in o&&o.isEntityReference()?r.jsx(ls,{...t}):(console.warn("Reference preview received value of type",typeof o),r.jsx(ht,{onClick:t.onClick,size:t.size,children:r.jsx(ye,{error:"Unexpected value. Click to edit",tooltip:JSON.stringify(o)})}))},ss);function ss(e,t){return e.disabled===t.disabled&&e.size===t.size&&e.hover===t.hover&&e.reference?.id===t.reference?.id&&e.reference?.path===t.reference?.path&&e.allowEntityNavigation===t.allowEntityNavigation}function ls({disabled:e,reference:t,previewProperties:o,size:a,hover:n,onClick:i,allowEntityNavigation:s=!0}){const l=oe(),u=pe().getCollection(t.path);if(!u){if(l.components?.missingReference)return r.jsx(l.components.missingReference,{path:t.path});throw Error(`Couldn't find the corresponding collection view for the path: ${t.path}`)}return r.jsx(cs,{reference:t,collection:u,previewProperties:o,size:a,disabled:e,allowEntityNavigation:s,onClick:i,hover:n})}function cs({reference:e,collection:t,previewProperties:o,size:a,disabled:n,allowEntityNavigation:i,onClick:s,hover:l}){const{entity:c,dataLoading:u,dataLoadingError:m}=Qr({path:e.path,entityId:e.id,collection:t,useCache:!0});c&&Ba.set(e.pathWithId,c);const g=c??Ba.get(e.pathWithId);let f;return e?g&&!g.values&&(f=r.jsx(ye,{error:"Reference does not exist",tooltip:e.path})):f=r.jsx(ye,{error:"Reference not set"}),f?r.jsx(ht,{onClick:n?void 0:s,hover:n?void 0:l,size:a,children:f}):u&&!g?r.jsx(ht,{onClick:n?void 0:s,hover:n?void 0:l,size:a,children:r.jsx(p.Skeleton,{})}):g?r.jsx(is,{size:a,previewProperties:o,disabled:n,entity:g,collection:t,onClick:s,includeEntityNavigation:i,hover:l}):r.jsx(ht,{onClick:n?void 0:s,hover:n?void 0:l,size:a,children:r.jsx(ye,{error:"Entity not found"})})}const Ba=new Map;function Sa({propertyKey:e,value:t,property:o,size:a}){const n=oe(),i=Xe({propertyKey:e,property:o,fields:n.propertyConfigs});if(Array.isArray(i?.of))throw Error("Using array properties instead of single one in `of` in ArrayProperty");if(i?.dataType!=="array"||!i.of||i.of.dataType!=="reference")throw Error("Picked wrong preview component ArrayOfReferencesPreview");const s=a==="medium"?"small":"tiny";return r.jsx("div",{className:"flex flex-col w-full",children:t&&t.map((l,c)=>{const u=i.of;return r.jsx("div",{className:"mt-1 mb-1 w-full",children:r.jsx(Oe,{disabled:!u.path,previewProperties:u.previewProperties,size:s,reference:l})},`preview_array_ref_${e}_${c}`)})})}function Ia({propertyKey:e,value:t,property:o,size:a}){const n=oe(),i=Xe({propertyKey:e,property:o,fields:n.propertyConfigs});if(Array.isArray(i.of))throw Error("Using array properties instead of single one in `of` in ArrayProperty");if(i.dataType!=="array"||!i.of||i.of.dataType!=="string")throw Error("Picked wrong preview component ArrayOfStorageComponentsPreview");const s=a==="medium"?"small":"tiny";return r.jsx("div",{className:"flex flex-wrap gap-2",children:t&&t.map((l,c)=>r.jsx(ae,{children:r.jsx(we,{propertyKey:e,value:l,property:i.of,size:s})},`preview_array_storage_${e}_${c}`))})}function Lr({name:e,value:t,enumValues:o,size:a}){return r.jsx("div",{className:"flex flex-wrap gap-1.5",children:t&&t.map((n,i)=>r.jsx(ae,{children:r.jsx(Ie,{enumKey:n,enumValues:o,size:a!=="medium"?"small":"medium"})},`preview_array_ref_${e}_${i}`))})}function Ur({propertyKey:e,value:t,property:o,size:a}){if(o.dataType!=="array")throw Error("Picked wrong preview component ArrayEnumPreview");const n=o.of;if(!n.enumValues)throw Error("Picked wrong preview component ArrayEnumPreview");return t?r.jsx(Lr,{name:e,value:t,enumValues:n.enumValues,size:a}):null}function Fa({propertyKey:e,value:t,property:o,size:a}){const n=oe(),i=Xe({propertyKey:e,property:o,fields:n.propertyConfigs});if(Array.isArray(i.of))throw Error("Using array properties instead of single one in `of` in ArrayProperty");if(!i.of||i.dataType!=="array"||i.of.dataType!=="string")throw Error("Picked wrong preview component ArrayOfStringsPreview");if(t&&!Array.isArray(t))return r.jsx("div",{children:`Unexpected value: ${t}`});const s=i.of;return r.jsx("div",{className:"flex flex-col gap-2",children:t&&t.map((l,c)=>r.jsx("div",{children:r.jsx(ae,{children:r.jsx(Yr,{propertyKey:e,property:s,value:l,size:a})})},`preview_array_strings_${e}_${c}`))})}function Na({propertyKey:e,value:t,property:o,size:a}){const n=oe(),i=Xe({propertyKey:e,property:o,fields:n.propertyConfigs});if(i?.dataType!=="array")throw Error("Picked wrong preview component ArrayPreview");if(!i?.oneOf)throw Error(`You need to specify an 'of' or 'oneOf' prop (or specify a custom field) in your array property ${e}`);const s=t;if(!s)return null;const l=a==="medium"?"small":"tiny",c=i.oneOf.typeField??wt,u=i.oneOf.valueField??Vt,m=i.oneOf.properties;return r.jsx("div",{className:"flex flex-col",children:s&&s.map((g,f)=>r.jsx(d.Fragment,{children:r.jsx("div",{className:p.cn(p.defaultBorderMixin,"m-1 border-b last:border-b-0"),children:r.jsx(ae,{children:g&&r.jsx(we,{propertyKey:e,value:g[u],property:i.resolvedProperties[f]??m[g[c]],size:l})})})},"preview_array_"+g+"_"+f))})}function Pa({propertyKey:e,value:t,property:o,size:a}){if(o.dataType!=="map")throw Error("Picked wrong preview component MapPropertyPreview");const n=o;if(!n.properties||Object.keys(n.properties??{}).length===0)return r.jsx($r,{value:t});if(!t)return null;const i=Object.keys(n.properties);return a==="tiny"?r.jsx("div",{className:"w-full flex flex-col space-y-1 md:space-y-2",children:i.map((s,l)=>r.jsx("div",{children:r.jsx(ae,{children:r.jsx(we,{propertyKey:s,value:t[s],property:n.properties[s],size:a})},"map_preview_"+n.name+s+l)},`map_${s}`))}):r.jsx("div",{className:"flex flex-col gap-1 w-full",children:i&&i.map((s,l)=>{const c=n.properties[s];return r.jsxs("div",{className:p.cn(p.defaultBorderMixin,"last:border-b-0 border-b"),children:[r.jsxs("div",{className:"flex flex-row pt-0.5 pb-0.5 gap-2",children:[r.jsx("div",{className:"min-w-[140px] w-[25%] py-1",children:r.jsx(p.Typography,{variant:"caption",className:"font-mono break-words",color:"secondary",children:c.name})}),r.jsx("div",{className:"flex-grow max-w-[75%]",children:r.jsx(ae,{children:!(c.dataType==="map"||c==="array")&&r.jsx(we,{propertyKey:s,value:t[s],property:c,size:a})})})]}),(c.dataType==="map"||c==="array")&&r.jsx("div",{className:p.cn(p.defaultBorderMixin,"border-l pl-4 ml-2 my-2"),children:r.jsx(we,{propertyKey:s,value:t[s],property:c,size:a})})]},`map_preview_table_${s}}`)})})}function $r({value:e}){return typeof e!="object"?null:e?r.jsx("div",{className:"flex flex-col gap-1 w-full",children:Object.entries(e).map(([t,o])=>r.jsxs("div",{className:p.cn(p.defaultBorderMixin,"last:border-b-0 border-b"),children:[r.jsxs("div",{className:"flex flex-row pt-0.5 pb-0.5 gap-2",children:[r.jsx("div",{className:"min-w-[140px] w-[25%] py-1",children:r.jsx(p.Typography,{variant:"caption",className:"font-mono break-words",color:"secondary",children:t})},`table-cell-title-${t}-${t}`),r.jsx("div",{className:"flex-grow max-w-[75%]",children:typeof o!="object"&&r.jsx(p.Typography,{children:r.jsx(ae,{children:o&&o.toString()})})})]}),typeof o=="object"&&r.jsx("div",{className:p.cn(p.defaultBorderMixin,"border-l pl-4"),children:r.jsx($r,{value:o})})]},`map_preview_table_${t}}`))}):r.jsx(et,{})}function Ta({date:e}){const t=oe(),o=t?.locale?Jn[t?.locale]:void 0,a=t?.dateTimeFormat??jo,n=e?Gn.format(e,a,{locale:o}):"";return r.jsx(r.Fragment,{children:n})}function Da({value:e,size:t,property:o}){return r.jsxs("div",{className:"flex flex-row gap-2 items-center",children:[r.jsx(p.Checkbox,{checked:e,padding:!1,size:t,color:"secondary"}),o.name&&r.jsx("span",{className:p.cn("text-text-secondary dark:text-text-secondary-dark",t==="tiny"?"text-sm":""),children:o.name})]})}function Qa({value:e,property:t,size:o}){if(t.enumValues){const a=e,n=qe(t.enumValues);return n?r.jsx(Ie,{enumKey:a,enumValues:n,size:o!=="medium"?"small":"medium"}):r.jsx(r.Fragment,{children:e})}else return r.jsx(r.Fragment,{children:e})}const we=d.memo(function(t){const o=oe();let a;const{property:n,propertyKey:i,value:s,size:l,height:c,width:u}=t,m=Pe({propertyKey:i,propertyOrBuilder:n,fields:o.propertyConfigs});if(s===void 0||m===null)a=r.jsx(et,{});else if(m.Preview)a=d.createElement(m.Preview,{propertyKey:i,value:s,property:m,size:l,height:c,width:u,customProps:m.customProps});else if(s===null)a=r.jsx(et,{});else if(m.dataType==="string"){const g=m;typeof s=="string"?g.url?typeof g.url=="boolean"?a=r.jsx(Et,{size:t.size,url:s}):typeof g.url=="string"&&(a=r.jsx(Et,{size:t.size,url:s,previewType:g.url})):g.storage?a=r.jsx(_a,{storeUrl:m.storage?.storeUrl??!1,size:t.size,storagePathOrDownloadUrl:s}):g.markdown?a=r.jsx(p.Markdown,{source:s,size:"small"}):a=r.jsx(Yr,{...t,property:g,value:s}):a=rt(i,m.dataType,s)}else if(m.dataType==="array")if(s instanceof Array){const g=m;if(!g.of&&!g.oneOf)throw Error(`You need to specify an 'of' or 'oneOf' prop (or specify a custom field) in your array property ${i}`);g.of?Array.isArray(g.of)?a=r.jsx(jr,{...t,value:s,property:m}):g.of.dataType==="reference"?a=r.jsx(Sa,{...t,value:s,property:m}):g.of.dataType==="string"?g.of.enumValues?a=r.jsx(Ur,{...t,value:s,property:m}):g.of.storage?a=r.jsx(Ia,{...t,value:s,property:m}):a=r.jsx(Fa,{...t,value:s,property:m}):g.of.dataType==="number"&&g.of.enumValues?a=r.jsx(Ur,{...t,value:s,property:m}):a=r.jsx(jr,{...t,value:s,property:m}):g.oneOf&&(a=r.jsx(Na,{...t,value:s,property:m}))}else a=rt(i,m.dataType,s);else m.dataType==="map"?typeof s=="object"?a=r.jsx(Pa,{...t,property:m}):a=rt(i,m.dataType,s):m.dataType==="date"?s instanceof Date?a=r.jsx(Ta,{date:s}):a=rt(i,m.dataType,s):m.dataType==="reference"?typeof m.path=="string"?typeof s=="object"&&"isEntityReference"in s&&s.isEntityReference()?a=r.jsx(Oe,{disabled:!m.path,previewProperties:m.previewProperties,size:t.size,reference:s}):a=rt(i,m.dataType,s):a=r.jsx(et,{}):m.dataType==="boolean"?typeof s=="boolean"?a=r.jsx(Da,{value:s,size:l,property:m}):a=rt(i,m.dataType,s):m.dataType==="number"?typeof s=="number"?a=r.jsx(Qa,{...t,value:s,property:m}):a=rt(i,m.dataType,s):a=JSON.stringify(s);return a==null||Array.isArray(a)&&a.length===0?r.jsx(et,{}):a},L);function rt(e,t,o){return console.warn(`Unexpected value for property ${e}, of type ${t}`,o),r.jsx(ye,{title:"Unexpected value",error:`${JSON.stringify(o)}`})}function ds({propertyKey:e,value:t,property:o,size:a}){const n=oe(),i=Xe({propertyKey:e,property:o,fields:n.propertyConfigs});if(Array.isArray(i?.of))throw Error("Using array properties instead of single one in `of` in ArrayProperty");if(i?.dataType!=="array"||!i.of||i.of.dataType!=="map")throw Error("Picked wrong preview component ArrayOfMapsPreview");const s=i.of,l=s.properties;if(!l)throw Error(`You need to specify a 'properties' prop (or specify a custom field) in your map property ${e}`);const c=t,u=s.previewProperties;if(!c)return null;let m=u;return(!m||!m.length)&&(m=Object.keys(l),a&&(m=m.slice(0,3))),r.jsx("div",{className:"table-auto text-xs",children:r.jsx("div",{children:c&&c.map((g,f)=>r.jsx("div",{className:"border-b last:border-b-0",children:m&&m.map(h=>r.jsx("div",{className:"table-cell",children:r.jsx(ae,{children:r.jsx(we,{propertyKey:h,value:g[h],property:l[h],size:"small"})})},`table-cell-${h}`))},`table_${g}_${f}`))})})}const ps=it.memo(function({builder:t}){const[o,a]=d.useState(!0),[n,i]=d.useState(null);return d.useEffect(()=>{let s=!1;return t.then(l=>{s||(a(!1),i(l))}).catch(l=>{a(!1),console.error(l)}),()=>{s=!0}},[t]),o?r.jsx(p.Skeleton,{}):r.jsx(it.Fragment,{children:n})});function qr({entity:e,collection:t,path:o,className:a}){const n=oe(),s=d.useMemo(()=>Ne({collection:t,path:o,entityId:e.id,values:e.values,fields:n.propertyConfigs}),[t,o,e]).properties;return r.jsx("div",{className:"w-full "+a,children:r.jsxs("div",{className:"w-full mb-4",children:[r.jsxs("div",{className:p.cn(p.defaultBorderMixin,"flex justify-between py-2 border-b last:border-b-0"),children:[r.jsx("div",{className:"flex items-center w-1/4",children:r.jsx("span",{className:"pl-2 text-sm text-gray-600",children:"Id"})}),r.jsxs("div",{className:"flex-grow p-2 ml-2 w-3/4 text-gray-900 dark:text-white min-h-[56px] flex items-center",children:[r.jsx("span",{className:"flex-grow mr-2",children:e.id}),n?.entityLinkBuilder&&r.jsx("a",{href:n.entityLinkBuilder({entity:e}),rel:"noopener noreferrer",target:"_blank",children:r.jsx(p.IconButton,{children:r.jsx(p.OpenInNewIcon,{size:"small"})})})]})]}),Object.entries(s).map(([l,c])=>{const u=e.values?.[l];return r.jsxs("div",{className:p.cn(p.defaultBorderMixin,"flex justify-between py-2 border-b last:border-b-0"),children:[r.jsx("div",{className:"flex items-center w-1/4",children:r.jsx("span",{className:"pl-2 text-sm text-gray-600",children:c.name})}),r.jsx("div",{className:"flex-grow p-2 ml-2 w-3/4 text-gray-900 dark:text-white min-h-[56px] flex items-center",children:r.jsx(we,{propertyKey:l,value:u,property:c,size:"medium"})})]},`reference_previews_${l}`)})]})})}function us(e){const t=d.useRef(null),{disabled:o,value:a,multiline:n,updateValue:i,focused:s}=e,l=d.useRef(a),[c,u]=d.useState(a),m=d.useRef(!1);d.useEffect(()=>{l.current!==a&&a!==c&&u(a),l.current=a},[a]);const g=d.useCallback(()=>{!a&&!c||c!==a&&(l.current=c,i(c))},[c,i,a]);return Ut(c,g,!s,2e3),d.useEffect(()=>{t.current&&s&&!m.current?(m.current=!0,t.current.focus({preventScroll:!0}),t.current.selectionStart=t.current.value.length,t.current.selectionEnd=t.current.value.length):m.current=s},[s,t]),r.jsx(p.TextareaAutosize,{ref:t,style:{padding:0,margin:0,width:"100%",color:"unset",fontWeight:"unset",lineHeight:"unset",fontSize:"unset",fontFamily:"unset",background:"unset",border:"unset",resize:"none",outline:"none"},value:c??"",onChange:f=>{const h=f.target.value;(n||!h.endsWith(`
|
|
5
|
-
`))&&u(h)},onFocus:()=>{m.current=!0},onBlur:()=>{m.current=!1,g()}})}function Wr(e){const{name:t,enumValues:o,error:a,internalValue:n,disabled:i,small:s,focused:l,updateValue:c,multiple:u,valueType:m}=e,g=Array.isArray(n)&&u||!Array.isArray(n)&&!u,f=d.useRef(null);d.useEffect(()=>{f.current&&l&&f.current?.focus({preventScroll:!0})},[l,f]);const h=d.useCallback(y=>{if(m==="number")if(u){const A=y.map(k=>parseFloat(k));c(A)}else c(parseFloat(y));else if(m==="string")c(y||null);else throw Error("Missing mapping in TableSelect")},[u,c,m]),b=(y,A)=>u&&Array.isArray(y)?r.jsx(Lr,{value:y,name:t,enumValues:o,size:s?"small":"medium"},`${y}-${A}`):r.jsx(Ie,{enumKey:y,enumValues:o,size:s?"small":"medium"},`${y}-${A}`);return u?r.jsx(p.MultiSelect,{inputRef:f,containerClassName:"w-full h-full",className:"w-full h-full p-0 bg-transparent",position:"item-aligned",disabled:i,padding:!1,includeFocusOutline:!1,value:g?n.map(y=>y.toString()):[],onMultiValueChange:h,renderValue:b,children:o?.map(y=>r.jsx(p.MultiSelectItem,{value:String(y.id),children:r.jsx(Ie,{enumKey:y.id,enumValues:o,size:s?"small":"medium"})},y.id))}):r.jsx(p.Select,{inputRef:f,className:"w-full h-full p-0 bg-transparent",position:"item-aligned",disabled:i,multiple:u,padding:!1,includeFocusOutline:!1,value:g?u?n.map(y=>y.toString()):n?.toString():u?[]:"",onValueChange:h,onMultiValueChange:h,renderValue:b,children:o?.map(y=>r.jsx(p.SelectItem,{value:String(y.id),children:r.jsx(Ie,{enumKey:y.id,enumValues:o,size:s?"small":"medium"})},y.id))})}function ms(e){const{align:t,value:o,updateValue:a,focused:n}=e,i=o&&typeof o=="number"?o.toString():"",[s,l]=d.useState(i),c=d.useRef(o);d.useEffect(()=>{c.current!==o&&String(o)!==s&&l(o?o.toString():null),c.current=o},[o]);const u=d.useCallback(()=>{if(s!==i)if(s!=null){const f=parseFloat(s);if(isNaN(f))return;f!=null&&a(f)}else a(null)},[s,o]);Ut(s,u,!n,2e3),d.useEffect(()=>{!n&&i!==s&&l(o!=null?o.toString():null)},[o,n]);const m=d.useRef(null);d.useEffect(()=>{m.current&&n&&m.current.focus({preventScroll:!0})},[n,m]);const g=/^-?[0-9]+[,.]?[0-9]*$/;return r.jsx("input",{ref:m,className:"w-full text-right p-0 m-0 bg-transparent border-none resize-none outline-none font-normal leading-normal text-unset",style:{textAlign:t},value:s??"",onChange:f=>{const h=f.target.value.replace(",",".");h.length===0&&l(null),(g.test(h)||h.startsWith("-"))&&l(h)}})}function fs(e){const{internalValue:t,updateValue:o,focused:a}=e,n=d.useRef(null);return d.useEffect(()=>{n.current&&a&&n.current.focus({preventScroll:!0})},[a,n]),r.jsx(p.BooleanSwitch,{ref:n,size:"small",value:!!t,onValueChange:o})}function hs(e){const{locale:t}=oe(),{disabled:o,error:a,mode:n,internalValue:i,updateValue:s}=e;return r.jsx(p.DateTimeField,{value:i??void 0,onChange:l=>s(l??null),size:"medium",invisible:!0,className:"w-full h-full",inputClassName:"w-full h-full",mode:n,locale:t})}class ae extends d.Component{constructor(t){super(t),this.state={error:null}}static getDerivedStateFromError(t){return{error:t}}componentDidCatch(t,o){console.error(t)}render(){return this.state.error?r.jsxs("div",{className:"flex flex-col m-2",children:[r.jsxs("div",{className:"flex items-center m-2",children:[r.jsx(p.ErrorIcon,{color:"error",size:"small"}),r.jsx("div",{className:"ml-4",children:"Error"})]}),r.jsx(p.Typography,{variant:"caption",children:this.state.error?.message??"See the error in the console"})]}):this.props.children}}async function gs(e,t,o,a,n,i,s,l){let c;return typeof e=="function"?(c=await e({path:n,entityId:a,values:o,property:i,file:s,storage:t,propertyKey:l}),c||console.warn("Storage callback returned empty result. Using default name value")):c=Ma(s,e,a,l,n),c||(c=lt()+"_"+s.name),c}function As(e,t,o,a,n,i,s,l){let c;return typeof e=="function"?(c=e({path:n,entityId:a,values:o,property:i,file:s,storage:t,propertyKey:l}),c||console.warn("Storage callback returned empty result. Using default name value")):c=Ma(s,e,a,l,n),c||(c=lt()+"_"+s.name),c}function Ma(e,t,o,a,n){const i=e.name.split(".").pop();let s=t.replace("{entityId}",o).replace("{propertyKey}",a).replace("{rand}",lt()).replace("{file}",e.name).replace("{file.type}",e.type).replace("{path}",n);if(i){s=s.replace("{file.ext}",i);const l=e.name.replace(`.${i}`,"");s=s.replace("{file.name}",l)}return s||(s=lt()+"_"+e.name),s}function Oa({entityId:e,entityValues:t,path:o,value:a,property:n,propertyKey:i,storageSource:s,disabled:l,onChange:c}){const u=n.dataType==="string"?n.storage:n.dataType==="array"&&n.of.dataType==="string"?n.of.storage:void 0,m=n.dataType==="array";if(!u)throw Error("Storage meta must be specified");const g=u?.metadata,f=m?"small":"medium",h=u?.imageCompression,b=(m?a??[]:a?[a]:[]).map(x=>({id:Jr(),storagePathOrDownloadUrl:x,metadata:g,size:f})),[y,A]=d.useState(a),[k,v]=d.useState(b);d.useEffect(()=>{L(y,a)||(A(a),v(b))},[b,a,y]);const _=d.useCallback(async x=>{if(u.fileName){const S=await gs(u.fileName,u,t,e,o,n,x,i);if(!S||S.length===0)throw Error("You need to return a valid filename");return S}return lt()+"_"+x.name},[e,t,o,n,i,u]),E=d.useCallback(x=>As(u.storagePath,u,t,e,o,n,x,i)??"/",[e,t,o,n,i,u]),C=d.useCallback(async(x,S,I)=>{console.debug("onFileUploadComplete",x,S);let D=x;if(u.storeUrl&&(D=(await s.getDownloadURL(x)).url),u.postProcess&&D&&(D=await u.postProcess(D)),!D){console.warn("uploadPathOrDownloadUrl is null");return}let P;S.storagePathOrDownloadUrl=D,S.metadata=I,P=[...k],P=za(P),v(P);const T=P.filter(V=>!!V.storagePathOrDownloadUrl).map(V=>V.storagePathOrDownloadUrl);c(m?T:T?T[0]:null)},[k,m,c,u,s]),B=d.useCallback(async x=>{if(!x.length||l)return;let S;if(m)S=[...k,...await Promise.all(x.map(async I=>(h&&Hr(I)&&(I=await Ga(I,h)),{id:Jr(),file:I,fileName:await _(I),metadata:g,size:f})))];else{let I=x[0];h&&Hr(I)&&(I=await Ga(I,h)),S=[{id:Jr(),file:I,fileName:await _(I),metadata:g,size:f}]}S=za(S),v(S)},[l,_,k,g,m,f]);return{internalValue:k,setInternalValue:v,storage:u,fileNameBuilder:_,storagePathBuilder:E,onFileUploadComplete:C,onFilesAdded:B,multipleFilesSupported:m}}function za(e){return e.filter((t,o)=>(e.map(a=>a.storagePathOrDownloadUrl).indexOf(t.storagePathOrDownloadUrl)===o||!t.storagePathOrDownloadUrl)&&(e.map(a=>a.file).indexOf(t.file)===o||!t.file))}function Jr(){return Math.floor(Math.random()*Math.floor(Number.MAX_SAFE_INTEGER))}const Va={"image/jpeg":"JPEG","image/png":"PNG","image/webp":"WEBP"},Hr=e=>Va[e.type]?Va[e.type]:null,bs=100,Ga=(e,t)=>new Promise(o=>{const a=t.quality===void 0?bs:t.quality,n=a>=0&&a<=100?a:100,i=Hr(e);if(!i)throw Error("resizeAndCompressImage: Unsupported image format");jn.imageFileResizer(e,t.maxWidth||Number.MAX_VALUE,t.maxHeight||Number.MAX_VALUE,i,n,0,s=>o(s),"file")});function Ya({storagePath:e,entry:t,metadata:o,onFileUploadComplete:a,imageSize:n,simple:i}){const s=dt(),l=He(),[c,u]=d.useState(),[m,g]=d.useState(!1),f=d.useRef(!1),h=d.useRef(!1),b=d.useCallback((y,A)=>{h.current||(h.current=!0,u(void 0),g(!0),s.uploadFile({file:y,fileName:A,path:e,metadata:o}).then(async({path:k})=>{console.debug("Upload successful"),await a(k,t,o),f.current&&g(!1)}).catch(k=>{console.warn("Upload error",k),f.current&&(u(k),g(!1),l.open({type:"error",message:"Error uploading file: "+k.message}))}).finally(()=>{h.current=!1}))},[t,o,a,s,e]);return d.useEffect(()=>(f.current=!0,t.file&&b(t.file,t.fileName),()=>{f.current=!1}),[t.file,t.fileName,b]),i?r.jsx("div",{className:`m-4 w-${n} h-${n}`,children:m&&r.jsx(p.Skeleton,{className:`w-${n} h-${n}`})}):r.jsxs("div",{className:p.cn(p.paperMixin,"relative m-4 border-box flex items-center justify-center",`min-w-[${n}px] min-h-[${n}px]`),children:[m&&r.jsx(p.Skeleton,{className:"w-full h-full"}),c&&r.jsx(ye,{title:"Error uploading file",error:c})]})}function ja({showError:e,disabled:t,showExpandIcon:o,selected:a,openPopup:n,children:i}){const s=d.useRef(null),l=d.useCallback(()=>{if(n){const u=s&&s?.current?.getBoundingClientRect();n(u)}},[]),c=d.useRef();return d.useEffect(()=>{c.current&&a&&c.current.focus({preventScroll:!0})},[a]),r.jsx(r.Fragment,{children:(e||!t&&o)&&r.jsxs("div",{ref:s,className:"absolute top-0.5 right-0.5 flex items-center",children:[a&&i,a&&!t&&o&&r.jsx(p.IconButton,{ref:c,color:"inherit",size:"small",onClick:l,children:r.jsxs("svg",{fill:"#888",width:"20",height:"20",viewBox:"0 0 24 24",children:[r.jsx("path",{className:"cls-2",d:"M20,5a1,1,0,0,0-1-1L14,4h0a1,1,0,0,0,0,2h2.57L13.29,9.29a1,1,0,0,0,0,1.42,1,1,0,0,0,1.42,0L18,7.42V10a1,1,0,0,0,1,1h0a1,1,0,0,0,1-1Z"}),r.jsx("path",{className:"cls-2",d:"M10.71,13.29a1,1,0,0,0-1.42,0L6,16.57V14a1,1,0,0,0-1-1H5a1,1,0,0,0-1,1l0,5a1,1,0,0,0,1,1h5a1,1,0,0,0,0-2H7.42l3.29-3.29A1,1,0,0,0,10.71,13.29Z"})]})}),e&&r.jsx(Go,{side:"left",className:"flex items-center justify-center",style:{width:32,height:32},title:e.message,children:r.jsx(p.ErrorOutlineIcon,{size:"small",color:"error"})})]})})}const ys="max-w-full box-border relative pt-[2px] items-center border border-transparent outline-none rounded-md duration-200 ease-[cubic-bezier(0.4,0,0.2,1)] focus:border-primary-solid",ws="pt-0 border-2 border-solid",vs="transition-colors duration-200 ease-[cubic-bezier(0,0,0.2,1)] border-2 border-solid border-green-500 bg-green-50 dark:bg-green-900",ks="transition-colors duration-200 ease-[cubic-bezier(0,0,0.2,1)] border-2 border-solid border-red-500 bg-red-50 dark:bg-red-900";function _s(e){const{propertyKey:t,error:o,selected:a,openPopup:n,value:i,disabled:s,property:l,entity:c,path:u,previewSize:m,updateValue:g}=e,f=dt(),{internalValue:h,setInternalValue:b,onFilesAdded:y,storage:A,onFileUploadComplete:k,storagePathBuilder:v,multipleFilesSupported:_}=Oa({entityValues:c.values,entityId:c.id,path:u,property:l,propertyKey:t,storageSource:f,onChange:g,value:i,disabled:s});return r.jsx(xs,{internalValue:h,setInternalValue:b,name:t,disabled:s,autoFocus:!1,openPopup:n,error:o,selected:a,property:l,onChange:g,entity:c,storagePathBuilder:v,storage:A,multipleFilesSupported:_,onFilesAdded:y,onFileUploadComplete:k,previewSize:m})}function xs({property:e,name:t,internalValue:o,setInternalValue:a,openPopup:n,entity:i,selected:s,error:l,onChange:c,multipleFilesSupported:u,previewSize:m,disabled:g,autoFocus:f,storage:h,onFilesAdded:b,onFileUploadComplete:y,storagePathBuilder:A}){const[k,v]=d.useState(!1),_=u&&m==="medium"?"small":m;if(u){const z=e;if(Array.isArray(z.of))throw Error("Using array properties instead of single one in `of` in ArrayProperty");if(z.of){if(z.of.dataType!=="string")throw Error("Storage field using array must be of data type string")}else throw Error("Storage field using array must be of data type string")}const E=h?.metadata,C=!!o,B=He(),{open:x,getRootProps:S,getInputProps:I,isDragActive:D,isDragAccept:P,isDragReject:T}=No.useDropzone({accept:h.acceptedFiles?h.acceptedFiles.map(z=>({[z]:[]})).reduce((z,H)=>({...z,...H}),{}):void 0,disabled:g,maxSize:h.maxSize,noClick:!0,noKeyboard:!0,onDrop:b,onDropRejected:(z,H)=>{for(const J of z)for(const ee of J.errors)B.open({type:"error",message:`Error uploading file: File is larger than ${h.maxSize} bytes`})}}),{...V}=S(),re=u?"Drag 'n' drop some files here, or click here to edit":"Drag 'n' drop a file here, or click here edit",R=u?e.of:e,$=d.useMemo(()=>ft(_),[_]),G=!g&&l;return r.jsxs("div",{...V,onMouseEnter:()=>v(!0),onMouseMove:()=>v(!0),onMouseLeave:()=>v(!1),className:p.cn(ys,"relative w-full h-full flex",`justify-${C?"start":"center"}`,D?ws:"",P?vs:"",T?ks:""),children:[r.jsx("input",{autoFocus:f,...I()}),o.map((z,H)=>{let J;return z.storagePathOrDownloadUrl?J=r.jsx(Cs,{property:R,value:z.storagePathOrDownloadUrl,entity:i,size:_},`storage_preview_${H}`):z.file&&(J=r.jsx(Ya,{entry:z,metadata:E,storagePath:A(z.file),onFileUploadComplete:y,imageSize:$,simple:!0},`storage_progress_${H}`)),J}),!o&&r.jsx("div",{className:"flex-grow m-2 max-w-[200px]",onClick:x,children:r.jsx(p.Typography,{className:"text-gray-400 dark:text-gray-600",variant:"body2",align:"center",children:re})}),r.jsx(ja,{showError:G,disabled:g,showExpandIcon:!0,selected:s,openPopup:g?void 0:n,children:r.jsx(p.IconButton,{color:"inherit",size:"small",onClick:x,children:r.jsx(p.EditIcon,{size:"small",className:"text-gray-500"})})})]})}function Cs({property:e,value:t,size:o,entity:a}){return r.jsx("div",{className:"relative p-2 max-w-full",children:t&&r.jsx(ae,{children:r.jsx(we,{propertyKey:"ignore",value:t,property:e,size:o})})})}function La(e){const t=oe(),o=pe(),{path:a}=e,n=o.getCollection(a);if(!n){if(t.components?.missingReference)return r.jsx(t.components.missingReference,{path:a});throw Error(`Couldn't find the corresponding collection view for the path: ${a}`)}return r.jsx(Es,{...e,collection:n})}const Es=d.memo(function(t){const{name:o,internalValue:a,updateValue:n,multiselect:i,path:s,size:l,previewProperties:c,title:u,disabled:m,forceFilter:g,collection:f}=t,h=d.useCallback(C=>{n(C?je(C):null)},[n]),b=d.useCallback(C=>{n(C.map(B=>je(B)))},[n]),y=a?Array.isArray(a)?a.map(C=>C.id):a.id?[a.id]:[]:[],A=mt({multiselect:i,path:s,collection:f,onMultipleEntitiesSelected:b,onSingleEntitySelected:h,selectedEntityIds:y,forceFilter:g}),k=d.useCallback(()=>{m||A.open()},[m,A]),v=!a||Array.isArray(a)&&a.length===0,_=()=>a&&!Array.isArray(a)&&a.isEntityReference&&a.isEntityReference()?r.jsx(Oe,{onClick:m?void 0:k,size:Ze(l),reference:a,hover:!m,disabled:!s,previewProperties:c}):r.jsx(ht,{onClick:m?void 0:k,size:Ze(l),children:r.jsx(ye,{title:"Value is not a reference.",error:"Click to edit"})}),E=()=>Array.isArray(a)?r.jsx(r.Fragment,{children:a.map((C,B)=>r.jsx("div",{className:"w-full my-0.5",children:r.jsx(Oe,{onClick:m?void 0:k,size:"tiny",reference:C,hover:!m,disabled:!s,previewProperties:c})},`preview_array_ref_${o}_${B}`))}):r.jsx(ye,{error:"Data is not an array of references"});return f?r.jsxs("div",{className:"w-full group",children:[a&&!i&&_(),a&&i&&E(),v&&r.jsxs(p.Button,{onClick:k,size:"small",variant:"outlined",color:"primary",children:["Edit ",u]})]}):r.jsx(ye,{error:"The specified collection does not exist"})},L);Fe.addMethod(Fe.array,"uniqueInArray",function(e=o=>o,t){return this.test("uniqueInArray",t,o=>!o||o.length===new Set(o.map(e)).size)});function Ua(e,t,o){const a={};return Object.entries(t).forEach(([n,i])=>{a[n]=Bt({property:i,customFieldValidator:o,name:n,entityId:e})}),Fe.object().shape(a)}function Bt(e){const t=e.property;if(ke(t))throw console.error("Error in property",e),Error("Trying to create a yup mapping from a property builder. Please use resolved properties only");if(t.dataType==="string")return Ss(e);if(t.dataType==="number")return Is(e);if(t.dataType==="boolean")return Ts(e);if(t.dataType==="map")return Bs(e);if(t.dataType==="array")return Qs(e);if(t.dataType==="date")return Ns(e);if(t.dataType==="geopoint")return Fs(e);if(t.dataType==="reference")return Ps(e);throw console.error("Unsupported data type in yup mapping",t),Error("Unsupported data type in yup mapping")}function Bs({property:e,entityId:t,customFieldValidator:o,name:a}){const n={},i=e.validation;e.properties&&Object.entries(e.properties).forEach(([l,c])=>{n[l]=Bt({property:c,parentProperty:e,customFieldValidator:o,name:`${a}[${l}]`,entityId:t})});const s=Fe.object().shape(n);return i?.required?s.required(i?.requiredMessage?i.requiredMessage:"Required").nullable(!0):s.nullable(!0)}function Ss({property:e,parentProperty:t,customFieldValidator:o,name:a,entityId:n}){let i=Fe.string();const s=e.validation;if(e.enumValues){s?.required&&(i=i.required(s?.requiredMessage?s.requiredMessage:"Required"));const l=qe(e.enumValues);i=i.oneOf((s?.required?l:[...l,null]).map(c=>c?.id??null)).nullable(!0)}if(s){if(i=s.required?i.required(s?.requiredMessage?s.requiredMessage:"Required").nullable(!0):i.notRequired().nullable(!0),s.unique&&o&&a&&(i=i.test("unique","This value already exists and should be unique",(l,c)=>o({name:a,property:e,parentProperty:t,value:l,entityId:n}))),(s.min||s.min===0)&&(i=i.min(s.min,`${e.name} must be min ${s.min} characters long`)),(s.max||s.max===0)&&(i=i.max(s.max,`${e.name} must be max ${s.max} characters long`)),s.matches){const l=typeof s.matches=="string"?$o(s.matches):s.matches;l&&(i=i.matches(l,s.matchesMessage?{message:s.matchesMessage}:void 0))}s.trim&&(i=i.trim()),s.lowercase&&(i=i.lowercase()),s.uppercase&&(i=i.uppercase()),e.email&&(i=i.email(`${e.name} must be an email`)),e.url&&(i=i.url(`${e.name} must be a url`))}else i=i.notRequired().nullable(!0);return i}function Is({property:e,parentProperty:t,customFieldValidator:o,name:a,entityId:n}){const i=e.validation;let s=Fe.number().typeError("Must be a number");return i?(s=i.required?s.required(i.requiredMessage?i.requiredMessage:"Required").nullable(!0):s.notRequired().nullable(!0),i.unique&&o&&a&&(s=s.test("unique","This value already exists and should be unique",l=>o({name:a,property:e,parentProperty:t,value:l,entityId:n}))),(i.min||i.min===0)&&(s=s.min(i.min,`${e.name} must be higher or equal to ${i.min}`)),(i.max||i.max===0)&&(s=s.max(i.max,`${e.name} must be lower or equal to ${i.max}`)),(i.lessThan||i.lessThan===0)&&(s=s.lessThan(i.lessThan,`${e.name} must be higher than ${i.lessThan}`)),(i.moreThan||i.moreThan===0)&&(s=s.moreThan(i.moreThan,`${e.name} must be lower than ${i.moreThan}`)),i.positive&&(s=s.positive(`${e.name} must be positive`)),i.negative&&(s=s.negative(`${e.name} must be negative`)),i.integer&&(s=s.integer(`${e.name} must be an integer`))):s=s.notRequired().nullable(!0),s}function Fs({property:e,parentProperty:t,customFieldValidator:o,name:a,entityId:n}){let i=Fe.object();const s=e.validation;return s?.unique&&o&&a&&(i=i.test("unique","This value already exists and should be unique",l=>o({name:a,property:e,parentProperty:t,value:l,entityId:n}))),s?.required?i=i.required(s.requiredMessage).nullable(!0):i=i.notRequired().nullable(!0),i}function Ns({property:e,parentProperty:t,customFieldValidator:o,name:a,entityId:n}){if(e.autoValue)return Fe.object().nullable();let i=Fe.date();const s=e.validation;return s?(i=s.required?i.required(s?.requiredMessage?s.requiredMessage:"Required"):i.notRequired(),s.unique&&o&&a&&(i=i.test("unique","This value already exists and should be unique",l=>o({name:a,property:e,parentProperty:t,value:l,entityId:n}))),s.min&&(i=i.min(s.min,`${e.name} must be after ${s.min}`)),s.max&&(i=i.max(s.max,`${e.name} must be before ${s.min}`))):i=i.notRequired(),i.transform(l=>l instanceof Date?l:null).nullable()}function Ps({property:e,parentProperty:t,customFieldValidator:o,name:a,entityId:n}){let i=Fe.object();const s=e.validation;return s?(i=s.required?i.required(s?.requiredMessage?s.requiredMessage:"Required").nullable(!0):i.notRequired().nullable(!0),s.unique&&o&&a&&(i=i.test("unique","This value already exists and should be unique",l=>o({name:a,property:e,parentProperty:t,value:l,entityId:n})))):i=i.notRequired().nullable(!0),i}function Ts({property:e,parentProperty:t,customFieldValidator:o,name:a,entityId:n}){let i=Fe.boolean();const s=e.validation;return s?(i=s.required?i.required(s?.requiredMessage?s.requiredMessage:"Required").nullable(!0):i.notRequired().nullable(!0),s.unique&&o&&a&&(i=i.test("unique","This value already exists and should be unique",l=>o({name:a,property:e,parentProperty:t,value:l,entityId:n})))):i=i.notRequired().nullable(!0),i}function Ds(e){return e.validation?.uniqueInArray?!0:e.dataType==="map"&&e.properties?Object.entries(e.properties).filter(([t,o])=>o.validation?.uniqueInArray):!1}function Qs({property:e,parentProperty:t,customFieldValidator:o,name:a,entityId:n}){let i=Fe.array();if(e.of)if(Array.isArray(e.of)){const l=e.of.map((c,u)=>({[`${a}[${u}]`]:Bt({property:c,parentProperty:e,entityId:n})})).reduce((c,u)=>({...c,...u}),{});return Fe.array().of(Fe.mixed().test("Dynamic object validation","Dynamic object validation error",(c,u)=>Ye(l,u.path).validate(c)))}else{i=i.of(Bt({property:e.of,parentProperty:e,entityId:n}));const l=Ds(e.of);l&&(typeof l=="boolean"?i=i.uniqueInArray(c=>c,`${e.name} should have unique values within the array`):Array.isArray(l)&&l.forEach(([c,u])=>{i=i.uniqueInArray(m=>m&&m[c],`${e.name} → ${u.name??c}: should have unique values within the array`)}))}const s=e.validation;return s?(i=s.required?i.required(s?.requiredMessage?s.requiredMessage:"Required").nullable(!0):i.notRequired().nullable(!0),(s.min||s.min===0)&&(i=i.min(s.min,`${e.name} should be min ${s.min} entries long`)),s.max&&(i=i.max(s.max,`${e.name} should be max ${s.max} entries long`))):i=i.notRequired().nullable(!0),i}function gt(e){switch(e){case"xl":return 400;case"l":return 280;case"m":return 140;case"s":return 80;case"xs":return 54;default:throw Error("Missing mapping for collection size -> height")}}const Ms=({justifyContent:e,scrollable:t,faded:o,fullHeight:a,children:n})=>r.jsx("div",{className:p.cn("flex flex-col max-h-full w-full",{"items-start":o||t}),style:{justifyContent:e,height:a?"100%":void 0,overflow:t?"auto":void 0,WebkitMaskImage:o?"linear-gradient(to bottom, black 60%, transparent 100%)":void 0,maskImage:o?"linear-gradient(to bottom, black 60%, transparent 100%)":void 0},children:n}),er=d.memo(function({children:t,actions:o,size:a,selected:n,disabled:i,disabledTooltip:s,saved:l,error:c,align:u,allowScroll:m,removePadding:g,fullHeight:f,onSelect:h,width:b,hideOverflow:y=!0,showExpandIcon:A=!0}){const[k,v]=Fo(),_=d.useRef(null),E=d.useMemo(()=>gt(a),[a]),[C,B]=d.useState(!1),[x,S]=d.useState(l),I=!i&&!!c;d.useEffect(()=>{l&&S(!0);const ee=setTimeout(()=>{S(!1)},800);return()=>{clearTimeout(ee)}},[l]);let D=0;if(!g)switch(a){case"l":case"xl":D=4;break;case"m":D=2;break;case"s":default:D=1;break}let P;switch(u){case"right":P="flex-end";break;case"center":P="center";break;case"left":default:P="flex-start"}const T=d.useCallback(()=>{if(!h)return;const ee=_&&_?.current?.getBoundingClientRect();i?h(void 0):!n&&ee&&h(ee)},[_,h,n,i]),V=d.useCallback(ee=>{T(),ee.stopPropagation()},[T]),re=d.useMemo(()=>v?v.height>E:!1,[v,E]),R=!I&&n,$=!i&&m&&re,G=!i&&!m&&re,z=d.useCallback(()=>B(!0),[]),H=d.useCallback(()=>B(!1),[]),J=I?"border-red-500":x?"border-green-500":R?"border-primary":"border-transparent";return r.jsxs("div",{className:p.cn("transition-colors duration-100 ease-in-out",`flex relative h-full rounded-md p-${D} border border-4 border-opacity-75`,C&&!i?"bg-gray-50 dark:bg-gray-900":"",l?"bg-gray-100 bg-opacity-75 dark:bg-gray-800 dark:bg-opacity-75":"",y?"overflow-hidden":"",R?"bg-gray-50 dark:bg-gray-900":"",J),ref:_,style:{justifyContent:P,alignItems:i||!re?"center":void 0,width:b??"100%",textAlign:u},tabIndex:n||i?void 0:0,onFocus:V,onMouseEnter:z,onMouseMove:z,onMouseLeave:H,children:[r.jsxs(ae,{children:[f&&!G&&t,(!f||G)&&r.jsx(Ms,{fullHeight:f??!1,justifyContent:P,scrollable:$??!1,faded:G,children:!f&&r.jsx("div",{ref:k,style:{display:"flex",width:"100%",justifyContent:P,height:f?"100%":void 0},children:t})})]}),o,i&&C&&s&&r.jsx("div",{className:"absolute top-1 right-1 text-xs",children:r.jsx(p.Tooltip,{title:s,children:r.jsx(p.RemoveCircleIcon,{size:"smallest",color:"disabled",className:"text-gray-500"})})})]})},(e,t)=>e.error===t.error&&e.value===t.value&&e.disabled===t.disabled&&e.saved===t.saved&&e.allowScroll===t.allowScroll&&e.align===t.align&&e.size===t.size&&e.disabledTooltip===t.disabledTooltip&&e.width===t.width&&e.showExpandIcon===t.showExpandIcon&&e.removePadding===t.removePadding&&e.fullHeight===t.fullHeight&&e.selected===t.selected),$a=d.createContext({}),Os=()=>d.useContext($a);function Te({property:e,value:t,setValue:o}){const a=d.useRef(null);d.useEffect(()=>{typeof e.disabled=="object"&&!!e.disabled.clearOnDisabled?t!=null&&(a.current=t,o(null)):a.current&&(o(a.current),a.current=null)},[e])}function zs(e){return e.dataType==="string"&&e.storage?!0:e.dataType==="array"?Array.isArray(e.of)?!1:e.of?.dataType==="string"&&e.of?.storage:!1}const qa=d.memo(function({propertyKey:t,customFieldValidator:o,value:a,property:n,align:i,width:s,height:l,path:c,entity:u,readonly:m,disabled:g,enablePopupIcon:f=!0}){const{onValueChange:h,size:b,selectedCell:y,select:A,setPopupCell:k}=Os(),v=y?.propertyKey===t&&y?.entity.path===u.path&&y?.entity.id===u.id,[_,E]=d.useState(a),C=d.useRef(a),[B,x]=d.useState(),[S,I]=d.useState(),[D,P]=d.useState(!1),T=d.useCallback(()=>{P(!0),setTimeout(()=>{P(!1)},100)},[]),V=!!n.Field,re=!!n.Preview,R=st(n),$=typeof n.disabled=="object"?n.disabled.disabledMessage:void 0,G=m||g||!!n.disabled,z=d.useMemo(()=>Bt({property:n,entityId:u.id,customFieldValidator:o,name:t}),[u.id,n,t]);d.useEffect(()=>{L(a,C.current)||(I(void 0),E(a),C.current=a,T())},[T,a]);const H=F=>{L(F,C.current)||(P(!1),z.validate(F).then(()=>{if(I(void 0),C.current=F,h)try{h({value:F,propertyKey:t,setError:x,onValueUpdated:T,data:u})}catch(N){console.error("onValueChange error",N),x(N)}}).catch(N=>{I(N)}))};d.useEffect(()=>{z.validate(_).then(()=>I(void 0)).catch(I)},[_,z,t,n,u]);const J=F=>{let N;F===void 0?N=null:N=F,E(N),H(N)};Te({property:n,value:_,setValue:J});const ee=d.useCallback(F=>{A(F?{width:s,height:l,entity:u,cellRect:F,propertyKey:t}:void 0)},[u,l,t,A,s]),ne=F=>{k&&k(F?{width:s,height:l,entity:u,cellRect:F,propertyKey:t}:void 0)};let U,X=!1,Q=!1,K=!0,Z=!1,M=!1,Y=!0;const q=!G&&B;if(m||R)return r.jsx(er,{size:b,width:s,saved:D,value:_,align:i??"left",fullHeight:!1,disabledTooltip:$??(R?"Read only":void 0),disabled:!0,children:r.jsx(we,{width:s,height:gt(b),propertyKey:t,property:n,value:_,size:Ze(b)})},`${t}_${u.path}_${u.id}`);if(!V&&(!re||v)){if(zs(n))U=r.jsx(_s,{error:S??B,disabled:G,focused:v,selected:v,openPopup:k?ne:void 0,property:n,entity:u,path:c,value:_,previewSize:Ze(b),updateValue:J,propertyKey:t}),Y=!1,Q=!0,M=!0,Z=!0;else if(v&&n.dataType==="number"){const N=n;N.enumValues?(U=r.jsx(Wr,{name:t,multiple:!1,disabled:G,focused:v,valueType:"number",small:Ze(b)!=="medium",enumValues:N.enumValues,error:S??B,internalValue:_,updateValue:J}),M=!0):(U=r.jsx(ms,{align:i,error:S??B,focused:v,disabled:G,value:_,updateValue:J}),X=!0)}else if(v&&n.dataType==="string"){const N=n;if(N.enumValues)U=r.jsx(Wr,{name:t,multiple:!1,focused:v,disabled:G,valueType:"string",small:Ze(b)!=="medium",enumValues:N.enumValues,error:S??B,internalValue:_,updateValue:J}),M=!0;else if(!N.storage){const le=!!N.multiline||!!N.markdown;U=r.jsx(us,{error:S??B,disabled:G,multiline:le,focused:v,value:_,updateValue:J}),X=!0}}else if(n.dataType==="boolean")U=r.jsx(fs,{error:S??B,disabled:G,focused:v,internalValue:_,updateValue:J});else if(n.dataType==="date")U=r.jsx(hs,{name:t,error:S??B,disabled:G,mode:n.mode,focused:v,internalValue:_,updateValue:J}),M=!0,K=!1,X=!1;else if(n.dataType==="reference")typeof n.path=="string"&&(U=r.jsx(La,{name:t,internalValue:_,updateValue:J,disabled:G,size:b,path:n.path,multiselect:!1,previewProperties:n.previewProperties,title:n.name,forceFilter:n.forceFilter})),X=!1;else if(n.dataType==="array"){const N=n;if(!N.of&&!N.oneOf)throw Error(`You need to specify an 'of' or 'oneOf' prop (or specify a custom field) in your array property ${t}`);N.of&&!Array.isArray(N.of)&&(N.of.dataType==="string"||N.of.dataType==="number"?v&&N.of.enumValues&&(U=r.jsx(Wr,{name:t,multiple:!0,disabled:G,focused:v,small:Ze(b)!=="medium",valueType:N.of.dataType,enumValues:N.of.enumValues,error:S??B,internalValue:_,updateValue:J}),X=!0,M=!0,K=!1):N.of.dataType==="reference"&&(typeof N.of.path=="string"&&(U=r.jsx(La,{name:t,disabled:G,internalValue:_,updateValue:J,size:b,multiselect:!0,path:N.of.path,previewProperties:N.of.previewProperties,title:N.name,forceFilter:N.of.forceFilter})),X=!1))}}return U||(X=!1,Q=f&&v&&!U&&!G&&!R,U=r.jsx(we,{width:s,height:l,propertyKey:t,value:_,property:n,size:Ze(b)})),r.jsx(er,{size:b,width:s,onSelect:ee,selected:v,disabled:G||R,disabledTooltip:$??"Disabled",removePadding:Z,fullHeight:M,saved:D,error:S??B,align:i,allowScroll:X,showExpandIcon:Q,value:_,hideOverflow:K,actions:Y&&r.jsx(ja,{showError:q,disabled:G,showExpandIcon:Q,selected:v,openPopup:G?void 0:ne}),children:U},`cell_${t}_${u.path}_${u.id}`)},Vs);function Vs(e,t){return e.height===t.height&&e.propertyKey===t.propertyKey&&e.align===t.align&&e.width===t.width&&L(e.property,t.property)&&L(e.value,t.value)&&L(e.entity.id,t.entity.id)&&L(e.entity.values,t.entity.values)}const tr=function({entity:t,collection:o,fullPath:a,width:n,frozen:i,isSelected:s,selectionEnabled:l,size:c,highlightEntity:u,onCollectionChange:m,unhighlightEntity:g,actions:f=[],hideId:h,selectionController:b}){const y=Qe(),A=Ae(),k=d.useCallback(x=>{b?.toggleEntitySelection(t)},[t,b?.toggleEntitySelection]),v=d.useCallback(x=>{x.stopPropagation(),b?.toggleEntitySelection(t)},[t,b?.toggleEntitySelection]),_=f.length>0,E=f.some(x=>x.collapsed||x.collapsed===void 0),C=f.filter(x=>x.collapsed||x.collapsed===void 0),B=f.filter(x=>x.collapsed===!1);return r.jsxs("div",{onClick:v,className:p.cn("h-full flex items-center justify-center flex-col bg-gray-50 dark:bg-gray-900 bg-opacity-90 dark:bg-opacity-90 z-10",i?"sticky left-0":""),style:{width:n,position:i?"sticky":"initial",left:i?0:"initial",contain:"strict"},children:[(_||l)&&r.jsxs("div",{className:"w-34 flex justify-center",children:[B.map((x,S)=>r.jsx(p.Tooltip,{title:x.name,children:r.jsx(p.IconButton,{onClick:I=>{I.stopPropagation(),x.onClick({entity:t,fullPath:a,collection:o,context:A,selectionController:b,highlightEntity:u,unhighlightEntity:g,onCollectionChange:m})},size:y?"medium":"small",children:x.icon})},S)),E&&r.jsx(p.Menu,{trigger:r.jsx(p.IconButton,{size:y?"medium":"small",children:r.jsx(p.MoreVertIcon,{})}),children:C.map((x,S)=>r.jsxs(p.MenuItem,{onClick:I=>{I.stopPropagation(),x.onClick({entity:t,fullPath:a,collection:o,context:A,selectionController:b,highlightEntity:u,unhighlightEntity:g,onCollectionChange:m})},children:[x.icon,x.name]},S))}),l&&r.jsx(p.Tooltip,{title:`Select ${t.id}`,children:r.jsx(p.Checkbox,{size:y?"medium":"small",checked:!!s,onCheckedChange:k})})]}),!h&&c!=="xs"&&r.jsx("div",{className:"w-[138px] text-center overflow-hidden truncate",children:t?r.jsxs(p.Typography,{onClick:x=>{x.stopPropagation()},className:"font-mono select-all",variant:"caption",color:"secondary",children:[" ",t.id," "]}):r.jsx(p.Skeleton,{})})]})};function Gs({actions:e,actionsStart:t,loading:o,onSizeChanged:a,onTextSearch:n,onTextSearchClick:i,size:s,textSearchLoading:l,title:c}){const u=d.useRef(null),m=Qe(),g=d.useRef(!1);d.useEffect(()=>{u.current&&g.current&&!l&&u.current.focus(),g.current=l??!1},[l]);const f=r.jsx(p.Tooltip,{title:"Table row size",side:"right",sideOffset:4,children:r.jsx(p.Select,{value:s,className:"w-16 h-10",size:"small",onValueChange:h=>a(h),renderValue:h=>r.jsx("div",{className:"font-medium",children:h.toUpperCase()}),children:["xs","s","m","l","xl"].map(h=>r.jsx(p.SelectItem,{value:h,className:"w-12 font-medium text-center",children:h.toUpperCase()},h))})});return r.jsxs("div",{className:p.cn(p.defaultBorderMixin,"no-scrollbar min-h-[56px] overflow-x-auto px-2 md:px-4 bg-gray-50 dark:bg-gray-900 border-b flex flex-row justify-between items-center w-full"),children:[r.jsxs("div",{className:"flex items-center gap-2 md:mr-4 mr-2",children:[c&&r.jsx("div",{className:"hidden lg:block",children:c}),f,t]}),r.jsxs("div",{className:"flex items-center gap-2",children:[m&&r.jsx("div",{className:"w-[22px]",children:o&&r.jsx(p.CircularProgress,{size:"small"})}),(n||i)&&r.jsx(p.SearchBar,{inputRef:u,loading:l,disabled:!!i,onClick:i,onTextSearch:i?void 0:n,expandable:!0},"search-bar"),e]})]})}function Ys(e){return e.dataType==="boolean"?"center":e.dataType==="number"?e.enumValues?"left":"right":e.dataType==="date"?"right":"left"}function Wa(e){if(e.columnWidth)return e.columnWidth;if(e.dataType==="string")return e.url?280:e.storage?160:e.enumValues?200:e.multiline||e.markdown?300:(e.email,200);if(e.dataType==="array"){const t=e;return t.of?Array.isArray(e.of)?300:Wa(t.of):300}else return e.dataType==="number"?e.enumValues?200:140:e.dataType==="map"?360:e.dataType==="date"?200:e.dataType==="reference"?220:e.dataType==="boolean"?140:200}function Zr(e){return`subcollection:${e.id??e.path}`}const Ja="collectionGroupParent";function Xr(e,t){return d.useMemo(()=>e.propertiesOrder?Ha(e,e.propertiesOrder):js(e,t),[e,t])}function Ha(e,t){return t.flatMap(o=>{const a=e.properties[o];return a?a.hideFromCollection?[null]:a.disabled&&typeof a.disabled=="object"&&a.disabled.hidden?[null]:a.dataType==="map"&&a.spreadChildren&&a.properties?rr(a,o):[{key:o,disabled:!!a.disabled||!!a.readOnly}]:e.additionalFields?.find(i=>i.key===o)?[{key:o,disabled:!0}]:e.subcollections&&e.subcollections.find(s=>Zr(s)===o)?[{key:o,disabled:!0}]:e.collectionGroup&&o===Ja?[{key:o,disabled:!0}]:[null]}).filter(Boolean)}function js(e,t){const o=Object.keys(e.properties),a=e.additionalFields??[],n=e.subcollections??[],i=[...o,...a.map(s=>s.key)];if(t){const s=n.map(l=>Zr(l));i.push(...s.filter(l=>!i.includes(l)))}return e.collectionGroup&&i.push(Ja),Ha(e,i)}function rr(e,t,o){return e.dataType==="map"&&e.spreadChildren&&e.properties?Object.entries(e.properties).flatMap(([a,n])=>rr(n,`${t}.${a}`,o||!!e.disabled||!!e.readOnly)):[{key:t,disabled:o||!!e.disabled||!!e.readOnly}]}function Ls(e){return{key:"id_ewcfedcswdf3",width:e?160:130,title:"ID",resizable:!1,frozen:e??!1,headerAlign:"center",align:"center"}}function Za({properties:e,sortable:t,forceFilter:o,AdditionalHeaderWidget:a}){const n=!!o;return Object.entries(e).flatMap(([i,s])=>rr(s,i)).map(({key:i,disabled:s})=>{const l=Sr(e,i);if(!l)throw Error("Internal error: no property found in path "+i);const c=Xa(l);return{key:i,align:Ys(l),icon:_e(l,"small"),title:l.name??i,sortable:t,filter:!n&&c,width:Wa(l),resizable:!0,custom:{resolvedProperty:l,disabled:s},AdditionalHeaderWidget:a?({onHover:u})=>r.jsx(a,{property:l,propertyKey:i,onHover:u}):void 0}})}function Xa(e,t=!1){return t?["string","number","date","reference"].includes(e.dataType):e.dataType==="array"?e.of?Xa(e.of,!0):!1:["string","number","boolean","date","reference","array"].includes(e.dataType)}function or({text:e,...t}){return r.jsx("div",{className:"flex w-full h-screen max-h-full max-w-full bg-gray-50 dark:bg-gray-900 gap-4",children:r.jsxs("div",{className:"m-auto flex flex-col gap-2 items-center",children:[r.jsx(p.CircularProgress,{...t}),e&&r.jsx(p.Typography,{color:"secondary",variant:"caption",className:"text-center",children:e})]})})}const Us=d.memo(function({resizeHandleRef:t,columnIndex:o,isResizingIndex:a,sort:n,onColumnSort:i,onFilterUpdate:s,filter:l,column:c,onClickResizeColumn:u,createFilterField:m,AdditionalHeaderWidget:g}){const[f,h]=d.useState(!1),[b,y]=d.useState(!1),[A,k]=d.useState(!1),v=d.useCallback(x=>{y(!0)},[]),_=d.useCallback((x,S)=>{s(c,x),S!==void 0&&y(S)},[c,s]),E=a===o,B=!(a!==o&&a>0)&&(f||E);return r.jsx(ae,{children:r.jsxs("div",{className:p.cn("flex py-0 px-3 h-full text-xs uppercase font-semibold relative select-none items-center bg-gray-50 dark:bg-gray-900","text-gray-600 hover:text-gray-800 dark:text-gray-400 dark:hover:text-gray-200 ","hover:bg-gray-100 dark:hover:bg-gray-800 hover:bg-opacity-50 dark:hover:bg-opacity-50",c.frozen?"sticky left-0 z-10":"relative z-0"),style:{left:c.frozen?0:void 0,minWidth:c.width,maxWidth:c.width},onMouseEnter:()=>h(!0),onMouseMove:()=>h(!0),onMouseLeave:()=>h(!1),children:[r.jsx("div",{className:"overflow-hidden flex-grow",children:r.jsxs("div",{className:`flex items-center justify-${c.headerAlign} flex-row`,children:[c.icon,r.jsx("div",{className:"truncate -webkit-box w-full mx-1 overflow-hidden",style:{WebkitBoxOrient:"vertical",WebkitLineClamp:2,justifyContent:c.align},children:c.title})]})}),r.jsxs(r.Fragment,{children:[g&&r.jsx(g,{onHover:f||b}),c.sortable&&(n||B||b)&&r.jsx(p.Badge,{color:"secondary",invisible:!n,children:r.jsxs(p.IconButton,{size:"small",className:f||b?"bg-white dark:bg-gray-950":void 0,onClick:()=>{i(c.key)},children:[!n&&r.jsx(p.ArrowUpwardIcon,{}),n==="asc"&&r.jsx(p.ArrowUpwardIcon,{}),n==="desc"&&r.jsx(p.ArrowUpwardIcon,{className:"rotate-180"})]})})]}),c.filter&&m&&r.jsx("div",{children:r.jsx(p.Badge,{color:"secondary",invisible:!l,children:r.jsx(p.Popover,{open:b,onOpenChange:y,className:A?"hidden":void 0,modal:!0,trigger:r.jsx(p.IconButton,{className:f||b?"bg-white dark:bg-gray-950":void 0,size:"small",onClick:v,children:r.jsx(p.FilterListIcon,{size:"small"})}),children:r.jsx($s,{column:c,filter:l,onHover:f,onFilterUpdate:_,createFilterField:m,hidden:A,setHidden:k})})})}),c.resizable&&r.jsx("div",{ref:t,className:p.cn("absolute h-full w-[6px] top-0 right-0 cursor-col-resize",B&&"bg-gray-300 dark:bg-gray-700"),onMouseDown:u?()=>u(o,c):void 0})]})})},L);function $s({column:e,onFilterUpdate:t,filter:o,onHover:a,createFilterField:n,hidden:i,setHidden:s}){const l=e.key,[c,u]=d.useState(o);if(d.useEffect(()=>{u(o)},[o]),!e.filter)return null;const m=()=>{t(c,!1)},g=b=>{t(void 0,!1)},f=!!o,h=n({id:l,filterValue:c,setFilterValue:u,column:e,hidden:i,setHidden:s});return h?r.jsxs("form",{noValidate:!0,onSubmit:b=>{b.stopPropagation(),b.preventDefault(),m()},className:"text-gray-900 dark:text-white",children:[r.jsx("div",{className:p.cn(p.defaultBorderMixin,"py-4 px-6 text-xs font-semibold uppercase border-b"),children:e.title??l}),h&&r.jsx("div",{className:"m-4",children:h}),r.jsxs("div",{className:"flex justify-end m-4",children:[r.jsx(p.Button,{className:"mr-4",disabled:!f,variant:"text",color:"primary",type:"reset","aria-label":"filter clear",onClick:g,children:"Clear"}),r.jsx(p.Button,{variant:"outlined",color:"primary",type:"submit",children:"Filter"})]})]}):null}const qs=({columns:e,currentSort:t,onColumnSort:o,onFilterUpdate:a,sortByProperty:n,filter:i,onColumnResize:s,onColumnResizeEnd:l,createFilterField:c,AddColumnComponent:u})=>{const m=e.map(()=>d.createRef()),[g,f]=d.useState(-1),h=d.useCallback((C,B,x)=>{const S=e[C],I=100,D=800,P=B>D?D:B<I?I:B,T={width:P,key:S.key,column:{...S,width:P}};x?l(T):s(T)},[e,s,l]),b=d.useCallback(C=>{if(g>=0){const B=m[g].current?.parentElement?.getBoundingClientRect().left;return B?C.clientX-B:void 0}},[m,g]),y=d.useCallback(C=>{document.body.style.cursor=C?"col-resize":"auto"},[]),A=d.useCallback(C=>{C.stopPropagation(),C.preventDefault();const B=b(C);B&&h(g,B,!1)},[h,b,g]),k=d.useCallback(C=>{C.stopPropagation(),C.preventDefault();const B=b(C);B&&h(g,B,!0),f(-1),y(!1)},[h,b,g,y]),v=d.useCallback(()=>{document.removeEventListener("mousemove",A),document.removeEventListener("mouseup",k)},[A,k]),_=d.useCallback(()=>{document.addEventListener("mousemove",A),document.addEventListener("mouseup",k)},[A,k]);d.useEffect(()=>(g>=0?_():v(),()=>{v()}),[_,g,v]);const E=d.useCallback(C=>{f(C),y(!0)},[y]);return r.jsxs("div",{className:p.cn(p.defaultBorderMixin,"z-20 sticky min-w-full flex w-fit flex-row top-0 left-0 h-12 border-b bg-gray-50 dark:bg-gray-900"),children:[e.map((C,B)=>{const x=e[B],S=x&&i&&i[x.key]?i[x.key]:void 0;return r.jsx(ae,{children:r.jsx(Us,{resizeHandleRef:m[B],columnIndex:B,isResizingIndex:g,onFilterUpdate:a,filter:S,sort:n===x.key?t:void 0,onColumnSort:o,onClickResizeColumn:E,column:x,createFilterField:c,AdditionalHeaderWidget:x.AdditionalHeaderWidget})},"header_"+x.key)}),u&&r.jsx(u,{})]})},Ws=d.memo(function({rowData:t,rowIndex:o,children:a,onRowClick:n,size:i,style:s,hoverRow:l,rowClassName:c}){const u=d.useCallback(m=>{n&&n({rowData:t,rowIndex:o,event:m})},[n,t,o]);return r.jsx("div",{className:p.cn("flex min-w-full text-sm border-b border-gray-200 dark:border-gray-800 border-opacity-40 dark:border-opacity-40",c?c(t):"",{"hover:bg-opacity-95":l,"cursor-pointer":n}),onClick:u,style:{...s,height:gt(i),width:"fit-content"},children:a})},L),Js=d.memo(function(t){return t.rowData&&t.cellRenderer({cellData:t.cellData,rowData:t.rowData,rowIndex:t.rowIndex,isScrolling:!1,column:t.column,columns:t.columns,columnIndex:t.columnIndex,width:t.column.width})},(e,t)=>L(e.rowData,t.rowData)&&L(e.column,t.column)&&L(e.cellData,t.cellData)&&L(e.rowIndex,t.rowIndex)&&L(e.cellRenderer,t.cellRenderer)&&L(e.columnIndex,t.columnIndex)),ar=d.createContext({});ar.displayName="VirtualListContext";const Hs=d.forwardRef(({children:e,...t},o)=>r.jsx(ar.Consumer,{children:a=>{const n=a.customView;return r.jsxs(r.Fragment,{children:[r.jsx("div",{id:"virtual-table",style:{position:"relative",height:"100%"},children:r.jsxs("div",{ref:o,...t,style:{...t?.style,minHeight:"100%",position:"relative"},children:[r.jsx(qs,{...a}),!n&&e]})}),n&&r.jsx("div",{style:{position:"sticky",top:"56px",flexGrow:1,height:"calc(100% - 56px)",marginTop:"calc(56px - 100vh)",left:0},children:n})]})}})),Ka=d.memo(function({data:t,onResetPagination:o,onEndReached:a,size:n="m",columns:i,onRowClick:s,onColumnResize:l,filter:c,checkFilterCombination:u,onFilterUpdate:m,sortBy:g,error:f,emptyComponent:h,onSortByUpdate:b,loading:y,cellRenderer:A,hoverRow:k,createFilterField:v,rowClassName:_,className:E,endAdornment:C,AddColumnComponent:B}){const x=g?g[0]:void 0,S=g?g[1]:void 0,[I,D]=d.useState(i),P=d.useRef(null),T=d.useRef(0);d.useEffect(()=>{D(i)},[i]);const[V,re]=Fo(),R=d.useCallback(M=>{D(I.map(Y=>Y.key===M.column.key?M.column:Y))},[I]),$=d.useCallback(M=>{D(I.map(Y=>Y.key===M.column.key?M.column:Y)),l&&l(M)},[I,l]),G=d.useRef();d.useEffect(()=>{G.current=c},[c]);const z=d.useCallback(()=>{T.current=0,P.current&&P.current.scrollTo(P.current?.scrollLeft,0)},[]),H=d.useCallback(M=>{const Y=x===M&&S==="desc",F=x===M&&S==="asc"?"desc":Y?void 0:"asc",N=Y?void 0:M,le=G.current,xe=F&&N?[N,F]:void 0;le&&u&&!u(le,xe)&&m&&m(void 0),o&&o(),b&&b(xe),z()},[u,S,m,o,b,z,x]);d.useCallback(()=>{T.current=0,b&&b(void 0)},[b]);const J=Math.max((t?.length??0)*gt(n)-re.height,0),ee=d.useCallback(M=>{a&&(t?.length??0)>0&&M>T.current+600&&(T.current=M,a())},[t?.length,a]),ne=d.useCallback(({scrollOffset:M,scrollUpdateWasRequested:Y})=>{!Y&&M>=J-600&&ee(M)},[J,ee]),U=d.useCallback((M,Y)=>{T.current=0;const q=G.current;let F=q?{...q}:{};Y?F[M.key]=Y:delete F[M.key],!u||u(F,x&&S?[x,S]:void 0)||(F=Y?{[M.key]:Y}:{}),m&&m(F)},[u,S,m,x]),X=d.useCallback(()=>y?r.jsx(or,{}):r.jsxs("div",{className:"flex flex-col overflow-auto items-center justify-center p-2 gap-2 h-full",children:[r.jsx(p.AssignmentIcon,{}),h]}),[h,y]),Q=!y&&(t?.length??0)===0,K=f?r.jsxs(p.CenteredView,{maxWidth:"2xl",className:"flex flex-col gap-2",children:[r.jsx(p.Typography,{variant:"h6",children:"Error fetching data from the data source"}),f?.message&&r.jsx(Xs,{text:f.message})]}):Q?X():void 0,Z={data:t,size:n,cellRenderer:A,columns:I,currentSort:S,onRowClick:s,customView:K,onColumnResize:R,onColumnResizeEnd:$,filter:G.current,onColumnSort:H,onFilterUpdate:U,sortByProperty:x,hoverRow:k??!1,createFilterField:v,rowClassName:_,endAdornment:C,AddColumnComponent:B};return r.jsx("div",{ref:V,className:p.cn("h-full w-full",E),children:r.jsx(ar.Provider,{value:Z,children:r.jsx(Zs,{outerRef:P,width:re.width,height:re.height,itemCount:(t?.length??0)+(C?1:0),onScroll:ne,includeAddColumn:!!B,itemSize:gt(n)},n)})})},L);function Zs({outerRef:e,width:t,height:o,itemCount:a,onScroll:n,itemSize:i,includeAddColumn:s}){const l=d.useCallback(({index:c,style:u})=>r.jsx(ar.Consumer,{children:({onRowClick:m,data:g,columns:f,size:h="m",cellRenderer:b,hoverRow:y,rowClassName:A,endAdornment:k})=>{if(k&&c===(g??[]).length)return r.jsx("div",{style:{...u,height:"auto",position:"sticky",bottom:0,zIndex:1},children:k});const v=g&&g[c];return r.jsxs(Ws,{rowData:v,rowIndex:c,onRowClick:m,columns:f,hoverRow:y,rowClassName:A,style:{...u,top:`calc(${u.top}px + 48px)`},size:h,children:[f.map((_,E)=>{const C=v&&v[_.key];return r.jsx(Js,{dataKey:_.key,cellRenderer:b,column:_,columns:f,rowData:v,cellData:C,rowIndex:c,columnIndex:E},`cell_${_.key}`)}),s&&r.jsx("div",{className:"w-20"})]},`row_${c}`)}}),[]);return r.jsx(Un.FixedSizeList,{outerRef:e,innerElementType:Hs,width:t,height:o,overscanCount:4,itemCount:a,onScroll:n,itemSize:i,children:l})}const Xs=({text:e})=>{const t=/https?:\/\/[^\s]+/g,o=e.replace(t,a=>`<a href="${a}" class="underline" target="_blank">Link</a><br/>`);return r.jsx("div",{className:"break-all",dangerouslySetInnerHTML:{__html:o}})},Ra={"==":"==","!=":"!=",">":">","<":"<",">=":">=","<=":"<=",in:"In","not-in":"Not in","array-contains":"Contains","array-contains-any":"Contains Any"},Kr=["array-contains-any","in","not-in"];function Ks({name:e,value:t,setValue:o,isArray:a,path:n,title:i,previewProperties:s,setHidden:l}){const c=a?["array-contains"]:["==","!=",">","<",">=","<="];a?c.push("array-contains-any"):c.push("in","not-in");const[u,m]=t||[c[0],void 0],[g,f]=d.useState(u),[h,b]=d.useState(m),y=h?Array.isArray(h)?h.map(I=>I?.isEntityReference&&I?.isEntityReference()?I.id:null).filter(Boolean):[h.id]:[];function A(I,D){const P=Kr.includes(g),T=Kr.includes(I);let V=D;P!==T&&(V=T?V?.isEntityReference&&V?.isEntityReference()?[V]:[]:void 0),f(I),b(V);const re=V!==null&&Array.isArray(V)?V.length>0:V!==void 0;o(I&&re?[I,V]:void 0)}const k=pe(),v=d.useMemo(()=>n?k.getCollection(n):void 0,[n]),_=I=>{A(g,je(I))},E=I=>{A(g,I.map(D=>je(D)))},C=Kr.includes(g),B=mt({multiselect:C,path:n,collection:v,onSingleEntitySelected:_,onMultipleEntitiesSelected:E,selectedEntityIds:y,onClose:()=>{l(!1)}}),x=()=>{l(!0),B.open()},S=I=>r.jsx(Oe,{disabled:!n,previewProperties:s,size:"medium",onClick:x,reference:I,hover:!0,allowEntityNavigation:!1});return r.jsxs("div",{className:"flex w-[440px] flex-row",children:[r.jsx("div",{className:"w-[140px]",children:r.jsx(p.Select,{value:g,onValueChange:I=>{A(I,h)},renderValue:I=>Ra[I],children:c.map(I=>r.jsx(p.SelectItem,{value:I,children:Ra[I]},I))})}),r.jsxs("div",{className:"flex-grow ml-2 h-full gap-2 flex flex-col",children:[h&&Array.isArray(h)&&r.jsx("div",{children:h.map((I,D)=>S(I))}),h&&!Array.isArray(h)&&r.jsx("div",{children:S(h)}),(!h||Array.isArray(h)&&h.length===0)&&r.jsx(p.Button,{onClick:x,variant:"outlined",size:"large",className:"h-full w-full",children:C?"Select references":"Select reference"}),!a&&r.jsxs(p.Label,{className:"border cursor-pointer rounded-md p-2 flex items-center gap-2 [&:has(:checked)]:bg-gray-100 dark:[&:has(:checked)]:bg-gray-800",htmlFor:"null-filter",children:[r.jsx(p.Checkbox,{id:"null-filter",checked:h===null,size:"small",onCheckedChange:I=>{h!==null?A(g,null):A(g,void 0)}}),"Filter for null values"]})]})]})}const en={"==":"==","!=":"!=",">":">","<":"<",">=":">=","<=":"<=",in:"In","not-in":"Not in","array-contains":"Contains","array-contains-any":"Any"},Rr=["array-contains-any","in","not-in"];function Rs({name:e,value:t,setValue:o,dataType:a,isArray:n,enumValues:i,title:s}){const l=n?["array-contains"]:["==","!=",">","<",">=","<="];i&&(n?l.push("array-contains-any"):l.push("in","not-in"));const[c,u]=t||[l[0],void 0],[m,g]=d.useState(c),[f,h]=d.useState(u);function b(A,k){let v=k;const _=Rr.includes(m),E=Rr.includes(A);_!==E&&(v=E?typeof k=="string"||typeof k=="number"?[k]:[]:void 0),typeof v=="number"&&isNaN(v)&&(v=void 0),g(A),h(v);const C=v!==null&&Array.isArray(v)?v.length>0:v!==void 0;o(A&&C?[A,v]:void 0)}const y=Rr.includes(m);return r.jsxs("div",{className:"flex w-[440px]",children:[r.jsx("div",{className:"w-[80px]",children:r.jsx(p.Select,{value:m,position:"item-aligned",onValueChange:A=>{b(A,f)},renderValue:A=>en[A],children:l.map(A=>r.jsx(p.SelectItem,{value:A,children:en[A]},A))})}),r.jsxs("div",{className:"flex-grow ml-2 flex flex-col gap-2",children:[!i&&r.jsx(p.TextField,{type:a==="number"?"number":void 0,value:f!==void 0&&f!=null?String(f):"",onChange:A=>{const k=a==="number"?parseFloat(A.target.value):A.target.value;b(m,k)},endAdornment:f&&r.jsx(p.IconButton,{onClick:A=>b(m,void 0),children:r.jsx(p.ClearIcon,{})})}),i&&r.jsx(p.Select,{position:"item-aligned",value:f!==void 0?Array.isArray(f)?f.map(A=>String(A)):String(f):n?[]:"",onValueChange:A=>{A!==""&&b(m,a==="number"?parseInt(A):A)},multiple:y,endAdornment:f&&r.jsx(p.IconButton,{className:"absolute right-2 top-3",onClick:A=>b(m,void 0),children:r.jsx(p.ClearIcon,{})}),renderValue:A=>A===null?"Filter for null values":r.jsx(Ie,{enumKey:A,enumValues:i,size:"small"},`select_value_${e}_${A}`),children:i.map(A=>r.jsx(p.SelectItem,{value:String(A.id),children:r.jsx(Ie,{enumKey:String(A.id),enumValues:i,size:"small"})},`select_value_${e}_${A.id}`))}),!n&&r.jsxs(p.Label,{className:"border cursor-pointer rounded-md p-2 flex items-center gap-2 [&:has(:checked)]:bg-gray-100 dark:[&:has(:checked)]:bg-gray-800",htmlFor:"null-filter",children:[r.jsx(p.Checkbox,{id:"null-filter",checked:f===null,size:"small",onCheckedChange:A=>{f!==null?b(m,null):b(m,void 0)}}),"Filter for null values"]})]})]})}function el({name:e,title:t,value:o,setValue:a}){function n(l){a(l!==void 0?["==",l]:void 0)}const i=o&&o[1],s=!!o;return r.jsx("div",{className:"w-[300px]",children:r.jsx(p.BooleanSwitchWithLabel,{value:i,allowIndeterminate:!0,onValueChange:l=>n(l===null?void 0:l),label:s?i?`${t} is true`:`${t} is false`:"No filter"})})}const tn={"==":"==","!=":"!=",">":">","<":"<",">=":">=","<=":"<=","not-in":"not in",in:"in","array-contains":"Contains","array-contains-any":"Any"},rn=["array-contains-any","in"];function tl({name:e,isArray:t,mode:o,value:a,setValue:n,title:i}){const{locale:s}=oe(),l=t?["array-contains"]:["==","!=",">","<",">=","<="],[c,u]=a||[l[0],void 0],[m,g]=d.useState(c),[f,h]=d.useState(u);function b(y,A){let k=A;const v=rn.includes(m),_=rn.includes(y);v!==_&&(k=_?A?[A]:[]:""),g(y),h(k===null?void 0:k);const E=k!==null&&Array.isArray(k)?k.length>0:k!==void 0;n(y&&E?[y,k]:void 0)}return r.jsxs("div",{className:"flex w-[440px]",children:[r.jsx("div",{className:"w-[80px]",children:r.jsx(p.Select,{value:m,onValueChange:y=>{b(y,f)},renderValue:y=>tn[y],children:l.map(y=>r.jsx(p.SelectItem,{value:y,children:tn[y]},y))})}),r.jsxs("div",{className:"flex-grow ml-2 flex flex-col gap-2",children:[r.jsx(p.DateTimeField,{mode:o,size:"medium",locale:s,value:f??void 0,onChange:y=>{b(m,y===null?void 0:y)},clearable:!0}),r.jsxs(p.Label,{className:"border cursor-pointer rounded-md p-2 flex items-center gap-2 [&:has(:checked)]:bg-gray-100 dark:[&:has(:checked)]:bg-gray-800",htmlFor:"null-filter",children:[r.jsx(p.Checkbox,{id:"null-filter",checked:f===null,size:"small",onCheckedChange:y=>{f!==null?b(m,null):b(m,void 0)}}),"Filter for null values"]})]})]})}const on=d.memo(function({onValueChange:t,cellRenderer:o,onEntityClick:a,onColumnResize:n,hoverRow:i=!0,size:s,inlineEditing:l=!1,tableController:{data:c,dataLoading:u,noMoreToLoad:m,dataLoadingError:g,filterValues:f,setFilterValues:h,sortBy:b,setSortBy:y,setSearchString:A,clearFilter:k,itemCount:v,setItemCount:_,pageSize:E=50,paginationEnabled:C,checkFilterCombination:B,setPopupCell:x},filterable:S=!0,emptyComponent:I,columns:D,forceFilter:P,highlightedRow:T,endAdornment:V,AddColumnComponent:re}){const R=d.useRef(null),[$,G]=d.useState(void 0),z=()=>{!C||u||m||v!==void 0&&_?.(v+E)},H=d.useCallback(()=>{_?.(E)},[E]),J=d.useCallback(({rowData:X})=>{if(!l)return a&&a(X)},[a,l]);p.useOutsideAlerter(R,()=>{$&&ne()},!!$),d.useEffect(()=>{const X=Q=>{Q.keyCode===27&&ne()};return document.addEventListener("keydown",X,!1),()=>{document.removeEventListener("keydown",X,!1)}});const ee=d.useCallback(X=>{G(X)},[]),ne=d.useCallback(()=>{G(void 0)},[]),U=d.useCallback(X=>{h?.({...X,...P})},[P]);return r.jsx($a.Provider,{value:{setPopupCell:x,select:ee,onValueChange:t,size:s??"m",selectedCell:$},children:r.jsx("div",{className:"h-full w-full flex flex-col bg-white dark:bg-gray-950",ref:R,children:r.jsx(Ka,{data:c,columns:D,cellRenderer:o,onRowClick:l?void 0:a?J:void 0,onEndReached:z,onResetPagination:H,error:g,paginationEnabled:C,onColumnResize:n,size:s,loading:u,filter:f,onFilterUpdate:h?U:void 0,sortBy:b,onSortByUpdate:y,hoverRow:i,checkFilterCombination:B,createFilterField:S?rl:void 0,rowClassName:d.useCallback(X=>T?.(X)?"bg-gray-100 bg-opacity-75 dark:bg-gray-800 dark:bg-opacity-75":"",[T]),className:"flex-grow",emptyComponent:I,endAdornment:V,AddColumnComponent:re})})})},L);function rl({id:e,filterValue:t,setFilterValue:o,column:a,hidden:n,setHidden:i}){if(!a.custom)return null;const{resolvedProperty:s}=a.custom,l=s?.dataType==="array",c=l?s.of:s;if(!c)return null;if(c.dataType==="reference")return r.jsx(Ks,{value:t,setValue:o,name:e,isArray:l,path:c.path,title:s?.name,previewProperties:c?.previewProperties,hidden:n,setHidden:i});if(c.dataType==="number"||c.dataType==="string"){const u=c.name,m=c.enumValues?qe(c.enumValues):void 0;return r.jsx(Rs,{value:t,setValue:o,name:e,dataType:c.dataType,isArray:l,enumValues:m,title:u})}else if(c.dataType==="boolean"){const u=c.name;return r.jsx(el,{value:t,setValue:o,name:e,title:u})}else if(c.dataType==="date"){const u=c.name;return r.jsx(tl,{value:t,setValue:o,name:e,mode:c.mode,isArray:l,title:u})}return r.jsx("div",{children:`Currently the filter field ${s.dataType} is not supported`})}const eo=function({className:t,style:o,forceFilter:a,actionsStart:n,actions:i,title:s,tableRowActionsBuilder:l,uniqueFieldValidator:c,getPropertyFor:u,onValueChange:m,selectionController:g,highlightedEntities:f,onEntityClick:h,onColumnResize:b,onSizeChanged:y,textSearchEnabled:A=!1,hoverRow:k=!0,inlineEditing:v=!1,additionalFields:_,displayedColumnIds:E,defaultSize:C,properties:B,tableController:x,filterable:S=!0,sortable:I=!0,endAdornment:D,AddColumnComponent:P,AdditionalHeaderWidget:T,additionalIDHeaderWidget:V,emptyComponent:re,getIdColumnWidth:R,onTextSearchClick:$,textSearchLoading:G,enablePopupIcon:z}){const H=d.useRef(null),J=Qe(),ee=(g?.selectedEntities?.length>0?g?.selectedEntities:f)?.filter(Boolean),ne=Ae(),[U,X]=d.useState(C??"m"),Q=ee?.map(O=>O.id),K=d.useCallback(O=>{y&&y(O),X(O)},[]),Z=d.useCallback(O=>x.setSearchString?.(O),[]),M=d.useMemo(()=>_?_.map(O=>({[O.key]:O})).reduce((O,ie)=>({...O,...ie}),{}):{},[_]),Y=c,q=({column:O,columnIndex:ie,rowData:fe,rowIndex:ue})=>{const he=fe,ze=O.key;let Ve=O.custom?.disabled;const Ge=u?.({propertyKey:ze,entity:he})??O.custom.resolvedProperty;return Ge?.disabled||(Ve=!1),Ge?r.jsx(ae,{children:he?r.jsx(qa,{readonly:!v,align:O.align??"left",propertyKey:ze,property:Ge,value:he?.values?Ye(he.values,ze):void 0,customFieldValidator:Y,columnIndex:ie,width:O.width,height:gt(U),entity:he,disabled:Ve,enablePopupIcon:z,path:he.path},`property_table_cell_${he.id}_${ze}`):Le()}):null},F=d.useCallback(({column:O,rowData:ie,width:fe})=>{const ue=ie,he=M[O.key],ze=he.dependencies?Object.entries(ue.values).filter(([Ue,at])=>he.dependencies.includes(Ue)).reduce((Ue,at)=>({...Ue,...at}),{}):ue,Ve=he.Builder;if(!Ve&&!he.value)throw new Error("When using additional fields you need to provide a Builder or a value");const Ge=Ve?r.jsx(Ve,{entity:ue,context:ne}):r.jsx(r.Fragment,{children:he.value?.({entity:ue,context:ne})});return r.jsx(er,{width:fe,size:U,value:ze,selected:!1,disabled:!0,align:"left",allowScroll:!1,showExpandIcon:!1,disabledTooltip:"This column can't be edited directly",children:r.jsx(ae,{children:Ge})},`additional_table_cell_${ue.id}_${O.key}`)},[U,Q]),N=(()=>{const O=Za({properties:B,sortable:I,forceFilter:a,AdditionalHeaderWidget:T}),ie=_?_.map(fe=>({key:fe.key,align:"left",sortable:!1,title:fe.name,width:fe.width??200})):[];return[...O,...ie]})(),xe=[{key:"id_ewcfedcswdf3",width:R?.()??(J?160:130),title:"ID",resizable:!1,frozen:J,headerAlign:"center",align:"center",AdditionalHeaderWidget:()=>V},...E?E.map(O=>N.find(ie=>ie.key===O.key)).filter(Boolean):N],te=O=>{const ie=O.column,fe=O.columns,ue=ie.key;try{if(O.columnIndex===0)return l?l({entity:O.rowData,size:U,width:ie.width,frozen:ie.frozen}):r.jsx(tr,{entity:O.rowData,width:ie.width,frozen:ie.frozen,isSelected:!1,size:U});if(M[ue])return F(O);if(O.columnIndex<fe.length+1)return q(O);throw Error("Internal: columns not mapped properly")}catch(he){return console.error("Error rendering cell",he),r.jsx(er,{size:U,width:ie.width,saved:!1,value:null,align:"left",fullHeight:!1,disabled:!0,children:r.jsx(ye,{error:he})})}};return r.jsxs("div",{ref:H,style:o,className:p.cn("h-full w-full flex flex-col bg-white dark:bg-gray-950",t),children:[r.jsx(Gs,{onTextSearch:A?Z:void 0,textSearchLoading:G,onTextSearchClick:A?$:void 0,size:U,onSizeChanged:K,title:s,actionsStart:n,actions:i,loading:x.dataLoading}),r.jsx(on,{columns:xe,size:U,inlineEditing:v,cellRenderer:te,onEntityClick:h,highlightedRow:d.useCallback(O=>Q?.includes(O.id)??!1,[Q]),tableController:x,onValueChange:m,onColumnResize:b,hoverRow:k,filterable:S,emptyComponent:re,endAdornment:D,AddColumnComponent:P})]})};function ol({data:e,entitiesDisplayedFirst:t}){if(!t)return e;const o=new Set(t.map(a=>a.id));return[...t,...e.filter(a=>!o.has(a.id))]}function an(e,t,o=5e3){const[a,n]=d.useState(e),i=d.useRef(a.length??0),s=d.useRef(!1),l=d.useRef(t),c=!L(l.current,t),u=e.length>=i.current||c;return d.useEffect(()=>{const m=()=>{L(a,e)||(l.current=t,i.current=e.length,n(e)),s.current=!1};s.current=!0;let g;return u?m():g=setTimeout(m,o),()=>{clearTimeout(g),s.current&&u&&m()}},[e,o,t,u]),u?e:a}const al=50;function to({fullPath:e,collection:t,entitiesDisplayedFirst:o,lastDeleteTimestamp:a,forceFilter:n}){const{initialFilter:i,initialSort:s,forceFilter:l}=t,[c,u]=d.useState(void 0),m=pe(),g=Me(t),f=d.useMemo(()=>m.resolveAliasesFrom(e),[e,m.resolveAliasesFrom]),h=n??l,b=t.pagination===void 0||!!t.pagination,y=typeof t.pagination=="number"?t.pagination:al,[A,k]=d.useState(),[v,_]=d.useState(b?y:void 0),E=d.useMemo(()=>{if(s&&h&&!J(h,s)){console.warn("Initial sort is not compatible with the force filter. Ignoring initial sort");return}return s},[s,h]);d.useEffect(()=>{L(h,C)||B(h)},[h]);const[C,B]=d.useState(h??i??void 0),[x,S]=d.useState(E),I=x?x[0]:void 0,D=x?x[1]:void 0,P=Ae(),[T,V]=d.useState([]),[re,R]=d.useState(!1),[$,G]=d.useState(),[z,H]=d.useState(!1),J=d.useCallback((Q,K)=>g.isFilterCombinationValid?g.isFilterCombinationValid({path:f,collection:t,filterValues:Q,sortBy:K}):!0,[]),ee=d.useCallback(()=>B(h??void 0),[h]),ne=d.useCallback(Q=>{if(h){console.warn("Filter is not compatible with the force filter. Ignoring filter");return}Q&&Object.keys(Q).length===0?B(void 0):B(Q)},[h]);d.useEffect(()=>{R(!0);const Q=async Z=>{if(t.callbacks?.onFetch)try{Z=await Promise.all(Z.map(M=>t.callbacks.onFetch({collection:t,path:f,entity:M,context:P})))}catch(M){console.error(M)}R(!1),G(void 0),V(Z.map(M=>({...M}))),H(!v||Z.length<v)},K=Z=>{console.error("ERROR",Z),R(!1),V([]),G(Z)};return g.listenCollection?g.listenCollection({path:f,collection:t,onUpdate:Q,onError:K,searchString:A,filter:C,limit:v,startAfter:void 0,orderBy:I,order:D}):(g.fetchCollection({path:f,collection:t,searchString:A,filter:C,limit:v,startAfter:void 0,orderBy:I,order:D}).then(Q).catch(K),()=>{})},[f,v,D,I,C,A]);const U=ol({data:T,entitiesDisplayedFirst:o});return{data:an(U,{filterValues:C,sortBy:x,searchString:A,lastDeleteTimestamp:a}),dataLoading:re,noMoreToLoad:z,dataLoadingError:$,filterValues:C,setFilterValues:ne,sortBy:x,setSortBy:S,searchString:A,setSearchString:k,clearFilter:ee,itemCount:v,setItemCount:_,paginationEnabled:b,pageSize:y,checkFilterCombination:J,popupCell:c,setPopupCell:u}}function ro(e){const[t,o]=d.useState([]),a=d.useCallback(i=>{let s;t.map(l=>l.id).includes(i.id)?(e?.(i,!1),s=t.filter(l=>l.id!==i.id)):(e?.(i,!0),s=[...t,i]),o(s)},[t]),n=d.useCallback(i=>t.map(s=>s.id).includes(i.id),[t]);return{selectedEntities:t,setSelectedEntities:o,isEntitySelected:n,toggleEntitySelection:a}}function oo({collection:e,fullPath:t,parentCollectionIds:o}){const a=Ae(),n=oe(),[i,s]=d.useState(!1),[l,c]=d.useState(!1);let u,m=!!e.textSearchEnabled;return n?.plugins&&(u=n.plugins?.find(f=>!!f.collectionView?.onTextSearchClick)?()=>{s(!0),Promise.all(n.plugins?.map(f=>f.collectionView?.onTextSearchClick?f.collectionView.onTextSearchClick({context:a,path:t,collection:e,parentCollectionIds:o}):Promise.resolve(!0))).then(f=>{f.every(Boolean)&&c(!0)}).finally(()=>s(!1))}:void 0,n.plugins?.forEach(f=>{m||f.collectionView?.showTextSearchBar&&(m=f.collectionView.showTextSearchBar({context:a,path:t,collection:e,parentCollectionIds:o}))})),{textSearchLoading:i,textSearchInitialised:l,onTextSearchClick:u,textSearchEnabled:m}}function nn({onSingleEntitySelected:e,onMultipleEntitiesSelected:t,multiselect:o,collection:a,path:n,selectedEntityIds:i,description:s,forceFilter:l,maxSelection:c}){const u=dr(),m=Je(),g=pe(),f=ut(),h=oe(),b=g.resolveAliasesFrom(n),y=Me(a),[A,k]=d.useState([]),v=$=>{let G;const z=_.selectedEntities;if(f.onAnalyticsEvent?.("reference_selection_toggle",{path:b,entityId:$.id}),z){if(z.map(H=>H.id).indexOf($.id)>-1)G=z.filter(H=>H.id!==$.id);else{if(c&&z.length>=c)return;G=[...z,$]}_.setSelectedEntities(G),t&&t(G)}},_=ro(v);d.useEffect(()=>{let $=!1;const G=i?.map(z=>z?.toString()).filter(Boolean);return G&&a?Promise.all(G.map(z=>y.fetchEntity({path:b,entityId:z,collection:a}))).then(z=>{if(!$){const H=z.filter(J=>J!==void 0);_.setSelectedEntities(H),k(H)}}):(_.setSelectedEntities([]),k([])),()=>{$=!0}},[y,b,i,a,_.setSelectedEntities]);const E=()=>{f.onAnalyticsEvent?.("reference_selection_clear",{path:b}),_.setSelectedEntities([]),!o&&e?e(null):t&&t([])},C=$=>{!o&&e?(f.onAnalyticsEvent?.("reference_selected_single",{path:b,entityId:$.id}),e($),u.close(!1)):v($)},B=()=>{f.onAnalyticsEvent?.("reference_selection_new_entity",{path:b}),m.open({path:b,collection:a,updateUrl:!0,onUpdate:({entity:$})=>{k([$,...A]),C($)},closeOnSave:!0})},x=({entity:$,size:G,width:z,frozen:H})=>{const J=_.selectedEntities,ee=J&&J.map(ne=>ne.id).indexOf($.id)>-1;return r.jsx(tr,{width:z,frozen:H,entity:$,size:G,isSelected:ee,selectionEnabled:o,hideId:a?.hideIdFromCollection,fullPath:b,selectionController:_})},S=d.useCallback($=>{$.stopPropagation(),u.close(!1)},[u]);if(!a)return r.jsx(ye,{error:"Could not find collection with id "+a});const I=d.useMemo(()=>Ne({collection:a,path:b,values:{},fields:h.propertyConfigs}),[a,h.propertyConfigs,b]),D=Xr(I,!1),P=to({fullPath:b,collection:a,entitiesDisplayedFirst:A,forceFilter:l}),{textSearchLoading:T,textSearchInitialised:V,onTextSearchClick:re,textSearchEnabled:R}=oo({collection:a,fullPath:b});return r.jsxs("div",{className:"flex flex-col h-full",children:[r.jsx("div",{className:"flex-grow",children:A&&r.jsx(eo,{textSearchLoading:T,onTextSearchClick:V?void 0:re,textSearchEnabled:R,displayedColumnIds:D,onEntityClick:C,tableController:P,enablePopupIcon:!1,tableRowActionsBuilder:x,title:r.jsx(p.Typography,{variant:"subtitle2",children:a.singularName?`Select ${a.singularName}`:`Select from ${a.name}`}),defaultSize:a.defaultSize,properties:I.properties,forceFilter:l,inlineEditing:!1,selectionController:_,actions:r.jsx(nl,{collection:a,path:b,onNewClick:B,onClear:E})})}),r.jsxs(p.DialogActions,{translucent:!1,children:[s&&r.jsx(p.Typography,{variant:"body2",className:"flex-grow text-left",children:s}),r.jsx(p.Button,{onClick:S,color:"primary",variant:"filled",children:"Done"})]})]})}function nl({collection:e,path:t,onClear:o,onNewClick:a}){const n=We(),i=Qe(),s=a?c=>{c.preventDefault(),a()}:void 0,l=ct(e,n,t,null)&&s&&(i?r.jsxs(p.Button,{onClick:s,startIcon:r.jsx(p.AddIcon,{}),variant:"outlined",color:"primary",children:["Add ",e.singularName??e.name]}):r.jsx(p.Button,{onClick:s,variant:"outlined",color:"primary",children:r.jsx(p.AddIcon,{})}));return r.jsxs(r.Fragment,{children:[r.jsx(p.Button,{onClick:o,variant:"text",color:"primary",children:"Clear"}),l]})}function St(e){return Array.isArray(e)?e:e?[e]:[]}function ao({children:e,group:t}){const o=pt();return r.jsx(p.ExpandablePanel,{invisible:!0,titleClassName:"font-medium text-sm text-gray-600 dark:text-gray-400",className:"py-4",initiallyExpanded:!(o?.collapsedGroups??[]).includes(t??"ungrouped"),onExpandedChange:a=>{if(o)if(a)o.setCollapsedGroups((o.collapsedGroups??[]).filter(n=>n!==(t??"ungrouped")));else{const n=(o.collapsedGroups??[]).concat(t??"ungrouped");o.setCollapsedGroups(n)}},title:r.jsx(p.Typography,{color:"secondary",className:"font-medium ml-1",children:t?.toUpperCase()??"Views".toUpperCase()}),children:r.jsx("div",{className:"mb-8",children:e})})}function sn({name:e,description:t,icon:o,actions:a,onClick:n}){return r.jsx(p.Card,{className:p.cn("h-full p-4 cursor-pointer min-h-[230px]"),onClick:()=>{n?.()},children:r.jsxs("div",{className:"flex flex-col items-start h-full",children:[r.jsxs("div",{className:"flex-grow w-full",children:[r.jsxs("div",{className:"h-10 flex items-center w-full justify-between text-gray-300 dark:text-gray-600",children:[o,r.jsx("div",{className:"flex items-center gap-1",onClick:i=>{i.preventDefault(),i.stopPropagation()},children:a})]}),r.jsx(p.Typography,{gutterBottom:!0,variant:"h5",component:"h2",children:e}),t&&r.jsx(p.Typography,{variant:"body2",color:"secondary",component:"div",children:r.jsx(p.Markdown,{source:t,size:"small"})})]}),r.jsx("div",{style:{alignSelf:"flex-end"},children:r.jsx("div",{className:"p-4",children:r.jsx(p.ArrowForwardIcon,{className:"text-primary"})})})]})})}function ln({name:e,url:t,icon:o}){return r.jsx(r.Fragment,{children:r.jsxs(ge.Link,{tabIndex:0,className:p.cn(p.cardMixin,p.cardClickableMixin,p.focusedMixin,"cursor-pointer flex flex-row items-center px-4 py-2 text-inherit dark:text-inherit visited:text-inherit visited:dark:text-inherit hover:text-inherit hover:dark:text-inherit "),to:t,children:[r.jsxs("div",{className:"flex flex-row items-center flex-grow gap-2 ",children:[o,r.jsx(p.Typography,{gutterBottom:!0,variant:"h5",component:"h2",className:"mb-0 ml-4",children:e})]}),r.jsx("div",{className:"p-4",children:r.jsx(p.ArrowForwardIcon,{color:"primary"})})]})})}function cn({path:e,collection:t,view:o,url:a,name:n,description:i,onClick:s,type:l}){const c=pt(),u=r.jsx(Zt,{collectionOrView:t??o}),m=ge.useNavigate(),g=Ae(),f=oe(),h=(c?.favouritePaths??[]).includes(e),b=c?[r.jsx(p.IconButton,{onClick:A=>{A.preventDefault(),A.stopPropagation(),h?c.setFavouritePaths(c.favouritePaths.filter(k=>k!==e)):c.setFavouritePaths([...c.favouritePaths,e])},children:h?r.jsx(p.StarIcon,{size:18,className:"text-secondary"}):r.jsx(p.StarBorderIcon,{size:18,className:"text-gray-400 dark:text-gray-500"})},"favourite")]:[];if(f.plugins&&t){const A={path:e,collection:t,context:g};f.plugins.forEach((k,v)=>b.push(k.homePage?.CollectionActions?r.jsx(k.homePage.CollectionActions,{...A,extraProps:k.homePage.extraProps},`actions_${v}`):null))}const y=r.jsx(r.Fragment,{children:b});return l==="admin"?r.jsx(ln,{icon:u,name:n,url:a}):r.jsx(sn,{icon:u,name:n,description:i,actions:y,onClick:()=>{s?.(),m(a),c&&c.setRecentlyVisitedPaths([e,...(c.recentlyVisitedPaths??[]).filter(A=>A!==e)])}})}function il({entry:e}){const t=ge.useNavigate(),o=pt();if(!o)return null;const a=o.favouritePaths.includes(e.path),n=i=>{i.preventDefault(),i.stopPropagation(),a?o.setFavouritePaths(o.favouritePaths.filter(s=>s!==e.path)):o.setFavouritePaths([...o.favouritePaths,e.path])};return r.jsx(p.Chip,{onClick:()=>t(e.url),icon:a?r.jsx(p.StarIcon,{onClick:n,size:18,className:"text-secondary"}):r.jsx(p.StarBorderIcon,{onClick:n,size:18,className:"text-gray-400 dark:text-gray-500"}),children:e.name},e.path)}function sl({hidden:e}){const t=pe(),o=pt();if(!o)return null;const a=(o?.favouritePaths??[]).map(n=>t.topLevelNavigation?.navigationEntries.find(i=>i.path===n)).filter(Boolean);return r.jsx(p.Collapse,{in:a.length>0,children:r.jsx("div",{className:"flex flex-row flex-wrap gap-2 pb-2 min-h-[32px]",children:a.map(n=>r.jsx(il,{entry:n},n.path))})})}const no={};function ll(){const e=ge.useLocation(),t=d.useRef(null),[o,a]=d.useState(0),[n,i]=d.useState("down"),s=d.useCallback(()=>{!t.current||!e.key||(no[e.key]=t.current.scrollTop,a(t.current.scrollTop),i(t.current.scrollTop>o?"down":"up"))},[t,e.key,o]);return d.useEffect(()=>{const l=t.current;if(l)return l.addEventListener("scroll",s,{passive:!0}),()=>{l&&l.removeEventListener("scroll",s)}},[t,s,e]),d.useEffect(()=>{!t.current||!no[e.key]||t.current.scrollTo({top:no[e.key],behavior:"auto"})},[e]),{containerRef:t,scroll:o,direction:n}}const At=new Po.Search("url");At.addIndex("name"),At.addIndex("description"),At.addIndex("group"),At.addIndex("path");function dn({additionalActions:e,additionalChildrenStart:t,additionalChildrenEnd:o}){const a=Ae(),n=oe(),i=pe();if(!i.topLevelNavigation)throw Error("Navigation not ready in FireCMSHomePage");const{containerRef:s,scroll:l,direction:c}=ll(),{navigationEntries:u,groups:m}=i.topLevelNavigation,[g,f]=d.useState(null),h=g?u.filter(_=>g.includes(_.url)):u;d.useEffect(()=>{At.addDocuments(u)},[u]);const b=d.useCallback(_=>{if(!_||_==="")f(null);else{const E=At.search(_);f(E.map(C=>C.url))}},[]),y=[...m];(h.filter(_=>!_.group).length>0||h.length===0)&&y.push(void 0);let A,k,v;if(n.plugins){const _={context:a};v=r.jsx(r.Fragment,{children:n.plugins.filter(E=>E.homePage?.includeSection).map((E,C)=>{const B=E.homePage.includeSection(_);return r.jsx(ao,{group:B.title,children:B.children},`plugin_section_${E.key}`)})}),A=r.jsx("div",{className:"flex flex-col gap-2",children:n.plugins.filter(E=>E.homePage?.additionalChildrenStart).map((E,C)=>r.jsx("div",{children:E.homePage.additionalChildrenStart},`plugin_children_start_${C}`))}),k=r.jsx("div",{className:"flex flex-col gap-2",children:n.plugins.filter(E=>E.homePage?.additionalChildrenEnd).map((E,C)=>r.jsx("div",{children:E.homePage.additionalChildrenEnd},`plugin_children_start_${C}`))})}return r.jsx("div",{id:"home_page",ref:s,className:"py-2 overflow-auto h-full w-full",children:r.jsxs(p.Container,{maxWidth:"6xl",children:[r.jsxs("div",{className:"w-full sticky py-4 transition-all duration-400 ease-in-out top-0 z-10 flex flex-row gap-4",style:{top:c==="down"?-84:0},children:[r.jsx(p.SearchBar,{onTextSearch:b,placeholder:"Search collections",large:!1,innerClassName:"w-full",className:"w-full flex-grow"}),e]}),r.jsx(sl,{hidden:!!g}),t,A,y.map((_,E)=>{const C=[],B={group:_,context:a};n.plugins&&n.plugins.forEach(S=>{S.homePage?.AdditionalCards&&C.push(...St(S.homePage?.AdditionalCards))});const x=h.filter(S=>S.group===_||!S.group&&_===void 0);return x.length===0&&C.length===0?null:r.jsx(ao,{group:_,children:r.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:[x.map(S=>r.jsx("div",{className:"col-span-1",children:r.jsx(cn,{...S,onClick:()=>{let I;S.type==="collection"?I="home_navigate_to_collection":S.type==="view"?I="home_navigate_to_view":S.type==="admin"?I="home_navigate_to_admin_view":I="unmapped_event",a.analyticsController?.onAnalyticsEvent?.(I,{path:S.path})}})},`nav_${S.group}_${S.name}`)),_?.toLowerCase()!=="admin"&&C&&C.map((S,I)=>r.jsx("div",{children:r.jsx(S,{...B})},`nav_${_}_add_${I}`))]})},`plugin_section_${_}`)}),v,k,o]})})}function pn({collection:e,relativePath:t,parentCollectionIds:o,onNewClick:a,onMultipleDeleteClick:n,selectionEnabled:i,path:s,selectionController:l,tableController:c,collectionEntitiesCount:u}){const m=Ae(),f=oe().plugins??[],h=We(),b=Qe(),y=l.selectedEntities,A=ct(e,h,s,null)&&a&&(b?r.jsxs(p.Button,{id:`add_entity_${s}`,onClick:a,startIcon:r.jsx(p.AddIcon,{}),variant:"filled",color:"primary",children:["Add ",e.singularName??e.name]}):r.jsx(p.Button,{id:`add_entity_${s}`,onClick:a,variant:"filled",color:"primary",children:r.jsx(p.AddIcon,{})})),k=Wt(e,h,s,null);let v;if(i){const C=b?r.jsxs(p.Button,{variant:"text",disabled:!y?.length||!k,startIcon:r.jsx(p.DeleteIcon,{}),onClick:n,color:"primary",className:"lg:w-20",children:["(",y?.length,")"]}):r.jsx(p.IconButton,{color:"primary",disabled:!y?.length||!k,onClick:n,children:r.jsx(p.DeleteIcon,{})});v=r.jsx(p.Tooltip,{title:k?"Delete":"You have selected at least one entity you cannot delete",children:C})}const _={path:s,relativePath:t,parentCollectionIds:o,collection:e,selectionController:l,context:m,tableController:c,collectionEntitiesCount:u},E=St(e.Actions).map((C,B)=>r.jsx(ae,{children:r.jsx(C,{..._})},`actions_${B}`));return f&&f.forEach((C,B)=>{C.collectionView?.CollectionActions&&E.push(...St(C.collectionView?.CollectionActions).map((x,S)=>r.jsx(ae,{children:r.jsx(x,{..._,...C.collectionView?.collectionActionsProps})},`plugin_actions_${B}_${S}`)))}),r.jsxs(r.Fragment,{children:[E,v,A]})}function cl({containerRef:e,innerRef:t,x:o,y:a,onMove:n}){let i=0,s=0;const l=d.useRef(!1),c=b=>{if(b.button!==0||!e.current||b.defaultPrevented||b.innerClicked)return;const{x:y,y:A}=e.current.getBoundingClientRect();i=b.screenX-y,s=b.screenY-A,document.addEventListener("mousemove",f),document.addEventListener("mouseup",g),document.addEventListener("selectstart",m),l.current=!0},u=b=>{b.innerClicked=!0},m=b=>{b.preventDefault(),b.stopPropagation()},g=b=>{document.removeEventListener("mousemove",f),document.removeEventListener("mouseup",g),document.removeEventListener("selectstart",m),b.stopPropagation(),l.current=!1},f=b=>{b.target.localName==="input"||!l.current||(n({x:b.screenX-i,y:b.screenY-s}),b.stopPropagation())},h=()=>{e.current&&(e.current.style.top=`${a}px`,e.current.style.left=`${o}px`)};d.useEffect(()=>{const b=e.current,y=t.current;if(!(!b||!y))return y&&y.addEventListener("mousedown",u),b&&b.addEventListener("mousedown",c),h(),()=>{b&&b.removeEventListener("mousedown",c),y&&y.removeEventListener("mousedown",u)}})}function dl(){const[e,t]=d.useState({width:0,height:0});return d.useLayoutEffect(()=>{function o(){t({width:window.innerWidth,height:window.innerHeight})}return window.addEventListener("resize",o),o(),()=>window.removeEventListener("resize",o)},[]),e}const pl=({onResize:e})=>{const t=d.useRef(0),o=d.useRef(null),a=d.useRef(e);a.current=e;const n=d.useCallback(s=>{t.current&&cancelAnimationFrame(t.current),t.current=requestAnimationFrame(()=>{a.current(s)})},[]),i=d.useCallback(()=>{const s=o.current;s&&s.contentDocument&&s.contentDocument.defaultView&&s.contentDocument.defaultView.addEventListener("resize",n)},[n]);return d.useEffect(()=>{const s=o.current;return()=>{s&&s.contentDocument&&s.contentDocument.defaultView&&s.contentDocument.defaultView.removeEventListener("resize",n)}},[n]),r.jsx("object",{onLoad:i,ref:o,tabIndex:-1,type:"text/html",data:"about:blank",title:"",style:{position:"absolute",top:0,left:0,height:"100%",width:"100%",pointerEvents:"none",zIndex:-1,opacity:0}})};function ul(e){return e.open?r.jsx(ml,{...e}):null}function ml({tableKey:e,entity:t,customFieldValidator:o,propertyKey:a,collection:n,path:i,cellRect:s,open:l,onClose:c,onCellValueChange:u,container:m}){const g=Ae(),f=oe(),[h,b]=d.useState(),[y,A]=d.useState(),k=t?.id,[v,_]=d.useState(t),[E,C]=d.useState(v?.values),B=n?Ne({collection:n,path:i,values:E,entityId:k,fields:f.propertyConfigs}):void 0,x=dl(),S=d.useRef(null),I=d.useRef(null),D=d.useRef(!1),P=d.useCallback(()=>{if(!s)throw Error("getInitialLocation error");return{x:s.left<x.width-s.right?s.x+s.width/2:s.x-s.width/2,y:s.top<x.height-s.bottom?s.y+s.height/2:s.y-s.height/2}},[s,x.height,x.width]),T=d.useCallback(({x:q,y:F})=>{const N=S.current?.getBoundingClientRect();if(!N)throw Error("normalizePosition called before draggableBoundingRect is set");return{x:Math.max(0,Math.min(q,x.width-N.width)),y:Math.max(0,Math.min(F,x.height-N.height))}},[x]),V=d.useCallback(q=>{const F=S.current?.getBoundingClientRect();if(!s||!F)return;const N=q??T(P());(!y||N.x!==y.x||N.y!==y.y)&&A(N)},[s,P,T,y]);cl({containerRef:S,innerRef:I,x:y?.x,y:y?.y,onMove:V}),d.useEffect(()=>{D.current=!1},[a,v]),d.useLayoutEffect(()=>{const q=S.current?.getBoundingClientRect();!s||!q||D.current||(V(),D.current=!0)},[s,V,D.current]),d.useLayoutEffect(()=>{V(y)},[x,s]);const re=d.useMemo(()=>{if(!(!B||!k))return Ua(k,a&&B.properties[a]?{[a]:B.properties[a]}:{},o)},[B,k,a,o]),R=d.useCallback(()=>V(y),[y,V]),$=async q=>(b(null),n&&v&&u&&a?u({value:q[a],propertyKey:a,data:v,setError:b,onValueUpdated:()=>{}}):Promise.resolve());if(!v)return r.jsx(r.Fragment,{});const G=ve.useCreateFormex({initialValues:v?.values??{},validation:q=>re?.validate(q,{abortEarly:!1}).then(()=>({})).catch(F=>{const N={};return F.inner.forEach(le=>{N[le.path]=le.message}),N}),validateOnInitialRender:!0,onSubmit:(q,F)=>{$(q).then(()=>c()).finally(()=>F.setSubmitting(!1))}}),{values:z,isSubmitting:H,setFieldValue:J,handleSubmit:ee}=G;if(d.useEffect(()=>{L(z,E)||C(z)},[z]),!v)return r.jsx(ye,{error:"PopupFormField misconfiguration"});if(!B)return r.jsx(r.Fragment,{});const ne=H,U={collection:B,entityId:k,values:z,path:i,setFieldValue:J,save:$},X=a&&Re(B.properties,a),Q=a&&X?{propertyKey:a,disabled:H||st(X)||!!X.disabled,property:X,includeDescription:!1,underlyingValueHasChanged:!1,context:U,tableMode:!0,partOfArray:!1,partOfBlock:!1,autoFocus:l}:void 0;let K=r.jsx(r.Fragment,{children:r.jsx("div",{className:"w-[560px] max-w-full max-h-[85vh]",children:r.jsxs("form",{onSubmit:ee,noValidate:!0,children:[r.jsx("div",{className:"mb-1 p-4 flex flex-col relative",children:r.jsx("div",{ref:I,className:"cursor-auto",style:{cursor:"auto !important"},children:Q&&r.jsx(ot,{...Q})})}),r.jsx(p.DialogActions,{children:r.jsx(p.Button,{variant:"filled",color:"primary",type:"submit",disabled:ne,children:"Save"})})]})},`popup_form_${e}_${k}_${a}`)});const Z=f.plugins;Z&&Z.forEach(q=>{q.form?.provider&&(K=r.jsx(q.form.provider.Component,{status:"existing",path:i,collection:B,entity:v,context:g,currentEntityId:k,formContext:U,...q.form.provider.props,children:K}))});const M=r.jsxs("div",{className:`text-gray-900 dark:text-white overflow-auto rounded rounded-md bg-white dark:bg-gray-950 ${l?"":"hidden"} cursor-grab max-w-[100vw]`,children:[K,h&&r.jsx(p.Typography,{color:"error",children:h.message})]}),Y=r.jsxs("div",{style:{boxShadow:"0 0 0 2px rgba(128,128,128,0.2)"},className:`inline-block fixed z-20 shadow-outline rounded-md bg-white dark:bg-gray-950 ${l?"visible":"invisible"} cursor-grab overflow-visible`,ref:S,children:[r.jsx(pl,{onResize:R}),r.jsxs("div",{className:"overflow-hidden",children:[M,r.jsx("div",{className:"absolute -top-3.5 -right-3.5 bg-gray-500 rounded-full",style:{width:"32px",height:"32px"},children:r.jsx(p.IconButton,{size:"small",onClick:q=>{q.stopPropagation(),c()},children:r.jsx(p.ClearIcon,{className:"text-white",size:"small"})})})]})]},`draggable_${a}_${k}_${l}`);return r.jsx(Hn.Root,{asChild:!0,container:m,children:r.jsx(ve.Formex,{value:G,children:Y})})}function un({entityOrEntitiesToDelete:e,collection:t,onClose:o,open:a,callbacks:n,onEntityDelete:i,onMultipleEntitiesDelete:s,path:l}){const c=Me(t),u=oe(),m=He(),[g,f]=d.useState(!1),[h,b]=d.useState(),[y,A]=d.useState(),k=Ae();d.useEffect(()=>{if(e){const T=Array.isArray(e)&&e.length===1?e[0]:e;b(T),A(Array.isArray(T))}},[e]);const v=d.useMemo(()=>Ne({collection:t,path:l,fields:u.propertyConfigs}),[t,l]),_=d.useCallback(()=>{o()},[o]),E=d.useCallback(T=>{console.debug("Deleted",T)},[]),C=d.useCallback((T,V)=>{m.open({type:"error",message:"Error deleting: "+V?.message}),console.error("Error deleting entity"),console.error(V)},[v.name]),B=d.useCallback((T,V)=>{m.open({type:"error",message:"Error before deleting: "+V?.message}),console.error(V)},[v.name]),x=d.useCallback((T,V)=>{m.open({type:"error",message:"Error after deleting: "+V?.message}),console.error(V)},[v.name]),S=d.useCallback(T=>ma({dataSource:c,entity:T,collection:v,callbacks:n,onDeleteSuccess:E,onDeleteFailure:C,onPreDeleteHookError:B,onDeleteSuccessHookError:x,context:k}),[c,v,n,E,C,B,x,k]),I=d.useCallback(async()=>{h&&(f(!0),y?Promise.all(h.map(S)).then(T=>{f(!1),s&&h&&s(l,h),T.every(Boolean)?m.open({type:"success",message:`${v.name}: multiple deleted`}):T.some(Boolean)?m.open({type:"warning",message:`${v.name}: Some of the entities have been deleted, but not all`}):m.open({type:"error",message:`${v.name}: Error deleting entities`}),o()}):S(h).then(T=>{f(!1),T&&(i&&h&&i(l,h),m.open({type:"success",message:`${v.singularName??v.name} deleted`}),o())}))},[h,y,S,s,l,o,m,v.name,i]);let D;if(h&&y)D=r.jsx(r.Fragment,{children:"Multiple entities"});else{const T=h;D=T?r.jsx(qr,{entity:T,collection:t,path:l}):r.jsx(r.Fragment,{})}const P=y?r.jsxs(r.Fragment,{children:[r.jsx("b",{children:v.name}),": Confirm multiple delete?"]}):`Would you like to delete this ${v.singularName??v.name}?`;return r.jsxs(p.Dialog,{maxWidth:y?"lg":"2xl","aria-labelledby":"delete-dialog",open:a,onOpenChange:T=>T?void 0:o(),children:[r.jsxs(p.DialogContent,{fullHeight:!0,children:[r.jsx(p.Typography,{variant:"subtitle2",className:"p-4",children:P}),!y&&r.jsx("div",{className:"p-4",children:D})]}),r.jsxs(p.DialogActions,{children:[g&&r.jsx(p.CircularProgress,{size:"small"}),r.jsx(p.Button,{onClick:_,disabled:g,variant:"text",color:"primary",children:"Cancel"}),r.jsx(p.Button,{autoFocus:!0,disabled:g,onClick:I,variant:"filled",color:"primary",children:"Ok"})]})]})}const fl={icon:r.jsx(p.KeyboardTabIcon,{}),name:"Edit",collapsed:!1,onClick({entity:e,collection:t,fullPath:o,context:a,highlightEntity:n,unhighlightEntity:i}){n?.(e),a.analyticsController?.onAnalyticsEvent?.("entity_click",{path:e.path,entityId:e.id});const s=t?.collectionGroup?e.path:o??e.path;return a.sideEntityController.open({entityId:e.id,path:s,collection:t,updateUrl:!0,onClose:()=>i?.(e)}),Promise.resolve(void 0)}},mn={icon:r.jsx(p.FileCopyIcon,{}),name:"Copy",onClick({entity:e,collection:t,context:o,highlightEntity:a,unhighlightEntity:n}){return a?.(e),o.analyticsController?.onAnalyticsEvent?.("copy_entity_click",{path:e.path,entityId:e.id}),o.sideEntityController.open({entityId:e.id,path:e.path,copy:!0,collection:t,updateUrl:!0,onClose:()=>n?.(e)}),Promise.resolve(void 0)}},fn={icon:r.jsx(p.DeleteIcon,{}),name:"Delete",onClick({entity:e,fullPath:t,collection:o,context:a,selectionController:n,onCollectionChange:i,sideEntityController:s}){const{closeDialog:l}=a.dialogsController.open({key:"delete_entity_dialog_"+e.id,Component:({open:c})=>{if(!o||!t)throw new Error("deleteEntityAction: Collection is undefined");return r.jsx(un,{entityOrEntitiesToDelete:e,path:t,collection:o,callbacks:o.callbacks,open:c,onEntityDelete:()=>{a.analyticsController?.onAnalyticsEvent?.("single_entity_deleted",{path:t}),n?.setSelectedEntities(n.selectedEntities.filter(u=>u.id!==e.id)),i?.(),s?.close()},onClose:l})}});return Promise.resolve(void 0)}};function hl({tableController:e,enabled:t}){if(!t)return null;const o=!!e.filterValues&&Object.keys(e.filterValues).length>0,a=!!e.sortBy&&e.sortBy.length>0;if((o||a)&&(e.clearFilter||e.setSortBy)){let n;return o&&a?n="Clear filter and sort":o?n="Clear filter":n="Clear sort",r.jsxs(p.Button,{variant:"outlined",className:"h-fit-content","aria-label":"filter clear",onClick:()=>{e.clearFilter?.(),e.setSortBy?.(void 0)},size:"small",children:[r.jsx(p.FilterListOffIcon,{}),n]})}return null}function gl({collection:e,relativePath:t,parentCollectionIds:o,path:a,selectionController:n,tableController:i,collectionEntitiesCount:s}){const l=Ae(),u=oe().plugins??[],m={path:a,relativePath:t,parentCollectionIds:o,collection:e,selectionController:n,context:l,tableController:i,collectionEntitiesCount:s},g=[r.jsx(hl,{tableController:i,enabled:!e.forceFilter},"clear_filter")];return u&&u.forEach((f,h)=>{f.collectionView?.CollectionActionsStart&&g.push(...St(f.collectionView?.CollectionActionsStart).map((b,y)=>r.jsx(ae,{children:r.jsx(b,{...m,...f.collectionView?.collectionActionsStartProps})},`plugin_actions_${h}_${y}`)))}),r.jsx(r.Fragment,{children:g})}const Al="collectionGroupParent",io=d.memo(function({fullPath:t,parentCollectionIds:o,isSubCollection:a,className:n,...i}){const s=Ae(),l=t??i.path,c=Me(i),u=pe(),m=Je(),g=We(),f=pt(),h=ut(),b=oe(),y=d.useRef(null),A=d.useMemo(()=>{const W=f?.getCollectionConfig(l);return W?De(i,W):i},[i,l,f?.getCollectionConfig]),k=d.useRef(A);d.useEffect(()=>{k.current=A},[A]);const v=ct(A,g,l,null),[_,E]=d.useState(void 0),[C,B]=d.useState(void 0),[x,S]=d.useState(0),[I,D]=d.useState(0),P=d.useCallback(()=>{const W=_;setTimeout(()=>{W===_&&E(void 0)},2400)},[_]),T=d.useCallback(W=>{const se=k.current;return Ir(se,g,l,W??null)?se.inlineEditing===void 0||se.inlineEditing:!1},[g,l]),V=A.selectionEnabled===void 0||A.selectionEnabled,re=!T(),[R,$]=d.useState(!1),G=ro(),z=A.selectionController??G,{selectedEntities:H,isEntitySelected:J,setSelectedEntities:ee}=z;d.useEffect(()=>{B(void 0)},[H]);const ne=to({fullPath:l,collection:A,lastDeleteTimestamp:x}),U=d.useRef(Math.random().toString(36)),X=ne.popupCell,Q=d.useCallback(()=>{ne.setPopupCell?.(void 0)},[ne.setPopupCell]),K=d.useCallback(W=>{console.log("Entity clicked",W);const se=k.current;return E(W),h.onAnalyticsEvent?.("edit_entity_clicked",{path:W.path,entityId:W.id}),m.open({entityId:W.id,path:W.path,collection:se,updateUrl:!0,onClose:P})},[P,m]),Z=d.useCallback(()=>{const W=k.current;h.onAnalyticsEvent?.("new_entity_click",{path:l}),m.open({path:l,collection:W,updateUrl:!0,onClose:P})},[l,m]),M=()=>{h.onAnalyticsEvent?.("multiple_delete_dialog_open",{path:l}),B(H)},Y=(W,se)=>{h.onAnalyticsEvent?.("single_entity_deleted",{path:l}),ee(ce=>ce.filter(de=>de.id!==se.id)),S(Date.now())},q=(W,se)=>{h.onAnalyticsEvent?.("multiple_entities_deleted",{path:l}),ee([]),B(void 0),S(Date.now())};let F;b?.plugins&&(F=b.plugins.find(W=>W.collectionView?.AddColumnComponent)?.collectionView?.AddColumnComponent);const N=d.useCallback((W,se)=>{if(f){const ce=f.getCollectionConfig(W),de=De(ce,se);f.onCollectionModified(W,de)}},[f]),le=d.useCallback(({width:W,key:se})=>{const ce=k.current;if(!Re(ce.properties,se))return;const de=hn(se,W);N(l,de)},[N,l]),xe=d.useCallback(W=>{f&&N(l,{defaultSize:W})},[N,l,f]),te=ct(A,g,l,null),O=d.useCallback(({name:W,value:se,property:ce,entityId:de})=>c.checkUniqueField(l,W,se,de),[l]),ie=({value:W,propertyKey:se,onValueUpdated:ce,setError:de,data:be})=>{const Dt=ve.setIn({...be.values},se,W),Bo={path:l,entityId:be.id,values:Dt,previousValues:be.values,collection:A,status:"existing"};return Mr({...Bo,collection:A,dataSource:c,context:s,onSaveSuccess:()=>{de(void 0),ce()},onSaveFailure:Vn=>{console.error("Save failure"),console.error(Vn),de(Vn)}})},fe=u.resolveAliasesFrom(l),ue=d.useMemo(()=>Ne({collection:A,path:l,fields:b.propertyConfigs}),[A,l]),he=d.useCallback(({propertyKey:W,entity:se})=>{let ce=Re(A.properties,W);return ce||(ce=Re(ue.properties,W)),Pe({propertyKey:W,propertyOrBuilder:ce,path:l,values:se.values,entityId:se.id,fields:b.propertyConfigs})},[A.properties,b.propertyConfigs,l,ue.properties]),ze=Xr(ue,!0),Ve=d.useMemo(()=>{const W=A.subcollections?.map(ce=>({key:Zr(ce),name:ce.name,width:200,dependencies:[],Builder:({entity:de})=>r.jsx(p.Button,{color:"primary",variant:"outlined",startIcon:r.jsx(p.KeyboardTabIcon,{size:"small"}),onClick:be=>{be.stopPropagation(),m.open({path:l,entityId:de.id,selectedSubPath:ce.id??ce.path,collection:A,updateUrl:!0})},children:ce.name})}))??[],se=A.collectionGroup?[{key:Al,name:"Parent entities",width:260,dependencies:[],Builder:({entity:ce})=>{const de=u.getParentReferencesFromPath(ce.path);return r.jsx(r.Fragment,{children:de.map(be=>r.jsx(Oe,{reference:be,size:"tiny"},be.path+"/"+be.id))})}}]:[];return[...A.additionalFields??[],...W,...se]},[A,l,m]),Ge=d.useCallback(()=>{S(Date.now())},[]),Ue=Qe(),at=({entity:W,customEntityActions:se})=>{const ce=W?Wt(A,g,l,W):!0,de=[fl];return te&&de.push(mn),ce&&de.push(fn),se&&de.push(...se),de},Co=()=>{const W=at({}),se=W.filter(be=>be.collapsed!==!1),de=W.filter(be=>be.collapsed===!1).length*(Ue?40:30);return(Ue?80+de:70+de)+(se.length>0?Ue?40:30:0)},Eo=({entity:W,size:se,width:ce,frozen:de})=>{const be=J(W),Dt=at({entity:W,customEntityActions:A.entityActions});return r.jsx(tr,{entity:W,width:ce,frozen:de,isSelected:be,selectionEnabled:V,size:se,highlightEntity:E,unhighlightEntity:P,collection:A,fullPath:l,actions:Dt,hideId:A?.hideIdFromCollection,onCollectionChange:Ge,selectionController:z})},j=r.jsx(p.Popover,{open:R,onOpenChange:$,enabled:!!A.description,trigger:r.jsxs("div",{className:"flex flex-col items-start",children:[r.jsx(p.Typography,{variant:"subtitle1",className:`leading-none truncate max-w-[160px] lg:max-w-[240px] ${A.description?"cursor-pointer":"cursor-auto"}`,onClick:A.description?W=>{$(!0),W.stopPropagation()}:void 0,children:`${A.name}`}),r.jsx(bl,{fullPath:l,collection:A,filter:ne.filterValues,sortBy:ne.sortBy,onCountChange:D})]}),children:A.description&&r.jsx("div",{className:"m-4 text-gray-900 dark:text-white",children:r.jsx(p.Markdown,{source:A.description})})}),Be=d.useCallback(({property:W,propertyKey:se,onHover:ce})=>{const de=k.current;return b.plugins?r.jsx(r.Fragment,{children:b.plugins.filter(be=>be.collectionView?.HeaderAction).map((be,Dt)=>{const Bo=be.collectionView.HeaderAction;return r.jsx(Bo,{onHover:ce,propertyKey:se,property:W,fullPath:l,collection:de,parentCollectionIds:o??[]},`plugin_header_action_${Dt}`)})}):null},[b.plugins,l,o]),Se=F?function(){return typeof F=="function"?r.jsx(F,{fullPath:l,parentCollectionIds:o??[],collection:A}):null}:void 0,{textSearchLoading:$e,textSearchInitialised:Nt,onTextSearchClick:Pt,textSearchEnabled:Tt}=oo({collection:A,fullPath:fe,parentCollectionIds:o});return r.jsxs("div",{className:p.cn("overflow-hidden h-full w-full rounded-md",n),ref:y,children:[r.jsx(eo,{additionalFields:Ve,tableController:ne,enablePopupIcon:!0,displayedColumnIds:ze,onSizeChanged:xe,onEntityClick:K,onColumnResize:le,onValueChange:ie,tableRowActionsBuilder:Eo,uniqueFieldValidator:O,title:j,selectionController:z,highlightedEntities:_?[_]:[],defaultSize:A.defaultSize,properties:ue.properties,getPropertyFor:he,onTextSearchClick:Nt?void 0:Pt,textSearchLoading:$e,textSearchEnabled:Tt,actionsStart:r.jsx(gl,{parentCollectionIds:o??[],collection:A,tableController:ne,path:l,relativePath:A.path,selectionController:z,collectionEntitiesCount:I}),actions:r.jsx(pn,{parentCollectionIds:o??[],collection:A,tableController:ne,onMultipleDeleteClick:M,onNewClick:Z,path:l,relativePath:A.path,selectionController:z,selectionEnabled:V,collectionEntitiesCount:I}),emptyComponent:v&&ne.filterValues===void 0&&ne.sortBy===void 0?r.jsxs("div",{className:"flex flex-col items-center justify-center",children:[r.jsx(p.Typography,{variant:"subtitle2",children:"So empty..."}),r.jsxs(p.Button,{color:"primary",variant:"outlined",onClick:Z,className:"mt-4",children:[r.jsx(p.AddIcon,{}),"Create your first entity"]})]}):r.jsx(p.Typography,{variant:"label",children:"No results with the applied filter/sort"}),hoverRow:re,inlineEditing:T(),AdditionalHeaderWidget:Be,AddColumnComponent:Se,getIdColumnWidth:Co,additionalIDHeaderWidget:r.jsx(yl,{path:l,collection:A})},`collection_table_${l}`),r.jsx(ul,{open:!!X,onClose:Q,cellRect:X?.cellRect,propertyKey:X?.propertyKey,collection:A,entity:X?.entity,tableKey:U.current,customFieldValidator:O,path:fe,onCellValueChange:ie,container:y.current},`popup_form_${X?.propertyKey}_${X?.entity?.id}`),C&&r.jsx(un,{entityOrEntitiesToDelete:C,path:l,collection:A,callbacks:A.callbacks,open:!!C,onEntityDelete:Y,onMultipleEntitiesDelete:q,onClose:()=>B(void 0)})]})},(e,t)=>L(e.fullPath,t.fullPath)&&L(e.parentCollectionIds,t.parentCollectionIds)&&L(e.isSubCollection,t.isSubCollection)&&L(e.className,t.className)&&L(e.properties,t.properties)&&L(e.propertiesOrder,t.propertiesOrder)&&L(e.hideIdFromCollection,t.hideIdFromCollection)&&L(e.inlineEditing,t.inlineEditing)&&L(e.selectionEnabled,t.selectionEnabled)&&L(e.selectionController,t.selectionController)&&L(e.Actions,t.Actions)&&L(e.defaultSize,t.defaultSize)&&L(e.initialFilter,t.initialFilter)&&L(e.initialSort,t.initialSort)&&L(e.textSearchEnabled,t.textSearchEnabled)&&L(e.additionalFields,t.additionalFields)&&L(e.sideDialogWidth,t.sideDialogWidth)&&L(e.forceFilter,t.forceFilter));function bl({fullPath:e,collection:t,filter:o,sortBy:a,onCountChange:n}){const i=Me(t),s=pe(),[l,c]=d.useState(void 0),[u,m]=d.useState(void 0),g=a?a[0]:void 0,f=a?a[1]:void 0,h=d.useMemo(()=>s.resolveAliasesFrom(e),[e,s.resolveAliasesFrom]);return d.useEffect(()=>{i.countEntities&&i.countEntities({path:h,collection:t,filter:o,orderBy:g,order:f}).then(c).catch(m)},[e,i.countEntities,h,t,o,g,f]),d.useEffect(()=>{n&&(m(void 0),n(l??0))},[n,l]),u?null:r.jsx(p.Typography,{className:"w-full text-ellipsis block overflow-hidden whitespace-nowrap max-w-xs text-left w-fit-content",variant:"caption",color:"secondary",children:l!==void 0?`${l} entities`:r.jsx(p.Skeleton,{className:"w-full max-w-[80px] mt-1"})})}function hn(e,t){if(e.includes(".")){const[o,...a]=e.split(".");return{properties:{[o]:hn(a.join("."),t)}}}return{properties:{[e]:{columnWidth:t}}}}function yl({collection:e,path:t}){const[o,a]=d.useState(!1),[n,i]=d.useState(""),s=Je();return r.jsx(p.Tooltip,{title:o?void 0:"Find by ID",children:r.jsx(p.Popover,{open:o,onOpenChange:a,trigger:r.jsx(p.IconButton,{size:"small",children:r.jsx(p.SearchIcon,{size:"small"})}),children:r.jsx("form",{noValidate:!0,onSubmit:l=>{if(l.preventDefault(),!!n)return a(!1),s.open({entityId:n,path:t,collection:e,updateUrl:!0})},className:"text-gray-900 dark:text-white w-96 max-w-full",children:r.jsxs("div",{className:"flex p-2 w-full gap-4",children:[r.jsx("input",{autoFocus:o,placeholder:"Find entity by ID",onChange:l=>i(l.target.value),value:n,className:"flex-grow bg-transparent outline-none p-1"}),r.jsx(p.Button,{variant:"outlined",disabled:!n,type:"submit",children:"Go"})]})})})})}function wl({propertyConfig:e}){const t="h-8 w-8 p-1 rounded-full shadow text-white",o=typeof e?.property=="object"?Dn(e.property):void 0;return r.jsx("div",{className:t,style:{background:e?.color??o?.color??"#888"},children:e?.Icon?$t(e,"medium"):$t(o,"medium")})}function gn(){return r.jsx("div",{className:"flex w-full h-full",children:r.jsxs("div",{className:"m-auto flex items-center flex-col",children:[r.jsx(p.Typography,{variant:"h4",align:"center",gutterBottom:!0,children:"Page not found"}),r.jsx(p.Typography,{align:"center",gutterBottom:!0,children:"This page does not exist or you may not have access to it"}),r.jsx(p.Button,{variant:"text",component:ge.Link,to:"/",children:"Back to home"})]})})}function vl({open:e,onAccept:t,onCancel:o,title:a,loading:n,body:i}){return r.jsxs(p.Dialog,{open:e,onOpenChange:s=>s?void 0:o(),children:[r.jsxs(p.DialogContent,{children:[r.jsx(p.Typography,{variant:"h6",className:"mb-2",children:a}),i]}),r.jsxs(p.DialogActions,{children:[r.jsx(p.Button,{variant:"text",onClick:o,autoFocus:!0,children:"Cancel"}),r.jsx(p.LoadingButton,{color:"primary",type:"submit",loading:n,onClick:t,children:"Ok"})]})]})}function so({width:e,height:t,className:o,style:a}){return r.jsxs("svg",{width:e??"100%",height:t??"100%",viewBox:"0 0 599 599",version:"1.1",style:a,className:o,xmlns:"http://www.w3.org/2000/svg",children:[r.jsxs("defs",{children:[r.jsxs("radialGradient",{cx:"28.6213569%",cy:"43.1133328%",fx:"28.6213569%",fy:"43.1133328%",r:"71.5003456%",gradientTransform:"translate(0.286214,0.431133),rotate(3.343450),scale(1.000000,0.996175),translate(-0.286214,-0.431133)",id:"radialGradient-1",children:[r.jsx("stop",{stopColor:"#FF5B79",offset:"0%"}),r.jsx("stop",{stopColor:"#FA5574",offset:"28.0930803%"}),r.jsx("stop",{stopColor:"#EC4C51",offset:"44.7242531%"}),r.jsx("stop",{stopColor:"#9543C1",offset:"71.4578165%"}),r.jsx("stop",{stopColor:"#3857B3",offset:"100%"})]}),r.jsxs("radialGradient",{cx:"53.6205516%",cy:"47.2473036%",fx:"53.6205516%",fy:"47.2473036%",r:"50.8229649%",gradientTransform:"translate(0.536206,0.472473),rotate(90.000000),scale(1.000000,1.206631),translate(-0.536206,-0.472473)",id:"radialGradient-2",children:[r.jsx("stop",{stopColor:"#68294F",stopOpacity:"0",offset:"0%"}),r.jsx("stop",{stopColor:"#5E2548",stopOpacity:"0.04641108",offset:"75.3503173%"}),r.jsx("stop",{stopColor:"#0D060B",stopOpacity:"0.437431709",offset:"100%"})]}),r.jsxs("radialGradient",{cx:"53.8605015%",cy:"48.1990423%",fx:"53.8605015%",fy:"48.1990423%",r:"59.9151549%",gradientTransform:"translate(0.538605,0.481990),rotate(180.000000),scale(1.000000,0.925027),translate(-0.538605,-0.481990)",id:"radialGradient-3",children:[r.jsx("stop",{stopColor:"#68294F",stopOpacity:"0",offset:"0%"}),r.jsx("stop",{stopColor:"#5E2548",stopOpacity:"0.04641108",offset:"84.0867343%"}),r.jsx("stop",{stopColor:"#FF0000",stopOpacity:"0.567324765",offset:"100%"})]})]}),r.jsx("g",{id:"Page-1",stroke:"none",strokeWidth:"1",fill:"none",fillRule:"evenodd",children:r.jsxs("g",{id:"firecms_logo",children:[r.jsx("circle",{fill:"url(#radialGradient-1)",cx:"299.5",cy:"299.5",r:"299.5"}),r.jsx("circle",{fill:"url(#radialGradient-2)",cx:"299.5",cy:"299.5",r:"299.5"}),r.jsx("circle",{fill:"url(#radialGradient-3)",cx:"299.5",cy:"299.5",r:"299.5"})]})})]})}const An=function({title:t,endAdornment:o,startAdornment:a,drawerOpen:n,dropDownActions:i,includeDrawer:s,className:l,style:c,logo:u,user:m}){const g=pe(),f=We(),{mode:h,toggleMode:b}=Or(),y=Qe(),A=m??f.user;let k;if(A&&A.photoURL)k=r.jsx(p.Avatar,{src:A.photoURL});else if(A===void 0||f.initialLoading)k=r.jsx("div",{className:"p-1 flex justify-center",children:r.jsx(p.Skeleton,{className:"w-10 h-10 rounded-full"})});else{const v=A?.displayName?A.displayName[0].toUpperCase():A?.email?A.email[0].toUpperCase():"A";k=r.jsx(p.Avatar,{children:v})}return r.jsx("div",{style:c,className:p.cn("pr-2",{"ml-[17rem]":n&&y,"ml-16":s&&!(n&&y),"h-16":!0,"z-10":y,"transition-all":!0,"ease-in":!0,"duration-75":!0,"w-full":!s,"w-[calc(100%-64px)]":s&&!(n&&y),"w-[calc(100%-17rem)]":s&&n&&y,"duration-150":n&&y,fixed:!0},l),children:r.jsxs("div",{className:"flex flex-row gap-2 px-4 h-full items-center",children:[g&&r.jsx("div",{className:"mr-8 hidden lg:block",children:r.jsx(ge.Link,{className:"visited:text-inherit visited:dark:text-inherit",to:g?.basePath??"/",children:r.jsxs("div",{className:"flex flex-row gap-4",children:[!s&&(u?r.jsx("img",{src:u,alt:"Logo",className:p.cn("w-[32px] h-[32px]")}):r.jsx(so,{width:"32px",height:"32px"})),typeof t=="string"?r.jsx(p.Typography,{variant:"subtitle1",noWrap:!0,className:"ml-2 !font-medium",children:t}):t]})})}),a,r.jsx("div",{className:"flex-grow"}),o&&r.jsx(ae,{children:o}),r.jsx(p.IconButton,{color:"inherit","aria-label":"Open drawer",onClick:b,size:"large",children:h==="dark"?r.jsx(p.DarkModeIcon,{}):r.jsx(p.LightModeIcon,{})}),r.jsxs(p.Menu,{trigger:k,children:[A&&r.jsxs("div",{className:"px-4 py-2 mb-2",children:[A.displayName&&r.jsx(p.Typography,{variant:"body1",color:"secondary",children:A.displayName}),A.email&&r.jsx(p.Typography,{variant:"body2",color:"secondary",children:A.email})]}),i,!i&&r.jsxs(p.MenuItem,{onClick:f.signOut,children:[r.jsx(p.LogoutIcon,{}),"Log Out"]})]})]})})},kl=e=>e&&Array.isArray(e)&&e.length>0?e.map((t,o)=>t?{[yr(t)+o]:It()}:{}).reduce((t,o)=>({...t,...o}),{}):{};function lo({droppableId:e,addLabel:t,value:o,disabled:a=!1,buildEntry:n,size:i="medium",onInternalIdAdded:s,includeAddButton:l,newDefaultEntry:c,onValueChange:u}){const m=o&&Array.isArray(o)&&o.length>0,g=d.useRef(kl(o)),[f,h]=d.useState(m?Object.values(g.current):[]);d.useEffect(()=>{if(m&&o&&o.length!==f.length){const v=o.map((_,E)=>{const C=yr(_)+E;if(C in g.current)return g.current[C];{const B=It();return g.current[C]=B,B}});h(v)}},[m,f.length,o]);const b=v=>{if(v.preventDefault(),a)return;const _=It(),E=[...f,_];s&&s(_),h(E),u([...o??[],c])},y=v=>{const _=[...f];_.splice(v,1),h(_),u(o.filter((E,C)=>C!==v))},A=v=>{const _=It(),E=o[v],C=[...f.splice(0,v+1),_,...f.splice(v+1,f.length-v-1)];s&&s(_),h(C),u([...o.slice(0,v+1),E,...o.slice(v+1)])},k=v=>{if(!v.destination)return;const _=v.source.index,E=v.destination.index,C=[...f],B=C[_];C[_]=C[E],C[E]=B,h(C),u(_l(o,_,E))};return r.jsx(nt.DragDropContext,{onDragEnd:k,children:r.jsx(nt.Droppable,{droppableId:e,renderClone:(v,_,E)=>{const C=E.source.index,B=f[C];return r.jsx(co,{provided:v,internalId:B,index:C,size:i,disabled:a,buildEntry:n,remove:y,copy:A,isDragging:_.isDragging})},children:(v,_)=>r.jsxs("div",{...v.droppableProps,ref:v.innerRef,children:[m&&f.map((E,C)=>r.jsx(nt.Draggable,{draggableId:`array_field_${E}`,isDragDisabled:a,index:C,children:(B,x)=>r.jsx(co,{provided:B,internalId:E,index:C,size:i,disabled:a,buildEntry:n,remove:y,copy:A,isDragging:x.isDragging})},`array_field_${E}`)),v.placeholder,l&&r.jsx("div",{className:"py-4 justify-center text-left",children:r.jsx(p.Button,{variant:"text",size:i==="small"?"small":"medium",color:"primary",disabled:a,startIcon:r.jsx(p.AddIcon,{}),onClick:b,children:t??"Add"})})]})})})}function co({provided:e,index:t,internalId:o,size:a,disabled:n,buildEntry:i,remove:s,copy:l,isDragging:c}){const[u,m]=d.useState(!1),g=d.useCallback(()=>m(!0),[]),f=d.useCallback(()=>m(!1),[]);return r.jsx("div",{onMouseEnter:g,onMouseMove:g,onMouseLeave:f,ref:e.innerRef,...e.draggableProps,style:e.draggableProps.style,className:`${c||u?p.fieldBackgroundHoverMixin:""} mb-1 rounded-md opacity-100`,children:r.jsxs("div",{className:"flex items-start",children:[r.jsx("div",{className:"flex-grow w-[calc(100%-48px)] text-text-primary dark:text-text-primary-dark",children:i(t,o)}),r.jsx(bn,{direction:a==="small"?"row":"column",disabled:n,remove:s,index:t,provided:e,copy:l})]})})}function bn({direction:e,disabled:t,remove:o,index:a,provided:n,copy:i}){const[s,l]=d.useState(!1),c=d.useRef(null);return p.useOutsideAlerter(c,()=>l(!1)),r.jsx("div",{className:`pl-2 pt-1 pb-4 flex ${e==="row"?"flex-row-reverse":"flex-col"} items-center`,ref:c,...n.dragHandleProps,children:r.jsxs(p.Tooltip,{delayDuration:400,open:s?!1:void 0,side:e==="column"?"left":void 0,title:"Drag to move. Click for more options",children:[r.jsx(p.IconButton,{size:"small",disabled:t,onClick:()=>l(!0),onDragStart:u=>{l(!1)},className:`cursor-${t?"inherit":"grab"}`,children:r.jsx(p.HandleIcon,{})}),r.jsxs(p.Menu,{portalContainer:c.current,open:s,trigger:r.jsx("div",{}),children:[r.jsxs(p.MenuItem,{dense:!0,onClick:u=>{l(!1),o(a)},children:[r.jsx(p.RemoveIcon,{size:"small"}),"Remove"]}),r.jsxs(p.MenuItem,{dense:!0,onClick:()=>{l(!1),i(a)},children:[r.jsx(p.ContentCopyIcon,{size:"small"}),"Copy"]})]})]})})}function _l(e,t,o){const a=Array.from(e),[n]=a.splice(t,1);return a.splice(o,0,n),a}function It(){return Math.floor(Math.random()*Math.floor(Number.MAX_SAFE_INTEGER))}function xl({name:e,multiselect:t=!1,path:o,disabled:a,value:n,onReferenceSelected:i,onMultipleReferenceSelected:s,previewProperties:l,forceFilter:c,size:u,className:m}){const g=pe(),f=d.useMemo(()=>g.getCollection(o),[o,g.getCollection]),h=d.useCallback(v=>{if(!a&&i){const _=v?je(v):null;i?.({reference:_,entity:v})}},[a,i]),b=d.useCallback(v=>{if(!a&&s){const _=v?v.map(E=>je(E)):null;s({references:_,entities:v})}},[a,i]),y=mt({multiselect:t,path:o,collection:f,onSingleEntitySelected:h,onMultipleEntitiesSelected:b,forceFilter:c});d.useCallback(v=>{v.stopPropagation(),t?b([]):h(null)},[i]);let A;const k=()=>{a||y.open()};return Array.isArray(n)?A=r.jsx("div",{className:"flex flex-col gap-4",children:n.map((v,_)=>r.jsx(Oe,{onClick:k,reference:v,disabled:a,previewProperties:l,size:u},`reference_preview_${_}`))}):n?.isEntityReference&&n?.isEntityReference()&&(A=r.jsx(Oe,{reference:n,onClick:k,disabled:a,previewProperties:l,size:u})),r.jsxs("div",{className:p.cn("text-sm font-medium text-gray-500","min-w-80 flex flex-col gap-4","relative transition-colors duration-200 ease-in rounded font-medium",a?"bg-opacity-50":"hover:bg-opacity-75","text-opacity-50 dark:text-white dark:text-opacity-50",m),children:[A,!n&&r.jsx("div",{className:"justify-center text-left",children:r.jsxs(p.Button,{variant:"outlined",color:"primary",disabled:a,onClick:k,children:["Edit ",e]})})]})}const Cl=220;Jt&&process.env.NODE_ENV!=="production"&&Object.keys(Jt).forEach(e=>{p.iconKeys.includes(e)||console.warn(`The icon ${e} no longer exists. Remove it from \`iconSynonyms\``)});function El({selectedIcon:e="",onIconSelected:t}){const[o,a]=d.useState(null),[n,i]=d.useState(""),s=d.useMemo(()=>p.debounce(c=>{if(!c||c==="")a(null);else{const u=Ht.search(c);a(u.map(m=>m.key))}},Cl),[]);d.useEffect(()=>(s(n),()=>{s.clear()}),[n,s]);const l=o===null?p.coolIconKeys:o;return r.jsxs(r.Fragment,{children:[r.jsx(p.SearchBar,{autoFocus:!0,innerClassName:"w-full sticky top-0 z-10",onTextSearch:c=>i(c??""),placeholder:"Search for more icons…"}),r.jsx("div",{className:"flex max-w-full flex-wrap mt-4",children:l.map(c=>r.jsx(p.Tooltip,{title:c,children:r.jsx(p.IconButton,{shape:"square",toggled:e===c,onClick:t?()=>t(c):void 0,className:"box-content m-1",children:r.jsx(p.Icon,{iconKey:c,size:24})})},c))})]})}function Bl({error:e,children:t}){return t?r.jsx(p.Typography,{variant:"caption",color:e?"error":"secondary",className:"ml-3.5 mt-0.5",children:t}):null}function nr({name:e,addLabel:t,value:o,disabled:a=!1,buildEntry:n,small:i,onInternalIdAdded:s,includeAddButton:l,newDefaultEntry:c=null,setFieldValue:u}){return r.jsx(lo,{droppableId:e,addLabel:t,value:o,disabled:a,buildEntry:n,size:i?"small":"medium",onInternalIdAdded:s,includeAddButton:l,newDefaultEntry:c,onValueChange:m=>u(e,m)})}function Ce({error:e,showError:t,property:o,includeDescription:a=!0,disabled:n}){const i=o.description||o.longDescription;if(!(t&&e)&&(!a||!i))return null;if(t&&e)return r.jsx(p.Typography,{variant:"caption",className:"ml-3.5 text-red-500 dark:text-red-500",children:e});const s=typeof o.disabled=="object"?o.disabled.disabledMessage:void 0;return r.jsxs("div",{className:"flex ml-3.5 mt-1",children:[r.jsx(p.Typography,{variant:"caption",color:n?"disabled":"secondary",className:"flex-grow",children:s||o.description}),o.longDescription&&r.jsx(p.Tooltip,{title:o.longDescription,side:"bottom",children:r.jsx(p.IconButton,{size:"small",className:"self-start",children:r.jsx(p.InfoIcon,{color:"disabled",size:"small"})})})]})}function Ee({icon:e,title:t,small:o,className:a,required:n}){return r.jsxs("span",{className:`inline-flex items-center my-0.5 ${o?"gap-1":"gap-2"} ${a??""}`,children:[e,r.jsx("span",{className:`text-start font-medium text-${o?"base":"sm"} origin-top-left transform ${o?"translate-x-2 scale-75":""}`,children:(t??"")+(n?" *":"")})]})}function po({propertyKey:e,value:t,setValue:o,error:a,showError:n,disabled:i,autoFocus:s,touched:l,property:c,includeDescription:u}){const m=c.enumValues;Te({property:c,value:t,setValue:o});const g=d.useCallback(f=>{f.stopPropagation(),f.preventDefault(),o(null)},[o]);return r.jsxs(r.Fragment,{children:[r.jsx(p.Select,{value:t?t.toString():"",disabled:i,position:"item-aligned",inputClassName:p.cn("w-full"),label:r.jsx(Ee,{icon:_e(c,"small"),required:c.validation?.required,title:c.name,className:"text-text-secondary dark:text-text-secondary-dark ml-3.5"}),endAdornment:c.clearable&&r.jsx(p.IconButton,{onClick:g,children:r.jsx(p.ClearIcon,{})}),onValueChange:f=>{const h=f?c.dataType==="number"?parseFloat(f):f:null;return o(h)},renderValue:f=>r.jsx(Ie,{enumKey:f,enumValues:m,size:"medium"}),children:m&&m.map(f=>r.jsx(p.SelectItem,{value:String(f.id),children:r.jsx(Ie,{enumKey:String(f.id),enumValues:m,size:"medium"})},f.id))}),r.jsx(Ce,{includeDescription:u,showError:n,error:a,disabled:i,property:c})]})}function uo({propertyKey:e,value:t,setValue:o,error:a,showError:n,disabled:i,property:s,includeDescription:l,autoFocus:c}){const u=s.of;if(!u)throw Error("Using wrong component ArrayEnumSelect");if(Array.isArray(u))throw Error("Using array properties instead of single one in `of` in ArrayProperty");if(u.dataType!=="string"&&u.dataType!=="number")throw Error("Field misconfiguration: array field of type string or number");const m=qe(u.enumValues);if(!m)throw console.error(s),Error("Field misconfiguration: array field of type string or number needs to have enumValues");Te({property:s,value:t,setValue:o});const g=!!t&&Array.isArray(t),f=d.useCallback((h,b)=>{const y=h!==void 0?jt(m,h):void 0;return r.jsxs(Ie,{enumKey:h,enumValues:m,size:"medium",children:[y?.label??h,!b&&r.jsx("button",{className:"ml-1 ring-offset-background rounded-full outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",onMouseDown:A=>{A.preventDefault(),A.stopPropagation()},onClick:A=>{A.preventDefault(),A.stopPropagation(),o(t.filter(k=>k!==h))},children:r.jsx(p.CloseIcon,{size:"smallest"})})]},h)},[m,o,t]);return r.jsxs("div",{className:"mt-0.5 ml-0.5 mt-2",children:[r.jsx(p.MultiSelect,{value:g?t.map(h=>h.toString()):[],disabled:i,label:r.jsx(Ee,{icon:_e(s,"small"),required:s.validation?.required,title:s.name,className:"text-text-secondary dark:text-text-secondary-dark ml-3.5"}),renderValue:d.useCallback(h=>f(h,!1),[f]),onMultiValueChange:h=>{let b;return u&&u?.dataType==="number"?b=h?h.map(y=>parseFloat(y)):[]:b=h,o(b)},children:m.map(h=>String(h.id)).map(h=>r.jsx(p.MultiSelectItem,{value:h,children:f(h,!0)},h))}),r.jsx(Ce,{includeDescription:l,showError:n,error:a,disabled:i,property:s})]})}function yn({propertyKey:e,value:t,error:o,showError:a,disabled:n,isSubmitting:i,tableMode:s,property:l,includeDescription:c,setValue:u,setFieldValue:m}){const g=l.of;if(g.dataType!=="reference")throw Error("ArrayOfReferencesField expected a property containing references");const f=l.expanded===void 0?!0:l.expanded,h=t&&Array.isArray(t)?t.map(B=>B.id):[];Te({property:l,value:t,setValue:u});const b=pe(),y=d.useMemo(()=>g.path?b.getCollection(g.path):void 0,[g.path]);if(!y)throw Error(`Couldn't find the corresponding collection for the path: ${g.path}`);const A=d.useCallback(B=>{console.debug("onMultipleEntitiesSelected",B),u(B.map(x=>je(x)))},[u]),k=mt({multiselect:!0,path:g.path,collection:y,onMultipleEntitiesSelected:A,selectedEntityIds:h,forceFilter:g.forceFilter}),v=d.useCallback(B=>{B.preventDefault(),k.open()},[k]),_=d.useCallback((B,x)=>{const S=t&&t.length>B?t[B]:void 0;return S?r.jsx(Oe,{disabled:!g.path,previewProperties:g.previewProperties,size:"medium",onClick:v,hover:!n,reference:S},x):r.jsx("div",{children:"Internal ERROR"})},[g.path,g.previewProperties,t]),E=r.jsx(Ee,{icon:_e(l,"small"),required:l.validation?.required,title:l.name,className:"text-text-secondary dark:text-text-secondary-dark"}),C=r.jsxs(r.Fragment,{children:[!y&&r.jsx(ye,{error:"The specified collection does not exist. Check console"}),y&&r.jsxs("div",{className:"group",children:[r.jsx(nr,{value:t,addLabel:l.name?"Add reference to "+l.name:"Add reference",name:e,buildEntry:_,disabled:i,setFieldValue:m,newDefaultEntry:l.of.defaultValue}),r.jsxs(p.Button,{className:"my-4 justify-center text-left",variant:"outlined",color:"primary",disabled:i,onClick:v,children:["Edit ",l.name]})]})]});return r.jsxs(r.Fragment,{children:[!s&&r.jsx(p.ExpandablePanel,{titleClassName:p.fieldBackgroundMixin,className:p.cn("px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2",p.fieldBackgroundMixin),initiallyExpanded:f,title:E,children:C}),s&&C,r.jsx(Ce,{includeDescription:c,showError:a,error:o,disabled:n,property:l})]})}function wn({name:e,property:t,value:o,entity:a,onRemove:n,disabled:i,size:s,collection:l}){return r.jsxs("div",{className:p.cn(p.paperMixin,"relative m-4 border-box flex items-center justify-center",s==="medium"?"min-w-[220px] min-h-[220px] max-w-[220px]":"min-w-[118px] min-h-[118px] max-w-[118px]"),children:[!i&&r.jsx("div",{className:"absolute rounded-full -top-2 -right-2 z-10 bg-white dark:bg-gray-900",children:r.jsx(p.Tooltip,{title:"Remove",children:r.jsx(p.IconButton,{size:"small",onClick:c=>{c.stopPropagation(),n(o)},children:r.jsx(p.RemoveIcon,{size:"small"})})})}),o&&r.jsx(ae,{children:r.jsx(we,{propertyKey:e,value:o,property:t,size:s})})]})}const Sl="box-border relative pt-[2px] items-center border border-transparent min-h-[254px] outline-none rounded-md duration-200 ease-[cubic-bezier(0.4,0,0.2,1)] focus:border-primary-solid",Il="border-dotted-gray",Fl="hover:bg-field-hover dark:hover:bg-field-hover-dark",Nl="pt-0 border-2 border-solid",Pl="transition-colors duration-200 ease-[cubic-bezier(0,0,0.2,1)] border-2 border-solid border-green-500",Tl="transition-colors duration-200 ease-[cubic-bezier(0,0,0.2,1)] border-2 border-solid border-red-500";function mo({propertyKey:e,value:t,setValue:o,error:a,showError:n,autoFocus:i,tableMode:s,property:l,includeDescription:c,context:u,isSubmitting:m}){if(!u.entityId)throw new Error("StorageUploadFieldBinding: Entity id is null");const g=dt(u.collection),f=st(l)||!!l.disabled||m,{internalValue:h,setInternalValue:b,onFilesAdded:y,storage:A,onFileUploadComplete:k,storagePathBuilder:v,multipleFilesSupported:_}=Oa({entityValues:u.values,entityId:u.entityId,path:u.path,property:l,propertyKey:e,value:t,storageSource:g,disabled:f,onChange:o});Te({property:l,value:t,setValue:o});const E={id:u.entityId,values:u.values,path:u.path};return r.jsxs(r.Fragment,{children:[!s&&r.jsx(Ee,{icon:_e(l,"small"),required:l.validation?.required,title:l.name,className:"text-text-secondary dark:text-text-secondary-dark ml-3.5"}),r.jsx(Ql,{value:h,collection:u.collection,name:e,disabled:f,autoFocus:i,property:l,onChange:o,setInternalValue:b,onFilesAdded:y,entity:E,onFileUploadComplete:k,storagePathBuilder:v,storage:A,multipleFilesSupported:_}),r.jsx(Ce,{includeDescription:c,showError:n,error:a,disabled:f,property:l})]})}function Dl({storage:e,collection:t,disabled:o,isDraggingOver:a,onFilesAdded:n,multipleFilesSupported:i,droppableProvided:s,autoFocus:l,internalValue:c,property:u,entity:m,onClear:g,metadata:f,storagePathBuilder:h,onFileUploadComplete:b,size:y,name:A,helpText:k}){const v=He(),{getRootProps:_,getInputProps:E,isDragActive:C,isDragAccept:B,isDragReject:x}=No.useDropzone({accept:e.acceptedFiles?e.acceptedFiles.map(S=>({[S]:[]})).reduce((S,I)=>({...S,...I}),{}):void 0,disabled:o||a,noDragEventsBubbling:!0,maxSize:e.maxSize,onDrop:n,onDropRejected:(S,I)=>{for(const D of S)for(const P of D.errors)v.open({type:"error",message:`Error uploading file: File is larger than ${e.maxSize} bytes`})}});return r.jsxs("div",{..._(),className:p.cn(p.fieldBackgroundMixin,o?p.fieldBackgroundDisabledMixin:p.fieldBackgroundHoverMixin,Sl,i&&c.length?"":"flex",p.focusedMixin,{[Fl]:!C,[Nl]:C,[Tl]:x,[Pl]:B,[Il]:o}),children:[r.jsxs("div",{...s.droppableProps,ref:s.innerRef,className:p.cn("flex items-center p-1 no-scrollbar",i&&c.length?"overflow-auto":"",i&&c.length?"min-h-[180px]":"min-h-[250px]"),children:[r.jsx("input",{autoFocus:l,...E()}),c.map((S,I)=>{let D;return S.storagePathOrDownloadUrl?D=r.jsx(wn,{collection:t,name:`storage_preview_${S.storagePathOrDownloadUrl}`,property:u,disabled:o,entity:m,value:S.storagePathOrDownloadUrl,onRemove:g,size:S.size}):S.file&&(D=r.jsx(Ya,{entry:S,metadata:f,storagePath:h(S.file),onFileUploadComplete:b,imageSize:y==="medium"?220:118,simple:!1})),r.jsx(nt.Draggable,{draggableId:`array_field_${A}_${S.id}`,index:I,children:(P,T)=>r.jsx("div",{tabIndex:-1,ref:P.innerRef,...P.draggableProps,...P.dragHandleProps,className:p.cn(p.focusedMixin,"rounded-md"),style:{...P.draggableProps.style},children:D})},`array_field_${A}_${S.id}`)}),s.placeholder]}),r.jsx("div",{className:"flex-grow min-h-[38px] box-border m-2 text-center",children:r.jsx(p.Typography,{align:"center",variant:"label",children:k})})]})}function Ql({collection:e,property:t,name:o,value:a,setInternalValue:n,onChange:i,multipleFilesSupported:s,onFileUploadComplete:l,disabled:c,onFilesAdded:u,autoFocus:m,storage:g,entity:f,storagePathBuilder:h}){if(s){const C=t;if(C.of){if(Array.isArray(C.of)||C.of.dataType!=="string")throw Error("Storage field using array must be of data type string")}else throw Error("Storage field using array must be of data type string")}const b=g?.metadata,y=s?"small":"medium",A=d.useCallback((C,B)=>{if(!s)return;const x=[...a],S=x[C];x.splice(C,1),x.splice(B,0,S),n(x);const I=x.filter(D=>!!D.storagePathOrDownloadUrl).map(D=>D.storagePathOrDownloadUrl);i(I)},[s,i,n,a]),k=d.useCallback(C=>{C.destination&&A(C.source.index,C.destination.index)},[A]),v=d.useCallback(C=>{if(s){const B=a.filter(x=>x.storagePathOrDownloadUrl!==C);i(B.filter(x=>!!x.storagePathOrDownloadUrl).map(x=>x.storagePathOrDownloadUrl)),n(B)}else i(null),n([])},[a,s,i]),_=s?"Drag 'n' drop some files here, or click to select files":"Drag 'n' drop a file here, or click to select one",E=s?t.of:t;return r.jsx(nt.DragDropContext,{onDragEnd:k,children:r.jsx(nt.Droppable,{droppableId:`droppable_${o}`,direction:"horizontal",renderClone:(C,B,x)=>{const S=a[x.source.index];return r.jsx("div",{ref:C.innerRef,...C.draggableProps,...C.dragHandleProps,style:C.draggableProps.style,className:"rounded",children:r.jsx(wn,{collection:e,name:`storage_preview_${S.storagePathOrDownloadUrl}`,property:E,disabled:!0,entity:f,value:S.storagePathOrDownloadUrl,onRemove:v,size:S.size})})},children:(C,B)=>r.jsx(Dl,{storage:g,collection:e,disabled:c,isDraggingOver:B.isDraggingOver,droppableProvided:C,onFilesAdded:u,multipleFilesSupported:s,autoFocus:m,internalValue:a,property:E,entity:f,onClear:v,metadata:b,storagePathBuilder:h,onFileUploadComplete:l,size:y,name:o,helpText:_})})})}function bt({context:e,propertyKey:t,value:o,setValue:a,error:n,showError:i,disabled:s,autoFocus:l,property:c,includeDescription:u}){let m,g;c.dataType==="string"&&(m=c.multiline,g=c.url),Te({property:c,value:o,setValue:a});const f=d.useCallback(A=>{A.stopPropagation(),A.preventDefault(),a(null)},[a]),h=A=>{if(y==="number"){const k=A.target.value?parseFloat(A.target.value):void 0;k&&isNaN(k)?a(null):k!=null?a(k):a(null)}else a(A.target.value)},b=!!m,y=c.dataType==="number"?"number":void 0;return r.jsxs(r.Fragment,{children:[r.jsx(p.TextField,{value:o,onChange:h,autoFocus:l,label:r.jsx(Ee,{icon:_e(c,"small"),required:c.validation?.required,title:c.name}),type:y,multiline:b,disabled:s,endAdornment:c.clearable&&r.jsx(p.IconButton,{onClick:f,children:r.jsx(p.ClearIcon,{})}),error:i?n:void 0,inputClassName:n?"text-red-500 dark:text-red-600":""}),r.jsx(Ce,{includeDescription:u,showError:i,error:n,disabled:s,property:c}),g&&r.jsx(p.Collapse,{className:"mt-1 ml-1",in:!!o,children:r.jsx(we,{value:o,property:c,size:"medium"})})]})}const vn=d.forwardRef(function({propertyKey:t,value:o,setValue:a,error:n,showError:i,autoFocus:s,disabled:l,touched:c,property:u,includeDescription:m},g){return Te({property:u,value:o,setValue:a}),r.jsxs(r.Fragment,{children:[r.jsx(p.BooleanSwitchWithLabel,{value:o,onValueChange:f=>a(f),error:i,label:r.jsx(Ee,{icon:_e(u,"small"),required:u.validation?.required,title:u.name}),disabled:l,autoFocus:s,size:"medium"}),r.jsx(Ce,{includeDescription:m,showError:i,error:n,disabled:l,property:u})]})});function kn({propertyKey:e,value:t,setValue:o,autoFocus:a,error:n,showError:i,disabled:s,touched:l,property:c,includeDescription:u}){const{locale:m}=oe(),g=t||null;return Te({property:c,value:t,setValue:o}),r.jsxs(r.Fragment,{children:[r.jsx(p.DateTimeField,{value:g,onChange:f=>o(f??null),size:"medium",mode:c.mode,clearable:c.clearable,locale:m,error:i,label:r.jsx(Ee,{icon:_e(c,"small"),required:c.validation?.required,className:i?"text-red-500 dark:text-red-500":"text-text-secondary dark:text-text-secondary-dark",title:c.name})}),r.jsx(Ce,{includeDescription:u,showError:i,error:n,disabled:s,property:c})]})}function fo({propertyKey:e,value:t,error:o,showError:a,tableMode:n,property:i,includeDescription:s,context:l}){if(!l.entityId)throw new Error("ReadOnlyFieldBinding: Entity id is null");return l.entityId,l.values,l.path,r.jsxs(r.Fragment,{children:[!n&&r.jsx(Ee,{icon:_e(i,"small"),required:i.validation?.required,title:i.name,className:"text-text-secondary dark:text-text-secondary-dark ml-3.5"}),r.jsx("div",{className:p.cn(p.paperMixin,"min-h-14 p-4 md:p-6 overflow-x-scroll no-scrollbar"),children:r.jsx(ae,{children:r.jsx(we,{propertyKey:e,value:t,property:i,size:"medium"})})}),r.jsx(Ce,{includeDescription:s,showError:a,error:o,property:i})]})}function _n(e){return typeof e.property.path!="string"?r.jsx(fo,{...e}):r.jsx(Ml,{...e})}function Ml({value:e,setValue:t,error:o,showError:a,isSubmitting:n,disabled:i,touched:s,autoFocus:l,property:c,includeDescription:u,context:m}){if(!c.path)throw new Error("Property path is required for ReferenceFieldBinding");Te({property:c,value:e,setValue:t});const g=e&&e.isEntityReference&&e.isEntityReference(),f=pe(),h=d.useMemo(()=>c.path?f.getCollection(c.path):void 0,[c.path]);if(!h)throw Error(`Couldn't find the corresponding collection for the path: ${c.path}`);const b=d.useCallback(k=>{t(k?je(k):null)},[t]),y=mt({multiselect:!1,path:c.path,collection:h,onSingleEntitySelected:b,selectedEntityIds:g?[e.id]:void 0,forceFilter:c.forceFilter}),A=d.useCallback(k=>{k.preventDefault(),y.open()},[y]);return r.jsxs(r.Fragment,{children:[r.jsx(Ee,{icon:_e(c,"small"),required:c.validation?.required,title:c.name,className:"text-text-secondary dark:text-text-secondary-dark ml-3.5"}),!h&&r.jsx(ye,{error:"The specified collection does not exist. Check console"}),h&&r.jsxs(r.Fragment,{children:[e&&r.jsx(Oe,{disabled:!c.path,previewProperties:c.previewProperties,hover:!i,size:"medium",onClick:i||n?void 0:A,reference:e}),!e&&r.jsx("div",{className:"justify-center text-left",children:r.jsxs(p.Button,{variant:"outlined",color:"primary",disabled:i||n,onClick:A,children:["Edit ",c.name]})})]}),r.jsx(Ce,{includeDescription:u,showError:a,error:o,disabled:i,property:c})]})}const ot=d.memo(Ol,(e,t)=>{if(e.propertyKey!==t.propertyKey)return!1;const o=ke(e.property)||e.property.fromBuilder,a=ke(t.property)||t.property.fromBuilder;return!((o===a||L(e.property,t.property))&&e.disabled===t.disabled)||ho(t.property),!1});function Ol({propertyKey:e,property:t,context:o,includeDescription:a,underlyingValueHasChanged:n,disabled:i,tableMode:s,partOfArray:l,partOfBlock:c,autoFocus:u}){const m=oe();return r.jsx(ve.Field,{name:e,children:g=>{let f;const h=Pe({propertyKey:e,propertyOrBuilder:t,values:g.form.values,path:o.path,entityId:o.entityId,fields:m.propertyConfigs});if(h===null||vt(h))return r.jsx(r.Fragment,{});if(st(h))f=fo;else if(h.Field)typeof h.Field=="function"&&(f=h.Field);else{const y=Ft(h,m.propertyConfigs);if(!y)throw console.log("INTERNAL: Could not find field config for property",{propertyKey:e,resolvedProperty:h,fields:m.propertyConfigs,propertyConfig:y}),new Error(`INTERNAL: Could not find field config for property ${e}`);f=Pe({propertyOrBuilder:y.property,values:g.form.values,path:o.path,entityId:o.entityId,fields:m.propertyConfigs}).Field}if(!f)return console.warn(`No field component found for property ${e}`),console.warn("Property:",t),r.jsx("div",{children:`Currently the field ${h.dataType} is not supported`});const b={propertyKey:e,property:h,includeDescription:a,underlyingValueHasChanged:n,context:o,disabled:i,tableMode:s,partOfArray:l,partOfBlock:c,autoFocus:u};return r.jsx(zl,{Component:f,componentProps:b,fieldProps:g})}})}function zl({Component:e,componentProps:{propertyKey:t,property:o,includeDescription:a,underlyingValueHasChanged:n,tableMode:i,partOfArray:s,partOfBlock:l,autoFocus:c,context:u,disabled:m},fieldProps:g}){const{plugins:f}=oe(),h=o.customProps,b=g.field.value,y=ve.getIn(g.form.errors,t),A=ve.getIn(g.form.touched,t),k=y&&(g.form.submitCount>0||o.validation?.unique)&&(!Array.isArray(y)||!!y.filter(S=>!!S).length),_=Vl(u.path,u.collection,t,o,e,f)??e,E=g.form.isSubmitting,C=d.useCallback((S,I)=>{g.form.setFieldTouched(t,!0,!1),g.form.setFieldValue(t,S,I)},[]),B=d.useCallback((S,I,D)=>{g.form.setFieldTouched(t,!0,!1),g.form.setFieldValue(S,I,D)},[]),x={propertyKey:t,value:b,setValue:C,setFieldValue:B,error:y,touched:A,showError:k,isSubmitting:E,includeDescription:a??!0,property:o,disabled:m??!1,underlyingValueHasChanged:n??!1,tableMode:i??!1,partOfArray:s??!1,partOfBlock:l??!1,autoFocus:c??!1,customProps:h,context:u};return r.jsxs(ae,{children:[r.jsx(_,{...x}),n&&!E&&r.jsx(p.Typography,{variant:"caption",className:"ml-3.5",children:"This value has been updated elsewhere"})]})}const ho=(e,t)=>{if(t?.some(n=>n.form?.fieldBuilder)||ke(e))return!0;const o=e,a=!!o.Field||"fromBuilder"in o&&o.fromBuilder;return o.dataType==="map"&&o.properties?a||Object.values(o.properties).some(n=>ho(n,t)):o.dataType==="array"&&"resolvedProperties"in o?a||o.resolvedProperties?.some(n=>n&&ho(n,t)):a};function Vl(e,t,o,a,n,i){return d.useRef((()=>{let l=null;return i&&i.forEach(c=>{const u=yo(a);if(u&&c.form?.fieldBuilder){const m={fieldConfigId:u,propertyKey:o,property:a,Field:n,plugin:c,path:e,collection:t},g=c.form?.fieldBuilderEnabled?.(m);(g===void 0||g)&&(l=c.form.fieldBuilder(m)||l)}u||console.warn("INTERNAL: Field id not found for property",a)}),l})()).current}function xn({propertyKey:e,value:t,showError:o,error:a,disabled:n,property:i,setValue:s,partOfBlock:l,tableMode:c,includeDescription:u,underlyingValueHasChanged:m,autoFocus:g,context:f}){const h=i.pickOnlySomeKeys||!1,b=(i.expanded===void 0?!0:i.expanded)||g;if(!i.properties)throw Error(`You need to specify a 'properties' prop (or specify a custom field) in your map property ${e}`);let y;h?t?y=Qo(i.properties,...Object.keys(t).filter(v=>v in i.properties)):y={}:y=i.properties;const A=r.jsx(r.Fragment,{children:r.jsx("div",{className:"py-1 flex flex-col space-y-2",children:Object.entries(y).filter(([v,_])=>!vt(_)).map(([v,_],E)=>{const C={propertyKey:`${e}.${v}`,disabled:n,property:_,includeDescription:u,underlyingValueHasChanged:m,context:f,tableMode:!1,partOfArray:!1,partOfBlock:!1,autoFocus:g&&E===0};return r.jsx("div",{children:r.jsx(ae,{children:r.jsx(ot,{...C})})},`map-${e}-${E}`)})})}),k=r.jsx(Ee,{icon:_e(i,"small"),required:i.validation?.required,title:i.name,className:"text-text-secondary dark:text-text-secondary-dark"});return r.jsxs(ae,{children:[!c&&!l&&r.jsx(p.ExpandablePanel,{initiallyExpanded:b,className:"px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2 bg-slate-50 bg-opacity-50 dark:bg-gray-900",title:k,children:A}),(c||l)&&A,r.jsx(Ce,{includeDescription:u,showError:o,error:a?typeof a=="string"?a:"A property of this map has an error":void 0,disabled:n,property:i})]})}function Cn({propertyKey:e,value:t,showError:o,error:a,disabled:n,property:i,setValue:s,tableMode:l,includeDescription:c,underlyingValueHasChanged:u,autoFocus:m,context:g}){const f=(i.expanded===void 0?!0:i.expanded)||m;if(!i.keyValue)throw Error(`Your property ${e} needs to have the 'keyValue' prop in order to use this field binding`);const h=r.jsx(go,{value:t,setValue:s,disabled:n,fieldName:i.name??e}),b=r.jsx(Ee,{icon:_e(i,"small"),required:i.validation?.required,title:i.name,className:"text-text-secondary dark:text-text-secondary-dark"});return r.jsxs(r.Fragment,{children:[!l&&r.jsx(p.ExpandablePanel,{initiallyExpanded:f,title:b,className:"px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2",children:h}),l&&h,r.jsx(Ce,{includeDescription:c,showError:o,error:a,disabled:n,property:i})]})}function go({value:e,setValue:t,fieldName:o,disabled:a}){const[n,i]=d.useState(Object.keys(e??{}).map(c=>[Ao(),{key:c,dataType:bo(e?.[c])??"string"}]));d.useEffect(()=>{const c=n.map(([h,{key:b}])=>b),u=Object.entries(e??{}).filter(([h,b])=>b!==void 0).map(([h])=>h),m=u.filter(h=>!c.includes(h)),g=c.filter(h=>!u.includes(h)),f=[...n];m.forEach(h=>{f.push([Ao(),{key:h,dataType:bo(e?.[h])??"string"}])}),g.forEach(h=>{const b=f.findIndex(([y,{key:A}])=>A===h);f.splice(b,1)}),i(f)},[e]);const s=d.useRef(e??{}),l=(c,u)=>{if(!c){console.warn("No key selected for data type update");return}i(n.map(m=>m[0]===c?[m[0],{key:m[1].key,dataType:u}]:m)),t({...e??{},[n.find(m=>m[0]===c)?.[1].key??""]:kr(u)})};return r.jsxs("div",{className:"py-1 flex flex-col gap-1",children:[n.map(([c,{key:u,dataType:m}],g)=>{const f=u?e?.[u]:"",h=b=>{if(i(n.map(A=>A[0]===c?[c,{key:b??"",dataType:A[1].dataType}]:A)),typeof e=="object"&&b in e)return;const y={...e??{}};typeof s.current=="object"&&u in s.current?y[u]=void 0:delete y[u],t({...y,[b??""]:f})};return r.jsx(Gl,{rowId:c,fieldKey:u,value:e??{},onDeleteClick:()=>{const b={...e??{}};s.current&&u in s.current?b[u]=void 0:delete b[u],i(n.filter(y=>y[0]!==c)),t({...b})},onFieldKeyChange:h,setValue:t,entryValue:f,dataType:m,disabled:a,updateDataType:l},c)}),r.jsx(p.Button,{variant:"text",size:"small",color:"primary",className:"w-full",disabled:a,startIcon:r.jsx(p.AddIcon,{}),onClick:c=>{c.preventDefault(),t({...e??{},"":null}),i([...n,[Ao(),{key:"",dataType:"string"}]])},children:o?`Add to ${o}`:"Add"})]})}function Gl({rowId:e,fieldKey:t,value:o,onFieldKeyChange:a,onDeleteClick:n,setValue:i,entryValue:s,dataType:l,updateDataType:c,disabled:u}){const{locale:m}=oe();function g(h,b,y){return y==="string"||y==="number"?r.jsx(p.TextField,{placeholder:"value",value:h,type:y==="number"?"number":"text",size:"small",disabled:u||!b,onChange:A=>{if(y==="number"){const k=A.target.value?parseFloat(A.target.value):void 0;k&&isNaN(k)?i({...o,[b]:null}):k!=null?i({...o,[b]:k}):i({...o,[b]:null})}else i({...o,[b]:A.target.value})}},y):y==="date"?r.jsx(p.DateTimeField,{value:h,size:"small",locale:m,disabled:u||!b,onChange:A=>{i({...o,[b]:A})}}):y==="boolean"?r.jsx(p.BooleanSwitchWithLabel,{value:h,size:"small",position:"start",disabled:u||!b,onValueChange:A=>{i({...o,[b]:A})}}):y==="array"?r.jsx("div",{className:p.cn(p.defaultBorderMixin,"ml-2 pl-2 border-l border-solid"),children:r.jsx(lo,{value:h,newDefaultEntry:"",droppableId:e.toString(),addLabel:b?`Add to ${b}`:"Add",size:"small",disabled:u||!b,includeAddButton:!0,onValueChange:A=>{i({...o,[b]:A})},buildEntry:(A,k)=>r.jsx(Yl,{index:A,id:k,value:h[A],disabled:u||!b,setValue:v=>{const _=[...h];_[A]=v,i({...o,[b]:_})}})})}):y==="map"?r.jsx("div",{className:p.cn(p.defaultBorderMixin,"ml-2 pl-2 border-l border-solid"),children:r.jsx(go,{value:h,fieldName:b,setValue:A=>{i({...o,[b]:A})}})}):r.jsx(p.Typography,{variant:"caption",children:`Data type ${y} not supported yet`})}function f(h){c(e,h)}return r.jsxs(r.Fragment,{children:[r.jsxs(p.Typography,{component:"div",className:"font-mono flex flex-row gap-1",children:[r.jsx("div",{className:"w-[200px] max-w-[25%]",children:r.jsx(p.TextField,{value:t,placeholder:"key",disabled:u||s!=null&&s!=="",size:"small",onChange:h=>{a(h.target.value)}})}),r.jsx("div",{className:"flex-grow",children:l!=="map"&&l!=="array"&&g(s,t,l)}),r.jsxs(p.Menu,{trigger:r.jsx(p.IconButton,{size:"small",className:"h-7 w-7",children:r.jsx(p.ArrowDropDownIcon,{})}),children:[r.jsx(p.MenuItem,{dense:!0,onClick:()=>f("string"),children:"string"}),r.jsx(p.MenuItem,{dense:!0,onClick:()=>f("number"),children:"number"}),r.jsx(p.MenuItem,{dense:!0,onClick:()=>f("boolean"),children:"boolean"}),r.jsx(p.MenuItem,{dense:!0,onClick:()=>f("date"),children:"date"}),r.jsx(p.MenuItem,{dense:!0,onClick:()=>f("map"),children:"map"}),r.jsx(p.MenuItem,{dense:!0,onClick:()=>f("array"),children:"array"})]}),r.jsx(p.IconButton,{"aria-label":"delete",size:"small",onClick:n,className:"h-7 w-7",children:r.jsx(p.RemoveIcon,{size:"small"})})]},e.toString()),(l==="map"||l==="array")&&g(s,t,l)]})}function Yl({id:e,index:t,value:o,setValue:a}){const{locale:n}=oe(),[i,s]=d.useState(bo(o)??"string");function l(u){s(u)}function c(u,m){return m==="string"||m==="number"?r.jsx(p.TextField,{value:u,type:m==="number"?"number":"text",size:"small",onChange:g=>{if(m==="number"){const f=g.target.value?parseFloat(g.target.value):void 0;f&&isNaN(f)?a(null):f!=null?a(f):a(null)}else a(g.target.value)}}):m==="date"?r.jsx(p.DateTimeField,{value:u,size:"small",locale:n,onChange:g=>{a(g)}}):m==="boolean"?r.jsx(p.BooleanSwitchWithLabel,{value:u,size:"small",position:"start",onValueChange:g=>{a(g)}}):m==="array"?r.jsx(p.Typography,{variant:"caption",children:"Arrays of arrays are not supported."}):m==="map"?r.jsx("div",{className:p.cn(p.defaultBorderMixin,"ml-2 pl-2 border-l border-solid"),children:r.jsx(go,{value:u,setValue:g=>{a(g)}})}):r.jsx(p.Typography,{variant:"caption",children:`Data type ${m} not supported yet`})}return r.jsxs(r.Fragment,{children:[r.jsxs(p.Typography,{component:"div",className:"font-mono flex min-h-12 flex-row gap-1 items-center",children:[r.jsx("div",{className:"flex-grow",children:i!=="map"&&c(o,i)}),r.jsxs(p.Menu,{trigger:r.jsx(p.IconButton,{size:"small",className:"h-7 w-7",children:r.jsx(p.ArrowDropDownIcon,{})}),children:[r.jsx(p.MenuItem,{dense:!0,onClick:()=>l("string"),children:"string"}),r.jsx(p.MenuItem,{dense:!0,onClick:()=>l("number"),children:"number"}),r.jsx(p.MenuItem,{dense:!0,onClick:()=>l("boolean"),children:"boolean"}),r.jsx(p.MenuItem,{dense:!0,onClick:()=>l("map"),children:"map"}),r.jsx(p.MenuItem,{dense:!0,onClick:()=>l("date"),children:"date"})]})]},e.toString()),i==="map"&&c(o,i)]})}function Ao(){return Math.floor(Math.random()*Math.floor(Number.MAX_SAFE_INTEGER))}function bo(e){if(typeof e=="string"||e===null)return"string";if(typeof e=="number")return"number";if(typeof e=="boolean")return"boolean";if(Array.isArray(e))return"array";if(e instanceof Date)return"date";if(e?.isEntityReference&&e?.isEntityReference())return"reference";if(e instanceof Ar)return"geopoint";if(typeof e=="object")return"map"}function En({propertyKey:e,value:t,error:o,showError:a,isSubmitting:n,setValue:i,setFieldValue:s,tableMode:l,property:c,includeDescription:u,underlyingValueHasChanged:m,context:g,disabled:f}){if(!c.of)throw Error("RepeatFieldBinding misconfiguration. Property `of` not set");if(!c.resolvedProperties||!Array.isArray(c.resolvedProperties))throw Error("RepeatFieldBinding - Internal error: Expected array in 'property.resolvedProperties'");const h=c.expanded===void 0?!0:c.expanded,b=c.of,[y,A]=d.useState();Te({property:c,value:t,setValue:i});const k=(E,C)=>{const B=c.resolvedProperties[E]??b,x={propertyKey:`${e}.${E}`,disabled:f,property:B,includeDescription:u,underlyingValueHasChanged:m,context:g,tableMode:!1,partOfArray:!0,partOfBlock:!1,autoFocus:C===y};return r.jsx(ae,{children:r.jsx(ot,{...x})})},v=r.jsx(nr,{value:t,addLabel:c.name?"Add entry to "+c.name:"Add entry",name:e,setFieldValue:s,buildEntry:k,onInternalIdAdded:A,disabled:n||!!c.disabled,includeAddButton:!c.disabled,newDefaultEntry:c.of.defaultValue}),_=r.jsx(Ee,{icon:_e(c,"small"),required:c.validation?.required,title:c.name,className:"text-text-secondary dark:text-text-secondary-dark"});return r.jsxs(r.Fragment,{children:[!l&&r.jsx(p.ExpandablePanel,{initiallyExpanded:h,className:"px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2",title:_,children:v}),l&&v,r.jsx(Ce,{includeDescription:u,showError:a,error:o,disabled:f,property:c})]})}function Bn({propertyKey:e,value:t,error:o,showError:a,isSubmitting:n,setValue:i,setFieldValue:s,tableMode:l,property:c,includeDescription:u,underlyingValueHasChanged:m,context:g,disabled:f}){if(!c.oneOf)throw Error("ArrayOneOfField misconfiguration. Property `oneOf` not set");const h=c.expanded===void 0?!0:c.expanded;Te({property:c,value:t,setValue:i});const[b,y]=d.useState(),A=d.useCallback((E,C)=>r.jsx(jl,{name:`${e}.${E}`,index:E,value:t[E],typeField:c.oneOf.typeField??wt,valueField:c.oneOf.valueField??Vt,properties:c.oneOf.properties,autoFocus:C===b,context:g},`array_one_of_${E}`),[g,b,c.oneOf,e,t]),k=r.jsx(Ee,{icon:_e(c,"small"),required:c.validation?.required,title:c.name,className:"text-text-secondary dark:text-text-secondary-dark"}),v=Object.keys(c.oneOf.properties)[0],_=r.jsx(nr,{value:t,name:e,addLabel:c.name?"Add entry to "+c.name:"Add entry",buildEntry:A,onInternalIdAdded:y,disabled:n||!!c.disabled,includeAddButton:!c.disabled,setFieldValue:s,newDefaultEntry:{[c.oneOf.typeField??wt]:v,[c.oneOf.valueField??Vt]:Gt(c.oneOf.properties[v])}});return r.jsxs(r.Fragment,{children:[!l&&r.jsx(p.ExpandablePanel,{className:"px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2",initiallyExpanded:h,title:k,children:_}),l&&_,r.jsx(Ce,{includeDescription:u,showError:a,error:o,disabled:f,property:c})]})}function jl({name:e,index:t,value:o,typeField:a,valueField:n,properties:i,autoFocus:s,context:l}){const c=o&&o[a],[u,m]=d.useState(c??void 0),g=ve.useFormex();d.useEffect(()=>{c||k(Object.keys(i)[0])},[]),d.useEffect(()=>{c!==u&&m(c)},[c]);const f=u?i[u]:void 0,h=Object.entries(i).map(([v,_])=>({id:v,label:_.name??v})),b=`${e}.${a}`,y=`${e}.${n}`,A=f?{propertyKey:y,property:f,context:l,autoFocus:s,partOfArray:!1,partOfBlock:!0,tableMode:!1}:void 0,k=v=>{const _=v?i[v]:void 0;m(v),g.setFieldTouched(b,!0),g.setFieldValue(b,v),g.setFieldValue(y,_?Gt(_):null)};return r.jsxs("div",{className:p.cn(p.paperMixin,"bg-transparent p-4 my-4 py-8"),children:[r.jsx(ve.Field,{name:b,children:v=>{const _=v.field.value!==void 0&&v.field.value!==null?v.field.value:"";return r.jsx(r.Fragment,{children:r.jsx(p.Select,{className:"mb-2",placeholder:r.jsx(p.Typography,{variant:"caption",className:"px-4 py-2 font-medium",children:"Type"}),size:"small",position:"item-aligned",value:_,renderValue:E=>r.jsx(Ie,{enumKey:E,enumValues:h,size:"small"}),onValueChange:E=>{k(E)},children:h.map(E=>r.jsx(p.SelectItem,{value:String(E.id),children:r.jsx(Ie,{enumKey:E.id,enumValues:h,size:"small"})},E.id))})})}}),A&&r.jsx(ot,{...A},`form_control_${e}_${u}`)]})}const Ll=new $n;try{Ke.use(Ke.Plugins.AutoResize,{min:100}),Ke.unuse(Ke.Plugins.FontUnderline),Ke.unuse(Ke.Plugins.Clear)}catch{}function Sn({propertyKey:e,value:t,setValue:o,error:a,showError:n,disabled:i,autoFocus:s,touched:l,property:c,tableMode:u,includeDescription:m,context:g}){const[f,h]=d.useState(t),b=d.useRef(t);p.useInjectStyles("MarkdownFieldBinding",Ul);const y=d.useDeferredValue({internalValue:f,value:t});return d.useEffect(()=>{b.current=t,h(t)},[t]),d.useEffect(()=>{y.internalValue!==b.current&&o(y.internalValue)},[y]),r.jsxs(r.Fragment,{children:[!u&&r.jsx(p.Typography,{variant:"caption",className:"flex-grow",children:r.jsx(Ee,{icon:_e(c,"small"),required:c.validation?.required,title:c.name,className:"text-text-secondary dark:text-text-secondary-dark ml-3.5"})}),r.jsx(Ke,{value:f??"",className:p.cn(p.fieldBackgroundMixin,i?p.fieldBackgroundDisabledMixin:p.fieldBackgroundHoverMixin,"text-base"),readOnly:i,renderHTML:A=>Ll.render(A),view:{menu:!0,md:!0,html:!1},onChange:({html:A,text:k})=>{h(k??null)}}),r.jsx(Ce,{includeDescription:m,showError:n,error:a,disabled:i,property:c})]})}const Ul=`
|
|
5
|
+
`))&&u(h)},onFocus:()=>{m.current=!0},onBlur:()=>{m.current=!1,g()}})}function Wr(e){const{name:t,enumValues:o,error:a,internalValue:n,disabled:i,small:s,focused:l,updateValue:c,multiple:u,valueType:m}=e,g=Array.isArray(n)&&u||!Array.isArray(n)&&!u,f=d.useRef(null);d.useEffect(()=>{f.current&&l&&f.current?.focus({preventScroll:!0})},[l,f]);const h=d.useCallback(y=>{if(m==="number")if(u){const A=y.map(k=>parseFloat(k));c(A)}else c(parseFloat(y));else if(m==="string")c(y||null);else throw Error("Missing mapping in TableSelect")},[u,c,m]),b=(y,A)=>u&&Array.isArray(y)?r.jsx(Lr,{value:y,name:t,enumValues:o,size:s?"small":"medium"},`${y}-${A}`):r.jsx(Ie,{enumKey:y,enumValues:o,size:s?"small":"medium"},`${y}-${A}`);return u?r.jsx(p.MultiSelect,{inputRef:f,containerClassName:"w-full h-full",className:"w-full h-full p-0 bg-transparent",position:"item-aligned",disabled:i,padding:!1,includeFocusOutline:!1,value:g?n.map(y=>y.toString()):[],onMultiValueChange:h,renderValue:b,children:o?.map(y=>r.jsx(p.MultiSelectItem,{value:String(y.id),children:r.jsx(Ie,{enumKey:y.id,enumValues:o,size:s?"small":"medium"})},y.id))}):r.jsx(p.Select,{inputRef:f,className:"w-full h-full p-0 bg-transparent",position:"item-aligned",disabled:i,multiple:u,padding:!1,includeFocusOutline:!1,value:g?u?n.map(y=>y.toString()):n?.toString():u?[]:"",onValueChange:h,onMultiValueChange:h,renderValue:b,children:o?.map(y=>r.jsx(p.SelectItem,{value:String(y.id),children:r.jsx(Ie,{enumKey:y.id,enumValues:o,size:s?"small":"medium"})},y.id))})}function ms(e){const{align:t,value:o,updateValue:a,focused:n}=e,i=o&&typeof o=="number"?o.toString():"",[s,l]=d.useState(i),c=d.useRef(o);d.useEffect(()=>{c.current!==o&&String(o)!==s&&l(o?o.toString():null),c.current=o},[o]);const u=d.useCallback(()=>{if(s!==i)if(s!=null){const f=parseFloat(s);if(isNaN(f))return;f!=null&&a(f)}else a(null)},[s,o]);Ut(s,u,!n,2e3),d.useEffect(()=>{!n&&i!==s&&l(o!=null?o.toString():null)},[o,n]);const m=d.useRef(null);d.useEffect(()=>{m.current&&n&&m.current.focus({preventScroll:!0})},[n,m]);const g=/^-?[0-9]+[,.]?[0-9]*$/;return r.jsx("input",{ref:m,className:"w-full text-right p-0 m-0 bg-transparent border-none resize-none outline-none font-normal leading-normal text-unset",style:{textAlign:t},value:s??"",onChange:f=>{const h=f.target.value.replace(",",".");h.length===0&&l(null),(g.test(h)||h.startsWith("-"))&&l(h)}})}function fs(e){const{internalValue:t,updateValue:o,focused:a}=e,n=d.useRef(null);return d.useEffect(()=>{n.current&&a&&n.current.focus({preventScroll:!0})},[a,n]),r.jsx(p.BooleanSwitch,{ref:n,size:"small",value:!!t,onValueChange:o})}function hs(e){const{locale:t}=oe(),{disabled:o,error:a,mode:n,internalValue:i,updateValue:s}=e;return r.jsx(p.DateTimeField,{value:i??void 0,onChange:l=>s(l??null),size:"medium",invisible:!0,className:"w-full h-full",inputClassName:"w-full h-full",mode:n,locale:t})}class ae extends d.Component{constructor(t){super(t),this.state={error:null}}static getDerivedStateFromError(t){return{error:t}}componentDidCatch(t,o){console.error(t)}render(){return this.state.error?r.jsxs("div",{className:"flex flex-col m-2",children:[r.jsxs("div",{className:"flex items-center m-2",children:[r.jsx(p.ErrorIcon,{color:"error",size:"small"}),r.jsx("div",{className:"ml-4",children:"Error"})]}),r.jsx(p.Typography,{variant:"caption",children:this.state.error?.message??"See the error in the console"})]}):this.props.children}}async function gs(e,t,o,a,n,i,s,l){let c;return typeof e=="function"?(c=await e({path:n,entityId:a,values:o,property:i,file:s,storage:t,propertyKey:l}),c||console.warn("Storage callback returned empty result. Using default name value")):c=Ma(s,e,a,l,n),c||(c=lt()+"_"+s.name),c}function As(e,t,o,a,n,i,s,l){let c;return typeof e=="function"?(c=e({path:n,entityId:a,values:o,property:i,file:s,storage:t,propertyKey:l}),c||console.warn("Storage callback returned empty result. Using default name value")):c=Ma(s,e,a,l,n),c||(c=lt()+"_"+s.name),c}function Ma(e,t,o,a,n){const i=e.name.split(".").pop();let s=t.replace("{entityId}",o).replace("{propertyKey}",a).replace("{rand}",lt()).replace("{file}",e.name).replace("{file.type}",e.type).replace("{path}",n);if(i){s=s.replace("{file.ext}",i);const l=e.name.replace(`.${i}`,"");s=s.replace("{file.name}",l)}return s||(s=lt()+"_"+e.name),s}function Oa({entityId:e,entityValues:t,path:o,value:a,property:n,propertyKey:i,storageSource:s,disabled:l,onChange:c}){const u=n.dataType==="string"?n.storage:n.dataType==="array"&&n.of.dataType==="string"?n.of.storage:void 0,m=n.dataType==="array";if(!u)throw Error("Storage meta must be specified");const g=u?.metadata,f=m?"small":"medium",h=u?.imageCompression,b=(m?a??[]:a?[a]:[]).map(x=>({id:Jr(),storagePathOrDownloadUrl:x,metadata:g,size:f})),[y,A]=d.useState(a),[k,v]=d.useState(b);d.useEffect(()=>{L(y,a)||(A(a),v(b))},[b,a,y]);const _=d.useCallback(async x=>{if(u.fileName){const S=await gs(u.fileName,u,t,e,o,n,x,i);if(!S||S.length===0)throw Error("You need to return a valid filename");return S}return lt()+"_"+x.name},[e,t,o,n,i,u]),E=d.useCallback(x=>As(u.storagePath,u,t,e,o,n,x,i)??"/",[e,t,o,n,i,u]),C=d.useCallback(async(x,S,I)=>{console.debug("onFileUploadComplete",x,S);let D=x;if(u.storeUrl&&(D=(await s.getDownloadURL(x)).url),u.postProcess&&D&&(D=await u.postProcess(D)),!D){console.warn("uploadPathOrDownloadUrl is null");return}let P;S.storagePathOrDownloadUrl=D,S.metadata=I,P=[...k],P=za(P),v(P);const T=P.filter(V=>!!V.storagePathOrDownloadUrl).map(V=>V.storagePathOrDownloadUrl);c(m?T:T?T[0]:null)},[k,m,c,u,s]),B=d.useCallback(async x=>{if(!x.length||l)return;let S;if(m)S=[...k,...await Promise.all(x.map(async I=>(h&&Hr(I)&&(I=await Ga(I,h)),{id:Jr(),file:I,fileName:await _(I),metadata:g,size:f})))];else{let I=x[0];h&&Hr(I)&&(I=await Ga(I,h)),S=[{id:Jr(),file:I,fileName:await _(I),metadata:g,size:f}]}S=za(S),v(S)},[l,_,k,g,m,f]);return{internalValue:k,setInternalValue:v,storage:u,fileNameBuilder:_,storagePathBuilder:E,onFileUploadComplete:C,onFilesAdded:B,multipleFilesSupported:m}}function za(e){return e.filter((t,o)=>(e.map(a=>a.storagePathOrDownloadUrl).indexOf(t.storagePathOrDownloadUrl)===o||!t.storagePathOrDownloadUrl)&&(e.map(a=>a.file).indexOf(t.file)===o||!t.file))}function Jr(){return Math.floor(Math.random()*Math.floor(Number.MAX_SAFE_INTEGER))}const Va={"image/jpeg":"JPEG","image/png":"PNG","image/webp":"WEBP"},Hr=e=>Va[e.type]?Va[e.type]:null,bs=100,Ga=(e,t)=>new Promise(o=>{const a=t.quality===void 0?bs:t.quality,n=a>=0&&a<=100?a:100,i=Hr(e);if(!i)throw Error("resizeAndCompressImage: Unsupported image format");jn.imageFileResizer(e,t.maxWidth||Number.MAX_VALUE,t.maxHeight||Number.MAX_VALUE,i,n,0,s=>o(s),"file")});function Ya({storagePath:e,entry:t,metadata:o,onFileUploadComplete:a,imageSize:n,simple:i}){const s=dt(),l=He(),[c,u]=d.useState(),[m,g]=d.useState(!1),f=d.useRef(!1),h=d.useRef(!1),b=d.useCallback((y,A)=>{h.current||(h.current=!0,u(void 0),g(!0),s.uploadFile({file:y,fileName:A,path:e,metadata:o}).then(async({path:k})=>{console.debug("Upload successful",k),await a(k,t,o),f.current&&g(!1)}).catch(k=>{console.warn("Upload error",k),f.current&&(u(k),g(!1),l.open({type:"error",message:"Error uploading file: "+k.message}))}).finally(()=>{h.current=!1}))},[t,o,a,s,e]);return d.useEffect(()=>(f.current=!0,t.file&&b(t.file,t.fileName),()=>{f.current=!1}),[t.file,t.fileName,b]),i?r.jsx("div",{className:`m-4 w-${n} h-${n}`,children:m&&r.jsx(p.Skeleton,{className:`w-${n} h-${n}`})}):r.jsxs("div",{className:p.cn(p.paperMixin,"relative m-4 border-box flex items-center justify-center",`min-w-[${n}px] min-h-[${n}px]`),children:[m&&r.jsx(p.Skeleton,{className:"w-full h-full"}),c&&r.jsx(ye,{title:"Error uploading file",error:c})]})}function ja({showError:e,disabled:t,showExpandIcon:o,selected:a,openPopup:n,children:i}){const s=d.useRef(null),l=d.useCallback(()=>{if(n){const u=s&&s?.current?.getBoundingClientRect();n(u)}},[]),c=d.useRef();return d.useEffect(()=>{c.current&&a&&c.current.focus({preventScroll:!0})},[a]),r.jsx(r.Fragment,{children:(e||!t&&o)&&r.jsxs("div",{ref:s,className:"absolute top-0.5 right-0.5 flex items-center",children:[a&&i,a&&!t&&o&&r.jsx(p.IconButton,{ref:c,color:"inherit",size:"small",onClick:l,children:r.jsxs("svg",{fill:"#888",width:"20",height:"20",viewBox:"0 0 24 24",children:[r.jsx("path",{className:"cls-2",d:"M20,5a1,1,0,0,0-1-1L14,4h0a1,1,0,0,0,0,2h2.57L13.29,9.29a1,1,0,0,0,0,1.42,1,1,0,0,0,1.42,0L18,7.42V10a1,1,0,0,0,1,1h0a1,1,0,0,0,1-1Z"}),r.jsx("path",{className:"cls-2",d:"M10.71,13.29a1,1,0,0,0-1.42,0L6,16.57V14a1,1,0,0,0-1-1H5a1,1,0,0,0-1,1l0,5a1,1,0,0,0,1,1h5a1,1,0,0,0,0-2H7.42l3.29-3.29A1,1,0,0,0,10.71,13.29Z"})]})}),e&&r.jsx(Go,{side:"left",className:"flex items-center justify-center",style:{width:32,height:32},title:e.message,children:r.jsx(p.ErrorOutlineIcon,{size:"small",color:"error"})})]})})}const ys="max-w-full box-border relative pt-[2px] items-center border border-transparent outline-none rounded-md duration-200 ease-[cubic-bezier(0.4,0,0.2,1)] focus:border-primary-solid",ws="pt-0 border-2 border-solid",vs="transition-colors duration-200 ease-[cubic-bezier(0,0,0.2,1)] border-2 border-solid border-green-500 bg-green-50 dark:bg-green-900",ks="transition-colors duration-200 ease-[cubic-bezier(0,0,0.2,1)] border-2 border-solid border-red-500 bg-red-50 dark:bg-red-900";function _s(e){const{propertyKey:t,error:o,selected:a,openPopup:n,value:i,disabled:s,property:l,entity:c,path:u,previewSize:m,updateValue:g}=e,f=dt(),{internalValue:h,setInternalValue:b,onFilesAdded:y,storage:A,onFileUploadComplete:k,storagePathBuilder:v,multipleFilesSupported:_}=Oa({entityValues:c.values,entityId:c.id,path:u,property:l,propertyKey:t,storageSource:f,onChange:g,value:i,disabled:s});return r.jsx(xs,{internalValue:h,setInternalValue:b,name:t,disabled:s,autoFocus:!1,openPopup:n,error:o,selected:a,property:l,onChange:g,entity:c,storagePathBuilder:v,storage:A,multipleFilesSupported:_,onFilesAdded:y,onFileUploadComplete:k,previewSize:m})}function xs({property:e,name:t,internalValue:o,setInternalValue:a,openPopup:n,entity:i,selected:s,error:l,onChange:c,multipleFilesSupported:u,previewSize:m,disabled:g,autoFocus:f,storage:h,onFilesAdded:b,onFileUploadComplete:y,storagePathBuilder:A}){const[k,v]=d.useState(!1),_=u&&m==="medium"?"small":m;if(u){const z=e;if(Array.isArray(z.of))throw Error("Using array properties instead of single one in `of` in ArrayProperty");if(z.of){if(z.of.dataType!=="string")throw Error("Storage field using array must be of data type string")}else throw Error("Storage field using array must be of data type string")}const E=h?.metadata,C=!!o,B=He(),{open:x,getRootProps:S,getInputProps:I,isDragActive:D,isDragAccept:P,isDragReject:T}=No.useDropzone({accept:h.acceptedFiles?h.acceptedFiles.map(z=>({[z]:[]})).reduce((z,H)=>({...z,...H}),{}):void 0,disabled:g,maxSize:h.maxSize,noClick:!0,noKeyboard:!0,onDrop:b,onDropRejected:(z,H)=>{for(const J of z)for(const ee of J.errors)B.open({type:"error",message:`Error uploading file: File is larger than ${h.maxSize} bytes`})}}),{...V}=S(),re=u?"Drag 'n' drop some files here, or click here to edit":"Drag 'n' drop a file here, or click here edit",R=u?e.of:e,$=d.useMemo(()=>ft(_),[_]),G=!g&&l;return r.jsxs("div",{...V,onMouseEnter:()=>v(!0),onMouseMove:()=>v(!0),onMouseLeave:()=>v(!1),className:p.cn(ys,"relative w-full h-full flex",`justify-${C?"start":"center"}`,D?ws:"",P?vs:"",T?ks:""),children:[r.jsx("input",{autoFocus:f,...I()}),o.map((z,H)=>{let J;return z.storagePathOrDownloadUrl?J=r.jsx(Cs,{property:R,value:z.storagePathOrDownloadUrl,entity:i,size:_},`storage_preview_${H}`):z.file&&(J=r.jsx(Ya,{entry:z,metadata:E,storagePath:A(z.file),onFileUploadComplete:y,imageSize:$,simple:!0},`storage_progress_${H}`)),J}),!o&&r.jsx("div",{className:"flex-grow m-2 max-w-[200px]",onClick:x,children:r.jsx(p.Typography,{className:"text-gray-400 dark:text-gray-600",variant:"body2",align:"center",children:re})}),r.jsx(ja,{showError:G,disabled:g,showExpandIcon:!0,selected:s,openPopup:g?void 0:n,children:r.jsx(p.IconButton,{color:"inherit",size:"small",onClick:x,children:r.jsx(p.EditIcon,{size:"small",className:"text-gray-500"})})})]})}function Cs({property:e,value:t,size:o,entity:a}){return r.jsx("div",{className:"relative p-2 max-w-full",children:t&&r.jsx(ae,{children:r.jsx(we,{propertyKey:"ignore",value:t,property:e,size:o})})})}function La(e){const t=oe(),o=pe(),{path:a}=e,n=o.getCollection(a);if(!n){if(t.components?.missingReference)return r.jsx(t.components.missingReference,{path:a});throw Error(`Couldn't find the corresponding collection view for the path: ${a}`)}return r.jsx(Es,{...e,collection:n})}const Es=d.memo(function(t){const{name:o,internalValue:a,updateValue:n,multiselect:i,path:s,size:l,previewProperties:c,title:u,disabled:m,forceFilter:g,collection:f}=t,h=d.useCallback(C=>{n(C?je(C):null)},[n]),b=d.useCallback(C=>{n(C.map(B=>je(B)))},[n]),y=a?Array.isArray(a)?a.map(C=>C.id):a.id?[a.id]:[]:[],A=mt({multiselect:i,path:s,collection:f,onMultipleEntitiesSelected:b,onSingleEntitySelected:h,selectedEntityIds:y,forceFilter:g}),k=d.useCallback(()=>{m||A.open()},[m,A]),v=!a||Array.isArray(a)&&a.length===0,_=()=>a&&!Array.isArray(a)&&a.isEntityReference&&a.isEntityReference()?r.jsx(Oe,{onClick:m?void 0:k,size:Ze(l),reference:a,hover:!m,disabled:!s,previewProperties:c}):r.jsx(ht,{onClick:m?void 0:k,size:Ze(l),children:r.jsx(ye,{title:"Value is not a reference.",error:"Click to edit"})}),E=()=>Array.isArray(a)?r.jsx(r.Fragment,{children:a.map((C,B)=>r.jsx("div",{className:"w-full my-0.5",children:r.jsx(Oe,{onClick:m?void 0:k,size:"tiny",reference:C,hover:!m,disabled:!s,previewProperties:c})},`preview_array_ref_${o}_${B}`))}):r.jsx(ye,{error:"Data is not an array of references"});return f?r.jsxs("div",{className:"w-full group",children:[a&&!i&&_(),a&&i&&E(),v&&r.jsxs(p.Button,{onClick:k,size:"small",variant:"outlined",color:"primary",children:["Edit ",u]})]}):r.jsx(ye,{error:"The specified collection does not exist"})},L);Fe.addMethod(Fe.array,"uniqueInArray",function(e=o=>o,t){return this.test("uniqueInArray",t,o=>!o||o.length===new Set(o.map(e)).size)});function Ua(e,t,o){const a={};return Object.entries(t).forEach(([n,i])=>{a[n]=Bt({property:i,customFieldValidator:o,name:n,entityId:e})}),Fe.object().shape(a)}function Bt(e){const t=e.property;if(ke(t))throw console.error("Error in property",e),Error("Trying to create a yup mapping from a property builder. Please use resolved properties only");if(t.dataType==="string")return Ss(e);if(t.dataType==="number")return Is(e);if(t.dataType==="boolean")return Ts(e);if(t.dataType==="map")return Bs(e);if(t.dataType==="array")return Qs(e);if(t.dataType==="date")return Ns(e);if(t.dataType==="geopoint")return Fs(e);if(t.dataType==="reference")return Ps(e);throw console.error("Unsupported data type in yup mapping",t),Error("Unsupported data type in yup mapping")}function Bs({property:e,entityId:t,customFieldValidator:o,name:a}){const n={},i=e.validation;e.properties&&Object.entries(e.properties).forEach(([l,c])=>{n[l]=Bt({property:c,parentProperty:e,customFieldValidator:o,name:`${a}[${l}]`,entityId:t})});const s=Fe.object().shape(n);return i?.required?s.required(i?.requiredMessage?i.requiredMessage:"Required").nullable(!0):s.nullable(!0)}function Ss({property:e,parentProperty:t,customFieldValidator:o,name:a,entityId:n}){let i=Fe.string();const s=e.validation;if(e.enumValues){s?.required&&(i=i.required(s?.requiredMessage?s.requiredMessage:"Required"));const l=qe(e.enumValues);i=i.oneOf((s?.required?l:[...l,null]).map(c=>c?.id??null)).nullable(!0)}if(s){if(i=s.required?i.required(s?.requiredMessage?s.requiredMessage:"Required").nullable(!0):i.notRequired().nullable(!0),s.unique&&o&&a&&(i=i.test("unique","This value already exists and should be unique",(l,c)=>o({name:a,property:e,parentProperty:t,value:l,entityId:n}))),(s.min||s.min===0)&&(i=i.min(s.min,`${e.name} must be min ${s.min} characters long`)),(s.max||s.max===0)&&(i=i.max(s.max,`${e.name} must be max ${s.max} characters long`)),s.matches){const l=typeof s.matches=="string"?$o(s.matches):s.matches;l&&(i=i.matches(l,s.matchesMessage?{message:s.matchesMessage}:void 0))}s.trim&&(i=i.trim()),s.lowercase&&(i=i.lowercase()),s.uppercase&&(i=i.uppercase()),e.email&&(i=i.email(`${e.name} must be an email`)),e.url&&(i=i.url(`${e.name} must be a url`))}else i=i.notRequired().nullable(!0);return i}function Is({property:e,parentProperty:t,customFieldValidator:o,name:a,entityId:n}){const i=e.validation;let s=Fe.number().typeError("Must be a number");return i?(s=i.required?s.required(i.requiredMessage?i.requiredMessage:"Required").nullable(!0):s.notRequired().nullable(!0),i.unique&&o&&a&&(s=s.test("unique","This value already exists and should be unique",l=>o({name:a,property:e,parentProperty:t,value:l,entityId:n}))),(i.min||i.min===0)&&(s=s.min(i.min,`${e.name} must be higher or equal to ${i.min}`)),(i.max||i.max===0)&&(s=s.max(i.max,`${e.name} must be lower or equal to ${i.max}`)),(i.lessThan||i.lessThan===0)&&(s=s.lessThan(i.lessThan,`${e.name} must be higher than ${i.lessThan}`)),(i.moreThan||i.moreThan===0)&&(s=s.moreThan(i.moreThan,`${e.name} must be lower than ${i.moreThan}`)),i.positive&&(s=s.positive(`${e.name} must be positive`)),i.negative&&(s=s.negative(`${e.name} must be negative`)),i.integer&&(s=s.integer(`${e.name} must be an integer`))):s=s.notRequired().nullable(!0),s}function Fs({property:e,parentProperty:t,customFieldValidator:o,name:a,entityId:n}){let i=Fe.object();const s=e.validation;return s?.unique&&o&&a&&(i=i.test("unique","This value already exists and should be unique",l=>o({name:a,property:e,parentProperty:t,value:l,entityId:n}))),s?.required?i=i.required(s.requiredMessage).nullable(!0):i=i.notRequired().nullable(!0),i}function Ns({property:e,parentProperty:t,customFieldValidator:o,name:a,entityId:n}){if(e.autoValue)return Fe.object().nullable();let i=Fe.date();const s=e.validation;return s?(i=s.required?i.required(s?.requiredMessage?s.requiredMessage:"Required"):i.notRequired(),s.unique&&o&&a&&(i=i.test("unique","This value already exists and should be unique",l=>o({name:a,property:e,parentProperty:t,value:l,entityId:n}))),s.min&&(i=i.min(s.min,`${e.name} must be after ${s.min}`)),s.max&&(i=i.max(s.max,`${e.name} must be before ${s.min}`))):i=i.notRequired(),i.transform(l=>l instanceof Date?l:null).nullable()}function Ps({property:e,parentProperty:t,customFieldValidator:o,name:a,entityId:n}){let i=Fe.object();const s=e.validation;return s?(i=s.required?i.required(s?.requiredMessage?s.requiredMessage:"Required").nullable(!0):i.notRequired().nullable(!0),s.unique&&o&&a&&(i=i.test("unique","This value already exists and should be unique",l=>o({name:a,property:e,parentProperty:t,value:l,entityId:n})))):i=i.notRequired().nullable(!0),i}function Ts({property:e,parentProperty:t,customFieldValidator:o,name:a,entityId:n}){let i=Fe.boolean();const s=e.validation;return s?(i=s.required?i.required(s?.requiredMessage?s.requiredMessage:"Required").nullable(!0):i.notRequired().nullable(!0),s.unique&&o&&a&&(i=i.test("unique","This value already exists and should be unique",l=>o({name:a,property:e,parentProperty:t,value:l,entityId:n})))):i=i.notRequired().nullable(!0),i}function Ds(e){return e.validation?.uniqueInArray?!0:e.dataType==="map"&&e.properties?Object.entries(e.properties).filter(([t,o])=>o.validation?.uniqueInArray):!1}function Qs({property:e,parentProperty:t,customFieldValidator:o,name:a,entityId:n}){let i=Fe.array();if(e.of)if(Array.isArray(e.of)){const l=e.of.map((c,u)=>({[`${a}[${u}]`]:Bt({property:c,parentProperty:e,entityId:n})})).reduce((c,u)=>({...c,...u}),{});return Fe.array().of(Fe.mixed().test("Dynamic object validation","Dynamic object validation error",(c,u)=>Ye(l,u.path).validate(c)))}else{i=i.of(Bt({property:e.of,parentProperty:e,entityId:n}));const l=Ds(e.of);l&&(typeof l=="boolean"?i=i.uniqueInArray(c=>c,`${e.name} should have unique values within the array`):Array.isArray(l)&&l.forEach(([c,u])=>{i=i.uniqueInArray(m=>m&&m[c],`${e.name} → ${u.name??c}: should have unique values within the array`)}))}const s=e.validation;return s?(i=s.required?i.required(s?.requiredMessage?s.requiredMessage:"Required").nullable(!0):i.notRequired().nullable(!0),(s.min||s.min===0)&&(i=i.min(s.min,`${e.name} should be min ${s.min} entries long`)),s.max&&(i=i.max(s.max,`${e.name} should be max ${s.max} entries long`))):i=i.notRequired().nullable(!0),i}function gt(e){switch(e){case"xl":return 400;case"l":return 280;case"m":return 140;case"s":return 80;case"xs":return 54;default:throw Error("Missing mapping for collection size -> height")}}const Ms=({justifyContent:e,scrollable:t,faded:o,fullHeight:a,children:n})=>r.jsx("div",{className:p.cn("flex flex-col max-h-full w-full",{"items-start":o||t}),style:{justifyContent:e,height:a?"100%":void 0,overflow:t?"auto":void 0,WebkitMaskImage:o?"linear-gradient(to bottom, black 60%, transparent 100%)":void 0,maskImage:o?"linear-gradient(to bottom, black 60%, transparent 100%)":void 0},children:n}),er=d.memo(function({children:t,actions:o,size:a,selected:n,disabled:i,disabledTooltip:s,saved:l,error:c,align:u,allowScroll:m,removePadding:g,fullHeight:f,onSelect:h,width:b,hideOverflow:y=!0,showExpandIcon:A=!0}){const[k,v]=Fo(),_=d.useRef(null),E=d.useMemo(()=>gt(a),[a]),[C,B]=d.useState(!1),[x,S]=d.useState(l),I=!i&&!!c;d.useEffect(()=>{l&&S(!0);const ee=setTimeout(()=>{S(!1)},800);return()=>{clearTimeout(ee)}},[l]);let D=0;if(!g)switch(a){case"l":case"xl":D=4;break;case"m":D=2;break;case"s":default:D=1;break}let P;switch(u){case"right":P="flex-end";break;case"center":P="center";break;case"left":default:P="flex-start"}const T=d.useCallback(()=>{if(!h)return;const ee=_&&_?.current?.getBoundingClientRect();i?h(void 0):!n&&ee&&h(ee)},[_,h,n,i]),V=d.useCallback(ee=>{T(),ee.stopPropagation()},[T]),re=d.useMemo(()=>v?v.height>E:!1,[v,E]),R=!I&&n,$=!i&&m&&re,G=!i&&!m&&re,z=d.useCallback(()=>B(!0),[]),H=d.useCallback(()=>B(!1),[]),J=I?"border-red-500":x?"border-green-500":R?"border-primary":"border-transparent";return r.jsxs("div",{className:p.cn("transition-colors duration-100 ease-in-out",`flex relative h-full rounded-md p-${D} border border-4 border-opacity-75`,C&&!i?"bg-gray-50 dark:bg-gray-900":"",l?"bg-gray-100 bg-opacity-75 dark:bg-gray-800 dark:bg-opacity-75":"",y?"overflow-hidden":"",R?"bg-gray-50 dark:bg-gray-900":"",J),ref:_,style:{justifyContent:P,alignItems:i||!re?"center":void 0,width:b??"100%",textAlign:u},tabIndex:n||i?void 0:0,onFocus:V,onMouseEnter:z,onMouseMove:z,onMouseLeave:H,children:[r.jsxs(ae,{children:[f&&!G&&t,(!f||G)&&r.jsx(Ms,{fullHeight:f??!1,justifyContent:P,scrollable:$??!1,faded:G,children:!f&&r.jsx("div",{ref:k,style:{display:"flex",width:"100%",justifyContent:P,height:f?"100%":void 0},children:t})})]}),o,i&&C&&s&&r.jsx("div",{className:"absolute top-1 right-1 text-xs",children:r.jsx(p.Tooltip,{title:s,children:r.jsx(p.RemoveCircleIcon,{size:"smallest",color:"disabled",className:"text-gray-500"})})})]})},(e,t)=>e.error===t.error&&e.value===t.value&&e.disabled===t.disabled&&e.saved===t.saved&&e.allowScroll===t.allowScroll&&e.align===t.align&&e.size===t.size&&e.disabledTooltip===t.disabledTooltip&&e.width===t.width&&e.showExpandIcon===t.showExpandIcon&&e.removePadding===t.removePadding&&e.fullHeight===t.fullHeight&&e.selected===t.selected),$a=d.createContext({}),Os=()=>d.useContext($a);function Te({property:e,value:t,setValue:o}){const a=d.useRef(null);d.useEffect(()=>{typeof e.disabled=="object"&&!!e.disabled.clearOnDisabled?t!=null&&(a.current=t,o(null)):a.current&&(o(a.current),a.current=null)},[e])}function zs(e){return e.dataType==="string"&&e.storage?!0:e.dataType==="array"?Array.isArray(e.of)?!1:e.of?.dataType==="string"&&e.of?.storage:!1}const qa=d.memo(function({propertyKey:t,customFieldValidator:o,value:a,property:n,align:i,width:s,height:l,path:c,entity:u,readonly:m,disabled:g,enablePopupIcon:f=!0}){const{onValueChange:h,size:b,selectedCell:y,select:A,setPopupCell:k}=Os(),v=y?.propertyKey===t&&y?.entity.path===u.path&&y?.entity.id===u.id,[_,E]=d.useState(a),C=d.useRef(a),[B,x]=d.useState(),[S,I]=d.useState(),[D,P]=d.useState(!1),T=d.useCallback(()=>{P(!0),setTimeout(()=>{P(!1)},100)},[]),V=!!n.Field,re=!!n.Preview,R=st(n),$=typeof n.disabled=="object"?n.disabled.disabledMessage:void 0,G=m||g||!!n.disabled,z=d.useMemo(()=>Bt({property:n,entityId:u.id,customFieldValidator:o,name:t}),[u.id,n,t]);d.useEffect(()=>{L(a,C.current)||(I(void 0),E(a),C.current=a,T())},[T,a]);const H=F=>{L(F,C.current)||(P(!1),z.validate(F).then(()=>{if(I(void 0),C.current=F,h)try{h({value:F,propertyKey:t,setError:x,onValueUpdated:T,data:u})}catch(N){console.error("onValueChange error",N),x(N)}}).catch(N=>{I(N)}))};d.useEffect(()=>{z.validate(_).then(()=>I(void 0)).catch(I)},[_,z,t,n,u]);const J=F=>{let N;F===void 0?N=null:N=F,E(N),H(N)};Te({property:n,value:_,setValue:J});const ee=d.useCallback(F=>{A(F?{width:s,height:l,entity:u,cellRect:F,propertyKey:t}:void 0)},[u,l,t,A,s]),ne=F=>{k&&k(F?{width:s,height:l,entity:u,cellRect:F,propertyKey:t}:void 0)};let U,X=!1,Q=!1,K=!0,Z=!1,M=!1,Y=!0;const q=!G&&B;if(m||R)return r.jsx(er,{size:b,width:s,saved:D,value:_,align:i??"left",fullHeight:!1,disabledTooltip:$??(R?"Read only":void 0),disabled:!0,children:r.jsx(we,{width:s,height:gt(b),propertyKey:t,property:n,value:_,size:Ze(b)})},`${t}_${u.path}_${u.id}`);if(!V&&(!re||v)){if(zs(n))U=r.jsx(_s,{error:S??B,disabled:G,focused:v,selected:v,openPopup:k?ne:void 0,property:n,entity:u,path:c,value:_,previewSize:Ze(b),updateValue:J,propertyKey:t}),Y=!1,Q=!0,M=!0,Z=!0;else if(v&&n.dataType==="number"){const N=n;N.enumValues?(U=r.jsx(Wr,{name:t,multiple:!1,disabled:G,focused:v,valueType:"number",small:Ze(b)!=="medium",enumValues:N.enumValues,error:S??B,internalValue:_,updateValue:J}),M=!0):(U=r.jsx(ms,{align:i,error:S??B,focused:v,disabled:G,value:_,updateValue:J}),X=!0)}else if(v&&n.dataType==="string"){const N=n;if(N.enumValues)U=r.jsx(Wr,{name:t,multiple:!1,focused:v,disabled:G,valueType:"string",small:Ze(b)!=="medium",enumValues:N.enumValues,error:S??B,internalValue:_,updateValue:J}),M=!0;else if(!N.storage){const le=!!N.multiline||!!N.markdown;U=r.jsx(us,{error:S??B,disabled:G,multiline:le,focused:v,value:_,updateValue:J}),X=!0}}else if(n.dataType==="boolean")U=r.jsx(fs,{error:S??B,disabled:G,focused:v,internalValue:_,updateValue:J});else if(n.dataType==="date")U=r.jsx(hs,{name:t,error:S??B,disabled:G,mode:n.mode,focused:v,internalValue:_,updateValue:J}),M=!0,K=!1,X=!1;else if(n.dataType==="reference")typeof n.path=="string"&&(U=r.jsx(La,{name:t,internalValue:_,updateValue:J,disabled:G,size:b,path:n.path,multiselect:!1,previewProperties:n.previewProperties,title:n.name,forceFilter:n.forceFilter})),X=!1;else if(n.dataType==="array"){const N=n;if(!N.of&&!N.oneOf)throw Error(`You need to specify an 'of' or 'oneOf' prop (or specify a custom field) in your array property ${t}`);N.of&&!Array.isArray(N.of)&&(N.of.dataType==="string"||N.of.dataType==="number"?v&&N.of.enumValues&&(U=r.jsx(Wr,{name:t,multiple:!0,disabled:G,focused:v,small:Ze(b)!=="medium",valueType:N.of.dataType,enumValues:N.of.enumValues,error:S??B,internalValue:_,updateValue:J}),X=!0,M=!0,K=!1):N.of.dataType==="reference"&&(typeof N.of.path=="string"&&(U=r.jsx(La,{name:t,disabled:G,internalValue:_,updateValue:J,size:b,multiselect:!0,path:N.of.path,previewProperties:N.of.previewProperties,title:N.name,forceFilter:N.of.forceFilter})),X=!1))}}return U||(X=!1,Q=f&&v&&!U&&!G&&!R,U=r.jsx(we,{width:s,height:l,propertyKey:t,value:_,property:n,size:Ze(b)})),r.jsx(er,{size:b,width:s,onSelect:ee,selected:v,disabled:G||R,disabledTooltip:$??"Disabled",removePadding:Z,fullHeight:M,saved:D,error:S??B,align:i,allowScroll:X,showExpandIcon:Q,value:_,hideOverflow:K,actions:Y&&r.jsx(ja,{showError:q,disabled:G,showExpandIcon:Q,selected:v,openPopup:G?void 0:ne}),children:U},`cell_${t}_${u.path}_${u.id}`)},Vs);function Vs(e,t){return e.height===t.height&&e.propertyKey===t.propertyKey&&e.align===t.align&&e.width===t.width&&L(e.property,t.property)&&L(e.value,t.value)&&L(e.entity.id,t.entity.id)&&L(e.entity.values,t.entity.values)}const tr=function({entity:t,collection:o,fullPath:a,width:n,frozen:i,isSelected:s,selectionEnabled:l,size:c,highlightEntity:u,onCollectionChange:m,unhighlightEntity:g,actions:f=[],hideId:h,selectionController:b}){const y=Qe(),A=Ae(),k=d.useCallback(x=>{b?.toggleEntitySelection(t)},[t,b?.toggleEntitySelection]),v=d.useCallback(x=>{x.stopPropagation(),b?.toggleEntitySelection(t)},[t,b?.toggleEntitySelection]),_=f.length>0,E=f.some(x=>x.collapsed||x.collapsed===void 0),C=f.filter(x=>x.collapsed||x.collapsed===void 0),B=f.filter(x=>x.collapsed===!1);return r.jsxs("div",{onClick:v,className:p.cn("h-full flex items-center justify-center flex-col bg-gray-50 dark:bg-gray-900 bg-opacity-90 dark:bg-opacity-90 z-10",i?"sticky left-0":""),style:{width:n,position:i?"sticky":"initial",left:i?0:"initial",contain:"strict"},children:[(_||l)&&r.jsxs("div",{className:"w-34 flex justify-center",children:[B.map((x,S)=>r.jsx(p.Tooltip,{title:x.name,children:r.jsx(p.IconButton,{onClick:I=>{I.stopPropagation(),x.onClick({entity:t,fullPath:a,collection:o,context:A,selectionController:b,highlightEntity:u,unhighlightEntity:g,onCollectionChange:m})},size:y?"medium":"small",children:x.icon})},S)),E&&r.jsx(p.Menu,{trigger:r.jsx(p.IconButton,{size:y?"medium":"small",children:r.jsx(p.MoreVertIcon,{})}),children:C.map((x,S)=>r.jsxs(p.MenuItem,{onClick:I=>{I.stopPropagation(),x.onClick({entity:t,fullPath:a,collection:o,context:A,selectionController:b,highlightEntity:u,unhighlightEntity:g,onCollectionChange:m})},children:[x.icon,x.name]},S))}),l&&r.jsx(p.Tooltip,{title:`Select ${t.id}`,children:r.jsx(p.Checkbox,{size:y?"medium":"small",checked:!!s,onCheckedChange:k})})]}),!h&&c!=="xs"&&r.jsx("div",{className:"w-[138px] text-center overflow-hidden truncate",children:t?r.jsxs(p.Typography,{onClick:x=>{x.stopPropagation()},className:"font-mono select-all",variant:"caption",color:"secondary",children:[" ",t.id," "]}):r.jsx(p.Skeleton,{})})]})};function Gs({actions:e,actionsStart:t,loading:o,onSizeChanged:a,onTextSearch:n,onTextSearchClick:i,size:s,textSearchLoading:l,title:c}){const u=d.useRef(null),m=Qe(),g=d.useRef(!1);d.useEffect(()=>{u.current&&g.current&&!l&&u.current.focus(),g.current=l??!1},[l]);const f=r.jsx(p.Tooltip,{title:"Table row size",side:"right",sideOffset:4,children:r.jsx(p.Select,{value:s,className:"w-16 h-10",size:"small",onValueChange:h=>a(h),renderValue:h=>r.jsx("div",{className:"font-medium",children:h.toUpperCase()}),children:["xs","s","m","l","xl"].map(h=>r.jsx(p.SelectItem,{value:h,className:"w-12 font-medium text-center",children:h.toUpperCase()},h))})});return r.jsxs("div",{className:p.cn(p.defaultBorderMixin,"no-scrollbar min-h-[56px] overflow-x-auto px-2 md:px-4 bg-gray-50 dark:bg-gray-900 border-b flex flex-row justify-between items-center w-full"),children:[r.jsxs("div",{className:"flex items-center gap-2 md:mr-4 mr-2",children:[c&&r.jsx("div",{className:"hidden lg:block",children:c}),f,t]}),r.jsxs("div",{className:"flex items-center gap-2",children:[m&&r.jsx("div",{className:"w-[22px]",children:o&&r.jsx(p.CircularProgress,{size:"small"})}),(n||i)&&r.jsx(p.SearchBar,{inputRef:u,loading:l,disabled:!!i,onClick:i,onTextSearch:i?void 0:n,expandable:!0},"search-bar"),e]})]})}function Ys(e){return e.dataType==="boolean"?"center":e.dataType==="number"?e.enumValues?"left":"right":e.dataType==="date"?"right":"left"}function Wa(e){if(e.columnWidth)return e.columnWidth;if(e.dataType==="string")return e.url?280:e.storage?160:e.enumValues?200:e.multiline||e.markdown?300:(e.email,200);if(e.dataType==="array"){const t=e;return t.of?Array.isArray(e.of)?300:Wa(t.of):300}else return e.dataType==="number"?e.enumValues?200:140:e.dataType==="map"?360:e.dataType==="date"?200:e.dataType==="reference"?220:e.dataType==="boolean"?140:200}function Zr(e){return`subcollection:${e.id??e.path}`}const Ja="collectionGroupParent";function Xr(e,t){return d.useMemo(()=>e.propertiesOrder?Ha(e,e.propertiesOrder):js(e,t),[e,t])}function Ha(e,t){return t.flatMap(o=>{const a=e.properties[o];return a?a.hideFromCollection?[null]:a.disabled&&typeof a.disabled=="object"&&a.disabled.hidden?[null]:a.dataType==="map"&&a.spreadChildren&&a.properties?rr(a,o):[{key:o,disabled:!!a.disabled||!!a.readOnly}]:e.additionalFields?.find(i=>i.key===o)?[{key:o,disabled:!0}]:e.subcollections&&e.subcollections.find(s=>Zr(s)===o)?[{key:o,disabled:!0}]:e.collectionGroup&&o===Ja?[{key:o,disabled:!0}]:[null]}).filter(Boolean)}function js(e,t){const o=Object.keys(e.properties),a=e.additionalFields??[],n=e.subcollections??[],i=[...o,...a.map(s=>s.key)];if(t){const s=n.map(l=>Zr(l));i.push(...s.filter(l=>!i.includes(l)))}return e.collectionGroup&&i.push(Ja),Ha(e,i)}function rr(e,t,o){return e.dataType==="map"&&e.spreadChildren&&e.properties?Object.entries(e.properties).flatMap(([a,n])=>rr(n,`${t}.${a}`,o||!!e.disabled||!!e.readOnly)):[{key:t,disabled:o||!!e.disabled||!!e.readOnly}]}function Ls(e){return{key:"id_ewcfedcswdf3",width:e?160:130,title:"ID",resizable:!1,frozen:e??!1,headerAlign:"center",align:"center"}}function Za({properties:e,sortable:t,forceFilter:o,AdditionalHeaderWidget:a}){const n=!!o;return Object.entries(e).flatMap(([i,s])=>rr(s,i)).map(({key:i,disabled:s})=>{const l=Sr(e,i);if(!l)throw Error("Internal error: no property found in path "+i);const c=Xa(l);return{key:i,align:Ys(l),icon:_e(l,"small"),title:l.name??i,sortable:t,filter:!n&&c,width:Wa(l),resizable:!0,custom:{resolvedProperty:l,disabled:s},AdditionalHeaderWidget:a?({onHover:u})=>r.jsx(a,{property:l,propertyKey:i,onHover:u}):void 0}})}function Xa(e,t=!1){return t?["string","number","date","reference"].includes(e.dataType):e.dataType==="array"?e.of?Xa(e.of,!0):!1:["string","number","boolean","date","reference","array"].includes(e.dataType)}function or({text:e,...t}){return r.jsx("div",{className:"flex w-full h-screen max-h-full max-w-full bg-gray-50 dark:bg-gray-900 gap-4",children:r.jsxs("div",{className:"m-auto flex flex-col gap-2 items-center",children:[r.jsx(p.CircularProgress,{...t}),e&&r.jsx(p.Typography,{color:"secondary",variant:"caption",className:"text-center",children:e})]})})}const Us=d.memo(function({resizeHandleRef:t,columnIndex:o,isResizingIndex:a,sort:n,onColumnSort:i,onFilterUpdate:s,filter:l,column:c,onClickResizeColumn:u,createFilterField:m,AdditionalHeaderWidget:g}){const[f,h]=d.useState(!1),[b,y]=d.useState(!1),[A,k]=d.useState(!1),v=d.useCallback(x=>{y(!0)},[]),_=d.useCallback((x,S)=>{s(c,x),S!==void 0&&y(S)},[c,s]),E=a===o,B=!(a!==o&&a>0)&&(f||E);return r.jsx(ae,{children:r.jsxs("div",{className:p.cn("flex py-0 px-3 h-full text-xs uppercase font-semibold relative select-none items-center bg-gray-50 dark:bg-gray-900","text-gray-600 hover:text-gray-800 dark:text-gray-400 dark:hover:text-gray-200 ","hover:bg-gray-100 dark:hover:bg-gray-800 hover:bg-opacity-50 dark:hover:bg-opacity-50",c.frozen?"sticky left-0 z-10":"relative z-0"),style:{left:c.frozen?0:void 0,minWidth:c.width,maxWidth:c.width},onMouseEnter:()=>h(!0),onMouseMove:()=>h(!0),onMouseLeave:()=>h(!1),children:[r.jsx("div",{className:"overflow-hidden flex-grow",children:r.jsxs("div",{className:`flex items-center justify-${c.headerAlign} flex-row`,children:[c.icon,r.jsx("div",{className:"truncate -webkit-box w-full mx-1 overflow-hidden",style:{WebkitBoxOrient:"vertical",WebkitLineClamp:2,justifyContent:c.align},children:c.title})]})}),r.jsxs(r.Fragment,{children:[g&&r.jsx(g,{onHover:f||b}),c.sortable&&(n||B||b)&&r.jsx(p.Badge,{color:"secondary",invisible:!n,children:r.jsxs(p.IconButton,{size:"small",className:f||b?"bg-white dark:bg-gray-950":void 0,onClick:()=>{i(c.key)},children:[!n&&r.jsx(p.ArrowUpwardIcon,{}),n==="asc"&&r.jsx(p.ArrowUpwardIcon,{}),n==="desc"&&r.jsx(p.ArrowUpwardIcon,{className:"rotate-180"})]})})]}),c.filter&&m&&r.jsx("div",{children:r.jsx(p.Badge,{color:"secondary",invisible:!l,children:r.jsx(p.Popover,{open:b,onOpenChange:y,className:A?"hidden":void 0,modal:!0,trigger:r.jsx(p.IconButton,{className:f||b?"bg-white dark:bg-gray-950":void 0,size:"small",onClick:v,children:r.jsx(p.FilterListIcon,{size:"small"})}),children:r.jsx($s,{column:c,filter:l,onHover:f,onFilterUpdate:_,createFilterField:m,hidden:A,setHidden:k})})})}),c.resizable&&r.jsx("div",{ref:t,className:p.cn("absolute h-full w-[6px] top-0 right-0 cursor-col-resize",B&&"bg-gray-300 dark:bg-gray-700"),onMouseDown:u?()=>u(o,c):void 0})]})})},L);function $s({column:e,onFilterUpdate:t,filter:o,onHover:a,createFilterField:n,hidden:i,setHidden:s}){const l=e.key,[c,u]=d.useState(o);if(d.useEffect(()=>{u(o)},[o]),!e.filter)return null;const m=()=>{t(c,!1)},g=b=>{t(void 0,!1)},f=!!o,h=n({id:l,filterValue:c,setFilterValue:u,column:e,hidden:i,setHidden:s});return h?r.jsxs("form",{noValidate:!0,onSubmit:b=>{b.stopPropagation(),b.preventDefault(),m()},className:"text-gray-900 dark:text-white",children:[r.jsx("div",{className:p.cn(p.defaultBorderMixin,"py-4 px-6 text-xs font-semibold uppercase border-b"),children:e.title??l}),h&&r.jsx("div",{className:"m-4",children:h}),r.jsxs("div",{className:"flex justify-end m-4",children:[r.jsx(p.Button,{className:"mr-4",disabled:!f,variant:"text",color:"primary",type:"reset","aria-label":"filter clear",onClick:g,children:"Clear"}),r.jsx(p.Button,{variant:"outlined",color:"primary",type:"submit",children:"Filter"})]})]}):null}const qs=({columns:e,currentSort:t,onColumnSort:o,onFilterUpdate:a,sortByProperty:n,filter:i,onColumnResize:s,onColumnResizeEnd:l,createFilterField:c,AddColumnComponent:u})=>{const m=e.map(()=>d.createRef()),[g,f]=d.useState(-1),h=d.useCallback((C,B,x)=>{const S=e[C],I=100,D=800,P=B>D?D:B<I?I:B,T={width:P,key:S.key,column:{...S,width:P}};x?l(T):s(T)},[e,s,l]),b=d.useCallback(C=>{if(g>=0){const B=m[g].current?.parentElement?.getBoundingClientRect().left;return B?C.clientX-B:void 0}},[m,g]),y=d.useCallback(C=>{document.body.style.cursor=C?"col-resize":"auto"},[]),A=d.useCallback(C=>{C.stopPropagation(),C.preventDefault();const B=b(C);B&&h(g,B,!1)},[h,b,g]),k=d.useCallback(C=>{C.stopPropagation(),C.preventDefault();const B=b(C);B&&h(g,B,!0),f(-1),y(!1)},[h,b,g,y]),v=d.useCallback(()=>{document.removeEventListener("mousemove",A),document.removeEventListener("mouseup",k)},[A,k]),_=d.useCallback(()=>{document.addEventListener("mousemove",A),document.addEventListener("mouseup",k)},[A,k]);d.useEffect(()=>(g>=0?_():v(),()=>{v()}),[_,g,v]);const E=d.useCallback(C=>{f(C),y(!0)},[y]);return r.jsxs("div",{className:p.cn(p.defaultBorderMixin,"z-20 sticky min-w-full flex w-fit flex-row top-0 left-0 h-12 border-b bg-gray-50 dark:bg-gray-900"),children:[e.map((C,B)=>{const x=e[B],S=x&&i&&i[x.key]?i[x.key]:void 0;return r.jsx(ae,{children:r.jsx(Us,{resizeHandleRef:m[B],columnIndex:B,isResizingIndex:g,onFilterUpdate:a,filter:S,sort:n===x.key?t:void 0,onColumnSort:o,onClickResizeColumn:E,column:x,createFilterField:c,AdditionalHeaderWidget:x.AdditionalHeaderWidget})},"header_"+x.key)}),u&&r.jsx(u,{})]})},Ws=d.memo(function({rowData:t,rowIndex:o,children:a,onRowClick:n,size:i,style:s,hoverRow:l,rowClassName:c}){const u=d.useCallback(m=>{n&&n({rowData:t,rowIndex:o,event:m})},[n,t,o]);return r.jsx("div",{className:p.cn("flex min-w-full text-sm border-b border-gray-200 dark:border-gray-800 border-opacity-40 dark:border-opacity-40",c?c(t):"",{"hover:bg-opacity-95":l,"cursor-pointer":n}),onClick:u,style:{...s,height:gt(i),width:"fit-content"},children:a})},L),Js=d.memo(function(t){return t.rowData&&t.cellRenderer({cellData:t.cellData,rowData:t.rowData,rowIndex:t.rowIndex,isScrolling:!1,column:t.column,columns:t.columns,columnIndex:t.columnIndex,width:t.column.width})},(e,t)=>L(e.rowData,t.rowData)&&L(e.column,t.column)&&L(e.cellData,t.cellData)&&L(e.rowIndex,t.rowIndex)&&L(e.cellRenderer,t.cellRenderer)&&L(e.columnIndex,t.columnIndex)),ar=d.createContext({});ar.displayName="VirtualListContext";const Hs=d.forwardRef(({children:e,...t},o)=>r.jsx(ar.Consumer,{children:a=>{const n=a.customView;return r.jsxs(r.Fragment,{children:[r.jsx("div",{id:"virtual-table",style:{position:"relative",height:"100%"},children:r.jsxs("div",{ref:o,...t,style:{...t?.style,minHeight:"100%",position:"relative"},children:[r.jsx(qs,{...a}),!n&&e]})}),n&&r.jsx("div",{style:{position:"sticky",top:"56px",flexGrow:1,height:"calc(100% - 56px)",marginTop:"calc(56px - 100vh)",left:0},children:n})]})}})),Ka=d.memo(function({data:t,onResetPagination:o,onEndReached:a,size:n="m",columns:i,onRowClick:s,onColumnResize:l,filter:c,checkFilterCombination:u,onFilterUpdate:m,sortBy:g,error:f,emptyComponent:h,onSortByUpdate:b,loading:y,cellRenderer:A,hoverRow:k,createFilterField:v,rowClassName:_,className:E,endAdornment:C,AddColumnComponent:B}){const x=g?g[0]:void 0,S=g?g[1]:void 0,[I,D]=d.useState(i),P=d.useRef(null),T=d.useRef(0);d.useEffect(()=>{D(i)},[i]);const[V,re]=Fo(),R=d.useCallback(M=>{D(I.map(Y=>Y.key===M.column.key?M.column:Y))},[I]),$=d.useCallback(M=>{D(I.map(Y=>Y.key===M.column.key?M.column:Y)),l&&l(M)},[I,l]),G=d.useRef();d.useEffect(()=>{G.current=c},[c]);const z=d.useCallback(()=>{T.current=0,P.current&&P.current.scrollTo(P.current?.scrollLeft,0)},[]),H=d.useCallback(M=>{const Y=x===M&&S==="desc",F=x===M&&S==="asc"?"desc":Y?void 0:"asc",N=Y?void 0:M,le=G.current,xe=F&&N?[N,F]:void 0;le&&u&&!u(le,xe)&&m&&m(void 0),o&&o(),b&&b(xe),z()},[u,S,m,o,b,z,x]);d.useCallback(()=>{T.current=0,b&&b(void 0)},[b]);const J=Math.max((t?.length??0)*gt(n)-re.height,0),ee=d.useCallback(M=>{a&&(t?.length??0)>0&&M>T.current+600&&(T.current=M,a())},[t?.length,a]),ne=d.useCallback(({scrollOffset:M,scrollUpdateWasRequested:Y})=>{!Y&&M>=J-600&&ee(M)},[J,ee]),U=d.useCallback((M,Y)=>{T.current=0;const q=G.current;let F=q?{...q}:{};Y?F[M.key]=Y:delete F[M.key],!u||u(F,x&&S?[x,S]:void 0)||(F=Y?{[M.key]:Y}:{}),m&&m(F)},[u,S,m,x]),X=d.useCallback(()=>y?r.jsx(or,{}):r.jsxs("div",{className:"flex flex-col overflow-auto items-center justify-center p-2 gap-2 h-full",children:[r.jsx(p.AssignmentIcon,{}),h]}),[h,y]),Q=!y&&(t?.length??0)===0,K=f?r.jsxs(p.CenteredView,{maxWidth:"2xl",className:"flex flex-col gap-2",children:[r.jsx(p.Typography,{variant:"h6",children:"Error fetching data from the data source"}),f?.message&&r.jsx(Xs,{text:f.message})]}):Q?X():void 0,Z={data:t,size:n,cellRenderer:A,columns:I,currentSort:S,onRowClick:s,customView:K,onColumnResize:R,onColumnResizeEnd:$,filter:G.current,onColumnSort:H,onFilterUpdate:U,sortByProperty:x,hoverRow:k??!1,createFilterField:v,rowClassName:_,endAdornment:C,AddColumnComponent:B};return r.jsx("div",{ref:V,className:p.cn("h-full w-full",E),children:r.jsx(ar.Provider,{value:Z,children:r.jsx(Zs,{outerRef:P,width:re.width,height:re.height,itemCount:(t?.length??0)+(C?1:0),onScroll:ne,includeAddColumn:!!B,itemSize:gt(n)},n)})})},L);function Zs({outerRef:e,width:t,height:o,itemCount:a,onScroll:n,itemSize:i,includeAddColumn:s}){const l=d.useCallback(({index:c,style:u})=>r.jsx(ar.Consumer,{children:({onRowClick:m,data:g,columns:f,size:h="m",cellRenderer:b,hoverRow:y,rowClassName:A,endAdornment:k})=>{if(k&&c===(g??[]).length)return r.jsx("div",{style:{...u,height:"auto",position:"sticky",bottom:0,zIndex:1},children:k});const v=g&&g[c];return r.jsxs(Ws,{rowData:v,rowIndex:c,onRowClick:m,columns:f,hoverRow:y,rowClassName:A,style:{...u,top:`calc(${u.top}px + 48px)`},size:h,children:[f.map((_,E)=>{const C=v&&v[_.key];return r.jsx(Js,{dataKey:_.key,cellRenderer:b,column:_,columns:f,rowData:v,cellData:C,rowIndex:c,columnIndex:E},`cell_${_.key}`)}),s&&r.jsx("div",{className:"w-20"})]},`row_${c}`)}}),[]);return r.jsx(Un.FixedSizeList,{outerRef:e,innerElementType:Hs,width:t,height:o,overscanCount:4,itemCount:a,onScroll:n,itemSize:i,children:l})}const Xs=({text:e})=>{const t=/https?:\/\/[^\s]+/g,o=e.replace(t,a=>`<a href="${a}" class="underline" target="_blank">Link</a><br/>`);return r.jsx("div",{className:"break-all",dangerouslySetInnerHTML:{__html:o}})},Ra={"==":"==","!=":"!=",">":">","<":"<",">=":">=","<=":"<=",in:"In","not-in":"Not in","array-contains":"Contains","array-contains-any":"Contains Any"},Kr=["array-contains-any","in","not-in"];function Ks({name:e,value:t,setValue:o,isArray:a,path:n,title:i,previewProperties:s,setHidden:l}){const c=a?["array-contains"]:["==","!=",">","<",">=","<="];a?c.push("array-contains-any"):c.push("in","not-in");const[u,m]=t||[c[0],void 0],[g,f]=d.useState(u),[h,b]=d.useState(m),y=h?Array.isArray(h)?h.map(I=>I?.isEntityReference&&I?.isEntityReference()?I.id:null).filter(Boolean):[h.id]:[];function A(I,D){const P=Kr.includes(g),T=Kr.includes(I);let V=D;P!==T&&(V=T?V?.isEntityReference&&V?.isEntityReference()?[V]:[]:void 0),f(I),b(V);const re=V!==null&&Array.isArray(V)?V.length>0:V!==void 0;o(I&&re?[I,V]:void 0)}const k=pe(),v=d.useMemo(()=>n?k.getCollection(n):void 0,[n]),_=I=>{A(g,je(I))},E=I=>{A(g,I.map(D=>je(D)))},C=Kr.includes(g),B=mt({multiselect:C,path:n,collection:v,onSingleEntitySelected:_,onMultipleEntitiesSelected:E,selectedEntityIds:y,onClose:()=>{l(!1)}}),x=()=>{l(!0),B.open()},S=I=>r.jsx(Oe,{disabled:!n,previewProperties:s,size:"medium",onClick:x,reference:I,hover:!0,allowEntityNavigation:!1});return r.jsxs("div",{className:"flex w-[440px] flex-row",children:[r.jsx("div",{className:"w-[140px]",children:r.jsx(p.Select,{value:g,onValueChange:I=>{A(I,h)},renderValue:I=>Ra[I],children:c.map(I=>r.jsx(p.SelectItem,{value:I,children:Ra[I]},I))})}),r.jsxs("div",{className:"flex-grow ml-2 h-full gap-2 flex flex-col",children:[h&&Array.isArray(h)&&r.jsx("div",{children:h.map((I,D)=>S(I))}),h&&!Array.isArray(h)&&r.jsx("div",{children:S(h)}),(!h||Array.isArray(h)&&h.length===0)&&r.jsx(p.Button,{onClick:x,variant:"outlined",size:"large",className:"h-full w-full",children:C?"Select references":"Select reference"}),!a&&r.jsxs(p.Label,{className:"border cursor-pointer rounded-md p-2 flex items-center gap-2 [&:has(:checked)]:bg-gray-100 dark:[&:has(:checked)]:bg-gray-800",htmlFor:"null-filter",children:[r.jsx(p.Checkbox,{id:"null-filter",checked:h===null,size:"small",onCheckedChange:I=>{h!==null?A(g,null):A(g,void 0)}}),"Filter for null values"]})]})]})}const en={"==":"==","!=":"!=",">":">","<":"<",">=":">=","<=":"<=",in:"In","not-in":"Not in","array-contains":"Contains","array-contains-any":"Any"},Rr=["array-contains-any","in","not-in"];function Rs({name:e,value:t,setValue:o,dataType:a,isArray:n,enumValues:i,title:s}){const l=n?["array-contains"]:["==","!=",">","<",">=","<="];i&&(n?l.push("array-contains-any"):l.push("in","not-in"));const[c,u]=t||[l[0],void 0],[m,g]=d.useState(c),[f,h]=d.useState(u);function b(A,k){let v=k;const _=Rr.includes(m),E=Rr.includes(A);_!==E&&(v=E?typeof k=="string"||typeof k=="number"?[k]:[]:void 0),typeof v=="number"&&isNaN(v)&&(v=void 0),g(A),h(v);const C=v!==null&&Array.isArray(v)?v.length>0:v!==void 0;o(A&&C?[A,v]:void 0)}const y=Rr.includes(m);return r.jsxs("div",{className:"flex w-[440px]",children:[r.jsx("div",{className:"w-[80px]",children:r.jsx(p.Select,{value:m,position:"item-aligned",onValueChange:A=>{b(A,f)},renderValue:A=>en[A],children:l.map(A=>r.jsx(p.SelectItem,{value:A,children:en[A]},A))})}),r.jsxs("div",{className:"flex-grow ml-2 flex flex-col gap-2",children:[!i&&r.jsx(p.TextField,{type:a==="number"?"number":void 0,value:f!==void 0&&f!=null?String(f):"",onChange:A=>{const k=a==="number"?parseFloat(A.target.value):A.target.value;b(m,k)},endAdornment:f&&r.jsx(p.IconButton,{onClick:A=>b(m,void 0),children:r.jsx(p.ClearIcon,{})})}),i&&r.jsx(p.Select,{position:"item-aligned",value:f!==void 0?Array.isArray(f)?f.map(A=>String(A)):String(f):n?[]:"",onValueChange:A=>{A!==""&&b(m,a==="number"?parseInt(A):A)},multiple:y,endAdornment:f&&r.jsx(p.IconButton,{className:"absolute right-2 top-3",onClick:A=>b(m,void 0),children:r.jsx(p.ClearIcon,{})}),renderValue:A=>A===null?"Filter for null values":r.jsx(Ie,{enumKey:A,enumValues:i,size:"small"},`select_value_${e}_${A}`),children:i.map(A=>r.jsx(p.SelectItem,{value:String(A.id),children:r.jsx(Ie,{enumKey:String(A.id),enumValues:i,size:"small"})},`select_value_${e}_${A.id}`))}),!n&&r.jsxs(p.Label,{className:"border cursor-pointer rounded-md p-2 flex items-center gap-2 [&:has(:checked)]:bg-gray-100 dark:[&:has(:checked)]:bg-gray-800",htmlFor:"null-filter",children:[r.jsx(p.Checkbox,{id:"null-filter",checked:f===null,size:"small",onCheckedChange:A=>{f!==null?b(m,null):b(m,void 0)}}),"Filter for null values"]})]})]})}function el({name:e,title:t,value:o,setValue:a}){function n(l){a(l!==void 0?["==",l]:void 0)}const i=o&&o[1],s=!!o;return r.jsx("div",{className:"w-[300px]",children:r.jsx(p.BooleanSwitchWithLabel,{value:i,allowIndeterminate:!0,onValueChange:l=>n(l===null?void 0:l),label:s?i?`${t} is true`:`${t} is false`:"No filter"})})}const tn={"==":"==","!=":"!=",">":">","<":"<",">=":">=","<=":"<=","not-in":"not in",in:"in","array-contains":"Contains","array-contains-any":"Any"},rn=["array-contains-any","in"];function tl({name:e,isArray:t,mode:o,value:a,setValue:n,title:i}){const{locale:s}=oe(),l=t?["array-contains"]:["==","!=",">","<",">=","<="],[c,u]=a||[l[0],void 0],[m,g]=d.useState(c),[f,h]=d.useState(u);function b(y,A){let k=A;const v=rn.includes(m),_=rn.includes(y);v!==_&&(k=_?A?[A]:[]:""),g(y),h(k===null?void 0:k);const E=k!==null&&Array.isArray(k)?k.length>0:k!==void 0;n(y&&E?[y,k]:void 0)}return r.jsxs("div",{className:"flex w-[440px]",children:[r.jsx("div",{className:"w-[80px]",children:r.jsx(p.Select,{value:m,onValueChange:y=>{b(y,f)},renderValue:y=>tn[y],children:l.map(y=>r.jsx(p.SelectItem,{value:y,children:tn[y]},y))})}),r.jsxs("div",{className:"flex-grow ml-2 flex flex-col gap-2",children:[r.jsx(p.DateTimeField,{mode:o,size:"medium",locale:s,value:f??void 0,onChange:y=>{b(m,y===null?void 0:y)},clearable:!0}),r.jsxs(p.Label,{className:"border cursor-pointer rounded-md p-2 flex items-center gap-2 [&:has(:checked)]:bg-gray-100 dark:[&:has(:checked)]:bg-gray-800",htmlFor:"null-filter",children:[r.jsx(p.Checkbox,{id:"null-filter",checked:f===null,size:"small",onCheckedChange:y=>{f!==null?b(m,null):b(m,void 0)}}),"Filter for null values"]})]})]})}const on=d.memo(function({onValueChange:t,cellRenderer:o,onEntityClick:a,onColumnResize:n,hoverRow:i=!0,size:s,inlineEditing:l=!1,tableController:{data:c,dataLoading:u,noMoreToLoad:m,dataLoadingError:g,filterValues:f,setFilterValues:h,sortBy:b,setSortBy:y,setSearchString:A,clearFilter:k,itemCount:v,setItemCount:_,pageSize:E=50,paginationEnabled:C,checkFilterCombination:B,setPopupCell:x},filterable:S=!0,emptyComponent:I,columns:D,forceFilter:P,highlightedRow:T,endAdornment:V,AddColumnComponent:re}){const R=d.useRef(null),[$,G]=d.useState(void 0),z=()=>{!C||u||m||v!==void 0&&_?.(v+E)},H=d.useCallback(()=>{_?.(E)},[E]),J=d.useCallback(({rowData:X})=>{if(!l)return a&&a(X)},[a,l]);p.useOutsideAlerter(R,()=>{$&&ne()},!!$),d.useEffect(()=>{const X=Q=>{Q.keyCode===27&&ne()};return document.addEventListener("keydown",X,!1),()=>{document.removeEventListener("keydown",X,!1)}});const ee=d.useCallback(X=>{G(X)},[]),ne=d.useCallback(()=>{G(void 0)},[]),U=d.useCallback(X=>{h?.({...X,...P})},[P]);return r.jsx($a.Provider,{value:{setPopupCell:x,select:ee,onValueChange:t,size:s??"m",selectedCell:$},children:r.jsx("div",{className:"h-full w-full flex flex-col bg-white dark:bg-gray-950",ref:R,children:r.jsx(Ka,{data:c,columns:D,cellRenderer:o,onRowClick:l?void 0:a?J:void 0,onEndReached:z,onResetPagination:H,error:g,paginationEnabled:C,onColumnResize:n,size:s,loading:u,filter:f,onFilterUpdate:h?U:void 0,sortBy:b,onSortByUpdate:y,hoverRow:i,checkFilterCombination:B,createFilterField:S?rl:void 0,rowClassName:d.useCallback(X=>T?.(X)?"bg-gray-100 bg-opacity-75 dark:bg-gray-800 dark:bg-opacity-75":"",[T]),className:"flex-grow",emptyComponent:I,endAdornment:V,AddColumnComponent:re})})})},L);function rl({id:e,filterValue:t,setFilterValue:o,column:a,hidden:n,setHidden:i}){if(!a.custom)return null;const{resolvedProperty:s}=a.custom,l=s?.dataType==="array",c=l?s.of:s;if(!c)return null;if(c.dataType==="reference")return r.jsx(Ks,{value:t,setValue:o,name:e,isArray:l,path:c.path,title:s?.name,previewProperties:c?.previewProperties,hidden:n,setHidden:i});if(c.dataType==="number"||c.dataType==="string"){const u=c.name,m=c.enumValues?qe(c.enumValues):void 0;return r.jsx(Rs,{value:t,setValue:o,name:e,dataType:c.dataType,isArray:l,enumValues:m,title:u})}else if(c.dataType==="boolean"){const u=c.name;return r.jsx(el,{value:t,setValue:o,name:e,title:u})}else if(c.dataType==="date"){const u=c.name;return r.jsx(tl,{value:t,setValue:o,name:e,mode:c.mode,isArray:l,title:u})}return r.jsx("div",{children:`Currently the filter field ${s.dataType} is not supported`})}const eo=function({className:t,style:o,forceFilter:a,actionsStart:n,actions:i,title:s,tableRowActionsBuilder:l,uniqueFieldValidator:c,getPropertyFor:u,onValueChange:m,selectionController:g,highlightedEntities:f,onEntityClick:h,onColumnResize:b,onSizeChanged:y,textSearchEnabled:A=!1,hoverRow:k=!0,inlineEditing:v=!1,additionalFields:_,displayedColumnIds:E,defaultSize:C,properties:B,tableController:x,filterable:S=!0,sortable:I=!0,endAdornment:D,AddColumnComponent:P,AdditionalHeaderWidget:T,additionalIDHeaderWidget:V,emptyComponent:re,getIdColumnWidth:R,onTextSearchClick:$,textSearchLoading:G,enablePopupIcon:z}){const H=d.useRef(null),J=Qe(),ee=(g?.selectedEntities?.length>0?g?.selectedEntities:f)?.filter(Boolean),ne=Ae(),[U,X]=d.useState(C??"m"),Q=ee?.map(O=>O.id),K=d.useCallback(O=>{y&&y(O),X(O)},[]),Z=d.useCallback(O=>x.setSearchString?.(O),[]),M=d.useMemo(()=>_?_.map(O=>({[O.key]:O})).reduce((O,ie)=>({...O,...ie}),{}):{},[_]),Y=c,q=({column:O,columnIndex:ie,rowData:fe,rowIndex:ue})=>{const he=fe,ze=O.key;let Ve=O.custom?.disabled;const Ge=u?.({propertyKey:ze,entity:he})??O.custom.resolvedProperty;return Ge?.disabled||(Ve=!1),Ge?r.jsx(ae,{children:he?r.jsx(qa,{readonly:!v,align:O.align??"left",propertyKey:ze,property:Ge,value:he?.values?Ye(he.values,ze):void 0,customFieldValidator:Y,columnIndex:ie,width:O.width,height:gt(U),entity:he,disabled:Ve,enablePopupIcon:z,path:he.path},`property_table_cell_${he.id}_${ze}`):Le()}):null},F=d.useCallback(({column:O,rowData:ie,width:fe})=>{const ue=ie,he=M[O.key],ze=he.dependencies?Object.entries(ue.values).filter(([Ue,at])=>he.dependencies.includes(Ue)).reduce((Ue,at)=>({...Ue,...at}),{}):ue,Ve=he.Builder;if(!Ve&&!he.value)throw new Error("When using additional fields you need to provide a Builder or a value");const Ge=Ve?r.jsx(Ve,{entity:ue,context:ne}):r.jsx(r.Fragment,{children:he.value?.({entity:ue,context:ne})});return r.jsx(er,{width:fe,size:U,value:ze,selected:!1,disabled:!0,align:"left",allowScroll:!1,showExpandIcon:!1,disabledTooltip:"This column can't be edited directly",children:r.jsx(ae,{children:Ge})},`additional_table_cell_${ue.id}_${O.key}`)},[U,Q]),N=(()=>{const O=Za({properties:B,sortable:I,forceFilter:a,AdditionalHeaderWidget:T}),ie=_?_.map(fe=>({key:fe.key,align:"left",sortable:!1,title:fe.name,width:fe.width??200})):[];return[...O,...ie]})(),xe=[{key:"id_ewcfedcswdf3",width:R?.()??(J?160:130),title:"ID",resizable:!1,frozen:J,headerAlign:"center",align:"center",AdditionalHeaderWidget:()=>V},...E?E.map(O=>N.find(ie=>ie.key===O.key)).filter(Boolean):N],te=O=>{const ie=O.column,fe=O.columns,ue=ie.key;try{if(O.columnIndex===0)return l?l({entity:O.rowData,size:U,width:ie.width,frozen:ie.frozen}):r.jsx(tr,{entity:O.rowData,width:ie.width,frozen:ie.frozen,isSelected:!1,size:U});if(M[ue])return F(O);if(O.columnIndex<fe.length+1)return q(O);throw Error("Internal: columns not mapped properly")}catch(he){return console.error("Error rendering cell",he),r.jsx(er,{size:U,width:ie.width,saved:!1,value:null,align:"left",fullHeight:!1,disabled:!0,children:r.jsx(ye,{error:he})})}};return r.jsxs("div",{ref:H,style:o,className:p.cn("h-full w-full flex flex-col bg-white dark:bg-gray-950",t),children:[r.jsx(Gs,{onTextSearch:A?Z:void 0,textSearchLoading:G,onTextSearchClick:A?$:void 0,size:U,onSizeChanged:K,title:s,actionsStart:n,actions:i,loading:x.dataLoading}),r.jsx(on,{columns:xe,size:U,inlineEditing:v,cellRenderer:te,onEntityClick:h,highlightedRow:d.useCallback(O=>Q?.includes(O.id)??!1,[Q]),tableController:x,onValueChange:m,onColumnResize:b,hoverRow:k,filterable:S,emptyComponent:re,endAdornment:D,AddColumnComponent:P})]})};function ol({data:e,entitiesDisplayedFirst:t}){if(!t)return e;const o=new Set(t.map(a=>a.id));return[...t,...e.filter(a=>!o.has(a.id))]}function an(e,t,o=5e3){const[a,n]=d.useState(e),i=d.useRef(a.length??0),s=d.useRef(!1),l=d.useRef(t),c=!L(l.current,t),u=e.length>=i.current||c;return d.useEffect(()=>{const m=()=>{L(a,e)||(l.current=t,i.current=e.length,n(e)),s.current=!1};s.current=!0;let g;return u?m():g=setTimeout(m,o),()=>{clearTimeout(g),s.current&&u&&m()}},[e,o,t,u]),u?e:a}const al=50;function to({fullPath:e,collection:t,entitiesDisplayedFirst:o,lastDeleteTimestamp:a,forceFilter:n}){const{initialFilter:i,initialSort:s,forceFilter:l}=t,[c,u]=d.useState(void 0),m=pe(),g=Me(t),f=d.useMemo(()=>m.resolveAliasesFrom(e),[e,m.resolveAliasesFrom]),h=n??l,b=t.pagination===void 0||!!t.pagination,y=typeof t.pagination=="number"?t.pagination:al,[A,k]=d.useState(),[v,_]=d.useState(b?y:void 0),E=d.useMemo(()=>{if(s&&h&&!J(h,s)){console.warn("Initial sort is not compatible with the force filter. Ignoring initial sort");return}return s},[s,h]);d.useEffect(()=>{L(h,C)||B(h)},[h]);const[C,B]=d.useState(h??i??void 0),[x,S]=d.useState(E),I=x?x[0]:void 0,D=x?x[1]:void 0,P=Ae(),[T,V]=d.useState([]),[re,R]=d.useState(!1),[$,G]=d.useState(),[z,H]=d.useState(!1),J=d.useCallback((Q,K)=>g.isFilterCombinationValid?g.isFilterCombinationValid({path:f,collection:t,filterValues:Q,sortBy:K}):!0,[]),ee=d.useCallback(()=>B(h??void 0),[h]),ne=d.useCallback(Q=>{if(h){console.warn("Filter is not compatible with the force filter. Ignoring filter");return}Q&&Object.keys(Q).length===0?B(void 0):B(Q)},[h]);d.useEffect(()=>{R(!0);const Q=async Z=>{if(t.callbacks?.onFetch)try{Z=await Promise.all(Z.map(M=>t.callbacks.onFetch({collection:t,path:f,entity:M,context:P})))}catch(M){console.error(M)}R(!1),G(void 0),V(Z.map(M=>({...M}))),H(!v||Z.length<v)},K=Z=>{console.error("ERROR",Z),R(!1),V([]),G(Z)};return g.listenCollection?g.listenCollection({path:f,collection:t,onUpdate:Q,onError:K,searchString:A,filter:C,limit:v,startAfter:void 0,orderBy:I,order:D}):(g.fetchCollection({path:f,collection:t,searchString:A,filter:C,limit:v,startAfter:void 0,orderBy:I,order:D}).then(Q).catch(K),()=>{})},[f,v,D,I,C,A]);const U=ol({data:T,entitiesDisplayedFirst:o});return{data:an(U,{filterValues:C,sortBy:x,searchString:A,lastDeleteTimestamp:a}),dataLoading:re,noMoreToLoad:z,dataLoadingError:$,filterValues:C,setFilterValues:ne,sortBy:x,setSortBy:S,searchString:A,setSearchString:k,clearFilter:ee,itemCount:v,setItemCount:_,paginationEnabled:b,pageSize:y,checkFilterCombination:J,popupCell:c,setPopupCell:u}}function ro(e){const[t,o]=d.useState([]),a=d.useCallback(i=>{let s;t.map(l=>l.id).includes(i.id)?(e?.(i,!1),s=t.filter(l=>l.id!==i.id)):(e?.(i,!0),s=[...t,i]),o(s)},[t]),n=d.useCallback(i=>t.map(s=>s.id).includes(i.id),[t]);return{selectedEntities:t,setSelectedEntities:o,isEntitySelected:n,toggleEntitySelection:a}}function oo({collection:e,fullPath:t,parentCollectionIds:o}){const a=Ae(),n=oe(),[i,s]=d.useState(!1),[l,c]=d.useState(!1);let u,m=!!e.textSearchEnabled;return n?.plugins&&(u=n.plugins?.find(f=>!!f.collectionView?.onTextSearchClick)?()=>{s(!0),Promise.all(n.plugins?.map(f=>f.collectionView?.onTextSearchClick?f.collectionView.onTextSearchClick({context:a,path:t,collection:e,parentCollectionIds:o}):Promise.resolve(!0))).then(f=>{f.every(Boolean)&&c(!0)}).finally(()=>s(!1))}:void 0,n.plugins?.forEach(f=>{m||f.collectionView?.showTextSearchBar&&(m=f.collectionView.showTextSearchBar({context:a,path:t,collection:e,parentCollectionIds:o}))})),{textSearchLoading:i,textSearchInitialised:l,onTextSearchClick:u,textSearchEnabled:m}}function nn({onSingleEntitySelected:e,onMultipleEntitiesSelected:t,multiselect:o,collection:a,path:n,selectedEntityIds:i,description:s,forceFilter:l,maxSelection:c}){const u=dr(),m=Je(),g=pe(),f=ut(),h=oe(),b=g.resolveAliasesFrom(n),y=Me(a),[A,k]=d.useState([]),v=$=>{let G;const z=_.selectedEntities;if(f.onAnalyticsEvent?.("reference_selection_toggle",{path:b,entityId:$.id}),z){if(z.map(H=>H.id).indexOf($.id)>-1)G=z.filter(H=>H.id!==$.id);else{if(c&&z.length>=c)return;G=[...z,$]}_.setSelectedEntities(G),t&&t(G)}},_=ro(v);d.useEffect(()=>{let $=!1;const G=i?.map(z=>z?.toString()).filter(Boolean);return G&&a?Promise.all(G.map(z=>y.fetchEntity({path:b,entityId:z,collection:a}))).then(z=>{if(!$){const H=z.filter(J=>J!==void 0);_.setSelectedEntities(H),k(H)}}):(_.setSelectedEntities([]),k([])),()=>{$=!0}},[y,b,i,a,_.setSelectedEntities]);const E=()=>{f.onAnalyticsEvent?.("reference_selection_clear",{path:b}),_.setSelectedEntities([]),!o&&e?e(null):t&&t([])},C=$=>{!o&&e?(f.onAnalyticsEvent?.("reference_selected_single",{path:b,entityId:$.id}),e($),u.close(!1)):v($)},B=()=>{f.onAnalyticsEvent?.("reference_selection_new_entity",{path:b}),m.open({path:b,collection:a,updateUrl:!0,onUpdate:({entity:$})=>{k([$,...A]),C($)},closeOnSave:!0})},x=({entity:$,size:G,width:z,frozen:H})=>{const J=_.selectedEntities,ee=J&&J.map(ne=>ne.id).indexOf($.id)>-1;return r.jsx(tr,{width:z,frozen:H,entity:$,size:G,isSelected:ee,selectionEnabled:o,hideId:a?.hideIdFromCollection,fullPath:b,selectionController:_})},S=d.useCallback($=>{$.stopPropagation(),u.close(!1)},[u]);if(!a)return r.jsx(ye,{error:"Could not find collection with id "+a});const I=d.useMemo(()=>Ne({collection:a,path:b,values:{},fields:h.propertyConfigs}),[a,h.propertyConfigs,b]),D=Xr(I,!1),P=to({fullPath:b,collection:a,entitiesDisplayedFirst:A,forceFilter:l}),{textSearchLoading:T,textSearchInitialised:V,onTextSearchClick:re,textSearchEnabled:R}=oo({collection:a,fullPath:b});return r.jsxs("div",{className:"flex flex-col h-full",children:[r.jsx("div",{className:"flex-grow",children:A&&r.jsx(eo,{textSearchLoading:T,onTextSearchClick:V?void 0:re,textSearchEnabled:R,displayedColumnIds:D,onEntityClick:C,tableController:P,enablePopupIcon:!1,tableRowActionsBuilder:x,title:r.jsx(p.Typography,{variant:"subtitle2",children:a.singularName?`Select ${a.singularName}`:`Select from ${a.name}`}),defaultSize:a.defaultSize,properties:I.properties,forceFilter:l,inlineEditing:!1,selectionController:_,actions:r.jsx(nl,{collection:a,path:b,onNewClick:B,onClear:E})})}),r.jsxs(p.DialogActions,{translucent:!1,children:[s&&r.jsx(p.Typography,{variant:"body2",className:"flex-grow text-left",children:s}),r.jsx(p.Button,{onClick:S,color:"primary",variant:"filled",children:"Done"})]})]})}function nl({collection:e,path:t,onClear:o,onNewClick:a}){const n=We(),i=Qe(),s=a?c=>{c.preventDefault(),a()}:void 0,l=ct(e,n,t,null)&&s&&(i?r.jsxs(p.Button,{onClick:s,startIcon:r.jsx(p.AddIcon,{}),variant:"outlined",color:"primary",children:["Add ",e.singularName??e.name]}):r.jsx(p.Button,{onClick:s,variant:"outlined",color:"primary",children:r.jsx(p.AddIcon,{})}));return r.jsxs(r.Fragment,{children:[r.jsx(p.Button,{onClick:o,variant:"text",color:"primary",children:"Clear"}),l]})}function St(e){return Array.isArray(e)?e:e?[e]:[]}function ao({children:e,group:t}){const o=pt();return r.jsx(p.ExpandablePanel,{invisible:!0,titleClassName:"font-medium text-sm text-gray-600 dark:text-gray-400",className:"py-4",initiallyExpanded:!(o?.collapsedGroups??[]).includes(t??"ungrouped"),onExpandedChange:a=>{if(o)if(a)o.setCollapsedGroups((o.collapsedGroups??[]).filter(n=>n!==(t??"ungrouped")));else{const n=(o.collapsedGroups??[]).concat(t??"ungrouped");o.setCollapsedGroups(n)}},title:r.jsx(p.Typography,{color:"secondary",className:"font-medium ml-1",children:t?.toUpperCase()??"Views".toUpperCase()}),children:r.jsx("div",{className:"mb-8",children:e})})}function sn({name:e,description:t,icon:o,actions:a,onClick:n}){return r.jsx(p.Card,{className:p.cn("h-full p-4 cursor-pointer min-h-[230px]"),onClick:()=>{n?.()},children:r.jsxs("div",{className:"flex flex-col items-start h-full",children:[r.jsxs("div",{className:"flex-grow w-full",children:[r.jsxs("div",{className:"h-10 flex items-center w-full justify-between text-gray-300 dark:text-gray-600",children:[o,r.jsx("div",{className:"flex items-center gap-1",onClick:i=>{i.preventDefault(),i.stopPropagation()},children:a})]}),r.jsx(p.Typography,{gutterBottom:!0,variant:"h5",component:"h2",children:e}),t&&r.jsx(p.Typography,{variant:"body2",color:"secondary",component:"div",children:r.jsx(p.Markdown,{source:t,size:"small"})})]}),r.jsx("div",{style:{alignSelf:"flex-end"},children:r.jsx("div",{className:"p-4",children:r.jsx(p.ArrowForwardIcon,{className:"text-primary"})})})]})})}function ln({name:e,url:t,icon:o}){return r.jsx(r.Fragment,{children:r.jsxs(ge.Link,{tabIndex:0,className:p.cn(p.cardMixin,p.cardClickableMixin,p.focusedMixin,"cursor-pointer flex flex-row items-center px-4 py-2 text-inherit dark:text-inherit visited:text-inherit visited:dark:text-inherit hover:text-inherit hover:dark:text-inherit "),to:t,children:[r.jsxs("div",{className:"flex flex-row items-center flex-grow gap-2 ",children:[o,r.jsx(p.Typography,{gutterBottom:!0,variant:"h5",component:"h2",className:"mb-0 ml-4",children:e})]}),r.jsx("div",{className:"p-4",children:r.jsx(p.ArrowForwardIcon,{color:"primary"})})]})})}function cn({path:e,collection:t,view:o,url:a,name:n,description:i,onClick:s,type:l}){const c=pt(),u=r.jsx(Zt,{collectionOrView:t??o}),m=ge.useNavigate(),g=Ae(),f=oe(),h=(c?.favouritePaths??[]).includes(e),b=c?[r.jsx(p.IconButton,{onClick:A=>{A.preventDefault(),A.stopPropagation(),h?c.setFavouritePaths(c.favouritePaths.filter(k=>k!==e)):c.setFavouritePaths([...c.favouritePaths,e])},children:h?r.jsx(p.StarIcon,{size:18,className:"text-secondary"}):r.jsx(p.StarBorderIcon,{size:18,className:"text-gray-400 dark:text-gray-500"})},"favourite")]:[];if(f.plugins&&t){const A={path:e,collection:t,context:g};f.plugins.forEach((k,v)=>b.push(k.homePage?.CollectionActions?r.jsx(k.homePage.CollectionActions,{...A,extraProps:k.homePage.extraProps},`actions_${v}`):null))}const y=r.jsx(r.Fragment,{children:b});return l==="admin"?r.jsx(ln,{icon:u,name:n,url:a}):r.jsx(sn,{icon:u,name:n,description:i,actions:y,onClick:()=>{s?.(),m(a),c&&c.setRecentlyVisitedPaths([e,...(c.recentlyVisitedPaths??[]).filter(A=>A!==e)])}})}function il({entry:e}){const t=ge.useNavigate(),o=pt();if(!o)return null;const a=o.favouritePaths.includes(e.path),n=i=>{i.preventDefault(),i.stopPropagation(),a?o.setFavouritePaths(o.favouritePaths.filter(s=>s!==e.path)):o.setFavouritePaths([...o.favouritePaths,e.path])};return r.jsx(p.Chip,{onClick:()=>t(e.url),icon:a?r.jsx(p.StarIcon,{onClick:n,size:18,className:"text-secondary"}):r.jsx(p.StarBorderIcon,{onClick:n,size:18,className:"text-gray-400 dark:text-gray-500"}),children:e.name},e.path)}function sl({hidden:e}){const t=pe(),o=pt();if(!o)return null;const a=(o?.favouritePaths??[]).map(n=>t.topLevelNavigation?.navigationEntries.find(i=>i.path===n)).filter(Boolean);return r.jsx(p.Collapse,{in:a.length>0,children:r.jsx("div",{className:"flex flex-row flex-wrap gap-2 pb-2 min-h-[32px]",children:a.map(n=>r.jsx(il,{entry:n},n.path))})})}const no={};function ll(){const e=ge.useLocation(),t=d.useRef(null),[o,a]=d.useState(0),[n,i]=d.useState("down"),s=d.useCallback(()=>{!t.current||!e.key||(no[e.key]=t.current.scrollTop,a(t.current.scrollTop),i(t.current.scrollTop>o?"down":"up"))},[t,e.key,o]);return d.useEffect(()=>{const l=t.current;if(l)return l.addEventListener("scroll",s,{passive:!0}),()=>{l&&l.removeEventListener("scroll",s)}},[t,s,e]),d.useEffect(()=>{!t.current||!no[e.key]||t.current.scrollTo({top:no[e.key],behavior:"auto"})},[e]),{containerRef:t,scroll:o,direction:n}}const At=new Po.Search("url");At.addIndex("name"),At.addIndex("description"),At.addIndex("group"),At.addIndex("path");function dn({additionalActions:e,additionalChildrenStart:t,additionalChildrenEnd:o}){const a=Ae(),n=oe(),i=pe();if(!i.topLevelNavigation)throw Error("Navigation not ready in FireCMSHomePage");const{containerRef:s,scroll:l,direction:c}=ll(),{navigationEntries:u,groups:m}=i.topLevelNavigation,[g,f]=d.useState(null),h=g?u.filter(_=>g.includes(_.url)):u;d.useEffect(()=>{At.addDocuments(u)},[u]);const b=d.useCallback(_=>{if(!_||_==="")f(null);else{const E=At.search(_);f(E.map(C=>C.url))}},[]),y=[...m];(h.filter(_=>!_.group).length>0||h.length===0)&&y.push(void 0);let A,k,v;if(n.plugins){const _={context:a};v=r.jsx(r.Fragment,{children:n.plugins.filter(E=>E.homePage?.includeSection).map((E,C)=>{const B=E.homePage.includeSection(_);return r.jsx(ao,{group:B.title,children:B.children},`plugin_section_${E.key}`)})}),A=r.jsx("div",{className:"flex flex-col gap-2",children:n.plugins.filter(E=>E.homePage?.additionalChildrenStart).map((E,C)=>r.jsx("div",{children:E.homePage.additionalChildrenStart},`plugin_children_start_${C}`))}),k=r.jsx("div",{className:"flex flex-col gap-2",children:n.plugins.filter(E=>E.homePage?.additionalChildrenEnd).map((E,C)=>r.jsx("div",{children:E.homePage.additionalChildrenEnd},`plugin_children_start_${C}`))})}return r.jsx("div",{id:"home_page",ref:s,className:"py-2 overflow-auto h-full w-full",children:r.jsxs(p.Container,{maxWidth:"6xl",children:[r.jsxs("div",{className:"w-full sticky py-4 transition-all duration-400 ease-in-out top-0 z-10 flex flex-row gap-4",style:{top:c==="down"?-84:0},children:[r.jsx(p.SearchBar,{onTextSearch:b,placeholder:"Search collections",large:!1,innerClassName:"w-full",className:"w-full flex-grow"}),e]}),r.jsx(sl,{hidden:!!g}),t,A,y.map((_,E)=>{const C=[],B={group:_,context:a};n.plugins&&n.plugins.forEach(S=>{S.homePage?.AdditionalCards&&C.push(...St(S.homePage?.AdditionalCards))});const x=h.filter(S=>S.group===_||!S.group&&_===void 0);return x.length===0&&C.length===0?null:r.jsx(ao,{group:_,children:r.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:[x.map(S=>r.jsx("div",{className:"col-span-1",children:r.jsx(cn,{...S,onClick:()=>{let I;S.type==="collection"?I="home_navigate_to_collection":S.type==="view"?I="home_navigate_to_view":S.type==="admin"?I="home_navigate_to_admin_view":I="unmapped_event",a.analyticsController?.onAnalyticsEvent?.(I,{path:S.path})}})},`nav_${S.group}_${S.name}`)),_?.toLowerCase()!=="admin"&&C&&C.map((S,I)=>r.jsx("div",{children:r.jsx(S,{...B})},`nav_${_}_add_${I}`))]})},`plugin_section_${_}`)}),v,k,o]})})}function pn({collection:e,relativePath:t,parentCollectionIds:o,onNewClick:a,onMultipleDeleteClick:n,selectionEnabled:i,path:s,selectionController:l,tableController:c,collectionEntitiesCount:u}){const m=Ae(),f=oe().plugins??[],h=We(),b=Qe(),y=l.selectedEntities,A=ct(e,h,s,null)&&a&&(b?r.jsxs(p.Button,{id:`add_entity_${s}`,onClick:a,startIcon:r.jsx(p.AddIcon,{}),variant:"filled",color:"primary",children:["Add ",e.singularName??e.name]}):r.jsx(p.Button,{id:`add_entity_${s}`,onClick:a,variant:"filled",color:"primary",children:r.jsx(p.AddIcon,{})})),k=Wt(e,h,s,null);let v;if(i){const C=b?r.jsxs(p.Button,{variant:"text",disabled:!y?.length||!k,startIcon:r.jsx(p.DeleteIcon,{}),onClick:n,color:"primary",className:"lg:w-20",children:["(",y?.length,")"]}):r.jsx(p.IconButton,{color:"primary",disabled:!y?.length||!k,onClick:n,children:r.jsx(p.DeleteIcon,{})});v=r.jsx(p.Tooltip,{title:k?"Delete":"You have selected at least one entity you cannot delete",children:C})}const _={path:s,relativePath:t,parentCollectionIds:o,collection:e,selectionController:l,context:m,tableController:c,collectionEntitiesCount:u},E=St(e.Actions).map((C,B)=>r.jsx(ae,{children:r.jsx(C,{..._})},`actions_${B}`));return f&&f.forEach((C,B)=>{C.collectionView?.CollectionActions&&E.push(...St(C.collectionView?.CollectionActions).map((x,S)=>r.jsx(ae,{children:r.jsx(x,{..._,...C.collectionView?.collectionActionsProps})},`plugin_actions_${B}_${S}`)))}),r.jsxs(r.Fragment,{children:[E,v,A]})}function cl({containerRef:e,innerRef:t,x:o,y:a,onMove:n}){let i=0,s=0;const l=d.useRef(!1),c=b=>{if(b.button!==0||!e.current||b.defaultPrevented||b.innerClicked)return;const{x:y,y:A}=e.current.getBoundingClientRect();i=b.screenX-y,s=b.screenY-A,document.addEventListener("mousemove",f),document.addEventListener("mouseup",g),document.addEventListener("selectstart",m),l.current=!0},u=b=>{b.innerClicked=!0},m=b=>{b.preventDefault(),b.stopPropagation()},g=b=>{document.removeEventListener("mousemove",f),document.removeEventListener("mouseup",g),document.removeEventListener("selectstart",m),b.stopPropagation(),l.current=!1},f=b=>{b.target.localName==="input"||!l.current||(n({x:b.screenX-i,y:b.screenY-s}),b.stopPropagation())},h=()=>{e.current&&(e.current.style.top=`${a}px`,e.current.style.left=`${o}px`)};d.useEffect(()=>{const b=e.current,y=t.current;if(!(!b||!y))return y&&y.addEventListener("mousedown",u),b&&b.addEventListener("mousedown",c),h(),()=>{b&&b.removeEventListener("mousedown",c),y&&y.removeEventListener("mousedown",u)}})}function dl(){const[e,t]=d.useState({width:0,height:0});return d.useLayoutEffect(()=>{function o(){t({width:window.innerWidth,height:window.innerHeight})}return window.addEventListener("resize",o),o(),()=>window.removeEventListener("resize",o)},[]),e}const pl=({onResize:e})=>{const t=d.useRef(0),o=d.useRef(null),a=d.useRef(e);a.current=e;const n=d.useCallback(s=>{t.current&&cancelAnimationFrame(t.current),t.current=requestAnimationFrame(()=>{a.current(s)})},[]),i=d.useCallback(()=>{const s=o.current;s&&s.contentDocument&&s.contentDocument.defaultView&&s.contentDocument.defaultView.addEventListener("resize",n)},[n]);return d.useEffect(()=>{const s=o.current;return()=>{s&&s.contentDocument&&s.contentDocument.defaultView&&s.contentDocument.defaultView.removeEventListener("resize",n)}},[n]),r.jsx("object",{onLoad:i,ref:o,tabIndex:-1,type:"text/html",data:"about:blank",title:"",style:{position:"absolute",top:0,left:0,height:"100%",width:"100%",pointerEvents:"none",zIndex:-1,opacity:0}})};function ul(e){return e.open?r.jsx(ml,{...e}):null}function ml({tableKey:e,entity:t,customFieldValidator:o,propertyKey:a,collection:n,path:i,cellRect:s,open:l,onClose:c,onCellValueChange:u,container:m}){const g=Ae(),f=oe(),[h,b]=d.useState(),[y,A]=d.useState(),k=t?.id,[v,_]=d.useState(t),[E,C]=d.useState(v?.values),B=n?Ne({collection:n,path:i,values:E,entityId:k,fields:f.propertyConfigs}):void 0,x=dl(),S=d.useRef(null),I=d.useRef(null),D=d.useRef(!1),P=d.useCallback(()=>{if(!s)throw Error("getInitialLocation error");return{x:s.left<x.width-s.right?s.x+s.width/2:s.x-s.width/2,y:s.top<x.height-s.bottom?s.y+s.height/2:s.y-s.height/2}},[s,x.height,x.width]),T=d.useCallback(({x:q,y:F})=>{const N=S.current?.getBoundingClientRect();if(!N)throw Error("normalizePosition called before draggableBoundingRect is set");return{x:Math.max(0,Math.min(q,x.width-N.width)),y:Math.max(0,Math.min(F,x.height-N.height))}},[x]),V=d.useCallback(q=>{const F=S.current?.getBoundingClientRect();if(!s||!F)return;const N=q??T(P());(!y||N.x!==y.x||N.y!==y.y)&&A(N)},[s,P,T,y]);cl({containerRef:S,innerRef:I,x:y?.x,y:y?.y,onMove:V}),d.useEffect(()=>{D.current=!1},[a,v]),d.useLayoutEffect(()=>{const q=S.current?.getBoundingClientRect();!s||!q||D.current||(V(),D.current=!0)},[s,V,D.current]),d.useLayoutEffect(()=>{V(y)},[x,s]);const re=d.useMemo(()=>{if(!(!B||!k))return Ua(k,a&&B.properties[a]?{[a]:B.properties[a]}:{},o)},[B,k,a,o]),R=d.useCallback(()=>V(y),[y,V]),$=async q=>(b(null),n&&v&&u&&a?u({value:q[a],propertyKey:a,data:v,setError:b,onValueUpdated:()=>{}}):Promise.resolve());if(!v)return r.jsx(r.Fragment,{});const G=ve.useCreateFormex({initialValues:v?.values??{},validation:q=>re?.validate(q,{abortEarly:!1}).then(()=>({})).catch(F=>{const N={};return F.inner.forEach(le=>{N[le.path]=le.message}),N}),validateOnInitialRender:!0,onSubmit:(q,F)=>{$(q).then(()=>c()).finally(()=>F.setSubmitting(!1))}}),{values:z,isSubmitting:H,setFieldValue:J,handleSubmit:ee}=G;if(d.useEffect(()=>{L(z,E)||C(z)},[z]),!v)return r.jsx(ye,{error:"PopupFormField misconfiguration"});if(!B)return r.jsx(r.Fragment,{});const ne=H,U={collection:B,entityId:k,values:z,path:i,setFieldValue:J,save:$},X=a&&Re(B.properties,a),Q=a&&X?{propertyKey:a,disabled:H||st(X)||!!X.disabled,property:X,includeDescription:!1,underlyingValueHasChanged:!1,context:U,tableMode:!0,partOfArray:!1,partOfBlock:!1,autoFocus:l}:void 0;let K=r.jsx(r.Fragment,{children:r.jsx("div",{className:"w-[560px] max-w-full max-h-[85vh]",children:r.jsxs("form",{onSubmit:ee,noValidate:!0,children:[r.jsx("div",{className:"mb-1 p-4 flex flex-col relative",children:r.jsx("div",{ref:I,className:"cursor-auto",style:{cursor:"auto !important"},children:Q&&r.jsx(ot,{...Q})})}),r.jsx(p.DialogActions,{children:r.jsx(p.Button,{variant:"filled",color:"primary",type:"submit",disabled:ne,children:"Save"})})]})},`popup_form_${e}_${k}_${a}`)});const Z=f.plugins;Z&&Z.forEach(q=>{q.form?.provider&&(K=r.jsx(q.form.provider.Component,{status:"existing",path:i,collection:B,entity:v,context:g,currentEntityId:k,formContext:U,...q.form.provider.props,children:K}))});const M=r.jsxs("div",{className:`text-gray-900 dark:text-white overflow-auto rounded rounded-md bg-white dark:bg-gray-950 ${l?"":"hidden"} cursor-grab max-w-[100vw]`,children:[K,h&&r.jsx(p.Typography,{color:"error",children:h.message})]}),Y=r.jsxs("div",{style:{boxShadow:"0 0 0 2px rgba(128,128,128,0.2)"},className:`inline-block fixed z-20 shadow-outline rounded-md bg-white dark:bg-gray-950 ${l?"visible":"invisible"} cursor-grab overflow-visible`,ref:S,children:[r.jsx(pl,{onResize:R}),r.jsxs("div",{className:"overflow-hidden",children:[M,r.jsx("div",{className:"absolute -top-3.5 -right-3.5 bg-gray-500 rounded-full",style:{width:"32px",height:"32px"},children:r.jsx(p.IconButton,{size:"small",onClick:q=>{q.stopPropagation(),c()},children:r.jsx(p.ClearIcon,{className:"text-white",size:"small"})})})]})]},`draggable_${a}_${k}_${l}`);return r.jsx(Hn.Root,{asChild:!0,container:m,children:r.jsx(ve.Formex,{value:G,children:Y})})}function un({entityOrEntitiesToDelete:e,collection:t,onClose:o,open:a,callbacks:n,onEntityDelete:i,onMultipleEntitiesDelete:s,path:l}){const c=Me(t),u=oe(),m=He(),[g,f]=d.useState(!1),[h,b]=d.useState(),[y,A]=d.useState(),k=Ae();d.useEffect(()=>{if(e){const T=Array.isArray(e)&&e.length===1?e[0]:e;b(T),A(Array.isArray(T))}},[e]);const v=d.useMemo(()=>Ne({collection:t,path:l,fields:u.propertyConfigs}),[t,l]),_=d.useCallback(()=>{o()},[o]),E=d.useCallback(T=>{console.debug("Deleted",T)},[]),C=d.useCallback((T,V)=>{m.open({type:"error",message:"Error deleting: "+V?.message}),console.error("Error deleting entity"),console.error(V)},[v.name]),B=d.useCallback((T,V)=>{m.open({type:"error",message:"Error before deleting: "+V?.message}),console.error(V)},[v.name]),x=d.useCallback((T,V)=>{m.open({type:"error",message:"Error after deleting: "+V?.message}),console.error(V)},[v.name]),S=d.useCallback(T=>ma({dataSource:c,entity:T,collection:v,callbacks:n,onDeleteSuccess:E,onDeleteFailure:C,onPreDeleteHookError:B,onDeleteSuccessHookError:x,context:k}),[c,v,n,E,C,B,x,k]),I=d.useCallback(async()=>{h&&(f(!0),y?Promise.all(h.map(S)).then(T=>{f(!1),s&&h&&s(l,h),T.every(Boolean)?m.open({type:"success",message:`${v.name}: multiple deleted`}):T.some(Boolean)?m.open({type:"warning",message:`${v.name}: Some of the entities have been deleted, but not all`}):m.open({type:"error",message:`${v.name}: Error deleting entities`}),o()}):S(h).then(T=>{f(!1),T&&(i&&h&&i(l,h),m.open({type:"success",message:`${v.singularName??v.name} deleted`}),o())}))},[h,y,S,s,l,o,m,v.name,i]);let D;if(h&&y)D=r.jsx(r.Fragment,{children:"Multiple entities"});else{const T=h;D=T?r.jsx(qr,{entity:T,collection:t,path:l}):r.jsx(r.Fragment,{})}const P=y?r.jsxs(r.Fragment,{children:[r.jsx("b",{children:v.name}),": Confirm multiple delete?"]}):`Would you like to delete this ${v.singularName??v.name}?`;return r.jsxs(p.Dialog,{maxWidth:y?"lg":"2xl","aria-labelledby":"delete-dialog",open:a,onOpenChange:T=>T?void 0:o(),children:[r.jsxs(p.DialogContent,{fullHeight:!0,children:[r.jsx(p.Typography,{variant:"subtitle2",className:"p-4",children:P}),!y&&r.jsx("div",{className:"p-4",children:D})]}),r.jsxs(p.DialogActions,{children:[g&&r.jsx(p.CircularProgress,{size:"small"}),r.jsx(p.Button,{onClick:_,disabled:g,variant:"text",color:"primary",children:"Cancel"}),r.jsx(p.Button,{autoFocus:!0,disabled:g,onClick:I,variant:"filled",color:"primary",children:"Ok"})]})]})}const fl={icon:r.jsx(p.KeyboardTabIcon,{}),name:"Edit",collapsed:!1,onClick({entity:e,collection:t,fullPath:o,context:a,highlightEntity:n,unhighlightEntity:i}){n?.(e),a.analyticsController?.onAnalyticsEvent?.("entity_click",{path:e.path,entityId:e.id});const s=t?.collectionGroup?e.path:o??e.path;return a.sideEntityController.open({entityId:e.id,path:s,collection:t,updateUrl:!0,onClose:()=>i?.(e)}),Promise.resolve(void 0)}},mn={icon:r.jsx(p.FileCopyIcon,{}),name:"Copy",onClick({entity:e,collection:t,context:o,highlightEntity:a,unhighlightEntity:n}){return a?.(e),o.analyticsController?.onAnalyticsEvent?.("copy_entity_click",{path:e.path,entityId:e.id}),o.sideEntityController.open({entityId:e.id,path:e.path,copy:!0,collection:t,updateUrl:!0,onClose:()=>n?.(e)}),Promise.resolve(void 0)}},fn={icon:r.jsx(p.DeleteIcon,{}),name:"Delete",onClick({entity:e,fullPath:t,collection:o,context:a,selectionController:n,onCollectionChange:i,sideEntityController:s}){const{closeDialog:l}=a.dialogsController.open({key:"delete_entity_dialog_"+e.id,Component:({open:c})=>{if(!o||!t)throw new Error("deleteEntityAction: Collection is undefined");return r.jsx(un,{entityOrEntitiesToDelete:e,path:t,collection:o,callbacks:o.callbacks,open:c,onEntityDelete:()=>{a.analyticsController?.onAnalyticsEvent?.("single_entity_deleted",{path:t}),n?.setSelectedEntities(n.selectedEntities.filter(u=>u.id!==e.id)),i?.(),s?.close()},onClose:l})}});return Promise.resolve(void 0)}};function hl({tableController:e,enabled:t}){if(!t)return null;const o=!!e.filterValues&&Object.keys(e.filterValues).length>0,a=!!e.sortBy&&e.sortBy.length>0;if((o||a)&&(e.clearFilter||e.setSortBy)){let n;return o&&a?n="Clear filter and sort":o?n="Clear filter":n="Clear sort",r.jsxs(p.Button,{variant:"outlined",className:"h-fit-content","aria-label":"filter clear",onClick:()=>{e.clearFilter?.(),e.setSortBy?.(void 0)},size:"small",children:[r.jsx(p.FilterListOffIcon,{}),n]})}return null}function gl({collection:e,relativePath:t,parentCollectionIds:o,path:a,selectionController:n,tableController:i,collectionEntitiesCount:s}){const l=Ae(),u=oe().plugins??[],m={path:a,relativePath:t,parentCollectionIds:o,collection:e,selectionController:n,context:l,tableController:i,collectionEntitiesCount:s},g=[r.jsx(hl,{tableController:i,enabled:!e.forceFilter},"clear_filter")];return u&&u.forEach((f,h)=>{f.collectionView?.CollectionActionsStart&&g.push(...St(f.collectionView?.CollectionActionsStart).map((b,y)=>r.jsx(ae,{children:r.jsx(b,{...m,...f.collectionView?.collectionActionsStartProps})},`plugin_actions_${h}_${y}`)))}),r.jsx(r.Fragment,{children:g})}const Al="collectionGroupParent",io=d.memo(function({fullPath:t,parentCollectionIds:o,isSubCollection:a,className:n,...i}){const s=Ae(),l=t??i.path,c=Me(i),u=pe(),m=Je(),g=We(),f=pt(),h=ut(),b=oe(),y=d.useRef(null),A=d.useMemo(()=>{const W=f?.getCollectionConfig(l);return W?De(i,W):i},[i,l,f?.getCollectionConfig]),k=d.useRef(A);d.useEffect(()=>{k.current=A},[A]);const v=ct(A,g,l,null),[_,E]=d.useState(void 0),[C,B]=d.useState(void 0),[x,S]=d.useState(0),[I,D]=d.useState(0),P=d.useCallback(()=>{const W=_;setTimeout(()=>{W===_&&E(void 0)},2400)},[_]),T=d.useCallback(W=>{const se=k.current;return Ir(se,g,l,W??null)?se.inlineEditing===void 0||se.inlineEditing:!1},[g,l]),V=A.selectionEnabled===void 0||A.selectionEnabled,re=!T(),[R,$]=d.useState(!1),G=ro(),z=A.selectionController??G,{selectedEntities:H,isEntitySelected:J,setSelectedEntities:ee}=z;d.useEffect(()=>{B(void 0)},[H]);const ne=to({fullPath:l,collection:A,lastDeleteTimestamp:x}),U=d.useRef(Math.random().toString(36)),X=ne.popupCell,Q=d.useCallback(()=>{ne.setPopupCell?.(void 0)},[ne.setPopupCell]),K=d.useCallback(W=>{console.log("Entity clicked",W);const se=k.current;return E(W),h.onAnalyticsEvent?.("edit_entity_clicked",{path:W.path,entityId:W.id}),m.open({entityId:W.id,path:W.path,collection:se,updateUrl:!0,onClose:P})},[P,m]),Z=d.useCallback(()=>{const W=k.current;h.onAnalyticsEvent?.("new_entity_click",{path:l}),m.open({path:l,collection:W,updateUrl:!0,onClose:P})},[l,m]),M=()=>{h.onAnalyticsEvent?.("multiple_delete_dialog_open",{path:l}),B(H)},Y=(W,se)=>{h.onAnalyticsEvent?.("single_entity_deleted",{path:l}),ee(ce=>ce.filter(de=>de.id!==se.id)),S(Date.now())},q=(W,se)=>{h.onAnalyticsEvent?.("multiple_entities_deleted",{path:l}),ee([]),B(void 0),S(Date.now())};let F;b?.plugins&&(F=b.plugins.find(W=>W.collectionView?.AddColumnComponent)?.collectionView?.AddColumnComponent);const N=d.useCallback((W,se)=>{if(f){const ce=f.getCollectionConfig(W),de=De(ce,se);f.onCollectionModified(W,de)}},[f]),le=d.useCallback(({width:W,key:se})=>{const ce=k.current;if(!Re(ce.properties,se))return;const de=hn(se,W);N(l,de)},[N,l]),xe=d.useCallback(W=>{f&&N(l,{defaultSize:W})},[N,l,f]),te=ct(A,g,l,null),O=d.useCallback(({name:W,value:se,property:ce,entityId:de})=>c.checkUniqueField(l,W,se,de),[l]),ie=({value:W,propertyKey:se,onValueUpdated:ce,setError:de,data:be})=>{const Dt=ve.setIn({...be.values},se,W),Bo={path:l,entityId:be.id,values:Dt,previousValues:be.values,collection:A,status:"existing"};return Mr({...Bo,collection:A,dataSource:c,context:s,onSaveSuccess:()=>{de(void 0),ce()},onSaveFailure:Vn=>{console.error("Save failure"),console.error(Vn),de(Vn)}})},fe=u.resolveAliasesFrom(l),ue=d.useMemo(()=>Ne({collection:A,path:l,fields:b.propertyConfigs}),[A,l]),he=d.useCallback(({propertyKey:W,entity:se})=>{let ce=Re(A.properties,W);return ce||(ce=Re(ue.properties,W)),Pe({propertyKey:W,propertyOrBuilder:ce,path:l,values:se.values,entityId:se.id,fields:b.propertyConfigs})},[A.properties,b.propertyConfigs,l,ue.properties]),ze=Xr(ue,!0),Ve=d.useMemo(()=>{const W=A.subcollections?.map(ce=>({key:Zr(ce),name:ce.name,width:200,dependencies:[],Builder:({entity:de})=>r.jsx(p.Button,{color:"primary",variant:"outlined",startIcon:r.jsx(p.KeyboardTabIcon,{size:"small"}),onClick:be=>{be.stopPropagation(),m.open({path:l,entityId:de.id,selectedSubPath:ce.id??ce.path,collection:A,updateUrl:!0})},children:ce.name})}))??[],se=A.collectionGroup?[{key:Al,name:"Parent entities",width:260,dependencies:[],Builder:({entity:ce})=>{const de=u.getParentReferencesFromPath(ce.path);return r.jsx(r.Fragment,{children:de.map(be=>r.jsx(Oe,{reference:be,size:"tiny"},be.path+"/"+be.id))})}}]:[];return[...A.additionalFields??[],...W,...se]},[A,l,m]),Ge=d.useCallback(()=>{S(Date.now())},[]),Ue=Qe(),at=({entity:W,customEntityActions:se})=>{const ce=W?Wt(A,g,l,W):!0,de=[fl];return te&&de.push(mn),ce&&de.push(fn),se&&de.push(...se),de},Co=()=>{const W=at({}),se=W.filter(be=>be.collapsed!==!1),de=W.filter(be=>be.collapsed===!1).length*(Ue?40:30);return(Ue?80+de:70+de)+(se.length>0?Ue?40:30:0)},Eo=({entity:W,size:se,width:ce,frozen:de})=>{const be=J(W),Dt=at({entity:W,customEntityActions:A.entityActions});return r.jsx(tr,{entity:W,width:ce,frozen:de,isSelected:be,selectionEnabled:V,size:se,highlightEntity:E,unhighlightEntity:P,collection:A,fullPath:l,actions:Dt,hideId:A?.hideIdFromCollection,onCollectionChange:Ge,selectionController:z})},j=r.jsx(p.Popover,{open:R,onOpenChange:$,enabled:!!A.description,trigger:r.jsxs("div",{className:"flex flex-col items-start",children:[r.jsx(p.Typography,{variant:"subtitle1",className:`leading-none truncate max-w-[160px] lg:max-w-[240px] ${A.description?"cursor-pointer":"cursor-auto"}`,onClick:A.description?W=>{$(!0),W.stopPropagation()}:void 0,children:`${A.name}`}),r.jsx(bl,{fullPath:l,collection:A,filter:ne.filterValues,sortBy:ne.sortBy,onCountChange:D})]}),children:A.description&&r.jsx("div",{className:"m-4 text-gray-900 dark:text-white",children:r.jsx(p.Markdown,{source:A.description})})}),Be=d.useCallback(({property:W,propertyKey:se,onHover:ce})=>{const de=k.current;return b.plugins?r.jsx(r.Fragment,{children:b.plugins.filter(be=>be.collectionView?.HeaderAction).map((be,Dt)=>{const Bo=be.collectionView.HeaderAction;return r.jsx(Bo,{onHover:ce,propertyKey:se,property:W,fullPath:l,collection:de,parentCollectionIds:o??[]},`plugin_header_action_${Dt}`)})}):null},[b.plugins,l,o]),Se=F?function(){return typeof F=="function"?r.jsx(F,{fullPath:l,parentCollectionIds:o??[],collection:A}):null}:void 0,{textSearchLoading:$e,textSearchInitialised:Nt,onTextSearchClick:Pt,textSearchEnabled:Tt}=oo({collection:A,fullPath:fe,parentCollectionIds:o});return r.jsxs("div",{className:p.cn("overflow-hidden h-full w-full rounded-md",n),ref:y,children:[r.jsx(eo,{additionalFields:Ve,tableController:ne,enablePopupIcon:!0,displayedColumnIds:ze,onSizeChanged:xe,onEntityClick:K,onColumnResize:le,onValueChange:ie,tableRowActionsBuilder:Eo,uniqueFieldValidator:O,title:j,selectionController:z,highlightedEntities:_?[_]:[],defaultSize:A.defaultSize,properties:ue.properties,getPropertyFor:he,onTextSearchClick:Nt?void 0:Pt,textSearchLoading:$e,textSearchEnabled:Tt,actionsStart:r.jsx(gl,{parentCollectionIds:o??[],collection:A,tableController:ne,path:l,relativePath:A.path,selectionController:z,collectionEntitiesCount:I}),actions:r.jsx(pn,{parentCollectionIds:o??[],collection:A,tableController:ne,onMultipleDeleteClick:M,onNewClick:Z,path:l,relativePath:A.path,selectionController:z,selectionEnabled:V,collectionEntitiesCount:I}),emptyComponent:v&&ne.filterValues===void 0&&ne.sortBy===void 0?r.jsxs("div",{className:"flex flex-col items-center justify-center",children:[r.jsx(p.Typography,{variant:"subtitle2",children:"So empty..."}),r.jsxs(p.Button,{color:"primary",variant:"outlined",onClick:Z,className:"mt-4",children:[r.jsx(p.AddIcon,{}),"Create your first entity"]})]}):r.jsx(p.Typography,{variant:"label",children:"No results with the applied filter/sort"}),hoverRow:re,inlineEditing:T(),AdditionalHeaderWidget:Be,AddColumnComponent:Se,getIdColumnWidth:Co,additionalIDHeaderWidget:r.jsx(yl,{path:l,collection:A})},`collection_table_${l}`),r.jsx(ul,{open:!!X,onClose:Q,cellRect:X?.cellRect,propertyKey:X?.propertyKey,collection:A,entity:X?.entity,tableKey:U.current,customFieldValidator:O,path:fe,onCellValueChange:ie,container:y.current},`popup_form_${X?.propertyKey}_${X?.entity?.id}`),C&&r.jsx(un,{entityOrEntitiesToDelete:C,path:l,collection:A,callbacks:A.callbacks,open:!!C,onEntityDelete:Y,onMultipleEntitiesDelete:q,onClose:()=>B(void 0)})]})},(e,t)=>L(e.fullPath,t.fullPath)&&L(e.parentCollectionIds,t.parentCollectionIds)&&L(e.isSubCollection,t.isSubCollection)&&L(e.className,t.className)&&L(e.properties,t.properties)&&L(e.propertiesOrder,t.propertiesOrder)&&L(e.hideIdFromCollection,t.hideIdFromCollection)&&L(e.inlineEditing,t.inlineEditing)&&L(e.selectionEnabled,t.selectionEnabled)&&L(e.selectionController,t.selectionController)&&L(e.Actions,t.Actions)&&L(e.defaultSize,t.defaultSize)&&L(e.initialFilter,t.initialFilter)&&L(e.initialSort,t.initialSort)&&L(e.textSearchEnabled,t.textSearchEnabled)&&L(e.additionalFields,t.additionalFields)&&L(e.sideDialogWidth,t.sideDialogWidth)&&L(e.forceFilter,t.forceFilter));function bl({fullPath:e,collection:t,filter:o,sortBy:a,onCountChange:n}){const i=Me(t),s=pe(),[l,c]=d.useState(void 0),[u,m]=d.useState(void 0),g=a?a[0]:void 0,f=a?a[1]:void 0,h=d.useMemo(()=>s.resolveAliasesFrom(e),[e,s.resolveAliasesFrom]);return d.useEffect(()=>{i.countEntities&&i.countEntities({path:h,collection:t,filter:o,orderBy:g,order:f}).then(c).catch(m)},[e,i.countEntities,h,t,o,g,f]),d.useEffect(()=>{n&&(m(void 0),n(l??0))},[n,l]),u?null:r.jsx(p.Typography,{className:"w-full text-ellipsis block overflow-hidden whitespace-nowrap max-w-xs text-left w-fit-content",variant:"caption",color:"secondary",children:l!==void 0?`${l} entities`:r.jsx(p.Skeleton,{className:"w-full max-w-[80px] mt-1"})})}function hn(e,t){if(e.includes(".")){const[o,...a]=e.split(".");return{properties:{[o]:hn(a.join("."),t)}}}return{properties:{[e]:{columnWidth:t}}}}function yl({collection:e,path:t}){const[o,a]=d.useState(!1),[n,i]=d.useState(""),s=Je();return r.jsx(p.Tooltip,{title:o?void 0:"Find by ID",children:r.jsx(p.Popover,{open:o,onOpenChange:a,trigger:r.jsx(p.IconButton,{size:"small",children:r.jsx(p.SearchIcon,{size:"small"})}),children:r.jsx("form",{noValidate:!0,onSubmit:l=>{if(l.preventDefault(),!!n)return a(!1),s.open({entityId:n.trim(),path:t,collection:e,updateUrl:!0})},className:"text-gray-900 dark:text-white w-96 max-w-full",children:r.jsxs("div",{className:"flex p-2 w-full gap-4",children:[r.jsx("input",{autoFocus:o,placeholder:"Find entity by ID",onChange:l=>{i(l.target.value)},value:n,className:"flex-grow bg-transparent outline-none p-1"}),r.jsx(p.Button,{variant:"outlined",disabled:!n.trim(),type:"submit",children:"Go"})]})})})})}function wl({propertyConfig:e}){const t="h-8 w-8 p-1 rounded-full shadow text-white",o=typeof e?.property=="object"?Dn(e.property):void 0;return r.jsx("div",{className:t,style:{background:e?.color??o?.color??"#888"},children:e?.Icon?$t(e,"medium"):$t(o,"medium")})}function gn(){return r.jsx("div",{className:"flex w-full h-full",children:r.jsxs("div",{className:"m-auto flex items-center flex-col",children:[r.jsx(p.Typography,{variant:"h4",align:"center",gutterBottom:!0,children:"Page not found"}),r.jsx(p.Typography,{align:"center",gutterBottom:!0,children:"This page does not exist or you may not have access to it"}),r.jsx(p.Button,{variant:"text",component:ge.Link,to:"/",children:"Back to home"})]})})}function vl({open:e,onAccept:t,onCancel:o,title:a,loading:n,body:i}){return r.jsxs(p.Dialog,{open:e,onOpenChange:s=>s?void 0:o(),children:[r.jsxs(p.DialogContent,{children:[r.jsx(p.Typography,{variant:"h6",className:"mb-2",children:a}),i]}),r.jsxs(p.DialogActions,{children:[r.jsx(p.Button,{variant:"text",onClick:o,autoFocus:!0,children:"Cancel"}),r.jsx(p.LoadingButton,{color:"primary",type:"submit",loading:n,onClick:t,children:"Ok"})]})]})}function so({width:e,height:t,className:o,style:a}){return r.jsxs("svg",{width:e??"100%",height:t??"100%",viewBox:"0 0 599 599",version:"1.1",style:a,className:o,xmlns:"http://www.w3.org/2000/svg",children:[r.jsxs("defs",{children:[r.jsxs("radialGradient",{cx:"28.6213569%",cy:"43.1133328%",fx:"28.6213569%",fy:"43.1133328%",r:"71.5003456%",gradientTransform:"translate(0.286214,0.431133),rotate(3.343450),scale(1.000000,0.996175),translate(-0.286214,-0.431133)",id:"radialGradient-1",children:[r.jsx("stop",{stopColor:"#FF5B79",offset:"0%"}),r.jsx("stop",{stopColor:"#FA5574",offset:"28.0930803%"}),r.jsx("stop",{stopColor:"#EC4C51",offset:"44.7242531%"}),r.jsx("stop",{stopColor:"#9543C1",offset:"71.4578165%"}),r.jsx("stop",{stopColor:"#3857B3",offset:"100%"})]}),r.jsxs("radialGradient",{cx:"53.6205516%",cy:"47.2473036%",fx:"53.6205516%",fy:"47.2473036%",r:"50.8229649%",gradientTransform:"translate(0.536206,0.472473),rotate(90.000000),scale(1.000000,1.206631),translate(-0.536206,-0.472473)",id:"radialGradient-2",children:[r.jsx("stop",{stopColor:"#68294F",stopOpacity:"0",offset:"0%"}),r.jsx("stop",{stopColor:"#5E2548",stopOpacity:"0.04641108",offset:"75.3503173%"}),r.jsx("stop",{stopColor:"#0D060B",stopOpacity:"0.437431709",offset:"100%"})]}),r.jsxs("radialGradient",{cx:"53.8605015%",cy:"48.1990423%",fx:"53.8605015%",fy:"48.1990423%",r:"59.9151549%",gradientTransform:"translate(0.538605,0.481990),rotate(180.000000),scale(1.000000,0.925027),translate(-0.538605,-0.481990)",id:"radialGradient-3",children:[r.jsx("stop",{stopColor:"#68294F",stopOpacity:"0",offset:"0%"}),r.jsx("stop",{stopColor:"#5E2548",stopOpacity:"0.04641108",offset:"84.0867343%"}),r.jsx("stop",{stopColor:"#FF0000",stopOpacity:"0.567324765",offset:"100%"})]})]}),r.jsx("g",{id:"Page-1",stroke:"none",strokeWidth:"1",fill:"none",fillRule:"evenodd",children:r.jsxs("g",{id:"firecms_logo",children:[r.jsx("circle",{fill:"url(#radialGradient-1)",cx:"299.5",cy:"299.5",r:"299.5"}),r.jsx("circle",{fill:"url(#radialGradient-2)",cx:"299.5",cy:"299.5",r:"299.5"}),r.jsx("circle",{fill:"url(#radialGradient-3)",cx:"299.5",cy:"299.5",r:"299.5"})]})})]})}const An=function({title:t,endAdornment:o,startAdornment:a,drawerOpen:n,dropDownActions:i,includeDrawer:s,className:l,style:c,logo:u,user:m}){const g=pe(),f=We(),{mode:h,toggleMode:b}=Or(),y=Qe(),A=m??f.user;let k;if(A&&A.photoURL)k=r.jsx(p.Avatar,{src:A.photoURL});else if(A===void 0||f.initialLoading)k=r.jsx("div",{className:"p-1 flex justify-center",children:r.jsx(p.Skeleton,{className:"w-10 h-10 rounded-full"})});else{const v=A?.displayName?A.displayName[0].toUpperCase():A?.email?A.email[0].toUpperCase():"A";k=r.jsx(p.Avatar,{children:v})}return r.jsx("div",{style:c,className:p.cn("pr-2",{"ml-[17rem]":n&&y,"ml-16":s&&!(n&&y),"h-16":!0,"z-10":y,"transition-all":!0,"ease-in":!0,"duration-75":!0,"w-full":!s,"w-[calc(100%-64px)]":s&&!(n&&y),"w-[calc(100%-17rem)]":s&&n&&y,"duration-150":n&&y,fixed:!0},l),children:r.jsxs("div",{className:"flex flex-row gap-2 px-4 h-full items-center",children:[g&&r.jsx("div",{className:"mr-8 hidden lg:block",children:r.jsx(ge.Link,{className:"visited:text-inherit visited:dark:text-inherit",to:g?.basePath??"/",children:r.jsxs("div",{className:"flex flex-row gap-4",children:[!s&&(u?r.jsx("img",{src:u,alt:"Logo",className:p.cn("w-[32px] h-[32px]")}):r.jsx(so,{width:"32px",height:"32px"})),typeof t=="string"?r.jsx(p.Typography,{variant:"subtitle1",noWrap:!0,className:"ml-2 !font-medium",children:t}):t]})})}),a,r.jsx("div",{className:"flex-grow"}),o&&r.jsx(ae,{children:o}),r.jsx(p.IconButton,{color:"inherit","aria-label":"Open drawer",onClick:b,size:"large",children:h==="dark"?r.jsx(p.DarkModeIcon,{}):r.jsx(p.LightModeIcon,{})}),r.jsxs(p.Menu,{trigger:k,children:[A&&r.jsxs("div",{className:"px-4 py-2 mb-2",children:[A.displayName&&r.jsx(p.Typography,{variant:"body1",color:"secondary",children:A.displayName}),A.email&&r.jsx(p.Typography,{variant:"body2",color:"secondary",children:A.email})]}),i,!i&&r.jsxs(p.MenuItem,{onClick:f.signOut,children:[r.jsx(p.LogoutIcon,{}),"Log Out"]})]})]})})},kl=e=>e&&Array.isArray(e)&&e.length>0?e.map((t,o)=>t?{[yr(t)+o]:It()}:{}).reduce((t,o)=>({...t,...o}),{}):{};function lo({droppableId:e,addLabel:t,value:o,disabled:a=!1,buildEntry:n,size:i="medium",onInternalIdAdded:s,includeAddButton:l,newDefaultEntry:c,onValueChange:u}){const m=o&&Array.isArray(o)&&o.length>0,g=d.useRef(kl(o)),[f,h]=d.useState(m?Object.values(g.current):[]);d.useEffect(()=>{if(m&&o&&o.length!==f.length){const v=o.map((_,E)=>{const C=yr(_)+E;if(C in g.current)return g.current[C];{const B=It();return g.current[C]=B,B}});h(v)}},[m,f.length,o]);const b=v=>{if(v.preventDefault(),a)return;const _=It(),E=[...f,_];s&&s(_),h(E),u([...o??[],c])},y=v=>{const _=[...f];_.splice(v,1),h(_),u(o.filter((E,C)=>C!==v))},A=v=>{const _=It(),E=o[v],C=[...f.splice(0,v+1),_,...f.splice(v+1,f.length-v-1)];s&&s(_),h(C),u([...o.slice(0,v+1),E,...o.slice(v+1)])},k=v=>{if(!v.destination)return;const _=v.source.index,E=v.destination.index,C=[...f],B=C[_];C[_]=C[E],C[E]=B,h(C),u(_l(o,_,E))};return r.jsx(nt.DragDropContext,{onDragEnd:k,children:r.jsx(nt.Droppable,{droppableId:e,renderClone:(v,_,E)=>{const C=E.source.index,B=f[C];return r.jsx(co,{provided:v,internalId:B,index:C,size:i,disabled:a,buildEntry:n,remove:y,copy:A,isDragging:_.isDragging})},children:(v,_)=>r.jsxs("div",{...v.droppableProps,ref:v.innerRef,children:[m&&f.map((E,C)=>r.jsx(nt.Draggable,{draggableId:`array_field_${E}`,isDragDisabled:a,index:C,children:(B,x)=>r.jsx(co,{provided:B,internalId:E,index:C,size:i,disabled:a,buildEntry:n,remove:y,copy:A,isDragging:x.isDragging})},`array_field_${E}`)),v.placeholder,l&&r.jsx("div",{className:"py-4 justify-center text-left",children:r.jsx(p.Button,{variant:"text",size:i==="small"?"small":"medium",color:"primary",disabled:a,startIcon:r.jsx(p.AddIcon,{}),onClick:b,children:t??"Add"})})]})})})}function co({provided:e,index:t,internalId:o,size:a,disabled:n,buildEntry:i,remove:s,copy:l,isDragging:c}){const[u,m]=d.useState(!1),g=d.useCallback(()=>m(!0),[]),f=d.useCallback(()=>m(!1),[]);return r.jsx("div",{onMouseEnter:g,onMouseMove:g,onMouseLeave:f,ref:e.innerRef,...e.draggableProps,style:e.draggableProps.style,className:`${c||u?p.fieldBackgroundHoverMixin:""} mb-1 rounded-md opacity-100`,children:r.jsxs("div",{className:"flex items-start",children:[r.jsx("div",{className:"flex-grow w-[calc(100%-48px)] text-text-primary dark:text-text-primary-dark",children:i(t,o)}),r.jsx(bn,{direction:a==="small"?"row":"column",disabled:n,remove:s,index:t,provided:e,copy:l})]})})}function bn({direction:e,disabled:t,remove:o,index:a,provided:n,copy:i}){const[s,l]=d.useState(!1),c=d.useRef(null);return p.useOutsideAlerter(c,()=>l(!1)),r.jsx("div",{className:`pl-2 pt-1 pb-4 flex ${e==="row"?"flex-row-reverse":"flex-col"} items-center`,ref:c,...n.dragHandleProps,children:r.jsxs(p.Tooltip,{delayDuration:400,open:s?!1:void 0,side:e==="column"?"left":void 0,title:"Drag to move. Click for more options",children:[r.jsx(p.IconButton,{size:"small",disabled:t,onClick:()=>l(!0),onDragStart:u=>{l(!1)},className:`cursor-${t?"inherit":"grab"}`,children:r.jsx(p.HandleIcon,{})}),r.jsxs(p.Menu,{portalContainer:c.current,open:s,trigger:r.jsx("div",{}),children:[r.jsxs(p.MenuItem,{dense:!0,onClick:u=>{l(!1),o(a)},children:[r.jsx(p.RemoveIcon,{size:"small"}),"Remove"]}),r.jsxs(p.MenuItem,{dense:!0,onClick:()=>{l(!1),i(a)},children:[r.jsx(p.ContentCopyIcon,{size:"small"}),"Copy"]})]})]})})}function _l(e,t,o){const a=Array.from(e),[n]=a.splice(t,1);return a.splice(o,0,n),a}function It(){return Math.floor(Math.random()*Math.floor(Number.MAX_SAFE_INTEGER))}function xl({name:e,multiselect:t=!1,path:o,disabled:a,value:n,onReferenceSelected:i,onMultipleReferenceSelected:s,previewProperties:l,forceFilter:c,size:u,className:m}){const g=pe(),f=d.useMemo(()=>g.getCollection(o),[o,g.getCollection]),h=d.useCallback(v=>{if(!a&&i){const _=v?je(v):null;i?.({reference:_,entity:v})}},[a,i]),b=d.useCallback(v=>{if(!a&&s){const _=v?v.map(E=>je(E)):null;s({references:_,entities:v})}},[a,i]),y=mt({multiselect:t,path:o,collection:f,onSingleEntitySelected:h,onMultipleEntitiesSelected:b,forceFilter:c});d.useCallback(v=>{v.stopPropagation(),t?b([]):h(null)},[i]);let A;const k=()=>{a||y.open()};return Array.isArray(n)?A=r.jsx("div",{className:"flex flex-col gap-4",children:n.map((v,_)=>r.jsx(Oe,{onClick:k,reference:v,disabled:a,previewProperties:l,size:u},`reference_preview_${_}`))}):n?.isEntityReference&&n?.isEntityReference()&&(A=r.jsx(Oe,{reference:n,onClick:k,disabled:a,previewProperties:l,size:u})),r.jsxs("div",{className:p.cn("text-sm font-medium text-gray-500","min-w-80 flex flex-col gap-4","relative transition-colors duration-200 ease-in rounded font-medium",a?"bg-opacity-50":"hover:bg-opacity-75","text-opacity-50 dark:text-white dark:text-opacity-50",m),children:[A,!n&&r.jsx("div",{className:"justify-center text-left",children:r.jsxs(p.Button,{variant:"outlined",color:"primary",disabled:a,onClick:k,children:["Edit ",e]})})]})}const Cl=220;Jt&&process.env.NODE_ENV!=="production"&&Object.keys(Jt).forEach(e=>{p.iconKeys.includes(e)||console.warn(`The icon ${e} no longer exists. Remove it from \`iconSynonyms\``)});function El({selectedIcon:e="",onIconSelected:t}){const[o,a]=d.useState(null),[n,i]=d.useState(""),s=d.useMemo(()=>p.debounce(c=>{if(!c||c==="")a(null);else{const u=Ht.search(c);a(u.map(m=>m.key))}},Cl),[]);d.useEffect(()=>(s(n),()=>{s.clear()}),[n,s]);const l=o===null?p.coolIconKeys:o;return r.jsxs(r.Fragment,{children:[r.jsx(p.SearchBar,{autoFocus:!0,innerClassName:"w-full sticky top-0 z-10",onTextSearch:c=>i(c??""),placeholder:"Search for more icons…"}),r.jsx("div",{className:"flex max-w-full flex-wrap mt-4",children:l.map(c=>r.jsx(p.Tooltip,{title:c,children:r.jsx(p.IconButton,{shape:"square",toggled:e===c,onClick:t?()=>t(c):void 0,className:"box-content m-1",children:r.jsx(p.Icon,{iconKey:c,size:24})})},c))})]})}function Bl({error:e,children:t}){return t?r.jsx(p.Typography,{variant:"caption",color:e?"error":"secondary",className:"ml-3.5 mt-0.5",children:t}):null}function nr({name:e,addLabel:t,value:o,disabled:a=!1,buildEntry:n,small:i,onInternalIdAdded:s,includeAddButton:l,newDefaultEntry:c=null,setFieldValue:u}){return r.jsx(lo,{droppableId:e,addLabel:t,value:o,disabled:a,buildEntry:n,size:i?"small":"medium",onInternalIdAdded:s,includeAddButton:l,newDefaultEntry:c,onValueChange:m=>u(e,m)})}function Ce({error:e,showError:t,property:o,includeDescription:a=!0,disabled:n}){const i=o.description||o.longDescription;if(!(t&&e)&&(!a||!i))return null;if(t&&e)return r.jsx(p.Typography,{variant:"caption",className:"ml-3.5 text-red-500 dark:text-red-500",children:e});const s=typeof o.disabled=="object"?o.disabled.disabledMessage:void 0;return r.jsxs("div",{className:"flex ml-3.5 mt-1",children:[r.jsx(p.Typography,{variant:"caption",color:n?"disabled":"secondary",className:"flex-grow",children:s||o.description}),o.longDescription&&r.jsx(p.Tooltip,{title:o.longDescription,side:"bottom",children:r.jsx(p.IconButton,{size:"small",className:"self-start",children:r.jsx(p.InfoIcon,{color:"disabled",size:"small"})})})]})}function Ee({icon:e,title:t,small:o,className:a,required:n}){return r.jsxs("span",{className:`inline-flex items-center my-0.5 ${o?"gap-1":"gap-2"} ${a??""}`,children:[e,r.jsx("span",{className:`text-start font-medium text-${o?"base":"sm"} origin-top-left transform ${o?"translate-x-2 scale-75":""}`,children:(t??"")+(n?" *":"")})]})}function po({propertyKey:e,value:t,setValue:o,error:a,showError:n,disabled:i,autoFocus:s,touched:l,property:c,includeDescription:u}){const m=c.enumValues;Te({property:c,value:t,setValue:o});const g=d.useCallback(f=>{f.stopPropagation(),f.preventDefault(),o(null)},[o]);return r.jsxs(r.Fragment,{children:[r.jsx(p.Select,{value:t?t.toString():"",disabled:i,position:"item-aligned",inputClassName:p.cn("w-full"),label:r.jsx(Ee,{icon:_e(c,"small"),required:c.validation?.required,title:c.name,className:"text-text-secondary dark:text-text-secondary-dark ml-3.5"}),endAdornment:c.clearable&&r.jsx(p.IconButton,{onClick:g,children:r.jsx(p.ClearIcon,{})}),onValueChange:f=>{const h=f?c.dataType==="number"?parseFloat(f):f:null;return o(h)},renderValue:f=>r.jsx(Ie,{enumKey:f,enumValues:m,size:"medium"}),children:m&&m.map(f=>r.jsx(p.SelectItem,{value:String(f.id),children:r.jsx(Ie,{enumKey:String(f.id),enumValues:m,size:"medium"})},f.id))}),r.jsx(Ce,{includeDescription:u,showError:n,error:a,disabled:i,property:c})]})}function uo({propertyKey:e,value:t,setValue:o,error:a,showError:n,disabled:i,property:s,includeDescription:l,autoFocus:c}){const u=s.of;if(!u)throw Error("Using wrong component ArrayEnumSelect");if(Array.isArray(u))throw Error("Using array properties instead of single one in `of` in ArrayProperty");if(u.dataType!=="string"&&u.dataType!=="number")throw Error("Field misconfiguration: array field of type string or number");const m=qe(u.enumValues);if(!m)throw console.error(s),Error("Field misconfiguration: array field of type string or number needs to have enumValues");Te({property:s,value:t,setValue:o});const g=!!t&&Array.isArray(t),f=d.useCallback((h,b)=>{const y=h!==void 0?jt(m,h):void 0;return r.jsxs(Ie,{enumKey:h,enumValues:m,size:"medium",children:[y?.label??h,!b&&r.jsx("button",{className:"ml-1 ring-offset-background rounded-full outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",onMouseDown:A=>{A.preventDefault(),A.stopPropagation()},onClick:A=>{A.preventDefault(),A.stopPropagation(),o(t.filter(k=>k!==h))},children:r.jsx(p.CloseIcon,{size:"smallest"})})]},h)},[m,o,t]);return r.jsxs("div",{className:"mt-0.5 ml-0.5 mt-2",children:[r.jsx(p.MultiSelect,{value:g?t.map(h=>h.toString()):[],disabled:i,label:r.jsx(Ee,{icon:_e(s,"small"),required:s.validation?.required,title:s.name,className:"text-text-secondary dark:text-text-secondary-dark ml-3.5"}),renderValue:d.useCallback(h=>f(h,!1),[f]),onMultiValueChange:h=>{let b;return u&&u?.dataType==="number"?b=h?h.map(y=>parseFloat(y)):[]:b=h,o(b)},children:m.map(h=>String(h.id)).map(h=>r.jsx(p.MultiSelectItem,{value:h,children:f(h,!0)},h))}),r.jsx(Ce,{includeDescription:l,showError:n,error:a,disabled:i,property:s})]})}function yn({propertyKey:e,value:t,error:o,showError:a,disabled:n,isSubmitting:i,tableMode:s,property:l,includeDescription:c,setValue:u,setFieldValue:m}){const g=l.of;if(g.dataType!=="reference")throw Error("ArrayOfReferencesField expected a property containing references");const f=l.expanded===void 0?!0:l.expanded,h=t&&Array.isArray(t)?t.map(B=>B.id):[];Te({property:l,value:t,setValue:u});const b=pe(),y=d.useMemo(()=>g.path?b.getCollection(g.path):void 0,[g.path]);if(!y)throw Error(`Couldn't find the corresponding collection for the path: ${g.path}`);const A=d.useCallback(B=>{console.debug("onMultipleEntitiesSelected",B),u(B.map(x=>je(x)))},[u]),k=mt({multiselect:!0,path:g.path,collection:y,onMultipleEntitiesSelected:A,selectedEntityIds:h,forceFilter:g.forceFilter}),v=d.useCallback(B=>{B.preventDefault(),k.open()},[k]),_=d.useCallback((B,x)=>{const S=t&&t.length>B?t[B]:void 0;return S?r.jsx(Oe,{disabled:!g.path,previewProperties:g.previewProperties,size:"medium",onClick:v,hover:!n,reference:S},x):r.jsx("div",{children:"Internal ERROR"})},[g.path,g.previewProperties,t]),E=r.jsx(Ee,{icon:_e(l,"small"),required:l.validation?.required,title:l.name,className:"text-text-secondary dark:text-text-secondary-dark"}),C=r.jsxs(r.Fragment,{children:[!y&&r.jsx(ye,{error:"The specified collection does not exist. Check console"}),y&&r.jsxs("div",{className:"group",children:[r.jsx(nr,{value:t,addLabel:l.name?"Add reference to "+l.name:"Add reference",name:e,buildEntry:_,disabled:i,setFieldValue:m,newDefaultEntry:l.of.defaultValue}),r.jsxs(p.Button,{className:"my-4 justify-center text-left",variant:"outlined",color:"primary",disabled:i,onClick:v,children:["Edit ",l.name]})]})]});return r.jsxs(r.Fragment,{children:[!s&&r.jsx(p.ExpandablePanel,{titleClassName:p.fieldBackgroundMixin,className:p.cn("px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2",p.fieldBackgroundMixin),initiallyExpanded:f,title:E,children:C}),s&&C,r.jsx(Ce,{includeDescription:c,showError:a,error:o,disabled:n,property:l})]})}function wn({name:e,property:t,value:o,entity:a,onRemove:n,disabled:i,size:s,collection:l}){return r.jsxs("div",{className:p.cn(p.paperMixin,"relative m-4 border-box flex items-center justify-center",s==="medium"?"min-w-[220px] min-h-[220px] max-w-[220px]":"min-w-[118px] min-h-[118px] max-w-[118px]"),children:[!i&&r.jsx("div",{className:"absolute rounded-full -top-2 -right-2 z-10 bg-white dark:bg-gray-900",children:r.jsx(p.Tooltip,{title:"Remove",children:r.jsx(p.IconButton,{size:"small",onClick:c=>{c.stopPropagation(),n(o)},children:r.jsx(p.RemoveIcon,{size:"small"})})})}),o&&r.jsx(ae,{children:r.jsx(we,{propertyKey:e,value:o,property:t,size:s})})]})}const Sl="box-border relative pt-[2px] items-center border border-transparent min-h-[254px] outline-none rounded-md duration-200 ease-[cubic-bezier(0.4,0,0.2,1)] focus:border-primary-solid",Il="border-dotted-gray",Fl="hover:bg-field-hover dark:hover:bg-field-hover-dark",Nl="pt-0 border-2 border-solid",Pl="transition-colors duration-200 ease-[cubic-bezier(0,0,0.2,1)] border-2 border-solid border-green-500",Tl="transition-colors duration-200 ease-[cubic-bezier(0,0,0.2,1)] border-2 border-solid border-red-500";function mo({propertyKey:e,value:t,setValue:o,error:a,showError:n,autoFocus:i,tableMode:s,property:l,includeDescription:c,context:u,isSubmitting:m}){if(!u.entityId)throw new Error("StorageUploadFieldBinding: Entity id is null");const g=dt(u.collection),f=st(l)||!!l.disabled||m,{internalValue:h,setInternalValue:b,onFilesAdded:y,storage:A,onFileUploadComplete:k,storagePathBuilder:v,multipleFilesSupported:_}=Oa({entityValues:u.values,entityId:u.entityId,path:u.path,property:l,propertyKey:e,value:t,storageSource:g,disabled:f,onChange:o});Te({property:l,value:t,setValue:o});const E={id:u.entityId,values:u.values,path:u.path};return r.jsxs(r.Fragment,{children:[!s&&r.jsx(Ee,{icon:_e(l,"small"),required:l.validation?.required,title:l.name,className:"text-text-secondary dark:text-text-secondary-dark ml-3.5"}),r.jsx(Ql,{value:h,collection:u.collection,name:e,disabled:f,autoFocus:i,property:l,onChange:o,setInternalValue:b,onFilesAdded:y,entity:E,onFileUploadComplete:k,storagePathBuilder:v,storage:A,multipleFilesSupported:_}),r.jsx(Ce,{includeDescription:c,showError:n,error:a,disabled:f,property:l})]})}function Dl({storage:e,collection:t,disabled:o,isDraggingOver:a,onFilesAdded:n,multipleFilesSupported:i,droppableProvided:s,autoFocus:l,internalValue:c,property:u,entity:m,onClear:g,metadata:f,storagePathBuilder:h,onFileUploadComplete:b,size:y,name:A,helpText:k}){const v=He(),{getRootProps:_,getInputProps:E,isDragActive:C,isDragAccept:B,isDragReject:x}=No.useDropzone({accept:e.acceptedFiles?e.acceptedFiles.map(S=>({[S]:[]})).reduce((S,I)=>({...S,...I}),{}):void 0,disabled:o||a,noDragEventsBubbling:!0,maxSize:e.maxSize,onDrop:n,onDropRejected:(S,I)=>{for(const D of S)for(const P of D.errors)v.open({type:"error",message:`Error uploading file: File is larger than ${e.maxSize} bytes`})}});return r.jsxs("div",{..._(),className:p.cn(p.fieldBackgroundMixin,o?p.fieldBackgroundDisabledMixin:p.fieldBackgroundHoverMixin,Sl,i&&c.length?"":"flex",p.focusedMixin,{[Fl]:!C,[Nl]:C,[Tl]:x,[Pl]:B,[Il]:o}),children:[r.jsxs("div",{...s.droppableProps,ref:s.innerRef,className:p.cn("flex items-center p-1 no-scrollbar",i&&c.length?"overflow-auto":"",i&&c.length?"min-h-[180px]":"min-h-[250px]"),children:[r.jsx("input",{autoFocus:l,...E()}),c.map((S,I)=>{let D;return S.storagePathOrDownloadUrl?D=r.jsx(wn,{collection:t,name:`storage_preview_${S.storagePathOrDownloadUrl}`,property:u,disabled:o,entity:m,value:S.storagePathOrDownloadUrl,onRemove:g,size:S.size}):S.file&&(D=r.jsx(Ya,{entry:S,metadata:f,storagePath:h(S.file),onFileUploadComplete:b,imageSize:y==="medium"?220:118,simple:!1})),r.jsx(nt.Draggable,{draggableId:`array_field_${A}_${S.id}`,index:I,children:(P,T)=>r.jsx("div",{tabIndex:-1,ref:P.innerRef,...P.draggableProps,...P.dragHandleProps,className:p.cn(p.focusedMixin,"rounded-md"),style:{...P.draggableProps.style},children:D})},`array_field_${A}_${S.id}`)}),s.placeholder]}),r.jsx("div",{className:"flex-grow min-h-[38px] box-border m-2 text-center",children:r.jsx(p.Typography,{align:"center",variant:"label",children:k})})]})}function Ql({collection:e,property:t,name:o,value:a,setInternalValue:n,onChange:i,multipleFilesSupported:s,onFileUploadComplete:l,disabled:c,onFilesAdded:u,autoFocus:m,storage:g,entity:f,storagePathBuilder:h}){if(s){const C=t;if(C.of){if(Array.isArray(C.of)||C.of.dataType!=="string")throw Error("Storage field using array must be of data type string")}else throw Error("Storage field using array must be of data type string")}const b=g?.metadata,y=s?"small":"medium",A=d.useCallback((C,B)=>{if(!s)return;const x=[...a],S=x[C];x.splice(C,1),x.splice(B,0,S),n(x);const I=x.filter(D=>!!D.storagePathOrDownloadUrl).map(D=>D.storagePathOrDownloadUrl);i(I)},[s,i,n,a]),k=d.useCallback(C=>{C.destination&&A(C.source.index,C.destination.index)},[A]),v=d.useCallback(C=>{if(s){const B=a.filter(x=>x.storagePathOrDownloadUrl!==C);i(B.filter(x=>!!x.storagePathOrDownloadUrl).map(x=>x.storagePathOrDownloadUrl)),n(B)}else i(null),n([])},[a,s,i]),_=s?"Drag 'n' drop some files here, or click to select files":"Drag 'n' drop a file here, or click to select one",E=s?t.of:t;return r.jsx(nt.DragDropContext,{onDragEnd:k,children:r.jsx(nt.Droppable,{droppableId:`droppable_${o}`,direction:"horizontal",renderClone:(C,B,x)=>{const S=a[x.source.index];return r.jsx("div",{ref:C.innerRef,...C.draggableProps,...C.dragHandleProps,style:C.draggableProps.style,className:"rounded",children:r.jsx(wn,{collection:e,name:`storage_preview_${S.storagePathOrDownloadUrl}`,property:E,disabled:!0,entity:f,value:S.storagePathOrDownloadUrl,onRemove:v,size:S.size})})},children:(C,B)=>r.jsx(Dl,{storage:g,collection:e,disabled:c,isDraggingOver:B.isDraggingOver,droppableProvided:C,onFilesAdded:u,multipleFilesSupported:s,autoFocus:m,internalValue:a,property:E,entity:f,onClear:v,metadata:b,storagePathBuilder:h,onFileUploadComplete:l,size:y,name:o,helpText:_})})})}function bt({context:e,propertyKey:t,value:o,setValue:a,error:n,showError:i,disabled:s,autoFocus:l,property:c,includeDescription:u}){let m,g;c.dataType==="string"&&(m=c.multiline,g=c.url),Te({property:c,value:o,setValue:a});const f=d.useCallback(A=>{A.stopPropagation(),A.preventDefault(),a(null)},[a]),h=A=>{if(y==="number"){const k=A.target.value?parseFloat(A.target.value):void 0;k&&isNaN(k)?a(null):k!=null?a(k):a(null)}else a(A.target.value)},b=!!m,y=c.dataType==="number"?"number":void 0;return r.jsxs(r.Fragment,{children:[r.jsx(p.TextField,{value:o,onChange:h,autoFocus:l,label:r.jsx(Ee,{icon:_e(c,"small"),required:c.validation?.required,title:c.name}),type:y,multiline:b,disabled:s,endAdornment:c.clearable&&r.jsx(p.IconButton,{onClick:f,children:r.jsx(p.ClearIcon,{})}),error:i?n:void 0,inputClassName:n?"text-red-500 dark:text-red-600":""}),r.jsx(Ce,{includeDescription:u,showError:i,error:n,disabled:s,property:c}),g&&r.jsx(p.Collapse,{className:"mt-1 ml-1",in:!!o,children:r.jsx(we,{value:o,property:c,size:"medium"})})]})}const vn=d.forwardRef(function({propertyKey:t,value:o,setValue:a,error:n,showError:i,autoFocus:s,disabled:l,touched:c,property:u,includeDescription:m},g){return Te({property:u,value:o,setValue:a}),r.jsxs(r.Fragment,{children:[r.jsx(p.BooleanSwitchWithLabel,{value:o,onValueChange:f=>a(f),error:i,label:r.jsx(Ee,{icon:_e(u,"small"),required:u.validation?.required,title:u.name}),disabled:l,autoFocus:s,size:"medium"}),r.jsx(Ce,{includeDescription:m,showError:i,error:n,disabled:l,property:u})]})});function kn({propertyKey:e,value:t,setValue:o,autoFocus:a,error:n,showError:i,disabled:s,touched:l,property:c,includeDescription:u}){const{locale:m}=oe(),g=t||null;return Te({property:c,value:t,setValue:o}),r.jsxs(r.Fragment,{children:[r.jsx(p.DateTimeField,{value:g,onChange:f=>o(f??null),size:"medium",mode:c.mode,clearable:c.clearable,locale:m,error:i,label:r.jsx(Ee,{icon:_e(c,"small"),required:c.validation?.required,className:i?"text-red-500 dark:text-red-500":"text-text-secondary dark:text-text-secondary-dark",title:c.name})}),r.jsx(Ce,{includeDescription:u,showError:i,error:n,disabled:s,property:c})]})}function fo({propertyKey:e,value:t,error:o,showError:a,tableMode:n,property:i,includeDescription:s,context:l}){if(!l.entityId)throw new Error("ReadOnlyFieldBinding: Entity id is null");return l.entityId,l.values,l.path,r.jsxs(r.Fragment,{children:[!n&&r.jsx(Ee,{icon:_e(i,"small"),required:i.validation?.required,title:i.name,className:"text-text-secondary dark:text-text-secondary-dark ml-3.5"}),r.jsx("div",{className:p.cn(p.paperMixin,"min-h-14 p-4 md:p-6 overflow-x-scroll no-scrollbar"),children:r.jsx(ae,{children:r.jsx(we,{propertyKey:e,value:t,property:i,size:"medium"})})}),r.jsx(Ce,{includeDescription:s,showError:a,error:o,property:i})]})}function _n(e){return typeof e.property.path!="string"?r.jsx(fo,{...e}):r.jsx(Ml,{...e})}function Ml({value:e,setValue:t,error:o,showError:a,isSubmitting:n,disabled:i,touched:s,autoFocus:l,property:c,includeDescription:u,context:m}){if(!c.path)throw new Error("Property path is required for ReferenceFieldBinding");Te({property:c,value:e,setValue:t});const g=e&&e.isEntityReference&&e.isEntityReference(),f=pe(),h=d.useMemo(()=>c.path?f.getCollection(c.path):void 0,[c.path]);if(!h)throw Error(`Couldn't find the corresponding collection for the path: ${c.path}`);const b=d.useCallback(k=>{t(k?je(k):null)},[t]),y=mt({multiselect:!1,path:c.path,collection:h,onSingleEntitySelected:b,selectedEntityIds:g?[e.id]:void 0,forceFilter:c.forceFilter}),A=d.useCallback(k=>{k.preventDefault(),y.open()},[y]);return r.jsxs(r.Fragment,{children:[r.jsx(Ee,{icon:_e(c,"small"),required:c.validation?.required,title:c.name,className:"text-text-secondary dark:text-text-secondary-dark ml-3.5"}),!h&&r.jsx(ye,{error:"The specified collection does not exist. Check console"}),h&&r.jsxs(r.Fragment,{children:[e&&r.jsx(Oe,{disabled:!c.path,previewProperties:c.previewProperties,hover:!i,size:"medium",onClick:i||n?void 0:A,reference:e}),!e&&r.jsx("div",{className:"justify-center text-left",children:r.jsxs(p.Button,{variant:"outlined",color:"primary",disabled:i||n,onClick:A,children:["Edit ",c.name]})})]}),r.jsx(Ce,{includeDescription:u,showError:a,error:o,disabled:i,property:c})]})}const ot=d.memo(Ol,(e,t)=>{if(e.propertyKey!==t.propertyKey)return!1;const o=ke(e.property)||e.property.fromBuilder,a=ke(t.property)||t.property.fromBuilder;return!((o===a||L(e.property,t.property))&&e.disabled===t.disabled)||ho(t.property),!1});function Ol({propertyKey:e,property:t,context:o,includeDescription:a,underlyingValueHasChanged:n,disabled:i,tableMode:s,partOfArray:l,partOfBlock:c,autoFocus:u}){const m=oe();return r.jsx(ve.Field,{name:e,children:g=>{let f;const h=Pe({propertyKey:e,propertyOrBuilder:t,values:g.form.values,path:o.path,entityId:o.entityId,fields:m.propertyConfigs});if(h===null||vt(h))return r.jsx(r.Fragment,{});if(st(h))f=fo;else if(h.Field)typeof h.Field=="function"&&(f=h.Field);else{const y=Ft(h,m.propertyConfigs);if(!y)throw console.log("INTERNAL: Could not find field config for property",{propertyKey:e,resolvedProperty:h,fields:m.propertyConfigs,propertyConfig:y}),new Error(`INTERNAL: Could not find field config for property ${e}`);f=Pe({propertyOrBuilder:y.property,values:g.form.values,path:o.path,entityId:o.entityId,fields:m.propertyConfigs}).Field}if(!f)return console.warn(`No field component found for property ${e}`),console.warn("Property:",t),r.jsx("div",{children:`Currently the field ${h.dataType} is not supported`});const b={propertyKey:e,property:h,includeDescription:a,underlyingValueHasChanged:n,context:o,disabled:i,tableMode:s,partOfArray:l,partOfBlock:c,autoFocus:u};return r.jsx(zl,{Component:f,componentProps:b,fieldProps:g})}})}function zl({Component:e,componentProps:{propertyKey:t,property:o,includeDescription:a,underlyingValueHasChanged:n,tableMode:i,partOfArray:s,partOfBlock:l,autoFocus:c,context:u,disabled:m},fieldProps:g}){const{plugins:f}=oe(),h=o.customProps,b=g.field.value,y=ve.getIn(g.form.errors,t),A=ve.getIn(g.form.touched,t),k=y&&(g.form.submitCount>0||o.validation?.unique)&&(!Array.isArray(y)||!!y.filter(S=>!!S).length),_=Vl(u.path,u.collection,t,o,e,f)??e,E=g.form.isSubmitting,C=d.useCallback((S,I)=>{g.form.setFieldTouched(t,!0,!1),g.form.setFieldValue(t,S,I)},[]),B=d.useCallback((S,I,D)=>{g.form.setFieldTouched(t,!0,!1),g.form.setFieldValue(S,I,D)},[]),x={propertyKey:t,value:b,setValue:C,setFieldValue:B,error:y,touched:A,showError:k,isSubmitting:E,includeDescription:a??!0,property:o,disabled:m??!1,underlyingValueHasChanged:n??!1,tableMode:i??!1,partOfArray:s??!1,partOfBlock:l??!1,autoFocus:c??!1,customProps:h,context:u};return r.jsxs(ae,{children:[r.jsx(_,{...x}),n&&!E&&r.jsx(p.Typography,{variant:"caption",className:"ml-3.5",children:"This value has been updated elsewhere"})]})}const ho=(e,t)=>{if(t?.some(n=>n.form?.fieldBuilder)||ke(e))return!0;const o=e,a=!!o.Field||"fromBuilder"in o&&o.fromBuilder;return o.dataType==="map"&&o.properties?a||Object.values(o.properties).some(n=>ho(n,t)):o.dataType==="array"&&"resolvedProperties"in o?a||o.resolvedProperties?.some(n=>n&&ho(n,t)):a};function Vl(e,t,o,a,n,i){return d.useRef((()=>{let l=null;return i&&i.forEach(c=>{const u=yo(a);if(u&&c.form?.fieldBuilder){const m={fieldConfigId:u,propertyKey:o,property:a,Field:n,plugin:c,path:e,collection:t},g=c.form?.fieldBuilderEnabled?.(m);(g===void 0||g)&&(l=c.form.fieldBuilder(m)||l)}u||console.warn("INTERNAL: Field id not found for property",a)}),l})()).current}function xn({propertyKey:e,value:t,showError:o,error:a,disabled:n,property:i,setValue:s,partOfBlock:l,tableMode:c,includeDescription:u,underlyingValueHasChanged:m,autoFocus:g,context:f}){const h=i.pickOnlySomeKeys||!1,b=(i.expanded===void 0?!0:i.expanded)||g;if(!i.properties)throw Error(`You need to specify a 'properties' prop (or specify a custom field) in your map property ${e}`);let y;h?t?y=Qo(i.properties,...Object.keys(t).filter(v=>v in i.properties)):y={}:y=i.properties;const A=r.jsx(r.Fragment,{children:r.jsx("div",{className:"py-1 flex flex-col space-y-2",children:Object.entries(y).filter(([v,_])=>!vt(_)).map(([v,_],E)=>{const C={propertyKey:`${e}.${v}`,disabled:n,property:_,includeDescription:u,underlyingValueHasChanged:m,context:f,tableMode:!1,partOfArray:!1,partOfBlock:!1,autoFocus:g&&E===0};return r.jsx("div",{children:r.jsx(ae,{children:r.jsx(ot,{...C})})},`map-${e}-${E}`)})})}),k=r.jsx(Ee,{icon:_e(i,"small"),required:i.validation?.required,title:i.name,className:"text-text-secondary dark:text-text-secondary-dark"});return r.jsxs(ae,{children:[!c&&!l&&r.jsx(p.ExpandablePanel,{initiallyExpanded:b,className:"px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2 bg-slate-50 bg-opacity-50 dark:bg-gray-900",title:k,children:A}),(c||l)&&A,r.jsx(Ce,{includeDescription:u,showError:o,error:a?typeof a=="string"?a:"A property of this map has an error":void 0,disabled:n,property:i})]})}function Cn({propertyKey:e,value:t,showError:o,error:a,disabled:n,property:i,setValue:s,tableMode:l,includeDescription:c,underlyingValueHasChanged:u,autoFocus:m,context:g}){const f=(i.expanded===void 0?!0:i.expanded)||m;if(!i.keyValue)throw Error(`Your property ${e} needs to have the 'keyValue' prop in order to use this field binding`);const h=r.jsx(go,{value:t,setValue:s,disabled:n,fieldName:i.name??e}),b=r.jsx(Ee,{icon:_e(i,"small"),required:i.validation?.required,title:i.name,className:"text-text-secondary dark:text-text-secondary-dark"});return r.jsxs(r.Fragment,{children:[!l&&r.jsx(p.ExpandablePanel,{initiallyExpanded:f,title:b,className:"px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2",children:h}),l&&h,r.jsx(Ce,{includeDescription:c,showError:o,error:a,disabled:n,property:i})]})}function go({value:e,setValue:t,fieldName:o,disabled:a}){const[n,i]=d.useState(Object.keys(e??{}).map(c=>[Ao(),{key:c,dataType:bo(e?.[c])??"string"}]));d.useEffect(()=>{const c=n.map(([h,{key:b}])=>b),u=Object.entries(e??{}).filter(([h,b])=>b!==void 0).map(([h])=>h),m=u.filter(h=>!c.includes(h)),g=c.filter(h=>!u.includes(h)),f=[...n];m.forEach(h=>{f.push([Ao(),{key:h,dataType:bo(e?.[h])??"string"}])}),g.forEach(h=>{const b=f.findIndex(([y,{key:A}])=>A===h);f.splice(b,1)}),i(f)},[e]);const s=d.useRef(e??{}),l=(c,u)=>{if(!c){console.warn("No key selected for data type update");return}i(n.map(m=>m[0]===c?[m[0],{key:m[1].key,dataType:u}]:m)),t({...e??{},[n.find(m=>m[0]===c)?.[1].key??""]:kr(u)})};return r.jsxs("div",{className:"py-1 flex flex-col gap-1",children:[n.map(([c,{key:u,dataType:m}],g)=>{const f=u?e?.[u]:"",h=b=>{if(i(n.map(A=>A[0]===c?[c,{key:b??"",dataType:A[1].dataType}]:A)),typeof e=="object"&&b in e)return;const y={...e??{}};typeof s.current=="object"&&u in s.current?y[u]=void 0:delete y[u],t({...y,[b??""]:f})};return r.jsx(Gl,{rowId:c,fieldKey:u,value:e??{},onDeleteClick:()=>{const b={...e??{}};s.current&&u in s.current?b[u]=void 0:delete b[u],i(n.filter(y=>y[0]!==c)),t({...b})},onFieldKeyChange:h,setValue:t,entryValue:f,dataType:m,disabled:a,updateDataType:l},c)}),r.jsx(p.Button,{variant:"text",size:"small",color:"primary",className:"w-full",disabled:a,startIcon:r.jsx(p.AddIcon,{}),onClick:c=>{c.preventDefault(),t({...e??{},"":null}),i([...n,[Ao(),{key:"",dataType:"string"}]])},children:o?`Add to ${o}`:"Add"})]})}function Gl({rowId:e,fieldKey:t,value:o,onFieldKeyChange:a,onDeleteClick:n,setValue:i,entryValue:s,dataType:l,updateDataType:c,disabled:u}){const{locale:m}=oe();function g(h,b,y){return y==="string"||y==="number"?r.jsx(p.TextField,{placeholder:"value",value:h,type:y==="number"?"number":"text",size:"small",disabled:u||!b,onChange:A=>{if(y==="number"){const k=A.target.value?parseFloat(A.target.value):void 0;k&&isNaN(k)?i({...o,[b]:null}):k!=null?i({...o,[b]:k}):i({...o,[b]:null})}else i({...o,[b]:A.target.value})}},y):y==="date"?r.jsx(p.DateTimeField,{value:h,size:"small",locale:m,disabled:u||!b,onChange:A=>{i({...o,[b]:A})}}):y==="boolean"?r.jsx(p.BooleanSwitchWithLabel,{value:h,size:"small",position:"start",disabled:u||!b,onValueChange:A=>{i({...o,[b]:A})}}):y==="array"?r.jsx("div",{className:p.cn(p.defaultBorderMixin,"ml-2 pl-2 border-l border-solid"),children:r.jsx(lo,{value:h,newDefaultEntry:"",droppableId:e.toString(),addLabel:b?`Add to ${b}`:"Add",size:"small",disabled:u||!b,includeAddButton:!0,onValueChange:A=>{i({...o,[b]:A})},buildEntry:(A,k)=>r.jsx(Yl,{index:A,id:k,value:h[A],disabled:u||!b,setValue:v=>{const _=[...h];_[A]=v,i({...o,[b]:_})}})})}):y==="map"?r.jsx("div",{className:p.cn(p.defaultBorderMixin,"ml-2 pl-2 border-l border-solid"),children:r.jsx(go,{value:h,fieldName:b,setValue:A=>{i({...o,[b]:A})}})}):r.jsx(p.Typography,{variant:"caption",children:`Data type ${y} not supported yet`})}function f(h){c(e,h)}return r.jsxs(r.Fragment,{children:[r.jsxs(p.Typography,{component:"div",className:"font-mono flex flex-row gap-1",children:[r.jsx("div",{className:"w-[200px] max-w-[25%]",children:r.jsx(p.TextField,{value:t,placeholder:"key",disabled:u||s!=null&&s!=="",size:"small",onChange:h=>{a(h.target.value)}})}),r.jsx("div",{className:"flex-grow",children:l!=="map"&&l!=="array"&&g(s,t,l)}),r.jsxs(p.Menu,{trigger:r.jsx(p.IconButton,{size:"small",className:"h-7 w-7",children:r.jsx(p.ArrowDropDownIcon,{})}),children:[r.jsx(p.MenuItem,{dense:!0,onClick:()=>f("string"),children:"string"}),r.jsx(p.MenuItem,{dense:!0,onClick:()=>f("number"),children:"number"}),r.jsx(p.MenuItem,{dense:!0,onClick:()=>f("boolean"),children:"boolean"}),r.jsx(p.MenuItem,{dense:!0,onClick:()=>f("date"),children:"date"}),r.jsx(p.MenuItem,{dense:!0,onClick:()=>f("map"),children:"map"}),r.jsx(p.MenuItem,{dense:!0,onClick:()=>f("array"),children:"array"})]}),r.jsx(p.IconButton,{"aria-label":"delete",size:"small",onClick:n,className:"h-7 w-7",children:r.jsx(p.RemoveIcon,{size:"small"})})]},e.toString()),(l==="map"||l==="array")&&g(s,t,l)]})}function Yl({id:e,index:t,value:o,setValue:a}){const{locale:n}=oe(),[i,s]=d.useState(bo(o)??"string");function l(u){s(u)}function c(u,m){return m==="string"||m==="number"?r.jsx(p.TextField,{value:u,type:m==="number"?"number":"text",size:"small",onChange:g=>{if(m==="number"){const f=g.target.value?parseFloat(g.target.value):void 0;f&&isNaN(f)?a(null):f!=null?a(f):a(null)}else a(g.target.value)}}):m==="date"?r.jsx(p.DateTimeField,{value:u,size:"small",locale:n,onChange:g=>{a(g)}}):m==="boolean"?r.jsx(p.BooleanSwitchWithLabel,{value:u,size:"small",position:"start",onValueChange:g=>{a(g)}}):m==="array"?r.jsx(p.Typography,{variant:"caption",children:"Arrays of arrays are not supported."}):m==="map"?r.jsx("div",{className:p.cn(p.defaultBorderMixin,"ml-2 pl-2 border-l border-solid"),children:r.jsx(go,{value:u,setValue:g=>{a(g)}})}):r.jsx(p.Typography,{variant:"caption",children:`Data type ${m} not supported yet`})}return r.jsxs(r.Fragment,{children:[r.jsxs(p.Typography,{component:"div",className:"font-mono flex min-h-12 flex-row gap-1 items-center",children:[r.jsx("div",{className:"flex-grow",children:i!=="map"&&c(o,i)}),r.jsxs(p.Menu,{trigger:r.jsx(p.IconButton,{size:"small",className:"h-7 w-7",children:r.jsx(p.ArrowDropDownIcon,{})}),children:[r.jsx(p.MenuItem,{dense:!0,onClick:()=>l("string"),children:"string"}),r.jsx(p.MenuItem,{dense:!0,onClick:()=>l("number"),children:"number"}),r.jsx(p.MenuItem,{dense:!0,onClick:()=>l("boolean"),children:"boolean"}),r.jsx(p.MenuItem,{dense:!0,onClick:()=>l("map"),children:"map"}),r.jsx(p.MenuItem,{dense:!0,onClick:()=>l("date"),children:"date"})]})]},e.toString()),i==="map"&&c(o,i)]})}function Ao(){return Math.floor(Math.random()*Math.floor(Number.MAX_SAFE_INTEGER))}function bo(e){if(typeof e=="string"||e===null)return"string";if(typeof e=="number")return"number";if(typeof e=="boolean")return"boolean";if(Array.isArray(e))return"array";if(e instanceof Date)return"date";if(e?.isEntityReference&&e?.isEntityReference())return"reference";if(e instanceof Ar)return"geopoint";if(typeof e=="object")return"map"}function En({propertyKey:e,value:t,error:o,showError:a,isSubmitting:n,setValue:i,setFieldValue:s,tableMode:l,property:c,includeDescription:u,underlyingValueHasChanged:m,context:g,disabled:f}){if(!c.of)throw Error("RepeatFieldBinding misconfiguration. Property `of` not set");if(!c.resolvedProperties||!Array.isArray(c.resolvedProperties))throw Error("RepeatFieldBinding - Internal error: Expected array in 'property.resolvedProperties'");const h=c.expanded===void 0?!0:c.expanded,b=c.of,[y,A]=d.useState();Te({property:c,value:t,setValue:i});const k=(E,C)=>{const B=c.resolvedProperties[E]??b,x={propertyKey:`${e}.${E}`,disabled:f,property:B,includeDescription:u,underlyingValueHasChanged:m,context:g,tableMode:!1,partOfArray:!0,partOfBlock:!1,autoFocus:C===y};return r.jsx(ae,{children:r.jsx(ot,{...x})})},v=r.jsx(nr,{value:t,addLabel:c.name?"Add entry to "+c.name:"Add entry",name:e,setFieldValue:s,buildEntry:k,onInternalIdAdded:A,disabled:n||!!c.disabled,includeAddButton:!c.disabled,newDefaultEntry:c.of.defaultValue}),_=r.jsx(Ee,{icon:_e(c,"small"),required:c.validation?.required,title:c.name,className:"text-text-secondary dark:text-text-secondary-dark"});return r.jsxs(r.Fragment,{children:[!l&&r.jsx(p.ExpandablePanel,{initiallyExpanded:h,className:"px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2",title:_,children:v}),l&&v,r.jsx(Ce,{includeDescription:u,showError:a,error:o,disabled:f,property:c})]})}function Bn({propertyKey:e,value:t,error:o,showError:a,isSubmitting:n,setValue:i,setFieldValue:s,tableMode:l,property:c,includeDescription:u,underlyingValueHasChanged:m,context:g,disabled:f}){if(!c.oneOf)throw Error("ArrayOneOfField misconfiguration. Property `oneOf` not set");const h=c.expanded===void 0?!0:c.expanded;Te({property:c,value:t,setValue:i});const[b,y]=d.useState(),A=d.useCallback((E,C)=>r.jsx(jl,{name:`${e}.${E}`,index:E,value:t[E],typeField:c.oneOf.typeField??wt,valueField:c.oneOf.valueField??Vt,properties:c.oneOf.properties,autoFocus:C===b,context:g},`array_one_of_${E}`),[g,b,c.oneOf,e,t]),k=r.jsx(Ee,{icon:_e(c,"small"),required:c.validation?.required,title:c.name,className:"text-text-secondary dark:text-text-secondary-dark"}),v=Object.keys(c.oneOf.properties)[0],_=r.jsx(nr,{value:t,name:e,addLabel:c.name?"Add entry to "+c.name:"Add entry",buildEntry:A,onInternalIdAdded:y,disabled:n||!!c.disabled,includeAddButton:!c.disabled,setFieldValue:s,newDefaultEntry:{[c.oneOf.typeField??wt]:v,[c.oneOf.valueField??Vt]:Gt(c.oneOf.properties[v])}});return r.jsxs(r.Fragment,{children:[!l&&r.jsx(p.ExpandablePanel,{className:"px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2",initiallyExpanded:h,title:k,children:_}),l&&_,r.jsx(Ce,{includeDescription:u,showError:a,error:o,disabled:f,property:c})]})}function jl({name:e,index:t,value:o,typeField:a,valueField:n,properties:i,autoFocus:s,context:l}){const c=o&&o[a],[u,m]=d.useState(c??void 0),g=ve.useFormex();d.useEffect(()=>{c||k(Object.keys(i)[0])},[]),d.useEffect(()=>{c!==u&&m(c)},[c]);const f=u?i[u]:void 0,h=Object.entries(i).map(([v,_])=>({id:v,label:_.name??v})),b=`${e}.${a}`,y=`${e}.${n}`,A=f?{propertyKey:y,property:f,context:l,autoFocus:s,partOfArray:!1,partOfBlock:!0,tableMode:!1}:void 0,k=v=>{const _=v?i[v]:void 0;m(v),g.setFieldTouched(b,!0),g.setFieldValue(b,v),g.setFieldValue(y,_?Gt(_):null)};return r.jsxs("div",{className:p.cn(p.paperMixin,"bg-transparent p-4 my-4 py-8"),children:[r.jsx(ve.Field,{name:b,children:v=>{const _=v.field.value!==void 0&&v.field.value!==null?v.field.value:"";return r.jsx(r.Fragment,{children:r.jsx(p.Select,{className:"mb-2",placeholder:r.jsx(p.Typography,{variant:"caption",className:"px-4 py-2 font-medium",children:"Type"}),size:"small",position:"item-aligned",value:_,renderValue:E=>r.jsx(Ie,{enumKey:E,enumValues:h,size:"small"}),onValueChange:E=>{k(E)},children:h.map(E=>r.jsx(p.SelectItem,{value:String(E.id),children:r.jsx(Ie,{enumKey:E.id,enumValues:h,size:"small"})},E.id))})})}}),A&&r.jsx(ot,{...A},`form_control_${e}_${u}`)]})}const Ll=new $n;try{Ke.use(Ke.Plugins.AutoResize,{min:100}),Ke.unuse(Ke.Plugins.FontUnderline),Ke.unuse(Ke.Plugins.Clear)}catch{}function Sn({propertyKey:e,value:t,setValue:o,error:a,showError:n,disabled:i,autoFocus:s,touched:l,property:c,tableMode:u,includeDescription:m,context:g}){const[f,h]=d.useState(t),b=d.useRef(t);p.useInjectStyles("MarkdownFieldBinding",Ul);const y=d.useDeferredValue({internalValue:f,value:t});return d.useEffect(()=>{b.current=t,h(t)},[t]),d.useEffect(()=>{y.internalValue!==b.current&&o(y.internalValue)},[y]),r.jsxs(r.Fragment,{children:[!u&&r.jsx(p.Typography,{variant:"caption",className:"flex-grow",children:r.jsx(Ee,{icon:_e(c,"small"),required:c.validation?.required,title:c.name,className:"text-text-secondary dark:text-text-secondary-dark ml-3.5"})}),r.jsx(Ke,{value:f??"",className:p.cn(p.fieldBackgroundMixin,i?p.fieldBackgroundDisabledMixin:p.fieldBackgroundHoverMixin,"text-base"),readOnly:i,renderHTML:A=>Ll.render(A),view:{menu:!0,md:!0,html:!1},onChange:({html:A,text:k})=>{h(k??null)}}),r.jsx(Ce,{includeDescription:m,showError:n,error:a,disabled:i,property:c})]})}const Ul=`
|
|
6
6
|
@font-face {
|
|
7
7
|
font-family: rmel-iconfont;
|
|
8
8
|
src: url(data:application/vnd.ms-fontobject;base64,fBkAAMAYAAABAAIAAAAAAAIABQMAAAAAAAABAJABAAAAAExQAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAB9vj4gAAAAAAAAAAAAAAAAAAAAAAABoAcgBtAGUAbAAtAGkAYwBvAG4AZgBvAG4AdAAAAA4AUgBlAGcAdQBsAGEAcgAAABYAVgBlAHIAcwBpAG8AbgAgADEALgAwAAAAGgByAG0AZQBsAC0AaQBjAG8AbgBmAG8AbgB0AAAAAAAAAQAAAAsAgAADADBHU1VCsP6z7QAAATgAAABCT1MvMj3jT5QAAAF8AAAAVmNtYXBA5I9dAAACPAAAAwhnbHlmMImhbQAABXwAAA9gaGVhZBtQ+k8AAADgAAAANmhoZWEH3gObAAAAvAAAACRobXR4aAAAAAAAAdQAAABobG9jYTX6MgAAAAVEAAAANm1heHABMAB7AAABGAAAACBuYW1lc9ztwgAAFNwAAAKpcG9zdCcpv64AABeIAAABNQABAAADgP+AAFwEAAAAAAAEAAABAAAAAAAAAAAAAAAAAAAAGgABAAAAAQAA4uPbB18PPPUACwQAAAAAANwY2ykAAAAA3BjbKQAA//8EAAMBAAAACAACAAAAAAAAAAEAAAAaAG8ADAAAAAAAAgAAAAoACgAAAP8AAAAAAAAAAQAAAAoAHgAsAAFERkxUAAgABAAAAAAAAAABAAAAAWxpZ2EACAAAAAEAAAABAAQABAAAAAEACAABAAYAAAABAAAAAAABBAABkAAFAAgCiQLMAAAAjwKJAswAAAHrADIBCAAAAgAFAwAAAAAAAAAAAAAAAAAAAAAAAAAAAABQZkVkAEDnbe2iA4D/gABcA4AAgAAAAAEAAAAAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAAAAAUAAAADAAAALAAAAAQAAAHMAAEAAAAAAMYAAwABAAAALAADAAoAAAHMAAQAmgAAABYAEAADAAbnbelB7TztRe1h7XXteO2A7Y3tov//AADnbelB7TvtRO1f7W/td+2A7Yztn///AAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAWABYAFgAYABoAHgAqACwALAAuAAAAAQAEAAUAAwAGAAcACAAJAAoACwAMAA0ADgAPABAAEQASABMAAgAUABUAFgAXABgAGQAAAQYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADAAAAAABPAAAAAAAAAAZAADnbQAA520AAAABAADpQQAA6UEAAAAEAADtOwAA7TsAAAAFAADtPAAA7TwAAAADAADtRAAA7UQAAAAGAADtRQAA7UUAAAAHAADtXwAA7V8AAAAIAADtYAAA7WAAAAAJAADtYQAA7WEAAAAKAADtbwAA7W8AAAALAADtcAAA7XAAAAAMAADtcQAA7XEAAAANAADtcgAA7XIAAAAOAADtcwAA7XMAAAAPAADtdAAA7XQAAAAQAADtdQAA7XUAAAARAADtdwAA7XcAAAASAADteAAA7XgAAAATAADtgAAA7YAAAAACAADtjAAA7YwAAAAUAADtjQAA7Y0AAAAVAADtnwAA7Z8AAAAWAADtoAAA7aAAAAAXAADtoQAA7aEAAAAYAADtogAA7aIAAAAZAAAAAABmAMwBHgGEAbwB/gJmAsgC/gM0A3IDogRABKgE7gUuBXAFygYKBmoGpAbEBugHRgewAAAABQAAAAADVgLWAAsAGAAlADQAQAAAEyEyFhQGByEuATQ2Fz4BNyEeARQGIyEiJgM0NjchHgEUBiMhIiY3PgEzITIeARQOASMhIiYnFhQPAQYmNRE0NhfWAlQSGRkS/awSGRnaARgTAWASGRkS/qASGfQZEgJUEhkZEv2sEhnzARgTAWAMFAsLFAz+oBIZOQgIkgseHgsC1RklGAEBGCUZ8hMYAQEYJRkZ/oUTGAEBGCUZGdkSGQsVFxQMGoYGFgaVDAwRASoRDAwAAAAADAAAAAADqwKrAA8AEwAXABsAHwAjACcAMwA3ADsAPwBDAAABIQ4BBwMeARchPgE3ES4BBTMVIxUzFSMnMxUjFTMVKwI1MzUjNTMBISImNDYzITIWFAY3IzUzNSM1MxcjNTM1IzUzA1X9ViQwAQEBMSQCqiQxAQEx/lxWVlZWgFZWVlYqVlZWVgFV/wASGBgSAQASGBgZVlZWVoBWVlZWAqsBMST+ViQxAQExJAGqJDF/VipW1lYqVlYqVv6AGCQZGSQYqlYqVtZWKlYAAwAAAAADKwMAAA8AHwAzAAAlHgEXIT4BNxEuASchDgEHMyEyFhcRDgEHIS4BJxE+ASUnJisBIg8BIyIGFBYzITI2NCYjAQABMCQBViQwAQEwJP6qJDABgAEAExcBARcT/wATFwEBFwEoHgsStBILHmsTFxcTAgARGRkRVSQwAQEwJAGrJDABATAkFxT+qxEZAQEZEQFVFBfVHg0NHhcnFxcnFwADAAAAAAOrAtkAFgAtAD4AAAEVBg8BBiIvASY0PwEnJjQ/ATYyHwEWBTc2NC8BJiIPAQYHFRYfARYyPwE2NCcBJyYGBwMGFh8BFjY3EzYmJwOrAQmwBxEHHgYGk5MGBh4HEQewCf0PkwYGHwYSBrAJAQEJsAcRBx4GBgFCKQkPBOMCBwgoCQ8E4gMHCQGIEA0KsAYGHgcRBpOTBhIGHgYGsAoVkwYRBx4GBrAKDRANCrAGBh4GEgYB2Q8DBwj9jAgQAw4DBwgCcwgPBAACAAAAAAOaAm8AEAAhAAAlJzc2NCYiDwEGFB8BFjI2NCU3JyY0NjIfARYUDwEGIiY0AXOmpg0ZJAzEDQ3EDiEaAQ2mpg0aIQ7EDQ3EDiEa2qamDiEaDcQNIg3EDRohDqamDCQZDcQNIg3EDRkkAAAAAwAAAAADuAKsAAsAFwAjAAABDgEHHgEXPgE3LgEDLgEnPgE3HgEXDgEDDgEHHgEXPgE3LgECAJjrNTXrmJjrNTXrmFZwAgJwVlZwAgJwVjRDAQFDNDRDAQFDAqwCpIaGpAICpIaGpP4OAnBWVnACAnBWVnABPgFDNDRDAQFDNDRDAAAABQAAAAADgAKrAAsAFwAjADAAQAAAEyEyNjQmIyEiBhQWFyE+ATQmJyEOARQWEyEyNjQmIyEiBhQWJx4BFyE+ATQmJyEOASUhHgEXEQ4BByEuATURNDarAQATFxcT/wARGRkRAQATFxcT/wARGRkRAQATFxcT/wARGRkaARkRAQATFxcT/wARGQHUAQARGQEBGRH/ABMXFwEAFycXFycXqwEZIhkBARkiGQFVFycXFycX1RMXAQEXJhcBARcYARcT/gARGQEBGRECABMXAAAAAAMAAAAAA6sCVgAZACYAQAAAASMiBhQWOwEeARcOAQcjIgYUFjsBPgE3LgEFHgEXIT4BNCYnIQ4BFyMuASc+ATczMjY0JisBDgEHHgEXMzI2NCYC1YASGBgSgDdIAQFIN4ASGBgSgFt4AwN4/iUBGBIBABIYGBL/ABIYVYA3SAEBSDeAEhgYEoBbeAMDeFuAEhgYAlUYJBkBSTY2SQEZJBgCeFtbeNMSGAEBGCQYAQEYkgFJNjZJARkkGAJ4W1t4AhgkGQABAAAAAAOsAisAHgAAAS4BJw4BBwYWFxY2Nz4BNzIWFwcGFhczPgE3NS4BBwMSO5ZVh9Q4ChMXFCMJK6FnP28sURMTHu4SGAECMRYBvDQ6AQKJchcqCAYPElZpASslUhYxAgEYEu8dFBMAAAABAAAAAAOyAisAHgAAAQ4BBycmBgcVHgEXMz4BLwE+ATMeARceATc+AScuAQIUVZY7URYxAgEYEu4eFBNSLW8+Z6ErCSQTFxMKOdMCKwE6NFAUFB3vEhgBAjEWUiUrAWlWEg8GCCoXcokAAAADAAAAAAL1Ar8AFAAcACQAAAE+ATcuAScjDgEHER4BFyE+ATc0JiUzHgEUBgcjEyM1Mx4BFAYCkyEpAQJmTu8UGQEBGRQBB0lpAjT+1IgdJycdiJ+fnx0nJwGKF0QkTmYCARoT/d4TGgECYUk1UtkBJjsmAf7viQEmOyYAAQAAAAADEgK/ABwAAAEeARczAyMOARQWFzM+ATQmJyMTMz4BNCYnIw4BAaUBJh0hnDsdJiYd5B0mJh0hnDsdJiYd5B0mAnodJgH+lAEmOicBASc6JgEBbAEmOicBAScABgAAAAADlgLWAAsAFwAjAEEAUgBuAAABIT4BNCYnIQ4BFBYBIQ4BFBYXIT4BNCYDIQ4BFBYXIT4BNCYFIyIGFBY7ARUjIgYUFjsBFSMiBhQWOwEyNjc1LgEDMxUeATI2PQE0JisBIgYUFhcjIgYUFjsBBwYdARQWOwEyNjQmKwE3Nj0BLgEBawIAEhgYEv4AEhkZAhL+ABIZGRICABIYGBL+ABIZGRICABIYGP1YVQkMDAlAFQoLCwoVQAkMDAlVCgsBAQtfFQELEwwMCSsJDAxeVQkMDAk3RwUMCVUKCwsKN0gFAQsCVQEYJBgBARgkGP5VARgkGAEBGCQYAQEBGCQYAQEYJBjVDBIMFgwSDBYMEgwMCYAJDAHWawkMDAmACQwMEgzWDBIMVAYICQkMDBIMVAYICQkMAAAAAAYAAAAAA4sCwAAIABEAGgAmADIAPwAAEw4BFBYyNjQmAw4BFBYyNjQmAw4BFBYyNjQmFyE+ATQmJyEOARQWNyE+ATQmJyEOARQWAx4BFyE+ATQmJyEOAbUbJCQ3JCQcGyQkNyQkHBskJDYlJI8CABIYGBL+ABIYGBICABIYGBL+ABIYGBkBGBICABIYGBL+ABIYAcABJDYkJDYkAQEBJDYkJDYk/gEBJDYkJDYkagEYJBgBARgkGP8BGCQYAQEYJBgBKhIYAQEYJBgBARgAAAACAAAAAANWAlYAFgAtAAAlMjY/ATY9AS4BKwEiBh0BFBYXMwcGFgUyNj8BNj0BNCYrASIGBxUeARczBwYWATIRGwc9CQEYEqsSGBgSViwOIAHMEBsIPAkYEqsSGAEBGBJVLA0gqxEOeRIUwhIYGBKrEhgBWB4zAREOeRIUwhIYGBKrEhgBWB4zAAAAAAMAAAAAA4ACwAAIABkAJQAAJT4BNzUjFR4BAR4BFzMVMzUzPgE0JichDgEDIT4BNCYnIQ4BFBYCACQwAaoBMP75ASQblqqWGyQkG/4qGyQrAqoSGRkS/VYSGRlAATAkKyskMAI/GyQBgIABJDYkAQEk/noBGCQYAQEYJBgAAAAAAgAA//8DKwMBABsAKAAAJT4BNxEuASIGBxEUBgcGLgI1ES4BIgYHER4BBx4BMyEyNjQmIyEiBgIiYnoCAR4tHgFBNSFBNR0BHi0eAQOm1AEYEgIAEhgYEv4AEhitD5NlARcWHh4W/uQ3UwwHDys8IwEgFh4eFv7gdpR2EhkZJBgYAAAAAwAAAAADcALHAAsALQA5AAATIT4BNCYjISIGFBYFISIGFBYXITIWFxYGByM1LgEPAQYUHwEWNjc1Mz4BJy4BBSMiBhQWFzM+ATQmwAJVEhkZEv2rEhgYAgv+BxIYGBICBiAzBgUxKGABGQtMBgZMDBgBVU1iBQhk/m2rEhgYEqsSGBgCcQEYJBgYJBisGCQYAScgKTkCIg8KCkwHEQdMCgoPIgJrTkRV/xgkGAEBGCQYAAAAAgAAAAADlgLAABQAKAAAARQWFzMRHgEyNjcRMz4BNCYnIQ4BAzMVFBYyNjc1MzI2NCYnIQ4BFBYBayQclQEkNiQBlRwkJBz+VhwkwEAkNyQBQBskJBv/ABwkJAKAGyQB/kAbJCQbAcABJDYkAQEk/tDrGyQkG+skNyQBASQ3JAAKAAAAAAN4AvgADwAWABoAIQAlACkALQA0ADgAPwAAASEOAQcRHgEXIT4BNxEuAQEjIiY9ATM1IzUzNSM1NDY7ARMjNTM1IzUzNSM1MxMjNTMVFAY3IzUzNSM1MzIWFQMs/aggKgEBKiACWCAqAQEq/h5xDxaWlpaWFg9x4ZaWlpaWlrxxlhYWlpaWcQ8WAvcBKiD9qCAqAQEqIAJYICr9XhYPcUuWS3EPFv2olkuWS5b9qJZxDxbhlkuWFg8AAAACAAD//wOAAwAADwAgAAAlES4BJyEOAQcRHgEXIT4BJRc3NjIfARYGIyEiJj8BPgEDgAEwJP2qJDABATAkAlYkMP39WYUHFAeVCAwN/gEOCwhqBxRVAlYkMAEBMCT9qiQwAQEw+2yqCAnHCxcXC4kIAQAAAAEAAAAAAzUCNgAQAAABBwYUFjI/ARcWMjY0LwEmIgHZ/hAhLBHX1xEsIRD+EC4CJv4RLCEQ19cQISwR/hAAAAABAAAAAAM1AjYAEgAAAQcnJiciDgEWHwEWMj8BNjQuAQLW1tcQFxEbDQYM/hEsEf4QIS0CJtfXDwESICAM/hAQ/hAtIAEAAAAEAAAAAANrAusAEAAhADMARAAANzMVFBYyNj0BNCYrASIGFBYTIyIGFBY7ATI2PQE0JiIGFQEyNj0BMzI2NCYrASIGHQEUFhM1NCYiBh0BFBY7ATI2NCYjyWgeLB0dFpwWHR1+aBYdHRacFh0dLB4BahYeaBYdHRacFh0dSh4sHR0WnBYdHRaxaBYdHRacFh0dLB4Bnh4sHR0WnBYdHRb9Xx0WaB4sHR0WnBYdAjloFh0dFpwWHR0sHgAAAAQAAAAAA1QC1AARACMANABGAAATDgEHFR4BFzM+ATQmKwE1NCYnPgE9ATMyNjQmJyMOAQcVHgEBIyIGFBYXMz4BNzUuASIGFQMeATsBFRQWMjY3NS4BJyMOAd0VGwEBGxWRFRsbFWEcFBQcYRUbGxWRFRsBARsCK2EVGxsVkRUbAQEbKRySARsVYRwpGwEBGxWRFRsBHwEbFZEVGwEBGykcYRUbwwEbFWEcKRsBARsVkRUb/qscKRsBARsVkRUbGxUBtRQcYRUbGxWRFRsBARsAAAAAAAASAN4AAQAAAAAAAAAVAAAAAQAAAAAAAQANABUAAQAAAAAAAgAHACIAAQAAAAAAAwANACkAAQAAAAAABAANADYAAQAAAAAABQALAEMAAQAAAAAABgANAE4AAQAAAAAACgArAFsAAQAAAAAACwATAIYAAwABBAkAAAAqAJkAAwABBAkAAQAaAMMAAwABBAkAAgAOAN0AAwABBAkAAwAaAOsAAwABBAkABAAaAQUAAwABBAkABQAWAR8AAwABBAkABgAaATUAAwABBAkACgBWAU8AAwABBAkACwAmAaUKQ3JlYXRlZCBieSBpY29uZm9udApybWVsLWljb25mb250UmVndWxhcnJtZWwtaWNvbmZvbnRybWVsLWljb25mb250VmVyc2lvbiAxLjBybWVsLWljb25mb250R2VuZXJhdGVkIGJ5IHN2ZzJ0dGYgZnJvbSBGb250ZWxsbyBwcm9qZWN0Lmh0dHA6Ly9mb250ZWxsby5jb20ACgBDAHIAZQBhAHQAZQBkACAAYgB5ACAAaQBjAG8AbgBmAG8AbgB0AAoAcgBtAGUAbAAtAGkAYwBvAG4AZgBvAG4AdABSAGUAZwB1AGwAYQByAHIAbQBlAGwALQBpAGMAbwBuAGYAbwBuAHQAcgBtAGUAbAAtAGkAYwBvAG4AZgBvAG4AdABWAGUAcgBzAGkAbwBuACAAMQAuADAAcgBtAGUAbAAtAGkAYwBvAG4AZgBvAG4AdABHAGUAbgBlAHIAYQB0AGUAZAAgAGIAeQAgAHMAdgBnADIAdAB0AGYAIABmAHIAbwBtACAARgBvAG4AdABlAGwAbABvACAAcAByAG8AagBlAGMAdAAuAGgAdAB0AHAAOgAvAC8AZgBvAG4AdABlAGwAbABvAC4AYwBvAG0AAAAAAgAAAAAAAAAKAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAaAQIBAwEEAQUBBgEHAQgBCQEKAQsBDAENAQ4BDwEQAREBEgETARQBFQEWARcBGAEZARoBGwADdGFiCGtleWJvYXJkBmRlbGV0ZQpjb2RlLWJsb2NrBGNvZGUKdmlzaWJpbGl0eQp2aWV3LXNwbGl0BGxpbmsEcmVkbwR1bmRvBGJvbGQGaXRhbGljDGxpc3Qtb3JkZXJlZA5saXN0LXVub3JkZXJlZAVxdW90ZQ1zdHJpa2V0aHJvdWdoCXVuZGVybGluZQR3cmFwCWZvbnQtc2l6ZQRncmlkBWltYWdlC2V4cGFuZC1sZXNzC2V4cGFuZC1tb3JlD2Z1bGxzY3JlZW4tZXhpdApmdWxsc2NyZWVuAAAAAAA=);
|
|
@@ -585,5 +585,5 @@
|
|
|
585
585
|
.rc-md-editor .header-list .list-item:hover {
|
|
586
586
|
}
|
|
587
587
|
|
|
588
|
-
`;function In({propertyKey:e,value:t,error:o,showError:a,isSubmitting:n,setValue:i,tableMode:s,property:l,includeDescription:c,underlyingValueHasChanged:u,context:m,disabled:g}){if(!Array.isArray(l.resolvedProperties))throw Error("ArrayCustomShapedFieldBinding misconfiguration. Property `of` not set");const f=l.expanded===void 0?!0:l.expanded;Te({property:l,value:t,setValue:i});const h=r.jsx(Ee,{icon:_e(l,"small"),required:l.validation?.required,className:"text-text-secondary dark:text-text-secondary-dark",title:l.name}),b=l.resolvedProperties.map((y,A)=>{const k={propertyKey:`${e}[${A}]`,disabled:g,property:y,includeDescription:c,underlyingValueHasChanged:u,context:m,tableMode:!1,partOfArray:!0,partOfBlock:!1,autoFocus:!1};return r.jsx("div",{className:"pb-4",children:r.jsx(ot,{...k})},`custom_shaped_array_${A}`)});return r.jsxs(r.Fragment,{children:[!s&&r.jsx(p.ExpandablePanel,{initiallyExpanded:f,title:h,className:"px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2",children:b}),s&&b,r.jsx(Ce,{includeDescription:c,showError:a,error:o,disabled:g,property:l})]})}const $l=({containerRef:e})=>{const{isSubmitting:t,isValidating:o,errors:a}=ve.useFormex();return d.useEffect(()=>{const n=Object.keys(a);if(n.length>0&&t&&!o){const i=e?.current?.querySelector(`#form_field_${n[0]}`);if(i&&e?.current){const s=Fn(e.current);if(s){const c=i.getBoundingClientRect().top;s.scrollTo({top:s.scrollTop+c-196,behavior:"smooth"})}const l=i.querySelector("input");l&&l.focus()}}},[t,o,a,e]),null},ql=e=>{const t=e&&e.scrollHeight>e.clientHeight,o=e?window.getComputedStyle(e).overflowY:null,a=o&&o.indexOf("hidden")!==-1;return t&&!a},Fn=e=>!e||e===document.body?document.body:ql(e)?e:Fn(e.parentNode);function Wl({customId:e,entityId:t,status:o,onChange:a,error:n,entity:i,loading:s}){const{errors:l}=ve.useFormex(),c=o==="existing"||!e,u=o!=="existing"&&!e,m=d.useMemo(()=>{if(!(!e||typeof e=="boolean"||e==="optional"))return qe(e)},[e]),g=He(),{copy:f}=ha({onSuccess:y=>g.open({type:"success",message:`Copied ${y}`})}),h=oe(),b={label:u?"ID is set automatically":"ID",disabled:c||s,name:"id",value:(i&&o==="existing"?i.id:t)??"",endAdornment:s?r.jsx(p.CircularProgress,{size:"small"}):i?r.jsxs(r.Fragment,{children:[r.jsx(p.Tooltip,{title:"Copy",children:r.jsx(p.IconButton,{onClick:y=>f(i.id),"aria-label":"copy-id",children:r.jsx(p.ContentCopyIcon,{size:"small"})})}),h?.entityLinkBuilder&&r.jsx(p.Tooltip,{title:"Open in the console",children:r.jsx(p.IconButton,{component:"a",href:h.entityLinkBuilder({entity:i}),rel:"noopener noreferrer",target:"_blank",onClick:y=>y.stopPropagation(),"aria-label":"go-to-datasource",children:r.jsx(p.OpenInNewIcon,{size:"small"})})})]}):void 0};return r.jsxs(r.Fragment,{children:[m&&r.jsx(p.Select,{error:n,onValueChange:y=>a(y),...b,renderValue:y=>{const A=m.find(k=>k.id===y);return A?`${A.id} - ${A.label}`:y},children:m.map(y=>r.jsx(p.SelectItem,{value:String(y.id),children:r.jsx(Ie,{enumKey:y.id,enumValues:m,size:"medium"})},y.id))}),!m&&r.jsx(p.TextField,{...b,error:n,placeholder:e==="optional"?"Autogenerated ID, it can be manually changed":o==="new"||o==="copy"?"ID of the new document":"ID of the document",onChange:y=>{let A=y.target.value;return A&&(A=A.trim()),a(A.length?A:void 0)}}),l.id&&r.jsx(p.Typography,{variant:"caption",className:"ml-3.5 text-red-500 dark:text-red-500",children:l.id})]})}function Jl({propertyId:e}){const[t,o]=d.useState(!1);return r.jsxs("div",{className:"flex flex-row gap-2 items-center justify-center text-white",children:[r.jsxs("div",{children:[r.jsx(p.Typography,{variant:"caption",className:"min-w-20 text-slate-400",color:"disabled",children:t?"Copied":"Property ID"}),r.jsx(p.Typography,{variant:"caption",className:"text-white",children:r.jsx("code",{children:e})})]}),r.jsx(p.IconButton,{size:"small",children:r.jsx(p.ContentPasteIcon,{size:"smallest",className:"text-white",onClick:d.useCallback(()=>{navigator.clipboard.writeText(e),o(!0),setTimeout(()=>o(!1),2e3)},[e])})})]})}const Nn=Hl;function Pn(e,t,o){const a=e.properties;if((t==="existing"||t==="copy")&&o)return o.values??kt(a);if(t==="new")return kt(a);throw console.error({status:t,entity:o}),new Error("Form has not been initialised with the correct parameters")}function Hl({status:e,path:t,collection:o,entity:a,onEntitySaveRequested:n,onDiscard:i,onModified:s,onValuesChanged:l,onIdChange:c,onFormContextChange:u,hideId:m,autoSave:g,onIdUpdateError:f}){const h=ut(),b=oe(),y=Ae(),A=Me(o),k=b.plugins,v=d.useMemo(()=>Ne({collection:o,path:t,values:a?.values,fields:b.propertyConfigs}),[a?.values,t]),_=(e==="new"||e==="copy")&&!!v.customId&&v.customId!=="optional",E=d.useMemo(()=>e==="new"||e==="copy"?_?void 0:A.generateEntityId(t):a?.id,[]),C=d.useRef(!1),B=d.useRef(Pn(v,e,a)),[x,S]=d.useState(E),[I,D]=d.useState(!1),[P,T]=d.useState(),[V,re]=d.useState(!1),[R,$]=d.useState(a?.values??B.current),G=te=>n({collection:ee,path:t,entityId:x,values:te,previousValues:a?.values,closeAfterSave:C.current,autoSave:g??!1}).then(O=>{const ie=e==="new"?"new_entity_saved":e==="copy"?"entity_copied":e==="existing"?"entity_edited":"unmapped_event";h.onAnalyticsEvent?.(ie,{path:t})}).catch(O=>{console.error(O),T(O)}).finally(()=>{C.current=!1}),z=(te,O)=>{if(_&&!x){console.error("Missing custom Id"),D(!0),O.setSubmitting(!1);return}if(T(void 0),D(!1),e==="existing"){if(!a?.id)throw Error("Form misconfiguration when saving, no id for existing entity")}else if(e==="new"||e==="copy"){if(o.customId&&o.customId!=="optional"&&!x)throw Error("Form misconfiguration when saving, entityId should be set")}else throw Error("New FormType added, check EntityForm");return G(te)?.then(ie=>{O.resetForm({values:te,submitCount:0,touched:{}})}).finally(()=>{O.setSubmitting(!1)})},H=ve.useCreateFormex({initialValues:B.current,onSubmit:z,validation:te=>Y?.validate(te,{abortEarly:!1}).then(()=>({})).catch(O=>{const ie={};return O.inner.forEach(fe=>{ie[fe.path]=fe.message}),Xl(O)})});d.useEffect(()=>{B.current=Pn(v,e,a);const te=H.initialValues;!H.isSubmitting&&te&&e==="existing"?Z(Object.entries(ee.properties).map(([O,ie])=>{if(vt(ie))return{};const fe=te[O],ue=B.current[O];return L(fe,ue)?{}:{[O]:ue}}).reduce((O,ie)=>({...O,...ie}),{})):Z({})},[a,v,e]);const J=te=>{const O=H.initialValues;$(te),l&&l(te),g&&te&&!L(te,O)&&G(te)};d.useEffect(()=>{x&&c&&c(x)},[x,c]);const ee=Ne({collection:o,path:t,entityId:x,values:R,previousValues:H.initialValues,fields:b.propertyConfigs}),ne=Fr(ee,b.propertyConfigs),U=R&&ne?Ye(R,ne):void 0,X=o.callbacks?.onIdUpdate,Q=d.useCallback(async()=>{if(X&&R&&(e==="new"||e==="copy")){re(!0);try{const te=await X({collection:ee,path:t,entityId:x,values:R,context:y});S(te)}catch(te){f&&f(te),console.error(te)}re(!1)}},[x,R,e]);d.useEffect(()=>{Q()},[Q]);const[K,Z]=d.useState({}),M=d.useCallback(({name:te,value:O,property:ie})=>A.checkUniqueField(t,te,O,x),[A,t,x]),Y=d.useMemo(()=>x?Ua(x,ee.properties,M):void 0,[x,ee.properties,M]),q=We(),F=d.useCallback(({entity:te,customEntityActions:O})=>{const ie=ct(o,q,t,null),fe=te?Wt(o,q,t,te):!0,ue=[];return ie&&ue.push(mn),fe&&ue.push(fn),O&&ue.push(...O),ue},[q,o,t]),N=[],le={setFieldValue:d.useCallback(H.setFieldValue,[]),values:H.values,collection:ee,entityId:x,path:t,save:G},xe=d.useRef(null);if(d.useEffect(()=>{u&&!Kl(xe.current??void 0,le)&&(u(le),xe.current=le)},[le,u]),k&&o){const te={entityId:x,path:t,status:e,collection:o,context:y,currentEntityId:x,formContext:le};N.push(...k.map((O,ie)=>O.form?.Actions?r.jsx(O.form.Actions,{...te},`actions_${O.key}`):null).filter(Boolean))}return r.jsx(ve.Formex,{value:H,children:r.jsxs("div",{className:"h-full overflow-auto",children:[N.length>0&&r.jsx("div",{className:p.cn("w-full flex justify-end items-center sticky top-0 right-0 left-0 z-10 bg-opacity-60 bg-slate-200 dark:bg-opacity-60 dark:bg-slate-800 backdrop-blur-md"),children:N}),r.jsxs("div",{className:"pt-12 pb-16 pl-8 pr-8 md:pl-10 md:pr-10",children:[r.jsxs("div",{className:`w-full py-2 flex flex-col items-start mt-${4+(N?8:0)} lg:mt-${8+(N?8:0)} mb-8`,children:[r.jsx(p.Typography,{className:"mt-4 flex-grow line-clamp-1 "+o.hideIdFromForm?"mb-2":"mb-0",variant:"h4",children:U??o.singularName??o.name}),r.jsx(p.Alert,{color:"base",className:"w-full",size:"small",children:r.jsxs("code",{className:"text-xs select-all",children:[t,"/",x]})})]}),!m&&r.jsx(Wl,{customId:o.customId,entityId:x,status:e,onChange:S,error:I,loading:V,entity:a}),x&&r.jsx(Zl,{...H,initialValues:H.initialValues,onModified:s,onDiscard:i,onValuesChanged:J,underlyingChanges:K,entity:a,resolvedCollection:ee,formContext:le,status:e,savingError:P,closeAfterSaveRef:C,autoSave:g,entityActions:F({entity:a,customEntityActions:o.entityActions})})]})]})})}function Zl(e){const{values:t,onDiscard:o,onModified:a,onValuesChanged:n,underlyingChanges:i,formContext:s,entity:l,touched:c,setFieldValue:u,resolvedCollection:m,isSubmitting:g,status:f,handleSubmit:h,resetForm:b,savingError:y,dirty:A,closeAfterSaveRef:k,autoSave:v,entityActions:_}=e,E=Ae(),C=_.filter(P=>P.includeInForm===void 0||P.includeInForm),B=Je(),x=A;d.useEffect(()=>{a&&a(x),n&&n(t)},[x,t]),d.useEffect(()=>{!v&&!g&&i&&l&&Object.entries(i).forEach(([P,T])=>{const V=t[P];!L(T,V)&&!c[P]&&(console.debug("Updated value from the datasource:",P,T),u(P,T!==void 0?T:null))})},[g,v,i,l,t,c,u]);const S=r.jsx("div",{className:"flex flex-col gap-8",children:(m.propertiesOrder??Object.keys(m.properties)).map(P=>{const T=m.properties[P];if(!T)return console.warn(`Property ${P} not found in collection ${m.name}`),null;const V=!!i&&Object.keys(i).includes(P)&&!!c[P],re=!v&&g||st(T)||!!T.disabled;if(vt(T))return null;const $={propertyKey:P,disabled:re,property:T,includeDescription:T.description||T.longDescription,underlyingValueHasChanged:V&&!v,context:s,tableMode:!1,partOfArray:!1,partOfBlock:!1,autoFocus:!1};return r.jsx("div",{id:`form_field_${P}`,children:r.jsx(ae,{children:r.jsx(p.Tooltip,{title:r.jsx(Jl,{propertyId:P}),delayDuration:800,side:"left",align:"start",sideOffset:16,children:r.jsx(ot,{...$})})})},`field_${m.name}_${P}`)}).filter(Boolean)}),I=g||!x&&f==="existing",D=d.useRef(null);return r.jsxs("form",{onSubmit:h,onReset:()=>(console.debug("Resetting form"),b(),o&&o()),noValidate:!0,children:[r.jsxs("div",{className:"mt-12",ref:D,children:[S,r.jsx($l,{containerRef:D})]}),r.jsx("div",{className:"h-14"}),!v&&r.jsxs(p.DialogActions,{position:"absolute",children:[y&&r.jsx("div",{className:"text-right",children:r.jsx(p.Typography,{color:"error",children:y.message})}),l&&C.length>0&&r.jsx("div",{className:"flex-grow flex overflow-auto no-scrollbar",children:C.map(P=>r.jsx(p.IconButton,{color:"primary",onClick:T=>{T.stopPropagation(),l&&P.onClick({entity:l,fullPath:m.path,collection:m,context:E,sideEntityController:B})},children:P.icon},P.name))}),r.jsx(p.Button,{variant:"text",disabled:I,type:"reset",children:f==="existing"?"Discard":"Clear"}),r.jsxs(p.Button,{variant:"text",color:"primary",type:"submit",disabled:I,onClick:()=>{k.current=!1},children:[f==="existing"&&"Save",f==="copy"&&"Create copy",f==="new"&&"Create"]}),r.jsxs(p.Button,{variant:"filled",color:"primary",type:"submit",disabled:I,onClick:()=>{k.current=!0},children:[f==="existing"&&"Save and close",f==="copy"&&"Create copy and close",f==="new"&&"Create and close"]})]})]})}function Xl(e){let t={};if(e.inner){if(e.inner.length===0)return ve.setIn(t,e.path,e.message);for(const o of e.inner)ve.getIn(t,o.path)||(t=ve.setIn(t,o.path,o.message))}return t}function Kl(e,t){return e?.path===t?.path&&e?.entityId===t?.entityId&&L(e?.values,t?.values)&&L(e?.collection,t?.collection)}function Tn(e){return Object.keys(ir).includes(e)}const ir={text_field:{key:"text_field",name:"Text field",description:"Simple short text",Icon:p.ShortTextIcon,color:"#2d7ff9",property:{dataType:"string",Field:bt}},multiline:{key:"multiline",name:"Multiline",description:"Text with multiple lines",Icon:p.SubjectIcon,color:"#2d7ff9",property:{dataType:"string",multiline:!0,Field:bt}},markdown:{key:"markdown",name:"Markdown",description:"Text with advanced markdown syntax",Icon:p.FormatQuoteIcon,color:"#2d7ff9",property:{dataType:"string",markdown:!0,Field:Sn}},url:{key:"url",name:"Url",description:"Text with URL validation",Icon:p.HttpIcon,color:"#154fb3",property:{dataType:"string",url:!0,Field:bt}},email:{key:"email",name:"Email",description:"Text with email validation",Icon:p.EmailIcon,color:"#154fb3",property:{dataType:"string",email:!0,Field:bt}},switch:{key:"switch",name:"Switch",description:"Boolean true or false field (or yes or no, 0 or 1...)",Icon:p.FlagIcon,color:"#20d9d2",property:{dataType:"boolean",Field:vn}},select:{key:"select",name:"Select/enum",description:"Select one text value from within an enumeration",Icon:p.ListIcon,color:"#4223c9",property:{dataType:"string",enumValues:[],Field:po}},multi_select:{key:"multi_select",name:"Multi select",description:"Select multiple text values from within an enumeration",Icon:p.ListAltIcon,color:"#4223c9",property:{dataType:"array",of:{dataType:"string",enumValues:[]},Field:uo}},number_input:{key:"number_input",name:"Number input",description:"Simple number field with validation",Icon:p.NumbersIcon,color:"#bec920",property:{dataType:"number",Field:bt}},number_select:{key:"number_select",name:"Number select",description:"Select a number value from within an enumeration",Icon:p.FormatListNumberedIcon,color:"#bec920",property:{dataType:"number",enumValues:[],Field:po}},multi_number_select:{key:"multi_number_select",name:"Multiple number select",description:"Select multiple number values from within an enumeration",Icon:p.FormatListNumberedIcon,color:"#bec920",property:{dataType:"array",of:{dataType:"number",enumValues:[]},Field:uo}},file_upload:{key:"file_upload",name:"File upload",description:"Input for uploading single files",Icon:p.UploadFileIcon,color:"#f92d9a",property:{dataType:"string",storage:{storagePath:"{path}"},Field:mo}},multi_file_upload:{key:"multi_file_upload",name:"Multiple file upload",description:"Input for uploading multiple files",Icon:p.DriveFolderUploadIcon,color:"#f92d9a",property:{dataType:"array",of:{dataType:"string",storage:{storagePath:"{path}"}},Field:mo}},reference:{key:"reference",name:"Reference",description:"The value refers to a different collection",Icon:p.LinkIcon,color:"#ff0042",property:{dataType:"reference",Field:_n}},multi_references:{key:"multi_references",name:"Multiple references",description:"Multiple values that refer to a different collection",Icon:p.AddLinkIcon,color:"#ff0042",property:{dataType:"array",of:{dataType:"reference"},Field:yn}},date_time:{key:"date_time",name:"Date/time",description:"A date time select field",Icon:p.ScheduleIcon,color:"#8b46ff",property:{dataType:"date",Field:kn}},group:{key:"group",name:"Group",description:"Group of multiple fields",Icon:p.BallotIcon,color:"#ff9408",property:{dataType:"map",properties:{},Field:xn}},key_value:{key:"key_value",name:"Key-value",description:"Flexible field that allows the user to add multiple key-value pairs",Icon:p.BallotIcon,color:"#ff9408",property:{dataType:"map",keyValue:!0,Field:Cn}},repeat:{key:"repeat",name:"Repeat/list",description:"A field that gets repeated multiple times (e.g. multiple text fields)",Icon:p.RepeatIcon,color:"#ff9408",property:{dataType:"array",of:{dataType:"string"},Field:En}},custom_array:{key:"custom_array",name:"Custom array",description:"A field that saved its value as an array of custom objects",Icon:p.RepeatIcon,color:"#ff9408",property:{dataType:"array",of:[],Field:In}},block:{key:"block",name:"Block",description:"A complex field that allows the user to compose different fields together, with a key->value format",Icon:p.ViewStreamIcon,color:"#ff9408",property:{dataType:"array",oneOf:{properties:{}},Field:Bn}}};function Dn(e){const t=sr(e);if(!t){console.error("No field id found for property",e);return}return ir[t]}function Ft(e,t){const o=yo(e),a=sr(e);if(!a){console.error("No field id found for property",e);return}const n=ir[a],i=o?t[o]:void 0;return De(n??{},i??{})}function sr(e){if(e.dataType==="string")return e.multiline?"multiline":e.markdown?"markdown":e.storage?"file_upload":e.url?"url":e.email?"email":e.enumValues?"select":"text_field";if(e.dataType==="number")return e.enumValues?"number_select":"number_input";if(e.dataType==="map")return e.keyValue?"key_value":"group";if(e.dataType==="array"){const t=e.of;return e.oneOf?"block":Array.isArray(t)?"custom_array":ke(t)?"repeat":t?.dataType==="string"&&t.enumValues?"multi_select":t?.dataType==="number"&&t.enumValues?"multi_number_select":t?.dataType==="string"&&t.storage?"multi_file_upload":t?.dataType==="reference"?"multi_references":"repeat"}else{if(e.dataType==="boolean")return"switch";if(e.dataType==="date")return"date_time";if(e.dataType==="reference")return"reference"}console.error("Unsupported field config mapping",e)}function yo(e){return e.propertyConfig?e.propertyConfig:sr(e)}const Ne=({collection:e,path:t,entityId:o,values:a,previousValues:n,userConfigPersistence:i,fields:s})=>{const l=i?.getCollectionConfig(t),c=Ye(l,"properties"),u=kt(e.properties),m=a??u,g=n??a??u,f=Object.entries(e.properties).map(([y,A])=>{const k=Pe({propertyKey:y,propertyOrBuilder:A,values:m,previousValues:g,path:t,entityId:o,fields:s});return k?{[y]:k}:{}}).filter(y=>y!==null).reduce((y,A)=>({...y,...A}),{}),h=De(f,c),b=Object.entries(h).filter(([y,A])=>!!A?.dataType).map(([y,A])=>({[y]:A})).reduce((y,A)=>({...y,...A}),{});return{...e,properties:b,originalCollection:e}};function Pe({propertyOrBuilder:e,fromBuilder:t=!1,...o}){if(typeof e=="object"&&"resolved"in e)return e;let a=null;if(e)if(ke(e)){const n=o.path;if(!n)throw Error("Trying to resolve a property builder without specifying the entity path");const i=o.propertyKey?ve.getIn(o.values,o.propertyKey):void 0,s=e({...o,path:n,propertyValue:i,values:o.values??{},previousValues:o.previousValues??o.values??{}});if(!s)return null;a=Pe({...o,propertyOrBuilder:s,fromBuilder:!0})}else{const n=e;if(n.dataType==="map"&&n.properties){const i=wo({...o,properties:n.properties});a={...n,resolved:!0,fromBuilder:t,properties:i}}else n.dataType==="array"?a=Xe({property:n,fromBuilder:t,...o}):(n.dataType==="string"||n.dataType==="number")&&n.enumValues&&(a=vo(n,t))}else return null;if(a||(a={...e,resolved:!0,fromBuilder:t}),a.propertyConfig&&!Tn(a.propertyConfig)){const n=o.fields;if(!n)throw Error(`Trying to resolve a property with key ${a.propertyConfig} that inherits from a custom property config but no custom property configs were provided. Use the property \`propertyConfigs\` in your app config to provide them`);const i=n[a.propertyConfig];if(!i)return console.warn(`Trying to resolve a property with key ${a.propertyConfig} that inherits from a custom property config but no custom property config with that key was found. Check the \`propertyConfigs\` in your app config`),console.warn("Available property configs",n),null;if(i.property){const s=i.property;"propertyConfig"in s&&delete s.propertyConfig;const l=Pe({propertyOrBuilder:s,...o});l&&(a=De(l,a))}}return a?{...a,resolved:!0}:null}function Xe({propertyKey:e,property:t,...o}){const a=e?ve.getIn(o.values,e):void 0;if(t.of){if(Array.isArray(t.of))return{...t,resolved:!0,fromBuilder:o.fromBuilder,resolvedProperties:t.of.map((n,i)=>Pe({propertyKey:`${e}.${i}`,propertyOrBuilder:n,...o,index:i}))};{const n=t.of,i=Array.isArray(a)?a.map((l,c)=>Pe({propertyKey:`${e}.${c}`,propertyOrBuilder:n,...o,index:c})).filter(l=>!!l):[],s=Pe({propertyKey:`${e}`,propertyOrBuilder:n,...o});if(!s)throw Error("When using a property builder as the 'of' prop of an ArrayProperty, you must return a valid child property");return{...t,resolved:!0,fromBuilder:o.fromBuilder,of:s,resolvedProperties:i}}}else if(t.oneOf){const n=t.oneOf?.typeField??wt,i=Array.isArray(a)?a.map((l,c)=>{const u=l&&l[n],m=t.oneOf?.properties[u];return!u||!m?null:Pe({propertyKey:`${e}.${c}`,propertyOrBuilder:m,...o})}).filter(l=>!!l):[],s=wo({properties:t.oneOf.properties,...o});return{...t,resolved:!0,oneOf:{...t.oneOf,properties:s},fromBuilder:o.fromBuilder,resolvedProperties:i}}else{if(t.Field)return{...t,resolved:!0,fromBuilder:o.fromBuilder};throw Error("The array property needs to declare an 'of' or a 'oneOf' property, or provide a custom `Field`")}}function wo({properties:e,...t}){return Object.entries(e).map(([o,a])=>{const n=Pe({propertyKey:o,propertyOrBuilder:a,...t});return n?{[o]:n}:{}}).filter(o=>o!==null).reduce((o,a)=>({...o,...a}),{})}function vo(e,t){return typeof e.enumValues=="object"?{...e,resolved:!0,enumValues:qe(e.enumValues)?.filter(o=>o&&o.id&&o.label)??[],fromBuilder:t??!1}:e}function Rl(e){return typeof e=="object"?Object.entries(e).map(([t,o])=>typeof o=="string"?{id:t,label:o}:o):Array.isArray(e)?e:void 0}function ko(e,t){return typeof e=="string"?t?.find(o=>o.key===e):e}function _o(e){const{path:t,collections:o=[],currentFullPath:a}=e,n=me(t).split("/"),i=Ot(n),s=[];for(let l=0;l<i.length;l++){const c=i[l],u=o&&o.find(m=>m.id===c||m.path===c);if(u){const m=u.id??u.path,g=a&&a.length>0?a+"/"+m:m;s.push({type:"collection",path:g,collection:u});const f=me(me(t).replace(c,"")),h=f.length>0?f.split("/"):[];if(h.length>0){const b=h[0],y=g+"/"+b;if(s.push({type:"entity",entityId:b,path:g,parentCollection:u}),h.length>1){const A=h.slice(1).join("/");if(!u)throw Error("collection not found resolving path: "+u);const k=u.entityViews,v=k&&k.map(_=>ko(_,e.contextEntityViews)).filter(Boolean).find(_=>_.key===A);if(v){const _=a&&a.length>0?a+"/"+v.key:v.key;s.push({type:"custom_view",path:_,view:v})}else u.subcollections&&s.push(..._o({path:A,collections:u.subcollections,currentFullPath:y,contextEntityViews:e.contextEntityViews}))}}break}}return s}const ec="100vw",tc="55vw",lr="768px",cr="main_##Q$SC^#S6";function rc({path:e,entityId:t,selectedSubPath:o,copy:a,collection:n,parentCollectionIds:i,onValuesAreModified:s,formWidth:l,onUpdate:c,onClose:u}){n.customId&&n.formAutoSave&&console.warn(`The collection ${n.path} has customId and formAutoSave enabled. This is not supported and formAutoSave will be ignored`);const[m,g]=d.useState(!1),[f,h]=d.useState(void 0);Ut(f,()=>{f&&F({entityId:U?.id,collection:n,path:e,values:f,closeAfterSave:!1})},!1,2e3);const b=Me(n),y=dr(),A=Je(),k=He(),v=oe(),_=Ae(),E=We(),[C,B]=d.useState(void 0),[x,S]=d.useState(a?"copy":t?"existing":"new"),I=d.useRef(void 0),D=I.current,P=(n.subcollections??[]).filter(j=>!j.hideFromNavigation),T=P?.length??0,V=n.entityViews,re=V?.length??0,R=n.formAutoSave&&!n.customId,$=re>0||T>0,G=o??Cr(n?n.defaultSelectedView:void 0,{status:x,entityId:t}),z=d.useRef(G??cr),H=z.current===cr,{entity:J,dataLoading:ee,dataLoadingError:ne}=Qr({path:e,entityId:t,collection:n,useCache:!1}),[U,X]=d.useState(J),[Q,K]=d.useState(void 0);d.useEffect(()=>{J&&X(J)},[J]),d.useEffect(()=>{if(x==="new")K(!1);else{const j=U?Ir(n,E,e,U??null):!1;U&&K(!j)}},[E,U,x]);const Z=d.useCallback(j=>{g(!1),k.open({type:"error",message:"Error before saving: "+j?.message}),console.error(j)},[k]),M=d.useCallback(j=>{g(!1),k.open({type:"error",message:"Error after saving (entity is saved): "+j?.message}),console.error(j)},[k]),Y=(j,Be)=>{g(!1),R||k.open({type:"success",message:`${n.singularName??n.name}: Saved correctly`}),X(j),S("existing"),s(!1),c&&c({entity:j}),Be?(y.setBlocked(!1),y.close(!0),u?.()):x!=="existing"&&A.replace({path:e,entityId:j.id,selectedSubPath:z.current,updateUrl:!0,collection:n})},q=d.useCallback(j=>{g(!1),k.open({type:"error",message:"Error saving: "+j?.message}),console.error("Error saving entity",e,t),console.error(j)},[t,e,k]),F=({values:j,previousValues:Be,closeAfterSave:Se,entityId:$e,collection:Nt,path:Pt})=>{g(!0),Mr({path:Pt,entityId:$e,values:j,previousValues:Be,collection:Nt,status:x,dataSource:b,context:_,onSaveSuccess:Tt=>Y(Tt,Se),onSaveFailure:q,onPreSaveHookError:Z,onSaveSuccessHookError:M}).then()},N=async({collection:j,path:Be,entityId:Se,values:$e,previousValues:Nt,closeAfterSave:Pt,autoSave:Tt})=>{x&&(Tt?h($e):F({collection:j,path:Be,entityId:Se,values:$e,previousValues:Nt,closeAfterSave:Pt}))},le=V?V.map(j=>ko(j,v.entityViews)).filter(Boolean):[],xe=V&&le.map((j,Be)=>{if(!j||z.current!==j.key)return null;const Se=j.Builder;return Se?r.jsx("div",{className:p.cn(p.defaultBorderMixin,"relative flex-grow w-full h-full overflow-auto "),role:"tabpanel",children:r.jsx(ae,{children:C&&r.jsx(Se,{collection:n,entity:U,modifiedValues:D??U?.values,formContext:C})})},`custom_view_${j.key}`):(console.error("customView.Builder is not defined"),null)}).filter(Boolean),te=ee&&!U||(!U||Q===void 0)&&(x==="existing"||x==="copy"),O=te||m,ie=P&&P.map((j,Be)=>{const Se=j.id??j.path,$e=U?`${e}/${U?.id}/${me(Se)}`:void 0;return z.current!==Se?null:r.jsxs("div",{className:"relative flex-grow h-full overflow-auto w-full",role:"tabpanel",children:[O&&r.jsx(or,{}),!te&&(U&&$e?r.jsx(io,{fullPath:$e,parentCollectionIds:[...i,n.id],isSubCollection:!0,...j}):r.jsx("div",{className:"flex items-center justify-center w-full h-full p-3",children:r.jsx(p.Typography,{variant:"label",children:"You need to save your entity before adding additional collections"})}))]},`subcol_${Se}`)}).filter(Boolean),fe=d.useCallback(()=>{s(!1)},[]),ue=j=>{z.current=j,A.replace({path:e,entityId:t,selectedSubPath:j===cr?void 0:j,updateUrl:!0,collection:n})},he=d.useCallback(j=>{I.current=j},[]),ze=d.useCallback(j=>{k.open({type:"error",message:"Error updating id, check the console"})},[]),Ve=d.useCallback(j=>{X(Be=>Be?{...Be,id:j}:void 0)},[]),Ge=j=>{R||s(j)};function Ue(){const j=v.plugins;let Be=r.jsx(Nn,{status:x,path:e,collection:n,onEntitySaveRequested:N,onDiscard:fe,onValuesChanged:he,onModified:Ge,entity:U,onIdChange:Ve,onFormContextChange:B,hideId:n.hideIdFromForm,autoSave:R,onIdUpdateError:ze});return j&&j.forEach(Se=>{Se.form?.provider&&(Be=r.jsx(Se.form.provider.Component,{status:x,path:e,collection:n,onDiscard:fe,onValuesChanged:he,onModified:Ge,entity:U,context:_,formContext:C,...Se.form.provider.props,children:Be}))}),r.jsx(ae,{children:Be})}const at=Q===void 0?r.jsx(r.Fragment,{}):Q?r.jsxs(r.Fragment,{children:[r.jsx(p.Typography,{className:"mt-16 mb-8 mx-8",variant:"h4",children:n.singularName??n.name}),r.jsx(qr,{className:"px-12",entity:U,path:e,collection:n})]}):Ue(),Co=P&&P.map(j=>r.jsx(p.Tab,{className:"text-sm min-w-[140px]",value:j.id,children:j.name},`entity_detail_collection_tab_${j.name}`)),Eo=le.map(j=>r.jsx(p.Tab,{className:"text-sm min-w-[140px]",value:j.key,children:j.name},`entity_detail_collection_tab_${j.name}`));return r.jsx("div",{className:"flex flex-col h-full w-full transition-width duration-250 ease-in-out",children:r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:p.cn(p.defaultBorderMixin,"no-scrollbar border-b pl-2 pr-2 pt-1 flex items-end overflow-scroll bg-gray-50 dark:bg-gray-950"),children:[r.jsx("div",{className:"pb-1 self-center",children:r.jsx(p.IconButton,{onClick:()=>(u?.(),y.close(!1)),size:"large",children:r.jsx(p.CloseIcon,{})})}),r.jsx("div",{className:"flex-grow"}),te&&r.jsx("div",{className:"self-center",children:r.jsx(p.CircularProgress,{size:"small"})}),r.jsxs(p.Tabs,{value:z.current,onValueChange:j=>{ue(j)},className:"pl-4 pr-4 pt-0",children:[r.jsx(p.Tab,{disabled:!$,value:cr,className:`${$?"":"hidden"} text-sm min-w-[140px]`,children:n.singularName??n.name}),Eo,Co]})]}),r.jsxs("div",{className:"flex-grow h-full flex overflow-auto flex-row w-full ",style:{},children:[r.jsx("div",{role:"tabpanel",hidden:!H,id:`form_${e}`,className:" w-full",children:te?r.jsx(or,{}):at}),xe,ie]})]})})}function oc(e,t){const[o,a]=d.useState(),{navigator:n}=d.useContext(ge.UNSAFE_NavigationContext),i=ge.useNavigate(),s=()=>{a(void 0)},l=()=>{t(),a(void 0),i(-1)},c=d.useCallback(({action:u,location:m,retry:g})=>{switch(u){case"REPLACE":{g();return}case"POP":a(m)}},[]);return d.useEffect(()=>{if(!e||o||!("block"in n))return;const u=n.block(m=>{const g={...m,retry(){u(),m.retry()}};c(g)});return u},[n,c,e,o]),{navigationWasBlocked:!!o,handleCancel:s,handleOk:l}}function ac({open:e,handleOk:t,handleCancel:o,body:a,title:n}){return r.jsxs(p.Dialog,{open:e,onOpenChange:i=>i?o():t(),children:[r.jsxs(p.DialogContent,{children:[r.jsx(p.Typography,{variant:"h6",children:n}),a,r.jsx(p.Typography,{children:"Are you sure you want to leave this page?"})]}),r.jsxs(p.DialogActions,{children:[r.jsx(p.Button,{variant:"text",onClick:o,autoFocus:!0,children:" Cancel "}),r.jsx(p.Button,{onClick:t,children:" Ok "})]})]})}const Qn=d.createContext({width:"",blocked:!1,setBlocked:e=>{},setBlockedNavigationMessage:e=>{},close:()=>{}}),dr=()=>d.useContext(Qn);function nc(){const t=xt().sidePanels,o=[...t];return o.push(void 0),r.jsx(r.Fragment,{children:o.map((a,n)=>r.jsx(ic,{panel:a,offsetPosition:t.length-n-1},`side_dialog_${n}`))})}function ic({offsetPosition:e,panel:t}){const[o,a]=d.useState(!1),[n,i]=d.useState(!1),[s,l]=d.useState(),c=d.useRef(t?.width),u=c.current,m=xt(),{navigationWasBlocked:g,handleOk:f,handleCancel:h}=oc(n&&!o,()=>i(!1));d.useEffect(()=>{t&&(c.current=t.width)},[t]);const b=()=>{i(!1),a(!1),m.close(),t?.onClose?.()},y=()=>{a(!1)},A=k=>{n&&!k?a(!0):(m.close(),t?.onClose?.())};return r.jsxs(Qn.Provider,{value:{blocked:n,setBlocked:i,setBlockedNavigationMessage:l,width:u,close:A},children:[r.jsxs(p.Sheet,{open:!!t,onOpenChange:k=>!k&&A(),children:[t&&r.jsx("div",{className:"transform max-w-[100vw] lg:max-w-[95vw] flex flex-col h-full transition-all duration-250 ease-in-out bg-white dark:bg-gray-900 ",style:{width:t.width,transform:`translateX(-${e*200}px)`},children:r.jsx(ae,{children:t.component})}),!t&&r.jsx("div",{style:{width:u}})]}),r.jsx(ac,{open:g||o,handleOk:o?b:f,handleCancel:o?y:h,body:s})]})}function sc(e){const{blocked:t,setBlocked:o,setBlockedNavigationMessage:a}=dr(),n=pe(),i=d.useMemo(()=>n.getParentCollectionIds(e.path),[n,e.path]),s=d.useMemo(()=>{if(!e)return;let c=e.collection;const u=n.getCollection(e.path,e.entityId);if(u&&(c=u),!c)throw console.error("ERROR: No collection found in path `",e.path,"`. Entity id: ",e.entityId),Error("ERROR: No collection found in path `"+e.path+"`. Make sure you have defined a collection for this path in the root navigation.");return c},[n,e]);d.useEffect(()=>{function c(u){t&&s&&(u.preventDefault(),u.returnValue=`You have unsaved changes in this ${s.name}. Are you sure you want to leave this page?`)}return typeof window<"u"&&window.addEventListener("beforeunload",c),()=>{typeof window<"u"&&window.removeEventListener("beforeunload",c)}},[t,s]);const l=d.useCallback(c=>{o(c),a(c?r.jsxs(r.Fragment,{children:[" You have unsaved changes in this ",r.jsx("b",{children:s?.singularName??s?.name}),"."]}):void 0)},[s?.name,o,a]);return!e||!s?r.jsx("div",{className:"w-full"}):r.jsx(r.Fragment,{children:r.jsx(ae,{children:r.jsx(rc,{...e,formWidth:e.width,collection:s,parentCollectionIds:i,onValuesAreModified:l})})})}const Mn="new";function lc(e,t){if(t)return ec;const o=!e.selectedSubPath;let a;return e.width?a=typeof e.width=="number"?`${e.width}px`:e.width:e.collection?.sideDialogWidth&&(a=typeof e.collection.sideDialogWidth=="number"?`${e.collection.sideDialogWidth}px`:e.collection.sideDialogWidth),o?a||(e.collection?cc(e.collection):lr):`calc(${tc} + ${a??lr})`}const xo={};function cc(e){if(xo[e.id])return xo[e.id];const t=Ne({collection:e,path:"__ignored"});let o=lr;if(t?.properties){const a=Object.values(t.properties).map(i=>pr(i)),n=Math.max(...a);n<3?o=lr:o=768+32*(n-2)+"px"}return xo[e.id]=o,o}function pr(e,t=0){if(e.dataType==="map"&&e.properties){const o=Object.values(e.properties).flatMap(a=>pr(a,t+1));return Math.max(...o)}else return e.dataType==="array"&&e.oneOf?t+3:e.dataType==="array"&&e.of?Array.isArray(e.of)?Math.max(...e.of.map(o=>pr(o,t+1))):pr(e.of,t+1):t+1}const dc=(e,t)=>{const o=ge.useLocation(),a=d.useRef(!1),n=!Qe();d.useEffect(()=>{if(!e.loading&&!a.current){if(console.debug("Initialising side entity controller"),e.isUrlCollectionPath(o.pathname)){const c=o.hash===`#${Mn}`,u=e.urlPathToDataPath(o.pathname),m=pc(u,e.collections??[],c);for(let g=0;g<m.length;g++){const f=m[g];setTimeout(()=>{g===0?t.replace(ur(f,e.buildUrlCollectionPath,e.resolveAliasesFrom,n)):t.open(ur(f,e.buildUrlCollectionPath,e.resolveAliasesFrom,n))},1)}}a.current=!0}},[o,e.loading,e.isUrlCollectionPath,e.buildUrlCollectionPath,e.resolveAliasesFrom,t,n,e]);const i=d.useCallback(()=>{t.close()},[t]),s=d.useCallback(c=>{if(c.copy&&!c.entityId)throw Error("If you want to copy an entity you need to provide an entityId");const u=Cr(c.collection?c.collection.defaultSelectedView:void 0,{status:c.copy?"copy":c.entityId?"existing":"new",entityId:c.entityId});t.open(ur({selectedSubPath:u,...c},e.buildUrlCollectionPath,e.resolveAliasesFrom,n))},[t,e.buildUrlCollectionPath,e.resolveAliasesFrom,n]),l=d.useCallback(c=>{if(c.copy&&!c.entityId)throw Error("If you want to copy an entity you need to provide an entityId");t.replace(ur(c,e.buildUrlCollectionPath,e.resolveAliasesFrom,n))},[e.buildUrlCollectionPath,e.resolveAliasesFrom,t,n]);return{close:i,open:s,replace:l}};function pc(e,t,o){const a=_o({path:e,collections:t}),n=[];let i="";for(let s=0;s<a.length;s++){const l=a[s];if(l.type==="collection"&&(i=l.path),s>0){const c=a[s-1];if(l.type==="entity")n.push({path:l.path,entityId:l.entityId,copy:!1,width:l.parentCollection?.sideDialogWidth});else if(l.type==="custom_view"){if(c.type==="entity"){const u=n[n.length-1];u&&(u.selectedSubPath=l.view.key)}}else if(l.type==="collection"&&c.type==="entity"){const u=n[n.length-1];u&&(u.selectedSubPath=l.collection.id??l.collection.path)}}}return o&&n.push({path:i,copy:!1}),n}const ur=(e,t,o,a)=>{const n=me(e.path),i=e.entityId?t(`${n}/${e.entityId}/${e.selectedSubPath||""}`):t(`${n}#${Mn}`),s=o(e.path),l={...e,path:s};return{key:`${e.path}/${e.entityId}`,component:r.jsx(sc,{...l}),urlPath:i,parentUrlPath:t(n),width:lc(e,a),onClose:e.onClose}};function uc(){const e=ge.useLocation(),t=ge.useNavigate(),[o,a]=d.useState([]),n=d.useRef(o),i=d.useRef({}),s=d.useRef(0),l=g=>{n.current=g,a(g)};d.useEffect(()=>{const h=(e.state?.panels??[]).map(b=>i.current[b]).filter(b=>!!b);L(n.current.map(b=>b.key),h.map(b=>b.key))||l(h)},[e]);const c=d.useCallback(()=>{if(o.length===0)return;const g=o[o.length-1],f=[...o.slice(0,-1)];if(l(f),s.current>0)g.urlPath&&t(-1),s.current--;else if(g.parentUrlPath){const h=e.state?.base_location??e;t(g.parentUrlPath,{replace:!0,state:{base_location:h,panels:f.map(b=>b.key)}})}},[o,t,e]),u=d.useCallback(g=>{const f=Array.isArray(g)?g:[g];f.forEach(y=>{i.current[y.key]=y}),s.current=s.current+f.length;const h=e.state?.base_location??e,b=[...o,...f];l(b),f.forEach(y=>{y.urlPath&&t(y.urlPath,{state:{base_location:h,panels:b.map(A=>A.key)}})})},[e,t,o]),m=d.useCallback(g=>{const f=Array.isArray(g)?g:[g];f.forEach(y=>{i.current[y.key]=y});const h=e.state?.base_location??e,b=[...o.slice(0,-f.length),...f];l(b),f.forEach(y=>{y.urlPath&&t(y.urlPath,{replace:!0,state:{base_location:h,panels:b.map(A=>A.key)}})})},[e,t,o]);return{sidePanels:o,close:c,open:u,replace:m}}function mc({delegate:e,propertyConfigs:t,navigationController:o}){return{fetchCollection:d.useCallback(({path:a,collection:n,filter:i,limit:s,startAfter:l,searchString:c,orderBy:u,order:m})=>e.fetchCollection({path:a,filter:i,limit:s,startAfter:l,searchString:c,orderBy:u,order:m}),[e]),listenCollection:e.listenCollection?d.useCallback(({path:a,collection:n,filter:i,limit:s,startAfter:l,searchString:c,orderBy:u,order:m,onUpdate:g,onError:f})=>{const h=n??o.getCollection(a),b=!!h?.collectionGroup;if(!e.listenCollection)throw Error("useBuildDataSource delegate not initialised");return e.listenCollection({path:a,filter:i,limit:s,startAfter:l,searchString:c,orderBy:u,order:m,onUpdate:g,onError:f,isCollectionGroup:b,collection:h})},[e,o.getCollection]):void 0,fetchEntity:d.useCallback(({path:a,entityId:n})=>e.fetchEntity({path:a,entityId:n}),[e]),listenEntity:e.listenEntity?d.useCallback(({path:a,entityId:n,collection:i,onUpdate:s,onError:l})=>{if(!e.listenEntity)throw Error("useBuildDataSource delegate not initialised");return e.listenEntity({path:a,entityId:n,onUpdate:s,onError:l})},[e.listenEntity]):void 0,saveEntity:d.useCallback(({path:a,entityId:n,values:i,collection:s,status:l})=>{const c=s??o.getCollection(a),m=(c?Ne({collection:c,path:a,entityId:n,fields:t}):void 0)?.properties,g=e.cmsToDelegateModel(i),f=m?Oo({inputValues:g,properties:m,status:l,timestampNowValue:e.currentTime(),setDateToMidnight:e.setDateToMidnight}):g;return e.saveEntity({path:a,entityId:n,values:f,status:l}).then(h=>({id:h.id,path:h.path,values:e.delegateToCMSModel(f)}))},[e.saveEntity,o.getCollection]),deleteEntity:d.useCallback(({entity:a})=>e.deleteEntity({entity:a}),[e.deleteEntity]),checkUniqueField:d.useCallback((a,n,i,s)=>e.checkUniqueField(a,n,i,s),[e.checkUniqueField]),generateEntityId:d.useCallback(a=>e.generateEntityId(a),[e.generateEntityId]),countEntities:e.countEntities?async({path:a,collection:n,filter:i,order:s,orderBy:l})=>e.countEntities({path:a,filter:i,orderBy:l,order:s,isCollectionGroup:!!n.collectionGroup}):void 0,isFilterCombinationValid:d.useCallback(({path:a,filterValues:n,sortBy:i})=>e.isFilterCombinationValid?e.isFilterCombinationValid({path:a,filterValues:n,sortBy:i}):!0,[e.isFilterCombinationValid])}}function xc(e){return e}const fc="https://api-drplyi3b6q-ey.a.run.app";async function hc(e,t){const o=await e.getAuthToken();return fetch(fc+"/access_log",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Basic ${o}`},body:JSON.stringify({plugins:t})}).then(async a=>a.json())}function gc(e,t){const[o,a]=d.useState(null),n=d.useRef(null),i=t?.map(s=>s.key);return d.useEffect(()=>{e.user&&e.user.uid!==n.current&&!e.initialLoading&&(hc(e,i).then(a),n.current=e.user.uid)},[e,i]),o}function Ac(e){const t=Or(),{children:o,entityLinkBuilder:a,userConfigPersistence:n,dateTimeFormat:i,locale:s,authController:l,storageSource:c,dataSourceDelegate:u,plugins:m,onAnalyticsEvent:g,propertyConfigs:f,entityViews:h,components:b,navigationController:y}=e;p.useLocaleConfig(s);const A=mc({delegate:u,propertyConfigs:f,navigationController:y}),k=uc(),v=dc(y,k),_=m?.some(S=>S.loading)??!1,E=l.initialLoading||y.loading||_,C={dateTimeFormat:i,locale:s,entityLinkBuilder:a,plugins:m,entityViews:h??[],propertyConfigs:f??{},components:b},B=d.useMemo(()=>({onAnalyticsEvent:g}),[]),x=gc(l,m);return y.navigationLoadingError?r.jsx(p.CenteredView,{maxWidth:"md",children:r.jsx(ye,{title:"Error loading navigation",error:y.navigationLoadingError})}):l.authError?r.jsx(p.CenteredView,{maxWidth:"md",children:r.jsx(ye,{title:"Error loading auth",error:l.authError})}):x?.blocked?r.jsxs(p.CenteredView,{maxWidth:"md",fullScreen:!0,children:[r.jsx(p.Typography,{variant:"h4",children:"Access blocked"}),r.jsxs(p.Typography,{children:["This app has been blocked. Please reach out at ",r.jsx("a",{href:"mailto:hello@firecms.co",children:"hello@firecms.co"})," for more information."]}),x?.message&&r.jsxs(p.Typography,{children:["Response from the server: ",x?.message]})]}):r.jsx(Qt.Provider,{value:t,children:r.jsx(ua.Provider,{value:B,children:r.jsx(pa.Provider,{value:C,children:r.jsx(ca.Provider,{value:n,children:r.jsx(la.Provider,{value:c,children:r.jsx(aa.Provider,{value:A,children:r.jsx(fr.Provider,{value:l,children:r.jsx(ia.Provider,{value:k,children:r.jsx(sa.Provider,{value:v,children:r.jsx(na.Provider,{value:y,children:r.jsx(Fi,{children:r.jsx(bc,{loading:E,children:o})})})})})})})})})})})})}function bc({loading:e,children:t}){const o=Ae(),a=oe();let n=t({context:o,loading:e});const i=a.plugins;return!e&&i&&i.forEach(s=>{s.provider&&(n=r.jsx(s.provider.Component,{...s.provider.props,context:o,children:n}))}),r.jsx(r.Fragment,{children:n})}function On({hovered:e,drawerOpen:t,closeDrawer:o}){const a=ut(),n=pe(),i=e&&!t,s=Qe(),l=ge.useNavigate(),[c,u]=d.useState(!1);if(!n.topLevelNavigation)throw Error("Navigation not ready in Drawer");const{navigationEntries:m,groups:g}=n.topLevelNavigation,f=m.filter(A=>A.type==="admin")??[],h=g.filter(A=>A!=="Admin"),b=d.useCallback(A=>t?r.jsx("div",{className:"pt-8 pl-6 pr-8 pb-2 flex flex-row items-center",children:r.jsx(p.Typography,{variant:"caption",color:"secondary",className:"font-medium flex-grow line-clamp-1",children:A?A.toUpperCase():"Views".toUpperCase()})}):r.jsx("div",{className:"h-12 w-full"}),[t]),y=A=>{const k=A.type==="collection"?"drawer_navigate_to_collection":A.type==="view"?"drawer_navigate_to_view":"unmapped_event";a.onAnalyticsEvent?.(k,{url:A.url}),s||o()};return r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"flex-grow overflow-scroll no-scrollbar",children:h.map(A=>r.jsxs(d.Fragment,{children:[b(A),Object.values(m).filter(k=>k.group===A).map((k,v)=>r.jsx(zn,{icon:r.jsx(Zt,{collectionOrView:k.collection??k.view}),tooltipsOpen:i,drawerOpen:t,onClick:()=>y(k),url:k.url,name:k.name},`navigation_${v}`))]},`drawer_group_${A}`))}),f.length>0&&r.jsx(p.Menu,{open:c,onOpenChange:u,trigger:r.jsxs(p.IconButton,{shape:"square",className:"m-4 text-gray-900 dark:text-white w-fit",children:[r.jsx(p.Tooltip,{title:"Admin",open:i,side:"right",sideOffset:28,children:r.jsx(p.MoreVertIcon,{})}),t&&r.jsx("div",{className:p.cn(t?"opacity-100":"opacity-0 hidden","mx-4 font-inherit text-inherit"),children:"ADMIN"})]}),children:f.map((A,k)=>r.jsxs(p.MenuItem,{onClick:v=>{v.preventDefault(),l(A.path)},children:[r.jsx(Zt,{collectionOrView:A.view}),A.name]},`navigation_${k}`))})]})}function zn({name:e,icon:t,drawerOpen:o,tooltipsOpen:a,url:n,onClick:i}){const s=r.jsx("div",{className:"text-gray-600 dark:text-gray-500",children:t}),l=r.jsxs(ge.NavLink,{onClick:i,style:{width:o?"280px":"72px",transition:o?"width 150ms ease-in":void 0},className:({isActive:c})=>p.cn("rounded-r-xl truncate","hover:bg-slate-300 hover:bg-opacity-75 dark:hover:bg-gray-700 dark:hover:bg-opacity-75 text-gray-800 dark:text-gray-200 hover:text-gray-900 hover:dark:text-white","flex flex-row items-center mr-8",o?"pl-8 h-12":"pl-6 h-11","font-medium text-sm",c?"bg-slate-200 bg-opacity-75 dark:bg-gray-800":""),to:n,children:[s,r.jsx("div",{className:p.cn(o?"opacity-100":"opacity-0 hidden","ml-4 font-inherit text-inherit"),children:e.toUpperCase()})]});return r.jsx(p.Tooltip,{open:o?!1:a,side:"right",title:e,children:l})}const yc=280,wc=d.memo(function(t){const{children:o,name:a,logo:n,includeDrawer:i=!0,autoOpenDrawer:s,Drawer:l=On,drawerProps:c,FireCMSAppBar:u=An,fireCMSAppBarProps:m}=t,g=Qe(),[f,h]=d.useState(!1),[b,y]=d.useState(!1),A=d.useCallback(()=>y(!0),[]),k=d.useCallback(()=>y(!1),[]),v=d.useCallback(()=>{h(!1)},[]),_=f||!!(g&&s&&b);return r.jsxs("div",{className:"flex h-screen w-screen bg-gray-50 dark:bg-gray-900 text-gray-900 dark:text-white overflow-hidden",style:{paddingTop:"env(safe-area-inset-top)",paddingLeft:"env(safe-area-inset-left)",paddingRight:"env(safe-area-inset-right)",paddingBottom:"env(safe-area-inset-bottom)",height:"100dvh"},children:[r.jsx(u,{title:a,includeDrawer:i,logo:n,drawerOpen:_,...m}),r.jsx(kc,{displayed:i,onMouseEnter:A,onMouseMove:A,onMouseLeave:k,open:_,logo:n,hovered:b,setDrawerOpen:h,children:i&&r.jsx(l,{hovered:b,drawerOpen:_,closeDrawer:v,...c})}),r.jsxs("main",{className:"flex flex-col flex-grow overflow-auto",children:[r.jsx(vc,{}),r.jsx("div",{className:p.cn(p.defaultBorderMixin,"flex-grow overflow-auto lg:m-0 lg:mx-4 lg:mb-4 lg:rounded-lg lg:border lg:border-solid m-0 mt-1"),children:r.jsx(ae,{children:o})})]})]})},L),vc=()=>r.jsx("div",{className:"flex flex-col min-h-[68px]"});function kc(e){const t=pe(),o=e.displayed?e.open?yc:72:0,a=r.jsxs("div",{className:"relative h-full no-scrollbar overflow-y-auto overflow-x-hidden",style:{width:o,transition:"left 100ms cubic-bezier(0.4, 0, 0.6, 1) 0ms, opacity 100ms cubic-bezier(0.4, 0, 0.6, 1) 0ms, width 100ms cubic-bezier(0.4, 0, 0.6, 1) 0ms"},children:[!e.open&&e.displayed&&r.jsx(p.Tooltip,{title:"Open menu",side:"right",sideOffset:12,className:"fixed top-2 left-3 !bg-gray-50 dark:!bg-gray-900 rounded-full w-fit",children:r.jsx(p.IconButton,{color:"inherit","aria-label":"Open menu",className:"sticky top-2 left-3 ",onClick:()=>e.setDrawerOpen(!0),size:"large",children:r.jsx(p.MenuIcon,{})})}),r.jsxs("div",{className:"flex flex-col h-full",children:[r.jsx("div",{style:{transition:"padding 100ms cubic-bezier(0.4, 0, 0.6, 1) 0ms",padding:e.open?"32px 144px 0px 24px":"72px 16px 0px"},className:p.cn("cursor-pointer"),children:r.jsx(p.Tooltip,{title:"Home",sideOffset:20,side:"right",children:r.jsx(ge.Link,{to:t.basePath,children:e.logo?r.jsx("img",{src:e.logo,alt:"Logo",className:p.cn("max-w-full max-h-full",e.open??"w-[112px] h-[112px]")}):r.jsx(so,{})})})}),e.children]})]});return Qe()?r.jsxs("div",{className:"relative",onMouseEnter:e.onMouseEnter,onMouseMove:e.onMouseMove,onMouseLeave:e.onMouseLeave,style:{width:o,transition:"left 100ms cubic-bezier(0.4, 0, 0.6, 1) 0ms, opacity 100ms cubic-bezier(0.4, 0, 0.6, 1) 0ms, width 100ms cubic-bezier(0.4, 0, 0.6, 1) 0ms"},children:[a,r.jsx("div",{className:`absolute right-0 top-4 ${e.open?"opacity-100":"opacity-0 invisible"} transition-opacity duration-1000 ease-in-out`,children:r.jsx(p.IconButton,{"aria-label":"Close drawer",onClick:()=>e.setDrawerOpen(!1),children:r.jsx(p.ChevronLeftIcon,{})})})]}):e.displayed?r.jsxs(r.Fragment,{children:[r.jsx(p.IconButton,{color:"inherit","aria-label":"Open drawer",onClick:()=>e.setDrawerOpen(!0),size:"large",className:"absolute top-2 left-6",children:r.jsx(p.MenuIcon,{})}),r.jsx(p.Sheet,{side:"left",transparent:!0,open:e.open,onOpenChange:e.setDrawerOpen,children:a})]}):null}const _c=d.memo(function({homePage:t=r.jsx(dn,{}),customRoutes:o}){const a=ge.useLocation(),n=pe();if(!n)return r.jsx(r.Fragment,{});const i=a.state,s=i&&i.base_location?i.base_location:a,l=[];n.views&&n.views.forEach(f=>{Array.isArray(f.path)?l.push(...f.path.map(h=>mr(h,f))):l.push(mr(f.path,f))}),n.adminViews&&n.adminViews.forEach(f=>{Array.isArray(f.path)?l.push(...f.path.map(h=>mr(h,f))):l.push(mr(f.path,f))});const u=[...n.collections??[]].sort((f,h)=>h.path.length-f.path.length).map(f=>{const h=n.buildUrlCollectionPath(f.id??f.path);return r.jsx(ge.Route,{path:h+"/*",element:r.jsx(ae,{children:r.jsx(io,{isSubCollection:!1,parentCollectionIds:[],fullPath:f.id??f.path,...f,Actions:St(f.Actions)},`collection_view_${f.id??f.path}`)})},`navigation_${f.id??f.path}`)}),m=r.jsx(ge.Route,{path:"/",element:t}),g=r.jsx(ge.Route,{path:"*",element:r.jsx(gn,{})});return r.jsxs(ge.Routes,{location:s,children:[u,l,m,g,o]})}),mr=(e,t)=>r.jsx(ge.Route,{path:e,element:t.view},"navigation_view_"+e);w.ArrayContainer=lo,w.ArrayContainerItem=co,w.ArrayCustomShapedFieldBinding=In,w.ArrayEnumPreview=Lr,w.ArrayItemOptions=bn,w.ArrayOfMapsPreview=ds,w.ArrayOfReferencesFieldBinding=yn,w.ArrayOfReferencesPreview=Sa,w.ArrayOfStorageComponentsPreview=Ia,w.ArrayOfStringsPreview=Fa,w.ArrayOneOfPreview=Na,w.ArrayPropertyEnumPreview=Ur,w.ArrayPropertyPreview=jr,w.AsyncPreviewComponent=ps,w.AuthControllerContext=fr,w.BlockFieldBinding=Bn,w.BooleanPreview=Da,w.COLLECTION_PATH_SEPARATOR=Lo,w.CircularProgressCenter=or,w.DEFAULT_FIELD_CONFIGS=ir,w.DatePreview=Ta,w.DateTimeFieldBinding=kn,w.DefaultHomePage=dn,w.DeleteConfirmationDialog=vl,w.Drawer=On,w.DrawerNavigationItem=zn,w.EmptyValue=et,w.EntityCollectionRowActions=tr,w.EntityCollectionTable=eo,w.EntityCollectionView=io,w.EntityCollectionViewActions=pn,w.EntityForm=Nn,w.EntityReference=gr,w.EntityView=qr,w.EnumValuesChip=Ie,w.ErrorBoundary=ae,w.ErrorView=ye,w.FieldCaption=Bl,w.FieldHelperText=Ce,w.FireCMS=Ac,w.FireCMSAppBar=An,w.FireCMSLogo=so,w.FormikArrayContainer=nr,w.GeoPoint=Ar,w.IconForView=Zt,w.ImagePreview=ka,w.KeyValueFieldBinding=Cn,w.KeyValuePreview=$r,w.LabelWithIcon=Ee,w.MapFieldBinding=xn,w.MapPropertyPreview=Pa,w.MarkdownFieldBinding=Sn,w.ModeControllerContext=Qt,w.ModeControllerProvider=Kn,w.MultiSelectBinding=uo,w.NavigationCard=sn,w.NavigationCardBinding=cn,w.NavigationGroup=ao,w.NavigationRoutes=_c,w.NotFoundPage=gn,w.NumberPropertyPreview=Qa,w.PropertyConfigBadge=wl,w.PropertyFieldBinding=ot,w.PropertyPreview=we,w.PropertyTableCell=qa,w.ReadOnlyFieldBinding=fo,w.ReferenceFieldBinding=_n,w.ReferencePreview=Oe,w.ReferenceSelectionTable=nn,w.ReferenceWidget=xl,w.RepeatFieldBinding=En,w.Scaffold=wc,w.SearchIconsView=El,w.SelectFieldBinding=po,w.SelectableTable=on,w.SideDialogs=nc,w.SkeletonPropertyComponent=tt,w.SmallNavigationCard=ln,w.SnackbarProvider=Zn,w.StorageThumbnail=_a,w.StorageThumbnailInternal=Ca,w.StorageUploadFieldBinding=mo,w.StringPropertyPreview=Yr,w.SwitchFieldBinding=vn,w.TextFieldBinding=bt,w.UrlComponentPreview=Et,w.Vector=ti,w.VirtualTable=Ka,w.addInitialSlash=Rn,w.applyPermissionsFunctionIfEmpty=Yo,w.buildAdditionalFieldDelegate=Bi,w.buildCollection=wi,w.buildEntityCallbacks=Ei,w.buildEnumLabel=Vo,w.buildEnumValueConfig=Ci,w.buildEnumValues=xi,w.buildFieldConfig=Si,w.buildIdColumn=Ls,w.buildProperties=ki,w.buildPropertiesOrBuilder=_i,w.buildProperty=vi,w.canCreateEntity=ct,w.canDeleteEntity=Wt,w.canEditEntity=Ir,w.defaultDateFormat=jo,w.deleteEntityWithCallbacks=ma,w.enumToObjectEntries=qe,w.flattenObject=Nr,w.fullPathToCollectionSegments=Br,w.getArrayValuesCount=Xo,w.getBracketNotation=hi,w.getCollectionByPathOrId=Mt,w.getCollectionPathsCombinations=Ot,w.getColorForProperty=fi,w.getColorScheme=zo,w.getColumnKeysForProperty=rr,w.getDefaultFieldConfig=Dn,w.getDefaultFieldId=sr,w.getDefaultPropertiesOrder=gi,w.getDefaultValueFor=Gt,w.getDefaultValueForDataType=kr,w.getDefaultValuesFor=kt,w.getEntityImagePreviewPropertyKey=Zo,w.getEntityPreviewKeys=Ho,w.getEntityTitlePropertyKey=Fr,w.getFieldConfig=Ft,w.getFieldId=yo,w.getHashValue=yr,w.getIcon=Jo,w.getIconForProperty=_e,w.getIconForWidget=$t,w.getIdIcon=mi,w.getLabelOrConfigFrom=jt,w.getLastSegment=ei,w.getPropertiesWithPropertiesOrder=Wo,w.getPropertyInPath=Re,w.getRandomId=It,w.getReferenceFrom=je,w.getResolvedPropertyInPath=Sr,w.getSidePanelKey=Yi,w.getValueInPath=Ye,w.hydrateRegExp=$o,w.iconSynonyms=Jt,w.iconsSearch=Ht,w.isDefaultFieldConfigId=Tn,w.isEmptyObject=vr,w.isEnumValueDisabled=ai,w.isHidden=vt,w.isObject=zt,w.isPropertyBuilder=ke,w.isReadOnly=st,w.isReferenceProperty=qo,w.isValidRegExp=ui,w.joinCollectionLists=ea,w.makePropertiesEditable=Ko,w.makePropertiesNonEditable=Ro,w.mergeCollection=ta,w.mergeDeep=De,w.pick=Qo,w.plural=bi,w.printChanged=Tr,w.propertiesToColumns=Za,w.randomColor=ci,w.randomString=lt,w.removeFunctions=br,w.removeInPath=ri,w.removeInitialAndTrailingSlashes=me,w.removeInitialSlash=To,w.removePropsIfExisting=Mo,w.removeTrailingSlash=Do,w.removeUndefined=wr,w.renderSkeletonCaptionText=os,w.renderSkeletonIcon=Gr,w.renderSkeletonImageThumbnail=Vr,w.renderSkeletonText=Le,w.resolveArrayProperty=Xe,w.resolveCollection=Ne,w.resolveCollectionPathIds=hr,w.resolveDefaultSelectedView=Cr,w.resolveEntityView=ko,w.resolveEnumValues=Rl,w.resolveNavigationFrom=fa,w.resolvePermissions=_t,w.resolveProperties=wo,w.resolveProperty=Pe,w.resolvePropertyEnum=vo,w.sanitizeData=oi,w.saveEntityWithCallbacks=Mr,w.segmentsToStrippedPath=Uo,w.serializeRegExp=pi,w.singular=yi,w.slugify=Lt,w.sortProperties=xr,w.stripCollectionPath=Er,w.toKebabCase=ii,w.toSnakeCase=li,w.traverseValueProperty=Yt,w.traverseValuesProperties=_r,w.unslugify=di,w.updateDateAutoValues=Oo,w.useAuthController=We,w.useBrowserTitleAndIcon=Oi,w.useBuildLocalConfigurationPersistence=Ui,w.useBuildModeController=$i,w.useBuildNavigationController=Gi,w.useClearRestoreValue=Te,w.useClipboard=ha,w.useCollectionFetch=Pi,w.useColumnIds=Xr,w.useCustomizationController=oe,w.useDataSource=Me,w.useDataSourceEntityCollectionTableController=to,w.useDebouncedCallback=Ut,w.useDebouncedData=an,w.useEntityFetch=Qr,w.useFireCMSContext=Ae,w.useLargeLayout=Qe,w.useModeController=Or,w.useNavigationController=pe,w.useReferenceDialog=mt,w.useResolvedNavigationFrom=Ti,w.useSelectionController=ro,w.useSideDialogContext=dr,w.useSideDialogsController=xt,w.useSideEntityController=Je,w.useSnackbarController=He,w.useStorageSource=dt,w.useTableSearchHelper=oo,w.useTraceUpdate=Ii,w.useValidateAuthenticator=qi,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
|
|
588
|
+
`;function In({propertyKey:e,value:t,error:o,showError:a,isSubmitting:n,setValue:i,tableMode:s,property:l,includeDescription:c,underlyingValueHasChanged:u,context:m,disabled:g}){if(!Array.isArray(l.resolvedProperties))throw Error("ArrayCustomShapedFieldBinding misconfiguration. Property `of` not set");const f=l.expanded===void 0?!0:l.expanded;Te({property:l,value:t,setValue:i});const h=r.jsx(Ee,{icon:_e(l,"small"),required:l.validation?.required,className:"text-text-secondary dark:text-text-secondary-dark",title:l.name}),b=l.resolvedProperties.map((y,A)=>{const k={propertyKey:`${e}[${A}]`,disabled:g,property:y,includeDescription:c,underlyingValueHasChanged:u,context:m,tableMode:!1,partOfArray:!0,partOfBlock:!1,autoFocus:!1};return r.jsx("div",{className:"pb-4",children:r.jsx(ot,{...k})},`custom_shaped_array_${A}`)});return r.jsxs(r.Fragment,{children:[!s&&r.jsx(p.ExpandablePanel,{initiallyExpanded:f,title:h,className:"px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2",children:b}),s&&b,r.jsx(Ce,{includeDescription:c,showError:a,error:o,disabled:g,property:l})]})}const $l=({containerRef:e})=>{const{isSubmitting:t,isValidating:o,errors:a}=ve.useFormex();return d.useEffect(()=>{const n=Object.keys(a);if(n.length>0&&t&&!o){const i=e?.current?.querySelector(`#form_field_${n[0]}`);if(i&&e?.current){const s=Fn(e.current);if(s){const c=i.getBoundingClientRect().top;s.scrollTo({top:s.scrollTop+c-196,behavior:"smooth"})}const l=i.querySelector("input");l&&l.focus()}}},[t,o,a,e]),null},ql=e=>{const t=e&&e.scrollHeight>e.clientHeight,o=e?window.getComputedStyle(e).overflowY:null,a=o&&o.indexOf("hidden")!==-1;return t&&!a},Fn=e=>!e||e===document.body?document.body:ql(e)?e:Fn(e.parentNode);function Wl({customId:e,entityId:t,status:o,onChange:a,error:n,entity:i,loading:s}){const{errors:l}=ve.useFormex(),c=o==="existing"||!e,u=o!=="existing"&&!e,m=d.useMemo(()=>{if(!(!e||typeof e=="boolean"||e==="optional"))return qe(e)},[e]),g=He(),{copy:f}=ha({onSuccess:y=>g.open({type:"success",message:`Copied ${y}`})}),h=oe(),b={label:u?"ID is set automatically":"ID",disabled:c||s,name:"id",value:(i&&o==="existing"?i.id:t)??"",endAdornment:s?r.jsx(p.CircularProgress,{size:"small"}):i?r.jsxs(r.Fragment,{children:[r.jsx(p.Tooltip,{title:"Copy",children:r.jsx(p.IconButton,{onClick:y=>f(i.id),"aria-label":"copy-id",children:r.jsx(p.ContentCopyIcon,{size:"small"})})}),h?.entityLinkBuilder&&r.jsx(p.Tooltip,{title:"Open in the console",children:r.jsx(p.IconButton,{component:"a",href:h.entityLinkBuilder({entity:i}),rel:"noopener noreferrer",target:"_blank",onClick:y=>y.stopPropagation(),"aria-label":"go-to-datasource",children:r.jsx(p.OpenInNewIcon,{size:"small"})})})]}):void 0};return r.jsxs(r.Fragment,{children:[m&&r.jsx(p.Select,{error:n,onValueChange:y=>a(y),...b,renderValue:y=>{const A=m.find(k=>k.id===y);return A?`${A.id} - ${A.label}`:y},children:m.map(y=>r.jsx(p.SelectItem,{value:String(y.id),children:r.jsx(Ie,{enumKey:y.id,enumValues:m,size:"medium"})},y.id))}),!m&&r.jsx(p.TextField,{...b,error:n,placeholder:e==="optional"?"Autogenerated ID, it can be manually changed":o==="new"||o==="copy"?"ID of the new document":"ID of the document",onChange:y=>{let A=y.target.value;return A&&(A=A.trim()),a(A.length?A:void 0)}}),l.id&&r.jsx(p.Typography,{variant:"caption",className:"ml-3.5 text-red-500 dark:text-red-500",children:l.id})]})}function Jl({propertyId:e}){const[t,o]=d.useState(!1);return r.jsxs("div",{className:"flex flex-row gap-2 items-center justify-center text-white",children:[r.jsxs("div",{children:[r.jsx(p.Typography,{variant:"caption",className:"min-w-20 text-slate-400",color:"disabled",children:t?"Copied":"Property ID"}),r.jsx(p.Typography,{variant:"caption",className:"text-white",children:r.jsx("code",{children:e})})]}),r.jsx(p.IconButton,{size:"small",children:r.jsx(p.ContentPasteIcon,{size:"smallest",className:"text-white",onClick:d.useCallback(()=>{navigator.clipboard.writeText(e),o(!0),setTimeout(()=>o(!1),2e3)},[e])})})]})}const Nn=Hl;function Pn(e,t,o){const a=e.properties;if((t==="existing"||t==="copy")&&o)return o.values??kt(a);if(t==="new")return kt(a);throw console.error({status:t,entity:o}),new Error("Form has not been initialised with the correct parameters")}function Hl({status:e,path:t,collection:o,entity:a,onEntitySaveRequested:n,onDiscard:i,onModified:s,onValuesChanged:l,onIdChange:c,onFormContextChange:u,hideId:m,autoSave:g,onIdUpdateError:f}){const h=ut(),b=oe(),y=Ae(),A=Me(o),k=b.plugins,v=d.useMemo(()=>Ne({collection:o,path:t,values:a?.values,fields:b.propertyConfigs}),[a?.values,t]),_=(e==="new"||e==="copy")&&!!v.customId&&v.customId!=="optional",E=d.useMemo(()=>e==="new"||e==="copy"?_?void 0:A.generateEntityId(t):a?.id,[]),C=d.useRef(!1),B=d.useRef(Pn(v,e,a)),[x,S]=d.useState(E),[I,D]=d.useState(!1),[P,T]=d.useState(),[V,re]=d.useState(!1),[R,$]=d.useState(a?.values??B.current),G=te=>n({collection:ee,path:t,entityId:x,values:te,previousValues:a?.values,closeAfterSave:C.current,autoSave:g??!1}).then(O=>{const ie=e==="new"?"new_entity_saved":e==="copy"?"entity_copied":e==="existing"?"entity_edited":"unmapped_event";h.onAnalyticsEvent?.(ie,{path:t})}).catch(O=>{console.error(O),T(O)}).finally(()=>{C.current=!1}),z=(te,O)=>{if(_&&!x){console.error("Missing custom Id"),D(!0),O.setSubmitting(!1);return}if(T(void 0),D(!1),e==="existing"){if(!a?.id)throw Error("Form misconfiguration when saving, no id for existing entity")}else if(e==="new"||e==="copy"){if(o.customId&&o.customId!=="optional"&&!x)throw Error("Form misconfiguration when saving, entityId should be set")}else throw Error("New FormType added, check EntityForm");return G(te)?.then(ie=>{O.resetForm({values:te,submitCount:0,touched:{}})}).finally(()=>{O.setSubmitting(!1)})},H=ve.useCreateFormex({initialValues:B.current,onSubmit:z,validation:te=>Y?.validate(te,{abortEarly:!1}).then(()=>({})).catch(O=>{const ie={};return O.inner.forEach(fe=>{ie[fe.path]=fe.message}),Xl(O)})});d.useEffect(()=>{B.current=Pn(v,e,a);const te=H.initialValues;!H.isSubmitting&&te&&e==="existing"?Z(Object.entries(ee.properties).map(([O,ie])=>{if(vt(ie))return{};const fe=te[O],ue=B.current[O];return L(fe,ue)?{}:{[O]:ue}}).reduce((O,ie)=>({...O,...ie}),{})):Z({})},[a,v,e]);const J=te=>{const O=H.initialValues;$(te),l&&l(te),g&&te&&!L(te,O)&&G(te)};d.useEffect(()=>{x&&c&&c(x)},[x,c]);const ee=Ne({collection:o,path:t,entityId:x,values:R,previousValues:H.initialValues,fields:b.propertyConfigs}),ne=Fr(ee,b.propertyConfigs),U=R&&ne?Ye(R,ne):void 0,X=o.callbacks?.onIdUpdate,Q=d.useCallback(async()=>{if(X&&R&&(e==="new"||e==="copy")){re(!0);try{const te=await X({collection:ee,path:t,entityId:x,values:R,context:y});S(te)}catch(te){f&&f(te),console.error(te)}re(!1)}},[x,R,e]);d.useEffect(()=>{Q()},[Q]);const[K,Z]=d.useState({}),M=d.useCallback(({name:te,value:O,property:ie})=>A.checkUniqueField(t,te,O,x),[A,t,x]),Y=d.useMemo(()=>x?Ua(x,ee.properties,M):void 0,[x,ee.properties,M]),q=We(),F=d.useCallback(({entity:te,customEntityActions:O})=>{const ie=ct(o,q,t,null),fe=te?Wt(o,q,t,te):!0,ue=[];return ie&&ue.push(mn),fe&&ue.push(fn),O&&ue.push(...O),ue},[q,o,t]),N=[],le={setFieldValue:d.useCallback(H.setFieldValue,[]),values:H.values,collection:ee,entityId:x,path:t,save:G},xe=d.useRef(null);if(d.useEffect(()=>{u&&!Kl(xe.current??void 0,le)&&(u(le),xe.current=le)},[le,u]),k&&o){const te={entityId:x,path:t,status:e,collection:o,context:y,currentEntityId:x,formContext:le};N.push(...k.map((O,ie)=>O.form?.Actions?r.jsx(O.form.Actions,{...te},`actions_${O.key}`):null).filter(Boolean))}return r.jsx(ve.Formex,{value:H,children:r.jsxs("div",{className:"h-full overflow-auto",children:[N.length>0&&r.jsx("div",{className:p.cn("w-full flex justify-end items-center sticky top-0 right-0 left-0 z-10 bg-opacity-60 bg-slate-200 dark:bg-opacity-60 dark:bg-slate-800 backdrop-blur-md"),children:N}),r.jsxs("div",{className:"pt-12 pb-16 pl-8 pr-8 md:pl-10 md:pr-10",children:[r.jsxs("div",{className:`w-full py-2 flex flex-col items-start mt-${4+(N?8:0)} lg:mt-${8+(N?8:0)} mb-8`,children:[r.jsx(p.Typography,{className:"mt-4 flex-grow line-clamp-1 "+o.hideIdFromForm?"mb-2":"mb-0",variant:"h4",children:U??o.singularName??o.name}),r.jsx(p.Alert,{color:"base",className:"w-full",size:"small",children:r.jsxs("code",{className:"text-xs select-all",children:[t,"/",x]})})]}),!m&&r.jsx(Wl,{customId:o.customId,entityId:x,status:e,onChange:S,error:I,loading:V,entity:a}),x&&r.jsx(Zl,{...H,initialValues:H.initialValues,onModified:s,onDiscard:i,onValuesChanged:J,underlyingChanges:K,entity:a,resolvedCollection:ee,formContext:le,status:e,savingError:P,closeAfterSaveRef:C,autoSave:g,entityActions:F({entity:a,customEntityActions:o.entityActions})})]})]})})}function Zl(e){const{values:t,onDiscard:o,onModified:a,onValuesChanged:n,underlyingChanges:i,formContext:s,entity:l,touched:c,setFieldValue:u,resolvedCollection:m,isSubmitting:g,status:f,handleSubmit:h,resetForm:b,savingError:y,dirty:A,closeAfterSaveRef:k,autoSave:v,entityActions:_}=e,E=Ae(),C=_.filter(P=>P.includeInForm===void 0||P.includeInForm),B=Je(),x=A;d.useEffect(()=>{a&&a(x),n&&n(t)},[x,t]),d.useEffect(()=>{!v&&!g&&i&&l&&Object.entries(i).forEach(([P,T])=>{const V=t[P];!L(T,V)&&!c[P]&&(console.debug("Updated value from the datasource:",P,T),u(P,T!==void 0?T:null))})},[g,v,i,l,t,c,u]);const S=r.jsx("div",{className:"flex flex-col gap-8",children:(m.propertiesOrder??Object.keys(m.properties)).map(P=>{const T=m.properties[P];if(!T)return console.warn(`Property ${P} not found in collection ${m.name}`),null;const V=!!i&&Object.keys(i).includes(P)&&!!c[P],re=!v&&g||st(T)||!!T.disabled;if(vt(T))return null;const $={propertyKey:P,disabled:re,property:T,includeDescription:T.description||T.longDescription,underlyingValueHasChanged:V&&!v,context:s,tableMode:!1,partOfArray:!1,partOfBlock:!1,autoFocus:!1};return r.jsx("div",{id:`form_field_${P}`,children:r.jsx(ae,{children:r.jsx(p.Tooltip,{title:r.jsx(Jl,{propertyId:P}),delayDuration:800,side:"left",align:"start",sideOffset:16,children:r.jsx(ot,{...$})})})},`field_${m.name}_${P}`)}).filter(Boolean)}),I=g||!x&&f==="existing",D=d.useRef(null);return r.jsxs("form",{onSubmit:h,onReset:()=>(console.debug("Resetting form"),b(),o&&o()),noValidate:!0,children:[r.jsxs("div",{className:"mt-12",ref:D,children:[S,r.jsx($l,{containerRef:D})]}),r.jsx("div",{className:"h-14"}),!v&&r.jsxs(p.DialogActions,{position:"absolute",children:[y&&r.jsx("div",{className:"text-right",children:r.jsx(p.Typography,{color:"error",children:y.message})}),l&&C.length>0&&r.jsx("div",{className:"flex-grow flex overflow-auto no-scrollbar",children:C.map(P=>r.jsx(p.IconButton,{color:"primary",onClick:T=>{T.stopPropagation(),l&&P.onClick({entity:l,fullPath:m.path,collection:m,context:E,sideEntityController:B})},children:P.icon},P.name))}),r.jsx(p.Button,{variant:"text",disabled:I,type:"reset",children:f==="existing"?"Discard":"Clear"}),r.jsxs(p.Button,{variant:"text",color:"primary",type:"submit",disabled:I,onClick:()=>{k.current=!1},children:[f==="existing"&&"Save",f==="copy"&&"Create copy",f==="new"&&"Create"]}),r.jsxs(p.Button,{variant:"filled",color:"primary",type:"submit",disabled:I,onClick:()=>{k.current=!0},children:[f==="existing"&&"Save and close",f==="copy"&&"Create copy and close",f==="new"&&"Create and close"]})]})]})}function Xl(e){let t={};if(e.inner){if(e.inner.length===0)return ve.setIn(t,e.path,e.message);for(const o of e.inner)ve.getIn(t,o.path)||(t=ve.setIn(t,o.path,o.message))}return t}function Kl(e,t){return e?.path===t?.path&&e?.entityId===t?.entityId&&L(e?.values,t?.values)&&L(e?.collection,t?.collection)}function Tn(e){return Object.keys(ir).includes(e)}const ir={text_field:{key:"text_field",name:"Text field",description:"Simple short text",Icon:p.ShortTextIcon,color:"#2d7ff9",property:{dataType:"string",Field:bt}},multiline:{key:"multiline",name:"Multiline",description:"Text with multiple lines",Icon:p.SubjectIcon,color:"#2d7ff9",property:{dataType:"string",multiline:!0,Field:bt}},markdown:{key:"markdown",name:"Markdown",description:"Text with advanced markdown syntax",Icon:p.FormatQuoteIcon,color:"#2d7ff9",property:{dataType:"string",markdown:!0,Field:Sn}},url:{key:"url",name:"Url",description:"Text with URL validation",Icon:p.HttpIcon,color:"#154fb3",property:{dataType:"string",url:!0,Field:bt}},email:{key:"email",name:"Email",description:"Text with email validation",Icon:p.EmailIcon,color:"#154fb3",property:{dataType:"string",email:!0,Field:bt}},switch:{key:"switch",name:"Switch",description:"Boolean true or false field (or yes or no, 0 or 1...)",Icon:p.FlagIcon,color:"#20d9d2",property:{dataType:"boolean",Field:vn}},select:{key:"select",name:"Select/enum",description:"Select one text value from within an enumeration",Icon:p.ListIcon,color:"#4223c9",property:{dataType:"string",enumValues:[],Field:po}},multi_select:{key:"multi_select",name:"Multi select",description:"Select multiple text values from within an enumeration",Icon:p.ListAltIcon,color:"#4223c9",property:{dataType:"array",of:{dataType:"string",enumValues:[]},Field:uo}},number_input:{key:"number_input",name:"Number input",description:"Simple number field with validation",Icon:p.NumbersIcon,color:"#bec920",property:{dataType:"number",Field:bt}},number_select:{key:"number_select",name:"Number select",description:"Select a number value from within an enumeration",Icon:p.FormatListNumberedIcon,color:"#bec920",property:{dataType:"number",enumValues:[],Field:po}},multi_number_select:{key:"multi_number_select",name:"Multiple number select",description:"Select multiple number values from within an enumeration",Icon:p.FormatListNumberedIcon,color:"#bec920",property:{dataType:"array",of:{dataType:"number",enumValues:[]},Field:uo}},file_upload:{key:"file_upload",name:"File upload",description:"Input for uploading single files",Icon:p.UploadFileIcon,color:"#f92d9a",property:{dataType:"string",storage:{storagePath:"{path}"},Field:mo}},multi_file_upload:{key:"multi_file_upload",name:"Multiple file upload",description:"Input for uploading multiple files",Icon:p.DriveFolderUploadIcon,color:"#f92d9a",property:{dataType:"array",of:{dataType:"string",storage:{storagePath:"{path}"}},Field:mo}},reference:{key:"reference",name:"Reference",description:"The value refers to a different collection",Icon:p.LinkIcon,color:"#ff0042",property:{dataType:"reference",Field:_n}},multi_references:{key:"multi_references",name:"Multiple references",description:"Multiple values that refer to a different collection",Icon:p.AddLinkIcon,color:"#ff0042",property:{dataType:"array",of:{dataType:"reference"},Field:yn}},date_time:{key:"date_time",name:"Date/time",description:"A date time select field",Icon:p.ScheduleIcon,color:"#8b46ff",property:{dataType:"date",Field:kn}},group:{key:"group",name:"Group",description:"Group of multiple fields",Icon:p.BallotIcon,color:"#ff9408",property:{dataType:"map",properties:{},Field:xn}},key_value:{key:"key_value",name:"Key-value",description:"Flexible field that allows the user to add multiple key-value pairs",Icon:p.BallotIcon,color:"#ff9408",property:{dataType:"map",keyValue:!0,Field:Cn}},repeat:{key:"repeat",name:"Repeat/list",description:"A field that gets repeated multiple times (e.g. multiple text fields)",Icon:p.RepeatIcon,color:"#ff9408",property:{dataType:"array",of:{dataType:"string"},Field:En}},custom_array:{key:"custom_array",name:"Custom array",description:"A field that saved its value as an array of custom objects",Icon:p.RepeatIcon,color:"#ff9408",property:{dataType:"array",of:[],Field:In}},block:{key:"block",name:"Block",description:"A complex field that allows the user to compose different fields together, with a key->value format",Icon:p.ViewStreamIcon,color:"#ff9408",property:{dataType:"array",oneOf:{properties:{}},Field:Bn}}};function Dn(e){const t=sr(e);if(!t){console.error("No field id found for property",e);return}return ir[t]}function Ft(e,t){const o=yo(e),a=sr(e);if(!a){console.error("No field id found for property",e);return}const n=ir[a],i=o?t[o]:void 0;return De(n??{},i??{})}function sr(e){if(e.dataType==="string")return e.multiline?"multiline":e.markdown?"markdown":e.storage?"file_upload":e.url?"url":e.email?"email":e.enumValues?"select":"text_field";if(e.dataType==="number")return e.enumValues?"number_select":"number_input";if(e.dataType==="map")return e.keyValue?"key_value":"group";if(e.dataType==="array"){const t=e.of;return e.oneOf?"block":Array.isArray(t)?"custom_array":ke(t)?"repeat":t?.dataType==="string"&&t.enumValues?"multi_select":t?.dataType==="number"&&t.enumValues?"multi_number_select":t?.dataType==="string"&&t.storage?"multi_file_upload":t?.dataType==="reference"?"multi_references":"repeat"}else{if(e.dataType==="boolean")return"switch";if(e.dataType==="date")return"date_time";if(e.dataType==="reference")return"reference"}console.error("Unsupported field config mapping",e)}function yo(e){return e.propertyConfig?e.propertyConfig:sr(e)}const Ne=({collection:e,path:t,entityId:o,values:a,previousValues:n,userConfigPersistence:i,fields:s})=>{const l=i?.getCollectionConfig(t),c=Ye(l,"properties"),u=kt(e.properties),m=a??u,g=n??a??u,f=Object.entries(e.properties).map(([y,A])=>{const k=Pe({propertyKey:y,propertyOrBuilder:A,values:m,previousValues:g,path:t,entityId:o,fields:s});return k?{[y]:k}:{}}).filter(y=>y!==null).reduce((y,A)=>({...y,...A}),{}),h=De(f,c),b=Object.entries(h).filter(([y,A])=>!!A?.dataType).map(([y,A])=>({[y]:A})).reduce((y,A)=>({...y,...A}),{});return{...e,properties:b,originalCollection:e}};function Pe({propertyOrBuilder:e,fromBuilder:t=!1,...o}){if(typeof e=="object"&&"resolved"in e)return e;let a=null;if(e)if(ke(e)){const n=o.path;if(!n)throw Error("Trying to resolve a property builder without specifying the entity path");const i=o.propertyKey?ve.getIn(o.values,o.propertyKey):void 0,s=e({...o,path:n,propertyValue:i,values:o.values??{},previousValues:o.previousValues??o.values??{}});if(!s)return null;a=Pe({...o,propertyOrBuilder:s,fromBuilder:!0})}else{const n=e;if(n.dataType==="map"&&n.properties){const i=wo({...o,properties:n.properties});a={...n,resolved:!0,fromBuilder:t,properties:i}}else n.dataType==="array"?a=Xe({property:n,fromBuilder:t,...o}):(n.dataType==="string"||n.dataType==="number")&&n.enumValues&&(a=vo(n,t))}else return null;if(a||(a={...e,resolved:!0,fromBuilder:t}),a.propertyConfig&&!Tn(a.propertyConfig)){const n=o.fields;if(!n)throw Error(`Trying to resolve a property with key '${a.propertyConfig}' that inherits from a custom property config but no custom property configs were provided. Use the property 'propertyConfigs' in your app config to provide them`);const i=n[a.propertyConfig];if(!i)return console.warn(`Trying to resolve a property with key '${a.propertyConfig}' that inherits from a custom property config but no custom property config with that key was found. Check the 'propertyConfigs' in your app config`),console.warn("Available property configs",n),null;if(i.property){const s=i.property;"propertyConfig"in s&&delete s.propertyConfig;const l=Pe({propertyOrBuilder:s,...o});l&&(a=De(l,a))}}return a?{...a,resolved:!0}:null}function Xe({propertyKey:e,property:t,...o}){const a=e?ve.getIn(o.values,e):void 0;if(t.of){if(Array.isArray(t.of))return{...t,resolved:!0,fromBuilder:o.fromBuilder,resolvedProperties:t.of.map((n,i)=>Pe({propertyKey:`${e}.${i}`,propertyOrBuilder:n,...o,index:i}))};{const n=t.of,i=Array.isArray(a)?a.map((l,c)=>Pe({propertyKey:`${e}.${c}`,propertyOrBuilder:n,...o,index:c})).filter(l=>!!l):[],s=Pe({propertyKey:`${e}`,propertyOrBuilder:n,...o});if(!s)throw Error("When using a property builder as the 'of' prop of an ArrayProperty, you must return a valid child property");return{...t,resolved:!0,fromBuilder:o.fromBuilder,of:s,resolvedProperties:i}}}else if(t.oneOf){const n=t.oneOf?.typeField??wt,i=Array.isArray(a)?a.map((l,c)=>{const u=l&&l[n],m=t.oneOf?.properties[u];return!u||!m?null:Pe({propertyKey:`${e}.${c}`,propertyOrBuilder:m,...o})}).filter(l=>!!l):[],s=wo({properties:t.oneOf.properties,...o});return{...t,resolved:!0,oneOf:{...t.oneOf,properties:s},fromBuilder:o.fromBuilder,resolvedProperties:i}}else{if(t.Field)return{...t,resolved:!0,fromBuilder:o.fromBuilder};throw Error("The array property needs to declare an 'of' or a 'oneOf' property, or provide a custom `Field`")}}function wo({properties:e,...t}){return Object.entries(e).map(([o,a])=>{const n=Pe({propertyKey:o,propertyOrBuilder:a,...t});return n?{[o]:n}:{}}).filter(o=>o!==null).reduce((o,a)=>({...o,...a}),{})}function vo(e,t){return typeof e.enumValues=="object"?{...e,resolved:!0,enumValues:qe(e.enumValues)?.filter(o=>o&&o.id&&o.label)??[],fromBuilder:t??!1}:e}function Rl(e){return typeof e=="object"?Object.entries(e).map(([t,o])=>typeof o=="string"?{id:t,label:o}:o):Array.isArray(e)?e:void 0}function ko(e,t){return typeof e=="string"?t?.find(o=>o.key===e):e}function _o(e){const{path:t,collections:o=[],currentFullPath:a}=e,n=me(t).split("/"),i=Ot(n),s=[];for(let l=0;l<i.length;l++){const c=i[l],u=o&&o.find(m=>m.id===c||m.path===c);if(u){const m=u.id??u.path,g=a&&a.length>0?a+"/"+m:m;s.push({type:"collection",path:g,collection:u});const f=me(me(t).replace(c,"")),h=f.length>0?f.split("/"):[];if(h.length>0){const b=h[0],y=g+"/"+b;if(s.push({type:"entity",entityId:b,path:g,parentCollection:u}),h.length>1){const A=h.slice(1).join("/");if(!u)throw Error("collection not found resolving path: "+u);const k=u.entityViews,v=k&&k.map(_=>ko(_,e.contextEntityViews)).filter(Boolean).find(_=>_.key===A);if(v){const _=a&&a.length>0?a+"/"+v.key:v.key;s.push({type:"custom_view",path:_,view:v})}else u.subcollections&&s.push(..._o({path:A,collections:u.subcollections,currentFullPath:y,contextEntityViews:e.contextEntityViews}))}}break}}return s}const ec="100vw",tc="55vw",lr="768px",cr="main_##Q$SC^#S6";function rc({path:e,entityId:t,selectedSubPath:o,copy:a,collection:n,parentCollectionIds:i,onValuesAreModified:s,formWidth:l,onUpdate:c,onClose:u}){n.customId&&n.formAutoSave&&console.warn(`The collection ${n.path} has customId and formAutoSave enabled. This is not supported and formAutoSave will be ignored`);const[m,g]=d.useState(!1),[f,h]=d.useState(void 0);Ut(f,()=>{f&&F({entityId:U?.id,collection:n,path:e,values:f,closeAfterSave:!1})},!1,2e3);const b=Me(n),y=dr(),A=Je(),k=He(),v=oe(),_=Ae(),E=We(),[C,B]=d.useState(void 0),[x,S]=d.useState(a?"copy":t?"existing":"new"),I=d.useRef(void 0),D=I.current,P=(n.subcollections??[]).filter(j=>!j.hideFromNavigation),T=P?.length??0,V=n.entityViews,re=V?.length??0,R=n.formAutoSave&&!n.customId,$=re>0||T>0,G=o??Cr(n?n.defaultSelectedView:void 0,{status:x,entityId:t}),z=d.useRef(G??cr),H=z.current===cr,{entity:J,dataLoading:ee,dataLoadingError:ne}=Qr({path:e,entityId:t,collection:n,useCache:!1}),[U,X]=d.useState(J),[Q,K]=d.useState(void 0);d.useEffect(()=>{J&&X(J)},[J]),d.useEffect(()=>{if(x==="new")K(!1);else{const j=U?Ir(n,E,e,U??null):!1;U&&K(!j)}},[E,U,x]);const Z=d.useCallback(j=>{g(!1),k.open({type:"error",message:"Error before saving: "+j?.message}),console.error(j)},[k]),M=d.useCallback(j=>{g(!1),k.open({type:"error",message:"Error after saving (entity is saved): "+j?.message}),console.error(j)},[k]),Y=(j,Be)=>{g(!1),R||k.open({type:"success",message:`${n.singularName??n.name}: Saved correctly`}),X(j),S("existing"),s(!1),c&&c({entity:j}),Be?(y.setBlocked(!1),y.close(!0),u?.()):x!=="existing"&&A.replace({path:e,entityId:j.id,selectedSubPath:z.current,updateUrl:!0,collection:n})},q=d.useCallback(j=>{g(!1),k.open({type:"error",message:"Error saving: "+j?.message}),console.error("Error saving entity",e,t),console.error(j)},[t,e,k]),F=({values:j,previousValues:Be,closeAfterSave:Se,entityId:$e,collection:Nt,path:Pt})=>{g(!0),Mr({path:Pt,entityId:$e,values:j,previousValues:Be,collection:Nt,status:x,dataSource:b,context:_,onSaveSuccess:Tt=>Y(Tt,Se),onSaveFailure:q,onPreSaveHookError:Z,onSaveSuccessHookError:M}).then()},N=async({collection:j,path:Be,entityId:Se,values:$e,previousValues:Nt,closeAfterSave:Pt,autoSave:Tt})=>{x&&(Tt?h($e):F({collection:j,path:Be,entityId:Se,values:$e,previousValues:Nt,closeAfterSave:Pt}))},le=V?V.map(j=>ko(j,v.entityViews)).filter(Boolean):[],xe=V&&le.map((j,Be)=>{if(!j||z.current!==j.key)return null;const Se=j.Builder;return Se?r.jsx("div",{className:p.cn(p.defaultBorderMixin,"relative flex-grow w-full h-full overflow-auto "),role:"tabpanel",children:r.jsx(ae,{children:C&&r.jsx(Se,{collection:n,entity:U,modifiedValues:D??U?.values,formContext:C})})},`custom_view_${j.key}`):(console.error("customView.Builder is not defined"),null)}).filter(Boolean),te=ee&&!U||(!U||Q===void 0)&&(x==="existing"||x==="copy"),O=te||m,ie=P&&P.map((j,Be)=>{const Se=j.id??j.path,$e=U?`${e}/${U?.id}/${me(Se)}`:void 0;return z.current!==Se?null:r.jsxs("div",{className:"relative flex-grow h-full overflow-auto w-full",role:"tabpanel",children:[O&&r.jsx(or,{}),!te&&(U&&$e?r.jsx(io,{fullPath:$e,parentCollectionIds:[...i,n.id],isSubCollection:!0,...j}):r.jsx("div",{className:"flex items-center justify-center w-full h-full p-3",children:r.jsx(p.Typography,{variant:"label",children:"You need to save your entity before adding additional collections"})}))]},`subcol_${Se}`)}).filter(Boolean),fe=d.useCallback(()=>{s(!1)},[]),ue=j=>{z.current=j,A.replace({path:e,entityId:t,selectedSubPath:j===cr?void 0:j,updateUrl:!0,collection:n})},he=d.useCallback(j=>{I.current=j},[]),ze=d.useCallback(j=>{k.open({type:"error",message:"Error updating id, check the console"})},[]),Ve=d.useCallback(j=>{X(Be=>Be?{...Be,id:j}:void 0)},[]),Ge=j=>{R||s(j)};function Ue(){const j=v.plugins;let Be=r.jsx(Nn,{status:x,path:e,collection:n,onEntitySaveRequested:N,onDiscard:fe,onValuesChanged:he,onModified:Ge,entity:U,onIdChange:Ve,onFormContextChange:B,hideId:n.hideIdFromForm,autoSave:R,onIdUpdateError:ze});return j&&j.forEach(Se=>{Se.form?.provider&&(Be=r.jsx(Se.form.provider.Component,{status:x,path:e,collection:n,onDiscard:fe,onValuesChanged:he,onModified:Ge,entity:U,context:_,formContext:C,...Se.form.provider.props,children:Be}))}),r.jsx(ae,{children:Be})}const at=Q===void 0?r.jsx(r.Fragment,{}):Q?r.jsxs(r.Fragment,{children:[r.jsx(p.Typography,{className:"mt-16 mb-8 mx-8",variant:"h4",children:n.singularName??n.name}),r.jsx(qr,{className:"px-12",entity:U,path:e,collection:n})]}):Ue(),Co=P&&P.map(j=>r.jsx(p.Tab,{className:"text-sm min-w-[140px]",value:j.id,children:j.name},`entity_detail_collection_tab_${j.name}`)),Eo=le.map(j=>r.jsx(p.Tab,{className:"text-sm min-w-[140px]",value:j.key,children:j.name},`entity_detail_collection_tab_${j.name}`));return r.jsx("div",{className:"flex flex-col h-full w-full transition-width duration-250 ease-in-out",children:r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:p.cn(p.defaultBorderMixin,"no-scrollbar border-b pl-2 pr-2 pt-1 flex items-end overflow-scroll bg-gray-50 dark:bg-gray-950"),children:[r.jsx("div",{className:"pb-1 self-center",children:r.jsx(p.IconButton,{onClick:()=>(u?.(),y.close(!1)),size:"large",children:r.jsx(p.CloseIcon,{})})}),r.jsx("div",{className:"flex-grow"}),te&&r.jsx("div",{className:"self-center",children:r.jsx(p.CircularProgress,{size:"small"})}),r.jsxs(p.Tabs,{value:z.current,onValueChange:j=>{ue(j)},className:"pl-4 pr-4 pt-0",children:[r.jsx(p.Tab,{disabled:!$,value:cr,className:`${$?"":"hidden"} text-sm min-w-[140px]`,children:n.singularName??n.name}),Eo,Co]})]}),r.jsxs("div",{className:"flex-grow h-full flex overflow-auto flex-row w-full ",style:{},children:[r.jsx("div",{role:"tabpanel",hidden:!H,id:`form_${e}`,className:" w-full",children:te?r.jsx(or,{}):at}),xe,ie]})]})})}function oc(e,t){const[o,a]=d.useState(),{navigator:n}=d.useContext(ge.UNSAFE_NavigationContext),i=ge.useNavigate(),s=()=>{a(void 0)},l=()=>{t(),a(void 0),i(-1)},c=d.useCallback(({action:u,location:m,retry:g})=>{switch(u){case"REPLACE":{g();return}case"POP":a(m)}},[]);return d.useEffect(()=>{if(!e||o||!("block"in n))return;const u=n.block(m=>{const g={...m,retry(){u(),m.retry()}};c(g)});return u},[n,c,e,o]),{navigationWasBlocked:!!o,handleCancel:s,handleOk:l}}function ac({open:e,handleOk:t,handleCancel:o,body:a,title:n}){return r.jsxs(p.Dialog,{open:e,onOpenChange:i=>i?o():t(),children:[r.jsxs(p.DialogContent,{children:[r.jsx(p.Typography,{variant:"h6",children:n}),a,r.jsx(p.Typography,{children:"Are you sure you want to leave this page?"})]}),r.jsxs(p.DialogActions,{children:[r.jsx(p.Button,{variant:"text",onClick:o,autoFocus:!0,children:" Cancel "}),r.jsx(p.Button,{onClick:t,children:" Ok "})]})]})}const Qn=d.createContext({width:"",blocked:!1,setBlocked:e=>{},setBlockedNavigationMessage:e=>{},close:()=>{}}),dr=()=>d.useContext(Qn);function nc(){const t=xt().sidePanels,o=[...t];return o.push(void 0),r.jsx(r.Fragment,{children:o.map((a,n)=>r.jsx(ic,{panel:a,offsetPosition:t.length-n-1},`side_dialog_${n}`))})}function ic({offsetPosition:e,panel:t}){const[o,a]=d.useState(!1),[n,i]=d.useState(!1),[s,l]=d.useState(),c=d.useRef(t?.width),u=c.current,m=xt(),{navigationWasBlocked:g,handleOk:f,handleCancel:h}=oc(n&&!o,()=>i(!1));d.useEffect(()=>{t&&(c.current=t.width)},[t]);const b=()=>{i(!1),a(!1),m.close(),t?.onClose?.()},y=()=>{a(!1)},A=k=>{n&&!k?a(!0):(m.close(),t?.onClose?.())};return r.jsxs(Qn.Provider,{value:{blocked:n,setBlocked:i,setBlockedNavigationMessage:l,width:u,close:A},children:[r.jsxs(p.Sheet,{open:!!t,onOpenChange:k=>!k&&A(),children:[t&&r.jsx("div",{className:"transform max-w-[100vw] lg:max-w-[95vw] flex flex-col h-full transition-all duration-250 ease-in-out bg-white dark:bg-gray-900 ",style:{width:t.width,transform:`translateX(-${e*200}px)`},children:r.jsx(ae,{children:t.component})}),!t&&r.jsx("div",{style:{width:u}})]}),r.jsx(ac,{open:g||o,handleOk:o?b:f,handleCancel:o?y:h,body:s})]})}function sc(e){const{blocked:t,setBlocked:o,setBlockedNavigationMessage:a}=dr(),n=pe(),i=d.useMemo(()=>n.getParentCollectionIds(e.path),[n,e.path]),s=d.useMemo(()=>{if(!e)return;let c=e.collection;const u=n.getCollection(e.path,e.entityId);if(u&&(c=u),!c)throw console.error("ERROR: No collection found in path `",e.path,"`. Entity id: ",e.entityId),Error("ERROR: No collection found in path `"+e.path+"`. Make sure you have defined a collection for this path in the root navigation.");return c},[n,e]);d.useEffect(()=>{function c(u){t&&s&&(u.preventDefault(),u.returnValue=`You have unsaved changes in this ${s.name}. Are you sure you want to leave this page?`)}return typeof window<"u"&&window.addEventListener("beforeunload",c),()=>{typeof window<"u"&&window.removeEventListener("beforeunload",c)}},[t,s]);const l=d.useCallback(c=>{o(c),a(c?r.jsxs(r.Fragment,{children:[" You have unsaved changes in this ",r.jsx("b",{children:s?.singularName??s?.name}),"."]}):void 0)},[s?.name,o,a]);return!e||!s?r.jsx("div",{className:"w-full"}):r.jsx(r.Fragment,{children:r.jsx(ae,{children:r.jsx(rc,{...e,formWidth:e.width,collection:s,parentCollectionIds:i,onValuesAreModified:l})})})}const Mn="new";function lc(e,t){if(t)return ec;const o=!e.selectedSubPath;let a;return e.width?a=typeof e.width=="number"?`${e.width}px`:e.width:e.collection?.sideDialogWidth&&(a=typeof e.collection.sideDialogWidth=="number"?`${e.collection.sideDialogWidth}px`:e.collection.sideDialogWidth),o?a||(e.collection?cc(e.collection):lr):`calc(${tc} + ${a??lr})`}const xo={};function cc(e){if(xo[e.id])return xo[e.id];const t=Ne({collection:e,path:"__ignored"});let o=lr;if(t?.properties){const a=Object.values(t.properties).map(i=>pr(i)),n=Math.max(...a);n<3?o=lr:o=768+32*(n-2)+"px"}return xo[e.id]=o,o}function pr(e,t=0){if(e.dataType==="map"&&e.properties){const o=Object.values(e.properties).flatMap(a=>pr(a,t+1));return Math.max(...o)}else return e.dataType==="array"&&e.oneOf?t+3:e.dataType==="array"&&e.of?Array.isArray(e.of)?Math.max(...e.of.map(o=>pr(o,t+1))):pr(e.of,t+1):t+1}const dc=(e,t)=>{const o=ge.useLocation(),a=d.useRef(!1),n=!Qe();d.useEffect(()=>{if(!e.loading&&!a.current){if(console.debug("Initialising side entity controller"),e.isUrlCollectionPath(o.pathname)){const c=o.hash===`#${Mn}`,u=e.urlPathToDataPath(o.pathname),m=pc(u,e.collections??[],c);for(let g=0;g<m.length;g++){const f=m[g];setTimeout(()=>{g===0?t.replace(ur(f,e.buildUrlCollectionPath,e.resolveAliasesFrom,n)):t.open(ur(f,e.buildUrlCollectionPath,e.resolveAliasesFrom,n))},1)}}a.current=!0}},[o,e.loading,e.isUrlCollectionPath,e.buildUrlCollectionPath,e.resolveAliasesFrom,t,n,e]);const i=d.useCallback(()=>{t.close()},[t]),s=d.useCallback(c=>{if(c.copy&&!c.entityId)throw Error("If you want to copy an entity you need to provide an entityId");const u=Cr(c.collection?c.collection.defaultSelectedView:void 0,{status:c.copy?"copy":c.entityId?"existing":"new",entityId:c.entityId});t.open(ur({selectedSubPath:u,...c},e.buildUrlCollectionPath,e.resolveAliasesFrom,n))},[t,e.buildUrlCollectionPath,e.resolveAliasesFrom,n]),l=d.useCallback(c=>{if(c.copy&&!c.entityId)throw Error("If you want to copy an entity you need to provide an entityId");t.replace(ur(c,e.buildUrlCollectionPath,e.resolveAliasesFrom,n))},[e.buildUrlCollectionPath,e.resolveAliasesFrom,t,n]);return{close:i,open:s,replace:l}};function pc(e,t,o){const a=_o({path:e,collections:t}),n=[];let i="";for(let s=0;s<a.length;s++){const l=a[s];if(l.type==="collection"&&(i=l.path),s>0){const c=a[s-1];if(l.type==="entity")n.push({path:l.path,entityId:l.entityId,copy:!1,width:l.parentCollection?.sideDialogWidth});else if(l.type==="custom_view"){if(c.type==="entity"){const u=n[n.length-1];u&&(u.selectedSubPath=l.view.key)}}else if(l.type==="collection"&&c.type==="entity"){const u=n[n.length-1];u&&(u.selectedSubPath=l.collection.id??l.collection.path)}}}return o&&n.push({path:i,copy:!1}),n}const ur=(e,t,o,a)=>{const n=me(e.path),i=e.entityId?t(`${n}/${e.entityId}/${e.selectedSubPath||""}`):t(`${n}#${Mn}`),s=o(e.path),l={...e,path:s};return{key:`${e.path}/${e.entityId}`,component:r.jsx(sc,{...l}),urlPath:i,parentUrlPath:t(n),width:lc(e,a),onClose:e.onClose}};function uc(){const e=ge.useLocation(),t=ge.useNavigate(),[o,a]=d.useState([]),n=d.useRef(o),i=d.useRef({}),s=d.useRef(0),l=g=>{n.current=g,a(g)};d.useEffect(()=>{const h=(e.state?.panels??[]).map(b=>i.current[b]).filter(b=>!!b);L(n.current.map(b=>b.key),h.map(b=>b.key))||l(h)},[e]);const c=d.useCallback(()=>{if(o.length===0)return;const g=o[o.length-1],f=[...o.slice(0,-1)];if(l(f),s.current>0)g.urlPath&&t(-1),s.current--;else if(g.parentUrlPath){const h=e.state?.base_location??e;t(g.parentUrlPath,{replace:!0,state:{base_location:h,panels:f.map(b=>b.key)}})}},[o,t,e]),u=d.useCallback(g=>{const f=Array.isArray(g)?g:[g];f.forEach(y=>{i.current[y.key]=y}),s.current=s.current+f.length;const h=e.state?.base_location??e,b=[...o,...f];l(b),f.forEach(y=>{y.urlPath&&t(y.urlPath,{state:{base_location:h,panels:b.map(A=>A.key)}})})},[e,t,o]),m=d.useCallback(g=>{const f=Array.isArray(g)?g:[g];f.forEach(y=>{i.current[y.key]=y});const h=e.state?.base_location??e,b=[...o.slice(0,-f.length),...f];l(b),f.forEach(y=>{y.urlPath&&t(y.urlPath,{replace:!0,state:{base_location:h,panels:b.map(A=>A.key)}})})},[e,t,o]);return{sidePanels:o,close:c,open:u,replace:m}}function mc({delegate:e,propertyConfigs:t,navigationController:o}){return{fetchCollection:d.useCallback(({path:a,collection:n,filter:i,limit:s,startAfter:l,searchString:c,orderBy:u,order:m})=>e.fetchCollection({path:a,filter:i,limit:s,startAfter:l,searchString:c,orderBy:u,order:m}),[e]),listenCollection:e.listenCollection?d.useCallback(({path:a,collection:n,filter:i,limit:s,startAfter:l,searchString:c,orderBy:u,order:m,onUpdate:g,onError:f})=>{const h=n??o.getCollection(a),b=!!h?.collectionGroup;if(!e.listenCollection)throw Error("useBuildDataSource delegate not initialised");return e.listenCollection({path:a,filter:i,limit:s,startAfter:l,searchString:c,orderBy:u,order:m,onUpdate:g,onError:f,isCollectionGroup:b,collection:h})},[e,o.getCollection]):void 0,fetchEntity:d.useCallback(({path:a,entityId:n})=>e.fetchEntity({path:a,entityId:n}),[e]),listenEntity:e.listenEntity?d.useCallback(({path:a,entityId:n,collection:i,onUpdate:s,onError:l})=>{if(!e.listenEntity)throw Error("useBuildDataSource delegate not initialised");return e.listenEntity({path:a,entityId:n,onUpdate:s,onError:l})},[e.listenEntity]):void 0,saveEntity:d.useCallback(({path:a,entityId:n,values:i,collection:s,status:l})=>{const c=s??o.getCollection(a),m=(c?Ne({collection:c,path:a,entityId:n,fields:t}):void 0)?.properties,g=e.cmsToDelegateModel(i),f=m?Oo({inputValues:g,properties:m,status:l,timestampNowValue:e.currentTime(),setDateToMidnight:e.setDateToMidnight}):g;return e.saveEntity({path:a,entityId:n,values:f,status:l}).then(h=>({id:h.id,path:h.path,values:e.delegateToCMSModel(f)}))},[e.saveEntity,o.getCollection]),deleteEntity:d.useCallback(({entity:a})=>e.deleteEntity({entity:a}),[e.deleteEntity]),checkUniqueField:d.useCallback((a,n,i,s)=>e.checkUniqueField(a,n,i,s),[e.checkUniqueField]),generateEntityId:d.useCallback(a=>e.generateEntityId(a),[e.generateEntityId]),countEntities:e.countEntities?async({path:a,collection:n,filter:i,order:s,orderBy:l})=>e.countEntities({path:a,filter:i,orderBy:l,order:s,isCollectionGroup:!!n.collectionGroup}):void 0,isFilterCombinationValid:d.useCallback(({path:a,filterValues:n,sortBy:i})=>e.isFilterCombinationValid?e.isFilterCombinationValid({path:a,filterValues:n,sortBy:i}):!0,[e.isFilterCombinationValid])}}function xc(e){return e}const fc="https://api-drplyi3b6q-ey.a.run.app";async function hc(e,t){const o=await e.getAuthToken();return fetch(fc+"/access_log",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Basic ${o}`},body:JSON.stringify({plugins:t})}).then(async a=>a.json())}function gc(e,t){const[o,a]=d.useState(null),n=d.useRef(null),i=t?.map(s=>s.key);return d.useEffect(()=>{e.user&&e.user.uid!==n.current&&!e.initialLoading&&(hc(e,i).then(a),n.current=e.user.uid)},[e,i]),o}function Ac(e){const t=Or(),{children:o,entityLinkBuilder:a,userConfigPersistence:n,dateTimeFormat:i,locale:s,authController:l,storageSource:c,dataSourceDelegate:u,plugins:m,onAnalyticsEvent:g,propertyConfigs:f,entityViews:h,components:b,navigationController:y}=e;p.useLocaleConfig(s);const A=mc({delegate:u,propertyConfigs:f,navigationController:y}),k=uc(),v=dc(y,k),_=m?.some(S=>S.loading)??!1,E=l.initialLoading||y.loading||_,C={dateTimeFormat:i,locale:s,entityLinkBuilder:a,plugins:m,entityViews:h??[],propertyConfigs:f??{},components:b},B=d.useMemo(()=>({onAnalyticsEvent:g}),[]),x=gc(l,m);return y.navigationLoadingError?r.jsx(p.CenteredView,{maxWidth:"md",children:r.jsx(ye,{title:"Error loading navigation",error:y.navigationLoadingError})}):l.authError?r.jsx(p.CenteredView,{maxWidth:"md",children:r.jsx(ye,{title:"Error loading auth",error:l.authError})}):x?.blocked?r.jsxs(p.CenteredView,{maxWidth:"md",fullScreen:!0,children:[r.jsx(p.Typography,{variant:"h4",children:"Access blocked"}),r.jsxs(p.Typography,{children:["This app has been blocked. Please reach out at ",r.jsx("a",{href:"mailto:hello@firecms.co",children:"hello@firecms.co"})," for more information."]}),x?.message&&r.jsxs(p.Typography,{children:["Response from the server: ",x?.message]})]}):r.jsx(Qt.Provider,{value:t,children:r.jsx(ua.Provider,{value:B,children:r.jsx(pa.Provider,{value:C,children:r.jsx(ca.Provider,{value:n,children:r.jsx(la.Provider,{value:c,children:r.jsx(aa.Provider,{value:A,children:r.jsx(fr.Provider,{value:l,children:r.jsx(ia.Provider,{value:k,children:r.jsx(sa.Provider,{value:v,children:r.jsx(na.Provider,{value:y,children:r.jsx(Fi,{children:r.jsx(bc,{loading:E,children:o})})})})})})})})})})})})}function bc({loading:e,children:t}){const o=Ae(),a=oe();let n=t({context:o,loading:e});const i=a.plugins;return!e&&i&&i.forEach(s=>{s.provider&&(n=r.jsx(s.provider.Component,{...s.provider.props,context:o,children:n}))}),r.jsx(r.Fragment,{children:n})}function On({hovered:e,drawerOpen:t,closeDrawer:o}){const a=ut(),n=pe(),i=e&&!t,s=Qe(),l=ge.useNavigate(),[c,u]=d.useState(!1);if(!n.topLevelNavigation)throw Error("Navigation not ready in Drawer");const{navigationEntries:m,groups:g}=n.topLevelNavigation,f=m.filter(A=>A.type==="admin")??[],h=g.filter(A=>A!=="Admin"),b=d.useCallback(A=>t?r.jsx("div",{className:"pt-8 pl-6 pr-8 pb-2 flex flex-row items-center",children:r.jsx(p.Typography,{variant:"caption",color:"secondary",className:"font-medium flex-grow line-clamp-1",children:A?A.toUpperCase():"Views".toUpperCase()})}):r.jsx("div",{className:"h-12 w-full"}),[t]),y=A=>{const k=A.type==="collection"?"drawer_navigate_to_collection":A.type==="view"?"drawer_navigate_to_view":"unmapped_event";a.onAnalyticsEvent?.(k,{url:A.url}),s||o()};return r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"flex-grow overflow-scroll no-scrollbar",children:h.map(A=>r.jsxs(d.Fragment,{children:[b(A),Object.values(m).filter(k=>k.group===A).map((k,v)=>r.jsx(zn,{icon:r.jsx(Zt,{collectionOrView:k.collection??k.view}),tooltipsOpen:i,drawerOpen:t,onClick:()=>y(k),url:k.url,name:k.name},`navigation_${v}`))]},`drawer_group_${A}`))}),f.length>0&&r.jsx(p.Menu,{open:c,onOpenChange:u,trigger:r.jsxs(p.IconButton,{shape:"square",className:"m-4 text-gray-900 dark:text-white w-fit",children:[r.jsx(p.Tooltip,{title:"Admin",open:i,side:"right",sideOffset:28,children:r.jsx(p.MoreVertIcon,{})}),t&&r.jsx("div",{className:p.cn(t?"opacity-100":"opacity-0 hidden","mx-4 font-inherit text-inherit"),children:"ADMIN"})]}),children:f.map((A,k)=>r.jsxs(p.MenuItem,{onClick:v=>{v.preventDefault(),l(A.path)},children:[r.jsx(Zt,{collectionOrView:A.view}),A.name]},`navigation_${k}`))})]})}function zn({name:e,icon:t,drawerOpen:o,tooltipsOpen:a,url:n,onClick:i}){const s=r.jsx("div",{className:"text-gray-600 dark:text-gray-500",children:t}),l=r.jsxs(ge.NavLink,{onClick:i,style:{width:o?"280px":"72px",transition:o?"width 150ms ease-in":void 0},className:({isActive:c})=>p.cn("rounded-r-xl truncate","hover:bg-slate-300 hover:bg-opacity-75 dark:hover:bg-gray-700 dark:hover:bg-opacity-75 text-gray-800 dark:text-gray-200 hover:text-gray-900 hover:dark:text-white","flex flex-row items-center mr-8",o?"pl-8 h-12":"pl-6 h-11","font-medium text-sm",c?"bg-slate-200 bg-opacity-75 dark:bg-gray-800":""),to:n,children:[s,r.jsx("div",{className:p.cn(o?"opacity-100":"opacity-0 hidden","ml-4 font-inherit text-inherit"),children:e.toUpperCase()})]});return r.jsx(p.Tooltip,{open:o?!1:a,side:"right",title:e,children:l})}const yc=280,wc=d.memo(function(t){const{children:o,name:a,logo:n,includeDrawer:i=!0,autoOpenDrawer:s,Drawer:l=On,drawerProps:c,FireCMSAppBar:u=An,fireCMSAppBarProps:m}=t,g=Qe(),[f,h]=d.useState(!1),[b,y]=d.useState(!1),A=d.useCallback(()=>y(!0),[]),k=d.useCallback(()=>y(!1),[]),v=d.useCallback(()=>{h(!1)},[]),_=f||!!(g&&s&&b);return r.jsxs("div",{className:"flex h-screen w-screen bg-gray-50 dark:bg-gray-900 text-gray-900 dark:text-white overflow-hidden",style:{paddingTop:"env(safe-area-inset-top)",paddingLeft:"env(safe-area-inset-left)",paddingRight:"env(safe-area-inset-right)",paddingBottom:"env(safe-area-inset-bottom)",height:"100dvh"},children:[r.jsx(u,{title:a,includeDrawer:i,logo:n,drawerOpen:_,...m}),r.jsx(kc,{displayed:i,onMouseEnter:A,onMouseMove:A,onMouseLeave:k,open:_,logo:n,hovered:b,setDrawerOpen:h,children:i&&r.jsx(l,{hovered:b,drawerOpen:_,closeDrawer:v,...c})}),r.jsxs("main",{className:"flex flex-col flex-grow overflow-auto",children:[r.jsx(vc,{}),r.jsx("div",{className:p.cn(p.defaultBorderMixin,"flex-grow overflow-auto lg:m-0 lg:mx-4 lg:mb-4 lg:rounded-lg lg:border lg:border-solid m-0 mt-1"),children:r.jsx(ae,{children:o})})]})]})},L),vc=()=>r.jsx("div",{className:"flex flex-col min-h-[68px]"});function kc(e){const t=pe(),o=e.displayed?e.open?yc:72:0,a=r.jsxs("div",{className:"relative h-full no-scrollbar overflow-y-auto overflow-x-hidden",style:{width:o,transition:"left 100ms cubic-bezier(0.4, 0, 0.6, 1) 0ms, opacity 100ms cubic-bezier(0.4, 0, 0.6, 1) 0ms, width 100ms cubic-bezier(0.4, 0, 0.6, 1) 0ms"},children:[!e.open&&e.displayed&&r.jsx(p.Tooltip,{title:"Open menu",side:"right",sideOffset:12,className:"fixed top-2 left-3 !bg-gray-50 dark:!bg-gray-900 rounded-full w-fit",children:r.jsx(p.IconButton,{color:"inherit","aria-label":"Open menu",className:"sticky top-2 left-3 ",onClick:()=>e.setDrawerOpen(!0),size:"large",children:r.jsx(p.MenuIcon,{})})}),r.jsxs("div",{className:"flex flex-col h-full",children:[r.jsx("div",{style:{transition:"padding 100ms cubic-bezier(0.4, 0, 0.6, 1) 0ms",padding:e.open?"32px 144px 0px 24px":"72px 16px 0px"},className:p.cn("cursor-pointer"),children:r.jsx(p.Tooltip,{title:"Home",sideOffset:20,side:"right",children:r.jsx(ge.Link,{to:t.basePath,children:e.logo?r.jsx("img",{src:e.logo,alt:"Logo",className:p.cn("max-w-full max-h-full",e.open??"w-[112px] h-[112px]")}):r.jsx(so,{})})})}),e.children]})]});return Qe()?r.jsxs("div",{className:"relative",onMouseEnter:e.onMouseEnter,onMouseMove:e.onMouseMove,onMouseLeave:e.onMouseLeave,style:{width:o,transition:"left 100ms cubic-bezier(0.4, 0, 0.6, 1) 0ms, opacity 100ms cubic-bezier(0.4, 0, 0.6, 1) 0ms, width 100ms cubic-bezier(0.4, 0, 0.6, 1) 0ms"},children:[a,r.jsx("div",{className:`absolute right-0 top-4 ${e.open?"opacity-100":"opacity-0 invisible"} transition-opacity duration-1000 ease-in-out`,children:r.jsx(p.IconButton,{"aria-label":"Close drawer",onClick:()=>e.setDrawerOpen(!1),children:r.jsx(p.ChevronLeftIcon,{})})})]}):e.displayed?r.jsxs(r.Fragment,{children:[r.jsx(p.IconButton,{color:"inherit","aria-label":"Open drawer",onClick:()=>e.setDrawerOpen(!0),size:"large",className:"absolute top-2 left-6",children:r.jsx(p.MenuIcon,{})}),r.jsx(p.Sheet,{side:"left",transparent:!0,open:e.open,onOpenChange:e.setDrawerOpen,children:a})]}):null}const _c=d.memo(function({homePage:t=r.jsx(dn,{}),customRoutes:o}){const a=ge.useLocation(),n=pe();if(!n)return r.jsx(r.Fragment,{});const i=a.state,s=i&&i.base_location?i.base_location:a,l=[];n.views&&n.views.forEach(f=>{Array.isArray(f.path)?l.push(...f.path.map(h=>mr(h,f))):l.push(mr(f.path,f))}),n.adminViews&&n.adminViews.forEach(f=>{Array.isArray(f.path)?l.push(...f.path.map(h=>mr(h,f))):l.push(mr(f.path,f))});const u=[...n.collections??[]].sort((f,h)=>h.path.length-f.path.length).map(f=>{const h=n.buildUrlCollectionPath(f.id??f.path);return r.jsx(ge.Route,{path:h+"/*",element:r.jsx(ae,{children:r.jsx(io,{isSubCollection:!1,parentCollectionIds:[],fullPath:f.id??f.path,...f,Actions:St(f.Actions)},`collection_view_${f.id??f.path}`)})},`navigation_${f.id??f.path}`)}),m=r.jsx(ge.Route,{path:"/",element:t}),g=r.jsx(ge.Route,{path:"*",element:r.jsx(gn,{})});return r.jsxs(ge.Routes,{location:s,children:[u,l,m,g,o]})}),mr=(e,t)=>r.jsx(ge.Route,{path:e,element:t.view},"navigation_view_"+e);w.ArrayContainer=lo,w.ArrayContainerItem=co,w.ArrayCustomShapedFieldBinding=In,w.ArrayEnumPreview=Lr,w.ArrayItemOptions=bn,w.ArrayOfMapsPreview=ds,w.ArrayOfReferencesFieldBinding=yn,w.ArrayOfReferencesPreview=Sa,w.ArrayOfStorageComponentsPreview=Ia,w.ArrayOfStringsPreview=Fa,w.ArrayOneOfPreview=Na,w.ArrayPropertyEnumPreview=Ur,w.ArrayPropertyPreview=jr,w.AsyncPreviewComponent=ps,w.AuthControllerContext=fr,w.BlockFieldBinding=Bn,w.BooleanPreview=Da,w.COLLECTION_PATH_SEPARATOR=Lo,w.CircularProgressCenter=or,w.DEFAULT_FIELD_CONFIGS=ir,w.DatePreview=Ta,w.DateTimeFieldBinding=kn,w.DefaultHomePage=dn,w.DeleteConfirmationDialog=vl,w.Drawer=On,w.DrawerNavigationItem=zn,w.EmptyValue=et,w.EntityCollectionRowActions=tr,w.EntityCollectionTable=eo,w.EntityCollectionView=io,w.EntityCollectionViewActions=pn,w.EntityForm=Nn,w.EntityReference=gr,w.EntityView=qr,w.EnumValuesChip=Ie,w.ErrorBoundary=ae,w.ErrorView=ye,w.FieldCaption=Bl,w.FieldHelperText=Ce,w.FireCMS=Ac,w.FireCMSAppBar=An,w.FireCMSLogo=so,w.FormikArrayContainer=nr,w.GeoPoint=Ar,w.IconForView=Zt,w.ImagePreview=ka,w.KeyValueFieldBinding=Cn,w.KeyValuePreview=$r,w.LabelWithIcon=Ee,w.MapFieldBinding=xn,w.MapPropertyPreview=Pa,w.MarkdownFieldBinding=Sn,w.ModeControllerContext=Qt,w.ModeControllerProvider=Kn,w.MultiSelectBinding=uo,w.NavigationCard=sn,w.NavigationCardBinding=cn,w.NavigationGroup=ao,w.NavigationRoutes=_c,w.NotFoundPage=gn,w.NumberPropertyPreview=Qa,w.PropertyConfigBadge=wl,w.PropertyFieldBinding=ot,w.PropertyPreview=we,w.PropertyTableCell=qa,w.ReadOnlyFieldBinding=fo,w.ReferenceFieldBinding=_n,w.ReferencePreview=Oe,w.ReferenceSelectionTable=nn,w.ReferenceWidget=xl,w.RepeatFieldBinding=En,w.Scaffold=wc,w.SearchIconsView=El,w.SelectFieldBinding=po,w.SelectableTable=on,w.SideDialogs=nc,w.SkeletonPropertyComponent=tt,w.SmallNavigationCard=ln,w.SnackbarProvider=Zn,w.StorageThumbnail=_a,w.StorageThumbnailInternal=Ca,w.StorageUploadFieldBinding=mo,w.StringPropertyPreview=Yr,w.SwitchFieldBinding=vn,w.TextFieldBinding=bt,w.UrlComponentPreview=Et,w.Vector=ti,w.VirtualTable=Ka,w.addInitialSlash=Rn,w.applyPermissionsFunctionIfEmpty=Yo,w.buildAdditionalFieldDelegate=Bi,w.buildCollection=wi,w.buildEntityCallbacks=Ei,w.buildEnumLabel=Vo,w.buildEnumValueConfig=Ci,w.buildEnumValues=xi,w.buildFieldConfig=Si,w.buildIdColumn=Ls,w.buildProperties=ki,w.buildPropertiesOrBuilder=_i,w.buildProperty=vi,w.canCreateEntity=ct,w.canDeleteEntity=Wt,w.canEditEntity=Ir,w.defaultDateFormat=jo,w.deleteEntityWithCallbacks=ma,w.enumToObjectEntries=qe,w.flattenObject=Nr,w.fullPathToCollectionSegments=Br,w.getArrayValuesCount=Xo,w.getBracketNotation=hi,w.getCollectionByPathOrId=Mt,w.getCollectionPathsCombinations=Ot,w.getColorForProperty=fi,w.getColorScheme=zo,w.getColumnKeysForProperty=rr,w.getDefaultFieldConfig=Dn,w.getDefaultFieldId=sr,w.getDefaultPropertiesOrder=gi,w.getDefaultValueFor=Gt,w.getDefaultValueForDataType=kr,w.getDefaultValuesFor=kt,w.getEntityImagePreviewPropertyKey=Zo,w.getEntityPreviewKeys=Ho,w.getEntityTitlePropertyKey=Fr,w.getFieldConfig=Ft,w.getFieldId=yo,w.getHashValue=yr,w.getIcon=Jo,w.getIconForProperty=_e,w.getIconForWidget=$t,w.getIdIcon=mi,w.getLabelOrConfigFrom=jt,w.getLastSegment=ei,w.getPropertiesWithPropertiesOrder=Wo,w.getPropertyInPath=Re,w.getRandomId=It,w.getReferenceFrom=je,w.getResolvedPropertyInPath=Sr,w.getSidePanelKey=Yi,w.getValueInPath=Ye,w.hydrateRegExp=$o,w.iconSynonyms=Jt,w.iconsSearch=Ht,w.isDefaultFieldConfigId=Tn,w.isEmptyObject=vr,w.isEnumValueDisabled=ai,w.isHidden=vt,w.isObject=zt,w.isPropertyBuilder=ke,w.isReadOnly=st,w.isReferenceProperty=qo,w.isValidRegExp=ui,w.joinCollectionLists=ea,w.makePropertiesEditable=Ko,w.makePropertiesNonEditable=Ro,w.mergeCollection=ta,w.mergeDeep=De,w.pick=Qo,w.plural=bi,w.printChanged=Tr,w.propertiesToColumns=Za,w.randomColor=ci,w.randomString=lt,w.removeFunctions=br,w.removeInPath=ri,w.removeInitialAndTrailingSlashes=me,w.removeInitialSlash=To,w.removePropsIfExisting=Mo,w.removeTrailingSlash=Do,w.removeUndefined=wr,w.renderSkeletonCaptionText=os,w.renderSkeletonIcon=Gr,w.renderSkeletonImageThumbnail=Vr,w.renderSkeletonText=Le,w.resolveArrayProperty=Xe,w.resolveCollection=Ne,w.resolveCollectionPathIds=hr,w.resolveDefaultSelectedView=Cr,w.resolveEntityView=ko,w.resolveEnumValues=Rl,w.resolveNavigationFrom=fa,w.resolvePermissions=_t,w.resolveProperties=wo,w.resolveProperty=Pe,w.resolvePropertyEnum=vo,w.sanitizeData=oi,w.saveEntityWithCallbacks=Mr,w.segmentsToStrippedPath=Uo,w.serializeRegExp=pi,w.singular=yi,w.slugify=Lt,w.sortProperties=xr,w.stripCollectionPath=Er,w.toKebabCase=ii,w.toSnakeCase=li,w.traverseValueProperty=Yt,w.traverseValuesProperties=_r,w.unslugify=di,w.updateDateAutoValues=Oo,w.useAuthController=We,w.useBrowserTitleAndIcon=Oi,w.useBuildLocalConfigurationPersistence=Ui,w.useBuildModeController=$i,w.useBuildNavigationController=Gi,w.useClearRestoreValue=Te,w.useClipboard=ha,w.useCollectionFetch=Pi,w.useColumnIds=Xr,w.useCustomizationController=oe,w.useDataSource=Me,w.useDataSourceEntityCollectionTableController=to,w.useDebouncedCallback=Ut,w.useDebouncedData=an,w.useEntityFetch=Qr,w.useFireCMSContext=Ae,w.useLargeLayout=Qe,w.useModeController=Or,w.useNavigationController=pe,w.useReferenceDialog=mt,w.useResolvedNavigationFrom=Ti,w.useSelectionController=ro,w.useSideDialogContext=dr,w.useSideDialogsController=xt,w.useSideEntityController=Je,w.useSnackbarController=He,w.useStorageSource=dt,w.useTableSearchHelper=oo,w.useTraceUpdate=Ii,w.useValidateAuthenticator=qi,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
|
|
589
589
|
//# sourceMappingURL=index.umd.js.map
|