@object-ui/plugin-form 17.5.0 → 17.6.0

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.
@@ -1 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("react"),require("@object-ui/core"),require("@object-ui/react"),require("@object-ui/fields"),require("@object-ui/components"),require("@object-ui/permissions"),require("@objectstack/spec/data"),require("lucide-react"),require("@object-ui/i18n"),require("react/jsx-runtime")):typeof define==`function`&&define.amd?define([`exports`,`react`,`@object-ui/core`,`@object-ui/react`,`@object-ui/fields`,`@object-ui/components`,`@object-ui/permissions`,`@objectstack/spec/data`,`lucide-react`,`@object-ui/i18n`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ObjectUIPluginForm={},e.React,e._object_ui_core,e._object_ui_react,e._object_ui_fields,e._object_ui_components,e._object_ui_permissions,e._objectstack_spec_data,e.lucide_react,e._object_ui_i18n,e.react_jsx_runtime))})(this,function(e,t,n,r,i,a,o,s,c,l,u){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var d=Object.create,f=Object.defineProperty,p=Object.getOwnPropertyDescriptor,m=Object.getOwnPropertyNames,h=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty,_=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=m(t),a=0,o=i.length,s;a<o;a++)s=i[a],!g.call(e,s)&&s!==n&&f(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=p(t,s))||r.enumerable});return e};t=((e,t,n)=>(n=e==null?{}:d(h(e)),_(t||!e||!e.__esModule||!g.call(e,`default`)?f(n,`default`,{value:e,enumerable:!0}):n,e)))(t,1);function v(e){try{return typeof window>`u`?!1:new URL(e,window.location.href).origin===window.location.origin}catch{return!1}}function y(e,t){if(!e)return null;let n=t?.id??t?.recordId??t?._id;if(n==null||n===``)return null;let r=e.replace(/\{(?:id|recordId)\}/g,String(n));return v(r)?r:null}function b(e){return typeof e==`object`&&!!e&&typeof e.dialect==`string`&&typeof e.source==`string`}function x(e){return(0,s.isRuntimeDefaultToken)(e)||b(e)}function S(e){return e!=null&&!x(e)}function C(e){return e?.mode===`create`||!e?.recordId}function w(e,t){return!(!e?.required||t&&x(e.defaultValue))}function T(e){let t=e?.fields;if(!t||typeof t!=`object`)return{};let n={};for(let e of Object.keys(t)){let r=t[e]?.defaultValue;S(r)&&(n[e]=r)}return n}function E(e,t){return{...T(e),...t??{}}}function D(e,t){if(!e||typeof e!=`object`)return e;let r=t?.fields;if(!r||typeof r!=`object`)return e;let i={};for(let[t,a]of Object.entries(e))x(r[t]?.defaultValue)&&(0,n.isMissingForRequired)(a)||(i[t]=a);return i}function O(e,t){return typeof t==`string`&&t.trim()||typeof t==`object`&&t&&typeof t.source==`string`&&t.source.trim()?{...e,visibleOn:t}:e}var k=new Set;function A(e,t){if(typeof e.name!=`string`||e.name===e.field)return;let n=`${t}:${e.field}:${e.name}`;k.has(n)||(k.add(n),console.warn(`[object-ui] section field { field: '${e.field}' } also carries name: '${e.name}' — mixed form-field vocabularies. The spec key wins (the runtime name becomes '${e.field}'); drop \`name\` from authored form views.`))}function j(e,t){let n=t.objectSchema?.fields?.[e];return n?{name:e,label:t.fieldLabel(t.objectName,e,n.label||e),type:(0,i.mapFieldTypeToFormType)(n.type,{multiple:n.multiple}),required:w(n,C(t)),disabled:t.readOnly||t.mode===`view`||n.readonly,placeholder:n.placeholder,description:n.help||n.description,validation:(0,i.buildValidationRules)(n),field:n,options:n.options,multiple:n.multiple,visibleWhen:n.visibleWhen,readonlyWhen:n.readonlyWhen,requiredWhen:n.requiredWhen}:{name:e,label:e,type:`input`}}function M(e,t){if(typeof e==`string`){let n=t.objectSchema?.fields?.[e];return O(j(e,t),n?.visible_on??n?.visibleOn)}let n=e;if(typeof n.field!=`string`)return O(n,n.visibleOn);A(n,t.objectName);let r=n.field,a=j(r,t);n.widget!=null&&(a.widget=n.widget),n.label!=null&&(a.label=n.label),n.placeholder!=null&&(a.placeholder=n.placeholder),n.helpText!=null&&(a.description=n.helpText),n.required!=null&&(a.required=w({required:n.required,defaultValue:t.objectSchema?.fields?.[r]?.defaultValue},C(t))),n.readonly!=null&&(a.disabled=n.readonly||a.disabled),n.immutable!=null&&(a.immutable=n.immutable),n.hidden!=null&&(a.hidden=n.hidden),n.colSpan!=null&&(a.colSpan=n.colSpan),n.span!=null&&(a.span=n.span),n.options!=null&&(a.options=n.options),n.multiple!=null&&(a.multiple=n.multiple);let o=n.type??t.objectSchema?.fields?.[r]?.type;o!=null&&(a.type=(0,i.mapFieldTypeToFormType)(o,{multiple:a.multiple}));let s=n.reference??n.reference_to;return s!=null&&(a.reference=s,a.reference_to=s),n.maxLength!=null&&(a.maxLength=n.maxLength),n.minLength!=null&&(a.minLength=n.minLength),n.min!=null&&(a.min=n.min),n.max!=null&&(a.max=n.max),n.precision!=null&&(a.precision=n.precision),n.scale!=null&&(a.scale=n.scale),n.language!=null&&(a.language=n.language),Array.isArray(n.fields)&&(a.fields=n.fields),n.dependsOn!=null&&(a.dependsOn=n.dependsOn),n.keyField!=null&&(a.keyField=n.keyField),n.disclosure!=null&&(a.disclosure=n.disclosure),O(a,n.visibleWhen??n.visibleOn)}function N(e,t){return(e.fields??[]).map(e=>M(e,t))}var P=new Set([`field:formula`,`field:summary`,`field:auto_number`,`field:autonumber`]),F=new Set([`field:textarea`,`field:markdown`,`field:html`,`field:grid`,`field:richtext`,`textarea`,`markdown`,`html`,`grid`,`richtext`]),I=new Set([`formula`,`summary`,`auto_number`,`autonumber`]);function L(e){return F.has(e)}function R(e){return I.has(e)}function ee(e){return e<=3?1:e<=8?2:e<=15?3:4}function z(e){return e&&e>0?Math.min(Math.floor(e),4):1}function B(e,t,n){let r=z(t);return r<=1?1:e.span===`full`?r:e.colSpan==null?e.type&&L(e.type)?r:Math.min(r,Math.max(1,Math.round(r/Math.min(Math.max(1,Math.floor(n||r)),r)))):Math.min(Math.max(1,Math.floor(e.colSpan)),r)}function V(e,t,n){let r=z(t);return r<=1?e:e.map(e=>{if(e.type===`section-divider`)return e;let t=B(e,r,n);return t>1?{...e,colSpan:t}:e.colSpan!=null&&e.colSpan!==1?{...e,colSpan:1}:e})}var H=new Set([`id`,`created_at`,`createdAt`,`updated_at`,`updatedAt`,`last_modified_at`,`lastModifiedAt`,`deleted_at`,`deletedAt`,`created_by`,`createdBy`,`updated_by`,`updatedBy`,`last_modified_by`,`lastModifiedBy`,`organization_id`,`organizationId`,`org_id`,`orgId`,`tenant_id`,`tenantId`,`owner`,`owner_id`,`_version`,`_rev`]);function te(e,t){return e.filter(e=>{if(H.has(e.name))return!1;let n=t?.fields?.[e.name];return n?.hidden!==!0&&n?.readonly!==!0})}function U(e,t){return e.filter(e=>{if(H.has(e.name)||e.type&&P.has(e.type))return!1;if(!t?.fields)return!0;let n=t.fields[e.name];return!n||n.readonly!==!0&&!R(n.type)})}function W(e,t){return e.filter(e=>{if(e.type&&P.has(e.type))return!1;let n=t?.fields?.[e.name];return!n||!R(n.type)})}var G={1:void 0,2:`grid gap-4 grid-cols-1 @md:grid-cols-2`,3:`grid gap-4 grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3`,4:`grid gap-4 grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3 @4xl:grid-cols-4`};function K(e){return G[e&&e>0?Math.min(Math.floor(e),4):1]}function ne(e){return e<=1?`default`:e===2?`xl`:`full`}function re(e,t,n,r){let i=[...e];if(i=te(i,t),r===`create`&&(i=W(i,t)),n!==void 0)return i=V(i,n),{fields:i,columns:n};let a=ee(i.length);return i=V(i,a),{fields:i,columns:a}}var q=(0,l.createSafeTranslation)({"form.conflictTitle":`Save conflict`,"form.conflictMessage":`This record was changed by someone else while you were editing. Overwriting will replace their changes with yours.`,"form.conflictLatestVersion":`Their save: {{time}}`,"form.conflictOverwrite":`Overwrite`,"form.keepEditing":`Keep editing`},`form.conflictTitle`);function J(e){let t=e?.updated_at;return typeof t==`string`&&t.length>0?t:void 0}function ie(e){if(!e||typeof e!=`object`)return!1;let t=e;return t.code===`CONCURRENT_UPDATE`||t.name===`ConcurrentUpdateError`}function Y(e){if(!e)return null;let t=/\d{4}-\d{2}-\d{2}[ T]/.test(e)?e.replace(` `,`T`):e,n=new Date(t);return Number.isNaN(n.getTime())?null:n.toLocaleString()}function ae(){let{t:e}=q(),[n,r]=t.useState(null),i=t.useRef(null),o=t.useCallback(e=>{i.current?.(e),i.current=null,r(null)},[]);t.useEffect(()=>()=>i.current?.(!1),[]);let s=t.useCallback(async({dataSource:e,objectName:t,recordId:n,payload:a,baseRecord:o})=>{let s=J(o);try{return{status:`saved`,result:await e.update(t,n,a,s?{ifMatch:s}:void 0)}}catch(o){if(!ie(o))throw o;let s=o.currentVersion;if(!await new Promise(e=>{i.current=e,r({currentVersion:typeof s==`string`?s:void 0})}))return{status:`cancelled`};let c=typeof s==`string`&&s.length>0?s:void 0;return{status:`saved`,result:await e.update(t,n,a,c?{ifMatch:c}:void 0)}}},[]),l=Y(n?.currentVersion);return{saveWithOcc:s,conflictDialog:(0,u.jsx)(a.AlertDialog,{open:!!n,onOpenChange:e=>{e||o(!1)},children:(0,u.jsxs)(a.AlertDialogContent,{children:[(0,u.jsxs)(a.AlertDialogHeader,{children:[(0,u.jsxs)(a.AlertDialogTitle,{className:`flex items-center gap-2`,children:[(0,u.jsx)(c.AlertTriangle,{className:`h-5 w-5 text-amber-500`,"aria-hidden":!0}),e(`form.conflictTitle`)]}),(0,u.jsxs)(a.AlertDialogDescription,{children:[e(`form.conflictMessage`),l&&(0,u.jsx)(`span`,{className:`mt-2 block text-xs text-muted-foreground`,children:e(`form.conflictLatestVersion`,{time:l})})]})]}),(0,u.jsxs)(a.AlertDialogFooter,{children:[(0,u.jsx)(`button`,{type:`button`,className:(0,a.cn)((0,a.buttonVariants)({variant:`outline`})),onClick:()=>o(!1),children:e(`form.keepEditing`)}),(0,u.jsx)(`button`,{type:`button`,className:(0,a.cn)((0,a.buttonVariants)({variant:`destructive`})),onClick:()=>o(!0),children:e(`form.conflictOverwrite`)})]})]})})}}var X=({schema:e,dataSource:n,className:i})=>{let{fieldLabel:o}=(0,r.useSafeFieldLabel)(),[s,c]=(0,t.useState)(null),[l,d]=(0,t.useState)({}),{saveWithOcc:f,conflictDialog:p}=ae(),[m,h]=(0,t.useState)(!0),[g,_]=(0,t.useState)(null),v=e.defaultTab||e.sections[0]?.name||e.sections[0]?.label||`tab-0`;t.default.useEffect(()=>{(async()=>{if(!n){h(!1);return}try{let t=await n.getObjectSchema(e.objectName);c(t)}catch(e){_(e)}})()},[e.objectName,n]);let y=(0,t.useRef)(void 0);t.default.useEffect(()=>{let t=!1;return(s||!n)&&(async()=>{if(e.mode===`create`||!e.recordId||!n){d(E(s,e.initialData||e.initialValues)),h(!1);return}y.current!==e.recordId&&h(!0);try{let r=await n.findOne(e.objectName,e.recordId);if(t)return;y.current=e.recordId,d(r||{})}catch(e){if(t)return;_(e)}finally{t||h(!1)}})(),()=>{t=!0}},[s,e.mode,e.recordId,e.initialData,e.initialValues,n,e.objectName]);let b=(0,t.useCallback)(t=>N(t,{objectSchema:s,objectName:e.objectName,readOnly:e.readOnly,mode:e.mode,recordId:e.recordId,fieldLabel:o}),[s,e.readOnly,e.mode,e.recordId,e.objectName,o]),x=(0,t.useCallback)(async t=>{if(!n)return e.onSuccess&&await e.onSuccess(t),t;try{let r;if(e.mode===`create`)r=await n.create(e.objectName,D(t,s));else if(e.mode===`edit`&&e.recordId){let i=await f({dataSource:n,objectName:e.objectName,recordId:e.recordId,payload:t,baseRecord:l});if(i.status===`cancelled`)return;r=i.result}return e.onSuccess&&await e.onSuccess(r),r}catch(t){throw e.onError&&e.onError(t),t}},[e,n,f,l]),S=(0,t.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),C=(e,t)=>e.name||e.label||`tab-${t}`;if(g)return(0,u.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,u.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,u.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:g.message})]});if(m)return(0,u.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,u.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,u.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let w=e=>typeof e==`number`&&e>0?Math.min(Math.floor(e),4):void 0,T=e.sections.map(e=>w(e.columns)).filter(e=>e!=null),O=w(e.columns)??(T.length?Math.max(...T):1),k=K(O),A=e.sections.map((e,t)=>{let n=b(e);return{key:C(e,t),label:e.label||`Tab ${t+1}`,description:e.description,containerClass:e.gridClassName,fields:O>1?V(n,O,w(e.columns)):n}}),j=A.flatMap(e=>e.fields);return(0,u.jsxs)(`div`,{className:(0,a.cn)(`w-full @container`,i,e.className),children:[(0,u.jsx)(r.SchemaRenderer,{schema:{type:`form`,objectName:e.objectName,fields:j,columns:O,...k?{fieldContainerClass:k}:{},layout:`vertical`,defaultValues:l,previousValues:e.mode===`edit`&&e.recordId?l:void 0,submitLabel:e.submitText||(e.mode===`create`?`Create`:`Update`),cancelLabel:e.cancelText,showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1,onSubmit:x,onCancel:S,fieldTabs:A.map(e=>({key:e.key,label:e.label,description:e.description,fields:e.fields.map(e=>e.name),containerClass:e.containerClass})),defaultFieldTab:v,fieldTabsPosition:e.tabPosition||`top`}}),p]})},Z=({label:e,description:n,collapsible:r=!1,collapsed:i=!1,columns:o=1,children:s,className:l,gridClassName:d,showBorder:f})=>{let[p,m]=(0,t.useState)(i),h={1:`grid-cols-1`,2:`grid-cols-1 md:grid-cols-2`,3:`grid-cols-1 md:grid-cols-2 lg:grid-cols-3`,4:`grid-cols-1 md:grid-cols-2 lg:grid-cols-4`},g=()=>{r&&m(!p)},_=f??!!e,v=e||n?(0,u.jsxs)(`div`,{className:(0,a.cn)(`flex items-start gap-2`,!_&&`mb-4`,r&&`cursor-pointer select-none`),onClick:g,role:r?`button`:void 0,"aria-expanded":r?!p:void 0,children:[r&&(0,u.jsx)(`span`,{className:`mt-0.5 text-muted-foreground`,children:p?(0,u.jsx)(c.ChevronRight,{className:`h-4 w-4`}):(0,u.jsx)(c.ChevronDown,{className:`h-4 w-4`})}),(0,u.jsxs)(`div`,{className:`flex-1`,children:[e&&(0,u.jsx)(`h3`,{className:`text-sm font-semibold text-foreground`,children:e}),n&&(0,u.jsx)(`p`,{className:`text-sm text-muted-foreground mt-0.5`,children:n})]})]}):null,y=p?null:(0,u.jsx)(`div`,{className:(0,a.cn)(`grid gap-4`,d||h[o]),children:s});return _?(0,u.jsxs)(a.Card,{className:(0,a.cn)(`form-section bg-muted/40 shadow-none`,l),children:[v&&(0,u.jsx)(a.CardHeader,{className:`border-b border-border pb-3`,children:v}),y&&(0,u.jsx)(a.CardContent,{className:`pt-4`,children:y})]}):(0,u.jsxs)(`div`,{className:(0,a.cn)(`form-section`,l),children:[v,y]})},Q=(0,l.createSafeTranslation)({"wizard.missingRequired":`Please complete the required fields: {{fields}}`},`wizard.missingRequired`),oe=n.isMissingForRequired,se=({schema:e,dataSource:i,className:o})=>{let{fieldLabel:s}=(0,r.useSafeFieldLabel)(),{t:l}=Q(),[d,f]=(0,t.useState)(null),[p,m]=(0,t.useState)({}),[h,g]=(0,t.useState)(void 0),{saveWithOcc:_,conflictDialog:b}=ae(),[x,S]=(0,t.useState)(!0),[C,w]=(0,t.useState)(null),[T,O]=(0,t.useState)(0),[k,A]=(0,t.useState)(new Set),[j,M]=(0,t.useState)(!1),[P,F]=(0,t.useState)(new Set),[I,L]=(0,t.useState)(null),R=t.default.useId(),[ee,z]=(0,t.useState)(0),B=t.default.useRef(!1),H=e.sections.length,te=T===0,U=T===H-1;t.default.useEffect(()=>{(async()=>{if(!i){S(!1);return}try{let t=await i.getObjectSchema(e.objectName);f(t)}catch(e){w(e)}})()},[e.objectName,i]),t.default.useEffect(()=>{(d||!i)&&(async()=>{if(e.mode===`create`||!e.recordId||!i){B.current||=(m(E(d,e.initialData||e.initialValues)),!0),S(!1);return}try{let t=await i.findOne(e.objectName,e.recordId);m(t||{}),g(t||{})}catch(e){w(e)}finally{S(!1)}})()},[d,e.mode,e.recordId,e.initialData,e.initialValues,i,e.objectName]);let W=(0,t.useCallback)(t=>N(t,{objectSchema:d,objectName:e.objectName,readOnly:e.readOnly,mode:e.mode,recordId:e.recordId,fieldLabel:s}),[d,e.readOnly,e.mode,e.recordId,e.objectName,s]),G=(0,t.useMemo)(()=>T>=0&&T<H?W(e.sections[T]):[],[T,H,e.sections,W]),ne=(0,t.useCallback)(t=>{let r=new Map;return e.sections.forEach((e,i)=>{for(let a of W(e)){let e=a?.name;if(!e||a.hidden===!0)continue;let o=(0,n.resolveFieldRuleState)({visibleWhen:a.visibleWhen,readonlyWhen:a.readonlyWhen,requiredWhen:a.requiredWhen},t,{required:!!a.required,readonly:a.readonly===!0},void 0,void 0,`field '${e}'`);!(a.visibleOn==null||(0,n.evalFieldPredicate)(a.visibleOn,t,!0,void 0,void 0,{context:`visibleOn of field '${e}'`}))||!o.visible||o.readonly||!o.required||oe(t[e])&&r.set(i,[...r.get(i)??[],a.label||e])}}),r},[e.sections,W]),re=(0,t.useCallback)(async t=>{let n={...p,...t};if(m(n),A(e=>new Set(e).add(T)),F(e=>{if(!e.has(T))return e;let t=new Set(e);return t.delete(T),t}),U){let t=ne(n);if(t.size>0){F(new Set(t.keys()));let e=[...t.values()].flat();a.toast.error(l(`wizard.missingRequired`,{fields:e.slice(0,3).join(`, `)+(e.length>3?`…`:``)})),q(Math.min(...t.keys()));return}F(new Set),M(!0);try{if(!i)return e.onSuccess&&await e.onSuccess(n),n;let t;if(e.mode===`create`)t=await i.create(e.objectName,D(n,d));else if(e.mode===`edit`&&e.recordId){let r=await _({dataSource:i,objectName:e.objectName,recordId:e.recordId,payload:n,baseRecord:p});if(r.status===`cancelled`)return;t=r.result}if(e.onSuccess)await e.onSuccess(t);else if(e.submitBehavior){let t=e.submitBehavior;switch(t.kind){case`redirect`:v(t.url)&&setTimeout(()=>window.location.assign(t.url),t.delayMs??0);break;case`continue`:m(E(d,e.initialData||e.initialValues)),A(new Set),O(0),z(e=>e+1);break;default:{let n=t.kind===`thank-you`&&t.message?t.message:e.successMessage||(e.mode===`create`?`Created`:`Saved`);a.toast.success(n),L({title:t.kind===`thank-you`?t.title:void 0,message:n});break}}}else{let n=y(e.navigateOnSuccess,t);if(n)return window.location.assign(n),t;a.toast.success(e.successMessage||(e.mode===`create`?`Created`:`Saved`)),e.resetOnSuccess&&e.mode===`create`&&(m(E(d,e.initialData||e.initialValues)),A(new Set),O(0),z(e=>e+1))}return t}catch(t){throw e.onError&&e.onError(t),t}finally{M(!1)}}q(T+1)},[p,T,U,e,d,i,ne,l,_]),q=(0,t.useCallback)(t=>{t>=0&&t<H&&(O(t),e.onStepChange&&e.onStepChange(t))},[H,e]),J=(0,t.useCallback)(()=>{q(T-1)},[T,q]),ie=(0,t.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),Y=(0,t.useCallback)(t=>{(e.allowSkip||k.has(t)||t<=T)&&q(t)},[e.allowSkip,k,T,q]);if(C)return(0,u.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,u.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,u.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:C.message})]});if(x)return(0,u.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,u.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,u.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});if(I)return(0,u.jsx)(`div`,{className:(0,a.cn)(`w-full`,o,e.className),children:(0,u.jsxs)(`div`,{className:`rounded-md border bg-card p-8 text-center`,children:[(0,u.jsx)(`h3`,{className:`text-lg font-semibold`,children:I.title??`Thanks!`}),I.message&&(0,u.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:I.message})]})});let X=e.sections[T],se=e=>typeof e==`number`&&e>0?Math.min(Math.floor(e),4):void 0,ce=se(e.columns)??se(X?.columns)??1,$=K(ce);return(0,u.jsxs)(`div`,{className:(0,a.cn)(`w-full @container`,o,e.className),children:[e.showStepIndicator!==!1&&(0,u.jsx)(`nav`,{"aria-label":`Progress`,className:`mb-8`,children:(0,u.jsx)(`ol`,{className:`flex items-center`,children:e.sections.map((t,n)=>{let r=n===T,i=k.has(n),o=e.allowSkip||i||n<=T,s=P.has(n);return(0,u.jsxs)(`li`,{className:(0,a.cn)(`relative flex-1`,n!==H-1&&`pr-8 sm:pr-12`),children:[n!==H-1&&(0,u.jsx)(`div`,{className:`absolute top-3 sm:top-4 left-6 -right-4 sm:left-10 sm:-right-2 h-0.5`,"aria-hidden":`true`,children:(0,u.jsx)(`div`,{className:(0,a.cn)(`h-full`,i?`bg-primary`:`bg-muted`)})}),(0,u.jsxs)(`button`,{type:`button`,className:(0,a.cn)(`group relative flex items-center`,o?`cursor-pointer`:`cursor-not-allowed`),onClick:()=>Y(n),disabled:!o,"data-testid":`wizard-step:${t.name||n}`,"data-error":s||void 0,children:[(0,u.jsx)(`span`,{className:(0,a.cn)(`flex h-6 w-6 sm:h-8 sm:w-8 items-center justify-center rounded-full text-xs sm:text-sm font-medium transition-colors`,s&&`border-2 border-destructive bg-background text-destructive`,!s&&i&&`bg-primary text-primary-foreground`,!s&&r&&!i&&`border-2 border-primary bg-background text-primary`,!s&&!r&&!i&&`border-2 border-muted bg-background text-muted-foreground`),children:s?(0,u.jsx)(c.AlertCircle,{className:`h-3 w-3 sm:h-4 sm:w-4`,"aria-hidden":!0}):i?(0,u.jsx)(c.Check,{className:`h-3 w-3 sm:h-4 sm:w-4`}):n+1}),(0,u.jsx)(`span`,{className:`ml-2 sm:ml-3 text-xs sm:text-sm font-medium hidden sm:block`,children:(0,u.jsx)(`span`,{className:(0,a.cn)(s?`text-destructive`:r?`text-foreground`:`text-muted-foreground`),children:t.label||`Step ${n+1}`})})]})]},n)})})}),(0,u.jsx)(`div`,{className:`min-h-[200px]`,children:X&&(0,u.jsx)(Z,{label:X.label,description:X.description,columns:1,className:X.className,gridClassName:X.gridClassName,children:G.length>0?(0,u.jsx)(r.SchemaRenderer,{schema:{type:`form`,objectName:e.objectName,id:R,fields:ce>1?V(G,ce,se(X.columns)):G,columns:ce,...$?{fieldContainerClass:$}:{},layout:`vertical`,defaultValues:p,previousValues:e.mode===`edit`?h:void 0,showSubmit:!1,showCancel:!1,onSubmit:re}},ee):(0,u.jsx)(`form`,{id:R,onSubmit:e=>{e.preventDefault(),re({})},children:(0,u.jsx)(`div`,{className:`text-center py-8 text-muted-foreground`,children:`No fields configured for this step`})})})}),(0,u.jsxs)(`div`,{className:`flex items-center justify-between mt-6 pt-4 border-t`,children:[(0,u.jsx)(`div`,{children:e.showCancel!==!1&&(0,u.jsx)(a.Button,{variant:`ghost`,onClick:ie,children:e.cancelText||`Cancel`})}),(0,u.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,u.jsxs)(`span`,{className:`text-sm text-muted-foreground mr-2`,children:[`Step `,T+1,` of `,H]}),!te&&(0,u.jsxs)(a.Button,{variant:`outline`,onClick:J,children:[(0,u.jsx)(c.ChevronLeft,{className:`h-4 w-4 mr-1`}),e.prevText||`Back`]}),U?(0,u.jsxs)(a.Button,{type:`submit`,form:R,disabled:j||e.mode===`view`,children:[j&&(0,u.jsx)(c.Loader2,{className:`mr-2 h-4 w-4 animate-spin`,"aria-hidden":!0}),j?`Submitting...`:e.submitText||(e.mode===`create`?`Create`:`Update`)]}):(0,u.jsxs)(a.Button,{type:`submit`,form:R,children:[e.nextText||`Next`,(0,u.jsx)(c.ChevronRight,{className:`h-4 w-4 ml-1`})]})]})]}),b]})},ce=({schema:e,dataSource:n,className:i})=>{let{fieldLabel:o}=(0,r.useSafeFieldLabel)(),[s,c]=(0,t.useState)(null),[l,d]=(0,t.useState)({}),{saveWithOcc:f,conflictDialog:p}=ae(),[m,h]=(0,t.useState)(!0),[g,_]=(0,t.useState)(null);(0,t.useEffect)(()=>{(async()=>{if(!n){h(!1);return}try{let t=await n.getObjectSchema(e.objectName);c(t)}catch(e){_(e),h(!1)}})()},[e.objectName,n]);let v=(0,t.useRef)(void 0);(0,t.useEffect)(()=>{let t=!1;return(s||!n)&&(async()=>{if(e.mode===`create`||!e.recordId){d(E(s,e.initialData||e.initialValues)),h(!1);return}if(!n){d(e.initialData||e.initialValues||{}),h(!1);return}v.current!==e.recordId&&h(!0);try{let r=await n.findOne(e.objectName,e.recordId);if(t)return;v.current=e.recordId,d(r||{})}catch(e){if(t)return;_(e)}finally{t||h(!1)}})(),()=>{t=!0}},[s,e.mode,e.recordId,e.initialData,e.initialValues,n,e.objectName]);let y=(0,t.useCallback)(t=>N(t,{objectSchema:s,objectName:e.objectName,readOnly:e.readOnly,mode:e.mode,recordId:e.recordId,fieldLabel:o}),[s,e.readOnly,e.mode,e.recordId,e.objectName,o]),b=(0,t.useCallback)(async t=>{if(!n)return e.onSuccess&&await e.onSuccess(t),t;try{let r;if(e.mode===`create`)r=await n.create(e.objectName,D(t,s));else if(e.mode===`edit`&&e.recordId){let i=await f({dataSource:n,objectName:e.objectName,recordId:e.recordId,payload:t,baseRecord:l});if(i.status===`cancelled`)return;r=i.result}return e.onSuccess&&await e.onSuccess(r),r}catch(t){throw e.onError&&e.onError(t),t}},[e,n,f,l]),x=(0,t.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),S=(e,t)=>e.pane===`primary`||e.pane===`secondary`?e.pane:t===0?`primary`:`secondary`,C=(0,t.useMemo)(()=>e.sections.filter((e,t)=>S(e,t)===`primary`),[e.sections]),w=(0,t.useMemo)(()=>e.sections.filter((e,t)=>S(e,t)===`secondary`),[e.sections]),T=e.splitDirection||`horizontal`,O=e.splitSize||50;if(g)return(0,u.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,u.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,u.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:g.message})]});if(m)return(0,u.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,u.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,u.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let k=e=>typeof e==`number`&&e>0?Math.min(Math.floor(e),4):void 0,A=e.sections.map(e=>k(e.columns)).filter(e=>e!=null),j=k(e.columns)??(A.length?Math.max(...A):1),M=K(j),P=(e,t)=>{let n=[];return e.forEach((e,r)=>{let i=y(e);i.length&&((e.label||e.description)&&n.push({name:`__section_${e.name||`${t}_${r}`}`,label:e.label,description:e.description,type:`section-divider`,colSpan:4,className:e.className}),n.push(...j>1?V(i,j,k(e.columns)):i))}),n},F=[{key:`primary`,sections:C,defaultSize:O},{key:`secondary`,sections:w,defaultSize:100-O}].map(e=>({...e,fields:P(e.sections,e.key),containerClass:e.sections.length===1?e.sections[0].gridClassName:void 0})).filter(e=>e.fields.length>0);return(0,u.jsxs)(`div`,{className:(0,a.cn)(`w-full @container`,i,e.className),children:[(0,u.jsx)(r.SchemaRenderer,{schema:{type:`form`,objectName:e.objectName,fields:F.flatMap(e=>e.fields),columns:j,...M?{fieldContainerClass:M}:{},layout:`vertical`,defaultValues:l,previousValues:e.mode===`edit`&&e.recordId?l:void 0,submitLabel:e.submitText||(e.mode===`create`?`Create`:`Update`),cancelLabel:e.cancelText,showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1,onSubmit:b,onCancel:x,fieldPanes:F.map(e=>({key:e.key,fields:e.fields.map(e=>e.name),defaultSize:e.defaultSize,...e.containerClass?{containerClass:e.containerClass}:{}})),fieldPanesOrientation:T,fieldPanesResizable:e.splitResizable!==!1}}),p]})},$=new Set([`id`,`_id`,`created_at`,`updated_at`,`createdAt`,`updatedAt`,`organization_id`,`organizationId`]),le=new Set([`formula`,`summary`,`rollup`,`lookup_value`,`auto_number`,`autonumber`,`computed`]);function ue(e,t){if(!e||typeof e!=`object`)return e;let n={},r=t?.fields;for(let[t,i]of Object.entries(e))if(!$.has(t)){if(r){let e=r[t];if(!e)continue;let n=String(e.type||``).toLowerCase();if(le.has(n)||e.computed===!0||e.formula||e.readOnly===!0||e.readonly===!0)continue}n[t]=i}return n}var de=e=>e==null?void 0:e.id??e._id??e.recordId,fe=(e,t)=>t?ue(e,t):e,pe=new Set([`id`,`_id`,`recordId`]);function me(e,t){return!e||Object.entries(e).every(([e,n])=>e===t||pe.has(e)?!0:n==null||n===``)}function he(e,t,n){let r=[{object:e,action:`create`,data:t}];for(let e of n)for(let t of e.rows)me(t,e.relationshipField)||r.push({object:e.childObject,action:`create`,data:{...fe(t,e.childSchema),[e.relationshipField]:{$ref:0}}});return r}function ge(e,t,n,r){let i=[{object:e,action:`update`,id:t,data:n}];for(let e of r){let n=(e.rows||[]).map(n=>({...n,[e.relationshipField]:t})),{toCreate:r,toUpdate:a,toDelete:o}=_e(e.original||[],n);for(let t of r){if(me(t,e.relationshipField))continue;let{id:n,_id:r,recordId:a,...o}=t;i.push({object:e.childObject,action:`create`,data:fe(o,e.childSchema)})}for(let t of a)i.push({object:e.childObject,action:`update`,id:de(t),data:fe(t,e.childSchema)});for(let t of o)i.push({object:e.childObject,action:`delete`,id:t})}return i}function _e(e,t){let n=new Set(t.map(de).filter(Boolean));return{toCreate:t.filter(e=>!de(e)),toUpdate:t.filter(e=>de(e)),toDelete:(e||[]).map(de).filter(e=>!!e&&!n.has(e))}}function ve(e,t){return Array.isArray(e)?e.reduce((e,n)=>{let r=Number(n?.[t]);return e+(Number.isFinite(r)?r:0)},0):0}var ye=new Set([`id`,`_id`,`recordId`,`created_at`,`updated_at`,`created_by`,`updated_by`,`createdAt`,`updatedAt`,`createdBy`,`updatedBy`,`organization_id`,`tenant_id`,`space`,`owner`]),be=new Set([`position`,`sort_order`,`sequence`,`line_no`,`line_number`,`sort`]),xe=new Set([`formula`,`summary`,`rollup`,`autonumber`,`auto_number`,`json`,`object`,`grid`,`table`,`location`,`vector`,`html`,`markdown`,`richtext`]);function Se(e){switch(e){case`number`:case`percent`:case`rating`:case`slider`:return`number`;case`currency`:return`currency`;case`date`:return`date`;case`datetime`:return`datetime`;case`time`:return`time`;case`select`:case`picklist`:case`radio`:case`boolean`:case`toggle`:return`select`;case`lookup`:case`master_detail`:return`lookup`;case`file`:case`image`:case`avatar`:return`file`;default:return`text`}}var Ce=new Set([`image`,`avatar`]);function we(e,t){e.multiple==null&&t?.multiple&&(e.multiple=!0),e.accept??(Array.isArray(t?.accept)&&t.accept.length>0?e.accept=t.accept:Ce.has(t?.type)&&(e.accept=[`image/*`]))}function Te(e){if(e?.type===`boolean`||e?.type===`toggle`)return[{label:`Yes`,value:`true`},{label:`No`,value:`false`}];let t=e?.options;if(Array.isArray(t))return t.map(e=>typeof e==`object`&&e?{label:String(e.label??e.value),value:String(e.value)}:{label:String(e),value:String(e)})}function Ee(e,t){let n=e?.fields;if(!n||typeof n!=`object`)return;let r;for(let[e,i]of Object.entries(n)){let n=i;if(n?.reference===t){if(n?.type===`master_detail`)return e;n?.type===`lookup`&&!r&&(r=e)}}return r}var De=[`name`,`title`,`subject`,`label`,`full_name`,`display_name`,`code`],Oe={select:0,currency:1,number:1,lookup:2,date:3,datetime:3,time:3,text:4};function ke(e){return(e.type?Oe[e.type]:void 0)??5}function Ae(e,t){if(t<=0||e.length<=t)return e;let n=new Set,r=e.find(e=>De.includes(e.field))??e[0];r&&n.add(r.field);for(let t of e)t.required&&n.add(t.field);let i=e.map((e,t)=>({c:e,i:t})).filter(({c:e})=>!n.has(e.field)).sort((e,t)=>ke(e.c)-ke(t.c)||e.i-t.i);for(let{c:e}of i){if(n.size>=t)break;n.add(e.field)}return e.map(e=>n.has(e.field)?e:{...e,defaultHidden:!0})}function je(e,t={}){let n=e?.fields;if(!n||typeof n!=`object`)return[];let r=new Set([...t.exclude??[],...t.relationshipField?[t.relationshipField]:[]]),i=[];for(let[e,t]of Object.entries(n)){let n=t;if(ye.has(e)||r.has(e)||be.has(e)||n?.system||n?.readonly||n?.hidden||xe.has(n?.type))continue;let a={field:e,label:n?.label||e,type:Se(n?.type),required:!!n?.required},o=Te(n);a.type===`select`&&o&&(a.options=o),a.type===`lookup`&&(a.reference=n?.reference,a.displayField=n?.display_field||n?.reference_field),a.type===`file`&&we(a,n),n?.readonlyWhen&&(a.readonlyWhen=n.readonlyWhen),n?.requiredWhen&&(a.requiredWhen=n.requiredWhen);let s=typeof n?.expression==`string`?n.expression:n?.expression?.source;s&&typeof s==`string`&&(a.computed=!0,a.expr=s,a.required=!1,typeof n?.scale==`number`&&(a.scale=n.scale)),i.push(a)}return Ae(i,t.maxColumns??6)}function Me(e,t){let n=e??[],r=t?.fields;return!n.length||!r||typeof r!=`object`?n:n.map(e=>{if(e.type)return e;let t=r[e.field];if(!t)return e;let n=Se(t?.type),i={...e,type:n};i.label??=t?.label||e.field,i.required??=!!t?.required;let a=Te(t);n===`select`&&a&&!i.options&&(i.options=a),n===`lookup`&&(i.reference??=t?.reference,i.displayField??=t?.display_field||t?.reference_field),n===`file`&&we(i,t),i.readonlyWhen==null&&t?.readonlyWhen&&(i.readonlyWhen=t.readonlyWhen),i.requiredWhen==null&&t?.requiredWhen&&(i.requiredWhen=t.requiredWhen);let o=typeof t?.expression==`string`?t.expression:t?.expression?.source;return!i.computed&&o&&typeof o==`string`&&(i.computed=!0,i.expr=o,i.required=!1,typeof t?.scale==`number`&&(i.scale=t.scale)),i})}var Ne=new Set([`formula`,`summary`,`rollup`,`autonumber`,`auto_number`]);function Pe(e,t={}){let n=e?.fields;if(!n||typeof n!=`object`)return[];let r=new Set([...t.exclude??[],...t.relationshipField?[t.relationshipField]:[]]),i=[];for(let[e,t]of Object.entries(n)){let n=t;ye.has(e)||r.has(e)||be.has(e)||n?.system||n?.hidden||Ne.has(n?.type)||i.push(e)}return i}var Fe=new Set([`textarea`,`richtext`,`html`,`markdown`,`rich-text`,`json`,`location`,`address`]),Ie=new Set([`file`,`image`,`avatar`]);function Le(e,t,n={}){if(t===`grid`||t===`form`)return t;let r=e?.fields??{},i=Pe(e,{relationshipField:n.relationshipField});return i.some(e=>Fe.has(r[e]?.type))||i.filter(e=>Ie.has(r[e]?.type)).length>=2||i.length>8?`form`:`grid`}var Re=[`amount`,`total`,`subtotal`,`line_total`,`line_amount`,`net_amount`];function ze(e){let t=e.filter(e=>e.type===`number`||e.type===`currency`);if(t.length===0)return;let n=t.find(e=>e.computed);if(n)return n.field;let r=t.find(e=>Re.includes(e.field));if(r)return r.field;let i=[...t].reverse().find(e=>e.type===`currency`);return i?i.field:t[t.length-1].field}function Be(e,t,n,r={}){let i=r.relationshipField||Ee(t,n);if(!i)throw Error(`MasterDetailForm: could not find a lookup/master_detail field on "${e}" referencing "${n}". Set relationshipField explicitly.`);let a=r.columns?.length?Me(r.columns,t):je(t,{relationshipField:i}),o=r.amountField||ze(a);return{childObject:e,relationshipField:i,columns:a,formFields:Pe(t,{relationshipField:i}),mode:Le(t,r.inlineEdit??(t?.fields)?.[i]?.inlineEdit,{relationshipField:i}),amountField:o,sortField:Object.keys(t?.fields??{}).find(e=>be.has(e))}}function Ve(e){if(!e)return{};let t={};return e.querySelectorAll(`[name]`).forEach(e=>{let n=e.getAttribute(`name`);if(n){if(e.tagName===`INPUT`){let r=e;if(r.type===`checkbox`){t[n]=r.checked;return}if(r.type===`radio`){r.checked&&(t[n]=r.value);return}if(r.type===`number`||r.type===`range`){if(r.value===``){t[n]=null;return}let e=Number(r.value);t[n]=Number.isFinite(e)?e:r.value;return}t[n]=r.value;return}t[n]=e.value}}),t}var He=({details:e,state:n,setRows:r,formHostRef:a,taxRateField:o,formKey:s,onRowExpand:c,onAddViaForm:l})=>{let[d,f]=(0,t.useState)({}),p=(0,t.useRef)(``);(0,t.useEffect)(()=>{let e=a.current;if(!e)return;let t=()=>{let t=Ve(e),n;try{n=JSON.stringify(t)}catch{n=String(Math.random())}n!==p.current&&(p.current=n,f(t))};t();let n=()=>t();e.addEventListener(`input`,n),e.addEventListener(`change`,n);let r=[120,360,800].map(e=>setTimeout(t,e));return()=>{e.removeEventListener(`input`,n),e.removeEventListener(`change`,n),r.forEach(clearTimeout)}},[a,s,e.length]);let m=d[o],h=m===void 0?null:Number.isFinite(Number(m))?Number(m):0,g=e.reduce((e,t,r)=>e+ve(n[r]?.rows??[],t.amountField||`amount`),0),_=h!==null&&e.some(e=>!!e.amountField),v=h??0,y=v/100*g,b=g+y,x=e=>`¥${e.toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2})}`;return(0,u.jsxs)(u.Fragment,{children:[e.map((e,t)=>(0,u.jsxs)(`section`,{className:`space-y-2`,children:[(0,u.jsx)(`h3`,{className:`text-sm font-medium text-foreground`,children:e.title||`Line Items`}),e.columns?.length?(0,u.jsx)(i.LineItemsField,{value:n[t]?.rows??[],onChange:e=>r(t,e),contextRecord:d,...e.inlineMode===`form`||(e.formFields?.length??0)>(e.columns?.length??0)?{onRowExpand:e=>c(t,e)}:{},displayMode:e.inlineMode===`form`?`list`:`grid`,...e.inlineMode===`form`?{onAdd:()=>l(t)}:{},field:{columns:e.columns,total_field:_?void 0:e.amountField||(e.totalField?`amount`:void 0),sort_field:e.sortField,min_rows:e.minRows,max_rows:e.maxRows,add_label:e.inlineMode===`form`?e.addLabel||`Add`:e.addLabel}}):(0,u.jsx)(`p`,{className:`py-4 text-sm text-muted-foreground`,children:`Loading columns…`})]},`${e.childObject}-${t}`)),_&&(0,u.jsx)(`div`,{className:`flex justify-end`,children:(0,u.jsxs)(`dl`,{className:`w-64 space-y-1.5 text-sm`,"data-testid":`md-totals`,children:[(0,u.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,u.jsx)(`dt`,{className:`text-muted-foreground`,children:`Subtotal`}),(0,u.jsx)(`dd`,{className:`tabular-nums`,"data-testid":`md-subtotal`,children:x(g)})]}),(0,u.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,u.jsxs)(`dt`,{className:`text-muted-foreground`,children:[`Tax (`,v,`%)`]}),(0,u.jsx)(`dd`,{className:`tabular-nums`,"data-testid":`md-tax`,children:x(y)})]}),(0,u.jsxs)(`div`,{className:`flex items-center justify-between border-t border-border pt-1.5 text-base font-semibold`,children:[(0,u.jsx)(`dt`,{children:`Total`}),(0,u.jsx)(`dd`,{className:`tabular-nums`,"data-testid":`md-grand-total`,children:x(b)})]})]})})]})},Ue=({schema:e,dataSource:r,className:i})=>{let o=e.details||[],s=e.mode===`edit`&&!!e.recordId,c=o.some(e=>!e.relationshipField||!e.columns?.length||e.columns.some(e=>!e.type)),[l,d]=(0,t.useState)(c?null:o),f=l??o;(0,t.useEffect)(()=>{if(!c){d(o);return}if(!r||typeof r.getObjectSchema!=`function`)return;let t=!1;return(async()=>{let n=await Promise.all(o.map(async t=>{let n=t.columns?.length?t.columns.every(e=>!!e.type):!1;if(t.relationshipField&&n)return t;try{let n=await r.getObjectSchema(t.childObject);if(t.relationshipField&&t.columns?.length)return{...t,columns:Me(t.columns,n)};let i=Be(t.childObject,n,e.objectName,{relationshipField:t.relationshipField,columns:t.columns,amountField:t.amountField});return{...t,relationshipField:i.relationshipField,columns:i.columns,formFields:t.formFields??i.formFields,inlineMode:t.inlineMode??i.mode,amountField:t.amountField??i.amountField,sortField:t.sortField??i.sortField}}catch{return t}}));t||d(n)})(),()=>{t=!0}},[r,e.objectName,e.details]);let[p,m]=(0,t.useState)(()=>o.map(()=>({rows:[],original:[]}))),h=(0,t.useRef)(p);h.current=p;let g=(0,t.useRef)({});(0,t.useEffect)(()=>{let e=r;if(!e||typeof e.getObjectSchema!=`function`)return;let t=!1,n=Array.from(new Set(o.map(e=>e.childObject).filter(Boolean)));return(async()=>{let r=await Promise.all(n.map(async t=>{try{return[t,await e.getObjectSchema(t)]}catch{return[t,null]}}));if(t)return;let i={};for(let[e,t]of r)t&&(i[e]=t);g.current=i})(),()=>{t=!0}},[r,e.objectName,e.details]);let[_,v]=(0,t.useState)(0),[y,b]=(0,t.useState)(!1),x=(0,t.useRef)(!1),S=(0,t.useRef)(null),C=(0,t.useCallback)(()=>{x.current=!1,b(!1),S.current&&=(clearTimeout(S.current),null)},[]);(0,t.useEffect)(()=>{let t=!1;if(!(!s||!r))return(async()=>{let n=await Promise.all(f.map(async t=>{if(!t.relationshipField)return{rows:[],original:[]};try{let n=(await r.find(t.childObject,{$filter:{[t.relationshipField]:e.recordId},$top:500}))?.data??[];return{rows:n.map(e=>({...e})),original:n.map(e=>({...e}))}}catch{return{rows:[],original:[]}}}));t||m(n)})(),()=>{t=!0}},[s,r,e.recordId,l]);let w=(0,t.useCallback)((e,t)=>{m(n=>n.map((n,r)=>r===e?{...n,rows:t}:n))},[]),T=e.taxRateField||`tax_rate`,[E,D]=(0,t.useState)(null),O=E?p[E.detailIdx]?.rows?.[E.rowIdx]:void 0,k=E?f[E.detailIdx]:void 0,A=(0,t.useCallback)((e,t,n)=>{m(r=>r.map((r,i)=>i===e?{...r,rows:r.rows.map((e,r)=>r===t?{...e,...n}:e)}:r))},[]),j=(0,t.useCallback)(e=>{m(t=>{let n=t.map((t,n)=>n===e?{...t,rows:[...t.rows,{}]}:t),r=n[e].rows.length-1;return D({detailIdx:e,rowIdx:r,isNew:!0}),n})},[]),M=(0,t.useCallback)(()=>{D(e=>(e?.isNew&&m(t=>t.map((t,n)=>n===e.detailIdx?{...t,rows:t.rows.filter((t,n)=>n!==e.rowIdx)}:t)),null))},[]),N=(0,t.useCallback)(async t=>{C(),e.onSuccess||a.toast.success(s?e.title?`${e.title} saved`:`Saved`:`Created`),s||(m(f.map(()=>({rows:[],original:[]}))),v(e=>e+1)),await e.onSuccess?.(t)},[s,e.onSuccess,e.title,f.length,C]),P=(0,t.useCallback)(t=>{C(),a.toast.error(t?.message||`Save failed`),e.onError?.(t)},[e,C]),F=(0,t.useCallback)(async t=>{if(!r)throw Error(`MasterDetailForm: dataSource is required`);let i={...t};f.forEach((e,t)=>{e.totalField&&(i[e.totalField]=ve(h.current[t]?.rows??[],e.amountField||`amount`))});let a=s?ge(e.objectName,String(e.recordId),i,f.filter(e=>e.relationshipField).map((e,t)=>({childObject:e.childObject,relationshipField:e.relationshipField,rows:h.current[t]?.rows??[],original:h.current[t]?.original??[],childSchema:g.current[e.childObject]}))):he(e.objectName,i,f.filter(e=>e.relationshipField).map((e,t)=>({childObject:e.childObject,relationshipField:e.relationshipField,rows:h.current[t]?.rows??[],childSchema:g.current[e.childObject]})));return(await(0,n.runBatchTransaction)(r,a))?.results?.[0]??{...i,id:e.recordId}},[r,f,e.objectName,e.recordId,s]),I=(0,t.useMemo)(()=>({type:`object-form`,objectName:e.objectName,mode:e.mode??`create`,recordId:e.recordId,initialValues:e.initialValues,initialData:e.initialData,formType:e.formType,sections:e.sections,fields:e.fields,title:e.title,showSubmit:!1,showCancel:!1,submitHandler:F,onSuccess:N,onError:P}),[e,F,N,P]),L=(0,t.useRef)(null),R=e.submitText??(s?`Save`:`Create`),ee=(0,t.useCallback)(()=>{x.current||L.current?.querySelector(`form`)&&(x.current=!0,b(!0),setTimeout(()=>{(L.current?.querySelector(`form`))?.requestSubmit()},0),S.current=setTimeout(()=>C(),1500))},[C]);return(0,t.useEffect)(()=>()=>{S.current&&clearTimeout(S.current)},[]),(0,u.jsxs)(`div`,{className:(0,a.cn)(`space-y-6`,i,e.className),children:[(0,u.jsx)(`div`,{ref:L,children:(0,u.jsx)(Qe,{schema:I,dataSource:r},_)}),(0,u.jsx)(He,{details:f,state:p,setRows:w,formHostRef:L,taxRateField:T,formKey:_,onRowExpand:(e,t)=>D({detailIdx:e,rowIdx:t}),onAddViaForm:j}),E&&k&&(0,u.jsxs)(a.Card,{className:`border-primary/40 shadow-none ring-1 ring-primary/10`,"data-testid":`md-row-form`,children:[(0,u.jsxs)(a.CardHeader,{className:`pb-2 flex flex-row items-center justify-between gap-2 space-y-0`,children:[(0,u.jsxs)(a.CardTitle,{className:`text-sm font-medium`,children:[k.title||`Line item`,` — row `,E.rowIdx+1]}),(0,u.jsx)(a.Button,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 text-xs text-muted-foreground`,onClick:M,children:`Close`})]}),(0,u.jsx)(a.CardContent,{children:(0,u.jsx)(Qe,{schema:{type:`object-form`,objectName:k.childObject,mode:`edit`,initialData:O??{},...k.formFields?.length?{fields:k.formFields}:{},submitText:`Apply`,submitHandler:async e=>e,onSuccess:e=>{A(E.detailIdx,E.rowIdx,e),D(null)},onCancel:M},dataSource:r},`row-${E.detailIdx}-${E.rowIdx}`)})]}),e.showSubmit!==!1&&(0,u.jsxs)(`div`,{className:`flex items-center justify-end gap-2 border-t border-border pt-4`,children:[e.onCancel&&(0,u.jsx)(a.Button,{type:`button`,variant:`outline`,onClick:e.onCancel,disabled:y,"data-testid":`md-form-cancel`,children:e.cancelText??`Cancel`}),(0,u.jsx)(a.Button,{type:`button`,onClick:ee,disabled:y||c&&!l,"data-testid":`md-form-submit`,children:y?`Saving…`:R})]})]})},We={1:void 0,2:`grid gap-4 grid-cols-1 @md:grid-cols-2`,3:`grid gap-4 grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3`,4:`grid gap-4 grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3 @4xl:grid-cols-4`},Ge=(0,l.createSafeTranslation)({"form.discardTitle":`Discard changes?`,"form.discardMessage":`You have unsaved changes. If you close this form now, your edits will be lost.`,"form.dialogDescriptionFallback":`Complete the form fields, then submit or cancel.`,"form.keepEditing":`Keep editing`,"form.discard":`Discard`},`form.discardTitle`),Ke=({schema:e,dataSource:n,className:o})=>{let{fieldLabel:s}=(0,r.useSafeFieldLabel)(),{t:l}=Ge(),d=(0,r.usePreviewMode)(),[f,p]=(0,t.useState)(null),[m,h]=(0,t.useState)([]),[g,_]=(0,t.useState)({}),[v,y]=(0,t.useState)(!0),[b,x]=(0,t.useState)(null),[S,T]=(0,t.useState)(!1),[O,k]=(0,t.useState)(!1),{saveWithOcc:A,conflictDialog:j}=ae(),[M,P]=(0,t.useState)(!1),F=(0,t.useRef)(!1),I=e.confirmOnDiscard!==!1,L=e.open!==!1,R=e.drawerSide||`right`,ee=(0,t.useId)(),[z,B]=(0,t.useState)(()=>{let t={};return e.sections?.forEach((e,n)=>{let r=e.name||String(n);e.collapsed&&(t[r]=!0)}),t});(0,t.useEffect)(()=>{(async()=>{if(!n){y(!1);return}try{let t=await n.getObjectSchema(e.objectName);p(t)}catch(e){x(e),y(!1)}})()},[e.objectName,n]);let V=(0,t.useRef)(void 0);(0,t.useEffect)(()=>{let t=!1;return(f||!n)&&(async()=>{if(e.mode===`create`||!e.recordId){_(E(f,e.initialData||e.initialValues)),y(!1);return}if(!n){_(e.initialData||e.initialValues||{}),y(!1);return}V.current!==e.recordId&&(y(!0),T(!1));try{let r=await n.findOne(e.objectName,e.recordId);if(t)return;V.current=e.recordId,_(r||{})}catch(e){if(t)return;x(e)}finally{t||y(!1)}})(),()=>{t=!0}},[f,e.mode,e.recordId,e.initialData,e.initialValues,n,e.objectName]);let H=(0,t.useCallback)(t=>N(t,{objectSchema:f,objectName:e.objectName,readOnly:e.readOnly,mode:e.mode,recordId:e.recordId,fieldLabel:s}),[f,e.readOnly,e.mode,e.recordId,e.objectName,s]);(0,t.useEffect)(()=>{if(!f&&n)return;if(e.customFields?.length){h(e.customFields),y(!1);return}if(e.sections?.length){y(!1);return}if(!f)return;let t=e.fields||Object.keys(f.fields||{}),r=[];for(let n of t){let t=typeof n==`string`?n:n.name;if(!t)continue;let a=f.fields?.[t];a&&r.push({name:t,label:s(e.objectName,t,a.label||t),type:(0,i.mapFieldTypeToFormType)(a.type,{multiple:a.multiple}),required:w(a,C(e)),disabled:e.readOnly||e.mode===`view`||a.readonly,placeholder:a.placeholder,description:a.help||a.description,validation:(0,i.buildValidationRules)(a),field:a,options:a.options,multiple:a.multiple})}h(r),y(!1)},[f,e.fields,e.customFields,e.sections,e.readOnly,e.mode,n]);let te=(0,t.useCallback)(async t=>{P(!0);try{if(!n)return e.onSuccess&&await e.onSuccess(t),e.onOpenChange?.(!1),t;let r,i=ue(t,f);if(e.mode===`create`)r=await n.create(e.objectName,D(i,f));else if(e.mode===`edit`&&e.recordId){let t=await A({dataSource:n,objectName:e.objectName,recordId:e.recordId,payload:i,baseRecord:g});if(t.status===`cancelled`)return;r=t.result}return e.onSuccess&&await e.onSuccess(r),e.onOpenChange?.(!1),r}catch(t){throw e.onError&&e.onError(t),t}finally{P(!1)}},[e,n,f,A,g]),U=(0,t.useCallback)(()=>{k(!1),F.current&&(F.current=!1,e.onCancel?.()),e.onOpenChange?.(!1)},[e]),W=(0,t.useCallback)(e=>{F.current=e,I&&S?k(!0):U()},[I,S,U]);(0,t.useEffect)(()=>{if(!L||!S||!I)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[L,S,I]);let G=(0,t.useCallback)(()=>{F.current=!0,U()},[U]),K=(0,t.useMemo)(()=>{if(e.drawerWidth)return R===`left`||R===`right`?{width:e.drawerWidth,maxWidth:e.drawerWidth}:{height:e.drawerWidth,maxHeight:e.drawerWidth}},[e.drawerWidth,R]),ne=e.layout===`vertical`||e.layout===`horizontal`?e.layout:`vertical`,q=e.showSubmit!==!1&&e.mode!==`view`,J=e.showCancel!==!1,ie=e.submitText||(e.mode===`create`?`Create`:`Update`),Y=e.cancelText||`Cancel`,X={type:`form`,objectName:e.objectName,layout:ne,defaultValues:g,previousValues:e.mode===`edit`&&e.recordId?g:void 0,submitLabel:ie,cancelLabel:Y,showSubmit:q,showCancel:J,onSubmit:te,onCancel:G,onDirtyChange:T,showActions:!1,id:ee},Z=()=>{if(b)return(0,u.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,u.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,u.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:b.message})]});if(v)return(0,u.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,u.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,u.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});if(e.sections?.length){let t=[];return e.sections.forEach((e,n)=>{let r=e.name||String(n),i=z[r]??e.collapsed??!1;t.push({name:`__section_${r}`,label:e.label||``,type:`section-divider`,colSpan:4,collapsible:e.collapsible,collapsed:i,onToggle:e.collapsible?()=>B(e=>({...e,[r]:!i})):void 0,className:e.className});let a=H(e);i?t.push(...a.map(e=>({...e,hidden:!0}))):t.push(...a)}),(0,u.jsx)(r.SchemaRenderer,{schema:{...X,fields:t}})}let t=re(m,f,e.columns,e.mode),n=We[t.columns||1];return(0,u.jsx)(r.SchemaRenderer,{schema:{...X,fields:t.fields,columns:t.columns,...n?{fieldContainerClass:n}:{}}})},Q=e.subforms,oe=Q?.length&&e.mode!==`view`?(0,u.jsx)(Ue,{schema:{type:`object-master-detail-form`,objectName:e.objectName,mode:e.mode===`edit`?`edit`:`create`,recordId:e.recordId,fields:e.fields,sections:e.sections,submitText:e.submitText,cancelText:Y,details:Q,onSuccess:async t=>{await e.onSuccess?.(t),e.onOpenChange?.(!1)},onError:e.onError,onCancel:()=>e.onOpenChange?.(!1)},dataSource:n}):Z();return d?(0,u.jsxs)(`div`,{className:`@container rounded-md border bg-card p-4`,children:[(e.title||e.description)&&(0,u.jsxs)(`div`,{className:`mb-3 space-y-0.5`,children:[e.title&&(0,u.jsx)(`div`,{className:`text-sm font-semibold`,children:e.title}),e.description&&(0,u.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.description})]}),oe]}):(0,u.jsx)(a.Sheet,{open:L,onOpenChange:t=>{if(t){e.onOpenChange?.(!0);return}W(!1)},children:(0,u.jsxs)(a.SheetContent,{side:R,className:(0,a.cn)(`overflow-y-auto`,o,e.className),style:K,children:[(e.title||e.description)&&(0,u.jsxs)(a.SheetHeader,{children:[e.title&&(0,u.jsx)(a.SheetTitle,{children:e.title}),e.description?(0,u.jsx)(a.SheetDescription,{children:e.description}):(0,u.jsx)(a.SheetDescription,{className:`sr-only`,children:l(`form.dialogDescriptionFallback`)})]}),(0,u.jsx)(`div`,{className:`@container py-4`,children:oe}),!b&&!v&&!(Q?.length&&e.mode!==`view`)&&(q||J)&&(0,u.jsx)(`div`,{className:`shrink-0 border-t px-4 py-3 bg-background`,"data-testid":`drawer-form-footer`,children:(0,u.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-2 sm:justify-end`,children:[J&&(0,u.jsx)(a.Button,{type:`button`,variant:`outline`,onClick:G,disabled:M,className:`w-full sm:w-auto`,children:Y}),q&&(0,u.jsxs)(a.Button,{type:`submit`,form:ee,disabled:M,className:`w-full sm:w-auto`,children:[M&&(0,u.jsx)(c.Loader2,{className:`mr-2 h-4 w-4 animate-spin`}),ie]})]})}),(0,u.jsx)(a.AlertDialog,{open:O,onOpenChange:k,children:(0,u.jsxs)(a.AlertDialogContent,{children:[(0,u.jsxs)(a.AlertDialogHeader,{children:[(0,u.jsx)(a.AlertDialogTitle,{children:l(`form.discardTitle`)}),(0,u.jsx)(a.AlertDialogDescription,{children:l(`form.discardMessage`)})]}),(0,u.jsxs)(a.AlertDialogFooter,{children:[(0,u.jsx)(a.AlertDialogCancel,{onClick:()=>{F.current=!1},children:l(`form.keepEditing`)}),(0,u.jsx)(a.AlertDialogAction,{onClick:U,children:l(`form.discard`)})]})]})}),j]})})};function qe(e,t){let n=(0,s.deriveFieldGroupLayout)({fieldGroups:t,fields:Object.fromEntries(e.map(e=>[e.name,{group:e.group}]))});if(!n)return null;let r=new Set(n.flatMap(e=>e.fields)),i=e.map(e=>e.name).filter(e=>!r.has(e)),a=n.map(e=>({...e.key===void 0?{}:{name:e.key},...e.key===void 0?{}:{label:e.label??e.key},fields:[...e.fields],...e.collapse===`none`?{}:{collapsible:!0},...e.collapse===`collapsed`?{collapsed:!0}:{}}));if(i.length>0){let e=a[a.length-1];e&&e.name===void 0?e.fields=[...e.fields??[],...i]:a.push({fields:i})}return a}var Je=(0,l.createSafeTranslation)({"form.discardTitle":`Discard changes?`,"form.discardMessage":`You have unsaved changes. If you close this form now, your edits will be lost.`,"form.dialogDescriptionFallback":`Complete the form fields, then submit or cancel.`,"form.keepEditing":`Keep editing`,"form.discard":`Discard`},`form.discardTitle`),Ye={sm:`sm:max-w-sm`,default:`sm:max-w-lg`,lg:`sm:max-w-2xl`,xl:`sm:max-w-5xl`,full:`sm:max-w-[95vw] sm:w-full`},Xe=({schema:e,dataSource:n,className:s})=>{let{fieldLabel:l,sectionLabel:d}=(0,r.useSafeFieldLabel)(),{t:f}=Je(),p=(0,r.usePreviewMode)(),m=(0,o.usePermissions)(),h=(0,t.useCallback)(t=>{if(!m?.isLoaded)return t;let n=[];for(let r of t){if(!r?.name){n.push(r);continue}m.checkField(e.objectName,r.name,`read`)&&(!m.checkField(e.objectName,r.name,`write`)&&e.mode!==`view`?n.push({...r,readOnly:!0,disabled:!0}):n.push(r))}return n},[m,e.objectName,e.mode]),[g,_]=(0,t.useState)(null),[v,y]=(0,t.useState)([]),[b,x]=(0,t.useState)({}),[S,T]=(0,t.useState)(!0),[O,k]=(0,t.useState)(null),[A,j]=(0,t.useState)(!1),[M,P]=(0,t.useState)(!1),[F,I]=(0,t.useState)(!1),{saveWithOcc:L,conflictDialog:R}=ae(),z=(0,t.useRef)(!1),B=e.confirmOnDiscard!==!1,H=e.open!==!1,U=(0,t.useId)(),K=(0,t.useMemo)(()=>{if(e.sections?.length||e.customFields?.length)return null;let t=te(v,g);e.mode===`create`&&(t=W(t,g));let n=qe(t,g?.fieldGroups);if(!n)return null;let r=e.columns&&e.columns>0?Math.min(Math.floor(e.columns),4):ee(t.length);return n.map(e=>({...e,columns:r}))},[e.sections,e.customFields,e.columns,e.mode,v,g]),q=e.sections?.length?e.sections:K??void 0,J=(0,t.useMemo)(()=>q?.length||e.customFields?.length?null:re(v,g,e.columns,e.mode),[v,g,e.columns,e.mode,q,e.customFields]),ie=Ye[(0,t.useMemo)(()=>{if(e.modalSize)return e.modalSize;if(J?.columns&&J.columns>1)return ne(J.columns);if(q?.length){let e=Math.max(...q.map(e=>Number(e.columns)||1));if(e>1)return ne(e)}return`default`},[e.modalSize,J,q])]||Ye.default;(0,t.useEffect)(()=>{(async()=>{if(!n){T(!1);return}try{let t=await n.getObjectSchema(e.objectName);_(t)}catch(e){k(e),T(!1)}})()},[e.objectName,n]);let Y=(0,t.useRef)(void 0);(0,t.useEffect)(()=>{let t=!1;return(g||!n)&&(async()=>{if(e.mode===`create`||!e.recordId){x(E(g,e.initialData||e.initialValues)),T(!1);return}if(!n){x(e.initialData||e.initialValues||{}),T(!1);return}Y.current!==e.recordId&&(T(!0),P(!1));try{let r=await n.findOne(e.objectName,e.recordId);if(t)return;Y.current=e.recordId,x(r||{})}catch(e){if(t)return;k(e)}finally{t||T(!1)}})(),()=>{t=!0}},[g,e.mode,e.recordId,e.initialData,e.initialValues,n,e.objectName]);let X=(0,t.useCallback)(t=>N(t,{objectSchema:g,objectName:e.objectName,readOnly:e.readOnly,mode:e.mode,recordId:e.recordId,fieldLabel:l}),[g,e.readOnly,e.mode,e.recordId,e.objectName,l]);(0,t.useEffect)(()=>{if(!g&&n)return;if(e.customFields?.length){y(e.customFields),T(!1);return}if(e.sections?.length){T(!1);return}if(!g)return;let t=e.fields||Object.keys(g.fields||{}),r=[];for(let n of t){let t=typeof n==`string`?n:n.name;if(!t)continue;let a=g.fields?.[t];a&&r.push({name:t,label:l(e.objectName,t,a.label||t),type:(0,i.mapFieldTypeToFormType)(a.type,{multiple:a.multiple}),required:w(a,C(e)),disabled:e.readOnly||e.mode===`view`||a.readonly,placeholder:a.placeholder,description:a.help||a.description,validation:(0,i.buildValidationRules)(a),field:a,options:a.options,multiple:a.multiple,visibleWhen:a.visibleWhen,readonlyWhen:a.readonlyWhen,requiredWhen:a.requiredWhen,group:a.group})}y(r),T(!1)},[g,e.fields,e.customFields,e.sections,e.readOnly,e.mode,n]);let Z=(0,t.useCallback)(async t=>{j(!0);try{if(!n)return e.onSuccess&&await e.onSuccess(t),e.onOpenChange?.(!1),t;let r,i=ue(t,g);if(m?.isLoaded){let t={};for(let n of Object.keys(i))m.checkField(e.objectName,n,`write`)&&(t[n]=i[n]);i=t}if(e.mode===`create`)r=await n.create(e.objectName,D(i,g));else if(e.mode===`edit`&&e.recordId){let t=await L({dataSource:n,objectName:e.objectName,recordId:e.recordId,payload:i,baseRecord:b});if(t.status===`cancelled`)return;r=t.result}return e.onSuccess&&await e.onSuccess(r),e.onOpenChange?.(!1),r}catch(t){throw e.onError&&e.onError(t),t}finally{j(!1)}},[e,n,g,m,L,b]),Q=(0,t.useCallback)(()=>{I(!1),z.current&&(z.current=!1,e.onCancel?.()),e.onOpenChange?.(!1)},[e]),oe=(0,t.useCallback)(e=>{z.current=e,B&&M?I(!0):Q()},[B,M,Q]);(0,t.useEffect)(()=>{if(!H||!M||!B)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[H,M,B]);let se=(0,t.useCallback)(()=>{z.current=!0,Q()},[Q]),ce=e.layout===`vertical`||e.layout===`horizontal`?e.layout:`vertical`,$=e.showSubmit!==!1&&e.mode!==`view`,le=e.showCancel!==!1,de=e.submitText||(e.mode===`create`?`Create`:`Update`),fe=e.cancelText||`Cancel`,pe={type:`form`,objectName:e.objectName,layout:ce,defaultValues:b,previousValues:e.mode===`edit`&&e.recordId?b:void 0,submitLabel:de,cancelLabel:fe,showSubmit:$,showCancel:le,onSubmit:Z,onCancel:se,onDirtyChange:P,showActions:!1,id:U},me=()=>{if(O)return(0,u.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,u.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,u.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:O.message})]});if(S)return(0,u.jsx)(`div`,{className:`space-y-4`,"data-testid":`modal-form-skeleton`,children:[1,2,3].map(e=>(0,u.jsxs)(`div`,{className:`space-y-2`,children:[(0,u.jsx)(a.Skeleton,{className:`h-4 w-24`}),(0,u.jsx)(a.Skeleton,{className:`h-10 w-full`})]},e))});if(e.sections?.length){let t=e.sections,n=(e,t)=>e.name||e.label||String(t),i=t=>t.name?d(e.objectName,t.name,t.label||t.name):t.label,a=e=>typeof e==`number`&&e>0?Math.min(Math.floor(e),4):void 0,o=t.map(e=>a(e.columns)).filter(e=>e!=null),s=a(e.columns)??(o.length?Math.max(...o):1),c=G[s],l=t.map((e,t)=>{let r=h(X(e));return{key:n(e,t),title:i(e),description:e.description,className:e.className,gridClassName:e.gridClassName,fields:s>1?V(r,s,a(e.columns)):r}}).filter(e=>e.fields.length>0),f={...pe,columns:s,...c?{fieldContainerClass:c}:{}};if(e.contentLayout===`tabbed`&&l.length>1)return(0,u.jsx)(r.SchemaRenderer,{schema:{...f,fields:l.flatMap(e=>e.fields),fieldTabs:l.map((e,t)=>({key:e.key,label:e.title||`Section ${t+1}`,description:e.description,fields:e.fields.map(e=>e.name),containerClass:e.gridClassName}))}});let p=[];return l.forEach(e=>{(e.title||e.description)&&p.push({name:`__section_${e.key}`,label:e.title,description:e.description,type:`section-divider`,colSpan:4,className:e.className}),p.push(...e.fields)}),(0,u.jsx)(r.SchemaRenderer,{schema:{...f,fields:p}})}if(K?.length){let t=Number(K[0]?.columns)||1,n=[];K.forEach((r,i)=>{let a=h(X(r));if(!a.length)return;let o=r.name?d(e.objectName,r.name,r.label||r.name):r.label;o&&n.push({name:`__section_${r.name||i}`,label:o,type:`section-divider`}),n.push(...t>1?V(a,t):a)});let i=G[t];return(0,u.jsx)(r.SchemaRenderer,{schema:{...pe,fields:n,columns:t,...i?{fieldContainerClass:i}:{}}})}let t=J??re(v,g,e.columns,e.mode),n=G[t.columns||1];return(0,u.jsx)(r.SchemaRenderer,{schema:{...pe,fields:h(t.fields),columns:t.columns,...n?{fieldContainerClass:n}:{}}})},he=e.subforms;if(p)return(0,u.jsxs)(`div`,{className:`@container rounded-md border bg-card p-4`,children:[(e.title||e.description)&&(0,u.jsxs)(`div`,{className:`mb-3 space-y-0.5`,children:[e.title&&(0,u.jsx)(`div`,{className:`text-sm font-semibold`,children:e.title}),e.description&&(0,u.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.description})]}),me()]});if(he?.length&&e.mode!==`view`)return(0,u.jsx)(a.Dialog,{open:H,onOpenChange:e.onOpenChange,children:(0,u.jsxs)(a.MobileDialogContent,{className:(0,a.cn)(ie,`flex flex-col h-[100dvh] sm:h-auto sm:max-h-[90vh] overflow-hidden p-0`,s,e.className),children:[(e.title||e.description)&&(0,u.jsxs)(a.DialogHeader,{className:`shrink-0 px-4 pt-4 sm:px-6 sm:pt-6 pb-2 border-b`,children:[e.title&&(0,u.jsx)(a.DialogTitle,{children:e.title}),e.description?(0,u.jsx)(a.DialogDescription,{children:e.description}):(0,u.jsx)(a.DialogDescription,{className:`sr-only`,children:`Enter the record and its line items, then save.`})]}),(0,u.jsx)(`div`,{className:`@container flex-1 overflow-y-auto px-4 sm:px-6 py-4`,children:(0,u.jsx)(Ue,{schema:{type:`object-master-detail-form`,objectName:e.objectName,mode:e.mode===`edit`?`edit`:`create`,recordId:e.recordId,fields:e.fields,sections:e.sections,initialValues:e.initialValues,initialData:e.initialData,submitText:de,cancelText:fe,details:he,onSuccess:async t=>{await e.onSuccess?.(t),e.onOpenChange?.(!1)},onError:e.onError,onCancel:()=>e.onOpenChange?.(!1)},dataSource:n})})]})});let ge=!S&&!O&&($||le);return(0,u.jsx)(a.Dialog,{open:H,onOpenChange:t=>{if(t){e.onOpenChange?.(!0);return}oe(!1)},children:(0,u.jsxs)(a.MobileDialogContent,{className:(0,a.cn)(ie,`flex flex-col h-[100dvh] sm:h-auto sm:max-h-[90vh] overflow-hidden p-0`,s,e.className),children:[(e.title||e.description)&&(0,u.jsxs)(a.DialogHeader,{className:`shrink-0 px-4 pt-4 sm:px-6 sm:pt-6 pb-2 border-b`,children:[e.title&&(0,u.jsx)(a.DialogTitle,{children:e.title}),e.description?(0,u.jsx)(a.DialogDescription,{children:e.description}):(0,u.jsx)(a.DialogDescription,{className:`sr-only`,children:f(`form.dialogDescriptionFallback`)})]}),(0,u.jsx)(`div`,{className:`@container flex-1 overflow-y-auto px-4 sm:px-6 py-4`,children:me()}),ge&&(0,u.jsx)(`div`,{className:`shrink-0 border-t px-4 sm:px-6 py-3 bg-background`,"data-testid":`modal-form-footer`,children:(0,u.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-2 sm:justify-end`,children:[le&&(0,u.jsx)(a.Button,{type:`button`,variant:`outline`,onClick:se,disabled:A,className:`w-full sm:w-auto`,children:fe}),$&&(0,u.jsxs)(a.Button,{type:`submit`,form:U,disabled:A,className:`w-full sm:w-auto`,children:[A&&(0,u.jsx)(c.Loader2,{className:`mr-2 h-4 w-4 animate-spin`}),de]})]})}),(0,u.jsx)(a.AlertDialog,{open:F,onOpenChange:I,children:(0,u.jsxs)(a.AlertDialogContent,{children:[(0,u.jsxs)(a.AlertDialogHeader,{children:[(0,u.jsx)(a.AlertDialogTitle,{children:f(`form.discardTitle`)}),(0,u.jsx)(a.AlertDialogDescription,{children:f(`form.discardMessage`)})]}),(0,u.jsxs)(a.AlertDialogFooter,{children:[(0,u.jsx)(a.AlertDialogCancel,{onClick:()=>{z.current=!1},children:f(`form.keepEditing`)}),(0,u.jsx)(a.AlertDialogAction,{onClick:Q,children:f(`form.discard`)})]})]})}),R]})})};function Ze(e){let t=e.buttons,n=e.defaults;if(!t&&!n)return e;let r=e,i={...r};return t?.submit?.show!==void 0&&r.showSubmit===void 0&&(i.showSubmit=t.submit.show),t?.submit?.label!=null&&r.submitText===void 0&&(i.submitText=t.submit.label),t?.cancel?.show!==void 0&&r.showCancel===void 0&&(i.showCancel=t.cancel.show),t?.cancel?.label!=null&&r.cancelText===void 0&&(i.cancelText=t.cancel.label),t?.reset?.show!==void 0&&r.showReset===void 0&&(i.showReset=t.reset.show),n&&r.initialValues===void 0&&(i.initialValues=n),i}var Qe=({schema:e,dataSource:n})=>{let i=(0,o.usePermissions)(),a=(0,t.useMemo)(()=>{let t=Ze(e),n=t.groups,r=!t.sections?.length&&Array.isArray(n)&&n.length?{...t,sections:n.map(e=>({label:e.title??e.label,description:e.description,collapsible:e.collapsible,collapsed:e.defaultCollapsed??e.collapsed,fields:e.fields??[]}))}:t;if(!i?.isLoaded)return r;let a=e=>e?.name?i.checkField(r.objectName,e.name,`read`)?!i.checkField(r.objectName,e.name,`write`)&&r.mode!==`view`?{...e,readOnly:!0,disabled:!0}:e:null:e,o=e=>Array.isArray(e)?e.map(a).filter(Boolean):e;return{...r,fields:o(r.fields),sections:r.sections?.map(e=>({...e,fields:o(e.fields)}))}},[e,i]),{sectionLabel:s}=(0,r.useSafeFieldLabel)(),c=e=>e?.name?s(a.objectName,e.name,e.label||e.name):e?.label;if(a.subforms?.length&&a.mode!==`view`&&a.formType!==`drawer`&&a.formType!==`modal`)return(0,u.jsx)(Ue,{schema:{type:`object-master-detail-form`,objectName:a.objectName,mode:a.mode===`edit`?`edit`:`create`,recordId:a.recordId,initialValues:a.initialValues,initialData:a.initialData,formType:a.formType===`tabbed`?`tabbed`:`simple`,sections:a.sections,fields:a.fields,title:a.title,submitText:a.submitText,cancelText:a.cancelText,showSubmit:a.showSubmit,details:a.subforms,onSuccess:a.onSuccess,onError:a.onError,onCancel:a.onCancel,className:a.className},dataSource:n});if(a.formType===`tabbed`&&a.sections?.length)return(0,u.jsx)(X,{schema:{...a,formType:`tabbed`,sections:a.sections.map(e=>({name:e.name,label:c(e),description:e.description,columns:e.columns,fields:e.fields,className:e.className,gridClassName:e.gridClassName})),defaultTab:a.defaultTab,tabPosition:a.tabPosition},dataSource:n,className:a.className});if(a.formType===`wizard`&&a.sections?.length)return(0,u.jsx)(se,{schema:{...a,formType:`wizard`,sections:a.sections.map(e=>({name:e.name,label:c(e),description:e.description,columns:e.columns,fields:e.fields,className:e.className,gridClassName:e.gridClassName})),allowSkip:a.allowSkip,showStepIndicator:a.showStepIndicator,nextText:a.nextText,prevText:a.prevText,onStepChange:a.onStepChange},dataSource:n,className:a.className});if(a.formType===`split`&&a.sections?.length)return(0,u.jsx)(ce,{schema:{...a,formType:`split`,sections:a.sections.map(e=>({name:e.name,label:c(e),description:e.description,columns:e.columns,fields:e.fields,pane:e.pane,className:e.className,gridClassName:e.gridClassName})),splitDirection:a.splitDirection,splitSize:a.splitSize,splitResizable:a.splitResizable},dataSource:n,className:a.className});if(a.formType===`drawer`){let{layout:e,...t}=a,r=a.layout===`vertical`||a.layout===`horizontal`?a.layout:void 0;return(0,u.jsx)(Ke,{schema:{...t,layout:r,formType:`drawer`,sections:a.sections?.map(e=>({name:e.name,label:c(e),description:e.description,columns:e.columns,fields:e.fields,collapsible:e.collapsible,collapsed:e.collapsed,className:e.className})),open:a.open,onOpenChange:a.onOpenChange,drawerSide:a.drawerSide,drawerWidth:a.drawerWidth},dataSource:n,className:a.className})}if(a.formType===`modal`){let{layout:e,...t}=a,r=a.layout===`vertical`||a.layout===`horizontal`?a.layout:void 0;return(0,u.jsx)(Xe,{schema:{...t,layout:r,formType:`modal`,sections:a.sections?.map(e=>({name:e.name,label:c(e),description:e.description,columns:e.columns,fields:e.fields,className:e.className,gridClassName:e.gridClassName})),open:a.open,onOpenChange:a.onOpenChange,modalSize:a.modalSize,modalCloseButton:a.modalCloseButton},dataSource:n,className:a.className})}return(0,u.jsx)($e,{schema:a,dataSource:n})},$e=({schema:e,dataSource:s})=>{let{fieldLabel:c,sectionLabel:l}=(0,r.useSafeFieldLabel)(),d=(0,a.useIsMobile)(),f=(0,o.usePermissions)(),p=(0,t.useCallback)(t=>{if(!f?.isLoaded)return t;let n=[];for(let r of t)f.checkField(e.objectName,r.name,`read`)&&(!f.checkField(e.objectName,r.name,`write`)&&e.mode!==`view`?n.push({...r,readOnly:!0,disabled:!0,description:r.description??`You do not have edit access to this field.`}):n.push(r));return n},[f,e.objectName,e.mode]),[m,h]=(0,t.useState)(null),[g,_]=(0,t.useState)([]),[b,x]=(0,t.useState)(null),[S,E]=(0,t.useState)(!0),[O,k]=(0,t.useState)(null),[A,j]=(0,t.useState)(null),{saveWithOcc:M,conflictDialog:N}=ae(),P=e.customFields&&e.customFields.length>0;(0,t.useEffect)(()=>{P&&(x(e.initialData||e.initialValues||{}),E(!1))},[P,e.initialData,e.initialValues]),(0,t.useEffect)(()=>{P?h({name:e.objectName,fields:{}}):e.objectName&&s?(async()=>{try{if(!s)throw Error(`DataSource is required when using ObjectQL schema fetching (inline fields not provided)`);let t=await s.getObjectSchema(e.objectName);if(!t)throw Error(`No schema found for object "${e.objectName}"`);h(t)}catch(e){k(e),E(!1)}})():P||E(!1)},[e.objectName,s,P]),(0,t.useEffect)(()=>{m&&!P&&(async()=>{if(!e.recordId||e.mode===`create`){x(e.initialData||e.initialValues||{}),E(!1);return}if(!P){if(!s){k(Error(`DataSource is required for fetching record data (inline data not provided)`)),E(!1);return}E(!0);try{let t=await s.findOne(e.objectName,e.recordId);x(t)}catch(e){console.error(`Failed to fetch record:`,e),k(e)}finally{E(!1)}}})()},[e.objectName,e.recordId,e.mode,e.initialValues,e.initialData,s,m,P]);let F=(0,t.useCallback)(e=>e,[]);(0,t.useEffect)(()=>{if(P&&e.customFields){_(e.customFields.map(F)),E(!1);return}if(!m)return;let t=[],r=(0,n.resolveEffectiveCrudAffordances)(m,f?.getObjectApiOperations?.(e.objectName)),a=!(e.mode===`edit`?r.edit:e.mode!==`create`||r.create),o=e.fields||Object.keys(m.fields||{});(Array.isArray(o)?o:Object.keys(o)).forEach(n=>{let r=typeof n==`string`?n:n.name;if(!r)return;let o=m.fields?.[r];if(!o&&!P)return;let s=e.customFields?.find(e=>e.name===r);if(s)t.push(F(s));else if(o){let s={name:r,label:c(e.objectName,r,o.label||n),type:(0,i.mapFieldTypeToFormType)(o.type,{multiple:o.multiple}),required:w(o,C(e)),disabled:e.readOnly||e.mode===`view`||o.readonly||a,placeholder:o.placeholder,description:o.help||o.description,validation:(0,i.buildValidationRules)(o),visibleWhen:o.visibleWhen,readonlyWhen:o.readonlyWhen,requiredWhen:o.requiredWhen,group:o.group,field:o,widget:o.widget};if((o.type===`select`||o.type===`lookup`||o.type===`master_detail`)&&(s.options=o.options||[],s.multiple=o.multiple),(o.type===`number`||o.type===`currency`||o.type===`percent`)&&(s.inputType=`number`,s.min=o.min,s.max=o.max,s.step=o.precision?10**-o.precision:void 0),o.type===`date`&&(s.inputType=`date`),o.type===`datetime`&&(s.inputType=`datetime-local`),(o.type===`text`||o.type===`textarea`||o.type===`markdown`||o.type===`html`)&&(s.maxLength=o.maxLength??o.max_length,s.minLength=o.minLength??o.min_length),(o.type===`file`||o.type===`image`)&&(s.inputType=`file`,s.multiple=o.multiple,s.accept=o.accept?o.accept.join(`,`):void 0,o.max_size)){let e=`Max size: ${(0,i.formatFileSize)(o.max_size)}`;s.description=s.description?`${s.description} (${e})`:e}o.type===`email`&&(s.inputType=`email`),o.type===`phone`&&(s.inputType=`tel`),o.type===`url`&&(s.inputType=`url`),o.type===`password`&&(s.inputType=`password`),o.type===`time`&&(s.inputType=`time`),(o.type===`formula`||o.type===`summary`||o.type===`auto_number`)&&(s.disabled=!0),o.visible_on&&(s.visibleOn=o.visible_on),t.push(s)}}),_(t),!P&&e.recordId&&e.mode!==`create`&&s||E(!1)},[m,e.fields,e.customFields,e.readOnly,e.mode,e.objectName,P,e.recordId,s,f]);let I=(0,t.useCallback)(async(t,n)=>{if(t&&(t.nativeEvent||t._reactName===`onSubmit`)&&(console.warn(`ObjectForm: Received Event instead of data in handleSubmit! This suggests a Form renderer issue.`),n===void 0&&(t={})),P&&!s)return e.onSuccess&&await e.onSuccess(t),t;if(!s)throw Error(`DataSource is required for form submission (inline mode not configured)`);let r=ue(t,P?null:m);if(C(e)&&(r=D(r,P?null:m)),f?.isLoaded&&r&&typeof r==`object`){let t={};for(let n of Object.keys(r))f.checkField(e.objectName,n,`write`)&&(t[n]=r[n]);r=t}try{let t;if(e.submitHandler)t=await e.submitHandler(r);else if(e.mode===`create`)t=await s.create(e.objectName,r);else if(e.mode===`edit`&&e.recordId){let n=await M({dataSource:s,objectName:e.objectName,recordId:e.recordId,payload:r,baseRecord:b});if(n.status===`cancelled`)return;t=n.result}else throw Error(`Invalid form mode or missing record ID`);if(e.onSuccess)await e.onSuccess(t);else if(!e.submitHandler&&e.submitBehavior){let t=e.submitBehavior;switch(t.kind){case`redirect`:v(t.url)&&setTimeout(()=>window.location.assign(t.url),t.delayMs??0);break;case`continue`:break;default:{let n=t.kind===`thank-you`&&t.message?t.message:e.successMessage||(e.mode===`create`?`Created`:`Saved`);a.toast.success(n),j({title:t.kind===`thank-you`?t.title:void 0,message:n});break}}}else if(!e.submitHandler){let n=y(e.navigateOnSuccess,t);if(n)return window.location.assign(n),t;a.toast.success(e.successMessage||(e.mode===`create`?`Created`:`Saved`))}return t}catch(t){throw console.error(`Failed to submit form:`,t),e.onError&&e.onError(t),t}},[e,s,P,f,m,M,b]),L=(0,t.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),R=C(e),z={...t.default.useMemo(()=>R?T(m):{},[m,R]),...b},B=e.mode===`edit`&&e.recordId&&b&&typeof b==`object`?b:void 0,H=t.default.useMemo(()=>{let t=te(g,m);return e.mode===`create`&&(t=W(t,m)),t},[g,m,e.mode]),U=t.default.useMemo(()=>e.sections?.length?null:qe(H,m?.fieldGroups),[e.sections,H,m]),G=e.sections?.length?e.sections:U,[ne,q]=(0,t.useState)({});if(O)return(0,u.jsxs)(`div`,{className:`p-3 sm:p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,u.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,u.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:O.message})]});if(S)return(0,u.jsxs)(`div`,{className:`p-4 sm:p-8 text-center`,children:[(0,u.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,u.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});if(A)return(0,u.jsxs)(`div`,{className:`rounded-md border bg-card p-6 sm:p-8 text-center`,children:[(0,u.jsx)(`h3`,{className:`text-lg font-semibold`,children:A.title??`Thanks!`}),A.message&&(0,u.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:A.message})]});let J=e.layout===`vertical`||e.layout===`horizontal`?e.layout:`vertical`;if(G?.length&&(!e.formType||e.formType===`simple`)){let t=U?H:g,n=e=>typeof e==`number`&&e>0?Math.min(Math.floor(e),4):void 0,i=G.map(e=>n(e.columns)).filter(e=>e!=null),a=G.reduce((e,t)=>e+(Array.isArray(t.fields)?t.fields.length:0),0),o=n(e.columns)??(i.length?Math.max(...i):ee(a)),s=[];G.forEach((r,i)=>{let a=new Map(r.fields.map(e=>[typeof e==`string`?e:e.field??e.name,e])),c=Array.from(a.keys()),u=p(t.filter(e=>c.includes(e.name))).map(e=>{let t=a.get(e.name);if(!t||typeof t!=`object`)return e;let n=t,r={...e};return n.visibleOn!=null&&(r.visibleOn=n.visibleOn),n.colSpan!=null&&(r.colSpan=n.colSpan),n.span!=null&&(r.span=n.span),r});if(u.length===0)return;let d=r.name||r.label||String(i),f=r.name?l(e.objectName,r.name,r.label||r.name):r.label,m=ne[d]??r.collapsed??!1;f&&s.push({name:`__section_${d}`,label:f,type:`section-divider`,colSpan:4,collapsible:r.collapsible,collapsed:m,onToggle:r.collapsible?()=>q(e=>({...e,[d]:!m})):void 0,className:r.className});let h=n(r.columns),g=o>1?V(u,o,h):u;f&&m?s.push(...g.map(e=>({...e,hidden:!0}))):s.push(...g)});let c=s,d=K(o);return(0,u.jsxs)(`div`,{className:`w-full @container`,children:[(0,u.jsx)(r.SchemaRenderer,{schema:{type:`form`,objectName:e.objectName,fields:c,layout:J,columns:o,...d?{fieldContainerClass:d}:{},defaultValues:z,previousValues:B,showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1,submitLabel:e.submitText||(e.mode===`create`?`Create`:`Update`),cancelLabel:e.cancelText,onSubmit:I,onCancel:L}}),N]})}let ie=e.sections?.length,Y=p(g),X=ie?{fields:Y,columns:e.columns}:re(Y,m,e.columns,e.mode),Z=e.mobile,Q=Z?.fullscreenLongText?X.fields.map(e=>{let t=e.type;return t!==`textarea`&&t!==`field:textarea`&&t!==`field:markdown`&&t!==`field:html`?e:e.field?{...e,field:{...e.field,mobile_fullscreen:!0}}:{...e,mobile_fullscreen:!0}}):X.fields,oe=Z?.stepper,ce=Z?.stepperMinFields??8,$=Math.max(1,Z?.stepperFieldsPerStep??1);if(!e.formType&&!ie&&Q.length>=2&&(oe===!0||oe===`auto`&&d&&Q.length>=ce)){let t=Q,n=[];for(let e=0;e<t.length;e+=$){let r=t.slice(e,e+$);n.push({name:`step-${Math.floor(e/$)+1}`,label:r[0]?.label||r[0]?.name||`Step ${Math.floor(e/$)+1}`,fields:r})}return(0,u.jsx)(se,{schema:{...e,formType:`wizard`,sections:n,showStepIndicator:!0},dataSource:s,className:e.className})}let le={type:`form`,objectName:e.objectName,fields:Q,layout:J,columns:X.columns,submitLabel:e.submitText||(e.mode===`create`?`Create`:`Update`),cancelLabel:e.cancelText,showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1,resetOnSubmit:e.showReset||e.submitBehavior?.kind===`continue`||!e.submitBehavior&&e.resetOnSuccess&&e.mode===`create`,defaultValues:z,previousValues:B,onSubmit:I,onCancel:L,className:e.className,mobileStickyActions:!!Z?.stickyActions};return(0,u.jsxs)(`div`,{className:Z?.stickyActions?`w-full pb-20 md:pb-0`:`w-full`,"data-mobile-form":Z?`true`:void 0,children:[(0,u.jsx)(r.SchemaRenderer,{schema:le}),N]})},et={text:200,email:254,url:2048,phone:32,textarea:5e3,markdown:5e3,html:5e3},tt=`_company_website_2`,nt=1500;function rt(e,t=[]){try{let n=new URL(e,typeof window<`u`?window.location.href:`http://localhost`);return typeof window<`u`&&n.origin===window.location.origin?!0:n.protocol!==`https:`&&n.protocol!==`http:`?!1:t.some(e=>{if(e===n.host)return!0;if(e.startsWith(`*.`)){let t=e.slice(1);return n.host.endsWith(t)&&n.host.length>t.length}return!1})}catch{return!1}}function it(e){return e&&e.map(e=>{let t=et[String(e.type||``).toLowerCase()];return!t||(e.maxLength??e.max_length)?e:{...e,maxLength:t}})}var at=({config:e,dataSource:n,prefillParams:r,className:i})=>{let[o,s]=(0,t.useState)(!1),[l,d]=(0,t.useState)(!1),[f,p]=(0,t.useState)(null),[m,h]=(0,t.useState)(!(e.consent?.required??!!e.consent)),[g,_]=(0,t.useState)(null),v=(0,t.useRef)(null),y=(0,t.useRef)(0);(0,t.useEffect)(()=>{o||(y.current=Date.now())},[o]);let b=e.honeypot===!1?null:e.honeypot||tt,x=e.minFillTime??nt,S=(0,t.useMemo)(()=>it(e.customFields),[e.customFields]),C=(0,t.useMemo)(()=>{if(!n||S&&S.length>0||!e.fields||e.fields.length===0)return;let t=async(e,t)=>t;return{...n,create:t,update:(e,t,n)=>Promise.resolve(n),delete:()=>Promise.reject(Error(`Not permitted on public form`))}},[n,S,e.fields]),w=(0,t.useMemo)(()=>{let t={};if(r)for(let[e,n]of Object.entries(r))t[e]=n;if(typeof window<`u`&&e.allowedPrefillFields?.length){let n=new Set(e.allowedPrefillFields);new URLSearchParams(window.location.search).forEach((e,r)=>{n.has(r)&&!(r in t)&&(t[r]=e)})}return Object.keys(t).length>0?t:void 0},[r,e.allowedPrefillFields]),T=(0,t.useCallback)(async t=>{if(e.consent?.required&&!m){_(e.texts?.consentRequired??`Please accept the privacy policy to continue.`);return}if(_(null),b&&v.current?.value){s(!0);return}if(x>0&&Date.now()-y.current<x){p(e.texts?.rateLimited??`Please take a moment to review your answers before submitting.`);return}let r={...t};b&&delete r[b],e.captchaToken&&(r._captcha=e.captchaToken),d(!0),p(null);try{n&&await n.create(e.objectName,r),s(!0);let t=e.thankYouPage?.redirectUrl;if(t){if(rt(t,e.allowedRedirectHosts)){let n=e.thankYouPage?.redirectDelay??3e3;setTimeout(()=>{window.location.href=t},n)}else console.warn(`[EmbeddableForm] Blocked unsafe redirect target:`,t),p(e.texts?.redirectBlocked??null)}}catch(e){p(e instanceof Error?e.message:`Failed to submit form. Please try again.`)}finally{d(!1)}},[n,e,m,b,x]),E=(0,t.useCallback)(()=>{s(!1),p(null)},[]),D=(0,t.useMemo)(()=>{let t={};return e.branding?.backgroundColor&&(t.backgroundColor=e.branding.backgroundColor),t},[e.branding]);if(o){let t=e.thankYouPage,n=e.texts??{},r=Math.ceil((t?.redirectDelay??3e3)/1e3),o=(n.redirecting??`Redirecting in {{seconds}} seconds…`).replace(`{{seconds}}`,String(r));return(0,u.jsx)(`div`,{className:`min-h-screen flex items-center justify-center p-4 bg-gradient-to-b from-muted/40 via-background to-background ${i||``}`,style:D,children:(0,u.jsxs)(`div`,{className:`max-w-md w-full bg-card border rounded-xl shadow-sm p-8 text-center space-y-4`,children:[(0,u.jsx)(`div`,{className:`mx-auto inline-flex h-14 w-14 items-center justify-center rounded-full bg-emerald-50 text-emerald-600 dark:bg-emerald-500/10 dark:text-emerald-400`,children:(0,u.jsx)(c.CheckCircle2,{className:`h-8 w-8`,"aria-hidden":`true`})}),(0,u.jsx)(`h2`,{className:`text-xl font-semibold text-foreground`,children:t?.title||n.thankYouTitle||`Thank You!`}),(0,u.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t?.message||n.thankYouMessage||`Your submission has been received successfully.`}),e.allowMultiple&&(0,u.jsx)(a.Button,{variant:`outline`,size:`sm`,onClick:E,className:`mt-2`,children:n.submitAnother??`Submit Another Response`}),t?.redirectUrl&&(0,u.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o})]})})}let O=e.texts??{},k=!!e.consent?.required,A=`${e.formId}-consent`;return(0,u.jsx)(`div`,{className:`min-h-screen flex items-center justify-center p-4 sm:p-6 bg-gradient-to-b from-muted/40 via-background to-background ${i||``}`,style:D,children:(0,u.jsxs)(`div`,{className:`max-w-2xl w-full bg-card border rounded-xl shadow-sm overflow-hidden`,children:[e.branding?.coverImage&&(0,u.jsx)(`div`,{className:`h-28 sm:h-32 w-full bg-cover bg-center`,style:{backgroundImage:`url(${JSON.stringify(e.branding.coverImage)})`},role:`presentation`}),(0,u.jsxs)(`div`,{className:`px-6 sm:px-8 pt-7 pb-5 border-b bg-muted/20`,style:e.branding?.primaryColor?{borderBottomColor:e.branding.primaryColor}:void 0,children:[e.branding?.logo&&(0,u.jsx)(`img`,{src:e.branding.logo,alt:``,className:`h-8 mb-4`}),e.title&&(0,u.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight text-foreground`,children:e.title}),e.description&&(0,u.jsx)(`p`,{className:`text-sm text-muted-foreground mt-2 leading-relaxed`,children:e.description}),(0,u.jsx)(`p`,{className:`text-[11px] text-muted-foreground/70 mt-3`,"aria-hidden":`true`,children:O.requiredHint??`* Required field`})]}),(0,u.jsxs)(`div`,{className:`relative px-6 sm:px-8 py-6`,children:[f&&(0,u.jsx)(`div`,{role:`alert`,"aria-live":`assertive`,className:`mb-4 p-3 bg-destructive/10 border border-destructive/30 rounded-md text-sm text-destructive`,children:f}),(0,u.jsx)(Qe,{schema:{type:`object-form`,objectName:e.objectName,mode:`create`,fields:e.fields,customFields:S,initialData:w,onSuccess:T,submitText:l?O.submitting??`Submitting...`:O.submit??`Submit`},dataSource:C}),b&&(0,u.jsxs)(`div`,{"aria-hidden":`true`,className:`absolute left-[-10000px] top-auto h-px w-px overflow-hidden`,children:[(0,u.jsx)(`label`,{htmlFor:`${e.formId}-${b}`,children:`Do not fill this field`}),(0,u.jsx)(`input`,{ref:v,id:`${e.formId}-${b}`,type:`text`,name:b,tabIndex:-1,autoComplete:`off`,defaultValue:``})]}),e.consent&&(0,u.jsxs)(`div`,{className:`mt-4`,children:[(0,u.jsxs)(`label`,{className:`flex items-start gap-2 text-sm text-foreground cursor-pointer select-none`,children:[(0,u.jsx)(`input`,{type:`checkbox`,id:A,checked:m,onChange:e=>{h(e.target.checked),e.target.checked&&_(null)},"aria-required":k||void 0,"aria-invalid":g?`true`:void 0,"aria-describedby":g?`${A}-error`:void 0,className:`mt-0.5 h-4 w-4 rounded border-input accent-primary`}),(0,u.jsxs)(`span`,{className:`leading-relaxed`,children:[e.consent.label??O.consentLabelDefault??`I agree to the privacy policy.`,k&&(0,u.jsx)(`span`,{"aria-hidden":`true`,className:`text-destructive ml-0.5`,children:`*`}),e.consent.privacyUrl&&(0,u.jsxs)(u.Fragment,{children:[` `,(0,u.jsx)(`a`,{href:e.consent.privacyUrl,target:`_blank`,rel:`noopener noreferrer`,className:`underline text-primary hover:opacity-80`,children:O.consentLink??`Privacy policy`})]})]})]}),g&&(0,u.jsx)(`p`,{id:`${A}-error`,role:`alert`,className:`mt-1.5 text-xs text-destructive`,children:g})]}),l&&(0,u.jsxs)(`div`,{className:`mt-3 flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,u.jsx)(c.Loader2,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":`true`}),(0,u.jsx)(`span`,{children:O.submitting??`Submitting…`})]})]}),(0,u.jsxs)(`div`,{className:`px-6 sm:px-8 py-4 border-t bg-muted/20 flex flex-col sm:flex-row items-center justify-between gap-2`,children:[(0,u.jsxs)(`p`,{className:`inline-flex items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,u.jsx)(c.Lock,{className:`h-3 w-3`,"aria-hidden":`true`}),(0,u.jsx)(`span`,{children:O.secureNotice??`Your information is transmitted securely and only used to respond to your request.`})]}),(0,u.jsxs)(`div`,{className:`flex items-center gap-3 text-xs text-muted-foreground/80`,children:[e.privacyPolicyUrl&&(0,u.jsxs)(`a`,{href:e.privacyPolicyUrl,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1 underline hover:text-foreground`,children:[(0,u.jsx)(c.ShieldCheck,{className:`h-3 w-3`,"aria-hidden":`true`}),O.consentLink??`Privacy policy`]}),(0,u.jsx)(`span`,{children:O.poweredBy??`Powered by ObjectStack`})]})]})]})})};function ot(e){return e<60?`${Math.round(e)}s`:e<3600?`${Math.floor(e/60)}m ${Math.round(e%60)}s`:`${Math.floor(e/3600)}h ${Math.floor(e%3600/60)}m`}var st=({formId:e,formTitle:n,metrics:r,className:i})=>{let o=(0,t.useMemo)(()=>{if(!r.abandonedSubmissions)return 100;let e=r.totalSubmissions+r.abandonedSubmissions;return e===0?0:Math.round(r.totalSubmissions/e*100)},[r.totalSubmissions,r.abandonedSubmissions]),s=(0,t.useMemo)(()=>r.dailySubmissions?.length?Math.max(...r.dailySubmissions.map(e=>e.count),1):1,[r.dailySubmissions]);return(0,u.jsxs)(`div`,{className:`space-y-4 ${i||``}`,children:[(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`h2`,{className:`text-lg font-semibold text-foreground`,children:n||`Form Analytics`}),(0,u.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Form ID: `,e]})]}),(0,u.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-4`,children:[(0,u.jsx)(a.Card,{children:(0,u.jsxs)(a.CardHeader,{className:`pb-2`,children:[(0,u.jsx)(a.CardDescription,{children:`Total Submissions`}),(0,u.jsx)(a.CardTitle,{className:`text-2xl`,children:r.totalSubmissions.toLocaleString()})]})}),(0,u.jsxs)(a.Card,{children:[(0,u.jsxs)(a.CardHeader,{className:`pb-2`,children:[(0,u.jsx)(a.CardDescription,{children:`Fill Rate`}),(0,u.jsxs)(a.CardTitle,{className:`text-2xl`,children:[o,`%`]})]}),(0,u.jsx)(a.CardContent,{children:(0,u.jsx)(`div`,{className:`w-full bg-muted rounded-full h-2`,children:(0,u.jsx)(`div`,{className:`bg-primary rounded-full h-2 transition-all`,style:{width:`${o}%`}})})})]}),(0,u.jsx)(a.Card,{children:(0,u.jsxs)(a.CardHeader,{className:`pb-2`,children:[(0,u.jsx)(a.CardDescription,{children:`Avg. Completion Time`}),(0,u.jsx)(a.CardTitle,{className:`text-2xl`,children:r.avgCompletionTime?ot(r.avgCompletionTime):`—`})]})})]}),r.dailySubmissions&&r.dailySubmissions.length>0&&(0,u.jsxs)(a.Card,{children:[(0,u.jsx)(a.CardHeader,{children:(0,u.jsx)(a.CardTitle,{className:`text-sm font-medium`,children:`Daily Submissions`})}),(0,u.jsx)(a.CardContent,{children:(0,u.jsx)(`div`,{className:`flex items-end gap-1 h-32`,children:r.dailySubmissions.map((e,t)=>(0,u.jsxs)(`div`,{className:`flex-1 flex flex-col items-center gap-1`,children:[(0,u.jsx)(`div`,{className:`w-full bg-primary/80 rounded-t transition-all hover:bg-primary`,style:{height:`${e.count/s*100}%`,minHeight:e.count>0?`4px`:`0`},title:`${e.date}: ${e.count} submissions`}),(0,u.jsx)(`span`,{className:`text-[10px] text-muted-foreground truncate w-full text-center`,children:e.date.slice(-5)})]},t))})})]}),r.fieldDropOff&&r.fieldDropOff.length>0&&(0,u.jsxs)(a.Card,{children:[(0,u.jsxs)(a.CardHeader,{children:[(0,u.jsx)(a.CardTitle,{className:`text-sm font-medium`,children:`Field Completion Rates`}),(0,u.jsx)(a.CardDescription,{children:`Percentage of users who completed each field`})]}),(0,u.jsx)(a.CardContent,{children:(0,u.jsx)(`div`,{className:`space-y-3`,children:r.fieldDropOff.map((e,t)=>(0,u.jsxs)(`div`,{className:`space-y-1`,children:[(0,u.jsxs)(`div`,{className:`flex justify-between text-sm`,children:[(0,u.jsx)(`span`,{className:`text-foreground`,children:e.label}),(0,u.jsxs)(`span`,{className:`text-muted-foreground`,children:[e.completionRate,`%`]})]}),(0,u.jsx)(`div`,{className:`w-full bg-muted rounded-full h-1.5`,children:(0,u.jsx)(`div`,{className:`rounded-full h-1.5 transition-all ${e.completionRate>=80?`bg-green-500`:e.completionRate>=50?`bg-yellow-500`:`bg-destructive`}`,style:{width:`${e.completionRate}%`}})})]},t))})})]})]})},ct=({schema:e})=>{let o=(0,r.useSchemaContext)()?.dataSource,s=(0,r.useRecordContext)(),c=e.parentObject||s?.objectName,l=e.parentId||e.recordId||s?.recordId,[d,f]=(0,t.useState)([]),[p,m]=(0,t.useState)([]),[h,g]=(0,t.useState)(!0),[_,v]=(0,t.useState)(!1),[y,b]=(0,t.useState)(!1),[x,S]=(0,t.useState)(null),[C,w]=(0,t.useState)(null);(0,t.useEffect)(()=>{let t=o;if(!t||typeof t.getObjectSchema!=`function`)return;let n=!1;return t.getObjectSchema(e.childObject).then(e=>{n||w(e??null)}).catch(()=>{n||w(null)}),()=>{n=!0}},[o,e.childObject]);let T=JSON.stringify(e.filter??null),E=JSON.stringify(e.sort??null),D=(0,t.useMemo)(()=>(0,n.toFilterNode)(e.filter),[T]),O=(0,t.useMemo)(()=>(0,n.convertSortToQueryParams)(e.sort),[E]),k=(0,t.useCallback)(async()=>{if(!o||!l){g(!1);return}g(!0);try{let t={[e.relationshipField]:l},r=(await o.find(e.childObject,{$filter:D===void 0?t:(0,n.mergeFilterNodes)(t,D),...O?{$orderby:O}:{},$top:e.limit??500}))?.data??[];f(r.map(e=>({...e}))),m(r.map(e=>({...e}))),b(!1)}catch(e){S(e?.message||`Failed to load line items`)}finally{g(!1)}},[o,l,e.childObject,e.relationshipField,e.limit,D,O]);(0,t.useEffect)(()=>{k()},[k]);let A=(0,t.useCallback)(e=>{f(e),b(!0)},[]),j=(0,t.useCallback)(async()=>{if(!(!o||!l)){v(!0),S(null);try{let t=!!(c&&e.totalField),r=t?{[e.totalField]:ve(d,e.amountField||`amount`)}:{},i=ge(c??``,l,r,[{childObject:e.childObject,relationshipField:e.relationshipField,rows:d,original:p,childSchema:C}]);t||(i=i.slice(1)),i.length&&await(0,n.runBatchTransaction)(o,i),await k()}catch(e){S(e?.message||`Failed to save line items`)}finally{v(!1)}}},[o,l,d,p,e,c,k,C]),M=(0,t.useMemo)(()=>({columns:e.columns,total_field:e.totalField?e.amountField||`amount`:void 0,min_rows:e.minRows,max_rows:e.maxRows,allow_add:!e.readonly,allow_delete:!e.readonly}),[e]);return(0,u.jsxs)(a.Card,{className:(0,a.cn)(`shadow-none`),children:[(0,u.jsxs)(a.CardHeader,{className:`flex-row items-center justify-between gap-2 pb-2`,children:[(0,u.jsx)(a.CardTitle,{className:`text-sm font-medium`,children:e.title||`Line Items`}),!e.readonly&&(0,u.jsx)(a.Button,{type:`button`,size:`sm`,onClick:j,disabled:_||h||!y||!l,children:_?`Saving…`:`Save`})]}),(0,u.jsxs)(a.CardContent,{children:[x&&(0,u.jsx)(`p`,{className:`mb-2 text-sm text-destructive`,children:x}),h?(0,u.jsx)(`p`,{className:`py-6 text-center text-sm text-muted-foreground`,children:`Loading…`}):l?(0,u.jsx)(i.LineItemsField,{value:d,onChange:A,field:M,readonly:e.readonly}):(0,u.jsx)(`p`,{className:`py-6 text-center text-sm text-muted-foreground`,children:`Save the record first to add line items.`})]})]})},lt=({schema:e})=>{let n=(0,t.useContext)(r.SchemaRendererContext)?.dataSource??void 0;return(0,u.jsx)(r.ElementDataSourceGate,{schema:e,dataSource:n,testId:`object-form`,errorTitle:`This form’s data source could not be resolved`,children:e=>(0,u.jsx)(Qe,{schema:e,dataSource:n})})};n.ComponentRegistry.register(`object-form`,lt,{namespace:`plugin-form`,label:`Object Form`,category:`plugin`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`fields`,type:`array`,label:`Fields`},{name:`mode`,type:`enum`,label:`Mode`,enum:[`create`,`edit`,`view`]},{name:`formType`,type:`enum`,label:`Form Type`,enum:[`simple`,`tabbed`,`wizard`,`split`,`drawer`,`modal`]},{name:`sections`,type:`array`,label:`Sections`},{name:`title`,type:`string`,label:`Title`},{name:`description`,type:`string`,label:`Description`},{name:`layout`,type:`enum`,label:`Layout`,enum:[`vertical`,`horizontal`,`inline`,`grid`]},{name:`columns`,type:`number`,label:`Columns`},{name:`defaultTab`,type:`string`,label:`Default Tab`},{name:`tabPosition`,type:`enum`,label:`Tab Position`,enum:[`top`,`bottom`,`left`,`right`]},{name:`allowSkip`,type:`boolean`,label:`Allow Skip Steps`},{name:`showStepIndicator`,type:`boolean`,label:`Show Step Indicator`},{name:`splitDirection`,type:`enum`,label:`Split Direction`,enum:[`horizontal`,`vertical`]},{name:`splitSize`,type:`number`,label:`Split Panel Size (%)`},{name:`splitResizable`,type:`boolean`,label:`Split Resizable`},{name:`drawerSide`,type:`enum`,label:`Drawer Side`,enum:[`top`,`bottom`,`left`,`right`]},{name:`drawerWidth`,type:`string`,label:`Drawer Width`},{name:`modalSize`,type:`enum`,label:`Modal Size`,enum:[`sm`,`default`,`lg`,`xl`,`full`]}]}),n.ComponentRegistry.register(`form`,lt,{namespace:`view`,skipFallback:!0,label:`Data Form View`,category:`view`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`fields`,type:`array`,label:`Fields`},{name:`mode`,type:`enum`,label:`Mode`,enum:[`create`,`edit`,`view`]}]}),n.ComponentRegistry.register(`embeddable-form`,({schema:e})=>{let n=(0,t.useContext)(r.SchemaRendererContext);return(0,u.jsx)(r.ElementDataSourceGate,{schema:e,dataSource:n?.dataSource,testId:`embeddable-form`,errorTitle:`This form’s data source could not be resolved`,children:e=>(0,u.jsx)(at,{config:e,dataSource:n?.dataSource})})},{namespace:`plugin-form`,label:`Embeddable Form`,category:`plugin`,inputs:[{name:`formId`,type:`string`,label:`Form ID`,required:!0},{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`title`,type:`string`,label:`Form Title`},{name:`description`,type:`string`,label:`Description`},{name:`fields`,type:`array`,label:`Fields`},{name:`allowMultiple`,type:`boolean`,label:`Allow Multiple Submissions`}]}),n.ComponentRegistry.register(`form-analytics`,({schema:e})=>(0,u.jsx)(st,{formId:e.formId,formTitle:e.formTitle,metrics:e.metrics||{totalSubmissions:0}}),{namespace:`plugin-form`,label:`Form Analytics`,category:`plugin`,inputs:[{name:`formId`,type:`string`,label:`Form ID`,required:!0},{name:`formTitle`,type:`string`,label:`Form Title`},{name:`metrics`,type:`object`,label:`Submission Metrics`}]}),n.ComponentRegistry.register(`object-master-detail-form`,({schema:e})=>{let n=(0,t.useContext)(r.SchemaRendererContext)?.dataSource??void 0;return(0,u.jsx)(r.ElementDataSourceGate,{schema:e,dataSource:n,testId:`object-master-detail-form`,errorTitle:`This form’s data source could not be resolved`,children:e=>(0,u.jsx)(Ue,{schema:e,dataSource:n})})},{namespace:`plugin-form`,label:`Master-Detail Form`,category:`plugin`,inputs:[{name:`objectName`,type:`string`,label:`Parent Object`,required:!0},{name:`mode`,type:`enum`,label:`Mode`,enum:[`create`,`edit`]},{name:`sections`,type:`array`,label:`Parent Sections`},{name:`details`,type:`array`,label:`Detail Collections`,required:!0}]});var ut={object:`childObject`,filter:!0,sort:!0,limit:`limit`};n.ComponentRegistry.register(`line_items`,({schema:e})=>(0,u.jsx)(r.ElementDataSourceGate,{schema:e,mapping:ut,testId:`record-line-items`,errorTitle:`This line-items panel’s data source could not be resolved`,children:e=>(0,u.jsx)(ct,{schema:e})}),{namespace:`record`,skipFallback:!0,label:`Line Items`,category:`record`,inputs:[{name:`childObject`,type:`string`,label:`Child Object`,required:!0},{name:`relationshipField`,type:`string`,label:`Relationship Field`,required:!0},{name:`columns`,type:`array`,label:`Columns`,required:!0},{name:`totalField`,type:`string`,label:`Parent Total Field`},{name:`amountField`,type:`string`,label:`Amount Column`}]}),e.DrawerForm=Ke,e.EmbeddableForm=at,e.FormAnalytics=st,e.FormSectionContainer=Z,e.LineItemsPanel=ct,e.MasterDetailForm=Ue,e.ModalForm=Xe,e.ObjectForm=Qe,e.SplitForm=ce,e.TabbedForm=X,e.WizardForm=se,e.applyAutoColSpan=V,e.applyAutoLayout=re,e.containerGridColsFor=K,e.deriveColumns=je,e.deriveDetail=Be,e.deriveFormFields=Pe,e.filterAutoGeneratedFields=W,e.filterCreateModeFields=U,e.filterSystemFields=te,e.findRelationshipField=Ee,e.inferColumns=ee,e.inferModalSize=ne,e.isAutoGeneratedFieldType=R,e.isWideFieldType=L,e.resolveInlineMode=Le});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("react"),require("@object-ui/core"),require("@object-ui/react"),require("@object-ui/fields"),require("@object-ui/components"),require("@objectstack/spec/ui"),require("@object-ui/permissions"),require("@objectstack/spec/data"),require("lucide-react"),require("@object-ui/i18n"),require("react/jsx-runtime")):typeof define==`function`&&define.amd?define([`exports`,`react`,`@object-ui/core`,`@object-ui/react`,`@object-ui/fields`,`@object-ui/components`,`@objectstack/spec/ui`,`@object-ui/permissions`,`@objectstack/spec/data`,`lucide-react`,`@object-ui/i18n`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ObjectUIPluginForm={},e.React,e._object_ui_core,e._object_ui_react,e._object_ui_fields,e._object_ui_components,e._objectstack_spec_ui,e._object_ui_permissions,e._objectstack_spec_data,e.lucide_react,e._object_ui_i18n,e.react_jsx_runtime))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var f=Object.create,p=Object.defineProperty,m=Object.getOwnPropertyDescriptor,h=Object.getOwnPropertyNames,g=Object.getPrototypeOf,_=Object.prototype.hasOwnProperty,v=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=h(t),a=0,o=i.length,s;a<o;a++)s=i[a],!_.call(e,s)&&s!==n&&p(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=m(t,s))||r.enumerable});return e};t=((e,t,n)=>(n=e==null?{}:f(g(e)),v(t||!e||!e.__esModule||!_.call(e,`default`)?p(n,`default`,{value:e,enumerable:!0}):n,e)))(t,1);function y(e){try{return typeof window>`u`?!1:new URL(e,window.location.href).origin===window.location.origin}catch{return!1}}function b(e,t){if(!e)return null;let n=t?.id??t?.recordId??t?._id;if(n==null||n===``)return null;let r=e.replace(/\{(?:id|recordId)\}/g,String(n));return y(r)?r:null}var x=/\{\{record\.([a-z_][a-z0-9_]*)\}\}/g;function S(e){return e==null?``:typeof e==`string`?e:typeof e==`boolean`||typeof e==`number`&&Number.isFinite(e)?String(e):``}function C(e,t){let n=e=>e&&typeof e==`object`&&!Array.isArray(e)?e:{};return{...n(e),...n(t)}}function w(e,t){let n=o.FormViewSchema.safeParse({submitBehavior:{kind:`redirect`,url:e}});if(!n.success)return{ok:!1,refusal:n.error.issues.find(e=>e.path[0]===`submitBehavior`&&e.path[1]===`url`)?.message??n.error.issues[0]?.message??`\`submitBehavior.url\` is not a value this contract accepts: ${JSON.stringify(e)}.`};let r=n.data.submitBehavior,i=(r?.kind===`redirect`?r.url:e).replace(x,(e,n)=>encodeURIComponent(S(t[n])));return i.includes(`{`)||i.includes(`}`)?{ok:!1,refusal:`\`submitBehavior.url\` carries an interpolation this renderer could not resolve (${JSON.stringify(e)}). A token names one declared record field, spelled \`{{record.field_name}}\`, and the redirect is refused rather than followed with the token left in it.`}:{ok:!0,url:i}}function T(e){let{navigate:n}=(0,r.useHostNavigation)(),i=(0,t.useRef)(n);(0,t.useEffect)(()=>{i.current=n},[n]),(0,t.useEffect)(()=>{if(!e)return;let t=setTimeout(()=>{let t=i.current;if(t){t(e.url);return}window.location.assign(e.url)},e.delayMs);return()=>clearTimeout(t)},[e])}var E=`https://a.invalid/`,D=`https://b.invalid/`;function O(e){try{return new URL(e,E).origin===`https://a.invalid`&&new URL(e,D).origin===`https://b.invalid`}catch{return!1}}function k(e){let{navigate:n}=(0,r.useHostNavigation)(),i=(0,t.useRef)(n);(0,t.useEffect)(()=>{i.current=n},[n]),(0,t.useEffect)(()=>{if(!e)return;let t=setTimeout(()=>{let t=O(e.url)?i.current:void 0;if(t){t(e.url);return}window.location.href=e.url},e.delayMs);return()=>clearTimeout(t)},[e])}function A(e){return e!=null&&!(0,n.isRuntimeDefault)(e)}function j(e){return e?.mode===`create`||!e?.recordId}function M(e,t){return!(!e?.required||t&&(0,n.isRuntimeDefault)(e.defaultValue))}function N(e,t){let n=e?.fields;if(!n||typeof n!=`object`)return{};let r={};for(let e of Object.keys(n)){let i=n[e],a=i?.defaultValue;A(a)?r[e]=a:P(i)&&t?.currentUserId&&(r[e]=t.currentUserId)}return r}function P(e){return!e||!(0,c.isCurrentUserDefaultToken)(e.defaultValue)?!1:e.type===`user`||e.type===`lookup`&&(e.reference===`sys_user`||e.reference_to===`sys_user`)}function F(e,t,n){return{...N(e,n),...t??{}}}function ee(e,t){if(!e||typeof e!=`object`)return e;let r=t?.fields;if(!r||typeof r!=`object`)return e;let i={};for(let[t,a]of Object.entries(e))(0,n.isRuntimeDefault)(r[t]?.defaultValue)&&(0,n.isMissingForRequired)(a)||(i[t]=a);return i}function I(e,t){return typeof t==`string`&&t.trim()||typeof t==`object`&&t&&typeof t.source==`string`&&t.source.trim()?{...e,visibleOn:t}:e}var L=new Set;function R(e,t){if(typeof e.name!=`string`||e.name===e.field)return;let n=`${t}:${e.field}:${e.name}`;L.has(n)||(L.add(n),console.warn(`[object-ui] section field { field: '${e.field}' } also carries name: '${e.name}' — mixed form-field vocabularies. The spec key wins (the runtime name becomes '${e.field}'); drop \`name\` from authored form views.`))}function z(e,t){let n=t.objectSchema?.fields?.[e];return n?{name:e,label:t.fieldLabel(t.objectName,e,n.label||e),type:(0,i.mapFieldTypeToFormType)(n.type,{multiple:n.multiple}),required:M(n,j(t)),disabled:t.readOnly||t.mode===`view`||n.readonly,placeholder:n.placeholder,description:n.help||n.description,validation:(0,i.buildValidationRules)(n),field:n,options:n.options,multiple:n.multiple,visibleWhen:n.visibleWhen,readonlyWhen:n.readonlyWhen,requiredWhen:n.requiredWhen}:{name:e,label:e,type:`input`}}function B(e,t){if(typeof e==`string`){let n=t.objectSchema?.fields?.[e];return I(z(e,t),n?.visible_on??n?.visibleOn)}let n=e;if(typeof n.field!=`string`)return I(n,n.visibleOn);R(n,t.objectName);let r=n.field,a=z(r,t);n.widget!=null&&(a.widget=n.widget),n.label!=null&&(a.label=n.label),n.placeholder!=null&&(a.placeholder=n.placeholder),n.helpText!=null&&(a.description=n.helpText),n.required!=null&&(a.required=M({required:n.required,defaultValue:t.objectSchema?.fields?.[r]?.defaultValue},j(t))),n.readonly!=null&&(a.disabled=n.readonly||a.disabled),n.immutable!=null&&(a.immutable=n.immutable),n.hidden!=null&&(a.hidden=n.hidden),n.colSpan!=null&&(a.colSpan=n.colSpan),n.span!=null&&(a.span=n.span),n.options!=null&&(a.options=n.options),n.multiple!=null&&(a.multiple=n.multiple);let o=n.type??t.objectSchema?.fields?.[r]?.type;o!=null&&(a.type=(0,i.mapFieldTypeToFormType)(o,{multiple:a.multiple}));let s=n.reference??n.reference_to;return s!=null&&(a.reference=s,a.reference_to=s),n.maxLength!=null&&(a.maxLength=n.maxLength),n.minLength!=null&&(a.minLength=n.minLength),n.min!=null&&(a.min=n.min),n.max!=null&&(a.max=n.max),n.precision!=null&&(a.precision=n.precision),n.scale!=null&&(a.scale=n.scale),n.language!=null&&(a.language=n.language),Array.isArray(n.fields)&&(a.fields=n.fields),n.dependsOn!=null&&(a.dependsOn=n.dependsOn),n.keyField!=null&&(a.keyField=n.keyField),n.disclosure!=null&&(a.disclosure=n.disclosure),I(a,n.visibleWhen??n.visibleOn)}function te(e,t){return(e.fields??[]).map(e=>B(e,t))}var V=new Set([`field:formula`,`field:summary`,`field:auto_number`,`field:autonumber`]),ne=new Set([`field:textarea`,`field:markdown`,`field:html`,`field:grid`,`field:richtext`,`textarea`,`markdown`,`html`,`grid`,`richtext`]),re=new Set([`formula`,`summary`,`auto_number`,`autonumber`]);function H(e){return ne.has(e)}function U(e){return re.has(e)}function ie(e){return e<=3?1:e<=8?2:e<=15?3:4}function W(e){return e&&e>0?Math.min(Math.floor(e),4):1}function G(e,t,n){let r=W(t);return r<=1?1:e.span===`full`?r:e.colSpan==null?e.type&&H(e.type)?r:Math.min(r,Math.max(1,Math.round(r/Math.min(Math.max(1,Math.floor(n||r)),r)))):Math.min(Math.max(1,Math.floor(e.colSpan)),r)}function K(e,t,n){let r=W(t);return r<=1?e:e.map(e=>{if(e.type===`section-divider`)return e;let t=G(e,r,n);return t>1?{...e,colSpan:t}:e.colSpan!=null&&e.colSpan!==1?{...e,colSpan:1}:e})}var ae=new Set([`id`,`created_at`,`createdAt`,`updated_at`,`updatedAt`,`last_modified_at`,`lastModifiedAt`,`deleted_at`,`deletedAt`,`created_by`,`createdBy`,`updated_by`,`updatedBy`,`last_modified_by`,`lastModifiedBy`,`organization_id`,`organizationId`,`org_id`,`orgId`,`tenant_id`,`tenantId`,`owner`,`owner_id`,`_version`,`_rev`]);function oe(e,t){return e.filter(e=>{if(ae.has(e.name))return!1;let n=t?.fields?.[e.name];return n?.hidden!==!0&&n?.readonly!==!0})}function q(e,t){return e.filter(e=>{if(ae.has(e.name)||e.type&&V.has(e.type))return!1;if(!t?.fields)return!0;let n=t.fields[e.name];return!n||n.readonly!==!0&&!U(n.type)})}function se(e,t){return e.filter(e=>{if(e.type&&V.has(e.type))return!1;let n=t?.fields?.[e.name];return!n||!U(n.type)})}var J={1:void 0,2:`grid gap-4 grid-cols-1 @md:grid-cols-2`,3:`grid gap-4 grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3`,4:`grid gap-4 grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3 @4xl:grid-cols-4`};function Y(e){return J[e&&e>0?Math.min(Math.floor(e),4):1]}function ce(e){return e<=1?`default`:e===2?`xl`:`full`}function le(e,t,n,r){let i=[...e];if(i=oe(i,t),r===`create`&&(i=se(i,t)),n!==void 0)return i=K(i,n),{fields:i,columns:n};let a=ie(i.length);return i=K(i,a),{fields:i,columns:a}}var X=(0,u.createSafeTranslation)({"form.conflictTitle":`Save conflict`,"form.conflictMessage":`This record was changed by someone else while you were editing. Overwriting will replace their changes with yours.`,"form.conflictLatestVersion":`Their save: {{time}}`,"form.conflictOverwrite":`Overwrite`,"form.keepEditing":`Keep editing`},`form.conflictTitle`);function Z(e){let t=e?.updated_at;return typeof t==`string`&&t.length>0?t:void 0}function Q(e){if(!e||typeof e!=`object`)return!1;let t=e;return t.code===`CONCURRENT_UPDATE`||t.name===`ConcurrentUpdateError`}function ue(e){if(!e)return null;let t=/\d{4}-\d{2}-\d{2}[ T]/.test(e)?e.replace(` `,`T`):e,n=new Date(t);return Number.isNaN(n.getTime())?null:n.toLocaleString()}function de(){let{t:e}=X(),[n,r]=t.useState(null),i=t.useRef(null),o=t.useCallback(e=>{i.current?.(e),i.current=null,r(null)},[]);t.useEffect(()=>()=>i.current?.(!1),[]);let s=t.useCallback(async({dataSource:e,objectName:t,recordId:n,payload:a,baseRecord:o})=>{let s=Z(o);try{return{status:`saved`,result:await e.update(t,n,a,s?{ifMatch:s}:void 0)}}catch(o){if(!Q(o))throw o;let s=o.currentVersion;if(!await new Promise(e=>{i.current=e,r({currentVersion:typeof s==`string`?s:void 0})}))return{status:`cancelled`};let c=typeof s==`string`&&s.length>0?s:void 0;return{status:`saved`,result:await e.update(t,n,a,c?{ifMatch:c}:void 0)}}},[]),c=ue(n?.currentVersion);return{saveWithOcc:s,conflictDialog:(0,d.jsx)(a.AlertDialog,{open:!!n,onOpenChange:e=>{e||o(!1)},children:(0,d.jsxs)(a.AlertDialogContent,{children:[(0,d.jsxs)(a.AlertDialogHeader,{children:[(0,d.jsxs)(a.AlertDialogTitle,{className:`flex items-center gap-2`,children:[(0,d.jsx)(l.AlertTriangle,{className:`h-5 w-5 text-amber-500`,"aria-hidden":!0}),e(`form.conflictTitle`)]}),(0,d.jsxs)(a.AlertDialogDescription,{children:[e(`form.conflictMessage`),c&&(0,d.jsx)(`span`,{className:`mt-2 block text-xs text-muted-foreground`,children:e(`form.conflictLatestVersion`,{time:c})})]})]}),(0,d.jsxs)(a.AlertDialogFooter,{children:[(0,d.jsx)(`button`,{type:`button`,className:(0,a.cn)((0,a.buttonVariants)({variant:`outline`})),onClick:()=>o(!1),children:e(`form.keepEditing`)}),(0,d.jsx)(`button`,{type:`button`,className:(0,a.cn)((0,a.buttonVariants)({variant:`destructive`})),onClick:()=>o(!0),children:e(`form.conflictOverwrite`)})]})]})})}}var $=({schema:e,dataSource:n,className:i})=>{let{fieldLabel:o}=(0,r.useSafeFieldLabel)(),{userId:c}=(0,s.usePermissions)(),[l,u]=(0,t.useState)(null),[f,p]=(0,t.useState)({}),{saveWithOcc:m,conflictDialog:h}=de(),[g,_]=(0,t.useState)(!0),[v,y]=(0,t.useState)(null),b=e.defaultTab||e.sections[0]?.name||e.sections[0]?.label||`tab-0`;t.default.useEffect(()=>{(async()=>{if(!n){_(!1);return}try{let t=await n.getObjectSchema(e.objectName);u(t)}catch(e){y(e)}})()},[e.objectName,n]);let x=(0,t.useRef)(void 0);t.default.useEffect(()=>{let t=!1;return(l||!n)&&(async()=>{if(e.mode===`create`||!e.recordId||!n){p(F(l,e.initialData||e.initialValues,{currentUserId:c})),_(!1);return}x.current!==e.recordId&&_(!0);try{let r=await n.findOne(e.objectName,e.recordId);if(t)return;x.current=e.recordId,p(r||{})}catch(e){if(t)return;y(e)}finally{t||_(!1)}})(),()=>{t=!0}},[l,e.mode,e.recordId,e.initialData,e.initialValues,n,e.objectName]);let S=(0,t.useCallback)(t=>te(t,{objectSchema:l,objectName:e.objectName,readOnly:e.readOnly,mode:e.mode,recordId:e.recordId,fieldLabel:o}),[l,e.readOnly,e.mode,e.recordId,e.objectName,o]),C=(0,t.useCallback)(async t=>{if(!n)return e.onSuccess&&await e.onSuccess(t),t;try{let r;if(e.mode===`create`)r=await n.create(e.objectName,ee(t,l));else if(e.mode===`edit`&&e.recordId){let i=await m({dataSource:n,objectName:e.objectName,recordId:e.recordId,payload:t,baseRecord:f});if(i.status===`cancelled`)return;r=i.result}return e.onSuccess&&await e.onSuccess(r),r}catch(t){throw e.onError&&e.onError(t),t}},[e,n,m,f]),w=(0,t.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),T=(e,t)=>e.name||e.label||`tab-${t}`;if(v)return(0,d.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,d.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,d.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:v.message})]});if(g)return(0,d.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,d.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,d.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let E=e=>typeof e==`number`&&e>0?Math.min(Math.floor(e),4):void 0,D=e.sections.map(e=>E(e.columns)).filter(e=>e!=null),O=E(e.columns)??(D.length?Math.max(...D):1),k=Y(O),A=e.sections.map((e,t)=>{let n=S(e);return{key:T(e,t),label:e.label||`Tab ${t+1}`,description:e.description,containerClass:e.gridClassName,fields:O>1?K(n,O,E(e.columns)):n}}),j=A.flatMap(e=>e.fields);return(0,d.jsxs)(`div`,{className:(0,a.cn)(`w-full @container`,i,e.className),children:[(0,d.jsx)(r.SchemaRenderer,{schema:{type:`form`,objectName:e.objectName,fields:j,columns:O,...k?{fieldContainerClass:k}:{},layout:`vertical`,defaultValues:f,previousValues:e.mode===`edit`&&e.recordId?f:void 0,submitLabel:e.submitText||(e.mode===`create`?`Create`:`Update`),cancelLabel:e.cancelText,showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1,onSubmit:C,onCancel:w,fieldTabs:A.map(e=>({key:e.key,label:e.label,description:e.description,fields:e.fields.map(e=>e.name),containerClass:e.containerClass})),defaultFieldTab:b,fieldTabsPosition:e.tabPosition||`top`}}),h]})},fe=({label:e,description:n,collapsible:r=!1,collapsed:i=!1,columns:o=1,children:s,className:c,gridClassName:u,showBorder:f})=>{let[p,m]=(0,t.useState)(i),h={1:`grid-cols-1`,2:`grid-cols-1 md:grid-cols-2`,3:`grid-cols-1 md:grid-cols-2 lg:grid-cols-3`,4:`grid-cols-1 md:grid-cols-2 lg:grid-cols-4`},g=()=>{r&&m(!p)},_=f??!!e,v=e||n?(0,d.jsxs)(`div`,{className:(0,a.cn)(`flex items-start gap-2`,!_&&`mb-4`,r&&`cursor-pointer select-none`),onClick:g,role:r?`button`:void 0,"aria-expanded":r?!p:void 0,children:[r&&(0,d.jsx)(`span`,{className:`mt-0.5 text-muted-foreground`,children:p?(0,d.jsx)(l.ChevronRight,{className:`h-4 w-4`}):(0,d.jsx)(l.ChevronDown,{className:`h-4 w-4`})}),(0,d.jsxs)(`div`,{className:`flex-1`,children:[e&&(0,d.jsx)(`h3`,{className:`text-sm font-semibold text-foreground`,children:e}),n&&(0,d.jsx)(`p`,{className:`text-sm text-muted-foreground mt-0.5`,children:n})]})]}):null,y=p?null:(0,d.jsx)(`div`,{className:(0,a.cn)(`grid gap-4`,u||h[o]),children:s});return _?(0,d.jsxs)(a.Card,{className:(0,a.cn)(`form-section bg-muted/40 shadow-none`,c),children:[v&&(0,d.jsx)(a.CardHeader,{className:`border-b border-border pb-3`,children:v}),y&&(0,d.jsx)(a.CardContent,{className:`pt-4`,children:y})]}):(0,d.jsxs)(`div`,{className:(0,a.cn)(`form-section`,c),children:[v,y]})},pe="The `navigateOnSuccess` destination declared for this form was refused, so the navigation did not happen.",me=(0,u.createSafeTranslation)({"wizard.missingRequired":`Please complete the required fields: {{fields}}`},`wizard.missingRequired`),he=n.isMissingForRequired,ge=({schema:e,dataSource:i,className:o})=>{let{fieldLabel:c}=(0,r.useSafeFieldLabel)(),{userId:u}=(0,s.usePermissions)(),{t:f}=me(),[p,m]=(0,t.useState)(null),[h,g]=(0,t.useState)({}),[_,v]=(0,t.useState)(void 0),{saveWithOcc:y,conflictDialog:x}=de(),[S,E]=(0,t.useState)(!0),[D,k]=(0,t.useState)(null),[A,M]=(0,t.useState)(0),[N,P]=(0,t.useState)(new Set),[I,L]=(0,t.useState)(!1),[R,z]=(0,t.useState)(new Set),[B,V]=(0,t.useState)(null),[ne,re]=(0,t.useState)(null);T(ne);let H=t.default.useId(),[U,ie]=(0,t.useState)(0),W=t.default.useRef(!1),G=e.sections.length,ae=A===0,oe=A===G-1;t.default.useEffect(()=>{(async()=>{if(!i){E(!1);return}try{let t=await i.getObjectSchema(e.objectName);m(t)}catch(e){k(e)}})()},[e.objectName,i]),t.default.useEffect(()=>{(p||!i)&&(async()=>{if(e.mode===`create`||!e.recordId||!i){W.current||=(g(F(p,e.initialData||e.initialValues,{currentUserId:u})),!0),E(!1);return}try{let t=await i.findOne(e.objectName,e.recordId);g(t||{}),v(t||{})}catch(e){k(e)}finally{E(!1)}})()},[p,e.mode,e.recordId,e.initialData,e.initialValues,i,e.objectName]);let q=(0,t.useCallback)(t=>te(t,{objectSchema:p,objectName:e.objectName,readOnly:e.readOnly,mode:e.mode,recordId:e.recordId,fieldLabel:c}),[p,e.readOnly,e.mode,e.recordId,e.objectName,c]),se=j(e),J=(0,t.useMemo)(()=>A>=0&&A<G?q(e.sections[A]):[],[A,G,e.sections,q]),ce=(0,t.useCallback)(t=>{let r=new Map;return e.sections.forEach((e,i)=>{for(let a of q(e)){let e=a?.name;if(!e||a.hidden===!0)continue;let o=(0,n.resolveFieldRuleState)({visibleWhen:a.visibleWhen,readonlyWhen:a.readonlyWhen,requiredWhen:a.requiredWhen},t,{required:!!a.required,readonly:a.readonly===!0,serverOwnedValue:(0,n.isServerOwnedValue)(a,se)},void 0,void 0,`field '${e}'`);!(a.visibleOn==null||(0,n.evalFieldPredicate)(a.visibleOn,t,!0,void 0,void 0,{context:`visibleOn of field '${e}'`}))||!o.visible||o.readonly||!o.required||he(t[e])&&r.set(i,[...r.get(i)??[],a.label||e])}}),r},[e.sections,q,se]),le=(0,t.useCallback)(async t=>{let n={...h,...t};if(g(n),P(e=>new Set(e).add(A)),z(e=>{if(!e.has(A))return e;let t=new Set(e);return t.delete(A),t}),oe){let t=ce(n);if(t.size>0){z(new Set(t.keys()));let e=[...t.values()].flat();a.toast.error(f(`wizard.missingRequired`,{fields:e.slice(0,3).join(`, `)+(e.length>3?`…`:``)})),X(Math.min(...t.keys()));return}z(new Set),L(!0);try{if(!i)return e.onSuccess&&await e.onSuccess(n),n;let t;if(e.mode===`create`)t=await i.create(e.objectName,ee(n,p));else if(e.mode===`edit`&&e.recordId){let r=await y({dataSource:i,objectName:e.objectName,recordId:e.recordId,payload:n,baseRecord:h});if(r.status===`cancelled`)return;t=r.result}if(e.onSuccess)await e.onSuccess(t);else if(e.submitBehavior){let r=e.submitBehavior;switch(r.kind){case`redirect`:{let i=w(r.url,C(n,t));if(!i.ok){a.toast.error(i.refusal),V({message:e.successMessage||(e.mode===`create`?`Created`:`Saved`),refusal:i.refusal});break}re({url:i.url,delayMs:r.delayMs??0});break}case`continue`:g(F(p,e.initialData||e.initialValues,{currentUserId:u})),P(new Set),M(0),ie(e=>e+1);break;default:{let t=r.kind===`thank-you`&&r.message?r.message:e.successMessage||(e.mode===`create`?`Created`:`Saved`);a.toast.success(t),V({title:r.kind===`thank-you`?r.title:void 0,message:t});break}}}else{let n=b(e.navigateOnSuccess,t);if(n)return O(n)?re({url:n,delayMs:0}):window.location.assign(n),t;e.navigateOnSuccess?(console.warn("[WizardForm] `navigateOnSuccess` was declared but produced no destination:",e.navigateOnSuccess),a.toast.success(e.successMessage||(e.mode===`create`?`Created`:`Saved`),{description:pe})):a.toast.success(e.successMessage||(e.mode===`create`?`Created`:`Saved`)),e.resetOnSuccess&&e.mode===`create`&&(g(F(p,e.initialData||e.initialValues,{currentUserId:u})),P(new Set),M(0),ie(e=>e+1))}return t}catch(t){throw e.onError&&e.onError(t),t}finally{L(!1)}}X(A+1)},[h,A,oe,e,p,i,ce,f,y]),X=(0,t.useCallback)(t=>{t>=0&&t<G&&(M(t),e.onStepChange&&e.onStepChange(t))},[G,e]),Z=(0,t.useCallback)(()=>{X(A-1)},[A,X]),Q=(0,t.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),ue=(0,t.useCallback)(t=>{(e.allowSkip||N.has(t)||t<=A)&&X(t)},[e.allowSkip,N,A,X]);if(D)return(0,d.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,d.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,d.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:D.message})]});if(S)return(0,d.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,d.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,d.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});if(B)return(0,d.jsxs)(`div`,{className:(0,a.cn)(`w-full space-y-4`,o,e.className),children:[(0,d.jsxs)(`div`,{className:`rounded-md border bg-card p-8 text-center`,children:[(0,d.jsx)(`h3`,{className:`text-lg font-semibold`,children:B.title??`Thanks!`}),B.message&&(0,d.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:B.message})]}),B.refusal&&(0,d.jsx)(`div`,{role:`alert`,className:`rounded-md border border-destructive/40 bg-destructive/10 p-4 text-sm text-destructive`,children:B.refusal})]});let $=e.sections[A],ge=e=>typeof e==`number`&&e>0?Math.min(Math.floor(e),4):void 0,_e=ge(e.columns)??ge($?.columns)??1,ve=Y(_e);return(0,d.jsxs)(`div`,{className:(0,a.cn)(`w-full @container`,o,e.className),children:[e.showStepIndicator!==!1&&(0,d.jsx)(`nav`,{"aria-label":`Progress`,className:`mb-8`,children:(0,d.jsx)(`ol`,{className:`flex items-center`,children:e.sections.map((t,n)=>{let r=n===A,i=N.has(n),o=e.allowSkip||i||n<=A,s=R.has(n);return(0,d.jsxs)(`li`,{className:(0,a.cn)(`relative flex-1`,n!==G-1&&`pr-8 sm:pr-12`),children:[n!==G-1&&(0,d.jsx)(`div`,{className:`absolute top-3 sm:top-4 left-6 -right-4 sm:left-10 sm:-right-2 h-0.5`,"aria-hidden":`true`,children:(0,d.jsx)(`div`,{className:(0,a.cn)(`h-full`,i?`bg-primary`:`bg-muted`)})}),(0,d.jsxs)(`button`,{type:`button`,className:(0,a.cn)(`group relative flex items-center`,o?`cursor-pointer`:`cursor-not-allowed`),onClick:()=>ue(n),disabled:!o,"data-testid":`wizard-step:${t.name||n}`,"data-error":s||void 0,children:[(0,d.jsx)(`span`,{className:(0,a.cn)(`flex h-6 w-6 sm:h-8 sm:w-8 items-center justify-center rounded-full text-xs sm:text-sm font-medium transition-colors`,s&&`border-2 border-destructive bg-background text-destructive`,!s&&i&&`bg-primary text-primary-foreground`,!s&&r&&!i&&`border-2 border-primary bg-background text-primary`,!s&&!r&&!i&&`border-2 border-muted bg-background text-muted-foreground`),children:s?(0,d.jsx)(l.AlertCircle,{className:`h-3 w-3 sm:h-4 sm:w-4`,"aria-hidden":!0}):i?(0,d.jsx)(l.Check,{className:`h-3 w-3 sm:h-4 sm:w-4`}):n+1}),(0,d.jsx)(`span`,{className:`ml-2 sm:ml-3 text-xs sm:text-sm font-medium hidden sm:block`,children:(0,d.jsx)(`span`,{className:(0,a.cn)(s?`text-destructive`:r?`text-foreground`:`text-muted-foreground`),children:t.label||`Step ${n+1}`})})]})]},n)})})}),(0,d.jsx)(`div`,{className:`min-h-[200px]`,children:$&&(0,d.jsx)(fe,{label:$.label,description:$.description,columns:1,className:$.className,gridClassName:$.gridClassName,children:J.length>0?(0,d.jsx)(r.SchemaRenderer,{schema:{type:`form`,objectName:e.objectName,id:H,fields:_e>1?K(J,_e,ge($.columns)):J,columns:_e,...ve?{fieldContainerClass:ve}:{},layout:`vertical`,defaultValues:h,previousValues:e.mode===`edit`?_:void 0,showSubmit:!1,showCancel:!1,onSubmit:le}},U):(0,d.jsx)(`form`,{id:H,onSubmit:e=>{e.preventDefault(),le({})},children:(0,d.jsx)(`div`,{className:`text-center py-8 text-muted-foreground`,children:`No fields configured for this step`})})})}),(0,d.jsxs)(`div`,{className:`flex items-center justify-between mt-6 pt-4 border-t`,children:[(0,d.jsx)(`div`,{children:e.showCancel!==!1&&(0,d.jsx)(a.Button,{variant:`ghost`,onClick:Q,children:e.cancelText||`Cancel`})}),(0,d.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,d.jsxs)(`span`,{className:`text-sm text-muted-foreground mr-2`,children:[`Step `,A+1,` of `,G]}),!ae&&(0,d.jsxs)(a.Button,{variant:`outline`,onClick:Z,children:[(0,d.jsx)(l.ChevronLeft,{className:`h-4 w-4 mr-1`}),e.prevText||`Back`]}),oe?(0,d.jsxs)(a.Button,{type:`submit`,form:H,disabled:I||e.mode===`view`,children:[I&&(0,d.jsx)(l.Loader2,{className:`mr-2 h-4 w-4 animate-spin`,"aria-hidden":!0}),I?`Submitting...`:e.submitText||(e.mode===`create`?`Create`:`Update`)]}):(0,d.jsxs)(a.Button,{type:`submit`,form:H,children:[e.nextText||`Next`,(0,d.jsx)(l.ChevronRight,{className:`h-4 w-4 ml-1`})]})]})]}),x]})},_e=({schema:e,dataSource:n,className:i})=>{let{fieldLabel:o}=(0,r.useSafeFieldLabel)(),{userId:c}=(0,s.usePermissions)(),[l,u]=(0,t.useState)(null),[f,p]=(0,t.useState)({}),{saveWithOcc:m,conflictDialog:h}=de(),[g,_]=(0,t.useState)(!0),[v,y]=(0,t.useState)(null);(0,t.useEffect)(()=>{(async()=>{if(!n){_(!1);return}try{let t=await n.getObjectSchema(e.objectName);u(t)}catch(e){y(e),_(!1)}})()},[e.objectName,n]);let b=(0,t.useRef)(void 0);(0,t.useEffect)(()=>{let t=!1;return(l||!n)&&(async()=>{if(e.mode===`create`||!e.recordId){p(F(l,e.initialData||e.initialValues,{currentUserId:c})),_(!1);return}if(!n){p(e.initialData||e.initialValues||{}),_(!1);return}b.current!==e.recordId&&_(!0);try{let r=await n.findOne(e.objectName,e.recordId);if(t)return;b.current=e.recordId,p(r||{})}catch(e){if(t)return;y(e)}finally{t||_(!1)}})(),()=>{t=!0}},[l,e.mode,e.recordId,e.initialData,e.initialValues,n,e.objectName]);let x=(0,t.useCallback)(t=>te(t,{objectSchema:l,objectName:e.objectName,readOnly:e.readOnly,mode:e.mode,recordId:e.recordId,fieldLabel:o}),[l,e.readOnly,e.mode,e.recordId,e.objectName,o]),S=(0,t.useCallback)(async t=>{if(!n)return e.onSuccess&&await e.onSuccess(t),t;try{let r;if(e.mode===`create`)r=await n.create(e.objectName,ee(t,l));else if(e.mode===`edit`&&e.recordId){let i=await m({dataSource:n,objectName:e.objectName,recordId:e.recordId,payload:t,baseRecord:f});if(i.status===`cancelled`)return;r=i.result}return e.onSuccess&&await e.onSuccess(r),r}catch(t){throw e.onError&&e.onError(t),t}},[e,n,m,f]),C=(0,t.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),w=(e,t)=>e.pane===`primary`||e.pane===`secondary`?e.pane:t===0?`primary`:`secondary`,T=(0,t.useMemo)(()=>e.sections.filter((e,t)=>w(e,t)===`primary`),[e.sections]),E=(0,t.useMemo)(()=>e.sections.filter((e,t)=>w(e,t)===`secondary`),[e.sections]),D=e.splitDirection||`horizontal`,O=e.splitSize||50;if(v)return(0,d.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,d.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,d.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:v.message})]});if(g)return(0,d.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,d.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,d.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let k=e=>typeof e==`number`&&e>0?Math.min(Math.floor(e),4):void 0,A=e.sections.map(e=>k(e.columns)).filter(e=>e!=null),j=k(e.columns)??(A.length?Math.max(...A):1),M=Y(j),N=(e,t)=>{let n=[];return e.forEach((e,r)=>{let i=x(e);i.length&&((e.label||e.description)&&n.push({name:`__section_${e.name||`${t}_${r}`}`,label:e.label,description:e.description,type:`section-divider`,colSpan:4,className:e.className}),n.push(...j>1?K(i,j,k(e.columns)):i))}),n},P=[{key:`primary`,sections:T,defaultSize:O},{key:`secondary`,sections:E,defaultSize:100-O}].map(e=>({...e,fields:N(e.sections,e.key),containerClass:e.sections.length===1?e.sections[0].gridClassName:void 0})).filter(e=>e.fields.length>0);return(0,d.jsxs)(`div`,{className:(0,a.cn)(`w-full @container`,i,e.className),children:[(0,d.jsx)(r.SchemaRenderer,{schema:{type:`form`,objectName:e.objectName,fields:P.flatMap(e=>e.fields),columns:j,...M?{fieldContainerClass:M}:{},layout:`vertical`,defaultValues:f,previousValues:e.mode===`edit`&&e.recordId?f:void 0,submitLabel:e.submitText||(e.mode===`create`?`Create`:`Update`),cancelLabel:e.cancelText,showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1,onSubmit:S,onCancel:C,fieldPanes:P.map(e=>({key:e.key,fields:e.fields.map(e=>e.name),defaultSize:e.defaultSize,...e.containerClass?{containerClass:e.containerClass}:{}})),fieldPanesOrientation:D,fieldPanesResizable:e.splitResizable!==!1}}),h]})},ve=new Set([`id`,`_id`,`created_at`,`updated_at`,`createdAt`,`updatedAt`,`organization_id`,`organizationId`]),ye=new Set([`formula`,`summary`,`rollup`,`lookup_value`,`auto_number`,`autonumber`,`computed`]);function be(e,t){if(!e||typeof e!=`object`)return e;let n={},r=t?.fields;for(let[t,i]of Object.entries(e))if(!ve.has(t)){if(r){let e=r[t];if(!e)continue;let n=String(e.type||``).toLowerCase();if(ye.has(n)||e.computed===!0||e.formula||e.readOnly===!0||e.readonly===!0)continue}n[t]=i}return n}var xe=e=>e==null?void 0:e.id??e._id??e.recordId,Se=(e,t)=>t?be(e,t):e,Ce=new Set([`id`,`_id`,`recordId`]);function we(e,t){return!e||Object.entries(e).every(([e,n])=>e===t||Ce.has(e)?!0:n==null||n===``)}function Te(e,t,n){let r=[{object:e,action:`create`,data:t}];for(let e of n)for(let t of e.rows)we(t,e.relationshipField)||r.push({object:e.childObject,action:`create`,data:{...Se(t,e.childSchema),[e.relationshipField]:{$ref:0}}});return r}function Ee(e,t,n,r){let i=[{object:e,action:`update`,id:t,data:n}];for(let e of r){let n=(e.rows||[]).map(n=>({...n,[e.relationshipField]:t})),{toCreate:r,toUpdate:a,toDelete:o}=De(e.original||[],n);for(let t of r){if(we(t,e.relationshipField))continue;let{id:n,_id:r,recordId:a,...o}=t;i.push({object:e.childObject,action:`create`,data:Se(o,e.childSchema)})}for(let t of a)i.push({object:e.childObject,action:`update`,id:xe(t),data:Se(t,e.childSchema)});for(let t of o)i.push({object:e.childObject,action:`delete`,id:t})}return i}function De(e,t){let n=new Set(t.map(xe).filter(Boolean));return{toCreate:t.filter(e=>!xe(e)),toUpdate:t.filter(e=>xe(e)),toDelete:(e||[]).map(xe).filter(e=>!!e&&!n.has(e))}}function Oe(e,t){return Array.isArray(e)?e.reduce((e,n)=>{let r=Number(n?.[t]);return e+(Number.isFinite(r)?r:0)},0):0}var ke=new Set([`id`,`_id`,`recordId`,`created_at`,`updated_at`,`created_by`,`updated_by`,`createdAt`,`updatedAt`,`createdBy`,`updatedBy`,`organization_id`,`tenant_id`,`space`,`owner`]),Ae=new Set([`position`,`sort_order`,`sequence`,`line_no`,`line_number`,`sort`]),je=new Set([`formula`,`summary`,`rollup`,`autonumber`,`auto_number`,`json`,`object`,`grid`,`table`,`location`,`vector`,`html`,`markdown`,`richtext`]);function Me(e){switch(e){case`number`:case`percent`:case`rating`:case`slider`:return`number`;case`currency`:return`currency`;case`date`:return`date`;case`datetime`:return`datetime`;case`time`:return`time`;case`select`:case`picklist`:case`radio`:case`boolean`:case`toggle`:return`select`;case`lookup`:case`master_detail`:return`lookup`;case`file`:case`image`:case`avatar`:return`file`;default:return`text`}}var Ne=new Set([`image`,`avatar`]);function Pe(e,t){e.multiple==null&&t?.multiple&&(e.multiple=!0),e.accept??(Array.isArray(t?.accept)&&t.accept.length>0?e.accept=t.accept:Ne.has(t?.type)&&(e.accept=[`image/*`]))}function Fe(e){if(e?.type===`boolean`||e?.type===`toggle`)return[{label:`Yes`,value:`true`},{label:`No`,value:`false`}];let t=e?.options;if(Array.isArray(t))return t.map(e=>typeof e==`object`&&e?{label:String(e.label??e.value),value:String(e.value)}:{label:String(e),value:String(e)})}function Ie(e,t){let n=e?.fields;if(!n||typeof n!=`object`)return;let r;for(let[e,i]of Object.entries(n)){let n=i;if(n?.reference===t){if(n?.type===`master_detail`)return e;n?.type===`lookup`&&!r&&(r=e)}}return r}var Le=[`name`,`title`,`subject`,`label`,`full_name`,`display_name`,`code`],Re={select:0,currency:1,number:1,lookup:2,date:3,datetime:3,time:3,text:4};function ze(e){return(e.type?Re[e.type]:void 0)??5}function Be(e,t){if(t<=0||e.length<=t)return e;let n=new Set,r=e.find(e=>Le.includes(e.name))??e[0];r&&n.add(r.name);for(let t of e)t.required&&n.add(t.name);let i=e.map((e,t)=>({c:e,i:t})).filter(({c:e})=>!n.has(e.name)).sort((e,t)=>ze(e.c)-ze(t.c)||e.i-t.i);for(let{c:e}of i){if(n.size>=t)break;n.add(e.name)}return e.map(e=>n.has(e.name)?e:{...e,defaultHidden:!0})}function Ve(e,t={}){let n=e?.fields;if(!n||typeof n!=`object`)return[];let r=new Set([...t.exclude??[],...t.relationshipField?[t.relationshipField]:[]]),i=[];for(let[e,t]of Object.entries(n)){let n=t;if(ke.has(e)||r.has(e)||Ae.has(e)||n?.system||n?.readonly||n?.hidden||je.has(n?.type))continue;let a={name:e,label:n?.label||e,type:Me(n?.type),required:!!n?.required},o=Fe(n);a.type===`select`&&o&&(a.options=o),a.type===`lookup`&&(a.reference=n?.reference,a.displayField=n?.display_field||n?.reference_field),a.type===`file`&&Pe(a,n),n?.readonlyWhen&&(a.readonlyWhen=n.readonlyWhen),n?.requiredWhen&&(a.requiredWhen=n.requiredWhen);let s=typeof n?.expression==`string`?n.expression:n?.expression?.source;s&&typeof s==`string`&&(a.computed=!0,a.expr=s,a.required=!1,typeof n?.scale==`number`&&(a.scale=n.scale)),i.push(a)}return Be(i,t.maxColumns??6)}function He(e,t){let n=e??[],r=t?.fields;return!n.length||!r||typeof r!=`object`?n:n.map(e=>{if(e.type)return e;let t=r[e.name];if(!t)return e;let n=Me(t?.type),i={...e,type:n};i.label??=t?.label||e.name,i.required??=!!t?.required;let a=Fe(t);n===`select`&&a&&!i.options&&(i.options=a),n===`lookup`&&(i.reference??=t?.reference,i.displayField??=t?.display_field||t?.reference_field),n===`file`&&Pe(i,t),i.readonlyWhen==null&&t?.readonlyWhen&&(i.readonlyWhen=t.readonlyWhen),i.requiredWhen==null&&t?.requiredWhen&&(i.requiredWhen=t.requiredWhen);let o=typeof t?.expression==`string`?t.expression:t?.expression?.source;return!i.computed&&o&&typeof o==`string`&&(i.computed=!0,i.expr=o,i.required=!1,typeof t?.scale==`number`&&(i.scale=t.scale)),i})}var Ue=new Set([`formula`,`summary`,`rollup`,`autonumber`,`auto_number`]);function We(e,t={}){let n=e?.fields;if(!n||typeof n!=`object`)return[];let r=new Set([...t.exclude??[],...t.relationshipField?[t.relationshipField]:[]]),i=[];for(let[e,t]of Object.entries(n)){let n=t;ke.has(e)||r.has(e)||Ae.has(e)||n?.system||n?.hidden||Ue.has(n?.type)||i.push(e)}return i}var Ge=new Set([`textarea`,`richtext`,`html`,`markdown`,`rich-text`,`json`,`location`,`address`]),Ke=new Set([`file`,`image`,`avatar`]);function qe(e,t,n={}){if(t===`grid`||t===`form`)return t;let r=e?.fields??{},i=We(e,{relationshipField:n.relationshipField});return i.some(e=>Ge.has(r[e]?.type))||i.filter(e=>Ke.has(r[e]?.type)).length>=2||i.length>8?`form`:`grid`}var Je=[`amount`,`total`,`subtotal`,`line_total`,`line_amount`,`net_amount`];function Ye(e){let t=e.filter(e=>e.type===`number`||e.type===`currency`);if(t.length===0)return;let n=t.find(e=>e.computed);if(n)return n.name;let r=t.find(e=>Je.includes(e.name));if(r)return r.name;let i=[...t].reverse().find(e=>e.type===`currency`);return i?i.name:t[t.length-1].name}function Xe(e,t,n,r={}){let i=r.relationshipField||Ie(t,n);if(!i)throw Error(`MasterDetailForm: could not find a lookup/master_detail field on "${e}" referencing "${n}". Set relationshipField explicitly.`);let a=r.columns?.length?He(r.columns,t):Ve(t,{relationshipField:i}),o=r.amountField||Ye(a);return{childObject:e,relationshipField:i,columns:a,formFields:We(t,{relationshipField:i}),mode:qe(t,r.inlineEdit??(t?.fields)?.[i]?.inlineEdit,{relationshipField:i}),amountField:o,sortField:Object.keys(t?.fields??{}).find(e=>Ae.has(e))}}function Ze(e){if(!e)return{};let t={};return e.querySelectorAll(`[name]`).forEach(e=>{let n=e.getAttribute(`name`);if(n){if(e.tagName===`INPUT`){let r=e;if(r.type===`checkbox`){t[n]=r.checked;return}if(r.type===`radio`){r.checked&&(t[n]=r.value);return}if(r.type===`number`||r.type===`range`){if(r.value===``){t[n]=null;return}let e=Number(r.value);t[n]=Number.isFinite(e)?e:r.value;return}t[n]=r.value;return}t[n]=e.value}}),t}var Qe=({details:e,state:n,setRows:r,formHostRef:a,taxRateField:o,formKey:s,onRowExpand:c,onAddViaForm:l})=>{let[u,f]=(0,t.useState)({}),p=(0,t.useRef)(``);(0,t.useEffect)(()=>{let e=a.current;if(!e)return;let t=()=>{let t=Ze(e),n;try{n=JSON.stringify(t)}catch{n=String(Math.random())}n!==p.current&&(p.current=n,f(t))};t();let n=()=>t();e.addEventListener(`input`,n),e.addEventListener(`change`,n);let r=[120,360,800].map(e=>setTimeout(t,e));return()=>{e.removeEventListener(`input`,n),e.removeEventListener(`change`,n),r.forEach(clearTimeout)}},[a,s,e.length]);let m=u[o],h=m===void 0?null:Number.isFinite(Number(m))?Number(m):0,g=e.reduce((e,t,r)=>e+Oe(n[r]?.rows??[],t.amountField||`amount`),0),_=h!==null&&e.some(e=>!!e.amountField),v=h??0,y=v/100*g,b=g+y,x=e=>`¥${e.toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2})}`;return(0,d.jsxs)(d.Fragment,{children:[e.map((e,t)=>(0,d.jsxs)(`section`,{className:`space-y-2`,children:[(0,d.jsx)(`h3`,{className:`text-sm font-medium text-foreground`,children:e.title||`Line Items`}),e.columns?.length?(0,d.jsx)(i.LineItemsField,{value:n[t]?.rows??[],onChange:e=>r(t,e),contextRecord:u,...e.inlineMode===`form`||(e.formFields?.length??0)>(e.columns?.length??0)?{onRowExpand:e=>c(t,e)}:{},displayMode:e.inlineMode===`form`?`list`:`grid`,...e.inlineMode===`form`?{onAdd:()=>l(t)}:{},field:{columns:e.columns,total_field:_?void 0:e.amountField||(e.totalField?`amount`:void 0),sort_field:e.sortField,min_rows:e.minRows,max_rows:e.maxRows,add_label:e.inlineMode===`form`?e.addLabel||`Add`:e.addLabel}}):(0,d.jsx)(`p`,{className:`py-4 text-sm text-muted-foreground`,children:`Loading columns…`})]},`${e.childObject}-${t}`)),_&&(0,d.jsx)(`div`,{className:`flex justify-end`,children:(0,d.jsxs)(`dl`,{className:`w-64 space-y-1.5 text-sm`,"data-testid":`md-totals`,children:[(0,d.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,d.jsx)(`dt`,{className:`text-muted-foreground`,children:`Subtotal`}),(0,d.jsx)(`dd`,{className:`tabular-nums`,"data-testid":`md-subtotal`,children:x(g)})]}),(0,d.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,d.jsxs)(`dt`,{className:`text-muted-foreground`,children:[`Tax (`,v,`%)`]}),(0,d.jsx)(`dd`,{className:`tabular-nums`,"data-testid":`md-tax`,children:x(y)})]}),(0,d.jsxs)(`div`,{className:`flex items-center justify-between border-t border-border pt-1.5 text-base font-semibold`,children:[(0,d.jsx)(`dt`,{children:`Total`}),(0,d.jsx)(`dd`,{className:`tabular-nums`,"data-testid":`md-grand-total`,children:x(b)})]})]})})]})},$e=({schema:e,dataSource:r,className:i})=>{let o=e.details||[],s=e.mode===`edit`&&!!e.recordId,c=o.some(e=>!e.relationshipField||!e.columns?.length||e.columns.some(e=>!e.type)),[l,u]=(0,t.useState)(c?null:o),f=l??o;(0,t.useEffect)(()=>{if(!c){u(o);return}if(!r||typeof r.getObjectSchema!=`function`)return;let t=!1;return(async()=>{let n=await Promise.all(o.map(async t=>{let n=t.columns?.length?t.columns.every(e=>!!e.type):!1;if(t.relationshipField&&n)return t;try{let n=await r.getObjectSchema(t.childObject);if(t.relationshipField&&t.columns?.length)return{...t,columns:He(t.columns,n)};let i=Xe(t.childObject,n,e.objectName,{relationshipField:t.relationshipField,columns:t.columns,amountField:t.amountField});return{...t,relationshipField:i.relationshipField,columns:i.columns,formFields:t.formFields??i.formFields,inlineMode:t.inlineMode??i.mode,amountField:t.amountField??i.amountField,sortField:t.sortField??i.sortField}}catch{return t}}));t||u(n)})(),()=>{t=!0}},[r,e.objectName,e.details]);let[p,m]=(0,t.useState)(()=>o.map(()=>({rows:[],original:[]}))),h=(0,t.useRef)(p);h.current=p;let g=(0,t.useRef)({});(0,t.useEffect)(()=>{let e=r;if(!e||typeof e.getObjectSchema!=`function`)return;let t=!1,n=Array.from(new Set(o.map(e=>e.childObject).filter(Boolean)));return(async()=>{let r=await Promise.all(n.map(async t=>{try{return[t,await e.getObjectSchema(t)]}catch{return[t,null]}}));if(t)return;let i={};for(let[e,t]of r)t&&(i[e]=t);g.current=i})(),()=>{t=!0}},[r,e.objectName,e.details]);let[_,v]=(0,t.useState)(0),[y,b]=(0,t.useState)(!1),x=(0,t.useRef)(!1),S=(0,t.useRef)(null),C=(0,t.useCallback)(()=>{x.current=!1,b(!1),S.current&&=(clearTimeout(S.current),null)},[]);(0,t.useEffect)(()=>{let t=!1;if(!(!s||!r))return(async()=>{let n=await Promise.all(f.map(async t=>{if(!t.relationshipField)return{rows:[],original:[]};try{let n=(await r.find(t.childObject,{$filter:{[t.relationshipField]:e.recordId},$top:500}))?.data??[];return{rows:n.map(e=>({...e})),original:n.map(e=>({...e}))}}catch{return{rows:[],original:[]}}}));t||m(n)})(),()=>{t=!0}},[s,r,e.recordId,l]);let w=(0,t.useCallback)((e,t)=>{m(n=>n.map((n,r)=>r===e?{...n,rows:t}:n))},[]),T=e.taxRateField||`tax_rate`,[E,D]=(0,t.useState)(null),O=E?p[E.detailIdx]?.rows?.[E.rowIdx]:void 0,k=E?f[E.detailIdx]:void 0,A=(0,t.useCallback)((e,t,n)=>{m(r=>r.map((r,i)=>i===e?{...r,rows:r.rows.map((e,r)=>r===t?{...e,...n}:e)}:r))},[]),j=(0,t.useCallback)(e=>{m(t=>{let n=t.map((t,n)=>n===e?{...t,rows:[...t.rows,{}]}:t),r=n[e].rows.length-1;return D({detailIdx:e,rowIdx:r,isNew:!0}),n})},[]),M=(0,t.useCallback)(()=>{D(e=>(e?.isNew&&m(t=>t.map((t,n)=>n===e.detailIdx?{...t,rows:t.rows.filter((t,n)=>n!==e.rowIdx)}:t)),null))},[]),N=(0,t.useCallback)(async t=>{C(),e.onSuccess||a.toast.success(s?e.title?`${e.title} saved`:`Saved`:`Created`),s||(m(f.map(()=>({rows:[],original:[]}))),v(e=>e+1)),await e.onSuccess?.(t)},[s,e.onSuccess,e.title,f.length,C]),P=(0,t.useCallback)(t=>{C(),a.toast.error(t?.message||`Save failed`),e.onError?.(t)},[e,C]),F=(0,t.useCallback)(async t=>{if(!r)throw Error(`MasterDetailForm: dataSource is required`);let i={...t};f.forEach((e,t)=>{e.totalField&&(i[e.totalField]=Oe(h.current[t]?.rows??[],e.amountField||`amount`))});let a=s?Ee(e.objectName,String(e.recordId),i,f.filter(e=>e.relationshipField).map((e,t)=>({childObject:e.childObject,relationshipField:e.relationshipField,rows:h.current[t]?.rows??[],original:h.current[t]?.original??[],childSchema:g.current[e.childObject]}))):Te(e.objectName,i,f.filter(e=>e.relationshipField).map((e,t)=>({childObject:e.childObject,relationshipField:e.relationshipField,rows:h.current[t]?.rows??[],childSchema:g.current[e.childObject]})));return(await(0,n.runBatchTransaction)(r,a))?.results?.[0]??{...i,id:e.recordId}},[r,f,e.objectName,e.recordId,s]),ee=(0,t.useMemo)(()=>({type:`object-form`,objectName:e.objectName,mode:e.mode??`create`,recordId:e.recordId,initialValues:e.initialValues,initialData:e.initialData,formType:e.formType,sections:e.sections,fields:e.fields,title:e.title,showSubmit:!1,showCancel:!1,submitHandler:F,onSuccess:N,onError:P}),[e,F,N,P]),I=(0,t.useRef)(null),L=e.submitText??(s?`Save`:`Create`),R=(0,t.useCallback)(()=>{x.current||I.current?.querySelector(`form`)&&(x.current=!0,b(!0),setTimeout(()=>{(I.current?.querySelector(`form`))?.requestSubmit()},0),S.current=setTimeout(()=>C(),1500))},[C]);return(0,t.useEffect)(()=>()=>{S.current&&clearTimeout(S.current)},[]),(0,d.jsxs)(`div`,{className:(0,a.cn)(`space-y-6`,i,e.className),children:[(0,d.jsx)(`div`,{ref:I,children:(0,d.jsx)(lt,{schema:ee,dataSource:r},_)}),(0,d.jsx)(Qe,{details:f,state:p,setRows:w,formHostRef:I,taxRateField:T,formKey:_,onRowExpand:(e,t)=>D({detailIdx:e,rowIdx:t}),onAddViaForm:j}),E&&k&&(0,d.jsxs)(a.Card,{className:`border-primary/40 shadow-none ring-1 ring-primary/10`,"data-testid":`md-row-form`,children:[(0,d.jsxs)(a.CardHeader,{className:`pb-2 flex flex-row items-center justify-between gap-2 space-y-0`,children:[(0,d.jsxs)(a.CardTitle,{className:`text-sm font-medium`,children:[k.title||`Line item`,` — row `,E.rowIdx+1]}),(0,d.jsx)(a.Button,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 text-xs text-muted-foreground`,onClick:M,children:`Close`})]}),(0,d.jsx)(a.CardContent,{children:(0,d.jsx)(lt,{schema:{type:`object-form`,objectName:k.childObject,mode:`edit`,initialData:O??{},...k.formFields?.length?{fields:k.formFields}:{},submitText:`Apply`,submitHandler:async e=>e,onSuccess:e=>{A(E.detailIdx,E.rowIdx,e),D(null)},onCancel:M},dataSource:r},`row-${E.detailIdx}-${E.rowIdx}`)})]}),e.showSubmit!==!1&&(0,d.jsxs)(`div`,{className:`flex items-center justify-end gap-2 border-t border-border pt-4`,children:[e.onCancel&&(0,d.jsx)(a.Button,{type:`button`,variant:`outline`,onClick:e.onCancel,disabled:y,"data-testid":`md-form-cancel`,children:e.cancelText??`Cancel`}),(0,d.jsx)(a.Button,{type:`button`,onClick:R,disabled:y||c&&!l,"data-testid":`md-form-submit`,children:y?`Saving…`:L})]})]})};function et(e){let t=e.fields||Object.keys(e.objectSchema?.fields||{}),n=[];for(let r of t){let t=typeof r==`string`?r:r?.name;if(!t)continue;let i=e.objectSchema?.fields?.[t];i&&n.push({...z(t,e),group:i.group})}return n}function tt(e,t){let n=(0,c.deriveFieldGroupLayout)({fieldGroups:t,fields:Object.fromEntries(e.map(e=>[e.name,{group:e.group}]))});if(!n)return null;let r=new Set(n.flatMap(e=>e.fields)),i=e.map(e=>e.name).filter(e=>!r.has(e)),a=n.map(e=>({...e.key===void 0?{}:{name:e.key},...e.key===void 0?{}:{label:e.label??e.key},fields:[...e.fields],...e.collapse===`none`?{}:{collapsible:!0},...e.collapse===`collapsed`?{collapsed:!0}:{}}));if(i.length>0){let e=a[a.length-1];e&&e.name===void 0?e.fields=[...e.fields??[],...i]:a.push({fields:i})}return a}var nt={1:void 0,2:`grid gap-4 grid-cols-1 @md:grid-cols-2`,3:`grid gap-4 grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3`,4:`grid gap-4 grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3 @4xl:grid-cols-4`},rt=(0,u.createSafeTranslation)({"form.discardTitle":`Discard changes?`,"form.discardMessage":`You have unsaved changes. If you close this form now, your edits will be lost.`,"form.dialogDescriptionFallback":`Complete the form fields, then submit or cancel.`,"form.keepEditing":`Keep editing`,"form.discard":`Discard`},`form.discardTitle`),it=({schema:e,dataSource:n,className:i})=>{let{fieldLabel:o,sectionLabel:c}=(0,r.useSafeFieldLabel)(),{userId:u}=(0,s.usePermissions)(),{t:f}=rt(),p=(0,r.usePreviewMode)(),[m,h]=(0,t.useState)(null),[g,_]=(0,t.useState)([]),[v,y]=(0,t.useState)({}),[b,x]=(0,t.useState)(!0),[S,C]=(0,t.useState)(null),[w,T]=(0,t.useState)(!1),[E,D]=(0,t.useState)(!1),{saveWithOcc:O,conflictDialog:k}=de(),[A,j]=(0,t.useState)(!1),M=(0,t.useRef)(!1),N=e.confirmOnDiscard!==!1,P=e.open!==!1,I=e.drawerSide||`right`,L=(0,t.useId)(),[R,z]=(0,t.useState)(()=>{let t={};return e.sections?.forEach((e,n)=>{let r=e.name||String(n);e.collapsed&&(t[r]=!0)}),t});(0,t.useEffect)(()=>{(async()=>{if(!n){x(!1);return}try{let t=await n.getObjectSchema(e.objectName);h(t)}catch(e){C(e),x(!1)}})()},[e.objectName,n]);let B=(0,t.useRef)(void 0);(0,t.useEffect)(()=>{let t=!1;return(m||!n)&&(async()=>{if(e.mode===`create`||!e.recordId){y(F(m,e.initialData||e.initialValues,{currentUserId:u})),x(!1);return}if(!n){y(e.initialData||e.initialValues||{}),x(!1);return}B.current!==e.recordId&&(x(!0),T(!1));try{let r=await n.findOne(e.objectName,e.recordId);if(t)return;B.current=e.recordId,y(r||{})}catch(e){if(t)return;C(e)}finally{t||x(!1)}})(),()=>{t=!0}},[m,e.mode,e.recordId,e.initialData,e.initialValues,n,e.objectName]);let V=(0,t.useCallback)(t=>te(t,{objectSchema:m,objectName:e.objectName,readOnly:e.readOnly,mode:e.mode,recordId:e.recordId,fieldLabel:o}),[m,e.readOnly,e.mode,e.recordId,e.objectName,o]);(0,t.useEffect)(()=>{if(!(!m&&n)){if(e.customFields?.length){_(e.customFields),x(!1);return}if(e.sections?.length){x(!1);return}m&&(_(et({fields:e.fields,objectSchema:m,objectName:e.objectName,readOnly:e.readOnly,mode:e.mode,recordId:e.recordId,fieldLabel:o})),x(!1))}},[m,e.fields,e.customFields,e.sections,e.readOnly,e.mode,n]);let ne=(0,t.useMemo)(()=>{if(e.sections?.length||e.customFields?.length)return null;let t=oe(g,m);e.mode===`create`&&(t=se(t,m));let n=tt(t,m?.fieldGroups);if(!n)return null;let r=e.columns&&e.columns>0?Math.min(Math.floor(e.columns),4):ie(t.length);return n.map(e=>({...e,columns:r}))},[e.sections,e.customFields,e.columns,e.mode,g,m]),re=(0,t.useCallback)(async t=>{j(!0);try{if(!n)return e.onSuccess&&await e.onSuccess(t),e.onOpenChange?.(!1),t;let r,i=be(t,m);if(e.mode===`create`)r=await n.create(e.objectName,ee(i,m));else if(e.mode===`edit`&&e.recordId){let t=await O({dataSource:n,objectName:e.objectName,recordId:e.recordId,payload:i,baseRecord:v});if(t.status===`cancelled`)return;r=t.result}return e.onSuccess&&await e.onSuccess(r),e.onOpenChange?.(!1),r}catch(t){throw e.onError&&e.onError(t),t}finally{j(!1)}},[e,n,m,O,v]),H=(0,t.useCallback)(()=>{D(!1),M.current&&(M.current=!1,e.onCancel?.()),e.onOpenChange?.(!1)},[e]),U=(0,t.useCallback)(e=>{M.current=e,N&&w?D(!0):H()},[N,w,H]);(0,t.useEffect)(()=>{if(!P||!w||!N)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[P,w,N]);let W=(0,t.useCallback)(()=>{M.current=!0,H()},[H]),G=(0,t.useMemo)(()=>{if(e.drawerWidth)return I===`left`||I===`right`?{width:e.drawerWidth,maxWidth:e.drawerWidth}:{height:e.drawerWidth,maxHeight:e.drawerWidth}},[e.drawerWidth,I]),ae=e.layout===`vertical`||e.layout===`horizontal`?e.layout:`vertical`,q=e.showSubmit!==!1&&e.mode!==`view`,J=e.showCancel!==!1,Y=e.submitText||(e.mode===`create`?`Create`:`Update`),ce=e.cancelText||`Cancel`,X={type:`form`,objectName:e.objectName,layout:ae,defaultValues:v,previousValues:e.mode===`edit`&&e.recordId?v:void 0,submitLabel:Y,cancelLabel:ce,showSubmit:q,showCancel:J,onSubmit:re,onCancel:W,onDirtyChange:T,showActions:!1,id:L},Z=()=>{if(S)return(0,d.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,d.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,d.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:S.message})]});if(b)return(0,d.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,d.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,d.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});if(e.sections?.length){let t=[];return e.sections.forEach((e,n)=>{let r=e.name||String(n),i=R[r]??e.collapsed??!1;t.push({name:`__section_${r}`,label:e.label||``,type:`section-divider`,colSpan:4,collapsible:e.collapsible,collapsed:i,onToggle:e.collapsible?()=>z(e=>({...e,[r]:!i})):void 0,className:e.className});let a=V(e);i?t.push(...a.map(e=>({...e,hidden:!0}))):t.push(...a)}),(0,d.jsx)(r.SchemaRenderer,{schema:{...X,fields:t}})}if(ne?.length){let t=Number(ne[0]?.columns)||1,n=[];ne.forEach((r,i)=>{let a=V(r);if(!a.length)return;let o=r.name||String(i),s=r.collapsible?R[o]??r.collapsed??!1:!1,l=r.name?c(e.objectName,r.name,r.label||r.name):r.label;l&&n.push({name:`__section_${o}`,label:l,type:`section-divider`,colSpan:4,collapsible:r.collapsible,collapsed:s,onToggle:r.collapsible?()=>z(e=>({...e,[o]:!s})):void 0});let u=t>1?K(a,t):a;n.push(...s?u.map(e=>({...e,hidden:!0})):u)});let i=nt[t];return(0,d.jsx)(r.SchemaRenderer,{schema:{...X,fields:n,columns:t,...i?{fieldContainerClass:i}:{}}})}let t=le(g,m,e.columns,e.mode),n=nt[t.columns||1];return(0,d.jsx)(r.SchemaRenderer,{schema:{...X,fields:t.fields,columns:t.columns,...n?{fieldContainerClass:n}:{}}})},Q=e.subforms,ue=Q?.length&&e.mode!==`view`?(0,d.jsx)($e,{schema:{type:`object-master-detail-form`,objectName:e.objectName,mode:e.mode===`edit`?`edit`:`create`,recordId:e.recordId,fields:e.fields,sections:e.sections,submitText:e.submitText,cancelText:ce,details:Q,onSuccess:async t=>{await e.onSuccess?.(t),e.onOpenChange?.(!1)},onError:e.onError,onCancel:()=>e.onOpenChange?.(!1)},dataSource:n}):Z();return p?(0,d.jsxs)(`div`,{className:`@container rounded-md border bg-card p-4`,children:[(e.title||e.description)&&(0,d.jsxs)(`div`,{className:`mb-3 space-y-0.5`,children:[e.title&&(0,d.jsx)(`div`,{className:`text-sm font-semibold`,children:e.title}),e.description&&(0,d.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.description})]}),ue]}):(0,d.jsx)(a.Sheet,{open:P,onOpenChange:t=>{if(t){e.onOpenChange?.(!0);return}U(!1)},children:(0,d.jsxs)(a.SheetContent,{side:I,className:(0,a.cn)(`overflow-y-auto`,i,e.className),style:G,children:[(e.title||e.description)&&(0,d.jsxs)(a.SheetHeader,{children:[e.title&&(0,d.jsx)(a.SheetTitle,{children:e.title}),e.description?(0,d.jsx)(a.SheetDescription,{children:e.description}):(0,d.jsx)(a.SheetDescription,{className:`sr-only`,children:f(`form.dialogDescriptionFallback`)})]}),(0,d.jsx)(`div`,{className:`@container py-4`,children:ue}),!S&&!b&&!(Q?.length&&e.mode!==`view`)&&(q||J)&&(0,d.jsx)(`div`,{className:`shrink-0 border-t px-4 py-3 bg-background`,"data-testid":`drawer-form-footer`,children:(0,d.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-2 sm:justify-end`,children:[J&&(0,d.jsx)(a.Button,{type:`button`,variant:`outline`,onClick:W,disabled:A,className:`w-full sm:w-auto`,children:ce}),q&&(0,d.jsxs)(a.Button,{type:`submit`,form:L,disabled:A,className:`w-full sm:w-auto`,children:[A&&(0,d.jsx)(l.Loader2,{className:`mr-2 h-4 w-4 animate-spin`}),Y]})]})}),(0,d.jsx)(a.AlertDialog,{open:E,onOpenChange:D,children:(0,d.jsxs)(a.AlertDialogContent,{children:[(0,d.jsxs)(a.AlertDialogHeader,{children:[(0,d.jsx)(a.AlertDialogTitle,{children:f(`form.discardTitle`)}),(0,d.jsx)(a.AlertDialogDescription,{children:f(`form.discardMessage`)})]}),(0,d.jsxs)(a.AlertDialogFooter,{children:[(0,d.jsx)(a.AlertDialogCancel,{onClick:()=>{M.current=!1},children:f(`form.keepEditing`)}),(0,d.jsx)(a.AlertDialogAction,{onClick:H,children:f(`form.discard`)})]})]})}),k]})})},at=(0,u.createSafeTranslation)({"form.discardTitle":`Discard changes?`,"form.discardMessage":`You have unsaved changes. If you close this form now, your edits will be lost.`,"form.dialogDescriptionFallback":`Complete the form fields, then submit or cancel.`,"form.keepEditing":`Keep editing`,"form.discard":`Discard`},`form.discardTitle`),ot={sm:`sm:max-w-sm`,default:`sm:max-w-lg`,lg:`sm:max-w-2xl`,xl:`sm:max-w-5xl`,full:`sm:max-w-[95vw] sm:w-full`},st=({schema:e,dataSource:n,className:i})=>{let{fieldLabel:o,sectionLabel:c}=(0,r.useSafeFieldLabel)(),{t:u}=at(),f=(0,r.usePreviewMode)(),p=(0,s.usePermissions)(),m=(0,t.useCallback)(t=>{if(!p?.isLoaded)return t;let n=[];for(let r of t){if(!r?.name){n.push(r);continue}p.checkField(e.objectName,r.name,`read`)&&(!p.checkField(e.objectName,r.name,`write`)&&e.mode!==`view`?n.push({...r,readOnly:!0,disabled:!0}):n.push(r))}return n},[p,e.objectName,e.mode]),[h,g]=(0,t.useState)(null),[_,v]=(0,t.useState)([]),[y,b]=(0,t.useState)({}),[x,S]=(0,t.useState)(!0),[C,w]=(0,t.useState)(null),[T,E]=(0,t.useState)(!1),[D,O]=(0,t.useState)(!1),[k,A]=(0,t.useState)(!1),{saveWithOcc:j,conflictDialog:M}=de(),N=(0,t.useRef)(!1),P=e.confirmOnDiscard!==!1,I=e.open!==!1,L=(0,t.useId)(),R=(0,t.useMemo)(()=>{if(e.sections?.length||e.customFields?.length)return null;let t=oe(_,h);e.mode===`create`&&(t=se(t,h));let n=tt(t,h?.fieldGroups);if(!n)return null;let r=e.columns&&e.columns>0?Math.min(Math.floor(e.columns),4):ie(t.length);return n.map(e=>({...e,columns:r}))},[e.sections,e.customFields,e.columns,e.mode,_,h]),z=e.sections?.length?e.sections:R??void 0,B=(0,t.useMemo)(()=>z?.length||e.customFields?.length?null:le(_,h,e.columns,e.mode),[_,h,e.columns,e.mode,z,e.customFields]),V=ot[(0,t.useMemo)(()=>{if(e.modalSize)return e.modalSize;if(B?.columns&&B.columns>1)return ce(B.columns);if(z?.length){let e=Math.max(...z.map(e=>Number(e.columns)||1));if(e>1)return ce(e)}return`default`},[e.modalSize,B,z])]||ot.default;(0,t.useEffect)(()=>{(async()=>{if(!n){S(!1);return}try{let t=await n.getObjectSchema(e.objectName);g(t)}catch(e){w(e),S(!1)}})()},[e.objectName,n]);let ne=(0,t.useRef)(void 0);(0,t.useEffect)(()=>{let t=!1;return(h||!n)&&(async()=>{if(e.mode===`create`||!e.recordId){b(F(h,e.initialData||e.initialValues,{currentUserId:p.userId})),S(!1);return}if(!n){b(e.initialData||e.initialValues||{}),S(!1);return}ne.current!==e.recordId&&(S(!0),O(!1));try{let r=await n.findOne(e.objectName,e.recordId);if(t)return;ne.current=e.recordId,b(r||{})}catch(e){if(t)return;w(e)}finally{t||S(!1)}})(),()=>{t=!0}},[h,e.mode,e.recordId,e.initialData,e.initialValues,n,e.objectName]);let re=(0,t.useCallback)(t=>te(t,{objectSchema:h,objectName:e.objectName,readOnly:e.readOnly,mode:e.mode,recordId:e.recordId,fieldLabel:o}),[h,e.readOnly,e.mode,e.recordId,e.objectName,o]);(0,t.useEffect)(()=>{if(!(!h&&n)){if(e.customFields?.length){v(e.customFields),S(!1);return}if(e.sections?.length){S(!1);return}h&&(v(et({fields:e.fields,objectSchema:h,objectName:e.objectName,readOnly:e.readOnly,mode:e.mode,recordId:e.recordId,fieldLabel:o})),S(!1))}},[h,e.fields,e.customFields,e.sections,e.readOnly,e.mode,n]);let H=(0,t.useCallback)(async t=>{E(!0);try{if(!n)return e.onSuccess&&await e.onSuccess(t),e.onOpenChange?.(!1),t;let r,i=be(t,h);if(p?.isLoaded){let t={};for(let n of Object.keys(i))p.checkField(e.objectName,n,`write`)&&(t[n]=i[n]);i=t}if(e.mode===`create`)r=await n.create(e.objectName,ee(i,h));else if(e.mode===`edit`&&e.recordId){let t=await j({dataSource:n,objectName:e.objectName,recordId:e.recordId,payload:i,baseRecord:y});if(t.status===`cancelled`)return;r=t.result}return e.onSuccess&&await e.onSuccess(r),e.onOpenChange?.(!1),r}catch(t){throw e.onError&&e.onError(t),t}finally{E(!1)}},[e,n,h,p,j,y]),U=(0,t.useCallback)(()=>{A(!1),N.current&&(N.current=!1,e.onCancel?.()),e.onOpenChange?.(!1)},[e]),W=(0,t.useCallback)(e=>{N.current=e,P&&D?A(!0):U()},[P,D,U]);(0,t.useEffect)(()=>{if(!I||!D||!P)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[I,D,P]);let G=(0,t.useCallback)(()=>{N.current=!0,U()},[U]),ae=e.layout===`vertical`||e.layout===`horizontal`?e.layout:`vertical`,q=e.showSubmit!==!1&&e.mode!==`view`,Y=e.showCancel!==!1,X=e.submitText||(e.mode===`create`?`Create`:`Update`),Z=e.cancelText||`Cancel`,Q={type:`form`,objectName:e.objectName,layout:ae,defaultValues:y,previousValues:e.mode===`edit`&&e.recordId?y:void 0,submitLabel:X,cancelLabel:Z,showSubmit:q,showCancel:Y,onSubmit:H,onCancel:G,onDirtyChange:O,showActions:!1,id:L},ue=()=>{if(C)return(0,d.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,d.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,d.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:C.message})]});if(x)return(0,d.jsx)(`div`,{className:`space-y-4`,"data-testid":`modal-form-skeleton`,children:[1,2,3].map(e=>(0,d.jsxs)(`div`,{className:`space-y-2`,children:[(0,d.jsx)(a.Skeleton,{className:`h-4 w-24`}),(0,d.jsx)(a.Skeleton,{className:`h-10 w-full`})]},e))});if(e.sections?.length){let t=e.sections,n=(e,t)=>e.name||e.label||String(t),i=t=>t.name?c(e.objectName,t.name,t.label||t.name):t.label,a=e=>typeof e==`number`&&e>0?Math.min(Math.floor(e),4):void 0,o=t.map(e=>a(e.columns)).filter(e=>e!=null),s=a(e.columns)??(o.length?Math.max(...o):1),l=J[s],u=t.map((e,t)=>{let r=m(re(e));return{key:n(e,t),title:i(e),description:e.description,className:e.className,gridClassName:e.gridClassName,fields:s>1?K(r,s,a(e.columns)):r}}).filter(e=>e.fields.length>0),f={...Q,columns:s,...l?{fieldContainerClass:l}:{}};if(e.contentLayout===`tabbed`&&u.length>1)return(0,d.jsx)(r.SchemaRenderer,{schema:{...f,fields:u.flatMap(e=>e.fields),fieldTabs:u.map((e,t)=>({key:e.key,label:e.title||`Section ${t+1}`,description:e.description,fields:e.fields.map(e=>e.name),containerClass:e.gridClassName}))}});let p=[];return u.forEach(e=>{(e.title||e.description)&&p.push({name:`__section_${e.key}`,label:e.title,description:e.description,type:`section-divider`,colSpan:4,className:e.className}),p.push(...e.fields)}),(0,d.jsx)(r.SchemaRenderer,{schema:{...f,fields:p}})}if(R?.length){let t=Number(R[0]?.columns)||1,n=[];R.forEach((r,i)=>{let a=m(re(r));if(!a.length)return;let o=r.name?c(e.objectName,r.name,r.label||r.name):r.label;o&&n.push({name:`__section_${r.name||i}`,label:o,type:`section-divider`}),n.push(...t>1?K(a,t):a)});let i=J[t];return(0,d.jsx)(r.SchemaRenderer,{schema:{...Q,fields:n,columns:t,...i?{fieldContainerClass:i}:{}}})}let t=B??le(_,h,e.columns,e.mode),n=J[t.columns||1];return(0,d.jsx)(r.SchemaRenderer,{schema:{...Q,fields:m(t.fields),columns:t.columns,...n?{fieldContainerClass:n}:{}}})},$=e.subforms;if(f)return(0,d.jsxs)(`div`,{className:`@container rounded-md border bg-card p-4`,children:[(e.title||e.description)&&(0,d.jsxs)(`div`,{className:`mb-3 space-y-0.5`,children:[e.title&&(0,d.jsx)(`div`,{className:`text-sm font-semibold`,children:e.title}),e.description&&(0,d.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.description})]}),ue()]});if($?.length&&e.mode!==`view`)return(0,d.jsx)(a.Dialog,{open:I,onOpenChange:e.onOpenChange,children:(0,d.jsxs)(a.MobileDialogContent,{className:(0,a.cn)(V,`flex flex-col h-[100dvh] sm:h-auto sm:max-h-[90vh] overflow-hidden p-0`,i,e.className),children:[(e.title||e.description)&&(0,d.jsxs)(a.DialogHeader,{className:`shrink-0 px-4 pt-4 sm:px-6 sm:pt-6 pb-2 border-b`,children:[e.title&&(0,d.jsx)(a.DialogTitle,{children:e.title}),e.description?(0,d.jsx)(a.DialogDescription,{children:e.description}):(0,d.jsx)(a.DialogDescription,{className:`sr-only`,children:`Enter the record and its line items, then save.`})]}),(0,d.jsx)(`div`,{className:`@container flex-1 overflow-y-auto px-4 sm:px-6 py-4`,children:(0,d.jsx)($e,{schema:{type:`object-master-detail-form`,objectName:e.objectName,mode:e.mode===`edit`?`edit`:`create`,recordId:e.recordId,fields:e.fields,sections:e.sections,initialValues:e.initialValues,initialData:e.initialData,submitText:X,cancelText:Z,details:$,onSuccess:async t=>{await e.onSuccess?.(t),e.onOpenChange?.(!1)},onError:e.onError,onCancel:()=>e.onOpenChange?.(!1)},dataSource:n})})]})});let fe=!x&&!C&&(q||Y);return(0,d.jsx)(a.Dialog,{open:I,onOpenChange:t=>{if(t){e.onOpenChange?.(!0);return}W(!1)},children:(0,d.jsxs)(a.MobileDialogContent,{className:(0,a.cn)(V,`flex flex-col h-[100dvh] sm:h-auto sm:max-h-[90vh] overflow-hidden p-0`,i,e.className),children:[(e.title||e.description)&&(0,d.jsxs)(a.DialogHeader,{className:`shrink-0 px-4 pt-4 sm:px-6 sm:pt-6 pb-2 border-b`,children:[e.title&&(0,d.jsx)(a.DialogTitle,{children:e.title}),e.description?(0,d.jsx)(a.DialogDescription,{children:e.description}):(0,d.jsx)(a.DialogDescription,{className:`sr-only`,children:u(`form.dialogDescriptionFallback`)})]}),(0,d.jsx)(`div`,{className:`@container flex-1 overflow-y-auto px-4 sm:px-6 py-4`,children:ue()}),fe&&(0,d.jsx)(`div`,{className:`shrink-0 border-t px-4 sm:px-6 py-3 bg-background`,"data-testid":`modal-form-footer`,children:(0,d.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-2 sm:justify-end`,children:[Y&&(0,d.jsx)(a.Button,{type:`button`,variant:`outline`,onClick:G,disabled:T,className:`w-full sm:w-auto`,children:Z}),q&&(0,d.jsxs)(a.Button,{type:`submit`,form:L,disabled:T,className:`w-full sm:w-auto`,children:[T&&(0,d.jsx)(l.Loader2,{className:`mr-2 h-4 w-4 animate-spin`}),X]})]})}),(0,d.jsx)(a.AlertDialog,{open:k,onOpenChange:A,children:(0,d.jsxs)(a.AlertDialogContent,{children:[(0,d.jsxs)(a.AlertDialogHeader,{children:[(0,d.jsx)(a.AlertDialogTitle,{children:u(`form.discardTitle`)}),(0,d.jsx)(a.AlertDialogDescription,{children:u(`form.discardMessage`)})]}),(0,d.jsxs)(a.AlertDialogFooter,{children:[(0,d.jsx)(a.AlertDialogCancel,{onClick:()=>{N.current=!1},children:u(`form.keepEditing`)}),(0,d.jsx)(a.AlertDialogAction,{onClick:U,children:u(`form.discard`)})]})]})}),M]})})};function ct(e){let t=e.buttons,n=e.defaults;if(!t&&!n)return e;let r=e,i={...r};return t?.submit?.show!==void 0&&r.showSubmit===void 0&&(i.showSubmit=t.submit.show),t?.submit?.label!=null&&r.submitText===void 0&&(i.submitText=t.submit.label),t?.cancel?.show!==void 0&&r.showCancel===void 0&&(i.showCancel=t.cancel.show),t?.cancel?.label!=null&&r.cancelText===void 0&&(i.cancelText=t.cancel.label),t?.reset?.show!==void 0&&r.showReset===void 0&&(i.showReset=t.reset.show),n&&r.initialValues===void 0&&(i.initialValues=n),i}var lt=({schema:e,dataSource:n})=>{let i=(0,s.usePermissions)(),a=(0,t.useMemo)(()=>{let t=ct(e),n=t.groups,r=!t.sections?.length&&Array.isArray(n)&&n.length?{...t,sections:n.map(e=>({label:e.title??e.label,description:e.description,collapsible:e.collapsible,collapsed:e.defaultCollapsed??e.collapsed,fields:e.fields??[]}))}:t;if(!i?.isLoaded)return r;let a=e=>e?.name?i.checkField(r.objectName,e.name,`read`)?!i.checkField(r.objectName,e.name,`write`)&&r.mode!==`view`?{...e,readOnly:!0,disabled:!0}:e:null:e,o=e=>Array.isArray(e)?e.map(a).filter(Boolean):e;return{...r,fields:o(r.fields),sections:r.sections?.map(e=>({...e,fields:o(e.fields)}))}},[e,i]),{sectionLabel:o}=(0,r.useSafeFieldLabel)(),c=e=>e?.name?o(a.objectName,e.name,e.label||e.name):e?.label;if(a.subforms?.length&&a.mode!==`view`&&a.formType!==`drawer`&&a.formType!==`modal`)return(0,d.jsx)($e,{schema:{type:`object-master-detail-form`,objectName:a.objectName,mode:a.mode===`edit`?`edit`:`create`,recordId:a.recordId,initialValues:a.initialValues,initialData:a.initialData,formType:a.formType===`tabbed`?`tabbed`:`simple`,sections:a.sections,fields:a.fields,title:a.title,submitText:a.submitText,cancelText:a.cancelText,showSubmit:a.showSubmit,details:a.subforms,onSuccess:a.onSuccess,onError:a.onError,onCancel:a.onCancel,className:a.className},dataSource:n});if(a.formType===`tabbed`&&a.sections?.length)return(0,d.jsx)($,{schema:{...a,formType:`tabbed`,sections:a.sections.map(e=>({name:e.name,label:c(e),description:e.description,columns:e.columns,fields:e.fields,className:e.className,gridClassName:e.gridClassName})),defaultTab:a.defaultTab,tabPosition:a.tabPosition},dataSource:n,className:a.className});if(a.formType===`wizard`&&a.sections?.length)return(0,d.jsx)(ge,{schema:{...a,formType:`wizard`,sections:a.sections.map(e=>({name:e.name,label:c(e),description:e.description,columns:e.columns,fields:e.fields,className:e.className,gridClassName:e.gridClassName})),allowSkip:a.allowSkip,showStepIndicator:a.showStepIndicator,nextText:a.nextText,prevText:a.prevText,onStepChange:a.onStepChange},dataSource:n,className:a.className});if(a.formType===`split`&&a.sections?.length)return(0,d.jsx)(_e,{schema:{...a,formType:`split`,sections:a.sections.map(e=>({name:e.name,label:c(e),description:e.description,columns:e.columns,fields:e.fields,pane:e.pane,className:e.className,gridClassName:e.gridClassName})),splitDirection:a.splitDirection,splitSize:a.splitSize,splitResizable:a.splitResizable},dataSource:n,className:a.className});if(a.formType===`drawer`){let{layout:e,...t}=a,r=a.layout===`vertical`||a.layout===`horizontal`?a.layout:void 0;return(0,d.jsx)(it,{schema:{...t,layout:r,formType:`drawer`,sections:a.sections?.map(e=>({name:e.name,label:c(e),description:e.description,columns:e.columns,fields:e.fields,collapsible:e.collapsible,collapsed:e.collapsed,className:e.className})),open:a.open,onOpenChange:a.onOpenChange,drawerSide:a.drawerSide,drawerWidth:a.drawerWidth},dataSource:n,className:a.className})}if(a.formType===`modal`){let{layout:e,...t}=a,r=a.layout===`vertical`||a.layout===`horizontal`?a.layout:void 0;return(0,d.jsx)(st,{schema:{...t,layout:r,formType:`modal`,sections:a.sections?.map(e=>({name:e.name,label:c(e),description:e.description,columns:e.columns,fields:e.fields,className:e.className,gridClassName:e.gridClassName})),open:a.open,onOpenChange:a.onOpenChange,modalSize:a.modalSize,modalCloseButton:a.modalCloseButton},dataSource:n,className:a.className})}return(0,d.jsx)(ut,{schema:a,dataSource:n})},ut=({schema:e,dataSource:o})=>{let{fieldLabel:c,sectionLabel:l}=(0,r.useSafeFieldLabel)(),u=(0,a.useIsMobile)(),f=(0,s.usePermissions)(),p=(0,t.useCallback)(t=>{if(!f?.isLoaded)return t;let n=[];for(let r of t)f.checkField(e.objectName,r.name,`read`)&&(!f.checkField(e.objectName,r.name,`write`)&&e.mode!==`view`?n.push({...r,readOnly:!0,disabled:!0,description:r.description??`You do not have edit access to this field.`}):n.push(r));return n},[f,e.objectName,e.mode]),[m,h]=(0,t.useState)(null),[g,_]=(0,t.useState)([]),[v,y]=(0,t.useState)(null),[x,S]=(0,t.useState)(!0),[E,D]=(0,t.useState)(null),[k,A]=(0,t.useState)(null),[P,F]=(0,t.useState)(null);T(P);let{saveWithOcc:I,conflictDialog:L}=de(),R=e.customFields&&e.customFields.length>0;(0,t.useEffect)(()=>{R&&(y(e.initialData||e.initialValues||{}),S(!1))},[R,e.initialData,e.initialValues]),(0,t.useEffect)(()=>{R?h({name:e.objectName,fields:{}}):e.objectName&&o?(async()=>{try{if(!o)throw Error(`DataSource is required when using ObjectQL schema fetching (inline fields not provided)`);let t=await o.getObjectSchema(e.objectName);if(!t)throw Error(`No schema found for object "${e.objectName}"`);h(t)}catch(e){D(e),S(!1)}})():R||S(!1)},[e.objectName,o,R]),(0,t.useEffect)(()=>{m&&!R&&(async()=>{if(!e.recordId||e.mode===`create`){y(e.initialData||e.initialValues||{}),S(!1);return}if(!R){if(!o){D(Error(`DataSource is required for fetching record data (inline data not provided)`)),S(!1);return}S(!0);try{let t=await o.findOne(e.objectName,e.recordId);y(t)}catch(e){console.error(`Failed to fetch record:`,e),D(e)}finally{S(!1)}}})()},[e.objectName,e.recordId,e.mode,e.initialValues,e.initialData,o,m,R]);let z=(0,t.useCallback)(e=>e,[]);(0,t.useEffect)(()=>{if(R&&e.customFields){_(e.customFields.map(z)),S(!1);return}if(!m)return;let t=[],r=(0,n.resolveEffectiveCrudAffordances)(m,f?.getObjectApiOperations?.(e.objectName)),a=!(e.mode===`edit`?r.edit:e.mode!==`create`||r.create),s=e.fields||Object.keys(m.fields||{});(Array.isArray(s)?s:Object.keys(s)).forEach(n=>{let r=typeof n==`string`?n:n.name;if(!r)return;let o=m.fields?.[r];if(!o&&!R)return;let s=e.customFields?.find(e=>e.name===r);if(s)t.push(z(s));else if(o){let s={name:r,label:c(e.objectName,r,o.label||n),type:(0,i.mapFieldTypeToFormType)(o.type,{multiple:o.multiple}),required:M(o,j(e)),disabled:e.readOnly||e.mode===`view`||o.readonly||a,placeholder:o.placeholder,description:o.help||o.description,validation:(0,i.buildValidationRules)(o),visibleWhen:o.visibleWhen,readonlyWhen:o.readonlyWhen,requiredWhen:o.requiredWhen,group:o.group,field:o,widget:o.widget};if((o.type===`select`||o.type===`lookup`||o.type===`master_detail`)&&(s.options=o.options||[],s.multiple=o.multiple),(o.type===`number`||o.type===`currency`||o.type===`percent`)&&(s.inputType=`number`,s.min=o.min,s.max=o.max,s.step=o.precision?10**-o.precision:void 0),o.type===`date`&&(s.inputType=`date`),o.type===`datetime`&&(s.inputType=`datetime-local`),(o.type===`text`||o.type===`textarea`||o.type===`markdown`||o.type===`html`)&&(s.maxLength=o.maxLength??o.max_length,s.minLength=o.minLength??o.min_length),(o.type===`file`||o.type===`image`)&&(s.inputType=`file`,s.multiple=o.multiple,s.accept=o.accept?o.accept.join(`,`):void 0,o.max_size)){let e=`Max size: ${(0,i.formatFileSize)(o.max_size)}`;s.description=s.description?`${s.description} (${e})`:e}o.type===`email`&&(s.inputType=`email`),o.type===`phone`&&(s.inputType=`tel`),o.type===`url`&&(s.inputType=`url`),o.type===`password`&&(s.inputType=`password`),o.type===`time`&&(s.inputType=`time`),(o.type===`formula`||o.type===`summary`||o.type===`auto_number`)&&(s.disabled=!0),o.visible_on&&(s.visibleOn=o.visible_on),t.push(s)}}),_(t),!R&&e.recordId&&e.mode!==`create`&&o||S(!1)},[m,e.fields,e.customFields,e.readOnly,e.mode,e.objectName,R,e.recordId,o,f]);let B=(0,t.useCallback)(async(t,n)=>{if(t&&(t.nativeEvent||t._reactName===`onSubmit`)&&(console.warn(`ObjectForm: Received Event instead of data in handleSubmit! This suggests a Form renderer issue.`),n===void 0&&(t={})),R&&!o)return e.onSuccess&&await e.onSuccess(t),t;if(!o)throw Error(`DataSource is required for form submission (inline mode not configured)`);let r=be(t,R?null:m);if(j(e)&&(r=ee(r,R?null:m)),f?.isLoaded&&r&&typeof r==`object`){let t={};for(let n of Object.keys(r))f.checkField(e.objectName,n,`write`)&&(t[n]=r[n]);r=t}try{let t;if(e.submitHandler)t=await e.submitHandler(r);else if(e.mode===`create`)t=await o.create(e.objectName,r);else if(e.mode===`edit`&&e.recordId){let n=await I({dataSource:o,objectName:e.objectName,recordId:e.recordId,payload:r,baseRecord:v});if(n.status===`cancelled`)return;t=n.result}else throw Error(`Invalid form mode or missing record ID`);if(e.onSuccess)await e.onSuccess(t);else if(!e.submitHandler&&e.submitBehavior){let n=e.submitBehavior;switch(n.kind){case`redirect`:{let i=w(n.url,C(r,t));if(!i.ok){a.toast.error(i.refusal),A({message:e.successMessage||(e.mode===`create`?`Created`:`Saved`),refusal:i.refusal});break}F({url:i.url,delayMs:n.delayMs??0});break}case`continue`:break;default:{let t=n.kind===`thank-you`&&n.message?n.message:e.successMessage||(e.mode===`create`?`Created`:`Saved`);a.toast.success(t),A({title:n.kind===`thank-you`?n.title:void 0,message:t});break}}}else if(!e.submitHandler){let n=b(e.navigateOnSuccess,t);if(n)return O(n)?F({url:n,delayMs:0}):window.location.assign(n),t;e.navigateOnSuccess?(console.warn("[ObjectForm] `navigateOnSuccess` was declared but produced no destination:",e.navigateOnSuccess),a.toast.success(e.successMessage||(e.mode===`create`?`Created`:`Saved`),{description:pe})):a.toast.success(e.successMessage||(e.mode===`create`?`Created`:`Saved`))}return t}catch(t){throw console.error(`Failed to submit form:`,t),e.onError&&e.onError(t),t}},[e,o,R,f,m,I,v]),te=(0,t.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),V=j(e),ne={...t.default.useMemo(()=>V?N(m,{currentUserId:f.userId}):{},[m,V,f.userId]),...v},re=e.mode===`edit`&&e.recordId&&v&&typeof v==`object`?v:void 0,H=t.default.useMemo(()=>{let t=oe(g,m);return e.mode===`create`&&(t=se(t,m)),t},[g,m,e.mode]),U=t.default.useMemo(()=>e.sections?.length?null:tt(H,m?.fieldGroups),[e.sections,H,m]),W=e.sections?.length?e.sections:U,[G,ae]=(0,t.useState)({});if(E)return(0,d.jsxs)(`div`,{className:`p-3 sm:p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,d.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,d.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:E.message})]});if(x)return(0,d.jsxs)(`div`,{className:`p-4 sm:p-8 text-center`,children:[(0,d.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,d.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});if(k){let e=(0,d.jsxs)(`div`,{className:`rounded-md border bg-card p-6 sm:p-8 text-center`,children:[(0,d.jsx)(`h3`,{className:`text-lg font-semibold`,children:k.title??`Thanks!`}),k.message&&(0,d.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:k.message})]});return k.refusal?(0,d.jsxs)(`div`,{className:`space-y-4`,children:[e,(0,d.jsx)(`div`,{role:`alert`,className:`rounded-md border border-destructive/40 bg-destructive/10 p-4 text-sm text-destructive`,children:k.refusal})]}):e}let q=e.layout===`vertical`||e.layout===`horizontal`?e.layout:`vertical`;if(W?.length&&(!e.formType||e.formType===`simple`)){let t=U?H:g,n=e=>typeof e==`number`&&e>0?Math.min(Math.floor(e),4):void 0,i=W.map(e=>n(e.columns)).filter(e=>e!=null),a=W.reduce((e,t)=>e+(Array.isArray(t.fields)?t.fields.length:0),0),o=n(e.columns)??(i.length?Math.max(...i):ie(a)),s=[];W.forEach((r,i)=>{let a=new Map(r.fields.map(e=>[typeof e==`string`?e:e.field??e.name,e])),c=Array.from(a.keys()),u=p(t.filter(e=>c.includes(e.name))).map(e=>{let t=a.get(e.name);if(!t||typeof t!=`object`)return e;let n=t,r={...e};return n.visibleOn!=null&&(r.visibleOn=n.visibleOn),n.colSpan!=null&&(r.colSpan=n.colSpan),n.span!=null&&(r.span=n.span),r});if(u.length===0)return;let d=r.name||r.label||String(i),f=r.name?l(e.objectName,r.name,r.label||r.name):r.label,m=G[d]??r.collapsed??!1;f&&s.push({name:`__section_${d}`,label:f,type:`section-divider`,colSpan:4,collapsible:r.collapsible,collapsed:m,onToggle:r.collapsible?()=>ae(e=>({...e,[d]:!m})):void 0,className:r.className});let h=n(r.columns),g=o>1?K(u,o,h):u;f&&m?s.push(...g.map(e=>({...e,hidden:!0}))):s.push(...g)});let c=s,u=Y(o);return(0,d.jsxs)(`div`,{className:`w-full @container`,children:[(0,d.jsx)(r.SchemaRenderer,{schema:{type:`form`,objectName:e.objectName,fields:c,layout:q,columns:o,...u?{fieldContainerClass:u}:{},defaultValues:ne,previousValues:re,showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1,submitLabel:e.submitText||(e.mode===`create`?`Create`:`Update`),cancelLabel:e.cancelText,onSubmit:B,onCancel:te}}),L]})}let J=e.sections?.length,ce=p(g),X=J?{fields:ce,columns:e.columns}:le(ce,m,e.columns,e.mode),Z=e.mobile,Q=Z?.fullscreenLongText?X.fields.map(e=>{let t=e.type;return t!==`textarea`&&t!==`field:textarea`&&t!==`field:markdown`&&t!==`field:html`&&t!==`field:richtext`?e:e.field?{...e,field:{...e.field,mobile_fullscreen:!0}}:{...e,mobile_fullscreen:!0}}):X.fields,ue=Z?.stepper,$=Z?.stepperMinFields??8,fe=Math.max(1,Z?.stepperFieldsPerStep??1);if(!e.formType&&!J&&Q.length>=2&&(ue===!0||ue===`auto`&&u&&Q.length>=$)){let t=Q,n=[];for(let e=0;e<t.length;e+=fe){let r=t.slice(e,e+fe);n.push({name:`step-${Math.floor(e/fe)+1}`,label:r[0]?.label||r[0]?.name||`Step ${Math.floor(e/fe)+1}`,fields:r})}return(0,d.jsx)(ge,{schema:{...e,formType:`wizard`,sections:n,showStepIndicator:!0},dataSource:o,className:e.className})}let me={type:`form`,objectName:e.objectName,fields:Q,layout:q,columns:X.columns,submitLabel:e.submitText||(e.mode===`create`?`Create`:`Update`),cancelLabel:e.cancelText,showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1,resetOnSubmit:e.showReset||e.submitBehavior?.kind===`continue`||!e.submitBehavior&&e.resetOnSuccess&&e.mode===`create`,defaultValues:ne,previousValues:re,onSubmit:B,onCancel:te,className:e.className,mobileStickyActions:!!Z?.stickyActions};return(0,d.jsxs)(`div`,{className:Z?.stickyActions?`w-full pb-20 md:pb-0`:`w-full`,"data-mobile-form":Z?`true`:void 0,children:[(0,d.jsx)(r.SchemaRenderer,{schema:me}),L]})},dt=1e3;function ft(e){return e?Math.max(0,Math.ceil(e.delayMs/1e3)):null}function pt(e){let[n,r]=(0,t.useState)(e),[i,a]=(0,t.useState)(()=>ft(e));return e!==n&&(r(e),a(ft(e))),(0,t.useEffect)(()=>{if(!e)return;let t=setInterval(()=>{a(e=>e===null||e<=1?(clearInterval(t),0):e-1)},dt);return()=>clearInterval(t)},[e]),i}var mt={text:200,email:254,url:2048,phone:32,textarea:5e3,markdown:5e3,html:5e3},ht=`_company_website_2`,gt=1500;function _t(e,t=[]){try{let n=new URL(e,typeof window<`u`?window.location.href:`http://localhost`);return typeof window<`u`&&n.origin===window.location.origin?!0:n.protocol!==`https:`&&n.protocol!==`http:`?!1:t.some(e=>{if(e===n.host)return!0;if(e.startsWith(`*.`)){let t=e.slice(1);return n.host.endsWith(t)&&n.host.length>t.length}return!1})}catch{return!1}}function vt(e){return e&&e.map(e=>{let t=mt[String(e.type||``).toLowerCase()];return!t||(e.maxLength??e.max_length)?e:{...e,maxLength:t}})}var yt=({config:e,dataSource:n,prefillParams:r,className:i})=>{let[o,s]=(0,t.useState)(!1),[c,u]=(0,t.useState)(!1),[f,p]=(0,t.useState)(null),[m,h]=(0,t.useState)(!(e.consent?.required??!!e.consent)),[g,_]=(0,t.useState)(null),[v,y]=(0,t.useState)(null),[b,x]=(0,t.useState)(!1),S=(0,t.useRef)(null),C=(0,t.useRef)(0);(0,t.useEffect)(()=>{o||(C.current=Date.now())},[o]),k(v);let w=pt(v),T=e.honeypot===!1?null:e.honeypot||ht,E=e.minFillTime??gt,D=(0,t.useMemo)(()=>vt(e.customFields),[e.customFields]),O=(0,t.useMemo)(()=>{if(!n||D&&D.length>0||!e.fields||e.fields.length===0)return;let t=async(e,t)=>t;return{...n,create:t,update:(e,t,n)=>Promise.resolve(n),delete:()=>Promise.reject(Error(`Not permitted on public form`))}},[n,D,e.fields]),A=(0,t.useMemo)(()=>{let t={};if(r)for(let[e,n]of Object.entries(r))t[e]=n;if(typeof window<`u`&&e.allowedPrefillFields?.length){let n=new Set(e.allowedPrefillFields);new URLSearchParams(window.location.search).forEach((e,r)=>{n.has(r)&&!(r in t)&&(t[r]=e)})}return Object.keys(t).length>0?t:void 0},[r,e.allowedPrefillFields]),j=(0,t.useCallback)(async t=>{if(e.consent?.required&&!m){_(e.texts?.consentRequired??`Please accept the privacy policy to continue.`);return}if(_(null),T&&S.current?.value){s(!0);return}if(E>0&&Date.now()-C.current<E){p(e.texts?.rateLimited??`Please take a moment to review your answers before submitting.`);return}let r={...t};T&&delete r[T],e.captchaToken&&(r._captcha=e.captchaToken),u(!0),p(null);try{n&&await n.create(e.objectName,r),s(!0);let t=e.thankYouPage?.redirectUrl;if(t){if(_t(t,e.allowedRedirectHosts)){let n=e.thankYouPage?.redirectDelay??3e3;y({url:t,delayMs:n})}else console.warn(`[EmbeddableForm] Blocked unsafe redirect target:`,t),x(!0)}}catch(e){p(e instanceof Error?e.message:`Failed to submit form. Please try again.`)}finally{u(!1)}},[n,e,m,T,E]),M=(0,t.useCallback)(()=>{s(!1),p(null),y(null),x(!1)},[]),N=(0,t.useMemo)(()=>{let t={};return e.branding?.backgroundColor&&(t.backgroundColor=e.branding.backgroundColor),t},[e.branding]);if(o){let t=e.thankYouPage,n=e.texts??{},r=v&&w!==null?(n.redirecting??`Redirecting in {{seconds}} seconds…`).replace(`{{seconds}}`,String(w)):null;return(0,d.jsx)(`div`,{className:`min-h-screen flex items-center justify-center p-4 bg-gradient-to-b from-muted/40 via-background to-background ${i||``}`,style:N,children:(0,d.jsxs)(`div`,{className:`max-w-md w-full bg-card border rounded-xl shadow-sm p-8 text-center space-y-4`,children:[(0,d.jsx)(`div`,{className:`mx-auto inline-flex h-14 w-14 items-center justify-center rounded-full bg-emerald-50 text-emerald-600 dark:bg-emerald-500/10 dark:text-emerald-400`,children:(0,d.jsx)(l.CheckCircle2,{className:`h-8 w-8`,"aria-hidden":`true`})}),(0,d.jsx)(`h2`,{className:`text-xl font-semibold text-foreground`,children:t?.title||n.thankYouTitle||`Thank You!`}),(0,d.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t?.message||n.thankYouMessage||`Your submission has been received successfully.`}),e.allowMultiple&&(0,d.jsx)(a.Button,{variant:`outline`,size:`sm`,onClick:M,className:`mt-2`,children:n.submitAnother??`Submit Another Response`}),r&&(0,d.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r}),b&&n.redirectBlocked&&(0,d.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n.redirectBlocked})]})})}let P=e.texts??{},F=!!e.consent?.required,ee=`${e.formId}-consent`;return(0,d.jsx)(`div`,{className:`min-h-screen flex items-center justify-center p-4 sm:p-6 bg-gradient-to-b from-muted/40 via-background to-background ${i||``}`,style:N,children:(0,d.jsxs)(`div`,{className:`max-w-2xl w-full bg-card border rounded-xl shadow-sm overflow-hidden`,children:[e.branding?.coverImage&&(0,d.jsx)(`div`,{className:`h-28 sm:h-32 w-full bg-cover bg-center`,style:{backgroundImage:`url(${JSON.stringify(e.branding.coverImage)})`},role:`presentation`}),(0,d.jsxs)(`div`,{className:`px-6 sm:px-8 pt-7 pb-5 border-b bg-muted/20`,style:e.branding?.primaryColor?{borderBottomColor:e.branding.primaryColor}:void 0,children:[e.branding?.logo&&(0,d.jsx)(`img`,{src:e.branding.logo,alt:``,className:`h-8 mb-4`}),e.title&&(0,d.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight text-foreground`,children:e.title}),e.description&&(0,d.jsx)(`p`,{className:`text-sm text-muted-foreground mt-2 leading-relaxed`,children:e.description}),(0,d.jsx)(`p`,{className:`text-[11px] text-muted-foreground/70 mt-3`,"aria-hidden":`true`,children:P.requiredHint??`* Required field`})]}),(0,d.jsxs)(`div`,{className:`relative px-6 sm:px-8 py-6`,children:[f&&(0,d.jsx)(`div`,{role:`alert`,"aria-live":`assertive`,className:`mb-4 p-3 bg-destructive/10 border border-destructive/30 rounded-md text-sm text-destructive`,children:f}),(0,d.jsx)(lt,{schema:{type:`object-form`,objectName:e.objectName,mode:`create`,fields:e.fields,customFields:D,initialData:A,onSuccess:j,submitText:c?P.submitting??`Submitting...`:P.submit??`Submit`},dataSource:O}),T&&(0,d.jsxs)(`div`,{"aria-hidden":`true`,className:`absolute left-[-10000px] top-auto h-px w-px overflow-hidden`,children:[(0,d.jsx)(`label`,{htmlFor:`${e.formId}-${T}`,children:`Do not fill this field`}),(0,d.jsx)(`input`,{ref:S,id:`${e.formId}-${T}`,type:`text`,name:T,tabIndex:-1,autoComplete:`off`,defaultValue:``})]}),e.consent&&(0,d.jsxs)(`div`,{className:`mt-4`,children:[(0,d.jsxs)(`label`,{className:`flex items-start gap-2 text-sm text-foreground cursor-pointer select-none`,children:[(0,d.jsx)(`input`,{type:`checkbox`,id:ee,checked:m,onChange:e=>{h(e.target.checked),e.target.checked&&_(null)},"aria-required":F||void 0,"aria-invalid":g?`true`:void 0,"aria-describedby":g?`${ee}-error`:void 0,className:`mt-0.5 h-4 w-4 rounded border-input accent-primary`}),(0,d.jsxs)(`span`,{className:`leading-relaxed`,children:[e.consent.label??P.consentLabelDefault??`I agree to the privacy policy.`,F&&(0,d.jsx)(`span`,{"aria-hidden":`true`,className:`text-destructive ml-0.5`,children:`*`}),e.consent.privacyUrl&&(0,d.jsxs)(d.Fragment,{children:[` `,(0,d.jsx)(`a`,{href:e.consent.privacyUrl,target:`_blank`,rel:`noopener noreferrer`,className:`underline text-primary hover:opacity-80`,children:P.consentLink??`Privacy policy`})]})]})]}),g&&(0,d.jsx)(`p`,{id:`${ee}-error`,role:`alert`,className:`mt-1.5 text-xs text-destructive`,children:g})]}),c&&(0,d.jsxs)(`div`,{className:`mt-3 flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,d.jsx)(l.Loader2,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":`true`}),(0,d.jsx)(`span`,{children:P.submitting??`Submitting…`})]})]}),(0,d.jsxs)(`div`,{className:`px-6 sm:px-8 py-4 border-t bg-muted/20 flex flex-col sm:flex-row items-center justify-between gap-2`,children:[(0,d.jsxs)(`p`,{className:`inline-flex items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,d.jsx)(l.Lock,{className:`h-3 w-3`,"aria-hidden":`true`}),(0,d.jsx)(`span`,{children:P.secureNotice??`Your information is transmitted securely and only used to respond to your request.`})]}),(0,d.jsxs)(`div`,{className:`flex items-center gap-3 text-xs text-muted-foreground/80`,children:[e.privacyPolicyUrl&&(0,d.jsxs)(`a`,{href:e.privacyPolicyUrl,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1 underline hover:text-foreground`,children:[(0,d.jsx)(l.ShieldCheck,{className:`h-3 w-3`,"aria-hidden":`true`}),P.consentLink??`Privacy policy`]}),(0,d.jsx)(`span`,{children:P.poweredBy??`Powered by ObjectStack`})]})]})]})})};function bt(e){return e<60?`${Math.round(e)}s`:e<3600?`${Math.floor(e/60)}m ${Math.round(e%60)}s`:`${Math.floor(e/3600)}h ${Math.floor(e%3600/60)}m`}var xt=({formId:e,formTitle:n,metrics:r,className:i})=>{let o=(0,t.useMemo)(()=>{if(!r.abandonedSubmissions)return 100;let e=r.totalSubmissions+r.abandonedSubmissions;return e===0?0:Math.round(r.totalSubmissions/e*100)},[r.totalSubmissions,r.abandonedSubmissions]),s=(0,t.useMemo)(()=>r.dailySubmissions?.length?Math.max(...r.dailySubmissions.map(e=>e.count),1):1,[r.dailySubmissions]);return(0,d.jsxs)(`div`,{className:`space-y-4 ${i||``}`,children:[(0,d.jsxs)(`div`,{children:[(0,d.jsx)(`h2`,{className:`text-lg font-semibold text-foreground`,children:n||`Form Analytics`}),(0,d.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Form ID: `,e]})]}),(0,d.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-4`,children:[(0,d.jsx)(a.Card,{children:(0,d.jsxs)(a.CardHeader,{className:`pb-2`,children:[(0,d.jsx)(a.CardDescription,{children:`Total Submissions`}),(0,d.jsx)(a.CardTitle,{className:`text-2xl`,children:r.totalSubmissions.toLocaleString()})]})}),(0,d.jsxs)(a.Card,{children:[(0,d.jsxs)(a.CardHeader,{className:`pb-2`,children:[(0,d.jsx)(a.CardDescription,{children:`Fill Rate`}),(0,d.jsxs)(a.CardTitle,{className:`text-2xl`,children:[o,`%`]})]}),(0,d.jsx)(a.CardContent,{children:(0,d.jsx)(`div`,{className:`w-full bg-muted rounded-full h-2`,children:(0,d.jsx)(`div`,{className:`bg-primary rounded-full h-2 transition-all`,style:{width:`${o}%`}})})})]}),(0,d.jsx)(a.Card,{children:(0,d.jsxs)(a.CardHeader,{className:`pb-2`,children:[(0,d.jsx)(a.CardDescription,{children:`Avg. Completion Time`}),(0,d.jsx)(a.CardTitle,{className:`text-2xl`,children:r.avgCompletionTime?bt(r.avgCompletionTime):`—`})]})})]}),r.dailySubmissions&&r.dailySubmissions.length>0&&(0,d.jsxs)(a.Card,{children:[(0,d.jsx)(a.CardHeader,{children:(0,d.jsx)(a.CardTitle,{className:`text-sm font-medium`,children:`Daily Submissions`})}),(0,d.jsx)(a.CardContent,{children:(0,d.jsx)(`div`,{className:`flex items-end gap-1 h-32`,children:r.dailySubmissions.map((e,t)=>(0,d.jsxs)(`div`,{className:`flex-1 flex flex-col items-center gap-1`,children:[(0,d.jsx)(`div`,{className:`w-full bg-primary/80 rounded-t transition-all hover:bg-primary`,style:{height:`${e.count/s*100}%`,minHeight:e.count>0?`4px`:`0`},title:`${e.date}: ${e.count} submissions`}),(0,d.jsx)(`span`,{className:`text-[10px] text-muted-foreground truncate w-full text-center`,children:e.date.slice(-5)})]},t))})})]}),r.fieldDropOff&&r.fieldDropOff.length>0&&(0,d.jsxs)(a.Card,{children:[(0,d.jsxs)(a.CardHeader,{children:[(0,d.jsx)(a.CardTitle,{className:`text-sm font-medium`,children:`Field Completion Rates`}),(0,d.jsx)(a.CardDescription,{children:`Percentage of users who completed each field`})]}),(0,d.jsx)(a.CardContent,{children:(0,d.jsx)(`div`,{className:`space-y-3`,children:r.fieldDropOff.map((e,t)=>(0,d.jsxs)(`div`,{className:`space-y-1`,children:[(0,d.jsxs)(`div`,{className:`flex justify-between text-sm`,children:[(0,d.jsx)(`span`,{className:`text-foreground`,children:e.label}),(0,d.jsxs)(`span`,{className:`text-muted-foreground`,children:[e.completionRate,`%`]})]}),(0,d.jsx)(`div`,{className:`w-full bg-muted rounded-full h-1.5`,children:(0,d.jsx)(`div`,{className:`rounded-full h-1.5 transition-all ${e.completionRate>=80?`bg-green-500`:e.completionRate>=50?`bg-yellow-500`:`bg-destructive`}`,style:{width:`${e.completionRate}%`}})})]},t))})})]})]})},St=({schema:e})=>{let o=(0,r.useSchemaContext)()?.dataSource,s=(0,r.useRecordContext)(),c=e.parentObject||s?.objectName,l=e.parentId||e.recordId||s?.recordId,[u,f]=(0,t.useState)([]),[p,m]=(0,t.useState)([]),[h,g]=(0,t.useState)(!0),[_,v]=(0,t.useState)(!1),[y,b]=(0,t.useState)(!1),[x,S]=(0,t.useState)(null),[C,w]=(0,t.useState)(null);(0,t.useEffect)(()=>{let t=o;if(!t||typeof t.getObjectSchema!=`function`)return;let n=!1;return t.getObjectSchema(e.childObject).then(e=>{n||w(e??null)}).catch(()=>{n||w(null)}),()=>{n=!0}},[o,e.childObject]);let T=JSON.stringify(e.filter??null),E=JSON.stringify(e.sort??null),D=(0,t.useMemo)(()=>(0,n.toFilterNode)(e.filter),[T]),O=(0,t.useMemo)(()=>(0,n.convertSortToQueryParams)(e.sort),[E]),k=(0,t.useCallback)(async()=>{if(!o||!l){g(!1);return}g(!0);try{let t={[e.relationshipField]:l},r=(await o.find(e.childObject,{$filter:D===void 0?t:(0,n.mergeFilterNodes)(t,D),...O?{$orderby:O}:{},$top:e.limit??500}))?.data??[];f(r.map(e=>({...e}))),m(r.map(e=>({...e}))),b(!1)}catch(e){S(e?.message||`Failed to load line items`)}finally{g(!1)}},[o,l,e.childObject,e.relationshipField,e.limit,D,O]);(0,t.useEffect)(()=>{k()},[k]);let A=(0,t.useCallback)(e=>{f(e),b(!0)},[]),j=(0,t.useCallback)(async()=>{if(!(!o||!l)){v(!0),S(null);try{let t=!!(c&&e.totalField),r=t?{[e.totalField]:Oe(u,e.amountField||`amount`)}:{},i=Ee(c??``,l,r,[{childObject:e.childObject,relationshipField:e.relationshipField,rows:u,original:p,childSchema:C}]);t||(i=i.slice(1)),i.length&&await(0,n.runBatchTransaction)(o,i),await k()}catch(e){S(e?.message||`Failed to save line items`)}finally{v(!1)}}},[o,l,u,p,e,c,k,C]),M=(0,t.useMemo)(()=>({columns:e.columns,total_field:e.totalField?e.amountField||`amount`:void 0,min_rows:e.minRows,max_rows:e.maxRows,allow_add:!e.readonly,allow_delete:!e.readonly}),[e]);return(0,d.jsxs)(a.Card,{className:(0,a.cn)(`shadow-none`),children:[(0,d.jsxs)(a.CardHeader,{className:`flex-row items-center justify-between gap-2 pb-2`,children:[(0,d.jsx)(a.CardTitle,{className:`text-sm font-medium`,children:e.title||`Line Items`}),!e.readonly&&(0,d.jsx)(a.Button,{type:`button`,size:`sm`,onClick:j,disabled:_||h||!y||!l,children:_?`Saving…`:`Save`})]}),(0,d.jsxs)(a.CardContent,{children:[x&&(0,d.jsx)(`p`,{className:`mb-2 text-sm text-destructive`,children:x}),h?(0,d.jsx)(`p`,{className:`py-6 text-center text-sm text-muted-foreground`,children:`Loading…`}):l?(0,d.jsx)(i.LineItemsField,{value:u,onChange:A,field:M,readonly:e.readonly}):(0,d.jsx)(`p`,{className:`py-6 text-center text-sm text-muted-foreground`,children:`Save the record first to add line items.`})]})]})},Ct=({schema:e,dataSource:t})=>{let n=(0,r.useResolvedDataSource)(t);return(0,d.jsx)(r.ElementDataSourceGate,{schema:e,dataSource:n,testId:`object-form`,errorTitle:`This form’s data source could not be resolved`,requiresDataSource:!(e?.customFields?.length>0)&&typeof e?.objectName==`string`&&e.objectName.length>0,noDataSourceMessage:(0,r.noDataSourceMessage)(`object-form`,e?.objectName),children:e=>(0,d.jsx)(lt,{schema:e,dataSource:n})})};n.ComponentRegistry.register(`object-form`,Ct,{namespace:`plugin-form`,label:`Object Form`,category:`plugin`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`fields`,type:`array`,label:`Fields`},{name:`mode`,type:`enum`,label:`Mode`,enum:[`create`,`edit`,`view`]},{name:`formType`,type:`enum`,label:`Form Type`,enum:[`simple`,`tabbed`,`wizard`,`split`,`drawer`,`modal`]},{name:`sections`,type:`array`,label:`Sections`},{name:`title`,type:`string`,label:`Title`},{name:`description`,type:`string`,label:`Description`},{name:`layout`,type:`enum`,label:`Layout`,enum:[`vertical`,`horizontal`,`inline`,`grid`]},{name:`columns`,type:`number`,label:`Columns`},{name:`defaultTab`,type:`string`,label:`Default Tab`},{name:`tabPosition`,type:`enum`,label:`Tab Position`,enum:[`top`,`bottom`,`left`,`right`]},{name:`allowSkip`,type:`boolean`,label:`Allow Skip Steps`},{name:`showStepIndicator`,type:`boolean`,label:`Show Step Indicator`},{name:`splitDirection`,type:`enum`,label:`Split Direction`,enum:[`horizontal`,`vertical`]},{name:`splitSize`,type:`number`,label:`Split Panel Size (%)`},{name:`splitResizable`,type:`boolean`,label:`Split Resizable`},{name:`drawerSide`,type:`enum`,label:`Drawer Side`,enum:[`top`,`bottom`,`left`,`right`]},{name:`drawerWidth`,type:`string`,label:`Drawer Width`},{name:`modalSize`,type:`enum`,label:`Modal Size`,enum:[`sm`,`default`,`lg`,`xl`,`full`]},{name:`modalCloseButton`,type:`boolean`,label:`Modal Close Button`,description:`Show the modal presentation’s close button. Read at ObjectForm.tsx:361 and honoured by ModalForm.`},{name:`contentLayout`,type:`enum`,label:`Modal Content Layout`,enum:[`simple`,`tabbed`],description:"How the modal presentation lays out sections. `tabbed` needs more than one section to differ from `simple` (ModalForm.tsx:638)."},{name:`confirmOnDiscard`,type:`boolean`,label:`Confirm On Discard`,description:"Ask before discarding unsaved edits when a drawer/modal form is dismissed. Set `false` to close immediately."},{name:`recordId`,type:`string`,label:`Record Id`,description:"The record to load in `edit` / `view` mode. Leave unset for `create`."},{name:`customFields`,type:`array`,label:`Custom Fields`,description:`Field definitions merged over the set generated from object metadata. With inline definitions and no data source, this becomes the only field source.`},{name:`initialValues`,type:`object`,label:`Initial Values`,description:"Values to prefill in `create` mode."},{name:`initialData`,type:`object`,label:`Initial Data`,description:"Alternate spelling of `initialValues` that the drawer/modal presentations read FIRST (`schema.initialData || schema.initialValues`). Prefer `initialValues` in new schemas."},{name:`readOnly`,type:`boolean`,label:`Read Only`,description:"Render every field read-only, whatever `mode` says."},{name:`submitText`,type:`string`,label:`Submit Button Text`},{name:`cancelText`,type:`string`,label:`Cancel Button Text`},{name:`nextText`,type:`string`,label:`Next Button Text`,description:`Label of the next-step button (wizard).`},{name:`prevText`,type:`string`,label:`Previous Button Text`,description:`Label of the previous-step button (wizard).`},{name:`showSubmit`,type:`boolean`,label:`Show Submit Button`},{name:`showCancel`,type:`boolean`,label:`Show Cancel Button`},{name:`showReset`,type:`boolean`,label:`Show Reset Button`},{name:`submitBehavior`,type:`object`,label:`Submit Behavior`,description:'Declarative post-submit behaviour, one of `{ kind: "thank-you", title?, message? }`, `{ kind: "redirect", url, delayMs? }`, `{ kind: "continue" }`, `{ kind: "next-record" }`. When present it takes precedence over `successMessage` / `navigateOnSuccess` / `resetOnSuccess`.'},{name:`successMessage`,type:`string`,label:`Success Message`,description:"Toast shown after a successful submit. Ignored when `submitBehavior` or `navigateOnSuccess` is set."},{name:`navigateOnSuccess`,type:`string`,label:`Navigate On Success`,description:"Path to navigate to after a successful create/update. Supports `{id}` / `{recordId}` interpolation from the saved record and is same-origin-guarded. Takes precedence over `successMessage`."},{name:`resetOnSuccess`,type:`boolean`,label:`Reset On Success`,description:`Clear the form after a successful submit instead of keeping the saved values.`},{name:`mobile`,type:`object`,label:`Mobile Overrides`,description:'Phone-only presentation overrides, e.g. `{ stepper: "auto", stepperMinFields: 8, fullscreenLongText: true }`.'}]}),n.ComponentRegistry.register(`form`,Ct,{namespace:`view`,skipFallback:!0,label:`Data Form View`,category:`view`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`fields`,type:`array`,label:`Fields`},{name:`mode`,type:`enum`,label:`Mode`,enum:[`create`,`edit`,`view`]}]}),n.ComponentRegistry.register(`embeddable-form`,({schema:e})=>{let n=(0,t.useContext)(r.SchemaRendererContext);return(0,d.jsx)(r.ElementDataSourceGate,{schema:e,dataSource:n?.dataSource,testId:`embeddable-form`,errorTitle:`This form’s data source could not be resolved`,children:e=>(0,d.jsx)(yt,{config:e,dataSource:n?.dataSource})})},{namespace:`plugin-form`,label:`Embeddable Form`,category:`plugin`,inputs:[{name:`formId`,type:`string`,label:`Form ID`,required:!0},{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`title`,type:`string`,label:`Form Title`},{name:`description`,type:`string`,label:`Description`},{name:`fields`,type:`array`,label:`Fields`},{name:`allowMultiple`,type:`boolean`,label:`Allow Multiple Submissions`}]}),n.ComponentRegistry.register(`form-analytics`,({schema:e})=>(0,d.jsx)(xt,{formId:e.formId,formTitle:e.formTitle,metrics:e.metrics||{totalSubmissions:0}}),{namespace:`plugin-form`,label:`Form Analytics`,category:`plugin`,inputs:[{name:`formId`,type:`string`,label:`Form ID`,required:!0},{name:`formTitle`,type:`string`,label:`Form Title`},{name:`metrics`,type:`object`,label:`Submission Metrics`}]}),n.ComponentRegistry.register(`object-master-detail-form`,({schema:e})=>{let n=(0,t.useContext)(r.SchemaRendererContext)?.dataSource??void 0;return(0,d.jsx)(r.ElementDataSourceGate,{schema:e,dataSource:n,testId:`object-master-detail-form`,errorTitle:`This form’s data source could not be resolved`,children:e=>(0,d.jsx)($e,{schema:e,dataSource:n})})},{namespace:`plugin-form`,label:`Master-Detail Form`,category:`plugin`,inputs:[{name:`objectName`,type:`string`,label:`Parent Object`,required:!0},{name:`mode`,type:`enum`,label:`Mode`,enum:[`create`,`edit`]},{name:`sections`,type:`array`,label:`Parent Sections`},{name:`details`,type:`array`,label:`Detail Collections`,required:!0},{name:`recordId`,type:`string`,label:`Parent Record Id`,description:"The parent record to load in `edit` mode. Leave unset for `create`."},{name:`formType`,type:`string`,label:`Parent Form Presentation`,description:`How the PARENT half of the form is presented. The detail grids below it are unaffected.`},{name:`fields`,type:`array`,label:`Parent Fields`,description:"Which parent fields to show, in order. Ignored when `sections` is given — sections carry their own field lists."},{name:`title`,type:`string`,label:`Title`},{name:`submitText`,type:`string`,label:`Submit Button Text`,description:`Label of the button that saves the parent and every detail row in one batch.`},{name:`cancelText`,type:`string`,label:`Cancel Button Text`},{name:`showSubmit`,type:`boolean`,label:`Show Submit Button`},{name:`initialValues`,type:`object`,label:`Initial Values`,description:"Values to prefill on the PARENT record in `create` mode."},{name:`initialData`,type:`object`,label:`Initial Data`,description:"Alternate spelling of `initialValues` the renderer also reads (MasterDetailForm.tsx:602). Prefer `initialValues` in new schemas."},{name:`taxRateField`,type:`string`,label:`Tax Rate Field`,description:`Name of the field ON THE CHILD object that holds each line’s tax rate. Feeds the line-items totals row; leave unset when the detail rows carry no tax.`}]});var wt={object:`childObject`,filter:!0,sort:!0,limit:`limit`};n.ComponentRegistry.register(`line_items`,({schema:e})=>(0,d.jsx)(r.ElementDataSourceGate,{schema:e,mapping:wt,testId:`record-line-items`,errorTitle:`This line-items panel’s data source could not be resolved`,children:e=>(0,d.jsx)(St,{schema:e})}),{namespace:`record`,skipFallback:!0,label:`Line Items`,category:`record`,inputs:[{name:`childObject`,type:`string`,label:`Child Object`,required:!0},{name:`relationshipField`,type:`string`,label:`Relationship Field`,required:!0},{name:`columns`,type:`array`,label:`Columns`,required:!0},{name:`totalField`,type:`string`,label:`Parent Total Field`},{name:`amountField`,type:`string`,label:`Amount Column`}]}),e.DrawerForm=it,e.EmbeddableForm=yt,e.FormAnalytics=xt,e.FormSectionContainer=fe,e.LineItemsPanel=St,e.MasterDetailForm=$e,e.ModalForm=st,e.ObjectForm=lt,e.SplitForm=_e,e.TabbedForm=$,e.WizardForm=ge,e.applyAutoColSpan=K,e.applyAutoLayout=le,e.containerGridColsFor=Y,e.deriveColumns=Ve,e.deriveDetail=Xe,e.deriveFormFields=We,e.filterAutoGeneratedFields=se,e.filterCreateModeFields=q,e.filterSystemFields=oe,e.findRelationshipField=Ie,e.inferColumns=ie,e.inferModalSize=ce,e.isAutoGeneratedFieldType=U,e.isWideFieldType=H,e.resolveInlineMode=qe});
@@ -1,34 +1,28 @@
1
- /**
2
- * ObjectUI
3
- * Copyright (c) 2024-present ObjectStack Inc.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
1
+ import { isRuntimeDefault } from '@object-ui/core';
2
+ export { isRuntimeDefault };
8
3
  /** An object schema as the data source serves it (`{ fields: { [name]: def } }`). */
