@firecms/core 3.0.0-alpha.62 → 3.0.0-alpha.64

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.
Files changed (40) hide show
  1. package/dist/components/HomePage/DefaultHomePage.d.ts +11 -1
  2. package/dist/index.d.ts +0 -1
  3. package/dist/index.es.js +4008 -4012
  4. package/dist/index.es.js.map +1 -1
  5. package/dist/index.umd.js +5 -5
  6. package/dist/index.umd.js.map +1 -1
  7. package/dist/preview/PropertyPreview.d.ts +2 -1
  8. package/dist/preview/PropertyPreviewProps.d.ts +1 -6
  9. package/dist/preview/property_previews/ArrayOfMapsPreview.d.ts +1 -1
  10. package/dist/preview/property_previews/ArrayOfStorageComponentsPreview.d.ts +1 -1
  11. package/dist/preview/property_previews/ArrayOfStringsPreview.d.ts +1 -1
  12. package/dist/preview/property_previews/ArrayOneOfPreview.d.ts +1 -1
  13. package/dist/preview/property_previews/ArrayPropertyPreview.d.ts +1 -1
  14. package/dist/preview/property_previews/MapPropertyPreview.d.ts +1 -1
  15. package/dist/types/navigation.d.ts +6 -1
  16. package/dist/types/plugins.d.ts +10 -0
  17. package/dist/util/navigation_utils.d.ts +2 -2
  18. package/package.json +3 -3
  19. package/src/components/EntityCollectionTable/fields/TableStorageUpload.tsx +1 -1
  20. package/src/components/EntityCollectionTable/internal/PropertyTableCell.tsx +2 -2
  21. package/src/components/EntityPreview.tsx +1 -1
  22. package/src/components/HomePage/DefaultHomePage.tsx +16 -4
  23. package/src/core/Scaffold.tsx +5 -8
  24. package/src/form/components/StorageItemPreview.tsx +1 -1
  25. package/src/form/field_bindings/ReadOnlyFieldBinding.tsx +1 -1
  26. package/src/index.ts +0 -2
  27. package/src/internal/useBuildNavigationController.tsx +21 -5
  28. package/src/preview/PropertyPreview.tsx +15 -13
  29. package/src/preview/PropertyPreviewProps.tsx +2 -2
  30. package/src/preview/components/ReferencePreview.tsx +1 -1
  31. package/src/preview/property_previews/ArrayOfMapsPreview.tsx +2 -2
  32. package/src/preview/property_previews/ArrayOfStorageComponentsPreview.tsx +2 -2
  33. package/src/preview/property_previews/ArrayOfStringsPreview.tsx +2 -2
  34. package/src/preview/property_previews/ArrayOneOfPreview.tsx +2 -2
  35. package/src/preview/property_previews/ArrayPropertyPreview.tsx +2 -2
  36. package/src/preview/property_previews/MapPropertyPreview.tsx +4 -4
  37. package/src/types/navigation.ts +7 -1
  38. package/src/types/plugins.tsx +13 -0
  39. package/src/util/join_collections.ts +5 -2
  40. package/src/util/navigation_utils.ts +5 -5
package/dist/index.umd.js CHANGED
@@ -1,7 +1,7 @@
1
- (function(v,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("react/jsx-runtime"),require("react"),require("notistack"),require("object-hash"),require("formik"),require("@firecms/ui"),require("react-router-dom"),require("date-fns"),require("date-fns/locale"),require("react-fast-compare"),require("react-window"),require("react-use-measure"),require("@hello-pangea/dnd"),require("react-dropzone"),require("react-image-file-resizer"),require("markdown-it"),require("react-markdown-editor-lite"),require("yup"),require("react-datepicker"),require("js-search"),require("@radix-ui/react-portal")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","notistack","object-hash","formik","@firecms/ui","react-router-dom","date-fns","date-fns/locale","react-fast-compare","react-window","react-use-measure","@hello-pangea/dnd","react-dropzone","react-image-file-resizer","markdown-it","react-markdown-editor-lite","yup","react-datepicker","js-search","@radix-ui/react-portal"],r):(v=typeof globalThis<"u"?globalThis:v||self,r(v["FireCMS Core"]={},v.jsxRuntime,v.React,v.notistack,v.hash,v.formik,v.ui,v.reactRouterDom,v.dateFns,v.locales,v.equal,v.reactWindow,v.useMeasure,v.dnd,v.reactDropzone,v.Resizer,v.MarkdownIt,v.MdEditor,v.yup,v.reactDatepicker,v.JsSearch,v.Portal))})(this,function(v,r,c,yn,vn,Ce,f,fe,vl,wl,oe,Cl,cr,lt,wn,El,Bl,et,kl,Cn,xl,Il){"use strict";function yt(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const o=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,o.get?o:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const dr=yt(c),En=yt(wl),Ee=yt(kl),Sl=yt(xl),Fl=yt(Il),Nl=({children:e})=>r.jsx(yn.SnackbarProvider,{maxSnack:3,autoHideDuration:3500,children:e}),Pl={mode:"light",setMode:e=>{},toggleMode:()=>{}},Dt=c.createContext(Pl),Ql=Dt.Provider,Ar=c.createContext({});function Tl(e){return e.includes("-")||e.includes("_")||!e.includes(" ")?e.replace(/[-_]/g," ").replace(/\w\S*/g,function(n){return n.charAt(0).toUpperCase()+n.substr(1)}):e}function ue(e){return Bn(kn(e))}function Bn(e){return e.startsWith("/")?e.slice(1):e}function kn(e){return e.endsWith("/")?e.slice(0,-1):e}function Ml(e){return e.startsWith("/")?e:`/${e}`}function Dl(e){const t=ue(e);if(t.includes("/")){const n=t.split("/");return n[n.length-1]}return t}function fr(e,t){const n=ue(e),o=n.split("/");if(o.length%2===0)throw Error(`resolveCollectionPathAliases: Collection paths must have an odd number of segments: ${e}`);const l=t.find(s=>s.id===o[0]);let i;if(l&&(i=l.path),o.length>1){const s=Ot(i??o[0],t);if(!s?.subcollections)return n;const a=n.split("/").slice(2).join("/");return(i??o[0])+"/"+o[1]+"/"+fr(a,s.subcollections)}else return i??n}function Ot(e,t){const n=ue(e).split("/");if(n.length%2===0)throw Error(`getCollectionByPathOrAlias: Collection paths must have an odd number of segments: ${e}`);const o=Vt(n);let l;for(let i=0;i<o.length;i++){const s=o[i],a=t&&t.sort((d,A)=>(d.id??"").localeCompare(A.id??"")).find(d=>d.id===s||d.path===s);if(a){if(s===e)l=a;else if(a.subcollections){const d=e.replace(s,"").split("/").slice(2).join("/");d.length>0&&(l=Ot(d,a.subcollections))}}if(l)break}return l}function Vt(e){const t=e.length>0&&e.length%2===0?e.splice(0,e.length-1):e,n=t.length,o=[];for(let l=n;l>0;l=l-2)o.push(t.slice(0,l).join("/"));return o}class Fe{id;path;constructor(t,n){this.id=t,this.path=n}get pathWithId(){return`${this.path}/${this.id}`}}class Gt{latitude;longitude;constructor(t,n){this.latitude=t,this.longitude=n}}const xn=(e,...t)=>({...t.reduce((n,o)=>({...n,[o]:e[o]}),{})});function Yt(e){return e&&typeof e=="object"&&!Array.isArray(e)}function Ne(e,t){const n=Yt(e),o=n?{...e}:e;return n&&Yt(t)&&Object.keys(t).forEach(l=>{Yt(t[l])?l in e?o[l]=Ne(e[l],t[l]):Object.assign(o,{[l]:t[l]}):Object.assign(o,{[l]:t[l]})}),o}function $e(e,t){if(e&&typeof e=="object"){if(t in e)return e[t];if(t.includes(".")||t.includes("[")){let n=t.split(/[.[]/);t.includes("[")&&(n=n.map(a=>a.replace("]","")));const o=n[0],l=Array.isArray(e[o])&&!isNaN(parseInt(n[1])),i=l?e[o][parseInt(n[1])]:e[o],s=n.slice(l?2:1).join(".");return s===""?i:$e(i,s)}}}function Ol(e,t){let n={...e};const o=t.split("."),l=o.pop();for(const i of o)n=n[i];return l&&delete n[l],n}function ur(e){if(e!==void 0)return e===null?null:typeof e=="object"?Object.entries(e).filter(([t,n])=>typeof n!="function").map(([t,n])=>Array.isArray(n)?{[t]:n.map(o=>ur(o))}:typeof n=="object"?{[t]:ur(n)}:{[t]:n}).reduce((t,n)=>({...t,...n}),{}):e}function gr(e){if(!e)return null;if(typeof e=="object"){if("id"in e)return e.id;if(e instanceof Date)return e.toLocaleString();if(e instanceof Gt)return vn(e)}return vn(e,{ignoreUnknown:!0})}function hr(e,t){if(typeof e=="function")return e;if(Array.isArray(e))return e.map(n=>hr(n,t));if(typeof e=="object"){const n={};return e===null?e:(Object.keys(e).forEach(o=>{if(!pr(e)){const l=hr(e[o],t),i=typeof l=="string",s=!t||t&&!i||t&&i&&l!=="";l!==void 0&&!pr(l)&&s&&(n[o]=l)}}),n)}return e}function pr(e){return e&&Object.getPrototypeOf(e)===Object.prototype&&Object.keys(e).length===0}function In(e,t){const n=i=>typeof i=="object"&&i!==null,o=i=>Array.isArray(i);if(!n(e)||!n(t))return e;const l=o(e)?[...e]:{...e};return Object.keys(t).forEach(i=>{i in l&&(n(l[i])&&n(t[i])?l[i]=In(l[i],t[i]):l[i]===t[i]&&(o(l)?l.splice(i,1):delete l[i]))}),l}const vt="type",zt="value";function it(e){return e.readOnly||e.dataType==="date"&&e.autoValue?!0:e.dataType==="reference"?!e.path:!1}function wt(e){return typeof e.disabled=="object"&&!!e.disabled.hidden}function ve(e){return typeof e=="function"}function Ct(e){return e?Object.entries(e).map(([t,n])=>{const o=Ut(n);return o===void 0?{}:{[t]:o}}).reduce((t,n)=>({...t,...n}),{}):{}}function Ut(e){if(!ve(e))if(e.dataType==="map"&&e.properties){const t=Ct(e.properties);return Object.keys(t).length===0?void 0:t}else return e.defaultValue?e.defaultValue:mr(e.dataType)}function mr(e){return e==="string"||e==="number"?null:e==="boolean"?!1:e==="date"?null:e==="array"?[]:e==="map"?{}:null}function Sn({inputValues:e,properties:t,status:n,timestampNowValue:o,setDateToMidnight:l}){return br(e,t,(i,s)=>{if(s.dataType==="date"){let a;return n==="existing"&&s.autoValue==="on_update"||(n==="new"||n==="copy")&&(s.autoValue==="on_update"||s.autoValue==="on_create")?a=o:a=i,s.mode==="date"&&(a=l(a)),a}else return i})??{}}function Vl(e,t){const n=e;return Object.entries(t).forEach(([o,l])=>{e&&e[o]!==void 0?n[o]=e[o]:l.validation?.required&&(n[o]=null)}),n}function Ge(e){return new Fe(e.id,e.path)}function br(e,t,n){const o=Object.entries(t).map(([i,s])=>{const a=e&&e[i],d=Lt(a,s,n);if(d!==void 0)return{[i]:d}}).reduce((i,s)=>({...i,...s}),{}),l={...e,...o};if(Object.keys(l).length!==0)return l}function Lt(e,t,n){let o;if(t.dataType==="map"&&t.properties)o=br(e,t.properties,n);else if(t.dataType==="array")if(t.of&&Array.isArray(e))o=e.map(l=>Lt(l,t.of,n));else if(t.oneOf&&Array.isArray(e)){const l=t.oneOf?.typeField??vt,i=t.oneOf?.valueField??zt;o=e.map(s=>{if(s===null)return null;if(typeof s!="object")return s;const a=s[l],d=t.oneOf?.properties[a];return!a||!d?s:{[l]:a,[i]:Lt(s[i],d,n)}})}else o=e;else o=n(e,t);return o}function Fn(e){let t=0,n,o;for(n=0;n<e.length;n++)o=e.charCodeAt(n),t=(t<<5)-t+o,t|=0;return Math.abs(t)}function Nn(e){const t=Fn(e),n=Object.keys(f.CHIP_COLORS),o=t%n.length;return f.CHIP_COLORS[n[o]]}function _e(e){return Array.isArray(e)?e:Object.entries(e).map(([t,n])=>typeof n=="string"?{id:t,label:n}:{...n,id:t})}function $t(e,t){if(t)return e.find(n=>String(n.id)===String(t))}function Pn(e,t){const n=$t(e,t);if(!n?.color)return Nn(t.toString());if(typeof n=="object"&&"color"in n){if(typeof n.color=="string")return f.CHIP_COLORS[n.color];if(typeof n.color=="object")return n.color}}function Gl(e){return typeof e=="object"&&e.disabled}function Qn(e){if(e!==void 0)return typeof e=="object"?e.label:e}const ke=({collection:e,path:t,entityId:n,values:o,previousValues:l,userConfigPersistence:i,fields:s})=>{const a=i?.getCollectionConfig(t),d=$e(a,"properties"),A=Ct(e.properties),g=o??A,p=l??o??A,h=Object.entries(e.properties).map(([b,y])=>{const w=g?Ce.getIn(g,b):void 0,C=Be({propertyKey:b,propertyOrBuilder:y,values:g,previousValues:p,path:t,propertyValue:w,entityId:n,fields:s});return C?{[b]:C}:{}}).filter(b=>b!==null).reduce((b,y)=>({...b,...y}),{}),u=Ne(h,d),m=Object.entries(u).filter(([b,y])=>!!y?.dataType).map(([b,y])=>({[b]:y})).reduce((b,y)=>({...b,...y}),{});return{...e,properties:m,originalCollection:e}};function Be({propertyOrBuilder:e,propertyValue:t,fromBuilder:n=!1,...o}){if(typeof e=="object"&&"resolved"in e)return e;let l=null;if(e)if(ve(e)){const i=o.path;if(!i)throw Error("Trying to resolve a property builder without specifying the entity path");const s=e({...o,path:i,propertyValue:t,values:o.values??{},previousValues:o.previousValues??o.values??{}});if(!s)return null;l=Be({...o,propertyValue:t,propertyOrBuilder:s,fromBuilder:!0})}else{const i=e;if(i.dataType==="map"&&i.properties){const s=yr({...o,properties:i.properties,propertyValue:t});l={...i,resolved:!0,fromBuilder:n,properties:s}}else i.dataType==="array"?l=We({property:i,propertyValue:t,fromBuilder:n,...o}):(i.dataType==="string"||i.dataType==="number")&&i.enumValues&&(l=vr(i,n))}else return null;if(l||(l={...e,resolved:!0,fromBuilder:n}),l.propertyConfig&&!pl(l.propertyConfig)){const i=o.fields;if(!i)throw Error(`Trying to resolve a property with key ${l.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=i[l.propertyConfig];if(!s)return console.warn(`Trying to resolve a property with key ${l.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",i),null;if(s.property){const a=s.property;"propertyConfig"in a&&delete a.propertyConfig;const d=Be({propertyOrBuilder:a,propertyValue:t,...o});d&&(l=Ne(d,l))}}return l?{...l,resolved:!0}:null}function We({propertyKey:e,property:t,propertyValue:n,...o}){if(t.of){if(Array.isArray(t.of))return{...t,resolved:!0,fromBuilder:o.fromBuilder,resolvedProperties:t.of.map((l,i)=>Be({propertyKey:`${e}.${i}`,propertyOrBuilder:l,propertyValue:Array.isArray(n)?n[i]:void 0,...o,index:i}))};{const l=t.of,i=Array.isArray(n)?n.map((a,d)=>Be({propertyKey:`${e}.${d}`,propertyOrBuilder:l,propertyValue:a,...o,index:d})).filter(a=>!!a):[],s=Be({propertyKey:`${e}`,propertyOrBuilder:l,propertyValue:void 0,...o});if(!s)throw Error("When using a property builder as the 'of' prop of an ArrayProperty, you must return a valid child property");return{...t,resolved:!0,fromBuilder:o.fromBuilder,of:s,resolvedProperties:i}}}else if(t.oneOf){const l=t.oneOf?.typeField??vt,i=Array.isArray(n)?n.map((a,d)=>{const A=a&&a[l],g=t.oneOf?.properties[A];return!A||!g?null:Be({propertyKey:`${e}.${d}`,propertyOrBuilder:g,propertyValue:n,...o})}).filter(a=>!!a):[],s=yr({properties:t.oneOf.properties,propertyValue:void 0,...o});return{...t,resolved:!0,oneOf:{...t.oneOf,properties:s},fromBuilder:o.fromBuilder,resolvedProperties:i}}else{if(t.Field)return{...t,resolved:!0,fromBuilder:o.fromBuilder};throw Error("The array property needs to declare an 'of' or a 'oneOf' property, or provide a custom `Field`")}}function yr({properties:e,propertyValue:t,...n}){return Object.entries(e).map(([o,l])=>{const i=t&&typeof t=="object"?$e(t,o):void 0,s=Be({propertyKey:o,propertyOrBuilder:l,propertyValue:i,...n});return s?{[o]:s}:{}}).filter(o=>o!==null).reduce((o,l)=>({...o,...l}),{})}function vr(e,t){return typeof e.enumValues=="object"?{...e,resolved:!0,enumValues:_e(e.enumValues)?.filter(n=>n&&n.id&&n.label)??[],fromBuilder:t??!1}:e}function Yl(e){return typeof e=="object"?Object.entries(e).map(([t,n])=>typeof n=="string"?{id:t,label:n}:n):Array.isArray(e)?e:void 0}function wr(e,t){return typeof e=="string"?t?.find(n=>n.key===e):e}function Cr(e){const{path:t,collections:n=[],currentFullPath:o}=e,l=ue(t).split("/"),i=Vt(l),s=[];for(let a=0;a<i.length;a++){const d=i[a],A=n&&n.find(g=>g.id===d||g.path===d);if(A){const g=A.id??A.path,p=o&&o.length>0?o+"/"+g:g;s.push({type:"collection",path:p,collection:A});const h=ue(ue(t).replace(d,"")),u=h.length>0?h.split("/"):[];if(u.length>0){const m=u[0],b=p+"/"+m;if(s.push({type:"entity",entityId:m,path:p,parentCollection:A}),u.length>1){const y=u.slice(1).join("/");if(!A)throw Error("collection not found resolving path: "+A);const w=A.entityViews,C=w&&w.map(E=>wr(E,e.contextEntityViews)).filter(Boolean).find(E=>E.key===y);if(C){const E=o&&o.length>0?o+"/"+C.key:C.key;s.push({type:"custom_view",path:E,view:C})}else A.subcollections&&s.push(...Cr({path:y,collections:A.subcollections,currentFullPath:b,contextEntityViews:e.contextEntityViews}))}}break}}return s}function Er(e,t){try{const n=Object.keys(e);return(t??n).map(l=>{if(e[l]){const i=e[l];return!ve(i)&&i?.dataType==="map"&&i.properties?{[l]:{...i,properties:Er(i.properties,i.propertiesOrder)}}:{[l]:i}}else return}).filter(l=>l!==void 0).reduce((l,i)=>({...l,...i}),{})}catch(n){return console.error("Error sorting properties",n),e}}function Br(e,t){if(e)return typeof e=="string"?e:e(t)}const zl=/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g,Ul=e=>{const t=e.match(zl);return t?t.map(n=>n.toLowerCase()).join("-"):""},Ll=/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g,$l=e=>{const t=e.match(Ll);return t?t.map(n=>n.toLowerCase()).join("_"):""};function st(e=5){return Math.random().toString(36).slice(2,2+e)}function _l(){return Math.floor(Math.random()*16777215).toString(16)}function _t(e,t="_",n=!0){if(!e)return"";const o="ãàáäâẽèéëêìíïîõòóöôùúüûñç·/_,:;-",l=`aaaaaeeeeeiiiiooooouuuunc${t}${t}${t}${t}${t}${t}${t}`;for(let i=0,s=o.length;i<s;i++)e=e.replace(new RegExp(o.charAt(i),"g"),l.charAt(i));return e=e.toString().replace(/\s+/g,t).replace(/&/g,t).replace(/[^\w\\-]+/g,"").replace(new RegExp("\\"+t+"\\"+t+"+","g"),t).trim().replace(/^\s+|\s+$/g,""),n?e.toLowerCase():e}const Tn="MMMM dd, yyyy, HH:mm:ss",Mn="::";function kr(e){return Dn(Pe(e))}function Dn(e){return e.length===1?e[0]:e.reduce((t,n)=>`${t}${Mn}${n}`)}function Pe(e){return e.split("/").filter((t,n)=>n%2===0)}function Wl(e){return e?e.toString():""}function On(e){if(!e)return;const t=e.match(/\/(.*?)\/([a-z]*)?$/i);return t?new RegExp(t[1],t[2]||""):new RegExp(e,"")}function jl(e){return e.match(/\/((?![*+?])(?:[^\r\n[/\\]|\\.|\[(?:[^\r\n\]\\]|\\.)*])+)\/((?:g(?:im?|mi?)?|i(?:gm?|mg?)?|m(?:gi?|ig?)?)?)/)?!0:!!e.match(/((?![*+?])(?:[^\r\n[/\\]|\\.|\[(?:[^\r\n\]\\]|\\.)*])+)/)}function Wt(e,t,n,o=300){const l=c.useRef(!1),i=()=>{t(),l.current=!1},s=c.useRef(void 0);c.useEffect(()=>(l.current=!0,clearTimeout(s.current),s.current=setTimeout(i,o),()=>{n&&i()}),[n,e])}function Hl(e,t=300){const[n,o]=c.useState(e);return c.useEffect(()=>{const l=setTimeout(()=>{o(e)},t);return()=>{clearTimeout(l)}},[e,t]),n}function Vn(e,t){const n=Be({propertyKey:"ignore",propertyOrBuilder:e,fields:t});return n?n.dataType==="reference"?!0:n.dataType==="array"?Array.isArray(n.of)?!1:n.of?.dataType==="reference":!1:null}function Jl(e){return r.jsx(f.CircleIcon,{size:e})}function jt(e,t){const n=e?.Icon??f.CircleIcon;return r.jsx(n,{size:t})}function he(e,t="small",n={}){if(ve(e))return r.jsx(f.FunctionsIcon,{size:t});{const o=sr(e,n);return jt(o,t)}}function ql(e,t){return ve(e)?"#888":sr(e,t)?.color??"#666"}function tt(e,t){if(typeof e=="object"){if(t in e)return e[t];if(t.includes(".")){const n=t.split("."),o=e[n[0]];if(typeof o=="object"&&o.dataType==="map"&&o.properties)return tt(o.properties,n.slice(1).join("."))}}}function xr(e,t){if(typeof e=="object"){if(t in e)return e[t];if(t.includes(".")){const n=t.split("."),o=e[n[0]];if(o.dataType==="map"&&o.properties)return xr(o.properties,n.slice(1).join("."))}}}function Zl(e){return e.replace(/\.([^.]*)/g,"[$1]")}function Gn(e,t){if(!t)return e;const n={};return t.filter(Boolean).forEach(o=>{const l=tt(e,o);typeof l=="object"&&l.dataType==="map"&&l.properties&&(n[o]={...l,properties:Gn(l.properties,l.propertiesOrder??[])}),l&&(n[o]=l)}),n}function Xl(e){return e.propertiesOrder?e.propertiesOrder:[...Object.keys(e.properties),...(e.additionalFields??[]).map(t=>t.key)]}const Ht={read:!0,edit:!0,create:!0,delete:!0};function Et(e,t,n,o){const l=e.permissions;if(l===void 0)return Ht;if(typeof l=="object")return l;if(typeof l=="function")return l({entity:o,user:t.user,authController:t,collection:e,pathSegments:n});throw console.error("Permissions:",l),Error("New type of permission added and not mapped")}function Ir(e,t,n,o){return Et(e,t,n,o).edit??Ht.edit}function at(e,t,n,o){return Et(e,t,n,o).create??Ht.create}function Jt(e,t,n,o){return Et(e,t,n,o).delete??Ht.delete}function Yn(e,t){if(e&&(e=_t(e),e in Zt))return e in Zt?r.jsx(f.Icon,{iconKey:e,size:"medium",className:t}):void 0}function qt(e,t){const n=Yn(e.icon,t);if(e?.icon&&n)return n;let o=_t(("singularName"in e?e.singularName:void 0)??e.name),l;o in Zt&&(l=o),l||(o=_t(e.path),o in Zt&&(l=o));const i=f.coolIconKeys.length;return l||(l=f.coolIconKeys[Fn(e.path)%i]),r.jsx(f.Icon,{iconKey:l,size:"medium",className:t})}const Zt=f.iconKeys.reduce((e,t)=>(e[t]=t,e),{});function Kl(e,t){if(t!==void 0&&t===1)return e;const n={"(quiz)$":"$1zes","^(ox)$":"$1en","([m|l])ouse$":"$1ice","(matr|vert|ind)ix|ex$":"$1ices","(x|ch|ss|sh)$":"$1es","([^aeiouy]|qu)y$":"$1ies","(hive)$":"$1s","(?:([^f])fe|([lr])f)$":"$1$2ves","(shea|lea|loa|thie)f$":"$1ves",sis$:"ses","([ti])um$":"$1a","(tomat|potat|ech|her|vet)o$":"$1oes","(bu)s$":"$1ses","(alias)$":"$1es","(octop)us$":"$1i","(ax|test)is$":"$1es","(us)$":"$1es","([^s]+)$":"$1s"},o={move:"moves",foot:"feet",goose:"geese",sex:"sexes",child:"children",man:"men",tooth:"teeth",person:"people"};if(["sheep","fish","deer","moose","series","species","money","rice","information","equipment","bison","cod","offspring","pike","salmon","shrimp","swine","trout","aircraft","hovercraft","spacecraft","sugar","tuna","you","wood"].indexOf(e.toLowerCase())>=0)return e;for(const i in o){const s=new RegExp(`${i}$`,"i"),a=o[i];if(s.test(e))return e.replace(s,a)}for(const i in n){const s=new RegExp(i,"i");if(s.test(e))return e.replace(s,n[i])}return e}function Rl(e,t){if(t!==void 0&&t!==1)return e;const n={"(quiz)zes$":"$1","(matr)ices$":"$1ix","(vert|ind)ices$":"$1ex","^(ox)en$":"$1","(alias)es$":"$1","(octop|vir)i$":"$1us","(cris|ax|test)es$":"$1is","(shoe)s$":"$1","(o)es$":"$1","(bus)es$":"$1","([m|l])ice$":"$1ouse","(x|ch|ss|sh)es$":"$1","(m)ovies$":"$1ovie","(s)eries$":"$1eries","([^aeiouy]|qu)ies$":"$1y","([lr])ves$":"$1f","(tive)s$":"$1","(hive)s$":"$1","(li|wi|kni)ves$":"$1fe","(shea|loa|lea|thie)ves$":"$1f","(^analy)ses$":"$1sis","((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$":"$1$2sis","([ti])a$":"$1um","(n)ews$":"$1ews","(h|bl)ouses$":"$1ouse","(corpse)s$":"$1","(us)es$":"$1",s$:""},o={move:"moves",foot:"feet",goose:"geese",sex:"sexes",child:"children",man:"men",tooth:"teeth",person:"people"};if(["sheep","fish","deer","moose","series","species","money","rice","information","equipment","bison","cod","offspring","pike","salmon","shrimp","swine","trout","aircraft","hovercraft","spacecraft","sugar","tuna","you","wood"].indexOf(e.toLowerCase())>=0)return e;for(const i in o){const s=new RegExp(`${o[i]}$`,"i");if(s.test(e))return e.replace(s,i)}for(const i in n){const s=new RegExp(i,"i");if(s.test(e))return e.replace(s,n[i])}return e}function zn(e,t,n,o=3){const l=Object.keys(e.properties);let i=n?.filter(s=>l.includes(s));return i&&i.length>0?i:(i=l,i.filter(s=>{const a=e.properties[s];return a&&!ve(a)&&!Vn(a,t)}).slice(0,o))}function Sr(e,t=""){return e&&Object.keys(e).reduce((n,o)=>{const l=t?`${t}.${o}`:o;return typeof e[o]=="object"&&e[o]!==null?Array.isArray(e[o])?e[o].forEach((i,s)=>{Object.assign(n,Sr(i,`${l}[${s}]`))}):Object.assign(n,Sr(e[o],l)):n[l]=e[o],n},{})}function Un(e){return e.reduce((t,n)=>(Object.entries(n).forEach(([o,l])=>{if(Array.isArray(l)&&(t[o]=Math.max(t[o]||0,l.length)),typeof l=="object"&&l!==null){const i=Un([l]);Object.entries(i).forEach(([s,a])=>{const d=`${o}.${s}`;t[d]=Math.max(t[d]||0,a)})}}),t),{})}function Ln(e){return Object.keys(e).forEach(t=>{const n=e[t];n.editable=!0,n.dataType==="map"&&n.properties&&Ln(n.properties)}),e}function $n(e){return Object.entries(e).reduce((t,[n,o])=>{if(!ve(o)&&o.dataType==="map"&&o.properties){const l={...o,properties:$n(o.properties)};t[n]=l}return ve(o)?t[n]=o:t[n]={...o,editable:!1},t},{})}function Fr(e,t,n){if(e){const l=e({collection:t,parentPaths:n})??t;return l.subcollections&&(l.subcollections=l.subcollections.map(i=>Fr(e,i,[...n,t.path]))),l}else return t}function _n(e,t,n=[],o){const l=(t??[]).map(s=>{const a=e?.find(d=>d.id===s.id);return a?Wn(a,s,n,o):Fr(o,s,n)}),i=e.filter(s=>!l.map(a=>a.id).includes(s.id)).map(s=>o?Fr(o,s,n):s);return[...l,...i]}function Wn(e,t,n=[],o){const l=_n(e?.subcollections??[],t?.subcollections??[],[...n,e.path],o),i={...e.properties};Object.keys(t.properties).forEach(h=>{const u=e.properties[h];u?i[h]=jn(u,t.properties[h]):i[h]=t.properties[h]});const s=Ne(e,t),a=Hn(e),d=Hn(t),A=[...new Set([...d,...a])],g=[...new Set([...e.entityViews??[],...t.entityViews??[]])];let p={...s,subcollections:l,properties:Er(i,A),propertiesOrder:A,entityViews:g};if(o){const h=o({collection:p,parentPaths:n});h&&(p=h)}return p}function jn(e,t){if(ve(t))return t;{const n=Ne(e,t),o=!!e.editable,l=!!t.editable;if(t.dataType==="map"&&t.properties){const i="properties"in e?e.properties:{},s="properties"in t?t.properties:{},a="propertiesOrder"in e&&e.propertiesOrder?e.propertiesOrder:Object.keys(i),d="propertiesOrder"in t&&t.propertiesOrder?t.propertiesOrder:"properties"in t?Object.keys(t.properties):[],A=[...new Set([...a,...d])],g={...i};return Object.keys(t.properties).forEach(p=>{const h=i[p];h&&(g[p]=jn(h,s[p]))}),{...n,editable:o&&l,properties:g,propertiesOrder:A}}return{...n,editable:o&&l}}}function Hn(e){if(e.propertiesOrder&&e.propertiesOrder.length>0){const t=e.propertiesOrder;return e.additionalFields&&e.additionalFields.forEach(n=>{t.includes(n.key)||t.push(n.key)}),t}return[...Object.keys(e.properties),...(e.additionalFields??[])?.map(t=>t.key)]}function ei(e){return e}function ti(e){return e}function ri(e){return e}function ni(e){return e}function oi(e){return e}function li(e){return e}function ii(e){return e}function si(e){return e}function ai(e){return e}const ci="100vw",di="55vw",Jn="768px",qn=c.createContext({}),Qe=()=>c.useContext(qn),Zn=c.createContext({}),ie=()=>c.useContext(Zn),je=()=>c.useContext(Ar),Xn=c.createContext({}),Bt=()=>c.useContext(Xn),Kn=c.createContext({}),He=()=>c.useContext(Kn),Rn=c.createContext({}),ct=()=>c.useContext(Rn),Je=()=>{const{enqueueSnackbar:e,closeSnackbar:t}=yn.useSnackbar(),n=c.useCallback(l=>{const{type:i,message:s,autoHideDuration:a}=l;e({message:s,variant:i,autoHideDuration:a})},[]),o=c.useCallback(()=>{t()},[]);return c.useMemo(()=>({open:n,close:o}),[n,o])},eo=c.createContext(void 0),dt=()=>c.useContext(eo),to=c.createContext({}),Ai=({children:e})=>{const[t,n]=c.useState([]),o=c.useRef(t),l=a=>{o.current=a,n(a)},i=c.useCallback(()=>{if(t.length===0)return;const a=[...t.slice(0,-1)];l(a)},[t]),s=c.useCallback(a=>{const d=[...t,a];return l(d),{closeDialog:()=>{const A=o.current.filter(g=>g.key!==a.key);l(A)}}},[t]);return r.jsxs(to.Provider,{value:{open:s,close:i},children:[e,t.map((a,d)=>r.jsx(a.Component,{open:!0},`dialog_${d}`))]})},fi=()=>c.useContext(to),Nr=c.createContext({}),Z=()=>{const e=c.useContext(Nr),t=je(),n=Bt(),o=He(),l=ie(),i=Qe(),s=ct(),a=Je(),d=dt(),A=fi();return{...e,authController:t,sideDialogsController:n,sideEntityController:o,navigation:l,dataSource:i,storageSource:s,snackbarController:a,userConfigPersistence:d,dialogsController:A}};function ro({path:e,collection:t,filterValues:n,sortBy:o,itemCount:l,searchString:i}){const s=Qe(),d=ie().resolveAliasesFrom(e),A=o?o[0]:void 0,g=o?o[1]:void 0,p=Z(),[h,u]=c.useState([]),[m,b]=c.useState(!1),[y,w]=c.useState(),[C,E]=c.useState(!1);return c.useEffect(()=>{b(!0);const B=async x=>{if(t.callbacks?.onFetch)try{x=await Promise.all(x.map(k=>t.callbacks.onFetch({collection:t,path:d,entity:k,context:p})))}catch(k){console.error(k)}b(!1),w(void 0),u(x.map(k=>({...k}))),E(!l||x.length<l)},I=x=>{console.error("ERROR",x),b(!1),u([]),w(x)};return s.listenCollection?s.listenCollection({path:d,collection:t,onUpdate:B,onError:I,searchString:i,filter:n,limit:l,startAfter:void 0,orderBy:A,order:g}):(s.fetchCollection({path:d,collection:t,searchString:i,filter:n,limit:l,startAfter:void 0,orderBy:A,order:g}).then(B).catch(I),()=>{})},[d,l,g,A,n,i]),{data:h,dataLoading:m,dataLoadingError:y,noMoreToLoad:C}}const Pr={};function Qr({path:e,entityId:t,collection:n,useCache:o=!1}){const l=Qe(),s=ie().resolveAliasesFrom(e),a=Z(),[d,A]=c.useState(),[g,p]=c.useState(!0),[h,u]=c.useState();return c.useEffect(()=>{p(!0);const m=async y=>{if(n.callbacks?.onFetch&&y)try{y=await n.callbacks.onFetch({collection:n,path:s,entity:y,context:a})}catch(w){console.error(w)}Pr[`${s}/${t}`]=y,A(y),p(!1),u(void 0)},b=y=>{console.error("ERROR fetching entity",y),p(!1),A(void 0),u(y)};return t&&o&&Pr[`${s}/${t}`]?(A(Pr[`${s}/${t}`]),p(!1),u(void 0),()=>{}):t&&s&&n?l.listenEntity?l.listenEntity({path:s,entityId:t,collection:n,onUpdate:m,onError:b}):(l.fetchEntity({path:s,entityId:t,collection:n}).then(m).catch(b),()=>{}):(m(void 0),()=>{})},[t,s]),{entity:d,dataLoading:g,dataLoadingError:h}}async function Tr({collection:e,path:t,entityId:n,values:o,previousValues:l,status:i,dataSource:s,context:a,onSaveSuccess:d,onSaveFailure:A,onPreSaveHookError:g,onSaveSuccessHookError:p}){let h;const u=a.navigation.resolveAliasesFrom(t),m=e.callbacks;if(m?.onPreSave)try{const b=ke({collection:e,path:t,values:l,entityId:n,fields:a.propertyConfigs});h=await m.onPreSave({collection:b,path:t,resolvedPath:u,entityId:n,values:o,previousValues:l,status:i,context:a})}catch(b){console.error(b),g&&g(b);return}else h=o;return s.saveEntity({collection:e,path:u,entityId:n,values:h,previousValues:l,status:i}).then(b=>{try{if(m?.onSaveSuccess){const y=ke({collection:e,path:t,values:h,entityId:n,fields:a.propertyConfigs});m.onSaveSuccess({collection:y,path:t,resolvedPath:u,entityId:b.id,values:h,previousValues:l,status:i,context:a})}}catch(y){p&&p(y)}d&&d(b)}).catch(b=>{if(m?.onSaveFailure){const y=ke({collection:e,path:t,values:h,entityId:n,fields:a.propertyConfigs});m.onSaveFailure({collection:y,path:t,resolvedPath:u,entityId:n,values:h,previousValues:l,status:i,context:a})}A&&A(b)})}async function no({dataSource:e,entity:t,collection:n,callbacks:o,onDeleteSuccess:l,onDeleteFailure:i,onPreDeleteHookError:s,onDeleteSuccessHookError:a,context:d}){console.debug("Deleting entity",t.path,t.id);const A={entity:t,collection:n,entityId:t.id,path:t.path,context:d};if(o?.onPreDelete)try{await o.onPreDelete(A)}catch(g){return console.error(g),s&&s(t,g),!1}return e.deleteEntity({entity:t}).then(()=>{l&&l(t);try{return o?.onDelete&&o.onDelete(A),!0}catch(g){return a&&a(t,g),!1}}).catch(g=>(i&&i(t,g),!1))}function xe({property:e,value:t,setValue:n}){const o=c.useRef(null);c.useEffect(()=>{typeof e.disabled=="object"&&!!e.disabled.clearOnDisabled?t!=null&&(o.current=t,n(null)):o.current&&(n(o.current),o.current=null)},[e])}function oo({path:e,context:t}){const n=t.dataSource,o=t.navigation;if(!o)throw Error("Calling getNavigationFrom, but main navigation has not yet been initialised");const i=Cr({path:e,collections:o.collections??[]}).map(s=>{if(s.type==="collection")return Promise.resolve(s);if(s.type==="entity"){const a=o.getCollection(s.path,s.entityId);if(!a)throw Error(`No collection defined in the navigation for the entity with path ${s.path}`);return n.fetchEntity({path:s.path,entityId:s.entityId,collection:a}).then(d=>{if(d)return{...s,entity:d}})}else{if(s.type==="custom_view")return Promise.resolve(s);throw Error("Unmapped element in useEntitiesFromPath")}}).filter(s=>!!s);return Promise.all(i)}function ui({path:e}){const t=Z(),[n,o]=c.useState(),[l,i]=c.useState(!1),[s,a]=c.useState();return c.useEffect(()=>{t.navigation&&(i(!0),a(void 0),oo({path:e,context:t}).then(A=>{o(A)}).catch(A=>a(A)).finally(()=>i(!1)))},[e,t]),t.navigation?{data:n,dataLoading:l,dataLoadingError:s}:{dataLoading:!0}}const Mr=()=>c.useContext(Dt),lo=e=>{const{onSuccess:t,onError:n,disableClipboardAPI:o=!1,copiedDuration:l}=e||{},i=c.useRef(null),[s,a]=c.useState(!1),[d,A]=c.useState("");c.useEffect(()=>{l&&setTimeout(()=>a(!1),l)},[s]);const g=()=>navigator.clipboard!==void 0,p=c.useCallback(C=>{if(n)n(C);else throw new Error(C)},[n]),h=c.useCallback(C=>{t&&t(C),a(!0),A(C)},[t]),u=c.useCallback(C=>{navigator.clipboard.writeText(C).then(()=>h(C)).catch(E=>{p(E),a(!1)})},[p,h]),m=()=>{g()&&navigator.clipboard.writeText("")},b=C=>w("copy",typeof C=="object"?void 0:C),y=()=>w("cut"),w=c.useCallback((C="copy",E)=>{const B=i.current,I=B&&(B.tagName==="INPUT"||B.tagName==="TEXTAREA"),x=i.current;g()&&!o&&(E?u(E):B?I?(u(x.value),C==="cut"&&(x.value="")):u(B.innerText):p("Both the ref & text were undefined"))},[o,u,p]);return{ref:i,isCoppied:s,clipboard:d,clearClipboard:m,isSupported:g,copy:b,cut:y}},gi={xs:0,sm:640,md:768,lg:1024,xl:1280,"2xl":1536,"3xl":1920},Te=(e="lg")=>{const[t,n]=c.useState(!1);return c.useEffect(()=>{const o=()=>{const l=window.matchMedia(`(min-width: ${gi[e]+1}px)`).matches;n(l)};return o(),window.addEventListener("resize",o),()=>{window.removeEventListener("resize",o)}},[]),t};function io(e){return r.jsx(f.Tooltip,{...e,tooltipClassName:"!text-red-500 bg-red-50",children:e.children})}function pe({title:e,error:t,tooltip:n}){const o=t instanceof Error?t.message:t;console.log("ErrorView",t);const l=r.jsxs("div",{className:"flex items-center m-2",children:[r.jsx(f.ErrorIcon,{size:"small",color:"error"}),r.jsxs("div",{className:"pl-2",children:[e&&r.jsx(f.Typography,{variant:"body2",className:"font-medium",children:e}),r.jsx(f.Typography,{variant:"body2",children:o})]})]});return n?r.jsx(io,{title:n,children:l}):l}function At(){return r.jsx("div",{className:"rounded-full bg-gray-200 bg-opacity-30 dark:bg-opacity-20 w-5 h-2 inline-block"})}const hi=40,pi=100,mi=200;function ft(e){if(e==="tiny")return hi;if(e==="small")return pi;if(e==="medium")return mi;throw Error("Thumbnail size not mapped")}function qe(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 so({size:e,url:t}){const[n,o]=c.useState(!1),l=c.useMemo(()=>ft(e),[e]);if(e==="tiny")return r.jsx("img",{src:t,className:"rounded-md",style:{position:"relative",objectFit:"cover",width:l,height:l,maxHeight:"100%"}},"tiny_image_preview_"+t);const i={maxWidth:"100%",maxHeight:"100%"};return r.jsxs("div",{className:"relative flex items-center justify-center max-w-full max-h-full",style:{width:l,height:l},onMouseEnter:()=>o(!0),onMouseMove:()=>o(!0),onMouseLeave:()=>o(!1),children:[r.jsx("img",{src:t,className:"rounded-md",style:i}),n&&r.jsxs(r.Fragment,{children:[navigator&&r.jsx(f.Tooltip,{title:"Copy url to clipboard",children:r.jsx("div",{className:"rounded-full absolute bottom-[-4px] right-8",children:r.jsx(f.IconButton,{variant:"filled",size:"small",onClick:s=>(s.stopPropagation(),s.preventDefault(),navigator.clipboard.writeText(t)),children:r.jsx(f.ContentCopyIcon,{className:"text-gray-500",size:"small"})})})}),r.jsx(f.Tooltip,{title:"Open image in new tab",children:r.jsx(f.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(f.OpenInNewIcon,{className:"text-gray-500",size:"small"})})})]})]},"image_preview_"+t)}function kt({url:e,previewType:t,size:n,hint:o}){return t?t==="image"?r.jsx(so,{url:e,size:n}):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-${n==="small"?"sm":"md"}`,controls:!0,children:r.jsx("source",{src:e})}):r.jsxs("a",{href:e,rel:"noopener noreferrer",target:"_blank",onClick:l=>l.stopPropagation(),className:"flex flex-col items-center justify-center",style:{width:ft(n),height:ft(n)},children:[r.jsx(f.DescriptionIcon,{className:"flex-grow"}),o&&r.jsx(f.Tooltip,{title:o,children:r.jsx(f.Typography,{className:"max-w-full truncate rtl text-left",variant:"caption",children:o})})]}):!e||!e.trim()?r.jsx(At,{}):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:l=>{l.preventDefault()},target:"_blank",children:[r.jsx(f.OpenInNewIcon,{size:"small"}),e]})}function ut({property:e,size:t}){e||console.error("No property assigned for skeleton component",e,t);let n;if(e.dataType==="string"){const o=e;o.url?n=Ei(o,t):o.storage?n=Or(t):n=Ye()}else if(e.dataType==="array"){const o=e;o.of&&(Array.isArray(o.of)?n=r.jsxs(r.Fragment,{children:[o.of.map((l,i)=>Dr(l,i))," "]}):o.of.dataType==="map"&&o.of.properties?n=yi(o.of.properties,t,o.of.previewProperties):o.of.dataType==="string"?o.of.enumValues?n=wi():o.of.storage?n=Dr(o.of):n=vi():n=Dr(o.of))}else e.dataType==="map"?n=bi(e,t):e.dataType==="date"?n=Ye():e.dataType==="reference"?n=Ci():(e.dataType,n=Ye());return n||null}function bi(e,t){if(!e.properties)return r.jsx(r.Fragment,{});let n;return t==="medium"?n=Object.keys(e.properties):(n=e.previewProperties||Object.keys(e.properties),t==="small"?n=n.slice(0,3):t==="tiny"&&(n=n.slice(0,1))),t!=="medium"?r.jsx("div",{className:"w-full flex flex-col space-y-4",children:n.map((o,l)=>r.jsx("div",{children:e.properties&&e.properties[o]&&r.jsx(ut,{property:e.properties[o],size:"small"})},`map_${o}`))}):r.jsx("table",{className:"table-auto",children:r.jsx("tbody",{children:n&&n.map((o,l)=>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[o].name})},`table-cell-title--${o}`),r.jsx("th",{style:{width:"70%"},children:e.properties&&e.properties[o]&&r.jsx(ut,{property:e.properties[o],size:"small"})},`table-cell-${o}`)]},`map_preview_table__${l}`))})})}function yi(e,t,n){let o=n;return(!o||!o.length)&&(o=Object.keys(e),t&&(o=o.slice(0,3))),r.jsx("table",{className:"table-auto",children:r.jsx("tbody",{children:[0,1,2].map((l,i)=>r.jsx("tr",{children:o&&o.map(s=>r.jsx("th",{children:r.jsx(ut,{property:e[s],size:"small"})},`table-cell-${s}`))},`table_${l}_${i}`))})})}function vi(){return r.jsx("div",{className:"flex flex-col gap-2",children:[0,1].map((e,t)=>Ye(t))})}function wi(){return r.jsx("div",{className:"flex flex-col gap-2",children:[0,1].map((e,t)=>r.jsx(r.Fragment,{children:Ye(t)}))})}function Dr(e,t=0){return r.jsx("div",{className:"flex flex-col gap-2",children:[0,1].map((n,o)=>r.jsx(r.Fragment,{children:r.jsx(ut,{property:e,size:"small"},`i_${o}`)}))},"array_index_"+t)}function Or(e){const t=e==="tiny"?40:e==="small"?100:200;return r.jsx(f.Skeleton,{width:t,height:t})}function Ci(){return r.jsx(f.Skeleton,{width:200,height:100})}function Ei(e,t="medium"){return typeof e.url=="boolean"?r.jsxs("div",{style:{display:"flex"},children:[Vr(),Ye()]}):Bi(t)}function Bi(e){return r.jsx("div",{className:`w-${ft(e)} h-${ft(e)}`,children:Vr()})}function Ye(e,t=120){return r.jsx(f.Skeleton,{width:t},`skeleton_${e}`)}function ki(e){return r.jsx(f.Skeleton,{height:20})}function Vr(){return r.jsx(f.Skeleton,{width:24,height:24})}const ao=c.memo(Ao,xi);function xi(e,t){return e.size===t.size&&e.storagePathOrDownloadUrl===t.storagePathOrDownloadUrl&&e.storeUrl===t.storeUrl}const co={};function Ao({storeUrl:e,storagePathOrDownloadUrl:t,size:n}){const[o,l]=c.useState(void 0),i=ct(),[s,a]=c.useState(co[t]);if(c.useEffect(()=>{if(!t)return;let g=!1;return i.getDownloadURL(t).then(function(p){g||(a(p),co[t]=p)}).catch(l),()=>{g=!0}},[t]),!t)return null;const d=s?.metadata?Ii(s?.metadata.contentType):void 0,A=d?.startsWith("image")?"image":d?.startsWith("video")?"video":d?.startsWith("audio")?"audio":"file";return s?.fileNotFound?r.jsx(pe,{error:"File not found"}):s?.url?r.jsx(kt,{previewType:A,url:s.url,size:n,hint:t}):Or(n)}function Ii(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 we({enumValues:e,enumKey:t,size:n,className:o,children:l}){if(!e)return null;const i=_e(e),s=t!==void 0?$t(i,t):void 0,a=Qn(s),d=Pn(i,t);return r.jsxs(f.Chip,{className:o,colorScheme:d,error:!a,outlined:!1,size:n,children:[l,!l&&(a!==void 0?a:String(t))]})}function Gr({propertyKey:e,value:t,property:n,size:o}){if(n.enumValues){const l=t,i=vr(n);return r.jsx(we,{enumKey:l,enumValues:i.enumValues,size:o!=="medium"?"small":"medium"})}else if(n.previewAsTag){const l=Nn(e??"");return r.jsx(ne,{children:r.jsx(f.Chip,{colorScheme:l,size:o!=="medium"?"small":"medium",children:t})})}else{if(n.url)return r.jsx(kt,{size:o,url:t,previewType:typeof n.url=="string"?n.url:void 0});{if(!t)return r.jsx(r.Fragment,{});const l=t.split(`
1
+ (function(v,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("react/jsx-runtime"),require("react"),require("notistack"),require("object-hash"),require("formik"),require("@firecms/ui"),require("react-router-dom"),require("react-fast-compare"),require("date-fns"),require("date-fns/locale"),require("react-window"),require("react-use-measure"),require("@hello-pangea/dnd"),require("react-dropzone"),require("react-image-file-resizer"),require("markdown-it"),require("react-markdown-editor-lite"),require("yup"),require("react-datepicker"),require("js-search"),require("@radix-ui/react-portal")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","notistack","object-hash","formik","@firecms/ui","react-router-dom","react-fast-compare","date-fns","date-fns/locale","react-window","react-use-measure","@hello-pangea/dnd","react-dropzone","react-image-file-resizer","markdown-it","react-markdown-editor-lite","yup","react-datepicker","js-search","@radix-ui/react-portal"],r):(v=typeof globalThis<"u"?globalThis:v||self,r(v["FireCMS Core"]={},v.jsxRuntime,v.React,v.notistack,v.hash,v.formik,v.ui,v.reactRouterDom,v.equal,v.dateFns,v.locales,v.reactWindow,v.useMeasure,v.dnd,v.reactDropzone,v.Resizer,v.MarkdownIt,v.MdEditor,v.yup,v.reactDatepicker,v.JsSearch,v.Portal))})(this,function(v,r,d,yn,vn,Be,A,ue,ne,vl,wl,Cl,cr,lt,wn,El,Bl,et,kl,Cn,xl,Il){"use strict";function yt(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const o=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,o.get?o:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const dr=yt(d),En=yt(wl),ke=yt(kl),Sl=yt(xl),Fl=yt(Il),Nl=({children:e})=>r.jsx(yn.SnackbarProvider,{maxSnack:3,autoHideDuration:3500,children:e}),Pl={mode:"light",setMode:e=>{},toggleMode:()=>{}},Mt=d.createContext(Pl),Tl=Mt.Provider,Ar=d.createContext({});function Ql(e){return e.includes("-")||e.includes("_")||!e.includes(" ")?e.replace(/[-_]/g," ").replace(/\w\S*/g,function(n){return n.charAt(0).toUpperCase()+n.substr(1)}):e}function ge(e){return Bn(kn(e))}function Bn(e){return e.startsWith("/")?e.slice(1):e}function kn(e){return e.endsWith("/")?e.slice(0,-1):e}function Ml(e){return e.startsWith("/")?e:`/${e}`}function Dl(e){const t=ge(e);if(t.includes("/")){const n=t.split("/");return n[n.length-1]}return t}function fr(e,t){const n=ge(e),o=n.split("/");if(o.length%2===0)throw Error(`resolveCollectionPathAliases: Collection paths must have an odd number of segments: ${e}`);const l=t.find(s=>s.id===o[0]);let i;if(l&&(i=l.path),o.length>1){const s=Dt(i??o[0],t);if(!s?.subcollections)return n;const a=n.split("/").slice(2).join("/");return(i??o[0])+"/"+o[1]+"/"+fr(a,s.subcollections)}else return i??n}function Dt(e,t){const n=ge(e).split("/");if(n.length%2===0)throw Error(`getCollectionByPathOrAlias: Collection paths must have an odd number of segments: ${e}`);const o=Ot(n);let l;for(let i=0;i<o.length;i++){const s=o[i],a=t&&t.sort((c,f)=>(c.id??"").localeCompare(f.id??"")).find(c=>c.id===s||c.path===s);if(a){if(s===e)l=a;else if(a.subcollections){const c=e.replace(s,"").split("/").slice(2).join("/");c.length>0&&(l=Dt(c,a.subcollections))}}if(l)break}return l}function Ot(e){const t=e.length>0&&e.length%2===0?e.splice(0,e.length-1):e,n=t.length,o=[];for(let l=n;l>0;l=l-2)o.push(t.slice(0,l).join("/"));return o}class Fe{id;path;constructor(t,n){this.id=t,this.path=n}get pathWithId(){return`${this.path}/${this.id}`}}class Vt{latitude;longitude;constructor(t,n){this.latitude=t,this.longitude=n}}const xn=(e,...t)=>({...t.reduce((n,o)=>({...n,[o]:e[o]}),{})});function Gt(e){return e&&typeof e=="object"&&!Array.isArray(e)}function Ne(e,t){const n=Gt(e),o=n?{...e}:e;return n&&Gt(t)&&Object.keys(t).forEach(l=>{Gt(t[l])?l in e?o[l]=Ne(e[l],t[l]):Object.assign(o,{[l]:t[l]}):Object.assign(o,{[l]:t[l]})}),o}function $e(e,t){if(e&&typeof e=="object"){if(t in e)return e[t];if(t.includes(".")||t.includes("[")){let n=t.split(/[.[]/);t.includes("[")&&(n=n.map(a=>a.replace("]","")));const o=n[0],l=Array.isArray(e[o])&&!isNaN(parseInt(n[1])),i=l?e[o][parseInt(n[1])]:e[o],s=n.slice(l?2:1).join(".");return s===""?i:$e(i,s)}}}function Ol(e,t){let n={...e};const o=t.split("."),l=o.pop();for(const i of o)n=n[i];return l&&delete n[l],n}function ur(e){if(e!==void 0)return e===null?null:typeof e=="object"?Object.entries(e).filter(([t,n])=>typeof n!="function").map(([t,n])=>Array.isArray(n)?{[t]:n.map(o=>ur(o))}:typeof n=="object"?{[t]:ur(n)}:{[t]:n}).reduce((t,n)=>({...t,...n}),{}):e}function gr(e){if(!e)return null;if(typeof e=="object"){if("id"in e)return e.id;if(e instanceof Date)return e.toLocaleString();if(e instanceof Vt)return vn(e)}return vn(e,{ignoreUnknown:!0})}function hr(e,t){if(typeof e=="function")return e;if(Array.isArray(e))return e.map(n=>hr(n,t));if(typeof e=="object"){const n={};return e===null?e:(Object.keys(e).forEach(o=>{if(!pr(e)){const l=hr(e[o],t),i=typeof l=="string",s=!t||t&&!i||t&&i&&l!=="";l!==void 0&&!pr(l)&&s&&(n[o]=l)}}),n)}return e}function pr(e){return e&&Object.getPrototypeOf(e)===Object.prototype&&Object.keys(e).length===0}function In(e,t){const n=i=>typeof i=="object"&&i!==null,o=i=>Array.isArray(i);if(!n(e)||!n(t))return e;const l=o(e)?[...e]:{...e};return Object.keys(t).forEach(i=>{i in l&&(n(l[i])&&n(t[i])?l[i]=In(l[i],t[i]):l[i]===t[i]&&(o(l)?l.splice(i,1):delete l[i]))}),l}const vt="type",Yt="value";function it(e){return e.readOnly||e.dataType==="date"&&e.autoValue?!0:e.dataType==="reference"?!e.path:!1}function wt(e){return typeof e.disabled=="object"&&!!e.disabled.hidden}function we(e){return typeof e=="function"}function Ct(e){return e?Object.entries(e).map(([t,n])=>{const o=zt(n);return o===void 0?{}:{[t]:o}}).reduce((t,n)=>({...t,...n}),{}):{}}function zt(e){if(!we(e))if(e.dataType==="map"&&e.properties){const t=Ct(e.properties);return Object.keys(t).length===0?void 0:t}else return e.defaultValue?e.defaultValue:mr(e.dataType)}function mr(e){return e==="string"||e==="number"?null:e==="boolean"?!1:e==="date"?null:e==="array"?[]:e==="map"?{}:null}function Sn({inputValues:e,properties:t,status:n,timestampNowValue:o,setDateToMidnight:l}){return br(e,t,(i,s)=>{if(s.dataType==="date"){let a;return n==="existing"&&s.autoValue==="on_update"||(n==="new"||n==="copy")&&(s.autoValue==="on_update"||s.autoValue==="on_create")?a=o:a=i,s.mode==="date"&&(a=l(a)),a}else return i})??{}}function Vl(e,t){const n=e;return Object.entries(t).forEach(([o,l])=>{e&&e[o]!==void 0?n[o]=e[o]:l.validation?.required&&(n[o]=null)}),n}function Ge(e){return new Fe(e.id,e.path)}function br(e,t,n){const o=Object.entries(t).map(([i,s])=>{const a=e&&e[i],c=Ut(a,s,n);if(c!==void 0)return{[i]:c}}).reduce((i,s)=>({...i,...s}),{}),l={...e,...o};if(Object.keys(l).length!==0)return l}function Ut(e,t,n){let o;if(t.dataType==="map"&&t.properties)o=br(e,t.properties,n);else if(t.dataType==="array")if(t.of&&Array.isArray(e))o=e.map(l=>Ut(l,t.of,n));else if(t.oneOf&&Array.isArray(e)){const l=t.oneOf?.typeField??vt,i=t.oneOf?.valueField??Yt;o=e.map(s=>{if(s===null)return null;if(typeof s!="object")return s;const a=s[l],c=t.oneOf?.properties[a];return!a||!c?s:{[l]:a,[i]:Ut(s[i],c,n)}})}else o=e;else o=n(e,t);return o}function Fn(e){let t=0,n,o;for(n=0;n<e.length;n++)o=e.charCodeAt(n),t=(t<<5)-t+o,t|=0;return Math.abs(t)}function Nn(e){const t=Fn(e),n=Object.keys(A.CHIP_COLORS),o=t%n.length;return A.CHIP_COLORS[n[o]]}function _e(e){return Array.isArray(e)?e:Object.entries(e).map(([t,n])=>typeof n=="string"?{id:t,label:n}:{...n,id:t})}function Lt(e,t){if(t)return e.find(n=>String(n.id)===String(t))}function Pn(e,t){const n=Lt(e,t);if(!n?.color)return Nn(t.toString());if(typeof n=="object"&&"color"in n){if(typeof n.color=="string")return A.CHIP_COLORS[n.color];if(typeof n.color=="object")return n.color}}function Gl(e){return typeof e=="object"&&e.disabled}function Tn(e){if(e!==void 0)return typeof e=="object"?e.label:e}const Ie=({collection:e,path:t,entityId:n,values:o,previousValues:l,userConfigPersistence:i,fields:s})=>{const a=i?.getCollectionConfig(t),c=$e(a,"properties"),f=Ct(e.properties),g=o??f,p=l??o??f,h=Object.entries(e.properties).map(([b,y])=>{const C=g?Be.getIn(g,b):void 0,w=xe({propertyKey:b,propertyOrBuilder:y,values:g,previousValues:p,path:t,propertyValue:C,entityId:n,fields:s});return w?{[b]:w}:{}}).filter(b=>b!==null).reduce((b,y)=>({...b,...y}),{}),u=Ne(h,c),m=Object.entries(u).filter(([b,y])=>!!y?.dataType).map(([b,y])=>({[b]:y})).reduce((b,y)=>({...b,...y}),{});return{...e,properties:m,originalCollection:e}};function xe({propertyOrBuilder:e,propertyValue:t,fromBuilder:n=!1,...o}){if(typeof e=="object"&&"resolved"in e)return e;let l=null;if(e)if(we(e)){const i=o.path;if(!i)throw Error("Trying to resolve a property builder without specifying the entity path");const s=e({...o,path:i,propertyValue:t,values:o.values??{},previousValues:o.previousValues??o.values??{}});if(!s)return null;l=xe({...o,propertyValue:t,propertyOrBuilder:s,fromBuilder:!0})}else{const i=e;if(i.dataType==="map"&&i.properties){const s=yr({...o,properties:i.properties,propertyValue:t});l={...i,resolved:!0,fromBuilder:n,properties:s}}else i.dataType==="array"?l=We({property:i,propertyValue:t,fromBuilder:n,...o}):(i.dataType==="string"||i.dataType==="number")&&i.enumValues&&(l=vr(i,n))}else return null;if(l||(l={...e,resolved:!0,fromBuilder:n}),l.propertyConfig&&!pl(l.propertyConfig)){const i=o.fields;if(!i)throw Error(`Trying to resolve a property with key ${l.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=i[l.propertyConfig];if(!s)return console.warn(`Trying to resolve a property with key ${l.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",i),null;if(s.property){const a=s.property;"propertyConfig"in a&&delete a.propertyConfig;const c=xe({propertyOrBuilder:a,propertyValue:t,...o});c&&(l=Ne(c,l))}}return l?{...l,resolved:!0}:null}function We({propertyKey:e,property:t,propertyValue:n,...o}){if(t.of){if(Array.isArray(t.of))return{...t,resolved:!0,fromBuilder:o.fromBuilder,resolvedProperties:t.of.map((l,i)=>xe({propertyKey:`${e}.${i}`,propertyOrBuilder:l,propertyValue:Array.isArray(n)?n[i]:void 0,...o,index:i}))};{const l=t.of,i=Array.isArray(n)?n.map((a,c)=>xe({propertyKey:`${e}.${c}`,propertyOrBuilder:l,propertyValue:a,...o,index:c})).filter(a=>!!a):[],s=xe({propertyKey:`${e}`,propertyOrBuilder:l,propertyValue:void 0,...o});if(!s)throw Error("When using a property builder as the 'of' prop of an ArrayProperty, you must return a valid child property");return{...t,resolved:!0,fromBuilder:o.fromBuilder,of:s,resolvedProperties:i}}}else if(t.oneOf){const l=t.oneOf?.typeField??vt,i=Array.isArray(n)?n.map((a,c)=>{const f=a&&a[l],g=t.oneOf?.properties[f];return!f||!g?null:xe({propertyKey:`${e}.${c}`,propertyOrBuilder:g,propertyValue:n,...o})}).filter(a=>!!a):[],s=yr({properties:t.oneOf.properties,propertyValue:void 0,...o});return{...t,resolved:!0,oneOf:{...t.oneOf,properties:s},fromBuilder:o.fromBuilder,resolvedProperties:i}}else{if(t.Field)return{...t,resolved:!0,fromBuilder:o.fromBuilder};throw Error("The array property needs to declare an 'of' or a 'oneOf' property, or provide a custom `Field`")}}function yr({properties:e,propertyValue:t,...n}){return Object.entries(e).map(([o,l])=>{const i=t&&typeof t=="object"?$e(t,o):void 0,s=xe({propertyKey:o,propertyOrBuilder:l,propertyValue:i,...n});return s?{[o]:s}:{}}).filter(o=>o!==null).reduce((o,l)=>({...o,...l}),{})}function vr(e,t){return typeof e.enumValues=="object"?{...e,resolved:!0,enumValues:_e(e.enumValues)?.filter(n=>n&&n.id&&n.label)??[],fromBuilder:t??!1}:e}function Yl(e){return typeof e=="object"?Object.entries(e).map(([t,n])=>typeof n=="string"?{id:t,label:n}:n):Array.isArray(e)?e:void 0}function wr(e,t){return typeof e=="string"?t?.find(n=>n.key===e):e}function Cr(e){const{path:t,collections:n=[],currentFullPath:o}=e,l=ge(t).split("/"),i=Ot(l),s=[];for(let a=0;a<i.length;a++){const c=i[a],f=n&&n.find(g=>g.id===c||g.path===c);if(f){const g=f.id??f.path,p=o&&o.length>0?o+"/"+g:g;s.push({type:"collection",path:p,collection:f});const h=ge(ge(t).replace(c,"")),u=h.length>0?h.split("/"):[];if(u.length>0){const m=u[0],b=p+"/"+m;if(s.push({type:"entity",entityId:m,path:p,parentCollection:f}),u.length>1){const y=u.slice(1).join("/");if(!f)throw Error("collection not found resolving path: "+f);const C=f.entityViews,w=C&&C.map(E=>wr(E,e.contextEntityViews)).filter(Boolean).find(E=>E.key===y);if(w){const E=o&&o.length>0?o+"/"+w.key:w.key;s.push({type:"custom_view",path:E,view:w})}else f.subcollections&&s.push(...Cr({path:y,collections:f.subcollections,currentFullPath:b,contextEntityViews:e.contextEntityViews}))}}break}}return s}function Er(e,t){try{const n=Object.keys(e);return(t??n).map(l=>{if(e[l]){const i=e[l];return!we(i)&&i?.dataType==="map"&&i.properties?{[l]:{...i,properties:Er(i.properties,i.propertiesOrder)}}:{[l]:i}}else return}).filter(l=>l!==void 0).reduce((l,i)=>({...l,...i}),{})}catch(n){return console.error("Error sorting properties",n),e}}function Br(e,t){if(e)return typeof e=="string"?e:e(t)}const zl=/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g,Ul=e=>{const t=e.match(zl);return t?t.map(n=>n.toLowerCase()).join("-"):""},Ll=/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g,$l=e=>{const t=e.match(Ll);return t?t.map(n=>n.toLowerCase()).join("_"):""};function st(e=5){return Math.random().toString(36).slice(2,2+e)}function _l(){return Math.floor(Math.random()*16777215).toString(16)}function $t(e,t="_",n=!0){if(!e)return"";const o="ãàáäâẽèéëêìíïîõòóöôùúüûñç·/_,:;-",l=`aaaaaeeeeeiiiiooooouuuunc${t}${t}${t}${t}${t}${t}${t}`;for(let i=0,s=o.length;i<s;i++)e=e.replace(new RegExp(o.charAt(i),"g"),l.charAt(i));return e=e.toString().replace(/\s+/g,t).replace(/&/g,t).replace(/[^\w\\-]+/g,"").replace(new RegExp("\\"+t+"\\"+t+"+","g"),t).trim().replace(/^\s+|\s+$/g,""),n?e.toLowerCase():e}const Qn="MMMM dd, yyyy, HH:mm:ss",Mn="::";function kr(e){return Dn(Pe(e))}function Dn(e){return e.length===1?e[0]:e.reduce((t,n)=>`${t}${Mn}${n}`)}function Pe(e){return e.split("/").filter((t,n)=>n%2===0)}function Wl(e){return e?e.toString():""}function On(e){if(!e)return;const t=e.match(/\/(.*?)\/([a-z]*)?$/i);return t?new RegExp(t[1],t[2]||""):new RegExp(e,"")}function jl(e){return e.match(/\/((?![*+?])(?:[^\r\n[/\\]|\\.|\[(?:[^\r\n\]\\]|\\.)*])+)\/((?:g(?:im?|mi?)?|i(?:gm?|mg?)?|m(?:gi?|ig?)?)?)/)?!0:!!e.match(/((?![*+?])(?:[^\r\n[/\\]|\\.|\[(?:[^\r\n\]\\]|\\.)*])+)/)}function _t(e,t,n,o=300){const l=d.useRef(!1),i=()=>{t(),l.current=!1},s=d.useRef(void 0);d.useEffect(()=>(l.current=!0,clearTimeout(s.current),s.current=setTimeout(i,o),()=>{n&&i()}),[n,e])}function Hl(e,t=300){const[n,o]=d.useState(e);return d.useEffect(()=>{const l=setTimeout(()=>{o(e)},t);return()=>{clearTimeout(l)}},[e,t]),n}function Vn(e,t){const n=xe({propertyKey:"ignore",propertyOrBuilder:e,fields:t});return n?n.dataType==="reference"?!0:n.dataType==="array"?Array.isArray(n.of)?!1:n.of?.dataType==="reference":!1:null}function Jl(e){return r.jsx(A.CircleIcon,{size:e})}function Wt(e,t){const n=e?.Icon??A.CircleIcon;return r.jsx(n,{size:t})}function pe(e,t="small",n={}){if(we(e))return r.jsx(A.FunctionsIcon,{size:t});{const o=sr(e,n);return Wt(o,t)}}function ql(e,t){return we(e)?"#888":sr(e,t)?.color??"#666"}function tt(e,t){if(typeof e=="object"){if(t in e)return e[t];if(t.includes(".")){const n=t.split("."),o=e[n[0]];if(typeof o=="object"&&o.dataType==="map"&&o.properties)return tt(o.properties,n.slice(1).join("."))}}}function xr(e,t){if(typeof e=="object"){if(t in e)return e[t];if(t.includes(".")){const n=t.split("."),o=e[n[0]];if(o.dataType==="map"&&o.properties)return xr(o.properties,n.slice(1).join("."))}}}function Zl(e){return e.replace(/\.([^.]*)/g,"[$1]")}function Gn(e,t){if(!t)return e;const n={};return t.filter(Boolean).forEach(o=>{const l=tt(e,o);typeof l=="object"&&l.dataType==="map"&&l.properties&&(n[o]={...l,properties:Gn(l.properties,l.propertiesOrder??[])}),l&&(n[o]=l)}),n}function Xl(e){return e.propertiesOrder?e.propertiesOrder:[...Object.keys(e.properties),...(e.additionalFields??[]).map(t=>t.key)]}const jt={read:!0,edit:!0,create:!0,delete:!0};function Et(e,t,n,o){const l=e.permissions;if(l===void 0)return jt;if(typeof l=="object")return l;if(typeof l=="function")return l({entity:o,user:t.user,authController:t,collection:e,pathSegments:n});throw console.error("Permissions:",l),Error("New type of permission added and not mapped")}function Ir(e,t,n,o){return Et(e,t,n,o).edit??jt.edit}function at(e,t,n,o){return Et(e,t,n,o).create??jt.create}function Ht(e,t,n,o){return Et(e,t,n,o).delete??jt.delete}function Yn(e,t){if(e&&(e=$t(e),e in qt))return e in qt?r.jsx(A.Icon,{iconKey:e,size:"medium",className:t}):void 0}function Jt(e,t){const n=Yn(e.icon,t);if(e?.icon&&n)return n;let o=$t(("singularName"in e?e.singularName:void 0)??e.name),l;o in qt&&(l=o),l||(o=$t(e.path),o in qt&&(l=o));const i=A.coolIconKeys.length;return l||(l=A.coolIconKeys[Fn(e.path)%i]),r.jsx(A.Icon,{iconKey:l,size:"medium",className:t})}const qt=A.iconKeys.reduce((e,t)=>(e[t]=t,e),{});function Kl(e,t){if(t!==void 0&&t===1)return e;const n={"(quiz)$":"$1zes","^(ox)$":"$1en","([m|l])ouse$":"$1ice","(matr|vert|ind)ix|ex$":"$1ices","(x|ch|ss|sh)$":"$1es","([^aeiouy]|qu)y$":"$1ies","(hive)$":"$1s","(?:([^f])fe|([lr])f)$":"$1$2ves","(shea|lea|loa|thie)f$":"$1ves",sis$:"ses","([ti])um$":"$1a","(tomat|potat|ech|her|vet)o$":"$1oes","(bu)s$":"$1ses","(alias)$":"$1es","(octop)us$":"$1i","(ax|test)is$":"$1es","(us)$":"$1es","([^s]+)$":"$1s"},o={move:"moves",foot:"feet",goose:"geese",sex:"sexes",child:"children",man:"men",tooth:"teeth",person:"people"};if(["sheep","fish","deer","moose","series","species","money","rice","information","equipment","bison","cod","offspring","pike","salmon","shrimp","swine","trout","aircraft","hovercraft","spacecraft","sugar","tuna","you","wood"].indexOf(e.toLowerCase())>=0)return e;for(const i in o){const s=new RegExp(`${i}$`,"i"),a=o[i];if(s.test(e))return e.replace(s,a)}for(const i in n){const s=new RegExp(i,"i");if(s.test(e))return e.replace(s,n[i])}return e}function Rl(e,t){if(t!==void 0&&t!==1)return e;const n={"(quiz)zes$":"$1","(matr)ices$":"$1ix","(vert|ind)ices$":"$1ex","^(ox)en$":"$1","(alias)es$":"$1","(octop|vir)i$":"$1us","(cris|ax|test)es$":"$1is","(shoe)s$":"$1","(o)es$":"$1","(bus)es$":"$1","([m|l])ice$":"$1ouse","(x|ch|ss|sh)es$":"$1","(m)ovies$":"$1ovie","(s)eries$":"$1eries","([^aeiouy]|qu)ies$":"$1y","([lr])ves$":"$1f","(tive)s$":"$1","(hive)s$":"$1","(li|wi|kni)ves$":"$1fe","(shea|loa|lea|thie)ves$":"$1f","(^analy)ses$":"$1sis","((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$":"$1$2sis","([ti])a$":"$1um","(n)ews$":"$1ews","(h|bl)ouses$":"$1ouse","(corpse)s$":"$1","(us)es$":"$1",s$:""},o={move:"moves",foot:"feet",goose:"geese",sex:"sexes",child:"children",man:"men",tooth:"teeth",person:"people"};if(["sheep","fish","deer","moose","series","species","money","rice","information","equipment","bison","cod","offspring","pike","salmon","shrimp","swine","trout","aircraft","hovercraft","spacecraft","sugar","tuna","you","wood"].indexOf(e.toLowerCase())>=0)return e;for(const i in o){const s=new RegExp(`${o[i]}$`,"i");if(s.test(e))return e.replace(s,i)}for(const i in n){const s=new RegExp(i,"i");if(s.test(e))return e.replace(s,n[i])}return e}function zn(e,t,n,o=3){const l=Object.keys(e.properties);let i=n?.filter(s=>l.includes(s));return i&&i.length>0?i:(i=l,i.filter(s=>{const a=e.properties[s];return a&&!we(a)&&!Vn(a,t)}).slice(0,o))}function Sr(e,t=""){return e&&Object.keys(e).reduce((n,o)=>{const l=t?`${t}.${o}`:o;return typeof e[o]=="object"&&e[o]!==null?Array.isArray(e[o])?e[o].forEach((i,s)=>{Object.assign(n,Sr(i,`${l}[${s}]`))}):Object.assign(n,Sr(e[o],l)):n[l]=e[o],n},{})}function Un(e){return e.reduce((t,n)=>(Object.entries(n).forEach(([o,l])=>{if(Array.isArray(l)&&(t[o]=Math.max(t[o]||0,l.length)),typeof l=="object"&&l!==null){const i=Un([l]);Object.entries(i).forEach(([s,a])=>{const c=`${o}.${s}`;t[c]=Math.max(t[c]||0,a)})}}),t),{})}function Ln(e){return Object.keys(e).forEach(t=>{const n=e[t];n.editable=!0,n.dataType==="map"&&n.properties&&Ln(n.properties)}),e}function $n(e){return Object.entries(e).reduce((t,[n,o])=>{if(!we(o)&&o.dataType==="map"&&o.properties){const l={...o,properties:$n(o.properties)};t[n]=l}return we(o)?t[n]=o:t[n]={...o,editable:!1},t},{})}function Fr(e,t,n){if(e){const l=e({collection:t,parentPaths:n})??t;return l.subcollections&&(l.subcollections=l.subcollections.map(i=>Fr(e,i,[...n,t.path]))),l}else return t}function _n(e,t,n=[],o){const l=(t??[]).map(a=>{const c=e?.find(f=>f.id===a.id);return c?Wn(c,a,n,o):Fr(o,a,n)}),i=l.map(a=>a.id),s=e.filter(a=>!i.includes(a.id)).map(a=>o?Fr(o,a,n):a);return[...l,...s]}function Wn(e,t,n=[],o){const l=_n(e?.subcollections??[],t?.subcollections??[],[...n,e.path],o),i={...e.properties};Object.keys(t.properties).forEach(h=>{const u=e.properties[h];u?i[h]=jn(u,t.properties[h]):i[h]=t.properties[h]});const s=Ne(e,t),a=Hn(e),c=Hn(t),f=[...new Set([...c,...a])],g=[...new Set([...e.entityViews??[],...t.entityViews??[]])];let p={...s,subcollections:l,properties:Er(i,f),propertiesOrder:f,entityViews:g};if(o){const h=o({collection:p,parentPaths:n});h&&(p=h)}return p}function jn(e,t){if(we(t))return t;{const n=Ne(e,t),o=!!e.editable,l=!!t.editable;if(t.dataType==="map"&&t.properties){const i="properties"in e?e.properties:{},s="properties"in t?t.properties:{},a="propertiesOrder"in e&&e.propertiesOrder?e.propertiesOrder:Object.keys(i),c="propertiesOrder"in t&&t.propertiesOrder?t.propertiesOrder:"properties"in t?Object.keys(t.properties):[],f=[...new Set([...a,...c])],g={...i};return Object.keys(t.properties).forEach(p=>{const h=i[p];h&&(g[p]=jn(h,s[p]))}),{...n,editable:o&&l,properties:g,propertiesOrder:f}}return{...n,editable:o&&l}}}function Hn(e){if(e.propertiesOrder&&e.propertiesOrder.length>0){const t=e.propertiesOrder;return e.additionalFields&&e.additionalFields.forEach(n=>{t.includes(n.key)||t.push(n.key)}),t}return[...Object.keys(e.properties),...(e.additionalFields??[])?.map(t=>t.key)]}function ei(e){return e}function ti(e){return e}function ri(e){return e}function ni(e){return e}function oi(e){return e}function li(e){return e}function ii(e){return e}function si(e){return e}function ai(e){return e}const ci="100vw",di="55vw",Jn="768px",qn=d.createContext({}),Te=()=>d.useContext(qn),Zn=d.createContext({}),ie=()=>d.useContext(Zn),je=()=>d.useContext(Ar),Xn=d.createContext({}),Bt=()=>d.useContext(Xn),Kn=d.createContext({}),He=()=>d.useContext(Kn),Rn=d.createContext({}),ct=()=>d.useContext(Rn),Je=()=>{const{enqueueSnackbar:e,closeSnackbar:t}=yn.useSnackbar(),n=d.useCallback(l=>{const{type:i,message:s,autoHideDuration:a}=l;e({message:s,variant:i,autoHideDuration:a})},[]),o=d.useCallback(()=>{t()},[]);return d.useMemo(()=>({open:n,close:o}),[n,o])},eo=d.createContext(void 0),dt=()=>d.useContext(eo),to=d.createContext({}),Ai=({children:e})=>{const[t,n]=d.useState([]),o=d.useRef(t),l=a=>{o.current=a,n(a)},i=d.useCallback(()=>{if(t.length===0)return;const a=[...t.slice(0,-1)];l(a)},[t]),s=d.useCallback(a=>{const c=[...t,a];return l(c),{closeDialog:()=>{const f=o.current.filter(g=>g.key!==a.key);l(f)}}},[t]);return r.jsxs(to.Provider,{value:{open:s,close:i},children:[e,t.map((a,c)=>r.jsx(a.Component,{open:!0},`dialog_${c}`))]})},fi=()=>d.useContext(to),Nr=d.createContext({}),q=()=>{const e=d.useContext(Nr),t=je(),n=Bt(),o=He(),l=ie(),i=Te(),s=ct(),a=Je(),c=dt(),f=fi();return{...e,authController:t,sideDialogsController:n,sideEntityController:o,navigation:l,dataSource:i,storageSource:s,snackbarController:a,userConfigPersistence:c,dialogsController:f}};function ro({path:e,collection:t,filterValues:n,sortBy:o,itemCount:l,searchString:i}){const s=Te(),c=ie().resolveAliasesFrom(e),f=o?o[0]:void 0,g=o?o[1]:void 0,p=q(),[h,u]=d.useState([]),[m,b]=d.useState(!1),[y,C]=d.useState(),[w,E]=d.useState(!1);return d.useEffect(()=>{b(!0);const k=async I=>{if(t.callbacks?.onFetch)try{I=await Promise.all(I.map(B=>t.callbacks.onFetch({collection:t,path:c,entity:B,context:p})))}catch(B){console.error(B)}b(!1),C(void 0),u(I.map(B=>({...B}))),E(!l||I.length<l)},x=I=>{console.error("ERROR",I),b(!1),u([]),C(I)};return s.listenCollection?s.listenCollection({path:c,collection:t,onUpdate:k,onError:x,searchString:i,filter:n,limit:l,startAfter:void 0,orderBy:f,order:g}):(s.fetchCollection({path:c,collection:t,searchString:i,filter:n,limit:l,startAfter:void 0,orderBy:f,order:g}).then(k).catch(x),()=>{})},[c,l,g,f,n,i]),{data:h,dataLoading:m,dataLoadingError:y,noMoreToLoad:w}}const Pr={};function Tr({path:e,entityId:t,collection:n,useCache:o=!1}){const l=Te(),s=ie().resolveAliasesFrom(e),a=q(),[c,f]=d.useState(),[g,p]=d.useState(!0),[h,u]=d.useState();return d.useEffect(()=>{p(!0);const m=async y=>{if(n.callbacks?.onFetch&&y)try{y=await n.callbacks.onFetch({collection:n,path:s,entity:y,context:a})}catch(C){console.error(C)}Pr[`${s}/${t}`]=y,f(y),p(!1),u(void 0)},b=y=>{console.error("ERROR fetching entity",y),p(!1),f(void 0),u(y)};return t&&o&&Pr[`${s}/${t}`]?(f(Pr[`${s}/${t}`]),p(!1),u(void 0),()=>{}):t&&s&&n?l.listenEntity?l.listenEntity({path:s,entityId:t,collection:n,onUpdate:m,onError:b}):(l.fetchEntity({path:s,entityId:t,collection:n}).then(m).catch(b),()=>{}):(m(void 0),()=>{})},[t,s]),{entity:c,dataLoading:g,dataLoadingError:h}}async function Qr({collection:e,path:t,entityId:n,values:o,previousValues:l,status:i,dataSource:s,context:a,onSaveSuccess:c,onSaveFailure:f,onPreSaveHookError:g,onSaveSuccessHookError:p}){let h;const u=a.navigation.resolveAliasesFrom(t),m=e.callbacks;if(m?.onPreSave)try{const b=Ie({collection:e,path:t,values:l,entityId:n,fields:a.propertyConfigs});h=await m.onPreSave({collection:b,path:t,resolvedPath:u,entityId:n,values:o,previousValues:l,status:i,context:a})}catch(b){console.error(b),g&&g(b);return}else h=o;return s.saveEntity({collection:e,path:u,entityId:n,values:h,previousValues:l,status:i}).then(b=>{try{if(m?.onSaveSuccess){const y=Ie({collection:e,path:t,values:h,entityId:n,fields:a.propertyConfigs});m.onSaveSuccess({collection:y,path:t,resolvedPath:u,entityId:b.id,values:h,previousValues:l,status:i,context:a})}}catch(y){p&&p(y)}c&&c(b)}).catch(b=>{if(m?.onSaveFailure){const y=Ie({collection:e,path:t,values:h,entityId:n,fields:a.propertyConfigs});m.onSaveFailure({collection:y,path:t,resolvedPath:u,entityId:n,values:h,previousValues:l,status:i,context:a})}f&&f(b)})}async function no({dataSource:e,entity:t,collection:n,callbacks:o,onDeleteSuccess:l,onDeleteFailure:i,onPreDeleteHookError:s,onDeleteSuccessHookError:a,context:c}){console.debug("Deleting entity",t.path,t.id);const f={entity:t,collection:n,entityId:t.id,path:t.path,context:c};if(o?.onPreDelete)try{await o.onPreDelete(f)}catch(g){return console.error(g),s&&s(t,g),!1}return e.deleteEntity({entity:t}).then(()=>{l&&l(t);try{return o?.onDelete&&o.onDelete(f),!0}catch(g){return a&&a(t,g),!1}}).catch(g=>(i&&i(t,g),!1))}function Se({property:e,value:t,setValue:n}){const o=d.useRef(null);d.useEffect(()=>{typeof e.disabled=="object"&&!!e.disabled.clearOnDisabled?t!=null&&(o.current=t,n(null)):o.current&&(n(o.current),o.current=null)},[e])}function oo({path:e,context:t}){const n=t.dataSource,o=t.navigation;if(!o)throw Error("Calling getNavigationFrom, but main navigation has not yet been initialised");const i=Cr({path:e,collections:o.collections??[]}).map(s=>{if(s.type==="collection")return Promise.resolve(s);if(s.type==="entity"){const a=o.getCollection(s.path,s.entityId);if(!a)throw Error(`No collection defined in the navigation for the entity with path ${s.path}`);return n.fetchEntity({path:s.path,entityId:s.entityId,collection:a}).then(c=>{if(c)return{...s,entity:c}})}else{if(s.type==="custom_view")return Promise.resolve(s);throw Error("Unmapped element in useEntitiesFromPath")}}).filter(s=>!!s);return Promise.all(i)}function ui({path:e}){const t=q(),[n,o]=d.useState(),[l,i]=d.useState(!1),[s,a]=d.useState();return d.useEffect(()=>{t.navigation&&(i(!0),a(void 0),oo({path:e,context:t}).then(f=>{o(f)}).catch(f=>a(f)).finally(()=>i(!1)))},[e,t]),t.navigation?{data:n,dataLoading:l,dataLoadingError:s}:{dataLoading:!0}}const Mr=()=>d.useContext(Mt),lo=e=>{const{onSuccess:t,onError:n,disableClipboardAPI:o=!1,copiedDuration:l}=e||{},i=d.useRef(null),[s,a]=d.useState(!1),[c,f]=d.useState("");d.useEffect(()=>{l&&setTimeout(()=>a(!1),l)},[s]);const g=()=>navigator.clipboard!==void 0,p=d.useCallback(w=>{if(n)n(w);else throw new Error(w)},[n]),h=d.useCallback(w=>{t&&t(w),a(!0),f(w)},[t]),u=d.useCallback(w=>{navigator.clipboard.writeText(w).then(()=>h(w)).catch(E=>{p(E),a(!1)})},[p,h]),m=()=>{g()&&navigator.clipboard.writeText("")},b=w=>C("copy",typeof w=="object"?void 0:w),y=()=>C("cut"),C=d.useCallback((w="copy",E)=>{const k=i.current,x=k&&(k.tagName==="INPUT"||k.tagName==="TEXTAREA"),I=i.current;g()&&!o&&(E?u(E):k?x?(u(I.value),w==="cut"&&(I.value="")):u(k.innerText):p("Both the ref & text were undefined"))},[o,u,p]);return{ref:i,isCoppied:s,clipboard:c,clearClipboard:m,isSupported:g,copy:b,cut:y}},gi={xs:0,sm:640,md:768,lg:1024,xl:1280,"2xl":1536,"3xl":1920},Qe=(e="lg")=>{const[t,n]=d.useState(!1);return d.useEffect(()=>{const o=()=>{const l=window.matchMedia(`(min-width: ${gi[e]+1}px)`).matches;n(l)};return o(),window.addEventListener("resize",o),()=>{window.removeEventListener("resize",o)}},[]),t};function io(e){return r.jsx(A.Tooltip,{...e,tooltipClassName:"!text-red-500 bg-red-50",children:e.children})}function me({title:e,error:t,tooltip:n}){const o=t instanceof Error?t.message:t;console.log("ErrorView",t);const l=r.jsxs("div",{className:"flex items-center m-2",children:[r.jsx(A.ErrorIcon,{size:"small",color:"error"}),r.jsxs("div",{className:"pl-2",children:[e&&r.jsx(A.Typography,{variant:"body2",className:"font-medium",children:e}),r.jsx(A.Typography,{variant:"body2",children:o})]})]});return n?r.jsx(io,{title:n,children:l}):l}function At(){return r.jsx("div",{className:"rounded-full bg-gray-200 bg-opacity-30 dark:bg-opacity-20 w-5 h-2 inline-block"})}const hi=40,pi=100,mi=200;function ft(e){if(e==="tiny")return hi;if(e==="small")return pi;if(e==="medium")return mi;throw Error("Thumbnail size not mapped")}function qe(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 so({size:e,url:t}){const[n,o]=d.useState(!1),l=d.useMemo(()=>ft(e),[e]);if(e==="tiny")return r.jsx("img",{src:t,className:"rounded-md",style:{position:"relative",objectFit:"cover",width:l,height:l,maxHeight:"100%"}},"tiny_image_preview_"+t);const i={maxWidth:"100%",maxHeight:"100%"};return r.jsxs("div",{className:"relative flex items-center justify-center max-w-full max-h-full",style:{width:l,height:l},onMouseEnter:()=>o(!0),onMouseMove:()=>o(!0),onMouseLeave:()=>o(!1),children:[r.jsx("img",{src:t,className:"rounded-md",style:i}),n&&r.jsxs(r.Fragment,{children:[navigator&&r.jsx(A.Tooltip,{title:"Copy url to clipboard",children:r.jsx("div",{className:"rounded-full absolute bottom-[-4px] right-8",children:r.jsx(A.IconButton,{variant:"filled",size:"small",onClick:s=>(s.stopPropagation(),s.preventDefault(),navigator.clipboard.writeText(t)),children:r.jsx(A.ContentCopyIcon,{className:"text-gray-500",size:"small"})})})}),r.jsx(A.Tooltip,{title:"Open image in new tab",children:r.jsx(A.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(A.OpenInNewIcon,{className:"text-gray-500",size:"small"})})})]})]},"image_preview_"+t)}function kt({url:e,previewType:t,size:n,hint:o}){return t?t==="image"?r.jsx(so,{url:e,size:n}):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-${n==="small"?"sm":"md"}`,controls:!0,children:r.jsx("source",{src:e})}):r.jsxs("a",{href:e,rel:"noopener noreferrer",target:"_blank",onClick:l=>l.stopPropagation(),className:"flex flex-col items-center justify-center",style:{width:ft(n),height:ft(n)},children:[r.jsx(A.DescriptionIcon,{className:"flex-grow"}),o&&r.jsx(A.Tooltip,{title:o,children:r.jsx(A.Typography,{className:"max-w-full truncate rtl text-left",variant:"caption",children:o})})]}):!e||!e.trim()?r.jsx(At,{}):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:l=>{l.preventDefault()},target:"_blank",children:[r.jsx(A.OpenInNewIcon,{size:"small"}),e]})}function ut({property:e,size:t}){e||console.error("No property assigned for skeleton component",e,t);let n;if(e.dataType==="string"){const o=e;o.url?n=Ei(o,t):o.storage?n=Or(t):n=Ye()}else if(e.dataType==="array"){const o=e;o.of&&(Array.isArray(o.of)?n=r.jsxs(r.Fragment,{children:[o.of.map((l,i)=>Dr(l,i))," "]}):o.of.dataType==="map"&&o.of.properties?n=yi(o.of.properties,t,o.of.previewProperties):o.of.dataType==="string"?o.of.enumValues?n=wi():o.of.storage?n=Dr(o.of):n=vi():n=Dr(o.of))}else e.dataType==="map"?n=bi(e,t):e.dataType==="date"?n=Ye():e.dataType==="reference"?n=Ci():(e.dataType,n=Ye());return n||null}function bi(e,t){if(!e.properties)return r.jsx(r.Fragment,{});let n;return t==="medium"?n=Object.keys(e.properties):(n=e.previewProperties||Object.keys(e.properties),t==="small"?n=n.slice(0,3):t==="tiny"&&(n=n.slice(0,1))),t!=="medium"?r.jsx("div",{className:"w-full flex flex-col space-y-4",children:n.map((o,l)=>r.jsx("div",{children:e.properties&&e.properties[o]&&r.jsx(ut,{property:e.properties[o],size:"small"})},`map_${o}`))}):r.jsx("table",{className:"table-auto",children:r.jsx("tbody",{children:n&&n.map((o,l)=>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[o].name})},`table-cell-title--${o}`),r.jsx("th",{style:{width:"70%"},children:e.properties&&e.properties[o]&&r.jsx(ut,{property:e.properties[o],size:"small"})},`table-cell-${o}`)]},`map_preview_table__${l}`))})})}function yi(e,t,n){let o=n;return(!o||!o.length)&&(o=Object.keys(e),t&&(o=o.slice(0,3))),r.jsx("table",{className:"table-auto",children:r.jsx("tbody",{children:[0,1,2].map((l,i)=>r.jsx("tr",{children:o&&o.map(s=>r.jsx("th",{children:r.jsx(ut,{property:e[s],size:"small"})},`table-cell-${s}`))},`table_${l}_${i}`))})})}function vi(){return r.jsx("div",{className:"flex flex-col gap-2",children:[0,1].map((e,t)=>Ye(t))})}function wi(){return r.jsx("div",{className:"flex flex-col gap-2",children:[0,1].map((e,t)=>r.jsx(r.Fragment,{children:Ye(t)}))})}function Dr(e,t=0){return r.jsx("div",{className:"flex flex-col gap-2",children:[0,1].map((n,o)=>r.jsx(r.Fragment,{children:r.jsx(ut,{property:e,size:"small"},`i_${o}`)}))},"array_index_"+t)}function Or(e){const t=e==="tiny"?40:e==="small"?100:200;return r.jsx(A.Skeleton,{width:t,height:t})}function Ci(){return r.jsx(A.Skeleton,{width:200,height:100})}function Ei(e,t="medium"){return typeof e.url=="boolean"?r.jsxs("div",{style:{display:"flex"},children:[Vr(),Ye()]}):Bi(t)}function Bi(e){return r.jsx("div",{className:`w-${ft(e)} h-${ft(e)}`,children:Vr()})}function Ye(e,t=120){return r.jsx(A.Skeleton,{width:t},`skeleton_${e}`)}function ki(e){return r.jsx(A.Skeleton,{height:20})}function Vr(){return r.jsx(A.Skeleton,{width:24,height:24})}const ao=d.memo(Ao,xi);function xi(e,t){return e.size===t.size&&e.storagePathOrDownloadUrl===t.storagePathOrDownloadUrl&&e.storeUrl===t.storeUrl}const co={};function Ao({storeUrl:e,storagePathOrDownloadUrl:t,size:n}){const[o,l]=d.useState(void 0),i=ct(),[s,a]=d.useState(co[t]);if(d.useEffect(()=>{if(!t)return;let g=!1;return i.getDownloadURL(t).then(function(p){g||(a(p),co[t]=p)}).catch(l),()=>{g=!0}},[t]),!t)return null;const c=s?.metadata?Ii(s?.metadata.contentType):void 0,f=c?.startsWith("image")?"image":c?.startsWith("video")?"video":c?.startsWith("audio")?"audio":"file";return s?.fileNotFound?r.jsx(me,{error:"File not found"}):s?.url?r.jsx(kt,{previewType:f,url:s.url,size:n,hint:t}):Or(n)}function Ii(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 Ce({enumValues:e,enumKey:t,size:n,className:o,children:l}){if(!e)return null;const i=_e(e),s=t!==void 0?Lt(i,t):void 0,a=Tn(s),c=Pn(i,t);return r.jsxs(A.Chip,{className:o,colorScheme:c,error:!a,outlined:!1,size:n,children:[l,!l&&(a!==void 0?a:String(t))]})}function Gr({propertyKey:e,value:t,property:n,size:o}){if(n.enumValues){const l=t,i=vr(n);return r.jsx(Ce,{enumKey:l,enumValues:i.enumValues,size:o!=="medium"?"small":"medium"})}else if(n.previewAsTag){const l=Nn(e??"");return r.jsx(re,{children:r.jsx(A.Chip,{colorScheme:l,size:o!=="medium"?"small":"medium",children:t})})}else{if(n.url)return r.jsx(kt,{size:o,url:t,previewType:typeof n.url=="string"?n.url:void 0});{if(!t)return r.jsx(r.Fragment,{});const l=t.split(`
2
2
  `);return t&&t.includes(`
3
- `)?r.jsx("div",{className:"overflow-x-scroll",children:l.map((i,s)=>r.jsxs(c.Fragment,{children:[r.jsx("span",{children:i}),s!==l.length-1&&r.jsx("br",{})]},`string_preview_${s}`))}):r.jsx(r.Fragment,{children:t})}}}function Yr({propertyKey:e,value:t,property:n,entity:o,size:l}){const i=Z(),s=We({propertyKey:e,property:n,propertyValue:t,fields:i.propertyConfigs});if(!s.of)throw Error(`You need to specify an 'of' prop (or specify a custom field) in your array property ${e}`);if(s.dataType!=="array")throw Error("Picked wrong preview component ArrayPreview");const a=t;if(!a)return null;const d=l==="medium"?"small":"tiny";return r.jsx("div",{className:"flex flex-col gap-2",children:a&&a.map((A,g)=>{const p=s.resolvedProperties[g]??s.resolvedProperties[g]??(Array.isArray(s.of)?s.of[g]:s.of);return p?r.jsx(c.Fragment,{children:r.jsx("div",{className:f.cn(f.defaultBorderMixin,"m-1 border-b last:border-b-0"),children:r.jsx(ne,{children:r.jsx(me,{propertyKey:e,entity:o,value:A,property:p,size:d})})})},"preview_array_"+g):null})})}const De=dr.memo(function(t){const n=t.reference;return n instanceof Fe?r.jsx(Fi,{...t}):(console.warn("Reference preview received value of type",typeof n),r.jsx(Xt,{onClick:t.onClick,size:t.size,children:r.jsx(pe,{error:"Unexpected value. Click to edit",tooltip:JSON.stringify(n)})}))},Si);function Si(e,t){return e.disabled===t.disabled&&e.size===t.size&&e.onHover===t.onHover&&e.reference?.id===t.reference?.id&&e.reference?.path===t.reference?.path&&e.allowEntityNavigation===t.allowEntityNavigation}function Fi({disabled:e,reference:t,previewProperties:n,size:o,onHover:l,onClick:i,allowEntityNavigation:s=!0}){const a=Z(),A=ie().getCollection(t.path);if(!A){if(a.components?.missingReference)return r.jsx(a.components.missingReference,{path:t.path});throw Error(`Couldn't find the corresponding collection view for the path: ${t.path}`)}return r.jsx(Ni,{reference:t,collection:A,previewProperties:n,size:o,disabled:e,allowEntityNavigation:s,onClick:i,onHover:l})}function Ni({reference:e,collection:t,previewProperties:n,size:o,disabled:l,allowEntityNavigation:i,onClick:s,onHover:a}){const d=Z(),A=He(),{entity:g,dataLoading:p,dataLoadingError:h}=Qr({path:e.path,entityId:e.id,collection:t,useCache:!0});g&&fo.set(e.pathWithId,g);const u=g??fo.get(e.pathWithId),m=c.useMemo(()=>ke({collection:t,path:e.path,values:u?.values,fields:d.propertyConfigs}),[t]),b=c.useMemo(()=>zn(m,d.propertyConfigs,n,o==="small"||o==="medium"?3:1),[n,m,o]);let y;return m?(e?u&&!u.values?y=r.jsx(pe,{error:"Reference does not exist",tooltip:e.path}):y=r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"flex flex-col flex-grow w-full max-w-[calc(100%-52px)] m-1",children:[o!=="tiny"&&(e?r.jsx("div",{className:`${o!=="medium"?"block whitespace-nowrap overflow-hidden truncate":""}`,children:r.jsx(f.Typography,{variant:"caption",className:"font-mono",children:e.id})}):r.jsx(f.Skeleton,{})),b&&b.map(w=>{const C=m.properties[w];return C?r.jsx("div",{className:b.length>1?"my-0.5":"my-0",children:u?r.jsx(me,{propertyKey:w,value:$e(u.values,w),property:C,entity:u,size:"tiny"}):r.jsx(ut,{property:C,size:"tiny"})},"ref_prev_"+w):null})]}),r.jsx("div",{className:`my-${o==="tiny"?2:4}`,children:!l&&u&&i&&r.jsx(f.Tooltip,{title:`See details for ${u.id}`,children:r.jsx(f.IconButton,{color:"inherit",size:"small",onClick:w=>{w.stopPropagation(),d.onAnalyticsEvent?.("entity_click_from_reference",{path:u.path,entityId:u.id}),A.open({entityId:u.id,path:u.path,collection:m,updateUrl:!0})},children:r.jsx(f.KeyboardTabIcon,{size:"small"})})})})]}):y=r.jsx(pe,{error:"Reference not set"}),r.jsx(Xt,{onClick:l?void 0:s,onHover:l?void 0:a,size:o,children:y})):r.jsx(pe,{error:"Could not find collection with id "+m})}function Xt({children:e,onHover:t,size:n,onClick:o}){return r.jsx(f.Typography,{variant:"label",className:f.cn("bg-opacity-70 bg-gray-100 dark:bg-gray-800 dark:bg-opacity-60","w-full","flex","rounded-md","overflow-hidden",t?"hover:bg-opacity-90 dark:hover:bg-opacity-90":"",n==="medium"?"p-2":"p-1",n==="tiny"?"items-center":"","transition-colors duration-300 ease-in-out ",o?"cursor-pointer":""),style:{tabindex:0},onClick:l=>{o&&(l.preventDefault(),o(l))},children:e})}const fo=new Map;function uo({propertyKey:e,value:t,property:n,size:o}){const l=Z(),i=We({propertyKey:e,property:n,propertyValue:t,fields:l.propertyConfigs});if(Array.isArray(i?.of))throw Error("Using array properties instead of single one in `of` in ArrayProperty");if(i?.dataType!=="array"||!i.of||i.of.dataType!=="reference")throw Error("Picked wrong preview component ArrayOfReferencesPreview");const s=o==="medium"?"small":"tiny";return r.jsx("div",{className:"flex flex-col w-full",children:t&&t.map((a,d)=>{const A=i.of;return r.jsx("div",{className:"mt-1 mb-1 w-full",children:r.jsx(De,{disabled:!A.path,previewProperties:A.previewProperties,size:s,reference:a})},`preview_array_ref_${e}_${d}`)})})}function go({propertyKey:e,entity:t,value:n,property:o,size:l}){const i=Z(),s=We({propertyKey:e,property:o,propertyValue:n,fields:i.propertyConfigs});if(Array.isArray(s.of))throw Error("Using array properties instead of single one in `of` in ArrayProperty");if(s.dataType!=="array"||!s.of||s.of.dataType!=="string")throw Error("Picked wrong preview component ArrayOfStorageComponentsPreview");const a=l==="medium"?"small":"tiny";return r.jsx("div",{className:"flex flex-wrap gap-2",children:n&&n.map((d,A)=>r.jsx(ne,{children:r.jsx(me,{propertyKey:e,value:d,entity:t,property:s.of,size:a})},`preview_array_storage_${e}_${A}`))})}function zr({name:e,value:t,enumValues:n,size:o}){return r.jsx("div",{className:"flex flex-wrap gap-1.5",children:t&&t.map((l,i)=>r.jsx(ne,{children:r.jsx(we,{enumKey:l,enumValues:n,size:o!=="medium"?"small":"medium"})},`preview_array_ref_${e}_${i}`))})}function Ur({propertyKey:e,value:t,property:n,size:o}){if(n.dataType!=="array")throw Error("Picked wrong preview component ArrayEnumPreview");const l=n.of;if(!l.enumValues)throw Error("Picked wrong preview component ArrayEnumPreview");return t?r.jsx(zr,{name:e,value:t,enumValues:l.enumValues,size:o}):null}function ho({propertyKey:e,value:t,property:n,entity:o,size:l}){const i=Z(),s=We({propertyKey:e,property:n,propertyValue:t,fields:i.propertyConfigs});if(Array.isArray(s.of))throw Error("Using array properties instead of single one in `of` in ArrayProperty");if(!s.of||s.dataType!=="array"||s.of.dataType!=="string")throw Error("Picked wrong preview component ArrayOfStringsPreview");if(t&&!Array.isArray(t))return r.jsx("div",{children:`Unexpected value: ${t}`});const a=s.of;return r.jsx("div",{className:"flex flex-col gap-2",children:t&&t.map((d,A)=>r.jsx("div",{children:r.jsx(ne,{children:r.jsx(Gr,{propertyKey:e,property:a,value:d,entity:o,size:l})})},`preview_array_strings_${e}_${A}`))})}function po({propertyKey:e,value:t,property:n,size:o,entity:l}){const i=Z(),s=We({propertyKey:e,property:n,propertyValue:t,fields:i.propertyConfigs});if(s?.dataType!=="array")throw Error("Picked wrong preview component ArrayPreview");if(!s?.oneOf)throw Error(`You need to specify an 'of' or 'oneOf' prop (or specify a custom field) in your array property ${e}`);const a=t;if(!a)return null;const d=o==="medium"?"small":"tiny",A=s.oneOf.typeField??vt,g=s.oneOf.valueField??zt,p=s.oneOf.properties;return r.jsx("div",{className:"flex flex-col",children:a&&a.map((h,u)=>r.jsx(c.Fragment,{children:r.jsx("div",{className:f.cn(f.defaultBorderMixin,"m-1 border-b last:border-b-0"),children:r.jsx(ne,{children:h&&r.jsx(me,{propertyKey:e,value:h[g],entity:l,property:s.resolvedProperties[u]??p[h[A]],size:d})})})},"preview_array_"+h+"_"+u))})}function mo({propertyKey:e,value:t,property:n,entity:o,size:l}){if(n.dataType!=="map")throw Error("Picked wrong preview component MapPropertyPreview");const i=n;if(!i.properties||Object.keys(i.properties??{}).length===0)return r.jsx(Lr,{value:t});if(!t)return null;const s=Object.keys(i.properties);return l==="tiny"?r.jsx("div",{className:"w-full flex flex-col space-y-1 md:space-y-2",children:s.map((a,d)=>r.jsx("div",{children:r.jsx(ne,{children:r.jsx(me,{propertyKey:a,value:t[a],property:i.properties[a],entity:o,size:l})},"map_preview_"+i.name+a+d)},`map_${a}`))}):r.jsx("div",{className:"flex flex-col gap-1 w-full",children:s&&s.map((a,d)=>{const A=i.properties[a];return r.jsxs("div",{className:f.cn(f.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(f.Typography,{variant:"caption",className:"font-mono break-words",color:"secondary",children:A.name})}),r.jsx("div",{className:"flex-grow max-w-[75%]",children:r.jsx(ne,{children:!(A.dataType==="map"||A==="array")&&r.jsx(me,{propertyKey:a,value:t[a],property:A,entity:o,size:l})})})]}),(A.dataType==="map"||A==="array")&&r.jsx("div",{className:f.cn(f.defaultBorderMixin,"border-l pl-4 ml-2 my-2"),children:r.jsx(me,{propertyKey:a,value:t[a],property:A,entity:o,size:l})})]},`map_preview_table_${a}}`)})})}function Lr({value:e}){return typeof e!="object"?null:r.jsx("div",{className:"flex flex-col gap-1 w-full",children:Object.entries(e).map(([t,n])=>r.jsxs("div",{className:f.cn(f.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(f.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 n!="object"&&r.jsx(f.Typography,{children:r.jsx(ne,{children:n&&n.toString()})})})]}),typeof n=="object"&&r.jsx("div",{className:f.cn(f.defaultBorderMixin,"border-l pl-4"),children:r.jsx(Lr,{value:n})})]},`map_preview_table_${t}}`))})}function bo({date:e}){const t=Z(),n=t?.locale?En[t?.locale]:void 0,o=t?.dateTimeFormat??Tn,l=e?vl.format(e,o,{locale:n}):"";return r.jsx(r.Fragment,{children:l})}function yo({value:e}){return r.jsx(f.Checkbox,{checked:e})}function vo({value:e,property:t,size:n}){if(t.enumValues){const o=e,l=_e(t.enumValues);return l?r.jsx(we,{enumKey:o,enumValues:l,size:n!=="medium"?"small":"medium"}):r.jsx(r.Fragment,{children:e})}else return r.jsx(r.Fragment,{children:e})}function me(e){const t=Z();let n;const{property:o,propertyKey:l,value:i,size:s,height:a,width:d,entity:A}=e,g=Be({propertyKey:l,propertyOrBuilder:o,propertyValue:i,fields:t.propertyConfigs});if(i===void 0||g===null)n=r.jsx(At,{});else if(g.Preview)n=c.createElement(g.Preview,{propertyKey:l,value:i,property:g,size:s,height:a,width:d,entity:A,customProps:g.customProps});else if(i===null)n=r.jsx(At,{});else if(g.dataType==="string"){const p=g;typeof i=="string"?p.url?typeof p.url=="boolean"?n=r.jsx(kt,{size:e.size,url:i}):typeof p.url=="string"&&(n=r.jsx(kt,{size:e.size,url:i,previewType:p.url})):p.storage?n=r.jsx(ao,{storeUrl:g.storage?.storeUrl??!1,size:e.size,storagePathOrDownloadUrl:i}):p.markdown?n=r.jsx(f.Markdown,{source:i}):n=r.jsx(Gr,{...e,property:p,value:i}):n=rt(l,g.dataType,i)}else if(g.dataType==="array")if(i instanceof Array){const p=g;if(!p.of&&!p.oneOf)throw Error(`You need to specify an 'of' or 'oneOf' prop (or specify a custom field) in your array property ${l}`);p.of?Array.isArray(p.of)?n=r.jsx(Yr,{...e,value:i,property:g}):p.of.dataType==="reference"?n=r.jsx(uo,{...e,value:i,property:g}):p.of.dataType==="string"?p.of.enumValues?n=r.jsx(Ur,{...e,value:i,property:g}):p.of.storage?n=r.jsx(go,{...e,value:i,property:g}):n=r.jsx(ho,{...e,value:i,property:g}):p.of.dataType==="number"&&p.of.enumValues?n=r.jsx(Ur,{...e,value:i,property:g}):n=r.jsx(Yr,{...e,value:i,property:g}):p.oneOf&&(n=r.jsx(po,{...e,value:i,property:g}))}else n=rt(l,g.dataType,i);else g.dataType==="map"?typeof i=="object"?n=r.jsx(mo,{...e,property:g}):n=rt(l,g.dataType,i):g.dataType==="date"?i instanceof Date?n=r.jsx(bo,{date:i}):n=rt(l,g.dataType,i):g.dataType==="reference"?typeof g.path=="string"?i instanceof Fe?n=r.jsx(De,{disabled:!g.path,previewProperties:g.previewProperties,size:e.size,onClick:e.onClick,reference:i}):n=rt(l,g.dataType,i):n=r.jsx(At,{}):g.dataType==="boolean"?typeof i=="boolean"?n=r.jsx(yo,{value:i}):n=rt(l,g.dataType,i):g.dataType==="number"?typeof i=="number"?n=r.jsx(vo,{...e,value:i,property:g}):n=rt(l,g.dataType,i):n=JSON.stringify(i);return n??r.jsx(At,{})}function rt(e,t,n){return console.warn(`Unexpected value for property ${e}, of type ${t}`,n),r.jsx(pe,{title:"Unexpected value",error:`${JSON.stringify(n)}`})}function Pi({propertyKey:e,value:t,property:n,size:o,entity:l}){const i=Z(),s=We({propertyKey:e,property:n,propertyValue:t,fields:i.propertyConfigs});if(Array.isArray(s?.of))throw Error("Using array properties instead of single one in `of` in ArrayProperty");if(s?.dataType!=="array"||!s.of||s.of.dataType!=="map")throw Error("Picked wrong preview component ArrayOfMapsPreview");const a=s.of,d=a.properties;if(!d)throw Error(`You need to specify a 'properties' prop (or specify a custom field) in your map property ${e}`);const A=t,g=a.previewProperties;if(!A)return null;let p=g;return(!p||!p.length)&&(p=Object.keys(d),o&&(p=p.slice(0,3))),r.jsx("div",{className:"table-auto text-xs",children:r.jsx("div",{children:A&&A.map((h,u)=>r.jsx("div",{className:"border-b last:border-b-0",children:p&&p.map(m=>r.jsx("div",{className:"table-cell",children:r.jsx(ne,{children:r.jsx(me,{propertyKey:m,value:h[m],property:d[m],entity:l,size:"small"})})},`table-cell-${m}`))},`table_${h}_${u}`))})})}const Qi=dr.memo(function({builder:t}){const[n,o]=c.useState(!0),[l,i]=c.useState(null);return c.useEffect(()=>{let s=!1;return t.then(a=>{s||(o(!1),i(a))}).catch(a=>{o(!1),console.error(a)}),()=>{s=!0}},[t]),n?r.jsx(f.Skeleton,{}):r.jsx(dr.Fragment,{children:l})});function $r({entity:e,collection:t,path:n,className:o}){const l=Z(),i=c.useMemo(()=>ke({collection:t,path:n,entityId:e.id,values:e.values,fields:l.propertyConfigs}),[t,n,e]),s=Z(),a=i.properties;return r.jsx("div",{className:"w-full "+o,children:r.jsxs("div",{className:"w-full mb-4",children:[r.jsxs("div",{className:f.cn(f.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}),s?.entityLinkBuilder&&r.jsx("a",{href:s.entityLinkBuilder({entity:e}),rel:"noopener noreferrer",target:"_blank",children:r.jsx(f.IconButton,{children:r.jsx(f.OpenInNewIcon,{size:"small"})})})]})]}),Object.entries(a).map(([d,A])=>{const g=e.values[d];return r.jsxs("div",{className:f.cn(f.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:A.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(me,{propertyKey:d,value:g,entity:e,property:A,size:"medium"})})]},`reference_previews_${d}`)})]})})}function Ti(e){return e.dataType==="boolean"?"center":e.dataType==="number"?e.enumValues?"left":"right":e.dataType==="date"?"right":"left"}function wo(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:wo(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 _r(e){return`subcollection:${e.id??e.path}`}function Mi(e){const t=c.useRef(null),{disabled:n,value:o,multiline:l,updateValue:i,focused:s}=e,a=c.useRef(o),[d,A]=c.useState(o),g=c.useRef(!1);c.useEffect(()=>{a.current!==o&&o!==d&&A(o),a.current=o},[o]);const p=c.useCallback(()=>{!o&&!d||d!==o&&(a.current=d,i(d))},[d,i,o]);return Wt(d,p,!s,2e3),c.useEffect(()=>{t.current&&s&&!g.current?(g.current=!0,t.current.focus({preventScroll:!0}),t.current.selectionStart=t.current.value.length,t.current.selectionEnd=t.current.value.length):g.current=s},[s,t]),r.jsx(f.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:d??"",onChange:h=>{const u=h.target.value;(l||!u.endsWith(`
4
- `))&&A(u)},onFocus:()=>{g.current=!0},onBlur:()=>{g.current=!1,p()}})}function Wr(e){const{name:t,enumValues:n,error:o,internalValue:l,disabled:i,small:s,focused:a,updateValue:d,multiple:A,valueType:g}=e,p=Array.isArray(l)&&A||!Array.isArray(l)&&!A,h=c.useRef(null);c.useEffect(()=>{h.current&&a&&h.current?.focus({preventScroll:!0})},[a,h]);const u=c.useCallback(b=>{if(g==="number")if(A){const y=b.map(w=>parseFloat(w));d(y)}else d(parseFloat(b));else if(g==="string")d(b||null);else throw Error("Missing mapping in TableSelect")},[A,d,g]),m=(b,y)=>A&&Array.isArray(b)?r.jsx(zr,{value:b,name:t,enumValues:n,size:s?"small":"medium"},`${b}-${y}`):r.jsx(we,{enumKey:b,enumValues:n,size:s?"small":"medium"},`${b}-${y}`);return A?r.jsx(f.MultiSelect,{inputRef:h,containerClassName:"w-full h-full",className:"w-full h-full p-0 bg-transparent",position:"item-aligned",disabled:i,padding:!1,includeFocusOutline:!1,value:p?l.map(b=>b.toString()):[],onMultiValueChange:u,renderValue:m,children:n?.map(b=>r.jsx(f.MultiSelectItem,{value:String(b.id),children:r.jsx(we,{enumKey:b.id,enumValues:n,size:s?"small":"medium"})},b.id))}):r.jsx(f.Select,{inputRef:h,className:"w-full h-full p-0 bg-transparent",position:"item-aligned",disabled:i,multiple:A,padding:!1,includeFocusOutline:!1,value:p?A?l.map(b=>b.toString()):l?.toString():A?[]:"",onValueChange:u,onMultiValueChange:u,renderValue:m,children:n?.map(b=>r.jsx(f.SelectItem,{value:String(b.id),children:r.jsx(we,{enumKey:b.id,enumValues:n,size:s?"small":"medium"})},b.id))})}function Di(e){const{align:t,value:n,updateValue:o,focused:l}=e,i=n&&typeof n=="number"?n.toString():"",[s,a]=c.useState(i),d=c.useRef(n);c.useEffect(()=>{d.current!==n&&String(n)!==s&&a(n?n.toString():null),d.current=n},[n]);const A=c.useCallback(()=>{if(s!==i)if(s!=null){const h=parseFloat(s);if(isNaN(h))return;h!=null&&o(h)}else o(null)},[s,n]);Wt(s,A,!l,2e3),c.useEffect(()=>{!l&&i!==s&&a(n!=null?n.toString():null)},[n,l]);const g=c.useRef(null);c.useEffect(()=>{g.current&&l&&g.current.focus({preventScroll:!0})},[l,g]);const p=/^-?[0-9]+[,.]?[0-9]*$/;return r.jsx("input",{ref:g,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:h=>{const u=h.target.value.replace(",",".");u.length===0&&a(null),(p.test(u)||u.startsWith("-"))&&a(u)}})}function Oi(e){const{internalValue:t,updateValue:n,focused:o}=e,l=c.useRef(null);return c.useEffect(()=>{l.current&&o&&l.current.focus({preventScroll:!0})},[o,l]),r.jsx(f.BooleanSwitch,{ref:l,size:"small",value:!!t,onValueChange:n})}function Vi(e){const{locale:t}=Z(),{disabled:n,error:o,mode:l,internalValue:i,updateValue:s}=e;return r.jsx(f.DateTimeField,{value:i??void 0,onChange:a=>s(a),size:"medium",invisible:!0,className:"w-full h-full",inputClassName:"w-full h-full",mode:l,locale:t})}class ne extends c.Component{constructor(t){super(t),this.state={error:null}}static getDerivedStateFromError(t){return{error:t}}componentDidCatch(t,n){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(f.ErrorIcon,{color:"error",size:"small"}),r.jsx("div",{className:"ml-4",children:"Error"})]}),r.jsx(f.Typography,{variant:"caption",children:this.state.error?.message??"See the error in the console"})]}):this.props.children}}async function Gi(e,t,n,o,l,i,s,a){let d;return typeof e=="function"?(d=await e({path:l,entityId:o,values:n,property:i,file:s,storage:t,propertyKey:a}),d||console.warn("Storage callback returned empty result. Using default name value")):d=Co(s,e,o,a,l),d||(d=st()+"_"+s.name),d}function Yi(e,t,n,o,l,i,s,a){let d;return typeof e=="function"?(d=e({path:l,entityId:o,values:n,property:i,file:s,storage:t,propertyKey:a}),d||console.warn("Storage callback returned empty result. Using default name value")):d=Co(s,e,o,a,l),d||(d=st()+"_"+s.name),d}function Co(e,t,n,o,l){const i=e.name.split(".").pop();let s=t.replace("{entityId}",n).replace("{propertyKey}",o).replace("{rand}",st()).replace("{file}",e.name).replace("{file.type}",e.type).replace("{path}",l);if(i){s=s.replace("{file.ext}",i);const a=e.name.replace(`.${i}`,"");s=s.replace("{file.name}",a)}return s||(s=st()+"_"+e.name),s}function Eo({entityId:e,entityValues:t,path:n,value:o,property:l,propertyKey:i,storageSource:s,disabled:a,onChange:d}){const A=l.dataType==="string"?l.storage:l.dataType==="array"&&l.of.dataType==="string"?l.of.storage:void 0,g=l.dataType==="array";if(!A)throw Error("Storage meta must be specified");const p=A?.metadata,h=g?"small":"medium",u=A?.imageCompression,m=(g?o??[]:o?[o]:[]).map(k=>({id:jr(),storagePathOrDownloadUrl:k,metadata:p,size:h})),[b,y]=c.useState(o),[w,C]=c.useState(m);c.useEffect(()=>{oe(b,o)||(y(o),C(m))},[m,o,b]);const E=c.useCallback(async k=>{if(A.fileName){const S=await Gi(A.fileName,A,t,e,n,l,k,i);if(!S||S.length===0)throw Error("You need to return a valid filename");return S}return st()+"_"+k.name},[e,t,n,l,i,A]),B=c.useCallback(k=>Yi(A.storagePath,A,t,e,n,l,k,i)??"/",[e,t,n,l,i,A]),I=c.useCallback(async(k,S,F)=>{console.debug("onFileUploadComplete",k,S);let P=k;if(A.storeUrl&&(P=(await s.getDownloadURL(k)).url),A.postProcess&&P&&(P=await A.postProcess(P)),!P){console.warn("uploadPathOrDownloadUrl is null");return}let N;S.storagePathOrDownloadUrl=P,S.metadata=F,N=[...w],N=Bo(N),C(N);const T=N.filter(Y=>!!Y.storagePathOrDownloadUrl).map(Y=>Y.storagePathOrDownloadUrl);d(g?T:T?T[0]:null)},[w,g,d,A,s]),x=c.useCallback(async k=>{if(!k.length||a)return;let S;if(g)S=[...w,...await Promise.all(k.map(async F=>(u&&Hr(F)&&(F=await xo(F,u)),{id:jr(),file:F,fileName:await E(F),metadata:p,size:h})))];else{let F=k[0];u&&Hr(F)&&(F=await xo(F,u)),S=[{id:jr(),file:F,fileName:await E(F),metadata:p,size:h}]}S=Bo(S),C(S)},[a,E,w,p,g,h]);return{internalValue:w,setInternalValue:C,storage:A,fileNameBuilder:E,storagePathBuilder:B,onFileUploadComplete:I,onFilesAdded:x,multipleFilesSupported:g}}function Bo(e){return e.filter((t,n)=>(e.map(o=>o.storagePathOrDownloadUrl).indexOf(t.storagePathOrDownloadUrl)===n||!t.storagePathOrDownloadUrl)&&(e.map(o=>o.file).indexOf(t.file)===n||!t.file))}function jr(){return Math.floor(Math.random()*Math.floor(Number.MAX_SAFE_INTEGER))}const ko={"image/jpeg":"JPEG","image/png":"PNG","image/webp":"WEBP"},Hr=e=>ko[e.type]?ko[e.type]:null,zi=100,xo=(e,t)=>new Promise(n=>{const o=t.quality===void 0?zi:t.quality,l=o>=0&&o<=100?o:100,i=Hr(e);if(!i)throw Error("resizeAndCompressImage: Unsupported image format");El.imageFileResizer(e,t.maxWidth||Number.MAX_VALUE,t.maxHeight||Number.MAX_VALUE,i,l,0,s=>n(s),"file")});function Io({storagePath:e,entry:t,metadata:n,onFileUploadComplete:o,imageSize:l,simple:i}){const s=ct(),a=Je(),[d,A]=c.useState(),[g,p]=c.useState(!1),h=c.useRef(!1),u=c.useRef(!1),m=c.useCallback((b,y)=>{u.current||(u.current=!0,A(void 0),p(!0),s.uploadFile({file:b,fileName:y,path:e,metadata:n}).then(async({path:w})=>{console.debug("Upload successful"),await o(w,t,n),h.current&&p(!1)}).catch(w=>{console.warn("Upload error",w),h.current&&(A(w),p(!1),a.open({type:"error",message:"Error uploading file: "+w.message}))}).finally(()=>{u.current=!1}))},[t,n,o,s,e]);return c.useEffect(()=>(h.current=!0,t.file&&m(t.file,t.fileName),()=>{h.current=!1}),[t.file,t.fileName,m]),i?r.jsx("div",{className:`m-4 w-${l} h-${l}`,children:g&&r.jsx(f.Skeleton,{className:`w-${l} h-${l}`})}):r.jsxs("div",{className:f.cn(f.paperMixin,"relative m-4 border-box flex items-center justify-center",`min-w-[${l}px] min-h-[${l}px]`),children:[g&&r.jsx(f.Skeleton,{className:"w-full h-full"}),d&&r.jsx(pe,{title:"Error uploading file",error:d})]})}function So({showError:e,disabled:t,showExpandIcon:n,selected:o,openPopup:l,children:i}){const s=c.useRef(null),a=c.useCallback(()=>{if(l){const A=s&&s?.current?.getBoundingClientRect();l(A)}},[]),d=c.useRef();return c.useEffect(()=>{d.current&&o&&d.current.focus({preventScroll:!0})},[o]),r.jsx(r.Fragment,{children:(e||!t&&n)&&r.jsxs("div",{ref:s,className:"absolute top-0.5 right-0.5 flex items-center",children:[o&&i,o&&!t&&n&&r.jsx(f.IconButton,{ref:d,color:"inherit",size:"small",onClick:a,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(io,{side:"left",className:"flex items-center justify-center",style:{width:32,height:32},title:e.message,children:r.jsx(f.ErrorOutlineIcon,{size:"small",color:"error"})})]})})}const Ui="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",Li="pt-0 border-2 border-solid",$i="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",_i="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 Wi(e){const{propertyKey:t,error:n,selected:o,openPopup:l,value:i,disabled:s,property:a,entity:d,path:A,previewSize:g,updateValue:p}=e,h=ct(),{internalValue:u,setInternalValue:m,onFilesAdded:b,storage:y,onFileUploadComplete:w,storagePathBuilder:C,multipleFilesSupported:E}=Eo({entityValues:d.values,entityId:d.id,path:A,property:a,propertyKey:t,storageSource:h,onChange:p,value:i,disabled:s});return r.jsx(ji,{internalValue:u,setInternalValue:m,name:t,disabled:s,autoFocus:!1,openPopup:l,error:n,selected:o,property:a,onChange:p,entity:d,storagePathBuilder:C,storage:y,multipleFilesSupported:E,onFilesAdded:b,onFileUploadComplete:w,previewSize:g})}function ji({property:e,name:t,internalValue:n,setInternalValue:o,openPopup:l,entity:i,selected:s,error:a,onChange:d,multipleFilesSupported:A,previewSize:g,disabled:p,autoFocus:h,storage:u,onFilesAdded:m,onFileUploadComplete:b,storagePathBuilder:y}){const[w,C]=c.useState(!1),E=A&&g==="medium"?"small":g;if(A){const z=e;if(Array.isArray(z.of))throw Error("Using array properties instead of single one in `of` in ArrayProperty");if(z.of){if(z.of.dataType!=="string")throw Error("Storage field using array must be of data type string")}else throw Error("Storage field using array must be of data type string")}const B=u?.metadata,I=!!n,x=Je(),{open:k,getRootProps:S,getInputProps:F,isDragActive:P,isDragAccept:N,isDragReject:T}=wn.useDropzone({accept:u.acceptedFiles?u.acceptedFiles.map(z=>({[z]:[]})).reduce((z,V)=>({...z,...V}),{}):void 0,disabled:p,maxSize:u.maxSize,noClick:!0,noKeyboard:!0,onDrop:m,onDropRejected:(z,V)=>{for(const re of z)for(const W of re.errors)x.open({type:"error",message:`Error uploading file: File is larger than ${u.maxSize} bytes`})}}),{...Y}=S(),H=A?"Drag 'n' drop some files here, or click here to edit":"Drag 'n' drop a file here, or click here edit",_=A?e.of:e,X=c.useMemo(()=>ft(E),[E]),te=!p&&a;return r.jsxs("div",{...Y,onMouseEnter:()=>C(!0),onMouseMove:()=>C(!0),onMouseLeave:()=>C(!1),className:f.cn(Ui,"relative w-full h-full flex",`justify-${I?"start":"center"}`,P?Li:"",N?$i:"",T?_i:""),children:[r.jsx("input",{autoFocus:h,...F()}),n.map((z,V)=>{let re;return z.storagePathOrDownloadUrl?re=r.jsx(Hi,{property:_,value:z.storagePathOrDownloadUrl,entity:i,size:E},`storage_preview_${V}`):z.file&&(re=r.jsx(Io,{entry:z,metadata:B,storagePath:y(z.file),onFileUploadComplete:b,imageSize:X,simple:!0},`storage_progress_${V}`)),re}),!n&&r.jsx("div",{className:"flex-grow m-2 max-w-[200px]",onClick:k,children:r.jsx(f.Typography,{className:"text-gray-400 dark:text-gray-600",variant:"body2",align:"center",children:H})}),r.jsx(So,{showError:te,disabled:p,showExpandIcon:!0,selected:s,openPopup:p?void 0:l,children:r.jsx(f.IconButton,{color:"inherit",size:"small",onClick:k,children:r.jsx(f.EditIcon,{size:"small",className:"text-gray-500"})})})]})}function Hi({property:e,value:t,size:n,entity:o}){return r.jsx("div",{className:"relative m-2",children:t&&r.jsx(ne,{children:r.jsx(me,{propertyKey:"ignore",value:t,property:e,entity:o,size:n})})})}function Fo(e){const t=Z(),n=ie(),{path:o}=e,l=n.getCollection(o);if(!l){if(t.components?.missingReference)return r.jsx(t.components.missingReference,{path:o});throw Error(`Couldn't find the corresponding collection view for the path: ${o}`)}return r.jsx(Ji,{...e,collection:l})}function Ji(e){const{name:t,internalValue:n,updateValue:o,multiselect:l,path:i,size:s,previewProperties:a,title:d,disabled:A,forceFilter:g,collection:p}=e,[h,u]=c.useState(!1),m=c.useCallback(()=>u(!0),[]),b=c.useCallback(()=>u(!1),[]),y=c.useCallback(S=>{o(S?Ge(S):null)},[o]),w=c.useCallback(S=>{o(S.map(F=>Ge(F)))},[o]),C=n?Array.isArray(n)?n.map(S=>S.id):n.id?[n.id]:[]:[],E=mt({multiselect:l,path:i,collection:p,onMultipleEntitiesSelected:w,onSingleEntitySelected:y,selectedEntityIds:C,forceFilter:g}),B=c.useCallback(()=>{A||E.open()},[A,E]),I=!n||Array.isArray(n)&&n.length===0,x=()=>n instanceof Fe?r.jsx(De,{onClick:A?void 0:B,size:qe(s),reference:n,onHover:h,disabled:!i,previewProperties:a}):r.jsx(Xt,{onClick:A?void 0:B,size:qe(s),children:r.jsx(pe,{title:"Value is not a reference.",error:"Click to edit"})}),k=()=>Array.isArray(n)?r.jsx(r.Fragment,{children:n.map((S,F)=>r.jsx("div",{className:"m-1 w-full",children:r.jsx(De,{onClick:A?void 0:B,size:"tiny",reference:S,onHover:h,disabled:!i,previewProperties:a})},`preview_array_ref_${t}_${F}`))}):r.jsx(pe,{error:"Data is not an array of references"});return p?r.jsxs("div",{className:"w-full",onMouseEnter:m,onMouseMove:m,onMouseLeave:b,children:[n&&!l&&x(),n&&l&&k(),I&&r.jsxs(f.Button,{onClick:B,size:"small",variant:"outlined",color:"primary",children:["Edit ",d]})]}):r.jsx(pe,{error:"The specified collection does not exist"})}Ee.addMethod(Ee.array,"uniqueInArray",function(e=n=>n,t){return this.test("uniqueInArray",t,n=>!n||n.length===new Set(n.map(e)).size)});function No(e,t,n){const o={};return Object.entries(t).forEach(([l,i])=>{o[l]=xt({property:i,customFieldValidator:n,name:l,entityId:e})}),Ee.object().shape(o)}function xt(e){const t=e.property;if(ve(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 Zi(e);if(t.dataType==="number")return Xi(e);if(t.dataType==="boolean")return ts(e);if(t.dataType==="map")return qi(e);if(t.dataType==="array")return ns(e);if(t.dataType==="date")return Ri(e);if(t.dataType==="geopoint")return Ki(e);if(t.dataType==="reference")return es(e);throw console.error("Unsupported data type in yup mapping",t),Error("Unsupported data type in yup mapping")}function qi({property:e,entityId:t,customFieldValidator:n,name:o}){const l={};return e.validation,e.properties&&Object.entries(e.properties).forEach(([i,s])=>{l[i]=xt({property:s,parentProperty:e,customFieldValidator:n,name:`${o}[${i}]`,entityId:t})}),Ee.object().shape(l)}function Zi({property:e,parentProperty:t,customFieldValidator:n,name:o,entityId:l}){let i=Ee.string();const s=e.validation;if(e.enumValues){s?.required&&(i=i.required(s?.requiredMessage?s.requiredMessage:"Required"));const a=_e(e.enumValues);i=i.oneOf((s?.required?a:[...a,null]).map(d=>d?.id??null)).nullable(!0)}if(s){if(i=s.required?i.required(s?.requiredMessage?s.requiredMessage:"Required").nullable(!0):i.notRequired().nullable(!0),s.unique&&n&&o&&(i=i.test("unique","This value already exists and should be unique",(a,d)=>n({name:o,property:e,parentProperty:t,value:a,entityId:l}))),(s.min||s.min===0)&&(i=i.min(s.min,`${e.name} must be min ${s.min} characters long`)),(s.max||s.max===0)&&(i=i.max(s.max,`${e.name} must be max ${s.max} characters long`)),s.matches){const a=typeof s.matches=="string"?On(s.matches):s.matches;a&&(i=i.matches(a,s.matchesMessage?{message:s.matchesMessage}:void 0))}s.trim&&(i=i.trim()),s.lowercase&&(i=i.lowercase()),s.uppercase&&(i=i.uppercase()),e.email&&(i=i.email(`${e.name} must be an email`)),e.url&&(i=i.url(`${e.name} must be a url`))}else i=i.notRequired().nullable(!0);return i}function Xi({property:e,parentProperty:t,customFieldValidator:n,name:o,entityId:l}){const i=e.validation;let s=Ee.number().typeError("Must be a number");return i?(s=i.required?s.required(i.requiredMessage?i.requiredMessage:"Required").nullable(!0):s.notRequired().nullable(!0),i.unique&&n&&o&&(s=s.test("unique","This value already exists and should be unique",a=>n({name:o,property:e,parentProperty:t,value:a,entityId:l}))),(i.min||i.min===0)&&(s=s.min(i.min,`${e.name} must be higher or equal to ${i.min}`)),(i.max||i.max===0)&&(s=s.max(i.max,`${e.name} must be lower or equal to ${i.max}`)),(i.lessThan||i.lessThan===0)&&(s=s.lessThan(i.lessThan,`${e.name} must be higher than ${i.lessThan}`)),(i.moreThan||i.moreThan===0)&&(s=s.moreThan(i.moreThan,`${e.name} must be lower than ${i.moreThan}`)),i.positive&&(s=s.positive(`${e.name} must be positive`)),i.negative&&(s=s.negative(`${e.name} must be negative`)),i.integer&&(s=s.integer(`${e.name} must be an integer`))):s=s.notRequired().nullable(!0),s}function Ki({property:e,parentProperty:t,customFieldValidator:n,name:o,entityId:l}){let i=Ee.object();const s=e.validation;return s?.unique&&n&&o&&(i=i.test("unique","This value already exists and should be unique",a=>n({name:o,property:e,parentProperty:t,value:a,entityId:l}))),s?.required?i=i.required(s.requiredMessage).nullable(!0):i=i.notRequired().nullable(!0),i}function Ri({property:e,parentProperty:t,customFieldValidator:n,name:o,entityId:l}){if(e.autoValue)return Ee.object().nullable();let i=Ee.date();const s=e.validation;return s?(i=s.required?i.required(s?.requiredMessage?s.requiredMessage:"Required"):i.notRequired(),s.unique&&n&&o&&(i=i.test("unique","This value already exists and should be unique",a=>n({name:o,property:e,parentProperty:t,value:a,entityId:l}))),s.min&&(i=i.min(s.min,`${e.name} must be after ${s.min}`)),s.max&&(i=i.max(s.max,`${e.name} must be before ${s.min}`))):i=i.notRequired(),i.transform(a=>a instanceof Date?a:null).nullable()}function es({property:e,parentProperty:t,customFieldValidator:n,name:o,entityId:l}){let i=Ee.object();const s=e.validation;return s?(i=s.required?i.required(s?.requiredMessage?s.requiredMessage:"Required").nullable(!0):i.notRequired().nullable(!0),s.unique&&n&&o&&(i=i.test("unique","This value already exists and should be unique",a=>n({name:o,property:e,parentProperty:t,value:a,entityId:l})))):i=i.notRequired().nullable(!0),i}function ts({property:e,parentProperty:t,customFieldValidator:n,name:o,entityId:l}){let i=Ee.boolean();const s=e.validation;return s?(i=s.required?i.required(s?.requiredMessage?s.requiredMessage:"Required").nullable(!0):i.notRequired().nullable(!0),s.unique&&n&&o&&(i=i.test("unique","This value already exists and should be unique",a=>n({name:o,property:e,parentProperty:t,value:a,entityId:l})))):i=i.notRequired().nullable(!0),i}function rs(e){return e.validation?.uniqueInArray?!0:e.dataType==="map"&&e.properties?Object.entries(e.properties).filter(([t,n])=>n.validation?.uniqueInArray):!1}function ns({property:e,parentProperty:t,customFieldValidator:n,name:o,entityId:l}){let i=Ee.array();if(e.of)if(Array.isArray(e.of)){const a=e.of.map((d,A)=>({[`${o}[${A}]`]:xt({property:d,parentProperty:e,entityId:l})})).reduce((d,A)=>({...d,...A}),{});return Ee.array().of(Ee.mixed().test("Dynamic object validation","Dynamic object validation error",(d,A)=>$e(a,A.path).validate(d)))}else{i=i.of(xt({property:e.of,parentProperty:e,entityId:l}));const a=rs(e.of);a&&(typeof a=="boolean"?i=i.uniqueInArray(d=>d,`${e.name} should have unique values within the array`):Array.isArray(a)&&a.forEach(([d,A])=>{i=i.uniqueInArray(g=>g&&g[d],`${e.name} → ${A.name??d}: should have unique values within the array`)}))}const s=e.validation;return s?(i=s.required?i.required(s?.requiredMessage?s.requiredMessage:"Required").nullable(!0):i.notRequired().nullable(!0),(s.min||s.min===0)&&(i=i.min(s.min,`${e.name} should be min ${s.min} entries long`)),s.max&&(i=i.max(s.max,`${e.name} should be max ${s.max} entries long`))):i=i.notRequired().nullable(!0),i}function gt(e){switch(e){case"xl":return 400;case"l":return 280;case"m":return 140;case"s":return 80;case"xs":return 54;default:throw Error("Missing mapping for collection size -> height")}}const os=({justifyContent:e,scrollable:t,faded:n,fullHeight:o,children:l})=>r.jsx("div",{className:f.cn("flex flex-col max-h-full w-full",{"items-start":n||t}),style:{justifyContent:e,height:o?"100%":void 0,overflow:t?"auto":void 0,WebkitMaskImage:n?"linear-gradient(to bottom, black 60%, transparent 100%)":void 0,maskImage:n?"linear-gradient(to bottom, black 60%, transparent 100%)":void 0},children:l}),Jr=c.memo(function({children:t,actions:n,size:o,selected:l,disabled:i,disabledTooltip:s,saved:a,error:d,align:A,allowScroll:g,removePadding:p,fullHeight:h,onSelect:u,width:m,hideOverflow:b=!0,showExpandIcon:y=!0}){const[w,C]=cr(),E=c.useRef(null);f.useOutsideAlerter(E,()=>{l&&u&&u(void 0)},!!(l&&u));const[B,I]=c.useState(!1),x=c.useMemo(()=>gt(o),[o]),[k,S]=c.useState(!1),[F,P]=c.useState(a),N=!i&&d;c.useEffect(()=>{a&&P(!0);const W=setTimeout(()=>{P(!1)},800);return()=>{clearTimeout(W)}},[a]);let T=0;if(!p)switch(o){case"l":case"xl":T=4;break;case"m":T=2;break;case"s":default:T=1;break}let Y;switch(A){case"right":Y="flex-end";break;case"center":Y="center";break;case"left":default:Y="flex-start"}const H=c.useCallback(()=>{if(!u)return;const W=E&&E?.current?.getBoundingClientRect();i?u(void 0):!l&&W&&u(W)},[E,u,l,i]),_=c.useCallback(W=>{H(),W.stopPropagation()},[H]);c.useEffect(()=>{if(C){const W=C.height>x;B!==W&&I(W)}},[C,B,x]);const X=!N&&l,te=!i&&g&&B,z=!i&&!g&&B,V=c.useCallback(()=>S(!0),[]),re=c.useCallback(()=>S(!1),[]);return r.jsxs("div",{ref:E,className:f.cn("transition-colors duration-100 ease-in-out",`flex relative h-full rounded-md p-${T} border border-4 border-opacity-75`,k&&!i?"bg-gray-50 dark:bg-gray-900":"",a?"bg-gray-100 bg-opacity-75 dark:bg-gray-800 dark:bg-opacity-75":"",!X&&!F&&!N?"border-transparent":"",b?"overflow-hidden":"",X?"bg-gray-50 dark:bg-gray-900":"",X&&!F?"border-primary":"",F?"border-green-500 ":"",N?"border-red-500":""),style:{justifyContent:Y,alignItems:i||!B?"center":void 0,width:m??"100%",textAlign:A},tabIndex:l||i?void 0:0,onFocus:_,onMouseEnter:V,onMouseMove:V,onMouseLeave:re,children:[r.jsxs(ne,{children:[h&&!z&&t,(!h||z)&&r.jsx(os,{fullHeight:h??!1,justifyContent:Y,scrollable:te??!1,faded:z,children:!h&&r.jsx("div",{ref:w,style:{display:"flex",width:"100%",justifyContent:Y,height:h?"100%":void 0},children:t})})]}),n,i&&k&&s&&r.jsx("div",{className:"absolute top-1 right-1 text-xs",children:r.jsx(f.Tooltip,{title:s,children:r.jsx(f.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);function ls(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 is=c.memo(function({propertyKey:t,customFieldValidator:n,value:o,property:l,align:i,width:s,height:a,path:d,entity:A,readonly:g,disabled:p}){const h=Z(),{onValueChange:u,size:m,selectedCell:b,select:y,setPopupCell:w}=Cs(),C=b?.propertyKey===t&&b?.entity.path===A.path&&b?.entity.id===A.id,[E,B]=c.useState(o),I=c.useRef(o),[x,k]=c.useState(),[S,F]=c.useState(!1),P=c.useCallback(()=>{F(!0),setTimeout(()=>{F(!1)},100)},[]),N=!!l.Field,T=!!l.Preview,Y=it(l),H=typeof l.disabled=="object"?l.disabled.disabledMessage:void 0,_=g||p||!!l.disabled,X=c.useMemo(()=>xt({property:l,entityId:A.id,customFieldValidator:n,name:t}),[A.id,l,t]);c.useEffect(()=>{oe(o,I.current)||(k(void 0),B(o),I.current=o,P())},[P,o]);const te=Q=>{oe(Q,I.current)||(F(!1),X.validate(Q).then(()=>{k(void 0),I.current=Q,u&&u({value:Q,propertyKey:t,setError:k,onValueUpdated:P,entity:A,fullPath:d,context:h})}).catch(D=>{k(D)}))};c.useEffect(()=>{X.validate(E).then(()=>k(void 0)).catch(Q=>{k(Q)})},[E,X,t,l,A]);const z=Q=>{let D;Q===void 0?D=null:D=Q,B(D),te(D)};xe({property:l,value:E,setValue:z});const V=c.useCallback(Q=>{y(Q?{width:s,height:a,entity:A,cellRect:Q,propertyKey:t}:void 0)},[A,a,t,y,s]),re=Q=>{w&&w(Q?{width:s,height:a,entity:A,cellRect:Q,propertyKey:t}:void 0)};let W,J=!1,se=!1,U=!0,M=!1,$=!1,K=!0;const L=!_&&x;if(g||Y)return r.jsx(Jr,{size:m,width:s,saved:S,value:E,align:i??"left",fullHeight:!1,disabledTooltip:H??(Y?"Read only":void 0),disabled:!0,children:r.jsx(me,{width:s,height:gt(m),propertyKey:t,property:l,entity:A,value:E,size:qe(m)})},`${t}_${A.path}_${A.id}`);if(!N&&(!T||C)){if(ls(l))W=r.jsx(Wi,{error:x,disabled:_,focused:C,selected:C,openPopup:w?re:void 0,property:l,entity:A,path:d,value:E,previewSize:qe(m),updateValue:z,propertyKey:t}),K=!1,se=!0,$=!0,M=!0;else if(C&&l.dataType==="number"){const D=l;D.enumValues?(W=r.jsx(Wr,{name:t,multiple:!1,disabled:_,focused:C,valueType:"number",small:qe(m)!=="medium",enumValues:D.enumValues,error:x,internalValue:E,updateValue:z}),$=!0):(W=r.jsx(Di,{align:i,error:x,focused:C,disabled:_,value:E,updateValue:z}),J=!0)}else if(C&&l.dataType==="string"){const D=l;if(D.enumValues)W=r.jsx(Wr,{name:t,multiple:!1,focused:C,disabled:_,valueType:"string",small:qe(m)!=="medium",enumValues:D.enumValues,error:x,internalValue:E,updateValue:z}),$=!0;else if(!D.storage){const Ie=!!D.multiline||!!D.markdown;W=r.jsx(Mi,{error:x,disabled:_,multiline:Ie,focused:C,value:E,updateValue:z}),J=!0}}else if(l.dataType==="boolean")W=r.jsx(Oi,{error:x,disabled:_,focused:C,internalValue:E,updateValue:z});else if(l.dataType==="date")W=r.jsx(Vi,{name:t,error:x,disabled:_,mode:l.mode,focused:C,internalValue:E,updateValue:z}),$=!0,U=!1,J=!1;else if(l.dataType==="reference")typeof l.path=="string"&&(W=r.jsx(Fo,{name:t,internalValue:E,updateValue:z,disabled:_,size:m,path:l.path,multiselect:!1,previewProperties:l.previewProperties,title:l.name,forceFilter:l.forceFilter})),J=!1;else if(l.dataType==="array"){const D=l;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"?C&&D.of.enumValues&&(W=r.jsx(Wr,{name:t,multiple:!0,disabled:_,focused:C,small:qe(m)!=="medium",valueType:D.of.dataType,enumValues:D.of.enumValues,error:x,internalValue:E,updateValue:z}),J=!0,$=!0,U=!1):D.of.dataType==="reference"&&(typeof D.of.path=="string"&&(W=r.jsx(Fo,{name:t,disabled:_,internalValue:E,updateValue:z,size:m,multiselect:!0,path:D.of.path,previewProperties:D.of.previewProperties,title:D.of.name,forceFilter:D.of.forceFilter})),J=!1))}}return W||(J=!1,se=C&&!W&&!_&&!Y,W=r.jsx(me,{width:s,height:a,entity:A,propertyKey:t,value:E,property:l,size:qe(m)})),r.jsx(Jr,{size:m,width:s,onSelect:V,selected:C,disabled:_||Y,disabledTooltip:H??"Disabled",removePadding:M,fullHeight:$,saved:S,error:x,align:i,allowScroll:J,showExpandIcon:se,value:E,hideOverflow:U,actions:K&&r.jsx(So,{showError:L,disabled:_,showExpandIcon:se,selected:C,openPopup:_?void 0:re}),children:W},`cell_${t}_${A.path}_${A.id}`)},ss);function ss(e,t){return e.height===t.height&&e.propertyKey===t.propertyKey&&e.align===t.align&&e.width===t.width&&oe(e.property,t.property)&&oe(e.value,t.value)&&oe(e.entity.id,t.entity.id)&&oe(e.entity.values,t.entity.values)}function It({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(f.CircularProgress,{...t}),e&&r.jsx(f.Typography,{color:"secondary",variant:"caption",className:"text-center",children:e})]})})}const as=c.memo(function({resizeHandleRef:t,columnIndex:n,isResizingIndex:o,sort:l,onColumnSort:i,onFilterUpdate:s,filter:a,column:d,onClickResizeColumn:A,createFilterField:g,AdditionalHeaderWidget:p}){const[h,u]=c.useState(!1),[m,b]=c.useState(!1),[y,w]=c.useState(!1),C=c.useCallback(k=>{b(!0)},[]),E=c.useCallback((k,S)=>{s(d,k),S!==void 0&&b(S)},[d,s]),B=o===n,x=!(o!==n&&o>0)&&(h||B);return r.jsx(ne,{children:r.jsxs("div",{className:f.cn("flex py-0 px-3 h-full text-xs uppercase font-semibold relative select-none items-center bg-gray-50 dark:bg-gray-900","text-gray-600 hover:text-gray-800 dark:text-gray-400 dark:hover:text-gray-200 ","hover:bg-gray-100 dark:hover:bg-gray-800 hover:bg-opacity-50 dark:hover:bg-opacity-50",d.frozen?"sticky left-0 z-10":"relative z-0"),style:{left:d.frozen?0:void 0,minWidth:d.width,maxWidth:d.width},onMouseEnter:()=>u(!0),onMouseMove:()=>u(!0),onMouseLeave:()=>u(!1),children:[r.jsx("div",{className:"overflow-hidden flex-grow",children:r.jsxs("div",{className:`flex items-center justify-${d.headerAlign} flex-row`,children:[d.icon&&d.icon(h||m),r.jsx("div",{className:"truncate -webkit-box w-full mx-1 overflow-hidden",style:{WebkitBoxOrient:"vertical",WebkitLineClamp:2,justifyContent:d.align},children:d.title})]})}),r.jsxs(r.Fragment,{children:[p&&r.jsx(p,{onHover:h||m}),d.sortable&&(l||x||m)&&r.jsx(f.Badge,{color:"secondary",invisible:!l,children:r.jsxs(f.IconButton,{size:"small",className:h||m?"bg-white dark:bg-gray-950":void 0,onClick:()=>{i(d.key)},children:[!l&&r.jsx(f.ArrowUpwardIcon,{}),l==="asc"&&r.jsx(f.ArrowUpwardIcon,{}),l==="desc"&&r.jsx(f.ArrowUpwardIcon,{className:"rotate-180"})]})})]}),d.filter&&g&&r.jsx("div",{children:r.jsx(f.Badge,{color:"secondary",invisible:!a,children:r.jsx(f.Popover,{open:m,onOpenChange:b,className:y?"hidden":void 0,modal:!0,trigger:r.jsx(f.IconButton,{className:h||m?"bg-white dark:bg-gray-950":void 0,size:"small",onClick:C,children:r.jsx(f.FilterListIcon,{size:"small"})}),children:r.jsx(cs,{column:d,filter:a,onHover:h,onFilterUpdate:E,createFilterField:g,hidden:y,setHidden:w})})})}),d.resizable&&r.jsx("div",{ref:t,className:f.cn("absolute h-full w-[6px] top-0 right-0 cursor-col-resize",x&&"bg-gray-300 dark:bg-gray-700"),onMouseDown:A?()=>A(n,d):void 0})]})})},oe);function cs({column:e,onFilterUpdate:t,filter:n,onHover:o,createFilterField:l,hidden:i,setHidden:s}){const a=e.key,[d,A]=c.useState(n);if(c.useEffect(()=>{A(n)},[n]),!e.filter)return null;const g=()=>{t(d,!1)},p=m=>{t(void 0,!1)},h=!!n,u=l({id:a,filterValue:d,setFilterValue:A,column:e,hidden:i,setHidden:s});return u?r.jsxs("div",{className:"text-gray-900 dark:text-white",children:[r.jsx("div",{className:f.cn(f.defaultBorderMixin,"py-4 px-6 text-xs font-semibold uppercase border-b"),children:e.title??a}),u&&r.jsx("div",{className:"m-4",children:u}),r.jsxs("div",{className:"flex justify-end m-4",children:[r.jsx(f.Button,{className:"mr-4",disabled:!h,variant:"text",color:"primary",type:"reset","aria-label":"filter clear",onClick:p,children:"Clear"}),r.jsx(f.Button,{variant:"outlined",color:"primary",onClick:g,children:"Filter"})]})]}):null}const ds=({columns:e,currentSort:t,onColumnSort:n,onFilterUpdate:o,sortByProperty:l,filter:i,onColumnResize:s,onColumnResizeEnd:a,createFilterField:d,AddColumnComponent:A})=>{const g=e.map(()=>c.createRef()),[p,h]=c.useState(-1),u=c.useCallback((I,x,k)=>{const S=e[I],F=100,P=800,N=x>P?P:x<F?F:x,T={width:N,key:S.key,column:{...S,width:N}};k?a(T):s(T)},[e,s,a]),m=c.useCallback(I=>{if(p>=0){const x=g[p].current?.parentElement?.getBoundingClientRect().left;return x?I.clientX-x:void 0}},[g,p]),b=c.useCallback(I=>{document.body.style.cursor=I?"col-resize":"auto"},[]),y=c.useCallback(I=>{I.stopPropagation(),I.preventDefault();const x=m(I);x&&u(p,x,!1)},[u,m,p]),w=c.useCallback(I=>{I.stopPropagation(),I.preventDefault();const x=m(I);x&&u(p,x,!0),h(-1),b(!1)},[u,m,p,b]),C=c.useCallback(()=>{document.removeEventListener("mousemove",y),document.removeEventListener("mouseup",w)},[y,w]),E=c.useCallback(()=>{document.addEventListener("mousemove",y),document.addEventListener("mouseup",w)},[y,w]);c.useEffect(()=>(p>=0?E():C(),()=>{C()}),[E,p,C]);const B=c.useCallback(I=>{h(I),b(!0)},[b]);return r.jsxs("div",{className:f.cn(f.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((I,x)=>{const k=e[x],S=k&&i&&i[k.key]?i[k.key]:void 0;return r.jsx(ne,{children:r.jsx(as,{resizeHandleRef:g[x],columnIndex:x,isResizingIndex:p,onFilterUpdate:o,filter:S,sort:l===k.key?t:void 0,onColumnSort:n,onClickResizeColumn:B,column:k,createFilterField:d,AdditionalHeaderWidget:k.AdditionalHeaderWidget})},"header_"+k.key)}),A&&r.jsx(A,{})]})},As=c.memo(function({rowData:t,rowIndex:n,children:o,onRowClick:l,size:i,style:s,hoverRow:a,rowClassName:d}){const A=c.useCallback(g=>{console.debug("VirtualTableRow click"),l&&l({rowData:t,rowIndex:n,event:g})},[l,t,n]);return r.jsx("div",{className:f.cn("flex min-w-full text-sm border-b border-gray-200 dark:border-gray-800 border-opacity-40 dark:border-opacity-40",d?d(t):"",{"hover:bg-opacity-95":a,"cursor-pointer":l}),onClick:A,style:{...s,height:gt(i),width:"fit-content"},children:o})},oe),fs=c.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)=>oe(e,t)),Kt=c.createContext({});Kt.displayName="VirtualListContext";const us=c.forwardRef(({children:e,...t},n)=>r.jsx(Kt.Consumer,{children:o=>{const l=o.customView;return r.jsxs(r.Fragment,{children:[r.jsx("div",{id:"virtual-table",style:{position:"relative",height:"100%"},children:r.jsxs("div",{ref:n,...t,style:{...t?.style,minHeight:"100%",position:"relative"},children:[r.jsx(ds,{...o}),!l&&e]})}),l&&r.jsx("div",{style:{position:"sticky",top:"56px",flexGrow:1,height:"calc(100% - 56px)",marginTop:"calc(56px - 100vh)",left:0},children:l})]})}})),Po=c.memo(function({data:t,onResetPagination:n,onEndReached:o,size:l="m",columns:i,onRowClick:s,onColumnResize:a,filter:d,checkFilterCombination:A,onFilterUpdate:g,sortBy:p,error:h,emptyComponent:u,onSortByUpdate:m,loading:b,cellRenderer:y,hoverRow:w,createFilterField:C,rowClassName:E,className:B,endAdornment:I,AddColumnComponent:x}){const k=p?p[0]:void 0,S=p?p[1]:void 0,[F,P]=c.useState(i),N=c.useRef(null),T=c.useRef(0);c.useEffect(()=>{P(i)},[i]);const[Y,H]=cr(),_=c.useCallback(Q=>{P(F.map(D=>D.key===Q.column.key?Q.column:D))},[F]),X=c.useCallback(Q=>{P(F.map(D=>D.key===Q.column.key?Q.column:D)),a&&a(Q)},[F,a]),te=c.useRef();c.useEffect(()=>{te.current=d},[d]);const z=c.useCallback(()=>{T.current=0,N.current&&N.current.scrollTo(N.current?.scrollLeft,0)},[]),V=c.useCallback(Q=>{const D=k===Q&&S==="desc",Ae=k===Q&&S==="asc"?"desc":D?void 0:"asc",ae=D?void 0:Q,Se=te.current,Ze=Ae&&ae?[ae,Ae]:void 0;Se&&A&&!A(Se,Ze)&&g&&g(void 0),n&&n(),m&&m(Ze),z()},[A,S,g,n,m,z,k]),re=c.useCallback(()=>{T.current=0,m&&m(void 0)},[m]),W=Math.max((t?.length??0)*gt(l)-H.height,0),J=c.useCallback(Q=>{o&&(t?.length??0)>0&&Q>T.current+600&&(T.current=Q,o())},[t?.length,o]),se=c.useCallback(({scrollOffset:Q,scrollUpdateWasRequested:D})=>{!D&&Q>=W-600&&J(Q)},[W,J]),U=c.useCallback((Q,D)=>{T.current=0;const Ie=te.current;let Ae=Ie?{...Ie}:{};D?Ae[Q.key]=D:delete Ae[Q.key],!A||A(Ae,k&&S?[k,S]:void 0)||(Ae=D?{[Q.key]:D}:{}),g&&g(Ae),Q.key!==k&&re()},[A,S,g,re,k]),M=c.useCallback(()=>r.jsxs("div",{className:"h-full flex flex-col items-center justify-center sticky left-0",children:[r.jsx(f.Typography,{variant:"h6",children:"Error fetching data from the data source"}),h?.message&&r.jsx(f.Markdown,{className:"px-4 break-all",source:h.message})]}),[h?.message]),$=c.useCallback(()=>b?r.jsx(It,{}):r.jsxs("div",{className:"flex flex-col overflow-auto items-center justify-center p-2 gap-2 h-full",children:[r.jsx(f.AssignmentIcon,{}),u]}),[u,b]),K=!b&&(t?.length??0)===0,L=h?M():K?$():void 0;return r.jsx("div",{ref:Y,className:f.cn("h-full w-full",B),children:r.jsx(Kt.Provider,{value:{data:t,size:l,cellRenderer:y,columns:F,currentSort:S,onRowClick:s,customView:L,onColumnResize:_,onColumnResizeEnd:X,filter:te.current,onColumnSort:V,onFilterUpdate:U,sortByProperty:k,hoverRow:w??!1,createFilterField:C,rowClassName:E,endAdornment:I,AddColumnComponent:x},children:r.jsx(gs,{outerRef:N,width:H.width,height:H.height,itemCount:(t?.length??0)+(I?1:0),onScroll:se,includeAddColumn:!!x,itemSize:gt(l)},l)})})},oe);function gs({outerRef:e,width:t,height:n,itemCount:o,onScroll:l,itemSize:i,includeAddColumn:s}){const a=c.useCallback(({index:d,style:A})=>r.jsx(Kt.Consumer,{children:({onRowClick:g,data:p,columns:h,size:u="m",cellRenderer:m,hoverRow:b,rowClassName:y,endAdornment:w})=>{if(w&&d===(p??[]).length)return r.jsx("div",{style:{...A,height:"auto",position:"sticky",bottom:0,zIndex:1},children:w});const C=p&&p[d];return r.jsxs(As,{rowData:C,rowIndex:d,onRowClick:g,columns:h,hoverRow:b,rowClassName:y,style:{...A,top:`calc(${A.top}px + 48px)`},size:u,children:[h.map((E,B)=>{const I=C&&C[E.key];return r.jsx(fs,{dataKey:E.key,cellRenderer:m,column:E,columns:h,rowData:C,cellData:I,rowIndex:d,columnIndex:B},`cell_${E.key}`)}),s&&r.jsx("div",{className:"w-20"})]},`row_${d}`)}}),[]);return r.jsx(Cl.FixedSizeList,{outerRef:e,innerElementType:us,width:t,height:n,overscanCount:4,itemCount:o,onScroll:l,itemSize:i,children:a})}const qr=c.memo(function({entity:t,collection:n,fullPath:o,width:l,frozen:i,isSelected:s,selectionEnabled:a,size:d,highlightEntity:A,onCollectionChange:g,unhighlightEntity:p,actions:h=[],hideId:u,selectionController:m}){const b=Te(),y=Z(),w=c.useCallback(k=>{m?.toggleEntitySelection(t)},[t,m?.toggleEntitySelection]),C=c.useCallback(k=>{k.stopPropagation(),m?.toggleEntitySelection(t)},[t,m?.toggleEntitySelection]),E=h.length>0,B=h.some(k=>k.collapsed||k.collapsed===void 0),I=h.filter(k=>k.collapsed||k.collapsed===void 0),x=h.filter(k=>k.collapsed===!1);return r.jsxs("div",{onClick:C,className:f.cn("h-full flex items-center justify-center flex-col bg-gray-50 dark:bg-gray-900 bg-opacity-90 dark:bg-opacity-90 z-10",i?"sticky left-0":""),style:{width:l,position:i?"sticky":"initial",left:i?0:"initial",contain:"strict"},children:[(E||a)&&r.jsxs("div",{className:"w-34 flex justify-center",children:[x.map((k,S)=>r.jsx(f.Tooltip,{title:k.name,children:r.jsx(f.IconButton,{onClick:F=>{F.stopPropagation(),k.onClick({entity:t,fullPath:o,collection:n,context:y,selectionController:m,highlightEntity:A,unhighlightEntity:p,onCollectionChange:g})},size:b?"medium":"small",children:k.icon})},S)),B&&r.jsx(f.Menu,{trigger:r.jsx(f.IconButton,{size:b?"medium":"small",children:r.jsx(f.MoreVertIcon,{})}),children:I.map((k,S)=>r.jsxs(f.MenuItem,{onClick:F=>{F.stopPropagation(),k.onClick({entity:t,fullPath:o,collection:n,context:y,selectionController:m,highlightEntity:A,unhighlightEntity:p,onCollectionChange:g})},children:[k.icon,k.name]},S))}),a&&r.jsx(f.Tooltip,{title:`Select ${t.id}`,children:r.jsx(f.Checkbox,{size:b?"medium":"small",checked:s,onCheckedChange:w})})]}),!u&&d!=="xs"&&r.jsx("div",{className:"w-[138px] text-center overflow-hidden truncate",children:t?r.jsxs(f.Typography,{onClick:k=>{k.stopPropagation()},className:"font-mono select-all",variant:"caption",color:"secondary",children:[" ",t.id," "]}):r.jsx(f.Skeleton,{})})]})},oe);function hs(e){const t=Te(),n=!e.forceFilter&&e.filterIsSet&&e.clearFilter&&r.jsxs(f.Button,{variant:"outlined",className:"h-fit-content","aria-label":"filter clear",onClick:e.clearFilter,size:"small",children:[r.jsx(f.FilterListOffIcon,{}),"Clear filter"]}),o=r.jsx(f.Select,{value:e.size,className:"w-16 h-10",size:"small",onValueChange:l=>e.onSizeChanged(l),renderValue:l=>r.jsx("div",{className:"font-medium",children:l.toUpperCase()}),children:["xs","s","m","l","xl"].map(l=>r.jsx(f.SelectItem,{value:l,className:"w-12 font-medium text-center",children:l.toUpperCase()},l))});return r.jsxs("div",{className:f.cn(f.defaultBorderMixin,"no-scrollbar min-h-[56px] overflow-x-auto 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",children:[e.title&&r.jsx("div",{className:"hidden lg:block",children:e.title}),o,e.actionsStart,n]}),r.jsxs("div",{className:"flex items-center gap-2",children:[t&&r.jsx("div",{className:"w-[22px]",children:e.loading&&r.jsx(f.CircularProgress,{size:"small"})}),e.onTextSearch&&r.jsx(f.SearchBar,{onTextSearch:e.onTextSearch,expandable:!0},"search-bar"),e.actions]})]})}const Qo={"==":"==","!=":"!=",">":">","<":"<",">=":">=","<=":"<=",in:"In","not-in":"Not in","array-contains":"Contains","array-contains-any":"Contains Any"},Zr=["array-contains-any","in","not-in"];function ps({name:e,value:t,setValue:n,isArray:o,path:l,title:i,previewProperties:s,setHidden:a}){const d=o?["array-contains"]:["==","!=",">","<",">=","<="],[A,g]=c.useState(!1);o?d.push("array-contains-any"):d.push("in","not-in");const[p,h]=t||[d[0],void 0],[u,m]=c.useState(p),[b,y]=c.useState(h),w=b?Array.isArray(b)?b.map(N=>N instanceof Fe?N.id:null).filter(Boolean):[b.id]:[];function C(N,T){const Y=Zr.includes(u),H=Zr.includes(N);let _=T;Y!==H&&(_=H?_ instanceof Fe?[_]:[]:void 0),m(N),y(_);const X=_!==null&&Array.isArray(_)?_.length>0:_!==void 0;n(N&&X?[N,_]:void 0)}const E=ie(),B=c.useMemo(()=>l?E.getCollection(l):void 0,[l]),I=N=>{C(u,Ge(N))},x=N=>{C(u,N.map(T=>Ge(T)))},k=Zr.includes(u),S=mt({multiselect:k,path:l,collection:B,onSingleEntitySelected:I,onMultipleEntitiesSelected:x,selectedEntityIds:w,onClose:()=>{a(!1)}}),F=()=>{a(!0),S.open()},P=N=>r.jsx("div",{className:"mb-0.5",onMouseEnter:()=>g(!0),onMouseMove:()=>g(!0),onMouseLeave:()=>g(!1),children:r.jsx(De,{disabled:!l,previewProperties:s,size:"medium",onClick:F,reference:N,onHover:A,allowEntityNavigation:!1})});return r.jsxs("div",{className:"flex w-[440px] flex-row",children:[r.jsx("div",{className:"w-[120px]",children:r.jsx(f.Select,{value:u,onValueChange:N=>{C(N,b)},renderValue:N=>Qo[N],children:d.map(N=>r.jsx(f.SelectItem,{value:N,children:Qo[N]},N))})}),r.jsxs("div",{className:"flex-grow ml-2 h-full",children:[b&&Array.isArray(b)&&r.jsx("div",{children:b.map((N,T)=>P(N))}),b&&!Array.isArray(b)&&r.jsx("div",{children:P(b)}),(!b||Array.isArray(b)&&b.length===0)&&r.jsx(f.Button,{onClick:F,variant:"outlined",className:"h-full w-full",children:k?"Select references":"Select reference"})]})]})}const To={"==":"==","!=":"!=",">":">","<":"<",">=":">=","<=":"<=",in:"In","not-in":"Not in","array-contains":"Contains","array-contains-any":"Any"},Xr=["array-contains-any","in","not-in"];function ms({name:e,value:t,setValue:n,dataType:o,isArray:l,enumValues:i,title:s}){const a=l?["array-contains"]:["==","!=",">","<",">=","<="];i&&(l?a.push("array-contains-any"):a.push("in","not-in"));const[d,A]=t||[a[0],void 0],[g,p]=c.useState(d),[h,u]=c.useState(A);function m(y,w){let C=w;const E=Xr.includes(g),B=Xr.includes(y);E!==B&&(C=B?typeof w=="string"||typeof w=="number"?[w]:[]:""),typeof C=="number"&&isNaN(C)&&(C=void 0),p(y),u(C);const I=C!==null&&Array.isArray(C)?C.length>0:C!==void 0;n(y&&I?[y,C]:void 0)}const b=Xr.includes(g);return r.jsxs("div",{className:"flex w-[440px] items-center",children:[r.jsx("div",{className:"w-[80px]",children:r.jsx(f.Select,{value:g,position:"item-aligned",onValueChange:y=>{m(y,h)},renderValue:y=>To[y],children:a.map(y=>r.jsx(f.SelectItem,{value:y,children:To[y]},y))})}),r.jsxs("div",{className:"flex-grow ml-2",children:[!i&&r.jsx(f.TextField,{type:o==="number"?"number":void 0,value:h!==void 0?String(h):"",onChange:y=>{const w=o==="number"?parseFloat(y.target.value):y.target.value;m(g,w)},endAdornment:h&&r.jsx(f.IconButton,{className:"absolute right-3 top-2",onClick:y=>m(g,void 0),children:r.jsx(f.ClearIcon,{})})}),i&&r.jsx(f.Select,{position:"item-aligned",value:h!==void 0?Array.isArray(h)?h.map(y=>String(y)):String(h):l?[]:"",onValueChange:y=>{m(g,o==="number"?parseInt(y):y)},multiple:b,endAdornment:h&&r.jsx(f.IconButton,{className:"absolute right-3 top-2",onClick:y=>m(g,void 0),children:r.jsx(f.ClearIcon,{})}),renderValue:y=>r.jsx(we,{enumKey:y,enumValues:i,size:"small"},`select_value_${e}_${y}`),children:i.map(y=>r.jsx(f.SelectItem,{value:String(y.id),children:r.jsx(we,{enumKey:String(y.id),enumValues:i,size:"small"})},`select_value_${e}_${y.id}`))})]})]})}function bs({name:e,title:t,value:n,setValue:o}){function l(a){o(a!==void 0?["==",a]:void 0)}const i=n&&n[1],s=!!n;return r.jsx("div",{className:"w-[200px]",children:r.jsx(f.BooleanSwitchWithLabel,{value:i,allowIndeterminate:!0,onValueChange:a=>l(a===null?void 0:a),label:s?i?`${t} is true`:`${t} is false`:"No filter"})})}const Mo={"==":"==","!=":"!=",">":">","<":"<",">=":">=","<=":"<=","not-in":"not in",in:"in","array-contains":"Contains","array-contains-any":"Any"},Do=["array-contains-any","in"];function ys({name:e,isArray:t,mode:n,value:o,setValue:l,title:i}){const{locale:s}=Z(),a=t?["array-contains"]:["==","!=",">","<",">=","<="],[d,A]=o||[a[0],void 0],[g,p]=c.useState(d),[h,u]=c.useState(A);function m(b,y){let w=y;const C=Do.includes(g),E=Do.includes(b);C!==E&&(w=E?y?[y]:[]:""),p(b),u(w===null?void 0:w);const B=w!==null&&Array.isArray(w)?w.length>0:w!==void 0;l(b&&B?[b,w]:void 0)}return r.jsxs("div",{className:"flex w-[440px] items-center",children:[r.jsx("div",{className:"w-[80px]",children:r.jsx(f.Select,{value:g,onValueChange:b=>{m(b,h)},renderValue:b=>Mo[b],children:a.map(b=>r.jsx(f.SelectItem,{value:b,children:Mo[b]},b))})}),r.jsx("div",{className:"flex-grow ml-2",children:r.jsx(f.DateTimeField,{mode:n,size:"medium",locale:s,value:h,onChange:b=>{m(g,b===null?void 0:b)},clearable:!0})})]})}const Oo="collectionGroupParent";function Vo(e,t){return c.useMemo(()=>e.propertiesOrder?Go(e,e.propertiesOrder):vs(e,t),[e,t])}function Go(e,t){return t.flatMap(n=>{const o=e.properties[n];return o?o.hideFromCollection?[null]:o.disabled&&typeof o.disabled=="object"&&o.disabled.hidden?[null]:o.dataType==="map"&&o.spreadChildren&&o.properties?Kr(o,n):[{key:n,disabled:!!o.disabled||!!o.readOnly}]:e.additionalFields?.find(i=>i.key===n)?[{key:n,disabled:!0}]:e.subcollections&&e.subcollections.find(s=>_r(s)===n)?[{key:n,disabled:!0}]:e.collectionGroup&&n===Oo?[{key:n,disabled:!0}]:[null]}).filter(Boolean)}function vs(e,t){const n=Object.keys(e.properties),o=e.additionalFields??[],l=e.subcollections??[],i=[...n,...o.map(s=>s.key)];if(t){const s=l.map(a=>_r(a));i.push(...s.filter(a=>!i.includes(a)))}return e.collectionGroup&&i.push(Oo),Go(e,i)}function Kr(e,t,n){return e.dataType==="map"&&e.spreadChildren&&e.properties?Object.entries(e.properties).flatMap(([o,l])=>Kr(l,`${t}.${o}`,n||!!e.disabled||!!e.readOnly)):[{key:t,disabled:n||!!e.disabled||!!e.readOnly}]}const ws={},Yo=c.createContext(ws),Cs=()=>c.useContext(Yo),Rr=c.memo(function({forceFilter:t,actionsStart:n,actions:o,title:l,tableRowActionsBuilder:i,uniqueFieldValidator:s,getPropertyFor:a,onValueChange:d,selectionController:A,highlightedEntities:g,onEntityClick:p,onColumnResize:h,onSizeChanged:u,textSearchEnabled:m=!1,hoverRow:b=!0,inlineEditing:y=!1,additionalFields:w,displayedColumnIds:C,defaultSize:E,properties:B,tableController:{data:I,dataLoading:x,noMoreToLoad:k,dataLoadingError:S,filterValues:F,setFilterValues:P,sortBy:N,setSortBy:T,setSearchString:Y,clearFilter:H,itemCount:_,setItemCount:X,pageSize:te=50,paginationEnabled:z,checkFilterCombination:V,setPopupCell:re},filterable:W=!0,sortable:J=!0,endAdornment:se,AddColumnComponent:U,AdditionalHeaderWidget:M,additionalIDHeaderWidget:$,emptyComponent:K,getIdColumnWidth:L}){const Q=Te(),D=!!t,Ie=A?.selectedEntities?.length>0?A?.selectedEntities:g,Ae=Z(),[ae,Se]=c.useState(E??"m"),[Ze,ze]=c.useState(void 0),Ve=Ie?.map(j=>j.id),Ft=!!F&&Object.keys(F).length>0,bt=()=>{!z||x||k||_!==void 0&&X?.(_+te)},Nt=c.useCallback(()=>{X?.(te)},[te]),Xe=c.useCallback(({rowData:j})=>{if(console.debug("EntityCollectionTable click"),!y)return p&&p(j)},[p,y]),Ke=c.useCallback(j=>{u&&u(j),Se(j)},[]),Pt=c.useCallback(j=>Y?.(j),[]),Re=c.useMemo(()=>w?w.map(j=>({[j.key]:j})).reduce((j,ge)=>({...j,...ge}),{}):{},[w]);c.useEffect(()=>{const j=ge=>{ge.keyCode===27&&Tt()};return document.addEventListener("keydown",j,!1),()=>{document.removeEventListener("keydown",j,!1)}});const Qt=c.useCallback(j=>{ze(j)},[]),Tt=c.useCallback(()=>{ze(void 0)},[]),G=s,O=c.useCallback(({column:j,columnIndex:ge,rowData:de,rowIndex:Me})=>{const le=de,Ue=j.key;let Le=j.custom?.disabled;const bn=le.values?$e(le.values,Ue):void 0,ot=a?.({propertyKey:Ue,propertyValue:bn,entity:le})??j.custom.resolvedProperty;return ot?.disabled||(Le=!1),ot?r.jsx(ne,{children:le?r.jsx(is,{readonly:!y,align:j.align??"left",propertyKey:Ue,property:ot,value:le?.values?$e(le.values,Ue):void 0,customFieldValidator:G,columnIndex:ge,width:j.width,height:gt(ae),entity:le,disabled:Le,path:le.path},`property_table_cell_${le.id}_${Ue}`):Ye()}):null},[G,y,ae,Ve]),q=c.useCallback(({column:j,rowData:ge,width:de})=>{const Me=ge,le=Re[j.key],Ue=le.dependencies?Object.entries(Me.values).filter(([ot,yl])=>le.dependencies.includes(ot)).reduce((ot,yl)=>({...ot,...yl}),{}):Me,Le=le.Builder;if(!Le&&!le.value)throw new Error("When using additional fields you need to provide a Builder or a value");const bn=Le?r.jsx(Le,{entity:Me,context:Ae}):r.jsx(r.Fragment,{children:le.value?.({entity:Me,context:Ae})});return r.jsx(Jr,{width:de,size:ae,value:Ue,selected:!1,disabled:!0,align:"left",allowScroll:!1,showExpandIcon:!1,disabledTooltip:"This column can't be edited directly",children:r.jsx(ne,{children:bn})},`additional_table_cell_${Me.id}_${j.key}`)},[Re,ae,Ve]),R=c.useMemo(()=>{const j=Object.entries(B).flatMap(([de,Me])=>Kr(Me,de)).map(({key:de,disabled:Me})=>{const le=xr(B,de);if(!le)throw Error("Internal error: no property found in path "+de);const Ue=zo(le);return{key:de,align:Ti(le),icon:Le=>he(le,"small"),title:le.name??de,sortable:J&&(t?Object.keys(t).includes(de):!0),filter:!D&&Ue,width:wo(le),resizable:!0,custom:{resolvedProperty:le,disabled:Me},AdditionalHeaderWidget:({onHover:Le})=>M?r.jsx(M,{property:le,propertyKey:de,onHover:Le}):void 0}}),ge=w?w.map(de=>({key:de.key,align:"left",sortable:!1,title:de.name,width:de.width??200})):[];return[...j,...ge]},[w,D,t,B,J]),ee=c.useMemo(()=>({key:"id_ewcfedcswdf3",width:L?.()??(Q?160:130),title:"ID",resizable:!1,frozen:Q,headerAlign:"center",align:"center",AdditionalHeaderWidget:()=>$}),[L,Q]),ce=c.useMemo(()=>[ee,...C.map(j=>R.find(ge=>ge.key===j.key)).filter(Boolean)],[R,C,ee]),Oe=c.useCallback(j=>{const ge=j.column,de=j.columns,Me=ge.key;if(j.columnIndex===0)return i?i({entity:j.rowData,size:ae,width:ge.width,frozen:ge.frozen}):r.jsx(qr,{entity:j.rowData,width:ge.width,frozen:ge.frozen,isSelected:!1,size:ae});if(Re[Me])return q(j);if(j.columnIndex<de.length+1)return O(j);throw Error("Internal: columns not mapped properly")},[Re,i,ae,q,O]),Mt=c.useCallback(j=>{P?.({...j,...t})},[t]);return r.jsx(Yo.Provider,{value:{setPopupCell:re,select:Qt,onValueChange:d,size:ae,selectedCell:Ze,selectedEntityIds:Ve},children:r.jsxs("div",{className:"h-full w-full flex flex-col bg-white dark:bg-gray-950",children:[r.jsx(hs,{forceFilter:D,filterIsSet:Ft,onTextSearch:m?Pt:void 0,clearFilter:H,size:ae,onSizeChanged:Ke,title:l,actionsStart:n,actions:o,loading:x}),r.jsx(Po,{data:I,columns:ce,cellRenderer:Oe,onRowClick:y?void 0:p?Xe:void 0,onEndReached:bt,onResetPagination:Nt,error:S,paginationEnabled:z,onColumnResize:h,size:ae,loading:x,filter:F,onFilterUpdate:P?Mt:void 0,sortBy:N,onSortByUpdate:T,hoverRow:b,emptyComponent:K,checkFilterCombination:V,createFilterField:W?Es:void 0,rowClassName:c.useCallback(j=>Ve?.includes(j.id)?"bg-gray-100 bg-opacity-75 dark:bg-gray-800 dark:bg-opacity-75":"",[Ve]),className:"flex-grow",endAdornment:se,AddColumnComponent:U})]})})},oe);function Es({id:e,filterValue:t,setFilterValue:n,column:o,hidden:l,setHidden:i}){if(!o.custom)return null;const{resolvedProperty:s}=o.custom,a=s?.dataType==="array",d=a?s.of:s;if(!d)return null;if(d.dataType==="reference")return r.jsx(ps,{value:t,setValue:n,name:e,isArray:a,path:d.path,title:s?.name,previewProperties:d?.previewProperties,hidden:l,setHidden:i});if(d.dataType==="number"||d.dataType==="string"){const A=d.name,g=d.enumValues?_e(d.enumValues):void 0;return r.jsx(ms,{value:t,setValue:n,name:e,dataType:d.dataType,isArray:a,enumValues:g,title:A})}else if(d.dataType==="boolean"){const A=d.name;return r.jsx(bs,{value:t,setValue:n,name:e,title:A})}else if(d.dataType==="date"){const A=d.name;return r.jsx(ys,{value:t,setValue:n,name:e,mode:d.mode,isArray:a,title:A})}return r.jsx("div",{children:`Currently the filter field ${s.dataType} is not supported`})}function zo(e,t=!1){return t?["string","number","date","reference"].includes(e.dataType):e.dataType==="array"?e.of?zo(e.of,!0):!1:["string","number","boolean","date","reference","array"].includes(e.dataType)}function Bs({data:e,entitiesDisplayedFirst:t}){if(!t)return e;const n=new Set(t.map(o=>o.id));return[...t,...e.filter(o=>!n.has(o.id))]}function ks(e,t,n=5e3){const[o,l]=c.useState(e),i=c.useRef(o.length??0),s=c.useRef(!1),a=c.useRef(t),d=!oe(a.current,t),A=e.length>=i.current||d;return c.useEffect(()=>{const g=()=>{oe(o,e)||(a.current=t,i.current=e.length,l(e)),s.current=!1};s.current=!0;let p;return A?g():p=setTimeout(g,n),()=>{clearTimeout(p),s.current&&A&&g()}},[e,n,t,A]),A?e:o}const xs=50;function en({fullPath:e,collection:t,entitiesDisplayedFirst:n,lastDeleteTimestamp:o,forceFilter:l}){const{initialFilter:i,initialSort:s,forceFilter:a}=t,[d,A]=c.useState(void 0),g=ie(),p=Qe(),h=c.useMemo(()=>g.resolveAliasesFrom(e),[e,g.resolveAliasesFrom]),u=l??a,m=t.pagination===void 0||!!t.pagination,b=typeof t.pagination=="number"?t.pagination:xs,[y,w]=c.useState(),[C,E]=c.useState(m?b:void 0),B=c.useCallback((z,V)=>p.isFilterCombinationValid?p.isFilterCombinationValid({path:h,collection:t,filterValues:z,sortBy:V}):!0,[]),I=c.useMemo(()=>{if(s&&u&&!B(u,s)){console.warn("Initial sort is not compatible with the force filter. Ignoring initial sort");return}return s},[s,u]),[x,k]=c.useState(u??i??void 0),[S,F]=c.useState(I),P=c.useCallback(()=>k(u??void 0),[u]),N=c.useCallback(z=>{if(u){console.warn("Filter is not compatible with the force filter. Ignoring filter");return}z&&Object.keys(z).length===0?k(void 0):k(z)},[u]),{data:T,dataLoading:Y,noMoreToLoad:H,dataLoadingError:_}=ro({path:e,collection:t,filterValues:x,sortBy:S,searchString:y,itemCount:C}),X=Bs({data:T,entitiesDisplayedFirst:n});return{data:ks(X,{filterValues:x,sortBy:S,searchString:y,lastDeleteTimestamp:o}),dataLoading:Y,noMoreToLoad:H,dataLoadingError:_,filterValues:x,setFilterValues:N,sortBy:S,setSortBy:F,searchString:y,setSearchString:w,clearFilter:P,itemCount:C,setItemCount:E,paginationEnabled:m,pageSize:b,checkFilterCombination:B,popupCell:d,setPopupCell:A}}function Uo({entityOrEntitiesToDelete:e,collection:t,onClose:n,open:o,callbacks:l,onEntityDelete:i,onMultipleEntitiesDelete:s,path:a}){const d=Qe();console.log("dataSource",d);const A=Je(),[g,p]=c.useState(!1),[h,u]=c.useState(),[m,b]=c.useState(),y=Z();c.useEffect(()=>{if(e){const N=Array.isArray(e)&&e.length===1?e[0]:e;u(N),b(Array.isArray(N))}},[e]);const w=c.useMemo(()=>ke({collection:t,path:a,fields:y.propertyConfigs}),[t,a]),C=c.useCallback(()=>{n()},[n]),E=c.useCallback(N=>{console.debug("Deleted",N)},[]),B=c.useCallback((N,T)=>{A.open({type:"error",message:"Error deleting: "+T?.message}),console.error("Error deleting entity"),console.error(T)},[w.name]),I=c.useCallback((N,T)=>{A.open({type:"error",message:"Error before deleting: "+T?.message}),console.error(T)},[w.name]),x=c.useCallback((N,T)=>{A.open({type:"error",message:"Error after deleting: "+T?.message}),console.error(T)},[w.name]),k=c.useCallback(N=>no({dataSource:d,entity:N,collection:w,callbacks:l,onDeleteSuccess:E,onDeleteFailure:B,onPreDeleteHookError:I,onDeleteSuccessHookError:x,context:y}),[d,w,l,E,B,I,x,y]),S=c.useCallback(async()=>{h&&(p(!0),m?Promise.all(h.map(k)).then(N=>{p(!1),s&&h&&s(a,h),N.every(Boolean)?A.open({type:"success",message:`${w.name}: multiple deleted`}):N.some(Boolean)?A.open({type:"warning",message:`${w.name}: Some of the entities have been deleted, but not all`}):A.open({type:"error",message:`${w.name}: Error deleting entities`}),n()}):k(h).then(N=>{p(!1),N&&(i&&h&&i(a,h),A.open({type:"success",message:`${w.singularName??w.name} deleted`}),n())}))},[h,m,k,s,a,n,A,w.name,i]);let F;if(h&&m)F=r.jsx(r.Fragment,{children:"Multiple entities"});else{const N=h;F=N?r.jsx($r,{entity:N,collection:t,path:a}):r.jsx(r.Fragment,{})}const P=m?r.jsxs(r.Fragment,{children:[r.jsx("b",{children:w.name}),": Confirm multiple delete?"]}):`Would you like to delete this ${w.singularName??w.name}?`;return r.jsxs(f.Dialog,{maxWidth:"2xl","aria-labelledby":"delete-dialog",open:o,onOpenChange:N=>N?void 0:n(),children:[r.jsxs(f.DialogContent,{fullHeight:!0,children:[r.jsx(f.Typography,{variant:"subtitle2",className:"p-4",children:P}),!m&&r.jsx("div",{className:"p-4",children:F})]}),r.jsxs(f.DialogActions,{children:[g&&r.jsx(f.CircularProgress,{size:"small"}),r.jsx(f.Button,{onClick:C,disabled:g,variant:"text",color:"primary",children:"Cancel"}),r.jsx(f.Button,{autoFocus:!0,disabled:g,onClick:S,variant:"filled",color:"primary",children:"Ok"})]})]})}function Rt(e){return Array.isArray(e)?e:e?[e]:[]}function Is({collection:e,relativePath:t,parentCollectionIds:n,onNewClick:o,onMultipleDeleteClick:l,selectionEnabled:i,path:s,selectionController:a,tableController:d,collectionEntitiesCount:A}){const g=Z(),p=g.plugins??[],h=je(),u=Te(),m=a.selectedEntities,b=at(e,h,Pe(s),null)&&o&&(u?r.jsxs(f.Button,{id:`add_entity_${s}`,onClick:o,startIcon:r.jsx(f.AddIcon,{}),size:"large",variant:"filled",color:"primary",children:["Add ",e.singularName??e.name]}):r.jsx(f.Button,{id:`add_entity_${s}`,onClick:o,size:"medium",variant:"filled",color:"primary",children:r.jsx(f.AddIcon,{})})),y=Jt(e,h,Pe(s),null);let w;if(i){const B=u?r.jsxs(f.Button,{variant:"text",disabled:!m?.length||!y,startIcon:r.jsx(f.DeleteIcon,{}),onClick:l,color:"primary",className:"lg:w-20",children:["(",m?.length,")"]}):r.jsx(f.IconButton,{color:"primary",disabled:!m?.length||!y,onClick:l,children:r.jsx(f.DeleteIcon,{})});w=r.jsx(f.Tooltip,{title:y?"Delete":"You have selected at least one entity you cannot delete",children:B})}const C={path:s,relativePath:t,parentCollectionIds:n,collection:e,selectionController:a,context:g,tableController:d,collectionEntitiesCount:A},E=Rt(e.Actions).map((B,I)=>r.jsx(ne,{children:r.jsx(B,{...C})},`actions_${I}`));return p&&p.forEach((B,I)=>{B.collections?.CollectionActions&&E.push(...Rt(B.collections?.CollectionActions).map((x,k)=>r.jsx(ne,{children:r.jsx(x,{...C,...B.collections?.collectionActionsProps})},`plugin_actions_${I}_${k}`)))}),r.jsxs(r.Fragment,{children:[E,w,b]})}function Ss({containerRef:e,innerRef:t,x:n,y:o,onMove:l}){let i=0,s=0;const a=c.useRef(!1),d=m=>{if(m.button!==0||!e.current||m.defaultPrevented||m.innerClicked)return;const{x:b,y}=e.current.getBoundingClientRect();i=m.screenX-b,s=m.screenY-y,document.addEventListener("mousemove",h),document.addEventListener("mouseup",p),document.addEventListener("selectstart",g),a.current=!0},A=m=>{m.innerClicked=!0},g=m=>{m.preventDefault(),m.stopPropagation()},p=m=>{document.removeEventListener("mousemove",h),document.removeEventListener("mouseup",p),document.removeEventListener("selectstart",g),m.stopPropagation(),a.current=!1},h=m=>{m.target.localName==="input"||!a.current||(l({x:m.screenX-i,y:m.screenY-s}),m.stopPropagation())},u=()=>{e.current&&(e.current.style.top=`${o}px`,e.current.style.left=`${n}px`)};c.useEffect(()=>{const m=e.current,b=t.current;if(!(!m||!b))return b&&b.addEventListener("mousedown",A),m&&m.addEventListener("mousedown",d),u(),()=>{m&&m.removeEventListener("mousedown",d),b&&b.removeEventListener("mousedown",A)}})}function Fs(){const[e,t]=c.useState({width:0,height:0});return c.useLayoutEffect(()=>{function n(){t({width:window.innerWidth,height:window.innerHeight})}return window.addEventListener("resize",n),n(),()=>window.removeEventListener("resize",n)},[]),e}const Ns=({onResize:e})=>{const t=c.useRef(0),n=c.useRef(null),o=c.useRef(e);o.current=e;const l=c.useCallback(s=>{t.current&&cancelAnimationFrame(t.current),t.current=requestAnimationFrame(()=>{o.current(s)})},[]),i=c.useCallback(()=>{const s=n.current;s&&s.contentDocument&&s.contentDocument.defaultView&&s.contentDocument.defaultView.addEventListener("resize",l)},[l]);return c.useEffect(()=>{const s=n.current;return()=>{s&&s.contentDocument&&s.contentDocument.defaultView&&s.contentDocument.defaultView.removeEventListener("resize",l)}},[l]),r.jsx("object",{onLoad:i,ref:n,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 er({name:e,addLabel:t,value:n,disabled:o=!1,buildEntry:l,small:i,onInternalIdAdded:s,includeAddButton:a,newDefaultEntry:d=null,setFieldValue:A}){return r.jsx(un,{droppableId:e,addLabel:t,value:n,disabled:o,buildEntry:l,size:i?"small":"medium",onInternalIdAdded:s,includeAddButton:a,newDefaultEntry:d,onValueChange:g=>A(e,g)})}function Ps({field:e,form:t,label:n,tooltip:o,disabled:l,size:i="small",allowIndeterminate:s}){const a=r.jsx(f.BooleanSwitchWithLabel,{label:n,size:i,position:"start",value:e.value,disabled:l,allowIndeterminate:s,onValueChange:d=>t.setFieldValue(e.name,d)});return o?r.jsx(f.Tooltip,{title:o,children:a}):a}function be({error:e,showError:t,property:n,includeDescription:o=!0,disabled:l}){const i=n.description||n.longDescription;if(!(t&&e)&&(!o||!i))return null;if(t&&e)return r.jsx(f.Typography,{variant:"caption",className:"ml-3.5 text-red-500",children:e});const s=typeof n.disabled=="object"?n.disabled.disabledMessage:void 0;return r.jsxs("div",{className:"flex ml-3.5 mt-1",children:[r.jsx(f.Typography,{variant:"caption",color:l?"disabled":"secondary",className:"flex-grow",children:s||n.description}),n.longDescription&&r.jsx(f.Tooltip,{title:n.longDescription,side:"bottom",children:r.jsx(f.IconButton,{size:"small",className:"self-start",children:r.jsx(f.InfoIcon,{color:"disabled",size:"small"})})})]})}function tn({propertyKey:e,value:t,setValue:n,error:o,showError:l,disabled:i,autoFocus:s,touched:a,property:d,includeDescription:A}){const g=d.enumValues;xe({property:d,value:t,setValue:n});const p=c.useCallback(h=>{h.stopPropagation(),h.preventDefault(),n(null)},[n]);return r.jsxs(r.Fragment,{children:[r.jsx(f.Select,{value:t?t.toString():"",disabled:i,position:"item-aligned",inputClassName:f.cn("w-full"),label:r.jsx(ye,{icon:he(d,"small"),required:d.validation?.required,title:d.name,className:"text-text-secondary dark:text-text-secondary-dark ml-3.5"}),endAdornment:d.clearable&&r.jsx(f.IconButton,{onClick:p,children:r.jsx(f.ClearIcon,{})}),onValueChange:h=>{const u=h?d.dataType==="number"?parseFloat(h):h:null;return n(u)},renderValue:h=>r.jsx(we,{enumKey:h,enumValues:g,size:"medium"}),children:g&&g.map(h=>r.jsx(f.SelectItem,{value:String(h.id),children:r.jsx(we,{enumKey:String(h.id),enumValues:g,size:"medium"})},h.id))}),r.jsx(be,{includeDescription:A,showError:l,error:o,disabled:i,property:d})]})}function rn({propertyKey:e,value:t,setValue:n,error:o,showError:l,disabled:i,property:s,includeDescription:a,autoFocus:d}){const A=s.of;if(!A)throw Error("Using wrong component ArrayEnumSelect");if(Array.isArray(A))throw Error("Using array properties instead of single one in `of` in ArrayProperty");if(A.dataType!=="string"&&A.dataType!=="number")throw Error("Field misconfiguration: array field of type string or number");const g=_e(A.enumValues);if(!g)throw console.error(s),Error("Field misconfiguration: array field of type string or number needs to have enumValues");xe({property:s,value:t,setValue:n});const p=!!t&&Array.isArray(t),h=c.useCallback((u,m)=>{const b=u!==void 0?$t(g,u):void 0;return r.jsxs(we,{enumKey:u,enumValues:g,size:"medium",children:[b?.label??u,!m&&r.jsx("button",{className:"ml-1 ring-offset-background rounded-full outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",onMouseDown:y=>{y.preventDefault(),y.stopPropagation()},onClick:y=>{y.preventDefault(),y.stopPropagation(),n(t.filter(w=>w!==u))},children:r.jsx(f.CloseIcon,{size:"smallest"})})]},u)},[g,n,t]);return r.jsxs("div",{className:"mt-0.5 ml-0.5 mt-2",children:[r.jsx(f.MultiSelect,{value:p?t.map(u=>u.toString()):[],disabled:i,label:r.jsx(ye,{icon:he(s,"small"),required:s.validation?.required,title:s.name,className:"text-text-secondary dark:text-text-secondary-dark ml-3.5"}),renderValue:c.useCallback(u=>h(u,!1),[h]),onMultiValueChange:u=>{let m;return A&&A?.dataType==="number"?m=u?u.map(b=>parseFloat(b)):[]:m=u,n(m)},children:g.map(u=>String(u.id)).map(u=>r.jsx(f.MultiSelectItem,{value:u,children:h(u,!0)},u))}),r.jsx(be,{includeDescription:a,showError:l,error:o,disabled:i,property:s})]})}function Lo({propertyKey:e,value:t,error:n,showError:o,disabled:l,isSubmitting:i,tableMode:s,property:a,includeDescription:d,setValue:A,setFieldValue:g}){const p=a.of;if(p.dataType!=="reference")throw Error("ArrayOfReferencesField expected a property containing references");const h=a.expanded===void 0?!0:a.expanded,[u,m]=c.useState(!1),b=t&&Array.isArray(t)?t.map(S=>S.id):[];xe({property:a,value:t,setValue:A});const y=ie(),w=c.useMemo(()=>p.path?y.getCollection(p.path):void 0,[p.path]);if(!w)throw Error(`Couldn't find the corresponding collection for the path: ${p.path}`);const C=c.useCallback(S=>{console.debug("onMultipleEntitiesSelected",S),A(S.map(F=>Ge(F)))},[A]),E=mt({multiselect:!0,path:p.path,collection:w,onMultipleEntitiesSelected:C,selectedEntityIds:b,forceFilter:p.forceFilter}),B=c.useCallback(S=>{S.preventDefault(),E.open()},[E]),I=c.useCallback((S,F)=>{const P=t&&t.length>S?t[S]:void 0;return P?r.jsx("div",{onMouseEnter:()=>m(!0),onMouseMove:()=>m(!0),onMouseLeave:()=>m(!1),children:r.jsx(De,{disabled:!p.path,previewProperties:p.previewProperties,size:"medium",onClick:B,reference:P,onHover:u})}):r.jsx("div",{children:"Internal ERROR"})},[p.path,p.previewProperties,u,t]),x=r.jsx(ye,{icon:he(a,"small"),required:a.validation?.required,title:a.name,className:"text-text-secondary dark:text-text-secondary-dark"}),k=r.jsxs(r.Fragment,{children:[!w&&r.jsx(pe,{error:"The specified collection does not exist. Check console"}),w&&r.jsxs(r.Fragment,{children:[r.jsx(er,{value:t,addLabel:a.name?"Add reference to "+a.name:"Add reference",name:e,buildEntry:I,disabled:i,setFieldValue:g,newDefaultEntry:a.of.defaultValue}),r.jsxs(f.Button,{className:"my-4 justify-center text-left",variant:"outlined",color:"primary",disabled:i,onClick:B,children:["Edit ",a.name]})]})]});return r.jsxs(r.Fragment,{children:[!s&&r.jsx(f.ExpandablePanel,{className:"px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2",initiallyExpanded:h,title:x,children:k}),s&&k,r.jsx(be,{includeDescription:d,showError:o,error:n,disabled:l,property:a})]})}function $o({name:e,property:t,value:n,entity:o,onRemove:l,disabled:i,size:s}){return r.jsxs("div",{className:f.cn(f.paperMixin,"relative m-4 border-box flex items-center justify-center",s==="medium"?"min-w-[220px] min-h-[220px] max-w-[220px]":"min-w-[118px] min-h-[118px] max-w-[118px]"),children:[!i&&r.jsx("div",{className:"absolute rounded-full -top-2 -right-2 z-10 bg-white dark:bg-gray-900",children:r.jsx(f.Tooltip,{title:"Remove",children:r.jsx(f.IconButton,{size:"small",onClick:a=>{a.stopPropagation(),l(n)},children:r.jsx(f.RemoveIcon,{size:"small"})})})}),n&&r.jsx(ne,{children:r.jsx(me,{propertyKey:e,value:n,property:t,entity:o,size:s})})]})}const Qs="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",Ts="border-dotted-gray",Ms="hover:bg-field-hover dark:hover:bg-field-hover-dark",Ds="pt-0 border-2 border-solid",Os="transition-colors duration-200 ease-[cubic-bezier(0,0,0.2,1)] border-2 border-solid border-green-500",Vs="transition-colors duration-200 ease-[cubic-bezier(0,0,0.2,1)] border-2 border-solid border-red-500";function nn({propertyKey:e,value:t,setValue:n,error:o,showError:l,autoFocus:i,tableMode:s,property:a,includeDescription:d,context:A,isSubmitting:g}){if(!A.entityId)throw new Error("StorageUploadFieldBinding: Entity id is null");const p=ct(),h=it(a)||!!a.disabled||g,{internalValue:u,setInternalValue:m,onFilesAdded:b,storage:y,onFileUploadComplete:w,storagePathBuilder:C,multipleFilesSupported:E}=Eo({entityValues:A.values,entityId:A.entityId,path:A.path,property:a,propertyKey:e,value:t,storageSource:p,disabled:h,onChange:n});xe({property:a,value:t,setValue:n});const B={id:A.entityId,values:A.values,path:A.path};return r.jsxs(r.Fragment,{children:[!s&&r.jsx(ye,{icon:he(a,"small"),required:a.validation?.required,title:a.name,className:"text-text-secondary dark:text-text-secondary-dark ml-3.5"}),r.jsx(Ys,{value:u,name:e,disabled:h,autoFocus:i,property:a,onChange:n,setInternalValue:m,onFilesAdded:b,entity:B,onFileUploadComplete:w,storagePathBuilder:C,storage:y,multipleFilesSupported:E}),r.jsx(be,{includeDescription:d,showError:l,error:o,disabled:h,property:a})]})}function Gs({storage:e,disabled:t,isDraggingOver:n,onFilesAdded:o,multipleFilesSupported:l,droppableProvided:i,autoFocus:s,internalValue:a,property:d,entity:A,onClear:g,metadata:p,storagePathBuilder:h,onFileUploadComplete:u,size:m,name:b,helpText:y}){const w=Je(),{getRootProps:C,getInputProps:E,isDragActive:B,isDragAccept:I,isDragReject:x}=wn.useDropzone({accept:e.acceptedFiles?e.acceptedFiles.map(k=>({[k]:[]})).reduce((k,S)=>({...k,...S}),{}):void 0,disabled:t||n,noDragEventsBubbling:!0,maxSize:e.maxSize,onDrop:o,onDropRejected:(k,S)=>{for(const F of k)for(const P of F.errors)w.open({type:"error",message:`Error uploading file: File is larger than ${e.maxSize} bytes`})}});return r.jsxs("div",{...C(),className:f.cn(f.fieldBackgroundMixin,t?f.fieldBackgroundDisabledMixin:f.fieldBackgroundHoverMixin,Qs,l&&a.length?"":"flex",f.focusedMixin,{[Ms]:!B,[Ds]:B,[Vs]:x,[Os]:I,[Ts]:t}),children:[r.jsxs("div",{...i.droppableProps,ref:i.innerRef,className:f.cn("flex items-center p-1 no-scrollbar",l&&a.length?"overflow-auto":"",l&&a.length?"min-h-[180px]":"min-h-[250px]"),children:[r.jsx("input",{autoFocus:s,...E()}),a.map((k,S)=>{let F;return k.storagePathOrDownloadUrl?F=r.jsx($o,{name:`storage_preview_${k.storagePathOrDownloadUrl}`,property:d,disabled:t,entity:A,value:k.storagePathOrDownloadUrl,onRemove:g,size:k.size}):k.file&&(F=r.jsx(Io,{entry:k,metadata:p,storagePath:h(k.file),onFileUploadComplete:u,imageSize:m==="medium"?220:118,simple:!1})),r.jsx(lt.Draggable,{draggableId:`array_field_${b}_${k.id}`,index:S,children:(P,N)=>r.jsx("div",{tabIndex:-1,ref:P.innerRef,...P.draggableProps,...P.dragHandleProps,className:f.cn(f.focusedMixin,"rounded-md"),style:{...P.draggableProps.style},children:F})},`array_field_${b}_${k.id}`)}),i.placeholder]}),r.jsx("div",{className:"flex-grow min-h-[38px] box-border m-2 text-center",children:r.jsx(f.Typography,{align:"center",variant:"label",children:y})})]})}function Ys({property:e,name:t,value:n,setInternalValue:o,onChange:l,multipleFilesSupported:i,onFileUploadComplete:s,disabled:a,onFilesAdded:d,autoFocus:A,storage:g,entity:p,storagePathBuilder:h}){if(i){const B=e;if(B.of){if(Array.isArray(B.of)||B.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 u=g?.metadata,m=i?"small":"medium",b=c.useCallback((B,I)=>{if(!i)return;const x=[...n],k=x[B];x.splice(B,1),x.splice(I,0,k),o(x);const S=x.filter(F=>!!F.storagePathOrDownloadUrl).map(F=>F.storagePathOrDownloadUrl);l(S)},[i,l,o,n]),y=c.useCallback(B=>{B.destination&&b(B.source.index,B.destination.index)},[b]),w=c.useCallback(B=>{if(i){const I=n.filter(x=>x.storagePathOrDownloadUrl!==B);l(I.filter(x=>!!x.storagePathOrDownloadUrl).map(x=>x.storagePathOrDownloadUrl)),o(I)}else l(null),o([])},[n,i,l]),C=i?"Drag 'n' drop some files here, or click to select files":"Drag 'n' drop a file here, or click to select one",E=i?e.of:e;return r.jsx(lt.DragDropContext,{onDragEnd:y,children:r.jsx(lt.Droppable,{droppableId:`droppable_${t}`,direction:"horizontal",renderClone:(B,I,x)=>{const k=n[x.source.index];return r.jsx("div",{ref:B.innerRef,...B.draggableProps,...B.dragHandleProps,style:B.draggableProps.style,className:"rounded",children:r.jsx($o,{name:`storage_preview_${k.storagePathOrDownloadUrl}`,property:E,disabled:!0,entity:p,value:k.storagePathOrDownloadUrl,onRemove:w,size:k.size})})},children:(B,I)=>r.jsx(Gs,{storage:g,disabled:a,isDraggingOver:I.isDraggingOver,droppableProvided:B,onFilesAdded:d,multipleFilesSupported:i,autoFocus:A,internalValue:n,property:E,entity:p,onClear:w,metadata:u,storagePathBuilder:h,onFileUploadComplete:s,size:m,name:t,helpText:C})})})}function ht({propertyKey:e,value:t,setValue:n,error:o,showError:l,disabled:i,autoFocus:s,property:a,includeDescription:d}){let A,g;a.dataType==="string"&&(A=a.multiline,g=a.url),xe({property:a,value:t,setValue:n});const p=c.useCallback(b=>{b.stopPropagation(),b.preventDefault(),n(null)},[n]),h=b=>{if(m==="number"){const y=b.target.value?parseFloat(b.target.value):void 0;y&&isNaN(y)?n(null):y!=null?n(y):n(null)}else n(b.target.value)},u=!!A,m=a.dataType==="number"?"number":void 0;return r.jsxs(r.Fragment,{children:[r.jsx(f.TextField,{value:t,onChange:h,autoFocus:s,label:r.jsx(ye,{icon:he(a,"small"),required:a.validation?.required,title:a.name}),type:m,multiline:u,disabled:i,endAdornment:a.clearable&&r.jsx(f.IconButton,{onClick:p,children:r.jsx(f.ClearIcon,{})}),error:l?o:void 0,inputClassName:o?"text-red-500 dark:text-red-600":""}),r.jsx(be,{includeDescription:d,showError:l,error:o,disabled:i,property:a}),g&&r.jsx(f.Collapse,{className:"mt-1 ml-1",in:!!t,children:r.jsx(me,{value:t,property:a,size:"medium"})})]})}const _o=c.forwardRef(function({propertyKey:t,value:n,setValue:o,error:l,showError:i,autoFocus:s,disabled:a,touched:d,property:A,includeDescription:g},p){return xe({property:A,value:n,setValue:o}),r.jsxs(r.Fragment,{children:[r.jsx(f.BooleanSwitchWithLabel,{value:n,onValueChange:h=>o(h),error:i,label:r.jsx(ye,{icon:he(A,"small"),required:A.validation?.required,title:A.name}),disabled:a,autoFocus:s,size:"medium"}),r.jsx(be,{includeDescription:g,showError:i,error:l,disabled:a,property:A})]})});function Wo({propertyKey:e,value:t,setValue:n,autoFocus:o,error:l,showError:i,disabled:s,touched:a,property:d,includeDescription:A}){const{locale:g}=Z(),p=t||null;return xe({property:d,value:t,setValue:n}),r.jsxs(r.Fragment,{children:[r.jsx(f.DateTimeField,{value:p,onChange:h=>n(h),size:"medium",mode:d.mode,clearable:d.clearable,locale:g,label:r.jsx(ye,{icon:he(d,"small"),required:d.validation?.required,className:"text-text-secondary dark:text-text-secondary-dark",title:d.name})}),r.jsx(be,{includeDescription:A,showError:i,error:l,disabled:s,property:d})]})}function on({propertyKey:e,value:t,error:n,showError:o,tableMode:l,property:i,includeDescription:s,context:a}){if(!a.entityId)throw new Error("ReadOnlyFieldBinding: Entity id is null");const d={id:a.entityId,values:a.values,path:a.path};return r.jsxs(r.Fragment,{children:[!l&&r.jsx(ye,{icon:he(i,"small"),required:i.validation?.required,title:i.name,className:"text-text-secondary dark:text-text-secondary-dark ml-3.5"}),r.jsx("div",{className:f.cn(f.paperMixin,"min-h-14 p-4 md:p-6 overflow-x-scroll no-scrollbar"),children:r.jsx(ne,{children:r.jsx(me,{propertyKey:e,value:t,property:i,entity:d,size:"medium"})})}),r.jsx(be,{includeDescription:s,showError:o,error:n,property:i})]})}function jo(e){return typeof e.property.path!="string"?r.jsx(on,{...e}):r.jsx(zs,{...e})}function zs({value:e,setValue:t,error:n,showError:o,isSubmitting:l,disabled:i,touched:s,autoFocus:a,property:d,includeDescription:A,context:g}){if(!d.path)throw new Error("Property path is required for ReferenceFieldBinding");xe({property:d,value:e,setValue:t});const p=e&&e instanceof Fe,h=ie(),u=c.useMemo(()=>d.path?h.getCollection(d.path):void 0,[d.path]);if(!u)throw Error(`Couldn't find the corresponding collection for the path: ${d.path}`);const m=c.useCallback(w=>{t(w?Ge(w):null)},[t]),b=mt({multiselect:!1,path:d.path,collection:u,onSingleEntitySelected:m,selectedEntityIds:p?[e.id]:void 0,forceFilter:d.forceFilter}),y=c.useCallback(w=>{w.preventDefault(),b.open()},[b]);return r.jsxs(r.Fragment,{children:[r.jsx(ye,{icon:he(d,"small"),required:d.validation?.required,title:d.name,className:"text-text-secondary dark:text-text-secondary-dark ml-3.5"}),!u&&r.jsx(pe,{error:"The specified collection does not exist. Check console"}),u&&r.jsxs(r.Fragment,{children:[e&&r.jsx(De,{disabled:!d.path,previewProperties:d.previewProperties,size:"medium",onClick:i||l?void 0:y,reference:e}),!e&&r.jsx("div",{className:"justify-center text-left",children:r.jsxs(f.Button,{variant:"outlined",color:"primary",disabled:i||l,onClick:y,children:["Edit ",d.name]})})]}),r.jsx(be,{includeDescription:A,showError:o,error:n,disabled:i,property:d})]})}const nt=c.memo(Us,(e,t)=>{if(e.propertyKey!==t.propertyKey)return!1;const n=ve(e.property)||e.property.fromBuilder,o=ve(t.property)||t.property.fromBuilder;return!((n===o||oe(e.property,t.property))&&e.disabled===t.disabled)||tr(t.property),!1});function Us({propertyKey:e,property:t,context:n,includeDescription:o,underlyingValueHasChanged:l,disabled:i,tableMode:s,partOfArray:a,partOfBlock:d,autoFocus:A}){const g=Z(),h=tr(t,g.plugins)?Ce.Field:Ce.FastField;return r.jsx(h,{name:e,children:u=>{let m;const b=Be({propertyKey:e,propertyValue:u.field.value,propertyOrBuilder:t,values:u.form.values,path:n.path,entityId:n.entityId,fields:g.propertyConfigs});if(b===null||wt(b))return r.jsx(r.Fragment,{});if(it(b))m=on;else if(b.Field)typeof b.Field=="function"&&(m=b.Field);else{const w=sr(b,g.propertyConfigs);if(!w)throw console.log("INTERNAL: Could not find field config for property",{propertyKey:e,resolvedProperty:b,fields:g.propertyConfigs,propertyConfig:w}),new Error(`INTERNAL: Could not find field config for property ${e}`);m=Be({propertyOrBuilder:w.property,propertyValue:u.field.value,values:u.form.values,path:n.path,entityId:n.entityId,fields:g.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 ${b.dataType} is not supported`});const y={propertyKey:e,property:b,includeDescription:o,underlyingValueHasChanged:l,context:n,disabled:i,tableMode:s,partOfArray:a,partOfBlock:d,autoFocus:A};return r.jsx(Ls,{Component:m,componentProps:y,fieldProps:u})}})}function Ls({Component:e,componentProps:{propertyKey:t,property:n,includeDescription:o,underlyingValueHasChanged:l,tableMode:i,partOfArray:s,partOfBlock:a,autoFocus:d,context:A,disabled:g},fieldProps:p}){const{plugins:h}=Z(),u=n.customProps,m=p.field.value,b=p.meta.initialValue,y=Ce.getIn(p.form.errors,t),w=Ce.getIn(p.form.touched,t),C=y&&(p.form.submitCount>0||n.validation?.unique)&&(!Array.isArray(y)||!!y.filter(S=>!!S).length);$s(A.path,A.collection,t,n,e,h);const E=e,B=p.form.isSubmitting,I=c.useCallback((S,F)=>{p.form.setFieldTouched(t,!0,!1),p.form.setFieldValue(t,S,F)},[]),x=c.useCallback((S,F,P)=>{p.form.setFieldTouched(t,!0,!1),p.form.setFieldValue(S,F,P)},[]),k={propertyKey:t,value:m,initialValue:b,setValue:I,setFieldValue:x,error:y,touched:w,showError:C,isSubmitting:B,includeDescription:o??!0,property:n,disabled:g??!1,underlyingValueHasChanged:l??!1,tableMode:i??!1,partOfArray:s??!1,partOfBlock:a??!1,autoFocus:d??!1,customProps:u,context:A};return r.jsxs(ne,{children:[r.jsx(E,{...k}),l&&!B&&r.jsx(f.Typography,{variant:"caption",className:"ml-3.5",children:"This value has been updated elsewhere"})]})}const tr=(e,t)=>{if(t?.some(l=>l.form?.fieldBuilder)||ve(e))return!0;const n=e,o=!!n.Field||"fromBuilder"in n&&n.fromBuilder;return n.dataType==="map"&&n.properties?o||Object.values(n.properties).some(l=>tr(l,t)):n.dataType==="array"&&"resolvedProperties"in n?o||n.resolvedProperties?.some(l=>l&&tr(l,t)):o};function $s(e,t,n,o,l,i){return c.useRef((()=>{let a=null;return i&&i.forEach(d=>{const A=mn(o);if(A&&d.form?.fieldBuilder){const g={fieldConfigId:A,propertyKey:n,property:o,Field:l,plugin:d,path:e,collection:t},p=d.form?.fieldBuilderEnabled?.(g);(p===void 0||p)&&(a=d.form.fieldBuilder(g)||a)}A||console.warn("INTERNAL: Field id not found for property",o)}),a})()).current}function Ho({propertyKey:e,value:t,showError:n,error:o,disabled:l,property:i,setValue:s,partOfBlock:a,tableMode:d,includeDescription:A,underlyingValueHasChanged:g,autoFocus:p,context:h}){const u=i.pickOnlySomeKeys||!1,m=(i.expanded===void 0?!0:i.expanded)||p;if(!i.properties)throw Error(`You need to specify a 'properties' prop (or specify a custom field) in your map property ${e}`);let b;u?t?b=xn(i.properties,...Object.keys(t).filter(C=>C in i.properties)):b={}:b=i.properties;const y=r.jsx(r.Fragment,{children:r.jsx("div",{className:"py-1 flex flex-col space-y-2",children:Object.entries(b).filter(([C,E])=>!wt(E)).map(([C,E],B)=>{const I={propertyKey:`${e}.${C}`,disabled:l,property:E,includeDescription:A,underlyingValueHasChanged:g,context:h,tableMode:!1,partOfArray:!1,partOfBlock:!1,autoFocus:p&&B===0};return r.jsx("div",{children:r.jsx(nt,{...I})},`map-${e}-${B}`)})})}),w=r.jsx(ye,{icon:he(i,"small"),required:i.validation?.required,title:i.name,className:"text-text-secondary dark:text-text-secondary-dark"});return r.jsxs(r.Fragment,{children:[!d&&!a&&r.jsx(f.ExpandablePanel,{initiallyExpanded:m,className:"px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2",title:w,children:y}),(d||a)&&y,r.jsx(be,{includeDescription:A,showError:n,error:o,disabled:l,property:i})]})}function Jo({propertyKey:e,value:t,showError:n,error:o,disabled:l,property:i,setValue:s,tableMode:a,includeDescription:d,underlyingValueHasChanged:A,autoFocus:g,context:p}){const h=(i.expanded===void 0?!0:i.expanded)||g;if(!i.keyValue)throw Error(`Your property ${e} needs to have the 'keyValue' prop in order to use this field binding`);const u=r.jsx(ln,{value:t,setValue:s,disabled:l,fieldName:i.name??e}),m=r.jsx(ye,{icon:he(i,"small"),required:i.validation?.required,title:i.name,className:"text-text-secondary dark:text-text-secondary-dark"});return r.jsxs(r.Fragment,{children:[!a&&r.jsx(f.ExpandablePanel,{initiallyExpanded:h,title:m,className:"px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2",children:u}),a&&u,r.jsx(be,{includeDescription:d,showError:n,error:o,disabled:l,property:i})]})}function ln({value:e,setValue:t,fieldName:n,disabled:o}){const[l,i]=c.useState(Object.keys(e??{}).map(d=>[sn(),{key:d,dataType:an(e?.[d])??"string"}]));c.useEffect(()=>{const d=l.map(([u,{key:m}])=>m),A=Object.entries(e??{}).filter(([u,m])=>m!==void 0).map(([u])=>u),g=A.filter(u=>!d.includes(u)),p=d.filter(u=>!A.includes(u)),h=[...l];g.forEach(u=>{h.push([sn(),{key:u,dataType:an(e?.[u])??"string"}])}),p.forEach(u=>{const m=h.findIndex(([b,{key:y}])=>y===u);h.splice(m,1)}),i(h)},[e]);const s=c.useRef(e??{}),a=(d,A)=>{if(!d){console.warn("No key selected for data type update");return}i(l.map(g=>g[0]===d?[g[0],{key:g[1].key,dataType:A}]:g)),t({...e??{},[l.find(g=>g[0]===d)?.[1].key??""]:mr(A)})};return r.jsxs("div",{className:"py-1 flex flex-col gap-1",children:[l.map(([d,{key:A,dataType:g}],p)=>{const h=A?e?.[A]:"",u=m=>{if(i(l.map(y=>y[0]===d?[d,{key:m??"",dataType:y[1].dataType}]:y)),typeof e=="object"&&m in e)return;const b={...e??{}};typeof s.current=="object"&&A in s.current?b[A]=void 0:delete b[A],t({...b,[m??""]:h})};return r.jsx(_s,{rowId:d,fieldKey:A,value:e??{},onDeleteClick:()=>{const m={...e??{}};s.current&&A in s.current?m[A]=void 0:delete m[A],i(l.filter(b=>b[0]!==d)),t({...m})},onFieldKeyChange:u,setValue:t,entryValue:h,dataType:g,disabled:o,updateDataType:a},d)}),r.jsx(f.Button,{variant:"text",size:"small",color:"primary",className:"w-full",disabled:o,startIcon:r.jsx(f.AddIcon,{}),onClick:d=>{d.preventDefault(),t({...e??{},"":null}),i([...l,[sn(),{key:"",dataType:"string"}]])},children:n?`Add to ${n}`:"Add"})]})}function _s({rowId:e,fieldKey:t,value:n,onFieldKeyChange:o,onDeleteClick:l,setValue:i,entryValue:s,dataType:a,updateDataType:d,disabled:A}){const{locale:g}=Z();function p(u,m,b){return b==="string"||b==="number"?r.jsx(f.TextField,{placeholder:"value",value:u,type:b==="number"?"number":"text",size:"small",disabled:A||!m,onChange:y=>{if(b==="number"){const w=y.target.value?parseFloat(y.target.value):void 0;w&&isNaN(w)?i({...n,[m]:null}):w!=null?i({...n,[m]:w}):i({...n,[m]:null})}else i({...n,[m]:y.target.value})}},b):b==="date"?r.jsx(f.DateTimeField,{value:u,size:"small",locale:g,disabled:A||!m,onChange:y=>{i({...n,[m]:y})}}):b==="boolean"?r.jsx(f.BooleanSwitchWithLabel,{value:u,size:"small",position:"start",disabled:A||!m,onValueChange:y=>{i({...n,[m]:y})}}):b==="array"?r.jsx("div",{className:f.cn(f.defaultBorderMixin,"ml-2 pl-2 border-l border-solid"),children:r.jsx(un,{value:u,newDefaultEntry:"",droppableId:e.toString(),addLabel:m?`Add to ${m}`:"Add",size:"small",disabled:A||!m,includeAddButton:!0,onValueChange:y=>{i({...n,[m]:y})},buildEntry:(y,w)=>r.jsx(Ws,{index:y,id:w,value:u[y],disabled:A||!m,setValue:C=>{const E=[...u];E[y]=C,i({...n,[m]:E})}})})}):b==="map"?r.jsx("div",{className:f.cn(f.defaultBorderMixin,"ml-2 pl-2 border-l border-solid"),children:r.jsx(ln,{value:u,fieldName:m,setValue:y=>{i({...n,[m]:y})}})}):r.jsx(f.Typography,{variant:"caption",children:`Data type ${b} not supported yet`})}function h(u){d(e,u)}return r.jsxs(r.Fragment,{children:[r.jsxs(f.Typography,{component:"div",className:"font-mono flex flex-row gap-1",children:[r.jsx("div",{className:"w-[200px] max-w-[25%]",children:r.jsx(f.TextField,{value:t,placeholder:"key",disabled:A||s!=null&&s!=="",size:"small",onChange:u=>{o(u.target.value)}})}),r.jsx("div",{className:"flex-grow",children:a!=="map"&&a!=="array"&&p(s,t,a)}),r.jsxs(f.Menu,{trigger:r.jsx(f.IconButton,{size:"small",className:"h-7 w-7",children:r.jsx(f.ArrowDropDownIcon,{})}),children:[r.jsx(f.MenuItem,{dense:!0,onClick:()=>h("string"),children:"string"}),r.jsx(f.MenuItem,{dense:!0,onClick:()=>h("number"),children:"number"}),r.jsx(f.MenuItem,{dense:!0,onClick:()=>h("boolean"),children:"boolean"}),r.jsx(f.MenuItem,{dense:!0,onClick:()=>h("date"),children:"date"}),r.jsx(f.MenuItem,{dense:!0,onClick:()=>h("map"),children:"map"}),r.jsx(f.MenuItem,{dense:!0,onClick:()=>h("array"),children:"array"})]}),r.jsx(f.IconButton,{"aria-label":"delete",size:"small",onClick:l,className:"h-7 w-7",children:r.jsx(f.RemoveIcon,{size:"small"})})]},e.toString()),(a==="map"||a==="array")&&p(s,t,a)]})}function Ws({id:e,index:t,value:n,setValue:o}){const{locale:l}=Z(),[i,s]=c.useState(an(n)??"string");function a(A){s(A)}function d(A,g){return g==="string"||g==="number"?r.jsx(f.TextField,{value:A,type:g==="number"?"number":"text",size:"small",onChange:p=>{if(g==="number"){const h=p.target.value?parseFloat(p.target.value):void 0;h&&isNaN(h)?o(null):h!=null?o(h):o(null)}else o(p.target.value)}}):g==="date"?r.jsx(f.DateTimeField,{value:A,size:"small",locale:l,onChange:p=>{o(p)}}):g==="boolean"?r.jsx(f.BooleanSwitchWithLabel,{value:A,size:"small",position:"start",onValueChange:p=>{o(p)}}):g==="array"?r.jsx(f.Typography,{variant:"caption",children:"Arrays of arrays are not supported."}):g==="map"?r.jsx("div",{className:f.cn(f.defaultBorderMixin,"ml-2 pl-2 border-l border-solid"),children:r.jsx(ln,{value:A,setValue:p=>{o(p)}})}):r.jsx(f.Typography,{variant:"caption",children:`Data type ${g} not supported yet`})}return r.jsxs(r.Fragment,{children:[r.jsxs(f.Typography,{component:"div",className:"font-mono flex min-h-12 flex-row gap-1 items-center",children:[r.jsx("div",{className:"flex-grow",children:i!=="map"&&d(n,i)}),r.jsxs(f.Menu,{trigger:r.jsx(f.IconButton,{size:"small",className:"h-7 w-7",children:r.jsx(f.ArrowDropDownIcon,{})}),children:[r.jsx(f.MenuItem,{dense:!0,onClick:()=>a("string"),children:"string"}),r.jsx(f.MenuItem,{dense:!0,onClick:()=>a("number"),children:"number"}),r.jsx(f.MenuItem,{dense:!0,onClick:()=>a("boolean"),children:"boolean"}),r.jsx(f.MenuItem,{dense:!0,onClick:()=>a("map"),children:"map"}),r.jsx(f.MenuItem,{dense:!0,onClick:()=>a("date"),children:"date"})]})]},e.toString()),i==="map"&&d(n,i)]})}function sn(){return Math.floor(Math.random()*Math.floor(Number.MAX_SAFE_INTEGER))}function an(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 instanceof Fe)return"reference";if(e instanceof Gt)return"geopoint";if(typeof e=="object")return"map"}function qo({propertyKey:e,value:t,error:n,showError:o,isSubmitting:l,setValue:i,setFieldValue:s,tableMode:a,property:d,includeDescription:A,underlyingValueHasChanged:g,context:p,disabled:h}){if(!d.of)throw Error("RepeatFieldBinding misconfiguration. Property `of` not set");if(!d.resolvedProperties||!Array.isArray(d.resolvedProperties))throw Error("RepeatFieldBinding - Internal error: Expected array in 'property.resolvedProperties'");const u=d.expanded===void 0?!0:d.expanded,m=d.of,[b,y]=c.useState();xe({property:d,value:t,setValue:i});const w=(B,I)=>{const x=d.resolvedProperties[B]??m,k={propertyKey:`${e}.${B}`,disabled:h,property:x,includeDescription:A,underlyingValueHasChanged:g,context:p,tableMode:!1,partOfArray:!0,partOfBlock:!1,autoFocus:I===b};return r.jsx(nt,{...k})},C=r.jsx(er,{value:t,addLabel:d.name?"Add entry to "+d.name:"Add entry",name:e,setFieldValue:s,buildEntry:w,onInternalIdAdded:y,disabled:l||!!d.disabled,includeAddButton:!d.disabled,newDefaultEntry:d.of.defaultValue}),E=r.jsx(ye,{icon:he(d,"small"),required:d.validation?.required,title:d.name,className:"text-text-secondary dark:text-text-secondary-dark"});return r.jsxs(r.Fragment,{children:[!a&&r.jsx(f.ExpandablePanel,{initiallyExpanded:u,className:"px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2",title:E,children:C}),a&&C,r.jsx(be,{includeDescription:A,showError:o,error:n,disabled:h,property:d})]})}function Zo({propertyKey:e,value:t,error:n,showError:o,isSubmitting:l,setValue:i,setFieldValue:s,tableMode:a,property:d,includeDescription:A,underlyingValueHasChanged:g,context:p,disabled:h}){if(!d.oneOf)throw Error("ArrayOneOfField misconfiguration. Property `oneOf` not set");const u=d.expanded===void 0?!0:d.expanded;xe({property:d,value:t,setValue:i});const[m,b]=c.useState(),y=c.useCallback((B,I)=>r.jsx(js,{name:`${e}.${B}`,index:B,value:t[B],typeField:d.oneOf.typeField??vt,valueField:d.oneOf.valueField??zt,properties:d.oneOf.properties,autoFocus:I===m,context:p},`array_one_of_${B}`),[p,m,d.oneOf,e,t]),w=r.jsx(ye,{icon:he(d,"small"),required:d.validation?.required,title:d.name,className:"text-text-secondary dark:text-text-secondary-dark"}),C=Object.keys(d.oneOf.properties)[0],E=r.jsx(er,{value:t,name:e,addLabel:d.name?"Add entry to "+d.name:"Add entry",buildEntry:y,onInternalIdAdded:b,disabled:l||!!d.disabled,includeAddButton:!d.disabled,setFieldValue:s,newDefaultEntry:{[d.oneOf.typeField??vt]:C,[d.oneOf.valueField??zt]:Ut(d.oneOf.properties[C])}});return r.jsxs(r.Fragment,{children:[!a&&r.jsx(f.ExpandablePanel,{className:"px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2",initiallyExpanded:u,title:w,children:E}),a&&E,r.jsx(be,{includeDescription:A,showError:o,error:n,disabled:h,property:d})]})}function js({name:e,index:t,value:n,typeField:o,valueField:l,properties:i,autoFocus:s,context:a}){const d=n&&n[o],[A,g]=c.useState(d??void 0),p=Ce.useFormikContext();c.useEffect(()=>{d||w(Object.keys(i)[0])},[]),c.useEffect(()=>{d!==A&&g(d)},[d]);const h=A?i[A]:void 0,u=Object.entries(i).map(([C,E])=>({id:C,label:E.name??C})),m=`${e}.${o}`,b=`${e}.${l}`,y=h?{propertyKey:b,property:h,context:a,autoFocus:s,partOfArray:!1,partOfBlock:!0,tableMode:!1}:void 0,w=C=>{const E=C?i[C]:void 0;g(C),p.setFieldTouched(m),p.setFieldValue(m,C),p.setFieldValue(b,E?Ut(E):null)};return r.jsxs("div",{className:f.cn(f.paperMixin,"bg-transparent p-4 my-4 py-8"),children:[r.jsx(Ce.FastField,{required:!0,name:m,children:C=>r.jsx(r.Fragment,{children:r.jsx(f.Select,{className:"mb-2",placeholder:r.jsx(f.Typography,{variant:"caption",className:"px-4 py-2 font-medium",children:"Type"}),size:"small",position:"item-aligned",value:C.field.value!==void 0&&C.field.value!==null?C.field.value:"",renderValue:E=>r.jsx(we,{enumKey:E,enumValues:u,size:"small"}),onValueChange:E=>{w(E)},children:u.map(E=>r.jsx(f.SelectItem,{value:String(E.id),children:r.jsx(we,{enumKey:E.id,enumValues:u,size:"small"})},E.id))})})}),y&&r.jsx(nt,{...y},`form_control_${e}_${A}`)]})}const Hs=new Bl;try{et.use(et.Plugins.AutoResize,{min:100}),et.unuse(et.Plugins.FontUnderline),et.unuse(et.Plugins.Clear)}catch{}function Xo({propertyKey:e,value:t,setValue:n,error:o,showError:l,disabled:i,autoFocus:s,touched:a,property:d,tableMode:A,includeDescription:g,context:p}){const[h,u]=c.useState(t),m=c.useRef(t);f.useInjectStyles("MarkdownFieldBinding",Js);const b=c.useDeferredValue({internalValue:h,value:t});return c.useEffect(()=>{m.current=t,u(t)},[t]),c.useEffect(()=>{b.internalValue!==m.current&&n(b.internalValue)},[b]),r.jsxs(r.Fragment,{children:[!A&&r.jsx(f.Typography,{variant:"caption",className:"flex-grow",children:r.jsx(ye,{icon:he(d,"small"),required:d.validation?.required,title:d.name,className:"text-text-secondary dark:text-text-secondary-dark ml-3.5"})}),r.jsx(et,{value:h??"",className:f.cn(f.fieldBackgroundMixin,i?f.fieldBackgroundDisabledMixin:f.fieldBackgroundHoverMixin,"text-base"),readOnly:i,renderHTML:y=>Hs.render(y),view:{menu:!0,md:!0,html:!1},onChange:({html:y,text:w})=>{u(w??null)}}),r.jsx(be,{includeDescription:g,showError:l,error:o,disabled:i,property:d})]})}const Js=`
3
+ `)?r.jsx("div",{className:"overflow-x-scroll",children:l.map((i,s)=>r.jsxs(d.Fragment,{children:[r.jsx("span",{children:i}),s!==l.length-1&&r.jsx("br",{})]},`string_preview_${s}`))}):r.jsx(r.Fragment,{children:t})}}}function Yr({propertyKey:e,value:t,property:n,size:o}){const l=q(),i=We({propertyKey:e,property:n,propertyValue:t,fields:l.propertyConfigs});if(!i.of)throw Error(`You need to specify an 'of' prop (or specify a custom field) in your array property ${e}`);if(i.dataType!=="array")throw Error("Picked wrong preview component ArrayPreview");const s=t;if(!s)return null;const a=o==="medium"?"small":"tiny";return r.jsx("div",{className:"flex flex-col gap-2",children:s&&s.map((c,f)=>{const g=i.resolvedProperties[f]??i.resolvedProperties[f]??(Array.isArray(i.of)?i.of[f]:i.of);return g?r.jsx(d.Fragment,{children:r.jsx("div",{className:A.cn(A.defaultBorderMixin,"m-1 border-b last:border-b-0"),children:r.jsx(re,{children:r.jsx(be,{propertyKey:e,value:c,property:g,size:a})})})},"preview_array_"+f):null})})}const De=dr.memo(function(t){const n=t.reference;return n instanceof Fe?r.jsx(Fi,{...t}):(console.warn("Reference preview received value of type",typeof n),r.jsx(Zt,{onClick:t.onClick,size:t.size,children:r.jsx(me,{error:"Unexpected value. Click to edit",tooltip:JSON.stringify(n)})}))},Si);function Si(e,t){return e.disabled===t.disabled&&e.size===t.size&&e.onHover===t.onHover&&e.reference?.id===t.reference?.id&&e.reference?.path===t.reference?.path&&e.allowEntityNavigation===t.allowEntityNavigation}function Fi({disabled:e,reference:t,previewProperties:n,size:o,onHover:l,onClick:i,allowEntityNavigation:s=!0}){const a=q(),f=ie().getCollection(t.path);if(!f){if(a.components?.missingReference)return r.jsx(a.components.missingReference,{path:t.path});throw Error(`Couldn't find the corresponding collection view for the path: ${t.path}`)}return r.jsx(Ni,{reference:t,collection:f,previewProperties:n,size:o,disabled:e,allowEntityNavigation:s,onClick:i,onHover:l})}function Ni({reference:e,collection:t,previewProperties:n,size:o,disabled:l,allowEntityNavigation:i,onClick:s,onHover:a}){const c=q(),f=He(),{entity:g,dataLoading:p,dataLoadingError:h}=Tr({path:e.path,entityId:e.id,collection:t,useCache:!0});g&&fo.set(e.pathWithId,g);const u=g??fo.get(e.pathWithId),m=d.useMemo(()=>Ie({collection:t,path:e.path,values:u?.values,fields:c.propertyConfigs}),[t]),b=d.useMemo(()=>zn(m,c.propertyConfigs,n,o==="small"||o==="medium"?3:1),[n,m,o]);let y;return m?(e?u&&!u.values?y=r.jsx(me,{error:"Reference does not exist",tooltip:e.path}):y=r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"flex flex-col flex-grow w-full max-w-[calc(100%-52px)] m-1",children:[o!=="tiny"&&(e?r.jsx("div",{className:`${o!=="medium"?"block whitespace-nowrap overflow-hidden truncate":""}`,children:r.jsx(A.Typography,{variant:"caption",className:"font-mono",children:e.id})}):r.jsx(A.Skeleton,{})),b&&b.map(C=>{const w=m.properties[C];return w?r.jsx("div",{className:b.length>1?"my-0.5":"my-0",children:u?r.jsx(be,{propertyKey:C,value:$e(u.values,C),property:w,size:"tiny"}):r.jsx(ut,{property:w,size:"tiny"})},"ref_prev_"+C):null})]}),r.jsx("div",{className:`my-${o==="tiny"?2:4}`,children:!l&&u&&i&&r.jsx(A.Tooltip,{title:`See details for ${u.id}`,children:r.jsx(A.IconButton,{color:"inherit",size:"small",onClick:C=>{C.stopPropagation(),c.onAnalyticsEvent?.("entity_click_from_reference",{path:u.path,entityId:u.id}),f.open({entityId:u.id,path:u.path,collection:m,updateUrl:!0})},children:r.jsx(A.KeyboardTabIcon,{size:"small"})})})})]}):y=r.jsx(me,{error:"Reference not set"}),r.jsx(Zt,{onClick:l?void 0:s,onHover:l?void 0:a,size:o,children:y})):r.jsx(me,{error:"Could not find collection with id "+m})}function Zt({children:e,onHover:t,size:n,onClick:o}){return r.jsx(A.Typography,{variant:"label",className:A.cn("bg-opacity-70 bg-gray-100 dark:bg-gray-800 dark:bg-opacity-60","w-full","flex","rounded-md","overflow-hidden",t?"hover:bg-opacity-90 dark:hover:bg-opacity-90":"",n==="medium"?"p-2":"p-1",n==="tiny"?"items-center":"","transition-colors duration-300 ease-in-out ",o?"cursor-pointer":""),style:{tabindex:0},onClick:l=>{o&&(l.preventDefault(),o(l))},children:e})}const fo=new Map;function uo({propertyKey:e,value:t,property:n,size:o}){const l=q(),i=We({propertyKey:e,property:n,propertyValue:t,fields:l.propertyConfigs});if(Array.isArray(i?.of))throw Error("Using array properties instead of single one in `of` in ArrayProperty");if(i?.dataType!=="array"||!i.of||i.of.dataType!=="reference")throw Error("Picked wrong preview component ArrayOfReferencesPreview");const s=o==="medium"?"small":"tiny";return r.jsx("div",{className:"flex flex-col w-full",children:t&&t.map((a,c)=>{const f=i.of;return r.jsx("div",{className:"mt-1 mb-1 w-full",children:r.jsx(De,{disabled:!f.path,previewProperties:f.previewProperties,size:s,reference:a})},`preview_array_ref_${e}_${c}`)})})}function go({propertyKey:e,value:t,property:n,size:o}){const l=q(),i=We({propertyKey:e,property:n,propertyValue:t,fields:l.propertyConfigs});if(Array.isArray(i.of))throw Error("Using array properties instead of single one in `of` in ArrayProperty");if(i.dataType!=="array"||!i.of||i.of.dataType!=="string")throw Error("Picked wrong preview component ArrayOfStorageComponentsPreview");const s=o==="medium"?"small":"tiny";return r.jsx("div",{className:"flex flex-wrap gap-2",children:t&&t.map((a,c)=>r.jsx(re,{children:r.jsx(be,{propertyKey:e,value:a,property:i.of,size:s})},`preview_array_storage_${e}_${c}`))})}function zr({name:e,value:t,enumValues:n,size:o}){return r.jsx("div",{className:"flex flex-wrap gap-1.5",children:t&&t.map((l,i)=>r.jsx(re,{children:r.jsx(Ce,{enumKey:l,enumValues:n,size:o!=="medium"?"small":"medium"})},`preview_array_ref_${e}_${i}`))})}function Ur({propertyKey:e,value:t,property:n,size:o}){if(n.dataType!=="array")throw Error("Picked wrong preview component ArrayEnumPreview");const l=n.of;if(!l.enumValues)throw Error("Picked wrong preview component ArrayEnumPreview");return t?r.jsx(zr,{name:e,value:t,enumValues:l.enumValues,size:o}):null}function ho({propertyKey:e,value:t,property:n,size:o}){const l=q(),i=We({propertyKey:e,property:n,propertyValue:t,fields:l.propertyConfigs});if(Array.isArray(i.of))throw Error("Using array properties instead of single one in `of` in ArrayProperty");if(!i.of||i.dataType!=="array"||i.of.dataType!=="string")throw Error("Picked wrong preview component ArrayOfStringsPreview");if(t&&!Array.isArray(t))return r.jsx("div",{children:`Unexpected value: ${t}`});const s=i.of;return r.jsx("div",{className:"flex flex-col gap-2",children:t&&t.map((a,c)=>r.jsx("div",{children:r.jsx(re,{children:r.jsx(Gr,{propertyKey:e,property:s,value:a,size:o})})},`preview_array_strings_${e}_${c}`))})}function po({propertyKey:e,value:t,property:n,size:o}){const l=q(),i=We({propertyKey:e,property:n,propertyValue:t,fields:l.propertyConfigs});if(i?.dataType!=="array")throw Error("Picked wrong preview component ArrayPreview");if(!i?.oneOf)throw Error(`You need to specify an 'of' or 'oneOf' prop (or specify a custom field) in your array property ${e}`);const s=t;if(!s)return null;const a=o==="medium"?"small":"tiny",c=i.oneOf.typeField??vt,f=i.oneOf.valueField??Yt,g=i.oneOf.properties;return r.jsx("div",{className:"flex flex-col",children:s&&s.map((p,h)=>r.jsx(d.Fragment,{children:r.jsx("div",{className:A.cn(A.defaultBorderMixin,"m-1 border-b last:border-b-0"),children:r.jsx(re,{children:p&&r.jsx(be,{propertyKey:e,value:p[f],property:i.resolvedProperties[h]??g[p[c]],size:a})})})},"preview_array_"+p+"_"+h))})}function mo({propertyKey:e,value:t,property:n,size:o}){if(n.dataType!=="map")throw Error("Picked wrong preview component MapPropertyPreview");const l=n;if(!l.properties||Object.keys(l.properties??{}).length===0)return r.jsx(Lr,{value:t});if(!t)return null;const i=Object.keys(l.properties);return o==="tiny"?r.jsx("div",{className:"w-full flex flex-col space-y-1 md:space-y-2",children:i.map((s,a)=>r.jsx("div",{children:r.jsx(re,{children:r.jsx(be,{propertyKey:s,value:t[s],property:l.properties[s],size:o})},"map_preview_"+l.name+s+a)},`map_${s}`))}):r.jsx("div",{className:"flex flex-col gap-1 w-full",children:i&&i.map((s,a)=>{const c=l.properties[s];return r.jsxs("div",{className:A.cn(A.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(A.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(re,{children:!(c.dataType==="map"||c==="array")&&r.jsx(be,{propertyKey:s,value:t[s],property:c,size:o})})})]}),(c.dataType==="map"||c==="array")&&r.jsx("div",{className:A.cn(A.defaultBorderMixin,"border-l pl-4 ml-2 my-2"),children:r.jsx(be,{propertyKey:s,value:t[s],property:c,size:o})})]},`map_preview_table_${s}}`)})})}function Lr({value:e}){return typeof e!="object"?null:r.jsx("div",{className:"flex flex-col gap-1 w-full",children:Object.entries(e).map(([t,n])=>r.jsxs("div",{className:A.cn(A.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(A.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 n!="object"&&r.jsx(A.Typography,{children:r.jsx(re,{children:n&&n.toString()})})})]}),typeof n=="object"&&r.jsx("div",{className:A.cn(A.defaultBorderMixin,"border-l pl-4"),children:r.jsx(Lr,{value:n})})]},`map_preview_table_${t}}`))})}function bo({date:e}){const t=q(),n=t?.locale?En[t?.locale]:void 0,o=t?.dateTimeFormat??Qn,l=e?vl.format(e,o,{locale:n}):"";return r.jsx(r.Fragment,{children:l})}function yo({value:e}){return r.jsx(A.Checkbox,{checked:e})}function vo({value:e,property:t,size:n}){if(t.enumValues){const o=e,l=_e(t.enumValues);return l?r.jsx(Ce,{enumKey:o,enumValues:l,size:n!=="medium"?"small":"medium"}):r.jsx(r.Fragment,{children:e})}else return r.jsx(r.Fragment,{children:e})}const be=d.memo(function(t){const n=q();let o;const{property:l,propertyKey:i,value:s,size:a,height:c,width:f}=t,g=xe({propertyKey:i,propertyOrBuilder:l,propertyValue:s,fields:n.propertyConfigs});if(s===void 0||g===null)o=r.jsx(At,{});else if(g.Preview)o=d.createElement(g.Preview,{propertyKey:i,value:s,property:g,size:a,height:c,width:f,customProps:g.customProps});else if(s===null)o=r.jsx(At,{});else if(g.dataType==="string"){const p=g;typeof s=="string"?p.url?typeof p.url=="boolean"?o=r.jsx(kt,{size:t.size,url:s}):typeof p.url=="string"&&(o=r.jsx(kt,{size:t.size,url:s,previewType:p.url})):p.storage?o=r.jsx(ao,{storeUrl:g.storage?.storeUrl??!1,size:t.size,storagePathOrDownloadUrl:s}):p.markdown?o=r.jsx(A.Markdown,{source:s}):o=r.jsx(Gr,{...t,property:p,value:s}):o=rt(i,g.dataType,s)}else if(g.dataType==="array")if(s instanceof Array){const p=g;if(!p.of&&!p.oneOf)throw Error(`You need to specify an 'of' or 'oneOf' prop (or specify a custom field) in your array property ${i}`);p.of?Array.isArray(p.of)?o=r.jsx(Yr,{...t,value:s,property:g}):p.of.dataType==="reference"?o=r.jsx(uo,{...t,value:s,property:g}):p.of.dataType==="string"?p.of.enumValues?o=r.jsx(Ur,{...t,value:s,property:g}):p.of.storage?o=r.jsx(go,{...t,value:s,property:g}):o=r.jsx(ho,{...t,value:s,property:g}):p.of.dataType==="number"&&p.of.enumValues?o=r.jsx(Ur,{...t,value:s,property:g}):o=r.jsx(Yr,{...t,value:s,property:g}):p.oneOf&&(o=r.jsx(po,{...t,value:s,property:g}))}else o=rt(i,g.dataType,s);else g.dataType==="map"?typeof s=="object"?o=r.jsx(mo,{...t,property:g}):o=rt(i,g.dataType,s):g.dataType==="date"?s instanceof Date?o=r.jsx(bo,{date:s}):o=rt(i,g.dataType,s):g.dataType==="reference"?typeof g.path=="string"?s instanceof Fe?o=r.jsx(De,{disabled:!g.path,previewProperties:g.previewProperties,size:t.size,reference:s}):o=rt(i,g.dataType,s):o=r.jsx(At,{}):g.dataType==="boolean"?typeof s=="boolean"?o=r.jsx(yo,{value:s}):o=rt(i,g.dataType,s):g.dataType==="number"?typeof s=="number"?o=r.jsx(vo,{...t,value:s,property:g}):o=rt(i,g.dataType,s):o=JSON.stringify(s);return o??r.jsx(At,{})},ne);function rt(e,t,n){return console.warn(`Unexpected value for property ${e}, of type ${t}`,n),r.jsx(me,{title:"Unexpected value",error:`${JSON.stringify(n)}`})}function Pi({propertyKey:e,value:t,property:n,size:o}){const l=q(),i=We({propertyKey:e,property:n,propertyValue:t,fields:l.propertyConfigs});if(Array.isArray(i?.of))throw Error("Using array properties instead of single one in `of` in ArrayProperty");if(i?.dataType!=="array"||!i.of||i.of.dataType!=="map")throw Error("Picked wrong preview component ArrayOfMapsPreview");const s=i.of,a=s.properties;if(!a)throw Error(`You need to specify a 'properties' prop (or specify a custom field) in your map property ${e}`);const c=t,f=s.previewProperties;if(!c)return null;let g=f;return(!g||!g.length)&&(g=Object.keys(a),o&&(g=g.slice(0,3))),r.jsx("div",{className:"table-auto text-xs",children:r.jsx("div",{children:c&&c.map((p,h)=>r.jsx("div",{className:"border-b last:border-b-0",children:g&&g.map(u=>r.jsx("div",{className:"table-cell",children:r.jsx(re,{children:r.jsx(be,{propertyKey:u,value:p[u],property:a[u],size:"small"})})},`table-cell-${u}`))},`table_${p}_${h}`))})})}const Ti=dr.memo(function({builder:t}){const[n,o]=d.useState(!0),[l,i]=d.useState(null);return d.useEffect(()=>{let s=!1;return t.then(a=>{s||(o(!1),i(a))}).catch(a=>{o(!1),console.error(a)}),()=>{s=!0}},[t]),n?r.jsx(A.Skeleton,{}):r.jsx(dr.Fragment,{children:l})});function $r({entity:e,collection:t,path:n,className:o}){const l=q(),i=d.useMemo(()=>Ie({collection:t,path:n,entityId:e.id,values:e.values,fields:l.propertyConfigs}),[t,n,e]),s=q(),a=i.properties;return r.jsx("div",{className:"w-full "+o,children:r.jsxs("div",{className:"w-full mb-4",children:[r.jsxs("div",{className:A.cn(A.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}),s?.entityLinkBuilder&&r.jsx("a",{href:s.entityLinkBuilder({entity:e}),rel:"noopener noreferrer",target:"_blank",children:r.jsx(A.IconButton,{children:r.jsx(A.OpenInNewIcon,{size:"small"})})})]})]}),Object.entries(a).map(([c,f])=>{const g=e.values[c];return r.jsxs("div",{className:A.cn(A.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:f.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(be,{propertyKey:c,value:g,property:f,size:"medium"})})]},`reference_previews_${c}`)})]})})}function Qi(e){return e.dataType==="boolean"?"center":e.dataType==="number"?e.enumValues?"left":"right":e.dataType==="date"?"right":"left"}function wo(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:wo(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 _r(e){return`subcollection:${e.id??e.path}`}function Mi(e){const t=d.useRef(null),{disabled:n,value:o,multiline:l,updateValue:i,focused:s}=e,a=d.useRef(o),[c,f]=d.useState(o),g=d.useRef(!1);d.useEffect(()=>{a.current!==o&&o!==c&&f(o),a.current=o},[o]);const p=d.useCallback(()=>{!o&&!c||c!==o&&(a.current=c,i(c))},[c,i,o]);return _t(c,p,!s,2e3),d.useEffect(()=>{t.current&&s&&!g.current?(g.current=!0,t.current.focus({preventScroll:!0}),t.current.selectionStart=t.current.value.length,t.current.selectionEnd=t.current.value.length):g.current=s},[s,t]),r.jsx(A.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:h=>{const u=h.target.value;(l||!u.endsWith(`
4
+ `))&&f(u)},onFocus:()=>{g.current=!0},onBlur:()=>{g.current=!1,p()}})}function Wr(e){const{name:t,enumValues:n,error:o,internalValue:l,disabled:i,small:s,focused:a,updateValue:c,multiple:f,valueType:g}=e,p=Array.isArray(l)&&f||!Array.isArray(l)&&!f,h=d.useRef(null);d.useEffect(()=>{h.current&&a&&h.current?.focus({preventScroll:!0})},[a,h]);const u=d.useCallback(b=>{if(g==="number")if(f){const y=b.map(C=>parseFloat(C));c(y)}else c(parseFloat(b));else if(g==="string")c(b||null);else throw Error("Missing mapping in TableSelect")},[f,c,g]),m=(b,y)=>f&&Array.isArray(b)?r.jsx(zr,{value:b,name:t,enumValues:n,size:s?"small":"medium"},`${b}-${y}`):r.jsx(Ce,{enumKey:b,enumValues:n,size:s?"small":"medium"},`${b}-${y}`);return f?r.jsx(A.MultiSelect,{inputRef:h,containerClassName:"w-full h-full",className:"w-full h-full p-0 bg-transparent",position:"item-aligned",disabled:i,padding:!1,includeFocusOutline:!1,value:p?l.map(b=>b.toString()):[],onMultiValueChange:u,renderValue:m,children:n?.map(b=>r.jsx(A.MultiSelectItem,{value:String(b.id),children:r.jsx(Ce,{enumKey:b.id,enumValues:n,size:s?"small":"medium"})},b.id))}):r.jsx(A.Select,{inputRef:h,className:"w-full h-full p-0 bg-transparent",position:"item-aligned",disabled:i,multiple:f,padding:!1,includeFocusOutline:!1,value:p?f?l.map(b=>b.toString()):l?.toString():f?[]:"",onValueChange:u,onMultiValueChange:u,renderValue:m,children:n?.map(b=>r.jsx(A.SelectItem,{value:String(b.id),children:r.jsx(Ce,{enumKey:b.id,enumValues:n,size:s?"small":"medium"})},b.id))})}function Di(e){const{align:t,value:n,updateValue:o,focused:l}=e,i=n&&typeof n=="number"?n.toString():"",[s,a]=d.useState(i),c=d.useRef(n);d.useEffect(()=>{c.current!==n&&String(n)!==s&&a(n?n.toString():null),c.current=n},[n]);const f=d.useCallback(()=>{if(s!==i)if(s!=null){const h=parseFloat(s);if(isNaN(h))return;h!=null&&o(h)}else o(null)},[s,n]);_t(s,f,!l,2e3),d.useEffect(()=>{!l&&i!==s&&a(n!=null?n.toString():null)},[n,l]);const g=d.useRef(null);d.useEffect(()=>{g.current&&l&&g.current.focus({preventScroll:!0})},[l,g]);const p=/^-?[0-9]+[,.]?[0-9]*$/;return r.jsx("input",{ref:g,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:h=>{const u=h.target.value.replace(",",".");u.length===0&&a(null),(p.test(u)||u.startsWith("-"))&&a(u)}})}function Oi(e){const{internalValue:t,updateValue:n,focused:o}=e,l=d.useRef(null);return d.useEffect(()=>{l.current&&o&&l.current.focus({preventScroll:!0})},[o,l]),r.jsx(A.BooleanSwitch,{ref:l,size:"small",value:!!t,onValueChange:n})}function Vi(e){const{locale:t}=q(),{disabled:n,error:o,mode:l,internalValue:i,updateValue:s}=e;return r.jsx(A.DateTimeField,{value:i??void 0,onChange:a=>s(a),size:"medium",invisible:!0,className:"w-full h-full",inputClassName:"w-full h-full",mode:l,locale:t})}class re extends d.Component{constructor(t){super(t),this.state={error:null}}static getDerivedStateFromError(t){return{error:t}}componentDidCatch(t,n){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(A.ErrorIcon,{color:"error",size:"small"}),r.jsx("div",{className:"ml-4",children:"Error"})]}),r.jsx(A.Typography,{variant:"caption",children:this.state.error?.message??"See the error in the console"})]}):this.props.children}}async function Gi(e,t,n,o,l,i,s,a){let c;return typeof e=="function"?(c=await e({path:l,entityId:o,values:n,property:i,file:s,storage:t,propertyKey:a}),c||console.warn("Storage callback returned empty result. Using default name value")):c=Co(s,e,o,a,l),c||(c=st()+"_"+s.name),c}function Yi(e,t,n,o,l,i,s,a){let c;return typeof e=="function"?(c=e({path:l,entityId:o,values:n,property:i,file:s,storage:t,propertyKey:a}),c||console.warn("Storage callback returned empty result. Using default name value")):c=Co(s,e,o,a,l),c||(c=st()+"_"+s.name),c}function Co(e,t,n,o,l){const i=e.name.split(".").pop();let s=t.replace("{entityId}",n).replace("{propertyKey}",o).replace("{rand}",st()).replace("{file}",e.name).replace("{file.type}",e.type).replace("{path}",l);if(i){s=s.replace("{file.ext}",i);const a=e.name.replace(`.${i}`,"");s=s.replace("{file.name}",a)}return s||(s=st()+"_"+e.name),s}function Eo({entityId:e,entityValues:t,path:n,value:o,property:l,propertyKey:i,storageSource:s,disabled:a,onChange:c}){const f=l.dataType==="string"?l.storage:l.dataType==="array"&&l.of.dataType==="string"?l.of.storage:void 0,g=l.dataType==="array";if(!f)throw Error("Storage meta must be specified");const p=f?.metadata,h=g?"small":"medium",u=f?.imageCompression,m=(g?o??[]:o?[o]:[]).map(B=>({id:jr(),storagePathOrDownloadUrl:B,metadata:p,size:h})),[b,y]=d.useState(o),[C,w]=d.useState(m);d.useEffect(()=>{ne(b,o)||(y(o),w(m))},[m,o,b]);const E=d.useCallback(async B=>{if(f.fileName){const S=await Gi(f.fileName,f,t,e,n,l,B,i);if(!S||S.length===0)throw Error("You need to return a valid filename");return S}return st()+"_"+B.name},[e,t,n,l,i,f]),k=d.useCallback(B=>Yi(f.storagePath,f,t,e,n,l,B,i)??"/",[e,t,n,l,i,f]),x=d.useCallback(async(B,S,F)=>{console.debug("onFileUploadComplete",B,S);let Q=B;if(f.storeUrl&&(Q=(await s.getDownloadURL(B)).url),f.postProcess&&Q&&(Q=await f.postProcess(Q)),!Q){console.warn("uploadPathOrDownloadUrl is null");return}let N;S.storagePathOrDownloadUrl=Q,S.metadata=F,N=[...C],N=Bo(N),w(N);const M=N.filter(Y=>!!Y.storagePathOrDownloadUrl).map(Y=>Y.storagePathOrDownloadUrl);c(g?M:M?M[0]:null)},[C,g,c,f,s]),I=d.useCallback(async B=>{if(!B.length||a)return;let S;if(g)S=[...C,...await Promise.all(B.map(async F=>(u&&Hr(F)&&(F=await xo(F,u)),{id:jr(),file:F,fileName:await E(F),metadata:p,size:h})))];else{let F=B[0];u&&Hr(F)&&(F=await xo(F,u)),S=[{id:jr(),file:F,fileName:await E(F),metadata:p,size:h}]}S=Bo(S),w(S)},[a,E,C,p,g,h]);return{internalValue:C,setInternalValue:w,storage:f,fileNameBuilder:E,storagePathBuilder:k,onFileUploadComplete:x,onFilesAdded:I,multipleFilesSupported:g}}function Bo(e){return e.filter((t,n)=>(e.map(o=>o.storagePathOrDownloadUrl).indexOf(t.storagePathOrDownloadUrl)===n||!t.storagePathOrDownloadUrl)&&(e.map(o=>o.file).indexOf(t.file)===n||!t.file))}function jr(){return Math.floor(Math.random()*Math.floor(Number.MAX_SAFE_INTEGER))}const ko={"image/jpeg":"JPEG","image/png":"PNG","image/webp":"WEBP"},Hr=e=>ko[e.type]?ko[e.type]:null,zi=100,xo=(e,t)=>new Promise(n=>{const o=t.quality===void 0?zi:t.quality,l=o>=0&&o<=100?o:100,i=Hr(e);if(!i)throw Error("resizeAndCompressImage: Unsupported image format");El.imageFileResizer(e,t.maxWidth||Number.MAX_VALUE,t.maxHeight||Number.MAX_VALUE,i,l,0,s=>n(s),"file")});function Io({storagePath:e,entry:t,metadata:n,onFileUploadComplete:o,imageSize:l,simple:i}){const s=ct(),a=Je(),[c,f]=d.useState(),[g,p]=d.useState(!1),h=d.useRef(!1),u=d.useRef(!1),m=d.useCallback((b,y)=>{u.current||(u.current=!0,f(void 0),p(!0),s.uploadFile({file:b,fileName:y,path:e,metadata:n}).then(async({path:C})=>{console.debug("Upload successful"),await o(C,t,n),h.current&&p(!1)}).catch(C=>{console.warn("Upload error",C),h.current&&(f(C),p(!1),a.open({type:"error",message:"Error uploading file: "+C.message}))}).finally(()=>{u.current=!1}))},[t,n,o,s,e]);return d.useEffect(()=>(h.current=!0,t.file&&m(t.file,t.fileName),()=>{h.current=!1}),[t.file,t.fileName,m]),i?r.jsx("div",{className:`m-4 w-${l} h-${l}`,children:g&&r.jsx(A.Skeleton,{className:`w-${l} h-${l}`})}):r.jsxs("div",{className:A.cn(A.paperMixin,"relative m-4 border-box flex items-center justify-center",`min-w-[${l}px] min-h-[${l}px]`),children:[g&&r.jsx(A.Skeleton,{className:"w-full h-full"}),c&&r.jsx(me,{title:"Error uploading file",error:c})]})}function So({showError:e,disabled:t,showExpandIcon:n,selected:o,openPopup:l,children:i}){const s=d.useRef(null),a=d.useCallback(()=>{if(l){const f=s&&s?.current?.getBoundingClientRect();l(f)}},[]),c=d.useRef();return d.useEffect(()=>{c.current&&o&&c.current.focus({preventScroll:!0})},[o]),r.jsx(r.Fragment,{children:(e||!t&&n)&&r.jsxs("div",{ref:s,className:"absolute top-0.5 right-0.5 flex items-center",children:[o&&i,o&&!t&&n&&r.jsx(A.IconButton,{ref:c,color:"inherit",size:"small",onClick:a,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(io,{side:"left",className:"flex items-center justify-center",style:{width:32,height:32},title:e.message,children:r.jsx(A.ErrorOutlineIcon,{size:"small",color:"error"})})]})})}const Ui="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",Li="pt-0 border-2 border-solid",$i="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",_i="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 Wi(e){const{propertyKey:t,error:n,selected:o,openPopup:l,value:i,disabled:s,property:a,entity:c,path:f,previewSize:g,updateValue:p}=e,h=ct(),{internalValue:u,setInternalValue:m,onFilesAdded:b,storage:y,onFileUploadComplete:C,storagePathBuilder:w,multipleFilesSupported:E}=Eo({entityValues:c.values,entityId:c.id,path:f,property:a,propertyKey:t,storageSource:h,onChange:p,value:i,disabled:s});return r.jsx(ji,{internalValue:u,setInternalValue:m,name:t,disabled:s,autoFocus:!1,openPopup:l,error:n,selected:o,property:a,onChange:p,entity:c,storagePathBuilder:w,storage:y,multipleFilesSupported:E,onFilesAdded:b,onFileUploadComplete:C,previewSize:g})}function ji({property:e,name:t,internalValue:n,setInternalValue:o,openPopup:l,entity:i,selected:s,error:a,onChange:c,multipleFilesSupported:f,previewSize:g,disabled:p,autoFocus:h,storage:u,onFilesAdded:m,onFileUploadComplete:b,storagePathBuilder:y}){const[C,w]=d.useState(!1),E=f&&g==="medium"?"small":g;if(f){const U=e;if(Array.isArray(U.of))throw Error("Using array properties instead of single one in `of` in ArrayProperty");if(U.of){if(U.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 k=u?.metadata,x=!!n,I=Je(),{open:B,getRootProps:S,getInputProps:F,isDragActive:Q,isDragAccept:N,isDragReject:M}=wn.useDropzone({accept:u.acceptedFiles?u.acceptedFiles.map(U=>({[U]:[]})).reduce((U,V)=>({...U,...V}),{}):void 0,disabled:p,maxSize:u.maxSize,noClick:!0,noKeyboard:!0,onDrop:m,onDropRejected:(U,V)=>{for(const te of U)for(const $ of te.errors)I.open({type:"error",message:`Error uploading file: File is larger than ${u.maxSize} bytes`})}}),{...Y}=S(),W=f?"Drag 'n' drop some files here, or click here to edit":"Drag 'n' drop a file here, or click here edit",L=f?e.of:e,Z=d.useMemo(()=>ft(E),[E]),ee=!p&&a;return r.jsxs("div",{...Y,onMouseEnter:()=>w(!0),onMouseMove:()=>w(!0),onMouseLeave:()=>w(!1),className:A.cn(Ui,"relative w-full h-full flex",`justify-${x?"start":"center"}`,Q?Li:"",N?$i:"",M?_i:""),children:[r.jsx("input",{autoFocus:h,...F()}),n.map((U,V)=>{let te;return U.storagePathOrDownloadUrl?te=r.jsx(Hi,{property:L,value:U.storagePathOrDownloadUrl,entity:i,size:E},`storage_preview_${V}`):U.file&&(te=r.jsx(Io,{entry:U,metadata:k,storagePath:y(U.file),onFileUploadComplete:b,imageSize:Z,simple:!0},`storage_progress_${V}`)),te}),!n&&r.jsx("div",{className:"flex-grow m-2 max-w-[200px]",onClick:B,children:r.jsx(A.Typography,{className:"text-gray-400 dark:text-gray-600",variant:"body2",align:"center",children:W})}),r.jsx(So,{showError:ee,disabled:p,showExpandIcon:!0,selected:s,openPopup:p?void 0:l,children:r.jsx(A.IconButton,{color:"inherit",size:"small",onClick:B,children:r.jsx(A.EditIcon,{size:"small",className:"text-gray-500"})})})]})}function Hi({property:e,value:t,size:n,entity:o}){return r.jsx("div",{className:"relative m-2",children:t&&r.jsx(re,{children:r.jsx(be,{propertyKey:"ignore",value:t,property:e,size:n})})})}function Fo(e){const t=q(),n=ie(),{path:o}=e,l=n.getCollection(o);if(!l){if(t.components?.missingReference)return r.jsx(t.components.missingReference,{path:o});throw Error(`Couldn't find the corresponding collection view for the path: ${o}`)}return r.jsx(Ji,{...e,collection:l})}function Ji(e){const{name:t,internalValue:n,updateValue:o,multiselect:l,path:i,size:s,previewProperties:a,title:c,disabled:f,forceFilter:g,collection:p}=e,[h,u]=d.useState(!1),m=d.useCallback(()=>u(!0),[]),b=d.useCallback(()=>u(!1),[]),y=d.useCallback(S=>{o(S?Ge(S):null)},[o]),C=d.useCallback(S=>{o(S.map(F=>Ge(F)))},[o]),w=n?Array.isArray(n)?n.map(S=>S.id):n.id?[n.id]:[]:[],E=mt({multiselect:l,path:i,collection:p,onMultipleEntitiesSelected:C,onSingleEntitySelected:y,selectedEntityIds:w,forceFilter:g}),k=d.useCallback(()=>{f||E.open()},[f,E]),x=!n||Array.isArray(n)&&n.length===0,I=()=>n instanceof Fe?r.jsx(De,{onClick:f?void 0:k,size:qe(s),reference:n,onHover:h,disabled:!i,previewProperties:a}):r.jsx(Zt,{onClick:f?void 0:k,size:qe(s),children:r.jsx(me,{title:"Value is not a reference.",error:"Click to edit"})}),B=()=>Array.isArray(n)?r.jsx(r.Fragment,{children:n.map((S,F)=>r.jsx("div",{className:"m-1 w-full",children:r.jsx(De,{onClick:f?void 0:k,size:"tiny",reference:S,onHover:h,disabled:!i,previewProperties:a})},`preview_array_ref_${t}_${F}`))}):r.jsx(me,{error:"Data is not an array of references"});return p?r.jsxs("div",{className:"w-full",onMouseEnter:m,onMouseMove:m,onMouseLeave:b,children:[n&&!l&&I(),n&&l&&B(),x&&r.jsxs(A.Button,{onClick:k,size:"small",variant:"outlined",color:"primary",children:["Edit ",c]})]}):r.jsx(me,{error:"The specified collection does not exist"})}ke.addMethod(ke.array,"uniqueInArray",function(e=n=>n,t){return this.test("uniqueInArray",t,n=>!n||n.length===new Set(n.map(e)).size)});function No(e,t,n){const o={};return Object.entries(t).forEach(([l,i])=>{o[l]=xt({property:i,customFieldValidator:n,name:l,entityId:e})}),ke.object().shape(o)}function xt(e){const t=e.property;if(we(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 Zi(e);if(t.dataType==="number")return Xi(e);if(t.dataType==="boolean")return ts(e);if(t.dataType==="map")return qi(e);if(t.dataType==="array")return ns(e);if(t.dataType==="date")return Ri(e);if(t.dataType==="geopoint")return Ki(e);if(t.dataType==="reference")return es(e);throw console.error("Unsupported data type in yup mapping",t),Error("Unsupported data type in yup mapping")}function qi({property:e,entityId:t,customFieldValidator:n,name:o}){const l={};return e.validation,e.properties&&Object.entries(e.properties).forEach(([i,s])=>{l[i]=xt({property:s,parentProperty:e,customFieldValidator:n,name:`${o}[${i}]`,entityId:t})}),ke.object().shape(l)}function Zi({property:e,parentProperty:t,customFieldValidator:n,name:o,entityId:l}){let i=ke.string();const s=e.validation;if(e.enumValues){s?.required&&(i=i.required(s?.requiredMessage?s.requiredMessage:"Required"));const a=_e(e.enumValues);i=i.oneOf((s?.required?a:[...a,null]).map(c=>c?.id??null)).nullable(!0)}if(s){if(i=s.required?i.required(s?.requiredMessage?s.requiredMessage:"Required").nullable(!0):i.notRequired().nullable(!0),s.unique&&n&&o&&(i=i.test("unique","This value already exists and should be unique",(a,c)=>n({name:o,property:e,parentProperty:t,value:a,entityId:l}))),(s.min||s.min===0)&&(i=i.min(s.min,`${e.name} must be min ${s.min} characters long`)),(s.max||s.max===0)&&(i=i.max(s.max,`${e.name} must be max ${s.max} characters long`)),s.matches){const a=typeof s.matches=="string"?On(s.matches):s.matches;a&&(i=i.matches(a,s.matchesMessage?{message:s.matchesMessage}:void 0))}s.trim&&(i=i.trim()),s.lowercase&&(i=i.lowercase()),s.uppercase&&(i=i.uppercase()),e.email&&(i=i.email(`${e.name} must be an email`)),e.url&&(i=i.url(`${e.name} must be a url`))}else i=i.notRequired().nullable(!0);return i}function Xi({property:e,parentProperty:t,customFieldValidator:n,name:o,entityId:l}){const i=e.validation;let s=ke.number().typeError("Must be a number");return i?(s=i.required?s.required(i.requiredMessage?i.requiredMessage:"Required").nullable(!0):s.notRequired().nullable(!0),i.unique&&n&&o&&(s=s.test("unique","This value already exists and should be unique",a=>n({name:o,property:e,parentProperty:t,value:a,entityId:l}))),(i.min||i.min===0)&&(s=s.min(i.min,`${e.name} must be higher or equal to ${i.min}`)),(i.max||i.max===0)&&(s=s.max(i.max,`${e.name} must be lower or equal to ${i.max}`)),(i.lessThan||i.lessThan===0)&&(s=s.lessThan(i.lessThan,`${e.name} must be higher than ${i.lessThan}`)),(i.moreThan||i.moreThan===0)&&(s=s.moreThan(i.moreThan,`${e.name} must be lower than ${i.moreThan}`)),i.positive&&(s=s.positive(`${e.name} must be positive`)),i.negative&&(s=s.negative(`${e.name} must be negative`)),i.integer&&(s=s.integer(`${e.name} must be an integer`))):s=s.notRequired().nullable(!0),s}function Ki({property:e,parentProperty:t,customFieldValidator:n,name:o,entityId:l}){let i=ke.object();const s=e.validation;return s?.unique&&n&&o&&(i=i.test("unique","This value already exists and should be unique",a=>n({name:o,property:e,parentProperty:t,value:a,entityId:l}))),s?.required?i=i.required(s.requiredMessage).nullable(!0):i=i.notRequired().nullable(!0),i}function Ri({property:e,parentProperty:t,customFieldValidator:n,name:o,entityId:l}){if(e.autoValue)return ke.object().nullable();let i=ke.date();const s=e.validation;return s?(i=s.required?i.required(s?.requiredMessage?s.requiredMessage:"Required"):i.notRequired(),s.unique&&n&&o&&(i=i.test("unique","This value already exists and should be unique",a=>n({name:o,property:e,parentProperty:t,value:a,entityId:l}))),s.min&&(i=i.min(s.min,`${e.name} must be after ${s.min}`)),s.max&&(i=i.max(s.max,`${e.name} must be before ${s.min}`))):i=i.notRequired(),i.transform(a=>a instanceof Date?a:null).nullable()}function es({property:e,parentProperty:t,customFieldValidator:n,name:o,entityId:l}){let i=ke.object();const s=e.validation;return s?(i=s.required?i.required(s?.requiredMessage?s.requiredMessage:"Required").nullable(!0):i.notRequired().nullable(!0),s.unique&&n&&o&&(i=i.test("unique","This value already exists and should be unique",a=>n({name:o,property:e,parentProperty:t,value:a,entityId:l})))):i=i.notRequired().nullable(!0),i}function ts({property:e,parentProperty:t,customFieldValidator:n,name:o,entityId:l}){let i=ke.boolean();const s=e.validation;return s?(i=s.required?i.required(s?.requiredMessage?s.requiredMessage:"Required").nullable(!0):i.notRequired().nullable(!0),s.unique&&n&&o&&(i=i.test("unique","This value already exists and should be unique",a=>n({name:o,property:e,parentProperty:t,value:a,entityId:l})))):i=i.notRequired().nullable(!0),i}function rs(e){return e.validation?.uniqueInArray?!0:e.dataType==="map"&&e.properties?Object.entries(e.properties).filter(([t,n])=>n.validation?.uniqueInArray):!1}function ns({property:e,parentProperty:t,customFieldValidator:n,name:o,entityId:l}){let i=ke.array();if(e.of)if(Array.isArray(e.of)){const a=e.of.map((c,f)=>({[`${o}[${f}]`]:xt({property:c,parentProperty:e,entityId:l})})).reduce((c,f)=>({...c,...f}),{});return ke.array().of(ke.mixed().test("Dynamic object validation","Dynamic object validation error",(c,f)=>$e(a,f.path).validate(c)))}else{i=i.of(xt({property:e.of,parentProperty:e,entityId:l}));const a=rs(e.of);a&&(typeof a=="boolean"?i=i.uniqueInArray(c=>c,`${e.name} should have unique values within the array`):Array.isArray(a)&&a.forEach(([c,f])=>{i=i.uniqueInArray(g=>g&&g[c],`${e.name} → ${f.name??c}: should have unique values within the array`)}))}const s=e.validation;return s?(i=s.required?i.required(s?.requiredMessage?s.requiredMessage:"Required").nullable(!0):i.notRequired().nullable(!0),(s.min||s.min===0)&&(i=i.min(s.min,`${e.name} should be min ${s.min} entries long`)),s.max&&(i=i.max(s.max,`${e.name} should be max ${s.max} entries long`))):i=i.notRequired().nullable(!0),i}function gt(e){switch(e){case"xl":return 400;case"l":return 280;case"m":return 140;case"s":return 80;case"xs":return 54;default:throw Error("Missing mapping for collection size -> height")}}const os=({justifyContent:e,scrollable:t,faded:n,fullHeight:o,children:l})=>r.jsx("div",{className:A.cn("flex flex-col max-h-full w-full",{"items-start":n||t}),style:{justifyContent:e,height:o?"100%":void 0,overflow:t?"auto":void 0,WebkitMaskImage:n?"linear-gradient(to bottom, black 60%, transparent 100%)":void 0,maskImage:n?"linear-gradient(to bottom, black 60%, transparent 100%)":void 0},children:l}),Jr=d.memo(function({children:t,actions:n,size:o,selected:l,disabled:i,disabledTooltip:s,saved:a,error:c,align:f,allowScroll:g,removePadding:p,fullHeight:h,onSelect:u,width:m,hideOverflow:b=!0,showExpandIcon:y=!0}){const[C,w]=cr(),E=d.useRef(null);A.useOutsideAlerter(E,()=>{l&&u&&u(void 0)},!!(l&&u));const[k,x]=d.useState(!1),I=d.useMemo(()=>gt(o),[o]),[B,S]=d.useState(!1),[F,Q]=d.useState(a),N=!i&&c;d.useEffect(()=>{a&&Q(!0);const $=setTimeout(()=>{Q(!1)},800);return()=>{clearTimeout($)}},[a]);let M=0;if(!p)switch(o){case"l":case"xl":M=4;break;case"m":M=2;break;case"s":default:M=1;break}let Y;switch(f){case"right":Y="flex-end";break;case"center":Y="center";break;case"left":default:Y="flex-start"}const W=d.useCallback(()=>{if(!u)return;const $=E&&E?.current?.getBoundingClientRect();i?u(void 0):!l&&$&&u($)},[E,u,l,i]),L=d.useCallback($=>{W(),$.stopPropagation()},[W]);d.useEffect(()=>{if(w){const $=w.height>I;k!==$&&x($)}},[w,k,I]);const Z=!N&&l,ee=!i&&g&&k,U=!i&&!g&&k,V=d.useCallback(()=>S(!0),[]),te=d.useCallback(()=>S(!1),[]);return r.jsxs("div",{ref:E,className:A.cn("transition-colors duration-100 ease-in-out",`flex relative h-full rounded-md p-${M} border border-4 border-opacity-75`,B&&!i?"bg-gray-50 dark:bg-gray-900":"",a?"bg-gray-100 bg-opacity-75 dark:bg-gray-800 dark:bg-opacity-75":"",!Z&&!F&&!N?"border-transparent":"",b?"overflow-hidden":"",Z?"bg-gray-50 dark:bg-gray-900":"",Z&&!F?"border-primary":"",F?"border-green-500 ":"",N?"border-red-500":""),style:{justifyContent:Y,alignItems:i||!k?"center":void 0,width:m??"100%",textAlign:f},tabIndex:l||i?void 0:0,onFocus:L,onMouseEnter:V,onMouseMove:V,onMouseLeave:te,children:[r.jsxs(re,{children:[h&&!U&&t,(!h||U)&&r.jsx(os,{fullHeight:h??!1,justifyContent:Y,scrollable:ee??!1,faded:U,children:!h&&r.jsx("div",{ref:C,style:{display:"flex",width:"100%",justifyContent:Y,height:h?"100%":void 0},children:t})})]}),n,i&&B&&s&&r.jsx("div",{className:"absolute top-1 right-1 text-xs",children:r.jsx(A.Tooltip,{title:s,children:r.jsx(A.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);function ls(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 is=d.memo(function({propertyKey:t,customFieldValidator:n,value:o,property:l,align:i,width:s,height:a,path:c,entity:f,readonly:g,disabled:p}){const h=q(),{onValueChange:u,size:m,selectedCell:b,select:y,setPopupCell:C}=Cs(),w=b?.propertyKey===t&&b?.entity.path===f.path&&b?.entity.id===f.id,[E,k]=d.useState(o),x=d.useRef(o),[I,B]=d.useState(),[S,F]=d.useState(!1),Q=d.useCallback(()=>{F(!0),setTimeout(()=>{F(!1)},100)},[]),N=!!l.Field,M=!!l.Preview,Y=it(l),W=typeof l.disabled=="object"?l.disabled.disabledMessage:void 0,L=g||p||!!l.disabled,Z=d.useMemo(()=>xt({property:l,entityId:f.id,customFieldValidator:n,name:t}),[f.id,l,t]);d.useEffect(()=>{ne(o,x.current)||(B(void 0),k(o),x.current=o,Q())},[Q,o]);const ee=P=>{ne(P,x.current)||(F(!1),Z.validate(P).then(()=>{B(void 0),x.current=P,u&&u({value:P,propertyKey:t,setError:B,onValueUpdated:Q,entity:f,fullPath:c,context:h})}).catch(D=>{B(D)}))};d.useEffect(()=>{Z.validate(E).then(()=>B(void 0)).catch(P=>{B(P)})},[E,Z,t,l,f]);const U=P=>{let D;P===void 0?D=null:D=P,k(D),ee(D)};Se({property:l,value:E,setValue:U});const V=d.useCallback(P=>{y(P?{width:s,height:a,entity:f,cellRect:P,propertyKey:t}:void 0)},[f,a,t,y,s]),te=P=>{C&&C(P?{width:s,height:a,entity:f,cellRect:P,propertyKey:t}:void 0)};let $,H=!1,se=!1,ae=!0,T=!1,z=!1,j=!0;const X=!L&&I;if(g||Y)return r.jsx(Jr,{size:m,width:s,saved:S,value:E,align:i??"left",fullHeight:!1,disabledTooltip:W??(Y?"Read only":void 0),disabled:!0,children:r.jsx(be,{width:s,height:gt(m),propertyKey:t,property:l,value:E,size:qe(m)})},`${t}_${f.path}_${f.id}`);if(!N&&(!M||w)){if(ls(l))$=r.jsx(Wi,{error:I,disabled:L,focused:w,selected:w,openPopup:C?te:void 0,property:l,entity:f,path:c,value:E,previewSize:qe(m),updateValue:U,propertyKey:t}),j=!1,se=!0,z=!0,T=!0;else if(w&&l.dataType==="number"){const D=l;D.enumValues?($=r.jsx(Wr,{name:t,multiple:!1,disabled:L,focused:w,valueType:"number",small:qe(m)!=="medium",enumValues:D.enumValues,error:I,internalValue:E,updateValue:U}),z=!0):($=r.jsx(Di,{align:i,error:I,focused:w,disabled:L,value:E,updateValue:U}),H=!0)}else if(w&&l.dataType==="string"){const D=l;if(D.enumValues)$=r.jsx(Wr,{name:t,multiple:!1,focused:w,disabled:L,valueType:"string",small:qe(m)!=="medium",enumValues:D.enumValues,error:I,internalValue:E,updateValue:U}),z=!0;else if(!D.storage){const le=!!D.multiline||!!D.markdown;$=r.jsx(Mi,{error:I,disabled:L,multiline:le,focused:w,value:E,updateValue:U}),H=!0}}else if(l.dataType==="boolean")$=r.jsx(Oi,{error:I,disabled:L,focused:w,internalValue:E,updateValue:U});else if(l.dataType==="date")$=r.jsx(Vi,{name:t,error:I,disabled:L,mode:l.mode,focused:w,internalValue:E,updateValue:U}),z=!0,ae=!1,H=!1;else if(l.dataType==="reference")typeof l.path=="string"&&($=r.jsx(Fo,{name:t,internalValue:E,updateValue:U,disabled:L,size:m,path:l.path,multiselect:!1,previewProperties:l.previewProperties,title:l.name,forceFilter:l.forceFilter})),H=!1;else if(l.dataType==="array"){const D=l;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"?w&&D.of.enumValues&&($=r.jsx(Wr,{name:t,multiple:!0,disabled:L,focused:w,small:qe(m)!=="medium",valueType:D.of.dataType,enumValues:D.of.enumValues,error:I,internalValue:E,updateValue:U}),H=!0,z=!0,ae=!1):D.of.dataType==="reference"&&(typeof D.of.path=="string"&&($=r.jsx(Fo,{name:t,disabled:L,internalValue:E,updateValue:U,size:m,multiselect:!0,path:D.of.path,previewProperties:D.of.previewProperties,title:D.of.name,forceFilter:D.of.forceFilter})),H=!1))}}return $||(H=!1,se=w&&!$&&!L&&!Y,$=r.jsx(be,{width:s,height:a,propertyKey:t,value:E,property:l,size:qe(m)})),r.jsx(Jr,{size:m,width:s,onSelect:V,selected:w,disabled:L||Y,disabledTooltip:W??"Disabled",removePadding:T,fullHeight:z,saved:S,error:I,align:i,allowScroll:H,showExpandIcon:se,value:E,hideOverflow:ae,actions:j&&r.jsx(So,{showError:X,disabled:L,showExpandIcon:se,selected:w,openPopup:L?void 0:te}),children:$},`cell_${t}_${f.path}_${f.id}`)},ss);function ss(e,t){return e.height===t.height&&e.propertyKey===t.propertyKey&&e.align===t.align&&e.width===t.width&&ne(e.property,t.property)&&ne(e.value,t.value)&&ne(e.entity.id,t.entity.id)&&ne(e.entity.values,t.entity.values)}function Xt({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(A.CircularProgress,{...t}),e&&r.jsx(A.Typography,{color:"secondary",variant:"caption",className:"text-center",children:e})]})})}const as=d.memo(function({resizeHandleRef:t,columnIndex:n,isResizingIndex:o,sort:l,onColumnSort:i,onFilterUpdate:s,filter:a,column:c,onClickResizeColumn:f,createFilterField:g,AdditionalHeaderWidget:p}){const[h,u]=d.useState(!1),[m,b]=d.useState(!1),[y,C]=d.useState(!1),w=d.useCallback(B=>{b(!0)},[]),E=d.useCallback((B,S)=>{s(c,B),S!==void 0&&b(S)},[c,s]),k=o===n,I=!(o!==n&&o>0)&&(h||k);return r.jsx(re,{children:r.jsxs("div",{className:A.cn("flex py-0 px-3 h-full text-xs uppercase font-semibold relative select-none items-center bg-gray-50 dark:bg-gray-900","text-gray-600 hover:text-gray-800 dark:text-gray-400 dark:hover:text-gray-200 ","hover:bg-gray-100 dark:hover:bg-gray-800 hover:bg-opacity-50 dark:hover:bg-opacity-50",c.frozen?"sticky left-0 z-10":"relative z-0"),style:{left:c.frozen?0:void 0,minWidth:c.width,maxWidth:c.width},onMouseEnter:()=>u(!0),onMouseMove:()=>u(!0),onMouseLeave:()=>u(!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&&c.icon(h||m),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:[p&&r.jsx(p,{onHover:h||m}),c.sortable&&(l||I||m)&&r.jsx(A.Badge,{color:"secondary",invisible:!l,children:r.jsxs(A.IconButton,{size:"small",className:h||m?"bg-white dark:bg-gray-950":void 0,onClick:()=>{i(c.key)},children:[!l&&r.jsx(A.ArrowUpwardIcon,{}),l==="asc"&&r.jsx(A.ArrowUpwardIcon,{}),l==="desc"&&r.jsx(A.ArrowUpwardIcon,{className:"rotate-180"})]})})]}),c.filter&&g&&r.jsx("div",{children:r.jsx(A.Badge,{color:"secondary",invisible:!a,children:r.jsx(A.Popover,{open:m,onOpenChange:b,className:y?"hidden":void 0,modal:!0,trigger:r.jsx(A.IconButton,{className:h||m?"bg-white dark:bg-gray-950":void 0,size:"small",onClick:w,children:r.jsx(A.FilterListIcon,{size:"small"})}),children:r.jsx(cs,{column:c,filter:a,onHover:h,onFilterUpdate:E,createFilterField:g,hidden:y,setHidden:C})})})}),c.resizable&&r.jsx("div",{ref:t,className:A.cn("absolute h-full w-[6px] top-0 right-0 cursor-col-resize",I&&"bg-gray-300 dark:bg-gray-700"),onMouseDown:f?()=>f(n,c):void 0})]})})},ne);function cs({column:e,onFilterUpdate:t,filter:n,onHover:o,createFilterField:l,hidden:i,setHidden:s}){const a=e.key,[c,f]=d.useState(n);if(d.useEffect(()=>{f(n)},[n]),!e.filter)return null;const g=()=>{t(c,!1)},p=m=>{t(void 0,!1)},h=!!n,u=l({id:a,filterValue:c,setFilterValue:f,column:e,hidden:i,setHidden:s});return u?r.jsxs("div",{className:"text-gray-900 dark:text-white",children:[r.jsx("div",{className:A.cn(A.defaultBorderMixin,"py-4 px-6 text-xs font-semibold uppercase border-b"),children:e.title??a}),u&&r.jsx("div",{className:"m-4",children:u}),r.jsxs("div",{className:"flex justify-end m-4",children:[r.jsx(A.Button,{className:"mr-4",disabled:!h,variant:"text",color:"primary",type:"reset","aria-label":"filter clear",onClick:p,children:"Clear"}),r.jsx(A.Button,{variant:"outlined",color:"primary",onClick:g,children:"Filter"})]})]}):null}const ds=({columns:e,currentSort:t,onColumnSort:n,onFilterUpdate:o,sortByProperty:l,filter:i,onColumnResize:s,onColumnResizeEnd:a,createFilterField:c,AddColumnComponent:f})=>{const g=e.map(()=>d.createRef()),[p,h]=d.useState(-1),u=d.useCallback((x,I,B)=>{const S=e[x],F=100,Q=800,N=I>Q?Q:I<F?F:I,M={width:N,key:S.key,column:{...S,width:N}};B?a(M):s(M)},[e,s,a]),m=d.useCallback(x=>{if(p>=0){const I=g[p].current?.parentElement?.getBoundingClientRect().left;return I?x.clientX-I:void 0}},[g,p]),b=d.useCallback(x=>{document.body.style.cursor=x?"col-resize":"auto"},[]),y=d.useCallback(x=>{x.stopPropagation(),x.preventDefault();const I=m(x);I&&u(p,I,!1)},[u,m,p]),C=d.useCallback(x=>{x.stopPropagation(),x.preventDefault();const I=m(x);I&&u(p,I,!0),h(-1),b(!1)},[u,m,p,b]),w=d.useCallback(()=>{document.removeEventListener("mousemove",y),document.removeEventListener("mouseup",C)},[y,C]),E=d.useCallback(()=>{document.addEventListener("mousemove",y),document.addEventListener("mouseup",C)},[y,C]);d.useEffect(()=>(p>=0?E():w(),()=>{w()}),[E,p,w]);const k=d.useCallback(x=>{h(x),b(!0)},[b]);return r.jsxs("div",{className:A.cn(A.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((x,I)=>{const B=e[I],S=B&&i&&i[B.key]?i[B.key]:void 0;return r.jsx(re,{children:r.jsx(as,{resizeHandleRef:g[I],columnIndex:I,isResizingIndex:p,onFilterUpdate:o,filter:S,sort:l===B.key?t:void 0,onColumnSort:n,onClickResizeColumn:k,column:B,createFilterField:c,AdditionalHeaderWidget:B.AdditionalHeaderWidget})},"header_"+B.key)}),f&&r.jsx(f,{})]})},As=d.memo(function({rowData:t,rowIndex:n,children:o,onRowClick:l,size:i,style:s,hoverRow:a,rowClassName:c}){const f=d.useCallback(g=>{console.debug("VirtualTableRow click"),l&&l({rowData:t,rowIndex:n,event:g})},[l,t,n]);return r.jsx("div",{className:A.cn("flex min-w-full text-sm border-b border-gray-200 dark:border-gray-800 border-opacity-40 dark:border-opacity-40",c?c(t):"",{"hover:bg-opacity-95":a,"cursor-pointer":l}),onClick:f,style:{...s,height:gt(i),width:"fit-content"},children:o})},ne),fs=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)=>ne(e,t)),Kt=d.createContext({});Kt.displayName="VirtualListContext";const us=d.forwardRef(({children:e,...t},n)=>r.jsx(Kt.Consumer,{children:o=>{const l=o.customView;return r.jsxs(r.Fragment,{children:[r.jsx("div",{id:"virtual-table",style:{position:"relative",height:"100%"},children:r.jsxs("div",{ref:n,...t,style:{...t?.style,minHeight:"100%",position:"relative"},children:[r.jsx(ds,{...o}),!l&&e]})}),l&&r.jsx("div",{style:{position:"sticky",top:"56px",flexGrow:1,height:"calc(100% - 56px)",marginTop:"calc(56px - 100vh)",left:0},children:l})]})}})),Po=d.memo(function({data:t,onResetPagination:n,onEndReached:o,size:l="m",columns:i,onRowClick:s,onColumnResize:a,filter:c,checkFilterCombination:f,onFilterUpdate:g,sortBy:p,error:h,emptyComponent:u,onSortByUpdate:m,loading:b,cellRenderer:y,hoverRow:C,createFilterField:w,rowClassName:E,className:k,endAdornment:x,AddColumnComponent:I}){const B=p?p[0]:void 0,S=p?p[1]:void 0,[F,Q]=d.useState(i),N=d.useRef(null),M=d.useRef(0);d.useEffect(()=>{Q(i)},[i]);const[Y,W]=cr(),L=d.useCallback(P=>{Q(F.map(D=>D.key===P.column.key?P.column:D))},[F]),Z=d.useCallback(P=>{Q(F.map(D=>D.key===P.column.key?P.column:D)),a&&a(P)},[F,a]),ee=d.useRef();d.useEffect(()=>{ee.current=c},[c]);const U=d.useCallback(()=>{M.current=0,N.current&&N.current.scrollTo(N.current?.scrollLeft,0)},[]),V=d.useCallback(P=>{const D=B===P&&S==="desc",fe=B===P&&S==="asc"?"desc":D?void 0:"asc",ce=D?void 0:P,Ee=ee.current,Ze=fe&&ce?[ce,fe]:void 0;Ee&&f&&!f(Ee,Ze)&&g&&g(void 0),n&&n(),m&&m(Ze),U()},[f,S,g,n,m,U,B]),te=d.useCallback(()=>{M.current=0,m&&m(void 0)},[m]),$=Math.max((t?.length??0)*gt(l)-W.height,0),H=d.useCallback(P=>{o&&(t?.length??0)>0&&P>M.current+600&&(M.current=P,o())},[t?.length,o]),se=d.useCallback(({scrollOffset:P,scrollUpdateWasRequested:D})=>{!D&&P>=$-600&&H(P)},[$,H]),ae=d.useCallback((P,D)=>{M.current=0;const le=ee.current;let fe=le?{...le}:{};D?fe[P.key]=D:delete fe[P.key],!f||f(fe,B&&S?[B,S]:void 0)||(fe=D?{[P.key]:D}:{}),g&&g(fe),P.key!==B&&te()},[f,S,g,te,B]),T=d.useCallback(()=>r.jsxs("div",{className:"h-full flex flex-col items-center justify-center sticky left-0",children:[r.jsx(A.Typography,{variant:"h6",children:"Error fetching data from the data source"}),h?.message&&r.jsx(A.Markdown,{className:"px-4 break-all",source:h.message})]}),[h?.message]),z=d.useCallback(()=>b?r.jsx(Xt,{}):r.jsxs("div",{className:"flex flex-col overflow-auto items-center justify-center p-2 gap-2 h-full",children:[r.jsx(A.AssignmentIcon,{}),u]}),[u,b]),j=!b&&(t?.length??0)===0,X=h?T():j?z():void 0;return r.jsx("div",{ref:Y,className:A.cn("h-full w-full",k),children:r.jsx(Kt.Provider,{value:{data:t,size:l,cellRenderer:y,columns:F,currentSort:S,onRowClick:s,customView:X,onColumnResize:L,onColumnResizeEnd:Z,filter:ee.current,onColumnSort:V,onFilterUpdate:ae,sortByProperty:B,hoverRow:C??!1,createFilterField:w,rowClassName:E,endAdornment:x,AddColumnComponent:I},children:r.jsx(gs,{outerRef:N,width:W.width,height:W.height,itemCount:(t?.length??0)+(x?1:0),onScroll:se,includeAddColumn:!!I,itemSize:gt(l)},l)})})},ne);function gs({outerRef:e,width:t,height:n,itemCount:o,onScroll:l,itemSize:i,includeAddColumn:s}){const a=d.useCallback(({index:c,style:f})=>r.jsx(Kt.Consumer,{children:({onRowClick:g,data:p,columns:h,size:u="m",cellRenderer:m,hoverRow:b,rowClassName:y,endAdornment:C})=>{if(C&&c===(p??[]).length)return r.jsx("div",{style:{...f,height:"auto",position:"sticky",bottom:0,zIndex:1},children:C});const w=p&&p[c];return r.jsxs(As,{rowData:w,rowIndex:c,onRowClick:g,columns:h,hoverRow:b,rowClassName:y,style:{...f,top:`calc(${f.top}px + 48px)`},size:u,children:[h.map((E,k)=>{const x=w&&w[E.key];return r.jsx(fs,{dataKey:E.key,cellRenderer:m,column:E,columns:h,rowData:w,cellData:x,rowIndex:c,columnIndex:k},`cell_${E.key}`)}),s&&r.jsx("div",{className:"w-20"})]},`row_${c}`)}}),[]);return r.jsx(Cl.FixedSizeList,{outerRef:e,innerElementType:us,width:t,height:n,overscanCount:4,itemCount:o,onScroll:l,itemSize:i,children:a})}const qr=d.memo(function({entity:t,collection:n,fullPath:o,width:l,frozen:i,isSelected:s,selectionEnabled:a,size:c,highlightEntity:f,onCollectionChange:g,unhighlightEntity:p,actions:h=[],hideId:u,selectionController:m}){const b=Qe(),y=q(),C=d.useCallback(B=>{m?.toggleEntitySelection(t)},[t,m?.toggleEntitySelection]),w=d.useCallback(B=>{B.stopPropagation(),m?.toggleEntitySelection(t)},[t,m?.toggleEntitySelection]),E=h.length>0,k=h.some(B=>B.collapsed||B.collapsed===void 0),x=h.filter(B=>B.collapsed||B.collapsed===void 0),I=h.filter(B=>B.collapsed===!1);return r.jsxs("div",{onClick:w,className:A.cn("h-full flex items-center justify-center flex-col bg-gray-50 dark:bg-gray-900 bg-opacity-90 dark:bg-opacity-90 z-10",i?"sticky left-0":""),style:{width:l,position:i?"sticky":"initial",left:i?0:"initial",contain:"strict"},children:[(E||a)&&r.jsxs("div",{className:"w-34 flex justify-center",children:[I.map((B,S)=>r.jsx(A.Tooltip,{title:B.name,children:r.jsx(A.IconButton,{onClick:F=>{F.stopPropagation(),B.onClick({entity:t,fullPath:o,collection:n,context:y,selectionController:m,highlightEntity:f,unhighlightEntity:p,onCollectionChange:g})},size:b?"medium":"small",children:B.icon})},S)),k&&r.jsx(A.Menu,{trigger:r.jsx(A.IconButton,{size:b?"medium":"small",children:r.jsx(A.MoreVertIcon,{})}),children:x.map((B,S)=>r.jsxs(A.MenuItem,{onClick:F=>{F.stopPropagation(),B.onClick({entity:t,fullPath:o,collection:n,context:y,selectionController:m,highlightEntity:f,unhighlightEntity:p,onCollectionChange:g})},children:[B.icon,B.name]},S))}),a&&r.jsx(A.Tooltip,{title:`Select ${t.id}`,children:r.jsx(A.Checkbox,{size:b?"medium":"small",checked:s,onCheckedChange:C})})]}),!u&&c!=="xs"&&r.jsx("div",{className:"w-[138px] text-center overflow-hidden truncate",children:t?r.jsxs(A.Typography,{onClick:B=>{B.stopPropagation()},className:"font-mono select-all",variant:"caption",color:"secondary",children:[" ",t.id," "]}):r.jsx(A.Skeleton,{})})]})},ne);function hs(e){const t=Qe(),n=!e.forceFilter&&e.filterIsSet&&e.clearFilter&&r.jsxs(A.Button,{variant:"outlined",className:"h-fit-content","aria-label":"filter clear",onClick:e.clearFilter,size:"small",children:[r.jsx(A.FilterListOffIcon,{}),"Clear filter"]}),o=r.jsx(A.Select,{value:e.size,className:"w-16 h-10",size:"small",onValueChange:l=>e.onSizeChanged(l),renderValue:l=>r.jsx("div",{className:"font-medium",children:l.toUpperCase()}),children:["xs","s","m","l","xl"].map(l=>r.jsx(A.SelectItem,{value:l,className:"w-12 font-medium text-center",children:l.toUpperCase()},l))});return r.jsxs("div",{className:A.cn(A.defaultBorderMixin,"no-scrollbar min-h-[56px] overflow-x-auto 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",children:[e.title&&r.jsx("div",{className:"hidden lg:block",children:e.title}),o,e.actionsStart,n]}),r.jsxs("div",{className:"flex items-center gap-2",children:[t&&r.jsx("div",{className:"w-[22px]",children:e.loading&&r.jsx(A.CircularProgress,{size:"small"})}),e.onTextSearch&&r.jsx(A.SearchBar,{onTextSearch:e.onTextSearch,expandable:!0},"search-bar"),e.actions]})]})}const To={"==":"==","!=":"!=",">":">","<":"<",">=":">=","<=":"<=",in:"In","not-in":"Not in","array-contains":"Contains","array-contains-any":"Contains Any"},Zr=["array-contains-any","in","not-in"];function ps({name:e,value:t,setValue:n,isArray:o,path:l,title:i,previewProperties:s,setHidden:a}){const c=o?["array-contains"]:["==","!=",">","<",">=","<="],[f,g]=d.useState(!1);o?c.push("array-contains-any"):c.push("in","not-in");const[p,h]=t||[c[0],void 0],[u,m]=d.useState(p),[b,y]=d.useState(h),C=b?Array.isArray(b)?b.map(N=>N instanceof Fe?N.id:null).filter(Boolean):[b.id]:[];function w(N,M){const Y=Zr.includes(u),W=Zr.includes(N);let L=M;Y!==W&&(L=W?L instanceof Fe?[L]:[]:void 0),m(N),y(L);const Z=L!==null&&Array.isArray(L)?L.length>0:L!==void 0;n(N&&Z?[N,L]:void 0)}const E=ie(),k=d.useMemo(()=>l?E.getCollection(l):void 0,[l]),x=N=>{w(u,Ge(N))},I=N=>{w(u,N.map(M=>Ge(M)))},B=Zr.includes(u),S=mt({multiselect:B,path:l,collection:k,onSingleEntitySelected:x,onMultipleEntitiesSelected:I,selectedEntityIds:C,onClose:()=>{a(!1)}}),F=()=>{a(!0),S.open()},Q=N=>r.jsx("div",{className:"mb-0.5",onMouseEnter:()=>g(!0),onMouseMove:()=>g(!0),onMouseLeave:()=>g(!1),children:r.jsx(De,{disabled:!l,previewProperties:s,size:"medium",onClick:F,reference:N,onHover:f,allowEntityNavigation:!1})});return r.jsxs("div",{className:"flex w-[440px] flex-row",children:[r.jsx("div",{className:"w-[120px]",children:r.jsx(A.Select,{value:u,onValueChange:N=>{w(N,b)},renderValue:N=>To[N],children:c.map(N=>r.jsx(A.SelectItem,{value:N,children:To[N]},N))})}),r.jsxs("div",{className:"flex-grow ml-2 h-full",children:[b&&Array.isArray(b)&&r.jsx("div",{children:b.map((N,M)=>Q(N))}),b&&!Array.isArray(b)&&r.jsx("div",{children:Q(b)}),(!b||Array.isArray(b)&&b.length===0)&&r.jsx(A.Button,{onClick:F,variant:"outlined",className:"h-full w-full",children:B?"Select references":"Select reference"})]})]})}const Qo={"==":"==","!=":"!=",">":">","<":"<",">=":">=","<=":"<=",in:"In","not-in":"Not in","array-contains":"Contains","array-contains-any":"Any"},Xr=["array-contains-any","in","not-in"];function ms({name:e,value:t,setValue:n,dataType:o,isArray:l,enumValues:i,title:s}){const a=l?["array-contains"]:["==","!=",">","<",">=","<="];i&&(l?a.push("array-contains-any"):a.push("in","not-in"));const[c,f]=t||[a[0],void 0],[g,p]=d.useState(c),[h,u]=d.useState(f);function m(y,C){let w=C;const E=Xr.includes(g),k=Xr.includes(y);E!==k&&(w=k?typeof C=="string"||typeof C=="number"?[C]:[]:""),typeof w=="number"&&isNaN(w)&&(w=void 0),p(y),u(w);const x=w!==null&&Array.isArray(w)?w.length>0:w!==void 0;n(y&&x?[y,w]:void 0)}const b=Xr.includes(g);return r.jsxs("div",{className:"flex w-[440px] items-center",children:[r.jsx("div",{className:"w-[80px]",children:r.jsx(A.Select,{value:g,position:"item-aligned",onValueChange:y=>{m(y,h)},renderValue:y=>Qo[y],children:a.map(y=>r.jsx(A.SelectItem,{value:y,children:Qo[y]},y))})}),r.jsxs("div",{className:"flex-grow ml-2",children:[!i&&r.jsx(A.TextField,{type:o==="number"?"number":void 0,value:h!==void 0?String(h):"",onChange:y=>{const C=o==="number"?parseFloat(y.target.value):y.target.value;m(g,C)},endAdornment:h&&r.jsx(A.IconButton,{className:"absolute right-3 top-2",onClick:y=>m(g,void 0),children:r.jsx(A.ClearIcon,{})})}),i&&r.jsx(A.Select,{position:"item-aligned",value:h!==void 0?Array.isArray(h)?h.map(y=>String(y)):String(h):l?[]:"",onValueChange:y=>{m(g,o==="number"?parseInt(y):y)},multiple:b,endAdornment:h&&r.jsx(A.IconButton,{className:"absolute right-3 top-2",onClick:y=>m(g,void 0),children:r.jsx(A.ClearIcon,{})}),renderValue:y=>r.jsx(Ce,{enumKey:y,enumValues:i,size:"small"},`select_value_${e}_${y}`),children:i.map(y=>r.jsx(A.SelectItem,{value:String(y.id),children:r.jsx(Ce,{enumKey:String(y.id),enumValues:i,size:"small"})},`select_value_${e}_${y.id}`))})]})]})}function bs({name:e,title:t,value:n,setValue:o}){function l(a){o(a!==void 0?["==",a]:void 0)}const i=n&&n[1],s=!!n;return r.jsx("div",{className:"w-[200px]",children:r.jsx(A.BooleanSwitchWithLabel,{value:i,allowIndeterminate:!0,onValueChange:a=>l(a===null?void 0:a),label:s?i?`${t} is true`:`${t} is false`:"No filter"})})}const Mo={"==":"==","!=":"!=",">":">","<":"<",">=":">=","<=":"<=","not-in":"not in",in:"in","array-contains":"Contains","array-contains-any":"Any"},Do=["array-contains-any","in"];function ys({name:e,isArray:t,mode:n,value:o,setValue:l,title:i}){const{locale:s}=q(),a=t?["array-contains"]:["==","!=",">","<",">=","<="],[c,f]=o||[a[0],void 0],[g,p]=d.useState(c),[h,u]=d.useState(f);function m(b,y){let C=y;const w=Do.includes(g),E=Do.includes(b);w!==E&&(C=E?y?[y]:[]:""),p(b),u(C===null?void 0:C);const k=C!==null&&Array.isArray(C)?C.length>0:C!==void 0;l(b&&k?[b,C]:void 0)}return r.jsxs("div",{className:"flex w-[440px] items-center",children:[r.jsx("div",{className:"w-[80px]",children:r.jsx(A.Select,{value:g,onValueChange:b=>{m(b,h)},renderValue:b=>Mo[b],children:a.map(b=>r.jsx(A.SelectItem,{value:b,children:Mo[b]},b))})}),r.jsx("div",{className:"flex-grow ml-2",children:r.jsx(A.DateTimeField,{mode:n,size:"medium",locale:s,value:h,onChange:b=>{m(g,b===null?void 0:b)},clearable:!0})})]})}const Oo="collectionGroupParent";function Vo(e,t){return d.useMemo(()=>e.propertiesOrder?Go(e,e.propertiesOrder):vs(e,t),[e,t])}function Go(e,t){return t.flatMap(n=>{const o=e.properties[n];return o?o.hideFromCollection?[null]:o.disabled&&typeof o.disabled=="object"&&o.disabled.hidden?[null]:o.dataType==="map"&&o.spreadChildren&&o.properties?Kr(o,n):[{key:n,disabled:!!o.disabled||!!o.readOnly}]:e.additionalFields?.find(i=>i.key===n)?[{key:n,disabled:!0}]:e.subcollections&&e.subcollections.find(s=>_r(s)===n)?[{key:n,disabled:!0}]:e.collectionGroup&&n===Oo?[{key:n,disabled:!0}]:[null]}).filter(Boolean)}function vs(e,t){const n=Object.keys(e.properties),o=e.additionalFields??[],l=e.subcollections??[],i=[...n,...o.map(s=>s.key)];if(t){const s=l.map(a=>_r(a));i.push(...s.filter(a=>!i.includes(a)))}return e.collectionGroup&&i.push(Oo),Go(e,i)}function Kr(e,t,n){return e.dataType==="map"&&e.spreadChildren&&e.properties?Object.entries(e.properties).flatMap(([o,l])=>Kr(l,`${t}.${o}`,n||!!e.disabled||!!e.readOnly)):[{key:t,disabled:n||!!e.disabled||!!e.readOnly}]}const ws={},Yo=d.createContext(ws),Cs=()=>d.useContext(Yo),Rr=d.memo(function({forceFilter:t,actionsStart:n,actions:o,title:l,tableRowActionsBuilder:i,uniqueFieldValidator:s,getPropertyFor:a,onValueChange:c,selectionController:f,highlightedEntities:g,onEntityClick:p,onColumnResize:h,onSizeChanged:u,textSearchEnabled:m=!1,hoverRow:b=!0,inlineEditing:y=!1,additionalFields:C,displayedColumnIds:w,defaultSize:E,properties:k,tableController:{data:x,dataLoading:I,noMoreToLoad:B,dataLoadingError:S,filterValues:F,setFilterValues:Q,sortBy:N,setSortBy:M,setSearchString:Y,clearFilter:W,itemCount:L,setItemCount:Z,pageSize:ee=50,paginationEnabled:U,checkFilterCombination:V,setPopupCell:te},filterable:$=!0,sortable:H=!0,endAdornment:se,AddColumnComponent:ae,AdditionalHeaderWidget:T,additionalIDHeaderWidget:z,emptyComponent:j,getIdColumnWidth:X}){const P=Qe(),D=!!t,le=f?.selectedEntities?.length>0?f?.selectedEntities:g,fe=q(),[ce,Ee]=d.useState(E??"m"),[Ze,ze]=d.useState(void 0),Ve=le?.map(_=>_.id),St=!!F&&Object.keys(F).length>0,bt=()=>{!U||I||B||L!==void 0&&Z?.(L+ee)},Ft=d.useCallback(()=>{Z?.(ee)},[ee]),Xe=d.useCallback(({rowData:_})=>{if(console.debug("EntityCollectionTable click"),!y)return p&&p(_)},[p,y]),Ke=d.useCallback(_=>{u&&u(_),Ee(_)},[]),Nt=d.useCallback(_=>Y?.(_),[]),Re=d.useMemo(()=>C?C.map(_=>({[_.key]:_})).reduce((_,he)=>({..._,...he}),{}):{},[C]);d.useEffect(()=>{const _=he=>{he.keyCode===27&&Tt()};return document.addEventListener("keydown",_,!1),()=>{document.removeEventListener("keydown",_,!1)}});const Pt=d.useCallback(_=>{ze(_)},[]),Tt=d.useCallback(()=>{ze(void 0)},[]),G=s,O=d.useCallback(({column:_,columnIndex:he,rowData:Ae,rowIndex:Me})=>{const oe=Ae,Ue=_.key;let Le=_.custom?.disabled;const bn=oe.values?$e(oe.values,Ue):void 0,ot=a?.({propertyKey:Ue,propertyValue:bn,entity:oe})??_.custom.resolvedProperty;return ot?.disabled||(Le=!1),ot?r.jsx(re,{children:oe?r.jsx(is,{readonly:!y,align:_.align??"left",propertyKey:Ue,property:ot,value:oe?.values?$e(oe.values,Ue):void 0,customFieldValidator:G,columnIndex:he,width:_.width,height:gt(ce),entity:oe,disabled:Le,path:oe.path},`property_table_cell_${oe.id}_${Ue}`):Ye()}):null},[G,y,ce,Ve]),J=d.useCallback(({column:_,rowData:he,width:Ae})=>{const Me=he,oe=Re[_.key],Ue=oe.dependencies?Object.entries(Me.values).filter(([ot,yl])=>oe.dependencies.includes(ot)).reduce((ot,yl)=>({...ot,...yl}),{}):Me,Le=oe.Builder;if(!Le&&!oe.value)throw new Error("When using additional fields you need to provide a Builder or a value");const bn=Le?r.jsx(Le,{entity:Me,context:fe}):r.jsx(r.Fragment,{children:oe.value?.({entity:Me,context:fe})});return r.jsx(Jr,{width:Ae,size:ce,value:Ue,selected:!1,disabled:!0,align:"left",allowScroll:!1,showExpandIcon:!1,disabledTooltip:"This column can't be edited directly",children:r.jsx(re,{children:bn})},`additional_table_cell_${Me.id}_${_.key}`)},[Re,ce,Ve]),K=d.useMemo(()=>{const _=Object.entries(k).flatMap(([Ae,Me])=>Kr(Me,Ae)).map(({key:Ae,disabled:Me})=>{const oe=xr(k,Ae);if(!oe)throw Error("Internal error: no property found in path "+Ae);const Ue=zo(oe);return{key:Ae,align:Qi(oe),icon:Le=>pe(oe,"small"),title:oe.name??Ae,sortable:H&&(t?Object.keys(t).includes(Ae):!0),filter:!D&&Ue,width:wo(oe),resizable:!0,custom:{resolvedProperty:oe,disabled:Me},AdditionalHeaderWidget:({onHover:Le})=>T?r.jsx(T,{property:oe,propertyKey:Ae,onHover:Le}):void 0}}),he=C?C.map(Ae=>({key:Ae.key,align:"left",sortable:!1,title:Ae.name,width:Ae.width??200})):[];return[..._,...he]},[C,D,t,k,H]),R=d.useMemo(()=>({key:"id_ewcfedcswdf3",width:X?.()??(P?160:130),title:"ID",resizable:!1,frozen:P,headerAlign:"center",align:"center",AdditionalHeaderWidget:()=>z}),[X,P]),de=d.useMemo(()=>[R,...w.map(_=>K.find(he=>he.key===_.key)).filter(Boolean)],[K,w,R]),Oe=d.useCallback(_=>{const he=_.column,Ae=_.columns,Me=he.key;if(_.columnIndex===0)return i?i({entity:_.rowData,size:ce,width:he.width,frozen:he.frozen}):r.jsx(qr,{entity:_.rowData,width:he.width,frozen:he.frozen,isSelected:!1,size:ce});if(Re[Me])return J(_);if(_.columnIndex<Ae.length+1)return O(_);throw Error("Internal: columns not mapped properly")},[Re,i,ce,J,O]),Qt=d.useCallback(_=>{Q?.({..._,...t})},[t]);return r.jsx(Yo.Provider,{value:{setPopupCell:te,select:Pt,onValueChange:c,size:ce,selectedCell:Ze,selectedEntityIds:Ve},children:r.jsxs("div",{className:"h-full w-full flex flex-col bg-white dark:bg-gray-950",children:[r.jsx(hs,{forceFilter:D,filterIsSet:St,onTextSearch:m?Nt:void 0,clearFilter:W,size:ce,onSizeChanged:Ke,title:l,actionsStart:n,actions:o,loading:I}),r.jsx(Po,{data:x,columns:de,cellRenderer:Oe,onRowClick:y?void 0:p?Xe:void 0,onEndReached:bt,onResetPagination:Ft,error:S,paginationEnabled:U,onColumnResize:h,size:ce,loading:I,filter:F,onFilterUpdate:Q?Qt:void 0,sortBy:N,onSortByUpdate:M,hoverRow:b,emptyComponent:j,checkFilterCombination:V,createFilterField:$?Es:void 0,rowClassName:d.useCallback(_=>Ve?.includes(_.id)?"bg-gray-100 bg-opacity-75 dark:bg-gray-800 dark:bg-opacity-75":"",[Ve]),className:"flex-grow",endAdornment:se,AddColumnComponent:ae})]})})},ne);function Es({id:e,filterValue:t,setFilterValue:n,column:o,hidden:l,setHidden:i}){if(!o.custom)return null;const{resolvedProperty:s}=o.custom,a=s?.dataType==="array",c=a?s.of:s;if(!c)return null;if(c.dataType==="reference")return r.jsx(ps,{value:t,setValue:n,name:e,isArray:a,path:c.path,title:s?.name,previewProperties:c?.previewProperties,hidden:l,setHidden:i});if(c.dataType==="number"||c.dataType==="string"){const f=c.name,g=c.enumValues?_e(c.enumValues):void 0;return r.jsx(ms,{value:t,setValue:n,name:e,dataType:c.dataType,isArray:a,enumValues:g,title:f})}else if(c.dataType==="boolean"){const f=c.name;return r.jsx(bs,{value:t,setValue:n,name:e,title:f})}else if(c.dataType==="date"){const f=c.name;return r.jsx(ys,{value:t,setValue:n,name:e,mode:c.mode,isArray:a,title:f})}return r.jsx("div",{children:`Currently the filter field ${s.dataType} is not supported`})}function zo(e,t=!1){return t?["string","number","date","reference"].includes(e.dataType):e.dataType==="array"?e.of?zo(e.of,!0):!1:["string","number","boolean","date","reference","array"].includes(e.dataType)}function Bs({data:e,entitiesDisplayedFirst:t}){if(!t)return e;const n=new Set(t.map(o=>o.id));return[...t,...e.filter(o=>!n.has(o.id))]}function ks(e,t,n=5e3){const[o,l]=d.useState(e),i=d.useRef(o.length??0),s=d.useRef(!1),a=d.useRef(t),c=!ne(a.current,t),f=e.length>=i.current||c;return d.useEffect(()=>{const g=()=>{ne(o,e)||(a.current=t,i.current=e.length,l(e)),s.current=!1};s.current=!0;let p;return f?g():p=setTimeout(g,n),()=>{clearTimeout(p),s.current&&f&&g()}},[e,n,t,f]),f?e:o}const xs=50;function en({fullPath:e,collection:t,entitiesDisplayedFirst:n,lastDeleteTimestamp:o,forceFilter:l}){const{initialFilter:i,initialSort:s,forceFilter:a}=t,[c,f]=d.useState(void 0),g=ie(),p=Te(),h=d.useMemo(()=>g.resolveAliasesFrom(e),[e,g.resolveAliasesFrom]),u=l??a,m=t.pagination===void 0||!!t.pagination,b=typeof t.pagination=="number"?t.pagination:xs,[y,C]=d.useState(),[w,E]=d.useState(m?b:void 0),k=d.useCallback((U,V)=>p.isFilterCombinationValid?p.isFilterCombinationValid({path:h,collection:t,filterValues:U,sortBy:V}):!0,[]),x=d.useMemo(()=>{if(s&&u&&!k(u,s)){console.warn("Initial sort is not compatible with the force filter. Ignoring initial sort");return}return s},[s,u]),[I,B]=d.useState(u??i??void 0),[S,F]=d.useState(x),Q=d.useCallback(()=>B(u??void 0),[u]),N=d.useCallback(U=>{if(u){console.warn("Filter is not compatible with the force filter. Ignoring filter");return}U&&Object.keys(U).length===0?B(void 0):B(U)},[u]),{data:M,dataLoading:Y,noMoreToLoad:W,dataLoadingError:L}=ro({path:e,collection:t,filterValues:I,sortBy:S,searchString:y,itemCount:w}),Z=Bs({data:M,entitiesDisplayedFirst:n});return{data:ks(Z,{filterValues:I,sortBy:S,searchString:y,lastDeleteTimestamp:o}),dataLoading:Y,noMoreToLoad:W,dataLoadingError:L,filterValues:I,setFilterValues:N,sortBy:S,setSortBy:F,searchString:y,setSearchString:C,clearFilter:Q,itemCount:w,setItemCount:E,paginationEnabled:m,pageSize:b,checkFilterCombination:k,popupCell:c,setPopupCell:f}}function Uo({entityOrEntitiesToDelete:e,collection:t,onClose:n,open:o,callbacks:l,onEntityDelete:i,onMultipleEntitiesDelete:s,path:a}){const c=Te();console.log("dataSource",c);const f=Je(),[g,p]=d.useState(!1),[h,u]=d.useState(),[m,b]=d.useState(),y=q();d.useEffect(()=>{if(e){const N=Array.isArray(e)&&e.length===1?e[0]:e;u(N),b(Array.isArray(N))}},[e]);const C=d.useMemo(()=>Ie({collection:t,path:a,fields:y.propertyConfigs}),[t,a]),w=d.useCallback(()=>{n()},[n]),E=d.useCallback(N=>{console.debug("Deleted",N)},[]),k=d.useCallback((N,M)=>{f.open({type:"error",message:"Error deleting: "+M?.message}),console.error("Error deleting entity"),console.error(M)},[C.name]),x=d.useCallback((N,M)=>{f.open({type:"error",message:"Error before deleting: "+M?.message}),console.error(M)},[C.name]),I=d.useCallback((N,M)=>{f.open({type:"error",message:"Error after deleting: "+M?.message}),console.error(M)},[C.name]),B=d.useCallback(N=>no({dataSource:c,entity:N,collection:C,callbacks:l,onDeleteSuccess:E,onDeleteFailure:k,onPreDeleteHookError:x,onDeleteSuccessHookError:I,context:y}),[c,C,l,E,k,x,I,y]),S=d.useCallback(async()=>{h&&(p(!0),m?Promise.all(h.map(B)).then(N=>{p(!1),s&&h&&s(a,h),N.every(Boolean)?f.open({type:"success",message:`${C.name}: multiple deleted`}):N.some(Boolean)?f.open({type:"warning",message:`${C.name}: Some of the entities have been deleted, but not all`}):f.open({type:"error",message:`${C.name}: Error deleting entities`}),n()}):B(h).then(N=>{p(!1),N&&(i&&h&&i(a,h),f.open({type:"success",message:`${C.singularName??C.name} deleted`}),n())}))},[h,m,B,s,a,n,f,C.name,i]);let F;if(h&&m)F=r.jsx(r.Fragment,{children:"Multiple entities"});else{const N=h;F=N?r.jsx($r,{entity:N,collection:t,path:a}):r.jsx(r.Fragment,{})}const Q=m?r.jsxs(r.Fragment,{children:[r.jsx("b",{children:C.name}),": Confirm multiple delete?"]}):`Would you like to delete this ${C.singularName??C.name}?`;return r.jsxs(A.Dialog,{maxWidth:"2xl","aria-labelledby":"delete-dialog",open:o,onOpenChange:N=>N?void 0:n(),children:[r.jsxs(A.DialogContent,{fullHeight:!0,children:[r.jsx(A.Typography,{variant:"subtitle2",className:"p-4",children:Q}),!m&&r.jsx("div",{className:"p-4",children:F})]}),r.jsxs(A.DialogActions,{children:[g&&r.jsx(A.CircularProgress,{size:"small"}),r.jsx(A.Button,{onClick:w,disabled:g,variant:"text",color:"primary",children:"Cancel"}),r.jsx(A.Button,{autoFocus:!0,disabled:g,onClick:S,variant:"filled",color:"primary",children:"Ok"})]})]})}function Rt(e){return Array.isArray(e)?e:e?[e]:[]}function Is({collection:e,relativePath:t,parentCollectionIds:n,onNewClick:o,onMultipleDeleteClick:l,selectionEnabled:i,path:s,selectionController:a,tableController:c,collectionEntitiesCount:f}){const g=q(),p=g.plugins??[],h=je(),u=Qe(),m=a.selectedEntities,b=at(e,h,Pe(s),null)&&o&&(u?r.jsxs(A.Button,{id:`add_entity_${s}`,onClick:o,startIcon:r.jsx(A.AddIcon,{}),size:"large",variant:"filled",color:"primary",children:["Add ",e.singularName??e.name]}):r.jsx(A.Button,{id:`add_entity_${s}`,onClick:o,size:"medium",variant:"filled",color:"primary",children:r.jsx(A.AddIcon,{})})),y=Ht(e,h,Pe(s),null);let C;if(i){const k=u?r.jsxs(A.Button,{variant:"text",disabled:!m?.length||!y,startIcon:r.jsx(A.DeleteIcon,{}),onClick:l,color:"primary",className:"lg:w-20",children:["(",m?.length,")"]}):r.jsx(A.IconButton,{color:"primary",disabled:!m?.length||!y,onClick:l,children:r.jsx(A.DeleteIcon,{})});C=r.jsx(A.Tooltip,{title:y?"Delete":"You have selected at least one entity you cannot delete",children:k})}const w={path:s,relativePath:t,parentCollectionIds:n,collection:e,selectionController:a,context:g,tableController:c,collectionEntitiesCount:f},E=Rt(e.Actions).map((k,x)=>r.jsx(re,{children:r.jsx(k,{...w})},`actions_${x}`));return p&&p.forEach((k,x)=>{k.collections?.CollectionActions&&E.push(...Rt(k.collections?.CollectionActions).map((I,B)=>r.jsx(re,{children:r.jsx(I,{...w,...k.collections?.collectionActionsProps})},`plugin_actions_${x}_${B}`)))}),r.jsxs(r.Fragment,{children:[E,C,b]})}function Ss({containerRef:e,innerRef:t,x:n,y:o,onMove:l}){let i=0,s=0;const a=d.useRef(!1),c=m=>{if(m.button!==0||!e.current||m.defaultPrevented||m.innerClicked)return;const{x:b,y}=e.current.getBoundingClientRect();i=m.screenX-b,s=m.screenY-y,document.addEventListener("mousemove",h),document.addEventListener("mouseup",p),document.addEventListener("selectstart",g),a.current=!0},f=m=>{m.innerClicked=!0},g=m=>{m.preventDefault(),m.stopPropagation()},p=m=>{document.removeEventListener("mousemove",h),document.removeEventListener("mouseup",p),document.removeEventListener("selectstart",g),m.stopPropagation(),a.current=!1},h=m=>{m.target.localName==="input"||!a.current||(l({x:m.screenX-i,y:m.screenY-s}),m.stopPropagation())},u=()=>{e.current&&(e.current.style.top=`${o}px`,e.current.style.left=`${n}px`)};d.useEffect(()=>{const m=e.current,b=t.current;if(!(!m||!b))return b&&b.addEventListener("mousedown",f),m&&m.addEventListener("mousedown",c),u(),()=>{m&&m.removeEventListener("mousedown",c),b&&b.removeEventListener("mousedown",f)}})}function Fs(){const[e,t]=d.useState({width:0,height:0});return d.useLayoutEffect(()=>{function n(){t({width:window.innerWidth,height:window.innerHeight})}return window.addEventListener("resize",n),n(),()=>window.removeEventListener("resize",n)},[]),e}const Ns=({onResize:e})=>{const t=d.useRef(0),n=d.useRef(null),o=d.useRef(e);o.current=e;const l=d.useCallback(s=>{t.current&&cancelAnimationFrame(t.current),t.current=requestAnimationFrame(()=>{o.current(s)})},[]),i=d.useCallback(()=>{const s=n.current;s&&s.contentDocument&&s.contentDocument.defaultView&&s.contentDocument.defaultView.addEventListener("resize",l)},[l]);return d.useEffect(()=>{const s=n.current;return()=>{s&&s.contentDocument&&s.contentDocument.defaultView&&s.contentDocument.defaultView.removeEventListener("resize",l)}},[l]),r.jsx("object",{onLoad:i,ref:n,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 er({name:e,addLabel:t,value:n,disabled:o=!1,buildEntry:l,small:i,onInternalIdAdded:s,includeAddButton:a,newDefaultEntry:c=null,setFieldValue:f}){return r.jsx(un,{droppableId:e,addLabel:t,value:n,disabled:o,buildEntry:l,size:i?"small":"medium",onInternalIdAdded:s,includeAddButton:a,newDefaultEntry:c,onValueChange:g=>f(e,g)})}function Ps({field:e,form:t,label:n,tooltip:o,disabled:l,size:i="small",allowIndeterminate:s}){const a=r.jsx(A.BooleanSwitchWithLabel,{label:n,size:i,position:"start",value:e.value,disabled:l,allowIndeterminate:s,onValueChange:c=>t.setFieldValue(e.name,c)});return o?r.jsx(A.Tooltip,{title:o,children:a}):a}function ye({error:e,showError:t,property:n,includeDescription:o=!0,disabled:l}){const i=n.description||n.longDescription;if(!(t&&e)&&(!o||!i))return null;if(t&&e)return r.jsx(A.Typography,{variant:"caption",className:"ml-3.5 text-red-500",children:e});const s=typeof n.disabled=="object"?n.disabled.disabledMessage:void 0;return r.jsxs("div",{className:"flex ml-3.5 mt-1",children:[r.jsx(A.Typography,{variant:"caption",color:l?"disabled":"secondary",className:"flex-grow",children:s||n.description}),n.longDescription&&r.jsx(A.Tooltip,{title:n.longDescription,side:"bottom",children:r.jsx(A.IconButton,{size:"small",className:"self-start",children:r.jsx(A.InfoIcon,{color:"disabled",size:"small"})})})]})}function tn({propertyKey:e,value:t,setValue:n,error:o,showError:l,disabled:i,autoFocus:s,touched:a,property:c,includeDescription:f}){const g=c.enumValues;Se({property:c,value:t,setValue:n});const p=d.useCallback(h=>{h.stopPropagation(),h.preventDefault(),n(null)},[n]);return r.jsxs(r.Fragment,{children:[r.jsx(A.Select,{value:t?t.toString():"",disabled:i,position:"item-aligned",inputClassName:A.cn("w-full"),label:r.jsx(ve,{icon:pe(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(A.IconButton,{onClick:p,children:r.jsx(A.ClearIcon,{})}),onValueChange:h=>{const u=h?c.dataType==="number"?parseFloat(h):h:null;return n(u)},renderValue:h=>r.jsx(Ce,{enumKey:h,enumValues:g,size:"medium"}),children:g&&g.map(h=>r.jsx(A.SelectItem,{value:String(h.id),children:r.jsx(Ce,{enumKey:String(h.id),enumValues:g,size:"medium"})},h.id))}),r.jsx(ye,{includeDescription:f,showError:l,error:o,disabled:i,property:c})]})}function rn({propertyKey:e,value:t,setValue:n,error:o,showError:l,disabled:i,property:s,includeDescription:a,autoFocus:c}){const f=s.of;if(!f)throw Error("Using wrong component ArrayEnumSelect");if(Array.isArray(f))throw Error("Using array properties instead of single one in `of` in ArrayProperty");if(f.dataType!=="string"&&f.dataType!=="number")throw Error("Field misconfiguration: array field of type string or number");const g=_e(f.enumValues);if(!g)throw console.error(s),Error("Field misconfiguration: array field of type string or number needs to have enumValues");Se({property:s,value:t,setValue:n});const p=!!t&&Array.isArray(t),h=d.useCallback((u,m)=>{const b=u!==void 0?Lt(g,u):void 0;return r.jsxs(Ce,{enumKey:u,enumValues:g,size:"medium",children:[b?.label??u,!m&&r.jsx("button",{className:"ml-1 ring-offset-background rounded-full outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",onMouseDown:y=>{y.preventDefault(),y.stopPropagation()},onClick:y=>{y.preventDefault(),y.stopPropagation(),n(t.filter(C=>C!==u))},children:r.jsx(A.CloseIcon,{size:"smallest"})})]},u)},[g,n,t]);return r.jsxs("div",{className:"mt-0.5 ml-0.5 mt-2",children:[r.jsx(A.MultiSelect,{value:p?t.map(u=>u.toString()):[],disabled:i,label:r.jsx(ve,{icon:pe(s,"small"),required:s.validation?.required,title:s.name,className:"text-text-secondary dark:text-text-secondary-dark ml-3.5"}),renderValue:d.useCallback(u=>h(u,!1),[h]),onMultiValueChange:u=>{let m;return f&&f?.dataType==="number"?m=u?u.map(b=>parseFloat(b)):[]:m=u,n(m)},children:g.map(u=>String(u.id)).map(u=>r.jsx(A.MultiSelectItem,{value:u,children:h(u,!0)},u))}),r.jsx(ye,{includeDescription:a,showError:l,error:o,disabled:i,property:s})]})}function Lo({propertyKey:e,value:t,error:n,showError:o,disabled:l,isSubmitting:i,tableMode:s,property:a,includeDescription:c,setValue:f,setFieldValue:g}){const p=a.of;if(p.dataType!=="reference")throw Error("ArrayOfReferencesField expected a property containing references");const h=a.expanded===void 0?!0:a.expanded,[u,m]=d.useState(!1),b=t&&Array.isArray(t)?t.map(S=>S.id):[];Se({property:a,value:t,setValue:f});const y=ie(),C=d.useMemo(()=>p.path?y.getCollection(p.path):void 0,[p.path]);if(!C)throw Error(`Couldn't find the corresponding collection for the path: ${p.path}`);const w=d.useCallback(S=>{console.debug("onMultipleEntitiesSelected",S),f(S.map(F=>Ge(F)))},[f]),E=mt({multiselect:!0,path:p.path,collection:C,onMultipleEntitiesSelected:w,selectedEntityIds:b,forceFilter:p.forceFilter}),k=d.useCallback(S=>{S.preventDefault(),E.open()},[E]),x=d.useCallback((S,F)=>{const Q=t&&t.length>S?t[S]:void 0;return Q?r.jsx("div",{onMouseEnter:()=>m(!0),onMouseMove:()=>m(!0),onMouseLeave:()=>m(!1),children:r.jsx(De,{disabled:!p.path,previewProperties:p.previewProperties,size:"medium",onClick:k,reference:Q,onHover:u})}):r.jsx("div",{children:"Internal ERROR"})},[p.path,p.previewProperties,u,t]),I=r.jsx(ve,{icon:pe(a,"small"),required:a.validation?.required,title:a.name,className:"text-text-secondary dark:text-text-secondary-dark"}),B=r.jsxs(r.Fragment,{children:[!C&&r.jsx(me,{error:"The specified collection does not exist. Check console"}),C&&r.jsxs(r.Fragment,{children:[r.jsx(er,{value:t,addLabel:a.name?"Add reference to "+a.name:"Add reference",name:e,buildEntry:x,disabled:i,setFieldValue:g,newDefaultEntry:a.of.defaultValue}),r.jsxs(A.Button,{className:"my-4 justify-center text-left",variant:"outlined",color:"primary",disabled:i,onClick:k,children:["Edit ",a.name]})]})]});return r.jsxs(r.Fragment,{children:[!s&&r.jsx(A.ExpandablePanel,{className:"px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2",initiallyExpanded:h,title:I,children:B}),s&&B,r.jsx(ye,{includeDescription:c,showError:o,error:n,disabled:l,property:a})]})}function $o({name:e,property:t,value:n,entity:o,onRemove:l,disabled:i,size:s}){return r.jsxs("div",{className:A.cn(A.paperMixin,"relative m-4 border-box flex items-center justify-center",s==="medium"?"min-w-[220px] min-h-[220px] max-w-[220px]":"min-w-[118px] min-h-[118px] max-w-[118px]"),children:[!i&&r.jsx("div",{className:"absolute rounded-full -top-2 -right-2 z-10 bg-white dark:bg-gray-900",children:r.jsx(A.Tooltip,{title:"Remove",children:r.jsx(A.IconButton,{size:"small",onClick:a=>{a.stopPropagation(),l(n)},children:r.jsx(A.RemoveIcon,{size:"small"})})})}),n&&r.jsx(re,{children:r.jsx(be,{propertyKey:e,value:n,property:t,size:s})})]})}const Ts="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",Qs="border-dotted-gray",Ms="hover:bg-field-hover dark:hover:bg-field-hover-dark",Ds="pt-0 border-2 border-solid",Os="transition-colors duration-200 ease-[cubic-bezier(0,0,0.2,1)] border-2 border-solid border-green-500",Vs="transition-colors duration-200 ease-[cubic-bezier(0,0,0.2,1)] border-2 border-solid border-red-500";function nn({propertyKey:e,value:t,setValue:n,error:o,showError:l,autoFocus:i,tableMode:s,property:a,includeDescription:c,context:f,isSubmitting:g}){if(!f.entityId)throw new Error("StorageUploadFieldBinding: Entity id is null");const p=ct(),h=it(a)||!!a.disabled||g,{internalValue:u,setInternalValue:m,onFilesAdded:b,storage:y,onFileUploadComplete:C,storagePathBuilder:w,multipleFilesSupported:E}=Eo({entityValues:f.values,entityId:f.entityId,path:f.path,property:a,propertyKey:e,value:t,storageSource:p,disabled:h,onChange:n});Se({property:a,value:t,setValue:n});const k={id:f.entityId,values:f.values,path:f.path};return r.jsxs(r.Fragment,{children:[!s&&r.jsx(ve,{icon:pe(a,"small"),required:a.validation?.required,title:a.name,className:"text-text-secondary dark:text-text-secondary-dark ml-3.5"}),r.jsx(Ys,{value:u,name:e,disabled:h,autoFocus:i,property:a,onChange:n,setInternalValue:m,onFilesAdded:b,entity:k,onFileUploadComplete:C,storagePathBuilder:w,storage:y,multipleFilesSupported:E}),r.jsx(ye,{includeDescription:c,showError:l,error:o,disabled:h,property:a})]})}function Gs({storage:e,disabled:t,isDraggingOver:n,onFilesAdded:o,multipleFilesSupported:l,droppableProvided:i,autoFocus:s,internalValue:a,property:c,entity:f,onClear:g,metadata:p,storagePathBuilder:h,onFileUploadComplete:u,size:m,name:b,helpText:y}){const C=Je(),{getRootProps:w,getInputProps:E,isDragActive:k,isDragAccept:x,isDragReject:I}=wn.useDropzone({accept:e.acceptedFiles?e.acceptedFiles.map(B=>({[B]:[]})).reduce((B,S)=>({...B,...S}),{}):void 0,disabled:t||n,noDragEventsBubbling:!0,maxSize:e.maxSize,onDrop:o,onDropRejected:(B,S)=>{for(const F of B)for(const Q of F.errors)C.open({type:"error",message:`Error uploading file: File is larger than ${e.maxSize} bytes`})}});return r.jsxs("div",{...w(),className:A.cn(A.fieldBackgroundMixin,t?A.fieldBackgroundDisabledMixin:A.fieldBackgroundHoverMixin,Ts,l&&a.length?"":"flex",A.focusedMixin,{[Ms]:!k,[Ds]:k,[Vs]:I,[Os]:x,[Qs]:t}),children:[r.jsxs("div",{...i.droppableProps,ref:i.innerRef,className:A.cn("flex items-center p-1 no-scrollbar",l&&a.length?"overflow-auto":"",l&&a.length?"min-h-[180px]":"min-h-[250px]"),children:[r.jsx("input",{autoFocus:s,...E()}),a.map((B,S)=>{let F;return B.storagePathOrDownloadUrl?F=r.jsx($o,{name:`storage_preview_${B.storagePathOrDownloadUrl}`,property:c,disabled:t,entity:f,value:B.storagePathOrDownloadUrl,onRemove:g,size:B.size}):B.file&&(F=r.jsx(Io,{entry:B,metadata:p,storagePath:h(B.file),onFileUploadComplete:u,imageSize:m==="medium"?220:118,simple:!1})),r.jsx(lt.Draggable,{draggableId:`array_field_${b}_${B.id}`,index:S,children:(Q,N)=>r.jsx("div",{tabIndex:-1,ref:Q.innerRef,...Q.draggableProps,...Q.dragHandleProps,className:A.cn(A.focusedMixin,"rounded-md"),style:{...Q.draggableProps.style},children:F})},`array_field_${b}_${B.id}`)}),i.placeholder]}),r.jsx("div",{className:"flex-grow min-h-[38px] box-border m-2 text-center",children:r.jsx(A.Typography,{align:"center",variant:"label",children:y})})]})}function Ys({property:e,name:t,value:n,setInternalValue:o,onChange:l,multipleFilesSupported:i,onFileUploadComplete:s,disabled:a,onFilesAdded:c,autoFocus:f,storage:g,entity:p,storagePathBuilder:h}){if(i){const k=e;if(k.of){if(Array.isArray(k.of)||k.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 u=g?.metadata,m=i?"small":"medium",b=d.useCallback((k,x)=>{if(!i)return;const I=[...n],B=I[k];I.splice(k,1),I.splice(x,0,B),o(I);const S=I.filter(F=>!!F.storagePathOrDownloadUrl).map(F=>F.storagePathOrDownloadUrl);l(S)},[i,l,o,n]),y=d.useCallback(k=>{k.destination&&b(k.source.index,k.destination.index)},[b]),C=d.useCallback(k=>{if(i){const x=n.filter(I=>I.storagePathOrDownloadUrl!==k);l(x.filter(I=>!!I.storagePathOrDownloadUrl).map(I=>I.storagePathOrDownloadUrl)),o(x)}else l(null),o([])},[n,i,l]),w=i?"Drag 'n' drop some files here, or click to select files":"Drag 'n' drop a file here, or click to select one",E=i?e.of:e;return r.jsx(lt.DragDropContext,{onDragEnd:y,children:r.jsx(lt.Droppable,{droppableId:`droppable_${t}`,direction:"horizontal",renderClone:(k,x,I)=>{const B=n[I.source.index];return r.jsx("div",{ref:k.innerRef,...k.draggableProps,...k.dragHandleProps,style:k.draggableProps.style,className:"rounded",children:r.jsx($o,{name:`storage_preview_${B.storagePathOrDownloadUrl}`,property:E,disabled:!0,entity:p,value:B.storagePathOrDownloadUrl,onRemove:C,size:B.size})})},children:(k,x)=>r.jsx(Gs,{storage:g,disabled:a,isDraggingOver:x.isDraggingOver,droppableProvided:k,onFilesAdded:c,multipleFilesSupported:i,autoFocus:f,internalValue:n,property:E,entity:p,onClear:C,metadata:u,storagePathBuilder:h,onFileUploadComplete:s,size:m,name:t,helpText:w})})})}function ht({propertyKey:e,value:t,setValue:n,error:o,showError:l,disabled:i,autoFocus:s,property:a,includeDescription:c}){let f,g;a.dataType==="string"&&(f=a.multiline,g=a.url),Se({property:a,value:t,setValue:n});const p=d.useCallback(b=>{b.stopPropagation(),b.preventDefault(),n(null)},[n]),h=b=>{if(m==="number"){const y=b.target.value?parseFloat(b.target.value):void 0;y&&isNaN(y)?n(null):y!=null?n(y):n(null)}else n(b.target.value)},u=!!f,m=a.dataType==="number"?"number":void 0;return r.jsxs(r.Fragment,{children:[r.jsx(A.TextField,{value:t,onChange:h,autoFocus:s,label:r.jsx(ve,{icon:pe(a,"small"),required:a.validation?.required,title:a.name}),type:m,multiline:u,disabled:i,endAdornment:a.clearable&&r.jsx(A.IconButton,{onClick:p,children:r.jsx(A.ClearIcon,{})}),error:l?o:void 0,inputClassName:o?"text-red-500 dark:text-red-600":""}),r.jsx(ye,{includeDescription:c,showError:l,error:o,disabled:i,property:a}),g&&r.jsx(A.Collapse,{className:"mt-1 ml-1",in:!!t,children:r.jsx(be,{value:t,property:a,size:"medium"})})]})}const _o=d.forwardRef(function({propertyKey:t,value:n,setValue:o,error:l,showError:i,autoFocus:s,disabled:a,touched:c,property:f,includeDescription:g},p){return Se({property:f,value:n,setValue:o}),r.jsxs(r.Fragment,{children:[r.jsx(A.BooleanSwitchWithLabel,{value:n,onValueChange:h=>o(h),error:i,label:r.jsx(ve,{icon:pe(f,"small"),required:f.validation?.required,title:f.name}),disabled:a,autoFocus:s,size:"medium"}),r.jsx(ye,{includeDescription:g,showError:i,error:l,disabled:a,property:f})]})});function Wo({propertyKey:e,value:t,setValue:n,autoFocus:o,error:l,showError:i,disabled:s,touched:a,property:c,includeDescription:f}){const{locale:g}=q(),p=t||null;return Se({property:c,value:t,setValue:n}),r.jsxs(r.Fragment,{children:[r.jsx(A.DateTimeField,{value:p,onChange:h=>n(h),size:"medium",mode:c.mode,clearable:c.clearable,locale:g,label:r.jsx(ve,{icon:pe(c,"small"),required:c.validation?.required,className:"text-text-secondary dark:text-text-secondary-dark",title:c.name})}),r.jsx(ye,{includeDescription:f,showError:i,error:l,disabled:s,property:c})]})}function on({propertyKey:e,value:t,error:n,showError:o,tableMode:l,property:i,includeDescription:s,context:a}){if(!a.entityId)throw new Error("ReadOnlyFieldBinding: Entity id is null");return a.entityId,a.values,a.path,r.jsxs(r.Fragment,{children:[!l&&r.jsx(ve,{icon:pe(i,"small"),required:i.validation?.required,title:i.name,className:"text-text-secondary dark:text-text-secondary-dark ml-3.5"}),r.jsx("div",{className:A.cn(A.paperMixin,"min-h-14 p-4 md:p-6 overflow-x-scroll no-scrollbar"),children:r.jsx(re,{children:r.jsx(be,{propertyKey:e,value:t,property:i,size:"medium"})})}),r.jsx(ye,{includeDescription:s,showError:o,error:n,property:i})]})}function jo(e){return typeof e.property.path!="string"?r.jsx(on,{...e}):r.jsx(zs,{...e})}function zs({value:e,setValue:t,error:n,showError:o,isSubmitting:l,disabled:i,touched:s,autoFocus:a,property:c,includeDescription:f,context:g}){if(!c.path)throw new Error("Property path is required for ReferenceFieldBinding");Se({property:c,value:e,setValue:t});const p=e&&e instanceof Fe,h=ie(),u=d.useMemo(()=>c.path?h.getCollection(c.path):void 0,[c.path]);if(!u)throw Error(`Couldn't find the corresponding collection for the path: ${c.path}`);const m=d.useCallback(C=>{t(C?Ge(C):null)},[t]),b=mt({multiselect:!1,path:c.path,collection:u,onSingleEntitySelected:m,selectedEntityIds:p?[e.id]:void 0,forceFilter:c.forceFilter}),y=d.useCallback(C=>{C.preventDefault(),b.open()},[b]);return r.jsxs(r.Fragment,{children:[r.jsx(ve,{icon:pe(c,"small"),required:c.validation?.required,title:c.name,className:"text-text-secondary dark:text-text-secondary-dark ml-3.5"}),!u&&r.jsx(me,{error:"The specified collection does not exist. Check console"}),u&&r.jsxs(r.Fragment,{children:[e&&r.jsx(De,{disabled:!c.path,previewProperties:c.previewProperties,size:"medium",onClick:i||l?void 0:y,reference:e}),!e&&r.jsx("div",{className:"justify-center text-left",children:r.jsxs(A.Button,{variant:"outlined",color:"primary",disabled:i||l,onClick:y,children:["Edit ",c.name]})})]}),r.jsx(ye,{includeDescription:f,showError:o,error:n,disabled:i,property:c})]})}const nt=d.memo(Us,(e,t)=>{if(e.propertyKey!==t.propertyKey)return!1;const n=we(e.property)||e.property.fromBuilder,o=we(t.property)||t.property.fromBuilder;return!((n===o||ne(e.property,t.property))&&e.disabled===t.disabled)||tr(t.property),!1});function Us({propertyKey:e,property:t,context:n,includeDescription:o,underlyingValueHasChanged:l,disabled:i,tableMode:s,partOfArray:a,partOfBlock:c,autoFocus:f}){const g=q(),h=tr(t,g.plugins)?Be.Field:Be.FastField;return r.jsx(h,{name:e,children:u=>{let m;const b=xe({propertyKey:e,propertyValue:u.field.value,propertyOrBuilder:t,values:u.form.values,path:n.path,entityId:n.entityId,fields:g.propertyConfigs});if(b===null||wt(b))return r.jsx(r.Fragment,{});if(it(b))m=on;else if(b.Field)typeof b.Field=="function"&&(m=b.Field);else{const C=sr(b,g.propertyConfigs);if(!C)throw console.log("INTERNAL: Could not find field config for property",{propertyKey:e,resolvedProperty:b,fields:g.propertyConfigs,propertyConfig:C}),new Error(`INTERNAL: Could not find field config for property ${e}`);m=xe({propertyOrBuilder:C.property,propertyValue:u.field.value,values:u.form.values,path:n.path,entityId:n.entityId,fields:g.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 ${b.dataType} is not supported`});const y={propertyKey:e,property:b,includeDescription:o,underlyingValueHasChanged:l,context:n,disabled:i,tableMode:s,partOfArray:a,partOfBlock:c,autoFocus:f};return r.jsx(Ls,{Component:m,componentProps:y,fieldProps:u})}})}function Ls({Component:e,componentProps:{propertyKey:t,property:n,includeDescription:o,underlyingValueHasChanged:l,tableMode:i,partOfArray:s,partOfBlock:a,autoFocus:c,context:f,disabled:g},fieldProps:p}){const{plugins:h}=q(),u=n.customProps,m=p.field.value,b=p.meta.initialValue,y=Be.getIn(p.form.errors,t),C=Be.getIn(p.form.touched,t),w=y&&(p.form.submitCount>0||n.validation?.unique)&&(!Array.isArray(y)||!!y.filter(S=>!!S).length);$s(f.path,f.collection,t,n,e,h);const E=e,k=p.form.isSubmitting,x=d.useCallback((S,F)=>{p.form.setFieldTouched(t,!0,!1),p.form.setFieldValue(t,S,F)},[]),I=d.useCallback((S,F,Q)=>{p.form.setFieldTouched(t,!0,!1),p.form.setFieldValue(S,F,Q)},[]),B={propertyKey:t,value:m,initialValue:b,setValue:x,setFieldValue:I,error:y,touched:C,showError:w,isSubmitting:k,includeDescription:o??!0,property:n,disabled:g??!1,underlyingValueHasChanged:l??!1,tableMode:i??!1,partOfArray:s??!1,partOfBlock:a??!1,autoFocus:c??!1,customProps:u,context:f};return r.jsxs(re,{children:[r.jsx(E,{...B}),l&&!k&&r.jsx(A.Typography,{variant:"caption",className:"ml-3.5",children:"This value has been updated elsewhere"})]})}const tr=(e,t)=>{if(t?.some(l=>l.form?.fieldBuilder)||we(e))return!0;const n=e,o=!!n.Field||"fromBuilder"in n&&n.fromBuilder;return n.dataType==="map"&&n.properties?o||Object.values(n.properties).some(l=>tr(l,t)):n.dataType==="array"&&"resolvedProperties"in n?o||n.resolvedProperties?.some(l=>l&&tr(l,t)):o};function $s(e,t,n,o,l,i){return d.useRef((()=>{let a=null;return i&&i.forEach(c=>{const f=mn(o);if(f&&c.form?.fieldBuilder){const g={fieldConfigId:f,propertyKey:n,property:o,Field:l,plugin:c,path:e,collection:t},p=c.form?.fieldBuilderEnabled?.(g);(p===void 0||p)&&(a=c.form.fieldBuilder(g)||a)}f||console.warn("INTERNAL: Field id not found for property",o)}),a})()).current}function Ho({propertyKey:e,value:t,showError:n,error:o,disabled:l,property:i,setValue:s,partOfBlock:a,tableMode:c,includeDescription:f,underlyingValueHasChanged:g,autoFocus:p,context:h}){const u=i.pickOnlySomeKeys||!1,m=(i.expanded===void 0?!0:i.expanded)||p;if(!i.properties)throw Error(`You need to specify a 'properties' prop (or specify a custom field) in your map property ${e}`);let b;u?t?b=xn(i.properties,...Object.keys(t).filter(w=>w in i.properties)):b={}:b=i.properties;const y=r.jsx(r.Fragment,{children:r.jsx("div",{className:"py-1 flex flex-col space-y-2",children:Object.entries(b).filter(([w,E])=>!wt(E)).map(([w,E],k)=>{const x={propertyKey:`${e}.${w}`,disabled:l,property:E,includeDescription:f,underlyingValueHasChanged:g,context:h,tableMode:!1,partOfArray:!1,partOfBlock:!1,autoFocus:p&&k===0};return r.jsx("div",{children:r.jsx(nt,{...x})},`map-${e}-${k}`)})})}),C=r.jsx(ve,{icon:pe(i,"small"),required:i.validation?.required,title:i.name,className:"text-text-secondary dark:text-text-secondary-dark"});return r.jsxs(r.Fragment,{children:[!c&&!a&&r.jsx(A.ExpandablePanel,{initiallyExpanded:m,className:"px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2",title:C,children:y}),(c||a)&&y,r.jsx(ye,{includeDescription:f,showError:n,error:o,disabled:l,property:i})]})}function Jo({propertyKey:e,value:t,showError:n,error:o,disabled:l,property:i,setValue:s,tableMode:a,includeDescription:c,underlyingValueHasChanged:f,autoFocus:g,context:p}){const h=(i.expanded===void 0?!0:i.expanded)||g;if(!i.keyValue)throw Error(`Your property ${e} needs to have the 'keyValue' prop in order to use this field binding`);const u=r.jsx(ln,{value:t,setValue:s,disabled:l,fieldName:i.name??e}),m=r.jsx(ve,{icon:pe(i,"small"),required:i.validation?.required,title:i.name,className:"text-text-secondary dark:text-text-secondary-dark"});return r.jsxs(r.Fragment,{children:[!a&&r.jsx(A.ExpandablePanel,{initiallyExpanded:h,title:m,className:"px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2",children:u}),a&&u,r.jsx(ye,{includeDescription:c,showError:n,error:o,disabled:l,property:i})]})}function ln({value:e,setValue:t,fieldName:n,disabled:o}){const[l,i]=d.useState(Object.keys(e??{}).map(c=>[sn(),{key:c,dataType:an(e?.[c])??"string"}]));d.useEffect(()=>{const c=l.map(([u,{key:m}])=>m),f=Object.entries(e??{}).filter(([u,m])=>m!==void 0).map(([u])=>u),g=f.filter(u=>!c.includes(u)),p=c.filter(u=>!f.includes(u)),h=[...l];g.forEach(u=>{h.push([sn(),{key:u,dataType:an(e?.[u])??"string"}])}),p.forEach(u=>{const m=h.findIndex(([b,{key:y}])=>y===u);h.splice(m,1)}),i(h)},[e]);const s=d.useRef(e??{}),a=(c,f)=>{if(!c){console.warn("No key selected for data type update");return}i(l.map(g=>g[0]===c?[g[0],{key:g[1].key,dataType:f}]:g)),t({...e??{},[l.find(g=>g[0]===c)?.[1].key??""]:mr(f)})};return r.jsxs("div",{className:"py-1 flex flex-col gap-1",children:[l.map(([c,{key:f,dataType:g}],p)=>{const h=f?e?.[f]:"",u=m=>{if(i(l.map(y=>y[0]===c?[c,{key:m??"",dataType:y[1].dataType}]:y)),typeof e=="object"&&m in e)return;const b={...e??{}};typeof s.current=="object"&&f in s.current?b[f]=void 0:delete b[f],t({...b,[m??""]:h})};return r.jsx(_s,{rowId:c,fieldKey:f,value:e??{},onDeleteClick:()=>{const m={...e??{}};s.current&&f in s.current?m[f]=void 0:delete m[f],i(l.filter(b=>b[0]!==c)),t({...m})},onFieldKeyChange:u,setValue:t,entryValue:h,dataType:g,disabled:o,updateDataType:a},c)}),r.jsx(A.Button,{variant:"text",size:"small",color:"primary",className:"w-full",disabled:o,startIcon:r.jsx(A.AddIcon,{}),onClick:c=>{c.preventDefault(),t({...e??{},"":null}),i([...l,[sn(),{key:"",dataType:"string"}]])},children:n?`Add to ${n}`:"Add"})]})}function _s({rowId:e,fieldKey:t,value:n,onFieldKeyChange:o,onDeleteClick:l,setValue:i,entryValue:s,dataType:a,updateDataType:c,disabled:f}){const{locale:g}=q();function p(u,m,b){return b==="string"||b==="number"?r.jsx(A.TextField,{placeholder:"value",value:u,type:b==="number"?"number":"text",size:"small",disabled:f||!m,onChange:y=>{if(b==="number"){const C=y.target.value?parseFloat(y.target.value):void 0;C&&isNaN(C)?i({...n,[m]:null}):C!=null?i({...n,[m]:C}):i({...n,[m]:null})}else i({...n,[m]:y.target.value})}},b):b==="date"?r.jsx(A.DateTimeField,{value:u,size:"small",locale:g,disabled:f||!m,onChange:y=>{i({...n,[m]:y})}}):b==="boolean"?r.jsx(A.BooleanSwitchWithLabel,{value:u,size:"small",position:"start",disabled:f||!m,onValueChange:y=>{i({...n,[m]:y})}}):b==="array"?r.jsx("div",{className:A.cn(A.defaultBorderMixin,"ml-2 pl-2 border-l border-solid"),children:r.jsx(un,{value:u,newDefaultEntry:"",droppableId:e.toString(),addLabel:m?`Add to ${m}`:"Add",size:"small",disabled:f||!m,includeAddButton:!0,onValueChange:y=>{i({...n,[m]:y})},buildEntry:(y,C)=>r.jsx(Ws,{index:y,id:C,value:u[y],disabled:f||!m,setValue:w=>{const E=[...u];E[y]=w,i({...n,[m]:E})}})})}):b==="map"?r.jsx("div",{className:A.cn(A.defaultBorderMixin,"ml-2 pl-2 border-l border-solid"),children:r.jsx(ln,{value:u,fieldName:m,setValue:y=>{i({...n,[m]:y})}})}):r.jsx(A.Typography,{variant:"caption",children:`Data type ${b} not supported yet`})}function h(u){c(e,u)}return r.jsxs(r.Fragment,{children:[r.jsxs(A.Typography,{component:"div",className:"font-mono flex flex-row gap-1",children:[r.jsx("div",{className:"w-[200px] max-w-[25%]",children:r.jsx(A.TextField,{value:t,placeholder:"key",disabled:f||s!=null&&s!=="",size:"small",onChange:u=>{o(u.target.value)}})}),r.jsx("div",{className:"flex-grow",children:a!=="map"&&a!=="array"&&p(s,t,a)}),r.jsxs(A.Menu,{trigger:r.jsx(A.IconButton,{size:"small",className:"h-7 w-7",children:r.jsx(A.ArrowDropDownIcon,{})}),children:[r.jsx(A.MenuItem,{dense:!0,onClick:()=>h("string"),children:"string"}),r.jsx(A.MenuItem,{dense:!0,onClick:()=>h("number"),children:"number"}),r.jsx(A.MenuItem,{dense:!0,onClick:()=>h("boolean"),children:"boolean"}),r.jsx(A.MenuItem,{dense:!0,onClick:()=>h("date"),children:"date"}),r.jsx(A.MenuItem,{dense:!0,onClick:()=>h("map"),children:"map"}),r.jsx(A.MenuItem,{dense:!0,onClick:()=>h("array"),children:"array"})]}),r.jsx(A.IconButton,{"aria-label":"delete",size:"small",onClick:l,className:"h-7 w-7",children:r.jsx(A.RemoveIcon,{size:"small"})})]},e.toString()),(a==="map"||a==="array")&&p(s,t,a)]})}function Ws({id:e,index:t,value:n,setValue:o}){const{locale:l}=q(),[i,s]=d.useState(an(n)??"string");function a(f){s(f)}function c(f,g){return g==="string"||g==="number"?r.jsx(A.TextField,{value:f,type:g==="number"?"number":"text",size:"small",onChange:p=>{if(g==="number"){const h=p.target.value?parseFloat(p.target.value):void 0;h&&isNaN(h)?o(null):h!=null?o(h):o(null)}else o(p.target.value)}}):g==="date"?r.jsx(A.DateTimeField,{value:f,size:"small",locale:l,onChange:p=>{o(p)}}):g==="boolean"?r.jsx(A.BooleanSwitchWithLabel,{value:f,size:"small",position:"start",onValueChange:p=>{o(p)}}):g==="array"?r.jsx(A.Typography,{variant:"caption",children:"Arrays of arrays are not supported."}):g==="map"?r.jsx("div",{className:A.cn(A.defaultBorderMixin,"ml-2 pl-2 border-l border-solid"),children:r.jsx(ln,{value:f,setValue:p=>{o(p)}})}):r.jsx(A.Typography,{variant:"caption",children:`Data type ${g} not supported yet`})}return r.jsxs(r.Fragment,{children:[r.jsxs(A.Typography,{component:"div",className:"font-mono flex min-h-12 flex-row gap-1 items-center",children:[r.jsx("div",{className:"flex-grow",children:i!=="map"&&c(n,i)}),r.jsxs(A.Menu,{trigger:r.jsx(A.IconButton,{size:"small",className:"h-7 w-7",children:r.jsx(A.ArrowDropDownIcon,{})}),children:[r.jsx(A.MenuItem,{dense:!0,onClick:()=>a("string"),children:"string"}),r.jsx(A.MenuItem,{dense:!0,onClick:()=>a("number"),children:"number"}),r.jsx(A.MenuItem,{dense:!0,onClick:()=>a("boolean"),children:"boolean"}),r.jsx(A.MenuItem,{dense:!0,onClick:()=>a("map"),children:"map"}),r.jsx(A.MenuItem,{dense:!0,onClick:()=>a("date"),children:"date"})]})]},e.toString()),i==="map"&&c(n,i)]})}function sn(){return Math.floor(Math.random()*Math.floor(Number.MAX_SAFE_INTEGER))}function an(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 instanceof Fe)return"reference";if(e instanceof Vt)return"geopoint";if(typeof e=="object")return"map"}function qo({propertyKey:e,value:t,error:n,showError:o,isSubmitting:l,setValue:i,setFieldValue:s,tableMode:a,property:c,includeDescription:f,underlyingValueHasChanged:g,context:p,disabled:h}){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 u=c.expanded===void 0?!0:c.expanded,m=c.of,[b,y]=d.useState();Se({property:c,value:t,setValue:i});const C=(k,x)=>{const I=c.resolvedProperties[k]??m,B={propertyKey:`${e}.${k}`,disabled:h,property:I,includeDescription:f,underlyingValueHasChanged:g,context:p,tableMode:!1,partOfArray:!0,partOfBlock:!1,autoFocus:x===b};return r.jsx(nt,{...B})},w=r.jsx(er,{value:t,addLabel:c.name?"Add entry to "+c.name:"Add entry",name:e,setFieldValue:s,buildEntry:C,onInternalIdAdded:y,disabled:l||!!c.disabled,includeAddButton:!c.disabled,newDefaultEntry:c.of.defaultValue}),E=r.jsx(ve,{icon:pe(c,"small"),required:c.validation?.required,title:c.name,className:"text-text-secondary dark:text-text-secondary-dark"});return r.jsxs(r.Fragment,{children:[!a&&r.jsx(A.ExpandablePanel,{initiallyExpanded:u,className:"px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2",title:E,children:w}),a&&w,r.jsx(ye,{includeDescription:f,showError:o,error:n,disabled:h,property:c})]})}function Zo({propertyKey:e,value:t,error:n,showError:o,isSubmitting:l,setValue:i,setFieldValue:s,tableMode:a,property:c,includeDescription:f,underlyingValueHasChanged:g,context:p,disabled:h}){if(!c.oneOf)throw Error("ArrayOneOfField misconfiguration. Property `oneOf` not set");const u=c.expanded===void 0?!0:c.expanded;Se({property:c,value:t,setValue:i});const[m,b]=d.useState(),y=d.useCallback((k,x)=>r.jsx(js,{name:`${e}.${k}`,index:k,value:t[k],typeField:c.oneOf.typeField??vt,valueField:c.oneOf.valueField??Yt,properties:c.oneOf.properties,autoFocus:x===m,context:p},`array_one_of_${k}`),[p,m,c.oneOf,e,t]),C=r.jsx(ve,{icon:pe(c,"small"),required:c.validation?.required,title:c.name,className:"text-text-secondary dark:text-text-secondary-dark"}),w=Object.keys(c.oneOf.properties)[0],E=r.jsx(er,{value:t,name:e,addLabel:c.name?"Add entry to "+c.name:"Add entry",buildEntry:y,onInternalIdAdded:b,disabled:l||!!c.disabled,includeAddButton:!c.disabled,setFieldValue:s,newDefaultEntry:{[c.oneOf.typeField??vt]:w,[c.oneOf.valueField??Yt]:zt(c.oneOf.properties[w])}});return r.jsxs(r.Fragment,{children:[!a&&r.jsx(A.ExpandablePanel,{className:"px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2",initiallyExpanded:u,title:C,children:E}),a&&E,r.jsx(ye,{includeDescription:f,showError:o,error:n,disabled:h,property:c})]})}function js({name:e,index:t,value:n,typeField:o,valueField:l,properties:i,autoFocus:s,context:a}){const c=n&&n[o],[f,g]=d.useState(c??void 0),p=Be.useFormikContext();d.useEffect(()=>{c||C(Object.keys(i)[0])},[]),d.useEffect(()=>{c!==f&&g(c)},[c]);const h=f?i[f]:void 0,u=Object.entries(i).map(([w,E])=>({id:w,label:E.name??w})),m=`${e}.${o}`,b=`${e}.${l}`,y=h?{propertyKey:b,property:h,context:a,autoFocus:s,partOfArray:!1,partOfBlock:!0,tableMode:!1}:void 0,C=w=>{const E=w?i[w]:void 0;g(w),p.setFieldTouched(m),p.setFieldValue(m,w),p.setFieldValue(b,E?zt(E):null)};return r.jsxs("div",{className:A.cn(A.paperMixin,"bg-transparent p-4 my-4 py-8"),children:[r.jsx(Be.FastField,{required:!0,name:m,children:w=>r.jsx(r.Fragment,{children:r.jsx(A.Select,{className:"mb-2",placeholder:r.jsx(A.Typography,{variant:"caption",className:"px-4 py-2 font-medium",children:"Type"}),size:"small",position:"item-aligned",value:w.field.value!==void 0&&w.field.value!==null?w.field.value:"",renderValue:E=>r.jsx(Ce,{enumKey:E,enumValues:u,size:"small"}),onValueChange:E=>{C(E)},children:u.map(E=>r.jsx(A.SelectItem,{value:String(E.id),children:r.jsx(Ce,{enumKey:E.id,enumValues:u,size:"small"})},E.id))})})}),y&&r.jsx(nt,{...y},`form_control_${e}_${f}`)]})}const Hs=new Bl;try{et.use(et.Plugins.AutoResize,{min:100}),et.unuse(et.Plugins.FontUnderline),et.unuse(et.Plugins.Clear)}catch{}function Xo({propertyKey:e,value:t,setValue:n,error:o,showError:l,disabled:i,autoFocus:s,touched:a,property:c,tableMode:f,includeDescription:g,context:p}){const[h,u]=d.useState(t),m=d.useRef(t);A.useInjectStyles("MarkdownFieldBinding",Js);const b=d.useDeferredValue({internalValue:h,value:t});return d.useEffect(()=>{m.current=t,u(t)},[t]),d.useEffect(()=>{b.internalValue!==m.current&&n(b.internalValue)},[b]),r.jsxs(r.Fragment,{children:[!f&&r.jsx(A.Typography,{variant:"caption",className:"flex-grow",children:r.jsx(ve,{icon:pe(c,"small"),required:c.validation?.required,title:c.name,className:"text-text-secondary dark:text-text-secondary-dark ml-3.5"})}),r.jsx(et,{value:h??"",className:A.cn(A.fieldBackgroundMixin,i?A.fieldBackgroundDisabledMixin:A.fieldBackgroundHoverMixin,"text-base"),readOnly:i,renderHTML:y=>Hs.render(y),view:{menu:!0,md:!0,html:!1},onChange:({html:y,text:C})=>{u(C??null)}}),r.jsx(ye,{includeDescription:g,showError:l,error:o,disabled:i,property:c})]})}const Js=`
5
5
  @font-face {
6
6
  font-family: rmel-iconfont;
7
7
  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=);
@@ -584,6 +584,6 @@
584
584
  .rc-md-editor .header-list .list-item:hover {
585
585
  }
586
586
 
587
- `;function Ko({propertyKey:e,value:t,error:n,showError:o,isSubmitting:l,setValue:i,tableMode:s,property:a,includeDescription:d,underlyingValueHasChanged:A,context:g,disabled:p}){if(Z(),!Array.isArray(a.resolvedProperties))throw Error("ArrayCustomShapedFieldBinding misconfiguration. Property `of` not set");const h=a.expanded===void 0?!0:a.expanded;xe({property:a,value:t,setValue:i});const u=r.jsx(ye,{icon:he(a,"small"),required:a.validation?.required,className:"text-text-secondary dark:text-text-secondary-dark",title:a.name}),m=a.resolvedProperties.map((b,y)=>{const w={propertyKey:`${e}[${y}]`,disabled:p,property:b,includeDescription:d,underlyingValueHasChanged:A,context:g,tableMode:!1,partOfArray:!0,partOfBlock:!1,autoFocus:!1};return r.jsx("div",{className:"pb-4",children:r.jsx(nt,{...w})},`custom_shaped_array_${y}`)});return r.jsxs(r.Fragment,{children:[!s&&r.jsx(f.ExpandablePanel,{initiallyExpanded:h,title:u,className:"px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2",children:m}),s&&m,r.jsx(be,{includeDescription:d,showError:o,error:n,disabled:p,property:a})]})}const qs=({containerRef:e})=>{const{isSubmitting:t,isValidating:n,errors:o}=Ce.useFormikContext();return c.useEffect(()=>{const l=Object.keys(o);if(l.length>0&&t&&!n){const i=e?.current?.querySelector(`#form_field_${l[0]}`);if(i&&e?.current){const s=Ro(e.current);if(s){const d=i.getBoundingClientRect().top;s.scrollTo({top:s.scrollTop+d-64,behavior:"smooth"})}const a=i.querySelector("input");a&&a.focus()}}},[t,n,o,e]),null},Zs=e=>{const t=e&&e.scrollHeight>e.clientHeight,n=e?window.getComputedStyle(e).overflowY:null,o=n&&n.indexOf("hidden")!==-1;return t&&!o},Ro=e=>!e||e===document.body?document.body:Zs(e)?e:Ro(e.parentNode);function Xs({customId:e,entityId:t,status:n,onChange:o,error:l,entity:i}){const s=n==="existing"||!e,a=n!=="existing"&&!e,d=c.useMemo(()=>{if(!(!e||typeof e=="boolean"||e==="optional"))return _e(e)},[e]),A=Je(),{copy:g}=lo({onSuccess:u=>A.open({type:"success",message:`Copied ${u}`})}),p=Z(),h={label:a?"ID is set automatically":"ID",disabled:s,name:"id",value:(i&&n==="existing"?i.id:t)??"",endAdornment:i?r.jsxs(r.Fragment,{children:[r.jsx(f.Tooltip,{title:"Copy",children:r.jsx(f.IconButton,{onClick:u=>g(i.id),"aria-label":"copy-id",children:r.jsx(f.ContentCopyIcon,{size:"small"})})}),p?.entityLinkBuilder&&r.jsx(f.Tooltip,{title:"Open in the console",children:r.jsx(f.IconButton,{component:"a",href:p.entityLinkBuilder({entity:i}),rel:"noopener noreferrer",target:"_blank",onClick:u=>u.stopPropagation(),"aria-label":"go-to-datasource",children:r.jsx(f.OpenInNewIcon,{size:"small"})})})]}):void 0};return r.jsxs(r.Fragment,{children:[d&&r.jsx(f.Select,{error:l,onValueChange:u=>o(u),...h,renderValue:u=>{const m=d.find(b=>b.id===u);return m?`${m.id} - ${m.label}`:u},children:d.map(u=>r.jsx(f.SelectItem,{value:String(u.id),children:r.jsx(we,{enumKey:u.id,enumValues:d,size:"medium"})},u.id))}),!d&&r.jsx(f.TextField,{...h,error:l,placeholder:e==="optional"?"Autogenerated ID, it can be manually changed":n==="new"||n==="copy"?"ID of the new document":"ID of the document",onChange:u=>{let m=u.target.value;return m&&(m=m.trim()),o(m.length?m:void 0)}}),r.jsx(Ce.ErrorMessage,{name:"id",component:"div",children:u=>"You need to specify an ID"})]})}const Ks={icon:r.jsx(f.KeyboardTabIcon,{}),name:"Edit",collapsed:!1,onClick({entity:e,collection:t,context:n,highlightEntity:o,unhighlightEntity:l}){return o?.(e),n.onAnalyticsEvent?.("entity_click",{path:e.path,entityId:e.id}),n.sideEntityController.open({entityId:e.id,path:e.path,collection:t,updateUrl:!0,onClose:()=>l?.(e)}),Promise.resolve(void 0)}},el={icon:r.jsx(f.FileCopyIcon,{}),name:"Copy",onClick({entity:e,collection:t,context:n,highlightEntity:o,unhighlightEntity:l}){return o?.(e),n.onAnalyticsEvent?.("copy_entity_click",{path:e.path,entityId:e.id}),n.sideEntityController.open({entityId:e.id,path:e.path,copy:!0,collection:t,updateUrl:!0,onClose:()=>l?.(e)}),Promise.resolve(void 0)}},tl={icon:r.jsx(f.DeleteIcon,{}),name:"Delete",onClick({entity:e,fullPath:t,collection:n,context:o,selectionController:l,onCollectionChange:i,sideEntityController:s}){const{closeDialog:a}=o.dialogsController.open({key:"delete_entity_dialog_"+e.id,Component:({open:d})=>{if(!n||!t)throw new Error("deleteEntityAction: Collection is undefined");return r.jsx(Uo,{entityOrEntitiesToDelete:e,path:t,collection:n,callbacks:n.callbacks,open:d,onEntityDelete:()=>{o.onAnalyticsEvent?.("single_entity_deleted",{path:t}),l?.setSelectedEntities(l.selectedEntities.filter(A=>A.id!==e.id)),i?.(),s?.close()},onClose:a})}});return Promise.resolve(void 0)}},rl=c.memo(Rs,(e,t)=>e.status===t.status&&e.path===t.path&&oe(e.entity?.values,t.entity?.values));function Rs({status:e,path:t,collection:n,entity:o,onEntitySaveRequested:l,onDiscard:i,onModified:s,onValuesChanged:a,onIdChange:d,onFormContextChange:A,hideId:g,autoSave:p,onIdUpdateError:h}){const u=Z(),m=Qe(),b=u.plugins,y=c.useMemo(()=>ke({collection:n,path:t,values:o?.values,fields:u.propertyConfigs}),[o?.values,t]),w=(e==="new"||e==="copy")&&!!y.customId&&y.customId!=="optional",C=c.useMemo(()=>e==="new"||e==="copy"?w?void 0:m.generateEntityId(t):o?.id,[]),E=c.useRef(!1),B=c.useMemo(()=>{const M=y.properties;if((e==="existing"||e==="copy")&&o)return o.values??Ct(M);if(e==="new")return Ct(M);throw console.error({status:e,entity:o}),new Error("Form has not been initialised with the correct parameters")},[e,y,o]),[I,x]=c.useState(C),[k,S]=c.useState(!1),[F,P]=c.useState(),N=c.useRef(o?.values??B),T=N.current,[Y,H]=c.useState(T),_=M=>{H(M),a&&a(M),p&&M&&!oe(M,T)&&V(M)};c.useEffect(()=>{I&&d&&d(I)},[I,d]);const X=ke({collection:n,path:t,entityId:I,values:Y,previousValues:T,fields:u.propertyConfigs}),te=n.callbacks?.onIdUpdate;c.useEffect(()=>{if(te&&Y&&(e==="new"||e==="copy"))try{const M=te({collection:X,path:t,entityId:I,values:Y,context:u});x(M)}catch(M){h&&h(M),console.error(M)}},[I,Y,e]);const z=c.useMemo(()=>T&&e==="existing"?Object.entries(X.properties).map(([M,$])=>{if(wt($))return{};const K=T[M],L=B[M];return oe(K,L)?{}:{[M]:L}}).reduce((M,$)=>({...M,...$}),{}):{},[B,X.properties,T,e]),V=M=>l({collection:X,path:t,entityId:I,values:M,previousValues:o?.values,closeAfterSave:E.current,autoSave:p??!1}).then($=>{const K=e==="new"?"new_entity_saved":e==="copy"?"entity_copied":e==="existing"?"entity_edited":"unmapped_event";u.onAnalyticsEvent?.(K,{path:t}),N.current=M}).catch($=>{console.error($),P($)}).finally(()=>{E.current=!1}),re=(M,$)=>{if(w&&!I){console.error("Missing custom Id"),S(!0),$.setSubmitting(!1);return}if(P(void 0),S(!1),e==="existing"){if(!o?.id)throw Error("Form misconfiguration when saving, no id for existing entity")}else if(e==="new"||e==="copy"){if(n.customId&&n.customId!=="optional"&&!I)throw Error("Form misconfiguration when saving, entityId should be set")}else throw Error("New FormType added, check EntityForm");V(M)?.then(K=>{$.resetForm({values:M,submitCount:0,touched:{}})}).finally(()=>{$.setSubmitting(!1)})},W=c.useCallback(({name:M,value:$,property:K})=>m.checkUniqueField(t,M,$,I),[m,t,I]),J=c.useMemo(()=>I?No(I,X.properties,W):void 0,[I,X.properties,W]),se=je(),U=c.useCallback(({entity:M,customEntityActions:$})=>{const K=at(n,se,Pe(t),null),L=M?Jt(n,se,Pe(t),M):!0,Q=[];return K&&Q.push(el),L&&Q.push(tl),$&&Q.push(...$),Q},[se,n,t]);return r.jsx(Ce.Formik,{initialValues:B,onSubmit:re,validationSchema:J,validate:M=>console.debug("Validating",M),onReset:()=>i&&i(),children:M=>{const $=[],K={setFieldValue:M.setFieldValue,values:M.values,collection:X,entityId:I,path:t,save:V};if(c.useEffect(()=>{A&&A(K)},[A,K]),b&&n){const L={entityId:I,path:t,status:e,collection:n,context:u,currentEntityId:I,formContext:K};$.push(...b.map((Q,D)=>Q.form?.Actions?r.jsx(Q.form.Actions,{...L},`actions_${Q.name}`):null).filter(Boolean))}return r.jsxs("div",{className:"h-full overflow-auto",children:[$.length>0&&r.jsx("div",{className:f.cn("w-full flex justify-end items-center sticky top-0 right-0 left-0 z-10 bg-opacity-60 bg-slate-200 dark:bg-opacity-60 dark:bg-slate-800 backdrop-blur-md"),children:$}),r.jsxs("div",{className:"pl-4 pr-4 pt-12 pb-16 md:pl-8",children:[r.jsx("div",{className:`w-full py-2 flex items-center mt-${4+($?8:0)} lg:mt-${8+($?8:0)} mb-8`,children:r.jsx(f.Typography,{className:"mt-4 flex-grow "+n.hideIdFromForm?"mb-2":"mb-0",variant:"h4",children:n.singularName??n.name})}),!g&&r.jsx(Xs,{customId:n.customId,entityId:I,status:e,onChange:x,error:k,entity:o}),I&&r.jsx(ea,{...M,initialValues:T,onModified:s,onValuesChanged:_,underlyingChanges:z,entity:o,resolvedCollection:X,formContext:K,status:e,savingError:F,closeAfterSaveRef:E,autoSave:p,entityActions:U({entity:o,customEntityActions:n.entityActions})})]})]})}})}function ea(e){const{values:t,onModified:n,onValuesChanged:o,underlyingChanges:l,formContext:i,entity:s,touched:a,setFieldValue:d,resolvedCollection:A,isSubmitting:g,status:p,handleSubmit:h,savingError:u,dirty:m,closeAfterSaveRef:b,autoSave:y,entityActions:w}=e,C=Z(),E=w.filter(F=>F.includeInForm===void 0||F.includeInForm),B=He(),I=m;c.useEffect(()=>{n&&n(I),o&&o(t)},[I,t]),c.useEffect(()=>{!y&&l&&s&&Object.entries(l).forEach(([F,P])=>{const N=t[F];!oe(P,N)&&!a[F]&&(console.debug("Updated value from the datasource:",F,P),d(F,P!==void 0?P:null))})},[y,l,s,t,a,d]);const x=r.jsx("div",{className:"flex flex-col gap-8",children:(A.propertiesOrder??Object.keys(A.properties)).map(F=>{const P=A.properties[F];if(!P)return console.warn(`Property ${F} not found in collection ${A.name}`),null;const N=!!l&&Object.keys(l).includes(F)&&!!a[F],T=!y&&g||it(P)||!!P.disabled;if(wt(P))return null;const H={propertyKey:F,disabled:T,property:P,includeDescription:P.description||P.longDescription,underlyingValueHasChanged:N&&!y,context:i,tableMode:!1,partOfArray:!1,partOfBlock:!1,autoFocus:!1};return r.jsx("div",{id:`form_field_${F}`,children:r.jsx(ne,{children:r.jsx(nt,{...H})})},`field_${A.name}_${F}`)}).filter(Boolean)}),k=g||!I&&p==="existing",S=c.useRef(null);return r.jsxs(Ce.Form,{onSubmit:h,noValidate:!0,children:[r.jsxs("div",{className:"mt-12",ref:S,children:[x,r.jsx(qs,{containerRef:S})]}),r.jsx("div",{className:"h-14"}),!y&&r.jsxs(f.DialogActions,{position:"absolute",children:[u&&r.jsx("div",{className:"text-right",children:r.jsx(f.Typography,{color:"error",children:u.message})}),s&&E.length>0&&r.jsx("div",{className:"flex-grow flex overflow-auto no-scrollbar",children:E.map(F=>r.jsx(f.IconButton,{color:"primary",onClick:P=>{P.stopPropagation(),s&&F.onClick({entity:s,fullPath:A.path,collection:A,context:C,sideEntityController:B})},children:F.icon},F.name))}),r.jsx(f.Button,{variant:"text",disabled:k,type:"reset",children:p==="existing"?"Discard":"Clear"}),r.jsxs(f.Button,{variant:"text",color:"primary",type:"submit",disabled:k,onClick:()=>{b.current=!1},children:[p==="existing"&&"Save",p==="copy"&&"Create copy",p==="new"&&"Create"]}),r.jsxs(f.Button,{variant:"filled",color:"primary",type:"submit",disabled:k,onClick:()=>{b.current=!0},children:[p==="existing"&&"Save and close",p==="copy"&&"Create copy and close",p==="new"&&"Create and close"]})]})]})}function ta(e){return e.open?r.jsx(ra,{...e}):null}function ra({tableKey:e,entity:t,customFieldValidator:n,propertyKey:o,collection:l,path:i,cellRect:s,open:a,onClose:d,onCellValueChange:A,container:g}){const p=Qe(),h=Z(),[u,m]=c.useState(),[b,y]=c.useState(),w=t?.id,[C,E]=c.useState(t);c.useEffect(()=>w&&l?p.listenEntity?.({path:i,entityId:w,collection:l,onUpdate:V=>{E(V),I(V?.values)}}):()=>{},[p,w,l,i,a]);const[B,I]=c.useState(C?.values),x=l?ke({collection:l,path:i,values:B,entityId:w,fields:h.propertyConfigs}):void 0,k=Fs(),S=c.useRef(null),F=c.useRef(null),P=c.useRef(!1),N=c.useCallback(()=>{if(!s)throw Error("getInitialLocation error");return{x:s.left<k.width-s.right?s.x+s.width/2:s.x-s.width/2,y:s.top<k.height-s.bottom?s.y+s.height/2:s.y-s.height/2}},[s,k.height,k.width]),T=c.useCallback(({x:V,y:re})=>{const W=S.current?.getBoundingClientRect();if(!W)throw Error("normalizePosition called before draggableBoundingRect is set");return{x:Math.max(0,Math.min(V,k.width-W.width)),y:Math.max(0,Math.min(re,k.height-W.height))}},[k]),Y=c.useCallback(V=>{const re=S.current?.getBoundingClientRect();if(!s||!re)return;const W=V??T(N());(!b||W.x!==b.x||W.y!==b.y)&&y(W)},[s,N,T,b]);Ss({containerRef:S,innerRef:F,x:b?.x,y:b?.y,onMove:Y}),c.useEffect(()=>{P.current=!1},[o,C]),c.useLayoutEffect(()=>{const V=S.current?.getBoundingClientRect();!s||!V||P.current||(Y(),P.current=!0)},[s,Y,P.current]),c.useLayoutEffect(()=>{Y(b)},[k,s]);const H=c.useMemo(()=>{if(!(!x||!w))return No(w,o&&x.properties[o]?{[o]:x.properties[o]}:{},n)},[x,w,o,n]),_=c.useCallback(()=>Y(b),[b,Y]),X=async V=>(m(null),l&&C&&A&&o?A({value:V[o],propertyKey:o,entity:C,setError:m,onValueUpdated:()=>{},fullPath:i,context:h}):Promise.resolve());if(!C)return r.jsx(r.Fragment,{});const te=C&&r.jsxs("div",{className:`text-gray-900 dark:text-white overflow-auto rounded rounded-md bg-white dark:bg-gray-950 ${a?"":"hidden"} cursor-grab max-w-[100vw]`,children:[r.jsx(Ce.Formik,{initialValues:C?.values??{},enableReinitialize:!0,validationSchema:H,validateOnMount:!0,validate:V=>console.debug("Validating",V),onSubmit:(V,re)=>{X(V).then(()=>d()).finally(()=>re.setSubmitting(!1))},children:({values:V,setFieldValue:re,handleSubmit:W,isSubmitting:J})=>{if(c.useEffect(()=>{oe(V,B)||I(V)},[V]),!C)return r.jsx(pe,{error:"PopupFormField misconfiguration"});if(!x)return r.jsx(r.Fragment,{});const se=J,U={collection:x,entityId:w,values:V,path:i,setFieldValue:re,save:X},M=o&&tt(x.properties,o),$=o&&M?{propertyKey:o,disabled:J||it(M)||!!M.disabled,property:M,includeDescription:!1,underlyingValueHasChanged:!1,context:U,tableMode:!0,partOfArray:!1,partOfBlock:!1,autoFocus:a}:void 0;let K=r.jsx(r.Fragment,{children:r.jsx("div",{className:"w-[560px] max-w-full max-h-[85vh]",children:r.jsxs(Ce.Form,{onSubmit:W,noValidate:!0,children:[r.jsx("div",{className:"mb-1 p-4 flex flex-col relative",children:r.jsx("div",{ref:F,className:"cursor-auto",style:{cursor:"auto !important"},children:$&&r.jsx(nt,{...$})})}),r.jsx(f.DialogActions,{children:r.jsx(f.Button,{variant:"filled",color:"primary",type:"submit",disabled:se,children:"Save"})})]})},`popup_form_${e}_${w}_${o}`)});const L=h.plugins;return L&&L.forEach(Q=>{Q.form?.provider&&(K=r.jsx(Q.form.provider.Component,{status:"existing",path:i,collection:x,entity:C,context:h,currentEntityId:w,formContext:U,...Q.form.provider.props,children:K}))}),K}}),u&&r.jsx(f.Typography,{color:"error",children:u.message})]}),z=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 ${a?"visible":"invisible"} cursor-grab overflow-visible`,ref:S,children:[r.jsx(Ns,{onResize:_}),r.jsxs("div",{className:"overflow-hidden",children:[te,r.jsx("div",{className:"absolute -top-3.5 -right-3.5 bg-gray-500 rounded-full",style:{width:"32px",height:"32px"},children:r.jsx(f.IconButton,{size:"small",onClick:V=>{V.stopPropagation(),d()},children:r.jsx(f.ClearIcon,{className:"text-white",size:"small"})})})]})]},`draggable_${o}_${w}_${a}`);return r.jsx(Fl.Root,{asChild:!0,container:g,children:z})}const na="collectionGroupParent",cn=c.memo(function({fullPath:t,parentCollectionIds:n,isSubCollection:o,className:l,...i}){const s=Qe(),a=ie(),d=He(),A=je(),g=dt(),p=Z(),h=c.useRef(null),u=c.useMemo(()=>{const O=g?.getCollectionConfig(t);return O?Ne(i,O):i},[i,t,g?.getCollectionConfig]),m=at(u,A,Pe(t),null),[b,y]=c.useState(void 0),[w,C]=c.useState(void 0),[E,B]=c.useState(0),[I,x]=c.useState(0),k=c.useCallback(()=>{const O=b;setTimeout(()=>{O===b&&y(void 0)},2400)},[b]),S=c.useCallback(O=>Ir(u,A,Pe(t),O??null)?u.inlineEditing===void 0||u.inlineEditing:!1,[u,A,t]),F=u.selectionEnabled===void 0||u.selectionEnabled,P=!S(),[N,T]=c.useState(!1),Y=dn(),H=u.selectionController??Y,{selectedEntities:_,toggleEntitySelection:X,isEntitySelected:te,setSelectedEntities:z}=H;c.useEffect(()=>{C(void 0)},[_]);const V=en({fullPath:t,collection:u,entitiesDisplayedFirst:[],lastDeleteTimestamp:E}),re=c.useRef(Math.random().toString(36)),W=V.popupCell,J=c.useCallback(()=>{V.setPopupCell?.(void 0)},[V.setPopupCell]),se=c.useCallback(O=>(y(O),p.onAnalyticsEvent?.("edit_entity_clicked",{path:O.path,entityId:O.id}),d.open({entityId:O.id,path:O.path,collection:u,updateUrl:!0,onClose:k})),[t,u,d]),U=c.useCallback(()=>{p.onAnalyticsEvent?.("new_entity_click",{path:t}),d.open({path:t,collection:u,updateUrl:!0,onClose:k})},[t,u,d]);c.useCallback(O=>{p.onAnalyticsEvent?.("single_delete_dialog_open",{path:t}),C(O)},[p,t]);const M=c.useCallback(()=>{p.onAnalyticsEvent?.("multiple_delete_dialog_open",{path:t}),C(_)},[p,t,_]),$=c.useCallback((O,q)=>{p.onAnalyticsEvent?.("single_entity_deleted",{path:t}),z(R=>R.filter(ee=>ee.id!==q.id)),B(Date.now())},[p,t,z]),K=c.useCallback((O,q)=>{p.onAnalyticsEvent?.("multiple_entities_deleted",{path:t}),z([]),C(void 0),B(Date.now())},[z]);let L;p?.plugins&&(L=p.plugins.find(O=>O.collectionView?.AddColumnComponent)?.collectionView?.AddColumnComponent);const Q=c.useCallback((O,q)=>{if(g){const R=g.getCollectionConfig(O),ee=Ne(R,q);g.onCollectionModified(O,ee)}},[g]),D=c.useCallback(({width:O,key:q})=>{if(!tt(u.properties,q))return;const R=nl(q,O);Q(t,R)},[u,Q,t]),Ie=c.useCallback(O=>{g&&Q(t,{defaultSize:O})},[Q,t,g]),Ae=at(u,A,Pe(t),null),ae=c.useCallback(({name:O,value:q,property:R,entityId:ee})=>s.checkUniqueField(t,O,q,ee),[t]),Se=({fullPath:O,context:q,value:R,propertyKey:ee,onValueUpdated:ce,setError:Oe,entity:Mt})=>{const j=Ce.setIn({...Mt.values},ee,R),ge={path:O,entityId:Mt.id,values:j,previousValues:Mt.values,collection:u,status:"existing"};return Tr({...ge,collection:u,callbacks:u.callbacks,dataSource:s,context:q,onSaveSuccess:()=>ce(),onSaveFailure:de=>{console.error("Save failure"),console.error(de),Oe(de)}})},Ze=a.resolveAliasesFrom(t),ze=c.useMemo(()=>ke({collection:u,path:t,fields:p.propertyConfigs}),[u,t]),Ve=c.useCallback(({propertyKey:O,propertyValue:q,entity:R})=>{let ee=tt(u.properties,O);return ee||(ee=tt(ze.properties,O)),Be({propertyKey:O,propertyOrBuilder:ee,path:t,propertyValue:q,values:R.values,entityId:R.id,fields:p.propertyConfigs})},[u.properties,p.propertyConfigs,t,ze.properties]),Ft=Vo(ze,!0),bt=c.useMemo(()=>{const O=u.subcollections?.map(R=>({key:_r(R),name:R.name,width:200,dependencies:[],Builder:({entity:ee})=>r.jsx(f.Button,{color:"primary",variant:"outlined",startIcon:r.jsx(f.KeyboardTabIcon,{size:"small"}),onClick:ce=>{ce.stopPropagation(),d.open({path:t,entityId:ee.id,selectedSubPath:R.id??R.path,collection:u,updateUrl:!0})},children:R.name})}))??[],q=u.collectionGroup?[{key:na,name:"Parent entities",width:260,dependencies:[],Builder:({entity:R})=>{const ee=a.getParentReferencesFromPath(R.path);return r.jsx(r.Fragment,{children:ee.map(ce=>r.jsx(De,{reference:ce,size:"tiny"},ce.path+"/"+ce.id))})}}]:[];return[...u.additionalFields??[],...O,...q]},[u,t]),Nt=c.useCallback(()=>{B(Date.now())},[]),Xe=Te(),Ke=c.useCallback(({entity:O,customEntityActions:q})=>{const R=O?Jt(u,A,Pe(t),O):!0,ee=[Ks];return Ae&&ee.push(el),R&&ee.push(tl),q&&ee.push(...q),ee},[A,u,Ae,t]),Pt=c.useCallback(()=>{const O=Ke({}),q=O.filter(ce=>ce.collapsed!==!1),ee=O.filter(ce=>ce.collapsed===!1).length*(Xe?40:30);return(Xe?80+ee:70+ee)+(q.length>0?Xe?40:30:0)},[Xe,Ke]),Re=c.useCallback(({entity:O,size:q,width:R,frozen:ee})=>{const ce=te(O),Oe=Ke({entity:O,customEntityActions:u.entityActions});return r.jsx(qr,{entity:O,width:R,frozen:ee,isSelected:ce,selectionEnabled:F,size:q,highlightEntity:y,unhighlightEntity:k,collection:u,fullPath:t,actions:Oe,hideId:u?.hideIdFromCollection,onCollectionChange:Nt,selectionController:H})},[te,u,A,t,F,X,Ae]),Qt=r.jsx(f.Popover,{open:N,onOpenChange:T,enabled:!!u.description,trigger:r.jsxs("div",{className:"flex flex-col items-start",children:[r.jsx(f.Typography,{variant:"subtitle1",className:`leading-none truncate max-w-[160px] lg:max-w-[240px] ${u.description?"cursor-pointer":"cursor-auto"}`,onClick:u.description?O=>{T(!0),O.stopPropagation()}:void 0,children:`${u.name}`}),r.jsx(oa,{fullPath:t,collection:u,filter:V.filterValues,sortBy:V.sortBy,onCountChange:x})]}),children:u.description&&r.jsx("div",{className:"m-4 text-gray-900 dark:text-white",children:r.jsx(f.Markdown,{source:u.description})})});function Tt({property:O,propertyKey:q,onHover:R}){return p.plugins?r.jsx(r.Fragment,{children:p.plugins.filter(ee=>ee.collectionView?.HeaderAction).map((ee,ce)=>{const Oe=ee.collectionView.HeaderAction;return r.jsx(Oe,{onHover:R,propertyKey:q,property:O,fullPath:t,collection:u,parentCollectionIds:n??[]},`plugin_header_action_${ce}`)})}):null}const G=L?function(){return typeof L=="function"?r.jsx(L,{fullPath:t,parentCollectionIds:n??[],collection:u}):null}:void 0;return r.jsxs("div",{className:f.cn("overflow-hidden h-full w-full",l),ref:h,children:[r.jsx(Rr,{additionalFields:bt,tableController:V,displayedColumnIds:Ft,onSizeChanged:Ie,onEntityClick:se,onColumnResize:D,onValueChange:Se,tableRowActionsBuilder:Re,uniqueFieldValidator:ae,title:Qt,selectionController:H,highlightedEntities:b?[b]:[],defaultSize:u.defaultSize,properties:ze.properties,getPropertyFor:Ve,actions:r.jsx(Is,{parentCollectionIds:n??[],collection:u,tableController:V,onMultipleDeleteClick:M,onNewClick:U,path:t,relativePath:u.path,selectionController:H,selectionEnabled:F,collectionEntitiesCount:I}),emptyComponent:m&&V.filterValues===void 0&&V.sortBy===void 0?r.jsxs("div",{className:"flex flex-col items-center justify-center",children:[r.jsx(f.Typography,{variant:"subtitle2",children:"So empty..."}),r.jsxs(f.Button,{color:"primary",variant:"outlined",onClick:U,className:"mt-4",children:[r.jsx(f.AddIcon,{}),"Create your first entity"]})]}):r.jsx(f.Typography,{variant:"label",children:"No results with the applied filter/sort"}),hoverRow:P,inlineEditing:S(),AdditionalHeaderWidget:Tt,AddColumnComponent:G,getIdColumnWidth:Pt,additionalIDHeaderWidget:r.jsx(la,{path:t,collection:u})},`collection_table_${t}`),r.jsx(ta,{open:!!W,onClose:J,cellRect:W?.cellRect,propertyKey:W?.propertyKey,collection:u,entity:W?.entity,tableKey:re.current,customFieldValidator:ae,path:Ze,onCellValueChange:Se,container:h.current},`popup_form_${W?.propertyKey}_${W?.entity?.id}`),w&&r.jsx(Uo,{entityOrEntitiesToDelete:w,path:t,collection:u,callbacks:u.callbacks,open:!!w,onEntityDelete:$,onMultipleEntitiesDelete:K,onClose:()=>C(void 0)})]})},oe);function dn(){const[e,t]=c.useState([]),n=c.useCallback(l=>{let i;e.map(s=>s.id).includes(l.id)?i=e.filter(s=>s.id!==l.id):i=[...e,l],t(i)},[e]),o=c.useCallback(l=>e.map(i=>i.id).includes(l.id),[e]);return{selectedEntities:e,setSelectedEntities:t,isEntitySelected:o,toggleEntitySelection:n}}function oa({fullPath:e,collection:t,filter:n,sortBy:o,onCountChange:l}){const i=Qe(),s=ie(),[a,d]=c.useState(void 0),[A,g]=c.useState(void 0),p=o?o[0]:void 0,h=o?o[1]:void 0,u=c.useMemo(()=>s.resolveAliasesFrom(e),[e,s.resolveAliasesFrom]);return c.useEffect(()=>{i.countEntities({path:u,collection:t,filter:n,orderBy:p,order:h}).then(d).catch(g)},[e,i,u,t,n,p,h]),c.useEffect(()=>{l&&l(a??0)},[l,a]),A?null:r.jsx(f.Typography,{className:"w-full text-ellipsis block overflow-hidden whitespace-nowrap max-w-xs text-left w-fit-content",variant:"caption",color:"secondary",children:a!==void 0?`${a} entities`:r.jsx(f.Skeleton,{className:"w-full max-w-[80px] mt-1"})})}function nl(e,t){if(e.includes(".")){const[n,...o]=e.split(".");return{properties:{[n]:nl(o.join("."),t)}}}return{properties:{[e]:{columnWidth:t}}}}function la({collection:e,path:t}){const[n,o]=c.useState(!1),[l,i]=c.useState(""),s=He();return r.jsx(f.Tooltip,{title:n?void 0:"Find by ID",children:r.jsx(f.Popover,{open:n,onOpenChange:o,trigger:r.jsx(f.IconButton,{size:"small",children:r.jsx(f.SearchIcon,{size:"small"})}),children:r.jsx("form",{noValidate:!0,onSubmit:a=>{if(a.preventDefault(),!!l)return o(!1),s.open({entityId:l,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-4 w-full gap-4",children:[r.jsx(f.TextField,{placeholder:"Find entity by ID",size:"small",onChange:a=>i(a.target.value),value:l,className:"flex-grow"}),r.jsx(f.Button,{variant:"outlined",disabled:!l,type:"submit",children:"Go"})]})})})})}function ol({onSingleEntitySelected:e,onMultipleEntitiesSelected:t,multiselect:n,collection:o,path:l,selectedEntityIds:i,description:s,forceFilter:a,maxSelection:d}){const A=nr(),g=He(),p=ie(),h=Z(),u=p.resolveAliasesFrom(l),m=Qe(),[b,y]=c.useState([]),w=dn();c.useEffect(()=>{let N=!1;const T=i?.map(Y=>Y?.toString()).filter(Boolean);return T&&o?Promise.all(T.map(Y=>m.fetchEntity({path:u,entityId:Y,collection:o}))).then(Y=>{if(!N){const H=Y.filter(_=>_!==void 0);w.setSelectedEntities(H),y(H)}}):(w.setSelectedEntities([]),y([])),()=>{N=!0}},[m,u,i,o,w.setSelectedEntities]);const C=()=>{h.onAnalyticsEvent?.("reference_selection_clear",{path:u}),w.setSelectedEntities([]),!n&&e?e(null):t&&t([])},E=N=>{console.debug("ReferenceSelectionInner toggleEntitySelection",N);let T;const Y=w.selectedEntities;if(h.onAnalyticsEvent?.("reference_selection_toggle",{path:u,entityId:N.id}),Y){if(Y.map(H=>H.id).indexOf(N.id)>-1)T=Y.filter(H=>H.id!==N.id);else{if(d&&Y.length>=d)return;T=[...Y,N]}w.setSelectedEntities(T),t&&t(T)}},B=N=>{console.debug("ReferenceSelectionInner onEntityClick",N),!n&&e?(h.onAnalyticsEvent?.("reference_selected_single",{path:u,entityId:N.id}),e(N),A.close(!1)):E(N)},I=()=>{h.onAnalyticsEvent?.("reference_selection_new_entity",{path:u}),g.open({path:u,collection:o,updateUrl:!0,onUpdate:({entity:N})=>{y([N,...b]),B(N)},closeOnSave:!0})},x=({entity:N,size:T,width:Y,frozen:H})=>{const _=w.selectedEntities,X=_&&_.map(te=>te.id).indexOf(N.id)>-1;return r.jsx(qr,{width:Y,frozen:H,entity:N,size:T,isSelected:X,selectionEnabled:n,hideId:o?.hideIdFromCollection,fullPath:u,selectionController:w})},k=c.useCallback(N=>{N.stopPropagation(),A.close(!1)},[A]);if(!o)return r.jsx(pe,{error:"Could not find collection with id "+o});const S=c.useMemo(()=>ke({collection:o,path:u,values:{},fields:h.propertyConfigs}),[o,h.propertyConfigs,u]),F=Vo(S,!1),P=en({fullPath:u,collection:o,entitiesDisplayedFirst:b,forceFilter:a});return r.jsxs("div",{className:"flex flex-col h-full",children:[r.jsx("div",{className:"flex-grow",children:b&&r.jsx(Rr,{displayedColumnIds:F,onEntityClick:B,tableController:P,tableRowActionsBuilder:x,title:r.jsx(f.Typography,{variant:"subtitle2",children:o.singularName?`Select ${o.singularName}`:`Select from ${o.name}`}),defaultSize:o.defaultSize,properties:S.properties,forceFilter:a,inlineEditing:!1,selectionController:w,actions:r.jsx(ia,{collection:o,path:u,onNewClick:I,onClear:C})})}),r.jsxs(f.DialogActions,{translucent:!1,children:[s&&r.jsx(f.Typography,{variant:"body2",className:"flex-grow text-left",children:s}),r.jsx(f.Button,{onClick:k,color:"primary",variant:"filled",children:"Done"})]})]})}function ia({collection:e,path:t,onClear:n,onNewClick:o}){const l=je(),i=Te(),s=o?d=>{d.preventDefault(),o()}:void 0,a=at(e,l,Pe(t),null)&&s&&(i?r.jsxs(f.Button,{onClick:s,startIcon:r.jsx(f.AddIcon,{}),variant:"outlined",color:"primary",children:["Add ",e.singularName??e.name]}):r.jsx(f.Button,{onClick:s,size:"medium",variant:"outlined",color:"primary",children:r.jsx(f.AddIcon,{})}));return r.jsxs(r.Fragment,{children:[r.jsx(f.Button,{onClick:n,variant:"text",color:"primary",children:"Clear"}),a]})}function An({children:e,group:t}){const n=dt();return r.jsx(f.ExpandablePanel,{invisible:!0,titleClassName:"font-medium text-sm text-gray-600 dark:text-gray-400",className:"py-4",initiallyExpanded:!(n?.collapsedGroups??[]).includes(t??"ungrouped"),onExpandedChange:o=>{if(n)if(o)n.setCollapsedGroups((n.collapsedGroups??[]).filter(l=>l!==(t??"ungrouped")));else{const l=(n.collapsedGroups??[]).concat(t??"ungrouped");n.setCollapsedGroups(l)}},title:r.jsx(f.Typography,{color:"secondary",className:"font-medium ml-1",children:t?.toUpperCase()??"Views".toUpperCase()}),children:r.jsx("div",{className:"mb-8",children:e})})}function ll({view:e,path:t,collection:n,url:o,name:l,description:i,onClick:s}){const a=dt(),d=qt(n??e),A=fe.useNavigate(),g=Z(),p=(a?.favouritePaths??[]).includes(t);let h;if(g.plugins&&n){const u={path:t,collection:n,context:g};h=r.jsx(r.Fragment,{children:g.plugins.map((m,b)=>m.homePage?.CollectionActions?r.jsx(m.homePage.CollectionActions,{...u,extraProps:m.homePage.extraProps},`actions_${b}`):null)})}return r.jsx(f.Card,{className:f.cn("h-full p-4 cursor-pointer min-h-[230px]"),onClick:()=>{s?.(),A(o),a&&a.setRecentlyVisitedPaths([t,...(a.recentlyVisitedPaths??[]).filter(u=>u!==t)])},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:[d,r.jsxs("div",{className:"flex items-center gap-1",onClick:u=>{u.preventDefault(),u.stopPropagation()},children:[h,a&&r.jsx(f.IconButton,{onClick:u=>{u.preventDefault(),u.stopPropagation(),p?a.setFavouritePaths(a.favouritePaths.filter(m=>m!==t)):a.setFavouritePaths([...a.favouritePaths,t])},children:p?r.jsx(f.StarIcon,{size:18,className:"text-secondary"}):r.jsx(f.StarBorderIcon,{size:18,className:"text-gray-400 dark:text-gray-500"})})]})]}),r.jsx(f.Typography,{gutterBottom:!0,variant:"h5",component:"h2",children:l}),i&&r.jsx(f.Typography,{variant:"body2",color:"secondary",component:"div",children:r.jsx(f.Markdown,{source:i})})]}),r.jsx("div",{style:{alignSelf:"flex-end"},children:r.jsx("div",{className:"p-4",children:r.jsx(f.ArrowForwardIcon,{className:"text-primary"})})})]})})}function sa({entry:e}){const t=fe.useNavigate(),n=dt();if(!n)return null;const o=n.favouritePaths.includes(e.path),l=i=>{i.preventDefault(),i.stopPropagation(),o?n.setFavouritePaths(n.favouritePaths.filter(s=>s!==e.path)):n.setFavouritePaths([...n.favouritePaths,e.path])};return r.jsx(f.Chip,{onClick:()=>t(e.url),icon:o?r.jsx(f.StarIcon,{onClick:l,size:18,className:"text-secondary"}):r.jsx(f.StarBorderIcon,{onClick:l,size:18,className:"text-gray-400 dark:text-gray-500"}),children:e.name},e.path)}function aa({hidden:e}){const t=ie(),n=dt();if(!n)return null;const o=(n?.favouritePaths??[]).map(l=>t.topLevelNavigation?.navigationEntries.find(i=>i.path===l)).filter(Boolean);return r.jsx(f.Collapse,{in:o.length>0,children:r.jsx("div",{className:"flex flex-row flex-wrap gap-2 pb-2 min-h-[32px]",children:o.map(l=>r.jsx(sa,{entry:l},l.path))})})}const fn={};function ca(){const e=fe.useLocation(),t=c.useRef(null),[n,o]=c.useState(0),[l,i]=c.useState("down"),s=c.useCallback(()=>{!t.current||!e.key||(fn[e.key]=t.current.scrollTop,o(t.current.scrollTop),i(t.current.scrollTop>n?"down":"up"))},[t,e.key,n]);return c.useEffect(()=>{const a=t.current;if(a)return a.addEventListener("scroll",s,{passive:!0}),()=>{a&&a.removeEventListener("scroll",s)}},[t,s,e]),c.useEffect(()=>{!t.current||!fn[e.key]||t.current.scrollTo({top:fn[e.key],behavior:"auto"})},[e]),{containerRef:t,scroll:n,direction:l}}const pt=new Sl.Search("url");pt.addIndex("name"),pt.addIndex("description"),pt.addIndex("group"),pt.addIndex("path");function il({additionalChildrenStart:e,additionalChildrenEnd:t}){const n=Z(),o=ie();if(!o.topLevelNavigation)throw Error("Navigation not ready in FireCMSHomePage");const{containerRef:l,scroll:i,direction:s}=ca(),{navigationEntries:a,groups:d}=o.topLevelNavigation,[A,g]=c.useState(null),p=A?a.filter(w=>A.includes(w.url)):a;c.useEffect(()=>{pt.addDocuments(a)},[a]);const h=c.useCallback(w=>{if(!w||w==="")g(null);else{const C=pt.search(w);g(C.map(E=>E.url))}},[]),u=[...d];(p.filter(w=>!w.group).length>0||p.length===0)&&u.push(void 0);let m,b,y;if(n.plugins){const w={context:n};y=r.jsx(r.Fragment,{children:n.plugins.filter(C=>C.homePage?.includeSection).map((C,E)=>{const B=C.homePage.includeSection(w);return r.jsx(An,{group:B.title,children:B.children},`plugin_section_${C.name}`)})}),m=r.jsx("div",{className:"flex flex-col gap-2",children:n.plugins.filter(C=>C.homePage?.additionalChildrenStart).map((C,E)=>r.jsx("div",{children:C.homePage.additionalChildrenStart},`plugin_children_start_${E}`))}),b=r.jsx("div",{className:"flex flex-col gap-2",children:n.plugins.filter(C=>C.homePage?.additionalChildrenEnd).map((C,E)=>r.jsx("div",{children:C.homePage.additionalChildrenEnd},`plugin_children_start_${E}`))})}return r.jsx("div",{id:"home_page",ref:l,className:"py-2 overflow-auto h-full w-full",children:r.jsxs(f.Container,{maxWidth:"6xl",children:[r.jsx("div",{className:"sticky py-4 transition-all duration-400 ease-in-out top-0 z-10",style:{top:s==="down"?-84:0},children:r.jsx(f.SearchBar,{onTextSearch:h,placeholder:"Search collections",large:!1,className:"w-full"})}),r.jsx(aa,{hidden:!!A}),e,m,u.map((w,C)=>{const E=[],B={group:w,context:n};n.plugins&&n.plugins.forEach(x=>{x.homePage?.AdditionalCards&&E.push(...Rt(x.homePage?.AdditionalCards))});const I=p.filter(x=>x.group===w||!x.group&&w===void 0);return I.length===0&&E.length===0?null:r.jsx(An,{group:w,children:r.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:[I.map(x=>r.jsx("div",{className:"col-span-1",children:r.jsx(ll,{...x,onClick:()=>{const k=x.type==="collection"?"home_navigate_to_collection":x.type==="view"?"home_navigate_to_view":"unmapped_event";n.onAnalyticsEvent?.(k,{path:x.path})}})},`nav_${x.group}_${x.name}`)),E&&E.map((x,k)=>r.jsx("div",{children:r.jsx(x,{...B})},`nav_${w}_add_${k}`))]})},`plugin_section_${w}`)}),y,b,t]})})}function da({propertyConfig:e}){const t="h-8 w-8 p-1 rounded-full shadow text-white",n=typeof e?.property=="object"?ml(e.property):void 0;return r.jsx("div",{className:t,style:{background:e?.color??n?.color??"#888"},children:e?.Icon?jt(e,"medium"):jt(n,"medium")})}function sl(){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(f.Typography,{variant:"h4",align:"center",gutterBottom:!0,children:"Page not found"}),r.jsx(f.Typography,{align:"center",gutterBottom:!0,children:"This page does not exist or you may not have access to it"}),r.jsx(f.Button,{variant:"text",component:fe.Link,to:"/",children:"Back to home"})]})})}function Aa({open:e,onAccept:t,onCancel:n,title:o,loading:l,body:i}){return r.jsxs(f.Dialog,{open:e,onOpenChange:s=>s?void 0:n(),children:[r.jsxs(f.DialogContent,{children:[r.jsx(f.Typography,{variant:"h6",className:"mb-2",children:o}),i]}),r.jsxs(f.DialogActions,{children:[r.jsx(f.Button,{variant:"text",onClick:n,autoFocus:!0,children:"Cancel"}),r.jsx(f.LoadingButton,{color:"primary",type:"submit",loading:l,onClick:t,children:"Ok"})]})]})}function al({width:e,height:t,className:n,style:o}){return r.jsxs("svg",{width:e??"100%",height:t??"100%",viewBox:"0 0 599 599",version:"1.1",style:o,className:n,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 cl=function({title:t,endAdornment:n,startAdornment:o,drawerOpen:l,dropDownActions:i,includeDrawer:s,className:a,style:d,user:A}){const g=ie(),p=je(),{mode:h,toggleMode:u}=Mr(),m=Te(),b=A??p.user;let y;if(b&&b.photoURL)y=r.jsx(f.Avatar,{src:b.photoURL});else if(b===void 0||p.initialLoading)y=r.jsx("div",{className:"p-1 flex justify-center",children:r.jsx(f.Skeleton,{className:"w-10 h-10 rounded-full"})});else{const w=b?.displayName?b.displayName[0].toUpperCase():b?.email?b.email[0].toUpperCase():"A";y=r.jsx(f.Avatar,{children:w})}return r.jsx("div",{style:d,className:f.cn("pr-2",{"ml-[17rem]":l&&m,"ml-16":s&&!(l&&m)&&!o,"h-16":!0,"z-10":m,"transition-all":!0,"ease-in":!0,"duration-75":!0,"w-full":!s,"w-[calc(100%-64px)]":s&&!(l&&m),"w-[calc(100%-17rem)]":s&&l&&m,"duration-150":l&&m,fixed:!0},a),children:r.jsxs("div",{className:"flex flex-row gap-2 px-4 h-full items-center",children:[o,g&&r.jsx("div",{className:"mr-8 hidden lg:block",children:r.jsx(fe.Link,{className:"visited:text-inherit visited:dark:text-inherit",to:g?.basePath??"/",children:r.jsx(f.Typography,{variant:"subtitle1",noWrap:!0,className:"ml-2 !font-medium",children:t})})}),r.jsx("div",{className:"flex-grow"}),n&&r.jsx(ne,{children:n}),r.jsx(f.IconButton,{color:"inherit","aria-label":"Open drawer",onClick:u,size:"large",children:h==="dark"?r.jsx(f.DarkModeIcon,{}):r.jsx(f.LightModeIcon,{})}),r.jsxs(f.Menu,{trigger:y,children:[i,!i&&r.jsxs(f.MenuItem,{onClick:p.signOut,children:[r.jsx(f.LogoutIcon,{}),"Log Out"]})]})]})})},fa=e=>e&&Array.isArray(e)&&e.length>0?e.map((t,n)=>t?{[gr(t)+n]:St()}:{}).reduce((t,n)=>({...t,...n}),{}):{};function un({droppableId:e,addLabel:t,value:n,disabled:o=!1,buildEntry:l,size:i,onInternalIdAdded:s,includeAddButton:a,newDefaultEntry:d,onValueChange:A}){const g=n&&Array.isArray(n)&&n.length>0,p=c.useRef(fa(n)),[h,u]=c.useState(g?Object.values(p.current):[]);c.useEffect(()=>{if(g&&n&&n.length!==h.length){const C=n.map((E,B)=>{const I=gr(E)+B;if(I in p.current)return p.current[I];{const x=St();return p.current[I]=x,x}});u(C)}},[g,h.length,n]);const m=C=>{if(C.preventDefault(),o)return;const E=St(),B=[...h,E];s&&s(E),u(B),A([...n??[],d])},b=C=>{const E=[...h];E.splice(C,1),u(E),A(n.filter((B,I)=>I!==C))},y=C=>{const E=St(),B=n[C],I=[...h.splice(0,C+1),E,...h.splice(C+1,h.length-C-1)];s&&s(E),u(I),A([...n.slice(0,C+1),B,...n.slice(C+1)])},w=C=>{if(!C.destination)return;const E=C.source.index,B=C.destination.index,I=[...h],x=I[E];I[E]=I[B],I[B]=x,u(I),A(ua(n,E,B))};return r.jsx(lt.DragDropContext,{onDragEnd:w,children:r.jsx(lt.Droppable,{droppableId:e,renderClone:(C,E,B)=>{const I=B.source.index,x=h[I];return r.jsx(gn,{provided:C,internalId:x,index:I,size:i,disabled:o,buildEntry:l,remove:b,copy:y,isDragging:E.isDragging})},children:(C,E)=>r.jsxs("div",{...C.droppableProps,ref:C.innerRef,children:[g&&h.map((B,I)=>r.jsx(lt.Draggable,{draggableId:`array_field_${B}`,isDragDisabled:o,index:I,children:(x,k)=>r.jsx(gn,{provided:x,internalId:B,index:I,size:i,disabled:o,buildEntry:l,remove:b,copy:y,isDragging:k.isDragging})},`array_field_${B}`)),C.placeholder,a&&r.jsx("div",{className:"py-4 justify-center text-left",children:r.jsx(f.Button,{variant:"text",size:i==="small"?"small":"medium",color:"primary",disabled:o,startIcon:r.jsx(f.AddIcon,{}),onClick:m,children:t??"Add"})})]})})})}function gn({provided:e,index:t,internalId:n,size:o,disabled:l,buildEntry:i,remove:s,copy:a,isDragging:d}){const[A,g]=cr(),p=o!=="small"&&g.height===0,h=o!=="small"&&g.height<100,[u,m]=c.useState(!1),b=c.useCallback(()=>m(!0),[]),y=c.useCallback(()=>m(!1),[]);return r.jsx("div",{onMouseEnter:b,onMouseMove:b,onMouseLeave:y,ref:e.innerRef,...e.draggableProps,style:e.draggableProps.style,className:`${d||u?f.fieldBackgroundHoverMixin:""} mb-1 rounded-md opacity-100`,children:r.jsxs("div",{className:"flex items-start",children:[r.jsx("div",{ref:A,className:"flex-grow w-[calc(100%-48px)] text-text-primary dark:text-text-primary-dark",children:i(t,n)}),r.jsx(dl,{direction:o==="small"?"row":"column",disabled:l,remove:s,index:t,provided:e,measuring:p,contentOverflow:h,copy:a})]})})}function dl({direction:e,disabled:t,remove:n,index:o,provided:l,copy:i,contentOverflow:s,measuring:a}){return r.jsxs("div",{className:`p-1 flex ${e==="row"?"flex-row-reverse":"flex-col"} items-center`,...l.dragHandleProps,children:[r.jsx(f.Tooltip,{side:e==="column"?"left":void 0,title:"Move",children:r.jsx(f.IconButton,{size:"small",disabled:t,className:`cursor-${t?"inherit":"grab"}`,children:r.jsx("svg",{focusable:"false",fill:"currentColor","aria-hidden":"true",viewBox:"0 0 24 24",children:r.jsx("path",{d:"M20 9H4v2h16V9zM4 15h16v-2H4v2z"})})})}),!a&&!s&&r.jsxs(r.Fragment,{children:[r.jsx(f.Tooltip,{title:"Remove",side:e==="column"?"left":void 0,children:r.jsx(f.IconButton,{size:"small","aria-label":"remove",disabled:t,onClick:()=>n(o),children:r.jsx(f.RemoveIcon,{size:"small"})})}),r.jsx(f.Tooltip,{side:e==="column"?"left":void 0,title:"Copy in this position",children:r.jsx(f.IconButton,{size:"small","aria-label":"copy",disabled:t,onClick:()=>i(o),children:r.jsx(f.ContentCopyIcon,{size:"small"})})})]}),!a&&s&&r.jsx(r.Fragment,{children:r.jsxs(f.Menu,{trigger:r.jsx(f.IconButton,{size:"small",children:r.jsx(f.MoreVertIcon,{size:"small"})}),children:[r.jsxs(f.MenuItem,{dense:!0,onClick:()=>n(o),children:[r.jsx(f.RemoveIcon,{size:"small"}),"Remove"]}),r.jsxs(f.MenuItem,{dense:!0,onClick:()=>i(o),children:[r.jsx(f.ContentCopyIcon,{size:"small"}),"Copy"]})]})})]})}function ua(e,t,n){const o=Array.from(e),[l]=o.splice(t,1);return o.splice(n,0,l),o}function St(){return Math.floor(Math.random()*Math.floor(Number.MAX_SAFE_INTEGER))}function ga({name:e,multiselect:t=!1,path:n,disabled:o,value:l,onReferenceSelected:i,onMultipleReferenceSelected:s,previewProperties:a,forceFilter:d,size:A,className:g}){const p=ie(),h=c.useMemo(()=>p.getCollection(n),[n,p]);if(!h)throw Error(`Couldn't find the corresponding collection for the path: ${n}`);const u=c.useCallback(C=>{if(!o&&i){const E=C?Ge(C):null;i?.({reference:E,entity:C})}},[o,i]),m=c.useCallback(C=>{if(!o&&s){const E=C?C.map(B=>Ge(B)):null;s({references:E,entities:C})}},[o,i]),b=mt({multiselect:t,path:n,collection:h,onSingleEntitySelected:u,onMultipleEntitiesSelected:m,forceFilter:d});c.useCallback(C=>{C.stopPropagation(),t?m([]):u(null)},[i]);let y;const w=()=>{o||b.open()};return Array.isArray(l)?y=r.jsx("div",{className:"flex flex-col gap-4",children:l.map((C,E)=>r.jsx(De,{onClick:w,reference:C,disabled:o,previewProperties:a,size:A},`reference_preview_${E}`))}):l instanceof Fe&&(y=r.jsx(De,{reference:l,onClick:w,disabled:o,previewProperties:a,size:A})),r.jsxs("div",{className:f.cn("text-sm font-medium text-gray-500","min-w-80 flex flex-col gap-4","relative transition-colors duration-200 ease-in rounded font-medium",o?"bg-opacity-50":"hover:bg-opacity-75","text-opacity-50 dark:text-white dark:text-opacity-50",g),children:[y,!l&&r.jsx("div",{className:"justify-center text-left",children:r.jsxs(f.Button,{variant:"outlined",color:"primary",disabled:o,onClick:w,children:["Edit ",e]})})]})}function ye({icon:e,title:t,small:n,className:o,required:l}){return r.jsxs("span",{className:`inline-flex items-center my-0.5 ${n?"gap-1":"gap-2"} ${o??""}`,children:[e,r.jsx("span",{className:`font-medium text-${n?"base":"sm"} origin-top-left transform ${n?"translate-x-2 scale-75":""}`,children:(t??"")+(l?" *":"")})]})}function mt(e){const t=ie(),n=Bt(),o=c.useCallback(()=>{if(e.path){let i=e.collection;if(i||(i=t.getCollection(e.path)),!i)throw Error("Not able to resolve the collection in useReferenceDialog");n.open({key:`reference_${e.path}`,component:r.jsx(ol,{collection:i,...e}),width:"90vw",onClose:()=>{e.onClose?.()}})}else throw Error("useReferenceDialog: You are trying to open a reference dialog, but have not declared the `path`")},[t,e,n]),l=c.useCallback(()=>{n.close()},[n]);return{open:o,close:l}}const ha=`data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAAASAAAAEgARslrPgAAB9pJREFUWMONl12obVUVx39jzLk+9j7nHq9y1QT1qpcbSIaXQFGs24PQl3HroSQyqHwJFJF6qaceCsqQoJdELHoIC6EeJCSKsi/TFLGozGsKXksljRLxnrP3WmvOOUYPa+19zsmPWpux5pxrzTX///Exx5hb+B/X1y+/nuIlVKF5m0v1YbQ55tIcKTQXFerNQkumOZ1oTiXCqUH8saR+74L8ZIWWux7+7JuuL2/04s5jJyhWQlXV71KtbhCtr1WtD6s0KlrjNBRaEi3JGzpv6bymQ0sn9mwv9otB7Ls7kn9Xo+U7D9z8/xG4+bz3cs35SjE/HEK8NWr8RBOrs+tQUUlEtAYaijRkbxmY0fuMzucsfcbSWnZQtiWxJL3Uid09iH0jIM8/1f+d3/zuS29M4PvHrmG+cZA8dMdjiLfNYrx6owrMVKlVUQkgkeI1iYbBJ3A2WPpKNtnx+UQisy29L0gPDGKfrwkPn2bJPfd/Zo0ZVp0fvOOdnLGxheX+A/Mq3nGwqS8/q645o4psxkgbhFqdSgqVJKIkghgqjuDoWh+dlm1AI0gUC3o4C9d04idbmZ06euQDPPHMj3YJ3HnkrZx98Fys2PFZ1dxxsJkdPbOecaBqmcWGqBVBIkEiKkoQJ5IJJBTbY8aRgBMwjxgVJoJJwDScnYUrOy2PBamfv/CS4zz9zE+IAIfPuQQzPzyrmq9u1e3RM+qWeaipNCCiE4DjbjgF94xZQj2htpjeK84ImqlIUpO9JllgEKgJDFpfOoh8paN8chbOeQ4g/OTq97PdLXSz3fjiVjO7/sx6g804ow41QWuCrjQPBB3bkZQgAkpBJOMojmIEjIgRKV6RpaYIZHGKQlK5OIv0L8bul8eOfsxjDJGD8613z6rmhq1qxkY1o9YKFUFEEED2xqoE1MNoWgPBwQZMl2SrSbQM9NQyUMlA5S3Rlcqd6E50RdRvPMvn9yE8qP9+9WWtQvXxzdic8xrwPaJrUYJGoq4sVBM1Ukuiln4UBipJVJrGoHUhrARB0XMQ/cizbSd61uaZlzUhXjuvWmqt9oOyAmUPEabnkSDV2j0Rp2YgksZdQpoCtRBwAiN4cKYdw4m3pNnbY9Tw4SZUh9tQEda+ld1WpmThgoivU8fYDbgEggRcleiZ6BOoFNRXLQQX1Eelggsgh8GPx6DhWB2iRgkj2OTuVX8dBzJtMx93BAKK4hIwUUSEID4BGspecWTfDwSCw+UxqByJoqPf9+xmYWQg7H3u+5Poyk3o5BZDxRBxxH29fdkF3YcBXKHgF+m+hLxn4OvbnnbPzMkjsm/+f5cXec2ye6ZfpO6+OX7pE8TqPj1zcN/7Zu8CDm44Bu6skrKjuOs0FlxWCJNMYxMOqLlR3DAvsAKaZo6t7+u7r6nhjN/5RKIQKESKhykhjeIINgJi+0m4Fiuns2WKZQybtJ2AfAWzGu/ayt0wz5gXimeKQyKSPI4kiCMhDxSgyLiOiY9kxnW2NVs+1ZeBbAmzhLmtgd0d8z1k1mIUTxQbKD5gnkmuDN6QvCF5TaIie0UmkIU1id3WcfwZHUo61eWB3gayDdOiZR+JXUuMWmcbyGWcny2RzOi8obeWwRsGrxm8JlGPBHCyOJmpJkwkHHs09pnfL1L60KLqtBKZtprhU+lVmSq9+xRsBfOMW6L4QLFM7zWdz+l8Ru8tA+10YKlJIiSxkcC6dQqlmJc/xaHIvTuZT7UpHalFUHEqL6iGsfKtM8FEzMdy7J4oXui9mk5CczpGErtEKgacQUZJE3gSwzw/i+dfx2G7e6IcOPALCXIkakGkYx4iwceyq+uENPp+RSI7DN7Q+5ylb7JgJLH0+XRGbOlRerWJwNgmnOwJ83Tvq/7KX2KZb1nJfnfp5YRoda7hFC/MQyGI7Mteow2E4pHkDT2zyfS758HV4bSjolOjF2PYS4KBbN2L5vmHZ7DpsWQnDsvfLj1+Lwufy9LSO2y5M1Mnik8OEJxAoSJRk7xhoKX3+URiztI3WPgGS2/p1OnE6CcSvRQGH+htQfH07dPSP7Lp9ajcNy+9DnG/oMT67qqZHz/QtGxVyjworQqVCIjiPiaaTD1ttZZ+fTIeCXQ+Y6HCQm0tO5LYpmfHlyy9/1nCPi3ICw/99JbxUHrdvxr6Q4depdhTfeGapVeH+imKxwhv6ZnR+5zeN0aNGU2+ZIPON0cX0LBQYSnGQgsLSSzoWdiCHVvQ2fLP2fMtwf2vDz50K6TpVPxj/sn7Ni5iu9l6Tof+yd78yoWFQ0uvWYvVLK1h6e34B8RnY9DZnIW3LAijxpLYkZ6Fd+z4km3bYcd2WNry8ezppsZ5ZMd2+MfTv3xtjbr9/PfwyoFDzPvtq7I2t+Vq/m6pt4hxThVaojao1CANRkORmkwkiTCI00thKYWOzJJR+6V1JE8/z2JfqGgfW9jLPPLg7a9Xe8frHs7j5MVXESxfmLS5KYXmxhQ3z/a4icQNRFtEGlwjJkoRIamTmIKNTE+it57kw0sF+1ah3CkSXkiPf42Htl+3WL/2+vIFJ6ishJ3QXD1o9dEhVCcGbS7ModUcakwrigaKChkoYmQK2XMp5L8V/F7DfuDePYrEcv8f7npdnDcksEvkg9RewquhuayTcHzQeCyJXpFVD2fRzSxCFtkuwqks8mjB/ujYr9y6k0gs9528503X/w/F3eUgyIBI4wAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAyMS0wNS0xMFQxOToyODozMyswMDowMEzeSx4AAAAldEVYdGRhdGU6bW9kaWZ5ADIwMjEtMDUtMTBUMTk6Mjg6MzMrMDA6MDA9g/OiAAAARnRFWHRzb2Z0d2FyZQBJbWFnZU1hZ2ljayA2LjcuOC05IDIwMTQtMDUtMTIgUTE2IGh0dHA6Ly93d3cuaW1hZ2VtYWdpY2sub3Jn3IbtAAAAABh0RVh0VGh1bWI6OkRvY3VtZW50OjpQYWdlcwAxp/+7LwAAABh0RVh0VGh1bWI6OkltYWdlOjpoZWlnaHQAMTkyDwByhQAAABd0RVh0VGh1bWI6OkltYWdlOjpXaWR0aAAxOTLTrCEIAAAAGXRFWHRUaHVtYjo6TWltZXR5cGUAaW1hZ2UvcG5nP7JWTgAAABd0RVh0VGh1bWI6Ok1UaW1lADE2MjA2NzQ5MTMk8oswAAAAD3RFWHRUaHVtYjo6U2l6ZQAwQkKUoj7sAAAAVnRFWHRUaHVtYjo6VVJJAGZpbGU6Ly8vbW50bG9nL2Zhdmljb25zLzIwMjEtMDUtMTAvOGIxNDNhYjgwODhkMjBlZThkYmUzOTFhN2NkNmQ3NmQuaWNvLnBuZ9msgG0AAAAASUVORK5CYII=
588
- `;function pa(e,t){c.useEffect(()=>{if(document){document.title=`${e} - FireCMS`;let n=document.querySelector("link[rel~='icon']");n||(n=document.createElement("link"),n.rel="icon",document.getElementsByTagName("head")[0].appendChild(n)),n.href=t??ha}},[e,t])}const rr="main_##Q$SC^#S6";function ma({path:e,entityId:t,selectedSubPath:n,copy:o,collection:l,parentCollectionIds:i,onValuesAreModified:s,formWidth:a,onUpdate:d,onClose:A}){l.customId&&l.formAutoSave&&console.warn(`The collection ${l.path} has customId and formAutoSave enabled. This is not supported and formAutoSave will be ignored`);const[g,p]=c.useState(!1),[h,u]=c.useState(void 0);Wt(h,()=>{h&&D({entityId:J?.id,collection:l,path:e,values:h,closeAfterSave:!1})},!1,2e3);const m=Qe(),b=nr(),y=He(),w=Je(),C=Z(),E=je(),[B,I]=c.useState(void 0),[x,k]=c.useState(o?"copy":t?"existing":"new"),S=c.useRef(void 0),F=S.current,P=(l.subcollections??[]).filter(G=>!G.hideFromNavigation),N=P?.length??0,T=l.entityViews,Y=T?.length??0,H=l.formAutoSave&&!l.customId,_=Y>0||N>0,X=n??Br(l?l.defaultSelectedView:void 0,{status:x,entityId:t}),te=c.useRef(X??rr),z=te.current===rr,{entity:V,dataLoading:re,dataLoadingError:W}=Qr({path:e,entityId:t,collection:l,useCache:!1}),[J,se]=c.useState(V),[U,M]=c.useState(void 0);c.useEffect(()=>{V&&se(V)},[V]),c.useEffect(()=>{if(x==="new")M(!1);else{const G=J?Ir(l,E,Pe(e),J??null):!1;J&&M(!G)}},[E,J,x]);const $=c.useCallback(G=>{p(!1),w.open({type:"error",message:"Error before saving: "+G?.message}),console.error(G)},[w]),K=c.useCallback(G=>{p(!1),w.open({type:"error",message:"Error after saving (entity is saved): "+G?.message}),console.error(G)},[w]),L=(G,O)=>{p(!1),H||w.open({type:"success",message:`${l.singularName??l.name}: Saved correctly`}),se(G),k("existing"),s(!1),d&&d({entity:G}),O?(b.setBlocked(!1),b.close(!0),A?.()):x!=="existing"&&y.replace({path:e,entityId:G.id,selectedSubPath:te.current,updateUrl:!0,collection:l})},Q=c.useCallback(G=>{p(!1),w.open({type:"error",message:"Error saving: "+G?.message}),console.error("Error saving entity",e,t),console.error(G)},[t,e,w]),D=({values:G,previousValues:O,closeAfterSave:q,entityId:R,collection:ee,path:ce})=>{p(!0),Tr({path:ce,entityId:R,values:G,previousValues:O,collection:ee,status:x,dataSource:m,context:C,onSaveSuccess:Oe=>L(Oe,q),onSaveFailure:Q,onPreSaveHookError:$,onSaveSuccessHookError:K}).then()},Ie=async({collection:G,path:O,entityId:q,values:R,previousValues:ee,closeAfterSave:ce,autoSave:Oe})=>{x&&(Oe?u(R):D({collection:G,path:O,entityId:q,values:R,previousValues:ee,closeAfterSave:ce}))},Ae=T?T.map(G=>wr(G,C.entityViews)).filter(Boolean):[],ae=T&&Ae.map((G,O)=>{if(!G||te.current!==G.key)return null;const q=G.Builder;return q?r.jsx("div",{className:f.cn(f.defaultBorderMixin,"relative flex-grow w-full h-full overflow-auto "),role:"tabpanel",children:r.jsx(ne,{children:B&&r.jsx(q,{collection:l,entity:J,modifiedValues:F??J?.values,formContext:B})})},`custom_view_${G.key}`):(console.error("customView.Builder is not defined"),null)}).filter(Boolean),Se=re&&!J||(!J||U===void 0)&&(x==="existing"||x==="copy"),Ze=Se||g,ze=P&&P.map((G,O)=>{const q=G.id??G.path,R=J?`${e}/${J?.id}/${ue(q)}`:void 0;return te.current!==q?null:r.jsxs("div",{className:"relative flex-grow h-full overflow-auto w-full",role:"tabpanel",children:[Ze&&r.jsx(It,{}),!Se&&(J&&R?r.jsx(cn,{fullPath:R,parentCollectionIds:[...i,l.id],isSubCollection:!0,...G}):r.jsx("div",{className:"flex items-center justify-center w-full h-full p-3",children:r.jsx(f.Typography,{variant:"label",children:"You need to save your entity before adding additional collections"})}))]},`subcol_${q}`)}).filter(Boolean),Ve=c.useCallback(()=>{s(!1)},[]),Ft=G=>{te.current=G,y.replace({path:e,entityId:t,selectedSubPath:G===rr?void 0:G,updateUrl:!0,collection:l})},bt=c.useCallback(G=>{S.current=G},[]),Nt=c.useCallback(G=>{w.open({type:"error",message:"Error updating id, check the console"})},[]),Xe=c.useCallback(G=>{se(O=>O?{...O,id:G}:void 0)},[]),Ke=G=>{H||s(G)};function Pt(){const G=C.plugins;let O=r.jsx(rl,{status:x,path:e,collection:l,onEntitySaveRequested:Ie,onDiscard:Ve,onValuesChanged:bt,onModified:Ke,entity:J,onIdChange:Xe,onFormContextChange:I,hideId:l.hideIdFromForm,autoSave:H,onIdUpdateError:Nt});return G&&G.forEach(q=>{q.form?.provider&&(O=r.jsx(q.form.provider.Component,{status:x,path:e,collection:l,onDiscard:Ve,onValuesChanged:bt,onModified:Ke,entity:J,context:C,formContext:B,...q.form.provider.props,children:O}))}),r.jsx(ne,{children:O})}const Re=U===void 0?r.jsx(r.Fragment,{}):U?r.jsxs(r.Fragment,{children:[r.jsx(f.Typography,{className:"mt-16 mb-8 mx-8",variant:"h4",children:l.singularName??l.name}),r.jsx($r,{className:"px-12",entity:J,path:e,collection:l})]}):Pt(),Qt=P&&P.map(G=>r.jsx(f.Tab,{className:"text-sm min-w-[140px]",value:G.id,children:G.name},`entity_detail_collection_tab_${G.name}`)),Tt=Ae.map(G=>r.jsx(f.Tab,{className:"text-sm min-w-[140px]",value:G.key,children:G.name},`entity_detail_collection_tab_${G.name}`));return r.jsx("div",{className:"flex flex-col h-full w-full transition-width duration-250 ease-in-out",children:r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:f.cn(f.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(f.IconButton,{onClick:()=>(A?.(),b.close(!1)),size:"large",children:r.jsx(f.CloseIcon,{})})}),r.jsx("div",{className:"flex-grow"}),Se&&r.jsx("div",{className:"self-center",children:r.jsx(f.CircularProgress,{size:"small"})}),r.jsxs(f.Tabs,{value:te.current,onValueChange:G=>{Ft(G)},className:"pl-4 pr-4 pt-0",children:[r.jsx(f.Tab,{disabled:!_,value:rr,className:`${_?"":"hidden"} text-sm min-w-[140px]`,children:l.singularName??l.name}),Tt,Qt]})]}),r.jsxs("div",{className:"flex-grow h-full flex overflow-auto flex-row w-full ",style:{},children:[r.jsx("div",{role:"tabpanel",hidden:!z,id:`form_${e}`,className:" w-full",children:Se?r.jsx(It,{}):Re}),ae,ze]})]})})}function ba(e,t){const[n,o]=c.useState(),{navigator:l}=c.useContext(fe.UNSAFE_NavigationContext),i=fe.useNavigate(),s=()=>{o(void 0)},a=()=>{t(),o(void 0),i(-1)},d=c.useCallback(({action:A,location:g,retry:p})=>{switch(A){case"REPLACE":{p();return}case"POP":o(g)}},[]);return c.useEffect(()=>{if(!e||n||!("block"in l))return;const A=l.block(g=>{const p={...g,retry(){A(),g.retry()}};d(p)});return A},[l,d,e,n]),{navigationWasBlocked:!!n,handleCancel:s,handleOk:a}}function ya({open:e,handleOk:t,handleCancel:n,body:o,title:l}){return r.jsxs(f.Dialog,{open:e,onOpenChange:i=>i?n():t(),children:[r.jsxs(f.DialogContent,{children:[r.jsx(f.Typography,{variant:"h6",children:l}),o,r.jsx(f.Typography,{children:"Are you sure you want to leave this page?"})]}),r.jsxs(f.DialogActions,{children:[r.jsx(f.Button,{variant:"text",onClick:n,autoFocus:!0,children:" Cancel "}),r.jsx(f.Button,{onClick:t,children:" Ok "})]})]})}const Al=c.createContext({width:"",blocked:!1,setBlocked:e=>{},setBlockedNavigationMessage:e=>{},close:()=>{}}),nr=()=>c.useContext(Al);function va(){const t=Bt().sidePanels,n=[...t];return n.push(void 0),r.jsx(r.Fragment,{children:n.map((o,l)=>r.jsx(wa,{panel:o,offsetPosition:t.length-l-1},`side_dialog_${l}`))})}function wa({offsetPosition:e,panel:t}){const[n,o]=c.useState(!1),[l,i]=c.useState(!1),[s,a]=c.useState(),d=c.useRef(t?.width),A=d.current,g=Bt(),{navigationWasBlocked:p,handleOk:h,handleCancel:u}=ba(l&&!n,()=>i(!1));c.useEffect(()=>{t&&(d.current=t.width)},[t]);const m=()=>{i(!1),o(!1),g.close(),t?.onClose?.()},b=()=>{o(!1)},y=w=>{l&&!w?o(!0):(g.close(),t?.onClose?.())};return r.jsxs(Al.Provider,{value:{blocked:l,setBlocked:i,setBlockedNavigationMessage:a,width:A,close:y},children:[r.jsxs(f.Sheet,{open:!!t,onOpenChange:w=>!w&&y(),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(ne,{children:t.component})}),!t&&r.jsx("div",{style:{width:A}})]}),r.jsx(ya,{open:p||n,handleOk:n?m:h,handleCancel:n?b:u,body:s})]})}function Ca(e){const{blocked:t,setBlocked:n,setBlockedNavigationMessage:o}=nr(),l=ie(),i=c.useMemo(()=>l.getParentCollectionIds(e.path),[l,e.path]),s=c.useMemo(()=>{if(!e)return;let d=e.collection;if(!d&&(d=l.getCollection(e.path,e.entityId),!d))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 d},[l,e]);c.useEffect(()=>{function d(A){t&&s&&(A.preventDefault(),A.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",d),()=>{typeof window<"u"&&window.removeEventListener("beforeunload",d)}},[t,s]);const a=c.useCallback(d=>{n(d),o(d?r.jsxs(r.Fragment,{children:[" You have unsaved changes in this ",r.jsx("b",{children:s?.singularName??s?.name}),"."]}):void 0)},[s?.name,n,o]);return!e||!s?r.jsx("div",{className:"w-full"}):r.jsx(r.Fragment,{children:r.jsx(ne,{children:r.jsx(ma,{...e,formWidth:e.width,collection:s,parentCollectionIds:i,onValuesAreModified:a})})})}const fl="new";function Ea(e,t){if(t)return ci;const n=!e.selectedSubPath,o=typeof e.width=="number"?`${e.width}px`:e.width;return n?o??Jn:`calc(${di} + ${o??Jn})`}const Ba=(e,t)=>{const n=fe.useLocation(),o=c.useRef(!1),l=!Te();c.useEffect(()=>{if(!e.loading&&!o.current){if(e.isUrlCollectionPath(n.pathname)){const d=n.hash===`#${fl}`,A=e.urlPathToDataPath(n.pathname),g=ka(A,e.collections,d);for(let p=0;p<g.length;p++){const h=g[p];setTimeout(()=>{p===0?t.replace(or(h,e,l)):t.open(or(h,e,l))},1)}}o.current=!0}},[n,e,t,l]);const i=c.useCallback(()=>{t.close()},[t]),s=c.useCallback(d=>{if(d.copy&&!d.entityId)throw Error("If you want to copy an entity you need to provide an entityId");const A=Br(d.collection?d.collection.defaultSelectedView:void 0,{status:d.copy?"copy":d.entityId?"existing":"new",entityId:d.entityId});t.open(or({selectedSubPath:A,...d},e,l))},[t,e,l]),a=c.useCallback(d=>{if(d.copy&&!d.entityId)throw Error("If you want to copy an entity you need to provide an entityId");t.replace(or(d,e,l))},[e,t,l]);return{close:i,open:s,replace:a}};function ka(e,t,n){const o=Cr({path:e,collections:t}),l=[];let i="";for(let s=0;s<o.length;s++){const a=o[s];if(a.type==="collection"&&(i=a.path),s>0){const d=o[s-1];if(a.type==="entity")l.push({path:a.path,entityId:a.entityId,copy:!1});else if(a.type==="custom_view"){if(d.type==="entity"){const A=l[l.length-1];A&&(A.selectedSubPath=a.view.key)}}else if(a.type==="collection"&&d.type==="entity"){const A=l[l.length-1];A&&(A.selectedSubPath=a.collection.id??a.collection.path)}}}return n&&l.push({path:i,copy:!1}),l}const or=(e,t,n)=>{const o=ue(e.path),l=e.entityId?t.buildUrlCollectionPath(`${o}/${e.entityId}/${e.selectedSubPath||""}`):t.buildUrlCollectionPath(`${o}#${fl}`);return{key:`${e.path}/${e.entityId}`,component:r.jsx(Ca,{...e}),urlPath:l,parentUrlPath:t.buildUrlCollectionPath(o),width:Ea(e,n),onClose:e.onClose}};function xa(){const e=fe.useLocation(),t=fe.useNavigate(),[n,o]=c.useState([]),l=c.useRef(n),i=c.useRef({}),s=c.useRef(0),a=p=>{l.current=p,o(p)};c.useEffect(()=>{const u=(e.state?.panels??[]).map(m=>i.current[m]).filter(m=>!!m);oe(l.current.map(m=>m.key),u.map(m=>m.key))||a(u)},[e]);const d=c.useCallback(()=>{if(n.length===0)return;const p=n[n.length-1],h=[...n.slice(0,-1)];if(a(h),s.current>0)p.urlPath&&t(-1),s.current--;else if(p.parentUrlPath){const u=e.state?.base_location??e;t(p.parentUrlPath,{replace:!0,state:{base_location:u,panels:h.map(m=>m.key)}})}},[n,t,e]),A=c.useCallback(p=>{const h=Array.isArray(p)?p:[p];h.forEach(b=>{i.current[b.key]=b}),s.current=s.current+h.length;const u=e.state?.base_location??e,m=[...n,...h];a(m),h.forEach(b=>{b.urlPath&&t(b.urlPath,{state:{base_location:u,panels:m.map(y=>y.key)}})})},[e,t,n]),g=c.useCallback(p=>{const h=Array.isArray(p)?p:[p];h.forEach(b=>{i.current[b.key]=b});const u=e.state?.base_location??e,m=[...n.slice(0,-h.length),...h];a(m),h.forEach(b=>{b.urlPath&&t(b.urlPath,{replace:!0,state:{base_location:u,panels:m.map(y=>y.key)}})})},[e,t,n]);return{sidePanels:n,close:d,open:A,replace:g}}function Ia(e){c.useEffect(()=>{if(!e)return;const t=En[e];t&&(Cn.registerLocale(e,t),Cn.setDefaultLocale(e))},[e])}function ul(e){const{path:t,collections:n=[],currentFullPath:o}=e,l=ue(t).split("/"),i=Vt(l),s=[];for(let a=0;a<i.length;a++){const d=i[a],A=n&&n.find(g=>g.id===d||g.path===d);if(A){const g=A.id??A.path,p=o&&o.length>0?o+"/"+g:g,h=ue(ue(t).replace(d,"")),u=h.length>0?h.split("/"):[];if(u.length>0){const m=u[0],b=p+"/"+m;if(s.push(new Fe(m,p)),u.length>1){const y=u.slice(1).join("/");if(!A)throw Error("collection not found resolving path: "+A);A.subcollections&&s.push(...ul({path:y,collections:A.subcollections,currentFullPath:b}))}}break}}return s}const Sa="/",Fa="/c";function Na({basePath:e=Sa,baseCollectionPath:t=Fa,authController:n,collections:o,views:l,userConfigPersistence:i,plugins:s,dataSource:a}){const d=fe.useLocation(),[A,g]=c.useState(),[p,h]=c.useState(),[u,m]=c.useState(!1),[b,y]=c.useState(void 0),[w,C]=c.useState(!0),[E,B]=c.useState(void 0),I=ue(e),x=ue(t),k=I?`/${I}`:"/",S=I?`/${I}/${x}`:`/${x}`,F=c.useCallback(U=>I?`/${I}/${lr(U)}`:`/${lr(U)}`,[I]),P=c.useCallback(U=>`${ue(t)}/${lr(U)}`,[t]),N=c.useCallback((U,M)=>{const $=[...(U??[]).map(L=>L.hideFromNavigation?void 0:{url:P(L.id??L.path),type:"collection",name:L.name.trim(),path:L.id??L.path,collection:L,description:L.description?.trim(),group:L.group?.trim()}).filter(Boolean),...(M??[]).map(L=>L.hideFromNavigation?void 0:{url:F(Array.isArray(L.path)?L.path[0]:L.path),name:L.name.trim(),type:"view",view:L,description:L.description?.trim(),group:L.group?.trim()}).filter(Boolean)],K=Object.values($).map(L=>L.group).filter(Boolean).filter((L,Q,D)=>D.indexOf(L)===Q);return{navigationEntries:$,groups:K}},[F,P]),T=c.useCallback(async()=>{if(!n.initialLoading){try{const[U=[],M=[]]=await Promise.all([Pa(o,n,a,s),Qa(l,n,a)]);g(U),h(M),y(N(U??[],M))}catch(U){console.error(U),B(U)}C(!1),m(!0)}},[o,n.user,n.initialLoading,s,l,N]);c.useEffect(()=>{T()},[T]);const Y=c.useCallback((U,M,$=!1)=>{if(!A)return;const K=Ot(ue(U),A),L=$?i?.getCollectionConfig(U):void 0,Q=K?Ne(K,L):void 0;let D=Q;if(Q){const Ie=Q.subcollections,Ae=Q.callbacks,ae=Q.permissions;D={...D,subcollections:D?.subcollections??Ie,callbacks:D?.callbacks??Ae,permissions:D?.permissions??ae}}if(D)return{...Q,...D}},[e,t,A]),H=c.useCallback(U=>{let M=A;if(!M)throw Error("Collections have not been initialised yet");for(let $=0;$<U.length;$++){const K=U[$],L=M.find(Q=>Q.id===K||Q.path===K);if(!L)return;if(M=L.subcollections,$===U.length-1)return L}},[A]),_=c.useCallback(U=>{let M=A;if(!M)throw Error("Collections have not been initialised yet");for(let $=0;$<U.length;$++){const K=U[$],L=M.find(Q=>Q.id===K);if(!L)return;if(M=L.subcollections,$===U.length-1)return L}},[A]),X=c.useCallback(U=>ue(U+"/").startsWith(ue(S)+"/"),[S]),te=c.useCallback(U=>{if(U.startsWith(S))return U.replace(S,"");throw Error("Expected path starting with "+S)},[S]),z=c.useCallback(({path:U})=>`s/edit/${lr(U)}`,[]),V=c.useCallback(U=>{if(!A)throw Error("Collections have not been initialised yet");return fr(U,A)},[A]),re=d.state,W=re&&re.base_location?re.base_location:d,J=c.useCallback(U=>ul({path:U,collections:A}),[A]),se=c.useCallback(U=>J(U).map(M=>M.id),[J]);return c.useMemo(()=>({collections:A??[],views:p??[],loading:!u||w,navigationLoadingError:E,homeUrl:k,basePath:e,baseCollectionPath:t,initialised:u,getCollection:Y,getCollectionFromPaths:H,getCollectionFromIds:_,isUrlCollectionPath:X,urlPathToDataPath:te,buildUrlCollectionPath:P,buildUrlEditCollectionPath:z,buildCMSUrlPath:F,resolveAliasesFrom:V,topLevelNavigation:b,baseLocation:W,refreshNavigation:T,getParentReferencesFromPath:J,getParentCollectionIds:se}),[t,W,e,F,P,z,A,J,Y,H,k,u,X,w,E,T,V,b,te,p])}function lr(e){return encodeURIComponent(ue(e)).replaceAll("%2F","/").replaceAll("%23","#")}function gl(e,t){return e.filter(n=>n.permissions?Et(n,t,[n.path],null).read!==!1:!0).map(n=>n.subcollections?{...n,subcollections:gl(n.subcollections,t)}:n)}async function Pa(e,t,n,o){let l=[];return typeof e=="function"?l=await e({user:t.user,authController:t,dataSource:n}):Array.isArray(e)&&(l=e),l=gl(l,t),o&&o.forEach(i=>{i.collections?.injectCollections&&(l=i.collections?.injectCollections(l??[]))}),l}async function Qa(e,t,n){let o=[];return typeof e=="function"?o=await e({user:t.user,authController:t,dataSource:n}):Array.isArray(e)&&(o=e),o}function Ta({delegate:e,propertyConfigs:t,navigationController:n}){return{fetchCollection:c.useCallback(({path:o,collection:l,filter:i,limit:s,startAfter:a,searchString:d,orderBy:A,order:g})=>e.fetchCollection({path:o,filter:i,limit:s,startAfter:a,searchString:d,orderBy:A,order:g}),[e]),listenCollection:e.listenCollection?c.useCallback(({path:o,collection:l,filter:i,limit:s,startAfter:a,searchString:d,orderBy:A,order:g,onUpdate:p,onError:h})=>{const m=!!(l??n.getCollection(o))?.collectionGroup;if(!e.listenCollection)throw Error("useBuildDataSource delegate not initialised");return e.listenCollection({path:o,filter:i,limit:s,startAfter:a,searchString:d,orderBy:A,order:g,onUpdate:p,onError:h,isCollectionGroup:m})},[e,n.getCollection]):void 0,fetchEntity:c.useCallback(({path:o,entityId:l})=>e.fetchEntity({path:o,entityId:l}),[e]),listenEntity:e.listenEntity?c.useCallback(({path:o,entityId:l,collection:i,onUpdate:s,onError:a})=>{if(!e.listenEntity)throw Error("useBuildDataSource delegate not initialised");return e.listenEntity({path:o,entityId:l,onUpdate:s,onError:a})},[e.listenEntity]):void 0,saveEntity:c.useCallback(({path:o,entityId:l,values:i,collection:s,status:a})=>{const d=s??n.getCollection(o),g=(d?ke({collection:d,path:o,entityId:l,fields:t}):void 0)?.properties,p=hn(i,e.buildReference,e.buildGeoPoint,e.buildDate,e.buildDeleteFieldValue),h=g?Sn({inputValues:p,properties:g,status:a,timestampNowValue:e.currentTime(),setDateToMidnight:e.setDateToMidnight}):p;return console.debug("Saving entity",o,l,h),e.saveEntity({path:o,entityId:l,values:h,status:a}).then(u=>({id:u.id,path:u.path,values:e.delegateToCMSModel(h)}))},[e.saveEntity,n.getCollection]),deleteEntity:c.useCallback(({entity:o})=>e.deleteEntity({entity:o}),[e.deleteEntity]),checkUniqueField:c.useCallback((o,l,i,s)=>e.checkUniqueField(o,l,i,s),[e.checkUniqueField]),generateEntityId:c.useCallback(o=>e.generateEntityId(o),[e.generateEntityId]),countEntities:c.useCallback(async({path:o,collection:l,filter:i,order:s,orderBy:a})=>e.countEntities({path:o,filter:i,orderBy:a,order:s,isCollectionGroup:!!l.collectionGroup}),[e.countEntities]),isFilterCombinationValid:c.useCallback(({path:o,filterValues:l,sortBy:i})=>e.isFilterCombinationValid?e.isFilterCombinationValid({path:o,filterValues:l,sortBy:i}):!0,[e.isFilterCombinationValid])}}function hn(e,t,n,o,l){return e===void 0?l():Array.isArray(e)?e.map(i=>hn(i,t,n,o,l)):e instanceof Fe?t(e):e instanceof Gt?n(e):e instanceof Date?o(e):e&&typeof e=="object"?Object.entries(e).map(([i,s])=>({[i]:hn(s,t,n,o,l)})).reduce((i,s)=>({...i,...s}),{}):e}function Ma(e){const t=Mr(),{children:n,entityLinkBuilder:o,userConfigPersistence:l,dateTimeFormat:i,locale:s,authController:a,storageSource:d,dataSourceDelegate:A,plugins:g,onAnalyticsEvent:p,propertyConfigs:h,entityViews:u,components:m,baseCollectionPath:b,basePath:y,collections:w,views:C}=e;Ia(s);const E=Na({basePath:y,baseCollectionPath:b,authController:a,collections:w,views:C,userConfigPersistence:l,dataSource:A,plugins:g}),B=Ta({delegate:A,propertyConfigs:h,navigationController:E}),I=xa(),x=Ba(E,I),k=g?.some(P=>P.loading)??!1,S=a.initialLoading||E.loading||k,F=c.useMemo(()=>({entityLinkBuilder:o,dateTimeFormat:i,locale:s,plugins:g,onAnalyticsEvent:p,entityViews:u??[],propertyConfigs:h??{},components:m}),[i,s,g,u,h,m]);return E.navigationLoadingError?r.jsx(f.CenteredView,{maxWidth:"md",fullScreen:!0,children:r.jsx(pe,{title:"Error loading navigation",error:E.navigationLoadingError})}):a.authError?r.jsx(f.CenteredView,{maxWidth:"md",fullScreen:!0,children:r.jsx(pe,{title:"Error loading auth",error:a.authError})}):r.jsx(Dt.Provider,{value:t,children:r.jsx(Nr.Provider,{value:F,children:r.jsx(eo.Provider,{value:l,children:r.jsx(Rn.Provider,{value:d,children:r.jsx(qn.Provider,{value:B,children:r.jsx(Ar.Provider,{value:a,children:r.jsx(Xn.Provider,{value:I,children:r.jsx(Kn.Provider,{value:x,children:r.jsx(Zn.Provider,{value:E,children:r.jsx(Ai,{children:r.jsx(Da,{loading:S,children:n})})})})})})})})})})})}function Da({loading:e,children:t}){const n=Z();let o=t({context:n,loading:e});const l=n.plugins;return!e&&l&&l.forEach(i=>{i.provider&&(o=r.jsx(i.provider.Component,{...i.provider.props,context:n,children:o}))}),r.jsx(r.Fragment,{children:o})}function hl({hovered:e,drawerOpen:t,closeDrawer:n}){const o=Z(),l=ie(),i=e&&!t,s=Te();if(!l.topLevelNavigation)throw Error("Navigation not ready in Drawer");const{navigationEntries:a,groups:d}=l.topLevelNavigation,A=Object.values(a).filter(h=>!h.group),g=c.useCallback(h=>t?r.jsx("div",{className:"pt-8 pl-6 pr-8 pb-2 flex flex-row items-center",children:r.jsx(f.Typography,{variant:"caption",color:"secondary",className:"font-medium flex-grow",children:h?h.toUpperCase():"Views".toUpperCase()})}):r.jsx("div",{className:"h-4"}),[t]),p=h=>{const u=h.type==="collection"?"drawer_navigate_to_collection":h.type==="view"?"drawer_navigate_to_view":"unmapped_event";o.onAnalyticsEvent?.(u,{url:h.url}),s||n()};return r.jsxs("div",{className:"flex-grow overflow-scroll no-scrollbar",children:[d.map(h=>r.jsxs(c.Fragment,{children:[g(h),Object.values(a).filter(u=>u.group===h).map((u,m)=>r.jsx(pn,{icon:qt(u.collection??u.view),tooltipsOpen:i,drawerOpen:t,onClick:()=>p(u),url:u.url,name:u.name},`navigation_${m}`))]},`drawer_group_${h}`)),A.length>0&&g(),A.map((h,u)=>r.jsx(pn,{icon:qt(h.collection??h.view),tooltipsOpen:i,onClick:()=>p(h),drawerOpen:t,url:h.url,name:h.name},`navigation_${u}`))]})}function pn({name:e,icon:t,drawerOpen:n,tooltipsOpen:o,url:l,onClick:i}){const s=r.jsx("div",{className:"text-gray-600 dark:text-gray-500",children:t}),a=r.jsxs(fe.NavLink,{onClick:i,className:({isActive:d})=>f.cn("rounded-r-xl truncate","hover:bg-gray-200 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-gray-100","flex flex-row items-center w-full mr-8",n?"pl-8 h-12":"pl-6 h-11","font-medium text-sm",d?"bg-gray-100 dark:bg-gray-800":""),to:l,children:[s,r.jsx("div",{className:f.cn(n?"opacity-100":"opacity-0 hidden","ml-4 font-inherit text-inherit"),children:e.toUpperCase()})]});return n?a:r.jsx(f.Tooltip,{open:o,side:"right",title:e,children:a})}const Oa=280,Va=c.memo(function(t){const{children:n,name:o,logo:l,includeDrawer:i=!0,autoOpenDrawer:s,Drawer:a=hl,drawerProps:d,FireCMSAppBarComponent:A=cl,fireCMSAppBarComponentProps:g}=t,p=Te(),h=ie(),[u,m]=c.useState(!1),[b,y]=c.useState(!1),w=c.useCallback(()=>y(!0),[]),C=c.useCallback(()=>y(!1),[]),E=c.useCallback(()=>{m(!1)},[]),B=u||!!(p&&s&&b);return r.jsxs("div",{className:"flex h-screen w-screen bg-gray-50 dark:bg-gray-900 text-gray-900 dark:text-white overflow-hidden",style:{paddingTop:"env(safe-area-inset-top)",paddingLeft:"env(safe-area-inset-left)",paddingRight:"env(safe-area-inset-right)",paddingBottom:"env(safe-area-inset-bottom)",height:"100dvh"},children:[r.jsx(A,{title:o,includeDrawer:i,drawerOpen:B,...g}),r.jsx(Ya,{displayed:i,onMouseEnter:w,onMouseMove:w,onMouseLeave:C,open:B,logo:l,hovered:b,setDrawerOpen:m,children:i&&(h.loading?r.jsx(It,{}):r.jsx(a,{hovered:b,drawerOpen:B,closeDrawer:E,...d}))}),r.jsxs("main",{className:"flex flex-col flex-grow overflow-auto",children:[r.jsx(Ga,{}),r.jsx("div",{className:f.cn(f.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(ne,{children:n})})]})]})},oe),Ga=()=>r.jsx("div",{className:"flex flex-col min-h-[68px]"});function Ya(e){const t=ie(),n=e.displayed?e.open?Oa:72:0,o=r.jsxs("div",{className:"relative h-full no-scrollbar overflow-y-auto overflow-x-hidden",style:{width:n,transition:"left 150ms cubic-bezier(0.4, 0, 0.6, 1) 0ms, opacity 150ms cubic-bezier(0.4, 0, 0.6, 1) 0ms, width 150ms cubic-bezier(0.4, 0, 0.6, 1) 0ms"},children:[!e.open&&e.displayed&&r.jsx(f.Tooltip,{title:"Open menu",side:"right",sideOffset:12,className:"fixed top-2 left-3 !bg-gray-50 dark:!bg-gray-900 rounded-full w-fit",children:r.jsx(f.IconButton,{color:"inherit","aria-label":"Open menu",className:"sticky top-2 left-3 ",onClick:()=>e.setDrawerOpen(!0),size:"large",children:r.jsx(f.MenuIcon,{})})}),r.jsxs("div",{className:"flex flex-col h-full",children:[r.jsx("div",{style:{transition:"padding 150ms cubic-bezier(0.4, 0, 0.6, 1) 0ms",padding:e.open?"32px 96px 0px 24px":"72px 16px 0px"},className:f.cn("cursor-pointer"),children:r.jsx(f.Tooltip,{title:"Home",sideOffset:20,side:"right",children:r.jsx(fe.Link,{to:t.basePath,children:e.logo?r.jsx("img",{src:e.logo,alt:"Logo",className:f.cn("max-w-full max-h-full",e.open??"w-[160px] h-[160px]")}):r.jsx(al,{})})})}),e.children]})]});return Te()?r.jsxs("div",{className:"relative",onMouseEnter:e.onMouseEnter,onMouseMove:e.onMouseMove,onMouseLeave:e.onMouseLeave,style:{width:n,transition:"left 150ms cubic-bezier(0.4, 0, 0.6, 1) 0ms, opacity 150ms cubic-bezier(0.4, 0, 0.6, 1) 0ms, width 150ms cubic-bezier(0.4, 0, 0.6, 1) 0ms"},children:[o,r.jsx("div",{className:`absolute right-0 top-4 ${e.open?"opacity-100":"opacity-0 invisible"} transition-opacity duration-1000 ease-in-out`,children:r.jsx(f.IconButton,{"aria-label":"Close drawer",onClick:()=>e.setDrawerOpen(!1),children:r.jsx(f.ChevronLeftIcon,{})})})]}):e.displayed?r.jsxs(r.Fragment,{children:[r.jsx(f.IconButton,{color:"inherit","aria-label":"Open drawer",onClick:()=>e.setDrawerOpen(!0),size:"large",className:"absolute top-2 left-6",children:r.jsx(f.MenuIcon,{})}),r.jsx(f.Sheet,{side:"left",transparent:!0,open:e.open,onOpenChange:e.setDrawerOpen,children:o})]}):null}function pl(e){return Object.keys(ir).includes(e)}const ir={text_field:{key:"text_field",name:"Text field",description:"Simple short text",Icon:f.ShortTextIcon,color:"#2d7ff9",property:{dataType:"string",Field:ht}},multiline:{key:"multiline",name:"Multiline",description:"Text with multiple lines",Icon:f.SubjectIcon,color:"#2d7ff9",property:{dataType:"string",multiline:!0,Field:ht}},markdown:{key:"markdown",name:"Markdown",description:"Text with advanced markdown syntax",Icon:f.FormatQuoteIcon,color:"#2d7ff9",property:{dataType:"string",markdown:!0,Field:Xo}},url:{key:"url",name:"Url",description:"Text with URL validation",Icon:f.HttpIcon,color:"#154fb3",property:{dataType:"string",url:!0,Field:ht}},email:{key:"email",name:"Email",description:"Text with email validation",Icon:f.EmailIcon,color:"#154fb3",property:{dataType:"string",email:!0,Field:ht}},select:{key:"select",name:"Select/enum",description:"Select one text value from within an enumeration",Icon:f.ListIcon,color:"#4223c9",property:{dataType:"string",enumValues:[],Field:tn}},multi_select:{key:"multi_select",name:"Multi select",description:"Select multiple text values from within an enumeration",Icon:f.ListAltIcon,color:"#4223c9",property:{dataType:"array",of:{dataType:"string",enumValues:[]},Field:rn}},number_input:{key:"number_input",name:"Number input",description:"Simple number field with validation",Icon:f.NumbersIcon,color:"#bec920",property:{dataType:"number",Field:ht}},number_select:{key:"number_select",name:"Number select",description:"Select a number value from within an enumeration",Icon:f.FormatListNumberedIcon,color:"#bec920",property:{dataType:"number",enumValues:[],Field:tn}},multi_number_select:{key:"multi_number_select",name:"Multiple number select",description:"Select multiple number values from within an enumeration",Icon:f.FormatListNumberedIcon,color:"#bec920",property:{dataType:"array",of:{dataType:"number",enumValues:[]},Field:rn}},file_upload:{key:"file_upload",name:"File upload",description:"Input for uploading single files",Icon:f.UploadFileIcon,color:"#f92d9a",property:{dataType:"string",storage:{storagePath:"{path}"},Field:nn}},multi_file_upload:{key:"multi_file_upload",name:"Multiple file upload",description:"Input for uploading multiple files",Icon:f.DriveFolderUploadIcon,color:"#f92d9a",property:{dataType:"array",of:{dataType:"string",storage:{storagePath:"{path}"}},Field:nn}},reference:{key:"reference",name:"Reference",description:"The value refers to a different collection",Icon:f.LinkIcon,color:"#ff0042",property:{dataType:"reference",Field:jo}},multi_references:{key:"multi_references",name:"Multiple references",description:"Multiple values that refer to a different collection",Icon:f.AddLinkIcon,color:"#ff0042",property:{dataType:"array",of:{dataType:"reference"},Field:Lo}},switch:{key:"switch",name:"Switch",description:"Boolean true or false field (or yes or no, 0 or 1...)",Icon:f.FlagIcon,color:"#20d9d2",property:{dataType:"boolean",Field:_o}},date_time:{key:"date_time",name:"Date/time",description:"A date time select field",Icon:f.ScheduleIcon,color:"#8b46ff",property:{dataType:"date",Field:Wo}},group:{key:"group",name:"Group",description:"Group of multiple fields",Icon:f.BallotIcon,color:"#ff9408",property:{dataType:"map",properties:{},Field:Ho}},key_value:{key:"key_value",name:"Key-value",description:"Flexible field that allows the user to add multiple key-value pairs",Icon:f.BallotIcon,color:"#ff9408",property:{dataType:"map",keyValue:!0,Field:Jo}},repeat:{key:"repeat",name:"Repeat/list",description:"A field that gets repeated multiple times (e.g. multiple text fields)",Icon:f.RepeatIcon,color:"#ff9408",property:{dataType:"array",of:{dataType:"string"},Field:qo}},custom_array:{key:"custom_array",name:"Custom array",description:"A field that saved its value as an array of custom objects",Icon:f.RepeatIcon,color:"#ff9408",property:{dataType:"array",of:[],Field:Ko}},block:{key:"block",name:"Block",description:"A complex field that allows the user to compose different fields together, with a key->value format",Icon:f.ViewStreamIcon,color:"#ff9408",property:{dataType:"array",oneOf:{properties:{}},Field:Zo}}};function ml(e){const t=ar(e);if(!t){console.error("No field id found for property",e);return}return ir[t]}function sr(e,t){const n=mn(e),o=ar(e);if(!o){console.error("No field id found for property",e);return}const l=ir[o],i=n?t[n]:void 0;return Ne(l??{},i??{})}function ar(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"){if(e.keyValue)return"key_value";if(e.properties)return"group"}else if(e.dataType==="array"){const t=e.of;return e.oneOf?"block":Array.isArray(t)?"custom_array":ve(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 mn(e){return e.propertyConfig?e.propertyConfig:ar(e)}const za=c.memo(function({HomePage:t=il,customRoutes:n}){const o=fe.useLocation(),l=ie();if(!l)return r.jsx(r.Fragment,{});const i=o.state,s=i&&i.base_location?i.base_location:o,a=[];l.views&&l.views.forEach(h=>{Array.isArray(h.path)?a.push(...h.path.map(u=>bl(u,h))):a.push(bl(h.path,h))});const A=[...l.collections??[]].sort((h,u)=>u.path.length-h.path.length).map(h=>{const u=l.buildUrlCollectionPath(h.id??h.path);return r.jsx(fe.Route,{path:u+"/*",element:r.jsx(cn,{isSubCollection:!1,parentCollectionIds:[],fullPath:h.id??h.path,...h,Actions:Rt(h.Actions)},`collection_view_${h.id??h.path}`)},`navigation_${h.id??h.path}`)}),g=r.jsx(fe.Route,{path:"/",element:r.jsx(t,{})}),p=r.jsx(fe.Route,{path:"*",element:r.jsx(sl,{})});return r.jsxs(fe.Routes,{location:s,children:[A,a,g,p,n]})}),bl=(e,t)=>r.jsx(fe.Route,{path:e,element:t.view},"navigation_view_"+e);function Ua(){const e=typeof window<"u"&&window.matchMedia("(prefers-color-scheme: dark)"),n=(localStorage.getItem("prefers-dark-mode")!=null?localStorage.getItem("prefers-dark-mode")==="true":null)??e,[o,l]=c.useState(n?"dark":"light");c.useEffect(()=>{l(n?"dark":"light"),a(n?"dark":"light")},[n]);const i=c.useCallback(()=>{l("dark"),a("dark")},[e]),s=c.useCallback(()=>{l("light"),a("light")},[]),a=A=>{document.body.style.setProperty("color-scheme",A),document.documentElement.dataset.theme=A},d=c.useCallback(()=>{o==="light"?(e?localStorage.removeItem("prefers-dark-mode"):localStorage.setItem("prefers-dark-mode","true"),i()):(e?localStorage.setItem("prefers-dark-mode","false"):localStorage.removeItem("prefers-dark-mode"),s())},[o,e]);return{mode:o,setMode:l,toggleMode:d}}function La(){const[e,t]=c.useState({}),n=c.useCallback(m=>{const b=localStorage.getItem(m);return b?JSON.parse(b):{}},[]),o=c.useCallback(m=>{const b=`collection_config::${kr(m)}`;return e[b]?e[b]:n(b)},[e,n]),l=c.useCallback((m,b)=>{const y=`collection_config::${kr(m)}`;localStorage.setItem(y,JSON.stringify(b)),t(w=>{const C=w[y],E=Ne(C??n(m),b);return Ne(w,E)})},[n]),[i,s]=c.useState([]),[a,d]=c.useState([]),[A,g]=c.useState([]);c.useEffect(()=>{s(localStorage.getItem("recently_visited_paths")?JSON.parse(localStorage.getItem("recently_visited_paths")):[]),d(localStorage.getItem("favourite_paths")?JSON.parse(localStorage.getItem("favourite_paths")):[]),g(localStorage.getItem("collapsed_groups")?JSON.parse(localStorage.getItem("collapsed_groups")):[])},[]);const p=c.useCallback(m=>{localStorage.setItem("recently_visited_paths",JSON.stringify(m)),s(m)},[]),h=c.useCallback(m=>{localStorage.setItem("favourite_paths",JSON.stringify(m)),d(m)},[]),u=c.useCallback(m=>{localStorage.setItem("collapsed_groups",JSON.stringify(m)),g(m)},[]);return{onCollectionModified:l,getCollectionConfig:o,recentlyVisitedPaths:i,setRecentlyVisitedPaths:p,favouritePaths:a,setFavouritePaths:h,collapsedGroups:A,setCollapsedGroups:u}}v.ArrayContainer=un,v.ArrayContainerItem=gn,v.ArrayCustomShapedFieldBinding=Ko,v.ArrayEnumPreview=zr,v.ArrayItemOptions=dl,v.ArrayOfMapsPreview=Pi,v.ArrayOfReferencesFieldBinding=Lo,v.ArrayOfReferencesPreview=uo,v.ArrayOfStorageComponentsPreview=go,v.ArrayOfStringsPreview=ho,v.ArrayOneOfPreview=po,v.ArrayPropertyEnumPreview=Ur,v.ArrayPropertyPreview=Yr,v.AsyncPreviewComponent=Qi,v.AuthControllerContext=Ar,v.BlockFieldBinding=Zo,v.BooleanPreview=yo,v.COLLECTION_PATH_SEPARATOR=Mn,v.CircularProgressCenter=It,v.DEFAULT_FIELD_CONFIGS=ir,v.DatePreview=bo,v.DateTimeFieldBinding=Wo,v.DefaultHomePage=il,v.DeleteConfirmationDialog=Aa,v.Drawer=hl,v.DrawerNavigationItem=pn,v.EmptyValue=At,v.EntityCollectionTable=Rr,v.EntityCollectionView=cn,v.EntityForm=rl,v.EntityPreview=$r,v.EntityReference=Fe,v.EnumValuesChip=we,v.ErrorBoundary=ne,v.ErrorView=pe,v.FieldConfigBadge=da,v.FieldHelperText=be,v.FireCMS=Ma,v.FireCMSAppBar=cl,v.FireCMSContextInstance=Nr,v.FireCMSLogo=al,v.FormikArrayContainer=er,v.GeoPoint=Gt,v.ImagePreview=so,v.KeyValueFieldBinding=Jo,v.KeyValuePreview=Lr,v.LabelWithIcon=ye,v.MapFieldBinding=Ho,v.MapPropertyPreview=mo,v.MarkdownFieldBinding=Xo,v.ModeControllerContext=Dt,v.ModeControllerProvider=Ql,v.MultiSelectBinding=rn,v.NavigationCollectionCard=ll,v.NavigationGroup=An,v.NavigationRoutes=za,v.NotFoundPage=sl,v.NumberPropertyPreview=vo,v.PropertyFieldBinding=nt,v.PropertyPreview=me,v.ReadOnlyFieldBinding=on,v.ReferenceFieldBinding=jo,v.ReferencePreview=De,v.ReferencePreviewContainer=Xt,v.ReferenceSelectionInner=ol,v.ReferenceWidget=ga,v.RepeatFieldBinding=qo,v.Scaffold=Va,v.SelectFieldBinding=tn,v.SideDialogs=va,v.SkeletonPropertyComponent=ut,v.SnackbarProvider=Nl,v.StorageThumbnail=ao,v.StorageThumbnailInternal=Ao,v.StorageUploadFieldBinding=nn,v.StringPropertyPreview=Gr,v.SwitchControl=Ps,v.SwitchFieldBinding=_o,v.TextFieldBinding=ht,v.UrlComponentPreview=kt,v.VirtualTable=Po,v.addInitialSlash=Ml,v.buildAdditionalFieldDelegate=si,v.buildCollection=ei,v.buildEntityCallbacks=ii,v.buildEnumLabel=Qn,v.buildEnumValueConfig=li,v.buildEnumValues=oi,v.buildFieldConfig=ai,v.buildProperties=ri,v.buildPropertiesOrBuilder=ni,v.buildProperty=ti,v.canCreateEntity=at,v.canDeleteEntity=Jt,v.canEditEntity=Ir,v.defaultDateFormat=Tn,v.deleteEntityWithCallbacks=no,v.enumToObjectEntries=_e,v.flattenObject=Sr,v.fullPathToCollectionSegments=Pe,v.getArrayValuesCount=Un,v.getBracketNotation=Zl,v.getCollectionByPathOrAlias=Ot,v.getCollectionPathsCombinations=Vt,v.getColorForProperty=ql,v.getColorScheme=Pn,v.getDefaultFieldConfig=ml,v.getDefaultFieldId=ar,v.getDefaultPropertiesOrder=Xl,v.getDefaultValueFor=Ut,v.getDefaultValueForDataType=mr,v.getDefaultValuesFor=Ct,v.getFieldConfig=sr,v.getFieldId=mn,v.getHashValue=gr,v.getIcon=Yn,v.getIconForProperty=he,v.getIconForView=qt,v.getIconForWidget=jt,v.getIdIcon=Jl,v.getLabelOrConfigFrom=$t,v.getLastSegment=Dl,v.getPropertiesWithPropertiesOrder=Gn,v.getPropertyInPath=tt,v.getRandomId=St,v.getReferenceFrom=Ge,v.getReferencePreviewKeys=zn,v.getResolvedPropertyInPath=xr,v.getValueInPath=$e,v.hydrateRegExp=On,v.isDefaultFieldConfigId=pl,v.isEmptyObject=pr,v.isEnumValueDisabled=Gl,v.isHidden=wt,v.isObject=Yt,v.isPropertyBuilder=ve,v.isReadOnly=it,v.isReferenceProperty=Vn,v.isValidRegExp=jl,v.joinCollectionLists=_n,v.makePropertiesEditable=Ln,v.makePropertiesNonEditable=$n,v.mergeCollection=Wn,v.mergeDeep=Ne,v.pick=xn,v.plural=Kl,v.randomColor=_l,v.randomString=st,v.removeFunctions=ur,v.removeInPath=Ol,v.removeInitialAndTrailingSlashes=ue,v.removeInitialSlash=Bn,v.removePropsIfExisting=In,v.removeTrailingSlash=kn,v.removeUndefined=hr,v.renderSkeletonCaptionText=ki,v.renderSkeletonIcon=Vr,v.renderSkeletonImageThumbnail=Or,v.renderSkeletonText=Ye,v.resolveArrayProperty=We,v.resolveCollection=ke,v.resolveCollectionPathAliases=fr,v.resolveDefaultSelectedView=Br,v.resolveEntityView=wr,v.resolveEnumValues=Yl,v.resolveNavigationFrom=oo,v.resolvePermissions=Et,v.resolveProperties=yr,v.resolveProperty=Be,v.resolvePropertyEnum=vr,v.sanitizeData=Vl,v.saveEntityWithCallbacks=Tr,v.segmentsToStrippedPath=Dn,v.serializeRegExp=Wl,v.singular=Rl,v.slugify=_t,v.sortProperties=Er,v.stripCollectionPath=kr,v.toKebabCase=Ul,v.toSnakeCase=$l,v.traverseValueProperty=Lt,v.traverseValuesProperties=br,v.unslugify=Tl,v.updateDateAutoValues=Sn,v.useAuthController=je,v.useBrowserTitleAndIcon=pa,v.useBuildLocalConfigurationPersistence=La,v.useBuildModeController=Ua,v.useClearRestoreValue=xe,v.useClipboard=lo,v.useCollectionFetch=ro,v.useDataSource=Qe,v.useDebounce=Wt,v.useDebounceValue=Hl,v.useEntityCollectionTableController=en,v.useEntityFetch=Qr,v.useFireCMSContext=Z,v.useLargeLayout=Te,v.useModeController=Mr,v.useNavigationController=ie,v.useReferenceDialog=mt,v.useResolvedNavigationFrom=ui,v.useSelectionController=dn,v.useSideDialogContext=nr,v.useSideDialogsController=Bt,v.useSideEntityController=He,v.useSnackbarController=Je,v.useStorageSource=ct,Object.keys(f).forEach(e=>{e!=="default"&&!Object.prototype.hasOwnProperty.call(v,e)&&Object.defineProperty(v,e,{enumerable:!0,get:()=>f[e]})}),Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})});
587
+ `;function Ko({propertyKey:e,value:t,error:n,showError:o,isSubmitting:l,setValue:i,tableMode:s,property:a,includeDescription:c,underlyingValueHasChanged:f,context:g,disabled:p}){if(q(),!Array.isArray(a.resolvedProperties))throw Error("ArrayCustomShapedFieldBinding misconfiguration. Property `of` not set");const h=a.expanded===void 0?!0:a.expanded;Se({property:a,value:t,setValue:i});const u=r.jsx(ve,{icon:pe(a,"small"),required:a.validation?.required,className:"text-text-secondary dark:text-text-secondary-dark",title:a.name}),m=a.resolvedProperties.map((b,y)=>{const C={propertyKey:`${e}[${y}]`,disabled:p,property:b,includeDescription:c,underlyingValueHasChanged:f,context:g,tableMode:!1,partOfArray:!0,partOfBlock:!1,autoFocus:!1};return r.jsx("div",{className:"pb-4",children:r.jsx(nt,{...C})},`custom_shaped_array_${y}`)});return r.jsxs(r.Fragment,{children:[!s&&r.jsx(A.ExpandablePanel,{initiallyExpanded:h,title:u,className:"px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2",children:m}),s&&m,r.jsx(ye,{includeDescription:c,showError:o,error:n,disabled:p,property:a})]})}const qs=({containerRef:e})=>{const{isSubmitting:t,isValidating:n,errors:o}=Be.useFormikContext();return d.useEffect(()=>{const l=Object.keys(o);if(l.length>0&&t&&!n){const i=e?.current?.querySelector(`#form_field_${l[0]}`);if(i&&e?.current){const s=Ro(e.current);if(s){const c=i.getBoundingClientRect().top;s.scrollTo({top:s.scrollTop+c-64,behavior:"smooth"})}const a=i.querySelector("input");a&&a.focus()}}},[t,n,o,e]),null},Zs=e=>{const t=e&&e.scrollHeight>e.clientHeight,n=e?window.getComputedStyle(e).overflowY:null,o=n&&n.indexOf("hidden")!==-1;return t&&!o},Ro=e=>!e||e===document.body?document.body:Zs(e)?e:Ro(e.parentNode);function Xs({customId:e,entityId:t,status:n,onChange:o,error:l,entity:i}){const s=n==="existing"||!e,a=n!=="existing"&&!e,c=d.useMemo(()=>{if(!(!e||typeof e=="boolean"||e==="optional"))return _e(e)},[e]),f=Je(),{copy:g}=lo({onSuccess:u=>f.open({type:"success",message:`Copied ${u}`})}),p=q(),h={label:a?"ID is set automatically":"ID",disabled:s,name:"id",value:(i&&n==="existing"?i.id:t)??"",endAdornment:i?r.jsxs(r.Fragment,{children:[r.jsx(A.Tooltip,{title:"Copy",children:r.jsx(A.IconButton,{onClick:u=>g(i.id),"aria-label":"copy-id",children:r.jsx(A.ContentCopyIcon,{size:"small"})})}),p?.entityLinkBuilder&&r.jsx(A.Tooltip,{title:"Open in the console",children:r.jsx(A.IconButton,{component:"a",href:p.entityLinkBuilder({entity:i}),rel:"noopener noreferrer",target:"_blank",onClick:u=>u.stopPropagation(),"aria-label":"go-to-datasource",children:r.jsx(A.OpenInNewIcon,{size:"small"})})})]}):void 0};return r.jsxs(r.Fragment,{children:[c&&r.jsx(A.Select,{error:l,onValueChange:u=>o(u),...h,renderValue:u=>{const m=c.find(b=>b.id===u);return m?`${m.id} - ${m.label}`:u},children:c.map(u=>r.jsx(A.SelectItem,{value:String(u.id),children:r.jsx(Ce,{enumKey:u.id,enumValues:c,size:"medium"})},u.id))}),!c&&r.jsx(A.TextField,{...h,error:l,placeholder:e==="optional"?"Autogenerated ID, it can be manually changed":n==="new"||n==="copy"?"ID of the new document":"ID of the document",onChange:u=>{let m=u.target.value;return m&&(m=m.trim()),o(m.length?m:void 0)}}),r.jsx(Be.ErrorMessage,{name:"id",component:"div",children:u=>"You need to specify an ID"})]})}const Ks={icon:r.jsx(A.KeyboardTabIcon,{}),name:"Edit",collapsed:!1,onClick({entity:e,collection:t,context:n,highlightEntity:o,unhighlightEntity:l}){return o?.(e),n.onAnalyticsEvent?.("entity_click",{path:e.path,entityId:e.id}),n.sideEntityController.open({entityId:e.id,path:e.path,collection:t,updateUrl:!0,onClose:()=>l?.(e)}),Promise.resolve(void 0)}},el={icon:r.jsx(A.FileCopyIcon,{}),name:"Copy",onClick({entity:e,collection:t,context:n,highlightEntity:o,unhighlightEntity:l}){return o?.(e),n.onAnalyticsEvent?.("copy_entity_click",{path:e.path,entityId:e.id}),n.sideEntityController.open({entityId:e.id,path:e.path,copy:!0,collection:t,updateUrl:!0,onClose:()=>l?.(e)}),Promise.resolve(void 0)}},tl={icon:r.jsx(A.DeleteIcon,{}),name:"Delete",onClick({entity:e,fullPath:t,collection:n,context:o,selectionController:l,onCollectionChange:i,sideEntityController:s}){const{closeDialog:a}=o.dialogsController.open({key:"delete_entity_dialog_"+e.id,Component:({open:c})=>{if(!n||!t)throw new Error("deleteEntityAction: Collection is undefined");return r.jsx(Uo,{entityOrEntitiesToDelete:e,path:t,collection:n,callbacks:n.callbacks,open:c,onEntityDelete:()=>{o.onAnalyticsEvent?.("single_entity_deleted",{path:t}),l?.setSelectedEntities(l.selectedEntities.filter(f=>f.id!==e.id)),i?.(),s?.close()},onClose:a})}});return Promise.resolve(void 0)}},rl=d.memo(Rs,(e,t)=>e.status===t.status&&e.path===t.path&&ne(e.entity?.values,t.entity?.values));function Rs({status:e,path:t,collection:n,entity:o,onEntitySaveRequested:l,onDiscard:i,onModified:s,onValuesChanged:a,onIdChange:c,onFormContextChange:f,hideId:g,autoSave:p,onIdUpdateError:h}){const u=q(),m=Te(),b=u.plugins,y=d.useMemo(()=>Ie({collection:n,path:t,values:o?.values,fields:u.propertyConfigs}),[o?.values,t]),C=(e==="new"||e==="copy")&&!!y.customId&&y.customId!=="optional",w=d.useMemo(()=>e==="new"||e==="copy"?C?void 0:m.generateEntityId(t):o?.id,[]),E=d.useRef(!1),k=d.useMemo(()=>{const T=y.properties;if((e==="existing"||e==="copy")&&o)return o.values??Ct(T);if(e==="new")return Ct(T);throw console.error({status:e,entity:o}),new Error("Form has not been initialised with the correct parameters")},[e,y,o]),[x,I]=d.useState(w),[B,S]=d.useState(!1),[F,Q]=d.useState(),N=d.useRef(o?.values??k),M=N.current,[Y,W]=d.useState(M),L=T=>{W(T),a&&a(T),p&&T&&!ne(T,M)&&V(T)};d.useEffect(()=>{x&&c&&c(x)},[x,c]);const Z=Ie({collection:n,path:t,entityId:x,values:Y,previousValues:M,fields:u.propertyConfigs}),ee=n.callbacks?.onIdUpdate;d.useEffect(()=>{if(ee&&Y&&(e==="new"||e==="copy"))try{const T=ee({collection:Z,path:t,entityId:x,values:Y,context:u});I(T)}catch(T){h&&h(T),console.error(T)}},[x,Y,e]);const U=d.useMemo(()=>M&&e==="existing"?Object.entries(Z.properties).map(([T,z])=>{if(wt(z))return{};const j=M[T],X=k[T];return ne(j,X)?{}:{[T]:X}}).reduce((T,z)=>({...T,...z}),{}):{},[k,Z.properties,M,e]),V=T=>l({collection:Z,path:t,entityId:x,values:T,previousValues:o?.values,closeAfterSave:E.current,autoSave:p??!1}).then(z=>{const j=e==="new"?"new_entity_saved":e==="copy"?"entity_copied":e==="existing"?"entity_edited":"unmapped_event";u.onAnalyticsEvent?.(j,{path:t}),N.current=T}).catch(z=>{console.error(z),Q(z)}).finally(()=>{E.current=!1}),te=(T,z)=>{if(C&&!x){console.error("Missing custom Id"),S(!0),z.setSubmitting(!1);return}if(Q(void 0),S(!1),e==="existing"){if(!o?.id)throw Error("Form misconfiguration when saving, no id for existing entity")}else if(e==="new"||e==="copy"){if(n.customId&&n.customId!=="optional"&&!x)throw Error("Form misconfiguration when saving, entityId should be set")}else throw Error("New FormType added, check EntityForm");V(T)?.then(j=>{z.resetForm({values:T,submitCount:0,touched:{}})}).finally(()=>{z.setSubmitting(!1)})},$=d.useCallback(({name:T,value:z,property:j})=>m.checkUniqueField(t,T,z,x),[m,t,x]),H=d.useMemo(()=>x?No(x,Z.properties,$):void 0,[x,Z.properties,$]),se=je(),ae=d.useCallback(({entity:T,customEntityActions:z})=>{const j=at(n,se,Pe(t),null),X=T?Ht(n,se,Pe(t),T):!0,P=[];return j&&P.push(el),X&&P.push(tl),z&&P.push(...z),P},[se,n,t]);return r.jsx(Be.Formik,{initialValues:k,onSubmit:te,validationSchema:H,validate:T=>console.debug("Validating",T),onReset:()=>i&&i(),children:T=>{const z=[],j={setFieldValue:T.setFieldValue,values:T.values,collection:Z,entityId:x,path:t,save:V};if(d.useEffect(()=>{f&&f(j)},[f,j]),b&&n){const X={entityId:x,path:t,status:e,collection:n,context:u,currentEntityId:x,formContext:j};z.push(...b.map((P,D)=>P.form?.Actions?r.jsx(P.form.Actions,{...X},`actions_${P.name}`):null).filter(Boolean))}return r.jsxs("div",{className:"h-full overflow-auto",children:[z.length>0&&r.jsx("div",{className:A.cn("w-full flex justify-end items-center sticky top-0 right-0 left-0 z-10 bg-opacity-60 bg-slate-200 dark:bg-opacity-60 dark:bg-slate-800 backdrop-blur-md"),children:z}),r.jsxs("div",{className:"pl-4 pr-4 pt-12 pb-16 md:pl-8",children:[r.jsx("div",{className:`w-full py-2 flex items-center mt-${4+(z?8:0)} lg:mt-${8+(z?8:0)} mb-8`,children:r.jsx(A.Typography,{className:"mt-4 flex-grow "+n.hideIdFromForm?"mb-2":"mb-0",variant:"h4",children:n.singularName??n.name})}),!g&&r.jsx(Xs,{customId:n.customId,entityId:x,status:e,onChange:I,error:B,entity:o}),x&&r.jsx(ea,{...T,initialValues:M,onModified:s,onValuesChanged:L,underlyingChanges:U,entity:o,resolvedCollection:Z,formContext:j,status:e,savingError:F,closeAfterSaveRef:E,autoSave:p,entityActions:ae({entity:o,customEntityActions:n.entityActions})})]})]})}})}function ea(e){const{values:t,onModified:n,onValuesChanged:o,underlyingChanges:l,formContext:i,entity:s,touched:a,setFieldValue:c,resolvedCollection:f,isSubmitting:g,status:p,handleSubmit:h,savingError:u,dirty:m,closeAfterSaveRef:b,autoSave:y,entityActions:C}=e,w=q(),E=C.filter(F=>F.includeInForm===void 0||F.includeInForm),k=He(),x=m;d.useEffect(()=>{n&&n(x),o&&o(t)},[x,t]),d.useEffect(()=>{!y&&l&&s&&Object.entries(l).forEach(([F,Q])=>{const N=t[F];!ne(Q,N)&&!a[F]&&(console.debug("Updated value from the datasource:",F,Q),c(F,Q!==void 0?Q:null))})},[y,l,s,t,a,c]);const I=r.jsx("div",{className:"flex flex-col gap-8",children:(f.propertiesOrder??Object.keys(f.properties)).map(F=>{const Q=f.properties[F];if(!Q)return console.warn(`Property ${F} not found in collection ${f.name}`),null;const N=!!l&&Object.keys(l).includes(F)&&!!a[F],M=!y&&g||it(Q)||!!Q.disabled;if(wt(Q))return null;const W={propertyKey:F,disabled:M,property:Q,includeDescription:Q.description||Q.longDescription,underlyingValueHasChanged:N&&!y,context:i,tableMode:!1,partOfArray:!1,partOfBlock:!1,autoFocus:!1};return r.jsx("div",{id:`form_field_${F}`,children:r.jsx(re,{children:r.jsx(nt,{...W})})},`field_${f.name}_${F}`)}).filter(Boolean)}),B=g||!x&&p==="existing",S=d.useRef(null);return r.jsxs(Be.Form,{onSubmit:h,noValidate:!0,children:[r.jsxs("div",{className:"mt-12",ref:S,children:[I,r.jsx(qs,{containerRef:S})]}),r.jsx("div",{className:"h-14"}),!y&&r.jsxs(A.DialogActions,{position:"absolute",children:[u&&r.jsx("div",{className:"text-right",children:r.jsx(A.Typography,{color:"error",children:u.message})}),s&&E.length>0&&r.jsx("div",{className:"flex-grow flex overflow-auto no-scrollbar",children:E.map(F=>r.jsx(A.IconButton,{color:"primary",onClick:Q=>{Q.stopPropagation(),s&&F.onClick({entity:s,fullPath:f.path,collection:f,context:w,sideEntityController:k})},children:F.icon},F.name))}),r.jsx(A.Button,{variant:"text",disabled:B,type:"reset",children:p==="existing"?"Discard":"Clear"}),r.jsxs(A.Button,{variant:"text",color:"primary",type:"submit",disabled:B,onClick:()=>{b.current=!1},children:[p==="existing"&&"Save",p==="copy"&&"Create copy",p==="new"&&"Create"]}),r.jsxs(A.Button,{variant:"filled",color:"primary",type:"submit",disabled:B,onClick:()=>{b.current=!0},children:[p==="existing"&&"Save and close",p==="copy"&&"Create copy and close",p==="new"&&"Create and close"]})]})]})}function ta(e){return e.open?r.jsx(ra,{...e}):null}function ra({tableKey:e,entity:t,customFieldValidator:n,propertyKey:o,collection:l,path:i,cellRect:s,open:a,onClose:c,onCellValueChange:f,container:g}){const p=Te(),h=q(),[u,m]=d.useState(),[b,y]=d.useState(),C=t?.id,[w,E]=d.useState(t);d.useEffect(()=>C&&l?p.listenEntity?.({path:i,entityId:C,collection:l,onUpdate:V=>{E(V),x(V?.values)}}):()=>{},[p,C,l,i,a]);const[k,x]=d.useState(w?.values),I=l?Ie({collection:l,path:i,values:k,entityId:C,fields:h.propertyConfigs}):void 0,B=Fs(),S=d.useRef(null),F=d.useRef(null),Q=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:V,y:te})=>{const $=S.current?.getBoundingClientRect();if(!$)throw Error("normalizePosition called before draggableBoundingRect is set");return{x:Math.max(0,Math.min(V,B.width-$.width)),y:Math.max(0,Math.min(te,B.height-$.height))}},[B]),Y=d.useCallback(V=>{const te=S.current?.getBoundingClientRect();if(!s||!te)return;const $=V??M(N());(!b||$.x!==b.x||$.y!==b.y)&&y($)},[s,N,M,b]);Ss({containerRef:S,innerRef:F,x:b?.x,y:b?.y,onMove:Y}),d.useEffect(()=>{Q.current=!1},[o,w]),d.useLayoutEffect(()=>{const V=S.current?.getBoundingClientRect();!s||!V||Q.current||(Y(),Q.current=!0)},[s,Y,Q.current]),d.useLayoutEffect(()=>{Y(b)},[B,s]);const W=d.useMemo(()=>{if(!(!I||!C))return No(C,o&&I.properties[o]?{[o]:I.properties[o]}:{},n)},[I,C,o,n]),L=d.useCallback(()=>Y(b),[b,Y]),Z=async V=>(m(null),l&&w&&f&&o?f({value:V[o],propertyKey:o,entity:w,setError:m,onValueUpdated:()=>{},fullPath:i,context:h}):Promise.resolve());if(!w)return r.jsx(r.Fragment,{});const ee=w&&r.jsxs("div",{className:`text-gray-900 dark:text-white overflow-auto rounded rounded-md bg-white dark:bg-gray-950 ${a?"":"hidden"} cursor-grab max-w-[100vw]`,children:[r.jsx(Be.Formik,{initialValues:w?.values??{},enableReinitialize:!0,validationSchema:W,validateOnMount:!0,validate:V=>console.debug("Validating",V),onSubmit:(V,te)=>{Z(V).then(()=>c()).finally(()=>te.setSubmitting(!1))},children:({values:V,setFieldValue:te,handleSubmit:$,isSubmitting:H})=>{if(d.useEffect(()=>{ne(V,k)||x(V)},[V]),!w)return r.jsx(me,{error:"PopupFormField misconfiguration"});if(!I)return r.jsx(r.Fragment,{});const se=H,ae={collection:I,entityId:C,values:V,path:i,setFieldValue:te,save:Z},T=o&&tt(I.properties,o),z=o&&T?{propertyKey:o,disabled:H||it(T)||!!T.disabled,property:T,includeDescription:!1,underlyingValueHasChanged:!1,context:ae,tableMode:!0,partOfArray:!1,partOfBlock:!1,autoFocus:a}:void 0;let j=r.jsx(r.Fragment,{children:r.jsx("div",{className:"w-[560px] max-w-full max-h-[85vh]",children:r.jsxs(Be.Form,{onSubmit:$,noValidate:!0,children:[r.jsx("div",{className:"mb-1 p-4 flex flex-col relative",children:r.jsx("div",{ref:F,className:"cursor-auto",style:{cursor:"auto !important"},children:z&&r.jsx(nt,{...z})})}),r.jsx(A.DialogActions,{children:r.jsx(A.Button,{variant:"filled",color:"primary",type:"submit",disabled:se,children:"Save"})})]})},`popup_form_${e}_${C}_${o}`)});const X=h.plugins;return X&&X.forEach(P=>{P.form?.provider&&(j=r.jsx(P.form.provider.Component,{status:"existing",path:i,collection:I,entity:w,context:h,currentEntityId:C,formContext:ae,...P.form.provider.props,children:j}))}),j}}),u&&r.jsx(A.Typography,{color:"error",children:u.message})]}),U=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 ${a?"visible":"invisible"} cursor-grab overflow-visible`,ref:S,children:[r.jsx(Ns,{onResize:L}),r.jsxs("div",{className:"overflow-hidden",children:[ee,r.jsx("div",{className:"absolute -top-3.5 -right-3.5 bg-gray-500 rounded-full",style:{width:"32px",height:"32px"},children:r.jsx(A.IconButton,{size:"small",onClick:V=>{V.stopPropagation(),c()},children:r.jsx(A.ClearIcon,{className:"text-white",size:"small"})})})]})]},`draggable_${o}_${C}_${a}`);return r.jsx(Fl.Root,{asChild:!0,container:g,children:U})}const na="collectionGroupParent",cn=d.memo(function({fullPath:t,parentCollectionIds:n,isSubCollection:o,className:l,...i}){const s=Te(),a=ie(),c=He(),f=je(),g=dt(),p=q(),h=d.useRef(null),u=d.useMemo(()=>{const O=g?.getCollectionConfig(t);return O?Ne(i,O):i},[i,t,g?.getCollectionConfig]),m=at(u,f,Pe(t),null),[b,y]=d.useState(void 0),[C,w]=d.useState(void 0),[E,k]=d.useState(0),[x,I]=d.useState(0),B=d.useCallback(()=>{const O=b;setTimeout(()=>{O===b&&y(void 0)},2400)},[b]),S=d.useCallback(O=>Ir(u,f,Pe(t),O??null)?u.inlineEditing===void 0||u.inlineEditing:!1,[u,f,t]),F=u.selectionEnabled===void 0||u.selectionEnabled,Q=!S(),[N,M]=d.useState(!1),Y=dn(),W=u.selectionController??Y,{selectedEntities:L,toggleEntitySelection:Z,isEntitySelected:ee,setSelectedEntities:U}=W;d.useEffect(()=>{w(void 0)},[L]);const V=en({fullPath:t,collection:u,entitiesDisplayedFirst:[],lastDeleteTimestamp:E}),te=d.useRef(Math.random().toString(36)),$=V.popupCell,H=d.useCallback(()=>{V.setPopupCell?.(void 0)},[V.setPopupCell]),se=d.useCallback(O=>(y(O),p.onAnalyticsEvent?.("edit_entity_clicked",{path:O.path,entityId:O.id}),c.open({entityId:O.id,path:O.path,collection:u,updateUrl:!0,onClose:B})),[t,u,c]),ae=d.useCallback(()=>{p.onAnalyticsEvent?.("new_entity_click",{path:t}),c.open({path:t,collection:u,updateUrl:!0,onClose:B})},[t,u,c]);d.useCallback(O=>{p.onAnalyticsEvent?.("single_delete_dialog_open",{path:t}),w(O)},[p,t]);const T=d.useCallback(()=>{p.onAnalyticsEvent?.("multiple_delete_dialog_open",{path:t}),w(L)},[p,t,L]),z=d.useCallback((O,J)=>{p.onAnalyticsEvent?.("single_entity_deleted",{path:t}),U(K=>K.filter(R=>R.id!==J.id)),k(Date.now())},[p,t,U]),j=d.useCallback((O,J)=>{p.onAnalyticsEvent?.("multiple_entities_deleted",{path:t}),U([]),w(void 0),k(Date.now())},[U]);let X;p?.plugins&&(X=p.plugins.find(O=>O.collectionView?.AddColumnComponent)?.collectionView?.AddColumnComponent);const P=d.useCallback((O,J)=>{if(g){const K=g.getCollectionConfig(O),R=Ne(K,J);g.onCollectionModified(O,R)}},[g]),D=d.useCallback(({width:O,key:J})=>{if(!tt(u.properties,J))return;const K=nl(J,O);P(t,K)},[u,P,t]),le=d.useCallback(O=>{g&&P(t,{defaultSize:O})},[P,t,g]),fe=at(u,f,Pe(t),null),ce=d.useCallback(({name:O,value:J,property:K,entityId:R})=>s.checkUniqueField(t,O,J,R),[t]),Ee=({fullPath:O,context:J,value:K,propertyKey:R,onValueUpdated:de,setError:Oe,entity:Qt})=>{const _=Be.setIn({...Qt.values},R,K),he={path:O,entityId:Qt.id,values:_,previousValues:Qt.values,collection:u,status:"existing"};return Qr({...he,collection:u,callbacks:u.callbacks,dataSource:s,context:J,onSaveSuccess:()=>de(),onSaveFailure:Ae=>{console.error("Save failure"),console.error(Ae),Oe(Ae)}})},Ze=a.resolveAliasesFrom(t),ze=d.useMemo(()=>Ie({collection:u,path:t,fields:p.propertyConfigs}),[u,t]),Ve=d.useCallback(({propertyKey:O,propertyValue:J,entity:K})=>{let R=tt(u.properties,O);return R||(R=tt(ze.properties,O)),xe({propertyKey:O,propertyOrBuilder:R,path:t,propertyValue:J,values:K.values,entityId:K.id,fields:p.propertyConfigs})},[u.properties,p.propertyConfigs,t,ze.properties]),St=Vo(ze,!0),bt=d.useMemo(()=>{const O=u.subcollections?.map(K=>({key:_r(K),name:K.name,width:200,dependencies:[],Builder:({entity:R})=>r.jsx(A.Button,{color:"primary",variant:"outlined",startIcon:r.jsx(A.KeyboardTabIcon,{size:"small"}),onClick:de=>{de.stopPropagation(),c.open({path:t,entityId:R.id,selectedSubPath:K.id??K.path,collection:u,updateUrl:!0})},children:K.name})}))??[],J=u.collectionGroup?[{key:na,name:"Parent entities",width:260,dependencies:[],Builder:({entity:K})=>{const R=a.getParentReferencesFromPath(K.path);return r.jsx(r.Fragment,{children:R.map(de=>r.jsx(De,{reference:de,size:"tiny"},de.path+"/"+de.id))})}}]:[];return[...u.additionalFields??[],...O,...J]},[u,t]),Ft=d.useCallback(()=>{k(Date.now())},[]),Xe=Qe(),Ke=d.useCallback(({entity:O,customEntityActions:J})=>{const K=O?Ht(u,f,Pe(t),O):!0,R=[Ks];return fe&&R.push(el),K&&R.push(tl),J&&R.push(...J),R},[f,u,fe,t]),Nt=d.useCallback(()=>{const O=Ke({}),J=O.filter(de=>de.collapsed!==!1),R=O.filter(de=>de.collapsed===!1).length*(Xe?40:30);return(Xe?80+R:70+R)+(J.length>0?Xe?40:30:0)},[Xe,Ke]),Re=d.useCallback(({entity:O,size:J,width:K,frozen:R})=>{const de=ee(O),Oe=Ke({entity:O,customEntityActions:u.entityActions});return r.jsx(qr,{entity:O,width:K,frozen:R,isSelected:de,selectionEnabled:F,size:J,highlightEntity:y,unhighlightEntity:B,collection:u,fullPath:t,actions:Oe,hideId:u?.hideIdFromCollection,onCollectionChange:Ft,selectionController:W})},[ee,u,f,t,F,Z,fe]),Pt=r.jsx(A.Popover,{open:N,onOpenChange:M,enabled:!!u.description,trigger:r.jsxs("div",{className:"flex flex-col items-start",children:[r.jsx(A.Typography,{variant:"subtitle1",className:`leading-none truncate max-w-[160px] lg:max-w-[240px] ${u.description?"cursor-pointer":"cursor-auto"}`,onClick:u.description?O=>{M(!0),O.stopPropagation()}:void 0,children:`${u.name}`}),r.jsx(oa,{fullPath:t,collection:u,filter:V.filterValues,sortBy:V.sortBy,onCountChange:I})]}),children:u.description&&r.jsx("div",{className:"m-4 text-gray-900 dark:text-white",children:r.jsx(A.Markdown,{source:u.description})})});function Tt({property:O,propertyKey:J,onHover:K}){return p.plugins?r.jsx(r.Fragment,{children:p.plugins.filter(R=>R.collectionView?.HeaderAction).map((R,de)=>{const Oe=R.collectionView.HeaderAction;return r.jsx(Oe,{onHover:K,propertyKey:J,property:O,fullPath:t,collection:u,parentCollectionIds:n??[]},`plugin_header_action_${de}`)})}):null}const G=X?function(){return typeof X=="function"?r.jsx(X,{fullPath:t,parentCollectionIds:n??[],collection:u}):null}:void 0;return r.jsxs("div",{className:A.cn("overflow-hidden h-full w-full",l),ref:h,children:[r.jsx(Rr,{additionalFields:bt,tableController:V,displayedColumnIds:St,onSizeChanged:le,onEntityClick:se,onColumnResize:D,onValueChange:Ee,tableRowActionsBuilder:Re,uniqueFieldValidator:ce,title:Pt,selectionController:W,highlightedEntities:b?[b]:[],defaultSize:u.defaultSize,properties:ze.properties,getPropertyFor:Ve,actions:r.jsx(Is,{parentCollectionIds:n??[],collection:u,tableController:V,onMultipleDeleteClick:T,onNewClick:ae,path:t,relativePath:u.path,selectionController:W,selectionEnabled:F,collectionEntitiesCount:x}),emptyComponent:m&&V.filterValues===void 0&&V.sortBy===void 0?r.jsxs("div",{className:"flex flex-col items-center justify-center",children:[r.jsx(A.Typography,{variant:"subtitle2",children:"So empty..."}),r.jsxs(A.Button,{color:"primary",variant:"outlined",onClick:ae,className:"mt-4",children:[r.jsx(A.AddIcon,{}),"Create your first entity"]})]}):r.jsx(A.Typography,{variant:"label",children:"No results with the applied filter/sort"}),hoverRow:Q,inlineEditing:S(),AdditionalHeaderWidget:Tt,AddColumnComponent:G,getIdColumnWidth:Nt,additionalIDHeaderWidget:r.jsx(la,{path:t,collection:u})},`collection_table_${t}`),r.jsx(ta,{open:!!$,onClose:H,cellRect:$?.cellRect,propertyKey:$?.propertyKey,collection:u,entity:$?.entity,tableKey:te.current,customFieldValidator:ce,path:Ze,onCellValueChange:Ee,container:h.current},`popup_form_${$?.propertyKey}_${$?.entity?.id}`),C&&r.jsx(Uo,{entityOrEntitiesToDelete:C,path:t,collection:u,callbacks:u.callbacks,open:!!C,onEntityDelete:z,onMultipleEntitiesDelete:j,onClose:()=>w(void 0)})]})},ne);function dn(){const[e,t]=d.useState([]),n=d.useCallback(l=>{let i;e.map(s=>s.id).includes(l.id)?i=e.filter(s=>s.id!==l.id):i=[...e,l],t(i)},[e]),o=d.useCallback(l=>e.map(i=>i.id).includes(l.id),[e]);return{selectedEntities:e,setSelectedEntities:t,isEntitySelected:o,toggleEntitySelection:n}}function oa({fullPath:e,collection:t,filter:n,sortBy:o,onCountChange:l}){const i=Te(),s=ie(),[a,c]=d.useState(void 0),[f,g]=d.useState(void 0),p=o?o[0]:void 0,h=o?o[1]:void 0,u=d.useMemo(()=>s.resolveAliasesFrom(e),[e,s.resolveAliasesFrom]);return d.useEffect(()=>{i.countEntities({path:u,collection:t,filter:n,orderBy:p,order:h}).then(c).catch(g)},[e,i,u,t,n,p,h]),d.useEffect(()=>{l&&l(a??0)},[l,a]),f?null:r.jsx(A.Typography,{className:"w-full text-ellipsis block overflow-hidden whitespace-nowrap max-w-xs text-left w-fit-content",variant:"caption",color:"secondary",children:a!==void 0?`${a} entities`:r.jsx(A.Skeleton,{className:"w-full max-w-[80px] mt-1"})})}function nl(e,t){if(e.includes(".")){const[n,...o]=e.split(".");return{properties:{[n]:nl(o.join("."),t)}}}return{properties:{[e]:{columnWidth:t}}}}function la({collection:e,path:t}){const[n,o]=d.useState(!1),[l,i]=d.useState(""),s=He();return r.jsx(A.Tooltip,{title:n?void 0:"Find by ID",children:r.jsx(A.Popover,{open:n,onOpenChange:o,trigger:r.jsx(A.IconButton,{size:"small",children:r.jsx(A.SearchIcon,{size:"small"})}),children:r.jsx("form",{noValidate:!0,onSubmit:a=>{if(a.preventDefault(),!!l)return o(!1),s.open({entityId:l,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-4 w-full gap-4",children:[r.jsx(A.TextField,{placeholder:"Find entity by ID",size:"small",onChange:a=>i(a.target.value),value:l,className:"flex-grow"}),r.jsx(A.Button,{variant:"outlined",disabled:!l,type:"submit",children:"Go"})]})})})})}function ol({onSingleEntitySelected:e,onMultipleEntitiesSelected:t,multiselect:n,collection:o,path:l,selectedEntityIds:i,description:s,forceFilter:a,maxSelection:c}){const f=nr(),g=He(),p=ie(),h=q(),u=p.resolveAliasesFrom(l),m=Te(),[b,y]=d.useState([]),C=dn();d.useEffect(()=>{let N=!1;const M=i?.map(Y=>Y?.toString()).filter(Boolean);return M&&o?Promise.all(M.map(Y=>m.fetchEntity({path:u,entityId:Y,collection:o}))).then(Y=>{if(!N){const W=Y.filter(L=>L!==void 0);C.setSelectedEntities(W),y(W)}}):(C.setSelectedEntities([]),y([])),()=>{N=!0}},[m,u,i,o,C.setSelectedEntities]);const w=()=>{h.onAnalyticsEvent?.("reference_selection_clear",{path:u}),C.setSelectedEntities([]),!n&&e?e(null):t&&t([])},E=N=>{console.debug("ReferenceSelectionInner toggleEntitySelection",N);let M;const Y=C.selectedEntities;if(h.onAnalyticsEvent?.("reference_selection_toggle",{path:u,entityId:N.id}),Y){if(Y.map(W=>W.id).indexOf(N.id)>-1)M=Y.filter(W=>W.id!==N.id);else{if(c&&Y.length>=c)return;M=[...Y,N]}C.setSelectedEntities(M),t&&t(M)}},k=N=>{console.debug("ReferenceSelectionInner onEntityClick",N),!n&&e?(h.onAnalyticsEvent?.("reference_selected_single",{path:u,entityId:N.id}),e(N),f.close(!1)):E(N)},x=()=>{h.onAnalyticsEvent?.("reference_selection_new_entity",{path:u}),g.open({path:u,collection:o,updateUrl:!0,onUpdate:({entity:N})=>{y([N,...b]),k(N)},closeOnSave:!0})},I=({entity:N,size:M,width:Y,frozen:W})=>{const L=C.selectedEntities,Z=L&&L.map(ee=>ee.id).indexOf(N.id)>-1;return r.jsx(qr,{width:Y,frozen:W,entity:N,size:M,isSelected:Z,selectionEnabled:n,hideId:o?.hideIdFromCollection,fullPath:u,selectionController:C})},B=d.useCallback(N=>{N.stopPropagation(),f.close(!1)},[f]);if(!o)return r.jsx(me,{error:"Could not find collection with id "+o});const S=d.useMemo(()=>Ie({collection:o,path:u,values:{},fields:h.propertyConfigs}),[o,h.propertyConfigs,u]),F=Vo(S,!1),Q=en({fullPath:u,collection:o,entitiesDisplayedFirst:b,forceFilter:a});return r.jsxs("div",{className:"flex flex-col h-full",children:[r.jsx("div",{className:"flex-grow",children:b&&r.jsx(Rr,{displayedColumnIds:F,onEntityClick:k,tableController:Q,tableRowActionsBuilder:I,title:r.jsx(A.Typography,{variant:"subtitle2",children:o.singularName?`Select ${o.singularName}`:`Select from ${o.name}`}),defaultSize:o.defaultSize,properties:S.properties,forceFilter:a,inlineEditing:!1,selectionController:C,actions:r.jsx(ia,{collection:o,path:u,onNewClick:x,onClear:w})})}),r.jsxs(A.DialogActions,{translucent:!1,children:[s&&r.jsx(A.Typography,{variant:"body2",className:"flex-grow text-left",children:s}),r.jsx(A.Button,{onClick:B,color:"primary",variant:"filled",children:"Done"})]})]})}function ia({collection:e,path:t,onClear:n,onNewClick:o}){const l=je(),i=Qe(),s=o?c=>{c.preventDefault(),o()}:void 0,a=at(e,l,Pe(t),null)&&s&&(i?r.jsxs(A.Button,{onClick:s,startIcon:r.jsx(A.AddIcon,{}),variant:"outlined",color:"primary",children:["Add ",e.singularName??e.name]}):r.jsx(A.Button,{onClick:s,size:"medium",variant:"outlined",color:"primary",children:r.jsx(A.AddIcon,{})}));return r.jsxs(r.Fragment,{children:[r.jsx(A.Button,{onClick:n,variant:"text",color:"primary",children:"Clear"}),a]})}function An({children:e,group:t}){const n=dt();return r.jsx(A.ExpandablePanel,{invisible:!0,titleClassName:"font-medium text-sm text-gray-600 dark:text-gray-400",className:"py-4",initiallyExpanded:!(n?.collapsedGroups??[]).includes(t??"ungrouped"),onExpandedChange:o=>{if(n)if(o)n.setCollapsedGroups((n.collapsedGroups??[]).filter(l=>l!==(t??"ungrouped")));else{const l=(n.collapsedGroups??[]).concat(t??"ungrouped");n.setCollapsedGroups(l)}},title:r.jsx(A.Typography,{color:"secondary",className:"font-medium ml-1",children:t?.toUpperCase()??"Views".toUpperCase()}),children:r.jsx("div",{className:"mb-8",children:e})})}function ll({view:e,path:t,collection:n,url:o,name:l,description:i,onClick:s}){const a=dt(),c=Jt(n??e),f=ue.useNavigate(),g=q(),p=(a?.favouritePaths??[]).includes(t);let h;if(g.plugins&&n){const u={path:t,collection:n,context:g};h=r.jsx(r.Fragment,{children:g.plugins.map((m,b)=>m.homePage?.CollectionActions?r.jsx(m.homePage.CollectionActions,{...u,extraProps:m.homePage.extraProps},`actions_${b}`):null)})}return r.jsx(A.Card,{className:A.cn("h-full p-4 cursor-pointer min-h-[230px]"),onClick:()=>{s?.(),f(o),a&&a.setRecentlyVisitedPaths([t,...(a.recentlyVisitedPaths??[]).filter(u=>u!==t)])},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:[c,r.jsxs("div",{className:"flex items-center gap-1",onClick:u=>{u.preventDefault(),u.stopPropagation()},children:[h,a&&r.jsx(A.IconButton,{onClick:u=>{u.preventDefault(),u.stopPropagation(),p?a.setFavouritePaths(a.favouritePaths.filter(m=>m!==t)):a.setFavouritePaths([...a.favouritePaths,t])},children:p?r.jsx(A.StarIcon,{size:18,className:"text-secondary"}):r.jsx(A.StarBorderIcon,{size:18,className:"text-gray-400 dark:text-gray-500"})})]})]}),r.jsx(A.Typography,{gutterBottom:!0,variant:"h5",component:"h2",children:l}),i&&r.jsx(A.Typography,{variant:"body2",color:"secondary",component:"div",children:r.jsx(A.Markdown,{source:i})})]}),r.jsx("div",{style:{alignSelf:"flex-end"},children:r.jsx("div",{className:"p-4",children:r.jsx(A.ArrowForwardIcon,{className:"text-primary"})})})]})})}function sa({entry:e}){const t=ue.useNavigate(),n=dt();if(!n)return null;const o=n.favouritePaths.includes(e.path),l=i=>{i.preventDefault(),i.stopPropagation(),o?n.setFavouritePaths(n.favouritePaths.filter(s=>s!==e.path)):n.setFavouritePaths([...n.favouritePaths,e.path])};return r.jsx(A.Chip,{onClick:()=>t(e.url),icon:o?r.jsx(A.StarIcon,{onClick:l,size:18,className:"text-secondary"}):r.jsx(A.StarBorderIcon,{onClick:l,size:18,className:"text-gray-400 dark:text-gray-500"}),children:e.name},e.path)}function aa({hidden:e}){const t=ie(),n=dt();if(!n)return null;const o=(n?.favouritePaths??[]).map(l=>t.topLevelNavigation?.navigationEntries.find(i=>i.path===l)).filter(Boolean);return r.jsx(A.Collapse,{in:o.length>0,children:r.jsx("div",{className:"flex flex-row flex-wrap gap-2 pb-2 min-h-[32px]",children:o.map(l=>r.jsx(sa,{entry:l},l.path))})})}const fn={};function ca(){const e=ue.useLocation(),t=d.useRef(null),[n,o]=d.useState(0),[l,i]=d.useState("down"),s=d.useCallback(()=>{!t.current||!e.key||(fn[e.key]=t.current.scrollTop,o(t.current.scrollTop),i(t.current.scrollTop>n?"down":"up"))},[t,e.key,n]);return d.useEffect(()=>{const a=t.current;if(a)return a.addEventListener("scroll",s,{passive:!0}),()=>{a&&a.removeEventListener("scroll",s)}},[t,s,e]),d.useEffect(()=>{!t.current||!fn[e.key]||t.current.scrollTo({top:fn[e.key],behavior:"auto"})},[e]),{containerRef:t,scroll:n,direction:l}}const pt=new Sl.Search("url");pt.addIndex("name"),pt.addIndex("description"),pt.addIndex("group"),pt.addIndex("path");function il({additionalActions:e,additionalChildrenStart:t,additionalChildrenEnd:n}){const o=q(),l=ie();if(!l.topLevelNavigation)throw Error("Navigation not ready in FireCMSHomePage");const{containerRef:i,scroll:s,direction:a}=ca(),{navigationEntries:c,groups:f}=l.topLevelNavigation,[g,p]=d.useState(null),h=g?c.filter(w=>g.includes(w.url)):c;d.useEffect(()=>{pt.addDocuments(c)},[c]);const u=d.useCallback(w=>{if(!w||w==="")p(null);else{const E=pt.search(w);p(E.map(k=>k.url))}},[]),m=[...f];(h.filter(w=>!w.group).length>0||h.length===0)&&m.push(void 0);let b,y,C;if(o.plugins){const w={context:o};C=r.jsx(r.Fragment,{children:o.plugins.filter(E=>E.homePage?.includeSection).map((E,k)=>{const x=E.homePage.includeSection(w);return r.jsx(An,{group:x.title,children:x.children},`plugin_section_${E.name}`)})}),b=r.jsx("div",{className:"flex flex-col gap-2",children:o.plugins.filter(E=>E.homePage?.additionalChildrenStart).map((E,k)=>r.jsx("div",{children:E.homePage.additionalChildrenStart},`plugin_children_start_${k}`))}),y=r.jsx("div",{className:"flex flex-col gap-2",children:o.plugins.filter(E=>E.homePage?.additionalChildrenEnd).map((E,k)=>r.jsx("div",{children:E.homePage.additionalChildrenEnd},`plugin_children_start_${k}`))})}return r.jsx("div",{id:"home_page",ref:i,className:"py-2 overflow-auto h-full w-full",children:r.jsxs(A.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:a==="down"?-84:0},children:[r.jsx(A.SearchBar,{onTextSearch:u,placeholder:"Search collections",large:!1,className:"w-full flex-grow"}),e]}),r.jsx(aa,{hidden:!!g}),t,b,m.map((w,E)=>{const k=[],x={group:w,context:o};o.plugins&&o.plugins.forEach(B=>{B.homePage?.AdditionalCards&&k.push(...Rt(B.homePage?.AdditionalCards))});const I=h.filter(B=>B.group===w||!B.group&&w===void 0);return I.length===0&&k.length===0?null:r.jsx(An,{group:w,children:r.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:[I.map(B=>r.jsx("div",{className:"col-span-1",children:r.jsx(ll,{...B,onClick:()=>{const S=B.type==="collection"?"home_navigate_to_collection":B.type==="view"?"home_navigate_to_view":"unmapped_event";o.onAnalyticsEvent?.(S,{path:B.path})}})},`nav_${B.group}_${B.name}`)),k&&k.map((B,S)=>r.jsx("div",{children:r.jsx(B,{...x})},`nav_${w}_add_${S}`))]})},`plugin_section_${w}`)}),C,y,n]})})}function da({propertyConfig:e}){const t="h-8 w-8 p-1 rounded-full shadow text-white",n=typeof e?.property=="object"?ml(e.property):void 0;return r.jsx("div",{className:t,style:{background:e?.color??n?.color??"#888"},children:e?.Icon?Wt(e,"medium"):Wt(n,"medium")})}function sl(){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(A.Typography,{variant:"h4",align:"center",gutterBottom:!0,children:"Page not found"}),r.jsx(A.Typography,{align:"center",gutterBottom:!0,children:"This page does not exist or you may not have access to it"}),r.jsx(A.Button,{variant:"text",component:ue.Link,to:"/",children:"Back to home"})]})})}function Aa({open:e,onAccept:t,onCancel:n,title:o,loading:l,body:i}){return r.jsxs(A.Dialog,{open:e,onOpenChange:s=>s?void 0:n(),children:[r.jsxs(A.DialogContent,{children:[r.jsx(A.Typography,{variant:"h6",className:"mb-2",children:o}),i]}),r.jsxs(A.DialogActions,{children:[r.jsx(A.Button,{variant:"text",onClick:n,autoFocus:!0,children:"Cancel"}),r.jsx(A.LoadingButton,{color:"primary",type:"submit",loading:l,onClick:t,children:"Ok"})]})]})}function al({width:e,height:t,className:n,style:o}){return r.jsxs("svg",{width:e??"100%",height:t??"100%",viewBox:"0 0 599 599",version:"1.1",style:o,className:n,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 cl=function({title:t,endAdornment:n,startAdornment:o,drawerOpen:l,dropDownActions:i,includeDrawer:s,className:a,style:c,user:f}){const g=ie(),p=je(),{mode:h,toggleMode:u}=Mr(),m=Qe(),b=f??p.user;let y;if(b&&b.photoURL)y=r.jsx(A.Avatar,{src:b.photoURL});else if(b===void 0||p.initialLoading)y=r.jsx("div",{className:"p-1 flex justify-center",children:r.jsx(A.Skeleton,{className:"w-10 h-10 rounded-full"})});else{const C=b?.displayName?b.displayName[0].toUpperCase():b?.email?b.email[0].toUpperCase():"A";y=r.jsx(A.Avatar,{children:C})}return r.jsx("div",{style:c,className:A.cn("pr-2",{"ml-[17rem]":l&&m,"ml-16":s&&!(l&&m)&&!o,"h-16":!0,"z-10":m,"transition-all":!0,"ease-in":!0,"duration-75":!0,"w-full":!s,"w-[calc(100%-64px)]":s&&!(l&&m),"w-[calc(100%-17rem)]":s&&l&&m,"duration-150":l&&m,fixed:!0},a),children:r.jsxs("div",{className:"flex flex-row gap-2 px-4 h-full items-center",children:[o,g&&r.jsx("div",{className:"mr-8 hidden lg:block",children:r.jsx(ue.Link,{className:"visited:text-inherit visited:dark:text-inherit",to:g?.basePath??"/",children:r.jsx(A.Typography,{variant:"subtitle1",noWrap:!0,className:"ml-2 !font-medium",children:t})})}),r.jsx("div",{className:"flex-grow"}),n&&r.jsx(re,{children:n}),r.jsx(A.IconButton,{color:"inherit","aria-label":"Open drawer",onClick:u,size:"large",children:h==="dark"?r.jsx(A.DarkModeIcon,{}):r.jsx(A.LightModeIcon,{})}),r.jsxs(A.Menu,{trigger:y,children:[i,!i&&r.jsxs(A.MenuItem,{onClick:p.signOut,children:[r.jsx(A.LogoutIcon,{}),"Log Out"]})]})]})})},fa=e=>e&&Array.isArray(e)&&e.length>0?e.map((t,n)=>t?{[gr(t)+n]:It()}:{}).reduce((t,n)=>({...t,...n}),{}):{};function un({droppableId:e,addLabel:t,value:n,disabled:o=!1,buildEntry:l,size:i,onInternalIdAdded:s,includeAddButton:a,newDefaultEntry:c,onValueChange:f}){const g=n&&Array.isArray(n)&&n.length>0,p=d.useRef(fa(n)),[h,u]=d.useState(g?Object.values(p.current):[]);d.useEffect(()=>{if(g&&n&&n.length!==h.length){const w=n.map((E,k)=>{const x=gr(E)+k;if(x in p.current)return p.current[x];{const I=It();return p.current[x]=I,I}});u(w)}},[g,h.length,n]);const m=w=>{if(w.preventDefault(),o)return;const E=It(),k=[...h,E];s&&s(E),u(k),f([...n??[],c])},b=w=>{const E=[...h];E.splice(w,1),u(E),f(n.filter((k,x)=>x!==w))},y=w=>{const E=It(),k=n[w],x=[...h.splice(0,w+1),E,...h.splice(w+1,h.length-w-1)];s&&s(E),u(x),f([...n.slice(0,w+1),k,...n.slice(w+1)])},C=w=>{if(!w.destination)return;const E=w.source.index,k=w.destination.index,x=[...h],I=x[E];x[E]=x[k],x[k]=I,u(x),f(ua(n,E,k))};return r.jsx(lt.DragDropContext,{onDragEnd:C,children:r.jsx(lt.Droppable,{droppableId:e,renderClone:(w,E,k)=>{const x=k.source.index,I=h[x];return r.jsx(gn,{provided:w,internalId:I,index:x,size:i,disabled:o,buildEntry:l,remove:b,copy:y,isDragging:E.isDragging})},children:(w,E)=>r.jsxs("div",{...w.droppableProps,ref:w.innerRef,children:[g&&h.map((k,x)=>r.jsx(lt.Draggable,{draggableId:`array_field_${k}`,isDragDisabled:o,index:x,children:(I,B)=>r.jsx(gn,{provided:I,internalId:k,index:x,size:i,disabled:o,buildEntry:l,remove:b,copy:y,isDragging:B.isDragging})},`array_field_${k}`)),w.placeholder,a&&r.jsx("div",{className:"py-4 justify-center text-left",children:r.jsx(A.Button,{variant:"text",size:i==="small"?"small":"medium",color:"primary",disabled:o,startIcon:r.jsx(A.AddIcon,{}),onClick:m,children:t??"Add"})})]})})})}function gn({provided:e,index:t,internalId:n,size:o,disabled:l,buildEntry:i,remove:s,copy:a,isDragging:c}){const[f,g]=cr(),p=o!=="small"&&g.height===0,h=o!=="small"&&g.height<100,[u,m]=d.useState(!1),b=d.useCallback(()=>m(!0),[]),y=d.useCallback(()=>m(!1),[]);return r.jsx("div",{onMouseEnter:b,onMouseMove:b,onMouseLeave:y,ref:e.innerRef,...e.draggableProps,style:e.draggableProps.style,className:`${c||u?A.fieldBackgroundHoverMixin:""} mb-1 rounded-md opacity-100`,children:r.jsxs("div",{className:"flex items-start",children:[r.jsx("div",{ref:f,className:"flex-grow w-[calc(100%-48px)] text-text-primary dark:text-text-primary-dark",children:i(t,n)}),r.jsx(dl,{direction:o==="small"?"row":"column",disabled:l,remove:s,index:t,provided:e,measuring:p,contentOverflow:h,copy:a})]})})}function dl({direction:e,disabled:t,remove:n,index:o,provided:l,copy:i,contentOverflow:s,measuring:a}){return r.jsxs("div",{className:`p-1 flex ${e==="row"?"flex-row-reverse":"flex-col"} items-center`,...l.dragHandleProps,children:[r.jsx(A.Tooltip,{side:e==="column"?"left":void 0,title:"Move",children:r.jsx(A.IconButton,{size:"small",disabled:t,className:`cursor-${t?"inherit":"grab"}`,children:r.jsx("svg",{focusable:"false",fill:"currentColor","aria-hidden":"true",viewBox:"0 0 24 24",children:r.jsx("path",{d:"M20 9H4v2h16V9zM4 15h16v-2H4v2z"})})})}),!a&&!s&&r.jsxs(r.Fragment,{children:[r.jsx(A.Tooltip,{title:"Remove",side:e==="column"?"left":void 0,children:r.jsx(A.IconButton,{size:"small","aria-label":"remove",disabled:t,onClick:()=>n(o),children:r.jsx(A.RemoveIcon,{size:"small"})})}),r.jsx(A.Tooltip,{side:e==="column"?"left":void 0,title:"Copy in this position",children:r.jsx(A.IconButton,{size:"small","aria-label":"copy",disabled:t,onClick:()=>i(o),children:r.jsx(A.ContentCopyIcon,{size:"small"})})})]}),!a&&s&&r.jsx(r.Fragment,{children:r.jsxs(A.Menu,{trigger:r.jsx(A.IconButton,{size:"small",children:r.jsx(A.MoreVertIcon,{size:"small"})}),children:[r.jsxs(A.MenuItem,{dense:!0,onClick:()=>n(o),children:[r.jsx(A.RemoveIcon,{size:"small"}),"Remove"]}),r.jsxs(A.MenuItem,{dense:!0,onClick:()=>i(o),children:[r.jsx(A.ContentCopyIcon,{size:"small"}),"Copy"]})]})})]})}function ua(e,t,n){const o=Array.from(e),[l]=o.splice(t,1);return o.splice(n,0,l),o}function It(){return Math.floor(Math.random()*Math.floor(Number.MAX_SAFE_INTEGER))}function ga({name:e,multiselect:t=!1,path:n,disabled:o,value:l,onReferenceSelected:i,onMultipleReferenceSelected:s,previewProperties:a,forceFilter:c,size:f,className:g}){const p=ie(),h=d.useMemo(()=>p.getCollection(n),[n,p]);if(!h)throw Error(`Couldn't find the corresponding collection for the path: ${n}`);const u=d.useCallback(w=>{if(!o&&i){const E=w?Ge(w):null;i?.({reference:E,entity:w})}},[o,i]),m=d.useCallback(w=>{if(!o&&s){const E=w?w.map(k=>Ge(k)):null;s({references:E,entities:w})}},[o,i]),b=mt({multiselect:t,path:n,collection:h,onSingleEntitySelected:u,onMultipleEntitiesSelected:m,forceFilter:c});d.useCallback(w=>{w.stopPropagation(),t?m([]):u(null)},[i]);let y;const C=()=>{o||b.open()};return Array.isArray(l)?y=r.jsx("div",{className:"flex flex-col gap-4",children:l.map((w,E)=>r.jsx(De,{onClick:C,reference:w,disabled:o,previewProperties:a,size:f},`reference_preview_${E}`))}):l instanceof Fe&&(y=r.jsx(De,{reference:l,onClick:C,disabled:o,previewProperties:a,size:f})),r.jsxs("div",{className:A.cn("text-sm font-medium text-gray-500","min-w-80 flex flex-col gap-4","relative transition-colors duration-200 ease-in rounded font-medium",o?"bg-opacity-50":"hover:bg-opacity-75","text-opacity-50 dark:text-white dark:text-opacity-50",g),children:[y,!l&&r.jsx("div",{className:"justify-center text-left",children:r.jsxs(A.Button,{variant:"outlined",color:"primary",disabled:o,onClick:C,children:["Edit ",e]})})]})}function ve({icon:e,title:t,small:n,className:o,required:l}){return r.jsxs("span",{className:`inline-flex items-center my-0.5 ${n?"gap-1":"gap-2"} ${o??""}`,children:[e,r.jsx("span",{className:`font-medium text-${n?"base":"sm"} origin-top-left transform ${n?"translate-x-2 scale-75":""}`,children:(t??"")+(l?" *":"")})]})}function mt(e){const t=ie(),n=Bt(),o=d.useCallback(()=>{if(e.path){let i=e.collection;if(i||(i=t.getCollection(e.path)),!i)throw Error("Not able to resolve the collection in useReferenceDialog");n.open({key:`reference_${e.path}`,component:r.jsx(ol,{collection:i,...e}),width:"90vw",onClose:()=>{e.onClose?.()}})}else throw Error("useReferenceDialog: You are trying to open a reference dialog, but have not declared the `path`")},[t,e,n]),l=d.useCallback(()=>{n.close()},[n]);return{open:o,close:l}}const ha=`data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAAASAAAAEgARslrPgAAB9pJREFUWMONl12obVUVx39jzLk+9j7nHq9y1QT1qpcbSIaXQFGs24PQl3HroSQyqHwJFJF6qaceCsqQoJdELHoIC6EeJCSKsi/TFLGozGsKXksljRLxnrP3WmvOOUYPa+19zsmPWpux5pxrzTX///Exx5hb+B/X1y+/nuIlVKF5m0v1YbQ55tIcKTQXFerNQkumOZ1oTiXCqUH8saR+74L8ZIWWux7+7JuuL2/04s5jJyhWQlXV71KtbhCtr1WtD6s0KlrjNBRaEi3JGzpv6bymQ0sn9mwv9otB7Ls7kn9Xo+U7D9z8/xG4+bz3cs35SjE/HEK8NWr8RBOrs+tQUUlEtAYaijRkbxmY0fuMzucsfcbSWnZQtiWxJL3Uid09iH0jIM8/1f+d3/zuS29M4PvHrmG+cZA8dMdjiLfNYrx6owrMVKlVUQkgkeI1iYbBJ3A2WPpKNtnx+UQisy29L0gPDGKfrwkPn2bJPfd/Zo0ZVp0fvOOdnLGxheX+A/Mq3nGwqS8/q645o4psxkgbhFqdSgqVJKIkghgqjuDoWh+dlm1AI0gUC3o4C9d04idbmZ06euQDPPHMj3YJ3HnkrZx98Fys2PFZ1dxxsJkdPbOecaBqmcWGqBVBIkEiKkoQJ5IJJBTbY8aRgBMwjxgVJoJJwDScnYUrOy2PBamfv/CS4zz9zE+IAIfPuQQzPzyrmq9u1e3RM+qWeaipNCCiE4DjbjgF94xZQj2htpjeK84ImqlIUpO9JllgEKgJDFpfOoh8paN8chbOeQ4g/OTq97PdLXSz3fjiVjO7/sx6g804ow41QWuCrjQPBB3bkZQgAkpBJOMojmIEjIgRKV6RpaYIZHGKQlK5OIv0L8bul8eOfsxjDJGD8613z6rmhq1qxkY1o9YKFUFEEED2xqoE1MNoWgPBwQZMl2SrSbQM9NQyUMlA5S3Rlcqd6E50RdRvPMvn9yE8qP9+9WWtQvXxzdic8xrwPaJrUYJGoq4sVBM1Ukuiln4UBipJVJrGoHUhrARB0XMQ/cizbSd61uaZlzUhXjuvWmqt9oOyAmUPEabnkSDV2j0Rp2YgksZdQpoCtRBwAiN4cKYdw4m3pNnbY9Tw4SZUh9tQEda+ld1WpmThgoivU8fYDbgEggRcleiZ6BOoFNRXLQQX1Eelggsgh8GPx6DhWB2iRgkj2OTuVX8dBzJtMx93BAKK4hIwUUSEID4BGspecWTfDwSCw+UxqByJoqPf9+xmYWQg7H3u+5Poyk3o5BZDxRBxxH29fdkF3YcBXKHgF+m+hLxn4OvbnnbPzMkjsm/+f5cXec2ye6ZfpO6+OX7pE8TqPj1zcN/7Zu8CDm44Bu6skrKjuOs0FlxWCJNMYxMOqLlR3DAvsAKaZo6t7+u7r6nhjN/5RKIQKESKhykhjeIINgJi+0m4Fiuns2WKZQybtJ2AfAWzGu/ayt0wz5gXimeKQyKSPI4kiCMhDxSgyLiOiY9kxnW2NVs+1ZeBbAmzhLmtgd0d8z1k1mIUTxQbKD5gnkmuDN6QvCF5TaIie0UmkIU1id3WcfwZHUo61eWB3gayDdOiZR+JXUuMWmcbyGWcny2RzOi8obeWwRsGrxm8JlGPBHCyOJmpJkwkHHs09pnfL1L60KLqtBKZtprhU+lVmSq9+xRsBfOMW6L4QLFM7zWdz+l8Ru8tA+10YKlJIiSxkcC6dQqlmJc/xaHIvTuZT7UpHalFUHEqL6iGsfKtM8FEzMdy7J4oXui9mk5CczpGErtEKgacQUZJE3gSwzw/i+dfx2G7e6IcOPALCXIkakGkYx4iwceyq+uENPp+RSI7DN7Q+5ylb7JgJLH0+XRGbOlRerWJwNgmnOwJ83Tvq/7KX2KZb1nJfnfp5YRoda7hFC/MQyGI7Mteow2E4pHkDT2zyfS758HV4bSjolOjF2PYS4KBbN2L5vmHZ7DpsWQnDsvfLj1+Lwufy9LSO2y5M1Mnik8OEJxAoSJRk7xhoKX3+URiztI3WPgGS2/p1OnE6CcSvRQGH+htQfH07dPSP7Lp9ajcNy+9DnG/oMT67qqZHz/QtGxVyjworQqVCIjiPiaaTD1ttZZ+fTIeCXQ+Y6HCQm0tO5LYpmfHlyy9/1nCPi3ICw/99JbxUHrdvxr6Q4depdhTfeGapVeH+imKxwhv6ZnR+5zeN0aNGU2+ZIPON0cX0LBQYSnGQgsLSSzoWdiCHVvQ2fLP2fMtwf2vDz50K6TpVPxj/sn7Ni5iu9l6Tof+yd78yoWFQ0uvWYvVLK1h6e34B8RnY9DZnIW3LAijxpLYkZ6Fd+z4km3bYcd2WNry8ezppsZ5ZMd2+MfTv3xtjbr9/PfwyoFDzPvtq7I2t+Vq/m6pt4hxThVaojao1CANRkORmkwkiTCI00thKYWOzJJR+6V1JE8/z2JfqGgfW9jLPPLg7a9Xe8frHs7j5MVXESxfmLS5KYXmxhQ3z/a4icQNRFtEGlwjJkoRIamTmIKNTE+it57kw0sF+1ah3CkSXkiPf42Htl+3WL/2+vIFJ6ishJ3QXD1o9dEhVCcGbS7ModUcakwrigaKChkoYmQK2XMp5L8V/F7DfuDePYrEcv8f7npdnDcksEvkg9RewquhuayTcHzQeCyJXpFVD2fRzSxCFtkuwqks8mjB/ujYr9y6k0gs9528503X/w/F3eUgyIBI4wAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAyMS0wNS0xMFQxOToyODozMyswMDowMEzeSx4AAAAldEVYdGRhdGU6bW9kaWZ5ADIwMjEtMDUtMTBUMTk6Mjg6MzMrMDA6MDA9g/OiAAAARnRFWHRzb2Z0d2FyZQBJbWFnZU1hZ2ljayA2LjcuOC05IDIwMTQtMDUtMTIgUTE2IGh0dHA6Ly93d3cuaW1hZ2VtYWdpY2sub3Jn3IbtAAAAABh0RVh0VGh1bWI6OkRvY3VtZW50OjpQYWdlcwAxp/+7LwAAABh0RVh0VGh1bWI6OkltYWdlOjpoZWlnaHQAMTkyDwByhQAAABd0RVh0VGh1bWI6OkltYWdlOjpXaWR0aAAxOTLTrCEIAAAAGXRFWHRUaHVtYjo6TWltZXR5cGUAaW1hZ2UvcG5nP7JWTgAAABd0RVh0VGh1bWI6Ok1UaW1lADE2MjA2NzQ5MTMk8oswAAAAD3RFWHRUaHVtYjo6U2l6ZQAwQkKUoj7sAAAAVnRFWHRUaHVtYjo6VVJJAGZpbGU6Ly8vbW50bG9nL2Zhdmljb25zLzIwMjEtMDUtMTAvOGIxNDNhYjgwODhkMjBlZThkYmUzOTFhN2NkNmQ3NmQuaWNvLnBuZ9msgG0AAAAASUVORK5CYII=
588
+ `;function pa(e,t){d.useEffect(()=>{if(document){document.title=`${e} - FireCMS`;let n=document.querySelector("link[rel~='icon']");n||(n=document.createElement("link"),n.rel="icon",document.getElementsByTagName("head")[0].appendChild(n)),n.href=t??ha}},[e,t])}const rr="main_##Q$SC^#S6";function ma({path:e,entityId:t,selectedSubPath:n,copy:o,collection:l,parentCollectionIds:i,onValuesAreModified:s,formWidth:a,onUpdate:c,onClose:f}){l.customId&&l.formAutoSave&&console.warn(`The collection ${l.path} has customId and formAutoSave enabled. This is not supported and formAutoSave will be ignored`);const[g,p]=d.useState(!1),[h,u]=d.useState(void 0);_t(h,()=>{h&&D({entityId:H?.id,collection:l,path:e,values:h,closeAfterSave:!1})},!1,2e3);const m=Te(),b=nr(),y=He(),C=Je(),w=q(),E=je(),[k,x]=d.useState(void 0),[I,B]=d.useState(o?"copy":t?"existing":"new"),S=d.useRef(void 0),F=S.current,Q=(l.subcollections??[]).filter(G=>!G.hideFromNavigation),N=Q?.length??0,M=l.entityViews,Y=M?.length??0,W=l.formAutoSave&&!l.customId,L=Y>0||N>0,Z=n??Br(l?l.defaultSelectedView:void 0,{status:I,entityId:t}),ee=d.useRef(Z??rr),U=ee.current===rr,{entity:V,dataLoading:te,dataLoadingError:$}=Tr({path:e,entityId:t,collection:l,useCache:!1}),[H,se]=d.useState(V),[ae,T]=d.useState(void 0);d.useEffect(()=>{V&&se(V)},[V]),d.useEffect(()=>{if(I==="new")T(!1);else{const G=H?Ir(l,E,Pe(e),H??null):!1;H&&T(!G)}},[E,H,I]);const z=d.useCallback(G=>{p(!1),C.open({type:"error",message:"Error before saving: "+G?.message}),console.error(G)},[C]),j=d.useCallback(G=>{p(!1),C.open({type:"error",message:"Error after saving (entity is saved): "+G?.message}),console.error(G)},[C]),X=(G,O)=>{p(!1),W||C.open({type:"success",message:`${l.singularName??l.name}: Saved correctly`}),se(G),B("existing"),s(!1),c&&c({entity:G}),O?(b.setBlocked(!1),b.close(!0),f?.()):I!=="existing"&&y.replace({path:e,entityId:G.id,selectedSubPath:ee.current,updateUrl:!0,collection:l})},P=d.useCallback(G=>{p(!1),C.open({type:"error",message:"Error saving: "+G?.message}),console.error("Error saving entity",e,t),console.error(G)},[t,e,C]),D=({values:G,previousValues:O,closeAfterSave:J,entityId:K,collection:R,path:de})=>{p(!0),Qr({path:de,entityId:K,values:G,previousValues:O,collection:R,status:I,dataSource:m,context:w,onSaveSuccess:Oe=>X(Oe,J),onSaveFailure:P,onPreSaveHookError:z,onSaveSuccessHookError:j}).then()},le=async({collection:G,path:O,entityId:J,values:K,previousValues:R,closeAfterSave:de,autoSave:Oe})=>{I&&(Oe?u(K):D({collection:G,path:O,entityId:J,values:K,previousValues:R,closeAfterSave:de}))},fe=M?M.map(G=>wr(G,w.entityViews)).filter(Boolean):[],ce=M&&fe.map((G,O)=>{if(!G||ee.current!==G.key)return null;const J=G.Builder;return J?r.jsx("div",{className:A.cn(A.defaultBorderMixin,"relative flex-grow w-full h-full overflow-auto "),role:"tabpanel",children:r.jsx(re,{children:k&&r.jsx(J,{collection:l,entity:H,modifiedValues:F??H?.values,formContext:k})})},`custom_view_${G.key}`):(console.error("customView.Builder is not defined"),null)}).filter(Boolean),Ee=te&&!H||(!H||ae===void 0)&&(I==="existing"||I==="copy"),Ze=Ee||g,ze=Q&&Q.map((G,O)=>{const J=G.id??G.path,K=H?`${e}/${H?.id}/${ge(J)}`:void 0;return ee.current!==J?null:r.jsxs("div",{className:"relative flex-grow h-full overflow-auto w-full",role:"tabpanel",children:[Ze&&r.jsx(Xt,{}),!Ee&&(H&&K?r.jsx(cn,{fullPath:K,parentCollectionIds:[...i,l.id],isSubCollection:!0,...G}):r.jsx("div",{className:"flex items-center justify-center w-full h-full p-3",children:r.jsx(A.Typography,{variant:"label",children:"You need to save your entity before adding additional collections"})}))]},`subcol_${J}`)}).filter(Boolean),Ve=d.useCallback(()=>{s(!1)},[]),St=G=>{ee.current=G,y.replace({path:e,entityId:t,selectedSubPath:G===rr?void 0:G,updateUrl:!0,collection:l})},bt=d.useCallback(G=>{S.current=G},[]),Ft=d.useCallback(G=>{C.open({type:"error",message:"Error updating id, check the console"})},[]),Xe=d.useCallback(G=>{se(O=>O?{...O,id:G}:void 0)},[]),Ke=G=>{W||s(G)};function Nt(){const G=w.plugins;let O=r.jsx(rl,{status:I,path:e,collection:l,onEntitySaveRequested:le,onDiscard:Ve,onValuesChanged:bt,onModified:Ke,entity:H,onIdChange:Xe,onFormContextChange:x,hideId:l.hideIdFromForm,autoSave:W,onIdUpdateError:Ft});return G&&G.forEach(J=>{J.form?.provider&&(O=r.jsx(J.form.provider.Component,{status:I,path:e,collection:l,onDiscard:Ve,onValuesChanged:bt,onModified:Ke,entity:H,context:w,formContext:k,...J.form.provider.props,children:O}))}),r.jsx(re,{children:O})}const Re=ae===void 0?r.jsx(r.Fragment,{}):ae?r.jsxs(r.Fragment,{children:[r.jsx(A.Typography,{className:"mt-16 mb-8 mx-8",variant:"h4",children:l.singularName??l.name}),r.jsx($r,{className:"px-12",entity:H,path:e,collection:l})]}):Nt(),Pt=Q&&Q.map(G=>r.jsx(A.Tab,{className:"text-sm min-w-[140px]",value:G.id,children:G.name},`entity_detail_collection_tab_${G.name}`)),Tt=fe.map(G=>r.jsx(A.Tab,{className:"text-sm min-w-[140px]",value:G.key,children:G.name},`entity_detail_collection_tab_${G.name}`));return r.jsx("div",{className:"flex flex-col h-full w-full transition-width duration-250 ease-in-out",children:r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:A.cn(A.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(A.IconButton,{onClick:()=>(f?.(),b.close(!1)),size:"large",children:r.jsx(A.CloseIcon,{})})}),r.jsx("div",{className:"flex-grow"}),Ee&&r.jsx("div",{className:"self-center",children:r.jsx(A.CircularProgress,{size:"small"})}),r.jsxs(A.Tabs,{value:ee.current,onValueChange:G=>{St(G)},className:"pl-4 pr-4 pt-0",children:[r.jsx(A.Tab,{disabled:!L,value:rr,className:`${L?"":"hidden"} text-sm min-w-[140px]`,children:l.singularName??l.name}),Tt,Pt]})]}),r.jsxs("div",{className:"flex-grow h-full flex overflow-auto flex-row w-full ",style:{},children:[r.jsx("div",{role:"tabpanel",hidden:!U,id:`form_${e}`,className:" w-full",children:Ee?r.jsx(Xt,{}):Re}),ce,ze]})]})})}function ba(e,t){const[n,o]=d.useState(),{navigator:l}=d.useContext(ue.UNSAFE_NavigationContext),i=ue.useNavigate(),s=()=>{o(void 0)},a=()=>{t(),o(void 0),i(-1)},c=d.useCallback(({action:f,location:g,retry:p})=>{switch(f){case"REPLACE":{p();return}case"POP":o(g)}},[]);return d.useEffect(()=>{if(!e||n||!("block"in l))return;const f=l.block(g=>{const p={...g,retry(){f(),g.retry()}};c(p)});return f},[l,c,e,n]),{navigationWasBlocked:!!n,handleCancel:s,handleOk:a}}function ya({open:e,handleOk:t,handleCancel:n,body:o,title:l}){return r.jsxs(A.Dialog,{open:e,onOpenChange:i=>i?n():t(),children:[r.jsxs(A.DialogContent,{children:[r.jsx(A.Typography,{variant:"h6",children:l}),o,r.jsx(A.Typography,{children:"Are you sure you want to leave this page?"})]}),r.jsxs(A.DialogActions,{children:[r.jsx(A.Button,{variant:"text",onClick:n,autoFocus:!0,children:" Cancel "}),r.jsx(A.Button,{onClick:t,children:" Ok "})]})]})}const Al=d.createContext({width:"",blocked:!1,setBlocked:e=>{},setBlockedNavigationMessage:e=>{},close:()=>{}}),nr=()=>d.useContext(Al);function va(){const t=Bt().sidePanels,n=[...t];return n.push(void 0),r.jsx(r.Fragment,{children:n.map((o,l)=>r.jsx(wa,{panel:o,offsetPosition:t.length-l-1},`side_dialog_${l}`))})}function wa({offsetPosition:e,panel:t}){const[n,o]=d.useState(!1),[l,i]=d.useState(!1),[s,a]=d.useState(),c=d.useRef(t?.width),f=c.current,g=Bt(),{navigationWasBlocked:p,handleOk:h,handleCancel:u}=ba(l&&!n,()=>i(!1));d.useEffect(()=>{t&&(c.current=t.width)},[t]);const m=()=>{i(!1),o(!1),g.close(),t?.onClose?.()},b=()=>{o(!1)},y=C=>{l&&!C?o(!0):(g.close(),t?.onClose?.())};return r.jsxs(Al.Provider,{value:{blocked:l,setBlocked:i,setBlockedNavigationMessage:a,width:f,close:y},children:[r.jsxs(A.Sheet,{open:!!t,onOpenChange:C=>!C&&y(),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(re,{children:t.component})}),!t&&r.jsx("div",{style:{width:f}})]}),r.jsx(ya,{open:p||n,handleOk:n?m:h,handleCancel:n?b:u,body:s})]})}function Ca(e){const{blocked:t,setBlocked:n,setBlockedNavigationMessage:o}=nr(),l=ie(),i=d.useMemo(()=>l.getParentCollectionIds(e.path),[l,e.path]),s=d.useMemo(()=>{if(!e)return;let c=e.collection;if(!c&&(c=l.getCollection(e.path,e.entityId),!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},[l,e]);d.useEffect(()=>{function c(f){t&&s&&(f.preventDefault(),f.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 a=d.useCallback(c=>{n(c),o(c?r.jsxs(r.Fragment,{children:[" You have unsaved changes in this ",r.jsx("b",{children:s?.singularName??s?.name}),"."]}):void 0)},[s?.name,n,o]);return!e||!s?r.jsx("div",{className:"w-full"}):r.jsx(r.Fragment,{children:r.jsx(re,{children:r.jsx(ma,{...e,formWidth:e.width,collection:s,parentCollectionIds:i,onValuesAreModified:a})})})}const fl="new";function Ea(e,t){if(t)return ci;const n=!e.selectedSubPath,o=typeof e.width=="number"?`${e.width}px`:e.width;return n?o??Jn:`calc(${di} + ${o??Jn})`}const Ba=(e,t)=>{const n=ue.useLocation(),o=d.useRef(!1),l=!Qe();d.useEffect(()=>{if(!e.loading&&!o.current){if(e.isUrlCollectionPath(n.pathname)){const c=n.hash===`#${fl}`,f=e.urlPathToDataPath(n.pathname),g=ka(f,e.collections,c);for(let p=0;p<g.length;p++){const h=g[p];setTimeout(()=>{p===0?t.replace(or(h,e,l)):t.open(or(h,e,l))},1)}}o.current=!0}},[n,e,t,l]);const i=d.useCallback(()=>{t.close()},[t]),s=d.useCallback(c=>{if(c.copy&&!c.entityId)throw Error("If you want to copy an entity you need to provide an entityId");const f=Br(c.collection?c.collection.defaultSelectedView:void 0,{status:c.copy?"copy":c.entityId?"existing":"new",entityId:c.entityId});t.open(or({selectedSubPath:f,...c},e,l))},[t,e,l]),a=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(or(c,e,l))},[e,t,l]);return{close:i,open:s,replace:a}};function ka(e,t,n){const o=Cr({path:e,collections:t}),l=[];let i="";for(let s=0;s<o.length;s++){const a=o[s];if(a.type==="collection"&&(i=a.path),s>0){const c=o[s-1];if(a.type==="entity")l.push({path:a.path,entityId:a.entityId,copy:!1});else if(a.type==="custom_view"){if(c.type==="entity"){const f=l[l.length-1];f&&(f.selectedSubPath=a.view.key)}}else if(a.type==="collection"&&c.type==="entity"){const f=l[l.length-1];f&&(f.selectedSubPath=a.collection.id??a.collection.path)}}}return n&&l.push({path:i,copy:!1}),l}const or=(e,t,n)=>{const o=ge(e.path),l=e.entityId?t.buildUrlCollectionPath(`${o}/${e.entityId}/${e.selectedSubPath||""}`):t.buildUrlCollectionPath(`${o}#${fl}`);return{key:`${e.path}/${e.entityId}`,component:r.jsx(Ca,{...e}),urlPath:l,parentUrlPath:t.buildUrlCollectionPath(o),width:Ea(e,n),onClose:e.onClose}};function xa(){const e=ue.useLocation(),t=ue.useNavigate(),[n,o]=d.useState([]),l=d.useRef(n),i=d.useRef({}),s=d.useRef(0),a=p=>{l.current=p,o(p)};d.useEffect(()=>{const u=(e.state?.panels??[]).map(m=>i.current[m]).filter(m=>!!m);ne(l.current.map(m=>m.key),u.map(m=>m.key))||a(u)},[e]);const c=d.useCallback(()=>{if(n.length===0)return;const p=n[n.length-1],h=[...n.slice(0,-1)];if(a(h),s.current>0)p.urlPath&&t(-1),s.current--;else if(p.parentUrlPath){const u=e.state?.base_location??e;t(p.parentUrlPath,{replace:!0,state:{base_location:u,panels:h.map(m=>m.key)}})}},[n,t,e]),f=d.useCallback(p=>{const h=Array.isArray(p)?p:[p];h.forEach(b=>{i.current[b.key]=b}),s.current=s.current+h.length;const u=e.state?.base_location??e,m=[...n,...h];a(m),h.forEach(b=>{b.urlPath&&t(b.urlPath,{state:{base_location:u,panels:m.map(y=>y.key)}})})},[e,t,n]),g=d.useCallback(p=>{const h=Array.isArray(p)?p:[p];h.forEach(b=>{i.current[b.key]=b});const u=e.state?.base_location??e,m=[...n.slice(0,-h.length),...h];a(m),h.forEach(b=>{b.urlPath&&t(b.urlPath,{replace:!0,state:{base_location:u,panels:m.map(y=>y.key)}})})},[e,t,n]);return{sidePanels:n,close:c,open:f,replace:g}}function Ia(e){d.useEffect(()=>{if(!e)return;const t=En[e];t&&(Cn.registerLocale(e,t),Cn.setDefaultLocale(e))},[e])}function ul(e){const{path:t,collections:n=[],currentFullPath:o}=e,l=ge(t).split("/"),i=Ot(l),s=[];for(let a=0;a<i.length;a++){const c=i[a],f=n&&n.find(g=>g.id===c||g.path===c);if(f){const g=f.id??f.path,p=o&&o.length>0?o+"/"+g:g,h=ge(ge(t).replace(c,"")),u=h.length>0?h.split("/"):[];if(u.length>0){const m=u[0],b=p+"/"+m;if(s.push(new Fe(m,p)),u.length>1){const y=u.slice(1).join("/");if(!f)throw Error("collection not found resolving path: "+f);f.subcollections&&s.push(...ul({path:y,collections:f.subcollections,currentFullPath:b}))}}break}}return s}const Sa="/",Fa="/c";function Na({basePath:e=Sa,baseCollectionPath:t=Fa,authController:n,collections:o,views:l,userConfigPersistence:i,plugins:s,dataSource:a}){const c=ue.useLocation(),[f,g]=d.useState(),[p,h]=d.useState(),[u,m]=d.useState(!1),[b,y]=d.useState(void 0),[C,w]=d.useState(!0),[E,k]=d.useState(void 0),x=ge(e),I=ge(t),B=x?`/${x}`:"/",S=x?`/${x}/${I}`:`/${I}`,F=d.useCallback(T=>x?`/${x}/${lr(T)}`:`/${lr(T)}`,[x]),Q=d.useCallback(T=>`${ge(t)}/${lr(T)}`,[t]),N=d.useCallback((T,z)=>{const j=[...(T??[]).map(P=>P.hideFromNavigation?void 0:{url:Q(P.id??P.path),type:"collection",name:P.name.trim(),path:P.id??P.path,collection:P,description:P.description?.trim(),group:P.group?.trim()}).filter(Boolean),...(z??[]).map(P=>P.hideFromNavigation?void 0:{url:F(Array.isArray(P.path)?P.path[0]:P.path),name:P.name.trim(),type:"view",view:P,description:P.description?.trim(),group:P.group?.trim()}).filter(Boolean)],X=Object.values(j).map(P=>P.group).filter(Boolean).filter((P,D,le)=>le.indexOf(P)===D);return{navigationEntries:j,groups:X}},[F,Q]),M=d.useCallback(async()=>{if(!n.initialLoading){try{const[T=[],z=[]]=await Promise.all([Pa(o,n,a,s),Ta(l,n,a)]);g(T),h(z),y(N(T??[],z))}catch(T){console.error(T),k(T)}w(!1),m(!0)}},[o,n.user,n.initialLoading,s,l,N]);d.useEffect(()=>{M()},[M]);const Y=d.useCallback((T,z,j=!1)=>{if(!f)return;const X=Dt(ge(T),f),P=j?i?.getCollectionConfig(T):void 0,D=X?Ne(X,P):void 0;let le=D;if(D){const fe=D.subcollections,ce=D.callbacks,Ee=D.permissions;le={...le,subcollections:le?.subcollections??fe,callbacks:le?.callbacks??ce,permissions:le?.permissions??Ee}}if(le)return{...D,...le}},[e,t,f]),W=d.useCallback(T=>{let z=f;if(!z)throw Error("Collections have not been initialised yet");for(let j=0;j<T.length;j++){const X=T[j],P=z.find(D=>D.id===X||D.path===X);if(!P)return;if(z=P.subcollections,j===T.length-1)return P}},[f]),L=d.useCallback(T=>{let z=f;if(!z)throw Error("Collections have not been initialised yet");for(let j=0;j<T.length;j++){const X=T[j],P=z.find(D=>D.id===X);if(!P)return;if(z=P.subcollections,j===T.length-1)return P}},[f]),Z=d.useCallback(T=>ge(T+"/").startsWith(ge(S)+"/"),[S]),ee=d.useCallback(T=>{if(T.startsWith(S))return T.replace(S,"");throw Error("Expected path starting with "+S)},[S]),U=d.useCallback(({path:T})=>`s/edit/${lr(T)}`,[]),V=d.useCallback(T=>{if(!f)throw Error("Collections have not been initialised yet");return fr(T,f)},[f]),te=c.state,$=te&&te.base_location?te.base_location:c,H=d.useCallback(T=>ul({path:T,collections:f}),[f]),se=d.useCallback(T=>H(T).map(z=>z.id),[H]),ae=d.useCallback(T=>{let z=f;const j=[];for(let X=0;X<T.length;X++){const P=T[X],D=z.find(le=>le.id===P);if(!D)throw Error(`Collection with id ${P} not found`);j.push(D.path),z=D.subcollections}return j},[L]);return d.useMemo(()=>({collections:f??[],views:p??[],loading:!u||C,navigationLoadingError:E,homeUrl:B,basePath:e,baseCollectionPath:t,initialised:u,getCollection:Y,getCollectionFromPaths:W,getCollectionFromIds:L,isUrlCollectionPath:Z,urlPathToDataPath:ee,buildUrlCollectionPath:Q,buildUrlEditCollectionPath:U,buildCMSUrlPath:F,resolveAliasesFrom:V,topLevelNavigation:b,baseLocation:$,refreshNavigation:M,getParentReferencesFromPath:H,getParentCollectionIds:se,convertIdsToPaths:ae}),[t,$,e,F,Q,U,f,H,Y,W,B,u,Z,C,E,M,V,b,ee,p])}function lr(e){return encodeURIComponent(ge(e)).replaceAll("%2F","/").replaceAll("%23","#")}function gl(e,t){return e.filter(n=>n.permissions?Et(n,t,[n.path],null).read!==!1:!0).map(n=>n.subcollections?{...n,subcollections:gl(n.subcollections,t)}:n)}async function Pa(e,t,n,o){let l=[];return typeof e=="function"?l=await e({user:t.user,authController:t,dataSource:n}):Array.isArray(e)&&(l=e),l=gl(l,t),o&&o.forEach(i=>{i.collections?.injectCollections&&(l=i.collections?.injectCollections(l??[]))}),l}async function Ta(e,t,n){let o=[];return typeof e=="function"?o=await e({user:t.user,authController:t,dataSource:n}):Array.isArray(e)&&(o=e),o}function Qa({delegate:e,propertyConfigs:t,navigationController:n}){return{fetchCollection:d.useCallback(({path:o,collection:l,filter:i,limit:s,startAfter:a,searchString:c,orderBy:f,order:g})=>e.fetchCollection({path:o,filter:i,limit:s,startAfter:a,searchString:c,orderBy:f,order:g}),[e]),listenCollection:e.listenCollection?d.useCallback(({path:o,collection:l,filter:i,limit:s,startAfter:a,searchString:c,orderBy:f,order:g,onUpdate:p,onError:h})=>{const m=!!(l??n.getCollection(o))?.collectionGroup;if(!e.listenCollection)throw Error("useBuildDataSource delegate not initialised");return e.listenCollection({path:o,filter:i,limit:s,startAfter:a,searchString:c,orderBy:f,order:g,onUpdate:p,onError:h,isCollectionGroup:m})},[e,n.getCollection]):void 0,fetchEntity:d.useCallback(({path:o,entityId:l})=>e.fetchEntity({path:o,entityId:l}),[e]),listenEntity:e.listenEntity?d.useCallback(({path:o,entityId:l,collection:i,onUpdate:s,onError:a})=>{if(!e.listenEntity)throw Error("useBuildDataSource delegate not initialised");return e.listenEntity({path:o,entityId:l,onUpdate:s,onError:a})},[e.listenEntity]):void 0,saveEntity:d.useCallback(({path:o,entityId:l,values:i,collection:s,status:a})=>{const c=s??n.getCollection(o),g=(c?Ie({collection:c,path:o,entityId:l,fields:t}):void 0)?.properties,p=hn(i,e.buildReference,e.buildGeoPoint,e.buildDate,e.buildDeleteFieldValue),h=g?Sn({inputValues:p,properties:g,status:a,timestampNowValue:e.currentTime(),setDateToMidnight:e.setDateToMidnight}):p;return console.debug("Saving entity",o,l,h),e.saveEntity({path:o,entityId:l,values:h,status:a}).then(u=>({id:u.id,path:u.path,values:e.delegateToCMSModel(h)}))},[e.saveEntity,n.getCollection]),deleteEntity:d.useCallback(({entity:o})=>e.deleteEntity({entity:o}),[e.deleteEntity]),checkUniqueField:d.useCallback((o,l,i,s)=>e.checkUniqueField(o,l,i,s),[e.checkUniqueField]),generateEntityId:d.useCallback(o=>e.generateEntityId(o),[e.generateEntityId]),countEntities:d.useCallback(async({path:o,collection:l,filter:i,order:s,orderBy:a})=>e.countEntities({path:o,filter:i,orderBy:a,order:s,isCollectionGroup:!!l.collectionGroup}),[e.countEntities]),isFilterCombinationValid:d.useCallback(({path:o,filterValues:l,sortBy:i})=>e.isFilterCombinationValid?e.isFilterCombinationValid({path:o,filterValues:l,sortBy:i}):!0,[e.isFilterCombinationValid])}}function hn(e,t,n,o,l){return e===void 0?l():Array.isArray(e)?e.map(i=>hn(i,t,n,o,l)):e instanceof Fe?t(e):e instanceof Vt?n(e):e instanceof Date?o(e):e&&typeof e=="object"?Object.entries(e).map(([i,s])=>({[i]:hn(s,t,n,o,l)})).reduce((i,s)=>({...i,...s}),{}):e}function Ma(e){const t=Mr(),{children:n,entityLinkBuilder:o,userConfigPersistence:l,dateTimeFormat:i,locale:s,authController:a,storageSource:c,dataSourceDelegate:f,plugins:g,onAnalyticsEvent:p,propertyConfigs:h,entityViews:u,components:m,baseCollectionPath:b,basePath:y,collections:C,views:w}=e;Ia(s);const E=Na({basePath:y,baseCollectionPath:b,authController:a,collections:C,views:w,userConfigPersistence:l,dataSource:f,plugins:g}),k=Qa({delegate:f,propertyConfigs:h,navigationController:E}),x=xa(),I=Ba(E,x),B=g?.some(Q=>Q.loading)??!1,S=a.initialLoading||E.loading||B,F=d.useMemo(()=>({entityLinkBuilder:o,dateTimeFormat:i,locale:s,plugins:g,onAnalyticsEvent:p,entityViews:u??[],propertyConfigs:h??{},components:m}),[i,s,g,u,h,m]);return E.navigationLoadingError?r.jsx(A.CenteredView,{maxWidth:"md",fullScreen:!0,children:r.jsx(me,{title:"Error loading navigation",error:E.navigationLoadingError})}):a.authError?r.jsx(A.CenteredView,{maxWidth:"md",fullScreen:!0,children:r.jsx(me,{title:"Error loading auth",error:a.authError})}):r.jsx(Mt.Provider,{value:t,children:r.jsx(Nr.Provider,{value:F,children:r.jsx(eo.Provider,{value:l,children:r.jsx(Rn.Provider,{value:c,children:r.jsx(qn.Provider,{value:k,children:r.jsx(Ar.Provider,{value:a,children:r.jsx(Xn.Provider,{value:x,children:r.jsx(Kn.Provider,{value:I,children:r.jsx(Zn.Provider,{value:E,children:r.jsx(Ai,{children:r.jsx(Da,{loading:S,children:n})})})})})})})})})})})}function Da({loading:e,children:t}){const n=q();let o=t({context:n,loading:e});const l=n.plugins;return!e&&l&&l.forEach(i=>{i.provider&&(o=r.jsx(i.provider.Component,{...i.provider.props,context:n,children:o}))}),r.jsx(r.Fragment,{children:o})}function hl({hovered:e,drawerOpen:t,closeDrawer:n}){const o=q(),l=ie(),i=e&&!t,s=Qe();if(!l.topLevelNavigation)throw Error("Navigation not ready in Drawer");const{navigationEntries:a,groups:c}=l.topLevelNavigation,f=Object.values(a).filter(h=>!h.group),g=d.useCallback(h=>t?r.jsx("div",{className:"pt-8 pl-6 pr-8 pb-2 flex flex-row items-center",children:r.jsx(A.Typography,{variant:"caption",color:"secondary",className:"font-medium flex-grow",children:h?h.toUpperCase():"Views".toUpperCase()})}):r.jsx("div",{className:"h-4"}),[t]),p=h=>{const u=h.type==="collection"?"drawer_navigate_to_collection":h.type==="view"?"drawer_navigate_to_view":"unmapped_event";o.onAnalyticsEvent?.(u,{url:h.url}),s||n()};return r.jsxs("div",{className:"flex-grow overflow-scroll no-scrollbar",children:[c.map(h=>r.jsxs(d.Fragment,{children:[g(h),Object.values(a).filter(u=>u.group===h).map((u,m)=>r.jsx(pn,{icon:Jt(u.collection??u.view),tooltipsOpen:i,drawerOpen:t,onClick:()=>p(u),url:u.url,name:u.name},`navigation_${m}`))]},`drawer_group_${h}`)),f.length>0&&g(),f.map((h,u)=>r.jsx(pn,{icon:Jt(h.collection??h.view),tooltipsOpen:i,onClick:()=>p(h),drawerOpen:t,url:h.url,name:h.name},`navigation_${u}`))]})}function pn({name:e,icon:t,drawerOpen:n,tooltipsOpen:o,url:l,onClick:i}){const s=r.jsx("div",{className:"text-gray-600 dark:text-gray-500",children:t}),a=r.jsxs(ue.NavLink,{onClick:i,className:({isActive:c})=>A.cn("rounded-r-xl truncate","hover:bg-gray-200 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-gray-100","flex flex-row items-center w-full mr-8",n?"pl-8 h-12":"pl-6 h-11","font-medium text-sm",c?"bg-gray-100 dark:bg-gray-800":""),to:l,children:[s,r.jsx("div",{className:A.cn(n?"opacity-100":"opacity-0 hidden","ml-4 font-inherit text-inherit"),children:e.toUpperCase()})]});return n?a:r.jsx(A.Tooltip,{open:o,side:"right",title:e,children:a})}const Oa=280,Va=d.memo(function(t){const{children:n,name:o,logo:l,includeDrawer:i=!0,autoOpenDrawer:s,Drawer:a=hl,drawerProps:c,FireCMSAppBarComponent:f=cl,fireCMSAppBarComponentProps:g}=t,p=Qe(),[h,u]=d.useState(!1),[m,b]=d.useState(!1),y=d.useCallback(()=>b(!0),[]),C=d.useCallback(()=>b(!1),[]),w=d.useCallback(()=>{u(!1)},[]),E=h||!!(p&&s&&m);return r.jsxs("div",{className:"flex h-screen w-screen bg-gray-50 dark:bg-gray-900 text-gray-900 dark:text-white overflow-hidden",style:{paddingTop:"env(safe-area-inset-top)",paddingLeft:"env(safe-area-inset-left)",paddingRight:"env(safe-area-inset-right)",paddingBottom:"env(safe-area-inset-bottom)",height:"100dvh"},children:[r.jsx(f,{title:o,includeDrawer:i,drawerOpen:E,...g}),r.jsx(Ya,{displayed:i,onMouseEnter:y,onMouseMove:y,onMouseLeave:C,open:E,logo:l,hovered:m,setDrawerOpen:u,children:i&&r.jsx(a,{hovered:m,drawerOpen:E,closeDrawer:w,...c})}),r.jsxs("main",{className:"flex flex-col flex-grow overflow-auto",children:[r.jsx(Ga,{}),r.jsx("div",{className:A.cn(A.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(re,{children:n})})]})]})},ne),Ga=()=>r.jsx("div",{className:"flex flex-col min-h-[68px]"});function Ya(e){const t=ie(),n=e.displayed?e.open?Oa:72:0,o=r.jsxs("div",{className:"relative h-full no-scrollbar overflow-y-auto overflow-x-hidden",style:{width:n,transition:"left 150ms cubic-bezier(0.4, 0, 0.6, 1) 0ms, opacity 150ms cubic-bezier(0.4, 0, 0.6, 1) 0ms, width 150ms cubic-bezier(0.4, 0, 0.6, 1) 0ms"},children:[!e.open&&e.displayed&&r.jsx(A.Tooltip,{title:"Open menu",side:"right",sideOffset:12,className:"fixed top-2 left-3 !bg-gray-50 dark:!bg-gray-900 rounded-full w-fit",children:r.jsx(A.IconButton,{color:"inherit","aria-label":"Open menu",className:"sticky top-2 left-3 ",onClick:()=>e.setDrawerOpen(!0),size:"large",children:r.jsx(A.MenuIcon,{})})}),r.jsxs("div",{className:"flex flex-col h-full",children:[r.jsx("div",{style:{transition:"padding 150ms cubic-bezier(0.4, 0, 0.6, 1) 0ms",padding:e.open?"32px 96px 0px 24px":"72px 16px 0px"},className:A.cn("cursor-pointer"),children:r.jsx(A.Tooltip,{title:"Home",sideOffset:20,side:"right",children:r.jsx(ue.Link,{to:t.basePath,children:e.logo?r.jsx("img",{src:e.logo,alt:"Logo",className:A.cn("max-w-full max-h-full",e.open??"w-[160px] h-[160px]")}):r.jsx(al,{})})})}),e.children]})]});return Qe()?r.jsxs("div",{className:"relative",onMouseEnter:e.onMouseEnter,onMouseMove:e.onMouseMove,onMouseLeave:e.onMouseLeave,style:{width:n,transition:"left 150ms cubic-bezier(0.4, 0, 0.6, 1) 0ms, opacity 150ms cubic-bezier(0.4, 0, 0.6, 1) 0ms, width 150ms cubic-bezier(0.4, 0, 0.6, 1) 0ms"},children:[o,r.jsx("div",{className:`absolute right-0 top-4 ${e.open?"opacity-100":"opacity-0 invisible"} transition-opacity duration-1000 ease-in-out`,children:r.jsx(A.IconButton,{"aria-label":"Close drawer",onClick:()=>e.setDrawerOpen(!1),children:r.jsx(A.ChevronLeftIcon,{})})})]}):e.displayed?r.jsxs(r.Fragment,{children:[r.jsx(A.IconButton,{color:"inherit","aria-label":"Open drawer",onClick:()=>e.setDrawerOpen(!0),size:"large",className:"absolute top-2 left-6",children:r.jsx(A.MenuIcon,{})}),r.jsx(A.Sheet,{side:"left",transparent:!0,open:e.open,onOpenChange:e.setDrawerOpen,children:o})]}):null}function pl(e){return Object.keys(ir).includes(e)}const ir={text_field:{key:"text_field",name:"Text field",description:"Simple short text",Icon:A.ShortTextIcon,color:"#2d7ff9",property:{dataType:"string",Field:ht}},multiline:{key:"multiline",name:"Multiline",description:"Text with multiple lines",Icon:A.SubjectIcon,color:"#2d7ff9",property:{dataType:"string",multiline:!0,Field:ht}},markdown:{key:"markdown",name:"Markdown",description:"Text with advanced markdown syntax",Icon:A.FormatQuoteIcon,color:"#2d7ff9",property:{dataType:"string",markdown:!0,Field:Xo}},url:{key:"url",name:"Url",description:"Text with URL validation",Icon:A.HttpIcon,color:"#154fb3",property:{dataType:"string",url:!0,Field:ht}},email:{key:"email",name:"Email",description:"Text with email validation",Icon:A.EmailIcon,color:"#154fb3",property:{dataType:"string",email:!0,Field:ht}},select:{key:"select",name:"Select/enum",description:"Select one text value from within an enumeration",Icon:A.ListIcon,color:"#4223c9",property:{dataType:"string",enumValues:[],Field:tn}},multi_select:{key:"multi_select",name:"Multi select",description:"Select multiple text values from within an enumeration",Icon:A.ListAltIcon,color:"#4223c9",property:{dataType:"array",of:{dataType:"string",enumValues:[]},Field:rn}},number_input:{key:"number_input",name:"Number input",description:"Simple number field with validation",Icon:A.NumbersIcon,color:"#bec920",property:{dataType:"number",Field:ht}},number_select:{key:"number_select",name:"Number select",description:"Select a number value from within an enumeration",Icon:A.FormatListNumberedIcon,color:"#bec920",property:{dataType:"number",enumValues:[],Field:tn}},multi_number_select:{key:"multi_number_select",name:"Multiple number select",description:"Select multiple number values from within an enumeration",Icon:A.FormatListNumberedIcon,color:"#bec920",property:{dataType:"array",of:{dataType:"number",enumValues:[]},Field:rn}},file_upload:{key:"file_upload",name:"File upload",description:"Input for uploading single files",Icon:A.UploadFileIcon,color:"#f92d9a",property:{dataType:"string",storage:{storagePath:"{path}"},Field:nn}},multi_file_upload:{key:"multi_file_upload",name:"Multiple file upload",description:"Input for uploading multiple files",Icon:A.DriveFolderUploadIcon,color:"#f92d9a",property:{dataType:"array",of:{dataType:"string",storage:{storagePath:"{path}"}},Field:nn}},reference:{key:"reference",name:"Reference",description:"The value refers to a different collection",Icon:A.LinkIcon,color:"#ff0042",property:{dataType:"reference",Field:jo}},multi_references:{key:"multi_references",name:"Multiple references",description:"Multiple values that refer to a different collection",Icon:A.AddLinkIcon,color:"#ff0042",property:{dataType:"array",of:{dataType:"reference"},Field:Lo}},switch:{key:"switch",name:"Switch",description:"Boolean true or false field (or yes or no, 0 or 1...)",Icon:A.FlagIcon,color:"#20d9d2",property:{dataType:"boolean",Field:_o}},date_time:{key:"date_time",name:"Date/time",description:"A date time select field",Icon:A.ScheduleIcon,color:"#8b46ff",property:{dataType:"date",Field:Wo}},group:{key:"group",name:"Group",description:"Group of multiple fields",Icon:A.BallotIcon,color:"#ff9408",property:{dataType:"map",properties:{},Field:Ho}},key_value:{key:"key_value",name:"Key-value",description:"Flexible field that allows the user to add multiple key-value pairs",Icon:A.BallotIcon,color:"#ff9408",property:{dataType:"map",keyValue:!0,Field:Jo}},repeat:{key:"repeat",name:"Repeat/list",description:"A field that gets repeated multiple times (e.g. multiple text fields)",Icon:A.RepeatIcon,color:"#ff9408",property:{dataType:"array",of:{dataType:"string"},Field:qo}},custom_array:{key:"custom_array",name:"Custom array",description:"A field that saved its value as an array of custom objects",Icon:A.RepeatIcon,color:"#ff9408",property:{dataType:"array",of:[],Field:Ko}},block:{key:"block",name:"Block",description:"A complex field that allows the user to compose different fields together, with a key->value format",Icon:A.ViewStreamIcon,color:"#ff9408",property:{dataType:"array",oneOf:{properties:{}},Field:Zo}}};function ml(e){const t=ar(e);if(!t){console.error("No field id found for property",e);return}return ir[t]}function sr(e,t){const n=mn(e),o=ar(e);if(!o){console.error("No field id found for property",e);return}const l=ir[o],i=n?t[n]:void 0;return Ne(l??{},i??{})}function ar(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"){if(e.keyValue)return"key_value";if(e.properties)return"group"}else if(e.dataType==="array"){const t=e.of;return e.oneOf?"block":Array.isArray(t)?"custom_array":we(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 mn(e){return e.propertyConfig?e.propertyConfig:ar(e)}const za=d.memo(function({HomePage:t=il,customRoutes:n}){const o=ue.useLocation(),l=ie();if(!l)return r.jsx(r.Fragment,{});const i=o.state,s=i&&i.base_location?i.base_location:o,a=[];l.views&&l.views.forEach(h=>{Array.isArray(h.path)?a.push(...h.path.map(u=>bl(u,h))):a.push(bl(h.path,h))});const f=[...l.collections??[]].sort((h,u)=>u.path.length-h.path.length).map(h=>{const u=l.buildUrlCollectionPath(h.id??h.path);return r.jsx(ue.Route,{path:u+"/*",element:r.jsx(cn,{isSubCollection:!1,parentCollectionIds:[],fullPath:h.id??h.path,...h,Actions:Rt(h.Actions)},`collection_view_${h.id??h.path}`)},`navigation_${h.id??h.path}`)}),g=r.jsx(ue.Route,{path:"/",element:r.jsx(t,{})}),p=r.jsx(ue.Route,{path:"*",element:r.jsx(sl,{})});return r.jsxs(ue.Routes,{location:s,children:[f,a,g,p,n]})}),bl=(e,t)=>r.jsx(ue.Route,{path:e,element:t.view},"navigation_view_"+e);function Ua(){const e=typeof window<"u"&&window.matchMedia("(prefers-color-scheme: dark)"),n=(localStorage.getItem("prefers-dark-mode")!=null?localStorage.getItem("prefers-dark-mode")==="true":null)??e,[o,l]=d.useState(n?"dark":"light");d.useEffect(()=>{l(n?"dark":"light"),a(n?"dark":"light")},[n]);const i=d.useCallback(()=>{l("dark"),a("dark")},[e]),s=d.useCallback(()=>{l("light"),a("light")},[]),a=f=>{document.body.style.setProperty("color-scheme",f),document.documentElement.dataset.theme=f},c=d.useCallback(()=>{o==="light"?(e?localStorage.removeItem("prefers-dark-mode"):localStorage.setItem("prefers-dark-mode","true"),i()):(e?localStorage.setItem("prefers-dark-mode","false"):localStorage.removeItem("prefers-dark-mode"),s())},[o,e]);return{mode:o,setMode:l,toggleMode:c}}function La(){const[e,t]=d.useState({}),n=d.useCallback(m=>{const b=localStorage.getItem(m);return b?JSON.parse(b):{}},[]),o=d.useCallback(m=>{const b=`collection_config::${kr(m)}`;return e[b]?e[b]:n(b)},[e,n]),l=d.useCallback((m,b)=>{const y=`collection_config::${kr(m)}`;localStorage.setItem(y,JSON.stringify(b)),t(C=>{const w=C[y],E=Ne(w??n(m),b);return Ne(C,E)})},[n]),[i,s]=d.useState([]),[a,c]=d.useState([]),[f,g]=d.useState([]);d.useEffect(()=>{s(localStorage.getItem("recently_visited_paths")?JSON.parse(localStorage.getItem("recently_visited_paths")):[]),c(localStorage.getItem("favourite_paths")?JSON.parse(localStorage.getItem("favourite_paths")):[]),g(localStorage.getItem("collapsed_groups")?JSON.parse(localStorage.getItem("collapsed_groups")):[])},[]);const p=d.useCallback(m=>{localStorage.setItem("recently_visited_paths",JSON.stringify(m)),s(m)},[]),h=d.useCallback(m=>{localStorage.setItem("favourite_paths",JSON.stringify(m)),c(m)},[]),u=d.useCallback(m=>{localStorage.setItem("collapsed_groups",JSON.stringify(m)),g(m)},[]);return{onCollectionModified:l,getCollectionConfig:o,recentlyVisitedPaths:i,setRecentlyVisitedPaths:p,favouritePaths:a,setFavouritePaths:h,collapsedGroups:f,setCollapsedGroups:u}}v.ArrayContainer=un,v.ArrayContainerItem=gn,v.ArrayCustomShapedFieldBinding=Ko,v.ArrayEnumPreview=zr,v.ArrayItemOptions=dl,v.ArrayOfMapsPreview=Pi,v.ArrayOfReferencesFieldBinding=Lo,v.ArrayOfReferencesPreview=uo,v.ArrayOfStorageComponentsPreview=go,v.ArrayOfStringsPreview=ho,v.ArrayOneOfPreview=po,v.ArrayPropertyEnumPreview=Ur,v.ArrayPropertyPreview=Yr,v.AsyncPreviewComponent=Ti,v.AuthControllerContext=Ar,v.BlockFieldBinding=Zo,v.BooleanPreview=yo,v.COLLECTION_PATH_SEPARATOR=Mn,v.CircularProgressCenter=Xt,v.DEFAULT_FIELD_CONFIGS=ir,v.DatePreview=bo,v.DateTimeFieldBinding=Wo,v.DefaultHomePage=il,v.DeleteConfirmationDialog=Aa,v.Drawer=hl,v.DrawerNavigationItem=pn,v.EmptyValue=At,v.EntityCollectionTable=Rr,v.EntityCollectionView=cn,v.EntityForm=rl,v.EntityPreview=$r,v.EntityReference=Fe,v.EnumValuesChip=Ce,v.ErrorBoundary=re,v.ErrorView=me,v.FieldConfigBadge=da,v.FieldHelperText=ye,v.FireCMS=Ma,v.FireCMSAppBar=cl,v.FireCMSContextInstance=Nr,v.FireCMSLogo=al,v.FormikArrayContainer=er,v.GeoPoint=Vt,v.ImagePreview=so,v.KeyValueFieldBinding=Jo,v.KeyValuePreview=Lr,v.LabelWithIcon=ve,v.MapFieldBinding=Ho,v.MapPropertyPreview=mo,v.MarkdownFieldBinding=Xo,v.ModeControllerContext=Mt,v.ModeControllerProvider=Tl,v.MultiSelectBinding=rn,v.NavigationCollectionCard=ll,v.NavigationGroup=An,v.NavigationRoutes=za,v.NotFoundPage=sl,v.NumberPropertyPreview=vo,v.PropertyFieldBinding=nt,v.PropertyPreview=be,v.ReadOnlyFieldBinding=on,v.ReferenceFieldBinding=jo,v.ReferencePreview=De,v.ReferencePreviewContainer=Zt,v.ReferenceSelectionInner=ol,v.ReferenceWidget=ga,v.RepeatFieldBinding=qo,v.Scaffold=Va,v.SelectFieldBinding=tn,v.SideDialogs=va,v.SkeletonPropertyComponent=ut,v.SnackbarProvider=Nl,v.StorageThumbnail=ao,v.StorageThumbnailInternal=Ao,v.StorageUploadFieldBinding=nn,v.StringPropertyPreview=Gr,v.SwitchControl=Ps,v.SwitchFieldBinding=_o,v.TextFieldBinding=ht,v.UrlComponentPreview=kt,v.VirtualTable=Po,v.addInitialSlash=Ml,v.buildAdditionalFieldDelegate=si,v.buildCollection=ei,v.buildEntityCallbacks=ii,v.buildEnumLabel=Tn,v.buildEnumValueConfig=li,v.buildEnumValues=oi,v.buildFieldConfig=ai,v.buildProperties=ri,v.buildPropertiesOrBuilder=ni,v.buildProperty=ti,v.canCreateEntity=at,v.canDeleteEntity=Ht,v.canEditEntity=Ir,v.defaultDateFormat=Qn,v.deleteEntityWithCallbacks=no,v.enumToObjectEntries=_e,v.flattenObject=Sr,v.fullPathToCollectionSegments=Pe,v.getArrayValuesCount=Un,v.getBracketNotation=Zl,v.getCollectionByPathOrId=Dt,v.getCollectionPathsCombinations=Ot,v.getColorForProperty=ql,v.getColorScheme=Pn,v.getDefaultFieldConfig=ml,v.getDefaultFieldId=ar,v.getDefaultPropertiesOrder=Xl,v.getDefaultValueFor=zt,v.getDefaultValueForDataType=mr,v.getDefaultValuesFor=Ct,v.getFieldConfig=sr,v.getFieldId=mn,v.getHashValue=gr,v.getIcon=Yn,v.getIconForProperty=pe,v.getIconForView=Jt,v.getIconForWidget=Wt,v.getIdIcon=Jl,v.getLabelOrConfigFrom=Lt,v.getLastSegment=Dl,v.getPropertiesWithPropertiesOrder=Gn,v.getPropertyInPath=tt,v.getRandomId=It,v.getReferenceFrom=Ge,v.getReferencePreviewKeys=zn,v.getResolvedPropertyInPath=xr,v.getValueInPath=$e,v.hydrateRegExp=On,v.isDefaultFieldConfigId=pl,v.isEmptyObject=pr,v.isEnumValueDisabled=Gl,v.isHidden=wt,v.isObject=Gt,v.isPropertyBuilder=we,v.isReadOnly=it,v.isReferenceProperty=Vn,v.isValidRegExp=jl,v.joinCollectionLists=_n,v.makePropertiesEditable=Ln,v.makePropertiesNonEditable=$n,v.mergeCollection=Wn,v.mergeDeep=Ne,v.pick=xn,v.plural=Kl,v.randomColor=_l,v.randomString=st,v.removeFunctions=ur,v.removeInPath=Ol,v.removeInitialAndTrailingSlashes=ge,v.removeInitialSlash=Bn,v.removePropsIfExisting=In,v.removeTrailingSlash=kn,v.removeUndefined=hr,v.renderSkeletonCaptionText=ki,v.renderSkeletonIcon=Vr,v.renderSkeletonImageThumbnail=Or,v.renderSkeletonText=Ye,v.resolveArrayProperty=We,v.resolveCollection=Ie,v.resolveCollectionPathIds=fr,v.resolveDefaultSelectedView=Br,v.resolveEntityView=wr,v.resolveEnumValues=Yl,v.resolveNavigationFrom=oo,v.resolvePermissions=Et,v.resolveProperties=yr,v.resolveProperty=xe,v.resolvePropertyEnum=vr,v.sanitizeData=Vl,v.saveEntityWithCallbacks=Qr,v.segmentsToStrippedPath=Dn,v.serializeRegExp=Wl,v.singular=Rl,v.slugify=$t,v.sortProperties=Er,v.stripCollectionPath=kr,v.toKebabCase=Ul,v.toSnakeCase=$l,v.traverseValueProperty=Ut,v.traverseValuesProperties=br,v.unslugify=Ql,v.updateDateAutoValues=Sn,v.useAuthController=je,v.useBrowserTitleAndIcon=pa,v.useBuildLocalConfigurationPersistence=La,v.useBuildModeController=Ua,v.useClearRestoreValue=Se,v.useClipboard=lo,v.useCollectionFetch=ro,v.useDataSource=Te,v.useDebounce=_t,v.useDebounceValue=Hl,v.useEntityCollectionTableController=en,v.useEntityFetch=Tr,v.useFireCMSContext=q,v.useLargeLayout=Qe,v.useModeController=Mr,v.useNavigationController=ie,v.useReferenceDialog=mt,v.useResolvedNavigationFrom=ui,v.useSelectionController=dn,v.useSideDialogContext=nr,v.useSideDialogsController=Bt,v.useSideEntityController=He,v.useSnackbarController=Je,v.useStorageSource=ct,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})});
589
589
  //# sourceMappingURL=index.umd.js.map