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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.umd.js CHANGED
@@ -585,5 +585,5 @@
585
585
  .rc-md-editor .header-list .list-item:hover {
586
586
  }
587
587
 
588
- `;function Da({propertyKey:e,value:t,error:o,showError:n,isSubmitting:i,setValue:a,tableMode:s,property:l,includeDescription:c,underlyingValueHasChanged:u,context:f,disabled:g}){if(!Array.isArray(l.resolvedProperties))throw Error("ArrayCustomShapedFieldBinding misconfiguration. Property `of` not set");const m=l.expanded===void 0?!0:l.expanded;Te({property:l,value:t,setValue:a});const h=r.jsx(Ee,{icon:Ce(l,"small"),required:l.validation?.required,className:"text-text-secondary dark:text-text-secondary-dark",title:l.name}),A=l.resolvedProperties.map((y,b)=>{const k={propertyKey:`${e}[${b}]`,disabled:g,property:y,includeDescription:c,underlyingValueHasChanged:u,context:f,tableMode:!1,partOfArray:!0,partOfBlock:!1,autoFocus:!1};return r.jsx("div",{className:"pb-4",children:r.jsx(ot,{...k})},`custom_shaped_array_${b}`)});return r.jsxs(r.Fragment,{children:[!s&&r.jsx(p.ExpandablePanel,{initiallyExpanded:m,title:h,className:"px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2",children:A}),s&&A,r.jsx(xe,{includeDescription:c,showError:n,error:o,disabled:g,property:l})]})}const Rl=({containerRef:e})=>{const{isSubmitting:t,isValidating:o,errors:n}=ke.useFormex();return d.useEffect(()=>{const i=Object.keys(n);if(i.length>0&&t&&!o){const a=e?.current?.querySelector(`#form_field_${i[0]}`);if(a&&e?.current){const s=Qa(e.current);if(s){const c=a.getBoundingClientRect().top;s.scrollTo({top:s.scrollTop+c-196,behavior:"smooth"})}const l=a.querySelector("input");l&&l.focus()}}},[t,o,n,e]),null},ec=e=>{const t=e&&e.scrollHeight>e.clientHeight,o=e?window.getComputedStyle(e).overflowY:null,n=o&&o.indexOf("hidden")!==-1;return t&&!n},Qa=e=>!e||e===document.body?document.body:ec(e)?e:Qa(e.parentNode);function tc({customId:e,entityId:t,status:o,onChange:n,error:i,entity:a,loading:s}){const{errors:l}=ke.useFormex(),c=o==="existing"||!e,u=o!=="existing"&&!e,f=d.useMemo(()=>{if(!(!e||typeof e=="boolean"||e==="optional"))return We(e)},[e]),g=Je(),{copy:m}=_n({onSuccess:y=>g.open({type:"success",message:`Copied ${y}`})}),h=ne(),A={label:u?"ID is set automatically":"ID",disabled:c||s,name:"id",value:(a&&o==="existing"?a.id:t)??"",endAdornment:s?r.jsx(p.CircularProgress,{size:"small"}):a?r.jsxs(r.Fragment,{children:[r.jsx(p.Tooltip,{title:"Copy",children:r.jsx(p.IconButton,{onClick:y=>m(a.id),"aria-label":"copy-id",children:r.jsx(p.ContentCopyIcon,{size:"small"})})}),h?.entityLinkBuilder&&r.jsx(p.Tooltip,{title:"Open in the console",children:r.jsx(p.IconButton,{component:"a",href:h.entityLinkBuilder({entity:a}),rel:"noopener noreferrer",target:"_blank",onClick:y=>y.stopPropagation(),"aria-label":"go-to-datasource",children:r.jsx(p.OpenInNewIcon,{size:"small"})})})]}):void 0};return r.jsxs(r.Fragment,{children:[f&&r.jsx(p.Select,{error:i,onValueChange:y=>n(y),...A,renderValue:y=>{const b=f.find(k=>k.id===y);return b?`${b.id} - ${b.label}`:y},children:f.map(y=>r.jsx(p.SelectItem,{value:String(y.id),children:r.jsx(Ie,{enumKey:y.id,enumValues:f,size:"medium"})},y.id))}),!f&&r.jsx(p.TextField,{...A,error:i,placeholder:e==="optional"?"Autogenerated ID, it can be manually changed":o==="new"||o==="copy"?"ID of the new document":"ID of the document",onChange:y=>{let b=y.target.value;return b&&(b=b.trim()),n(b.length?b:void 0)}}),l.id&&r.jsx(p.Typography,{variant:"caption",className:"ml-3.5 text-red-500 dark:text-red-500",children:l.id})]})}function rc({propertyId:e}){const[t,o]=d.useState(!1);return r.jsxs("div",{className:"flex flex-row gap-2 items-center justify-center text-white",children:[r.jsxs("div",{children:[r.jsx(p.Typography,{variant:"caption",className:"min-w-20 text-slate-400",color:"disabled",children:t?"Copied":"Property ID"}),r.jsx(p.Typography,{variant:"caption",className:"text-white",children:r.jsx("code",{children:e})})]}),r.jsx(p.IconButton,{size:"small",children:r.jsx(p.ContentCopyIcon,{size:"smallest",className:"text-white",onClick:d.useCallback(()=>{navigator.clipboard.writeText(e),o(!0),setTimeout(()=>o(!1),2e3)},[e])})})]})}const Ma=d.memo(oc,(e,t)=>e.status===t.status&&e.path===t.path&&L(e.entity?.values,t.entity?.values));function Oa(e,t,o){const n=e.properties;if((t==="existing"||t==="copy")&&o)return o.values??vt(n);if(t==="new")return vt(n);throw console.error({status:t,entity:o}),new Error("Form has not been initialised with the correct parameters")}function oc({status:e,path:t,collection:o,entity:n,onEntitySaveRequested:i,onDiscard:a,onModified:s,onValuesChanged:l,onIdChange:c,onFormContextChange:u,hideId:f,autoSave:g,onIdUpdateError:m}){const h=ut(),A=ne(),y=Ae(),b=Qe(o),k=A.plugins,v=d.useMemo(()=>Ne({collection:o,path:t,values:n?.values,fields:A.propertyConfigs}),[n?.values,t,A.propertyConfigs]),_=(e==="new"||e==="copy")&&!!v.customId&&v.customId!=="optional",E=d.useMemo(()=>e==="new"||e==="copy"?_?void 0:b.generateEntityId(t):n?.id,[]),C=d.useRef(!1),B=d.useRef(Oa(v,e,n)),[x,S]=d.useState(E),[N,I]=d.useState(!1),[P,D]=d.useState(),[G,R]=d.useState(!1),[K,W]=d.useState(n?.values??B.current),j=te=>i({collection:re,path:t,entityId:x,values:te,previousValues:n?.values,closeAfterSave:C.current,autoSave:g??!1}).then(O=>{const ie=e==="new"?"new_entity_saved":e==="copy"?"entity_copied":e==="existing"?"entity_edited":"unmapped_event";h.onAnalyticsEvent?.(ie,{path:t})}).catch(O=>{console.error(O),D(O)}).finally(()=>{C.current=!1}),M=(te,O)=>{if(_&&!x){console.error("Missing custom Id"),I(!0),O.setSubmitting(!1);return}if(D(void 0),I(!1),e==="existing"){if(!n?.id)throw Error("Form misconfiguration when saving, no id for existing entity")}else if(e==="new"||e==="copy"){if(o.customId&&o.customId!=="optional"&&!x)throw Error("Form misconfiguration when saving, entityId should be set")}else throw Error("New FormType added, check EntityForm");return j(te)?.then(ie=>{O.resetForm({values:te,submitCount:0,touched:{}})}).finally(()=>{O.setSubmitting(!1)})},H=ke.useCreateFormex({initialValues:B.current,onSubmit:M,validation:te=>V?.validate(te,{abortEarly:!1}).then(()=>({})).catch(O=>{const ie={};return O.inner.forEach(me=>{ie[me.path]=me.message}),ac(O)})});d.useEffect(()=>{B.current=Oa(v,e,n);const te=H.initialValues;!H.isSubmitting&&te&&e==="existing"?Z(Object.entries(re.properties).map(([O,ie])=>{if(wt(ie))return{};const me=te[O],ue=B.current[O];return L(me,ue)?{}:{[O]:ue}}).reduce((O,ie)=>({...O,...ie}),{})):Z({})},[n,v,e]);const J=te=>{const O=H.initialValues;W(te),l&&l(te),g&&te&&!L(te,O)&&j(te)};d.useEffect(()=>{x&&c&&c(x)},[x,c]);const re=Ne({collection:o,path:t,entityId:x,values:K,previousValues:H.initialValues,fields:A.propertyConfigs}),oe=Nr(re,A.propertyConfigs),U=K&&oe?Ye(K,oe):void 0,X=o.callbacks?.onIdUpdate,Q=d.useCallback(async()=>{if(X&&K&&(e==="new"||e==="copy")){R(!0);try{const te=await X({collection:re,path:t,entityId:x,values:K,context:y});S(te)}catch(te){m&&m(te),console.error(te)}R(!1)}},[x,K,e]);d.useEffect(()=>{Q()},[Q]);const[ee,Z]=d.useState({}),$=d.useCallback(({name:te,value:O,property:ie})=>b.checkUniqueField(t,te,O,x),[b,t,x]),V=d.useMemo(()=>x?Kn(x,re.properties,$):void 0,[x,re.properties,$]),z=qe(),F=d.useCallback(({entity:te,customEntityActions:O})=>{const ie=ct(o,z,t,null),me=te?$t(o,z,t,te):!0,ue=[];return ie&&ue.push(io),me&&ue.push(so),O&&ue.push(...O),ue},[z,o,t]),T=[],le={setFieldValue:d.useCallback(H.setFieldValue,[]),values:H.values,collection:re,entityId:x,path:t,save:j},ve=d.useRef(null);if(d.useEffect(()=>{u&&!ic(ve.current??void 0,le)&&(u(le),ve.current=le)},[le,u]),k&&o){const te={entityId:x,path:t,status:e,collection:o,context:y,currentEntityId:x,formContext:le};T.push(...k.map((O,ie)=>O.form?.Actions?r.jsx(O.form.Actions,{...te},`actions_${O.key}`):null).filter(Boolean))}return r.jsx(ke.Formex,{value:H,children:r.jsxs("div",{className:"h-full overflow-auto",children:[T.length>0&&r.jsx("div",{className:p.cls("w-full flex justify-end items-center sticky top-0 right-0 left-0 z-10 bg-opacity-60 bg-slate-200 dark:bg-opacity-60 dark:bg-slate-800 backdrop-blur-md"),children:T}),r.jsxs("div",{className:"pt-12 pb-16 pl-8 pr-8 md:pl-10 md:pr-10",children:[r.jsxs("div",{className:`w-full py-2 flex flex-col items-start mt-${4+(T?8:0)} lg:mt-${8+(T?8:0)} mb-8`,children:[r.jsx(p.Typography,{className:"mt-4 flex-grow line-clamp-1 "+o.hideIdFromForm?"mb-2":"mb-0",variant:"h4",children:U??o.singularName??o.name}),r.jsx(p.Alert,{color:"base",className:"w-full",size:"small",children:r.jsxs("code",{className:"text-xs select-all",children:[t,"/",x]})})]}),!f&&r.jsx(tc,{customId:o.customId,entityId:x,status:e,onChange:S,error:N,loading:G,entity:n}),x&&r.jsx(nc,{...H,initialValues:H.initialValues,onModified:s,onDiscard:a,onValuesChanged:J,underlyingChanges:ee,entity:n,resolvedCollection:re,formContext:le,status:e,savingError:P,closeAfterSaveRef:C,autoSave:g,entityActions:F({entity:n,customEntityActions:o.entityActions})})]})]})})}function nc(e){const{values:t,onDiscard:o,onModified:n,onValuesChanged:i,underlyingChanges:a,formContext:s,entity:l,touched:c,setFieldValue:u,resolvedCollection:f,isSubmitting:g,status:m,handleSubmit:h,resetForm:A,savingError:y,dirty:b,closeAfterSaveRef:k,autoSave:v,entityActions:_}=e,E=Ae(),C=_.filter(P=>P.includeInForm===void 0||P.includeInForm),B=He(),x=b;d.useEffect(()=>{n&&n(x),i&&i(t)},[x,t]),d.useEffect(()=>{!v&&!g&&a&&l&&Object.entries(a).forEach(([P,D])=>{const G=t[P];!L(D,G)&&!c[P]&&(console.debug("Updated value from the datasource:",P,D),u(P,D!==void 0?D:null))})},[g,v,a,l,t,c,u]);const S=r.jsx("div",{className:"flex flex-col gap-8",children:(f.propertiesOrder??Object.keys(f.properties)).map(P=>{const D=f.properties[P];if(!D)return console.warn(`Property ${P} not found in collection ${f.name}`),null;const G=!!a&&Object.keys(a).includes(P)&&!!c[P],R=!v&&g||st(D)||!!D.disabled;if(wt(D))return null;const W={propertyKey:P,disabled:R,property:D,includeDescription:D.description||D.longDescription,underlyingValueHasChanged:G&&!v,context:s,tableMode:!1,partOfArray:!1,partOfBlock:!1,autoFocus:!1};return r.jsx("div",{id:`form_field_${P}`,children:r.jsx(ae,{children:r.jsx(p.Tooltip,{title:r.jsx(rc,{propertyId:P}),delayDuration:800,side:"left",align:"start",sideOffset:16,children:r.jsx(ot,{...W})})})},`field_${f.name}_${P}`)}).filter(Boolean)}),N=g||!x&&m==="existing",I=d.useRef(null);return r.jsxs("form",{onSubmit:h,onReset:()=>(console.debug("Resetting form"),A(),o&&o()),noValidate:!0,children:[r.jsxs("div",{className:"mt-12",ref:I,children:[S,r.jsx(Rl,{containerRef:I})]}),r.jsx("div",{className:"h-14"}),!v&&r.jsxs(p.DialogActions,{position:"absolute",children:[y&&r.jsx("div",{className:"text-right",children:r.jsx(p.Typography,{color:"error",children:y.message})}),l&&C.length>0&&r.jsx("div",{className:"flex-grow flex overflow-auto no-scrollbar",children:C.map(P=>r.jsx(p.IconButton,{color:"primary",onClick:D=>{D.stopPropagation(),l&&P.onClick({entity:l,fullPath:f.path,collection:f,context:E,sideEntityController:B})},children:P.icon},P.name))}),g&&r.jsx(p.CircularProgress,{size:"small"}),r.jsx(p.Button,{variant:"text",disabled:N||g,type:"reset",children:m==="existing"?"Discard":"Clear"}),r.jsxs(p.Button,{variant:"text",color:"primary",type:"submit",disabled:N||g,onClick:()=>{k.current=!1},children:[m==="existing"&&"Save",m==="copy"&&"Create copy",m==="new"&&"Create"]}),r.jsxs(p.Button,{variant:"filled",color:"primary",type:"submit",disabled:N||g,onClick:()=>{k.current=!0},children:[m==="existing"&&"Save and close",m==="copy"&&"Create copy and close",m==="new"&&"Create and close"]})]})]})}function ac(e){let t={};if(e.inner){if(e.inner.length===0)return ke.setIn(t,e.path,e.message);for(const o of e.inner)ke.getIn(t,o.path)||(t=ke.setIn(t,o.path,o.message))}return t}function ic(e,t){return e?.path===t?.path&&e?.entityId===t?.entityId&&L(e?.values,t?.values)&&L(e?.collection,t?.collection)}function za(e){return Object.keys(ir).includes(e)}const ir={text_field:{key:"text_field",name:"Text field",description:"Simple short text",Icon:p.ShortTextIcon,color:"#2d7ff9",property:{dataType:"string",Field:At}},multiline:{key:"multiline",name:"Multiline",description:"Text with multiple lines",Icon:p.SubjectIcon,color:"#2d7ff9",property:{dataType:"string",multiline:!0,Field:At}},markdown:{key:"markdown",name:"Markdown",description:"Text with advanced markdown syntax",Icon:p.FormatQuoteIcon,color:"#2d7ff9",property:{dataType:"string",markdown:!0,Field:Ta}},url:{key:"url",name:"Url",description:"Text with URL validation",Icon:p.HttpIcon,color:"#154fb3",property:{dataType:"string",url:!0,Field:At}},email:{key:"email",name:"Email",description:"Text with email validation",Icon:p.EmailIcon,color:"#154fb3",property:{dataType:"string",email:!0,Field:At}},switch:{key:"switch",name:"Switch",description:"Boolean true or false field (or yes or no, 0 or 1...)",Icon:p.FlagIcon,color:"#20d9d2",property:{dataType:"boolean",Field:Ea}},select:{key:"select",name:"Select/enum",description:"Select one text value from within an enumeration",Icon:p.ListIcon,color:"#4223c9",property:{dataType:"string",enumValues:[],Field:go}},multi_select:{key:"multi_select",name:"Multi select",description:"Select multiple text values from within an enumeration",Icon:p.ListAltIcon,color:"#4223c9",property:{dataType:"array",of:{dataType:"string",enumValues:[]},Field:Ao}},number_input:{key:"number_input",name:"Number input",description:"Simple number field with validation",Icon:p.NumbersIcon,color:"#bec920",property:{dataType:"number",Field:At}},number_select:{key:"number_select",name:"Number select",description:"Select a number value from within an enumeration",Icon:p.FormatListNumberedIcon,color:"#bec920",property:{dataType:"number",enumValues:[],Field:go}},multi_number_select:{key:"multi_number_select",name:"Multiple number select",description:"Select multiple number values from within an enumeration",Icon:p.FormatListNumberedIcon,color:"#bec920",property:{dataType:"array",of:{dataType:"number",enumValues:[]},Field:Ao}},file_upload:{key:"file_upload",name:"File upload",description:"Input for uploading single files",Icon:p.UploadFileIcon,color:"#f92d9a",property:{dataType:"string",storage:{storagePath:"{path}"},Field:bo}},multi_file_upload:{key:"multi_file_upload",name:"Multiple file upload",description:"Input for uploading multiple files",Icon:p.DriveFolderUploadIcon,color:"#f92d9a",property:{dataType:"array",of:{dataType:"string",storage:{storagePath:"{path}"}},Field:bo}},reference:{key:"reference",name:"Reference",description:"The value refers to a different collection",Icon:p.LinkIcon,color:"#ff0042",property:{dataType:"reference",Field:Sa}},multi_references:{key:"multi_references",name:"Multiple references",description:"Multiple values that refer to a different collection",Icon:p.AddLinkIcon,color:"#ff0042",property:{dataType:"array",of:{dataType:"reference"},Field:Ca}},date_time:{key:"date_time",name:"Date/time",description:"A date time select field",Icon:p.ScheduleIcon,color:"#8b46ff",property:{dataType:"date",Field:Ba}},group:{key:"group",name:"Group",description:"Group of multiple fields",Icon:p.BallotIcon,color:"#ff9408",property:{dataType:"map",properties:{},Field:Ia}},key_value:{key:"key_value",name:"Key-value",description:"Flexible field that allows the user to add multiple key-value pairs",Icon:p.BallotIcon,color:"#ff9408",property:{dataType:"map",keyValue:!0,Field:Fa}},repeat:{key:"repeat",name:"Repeat/list",description:"A field that gets repeated multiple times (e.g. multiple text fields)",Icon:p.RepeatIcon,color:"#ff9408",property:{dataType:"array",of:{dataType:"string"},Field:Na}},custom_array:{key:"custom_array",name:"Custom array",description:"A field that saved its value as an array of custom objects",Icon:p.RepeatIcon,color:"#ff9408",property:{dataType:"array",of:[],Field:Da}},block:{key:"block",name:"Block",description:"A complex field that allows the user to compose different fields together, with a key->value format",Icon:p.ViewStreamIcon,color:"#ff9408",property:{dataType:"array",oneOf:{properties:{}},Field:Pa}}};function Va(e){const t=sr(e);if(!t){console.error("No field id found for property",e);return}return ir[t]}function It(e,t){const o=Co(e),n=sr(e);if(!n){console.error("No field id found for property",e);return}const i=ir[n],a=o?t[o]:void 0;return De(i??{},a??{})}function sr(e){if(e.dataType==="string")return e.multiline?"multiline":e.markdown?"markdown":e.storage?"file_upload":e.url?"url":e.email?"email":e.enumValues?"select":"text_field";if(e.dataType==="number")return e.enumValues?"number_select":"number_input";if(e.dataType==="map")return e.keyValue?"key_value":"group";if(e.dataType==="array"){const t=e.of;return e.oneOf?"block":Array.isArray(t)?"custom_array":_e(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 Co(e){return e.propertyConfig?e.propertyConfig:sr(e)}const Ne=({collection:e,path:t,entityId:o,values:n,previousValues:i,userConfigPersistence:a,fields:s,ignoreMissingFields:l=!1})=>{const c=a?.getCollectionConfig(t),u=Ye(c,"properties"),f=vt(e.properties),g=n??f,m=i??n??f,h=Object.entries(e.properties).map(([b,k])=>{const v=Pe({propertyKey:b,propertyOrBuilder:k,values:g,previousValues:m,path:t,entityId:o,fields:s,ignoreMissingFields:l});return v?{[b]:v}:{}}).filter(b=>b!==null).reduce((b,k)=>({...b,...k}),{}),A=De(h,u),y=Object.entries(A).filter(([b,k])=>!!k?.dataType).map(([b,k])=>({[b]:k})).reduce((b,k)=>({...b,...k}),{});return{...e,properties:y,originalCollection:e}};function Pe({propertyOrBuilder:e,fromBuilder:t=!1,ignoreMissingFields:o=!1,...n}){if(typeof e=="object"&&"resolved"in e)return e;let i=null;if(e)if(_e(e)){const a=n.path;if(!a)throw Error("Trying to resolve a property builder without specifying the entity path");const s=n.propertyKey?ke.getIn(n.values,n.propertyKey):void 0,l=e({...n,path:a,propertyValue:s,values:n.values??{},previousValues:n.previousValues??n.values??{}});if(!l)return null;i=Pe({...n,propertyOrBuilder:l,fromBuilder:!0,ignoreMissingFields:o})}else{const a=e;if(a.dataType==="map"&&a.properties){const s=xo({ignoreMissingFields:o,...n,properties:a.properties});i={...a,resolved:!0,fromBuilder:t,properties:s}}else a.dataType==="array"?i=Xe({property:a,fromBuilder:t,ignoreMissingFields:o,...n}):(a.dataType==="string"||a.dataType==="number")&&a.enumValues&&(i=Eo(a,t))}else return null;if(i||(i={...e,resolved:!0,fromBuilder:t}),i.propertyConfig&&!za(i.propertyConfig)){const a=n.fields;if(!a&&!o)throw Error(`Trying to resolve a property with key '${i.propertyConfig}' that inherits from a custom property config but no custom property configs were provided. Use the property 'propertyConfigs' in your app config to provide them`);const s=a?.[i.propertyConfig];if(!s)return console.warn(`Trying to resolve a property with key '${i.propertyConfig}' that inherits from a custom property config but no custom property config with that key was found. Check the 'propertyConfigs' in your app config`),console.warn("Available property configs",a),null;if(s.property){const l=s.property;"propertyConfig"in l&&delete l.propertyConfig;const c=Pe({propertyOrBuilder:l,ignoreMissingFields:o,...n});c&&(i=De(c,i))}}return i?{...i,resolved:!0}:null}function Xe({propertyKey:e,property:t,ignoreMissingFields:o=!1,...n}){const i=e?ke.getIn(n.values,e):void 0;if(t.of){if(Array.isArray(t.of))return{...t,resolved:!0,fromBuilder:n.fromBuilder,resolvedProperties:t.of.map((a,s)=>Pe({propertyKey:`${e}.${s}`,propertyOrBuilder:a,ignoreMissingFields:o,...n,index:s}))};{const a=t.of,s=Array.isArray(i)?i.map((c,u)=>Pe({propertyKey:`${e}.${u}`,propertyOrBuilder:a,ignoreMissingFields:o,...n,index:u})).filter(c=>!!c):[],l=Pe({propertyKey:`${e}`,propertyOrBuilder:a,ignoreMissingFields:o,...n});if(!l&&!o)throw Error("When using a property builder as the 'of' prop of an ArrayProperty, you must return a valid child property");return{...t,resolved:!0,fromBuilder:n.fromBuilder,of:l,resolvedProperties:s}}}else if(t.oneOf){const a=t.oneOf?.typeField??yt,s=Array.isArray(i)?i.map((c,u)=>{const f=c&&c[a],g=t.oneOf?.properties[f];return!f||!g?null:Pe({propertyKey:`${e}.${u}`,propertyOrBuilder:g,ignoreMissingFields:o,...n})}).filter(c=>!!c):[],l=xo({properties:t.oneOf.properties,ignoreMissingFields:o,...n});return{...t,resolved:!0,oneOf:{...t.oneOf,properties:l},fromBuilder:n.fromBuilder,resolvedProperties:s}}else{if(t.Field)return{...t,resolved:!0,fromBuilder:n.fromBuilder};throw Error("The array property needs to declare an 'of' or a 'oneOf' property, or provide a custom `Field`")}}function xo({properties:e,ignoreMissingFields:t,...o}){return Object.entries(e).map(([n,i])=>{const a=Pe({propertyKey:n,propertyOrBuilder:i,ignoreMissingFields:t,...o});return a?{[n]:a}:{}}).filter(n=>n!==null).reduce((n,i)=>({...n,...i}),{})}function Eo(e,t){return typeof e.enumValues=="object"?{...e,resolved:!0,enumValues:We(e.enumValues)?.filter(o=>o&&(o.id||o.id===0)&&o.label)??[],fromBuilder:t??!1}:e}function sc(e){return typeof e=="object"?Object.entries(e).map(([t,o])=>typeof o=="string"?{id:t,label:o}:o):Array.isArray(e)?e:void 0}function Bo(e,t){return typeof e=="string"?t?.find(o=>o.key===e):e}function So(e){const{path:t,collections:o=[],currentFullPath:n}=e,i=fe(t).split("/"),a=Qt(i),s=[];for(let l=0;l<a.length;l++){const c=a[l],u=o&&o.find(f=>f.id===c||f.path===c);if(u){const f=u.id??u.path,g=n&&n.length>0?n+"/"+f:f;s.push({type:"collection",path:g,collection:u});const m=fe(fe(t).replace(c,"")),h=m.length>0?m.split("/"):[];if(h.length>0){const A=h[0],y=g+"/"+A;if(s.push({type:"entity",entityId:A,path:g,parentCollection:u}),h.length>1){const b=h.slice(1).join("/");if(!u)throw Error("collection not found resolving path: "+u);const k=u.entityViews,v=k&&k.map(_=>Bo(_,e.contextEntityViews)).filter(Boolean).find(_=>_.key===b);if(v){const _=n&&n.length>0?n+"/"+v.key:v.key;s.push({type:"custom_view",path:_,view:v})}else u.subcollections&&s.push(...So({path:b,collections:u.subcollections,currentFullPath:y,contextEntityViews:e.contextEntityViews}))}}break}}return s}const lc="100vw",cc="55vw",lr="768px",cr="main_##Q$SC^#S6";function dc({path:e,entityId:t,selectedSubPath:o,copy:n,collection:i,parentCollectionIds:a,onValuesAreModified:s,formWidth:l,onUpdate:c,onClose:u}){i.customId&&i.formAutoSave&&console.warn(`The collection ${i.path} has customId and formAutoSave enabled. This is not supported and formAutoSave will be ignored`);const[f,g]=d.useState(!1),[m,h]=d.useState(void 0);Lt(m,()=>{m&&F({entityId:U?.id,collection:i,path:e,values:m,closeAfterSave:!1})},!1,2e3);const A=Qe(i),y=dr(),b=He(),k=Je(),v=ne(),_=Ae(),E=qe(),[C,B]=d.useState(void 0),[x,S]=d.useState(n?"copy":t?"existing":"new"),N=d.useRef(void 0),I=N.current,P=(i.subcollections??[]).filter(Y=>!Y.hideFromNavigation),D=P?.length??0,G=i.entityViews,R=G?.length??0,K=i.formAutoSave&&!i.customId,W=R>0||D>0,j=o??Er(i?i.defaultSelectedView:void 0,{status:x,entityId:t}),M=d.useRef(j??cr),H=M.current===cr,{entity:J,dataLoading:re,dataLoadingError:oe}=Mr({path:e,entityId:t,collection:i,useCache:!1}),[U,X]=d.useState(J),[Q,ee]=d.useState(void 0);d.useEffect(()=>{J&&X(J)},[J]),d.useEffect(()=>{if(x==="new")ee(!1);else{const Y=U?Fr(i,E,e,U??null):!1;U&&ee(!Y)}},[E,U,x]);const Z=d.useCallback(Y=>{g(!1),k.open({type:"error",message:"Error before saving: "+Y?.message}),console.error(Y)},[k]),$=d.useCallback(Y=>{g(!1),k.open({type:"error",message:"Error after saving (entity is saved): "+Y?.message}),console.error(Y)},[k]),V=(Y,Be)=>{g(!1),K||k.open({type:"success",message:`${i.singularName??i.name}: Saved correctly`}),X(Y),S("existing"),s(!1),c&&c({entity:Y}),Be?(console.log("Closing side dialog"),y.setBlocked(!1),y.close(!0),u?.()):x!=="existing"&&b.replace({path:e,entityId:Y.id,selectedSubPath:M.current,updateUrl:!0,collection:i})},z=d.useCallback(Y=>{g(!1),k.open({type:"error",message:"Error saving: "+Y?.message}),console.error("Error saving entity",e,t),console.error(Y)},[t,e,k]),F=({values:Y,previousValues:Be,closeAfterSave:Se,entityId:$e,collection:Ft,path:Nt})=>(g(!0),Or({path:Nt,entityId:$e,values:Y,previousValues:Be,collection:Ft,status:x,dataSource:A,context:_,onSaveSuccess:Pt=>V(Pt,Se),onSaveFailure:z,onPreSaveHookError:Z,onSaveSuccessHookError:$}).then()),T=async({collection:Y,path:Be,entityId:Se,values:$e,previousValues:Ft,closeAfterSave:Nt,autoSave:Pt})=>{if(x)if(Pt)h($e);else return F({collection:Y,path:Be,entityId:Se,values:$e,previousValues:Ft,closeAfterSave:Nt})},le=G?G.map(Y=>Bo(Y,v.entityViews)).filter(Boolean):[],ve=G&&le.map((Y,Be)=>{if(!Y||M.current!==Y.key)return null;const Se=Y.Builder;return Se?r.jsx("div",{className:p.cls(p.defaultBorderMixin,"relative flex-grow w-full h-full overflow-auto "),role:"tabpanel",children:r.jsx(ae,{children:C&&r.jsx(Se,{collection:i,entity:U,modifiedValues:I??U?.values,formContext:C})})},`custom_view_${Y.key}`):(console.error("customView.Builder is not defined"),null)}).filter(Boolean),te=re&&!U||(!U||Q===void 0)&&(x==="existing"||x==="copy"),O=te||f,ie=P&&P.map((Y,Be)=>{const Se=Y.id??Y.path,$e=U?`${e}/${U?.id}/${fe(Se)}`:void 0;return M.current!==Se?null:r.jsxs("div",{className:"relative flex-grow h-full overflow-auto w-full",role:"tabpanel",children:[O&&r.jsx(rr,{}),!te&&(U&&$e?r.jsx(po,{fullPath:$e,parentCollectionIds:[...a,i.id],isSubCollection:!0,...Y}):r.jsx("div",{className:"flex items-center justify-center w-full h-full p-3",children:r.jsx(p.Typography,{variant:"label",children:"You need to save your entity before adding additional collections"})}))]},`subcol_${Se}`)}).filter(Boolean),me=d.useCallback(()=>{s(!1)},[]),ue=Y=>{M.current=Y,b.replace({path:e,entityId:t,selectedSubPath:Y===cr?void 0:Y,updateUrl:!0,collection:i})},he=d.useCallback(Y=>{N.current=Y},[]),ze=d.useCallback(Y=>{k.open({type:"error",message:"Error updating id, check the console"})},[]),Ve=d.useCallback(Y=>{X(Be=>Be?{...Be,id:Y}:void 0)},[]),Ge=Y=>{K||s(Y)};function Ue(){const Y=v.plugins;let Be=r.jsx(Ma,{status:x,path:e,collection:i,onEntitySaveRequested:T,onDiscard:me,onValuesChanged:he,onModified:Ge,entity:U,onIdChange:Ve,onFormContextChange:B,hideId:i.hideIdFromForm,autoSave:K,onIdUpdateError:ze});return Y&&Y.forEach(Se=>{Se.form?.provider&&(Be=r.jsx(Se.form.provider.Component,{status:x,path:e,collection:i,onDiscard:me,onValuesChanged:he,onModified:Ge,entity:U,context:_,formContext:C,...Se.form.provider.props,children:Be}))}),r.jsx(ae,{children:Be})}const nt=Q===void 0?r.jsx(r.Fragment,{}):Q?r.jsxs(r.Fragment,{children:[r.jsx(p.Typography,{className:"mt-16 mb-8 mx-8",variant:"h4",children:i.singularName??i.name}),r.jsx(Wr,{className:"px-12",entity:U,path:e,collection:i})]}):Ue(),Fo=P&&P.map(Y=>r.jsx(p.Tab,{className:"text-sm min-w-[140px]",value:Y.id,children:Y.name},`entity_detail_collection_tab_${Y.name}`)),No=le.map(Y=>r.jsx(p.Tab,{className:"text-sm min-w-[140px]",value:Y.key,children:Y.name},`entity_detail_collection_tab_${Y.name}`));return r.jsx("div",{className:"flex flex-col h-full w-full transition-width duration-250 ease-in-out",children:r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:p.cls(p.defaultBorderMixin,"no-scrollbar border-b pl-2 pr-2 pt-1 flex items-end overflow-scroll bg-gray-50 dark:bg-gray-950"),children:[r.jsx("div",{className:"pb-1 self-center",children:r.jsx(p.IconButton,{onClick:()=>(u?.(),y.close(!1)),size:"large",children:r.jsx(p.CloseIcon,{})})}),r.jsx("div",{className:"flex-grow"}),te&&r.jsx("div",{className:"self-center",children:r.jsx(p.CircularProgress,{size:"small"})}),r.jsxs(p.Tabs,{value:M.current,onValueChange:Y=>{ue(Y)},className:"pl-4 pr-4 pt-0",children:[r.jsx(p.Tab,{disabled:!W,value:cr,className:`${W?"":"hidden"} text-sm min-w-[140px]`,children:i.singularName??i.name}),No,Fo]})]}),r.jsxs("div",{className:"flex-grow h-full flex overflow-auto flex-row w-full ",style:{},children:[r.jsx("div",{role:"tabpanel",hidden:!H,id:`form_${e}`,className:" w-full",children:te?r.jsx(rr,{}):nt}),ve,ie]})]})})}function pc(e,t){const[o,n]=d.useState(),{navigator:i}=d.useContext(ge.UNSAFE_NavigationContext),a=ge.useNavigate(),s=()=>{n(void 0)},l=()=>{t(),n(void 0),a(-1)},c=d.useCallback(({action:u,location:f,retry:g})=>{switch(u){case"REPLACE":{g();return}case"POP":n(f)}},[]);return d.useEffect(()=>{if(!e||o||!("block"in i))return;const u=i.block(f=>{const g={...f,retry(){u(),f.retry()}};c(g)});return u},[i,c,e,o]),{navigationWasBlocked:!!o,handleCancel:s,handleOk:l}}function uc({open:e,handleOk:t,handleCancel:o,body:n,title:i}){return r.jsxs(p.Dialog,{open:e,onOpenChange:a=>a?o():t(),children:[r.jsxs(p.DialogContent,{children:[r.jsx(p.Typography,{variant:"h6",children:i}),n,r.jsx(p.Typography,{children:"Are you sure you want to leave this page?"})]}),r.jsxs(p.DialogActions,{children:[r.jsx(p.Button,{variant:"text",onClick:o,autoFocus:!0,children:" Cancel "}),r.jsx(p.Button,{onClick:t,children:" Ok "})]})]})}const Ga=d.createContext({width:"",blocked:!1,setBlocked:e=>{},setBlockedNavigationMessage:e=>{},close:()=>{}}),dr=()=>d.useContext(Ga);function fc(){const t=_t().sidePanels,o=[...t];return o.push(void 0),r.jsx(r.Fragment,{children:o.map((n,i)=>r.jsx(mc,{panel:n,offsetPosition:t.length-i-1},`side_dialog_${i}`))})}function mc({offsetPosition:e,panel:t}){const[o,n]=d.useState(!1),[i,a]=d.useState(!1),[s,l]=d.useState(),c=d.useRef(t?.width),u=c.current,f=_t(),{navigationWasBlocked:g,handleOk:m,handleCancel:h}=pc(i&&!o,()=>a(!1));d.useEffect(()=>{t&&(c.current=t.width)},[t]);const A=()=>{a(!1),n(!1),f.close(),t?.onClose?.()},y=()=>{n(!1)},b=k=>{i&&!k?n(!0):(f.close(),t?.onClose?.())};return r.jsxs(Ga.Provider,{value:{blocked:i,setBlocked:a,setBlockedNavigationMessage:l,width:u,close:b},children:[r.jsxs(p.Sheet,{open:!!t,onOpenChange:k=>!k&&b(),children:[t&&r.jsx("div",{className:"transform max-w-[100vw] lg:max-w-[95vw] flex flex-col h-full transition-all duration-250 ease-in-out bg-white dark:bg-gray-900 ",style:{width:t.width,transform:`translateX(-${e*200}px)`},children:r.jsx(ae,{children:t.component})}),!t&&r.jsx("div",{style:{width:u}})]}),r.jsx(uc,{open:g||o,handleOk:o?A:m,handleCancel:o?y:h,body:s})]})}function hc(e){const{blocked:t,setBlocked:o,setBlockedNavigationMessage:n}=dr(),i=pe(),a=d.useMemo(()=>i.getParentCollectionIds(e.path),[i,e.path]),s=d.useMemo(()=>{if(!e)return;let c=e.collection;const u=i.getCollection(e.path);if(u&&(c=u),!c)throw console.error("ERROR: No collection found in path `",e.path,"`. Entity id: ",e.entityId),Error("ERROR: No collection found in path `"+e.path+"`. Make sure you have defined a collection for this path in the root navigation.");return c},[i,e]);d.useEffect(()=>{function c(u){t&&s&&(u.preventDefault(),u.returnValue=`You have unsaved changes in this ${s.name}. Are you sure you want to leave this page?`)}return typeof window<"u"&&window.addEventListener("beforeunload",c),()=>{typeof window<"u"&&window.removeEventListener("beforeunload",c)}},[t,s]);const l=d.useCallback(c=>{o(c),n(c?r.jsxs(r.Fragment,{children:[" You have unsaved changes in this ",r.jsx("b",{children:s?.singularName??s?.name}),"."]}):void 0)},[s?.name,o,n]);return!e||!s?r.jsx("div",{className:"w-full"}):r.jsx(r.Fragment,{children:r.jsx(ae,{children:r.jsx(dc,{...e,formWidth:e.width,collection:s,parentCollectionIds:a,onValuesAreModified:l})})})}const Ya="new";function gc(e,t){if(t)return lc;const o=!e.selectedSubPath;let n;return e.width?n=typeof e.width=="number"?`${e.width}px`:e.width:e.collection?.sideDialogWidth&&(n=typeof e.collection.sideDialogWidth=="number"?`${e.collection.sideDialogWidth}px`:e.collection.sideDialogWidth),o?n||(e.collection?Ac(e.collection):lr):`calc(${cc} + ${n??lr})`}const Io={};function Ac(e){if(Io[e.id])return Io[e.id];const t=Ne({collection:e,path:"__ignored",ignoreMissingFields:!0});let o=lr;if(t?.properties){const n=Object.values(t.properties).map(a=>pr(a)),i=Math.max(...n);i<3?o=lr:o=768+32*(i-2)+"px"}return Io[e.id]=o,o}function pr(e,t=0){if(e.dataType==="map"&&e.properties){const o=Object.values(e.properties).flatMap(n=>pr(n,t+1));return Math.max(...o)}else return e.dataType==="array"&&e.oneOf?t+3:e.dataType==="array"&&e.of?Array.isArray(e.of)?Math.max(...e.of.map(o=>pr(o,t+1))):pr(e.of,t+1):t+1}const bc=(e,t)=>{const o=ge.useLocation(),n=d.useRef(!1),i=!Me();d.useEffect(()=>{if(!e.loading&&!n.current){if(console.debug("Initialising side entity controller"),e.isUrlCollectionPath(o.pathname)){const c=o.hash===`#${Ya}`,u=e.urlPathToDataPath(o.pathname),f=yc(u,e.collections??[],c);for(let g=0;g<f.length;g++){const m=f[g];setTimeout(()=>{g===0?t.replace(ur(m,e.buildUrlCollectionPath,e.resolveAliasesFrom,i)):t.open(ur(m,e.buildUrlCollectionPath,e.resolveAliasesFrom,i))},1)}}n.current=!0}},[o,e.loading,e.isUrlCollectionPath,e.buildUrlCollectionPath,e.resolveAliasesFrom,t,i,e]);const a=d.useCallback(()=>{t.close()},[t]),s=d.useCallback(c=>{if(c.copy&&!c.entityId)throw Error("If you want to copy an entity you need to provide an entityId");const u=Er(c.collection?c.collection.defaultSelectedView:void 0,{status:c.copy?"copy":c.entityId?"existing":"new",entityId:c.entityId});t.open(ur({selectedSubPath:u,...c},e.buildUrlCollectionPath,e.resolveAliasesFrom,i))},[t,e.buildUrlCollectionPath,e.resolveAliasesFrom,i]),l=d.useCallback(c=>{if(c.copy&&!c.entityId)throw Error("If you want to copy an entity you need to provide an entityId");t.replace(ur(c,e.buildUrlCollectionPath,e.resolveAliasesFrom,i))},[e.buildUrlCollectionPath,e.resolveAliasesFrom,t,i]);return{close:a,open:s,replace:l}};function yc(e,t,o){const n=So({path:e,collections:t}),i=[];let a="";for(let s=0;s<n.length;s++){const l=n[s];if(l.type==="collection"&&(a=l.path),s>0){const c=n[s-1];if(l.type==="entity")i.push({path:l.path,entityId:l.entityId,copy:!1,width:l.parentCollection?.sideDialogWidth});else if(l.type==="custom_view"){if(c.type==="entity"){const u=i[i.length-1];u&&(u.selectedSubPath=l.view.key)}}else if(l.type==="collection"&&c.type==="entity"){const u=i[i.length-1];u&&(u.selectedSubPath=l.collection.id??l.collection.path)}}}return o&&i.push({path:a,copy:!1}),i}const ur=(e,t,o,n)=>{const i=fe(e.path),a=e.entityId?t(`${i}/${e.entityId}/${e.selectedSubPath||""}`):t(`${i}#${Ya}`),s=o(e.path),l={...e,path:s};return{key:`${e.path}/${e.entityId}`,component:r.jsx(hc,{...l}),urlPath:a,parentUrlPath:t(i),width:gc(e,n),onClose:e.onClose}};function wc(){const e=ge.useLocation(),t=ge.useNavigate(),[o,n]=d.useState([]),i=d.useRef(o),a=d.useRef({}),s=d.useRef(0),l=g=>{i.current=g,n(g)};d.useEffect(()=>{const h=(e.state?.panels??[]).map(A=>a.current[A]).filter(A=>!!A);L(i.current.map(A=>A.key),h.map(A=>A.key))||l(h)},[e]);const c=d.useCallback(()=>{if(o.length===0)return;const g=o[o.length-1],m=[...o.slice(0,-1)];if(l(m),s.current>0)g.urlPath&&t(-1),s.current--;else if(g.parentUrlPath){const h=e.state?.base_location??e;t(g.parentUrlPath,{replace:!0,state:{base_location:h,panels:m.map(A=>A.key)}})}},[o,t,e]),u=d.useCallback(g=>{const m=Array.isArray(g)?g:[g];m.forEach(y=>{a.current[y.key]=y}),s.current=s.current+m.length;const h=e.state?.base_location??e,A=[...o,...m];l(A),m.forEach(y=>{y.urlPath&&t(y.urlPath,{state:{base_location:h,panels:A.map(b=>b.key)}})})},[e,t,o]),f=d.useCallback(g=>{const m=Array.isArray(g)?g:[g];m.forEach(y=>{a.current[y.key]=y});const h=e.state?.base_location??e,A=[...o.slice(0,-m.length),...m];l(A),m.forEach(y=>{y.urlPath&&t(y.urlPath,{replace:!0,state:{base_location:h,panels:A.map(b=>b.key)}})})},[e,t,o]);return{sidePanels:o,close:c,open:u,replace:f}}function vc({delegate:e,propertyConfigs:t,navigationController:o}){return{fetchCollection:d.useCallback(({path:n,collection:i,filter:a,limit:s,startAfter:l,searchString:c,orderBy:u,order:f})=>e.fetchCollection({path:n,filter:a,limit:s,startAfter:l,searchString:c,orderBy:u,order:f}),[e]),listenCollection:e.listenCollection?d.useCallback(({path:n,collection:i,filter:a,limit:s,startAfter:l,searchString:c,orderBy:u,order:f,onUpdate:g,onError:m})=>{const h=i??o.getCollection(n),A=!!h?.collectionGroup;if(!e.listenCollection)throw Error("useBuildDataSource delegate not initialised");return e.listenCollection({path:n,filter:a,limit:s,startAfter:l,searchString:c,orderBy:u,order:f,onUpdate:g,onError:m,isCollectionGroup:A,collection:h})},[e,o.getCollection]):void 0,fetchEntity:d.useCallback(({path:n,entityId:i})=>e.fetchEntity({path:n,entityId:i}),[e]),listenEntity:e.listenEntity?d.useCallback(({path:n,entityId:i,collection:a,onUpdate:s,onError:l})=>{if(!e.listenEntity)throw Error("useBuildDataSource delegate not initialised");return e.listenEntity({path:n,entityId:i,onUpdate:s,onError:l})},[e.listenEntity]):void 0,saveEntity:d.useCallback(({path:n,entityId:i,values:a,collection:s,status:l})=>{const c=s??o.getCollection(n),f=(c?Ne({collection:c,path:n,entityId:i,fields:t}):void 0)?.properties,g=e.cmsToDelegateModel(a),m=f?Lo({inputValues:g,properties:f,status:l,timestampNowValue:e.currentTime(),setDateToMidnight:e.setDateToMidnight}):g;return e.saveEntity({path:n,entityId:i,values:m,status:l}).then(h=>({id:h.id,path:h.path,values:e.delegateToCMSModel(m)}))},[e.saveEntity,o.getCollection]),deleteEntity:d.useCallback(({entity:n})=>e.deleteEntity({entity:n}),[e.deleteEntity]),checkUniqueField:d.useCallback((n,i,a,s)=>e.checkUniqueField(n,i,a,s),[e.checkUniqueField]),generateEntityId:d.useCallback(n=>e.generateEntityId(n),[e.generateEntityId]),countEntities:e.countEntities?async({path:n,collection:i,filter:a,order:s,orderBy:l})=>e.countEntities({path:n,filter:a,orderBy:l,order:s,isCollectionGroup:!!i.collectionGroup}):void 0,isFilterCombinationValid:d.useCallback(({path:n,filterValues:i,sortBy:a})=>e.isFilterCombinationValid?e.isFilterCombinationValid({path:n,filterValues:i,sortBy:a}):!0,[e.isFilterCombinationValid]),initTextSearch:d.useCallback(async n=>e.initTextSearch?e.initTextSearch(n):!1,[e.initTextSearch])}}const kc="https://api-drplyi3b6q-ey.a.run.app";async function _c(e,t){const o=await e.getAuthToken();return fetch(kc+"/access_log",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Basic ${o}`},body:JSON.stringify({plugins:t})}).then(async n=>n.json())}function Cc(e,t){const[o,n]=d.useState(null),i=d.useRef(null),a=t?.map(s=>s.key);return d.useEffect(()=>{e.user&&e.user.uid!==i.current&&!e.initialLoading&&(_c(e,a).then(n),i.current=e.user.uid)},[e,a]),o}function xc(e){const{children:t,entityLinkBuilder:o,userConfigPersistence:n,dateTimeFormat:i,locale:a,authController:s,storageSource:l,dataSourceDelegate:c,plugins:u,onAnalyticsEvent:f,propertyConfigs:g,entityViews:m,components:h,navigationController:A}=e;p.useLocaleConfig(a);const y=vc({delegate:c,propertyConfigs:g,navigationController:A}),b=wc(),k=bc(A,b),v=u?.some(x=>x.loading)??!1,_=s.initialLoading||A.loading||v,E={dateTimeFormat:i,locale:a,entityLinkBuilder:o,plugins:u,entityViews:m??[],propertyConfigs:g??{},components:h},C=d.useMemo(()=>({onAnalyticsEvent:f}),[]),B=Cc(s,u);return A.navigationLoadingError?r.jsx(p.CenteredView,{maxWidth:"md",children:r.jsx(ye,{title:"Error loading navigation",error:A.navigationLoadingError})}):s.authError?r.jsx(p.CenteredView,{maxWidth:"md",children:r.jsx(ye,{title:"Error loading auth",error:s.authError})}):B?.blocked?r.jsxs(p.CenteredView,{maxWidth:"md",fullScreen:!0,children:[r.jsx(p.Typography,{variant:"h4",children:"Access blocked"}),r.jsxs(p.Typography,{children:["This app has been blocked. Please reach out at ",r.jsx("a",{href:"mailto:hello@firecms.co",children:"hello@firecms.co"})," for more information."]}),B?.message&&r.jsxs(p.Typography,{children:["Response from the server: ",B?.message]})]}):r.jsx(yn.Provider,{value:C,children:r.jsx(bn.Provider,{value:E,children:r.jsx(hn.Provider,{value:n,children:r.jsx(mn.Provider,{value:l,children:r.jsx(dn.Provider,{value:y,children:r.jsx(hr.Provider,{value:s,children:r.jsx(un.Provider,{value:b,children:r.jsx(fn.Provider,{value:k,children:r.jsx(pn.Provider,{value:A,children:r.jsx(Vi,{children:r.jsx(Ec,{loading:_,children:t})})})})})})})})})})})}function Ec({loading:e,children:t}){const o=Ae(),n=ne();let i=t({context:o,loading:e});const a=n.plugins;return!e&&a&&a.forEach(s=>{s.provider&&(i=r.jsx(s.provider.Component,{...s.provider.props,context:o,children:i}))}),r.jsx(r.Fragment,{children:i})}const La=280,Bc=d.memo(function(t){const{children:o,autoOpenDrawer:n,logo:i,className:a,style:s}=t,l=d.Children.toArray(o).filter(C=>C.type.componentType==="Drawer");if(l.length>1)throw Error("Only one Drawer component is allowed in Scaffold");const c=d.Children.toArray(o).filter(C=>C.type.componentType==="AppBar");if(c.length>1)throw Error("Only one AppBar component is allowed in Scaffold");const u=d.Children.toArray(o).filter(C=>C.type.componentType!=="Drawer"&&C.type.componentType!=="AppBar"),f=l.length>0,g=Me(),[m,h]=d.useState(!1),[A,y]=d.useState(!1),b=d.useCallback(()=>y(!0),[]),k=d.useCallback(()=>y(!1),[]),v=d.useCallback(()=>{h(!0)},[]),_=d.useCallback(()=>{h(!1)},[]),E=m||!!(g&&n&&A);return r.jsx(fo.Provider,{value:{logo:i,hasDrawer:f,drawerHovered:A,drawerOpen:E,closeDrawer:_,openDrawer:v,autoOpenDrawer:n},children:r.jsxs("div",{className:p.cls("flex h-screen w-screen bg-gray-50 dark:bg-gray-900 text-gray-900 dark:text-white overflow-hidden",a),style:{paddingTop:"env(safe-area-inset-top)",paddingLeft:"env(safe-area-inset-left)",paddingRight:"env(safe-area-inset-right)",paddingBottom:"env(safe-area-inset-bottom)",height:"100dvh",...s},children:[c,r.jsx(Ic,{displayed:f,onMouseEnter:b,onMouseMove:b,onMouseLeave:k,open:E,hovered:A,setDrawerOpen:h,children:f&&l}),r.jsxs("main",{className:"flex flex-col flex-grow overflow-auto",children:[r.jsx(Sc,{}),r.jsx("div",{className:p.cls(p.defaultBorderMixin,"flex-grow overflow-auto lg:m-0 lg:mx-4 lg:mb-4 lg:rounded-lg lg:border lg:border-solid m-0 mt-1"),children:r.jsx(ae,{children:u})})]})]})})},L),Sc=()=>r.jsx("div",{className:"flex flex-col min-h-[68px]"});function Ic(e){const t=e.displayed?e.open?La:72:0,o=r.jsxs("div",{className:"relative h-full no-scrollbar overflow-y-auto overflow-x-hidden",style:{width:t,transition:"left 100ms cubic-bezier(0.4, 0, 0.6, 1) 0ms, opacity 100ms cubic-bezier(0.4, 0, 0.6, 1) 0ms, width 100ms cubic-bezier(0.4, 0, 0.6, 1) 0ms"},children:[!e.open&&e.displayed&&r.jsx(p.Tooltip,{title:"Open menu",side:"right",sideOffset:12,className:"fixed top-2 left-3 !bg-gray-50 dark:!bg-gray-900 rounded-full w-fit z-20",children:r.jsx(p.IconButton,{color:"inherit","aria-label":"Open menu",className:"sticky top-2 left-3 ",onClick:()=>e.setDrawerOpen(!0),size:"large",children:r.jsx(p.MenuIcon,{})})}),r.jsx("div",{className:`absolute right-0 top-4 ${e.open?"opacity-100":"opacity-0 invisible"} transition-opacity duration-200 ease-in-out`,children:r.jsx(p.IconButton,{"aria-label":"Close drawer",onClick:()=>e.setDrawerOpen(!1),children:r.jsx(p.ChevronLeftIcon,{})})}),r.jsx("div",{className:"flex flex-col h-full",children:e.children})]});return Me()?r.jsx("div",{className:"z-20 relative",onMouseEnter:e.onMouseEnter,onMouseMove:e.onMouseMove,onMouseLeave:e.onMouseLeave,style:{width:t,transition:"left 100ms cubic-bezier(0.4, 0, 0.6, 1) 0ms, opacity 100ms cubic-bezier(0.4, 0, 0.6, 1) 0ms, width 100ms cubic-bezier(0.4, 0, 0.6, 1) 0ms"},children:o}):e.displayed?r.jsxs(r.Fragment,{children:[r.jsx(p.IconButton,{color:"inherit","aria-label":"Open drawer",onClick:()=>e.setDrawerOpen(!0),size:"large",className:"absolute top-2 left-6",children:r.jsx(p.MenuIcon,{})}),r.jsx(p.Sheet,{side:"left",transparent:!0,open:e.open,onOpenChange:e.setDrawerOpen,children:o})]}):null}function ja({name:e,icon:t,drawerOpen:o,tooltipsOpen:n,url:i,onClick:a}){const s=r.jsx("div",{className:"text-gray-600 dark:text-gray-500",children:t}),l=r.jsxs(ge.NavLink,{onClick:a,style:{width:o?"280px":"72px",transition:o?"width 150ms ease-in":void 0},className:({isActive:c})=>p.cls("rounded-r-lg truncate","hover:bg-slate-300 hover:bg-opacity-75 dark:hover:bg-gray-700 dark:hover:bg-opacity-75 text-gray-800 dark:text-gray-200 hover:text-gray-900 hover:dark:text-white","flex flex-row items-center mr-8",o?"pl-8 h-12":"pl-6 h-11","font-medium text-sm",c?"bg-slate-200 bg-opacity-60 dark:bg-gray-800 dark:bg-opacity-30":""),to:i,children:[s,r.jsx("div",{className:p.cls(o?"opacity-100":"opacity-0 hidden","ml-4 font-inherit text-inherit"),children:e.toUpperCase()})]});return r.jsx(p.Tooltip,{open:o?!1:n,side:"right",title:e,children:l})}function Ua({className:e,style:t}){const{drawerHovered:o,drawerOpen:n,closeDrawer:i,logo:a}=nr(),s=ut(),l=pe(),c=o&&!n,u=Me(),f=ge.useNavigate(),[g,m]=d.useState(!1);if(!l.topLevelNavigation)throw Error("Navigation not ready in Drawer");const{navigationEntries:h,groups:A}=l.topLevelNavigation,y=h.filter(_=>_.type==="admin")??[],b=A.filter(_=>_!=="Admin"),k=d.useCallback(_=>n?r.jsx("div",{className:"pt-8 pl-6 pr-8 pb-2 flex flex-row items-center",children:r.jsx(p.Typography,{variant:"caption",color:"secondary",className:"font-medium flex-grow line-clamp-1",children:_?_.toUpperCase():"Views".toUpperCase()})}):r.jsx("div",{className:"h-12 w-full"}),[n]),v=_=>{const E=_.type==="collection"?"drawer_navigate_to_collection":_.type==="view"?"drawer_navigate_to_view":"unmapped_event";s.onAnalyticsEvent?.(E,{url:_.url}),u||i()};return r.jsx(r.Fragment,{children:r.jsxs("div",{className:p.cls("flex flex-col h-full relative flex-grow w-full",e),style:t,children:[r.jsx($a,{logo:a}),r.jsx("div",{className:"overflow-scroll no-scrollbar",children:b.map(_=>r.jsxs(d.Fragment,{children:[k(_),Object.values(h).filter(E=>E.group===_).map((E,C)=>r.jsx(ja,{icon:r.jsx(Ht,{collectionOrView:E.collection??E.view}),tooltipsOpen:c,drawerOpen:n,onClick:()=>v(E),url:E.url,name:E.name},`navigation_${C}`))]},`drawer_group_${_}`))}),y.length>0&&r.jsx(p.Menu,{open:g,onOpenChange:m,trigger:r.jsxs(p.IconButton,{shape:"square",className:"m-4 text-gray-900 dark:text-white w-fit",children:[r.jsx(p.Tooltip,{title:"Admin",open:c,side:"right",sideOffset:28,children:r.jsx(p.MoreVertIcon,{})}),n&&r.jsx("div",{className:p.cls(n?"opacity-100":"opacity-0 hidden","mx-4 font-inherit text-inherit"),children:"ADMIN"})]}),children:y.map((_,E)=>r.jsxs(p.MenuItem,{onClick:C=>{C.preventDefault(),f(_.path)},children:[r.jsx(Ht,{collectionOrView:_.view}),_.name]},`navigation_${E}`))})]})})}function $a({logo:e}){const t=pe(),{drawerOpen:o}=nr();return r.jsx("div",{style:{transition:"padding 100ms cubic-bezier(0.4, 0, 0.6, 1) 0ms",padding:o?"32px 144px 0px 24px":"72px 16px 0px"},className:p.cls("cursor-pointer"),children:r.jsx(p.Tooltip,{title:"Home",sideOffset:20,side:"right",children:r.jsx(ge.Link,{to:t.basePath,children:e?r.jsx("img",{src:e,alt:"Logo",className:p.cls("max-w-full max-h-full",o??"w-[112px] h-[112px]")}):r.jsx(uo,{})})})})}const Fc=d.memo(function({homePage:t=r.jsx(ba,{}),customRoutes:o}){const n=ge.useLocation(),i=pe();if(!i)return r.jsx(r.Fragment,{});const a=n.state,s=a&&a.base_location?a.base_location:n,l=[];i.views&&i.views.forEach(m=>{Array.isArray(m.path)?l.push(...m.path.map(h=>fr(h,m))):l.push(fr(m.path,m))}),i.adminViews&&i.adminViews.forEach(m=>{Array.isArray(m.path)?l.push(...m.path.map(h=>fr(h,m))):l.push(fr(m.path,m))});const u=[...i.collections??[]].sort((m,h)=>h.path.length-m.path.length).map(m=>{const h=i.buildUrlCollectionPath(m.id??m.path);return r.jsx(ge.Route,{path:h+"/*",element:r.jsx(ae,{children:r.jsx(po,{isSubCollection:!1,parentCollectionIds:[],fullPath:m.id??m.path,...m,Actions:Bt(m.Actions)},`collection_view_${m.id??m.path}`)})},`navigation_${m.id??m.path}`)}),f=r.jsx(ge.Route,{path:"/",element:t}),g=r.jsx(ge.Route,{path:"*",element:r.jsx(va,{})});return r.jsxs(ge.Routes,{location:s,children:[u,l,f,g,o]})}),fr=(e,t)=>r.jsx(ge.Route,{path:e,element:t.view},"navigation_view_"+e);function Wa({children:e,className:t,style:o}){const n=e??r.jsx(Ua,{className:t,style:o});return r.jsx(r.Fragment,{children:n})}Wa.componentType="Drawer";function qa({children:e,...t}){const o=e??r.jsx(ka,{...t});return r.jsx(r.Fragment,{children:o})}qa.componentType="AppBar",w.AppBar=qa,w.AppContext=fo,w.ArrayContainer=mo,w.ArrayContainerItem=ho,w.ArrayCustomShapedFieldBinding=Da,w.ArrayEnumPreview=jr,w.ArrayItemOptions=_a,w.ArrayOfMapsPreview=bs,w.ArrayOfReferencesFieldBinding=Ca,w.ArrayOfReferencesPreview=Mn,w.ArrayOfStorageComponentsPreview=On,w.ArrayOfStringsPreview=zn,w.ArrayOneOfPreview=Vn,w.ArrayPropertyEnumPreview=Ur,w.ArrayPropertyPreview=Lr,w.AsyncPreviewComponent=ys,w.AuthControllerContext=hr,w.BlockFieldBinding=Pa,w.BooleanPreview=Ln,w.COLLECTION_PATH_SEPARATOR=Ho,w.CircularProgressCenter=rr,w.DEFAULT_FIELD_CONFIGS=ir,w.DRAWER_WIDTH=La,w.DatePreview=Yn,w.DateTimeFieldBinding=Ba,w.DefaultAppBar=ka,w.DefaultDrawer=Ua,w.DefaultHomePage=ba,w.DeleteConfirmationDialog=Il,w.Drawer=Wa,w.DrawerLogo=$a,w.DrawerNavigationItem=ja,w.EmptyValue=et,w.EntityCollectionRowActions=er,w.EntityCollectionTable=ro,w.EntityCollectionView=po,w.EntityCollectionViewActions=ya,w.EntityForm=Ma,w.EntityReference=Ar,w.EntityView=Wr,w.EnumValuesChip=Ie,w.ErrorBoundary=ae,w.ErrorView=ye,w.FieldCaption=Ql,w.FieldHelperText=xe,w.FireCMS=xc,w.FireCMSLogo=uo,w.FormikArrayContainer=ar,w.GeoPoint=br,w.IconForView=Ht,w.ImagePreview=Fn,w.KeyValueFieldBinding=Fa,w.KeyValuePreview=$r,w.LabelWithIcon=Ee,w.MapFieldBinding=Ia,w.MapPropertyPreview=Gn,w.MarkdownFieldBinding=Ta,w.ModeControllerContext=mr,w.ModeControllerProvider=si,w.MultiSelectBinding=Ao,w.NavigationCard=ha,w.NavigationCardBinding=Aa,w.NavigationGroup=lo,w.NavigationRoutes=Fc,w.NotFoundPage=va,w.NumberPropertyPreview=jn,w.PropertyConfigBadge=Sl,w.PropertyFieldBinding=ot,w.PropertyPreview=we,w.PropertyTableCell=ea,w.ReadOnlyFieldBinding=yo,w.ReferenceFieldBinding=Sa,w.ReferencePreview=Oe,w.ReferenceSelectionTable=ma,w.ReferenceWidget=Pl,w.RepeatFieldBinding=Na,w.Scaffold=Bc,w.SearchIconsView=Dl,w.SelectFieldBinding=go,w.SelectableTable=da,w.SelectableTableContext=Zr,w.SideDialogs=fc,w.SkeletonPropertyComponent=tt,w.SmallNavigationCard=ga,w.SnackbarProvider=ai,w.StorageThumbnail=Nn,w.StorageThumbnailInternal=Tn,w.StorageUploadFieldBinding=bo,w.StringPropertyPreview=Yr,w.SwitchFieldBinding=Ea,w.TextFieldBinding=At,w.UrlComponentPreview=xt,w.Vector=di,w.VirtualTable=aa,w.addInitialSlash=li,w.applyPermissionsFunctionIfEmpty=Wo,w.archiveEntityAction=ul,w.buildAdditionalFieldDelegate=Mi,w.buildCollection=Ii,w.buildEntityCallbacks=Qi,w.buildEnumLabel=Uo,w.buildEnumValueConfig=Di,w.buildEnumValues=Ti,w.buildFieldConfig=Oi,w.buildIdColumn=Zs,w.buildProperties=Ni,w.buildPropertiesOrBuilder=Pi,w.buildProperty=Fi,w.canCreateEntity=ct,w.canDeleteEntity=$t,w.canEditEntity=Fr,w.copyEntityAction=io,w.defaultDateFormat=qo,w.deleteEntityAction=so,w.deleteEntityWithCallbacks=wn,w.editEntityAction=fa,w.enumToObjectEntries=We,w.flattenObject=Pr,w.fullPathToCollectionSegments=Sr,w.getArrayValuesCount=rn,w.getBracketNotation=Ci,w.getCollectionByPathOrId=Dt,w.getCollectionPathsCombinations=Qt,w.getColorForProperty=_i,w.getColorScheme=jo,w.getColumnKeysForProperty=tr,w.getDefaultFieldConfig=Va,w.getDefaultFieldId=sr,w.getDefaultPropertiesOrder=xi,w.getDefaultValueFor=zt,w.getDefaultValueForDataType=_r,w.getDefaultValuesFor=vt,w.getEntityImagePreviewPropertyKey=tn,w.getEntityPreviewKeys=en,w.getEntityTitlePropertyKey=Nr,w.getFieldConfig=It,w.getFieldId=Co,w.getHashValue=wr,w.getIcon=Ro,w.getIconForProperty=Ce,w.getIconForWidget=jt,w.getIdIcon=ki,w.getLabelOrConfigFrom=Gt,w.getLastSegment=ci,w.getPropertiesWithPropertiesOrder=Ko,w.getPropertyInPath=Re,w.getRandomId=St,w.getReferenceFrom=Le,w.getResolvedPropertyInPath=Ir,w.getSidePanelKey=Ji,w.getValueInPath=Ye,w.hydrateRegExp=Zo,w.iconSynonyms=Wt,w.iconsSearch=qt,w.isDefaultFieldConfigId=za,w.isEmptyObject=kr,w.isEnumValueDisabled=fi,w.isHidden=wt,w.isObject=Mt,w.isPropertyBuilder=_e,w.isReadOnly=st,w.isReferenceProperty=Xo,w.isValidRegExp=vi,w.joinCollectionLists=an,w.makePropertiesEditable=on,w.makePropertiesNonEditable=nn,w.mergeCollection=sn,w.mergeDeep=De,w.openWebsiteAction=fl,w.pick=Go,w.plural=Bi,w.printChanged=Dr,w.propertiesToColumns=oa,w.randomColor=bi,w.randomString=lt,w.removeFunctions=yr,w.removeInPath=pi,w.removeInitialAndTrailingSlashes=fe,w.removeInitialSlash=zo,w.removePropsIfExisting=Yo,w.removeTrailingSlash=Vo,w.removeUndefined=vr,w.renderSkeletonCaptionText=ps,w.renderSkeletonIcon=Gr,w.renderSkeletonImageThumbnail=Vr,w.renderSkeletonText=je,w.resolveArrayProperty=Xe,w.resolveCollection=Ne,w.resolveCollectionPathIds=gr,w.resolveDefaultSelectedView=Er,w.resolveEntityView=Bo,w.resolveEnumValues=sc,w.resolveNavigationFrom=vn,w.resolvePermissions=kt,w.resolveProperties=xo,w.resolveProperty=Pe,w.resolvePropertyEnum=Eo,w.sanitizeData=ui,w.saveEntityWithCallbacks=Or,w.segmentsToStrippedPath=Jo,w.serializeRegExp=wi,w.singular=Si,w.slugify=Yt,w.sortProperties=xr,w.stripCollectionPath=Br,w.toKebabCase=hi,w.toSnakeCase=Ai,w.traverseValueProperty=Vt,w.traverseValuesProperties=Cr,w.unslugify=yi,w.updateDateAutoValues=Lo,w.useApp=nr,w.useAuthController=qe,w.useBrowserTitleAndIcon=$i,w.useBuildLocalConfigurationPersistence=Ki,w.useBuildModeController=Ri,w.useBuildNavigationController=Hi,w.useClearRestoreValue=Te,w.useClipboard=_n,w.useCollectionFetch=Gi,w.useColumnIds=Rr,w.useCustomizationController=ne,w.useDataSource=Qe,w.useDataSourceEntityCollectionTableController=oo,w.useDebouncedCallback=Lt,w.useDebouncedData=pa,w.useDialogsController=An,w.useEntityFetch=Mr,w.useFireCMSContext=Ae,w.useLargeLayout=Me,w.useModeController=kn,w.useNavigationController=pe,w.useReferenceDialog=ft,w.useResolvedNavigationFrom=Yi,w.useSelectableTableController=Rn,w.useSelectionController=no,w.useSideDialogContext=dr,w.useSideDialogsController=_t,w.useSideEntityController=He,w.useSnackbarController=Je,w.useStorageSource=dt,w.useTableSearchHelper=ao,w.useTraceUpdate=zi,w.useValidateAuthenticator=es,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
588
+ `;function Da({propertyKey:e,value:t,error:o,showError:n,isSubmitting:i,setValue:a,tableMode:s,property:l,includeDescription:c,underlyingValueHasChanged:u,context:f,disabled:g}){if(!Array.isArray(l.resolvedProperties))throw Error("ArrayCustomShapedFieldBinding misconfiguration. Property `of` not set");const m=l.expanded===void 0?!0:l.expanded;Te({property:l,value:t,setValue:a});const h=r.jsx(Ee,{icon:Ce(l,"small"),required:l.validation?.required,className:"text-text-secondary dark:text-text-secondary-dark",title:l.name}),A=l.resolvedProperties.map((y,b)=>{const k={propertyKey:`${e}[${b}]`,disabled:g,property:y,includeDescription:c,underlyingValueHasChanged:u,context:f,tableMode:!1,partOfArray:!0,partOfBlock:!1,autoFocus:!1};return r.jsx("div",{className:"pb-4",children:r.jsx(ot,{...k})},`custom_shaped_array_${b}`)});return r.jsxs(r.Fragment,{children:[!s&&r.jsx(p.ExpandablePanel,{initiallyExpanded:m,title:h,className:"px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2",children:A}),s&&A,r.jsx(xe,{includeDescription:c,showError:n,error:o,disabled:g,property:l})]})}const Rl=({containerRef:e})=>{const{isSubmitting:t,isValidating:o,errors:n}=ke.useFormex();return d.useEffect(()=>{const i=Object.keys(n);if(i.length>0&&t&&!o){const a=e?.current?.querySelector(`#form_field_${i[0]}`);if(a&&e?.current){const s=Qa(e.current);if(s){const c=a.getBoundingClientRect().top;s.scrollTo({top:s.scrollTop+c-196,behavior:"smooth"})}const l=a.querySelector("input");l&&l.focus()}}},[t,o,n,e]),null},ec=e=>{const t=e&&e.scrollHeight>e.clientHeight,o=e?window.getComputedStyle(e).overflowY:null,n=o&&o.indexOf("hidden")!==-1;return t&&!n},Qa=e=>!e||e===document.body?document.body:ec(e)?e:Qa(e.parentNode);function tc({customId:e,entityId:t,status:o,onChange:n,error:i,entity:a,loading:s}){const{errors:l}=ke.useFormex(),c=o==="existing"||!e,u=o!=="existing"&&!e,f=d.useMemo(()=>{if(!(!e||typeof e=="boolean"||e==="optional"))return We(e)},[e]),g=Je(),{copy:m}=_n({onSuccess:y=>g.open({type:"success",message:`Copied ${y}`})}),h=ne(),A={label:u?"ID is set automatically":"ID",disabled:c||s,name:"id",value:(a&&o==="existing"?a.id:t)??"",endAdornment:s?r.jsx(p.CircularProgress,{size:"small"}):a?r.jsxs(r.Fragment,{children:[r.jsx(p.Tooltip,{title:"Copy",children:r.jsx(p.IconButton,{onClick:y=>m(a.id),"aria-label":"copy-id",children:r.jsx(p.ContentCopyIcon,{size:"small"})})}),h?.entityLinkBuilder&&r.jsx(p.Tooltip,{title:"Open in the console",children:r.jsx(p.IconButton,{component:"a",href:h.entityLinkBuilder({entity:a}),rel:"noopener noreferrer",target:"_blank",onClick:y=>y.stopPropagation(),"aria-label":"go-to-datasource",children:r.jsx(p.OpenInNewIcon,{size:"small"})})})]}):void 0};return r.jsxs(r.Fragment,{children:[f&&r.jsx(p.Select,{error:i,onValueChange:y=>n(y),...A,renderValue:y=>{const b=f.find(k=>k.id===y);return b?`${b.id} - ${b.label}`:y},children:f.map(y=>r.jsx(p.SelectItem,{value:String(y.id),children:r.jsx(Ie,{enumKey:y.id,enumValues:f,size:"medium"})},y.id))}),!f&&r.jsx(p.TextField,{...A,error:i,placeholder:e==="optional"?"Autogenerated ID, it can be manually changed":o==="new"||o==="copy"?"ID of the new document":"ID of the document",onChange:y=>{let b=y.target.value;return b&&(b=b.trim()),n(b.length?b:void 0)}}),l.id&&r.jsx(p.Typography,{variant:"caption",className:"ml-3.5 text-red-500 dark:text-red-500",children:l.id})]})}function rc({propertyId:e}){const[t,o]=d.useState(!1);return r.jsxs("div",{className:"flex flex-row gap-2 items-center justify-center text-white",children:[r.jsxs("div",{children:[r.jsx(p.Typography,{variant:"caption",className:"min-w-20 text-slate-400",color:"disabled",children:t?"Copied":"Property ID"}),r.jsx(p.Typography,{variant:"caption",className:"text-white",children:r.jsx("code",{children:e})})]}),r.jsx(p.IconButton,{size:"small",children:r.jsx(p.ContentCopyIcon,{size:"smallest",className:"text-white",onClick:d.useCallback(()=>{navigator.clipboard.writeText(e),o(!0),setTimeout(()=>o(!1),2e3)},[e])})})]})}const Ma=d.memo(oc,(e,t)=>e.status===t.status&&e.path===t.path&&L(e.entity?.values,t.entity?.values));function Oa(e,t,o){const n=e.properties;if((t==="existing"||t==="copy")&&o)return o.values??vt(n);if(t==="new")return vt(n);throw console.error({status:t,entity:o}),new Error("Form has not been initialised with the correct parameters")}function oc({status:e,path:t,collection:o,entity:n,onEntitySaveRequested:i,onDiscard:a,onModified:s,onValuesChanged:l,onIdChange:c,onFormContextChange:u,hideId:f,autoSave:g,onIdUpdateError:m}){const h=ut(),A=ne(),y=Ae(),b=Qe(o),k=A.plugins,v=d.useMemo(()=>Ne({collection:o,path:t,values:n?.values,fields:A.propertyConfigs}),[n?.values,t,A.propertyConfigs]),_=(e==="new"||e==="copy")&&!!v.customId&&v.customId!=="optional",E=d.useMemo(()=>e==="new"||e==="copy"?_?void 0:b.generateEntityId(t):n?.id,[]),C=d.useRef(!1),B=d.useRef(Oa(v,e,n)),[x,S]=d.useState(E),[N,I]=d.useState(!1),[P,D]=d.useState(),[G,R]=d.useState(!1),[K,W]=d.useState(n?.values??B.current),j=te=>i({collection:re,path:t,entityId:x,values:te,previousValues:n?.values,closeAfterSave:C.current,autoSave:g??!1}).then(O=>{const ie=e==="new"?"new_entity_saved":e==="copy"?"entity_copied":e==="existing"?"entity_edited":"unmapped_event";h.onAnalyticsEvent?.(ie,{path:t})}).catch(O=>{console.error(O),D(O)}).finally(()=>{C.current=!1}),M=(te,O)=>{if(_&&!x){console.error("Missing custom Id"),I(!0),O.setSubmitting(!1);return}if(D(void 0),I(!1),e==="existing"){if(!n?.id)throw Error("Form misconfiguration when saving, no id for existing entity")}else if(e==="new"||e==="copy"){if(o.customId&&o.customId!=="optional"&&!x)throw Error("Form misconfiguration when saving, entityId should be set")}else throw Error("New FormType added, check EntityForm");return j(te)?.then(ie=>{O.resetForm({values:te,submitCount:0,touched:{}})}).finally(()=>{O.setSubmitting(!1)})},H=ke.useCreateFormex({initialValues:B.current,onSubmit:M,validation:te=>V?.validate(te,{abortEarly:!1}).then(()=>({})).catch(O=>{const ie={};return O.inner.forEach(me=>{ie[me.path]=me.message}),ac(O)})});d.useEffect(()=>{B.current=Oa(v,e,n);const te=H.initialValues;!H.isSubmitting&&te&&e==="existing"?Z(Object.entries(re.properties).map(([O,ie])=>{if(wt(ie))return{};const me=te[O],ue=B.current[O];return L(me,ue)?{}:{[O]:ue}}).reduce((O,ie)=>({...O,...ie}),{})):Z({})},[n,v,e]);const J=te=>{const O=H.initialValues;W(te),l&&l(te),g&&te&&!L(te,O)&&j(te)};d.useEffect(()=>{x&&c&&c(x)},[x,c]);const re=Ne({collection:o,path:t,entityId:x,values:K,previousValues:H.initialValues,fields:A.propertyConfigs}),oe=Nr(re,A.propertyConfigs),U=K&&oe?Ye(K,oe):void 0,X=o.callbacks?.onIdUpdate,Q=d.useCallback(async()=>{if(X&&K&&(e==="new"||e==="copy")){R(!0);try{const te=await X({collection:re,path:t,entityId:x,values:K,context:y});S(te)}catch(te){m&&m(te),console.error(te)}R(!1)}},[x,K,e]);d.useEffect(()=>{Q()},[Q]);const[ee,Z]=d.useState({}),$=d.useCallback(({name:te,value:O,property:ie})=>b.checkUniqueField(t,te,O,x),[b,t,x]),V=d.useMemo(()=>x?Kn(x,re.properties,$):void 0,[x,re.properties,$]),z=qe(),F=d.useCallback(({entity:te,customEntityActions:O})=>{const ie=ct(o,z,t,null),me=te?$t(o,z,t,te):!0,ue=[];return ie&&ue.push(io),me&&ue.push(so),O&&ue.push(...O),ue},[z,o,t]),T=[],le={setFieldValue:d.useCallback(H.setFieldValue,[]),values:H.values,collection:re,entityId:x,path:t,save:j},ve=d.useRef(null);if(d.useEffect(()=>{u&&!ic(ve.current??void 0,le)&&(u(le),ve.current=le)},[le,u]),k&&o){const te={entityId:x,path:t,status:e,collection:o,context:y,currentEntityId:x,formContext:le};T.push(...k.map((O,ie)=>O.form?.Actions?r.jsx(O.form.Actions,{...te},`actions_${O.key}`):null).filter(Boolean))}return r.jsx(ke.Formex,{value:H,children:r.jsxs("div",{className:"h-full overflow-auto",children:[T.length>0&&r.jsx("div",{className:p.cls("w-full flex justify-end items-center sticky top-0 right-0 left-0 z-10 bg-opacity-60 bg-slate-200 dark:bg-opacity-60 dark:bg-slate-800 backdrop-blur-md"),children:T}),r.jsxs("div",{className:"pt-12 pb-16 pl-8 pr-8 md:pl-10 md:pr-10",children:[r.jsxs("div",{className:`w-full py-2 flex flex-col items-start mt-${4+(T?8:0)} lg:mt-${8+(T?8:0)} mb-8`,children:[r.jsx(p.Typography,{className:"mt-4 flex-grow line-clamp-1 "+o.hideIdFromForm?"mb-2":"mb-0",variant:"h4",children:U??o.singularName??o.name}),r.jsx(p.Alert,{color:"base",className:"w-full",size:"small",children:r.jsxs("code",{className:"text-xs select-all",children:[t,"/",x]})})]}),!f&&r.jsx(tc,{customId:o.customId,entityId:x,status:e,onChange:S,error:N,loading:G,entity:n}),x&&r.jsx(nc,{...H,initialValues:H.initialValues,onModified:s,onDiscard:a,onValuesChanged:J,underlyingChanges:ee,entity:n,resolvedCollection:re,formContext:le,status:e,savingError:P,closeAfterSaveRef:C,autoSave:g,entityActions:F({entity:n,customEntityActions:o.entityActions})})]})]})})}function nc(e){const{values:t,onDiscard:o,onModified:n,onValuesChanged:i,underlyingChanges:a,formContext:s,entity:l,touched:c,setFieldValue:u,resolvedCollection:f,isSubmitting:g,status:m,handleSubmit:h,resetForm:A,savingError:y,dirty:b,closeAfterSaveRef:k,autoSave:v,entityActions:_}=e,E=Ae(),C=_.filter(P=>P.includeInForm===void 0||P.includeInForm),B=He(),x=b;d.useEffect(()=>{n&&n(x),i&&i(t)},[x,t]),d.useEffect(()=>{!v&&!g&&a&&l&&Object.entries(a).forEach(([P,D])=>{const G=t[P];!L(D,G)&&!c[P]&&(console.debug("Updated value from the datasource:",P,D),u(P,D!==void 0?D:null))})},[g,v,a,l,t,c,u]);const S=r.jsx("div",{className:"flex flex-col gap-8",children:(f.propertiesOrder??Object.keys(f.properties)).map(P=>{const D=f.properties[P];if(!D)return console.warn(`Property ${P} not found in collection ${f.name}`),null;const G=!!a&&Object.keys(a).includes(P)&&!!c[P],R=!v&&g||st(D)||!!D.disabled;if(wt(D))return null;const W={propertyKey:P,disabled:R,property:D,includeDescription:D.description||D.longDescription,underlyingValueHasChanged:G&&!v,context:s,tableMode:!1,partOfArray:!1,partOfBlock:!1,autoFocus:!1};return r.jsx("div",{id:`form_field_${P}`,children:r.jsx(ae,{children:r.jsx(p.Tooltip,{title:r.jsx(rc,{propertyId:P}),delayDuration:800,side:"left",align:"start",sideOffset:16,children:r.jsx(ot,{...W})})})},`field_${f.name}_${P}`)}).filter(Boolean)}),N=g||!x&&m==="existing",I=d.useRef(null);return r.jsxs("form",{onSubmit:h,onReset:()=>(console.debug("Resetting form"),A(),o&&o()),noValidate:!0,children:[r.jsxs("div",{className:"mt-12",ref:I,children:[S,r.jsx(Rl,{containerRef:I})]}),r.jsx("div",{className:"h-14"}),!v&&r.jsxs(p.DialogActions,{position:"absolute",children:[y&&r.jsx("div",{className:"text-right",children:r.jsx(p.Typography,{color:"error",children:y.message})}),l&&C.length>0&&r.jsx("div",{className:"flex-grow flex overflow-auto no-scrollbar",children:C.map(P=>r.jsx(p.IconButton,{color:"primary",onClick:D=>{D.stopPropagation(),l&&P.onClick({entity:l,fullPath:f.path,collection:f,context:E,sideEntityController:B})},children:P.icon},P.name))}),g&&r.jsx(p.CircularProgress,{size:"small"}),r.jsx(p.Button,{variant:"text",disabled:N||g,type:"reset",children:m==="existing"?"Discard":"Clear"}),r.jsxs(p.Button,{variant:"text",color:"primary",type:"submit",disabled:N||g,onClick:()=>{k.current=!1},children:[m==="existing"&&"Save",m==="copy"&&"Create copy",m==="new"&&"Create"]}),r.jsxs(p.Button,{variant:"filled",color:"primary",type:"submit",disabled:N||g,onClick:()=>{k.current=!0},children:[m==="existing"&&"Save and close",m==="copy"&&"Create copy and close",m==="new"&&"Create and close"]})]})]})}function ac(e){let t={};if(e.inner){if(e.inner.length===0)return ke.setIn(t,e.path,e.message);for(const o of e.inner)ke.getIn(t,o.path)||(t=ke.setIn(t,o.path,o.message))}return t}function ic(e,t){return e?.path===t?.path&&e?.entityId===t?.entityId&&L(e?.values,t?.values)&&L(e?.collection,t?.collection)}function za(e){return Object.keys(ir).includes(e)}const ir={text_field:{key:"text_field",name:"Text field",description:"Simple short text",Icon:p.ShortTextIcon,color:"#2d7ff9",property:{dataType:"string",Field:At}},multiline:{key:"multiline",name:"Multiline",description:"Text with multiple lines",Icon:p.SubjectIcon,color:"#2d7ff9",property:{dataType:"string",multiline:!0,Field:At}},markdown:{key:"markdown",name:"Markdown",description:"Text with advanced markdown syntax",Icon:p.FormatQuoteIcon,color:"#2d7ff9",property:{dataType:"string",markdown:!0,Field:Ta}},url:{key:"url",name:"Url",description:"Text with URL validation",Icon:p.HttpIcon,color:"#154fb3",property:{dataType:"string",url:!0,Field:At}},email:{key:"email",name:"Email",description:"Text with email validation",Icon:p.EmailIcon,color:"#154fb3",property:{dataType:"string",email:!0,Field:At}},switch:{key:"switch",name:"Switch",description:"Boolean true or false field (or yes or no, 0 or 1...)",Icon:p.FlagIcon,color:"#20d9d2",property:{dataType:"boolean",Field:Ea}},select:{key:"select",name:"Select/enum",description:"Select one text value from within an enumeration",Icon:p.ListIcon,color:"#4223c9",property:{dataType:"string",enumValues:[],Field:go}},multi_select:{key:"multi_select",name:"Multi select",description:"Select multiple text values from within an enumeration",Icon:p.ListAltIcon,color:"#4223c9",property:{dataType:"array",of:{dataType:"string",enumValues:[]},Field:Ao}},number_input:{key:"number_input",name:"Number input",description:"Simple number field with validation",Icon:p.NumbersIcon,color:"#bec920",property:{dataType:"number",Field:At}},number_select:{key:"number_select",name:"Number select",description:"Select a number value from within an enumeration",Icon:p.FormatListNumberedIcon,color:"#bec920",property:{dataType:"number",enumValues:[],Field:go}},multi_number_select:{key:"multi_number_select",name:"Multiple number select",description:"Select multiple number values from within an enumeration",Icon:p.FormatListNumberedIcon,color:"#bec920",property:{dataType:"array",of:{dataType:"number",enumValues:[]},Field:Ao}},file_upload:{key:"file_upload",name:"File upload",description:"Input for uploading single files",Icon:p.UploadFileIcon,color:"#f92d9a",property:{dataType:"string",storage:{storagePath:"{path}"},Field:bo}},multi_file_upload:{key:"multi_file_upload",name:"Multiple file upload",description:"Input for uploading multiple files",Icon:p.DriveFolderUploadIcon,color:"#f92d9a",property:{dataType:"array",of:{dataType:"string",storage:{storagePath:"{path}"}},Field:bo}},reference:{key:"reference",name:"Reference",description:"The value refers to a different collection",Icon:p.LinkIcon,color:"#ff0042",property:{dataType:"reference",Field:Sa}},multi_references:{key:"multi_references",name:"Multiple references",description:"Multiple values that refer to a different collection",Icon:p.AddLinkIcon,color:"#ff0042",property:{dataType:"array",of:{dataType:"reference"},Field:Ca}},date_time:{key:"date_time",name:"Date/time",description:"A date time select field",Icon:p.ScheduleIcon,color:"#8b46ff",property:{dataType:"date",Field:Ba}},group:{key:"group",name:"Group",description:"Group of multiple fields",Icon:p.BallotIcon,color:"#ff9408",property:{dataType:"map",properties:{},Field:Ia}},key_value:{key:"key_value",name:"Key-value",description:"Flexible field that allows the user to add multiple key-value pairs",Icon:p.BallotIcon,color:"#ff9408",property:{dataType:"map",keyValue:!0,Field:Fa}},repeat:{key:"repeat",name:"Repeat/list",description:"A field that gets repeated multiple times (e.g. multiple text fields)",Icon:p.RepeatIcon,color:"#ff9408",property:{dataType:"array",of:{dataType:"string"},Field:Na}},custom_array:{key:"custom_array",name:"Custom array",description:"A field that saved its value as an array of custom objects",Icon:p.RepeatIcon,color:"#ff9408",property:{dataType:"array",of:[],Field:Da}},block:{key:"block",name:"Block",description:"A complex field that allows the user to compose different fields together, with a key->value format",Icon:p.ViewStreamIcon,color:"#ff9408",property:{dataType:"array",oneOf:{properties:{}},Field:Pa}}};function Va(e){const t=sr(e);if(!t){console.error("No field id found for property",e);return}return ir[t]}function It(e,t){const o=Co(e),n=sr(e);if(!n){console.error("No field id found for property",e);return}const i=ir[n],a=o?t[o]:void 0;return De(i??{},a??{})}function sr(e){if(e.dataType==="string")return e.multiline?"multiline":e.markdown?"markdown":e.storage?"file_upload":e.url?"url":e.email?"email":e.enumValues?"select":"text_field";if(e.dataType==="number")return e.enumValues?"number_select":"number_input";if(e.dataType==="map")return e.keyValue?"key_value":"group";if(e.dataType==="array"){const t=e.of;return e.oneOf?"block":Array.isArray(t)?"custom_array":_e(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 Co(e){return e.propertyConfig?e.propertyConfig:sr(e)}const Ne=({collection:e,path:t,entityId:o,values:n,previousValues:i,userConfigPersistence:a,fields:s,ignoreMissingFields:l=!1})=>{const c=a?.getCollectionConfig(t),u=Ye(c,"properties"),f=vt(e.properties),g=n??f,m=i??n??f,h=Object.entries(e.properties).map(([b,k])=>{const v=Pe({propertyKey:b,propertyOrBuilder:k,values:g,previousValues:m,path:t,entityId:o,fields:s,ignoreMissingFields:l});return v?{[b]:v}:{}}).filter(b=>b!==null).reduce((b,k)=>({...b,...k}),{}),A=De(h,u),y=Object.entries(A).filter(([b,k])=>!!k?.dataType).map(([b,k])=>({[b]:k})).reduce((b,k)=>({...b,...k}),{});return{...e,properties:y,originalCollection:e}};function Pe({propertyOrBuilder:e,fromBuilder:t=!1,ignoreMissingFields:o=!1,...n}){if(typeof e=="object"&&"resolved"in e)return e;let i=null;if(e)if(_e(e)){const a=n.path;if(!a)throw Error("Trying to resolve a property builder without specifying the entity path");const s=n.propertyKey?ke.getIn(n.values,n.propertyKey):void 0,l=e({...n,path:a,propertyValue:s,values:n.values??{},previousValues:n.previousValues??n.values??{}});if(!l)return null;i=Pe({...n,propertyOrBuilder:l,fromBuilder:!0,ignoreMissingFields:o})}else{const a=e;if(a.dataType==="map"&&a.properties){const s=xo({ignoreMissingFields:o,...n,properties:a.properties});i={...a,resolved:!0,fromBuilder:t,properties:s}}else a.dataType==="array"?i=Xe({property:a,fromBuilder:t,ignoreMissingFields:o,...n}):(a.dataType==="string"||a.dataType==="number")&&a.enumValues&&(i=Eo(a,t))}else return null;if(i||(i={...e,resolved:!0,fromBuilder:t}),i.propertyConfig&&!za(i.propertyConfig)){const a=n.fields;if(!a&&!o)throw Error(`Trying to resolve a property with key '${i.propertyConfig}' that inherits from a custom property config but no custom property configs were provided. Use the property 'propertyConfigs' in your app config to provide them`);const s=a?.[i.propertyConfig];if(!s)return console.warn(`Trying to resolve a property with key '${i.propertyConfig}' that inherits from a custom property config but no custom property config with that key was found. Check the 'propertyConfigs' in your app config`),console.warn("Available property configs",a),null;if(s.property){const l=s.property;"propertyConfig"in l&&delete l.propertyConfig;const c=Pe({propertyOrBuilder:l,ignoreMissingFields:o,...n});c&&(i=De(c,i))}}return i?{...i,resolved:!0}:null}function Xe({propertyKey:e,property:t,ignoreMissingFields:o=!1,...n}){const i=e?ke.getIn(n.values,e):void 0;if(t.of){if(Array.isArray(t.of))return{...t,resolved:!0,fromBuilder:n.fromBuilder,resolvedProperties:t.of.map((a,s)=>Pe({propertyKey:`${e}.${s}`,propertyOrBuilder:a,ignoreMissingFields:o,...n,index:s}))};{const a=t.of,s=Array.isArray(i)?i.map((c,u)=>Pe({propertyKey:`${e}.${u}`,propertyOrBuilder:a,ignoreMissingFields:o,...n,index:u})).filter(c=>!!c):[],l=Pe({propertyKey:`${e}`,propertyOrBuilder:a,ignoreMissingFields:o,...n});if(!l&&!o)throw Error("When using a property builder as the 'of' prop of an ArrayProperty, you must return a valid child property");return{...t,resolved:!0,fromBuilder:n.fromBuilder,of:l,resolvedProperties:s}}}else if(t.oneOf){const a=t.oneOf?.typeField??yt,s=Array.isArray(i)?i.map((c,u)=>{const f=c&&c[a],g=t.oneOf?.properties[f];return!f||!g?null:Pe({propertyKey:`${e}.${u}`,propertyOrBuilder:g,ignoreMissingFields:o,...n})}).filter(c=>!!c):[],l=xo({properties:t.oneOf.properties,ignoreMissingFields:o,...n});return{...t,resolved:!0,oneOf:{...t.oneOf,properties:l},fromBuilder:n.fromBuilder,resolvedProperties:s}}else{if(t.Field)return{...t,resolved:!0,fromBuilder:n.fromBuilder};throw Error("The array property needs to declare an 'of' or a 'oneOf' property, or provide a custom `Field`")}}function xo({properties:e,ignoreMissingFields:t,...o}){return Object.entries(e).map(([n,i])=>{const a=Pe({propertyKey:n,propertyOrBuilder:i,ignoreMissingFields:t,...o});return a?{[n]:a}:{}}).filter(n=>n!==null).reduce((n,i)=>({...n,...i}),{})}function Eo(e,t){return typeof e.enumValues=="object"?{...e,resolved:!0,enumValues:We(e.enumValues)?.filter(o=>o&&(o.id||o.id===0)&&o.label)??[],fromBuilder:t??!1}:e}function sc(e){return typeof e=="object"?Object.entries(e).map(([t,o])=>typeof o=="string"?{id:t,label:o}:o):Array.isArray(e)?e:void 0}function Bo(e,t){return typeof e=="string"?t?.find(o=>o.key===e):e}function So(e){const{path:t,collections:o=[],currentFullPath:n}=e,i=fe(t).split("/"),a=Qt(i),s=[];for(let l=0;l<a.length;l++){const c=a[l],u=o&&o.find(f=>f.id===c||f.path===c);if(u){const f=u.id??u.path,g=n&&n.length>0?n+"/"+f:f;s.push({type:"collection",path:g,collection:u});const m=fe(fe(t).replace(c,"")),h=m.length>0?m.split("/"):[];if(h.length>0){const A=h[0],y=g+"/"+A;if(s.push({type:"entity",entityId:A,path:g,parentCollection:u}),h.length>1){const b=h.slice(1).join("/");if(!u)throw Error("collection not found resolving path: "+u);const k=u.entityViews,v=k&&k.map(_=>Bo(_,e.contextEntityViews)).filter(Boolean).find(_=>_.key===b);if(v){const _=n&&n.length>0?n+"/"+v.key:v.key;s.push({type:"custom_view",path:_,view:v})}else u.subcollections&&s.push(...So({path:b,collections:u.subcollections,currentFullPath:y,contextEntityViews:e.contextEntityViews}))}}break}}return s}const lc="100vw",cc="55vw",lr="768px",cr="main_##Q$SC^#S6";function dc({path:e,entityId:t,selectedSubPath:o,copy:n,collection:i,parentCollectionIds:a,onValuesAreModified:s,formWidth:l,onUpdate:c,onClose:u}){i.customId&&i.formAutoSave&&console.warn(`The collection ${i.path} has customId and formAutoSave enabled. This is not supported and formAutoSave will be ignored`);const[f,g]=d.useState(!1),[m,h]=d.useState(void 0);Lt(m,()=>{m&&F({entityId:U?.id,collection:i,path:e,values:m,closeAfterSave:!1})},!1,2e3);const A=Qe(i),y=dr(),b=He(),k=Je(),v=ne(),_=Ae(),E=qe(),[C,B]=d.useState(void 0),[x,S]=d.useState(n?"copy":t?"existing":"new"),N=d.useRef(void 0),I=N.current,P=(i.subcollections??[]).filter(Y=>!Y.hideFromNavigation),D=P?.length??0,G=i.entityViews,R=G?.length??0,K=i.formAutoSave&&!i.customId,W=R>0||D>0,j=o??Er(i?i.defaultSelectedView:void 0,{status:x,entityId:t}),M=d.useRef(j??cr),H=M.current===cr,{entity:J,dataLoading:re,dataLoadingError:oe}=Mr({path:e,entityId:t,collection:i,useCache:!1}),[U,X]=d.useState(J),[Q,ee]=d.useState(void 0);d.useEffect(()=>{J&&X(J)},[J]),d.useEffect(()=>{if(x==="new")ee(!1);else{const Y=U?Fr(i,E,e,U??null):!1;U&&ee(!Y)}},[E,U,x]);const Z=d.useCallback(Y=>{g(!1),k.open({type:"error",message:"Error before saving: "+Y?.message}),console.error(Y)},[k]),$=d.useCallback(Y=>{g(!1),k.open({type:"error",message:"Error after saving (entity is saved): "+Y?.message}),console.error(Y)},[k]),V=(Y,Be)=>{g(!1),K||k.open({type:"success",message:`${i.singularName??i.name}: Saved correctly`}),X(Y),S("existing"),s(!1),c&&c({entity:Y}),Be?(console.log("Closing side dialog"),y.setBlocked(!1),y.close(!0),u?.()):x!=="existing"&&b.replace({path:e,entityId:Y.id,selectedSubPath:M.current,updateUrl:!0,collection:i})},z=d.useCallback(Y=>{g(!1),k.open({type:"error",message:"Error saving: "+Y?.message}),console.error("Error saving entity",e,t),console.error(Y)},[t,e,k]),F=({values:Y,previousValues:Be,closeAfterSave:Se,entityId:$e,collection:Ft,path:Nt})=>(g(!0),Or({path:Nt,entityId:$e,values:Y,previousValues:Be,collection:Ft,status:x,dataSource:A,context:_,onSaveSuccess:Pt=>V(Pt,Se),onSaveFailure:z,onPreSaveHookError:Z,onSaveSuccessHookError:$}).then()),T=async({collection:Y,path:Be,entityId:Se,values:$e,previousValues:Ft,closeAfterSave:Nt,autoSave:Pt})=>{if(x)if(Pt)h($e);else return F({collection:Y,path:Be,entityId:Se,values:$e,previousValues:Ft,closeAfterSave:Nt})},le=G?G.map(Y=>Bo(Y,v.entityViews)).filter(Boolean):[],ve=G&&le.map((Y,Be)=>{if(!Y||M.current!==Y.key)return null;const Se=Y.Builder;return Se?r.jsx("div",{className:p.cls(p.defaultBorderMixin,"relative flex-grow w-full h-full overflow-auto "),role:"tabpanel",children:r.jsx(ae,{children:C&&r.jsx(Se,{collection:i,entity:U,modifiedValues:I??U?.values,formContext:C})})},`custom_view_${Y.key}`):(console.error("customView.Builder is not defined"),null)}).filter(Boolean),te=re&&!U||(!U||Q===void 0)&&(x==="existing"||x==="copy"),O=te||f,ie=P&&P.map((Y,Be)=>{const Se=Y.id??Y.path,$e=U?`${e}/${U?.id}/${fe(Se)}`:void 0;return M.current!==Se?null:r.jsxs("div",{className:"relative flex-grow h-full overflow-auto w-full",role:"tabpanel",children:[O&&r.jsx(rr,{}),!te&&(U&&$e?r.jsx(po,{fullPath:$e,parentCollectionIds:[...a,i.id],isSubCollection:!0,...Y}):r.jsx("div",{className:"flex items-center justify-center w-full h-full p-3",children:r.jsx(p.Typography,{variant:"label",children:"You need to save your entity before adding additional collections"})}))]},`subcol_${Se}`)}).filter(Boolean),me=d.useCallback(()=>{s(!1)},[]),ue=Y=>{M.current=Y,b.replace({path:e,entityId:t,selectedSubPath:Y===cr?void 0:Y,updateUrl:!0,collection:i})},he=d.useCallback(Y=>{N.current=Y},[]),ze=d.useCallback(Y=>{k.open({type:"error",message:"Error updating id, check the console"})},[]),Ve=d.useCallback(Y=>{X(Be=>Be?{...Be,id:Y}:void 0)},[]),Ge=Y=>{K||s(Y)};function Ue(){const Y=v.plugins;let Be=r.jsx(Ma,{status:x,path:e,collection:i,onEntitySaveRequested:T,onDiscard:me,onValuesChanged:he,onModified:Ge,entity:U,onIdChange:Ve,onFormContextChange:B,hideId:i.hideIdFromForm,autoSave:K,onIdUpdateError:ze});return Y&&Y.forEach(Se=>{Se.form?.provider&&(Be=r.jsx(Se.form.provider.Component,{status:x,path:e,collection:i,onDiscard:me,onValuesChanged:he,onModified:Ge,entity:U,context:_,formContext:C,...Se.form.provider.props,children:Be}))}),r.jsx(ae,{children:Be})}const nt=Q===void 0?r.jsx(r.Fragment,{}):Q?r.jsxs(r.Fragment,{children:[r.jsx(p.Typography,{className:"mt-16 mb-8 mx-8",variant:"h4",children:i.singularName??i.name}),r.jsx(Wr,{className:"px-12",entity:U,path:e,collection:i})]}):Ue(),Fo=P&&P.map(Y=>r.jsx(p.Tab,{className:"text-sm min-w-[140px]",value:Y.id,children:Y.name},`entity_detail_collection_tab_${Y.name}`)),No=le.map(Y=>r.jsx(p.Tab,{className:"text-sm min-w-[140px]",value:Y.key,children:Y.name},`entity_detail_collection_tab_${Y.name}`));return r.jsx("div",{className:"flex flex-col h-full w-full transition-width duration-250 ease-in-out",children:r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:p.cls(p.defaultBorderMixin,"no-scrollbar border-b pl-2 pr-2 pt-1 flex items-end overflow-scroll bg-gray-50 dark:bg-gray-950"),children:[r.jsx("div",{className:"pb-1 self-center",children:r.jsx(p.IconButton,{onClick:()=>(u?.(),y.close(!1)),size:"large",children:r.jsx(p.CloseIcon,{})})}),r.jsx("div",{className:"flex-grow"}),te&&r.jsx("div",{className:"self-center",children:r.jsx(p.CircularProgress,{size:"small"})}),r.jsxs(p.Tabs,{value:M.current,onValueChange:Y=>{ue(Y)},className:"pl-4 pr-4 pt-0",children:[r.jsx(p.Tab,{disabled:!W,value:cr,className:`${W?"":"hidden"} text-sm min-w-[140px]`,children:i.singularName??i.name}),No,Fo]})]}),r.jsxs("div",{className:"flex-grow h-full flex overflow-auto flex-row w-full ",style:{},children:[r.jsx("div",{role:"tabpanel",hidden:!H,id:`form_${e}`,className:" w-full",children:te?r.jsx(rr,{}):nt}),ve,ie]})]})})}function pc(e,t){const[o,n]=d.useState(),{navigator:i}=d.useContext(ge.UNSAFE_NavigationContext),a=ge.useNavigate(),s=()=>{n(void 0)},l=()=>{t(),n(void 0),a(-1)},c=d.useCallback(({action:u,location:f,retry:g})=>{switch(u){case"REPLACE":{g();return}case"POP":n(f)}},[]);return d.useEffect(()=>{if(!e||o||!("block"in i))return;const u=i.block(f=>{const g={...f,retry(){u(),f.retry()}};c(g)});return u},[i,c,e,o]),{navigationWasBlocked:!!o,handleCancel:s,handleOk:l}}function uc({open:e,handleOk:t,handleCancel:o,body:n,title:i}){return r.jsxs(p.Dialog,{open:e,onOpenChange:a=>a?o():t(),children:[r.jsxs(p.DialogContent,{children:[r.jsx(p.Typography,{variant:"h6",children:i}),n,r.jsx(p.Typography,{children:"Are you sure you want to leave this page?"})]}),r.jsxs(p.DialogActions,{children:[r.jsx(p.Button,{variant:"text",onClick:o,autoFocus:!0,children:" Cancel "}),r.jsx(p.Button,{onClick:t,children:" Ok "})]})]})}const Ga=d.createContext({width:"",blocked:!1,setBlocked:e=>{},setBlockedNavigationMessage:e=>{},close:()=>{}}),dr=()=>d.useContext(Ga);function fc(){const t=_t().sidePanels,o=[...t];return o.push(void 0),r.jsx(r.Fragment,{children:o.map((n,i)=>r.jsx(mc,{panel:n,offsetPosition:t.length-i-1},`side_dialog_${i}`))})}function mc({offsetPosition:e,panel:t}){const[o,n]=d.useState(!1),[i,a]=d.useState(!1),[s,l]=d.useState(),c=d.useRef(t?.width),u=c.current,f=_t(),{navigationWasBlocked:g,handleOk:m,handleCancel:h}=pc(i&&!o,()=>a(!1));d.useEffect(()=>{t&&(c.current=t.width)},[t]);const A=()=>{a(!1),n(!1),f.close(),t?.onClose?.()},y=()=>{n(!1)},b=k=>{i&&!k?n(!0):(f.close(),t?.onClose?.())};return r.jsxs(Ga.Provider,{value:{blocked:i,setBlocked:a,setBlockedNavigationMessage:l,width:u,close:b},children:[r.jsxs(p.Sheet,{open:!!t,onOpenChange:k=>!k&&b(),children:[t&&r.jsx("div",{className:"transform max-w-[100vw] lg:max-w-[95vw] flex flex-col h-full transition-all duration-250 ease-in-out bg-white dark:bg-gray-900 ",style:{width:t.width,transform:`translateX(-${e*200}px)`},children:r.jsx(ae,{children:t.component})}),!t&&r.jsx("div",{style:{width:u}})]}),r.jsx(uc,{open:g||o,handleOk:o?A:m,handleCancel:o?y:h,body:s})]})}function hc(e){const{blocked:t,setBlocked:o,setBlockedNavigationMessage:n}=dr(),i=pe(),a=d.useMemo(()=>i.getParentCollectionIds(e.path),[i,e.path]),s=d.useMemo(()=>{if(!e)return;let c=e.collection;const u=i.getCollection(e.path);if(u&&(c=u),!c)throw console.error("ERROR: No collection found in path `",e.path,"`. Entity id: ",e.entityId),Error("ERROR: No collection found in path `"+e.path+"`. Make sure you have defined a collection for this path in the root navigation.");return c},[i,e]);d.useEffect(()=>{function c(u){t&&s&&(u.preventDefault(),u.returnValue=`You have unsaved changes in this ${s.name}. Are you sure you want to leave this page?`)}return typeof window<"u"&&window.addEventListener("beforeunload",c),()=>{typeof window<"u"&&window.removeEventListener("beforeunload",c)}},[t,s]);const l=d.useCallback(c=>{o(c),n(c?r.jsxs(r.Fragment,{children:[" You have unsaved changes in this ",r.jsx("b",{children:s?.singularName??s?.name}),"."]}):void 0)},[s?.name,o,n]);return!e||!s?r.jsx("div",{className:"w-full"}):r.jsx(r.Fragment,{children:r.jsx(ae,{children:r.jsx(dc,{...e,formWidth:e.width,collection:s,parentCollectionIds:a,onValuesAreModified:l})})})}const Ya="new";function gc(e,t){if(t)return lc;const o=!e.selectedSubPath;let n;return e.width?n=typeof e.width=="number"?`${e.width}px`:e.width:e.collection?.sideDialogWidth&&(n=typeof e.collection.sideDialogWidth=="number"?`${e.collection.sideDialogWidth}px`:e.collection.sideDialogWidth),o?n||(e.collection?Ac(e.collection):lr):`calc(${cc} + ${n??lr})`}const Io={};function Ac(e){if(Io[e.id])return Io[e.id];const t=Ne({collection:e,path:"__ignored",ignoreMissingFields:!0});let o=lr;if(t?.properties){const n=Object.values(t.properties).map(a=>pr(a)),i=Math.max(...n);i<3?o=lr:o=768+32*(i-2)+"px"}return Io[e.id]=o,o}function pr(e,t=0){if(e.dataType==="map"&&e.properties){const o=Object.values(e.properties).flatMap(n=>pr(n,t+1));return Math.max(...o)}else return e.dataType==="array"&&e.oneOf?t+3:e.dataType==="array"&&e.of?Array.isArray(e.of)?Math.max(...e.of.map(o=>pr(o,t+1))):pr(e.of,t+1):t+1}const bc=(e,t)=>{const o=ge.useLocation(),n=d.useRef(!1),i=!Me();d.useEffect(()=>{if(!e.loading&&!n.current){if(console.debug("Initialising side entity controller"),e.isUrlCollectionPath(o.pathname)){const c=o.hash===`#${Ya}`,u=e.urlPathToDataPath(o.pathname),f=yc(u,e.collections??[],c);for(let g=0;g<f.length;g++){const m=f[g];setTimeout(()=>{g===0?t.replace(ur(m,e.buildUrlCollectionPath,e.resolveAliasesFrom,i)):t.open(ur(m,e.buildUrlCollectionPath,e.resolveAliasesFrom,i))},1)}}n.current=!0}},[o,e.loading,e.isUrlCollectionPath,e.buildUrlCollectionPath,e.resolveAliasesFrom,t,i,e]);const a=d.useCallback(()=>{t.close()},[t]),s=d.useCallback(c=>{if(c.copy&&!c.entityId)throw Error("If you want to copy an entity you need to provide an entityId");const u=Er(c.collection?c.collection.defaultSelectedView:void 0,{status:c.copy?"copy":c.entityId?"existing":"new",entityId:c.entityId});t.open(ur({selectedSubPath:u,...c},e.buildUrlCollectionPath,e.resolveAliasesFrom,i))},[t,e.buildUrlCollectionPath,e.resolveAliasesFrom,i]),l=d.useCallback(c=>{if(c.copy&&!c.entityId)throw Error("If you want to copy an entity you need to provide an entityId");t.replace(ur(c,e.buildUrlCollectionPath,e.resolveAliasesFrom,i))},[e.buildUrlCollectionPath,e.resolveAliasesFrom,t,i]);return{close:a,open:s,replace:l}};function yc(e,t,o){const n=So({path:e,collections:t}),i=[];let a="";for(let s=0;s<n.length;s++){const l=n[s];if(l.type==="collection"&&(a=l.path),s>0){const c=n[s-1];if(l.type==="entity")i.push({path:l.path,entityId:l.entityId,copy:!1,width:l.parentCollection?.sideDialogWidth});else if(l.type==="custom_view"){if(c.type==="entity"){const u=i[i.length-1];u&&(u.selectedSubPath=l.view.key)}}else if(l.type==="collection"&&c.type==="entity"){const u=i[i.length-1];u&&(u.selectedSubPath=l.collection.id??l.collection.path)}}}return o&&i.push({path:a,copy:!1}),i}const ur=(e,t,o,n)=>{const i=fe(e.path),a=e.entityId?t(`${i}/${e.entityId}/${e.selectedSubPath||""}`):t(`${i}#${Ya}`),s=o(e.path),l={...e,path:s};return{key:`${e.path}/${e.entityId}`,component:r.jsx(hc,{...l}),urlPath:a,parentUrlPath:t(i),width:gc(e,n),onClose:e.onClose}};function wc(){const e=ge.useLocation(),t=ge.useNavigate(),[o,n]=d.useState([]),i=d.useRef(o),a=d.useRef({}),s=d.useRef(0),l=g=>{i.current=g,n(g)};d.useEffect(()=>{const h=(e.state?.panels??[]).map(A=>a.current[A]).filter(A=>!!A);L(i.current.map(A=>A.key),h.map(A=>A.key))||l(h)},[e]);const c=d.useCallback(()=>{if(o.length===0)return;const g=o[o.length-1],m=[...o.slice(0,-1)];if(l(m),s.current>0)g.urlPath&&t(-1),s.current--;else if(g.parentUrlPath){const h=e.state?.base_location??e;t(g.parentUrlPath,{replace:!0,state:{base_location:h,panels:m.map(A=>A.key)}})}},[o,t,e]),u=d.useCallback(g=>{const m=Array.isArray(g)?g:[g];m.forEach(y=>{a.current[y.key]=y}),s.current=s.current+m.length;const h=e.state?.base_location??e,A=[...o,...m];l(A),m.forEach(y=>{y.urlPath&&t(y.urlPath,{state:{base_location:h,panels:A.map(b=>b.key)}})})},[e,t,o]),f=d.useCallback(g=>{const m=Array.isArray(g)?g:[g];m.forEach(y=>{a.current[y.key]=y});const h=e.state?.base_location??e,A=[...o.slice(0,-m.length),...m];l(A),m.forEach(y=>{y.urlPath&&t(y.urlPath,{replace:!0,state:{base_location:h,panels:A.map(b=>b.key)}})})},[e,t,o]);return{sidePanels:o,close:c,open:u,replace:f}}function vc({delegate:e,propertyConfigs:t,navigationController:o}){return{fetchCollection:d.useCallback(({path:n,collection:i,filter:a,limit:s,startAfter:l,searchString:c,orderBy:u,order:f})=>e.fetchCollection({path:n,filter:a,limit:s,startAfter:l,searchString:c,orderBy:u,order:f}),[e]),listenCollection:e.listenCollection?d.useCallback(({path:n,collection:i,filter:a,limit:s,startAfter:l,searchString:c,orderBy:u,order:f,onUpdate:g,onError:m})=>{const h=i??o.getCollection(n),A=!!h?.collectionGroup;if(!e.listenCollection)throw Error("useBuildDataSource delegate not initialised");return e.listenCollection({path:n,filter:a,limit:s,startAfter:l,searchString:c,orderBy:u,order:f,onUpdate:g,onError:m,isCollectionGroup:A,collection:h})},[e,o.getCollection]):void 0,fetchEntity:d.useCallback(({path:n,entityId:i})=>e.fetchEntity({path:n,entityId:i}),[e]),listenEntity:e.listenEntity?d.useCallback(({path:n,entityId:i,collection:a,onUpdate:s,onError:l})=>{if(!e.listenEntity)throw Error("useBuildDataSource delegate not initialised");return e.listenEntity({path:n,entityId:i,onUpdate:s,onError:l})},[e.listenEntity]):void 0,saveEntity:d.useCallback(({path:n,entityId:i,values:a,collection:s,status:l})=>{const c=s??o.getCollection(n),f=(c?Ne({collection:c,path:n,entityId:i,fields:t}):void 0)?.properties,g=e.cmsToDelegateModel(a),m=f?Lo({inputValues:g,properties:f,status:l,timestampNowValue:e.currentTime(),setDateToMidnight:e.setDateToMidnight}):g;return e.saveEntity({path:n,entityId:i,values:m,status:l}).then(h=>({id:h.id,path:h.path,values:e.delegateToCMSModel(m)}))},[e.saveEntity,o.getCollection]),deleteEntity:d.useCallback(({entity:n})=>e.deleteEntity({entity:n}),[e.deleteEntity]),checkUniqueField:d.useCallback((n,i,a,s)=>e.checkUniqueField(n,i,a,s),[e.checkUniqueField]),generateEntityId:d.useCallback(n=>e.generateEntityId(n),[e.generateEntityId]),countEntities:e.countEntities?async({path:n,collection:i,filter:a,order:s,orderBy:l})=>e.countEntities({path:n,filter:a,orderBy:l,order:s,isCollectionGroup:!!i.collectionGroup}):void 0,isFilterCombinationValid:d.useCallback(({path:n,filterValues:i,sortBy:a})=>e.isFilterCombinationValid?e.isFilterCombinationValid({path:n,filterValues:i,sortBy:a}):!0,[e.isFilterCombinationValid]),initTextSearch:d.useCallback(async n=>e.initTextSearch?e.initTextSearch(n):!1,[e.initTextSearch])}}const kc="https://api-drplyi3b6q-ey.a.run.app";async function _c(e,t){const o=await e.getAuthToken();return fetch(kc+"/access_log",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Basic ${o}`},body:JSON.stringify({plugins:t})}).then(async n=>n.json())}function Cc(e,t){const[o,n]=d.useState(null),i=d.useRef(null),a=t?.map(s=>s.key);return d.useEffect(()=>{e.user&&e.user.uid!==i.current&&!e.initialLoading&&(_c(e,a).then(n),i.current=e.user.uid)},[e,a]),o}function xc(e){const{children:t,entityLinkBuilder:o,userConfigPersistence:n,dateTimeFormat:i,locale:a,authController:s,storageSource:l,dataSourceDelegate:c,plugins:u,onAnalyticsEvent:f,propertyConfigs:g,entityViews:m,components:h,navigationController:A}=e;p.useLocaleConfig(a);const y=vc({delegate:c,propertyConfigs:g,navigationController:A}),b=wc(),k=bc(A,b),v=u?.some(x=>x.loading)??!1,_=s.initialLoading||A.loading||v,E={dateTimeFormat:i,locale:a,entityLinkBuilder:o,plugins:u,entityViews:m??[],propertyConfigs:g??{},components:h},C=d.useMemo(()=>({onAnalyticsEvent:f}),[]),B=Cc(s,u);return A.navigationLoadingError?r.jsx(p.CenteredView,{maxWidth:"md",children:r.jsx(ye,{title:"Error loading navigation",error:A.navigationLoadingError})}):s.authError?r.jsx(p.CenteredView,{maxWidth:"md",children:r.jsx(ye,{title:"Error loading auth",error:s.authError})}):B?.blocked?r.jsxs(p.CenteredView,{maxWidth:"md",fullScreen:!0,children:[r.jsx(p.Typography,{variant:"h4",children:"Access blocked"}),r.jsxs(p.Typography,{children:["This app has been blocked. Please reach out at ",r.jsx("a",{href:"mailto:hello@firecms.co",children:"hello@firecms.co"})," for more information."]}),B?.message&&r.jsxs(p.Typography,{children:["Response from the server: ",B?.message]})]}):r.jsx(yn.Provider,{value:C,children:r.jsx(bn.Provider,{value:E,children:r.jsx(hn.Provider,{value:n,children:r.jsx(mn.Provider,{value:l,children:r.jsx(dn.Provider,{value:y,children:r.jsx(hr.Provider,{value:s,children:r.jsx(un.Provider,{value:b,children:r.jsx(fn.Provider,{value:k,children:r.jsx(pn.Provider,{value:A,children:r.jsx(Vi,{children:r.jsx(Ec,{loading:_,children:t})})})})})})})})})})})}function Ec({loading:e,children:t}){const o=Ae(),n=ne();let i=t({context:o,loading:e});const a=n.plugins;return!e&&a&&a.forEach(s=>{s.provider&&(i=r.jsx(s.provider.Component,{...s.provider.props,context:o,children:i}))}),r.jsx(r.Fragment,{children:i})}const La=280,Bc=d.memo(function(t){const{children:o,autoOpenDrawer:n,logo:i,className:a,style:s}=t,l=d.Children.toArray(o).filter(C=>C.type.componentType==="Drawer");if(l.length>1)throw Error("Only one Drawer component is allowed in Scaffold");const c=d.Children.toArray(o).filter(C=>C.type.componentType==="AppBar");if(c.length>1)throw Error("Only one AppBar component is allowed in Scaffold");const u=d.Children.toArray(o).filter(C=>C.type.componentType!=="Drawer"&&C.type.componentType!=="AppBar"),f=l.length>0,g=Me(),[m,h]=d.useState(!1),[A,y]=d.useState(!1),b=d.useCallback(()=>y(!0),[]),k=d.useCallback(()=>y(!1),[]),v=d.useCallback(()=>{h(!0)},[]),_=d.useCallback(()=>{h(!1)},[]),E=m||!!(g&&n&&A);return r.jsx(fo.Provider,{value:{logo:i,hasDrawer:f,drawerHovered:A,drawerOpen:E,closeDrawer:_,openDrawer:v,autoOpenDrawer:n},children:r.jsxs("div",{className:p.cls("flex h-screen w-screen bg-gray-50 dark:bg-gray-900 text-gray-900 dark:text-white overflow-hidden",a),style:{paddingTop:"env(safe-area-inset-top)",paddingLeft:"env(safe-area-inset-left)",paddingRight:"env(safe-area-inset-right)",paddingBottom:"env(safe-area-inset-bottom)",height:"100dvh",...s},children:[c,r.jsx(Ic,{displayed:f,onMouseEnter:b,onMouseMove:b,onMouseLeave:k,open:E,hovered:A,setDrawerOpen:h,children:f&&l}),r.jsxs("main",{className:"flex flex-col flex-grow overflow-auto",children:[r.jsx(Sc,{}),r.jsx("div",{className:p.cls(p.defaultBorderMixin,"flex-grow overflow-auto lg:m-0 lg:mx-4 lg:mb-4 lg:rounded-lg lg:border lg:border-solid m-0 mt-1"),children:r.jsx(ae,{children:u})})]})]})})},L),Sc=()=>r.jsx("div",{className:"flex flex-col min-h-[68px]"});function Ic(e){const t=e.displayed?e.open?La:72:0,o=r.jsxs("div",{className:"relative h-full no-scrollbar overflow-y-auto overflow-x-hidden",style:{width:t,transition:"left 100ms cubic-bezier(0.4, 0, 0.6, 1) 0ms, opacity 100ms cubic-bezier(0.4, 0, 0.6, 1) 0ms, width 100ms cubic-bezier(0.4, 0, 0.6, 1) 0ms"},children:[!e.open&&e.displayed&&r.jsx(p.Tooltip,{title:"Open menu",side:"right",sideOffset:12,className:"fixed top-2 left-3 !bg-gray-50 dark:!bg-gray-900 rounded-full w-fit z-20",children:r.jsx(p.IconButton,{color:"inherit","aria-label":"Open menu",className:"sticky top-2 left-3 ",onClick:()=>e.setDrawerOpen(!0),size:"large",children:r.jsx(p.MenuIcon,{})})}),r.jsx("div",{className:`z-20 absolute right-0 top-4 ${e.open?"opacity-100":"opacity-0 invisible"} transition-opacity duration-200 ease-in-out`,children:r.jsx(p.IconButton,{"aria-label":"Close drawer",onClick:()=>e.setDrawerOpen(!1),children:r.jsx(p.ChevronLeftIcon,{})})}),r.jsx("div",{className:"flex flex-col h-full",children:e.children})]});return Me()?r.jsx("div",{className:"z-20 relative",onMouseEnter:e.onMouseEnter,onMouseMove:e.onMouseMove,onMouseLeave:e.onMouseLeave,style:{width:t,transition:"left 100ms cubic-bezier(0.4, 0, 0.6, 1) 0ms, opacity 100ms cubic-bezier(0.4, 0, 0.6, 1) 0ms, width 100ms cubic-bezier(0.4, 0, 0.6, 1) 0ms"},children:o}):e.displayed?r.jsxs(r.Fragment,{children:[r.jsx(p.IconButton,{color:"inherit","aria-label":"Open drawer",onClick:()=>e.setDrawerOpen(!0),size:"large",className:"absolute top-2 left-6",children:r.jsx(p.MenuIcon,{})}),r.jsx(p.Sheet,{side:"left",transparent:!0,open:e.open,onOpenChange:e.setDrawerOpen,children:o})]}):null}function ja({name:e,icon:t,drawerOpen:o,tooltipsOpen:n,url:i,onClick:a}){const s=r.jsx("div",{className:"text-gray-600 dark:text-gray-500",children:t}),l=r.jsxs(ge.NavLink,{onClick:a,style:{width:o?"280px":"72px",transition:o?"width 150ms ease-in":void 0},className:({isActive:c})=>p.cls("rounded-r-lg truncate","hover:bg-slate-300 hover:bg-opacity-75 dark:hover:bg-gray-700 dark:hover:bg-opacity-75 text-gray-800 dark:text-gray-200 hover:text-gray-900 hover:dark:text-white","flex flex-row items-center mr-8",o?"pl-8 h-12":"pl-6 h-11","font-medium text-sm",c?"bg-slate-200 bg-opacity-60 dark:bg-gray-800 dark:bg-opacity-30":""),to:i,children:[s,r.jsx("div",{className:p.cls(o?"opacity-100":"opacity-0 hidden","ml-4 font-inherit text-inherit"),children:e.toUpperCase()})]});return r.jsx(p.Tooltip,{open:o?!1:n,side:"right",title:e,children:l})}function Ua({className:e,style:t}){const{drawerHovered:o,drawerOpen:n,closeDrawer:i,logo:a}=nr(),s=ut(),l=pe(),c=o&&!n,u=Me(),f=ge.useNavigate(),[g,m]=d.useState(!1);if(!l.topLevelNavigation)throw Error("Navigation not ready in Drawer");const{navigationEntries:h,groups:A}=l.topLevelNavigation,y=h.filter(_=>_.type==="admin")??[],b=A.filter(_=>_!=="Admin"),k=d.useCallback(_=>n?r.jsx("div",{className:"pt-8 pl-6 pr-8 pb-2 flex flex-row items-center",children:r.jsx(p.Typography,{variant:"caption",color:"secondary",className:"font-medium flex-grow line-clamp-1",children:_?_.toUpperCase():"Views".toUpperCase()})}):r.jsx("div",{className:"h-12 w-full"}),[n]),v=_=>{const E=_.type==="collection"?"drawer_navigate_to_collection":_.type==="view"?"drawer_navigate_to_view":"unmapped_event";s.onAnalyticsEvent?.(E,{url:_.url}),u||i()};return r.jsx(r.Fragment,{children:r.jsxs("div",{className:p.cls("flex flex-col h-full relative flex-grow w-full",e),style:t,children:[r.jsx($a,{logo:a}),r.jsx("div",{className:"overflow-scroll no-scrollbar",children:b.map(_=>r.jsxs(d.Fragment,{children:[k(_),Object.values(h).filter(E=>E.group===_).map((E,C)=>r.jsx(ja,{icon:r.jsx(Ht,{collectionOrView:E.collection??E.view}),tooltipsOpen:c,drawerOpen:n,onClick:()=>v(E),url:E.url,name:E.name},`navigation_${C}`))]},`drawer_group_${_}`))}),y.length>0&&r.jsx(p.Menu,{open:g,onOpenChange:m,trigger:r.jsxs(p.IconButton,{shape:"square",className:"m-4 text-gray-900 dark:text-white w-fit",children:[r.jsx(p.Tooltip,{title:"Admin",open:c,side:"right",sideOffset:28,children:r.jsx(p.MoreVertIcon,{})}),n&&r.jsx("div",{className:p.cls(n?"opacity-100":"opacity-0 hidden","mx-4 font-inherit text-inherit"),children:"ADMIN"})]}),children:y.map((_,E)=>r.jsxs(p.MenuItem,{onClick:C=>{C.preventDefault(),f(_.path)},children:[r.jsx(Ht,{collectionOrView:_.view}),_.name]},`navigation_${E}`))})]})})}function $a({logo:e}){const t=pe(),{drawerOpen:o}=nr();return r.jsx("div",{style:{transition:"padding 100ms cubic-bezier(0.4, 0, 0.6, 1) 0ms",padding:o?"32px 144px 0px 24px":"72px 16px 0px"},className:p.cls("cursor-pointer"),children:r.jsx(p.Tooltip,{title:"Home",sideOffset:20,side:"right",children:r.jsx(ge.Link,{to:t.basePath,children:e?r.jsx("img",{src:e,alt:"Logo",className:p.cls("max-w-full max-h-full",o??"w-[112px] h-[112px]")}):r.jsx(uo,{})})})})}const Fc=d.memo(function({homePage:t=r.jsx(ba,{}),children:o}){const n=ge.useLocation(),i=pe();if(!i)return r.jsx(r.Fragment,{});const a=n.state,s=a&&a.base_location?a.base_location:n,l=[];i.views&&i.views.forEach(m=>{Array.isArray(m.path)?l.push(...m.path.map(h=>fr(h,m))):l.push(fr(m.path,m))}),i.adminViews&&i.adminViews.forEach(m=>{Array.isArray(m.path)?l.push(...m.path.map(h=>fr(h,m))):l.push(fr(m.path,m))});const u=[...i.collections??[]].sort((m,h)=>h.path.length-m.path.length).map(m=>{const h=i.buildUrlCollectionPath(m.id??m.path);return r.jsx(ge.Route,{path:h+"/*",element:r.jsx(ae,{children:r.jsx(po,{isSubCollection:!1,parentCollectionIds:[],fullPath:m.id??m.path,...m,Actions:Bt(m.Actions)},`collection_view_${m.id??m.path}`)})},`navigation_${m.id??m.path}`)}),f=r.jsx(ge.Route,{path:"/",element:t}),g=r.jsx(ge.Route,{path:"*",element:r.jsx(va,{})});return r.jsxs(ge.Routes,{location:s,children:[u,l,f,g,o]})}),fr=(e,t)=>r.jsx(ge.Route,{path:e,element:t.view},"navigation_view_"+e);function Wa({children:e,className:t,style:o}){const n=e??r.jsx(Ua,{className:t,style:o});return r.jsx(r.Fragment,{children:n})}Wa.componentType="Drawer";function qa({children:e,...t}){const o=e??r.jsx(ka,{...t});return r.jsx(r.Fragment,{children:o})}qa.componentType="AppBar",w.AppBar=qa,w.AppContext=fo,w.ArrayContainer=mo,w.ArrayContainerItem=ho,w.ArrayCustomShapedFieldBinding=Da,w.ArrayEnumPreview=jr,w.ArrayItemOptions=_a,w.ArrayOfMapsPreview=bs,w.ArrayOfReferencesFieldBinding=Ca,w.ArrayOfReferencesPreview=Mn,w.ArrayOfStorageComponentsPreview=On,w.ArrayOfStringsPreview=zn,w.ArrayOneOfPreview=Vn,w.ArrayPropertyEnumPreview=Ur,w.ArrayPropertyPreview=Lr,w.AsyncPreviewComponent=ys,w.AuthControllerContext=hr,w.BlockFieldBinding=Pa,w.BooleanPreview=Ln,w.COLLECTION_PATH_SEPARATOR=Ho,w.CircularProgressCenter=rr,w.DEFAULT_FIELD_CONFIGS=ir,w.DRAWER_WIDTH=La,w.DatePreview=Yn,w.DateTimeFieldBinding=Ba,w.DefaultAppBar=ka,w.DefaultDrawer=Ua,w.DefaultHomePage=ba,w.DeleteConfirmationDialog=Il,w.Drawer=Wa,w.DrawerLogo=$a,w.DrawerNavigationItem=ja,w.EmptyValue=et,w.EntityCollectionRowActions=er,w.EntityCollectionTable=ro,w.EntityCollectionView=po,w.EntityCollectionViewActions=ya,w.EntityForm=Ma,w.EntityReference=Ar,w.EntityView=Wr,w.EnumValuesChip=Ie,w.ErrorBoundary=ae,w.ErrorView=ye,w.FieldCaption=Ql,w.FieldHelperText=xe,w.FireCMS=xc,w.FireCMSLogo=uo,w.FormikArrayContainer=ar,w.GeoPoint=br,w.IconForView=Ht,w.ImagePreview=Fn,w.KeyValueFieldBinding=Fa,w.KeyValuePreview=$r,w.LabelWithIcon=Ee,w.MapFieldBinding=Ia,w.MapPropertyPreview=Gn,w.MarkdownFieldBinding=Ta,w.ModeControllerContext=mr,w.ModeControllerProvider=si,w.MultiSelectBinding=Ao,w.NavigationCard=ha,w.NavigationCardBinding=Aa,w.NavigationGroup=lo,w.NavigationRoutes=Fc,w.NotFoundPage=va,w.NumberPropertyPreview=jn,w.PropertyConfigBadge=Sl,w.PropertyFieldBinding=ot,w.PropertyPreview=we,w.PropertyTableCell=ea,w.ReadOnlyFieldBinding=yo,w.ReferenceFieldBinding=Sa,w.ReferencePreview=Oe,w.ReferenceSelectionTable=ma,w.ReferenceWidget=Pl,w.RepeatFieldBinding=Na,w.Scaffold=Bc,w.SearchIconsView=Dl,w.SelectFieldBinding=go,w.SelectableTable=da,w.SelectableTableContext=Zr,w.SideDialogs=fc,w.SkeletonPropertyComponent=tt,w.SmallNavigationCard=ga,w.SnackbarProvider=ai,w.StorageThumbnail=Nn,w.StorageThumbnailInternal=Tn,w.StorageUploadFieldBinding=bo,w.StringPropertyPreview=Yr,w.SwitchFieldBinding=Ea,w.TextFieldBinding=At,w.UrlComponentPreview=xt,w.Vector=di,w.VirtualTable=aa,w.addInitialSlash=li,w.applyPermissionsFunctionIfEmpty=Wo,w.archiveEntityAction=ul,w.buildAdditionalFieldDelegate=Mi,w.buildCollection=Ii,w.buildEntityCallbacks=Qi,w.buildEnumLabel=Uo,w.buildEnumValueConfig=Di,w.buildEnumValues=Ti,w.buildFieldConfig=Oi,w.buildIdColumn=Zs,w.buildProperties=Ni,w.buildPropertiesOrBuilder=Pi,w.buildProperty=Fi,w.canCreateEntity=ct,w.canDeleteEntity=$t,w.canEditEntity=Fr,w.copyEntityAction=io,w.defaultDateFormat=qo,w.deleteEntityAction=so,w.deleteEntityWithCallbacks=wn,w.editEntityAction=fa,w.enumToObjectEntries=We,w.flattenObject=Pr,w.fullPathToCollectionSegments=Sr,w.getArrayValuesCount=rn,w.getBracketNotation=Ci,w.getCollectionByPathOrId=Dt,w.getCollectionPathsCombinations=Qt,w.getColorForProperty=_i,w.getColorScheme=jo,w.getColumnKeysForProperty=tr,w.getDefaultFieldConfig=Va,w.getDefaultFieldId=sr,w.getDefaultPropertiesOrder=xi,w.getDefaultValueFor=zt,w.getDefaultValueForDataType=_r,w.getDefaultValuesFor=vt,w.getEntityImagePreviewPropertyKey=tn,w.getEntityPreviewKeys=en,w.getEntityTitlePropertyKey=Nr,w.getFieldConfig=It,w.getFieldId=Co,w.getHashValue=wr,w.getIcon=Ro,w.getIconForProperty=Ce,w.getIconForWidget=jt,w.getIdIcon=ki,w.getLabelOrConfigFrom=Gt,w.getLastSegment=ci,w.getPropertiesWithPropertiesOrder=Ko,w.getPropertyInPath=Re,w.getRandomId=St,w.getReferenceFrom=Le,w.getResolvedPropertyInPath=Ir,w.getSidePanelKey=Ji,w.getValueInPath=Ye,w.hydrateRegExp=Zo,w.iconSynonyms=Wt,w.iconsSearch=qt,w.isDefaultFieldConfigId=za,w.isEmptyObject=kr,w.isEnumValueDisabled=fi,w.isHidden=wt,w.isObject=Mt,w.isPropertyBuilder=_e,w.isReadOnly=st,w.isReferenceProperty=Xo,w.isValidRegExp=vi,w.joinCollectionLists=an,w.makePropertiesEditable=on,w.makePropertiesNonEditable=nn,w.mergeCollection=sn,w.mergeDeep=De,w.openWebsiteAction=fl,w.pick=Go,w.plural=Bi,w.printChanged=Dr,w.propertiesToColumns=oa,w.randomColor=bi,w.randomString=lt,w.removeFunctions=yr,w.removeInPath=pi,w.removeInitialAndTrailingSlashes=fe,w.removeInitialSlash=zo,w.removePropsIfExisting=Yo,w.removeTrailingSlash=Vo,w.removeUndefined=vr,w.renderSkeletonCaptionText=ps,w.renderSkeletonIcon=Gr,w.renderSkeletonImageThumbnail=Vr,w.renderSkeletonText=je,w.resolveArrayProperty=Xe,w.resolveCollection=Ne,w.resolveCollectionPathIds=gr,w.resolveDefaultSelectedView=Er,w.resolveEntityView=Bo,w.resolveEnumValues=sc,w.resolveNavigationFrom=vn,w.resolvePermissions=kt,w.resolveProperties=xo,w.resolveProperty=Pe,w.resolvePropertyEnum=Eo,w.sanitizeData=ui,w.saveEntityWithCallbacks=Or,w.segmentsToStrippedPath=Jo,w.serializeRegExp=wi,w.singular=Si,w.slugify=Yt,w.sortProperties=xr,w.stripCollectionPath=Br,w.toKebabCase=hi,w.toSnakeCase=Ai,w.traverseValueProperty=Vt,w.traverseValuesProperties=Cr,w.unslugify=yi,w.updateDateAutoValues=Lo,w.useApp=nr,w.useAuthController=qe,w.useBrowserTitleAndIcon=$i,w.useBuildLocalConfigurationPersistence=Ki,w.useBuildModeController=Ri,w.useBuildNavigationController=Hi,w.useClearRestoreValue=Te,w.useClipboard=_n,w.useCollectionFetch=Gi,w.useColumnIds=Rr,w.useCustomizationController=ne,w.useDataSource=Qe,w.useDataSourceEntityCollectionTableController=oo,w.useDebouncedCallback=Lt,w.useDebouncedData=pa,w.useDialogsController=An,w.useEntityFetch=Mr,w.useFireCMSContext=Ae,w.useLargeLayout=Me,w.useModeController=kn,w.useNavigationController=pe,w.useReferenceDialog=ft,w.useResolvedNavigationFrom=Yi,w.useSelectableTableController=Rn,w.useSelectionController=no,w.useSideDialogContext=dr,w.useSideDialogsController=_t,w.useSideEntityController=He,w.useSnackbarController=Je,w.useStorageSource=dt,w.useTableSearchHelper=ao,w.useTraceUpdate=zi,w.useValidateAuthenticator=es,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
589
589
  //# sourceMappingURL=index.umd.js.map