9
4
  interface ObjectSchemaLike {
10
5
  fields?: Record<string, {
11
6
  defaultValue?: unknown;
7
+ type?: unknown;
8
+ reference?: unknown;
9
+ reference_to?: unknown;
12
10
  } | undefined>;
13
11
  }
14
12
  /**
15
- * Is this declared `defaultValue` a RUNTIME INSTRUCTION the server resolves per
16
- * insert, rather than a literal value?
17
- *
18
- * True for the `DEFAULT_VALUE_TOKENS` family (`'NOW()'` / `'current_user'`) and
19
- * for CEL/template Expression envelopes. This is THE classifier for "the
20
- * producer owns this field's create value" — both consumers in this package
21
- * read it, and neither may grow a second copy:
22
- *
23
- * 1. seeding (#4047 / #4068) — such a default is not seeded, because putting
24
- * the literal text `NOW()` into a datetime input and submitting it
25
- * suppresses the very resolution the declaration asked for;
26
- * 2. the create-mode `required` rule (#4069) — see {@link isRequiredInForm}.
27
- *
28
- * The two are the same fact seen twice: a field whose value the server supplies
29
- * is neither seedable nor missing.
13
+ * The session facts create-form seeding may draw on (#5683). Callers thread it
14
+ * from `usePermissions()`; every key is optional so existing call sites keep
15
+ * compiling and behaving unchanged until they opt in.
30
16
  */
