@firecms/core 3.0.0-alpha.50 → 3.0.0-alpha.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/ErrorBoundary.d.ts +1 -1
- package/dist/{form/form_field_configs.d.ts → core/field_configs.d.ts} +2 -1
- package/dist/core/index.d.ts +1 -0
- package/dist/form/index.d.ts +0 -1
- package/dist/index.es.js +5892 -5882
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +5 -5
- package/dist/index.umd.js.map +1 -1
- package/package.json +3 -3
- package/src/components/FieldConfigBadge.tsx +5 -2
- package/src/{form/form_field_configs.tsx → core/field_configs.tsx} +9 -1
- package/src/core/index.tsx +2 -0
- package/src/form/PropertyFieldBinding.tsx +1 -1
- package/src/form/index.tsx +0 -2
- package/src/util/property_utils.tsx +1 -1
- package/src/util/resolutions.ts +1 -1
package/dist/index.umd.js
CHANGED
|
@@ -1,8 +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("date-fns/format"),require("date-fns/locale"),require("react-fast-compare"),require("react-router-dom"),require("react-datepicker"),require("react-dropzone"),require("@hello-pangea/dnd"),require("react-image-file-resizer"),require("react-window"),require("react-use-measure"),require("markdown-it"),require("react-markdown-editor-lite"),require("yup"),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","date-fns/format","date-fns/locale","react-fast-compare","react-router-dom","react-datepicker","react-dropzone","@hello-pangea/dnd","react-image-file-resizer","react-window","react-use-measure","markdown-it","react-markdown-editor-lite","yup","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.format,v.locales,v.equal,v.reactRouterDom,v.reactDatepicker,v.reactDropzone,v.dnd,v.Resizer,v.reactWindow,v.useMeasure,v.MarkdownIt,v.MdEditor,v.yup,v.JsSearch,v.Portal))})(this,function(v,r,c,wn,Cn,Ce,f,Cl,El,oe,fe,En,Bn,lt,Bl,kl,sr,xl,Re,Sl,Il,Fl){"use strict";function bt(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 ar=bt(c),kn=bt(El),Ee=bt(Sl),Nl=bt(Il),Tl=bt(Fl),Pl={breadcrumbs:[],set:e=>{}},xn=c.createContext(Pl),Ql=({children:e})=>{const[t,n]=c.useState([]),o=l=>{n(l.breadcrumbs)};return r.jsx(xn.Provider,{value:{breadcrumbs:t,set:o},children:e})},Ml=({children:e})=>r.jsx(wn.SnackbarProvider,{maxSnack:3,autoHideDuration:3500,children:e}),Dl={mode:"light",setMode:e=>{},toggleMode:()=>{}},Dt=c.createContext(Dl),Ol=Dt.Provider,cr=c.createContext({});function Vl(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 Sn(In(e))}function Sn(e){return e.startsWith("/")?e.slice(1):e}function In(e){return e.endsWith("/")?e.slice(0,-1):e}function Gl(e){return e.startsWith("/")?e:`/${e}`}function Yl(e){const t=ue(e);if(t.includes("/")){const n=t.split("/");return n[n.length-1]}return t}function dr(e,t){const n=ue(e),o=n.split("/");if(o.length%2===0)throw Error(`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]+"/"+dr(a,s.subcollections)}else return i??n}function Ot(e,t){const n=ue(e).split("/");if(n.length%2===0)throw Error(`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 Me{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 Fn=(e,...t)=>({...t.reduce((n,o)=>({...n,[o]:e[o]}),{})});function Yt(e){return e&&typeof e=="object"&&!Array.isArray(e)}function Fe(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]=Fe(e[l],t[l]):Object.assign(o,{[l]:t[l]}):Object.assign(o,{[l]:t[l]})}),o}function Le(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:Le(i,s)}}}function zl(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 Ar(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=>Ar(o))}:typeof n=="object"?{[t]:Ar(n)}:{[t]:n}).reduce((t,n)=>({...t,...n}),{}):e}function fr(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 Cn(e)}return Cn(e,{ignoreUnknown:!0})}function ur(e,t){if(typeof e=="function")return e;if(Array.isArray(e))return e.map(n=>ur(n,t));if(typeof e=="object"){const n={};return e===null?e:(Object.keys(e).forEach(o=>{if(!gr(e)){const l=ur(e[o],t),i=typeof l=="string",s=!t||t&&!i||t&&i&&l!=="";l!==void 0&&!gr(l)&&s&&(n[o]=l)}}),n)}return e}function gr(e){return e&&Object.getPrototypeOf(e)===Object.prototype&&Object.keys(e).length===0}function Nn(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]=Nn(l[i],t[i]):l[i]===t[i]&&(o(l)?l.splice(i,1):delete l[i]))}),l}const yt="type",zt="value";function it(e){return e.readOnly||e.dataType==="date"&&e.autoValue?!0:e.dataType==="reference"?!e.path:!1}function vt(e){return typeof e.disabled=="object"&&!!e.disabled.hidden}function ve(e){return typeof e=="function"}function wt(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=wt(e.properties);return Object.keys(t).length===0?void 0:t}else return e.defaultValue?e.defaultValue:hr(e.dataType)}function hr(e){return e==="string"||e==="number"?null:e==="boolean"?!1:e==="date"?null:e==="array"?[]:e==="map"?{}:null}function Tn({inputValues:e,properties:t,status:n,timestampNowValue:o,setDateToMidnight:l}){return pr(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 Ul(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 et(e){return new Me(e.id,e.path)}function pr(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=pr(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??yt,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 Pn(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 Qn(e){const t=Pn(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 Mn(e,t){const n=$t(e,t);if(!n?.color)return Qn(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 Ll(e){return typeof e=="object"&&e.disabled}function Dn(e){if(e!==void 0)return typeof e=="object"?e.label:e}function On(e){return r.jsx(f.Tooltip,{...e,tooltipClassName:"!text-red-500 bg-red-50",children:e.children})}function he({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(On,{title:n,children:l}):l}function mr(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:mr(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 $l=/[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($l);return t?t.map(n=>n.toLowerCase()).join("-"):""},Wl=/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g,jl=e=>{const t=e.match(Wl);return t?t.map(n=>n.toLowerCase()).join("_"):""};function st(e=5){return Math.random().toString(36).slice(2,2+e)}function Hl(){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 Vn="MMMM dd, yyyy, HH:mm:ss",Gn="::";function yr(e){return Yn(Ne(e))}function Yn(e){return e.length===1?e[0]:e.reduce((t,n)=>`${t}${Gn}${n}`)}function Ne(e){return e.split("/").filter((t,n)=>n%2===0)}function Jl(e){return e?e.toString():""}function zn(e){if(!e)return;const t=e.match(/\/(.*?)\/([a-z]*)?$/i);return t?new RegExp(t[1],t[2]||""):new RegExp(e,"")}function ql(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 Zl(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 Un(e,t){const n=ke({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 Xl(e){return r.jsx(f.CircleIcon,{size:e})}function vr(e,t){const n=e?.Icon??f.CircleIcon;return r.jsx(n,{size:t})}function pe(e,t="small",n={}){if(ve(e))return r.jsx(f.FunctionsIcon,{size:t});{const o=tr(e,n);return vr(o,t)}}function Kl(e,t){return ve(e)?"#888":tr(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 wr(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 wr(o.properties,n.slice(1).join("."))}}}function Rl(e){return e.replace(/\.([^.]*)/g,"[$1]")}function Ln(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:Ln(l.properties,l.propertiesOrder??[])}),l&&(n[o]=l)}),n}function ei(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 Ct(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 Cr(e,t,n,o){return Ct(e,t,n,o).edit??jt.edit}function at(e,t,n,o){return Ct(e,t,n,o).create??jt.create}function Ht(e,t,n,o){return Ct(e,t,n,o).delete??jt.delete}function $n(e,t){if(e&&(e=_t(e),e in qt))return e in qt?r.jsx(f.Icon,{iconKey:e,size:"medium",className:t}):void 0}function Jt(e,t){const n=$n(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=f.coolIconKeys.length;return l||(l=f.coolIconKeys[Pn(e.path)%i]),r.jsx(f.Icon,{iconKey:l,size:"medium",className:t})}const qt=f.iconKeys.reduce((e,t)=>(e[t]=t,e),{});function ti(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 ri(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 _n(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)&&!Un(a,t)}).slice(0,o))}function Er(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,Er(i,`${l}[${s}]`))}):Object.assign(n,Er(e[o],l)):n[l]=e[o],n},{})}function Wn(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=Wn([l]);Object.entries(i).forEach(([s,a])=>{const d=`${o}.${s}`;t[d]=Math.max(t[d]||0,a)})}}),t),{})}function jn(e){return Object.keys(e).forEach(t=>{const n=e[t];n.editable=!0,n.dataType==="map"&&n.properties&&jn(n.properties)}),e}function Hn(e){return Object.entries(e).reduce((t,[n,o])=>{if(!ve(o)&&o.dataType==="map"&&o.properties){const l={...o,properties:Hn(o.properties)};t[n]=l}return ve(o)?t[n]=o:t[n]={...o,editable:!1},t},{})}function Br(e,t,n){if(e){const l=e({collection:t,parentPaths:n})??t;return l.subcollections&&(l.subcollections=l.subcollections.map(i=>Br(e,i,[...n,t.path]))),l}else return t}function Jn(e,t,n=[],o){const l=(t??[]).map(s=>{const a=e?.find(d=>d.id===s.id);return a?qn(a,s,n,o):Br(o,s,n)}),i=e.filter(s=>!l.map(a=>a.id).includes(s.id)).map(s=>o?Br(o,s,n):s);return[...l,...i]}function qn(e,t,n=[],o){const l=Jn(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]=Zn(u,t.properties[h]):i[h]=t.properties[h]});const s=Fe(e,t),a=Xn(e),d=Xn(t),A=[...new Set([...d,...a])],g=[...new Set([...e.entityViews??[],...t.entityViews??[]])];let p={...s,subcollections:l,properties:mr(i,A),propertiesOrder:A,entityViews:g};if(o){const h=o({collection:p,parentPaths:n});h&&(p=h)}return p}function Zn(e,t){if(ve(t))return t;{const n=Fe(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]=Zn(h,s[p]))}),{...n,editable:o&&l,properties:g,propertiesOrder:A}}return{...n,editable:o&&l}}}function Xn(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 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}function ci(e){return e}function di(e){return e}function Ai(e){return e}const Kn=c.createContext({}),Te=()=>c.useContext(Kn),Rn=c.createContext({}),ie=()=>c.useContext(Rn),_e=()=>c.useContext(cr),eo=c.createContext({}),Et=()=>c.useContext(eo),to=c.createContext({}),We=()=>c.useContext(to),ro=c.createContext({}),ct=()=>c.useContext(ro),je=()=>{const{enqueueSnackbar:e,closeSnackbar:t}=wn.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])},no=c.createContext(void 0),dt=()=>c.useContext(no),oo=c.createContext({}),fi=({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(oo.Provider,{value:{open:s,close:i},children:[e,t.map((a,d)=>r.jsx(a.Component,{open:!0},`dialog_${d}`))]})},ui=()=>c.useContext(oo),kr=c.createContext({}),X=()=>{const e=c.useContext(kr),t=_e(),n=Et(),o=We(),l=ie(),i=Te(),s=ct(),a=je(),d=dt(),A=ui();return{...e,authController:t,sideDialogsController:n,sideEntityController:o,navigation:l,dataSource:i,storageSource:s,snackbarController:a,userConfigPersistence:d,dialogsController:A}};function lo({path:e,collection:t,filterValues:n,sortBy:o,itemCount:l,searchString:i}){const s=Te(),d=ie().resolveAliasesFrom(e),A=o?o[0]:void 0,g=o?o[1]:void 0,p=X(),[h,u]=c.useState([]),[m,b]=c.useState(!1),[y,w]=c.useState(),[C,E]=c.useState(!1);return c.useEffect(()=>{b(!0);const k=async x=>{if(t.callbacks?.onFetch)try{x=await Promise.all(x.map(B=>t.callbacks.onFetch({collection:t,path:d,entity:B,context:p})))}catch(B){console.error(B)}b(!1),w(void 0),u(x.map(B=>({...B}))),E(!l||x.length<l)},S=x=>{console.error("ERROR",x),b(!1),u([]),w(x)};return s.listenCollection?s.listenCollection({path:d,collection:t,onUpdate:k,onError:S,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(k).catch(S),()=>{})},[d,l,g,A,n,i]),{data:h,dataLoading:m,dataLoadingError:y,noMoreToLoad:C}}const xr={};function Sr({path:e,entityId:t,collection:n,useCache:o=!1}){const l=Te(),s=ie().resolveAliasesFrom(e),a=X(),[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)}xr[`${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&&xr[`${s}/${t}`]?(A(xr[`${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 Ir({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=Be({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=Be({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=Be({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 io({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 so({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=mn({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 gi({path:e}){const t=X(),[n,o]=c.useState(),[l,i]=c.useState(!1),[s,a]=c.useState();return c.useEffect(()=>{t.navigation&&(i(!0),a(void 0),so({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 Fr=()=>c.useContext(Dt),ao=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 k=i.current,S=k&&(k.tagName==="INPUT"||k.tagName==="TEXTAREA"),x=i.current;g()&&!o&&(E?u(E):k?S?(u(x.value),C==="cut"&&(x.value="")):u(k.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}},Nr=()=>c.useContext(xn),hi={xs:0,sm:640,md:768,lg:1024,xl:1280,"2xl":1536,"3xl":1920},Pe=(e="lg")=>{const[t,n]=c.useState(!1);return c.useEffect(()=>{const o=()=>{const l=window.matchMedia(`(min-width: ${hi[e]+1}px)`).matches;n(l)};return o(),window.addEventListener("resize",o),()=>{window.removeEventListener("resize",o)}},[]),t};function Bt(e){const t=ie(),n=Et(),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(Ho,{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 pi=`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=
|
|
2
|
-
`;function mi(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??pi}},[e,t])}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 bi=40,yi=100,vi=200;function ft(e){if(e==="tiny")return bi;if(e==="small")return yi;if(e==="medium")return vi;throw Error("Thumbnail size not mapped")}function He(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 co({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(co,{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=xi(o,t):o.storage?n=Pr(t):n=Ve()}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)=>Tr(l,i))," "]}):o.of.dataType==="map"&&o.of.properties?n=Ci(o.of.properties,t,o.of.previewProperties):o.of.dataType==="string"?o.of.enumValues?n=Bi():o.of.storage?n=Tr(o.of):n=Ei():n=Tr(o.of))}else e.dataType==="map"?n=wi(e,t):e.dataType==="date"?n=Ve():e.dataType==="reference"?n=ki():(e.dataType,n=Ve());return n||null}function wi(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 Ci(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 Ei(){return r.jsx("div",{className:"flex flex-col gap-2",children:[0,1].map((e,t)=>Ve(t))})}function Bi(){return r.jsx("div",{className:"flex flex-col gap-2",children:[0,1].map((e,t)=>r.jsx(r.Fragment,{children:Ve(t)}))})}function Tr(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 Pr(e){const t=e==="tiny"?40:e==="small"?100:200;return r.jsx(f.Skeleton,{width:t,height:t})}function ki(){return r.jsx(f.Skeleton,{width:200,height:100})}function xi(e,t="medium"){return typeof e.url=="boolean"?r.jsxs("div",{style:{display:"flex"},children:[Qr(),Ve()]}):Si(t)}function Si(e){return r.jsx("div",{className:`w-${ft(e)} h-${ft(e)}`,children:Qr()})}function Ve(e,t=120){return r.jsx(f.Skeleton,{width:t},`skeleton_${e}`)}function Ii(e){return r.jsx(f.Skeleton,{height:20})}function Qr(){return r.jsx(f.Skeleton,{width:24,height:24})}const Ao=c.memo(uo,Fi);function Fi(e,t){return e.size===t.size&&e.storagePathOrDownloadUrl===t.storagePathOrDownloadUrl&&e.storeUrl===t.storeUrl}const fo={};function uo({storeUrl:e,storagePathOrDownloadUrl:t,size:n}){const[o,l]=c.useState(void 0),i=ct(),[s,a]=c.useState(fo[t]);if(c.useEffect(()=>{if(!t)return;let g=!1;return i.getDownloadURL(t).then(function(p){g||(a(p),fo[t]=p)}).catch(l),()=>{g=!0}},[t]),!t)return null;const d=s?.metadata?Ni(s?.metadata.contentType):void 0,A=d?.startsWith("image")?"image":d?.startsWith("video")?"video":d?.startsWith("audio")?"audio":"file";return s?.fileNotFound?r.jsx(he,{error:"File not found"}):s?.url?r.jsx(kt,{previewType:A,url:s.url,size:n,hint:t}):Pr(n)}function Ni(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=Dn(s),d=Mn(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 Mr({propertyKey:e,value:t,property:n,size:o}){if(n.enumValues){const l=t,i=hn(n);return r.jsx(we,{enumKey:l,enumValues:i.enumValues,size:o!=="medium"?"small":"medium"})}else if(n.previewAsTag){const l=Qn(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("date-fns/format"),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/format","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.format,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,wn,Cn,Ce,f,fe,El,Bl,oe,kl,dr,lt,En,xl,Sl,Re,Il,Bn,Fl,Nl){"use strict";function bt(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 Ar=bt(c),kn=bt(Bl),Ee=bt(Il),Pl=bt(Fl),Tl=bt(Nl),Ql={breadcrumbs:[],set:e=>{}},xn=c.createContext(Ql),Ml=({children:e})=>{const[t,n]=c.useState([]),o=l=>{n(l.breadcrumbs)};return r.jsx(xn.Provider,{value:{breadcrumbs:t,set:o},children:e})},Dl=({children:e})=>r.jsx(wn.SnackbarProvider,{maxSnack:3,autoHideDuration:3500,children:e}),Ol={mode:"light",setMode:e=>{},toggleMode:()=>{}},Dt=c.createContext(Ol),Vl=Dt.Provider,fr=c.createContext({});function Gl(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 Sn(In(e))}function Sn(e){return e.startsWith("/")?e.slice(1):e}function In(e){return e.endsWith("/")?e.slice(0,-1):e}function Yl(e){return e.startsWith("/")?e:`/${e}`}function zl(e){const t=ue(e);if(t.includes("/")){const n=t.split("/");return n[n.length-1]}return t}function ur(e,t){const n=ue(e),o=n.split("/");if(o.length%2===0)throw Error(`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]+"/"+ur(a,s.subcollections)}else return i??n}function Ot(e,t){const n=ue(e).split("/");if(n.length%2===0)throw Error(`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 Me{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 Fn=(e,...t)=>({...t.reduce((n,o)=>({...n,[o]:e[o]}),{})});function Yt(e){return e&&typeof e=="object"&&!Array.isArray(e)}function Fe(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]=Fe(e[l],t[l]):Object.assign(o,{[l]:t[l]}):Object.assign(o,{[l]:t[l]})}),o}function Le(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:Le(i,s)}}}function Ul(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 gr(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=>gr(o))}:typeof n=="object"?{[t]:gr(n)}:{[t]:n}).reduce((t,n)=>({...t,...n}),{}):e}function hr(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 Cn(e)}return Cn(e,{ignoreUnknown:!0})}function pr(e,t){if(typeof e=="function")return e;if(Array.isArray(e))return e.map(n=>pr(n,t));if(typeof e=="object"){const n={};return e===null?e:(Object.keys(e).forEach(o=>{if(!mr(e)){const l=pr(e[o],t),i=typeof l=="string",s=!t||t&&!i||t&&i&&l!=="";l!==void 0&&!mr(l)&&s&&(n[o]=l)}}),n)}return e}function mr(e){return e&&Object.getPrototypeOf(e)===Object.prototype&&Object.keys(e).length===0}function Nn(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]=Nn(l[i],t[i]):l[i]===t[i]&&(o(l)?l.splice(i,1):delete l[i]))}),l}const yt="type",zt="value";function it(e){return e.readOnly||e.dataType==="date"&&e.autoValue?!0:e.dataType==="reference"?!e.path:!1}function vt(e){return typeof e.disabled=="object"&&!!e.disabled.hidden}function ve(e){return typeof e=="function"}function wt(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=wt(e.properties);return Object.keys(t).length===0?void 0:t}else return e.defaultValue?e.defaultValue:br(e.dataType)}function br(e){return e==="string"||e==="number"?null:e==="boolean"?!1:e==="date"?null:e==="array"?[]:e==="map"?{}:null}function Pn({inputValues:e,properties:t,status:n,timestampNowValue:o,setDateToMidnight:l}){return yr(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 Ll(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 et(e){return new Me(e.id,e.path)}function yr(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=yr(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??yt,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 Tn(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 Qn(e){const t=Tn(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 Mn(e,t){const n=$t(e,t);if(!n?.color)return Qn(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 $l(e){return typeof e=="object"&&e.disabled}function Dn(e){if(e!==void 0)return typeof e=="object"?e.label:e}const Be=({collection:e,path:t,entityId:n,values:o,previousValues:l,userConfigPersistence:i,fields:s})=>{const a=i?.getCollectionConfig(t),d=Le(a,"properties"),A=wt(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;return{[b]:ke({propertyKey:b,propertyOrBuilder:y,values:g,previousValues:p,path:t,propertyValue:w,entityId:n,fields:s})}}).filter(b=>b!==null).reduce((b,y)=>({...b,...y}),{}),u=Fe(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 ke({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 console.debug("Property builder not returning `Property` so it is not rendered",i,o.entityId,e),null;l=ke({...o,propertyValue:t,propertyOrBuilder:s,fromBuilder:!0})}else{const i=e;if(i.dataType==="map"&&i.properties){const s=vr({...o,properties:i.properties,propertyValue:t});l={...i,resolved:!0,fromBuilder:n,properties:s}}else i.dataType==="array"?l=_e({property:i,propertyValue:t,fromBuilder:n,...o}):(i.dataType==="string"||i.dataType==="number")&&i.enumValues&&(l=wr(i,n))}else return null;if(l||(l={...e,resolved:!0,fromBuilder:n}),l.propertyConfig&&!yl(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=ke({propertyOrBuilder:a,propertyValue:t,...o});d&&(l=Fe(d,l))}}return l?{...l,resolved:!0}:null}function _e({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)=>ke({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)=>ke({propertyKey:`${e}.${d}`,propertyOrBuilder:l,propertyValue:a,...o,index:d})).filter(a=>!!a):[],s=ke({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??yt,i=Array.isArray(n)?n.map((a,d)=>{const A=a&&a[l],g=t.oneOf?.properties[A];return!A||!g?null:ke({propertyKey:`${e}.${d}`,propertyOrBuilder:g,propertyValue:n,...o})}).filter(a=>!!a):[],s=vr({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 vr({properties:e,propertyValue:t,...n}){return Object.entries(e).map(([o,l])=>({[o]:ke({propertyKey:o,propertyOrBuilder:l,propertyValue:t&&typeof t=="object"?Le(t,o):void 0,...n})})).filter(o=>o!==null).reduce((o,l)=>({...o,...l}),{})}function wr(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 _l(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 Cr(e,t){return typeof e=="string"?t?.find(n=>n.key===e):e}function Er(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=>Cr(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(...Er({path:y,collections:A.subcollections,currentFullPath:b,contextEntityViews:e.contextEntityViews}))}}break}}return s}function Br(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:Br(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 kr(e,t){if(e)return typeof e=="string"?e:e(t)}const Wl=/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g,jl=e=>{const t=e.match(Wl);return t?t.map(n=>n.toLowerCase()).join("-"):""},Hl=/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g,Jl=e=>{const t=e.match(Hl);return t?t.map(n=>n.toLowerCase()).join("_"):""};function st(e=5){return Math.random().toString(36).slice(2,2+e)}function ql(){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 On="MMMM dd, yyyy, HH:mm:ss",Vn="::";function xr(e){return Gn(Ne(e))}function Gn(e){return e.length===1?e[0]:e.reduce((t,n)=>`${t}${Vn}${n}`)}function Ne(e){return e.split("/").filter((t,n)=>n%2===0)}function Zl(e){return e?e.toString():""}function Yn(e){if(!e)return;const t=e.match(/\/(.*?)\/([a-z]*)?$/i);return t?new RegExp(t[1],t[2]||""):new RegExp(e,"")}function Xl(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 Kl(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 zn(e,t){const n=ke({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 Rl(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 ei(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 Sr(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 Sr(o.properties,n.slice(1).join("."))}}}function ti(e){return e.replace(/\.([^.]*)/g,"[$1]")}function Un(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:Un(l.properties,l.propertiesOrder??[])}),l&&(n[o]=l)}),n}function ri(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 Ct(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 Ct(e,t,n,o).edit??Ht.edit}function at(e,t,n,o){return Ct(e,t,n,o).create??Ht.create}function Jt(e,t,n,o){return Ct(e,t,n,o).delete??Ht.delete}function Ln(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=Ln(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[Tn(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 ni(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 oi(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 $n(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)&&!zn(a,t)}).slice(0,o))}function Fr(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,Fr(i,`${l}[${s}]`))}):Object.assign(n,Fr(e[o],l)):n[l]=e[o],n},{})}function _n(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=_n([l]);Object.entries(i).forEach(([s,a])=>{const d=`${o}.${s}`;t[d]=Math.max(t[d]||0,a)})}}),t),{})}function Wn(e){return Object.keys(e).forEach(t=>{const n=e[t];n.editable=!0,n.dataType==="map"&&n.properties&&Wn(n.properties)}),e}function jn(e){return Object.entries(e).reduce((t,[n,o])=>{if(!ve(o)&&o.dataType==="map"&&o.properties){const l={...o,properties:jn(o.properties)};t[n]=l}return ve(o)?t[n]=o:t[n]={...o,editable:!1},t},{})}function Nr(e,t,n){if(e){const l=e({collection:t,parentPaths:n})??t;return l.subcollections&&(l.subcollections=l.subcollections.map(i=>Nr(e,i,[...n,t.path]))),l}else return t}function Hn(e,t,n=[],o){const l=(t??[]).map(s=>{const a=e?.find(d=>d.id===s.id);return a?Jn(a,s,n,o):Nr(o,s,n)}),i=e.filter(s=>!l.map(a=>a.id).includes(s.id)).map(s=>o?Nr(o,s,n):s);return[...l,...i]}function Jn(e,t,n=[],o){const l=Hn(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]=qn(u,t.properties[h]):i[h]=t.properties[h]});const s=Fe(e,t),a=Zn(e),d=Zn(t),A=[...new Set([...d,...a])],g=[...new Set([...e.entityViews??[],...t.entityViews??[]])];let p={...s,subcollections:l,properties:Br(i,A),propertiesOrder:A,entityViews:g};if(o){const h=o({collection:p,parentPaths:n});h&&(p=h)}return p}function qn(e,t){if(ve(t))return t;{const n=Fe(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]=qn(h,s[p]))}),{...n,editable:o&&l,properties:g,propertiesOrder:A}}return{...n,editable:o&&l}}}function Zn(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 li(e){return e}function ii(e){return e}function si(e){return e}function ai(e){return e}function ci(e){return e}function di(e){return e}function Ai(e){return e}function fi(e){return e}function ui(e){return e}const gi="100vw",hi="55vw",Xn="768px",Kn=c.createContext({}),Pe=()=>c.useContext(Kn),Rn=c.createContext({}),ie=()=>c.useContext(Rn),We=()=>c.useContext(fr),eo=c.createContext({}),Et=()=>c.useContext(eo),to=c.createContext({}),je=()=>c.useContext(to),ro=c.createContext({}),ct=()=>c.useContext(ro),He=()=>{const{enqueueSnackbar:e,closeSnackbar:t}=wn.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])},no=c.createContext(void 0),dt=()=>c.useContext(no),oo=c.createContext({}),pi=({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(oo.Provider,{value:{open:s,close:i},children:[e,t.map((a,d)=>r.jsx(a.Component,{open:!0},`dialog_${d}`))]})},mi=()=>c.useContext(oo),Pr=c.createContext({}),X=()=>{const e=c.useContext(Pr),t=We(),n=Et(),o=je(),l=ie(),i=Pe(),s=ct(),a=He(),d=dt(),A=mi();return{...e,authController:t,sideDialogsController:n,sideEntityController:o,navigation:l,dataSource:i,storageSource:s,snackbarController:a,userConfigPersistence:d,dialogsController:A}};function lo({path:e,collection:t,filterValues:n,sortBy:o,itemCount:l,searchString:i}){const s=Pe(),d=ie().resolveAliasesFrom(e),A=o?o[0]:void 0,g=o?o[1]:void 0,p=X(),[h,u]=c.useState([]),[m,b]=c.useState(!1),[y,w]=c.useState(),[C,E]=c.useState(!1);return c.useEffect(()=>{b(!0);const k=async x=>{if(t.callbacks?.onFetch)try{x=await Promise.all(x.map(B=>t.callbacks.onFetch({collection:t,path:d,entity:B,context:p})))}catch(B){console.error(B)}b(!1),w(void 0),u(x.map(B=>({...B}))),E(!l||x.length<l)},S=x=>{console.error("ERROR",x),b(!1),u([]),w(x)};return s.listenCollection?s.listenCollection({path:d,collection:t,onUpdate:k,onError:S,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(k).catch(S),()=>{})},[d,l,g,A,n,i]),{data:h,dataLoading:m,dataLoadingError:y,noMoreToLoad:C}}const Tr={};function Qr({path:e,entityId:t,collection:n,useCache:o=!1}){const l=Pe(),s=ie().resolveAliasesFrom(e),a=X(),[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)}Tr[`${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&&Tr[`${s}/${t}`]?(A(Tr[`${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 Mr({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=Be({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=Be({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=Be({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 io({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 so({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=Er({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 bi({path:e}){const t=X(),[n,o]=c.useState(),[l,i]=c.useState(!1),[s,a]=c.useState();return c.useEffect(()=>{t.navigation&&(i(!0),a(void 0),so({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 Dr=()=>c.useContext(Dt),ao=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 k=i.current,S=k&&(k.tagName==="INPUT"||k.tagName==="TEXTAREA"),x=i.current;g()&&!o&&(E?u(E):k?S?(u(x.value),C==="cut"&&(x.value="")):u(k.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}},Or=()=>c.useContext(xn),yi={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: ${yi[e]+1}px)`).matches;n(l)};return o(),window.addEventListener("resize",o),()=>{window.removeEventListener("resize",o)}},[]),t};function co(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(co,{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 vi=40,wi=100,Ci=200;function ft(e){if(e==="tiny")return vi;if(e==="small")return wi;if(e==="medium")return Ci;throw Error("Thumbnail size not mapped")}function Je(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 Ao({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 Bt({url:e,previewType:t,size:n,hint:o}){return t?t==="image"?r.jsx(Ao,{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=Ii(o,t):o.storage?n=Gr(t):n=Ve()}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)=>Vr(l,i))," "]}):o.of.dataType==="map"&&o.of.properties?n=Bi(o.of.properties,t,o.of.previewProperties):o.of.dataType==="string"?o.of.enumValues?n=xi():o.of.storage?n=Vr(o.of):n=ki():n=Vr(o.of))}else e.dataType==="map"?n=Ei(e,t):e.dataType==="date"?n=Ve():e.dataType==="reference"?n=Si():(e.dataType,n=Ve());return n||null}function Ei(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 Bi(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 ki(){return r.jsx("div",{className:"flex flex-col gap-2",children:[0,1].map((e,t)=>Ve(t))})}function xi(){return r.jsx("div",{className:"flex flex-col gap-2",children:[0,1].map((e,t)=>r.jsx(r.Fragment,{children:Ve(t)}))})}function Vr(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 Gr(e){const t=e==="tiny"?40:e==="small"?100:200;return r.jsx(f.Skeleton,{width:t,height:t})}function Si(){return r.jsx(f.Skeleton,{width:200,height:100})}function Ii(e,t="medium"){return typeof e.url=="boolean"?r.jsxs("div",{style:{display:"flex"},children:[Yr(),Ve()]}):Fi(t)}function Fi(e){return r.jsx("div",{className:`w-${ft(e)} h-${ft(e)}`,children:Yr()})}function Ve(e,t=120){return r.jsx(f.Skeleton,{width:t},`skeleton_${e}`)}function Ni(e){return r.jsx(f.Skeleton,{height:20})}function Yr(){return r.jsx(f.Skeleton,{width:24,height:24})}const fo=c.memo(go,Pi);function Pi(e,t){return e.size===t.size&&e.storagePathOrDownloadUrl===t.storagePathOrDownloadUrl&&e.storeUrl===t.storeUrl}const uo={};function go({storeUrl:e,storagePathOrDownloadUrl:t,size:n}){const[o,l]=c.useState(void 0),i=ct(),[s,a]=c.useState(uo[t]);if(c.useEffect(()=>{if(!t)return;let g=!1;return i.getDownloadURL(t).then(function(p){g||(a(p),uo[t]=p)}).catch(l),()=>{g=!0}},[t]),!t)return null;const d=s?.metadata?Ti(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(Bt,{previewType:A,url:s.url,size:n,hint:t}):Gr(n)}function Ti(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=Dn(s),d=Mn(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 zr({propertyKey:e,value:t,property:n,size:o}){if(n.enumValues){const l=t,i=wr(n);return r.jsx(we,{enumKey:l,enumValues:i.enumValues,size:o!=="medium"?"small":"medium"})}else if(n.previewAsTag){const l=Qn(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(Bt,{size:o,url:t,previewType:typeof n.url=="string"?n.url:void 0});{if(!t)return r.jsx(r.Fragment,{});const l=t.split(`
|
|
3
2
|
`);return t&&t.includes(`
|
|
4
|
-
`)?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 Dr({propertyKey:e,value:t,property:n,entity:o,size:l}){const i=X(),s=Je({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 Ge=ar.memo(function(t){const n=t.reference;return n instanceof Me?r.jsx(Pi,{...t}):(console.warn("Reference preview received value of type",typeof n),r.jsx(Zt,{onClick:t.onClick,size:t.size,children:r.jsx(he,{error:"Unexpected value. Click to edit",tooltip:JSON.stringify(n)})}))},Ti);function Ti(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 Pi({disabled:e,reference:t,previewProperties:n,size:o,onHover:l,onClick:i,allowEntityNavigation:s=!0}){const a=X(),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(Qi,{reference:t,collection:A,previewProperties:n,size:o,disabled:e,allowEntityNavigation:s,onClick:i,onHover:l})}function Qi({reference:e,collection:t,previewProperties:n,size:o,disabled:l,allowEntityNavigation:i,onClick:s,onHover:a}){const d=X(),A=We(),{entity:g,dataLoading:p,dataLoadingError:h}=Sr({path:e.path,entityId:e.id,collection:t,useCache:!0});g&&go.set(e.pathWithId,g);const u=g??go.get(e.pathWithId),m=c.useMemo(()=>Be({collection:t,path:e.path,values:u?.values,fields:d.propertyConfigs}),[t]),b=c.useMemo(()=>_n(m,d.propertyConfigs,n,o==="small"||o==="medium"?3:1),[n,m,o]);let y;return m?(e?u&&!u.values?y=r.jsx(he,{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:Le(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(he,{error:"Reference not set"}),r.jsx(Zt,{onClick:l?void 0:s,onHover:l?void 0:a,size:o,children:y})):r.jsx(he,{error:"Could not find collection with id "+m})}function Zt({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 go=new Map;function ho({propertyKey:e,value:t,property:n,size:o}){const l=X(),i=Je({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(Ge,{disabled:!A.path,previewProperties:A.previewProperties,size:s,reference:a})},`preview_array_ref_${e}_${d}`)})})}function po({propertyKey:e,entity:t,value:n,property:o,size:l}){const i=X(),s=Je({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 Or({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 Vr({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(Or,{name:e,value:t,enumValues:l.enumValues,size:o}):null}function mo({propertyKey:e,value:t,property:n,entity:o,size:l}){const i=X(),s=Je({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(Mr,{propertyKey:e,property:a,value:d,entity:o,size:l})})},`preview_array_strings_${e}_${A}`))})}function bo({propertyKey:e,value:t,property:n,size:o,entity:l}){const i=X(),s=Je({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??yt,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 yo({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(Gr,{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 Gr({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(Gr,{value:n})})]},`map_preview_table_${t}}`))})}function vo({date:e}){const t=X(),n=t?.locale?kn[t?.locale]:void 0,o=t?.dateTimeFormat??Vn,l=e?Cl(e,o,{locale:n}):"";return r.jsx(r.Fragment,{children:l})}function wo({value:e}){return r.jsx(f.Checkbox,{checked:e})}function Co({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=X();let n;const{property:o,propertyKey:l,value:i,size:s,height:a,width:d,entity:A}=e,g=ke({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(Mr,{...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(Dr,{...e,value:i,property:g}):p.of.dataType==="reference"?n=r.jsx(ho,{...e,value:i,property:g}):p.of.dataType==="string"?p.of.enumValues?n=r.jsx(Vr,{...e,value:i,property:g}):p.of.storage?n=r.jsx(po,{...e,value:i,property:g}):n=r.jsx(mo,{...e,value:i,property:g}):p.of.dataType==="number"&&p.of.enumValues?n=r.jsx(Vr,{...e,value:i,property:g}):n=r.jsx(Dr,{...e,value:i,property:g}):p.oneOf&&(n=r.jsx(bo,{...e,value:i,property:g}))}else n=rt(l,g.dataType,i);else g.dataType==="map"?typeof i=="object"?n=r.jsx(yo,{...e,property:g}):n=rt(l,g.dataType,i):g.dataType==="date"?i instanceof Date?n=r.jsx(vo,{date:i}):n=rt(l,g.dataType,i):g.dataType==="reference"?typeof g.path=="string"?i instanceof Me?n=r.jsx(Ge,{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(wo,{value:i}):n=rt(l,g.dataType,i):g.dataType==="number"?typeof i=="number"?n=r.jsx(Co,{...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(he,{title:"Unexpected value",error:`${JSON.stringify(n)}`})}function Mi({propertyKey:e,value:t,property:n,size:o,entity:l}){const i=X(),s=Je({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 Di=ar.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(ar.Fragment,{children:l})});function Yr({entity:e,collection:t,path:n,className:o}){const l=X(),i=c.useMemo(()=>Be({collection:t,path:n,entityId:e.id,values:e.values,fields:l.propertyConfigs}),[t,n,e]),s=X(),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 Oi(e){return e.dataType==="boolean"?"center":e.dataType==="number"?e.enumValues?"left":"right":e.dataType==="date"?"right":"left"}function Eo(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:Eo(t.of):300}else return e.dataType==="number"?e.enumValues?200:140:e.dataType==="map"?360:e.dataType==="date"?200:e.dataType==="reference"?220:e.dataType==="boolean"?140:200}function zr(e){return`subcollection:${e.id??e.path}`}function Vi(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(`
|
|
5
|
-
`))&&A(u)},onFocus:()=>{g.current=!0},onBlur:()=>{g.current=!1,p()}})}function Ur(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(Or,{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 Gi(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 Yi(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 zi(e){const{locale:t}=X(),{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 Ui(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=Bo(s,e,o,a,l),d||(d=st()+"_"+s.name),d}function Li(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=Bo(s,e,o,a,l),d||(d=st()+"_"+s.name),d}function Bo(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 ko({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(B=>({id:Lr(),storagePathOrDownloadUrl:B,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 B=>{if(A.fileName){const N=await Ui(A.fileName,A,t,e,n,l,B,i);if(!N||N.length===0)throw Error("You need to return a valid filename");return N}return st()+"_"+B.name},[e,t,n,l,i,A]),k=c.useCallback(B=>Li(A.storagePath,A,t,e,n,l,B,i)??"/",[e,t,n,l,i,A]),S=c.useCallback(async(B,N,I)=>{console.debug("onFileUploadComplete",B,N);let T=B;if(A.storeUrl&&(T=(await s.getDownloadURL(B)).url),A.postProcess&&T&&(T=await A.postProcess(T)),!T){console.warn("uploadPathOrDownloadUrl is null");return}let F;N.storagePathOrDownloadUrl=T,N.metadata=I,F=[...w],F=xo(F),C(F);const Q=F.filter(Y=>!!Y.storagePathOrDownloadUrl).map(Y=>Y.storagePathOrDownloadUrl);d(g?Q:Q?Q[0]:null)},[w,g,d,A,s]),x=c.useCallback(async B=>{if(!B.length||a)return;let N;if(g)N=[...w,...await Promise.all(B.map(async I=>(u&&$r(I)&&(I=await Io(I,u)),{id:Lr(),file:I,fileName:await E(I),metadata:p,size:h})))];else{let I=B[0];u&&$r(I)&&(I=await Io(I,u)),N=[{id:Lr(),file:I,fileName:await E(I),metadata:p,size:h}]}N=xo(N),C(N)},[a,E,w,p,g,h]);return{internalValue:w,setInternalValue:C,storage:A,fileNameBuilder:E,storagePathBuilder:k,onFileUploadComplete:S,onFilesAdded:x,multipleFilesSupported:g}}function xo(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 Lr(){return Math.floor(Math.random()*Math.floor(Number.MAX_SAFE_INTEGER))}const So={"image/jpeg":"JPEG","image/png":"PNG","image/webp":"WEBP"},$r=e=>So[e.type]?So[e.type]:null,$i=100,Io=(e,t)=>new Promise(n=>{const o=t.quality===void 0?$i:t.quality,l=o>=0&&o<=100?o:100,i=$r(e);if(!i)throw Error("resizeAndCompressImage: Unsupported image format");Bl.imageFileResizer(e,t.maxWidth||Number.MAX_VALUE,t.maxHeight||Number.MAX_VALUE,i,l,0,s=>n(s),"file")});function Fo({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(he,{title:"Error uploading file",error:d})]})}function No({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(On,{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 _i="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",Wi="pt-0 border-2 border-solid",ji="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",Hi="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 Ji(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}=ko({entityValues:d.values,entityId:d.id,path:A,property:a,propertyKey:t,storageSource:h,onChange:p,value:i,disabled:s});return r.jsx(qi,{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 qi({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 k=u?.metadata,S=!!n,x=je(),{open:B,getRootProps:N,getInputProps:I,isDragActive:T,isDragAccept:F,isDragReject:Q}=Bn.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}=N(),J=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,j=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(_i,"relative w-full h-full flex",`justify-${S?"start":"center"}`,T?Wi:"",F?ji:"",Q?Hi:""),children:[r.jsx("input",{autoFocus:h,...I()}),n.map((z,V)=>{let re;return z.storagePathOrDownloadUrl?re=r.jsx(Zi,{property:_,value:z.storagePathOrDownloadUrl,entity:i,size:E},`storage_preview_${V}`):z.file&&(re=r.jsx(Fo,{entry:z,metadata:k,storagePath:y(z.file),onFileUploadComplete:b,imageSize:j,simple:!0},`storage_progress_${V}`)),re}),!n&&r.jsx("div",{className:"flex-grow m-2 max-w-[200px]",onClick:B,children:r.jsx(f.Typography,{className:"text-gray-400 dark:text-gray-600",variant:"body2",align:"center",children:J})}),r.jsx(No,{showError:te,disabled:p,showExpandIcon:!0,selected:s,openPopup:p?void 0:l,children:r.jsx(f.IconButton,{color:"inherit",size:"small",onClick:B,children:r.jsx(f.EditIcon,{size:"small",className:"text-gray-500"})})})]})}function Zi({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 To(e){const t=X(),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(Xi,{...e,collection:l})}function Xi(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(N=>{o(N?et(N):null)},[o]),w=c.useCallback(N=>{o(N.map(I=>et(I)))},[o]),C=n?Array.isArray(n)?n.map(N=>N.id):n.id?[n.id]:[]:[],E=Bt({multiselect:l,path:i,collection:p,onMultipleEntitiesSelected:w,onSingleEntitySelected:y,selectedEntityIds:C,forceFilter:g}),k=c.useCallback(()=>{A||E.open()},[A,E]),S=!n||Array.isArray(n)&&n.length===0,x=()=>n instanceof Me?r.jsx(Ge,{onClick:A?void 0:k,size:He(s),reference:n,onHover:h,disabled:!i,previewProperties:a}):r.jsx(Zt,{onClick:A?void 0:k,size:He(s),children:r.jsx(he,{title:"Value is not a reference.",error:"Click to edit"})}),B=()=>Array.isArray(n)?r.jsx(r.Fragment,{children:n.map((N,I)=>r.jsx("div",{className:"m-1 w-full",children:r.jsx(Ge,{onClick:A?void 0:k,size:"tiny",reference:N,onHover:h,disabled:!i,previewProperties:a})},`preview_array_ref_${t}_${I}`))}):r.jsx(he,{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&&B(),S&&r.jsxs(f.Button,{onClick:k,size:"small",variant:"outlined",color:"primary",children:["Edit ",d]})]}):r.jsx(he,{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 Po(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 Ri(e);if(t.dataType==="number")return es(e);if(t.dataType==="boolean")return os(e);if(t.dataType==="map")return Ki(e);if(t.dataType==="array")return is(e);if(t.dataType==="date")return rs(e);if(t.dataType==="geopoint")return ts(e);if(t.dataType==="reference")return ns(e);throw console.error("Unsupported data type in yup mapping",t),Error("Unsupported data type in yup mapping")}function Ki({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 Ri({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"?zn(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 es({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 ts({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 rs({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 ns({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 os({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 ls(e){return e.validation?.uniqueInArray?!0:e.dataType==="map"&&e.properties?Object.entries(e.properties).filter(([t,n])=>n.validation?.uniqueInArray):!1}function is({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)=>Le(a,A.path).validate(d)))}else{i=i.of(xt({property:e.of,parentProperty:e,entityId:l}));const a=ls(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 ss=({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}),_r=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]=sr(),E=c.useRef(null);f.useOutsideAlerter(E,()=>{l&&u&&u(void 0)},!!(l&&u));const[k,S]=c.useState(!1),x=c.useMemo(()=>gt(o),[o]),[B,N]=c.useState(!1),[I,T]=c.useState(a),F=!i&&d;c.useEffect(()=>{a&&T(!0);const W=setTimeout(()=>{T(!1)},800);return()=>{clearTimeout(W)}},[a]);let Q=0;if(!p)switch(o){case"l":case"xl":Q=4;break;case"m":Q=2;break;case"s":default:Q=1;break}let Y;switch(A){case"right":Y="flex-end";break;case"center":Y="center";break;case"left":default:Y="flex-start"}const J=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=>{J(),W.stopPropagation()},[J]);c.useEffect(()=>{if(C){const W=C.height>x;k!==W&&S(W)}},[C,k,x]);const j=!F&&l,te=!i&&g&&k,z=!i&&!g&&k,V=c.useCallback(()=>N(!0),[]),re=c.useCallback(()=>N(!1),[]);return r.jsxs("div",{ref:E,className:f.cn("transition-colors duration-100 ease-in-out",`flex relative h-full rounded-md p-${Q} 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":"",!j&&!I&&!F?"border-transparent":"",b?"overflow-hidden":"",j?"bg-gray-50 dark:bg-gray-900":"",j&&!I?"border-primary":"",I?"border-green-500 ":"",F?"border-red-500":""),style:{justifyContent:Y,alignItems:i||!k?"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(ss,{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&&B&&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 as(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 cs=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=X(),{onValueChange:u,size:m,selectedCell:b,select:y,setPopupCell:w}=ks(),C=b?.propertyKey===t&&b?.entity.path===A.path&&b?.entity.id===A.id,[E,k]=c.useState(o),S=c.useRef(o),[x,B]=c.useState(),[N,I]=c.useState(!1),T=c.useCallback(()=>{I(!0),setTimeout(()=>{I(!1)},100)},[]),F=!!l.Field,Q=!!l.Preview,Y=it(l),J=typeof l.disabled=="object"?l.disabled.disabledMessage:void 0,_=g||p||!!l.disabled,j=c.useMemo(()=>xt({property:l,entityId:A.id,customFieldValidator:n,name:t}),[A.id,l,t]);c.useEffect(()=>{oe(o,S.current)||(B(void 0),k(o),S.current=o,T())},[T,o]);const te=P=>{oe(P,S.current)||(I(!1),j.validate(P).then(()=>{B(void 0),S.current=P,u&&u({value:P,propertyKey:t,setError:B,onValueUpdated:T,entity:A,fullPath:d,context:h})}).catch(D=>{B(D)}))};c.useEffect(()=>{j.validate(E).then(()=>B(void 0)).catch(P=>{B(P)})},[E,j,t,l,A]);const z=P=>{let D;P===void 0?D=null:D=P,k(D),te(D)};xe({property:l,value:E,setValue:z});const V=c.useCallback(P=>{y(P?{width:s,height:a,entity:A,cellRect:P,propertyKey:t}:void 0)},[A,a,t,y,s]),re=P=>{w&&w(P?{width:s,height:a,entity:A,cellRect:P,propertyKey:t}:void 0)};let W,q=!1,se=!1,U=!0,M=!1,$=!1,K=!0;const L=!_&&x;if(g||Y)return r.jsx(_r,{size:m,width:s,saved:N,value:E,align:i??"left",fullHeight:!1,disabledTooltip:J??(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:He(m)})},`${t}_${A.path}_${A.id}`);if(!F&&(!Q||C)){if(as(l))W=r.jsx(Ji,{error:x,disabled:_,focused:C,selected:C,openPopup:w?re:void 0,property:l,entity:A,path:d,value:E,previewSize:He(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(Ur,{name:t,multiple:!1,disabled:_,focused:C,valueType:"number",small:He(m)!=="medium",enumValues:D.enumValues,error:x,internalValue:E,updateValue:z}),$=!0):(W=r.jsx(Gi,{align:i,error:x,focused:C,disabled:_,value:E,updateValue:z}),q=!0)}else if(C&&l.dataType==="string"){const D=l;if(D.enumValues)W=r.jsx(Ur,{name:t,multiple:!1,focused:C,disabled:_,valueType:"string",small:He(m)!=="medium",enumValues:D.enumValues,error:x,internalValue:E,updateValue:z}),$=!0;else if(!D.storage){const Se=!!D.multiline||!!D.markdown;W=r.jsx(Vi,{error:x,disabled:_,multiline:Se,focused:C,value:E,updateValue:z}),q=!0}}else if(l.dataType==="boolean")W=r.jsx(Yi,{error:x,disabled:_,focused:C,internalValue:E,updateValue:z});else if(l.dataType==="date")W=r.jsx(zi,{name:t,error:x,disabled:_,mode:l.mode,focused:C,internalValue:E,updateValue:z}),$=!0,U=!1,q=!1;else if(l.dataType==="reference")typeof l.path=="string"&&(W=r.jsx(To,{name:t,internalValue:E,updateValue:z,disabled:_,size:m,path:l.path,multiselect:!1,previewProperties:l.previewProperties,title:l.name,forceFilter:l.forceFilter})),q=!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(Ur,{name:t,multiple:!0,disabled:_,focused:C,small:He(m)!=="medium",valueType:D.of.dataType,enumValues:D.of.enumValues,error:x,internalValue:E,updateValue:z}),q=!0,$=!0,U=!1):D.of.dataType==="reference"&&(typeof D.of.path=="string"&&(W=r.jsx(To,{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})),q=!1))}}return W||(q=!1,se=C&&!W&&!_&&!Y,W=r.jsx(me,{width:s,height:a,entity:A,propertyKey:t,value:E,property:l,size:He(m)})),r.jsx(_r,{size:m,width:s,onSelect:V,selected:C,disabled:_||Y,disabledTooltip:J??"Disabled",removePadding:M,fullHeight:$,saved:N,error:x,align:i,allowScroll:q,showExpandIcon:se,value:E,hideOverflow:U,actions:K&&r.jsx(No,{showError:L,disabled:_,showExpandIcon:se,selected:C,openPopup:_?void 0:re}),children:W},`cell_${t}_${A.path}_${A.id}`)},ds);function ds(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 St({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(B=>{b(!0)},[]),E=c.useCallback((B,N)=>{s(d,B),N!==void 0&&b(N)},[d,s]),k=o===n,x=!(o!==n&&o>0)&&(h||k);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(fs,{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 fs({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 us=({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((S,x,B)=>{const N=e[S],I=100,T=800,F=x>T?T:x<I?I:x,Q={width:F,key:N.key,column:{...N,width:F}};B?a(Q):s(Q)},[e,s,a]),m=c.useCallback(S=>{if(p>=0){const x=g[p].current?.parentElement?.getBoundingClientRect().left;return x?S.clientX-x:void 0}},[g,p]),b=c.useCallback(S=>{document.body.style.cursor=S?"col-resize":"auto"},[]),y=c.useCallback(S=>{S.stopPropagation(),S.preventDefault();const x=m(S);x&&u(p,x,!1)},[u,m,p]),w=c.useCallback(S=>{S.stopPropagation(),S.preventDefault();const x=m(S);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 k=c.useCallback(S=>{h(S),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((S,x)=>{const B=e[x],N=B&&i&&i[B.key]?i[B.key]:void 0;return r.jsx(ne,{children:r.jsx(As,{resizeHandleRef:g[x],columnIndex:x,isResizingIndex:p,onFilterUpdate:o,filter:N,sort:l===B.key?t:void 0,onColumnSort:n,onClickResizeColumn:k,column:B,createFilterField:d,AdditionalHeaderWidget:B.AdditionalHeaderWidget})},"header_"+B.key)}),A&&r.jsx(A,{})]})},gs=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),hs=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)),Xt=c.createContext({});Xt.displayName="VirtualListContext";const ps=c.forwardRef(({children:e,...t},n)=>r.jsx(Xt.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(us,{...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})]})}})),Qo=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:k,endAdornment:S,AddColumnComponent:x}){const B=p?p[0]:void 0,N=p?p[1]:void 0,[I,T]=c.useState(i),F=c.useRef(null),Q=c.useRef(0);c.useEffect(()=>{T(i)},[i]);const[Y,J]=sr(),_=c.useCallback(P=>{T(I.map(D=>D.key===P.column.key?P.column:D))},[I]),j=c.useCallback(P=>{T(I.map(D=>D.key===P.column.key?P.column:D)),a&&a(P)},[I,a]),te=c.useRef();c.useEffect(()=>{te.current=d},[d]);const z=c.useCallback(()=>{Q.current=0,F.current&&F.current.scrollTo(F.current?.scrollLeft,0)},[]),V=c.useCallback(P=>{const D=B===P&&N==="desc",Ae=B===P&&N==="asc"?"desc":D?void 0:"asc",ae=D?void 0:P,Ie=te.current,qe=Ae&&ae?[ae,Ae]:void 0;Ie&&A&&!A(Ie,qe)&&g&&g(void 0),n&&n(),m&&m(qe),z()},[A,N,g,n,m,z,B]),re=c.useCallback(()=>{Q.current=0,m&&m(void 0)},[m]),W=Math.max((t?.length??0)*gt(l)-J.height,0),q=c.useCallback(P=>{o&&(t?.length??0)>0&&P>Q.current+600&&(Q.current=P,o())},[t?.length,o]),se=c.useCallback(({scrollOffset:P,scrollUpdateWasRequested:D})=>{!D&&P>=W-600&&q(P)},[W,q]),U=c.useCallback((P,D)=>{Q.current=0;const Se=te.current;let Ae=Se?{...Se}:{};D?Ae[P.key]=D:delete Ae[P.key],!A||A(Ae,B&&N?[B,N]:void 0)||(Ae=D?{[P.key]:D}:{}),g&&g(Ae),P.key!==B&&re()},[A,N,g,re,B]),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(St,{}):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",k),children:r.jsx(Xt.Provider,{value:{data:t,size:l,cellRenderer:y,columns:I,currentSort:N,onRowClick:s,customView:L,onColumnResize:_,onColumnResizeEnd:j,filter:te.current,onColumnSort:V,onFilterUpdate:U,sortByProperty:B,hoverRow:w??!1,createFilterField:C,rowClassName:E,endAdornment:S,AddColumnComponent:x},children:r.jsx(ms,{outerRef:F,width:J.width,height:J.height,itemCount:(t?.length??0)+(S?1:0),onScroll:se,includeAddColumn:!!x,itemSize:gt(l)},l)})})},oe);function ms({outerRef:e,width:t,height:n,itemCount:o,onScroll:l,itemSize:i,includeAddColumn:s}){const a=c.useCallback(({index:d,style:A})=>r.jsx(Xt.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(gs,{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,k)=>{const S=C&&C[E.key];return r.jsx(hs,{dataKey:E.key,cellRenderer:m,column:E,columns:h,rowData:C,cellData:S,rowIndex:d,columnIndex:k},`cell_${E.key}`)}),s&&r.jsx("div",{className:"w-20"})]},`row_${d}`)}}),[]);return r.jsx(kl.FixedSizeList,{outerRef:e,innerElementType:ps,width:t,height:n,overscanCount:4,itemCount:o,onScroll:l,itemSize:i,children:a})}const Wr=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=Pe(),y=X(),w=c.useCallback(B=>{m?.toggleEntitySelection(t)},[t,m?.toggleEntitySelection]),C=c.useCallback(B=>{B.stopPropagation(),m?.toggleEntitySelection(t)},[t,m?.toggleEntitySelection]),E=h.length>0,k=h.some(B=>B.collapsed||B.collapsed===void 0),S=h.filter(B=>B.collapsed||B.collapsed===void 0),x=h.filter(B=>B.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((B,N)=>r.jsx(f.Tooltip,{title:B.name,children:r.jsx(f.IconButton,{onClick:I=>{I.stopPropagation(),B.onClick({entity:t,fullPath:o,collection:n,context:y,selectionController:m,highlightEntity:A,unhighlightEntity:p,onCollectionChange:g})},size:b?"medium":"small",children:B.icon})},N)),k&&r.jsx(f.Menu,{trigger:r.jsx(f.IconButton,{size:b?"medium":"small",children:r.jsx(f.MoreVertIcon,{})}),children:S.map((B,N)=>r.jsxs(f.MenuItem,{onClick:I=>{I.stopPropagation(),B.onClick({entity:t,fullPath:o,collection:n,context:y,selectionController:m,highlightEntity:A,unhighlightEntity:p,onCollectionChange:g})},children:[B.icon,B.name]},N))}),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:B=>{B.stopPropagation()},className:"font-mono select-all",variant:"caption",color:"secondary",children:[" ",t.id," "]}):r.jsx(f.Skeleton,{})})]})},oe);function bs(e){const t=Pe(),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 Mo={"==":"==","!=":"!=",">":">","<":"<",">=":">=","<=":"<=",in:"In","not-in":"Not in","array-contains":"Contains","array-contains-any":"Contains Any"},jr=["array-contains-any","in","not-in"];function ys({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(F=>F instanceof Me?F.id:null).filter(Boolean):[b.id]:[];function C(F,Q){const Y=jr.includes(u),J=jr.includes(F);let _=Q;Y!==J&&(_=J?_ instanceof Me?[_]:[]:void 0),m(F),y(_);const j=_!==null&&Array.isArray(_)?_.length>0:_!==void 0;n(F&&j?[F,_]:void 0)}const E=ie(),k=c.useMemo(()=>l?E.getCollection(l):void 0,[l]),S=F=>{C(u,et(F))},x=F=>{C(u,F.map(Q=>et(Q)))},B=jr.includes(u),N=Bt({multiselect:B,path:l,collection:k,onSingleEntitySelected:S,onMultipleEntitiesSelected:x,selectedEntityIds:w,onClose:()=>{a(!1)}}),I=()=>{a(!0),N.open()},T=F=>r.jsx("div",{className:"mb-0.5",onMouseEnter:()=>g(!0),onMouseMove:()=>g(!0),onMouseLeave:()=>g(!1),children:r.jsx(Ge,{disabled:!l,previewProperties:s,size:"medium",onClick:I,reference:F,onHover:A,allowEntityNavigation:!1})});return console.log("ReferenceFilterField",{internalValue:b}),r.jsxs("div",{className:"flex w-[440px] flex-row",children:[r.jsx("div",{className:"w-[120px]",children:r.jsx(f.Select,{value:u,onValueChange:F=>{C(F,b)},renderValue:F=>Mo[F],children:d.map(F=>r.jsx(f.SelectItem,{value:F,children:Mo[F]},F))})}),r.jsxs("div",{className:"flex-grow ml-2 h-full",children:[b&&Array.isArray(b)&&r.jsx("div",{children:b.map((F,Q)=>T(F))}),b&&!Array.isArray(b)&&r.jsx("div",{children:T(b)}),(!b||Array.isArray(b)&&b.length===0)&&r.jsx(f.Button,{onClick:I,variant:"outlined",className:"h-full w-full",children:B?"Select references":"Select reference"})]})]})}const Do={"==":"==","!=":"!=",">":">","<":"<",">=":">=","<=":"<=",in:"In","not-in":"Not in","array-contains":"Contains","array-contains-any":"Any"},Hr=["array-contains-any","in","not-in"];function vs({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=Hr.includes(g),k=Hr.includes(y);E!==k&&(C=k?typeof w=="string"||typeof w=="number"?[w]:[]:""),typeof C=="number"&&isNaN(C)&&(C=void 0),p(y),u(C);const S=C!==null&&Array.isArray(C)?C.length>0:C!==void 0;n(y&&S?[y,C]:void 0)}const b=Hr.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=>Do[y],children:a.map(y=>r.jsx(f.SelectItem,{value:y,children:Do[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 ws({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 Oo={"==":"==","!=":"!=",">":">","<":"<",">=":">=","<=":"<=","not-in":"not in",in:"in","array-contains":"Contains","array-contains-any":"Any"},Vo=["array-contains-any","in"];function Cs({name:e,isArray:t,mode:n,value:o,setValue:l,title:i}){const{locale:s}=X(),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=Vo.includes(g),E=Vo.includes(b);C!==E&&(w=E?y?[y]:[]:""),p(b),u(w===null?void 0:w);const k=w!==null&&Array.isArray(w)?w.length>0:w!==void 0;l(b&&k?[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=>Oo[b],children:a.map(b=>r.jsx(f.SelectItem,{value:b,children:Oo[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 Go="collectionGroupParent";function Yo(e,t){return c.useMemo(()=>e.propertiesOrder?zo(e,e.propertiesOrder):Es(e,t),[e,t])}function zo(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?Jr(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=>zr(s)===n)?[{key:n,disabled:!0}]:e.collectionGroup&&n===Go?[{key:n,disabled:!0}]:[null]}).filter(Boolean)}function Es(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=>zr(a));i.push(...s.filter(a=>!i.includes(a)))}return e.collectionGroup&&i.push(Go),zo(e,i)}function Jr(e,t,n){return e.dataType==="map"&&e.spreadChildren&&e.properties?Object.entries(e.properties).flatMap(([o,l])=>Jr(l,`${t}.${o}`,n||!!e.disabled||!!e.readOnly)):[{key:t,disabled:n||!!e.disabled||!!e.readOnly}]}const Bs={},Uo=c.createContext(Bs),ks=()=>c.useContext(Uo),qr=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:k,tableController:{data:S,dataLoading:x,noMoreToLoad:B,dataLoadingError:N,filterValues:I,setFilterValues:T,sortBy:F,setSortBy:Q,setSearchString:Y,clearFilter:J,itemCount:_,setItemCount:j,pageSize:te=50,paginationEnabled:z,checkFilterCombination:V,setPopupCell:re},filterable:W=!0,sortable:q=!0,endAdornment:se,AddColumnComponent:U,AdditionalHeaderWidget:M,additionalIDHeaderWidget:$,emptyComponent:K,getIdColumnWidth:L}){const P=Pe(),D=!!t,Se=A?.selectedEntities?.length>0?A?.selectedEntities:g,Ae=X(),[ae,Ie]=c.useState(E??"m"),[qe,Ye]=c.useState(void 0),Oe=Se?.map(H=>H.id),Ft=!!I&&Object.keys(I).length>0,mt=()=>{!z||x||B||_!==void 0&&j?.(_+te)},Nt=c.useCallback(()=>{j?.(te)},[te]),Ze=c.useCallback(({rowData:H})=>{if(console.debug("EntityCollectionTable click"),!y)return p&&p(H)},[p,y]),Xe=c.useCallback(H=>{u&&u(H),Ie(H)},[]),Tt=c.useCallback(H=>Y?.(H),[]),Ke=c.useMemo(()=>w?w.map(H=>({[H.key]:H})).reduce((H,ge)=>({...H,...ge}),{}):{},[w]);c.useEffect(()=>{const H=ge=>{ge.keyCode===27&&Qt()};return document.addEventListener("keydown",H,!1),()=>{document.removeEventListener("keydown",H,!1)}});const Pt=c.useCallback(H=>{Ye(H)},[]),Qt=c.useCallback(()=>{Ye(void 0)},[]),G=s,O=c.useCallback(({column:H,columnIndex:ge,rowData:de,rowIndex:Qe})=>{const le=de,ze=H.key;let Ue=H.custom?.disabled;const vn=le.values?Le(le.values,ze):void 0,ot=a?.({propertyKey:ze,propertyValue:vn,entity:le})??H.custom.resolvedProperty;return ot?.disabled||(Ue=!1),ot?r.jsx(ne,{children:le?r.jsx(cs,{readonly:!y,align:H.align??"left",propertyKey:ze,property:ot,value:le?.values?Le(le.values,ze):void 0,customFieldValidator:G,columnIndex:ge,width:H.width,height:gt(ae),entity:le,disabled:Ue,path:le.path},`property_table_cell_${le.id}_${ze}`):Ve()}):null},[G,y,ae,Oe]),Z=c.useCallback(({column:H,rowData:ge,width:de})=>{const Qe=ge,le=Ke[H.key],ze=le.dependencies?Object.entries(Qe.values).filter(([ot,wl])=>le.dependencies.includes(ot)).reduce((ot,wl)=>({...ot,...wl}),{}):Qe,Ue=le.Builder;if(!Ue&&!le.value)throw new Error("When using additional fields you need to provide a Builder or a value");const vn=Ue?r.jsx(Ue,{entity:Qe,context:Ae}):r.jsx(r.Fragment,{children:le.value?.({entity:Qe,context:Ae})});return r.jsx(_r,{width:de,size:ae,value:ze,selected:!1,disabled:!0,align:"left",allowScroll:!1,showExpandIcon:!1,disabledTooltip:"This column can't be edited directly",children:r.jsx(ne,{children:vn})},`additional_table_cell_${Qe.id}_${H.key}`)},[Ke,ae,Oe]),R=c.useMemo(()=>{const H=Object.entries(k).flatMap(([de,Qe])=>Jr(Qe,de)).map(({key:de,disabled:Qe})=>{const le=wr(k,de);if(!le)throw Error("Internal error: no property found in path "+de);const ze=Lo(le);return{key:de,align:Oi(le),icon:Ue=>pe(le,"small"),title:le.name??de,sortable:q&&(t?Object.keys(t).includes(de):!0),filter:!D&&ze,width:Eo(le),resizable:!0,custom:{resolvedProperty:le,disabled:Qe},AdditionalHeaderWidget:({onHover:Ue})=>M?r.jsx(M,{property:le,propertyKey:de,onHover:Ue}):void 0}}),ge=w?w.map(de=>({key:de.key,align:"left",sortable:!1,title:de.name,width:de.width??200})):[];return[...H,...ge]},[w,D,t,k,q]),ee=c.useMemo(()=>({key:"id_ewcfedcswdf3",width:L?.()??(P?160:130),title:"ID",resizable:!1,frozen:P,headerAlign:"center",align:"center",AdditionalHeaderWidget:()=>$}),[L,P]),ce=c.useMemo(()=>[ee,...C.map(H=>R.find(ge=>ge.key===H.key)).filter(Boolean)],[R,C,ee]),De=c.useCallback(H=>{const ge=H.column,de=H.columns,Qe=ge.key;if(H.columnIndex===0)return i?i({entity:H.rowData,size:ae,width:ge.width,frozen:ge.frozen}):r.jsx(Wr,{entity:H.rowData,width:ge.width,frozen:ge.frozen,isSelected:!1,size:ae});if(Ke[Qe])return Z(H);if(H.columnIndex<de.length+1)return O(H);throw Error("Internal: columns not mapped properly")},[Ke,i,ae,Z,O]),Mt=c.useCallback(H=>{T?.({...H,...t})},[t]);return r.jsx(Uo.Provider,{value:{setPopupCell:re,select:Pt,onValueChange:d,size:ae,selectedCell:qe,selectedEntityIds:Oe},children:r.jsxs("div",{className:"h-full w-full flex flex-col bg-white dark:bg-gray-950",children:[r.jsx(bs,{forceFilter:D,filterIsSet:Ft,onTextSearch:m?Tt:void 0,clearFilter:J,size:ae,onSizeChanged:Xe,title:l,actionsStart:n,actions:o,loading:x}),r.jsx(Qo,{data:S,columns:ce,cellRenderer:De,onRowClick:y?void 0:p?Ze:void 0,onEndReached:mt,onResetPagination:Nt,error:N,paginationEnabled:z,onColumnResize:h,size:ae,loading:x,filter:I,onFilterUpdate:T?Mt:void 0,sortBy:F,onSortByUpdate:Q,hoverRow:b,emptyComponent:K,checkFilterCombination:V,createFilterField:W?xs:void 0,rowClassName:c.useCallback(H=>Oe?.includes(H.id)?"bg-gray-100 bg-opacity-75 dark:bg-gray-800 dark:bg-opacity-75":"",[Oe]),className:"flex-grow",endAdornment:se,AddColumnComponent:U})]})})},oe);function xs({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(ys,{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(vs,{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(ws,{value:t,setValue:n,name:e,title:A})}else if(d.dataType==="date"){const A=d.name;return r.jsx(Cs,{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 Lo(e,t=!1){return t?["string","number","date","reference"].includes(e.dataType):e.dataType==="array"?e.of?Lo(e.of,!0):!1:["string","number","boolean","date","reference","array"].includes(e.dataType)}function Ss({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 Is(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 Fs=50;function Zr({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=Te(),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:Fs,[y,w]=c.useState(),[C,E]=c.useState(m?b:void 0),k=c.useCallback((z,V)=>p.isFilterCombinationValid?p.isFilterCombinationValid({path:h,collection:t,filterValues:z,sortBy:V}):!0,[]),S=c.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]),[x,B]=c.useState(u??i??void 0),[N,I]=c.useState(S),T=c.useCallback(()=>B(u??void 0),[u]),F=c.useCallback(z=>{if(u){console.warn("Filter is not compatible with the force filter. Ignoring filter");return}z&&Object.keys(z).length===0?B(void 0):B(z)},[u]),{data:Q,dataLoading:Y,noMoreToLoad:J,dataLoadingError:_}=lo({path:e,collection:t,filterValues:x,sortBy:N,searchString:y,itemCount:C}),j=Ss({data:Q,entitiesDisplayedFirst:n});return{data:Is(j,{filterValues:x,sortBy:N,searchString:y,lastDeleteTimestamp:o}),dataLoading:Y,noMoreToLoad:J,dataLoadingError:_,filterValues:x,setFilterValues:F,sortBy:N,setSortBy:I,searchString:y,setSearchString:w,clearFilter:T,itemCount:C,setItemCount:E,paginationEnabled:m,pageSize:b,checkFilterCombination:k,popupCell:d,setPopupCell:A}}function $o({entityOrEntitiesToDelete:e,collection:t,onClose:n,open:o,callbacks:l,onEntityDelete:i,onMultipleEntitiesDelete:s,path:a}){const d=Te(),A=je(),[g,p]=c.useState(!1),[h,u]=c.useState(),[m,b]=c.useState(),y=X();c.useEffect(()=>{if(e){const F=Array.isArray(e)&&e.length===1?e[0]:e;u(F),b(Array.isArray(F))}},[e]);const w=c.useMemo(()=>Be({collection:t,path:a,fields:y.propertyConfigs}),[t,a]),C=c.useCallback(()=>{n()},[n]),E=c.useCallback(F=>{console.debug("Deleted",F)},[]),k=c.useCallback((F,Q)=>{A.open({type:"error",message:"Error deleting: "+Q?.message}),console.error("Error deleting entity"),console.error(Q)},[w.name]),S=c.useCallback((F,Q)=>{A.open({type:"error",message:"Error before deleting: "+Q?.message}),console.error(Q)},[w.name]),x=c.useCallback((F,Q)=>{A.open({type:"error",message:"Error after deleting: "+Q?.message}),console.error(Q)},[w.name]),B=c.useCallback(F=>io({dataSource:d,entity:F,collection:w,callbacks:l,onDeleteSuccess:E,onDeleteFailure:k,onPreDeleteHookError:S,onDeleteSuccessHookError:x,context:y}),[d,w,l,E,k,S,x,y]),N=c.useCallback(async()=>{h&&(p(!0),m?Promise.all(h.map(B)).then(F=>{p(!1),s&&h&&s(a,h),F.every(Boolean)?A.open({type:"success",message:`${w.name}: multiple deleted`}):F.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()}):B(h).then(F=>{p(!1),F&&(i&&h&&i(a,h),A.open({type:"success",message:`${w.singularName??w.name} deleted`}),n())}))},[h,m,B,s,a,n,A,w.name,i]);let I;if(h&&m)I=r.jsx(r.Fragment,{children:"Multiple entities"});else{const F=h;I=F?r.jsx(Yr,{entity:F,collection:t,path:a}):r.jsx(r.Fragment,{})}const T=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:F=>F?void 0:n(),children:[r.jsxs(f.DialogContent,{fullHeight:!0,children:[r.jsx(f.Typography,{variant:"subtitle2",className:"p-4",children:T}),!m&&r.jsx("div",{className:"p-4",children:I})]}),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:N,variant:"filled",color:"primary",children:"Ok"})]})]})}function Kt(e){return Array.isArray(e)?e:e?[e]:[]}function Ns({collection:e,relativePath:t,parentCollectionIds:n,onNewClick:o,onMultipleDeleteClick:l,selectionEnabled:i,path:s,selectionController:a,tableController:d,collectionEntitiesCount:A}){const g=X(),p=g.plugins??[],h=_e(),u=Pe(),m=a.selectedEntities,b=at(e,h,Ne(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=Ht(e,h,Ne(s),null);let w;if(i){const k=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:k})}const C={path:s,relativePath:t,parentCollectionIds:n,collection:e,selectionController:a,context:g,tableController:d,collectionEntitiesCount:A},E=Kt(e.Actions).map((k,S)=>r.jsx(ne,{children:r.jsx(k,{...C})},`actions_${S}`));return p&&p.forEach((k,S)=>{k.collections?.CollectionActions&&E.push(...Kt(k.collections?.CollectionActions).map((x,B)=>r.jsx(ne,{children:r.jsx(x,{...C,...k.collections?.collectionActionsProps})},`plugin_actions_${S}_${B}`)))}),r.jsxs(r.Fragment,{children:[E,w,b]})}function Ts({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 Ps(){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 Qs=({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 Ms(e){return e.open?r.jsx(Ds,{...e}):null}function Ds({tableKey:e,entity:t,customFieldValidator:n,propertyKey:o,collection:l,path:i,cellRect:s,open:a,onClose:d,onCellValueChange:A,container:g}){const p=Te(),h=X(),[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),S(V?.values)}}):()=>{},[p,w,l,i,a]);const[k,S]=c.useState(C?.values),x=l?Be({collection:l,path:i,values:k,entityId:w,fields:h.propertyConfigs}):void 0,B=Ps(),N=c.useRef(null),I=c.useRef(null),T=c.useRef(!1),F=c.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]),Q=c.useCallback(({x:V,y:re})=>{const W=N.current?.getBoundingClientRect();if(!W)throw Error("normalizePosition called before draggableBoundingRect is set");return{x:Math.max(0,Math.min(V,B.width-W.width)),y:Math.max(0,Math.min(re,B.height-W.height))}},[B]),Y=c.useCallback(V=>{const re=N.current?.getBoundingClientRect();if(!s||!re)return;const W=V??Q(F());(!b||W.x!==b.x||W.y!==b.y)&&y(W)},[s,F,Q,b]);Ts({containerRef:N,innerRef:I,x:b?.x,y:b?.y,onMove:Y}),c.useEffect(()=>{T.current=!1},[o,C]),c.useLayoutEffect(()=>{const V=N.current?.getBoundingClientRect();!s||!V||T.current||(Y(),T.current=!0)},[s,Y,T.current]),c.useLayoutEffect(()=>{Y(b)},[B,s]);const J=c.useMemo(()=>{if(!(!x||!w))return Po(w,o&&x.properties[o]?{[o]:x.properties[o]}:{},n)},[x,w,o,n]),_=c.useCallback(()=>Y(b),[b,Y]),j=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:J,validateOnMount:!0,validate:V=>console.debug("Validating",V),onSubmit:(V,re)=>{j(V).then(()=>d()).finally(()=>re.setSubmitting(!1))},children:({values:V,setFieldValue:re,handleSubmit:W,isSubmitting:q})=>{if(c.useEffect(()=>{oe(V,k)||S(V)},[V]),!C)return r.jsx(he,{error:"PopupFormField misconfiguration"});if(!x)return r.jsx(r.Fragment,{});const se=q,U={collection:x,entityId:w,values:V,path:i,setFieldValue:re,save:j},M=o&&tt(x.properties,o),$=o&&M?{propertyKey:o,disabled:q||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:I,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(P=>{P.form?.provider&&(K=r.jsx(P.form.provider.Component,{status:"existing",path:i,collection:x,entity:C,context:h,currentEntityId:w,formContext:U,...P.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:N,children:[r.jsx(Qs,{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(Tl.Root,{asChild:!0,container:g,children:z})}const Os={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)}},_o={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)}},Wo={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($o,{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)}},Vs="collectionGroupParent",Xr=c.memo(function({fullPath:t,parentCollectionIds:n,isSubCollection:o,className:l,...i}){const s=Te(),a=ie(),d=We(),A=_e(),g=dt(),p=X(),h=c.useRef(null),u=c.useMemo(()=>{const O=g?.getCollectionConfig(t);return O?Fe(i,O):i},[i,t,g?.getCollectionConfig]),m=at(u,A,Ne(t),null),[b,y]=c.useState(void 0),[w,C]=c.useState(void 0),[E,k]=c.useState(0),[S,x]=c.useState(0),B=c.useCallback(()=>{const O=b;setTimeout(()=>{O===b&&y(void 0)},2400)},[b]),N=c.useCallback(O=>Cr(u,A,Ne(t),O??null)?u.inlineEditing===void 0||u.inlineEditing:!1,[u,A,t]),I=u.selectionEnabled===void 0||u.selectionEnabled,T=!N(),[F,Q]=c.useState(!1),Y=Kr(),J=u.selectionController??Y,{selectedEntities:_,toggleEntitySelection:j,isEntitySelected:te,setSelectedEntities:z}=J;c.useEffect(()=>{C(void 0)},[_]);const V=Zr({fullPath:t,collection:u,entitiesDisplayedFirst:[],lastDeleteTimestamp:E}),re=c.useRef(Math.random().toString(36)),W=V.popupCell,q=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:B})),[t,u,d]),U=c.useCallback(()=>{p.onAnalyticsEvent?.("new_entity_click",{path:t}),d.open({path:t,collection:u,updateUrl:!0,onClose:B})},[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,Z)=>{p.onAnalyticsEvent?.("single_entity_deleted",{path:t}),z(R=>R.filter(ee=>ee.id!==Z.id)),k(Date.now())},[p,t,z]),K=c.useCallback((O,Z)=>{p.onAnalyticsEvent?.("multiple_entities_deleted",{path:t}),z([]),C(void 0),k(Date.now())},[z]);let L;p?.plugins&&(L=p.plugins.find(O=>O.collectionView?.AddColumnComponent)?.collectionView?.AddColumnComponent);const P=c.useCallback((O,Z)=>{if(g){const R=g.getCollectionConfig(O),ee=Fe(R,Z);g.onCollectionModified(O,ee)}},[g]),D=c.useCallback(({width:O,key:Z})=>{if(!tt(u.properties,Z))return;const R=jo(Z,O);P(t,R)},[u,P,t]),Se=c.useCallback(O=>{g&&P(t,{defaultSize:O})},[P,t,g]),Ae=at(u,A,Ne(t),null),ae=c.useCallback(({name:O,value:Z,property:R,entityId:ee})=>s.checkUniqueField(t,O,Z,ee),[t]),Ie=({fullPath:O,context:Z,value:R,propertyKey:ee,onValueUpdated:ce,setError:De,entity:Mt})=>{const H=Ce.setIn({...Mt.values},ee,R),ge={path:O,entityId:Mt.id,values:H,previousValues:Mt.values,collection:u,status:"existing"};return Ir({...ge,collection:u,callbacks:u.callbacks,dataSource:s,context:Z,onSaveSuccess:()=>ce(),onSaveFailure:de=>{console.error("Save failure"),console.error(de),De(de)}})},qe=a.resolveAliasesFrom(t),Ye=c.useMemo(()=>Be({collection:u,path:t,fields:p.propertyConfigs}),[u,t]),Oe=c.useCallback(({propertyKey:O,propertyValue:Z,entity:R})=>{let ee=tt(u.properties,O);return ee||(ee=tt(Ye.properties,O)),ke({propertyKey:O,propertyOrBuilder:ee,path:t,propertyValue:Z,values:R.values,entityId:R.id,fields:p.propertyConfigs})},[u.properties,p.propertyConfigs,t,Ye.properties]),Ft=Yo(Ye,!0),mt=c.useMemo(()=>{const O=u.subcollections?.map(R=>({key:zr(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})}))??[],Z=u.collectionGroup?[{key:Vs,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(Ge,{reference:ce,size:"tiny"},ce.path+"/"+ce.id))})}}]:[];return[...u.additionalFields??[],...O,...Z]},[u,t]),Nt=c.useCallback(()=>{k(Date.now())},[]),Ze=Pe(),Xe=c.useCallback(({entity:O,customEntityActions:Z})=>{const R=O?Ht(u,A,Ne(t),O):!0,ee=[Os];return Ae&&ee.push(_o),R&&ee.push(Wo),Z&&ee.push(...Z),ee},[A,u,Ae,t]),Tt=c.useCallback(()=>{const O=Xe({}),Z=O.filter(ce=>ce.collapsed!==!1),ee=O.filter(ce=>ce.collapsed===!1).length*(Ze?40:30);return(Ze?80+ee:70+ee)+(Z.length>0?Ze?40:30:0)},[Ze,Xe]),Ke=c.useCallback(({entity:O,size:Z,width:R,frozen:ee})=>{const ce=te(O),De=Xe({entity:O,customEntityActions:u.entityActions});return r.jsx(Wr,{entity:O,width:R,frozen:ee,isSelected:ce,selectionEnabled:I,size:Z,highlightEntity:y,unhighlightEntity:B,collection:u,fullPath:t,actions:De,hideId:u?.hideIdFromCollection,onCollectionChange:Nt,selectionController:J})},[te,u,A,t,I,j,Ae]),Pt=r.jsx(f.Popover,{open:F,onOpenChange:Q,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=>{Q(!0),O.stopPropagation()}:void 0,children:`${u.name}`}),r.jsx(Gs,{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 Qt({property:O,propertyKey:Z,onHover:R}){return p.plugins?r.jsx(r.Fragment,{children:p.plugins.filter(ee=>ee.collectionView?.HeaderAction).map((ee,ce)=>{const De=ee.collectionView.HeaderAction;return r.jsx(De,{onHover:R,propertyKey:Z,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(qr,{additionalFields:mt,tableController:V,displayedColumnIds:Ft,onSizeChanged:Se,onEntityClick:se,onColumnResize:D,onValueChange:Ie,tableRowActionsBuilder:Ke,uniqueFieldValidator:ae,title:Pt,selectionController:J,highlightedEntities:b?[b]:[],defaultSize:u.defaultSize,properties:Ye.properties,getPropertyFor:Oe,actions:r.jsx(Ns,{parentCollectionIds:n??[],collection:u,tableController:V,onMultipleDeleteClick:M,onNewClick:U,path:t,relativePath:u.path,selectionController:J,selectionEnabled:I,collectionEntitiesCount:S}),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:T,inlineEditing:N(),AdditionalHeaderWidget:Qt,AddColumnComponent:G,getIdColumnWidth:Tt,additionalIDHeaderWidget:r.jsx(Ys,{path:t,collection:u})},`collection_table_${t}`),r.jsx(Ms,{open:!!W,onClose:q,cellRect:W?.cellRect,propertyKey:W?.propertyKey,collection:u,entity:W?.entity,tableKey:re.current,customFieldValidator:ae,path:qe,onCellValueChange:Ie,container:h.current},`popup_form_${W?.propertyKey}_${W?.entity?.id}`),w&&r.jsx($o,{entityOrEntitiesToDelete:w,path:t,collection:u,callbacks:u.callbacks,open:!!w,onEntityDelete:$,onMultipleEntitiesDelete:K,onClose:()=>C(void 0)})]})},oe);function Kr(){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 Gs({fullPath:e,collection:t,filter:n,sortBy:o,onCountChange:l}){const i=Te(),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 jo(e,t){if(e.includes(".")){const[n,...o]=e.split(".");return{properties:{[n]:jo(o.join("."),t)}}}return{properties:{[e]:{columnWidth:t}}}}function Ys({collection:e,path:t}){const[n,o]=c.useState(!1),[l,i]=c.useState(""),s=We();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 Ho({onSingleEntitySelected:e,onMultipleEntitiesSelected:t,multiselect:n,collection:o,path:l,selectedEntityIds:i,description:s,forceFilter:a,maxSelection:d}){console.log("ReferenceSelectionInner");const A=nr(),g=We(),p=ie(),h=X(),u=p.resolveAliasesFrom(l),m=Te(),[b,y]=c.useState([]),w=Kr();c.useEffect(()=>{let F=!1;const Q=i?.map(Y=>Y?.toString()).filter(Boolean);return Q&&o?Promise.all(Q.map(Y=>m.fetchEntity({path:u,entityId:Y,collection:o}))).then(Y=>{if(!F){const J=Y.filter(_=>_!==void 0);w.setSelectedEntities(J),y(J)}}):(w.setSelectedEntities([]),y([])),()=>{F=!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=F=>{console.debug("ReferenceSelectionInner toggleEntitySelection",F);let Q;const Y=w.selectedEntities;if(h.onAnalyticsEvent?.("reference_selection_toggle",{path:u,entityId:F.id}),Y){if(Y.map(J=>J.id).indexOf(F.id)>-1)Q=Y.filter(J=>J.id!==F.id);else{if(d&&Y.length>=d)return;Q=[...Y,F]}w.setSelectedEntities(Q),t&&t(Q)}},k=F=>{console.debug("ReferenceSelectionInner onEntityClick",F),!n&&e?(h.onAnalyticsEvent?.("reference_selected_single",{path:u,entityId:F.id}),e(F),A.close(!1)):E(F)},S=()=>{h.onAnalyticsEvent?.("reference_selection_new_entity",{path:u}),g.open({path:u,collection:o,updateUrl:!0,onUpdate:({entity:F})=>{y([F,...b]),k(F)},closeOnSave:!0})},x=({entity:F,size:Q,width:Y,frozen:J})=>{const _=w.selectedEntities,j=_&&_.map(te=>te.id).indexOf(F.id)>-1;return r.jsx(Wr,{width:Y,frozen:J,entity:F,size:Q,isSelected:j,selectionEnabled:n,hideId:o?.hideIdFromCollection,fullPath:u,selectionController:w})},B=c.useCallback(F=>{F.stopPropagation(),A.close(!1)},[A]);if(!o)return r.jsx(he,{error:"Could not find collection with id "+o});const N=c.useMemo(()=>Be({collection:o,path:u,values:{},fields:h.propertyConfigs}),[o,h.propertyConfigs,u]),I=Yo(N,!1),T=Zr({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(qr,{displayedColumnIds:I,onEntityClick:k,tableController:T,tableRowActionsBuilder:x,title:r.jsx(f.Typography,{variant:"subtitle2",children:o.singularName?`Select ${o.singularName}`:`Select from ${o.name}`}),defaultSize:o.defaultSize,properties:N.properties,forceFilter:a,inlineEditing:!1,selectionController:w,actions:r.jsx(zs,{collection:o,path:u,onNewClick:S,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:B,color:"primary",variant:"filled",children:"Done"})]})]})}function zs({collection:e,path:t,onClear:n,onNewClick:o}){const l=_e(),i=Pe(),s=o?d=>{d.preventDefault(),o()}:void 0,a=at(e,l,Ne(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 Rr({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 Jo({view:e,path:t,collection:n,url:o,name:l,description:i,onClick:s}){const a=dt(),d=Jt(n??e),A=fe.useNavigate(),g=X(),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 Us({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 Ls({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(Us,{entry:l},l.path))})})}const en={};function $s(){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||(en[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||!en[e.key]||t.current.scrollTo({top:en[e.key],behavior:"auto"})},[e]),{containerRef:t,scroll:n,direction:l}}const ht=new Nl.Search("url");ht.addIndex("name"),ht.addIndex("description"),ht.addIndex("group"),ht.addIndex("path");function qo({additionalChildrenStart:e,additionalChildrenEnd:t}){const n=X(),o=ie();if(!o.topLevelNavigation)throw Error("Navigation not ready in FireCMSHomePage");const{containerRef:l,scroll:i,direction:s}=$s(),{navigationEntries:a,groups:d}=o.topLevelNavigation,[A,g]=c.useState(null),p=A?a.filter(w=>A.includes(w.url)):a;c.useEffect(()=>{ht.addDocuments(a)},[a]);const h=c.useCallback(w=>{if(!w||w==="")g(null);else{const C=ht.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 k=C.homePage.includeSection(w);return r.jsx(Rr,{group:k.title,children:k.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(Ls,{hidden:!!A}),e,m,u.map((w,C)=>{const E=[],k={group:w,context:n};n.plugins&&n.plugins.forEach(x=>{x.homePage?.AdditionalCards&&E.push(...Kt(x.homePage?.AdditionalCards))});const S=p.filter(x=>x.group===w||!x.group&&w===void 0);return S.length===0&&E.length===0?null:r.jsx(Rr,{group:w,children:r.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:[S.map(x=>r.jsx("div",{className:"col-span-1",children:r.jsx(Jo,{...x,onClick:()=>{const B=x.type==="collection"?"home_navigate_to_collection":x.type==="view"?"home_navigate_to_view":"unmapped_event";n.onAnalyticsEvent?.(B,{path:x.path})}})},`nav_${x.group}_${x.name}`)),E&&E.map((x,B)=>r.jsx("div",{children:r.jsx(x,{...k})},`nav_${w}_add_${B}`))]})},`plugin_section_${w}`)}),y,b,t]})})}function _s({propertyConfig:e}){const t="h-8 w-8 p-1 rounded-full shadow text-white";return r.jsx("div",{className:t,style:{background:e?.color??"#888"},children:vr(e,"medium")})}function Ws({children:e,title:t,path:n}){const o=Nr();return c.useEffect(()=>{o.set({breadcrumbs:[{title:t,url:n}]})},[n,t]),r.jsx(r.Fragment,{children:e})}function Zo(){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 js({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 Xo({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 Ko=function({title:t,endAdornment:n,startAdornment:o,drawerOpen:l,dropDownActions:i,includeDrawer:s,className:a,style:d,user:A}){const g=ie(),p=_e(),{mode:h,toggleMode:u}=Fr(),m=Pe(),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"]})]})]})})},Hs=e=>e&&Array.isArray(e)&&e.length>0?e.map((t,n)=>t?{[fr(t)+n]:It()}:{}).reduce((t,n)=>({...t,...n}),{}):{};function tn({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(Hs(n)),[h,u]=c.useState(g?Object.values(p.current):[]);c.useEffect(()=>{if(g&&n&&n.length!==h.length){const C=n.map((E,k)=>{const S=fr(E)+k;if(S in p.current)return p.current[S];{const x=It();return p.current[S]=x,x}});u(C)}},[g,h.length,n]);const m=C=>{if(C.preventDefault(),o)return;const E=It(),k=[...h,E];s&&s(E),u(k),A([...n??[],d])},b=C=>{const E=[...h];E.splice(C,1),u(E),A(n.filter((k,S)=>S!==C))},y=C=>{const E=It(),k=n[C],S=[...h.splice(0,C+1),E,...h.splice(C+1,h.length-C-1)];s&&s(E),u(S),A([...n.slice(0,C+1),k,...n.slice(C+1)])},w=C=>{if(!C.destination)return;const E=C.source.index,k=C.destination.index,S=[...h],x=S[E];S[E]=S[k],S[k]=x,u(S),A(Js(n,E,k))};return r.jsx(lt.DragDropContext,{onDragEnd:w,children:r.jsx(lt.Droppable,{droppableId:e,renderClone:(C,E,k)=>{const S=k.source.index,x=h[S];return r.jsx(rn,{provided:C,internalId:x,index:S,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((k,S)=>r.jsx(lt.Draggable,{draggableId:`array_field_${k}`,isDragDisabled:o,index:S,children:(x,B)=>r.jsx(rn,{provided:x,internalId:k,index:S,size:i,disabled:o,buildEntry:l,remove:b,copy:y,isDragging:B.isDragging})},`array_field_${k}`)),C.placeholder,a&&r.jsx("div",{className:"py-4 justify-center text-left",children:r.jsx(f.Button,{variant:i==="small"?"text":"outlined",size:i==="small"?"small":"medium",color:"primary",disabled:o,startIcon:r.jsx(f.AddIcon,{}),onClick:m,children:t??"Add"})})]})})})}function rn({provided:e,index:t,internalId:n,size:o,disabled:l,buildEntry:i,remove:s,copy:a,isDragging:d}){const[A,g]=sr(),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(Ro,{direction:o==="small"?"row":"column",disabled:l,remove:s,index:t,provided:e,measuring:p,contentOverflow:h,copy:a})]})})}function Ro({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 Js(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 Rt({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(tn,{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 be({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 qs({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 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(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 nn({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(be,{icon:pe(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(ye,{includeDescription:A,showError:l,error:o,disabled:i,property:d})]})}function on({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(be,{icon:pe(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(ye,{includeDescription:a,showError:l,error:o,disabled:i,property:s})]})}function el({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(N=>N.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(N=>{console.debug("onMultipleEntitiesSelected",N),A(N.map(I=>et(I)))},[A]),E=Bt({multiselect:!0,path:p.path,collection:w,onMultipleEntitiesSelected:C,selectedEntityIds:b,forceFilter:p.forceFilter}),k=c.useCallback(N=>{N.preventDefault(),E.open()},[E]),S=c.useCallback((N,I)=>{const T=t&&t.length>N?t[N]:void 0;return T?r.jsx("div",{onMouseEnter:()=>m(!0),onMouseMove:()=>m(!0),onMouseLeave:()=>m(!1),children:r.jsx(Ge,{disabled:!p.path,previewProperties:p.previewProperties,size:"medium",onClick:k,reference:T,onHover:u})}):r.jsx("div",{children:"Internal ERROR"})},[p.path,p.previewProperties,u,t]),x=r.jsx(be,{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:[!w&&r.jsx(he,{error:"The specified collection does not exist. Check console"}),w&&r.jsxs(r.Fragment,{children:[r.jsx(Rt,{value:t,addLabel:a.name?"Add reference to "+a.name:"Add reference",name:e,buildEntry:S,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:k,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:B}),s&&B,r.jsx(ye,{includeDescription:d,showError:o,error:n,disabled:l,property:a})]})}function tl({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 Zs="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",Xs="border-dotted-gray",Ks="hover:bg-field-hover dark:hover:bg-field-hover-dark",Rs="pt-0 border-2 border-solid",ea="transition-colors duration-200 ease-[cubic-bezier(0,0,0.2,1)] border-2 border-solid border-green-500",ta="transition-colors duration-200 ease-[cubic-bezier(0,0,0.2,1)] border-2 border-solid border-red-500";function ln({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}=ko({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 k={id:A.entityId,values:A.values,path:A.path};return r.jsxs(r.Fragment,{children:[!s&&r.jsx(be,{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(na,{value:u,name:e,disabled:h,autoFocus:i,property:a,onChange:n,setInternalValue:m,onFilesAdded:b,entity:k,onFileUploadComplete:w,storagePathBuilder:C,storage:y,multipleFilesSupported:E}),r.jsx(ye,{includeDescription:d,showError:l,error:o,disabled:h,property:a})]})}function ra({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:k,isDragAccept:S,isDragReject:x}=Bn.useDropzone({accept:e.acceptedFiles?e.acceptedFiles.map(B=>({[B]:[]})).reduce((B,N)=>({...B,...N}),{}):void 0,disabled:t||n,noDragEventsBubbling:!0,maxSize:e.maxSize,onDrop:o,onDropRejected:(B,N)=>{for(const I of B)for(const T of I.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,Zs,l&&a.length?"":"flex",f.focusedMixin,{[Ks]:!k,[Rs]:k,[ta]:x,[ea]:S,[Xs]: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((B,N)=>{let I;return B.storagePathOrDownloadUrl?I=r.jsx(tl,{name:`storage_preview_${B.storagePathOrDownloadUrl}`,property:d,disabled:t,entity:A,value:B.storagePathOrDownloadUrl,onRemove:g,size:B.size}):B.file&&(I=r.jsx(Fo,{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:N,children:(T,F)=>r.jsx("div",{tabIndex:-1,ref:T.innerRef,...T.draggableProps,...T.dragHandleProps,className:f.cn(f.focusedMixin,"rounded-md"),style:{...T.draggableProps.style},children:I})},`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(f.Typography,{align:"center",variant:"label",children:y})})]})}function na({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 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=c.useCallback((k,S)=>{if(!i)return;const x=[...n],B=x[k];x.splice(k,1),x.splice(S,0,B),o(x);const N=x.filter(I=>!!I.storagePathOrDownloadUrl).map(I=>I.storagePathOrDownloadUrl);l(N)},[i,l,o,n]),y=c.useCallback(k=>{k.destination&&b(k.source.index,k.destination.index)},[b]),w=c.useCallback(k=>{if(i){const S=n.filter(x=>x.storagePathOrDownloadUrl!==k);l(S.filter(x=>!!x.storagePathOrDownloadUrl).map(x=>x.storagePathOrDownloadUrl)),o(S)}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:(k,S,x)=>{const B=n[x.source.index];return r.jsx("div",{ref:k.innerRef,...k.draggableProps,...k.dragHandleProps,style:k.draggableProps.style,className:"rounded",children:r.jsx(tl,{name:`storage_preview_${B.storagePathOrDownloadUrl}`,property:E,disabled:!0,entity:p,value:B.storagePathOrDownloadUrl,onRemove:w,size:B.size})})},children:(k,S)=>r.jsx(ra,{storage:g,disabled:a,isDraggingOver:S.isDraggingOver,droppableProvided:k,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 pt({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(be,{icon:pe(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(ye,{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 rl=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(be,{icon:pe(A,"small"),required:A.validation?.required,title:A.name}),disabled:a,autoFocus:s,size:"medium"}),r.jsx(ye,{includeDescription:g,showError:i,error:l,disabled:a,property:A})]})});function nl({propertyKey:e,value:t,setValue:n,autoFocus:o,error:l,showError:i,disabled:s,touched:a,property:d,includeDescription:A}){const{locale:g}=X(),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(be,{icon:pe(d,"small"),required:d.validation?.required,className:"text-text-secondary dark:text-text-secondary-dark",title:d.name})}),r.jsx(ye,{includeDescription:A,showError:i,error:l,disabled:s,property:d})]})}function sn({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(be,{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: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(ye,{includeDescription:s,showError:o,error:n,property:i})]})}function ol(e){return typeof e.property.path!="string"?r.jsx(sn,{...e}):r.jsx(oa,{...e})}function oa({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 Me,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?et(w):null)},[t]),b=Bt({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(be,{icon:pe(d,"small"),required:d.validation?.required,title:d.name,className:"text-text-secondary dark:text-text-secondary-dark ml-3.5"}),!u&&r.jsx(he,{error:"The specified collection does not exist. Check console"}),u&&r.jsxs(r.Fragment,{children:[e&&r.jsx(Ge,{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(ye,{includeDescription:A,showError:o,error:n,disabled:i,property:d})]})}const nt=c.memo(la,(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)||er(t.property),!1});function la({propertyKey:e,property:t,context:n,includeDescription:o,underlyingValueHasChanged:l,disabled:i,tableMode:s,partOfArray:a,partOfBlock:d,autoFocus:A}){const g=X(),h=er(t,g.plugins)?Ce.Field:Ce.FastField;return r.jsx(h,{name:e,children:u=>{let m;const b=ke({propertyKey:e,propertyValue:u.field.value,propertyOrBuilder:t,values:u.form.values,path:n.path,entityId:n.entityId,fields:g.propertyConfigs});if(b===null||vt(b))return r.jsx(r.Fragment,{});if(it(b))m=sn;else if(b.Field)typeof b.Field=="function"&&(m=b.Field);else{const w=tr(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=ke({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(ia,{Component:m,componentProps:y,fieldProps:u})}})}function ia({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}=X(),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(I=>!!I).length),k=sa(A.path,A.collection,t,n,e,h)??e,S=p.form.isSubmitting,x=c.useCallback((I,T)=>{p.form.setFieldTouched(t,!0,!1),p.form.setFieldValue(t,I,T)},[]),B=c.useCallback((I,T,F)=>{p.form.setFieldTouched(t,!0,!1),p.form.setFieldValue(I,T,F)},[]),N={propertyKey:t,value:m,initialValue:b,setValue:x,setFieldValue:B,error:y,touched:w,showError:C,isSubmitting:S,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(k,{...N}),l&&!S&&r.jsx(f.Typography,{variant:"caption",className:"ml-3.5",children:"This value has been updated elsewhere"})]})}const er=(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=>er(l,t)):n.dataType==="array"&&"resolvedProperties"in n?o||n.resolvedProperties?.some(l=>l&&er(l,t)):o};function sa(e,t,n,o,l,i){return c.useRef((()=>{let a=null;return i&&i.forEach(d=>{const A=un(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 ll({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=Fn(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])=>!vt(E)).map(([C,E],k)=>{const S={propertyKey:`${e}.${C}`,disabled:l,property:E,includeDescription:A,underlyingValueHasChanged:g,context:h,tableMode:!1,partOfArray:!1,partOfBlock:!1,autoFocus:p&&k===0};return r.jsx("div",{children:r.jsx(nt,{...S})},`map-${e}-${k}`)})})}),w=r.jsx(be,{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:[!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(ye,{includeDescription:A,showError:n,error:o,disabled:l,property:i})]})}function il({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(an,{value:t,setValue:s,disabled:l,fieldName:i.name??e}),m=r.jsx(be,{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(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(ye,{includeDescription:d,showError:n,error:o,disabled:l,property:i})]})}function an({value:e,setValue:t,fieldName:n,disabled:o}){const[l,i]=c.useState(Object.keys(e??{}).map(d=>[cn(),{key:d,dataType:dn(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([cn(),{key:u,dataType:dn(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??""]:hr(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(aa,{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,[cn(),{key:"",dataType:"string"}]])},children:n?`Add to ${n}`:"Add"})]})}function aa({rowId:e,fieldKey:t,value:n,onFieldKeyChange:o,onDeleteClick:l,setValue:i,entryValue:s,dataType:a,updateDataType:d,disabled:A}){const{locale:g}=X();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(tn,{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(ca,{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(an,{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 ca({id:e,index:t,value:n,setValue:o}){const{locale:l}=X(),[i,s]=c.useState(dn(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(an,{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 cn(){return Math.floor(Math.random()*Math.floor(Number.MAX_SAFE_INTEGER))}function dn(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 Me)return"reference";if(e instanceof Gt)return"geopoint";if(typeof e=="object")return"map"}function sl({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=(k,S)=>{const x=d.resolvedProperties[k]??m,B={propertyKey:`${e}.${k}`,disabled:h,property:x,includeDescription:A,underlyingValueHasChanged:g,context:p,tableMode:!1,partOfArray:!0,partOfBlock:!1,autoFocus:S===b};return r.jsx(nt,{...B})},C=r.jsx(Rt,{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(be,{icon:pe(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(ye,{includeDescription:A,showError:o,error:n,disabled:h,property:d})]})}function al({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((k,S)=>r.jsx(da,{name:`${e}.${k}`,index:k,value:t[k],typeField:d.oneOf.typeField??yt,valueField:d.oneOf.valueField??zt,properties:d.oneOf.properties,autoFocus:S===m,context:p},`array_one_of_${k}`),[p,m,d.oneOf,e,t]),w=r.jsx(be,{icon:pe(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(Rt,{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??yt]: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(ye,{includeDescription:A,showError:o,error:n,disabled:h,property:d})]})}function da({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 Aa=new xl;try{Re.use(Re.Plugins.AutoResize,{min:100}),Re.unuse(Re.Plugins.FontUnderline),Re.unuse(Re.Plugins.Clear)}catch{}function cl({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",fa);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(be,{icon:pe(d,"small"),required:d.validation?.required,title:d.name,className:"text-text-secondary dark:text-text-secondary-dark ml-3.5"})}),r.jsx(Re,{value:h??"",className:f.cn(f.fieldBackgroundMixin,i?f.fieldBackgroundDisabledMixin:f.fieldBackgroundHoverMixin,"text-base"),readOnly:i,renderHTML:y=>Aa.render(y),view:{menu:!0,md:!0,html:!1},onChange:({html:y,text:w})=>{u(w??null)}}),r.jsx(ye,{includeDescription:g,showError:l,error:o,disabled:i,property:d})]})}const fa=`
|
|
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 Ur({propertyKey:e,value:t,property:n,entity:o,size:l}){const i=X(),s=_e({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 Ge=Ar.memo(function(t){const n=t.reference;return n instanceof Me?r.jsx(Mi,{...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)})}))},Qi);function Qi(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 Mi({disabled:e,reference:t,previewProperties:n,size:o,onHover:l,onClick:i,allowEntityNavigation:s=!0}){const a=X(),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(Di,{reference:t,collection:A,previewProperties:n,size:o,disabled:e,allowEntityNavigation:s,onClick:i,onHover:l})}function Di({reference:e,collection:t,previewProperties:n,size:o,disabled:l,allowEntityNavigation:i,onClick:s,onHover:a}){const d=X(),A=je(),{entity:g,dataLoading:p,dataLoadingError:h}=Qr({path:e.path,entityId:e.id,collection:t,useCache:!0});g&&ho.set(e.pathWithId,g);const u=g??ho.get(e.pathWithId),m=c.useMemo(()=>Be({collection:t,path:e.path,values:u?.values,fields:d.propertyConfigs}),[t]),b=c.useMemo(()=>$n(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:Le(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 ho=new Map;function po({propertyKey:e,value:t,property:n,size:o}){const l=X(),i=_e({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(Ge,{disabled:!A.path,previewProperties:A.previewProperties,size:s,reference:a})},`preview_array_ref_${e}_${d}`)})})}function mo({propertyKey:e,entity:t,value:n,property:o,size:l}){const i=X(),s=_e({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 Lr({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 $r({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(Lr,{name:e,value:t,enumValues:l.enumValues,size:o}):null}function bo({propertyKey:e,value:t,property:n,entity:o,size:l}){const i=X(),s=_e({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(zr,{propertyKey:e,property:a,value:d,entity:o,size:l})})},`preview_array_strings_${e}_${A}`))})}function yo({propertyKey:e,value:t,property:n,size:o,entity:l}){const i=X(),s=_e({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??yt,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 vo({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(_r,{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 _r({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(_r,{value:n})})]},`map_preview_table_${t}}`))})}function wo({date:e}){const t=X(),n=t?.locale?kn[t?.locale]:void 0,o=t?.dateTimeFormat??On,l=e?El(e,o,{locale:n}):"";return r.jsx(r.Fragment,{children:l})}function Co({value:e}){return r.jsx(f.Checkbox,{checked:e})}function Eo({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=X();let n;const{property:o,propertyKey:l,value:i,size:s,height:a,width:d,entity:A}=e,g=ke({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(Bt,{size:e.size,url:i}):typeof p.url=="string"&&(n=r.jsx(Bt,{size:e.size,url:i,previewType:p.url})):p.storage?n=r.jsx(fo,{storeUrl:g.storage?.storeUrl??!1,size:e.size,storagePathOrDownloadUrl:i}):p.markdown?n=r.jsx(f.Markdown,{source:i}):n=r.jsx(zr,{...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(Ur,{...e,value:i,property:g}):p.of.dataType==="reference"?n=r.jsx(po,{...e,value:i,property:g}):p.of.dataType==="string"?p.of.enumValues?n=r.jsx($r,{...e,value:i,property:g}):p.of.storage?n=r.jsx(mo,{...e,value:i,property:g}):n=r.jsx(bo,{...e,value:i,property:g}):p.of.dataType==="number"&&p.of.enumValues?n=r.jsx($r,{...e,value:i,property:g}):n=r.jsx(Ur,{...e,value:i,property:g}):p.oneOf&&(n=r.jsx(yo,{...e,value:i,property:g}))}else n=rt(l,g.dataType,i);else g.dataType==="map"?typeof i=="object"?n=r.jsx(vo,{...e,property:g}):n=rt(l,g.dataType,i):g.dataType==="date"?i instanceof Date?n=r.jsx(wo,{date:i}):n=rt(l,g.dataType,i):g.dataType==="reference"?typeof g.path=="string"?i instanceof Me?n=r.jsx(Ge,{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(Co,{value:i}):n=rt(l,g.dataType,i):g.dataType==="number"?typeof i=="number"?n=r.jsx(Eo,{...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 Oi({propertyKey:e,value:t,property:n,size:o,entity:l}){const i=X(),s=_e({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 Vi=Ar.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(Ar.Fragment,{children:l})});function Wr({entity:e,collection:t,path:n,className:o}){const l=X(),i=c.useMemo(()=>Be({collection:t,path:n,entityId:e.id,values:e.values,fields:l.propertyConfigs}),[t,n,e]),s=X(),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 Gi(e){return e.dataType==="boolean"?"center":e.dataType==="number"?e.enumValues?"left":"right":e.dataType==="date"?"right":"left"}function Bo(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:Bo(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 jr(e){return`subcollection:${e.id??e.path}`}function Yi(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 Hr(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(Lr,{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 zi(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 Ui(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 Li(e){const{locale:t}=X(),{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 $i(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=ko(s,e,o,a,l),d||(d=st()+"_"+s.name),d}function _i(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=ko(s,e,o,a,l),d||(d=st()+"_"+s.name),d}function ko(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 xo({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(B=>({id:Jr(),storagePathOrDownloadUrl:B,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 B=>{if(A.fileName){const N=await $i(A.fileName,A,t,e,n,l,B,i);if(!N||N.length===0)throw Error("You need to return a valid filename");return N}return st()+"_"+B.name},[e,t,n,l,i,A]),k=c.useCallback(B=>_i(A.storagePath,A,t,e,n,l,B,i)??"/",[e,t,n,l,i,A]),S=c.useCallback(async(B,N,I)=>{console.debug("onFileUploadComplete",B,N);let P=B;if(A.storeUrl&&(P=(await s.getDownloadURL(B)).url),A.postProcess&&P&&(P=await A.postProcess(P)),!P){console.warn("uploadPathOrDownloadUrl is null");return}let F;N.storagePathOrDownloadUrl=P,N.metadata=I,F=[...w],F=So(F),C(F);const Q=F.filter(Y=>!!Y.storagePathOrDownloadUrl).map(Y=>Y.storagePathOrDownloadUrl);d(g?Q:Q?Q[0]:null)},[w,g,d,A,s]),x=c.useCallback(async B=>{if(!B.length||a)return;let N;if(g)N=[...w,...await Promise.all(B.map(async I=>(u&&qr(I)&&(I=await Fo(I,u)),{id:Jr(),file:I,fileName:await E(I),metadata:p,size:h})))];else{let I=B[0];u&&qr(I)&&(I=await Fo(I,u)),N=[{id:Jr(),file:I,fileName:await E(I),metadata:p,size:h}]}N=So(N),C(N)},[a,E,w,p,g,h]);return{internalValue:w,setInternalValue:C,storage:A,fileNameBuilder:E,storagePathBuilder:k,onFileUploadComplete:S,onFilesAdded:x,multipleFilesSupported:g}}function So(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 Io={"image/jpeg":"JPEG","image/png":"PNG","image/webp":"WEBP"},qr=e=>Io[e.type]?Io[e.type]:null,Wi=100,Fo=(e,t)=>new Promise(n=>{const o=t.quality===void 0?Wi:t.quality,l=o>=0&&o<=100?o:100,i=qr(e);if(!i)throw Error("resizeAndCompressImage: Unsupported image format");xl.imageFileResizer(e,t.maxWidth||Number.MAX_VALUE,t.maxHeight||Number.MAX_VALUE,i,l,0,s=>n(s),"file")});function No({storagePath:e,entry:t,metadata:n,onFileUploadComplete:o,imageSize:l,simple:i}){const s=ct(),a=He(),[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 Po({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(co,{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 ji="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",Hi="pt-0 border-2 border-solid",Ji="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",qi="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 Zi(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}=xo({entityValues:d.values,entityId:d.id,path:A,property:a,propertyKey:t,storageSource:h,onChange:p,value:i,disabled:s});return r.jsx(Xi,{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 Xi({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 k=u?.metadata,S=!!n,x=He(),{open:B,getRootProps:N,getInputProps:I,isDragActive:P,isDragAccept:F,isDragReject:Q}=En.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}=N(),J=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,j=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(ji,"relative w-full h-full flex",`justify-${S?"start":"center"}`,P?Hi:"",F?Ji:"",Q?qi:""),children:[r.jsx("input",{autoFocus:h,...I()}),n.map((z,V)=>{let re;return z.storagePathOrDownloadUrl?re=r.jsx(Ki,{property:_,value:z.storagePathOrDownloadUrl,entity:i,size:E},`storage_preview_${V}`):z.file&&(re=r.jsx(No,{entry:z,metadata:k,storagePath:y(z.file),onFileUploadComplete:b,imageSize:j,simple:!0},`storage_progress_${V}`)),re}),!n&&r.jsx("div",{className:"flex-grow m-2 max-w-[200px]",onClick:B,children:r.jsx(f.Typography,{className:"text-gray-400 dark:text-gray-600",variant:"body2",align:"center",children:J})}),r.jsx(Po,{showError:te,disabled:p,showExpandIcon:!0,selected:s,openPopup:p?void 0:l,children:r.jsx(f.IconButton,{color:"inherit",size:"small",onClick:B,children:r.jsx(f.EditIcon,{size:"small",className:"text-gray-500"})})})]})}function Ki({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 To(e){const t=X(),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(Ri,{...e,collection:l})}function Ri(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(N=>{o(N?et(N):null)},[o]),w=c.useCallback(N=>{o(N.map(I=>et(I)))},[o]),C=n?Array.isArray(n)?n.map(N=>N.id):n.id?[n.id]:[]:[],E=It({multiselect:l,path:i,collection:p,onMultipleEntitiesSelected:w,onSingleEntitySelected:y,selectedEntityIds:C,forceFilter:g}),k=c.useCallback(()=>{A||E.open()},[A,E]),S=!n||Array.isArray(n)&&n.length===0,x=()=>n instanceof Me?r.jsx(Ge,{onClick:A?void 0:k,size:Je(s),reference:n,onHover:h,disabled:!i,previewProperties:a}):r.jsx(Xt,{onClick:A?void 0:k,size:Je(s),children:r.jsx(pe,{title:"Value is not a reference.",error:"Click to edit"})}),B=()=>Array.isArray(n)?r.jsx(r.Fragment,{children:n.map((N,I)=>r.jsx("div",{className:"m-1 w-full",children:r.jsx(Ge,{onClick:A?void 0:k,size:"tiny",reference:N,onHover:h,disabled:!i,previewProperties:a})},`preview_array_ref_${t}_${I}`))}):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&&B(),S&&r.jsxs(f.Button,{onClick:k,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 Qo(e,t,n){const o={};return Object.entries(t).forEach(([l,i])=>{o[l]=kt({property:i,customFieldValidator:n,name:l,entityId:e})}),Ee.object().shape(o)}function kt(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 ts(e);if(t.dataType==="number")return rs(e);if(t.dataType==="boolean")return is(e);if(t.dataType==="map")return es(e);if(t.dataType==="array")return as(e);if(t.dataType==="date")return os(e);if(t.dataType==="geopoint")return ns(e);if(t.dataType==="reference")return ls(e);throw console.error("Unsupported data type in yup mapping",t),Error("Unsupported data type in yup mapping")}function es({property:e,entityId:t,customFieldValidator:n,name:o}){const l={};return e.validation,e.properties&&Object.entries(e.properties).forEach(([i,s])=>{l[i]=kt({property:s,parentProperty:e,customFieldValidator:n,name:`${o}[${i}]`,entityId:t})}),Ee.object().shape(l)}function ts({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"?Yn(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 rs({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 ns({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 os({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 ls({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 is({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 ss(e){return e.validation?.uniqueInArray?!0:e.dataType==="map"&&e.properties?Object.entries(e.properties).filter(([t,n])=>n.validation?.uniqueInArray):!1}function as({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}]`]:kt({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)=>Le(a,A.path).validate(d)))}else{i=i.of(kt({property:e.of,parentProperty:e,entityId:l}));const a=ss(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 cs=({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}),Zr=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]=dr(),E=c.useRef(null);f.useOutsideAlerter(E,()=>{l&&u&&u(void 0)},!!(l&&u));const[k,S]=c.useState(!1),x=c.useMemo(()=>gt(o),[o]),[B,N]=c.useState(!1),[I,P]=c.useState(a),F=!i&&d;c.useEffect(()=>{a&&P(!0);const W=setTimeout(()=>{P(!1)},800);return()=>{clearTimeout(W)}},[a]);let Q=0;if(!p)switch(o){case"l":case"xl":Q=4;break;case"m":Q=2;break;case"s":default:Q=1;break}let Y;switch(A){case"right":Y="flex-end";break;case"center":Y="center";break;case"left":default:Y="flex-start"}const J=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=>{J(),W.stopPropagation()},[J]);c.useEffect(()=>{if(C){const W=C.height>x;k!==W&&S(W)}},[C,k,x]);const j=!F&&l,te=!i&&g&&k,z=!i&&!g&&k,V=c.useCallback(()=>N(!0),[]),re=c.useCallback(()=>N(!1),[]);return r.jsxs("div",{ref:E,className:f.cn("transition-colors duration-100 ease-in-out",`flex relative h-full rounded-md p-${Q} 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":"",!j&&!I&&!F?"border-transparent":"",b?"overflow-hidden":"",j?"bg-gray-50 dark:bg-gray-900":"",j&&!I?"border-primary":"",I?"border-green-500 ":"",F?"border-red-500":""),style:{justifyContent:Y,alignItems:i||!k?"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(cs,{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&&B&&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 ds(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 As=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=X(),{onValueChange:u,size:m,selectedCell:b,select:y,setPopupCell:w}=Ss(),C=b?.propertyKey===t&&b?.entity.path===A.path&&b?.entity.id===A.id,[E,k]=c.useState(o),S=c.useRef(o),[x,B]=c.useState(),[N,I]=c.useState(!1),P=c.useCallback(()=>{I(!0),setTimeout(()=>{I(!1)},100)},[]),F=!!l.Field,Q=!!l.Preview,Y=it(l),J=typeof l.disabled=="object"?l.disabled.disabledMessage:void 0,_=g||p||!!l.disabled,j=c.useMemo(()=>kt({property:l,entityId:A.id,customFieldValidator:n,name:t}),[A.id,l,t]);c.useEffect(()=>{oe(o,S.current)||(B(void 0),k(o),S.current=o,P())},[P,o]);const te=T=>{oe(T,S.current)||(I(!1),j.validate(T).then(()=>{B(void 0),S.current=T,u&&u({value:T,propertyKey:t,setError:B,onValueUpdated:P,entity:A,fullPath:d,context:h})}).catch(D=>{B(D)}))};c.useEffect(()=>{j.validate(E).then(()=>B(void 0)).catch(T=>{B(T)})},[E,j,t,l,A]);const z=T=>{let D;T===void 0?D=null:D=T,k(D),te(D)};xe({property:l,value:E,setValue:z});const V=c.useCallback(T=>{y(T?{width:s,height:a,entity:A,cellRect:T,propertyKey:t}:void 0)},[A,a,t,y,s]),re=T=>{w&&w(T?{width:s,height:a,entity:A,cellRect:T,propertyKey:t}:void 0)};let W,q=!1,se=!1,U=!0,M=!1,$=!1,K=!0;const L=!_&&x;if(g||Y)return r.jsx(Zr,{size:m,width:s,saved:N,value:E,align:i??"left",fullHeight:!1,disabledTooltip:J??(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:Je(m)})},`${t}_${A.path}_${A.id}`);if(!F&&(!Q||C)){if(ds(l))W=r.jsx(Zi,{error:x,disabled:_,focused:C,selected:C,openPopup:w?re:void 0,property:l,entity:A,path:d,value:E,previewSize:Je(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(Hr,{name:t,multiple:!1,disabled:_,focused:C,valueType:"number",small:Je(m)!=="medium",enumValues:D.enumValues,error:x,internalValue:E,updateValue:z}),$=!0):(W=r.jsx(zi,{align:i,error:x,focused:C,disabled:_,value:E,updateValue:z}),q=!0)}else if(C&&l.dataType==="string"){const D=l;if(D.enumValues)W=r.jsx(Hr,{name:t,multiple:!1,focused:C,disabled:_,valueType:"string",small:Je(m)!=="medium",enumValues:D.enumValues,error:x,internalValue:E,updateValue:z}),$=!0;else if(!D.storage){const Se=!!D.multiline||!!D.markdown;W=r.jsx(Yi,{error:x,disabled:_,multiline:Se,focused:C,value:E,updateValue:z}),q=!0}}else if(l.dataType==="boolean")W=r.jsx(Ui,{error:x,disabled:_,focused:C,internalValue:E,updateValue:z});else if(l.dataType==="date")W=r.jsx(Li,{name:t,error:x,disabled:_,mode:l.mode,focused:C,internalValue:E,updateValue:z}),$=!0,U=!1,q=!1;else if(l.dataType==="reference")typeof l.path=="string"&&(W=r.jsx(To,{name:t,internalValue:E,updateValue:z,disabled:_,size:m,path:l.path,multiselect:!1,previewProperties:l.previewProperties,title:l.name,forceFilter:l.forceFilter})),q=!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(Hr,{name:t,multiple:!0,disabled:_,focused:C,small:Je(m)!=="medium",valueType:D.of.dataType,enumValues:D.of.enumValues,error:x,internalValue:E,updateValue:z}),q=!0,$=!0,U=!1):D.of.dataType==="reference"&&(typeof D.of.path=="string"&&(W=r.jsx(To,{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})),q=!1))}}return W||(q=!1,se=C&&!W&&!_&&!Y,W=r.jsx(me,{width:s,height:a,entity:A,propertyKey:t,value:E,property:l,size:Je(m)})),r.jsx(Zr,{size:m,width:s,onSelect:V,selected:C,disabled:_||Y,disabledTooltip:J??"Disabled",removePadding:M,fullHeight:$,saved:N,error:x,align:i,allowScroll:q,showExpandIcon:se,value:E,hideOverflow:U,actions:K&&r.jsx(Po,{showError:L,disabled:_,showExpandIcon:se,selected:C,openPopup:_?void 0:re}),children:W},`cell_${t}_${A.path}_${A.id}`)},fs);function fs(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 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(f.CircularProgress,{...t}),e&&r.jsx(f.Typography,{color:"secondary",variant:"caption",className:"text-center",children:e})]})})}const us=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(B=>{b(!0)},[]),E=c.useCallback((B,N)=>{s(d,B),N!==void 0&&b(N)},[d,s]),k=o===n,x=!(o!==n&&o>0)&&(h||k);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(gs,{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 gs({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 hs=({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((S,x,B)=>{const N=e[S],I=100,P=800,F=x>P?P:x<I?I:x,Q={width:F,key:N.key,column:{...N,width:F}};B?a(Q):s(Q)},[e,s,a]),m=c.useCallback(S=>{if(p>=0){const x=g[p].current?.parentElement?.getBoundingClientRect().left;return x?S.clientX-x:void 0}},[g,p]),b=c.useCallback(S=>{document.body.style.cursor=S?"col-resize":"auto"},[]),y=c.useCallback(S=>{S.stopPropagation(),S.preventDefault();const x=m(S);x&&u(p,x,!1)},[u,m,p]),w=c.useCallback(S=>{S.stopPropagation(),S.preventDefault();const x=m(S);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 k=c.useCallback(S=>{h(S),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((S,x)=>{const B=e[x],N=B&&i&&i[B.key]?i[B.key]:void 0;return r.jsx(ne,{children:r.jsx(us,{resizeHandleRef:g[x],columnIndex:x,isResizingIndex:p,onFilterUpdate:o,filter:N,sort:l===B.key?t:void 0,onColumnSort:n,onClickResizeColumn:k,column:B,createFilterField:d,AdditionalHeaderWidget:B.AdditionalHeaderWidget})},"header_"+B.key)}),A&&r.jsx(A,{})]})},ps=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),ms=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 bs=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(hs,{...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})]})}})),Mo=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:k,endAdornment:S,AddColumnComponent:x}){const B=p?p[0]:void 0,N=p?p[1]:void 0,[I,P]=c.useState(i),F=c.useRef(null),Q=c.useRef(0);c.useEffect(()=>{P(i)},[i]);const[Y,J]=dr(),_=c.useCallback(T=>{P(I.map(D=>D.key===T.column.key?T.column:D))},[I]),j=c.useCallback(T=>{P(I.map(D=>D.key===T.column.key?T.column:D)),a&&a(T)},[I,a]),te=c.useRef();c.useEffect(()=>{te.current=d},[d]);const z=c.useCallback(()=>{Q.current=0,F.current&&F.current.scrollTo(F.current?.scrollLeft,0)},[]),V=c.useCallback(T=>{const D=B===T&&N==="desc",Ae=B===T&&N==="asc"?"desc":D?void 0:"asc",ae=D?void 0:T,Ie=te.current,qe=Ae&&ae?[ae,Ae]:void 0;Ie&&A&&!A(Ie,qe)&&g&&g(void 0),n&&n(),m&&m(qe),z()},[A,N,g,n,m,z,B]),re=c.useCallback(()=>{Q.current=0,m&&m(void 0)},[m]),W=Math.max((t?.length??0)*gt(l)-J.height,0),q=c.useCallback(T=>{o&&(t?.length??0)>0&&T>Q.current+600&&(Q.current=T,o())},[t?.length,o]),se=c.useCallback(({scrollOffset:T,scrollUpdateWasRequested:D})=>{!D&&T>=W-600&&q(T)},[W,q]),U=c.useCallback((T,D)=>{Q.current=0;const Se=te.current;let Ae=Se?{...Se}:{};D?Ae[T.key]=D:delete Ae[T.key],!A||A(Ae,B&&N?[B,N]:void 0)||(Ae=D?{[T.key]:D}:{}),g&&g(Ae),T.key!==B&&re()},[A,N,g,re,B]),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(xt,{}):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",k),children:r.jsx(Kt.Provider,{value:{data:t,size:l,cellRenderer:y,columns:I,currentSort:N,onRowClick:s,customView:L,onColumnResize:_,onColumnResizeEnd:j,filter:te.current,onColumnSort:V,onFilterUpdate:U,sortByProperty:B,hoverRow:w??!1,createFilterField:C,rowClassName:E,endAdornment:S,AddColumnComponent:x},children:r.jsx(ys,{outerRef:F,width:J.width,height:J.height,itemCount:(t?.length??0)+(S?1:0),onScroll:se,includeAddColumn:!!x,itemSize:gt(l)},l)})})},oe);function ys({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(ps,{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,k)=>{const S=C&&C[E.key];return r.jsx(ms,{dataKey:E.key,cellRenderer:m,column:E,columns:h,rowData:C,cellData:S,rowIndex:d,columnIndex:k},`cell_${E.key}`)}),s&&r.jsx("div",{className:"w-20"})]},`row_${d}`)}}),[]);return r.jsx(kl.FixedSizeList,{outerRef:e,innerElementType:bs,width:t,height:n,overscanCount:4,itemCount:o,onScroll:l,itemSize:i,children:a})}const Xr=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=X(),w=c.useCallback(B=>{m?.toggleEntitySelection(t)},[t,m?.toggleEntitySelection]),C=c.useCallback(B=>{B.stopPropagation(),m?.toggleEntitySelection(t)},[t,m?.toggleEntitySelection]),E=h.length>0,k=h.some(B=>B.collapsed||B.collapsed===void 0),S=h.filter(B=>B.collapsed||B.collapsed===void 0),x=h.filter(B=>B.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((B,N)=>r.jsx(f.Tooltip,{title:B.name,children:r.jsx(f.IconButton,{onClick:I=>{I.stopPropagation(),B.onClick({entity:t,fullPath:o,collection:n,context:y,selectionController:m,highlightEntity:A,unhighlightEntity:p,onCollectionChange:g})},size:b?"medium":"small",children:B.icon})},N)),k&&r.jsx(f.Menu,{trigger:r.jsx(f.IconButton,{size:b?"medium":"small",children:r.jsx(f.MoreVertIcon,{})}),children:S.map((B,N)=>r.jsxs(f.MenuItem,{onClick:I=>{I.stopPropagation(),B.onClick({entity:t,fullPath:o,collection:n,context:y,selectionController:m,highlightEntity:A,unhighlightEntity:p,onCollectionChange:g})},children:[B.icon,B.name]},N))}),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:B=>{B.stopPropagation()},className:"font-mono select-all",variant:"caption",color:"secondary",children:[" ",t.id," "]}):r.jsx(f.Skeleton,{})})]})},oe);function vs(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 Do={"==":"==","!=":"!=",">":">","<":"<",">=":">=","<=":"<=",in:"In","not-in":"Not in","array-contains":"Contains","array-contains-any":"Contains Any"},Kr=["array-contains-any","in","not-in"];function ws({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(F=>F instanceof Me?F.id:null).filter(Boolean):[b.id]:[];function C(F,Q){const Y=Kr.includes(u),J=Kr.includes(F);let _=Q;Y!==J&&(_=J?_ instanceof Me?[_]:[]:void 0),m(F),y(_);const j=_!==null&&Array.isArray(_)?_.length>0:_!==void 0;n(F&&j?[F,_]:void 0)}const E=ie(),k=c.useMemo(()=>l?E.getCollection(l):void 0,[l]),S=F=>{C(u,et(F))},x=F=>{C(u,F.map(Q=>et(Q)))},B=Kr.includes(u),N=It({multiselect:B,path:l,collection:k,onSingleEntitySelected:S,onMultipleEntitiesSelected:x,selectedEntityIds:w,onClose:()=>{a(!1)}}),I=()=>{a(!0),N.open()},P=F=>r.jsx("div",{className:"mb-0.5",onMouseEnter:()=>g(!0),onMouseMove:()=>g(!0),onMouseLeave:()=>g(!1),children:r.jsx(Ge,{disabled:!l,previewProperties:s,size:"medium",onClick:I,reference:F,onHover:A,allowEntityNavigation:!1})});return console.log("ReferenceFilterField",{internalValue:b}),r.jsxs("div",{className:"flex w-[440px] flex-row",children:[r.jsx("div",{className:"w-[120px]",children:r.jsx(f.Select,{value:u,onValueChange:F=>{C(F,b)},renderValue:F=>Do[F],children:d.map(F=>r.jsx(f.SelectItem,{value:F,children:Do[F]},F))})}),r.jsxs("div",{className:"flex-grow ml-2 h-full",children:[b&&Array.isArray(b)&&r.jsx("div",{children:b.map((F,Q)=>P(F))}),b&&!Array.isArray(b)&&r.jsx("div",{children:P(b)}),(!b||Array.isArray(b)&&b.length===0)&&r.jsx(f.Button,{onClick:I,variant:"outlined",className:"h-full w-full",children:B?"Select references":"Select reference"})]})]})}const Oo={"==":"==","!=":"!=",">":">","<":"<",">=":">=","<=":"<=",in:"In","not-in":"Not in","array-contains":"Contains","array-contains-any":"Any"},Rr=["array-contains-any","in","not-in"];function Cs({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=Rr.includes(g),k=Rr.includes(y);E!==k&&(C=k?typeof w=="string"||typeof w=="number"?[w]:[]:""),typeof C=="number"&&isNaN(C)&&(C=void 0),p(y),u(C);const S=C!==null&&Array.isArray(C)?C.length>0:C!==void 0;n(y&&S?[y,C]:void 0)}const b=Rr.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=>Oo[y],children:a.map(y=>r.jsx(f.SelectItem,{value:y,children:Oo[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 Es({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 Vo={"==":"==","!=":"!=",">":">","<":"<",">=":">=","<=":"<=","not-in":"not in",in:"in","array-contains":"Contains","array-contains-any":"Any"},Go=["array-contains-any","in"];function Bs({name:e,isArray:t,mode:n,value:o,setValue:l,title:i}){const{locale:s}=X(),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=Go.includes(g),E=Go.includes(b);C!==E&&(w=E?y?[y]:[]:""),p(b),u(w===null?void 0:w);const k=w!==null&&Array.isArray(w)?w.length>0:w!==void 0;l(b&&k?[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=>Vo[b],children:a.map(b=>r.jsx(f.SelectItem,{value:b,children:Vo[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 Yo="collectionGroupParent";function zo(e,t){return c.useMemo(()=>e.propertiesOrder?Uo(e,e.propertiesOrder):ks(e,t),[e,t])}function Uo(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?en(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=>jr(s)===n)?[{key:n,disabled:!0}]:e.collectionGroup&&n===Yo?[{key:n,disabled:!0}]:[null]}).filter(Boolean)}function ks(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=>jr(a));i.push(...s.filter(a=>!i.includes(a)))}return e.collectionGroup&&i.push(Yo),Uo(e,i)}function en(e,t,n){return e.dataType==="map"&&e.spreadChildren&&e.properties?Object.entries(e.properties).flatMap(([o,l])=>en(l,`${t}.${o}`,n||!!e.disabled||!!e.readOnly)):[{key:t,disabled:n||!!e.disabled||!!e.readOnly}]}const xs={},Lo=c.createContext(xs),Ss=()=>c.useContext(Lo),tn=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:k,tableController:{data:S,dataLoading:x,noMoreToLoad:B,dataLoadingError:N,filterValues:I,setFilterValues:P,sortBy:F,setSortBy:Q,setSearchString:Y,clearFilter:J,itemCount:_,setItemCount:j,pageSize:te=50,paginationEnabled:z,checkFilterCombination:V,setPopupCell:re},filterable:W=!0,sortable:q=!0,endAdornment:se,AddColumnComponent:U,AdditionalHeaderWidget:M,additionalIDHeaderWidget:$,emptyComponent:K,getIdColumnWidth:L}){const T=Te(),D=!!t,Se=A?.selectedEntities?.length>0?A?.selectedEntities:g,Ae=X(),[ae,Ie]=c.useState(E??"m"),[qe,Ye]=c.useState(void 0),Oe=Se?.map(H=>H.id),Ft=!!I&&Object.keys(I).length>0,mt=()=>{!z||x||B||_!==void 0&&j?.(_+te)},Nt=c.useCallback(()=>{j?.(te)},[te]),Ze=c.useCallback(({rowData:H})=>{if(console.debug("EntityCollectionTable click"),!y)return p&&p(H)},[p,y]),Xe=c.useCallback(H=>{u&&u(H),Ie(H)},[]),Pt=c.useCallback(H=>Y?.(H),[]),Ke=c.useMemo(()=>w?w.map(H=>({[H.key]:H})).reduce((H,ge)=>({...H,...ge}),{}):{},[w]);c.useEffect(()=>{const H=ge=>{ge.keyCode===27&&Qt()};return document.addEventListener("keydown",H,!1),()=>{document.removeEventListener("keydown",H,!1)}});const Tt=c.useCallback(H=>{Ye(H)},[]),Qt=c.useCallback(()=>{Ye(void 0)},[]),G=s,O=c.useCallback(({column:H,columnIndex:ge,rowData:de,rowIndex:Qe})=>{const le=de,ze=H.key;let Ue=H.custom?.disabled;const vn=le.values?Le(le.values,ze):void 0,ot=a?.({propertyKey:ze,propertyValue:vn,entity:le})??H.custom.resolvedProperty;return ot?.disabled||(Ue=!1),ot?r.jsx(ne,{children:le?r.jsx(As,{readonly:!y,align:H.align??"left",propertyKey:ze,property:ot,value:le?.values?Le(le.values,ze):void 0,customFieldValidator:G,columnIndex:ge,width:H.width,height:gt(ae),entity:le,disabled:Ue,path:le.path},`property_table_cell_${le.id}_${ze}`):Ve()}):null},[G,y,ae,Oe]),Z=c.useCallback(({column:H,rowData:ge,width:de})=>{const Qe=ge,le=Ke[H.key],ze=le.dependencies?Object.entries(Qe.values).filter(([ot,Cl])=>le.dependencies.includes(ot)).reduce((ot,Cl)=>({...ot,...Cl}),{}):Qe,Ue=le.Builder;if(!Ue&&!le.value)throw new Error("When using additional fields you need to provide a Builder or a value");const vn=Ue?r.jsx(Ue,{entity:Qe,context:Ae}):r.jsx(r.Fragment,{children:le.value?.({entity:Qe,context:Ae})});return r.jsx(Zr,{width:de,size:ae,value:ze,selected:!1,disabled:!0,align:"left",allowScroll:!1,showExpandIcon:!1,disabledTooltip:"This column can't be edited directly",children:r.jsx(ne,{children:vn})},`additional_table_cell_${Qe.id}_${H.key}`)},[Ke,ae,Oe]),R=c.useMemo(()=>{const H=Object.entries(k).flatMap(([de,Qe])=>en(Qe,de)).map(({key:de,disabled:Qe})=>{const le=Sr(k,de);if(!le)throw Error("Internal error: no property found in path "+de);const ze=$o(le);return{key:de,align:Gi(le),icon:Ue=>he(le,"small"),title:le.name??de,sortable:q&&(t?Object.keys(t).includes(de):!0),filter:!D&&ze,width:Bo(le),resizable:!0,custom:{resolvedProperty:le,disabled:Qe},AdditionalHeaderWidget:({onHover:Ue})=>M?r.jsx(M,{property:le,propertyKey:de,onHover:Ue}):void 0}}),ge=w?w.map(de=>({key:de.key,align:"left",sortable:!1,title:de.name,width:de.width??200})):[];return[...H,...ge]},[w,D,t,k,q]),ee=c.useMemo(()=>({key:"id_ewcfedcswdf3",width:L?.()??(T?160:130),title:"ID",resizable:!1,frozen:T,headerAlign:"center",align:"center",AdditionalHeaderWidget:()=>$}),[L,T]),ce=c.useMemo(()=>[ee,...C.map(H=>R.find(ge=>ge.key===H.key)).filter(Boolean)],[R,C,ee]),De=c.useCallback(H=>{const ge=H.column,de=H.columns,Qe=ge.key;if(H.columnIndex===0)return i?i({entity:H.rowData,size:ae,width:ge.width,frozen:ge.frozen}):r.jsx(Xr,{entity:H.rowData,width:ge.width,frozen:ge.frozen,isSelected:!1,size:ae});if(Ke[Qe])return Z(H);if(H.columnIndex<de.length+1)return O(H);throw Error("Internal: columns not mapped properly")},[Ke,i,ae,Z,O]),Mt=c.useCallback(H=>{P?.({...H,...t})},[t]);return r.jsx(Lo.Provider,{value:{setPopupCell:re,select:Tt,onValueChange:d,size:ae,selectedCell:qe,selectedEntityIds:Oe},children:r.jsxs("div",{className:"h-full w-full flex flex-col bg-white dark:bg-gray-950",children:[r.jsx(vs,{forceFilter:D,filterIsSet:Ft,onTextSearch:m?Pt:void 0,clearFilter:J,size:ae,onSizeChanged:Xe,title:l,actionsStart:n,actions:o,loading:x}),r.jsx(Mo,{data:S,columns:ce,cellRenderer:De,onRowClick:y?void 0:p?Ze:void 0,onEndReached:mt,onResetPagination:Nt,error:N,paginationEnabled:z,onColumnResize:h,size:ae,loading:x,filter:I,onFilterUpdate:P?Mt:void 0,sortBy:F,onSortByUpdate:Q,hoverRow:b,emptyComponent:K,checkFilterCombination:V,createFilterField:W?Is:void 0,rowClassName:c.useCallback(H=>Oe?.includes(H.id)?"bg-gray-100 bg-opacity-75 dark:bg-gray-800 dark:bg-opacity-75":"",[Oe]),className:"flex-grow",endAdornment:se,AddColumnComponent:U})]})})},oe);function Is({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(ws,{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(Cs,{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(Es,{value:t,setValue:n,name:e,title:A})}else if(d.dataType==="date"){const A=d.name;return r.jsx(Bs,{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 $o(e,t=!1){return t?["string","number","date","reference"].includes(e.dataType):e.dataType==="array"?e.of?$o(e.of,!0):!1:["string","number","boolean","date","reference","array"].includes(e.dataType)}function Fs({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 Ns(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 Ps=50;function rn({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=Pe(),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:Ps,[y,w]=c.useState(),[C,E]=c.useState(m?b:void 0),k=c.useCallback((z,V)=>p.isFilterCombinationValid?p.isFilterCombinationValid({path:h,collection:t,filterValues:z,sortBy:V}):!0,[]),S=c.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]),[x,B]=c.useState(u??i??void 0),[N,I]=c.useState(S),P=c.useCallback(()=>B(u??void 0),[u]),F=c.useCallback(z=>{if(u){console.warn("Filter is not compatible with the force filter. Ignoring filter");return}z&&Object.keys(z).length===0?B(void 0):B(z)},[u]),{data:Q,dataLoading:Y,noMoreToLoad:J,dataLoadingError:_}=lo({path:e,collection:t,filterValues:x,sortBy:N,searchString:y,itemCount:C}),j=Fs({data:Q,entitiesDisplayedFirst:n});return{data:Ns(j,{filterValues:x,sortBy:N,searchString:y,lastDeleteTimestamp:o}),dataLoading:Y,noMoreToLoad:J,dataLoadingError:_,filterValues:x,setFilterValues:F,sortBy:N,setSortBy:I,searchString:y,setSearchString:w,clearFilter:P,itemCount:C,setItemCount:E,paginationEnabled:m,pageSize:b,checkFilterCombination:k,popupCell:d,setPopupCell:A}}function _o({entityOrEntitiesToDelete:e,collection:t,onClose:n,open:o,callbacks:l,onEntityDelete:i,onMultipleEntitiesDelete:s,path:a}){const d=Pe(),A=He(),[g,p]=c.useState(!1),[h,u]=c.useState(),[m,b]=c.useState(),y=X();c.useEffect(()=>{if(e){const F=Array.isArray(e)&&e.length===1?e[0]:e;u(F),b(Array.isArray(F))}},[e]);const w=c.useMemo(()=>Be({collection:t,path:a,fields:y.propertyConfigs}),[t,a]),C=c.useCallback(()=>{n()},[n]),E=c.useCallback(F=>{console.debug("Deleted",F)},[]),k=c.useCallback((F,Q)=>{A.open({type:"error",message:"Error deleting: "+Q?.message}),console.error("Error deleting entity"),console.error(Q)},[w.name]),S=c.useCallback((F,Q)=>{A.open({type:"error",message:"Error before deleting: "+Q?.message}),console.error(Q)},[w.name]),x=c.useCallback((F,Q)=>{A.open({type:"error",message:"Error after deleting: "+Q?.message}),console.error(Q)},[w.name]),B=c.useCallback(F=>io({dataSource:d,entity:F,collection:w,callbacks:l,onDeleteSuccess:E,onDeleteFailure:k,onPreDeleteHookError:S,onDeleteSuccessHookError:x,context:y}),[d,w,l,E,k,S,x,y]),N=c.useCallback(async()=>{h&&(p(!0),m?Promise.all(h.map(B)).then(F=>{p(!1),s&&h&&s(a,h),F.every(Boolean)?A.open({type:"success",message:`${w.name}: multiple deleted`}):F.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()}):B(h).then(F=>{p(!1),F&&(i&&h&&i(a,h),A.open({type:"success",message:`${w.singularName??w.name} deleted`}),n())}))},[h,m,B,s,a,n,A,w.name,i]);let I;if(h&&m)I=r.jsx(r.Fragment,{children:"Multiple entities"});else{const F=h;I=F?r.jsx(Wr,{entity:F,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:F=>F?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:I})]}),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:N,variant:"filled",color:"primary",children:"Ok"})]})]})}function Rt(e){return Array.isArray(e)?e:e?[e]:[]}function Ts({collection:e,relativePath:t,parentCollectionIds:n,onNewClick:o,onMultipleDeleteClick:l,selectionEnabled:i,path:s,selectionController:a,tableController:d,collectionEntitiesCount:A}){const g=X(),p=g.plugins??[],h=We(),u=Te(),m=a.selectedEntities,b=at(e,h,Ne(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,Ne(s),null);let w;if(i){const k=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:k})}const C={path:s,relativePath:t,parentCollectionIds:n,collection:e,selectionController:a,context:g,tableController:d,collectionEntitiesCount:A},E=Rt(e.Actions).map((k,S)=>r.jsx(ne,{children:r.jsx(k,{...C})},`actions_${S}`));return p&&p.forEach((k,S)=>{k.collections?.CollectionActions&&E.push(...Rt(k.collections?.CollectionActions).map((x,B)=>r.jsx(ne,{children:r.jsx(x,{...C,...k.collections?.collectionActionsProps})},`plugin_actions_${S}_${B}`)))}),r.jsxs(r.Fragment,{children:[E,w,b]})}function Qs({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 Ms(){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 Ds=({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(hn,{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 be({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 Os({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 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(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 nn({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(be,{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(ye,{includeDescription:A,showError:l,error:o,disabled:i,property:d})]})}function on({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(be,{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(ye,{includeDescription:a,showError:l,error:o,disabled:i,property:s})]})}function Wo({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(N=>N.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(N=>{console.debug("onMultipleEntitiesSelected",N),A(N.map(I=>et(I)))},[A]),E=It({multiselect:!0,path:p.path,collection:w,onMultipleEntitiesSelected:C,selectedEntityIds:b,forceFilter:p.forceFilter}),k=c.useCallback(N=>{N.preventDefault(),E.open()},[E]),S=c.useCallback((N,I)=>{const P=t&&t.length>N?t[N]:void 0;return P?r.jsx("div",{onMouseEnter:()=>m(!0),onMouseMove:()=>m(!0),onMouseLeave:()=>m(!1),children:r.jsx(Ge,{disabled:!p.path,previewProperties:p.previewProperties,size:"medium",onClick:k,reference:P,onHover:u})}):r.jsx("div",{children:"Internal ERROR"})},[p.path,p.previewProperties,u,t]),x=r.jsx(be,{icon:he(a,"small"),required:a.validation?.required,title:a.name,className:"text-text-secondary dark:text-text-secondary-dark"}),B=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:S,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:k,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:B}),s&&B,r.jsx(ye,{includeDescription:d,showError:o,error:n,disabled:l,property:a})]})}function jo({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 Vs="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",Gs="border-dotted-gray",Ys="hover:bg-field-hover dark:hover:bg-field-hover-dark",zs="pt-0 border-2 border-solid",Us="transition-colors duration-200 ease-[cubic-bezier(0,0,0.2,1)] border-2 border-solid border-green-500",Ls="transition-colors duration-200 ease-[cubic-bezier(0,0,0.2,1)] border-2 border-solid border-red-500";function ln({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}=xo({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 k={id:A.entityId,values:A.values,path:A.path};return r.jsxs(r.Fragment,{children:[!s&&r.jsx(be,{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(_s,{value:u,name:e,disabled:h,autoFocus:i,property:a,onChange:n,setInternalValue:m,onFilesAdded:b,entity:k,onFileUploadComplete:w,storagePathBuilder:C,storage:y,multipleFilesSupported:E}),r.jsx(ye,{includeDescription:d,showError:l,error:o,disabled:h,property:a})]})}function $s({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=He(),{getRootProps:C,getInputProps:E,isDragActive:k,isDragAccept:S,isDragReject:x}=En.useDropzone({accept:e.acceptedFiles?e.acceptedFiles.map(B=>({[B]:[]})).reduce((B,N)=>({...B,...N}),{}):void 0,disabled:t||n,noDragEventsBubbling:!0,maxSize:e.maxSize,onDrop:o,onDropRejected:(B,N)=>{for(const I of B)for(const P of I.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,Vs,l&&a.length?"":"flex",f.focusedMixin,{[Ys]:!k,[zs]:k,[Ls]:x,[Us]:S,[Gs]: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((B,N)=>{let I;return B.storagePathOrDownloadUrl?I=r.jsx(jo,{name:`storage_preview_${B.storagePathOrDownloadUrl}`,property:d,disabled:t,entity:A,value:B.storagePathOrDownloadUrl,onRemove:g,size:B.size}):B.file&&(I=r.jsx(No,{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:N,children:(P,F)=>r.jsx("div",{tabIndex:-1,ref:P.innerRef,...P.draggableProps,...P.dragHandleProps,className:f.cn(f.focusedMixin,"rounded-md"),style:{...P.draggableProps.style},children:I})},`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(f.Typography,{align:"center",variant:"label",children:y})})]})}function _s({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 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=c.useCallback((k,S)=>{if(!i)return;const x=[...n],B=x[k];x.splice(k,1),x.splice(S,0,B),o(x);const N=x.filter(I=>!!I.storagePathOrDownloadUrl).map(I=>I.storagePathOrDownloadUrl);l(N)},[i,l,o,n]),y=c.useCallback(k=>{k.destination&&b(k.source.index,k.destination.index)},[b]),w=c.useCallback(k=>{if(i){const S=n.filter(x=>x.storagePathOrDownloadUrl!==k);l(S.filter(x=>!!x.storagePathOrDownloadUrl).map(x=>x.storagePathOrDownloadUrl)),o(S)}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:(k,S,x)=>{const B=n[x.source.index];return r.jsx("div",{ref:k.innerRef,...k.draggableProps,...k.dragHandleProps,style:k.draggableProps.style,className:"rounded",children:r.jsx(jo,{name:`storage_preview_${B.storagePathOrDownloadUrl}`,property:E,disabled:!0,entity:p,value:B.storagePathOrDownloadUrl,onRemove:w,size:B.size})})},children:(k,S)=>r.jsx($s,{storage:g,disabled:a,isDraggingOver:S.isDraggingOver,droppableProvided:k,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(be,{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(ye,{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 Ho=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(be,{icon:he(A,"small"),required:A.validation?.required,title:A.name}),disabled:a,autoFocus:s,size:"medium"}),r.jsx(ye,{includeDescription:g,showError:i,error:l,disabled:a,property:A})]})});function Jo({propertyKey:e,value:t,setValue:n,autoFocus:o,error:l,showError:i,disabled:s,touched:a,property:d,includeDescription:A}){const{locale:g}=X(),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(be,{icon:he(d,"small"),required:d.validation?.required,className:"text-text-secondary dark:text-text-secondary-dark",title:d.name})}),r.jsx(ye,{includeDescription:A,showError:i,error:l,disabled:s,property:d})]})}function sn({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(be,{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(ye,{includeDescription:s,showError:o,error:n,property:i})]})}function qo(e){return typeof e.property.path!="string"?r.jsx(sn,{...e}):r.jsx(Ws,{...e})}function Ws({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 Me,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?et(w):null)},[t]),b=It({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(be,{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(Ge,{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(ye,{includeDescription:A,showError:o,error:n,disabled:i,property:d})]})}const nt=c.memo(js,(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 js({propertyKey:e,property:t,context:n,includeDescription:o,underlyingValueHasChanged:l,disabled:i,tableMode:s,partOfArray:a,partOfBlock:d,autoFocus:A}){const g=X(),h=tr(t,g.plugins)?Ce.Field:Ce.FastField;return r.jsx(h,{name:e,children:u=>{let m;const b=ke({propertyKey:e,propertyValue:u.field.value,propertyOrBuilder:t,values:u.form.values,path:n.path,entityId:n.entityId,fields:g.propertyConfigs});if(b===null||vt(b))return r.jsx(r.Fragment,{});if(it(b))m=sn;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=ke({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(Hs,{Component:m,componentProps:y,fieldProps:u})}})}function Hs({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}=X(),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(I=>!!I).length),k=Js(A.path,A.collection,t,n,e,h)??e,S=p.form.isSubmitting,x=c.useCallback((I,P)=>{p.form.setFieldTouched(t,!0,!1),p.form.setFieldValue(t,I,P)},[]),B=c.useCallback((I,P,F)=>{p.form.setFieldTouched(t,!0,!1),p.form.setFieldValue(I,P,F)},[]),N={propertyKey:t,value:m,initialValue:b,setValue:x,setFieldValue:B,error:y,touched:w,showError:C,isSubmitting:S,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(k,{...N}),l&&!S&&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 Js(e,t,n,o,l,i){return c.useRef((()=>{let a=null;return i&&i.forEach(d=>{const A=yn(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 Zo({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=Fn(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])=>!vt(E)).map(([C,E],k)=>{const S={propertyKey:`${e}.${C}`,disabled:l,property:E,includeDescription:A,underlyingValueHasChanged:g,context:h,tableMode:!1,partOfArray:!1,partOfBlock:!1,autoFocus:p&&k===0};return r.jsx("div",{children:r.jsx(nt,{...S})},`map-${e}-${k}`)})})}),w=r.jsx(be,{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(ye,{includeDescription:A,showError:n,error:o,disabled:l,property:i})]})}function Xo({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(an,{value:t,setValue:s,disabled:l,fieldName:i.name??e}),m=r.jsx(be,{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(ye,{includeDescription:d,showError:n,error:o,disabled:l,property:i})]})}function an({value:e,setValue:t,fieldName:n,disabled:o}){const[l,i]=c.useState(Object.keys(e??{}).map(d=>[cn(),{key:d,dataType:dn(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([cn(),{key:u,dataType:dn(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??""]:br(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(qs,{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,[cn(),{key:"",dataType:"string"}]])},children:n?`Add to ${n}`:"Add"})]})}function qs({rowId:e,fieldKey:t,value:n,onFieldKeyChange:o,onDeleteClick:l,setValue:i,entryValue:s,dataType:a,updateDataType:d,disabled:A}){const{locale:g}=X();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(hn,{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(Zs,{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(an,{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 Zs({id:e,index:t,value:n,setValue:o}){const{locale:l}=X(),[i,s]=c.useState(dn(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(an,{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 cn(){return Math.floor(Math.random()*Math.floor(Number.MAX_SAFE_INTEGER))}function dn(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 Me)return"reference";if(e instanceof Gt)return"geopoint";if(typeof e=="object")return"map"}function Ko({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=(k,S)=>{const x=d.resolvedProperties[k]??m,B={propertyKey:`${e}.${k}`,disabled:h,property:x,includeDescription:A,underlyingValueHasChanged:g,context:p,tableMode:!1,partOfArray:!0,partOfBlock:!1,autoFocus:S===b};return r.jsx(nt,{...B})},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(be,{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(ye,{includeDescription:A,showError:o,error:n,disabled:h,property:d})]})}function Ro({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((k,S)=>r.jsx(Xs,{name:`${e}.${k}`,index:k,value:t[k],typeField:d.oneOf.typeField??yt,valueField:d.oneOf.valueField??zt,properties:d.oneOf.properties,autoFocus:S===m,context:p},`array_one_of_${k}`),[p,m,d.oneOf,e,t]),w=r.jsx(be,{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??yt]: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(ye,{includeDescription:A,showError:o,error:n,disabled:h,property:d})]})}function Xs({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 Ks=new Sl;try{Re.use(Re.Plugins.AutoResize,{min:100}),Re.unuse(Re.Plugins.FontUnderline),Re.unuse(Re.Plugins.Clear)}catch{}function el({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",Rs);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(be,{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(Re,{value:h??"",className:f.cn(f.fieldBackgroundMixin,i?f.fieldBackgroundDisabledMixin:f.fieldBackgroundHoverMixin,"text-base"),readOnly:i,renderHTML:y=>Ks.render(y),view:{menu:!0,md:!0,html:!1},onChange:({html:y,text:w})=>{u(w??null)}}),r.jsx(ye,{includeDescription:g,showError:l,error:o,disabled:i,property:d})]})}const Rs=`
|
|
6
5
|
@font-face {
|
|
7
6
|
font-family: rmel-iconfont;
|
|
8
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=);
|
|
@@ -585,5 +584,6 @@
|
|
|
585
584
|
.rc-md-editor .header-list .list-item:hover {
|
|
586
585
|
}
|
|
587
586
|
|
|
588
|
-
`;function dl({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(X(),!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(be,{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 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(ye,{includeDescription:d,showError:o,error:n,disabled:p,property:a})]})}const ua=({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=Al(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},ga=e=>{const t=e&&e.scrollHeight>e.clientHeight,n=e?window.getComputedStyle(e).overflowY:null,o=n&&n.indexOf("hidden")!==-1;return t&&!o},Al=e=>!e||e===document.body?document.body:ga(e)?e:Al(e.parentNode);function ha({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}=ao({onSuccess:u=>A.open({type:"success",message:`Copied ${u}`})}),p=X(),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 fl=c.memo(pa,(e,t)=>e.status===t.status&&e.path===t.path&&oe(e.entity?.values,t.entity?.values));function pa({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=X(),m=Te(),b=u.plugins,y=c.useMemo(()=>Be({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),k=c.useMemo(()=>{const M=y.properties;if((e==="existing"||e==="copy")&&o)return o.values??wt(M);if(e==="new")return wt(M);throw console.error({status:e,entity:o}),new Error("Form has not been initialised with the correct parameters")},[e,y,o]),[S,x]=c.useState(C),[B,N]=c.useState(!1),[I,T]=c.useState(),F=c.useRef(o?.values??k),Q=F.current,[Y,J]=c.useState(Q),_=M=>{J(M),a&&a(M),p&&M&&!oe(M,Q)&&V(M)};c.useEffect(()=>{S&&d&&d(S)},[S,d]);const j=Be({collection:n,path:t,entityId:S,values:Y,previousValues:Q,fields:u.propertyConfigs}),te=j.callbacks?.onIdUpdate;c.useEffect(()=>{if(te&&Y&&(e==="new"||e==="copy"))try{const M=te({collection:j,path:t,entityId:S,values:Y,context:u});x(M)}catch(M){h&&h(M),console.error(M)}},[S,Y,e]);const z=c.useMemo(()=>Q&&e==="existing"?Object.entries(j.properties).map(([M,$])=>{if(vt($))return{};const K=Q[M],L=k[M];return oe(K,L)?{}:{[M]:L}}).reduce((M,$)=>({...M,...$}),{}):{},[k,j.properties,Q,e]),V=M=>l({collection:j,path:t,entityId:S,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}),F.current=M}).catch($=>{console.error($),T($)}).finally(()=>{E.current=!1}),re=(M,$)=>{if(w&&!S){console.error("Missing custom Id"),N(!0),$.setSubmitting(!1);return}if(T(void 0),N(!1),e==="existing"){if(!o?.id)throw Error("Form misconfiguration when saving, no id for existing entity")}else if(e==="new"||e==="copy"){if(j.customId&&j.customId!=="optional"&&!S)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,$,S),[m,t,S]),q=c.useMemo(()=>S?Po(S,j.properties,W):void 0,[S,j.properties,W]),se=_e(),U=c.useCallback(({entity:M,customEntityActions:$})=>{const K=at(j,se,Ne(t),null),L=M?Ht(j,se,Ne(t),M):!0,P=[];return K&&P.push(_o),L&&P.push(Wo),$&&P.push(...$),P},[se,j,t]);return r.jsx(Ce.Formik,{initialValues:k,onSubmit:re,validationSchema:q,validate:M=>console.debug("Validating",M),onReset:()=>i&&i(),children:M=>{const $=[],K={setFieldValue:M.setFieldValue,values:M.values,collection:Be({collection:j,path:t,fields:u.propertyConfigs}),entityId:S,path:t,save:V};if(c.useEffect(()=>{A&&A(K)},[A,K]),b&&j){const L={entityId:S,path:t,status:e,collection:n,context:u,currentEntityId:S,formContext:K};$.push(...b.map((P,D)=>P.form?.Actions?r.jsx(P.form.Actions,{...L},`actions_${P.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 "+j.hideIdFromForm?"mb-2":"mb-0",variant:"h4",children:j.singularName??j.name})}),!g&&r.jsx(ha,{customId:j.customId,entityId:S,status:e,onChange:x,error:B,entity:o}),S&&r.jsx(ma,{...M,initialValues:Q,onModified:s,onValuesChanged:_,underlyingChanges:z,entity:o,resolvedCollection:j,formContext:K,status:e,savingError:I,closeAfterSaveRef:E,autoSave:p,entityActions:U({entity:o,customEntityActions:j.entityActions})})]})]})}})}function ma(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=X(),E=w.filter(I=>I.includeInForm===void 0||I.includeInForm),k=We(),S=m;c.useEffect(()=>{n&&n(S),o&&o(t)},[S,t]),c.useEffect(()=>{!y&&l&&s&&Object.entries(l).forEach(([I,T])=>{const F=t[I];!oe(T,F)&&!a[I]&&(console.debug("Updated value from the datasource:",I,T),d(I,T!==void 0?T: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(I=>{const T=A.properties[I];if(!T)return console.warn(`Property ${I} not found in collection ${A.name}`),null;const F=!!l&&Object.keys(l).includes(I)&&!!a[I],Q=!y&&g||it(T)||!!T.disabled;if(vt(T))return null;const J={propertyKey:I,disabled:Q,property:T,includeDescription:T.description||T.longDescription,underlyingValueHasChanged:F&&!y,context:i,tableMode:!1,partOfArray:!1,partOfBlock:!1,autoFocus:!1};return r.jsx("div",{id:`form_field_${I}`,children:r.jsx(ne,{children:r.jsx(nt,{...J})})},`field_${A.name}_${I}`)}).filter(Boolean)}),B=g||!S&&p==="existing",N=c.useRef(null);return r.jsxs(Ce.Form,{onSubmit:h,noValidate:!0,children:[r.jsxs("div",{className:"mt-12",ref:N,children:[x,r.jsx(ua,{containerRef:N})]}),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(I=>r.jsx(f.IconButton,{color:"primary",onClick:T=>{T.stopPropagation(),s&&I.onClick({entity:s,fullPath:A.path,collection:A,context:C,sideEntityController:k})},children:I.icon},I.name))}),r.jsx(f.Button,{variant:"text",disabled:B,type:"reset",children:p==="existing"?"Discard":"Clear"}),r.jsxs(f.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(f.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 ul(e){return Object.keys(An).includes(e)}const An={text_field:{key:"text_field",name:"Text field",description:"Simple short text",Icon:f.ShortTextIcon,color:"#2d7ff9",property:{dataType:"string",Field:pt}},multiline:{key:"multiline",name:"Multiline",description:"Text with multiple lines",Icon:f.SubjectIcon,color:"#2d7ff9",property:{dataType:"string",multiline:!0,Field:pt}},markdown:{key:"markdown",name:"Markdown",description:"Text with advanced markdown syntax",Icon:f.FormatQuoteIcon,color:"#2d7ff9",property:{dataType:"string",markdown:!0,Field:cl}},url:{key:"url",name:"Url",description:"Text with URL validation",Icon:f.HttpIcon,color:"#154fb3",property:{dataType:"string",url:!0,Field:pt}},email:{key:"email",name:"Email",description:"Text with email validation",Icon:f.EmailIcon,color:"#154fb3",property:{dataType:"string",email:!0,Field:pt}},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:nn}},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:on}},number_input:{key:"number_input",name:"Number input",description:"Simple number field with validation",Icon:f.NumbersIcon,color:"#bec920",property:{dataType:"number",Field:pt}},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:nn}},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:on}},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:ln}},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:ln}},reference:{key:"reference",name:"Reference",description:"The value refers to a different collection",Icon:f.LinkIcon,color:"#ff0042",property:{dataType:"reference",Field:ol}},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:el}},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:rl}},date_time:{key:"date_time",name:"Date/time",description:"A date time select field",Icon:f.ScheduleIcon,color:"#8b46ff",property:{dataType:"date",Field:nl}},group:{key:"group",name:"Group",description:"Group of multiple fields",Icon:f.BallotIcon,color:"#ff9408",property:{dataType:"map",properties:{},Field:ll}},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:il}},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:sl}},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:dl}},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:al}}};function tr(e,t){const n=un(e),o=fn(e);if(!o){console.error("No field id found for property",e);return}const l=An[o],i=n?t[n]:void 0;return Fe(l??{},i??{})}function fn(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 un(e){return e.propertyConfig?e.propertyConfig:fn(e)}const Be=({collection:e,path:t,entityId:n,values:o,previousValues:l,userConfigPersistence:i,fields:s})=>{const a=i?.getCollectionConfig(t),d=Le(a,"properties"),A=wt(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;return{[b]:ke({propertyKey:b,propertyOrBuilder:y,values:g,previousValues:p,path:t,propertyValue:w,entityId:n,fields:s})}}).filter(b=>b!==null).reduce((b,y)=>({...b,...y}),{}),u=Fe(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 ke({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 console.debug("Property builder not returning `Property` so it is not rendered",i,o.entityId,e),null;l=ke({...o,propertyValue:t,propertyOrBuilder:s,fromBuilder:!0})}else{const i=e;if(i.dataType==="map"&&i.properties){const s=gn({...o,properties:i.properties,propertyValue:t});l={...i,resolved:!0,fromBuilder:n,properties:s}}else i.dataType==="array"?l=Je({property:i,propertyValue:t,fromBuilder:n,...o}):(i.dataType==="string"||i.dataType==="number")&&i.enumValues&&(l=hn(i,n))}else return null;if(l||(l={...e,resolved:!0,fromBuilder:n}),l.propertyConfig&&!ul(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=ke({propertyOrBuilder:a,propertyValue:t,...o});d&&(l=Fe(d,l))}}return l?{...l,resolved:!0}:null}function Je({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)=>ke({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)=>ke({propertyKey:`${e}.${d}`,propertyOrBuilder:l,propertyValue:a,...o,index:d})).filter(a=>!!a):[],s=ke({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??yt,i=Array.isArray(n)?n.map((a,d)=>{const A=a&&a[l],g=t.oneOf?.properties[A];return!A||!g?null:ke({propertyKey:`${e}.${d}`,propertyOrBuilder:g,propertyValue:n,...o})}).filter(a=>!!a):[],s=gn({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 gn({properties:e,propertyValue:t,...n}){return Object.entries(e).map(([o,l])=>({[o]:ke({propertyKey:o,propertyOrBuilder:l,propertyValue:t&&typeof t=="object"?Le(t,o):void 0,...n})})).filter(o=>o!==null).reduce((o,l)=>({...o,...l}),{})}function hn(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 ba(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 pn(e,t){return typeof e=="string"?t?.find(n=>n.key===e):e}function mn(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=>pn(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(...mn({path:y,collections:A.subcollections,currentFullPath:b,contextEntityViews:e.contextEntityViews}))}}break}}return s}const ya="100vw",va="55vw",gl="768px",rr="main_##Q$SC^#S6";function wa({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:q?.id,collection:l,path:e,values:h,closeAfterSave:!1})},!1,2e3);const m=Te(),b=nr(),y=We(),w=je(),C=X(),E=_e(),[k,S]=c.useState(void 0),[x,B]=c.useState(o?"copy":t?"existing":"new"),N=c.useRef(void 0),I=N.current,T=(l.subcollections??[]).filter(G=>!G.hideFromNavigation),F=T?.length??0,Q=l.entityViews,Y=Q?.length??0,J=l.formAutoSave&&!l.customId,_=Y>0||F>0,j=n??br(l?l.defaultSelectedView:void 0,{status:x,entityId:t}),te=c.useRef(j??rr),z=te.current===rr,{entity:V,dataLoading:re,dataLoadingError:W}=Sr({path:e,entityId:t,collection:l,useCache:!1}),[q,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=q?Cr(l,E,Ne(e),q??null):!1;q&&M(!G)}},[E,q,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),J||w.open({type:"success",message:`${l.singularName??l.name}: Saved correctly`}),se(G),B("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})},P=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:Z,entityId:R,collection:ee,path:ce})=>{p(!0),Ir({path:ce,entityId:R,values:G,previousValues:O,collection:ee,status:x,dataSource:m,context:C,onSaveSuccess:De=>L(De,Z),onSaveFailure:P,onPreSaveHookError:$,onSaveSuccessHookError:K}).then()},Se=async({collection:G,path:O,entityId:Z,values:R,previousValues:ee,closeAfterSave:ce,autoSave:De})=>{x&&(De?u(R):D({collection:G,path:O,entityId:Z,values:R,previousValues:ee,closeAfterSave:ce}))},Ae=Q?Q.map(G=>pn(G,C.entityViews)).filter(Boolean):[],ae=Q&&Ae.map((G,O)=>{if(!G||te.current!==G.key)return null;const Z=G.Builder;return Z?r.jsx("div",{className:f.cn(f.defaultBorderMixin,"relative flex-grow w-full h-full overflow-auto "),role:"tabpanel",children:r.jsx(ne,{children:k&&r.jsx(Z,{collection:l,entity:q,modifiedValues:I??q?.values,formContext:k})})},`custom_view_${G.key}`):(console.error("customView.Builder is not defined"),null)}).filter(Boolean),Ie=re&&!q||(!q||U===void 0)&&(x==="existing"||x==="copy"),qe=Ie||g,Ye=T&&T.map((G,O)=>{const Z=G.id??G.path,R=q?`${e}/${q?.id}/${ue(Z)}`:void 0;return te.current!==Z?null:r.jsxs("div",{className:"relative flex-grow h-full overflow-auto w-full",role:"tabpanel",children:[qe&&r.jsx(St,{}),!Ie&&(q&&R?r.jsx(Xr,{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_${Z}`)}).filter(Boolean),Oe=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})},mt=c.useCallback(G=>{N.current=G},[]),Nt=c.useCallback(G=>{w.open({type:"error",message:"Error updating id, check the console"})},[]),Ze=c.useCallback(G=>{se(O=>O?{...O,id:G}:void 0)},[]),Xe=G=>{J||s(G)};function Tt(){const G=C.plugins;let O=r.jsx(fl,{status:x,path:e,collection:l,onEntitySaveRequested:Se,onDiscard:Oe,onValuesChanged:mt,onModified:Xe,entity:q,onIdChange:Ze,onFormContextChange:S,hideId:l.hideIdFromForm,autoSave:J,onIdUpdateError:Nt});return G&&G.forEach(Z=>{Z.form?.provider&&(O=r.jsx(Z.form.provider.Component,{status:x,path:e,collection:l,onDiscard:Oe,onValuesChanged:mt,onModified:Xe,entity:q,context:C,formContext:k,...Z.form.provider.props,children:O}))}),r.jsx(ne,{children:O})}const Ke=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(Yr,{className:"px-12",entity:q,path:e,collection:l})]}):Tt(),Pt=T&&T.map(G=>r.jsx(f.Tab,{className:"text-sm min-w-[140px]",value:G.id,children:G.name},`entity_detail_collection_tab_${G.name}`)),Qt=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"}),Ie&&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}),Qt,Pt]})]}),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:Ie?r.jsx(St,{}):Ke}),ae,Ye]})]})})}function Ca(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 Ea({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 hl=c.createContext({width:"",blocked:!1,setBlocked:e=>{},setBlockedNavigationMessage:e=>{},close:()=>{}}),nr=()=>c.useContext(hl);function Ba(){const t=Et().sidePanels,n=[...t];return n.push(void 0),r.jsx(r.Fragment,{children:n.map((o,l)=>r.jsx(ka,{panel:o,offsetPosition:t.length-l-1},`side_dialog_${l}`))})}function ka({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=Et(),{navigationWasBlocked:p,handleOk:h,handleCancel:u}=Ca(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(hl.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(Ea,{open:p||n,handleOk:n?m:h,handleCancel:n?b:u,body:s})]})}function xa(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(wa,{...e,formWidth:e.width,collection:s,parentCollectionIds:i,onValuesAreModified:a})})})}const pl="new";function Sa(e,t){if(t)return ya;const n=!e.selectedSubPath,o=typeof e.width=="number"?`${e.width}px`:e.width;return n?o??gl:`calc(${va} + ${o??gl})`}const Ia=(e,t)=>{const n=fe.useLocation(),o=c.useRef(!1),l=!Pe();c.useEffect(()=>{if(!e.loading&&!o.current){if(e.isUrlCollectionPath(n.pathname)){const d=n.hash===`#${pl}`,A=e.urlPathToDataPath(n.pathname),g=Fa(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 Fa(e,t,n){const o=mn({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}#${pl}`);return{key:`${e.path}/${e.entityId}`,component:r.jsx(xa,{...e}),urlPath:l,parentUrlPath:t.buildUrlCollectionPath(o),width:Sa(e,n),onClose:e.onClose}};function Na(){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 Ta(e){c.useEffect(()=>{if(!e)return;const t=kn[e];t&&(En.registerLocale(e,t),En.setDefaultLocale(e))},[e])}function ml(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 Me(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(...ml({path:y,collections:A.subcollections,currentFullPath:b}))}}break}}return s}const Pa="/",Qa="/c";function Ma({basePath:e=Pa,baseCollectionPath:t=Qa,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,k]=c.useState(void 0),S=ue(e),x=ue(t),B=S?`/${S}`:"/",N=S?`/${S}/${x}`:`/${x}`,I=c.useCallback(U=>S?`/${S}/${lr(U)}`:`/${lr(U)}`,[S]),T=c.useCallback(U=>`${ue(t)}/${lr(U)}`,[t]),F=c.useCallback((U,M)=>{const $=[...(U??[]).map(L=>L.hideFromNavigation?void 0:{url:T(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:I(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,P,D)=>D.indexOf(L)===P);return{navigationEntries:$,groups:K}},[I,T]),Q=c.useCallback(async()=>{if(!n.initialLoading){try{const[U=[],M=[]]=await Promise.all([Da(o,n,a,s),Oa(l,n,a)]);g(U),h(M),y(F(U??[],M))}catch(U){console.error(U),k(U)}C(!1),m(!0)}},[o,n.user,n.initialLoading,s,l,F]);c.useEffect(()=>{Q()},[Q]);const Y=c.useCallback((U,M,$=!1)=>{if(!A)return;const K=Ot(ue(U),A),L=$?i?.getCollectionConfig(U):void 0,P=K?Fe(K,L):void 0;let D=P;if(P){const Se=P.subcollections,Ae=P.callbacks,ae=P.permissions;D={...D,subcollections:D?.subcollections??Se,callbacks:D?.callbacks??Ae,permissions:D?.permissions??ae}}if(D)return{...P,...D}},[e,t,A]),J=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(P=>P.id===K||P.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(P=>P.id===K);if(!L)return;if(M=L.subcollections,$===U.length-1)return L}},[A]),j=c.useCallback(U=>ue(U+"/").startsWith(ue(N)+"/"),[N]),te=c.useCallback(U=>{if(U.startsWith(N))return U.replace(N,"");throw Error("Expected path starting with "+N)},[N]),z=c.useCallback(({path:U})=>`s/edit/${lr(U)}`,[]),V=c.useCallback(U=>{if(!A)throw Error("Collections have not been initialised yet");return dr(U,A)},[A]),re=d.state,W=re&&re.base_location?re.base_location:d,q=c.useCallback(U=>ml({path:U,collections:A}),[A]),se=c.useCallback(U=>q(U).map(M=>M.id),[q]);return c.useMemo(()=>({collections:A??[],views:p??[],loading:!u||w,navigationLoadingError:E,homeUrl:B,basePath:e,baseCollectionPath:t,initialised:u,getCollection:Y,getCollectionFromPaths:J,getCollectionFromIds:_,isUrlCollectionPath:j,urlPathToDataPath:te,buildUrlCollectionPath:T,buildUrlEditCollectionPath:z,buildCMSUrlPath:I,resolveAliasesFrom:V,topLevelNavigation:b,baseLocation:W,refreshNavigation:Q,getParentReferencesFromPath:q,getParentCollectionIds:se}),[t,W,e,I,T,z,A,q,Y,J,B,u,j,w,E,Q,V,b,te,p])}function lr(e){return encodeURIComponent(ue(e)).replaceAll("%2F","/").replaceAll("%23","#")}function bl(e,t){return e.filter(n=>n.permissions?Ct(n,t,[n.path],null).read!==!1:!0).map(n=>n.subcollections?{...n,subcollections:bl(n.subcollections,t)}:n)}async function Da(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=bl(l,t),o&&o.forEach(i=>{i.collections?.injectCollections&&(l=i.collections?.injectCollections(l??[]))}),l}async function Oa(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 Va({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?Be({collection:d,path:o,entityId:l,fields:t}):void 0)?.properties,p=bn(i,e.buildReference,e.buildGeoPoint,e.buildDate,e.buildDeleteFieldValue),h=g?Tn({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 bn(e,t,n,o,l){return e===void 0?l():Array.isArray(e)?e.map(i=>bn(i,t,n,o,l)):e instanceof Me?t(e):e instanceof Gt?n(e):e instanceof Date?o(e):e&&typeof e=="object"?Object.entries(e).map(([i,s])=>({[i]:bn(s,t,n,o,l)})).reduce((i,s)=>({...i,...s}),{}):e}function Ga(e){const t=Fr(),{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;Ta(s);const E=Ma({basePath:y,baseCollectionPath:b,authController:a,collections:w,views:C,userConfigPersistence:l,dataSource:A,plugins:g}),k=Va({delegate:A,propertyConfigs:h,navigationController:E}),S=Na(),x=Ia(E,S),B=g?.some(T=>T.loading)??!1,N=a.initialLoading||E.loading||B,I=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(he,{title:"Error loading navigation",error:E.navigationLoadingError})}):a.authError?r.jsx(f.CenteredView,{maxWidth:"md",fullScreen:!0,children:r.jsx(he,{title:"Error loading auth",error:a.authError})}):r.jsx(Dt.Provider,{value:t,children:r.jsx(kr.Provider,{value:I,children:r.jsx(no.Provider,{value:l,children:r.jsx(ro.Provider,{value:d,children:r.jsx(Kn.Provider,{value:k,children:r.jsx(cr.Provider,{value:a,children:r.jsx(eo.Provider,{value:S,children:r.jsx(to.Provider,{value:x,children:r.jsx(Rn.Provider,{value:E,children:r.jsx(Ql,{children:r.jsx(fi,{children:r.jsx(Ya,{loading:N,children:n})})})})})})})})})})})})}function Ya({loading:e,children:t}){const n=X();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 yl({hovered:e,drawerOpen:t,closeDrawer:n}){const o=X(),l=ie(),i=e&&!t,s=Pe();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(yn,{icon:Jt(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(yn,{icon:Jt(h.collection??h.view),tooltipsOpen:i,onClick:()=>p(h),drawerOpen:t,url:h.url,name:h.name},`navigation_${u}`))]})}function yn({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 za=280,Ua=c.memo(function(t){const{children:n,name:o,logo:l,includeDrawer:i=!0,autoOpenDrawer:s,Drawer:a=yl,drawerProps:d,FireCMSAppBarComponent:A=Ko,fireCMSAppBarComponentProps:g}=t,p=Pe(),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)},[]),k=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:k,...g}),r.jsx($a,{displayed:i,onMouseEnter:w,onMouseMove:w,onMouseLeave:C,open:k,logo:l,hovered:b,setDrawerOpen:m,children:i&&(h.loading?r.jsx(St,{}):r.jsx(a,{hovered:b,drawerOpen:k,closeDrawer:E,...d}))}),r.jsxs("main",{className:"flex flex-col flex-grow overflow-auto",children:[r.jsx(La,{}),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),La=()=>r.jsx("div",{className:"flex flex-col min-h-[68px]"});function $a(e){const t=ie(),n=e.displayed?e.open?za: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(Xo,{})})})}),e.children]})]});return Pe()?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}const _a=c.memo(function({HomePage:t=qo,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=>vl(u,h))):a.push(vl(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(ir,{path:u,title:h.name,type:"collection",children:r.jsx(Xr,{isSubCollection:!1,parentCollectionIds:[],fullPath:h.id??h.path,...h,Actions:Kt(h.Actions)},`collection_view_${h.id??h.path}`)})},`navigation_${h.id??h.path}`)}),g=r.jsx(fe.Route,{path:"/",element:r.jsx(ir,{path:l.homeUrl,title:"Home",type:"home",children:r.jsx(t,{})},"navigation_home")}),p=r.jsx(fe.Route,{path:"*",element:r.jsx(Zo,{})});return r.jsxs(fe.Routes,{location:s,children:[A,a,g,p,n]})}),vl=(e,t)=>r.jsx(fe.Route,{path:e,element:r.jsx(ir,{path:e,title:t.name,type:"view",children:t.view},`navigation_${e}`)},"navigation_view_"+e),ir=c.memo(function({children:t,title:n,path:o,type:l}){const i=Nr();return c.useEffect(()=>{i.set({breadcrumbs:[{title:n,url:o}]})},[o,n]),r.jsx(r.Fragment,{children:t})},oe);function Wa(){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 ja(){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::${yr(m)}`;return e[b]?e[b]:n(b)},[e,n]),l=c.useCallback((m,b)=>{const y=`collection_config::${yr(m)}`;localStorage.setItem(y,JSON.stringify(b)),t(w=>{const C=w[y],E=Fe(C??n(m),b);return Fe(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=tn,v.ArrayContainerItem=rn,v.ArrayCustomShapedFieldBinding=dl,v.ArrayEnumPreview=Or,v.ArrayItemOptions=Ro,v.ArrayOfMapsPreview=Mi,v.ArrayOfReferencesFieldBinding=el,v.ArrayOfReferencesPreview=ho,v.ArrayOfStorageComponentsPreview=po,v.ArrayOfStringsPreview=mo,v.ArrayOneOfPreview=bo,v.ArrayPropertyEnumPreview=Vr,v.ArrayPropertyPreview=Dr,v.AsyncPreviewComponent=Di,v.AuthControllerContext=cr,v.BlockFieldBinding=al,v.BooleanPreview=wo,v.BreadcrumbUpdater=Ws,v.COLLECTION_PATH_SEPARATOR=Gn,v.CircularProgressCenter=St,v.DEFAULT_FIELD_CONFIGS=An,v.DatePreview=vo,v.DateTimeFieldBinding=nl,v.DefaultHomePage=qo,v.DeleteConfirmationDialog=js,v.Drawer=yl,v.DrawerNavigationItem=yn,v.EmptyValue=At,v.EntityCollectionTable=qr,v.EntityCollectionView=Xr,v.EntityForm=fl,v.EntityPreview=Yr,v.EntityReference=Me,v.EnumValuesChip=we,v.ErrorBoundary=ne,v.ErrorView=he,v.FieldConfigBadge=_s,v.FieldHelperText=ye,v.FireCMS=Ga,v.FireCMSAppBar=Ko,v.FireCMSContextInstance=kr,v.FireCMSLogo=Xo,v.FormikArrayContainer=Rt,v.GeoPoint=Gt,v.ImagePreview=co,v.KeyValueFieldBinding=il,v.KeyValuePreview=Gr,v.LabelWithIcon=be,v.MapFieldBinding=ll,v.MapPropertyPreview=yo,v.MarkdownFieldBinding=cl,v.ModeControllerContext=Dt,v.ModeControllerProvider=Ol,v.MultiSelectBinding=on,v.NavigationCollectionCard=Jo,v.NavigationGroup=Rr,v.NavigationRoutes=_a,v.NotFoundPage=Zo,v.NumberPropertyPreview=Co,v.PropertyFieldBinding=nt,v.PropertyPreview=me,v.ReadOnlyFieldBinding=sn,v.ReferenceFieldBinding=ol,v.ReferencePreview=Ge,v.ReferencePreviewContainer=Zt,v.ReferenceSelectionInner=Ho,v.RepeatFieldBinding=sl,v.RouteWrapper=ir,v.Scaffold=Ua,v.SelectFieldBinding=nn,v.SideDialogs=Ba,v.SkeletonPropertyComponent=ut,v.SnackbarProvider=Ml,v.StorageThumbnail=Ao,v.StorageThumbnailInternal=uo,v.StorageUploadFieldBinding=ln,v.StringPropertyPreview=Mr,v.SwitchControl=qs,v.SwitchFieldBinding=rl,v.TextFieldBinding=pt,v.UrlComponentPreview=kt,v.VirtualTable=Qo,v.addInitialSlash=Gl,v.buildAdditionalFieldDelegate=di,v.buildCollection=ni,v.buildEntityCallbacks=ci,v.buildEnumLabel=Dn,v.buildEnumValueConfig=ai,v.buildEnumValues=si,v.buildFieldConfig=Ai,v.buildProperties=li,v.buildPropertiesOrBuilder=ii,v.buildProperty=oi,v.canCreateEntity=at,v.canDeleteEntity=Ht,v.canEditEntity=Cr,v.defaultDateFormat=Vn,v.deleteEntityWithCallbacks=io,v.enumToObjectEntries=$e,v.flattenObject=Er,v.fullPathToCollectionSegments=Ne,v.getArrayValuesCount=Wn,v.getBracketNotation=Rl,v.getCollectionByPathOrAlias=Ot,v.getCollectionPathsCombinations=Vt,v.getColorForProperty=Kl,v.getColorScheme=Mn,v.getDefaultFieldId=fn,v.getDefaultPropertiesOrder=ei,v.getDefaultValueFor=Ut,v.getDefaultValueForDataType=hr,v.getDefaultValuesFor=wt,v.getFieldConfig=tr,v.getFieldId=un,v.getHashValue=fr,v.getIcon=$n,v.getIconForProperty=pe,v.getIconForView=Jt,v.getIconForWidget=vr,v.getIdIcon=Xl,v.getLabelOrConfigFrom=$t,v.getLastSegment=Yl,v.getPropertiesWithPropertiesOrder=Ln,v.getPropertyInPath=tt,v.getRandomId=It,v.getReferenceFrom=et,v.getReferencePreviewKeys=_n,v.getResolvedPropertyInPath=wr,v.getValueInPath=Le,v.hydrateRegExp=zn,v.isDefaultFieldConfigId=ul,v.isEmptyObject=gr,v.isEnumValueDisabled=Ll,v.isHidden=vt,v.isObject=Yt,v.isPropertyBuilder=ve,v.isReadOnly=it,v.isReferenceProperty=Un,v.isValidRegExp=ql,v.joinCollectionLists=Jn,v.makePropertiesEditable=jn,v.makePropertiesNonEditable=Hn,v.mergeCollection=qn,v.mergeDeep=Fe,v.pick=Fn,v.plural=ti,v.randomColor=Hl,v.randomString=st,v.removeFunctions=Ar,v.removeInPath=zl,v.removeInitialAndTrailingSlashes=ue,v.removeInitialSlash=Sn,v.removePropsIfExisting=Nn,v.removeTrailingSlash=In,v.removeUndefined=ur,v.renderSkeletonCaptionText=Ii,v.renderSkeletonIcon=Qr,v.renderSkeletonImageThumbnail=Pr,v.renderSkeletonText=Ve,v.resolveArrayProperty=Je,v.resolveCollection=Be,v.resolveCollectionPathAliases=dr,v.resolveDefaultSelectedView=br,v.resolveEntityView=pn,v.resolveEnumValues=ba,v.resolveNavigationFrom=so,v.resolvePermissions=Ct,v.resolveProperties=gn,v.resolveProperty=ke,v.resolvePropertyEnum=hn,v.sanitizeData=Ul,v.saveEntityWithCallbacks=Ir,v.segmentsToStrippedPath=Yn,v.serializeRegExp=Jl,v.singular=ri,v.slugify=_t,v.sortProperties=mr,v.stripCollectionPath=yr,v.toKebabCase=_l,v.toSnakeCase=jl,v.traverseValueProperty=Lt,v.traverseValuesProperties=pr,v.unslugify=Vl,v.updateDateAutoValues=Tn,v.useAuthController=_e,v.useBreadcrumbsContext=Nr,v.useBrowserTitleAndIcon=mi,v.useBuildLocalConfigurationPersistence=ja,v.useBuildModeController=Wa,v.useClearRestoreValue=xe,v.useClipboard=ao,v.useCollectionFetch=lo,v.useDataSource=Te,v.useDebounce=Wt,v.useDebounceValue=Zl,v.useEntityCollectionTableController=Zr,v.useEntityFetch=Sr,v.useFireCMSContext=X,v.useLargeLayout=Pe,v.useModeController=Fr,v.useNavigationController=ie,v.useReferenceDialog=Bt,v.useResolvedNavigationFrom=gi,v.useSelectionController=Kr,v.useSideDialogContext=nr,v.useSideDialogsController=Et,v.useSideEntityController=We,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 tl({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(X(),!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(be,{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(ye,{includeDescription:d,showError:o,error:n,disabled:p,property:a})]})}const ea=({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=rl(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},ta=e=>{const t=e&&e.scrollHeight>e.clientHeight,n=e?window.getComputedStyle(e).overflowY:null,o=n&&n.indexOf("hidden")!==-1;return t&&!o},rl=e=>!e||e===document.body?document.body:ta(e)?e:rl(e.parentNode);function ra({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=He(),{copy:g}=ao({onSuccess:u=>A.open({type:"success",message:`Copied ${u}`})}),p=X(),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 na={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)}},nl={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)}},ol={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(_o,{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)}},ll=c.memo(oa,(e,t)=>e.status===t.status&&e.path===t.path&&oe(e.entity?.values,t.entity?.values));function oa({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=X(),m=Pe(),b=u.plugins,y=c.useMemo(()=>Be({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),k=c.useMemo(()=>{const M=y.properties;if((e==="existing"||e==="copy")&&o)return o.values??wt(M);if(e==="new")return wt(M);throw console.error({status:e,entity:o}),new Error("Form has not been initialised with the correct parameters")},[e,y,o]),[S,x]=c.useState(C),[B,N]=c.useState(!1),[I,P]=c.useState(),F=c.useRef(o?.values??k),Q=F.current,[Y,J]=c.useState(Q),_=M=>{J(M),a&&a(M),p&&M&&!oe(M,Q)&&V(M)};c.useEffect(()=>{S&&d&&d(S)},[S,d]);const j=Be({collection:n,path:t,entityId:S,values:Y,previousValues:Q,fields:u.propertyConfigs}),te=j.callbacks?.onIdUpdate;c.useEffect(()=>{if(te&&Y&&(e==="new"||e==="copy"))try{const M=te({collection:j,path:t,entityId:S,values:Y,context:u});x(M)}catch(M){h&&h(M),console.error(M)}},[S,Y,e]);const z=c.useMemo(()=>Q&&e==="existing"?Object.entries(j.properties).map(([M,$])=>{if(vt($))return{};const K=Q[M],L=k[M];return oe(K,L)?{}:{[M]:L}}).reduce((M,$)=>({...M,...$}),{}):{},[k,j.properties,Q,e]),V=M=>l({collection:j,path:t,entityId:S,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}),F.current=M}).catch($=>{console.error($),P($)}).finally(()=>{E.current=!1}),re=(M,$)=>{if(w&&!S){console.error("Missing custom Id"),N(!0),$.setSubmitting(!1);return}if(P(void 0),N(!1),e==="existing"){if(!o?.id)throw Error("Form misconfiguration when saving, no id for existing entity")}else if(e==="new"||e==="copy"){if(j.customId&&j.customId!=="optional"&&!S)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,$,S),[m,t,S]),q=c.useMemo(()=>S?Qo(S,j.properties,W):void 0,[S,j.properties,W]),se=We(),U=c.useCallback(({entity:M,customEntityActions:$})=>{const K=at(j,se,Ne(t),null),L=M?Jt(j,se,Ne(t),M):!0,T=[];return K&&T.push(nl),L&&T.push(ol),$&&T.push(...$),T},[se,j,t]);return r.jsx(Ce.Formik,{initialValues:k,onSubmit:re,validationSchema:q,validate:M=>console.debug("Validating",M),onReset:()=>i&&i(),children:M=>{const $=[],K={setFieldValue:M.setFieldValue,values:M.values,collection:Be({collection:j,path:t,fields:u.propertyConfigs}),entityId:S,path:t,save:V};if(c.useEffect(()=>{A&&A(K)},[A,K]),b&&j){const L={entityId:S,path:t,status:e,collection:n,context:u,currentEntityId:S,formContext:K};$.push(...b.map((T,D)=>T.form?.Actions?r.jsx(T.form.Actions,{...L},`actions_${T.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 "+j.hideIdFromForm?"mb-2":"mb-0",variant:"h4",children:j.singularName??j.name})}),!g&&r.jsx(ra,{customId:j.customId,entityId:S,status:e,onChange:x,error:B,entity:o}),S&&r.jsx(la,{...M,initialValues:Q,onModified:s,onValuesChanged:_,underlyingChanges:z,entity:o,resolvedCollection:j,formContext:K,status:e,savingError:I,closeAfterSaveRef:E,autoSave:p,entityActions:U({entity:o,customEntityActions:j.entityActions})})]})]})}})}function la(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=X(),E=w.filter(I=>I.includeInForm===void 0||I.includeInForm),k=je(),S=m;c.useEffect(()=>{n&&n(S),o&&o(t)},[S,t]),c.useEffect(()=>{!y&&l&&s&&Object.entries(l).forEach(([I,P])=>{const F=t[I];!oe(P,F)&&!a[I]&&(console.debug("Updated value from the datasource:",I,P),d(I,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(I=>{const P=A.properties[I];if(!P)return console.warn(`Property ${I} not found in collection ${A.name}`),null;const F=!!l&&Object.keys(l).includes(I)&&!!a[I],Q=!y&&g||it(P)||!!P.disabled;if(vt(P))return null;const J={propertyKey:I,disabled:Q,property:P,includeDescription:P.description||P.longDescription,underlyingValueHasChanged:F&&!y,context:i,tableMode:!1,partOfArray:!1,partOfBlock:!1,autoFocus:!1};return r.jsx("div",{id:`form_field_${I}`,children:r.jsx(ne,{children:r.jsx(nt,{...J})})},`field_${A.name}_${I}`)}).filter(Boolean)}),B=g||!S&&p==="existing",N=c.useRef(null);return r.jsxs(Ce.Form,{onSubmit:h,noValidate:!0,children:[r.jsxs("div",{className:"mt-12",ref:N,children:[x,r.jsx(ea,{containerRef:N})]}),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(I=>r.jsx(f.IconButton,{color:"primary",onClick:P=>{P.stopPropagation(),s&&I.onClick({entity:s,fullPath:A.path,collection:A,context:C,sideEntityController:k})},children:I.icon},I.name))}),r.jsx(f.Button,{variant:"text",disabled:B,type:"reset",children:p==="existing"?"Discard":"Clear"}),r.jsxs(f.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(f.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 ia(e){return e.open?r.jsx(sa,{...e}):null}function sa({tableKey:e,entity:t,customFieldValidator:n,propertyKey:o,collection:l,path:i,cellRect:s,open:a,onClose:d,onCellValueChange:A,container:g}){const p=Pe(),h=X(),[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),S(V?.values)}}):()=>{},[p,w,l,i,a]);const[k,S]=c.useState(C?.values),x=l?Be({collection:l,path:i,values:k,entityId:w,fields:h.propertyConfigs}):void 0,B=Ms(),N=c.useRef(null),I=c.useRef(null),P=c.useRef(!1),F=c.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]),Q=c.useCallback(({x:V,y:re})=>{const W=N.current?.getBoundingClientRect();if(!W)throw Error("normalizePosition called before draggableBoundingRect is set");return{x:Math.max(0,Math.min(V,B.width-W.width)),y:Math.max(0,Math.min(re,B.height-W.height))}},[B]),Y=c.useCallback(V=>{const re=N.current?.getBoundingClientRect();if(!s||!re)return;const W=V??Q(F());(!b||W.x!==b.x||W.y!==b.y)&&y(W)},[s,F,Q,b]);Qs({containerRef:N,innerRef:I,x:b?.x,y:b?.y,onMove:Y}),c.useEffect(()=>{P.current=!1},[o,C]),c.useLayoutEffect(()=>{const V=N.current?.getBoundingClientRect();!s||!V||P.current||(Y(),P.current=!0)},[s,Y,P.current]),c.useLayoutEffect(()=>{Y(b)},[B,s]);const J=c.useMemo(()=>{if(!(!x||!w))return Qo(w,o&&x.properties[o]?{[o]:x.properties[o]}:{},n)},[x,w,o,n]),_=c.useCallback(()=>Y(b),[b,Y]),j=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:J,validateOnMount:!0,validate:V=>console.debug("Validating",V),onSubmit:(V,re)=>{j(V).then(()=>d()).finally(()=>re.setSubmitting(!1))},children:({values:V,setFieldValue:re,handleSubmit:W,isSubmitting:q})=>{if(c.useEffect(()=>{oe(V,k)||S(V)},[V]),!C)return r.jsx(pe,{error:"PopupFormField misconfiguration"});if(!x)return r.jsx(r.Fragment,{});const se=q,U={collection:x,entityId:w,values:V,path:i,setFieldValue:re,save:j},M=o&&tt(x.properties,o),$=o&&M?{propertyKey:o,disabled:q||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:I,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(T=>{T.form?.provider&&(K=r.jsx(T.form.provider.Component,{status:"existing",path:i,collection:x,entity:C,context:h,currentEntityId:w,formContext:U,...T.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:N,children:[r.jsx(Ds,{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(Tl.Root,{asChild:!0,container:g,children:z})}const aa="collectionGroupParent",An=c.memo(function({fullPath:t,parentCollectionIds:n,isSubCollection:o,className:l,...i}){const s=Pe(),a=ie(),d=je(),A=We(),g=dt(),p=X(),h=c.useRef(null),u=c.useMemo(()=>{const O=g?.getCollectionConfig(t);return O?Fe(i,O):i},[i,t,g?.getCollectionConfig]),m=at(u,A,Ne(t),null),[b,y]=c.useState(void 0),[w,C]=c.useState(void 0),[E,k]=c.useState(0),[S,x]=c.useState(0),B=c.useCallback(()=>{const O=b;setTimeout(()=>{O===b&&y(void 0)},2400)},[b]),N=c.useCallback(O=>Ir(u,A,Ne(t),O??null)?u.inlineEditing===void 0||u.inlineEditing:!1,[u,A,t]),I=u.selectionEnabled===void 0||u.selectionEnabled,P=!N(),[F,Q]=c.useState(!1),Y=fn(),J=u.selectionController??Y,{selectedEntities:_,toggleEntitySelection:j,isEntitySelected:te,setSelectedEntities:z}=J;c.useEffect(()=>{C(void 0)},[_]);const V=rn({fullPath:t,collection:u,entitiesDisplayedFirst:[],lastDeleteTimestamp:E}),re=c.useRef(Math.random().toString(36)),W=V.popupCell,q=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:B})),[t,u,d]),U=c.useCallback(()=>{p.onAnalyticsEvent?.("new_entity_click",{path:t}),d.open({path:t,collection:u,updateUrl:!0,onClose:B})},[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,Z)=>{p.onAnalyticsEvent?.("single_entity_deleted",{path:t}),z(R=>R.filter(ee=>ee.id!==Z.id)),k(Date.now())},[p,t,z]),K=c.useCallback((O,Z)=>{p.onAnalyticsEvent?.("multiple_entities_deleted",{path:t}),z([]),C(void 0),k(Date.now())},[z]);let L;p?.plugins&&(L=p.plugins.find(O=>O.collectionView?.AddColumnComponent)?.collectionView?.AddColumnComponent);const T=c.useCallback((O,Z)=>{if(g){const R=g.getCollectionConfig(O),ee=Fe(R,Z);g.onCollectionModified(O,ee)}},[g]),D=c.useCallback(({width:O,key:Z})=>{if(!tt(u.properties,Z))return;const R=il(Z,O);T(t,R)},[u,T,t]),Se=c.useCallback(O=>{g&&T(t,{defaultSize:O})},[T,t,g]),Ae=at(u,A,Ne(t),null),ae=c.useCallback(({name:O,value:Z,property:R,entityId:ee})=>s.checkUniqueField(t,O,Z,ee),[t]),Ie=({fullPath:O,context:Z,value:R,propertyKey:ee,onValueUpdated:ce,setError:De,entity:Mt})=>{const H=Ce.setIn({...Mt.values},ee,R),ge={path:O,entityId:Mt.id,values:H,previousValues:Mt.values,collection:u,status:"existing"};return Mr({...ge,collection:u,callbacks:u.callbacks,dataSource:s,context:Z,onSaveSuccess:()=>ce(),onSaveFailure:de=>{console.error("Save failure"),console.error(de),De(de)}})},qe=a.resolveAliasesFrom(t),Ye=c.useMemo(()=>Be({collection:u,path:t,fields:p.propertyConfigs}),[u,t]),Oe=c.useCallback(({propertyKey:O,propertyValue:Z,entity:R})=>{let ee=tt(u.properties,O);return ee||(ee=tt(Ye.properties,O)),ke({propertyKey:O,propertyOrBuilder:ee,path:t,propertyValue:Z,values:R.values,entityId:R.id,fields:p.propertyConfigs})},[u.properties,p.propertyConfigs,t,Ye.properties]),Ft=zo(Ye,!0),mt=c.useMemo(()=>{const O=u.subcollections?.map(R=>({key:jr(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})}))??[],Z=u.collectionGroup?[{key:aa,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(Ge,{reference:ce,size:"tiny"},ce.path+"/"+ce.id))})}}]:[];return[...u.additionalFields??[],...O,...Z]},[u,t]),Nt=c.useCallback(()=>{k(Date.now())},[]),Ze=Te(),Xe=c.useCallback(({entity:O,customEntityActions:Z})=>{const R=O?Jt(u,A,Ne(t),O):!0,ee=[na];return Ae&&ee.push(nl),R&&ee.push(ol),Z&&ee.push(...Z),ee},[A,u,Ae,t]),Pt=c.useCallback(()=>{const O=Xe({}),Z=O.filter(ce=>ce.collapsed!==!1),ee=O.filter(ce=>ce.collapsed===!1).length*(Ze?40:30);return(Ze?80+ee:70+ee)+(Z.length>0?Ze?40:30:0)},[Ze,Xe]),Ke=c.useCallback(({entity:O,size:Z,width:R,frozen:ee})=>{const ce=te(O),De=Xe({entity:O,customEntityActions:u.entityActions});return r.jsx(Xr,{entity:O,width:R,frozen:ee,isSelected:ce,selectionEnabled:I,size:Z,highlightEntity:y,unhighlightEntity:B,collection:u,fullPath:t,actions:De,hideId:u?.hideIdFromCollection,onCollectionChange:Nt,selectionController:J})},[te,u,A,t,I,j,Ae]),Tt=r.jsx(f.Popover,{open:F,onOpenChange:Q,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=>{Q(!0),O.stopPropagation()}:void 0,children:`${u.name}`}),r.jsx(ca,{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 Qt({property:O,propertyKey:Z,onHover:R}){return p.plugins?r.jsx(r.Fragment,{children:p.plugins.filter(ee=>ee.collectionView?.HeaderAction).map((ee,ce)=>{const De=ee.collectionView.HeaderAction;return r.jsx(De,{onHover:R,propertyKey:Z,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(tn,{additionalFields:mt,tableController:V,displayedColumnIds:Ft,onSizeChanged:Se,onEntityClick:se,onColumnResize:D,onValueChange:Ie,tableRowActionsBuilder:Ke,uniqueFieldValidator:ae,title:Tt,selectionController:J,highlightedEntities:b?[b]:[],defaultSize:u.defaultSize,properties:Ye.properties,getPropertyFor:Oe,actions:r.jsx(Ts,{parentCollectionIds:n??[],collection:u,tableController:V,onMultipleDeleteClick:M,onNewClick:U,path:t,relativePath:u.path,selectionController:J,selectionEnabled:I,collectionEntitiesCount:S}),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:N(),AdditionalHeaderWidget:Qt,AddColumnComponent:G,getIdColumnWidth:Pt,additionalIDHeaderWidget:r.jsx(da,{path:t,collection:u})},`collection_table_${t}`),r.jsx(ia,{open:!!W,onClose:q,cellRect:W?.cellRect,propertyKey:W?.propertyKey,collection:u,entity:W?.entity,tableKey:re.current,customFieldValidator:ae,path:qe,onCellValueChange:Ie,container:h.current},`popup_form_${W?.propertyKey}_${W?.entity?.id}`),w&&r.jsx(_o,{entityOrEntitiesToDelete:w,path:t,collection:u,callbacks:u.callbacks,open:!!w,onEntityDelete:$,onMultipleEntitiesDelete:K,onClose:()=>C(void 0)})]})},oe);function fn(){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 ca({fullPath:e,collection:t,filter:n,sortBy:o,onCountChange:l}){const i=Pe(),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 il(e,t){if(e.includes(".")){const[n,...o]=e.split(".");return{properties:{[n]:il(o.join("."),t)}}}return{properties:{[e]:{columnWidth:t}}}}function da({collection:e,path:t}){const[n,o]=c.useState(!1),[l,i]=c.useState(""),s=je();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 sl({onSingleEntitySelected:e,onMultipleEntitiesSelected:t,multiselect:n,collection:o,path:l,selectedEntityIds:i,description:s,forceFilter:a,maxSelection:d}){console.log("ReferenceSelectionInner");const A=nr(),g=je(),p=ie(),h=X(),u=p.resolveAliasesFrom(l),m=Pe(),[b,y]=c.useState([]),w=fn();c.useEffect(()=>{let F=!1;const Q=i?.map(Y=>Y?.toString()).filter(Boolean);return Q&&o?Promise.all(Q.map(Y=>m.fetchEntity({path:u,entityId:Y,collection:o}))).then(Y=>{if(!F){const J=Y.filter(_=>_!==void 0);w.setSelectedEntities(J),y(J)}}):(w.setSelectedEntities([]),y([])),()=>{F=!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=F=>{console.debug("ReferenceSelectionInner toggleEntitySelection",F);let Q;const Y=w.selectedEntities;if(h.onAnalyticsEvent?.("reference_selection_toggle",{path:u,entityId:F.id}),Y){if(Y.map(J=>J.id).indexOf(F.id)>-1)Q=Y.filter(J=>J.id!==F.id);else{if(d&&Y.length>=d)return;Q=[...Y,F]}w.setSelectedEntities(Q),t&&t(Q)}},k=F=>{console.debug("ReferenceSelectionInner onEntityClick",F),!n&&e?(h.onAnalyticsEvent?.("reference_selected_single",{path:u,entityId:F.id}),e(F),A.close(!1)):E(F)},S=()=>{h.onAnalyticsEvent?.("reference_selection_new_entity",{path:u}),g.open({path:u,collection:o,updateUrl:!0,onUpdate:({entity:F})=>{y([F,...b]),k(F)},closeOnSave:!0})},x=({entity:F,size:Q,width:Y,frozen:J})=>{const _=w.selectedEntities,j=_&&_.map(te=>te.id).indexOf(F.id)>-1;return r.jsx(Xr,{width:Y,frozen:J,entity:F,size:Q,isSelected:j,selectionEnabled:n,hideId:o?.hideIdFromCollection,fullPath:u,selectionController:w})},B=c.useCallback(F=>{F.stopPropagation(),A.close(!1)},[A]);if(!o)return r.jsx(pe,{error:"Could not find collection with id "+o});const N=c.useMemo(()=>Be({collection:o,path:u,values:{},fields:h.propertyConfigs}),[o,h.propertyConfigs,u]),I=zo(N,!1),P=rn({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(tn,{displayedColumnIds:I,onEntityClick:k,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:N.properties,forceFilter:a,inlineEditing:!1,selectionController:w,actions:r.jsx(Aa,{collection:o,path:u,onNewClick:S,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:B,color:"primary",variant:"filled",children:"Done"})]})]})}function Aa({collection:e,path:t,onClear:n,onNewClick:o}){const l=We(),i=Te(),s=o?d=>{d.preventDefault(),o()}:void 0,a=at(e,l,Ne(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 un({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 al({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=X(),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 fa({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 ua({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(fa,{entry:l},l.path))})})}const gn={};function ga(){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||(gn[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||!gn[e.key]||t.current.scrollTo({top:gn[e.key],behavior:"auto"})},[e]),{containerRef:t,scroll:n,direction:l}}const pt=new Pl.Search("url");pt.addIndex("name"),pt.addIndex("description"),pt.addIndex("group"),pt.addIndex("path");function cl({additionalChildrenStart:e,additionalChildrenEnd:t}){const n=X(),o=ie();if(!o.topLevelNavigation)throw Error("Navigation not ready in FireCMSHomePage");const{containerRef:l,scroll:i,direction:s}=ga(),{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 k=C.homePage.includeSection(w);return r.jsx(un,{group:k.title,children:k.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(ua,{hidden:!!A}),e,m,u.map((w,C)=>{const E=[],k={group:w,context:n};n.plugins&&n.plugins.forEach(x=>{x.homePage?.AdditionalCards&&E.push(...Rt(x.homePage?.AdditionalCards))});const S=p.filter(x=>x.group===w||!x.group&&w===void 0);return S.length===0&&E.length===0?null:r.jsx(un,{group:w,children:r.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:[S.map(x=>r.jsx("div",{className:"col-span-1",children:r.jsx(al,{...x,onClick:()=>{const B=x.type==="collection"?"home_navigate_to_collection":x.type==="view"?"home_navigate_to_view":"unmapped_event";n.onAnalyticsEvent?.(B,{path:x.path})}})},`nav_${x.group}_${x.name}`)),E&&E.map((x,B)=>r.jsx("div",{children:r.jsx(x,{...k})},`nav_${w}_add_${B}`))]})},`plugin_section_${w}`)}),y,b,t]})})}function ha({propertyConfig:e}){const t="h-8 w-8 p-1 rounded-full shadow text-white",n=typeof e?.property=="object"?vl(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 pa({children:e,title:t,path:n}){const o=Or();return c.useEffect(()=>{o.set({breadcrumbs:[{title:t,url:n}]})},[n,t]),r.jsx(r.Fragment,{children:e})}function dl(){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 ma({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 fl=function({title:t,endAdornment:n,startAdornment:o,drawerOpen:l,dropDownActions:i,includeDrawer:s,className:a,style:d,user:A}){const g=ie(),p=We(),{mode:h,toggleMode:u}=Dr(),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"]})]})]})})},ba=e=>e&&Array.isArray(e)&&e.length>0?e.map((t,n)=>t?{[hr(t)+n]:St()}:{}).reduce((t,n)=>({...t,...n}),{}):{};function hn({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(ba(n)),[h,u]=c.useState(g?Object.values(p.current):[]);c.useEffect(()=>{if(g&&n&&n.length!==h.length){const C=n.map((E,k)=>{const S=hr(E)+k;if(S in p.current)return p.current[S];{const x=St();return p.current[S]=x,x}});u(C)}},[g,h.length,n]);const m=C=>{if(C.preventDefault(),o)return;const E=St(),k=[...h,E];s&&s(E),u(k),A([...n??[],d])},b=C=>{const E=[...h];E.splice(C,1),u(E),A(n.filter((k,S)=>S!==C))},y=C=>{const E=St(),k=n[C],S=[...h.splice(0,C+1),E,...h.splice(C+1,h.length-C-1)];s&&s(E),u(S),A([...n.slice(0,C+1),k,...n.slice(C+1)])},w=C=>{if(!C.destination)return;const E=C.source.index,k=C.destination.index,S=[...h],x=S[E];S[E]=S[k],S[k]=x,u(S),A(ya(n,E,k))};return r.jsx(lt.DragDropContext,{onDragEnd:w,children:r.jsx(lt.Droppable,{droppableId:e,renderClone:(C,E,k)=>{const S=k.source.index,x=h[S];return r.jsx(pn,{provided:C,internalId:x,index:S,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((k,S)=>r.jsx(lt.Draggable,{draggableId:`array_field_${k}`,isDragDisabled:o,index:S,children:(x,B)=>r.jsx(pn,{provided:x,internalId:k,index:S,size:i,disabled:o,buildEntry:l,remove:b,copy:y,isDragging:B.isDragging})},`array_field_${k}`)),C.placeholder,a&&r.jsx("div",{className:"py-4 justify-center text-left",children:r.jsx(f.Button,{variant:i==="small"?"text":"outlined",size:i==="small"?"small":"medium",color:"primary",disabled:o,startIcon:r.jsx(f.AddIcon,{}),onClick:m,children:t??"Add"})})]})})})}function pn({provided:e,index:t,internalId:n,size:o,disabled:l,buildEntry:i,remove:s,copy:a,isDragging:d}){const[A,g]=dr(),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(ul,{direction:o==="small"?"row":"column",disabled:l,remove:s,index:t,provided:e,measuring:p,contentOverflow:h,copy:a})]})})}function ul({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 ya(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 It(e){const t=ie(),n=Et(),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(sl,{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 va=`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 wa(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??va}},[e,t])}const rr="main_##Q$SC^#S6";function Ca({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:q?.id,collection:l,path:e,values:h,closeAfterSave:!1})},!1,2e3);const m=Pe(),b=nr(),y=je(),w=He(),C=X(),E=We(),[k,S]=c.useState(void 0),[x,B]=c.useState(o?"copy":t?"existing":"new"),N=c.useRef(void 0),I=N.current,P=(l.subcollections??[]).filter(G=>!G.hideFromNavigation),F=P?.length??0,Q=l.entityViews,Y=Q?.length??0,J=l.formAutoSave&&!l.customId,_=Y>0||F>0,j=n??kr(l?l.defaultSelectedView:void 0,{status:x,entityId:t}),te=c.useRef(j??rr),z=te.current===rr,{entity:V,dataLoading:re,dataLoadingError:W}=Qr({path:e,entityId:t,collection:l,useCache:!1}),[q,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=q?Ir(l,E,Ne(e),q??null):!1;q&&M(!G)}},[E,q,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),J||w.open({type:"success",message:`${l.singularName??l.name}: Saved correctly`}),se(G),B("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})},T=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:Z,entityId:R,collection:ee,path:ce})=>{p(!0),Mr({path:ce,entityId:R,values:G,previousValues:O,collection:ee,status:x,dataSource:m,context:C,onSaveSuccess:De=>L(De,Z),onSaveFailure:T,onPreSaveHookError:$,onSaveSuccessHookError:K}).then()},Se=async({collection:G,path:O,entityId:Z,values:R,previousValues:ee,closeAfterSave:ce,autoSave:De})=>{x&&(De?u(R):D({collection:G,path:O,entityId:Z,values:R,previousValues:ee,closeAfterSave:ce}))},Ae=Q?Q.map(G=>Cr(G,C.entityViews)).filter(Boolean):[],ae=Q&&Ae.map((G,O)=>{if(!G||te.current!==G.key)return null;const Z=G.Builder;return Z?r.jsx("div",{className:f.cn(f.defaultBorderMixin,"relative flex-grow w-full h-full overflow-auto "),role:"tabpanel",children:r.jsx(ne,{children:k&&r.jsx(Z,{collection:l,entity:q,modifiedValues:I??q?.values,formContext:k})})},`custom_view_${G.key}`):(console.error("customView.Builder is not defined"),null)}).filter(Boolean),Ie=re&&!q||(!q||U===void 0)&&(x==="existing"||x==="copy"),qe=Ie||g,Ye=P&&P.map((G,O)=>{const Z=G.id??G.path,R=q?`${e}/${q?.id}/${ue(Z)}`:void 0;return te.current!==Z?null:r.jsxs("div",{className:"relative flex-grow h-full overflow-auto w-full",role:"tabpanel",children:[qe&&r.jsx(xt,{}),!Ie&&(q&&R?r.jsx(An,{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_${Z}`)}).filter(Boolean),Oe=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})},mt=c.useCallback(G=>{N.current=G},[]),Nt=c.useCallback(G=>{w.open({type:"error",message:"Error updating id, check the console"})},[]),Ze=c.useCallback(G=>{se(O=>O?{...O,id:G}:void 0)},[]),Xe=G=>{J||s(G)};function Pt(){const G=C.plugins;let O=r.jsx(ll,{status:x,path:e,collection:l,onEntitySaveRequested:Se,onDiscard:Oe,onValuesChanged:mt,onModified:Xe,entity:q,onIdChange:Ze,onFormContextChange:S,hideId:l.hideIdFromForm,autoSave:J,onIdUpdateError:Nt});return G&&G.forEach(Z=>{Z.form?.provider&&(O=r.jsx(Z.form.provider.Component,{status:x,path:e,collection:l,onDiscard:Oe,onValuesChanged:mt,onModified:Xe,entity:q,context:C,formContext:k,...Z.form.provider.props,children:O}))}),r.jsx(ne,{children:O})}const Ke=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(Wr,{className:"px-12",entity:q,path:e,collection:l})]}):Pt(),Tt=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}`)),Qt=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"}),Ie&&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}),Qt,Tt]})]}),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:Ie?r.jsx(xt,{}):Ke}),ae,Ye]})]})})}function Ea(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 Ba({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 gl=c.createContext({width:"",blocked:!1,setBlocked:e=>{},setBlockedNavigationMessage:e=>{},close:()=>{}}),nr=()=>c.useContext(gl);function ka(){const t=Et().sidePanels,n=[...t];return n.push(void 0),r.jsx(r.Fragment,{children:n.map((o,l)=>r.jsx(xa,{panel:o,offsetPosition:t.length-l-1},`side_dialog_${l}`))})}function xa({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=Et(),{navigationWasBlocked:p,handleOk:h,handleCancel:u}=Ea(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(gl.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(Ba,{open:p||n,handleOk:n?m:h,handleCancel:n?b:u,body:s})]})}function Sa(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(Ca,{...e,formWidth:e.width,collection:s,parentCollectionIds:i,onValuesAreModified:a})})})}const hl="new";function Ia(e,t){if(t)return gi;const n=!e.selectedSubPath,o=typeof e.width=="number"?`${e.width}px`:e.width;return n?o??Xn:`calc(${hi} + ${o??Xn})`}const Fa=(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===`#${hl}`,A=e.urlPathToDataPath(n.pathname),g=Na(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=kr(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 Na(e,t,n){const o=Er({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}#${hl}`);return{key:`${e.path}/${e.entityId}`,component:r.jsx(Sa,{...e}),urlPath:l,parentUrlPath:t.buildUrlCollectionPath(o),width:Ia(e,n),onClose:e.onClose}};function Pa(){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 Ta(e){c.useEffect(()=>{if(!e)return;const t=kn[e];t&&(Bn.registerLocale(e,t),Bn.setDefaultLocale(e))},[e])}function pl(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 Me(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(...pl({path:y,collections:A.subcollections,currentFullPath:b}))}}break}}return s}const Qa="/",Ma="/c";function Da({basePath:e=Qa,baseCollectionPath:t=Ma,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,k]=c.useState(void 0),S=ue(e),x=ue(t),B=S?`/${S}`:"/",N=S?`/${S}/${x}`:`/${x}`,I=c.useCallback(U=>S?`/${S}/${lr(U)}`:`/${lr(U)}`,[S]),P=c.useCallback(U=>`${ue(t)}/${lr(U)}`,[t]),F=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:I(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,T,D)=>D.indexOf(L)===T);return{navigationEntries:$,groups:K}},[I,P]),Q=c.useCallback(async()=>{if(!n.initialLoading){try{const[U=[],M=[]]=await Promise.all([Oa(o,n,a,s),Va(l,n,a)]);g(U),h(M),y(F(U??[],M))}catch(U){console.error(U),k(U)}C(!1),m(!0)}},[o,n.user,n.initialLoading,s,l,F]);c.useEffect(()=>{Q()},[Q]);const Y=c.useCallback((U,M,$=!1)=>{if(!A)return;const K=Ot(ue(U),A),L=$?i?.getCollectionConfig(U):void 0,T=K?Fe(K,L):void 0;let D=T;if(T){const Se=T.subcollections,Ae=T.callbacks,ae=T.permissions;D={...D,subcollections:D?.subcollections??Se,callbacks:D?.callbacks??Ae,permissions:D?.permissions??ae}}if(D)return{...T,...D}},[e,t,A]),J=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(T=>T.id===K||T.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(T=>T.id===K);if(!L)return;if(M=L.subcollections,$===U.length-1)return L}},[A]),j=c.useCallback(U=>ue(U+"/").startsWith(ue(N)+"/"),[N]),te=c.useCallback(U=>{if(U.startsWith(N))return U.replace(N,"");throw Error("Expected path starting with "+N)},[N]),z=c.useCallback(({path:U})=>`s/edit/${lr(U)}`,[]),V=c.useCallback(U=>{if(!A)throw Error("Collections have not been initialised yet");return ur(U,A)},[A]),re=d.state,W=re&&re.base_location?re.base_location:d,q=c.useCallback(U=>pl({path:U,collections:A}),[A]),se=c.useCallback(U=>q(U).map(M=>M.id),[q]);return c.useMemo(()=>({collections:A??[],views:p??[],loading:!u||w,navigationLoadingError:E,homeUrl:B,basePath:e,baseCollectionPath:t,initialised:u,getCollection:Y,getCollectionFromPaths:J,getCollectionFromIds:_,isUrlCollectionPath:j,urlPathToDataPath:te,buildUrlCollectionPath:P,buildUrlEditCollectionPath:z,buildCMSUrlPath:I,resolveAliasesFrom:V,topLevelNavigation:b,baseLocation:W,refreshNavigation:Q,getParentReferencesFromPath:q,getParentCollectionIds:se}),[t,W,e,I,P,z,A,q,Y,J,B,u,j,w,E,Q,V,b,te,p])}function lr(e){return encodeURIComponent(ue(e)).replaceAll("%2F","/").replaceAll("%23","#")}function ml(e,t){return e.filter(n=>n.permissions?Ct(n,t,[n.path],null).read!==!1:!0).map(n=>n.subcollections?{...n,subcollections:ml(n.subcollections,t)}:n)}async function Oa(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=ml(l,t),o&&o.forEach(i=>{i.collections?.injectCollections&&(l=i.collections?.injectCollections(l??[]))}),l}async function Va(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 Ga({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?Be({collection:d,path:o,entityId:l,fields:t}):void 0)?.properties,p=mn(i,e.buildReference,e.buildGeoPoint,e.buildDate,e.buildDeleteFieldValue),h=g?Pn({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 mn(e,t,n,o,l){return e===void 0?l():Array.isArray(e)?e.map(i=>mn(i,t,n,o,l)):e instanceof Me?t(e):e instanceof Gt?n(e):e instanceof Date?o(e):e&&typeof e=="object"?Object.entries(e).map(([i,s])=>({[i]:mn(s,t,n,o,l)})).reduce((i,s)=>({...i,...s}),{}):e}function Ya(e){const t=Dr(),{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;Ta(s);const E=Da({basePath:y,baseCollectionPath:b,authController:a,collections:w,views:C,userConfigPersistence:l,dataSource:A,plugins:g}),k=Ga({delegate:A,propertyConfigs:h,navigationController:E}),S=Pa(),x=Fa(E,S),B=g?.some(P=>P.loading)??!1,N=a.initialLoading||E.loading||B,I=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(Pr.Provider,{value:I,children:r.jsx(no.Provider,{value:l,children:r.jsx(ro.Provider,{value:d,children:r.jsx(Kn.Provider,{value:k,children:r.jsx(fr.Provider,{value:a,children:r.jsx(eo.Provider,{value:S,children:r.jsx(to.Provider,{value:x,children:r.jsx(Rn.Provider,{value:E,children:r.jsx(Ml,{children:r.jsx(pi,{children:r.jsx(za,{loading:N,children:n})})})})})})})})})})})})}function za({loading:e,children:t}){const n=X();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 bl({hovered:e,drawerOpen:t,closeDrawer:n}){const o=X(),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(bn,{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(bn,{icon:qt(h.collection??h.view),tooltipsOpen:i,onClick:()=>p(h),drawerOpen:t,url:h.url,name:h.name},`navigation_${u}`))]})}function bn({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 Ua=280,La=c.memo(function(t){const{children:n,name:o,logo:l,includeDrawer:i=!0,autoOpenDrawer:s,Drawer:a=bl,drawerProps:d,FireCMSAppBarComponent:A=fl,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)},[]),k=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:k,...g}),r.jsx(_a,{displayed:i,onMouseEnter:w,onMouseMove:w,onMouseLeave:C,open:k,logo:l,hovered:b,setDrawerOpen:m,children:i&&(h.loading?r.jsx(xt,{}):r.jsx(a,{hovered:b,drawerOpen:k,closeDrawer:E,...d}))}),r.jsxs("main",{className:"flex flex-col flex-grow overflow-auto",children:[r.jsx($a,{}),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),$a=()=>r.jsx("div",{className:"flex flex-col min-h-[68px]"});function _a(e){const t=ie(),n=e.displayed?e.open?Ua: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 yl(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:el}},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:nn}},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:on}},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:nn}},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:on}},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:ln}},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:ln}},reference:{key:"reference",name:"Reference",description:"The value refers to a different collection",Icon:f.LinkIcon,color:"#ff0042",property:{dataType:"reference",Field:qo}},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:Wo}},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:Ho}},date_time:{key:"date_time",name:"Date/time",description:"A date time select field",Icon:f.ScheduleIcon,color:"#8b46ff",property:{dataType:"date",Field:Jo}},group:{key:"group",name:"Group",description:"Group of multiple fields",Icon:f.BallotIcon,color:"#ff9408",property:{dataType:"map",properties:{},Field:Zo}},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:Xo}},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:Ko}},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:tl}},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:Ro}}};function vl(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=yn(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 Fe(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 yn(e){return e.propertyConfig?e.propertyConfig:ar(e)}const Wa=c.memo(function({HomePage:t=cl,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=>wl(u,h))):a.push(wl(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(cr,{path:u,title:h.name,type:"collection",children:r.jsx(An,{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(cr,{path:l.homeUrl,title:"Home",type:"home",children:r.jsx(t,{})},"navigation_home")}),p=r.jsx(fe.Route,{path:"*",element:r.jsx(dl,{})});return r.jsxs(fe.Routes,{location:s,children:[A,a,g,p,n]})}),wl=(e,t)=>r.jsx(fe.Route,{path:e,element:r.jsx(cr,{path:e,title:t.name,type:"view",children:t.view},`navigation_${e}`)},"navigation_view_"+e),cr=c.memo(function({children:t,title:n,path:o,type:l}){const i=Or();return c.useEffect(()=>{i.set({breadcrumbs:[{title:n,url:o}]})},[o,n]),r.jsx(r.Fragment,{children:t})},oe);function ja(){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 Ha(){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::${xr(m)}`;return e[b]?e[b]:n(b)},[e,n]),l=c.useCallback((m,b)=>{const y=`collection_config::${xr(m)}`;localStorage.setItem(y,JSON.stringify(b)),t(w=>{const C=w[y],E=Fe(C??n(m),b);return Fe(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=hn,v.ArrayContainerItem=pn,v.ArrayCustomShapedFieldBinding=tl,v.ArrayEnumPreview=Lr,v.ArrayItemOptions=ul,v.ArrayOfMapsPreview=Oi,v.ArrayOfReferencesFieldBinding=Wo,v.ArrayOfReferencesPreview=po,v.ArrayOfStorageComponentsPreview=mo,v.ArrayOfStringsPreview=bo,v.ArrayOneOfPreview=yo,v.ArrayPropertyEnumPreview=$r,v.ArrayPropertyPreview=Ur,v.AsyncPreviewComponent=Vi,v.AuthControllerContext=fr,v.BlockFieldBinding=Ro,v.BooleanPreview=Co,v.BreadcrumbUpdater=pa,v.COLLECTION_PATH_SEPARATOR=Vn,v.CircularProgressCenter=xt,v.DEFAULT_FIELD_CONFIGS=ir,v.DatePreview=wo,v.DateTimeFieldBinding=Jo,v.DefaultHomePage=cl,v.DeleteConfirmationDialog=ma,v.Drawer=bl,v.DrawerNavigationItem=bn,v.EmptyValue=At,v.EntityCollectionTable=tn,v.EntityCollectionView=An,v.EntityForm=ll,v.EntityPreview=Wr,v.EntityReference=Me,v.EnumValuesChip=we,v.ErrorBoundary=ne,v.ErrorView=pe,v.FieldConfigBadge=ha,v.FieldHelperText=ye,v.FireCMS=Ya,v.FireCMSAppBar=fl,v.FireCMSContextInstance=Pr,v.FireCMSLogo=Al,v.FormikArrayContainer=er,v.GeoPoint=Gt,v.ImagePreview=Ao,v.KeyValueFieldBinding=Xo,v.KeyValuePreview=_r,v.LabelWithIcon=be,v.MapFieldBinding=Zo,v.MapPropertyPreview=vo,v.MarkdownFieldBinding=el,v.ModeControllerContext=Dt,v.ModeControllerProvider=Vl,v.MultiSelectBinding=on,v.NavigationCollectionCard=al,v.NavigationGroup=un,v.NavigationRoutes=Wa,v.NotFoundPage=dl,v.NumberPropertyPreview=Eo,v.PropertyFieldBinding=nt,v.PropertyPreview=me,v.ReadOnlyFieldBinding=sn,v.ReferenceFieldBinding=qo,v.ReferencePreview=Ge,v.ReferencePreviewContainer=Xt,v.ReferenceSelectionInner=sl,v.RepeatFieldBinding=Ko,v.RouteWrapper=cr,v.Scaffold=La,v.SelectFieldBinding=nn,v.SideDialogs=ka,v.SkeletonPropertyComponent=ut,v.SnackbarProvider=Dl,v.StorageThumbnail=fo,v.StorageThumbnailInternal=go,v.StorageUploadFieldBinding=ln,v.StringPropertyPreview=zr,v.SwitchControl=Os,v.SwitchFieldBinding=Ho,v.TextFieldBinding=ht,v.UrlComponentPreview=Bt,v.VirtualTable=Mo,v.addInitialSlash=Yl,v.buildAdditionalFieldDelegate=fi,v.buildCollection=li,v.buildEntityCallbacks=Ai,v.buildEnumLabel=Dn,v.buildEnumValueConfig=di,v.buildEnumValues=ci,v.buildFieldConfig=ui,v.buildProperties=si,v.buildPropertiesOrBuilder=ai,v.buildProperty=ii,v.canCreateEntity=at,v.canDeleteEntity=Jt,v.canEditEntity=Ir,v.defaultDateFormat=On,v.deleteEntityWithCallbacks=io,v.enumToObjectEntries=$e,v.flattenObject=Fr,v.fullPathToCollectionSegments=Ne,v.getArrayValuesCount=_n,v.getBracketNotation=ti,v.getCollectionByPathOrAlias=Ot,v.getCollectionPathsCombinations=Vt,v.getColorForProperty=ei,v.getColorScheme=Mn,v.getDefaultFieldConfig=vl,v.getDefaultFieldId=ar,v.getDefaultPropertiesOrder=ri,v.getDefaultValueFor=Ut,v.getDefaultValueForDataType=br,v.getDefaultValuesFor=wt,v.getFieldConfig=sr,v.getFieldId=yn,v.getHashValue=hr,v.getIcon=Ln,v.getIconForProperty=he,v.getIconForView=qt,v.getIconForWidget=jt,v.getIdIcon=Rl,v.getLabelOrConfigFrom=$t,v.getLastSegment=zl,v.getPropertiesWithPropertiesOrder=Un,v.getPropertyInPath=tt,v.getRandomId=St,v.getReferenceFrom=et,v.getReferencePreviewKeys=$n,v.getResolvedPropertyInPath=Sr,v.getValueInPath=Le,v.hydrateRegExp=Yn,v.isDefaultFieldConfigId=yl,v.isEmptyObject=mr,v.isEnumValueDisabled=$l,v.isHidden=vt,v.isObject=Yt,v.isPropertyBuilder=ve,v.isReadOnly=it,v.isReferenceProperty=zn,v.isValidRegExp=Xl,v.joinCollectionLists=Hn,v.makePropertiesEditable=Wn,v.makePropertiesNonEditable=jn,v.mergeCollection=Jn,v.mergeDeep=Fe,v.pick=Fn,v.plural=ni,v.randomColor=ql,v.randomString=st,v.removeFunctions=gr,v.removeInPath=Ul,v.removeInitialAndTrailingSlashes=ue,v.removeInitialSlash=Sn,v.removePropsIfExisting=Nn,v.removeTrailingSlash=In,v.removeUndefined=pr,v.renderSkeletonCaptionText=Ni,v.renderSkeletonIcon=Yr,v.renderSkeletonImageThumbnail=Gr,v.renderSkeletonText=Ve,v.resolveArrayProperty=_e,v.resolveCollection=Be,v.resolveCollectionPathAliases=ur,v.resolveDefaultSelectedView=kr,v.resolveEntityView=Cr,v.resolveEnumValues=_l,v.resolveNavigationFrom=so,v.resolvePermissions=Ct,v.resolveProperties=vr,v.resolveProperty=ke,v.resolvePropertyEnum=wr,v.sanitizeData=Ll,v.saveEntityWithCallbacks=Mr,v.segmentsToStrippedPath=Gn,v.serializeRegExp=Zl,v.singular=oi,v.slugify=_t,v.sortProperties=Br,v.stripCollectionPath=xr,v.toKebabCase=jl,v.toSnakeCase=Jl,v.traverseValueProperty=Lt,v.traverseValuesProperties=yr,v.unslugify=Gl,v.updateDateAutoValues=Pn,v.useAuthController=We,v.useBreadcrumbsContext=Or,v.useBrowserTitleAndIcon=wa,v.useBuildLocalConfigurationPersistence=Ha,v.useBuildModeController=ja,v.useClearRestoreValue=xe,v.useClipboard=ao,v.useCollectionFetch=lo,v.useDataSource=Pe,v.useDebounce=Wt,v.useDebounceValue=Kl,v.useEntityCollectionTableController=rn,v.useEntityFetch=Qr,v.useFireCMSContext=X,v.useLargeLayout=Te,v.useModeController=Dr,v.useNavigationController=ie,v.useReferenceDialog=It,v.useResolvedNavigationFrom=bi,v.useSelectionController=fn,v.useSideDialogContext=nr,v.useSideDialogsController=Et,v.useSideEntityController=je,v.useSnackbarController=He,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"})});
|
|
589
589
|
//# sourceMappingURL=index.umd.js.map
|