@firecms/core 3.0.0-canary.70 → 3.0.0-canary.71

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.umd.js CHANGED
@@ -2,7 +2,7 @@
2
2
  `;function as(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??os}},[e,t])}function Qa(e){const{path:t,collections:o=[],currentFullPath:a}=e,i=me(t).split("/"),n=Lt(i),s=[];for(let l=0;l<n.length;l++){const c=n[l],u=o&&o.find(f=>f.id===c||f.path===c);if(u){const f=u.id??u.path,g=a&&a.length>0?a+"/"+f:f,m=me(me(t).replace(c,"")),h=m.length>0?m.split("/"):[];if(h.length>0){const A=h[0],y=g+"/"+A;if(s.push(new Cr(A,g)),h.length>1){const b=h.slice(1).join("/");if(!u)throw Error("collection not found resolving path: "+u);u.subcollections&&s.push(...Qa({path:b,collections:u.subcollections,currentFullPath:y}))}}break}}return s}const ns="/",is="/c";function ss(e){const{basePath:t=ns,baseCollectionPath:o=is,authController:a,collections:i,collectionPermissions:n,views:s,adminViews:l,viewsOrder:c,userConfigPersistence:u,dataSourceDelegate:f,injectCollections:g}=e,m=d.useRef(),h=d.useRef(),A=d.useRef(),[y,b]=d.useState(!1),[k,_]=d.useState(void 0),[v,x]=d.useState(!0),[C,E]=d.useState(void 0),B=me(t),S=me(o),P=B?`/${B}`:"/",T=B?`/${B}/${S}`:`/${S}`,N=d.useCallback(Q=>B?`/${B}/${nr(Q)}`:`/${nr(Q)}`,[B]),M=d.useCallback(Q=>`${me(o)}/${nr(Q)}`,[o]),L=d.useCallback((Q,R,H,$)=>{let V=[...(Q??[]).map(I=>I.hideFromNavigation?void 0:{url:M(I.id??I.path),type:"collection",name:I.name.trim(),path:I.id??I.path,collection:I,description:I.description?.trim(),group:za(I)}).filter(Boolean),...(R??[]).map(I=>I.hideFromNavigation?void 0:{url:N(Array.isArray(I.path)?I.path[0]:I.path),name:I.name.trim(),type:"view",path:I.path,view:I,description:I.description?.trim(),group:za(I)}).filter(Boolean),...(H??[]).map(I=>I.hideFromNavigation?void 0:{url:N(Array.isArray(I.path)?I.path[0]:I.path),name:I.name.trim(),type:"admin",path:I.path,view:I,description:I.description?.trim(),group:"Admin"}).filter(Boolean)];V=V.sort((I,D)=>I.group!=="Views"&&I.group!=="Admin"&&(D.group==="Views"||D.group==="Admin")?-1:D.group!=="Views"&&D.group!=="Admin"&&(I.group==="Views"||I.group==="Admin")||I.group==="Admin"&&D.group!=="Admin"?1:I.group!=="Admin"&&D.group==="Admin"||I.group==="Views"&&D.group!=="Views"?-1:I.group!=="Views"&&D.group==="Views"?1:0),$&&(V=V.sort((I,D)=>{const ie=$.indexOf(I.path),xe=$.indexOf(D.path);return ie===-1&&xe===-1?0:ie===-1?1:xe===-1?-1:ie-xe}));const z=Object.values(V).map(I=>I.group).filter(Boolean).filter((I,D,ie)=>ie.indexOf(I)===D);return{navigationEntries:V,groups:z}},[N,M]),ee=d.useCallback(async()=>{if(!a.initialLoading){console.debug("Refreshing navigation");try{const[Q=[],R,H=[]]=await Promise.all([cs(i,n,a,f,g),Oa(s,a,f),Oa(l,a,f)]);let $=!1;Va(m.current??[],Q)||(m.current=Q,$=!0),Y(h.current,R)||(h.current=R,$=!0),Y(A.current,H)||(A.current=H,$=!0);const V=L(Q,R,H,c);$&&!Y(k,V)&&_(V)}catch(Q){console.error(Q),E(Q)}x(!1),b(!0)}},[i,n,a.user,a.initialLoading,s,l,L,g]);d.useEffect(()=>{ee()},[ee]);const G=d.useCallback((Q,R=!1)=>{const H=m.current;if(!H)return;const $=Yt(me(Q),H),V=R?u?.getCollectionConfig(Q):void 0,z=$?Me($,V??{}):void 0;let I=z;if(z){const D=z.subcollections,ie=z.callbacks,xe=z.permissions;I={...I,subcollections:I?.subcollections??D,callbacks:I?.callbacks??ie,permissions:I?.permissions??xe}}if(I)return{...z,...I}},[u]),q=d.useCallback(Q=>{const R=m.current;if(R===void 0)throw Error("getCollectionFromPaths: Collections have not been initialised yet");let H=[...R??[]];for(let $=0;$<Q.length;$++){const V=Q[$],z=H.find(I=>I.id===V||I.path===V);if(!z)return;if(H=z.subcollections,$===Q.length-1)return z}},[]),j=d.useCallback(Q=>{const R=m.current;if(R===void 0)throw Error("getCollectionFromIds: Collections have not been initialised yet");let H=[...R??[]];for(let $=0;$<Q.length;$++){const V=Q[$],z=H.find(I=>I.id===V);if(!z)return;if(H=z.subcollections,$===Q.length-1)return z}},[]),O=d.useCallback(Q=>me(Q+"/").startsWith(me(T)+"/"),[T]),te=d.useCallback(Q=>{if(Q.startsWith(T))return Q.replace(T,"");throw Error("Expected path starting with "+T)},[T]),Z=d.useCallback(({path:Q})=>`s/edit/${nr(Q)}`,[]),le=d.useCallback(Q=>{const R=m.current??[];return _r(Q,R)},[]),ne=d.useCallback(Q=>{const R=m.current??[];return Qa({path:Q,collections:R})},[]),re=d.useCallback(Q=>{const H=Q.split("/").filter((V,z)=>z%2===0);H.pop();const $=[];for(let V=1;V<=H.length;V++)$.push(H.slice(0,V));return $.map(V=>q(V)?.id).filter(Boolean)},[ne]),J=d.useCallback(Q=>{let H=m.current;const $=[];for(let V=0;V<Q.length;V++){const z=Q[V],I=H.find(D=>D.id===z);if(!I)throw Error(`Collection with id ${z} not found`);$.push(I.path),H=I.subcollections}return $},[j]);return{collections:m.current,views:h.current,adminViews:A.current,loading:!y||v,navigationLoadingError:C,homeUrl:P,basePath:t,baseCollectionPath:o,initialised:y,getCollection:G,getCollectionFromPaths:q,getCollectionFromIds:j,isUrlCollectionPath:O,urlPathToDataPath:te,buildUrlCollectionPath:M,buildUrlEditCollectionPath:Z,buildCMSUrlPath:N,resolveAliasesFrom:le,topLevelNavigation:k,refreshNavigation:ee,getParentReferencesFromPath:ne,getParentCollectionIds:re,convertIdsToPaths:J}}function ls(e,t){return t?`${me(e)}/${me(t)}`:me(e)}function nr(e){return encodeURIComponent(me(e)).replaceAll("%2F","/").replaceAll("%23","#")}function Ma(e,t){return e.filter(o=>o.permissions?Et(o,t,o.path,null)?.read!==!1:!0).map(o=>o.subcollections?{...o,subcollections:Ma(o.subcollections,t)}:o)}async function cs(e,t,o,a,i){let n=[];return typeof e=="function"?n=await e({user:o.user,authController:o,dataSource:a}):Array.isArray(e)&&(n=e),i&&(n=i(n??[])),n=oa(n,t),n=Ma(n,o),n}async function Oa(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 za(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],i=o.sort((s,l)=>s.id.localeCompare(l.id)),n=a.sort((s,l)=>s.id.localeCompare(l.id));return i.every((s,l)=>ds(s,n[l]))}function ds(e,t){const{subcollections:o,...a}=e,{subcollections:i,...n}=t;return Va(o??[],i??[])?Y(a,n):!1}function ps(){const e=d.useRef({}),t=d.useCallback(h=>{const A=localStorage.getItem(h);return A?JSON.parse(A):{}},[]),o=d.useCallback(h=>{const A=`collection_config::${Dr(h)}`;return e.current[A]?e.current[A]:t(A)},[t]),a=d.useCallback((h,A)=>{const y=`collection_config::${Dr(h)}`;localStorage.setItem(y,JSON.stringify(A));const b=e.current[y],k=Me(b??t(h),A);e.current[y]=Me(e.current[y],k)},[t]),[i,n]=d.useState([]),[s,l]=d.useState([]),[c,u]=d.useState([]);d.useEffect(()=>{n(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 f=d.useCallback(h=>{localStorage.setItem("recently_visited_paths",JSON.stringify(h)),n(h)},[]),g=d.useCallback(h=>{localStorage.setItem("favourite_paths",JSON.stringify(h)),l(h)},[]),m=d.useCallback(h=>{localStorage.setItem("collapsed_groups",JSON.stringify(h)),u(h)},[]);return{onCollectionModified:a,getCollectionConfig:o,recentlyVisitedPaths:i,setRecentlyVisitedPaths:f,favouritePaths:s,setFavouritePaths:g,collapsedGroups:c,setCollapsedGroups:m}}function us(){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,i]=d.useState(o?"dark":"light");d.useEffect(()=>{i(o?"dark":"light"),l(o?"dark":"light")},[o]);const n=d.useCallback(()=>{i("dark"),l("dark")},[]),s=d.useCallback(()=>{i("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"),n()):(u?localStorage.setItem("prefers-dark-mode","false"):localStorage.removeItem("prefers-dark-mode"),s())},[a,e]);return{mode:a,setMode:i,toggleMode:c}}function fs({disabled:e,authController:t,authenticator:o,storageSource:a,dataSourceDelegate:i}){const n=!!o,[s,l]=d.useState(n),[c,u]=d.useState(!1),[f,g]=d.useState(!n||!!t.loginSkipped),m=f&&(!n||!!t.user||!!t.loginSkipped)&&!c;d.useEffect(()=>{t.loginSkipped&&g(!0)},[t.loginSkipped]);const h=d.useRef(),A=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(o instanceof Function&&y&&!Y(h.current?.uid,y.uid)){l(!0);try{await o({user:y,authController:t,dataSourceDelegate:i,storageSource:a})||(t.signOut(),u(!0))}catch(b){u(b),t.signOut()}l(!1),g(!0),h.current=y}else l(!1);!t.initialLoading&&!y&&g(!0)},[e,t,o,i,a]);return d.useEffect(()=>{A()},[A]),{canAccessMainView:m,authLoading:n&&s,notAllowedError:c,authVerified:f}}function nt(){return r.jsx("div",{className:"rounded-full bg-gray-200 bg-opacity-30 dark:bg-opacity-20 w-5 h-2 inline-block"})}const ms=40,hs=100,gs=200;function bt(e){if(e==="tiny")return ms;if(e==="small")return hs;if(e==="medium")return gs;throw Error("Thumbnail size not mapped")}function Xe(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 Ga({size:e,url:t}){const[o,a]=d.useState(!1),i=d.useMemo(()=>bt(e),[e]);if(e==="tiny")return r.jsx("img",{src:t,className:"rounded-md",style:{position:"relative",objectFit:"cover",width:i,height:i,maxHeight:"100%"}},"tiny_image_preview_"+t);const n={maxWidth:"100%",maxHeight:"100%"};return r.jsxs("div",{className:"relative flex items-center justify-center max-w-full max-h-full",style:{width:i,height:i},onMouseEnter:()=>a(!0),onMouseMove:()=>a(!0),onMouseLeave:()=>a(!1),children:[r.jsx("img",{src:t,className:"rounded-md",style:n}),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 It({url:e,previewType:t,size:o,hint:a}){return t?t==="image"?r.jsx(Ga,{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:i=>i.stopPropagation(),className:"flex flex-col items-center justify-center",style:{width:bt(o),height:bt(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(nt,{}):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:i=>{i.preventDefault()},target:"_blank",children:[r.jsx(p.OpenInNewIcon,{size:"small"}),e]})}function it({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=ks(a,t):a.storage?o=Wr(t):o=We()}else if(e.dataType==="array"){const a=e;a.of&&(Array.isArray(a.of)?o=r.jsxs(r.Fragment,{children:[a.of.map((i,n)=>$r(i,n))," "]}):a.of.dataType==="map"&&a.of.properties?o=bs(a.of.properties,t,a.of.previewProperties):a.of.dataType==="string"?a.of.enumValues?o=ws():a.of.storage?o=$r(a.of):o=ys():o=$r(a.of))}else e.dataType==="map"?o=As(e,t):e.dataType==="date"?o=We():e.dataType==="reference"?o=vs():(e.dataType,o=We());return o||null}function As(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,i)=>r.jsx("div",{children:e.properties&&e.properties[a]&&r.jsx(it,{property:e.properties[a],size:"small"})},`map_${a}`))}):r.jsx("table",{className:"table-auto",children:r.jsx("tbody",{children:o&&o.map((a,i)=>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(it,{property:e.properties[a],size:"small"})},`table-cell-${a}`)]},`map_preview_table__${i}`))})})}function bs(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((i,n)=>r.jsx("tr",{children:a&&a.map(s=>r.jsx("th",{children:r.jsx(it,{property:e[s],size:"small"})},`table-cell-${s}`))},`table_${i}_${n}`))})})}function ys(){return r.jsx("div",{className:"flex flex-col gap-2",children:[0,1].map((e,t)=>We(t))})}function ws(){return r.jsx("div",{className:"flex flex-col gap-2",children:[0,1].map((e,t)=>r.jsx(r.Fragment,{children:We(t)}))})}function $r(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(it,{property:e,size:"small"},`i_${a}`)}))},"array_index_"+t)}function Wr(e){const t=e==="tiny"?40:e==="small"?100:200;return r.jsx(p.Skeleton,{width:t,height:t})}function vs(){return r.jsx(p.Skeleton,{width:200,height:100})}function ks(e,t="medium"){return typeof e.url=="boolean"?r.jsxs("div",{style:{display:"flex"},children:[qr(),We()]}):_s(t)}function _s(e){return r.jsx("div",{className:`w-${bt(e)} h-${bt(e)}`,children:qr()})}function We(e,t=120){return r.jsx(p.Skeleton,{width:t},`skeleton_${e}`)}function Cs(e){return r.jsx(p.Skeleton,{height:20})}function qr(){return r.jsx(p.Skeleton,{width:24,height:24})}const Ya=d.memo(ja,xs);function xs(e,t){return e.size===t.size&&e.storagePathOrDownloadUrl===t.storagePathOrDownloadUrl&&e.storeUrl===t.storeUrl}const La={};function ja({storeUrl:e,storagePathOrDownloadUrl:t,size:o}){const[a,i]=d.useState(void 0),n=mt(),[s,l]=d.useState(La[t]);if(d.useEffect(()=>{if(!t)return;let f=!1;return n.getDownloadURL(t).then(function(g){f||(l(g),La[t]=g)}).catch(i),()=>{f=!0}},[t]),!t)return null;const c=s?.metadata?Es(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(It,{previewType:u,url:s.url,size:o,hint:t}):Wr(o)}function Es(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:i}){if(!e)return null;const n=Je(e),s=t!==void 0?Ht(n,t):void 0,l=ta(s),c=ea(n,t);return r.jsxs(p.Chip,{className:a,colorScheme:c,error:!l,outlined:!1,size:o,children:[i,!i&&(l!==void 0?l:String(t))]})}function Hr({propertyKey:e,value:t,property:o,size:a}){if(o.enumValues){const i=t,n=To(o);return r.jsx(Ie,{enumKey:i,enumValues:n.enumValues,size:a})}else if(o.previewAsTag){const i=p.getColorSchemeForSeed(e??"");return r.jsx(ae,{children:r.jsx(p.Chip,{colorScheme:i,size:a,children:t})})}else{if(o.url)return r.jsx(It,{size:a,url:t,previewType:typeof o.url=="string"?o.url:void 0});{if(!t)return r.jsx(r.Fragment,{});const i=t.split(`
3
3
  `);return t&&t.includes(`
4
4
  `)?r.jsx("div",{className:p.cls("overflow-x-scroll",a==="tiny"?"text-sm":""),children:i.map((n,s)=>r.jsxs(d.Fragment,{children:[r.jsx("span",{children:n}),s!==i.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 i=se(),n=Ke({propertyKey:e,property:o,fields:i.propertyConfigs});if(!n.of)throw Error(`You need to specify an 'of' prop (or specify a custom field) in your array property ${e}`);if(n.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 f=n.resolvedProperties[u]??n.resolvedProperties[u]??(Array.isArray(n.of)?n.of[u]:n.of);return f?r.jsx(d.Fragment,{children:r.jsx("div",{className:p.cls(p.defaultBorderMixin,"m-1 border-b last:border-b-0"),children:r.jsx(ae,{children:r.jsx(we,{propertyKey:e,value:c,property:f,size:l})})})},"preview_array_"+u):null})})}function Bs({actions:e,disabled:t,hover:o,collection:a,previewProperties:i,onClick:n,size:s,includeId:l=!0,includeEntityLink:c=!0,entity:u}){const f=gt(),g=at(),m=se(),h=pe(),A=a??h.getCollection(u.path);if(!A)throw Error(`Couldn't find the corresponding collection view for the path: ${u.path}`);const y=dt.useMemo(()=>Ne({collection:A,path:u.path,values:u.values,fields:m.propertyConfigs}),[A]),b=d.useMemo(()=>pa(y,m.propertyConfigs,i,s==="small"||s==="medium"?3:1),[i,y,s]),k=zr(y,m.propertyConfigs),_=ua(y),v=_?y.properties[_]:void 0,x=b.filter(C=>C!==k&&C!==_);return r.jsxs(yt,{onClick:t?void 0:n,hover:t?void 0:o,size:s,children:[v&&r.jsx("div",{className:p.cls("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:_,size:"tiny",value:Ue(u.values,_)})}),r.jsxs("div",{className:"flex flex-col flex-grow w-full m-1",children:[s!=="tiny"&&l&&(u?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:u.id})}):r.jsx(p.Skeleton,{})),k&&r.jsx("div",{className:"my-0.5 text-sm font-medium",children:u?r.jsx(we,{propertyKey:k,value:Ue(u.values,k),property:y.properties[k],size:"medium"}):r.jsx(it,{property:y.properties[k],size:"medium"})}),x&&x.map(C=>{const E=y.properties[C];return E?r.jsx("div",{className:x.length>1?"my-0.5":"my-0",children:u?r.jsx(we,{propertyKey:C,value:Ue(u.values,C),property:E,size:"tiny"}):r.jsx(it,{property:E,size:"tiny"})},"ref_prev_"+C):null})]}),u&&c&&r.jsx(p.Tooltip,{title:`See details for ${u.id}`,className:s!=="tiny"?"self-start":"",children:r.jsx(p.IconButton,{color:"inherit",size:"small",onClick:C=>{C.stopPropagation(),f.onAnalyticsEvent?.("entity_click_from_reference",{path:u.path,entityId:u.id}),g.open({entityId:u.id,path:u.path,collection:A,updateUrl:!0})},children:r.jsx(p.KeyboardTabIcon,{size:"small"})})}),e]})}const Ua=dt.forwardRef(({children:e,hover:t,onClick:o,size:a,style:i,className:n,fullwidth:s=!0,...l},c)=>r.jsx("div",{ref:c,style:{...i,tabindex:0},className:p.cls("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,n),onClick:u=>{o&&(u.preventDefault(),o(u))},...l,children:e}));Ua.displayName="EntityPreviewContainer";const yt=dt.memo(Ua),Ve=dt.memo(function(t){const o=t.reference;return typeof o=="object"&&"isEntityReference"in o&&o.isEntityReference()?r.jsx(Is,{...t}):(console.warn("Reference preview received value of type",typeof o),r.jsx(yt,{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.includeEntityLink===t.includeEntityLink}function Is({disabled:e,reference:t,previewProperties:o,size:a,hover:i,onClick:n,includeEntityLink:s=!0,includeId:l=!0}){const c=se(),f=pe().getCollection(t.path);if(!f){if(c.components?.missingReference)return r.jsx(c.components.missingReference,{path:t.path});throw Error(`Couldn't find the corresponding collection view for the path: ${t.path}`)}return r.jsx(Fs,{reference:t,collection:f,previewProperties:o,size:a,disabled:e,includeEntityLink:s,includeId:l,onClick:n,hover:i})}function Fs({reference:e,collection:t,previewProperties:o,size:a,disabled:i,includeEntityLink:n,includeId:s,onClick:l,hover:c}){const{entity:u,dataLoading:f,dataLoadingError:g}=jr({path:e.path,entityId:e.id,collection:t,useCache:!0});u&&$a.set(e.pathWithId,u);const m=u??$a.get(e.pathWithId);let h;return e?m&&!m.values&&(h=r.jsx(ye,{error:"Reference does not exist",tooltip:e.path})):h=r.jsx(ye,{error:"Reference not set"}),h?r.jsx(yt,{onClick:i?void 0:l,hover:i?void 0:c,size:a,children:h}):f&&!m?r.jsx(yt,{onClick:i?void 0:l,hover:i?void 0:c,size:a,children:r.jsx(p.Skeleton,{})}):m?r.jsx(Bs,{size:a,previewProperties:o,disabled:i,entity:m,collection:t,onClick:l,includeEntityLink:n,includeId:s,hover:c}):r.jsx(yt,{onClick:i?void 0:l,hover:i?void 0:c,size:a,children:r.jsx(ye,{error:"Entity not found"})})}const $a=new Map;function Wa({propertyKey:e,value:t,property:o,size:a}){const i=se(),n=Ke({propertyKey:e,property:o,fields:i.propertyConfigs});if(Array.isArray(n?.of))throw Error("Using array properties instead of single one in `of` in ArrayProperty");if(n?.dataType!=="array"||!n.of||n.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=n.of;return r.jsx("div",{className:"mt-1 mb-1 w-full",children:r.jsx(Ve,{disabled:!u.path,previewProperties:u.previewProperties,size:s,reference:l,includeId:u.includeId,includeEntityLink:u.includeEntityLink})},`preview_array_ref_${e}_${c}`)})})}function qa({propertyKey:e,value:t,property:o,size:a}){const i=se(),n=Ke({propertyKey:e,property:o,fields:i.propertyConfigs});if(Array.isArray(n.of))throw Error("Using array properties instead of single one in `of` in ArrayProperty");if(n.dataType!=="array"||!n.of||n.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:n.of,size:s})},`preview_array_storage_${e}_${c}`))})}function Zr({name:e,value:t,enumValues:o,size:a}){return r.jsx("div",{className:"flex flex-wrap gap-1.5",children:t&&t.map((i,n)=>r.jsx(ae,{children:r.jsx(Ie,{enumKey:i,enumValues:o,size:a!=="medium"?"small":"medium"})},`preview_array_ref_${e}_${n}`))})}function Xr({propertyKey:e,value:t,property:o,size:a}){if(o.dataType!=="array")throw Error("Picked wrong preview component ArrayEnumPreview");const i=o.of;if(!i.enumValues)throw Error("Picked wrong preview component ArrayEnumPreview");return t?r.jsx(Zr,{name:e,value:t,enumValues:i.enumValues,size:a}):null}function Ha({propertyKey:e,value:t,property:o,size:a}){const i=se(),n=Ke({propertyKey:e,property:o,fields:i.propertyConfigs});if(Array.isArray(n.of))throw Error("Using array properties instead of single one in `of` in ArrayProperty");if(!n.of||n.dataType!=="array"||n.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=n.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(Hr,{propertyKey:e,property:s,value:l,size:a})})},`preview_array_strings_${e}_${c}`))})}function Ja({propertyKey:e,value:t,property:o,size:a}){const i=se(),n=Ke({propertyKey:e,property:o,fields:i.propertyConfigs});if(n?.dataType!=="array")throw Error("Picked wrong preview component ArrayPreview");if(!n?.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=n.oneOf.typeField??Ct,u=n.oneOf.valueField??Ut,f=n.oneOf.properties;return r.jsx("div",{className:"flex flex-col",children:s&&s.map((g,m)=>r.jsx(d.Fragment,{children:r.jsx("div",{className:p.cls(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:n.resolvedProperties[m]??f[g[c]],size:l})})})},"preview_array_"+g+"_"+m))})}function Za({propertyKey:e,value:t,property:o,size:a}){if(o.dataType!=="map")throw Error("Picked wrong preview component MapPropertyPreview");const i=o;if(!i.properties||Object.keys(i.properties??{}).length===0)return r.jsx(Kr,{value:t});if(!t)return null;const n=Object.keys(i.properties);return a==="tiny"?r.jsx("div",{className:"w-full flex flex-col space-y-1 md:space-y-2",children:n.map((s,l)=>r.jsx("div",{children:r.jsx(ae,{children:r.jsx(we,{propertyKey:s,value:t[s],property:i.properties[s],size:a})},"map_preview_"+i.name+s+l)},`map_${s}`))}):r.jsx("div",{className:"flex flex-col gap-1 w-full",children:n&&n.map((s,l)=>{const c=i.properties[s];return r.jsxs("div",{className:p.cls(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.cls(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 Kr({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.cls(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.cls(p.defaultBorderMixin,"border-l pl-4"),children:r.jsx(Kr,{value:o})})]},`map_preview_table_${t}}`))}):r.jsx(nt,{})}function Xa({date:e}){const t=se(),o=t?.locale?gi[t?.locale]:void 0,a=t?.dateTimeFormat??aa,i=e?li.format(e,a,{locale:o}):"";return r.jsx(r.Fragment,{children:i})}function Ka({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.cls("text-text-secondary dark:text-text-secondary-dark",t==="tiny"?"text-sm":""),children:o.name})]})}function Ra({value:e,property:t,size:o}){if(t.enumValues){const a=e,i=Je(t.enumValues);return i?r.jsx(Ie,{enumKey:a,enumValues:i,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=se();let a;const{property:i,propertyKey:n,value:s,size:l,height:c,width:u}=t,f=Pe({propertyKey:n,propertyOrBuilder:i,fields:o.propertyConfigs});if(s===void 0||f===null)a=r.jsx(nt,{});else if(f.Preview)a=d.createElement(f.Preview,{propertyKey:n,value:s,property:f,size:l,height:c,width:u,customProps:f.customProps});else if(s===null)a=r.jsx(nt,{});else if(f.dataType==="string"){const g=f;typeof s=="string"?g.url?typeof g.url=="boolean"?a=r.jsx(It,{size:t.size,url:s}):typeof g.url=="string"&&(a=r.jsx(It,{size:t.size,url:s,previewType:g.url})):g.storage?a=r.jsx(Ya,{storeUrl:f.storage?.storeUrl??!1,size:t.size,storagePathOrDownloadUrl:s}):g.markdown?a=r.jsx(p.Markdown,{source:s,size:"small"}):a=r.jsx(Hr,{...t,property:g,value:s}):a=st(n,f.dataType,s)}else if(f.dataType==="array")if(s instanceof Array){const g=f;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 ${n}`);g.of?Array.isArray(g.of)?a=r.jsx(Jr,{...t,value:s,property:f}):g.of.dataType==="reference"?a=r.jsx(Wa,{...t,value:s,property:f}):g.of.dataType==="string"?g.of.enumValues?a=r.jsx(Xr,{...t,value:s,property:f}):g.of.storage?a=r.jsx(qa,{...t,value:s,property:f}):a=r.jsx(Ha,{...t,value:s,property:f}):g.of.dataType==="number"&&g.of.enumValues?a=r.jsx(Xr,{...t,value:s,property:f}):a=r.jsx(Jr,{...t,value:s,property:f}):g.oneOf&&(a=r.jsx(Ja,{...t,value:s,property:f}))}else a=st(n,f.dataType,s);else f.dataType==="map"?typeof s=="object"?a=r.jsx(Za,{...t,property:f}):a=st(n,f.dataType,s):f.dataType==="date"?s instanceof Date?a=r.jsx(Xa,{date:s}):a=st(n,f.dataType,s):f.dataType==="reference"?typeof f.path=="string"?typeof s=="object"&&"isEntityReference"in s&&s.isEntityReference()?a=r.jsx(Ve,{disabled:!f.path,previewProperties:f.previewProperties,includeId:f.includeId,includeEntityLink:f.includeEntityLink,size:t.size,reference:s}):a=st(n,f.dataType,s):a=r.jsx(nt,{}):f.dataType==="boolean"?typeof s=="boolean"?a=r.jsx(Ka,{value:s,size:l,property:f}):a=st(n,f.dataType,s):f.dataType==="number"?typeof s=="number"?a=r.jsx(Ra,{...t,value:s,property:f}):a=st(n,f.dataType,s):a=JSON.stringify(s);return a==null||Array.isArray(a)&&a.length===0?r.jsx(nt,{}):a},Y);function st(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 Ns({propertyKey:e,value:t,property:o,size:a}){const i=se(),n=Ke({propertyKey:e,property:o,fields:i.propertyConfigs});if(Array.isArray(n?.of))throw Error("Using array properties instead of single one in `of` in ArrayProperty");if(n?.dataType!=="array"||!n.of||n.of.dataType!=="map")throw Error("Picked wrong preview component ArrayOfMapsPreview");const s=n.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 f=u;return(!f||!f.length)&&(f=Object.keys(l),a&&(f=f.slice(0,3))),r.jsx("div",{className:"table-auto text-xs",children:r.jsx("div",{children:c&&c.map((g,m)=>r.jsx("div",{className:"border-b last:border-b-0",children:f&&f.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}_${m}`))})})}const Ps=dt.memo(function({builder:t}){const[o,a]=d.useState(!0),[i,n]=d.useState(null);return d.useEffect(()=>{let s=!1;return t.then(l=>{s||(a(!1),n(l))}).catch(l=>{a(!1),console.error(l)}),()=>{s=!0}},[t]),o?r.jsx(p.Skeleton,{}):r.jsx(dt.Fragment,{children:i})});function Rr({entity:e,collection:t,path:o,className:a}){const i=se(),s=d.useMemo(()=>Ne({collection:t,path:o,entityId:e.id,values:e.values,fields:i.propertyConfigs}),[t,o,e,i.propertyConfigs]).properties;return r.jsx("div",{className:"w-full "+a,children:r.jsxs("div",{className:"w-full mb-4",children:[r.jsxs("div",{className:p.cls(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}),i?.entityLinkBuilder&&r.jsx("a",{href:i.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.cls(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 Ts(e){const t=d.useRef(null),{disabled:o,value:a,multiline:i,updateValue:n,focused:s}=e,l=d.useRef(a),[c,u]=d.useState(a),f=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,n(c))},[c,n,a]);return Zt(c,g,!s,2e3),d.useEffect(()=>{t.current&&s&&!f.current?(f.current=!0,t.current.focus({preventScroll:!0}),t.current.selectionStart=t.current.value.length,t.current.selectionEnd=t.current.value.length):f.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:m=>{const h=m.target.value;(i||!h.endsWith(`
5
- `))&&u(h)},onFocus:()=>{f.current=!0},onBlur:()=>{f.current=!1,g()}})}function eo(e){const{name:t,enumValues:o,error:a,internalValue:i,disabled:n,small:s,focused:l,updateValue:c,multiple:u,valueType:f}=e,g=Array.isArray(i)&&u||!Array.isArray(i)&&!u,m=d.useRef(null);d.useEffect(()=>{m.current&&l&&m.current?.focus({preventScroll:!0})},[l,m]);const h=d.useCallback(y=>{if(f==="number")if(u){const b=y.map(k=>parseFloat(k));c(b)}else c(parseFloat(y));else if(f==="string")c(y||null);else throw Error("Missing mapping in TableSelect")},[u,c,f]),A=(y,b)=>u&&Array.isArray(y)?r.jsx(Zr,{value:y,name:t,enumValues:o,size:s?"small":"medium"},`${y}-${b}`):r.jsx(Ie,{enumKey:y,enumValues:o,size:s?"small":"medium"},`${y}-${b}`);return u?r.jsx(p.MultiSelect,{inputRef:m,containerClassName:"w-full h-full",className:"w-full h-full p-0 bg-transparent",position:"item-aligned",disabled:n,padding:!1,includeFocusOutline:!1,value:g?i.map(y=>y.toString()):[],onMultiValueChange:h,renderValue:A,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:m,className:"w-full h-full p-0 bg-transparent",position:"item-aligned",disabled:n,multiple:u,padding:!1,includeFocusOutline:!1,value:g?u?i.map(y=>y.toString()):i?.toString():u?[]:"",onValueChange:h,onMultiValueChange:h,renderValue:A,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 Ds(e){const{align:t,value:o,updateValue:a,focused:i}=e,n=o&&typeof o=="number"?o.toString():"",[s,l]=d.useState(n),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!==n)if(s!=null){const m=parseFloat(s);if(isNaN(m))return;m!=null&&a(m)}else a(null)},[s,o]);Zt(s,u,!i,2e3),d.useEffect(()=>{!i&&n!==s&&l(o!=null?o.toString():null)},[o,i]);const f=d.useRef(null);d.useEffect(()=>{f.current&&i&&f.current.focus({preventScroll:!0})},[i,f]);const g=/^-?[0-9]+[,.]?[0-9]*$/;return r.jsx("input",{ref:f,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:m=>{const h=m.target.value.replace(",",".");h.length===0&&l(null),(g.test(h)||h.startsWith("-"))&&l(h)}})}function Qs(e){const{internalValue:t,updateValue:o,focused:a}=e,i=d.useRef(null);return d.useEffect(()=>{i.current&&a&&i.current.focus({preventScroll:!0})},[a,i]),r.jsx(p.BooleanSwitch,{ref:i,size:"small",value:!!t,onValueChange:o})}function Ms(e){const{locale:t}=se(),{disabled:o,error:a,mode:i,internalValue:n,updateValue:s}=e;return r.jsx(p.DateTimeField,{value:n??void 0,onChange:l=>s(l??null),size:"medium",invisible:!0,className:"w-full h-full",inputClassName:"w-full h-full",mode:i,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 Os({input:e,storage:t,values:o,entityId:a,path:i,property:n,file:s,propertyKey:l}){let c;return typeof e=="function"?(c=await e({path:i,entityId:a,values:o,property:n,file:s,storage:t,propertyKey:l}),c||console.warn("Storage callback returned empty result. Using default name value")):c=en({file:s,input:e,entityId:a,propertyKey:l,path:i}),c||(c=ut()+"_"+s.name),c}function zs({input:e,storage:t,values:o,entityId:a,path:i,property:n,file:s,propertyKey:l}){let c;return typeof e=="function"?(c=e({path:i,entityId:a,values:o,property:n,file:s,storage:t,propertyKey:l}),c||console.warn("Storage callback returned empty result. Using default name value")):c=en({file:s,input:e,entityId:a,propertyKey:l,path:i}),c||(c=ut()+"_"+s.name),c}function en({file:e,input:t,entityId:o,propertyKey:a,path:i}){const n=e.name.split(".").pop();let s=t.replace("{entityId}",o).replace("{propertyKey}",a).replace("{rand}",ut()).replace("{file}",e.name).replace("{file.type}",e.type);if(i&&(s=s.replace("{path}",i)),n){s=s.replace("{file.ext}",n);const l=e.name.replace(`.${n}`,"");s=s.replace("{file.name}",l)}return s||(s=ut()+"_"+e.name),s}function tn({entityId:e,entityValues:t,path:o,value:a,property:i,propertyKey:n,storageSource:s,disabled:l,onChange:c}){const u=i.dataType==="string"?i.storage:i.dataType==="array"&&i.of.dataType==="string"?i.of.storage:void 0,f=i.dataType==="array";if(!u)throw Error("Storage meta must be specified");const g=u?.metadata,m=f?"small":"medium",h=u?.imageCompression,A=(f?a??[]:a?[a]:[]).map(B=>({id:to(),storagePathOrDownloadUrl:B,metadata:g,size:m})),[y,b]=d.useState(a),[k,_]=d.useState(A);d.useEffect(()=>{Y(y,a)||(b(a),_(A))},[A,a,y]);const v=d.useCallback(async B=>{if(u.fileName){const S=await Os({input:u.fileName,storage:u,values:t,entityId:e,path:o,property:i,file:B,propertyKey:n});if(!S||S.length===0)throw Error("You need to return a valid filename");return S}return ut()+"_"+B.name},[e,t,o,i,n,u]),x=d.useCallback(B=>zs({input:u.storagePath,storage:u,values:t,entityId:e,path:o,property:i,file:B,propertyKey:n})??"/",[e,t,o,i,n,u]),C=d.useCallback(async(B,S,P)=>{console.debug("onFileUploadComplete",B,S);let T=B;if(u.storeUrl&&(T=(await s.getDownloadURL(B)).url),u.postProcess&&T&&(T=await u.postProcess(T)),!T){console.warn("uploadPathOrDownloadUrl is null");return}let N;S.storagePathOrDownloadUrl=T,S.metadata=P,N=[...k],N=rn(N),_(N);const M=N.filter(L=>!!L.storagePathOrDownloadUrl).map(L=>L.storagePathOrDownloadUrl);c(f?M:M?M[0]:null)},[k,f,c,u,s]),E=d.useCallback(async B=>{if(!B.length||l)return;let S;if(f)S=[...k,...await Promise.all(B.map(async P=>(h&&ro(P)&&(P=await an(P,h)),{id:to(),file:P,fileName:await v(P),metadata:g,size:m})))];else{let P=B[0];h&&ro(P)&&(P=await an(P,h)),S=[{id:to(),file:P,fileName:await v(P),metadata:g,size:m}]}S=rn(S),_(S)},[l,v,k,g,f,m]);return{internalValue:k,setInternalValue:_,storage:u,fileNameBuilder:v,storagePathBuilder:x,onFileUploadComplete:C,onFilesAdded:E,multipleFilesSupported:f}}function rn(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 to(){return Math.floor(Math.random()*Math.floor(Number.MAX_SAFE_INTEGER))}const on={"image/jpeg":"JPEG","image/png":"PNG","image/webp":"WEBP"},ro=e=>on[e.type]?on[e.type]:null,Vs=100,an=(e,t)=>new Promise(o=>{const a=t.quality===void 0?Vs:t.quality,i=a>=0&&a<=100?a:100,n=ro(e);if(!n)throw Error("resizeAndCompressImage: Unsupported image format");di.imageFileResizer(e,t.maxWidth||Number.MAX_VALUE,t.maxHeight||Number.MAX_VALUE,n,i,0,s=>o(s),"file")});function nn({storagePath:e,entry:t,metadata:o,onFileUploadComplete:a,imageSize:i,simple:n}){const s=mt(),l=Ze(),[c,u]=d.useState(),[f,g]=d.useState(!1),m=d.useRef(!1),h=d.useRef(!1),A=d.useCallback((y,b)=>{h.current||(h.current=!0,u(void 0),g(!0),s.uploadFile({file:y,fileName:b,path:e,metadata:o}).then(async({path:k})=>{console.debug("Upload successful",k),await a(k,t,o),m.current&&g(!1)}).catch(k=>{console.warn("Upload error",k),m.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(()=>(m.current=!0,t.file&&A(t.file,t.fileName),()=>{m.current=!1}),[t.file,t.fileName,A]),n?r.jsx("div",{className:`m-4 w-${i} h-${i}`,children:f&&r.jsx(p.Skeleton,{className:`w-${i} h-${i}`})}):r.jsxs("div",{className:p.cls(p.paperMixin,"relative m-4 border-box flex items-center justify-center",`min-w-[${i}px] min-h-[${i}px]`),children:[f&&r.jsx(p.Skeleton,{className:"w-full h-full"}),c&&r.jsx(ye,{title:"Error uploading file",error:c})]})}function sn({showError:e,disabled:t,showExpandIcon:o,selected:a,openPopup:i,children:n}){const s=d.useRef(null),l=d.useCallback(()=>{if(i){const u=s&&s?.current?.getBoundingClientRect();i(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&&n,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(ra,{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 Gs="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",Ys="pt-0 border-2 border-solid",Ls="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",js="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 Us(e){const{propertyKey:t,error:o,selected:a,openPopup:i,value:n,disabled:s,property:l,entity:c,path:u,previewSize:f,updateValue:g}=e,m=mt(),{internalValue:h,setInternalValue:A,onFilesAdded:y,storage:b,onFileUploadComplete:k,storagePathBuilder:_,multipleFilesSupported:v}=tn({entityValues:c.values,entityId:c.id,path:u,property:l,propertyKey:t,storageSource:m,onChange:g,value:n,disabled:s});return r.jsx($s,{internalValue:h,setInternalValue:A,name:t,disabled:s,autoFocus:!1,openPopup:i,error:o,selected:a,property:l,onChange:g,entity:c,storagePathBuilder:_,storage:b,multipleFilesSupported:v,onFilesAdded:y,onFileUploadComplete:k,previewSize:f})}function $s({property:e,name:t,internalValue:o,setInternalValue:a,openPopup:i,entity:n,selected:s,error:l,onChange:c,multipleFilesSupported:u,previewSize:f,disabled:g,autoFocus:m,storage:h,onFilesAdded:A,onFileUploadComplete:y,storagePathBuilder:b}){const[k,_]=d.useState(!1),v=u&&f==="medium"?"small":f;if(u){const O=e;if(Array.isArray(O.of))throw Error("Using array properties instead of single one in `of` in ArrayProperty");if(O.of){if(O.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 x=h?.metadata,C=!!o,E=Ze(),{open:B,getRootProps:S,getInputProps:P,isDragActive:T,isDragAccept:N,isDragReject:M}=qo.useDropzone({accept:h.acceptedFiles?h.acceptedFiles.map(O=>({[O]:[]})).reduce((O,te)=>({...O,...te}),{}):void 0,disabled:g,maxSize:h.maxSize,noClick:!0,noKeyboard:!0,onDrop:A,onDropRejected:(O,te)=>{for(const Z of O)for(const le of Z.errors)E.open({type:"error",message:`Error uploading file: File is larger than ${h.maxSize} bytes`})}}),{...L}=S(),ee=u?"Drag 'n' drop some files here, or click here to edit":"Drag 'n' drop a file here, or click here edit",G=u?e.of:e,q=d.useMemo(()=>bt(v),[v]),j=!g&&l;return r.jsxs("div",{...L,onMouseEnter:()=>_(!0),onMouseMove:()=>_(!0),onMouseLeave:()=>_(!1),className:p.cls(Gs,"relative w-full h-full flex",`justify-${C?"start":"center"}`,T?Ys:"",N?Ls:"",M?js:""),children:[r.jsx("input",{autoFocus:m,...P()}),o.map((O,te)=>{let Z;return O.storagePathOrDownloadUrl?Z=r.jsx(Ws,{property:G,value:O.storagePathOrDownloadUrl,entity:n,size:v},`storage_preview_${te}`):O.file&&(Z=r.jsx(nn,{entry:O,metadata:x,storagePath:b(O.file),onFileUploadComplete:y,imageSize:q,simple:!0},`storage_progress_${te}`)),Z}),!o&&r.jsx("div",{className:"flex-grow m-2 max-w-[200px]",onClick:B,children:r.jsx(p.Typography,{className:"text-gray-400 dark:text-gray-600",variant:"body2",align:"center",children:ee})}),r.jsx(sn,{showError:j,disabled:g,showExpandIcon:!0,selected:s,openPopup:g?void 0:i,children:r.jsx(p.IconButton,{color:"inherit",size:"small",onClick:B,children:r.jsx(p.EditIcon,{size:"small",className:"text-gray-500"})})})]})}function Ws({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 ln(e){const t=se(),o=pe(),{path:a}=e,i=o.getCollection(a);if(!i){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(qs,{...e,collection:i})}const qs=d.memo(function(t){const{name:o,internalValue:a,updateValue:i,multiselect:n,path:s,size:l,previewProperties:c,title:u,disabled:f,forceFilter:g,collection:m,includeId:h,includeEntityLink:A}=t,y=d.useCallback(B=>{i(B?$e(B):null)},[i]),b=d.useCallback(B=>{i(B.map(S=>$e(S)))},[i]),k=a?Array.isArray(a)?a.map(B=>B.id):a.id?[a.id]:[]:[],_=At({multiselect:n,path:s,collection:m,onMultipleEntitiesSelected:b,onSingleEntitySelected:y,selectedEntityIds:k,forceFilter:g}),v=d.useCallback(()=>{f||_.open()},[f,_]),x=!a||Array.isArray(a)&&a.length===0,C=()=>a&&!Array.isArray(a)&&a.isEntityReference&&a.isEntityReference()?r.jsx(Ve,{onClick:f?void 0:v,size:Xe(l),reference:a,hover:!f,disabled:!s,previewProperties:c,includeId:h,includeEntityLink:A}):r.jsx(yt,{onClick:f?void 0:v,size:Xe(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((B,S)=>r.jsx("div",{className:"w-full my-0.5",children:r.jsx(Ve,{onClick:f?void 0:v,size:"tiny",reference:B,hover:!f,disabled:!s,previewProperties:c,includeId:h,includeEntityLink:A})},`preview_array_ref_${o}_${S}`))}):r.jsx(ye,{error:"Data is not an array of references"});return m?r.jsxs("div",{className:"w-full group",children:[a&&!n&&C(),a&&n&&E(),x&&r.jsxs(p.Button,{onClick:v,size:"small",variant:"outlined",color:"primary",children:["Edit ",u]})]}):r.jsx(ye,{error:"The specified collection does not exist"})},Y);Se.addMethod(Se.array,"uniqueInArray",function(e=o=>o,t){return this.test("uniqueInArray",t,o=>!o||o.length===new Set(o.map(e)).size)});function cn(e,t,o){const a={};return Object.entries(t).forEach(([i,n])=>{a[i]=Ft({property:n,customFieldValidator:o,name:i,entityId:e})}),Se.object().shape(a)}function Ft(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 Js(e);if(t.dataType==="number")return Zs(e);if(t.dataType==="boolean")return el(e);if(t.dataType==="map")return Hs(e);if(t.dataType==="array")return rl(e);if(t.dataType==="date")return Ks(e);if(t.dataType==="geopoint")return Xs(e);if(t.dataType==="reference")return Rs(e);throw console.error("Unsupported data type in yup mapping",t),Error("Unsupported data type in yup mapping")}function Hs({property:e,entityId:t,customFieldValidator:o,name:a}){const i={},n=e.validation;e.properties&&Object.entries(e.properties).forEach(([l,c])=>{i[l]=Ft({property:c,parentProperty:e,customFieldValidator:o,name:`${a}[${l}]`,entityId:t})});const s=Se.object().shape(i);return n?.required?s.required(n?.requiredMessage?n.requiredMessage:"Required").nullable(!0):Se.object().shape(s.fields).default(void 0).notRequired().nullable(!0)}function Js({property:e,parentProperty:t,customFieldValidator:o,name:a,entityId:i}){let n=Se.string();const s=e.validation;if(e.enumValues){s?.required&&(n=n.required(s?.requiredMessage?s.requiredMessage:"Required"));const l=Je(e.enumValues);n=n.oneOf((s?.required?l:[...l,null]).map(c=>c?.id??null)).nullable(!0)}if(s){if(n=s.required?n.required(s?.requiredMessage?s.requiredMessage:"Required").nullable(!0):n.notRequired().nullable(!0),s.unique&&o&&a&&(n=n.test("unique","This value already exists and should be unique",(l,c)=>o({name:a,property:e,parentProperty:t,value:l,entityId:i}))),(s.min||s.min===0)&&(n=n.min(s.min,`${e.name} must be min ${s.min} characters long`)),(s.max||s.max===0)&&(n=n.max(s.max,`${e.name} must be max ${s.max} characters long`)),s.matches){const l=typeof s.matches=="string"?sa(s.matches):s.matches;l&&(n=n.matches(l,s.matchesMessage?{message:s.matchesMessage}:void 0))}s.trim&&(n=n.trim()),s.lowercase&&(n=n.lowercase()),s.uppercase&&(n=n.uppercase()),e.email&&(n=n.email(`${e.name} must be an email`)),e.url&&(n=n.url(`${e.name} must be a url`))}else n=n.notRequired().nullable(!0);return n}function Zs({property:e,parentProperty:t,customFieldValidator:o,name:a,entityId:i}){const n=e.validation;let s=Se.number().typeError("Must be a number");return n?(s=n.required?s.required(n.requiredMessage?n.requiredMessage:"Required").nullable(!0):s.notRequired().nullable(!0),n.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:i}))),(n.min||n.min===0)&&(s=s.min(n.min,`${e.name} must be higher or equal to ${n.min}`)),(n.max||n.max===0)&&(s=s.max(n.max,`${e.name} must be lower or equal to ${n.max}`)),(n.lessThan||n.lessThan===0)&&(s=s.lessThan(n.lessThan,`${e.name} must be higher than ${n.lessThan}`)),(n.moreThan||n.moreThan===0)&&(s=s.moreThan(n.moreThan,`${e.name} must be lower than ${n.moreThan}`)),n.positive&&(s=s.positive(`${e.name} must be positive`)),n.negative&&(s=s.negative(`${e.name} must be negative`)),n.integer&&(s=s.integer(`${e.name} must be an integer`))):s=s.notRequired().nullable(!0),s}function Xs({property:e,parentProperty:t,customFieldValidator:o,name:a,entityId:i}){let n=Se.object();const s=e.validation;return s?.unique&&o&&a&&(n=n.test("unique","This value already exists and should be unique",l=>o({name:a,property:e,parentProperty:t,value:l,entityId:i}))),s?.required?n=n.required(s.requiredMessage).nullable(!0):n=n.notRequired().nullable(!0),n}function Ks({property:e,parentProperty:t,customFieldValidator:o,name:a,entityId:i}){if(e.autoValue)return Se.object().nullable();let n=Se.date();const s=e.validation;return s?(n=s.required?n.required(s?.requiredMessage?s.requiredMessage:"Required"):n.notRequired(),s.unique&&o&&a&&(n=n.test("unique","This value already exists and should be unique",l=>o({name:a,property:e,parentProperty:t,value:l,entityId:i}))),s.min&&(n=n.min(s.min,`${e.name} must be after ${s.min}`)),s.max&&(n=n.max(s.max,`${e.name} must be before ${s.min}`))):n=n.notRequired(),n.transform(l=>l instanceof Date?l:null).nullable()}function Rs({property:e,parentProperty:t,customFieldValidator:o,name:a,entityId:i}){let n=Se.object();const s=e.validation;return s?(n=s.required?n.required(s?.requiredMessage?s.requiredMessage:"Required").nullable(!0):n.notRequired().nullable(!0),s.unique&&o&&a&&(n=n.test("unique","This value already exists and should be unique",l=>o({name:a,property:e,parentProperty:t,value:l,entityId:i})))):n=n.notRequired().nullable(!0),n}function el({property:e,parentProperty:t,customFieldValidator:o,name:a,entityId:i}){let n=Se.boolean();const s=e.validation;return s?(n=s.required?n.required(s?.requiredMessage?s.requiredMessage:"Required").nullable(!0):n.notRequired().nullable(!0),s.unique&&o&&a&&(n=n.test("unique","This value already exists and should be unique",l=>o({name:a,property:e,parentProperty:t,value:l,entityId:i})))):n=n.notRequired().nullable(!0),n}function tl(e){return e.validation?.uniqueInArray?!0:e.dataType==="map"&&e.properties?Object.entries(e.properties).filter(([t,o])=>o.validation?.uniqueInArray):!1}function rl({property:e,parentProperty:t,customFieldValidator:o,name:a,entityId:i}){let n=Se.array();if(e.of)if(Array.isArray(e.of)){const l=e.of.map((c,u)=>({[`${a}[${u}]`]:Ft({property:c,parentProperty:e,entityId:i})})).reduce((c,u)=>({...c,...u}),{});return Se.array().of(Se.mixed().test("Dynamic object validation","Dynamic object validation error",(c,u)=>Ue(l,u.path).validate(c)))}else{n=n.of(Ft({property:e.of,parentProperty:e,entityId:i}));const l=tl(e.of);l&&(typeof l=="boolean"?n=n.uniqueInArray(c=>c,`${e.name} should have unique values within the array`):Array.isArray(l)&&l.forEach(([c,u])=>{n=n.uniqueInArray(f=>f&&f[c],`${e.name} → ${u.name??c}: should have unique values within the array`)}))}const s=e.validation;return s?(n=s.required?n.required(s?.requiredMessage?s.requiredMessage:"Required").nullable(!0):n.notRequired().nullable(!0),(s.min||s.min===0)&&(n=n.min(s.min,`${e.name} should be min ${s.min} entries long`)),s.max&&(n=n.max(s.max,`${e.name} should be max ${s.max} entries long`))):n=n.notRequired().nullable(!0),n}function ir(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 ol=({justifyContent:e,scrollable:t,faded:o,fullHeight:a,children:i})=>r.jsx("div",{className:p.cls("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:i}),sr=d.memo(function({children:t,actions:o,size:a,selected:i,disabled:n,disabledTooltip:s,saved:l,error:c,align:u,allowScroll:f,removePadding:g,fullHeight:m,onSelect:h,width:A,hideOverflow:y=!0,showExpandIcon:b=!0}){const[k,_]=Wo(),v=d.useRef(null),x=d.useMemo(()=>ir(a),[a]),[C,E]=d.useState(!1),[B,S]=d.useState(l),P=!n&&!!c;d.useEffect(()=>{l&&S(!0);const le=setTimeout(()=>{S(!1)},800);return()=>{clearTimeout(le)}},[l]);let T=0;if(!g)switch(a){case"l":case"xl":T=4;break;case"m":T=2;break;case"s":default:T=1;break}let N;switch(u){case"right":N="flex-end";break;case"center":N="center";break;case"left":default:N="flex-start"}const M=d.useCallback(()=>{if(!h)return;const le=v&&v?.current?.getBoundingClientRect();n?h(void 0):!i&&le&&h(le)},[v,h,i,n]),L=d.useCallback(le=>{M(),le.stopPropagation()},[M]),ee=d.useMemo(()=>_?_.height>x:!1,[_,x]),G=!P&&i,q=!n&&f&&ee,j=!n&&!f&&ee,O=d.useCallback(()=>E(!0),[]),te=d.useCallback(()=>E(!1),[]),Z=P?"border-red-500":B?"border-green-500":G?"border-primary":"border-transparent";return r.jsxs("div",{className:p.cls("transition-colors duration-100 ease-in-out",`flex relative h-full rounded-md p-${T} border border-4 border-opacity-75`,C&&!n?"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":"",G?"bg-gray-50 dark:bg-gray-900":"",Z),ref:v,style:{justifyContent:N,alignItems:n||!ee?"center":void 0,width:A??"100%",textAlign:u},tabIndex:i||n?void 0:0,onFocus:L,onMouseEnter:O,onMouseMove:O,onMouseLeave:te,children:[r.jsxs(ae,{children:[m&&!j&&t,(!m||j)&&r.jsx(ol,{fullHeight:m??!1,justifyContent:N,scrollable:q??!1,faded:j,children:!m&&r.jsx("div",{ref:k,style:{display:"flex",width:"100%",justifyContent:N,height:m?"100%":void 0},children:t})})]}),o,n&&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),oo=d.createContext({}),dn=()=>d.useContext(oo);function Qe({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 al(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 pn=d.memo(function({propertyKey:t,customFieldValidator:o,value:a,property:i,align:n,width:s,height:l,path:c,entity:u,readonly:f,disabled:g,enablePopupIcon:m=!0}){const{onValueChange:h,size:A,selectedCell:y,select:b,setPopupCell:k}=dn(),_=y?.propertyKey===t&&y?.entity.path===u.path&&y?.entity.id===u.id,[v,x]=d.useState(a),C=d.useRef(a),[E,B]=d.useState(),[S,P]=d.useState(),[T,N]=d.useState(!1),M=d.useCallback(()=>{N(!0),setTimeout(()=>{N(!1)},100)},[]),L=!!i.Field,ee=!!i.Preview,G=pt(i),q=typeof i.disabled=="object"?i.disabled.disabledMessage:void 0,j=f||g||!!i.disabled,O=d.useMemo(()=>Ft({property:i,entityId:u.id,customFieldValidator:o,name:t}),[u.id,i,t]);d.useEffect(()=>{Y(a,C.current)||(P(void 0),x(a),C.current=a,M())},[M,a]);const te=I=>{Y(I,C.current)||(N(!1),O.validate(I).then(()=>{if(P(void 0),C.current=I,h)try{h({value:I,propertyKey:t,setError:B,onValueUpdated:M,data:u})}catch(D){console.error("onValueChange error",D),B(D)}}).catch(D=>{P(D)}))};d.useEffect(()=>{O.validate(v).then(()=>P(void 0)).catch(P)},[v,O,t,i,u]);const Z=I=>{let D;I===void 0?D=null:D=I,x(D),te(D)};Qe({property:i,value:v,setValue:Z});const le=d.useCallback(I=>{b(I?{width:s,height:l,entity:u,cellRect:I,propertyKey:t}:void 0)},[u,l,t,b,s]),ne=I=>{k&&k(I?{width:s,height:l,entity:u,cellRect:I,propertyKey:t}:void 0)};let re,J=!1,Q=!1,R=!0,H=!1,$=!1,V=!0;const z=!j&&E;if(f||G)return r.jsx(sr,{size:A,width:s,saved:T,value:v,align:n??"left",fullHeight:!1,disabledTooltip:q??(G?"Read only":void 0),disabled:!0,children:r.jsx(we,{width:s,height:ir(A),propertyKey:t,property:i,value:v,size:Xe(A)})},`${t}_${u.path}_${u.id}`);if(!L&&(!ee||_)){if(al(i))re=r.jsx(Us,{error:S??E,disabled:j,focused:_,selected:_,openPopup:k?ne:void 0,property:i,entity:u,path:c,value:v,previewSize:Xe(A),updateValue:Z,propertyKey:t}),V=!1,Q=!0,$=!0,H=!0;else if(_&&i.dataType==="number"){const D=i;D.enumValues?(re=r.jsx(eo,{name:t,multiple:!1,disabled:j,focused:_,valueType:"number",small:Xe(A)!=="medium",enumValues:D.enumValues,error:S??E,internalValue:v,updateValue:Z}),$=!0):(re=r.jsx(Ds,{align:n,error:S??E,focused:_,disabled:j,value:v,updateValue:Z}),J=!0)}else if(_&&i.dataType==="string"){const D=i;if(D.enumValues)re=r.jsx(eo,{name:t,multiple:!1,focused:_,disabled:j,valueType:"string",small:Xe(A)!=="medium",enumValues:D.enumValues,error:S??E,internalValue:v,updateValue:Z}),$=!0;else if(!D.storage){const ie=!!D.multiline||!!D.markdown;re=r.jsx(Ts,{error:S??E,disabled:j,multiline:ie,focused:_,value:v,updateValue:Z}),J=!0}}else if(i.dataType==="boolean")re=r.jsx(Qs,{error:S??E,disabled:j,focused:_,internalValue:v,updateValue:Z});else if(i.dataType==="date")re=r.jsx(Ms,{name:t,error:S??E,disabled:j,mode:i.mode,focused:_,internalValue:v,updateValue:Z}),$=!0,R=!1,J=!1;else if(i.dataType==="reference")typeof i.path=="string"&&(re=r.jsx(ln,{name:t,internalValue:v,updateValue:Z,disabled:j,size:A,path:i.path,multiselect:!1,previewProperties:i.previewProperties,includeId:i.includeId,includeEntityLink:i.includeEntityLink,title:i.name,forceFilter:i.forceFilter})),J=!1;else if(i.dataType==="array"){const D=i;if(!D.of&&!D.oneOf)throw Error(`You need to specify an 'of' or 'oneOf' prop (or specify a custom field) in your array property ${t}`);D.of&&!Array.isArray(D.of)&&(D.of.dataType==="string"||D.of.dataType==="number"?_&&D.of.enumValues&&(re=r.jsx(eo,{name:t,multiple:!0,disabled:j,focused:_,small:Xe(A)!=="medium",valueType:D.of.dataType,enumValues:D.of.enumValues,error:S??E,internalValue:v,updateValue:Z}),J=!0,$=!0,R=!1):D.of.dataType==="reference"&&(typeof D.of.path=="string"&&(re=r.jsx(ln,{name:t,disabled:j,internalValue:v,updateValue:Z,size:A,multiselect:!0,path:D.of.path,previewProperties:D.of.previewProperties,title:D.name,forceFilter:D.of.forceFilter,includeId:D.of.includeId,includeEntityLink:D.of.includeEntityLink})),J=!1))}}return re||(J=!1,Q=m&&_&&!re&&!j&&!G,re=r.jsx(we,{width:s,height:l,propertyKey:t,value:v,property:i,size:Xe(A)})),r.jsx(sr,{size:A,width:s,onSelect:le,selected:_,disabled:j||G,disabledTooltip:q??"Disabled",removePadding:H,fullHeight:$,saved:T,error:S??E,align:n,allowScroll:J,showExpandIcon:Q,value:v,hideOverflow:R,actions:V&&r.jsx(sn,{showError:z,disabled:j,showExpandIcon:Q,selected:_,openPopup:j?void 0:ne}),children:re},`cell_${t}_${u.path}_${u.id}`)},nl);function nl(e,t){return e.height===t.height&&e.propertyKey===t.propertyKey&&e.align===t.align&&e.width===t.width&&Y(e.property,t.property)&&Y(e.value,t.value)&&Y(e.entity.id,t.entity.id)&&Y(e.entity.values,t.entity.values)}const lr=function({entity:t,collection:o,fullPath:a,width:i,frozen:n,isSelected:s,selectionEnabled:l,size:c,highlightEntity:u,onCollectionChange:f,unhighlightEntity:g,actions:m=[],hideId:h,selectionController:A}){const y=Oe(),b=Ce(),k=d.useCallback(B=>{A?.toggleEntitySelection(t)},[t,A?.toggleEntitySelection]),_=d.useCallback(B=>{B.stopPropagation(),A?.toggleEntitySelection(t)},[t,A?.toggleEntitySelection]),v=m.length>0,x=m.some(B=>B.collapsed||B.collapsed===void 0),C=m.filter(B=>B.collapsed||B.collapsed===void 0),E=m.filter(B=>B.collapsed===!1);return r.jsxs("div",{onClick:_,className:p.cls("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",n?"sticky left-0":""),style:{width:i,position:n?"sticky":"initial",left:n?0:"initial",contain:"strict"},children:[(v||l)&&r.jsxs("div",{className:"w-34 flex justify-center",children:[E.map((B,S)=>r.jsx(p.Tooltip,{title:B.name,children:r.jsx(p.IconButton,{onClick:P=>{P.stopPropagation(),B.onClick({entity:t,fullPath:a,collection:o,context:b,selectionController:A,highlightEntity:u,unhighlightEntity:g,onCollectionChange:f})},size:y?"medium":"small",children:B.icon})},S)),x&&r.jsx(p.Menu,{trigger:r.jsx(p.IconButton,{size:y?"medium":"small",children:r.jsx(p.MoreVertIcon,{})}),children:C.map((B,S)=>r.jsxs(p.MenuItem,{onClick:P=>{P.stopPropagation(),B.onClick({entity:t,fullPath:a,collection:o,context:b,selectionController:A,highlightEntity:u,unhighlightEntity:g,onCollectionChange:f})},children:[B.icon,B.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:B=>{B.stopPropagation()},className:"font-mono select-all",variant:"caption",color:"secondary",children:[" ",t.id," "]}):r.jsx(p.Skeleton,{})})]})};function il({actions:e,actionsStart:t,loading:o,onSizeChanged:a,onTextSearch:i,onTextSearchClick:n,size:s,textSearchLoading:l,title:c}){const u=d.useRef(null),f=Oe(),g=d.useRef(!1);d.useEffect(()=>{u.current&&g.current&&!l&&u.current.focus(),g.current=l??!1},[l]);const m=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.cls(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}),m,t]}),r.jsxs("div",{className:"flex items-center gap-2",children:[f&&r.jsx("div",{className:"w-[22px]",children:o&&r.jsx(p.CircularProgress,{size:"small"})}),(i||n)&&r.jsx(p.SearchBar,{inputRef:u,loading:l,disabled:!!n,onClick:n,onTextSearch:n?void 0:i,expandable:!0},"search-bar"),e]})]})}function sl(e){return e.dataType==="boolean"?"center":e.dataType==="number"?e.enumValues?"left":"right":e.dataType==="date"?"right":"left"}function un(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:un(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 ao(e){return`subcollection:${e.id??e.path}`}const no="collectionGroupParent";function io(e,t){return d.useMemo(()=>{if(e.propertiesOrder){const o=fn(e,e.propertiesOrder);return e.collectionGroup&&o.push({key:no,disabled:!0}),o}return ll(e,t)},[e,t])}function fn(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?cr(a,o):[{key:o,disabled:!!a.disabled||!!a.readOnly}]:e.additionalFields?.find(n=>n.key===o)?[{key:o,disabled:!0}]:e.subcollections&&e.subcollections.find(s=>ao(s)===o)?[{key:o,disabled:!0}]:e.collectionGroup&&o===no?[{key:o,disabled:!0}]:[null]}).filter(Boolean)}function ll(e,t){const o=Object.keys(e.properties),a=e.additionalFields??[],i=e.subcollections??[],n=[...o,...a.map(s=>s.key)];if(t){const s=i.map(l=>ao(l));n.push(...s.filter(l=>!n.includes(l)))}return e.collectionGroup&&n.push(no),fn(e,n)}function cr(e,t,o){return e.dataType==="map"&&e.spreadChildren&&e.properties?Object.entries(e.properties).flatMap(([a,i])=>cr(i,`${t}.${a}`,o||!!e.disabled||!!e.readOnly)):[{key:t,disabled:o||!!e.disabled||!!e.readOnly}]}function cl(e){return{key:"id_ewcfedcswdf3",width:e?160:130,title:"ID",resizable:!1,frozen:e??!1,headerAlign:"center",align:"center"}}function mn({properties:e,sortable:t,forceFilter:o,AdditionalHeaderWidget:a}){const i=!!o;return Object.entries(e).flatMap(([n,s])=>cr(s,n)).map(({key:n,disabled:s})=>{const l=Mr(e,n);if(!l)throw Error("Internal error: no property found in path "+n);const c=hn(l);return{key:n,align:sl(l),icon:_e(l,"small"),title:l.name??n,sortable:t,filter:!i&&c,width:un(l),resizable:!0,custom:{resolvedProperty:l,disabled:s},AdditionalHeaderWidget:a?({onHover:u})=>r.jsx(a,{property:l,propertyKey:n,onHover:u}):void 0}})}function hn(e,t=!1){return t?["string","number","date","reference"].includes(e.dataType):e.dataType==="array"?e.of?hn(e.of,!0):!1:["string","number","boolean","date","reference","array"].includes(e.dataType)}function Nt({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 dl=d.memo(function({resizeHandleRef:t,columnIndex:o,isResizingIndex:a,sort:i,onColumnSort:n,onFilterUpdate:s,filter:l,column:c,onClickResizeColumn:u,createFilterField:f,AdditionalHeaderWidget:g}){const[m,h]=d.useState(!1),[A,y]=d.useState(!1),[b,k]=d.useState(!1),_=d.useCallback(B=>{y(!0)},[]),v=d.useCallback((B,S)=>{s(c,B),S!==void 0&&y(S)},[c,s]),x=a===o,E=!(a!==o&&a>0)&&(m||x);return r.jsx(ae,{children:r.jsxs("div",{className:p.cls("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:m||A}),c.sortable&&(i||E||A)&&r.jsx(p.Badge,{color:"secondary",invisible:!i,children:r.jsxs(p.IconButton,{size:"small",className:m||A?"bg-white dark:bg-gray-950":void 0,onClick:()=>{n(c.key)},children:[!i&&r.jsx(p.ArrowUpwardIcon,{}),i==="asc"&&r.jsx(p.ArrowUpwardIcon,{}),i==="desc"&&r.jsx(p.ArrowUpwardIcon,{className:"rotate-180"})]})})]}),c.filter&&f&&r.jsx("div",{children:r.jsx(p.Badge,{color:"secondary",invisible:!l,children:r.jsx(p.Popover,{open:A,onOpenChange:y,className:b?"hidden":void 0,modal:!0,trigger:r.jsx(p.IconButton,{className:m||A?"bg-white dark:bg-gray-950":void 0,size:"small",onClick:_,children:r.jsx(p.FilterListIcon,{size:"small"})}),children:r.jsx(pl,{column:c,filter:l,onHover:m,onFilterUpdate:v,createFilterField:f,hidden:b,setHidden:k})})})}),c.resizable&&r.jsx("div",{ref:t,className:p.cls("absolute h-full w-[6px] top-0 right-0 cursor-col-resize",E&&"bg-gray-300 dark:bg-gray-700"),onMouseDown:u?()=>u(o,c):void 0})]})})},Y);function pl({column:e,onFilterUpdate:t,filter:o,onHover:a,createFilterField:i,hidden:n,setHidden:s}){const l=e.key,[c,u]=d.useState(o);if(d.useEffect(()=>{u(o)},[o]),!e.filter)return null;const f=()=>{t(c,!1)},g=A=>{t(void 0,!1)},m=!!o,h=i({id:l,filterValue:c,setFilterValue:u,column:e,hidden:n,setHidden:s});return h?r.jsxs("form",{noValidate:!0,onSubmit:A=>{A.stopPropagation(),A.preventDefault(),f()},className:"text-gray-900 dark:text-white",children:[r.jsx("div",{className:p.cls(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:!m,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 ul=({columns:e,currentSort:t,onColumnSort:o,onFilterUpdate:a,sortByProperty:i,filter:n,onColumnResize:s,onColumnResizeEnd:l,createFilterField:c,AddColumnComponent:u})=>{const f=e.map(()=>d.createRef()),[g,m]=d.useState(-1),h=d.useCallback((C,E,B)=>{const S=e[C],P=100,T=800,N=E>T?T:E<P?P:E,M={width:N,key:S.key,column:{...S,width:N}};B?l(M):s(M)},[e,s,l]),A=d.useCallback(C=>{if(g>=0){const E=f[g].current?.parentElement?.getBoundingClientRect().left;return E?C.clientX-E:void 0}},[f,g]),y=d.useCallback(C=>{document.body.style.cursor=C?"col-resize":"auto"},[]),b=d.useCallback(C=>{C.stopPropagation(),C.preventDefault();const E=A(C);E&&h(g,E,!1)},[h,A,g]),k=d.useCallback(C=>{C.stopPropagation(),C.preventDefault();const E=A(C);E&&h(g,E,!0),m(-1),y(!1)},[h,A,g,y]),_=d.useCallback(()=>{document.removeEventListener("mousemove",b),document.removeEventListener("mouseup",k)},[b,k]),v=d.useCallback(()=>{document.addEventListener("mousemove",b),document.addEventListener("mouseup",k)},[b,k]);d.useEffect(()=>(g>=0?v():_(),()=>{_()}),[v,g,_]);const x=d.useCallback(C=>{m(C),y(!0)},[y]);return r.jsxs("div",{className:p.cls(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,E)=>{const B=e[E],S=B&&n&&n[B.key]?n[B.key]:void 0;return r.jsx(ae,{children:r.jsx(dl,{resizeHandleRef:f[E],columnIndex:E,isResizingIndex:g,onFilterUpdate:a,filter:S,sort:i===B.key?t:void 0,onColumnSort:o,onClickResizeColumn:x,column:B,createFilterField:c,AdditionalHeaderWidget:B.AdditionalHeaderWidget})},"header_"+B.key)}),u&&r.jsx(u,{})]})},fl=d.memo(function({rowData:t,rowIndex:o,children:a,onRowClick:i,rowHeight:n,style:s,hoverRow:l,rowClassName:c}){const u=d.useCallback(f=>{i&&i({rowData:t,rowIndex:o,event:f})},[i,t,o]);return r.jsx("div",{className:p.cls("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":i}),onClick:u,style:{...s,height:n,width:"fit-content"},children:a})},Y),ml=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)=>Y(e.rowData,t.rowData)&&Y(e.column,t.column)&&Y(e.cellData,t.cellData)&&Y(e.rowIndex,t.rowIndex)&&Y(e.cellRenderer,t.cellRenderer)&&Y(e.columnIndex,t.columnIndex)),dr=d.createContext({});dr.displayName="VirtualListContext";const hl=d.forwardRef(({children:e,...t},o)=>r.jsx(dr.Consumer,{children:a=>{const i=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(ul,{...a}),!i&&e]})}),i&&r.jsx("div",{style:{position:"sticky",top:"56px",flexGrow:1,height:"calc(100% - 56px)",marginTop:"calc(56px - 100vh)",left:0},children:i})]})}})),gn=d.memo(function({data:t,onResetPagination:o,onEndReached:a,rowHeight:i=54,columns:n,onRowClick:s,onColumnResize:l,filter:c,checkFilterCombination:u,onFilterUpdate:f,sortBy:g,error:m,emptyComponent:h,onSortByUpdate:A,loading:y,cellRenderer:b,hoverRow:k,createFilterField:_,rowClassName:v,style:x,className:C,endAdornment:E,AddColumnComponent:B}){const S=g?g[0]:void 0,P=g?g[1]:void 0,[T,N]=d.useState(n),M=d.useRef(null),L=d.useRef(0);d.useEffect(()=>{N(n)},[n]);const[ee,G]=Wo(),q=d.useCallback(V=>{N(T.map(z=>z.key===V.column.key?V.column:z))},[T]),j=d.useCallback(V=>{N(T.map(z=>z.key===V.column.key?V.column:z)),l&&l(V)},[T,l]),O=d.useRef();d.useEffect(()=>{O.current=c},[c]);const te=d.useCallback(()=>{L.current=0,M.current&&M.current.scrollTo(M.current?.scrollLeft,0)},[]),Z=d.useCallback(V=>{const z=S===V&&P==="desc",D=S===V&&P==="asc"?"desc":z?void 0:"asc",ie=z?void 0:V,xe=O.current,Le=D&&ie?[ie,D]:void 0;xe&&u&&!u(xe,Le)&&f&&f(void 0),o&&o(),A&&A(Le),te()},[u,P,f,o,A,te,S]);d.useCallback(()=>{L.current=0,A&&A(void 0)},[A]);const le=Math.max((t?.length??0)*i-G.height,0),ne=d.useCallback(V=>{a&&(t?.length??0)>0&&V>L.current+600&&(L.current=V,a())},[t?.length,a]),re=d.useCallback(({scrollOffset:V,scrollUpdateWasRequested:z})=>{!z&&V>=le-600&&ne(V)},[le,ne]),J=d.useCallback((V,z)=>{L.current=0;const I=O.current;let D=I?{...I}:{};z?D[V.key]=z:delete D[V.key],!u||u(D,S&&P?[S,P]:void 0)||(D=z?{[V.key]:z}:{}),f&&f(D)},[u,P,f,S]),Q=d.useCallback(()=>y?r.jsx(Nt,{}):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]),R=!y&&(t?.length??0)===0,H=m?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"}),m?.message&&r.jsx(Al,{text:m.message})]}):R?Q():void 0,$={data:t,rowHeight:i,cellRenderer:b,columns:T,currentSort:P,onRowClick:s,customView:H,onColumnResize:q,onColumnResizeEnd:j,filter:O.current,onColumnSort:Z,onFilterUpdate:J,sortByProperty:S,hoverRow:k??!1,createFilterField:_,rowClassName:v,endAdornment:E,AddColumnComponent:B};return r.jsx("div",{ref:ee,style:x,className:p.cls("h-full w-full",C),children:r.jsx(dr.Provider,{value:$,children:r.jsx(gl,{outerRef:M,width:G.width,height:G.height,itemCount:(t?.length??0)+(E?1:0),onScroll:re,includeAddColumn:!!B,itemSize:i},i)})})},Y);function gl({outerRef:e,width:t,height:o,itemCount:a,onScroll:i,itemSize:n,includeAddColumn:s}){const l=d.useCallback(({index:c,style:u})=>r.jsx(dr.Consumer,{children:({onRowClick:f,data:g,columns:m,rowHeight:h=54,cellRenderer:A,hoverRow:y,rowClassName:b,endAdornment:k})=>{if(k&&c===(g??[]).length)return r.jsx("div",{style:{...u,height:"auto",position:"sticky",bottom:0,zIndex:1},children:k});const _=g&&g[c];return r.jsxs(fl,{rowData:_,rowIndex:c,onRowClick:f,columns:m,hoverRow:y,rowClassName:b,style:{...u,top:`calc(${u.top}px + 48px)`},rowHeight:h,children:[m.map((v,x)=>{const C=_&&_[v.key];return r.jsx(ml,{dataKey:v.key,cellRenderer:A,column:v,columns:m,rowData:_,cellData:C,rowIndex:c,columnIndex:x},`cell_${v.key}`)}),s&&r.jsx("div",{className:"w-20"})]},`row_${c}`)}}),[]);return r.jsx(ui.FixedSizeList,{outerRef:e,innerElementType:hl,width:t,height:o,overscanCount:4,itemCount:a,onScroll:i,itemSize:n,children:l})}const Al=({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}})},An={"==":"==","!=":"!=",">":">","<":"<",">=":">=","<=":"<=",in:"In","not-in":"Not in","array-contains":"Contains","array-contains-any":"Contains Any"},so=["array-contains-any","in","not-in"];function bl({name:e,value:t,setValue:o,isArray:a,path:i,title:n,includeId:s=!0,previewProperties:l,setHidden:c}){const u=a?["array-contains"]:["==","!=",">","<",">=","<="];a?u.push("array-contains-any"):u.push("in","not-in");const[f,g]=t||[u[0],void 0],[m,h]=d.useState(f),[A,y]=d.useState(g),b=A?Array.isArray(A)?A.map(T=>T?.isEntityReference&&T?.isEntityReference()?T.id:null).filter(Boolean):[A.id]:[];function k(T,N){const M=so.includes(m),L=so.includes(T);let ee=N;M!==L&&(ee=L?ee?.isEntityReference&&ee?.isEntityReference()?[ee]:[]:void 0),h(T),y(ee);const G=ee!==null&&Array.isArray(ee)?ee.length>0:ee!==void 0;o(T&&G?[T,ee]:void 0)}const _=pe(),v=d.useMemo(()=>i?_.getCollection(i):void 0,[i]),x=T=>{k(m,$e(T))},C=T=>{k(m,T.map(N=>$e(N)))},E=so.includes(m),B=At({multiselect:E,path:i,collection:v,onSingleEntitySelected:x,onMultipleEntitiesSelected:C,selectedEntityIds:b,onClose:()=>{c(!1)}}),S=()=>{c(!0),B.open()},P=T=>r.jsx(Ve,{disabled:!i,previewProperties:l,size:"medium",onClick:S,reference:T,hover:!0,includeId:s,includeEntityLink:!1});return r.jsxs("div",{className:"flex w-[440px] flex-row",children:[r.jsx("div",{className:"w-[140px]",children:r.jsx(p.Select,{value:m,onValueChange:T=>{k(T,A)},renderValue:T=>An[T],children:u.map(T=>r.jsx(p.SelectItem,{value:T,children:An[T]},T))})}),r.jsxs("div",{className:"flex-grow ml-2 h-full gap-2 flex flex-col",children:[A&&Array.isArray(A)&&r.jsx("div",{children:A.map((T,N)=>P(T))}),A&&!Array.isArray(A)&&r.jsx("div",{children:P(A)}),(!A||Array.isArray(A)&&A.length===0)&&r.jsx(p.Button,{onClick:S,variant:"outlined",size:"large",className:"h-full w-full",children:E?"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:A===null,size:"small",onCheckedChange:T=>{A!==null?k(m,null):k(m,void 0)}}),"Filter for null values"]})]})]})}const bn={"==":"==","!=":"!=",">":">","<":"<",">=":">=","<=":"<=",in:"In","not-in":"Not in","array-contains":"Contains","array-contains-any":"Any"},lo=["array-contains-any","in","not-in"];function yl({name:e,value:t,setValue:o,dataType:a,isArray:i,enumValues:n,title:s}){const l=i?["array-contains"]:["==","!=",">","<",">=","<="];n&&(i?l.push("array-contains-any"):l.push("in","not-in"));const[c,u]=t||[l[0],void 0],[f,g]=d.useState(c),[m,h]=d.useState(u);function A(b,k){let _=k;const v=lo.includes(f),x=lo.includes(b);v!==x&&(_=x?typeof k=="string"||typeof k=="number"?[k]:[]:void 0),typeof _=="number"&&isNaN(_)&&(_=void 0),g(b),h(_);const C=_!==null&&Array.isArray(_)?_.length>0:_!==void 0;o(b&&C?[b,_]:void 0)}const y=lo.includes(f);return r.jsxs("div",{className:"flex w-[440px]",children:[r.jsx("div",{className:"w-[80px]",children:r.jsx(p.Select,{value:f,position:"item-aligned",onValueChange:b=>{A(b,m)},renderValue:b=>bn[b],children:l.map(b=>r.jsx(p.SelectItem,{value:b,children:bn[b]},b))})}),r.jsxs("div",{className:"flex-grow ml-2 flex flex-col gap-2",children:[!n&&r.jsx(p.TextField,{type:a==="number"?"number":void 0,value:m!==void 0&&m!=null?String(m):"",onChange:b=>{const k=a==="number"?parseFloat(b.target.value):b.target.value;A(f,k)},endAdornment:m&&r.jsx(p.IconButton,{onClick:b=>A(f,void 0),children:r.jsx(p.ClearIcon,{})})}),n&&r.jsx(p.Select,{position:"item-aligned",value:m!==void 0?Array.isArray(m)?m.map(b=>String(b)):String(m):i?[]:"",onValueChange:b=>{b!==""&&A(f,a==="number"?parseInt(b):b)},multiple:y,endAdornment:m&&r.jsx(p.IconButton,{className:"absolute right-2 top-3",onClick:b=>A(f,void 0),children:r.jsx(p.ClearIcon,{})}),renderValue:b=>b===null?"Filter for null values":r.jsx(Ie,{enumKey:b,enumValues:n,size:"small"},`select_value_${e}_${b}`),children:n.map(b=>r.jsx(p.SelectItem,{value:String(b.id),children:r.jsx(Ie,{enumKey:String(b.id),enumValues:n,size:"small"})},`select_value_${e}_${b.id}`))}),!i&&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:m===null,size:"small",onCheckedChange:b=>{m!==null?A(f,null):A(f,void 0)}}),"Filter for null values"]})]})]})}function wl({name:e,title:t,value:o,setValue:a}){function i(l){a(l!==void 0?["==",l]:void 0)}const n=o&&o[1],s=!!o;return r.jsx("div",{className:"w-[300px]",children:r.jsx(p.BooleanSwitchWithLabel,{value:n,allowIndeterminate:!0,onValueChange:l=>i(l===null?void 0:l),label:s?n?`${t} is true`:`${t} is false`:"No filter"})})}const yn={"==":"==","!=":"!=",">":">","<":"<",">=":">=","<=":"<=","not-in":"not in",in:"in","array-contains":"Contains","array-contains-any":"Any"},wn=["array-contains-any","in"];function vl({name:e,isArray:t,mode:o,value:a,setValue:i,title:n}){const{locale:s}=se(),l=t?["array-contains"]:["==","!=",">","<",">=","<="],[c,u]=a||[l[0],void 0],[f,g]=d.useState(c),[m,h]=d.useState(u);function A(y,b){let k=b;const _=wn.includes(f),v=wn.includes(y);_!==v&&(k=v?b?[b]:[]:""),g(y),h(k===null?void 0:k);const x=k!==null&&Array.isArray(k)?k.length>0:k!==void 0;i(y&&x?[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:f,onValueChange:y=>{A(y,m)},renderValue:y=>yn[y],children:l.map(y=>r.jsx(p.SelectItem,{value:y,children:yn[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:m??void 0,onChange:y=>{A(f,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:m===null,size:"small",onCheckedChange:y=>{m!==null?A(f,null):A(f,void 0)}}),"Filter for null values"]})]})]})}const vn=d.memo(function({onValueChange:t,cellRenderer:o,onEntityClick:a,onColumnResize:i,hoverRow:n=!0,size:s="m",inlineEditing:l=!1,tableController:{data:c,dataLoading:u,noMoreToLoad:f,dataLoadingError:g,filterValues:m,setFilterValues:h,sortBy:A,setSortBy:y,setSearchString:b,clearFilter:k,itemCount:_,setItemCount:v,pageSize:x=50,paginationEnabled:C,checkFilterCombination:E,setPopupCell:B},filterable:S=!0,emptyComponent:P,columns:T,forceFilter:N,highlightedRow:M,endAdornment:L,AddColumnComponent:ee}){const G=d.useRef(null),[q,j]=d.useState(void 0),O=()=>{!C||u||f||_!==void 0&&v?.(_+x)},te=d.useCallback(()=>{v?.(x)},[x]),Z=d.useCallback(({rowData:J})=>{if(!l)return a&&a(J)},[a,l]);p.useOutsideAlerter(G,()=>{q&&ne()},!!q),d.useEffect(()=>{const J=Q=>{Q.keyCode===27&&ne()};return document.addEventListener("keydown",J,!1),()=>{document.removeEventListener("keydown",J,!1)}});const le=d.useCallback(J=>{j(J)},[]),ne=d.useCallback(()=>{j(void 0)},[]),re=d.useCallback(J=>{h?.({...J,...N})},[N]);return r.jsx(oo.Provider,{value:{setPopupCell:B,select:le,onValueChange:t,size:s??"m",selectedCell:q},children:r.jsx("div",{className:"h-full w-full flex flex-col bg-white dark:bg-gray-950",ref:G,children:r.jsx(gn,{data:c,columns:T,cellRenderer:o,onRowClick:l?void 0:a?Z:void 0,onEndReached:O,onResetPagination:te,error:g,paginationEnabled:C,onColumnResize:i,rowHeight:ir(s),loading:u,filter:m,onFilterUpdate:h?re:void 0,sortBy:A,onSortByUpdate:y,hoverRow:n,checkFilterCombination:E,createFilterField:S?kl:void 0,rowClassName:d.useCallback(J=>M?.(J)?"bg-gray-100 bg-opacity-75 dark:bg-gray-800 dark:bg-opacity-75":"",[M]),className:"flex-grow",emptyComponent:P,endAdornment:L,AddColumnComponent:ee})})})},Y);function kl({id:e,filterValue:t,setFilterValue:o,column:a,hidden:i,setHidden:n}){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(bl,{value:t,setValue:o,name:e,isArray:l,path:c.path,title:s?.name,includeId:c.includeId,previewProperties:c?.previewProperties,hidden:i,setHidden:n});if(c.dataType==="number"||c.dataType==="string"){const u=c.name,f=c.enumValues?Je(c.enumValues):void 0;return r.jsx(yl,{value:t,setValue:o,name:e,dataType:c.dataType,isArray:l,enumValues:f,title:u})}else if(c.dataType==="boolean"){const u=c.name;return r.jsx(wl,{value:t,setValue:o,name:e,title:u})}else if(c.dataType==="date"){const u=c.name;return r.jsx(vl,{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 co=function({className:t,style:o,forceFilter:a,actionsStart:i,actions:n,title:s,tableRowActionsBuilder:l,uniqueFieldValidator:c,getPropertyFor:u,onValueChange:f,selectionController:g,highlightedEntities:m,onEntityClick:h,onColumnResize:A,onSizeChanged:y,textSearchEnabled:b=!1,hoverRow:k=!0,inlineEditing:_=!1,additionalFields:v,displayedColumnIds:x,defaultSize:C,properties:E,tableController:B,filterable:S=!0,sortable:P=!0,endAdornment:T,AddColumnComponent:N,AdditionalHeaderWidget:M,additionalIDHeaderWidget:L,emptyComponent:ee,getIdColumnWidth:G,onTextSearchClick:q,textSearchLoading:j,enablePopupIcon:O}){const te=d.useRef(null),Z=Oe(),le=(g?.selectedEntities?.length>0?g?.selectedEntities:m)?.filter(Boolean),ne=Ce(),[re,J]=d.useState(C??"m"),Q=le?.map(K=>K.id),R=d.useCallback(K=>{y&&y(K),J(K)},[]),H=d.useCallback(K=>B.setSearchString?.(K),[]),$=d.useMemo(()=>v?v.map(K=>({[K.key]:K})).reduce((K,he)=>({...K,...he}),{}):{},[v]),V=c,z=({column:K,columnIndex:he,rowData:Te,rowIndex:Fe})=>{const Ae=Te,Ge=K.key;let je=K.custom?.disabled;const qe=u?.({propertyKey:Ge,entity:Ae})??K.custom.resolvedProperty;return qe?.disabled||(je=!1),qe?r.jsx(ae,{children:Ae?r.jsx(pn,{readonly:!_,align:K.align??"left",propertyKey:Ge,property:qe,value:Ae?.values?Ue(Ae.values,Ge):void 0,customFieldValidator:V,columnIndex:he,width:K.width,height:ir(re),entity:Ae,disabled:je,enablePopupIcon:O,path:Ae.path},`property_table_cell_${Ae.id}_${Ge}`):We()}):null},I=d.useCallback(({column:K,rowData:he,width:Te})=>{const Fe=he,Ae=$[K.key],Ge=Ae.dependencies?Object.entries(Fe.values).filter(([X,be])=>Ae.dependencies.includes(X)).reduce((X,be)=>({...X,...be}),{}):Fe,je=Ae.Builder;if(!je&&!Ae.value)throw new Error("When using additional fields you need to provide a Builder or a value");const qe=je?r.jsx(je,{entity:Fe,context:ne}):r.jsx(r.Fragment,{children:Ae.value?.({entity:Fe,context:ne})});return r.jsx(sr,{width:Te,size:re,value:Ge,selected:!1,disabled:!0,align:"left",allowScroll:!1,showExpandIcon:!1,disabledTooltip:"This column can't be edited directly",children:r.jsx(ae,{children:qe})},`additional_table_cell_${Fe.id}_${K.key}`)},[re,Q]),D=(()=>{const K=mn({properties:E,sortable:P,forceFilter:a,AdditionalHeaderWidget:M}),he=v?v.map(Te=>({key:Te.key,align:"left",sortable:!1,title:Te.name,width:Te.width??200})):[];return[...K,...he]})(),xe=[{key:"id_ewcfedcswdf3",width:G?.()??(Z?160:130),title:"ID",resizable:!1,frozen:Z,headerAlign:"center",align:"center",AdditionalHeaderWidget:()=>L},...x?x.map(K=>D.find(he=>he.key===K.key)).filter(Boolean):D],Le=K=>{const he=K.column,Te=K.columns,Fe=he.key;try{if(K.columnIndex===0)return l?l({entity:K.rowData,size:re,width:he.width,frozen:he.frozen}):r.jsx(lr,{entity:K.rowData,width:he.width,frozen:he.frozen,isSelected:!1,size:re});if($[Fe])return I(K);if(K.columnIndex<Te.length+1)return z(K);throw Error("Internal: columns not mapped properly")}catch(Ae){return console.error("Error rendering cell",Ae),r.jsx(sr,{size:re,width:he.width,saved:!1,value:null,align:"left",fullHeight:!1,disabled:!0,children:r.jsx(ye,{error:Ae})})}};return r.jsxs("div",{ref:te,style:o,className:p.cls("h-full w-full flex flex-col bg-white dark:bg-gray-950",t),children:[r.jsx(il,{onTextSearch:b?H:void 0,textSearchLoading:j,onTextSearchClick:b?q:void 0,size:re,onSizeChanged:R,title:s,actionsStart:i,actions:n,loading:B.dataLoading}),r.jsx(vn,{columns:xe,size:re,inlineEditing:_,cellRenderer:Le,onEntityClick:h,highlightedRow:d.useCallback(K=>Q?.includes(K.id)??!1,[Q]),tableController:B,onValueChange:f,onColumnResize:A,hoverRow:k,filterable:S,emptyComponent:ee,endAdornment:T,AddColumnComponent:N})]})};function _l({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 kn(e,t,o=5e3){const[a,i]=d.useState(e),n=d.useRef(a.length??0),s=d.useRef(!1),l=d.useRef(t),c=!Y(l.current,t),u=e.length>=n.current||c;return d.useEffect(()=>{const f=()=>{Y(a,e)||(l.current=t,n.current=e.length,i(e)),s.current=!1};s.current=!0;let g;return u?f():g=setTimeout(f,o),()=>{clearTimeout(g),s.current&&u&&f()}},[e,o,t,u]),u?e:a}const Cl=50;function po({fullPath:e,collection:t,entitiesDisplayedFirst:o,lastDeleteTimestamp:a,forceFilter:i}){const{initialFilter:n,initialSort:s,forceFilter:l}=t,[c,u]=d.useState(void 0),f=pe(),g=ze(t),m=d.useMemo(()=>f.resolveAliasesFrom(e),[e,f.resolveAliasesFrom]),h=i??l,A=t.pagination===void 0||!!t.pagination,y=typeof t.pagination=="number"?t.pagination:Cl,[b,k]=d.useState(),[_,v]=d.useState(A?y:void 0),x=d.useMemo(()=>{if(s&&h&&!Z(h,s)){console.warn("Initial sort is not compatible with the force filter. Ignoring initial sort");return}return s},[s,h]);d.useEffect(()=>{Y(h,C)||E(h)},[h]);const[C,E]=d.useState(h??n??void 0),[B,S]=d.useState(x),P=B?B[0]:void 0,T=B?B[1]:void 0,N=Ce(),[M,L]=d.useState([]),[ee,G]=d.useState(!1),[q,j]=d.useState(),[O,te]=d.useState(!1),Z=d.useCallback((Q,R)=>g.isFilterCombinationValid?g.isFilterCombinationValid({path:m,collection:t,filterValues:Q,sortBy:R}):!0,[]),le=d.useCallback(()=>E(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?E(void 0):E(Q)},[h]);d.useEffect(()=>{G(!0);const Q=async H=>{if(t.callbacks?.onFetch)try{H=await Promise.all(H.map($=>t.callbacks.onFetch({collection:t,path:m,entity:$,context:N})))}catch($){console.error($)}G(!1),j(void 0),L(H.map($=>({...$}))),te(!_||H.length<_)},R=H=>{console.error("ERROR",H),G(!1),L([]),j(H)};return g.listenCollection?g.listenCollection({path:m,collection:t,onUpdate:Q,onError:R,searchString:b,filter:C,limit:_,startAfter:void 0,orderBy:P,order:T}):(g.fetchCollection({path:m,collection:t,searchString:b,filter:C,limit:_,startAfter:void 0,orderBy:P,order:T}).then(Q).catch(R),()=>{})},[m,_,T,P,C,b]);const re=_l({data:M,entitiesDisplayedFirst:o});return{data:kn(re,{filterValues:C,sortBy:B,searchString:b,lastDeleteTimestamp:a}),dataLoading:ee,noMoreToLoad:O,dataLoadingError:q,filterValues:C,setFilterValues:ne,sortBy:B,setSortBy:S,searchString:b,setSearchString:k,clearFilter:le,itemCount:_,setItemCount:v,paginationEnabled:A,pageSize:y,checkFilterCombination:Z,popupCell:c,setPopupCell:u}}function uo(e){const[t,o]=d.useState([]),a=d.useCallback(n=>{let s;t.map(l=>l.id).includes(n.id)?(e?.(n,!1),s=t.filter(l=>l.id!==n.id)):(e?.(n,!0),s=[...t,n]),o(s)},[t]),i=d.useCallback(n=>t.map(s=>s.id).includes(n.id),[t]);return{selectedEntities:t,setSelectedEntities:o,isEntitySelected:i,toggleEntitySelection:a}}function fo({collection:e,fullPath:t,parentCollectionIds:o}){const a=Ce(),i=se(),n=ze(),[s,l]=d.useState(!1),[c,u]=d.useState(!1);let f,g=!!e.textSearchEnabled;return i?.plugins&&(f=n?.initTextSearch||i.plugins?.find(h=>!!h.collectionView?.onTextSearchClick)?()=>{l(!0);const h=[];return n?.initTextSearch&&h.push(n.initTextSearch({context:a,path:t,collection:e,parentCollectionIds:o})),i.plugins?.forEach(A=>(A.collectionView?.onTextSearchClick&&h.push(A.collectionView.onTextSearchClick({context:a,path:t,collection:e,parentCollectionIds:o})),Promise.resolve(!0))),Promise.all(h).then(A=>{A.every(Boolean)&&u(!0)}).finally(()=>l(!1))}:void 0,i.plugins?.forEach(h=>{g||h.collectionView?.showTextSearchBar&&(g=h.collectionView.showTextSearchBar({context:a,path:t,collection:e,parentCollectionIds:o}))})),{textSearchLoading:s,textSearchInitialised:c,onTextSearchClick:f,textSearchEnabled:g}}function _n({entityOrEntitiesToDelete:e,collection:t,onClose:o,open:a,callbacks:i,onEntityDelete:n,onMultipleEntitiesDelete:s,path:l}){const c=ze(t),u=se(),f=Ze(),[g,m]=d.useState(!1),[h,A]=d.useState(),[y,b]=d.useState(),k=Ce();d.useEffect(()=>{if(e){const M=Array.isArray(e)&&e.length===1?e[0]:e;A(M),b(Array.isArray(M))}},[e]);const _=d.useMemo(()=>Ne({collection:t,path:l,fields:u.propertyConfigs}),[t,l]),v=d.useCallback(()=>{o()},[o]),x=d.useCallback(M=>{console.debug("Deleted",M)},[]),C=d.useCallback((M,L)=>{f.open({type:"error",message:"Error deleting: "+L?.message}),console.error("Error deleting entity"),console.error(L)},[_.name]),E=d.useCallback((M,L)=>{f.open({type:"error",message:"Error before deleting: "+L?.message}),console.error(L)},[_.name]),B=d.useCallback((M,L)=>{f.open({type:"error",message:"Error after deleting: "+L?.message}),console.error(L)},[_.name]),S=d.useCallback(M=>Fa({dataSource:c,entity:M,collection:_,callbacks:i,onDeleteSuccess:x,onDeleteFailure:C,onPreDeleteHookError:E,onDeleteSuccessHookError:B,context:k}),[c,_,i,x,C,E,B,k]),P=d.useCallback(async()=>{h&&(m(!0),y?Promise.all(h.map(S)).then(M=>{m(!1),s&&h&&s(l,h),M.every(Boolean)?f.open({type:"success",message:`${_.name}: multiple deleted`}):M.some(Boolean)?f.open({type:"warning",message:`${_.name}: Some of the entities have been deleted, but not all`}):f.open({type:"error",message:`${_.name}: Error deleting entities`}),o()}):S(h).then(M=>{m(!1),M&&(n&&h&&n(l,h),f.open({type:"success",message:`${_.singularName??_.name} deleted`}),o())}))},[h,y,S,s,l,o,f,_.name,n]);let T;if(h&&y)T=r.jsx(r.Fragment,{children:"Multiple entities"});else{const M=h;T=M?r.jsx(Rr,{entity:M,collection:t,path:l}):r.jsx(r.Fragment,{})}const N=y?r.jsxs(r.Fragment,{children:[r.jsx("b",{children:_.name}),": Confirm multiple delete?"]}):`Would you like to delete this ${_.singularName??_.name}?`;return r.jsxs(p.Dialog,{maxWidth:y?"lg":"2xl","aria-labelledby":"delete-dialog",open:a,onOpenChange:M=>M?void 0:o(),children:[r.jsxs(p.DialogContent,{fullHeight:!0,children:[r.jsx(p.Typography,{variant:"subtitle2",className:"p-4",children:N}),!y&&r.jsx("div",{className:"p-4",children:T})]}),r.jsxs(p.DialogActions,{children:[g&&r.jsx(p.CircularProgress,{size:"small"}),r.jsx(p.Button,{onClick:v,disabled:g,variant:"text",color:"primary",children:"Cancel"}),r.jsx(p.Button,{autoFocus:!0,disabled:g,onClick:P,variant:"filled",color:"primary",children:"Ok"})]})]})}const Cn={icon:r.jsx(p.KeyboardTabIcon,{}),name:"Edit",collapsed:!1,onClick({entity:e,collection:t,fullPath:o,context:a,highlightEntity:i,unhighlightEntity:n}){i?.(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:()=>n?.(e)}),Promise.resolve(void 0)}},mo={icon:r.jsx(p.FileCopyIcon,{}),name:"Copy",onClick({entity:e,collection:t,context:o,highlightEntity:a,unhighlightEntity:i}){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:()=>i?.(e)}),Promise.resolve(void 0)}},xl={icon:r.jsx(p.ArchiveIcon,{}),name:"Archive",onClick({entity:e,collection:t,context:{dataSource:o}}){return Promise.resolve(void 0)}},El={icon:r.jsx(p.OpenInNewIcon,{}),name:"See in website",onClick({entity:e,collection:t,context:o}){return window.open(`https://example.com/${e.id}`,"_blank"),Promise.resolve(void 0)}},ho={icon:r.jsx(p.DeleteIcon,{}),name:"Delete",onClick({entity:e,fullPath:t,collection:o,context:a,selectionController:i,onCollectionChange:n,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(_n,{entityOrEntitiesToDelete:e,path:t,collection:o,callbacks:o.callbacks,open:c,onEntityDelete:()=>{a.analyticsController?.onAnalyticsEvent?.("single_entity_deleted",{path:t}),i?.setSelectedEntities(i.selectedEntities.filter(u=>u.id!==e.id)),n?.(),s?.close()},onClose:l})}});return Promise.resolve(void 0)}};function xn({onSingleEntitySelected:e,onMultipleEntitiesSelected:t,multiselect:o,collection:a,path:i,selectedEntityIds:n,description:s,forceFilter:l,maxSelection:c}){const u=gr(),f=at(),g=pe(),m=gt(),h=se(),A=g.resolveAliasesFrom(i),y=ze(a),[b,k]=d.useState([]),_=q=>{let j;const O=v.selectedEntities;if(m.onAnalyticsEvent?.("reference_selection_toggle",{path:A,entityId:q.id}),O){if(O.map(te=>te.id).indexOf(q.id)>-1)j=O.filter(te=>te.id!==q.id);else{if(c&&O.length>=c)return;j=[...O,q]}v.setSelectedEntities(j),t&&t(j)}},v=uo(_);d.useEffect(()=>{let q=!1;const j=n?.map(O=>O?.toString()).filter(Boolean);return j&&a?Promise.all(j.map(O=>y.fetchEntity({path:A,entityId:O,collection:a}))).then(O=>{if(!q){const te=O.filter(Z=>Z!==void 0);v.setSelectedEntities(te),k(te)}}):(v.setSelectedEntities([]),k([])),()=>{q=!0}},[y,A,n,a,v.setSelectedEntities]);const x=()=>{m.onAnalyticsEvent?.("reference_selection_clear",{path:A}),v.setSelectedEntities([]),!o&&e?e(null):t&&t([])},C=q=>{!o&&e?(m.onAnalyticsEvent?.("reference_selected_single",{path:A,entityId:q.id}),e(q),u.close(!1)):_(q)},E=()=>{m.onAnalyticsEvent?.("reference_selection_new_entity",{path:A}),f.open({path:A,collection:a,updateUrl:!0,onUpdate:({entity:q})=>{k([q,...b]),C(q)},closeOnSave:!0})},B=({entity:q,size:j,width:O,frozen:te})=>{const Z=v.selectedEntities,le=Z&&Z.map(ne=>ne.id).indexOf(q.id)>-1;return r.jsx(lr,{width:O,frozen:te,entity:q,size:j,isSelected:le,selectionEnabled:o,hideId:a?.hideIdFromCollection,fullPath:A,selectionController:v})},S=d.useCallback(q=>{q.stopPropagation(),u.close(!1)},[u]);if(!a)return r.jsx(ye,{error:"Could not find collection with id "+a});const P=d.useMemo(()=>Ne({collection:a,path:A,values:{},fields:h.propertyConfigs}),[a,h.propertyConfigs,A]),T=io(P,!1),N=po({fullPath:A,collection:a,entitiesDisplayedFirst:b,forceFilter:l}),{textSearchLoading:M,textSearchInitialised:L,onTextSearchClick:ee,textSearchEnabled:G}=fo({collection:a,fullPath:A});return r.jsxs("div",{className:"flex flex-col h-full",children:[r.jsx("div",{className:"flex-grow",children:b&&r.jsx(co,{textSearchLoading:M,onTextSearchClick:L?void 0:ee,textSearchEnabled:G,displayedColumnIds:T,onEntityClick:C,tableController:N,enablePopupIcon:!1,tableRowActionsBuilder:B,title:r.jsx(p.Typography,{variant:"subtitle2",children:a.singularName?`Select ${a.singularName}`:`Select from ${a.name}`}),defaultSize:a.defaultSize,properties:P.properties,forceFilter:l,inlineEditing:!1,selectionController:v,actions:r.jsx(Bl,{collection:a,path:A,onNewClick:E,onClear:x})})}),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 Bl({collection:e,path:t,onClear:o,onNewClick:a}){const i=ot(),n=Oe(),s=a?c=>{c.preventDefault(),a()}:void 0,l=ft(e,i,t,null)&&s&&(n?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 Pt(e){return Array.isArray(e)?e:e?[e]:[]}function go({children:e,group:t}){const o=ht();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(i=>i!==(t??"ungrouped")));else{const i=(o.collapsedGroups??[]).concat(t??"ungrouped");o.setCollapsedGroups(i)}},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 En({name:e,description:t,icon:o,actions:a,onClick:i}){return r.jsx(p.Card,{className:p.cls("h-full p-4 cursor-pointer min-h-[230px]"),onClick:()=>{i?.()},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:n=>{n.preventDefault(),n.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 Bn({name:e,url:t,icon:o}){return r.jsx(r.Fragment,{children:r.jsxs(ge.Link,{tabIndex:0,className:p.cls(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 Sn({path:e,collection:t,view:o,url:a,name:i,description:n,onClick:s,type:l}){const c=ht(),u=r.jsx(rr,{collectionOrView:t??o}),f=ge.useNavigate(),g=Ce(),m=se(),h=(c?.favouritePaths??[]).includes(e),A=c?[r.jsx(p.IconButton,{onClick:b=>{b.preventDefault(),b.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(m.plugins&&t){const b={path:e,collection:t,context:g};m.plugins.forEach((k,_)=>A.push(k.homePage?.CollectionActions?r.jsx(k.homePage.CollectionActions,{...b,extraProps:k.homePage.extraProps},`actions_${_}`):null))}const y=r.jsx(r.Fragment,{children:A});return l==="admin"?r.jsx(Bn,{icon:u,name:i,url:a}):r.jsx(En,{icon:u,name:i,description:n,actions:y,onClick:()=>{s?.(),f(a),c&&c.setRecentlyVisitedPaths([e,...(c.recentlyVisitedPaths??[]).filter(b=>b!==e)])}})}function Sl({entry:e}){const t=ge.useNavigate(),o=ht();if(!o)return null;const a=o.favouritePaths.includes(e.path),i=n=>{n.preventDefault(),n.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:i,size:18,className:"text-secondary"}):r.jsx(p.StarBorderIcon,{onClick:i,size:18,className:"text-gray-400 dark:text-gray-500"}),children:e.name},e.path)}function Il({hidden:e}){const t=pe(),o=ht();if(!o)return null;const a=(o?.favouritePaths??[]).map(i=>t.topLevelNavigation?.navigationEntries.find(n=>n.path===i)).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(i=>r.jsx(Sl,{entry:i},i.path))})})}const Ao={};function Fl(){const e=ge.useLocation(),t=d.useRef(null),[o,a]=d.useState(0),[i,n]=d.useState("down"),s=d.useCallback(()=>{!t.current||!e.key||(Ao[e.key]=t.current.scrollTop,a(t.current.scrollTop),n(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||!Ao[e.key]||t.current.scrollTo({top:Ao[e.key],behavior:"auto"})},[e]),{containerRef:t,scroll:o,direction:i}}const wt=new Ho.Search("url");wt.addIndex("name"),wt.addIndex("description"),wt.addIndex("group"),wt.addIndex("path");function In({additionalActions:e,additionalChildrenStart:t,additionalChildrenEnd:o}){const a=Ce(),i=se(),n=pe();if(!n.topLevelNavigation)throw Error("Navigation not ready in FireCMSHomePage");const{containerRef:s,scroll:l,direction:c}=Fl(),{navigationEntries:u,groups:f}=n.topLevelNavigation,[g,m]=d.useState(null),h=g?u.filter(v=>g.includes(v.url)):u;d.useEffect(()=>{wt.addDocuments(u)},[u]);const A=d.useCallback(v=>{if(!v||v==="")m(null);else{const x=wt.search(v);m(x.map(C=>C.url))}},[]),y=[...f];(h.filter(v=>!v.group).length>0||h.length===0)&&y.push(void 0);let b,k,_;if(i.plugins){const v={context:a};_=r.jsx(r.Fragment,{children:i.plugins.filter(x=>x.homePage?.includeSection).map((x,C)=>{const E=x.homePage.includeSection(v);return r.jsx(go,{group:E.title,children:E.children},`plugin_section_${x.key}`)})}),b=r.jsx("div",{className:"flex flex-col gap-2",children:i.plugins.filter(x=>x.homePage?.additionalChildrenStart).map((x,C)=>r.jsx("div",{children:x.homePage.additionalChildrenStart},`plugin_children_start_${C}`))}),k=r.jsx("div",{className:"flex flex-col gap-2",children:i.plugins.filter(x=>x.homePage?.additionalChildrenEnd).map((x,C)=>r.jsx("div",{children:x.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:A,placeholder:"Search collections",large:!1,innerClassName:"w-full",className:"w-full flex-grow"}),e]}),r.jsx(Il,{hidden:!!g}),t,b,y.map((v,x)=>{const C=[],E={group:v,context:a};i.plugins&&i.plugins.forEach(S=>{S.homePage?.AdditionalCards&&C.push(...Pt(S.homePage?.AdditionalCards))});const B=h.filter(S=>S.group===v||!S.group&&v===void 0);return B.length===0&&C.length===0?null:r.jsx(go,{group:v,children:r.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:[B.map(S=>r.jsx("div",{className:"col-span-1",children:r.jsx(Sn,{...S,onClick:()=>{let P;S.type==="collection"?P="home_navigate_to_collection":S.type==="view"?P="home_navigate_to_view":S.type==="admin"?P="home_navigate_to_admin_view":P="unmapped_event",a.analyticsController?.onAnalyticsEvent?.(P,{path:S.path})}})},`nav_${S.group}_${S.name}`)),v?.toLowerCase()!=="admin"&&C&&C.map((S,P)=>r.jsx("div",{children:r.jsx(S,{...E})},`nav_${v}_add_${P}`))]})},`plugin_section_${v}`)}),_,k,o]})})}function Fn({collection:e,relativePath:t,parentCollectionIds:o,onNewClick:a,onMultipleDeleteClick:i,selectionEnabled:n,path:s,selectionController:l,tableController:c,collectionEntitiesCount:u}){const f=Ce(),m=se().plugins??[],h=ot(),A=Oe(),y=l.selectedEntities,b=ft(e,h,s,null)&&a&&(A?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=Rt(e,h,s,null);let _;if(n){const C=A?r.jsxs(p.Button,{variant:"text",disabled:!y?.length||!k,startIcon:r.jsx(p.DeleteIcon,{}),onClick:i,color:"primary",className:"lg:w-20",children:["(",y?.length,")"]}):r.jsx(p.IconButton,{color:"primary",disabled:!y?.length||!k,onClick:i,children:r.jsx(p.DeleteIcon,{})});_=r.jsx(p.Tooltip,{title:k?"Delete":"You have selected at least one entity you cannot delete",children:C})}const v={path:s,relativePath:t,parentCollectionIds:o,collection:e,selectionController:l,context:f,tableController:c,collectionEntitiesCount:u},x=Pt(e.Actions).map((C,E)=>r.jsx(ae,{children:r.jsx(C,{...v})},`actions_${E}`));return m&&m.forEach((C,E)=>{C.collectionView?.CollectionActions&&x.push(...Pt(C.collectionView?.CollectionActions).map((B,S)=>r.jsx(ae,{children:r.jsx(B,{...v,...C.collectionView?.collectionActionsProps})},`plugin_actions_${E}_${S}`)))}),r.jsxs(r.Fragment,{children:[x,_,b]})}function Nl({containerRef:e,innerRef:t,x:o,y:a,onMove:i}){let n=0,s=0;const l=d.useRef(!1),c=A=>{if(A.button!==0||!e.current||A.defaultPrevented||A.innerClicked)return;const{x:y,y:b}=e.current.getBoundingClientRect();n=A.screenX-y,s=A.screenY-b,document.addEventListener("mousemove",m),document.addEventListener("mouseup",g),document.addEventListener("selectstart",f),l.current=!0},u=A=>{A.innerClicked=!0},f=A=>{A.preventDefault(),A.stopPropagation()},g=A=>{document.removeEventListener("mousemove",m),document.removeEventListener("mouseup",g),document.removeEventListener("selectstart",f),A.stopPropagation(),l.current=!1},m=A=>{A.target.localName==="input"||!l.current||(i({x:A.screenX-n,y:A.screenY-s}),A.stopPropagation())},h=()=>{e.current&&(e.current.style.top=`${a}px`,e.current.style.left=`${o}px`)};d.useEffect(()=>{const A=e.current,y=t.current;if(!(!A||!y))return y&&y.addEventListener("mousedown",u),A&&A.addEventListener("mousedown",c),h(),()=>{A&&A.removeEventListener("mousedown",c),y&&y.removeEventListener("mousedown",u)}})}function Pl(){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 Tl=({onResize:e})=>{const t=d.useRef(0),o=d.useRef(null),a=d.useRef(e);a.current=e;const i=d.useCallback(s=>{t.current&&cancelAnimationFrame(t.current),t.current=requestAnimationFrame(()=>{a.current(s)})},[]),n=d.useCallback(()=>{const s=o.current;s&&s.contentDocument&&s.contentDocument.defaultView&&s.contentDocument.defaultView.addEventListener("resize",i)},[i]);return d.useEffect(()=>{const s=o.current;return()=>{s&&s.contentDocument&&s.contentDocument.defaultView&&s.contentDocument.defaultView.removeEventListener("resize",i)}},[i]),r.jsx("object",{onLoad:n,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 Dl(e){return e.open?r.jsx(Ql,{...e}):null}function Ql({tableKey:e,entity:t,customFieldValidator:o,propertyKey:a,collection:i,path:n,cellRect:s,open:l,onClose:c,onCellValueChange:u,container:f}){const g=Ce(),m=se(),[h,A]=d.useState(),[y,b]=d.useState(),k=t?.id,[_,v]=d.useState(t),[x,C]=d.useState(_?.values),E=i?Ne({collection:i,path:n,values:x,entityId:k,fields:m.propertyConfigs}):void 0,B=Pl(),S=d.useRef(null),P=d.useRef(null),T=d.useRef(!1),N=d.useCallback(()=>{if(!s)throw Error("getInitialLocation error");return{x:s.left<B.width-s.right?s.x+s.width/2:s.x-s.width/2,y:s.top<B.height-s.bottom?s.y+s.height/2:s.y-s.height/2}},[s,B.height,B.width]),M=d.useCallback(({x:z,y:I})=>{const D=S.current?.getBoundingClientRect();if(!D)throw Error("normalizePosition called before draggableBoundingRect is set");return{x:Math.max(0,Math.min(z,B.width-D.width)),y:Math.max(0,Math.min(I,B.height-D.height))}},[B]),L=d.useCallback(z=>{const I=S.current?.getBoundingClientRect();if(!s||!I)return;const D=z??M(N());(!y||D.x!==y.x||D.y!==y.y)&&b(D)},[s,N,M,y]);Nl({containerRef:S,innerRef:P,x:y?.x,y:y?.y,onMove:L}),d.useEffect(()=>{T.current=!1},[a,_]),d.useLayoutEffect(()=>{const z=S.current?.getBoundingClientRect();!s||!z||T.current||(L(),T.current=!0)},[s,L,T.current]),d.useLayoutEffect(()=>{L(y)},[B,s]);const ee=d.useMemo(()=>{if(!(!E||!k))return cn(k,a&&E.properties[a]?{[a]:E.properties[a]}:{},o)},[E,k,a,o]),G=d.useCallback(()=>L(y),[y,L]),q=async z=>(A(null),i&&_&&u&&a?u({value:z[a],propertyKey:a,data:_,setError:A,onValueUpdated:()=>{}}):Promise.resolve());if(!_)return r.jsx(r.Fragment,{});const j=ve.useCreateFormex({initialValues:_?.values??{},validation:z=>ee?.validate(z,{abortEarly:!1}).then(()=>({})).catch(I=>{const D={};return I.inner.forEach(ie=>{D[ie.path]=ie.message}),D}),validateOnInitialRender:!0,onSubmit:(z,I)=>{q(z).then(()=>c()).finally(()=>I.setSubmitting(!1))}}),{values:O,isSubmitting:te,setFieldValue:Z,handleSubmit:le}=j;if(d.useEffect(()=>{Y(O,x)||C(O)},[O]),!_)return r.jsx(ye,{error:"PopupFormField misconfiguration"});if(!E)return r.jsx(r.Fragment,{});const ne=te,re={collection:E,entityId:k,values:O,path:n,setFieldValue:Z,save:q,formex:j},J=a&&rt(E.properties,a),Q=a&&J?{propertyKey:a,disabled:te||pt(J)||!!J.disabled,property:J,includeDescription:!1,underlyingValueHasChanged:!1,context:re,tableMode:!0,partOfArray:!1,partOfBlock:!1,autoFocus:l}:void 0;let R=r.jsx(r.Fragment,{children:r.jsx("div",{className:"w-[560px] max-w-full max-h-[85vh]",children:r.jsxs("form",{onSubmit:le,noValidate:!0,children:[r.jsx("div",{className:"mb-1 p-4 flex flex-col relative",children:r.jsx("div",{ref:P,className:"cursor-auto",style:{cursor:"auto !important"},children:Q&&r.jsx(lt,{...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 H=m.plugins;H&&H.forEach(z=>{z.form?.provider&&(R=r.jsx(z.form.provider.Component,{status:"existing",path:n,collection:E,entity:_,context:g,currentEntityId:k,formContext:re,...z.form.provider.props,children:R}))});const $=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:[R,h&&r.jsx(p.Typography,{color:"error",children:h.message})]}),V=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(Tl,{onResize:G}),r.jsxs("div",{className:"overflow-hidden",children:[$,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:z=>{z.stopPropagation(),c()},children:r.jsx(p.ClearIcon,{className:"text-white",size:"small"})})})]})]},`draggable_${a}_${k}_${l}`);return r.jsx(Ai.Root,{asChild:!0,container:f,children:r.jsx(ve.Formex,{value:j,children:V})})}function Ml({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 i;return o&&a?i="Clear filter and sort":o?i="Clear filter":i="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,{}),i]})}return null}function Ol({collection:e,relativePath:t,parentCollectionIds:o,path:a,selectionController:i,tableController:n,collectionEntitiesCount:s}){const l=Ce(),u=se().plugins??[],f={path:a,relativePath:t,parentCollectionIds:o,collection:e,selectionController:i,context:l,tableController:n,collectionEntitiesCount:s},g=[r.jsx(Ml,{tableController:n,enabled:!e.forceFilter},"clear_filter")];return u&&u.forEach((m,h)=>{m.collectionView?.CollectionActionsStart&&g.push(...Pt(m.collectionView?.CollectionActionsStart).map((A,y)=>r.jsx(ae,{children:r.jsx(A,{...f,...m.collectionView?.collectionActionsStartProps})},`plugin_actions_${h}_${y}`)))}),r.jsx(r.Fragment,{children:g})}const zl="collectionGroupParent",bo=d.memo(function({fullPath:t,parentCollectionIds:o,isSubCollection:a,className:i,...n}){const s=Ce(),l=t??n.path,c=ze(n),u=pe(),f=at(),g=ot(),m=ht(),h=gt(),A=se(),y=d.useRef(null),b=d.useMemo(()=>{const U=m?.getCollectionConfig(l);return U?Me(n,U):n},[n,l,m?.getCollectionConfig]),k=d.useRef(b);d.useEffect(()=>{k.current=b},[b]);const _=ft(b,g,l,null),[v,x]=d.useState(void 0),[C,E]=d.useState(void 0),[B,S]=d.useState(0),[P,T]=d.useState(0),N=d.useCallback(()=>{const U=v;setTimeout(()=>{U===v&&x(void 0)},2400)},[v]),M=d.useCallback(U=>{const oe=k.current;return Or(oe,g,l,U??null)?oe.inlineEditing===void 0||oe.inlineEditing:!1},[g,l]),L=b.selectionEnabled===void 0||b.selectionEnabled,ee=!M(),[G,q]=d.useState(!1),j=uo(),O=b.selectionController??j,{selectedEntities:te,isEntitySelected:Z,setSelectedEntities:le}=O;d.useEffect(()=>{E(void 0)},[te]);const ne=po({fullPath:l,collection:b,lastDeleteTimestamp:B}),re=d.useRef(Math.random().toString(36)),J=ne.popupCell,Q=d.useCallback(()=>{ne.setPopupCell?.(void 0)},[ne.setPopupCell]),R=d.useCallback(U=>{console.log("Entity clicked",U);const oe=k.current;return x(U),h.onAnalyticsEvent?.("edit_entity_clicked",{path:U.path,entityId:U.id}),f.open({entityId:U.id,path:U.path,collection:oe,updateUrl:!0,onClose:N})},[N,f]),H=d.useCallback(()=>{const U=k.current;h.onAnalyticsEvent?.("new_entity_click",{path:l}),f.open({path:l,collection:U,updateUrl:!0,onClose:N})},[l,f]),$=()=>{h.onAnalyticsEvent?.("multiple_delete_dialog_open",{path:l}),E(te)},V=(U,oe)=>{h.onAnalyticsEvent?.("single_entity_deleted",{path:l}),le(ce=>ce.filter(de=>de.id!==oe.id)),S(Date.now())},z=(U,oe)=>{h.onAnalyticsEvent?.("multiple_entities_deleted",{path:l}),le([]),E(void 0),S(Date.now())};let I;A?.plugins&&(I=A.plugins.find(U=>U.collectionView?.AddColumnComponent)?.collectionView?.AddColumnComponent);const D=d.useCallback((U,oe)=>{if(m){const ce=m.getCollectionConfig(U),de=Me(ce,oe);m.onCollectionModified(U,de)}},[m]),ie=d.useCallback(({width:U,key:oe})=>{const ce=k.current;if(!rt(ce.properties,oe))return;const de=Nn(oe,U);D(l,de)},[D,l]),xe=d.useCallback(U=>{m&&D(l,{defaultSize:U})},[D,l,m]),Le=ft(b,g,l,null),K=d.useCallback(({name:U,value:oe,property:ce,entityId:de})=>c.checkUniqueField(l,U,oe,de),[l]),he=({value:U,propertyKey:oe,onValueUpdated:ce,setError:de,data:ue})=>{const Ye=ve.setIn({...ue.values},oe,U),et={path:l,entityId:ue.id,values:Ye,previousValues:ue.values,collection:b,status:"existing"};return Ur({...et,collection:b,dataSource:c,context:s,onSaveSuccess:()=>{de(void 0),ce()},onSaveFailure:zt=>{console.error("Save failure"),console.error(zt),de(zt)}})},Te=u.resolveAliasesFrom(l),Fe=d.useMemo(()=>Ne({collection:b,path:l,fields:A.propertyConfigs}),[b,l]),Ae=d.useCallback(({propertyKey:U,entity:oe})=>{let ce=rt(b.properties,U);return ce||(ce=rt(Fe.properties,U)),Pe({propertyKey:U,propertyOrBuilder:ce,path:l,values:oe.values,entityId:oe.id,fields:A.propertyConfigs})},[b.properties,A.propertyConfigs,l,Fe.properties]),Ge=io(Fe,!0),je=d.useMemo(()=>{const U=b.subcollections?.map(ce=>({key:ao(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:ue=>{ue.stopPropagation(),f.open({path:l,entityId:de.id,selectedSubPath:ce.id??ce.path,collection:b,updateUrl:!0})},children:ce.name})}))??[],oe=b.collectionGroup?[{key:zl,name:"Parent entities",width:260,dependencies:[],Builder:({entity:ce})=>{const de=u.getParentReferencesFromPath(ce.path);return r.jsx("div",{className:"flex flex-col gap-2 w-full",children:de.map(ue=>r.jsx(Ve,{reference:ue,size:"tiny"},ue.path+"/"+ue.id))})}}]:[];return[...b.additionalFields??[],...U,...oe]},[b,l,f]),qe=d.useCallback(()=>{S(Date.now())},[]),X=Oe(),be=({entity:U,customEntityActions:oe})=>{const ce=U?Rt(b,g,l,U):!0,de=[Cn];return Le&&de.push(mo),ce&&de.push(ho),oe&&de.push(...oe),de},wr=()=>{const U=be({}),oe=U.filter(ue=>ue.collapsed!==!1),de=U.filter(ue=>ue.collapsed===!1).length*(X?40:30);return(X?80+de:70+de)+(oe.length>0?X?40:30:0)},Mt=({entity:U,size:oe,width:ce,frozen:de})=>{const ue=Z(U),Ye=be({entity:U,customEntityActions:b.entityActions});return r.jsx(lr,{entity:U,width:ce,frozen:de,isSelected:ue,selectionEnabled:L,size:oe,highlightEntity:x,unhighlightEntity:N,collection:b,fullPath:l,actions:Ye,hideId:b?.hideIdFromCollection,onCollectionChange:qe,selectionController:O})},Re=r.jsx(p.Popover,{open:G,onOpenChange:q,enabled:!!b.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] ${b.description?"cursor-pointer":"cursor-auto"}`,onClick:b.description?U=>{q(!0),U.stopPropagation()}:void 0,children:`${b.name}`}),r.jsx(Vl,{fullPath:l,collection:b,filter:ne.filterValues,sortBy:ne.sortBy,onCountChange:T})]}),children:b.description&&r.jsx("div",{className:"m-4 text-gray-900 dark:text-white",children:r.jsx(p.Markdown,{source:b.description})})}),Ot=d.useCallback(({property:U,propertyKey:oe,onHover:ce})=>{const de=k.current;return A.plugins?r.jsx(r.Fragment,{children:A.plugins.filter(ue=>ue.collectionView?.HeaderAction).map((ue,Ye)=>{const et=ue.collectionView.HeaderAction;return r.jsx(et,{onHover:ce,propertyKey:oe,property:U,fullPath:l,collection:de,parentCollectionIds:o??[]},`plugin_header_action_${Ye}`)})}):null},[A.plugins,l,o]),Oo=I?function(){return typeof I=="function"?r.jsx(I,{fullPath:l,parentCollectionIds:o??[],collection:b}):null}:void 0,{textSearchLoading:zo,textSearchInitialised:Vo,onTextSearchClick:kt,textSearchEnabled:Go}=fo({collection:b,fullPath:Te,parentCollectionIds:o});return r.jsxs("div",{className:p.cls("overflow-hidden h-full w-full rounded-md",i),ref:y,children:[r.jsx(co,{additionalFields:je,tableController:ne,enablePopupIcon:!0,displayedColumnIds:Ge,onSizeChanged:xe,onEntityClick:R,onColumnResize:ie,onValueChange:he,tableRowActionsBuilder:Mt,uniqueFieldValidator:K,title:Re,selectionController:O,highlightedEntities:v?[v]:[],defaultSize:b.defaultSize,properties:Fe.properties,getPropertyFor:Ae,onTextSearchClick:Vo?void 0:kt,textSearchLoading:zo,textSearchEnabled:Go,actionsStart:r.jsx(Ol,{parentCollectionIds:o??[],collection:b,tableController:ne,path:l,relativePath:b.path,selectionController:O,collectionEntitiesCount:P}),actions:r.jsx(Fn,{parentCollectionIds:o??[],collection:b,tableController:ne,onMultipleDeleteClick:$,onNewClick:H,path:l,relativePath:b.path,selectionController:O,selectionEnabled:L,collectionEntitiesCount:P}),emptyComponent:_&&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:H,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:ee,inlineEditing:M(),AdditionalHeaderWidget:Ot,AddColumnComponent:Oo,getIdColumnWidth:wr,additionalIDHeaderWidget:r.jsx(Gl,{path:l,collection:b})},`collection_table_${l}`),r.jsx(Dl,{open:!!J,onClose:Q,cellRect:J?.cellRect,propertyKey:J?.propertyKey,collection:b,entity:J?.entity,tableKey:re.current,customFieldValidator:K,path:Te,onCellValueChange:he,container:y.current},`popup_form_${J?.propertyKey}_${J?.entity?.id}`),C&&r.jsx(_n,{entityOrEntitiesToDelete:C,path:l,collection:b,callbacks:b.callbacks,open:!!C,onEntityDelete:V,onMultipleEntitiesDelete:z,onClose:()=>E(void 0)})]})},(e,t)=>Y(e.fullPath,t.fullPath)&&Y(e.parentCollectionIds,t.parentCollectionIds)&&Y(e.isSubCollection,t.isSubCollection)&&Y(e.className,t.className)&&Y(e.properties,t.properties)&&Y(e.propertiesOrder,t.propertiesOrder)&&Y(e.hideIdFromCollection,t.hideIdFromCollection)&&Y(e.inlineEditing,t.inlineEditing)&&Y(e.selectionEnabled,t.selectionEnabled)&&Y(e.selectionController,t.selectionController)&&Y(e.Actions,t.Actions)&&Y(e.defaultSize,t.defaultSize)&&Y(e.initialFilter,t.initialFilter)&&Y(e.initialSort,t.initialSort)&&Y(e.textSearchEnabled,t.textSearchEnabled)&&Y(e.additionalFields,t.additionalFields)&&Y(e.sideDialogWidth,t.sideDialogWidth)&&Y(e.forceFilter,t.forceFilter));function Vl({fullPath:e,collection:t,filter:o,sortBy:a,onCountChange:i}){const n=ze(t),s=pe(),[l,c]=d.useState(void 0),[u,f]=d.useState(void 0),g=a?a[0]:void 0,m=a?a[1]:void 0,h=d.useMemo(()=>s.resolveAliasesFrom(e),[e,s.resolveAliasesFrom]);return d.useEffect(()=>{n.countEntities&&n.countEntities({path:h,collection:t,filter:o,orderBy:g,order:m}).then(c).catch(f)},[e,n.countEntities,h,t,o,g,m]),d.useEffect(()=>{i&&(f(void 0),i(l??0))},[i,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 Nn(e,t){if(e.includes(".")){const[o,...a]=e.split(".");return{properties:{[o]:Nn(a.join("."),t)}}}return{properties:{[e]:{columnWidth:t}}}}function Gl({collection:e,path:t}){const[o,a]=d.useState(!1),[i,n]=d.useState(""),s=at();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(),!!i)return a(!1),s.open({entityId:i.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=>{n(l.target.value)},value:i,className:"flex-grow bg-transparent outline-none p-1"}),r.jsx(p.Button,{variant:"outlined",disabled:!i.trim(),type:"submit",children:"Go"})]})})})})}function Yl({propertyConfig:e}){const t="h-8 w-8 p-1 rounded-full shadow text-white",o=typeof e?.property=="object"?qn(e.property):void 0;return r.jsx("div",{className:t,style:{background:e?.color??o?.color??"#888"},children:e?.Icon?Xt(e,"medium"):Xt(o,"medium")})}function Pn(){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 Ll({open:e,onAccept:t,onCancel:o,title:a,loading:i,body:n}){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}),n]}),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:i,onClick:t,children:"Ok"})]})]})}function yo({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 wo=d.createContext({hasDrawer:!1,drawerHovered:!1,drawerOpen:!1,openDrawer:()=>{throw new Error("openDrawer not implemented")},closeDrawer:()=>{throw new Error("closeDrawer not implemented")},autoOpenDrawer:!1});function pr(){return d.useContext(wo)}const Tn=function({title:t,endAdornment:o,startAdornment:a,dropDownActions:i,includeModeToggle:n=!0,className:s,style:l,user:c}){const{hasDrawer:u,drawerOpen:f,logo:g}=pr(),m=pe(),h=ot(),{mode:A,toggleMode:y}=Pa(),b=Oe(),k=c??h.user;let _;if(k&&k.photoURL)_=r.jsx(p.Avatar,{src:k.photoURL});else if(k===void 0||h.initialLoading)_=r.jsx("div",{className:"p-1 flex justify-center",children:r.jsx(p.Skeleton,{className:"w-10 h-10 rounded-full"})});else{const v=k?.displayName?k.displayName[0].toUpperCase():k?.email?k.email[0].toUpperCase():"A";_=r.jsx(p.Avatar,{children:v})}return r.jsx("div",{style:l,className:p.cls("pr-2 w-full h-16 transition-all ease-in duration-75 fixed",{"pl-[17rem]":f&&b,"pl-20":u&&!(f&&b),"z-10":b,"duration-150":f&&b},s),children:r.jsxs("div",{className:"flex flex-row gap-2 px-4 h-full items-center",children:[m&&r.jsx("div",{className:"mr-8 hidden lg:block",children:r.jsx(ge.Link,{className:"visited:text-inherit visited:dark:text-inherit",to:m?.basePath??"/",children:r.jsxs("div",{className:"flex flex-row gap-4",children:[!u&&(g?r.jsx("img",{src:g,alt:"Logo",className:p.cls("w-[32px] h-[32px] object-contain")}):r.jsx(yo,{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}),n&&r.jsx(p.IconButton,{color:"inherit","aria-label":"Open drawer",onClick:y,size:"large",children:A==="dark"?r.jsx(p.DarkModeIcon,{}):r.jsx(p.LightModeIcon,{})}),r.jsxs(p.Menu,{trigger:_,children:[k&&r.jsxs("div",{className:"px-4 py-2 mb-2",children:[k.displayName&&r.jsx(p.Typography,{variant:"body1",color:"secondary",children:k.displayName}),k.email&&r.jsx(p.Typography,{variant:"body2",color:"secondary",children:k.email})]}),i,!i&&r.jsxs(p.MenuItem,{onClick:h.signOut,children:[r.jsx(p.LogoutIcon,{}),"Log Out"]})]})]})})},jl=e=>e&&Array.isArray(e)&&e.length>0?e.map((t,o)=>t?{[Br(t)+o]:Tt()}:{}).reduce((t,o)=>({...t,...o}),{}):{};function vo({droppableId:e,addLabel:t,value:o,disabled:a=!1,buildEntry:i,size:n="medium",onInternalIdAdded:s,includeAddButton:l,newDefaultEntry:c,onValueChange:u}){const f=o&&Array.isArray(o)&&o.length>0,g=d.useRef(jl(o)),[m,h]=d.useState(f?Object.values(g.current):[]);d.useEffect(()=>{if(f&&o&&o.length!==m.length){const _=o.map((v,x)=>{const C=Br(v)+x;if(C in g.current)return g.current[C];{const E=Tt();return g.current[C]=E,E}});h(_)}},[f,m.length,o]);const A=_=>{if(_.preventDefault(),a)return;const v=Tt(),x=[...m,v];s&&s(v),h(x),u([...o??[],c])},y=_=>{const v=[...m];v.splice(_,1),h(v),u(o.filter((x,C)=>C!==_))},b=_=>{const v=Tt(),x=o[_],C=[...m.splice(0,_+1),v,...m.splice(_+1,m.length-_-1)];s&&s(v),h(C),u([...o.slice(0,_+1),x,...o.slice(_+1)])},k=_=>{if(!_.destination)return;const v=_.source.index,x=_.destination.index,C=[...m],E=C[v];C[v]=C[x],C[x]=E,h(C),u(Ul(o,v,x))};return r.jsx(ct.DragDropContext,{onDragEnd:k,children:r.jsx(ct.Droppable,{droppableId:e,renderClone:(_,v,x)=>{const C=x.source.index,E=m[C];return r.jsx(ko,{provided:_,internalId:E,index:C,size:n,disabled:a,buildEntry:i,remove:y,copy:b,isDragging:v.isDragging})},children:(_,v)=>r.jsxs("div",{..._.droppableProps,ref:_.innerRef,children:[f&&m.map((x,C)=>r.jsx(ct.Draggable,{draggableId:`array_field_${x}`,isDragDisabled:a,index:C,children:(E,B)=>r.jsx(ko,{provided:E,internalId:x,index:C,size:n,disabled:a,buildEntry:i,remove:y,copy:b,isDragging:B.isDragging})},`array_field_${x}`)),_.placeholder,l&&r.jsx("div",{className:"py-4 justify-center text-left",children:r.jsx(p.Button,{variant:"text",size:n==="small"?"small":"medium",color:"primary",disabled:a,startIcon:r.jsx(p.AddIcon,{}),onClick:A,children:t??"Add"})})]})})})}function ko({provided:e,index:t,internalId:o,size:a,disabled:i,buildEntry:n,remove:s,copy:l,isDragging:c}){const[u,f]=d.useState(!1),g=d.useCallback(()=>f(!0),[]),m=d.useCallback(()=>f(!1),[]);return r.jsx("div",{onMouseEnter:g,onMouseMove:g,onMouseLeave:m,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:n(t,o)}),r.jsx(Dn,{direction:a==="small"?"row":"column",disabled:i,remove:s,index:t,provided:e,copy:l})]})})}function Dn({direction:e,disabled:t,remove:o,index:a,provided:i,copy:n}){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,...i.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),n(a)},children:[r.jsx(p.ContentCopyIcon,{size:"small"}),"Copy"]})]})]})})}function Ul(e,t,o){const a=Array.from(e),[i]=a.splice(t,1);return a.splice(o,0,i),a}function Tt(){return Math.floor(Math.random()*Math.floor(Number.MAX_SAFE_INTEGER))}function $l({name:e,multiselect:t=!1,path:o,disabled:a,value:i,onReferenceSelected:n,onMultipleReferenceSelected:s,previewProperties:l,forceFilter:c,size:u,className:f,includeId:g,includeEntityLink:m}){const h=pe(),A=d.useMemo(()=>h.getCollection(o),[o,h.getCollection]),y=d.useCallback(x=>{if(!a&&n){const C=x?$e(x):null;n?.({reference:C,entity:x})}},[a,n]),b=d.useCallback(x=>{if(!a&&s){const C=x?x.map(E=>$e(E)):null;s({references:C,entities:x})}},[a,n]),k=At({multiselect:t,path:o,collection:A,onSingleEntitySelected:y,onMultipleEntitiesSelected:b,forceFilter:c});d.useCallback(x=>{x.stopPropagation(),t?b([]):y(null)},[n]);let _;const v=()=>{a||k.open()};return Array.isArray(i)?_=r.jsx("div",{className:"flex flex-col gap-4",children:i.map((x,C)=>r.jsx(Ve,{onClick:v,reference:x,disabled:a,previewProperties:l,size:u,includeId:g,includeEntityLink:m},`reference_preview_${C}`))}):i?.isEntityReference&&i?.isEntityReference()&&(_=r.jsx(Ve,{reference:i,onClick:v,disabled:a,previewProperties:l,size:u,includeId:g,includeEntityLink:m})),r.jsxs("div",{className:p.cls("text-sm font-medium","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",f),children:[_,!i&&r.jsx("div",{className:"justify-center text-left",children:r.jsxs(p.Button,{variant:"outlined",color:"primary",disabled:a,onClick:v,children:["Edit ",e]})})]})}const Wl=220;er&&process.env.NODE_ENV!=="production"&&Object.keys(er).forEach(e=>{p.iconKeys.includes(e)||console.warn(`The icon ${e} no longer exists. Remove it from \`iconSynonyms\``)});function ql({selectedIcon:e="",onIconSelected:t}){const[o,a]=d.useState(null),[i,n]=d.useState(""),s=d.useMemo(()=>p.debounce(c=>{if(!c||c==="")a(null);else{const u=tr.search(c);a(u.map(f=>f.key))}},Wl),[]);d.useEffect(()=>(s(i),()=>{s.clear()}),[i,s]);const l=o===null?p.coolIconKeys:o;return r.jsxs(r.Fragment,{children:[r.jsx(p.SearchBar,{autoFocus:!1,innerClassName:"w-full sticky top-0 z-10",onTextSearch:c=>n(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 Hl({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 ur({name:e,addLabel:t,value:o,disabled:a=!1,buildEntry:i,small:n,onInternalIdAdded:s,includeAddButton:l,newDefaultEntry:c=null,setFieldValue:u}){return r.jsx(vo,{droppableId:e,addLabel:t,value:o,disabled:a,buildEntry:i,size:n?"small":"medium",onInternalIdAdded:s,includeAddButton:l,newDefaultEntry:c,onValueChange:f=>u(e,f)})}function Ee({error:e,showError:t,property:o,includeDescription:a=!0,disabled:i}){const n=o.description||o.longDescription;if(!(t&&e)&&(!a||!n))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:i?"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 Be({icon:e,title:t,small:o,className:a,required:i}){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??"")+(i?" *":"")})]})}function _o({propertyKey:e,value:t,setValue:o,error:a,showError:i,disabled:n,autoFocus:s,touched:l,property:c,includeDescription:u}){const f=c.enumValues;Qe({property:c,value:t,setValue:o});const g=d.useCallback(m=>{m.stopPropagation(),m.preventDefault(),o(null)},[o]);return r.jsxs(r.Fragment,{children:[r.jsx(p.Select,{value:t!==void 0&&t!=null?t.toString():"",disabled:n,position:"item-aligned",inputClassName:p.cls("w-full"),label:r.jsx(Be,{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:m=>{const h=m?c.dataType==="number"?parseFloat(m):m:null;return o(h)},renderValue:m=>r.jsx(Ie,{enumKey:m,enumValues:f,size:"medium"}),children:f&&f.map(m=>r.jsx(p.SelectItem,{value:String(m.id),children:r.jsx(Ie,{enumKey:String(m.id),enumValues:f,size:"medium"})},m.id))}),r.jsx(Ee,{includeDescription:u,showError:i,error:a,disabled:n,property:c})]})}function Co({propertyKey:e,value:t,setValue:o,error:a,showError:i,disabled:n,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 f=Je(u.enumValues);if(!f)throw console.error(s),Error("Field misconfiguration: array field of type string or number needs to have enumValues");Qe({property:s,value:t,setValue:o});const g=!!t&&Array.isArray(t),m=d.useCallback((h,A)=>{const y=h!==void 0?Ht(f,h):void 0;return r.jsxs(Ie,{enumKey:h,enumValues:f,size:"medium",children:[y?.label??h,!A&&r.jsx("button",{className:"ml-1 ring-offset-background rounded-full outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",onMouseDown:b=>{b.preventDefault(),b.stopPropagation()},onClick:b=>{b.preventDefault(),b.stopPropagation(),o(t.filter(k=>k!==h))},children:r.jsx(p.CloseIcon,{size:"smallest"})})]},h)},[f,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:n,label:r.jsx(Be,{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=>m(h,!1),[m]),onMultiValueChange:h=>{let A;return u&&u?.dataType==="number"?A=h?h.map(y=>parseFloat(y)):[]:A=h,o(A)},children:f.map(h=>String(h.id)).map(h=>r.jsx(p.MultiSelectItem,{value:h,children:m(h,!0)},h))}),r.jsx(Ee,{includeDescription:l,showError:i,error:a,disabled:n,property:s})]})}function Qn({propertyKey:e,value:t,error:o,showError:a,disabled:i,isSubmitting:n,tableMode:s,property:l,includeDescription:c,setValue:u,setFieldValue:f}){const g=l.of;if(g.dataType!=="reference")throw Error("ArrayOfReferencesField expected a property containing references");const m=l.expanded===void 0?!0:l.expanded,h=t&&Array.isArray(t)?t.map(E=>E.id):[];Qe({property:l,value:t,setValue:u});const A=pe(),y=d.useMemo(()=>g.path?A.getCollection(g.path):void 0,[g.path]);if(!y)throw Error(`Couldn't find the corresponding collection for the path: ${g.path}`);const b=d.useCallback(E=>{console.debug("onMultipleEntitiesSelected",E),u(E.map(B=>$e(B)))},[u]),k=At({multiselect:!0,path:g.path,collection:y,onMultipleEntitiesSelected:b,selectedEntityIds:h,forceFilter:g.forceFilter}),_=d.useCallback(E=>{E.preventDefault(),k.open()},[k]),v=d.useCallback((E,B)=>{const S=t&&t.length>E?t[E]:void 0;return S?r.jsx(Ve,{disabled:!g.path,previewProperties:g.previewProperties,size:"medium",onClick:_,hover:!i,reference:S,includeId:g.includeId,includeEntityLink:g.includeEntityLink},B):r.jsx("div",{children:"Internal ERROR"})},[g.path,g.previewProperties,t]),x=r.jsx(Be,{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(ur,{value:t,addLabel:l.name?"Add reference to "+l.name:"Add reference",name:e,buildEntry:v,disabled:n,setFieldValue:f,newDefaultEntry:l.of.defaultValue}),r.jsxs(p.Button,{className:"my-4 justify-center text-left",variant:"outlined",color:"primary",disabled:n,onClick:_,children:["Edit ",l.name]})]})]});return r.jsxs(r.Fragment,{children:[!s&&r.jsx(p.ExpandablePanel,{titleClassName:p.fieldBackgroundMixin,className:p.cls("px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2",p.fieldBackgroundMixin),initiallyExpanded:m,title:x,children:C}),s&&C,r.jsx(Ee,{includeDescription:c,showError:a,error:o,disabled:i,property:l})]})}function Mn({name:e,property:t,value:o,onRemove:a,disabled:i,size:n}){return r.jsxs("div",{className:p.cls(p.paperMixin,"relative m-4 border-box flex items-center justify-center",n==="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:s=>{s.stopPropagation(),a(o)},children:r.jsx(p.RemoveIcon,{size:"small"})})})}),o&&r.jsx(ae,{children:r.jsx(we,{propertyKey:e,value:o,property:t,size:n})})]})}const Jl="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",Zl="border-dotted-gray",Xl=p.fieldBackgroundHoverMixin,Kl="pt-0 border-2 border-solid",Rl="transition-colors duration-200 ease-[cubic-bezier(0,0,0.2,1)] border-2 border-solid border-green-500",ec="transition-colors duration-200 ease-[cubic-bezier(0,0,0.2,1)] border-2 border-solid border-red-500";function xo({propertyKey:e,value:t,setValue:o,error:a,showError:i,autoFocus:n,tableMode:s,property:l,includeDescription:c,context:u,isSubmitting:f}){if(!u.entityId)throw new Error("StorageUploadFieldBinding: Entity id is null");const g=mt(u.collection),m=pt(l)||!!l.disabled||f,{internalValue:h,setInternalValue:A,onFilesAdded:y,storage:b,onFileUploadComplete:k,storagePathBuilder:_,multipleFilesSupported:v}=tn({entityValues:u.values,entityId:u.entityId,path:u.path,property:l,propertyKey:e,value:t,storageSource:g,disabled:m??!1,onChange:o});return Qe({property:l,value:t,setValue:o}),r.jsxs(r.Fragment,{children:[!s&&r.jsx(Be,{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(rc,{value:h,name:e,disabled:m??!1,autoFocus:n??!1,property:l,onChange:o,setInternalValue:A,onFilesAdded:y,onFileUploadComplete:k,storagePathBuilder:_,storage:b,multipleFilesSupported:v}),r.jsx(Ee,{includeDescription:c,showError:i,error:a,disabled:m,property:l})]})}function tc({storage:e,disabled:t,isDraggingOver:o,onFilesAdded:a,multipleFilesSupported:i,droppableProvided:n,autoFocus:s,internalValue:l,property:c,onClear:u,metadata:f,storagePathBuilder:g,onFileUploadComplete:m,size:h,name:A,helpText:y}){const b=Ze(),{getRootProps:k,getInputProps:_,isDragActive:v,isDragAccept:x,isDragReject:C}=qo.useDropzone({accept:e.acceptedFiles?e.acceptedFiles.map(E=>({[E]:[]})).reduce((E,B)=>({...E,...B}),{}):void 0,disabled:t||o,noDragEventsBubbling:!0,maxSize:e.maxSize,onDrop:a,onDropRejected:(E,B)=>{for(const S of E)for(const P of S.errors)b.open({type:"error",message:`Error uploading file: File is larger than ${e.maxSize} bytes`})}});return r.jsxs("div",{...k(),className:p.cls(p.fieldBackgroundMixin,t?p.fieldBackgroundDisabledMixin:p.fieldBackgroundHoverMixin,Jl,i&&l.length?"":"flex",p.focusedMixin,{[Xl]:!v,[Kl]:v,[ec]:C,[Rl]:x,[Zl]:t}),children:[r.jsxs("div",{...n.droppableProps,ref:n.innerRef,className:p.cls("flex items-center p-1 no-scrollbar",i&&l.length?"overflow-auto":"",i&&l.length?"min-h-[180px]":"min-h-[250px]"),children:[r.jsx("input",{autoFocus:s,..._()}),l.map((E,B)=>{let S;return E.storagePathOrDownloadUrl?S=r.jsx(Mn,{name:`storage_preview_${E.storagePathOrDownloadUrl}`,property:c,disabled:t,value:E.storagePathOrDownloadUrl,onRemove:u,size:E.size}):E.file&&(S=r.jsx(nn,{entry:E,metadata:f,storagePath:g(E.file),onFileUploadComplete:m,imageSize:h==="medium"?220:118,simple:!1})),r.jsx(ct.Draggable,{draggableId:`array_field_${A}_${E.id}`,index:B,children:(P,T)=>r.jsx("div",{tabIndex:-1,ref:P.innerRef,...P.draggableProps,...P.dragHandleProps,className:p.cls(p.focusedMixin,"rounded-md"),style:{...P.draggableProps.style},children:S})},`array_field_${A}_${E.id}`)}),n.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:y})})]})}function rc({property:e,name:t,value:o,setInternalValue:a,onChange:i,multipleFilesSupported:n,onFileUploadComplete:s,disabled:l,onFilesAdded:c,autoFocus:u,storage:f,storagePathBuilder:g}){if(n){const v=e;if(v.of){if(Array.isArray(v.of)||v.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 m=f?.metadata,h=n?"small":"medium",A=d.useCallback((v,x)=>{if(!n)return;const C=[...o],E=C[v];C.splice(v,1),C.splice(x,0,E),a(C);const B=C.filter(S=>!!S.storagePathOrDownloadUrl).map(S=>S.storagePathOrDownloadUrl);i(B)},[n,i,a,o]),y=d.useCallback(v=>{v.destination&&A(v.source.index,v.destination.index)},[A]),b=d.useCallback(v=>{if(n){const x=o.filter(C=>C.storagePathOrDownloadUrl!==v);i(x.filter(C=>!!C.storagePathOrDownloadUrl).map(C=>C.storagePathOrDownloadUrl)),a(x)}else i(null),a([])},[o,n,i]),k=n?"Drag 'n' drop some files here, or click to select files":"Drag 'n' drop a file here, or click to select one",_=n?e.of:e;return r.jsx(ct.DragDropContext,{onDragEnd:y,children:r.jsx(ct.Droppable,{droppableId:`droppable_${t}`,direction:"horizontal",renderClone:(v,x,C)=>{const E=o[C.source.index];return r.jsx("div",{ref:v.innerRef,...v.draggableProps,...v.dragHandleProps,style:v.draggableProps.style,className:"rounded",children:r.jsx(Mn,{name:`storage_preview_${E.storagePathOrDownloadUrl}`,property:_,disabled:!0,value:E.storagePathOrDownloadUrl,onRemove:b,size:E.size})})},children:(v,x)=>r.jsx(tc,{storage:f,disabled:l,isDraggingOver:x.isDraggingOver,droppableProvided:v,onFilesAdded:c,multipleFilesSupported:n,autoFocus:u,internalValue:o,property:_,onClear:b,metadata:m,storagePathBuilder:g,onFileUploadComplete:s,size:h,name:t,helpText:k})})})}function vt({context:e,propertyKey:t,value:o,setValue:a,error:i,showError:n,disabled:s,autoFocus:l,property:c,includeDescription:u}){let f,g;c.dataType==="string"&&(f=c.multiline,g=c.url),Qe({property:c,value:o,setValue:a});const m=d.useCallback(b=>{b.stopPropagation(),b.preventDefault(),a(null)},[a]),h=b=>{if(y==="number"){const k=b.target.value?parseFloat(b.target.value):void 0;k&&isNaN(k)?a(null):k!=null?a(k):a(null)}else a(b.target.value)},A=!!f,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(Be,{icon:_e(c,"small"),required:c.validation?.required,title:c.name}),type:y,multiline:A,disabled:s,endAdornment:c.clearable&&r.jsx(p.IconButton,{onClick:m,children:r.jsx(p.ClearIcon,{})}),error:n?i:void 0,inputClassName:i?"text-red-500 dark:text-red-600":""}),r.jsx(Ee,{includeDescription:u,showError:n,error:i,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 On=d.forwardRef(function({propertyKey:t,value:o,setValue:a,error:i,showError:n,autoFocus:s,disabled:l,touched:c,property:u,includeDescription:f},g){return Qe({property:u,value:o,setValue:a}),r.jsxs(r.Fragment,{children:[r.jsx(p.BooleanSwitchWithLabel,{value:o,onValueChange:m=>a(m),error:n,label:r.jsx(Be,{icon:_e(u,"small"),required:u.validation?.required,title:u.name}),disabled:l,autoFocus:s,size:"medium"}),r.jsx(Ee,{includeDescription:f,showError:n,error:i,disabled:l,property:u})]})});function zn({propertyKey:e,value:t,setValue:o,autoFocus:a,error:i,showError:n,disabled:s,touched:l,property:c,includeDescription:u}){const{locale:f}=se(),g=t||null;return Qe({property:c,value:t,setValue:o}),r.jsxs(r.Fragment,{children:[r.jsx(p.DateTimeField,{value:g,onChange:m=>o(m??null),size:"medium",mode:c.mode,clearable:c.clearable,locale:f,error:n,label:r.jsx(Be,{icon:_e(c,"small"),required:c.validation?.required,className:n?"text-red-500 dark:text-red-500":"text-text-secondary dark:text-text-secondary-dark",title:c.name})}),r.jsx(Ee,{includeDescription:u,showError:n,error:i,disabled:s,property:c})]})}function Eo({propertyKey:e,value:t,error:o,showError:a,tableMode:i,property:n,includeDescription:s,context:l}){if(!l.entityId)throw new Error("ReadOnlyFieldBinding: Entity id is null");return r.jsxs(r.Fragment,{children:[!i&&r.jsx(Be,{icon:_e(n,"small"),required:n.validation?.required,title:n.name,className:"text-text-secondary dark:text-text-secondary-dark ml-3.5"}),r.jsx("div",{className:p.cls(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:n,size:"medium"})})}),r.jsx(Ee,{includeDescription:s,showError:a,error:o,property:n})]})}function Vn(e){return typeof e.property.path!="string"?r.jsx(Eo,{...e}):r.jsx(oc,{...e})}function oc({value:e,setValue:t,error:o,showError:a,isSubmitting:i,disabled:n,touched:s,autoFocus:l,property:c,includeDescription:u,context:f}){if(!c.path)throw new Error("Property path is required for ReferenceFieldBinding");Qe({property:c,value:e,setValue:t});const g=e&&e.isEntityReference&&e.isEntityReference(),m=pe(),h=d.useMemo(()=>c.path?m.getCollection(c.path):void 0,[c.path]);if(!h)throw Error(`Couldn't find the corresponding collection for the path: ${c.path}`);const A=d.useCallback(k=>{t(k?$e(k):null)},[t]),y=At({multiselect:!1,path:c.path,collection:h,onSingleEntitySelected:A,selectedEntityIds:g?[e.id]:void 0,forceFilter:c.forceFilter}),b=d.useCallback(k=>{k.preventDefault(),y.open()},[y]);return r.jsxs(r.Fragment,{children:[r.jsx(Be,{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(Ve,{disabled:!c.path,previewProperties:c.previewProperties,hover:!n,size:"medium",onClick:n||i?void 0:b,reference:e,includeEntityLink:c.includeEntityLink,includeId:c.includeId}),!e&&r.jsx("div",{className:"justify-center text-left",children:r.jsxs(p.Button,{variant:"outlined",color:"primary",disabled:n||i,onClick:b,children:["Edit ",c.name]})})]}),r.jsx(Ee,{includeDescription:u,showError:a,error:o,disabled:n,property:c})]})}const lt=d.memo(ac,(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||Y(e.property,t.property))&&e.disabled===t.disabled)||Bo(t.property),!1});function ac({propertyKey:e,property:t,context:o,includeDescription:a,underlyingValueHasChanged:i,disabled:n,tableMode:s,partOfArray:l,partOfBlock:c,autoFocus:u}){const f=se();return r.jsx(ve.Field,{name:e,children:g=>{let m;const h=Pe({propertyKey:e,propertyOrBuilder:t,values:g.form.values,path:o.path,entityId:o.entityId,fields:f.propertyConfigs});if(h===null||$t(h))return r.jsx(r.Fragment,{});if(pt(h))m=Eo;else if(h.Field)typeof h.Field=="function"&&(m=h.Field);else{const y=Dt(h,f.propertyConfigs);if(!y)throw console.log("INTERNAL: Could not find field config for property",{propertyKey:e,resolvedProperty:h,fields:f.propertyConfigs,propertyConfig:y}),new Error(`INTERNAL: Could not find field config for property ${e}`);m=Pe({propertyOrBuilder:y.property,values:g.form.values,path:o.path,entityId:o.entityId,fields:f.propertyConfigs}).Field}if(!m)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 A={propertyKey:e,property:h,includeDescription:a,underlyingValueHasChanged:i,context:o,disabled:n,tableMode:s,partOfArray:l,partOfBlock:c,autoFocus:u};return r.jsx(nc,{Component:m,componentProps:A,fieldProps:g})}},e)}function nc({Component:e,componentProps:{propertyKey:t,property:o,includeDescription:a,underlyingValueHasChanged:i,tableMode:n,partOfArray:s,partOfBlock:l,autoFocus:c,context:u,disabled:f},fieldProps:g}){const{plugins:m}=se(),h=o.customProps,A=g.field.value,y=ve.getIn(g.form.errors,t),b=ve.getIn(g.form.touched,t),k=y&&(g.form.submitCount>0||o.validation?.unique)&&(!Array.isArray(y)||!!y.filter(S=>!!S).length),v=ic({path:u.path,collection:u.collection,propertyKey:t,property:o,Component:e,plugins:m})??e,x=g.form.isSubmitting,C=d.useCallback((S,P)=>{g.form.setFieldTouched(t,!0,!1),g.form.setFieldValue(t,S,P)},[]),E=d.useCallback((S,P,T)=>{g.form.setFieldTouched(t,!0,!1),g.form.setFieldValue(S,P,T)},[]),B={propertyKey:t,value:A,setValue:C,setFieldValue:E,error:y,touched:b,showError:k,isSubmitting:x,includeDescription:a??!0,property:o,disabled:f??!1,underlyingValueHasChanged:i??!1,tableMode:n??!1,partOfArray:s??!1,partOfBlock:l??!1,autoFocus:c??!1,customProps:h,context:u};return r.jsxs(ae,{children:[r.jsx(v,{...B}),i&&!x&&r.jsx(p.Typography,{variant:"caption",className:"ml-3.5",children:"This value has been updated elsewhere"})]})}const Bo=(e,t)=>{if(t?.some(i=>i.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(i=>Bo(i,t)):o.dataType==="array"&&"resolvedProperties"in o?a||o.resolvedProperties?.some(i=>i&&Bo(i,t)):a};function ic({path:e,collection:t,propertyKey:o,property:a,Component:i,plugins:n}){return d.useRef((()=>{let l=null;return n&&n.forEach(c=>{const u=No(a);if(u&&c.form?.fieldBuilder){const f={fieldConfigId:u,propertyKey:o,property:a,Field:i,plugin:c,path:e,collection:t},g=c.form?.fieldBuilderEnabled?.(f);(g===void 0||g)&&(l=c.form.fieldBuilder(f)||l)}u||console.warn("INTERNAL: Field id not found for property",a)}),l})()).current}function Gn({propertyKey:e,value:t,showError:o,error:a,disabled:i,property:n,partOfBlock:s,tableMode:l,includeDescription:c,underlyingValueHasChanged:u,autoFocus:f,context:g}){const m=n.pickOnlySomeKeys||!1,h=(n.expanded===void 0?!0:n.expanded)||f;if(!n.properties)throw Error(`You need to specify a 'properties' prop (or specify a custom field) in your map property ${e}`);let A;m?t?A=Xo(n.properties,...Object.keys(t).filter(k=>k in n.properties)):A={}:A=n.properties;const y=r.jsx(r.Fragment,{children:r.jsx("div",{className:"py-1 flex flex-col space-y-2",children:Object.entries(A).filter(([k,_])=>!$t(_)).map(([k,_],v)=>{const x={propertyKey:`${e}.${k}`,disabled:i,property:_,includeDescription:c,underlyingValueHasChanged:u,context:g,tableMode:!1,partOfArray:!1,partOfBlock:!1,autoFocus:f&&v===0};return r.jsx("div",{children:r.jsx(ae,{children:r.jsx(lt,{...x})})},`map-${e}-${v}`)})})}),b=r.jsx(Be,{icon:_e(n,"small"),required:n.validation?.required,title:n.name,className:"text-text-secondary dark:text-text-secondary-dark"});return r.jsxs(ae,{children:[!l&&!s&&r.jsx(p.ExpandablePanel,{initiallyExpanded:h,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:b,children:y}),(l||s)&&y,r.jsx(Ee,{includeDescription:c,showError:o??!1,error:a?typeof a=="string"?a:"A property of this map has an error":void 0,disabled:i,property:n})]})}function Yn({propertyKey:e,value:t,showError:o,error:a,disabled:i,property:n,setValue:s,tableMode:l,includeDescription:c,underlyingValueHasChanged:u,autoFocus:f,context:g}){const m=(n.expanded===void 0?!0:n.expanded)||f;if(!n.keyValue)throw Error(`Your property ${e} needs to have the 'keyValue' prop in order to use this field binding`);const h=r.jsx(So,{value:t,setValue:s,disabled:i,fieldName:n.name??e}),A=r.jsx(Be,{icon:_e(n,"small"),required:n.validation?.required,title:n.name,className:"text-text-secondary dark:text-text-secondary-dark"});return r.jsxs(r.Fragment,{children:[!l&&r.jsx(p.ExpandablePanel,{initiallyExpanded:m,title:A,className:"px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2",children:h}),l&&h,r.jsx(Ee,{includeDescription:c,showError:o,error:a,disabled:i,property:n})]})}function So({value:e,setValue:t,fieldName:o,disabled:a}){const[i,n]=d.useState(Object.keys(e??{}).map(c=>[Io(),{key:c,dataType:Fo(e?.[c])??"string"}]));d.useEffect(()=>{const c=i.map(([h,{key:A}])=>A),u=Object.entries(e??{}).filter(([h,A])=>A!==void 0).map(([h])=>h),f=u.filter(h=>!c.includes(h)),g=c.filter(h=>!u.includes(h)),m=[...i];f.forEach(h=>{m.push([Io(),{key:h,dataType:Fo(e?.[h])??"string"}])}),g.forEach(h=>{const A=m.findIndex(([y,{key:b}])=>b===h);m.splice(A,1)}),n(m)},[e]);const s=d.useRef(e??{}),l=(c,u)=>{if(!c){console.warn("No key selected for data type update");return}n(i.map(f=>f[0]===c?[f[0],{key:f[1].key,dataType:u}]:f)),t({...e??{},[i.find(f=>f[0]===c)?.[1].key??""]:Fr(u)})};return r.jsxs("div",{className:"py-1 flex flex-col gap-1",children:[i.map(([c,{key:u,dataType:f}],g)=>{const m=u?e?.[u]:"",h=A=>{if(n(i.map(b=>b[0]===c?[c,{key:A??"",dataType:b[1].dataType}]:b)),typeof e=="object"&&A in e)return;const y={...e??{}};typeof s.current=="object"&&u in s.current?y[u]=void 0:delete y[u],t({...y,[A??""]:m})};return r.jsx(sc,{rowId:c,fieldKey:u,value:e??{},onDeleteClick:()=>{const A={...e??{}};s.current&&u in s.current?A[u]=void 0:delete A[u],n(i.filter(y=>y[0]!==c)),t({...A})},onFieldKeyChange:h,setValue:t,entryValue:m,dataType:f,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}),n([...i,[Io(),{key:"",dataType:"string"}]])},children:o?`Add to ${o}`:"Add"})]})}function sc({rowId:e,fieldKey:t,value:o,onFieldKeyChange:a,onDeleteClick:i,setValue:n,entryValue:s,dataType:l,updateDataType:c,disabled:u}){const{locale:f}=se();function g(h,A,y){return y==="string"||y==="number"?r.jsx(p.TextField,{placeholder:"value",value:h,type:y==="number"?"number":"text",size:"small",disabled:u||!A,onChange:b=>{if(y==="number"){const k=b.target.value?parseFloat(b.target.value):void 0;k&&isNaN(k)?n({...o,[A]:null}):k!=null?n({...o,[A]:k}):n({...o,[A]:null})}else n({...o,[A]:b.target.value})}},y):y==="date"?r.jsx(p.DateTimeField,{value:h,size:"small",locale:f,disabled:u||!A,onChange:b=>{n({...o,[A]:b})}}):y==="boolean"?r.jsx(p.BooleanSwitchWithLabel,{value:h,size:"small",position:"start",disabled:u||!A,onValueChange:b=>{n({...o,[A]:b})}}):y==="array"?r.jsx("div",{className:p.cls(p.defaultBorderMixin,"ml-2 pl-2 border-l border-solid"),children:r.jsx(vo,{value:h,newDefaultEntry:"",droppableId:e.toString(),addLabel:A?`Add to ${A}`:"Add",size:"small",disabled:u||!A,includeAddButton:!0,onValueChange:b=>{n({...o,[A]:b})},buildEntry:(b,k)=>r.jsx(lc,{index:b,id:k,value:h[b],disabled:u||!A,setValue:_=>{const v=[...h];v[b]=_,n({...o,[A]:v})}})})}):y==="map"?r.jsx("div",{className:p.cls(p.defaultBorderMixin,"ml-2 pl-2 border-l border-solid"),children:r.jsx(So,{value:h,fieldName:A,setValue:b=>{n({...o,[A]:b})}})}):r.jsx(p.Typography,{variant:"caption",children:`Data type ${y} not supported yet`})}function m(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:()=>m("string"),children:"string"}),r.jsx(p.MenuItem,{dense:!0,onClick:()=>m("number"),children:"number"}),r.jsx(p.MenuItem,{dense:!0,onClick:()=>m("boolean"),children:"boolean"}),r.jsx(p.MenuItem,{dense:!0,onClick:()=>m("date"),children:"date"}),r.jsx(p.MenuItem,{dense:!0,onClick:()=>m("map"),children:"map"}),r.jsx(p.MenuItem,{dense:!0,onClick:()=>m("array"),children:"array"})]}),r.jsx(p.IconButton,{"aria-label":"delete",size:"small",onClick:i,className:"h-7 w-7",children:r.jsx(p.RemoveIcon,{size:"small"})})]},e.toString()),(l==="map"||l==="array")&&g(s,t,l)]})}function lc({id:e,index:t,value:o,setValue:a}){const{locale:i}=se(),[n,s]=d.useState(Fo(o)??"string");function l(u){s(u)}function c(u,f){return f==="string"||f==="number"?r.jsx(p.TextField,{value:u,type:f==="number"?"number":"text",size:"small",onChange:g=>{if(f==="number"){const m=g.target.value?parseFloat(g.target.value):void 0;m&&isNaN(m)?a(null):m!=null?a(m):a(null)}else a(g.target.value)}}):f==="date"?r.jsx(p.DateTimeField,{value:u,size:"small",locale:i,onChange:g=>{a(g)}}):f==="boolean"?r.jsx(p.BooleanSwitchWithLabel,{value:u,size:"small",position:"start",onValueChange:g=>{a(g)}}):f==="array"?r.jsx(p.Typography,{variant:"caption",children:"Arrays of arrays are not supported."}):f==="map"?r.jsx("div",{className:p.cls(p.defaultBorderMixin,"ml-2 pl-2 border-l border-solid"),children:r.jsx(So,{value:u,setValue:g=>{a(g)}})}):r.jsx(p.Typography,{variant:"caption",children:`Data type ${f} 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:n!=="map"&&c(o,n)}),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()),n==="map"&&c(o,n)]})}function Io(){return Math.floor(Math.random()*Math.floor(Number.MAX_SAFE_INTEGER))}function Fo(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 xr)return"geopoint";if(typeof e=="object")return"map"}function Ln({propertyKey:e,value:t,error:o,showError:a,isSubmitting:i,setValue:n,setFieldValue:s,tableMode:l,property:c,includeDescription:u,underlyingValueHasChanged:f,context:g,disabled:m}){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,A=c.of,[y,b]=d.useState();Qe({property:c,value:t,setValue:n});const k=(x,C)=>{const E=c.resolvedProperties[x]??A,B={propertyKey:`${e}.${x}`,disabled:m,property:E,includeDescription:u,underlyingValueHasChanged:f,context:g,tableMode:!1,partOfArray:!0,partOfBlock:!1,autoFocus:C===y};return r.jsx(ae,{children:r.jsx(lt,{...B})})},_=r.jsx(ur,{value:t,addLabel:c.name?"Add entry to "+c.name:"Add entry",name:e,setFieldValue:s,buildEntry:k,onInternalIdAdded:b,disabled:i||!!c.disabled,includeAddButton:!c.disabled,newDefaultEntry:c.of.defaultValue}),v=r.jsx(Be,{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:v,children:_}),l&&_,r.jsx(Ee,{includeDescription:u,showError:a,error:o,disabled:m,property:c})]})}function jn({propertyKey:e,value:t,error:o,showError:a,isSubmitting:i,setValue:n,setFieldValue:s,tableMode:l,property:c,includeDescription:u,underlyingValueHasChanged:f,context:g,disabled:m}){if(!c.oneOf)throw Error("ArrayOneOfField misconfiguration. Property `oneOf` not set");const h=c.expanded===void 0?!0:c.expanded;Qe({property:c,value:t,setValue:n});const[A,y]=d.useState(),b=d.useCallback((x,C)=>r.jsx(cc,{name:`${e}.${x}`,index:x,value:t[x],typeField:c.oneOf.typeField??Ct,valueField:c.oneOf.valueField??Ut,properties:c.oneOf.properties,autoFocus:C===A,context:g},`array_one_of_${x}`),[g,A,c.oneOf,e,t]),k=r.jsx(Be,{icon:_e(c,"small"),required:c.validation?.required,title:c.name,className:"text-text-secondary dark:text-text-secondary-dark"}),_=Object.keys(c.oneOf.properties)[0],v=r.jsx(ur,{value:t,name:e,addLabel:c.name?"Add entry to "+c.name:"Add entry",buildEntry:b,onInternalIdAdded:y,disabled:i||!!c.disabled,includeAddButton:!c.disabled,setFieldValue:s,newDefaultEntry:{[c.oneOf.typeField??Ct]:_,[c.oneOf.valueField??Ut]:Wt(c.oneOf.properties[_])}});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:v}),l&&v,r.jsx(Ee,{includeDescription:u,showError:a,error:o,disabled:m,property:c})]})}function cc({name:e,index:t,value:o,typeField:a,valueField:i,properties:n,autoFocus:s,context:l}){const c=o&&o[a],[u,f]=d.useState(c??void 0),g=ve.useFormex();d.useEffect(()=>{c||k(Object.keys(n)[0])},[]),d.useEffect(()=>{c!==u&&f(c)},[c]);const m=u?n[u]:void 0,h=Object.entries(n).map(([_,v])=>({id:_,label:v.name??_})),A=`${e}.${a}`,y=`${e}.${i}`,b=m?{propertyKey:y,property:m,context:l,autoFocus:s,partOfArray:!1,partOfBlock:!0,tableMode:!1}:void 0,k=_=>{const v=_?n[_]:void 0;f(_),g.setFieldTouched(A,!0),g.setFieldValue(A,_),g.setFieldValue(y,v?Wt(v):null)};return r.jsxs("div",{className:p.cls(p.paperMixin,"bg-transparent p-4 my-4 py-8"),children:[r.jsx(ve.Field,{name:A,children:_=>{const v=_.field.value!==void 0&&_.field.value!==null?_.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:v,renderValue:x=>r.jsx(Ie,{enumKey:x,enumValues:h,size:"small"}),onValueChange:x=>{k(x)},children:h.map(x=>r.jsx(p.SelectItem,{value:String(x.id),children:r.jsx(Ie,{enumKey:x.id,enumValues:h,size:"small"})},x.id))})})}}),b&&r.jsx(lt,{...b},`form_control_${e}_${u}`)]})}const dc=new mi;try{tt.use(tt.Plugins.AutoResize,{min:100}),tt.unuse(tt.Plugins.FontUnderline),tt.unuse(tt.Plugins.Clear)}catch{}function Un({propertyKey:e,value:t,setValue:o,error:a,showError:i,disabled:n,autoFocus:s,touched:l,property:c,tableMode:u,includeDescription:f,context:g}){const[m,h]=d.useState(t),A=d.useRef(t);p.useInjectStyles("MarkdownFieldBinding",pc);const y=d.useDeferredValue({internalValue:m,value:t});return d.useEffect(()=>{A.current=t,h(t)},[t]),d.useEffect(()=>{y.internalValue!==A.current&&o(y.internalValue)},[y]),r.jsxs(r.Fragment,{children:[!u&&r.jsx(p.Typography,{variant:"caption",className:"flex-grow",children:r.jsx(Be,{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(tt,{value:m??"",className:p.cls(p.fieldBackgroundMixin,n?p.fieldBackgroundDisabledMixin:p.fieldBackgroundHoverMixin,"text-base"),readOnly:n,renderHTML:b=>dc.render(b),view:{menu:!0,md:!0,html:!1},onChange:({html:b,text:k})=>{h(k??null)}}),r.jsx(Ee,{includeDescription:f,showError:i,error:a,disabled:n,property:c})]})}const pc=`
5
+ `))&&u(h)},onFocus:()=>{f.current=!0},onBlur:()=>{f.current=!1,g()}})}function eo(e){const{name:t,enumValues:o,error:a,internalValue:i,disabled:n,small:s,focused:l,updateValue:c,multiple:u,valueType:f}=e,g=Array.isArray(i)&&u||!Array.isArray(i)&&!u,m=d.useRef(null);d.useEffect(()=>{m.current&&l&&m.current?.focus({preventScroll:!0})},[l,m]);const h=d.useCallback(y=>{if(f==="number")if(u){const b=y.map(k=>parseFloat(k));c(b)}else c(parseFloat(y));else if(f==="string")c(y||null);else throw Error("Missing mapping in TableSelect")},[u,c,f]),A=(y,b)=>u&&Array.isArray(y)?r.jsx(Zr,{value:y,name:t,enumValues:o,size:s?"small":"medium"},`${y}-${b}`):r.jsx(Ie,{enumKey:y,enumValues:o,size:s?"small":"medium"},`${y}-${b}`);return u?r.jsx(p.MultiSelect,{inputRef:m,containerClassName:"w-full h-full",className:"w-full h-full p-0 bg-transparent",position:"item-aligned",disabled:n,padding:!1,includeFocusOutline:!1,value:g?i.map(y=>y.toString()):[],onMultiValueChange:h,renderValue:A,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:m,className:"w-full h-full p-0 bg-transparent",position:"item-aligned",disabled:n,multiple:u,padding:!1,includeFocusOutline:!1,value:g?u?i.map(y=>y.toString()):i?.toString():u?[]:"",onValueChange:h,onMultiValueChange:h,renderValue:A,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 Ds(e){const{align:t,value:o,updateValue:a,focused:i}=e,n=o&&typeof o=="number"?o.toString():"",[s,l]=d.useState(n),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!==n)if(s!=null){const m=parseFloat(s);if(isNaN(m))return;m!=null&&a(m)}else a(null)},[s,o]);Zt(s,u,!i,2e3),d.useEffect(()=>{!i&&n!==s&&l(o!=null?o.toString():null)},[o,i]);const f=d.useRef(null);d.useEffect(()=>{f.current&&i&&f.current.focus({preventScroll:!0})},[i,f]);const g=/^-?[0-9]+[,.]?[0-9]*$/;return r.jsx("input",{ref:f,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:m=>{const h=m.target.value.replace(",",".");h.length===0&&l(null),(g.test(h)||h.startsWith("-"))&&l(h)}})}function Qs(e){const{internalValue:t,updateValue:o,focused:a}=e,i=d.useRef(null);return d.useEffect(()=>{i.current&&a&&i.current.focus({preventScroll:!0})},[a,i]),r.jsx(p.BooleanSwitch,{ref:i,size:"small",value:!!t,onValueChange:o})}function Ms(e){const{locale:t}=se(),{disabled:o,error:a,mode:i,internalValue:n,updateValue:s}=e;return r.jsx(p.DateTimeField,{value:n??void 0,onChange:l=>s(l??null),size:"medium",invisible:!0,className:"w-full h-full",inputClassName:"w-full h-full",mode:i,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 Os({input:e,storage:t,values:o,entityId:a,path:i,property:n,file:s,propertyKey:l}){let c;return typeof e=="function"?(c=await e({path:i,entityId:a,values:o,property:n,file:s,storage:t,propertyKey:l}),c||console.warn("Storage callback returned empty result. Using default name value")):c=en({file:s,input:e,entityId:a,propertyKey:l,path:i}),c||(c=ut()+"_"+s.name),c}function zs({input:e,storage:t,values:o,entityId:a,path:i,property:n,file:s,propertyKey:l}){let c;return typeof e=="function"?(c=e({path:i,entityId:a,values:o,property:n,file:s,storage:t,propertyKey:l}),c||console.warn("Storage callback returned empty result. Using default name value")):c=en({file:s,input:e,entityId:a,propertyKey:l,path:i}),c||(c=ut()+"_"+s.name),c}function en({file:e,input:t,entityId:o,propertyKey:a,path:i}){const n=e.name.split(".").pop();let s=t.replace("{entityId}",o).replace("{propertyKey}",a).replace("{rand}",ut()).replace("{file}",e.name).replace("{file.type}",e.type);if(i&&(s=s.replace("{path}",i)),n){s=s.replace("{file.ext}",n);const l=e.name.replace(`.${n}`,"");s=s.replace("{file.name}",l)}return s||(s=ut()+"_"+e.name),s}function tn({entityId:e,entityValues:t,path:o,value:a,property:i,propertyKey:n,storageSource:s,disabled:l,onChange:c}){const u=i.dataType==="string"?i.storage:i.dataType==="array"&&i.of.dataType==="string"?i.of.storage:void 0,f=i.dataType==="array";if(!u)throw Error("Storage meta must be specified");const g=u?.metadata,m=f?"small":"medium",h=u?.imageCompression,A=(f?a??[]:a?[a]:[]).map(B=>({id:to(),storagePathOrDownloadUrl:B,metadata:g,size:m})),[y,b]=d.useState(a),[k,_]=d.useState(A);d.useEffect(()=>{Y(y,a)||(b(a),_(A))},[A,a,y]);const v=d.useCallback(async B=>{if(u.fileName){const S=await Os({input:u.fileName,storage:u,values:t,entityId:e,path:o,property:i,file:B,propertyKey:n});if(!S||S.length===0)throw Error("You need to return a valid filename");return S}return ut()+"_"+B.name},[e,t,o,i,n,u]),x=d.useCallback(B=>zs({input:u.storagePath,storage:u,values:t,entityId:e,path:o,property:i,file:B,propertyKey:n})??"/",[e,t,o,i,n,u]),C=d.useCallback(async(B,S,P)=>{console.debug("onFileUploadComplete",B,S);let T=B;if(u.storeUrl&&(T=(await s.getDownloadURL(B)).url),u.postProcess&&T&&(T=await u.postProcess(T)),!T){console.warn("uploadPathOrDownloadUrl is null");return}let N;S.storagePathOrDownloadUrl=T,S.metadata=P,N=[...k],N=rn(N),_(N);const M=N.filter(L=>!!L.storagePathOrDownloadUrl).map(L=>L.storagePathOrDownloadUrl);c(f?M:M?M[0]:null)},[k,f,c,u,s]),E=d.useCallback(async B=>{if(!B.length||l)return;let S;if(f)S=[...k,...await Promise.all(B.map(async P=>(h&&ro(P)&&(P=await an(P,h)),{id:to(),file:P,fileName:await v(P),metadata:g,size:m})))];else{let P=B[0];h&&ro(P)&&(P=await an(P,h)),S=[{id:to(),file:P,fileName:await v(P),metadata:g,size:m}]}S=rn(S),_(S)},[l,v,k,g,f,m]);return{internalValue:k,setInternalValue:_,storage:u,fileNameBuilder:v,storagePathBuilder:x,onFileUploadComplete:C,onFilesAdded:E,multipleFilesSupported:f}}function rn(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 to(){return Math.floor(Math.random()*Math.floor(Number.MAX_SAFE_INTEGER))}const on={"image/jpeg":"JPEG","image/png":"PNG","image/webp":"WEBP"},ro=e=>on[e.type]?on[e.type]:null,Vs=100,an=(e,t)=>new Promise(o=>{const a=t.quality===void 0?Vs:t.quality,i=a>=0&&a<=100?a:100,n=ro(e);if(!n)throw Error("resizeAndCompressImage: Unsupported image format");di.imageFileResizer(e,t.maxWidth||Number.MAX_VALUE,t.maxHeight||Number.MAX_VALUE,n,i,0,s=>o(s),"file")});function nn({storagePath:e,entry:t,metadata:o,onFileUploadComplete:a,imageSize:i,simple:n}){const s=mt(),l=Ze(),[c,u]=d.useState(),[f,g]=d.useState(!1),m=d.useRef(!1),h=d.useRef(!1),A=d.useCallback((y,b)=>{h.current||(h.current=!0,u(void 0),g(!0),s.uploadFile({file:y,fileName:b,path:e,metadata:o}).then(async({path:k})=>{console.debug("Upload successful",k),await a(k,t,o),m.current&&g(!1)}).catch(k=>{console.warn("Upload error",k),m.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(()=>(m.current=!0,t.file&&A(t.file,t.fileName),()=>{m.current=!1}),[t.file,t.fileName,A]),n?r.jsx("div",{className:`m-4 w-${i} h-${i}`,children:f&&r.jsx(p.Skeleton,{className:`w-${i} h-${i}`})}):r.jsxs("div",{className:p.cls(p.paperMixin,"relative m-4 border-box flex items-center justify-center",`min-w-[${i}px] min-h-[${i}px]`),children:[f&&r.jsx(p.Skeleton,{className:"w-full h-full"}),c&&r.jsx(ye,{title:"Error uploading file",error:c})]})}function sn({showError:e,disabled:t,showExpandIcon:o,selected:a,openPopup:i,children:n}){const s=d.useRef(null),l=d.useCallback(()=>{if(i){const u=s&&s?.current?.getBoundingClientRect();i(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&&n,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(ra,{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 Gs="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",Ys="pt-0 border-2 border-solid",Ls="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",js="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 Us(e){const{propertyKey:t,error:o,selected:a,openPopup:i,value:n,disabled:s,property:l,entity:c,path:u,previewSize:f,updateValue:g}=e,m=mt(),{internalValue:h,setInternalValue:A,onFilesAdded:y,storage:b,onFileUploadComplete:k,storagePathBuilder:_,multipleFilesSupported:v}=tn({entityValues:c.values,entityId:c.id,path:u,property:l,propertyKey:t,storageSource:m,onChange:g,value:n,disabled:s});return r.jsx($s,{internalValue:h,setInternalValue:A,name:t,disabled:s,autoFocus:!1,openPopup:i,error:o,selected:a,property:l,onChange:g,entity:c,storagePathBuilder:_,storage:b,multipleFilesSupported:v,onFilesAdded:y,onFileUploadComplete:k,previewSize:f})}function $s({property:e,name:t,internalValue:o,setInternalValue:a,openPopup:i,entity:n,selected:s,error:l,onChange:c,multipleFilesSupported:u,previewSize:f,disabled:g,autoFocus:m,storage:h,onFilesAdded:A,onFileUploadComplete:y,storagePathBuilder:b}){const[k,_]=d.useState(!1),v=u&&f==="medium"?"small":f;if(u){const O=e;if(Array.isArray(O.of))throw Error("Using array properties instead of single one in `of` in ArrayProperty");if(O.of){if(O.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 x=h?.metadata,C=!!o,E=Ze(),{open:B,getRootProps:S,getInputProps:P,isDragActive:T,isDragAccept:N,isDragReject:M}=qo.useDropzone({accept:h.acceptedFiles?h.acceptedFiles.map(O=>({[O]:[]})).reduce((O,te)=>({...O,...te}),{}):void 0,disabled:g,maxSize:h.maxSize,noClick:!0,noKeyboard:!0,onDrop:A,onDropRejected:(O,te)=>{for(const Z of O)for(const le of Z.errors)E.open({type:"error",message:`Error uploading file: File is larger than ${h.maxSize} bytes`})}}),{...L}=S(),ee=u?"Drag 'n' drop some files here, or click here to edit":"Drag 'n' drop a file here, or click here edit",G=u?e.of:e,q=d.useMemo(()=>bt(v),[v]),j=!g&&l;return r.jsxs("div",{...L,onMouseEnter:()=>_(!0),onMouseMove:()=>_(!0),onMouseLeave:()=>_(!1),className:p.cls(Gs,"relative w-full h-full flex",`justify-${C?"start":"center"}`,T?Ys:"",N?Ls:"",M?js:""),children:[r.jsx("input",{autoFocus:m,...P()}),o.map((O,te)=>{let Z;return O.storagePathOrDownloadUrl?Z=r.jsx(Ws,{property:G,value:O.storagePathOrDownloadUrl,entity:n,size:v},`storage_preview_${te}`):O.file&&(Z=r.jsx(nn,{entry:O,metadata:x,storagePath:b(O.file),onFileUploadComplete:y,imageSize:q,simple:!0},`storage_progress_${te}`)),Z}),!o&&r.jsx("div",{className:"flex-grow m-2 max-w-[200px]",onClick:B,children:r.jsx(p.Typography,{className:"text-gray-400 dark:text-gray-600",variant:"body2",align:"center",children:ee})}),r.jsx(sn,{showError:j,disabled:g,showExpandIcon:!0,selected:s,openPopup:g?void 0:i,children:r.jsx(p.IconButton,{color:"inherit",size:"small",onClick:B,children:r.jsx(p.EditIcon,{size:"small",className:"text-gray-500"})})})]})}function Ws({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 ln(e){const t=se(),o=pe(),{path:a}=e,i=o.getCollection(a);if(!i){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(qs,{...e,collection:i})}const qs=d.memo(function(t){const{name:o,internalValue:a,updateValue:i,multiselect:n,path:s,size:l,previewProperties:c,title:u,disabled:f,forceFilter:g,collection:m,includeId:h,includeEntityLink:A}=t,y=d.useCallback(B=>{i(B?$e(B):null)},[i]),b=d.useCallback(B=>{i(B.map(S=>$e(S)))},[i]),k=a?Array.isArray(a)?a.map(B=>B.id):a.id?[a.id]:[]:[],_=At({multiselect:n,path:s,collection:m,onMultipleEntitiesSelected:b,onSingleEntitySelected:y,selectedEntityIds:k,forceFilter:g}),v=d.useCallback(()=>{f||_.open()},[f,_]),x=!a||Array.isArray(a)&&a.length===0,C=()=>a&&!Array.isArray(a)&&a.isEntityReference&&a.isEntityReference()?r.jsx(Ve,{onClick:f?void 0:v,size:Xe(l),reference:a,hover:!f,disabled:!s,previewProperties:c,includeId:h,includeEntityLink:A}):r.jsx(yt,{onClick:f?void 0:v,size:Xe(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((B,S)=>r.jsx("div",{className:"w-full my-0.5",children:r.jsx(Ve,{onClick:f?void 0:v,size:"tiny",reference:B,hover:!f,disabled:!s,previewProperties:c,includeId:h,includeEntityLink:A})},`preview_array_ref_${o}_${S}`))}):r.jsx(ye,{error:"Data is not an array of references"});return m?r.jsxs("div",{className:"w-full group",children:[a&&!n&&C(),a&&n&&E(),x&&r.jsxs(p.Button,{onClick:v,size:"small",variant:"outlined",color:"primary",children:["Edit ",u]})]}):r.jsx(ye,{error:"The specified collection does not exist"})},Y);Se.addMethod(Se.array,"uniqueInArray",function(e=o=>o,t){return this.test("uniqueInArray",t,o=>!o||o.length===new Set(o.map(e)).size)});function cn(e,t,o){const a={};return Object.entries(t).forEach(([i,n])=>{a[i]=Ft({property:n,customFieldValidator:o,name:i,entityId:e})}),Se.object().shape(a)}function Ft(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 Js(e);if(t.dataType==="number")return Zs(e);if(t.dataType==="boolean")return el(e);if(t.dataType==="map")return Hs(e);if(t.dataType==="array")return rl(e);if(t.dataType==="date")return Ks(e);if(t.dataType==="geopoint")return Xs(e);if(t.dataType==="reference")return Rs(e);throw console.error("Unsupported data type in yup mapping",t),Error("Unsupported data type in yup mapping")}function Hs({property:e,entityId:t,customFieldValidator:o,name:a}){const i={},n=e.validation;e.properties&&Object.entries(e.properties).forEach(([l,c])=>{i[l]=Ft({property:c,parentProperty:e,customFieldValidator:o,name:`${a}[${l}]`,entityId:t})});const s=Se.object().shape(i);return n?.required?s.required(n?.requiredMessage?n.requiredMessage:"Required").nullable(!0):Se.object().shape(s.fields).default(void 0).notRequired().nullable(!0)}function Js({property:e,parentProperty:t,customFieldValidator:o,name:a,entityId:i}){let n=Se.string();const s=e.validation;if(e.enumValues){s?.required&&(n=n.required(s?.requiredMessage?s.requiredMessage:"Required"));const l=Je(e.enumValues);n=n.oneOf((s?.required?l:[...l,null]).map(c=>c?.id??null)).nullable(!0)}if(s){if(n=s.required?n.required(s?.requiredMessage?s.requiredMessage:"Required").nullable(!0):n.notRequired().nullable(!0),s.unique&&o&&a&&(n=n.test("unique","This value already exists and should be unique",(l,c)=>o({name:a,property:e,parentProperty:t,value:l,entityId:i}))),(s.min||s.min===0)&&(n=n.min(s.min,`${e.name} must be min ${s.min} characters long`)),(s.max||s.max===0)&&(n=n.max(s.max,`${e.name} must be max ${s.max} characters long`)),s.matches){const l=typeof s.matches=="string"?sa(s.matches):s.matches;l&&(n=n.matches(l,s.matchesMessage?{message:s.matchesMessage}:void 0))}s.trim&&(n=n.trim()),s.lowercase&&(n=n.lowercase()),s.uppercase&&(n=n.uppercase()),e.email&&(n=n.email(`${e.name} must be an email`)),e.url&&(n=n.url(`${e.name} must be a url`))}else n=n.notRequired().nullable(!0);return n}function Zs({property:e,parentProperty:t,customFieldValidator:o,name:a,entityId:i}){const n=e.validation;let s=Se.number().typeError("Must be a number");return n?(s=n.required?s.required(n.requiredMessage?n.requiredMessage:"Required").nullable(!0):s.notRequired().nullable(!0),n.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:i}))),(n.min||n.min===0)&&(s=s.min(n.min,`${e.name} must be higher or equal to ${n.min}`)),(n.max||n.max===0)&&(s=s.max(n.max,`${e.name} must be lower or equal to ${n.max}`)),(n.lessThan||n.lessThan===0)&&(s=s.lessThan(n.lessThan,`${e.name} must be higher than ${n.lessThan}`)),(n.moreThan||n.moreThan===0)&&(s=s.moreThan(n.moreThan,`${e.name} must be lower than ${n.moreThan}`)),n.positive&&(s=s.positive(`${e.name} must be positive`)),n.negative&&(s=s.negative(`${e.name} must be negative`)),n.integer&&(s=s.integer(`${e.name} must be an integer`))):s=s.notRequired().nullable(!0),s}function Xs({property:e,parentProperty:t,customFieldValidator:o,name:a,entityId:i}){let n=Se.object();const s=e.validation;return s?.unique&&o&&a&&(n=n.test("unique","This value already exists and should be unique",l=>o({name:a,property:e,parentProperty:t,value:l,entityId:i}))),s?.required?n=n.required(s.requiredMessage).nullable(!0):n=n.notRequired().nullable(!0),n}function Ks({property:e,parentProperty:t,customFieldValidator:o,name:a,entityId:i}){if(e.autoValue)return Se.object().nullable();let n=Se.date();const s=e.validation;return s?(n=s.required?n.required(s?.requiredMessage?s.requiredMessage:"Required"):n.notRequired(),s.unique&&o&&a&&(n=n.test("unique","This value already exists and should be unique",l=>o({name:a,property:e,parentProperty:t,value:l,entityId:i}))),s.min&&(n=n.min(s.min,`${e.name} must be after ${s.min}`)),s.max&&(n=n.max(s.max,`${e.name} must be before ${s.min}`))):n=n.notRequired(),n.transform(l=>l instanceof Date?l:null).nullable()}function Rs({property:e,parentProperty:t,customFieldValidator:o,name:a,entityId:i}){let n=Se.object();const s=e.validation;return s?(n=s.required?n.required(s?.requiredMessage?s.requiredMessage:"Required").nullable(!0):n.notRequired().nullable(!0),s.unique&&o&&a&&(n=n.test("unique","This value already exists and should be unique",l=>o({name:a,property:e,parentProperty:t,value:l,entityId:i})))):n=n.notRequired().nullable(!0),n}function el({property:e,parentProperty:t,customFieldValidator:o,name:a,entityId:i}){let n=Se.boolean();const s=e.validation;return s?(n=s.required?n.required(s?.requiredMessage?s.requiredMessage:"Required").nullable(!0):n.notRequired().nullable(!0),s.unique&&o&&a&&(n=n.test("unique","This value already exists and should be unique",l=>o({name:a,property:e,parentProperty:t,value:l,entityId:i})))):n=n.notRequired().nullable(!0),n}function tl(e){return e.validation?.uniqueInArray?!0:e.dataType==="map"&&e.properties?Object.entries(e.properties).filter(([t,o])=>o.validation?.uniqueInArray):!1}function rl({property:e,parentProperty:t,customFieldValidator:o,name:a,entityId:i}){let n=Se.array();if(e.of)if(Array.isArray(e.of)){const l=e.of.map((c,u)=>({[`${a}[${u}]`]:Ft({property:c,parentProperty:e,entityId:i})})).reduce((c,u)=>({...c,...u}),{});return Se.array().of(Se.mixed().test("Dynamic object validation","Dynamic object validation error",(c,u)=>Ue(l,u.path).validate(c)))}else{n=n.of(Ft({property:e.of,parentProperty:e,entityId:i}));const l=tl(e.of);l&&(typeof l=="boolean"?n=n.uniqueInArray(c=>c,`${e.name} should have unique values within the array`):Array.isArray(l)&&l.forEach(([c,u])=>{n=n.uniqueInArray(f=>f&&f[c],`${e.name} → ${u.name??c}: should have unique values within the array`)}))}const s=e.validation;return s?(n=s.required?n.required(s?.requiredMessage?s.requiredMessage:"Required").nullable(!0):n.notRequired().nullable(!0),(s.min||s.min===0)&&(n=n.min(s.min,`${e.name} should be min ${s.min} entries long`)),s.max&&(n=n.max(s.max,`${e.name} should be max ${s.max} entries long`))):n=n.notRequired().nullable(!0),n}function ir(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 ol=({justifyContent:e,scrollable:t,faded:o,fullHeight:a,children:i})=>r.jsx("div",{className:p.cls("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:i}),sr=d.memo(function({children:t,actions:o,size:a,selected:i,disabled:n,disabledTooltip:s,saved:l,error:c,align:u,allowScroll:f,removePadding:g,fullHeight:m,onSelect:h,width:A,hideOverflow:y=!0,showExpandIcon:b=!0}){const[k,_]=Wo(),v=d.useRef(null),x=d.useMemo(()=>ir(a),[a]),[C,E]=d.useState(!1),[B,S]=d.useState(l),P=!n&&!!c;d.useEffect(()=>{l&&S(!0);const le=setTimeout(()=>{S(!1)},800);return()=>{clearTimeout(le)}},[l]);let T=0;if(!g)switch(a){case"l":case"xl":T=4;break;case"m":T=2;break;case"s":default:T=1;break}let N;switch(u){case"right":N="flex-end";break;case"center":N="center";break;case"left":default:N="flex-start"}const M=d.useCallback(()=>{if(!h)return;const le=v&&v?.current?.getBoundingClientRect();n?h(void 0):!i&&le&&h(le)},[v,h,i,n]),L=d.useCallback(le=>{M(),le.stopPropagation()},[M]),ee=d.useMemo(()=>_?_.height>x:!1,[_,x]),G=!P&&i,q=!n&&f&&ee,j=!n&&!f&&ee,O=d.useCallback(()=>E(!0),[]),te=d.useCallback(()=>E(!1),[]),Z=P?"border-red-500":B?"border-green-500":G?"border-primary":"border-transparent";return r.jsxs("div",{className:p.cls("transition-colors duration-100 ease-in-out",`flex relative h-full rounded-md p-${T} border border-4 border-opacity-75`,C&&!n?"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":"",G?"bg-gray-50 dark:bg-gray-900":"",Z),ref:v,style:{justifyContent:N,alignItems:n||!ee?"center":void 0,width:A??"100%",textAlign:u},tabIndex:i||n?void 0:0,onFocus:L,onMouseEnter:O,onMouseMove:O,onMouseLeave:te,children:[r.jsxs(ae,{children:[m&&!j&&t,(!m||j)&&r.jsx(ol,{fullHeight:m??!1,justifyContent:N,scrollable:q??!1,faded:j,children:!m&&r.jsx("div",{ref:k,style:{display:"flex",width:"100%",justifyContent:N,height:m?"100%":void 0},children:t})})]}),o,n&&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),oo=d.createContext({}),dn=()=>d.useContext(oo);function Qe({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 al(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 pn=d.memo(function({propertyKey:t,customFieldValidator:o,value:a,property:i,align:n,width:s,height:l,path:c,entity:u,readonly:f,disabled:g,enablePopupIcon:m=!0}){const{onValueChange:h,size:A,selectedCell:y,select:b,setPopupCell:k}=dn(),_=y?.propertyKey===t&&y?.entity.path===u.path&&y?.entity.id===u.id,[v,x]=d.useState(a),C=d.useRef(a),[E,B]=d.useState(),[S,P]=d.useState(),[T,N]=d.useState(!1),M=d.useCallback(()=>{N(!0),setTimeout(()=>{N(!1)},100)},[]),L=!!i.Field,ee=!!i.Preview,G=pt(i),q=typeof i.disabled=="object"?i.disabled.disabledMessage:void 0,j=f||g||!!i.disabled,O=d.useMemo(()=>Ft({property:i,entityId:u.id,customFieldValidator:o,name:t}),[u.id,i,t]);d.useEffect(()=>{Y(a,C.current)||(P(void 0),x(a),C.current=a,M())},[M,a]);const te=I=>{Y(I,C.current)||(N(!1),O.validate(I).then(()=>{if(P(void 0),C.current=I,h)try{h({value:I,propertyKey:t,setError:B,onValueUpdated:M,data:u})}catch(D){console.error("onValueChange error",D),B(D)}}).catch(D=>{P(D)}))};d.useEffect(()=>{O.validate(v).then(()=>P(void 0)).catch(P)},[v,O,t,i,u]);const Z=I=>{let D;I===void 0?D=null:D=I,x(D),te(D)};Qe({property:i,value:v,setValue:Z});const le=d.useCallback(I=>{b(I?{width:s,height:l,entity:u,cellRect:I,propertyKey:t}:void 0)},[u,l,t,b,s]),ne=I=>{k&&k(I?{width:s,height:l,entity:u,cellRect:I,propertyKey:t}:void 0)};let re,J=!1,Q=!1,R=!0,H=!1,$=!1,V=!0;const z=!j&&E;if(f||G)return r.jsx(sr,{size:A,width:s,saved:T,value:v,align:n??"left",fullHeight:!1,disabledTooltip:q??(G?"Read only":void 0),disabled:!0,children:r.jsx(we,{width:s,height:ir(A),propertyKey:t,property:i,value:v,size:Xe(A)})},`${t}_${u.path}_${u.id}`);if(!L&&(!ee||_)){if(al(i))re=r.jsx(Us,{error:S??E,disabled:j,focused:_,selected:_,openPopup:k?ne:void 0,property:i,entity:u,path:c,value:v,previewSize:Xe(A),updateValue:Z,propertyKey:t}),V=!1,Q=!0,$=!0,H=!0;else if(_&&i.dataType==="number"){const D=i;D.enumValues?(re=r.jsx(eo,{name:t,multiple:!1,disabled:j,focused:_,valueType:"number",small:Xe(A)!=="medium",enumValues:D.enumValues,error:S??E,internalValue:v,updateValue:Z}),$=!0):(re=r.jsx(Ds,{align:n,error:S??E,focused:_,disabled:j,value:v,updateValue:Z}),J=!0)}else if(_&&i.dataType==="string"){const D=i;if(D.enumValues)re=r.jsx(eo,{name:t,multiple:!1,focused:_,disabled:j,valueType:"string",small:Xe(A)!=="medium",enumValues:D.enumValues,error:S??E,internalValue:v,updateValue:Z}),$=!0;else if(!D.storage){const ie=!!D.multiline||!!D.markdown;re=r.jsx(Ts,{error:S??E,disabled:j,multiline:ie,focused:_,value:v,updateValue:Z}),J=!0}}else if(i.dataType==="boolean")re=r.jsx(Qs,{error:S??E,disabled:j,focused:_,internalValue:v,updateValue:Z});else if(i.dataType==="date")re=r.jsx(Ms,{name:t,error:S??E,disabled:j,mode:i.mode,focused:_,internalValue:v,updateValue:Z}),$=!0,R=!1,J=!1;else if(i.dataType==="reference")typeof i.path=="string"&&(re=r.jsx(ln,{name:t,internalValue:v,updateValue:Z,disabled:j,size:A,path:i.path,multiselect:!1,previewProperties:i.previewProperties,includeId:i.includeId,includeEntityLink:i.includeEntityLink,title:i.name,forceFilter:i.forceFilter})),J=!1;else if(i.dataType==="array"){const D=i;if(!D.of&&!D.oneOf)throw Error(`You need to specify an 'of' or 'oneOf' prop (or specify a custom field) in your array property ${t}`);D.of&&!Array.isArray(D.of)&&(D.of.dataType==="string"||D.of.dataType==="number"?_&&D.of.enumValues&&(re=r.jsx(eo,{name:t,multiple:!0,disabled:j,focused:_,small:Xe(A)!=="medium",valueType:D.of.dataType,enumValues:D.of.enumValues,error:S??E,internalValue:v,updateValue:Z}),J=!0,$=!0,R=!1):D.of.dataType==="reference"&&(typeof D.of.path=="string"&&(re=r.jsx(ln,{name:t,disabled:j,internalValue:v,updateValue:Z,size:A,multiselect:!0,path:D.of.path,previewProperties:D.of.previewProperties,title:D.name,forceFilter:D.of.forceFilter,includeId:D.of.includeId,includeEntityLink:D.of.includeEntityLink})),J=!1))}}return re||(J=!1,Q=m&&_&&!re&&!j&&!G,re=r.jsx(we,{width:s,height:l,propertyKey:t,value:v,property:i,size:Xe(A)})),r.jsx(sr,{size:A,width:s,onSelect:le,selected:_,disabled:j||G,disabledTooltip:q??"Disabled",removePadding:H,fullHeight:$,saved:T,error:S??E,align:n,allowScroll:J,showExpandIcon:Q,value:v,hideOverflow:R,actions:V&&r.jsx(sn,{showError:z,disabled:j,showExpandIcon:Q,selected:_,openPopup:j?void 0:ne}),children:re},`cell_${t}_${u.path}_${u.id}`)},nl);function nl(e,t){return e.height===t.height&&e.propertyKey===t.propertyKey&&e.align===t.align&&e.width===t.width&&Y(e.property,t.property)&&Y(e.value,t.value)&&Y(e.entity.id,t.entity.id)&&Y(e.entity.values,t.entity.values)}const lr=function({entity:t,collection:o,fullPath:a,width:i,frozen:n,isSelected:s,selectionEnabled:l,size:c,highlightEntity:u,onCollectionChange:f,unhighlightEntity:g,actions:m=[],hideId:h,selectionController:A}){const y=Oe(),b=Ce(),k=d.useCallback(B=>{A?.toggleEntitySelection(t)},[t,A?.toggleEntitySelection]),_=d.useCallback(B=>{B.stopPropagation(),A?.toggleEntitySelection(t)},[t,A?.toggleEntitySelection]),v=m.length>0,x=m.some(B=>B.collapsed||B.collapsed===void 0),C=m.filter(B=>B.collapsed||B.collapsed===void 0),E=m.filter(B=>B.collapsed===!1);return r.jsxs("div",{onClick:_,className:p.cls("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",n?"sticky left-0":""),style:{width:i,position:n?"sticky":"initial",left:n?0:"initial",contain:"strict"},children:[(v||l)&&r.jsxs("div",{className:"w-34 flex justify-center",children:[E.map((B,S)=>r.jsx(p.Tooltip,{title:B.name,children:r.jsx(p.IconButton,{onClick:P=>{P.stopPropagation(),B.onClick({entity:t,fullPath:a,collection:o,context:b,selectionController:A,highlightEntity:u,unhighlightEntity:g,onCollectionChange:f})},size:y?"medium":"small",children:B.icon})},S)),x&&r.jsx(p.Menu,{trigger:r.jsx(p.IconButton,{size:y?"medium":"small",children:r.jsx(p.MoreVertIcon,{})}),children:C.map((B,S)=>r.jsxs(p.MenuItem,{onClick:P=>{P.stopPropagation(),B.onClick({entity:t,fullPath:a,collection:o,context:b,selectionController:A,highlightEntity:u,unhighlightEntity:g,onCollectionChange:f})},children:[B.icon,B.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:B=>{B.stopPropagation()},className:"font-mono select-all",variant:"caption",color:"secondary",children:[" ",t.id," "]}):r.jsx(p.Skeleton,{})})]})};function il({actions:e,actionsStart:t,loading:o,onSizeChanged:a,onTextSearch:i,onTextSearchClick:n,size:s,textSearchLoading:l,title:c}){const u=d.useRef(null),f=Oe(),g=d.useRef(!1);d.useEffect(()=>{u.current&&g.current&&!l&&u.current.focus(),g.current=l??!1},[l]);const m=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.cls(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}),m,t]}),r.jsxs("div",{className:"flex items-center gap-2",children:[f&&r.jsx("div",{className:"w-[22px]",children:o&&r.jsx(p.CircularProgress,{size:"small"})}),(i||n)&&r.jsx(p.SearchBar,{inputRef:u,loading:l,disabled:!!n,onClick:n,onTextSearch:n?void 0:i,expandable:!0},"search-bar"),e]})]})}function sl(e){return e.dataType==="boolean"?"center":e.dataType==="number"?e.enumValues?"left":"right":e.dataType==="date"?"right":"left"}function un(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:un(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 ao(e){return`subcollection:${e.id??e.path}`}const no="collectionGroupParent";function io(e,t){return d.useMemo(()=>{if(e.propertiesOrder){const o=fn(e,e.propertiesOrder);return e.collectionGroup&&o.push({key:no,disabled:!0}),o}return ll(e,t)},[e,t])}function fn(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?cr(a,o):[{key:o,disabled:!!a.disabled||!!a.readOnly}]:e.additionalFields?.find(n=>n.key===o)?[{key:o,disabled:!0}]:e.subcollections&&e.subcollections.find(s=>ao(s)===o)?[{key:o,disabled:!0}]:e.collectionGroup&&o===no?[{key:o,disabled:!0}]:[null]}).filter(Boolean)}function ll(e,t){const o=Object.keys(e.properties),a=e.additionalFields??[],i=e.subcollections??[],n=[...o,...a.map(s=>s.key)];if(t){const s=i.map(l=>ao(l));n.push(...s.filter(l=>!n.includes(l)))}return e.collectionGroup&&n.push(no),fn(e,n)}function cr(e,t,o){return e.dataType==="map"&&e.spreadChildren&&e.properties?Object.entries(e.properties).flatMap(([a,i])=>cr(i,`${t}.${a}`,o||!!e.disabled||!!e.readOnly)):[{key:t,disabled:o||!!e.disabled||!!e.readOnly}]}function cl(e){return{key:"id_ewcfedcswdf3",width:e?160:130,title:"ID",resizable:!1,frozen:e??!1,headerAlign:"center",align:"center"}}function mn({properties:e,sortable:t,forceFilter:o,AdditionalHeaderWidget:a}){const i=!!o;return Object.entries(e).flatMap(([n,s])=>cr(s,n)).map(({key:n,disabled:s})=>{const l=Mr(e,n);if(!l)throw Error("Internal error: no property found in path "+n);const c=hn(l);return{key:n,align:sl(l),icon:_e(l,"small"),title:l.name??n,sortable:t,filter:!i&&c,width:un(l),resizable:!0,custom:{resolvedProperty:l,disabled:s},AdditionalHeaderWidget:a?({onHover:u})=>r.jsx(a,{property:l,propertyKey:n,onHover:u}):void 0}})}function hn(e,t=!1){return t?["string","number","date","reference"].includes(e.dataType):e.dataType==="array"?e.of?hn(e.of,!0):!1:["string","number","boolean","date","reference","array"].includes(e.dataType)}function Nt({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 dl=d.memo(function({resizeHandleRef:t,columnIndex:o,isResizingIndex:a,sort:i,onColumnSort:n,onFilterUpdate:s,filter:l,column:c,onClickResizeColumn:u,createFilterField:f,AdditionalHeaderWidget:g}){const[m,h]=d.useState(!1),[A,y]=d.useState(!1),[b,k]=d.useState(!1),_=d.useCallback(B=>{y(!0)},[]),v=d.useCallback((B,S)=>{s(c,B),S!==void 0&&y(S)},[c,s]),x=a===o,E=!(a!==o&&a>0)&&(m||x);return r.jsx(ae,{children:r.jsxs("div",{className:p.cls("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:m||A}),c.sortable&&(i||E||A)&&r.jsx(p.Badge,{color:"secondary",invisible:!i,children:r.jsxs(p.IconButton,{size:"small",className:m||A?"bg-white dark:bg-gray-950":void 0,onClick:()=>{n(c.key)},children:[!i&&r.jsx(p.ArrowUpwardIcon,{}),i==="asc"&&r.jsx(p.ArrowUpwardIcon,{}),i==="desc"&&r.jsx(p.ArrowUpwardIcon,{className:"rotate-180"})]})})]}),c.filter&&f&&r.jsx("div",{children:r.jsx(p.Badge,{color:"secondary",invisible:!l,children:r.jsx(p.Popover,{open:A,onOpenChange:y,className:b?"hidden":void 0,modal:!0,trigger:r.jsx(p.IconButton,{className:m||A?"bg-white dark:bg-gray-950":void 0,size:"small",onClick:_,children:r.jsx(p.FilterListIcon,{size:"small"})}),children:r.jsx(pl,{column:c,filter:l,onHover:m,onFilterUpdate:v,createFilterField:f,hidden:b,setHidden:k})})})}),c.resizable&&r.jsx("div",{ref:t,className:p.cls("absolute h-full w-[6px] top-0 right-0 cursor-col-resize",E&&"bg-gray-300 dark:bg-gray-700"),onMouseDown:u?()=>u(o,c):void 0})]})})},Y);function pl({column:e,onFilterUpdate:t,filter:o,onHover:a,createFilterField:i,hidden:n,setHidden:s}){const l=e.key,[c,u]=d.useState(o);if(d.useEffect(()=>{u(o)},[o]),!e.filter)return null;const f=()=>{t(c,!1)},g=A=>{t(void 0,!1)},m=!!o,h=i({id:l,filterValue:c,setFilterValue:u,column:e,hidden:n,setHidden:s});return h?r.jsxs("form",{noValidate:!0,onSubmit:A=>{A.stopPropagation(),A.preventDefault(),f()},className:"text-gray-900 dark:text-white",children:[r.jsx("div",{className:p.cls(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:!m,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 ul=({columns:e,currentSort:t,onColumnSort:o,onFilterUpdate:a,sortByProperty:i,filter:n,onColumnResize:s,onColumnResizeEnd:l,createFilterField:c,AddColumnComponent:u})=>{const f=e.map(()=>d.createRef()),[g,m]=d.useState(-1),h=d.useCallback((C,E,B)=>{const S=e[C],P=100,T=800,N=E>T?T:E<P?P:E,M={width:N,key:S.key,column:{...S,width:N}};B?l(M):s(M)},[e,s,l]),A=d.useCallback(C=>{if(g>=0){const E=f[g].current?.parentElement?.getBoundingClientRect().left;return E?C.clientX-E:void 0}},[f,g]),y=d.useCallback(C=>{document.body.style.cursor=C?"col-resize":"auto"},[]),b=d.useCallback(C=>{C.stopPropagation(),C.preventDefault();const E=A(C);E&&h(g,E,!1)},[h,A,g]),k=d.useCallback(C=>{C.stopPropagation(),C.preventDefault();const E=A(C);E&&h(g,E,!0),m(-1),y(!1)},[h,A,g,y]),_=d.useCallback(()=>{document.removeEventListener("mousemove",b),document.removeEventListener("mouseup",k)},[b,k]),v=d.useCallback(()=>{document.addEventListener("mousemove",b),document.addEventListener("mouseup",k)},[b,k]);d.useEffect(()=>(g>=0?v():_(),()=>{_()}),[v,g,_]);const x=d.useCallback(C=>{m(C),y(!0)},[y]);return r.jsxs("div",{className:p.cls(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,E)=>{const B=e[E],S=B&&n&&n[B.key]?n[B.key]:void 0;return r.jsx(ae,{children:r.jsx(dl,{resizeHandleRef:f[E],columnIndex:E,isResizingIndex:g,onFilterUpdate:a,filter:S,sort:i===B.key?t:void 0,onColumnSort:o,onClickResizeColumn:x,column:B,createFilterField:c,AdditionalHeaderWidget:B.AdditionalHeaderWidget})},"header_"+B.key)}),u&&r.jsx(u,{})]})},fl=d.memo(function({rowData:t,rowIndex:o,children:a,onRowClick:i,rowHeight:n,style:s,hoverRow:l,rowClassName:c}){const u=d.useCallback(f=>{i&&i({rowData:t,rowIndex:o,event:f})},[i,t,o]);return r.jsx("div",{className:p.cls("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":i}),onClick:u,style:{...s,height:n,width:"fit-content"},children:a})},Y),ml=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)=>Y(e.rowData,t.rowData)&&Y(e.column,t.column)&&Y(e.cellData,t.cellData)&&Y(e.rowIndex,t.rowIndex)&&Y(e.cellRenderer,t.cellRenderer)&&Y(e.columnIndex,t.columnIndex)),dr=d.createContext({});dr.displayName="VirtualListContext";const hl=d.forwardRef(({children:e,...t},o)=>r.jsx(dr.Consumer,{children:a=>{const i=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(ul,{...a}),!i&&e]})}),i&&r.jsx("div",{style:{position:"sticky",top:"56px",flexGrow:1,height:"calc(100% - 56px)",marginTop:"calc(56px - 100vh)",left:0},children:i})]})}})),gn=d.memo(function({data:t,onResetPagination:o,onEndReached:a,rowHeight:i=54,columns:n,onRowClick:s,onColumnResize:l,filter:c,checkFilterCombination:u,onFilterUpdate:f,sortBy:g,error:m,emptyComponent:h,onSortByUpdate:A,loading:y,cellRenderer:b,hoverRow:k,createFilterField:_,rowClassName:v,style:x,className:C,endAdornment:E,AddColumnComponent:B}){const S=g?g[0]:void 0,P=g?g[1]:void 0,[T,N]=d.useState(n),M=d.useRef(null),L=d.useRef(0);d.useEffect(()=>{N(n)},[n]);const[ee,G]=Wo(),q=d.useCallback(V=>{N(T.map(z=>z.key===V.column.key?V.column:z))},[T]),j=d.useCallback(V=>{N(T.map(z=>z.key===V.column.key?V.column:z)),l&&l(V)},[T,l]),O=d.useRef();d.useEffect(()=>{O.current=c},[c]);const te=d.useCallback(()=>{L.current=0,M.current&&M.current.scrollTo(M.current?.scrollLeft,0)},[]),Z=d.useCallback(V=>{const z=S===V&&P==="desc",D=S===V&&P==="asc"?"desc":z?void 0:"asc",ie=z?void 0:V,xe=O.current,Le=D&&ie?[ie,D]:void 0;xe&&u&&!u(xe,Le)&&f&&f(void 0),o&&o(),A&&A(Le),te()},[u,P,f,o,A,te,S]);d.useCallback(()=>{L.current=0,A&&A(void 0)},[A]);const le=Math.max((t?.length??0)*i-G.height,0),ne=d.useCallback(V=>{a&&(t?.length??0)>0&&V>L.current+600&&(L.current=V,a())},[t?.length,a]),re=d.useCallback(({scrollOffset:V,scrollUpdateWasRequested:z})=>{!z&&V>=le-600&&ne(V)},[le,ne]),J=d.useCallback((V,z)=>{L.current=0;const I=O.current;let D=I?{...I}:{};z?D[V.key]=z:delete D[V.key],!u||u(D,S&&P?[S,P]:void 0)||(D=z?{[V.key]:z}:{}),f&&f(D)},[u,P,f,S]),Q=d.useCallback(()=>y?r.jsx(Nt,{}):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]),R=!y&&(t?.length??0)===0,H=m?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"}),m?.message&&r.jsx(Al,{text:m.message})]}):R?Q():void 0,$={data:t,rowHeight:i,cellRenderer:b,columns:T,currentSort:P,onRowClick:s,customView:H,onColumnResize:q,onColumnResizeEnd:j,filter:O.current,onColumnSort:Z,onFilterUpdate:J,sortByProperty:S,hoverRow:k??!1,createFilterField:_,rowClassName:v,endAdornment:E,AddColumnComponent:B};return r.jsx("div",{ref:ee,style:x,className:p.cls("h-full w-full",C),children:r.jsx(dr.Provider,{value:$,children:r.jsx(gl,{outerRef:M,width:G.width,height:G.height,itemCount:(t?.length??0)+(E?1:0),onScroll:re,includeAddColumn:!!B,itemSize:i},i)})})},Y);function gl({outerRef:e,width:t,height:o,itemCount:a,onScroll:i,itemSize:n,includeAddColumn:s}){const l=d.useCallback(({index:c,style:u})=>r.jsx(dr.Consumer,{children:({onRowClick:f,data:g,columns:m,rowHeight:h=54,cellRenderer:A,hoverRow:y,rowClassName:b,endAdornment:k})=>{if(k&&c===(g??[]).length)return r.jsx("div",{style:{...u,height:"auto",position:"sticky",bottom:0,zIndex:1},children:k});const _=g&&g[c];return r.jsxs(fl,{rowData:_,rowIndex:c,onRowClick:f,columns:m,hoverRow:y,rowClassName:b,style:{...u,top:`calc(${u.top}px + 48px)`},rowHeight:h,children:[m.map((v,x)=>{const C=_&&_[v.key];return r.jsx(ml,{dataKey:v.key,cellRenderer:A,column:v,columns:m,rowData:_,cellData:C,rowIndex:c,columnIndex:x},`cell_${v.key}`)}),s&&r.jsx("div",{className:"w-20"})]},`row_${c}`)}}),[]);return r.jsx(ui.FixedSizeList,{outerRef:e,innerElementType:hl,width:t,height:o,overscanCount:4,itemCount:a,onScroll:i,itemSize:n,children:l})}const Al=({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}})},An={"==":"==","!=":"!=",">":">","<":"<",">=":">=","<=":"<=",in:"In","not-in":"Not in","array-contains":"Contains","array-contains-any":"Contains Any"},so=["array-contains-any","in","not-in"];function bl({name:e,value:t,setValue:o,isArray:a,path:i,title:n,includeId:s=!0,previewProperties:l,setHidden:c}){const u=a?["array-contains"]:["==","!=",">","<",">=","<="];a?u.push("array-contains-any"):u.push("in","not-in");const[f,g]=t||[u[0],void 0],[m,h]=d.useState(f),[A,y]=d.useState(g),b=A?Array.isArray(A)?A.map(T=>T?.isEntityReference&&T?.isEntityReference()?T.id:null).filter(Boolean):[A.id]:[];function k(T,N){const M=so.includes(m),L=so.includes(T);let ee=N;M!==L&&(ee=L?ee?.isEntityReference&&ee?.isEntityReference()?[ee]:[]:void 0),h(T),y(ee);const G=ee!==null&&Array.isArray(ee)?ee.length>0:ee!==void 0;o(T&&G?[T,ee]:void 0)}const _=pe(),v=d.useMemo(()=>i?_.getCollection(i):void 0,[i]),x=T=>{k(m,$e(T))},C=T=>{k(m,T.map(N=>$e(N)))},E=so.includes(m),B=At({multiselect:E,path:i,collection:v,onSingleEntitySelected:x,onMultipleEntitiesSelected:C,selectedEntityIds:b,onClose:()=>{c(!1)}}),S=()=>{c(!0),B.open()},P=T=>r.jsx(Ve,{disabled:!i,previewProperties:l,size:"medium",onClick:S,reference:T,hover:!0,includeId:s,includeEntityLink:!1});return r.jsxs("div",{className:"flex w-[440px] flex-row",children:[r.jsx("div",{className:"w-[140px]",children:r.jsx(p.Select,{value:m,onValueChange:T=>{k(T,A)},renderValue:T=>An[T],children:u.map(T=>r.jsx(p.SelectItem,{value:T,children:An[T]},T))})}),r.jsxs("div",{className:"flex-grow ml-2 h-full gap-2 flex flex-col",children:[A&&Array.isArray(A)&&r.jsx("div",{children:A.map((T,N)=>P(T))}),A&&!Array.isArray(A)&&r.jsx("div",{children:P(A)}),(!A||Array.isArray(A)&&A.length===0)&&r.jsx(p.Button,{onClick:S,variant:"outlined",size:"large",className:"h-full w-full",children:E?"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:A===null,size:"small",onCheckedChange:T=>{A!==null?k(m,null):k(m,void 0)}}),"Filter for null values"]})]})]})}const bn={"==":"==","!=":"!=",">":">","<":"<",">=":">=","<=":"<=",in:"In","not-in":"Not in","array-contains":"Contains","array-contains-any":"Any"},lo=["array-contains-any","in","not-in"];function yl({name:e,value:t,setValue:o,dataType:a,isArray:i,enumValues:n,title:s}){const l=i?["array-contains"]:["==","!=",">","<",">=","<="];n&&(i?l.push("array-contains-any"):l.push("in","not-in"));const[c,u]=t||[l[0],void 0],[f,g]=d.useState(c),[m,h]=d.useState(u);function A(b,k){let _=k;const v=lo.includes(f),x=lo.includes(b);v!==x&&(_=x?typeof k=="string"||typeof k=="number"?[k]:[]:void 0),typeof _=="number"&&isNaN(_)&&(_=void 0),g(b),h(_);const C=_!==null&&Array.isArray(_)?_.length>0:_!==void 0;o(b&&C?[b,_]:void 0)}const y=lo.includes(f);return r.jsxs("div",{className:"flex w-[440px]",children:[r.jsx("div",{className:"w-[80px]",children:r.jsx(p.Select,{value:f,position:"item-aligned",onValueChange:b=>{A(b,m)},renderValue:b=>bn[b],children:l.map(b=>r.jsx(p.SelectItem,{value:b,children:bn[b]},b))})}),r.jsxs("div",{className:"flex-grow ml-2 flex flex-col gap-2",children:[!n&&r.jsx(p.TextField,{type:a==="number"?"number":void 0,value:m!==void 0&&m!=null?String(m):"",onChange:b=>{const k=a==="number"?parseFloat(b.target.value):b.target.value;A(f,k)},endAdornment:m&&r.jsx(p.IconButton,{onClick:b=>A(f,void 0),children:r.jsx(p.ClearIcon,{})})}),n&&r.jsx(p.Select,{position:"item-aligned",value:m!==void 0?Array.isArray(m)?m.map(b=>String(b)):String(m):i?[]:"",onValueChange:b=>{b!==""&&A(f,a==="number"?parseInt(b):b)},multiple:y,endAdornment:m&&r.jsx(p.IconButton,{className:"absolute right-2 top-3",onClick:b=>A(f,void 0),children:r.jsx(p.ClearIcon,{})}),renderValue:b=>b===null?"Filter for null values":r.jsx(Ie,{enumKey:b,enumValues:n,size:"small"},`select_value_${e}_${b}`),children:n.map(b=>r.jsx(p.SelectItem,{value:String(b.id),children:r.jsx(Ie,{enumKey:String(b.id),enumValues:n,size:"small"})},`select_value_${e}_${b.id}`))}),!i&&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:m===null,size:"small",onCheckedChange:b=>{m!==null?A(f,null):A(f,void 0)}}),"Filter for null values"]})]})]})}function wl({name:e,title:t,value:o,setValue:a}){function i(l){a(l!==void 0?["==",l]:void 0)}const n=o&&o[1],s=!!o;return r.jsx("div",{className:"w-[300px]",children:r.jsx(p.BooleanSwitchWithLabel,{value:n,allowIndeterminate:!0,onValueChange:l=>i(l===null?void 0:l),label:s?n?`${t} is true`:`${t} is false`:"No filter"})})}const yn={"==":"==","!=":"!=",">":">","<":"<",">=":">=","<=":"<=","not-in":"not in",in:"in","array-contains":"Contains","array-contains-any":"Any"},wn=["array-contains-any","in"];function vl({name:e,isArray:t,mode:o,value:a,setValue:i,title:n}){const{locale:s}=se(),l=t?["array-contains"]:["==","!=",">","<",">=","<="],[c,u]=a||[l[0],void 0],[f,g]=d.useState(c),[m,h]=d.useState(u);function A(y,b){let k=b;const _=wn.includes(f),v=wn.includes(y);_!==v&&(k=v?b?[b]:[]:""),g(y),h(k===null?void 0:k);const x=k!==null&&Array.isArray(k)?k.length>0:k!==void 0;i(y&&x?[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:f,onValueChange:y=>{A(y,m)},renderValue:y=>yn[y],children:l.map(y=>r.jsx(p.SelectItem,{value:y,children:yn[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:m??void 0,onChange:y=>{A(f,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:m===null,size:"small",onCheckedChange:y=>{m!==null?A(f,null):A(f,void 0)}}),"Filter for null values"]})]})]})}const vn=d.memo(function({onValueChange:t,cellRenderer:o,onEntityClick:a,onColumnResize:i,hoverRow:n=!0,size:s="m",inlineEditing:l=!1,tableController:{data:c,dataLoading:u,noMoreToLoad:f,dataLoadingError:g,filterValues:m,setFilterValues:h,sortBy:A,setSortBy:y,setSearchString:b,clearFilter:k,itemCount:_,setItemCount:v,pageSize:x=50,paginationEnabled:C,checkFilterCombination:E,setPopupCell:B},filterable:S=!0,emptyComponent:P,columns:T,forceFilter:N,highlightedRow:M,endAdornment:L,AddColumnComponent:ee}){const G=d.useRef(null),[q,j]=d.useState(void 0),O=()=>{!C||u||f||_!==void 0&&v?.(_+x)},te=d.useCallback(()=>{v?.(x)},[x]),Z=d.useCallback(({rowData:J})=>{if(!l)return a&&a(J)},[a,l]);p.useOutsideAlerter(G,()=>{q&&ne()},!!q),d.useEffect(()=>{const J=Q=>{Q.keyCode===27&&ne()};return document.addEventListener("keydown",J,!1),()=>{document.removeEventListener("keydown",J,!1)}});const le=d.useCallback(J=>{j(J)},[]),ne=d.useCallback(()=>{j(void 0)},[]),re=d.useCallback(J=>{h?.({...J,...N})},[N]);return r.jsx(oo.Provider,{value:{setPopupCell:B,select:le,onValueChange:t,size:s??"m",selectedCell:q},children:r.jsx("div",{className:"h-full w-full flex flex-col bg-white dark:bg-gray-950",ref:G,children:r.jsx(gn,{data:c,columns:T,cellRenderer:o,onRowClick:l?void 0:a?Z:void 0,onEndReached:O,onResetPagination:te,error:g,paginationEnabled:C,onColumnResize:i,rowHeight:ir(s),loading:u,filter:m,onFilterUpdate:h?re:void 0,sortBy:A,onSortByUpdate:y,hoverRow:n,checkFilterCombination:E,createFilterField:S?kl:void 0,rowClassName:d.useCallback(J=>M?.(J)?"bg-gray-100 bg-opacity-75 dark:bg-gray-800 dark:bg-opacity-75":"",[M]),className:"flex-grow",emptyComponent:P,endAdornment:L,AddColumnComponent:ee})})})},Y);function kl({id:e,filterValue:t,setFilterValue:o,column:a,hidden:i,setHidden:n}){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(bl,{value:t,setValue:o,name:e,isArray:l,path:c.path,title:s?.name,includeId:c.includeId,previewProperties:c?.previewProperties,hidden:i,setHidden:n});if(c.dataType==="number"||c.dataType==="string"){const u=c.name,f=c.enumValues?Je(c.enumValues):void 0;return r.jsx(yl,{value:t,setValue:o,name:e,dataType:c.dataType,isArray:l,enumValues:f,title:u})}else if(c.dataType==="boolean"){const u=c.name;return r.jsx(wl,{value:t,setValue:o,name:e,title:u})}else if(c.dataType==="date"){const u=c.name;return r.jsx(vl,{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 co=function({className:t,style:o,forceFilter:a,actionsStart:i,actions:n,title:s,tableRowActionsBuilder:l,uniqueFieldValidator:c,getPropertyFor:u,onValueChange:f,selectionController:g,highlightedEntities:m,onEntityClick:h,onColumnResize:A,onSizeChanged:y,textSearchEnabled:b=!1,hoverRow:k=!0,inlineEditing:_=!1,additionalFields:v,displayedColumnIds:x,defaultSize:C,properties:E,tableController:B,filterable:S=!0,sortable:P=!0,endAdornment:T,AddColumnComponent:N,AdditionalHeaderWidget:M,additionalIDHeaderWidget:L,emptyComponent:ee,getIdColumnWidth:G,onTextSearchClick:q,textSearchLoading:j,enablePopupIcon:O}){const te=d.useRef(null),Z=Oe(),le=(g?.selectedEntities?.length>0?g?.selectedEntities:m)?.filter(Boolean),ne=Ce(),[re,J]=d.useState(C??"m"),Q=le?.map(K=>K.id),R=d.useCallback(K=>{y&&y(K),J(K)},[]),H=d.useCallback(K=>B.setSearchString?.(K),[]),$=d.useMemo(()=>v?v.map(K=>({[K.key]:K})).reduce((K,he)=>({...K,...he}),{}):{},[v]),V=c,z=({column:K,columnIndex:he,rowData:Te,rowIndex:Fe})=>{const Ae=Te,Ge=K.key;let je=K.custom?.disabled;const qe=u?.({propertyKey:Ge,entity:Ae})??K.custom.resolvedProperty;return qe?.disabled||(je=!1),qe?r.jsx(ae,{children:Ae?r.jsx(pn,{readonly:!_,align:K.align??"left",propertyKey:Ge,property:qe,value:Ae?.values?Ue(Ae.values,Ge):void 0,customFieldValidator:V,columnIndex:he,width:K.width,height:ir(re),entity:Ae,disabled:je,enablePopupIcon:O,path:Ae.path},`property_table_cell_${Ae.id}_${Ge}`):We()}):null},I=d.useCallback(({column:K,rowData:he,width:Te})=>{const Fe=he,Ae=$[K.key],Ge=Ae.dependencies?Object.entries(Fe.values).filter(([X,be])=>Ae.dependencies.includes(X)).reduce((X,be)=>({...X,...be}),{}):Fe,je=Ae.Builder;if(!je&&!Ae.value)throw new Error("When using additional fields you need to provide a Builder or a value");const qe=je?r.jsx(je,{entity:Fe,context:ne}):r.jsx(r.Fragment,{children:Ae.value?.({entity:Fe,context:ne})});return r.jsx(sr,{width:Te,size:re,value:Ge,selected:!1,disabled:!0,align:"left",allowScroll:!1,showExpandIcon:!1,disabledTooltip:"This column can't be edited directly",children:r.jsx(ae,{children:qe})},`additional_table_cell_${Fe.id}_${K.key}`)},[re,Q]),D=(()=>{const K=mn({properties:E,sortable:P,forceFilter:a,AdditionalHeaderWidget:M}),he=v?v.map(Te=>({key:Te.key,align:"left",sortable:!1,title:Te.name,width:Te.width??200})):[];return[...K,...he]})(),xe=[{key:"id_ewcfedcswdf3",width:G?.()??(Z?160:130),title:"ID",resizable:!1,frozen:Z,headerAlign:"center",align:"center",AdditionalHeaderWidget:()=>L},...x?x.map(K=>D.find(he=>he.key===K.key)).filter(Boolean):D],Le=K=>{const he=K.column,Te=K.columns,Fe=he.key;try{if(K.columnIndex===0)return l?l({entity:K.rowData,size:re,width:he.width,frozen:he.frozen}):r.jsx(lr,{entity:K.rowData,width:he.width,frozen:he.frozen,isSelected:!1,size:re});if($[Fe])return I(K);if(K.columnIndex<Te.length+1)return z(K);throw Error("Internal: columns not mapped properly")}catch(Ae){return console.error("Error rendering cell",Ae),r.jsx(sr,{size:re,width:he.width,saved:!1,value:null,align:"left",fullHeight:!1,disabled:!0,children:r.jsx(ye,{error:Ae})})}};return r.jsxs("div",{ref:te,style:o,className:p.cls("h-full w-full flex flex-col bg-white dark:bg-gray-950",t),children:[r.jsx(il,{onTextSearch:b?H:void 0,textSearchLoading:j,onTextSearchClick:b?q:void 0,size:re,onSizeChanged:R,title:s,actionsStart:i,actions:n,loading:B.dataLoading}),r.jsx(vn,{columns:xe,size:re,inlineEditing:_,cellRenderer:Le,onEntityClick:h,highlightedRow:d.useCallback(K=>Q?.includes(K.id)??!1,[Q]),tableController:B,onValueChange:f,onColumnResize:A,hoverRow:k,filterable:S,emptyComponent:ee,endAdornment:T,AddColumnComponent:N})]})};function _l({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 kn(e,t,o=5e3){const[a,i]=d.useState(e),n=d.useRef(a.length??0),s=d.useRef(!1),l=d.useRef(t),c=!Y(l.current,t),u=e.length>=n.current||c;return d.useEffect(()=>{const f=()=>{Y(a,e)||(l.current=t,n.current=e.length,i(e)),s.current=!1};s.current=!0;let g;return u?f():g=setTimeout(f,o),()=>{clearTimeout(g),s.current&&u&&f()}},[e,o,t,u]),u?e:a}const Cl=50;function po({fullPath:e,collection:t,entitiesDisplayedFirst:o,lastDeleteTimestamp:a,forceFilter:i}){const{initialFilter:n,initialSort:s,forceFilter:l}=t,[c,u]=d.useState(void 0),f=pe(),g=ze(t),m=d.useMemo(()=>f.resolveAliasesFrom(e),[e,f.resolveAliasesFrom]),h=i??l,A=t.pagination===void 0||!!t.pagination,y=typeof t.pagination=="number"?t.pagination:Cl,[b,k]=d.useState(),[_,v]=d.useState(A?y:void 0),x=d.useMemo(()=>{if(s&&h&&!Z(h,s)){console.warn("Initial sort is not compatible with the force filter. Ignoring initial sort");return}return s},[s,h]);d.useEffect(()=>{Y(h,C)||E(h)},[h]);const[C,E]=d.useState(h??n??void 0),[B,S]=d.useState(x),P=B?B[0]:void 0,T=B?B[1]:void 0,N=Ce(),[M,L]=d.useState([]),[ee,G]=d.useState(!1),[q,j]=d.useState(),[O,te]=d.useState(!1),Z=d.useCallback((Q,R)=>g.isFilterCombinationValid?g.isFilterCombinationValid({path:m,collection:t,filterValues:Q,sortBy:R}):!0,[]),le=d.useCallback(()=>E(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?E(void 0):E(Q)},[h]);d.useEffect(()=>{G(!0);const Q=async H=>{if(t.callbacks?.onFetch)try{H=await Promise.all(H.map($=>t.callbacks.onFetch({collection:t,path:m,entity:$,context:N})))}catch($){console.error($)}G(!1),j(void 0),L(H.map($=>({...$}))),te(!_||H.length<_)},R=H=>{console.error("ERROR",H),G(!1),L([]),j(H)};return g.listenCollection?g.listenCollection({path:m,collection:t,onUpdate:Q,onError:R,searchString:b,filter:C,limit:_,startAfter:void 0,orderBy:P,order:T}):(g.fetchCollection({path:m,collection:t,searchString:b,filter:C,limit:_,startAfter:void 0,orderBy:P,order:T}).then(Q).catch(R),()=>{})},[m,_,T,P,C,b]);const re=_l({data:M,entitiesDisplayedFirst:o});return{data:kn(re,{filterValues:C,sortBy:B,searchString:b,lastDeleteTimestamp:a}),dataLoading:ee,noMoreToLoad:O,dataLoadingError:q,filterValues:C,setFilterValues:ne,sortBy:B,setSortBy:S,searchString:b,setSearchString:k,clearFilter:le,itemCount:_,setItemCount:v,paginationEnabled:A,pageSize:y,checkFilterCombination:Z,popupCell:c,setPopupCell:u}}function uo(e){const[t,o]=d.useState([]),a=d.useCallback(n=>{let s;t.map(l=>l.id).includes(n.id)?(e?.(n,!1),s=t.filter(l=>l.id!==n.id)):(e?.(n,!0),s=[...t,n]),o(s)},[t]),i=d.useCallback(n=>t.map(s=>s.id).includes(n.id),[t]);return{selectedEntities:t,setSelectedEntities:o,isEntitySelected:i,toggleEntitySelection:a}}function fo({collection:e,fullPath:t,parentCollectionIds:o}){const a=Ce(),i=se(),n=ze(),[s,l]=d.useState(!1),[c,u]=d.useState(!1);let f,g=!!e.textSearchEnabled;return i?.plugins&&(f=n?.initTextSearch||i.plugins?.find(h=>!!h.collectionView?.onTextSearchClick)?()=>{l(!0);const h=[];return n?.initTextSearch&&h.push(n.initTextSearch({context:a,path:t,collection:e,parentCollectionIds:o})),i.plugins?.forEach(A=>(A.collectionView?.onTextSearchClick&&h.push(A.collectionView.onTextSearchClick({context:a,path:t,collection:e,parentCollectionIds:o})),Promise.resolve(!0))),Promise.all(h).then(A=>{A.every(Boolean)&&u(!0)}).finally(()=>l(!1))}:void 0,i.plugins?.forEach(h=>{g||h.collectionView?.showTextSearchBar&&(g=h.collectionView.showTextSearchBar({context:a,path:t,collection:e,parentCollectionIds:o}))})),{textSearchLoading:s,textSearchInitialised:c,onTextSearchClick:f,textSearchEnabled:g}}function _n({entityOrEntitiesToDelete:e,collection:t,onClose:o,open:a,callbacks:i,onEntityDelete:n,onMultipleEntitiesDelete:s,path:l}){const c=ze(t),u=se(),f=Ze(),[g,m]=d.useState(!1),[h,A]=d.useState(),[y,b]=d.useState(),k=Ce();d.useEffect(()=>{if(e){const M=Array.isArray(e)&&e.length===1?e[0]:e;A(M),b(Array.isArray(M))}},[e]);const _=d.useMemo(()=>Ne({collection:t,path:l,fields:u.propertyConfigs}),[t,l]),v=d.useCallback(()=>{o()},[o]),x=d.useCallback(M=>{console.debug("Deleted",M)},[]),C=d.useCallback((M,L)=>{f.open({type:"error",message:"Error deleting: "+L?.message}),console.error("Error deleting entity"),console.error(L)},[_.name]),E=d.useCallback((M,L)=>{f.open({type:"error",message:"Error before deleting: "+L?.message}),console.error(L)},[_.name]),B=d.useCallback((M,L)=>{f.open({type:"error",message:"Error after deleting: "+L?.message}),console.error(L)},[_.name]),S=d.useCallback(M=>Fa({dataSource:c,entity:M,collection:_,callbacks:i,onDeleteSuccess:x,onDeleteFailure:C,onPreDeleteHookError:E,onDeleteSuccessHookError:B,context:k}),[c,_,i,x,C,E,B,k]),P=d.useCallback(async()=>{h&&(m(!0),y?Promise.all(h.map(S)).then(M=>{m(!1),s&&h&&s(l,h),M.every(Boolean)?f.open({type:"success",message:`${_.name}: multiple deleted`}):M.some(Boolean)?f.open({type:"warning",message:`${_.name}: Some of the entities have been deleted, but not all`}):f.open({type:"error",message:`${_.name}: Error deleting entities`}),o()}):S(h).then(M=>{m(!1),M&&(n&&h&&n(l,h),f.open({type:"success",message:`${_.singularName??_.name} deleted`}),o())}))},[h,y,S,s,l,o,f,_.name,n]);let T;if(h&&y)T=r.jsx(r.Fragment,{children:"Multiple entities"});else{const M=h;T=M?r.jsx(Rr,{entity:M,collection:t,path:l}):r.jsx(r.Fragment,{})}const N=y?r.jsxs(r.Fragment,{children:[r.jsx("b",{children:_.name}),": Confirm multiple delete?"]}):`Would you like to delete this ${_.singularName??_.name}?`;return r.jsxs(p.Dialog,{maxWidth:y?"lg":"2xl","aria-labelledby":"delete-dialog",open:a,onOpenChange:M=>M?void 0:o(),children:[r.jsxs(p.DialogContent,{fullHeight:!0,children:[r.jsx(p.Typography,{variant:"subtitle2",className:"p-4",children:N}),!y&&r.jsx("div",{className:"p-4",children:T})]}),r.jsxs(p.DialogActions,{children:[g&&r.jsx(p.CircularProgress,{size:"small"}),r.jsx(p.Button,{onClick:v,disabled:g,variant:"text",color:"primary",children:"Cancel"}),r.jsx(p.Button,{autoFocus:!0,disabled:g,onClick:P,variant:"filled",color:"primary",children:"Ok"})]})]})}const Cn={icon:r.jsx(p.KeyboardTabIcon,{}),name:"Edit",collapsed:!1,onClick({entity:e,collection:t,fullPath:o,context:a,highlightEntity:i,unhighlightEntity:n}){i?.(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:()=>n?.(e)}),Promise.resolve(void 0)}},mo={icon:r.jsx(p.FileCopyIcon,{}),name:"Copy",onClick({entity:e,collection:t,context:o,highlightEntity:a,unhighlightEntity:i}){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:()=>i?.(e)}),Promise.resolve(void 0)}},xl={icon:r.jsx(p.ArchiveIcon,{}),name:"Archive",onClick({entity:e,collection:t,context:{dataSource:o}}){return Promise.resolve(void 0)}},El={icon:r.jsx(p.OpenInNewIcon,{}),name:"See in website",onClick({entity:e,collection:t,context:o}){return window.open(`https://example.com/${e.id}`,"_blank"),Promise.resolve(void 0)}},ho={icon:r.jsx(p.DeleteIcon,{}),name:"Delete",onClick({entity:e,fullPath:t,collection:o,context:a,selectionController:i,onCollectionChange:n,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(_n,{entityOrEntitiesToDelete:e,path:t,collection:o,callbacks:o.callbacks,open:c,onEntityDelete:()=>{a.analyticsController?.onAnalyticsEvent?.("single_entity_deleted",{path:t}),i?.setSelectedEntities(i.selectedEntities.filter(u=>u.id!==e.id)),n?.(),s?.close()},onClose:l})}});return Promise.resolve(void 0)}};function xn({onSingleEntitySelected:e,onMultipleEntitiesSelected:t,multiselect:o,collection:a,path:i,selectedEntityIds:n,description:s,forceFilter:l,maxSelection:c}){const u=gr(),f=at(),g=pe(),m=gt(),h=se(),A=g.resolveAliasesFrom(i),y=ze(a),[b,k]=d.useState([]),_=q=>{let j;const O=v.selectedEntities;if(m.onAnalyticsEvent?.("reference_selection_toggle",{path:A,entityId:q.id}),O){if(O.map(te=>te.id).indexOf(q.id)>-1)j=O.filter(te=>te.id!==q.id);else{if(c&&O.length>=c)return;j=[...O,q]}v.setSelectedEntities(j),t&&t(j)}},v=uo(_);d.useEffect(()=>{let q=!1;const j=n?.map(O=>O?.toString()).filter(Boolean);return j&&a?Promise.all(j.map(O=>y.fetchEntity({path:A,entityId:O,collection:a}))).then(O=>{if(!q){const te=O.filter(Z=>Z!==void 0);v.setSelectedEntities(te),k(te)}}):(v.setSelectedEntities([]),k([])),()=>{q=!0}},[y,A,n,a,v.setSelectedEntities]);const x=()=>{m.onAnalyticsEvent?.("reference_selection_clear",{path:A}),v.setSelectedEntities([]),!o&&e?e(null):t&&t([])},C=q=>{!o&&e?(m.onAnalyticsEvent?.("reference_selected_single",{path:A,entityId:q.id}),e(q),u.close(!1)):_(q)},E=()=>{m.onAnalyticsEvent?.("reference_selection_new_entity",{path:A}),f.open({path:A,collection:a,updateUrl:!0,onUpdate:({entity:q})=>{k([q,...b]),C(q)},closeOnSave:!0})},B=({entity:q,size:j,width:O,frozen:te})=>{const Z=v.selectedEntities,le=Z&&Z.map(ne=>ne.id).indexOf(q.id)>-1;return r.jsx(lr,{width:O,frozen:te,entity:q,size:j,isSelected:le,selectionEnabled:o,hideId:a?.hideIdFromCollection,fullPath:A,selectionController:v})},S=d.useCallback(q=>{q.stopPropagation(),u.close(!1)},[u]);if(!a)return r.jsx(ye,{error:"Could not find collection with id "+a});const P=d.useMemo(()=>Ne({collection:a,path:A,values:{},fields:h.propertyConfigs}),[a,h.propertyConfigs,A]),T=io(P,!1),N=po({fullPath:A,collection:a,entitiesDisplayedFirst:b,forceFilter:l}),{textSearchLoading:M,textSearchInitialised:L,onTextSearchClick:ee,textSearchEnabled:G}=fo({collection:a,fullPath:A});return r.jsxs("div",{className:"flex flex-col h-full",children:[r.jsx("div",{className:"flex-grow",children:b&&r.jsx(co,{textSearchLoading:M,onTextSearchClick:L?void 0:ee,textSearchEnabled:G,displayedColumnIds:T,onEntityClick:C,tableController:N,enablePopupIcon:!1,tableRowActionsBuilder:B,title:r.jsx(p.Typography,{variant:"subtitle2",children:a.singularName?`Select ${a.singularName}`:`Select from ${a.name}`}),defaultSize:a.defaultSize,properties:P.properties,forceFilter:l,inlineEditing:!1,selectionController:v,actions:r.jsx(Bl,{collection:a,path:A,onNewClick:E,onClear:x})})}),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 Bl({collection:e,path:t,onClear:o,onNewClick:a}){const i=ot(),n=Oe(),s=a?c=>{c.preventDefault(),a()}:void 0,l=ft(e,i,t,null)&&s&&(n?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 Pt(e){return Array.isArray(e)?e:e?[e]:[]}function go({children:e,group:t}){const o=ht();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(i=>i!==(t??"ungrouped")));else{const i=(o.collapsedGroups??[]).concat(t??"ungrouped");o.setCollapsedGroups(i)}},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 En({name:e,description:t,icon:o,actions:a,onClick:i}){return r.jsx(p.Card,{className:p.cls("h-full p-4 cursor-pointer min-h-[230px]"),onClick:()=>{i?.()},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:n=>{n.preventDefault(),n.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 Bn({name:e,url:t,icon:o}){return r.jsx(r.Fragment,{children:r.jsxs(ge.Link,{tabIndex:0,className:p.cls(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 Sn({path:e,collection:t,view:o,url:a,name:i,description:n,onClick:s,type:l}){const c=ht(),u=r.jsx(rr,{collectionOrView:t??o}),f=ge.useNavigate(),g=Ce(),m=se(),h=(c?.favouritePaths??[]).includes(e),A=c?[r.jsx(p.IconButton,{onClick:b=>{b.preventDefault(),b.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(m.plugins&&t){const b={path:e,collection:t,context:g};m.plugins.forEach((k,_)=>A.push(k.homePage?.CollectionActions?r.jsx(k.homePage.CollectionActions,{...b,extraProps:k.homePage.extraProps},`actions_${_}`):null))}const y=r.jsx(r.Fragment,{children:A});return l==="admin"?r.jsx(Bn,{icon:u,name:i,url:a}):r.jsx(En,{icon:u,name:i,description:n,actions:y,onClick:()=>{s?.(),f(a),c&&c.setRecentlyVisitedPaths([e,...(c.recentlyVisitedPaths??[]).filter(b=>b!==e)])}})}function Sl({entry:e}){const t=ge.useNavigate(),o=ht();if(!o)return null;const a=o.favouritePaths.includes(e.path),i=n=>{n.preventDefault(),n.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:i,size:18,className:"text-secondary"}):r.jsx(p.StarBorderIcon,{onClick:i,size:18,className:"text-gray-400 dark:text-gray-500"}),children:e.name},e.path)}function Il({hidden:e}){const t=pe(),o=ht();if(!o)return null;const a=(o?.favouritePaths??[]).map(i=>t.topLevelNavigation?.navigationEntries.find(n=>n.path===i)).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(i=>r.jsx(Sl,{entry:i},i.path))})})}const Ao={};function Fl(){const e=ge.useLocation(),t=d.useRef(null),[o,a]=d.useState(0),[i,n]=d.useState("down"),s=d.useCallback(()=>{!t.current||!e.key||(Ao[e.key]=t.current.scrollTop,a(t.current.scrollTop),n(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||!Ao[e.key]||t.current.scrollTo({top:Ao[e.key],behavior:"auto"})},[e]),{containerRef:t,scroll:o,direction:i}}const wt=new Ho.Search("url");wt.addIndex("name"),wt.addIndex("description"),wt.addIndex("group"),wt.addIndex("path");function In({additionalActions:e,additionalChildrenStart:t,additionalChildrenEnd:o}){const a=Ce(),i=se(),n=pe();if(!n.topLevelNavigation)throw Error("Navigation not ready in FireCMSHomePage");const{containerRef:s,scroll:l,direction:c}=Fl(),{navigationEntries:u,groups:f}=n.topLevelNavigation,[g,m]=d.useState(null),h=g?u.filter(v=>g.includes(v.url)):u;d.useEffect(()=>{wt.addDocuments(u)},[u]);const A=d.useCallback(v=>{if(!v||v==="")m(null);else{const x=wt.search(v);m(x.map(C=>C.url))}},[]),y=[...f];(h.filter(v=>!v.group).length>0||h.length===0)&&y.push(void 0);let b,k,_;if(i.plugins){const v={context:a};_=r.jsx(r.Fragment,{children:i.plugins.filter(x=>x.homePage?.includeSection).map((x,C)=>{const E=x.homePage.includeSection(v);return r.jsx(go,{group:E.title,children:E.children},`plugin_section_${x.key}`)})}),b=r.jsx("div",{className:"flex flex-col gap-2",children:i.plugins.filter(x=>x.homePage?.additionalChildrenStart).map((x,C)=>r.jsx("div",{children:x.homePage.additionalChildrenStart},`plugin_children_start_${C}`))}),k=r.jsx("div",{className:"flex flex-col gap-2",children:i.plugins.filter(x=>x.homePage?.additionalChildrenEnd).map((x,C)=>r.jsx("div",{children:x.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:A,placeholder:"Search collections",large:!1,innerClassName:"w-full",className:"w-full flex-grow"}),e]}),r.jsx(Il,{hidden:!!g}),t,b,y.map((v,x)=>{const C=[],E={group:v,context:a};i.plugins&&i.plugins.forEach(S=>{S.homePage?.AdditionalCards&&C.push(...Pt(S.homePage?.AdditionalCards))});const B=h.filter(S=>S.group===v||!S.group&&v===void 0);return B.length===0&&C.length===0?null:r.jsx(go,{group:v,children:r.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:[B.map(S=>r.jsx("div",{className:"col-span-1",children:r.jsx(Sn,{...S,onClick:()=>{let P;S.type==="collection"?P="home_navigate_to_collection":S.type==="view"?P="home_navigate_to_view":S.type==="admin"?P="home_navigate_to_admin_view":P="unmapped_event",a.analyticsController?.onAnalyticsEvent?.(P,{path:S.path})}})},`nav_${S.group}_${S.name}`)),v?.toLowerCase()!=="admin"&&C&&C.map((S,P)=>r.jsx("div",{children:r.jsx(S,{...E})},`nav_${v}_add_${P}`))]})},`plugin_section_${v}`)}),_,k,o]})})}function Fn({collection:e,relativePath:t,parentCollectionIds:o,onNewClick:a,onMultipleDeleteClick:i,selectionEnabled:n,path:s,selectionController:l,tableController:c,collectionEntitiesCount:u}){const f=Ce(),m=se().plugins??[],h=ot(),A=Oe(),y=l.selectedEntities,b=ft(e,h,s,null)&&a&&(A?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=Rt(e,h,s,null);let _;if(n){const C=A?r.jsxs(p.Button,{variant:"text",disabled:!y?.length||!k,startIcon:r.jsx(p.DeleteIcon,{}),onClick:i,color:"primary",className:"lg:w-20",children:["(",y?.length,")"]}):r.jsx(p.IconButton,{color:"primary",disabled:!y?.length||!k,onClick:i,children:r.jsx(p.DeleteIcon,{})});_=r.jsx(p.Tooltip,{title:k?"Delete":"You have selected at least one entity you cannot delete",children:C})}const v={path:s,relativePath:t,parentCollectionIds:o,collection:e,selectionController:l,context:f,tableController:c,collectionEntitiesCount:u},x=Pt(e.Actions).map((C,E)=>r.jsx(ae,{children:r.jsx(C,{...v})},`actions_${E}`));return m&&m.forEach((C,E)=>{C.collectionView?.CollectionActions&&x.push(...Pt(C.collectionView?.CollectionActions).map((B,S)=>r.jsx(ae,{children:r.jsx(B,{...v,...C.collectionView?.collectionActionsProps})},`plugin_actions_${E}_${S}`)))}),r.jsxs(r.Fragment,{children:[x,_,b]})}function Nl({containerRef:e,innerRef:t,x:o,y:a,onMove:i}){let n=0,s=0;const l=d.useRef(!1),c=A=>{if(A.button!==0||!e.current||A.defaultPrevented||A.innerClicked)return;const{x:y,y:b}=e.current.getBoundingClientRect();n=A.screenX-y,s=A.screenY-b,document.addEventListener("mousemove",m),document.addEventListener("mouseup",g),document.addEventListener("selectstart",f),l.current=!0},u=A=>{A.innerClicked=!0},f=A=>{A.preventDefault(),A.stopPropagation()},g=A=>{document.removeEventListener("mousemove",m),document.removeEventListener("mouseup",g),document.removeEventListener("selectstart",f),A.stopPropagation(),l.current=!1},m=A=>{A.target.localName==="input"||!l.current||(i({x:A.screenX-n,y:A.screenY-s}),A.stopPropagation())},h=()=>{e.current&&(e.current.style.top=`${a}px`,e.current.style.left=`${o}px`)};d.useEffect(()=>{const A=e.current,y=t.current;if(!(!A||!y))return y&&y.addEventListener("mousedown",u),A&&A.addEventListener("mousedown",c),h(),()=>{A&&A.removeEventListener("mousedown",c),y&&y.removeEventListener("mousedown",u)}})}function Pl(){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 Tl=({onResize:e})=>{const t=d.useRef(0),o=d.useRef(null),a=d.useRef(e);a.current=e;const i=d.useCallback(s=>{t.current&&cancelAnimationFrame(t.current),t.current=requestAnimationFrame(()=>{a.current(s)})},[]),n=d.useCallback(()=>{const s=o.current;s&&s.contentDocument&&s.contentDocument.defaultView&&s.contentDocument.defaultView.addEventListener("resize",i)},[i]);return d.useEffect(()=>{const s=o.current;return()=>{s&&s.contentDocument&&s.contentDocument.defaultView&&s.contentDocument.defaultView.removeEventListener("resize",i)}},[i]),r.jsx("object",{onLoad:n,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 Dl(e){return e.open?r.jsx(Ql,{...e}):null}function Ql({tableKey:e,entity:t,customFieldValidator:o,propertyKey:a,collection:i,path:n,cellRect:s,open:l,onClose:c,onCellValueChange:u,container:f}){const g=Ce(),m=se(),[h,A]=d.useState(),[y,b]=d.useState(),k=t?.id,[_,v]=d.useState(t),[x,C]=d.useState(_?.values),E=i?Ne({collection:i,path:n,values:x,entityId:k,fields:m.propertyConfigs}):void 0,B=Pl(),S=d.useRef(null),P=d.useRef(null),T=d.useRef(!1),N=d.useCallback(()=>{if(!s)throw Error("getInitialLocation error");return{x:s.left<B.width-s.right?s.x+s.width/2:s.x-s.width/2,y:s.top<B.height-s.bottom?s.y+s.height/2:s.y-s.height/2}},[s,B.height,B.width]),M=d.useCallback(({x:z,y:I})=>{const D=S.current?.getBoundingClientRect();if(!D)throw Error("normalizePosition called before draggableBoundingRect is set");return{x:Math.max(0,Math.min(z,B.width-D.width)),y:Math.max(0,Math.min(I,B.height-D.height))}},[B]),L=d.useCallback(z=>{const I=S.current?.getBoundingClientRect();if(!s||!I)return;const D=z??M(N());(!y||D.x!==y.x||D.y!==y.y)&&b(D)},[s,N,M,y]);Nl({containerRef:S,innerRef:P,x:y?.x,y:y?.y,onMove:L}),d.useEffect(()=>{T.current=!1},[a,_]),d.useLayoutEffect(()=>{const z=S.current?.getBoundingClientRect();!s||!z||T.current||(L(),T.current=!0)},[s,L,T.current]),d.useLayoutEffect(()=>{L(y)},[B,s]);const ee=d.useMemo(()=>{if(!(!E||!k))return cn(k,a&&E.properties[a]?{[a]:E.properties[a]}:{},o)},[E,k,a,o]),G=d.useCallback(()=>L(y),[y,L]),q=async z=>(A(null),i&&_&&u&&a?u({value:z[a],propertyKey:a,data:_,setError:A,onValueUpdated:()=>{}}):Promise.resolve());if(!_)return r.jsx(r.Fragment,{});const j=ve.useCreateFormex({initialValues:_?.values??{},validation:z=>ee?.validate(z,{abortEarly:!1}).then(()=>({})).catch(I=>{const D={};return I.inner.forEach(ie=>{D[ie.path]=ie.message}),D}),validateOnInitialRender:!0,onSubmit:(z,I)=>{q(z).then(()=>c()).finally(()=>I.setSubmitting(!1))}}),{values:O,isSubmitting:te,setFieldValue:Z,handleSubmit:le}=j;if(d.useEffect(()=>{Y(O,x)||C(O)},[O]),!_)return r.jsx(ye,{error:"PopupFormField misconfiguration"});if(!E)return r.jsx(r.Fragment,{});const ne=te,re={collection:E,entityId:k,values:O,path:n,setFieldValue:Z,save:q,formex:j},J=a&&rt(E.properties,a),Q=a&&J?{propertyKey:a,disabled:te||pt(J)||!!J.disabled,property:J,includeDescription:!1,underlyingValueHasChanged:!1,context:re,tableMode:!0,partOfArray:!1,partOfBlock:!1,autoFocus:l}:void 0;let R=r.jsx(r.Fragment,{children:r.jsx("div",{className:"w-[560px] max-w-full max-h-[85vh]",children:r.jsxs("form",{onSubmit:le,noValidate:!0,children:[r.jsx("div",{className:"mb-1 p-4 flex flex-col relative",children:r.jsx("div",{ref:P,className:"cursor-auto",style:{cursor:"auto !important"},children:Q&&r.jsx(lt,{...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 H=m.plugins;H&&H.forEach(z=>{z.form?.provider&&(R=r.jsx(z.form.provider.Component,{status:"existing",path:n,collection:E,entity:_,context:g,currentEntityId:k,formContext:re,...z.form.provider.props,children:R}))});const $=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:[R,h&&r.jsx(p.Typography,{color:"error",children:h.message})]}),V=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(Tl,{onResize:G}),r.jsxs("div",{className:"overflow-hidden",children:[$,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:z=>{z.stopPropagation(),c()},children:r.jsx(p.ClearIcon,{className:"text-white",size:"small"})})})]})]},`draggable_${a}_${k}_${l}`);return r.jsx(Ai.Root,{asChild:!0,container:f,children:r.jsx(ve.Formex,{value:j,children:V})})}function Ml({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 i;return o&&a?i="Clear filter and sort":o?i="Clear filter":i="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,{}),i]})}return null}function Ol({collection:e,relativePath:t,parentCollectionIds:o,path:a,selectionController:i,tableController:n,collectionEntitiesCount:s}){const l=Ce(),u=se().plugins??[],f={path:a,relativePath:t,parentCollectionIds:o,collection:e,selectionController:i,context:l,tableController:n,collectionEntitiesCount:s},g=[r.jsx(Ml,{tableController:n,enabled:!e.forceFilter},"clear_filter")];return u&&u.forEach((m,h)=>{m.collectionView?.CollectionActionsStart&&g.push(...Pt(m.collectionView?.CollectionActionsStart).map((A,y)=>r.jsx(ae,{children:r.jsx(A,{...f,...m.collectionView?.collectionActionsStartProps})},`plugin_actions_${h}_${y}`)))}),r.jsx(r.Fragment,{children:g})}const zl="collectionGroupParent",bo=d.memo(function({fullPath:t,parentCollectionIds:o,isSubCollection:a,className:i,...n}){const s=Ce(),l=t??n.path,c=ze(n),u=pe(),f=at(),g=ot(),m=ht(),h=gt(),A=se(),y=d.useRef(null),b=d.useMemo(()=>{const U=m?.getCollectionConfig(l);return U?Me(n,U):n},[n,l,m?.getCollectionConfig]),k=d.useRef(b);d.useEffect(()=>{k.current=b},[b]);const _=ft(b,g,l,null),[v,x]=d.useState(void 0),[C,E]=d.useState(void 0),[B,S]=d.useState(0),[P,T]=d.useState(0),N=d.useCallback(()=>{const U=v;setTimeout(()=>{U===v&&x(void 0)},2400)},[v]),M=d.useCallback(U=>{const oe=k.current;return Or(oe,g,l,U??null)?oe.inlineEditing===void 0||oe.inlineEditing:!1},[g,l]),L=b.selectionEnabled===void 0||b.selectionEnabled,ee=!M(),[G,q]=d.useState(!1),j=uo(),O=b.selectionController??j,{selectedEntities:te,isEntitySelected:Z,setSelectedEntities:le}=O;d.useEffect(()=>{E(void 0)},[te]);const ne=po({fullPath:l,collection:b,lastDeleteTimestamp:B}),re=d.useRef(Math.random().toString(36)),J=ne.popupCell,Q=d.useCallback(()=>{ne.setPopupCell?.(void 0)},[ne.setPopupCell]),R=d.useCallback(U=>{console.log("Entity clicked",U);const oe=k.current;return x(U),h.onAnalyticsEvent?.("edit_entity_clicked",{path:U.path,entityId:U.id}),f.open({entityId:U.id,path:U.path,collection:oe,updateUrl:!0,onClose:N})},[N,f]),H=d.useCallback(()=>{const U=k.current;h.onAnalyticsEvent?.("new_entity_click",{path:l}),f.open({path:l,collection:U,updateUrl:!0,onClose:N})},[l,f]),$=()=>{h.onAnalyticsEvent?.("multiple_delete_dialog_open",{path:l}),E(te)},V=(U,oe)=>{h.onAnalyticsEvent?.("single_entity_deleted",{path:l}),le(ce=>ce.filter(de=>de.id!==oe.id)),S(Date.now())},z=(U,oe)=>{h.onAnalyticsEvent?.("multiple_entities_deleted",{path:l}),le([]),E(void 0),S(Date.now())};let I;A?.plugins&&(I=A.plugins.find(U=>U.collectionView?.AddColumnComponent)?.collectionView?.AddColumnComponent);const D=d.useCallback((U,oe)=>{if(m){const ce=m.getCollectionConfig(U),de=Me(ce,oe);m.onCollectionModified(U,de)}},[m]),ie=d.useCallback(({width:U,key:oe})=>{const ce=k.current;if(!rt(ce.properties,oe))return;const de=Nn(oe,U);D(l,de)},[D,l]),xe=d.useCallback(U=>{m&&D(l,{defaultSize:U})},[D,l,m]),Le=ft(b,g,l,null),K=d.useCallback(({name:U,value:oe,property:ce,entityId:de})=>c.checkUniqueField(l,U,oe,de),[l]),he=({value:U,propertyKey:oe,onValueUpdated:ce,setError:de,data:ue})=>{const Ye=ve.setIn({...ue.values},oe,U),et={path:l,entityId:ue.id,values:Ye,previousValues:ue.values,collection:b,status:"existing"};return Ur({...et,collection:b,dataSource:c,context:s,onSaveSuccess:()=>{de(void 0),ce()},onSaveFailure:zt=>{console.error("Save failure"),console.error(zt),de(zt)}})},Te=u.resolveAliasesFrom(l),Fe=d.useMemo(()=>Ne({collection:b,path:l,fields:A.propertyConfigs}),[b,l]),Ae=d.useCallback(({propertyKey:U,entity:oe})=>{let ce=rt(b.properties,U);return ce||(ce=rt(Fe.properties,U)),Pe({propertyKey:U,propertyOrBuilder:ce,path:oe.path,values:oe.values,entityId:oe.id,fields:A.propertyConfigs})},[b.properties,A.propertyConfigs,Fe.properties]),Ge=io(Fe,!0),je=d.useMemo(()=>{const U=b.subcollections?.map(ce=>({key:ao(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:ue=>{ue.stopPropagation(),f.open({path:l,entityId:de.id,selectedSubPath:ce.id??ce.path,collection:b,updateUrl:!0})},children:ce.name})}))??[],oe=b.collectionGroup?[{key:zl,name:"Parent entities",width:260,dependencies:[],Builder:({entity:ce})=>{const de=u.getParentReferencesFromPath(ce.path);return r.jsx("div",{className:"flex flex-col gap-2 w-full",children:de.map(ue=>r.jsx(Ve,{reference:ue,size:"tiny"},ue.path+"/"+ue.id))})}}]:[];return[...b.additionalFields??[],...U,...oe]},[b,l,f]),qe=d.useCallback(()=>{S(Date.now())},[]),X=Oe(),be=({entity:U,customEntityActions:oe})=>{const ce=U?Rt(b,g,l,U):!0,de=[Cn];return Le&&de.push(mo),ce&&de.push(ho),oe&&de.push(...oe),de},wr=()=>{const U=be({}),oe=U.filter(ue=>ue.collapsed!==!1),de=U.filter(ue=>ue.collapsed===!1).length*(X?40:30);return(X?80+de:70+de)+(oe.length>0?X?40:30:0)},Mt=({entity:U,size:oe,width:ce,frozen:de})=>{const ue=Z(U),Ye=be({entity:U,customEntityActions:b.entityActions});return r.jsx(lr,{entity:U,width:ce,frozen:de,isSelected:ue,selectionEnabled:L,size:oe,highlightEntity:x,unhighlightEntity:N,collection:b,fullPath:l,actions:Ye,hideId:b?.hideIdFromCollection,onCollectionChange:qe,selectionController:O})},Re=r.jsx(p.Popover,{open:G,onOpenChange:q,enabled:!!b.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] ${b.description?"cursor-pointer":"cursor-auto"}`,onClick:b.description?U=>{q(!0),U.stopPropagation()}:void 0,children:`${b.name}`}),r.jsx(Vl,{fullPath:l,collection:b,filter:ne.filterValues,sortBy:ne.sortBy,onCountChange:T})]}),children:b.description&&r.jsx("div",{className:"m-4 text-gray-900 dark:text-white",children:r.jsx(p.Markdown,{source:b.description})})}),Ot=d.useCallback(({property:U,propertyKey:oe,onHover:ce})=>{const de=k.current;return A.plugins?r.jsx(r.Fragment,{children:A.plugins.filter(ue=>ue.collectionView?.HeaderAction).map((ue,Ye)=>{const et=ue.collectionView.HeaderAction;return r.jsx(et,{onHover:ce,propertyKey:oe,property:U,fullPath:l,collection:de,parentCollectionIds:o??[]},`plugin_header_action_${Ye}`)})}):null},[A.plugins,l,o]),Oo=I?function(){return typeof I=="function"?r.jsx(I,{fullPath:l,parentCollectionIds:o??[],collection:b}):null}:void 0,{textSearchLoading:zo,textSearchInitialised:Vo,onTextSearchClick:kt,textSearchEnabled:Go}=fo({collection:b,fullPath:Te,parentCollectionIds:o});return r.jsxs("div",{className:p.cls("overflow-hidden h-full w-full rounded-md",i),ref:y,children:[r.jsx(co,{additionalFields:je,tableController:ne,enablePopupIcon:!0,displayedColumnIds:Ge,onSizeChanged:xe,onEntityClick:R,onColumnResize:ie,onValueChange:he,tableRowActionsBuilder:Mt,uniqueFieldValidator:K,title:Re,selectionController:O,highlightedEntities:v?[v]:[],defaultSize:b.defaultSize,properties:Fe.properties,getPropertyFor:Ae,onTextSearchClick:Vo?void 0:kt,textSearchLoading:zo,textSearchEnabled:Go,actionsStart:r.jsx(Ol,{parentCollectionIds:o??[],collection:b,tableController:ne,path:l,relativePath:b.path,selectionController:O,collectionEntitiesCount:P}),actions:r.jsx(Fn,{parentCollectionIds:o??[],collection:b,tableController:ne,onMultipleDeleteClick:$,onNewClick:H,path:l,relativePath:b.path,selectionController:O,selectionEnabled:L,collectionEntitiesCount:P}),emptyComponent:_&&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:H,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:ee,inlineEditing:M(),AdditionalHeaderWidget:Ot,AddColumnComponent:Oo,getIdColumnWidth:wr,additionalIDHeaderWidget:r.jsx(Gl,{path:l,collection:b})},`collection_table_${l}`),r.jsx(Dl,{open:!!J,onClose:Q,cellRect:J?.cellRect,propertyKey:J?.propertyKey,collection:b,entity:J?.entity,tableKey:re.current,customFieldValidator:K,path:Te,onCellValueChange:he,container:y.current},`popup_form_${J?.propertyKey}_${J?.entity?.id}`),C&&r.jsx(_n,{entityOrEntitiesToDelete:C,path:l,collection:b,callbacks:b.callbacks,open:!!C,onEntityDelete:V,onMultipleEntitiesDelete:z,onClose:()=>E(void 0)})]})},(e,t)=>Y(e.fullPath,t.fullPath)&&Y(e.parentCollectionIds,t.parentCollectionIds)&&Y(e.isSubCollection,t.isSubCollection)&&Y(e.className,t.className)&&Y(e.properties,t.properties)&&Y(e.propertiesOrder,t.propertiesOrder)&&Y(e.hideIdFromCollection,t.hideIdFromCollection)&&Y(e.inlineEditing,t.inlineEditing)&&Y(e.selectionEnabled,t.selectionEnabled)&&Y(e.selectionController,t.selectionController)&&Y(e.Actions,t.Actions)&&Y(e.defaultSize,t.defaultSize)&&Y(e.initialFilter,t.initialFilter)&&Y(e.initialSort,t.initialSort)&&Y(e.textSearchEnabled,t.textSearchEnabled)&&Y(e.additionalFields,t.additionalFields)&&Y(e.sideDialogWidth,t.sideDialogWidth)&&Y(e.forceFilter,t.forceFilter));function Vl({fullPath:e,collection:t,filter:o,sortBy:a,onCountChange:i}){const n=ze(t),s=pe(),[l,c]=d.useState(void 0),[u,f]=d.useState(void 0),g=a?a[0]:void 0,m=a?a[1]:void 0,h=d.useMemo(()=>s.resolveAliasesFrom(e),[e,s.resolveAliasesFrom]);return d.useEffect(()=>{n.countEntities&&n.countEntities({path:h,collection:t,filter:o,orderBy:g,order:m}).then(c).catch(f)},[e,n.countEntities,h,t,o,g,m]),d.useEffect(()=>{i&&(f(void 0),i(l??0))},[i,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 Nn(e,t){if(e.includes(".")){const[o,...a]=e.split(".");return{properties:{[o]:Nn(a.join("."),t)}}}return{properties:{[e]:{columnWidth:t}}}}function Gl({collection:e,path:t}){const[o,a]=d.useState(!1),[i,n]=d.useState(""),s=at();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(),!!i)return a(!1),s.open({entityId:i.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=>{n(l.target.value)},value:i,className:"flex-grow bg-transparent outline-none p-1"}),r.jsx(p.Button,{variant:"outlined",disabled:!i.trim(),type:"submit",children:"Go"})]})})})})}function Yl({propertyConfig:e}){const t="h-8 w-8 p-1 rounded-full shadow text-white",o=typeof e?.property=="object"?qn(e.property):void 0;return r.jsx("div",{className:t,style:{background:e?.color??o?.color??"#888"},children:e?.Icon?Xt(e,"medium"):Xt(o,"medium")})}function Pn(){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 Ll({open:e,onAccept:t,onCancel:o,title:a,loading:i,body:n}){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}),n]}),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:i,onClick:t,children:"Ok"})]})]})}function yo({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 wo=d.createContext({hasDrawer:!1,drawerHovered:!1,drawerOpen:!1,openDrawer:()=>{throw new Error("openDrawer not implemented")},closeDrawer:()=>{throw new Error("closeDrawer not implemented")},autoOpenDrawer:!1});function pr(){return d.useContext(wo)}const Tn=function({title:t,endAdornment:o,startAdornment:a,dropDownActions:i,includeModeToggle:n=!0,className:s,style:l,user:c}){const{hasDrawer:u,drawerOpen:f,logo:g}=pr(),m=pe(),h=ot(),{mode:A,toggleMode:y}=Pa(),b=Oe(),k=c??h.user;let _;if(k&&k.photoURL)_=r.jsx(p.Avatar,{src:k.photoURL});else if(k===void 0||h.initialLoading)_=r.jsx("div",{className:"p-1 flex justify-center",children:r.jsx(p.Skeleton,{className:"w-10 h-10 rounded-full"})});else{const v=k?.displayName?k.displayName[0].toUpperCase():k?.email?k.email[0].toUpperCase():"A";_=r.jsx(p.Avatar,{children:v})}return r.jsx("div",{style:l,className:p.cls("pr-2 w-full h-16 transition-all ease-in duration-75 fixed",{"pl-[17rem]":f&&b,"pl-20":u&&!(f&&b),"z-10":b,"duration-150":f&&b},s),children:r.jsxs("div",{className:"flex flex-row gap-2 px-4 h-full items-center",children:[m&&r.jsx("div",{className:"mr-8 hidden lg:block",children:r.jsx(ge.Link,{className:"visited:text-inherit visited:dark:text-inherit",to:m?.basePath??"/",children:r.jsxs("div",{className:"flex flex-row gap-4",children:[!u&&(g?r.jsx("img",{src:g,alt:"Logo",className:p.cls("w-[32px] h-[32px] object-contain")}):r.jsx(yo,{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}),n&&r.jsx(p.IconButton,{color:"inherit","aria-label":"Open drawer",onClick:y,size:"large",children:A==="dark"?r.jsx(p.DarkModeIcon,{}):r.jsx(p.LightModeIcon,{})}),r.jsxs(p.Menu,{trigger:_,children:[k&&r.jsxs("div",{className:"px-4 py-2 mb-2",children:[k.displayName&&r.jsx(p.Typography,{variant:"body1",color:"secondary",children:k.displayName}),k.email&&r.jsx(p.Typography,{variant:"body2",color:"secondary",children:k.email})]}),i,!i&&r.jsxs(p.MenuItem,{onClick:h.signOut,children:[r.jsx(p.LogoutIcon,{}),"Log Out"]})]})]})})},jl=e=>e&&Array.isArray(e)&&e.length>0?e.map((t,o)=>t?{[Br(t)+o]:Tt()}:{}).reduce((t,o)=>({...t,...o}),{}):{};function vo({droppableId:e,addLabel:t,value:o,disabled:a=!1,buildEntry:i,size:n="medium",onInternalIdAdded:s,includeAddButton:l,newDefaultEntry:c,onValueChange:u}){const f=o&&Array.isArray(o)&&o.length>0,g=d.useRef(jl(o)),[m,h]=d.useState(f?Object.values(g.current):[]);d.useEffect(()=>{if(f&&o&&o.length!==m.length){const _=o.map((v,x)=>{const C=Br(v)+x;if(C in g.current)return g.current[C];{const E=Tt();return g.current[C]=E,E}});h(_)}},[f,m.length,o]);const A=_=>{if(_.preventDefault(),a)return;const v=Tt(),x=[...m,v];s&&s(v),h(x),u([...o??[],c])},y=_=>{const v=[...m];v.splice(_,1),h(v),u(o.filter((x,C)=>C!==_))},b=_=>{const v=Tt(),x=o[_],C=[...m.splice(0,_+1),v,...m.splice(_+1,m.length-_-1)];s&&s(v),h(C),u([...o.slice(0,_+1),x,...o.slice(_+1)])},k=_=>{if(!_.destination)return;const v=_.source.index,x=_.destination.index,C=[...m],E=C[v];C[v]=C[x],C[x]=E,h(C),u(Ul(o,v,x))};return r.jsx(ct.DragDropContext,{onDragEnd:k,children:r.jsx(ct.Droppable,{droppableId:e,renderClone:(_,v,x)=>{const C=x.source.index,E=m[C];return r.jsx(ko,{provided:_,internalId:E,index:C,size:n,disabled:a,buildEntry:i,remove:y,copy:b,isDragging:v.isDragging})},children:(_,v)=>r.jsxs("div",{..._.droppableProps,ref:_.innerRef,children:[f&&m.map((x,C)=>r.jsx(ct.Draggable,{draggableId:`array_field_${x}`,isDragDisabled:a,index:C,children:(E,B)=>r.jsx(ko,{provided:E,internalId:x,index:C,size:n,disabled:a,buildEntry:i,remove:y,copy:b,isDragging:B.isDragging})},`array_field_${x}`)),_.placeholder,l&&r.jsx("div",{className:"py-4 justify-center text-left",children:r.jsx(p.Button,{variant:"text",size:n==="small"?"small":"medium",color:"primary",disabled:a,startIcon:r.jsx(p.AddIcon,{}),onClick:A,children:t??"Add"})})]})})})}function ko({provided:e,index:t,internalId:o,size:a,disabled:i,buildEntry:n,remove:s,copy:l,isDragging:c}){const[u,f]=d.useState(!1),g=d.useCallback(()=>f(!0),[]),m=d.useCallback(()=>f(!1),[]);return r.jsx("div",{onMouseEnter:g,onMouseMove:g,onMouseLeave:m,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:n(t,o)}),r.jsx(Dn,{direction:a==="small"?"row":"column",disabled:i,remove:s,index:t,provided:e,copy:l})]})})}function Dn({direction:e,disabled:t,remove:o,index:a,provided:i,copy:n}){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,...i.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),n(a)},children:[r.jsx(p.ContentCopyIcon,{size:"small"}),"Copy"]})]})]})})}function Ul(e,t,o){const a=Array.from(e),[i]=a.splice(t,1);return a.splice(o,0,i),a}function Tt(){return Math.floor(Math.random()*Math.floor(Number.MAX_SAFE_INTEGER))}function $l({name:e,multiselect:t=!1,path:o,disabled:a,value:i,onReferenceSelected:n,onMultipleReferenceSelected:s,previewProperties:l,forceFilter:c,size:u,className:f,includeId:g,includeEntityLink:m}){const h=pe(),A=d.useMemo(()=>h.getCollection(o),[o,h.getCollection]),y=d.useCallback(x=>{if(!a&&n){const C=x?$e(x):null;n?.({reference:C,entity:x})}},[a,n]),b=d.useCallback(x=>{if(!a&&s){const C=x?x.map(E=>$e(E)):null;s({references:C,entities:x})}},[a,n]),k=At({multiselect:t,path:o,collection:A,onSingleEntitySelected:y,onMultipleEntitiesSelected:b,forceFilter:c});d.useCallback(x=>{x.stopPropagation(),t?b([]):y(null)},[n]);let _;const v=()=>{a||k.open()};return Array.isArray(i)?_=r.jsx("div",{className:"flex flex-col gap-4",children:i.map((x,C)=>r.jsx(Ve,{onClick:v,reference:x,disabled:a,previewProperties:l,size:u,includeId:g,includeEntityLink:m},`reference_preview_${C}`))}):i?.isEntityReference&&i?.isEntityReference()&&(_=r.jsx(Ve,{reference:i,onClick:v,disabled:a,previewProperties:l,size:u,includeId:g,includeEntityLink:m})),r.jsxs("div",{className:p.cls("text-sm font-medium","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",f),children:[_,!i&&r.jsx("div",{className:"justify-center text-left",children:r.jsxs(p.Button,{variant:"outlined",color:"primary",disabled:a,onClick:v,children:["Edit ",e]})})]})}const Wl=220;er&&process.env.NODE_ENV!=="production"&&Object.keys(er).forEach(e=>{p.iconKeys.includes(e)||console.warn(`The icon ${e} no longer exists. Remove it from \`iconSynonyms\``)});function ql({selectedIcon:e="",onIconSelected:t}){const[o,a]=d.useState(null),[i,n]=d.useState(""),s=d.useMemo(()=>p.debounce(c=>{if(!c||c==="")a(null);else{const u=tr.search(c);a(u.map(f=>f.key))}},Wl),[]);d.useEffect(()=>(s(i),()=>{s.clear()}),[i,s]);const l=o===null?p.coolIconKeys:o;return r.jsxs(r.Fragment,{children:[r.jsx(p.SearchBar,{autoFocus:!1,innerClassName:"w-full sticky top-0 z-10",onTextSearch:c=>n(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 Hl({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 ur({name:e,addLabel:t,value:o,disabled:a=!1,buildEntry:i,small:n,onInternalIdAdded:s,includeAddButton:l,newDefaultEntry:c=null,setFieldValue:u}){return r.jsx(vo,{droppableId:e,addLabel:t,value:o,disabled:a,buildEntry:i,size:n?"small":"medium",onInternalIdAdded:s,includeAddButton:l,newDefaultEntry:c,onValueChange:f=>u(e,f)})}function Ee({error:e,showError:t,property:o,includeDescription:a=!0,disabled:i}){const n=o.description||o.longDescription;if(!(t&&e)&&(!a||!n))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:i?"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 Be({icon:e,title:t,small:o,className:a,required:i}){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??"")+(i?" *":"")})]})}function _o({propertyKey:e,value:t,setValue:o,error:a,showError:i,disabled:n,autoFocus:s,touched:l,property:c,includeDescription:u}){const f=c.enumValues;Qe({property:c,value:t,setValue:o});const g=d.useCallback(m=>{m.stopPropagation(),m.preventDefault(),o(null)},[o]);return r.jsxs(r.Fragment,{children:[r.jsx(p.Select,{value:t!==void 0&&t!=null?t.toString():"",disabled:n,position:"item-aligned",inputClassName:p.cls("w-full"),label:r.jsx(Be,{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:m=>{const h=m?c.dataType==="number"?parseFloat(m):m:null;return o(h)},renderValue:m=>r.jsx(Ie,{enumKey:m,enumValues:f,size:"medium"}),children:f&&f.map(m=>r.jsx(p.SelectItem,{value:String(m.id),children:r.jsx(Ie,{enumKey:String(m.id),enumValues:f,size:"medium"})},m.id))}),r.jsx(Ee,{includeDescription:u,showError:i,error:a,disabled:n,property:c})]})}function Co({propertyKey:e,value:t,setValue:o,error:a,showError:i,disabled:n,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 f=Je(u.enumValues);if(!f)throw console.error(s),Error("Field misconfiguration: array field of type string or number needs to have enumValues");Qe({property:s,value:t,setValue:o});const g=!!t&&Array.isArray(t),m=d.useCallback((h,A)=>{const y=h!==void 0?Ht(f,h):void 0;return r.jsxs(Ie,{enumKey:h,enumValues:f,size:"medium",children:[y?.label??h,!A&&r.jsx("button",{className:"ml-1 ring-offset-background rounded-full outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",onMouseDown:b=>{b.preventDefault(),b.stopPropagation()},onClick:b=>{b.preventDefault(),b.stopPropagation(),o(t.filter(k=>k!==h))},children:r.jsx(p.CloseIcon,{size:"smallest"})})]},h)},[f,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:n,label:r.jsx(Be,{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=>m(h,!1),[m]),onMultiValueChange:h=>{let A;return u&&u?.dataType==="number"?A=h?h.map(y=>parseFloat(y)):[]:A=h,o(A)},children:f.map(h=>String(h.id)).map(h=>r.jsx(p.MultiSelectItem,{value:h,children:m(h,!0)},h))}),r.jsx(Ee,{includeDescription:l,showError:i,error:a,disabled:n,property:s})]})}function Qn({propertyKey:e,value:t,error:o,showError:a,disabled:i,isSubmitting:n,tableMode:s,property:l,includeDescription:c,setValue:u,setFieldValue:f}){const g=l.of;if(g.dataType!=="reference")throw Error("ArrayOfReferencesField expected a property containing references");const m=l.expanded===void 0?!0:l.expanded,h=t&&Array.isArray(t)?t.map(E=>E.id):[];Qe({property:l,value:t,setValue:u});const A=pe(),y=d.useMemo(()=>g.path?A.getCollection(g.path):void 0,[g.path]);if(!y)throw Error(`Couldn't find the corresponding collection for the path: ${g.path}`);const b=d.useCallback(E=>{console.debug("onMultipleEntitiesSelected",E),u(E.map(B=>$e(B)))},[u]),k=At({multiselect:!0,path:g.path,collection:y,onMultipleEntitiesSelected:b,selectedEntityIds:h,forceFilter:g.forceFilter}),_=d.useCallback(E=>{E.preventDefault(),k.open()},[k]),v=d.useCallback((E,B)=>{const S=t&&t.length>E?t[E]:void 0;return S?r.jsx(Ve,{disabled:!g.path,previewProperties:g.previewProperties,size:"medium",onClick:_,hover:!i,reference:S,includeId:g.includeId,includeEntityLink:g.includeEntityLink},B):r.jsx("div",{children:"Internal ERROR"})},[g.path,g.previewProperties,t]),x=r.jsx(Be,{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(ur,{value:t,addLabel:l.name?"Add reference to "+l.name:"Add reference",name:e,buildEntry:v,disabled:n,setFieldValue:f,newDefaultEntry:l.of.defaultValue}),r.jsxs(p.Button,{className:"my-4 justify-center text-left",variant:"outlined",color:"primary",disabled:n,onClick:_,children:["Edit ",l.name]})]})]});return r.jsxs(r.Fragment,{children:[!s&&r.jsx(p.ExpandablePanel,{titleClassName:p.fieldBackgroundMixin,className:p.cls("px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2",p.fieldBackgroundMixin),initiallyExpanded:m,title:x,children:C}),s&&C,r.jsx(Ee,{includeDescription:c,showError:a,error:o,disabled:i,property:l})]})}function Mn({name:e,property:t,value:o,onRemove:a,disabled:i,size:n}){return r.jsxs("div",{className:p.cls(p.paperMixin,"relative m-4 border-box flex items-center justify-center",n==="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:s=>{s.stopPropagation(),a(o)},children:r.jsx(p.RemoveIcon,{size:"small"})})})}),o&&r.jsx(ae,{children:r.jsx(we,{propertyKey:e,value:o,property:t,size:n})})]})}const Jl="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",Zl="border-dotted-gray",Xl=p.fieldBackgroundHoverMixin,Kl="pt-0 border-2 border-solid",Rl="transition-colors duration-200 ease-[cubic-bezier(0,0,0.2,1)] border-2 border-solid border-green-500",ec="transition-colors duration-200 ease-[cubic-bezier(0,0,0.2,1)] border-2 border-solid border-red-500";function xo({propertyKey:e,value:t,setValue:o,error:a,showError:i,autoFocus:n,tableMode:s,property:l,includeDescription:c,context:u,isSubmitting:f}){if(!u.entityId)throw new Error("StorageUploadFieldBinding: Entity id is null");const g=mt(u.collection),m=pt(l)||!!l.disabled||f,{internalValue:h,setInternalValue:A,onFilesAdded:y,storage:b,onFileUploadComplete:k,storagePathBuilder:_,multipleFilesSupported:v}=tn({entityValues:u.values,entityId:u.entityId,path:u.path,property:l,propertyKey:e,value:t,storageSource:g,disabled:m??!1,onChange:o});return Qe({property:l,value:t,setValue:o}),r.jsxs(r.Fragment,{children:[!s&&r.jsx(Be,{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(rc,{value:h,name:e,disabled:m??!1,autoFocus:n??!1,property:l,onChange:o,setInternalValue:A,onFilesAdded:y,onFileUploadComplete:k,storagePathBuilder:_,storage:b,multipleFilesSupported:v}),r.jsx(Ee,{includeDescription:c,showError:i,error:a,disabled:m,property:l})]})}function tc({storage:e,disabled:t,isDraggingOver:o,onFilesAdded:a,multipleFilesSupported:i,droppableProvided:n,autoFocus:s,internalValue:l,property:c,onClear:u,metadata:f,storagePathBuilder:g,onFileUploadComplete:m,size:h,name:A,helpText:y}){const b=Ze(),{getRootProps:k,getInputProps:_,isDragActive:v,isDragAccept:x,isDragReject:C}=qo.useDropzone({accept:e.acceptedFiles?e.acceptedFiles.map(E=>({[E]:[]})).reduce((E,B)=>({...E,...B}),{}):void 0,disabled:t||o,noDragEventsBubbling:!0,maxSize:e.maxSize,onDrop:a,onDropRejected:(E,B)=>{for(const S of E)for(const P of S.errors)b.open({type:"error",message:`Error uploading file: File is larger than ${e.maxSize} bytes`})}});return r.jsxs("div",{...k(),className:p.cls(p.fieldBackgroundMixin,t?p.fieldBackgroundDisabledMixin:p.fieldBackgroundHoverMixin,Jl,i&&l.length?"":"flex",p.focusedMixin,{[Xl]:!v,[Kl]:v,[ec]:C,[Rl]:x,[Zl]:t}),children:[r.jsxs("div",{...n.droppableProps,ref:n.innerRef,className:p.cls("flex items-center p-1 no-scrollbar",i&&l.length?"overflow-auto":"",i&&l.length?"min-h-[180px]":"min-h-[250px]"),children:[r.jsx("input",{autoFocus:s,..._()}),l.map((E,B)=>{let S;return E.storagePathOrDownloadUrl?S=r.jsx(Mn,{name:`storage_preview_${E.storagePathOrDownloadUrl}`,property:c,disabled:t,value:E.storagePathOrDownloadUrl,onRemove:u,size:E.size}):E.file&&(S=r.jsx(nn,{entry:E,metadata:f,storagePath:g(E.file),onFileUploadComplete:m,imageSize:h==="medium"?220:118,simple:!1})),r.jsx(ct.Draggable,{draggableId:`array_field_${A}_${E.id}`,index:B,children:(P,T)=>r.jsx("div",{tabIndex:-1,ref:P.innerRef,...P.draggableProps,...P.dragHandleProps,className:p.cls(p.focusedMixin,"rounded-md"),style:{...P.draggableProps.style},children:S})},`array_field_${A}_${E.id}`)}),n.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:y})})]})}function rc({property:e,name:t,value:o,setInternalValue:a,onChange:i,multipleFilesSupported:n,onFileUploadComplete:s,disabled:l,onFilesAdded:c,autoFocus:u,storage:f,storagePathBuilder:g}){if(n){const v=e;if(v.of){if(Array.isArray(v.of)||v.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 m=f?.metadata,h=n?"small":"medium",A=d.useCallback((v,x)=>{if(!n)return;const C=[...o],E=C[v];C.splice(v,1),C.splice(x,0,E),a(C);const B=C.filter(S=>!!S.storagePathOrDownloadUrl).map(S=>S.storagePathOrDownloadUrl);i(B)},[n,i,a,o]),y=d.useCallback(v=>{v.destination&&A(v.source.index,v.destination.index)},[A]),b=d.useCallback(v=>{if(n){const x=o.filter(C=>C.storagePathOrDownloadUrl!==v);i(x.filter(C=>!!C.storagePathOrDownloadUrl).map(C=>C.storagePathOrDownloadUrl)),a(x)}else i(null),a([])},[o,n,i]),k=n?"Drag 'n' drop some files here, or click to select files":"Drag 'n' drop a file here, or click to select one",_=n?e.of:e;return r.jsx(ct.DragDropContext,{onDragEnd:y,children:r.jsx(ct.Droppable,{droppableId:`droppable_${t}`,direction:"horizontal",renderClone:(v,x,C)=>{const E=o[C.source.index];return r.jsx("div",{ref:v.innerRef,...v.draggableProps,...v.dragHandleProps,style:v.draggableProps.style,className:"rounded",children:r.jsx(Mn,{name:`storage_preview_${E.storagePathOrDownloadUrl}`,property:_,disabled:!0,value:E.storagePathOrDownloadUrl,onRemove:b,size:E.size})})},children:(v,x)=>r.jsx(tc,{storage:f,disabled:l,isDraggingOver:x.isDraggingOver,droppableProvided:v,onFilesAdded:c,multipleFilesSupported:n,autoFocus:u,internalValue:o,property:_,onClear:b,metadata:m,storagePathBuilder:g,onFileUploadComplete:s,size:h,name:t,helpText:k})})})}function vt({context:e,propertyKey:t,value:o,setValue:a,error:i,showError:n,disabled:s,autoFocus:l,property:c,includeDescription:u}){let f,g;c.dataType==="string"&&(f=c.multiline,g=c.url),Qe({property:c,value:o,setValue:a});const m=d.useCallback(b=>{b.stopPropagation(),b.preventDefault(),a(null)},[a]),h=b=>{if(y==="number"){const k=b.target.value?parseFloat(b.target.value):void 0;k&&isNaN(k)?a(null):k!=null?a(k):a(null)}else a(b.target.value)},A=!!f,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(Be,{icon:_e(c,"small"),required:c.validation?.required,title:c.name}),type:y,multiline:A,disabled:s,endAdornment:c.clearable&&r.jsx(p.IconButton,{onClick:m,children:r.jsx(p.ClearIcon,{})}),error:n?i:void 0,inputClassName:i?"text-red-500 dark:text-red-600":""}),r.jsx(Ee,{includeDescription:u,showError:n,error:i,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 On=d.forwardRef(function({propertyKey:t,value:o,setValue:a,error:i,showError:n,autoFocus:s,disabled:l,touched:c,property:u,includeDescription:f},g){return Qe({property:u,value:o,setValue:a}),r.jsxs(r.Fragment,{children:[r.jsx(p.BooleanSwitchWithLabel,{value:o,onValueChange:m=>a(m),error:n,label:r.jsx(Be,{icon:_e(u,"small"),required:u.validation?.required,title:u.name}),disabled:l,autoFocus:s,size:"medium"}),r.jsx(Ee,{includeDescription:f,showError:n,error:i,disabled:l,property:u})]})});function zn({propertyKey:e,value:t,setValue:o,autoFocus:a,error:i,showError:n,disabled:s,touched:l,property:c,includeDescription:u}){const{locale:f}=se(),g=t||null;return Qe({property:c,value:t,setValue:o}),r.jsxs(r.Fragment,{children:[r.jsx(p.DateTimeField,{value:g,onChange:m=>o(m??null),size:"medium",mode:c.mode,clearable:c.clearable,locale:f,error:n,label:r.jsx(Be,{icon:_e(c,"small"),required:c.validation?.required,className:n?"text-red-500 dark:text-red-500":"text-text-secondary dark:text-text-secondary-dark",title:c.name})}),r.jsx(Ee,{includeDescription:u,showError:n,error:i,disabled:s,property:c})]})}function Eo({propertyKey:e,value:t,error:o,showError:a,tableMode:i,property:n,includeDescription:s,context:l}){if(!l.entityId)throw new Error("ReadOnlyFieldBinding: Entity id is null");return r.jsxs(r.Fragment,{children:[!i&&r.jsx(Be,{icon:_e(n,"small"),required:n.validation?.required,title:n.name,className:"text-text-secondary dark:text-text-secondary-dark ml-3.5"}),r.jsx("div",{className:p.cls(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:n,size:"medium"})})}),r.jsx(Ee,{includeDescription:s,showError:a,error:o,property:n})]})}function Vn(e){return typeof e.property.path!="string"?r.jsx(Eo,{...e}):r.jsx(oc,{...e})}function oc({value:e,setValue:t,error:o,showError:a,isSubmitting:i,disabled:n,touched:s,autoFocus:l,property:c,includeDescription:u,context:f}){if(!c.path)throw new Error("Property path is required for ReferenceFieldBinding");Qe({property:c,value:e,setValue:t});const g=e&&e.isEntityReference&&e.isEntityReference(),m=pe(),h=d.useMemo(()=>c.path?m.getCollection(c.path):void 0,[c.path]);if(!h)throw Error(`Couldn't find the corresponding collection for the path: ${c.path}`);const A=d.useCallback(k=>{t(k?$e(k):null)},[t]),y=At({multiselect:!1,path:c.path,collection:h,onSingleEntitySelected:A,selectedEntityIds:g?[e.id]:void 0,forceFilter:c.forceFilter}),b=d.useCallback(k=>{k.preventDefault(),y.open()},[y]);return r.jsxs(r.Fragment,{children:[r.jsx(Be,{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(Ve,{disabled:!c.path,previewProperties:c.previewProperties,hover:!n,size:"medium",onClick:n||i?void 0:b,reference:e,includeEntityLink:c.includeEntityLink,includeId:c.includeId}),!e&&r.jsx("div",{className:"justify-center text-left",children:r.jsxs(p.Button,{variant:"outlined",color:"primary",disabled:n||i,onClick:b,children:["Edit ",c.name]})})]}),r.jsx(Ee,{includeDescription:u,showError:a,error:o,disabled:n,property:c})]})}const lt=d.memo(ac,(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||Y(e.property,t.property))&&e.disabled===t.disabled)||Bo(t.property),!1});function ac({propertyKey:e,property:t,context:o,includeDescription:a,underlyingValueHasChanged:i,disabled:n,tableMode:s,partOfArray:l,partOfBlock:c,autoFocus:u}){const f=se();return r.jsx(ve.Field,{name:e,children:g=>{let m;const h=Pe({propertyKey:e,propertyOrBuilder:t,values:g.form.values,path:o.path,entityId:o.entityId,fields:f.propertyConfigs});if(h===null||$t(h))return r.jsx(r.Fragment,{});if(pt(h))m=Eo;else if(h.Field)typeof h.Field=="function"&&(m=h.Field);else{const y=Dt(h,f.propertyConfigs);if(!y)throw console.log("INTERNAL: Could not find field config for property",{propertyKey:e,resolvedProperty:h,fields:f.propertyConfigs,propertyConfig:y}),new Error(`INTERNAL: Could not find field config for property ${e}`);m=Pe({propertyOrBuilder:y.property,values:g.form.values,path:o.path,entityId:o.entityId,fields:f.propertyConfigs}).Field}if(!m)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 A={propertyKey:e,property:h,includeDescription:a,underlyingValueHasChanged:i,context:o,disabled:n,tableMode:s,partOfArray:l,partOfBlock:c,autoFocus:u};return r.jsx(nc,{Component:m,componentProps:A,fieldProps:g})}},e)}function nc({Component:e,componentProps:{propertyKey:t,property:o,includeDescription:a,underlyingValueHasChanged:i,tableMode:n,partOfArray:s,partOfBlock:l,autoFocus:c,context:u,disabled:f},fieldProps:g}){const{plugins:m}=se(),h=o.customProps,A=g.field.value,y=ve.getIn(g.form.errors,t),b=ve.getIn(g.form.touched,t),k=y&&(g.form.submitCount>0||o.validation?.unique)&&(!Array.isArray(y)||!!y.filter(S=>!!S).length),v=ic({path:u.path,collection:u.collection,propertyKey:t,property:o,Component:e,plugins:m})??e,x=g.form.isSubmitting,C=d.useCallback((S,P)=>{g.form.setFieldTouched(t,!0,!1),g.form.setFieldValue(t,S,P)},[]),E=d.useCallback((S,P,T)=>{g.form.setFieldTouched(t,!0,!1),g.form.setFieldValue(S,P,T)},[]),B={propertyKey:t,value:A,setValue:C,setFieldValue:E,error:y,touched:b,showError:k,isSubmitting:x,includeDescription:a??!0,property:o,disabled:f??!1,underlyingValueHasChanged:i??!1,tableMode:n??!1,partOfArray:s??!1,partOfBlock:l??!1,autoFocus:c??!1,customProps:h,context:u};return r.jsxs(ae,{children:[r.jsx(v,{...B}),i&&!x&&r.jsx(p.Typography,{variant:"caption",className:"ml-3.5",children:"This value has been updated elsewhere"})]})}const Bo=(e,t)=>{if(t?.some(i=>i.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(i=>Bo(i,t)):o.dataType==="array"&&"resolvedProperties"in o?a||o.resolvedProperties?.some(i=>i&&Bo(i,t)):a};function ic({path:e,collection:t,propertyKey:o,property:a,Component:i,plugins:n}){return d.useRef((()=>{let l=null;return n&&n.forEach(c=>{const u=No(a);if(u&&c.form?.fieldBuilder){const f={fieldConfigId:u,propertyKey:o,property:a,Field:i,plugin:c,path:e,collection:t},g=c.form?.fieldBuilderEnabled?.(f);(g===void 0||g)&&(l=c.form.fieldBuilder(f)||l)}u||console.warn("INTERNAL: Field id not found for property",a)}),l})()).current}function Gn({propertyKey:e,value:t,showError:o,error:a,disabled:i,property:n,partOfBlock:s,tableMode:l,includeDescription:c,underlyingValueHasChanged:u,autoFocus:f,context:g}){const m=n.pickOnlySomeKeys||!1,h=(n.expanded===void 0?!0:n.expanded)||f;if(!n.properties)throw Error(`You need to specify a 'properties' prop (or specify a custom field) in your map property ${e}`);let A;m?t?A=Xo(n.properties,...Object.keys(t).filter(k=>k in n.properties)):A={}:A=n.properties;const y=r.jsx(r.Fragment,{children:r.jsx("div",{className:"py-1 flex flex-col space-y-2",children:Object.entries(A).filter(([k,_])=>!$t(_)).map(([k,_],v)=>{const x={propertyKey:`${e}.${k}`,disabled:i,property:_,includeDescription:c,underlyingValueHasChanged:u,context:g,tableMode:!1,partOfArray:!1,partOfBlock:!1,autoFocus:f&&v===0};return r.jsx("div",{children:r.jsx(ae,{children:r.jsx(lt,{...x})})},`map-${e}-${v}`)})})}),b=r.jsx(Be,{icon:_e(n,"small"),required:n.validation?.required,title:n.name,className:"text-text-secondary dark:text-text-secondary-dark"});return r.jsxs(ae,{children:[!l&&!s&&r.jsx(p.ExpandablePanel,{initiallyExpanded:h,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:b,children:y}),(l||s)&&y,r.jsx(Ee,{includeDescription:c,showError:o??!1,error:a?typeof a=="string"?a:"A property of this map has an error":void 0,disabled:i,property:n})]})}function Yn({propertyKey:e,value:t,showError:o,error:a,disabled:i,property:n,setValue:s,tableMode:l,includeDescription:c,underlyingValueHasChanged:u,autoFocus:f,context:g}){const m=(n.expanded===void 0?!0:n.expanded)||f;if(!n.keyValue)throw Error(`Your property ${e} needs to have the 'keyValue' prop in order to use this field binding`);const h=r.jsx(So,{value:t,setValue:s,disabled:i,fieldName:n.name??e}),A=r.jsx(Be,{icon:_e(n,"small"),required:n.validation?.required,title:n.name,className:"text-text-secondary dark:text-text-secondary-dark"});return r.jsxs(r.Fragment,{children:[!l&&r.jsx(p.ExpandablePanel,{initiallyExpanded:m,title:A,className:"px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2",children:h}),l&&h,r.jsx(Ee,{includeDescription:c,showError:o,error:a,disabled:i,property:n})]})}function So({value:e,setValue:t,fieldName:o,disabled:a}){const[i,n]=d.useState(Object.keys(e??{}).map(c=>[Io(),{key:c,dataType:Fo(e?.[c])??"string"}]));d.useEffect(()=>{const c=i.map(([h,{key:A}])=>A),u=Object.entries(e??{}).filter(([h,A])=>A!==void 0).map(([h])=>h),f=u.filter(h=>!c.includes(h)),g=c.filter(h=>!u.includes(h)),m=[...i];f.forEach(h=>{m.push([Io(),{key:h,dataType:Fo(e?.[h])??"string"}])}),g.forEach(h=>{const A=m.findIndex(([y,{key:b}])=>b===h);m.splice(A,1)}),n(m)},[e]);const s=d.useRef(e??{}),l=(c,u)=>{if(!c){console.warn("No key selected for data type update");return}n(i.map(f=>f[0]===c?[f[0],{key:f[1].key,dataType:u}]:f)),t({...e??{},[i.find(f=>f[0]===c)?.[1].key??""]:Fr(u)})};return r.jsxs("div",{className:"py-1 flex flex-col gap-1",children:[i.map(([c,{key:u,dataType:f}],g)=>{const m=u?e?.[u]:"",h=A=>{if(n(i.map(b=>b[0]===c?[c,{key:A??"",dataType:b[1].dataType}]:b)),typeof e=="object"&&A in e)return;const y={...e??{}};typeof s.current=="object"&&u in s.current?y[u]=void 0:delete y[u],t({...y,[A??""]:m})};return r.jsx(sc,{rowId:c,fieldKey:u,value:e??{},onDeleteClick:()=>{const A={...e??{}};s.current&&u in s.current?A[u]=void 0:delete A[u],n(i.filter(y=>y[0]!==c)),t({...A})},onFieldKeyChange:h,setValue:t,entryValue:m,dataType:f,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}),n([...i,[Io(),{key:"",dataType:"string"}]])},children:o?`Add to ${o}`:"Add"})]})}function sc({rowId:e,fieldKey:t,value:o,onFieldKeyChange:a,onDeleteClick:i,setValue:n,entryValue:s,dataType:l,updateDataType:c,disabled:u}){const{locale:f}=se();function g(h,A,y){return y==="string"||y==="number"?r.jsx(p.TextField,{placeholder:"value",value:h,type:y==="number"?"number":"text",size:"small",disabled:u||!A,onChange:b=>{if(y==="number"){const k=b.target.value?parseFloat(b.target.value):void 0;k&&isNaN(k)?n({...o,[A]:null}):k!=null?n({...o,[A]:k}):n({...o,[A]:null})}else n({...o,[A]:b.target.value})}},y):y==="date"?r.jsx(p.DateTimeField,{value:h,size:"small",locale:f,disabled:u||!A,onChange:b=>{n({...o,[A]:b})}}):y==="boolean"?r.jsx(p.BooleanSwitchWithLabel,{value:h,size:"small",position:"start",disabled:u||!A,onValueChange:b=>{n({...o,[A]:b})}}):y==="array"?r.jsx("div",{className:p.cls(p.defaultBorderMixin,"ml-2 pl-2 border-l border-solid"),children:r.jsx(vo,{value:h,newDefaultEntry:"",droppableId:e.toString(),addLabel:A?`Add to ${A}`:"Add",size:"small",disabled:u||!A,includeAddButton:!0,onValueChange:b=>{n({...o,[A]:b})},buildEntry:(b,k)=>r.jsx(lc,{index:b,id:k,value:h[b],disabled:u||!A,setValue:_=>{const v=[...h];v[b]=_,n({...o,[A]:v})}})})}):y==="map"?r.jsx("div",{className:p.cls(p.defaultBorderMixin,"ml-2 pl-2 border-l border-solid"),children:r.jsx(So,{value:h,fieldName:A,setValue:b=>{n({...o,[A]:b})}})}):r.jsx(p.Typography,{variant:"caption",children:`Data type ${y} not supported yet`})}function m(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:()=>m("string"),children:"string"}),r.jsx(p.MenuItem,{dense:!0,onClick:()=>m("number"),children:"number"}),r.jsx(p.MenuItem,{dense:!0,onClick:()=>m("boolean"),children:"boolean"}),r.jsx(p.MenuItem,{dense:!0,onClick:()=>m("date"),children:"date"}),r.jsx(p.MenuItem,{dense:!0,onClick:()=>m("map"),children:"map"}),r.jsx(p.MenuItem,{dense:!0,onClick:()=>m("array"),children:"array"})]}),r.jsx(p.IconButton,{"aria-label":"delete",size:"small",onClick:i,className:"h-7 w-7",children:r.jsx(p.RemoveIcon,{size:"small"})})]},e.toString()),(l==="map"||l==="array")&&g(s,t,l)]})}function lc({id:e,index:t,value:o,setValue:a}){const{locale:i}=se(),[n,s]=d.useState(Fo(o)??"string");function l(u){s(u)}function c(u,f){return f==="string"||f==="number"?r.jsx(p.TextField,{value:u,type:f==="number"?"number":"text",size:"small",onChange:g=>{if(f==="number"){const m=g.target.value?parseFloat(g.target.value):void 0;m&&isNaN(m)?a(null):m!=null?a(m):a(null)}else a(g.target.value)}}):f==="date"?r.jsx(p.DateTimeField,{value:u,size:"small",locale:i,onChange:g=>{a(g)}}):f==="boolean"?r.jsx(p.BooleanSwitchWithLabel,{value:u,size:"small",position:"start",onValueChange:g=>{a(g)}}):f==="array"?r.jsx(p.Typography,{variant:"caption",children:"Arrays of arrays are not supported."}):f==="map"?r.jsx("div",{className:p.cls(p.defaultBorderMixin,"ml-2 pl-2 border-l border-solid"),children:r.jsx(So,{value:u,setValue:g=>{a(g)}})}):r.jsx(p.Typography,{variant:"caption",children:`Data type ${f} 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:n!=="map"&&c(o,n)}),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()),n==="map"&&c(o,n)]})}function Io(){return Math.floor(Math.random()*Math.floor(Number.MAX_SAFE_INTEGER))}function Fo(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 xr)return"geopoint";if(typeof e=="object")return"map"}function Ln({propertyKey:e,value:t,error:o,showError:a,isSubmitting:i,setValue:n,setFieldValue:s,tableMode:l,property:c,includeDescription:u,underlyingValueHasChanged:f,context:g,disabled:m}){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,A=c.of,[y,b]=d.useState();Qe({property:c,value:t,setValue:n});const k=(x,C)=>{const E=c.resolvedProperties[x]??A,B={propertyKey:`${e}.${x}`,disabled:m,property:E,includeDescription:u,underlyingValueHasChanged:f,context:g,tableMode:!1,partOfArray:!0,partOfBlock:!1,autoFocus:C===y};return r.jsx(ae,{children:r.jsx(lt,{...B})})},_=r.jsx(ur,{value:t,addLabel:c.name?"Add entry to "+c.name:"Add entry",name:e,setFieldValue:s,buildEntry:k,onInternalIdAdded:b,disabled:i||!!c.disabled,includeAddButton:!c.disabled,newDefaultEntry:c.of.defaultValue}),v=r.jsx(Be,{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:v,children:_}),l&&_,r.jsx(Ee,{includeDescription:u,showError:a,error:o,disabled:m,property:c})]})}function jn({propertyKey:e,value:t,error:o,showError:a,isSubmitting:i,setValue:n,setFieldValue:s,tableMode:l,property:c,includeDescription:u,underlyingValueHasChanged:f,context:g,disabled:m}){if(!c.oneOf)throw Error("ArrayOneOfField misconfiguration. Property `oneOf` not set");const h=c.expanded===void 0?!0:c.expanded;Qe({property:c,value:t,setValue:n});const[A,y]=d.useState(),b=d.useCallback((x,C)=>r.jsx(cc,{name:`${e}.${x}`,index:x,value:t[x],typeField:c.oneOf.typeField??Ct,valueField:c.oneOf.valueField??Ut,properties:c.oneOf.properties,autoFocus:C===A,context:g},`array_one_of_${x}`),[g,A,c.oneOf,e,t]),k=r.jsx(Be,{icon:_e(c,"small"),required:c.validation?.required,title:c.name,className:"text-text-secondary dark:text-text-secondary-dark"}),_=Object.keys(c.oneOf.properties)[0],v=r.jsx(ur,{value:t,name:e,addLabel:c.name?"Add entry to "+c.name:"Add entry",buildEntry:b,onInternalIdAdded:y,disabled:i||!!c.disabled,includeAddButton:!c.disabled,setFieldValue:s,newDefaultEntry:{[c.oneOf.typeField??Ct]:_,[c.oneOf.valueField??Ut]:Wt(c.oneOf.properties[_])}});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:v}),l&&v,r.jsx(Ee,{includeDescription:u,showError:a,error:o,disabled:m,property:c})]})}function cc({name:e,index:t,value:o,typeField:a,valueField:i,properties:n,autoFocus:s,context:l}){const c=o&&o[a],[u,f]=d.useState(c??void 0),g=ve.useFormex();d.useEffect(()=>{c||k(Object.keys(n)[0])},[]),d.useEffect(()=>{c!==u&&f(c)},[c]);const m=u?n[u]:void 0,h=Object.entries(n).map(([_,v])=>({id:_,label:v.name??_})),A=`${e}.${a}`,y=`${e}.${i}`,b=m?{propertyKey:y,property:m,context:l,autoFocus:s,partOfArray:!1,partOfBlock:!0,tableMode:!1}:void 0,k=_=>{const v=_?n[_]:void 0;f(_),g.setFieldTouched(A,!0),g.setFieldValue(A,_),g.setFieldValue(y,v?Wt(v):null)};return r.jsxs("div",{className:p.cls(p.paperMixin,"bg-transparent p-4 my-4 py-8"),children:[r.jsx(ve.Field,{name:A,children:_=>{const v=_.field.value!==void 0&&_.field.value!==null?_.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:v,renderValue:x=>r.jsx(Ie,{enumKey:x,enumValues:h,size:"small"}),onValueChange:x=>{k(x)},children:h.map(x=>r.jsx(p.SelectItem,{value:String(x.id),children:r.jsx(Ie,{enumKey:x.id,enumValues:h,size:"small"})},x.id))})})}}),b&&r.jsx(lt,{...b},`form_control_${e}_${u}`)]})}const dc=new mi;try{tt.use(tt.Plugins.AutoResize,{min:100}),tt.unuse(tt.Plugins.FontUnderline),tt.unuse(tt.Plugins.Clear)}catch{}function Un({propertyKey:e,value:t,setValue:o,error:a,showError:i,disabled:n,autoFocus:s,touched:l,property:c,tableMode:u,includeDescription:f,context:g}){const[m,h]=d.useState(t),A=d.useRef(t);p.useInjectStyles("MarkdownFieldBinding",pc);const y=d.useDeferredValue({internalValue:m,value:t});return d.useEffect(()=>{A.current=t,h(t)},[t]),d.useEffect(()=>{y.internalValue!==A.current&&o(y.internalValue)},[y]),r.jsxs(r.Fragment,{children:[!u&&r.jsx(p.Typography,{variant:"caption",className:"flex-grow",children:r.jsx(Be,{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(tt,{value:m??"",className:p.cls(p.fieldBackgroundMixin,n?p.fieldBackgroundDisabledMixin:p.fieldBackgroundHoverMixin,"text-base"),readOnly:n,renderHTML:b=>dc.render(b),view:{menu:!0,md:!0,html:!1},onChange:({html:b,text:k})=>{h(k??null)}}),r.jsx(Ee,{includeDescription:f,showError:i,error:a,disabled:n,property:c})]})}const pc=`
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 $n({propertyKey:e,value:t,error:o,showError:a,isSubmitting:i,setValue:n,tableMode:s,property:l,includeDescription:c,underlyingValueHasChanged:u,context:f,disabled:g}){if(!Array.isArray(l.resolvedProperties))throw Error("ArrayCustomShapedFieldBinding misconfiguration. Property `of` not set");const m=l.expanded===void 0?!0:l.expanded;Qe({property:l,value:t,setValue:n});const h=r.jsx(Be,{icon:_e(l,"small"),required:l.validation?.required,className:"text-text-secondary dark:text-text-secondary-dark",title:l.name}),A=l.resolvedProperties.map((y,b)=>{const k={propertyKey:`${e}[${b}]`,disabled:g,property:y,includeDescription:c,underlyingValueHasChanged:u,context:f,tableMode:!1,partOfArray:!0,partOfBlock:!1,autoFocus:!1};return r.jsx("div",{className:"pb-4",children:r.jsx(lt,{...k})},`custom_shaped_array_${b}`)});return r.jsxs(r.Fragment,{children:[!s&&r.jsx(p.ExpandablePanel,{initiallyExpanded:m,title:h,className:"px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2",children:A}),s&&A,r.jsx(Ee,{includeDescription:c,showError:a,error:o,disabled:g,property:l})]})}function Wn(e){return Object.keys(fr).includes(e)}const fr={text_field:{key:"text_field",name:"Text field",description:"Simple short text",Icon:p.ShortTextIcon,color:"#2d7ff9",property:{dataType:"string",Field:vt}},multiline:{key:"multiline",name:"Multiline",description:"Text with multiple lines",Icon:p.SubjectIcon,color:"#2d7ff9",property:{dataType:"string",multiline:!0,Field:vt}},markdown:{key:"markdown",name:"Markdown",description:"Text with advanced markdown syntax",Icon:p.FormatQuoteIcon,color:"#2d7ff9",property:{dataType:"string",markdown:!0,Field:Un}},url:{key:"url",name:"Url",description:"Text with URL validation",Icon:p.HttpIcon,color:"#154fb3",property:{dataType:"string",url:!0,Field:vt}},email:{key:"email",name:"Email",description:"Text with email validation",Icon:p.EmailIcon,color:"#154fb3",property:{dataType:"string",email:!0,Field:vt}},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:On}},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:_o}},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:Co}},number_input:{key:"number_input",name:"Number input",description:"Simple number field with validation",Icon:p.NumbersIcon,color:"#bec920",property:{dataType:"number",Field:vt}},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:_o}},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:Co}},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:xo}},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:xo}},reference:{key:"reference",name:"Reference",description:"The value refers to a different collection",Icon:p.LinkIcon,color:"#ff0042",property:{dataType:"reference",Field:Vn}},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:Qn}},date_time:{key:"date_time",name:"Date/time",description:"A date time select field",Icon:p.ScheduleIcon,color:"#8b46ff",property:{dataType:"date",Field:zn}},group:{key:"group",name:"Group",description:"Group of multiple fields",Icon:p.BallotIcon,color:"#ff9408",property:{dataType:"map",properties:{},Field:Gn}},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:Yn}},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:Ln}},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:$n}},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:jn}}};function qn(e){const t=mr(e);if(!t){console.error("No field id found for property",e);return}return fr[t]}function Dt(e,t){const o=No(e),a=mr(e);if(!a){console.error("No field id found for property",e);return}const i=fr[a],n=o?t[o]:void 0;return Me(i??{},n??{})}function mr(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 No(e){return e.propertyConfig?e.propertyConfig:mr(e)}const Ne=({collection:e,path:t,entityId:o,values:a,previousValues:i,userConfigPersistence:n,fields:s,ignoreMissingFields:l=!1})=>{const c=n?.getCollectionConfig(t),u=Ue(c,"properties"),f=xt(e.properties),g=a??f,m=i??a??f,h=Object.entries(e.properties).map(([b,k])=>{const _=Pe({propertyKey:b,propertyOrBuilder:k,values:g,previousValues:m,path:t,entityId:o,fields:s,ignoreMissingFields:l});return _?{[b]:_}:{}}).filter(b=>b!==null).reduce((b,k)=>({...b,...k}),{}),A=Me(h,u),y=Object.entries(A).filter(([b,k])=>!!k?.dataType).map(([b,k])=>({[b]:k})).reduce((b,k)=>({...b,...k}),{});return{...e,properties:y,originalCollection:e}};function Pe({propertyOrBuilder:e,fromBuilder:t=!1,ignoreMissingFields:o=!1,...a}){if(typeof e=="object"&&"resolved"in e)return e;let i=null;if(e)if(ke(e)){const n=a.path;if(!n)throw Error("Trying to resolve a property builder without specifying the entity path");const s=a.propertyKey?ve.getIn(a.values,a.propertyKey):void 0,l=e({...a,path:n,propertyValue:s,values:a.values??{},previousValues:a.previousValues??a.values??{}});if(!l)return null;i=Pe({...a,propertyOrBuilder:l,fromBuilder:!0,ignoreMissingFields:o})}else{const n=e;if(n.dataType==="map"&&n.properties){const s=Po({ignoreMissingFields:o,...a,properties:n.properties});i={...n,resolved:!0,fromBuilder:t,properties:s}}else n.dataType==="array"?i=Ke({property:n,fromBuilder:t,ignoreMissingFields:o,...a}):(n.dataType==="string"||n.dataType==="number")&&n.enumValues&&(i=To(n,t))}else return null;if(i||(i={...e,resolved:!0,fromBuilder:t}),i.propertyConfig&&!Wn(i.propertyConfig)){const n=a.fields;if(!n&&!o)throw Error(`Trying to resolve a property with key '${i.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 s=n?.[i.propertyConfig];if(!s)return console.warn(`Trying to resolve a property with key '${i.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(s.property){const l=s.property;"propertyConfig"in l&&delete l.propertyConfig;const c=Pe({propertyOrBuilder:l,ignoreMissingFields:o,...a});c&&(i=Me(c,i))}}return i?{...i,resolved:!0}:null}function Ke({propertyKey:e,property:t,ignoreMissingFields:o=!1,...a}){const i=e?ve.getIn(a.values,e):void 0;if(t.of){if(Array.isArray(t.of))return{...t,resolved:!0,fromBuilder:a.fromBuilder,resolvedProperties:t.of.map((n,s)=>Pe({propertyKey:`${e}.${s}`,propertyOrBuilder:n,ignoreMissingFields:o,...a,index:s}))};{const n=t.of,s=Array.isArray(i)?i.map((c,u)=>Pe({propertyKey:`${e}.${u}`,propertyOrBuilder:n,ignoreMissingFields:o,...a,index:u})).filter(c=>!!c):[],l=Pe({propertyKey:`${e}`,propertyOrBuilder:n,ignoreMissingFields:o,...a});if(!l&&!o)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:a.fromBuilder,of:l,resolvedProperties:s}}}else if(t.oneOf){const n=t.oneOf?.typeField??Ct,s=Array.isArray(i)?i.map((c,u)=>{const f=c&&c[n],g=t.oneOf?.properties[f];return!f||!g?null:Pe({propertyKey:`${e}.${u}`,propertyOrBuilder:g,ignoreMissingFields:o,...a})}).filter(c=>!!c):[],l=Po({properties:t.oneOf.properties,ignoreMissingFields:o,...a});return{...t,resolved:!0,oneOf:{...t.oneOf,properties:l},fromBuilder:a.fromBuilder,resolvedProperties:s}}else{if(t.Field)return{...t,resolved:!0,fromBuilder:a.fromBuilder};throw Error("The array property needs to declare an 'of' or a 'oneOf' property, or provide a custom `Field`")}}function Po({properties:e,ignoreMissingFields:t,...o}){return Object.entries(e).map(([a,i])=>{const n=Pe({propertyKey:a,propertyOrBuilder:i,ignoreMissingFields:t,...o});return n?{[a]:n}:{}}).filter(a=>a!==null).reduce((a,i)=>({...a,...i}),{})}function To(e,t){return typeof e.enumValues=="object"?{...e,resolved:!0,enumValues:Je(e.enumValues)?.filter(o=>o&&(o.id||o.id===0)&&o.label)??[],fromBuilder:t??!1}:e}function uc(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 Do(e,t){return typeof e=="string"?t?.find(o=>o.key===e):e}function Qo(e){const{path:t,collections:o=[],currentFullPath:a}=e,i=me(t).split("/"),n=Lt(i),s=[];for(let l=0;l<n.length;l++){const c=n[l],u=o&&o.find(f=>f.id===c||f.path===c);if(u){const f=u.id??u.path,g=a&&a.length>0?a+"/"+f:f;s.push({type:"collection",path:g,collection:u});const m=me(me(t).replace(c,"")),h=m.length>0?m.split("/"):[];if(h.length>0){const A=h[0],y=g+"/"+A;if(s.push({type:"entity",entityId:A,path:g,parentCollection:u}),h.length>1){const b=h.slice(1).join("/");if(!u)throw Error("collection not found resolving path: "+u);const k=u.entityViews,_=k&&k.map(v=>Do(v,e.contextEntityViews)).filter(Boolean).find(v=>v.key===b);if(_){const v=a&&a.length>0?a+"/"+_.key:_.key;s.push({type:"custom_view",path:v,view:_})}else u.subcollections&&s.push(...Qo({path:b,collections:u.subcollections,currentFullPath:y,contextEntityViews:e.contextEntityViews}))}}break}}return s}const fc="100vw",mc="55vw",hr="768px";function hc({customId:e,entityId:t,status:o,onChange:a,error:i,entity:n,loading:s}){const{errors:l}=ve.useFormex(),c=o==="existing"||!e,u=o!=="existing"&&!e,f=d.useMemo(()=>{if(!(!e||typeof e=="boolean"||e==="optional"))return Je(e)},[e]),g=Ze(),{copy:m}=Ta({onSuccess:y=>g.open({type:"success",message:`Copied ${y}`})}),h=se(),A={label:u?"ID is set automatically":"ID",disabled:c||s,name:"id",value:(n&&o==="existing"?n.id:t)??"",endAdornment:s?r.jsx(p.CircularProgress,{size:"small"}):n?r.jsxs(r.Fragment,{children:[r.jsx(p.Tooltip,{title:"Copy",children:r.jsx(p.IconButton,{onClick:y=>m(n.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:n}),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:[f&&r.jsx(p.Select,{error:i,onValueChange:y=>a(y),...A,renderValue:y=>{const b=f.find(k=>k.id===y);return b?`${b.id} - ${b.label}`:y},children:f.map(y=>r.jsx(p.SelectItem,{value:String(y.id),children:r.jsx(Ie,{enumKey:y.id,enumValues:f,size:"medium"})},y.id))}),!f&&r.jsx(p.TextField,{...A,error:i,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 b=y.target.value;return b&&(b=b.trim()),a(b.length?b:void 0)}}),l.id&&r.jsx(p.Typography,{variant:"caption",className:"ml-3.5 text-red-500 dark:text-red-500",children:l.id})]})}const gc=({containerRef:e})=>{const{isSubmitting:t,isValidating:o,errors:a}=ve.useFormex();return d.useEffect(()=>{const i=Object.keys(a);if(i.length>0&&t&&!o){const n=e?.current?.querySelector(`#form_field_${i[0]}`);if(n&&e?.current){const s=Hn(e.current);if(s){const c=n.getBoundingClientRect().top;s.scrollTo({top:s.scrollTop+c-196,behavior:"smooth"})}const l=n.querySelector("input");l&&l.focus()}}},[t,o,a,e]),null},Ac=e=>{const t=e&&e.scrollHeight>e.clientHeight,o=e?window.getComputedStyle(e).overflowY:null,a=o&&o.indexOf("hidden")!==-1;return t&&!a},Hn=e=>!e||e===document.body?document.body:Ac(e)?e:Hn(e.parentNode);function bc({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.ContentCopyIcon,{size:"smallest",className:"text-white",onClick:d.useCallback(()=>{navigator.clipboard.writeText(e),o(!0),setTimeout(()=>o(!1),2e3)},[e])})})]})}const Qt="main_##Q$SC^#S6";function yc({entityId:e,...t}){const{entity:o,dataLoading:a,dataLoadingError:i}=jr({path:t.path,entityId:e,collection:t.collection,useCache:!1});return a?r.jsx(Nt,{}):r.jsx(wc,{...t,entityId:e,entity:o,dataLoading:a})}function wc({path:e,entityId:t,selectedSubPath:o,copy:a,collection:i,parentCollectionIds:n,onValuesAreModified:s,onUpdate:l,onClose:c,entity:u,dataLoading:f}){i.customId&&i.formAutoSave&&console.warn(`The collection ${i.path} has customId and formAutoSave enabled. This is not supported and formAutoSave will be ignored`);const[g,m]=d.useState(!1),[h,A]=d.useState(void 0);Zt(h,()=>{h&&Ge({entityId:ie?.id,collection:i,path:e,values:h,closeAfterSave:!1})},!1,2e3);const y=i,b=ot(),k=ze(i),_=gr(),v=at(),x=Ze(),C=se(),E=Ce(),B=d.useRef(!1),S=gt(),P=d.useMemo(()=>Ne({collection:y,path:e,values:u?.values,fields:C.propertyConfigs}),[u?.values,e,C.propertyConfigs]),T=a?"copy":t?"existing":"new",[N,M]=d.useState(T),L=(N==="new"||N==="copy")&&!!P.customId&&P.customId!=="optional",ee=d.useMemo(()=>N==="new"||N==="copy"?L?void 0:k.generateEntityId(e):t,[t,N]),[G,q]=d.useState(ee),[j,O]=d.useState(!1),[te,Z]=d.useState(),[le,ne]=d.useState(!1),re=o??Tr(i?i.defaultSelectedView:void 0,{status:N,entityId:G}),J=d.useRef(re??Qt),Q=d.useRef(vc(P,N,u)),R=J.current===Qt,H=(i.subcollections??[]).filter(F=>!F.hideFromNavigation),$=H?.length??0,V=i.entityViews,z=V?.length??0,I=i.formAutoSave&&!i.customId,D=z>0||$>0,[ie,xe]=d.useState(u),[Le,K]=d.useState(void 0);d.useEffect(()=>{u&&xe(u)},[u]),d.useEffect(()=>{if(N==="new")K(!1);else{const F=ie?Or(i,b,e,ie??null):!1;ie&&K(!F)}},[b,ie,N]);const he=d.useCallback(F=>{m(!1),x.open({type:"error",message:"Error before saving: "+F?.message}),console.error(F)},[x]),Te=d.useCallback(F=>{m(!1),x.open({type:"error",message:"Error after saving (entity is saved): "+F?.message}),console.error(F)},[x]),Fe=(F,W)=>{m(!1),I||x.open({type:"success",message:`${i.singularName??i.name}: Saved correctly`}),xe(F),M("existing"),s(!1),l&&l({entity:F}),W?(console.log("Closing side dialog"),_.setBlocked(!1),_.close(!0),c?.()):N!=="existing"&&v.replace({path:e,entityId:F.id,selectedSubPath:J.current,updateUrl:!0,collection:i})},Ae=d.useCallback(F=>{m(!1),x.open({type:"error",message:"Error saving: "+F?.message}),console.error("Error saving entity",e,G),console.error(F)},[G,e,x]),Ge=({values:F,previousValues:W,closeAfterSave:fe,entityId:De,collection:He,path:Gt})=>(m(!0),Ur({path:Gt,entityId:De,values:F,previousValues:W,collection:He,status:N,dataSource:k,context:E,onSaveSuccess:jo=>Fe(jo,fe),onSaveFailure:Ae,onPreSaveHookError:he,onSaveSuccessHookError:Te}).then()),je=async({collection:F,path:W,entityId:fe,values:De,previousValues:He,closeAfterSave:Gt,autoSave:jo})=>{if(N)if(jo)A(De);else return Ge({collection:F,path:W,entityId:fe,values:De,previousValues:He,closeAfterSave:Gt})},qe=(F,W)=>{if(L&&!G){console.error("Missing custom Id"),O(!0),W.setSubmitting(!1);return}if(Z(void 0),O(!1),N==="existing"){if(!u?.id)throw Error("Form misconfiguration when saving, no id for existing entity")}else if(N==="new"||N==="copy"){if(y.customId&&y.customId!=="optional"&&!G)throw Error("Form misconfiguration when saving, entityId should be set")}else throw Error("New FormType added, check EntityForm");return Mt(F)?.then(fe=>{W.resetForm({values:F,submitCount:0,touched:{}})}).finally(()=>{W.setSubmitting(!1)})},X=ve.useCreateFormex({initialValues:Q.current,onSubmit:qe,validation:F=>Uc?.validate(F,{abortEarly:!1}).then(()=>({})).catch(W=>{const fe={};return W.inner.forEach(De=>{fe[De.path]=De.message}),kc(W)})}),be=Ne({collection:y,path:e,entityId:G,values:X.values,previousValues:X.initialValues,fields:C.propertyConfigs}),wr=d.useRef(u?.values),Mt=F=>(wr.current=F,je({collection:be,path:e,entityId:G,values:F,previousValues:u?.values,closeAfterSave:B.current,autoSave:I??!1}).then(W=>{const fe=N==="new"?"new_entity_saved":N==="copy"?"entity_copied":N==="existing"?"entity_edited":"unmapped_event";S.onAnalyticsEvent?.(fe,{path:e})}).catch(W=>{console.error(W),Z(W)}).finally(()=>{B.current=!1})),Re={setFieldValue:d.useCallback(X.setFieldValue,[]),values:X.values,collection:be,entityId:G,path:e,save:Mt,formex:X},Ot=V?V.map(F=>Do(F,C.entityViews)).filter(Boolean):[],Oo=Ot.find(F=>F.key===J.current),zo=!I&&(J.current===Qt||Oo?.includeActions),Vo=V&&Ot.map((F,W)=>{if(!F||J.current!==F.key)return null;const fe=F.Builder;return fe?r.jsx("div",{className:p.cls(p.defaultBorderMixin,"relative flex-grow w-full h-full overflow-auto "),role:"tabpanel",children:r.jsx(ae,{children:Re&&r.jsx(fe,{collection:i,entity:ie,modifiedValues:X.values??ie?.values,formContext:Re})})},`custom_view_${F.key}`):(console.error("customView.Builder is not defined"),null)}).filter(Boolean),kt=f&&!ie||(!ie||Le===void 0)&&(N==="existing"||N==="copy"),Go=kt||g,U=H&&H.map((F,W)=>{const fe=F.id??F.path,De=ie?`${e}/${ie?.id}/${me(fe)}`:void 0;return J.current!==fe?null:r.jsxs("div",{className:"relative flex-grow h-full overflow-auto w-full",role:"tabpanel",children:[Go&&r.jsx(Nt,{}),!kt&&(ie&&De?r.jsx(bo,{fullPath:De,parentCollectionIds:[...n,i.id],isSubCollection:!0,...F}):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_${fe}`)}).filter(Boolean),oe=d.useCallback(()=>{s(!1)},[]),ce=F=>{J.current=F,v.replace({path:e,entityId:G,selectedSubPath:F===Qt?void 0:F,updateUrl:!0,collection:i})},de=d.useCallback(F=>{x.open({type:"error",message:"Error updating id, check the console"})},[]),ue=d.useCallback(F=>{xe(W=>W?{...W,id:F}:void 0)},[]),Ye=[],et=C.plugins;if(et&&y){const F={entityId:G,path:e,status:N,collection:y,context:E,currentEntityId:G,formContext:Re};Ye.push(...et.map((W,fe)=>W.form?.Actions?r.jsx(W.form.Actions,{...F},`actions_${W.key}`):null).filter(Boolean))}const zt=zr(be,C.propertyConfigs),jc=X.values&&zt?Ue(X.values,zt):void 0,oi=y.callbacks?.onIdUpdate,ai=d.useCallback(async()=>{if(oi&&X.values&&(N==="new"||N==="copy")){ne(!0);try{const F=await oi({collection:be,path:e,entityId:G,values:X.values,context:E});q(F)}catch(F){de&&de(F),console.error(F)}ne(!1)}},[G,X.values,N]);d.useEffect(()=>{ai()},[ai]);const[Vt,Kc]=d.useState({}),ni=d.useCallback(({name:F,value:W,property:fe})=>k.checkUniqueField(e,F,W,G),[k,e,G]),Uc=d.useMemo(()=>G?cn(G,be.properties,ni):void 0,[G,be.properties,ni]),$c=d.useCallback(({entity:F,customEntityActions:W})=>{const fe=ft(y,b,e,null),De=F?Rt(y,b,e,F):!0,He=[];return fe&&He.push(mo),De&&He.push(ho),W&&He.push(...W),He},[b,y,e]),Yo=X.dirty;d.useEffect(()=>{I?X.values&&!Y(X.values,wr.current)&&Mt(X.values):s(Yo)},[Yo,X.values]),d.useEffect(()=>{!I&&!X.isSubmitting&&Vt&&u&&Object.entries(Vt).forEach(([F,W])=>{const fe=X.values[F];!Y(W,fe)&&!X.touched[F]&&(console.debug("Updated value from the datasource:",F,W),X.setFieldValue(F,W!==void 0?W:null))})},[X.isSubmitting,I,Vt,u,X.values,X.touched,X.setFieldValue]);const Wc=r.jsx(r.Fragment,{children:(be.propertiesOrder??Object.keys(be.properties)).map(F=>{const W=be.properties[F];if(!W)return console.warn(`Property ${F} not found in collection ${be.name}`),null;const fe=!!Vt&&Object.keys(Vt).includes(F)&&!!X.touched[F],De=!I&&X.isSubmitting||pt(W)||!!W.disabled;if($t(W))return null;const Gt={propertyKey:F,disabled:De,property:W,includeDescription:W.description||W.longDescription,underlyingValueHasChanged:fe&&!I,context:Re,tableMode:!1,partOfArray:!1,partOfBlock:!1,autoFocus:!1};return r.jsx("div",{id:`form_field_${F}`,children:r.jsx(ae,{children:r.jsx(p.Tooltip,{title:r.jsx(bc,{propertyId:F}),delayDuration:800,side:"left",align:"start",sideOffset:16,children:r.jsx(lt,{...Gt})})})},`field_${be.name}_${F}`)}).filter(Boolean)}),Lo=X.isSubmitting||!Yo&&N==="existing",ii=d.useRef(null),si=$c({entity:u,customEntityActions:y.entityActions}).filter(F=>F.includeInForm===void 0||F.includeInForm),qc=r.jsxs(p.DialogActions,{position:"absolute",children:[te&&r.jsx("div",{className:"text-right",children:r.jsx(p.Typography,{color:"error",children:te.message})}),u&&si.length>0&&r.jsx("div",{className:"flex-grow flex overflow-auto no-scrollbar",children:si.map(F=>r.jsx(p.IconButton,{color:"primary",onClick:W=>{W.stopPropagation(),u&&F.onClick({entity:u,fullPath:be.path,collection:be,context:E,sideEntityController:v})},children:F.icon},F.name))}),X.isSubmitting&&r.jsx(p.CircularProgress,{size:"small"}),r.jsx(p.Button,{variant:"text",disabled:Lo||X.isSubmitting,type:"reset",children:N==="existing"?"Discard":"Clear"}),r.jsxs(p.Button,{variant:"text",color:"primary",type:"submit",disabled:Lo||X.isSubmitting,onClick:()=>{B.current=!1},children:[N==="existing"&&"Save",N==="copy"&&"Create copy",N==="new"&&"Create"]}),r.jsxs(p.Button,{variant:"filled",color:"primary",type:"submit",disabled:Lo||X.isSubmitting,onClick:()=>{B.current=!0},children:[N==="existing"&&"Save and close",N==="copy"&&"Create copy and close",N==="new"&&"Create and close"]})]});function Hc(){let F=r.jsxs("div",{className:"h-full overflow-auto",children:[Ye.length>0&&r.jsx("div",{className:p.cls("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:Ye}),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+(Ye?8:0)} lg:mt-${8+(Ye?8:0)} mb-8`,children:[r.jsx(p.Typography,{className:"mt-4 flex-grow line-clamp-1 "+y.hideIdFromForm?"mb-2":"mb-0",variant:"h4",children:jc??y.singularName??y.name}),r.jsx(p.Alert,{color:"base",className:"w-full",size:"small",children:r.jsxs("code",{className:"text-xs select-all",children:[e,"/",G]})})]}),!i.hideIdFromForm&&r.jsx(hc,{customId:y.customId,entityId:G,status:N,onChange:q,error:j,loading:le,entity:u}),G&&Re&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"mt-12 flex flex-col gap-8",ref:ii,children:[Wc,r.jsx(gc,{containerRef:ii})]}),r.jsx("div",{className:"h-14"})]})]})]});return et&&et.forEach(W=>{W.form?.provider&&(F=r.jsx(W.form.provider.Component,{status:N,path:e,collection:i,onDiscard:oe,entity:ie,context:E,formContext:Re,...W.form.provider.props,children:F}))}),r.jsx(ae,{children:F})}const Jc=Le===void 0?r.jsx(r.Fragment,{}):Le?r.jsxs(r.Fragment,{children:[r.jsx(p.Typography,{className:"mt-16 mb-8 mx-8",variant:"h4",children:i.singularName??i.name}),r.jsx(Rr,{className:"px-12",entity:ie,path:e,collection:i})]}):Hc(),Zc=H&&H.map(F=>r.jsx(p.Tab,{className:"text-sm min-w-[140px]",value:F.id,children:F.name},`entity_detail_collection_tab_${F.name}`)),Xc=Ot.map(F=>r.jsx(p.Tab,{className:"text-sm min-w-[140px]",value:F.key,children:F.name},`entity_detail_collection_tab_${F.name}`));return d.useEffect(()=>{G&&ue&&ue(G)},[G,ue]),r.jsx(ve.Formex,{value:X,children:r.jsxs("div",{className:"flex flex-col h-full w-full transition-width duration-250 ease-in-out",children:[r.jsxs("div",{className:p.cls(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:()=>(c?.(),_.close(!1)),size:"large",children:r.jsx(p.CloseIcon,{})})}),r.jsx("div",{className:"flex-grow"}),kt&&r.jsx("div",{className:"self-center",children:r.jsx(p.CircularProgress,{size:"small"})}),r.jsxs(p.Tabs,{value:J.current,onValueChange:F=>{ce(F)},className:"pl-4 pr-4 pt-0",children:[r.jsx(p.Tab,{disabled:!D,value:Qt,className:`${D?"":"hidden"} text-sm min-w-[140px]`,children:i.singularName??i.name}),Xc,Zc]})]}),r.jsxs("form",{onSubmit:X.handleSubmit,onReset:()=>(X.resetForm(),oe&&oe()),noValidate:!0,className:"flex-grow h-full flex overflow-auto flex-col w-full",children:[r.jsx("div",{role:"tabpanel",hidden:!R,id:`form_${e}`,className:" w-full",children:kt?r.jsx(Nt,{}):Jc}),Vo,U,zo&&qc]})]})})}function vc(e,t,o){const a=e.properties;if((t==="existing"||t==="copy")&&o)return o.values??xt(a);if(t==="new")return xt(a);throw console.error({status:t,entity:o}),new Error("Form has not been initialised with the correct parameters")}function kc(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 _c(e,t){const[o,a]=d.useState(),{navigator:i}=d.useContext(ge.UNSAFE_NavigationContext),n=ge.useNavigate(),s=()=>{a(void 0)},l=()=>{t(),a(void 0),n(-1)},c=d.useCallback(({action:u,location:f,retry:g})=>{switch(u){case"REPLACE":{g();return}case"POP":a(f)}},[]);return d.useEffect(()=>{if(!e||o||!("block"in i))return;const u=i.block(f=>{const g={...f,retry(){u(),f.retry()}};c(g)});return u},[i,c,e,o]),{navigationWasBlocked:!!o,handleCancel:s,handleOk:l}}function Cc({open:e,handleOk:t,handleCancel:o,body:a,title:i}){return r.jsxs(p.Dialog,{open:e,onOpenChange:n=>n?o():t(),children:[r.jsxs(p.DialogContent,{children:[r.jsx(p.Typography,{variant:"h6",children:i}),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 Jn=d.createContext({width:"",blocked:!1,setBlocked:e=>{},setBlockedNavigationMessage:e=>{},close:()=>{}}),gr=()=>d.useContext(Jn);function xc(){const t=Bt().sidePanels,o=[...t];return o.push(void 0),r.jsx(r.Fragment,{children:o.map((a,i)=>r.jsx(Ec,{panel:a,offsetPosition:t.length-i-1},`side_dialog_${i}`))})}function Ec({offsetPosition:e,panel:t}){const[o,a]=d.useState(!1),[i,n]=d.useState(!1),[s,l]=d.useState(),c=d.useRef(t?.width),u=c.current,f=Bt(),{navigationWasBlocked:g,handleOk:m,handleCancel:h}=_c(i&&!o,()=>n(!1));d.useEffect(()=>{t&&(c.current=t.width)},[t]);const A=()=>{n(!1),a(!1),f.close(),t?.onClose?.()},y=()=>{a(!1)},b=k=>{i&&!k?a(!0):(f.close(),t?.onClose?.())};return r.jsxs(Jn.Provider,{value:{blocked:i,setBlocked:n,setBlockedNavigationMessage:l,width:u,close:b},children:[r.jsxs(p.Sheet,{open:!!t,onOpenChange:k=>!k&&b(),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(Cc,{open:g||o,handleOk:o?A:m,handleCancel:o?y:h,body:s})]})}function Bc(e){const{blocked:t,setBlocked:o,setBlockedNavigationMessage:a}=gr(),i=pe(),n=d.useMemo(()=>i.getParentCollectionIds(e.path),[i,e.path]),s=d.useMemo(()=>{if(!e)return;let c=e.collection;const u=i.getCollection(e.path);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},[i,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(yc,{...e,collection:s,parentCollectionIds:n,onValuesAreModified:l})})})}const Zn="new";function Sc(e,t){if(t)return fc;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?Ic(e.collection):hr):`calc(${mc} + ${a??hr})`}const Mo={};function Ic(e){if(Mo[e.id])return Mo[e.id];const t=Ne({collection:e,path:"__ignored",ignoreMissingFields:!0});let o=hr;if(t?.properties){const a=Object.values(t.properties).map(n=>Ar(n)),i=Math.max(...a);i<3?o=hr:o=768+32*(i-2)+"px"}return Mo[e.id]=o,o}function Ar(e,t=0){if(e.dataType==="map"&&e.properties){const o=Object.values(e.properties).flatMap(a=>Ar(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=>Ar(o,t+1))):Ar(e.of,t+1):t+1}const Fc=(e,t)=>{const o=ge.useLocation(),a=d.useRef(!1),i=!Oe();d.useEffect(()=>{if(!e.loading&&!a.current){if(console.debug("Initialising side entity controller"),e.isUrlCollectionPath(o.pathname)){const c=o.hash===`#${Zn}`,u=e.urlPathToDataPath(o.pathname),f=Nc(u,e.collections??[],c);for(let g=0;g<f.length;g++){const m=f[g];setTimeout(()=>{g===0?t.replace(br(m,e.buildUrlCollectionPath,e.resolveAliasesFrom,i)):t.open(br(m,e.buildUrlCollectionPath,e.resolveAliasesFrom,i))},1)}}a.current=!0}},[o,e.loading,e.isUrlCollectionPath,e.buildUrlCollectionPath,e.resolveAliasesFrom,t,i,e]);const n=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=Tr(c.collection?c.collection.defaultSelectedView:void 0,{status:c.copy?"copy":c.entityId?"existing":"new",entityId:c.entityId});t.open(br({selectedSubPath:u,...c},e.buildUrlCollectionPath,e.resolveAliasesFrom,i))},[t,e.buildUrlCollectionPath,e.resolveAliasesFrom,i]),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(br(c,e.buildUrlCollectionPath,e.resolveAliasesFrom,i))},[e.buildUrlCollectionPath,e.resolveAliasesFrom,t,i]);return{close:n,open:s,replace:l}};function Nc(e,t,o){const a=Qo({path:e,collections:t}),i=[];let n="";for(let s=0;s<a.length;s++){const l=a[s];if(l.type==="collection"&&(n=l.path),s>0){const c=a[s-1];if(l.type==="entity")i.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=i[i.length-1];u&&(u.selectedSubPath=l.view.key)}}else if(l.type==="collection"&&c.type==="entity"){const u=i[i.length-1];u&&(u.selectedSubPath=l.collection.id??l.collection.path)}}}return o&&i.push({path:n,copy:!1}),i}const br=(e,t,o,a)=>{const i=me(e.path),n=e.entityId?t(`${i}/${e.entityId}/${e.selectedSubPath||""}`):t(`${i}#${Zn}`),s=o(e.path),l={...e,path:s};return{key:`${e.path}/${e.entityId}`,component:r.jsx(Bc,{...l}),urlPath:n,parentUrlPath:t(i),width:Sc(e,a),onClose:e.onClose}};function Pc(){const e=ge.useLocation(),t=ge.useNavigate(),[o,a]=d.useState([]),i=d.useRef(o),n=d.useRef({}),s=d.useRef(0),l=g=>{i.current=g,a(g)};d.useEffect(()=>{const h=(e.state?.panels??[]).map(A=>n.current[A]).filter(A=>!!A);Y(i.current.map(A=>A.key),h.map(A=>A.key))||l(h)},[e]);const c=d.useCallback(()=>{if(o.length===0)return;const g=o[o.length-1],m=[...o.slice(0,-1)];if(l(m),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:m.map(A=>A.key)}})}},[o,t,e]),u=d.useCallback(g=>{const m=Array.isArray(g)?g:[g];m.forEach(y=>{n.current[y.key]=y}),s.current=s.current+m.length;const h=e.state?.base_location??e,A=[...o,...m];l(A),m.forEach(y=>{y.urlPath&&t(y.urlPath,{state:{base_location:h,panels:A.map(b=>b.key)}})})},[e,t,o]),f=d.useCallback(g=>{const m=Array.isArray(g)?g:[g];m.forEach(y=>{n.current[y.key]=y});const h=e.state?.base_location??e,A=[...o.slice(0,-m.length),...m];l(A),m.forEach(y=>{y.urlPath&&t(y.urlPath,{replace:!0,state:{base_location:h,panels:A.map(b=>b.key)}})})},[e,t,o]);return{sidePanels:o,close:c,open:u,replace:f}}function Tc({delegate:e,propertyConfigs:t,navigationController:o}){return{fetchCollection:d.useCallback(({path:a,collection:i,filter:n,limit:s,startAfter:l,searchString:c,orderBy:u,order:f})=>e.fetchCollection({path:a,filter:n,limit:s,startAfter:l,searchString:c,orderBy:u,order:f}),[e]),listenCollection:e.listenCollection?d.useCallback(({path:a,collection:i,filter:n,limit:s,startAfter:l,searchString:c,orderBy:u,order:f,onUpdate:g,onError:m})=>{const h=i??o.getCollection(a),A=!!h?.collectionGroup;if(!e.listenCollection)throw Error("useBuildDataSource delegate not initialised");return e.listenCollection({path:a,filter:n,limit:s,startAfter:l,searchString:c,orderBy:u,order:f,onUpdate:g,onError:m,isCollectionGroup:A,collection:h})},[e,o.getCollection]):void 0,fetchEntity:d.useCallback(({path:a,entityId:i})=>e.fetchEntity({path:a,entityId:i}),[e]),listenEntity:e.listenEntity?d.useCallback(({path:a,entityId:i,collection:n,onUpdate:s,onError:l})=>{if(!e.listenEntity)throw Error("useBuildDataSource delegate not initialised");return e.listenEntity({path:a,entityId:i,onUpdate:s,onError:l})},[e.listenEntity]):void 0,saveEntity:d.useCallback(({path:a,entityId:i,values:n,collection:s,status:l})=>{const c=s??o.getCollection(a),f=(c?Ne({collection:c,path:a,entityId:i,fields:t}):void 0)?.properties,g=e.cmsToDelegateModel(n),m=f?Ro({inputValues:g,properties:f,status:l,timestampNowValue:e.currentTime(),setDateToMidnight:e.setDateToMidnight}):g;return e.saveEntity({path:a,entityId:i,values:m,status:l}).then(h=>({id:h.id,path:h.path,values:e.delegateToCMSModel(m)}))},[e.saveEntity,o.getCollection]),deleteEntity:d.useCallback(({entity:a})=>e.deleteEntity({entity:a}),[e.deleteEntity]),checkUniqueField:d.useCallback((a,i,n,s)=>e.checkUniqueField(a,i,n,s),[e.checkUniqueField]),generateEntityId:d.useCallback(a=>e.generateEntityId(a),[e.generateEntityId]),countEntities:e.countEntities?async({path:a,collection:i,filter:n,order:s,orderBy:l})=>e.countEntities({path:a,filter:n,orderBy:l,order:s,isCollectionGroup:!!i.collectionGroup}):void 0,isFilterCombinationValid:d.useCallback(({path:a,filterValues:i,sortBy:n})=>e.isFilterCombinationValid?e.isFilterCombinationValid({path:a,filterValues:i,sortBy:n}):!0,[e.isFilterCombinationValid]),initTextSearch:d.useCallback(async a=>e.initTextSearch?e.initTextSearch(a):!1,[e.initTextSearch])}}const Dc="https://api-drplyi3b6q-ey.a.run.app";async function Qc(e,t){const o=await e.getAuthToken();return fetch(Dc+"/access_log",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Basic ${o}`},body:JSON.stringify({plugins:t})}).then(async a=>a.json())}function Mc(e,t){const[o,a]=d.useState(null),i=d.useRef(null),n=t?.map(s=>s.key);return d.useEffect(()=>{e.user&&e.user.uid!==i.current&&!e.initialLoading&&(Qc(e,n).then(a),i.current=e.user.uid)},[e,n]),o}function Oc(e){const{children:t,entityLinkBuilder:o,userConfigPersistence:a,dateTimeFormat:i,locale:n,authController:s,storageSource:l,dataSourceDelegate:c,plugins:u,onAnalyticsEvent:f,propertyConfigs:g,entityViews:m,components:h,navigationController:A}=e;p.useLocaleConfig(n);const y=Tc({delegate:c,propertyConfigs:g,navigationController:A}),b=Pc(),k=Fc(A,b),_=u?.some(B=>B.loading)??!1,v=s.initialLoading||A.loading||_,x={dateTimeFormat:i,locale:n,entityLinkBuilder:o,plugins:u,entityViews:m??[],propertyConfigs:g??{},components:h},C=d.useMemo(()=>({onAnalyticsEvent:f}),[]),E=Mc(s,u);return A.navigationLoadingError?r.jsx(p.CenteredView,{maxWidth:"md",children:r.jsx(ye,{title:"Error loading navigation",error:A.navigationLoadingError})}):s.authError?r.jsx(p.CenteredView,{maxWidth:"md",children:r.jsx(ye,{title:"Error loading auth",error:s.authError})}):E?.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."]}),E?.message&&r.jsxs(p.Typography,{children:["Response from the server: ",E?.message]})]}):r.jsx(Ia.Provider,{value:C,children:r.jsx(Sa.Provider,{value:x,children:r.jsx(xa.Provider,{value:a,children:r.jsx(Ca.Provider,{value:l,children:r.jsx(wa.Provider,{value:y,children:r.jsx(kr.Provider,{value:s,children:r.jsx(ka.Provider,{value:b,children:r.jsx(_a.Provider,{value:k,children:r.jsx(va.Provider,{value:A,children:r.jsx(Ki,{children:r.jsx(zc,{loading:v,children:t})})})})})})})})})})})}function zc({loading:e,children:t}){const o=Ce(),a=se();let i=t({context:o,loading:e});const n=a.plugins;return!e&&n&&n.forEach(s=>{s.provider&&(i=r.jsx(s.provider.Component,{...s.provider.props,context:o,children:i}))}),r.jsx(r.Fragment,{children:i})}const Xn=280,Vc=d.memo(function(t){const{children:o,autoOpenDrawer:a,logo:i,className:n,style:s}=t,l=d.Children.toArray(o).filter(C=>C.type.componentType==="Drawer");if(l.length>1)throw Error("Only one Drawer component is allowed in Scaffold");const c=d.Children.toArray(o).filter(C=>C.type.componentType==="AppBar");if(c.length>1)throw Error("Only one AppBar component is allowed in Scaffold");const u=d.Children.toArray(o).filter(C=>C.type.componentType!=="Drawer"&&C.type.componentType!=="AppBar"),f=l.length>0,g=Oe(),[m,h]=d.useState(!1),[A,y]=d.useState(!1),b=d.useCallback(()=>y(!0),[]),k=d.useCallback(()=>y(!1),[]),_=d.useCallback(()=>{h(!0)},[]),v=d.useCallback(()=>{h(!1)},[]),x=m||!!(g&&a&&A);return r.jsx(wo.Provider,{value:{logo:i,hasDrawer:f,drawerHovered:A,drawerOpen:x,closeDrawer:v,openDrawer:_,autoOpenDrawer:a},children:r.jsxs("div",{className:p.cls("flex h-screen w-screen bg-gray-50 dark:bg-gray-900 text-gray-900 dark:text-white overflow-hidden",n),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",...s},children:[c,r.jsx(Yc,{displayed:f,onMouseEnter:b,onMouseMove:b,onMouseLeave:k,open:x,hovered:A,setDrawerOpen:h,children:f&&l}),r.jsxs("main",{className:"flex flex-col flex-grow overflow-auto",children:[r.jsx(Gc,{}),r.jsx("div",{className:p.cls(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:u})})]})]})})},Y),Gc=()=>r.jsx("div",{className:"flex flex-col min-h-[68px]"});function Yc(e){const t=e.displayed?e.open?Xn:72:0,o=r.jsxs("div",{className:"relative h-full no-scrollbar overflow-y-auto overflow-x-hidden",style:{width:t,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 z-20",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.jsx("div",{className:`z-20 absolute right-0 top-4 ${e.open?"opacity-100":"opacity-0 invisible"} transition-opacity duration-200 ease-in-out`,children:r.jsx(p.IconButton,{"aria-label":"Close drawer",onClick:()=>e.setDrawerOpen(!1),children:r.jsx(p.ChevronLeftIcon,{})})}),r.jsx("div",{className:"flex flex-col h-full",children:e.children})]});return Oe()?r.jsx("div",{className:"z-20 relative",onMouseEnter:e.onMouseEnter,onMouseMove:e.onMouseMove,onMouseLeave:e.onMouseLeave,style:{width:t,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:o}):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:o})]}):null}function Kn({name:e,icon:t,drawerOpen:o,tooltipsOpen:a,url:i,onClick:n}){const s=r.jsx("div",{className:"text-gray-600 dark:text-gray-500",children:t}),l=r.jsxs(ge.NavLink,{onClick:n,style:{width:o?"280px":"72px",transition:o?"width 150ms ease-in":void 0},className:({isActive:c})=>p.cls("rounded-r-lg 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-60 dark:bg-gray-800 dark:bg-opacity-30":""),to:i,children:[s,r.jsx("div",{className:p.cls(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})}function Rn({className:e,style:t}){const{drawerHovered:o,drawerOpen:a,closeDrawer:i,logo:n}=pr(),s=gt(),l=pe(),c=o&&!a,u=Oe(),f=ge.useNavigate(),[g,m]=d.useState(!1);if(!l.topLevelNavigation)throw Error("Navigation not ready in Drawer");const{navigationEntries:h,groups:A}=l.topLevelNavigation,y=h.filter(v=>v.type==="admin")??[],b=A.filter(v=>v!=="Admin"),k=d.useCallback(v=>a?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:v?v.toUpperCase():"Views".toUpperCase()})}):r.jsx("div",{className:"h-12 w-full"}),[a]),_=v=>{const x=v.type==="collection"?"drawer_navigate_to_collection":v.type==="view"?"drawer_navigate_to_view":"unmapped_event";s.onAnalyticsEvent?.(x,{url:v.url}),u||i()};return r.jsx(r.Fragment,{children:r.jsxs("div",{className:p.cls("flex flex-col h-full relative flex-grow w-full",e),style:t,children:[r.jsx(ei,{logo:n}),r.jsx("div",{className:"overflow-scroll no-scrollbar",children:b.map(v=>r.jsxs(d.Fragment,{children:[k(v),Object.values(h).filter(x=>x.group===v).map((x,C)=>r.jsx(Kn,{icon:r.jsx(rr,{collectionOrView:x.collection??x.view}),tooltipsOpen:c,drawerOpen:a,onClick:()=>_(x),url:x.url,name:x.name},`navigation_${C}`))]},`drawer_group_${v}`))}),y.length>0&&r.jsx(p.Menu,{open:g,onOpenChange:m,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:c,side:"right",sideOffset:28,children:r.jsx(p.MoreVertIcon,{})}),a&&r.jsx("div",{className:p.cls(a?"opacity-100":"opacity-0 hidden","mx-4 font-inherit text-inherit"),children:"ADMIN"})]}),children:y.map((v,x)=>r.jsxs(p.MenuItem,{onClick:C=>{C.preventDefault(),f(v.path)},children:[r.jsx(rr,{collectionOrView:v.view}),v.name]},`navigation_${x}`))})]})})}function ei({logo:e}){const t=pe(),{drawerOpen:o}=pr();return r.jsx("div",{style:{transition:"padding 100ms cubic-bezier(0.4, 0, 0.6, 1) 0ms",padding:o?"32px 144px 0px 24px":"72px 16px 0px"},className:p.cls("cursor-pointer"),children:r.jsx(p.Tooltip,{title:"Home",sideOffset:20,side:"right",children:r.jsx(ge.Link,{to:t.basePath,children:e?r.jsx("img",{src:e,alt:"Logo",className:p.cls("max-w-full max-h-full",o??"w-[112px] h-[112px]")}):r.jsx(yo,{})})})})}const Lc=d.memo(function({homePage:t=r.jsx(In,{}),children:o}){const a=ge.useLocation(),i=pe();if(!i)return r.jsx(r.Fragment,{});const n=a.state,s=n&&n.base_location?n.base_location:a,l=[];i.views&&i.views.forEach(m=>{Array.isArray(m.path)?l.push(...m.path.map(h=>yr(h,m))):l.push(yr(m.path,m))}),i.adminViews&&i.adminViews.forEach(m=>{Array.isArray(m.path)?l.push(...m.path.map(h=>yr(h,m))):l.push(yr(m.path,m))});const u=[...i.collections??[]].sort((m,h)=>h.path.length-m.path.length).map(m=>{const h=i.buildUrlCollectionPath(m.id??m.path);return r.jsx(ge.Route,{path:h+"/*",element:r.jsx(ae,{children:r.jsx(bo,{isSubCollection:!1,parentCollectionIds:[],fullPath:m.id??m.path,...m,Actions:Pt(m.Actions)},`collection_view_${m.id??m.path}`)})},`navigation_${m.id??m.path}`)}),f=r.jsx(ge.Route,{path:"/",element:t}),g=r.jsx(ge.Route,{path:"*",element:r.jsx(Pn,{})});return r.jsxs(ge.Routes,{location:s,children:[u,l,f,g,o]})}),yr=(e,t)=>r.jsx(ge.Route,{path:e,element:t.view},"navigation_view_"+e);function ti({children:e,className:t,style:o}){const a=e??r.jsx(Rn,{className:t,style:o});return r.jsx(r.Fragment,{children:a})}ti.componentType="Drawer";function ri({children:e,...t}){const o=e??r.jsx(Tn,{...t});return r.jsx(r.Fragment,{children:o})}ri.componentType="AppBar",w.AppBar=ri,w.AppContext=wo,w.ArrayContainer=vo,w.ArrayContainerItem=ko,w.ArrayCustomShapedFieldBinding=$n,w.ArrayEnumPreview=Zr,w.ArrayItemOptions=Dn,w.ArrayOfMapsPreview=Ns,w.ArrayOfReferencesFieldBinding=Qn,w.ArrayOfReferencesPreview=Wa,w.ArrayOfStorageComponentsPreview=qa,w.ArrayOfStringsPreview=Ha,w.ArrayOneOfPreview=Ja,w.ArrayPropertyEnumPreview=Xr,w.ArrayPropertyPreview=Jr,w.AsyncPreviewComponent=Ps,w.AuthControllerContext=kr,w.BlockFieldBinding=jn,w.BooleanPreview=Ka,w.COLLECTION_PATH_SEPARATOR=na,w.CircularProgressCenter=Nt,w.DEFAULT_FIELD_CONFIGS=fr,w.DRAWER_WIDTH=Xn,w.DatePreview=Xa,w.DateTimeFieldBinding=zn,w.DefaultAppBar=Tn,w.DefaultDrawer=Rn,w.DefaultHomePage=In,w.DeleteConfirmationDialog=Ll,w.Drawer=ti,w.DrawerLogo=ei,w.DrawerNavigationItem=Kn,w.EmptyValue=nt,w.EntityCollectionRowActions=lr,w.EntityCollectionTable=co,w.EntityCollectionView=bo,w.EntityCollectionViewActions=Fn,w.EntityReference=Cr,w.EntityView=Rr,w.EnumValuesChip=Ie,w.ErrorBoundary=ae,w.ErrorView=ye,w.FieldCaption=Hl,w.FieldHelperText=Ee,w.FireCMS=Oc,w.FireCMSLogo=yo,w.FormikArrayContainer=ur,w.GeoPoint=xr,w.IconForView=rr,w.ImagePreview=Ga,w.KeyValueFieldBinding=Yn,w.KeyValuePreview=Kr,w.LabelWithIcon=Be,w.MapFieldBinding=Gn,w.MapPropertyPreview=Za,w.MarkdownFieldBinding=Un,w.ModeControllerContext=vr,w.ModeControllerProvider=wi,w.MultiSelectBinding=Co,w.NavigationCard=En,w.NavigationCardBinding=Sn,w.NavigationGroup=go,w.NavigationRoutes=Lc,w.NotFoundPage=Pn,w.NumberPropertyPreview=Ra,w.PropertyConfigBadge=Yl,w.PropertyFieldBinding=lt,w.PropertyPreview=we,w.PropertyTableCell=pn,w.ReadOnlyFieldBinding=Eo,w.ReferenceFieldBinding=Vn,w.ReferencePreview=Ve,w.ReferenceSelectionTable=xn,w.ReferenceWidget=$l,w.RepeatFieldBinding=Ln,w.Scaffold=Vc,w.SearchIconsView=ql,w.SelectFieldBinding=_o,w.SelectableTable=vn,w.SelectableTableContext=oo,w.SideDialogs=xc,w.SkeletonPropertyComponent=it,w.SmallNavigationCard=Bn,w.SnackbarProvider=bi,w.StorageThumbnail=Ya,w.StorageThumbnailInternal=ja,w.StorageUploadFieldBinding=xo,w.StringPropertyPreview=Hr,w.SwitchFieldBinding=On,w.TextFieldBinding=vt,w.UrlComponentPreview=It,w.Vector=_i,w.VirtualTable=gn,w.addInitialSlash=vi,w.applyPermissionsFunctionIfEmpty=oa,w.archiveEntityAction=xl,w.buildAdditionalFieldDelegate=Ji,w.buildCollection=Li,w.buildEntityCallbacks=Hi,w.buildEnumLabel=ta,w.buildEnumValueConfig=qi,w.buildEnumValues=Wi,w.buildFieldConfig=Zi,w.buildIdColumn=cl,w.buildProperties=Ui,w.buildPropertiesOrBuilder=$i,w.buildProperty=ji,w.canCreateEntity=ft,w.canDeleteEntity=Rt,w.canEditEntity=Or,w.copyEntityAction=mo,w.defaultDateFormat=aa,w.deleteEntityAction=ho,w.deleteEntityWithCallbacks=Fa,w.editEntityAction=Cn,w.enumToObjectEntries=Je,w.flattenObject=Vr,w.fullPathToCollectionSegments=Qr,w.getArrayValuesCount=fa,w.getBracketNotation=Oi,w.getCollectionByPathOrId=Yt,w.getCollectionPathsCombinations=Lt,w.getColorForProperty=Mi,w.getColorScheme=ea,w.getColumnKeysForProperty=cr,w.getDefaultFieldConfig=qn,w.getDefaultFieldId=mr,w.getDefaultPropertiesOrder=zi,w.getDefaultValueFor=Wt,w.getDefaultValueForDataType=Fr,w.getDefaultValuesFor=xt,w.getEntityImagePreviewPropertyKey=ua,w.getEntityPreviewKeys=pa,w.getEntityTitlePropertyKey=zr,w.getFieldConfig=Dt,w.getFieldId=No,w.getHashValue=Br,w.getIcon=da,w.getIconForProperty=_e,w.getIconForWidget=Xt,w.getIdIcon=Qi,w.getLabelOrConfigFrom=Ht,w.getLastSegment=ki,w.getPropertiesWithPropertiesOrder=ca,w.getPropertyInPath=rt,w.getRandomId=Tt,w.getReferenceFrom=$e,w.getResolvedPropertyInPath=Mr,w.getSidePanelKey=ls,w.getValueInPath=Ue,w.hydrateRegExp=sa,w.iconSynonyms=er,w.iconsSearch=tr,w.isDefaultFieldConfigId=Wn,w.isEmptyObject=Ir,w.isEnumValueDisabled=Ei,w.isHidden=$t,w.isObject=jt,w.isPropertyBuilder=ke,w.isReadOnly=pt,w.isReferenceProperty=la,w.isValidRegExp=Di,w.joinCollectionLists=ga,w.makePropertiesEditable=ma,w.makePropertiesNonEditable=ha,w.mergeCollection=Aa,w.mergeDeep=Me,w.openWebsiteAction=El,w.pick=Xo,w.plural=Gi,w.printChanged=Yr,w.propertiesToColumns=mn,w.randomColor=Ni,w.randomString=ut,w.removeFunctions=Er,w.removeInPath=Ci,w.removeInitialAndTrailingSlashes=me,w.removeInitialSlash=Jo,w.removePropsIfExisting=Ko,w.removeTrailingSlash=Zo,w.removeUndefined=Sr,w.renderSkeletonCaptionText=Cs,w.renderSkeletonIcon=qr,w.renderSkeletonImageThumbnail=Wr,w.renderSkeletonText=We,w.resolveArrayProperty=Ke,w.resolveCollection=Ne,w.resolveCollectionPathIds=_r,w.resolveDefaultSelectedView=Tr,w.resolveEntityView=Do,w.resolveEnumValues=uc,w.resolveNavigationFrom=Na,w.resolvePermissions=Et,w.resolveProperties=Po,w.resolveProperty=Pe,w.resolvePropertyEnum=To,w.sanitizeData=xi,w.saveEntityWithCallbacks=Ur,w.segmentsToStrippedPath=ia,w.serializeRegExp=Ti,w.singular=Yi,w.slugify=Jt,w.sortProperties=Pr,w.stripCollectionPath=Dr,w.toKebabCase=Si,w.toSnakeCase=Fi,w.traverseValueProperty=qt,w.traverseValuesProperties=Nr,w.unslugify=Pi,w.updateDateAutoValues=Ro,w.useApp=pr,w.useAuthController=ot,w.useBrowserTitleAndIcon=as,w.useBuildLocalConfigurationPersistence=ps,w.useBuildModeController=us,w.useBuildNavigationController=ss,w.useClearRestoreValue=Qe,w.useClipboard=Ta,w.useCollectionFetch=Ri,w.useColumnIds=io,w.useCustomizationController=se,w.useDataSource=ze,w.useDataSourceEntityCollectionTableController=po,w.useDebouncedCallback=Zt,w.useDebouncedData=kn,w.useDialogsController=Ba,w.useEntityFetch=jr,w.useFireCMSContext=Ce,w.useLargeLayout=Oe,w.useModeController=Pa,w.useNavigationController=pe,w.useReferenceDialog=At,w.useResolvedNavigationFrom=es,w.useSelectableTableController=dn,w.useSelectionController=uo,w.useSideDialogContext=gr,w.useSideDialogsController=Bt,w.useSideEntityController=at,w.useSnackbarController=Ze,w.useStorageSource=mt,w.useTableSearchHelper=fo,w.useTraceUpdate=Xi,w.useValidateAuthenticator=fs,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
588
+ `;function $n({propertyKey:e,value:t,error:o,showError:a,isSubmitting:i,setValue:n,tableMode:s,property:l,includeDescription:c,underlyingValueHasChanged:u,context:f,disabled:g}){if(!Array.isArray(l.resolvedProperties))throw Error("ArrayCustomShapedFieldBinding misconfiguration. Property `of` not set");const m=l.expanded===void 0?!0:l.expanded;Qe({property:l,value:t,setValue:n});const h=r.jsx(Be,{icon:_e(l,"small"),required:l.validation?.required,className:"text-text-secondary dark:text-text-secondary-dark",title:l.name}),A=l.resolvedProperties.map((y,b)=>{const k={propertyKey:`${e}[${b}]`,disabled:g,property:y,includeDescription:c,underlyingValueHasChanged:u,context:f,tableMode:!1,partOfArray:!0,partOfBlock:!1,autoFocus:!1};return r.jsx("div",{className:"pb-4",children:r.jsx(lt,{...k})},`custom_shaped_array_${b}`)});return r.jsxs(r.Fragment,{children:[!s&&r.jsx(p.ExpandablePanel,{initiallyExpanded:m,title:h,className:"px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2",children:A}),s&&A,r.jsx(Ee,{includeDescription:c,showError:a,error:o,disabled:g,property:l})]})}function Wn(e){return Object.keys(fr).includes(e)}const fr={text_field:{key:"text_field",name:"Text field",description:"Simple short text",Icon:p.ShortTextIcon,color:"#2d7ff9",property:{dataType:"string",Field:vt}},multiline:{key:"multiline",name:"Multiline",description:"Text with multiple lines",Icon:p.SubjectIcon,color:"#2d7ff9",property:{dataType:"string",multiline:!0,Field:vt}},markdown:{key:"markdown",name:"Markdown",description:"Text with advanced markdown syntax",Icon:p.FormatQuoteIcon,color:"#2d7ff9",property:{dataType:"string",markdown:!0,Field:Un}},url:{key:"url",name:"Url",description:"Text with URL validation",Icon:p.HttpIcon,color:"#154fb3",property:{dataType:"string",url:!0,Field:vt}},email:{key:"email",name:"Email",description:"Text with email validation",Icon:p.EmailIcon,color:"#154fb3",property:{dataType:"string",email:!0,Field:vt}},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:On}},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:_o}},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:Co}},number_input:{key:"number_input",name:"Number input",description:"Simple number field with validation",Icon:p.NumbersIcon,color:"#bec920",property:{dataType:"number",Field:vt}},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:_o}},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:Co}},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:xo}},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:xo}},reference:{key:"reference",name:"Reference",description:"The value refers to a different collection",Icon:p.LinkIcon,color:"#ff0042",property:{dataType:"reference",Field:Vn}},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:Qn}},date_time:{key:"date_time",name:"Date/time",description:"A date time select field",Icon:p.ScheduleIcon,color:"#8b46ff",property:{dataType:"date",Field:zn}},group:{key:"group",name:"Group",description:"Group of multiple fields",Icon:p.BallotIcon,color:"#ff9408",property:{dataType:"map",properties:{},Field:Gn}},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:Yn}},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:Ln}},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:$n}},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:jn}}};function qn(e){const t=mr(e);if(!t){console.error("No field id found for property",e);return}return fr[t]}function Dt(e,t){const o=No(e),a=mr(e);if(!a){console.error("No field id found for property",e);return}const i=fr[a],n=o?t[o]:void 0;return Me(i??{},n??{})}function mr(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 No(e){return e.propertyConfig?e.propertyConfig:mr(e)}const Ne=({collection:e,path:t,entityId:o,values:a,previousValues:i,userConfigPersistence:n,fields:s,ignoreMissingFields:l=!1})=>{const c=n?.getCollectionConfig(t),u=Ue(c,"properties"),f=xt(e.properties),g=a??f,m=i??a??f,h=Object.entries(e.properties).map(([b,k])=>{const _=Pe({propertyKey:b,propertyOrBuilder:k,values:g,previousValues:m,path:t,entityId:o,fields:s,ignoreMissingFields:l});return _?{[b]:_}:{}}).filter(b=>b!==null).reduce((b,k)=>({...b,...k}),{}),A=Me(h,u),y=Object.entries(A).filter(([b,k])=>!!k?.dataType).map(([b,k])=>({[b]:k})).reduce((b,k)=>({...b,...k}),{});return{...e,properties:y,originalCollection:e}};function Pe({propertyOrBuilder:e,fromBuilder:t=!1,ignoreMissingFields:o=!1,...a}){if(typeof e=="object"&&"resolved"in e)return e;let i=null;if(e)if(ke(e)){const n=a.path;if(!n)throw Error("Trying to resolve a property builder without specifying the entity path");const s=a.propertyKey?ve.getIn(a.values,a.propertyKey):void 0,l=e({...a,path:n,propertyValue:s,values:a.values??{},previousValues:a.previousValues??a.values??{}});if(!l)return null;i=Pe({...a,propertyOrBuilder:l,fromBuilder:!0,ignoreMissingFields:o})}else{const n=e;if(n.dataType==="map"&&n.properties){const s=Po({ignoreMissingFields:o,...a,properties:n.properties});i={...n,resolved:!0,fromBuilder:t,properties:s}}else n.dataType==="array"?i=Ke({property:n,fromBuilder:t,ignoreMissingFields:o,...a}):(n.dataType==="string"||n.dataType==="number")&&n.enumValues&&(i=To(n,t))}else return null;if(i||(i={...e,resolved:!0,fromBuilder:t}),i.propertyConfig&&!Wn(i.propertyConfig)){const n=a.fields;if(!n&&!o)throw Error(`Trying to resolve a property with key '${i.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 s=n?.[i.propertyConfig];if(!s)return console.warn(`Trying to resolve a property with key '${i.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(s.property){const l=s.property;"propertyConfig"in l&&delete l.propertyConfig;const c=Pe({propertyOrBuilder:l,ignoreMissingFields:o,...a});c&&(i=Me(c,i))}}return i?{...i,resolved:!0}:null}function Ke({propertyKey:e,property:t,ignoreMissingFields:o=!1,...a}){const i=e?ve.getIn(a.values,e):void 0;if(t.of){if(Array.isArray(t.of))return{...t,resolved:!0,fromBuilder:a.fromBuilder,resolvedProperties:t.of.map((n,s)=>Pe({propertyKey:`${e}.${s}`,propertyOrBuilder:n,ignoreMissingFields:o,...a,index:s}))};{const n=t.of,s=Array.isArray(i)?i.map((c,u)=>Pe({propertyKey:`${e}.${u}`,propertyOrBuilder:n,ignoreMissingFields:o,...a,index:u})).filter(c=>!!c):[],l=Pe({propertyKey:`${e}`,propertyOrBuilder:n,ignoreMissingFields:o,...a});if(!l&&!o)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:a.fromBuilder,of:l,resolvedProperties:s}}}else if(t.oneOf){const n=t.oneOf?.typeField??Ct,s=Array.isArray(i)?i.map((c,u)=>{const f=c&&c[n],g=t.oneOf?.properties[f];return!f||!g?null:Pe({propertyKey:`${e}.${u}`,propertyOrBuilder:g,ignoreMissingFields:o,...a})}).filter(c=>!!c):[],l=Po({properties:t.oneOf.properties,ignoreMissingFields:o,...a});return{...t,resolved:!0,oneOf:{...t.oneOf,properties:l},fromBuilder:a.fromBuilder,resolvedProperties:s}}else{if(t.Field)return{...t,resolved:!0,fromBuilder:a.fromBuilder};throw Error("The array property needs to declare an 'of' or a 'oneOf' property, or provide a custom `Field`")}}function Po({properties:e,ignoreMissingFields:t,...o}){return Object.entries(e).map(([a,i])=>{const n=Pe({propertyKey:a,propertyOrBuilder:i,ignoreMissingFields:t,...o});return n?{[a]:n}:{}}).filter(a=>a!==null).reduce((a,i)=>({...a,...i}),{})}function To(e,t){return typeof e.enumValues=="object"?{...e,resolved:!0,enumValues:Je(e.enumValues)?.filter(o=>o&&(o.id||o.id===0)&&o.label)??[],fromBuilder:t??!1}:e}function uc(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 Do(e,t){return typeof e=="string"?t?.find(o=>o.key===e):e}function Qo(e){const{path:t,collections:o=[],currentFullPath:a}=e,i=me(t).split("/"),n=Lt(i),s=[];for(let l=0;l<n.length;l++){const c=n[l],u=o&&o.find(f=>f.id===c||f.path===c);if(u){const f=u.id??u.path,g=a&&a.length>0?a+"/"+f:f;s.push({type:"collection",path:g,collection:u});const m=me(me(t).replace(c,"")),h=m.length>0?m.split("/"):[];if(h.length>0){const A=h[0],y=g+"/"+A;if(s.push({type:"entity",entityId:A,path:g,parentCollection:u}),h.length>1){const b=h.slice(1).join("/");if(!u)throw Error("collection not found resolving path: "+u);const k=u.entityViews,_=k&&k.map(v=>Do(v,e.contextEntityViews)).filter(Boolean).find(v=>v.key===b);if(_){const v=a&&a.length>0?a+"/"+_.key:_.key;s.push({type:"custom_view",path:v,view:_})}else u.subcollections&&s.push(...Qo({path:b,collections:u.subcollections,currentFullPath:y,contextEntityViews:e.contextEntityViews}))}}break}}return s}const fc="100vw",mc="55vw",hr="768px";function hc({customId:e,entityId:t,status:o,onChange:a,error:i,entity:n,loading:s}){const{errors:l}=ve.useFormex(),c=o==="existing"||!e,u=o!=="existing"&&!e,f=d.useMemo(()=>{if(!(!e||typeof e=="boolean"||e==="optional"))return Je(e)},[e]),g=Ze(),{copy:m}=Ta({onSuccess:y=>g.open({type:"success",message:`Copied ${y}`})}),h=se(),A={label:u?"ID is set automatically":"ID",disabled:c||s,name:"id",value:(n&&o==="existing"?n.id:t)??"",endAdornment:s?r.jsx(p.CircularProgress,{size:"small"}):n?r.jsxs(r.Fragment,{children:[r.jsx(p.Tooltip,{title:"Copy",children:r.jsx(p.IconButton,{onClick:y=>m(n.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:n}),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:[f&&r.jsx(p.Select,{error:i,onValueChange:y=>a(y),...A,renderValue:y=>{const b=f.find(k=>k.id===y);return b?`${b.id} - ${b.label}`:y},children:f.map(y=>r.jsx(p.SelectItem,{value:String(y.id),children:r.jsx(Ie,{enumKey:y.id,enumValues:f,size:"medium"})},y.id))}),!f&&r.jsx(p.TextField,{...A,error:i,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 b=y.target.value;return b&&(b=b.trim()),a(b.length?b:void 0)}}),l.id&&r.jsx(p.Typography,{variant:"caption",className:"ml-3.5 text-red-500 dark:text-red-500",children:l.id})]})}const gc=({containerRef:e})=>{const{isSubmitting:t,isValidating:o,errors:a}=ve.useFormex();return d.useEffect(()=>{const i=Object.keys(a);if(i.length>0&&t&&!o){const n=e?.current?.querySelector(`#form_field_${i[0]}`);if(n&&e?.current){const s=Hn(e.current);if(s){const c=n.getBoundingClientRect().top;s.scrollTo({top:s.scrollTop+c-196,behavior:"smooth"})}const l=n.querySelector("input");l&&l.focus()}}},[t,o,a,e]),null},Ac=e=>{const t=e&&e.scrollHeight>e.clientHeight,o=e?window.getComputedStyle(e).overflowY:null,a=o&&o.indexOf("hidden")!==-1;return t&&!a},Hn=e=>!e||e===document.body?document.body:Ac(e)?e:Hn(e.parentNode);function bc({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.ContentCopyIcon,{size:"smallest",className:"text-white",onClick:d.useCallback(()=>{navigator.clipboard.writeText(e),o(!0),setTimeout(()=>o(!1),2e3)},[e])})})]})}const Qt="main_##Q$SC^#S6";function yc({entityId:e,...t}){const{entity:o,dataLoading:a,dataLoadingError:i}=jr({path:t.path,entityId:e,collection:t.collection,useCache:!1});return a?r.jsx(Nt,{}):r.jsx(wc,{...t,entityId:e,entity:o,dataLoading:a})}function wc({path:e,entityId:t,selectedSubPath:o,copy:a,collection:i,parentCollectionIds:n,onValuesAreModified:s,onUpdate:l,onClose:c,entity:u,dataLoading:f}){i.customId&&i.formAutoSave&&console.warn(`The collection ${i.path} has customId and formAutoSave enabled. This is not supported and formAutoSave will be ignored`);const[g,m]=d.useState(!1),[h,A]=d.useState(void 0);Zt(h,()=>{h&&Ge({entityId:ie?.id,collection:i,path:e,values:h,closeAfterSave:!1})},!1,2e3);const y=i,b=ot(),k=ze(i),_=gr(),v=at(),x=Ze(),C=se(),E=Ce(),B=d.useRef(!1),S=gt(),P=d.useMemo(()=>Ne({collection:y,path:e,values:u?.values,fields:C.propertyConfigs}),[u?.values,e,C.propertyConfigs]),T=a?"copy":t?"existing":"new",[N,M]=d.useState(T),L=(N==="new"||N==="copy")&&!!P.customId&&P.customId!=="optional",ee=d.useMemo(()=>N==="new"||N==="copy"?L?void 0:k.generateEntityId(e):t,[t,N]),[G,q]=d.useState(ee),[j,O]=d.useState(!1),[te,Z]=d.useState(),[le,ne]=d.useState(!1),re=o??Tr(i?i.defaultSelectedView:void 0,{status:N,entityId:G}),J=d.useRef(re??Qt),Q=d.useRef(vc(P,N,u)),R=J.current===Qt,H=(i.subcollections??[]).filter(F=>!F.hideFromNavigation),$=H?.length??0,V=i.entityViews,z=V?.length??0,I=i.formAutoSave&&!i.customId,D=z>0||$>0,[ie,xe]=d.useState(u),[Le,K]=d.useState(void 0);d.useEffect(()=>{u&&xe(u)},[u]),d.useEffect(()=>{if(N==="new")K(!1);else{const F=ie?Or(i,b,e,ie??null):!1;ie&&K(!F)}},[b,ie,N]);const he=d.useCallback(F=>{m(!1),x.open({type:"error",message:"Error before saving: "+F?.message}),console.error(F)},[x]),Te=d.useCallback(F=>{m(!1),x.open({type:"error",message:"Error after saving (entity is saved): "+F?.message}),console.error(F)},[x]),Fe=(F,W)=>{m(!1),I||x.open({type:"success",message:`${i.singularName??i.name}: Saved correctly`}),xe(F),M("existing"),s(!1),l&&l({entity:F}),W?(console.log("Closing side dialog"),_.setBlocked(!1),_.close(!0),c?.()):N!=="existing"&&v.replace({path:e,entityId:F.id,selectedSubPath:J.current,updateUrl:!0,collection:i})},Ae=d.useCallback(F=>{m(!1),x.open({type:"error",message:"Error saving: "+F?.message}),console.error("Error saving entity",e,G),console.error(F)},[G,e,x]),Ge=({values:F,previousValues:W,closeAfterSave:fe,entityId:De,collection:He,path:Gt})=>(m(!0),Ur({path:Gt,entityId:De,values:F,previousValues:W,collection:He,status:N,dataSource:k,context:E,onSaveSuccess:jo=>Fe(jo,fe),onSaveFailure:Ae,onPreSaveHookError:he,onSaveSuccessHookError:Te}).then()),je=async({collection:F,path:W,entityId:fe,values:De,previousValues:He,closeAfterSave:Gt,autoSave:jo})=>{if(N)if(jo)A(De);else return Ge({collection:F,path:W,entityId:fe,values:De,previousValues:He,closeAfterSave:Gt})},qe=(F,W)=>{if(L&&!G){console.error("Missing custom Id"),O(!0),W.setSubmitting(!1);return}if(Z(void 0),O(!1),N==="existing"){if(!u?.id)throw Error("Form misconfiguration when saving, no id for existing entity")}else if(N==="new"||N==="copy"){if(y.customId&&y.customId!=="optional"&&!G)throw Error("Form misconfiguration when saving, entityId should be set")}else throw Error("New FormType added, check EntityForm");return Mt(F)?.then(fe=>{W.resetForm({values:F,submitCount:0,touched:{}})}).finally(()=>{W.setSubmitting(!1)})},X=ve.useCreateFormex({initialValues:Q.current,onSubmit:qe,validation:F=>Uc?.validate(F,{abortEarly:!1}).then(()=>({})).catch(W=>{const fe={};return W.inner.forEach(De=>{fe[De.path]=De.message}),kc(W)})}),be=Ne({collection:y,path:e,entityId:G,values:X.values,previousValues:X.initialValues,fields:C.propertyConfigs}),wr=d.useRef(u?.values),Mt=F=>(wr.current=F,je({collection:be,path:e,entityId:G,values:F,previousValues:u?.values,closeAfterSave:B.current,autoSave:I??!1}).then(W=>{const fe=N==="new"?"new_entity_saved":N==="copy"?"entity_copied":N==="existing"?"entity_edited":"unmapped_event";S.onAnalyticsEvent?.(fe,{path:e})}).catch(W=>{console.error(W),Z(W)}).finally(()=>{B.current=!1})),Re={setFieldValue:d.useCallback(X.setFieldValue,[]),values:X.values,collection:be,entityId:G,path:e,save:Mt,formex:X},Ot=V?V.map(F=>Do(F,C.entityViews)).filter(Boolean):[],Oo=Ot.find(F=>F.key===J.current),zo=!I&&(J.current===Qt||Oo?.includeActions),Vo=V&&Ot.map((F,W)=>{if(!F||J.current!==F.key)return null;const fe=F.Builder;return fe?r.jsx("div",{className:p.cls(p.defaultBorderMixin,"relative flex-grow w-full h-full overflow-auto "),role:"tabpanel",children:r.jsx(ae,{children:Re&&r.jsx(fe,{collection:i,entity:ie,modifiedValues:X.values??ie?.values,formContext:Re})})},`custom_view_${F.key}`):(console.error("customView.Builder is not defined"),null)}).filter(Boolean),kt=f&&!ie||(!ie||Le===void 0)&&(N==="existing"||N==="copy"),Go=kt||g,U=H&&H.map((F,W)=>{const fe=F.id??F.path,De=ie?`${e}/${ie?.id}/${me(fe)}`:void 0;return J.current!==fe?null:r.jsxs("div",{className:"relative flex-grow h-full overflow-auto w-full",role:"tabpanel",children:[Go&&r.jsx(Nt,{}),!kt&&(ie&&De?r.jsx(bo,{fullPath:De,parentCollectionIds:[...n,i.id],isSubCollection:!0,...F}):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_${fe}`)}).filter(Boolean),oe=d.useCallback(()=>{s(!1)},[]),ce=F=>{J.current=F,v.replace({path:e,entityId:G,selectedSubPath:F===Qt?void 0:F,updateUrl:!0,collection:i})},de=d.useCallback(F=>{x.open({type:"error",message:"Error updating id, check the console"})},[]),ue=d.useCallback(F=>{xe(W=>W?{...W,id:F}:void 0)},[]),Ye=[],et=C.plugins;if(et&&y){const F={entityId:G,path:e,status:N,collection:y,context:E,currentEntityId:G,formContext:Re};Ye.push(...et.map((W,fe)=>W.form?.Actions?r.jsx(W.form.Actions,{...F},`actions_${W.key}`):null).filter(Boolean))}const zt=zr(be,C.propertyConfigs),jc=X.values&&zt?Ue(X.values,zt):void 0,oi=y.callbacks?.onIdUpdate,ai=d.useCallback(async()=>{if(oi&&X.values&&(N==="new"||N==="copy")){ne(!0);try{const F=await oi({collection:be,path:e,entityId:G,values:X.values,context:E});q(F)}catch(F){de&&de(F),console.error(F)}ne(!1)}},[G,X.values,N]);d.useEffect(()=>{ai()},[ai]);const[Vt,Kc]=d.useState({}),ni=d.useCallback(({name:F,value:W,property:fe})=>k.checkUniqueField(e,F,W,G),[k,e,G]),Uc=d.useMemo(()=>G?cn(G,be.properties,ni):void 0,[G,be.properties,ni]),$c=d.useCallback(({entity:F,customEntityActions:W})=>{const fe=ft(y,b,e,null),De=F?Rt(y,b,e,F):!0,He=[];return fe&&He.push(mo),De&&He.push(ho),W&&He.push(...W),He},[b,y,e]),Yo=X.dirty;d.useEffect(()=>{I?X.values&&!Y(X.values,wr.current)&&Mt(X.values):s(Yo)},[Yo,X.values]),d.useEffect(()=>{!I&&!X.isSubmitting&&Vt&&u&&Object.entries(Vt).forEach(([F,W])=>{const fe=X.values[F];!Y(W,fe)&&!X.touched[F]&&(console.debug("Updated value from the datasource:",F,W),X.setFieldValue(F,W!==void 0?W:null))})},[X.isSubmitting,I,Vt,u,X.values,X.touched,X.setFieldValue]);const Wc=r.jsx(r.Fragment,{children:(be.propertiesOrder??Object.keys(be.properties)).map(F=>{const W=be.properties[F];if(!W)return console.warn(`Property ${F} not found in collection ${be.name}`),null;const fe=!!Vt&&Object.keys(Vt).includes(F)&&!!X.touched[F],De=!I&&X.isSubmitting||pt(W)||!!W.disabled;if($t(W))return null;const Gt={propertyKey:F,disabled:De,property:W,includeDescription:W.description||W.longDescription,underlyingValueHasChanged:fe&&!I,context:Re,tableMode:!1,partOfArray:!1,partOfBlock:!1,autoFocus:!1};return r.jsx("div",{id:`form_field_${F}`,children:r.jsx(ae,{children:r.jsx(p.Tooltip,{title:r.jsx(bc,{propertyId:F}),delayDuration:800,side:"left",align:"start",sideOffset:16,children:r.jsx(lt,{...Gt})})})},`field_${be.name}_${F}`)}).filter(Boolean)}),Lo=X.isSubmitting||!Yo&&N==="existing",ii=d.useRef(null),si=$c({entity:u,customEntityActions:y.entityActions}).filter(F=>F.includeInForm===void 0||F.includeInForm),qc=r.jsxs(p.DialogActions,{position:"absolute",children:[te&&r.jsx("div",{className:"text-right",children:r.jsx(p.Typography,{color:"error",children:te.message})}),u&&si.length>0&&r.jsx("div",{className:"flex-grow flex overflow-auto no-scrollbar",children:si.map(F=>r.jsx(p.IconButton,{color:"primary",onClick:W=>{W.stopPropagation(),u&&F.onClick({entity:u,fullPath:be.path,collection:be,context:E,sideEntityController:v})},children:F.icon},F.name))}),X.isSubmitting&&r.jsx(p.CircularProgress,{size:"small"}),r.jsx(p.Button,{variant:"text",disabled:Lo||X.isSubmitting,type:"reset",children:N==="existing"?"Discard":"Clear"}),r.jsxs(p.Button,{variant:"text",color:"primary",type:"submit",disabled:Lo||X.isSubmitting,onClick:()=>{B.current=!1},children:[N==="existing"&&"Save",N==="copy"&&"Create copy",N==="new"&&"Create"]}),r.jsxs(p.Button,{variant:"filled",color:"primary",type:"submit",disabled:Lo||X.isSubmitting,onClick:()=>{B.current=!0},children:[N==="existing"&&"Save and close",N==="copy"&&"Create copy and close",N==="new"&&"Create and close"]})]});function Hc(){let F=r.jsxs("div",{className:"h-full overflow-auto",children:[Ye.length>0&&r.jsx("div",{className:p.cls("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:Ye}),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+(Ye?8:0)} lg:mt-${8+(Ye?8:0)} mb-8`,children:[r.jsx(p.Typography,{className:"mt-4 flex-grow line-clamp-1 "+y.hideIdFromForm?"mb-2":"mb-0",variant:"h4",children:jc??y.singularName??y.name}),r.jsx(p.Alert,{color:"base",className:"w-full",size:"small",children:r.jsxs("code",{className:"text-xs select-all",children:[e,"/",G]})})]}),!i.hideIdFromForm&&r.jsx(hc,{customId:y.customId,entityId:G,status:N,onChange:q,error:j,loading:le,entity:u}),G&&Re&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"mt-12 flex flex-col gap-8",ref:ii,children:[Wc,r.jsx(gc,{containerRef:ii})]}),r.jsx("div",{className:"h-14"})]})]})]});return et&&et.forEach(W=>{W.form?.provider&&(F=r.jsx(W.form.provider.Component,{status:N,path:e,collection:i,onDiscard:oe,entity:ie,context:E,formContext:Re,...W.form.provider.props,children:F}))}),r.jsx(ae,{children:F})}const Jc=Le===void 0?r.jsx(r.Fragment,{}):Le?r.jsxs(r.Fragment,{children:[r.jsx(p.Typography,{className:"mt-16 mb-8 mx-8",variant:"h4",children:i.singularName??i.name}),r.jsx(Rr,{className:"px-12",entity:ie,path:e,collection:i})]}):Hc(),Zc=H&&H.map(F=>r.jsx(p.Tab,{className:"text-sm min-w-[140px]",value:F.id,children:F.name},`entity_detail_collection_tab_${F.name}`)),Xc=Ot.map(F=>r.jsx(p.Tab,{className:"text-sm min-w-[140px]",value:F.key,children:F.name},`entity_detail_collection_tab_${F.name}`));return d.useEffect(()=>{G&&ue&&ue(G)},[G,ue]),r.jsx(ve.Formex,{value:X,children:r.jsxs("div",{className:"flex flex-col h-full w-full transition-width duration-250 ease-in-out",children:[r.jsxs("div",{className:p.cls(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:()=>(c?.(),_.close(!1)),children:r.jsx(p.CloseIcon,{size:"small"})})}),r.jsx("div",{className:"flex-grow"}),kt&&r.jsx("div",{className:"self-center",children:r.jsx(p.CircularProgress,{size:"small"})}),r.jsxs(p.Tabs,{value:J.current,onValueChange:F=>{ce(F)},className:"pl-4 pr-4 pt-0",children:[r.jsx(p.Tab,{disabled:!D,value:Qt,className:`${D?"":"hidden"} text-sm min-w-[140px]`,children:i.singularName??i.name}),Xc,Zc]})]}),r.jsxs("form",{onSubmit:X.handleSubmit,onReset:()=>(X.resetForm(),oe&&oe()),noValidate:!0,className:"flex-grow h-full flex overflow-auto flex-col w-full",children:[r.jsx("div",{role:"tabpanel",hidden:!R,id:`form_${e}`,className:" w-full",children:kt?r.jsx(Nt,{}):Jc}),Vo,U,zo&&qc]})]})})}function vc(e,t,o){const a=e.properties;if((t==="existing"||t==="copy")&&o)return o.values??xt(a);if(t==="new")return xt(a);throw console.error({status:t,entity:o}),new Error("Form has not been initialised with the correct parameters")}function kc(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 _c(e,t){const[o,a]=d.useState(),{navigator:i}=d.useContext(ge.UNSAFE_NavigationContext),n=ge.useNavigate(),s=()=>{a(void 0)},l=()=>{t(),a(void 0),n(-1)},c=d.useCallback(({action:u,location:f,retry:g})=>{switch(u){case"REPLACE":{g();return}case"POP":a(f)}},[]);return d.useEffect(()=>{if(!e||o||!("block"in i))return;const u=i.block(f=>{const g={...f,retry(){u(),f.retry()}};c(g)});return u},[i,c,e,o]),{navigationWasBlocked:!!o,handleCancel:s,handleOk:l}}function Cc({open:e,handleOk:t,handleCancel:o,body:a,title:i}){return r.jsxs(p.Dialog,{open:e,onOpenChange:n=>n?o():t(),children:[r.jsxs(p.DialogContent,{children:[r.jsx(p.Typography,{variant:"h6",children:i}),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 Jn=d.createContext({width:"",blocked:!1,setBlocked:e=>{},setBlockedNavigationMessage:e=>{},close:()=>{}}),gr=()=>d.useContext(Jn);function xc(){const t=Bt().sidePanels,o=[...t];return o.push(void 0),r.jsx(r.Fragment,{children:o.map((a,i)=>r.jsx(Ec,{panel:a,offsetPosition:t.length-i-1},`side_dialog_${i}`))})}function Ec({offsetPosition:e,panel:t}){const[o,a]=d.useState(!1),[i,n]=d.useState(!1),[s,l]=d.useState(),c=d.useRef(t?.width),u=c.current,f=Bt(),{navigationWasBlocked:g,handleOk:m,handleCancel:h}=_c(i&&!o,()=>n(!1));d.useEffect(()=>{t&&(c.current=t.width)},[t]);const A=()=>{n(!1),a(!1),f.close(),t?.onClose?.()},y=()=>{a(!1)},b=k=>{i&&!k?a(!0):(f.close(),t?.onClose?.())};return r.jsxs(Jn.Provider,{value:{blocked:i,setBlocked:n,setBlockedNavigationMessage:l,width:u,close:b},children:[r.jsxs(p.Sheet,{open:!!t,onOpenChange:k=>!k&&b(),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(Cc,{open:g||o,handleOk:o?A:m,handleCancel:o?y:h,body:s})]})}function Bc(e){const{blocked:t,setBlocked:o,setBlockedNavigationMessage:a}=gr(),i=pe(),n=d.useMemo(()=>i.getParentCollectionIds(e.path),[i,e.path]),s=d.useMemo(()=>{if(!e)return;let c=e.collection;const u=i.getCollection(e.path);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},[i,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(yc,{...e,collection:s,parentCollectionIds:n,onValuesAreModified:l})})})}const Zn="new";function Sc(e,t){if(t)return fc;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?Ic(e.collection):hr):`calc(${mc} + ${a??hr})`}const Mo={};function Ic(e){if(Mo[e.id])return Mo[e.id];const t=Ne({collection:e,path:"__ignored",ignoreMissingFields:!0});let o=hr;if(t?.properties){const a=Object.values(t.properties).map(n=>Ar(n)),i=Math.max(...a);i<3?o=hr:o=768+32*(i-2)+"px"}return Mo[e.id]=o,o}function Ar(e,t=0){if(e.dataType==="map"&&e.properties){const o=Object.values(e.properties).flatMap(a=>Ar(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=>Ar(o,t+1))):Ar(e.of,t+1):t+1}const Fc=(e,t)=>{const o=ge.useLocation(),a=d.useRef(!1),i=!Oe();d.useEffect(()=>{if(!e.loading&&!a.current){if(console.debug("Initialising side entity controller"),e.isUrlCollectionPath(o.pathname)){const c=o.hash===`#${Zn}`,u=e.urlPathToDataPath(o.pathname),f=Nc(u,e.collections??[],c);for(let g=0;g<f.length;g++){const m=f[g];setTimeout(()=>{g===0?t.replace(br(m,e.buildUrlCollectionPath,e.resolveAliasesFrom,i)):t.open(br(m,e.buildUrlCollectionPath,e.resolveAliasesFrom,i))},1)}}a.current=!0}},[o,e.loading,e.isUrlCollectionPath,e.buildUrlCollectionPath,e.resolveAliasesFrom,t,i,e]);const n=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=Tr(c.collection?c.collection.defaultSelectedView:void 0,{status:c.copy?"copy":c.entityId?"existing":"new",entityId:c.entityId});t.open(br({selectedSubPath:u,...c},e.buildUrlCollectionPath,e.resolveAliasesFrom,i))},[t,e.buildUrlCollectionPath,e.resolveAliasesFrom,i]),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(br(c,e.buildUrlCollectionPath,e.resolveAliasesFrom,i))},[e.buildUrlCollectionPath,e.resolveAliasesFrom,t,i]);return{close:n,open:s,replace:l}};function Nc(e,t,o){const a=Qo({path:e,collections:t}),i=[];let n="";for(let s=0;s<a.length;s++){const l=a[s];if(l.type==="collection"&&(n=l.path),s>0){const c=a[s-1];if(l.type==="entity")i.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=i[i.length-1];u&&(u.selectedSubPath=l.view.key)}}else if(l.type==="collection"&&c.type==="entity"){const u=i[i.length-1];u&&(u.selectedSubPath=l.collection.id??l.collection.path)}}}return o&&i.push({path:n,copy:!1}),i}const br=(e,t,o,a)=>{const i=me(e.path),n=e.entityId?t(`${i}/${e.entityId}/${e.selectedSubPath||""}`):t(`${i}#${Zn}`),s=o(e.path),l={...e,path:s};return{key:`${e.path}/${e.entityId}`,component:r.jsx(Bc,{...l}),urlPath:n,parentUrlPath:t(i),width:Sc(e,a),onClose:e.onClose}};function Pc(){const e=ge.useLocation(),t=ge.useNavigate(),[o,a]=d.useState([]),i=d.useRef(o),n=d.useRef({}),s=d.useRef(0),l=g=>{i.current=g,a(g)};d.useEffect(()=>{const h=(e.state?.panels??[]).map(A=>n.current[A]).filter(A=>!!A);Y(i.current.map(A=>A.key),h.map(A=>A.key))||l(h)},[e]);const c=d.useCallback(()=>{if(o.length===0)return;const g=o[o.length-1],m=[...o.slice(0,-1)];if(l(m),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:m.map(A=>A.key)}})}},[o,t,e]),u=d.useCallback(g=>{const m=Array.isArray(g)?g:[g];m.forEach(y=>{n.current[y.key]=y}),s.current=s.current+m.length;const h=e.state?.base_location??e,A=[...o,...m];l(A),m.forEach(y=>{y.urlPath&&t(y.urlPath,{state:{base_location:h,panels:A.map(b=>b.key)}})})},[e,t,o]),f=d.useCallback(g=>{const m=Array.isArray(g)?g:[g];m.forEach(y=>{n.current[y.key]=y});const h=e.state?.base_location??e,A=[...o.slice(0,-m.length),...m];l(A),m.forEach(y=>{y.urlPath&&t(y.urlPath,{replace:!0,state:{base_location:h,panels:A.map(b=>b.key)}})})},[e,t,o]);return{sidePanels:o,close:c,open:u,replace:f}}function Tc({delegate:e,propertyConfigs:t,navigationController:o}){return{fetchCollection:d.useCallback(({path:a,collection:i,filter:n,limit:s,startAfter:l,searchString:c,orderBy:u,order:f})=>e.fetchCollection({path:a,filter:n,limit:s,startAfter:l,searchString:c,orderBy:u,order:f}),[e]),listenCollection:e.listenCollection?d.useCallback(({path:a,collection:i,filter:n,limit:s,startAfter:l,searchString:c,orderBy:u,order:f,onUpdate:g,onError:m})=>{const h=i??o.getCollection(a),A=!!h?.collectionGroup;if(!e.listenCollection)throw Error("useBuildDataSource delegate not initialised");return e.listenCollection({path:a,filter:n,limit:s,startAfter:l,searchString:c,orderBy:u,order:f,onUpdate:g,onError:m,isCollectionGroup:A,collection:h})},[e,o.getCollection]):void 0,fetchEntity:d.useCallback(({path:a,entityId:i})=>e.fetchEntity({path:a,entityId:i}),[e]),listenEntity:e.listenEntity?d.useCallback(({path:a,entityId:i,collection:n,onUpdate:s,onError:l})=>{if(!e.listenEntity)throw Error("useBuildDataSource delegate not initialised");return e.listenEntity({path:a,entityId:i,onUpdate:s,onError:l})},[e.listenEntity]):void 0,saveEntity:d.useCallback(({path:a,entityId:i,values:n,collection:s,status:l})=>{const c=s??o.getCollection(a),f=(c?Ne({collection:c,path:a,entityId:i,fields:t}):void 0)?.properties,g=e.cmsToDelegateModel(n),m=f?Ro({inputValues:g,properties:f,status:l,timestampNowValue:e.currentTime(),setDateToMidnight:e.setDateToMidnight}):g;return e.saveEntity({path:a,entityId:i,values:m,status:l}).then(h=>({id:h.id,path:h.path,values:e.delegateToCMSModel(m)}))},[e.saveEntity,o.getCollection]),deleteEntity:d.useCallback(({entity:a})=>e.deleteEntity({entity:a}),[e.deleteEntity]),checkUniqueField:d.useCallback((a,i,n,s)=>e.checkUniqueField(a,i,n,s),[e.checkUniqueField]),generateEntityId:d.useCallback(a=>e.generateEntityId(a),[e.generateEntityId]),countEntities:e.countEntities?async({path:a,collection:i,filter:n,order:s,orderBy:l})=>e.countEntities({path:a,filter:n,orderBy:l,order:s,isCollectionGroup:!!i.collectionGroup}):void 0,isFilterCombinationValid:d.useCallback(({path:a,filterValues:i,sortBy:n})=>e.isFilterCombinationValid?e.isFilterCombinationValid({path:a,filterValues:i,sortBy:n}):!0,[e.isFilterCombinationValid]),initTextSearch:d.useCallback(async a=>e.initTextSearch?e.initTextSearch(a):!1,[e.initTextSearch])}}const Dc="https://api-drplyi3b6q-ey.a.run.app";async function Qc(e,t){const o=await e.getAuthToken();return fetch(Dc+"/access_log",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Basic ${o}`},body:JSON.stringify({plugins:t})}).then(async a=>a.json())}function Mc(e,t){const[o,a]=d.useState(null),i=d.useRef(null),n=t?.map(s=>s.key);return d.useEffect(()=>{e.user&&e.user.uid!==i.current&&!e.initialLoading&&(Qc(e,n).then(a),i.current=e.user.uid)},[e,n]),o}function Oc(e){const{children:t,entityLinkBuilder:o,userConfigPersistence:a,dateTimeFormat:i,locale:n,authController:s,storageSource:l,dataSourceDelegate:c,plugins:u,onAnalyticsEvent:f,propertyConfigs:g,entityViews:m,components:h,navigationController:A}=e;p.useLocaleConfig(n);const y=Tc({delegate:c,propertyConfigs:g,navigationController:A}),b=Pc(),k=Fc(A,b),_=u?.some(B=>B.loading)??!1,v=s.initialLoading||A.loading||_,x={dateTimeFormat:i,locale:n,entityLinkBuilder:o,plugins:u,entityViews:m??[],propertyConfigs:g??{},components:h},C=d.useMemo(()=>({onAnalyticsEvent:f}),[]),E=Mc(s,u);return A.navigationLoadingError?r.jsx(p.CenteredView,{maxWidth:"md",children:r.jsx(ye,{title:"Error loading navigation",error:A.navigationLoadingError})}):s.authError?r.jsx(p.CenteredView,{maxWidth:"md",children:r.jsx(ye,{title:"Error loading auth",error:s.authError})}):E?.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."]}),E?.message&&r.jsxs(p.Typography,{children:["Response from the server: ",E?.message]})]}):r.jsx(Ia.Provider,{value:C,children:r.jsx(Sa.Provider,{value:x,children:r.jsx(xa.Provider,{value:a,children:r.jsx(Ca.Provider,{value:l,children:r.jsx(wa.Provider,{value:y,children:r.jsx(kr.Provider,{value:s,children:r.jsx(ka.Provider,{value:b,children:r.jsx(_a.Provider,{value:k,children:r.jsx(va.Provider,{value:A,children:r.jsx(Ki,{children:r.jsx(zc,{loading:v,children:t})})})})})})})})})})})}function zc({loading:e,children:t}){const o=Ce(),a=se();let i=t({context:o,loading:e});const n=a.plugins;return!e&&n&&n.forEach(s=>{s.provider&&(i=r.jsx(s.provider.Component,{...s.provider.props,context:o,children:i}))}),r.jsx(r.Fragment,{children:i})}const Xn=280,Vc=d.memo(function(t){const{children:o,autoOpenDrawer:a,logo:i,className:n,style:s}=t,l=d.Children.toArray(o).filter(C=>C.type.componentType==="Drawer");if(l.length>1)throw Error("Only one Drawer component is allowed in Scaffold");const c=d.Children.toArray(o).filter(C=>C.type.componentType==="AppBar");if(c.length>1)throw Error("Only one AppBar component is allowed in Scaffold");const u=d.Children.toArray(o).filter(C=>C.type.componentType!=="Drawer"&&C.type.componentType!=="AppBar"),f=l.length>0,g=Oe(),[m,h]=d.useState(!1),[A,y]=d.useState(!1),b=d.useCallback(()=>y(!0),[]),k=d.useCallback(()=>y(!1),[]),_=d.useCallback(()=>{h(!0)},[]),v=d.useCallback(()=>{h(!1)},[]),x=m||!!(g&&a&&A);return r.jsx(wo.Provider,{value:{logo:i,hasDrawer:f,drawerHovered:A,drawerOpen:x,closeDrawer:v,openDrawer:_,autoOpenDrawer:a},children:r.jsxs("div",{className:p.cls("flex h-screen w-screen bg-gray-50 dark:bg-gray-900 text-gray-900 dark:text-white overflow-hidden",n),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",...s},children:[c,r.jsx(Yc,{displayed:f,onMouseEnter:b,onMouseMove:b,onMouseLeave:k,open:x,hovered:A,setDrawerOpen:h,children:f&&l}),r.jsxs("main",{className:"flex flex-col flex-grow overflow-auto",children:[r.jsx(Gc,{}),r.jsx("div",{className:p.cls(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:u})})]})]})})},Y),Gc=()=>r.jsx("div",{className:"flex flex-col min-h-[68px]"});function Yc(e){const t=e.displayed?e.open?Xn:72:0,o=r.jsxs("div",{className:"relative h-full no-scrollbar overflow-y-auto overflow-x-hidden",style:{width:t,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 z-20",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.jsx("div",{className:`z-20 absolute right-0 top-4 ${e.open?"opacity-100":"opacity-0 invisible"} transition-opacity duration-200 ease-in-out`,children:r.jsx(p.IconButton,{"aria-label":"Close drawer",onClick:()=>e.setDrawerOpen(!1),children:r.jsx(p.ChevronLeftIcon,{})})}),r.jsx("div",{className:"flex flex-col h-full",children:e.children})]});return Oe()?r.jsx("div",{className:"z-20 relative",onMouseEnter:e.onMouseEnter,onMouseMove:e.onMouseMove,onMouseLeave:e.onMouseLeave,style:{width:t,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:o}):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:o})]}):null}function Kn({name:e,icon:t,drawerOpen:o,tooltipsOpen:a,url:i,onClick:n}){const s=r.jsx("div",{className:"text-gray-600 dark:text-gray-500",children:t}),l=r.jsxs(ge.NavLink,{onClick:n,style:{width:o?"280px":"72px",transition:o?"width 150ms ease-in":void 0},className:({isActive:c})=>p.cls("rounded-r-lg 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-60 dark:bg-gray-800 dark:bg-opacity-30":""),to:i,children:[s,r.jsx("div",{className:p.cls(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})}function Rn({className:e,style:t}){const{drawerHovered:o,drawerOpen:a,closeDrawer:i,logo:n}=pr(),s=gt(),l=pe(),c=o&&!a,u=Oe(),f=ge.useNavigate(),[g,m]=d.useState(!1);if(!l.topLevelNavigation)throw Error("Navigation not ready in Drawer");const{navigationEntries:h,groups:A}=l.topLevelNavigation,y=h.filter(v=>v.type==="admin")??[],b=A.filter(v=>v!=="Admin"),k=d.useCallback(v=>a?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:v?v.toUpperCase():"Views".toUpperCase()})}):r.jsx("div",{className:"h-12 w-full"}),[a]),_=v=>{const x=v.type==="collection"?"drawer_navigate_to_collection":v.type==="view"?"drawer_navigate_to_view":"unmapped_event";s.onAnalyticsEvent?.(x,{url:v.url}),u||i()};return r.jsx(r.Fragment,{children:r.jsxs("div",{className:p.cls("flex flex-col h-full relative flex-grow w-full",e),style:t,children:[r.jsx(ei,{logo:n}),r.jsx("div",{className:"overflow-scroll no-scrollbar",children:b.map(v=>r.jsxs(d.Fragment,{children:[k(v),Object.values(h).filter(x=>x.group===v).map((x,C)=>r.jsx(Kn,{icon:r.jsx(rr,{collectionOrView:x.collection??x.view}),tooltipsOpen:c,drawerOpen:a,onClick:()=>_(x),url:x.url,name:x.name},`navigation_${C}`))]},`drawer_group_${v}`))}),y.length>0&&r.jsx(p.Menu,{open:g,onOpenChange:m,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:c,side:"right",sideOffset:28,children:r.jsx(p.MoreVertIcon,{})}),a&&r.jsx("div",{className:p.cls(a?"opacity-100":"opacity-0 hidden","mx-4 font-inherit text-inherit"),children:"ADMIN"})]}),children:y.map((v,x)=>r.jsxs(p.MenuItem,{onClick:C=>{C.preventDefault(),f(v.path)},children:[r.jsx(rr,{collectionOrView:v.view}),v.name]},`navigation_${x}`))})]})})}function ei({logo:e}){const t=pe(),{drawerOpen:o}=pr();return r.jsx("div",{style:{transition:"padding 100ms cubic-bezier(0.4, 0, 0.6, 1) 0ms",padding:o?"32px 144px 0px 24px":"72px 16px 0px"},className:p.cls("cursor-pointer"),children:r.jsx(p.Tooltip,{title:"Home",sideOffset:20,side:"right",children:r.jsx(ge.Link,{to:t.basePath,children:e?r.jsx("img",{src:e,alt:"Logo",className:p.cls("max-w-full max-h-full",o??"w-[112px] h-[112px]")}):r.jsx(yo,{})})})})}const Lc=d.memo(function({homePage:t=r.jsx(In,{}),children:o}){const a=ge.useLocation(),i=pe();if(!i)return r.jsx(r.Fragment,{});const n=a.state,s=n&&n.base_location?n.base_location:a,l=[];i.views&&i.views.forEach(m=>{Array.isArray(m.path)?l.push(...m.path.map(h=>yr(h,m))):l.push(yr(m.path,m))}),i.adminViews&&i.adminViews.forEach(m=>{Array.isArray(m.path)?l.push(...m.path.map(h=>yr(h,m))):l.push(yr(m.path,m))});const u=[...i.collections??[]].sort((m,h)=>h.path.length-m.path.length).map(m=>{const h=i.buildUrlCollectionPath(m.id??m.path);return r.jsx(ge.Route,{path:h+"/*",element:r.jsx(ae,{children:r.jsx(bo,{isSubCollection:!1,parentCollectionIds:[],fullPath:m.id??m.path,...m,Actions:Pt(m.Actions)},`collection_view_${m.id??m.path}`)})},`navigation_${m.id??m.path}`)}),f=r.jsx(ge.Route,{path:"/",element:t}),g=r.jsx(ge.Route,{path:"*",element:r.jsx(Pn,{})});return r.jsxs(ge.Routes,{location:s,children:[u,l,f,g,o]})}),yr=(e,t)=>r.jsx(ge.Route,{path:e,element:t.view},"navigation_view_"+e);function ti({children:e,className:t,style:o}){const a=e??r.jsx(Rn,{className:t,style:o});return r.jsx(r.Fragment,{children:a})}ti.componentType="Drawer";function ri({children:e,...t}){const o=e??r.jsx(Tn,{...t});return r.jsx(r.Fragment,{children:o})}ri.componentType="AppBar",w.AppBar=ri,w.AppContext=wo,w.ArrayContainer=vo,w.ArrayContainerItem=ko,w.ArrayCustomShapedFieldBinding=$n,w.ArrayEnumPreview=Zr,w.ArrayItemOptions=Dn,w.ArrayOfMapsPreview=Ns,w.ArrayOfReferencesFieldBinding=Qn,w.ArrayOfReferencesPreview=Wa,w.ArrayOfStorageComponentsPreview=qa,w.ArrayOfStringsPreview=Ha,w.ArrayOneOfPreview=Ja,w.ArrayPropertyEnumPreview=Xr,w.ArrayPropertyPreview=Jr,w.AsyncPreviewComponent=Ps,w.AuthControllerContext=kr,w.BlockFieldBinding=jn,w.BooleanPreview=Ka,w.COLLECTION_PATH_SEPARATOR=na,w.CircularProgressCenter=Nt,w.DEFAULT_FIELD_CONFIGS=fr,w.DRAWER_WIDTH=Xn,w.DatePreview=Xa,w.DateTimeFieldBinding=zn,w.DefaultAppBar=Tn,w.DefaultDrawer=Rn,w.DefaultHomePage=In,w.DeleteConfirmationDialog=Ll,w.Drawer=ti,w.DrawerLogo=ei,w.DrawerNavigationItem=Kn,w.EmptyValue=nt,w.EntityCollectionRowActions=lr,w.EntityCollectionTable=co,w.EntityCollectionView=bo,w.EntityCollectionViewActions=Fn,w.EntityReference=Cr,w.EntityView=Rr,w.EnumValuesChip=Ie,w.ErrorBoundary=ae,w.ErrorView=ye,w.FieldCaption=Hl,w.FieldHelperText=Ee,w.FireCMS=Oc,w.FireCMSLogo=yo,w.FormikArrayContainer=ur,w.GeoPoint=xr,w.IconForView=rr,w.ImagePreview=Ga,w.KeyValueFieldBinding=Yn,w.KeyValuePreview=Kr,w.LabelWithIcon=Be,w.MapFieldBinding=Gn,w.MapPropertyPreview=Za,w.MarkdownFieldBinding=Un,w.ModeControllerContext=vr,w.ModeControllerProvider=wi,w.MultiSelectBinding=Co,w.NavigationCard=En,w.NavigationCardBinding=Sn,w.NavigationGroup=go,w.NavigationRoutes=Lc,w.NotFoundPage=Pn,w.NumberPropertyPreview=Ra,w.PropertyConfigBadge=Yl,w.PropertyFieldBinding=lt,w.PropertyPreview=we,w.PropertyTableCell=pn,w.ReadOnlyFieldBinding=Eo,w.ReferenceFieldBinding=Vn,w.ReferencePreview=Ve,w.ReferenceSelectionTable=xn,w.ReferenceWidget=$l,w.RepeatFieldBinding=Ln,w.Scaffold=Vc,w.SearchIconsView=ql,w.SelectFieldBinding=_o,w.SelectableTable=vn,w.SelectableTableContext=oo,w.SideDialogs=xc,w.SkeletonPropertyComponent=it,w.SmallNavigationCard=Bn,w.SnackbarProvider=bi,w.StorageThumbnail=Ya,w.StorageThumbnailInternal=ja,w.StorageUploadFieldBinding=xo,w.StringPropertyPreview=Hr,w.SwitchFieldBinding=On,w.TextFieldBinding=vt,w.UrlComponentPreview=It,w.Vector=_i,w.VirtualTable=gn,w.addInitialSlash=vi,w.applyPermissionsFunctionIfEmpty=oa,w.archiveEntityAction=xl,w.buildAdditionalFieldDelegate=Ji,w.buildCollection=Li,w.buildEntityCallbacks=Hi,w.buildEnumLabel=ta,w.buildEnumValueConfig=qi,w.buildEnumValues=Wi,w.buildFieldConfig=Zi,w.buildIdColumn=cl,w.buildProperties=Ui,w.buildPropertiesOrBuilder=$i,w.buildProperty=ji,w.canCreateEntity=ft,w.canDeleteEntity=Rt,w.canEditEntity=Or,w.copyEntityAction=mo,w.defaultDateFormat=aa,w.deleteEntityAction=ho,w.deleteEntityWithCallbacks=Fa,w.editEntityAction=Cn,w.enumToObjectEntries=Je,w.flattenObject=Vr,w.fullPathToCollectionSegments=Qr,w.getArrayValuesCount=fa,w.getBracketNotation=Oi,w.getCollectionByPathOrId=Yt,w.getCollectionPathsCombinations=Lt,w.getColorForProperty=Mi,w.getColorScheme=ea,w.getColumnKeysForProperty=cr,w.getDefaultFieldConfig=qn,w.getDefaultFieldId=mr,w.getDefaultPropertiesOrder=zi,w.getDefaultValueFor=Wt,w.getDefaultValueForDataType=Fr,w.getDefaultValuesFor=xt,w.getEntityImagePreviewPropertyKey=ua,w.getEntityPreviewKeys=pa,w.getEntityTitlePropertyKey=zr,w.getFieldConfig=Dt,w.getFieldId=No,w.getHashValue=Br,w.getIcon=da,w.getIconForProperty=_e,w.getIconForWidget=Xt,w.getIdIcon=Qi,w.getLabelOrConfigFrom=Ht,w.getLastSegment=ki,w.getPropertiesWithPropertiesOrder=ca,w.getPropertyInPath=rt,w.getRandomId=Tt,w.getReferenceFrom=$e,w.getResolvedPropertyInPath=Mr,w.getSidePanelKey=ls,w.getValueInPath=Ue,w.hydrateRegExp=sa,w.iconSynonyms=er,w.iconsSearch=tr,w.isDefaultFieldConfigId=Wn,w.isEmptyObject=Ir,w.isEnumValueDisabled=Ei,w.isHidden=$t,w.isObject=jt,w.isPropertyBuilder=ke,w.isReadOnly=pt,w.isReferenceProperty=la,w.isValidRegExp=Di,w.joinCollectionLists=ga,w.makePropertiesEditable=ma,w.makePropertiesNonEditable=ha,w.mergeCollection=Aa,w.mergeDeep=Me,w.openWebsiteAction=El,w.pick=Xo,w.plural=Gi,w.printChanged=Yr,w.propertiesToColumns=mn,w.randomColor=Ni,w.randomString=ut,w.removeFunctions=Er,w.removeInPath=Ci,w.removeInitialAndTrailingSlashes=me,w.removeInitialSlash=Jo,w.removePropsIfExisting=Ko,w.removeTrailingSlash=Zo,w.removeUndefined=Sr,w.renderSkeletonCaptionText=Cs,w.renderSkeletonIcon=qr,w.renderSkeletonImageThumbnail=Wr,w.renderSkeletonText=We,w.resolveArrayProperty=Ke,w.resolveCollection=Ne,w.resolveCollectionPathIds=_r,w.resolveDefaultSelectedView=Tr,w.resolveEntityView=Do,w.resolveEnumValues=uc,w.resolveNavigationFrom=Na,w.resolvePermissions=Et,w.resolveProperties=Po,w.resolveProperty=Pe,w.resolvePropertyEnum=To,w.sanitizeData=xi,w.saveEntityWithCallbacks=Ur,w.segmentsToStrippedPath=ia,w.serializeRegExp=Ti,w.singular=Yi,w.slugify=Jt,w.sortProperties=Pr,w.stripCollectionPath=Dr,w.toKebabCase=Si,w.toSnakeCase=Fi,w.traverseValueProperty=qt,w.traverseValuesProperties=Nr,w.unslugify=Pi,w.updateDateAutoValues=Ro,w.useApp=pr,w.useAuthController=ot,w.useBrowserTitleAndIcon=as,w.useBuildLocalConfigurationPersistence=ps,w.useBuildModeController=us,w.useBuildNavigationController=ss,w.useClearRestoreValue=Qe,w.useClipboard=Ta,w.useCollectionFetch=Ri,w.useColumnIds=io,w.useCustomizationController=se,w.useDataSource=ze,w.useDataSourceEntityCollectionTableController=po,w.useDebouncedCallback=Zt,w.useDebouncedData=kn,w.useDialogsController=Ba,w.useEntityFetch=jr,w.useFireCMSContext=Ce,w.useLargeLayout=Oe,w.useModeController=Pa,w.useNavigationController=pe,w.useReferenceDialog=At,w.useResolvedNavigationFrom=es,w.useSelectableTableController=dn,w.useSelectionController=uo,w.useSideDialogContext=gr,w.useSideDialogsController=Bt,w.useSideEntityController=at,w.useSnackbarController=Ze,w.useStorageSource=mt,w.useTableSearchHelper=fo,w.useTraceUpdate=Xi,w.useValidateAuthenticator=fs,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
589
589
  //# sourceMappingURL=index.umd.js.map