31
- export declare function isRuntimeDefault(v: unknown): boolean;
17
+ export interface SeedContext {
18
+ /**
19
+ * The acting user's id (`usePermissions().userId`), or null/undefined when
20
+ * unknown — no provider, anonymous, or still loading. Unknown seeds nothing:
21
+ * the field stays empty and OMITTED from the payload, which is the case the
22
+ * engine's own `current_user` resolution handles at insert.
23
+ */
24
+ currentUserId?: string | null;
25
+ }
32
26
  /**
33
27
  * Can this declared `defaultValue` be used as a form's initial value as-is?
34
28
  *
@@ -85,9 +79,16 @@ export declare function isCreateFormMode(form: {
85
79
  * user really is not required to provide the value. Surfacing what the server
86
80
  * WILL supply is issue #4069's option B, a separate follow-up card.
87
81
  *
88
- * Deliberately NOT extended to `requiredWhen` (the conditional-required CEL
89
- * rule): that is resolved downstream in the form renderer against the live
90
- * record, outside this package.
82
+ * The CONDITIONAL spelling (`requiredWhen`) reaches the same verdict, ruled
83
+ * identically in #4085 — but it cannot be decided here, because it is resolved
84
+ * downstream against the live record. It is suppressed in the one evaluator
85
+ * that resolves it, `resolveFieldRuleState`, which reads the same fact off
86
+ * `@object-ui/core`'s `isServerOwnedValue` (and therefore the same
87
+ * {@link isRuntimeDefault} classifier this function reads). That evaluator
88
+ * subsumes this function on every path that threads the fact; this static
89
+ * answer stays because it is also the one the containers publish as the
90
+ * FormField's `required` flag, and because it is what re-runs when a form VIEW
91
+ * restates `required` over the object field (see `normalizeSectionField`).
91
92
  */
92
93
  export declare function isRequiredInForm(field: {
93
94
  required?: unknown;
@@ -99,7 +100,7 @@ export declare function isRequiredInForm(field: {
99
100
  * Returns a fresh object (never shared), and `{}` for a missing/!object schema
100
101
  * so callers can spread it unconditionally.
101
102
  */
102
- export declare function schemaDefaultValues(objectSchema: ObjectSchemaLike | null | undefined): Record<string, unknown>;
103
+ export declare function schemaDefaultValues(objectSchema: ObjectSchemaLike | null | undefined, ctx?: SeedContext): Record<string, unknown>;
103
104
  /**
104
105
  * The initial values a CREATE form opens with: the schema's static defaults,
105
106
  * overlaid with whatever the caller supplied.
@@ -109,7 +110,7 @@ export declare function schemaDefaultValues(objectSchema: ObjectSchemaLike | nul
109
110
  * carrying state forward), and an explicit `null` from a caller is a real
110
111
  * "leave this blank", not an absence.
111
112
  */
112
- export declare function seedCreateValues(objectSchema: ObjectSchemaLike | null | undefined, initial?: Record<string, unknown> | null): Record<string, unknown>;
113
+ export declare function seedCreateValues(objectSchema: ObjectSchemaLike | null | undefined, initial?: Record<string, unknown> | null, ctx?: SeedContext): Record<string, unknown>;
113
114
  /**
114
115
  * Drop the fields a CREATE payload must leave to the producer (#4069).
115
116
  *
@@ -138,5 +139,4 @@ export declare function seedCreateValues(objectSchema: ObjectSchemaLike | null |
138
139
  * discard the user's edit.
139
140
  */
140
141
  export declare function omitServerResolvedDefaults(data: Record<string, unknown>, objectSchema: ObjectSchemaLike | null | undefined): Record<string, unknown>;
141
- export {};
142
142
  //# sourceMappingURL=schemaDefaults.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"schemaDefaults.d.ts","sourceRoot":"","sources":["../src/schemaDefaults.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAgEH,qFAAqF;AACrF,UAAU,gBAAgB;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,YAAY,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,SAAS,CAAC,CAAC;CACjE;AAkBD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAEpD;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAGrD;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,GAAG,SAAS,GACpE,OAAO,CAET;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;IAAC,YAAY,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,GAAG,SAAS,EACxE,YAAY,EAAE,OAAO,GACpB,OAAO,CAIT;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,gBAAgB,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAS9G;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,YAAY,EAAE,gBAAgB,GAAG,IAAI,GAAG,SAAS,EACjD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GACvC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAEzB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,0BAA0B,CACxC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,YAAY,EAAE,gBAAgB,GAAG,IAAI,GAAG,SAAS,GAChD,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAUzB"}
1
+ {"version":3,"file":"schemaDefaults.d.ts","sourceRoot":"","sources":["../src/schemaDefaults.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmEG;AAEH,OAAO,EAAwB,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAQzE,OAAO,EAAE,gBAAgB,EAAE,CAAC;AAE5B,qFAAqF;AACrF,UAAU,gBAAgB;IACxB,MAAM,CAAC,EAAE,MAAM,CACb,MAAM,EACN;QAAE,YAAY,CAAC,EAAE,OAAO,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,CAAC;QAAC,SAAS,CAAC,EAAE,OAAO,CAAC;QAAC,YAAY,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,SAAS,CACpG,CAAC;CACH;AAED;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC1B;;;;;OAKG;IACH,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAGrD;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,GAAG,SAAS,GACpE,OAAO,CAET;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;IAAC,YAAY,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,GAAG,SAAS,EACxE,YAAY,EAAE,OAAO,GACpB,OAAO,CAIT;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,YAAY,EAAE,gBAAgB,GAAG,IAAI,GAAG,SAAS,EACjD,GAAG,CAAC,EAAE,WAAW,GAChB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAyBzB;AAqBD;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,YAAY,EAAE,gBAAgB,GAAG,IAAI,GAAG,SAAS,EACjD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,EACxC,GAAG,CAAC,EAAE,WAAW,GAChB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAEzB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,0BAA0B,CACxC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,YAAY,EAAE,gBAAgB,GAAG,IAAI,GAAG,SAAS,GAChD,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAUzB"}
@@ -27,6 +27,15 @@ export interface SectionFieldsContext {
27
27
  */
28
28
  fieldLabel: (objectName: string, fieldName: string, fallback: string) => string;
29
29
  }
30
+ /**
31
+ * Build a runtime FormField from object-schema metadata for `fieldName`.
32
+ *
33
+ * The ONE object-field-to-FormField mapping in this package. Exported because
34
+ * the flat (no-sections) containers need the identical mapping — see
35
+ * `flatFields.ts`, and objectui#4755 for what a second hand-copied version
36
+ * costs.
37
+ */
38
+ export declare function fromObjectSchema(fieldName: string, ctx: SectionFieldsContext): FormField;
30
39
  /**
31
40
  * Normalize one section field definition (string | spec object | runtime
32
41
  * FormField) into a runtime FormField with a guaranteed `name`.
@@ -1 +1 @@
1
- {"version":3,"file":"sectionFields.d.ts","sourceRoot":"","sources":["../src/sectionFields.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAIlD,MAAM,WAAW,oBAAoB;IACnC,2EAA2E;IAC3E,YAAY,EAAE,GAAG,CAAC;IAClB,0CAA0C;IAC1C,UAAU,EAAE,MAAM,CAAC;IACnB,iCAAiC;IACjC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,sDAAsD;IACtD,IAAI,CAAC,EAAE,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;IAClC;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;;;;OAOG;IACH,UAAU,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAC;CACjF;AA8ED;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACtC,GAAG,EAAE,oBAAoB,GACxB,SAAS,CA2FX;AAED,8CAA8C;AAC9C,wBAAgB,kBAAkB,CAChC,OAAO,EAAE;IAAE,MAAM,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAA;CAAE,EACxD,GAAG,EAAE,oBAAoB,GACxB,SAAS,EAAE,CAEb"}
1
+ {"version":3,"file":"sectionFields.d.ts","sourceRoot":"","sources":["../src/sectionFields.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAIlD,MAAM,WAAW,oBAAoB;IACnC,2EAA2E;IAC3E,YAAY,EAAE,GAAG,CAAC;IAClB,0CAA0C;IAC1C,UAAU,EAAE,MAAM,CAAC;IACnB,iCAAiC;IACjC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,sDAAsD;IACtD,IAAI,CAAC,EAAE,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;IAClC;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;;;;OAOG;IACH,UAAU,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAC;CACjF;AA2CD;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,oBAAoB,GAAG,SAAS,CAgCxF;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACtC,GAAG,EAAE,oBAAoB,GACxB,SAAS,CA2FX;AAED,8CAA8C;AAC9C,wBAAgB,kBAAkB,CAChC,OAAO,EAAE;IAAE,MAAM,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAA;CAAE,EACxD,GAAG,EAAE,oBAAoB,GACxB,SAAS,EAAE,CAEb"}