@object-ui/plugin-detail 17.1.0 → 17.3.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,5 +1,5 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@object-ui/core"),require("react"),require("@object-ui/components"),require("lucide-react"),require("@object-ui/react"),require("@object-ui/fields"),require("@object-ui/i18n"),require("react-router-dom"),require("react/jsx-runtime"),require("@object-ui/permissions"),require("@object-ui/types"),require("@objectstack/spec/data")):typeof define==`function`&&define.amd?define([`exports`,`@object-ui/core`,`react`,`@object-ui/components`,`lucide-react`,`@object-ui/react`,`@object-ui/fields`,`@object-ui/i18n`,`react-router-dom`,`react/jsx-runtime`,`@object-ui/permissions`,`@object-ui/types`,`@objectstack/spec/data`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ObjectUIPluginDetail={},e.ObjectUICore,e.React,e.ObjectUIComponents,e.LucideReact,e.ObjectUIReact,e.ObjectUIFields,e._object_ui_i18n,e.react_router_dom,e.jsxRuntime,e._object_ui_permissions,e.ObjectUITypes,e._objectstack_spec_data))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d,f){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var p=Object.create,m=Object.defineProperty,h=Object.getOwnPropertyDescriptor,g=Object.getOwnPropertyNames,_=Object.getPrototypeOf,v=Object.prototype.hasOwnProperty,y=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=g(t),a=0,o=i.length,s;a<o;a++)s=i[a],!v.call(e,s)&&s!==n&&m(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=h(t,s))||r.enumerable});return e};n=((e,t,n)=>(n=e==null?{}:p(_(e)),y(t||!e||!e.__esModule?m(n,`default`,{value:e,enumerable:!0}):n,e)))(n,1);var b=new Set([`textarea`,`markdown`,`html`,`grid`,`rich-text`,`field:textarea`,`field:markdown`,`field:html`,`field:grid`,`field:rich-text`]);function x(e){return b.has(e)}function S(e,t){let n;return n=e<=3?1:e<=8?2:e<=15?3:4,t!==void 0&&t<640?Math.min(n,1):n}function C(e,t){return t<=1?e:e.map(e=>e.span===void 0&&e.type&&x(e.type)?{...e,span:t}:e)}function w(e,t,n){if(t!==void 0)return{fields:C(e,t),columns:t};let r=S(e.length,n);return{fields:C(e,r),columns:r}}var T=s.createSafeTranslation,E={"detail.back":`Back`,"detail.edit":`Edit`,"detail.editInline":`Edit`,"detail.save":`Save`,"detail.saveChanges":`Save changes`,"detail.editFieldsInline":`Edit fields inline`,"detail.editInlineHint":`Double-click to edit`,"detail.cancel":`Cancel`,"detail.cancelEdit":`Discard changes`,"detail.openInNewTab":`Open in new tab`,"detail.share":`Share`,"detail.duplicate":`Duplicate`,"detail.export":`Export`,"detail.viewHistory":`View history`,"detail.delete":`Delete`,"detail.moreActions":`More actions`,"detail.addToFavorites":`Add to favorites`,"detail.removeFromFavorites":`Remove from favorites`,"detail.previousRecord":`Previous record`,"detail.nextRecord":`Next record`,"detail.recordOf":`{{current}} of {{total}}`,"detail.recordNotFound":`Record not found`,"detail.recordNotFoundDescription":`The record you are looking for does not exist or may have been deleted.`,"detail.goBack":`Go back`,"detail.details":`Details`,"detail.related":`Related`,"detail.relatedRecords":`{{count}} records`,"detail.relatedRecordOne":`{{count}} record`,"detail.noRelatedRecords":`No related records found`,"detail.loading":`Loading...`,"detail.copyToClipboard":`Copy to clipboard`,"detail.copied":`Copied!`,"detail.deleteConfirmation":`Are you sure you want to delete this record?`,"detail.editRecord":`Edit record`,"detail.viewAll":`View All`,"detail.new":`New`,"detail.emptyValue":`—`,"detail.noValue":`No value`,"detail.activity":`Activity`,"detail.copyRecordId":`Copy record ID`,"detail.showEmptyFields":`Show {{count}} empty fields`,"detail.hideEmptyFields":`Hide empty fields`,"detail.editRow":`Edit`,"detail.deleteRow":`Delete`,"detail.deleteRowConfirmation":`Are you sure you want to delete this record?`,"detail.actions":`Actions`,"detail.previousPage":`Previous`,"detail.nextPage":`Next`,"detail.pageOf":`Page {{current}} of {{total}}`,"detail.sortBy":`Sort by`,"detail.filterPlaceholder":`Filter...`,"detail.highlightFields":`Key Fields`,"detail.comments":`Comments`,"detail.searchComments":`Search comments…`,"detail.addCommentPlaceholder":`Add a comment… (Ctrl+Enter to submit)`,"detail.noMatchingComments":`No matching comments`,"detail.noCommentsYet":`No comments yet`,"detail.pinned":`Pinned`,"detail.pin":`Pin`,"detail.unpin":`Unpin`,"detail.justNow":`just now`,"detail.minutesAgo":`{{count}}m ago`,"detail.hoursAgo":`{{count}}h ago`,"detail.daysAgo":`{{count}}d ago`,"detail.createdBy":`Created by`,"detail.updatedBy":`Updated by`,"detail.created":`Created`,"detail.updated":`Updated`,"detail.dropFilesToUpload":`Drop files here or click to upload`,"detail.attachmentCount":`{{count}} attachment`,"detail.attachmentCountPlural":`{{count}} attachments`,"detail.removeAttachment":`Remove attachment`,"detail.unifiedDiff":`Unified diff`,"detail.sideBySideDiff":`Side-by-side diff`,"detail.noChanges":`No changes`,"detail.previousVersion":`Previous`,"detail.currentVersion":`Current`,"detail.discussion":`Discussion`,"detail.showDiscussion":`Show Discussion ({{count}})`,"detail.hideDiscussion":`Hide discussion`,"detail.bold":`Bold (Ctrl+B)`,"detail.italic":`Italic (Ctrl+I)`,"detail.listFormat":`List`,"detail.inlineCode":`Inline code`,"detail.mentionSomeone":`Mention someone`,"detail.preview":`Preview`,"detail.submitComment":`Submit (Ctrl+Enter)`,"detail.sendComment":`Send`,"detail.writeComment":`Write a comment…`,"detail.subscribedTooltip":`Subscribed — click to unsubscribe`,"detail.unsubscribedTooltip":`Subscribe to notifications`,"detail.firstRecord":`First record (Home)`,"detail.previousRecordKey":`Previous record (←)`,"detail.nextRecordKey":`Next record (→)`,"detail.lastRecord":`Last record (End)`,"detail.noRecords":`No records`,"detail.showEmptyRelated_one":`+ {{count}} empty`,"detail.showEmptyRelated_other":`+ {{count}} empty`,"detail.searchWhileNavigating":`Search while navigating`,"detail.searchRecords":`Search records…`,"detail.allActivity":`All Activity`,"detail.commentsOnly":`Comments Only`,"detail.fieldChangesFilter":`Field Changes`,"detail.tasksOnly":`Tasks Only`,"detail.leaveCommentPlaceholder":`Leave a comment… (Ctrl+Enter to submit)`,"detail.noActivity":`No activity recorded`,"detail.loadMore":`Load more`,"detail.edited":`(edited)`,"detail.via":`via {{source}}`,"detail.viewSource":`View source`,"detail.replyCount":`{{count}} reply`,"detail.replyCountPlural":`{{count}} replies`,"detail.replyPlaceholder":`Reply…`,"detail.filterActivity":`Filter activity`,"detail.openDiscussion":`Open discussion panel`,"detail.closeDiscussion":`Close discussion panel`,"detail.subscribeAriaLabel":`Subscribe to notifications`,"detail.unsubscribeAriaLabel":`Unsubscribe from notifications`,"detail.clearSearch":`Clear search`,"detail.concurrentUpdateTitle":`This record was modified by someone else`,"detail.concurrentUpdateDescription":`Another user saved a newer version of {{field}} while you were editing. To prevent silently overwriting their change, please choose how to resolve the conflict.`,"detail.concurrentUpdateYourEdit":`Your edit`,"detail.concurrentUpdateCurrentValue":`Current value`,"detail.concurrentUpdateUpdatedBy":`Updated by {{name}}`,"detail.concurrentUpdateUpdatedAt":`Updated at {{when}}`,"detail.concurrentUpdateReload":`Reload latest`,"detail.concurrentUpdateOverwrite":`Overwrite anyway`,"detail.concurrentUpdateCancel":`Cancel`,"detail.lockedByApproval":`Locked for approval`,"detail.lockedTooltip":`This record has a pending approval request; editing is locked`,"detail.approvalPendingEditable":`In approval · editable`,"detail.approvalPendingTooltip":`This record has a pending approval request; this step still allows editing`,"detail.cancelApproval":`Recall approval`,"detail.cancelApprovalInFlight":`Recalling…`,"detail.cancelApprovalTooltip":`Recall the pending approval request to unlock this record`,"detail.cancelApprovalTooltipUnlocked":`Recall the pending approval request`,"detail.cancelApprovalFailed":`Failed to recall approval`,"detail.cancelApprovalUnavailable":`Recalling approvals is not supported on this data source`},D=T(E,`detail.back`);function O(e){if(typeof e==`string`){let t=e.trim();if(!t)return null;try{return JSON.parse(t)}catch{return t}}return e??null}function k(e){let t=O(e);return t==null||t===``?0:Array.isArray(t)?t.length:typeof t==`object`?Object.keys(t).length:1}function A({value:e,field:t}){let{t:n}=D(),i=(0,a.useRecordContext)(),{appName:s}=(0,c.useParams)(),u=t?.name||``,d=i?.data?.name,f=s&&d?`/apps/${s}/metadata/permission/${encodeURIComponent(String(d))}`:null,p=k(e),m=p===0;return(0,l.jsxs)(`span`,{className:`inline-flex flex-wrap items-center gap-x-2 gap-y-1 text-sm`,children:[(()=>{if(m)return(0,l.jsx)(`span`,{className:`text-muted-foreground`,children:n(`perm.facet.none`,{defaultValue:`None`})});if(u===`system_permissions`){let t=(0,o.parseCapabilityNames)(e),i=t.slice(0,6),a=t.length-i.length;return(0,l.jsxs)(`span`,{className:`inline-flex flex-wrap items-center gap-1`,children:[i.map(e=>(0,l.jsx)(r.Badge,{variant:`outline`,children:e},e)),a>0&&(0,l.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:n(`perm.facet.more`,{count:a,defaultValue:`+${a} more`})})]})}return(0,l.jsx)(`span`,{className:`text-foreground`,children:(()=>{switch(u){case`object_permissions`:return n(`perm.facet.objects`,{count:p,defaultValue:`${p} object${p===1?``:`s`}`});case`field_permissions`:return n(`perm.facet.fields`,{count:p,defaultValue:`${p} field rule${p===1?``:`s`}`});case`row_level_security`:return n(`perm.facet.rls`,{count:p,defaultValue:`${p} RLS polic${p===1?`y`:`ies`}`});case`tab_permissions`:return n(`perm.facet.tabs`,{count:p,defaultValue:`${p} tab rule${p===1?``:`s`}`});case`admin_scope`:return n(`perm.facet.adminScope`,{defaultValue:`Delegated admin configured`});default:return String(p)}})()})})(),f?(0,l.jsx)(c.Link,{to:f,className:`text-primary hover:underline whitespace-nowrap`,children:n(`perm.facet.designInStudio`,{defaultValue:`Design in Studio →`})}):(0,l.jsx)(`span`,{className:`text-muted-foreground/60 whitespace-nowrap`,children:n(`perm.facet.designInStudioHint`,{defaultValue:`Design in Studio`})})]})}var j=new Set([`id`,`_id`,`__v`,`created`,`created_at`,`createdAt`,`created_by`,`modified`,`modified_by`,`updated_at`,`updatedAt`,`updated_by`,`deleted_at`,`is_deleted`,`deleted`,`instance_state`]),M=new Set([`formula`,`summary`,`rollup`,`auto_number`]);function N(e){if(e==null)return e;if(Array.isArray(e))return e.map(N);if(typeof e==`object`){let t=e;return t.id??t._id??t.value??``}return e}var ee=({field:e,value:t,onChange:n,dataSource:r,autoFocus:i})=>{let a=e.type,s=e.widget;if(s===`permission-facet-link`)return(0,l.jsx)(A,{value:t,field:e});if(s===`capability-multiselect`)return(0,l.jsx)(o.CapabilityMultiSelectField,{value:t,onChange:e=>n(e),field:e,dataSource:r});let c=a===`multiselect`||!!e.multiple;if((a===`select`||a===`multiselect`)&&Array.isArray(e.options)&&e.options.length>0)return c?(0,l.jsx)(o.SelectField,{field:{...e,multiple:!0},value:Array.isArray(t)?t:t==null||t===``?[]:[t],onChange:e=>n(e)}):(0,l.jsx)(o.SelectField,{field:e,value:t==null?``:String(t),onChange:e=>n(e)});if(a===`boolean`)return(0,l.jsx)(o.BooleanField,{field:e,value:!!t,onChange:e=>n(e)});if(a===`image`)return(0,l.jsx)(o.ImageField,{field:e,value:t,onChange:e=>n(e)});if(a===`avatar`)return(0,l.jsx)(o.AvatarField,{field:e,value:t,onChange:e=>n(e)});if(a===`signature`)return(0,l.jsx)(o.SignatureField,{field:e,value:t,onChange:e=>n(e)});if(a===`file`||a===`video`||a===`audio`)return(0,l.jsx)(o.FileField,{field:e,value:t,onChange:e=>n(e)});let u=a===`user`||a===`owner`,d=a===`lookup`||a===`master_detail`||a===`tree`||!!e.reference_to&&!M.has(a);if(u||d)return(0,l.jsx)(u?o.UserField:o.LookupField,{field:e,value:t,onChange:e=>n(e),dataSource:r});if(a===`number`)return(0,l.jsx)(o.NumberField,{field:e,value:t,onChange:e=>n(e),autoFocus:i});if(a===`currency`)return(0,l.jsx)(o.CurrencyField,{field:e,value:t,onChange:e=>n(e),autoFocus:i});if(a===`percent`)return(0,l.jsx)(o.PercentField,{field:e,value:t,onChange:e=>n(e),autoFocus:i});let f=a===`date`||a===`datetime`;return(0,l.jsx)(`input`,{type:f?`date`:`text`,autoFocus:i,className:`w-full px-2 py-1.5 text-sm border rounded-md bg-background focus:outline-none focus:ring-2 focus:ring-ring`,value:t==null?``:f?(()=>{let e=String(t);if(/^\d{4}-\d{2}-\d{2}/.test(e))return e.slice(0,10);let n=new Date(e);return isNaN(n.getTime())?``:n.toLocaleDateString(`en-CA`)})():String(typeof t==`object`?(0,o.coerceToSafeValue)(t)??``:t),onChange:e=>{let t=e.target.value;n(f&&t?new Date(t+`T00:00:00`).toISOString():t)}})},P=`options.currency.currencyConfig.precision.scale.min.max.step.format.widget.dueLike.multiple.reference_field.display_field.displayField.description_field.descriptionField.id_field.allow_create.allowCreate.lookup_columns.lookupColumns.lookup_page_size.lookupPageSize.lookup_filters.lookupFilters.picker.subtitle.avatar_field.avatarField.depends_on.dependsOn`.split(`.`);function F(e,t){let n={...e};if(!t)return n;!n.type&&t.type&&(n.type=t.type);for(let e of P){let r=t[e];r!==void 0&&n[e]===void 0&&(n[e]=r)}let r=t.reference_to||t.reference;return r&&n.reference_to===void 0&&(n.reference_to=r),n}var te=({name:e})=>/^[a-z0-9][a-z0-9-]*$/i.test(e)?(0,l.jsx)(r.LazyIcon,{name:e,className:`h-4 w-4 shrink-0 text-muted-foreground`,"aria-hidden":!0}):(0,l.jsx)(`span`,{className:`text-muted-foreground`,children:e});function I(e,t){return!e||e<=1||t<=1?``:t===2?e>=2?`md:col-span-2`:``:t===3?e===2?`md:col-span-2`:e>=3?`md:col-span-2 lg:col-span-3`:``:e===2?`md:col-span-2`:e===3?`md:col-span-2 lg:col-span-3`:e>=4?`md:col-span-2 lg:col-span-3 xl:col-span-4`:``}var L=({section:e,data:t,className:s,objectSchema:c,objectName:u,isEditing:d=!1,onFieldChange:f,onEnterInlineEdit:p,autoFocusField:m,dataSource:h,virtualScroll:g})=>{let[_,v]=n.useState(e.defaultCollapsed??!1),[y,b]=n.useState(null),[x,S]=n.useState(void 0),[C,T]=n.useState(!1),{t:E}=D(),{fieldLabel:O,translateOptions:k}=(0,a.useSafeFieldLabel)(),N=n.useCallback((e,t)=>{let n=t==null?``:String(t);navigator.clipboard.writeText(n).then(()=>{b(e),setTimeout(()=>b(null),2e3)})},[]),P=n.useCallback(e=>{let n=t?.[e.name]??e.value;return n==null||n===``},[t]),L=n.useMemo(()=>e.fields.filter(P).length,[e.fields,P]),R=(0,r.useIsMobile)(),ne=R?3:4,re=R?.2:.25,ie=e.fields.length-L,z=!e.hideEmpty&&!d&&e.fields.length>=ne&&L/e.fields.length>=re&&ie>0,B=!C&&(e.hideEmpty||z)?e.fields.filter(e=>!P(e)):e.fields,{fields:V,columns:H}=w(B,e.columns),U=Math.min(H,Math.max(1,B.length)),W=e=>{let n=t?.[e.name]??e.value;if(e.render)return(0,l.jsx)(a.SchemaRenderer,{schema:e.render,data:{...t,value:n}});let s=I(e.span,U),g=c?.fields?.[e.name],_=F(e,g);u&&Array.isArray(_.options)&&_.options.length>0&&(_.options=k(u,e.name,_.options));let v=_.type||e.type,b=M.has(v),x=e.readonly===!0||g?.readonly===!0,S=j.has(e.name),C=!x&&!b&&!S,w=C&&!!p,T=(()=>{if((_.widget||e.widget)===`permission-facet-link`)return(0,l.jsx)(A,{value:n,field:_});if(n==null||n===``)return(0,l.jsx)(`span`,{className:`text-muted-foreground/60 text-sm select-none`,"aria-label":E(`detail.noValue`,{defaultValue:`No value`}),title:E(`detail.noValue`,{defaultValue:`No value`}),children:`—`});let t=(0,o.resolveCellRendererType)(_)||e.type;if(t){let e=(0,o.getCellRenderer)(t);if(e)return(0,l.jsx)(e,{value:n,field:_})}return String(n)})(),D=n!=null&&n!==``,P=D&&!w,te=y===e.name,L=O(u||``,e.name,e.label||e.name);return R&&!(d&&C)?(0,l.jsxs)(`div`,{className:(0,r.cn)(`flex items-baseline justify-between gap-4 py-2.5 min-h-[44px] group`,D&&`cursor-pointer active:bg-muted/40 transition-colors`),onClick:D?()=>N(e.name,n):void 0,onKeyDown:D?t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),N(e.name,n))}:void 0,role:D?`button`:void 0,tabIndex:D?0:void 0,children:[(0,l.jsx)(`span`,{className:`text-[15px] text-muted-foreground shrink-0`,children:L}),(0,l.jsx)(`span`,{className:`text-[15px] text-foreground text-right break-words min-w-0 leading-snug`,children:T})]},e.name):(0,l.jsxs)(`div`,{className:(0,r.cn)(`space-y-1.5 group min-w-0`,s),children:[(0,l.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:O(u||``,e.name,e.label||e.name)}),d&&C?(0,l.jsx)(`div`,{className:`min-h-[44px] sm:min-h-0`,children:(0,l.jsx)(ee,{field:_,value:n,onChange:t=>f?.(e.name,t),dataSource:h,autoFocus:m===e.name})}):(0,l.jsxs)(`div`,{className:(0,r.cn)(`flex items-start justify-between gap-2 min-h-[44px] sm:min-h-0 rounded-md`,P&&`cursor-pointer active:bg-muted/60 transition-colors`,w&&`cursor-pointer hover:bg-muted/40 transition-colors -mx-1.5 px-1.5`),onClick:P?()=>N(e.name,n):void 0,onDoubleClick:w?()=>p?.(e.name):void 0,onKeyDown:P?t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),N(e.name,n))}:void 0,role:P?`button`:void 0,tabIndex:P?0:void 0,title:w?E(`detail.editInlineHint`):void 0,children:[(0,l.jsx)(`div`,{className:`text-sm flex-1 min-w-0 break-words py-1`,children:T}),w?(0,l.jsx)(r.TooltipProvider,{children:(0,l.jsxs)(r.Tooltip,{children:[(0,l.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,l.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-6 w-6 opacity-0 group-hover:opacity-100 transition-opacity shrink-0`,"aria-label":E(`detail.editInlineHint`),onClick:t=>{t.stopPropagation(),p?.(e.name)},children:(0,l.jsx)(i.Pencil,{className:`h-3 w-3`})})}),(0,l.jsx)(r.TooltipContent,{children:E(`detail.editInlineHint`)})]})}):D?(0,l.jsx)(r.TooltipProvider,{children:(0,l.jsxs)(r.Tooltip,{children:[(0,l.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,l.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-6 w-6 opacity-0 group-hover:opacity-100 transition-opacity shrink-0`,onClick:t=>{t.stopPropagation(),N(e.name,n)},children:te?(0,l.jsx)(i.Check,{className:`h-3 w-3 text-green-600`}):(0,l.jsx)(i.Copy,{className:`h-3 w-3`})})}),(0,l.jsx)(r.TooltipContent,{children:E(te?`detail.copied`:`detail.copyToClipboard`)})]})}):null]})]},e.name)},G=g?.enabled===!0,K=g?.batchSize??20;if(n.useEffect(()=>{if(!G){S(void 0);return}if(V.length<=K){S(void 0);return}S(K);let e=setTimeout(()=>S(void 0),100);return()=>clearTimeout(e)},[G,V.length,K]),B.length===0&&L===e.fields.length)return null;let ae=x===void 0?V:V.slice(0,x),q=L>0&&(e.hideEmpty||z),oe=(0,l.jsxs)(l.Fragment,{children:[R?(0,l.jsx)(`div`,{className:`flex flex-col divide-y divide-border/60`,children:ae.map(W)}):(0,l.jsx)(`div`,{className:(0,r.cn)(`grid gap-3 sm:gap-4`,U===1?`grid-cols-1`:U===2?`grid-cols-1 md:grid-cols-2`:U===3?`grid-cols-1 md:grid-cols-2 lg:grid-cols-3`:`grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4`),children:ae.map(W)}),q&&(0,l.jsx)(`div`,{className:`mt-3 -ml-2`,children:(0,l.jsxs)(r.Button,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>T(e=>!e),className:`h-7 px-2 text-xs text-muted-foreground hover:text-foreground`,children:[C?(0,l.jsx)(i.EyeOff,{className:`h-3.5 w-3.5 mr-1.5`}):(0,l.jsx)(i.Eye,{className:`h-3.5 w-3.5 mr-1.5`}),C?E(`detail.hideEmptyFields`,{defaultValue:`Hide empty fields`}):E(`detail.showEmptyFields`,{count:L,defaultValue:`Show ${L} empty field${L===1?``:`s`}`})]})})]});return!e.title&&!e.collapsible&&e.showBorder===!1?(0,l.jsx)(`div`,{className:(0,r.cn)(s),children:oe}):e.collapsible?(0,l.jsx)(r.Collapsible,{open:!_,onOpenChange:e=>v(!e),className:s,children:(0,l.jsxs)(r.Card,{children:[(0,l.jsx)(r.CollapsibleTrigger,{asChild:!0,children:(0,l.jsxs)(r.CardHeader,{className:(0,r.cn)(`py-3 px-4 sm:py-4 sm:px-6 cursor-pointer hover:bg-muted/50 transition-colors`,e.headerColor&&`bg-${e.headerColor}`),children:[(0,l.jsxs)(r.CardTitle,{className:`flex items-center justify-between text-base font-semibold tracking-tight`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.icon&&(0,l.jsx)(te,{name:e.icon}),(0,l.jsx)(`span`,{children:e.title})]}),(0,l.jsx)(`div`,{className:`flex items-center gap-2`,children:_?(0,l.jsx)(i.ChevronRight,{className:`h-4 w-4 text-muted-foreground`}):(0,l.jsx)(i.ChevronDown,{className:`h-4 w-4 text-muted-foreground`})})]}),e.description&&!_&&(0,l.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:e.description})]})}),(0,l.jsx)(r.CollapsibleContent,{children:(0,l.jsx)(r.CardContent,{className:`pt-3 sm:pt-4 px-3 sm:px-6 pb-4 sm:pb-5`,children:oe})})]})}):(0,l.jsxs)(r.Card,{className:(0,r.cn)(e.showBorder===!1?`border-none shadow-none`:``,s),children:[e.title&&(0,l.jsxs)(r.CardHeader,{className:(0,r.cn)(`py-3 px-4 sm:py-4 sm:px-6`,e.headerColor&&`bg-${e.headerColor}`),children:[(0,l.jsx)(r.CardTitle,{className:`flex items-center justify-between text-base font-semibold tracking-tight`,children:(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.icon&&(0,l.jsx)(te,{name:e.icon}),(0,l.jsx)(`span`,{children:e.title})]})}),e.description&&(0,l.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:e.description})]}),(0,l.jsx)(r.CardContent,{className:`pt-3 sm:pt-4 px-3 sm:px-6 pb-4 sm:pb-5`,children:oe})]})},R=({tabs:e,data:t,className:i})=>{let[o,s]=n.useState(e[0]?.key),c=e.filter(e=>typeof e.visible==`boolean`?e.visible:(e.visible,!0));return(0,l.jsxs)(r.Tabs,{value:o,onValueChange:s,className:i,children:[(0,l.jsx)(r.TabsList,{className:`w-full justify-start border-b rounded-none bg-transparent p-0`,children:c.map(e=>(0,l.jsx)(r.TabsTrigger,{value:e.key,className:`relative rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent`,children:(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.icon&&(0,l.jsx)(`span`,{children:e.icon}),(0,l.jsx)(`span`,{children:e.label}),e.badge&&(0,l.jsx)(r.Badge,{variant:`secondary`,className:`ml-1`,children:e.badge})]})},e.key))}),c.map(e=>(0,l.jsx)(r.TabsContent,{value:e.key,className:`mt-4 motion-safe:data-[state=active]:animate-in motion-safe:data-[state=active]:fade-in-0 motion-safe:duration-150`,children:(0,l.jsx)(n.Suspense,{fallback:null,children:Array.isArray(e.content)?(0,l.jsx)(`div`,{className:`space-y-4`,children:e.content.map((e,n)=>(0,l.jsx)(a.SchemaRenderer,{schema:e,data:t},n))}):(0,l.jsx)(a.SchemaRenderer,{schema:e.content,data:t})})},e.key))]})};function ne(e){return e&&i.icons[e.split(/[-_\s]/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``)]||i.Inbox}function re(e){if(!e)return[];if(typeof e==`string`){let t=e.trim();return t?t.startsWith(`-`)?[{field:t.slice(1),order:`desc`}]:[{field:t,order:`asc`}]:[]}return e.filter(e=>!!e?.field)}var ie=({action:e,onToolbarAction:t})=>{let n=e.visible,i=(0,a.useCondition)((0,a.toPredicateInput)(n));if(n&&!i)return null;let o=e.icon?ne(e.icon):null;return(0,l.jsxs)(r.Button,{variant:e.variant===`primary`?`default`:`outline`,size:`sm`,onClick:n=>{n.stopPropagation(),t(e)},className:`gap-1 h-9 sm:h-7 text-xs shadow-none`,"data-testid":`related-toolbar-action-${e.name}`,children:[o&&(0,l.jsx)(o,{className:`h-3.5 w-3.5`}),e.label||e.name]})},z=({title:e,type:s,api:c,data:d,schema:f,columns:p,className:m,dataSource:h,objectName:g,onNew:_,onViewAll:v,onRowEdit:y,onRowDelete:b,onRowClick:x,rowActions:S,onRowAction:C,toolbarActions:w,onToolbarAction:T,add:E,maxColumns:O=6,pageSize:k,defaultSort:A,sortable:j=!1,filterable:M=!1,collapsible:N=!1,defaultCollapsed:ee=!1,referenceField:P,parentId:F,icon:te})=>{let I=d!==void 0,L=d??[],[R,z]=n.useState(L),[B,V]=n.useState(()=>!!c&&!I),[H,U]=n.useState(0),[W,G]=n.useState(null),[K,ae]=n.useState(`asc`),[q,oe]=n.useState(``),[J,se]=n.useState(null),[ce,le]=n.useState(!1),[Y,ue]=n.useState(null),[de,fe]=n.useState(ee),[X,pe]=n.useState(!1),[me,he]=n.useState(!1),[ge,_e]=n.useState(null),[ve,ye]=n.useState(0),[be,xe]=n.useState({}),{t:Z}=D(),{fieldLabel:Se}=(0,a.useSafeFieldLabel)(),Q=k&&k>0?k:0,Ce=M&&q!==``,$=!I&&!!c&&Q>0&&!!h&&typeof h.find==`function`&&!Ce,we=$?H:0,Te=$?W:null,Ee=$?K:`asc`,De=JSON.stringify(A??null),Oe=n.useMemo(()=>re(A),[De]);n.useEffect(()=>{I&&z(d??[])},[d,I]),n.useEffect(()=>{c&&h?.getObjectSchema&&h.getObjectSchema(c).then(ue).catch(e=>{console.warn(`[RelatedList] Failed to fetch schema for ${c}:`,e)})},[c,h]),n.useEffect(()=>{let e=!1;if(c&&!I){if(!(P&&F!=null&&F!==``)){c&&(F==null||F===``)&&!P&&console.warn(`[RelatedList] "${c}" has no referenceField/parentId — refusing to fetch all rows. Pass relationshipField + parentId to scope the query.`),z([]),se(null),le(!1),V(!1);return}V(!0);let t={[P]:F};if(h&&typeof h.find==`function`){let n={$filter:t};if($){n.$top=Q,n.$skip=we*Q;let e=Te?[{field:Te,order:Ee}]:Oe;e.length>0&&(n.$orderby=e)}h.find(c,n).then(t=>{if(e)return;let n=Array.isArray(t),r=n?t:Array.isArray(t?.data)?t.data:[];if(z(r),$){let e=!n&&typeof t?.total==`number`?t.total:null;se(e),le(!n&&typeof t?.hasMore==`boolean`?t.hasMore:r.length===Q)}else se(null),le(!1);V(!1)}).catch(t=>{console.error(`Failed to fetch related data:`,t),e||V(!1)})}else{let t=new URLSearchParams({[`filter[${P}]`]:String(F)}).toString();fetch(`${c}?${t}`).then(e=>e.json()).then(t=>{if(e)return;let n=Array.isArray(t)?t:t?.data||[];z(n),se(null),le(!1)}).catch(e=>{console.error(`Failed to fetch related data:`,e)}).finally(()=>{e||V(!1)})}}return()=>{e=!0}},[c,I,h,P,F,ve,$,Q,we,Te,Ee,Oe]),n.useEffect(()=>{!$||B||H>0&&R.length===0&&U(e=>Math.max(0,e-1))},[$,B,R,H]),n.useEffect(()=>{U(0)},[c,P,F]),n.useEffect(()=>{if(!c||I)return;let e=e=>{let t=e.detail||{};t.objectName&&t.objectName!==c||ye(e=>e+1)};return window.addEventListener(`objectui:related-changed`,e),()=>window.removeEventListener(`objectui:related-changed`,e)},[c,I]),n.useEffect(()=>{if(!h?.find||!Y?.fields||!R.length)return;let e=Y.fields,t=[];for(let[n,r]of Object.entries(e)){if(!r||r.type!==`lookup`&&r.type!==`master_detail`)continue;let e=r.reference_to||r.reference;if(!e)continue;let i=new Set;for(let e of R){let t=e?.[n];t!=null&&(typeof t==`string`&&t?i.add(t):typeof t==`number`&&i.add(String(t)))}let a=be[n]||{},o=Array.from(i).filter(e=>!(e in a));o.length>0&&t.push({fieldName:n,target:e,ids:o})}if(t.length===0)return;let n=!1;return Promise.all(t.map(({fieldName:e,target:t,ids:n})=>h.find(t,{$filter:{id:{$in:n}},$top:n.length}).then(t=>{let n=Array.isArray(t)?t:t?.data||[],r={};for(let e of n){let t=e?.id||e?._id;t&&(r[String(t)]=e?.full_name||e?.fullname||e?.display_name||e?.name||e?.subject||e?.title||e?.label||e?.code||e?.email||String(t))}return{fieldName:e,map:r}}).catch(t=>(console.warn(`[RelatedList] Failed to resolve lookups for ${e}:`,t),{fieldName:e,map:{}})))).then(e=>{n||xe(t=>{let n={...t};for(let{fieldName:t,map:r}of e)n[t]={...n[t]||{},...r};return n})}),()=>{n=!0}},[h,Y,R]);let ke=n.useMemo(()=>{if($||!q)return R;let e=q.toLowerCase();return R.filter(t=>Object.values(t).some(t=>t!=null&&String(t).toLowerCase().includes(e)))},[R,q,$]),Ae=n.useMemo(()=>{if($||!W)return ke;let e=be[W],n=ke.map(n=>({row:n,key:(0,t.getSortValue)(n[W],{labels:e})}));return n.sort((e,n)=>{let r=(0,t.compareSortValues)(e.key,n.key);return K===`asc`?r:-r}),n.map(e=>e.row)},[ke,W,K,$,be]),je=Q&&!$?Ae.slice(H*Q,(H+1)*Q):Ae,Me=Q?$?J==null?H+(ce?2:1):Math.max(1,Math.ceil(J/Q)):Math.max(1,Math.ceil(Ae.length/Q)):1,Ne=$?J==null?ce:(H+1)*Q<J:H<Me-1,Pe=Q>0&&($?H>0||Ne:Ae.length>Q);n.useEffect(()=>{U(0)},[q,W,K]);let Fe=n.useCallback(e=>{U(0),W===e?ae(e=>e===`asc`?`desc`:`asc`):(G(e),ae(`asc`))},[W]),Ie=n.useMemo(()=>W?[{field:W,order:K}]:Oe,[W,K,Oe]),Le=n.useCallback(e=>{let t=e[0];t&&(U(0),G(t.field),ae(t.order))},[]),[Re,ze]=n.useState(null),Be=n.useCallback(e=>{ze(e)},[]),Ve=n.useCallback(async()=>{if(Re)try{await b?.(Re),ye(e=>e+1)}catch(e){console.error(`[RelatedList] remove failed`,e)}ze(null)},[Re,b]),He=n.useCallback(async e=>{if(!E||!h||!c||P==null||F==null)return;let t=E.picker.valueField||`id`;he(!0),_e(null);try{for(let n of e||[]){let e=n?.[t]??n?.id;e!=null&&(E.linkField?await h.create?.(c,{[P]:F,[E.linkField]:e}):await h.update?.(E.picker.object,String(e),{[P]:F}))}ye(e=>e+1)}catch(e){let t=e?.body?.error??e?.error??e?.message??String(e);_e(typeof t==`string`?t:`Failed to add`)}finally{he(!1),pe(!1)}},[E,h,c,P,F]),Ue=(0,u.usePermissions)(),We=n.useMemo(()=>{let e=g||c||``,r=n=>!Ue?.isLoaded||!e?n:n.filter(n=>{let r=n?.accessorKey||(0,t.columnIdentity)(n);return!r||Ue.checkField(e,String(r),`read`)}),i=e=>P?e.filter(e=>(e?.accessorKey||(0,t.columnIdentity)(e))!==P):e,a=e=>e==null||typeof e==`string`&&e.trim()===``||Array.isArray(e)&&e.length===0,s=e=>R.length?e.filter(e=>{let n=e?.accessorKey||(0,t.columnIdentity)(e);return!n||R.some(e=>!a(e?.[n]))}):e,l=(e,t)=>{if(!t?.type)return;let r=(0,o.getCellRenderer)((0,o.resolveCellRendererType)({type:t.type,format:t.format})||t.type);if(!r)return;let i=t.type===`lookup`||t.type===`master_detail`?be[e]:void 0,a=i&&Object.keys(i).length>0?Object.entries(i).map(([e,t])=>({value:e,label:t})):void 0,s={name:e,label:t.label||e,type:t.type,...(a||t.options)&&{options:a||t.options},...t.currency&&{currency:t.currency},...t.precision!==void 0&&{precision:t.precision},...t.scale!==void 0&&{scale:t.scale},...t.format&&{format:t.format},...(t.reference_to||t.reference)&&{reference_to:t.reference_to||t.reference},...t.reference_field&&{reference_field:t.reference_field}};return e=>e==null?n.createElement(`span`,{className:`text-muted-foreground/50 text-xs italic`},`—`):n.createElement(r,{value:e,field:s})},u=n=>{if(typeof n!=`string`){let e=n?.accessorKey||(0,t.columnIdentity)(n);if(n&&!n.cell&&!n.render&&e){let t=Y?.fields?.[e],r=t?l(String(e),t):void 0;if(r)return{...n,cell:r}}return n}let r=Y?.fields?.[n],i={accessorKey:n,header:r?.label||Se(e,n,r)||n,fieldDef:r,fieldType:r?.type},a=r?l(n,r):void 0;return a&&(i.cell=a),i};if(p&&p.length>0)return s(r(i(p.map(u))));if(!Y?.fields)return[];let d=Array.isArray(Y.highlightFields)?Y.highlightFields.filter(e=>typeof e==`string`&&e.length>0):[];if(d.length>0){let e=s(r(i(d.map(u))));if(e.length>0)return e.slice(0,Math.max(1,O))}let f=e,m=new Set([`rich_text`,`html`,`json`]),h=[`name`,`full_name`,`fullname`,`title`,`subject`,`label`,`code`,`number`],_=Object.entries(Y.fields).filter(([e,t])=>!(e.startsWith(`_`)||e===`id`||e===P||t?.hidden||t?.type&&m.has(t.type)||Ue?.isLoaded&&f&&!Ue.checkField(f,e,`read`))),v=new Set([`created_at`,`updated_at`,`created_by`,`updated_by`,`owner_id`,`organization_id`]);return _.sort(([e,t],[n,r])=>{let i=v.has(e);if(i!==v.has(n))return i?1:-1;let a=h.indexOf(e),o=h.indexOf(n),s=a>=0?a:100,c=o>=0?o:100;if(s!==c)return s-c;let l=t?.type===`select`||e.includes(`status`);return l===(r?.type===`select`||n.includes(`status`))?0:l?-1:1}),s(_.map(([e,t])=>{let n={accessorKey:e,header:Se(f,e,t.label||e)};if(t.type){let r=l(e,t);r&&(n.cell=r)}return n})).slice(0,Math.max(1,O))},[p,Y,g,c,Se,P,R,O,be,Ue]),Ge=n.useMemo(()=>$?We.map(e=>{let n=e.accessorKey||(0,t.columnIdentity)(e);return n&&(0,t.isExpandableFieldType)(Y?.fields?.[n])?{...e,sortable:!1}:e}):We,[We,$,Y]),Ke=!f&&(s===`grid`||s===`table`),qe=Array.isArray(S)&&S.length>0,Je=!!y||!!b||qe,Ye=(0,r.useIsMobile)(),Xe=n.useMemo(()=>{if(f)return f;if(Ye&&(s===`grid`||s===`table`)){let e=We[0]?.accessorKey||(0,t.columnIdentity)(We[0]),n=We.slice(1,4).map(e=>e.accessorKey||(0,t.columnIdentity)(e)).filter(Boolean);return{type:`object-gallery`,data:je,objectName:c,gallery:{titleField:e||`name`,visibleFields:n,cardSize:`medium`},onRowClick:x}}let e=(0,t.userActionPredicates)(Y?.userActions?.edit),n=(0,t.userActionPredicates)(Y?.userActions?.delete);switch(s){case`grid`:case`table`:return{type:`data-table`,data:je,columns:Ge,pagination:!1,pageSize:Q||10,searchable:!1,exportable:!1,manualSorting:!0,sort:Ie,onSortChange:Le,rowActions:Je,onRowEdit:y,onRowDelete:b?Be:void 0,rowEditPredicates:e,rowDeletePredicates:n,onRowClick:x,rowActionDefs:qe?S:void 0,onRowActionDef:qe?C:void 0};case`list`:return{type:`data-list`,data:je};default:return{type:`div`,children:`No view configured`}}},[s,je,Ge,We,f,Q,Je,qe,S,C,y,b,Be,x,Ye,c,Y,Ie,Le]),Ze=N?`cursor-pointer select-none`:void 0,Qe=N?()=>fe(e=>!e):void 0,$e=ne(te),et=$&&J!=null?J:R.length,tt=!B&&R.length===0&&(!$||H===0),nt=M;return(0,l.jsxs)(r.Card,{className:(0,r.cn)(`shadow-none border-border/60 bg-transparent`,tt&&`bg-muted/10`,m),children:[(0,l.jsx)(r.CardHeader,{className:(0,r.cn)(`py-3 px-4 sm:py-3 min-h-12 sm:min-h-0`,Ze),onClick:Qe,children:(0,l.jsxs)(r.CardTitle,{className:`flex items-center justify-between gap-2 text-sm font-semibold`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[N&&(de?(0,l.jsx)(i.ChevronRight,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}):(0,l.jsx)(i.ChevronDown,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`})),(0,l.jsx)($e,{className:`h-4 w-4 text-muted-foreground shrink-0`,"aria-hidden":!0}),(0,l.jsx)(`span`,{className:(0,r.cn)(`truncate`,tt&&`text-muted-foreground font-medium`),children:e}),(0,l.jsx)(r.Badge,{variant:`secondary`,className:(0,r.cn)(`text-xs font-normal h-5 px-1.5`,et===0&&`bg-muted text-muted-foreground`),"aria-label":`${et} records`,children:et}),tt&&(0,l.jsx)(`span`,{className:`text-xs text-muted-foreground/70 italic ml-1 truncate`,children:Z(`detail.noRelatedRecords`)})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[T&&(w??[]).map(e=>(0,l.jsx)(ie,{action:e,onToolbarAction:T},e.name)),E&&(0,l.jsxs)(r.Button,{variant:tt?`ghost`:`outline`,size:`sm`,disabled:me,onClick:e=>{e.stopPropagation(),_e(null),pe(!0)},className:`gap-1 h-9 sm:h-7 text-xs shadow-none`,children:[(0,l.jsx)(i.Plus,{className:`h-3.5 w-3.5`}),E.label||Z(`detail.add`,{defaultValue:`Add`})]}),_&&(0,l.jsxs)(r.Button,{variant:tt?`ghost`:`outline`,size:`sm`,onClick:e=>{e.stopPropagation(),_()},className:`gap-1 h-9 sm:h-7 text-xs shadow-none`,children:[(0,l.jsx)(i.Plus,{className:`h-3.5 w-3.5`}),Z(`detail.new`)]})]})]})}),!de&&!tt&&(0,l.jsxs)(r.CardContent,{className:(0,r.cn)(`pt-0 pb-4 px-4`),children:[nt&&(0,l.jsx)(`div`,{className:`mb-3`,children:(0,l.jsx)(r.Input,{placeholder:Z(`detail.filterPlaceholder`),value:q,onChange:e=>oe(e.target.value),className:`h-8 text-sm`})}),j&&!Ke&&We&&We.length>0&&R.length>0&&(0,l.jsx)(`div`,{className:`flex flex-wrap gap-1 mb-3`,children:We.map(e=>{let n=e.accessorKey||(0,t.columnIdentity)(e);if(!n||$&&(0,t.isExpandableFieldType)(Y?.fields?.[n]))return null;let a=e.header||e.label||n,o=W===n;return(0,l.jsxs)(r.Button,{variant:o?`secondary`:`ghost`,size:`sm`,className:`gap-1 h-7 text-xs`,onClick:()=>Fe(n),children:[(0,l.jsx)(i.ArrowUpDown,{className:`h-3 w-3`}),a,o&&(K===`asc`?` ↑`:` ↓`)]},n)})}),B&&R.length===0?(0,l.jsx)(`div`,{className:`flex items-center justify-center py-6 text-muted-foreground text-sm`,children:Z(`detail.loading`)}):(0,l.jsx)(`div`,{className:(0,r.cn)(B&&`opacity-60 pointer-events-none transition-opacity`),children:(0,l.jsx)(a.SchemaRenderer,{schema:Xe})}),Pe&&(0,l.jsxs)(`div`,{className:`flex items-center justify-between mt-3 pt-3 border-t`,children:[(0,l.jsxs)(r.Button,{variant:`outline`,size:`sm`,className:`h-7 text-xs gap-1`,disabled:H===0,onClick:()=>U(e=>Math.max(0,e-1)),children:[(0,l.jsx)(i.ChevronLeft,{className:`h-3 w-3`}),Z(`detail.previousPage`)]}),(0,l.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:Z(`detail.pageOf`,{current:H+1,total:Me})}),(0,l.jsxs)(r.Button,{variant:`outline`,size:`sm`,className:`h-7 text-xs gap-1`,disabled:!Ne,onClick:()=>U(e=>Ne?e+1:e),children:[Z(`detail.nextPage`),(0,l.jsx)(i.ChevronRight,{className:`h-3 w-3`})]})]}),v&&!tt&&Pe&&(0,l.jsx)(`div`,{className:`mt-3 pt-3 border-t flex justify-center`,children:(0,l.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),v()},className:`text-xs text-muted-foreground hover:text-foreground inline-flex items-center gap-1 transition-colors`,children:[Z(`detail.viewAll`),(0,l.jsx)(i.ExternalLink,{className:`h-3 w-3`})]})})]}),(0,l.jsx)(r.AlertDialog,{open:Re!==null,onOpenChange:e=>{e||ze(null)},children:(0,l.jsxs)(r.AlertDialogContent,{children:[(0,l.jsxs)(r.AlertDialogHeader,{children:[(0,l.jsx)(r.AlertDialogTitle,{children:Z(`detail.deleteRowTitle`,{defaultValue:`Delete record`})}),(0,l.jsx)(r.AlertDialogDescription,{children:Z(`detail.deleteRowConfirmation`)})]}),(0,l.jsxs)(r.AlertDialogFooter,{children:[(0,l.jsx)(r.AlertDialogCancel,{children:Z(`detail.cancel`,{defaultValue:`Cancel`})}),(0,l.jsx)(r.AlertDialogAction,{onClick:Ve,className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:Z(`detail.delete`,{defaultValue:`Delete`})})]})]})}),ge&&(0,l.jsx)(`div`,{className:`mx-4 mb-3 rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,role:`alert`,children:ge}),E&&h&&(0,l.jsx)(o.RecordPickerDialog,{open:X,onOpenChange:e=>pe(e),multiple:!0,dataSource:h,objectName:E.picker.object,title:E.label||Z(`detail.add`,{defaultValue:`Add`}),onSelect:()=>{},onSelectRecords:e=>{He(e)}})]})},B=({group:e,data:t,className:a,objectSchema:o,objectName:s,isEditing:c=!1,onFieldChange:u,onEnterInlineEdit:d,autoFocusField:f,dataSource:p})=>{let m=e.collapsible??!0,[h,g]=n.useState(e.defaultCollapsed??!1),_=(0,l.jsx)(`div`,{className:`space-y-3 sm:space-y-4`,children:e.sections.map((e,n)=>(0,l.jsx)(L,{section:e,data:t,objectSchema:o,objectName:s,isEditing:c,onFieldChange:u,onEnterInlineEdit:d,autoFocusField:f,dataSource:p},n))});return m?(0,l.jsxs)(r.Collapsible,{open:!h,onOpenChange:e=>g(!e),className:a,children:[(0,l.jsx)(r.CollapsibleTrigger,{asChild:!0,children:(0,l.jsxs)(`div`,{className:`flex items-center gap-2 pb-2 border-b cursor-pointer hover:bg-muted/50 transition-colors rounded-t-md px-2 py-1.5`,children:[h?(0,l.jsx)(i.ChevronRight,{className:`h-4 w-4 text-muted-foreground shrink-0`}):(0,l.jsx)(i.ChevronDown,{className:`h-4 w-4 text-muted-foreground shrink-0`}),e.icon&&(0,l.jsx)(`span`,{className:`text-muted-foreground`,children:e.icon}),(0,l.jsx)(`h3`,{className:`text-lg font-semibold`,children:e.title})]})}),e.description&&!h&&(0,l.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:e.description}),(0,l.jsx)(r.CollapsibleContent,{children:(0,l.jsx)(`div`,{className:`mt-3`,children:_})})]}):(0,l.jsxs)(`div`,{className:(0,r.cn)(`space-y-3`,a),children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2 pb-2 border-b`,children:[e.icon&&(0,l.jsx)(`span`,{className:`text-muted-foreground`,children:e.icon}),(0,l.jsx)(`h3`,{className:`text-lg font-semibold`,children:e.title})]}),e.description&&(0,l.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e.description}),_]})},V=({fields:e,data:t,className:n,objectName:s,objectSchema:c,dataSource:u})=>{let{fieldLabel:d}=(0,a.useSafeFieldLabel)(),{t:f}=D(),p=(0,a.useInlineEdit)(),m=p?.editing??!1,h=p?.canEdit??!1;if(!e.length||!t)return null;let g=m?e:e.filter(e=>{let n=t?.[e.name];return n!=null&&n!==``});return g.length===0?null:(0,l.jsx)(r.TooltipProvider,{children:(0,l.jsx)(`section`,{className:(0,r.cn)(`@container border-b border-border/60 pb-4`,n),"aria-label":`Record highlights`,children:(0,l.jsx)(`div`,{className:(0,r.cn)(`flex flex-wrap gap-y-4`),children:g.map(e=>{let n=t[e.name],a=c?.fields?.[e.name],g=e.type||a?.type,_=F({name:e.name,label:e.label,type:g||`text`},a),v=p?.draft?.[e.name],y=v===void 0?n:v,b=M.has(g),x=e.readonly===!0||a?.readonly===!0,S=j.has(e.name),C=h&&!b&&!x&&!S,w=m&&C,T=(0,o.getCellRenderer)((0,o.resolveCellRendererType)(_)||g||`text`),E=g===`number`||g===`integer`||g===`currency`||g===`percent`||g===`decimal`,D=g===`email`||g===`url`||g===`textarea`||g===`reference`||g===`lookup`||g===`master_detail`,O=g===`boolean`,k=y==null||y===``;return(0,l.jsxs)(`div`,{className:(0,r.cn)(`group flex flex-col gap-1 min-w-[7rem] px-5 border-l border-border/60 first:border-l-0 first:pl-0`,D||w?`basis-[16rem] max-w-[24rem]`:`basis-[9rem] max-w-[16rem]`),children:[(0,l.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:d(s||``,e.name,e.label)}),w?(0,l.jsx)(ee,{field:_,value:y,onChange:t=>p.setField(e.name,t),dataSource:u,autoFocus:p.autoFocusField===e.name}):(0,l.jsxs)(`div`,{className:(0,r.cn)(`flex items-start justify-between gap-1`,C&&`cursor-pointer rounded-md -mx-1.5 px-1.5 hover:bg-muted/40 transition-colors`),onDoubleClick:C?()=>p.enter(e.name):void 0,title:C?f(`detail.editInlineHint`):void 0,children:[(0,l.jsx)(`div`,{className:`min-w-0 flex-1`,children:O?y?(0,l.jsxs)(`span`,{className:`inline-flex items-center gap-1 self-start rounded-full bg-emerald-500/10 px-2 py-0.5 text-xs font-medium text-emerald-600 ring-1 ring-inset ring-emerald-500/30 dark:text-emerald-400`,children:[(0,l.jsx)(i.Check,{className:`h-3 w-3`,"aria-hidden":!0}),`Yes`]}):(0,l.jsxs)(`span`,{className:`inline-flex items-center gap-1 self-start rounded-full bg-amber-500/10 px-2 py-0.5 text-xs font-medium text-amber-700 ring-1 ring-inset ring-amber-500/30 dark:text-amber-400`,children:[(0,l.jsx)(i.X,{className:`h-3 w-3`,"aria-hidden":!0}),`No`]}):k?(0,l.jsx)(`span`,{className:`block text-sm text-muted-foreground/60 select-none`,"aria-label":f(`detail.noValue`,{defaultValue:`No value`}),children:`—`}):(0,l.jsx)(`span`,{title:(Array.isArray(_.options)?_.options.find(e=>e?.value===y)?.label:void 0)??(typeof y==`string`||typeof y==`number`?String(y):void 0),className:(0,r.cn)(`block min-w-0 truncate text-sm font-semibold`,E&&`tabular-nums tracking-tight`),children:(0,l.jsx)(T,{value:y,field:_})})}),C&&(0,l.jsxs)(r.Tooltip,{children:[(0,l.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,l.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-5 w-5 shrink-0 opacity-0 group-hover:opacity-100 transition-opacity`,"aria-label":f(`detail.editInlineHint`),onClick:t=>{t.stopPropagation(),p.enter(e.name)},children:(0,l.jsx)(i.Pencil,{className:`h-3 w-3`})})}),(0,l.jsx)(r.TooltipContent,{children:f(`detail.editInlineHint`)})]})]})]},e.name)})})})})};function H(e){try{let t=new Date(e),n=new Date().getTime()-t.getTime(),r=Math.floor(n/6e4);if(r<1)return`just now`;if(r<60)return`${r}m ago`;let i=Math.floor(r/60);if(i<24)return`${i}h ago`;let a=Math.floor(i/24);return a<7?`${a}d ago`:t.toLocaleDateString()}catch{return e}}var U=({comments:e,onAddComment:t,onTogglePin:a,searchable:o=!1,className:s})=>{let{t:c}=D(),[u,d]=n.useState(``),[f,p]=n.useState(!1),[m,h]=n.useState(``),g=n.useCallback(async()=>{let e=u.trim();if(!(!e||!t)){p(!0);try{await t(e),d(``)}finally{p(!1)}}},[u,t]),_=n.useCallback(e=>{e.key===`Enter`&&(e.ctrlKey||e.metaKey)&&(e.preventDefault(),g())},[g]),v=n.useMemo(()=>[...m.trim()?e.filter(e=>{let t=m.trim().toLowerCase();return e.text.toLowerCase().includes(t)||e.author.toLowerCase().includes(t)}):e].sort((e,t)=>e.pinned&&!t.pinned?-1:!e.pinned&&t.pinned?1:0),[e,m]);return(0,l.jsxs)(r.Card,{className:(0,r.cn)(``,s),children:[(0,l.jsx)(r.CardHeader,{children:(0,l.jsxs)(r.CardTitle,{className:`flex items-center gap-2 text-base`,children:[(0,l.jsx)(i.MessageSquare,{className:`h-4 w-4`}),c(`detail.comments`),(0,l.jsxs)(`span`,{className:`text-sm font-normal text-muted-foreground`,children:[`(`,e.length,`)`]})]})}),(0,l.jsxs)(r.CardContent,{className:`space-y-4`,children:[o&&(0,l.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,l.jsxs)(`div`,{className:`relative flex-1`,children:[(0,l.jsx)(i.Search,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,l.jsx)(`input`,{className:`w-full rounded-md border border-input bg-background pl-8 pr-8 py-1.5 text-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`,placeholder:c(`detail.searchComments`),value:m,onChange:e=>h(e.target.value),"aria-label":c(`detail.searchComments`)}),m&&(0,l.jsx)(`button`,{className:`absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground`,onClick:()=>h(``),"aria-label":c(`detail.clearSearch`),type:`button`,children:(0,l.jsx)(i.X,{className:`h-3.5 w-3.5`})})]})}),t&&(0,l.jsxs)(`div`,{className:`flex gap-2`,children:[(0,l.jsx)(`textarea`,{className:`flex-1 min-h-[60px] rounded-md border border-input bg-background px-3 py-2 text-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring resize-none`,placeholder:c(`detail.addCommentPlaceholder`),value:u,onChange:e=>d(e.target.value),onKeyDown:_,disabled:f}),(0,l.jsx)(r.Button,{size:`icon`,variant:`default`,onClick:g,disabled:!u.trim()||f,className:`shrink-0 self-end`,children:(0,l.jsx)(i.Send,{className:`h-4 w-4`})})]}),v.length===0?(0,l.jsx)(`p`,{className:`text-sm text-muted-foreground text-center py-4`,children:m.trim()?c(`detail.noMatchingComments`):c(`detail.noCommentsYet`)}):(0,l.jsx)(`div`,{className:`space-y-3`,children:v.map(e=>(0,l.jsxs)(`div`,{className:(0,r.cn)(`flex gap-3`,e.pinned&&`bg-muted/40 rounded-md p-2 -mx-2`),children:[(0,l.jsx)(`div`,{className:`shrink-0`,children:e.avatarUrl?(0,l.jsx)(`img`,{src:e.avatarUrl,alt:e.author,className:`h-8 w-8 rounded-full object-cover`}):(0,l.jsx)(`div`,{className:`h-8 w-8 rounded-full bg-muted flex items-center justify-center text-xs font-medium text-muted-foreground`,children:e.author.charAt(0).toUpperCase()})}),(0,l.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2 mb-0.5`,children:[(0,l.jsx)(`span`,{className:`text-sm font-medium truncate`,children:e.author}),(0,l.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:H(e.createdAt)}),e.pinned&&(0,l.jsxs)(`span`,{className:`text-xs text-amber-600 flex items-center gap-0.5`,children:[(0,l.jsx)(i.Pin,{className:`h-3 w-3`}),c(`detail.pinned`)]})]}),(0,l.jsx)(`p`,{className:`text-sm whitespace-pre-wrap break-words`,children:e.text}),a&&(0,l.jsxs)(`button`,{type:`button`,className:`mt-1 text-xs text-muted-foreground hover:text-foreground flex items-center gap-1`,onClick:()=>a(e.id),"aria-label":e.pinned?c(`detail.unpin`):c(`detail.pin`),children:[(0,l.jsx)(i.Pin,{className:`h-3 w-3`}),e.pinned?c(`detail.unpin`):c(`detail.pin`)]})]})]},e.id))})]})]})},W={field_change:i.Edit,create:i.PlusCircle,delete:i.Trash2,comment:i.MessageSquare,status_change:i.ArrowRightLeft},G={field_change:`bg-blue-100 text-blue-600`,create:`bg-green-100 text-green-600`,delete:`bg-red-100 text-red-600`,comment:`bg-purple-100 text-purple-600`,status_change:`bg-amber-100 text-amber-600`};function K(e){try{let t=new Date(e),n=new Date().getTime()-t.getTime(),r=Math.floor(n/6e4);if(r<1)return`just now`;if(r<60)return`${r}m ago`;let i=Math.floor(r/60);if(i<24)return`${i}h ago`;let a=Math.floor(i/24);return a<7?`${a}d ago`:t.toLocaleDateString()}catch{return e}}function ae(e){return e.description?e.description:e.type===`field_change`&&e.field?`Changed ${e.field.charAt(0).toUpperCase()+e.field.slice(1).replace(/_/g,` `)} from "${e.oldValue==null?`(empty)`:String(e.oldValue)}" to "${e.newValue==null?`(empty)`:String(e.newValue)}"`:e.type===`create`?`Created this record`:e.type===`delete`?`Deleted this record`:e.type===`status_change`&&e.field?`Changed status to "${e.newValue==null?`(empty)`:String(e.newValue)}"`:`Updated record`}var q={all:`All`,field_change:`Field Changes`,create:`Creates`,delete:`Deletes`,comment:`Comments`,status_change:`Status Changes`},oe=({activities:e,filterable:t=!1,defaultFilter:a=`all`,className:o})=>{let[s,c]=n.useState(a),u=n.useMemo(()=>s===`all`?e:e.filter(e=>e.type===s),[e,s]);return(0,l.jsxs)(r.Card,{className:(0,r.cn)(``,o),children:[(0,l.jsx)(r.CardHeader,{children:(0,l.jsxs)(r.CardTitle,{className:`flex items-center gap-2 text-base`,children:[(0,l.jsx)(i.Activity,{className:`h-4 w-4`}),`Activity`,(0,l.jsxs)(`span`,{className:`text-sm font-normal text-muted-foreground`,children:[`(`,u.length,`)`]})]})}),(0,l.jsxs)(r.CardContent,{children:[t&&(0,l.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mb-4`,role:`group`,"aria-label":`Activity type filter`,children:Object.keys(q).map(e=>(0,l.jsxs)(`button`,{type:`button`,className:(0,r.cn)(`inline-flex items-center gap-1 rounded-full px-2.5 py-0.5 text-xs font-medium transition-colors`,s===e?`bg-primary text-primary-foreground`:`bg-muted text-muted-foreground hover:bg-muted/80`),onClick:()=>c(e),"aria-pressed":s===e,children:[e!==`all`&&n.createElement(W[e]||i.Edit,{className:`h-3 w-3`}),q[e]]},e))}),u.length===0?(0,l.jsx)(r.DataEmptyState,{title:`No activity recorded`,className:`py-6`}):(0,l.jsxs)(`div`,{className:`relative`,children:[(0,l.jsx)(`div`,{className:`absolute left-4 top-2 bottom-2 w-px bg-border`}),(0,l.jsx)(`div`,{className:`space-y-4`,children:u.map(e=>{let t=W[e.type]||i.Edit;return(0,l.jsxs)(`div`,{className:`flex gap-3 relative`,children:[(0,l.jsx)(`div`,{className:(0,r.cn)(`shrink-0 h-8 w-8 rounded-full flex items-center justify-center z-10`,G[e.type]||`bg-gray-100 text-gray-600`),children:(0,l.jsx)(t,{className:`h-3.5 w-3.5`})}),(0,l.jsxs)(`div`,{className:`flex-1 min-w-0 pt-1`,children:[(0,l.jsxs)(`p`,{className:`text-sm`,children:[(0,l.jsx)(`span`,{className:`font-medium`,children:e.user}),` `,(0,l.jsx)(`span`,{className:`text-muted-foreground`,children:ae(e)})]}),(0,l.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:K(e.timestamp)})]})]},e.id)})})]})]})]})},J={create:`default`,update:`secondary`,delete:`destructive`,restore:`outline`,login:`outline`,logout:`outline`,permission_change:`secondary`,config_change:`secondary`,export:`outline`,import:`outline`};function se(e){if(!e)return``;let t=e instanceof Date?e:new Date(e);return Number.isNaN(t.getTime())?String(e):t.toLocaleString()}var ce=[[60,`second`],[60,`minute`],[24,`hour`],[7,`day`],[4.34524,`week`],[12,`month`],[1/0,`year`]];function le(e,t){if(!e)return``;let n=e instanceof Date?e:new Date(e);if(Number.isNaN(n.getTime()))return String(e);let r=(n.getTime()-Date.now())/1e3;for(let[n,i]of ce){if(Math.abs(r)<n)try{return new Intl.RelativeTimeFormat(t,{numeric:`auto`}).format(Math.round(r),i)}catch{return se(e)}r/=n}return se(e)}function Y(e){if(!e)return`?`;let t=e.trim().split(/\s+/).filter(Boolean).slice(0,2);return t.length===0?`?`:t.map(e=>e.charAt(0).toUpperCase()).join(``)}function ue(e){if(e==null||e===``)return`—`;if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`boolean`)return String(e);try{return JSON.stringify(e)}catch{return String(e)}}function de({entries:e,loading:t,emptyText:n,unknownUserText:i,className:a,locale:o}){return t?(0,l.jsx)(`div`,{className:(0,r.cn)(`space-y-3`,a),children:Array.from({length:4}).map((e,t)=>(0,l.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,l.jsx)(r.Skeleton,{className:`h-8 w-8 rounded-full`}),(0,l.jsxs)(`div`,{className:`flex-1 space-y-2`,children:[(0,l.jsx)(r.Skeleton,{className:`h-4 w-1/3`}),(0,l.jsx)(r.Skeleton,{className:`h-3 w-1/2`})]})]},t))}):!e||e.length===0?(0,l.jsx)(`div`,{className:(0,r.cn)(`flex items-center justify-center rounded-md border border-dashed py-10 text-sm text-muted-foreground`,a),children:n??`No history yet`}):(0,l.jsx)(r.TooltipProvider,{delayDuration:150,children:(0,l.jsx)(`ol`,{className:(0,r.cn)(`space-y-4`,a),children:e.map((e,t)=>{let n=(e.action??``).toLowerCase(),a=J[n]??`outline`,s=typeof e.user_name==`string`&&e.user_name.trim()||i||`Unknown user`,c=se(e.created_at),u=le(e.created_at,o),d=typeof e.user_avatar==`string`?e.user_avatar:void 0;return(0,l.jsxs)(`li`,{className:`flex items-start gap-3`,children:[(0,l.jsxs)(r.Avatar,{className:`h-8 w-8 mt-0.5 shrink-0`,children:[d?(0,l.jsx)(r.AvatarImage,{src:d,alt:s}):null,(0,l.jsx)(r.AvatarFallback,{className:`text-[10px] font-medium`,children:Y(e.user_name)})]}),(0,l.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,l.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2 gap-y-1`,children:[(0,l.jsx)(`span`,{className:`text-sm font-medium text-foreground`,children:s}),e.action&&(0,l.jsx)(r.Badge,{variant:a,className:`text-[10px] uppercase tracking-wide`,children:e.action}),c&&(0,l.jsxs)(r.Tooltip,{children:[(0,l.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,l.jsx)(`span`,{className:`text-xs text-muted-foreground cursor-help`,"aria-label":c,children:u||c})}),(0,l.jsx)(r.TooltipContent,{children:c})]})]}),e.summary&&(0,l.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:e.summary}),e.changes&&e.changes.length>0&&(n===`create`?(0,l.jsxs)(`details`,{className:`mt-1 group`,children:[(0,l.jsxs)(`summary`,{className:`cursor-pointer list-none text-xs text-muted-foreground hover:text-foreground inline-flex items-center gap-1 select-none`,children:[(0,l.jsx)(`span`,{className:`transition-transform group-open:rotate-90`,children:`▸`}),(0,l.jsx)(`span`,{children:e.changes.length===1?`1 field populated`:`${e.changes.length} fields populated`})]}),(0,l.jsx)(`ul`,{className:`mt-1.5 space-y-0.5 text-xs text-muted-foreground pl-4`,children:e.changes.map(e=>(0,l.jsxs)(`li`,{className:`leading-relaxed`,children:[(0,l.jsx)(`span`,{className:`font-medium text-foreground`,children:e.label||e.field}),`: `,(0,l.jsx)(`span`,{className:`text-foreground`,children:ue(e.to)})]},e.field))})]}):(0,l.jsx)(`ul`,{className:`mt-1.5 space-y-0.5 text-xs text-muted-foreground`,children:e.changes.map(e=>(0,l.jsxs)(`li`,{className:`leading-relaxed`,children:[(0,l.jsx)(`span`,{className:`font-medium text-foreground`,children:e.label||e.field}),`: `,(0,l.jsx)(`span`,{className:`line-through opacity-70`,children:ue(e.from)}),` → `,(0,l.jsx)(`span`,{className:`text-foreground`,children:ue(e.to)})]},e.field))}))]})]},e.id??t)})})})}var fe=d.AUDIT_FIELD_BY_ROLE;function X(e){if(!e)return null;if(e instanceof Date)return isNaN(e.getTime())?null:e;if(typeof e==`string`||typeof e==`number`){let t=new Date(e);return isNaN(t.getTime())?null:t}return null}function pe(e,t){let n=Date.now()-e.getTime(),r=Math.max(0,Math.floor(n/1e3));if(r<60)return t(`detail.justNow`);let i=Math.floor(r/60);if(i<60)return t(`detail.minutesAgo`,{count:i});let a=Math.floor(i/60);return a<24?t(`detail.hoursAgo`,{count:a}):t(`detail.daysAgo`,{count:Math.floor(a/24)})}function me(e){try{return new Intl.DateTimeFormat(void 0,{dateStyle:`medium`,timeStyle:`short`}).format(e)}catch{return e.toISOString()}}var he=({value:e,objectSchema:t,fieldName:r})=>{if(e==null||e===``)return null;let i=t?.fields?.[r],a=i?.reference_to||i?.reference||`sys_user`,s={name:r,type:i?.type||`lookup`,reference_to:a,...i?.reference_field&&{reference_field:i.reference_field}},c=(0,o.resolveCellRendererType)(s)||s.type;if(c){let t=(0,o.getCellRenderer)(c);if(t)return(0,l.jsx)(`span`,{className:`inline-flex items-center [&_a]:text-inherit [&_a]:hover:underline`,children:n.createElement(t,{value:e,field:s})})}return(0,l.jsx)(`span`,{children:String(e)})},ge=({label:e,user:t,date:n,objectSchema:i,userField:a,t:o})=>{if(!t&&!n)return null;let s=n?(0,l.jsx)(r.TooltipProvider,{delayDuration:200,children:(0,l.jsxs)(r.Tooltip,{children:[(0,l.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,l.jsx)(`time`,{dateTime:n.toISOString(),className:`cursor-default underline decoration-dotted decoration-muted-foreground/40 underline-offset-2`,children:pe(n,o)})}),(0,l.jsx)(r.TooltipContent,{side:`top`,children:me(n)})]})}):null;return(0,l.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,l.jsx)(`span`,{className:`text-muted-foreground/70`,children:e}),t?(0,l.jsx)(he,{value:t,objectSchema:i,fieldName:a}):null,t&&s?(0,l.jsx)(`span`,{className:`text-muted-foreground/40`,children:`·`}):null,s]})},_e=({data:e,objectSchema:t,objectName:n,className:i})=>{let{t:a}=D();if(!e)return null;let o=X(e[fe.createdAt]),s=X(e[fe.updatedAt]),c=e[fe.createdBy],u=e[fe.updatedBy],d=!!(o||c),f=o&&s&&Math.abs(s.getTime()-o.getTime())<2e3,p=!!(s||u)&&!(f&&(c!=null&&u!=null&&String(c)===String(u)||!u));return!d&&!p?null:(0,l.jsxs)(`div`,{className:(0,r.cn)(`mt-6 pt-3 border-t border-border/40`,`flex flex-wrap items-center gap-x-4 gap-y-1`,`text-xs text-muted-foreground`,i),"data-testid":`record-meta-footer`,children:[d&&(0,l.jsx)(ge,{label:a(c?`detail.createdBy`:`detail.created`),user:c,date:o,objectSchema:t,userField:fe.createdBy,t:a}),p&&(0,l.jsx)(ge,{label:a(u?`detail.updatedBy`:`detail.updated`),user:u,date:s,objectSchema:t,userField:fe.updatedBy,t:a})]})},ve=new Map;function ye(e,t,r=`update`,i=!0){let o=e&&t?`${e}:${t}:${r}`:``,[s,c]=n.useState(()=>o&&ve.has(o)?ve.get(o):!0),l=n.useContext(a.SchemaRendererContext)?.apiFetch;return n.useEffect(()=>{if(!i||!o){c(!0);return}if(ve.has(o)){c(ve.get(o));return}let n=!1;return(async()=>{try{let i=await(l??fetch)(`/api/v1/security/explain`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`include`,body:JSON.stringify({object:e,operation:r,recordId:t})});if(!i.ok)return;let a=(await i.json())?.record?.visible;if(typeof a!=`boolean`)return;ve.set(o,a),n||c(a)}catch{}})(),()=>{n=!0}},[o,e,t,r,i,l]),s}function be(){ve.clear()}var xe=5,Z={};function Se(e,n,r,i){if(e&&typeof e==`object`){if(n.primaryField){let t=e[n.primaryField];if(t!=null&&t!==``)return String(t)}let i=(0,t.formatTitleTemplate)(r?.titleFormat,e);if(i)return i}if(e&&typeof e==`object`){let n=e.id??e._id,i=(0,t.getRecordDisplayName)(r,e,{deriveFromRecordKeys:!1});if(!(i===`Untitled`||n!=null&&i===`Record #${n}`))return i}if(n.title)return n.title;if(e&&typeof e==`object`){let n=e.id??e._id,i=(0,t.getRecordDisplayName)(r,e);if(!(i===`Untitled`||n!=null&&i===`Record #${n}`))return i}if(e&&typeof e==`object`){let t=e.id??e._id;if(t!=null&&String(t).trim()!==``)return`Record #${t}`}return i}var Q=({schema:e,dataSource:o,className:c,onEdit:d,onDelete:f,onBack:p,inlineEdit:m=!1,discussionSlot:h,rightRail:g,objectLabel:_,onDataLoaded:v,isFavorite:y,onToggleFavorite:b})=>{let[x,S]=n.useState(e.data),[C,w]=n.useState(!e.data&&!!(e.api&&e.resourceId||o&&e.objectName&&e.resourceId)),[T,E]=n.useState(!1),O=y??T,k=(0,a.useInlineEdit)(),A=k?.editing??!1,j=k?.draft??Z,M=k?.autoFocusField??null,[N,ee]=n.useState(null),[P,F]=n.useState(null),[te,I]=n.useState(!1),[ne,re]=n.useState(0),ie=(0,a.useDataInvalidation)(e.objectName||void 0,e.resourceId==null?void 0:String(e.resourceId)),[H,W]=n.useState(!1),{t:G}=D(),{currency:K}=(0,s.useLocalization)(),{fieldOptionLabel:ae}=(0,a.useSafeFieldLabel)(),q=(0,r.useIsMobile)(),J=(0,u.usePermissions)(),se=n.useMemo(()=>{if(!J?.isLoaded||!e.objectName)return e;let t=t=>J.checkField(e.objectName,t,`read`),n=e=>e&&e.filter(e=>{let n=typeof e==`string`?e:e?.name;return!n||t(n)});return{...e,fields:n(e.fields),sections:e.sections?.map(e=>({...e,fields:n(e.fields)})),summaryFields:n(e.summaryFields)}},[e,J]),ce=n.useMemo(()=>!J?.isLoaded||!e.objectName||J.can(e.objectName,`update`),[J,e.objectName]),le=n.useMemo(()=>!J?.isLoaded||!e.objectName||J.can(e.objectName,`delete`),[J,e.objectName]),Y=e.resourceId==null?void 0:String(e.resourceId),ue=ye(e.objectName,Y,`update`,ce),fe=ye(e.objectName,Y,`delete`,le),X=n.useMemo(()=>({...se,showEdit:se.showEdit&&ce&&ue,showDelete:se.showDelete&&le&&fe}),[se,ce,ue,le,fe]);n.useEffect(()=>{x&&v&&v(x)},[x,v]);let pe=n.useMemo(()=>{if(X.summaryFields&&X.summaryFields.length>0)return[];let e=[...X.sections?.flatMap(e=>e.fields)||[],...X.fields||[]],t={};for(let n of e)t[n.name]||(t[n.name]=n);if(P?.fields)for(let[e,n]of Object.entries(P.fields))t[e]={...t[e]||{},...n,name:e};let n=e=>x?.[e]!==void 0&&x?.[e]!==null&&x?.[e]!==``,r=[],i=[`status`,`stage`,`state`,`phase`].find(e=>t[e]&&n(e))||Object.keys(t).find(e=>t[e]?.type===`select`&&n(e));i&&r.push(i);let a=Object.keys(t).find(e=>(t[e]?.type===`currency`||/amount|revenue|value|total|price/i.test(e))&&n(e));a&&!r.includes(a)&&r.push(a);let o=Object.keys(t).find(e=>(t[e]?.type===`date`||t[e]?.type===`datetime`)&&/close|due|start|end|expected/i.test(e)&&n(e));return o&&!r.includes(o)&&r.push(o),r},[X.summaryFields,X.sections,X.fields,P,x]),me=X.summaryFields&&X.summaryFields.length>0?X.summaryFields:pe,he=n.useCallback(()=>{X.resourceId&&navigator.clipboard.writeText(String(X.resourceId)).then(()=>{I(!0),setTimeout(()=>I(!1),1500)})},[X.resourceId]);n.useEffect(()=>{let e=!0;if(X.data)return S(X.data),w(!1),o?.getObjectSchema&&X.objectName&&o.getObjectSchema(X.objectName).then(t=>{e&&F(t)}).catch(()=>{}),()=>{e=!1};if(o&&X.objectName&&X.resourceId){w(!0),F(null),S(null);let n=X.objectName,r=X.resourceId,i=`${n}-`,a=[...X.sections?.flatMap(e=>e.fields)||[],...X.fields||[]];(o.getObjectSchema?o.getObjectSchema(n).catch(()=>null):Promise.resolve(null)).then(s=>{if(!e)return;F(s);let c=(0,t.buildExpandFields)(s?.fields,a),l=c.length>0?{$expand:c}:void 0,u=l?o.findOne(n,r,l):o.findOne(n,r),d=()=>{let t=String(r),a=t.startsWith(i)?t.slice(i.length):`${i}${t}`;return(l?o.findOne(n,a,l):o.findOne(n,a)).then(t=>{e&&(S(t),w(!1))}).catch(()=>{e&&(S(null),w(!1))})};return u.catch(()=>null).then(t=>{if(e){if(t){S(t),w(!1);return}return d()}})}).catch(t=>{e&&(console.error(`Failed to fetch detail data:`,t),w(!1))})}else X.api&&X.resourceId&&(w(!0),fetch(`${X.api}/${X.resourceId}`).then(e=>e.json()).then(t=>{e&&S(t?.data||t)}).catch(e=>{console.error(`Failed to fetch detail data:`,e)}).finally(()=>{e&&w(!1)}));return()=>{e=!1}},[X.api,X.resourceId,X.objectName,o,X.sections,X.fields,ne,ie]);let ge=n.useCallback(()=>{if(p)p();else if(X.onNavigate){let e=X.backUrl||(X.objectName?`/${X.objectName}`:`/`);X.onNavigate(e,{replace:!0})}else X.backUrl?window.location.href=X.backUrl:window.history.back()},[p,X]),ve=n.useCallback(()=>{d?d():X.onNavigate&&X.editUrl?X.onNavigate(X.editUrl):X.onNavigate&&X.objectName&&X.resourceId?X.onNavigate(`/${X.objectName}/${X.resourceId}/edit`):X.editUrl&&(window.location.href=X.editUrl)},[d,X]),be=n.useCallback(async()=>{if(!o?.cancelPendingApproval||!X.objectName||!X.resourceId){ee(G(`detail.cancelApprovalUnavailable`));return}W(!0),ee(null);try{if(await o.cancelPendingApproval(String(X.objectName),String(X.resourceId)),o.findOne)try{let e=await o.findOne(String(X.objectName),String(X.resourceId));e&&S(e)}catch{}re(e=>e+1);try{window.dispatchEvent(new CustomEvent(`objectui:record-changed`,{detail:{objectName:String(X.objectName),recordId:String(X.resourceId),reason:`approval-recalled`}}))}catch{}}catch(e){let t=(e?.message||e?.error||String(e??`Cancel failed`)).replace(/^\[[^\]]+\]\s*/,``).replace(/^[A-Z][A-Z0-9_]+:\s*/,``);ee(`${G(`detail.cancelApprovalFailed`)}: ${t}`)}finally{W(!1)}},[o,X.objectName,X.resourceId,G]),Q=n.useCallback(()=>{let e=X.deleteConfirmation||G(`detail.deleteConfirmation`);window.confirm(e)&&(f?.(),X.onNavigate&&X.objectName&&X.onNavigate(`/${X.objectName}`,{replace:!0}))},[f,X]),Ce=n.useCallback(()=>{navigator.share&&X.objectName&&X.resourceId?navigator.share({title:X.title||G(`detail.details`),text:`${X.objectName} #${X.resourceId}`,url:window.location.href}).catch(e=>console.log(`Share failed:`,e)):navigator.clipboard.writeText(window.location.href).then(()=>{console.log(`Link copied to clipboard`)})},[X]),$=n.useCallback(()=>{let e=!O;b&&b(e),y===void 0&&E(e)},[O,y,b]),we=k?.setField,Te=k&&k.canEdit?k.enter:void 0;n.useEffect(()=>{if(!X.recordNavigation)return;let e=X.recordNavigation,t=t=>{let n=t.target?.tagName;n===`INPUT`||n===`TEXTAREA`||t.target?.isContentEditable||(t.key===`ArrowLeft`&&e.currentIndex>0?(t.preventDefault(),e.onNavigate(e.recordIds[e.currentIndex-1])):t.key===`ArrowRight`&&e.currentIndex<e.recordIds.length-1&&(t.preventDefault(),e.onNavigate(e.recordIds[e.currentIndex+1])))};return document.addEventListener(`keydown`,t),()=>document.removeEventListener(`keydown`,t)},[X.recordNavigation]);let Ee=n.useMemo(()=>X.related??[],[X.related]),De=n.useMemo(()=>{let e=[];return e.push({name:`sys_share`,label:G(`detail.share`),icon:`share-2`,type:`script`,onClick:Ce}),X.showEdit&&e.push({name:`sys_edit_mobile`,label:G(`detail.edit`),icon:`edit`,type:`script`,className:`sm:hidden`,onClick:ve}),X.showDelete&&e.push({name:`sys_delete`,label:G(`detail.delete`),icon:`trash-2`,type:`script`,variant:`destructive`,tags:[`separator-before`],onClick:Q}),e},[G,X.showEdit,X.showDelete,Ce,ve,Q]),Oe=n.useMemo(()=>{let e=X.actions??[];if(De.length===0)return e;let t=!1,n=e.map(e=>{let n=e;if(n&&typeof n==`object`&&n.type===`action:bar`&&(!n.location||n.location===`record_header`)){t=!0;let e=Array.isArray(n.systemActions)?n.systemActions:[];return{...n,systemActions:[...e,...De]}}return e});return t||n.push({type:`action:bar`,location:`record_header`,systemActions:De}),n},[X.actions,De]);return C||X.loading?(0,l.jsxs)(`div`,{className:(0,r.cn)(`space-y-4`,c),children:[(0,l.jsx)(r.Skeleton,{className:`h-10 w-full`}),(0,l.jsx)(r.Skeleton,{className:`h-64 w-full`}),(0,l.jsx)(r.Skeleton,{className:`h-48 w-full`})]}):!x&&!X.data?(0,l.jsxs)(`div`,{className:(0,r.cn)(`flex flex-col items-center justify-center py-16 text-center`,c),children:[(0,l.jsx)(`p`,{className:`text-lg font-semibold`,children:G(`detail.recordNotFound`)}),(0,l.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:G(`detail.recordNotFoundDescription`)}),(X.showBack??!0)&&(0,l.jsxs)(r.Button,{variant:`outline`,size:`sm`,onClick:ge,className:`mt-4 gap-2`,children:[(0,l.jsx)(i.ArrowLeft,{className:`h-4 w-4`}),G(`detail.goBack`)]})]}):(0,l.jsx)(r.TooltipProvider,{children:(0,l.jsxs)(`div`,{className:(0,r.cn)(`space-y-6`,c),children:[X.showHeader!==!1&&(0,l.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start justify-between gap-3 sm:gap-4 pb-4 border-b`,children:[(0,l.jsxs)(`div`,{className:`flex items-start gap-2 sm:gap-3 flex-1 min-w-0`,children:[(X.showBack??!0)&&(0,l.jsxs)(r.Tooltip,{children:[(0,l.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,l.jsx)(r.Button,{variant:`ghost`,size:`icon`,onClick:ge,className:`shrink-0 mt-1`,children:(0,l.jsx)(i.ArrowLeft,{className:`h-4 w-4`})})}),(0,l.jsx)(r.TooltipContent,{children:G(`detail.back`)})]}),(0,l.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,l.jsx)(`h1`,{className:`text-xl sm:text-2xl font-bold truncate`,children:Se(x,X,P,G(`detail.details`))}),me.map(e=>{let t=x?.[e];if(t==null||t===``)return null;let n=(X.sections||[]).flatMap(e=>e.fields).concat(X.fields||[]).find(t=>t.name===e),i=P?.fields?.[e],a=n?.type||i?.type,o=String(t),c=null;try{if(a===`currency`){let e=Number(t);if(!Number.isNaN(e)){let t=(0,s.resolveFieldCurrency)({...i,...n},K);o=t?new Intl.NumberFormat(void 0,{style:`currency`,currency:t,maximumFractionDigits:0}).format(e):new Intl.NumberFormat(void 0,{maximumFractionDigits:0}).format(e)}}else if(a===`date`||a===`datetime`){let e=new Date(t);Number.isNaN(e.getTime())||(o=a===`datetime`?e.toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`}):e.toLocaleDateString(void 0,{dateStyle:`medium`}))}else if(a===`percent`){let e=Number(t);if(!Number.isNaN(e)){o=`${e}%`;let t=e<=1?e*100:e;c=Math.max(0,Math.min(100,t))}}else if(a===`select`||a===`status`||a===`multiselect`){let r=n?.options||i?.options,a=String(t);if(Array.isArray(r)){let e=r.find(e=>String(e?.value??e)===String(t));e?.label&&(a=e.label)}else if(r&&typeof r==`object`){let e=r[String(t)];e?.label&&(a=e.label)}o=X.objectName?ae(X.objectName,e,String(t),a):a}}catch{}return c===null?(0,l.jsx)(r.Badge,{variant:`secondary`,className:`text-xs bg-primary/10 text-primary border-transparent hover:bg-primary/15`,"aria-label":`${e}: ${o}`,children:o},e):(0,l.jsxs)(r.Badge,{variant:`secondary`,className:`text-xs bg-primary/10 text-primary border-transparent hover:bg-primary/15 gap-1.5 pl-2 pr-2`,"aria-label":`${e}: ${o}`,children:[(0,l.jsx)(`span`,{className:`relative inline-block h-1.5 w-12 rounded-full bg-primary/20 overflow-hidden`,"aria-hidden":!0,children:(0,l.jsx)(`span`,{className:`absolute inset-y-0 left-0 rounded-full bg-primary`,style:{width:`${c}%`}})}),o]},e)}),(0,l.jsxs)(r.Tooltip,{children:[(0,l.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,l.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-6 w-6 shrink-0`,onClick:$,"aria-label":G(O?`detail.removeFromFavorites`:`detail.addToFavorites`),children:O?(0,l.jsx)(i.Star,{className:`h-4 w-4 fill-yellow-400 text-yellow-400`}):(0,l.jsx)(i.Star,{className:`h-4 w-4 text-muted-foreground`})})}),(0,l.jsx)(r.TooltipContent,{children:G(O?`detail.removeFromFavorites`:`detail.addToFavorites`)})]})]}),X.objectName&&(0,l.jsxs)(`p`,{className:`text-sm text-muted-foreground mt-1 flex items-center gap-1`,children:[(0,l.jsx)(`span`,{className:`font-medium`,children:_||X.objectName}),X.resourceId&&(0,l.jsxs)(r.Tooltip,{children:[(0,l.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,l.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-5 w-5 shrink-0 text-muted-foreground/60 hover:text-foreground`,onClick:he,"aria-label":G(`detail.copyRecordId`,{defaultValue:`Copy record ID`}),children:te?(0,l.jsx)(i.Check,{className:`h-3 w-3 text-green-600`}):(0,l.jsx)(i.Copy,{className:`h-3 w-3`})})}),(0,l.jsx)(r.TooltipContent,{children:te?G(`detail.copied`,{defaultValue:`Copied`}):G(`detail.copyRecordId`,{defaultValue:`Copy record ID`})})]})]})]})]}),(0,l.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 shrink-0 w-full sm:w-auto`,children:[X.recordNavigation&&(0,l.jsxs)(`div`,{className:`flex items-center gap-1 mr-2`,children:[(0,l.jsxs)(r.Tooltip,{children:[(0,l.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,l.jsx)(r.Button,{variant:`outline`,size:`icon`,className:`h-8 w-8`,disabled:X.recordNavigation.currentIndex<=0,onClick:()=>{let e=X.recordNavigation;e.currentIndex>0&&e.onNavigate(e.recordIds[e.currentIndex-1])},children:(0,l.jsx)(i.ChevronLeft,{className:`h-4 w-4`})})}),(0,l.jsx)(r.TooltipContent,{children:G(`detail.previousRecord`)})]}),(0,l.jsx)(`span`,{className:`text-xs text-muted-foreground whitespace-nowrap px-1`,children:G(`detail.recordOf`,{current:X.recordNavigation.currentIndex+1,total:X.recordNavigation.recordIds.length})}),(0,l.jsxs)(r.Tooltip,{children:[(0,l.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,l.jsx)(r.Button,{variant:`outline`,size:`icon`,className:`h-8 w-8`,disabled:X.recordNavigation.currentIndex>=X.recordNavigation.recordIds.length-1,onClick:()=>{let e=X.recordNavigation;e.currentIndex<e.recordIds.length-1&&e.onNavigate(e.recordIds[e.currentIndex+1])},children:(0,l.jsx)(i.ChevronRight,{className:`h-4 w-4`})})}),(0,l.jsx)(r.TooltipContent,{children:G(`detail.nextRecord`)})]})]}),X.showEdit&&(0,l.jsxs)(r.Tooltip,{children:[(0,l.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,l.jsxs)(r.Button,{variant:`default`,onClick:ve,className:`gap-2 hidden sm:inline-flex`,children:[(0,l.jsx)(i.Edit,{className:`h-4 w-4`}),(0,l.jsx)(`span`,{className:`hidden sm:inline`,children:G(`detail.edit`)})]})}),(0,l.jsx)(r.TooltipContent,{children:G(`detail.editRecord`)})]}),Oe.map((e,t)=>(0,l.jsx)(a.SchemaRenderer,{schema:e,data:x},`header-action-${t}`))]})]}),X.header&&(0,l.jsx)(`div`,{children:(0,l.jsx)(a.SchemaRenderer,{schema:X.header,data:x})}),X.highlightFields&&X.highlightFields.length>0&&(0,l.jsx)(V,{fields:X.highlightFields,data:x,objectName:X.objectName,objectSchema:P}),m&&X.showHeader===!1&&(()=>{let e=x?.approval_status,t=e===`pending`||e===`in_approval`,n=k?.approvalPending??!1,a=n&&!(k?.locked??!1)?!1:(k?.locked??!1)||t,s=a||n||t;return!s&&!N?null:(0,l.jsxs)(`div`,{className:`flex flex-col items-end gap-1`,children:[s&&(0,l.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[(0,l.jsxs)(`span`,{role:`status`,className:a?`inline-flex items-center gap-1 rounded-md border border-amber-300 bg-amber-50 px-2 py-1 text-xs text-amber-800`:`inline-flex items-center gap-1 rounded-md border border-sky-300 bg-sky-50 px-2 py-1 text-xs text-sky-800`,title:a?k?.lockedReason??G(`detail.lockedTooltip`):G(`detail.approvalPendingTooltip`),children:[a?(0,l.jsx)(i.Lock,{className:`h-3 w-3`}):(0,l.jsx)(i.Clock,{className:`h-3 w-3`}),(0,l.jsx)(`span`,{children:G(a?`detail.lockedByApproval`:`detail.approvalPendingEditable`)})]}),o?.cancelPendingApproval&&(0,l.jsxs)(r.Button,{variant:`outline`,size:`sm`,onClick:be,disabled:H,className:a?`gap-2 border-amber-300 text-amber-800 hover:bg-amber-50`:`gap-2 border-sky-300 text-sky-800 hover:bg-sky-50`,title:G(a?`detail.cancelApprovalTooltip`:`detail.cancelApprovalTooltipUnlocked`),children:[(0,l.jsx)(i.X,{className:`h-4 w-4`}),(0,l.jsx)(`span`,{children:G(H?`detail.cancelApprovalInFlight`:`detail.cancelApproval`)})]})]}),N&&(0,l.jsx)(`div`,{role:`alert`,className:`text-xs text-destructive bg-destructive/10 border border-destructive/20 rounded-md px-2 py-1 max-w-md text-right`,children:N})]})})(),X.autoTabs&&!X.tabs?.length?(()=>{let e=Ee.length>0,t=!!X.activities&&X.activities.length>0,n=!!h,i=!!X.history,a=[`details`,...e?[`related`]:[],...t?[`activity`]:[],...n?[`discussion`]:[],...i?[`history`]:[]],s=X.defaultTab,c=s&&a.includes(s)?s:`details`,u=X.onTabChange,d=(0,l.jsxs)(`div`,{className:`space-y-3 sm:space-y-4`,children:[X.sectionGroups&&X.sectionGroups.length>0&&X.sectionGroups.map((e,t)=>(0,l.jsx)(B,{group:e,data:{...x,...j},objectSchema:P,objectName:X.objectName,isEditing:A,onFieldChange:we,onEnterInlineEdit:m?Te:void 0,autoFocusField:M,dataSource:o},t)),X.sections&&X.sections.length>0&&X.sections.map((e,t)=>(0,l.jsx)(L,{section:e,data:{...x,...j},objectSchema:P,objectName:X.objectName,isEditing:A,onFieldChange:we,onEnterInlineEdit:m?Te:void 0,autoFocusField:M,dataSource:o},t)),X.fields&&X.fields.length>0&&!X.sections?.length&&(0,l.jsx)(L,{section:{fields:X.fields,columns:X.columns},data:{...x,...j},objectSchema:P,objectName:X.objectName,isEditing:A,onFieldChange:we,onEnterInlineEdit:m?Te:void 0,autoFocusField:M,dataSource:o}),X.comments&&(0,l.jsx)(U,{comments:X.comments,onAddComment:X.onAddComment})]});return!e&&!t&&!n&&!i?(0,l.jsx)(`div`,{className:`mt-2`,children:d}):(0,l.jsxs)(r.Tabs,{defaultValue:c,onValueChange:u,className:`w-full`,children:[(0,l.jsxs)(r.TabsList,{className:`w-full justify-start border-b rounded-none bg-transparent p-0`,children:[(0,l.jsx)(r.TabsTrigger,{value:`details`,className:`relative rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent`,children:G(`detail.details`)}),e&&(0,l.jsx)(r.TabsTrigger,{value:`related`,className:`relative rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent`,children:(0,l.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[G(`detail.related`),(0,l.jsx)(r.Badge,{variant:`secondary`,className:`text-xs bg-primary/10 text-primary border-transparent`,children:Ee.length})]})}),t&&(0,l.jsx)(r.TabsTrigger,{value:`activity`,className:`relative rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent`,children:(0,l.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[G(`detail.activity`),(0,l.jsx)(r.Badge,{variant:`secondary`,className:`text-xs bg-primary/10 text-primary border-transparent`,children:X.activities.length})]})}),n&&(0,l.jsx)(r.TabsTrigger,{value:`discussion`,className:`relative rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent`,children:G(`detail.discussion`,{defaultValue:`Discussion`})}),i&&(0,l.jsx)(r.TabsTrigger,{value:`history`,className:`relative rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent`,children:(0,l.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[G(`detail.history`,{defaultValue:`History`}),!X.history.loading&&X.history.entries.length>0&&(0,l.jsx)(r.Badge,{variant:`secondary`,className:`text-xs bg-primary/10 text-primary border-transparent`,children:X.history.entries.length})]})})]}),(0,l.jsx)(r.TabsContent,{value:`details`,className:`mt-4 motion-safe:data-[state=active]:animate-in motion-safe:data-[state=active]:fade-in-0 motion-safe:duration-150`,children:d}),e&&(0,l.jsx)(r.TabsContent,{value:`related`,className:`mt-4 motion-safe:data-[state=active]:animate-in motion-safe:data-[state=active]:fade-in-0 motion-safe:duration-150`,children:(0,l.jsx)(`div`,{className:`space-y-3`,children:Ee.map((e,t)=>(0,l.jsx)(z,{title:e.title,type:e.type,api:e.api,data:e.data,columns:e.columns,dataSource:o,objectName:e.api,referenceField:e.referenceField,icon:e.icon,onNew:e.onNew,onViewAll:e.onViewAll,onRowClick:e.onRowClick,onRowEdit:e.onRowEdit,onRowDelete:e.onRowDelete,collapsible:!0,defaultCollapsed:q&&t>0,pageSize:xe},t))})}),t&&(0,l.jsx)(r.TabsContent,{value:`activity`,className:`mt-4 motion-safe:data-[state=active]:animate-in motion-safe:data-[state=active]:fade-in-0 motion-safe:duration-150`,children:(0,l.jsx)(oe,{activities:X.activities})}),n&&(0,l.jsx)(r.TabsContent,{value:`discussion`,className:`mt-4 motion-safe:data-[state=active]:animate-in motion-safe:data-[state=active]:fade-in-0 motion-safe:duration-150`,children:h}),i&&(0,l.jsx)(r.TabsContent,{value:`history`,className:`mt-4 motion-safe:data-[state=active]:animate-in motion-safe:data-[state=active]:fade-in-0 motion-safe:duration-150`,children:(0,l.jsx)(de,{entries:X.history.entries,loading:X.history.loading,emptyText:X.history.emptyText??G(`detail.historyEmpty`,{defaultValue:`No history yet`})})})]})})():(0,l.jsxs)(l.Fragment,{children:[X.sectionGroups&&X.sectionGroups.length>0&&(0,l.jsx)(`div`,{className:`space-y-3 sm:space-y-4`,children:X.sectionGroups.map((e,t)=>(0,l.jsx)(B,{group:e,data:{...x,...j},objectSchema:P,objectName:X.objectName,isEditing:A,onFieldChange:we,onEnterInlineEdit:m?Te:void 0,autoFocusField:M,dataSource:o},t))}),X.sections&&X.sections.length>0&&(0,l.jsx)(`div`,{className:`space-y-3 sm:space-y-4`,children:X.sections.map((e,t)=>(0,l.jsx)(L,{section:e,data:{...x,...j},objectSchema:P,objectName:X.objectName,isEditing:A,onFieldChange:we,onEnterInlineEdit:m?Te:void 0,autoFocusField:M,dataSource:o},t))}),X.fields&&X.fields.length>0&&!X.sections?.length&&(0,l.jsx)(L,{section:{fields:X.fields,columns:X.columns},data:{...x,...j},objectSchema:P,objectName:X.objectName,isEditing:A,onFieldChange:we,onEnterInlineEdit:m?Te:void 0,autoFocusField:M,dataSource:o}),X.tabs&&X.tabs.length>0&&(0,l.jsx)(R,{tabs:X.tabs,data:x}),Ee.length>0&&(0,l.jsxs)(`div`,{className:`space-y-3`,children:[(0,l.jsx)(`h2`,{className:`text-lg font-semibold`,children:G(`detail.related`)}),Ee.map((e,t)=>(0,l.jsx)(z,{title:e.title,type:e.type,api:e.api,data:e.data,columns:e.columns,dataSource:o,objectName:e.api,referenceField:e.referenceField,icon:e.icon,onNew:e.onNew,onViewAll:e.onViewAll,onRowClick:e.onRowClick,onRowEdit:e.onRowEdit,onRowDelete:e.onRowDelete,collapsible:!0,defaultCollapsed:q&&t>0,pageSize:xe},t))]}),X.comments&&(0,l.jsx)(U,{comments:X.comments,onAddComment:X.onAddComment}),X.activities&&X.activities.length>0&&(0,l.jsx)(oe,{activities:X.activities})]}),(0,l.jsx)(_e,{data:{...x,...j},objectSchema:P,objectName:X.objectName}),X.footer&&(0,l.jsx)(`div`,{children:(0,l.jsx)(a.SchemaRenderer,{schema:X.footer,data:x})})]})})},Ce=e=>(0,t.columnIdentity)(e)??null,$=e=>{let{"data-obj-id":t,"data-obj-type":n,style:r,...i}=e||{};return{designer:{"data-obj-id":t,"data-obj-type":n,style:r},rest:i}},we=({schema:e={},className:n,...r})=>{let i=(0,a.useRecordContext)(),{designer:o}=$(r),c=i?.objectName||``,d=(0,u.usePermissions)(),{readableFields:f}=(0,u.useFieldPermissions)(c),{sectionLabel:p}=(0,a.useSafeFieldLabel)(),{language:m}=(0,s.useObjectTranslation)(),h=(0,a.useHighlightFieldNames)();if(!i)return(0,l.jsx)(`div`,{className:n,"data-record-details-placeholder":!0,...o,children:(0,l.jsx)(`div`,{className:`text-xs text-muted-foreground italic px-3 py-2 border border-dashed rounded`,children:`record:details — bind a record to preview`})});let g=Array.isArray(e.requiredPermissions)?e.requiredPermissions:[];if(g.length>0&&c&&!g.every(e=>d.can(c,e)))return(0,l.jsx)(`div`,{className:n,...o,role:`status`,"aria-live":`polite`,children:(0,l.jsx)(`p`,{className:`text-sm text-muted-foreground italic`,children:`Insufficient permissions to view details.`})});let _=e.layout===`inline`||e.layout===`compact`?`horizontal`:`vertical`,v=e.enforceFieldSecurity===!0,y=Array.isArray(e.redactFields)?e.redactFields:[],b=e=>{if(!e||!v&&y.length===0)return e;let t=e.map(Ce).filter(e=>!!e),n=new Set((v&&c?f(t):t).filter(e=>!y.includes(e)));return e.filter(e=>{let t=Ce(e);return!t||n.has(t)})},x=e=>typeof e==`string`?{name:e}:e&&typeof e==`object`&&!e.name&&e.field?{...e,name:e.field}:e,S=e=>Array.isArray(e)?e.map(x):e,C=new Set((Array.isArray(e.hideFields)?e.hideFields:[]).map(e=>typeof e==`string`?e:Ce(e)).filter(e=>!!e));for(let e of h)C.add(e);let w=i.objectSchema,T=i.data??{},E=[w?.primaryField,`name`,`full_name`,`title`,`subject`,`display_name`,`label`].filter(e=>typeof e==`string`&&e.length>0);for(let e of E)if(T[e]!==void 0&&T[e]!==null&&T[e]!==``){C.add(e);break}let D=e=>!e||C.size===0?e:e.filter(e=>{let t=Ce(e);return!t||!C.has(t)}),O=D(S(b(e.fields))),k=Array.isArray(e.sections)?e.sections.map(e=>{let t=e.title??e.label,n=t==null?void 0:(0,s.pickLocalized)(t,m),r=e.name&&c?p(c,e.name,n??e.name):n;return{...e,title:r,showBorder:e.showBorder??!!r,hideEmpty:e.hideEmpty??!0,fields:D(S(b(e.fields)))}}):e.sections,A=(0,t.isObjectInlineEditable)(w,d?.getObjectApiOperations?.(c)),j=(e.inlineEdit??!0)&&A,M={type:`detail-view`,objectName:i.objectName,resourceId:i.recordId,data:i.data,layout:_,columns:e.columns,sections:k,fields:O,showBack:!1,showHeader:e.showHeader??!1,inlineEdit:j};return(0,l.jsx)(`div`,{className:n,...o,children:(0,l.jsx)(Q,{schema:M,dataSource:i.dataSource,inlineEdit:j})})},Te=e=>(0,t.columnIdentity)(e)||(e&&typeof e==`object`?e.key:null)||null,Ee=e=>e?.id??e?._id??null,De=5,Oe=e=>{let{"data-obj-id":t,"data-obj-type":n,style:r,...i}=e||{};return{designer:{"data-obj-id":t,"data-obj-type":n,style:r},rest:i}},ke=({schema:e={},className:t,...r})=>{let i=(0,a.useRecordContext)(),{designer:c}=Oe(r),d=(0,a.useSafeFieldLabel)(),{language:f}=(0,s.useObjectTranslation)(),p=e.objectName,m=p&&d.objectLabel?d.objectLabel({name:p,label:(0,o.humanizeLabel)(p)}):p?(0,o.humanizeLabel)(p):``,h=(0,s.pickLocalized)(e.title,f)||m||`Related`,g=(0,u.usePermissions)(),{readableFields:_}=(0,u.useFieldPermissions)(p||``),v=e.relationshipValueField||`id`,y=v===`id`?i?.recordId??null:i?.data?.[v]??null,b=(0,a.useRelatedRecordActions)(),x=n.default.useMemo(()=>b?.resolve({objectName:p,relationshipField:e.relationshipField,parentId:y})??null,[b,p,e.relationshipField,y]);if(!p)return(0,l.jsx)(`div`,{className:t,...c,children:(0,l.jsx)(`div`,{className:`text-xs text-muted-foreground italic px-3 py-2 border border-dashed rounded`,children:`record:related_list — missing objectName`})});if(g.isLoaded&&!g.can(p,`read`))return null;let S=Array.isArray(e.requiredPermissions)?e.requiredPermissions:[];if(S.length>0&&!S.every(e=>g.can(p,e)))return(0,l.jsx)(`div`,{className:t,...c,role:`status`,"aria-live":`polite`,children:(0,l.jsx)(`p`,{className:`text-sm text-muted-foreground italic`,children:`Insufficient permissions to view related list.`})});let C=e.enforceFieldSecurity===!0,w=Array.isArray(e.redactFields)?e.redactFields:[],T=Array.isArray(e.columns)?e.columns:[],E=T;if(C||w.length>0){let e=T.map(Te).filter(e=>!!e),t=new Set((C?_(e):e).filter(e=>!w.includes(e)));E=T.filter(e=>{let n=Te(e);return!n||t.has(n)})}return(0,l.jsx)(`div`,{className:t,...c,children:(0,l.jsx)(z,{title:h,type:`table`,api:p,objectName:p,referenceField:e.relationshipField,parentId:y,columns:E,pageSize:typeof e.limit==`number`&&e.limit>0?e.limit:De,defaultSort:e.sort,dataSource:i?.dataSource,add:e.add?{...e.add,label:(0,s.pickLocalized)(e.add.label,f)||void 0}:void 0,rowActions:x?.rowActions,onRowAction:x?.onRowAction,toolbarActions:x?.toolbarActions,onToolbarAction:x?.onToolbarAction,onNew:x?.onCreate,onRowClick:x?.onView?e=>{let t=Ee(e);t!=null&&x.onView(t,e)}:void 0,onRowEdit:x?.onEdit?e=>{let t=Ee(e);t!=null&&x.onEdit(t,e)}:void 0,onRowDelete:x?.onDelete?e=>{let t=Ee(e);if(t!=null)return x.onDelete(t,e)}:e.add&&i?.dataSource?async e=>{let t=e?.id??e?._id;t!=null&&await i.dataSource.delete?.(p,String(t))}:void 0})})},Ae=e=>{let{"data-obj-id":t,"data-obj-type":n,style:r,...i}=e||{};return{designer:{"data-obj-id":t,"data-obj-type":n,style:r},rest:i}},je=({schema:e={},className:t,...r})=>{let i=(0,a.useRecordContext)(),{designer:o}=Ae(r),s=i?.objectName||``,c=(0,u.usePermissions)(),{readableFields:d}=(0,u.useFieldPermissions)(s),f=Array.isArray(e.requiredPermissions)?e.requiredPermissions:[],p=!(f.length>0&&s)||f.every(e=>c.can(s,e)),m=(Array.isArray(e.fields)?e.fields:[]).map(e=>typeof e==`string`?{name:e}:{name:e?.name,label:e?.label,icon:e?.icon,type:e?.type}).filter(e=>typeof e.name==`string`&&e.name.length>0),h=e.enforceFieldSecurity===!0,g=Array.isArray(e.redactFields)?e.redactFields:[],_=h&&s?new Set(d(m.map(e=>e.name))):null,v=m.filter(e=>!(g.includes(e.name)||_&&!_.has(e.name)));return(0,a.useRegisterHighlightFields)(n.default.useId(),p?v.map(e=>e.name):[]),p?(0,l.jsx)(`div`,{className:t,...o,children:(0,l.jsx)(V,{fields:v,data:i?.data,objectName:i?.objectName,objectSchema:i?.objectSchema,dataSource:i?.dataSource})}):(0,l.jsx)(`div`,{className:t,...o,role:`status`,"aria-live":`polite`,children:(0,l.jsx)(`p`,{className:`text-sm text-muted-foreground italic`,children:`Insufficient permissions to view highlights.`})})},Me=({change:e,className:t})=>{let n=e.fieldLabel??e.field.charAt(0).toUpperCase()+e.field.slice(1).replace(/_/g,` `),a=e.oldDisplayValue??(e.oldValue==null?`(empty)`:String(e.oldValue)),o=e.newDisplayValue??(e.newValue==null?`(empty)`:String(e.newValue));return(0,l.jsxs)(`div`,{className:(0,r.cn)(`flex items-center gap-1.5 text-sm flex-wrap`,t),children:[(0,l.jsx)(`span`,{className:`font-medium text-foreground`,children:n}),(0,l.jsx)(`span`,{className:`text-muted-foreground line-through`,children:a}),(0,l.jsx)(i.ArrowRight,{className:`h-3 w-3 text-muted-foreground shrink-0`}),(0,l.jsx)(`span`,{className:`text-foreground`,children:o})]})},Ne=[`👍`,`❤️`,`🎉`,`😂`,`😮`,`😢`],Pe=({reactions:e,onToggleReaction:t,emojiOptions:a=Ne,className:o})=>{let[s,c]=n.useState(!1),u=n.useCallback(e=>{t?.(e),c(!1)},[t]);return(0,l.jsxs)(`div`,{className:(0,r.cn)(`flex items-center gap-1 flex-wrap`,o),children:[e.map(e=>(0,l.jsxs)(`button`,{type:`button`,className:(0,r.cn)(`inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-xs border transition-colors`,e.reacted?`bg-primary/10 border-primary/30 text-primary`:`bg-muted border-border text-muted-foreground hover:bg-muted/80`),onClick:()=>u(e.emoji),disabled:!t,"aria-label":`${e.emoji} ${e.count} reaction${e.count===1?``:`s`}`,children:[(0,l.jsx)(`span`,{children:e.emoji}),(0,l.jsx)(`span`,{children:e.count})]},e.emoji)),t&&(0,l.jsxs)(`div`,{className:`relative`,children:[(0,l.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-6 w-6`,onClick:()=>c(!s),"aria-label":`Add reaction`,children:(0,l.jsx)(i.SmilePlus,{className:`h-3.5 w-3.5`})}),s&&(0,l.jsx)(`div`,{className:`absolute bottom-full mb-1 left-0 bg-popover border rounded-md shadow-md z-50 p-1.5 flex gap-1`,role:`listbox`,"aria-label":`Emoji picker`,children:a.map(t=>(0,l.jsx)(`button`,{type:`button`,className:`hover:bg-accent rounded p-1 text-base transition-colors`,onClick:()=>u(t),role:`option`,"aria-selected":e.some(e=>e.emoji===t&&e.reacted),children:t},t))})]})]})};function Fe(e,t){try{let n=new Date(e),r=new Date().getTime()-n.getTime(),i=Math.floor(r/6e4);if(i<1)return t(`detail.justNow`);if(i<60)return t(`detail.minutesAgo`,{count:i});let a=Math.floor(i/60);if(a<24)return t(`detail.hoursAgo`,{count:a});let o=Math.floor(a/24);return o<7?t(`detail.daysAgo`,{count:o}):n.toLocaleDateString()}catch{return e}}var Ie=({parentItem:e,replies:t,onAddReply:a,showReplyInput:o=!0,className:s})=>{let{t:c}=D(),[u,d]=n.useState(!1),[f,p]=n.useState(``),[m,h]=n.useState(!1),g=n.useCallback(async()=>{let t=f.trim();if(!(!t||!a)){h(!0);try{await a(e.id,t),p(``)}finally{h(!1)}}},[f,a,e.id]),_=n.useCallback(e=>{e.key===`Enter`&&(e.ctrlKey||e.metaKey)&&(e.preventDefault(),g())},[g]);return t.length===0&&!o?null:(0,l.jsxs)(`div`,{className:(0,r.cn)(`ml-10 mt-1`,s),children:[t.length>0&&(0,l.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors mb-1`,onClick:()=>d(!u),"aria-expanded":u,children:[u?(0,l.jsx)(i.ChevronDown,{className:`h-3 w-3`}):(0,l.jsx)(i.ChevronRight,{className:`h-3 w-3`}),(0,l.jsx)(i.MessageSquare,{className:`h-3 w-3`}),(0,l.jsx)(`span`,{children:t.length===1?c(`detail.replyCount`,{count:t.length}):c(`detail.replyCountPlural`,{count:t.length})})]}),u&&(0,l.jsx)(`div`,{className:`space-y-2 border-l-2 border-border pl-3`,children:t.map(e=>(0,l.jsxs)(`div`,{className:`flex gap-2`,children:[(0,l.jsx)(`div`,{className:`shrink-0`,children:e.actorAvatarUrl?(0,l.jsx)(`img`,{src:e.actorAvatarUrl,alt:e.actor,className:`h-6 w-6 rounded-full object-cover`}):(0,l.jsx)(`div`,{className:`h-6 w-6 rounded-full bg-muted flex items-center justify-center text-[10px] font-medium text-muted-foreground`,children:e.actor.charAt(0).toUpperCase()})}),(0,l.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,l.jsx)(`span`,{className:`text-xs font-medium`,children:e.actor}),(0,l.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:Fe(e.createdAt,c)})]}),(0,l.jsx)(`p`,{className:`text-xs whitespace-pre-wrap break-words`,children:e.body})]})]},e.id))}),o&&a&&(0,l.jsxs)(`div`,{className:`flex gap-1.5 mt-1.5`,children:[(0,l.jsx)(`input`,{className:`flex-1 rounded-md border border-input bg-background px-2 py-1 text-xs placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`,placeholder:c(`detail.replyPlaceholder`),value:f,onChange:e=>p(e.target.value),onKeyDown:_,disabled:m}),(0,l.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-6 w-6 shrink-0`,onClick:g,disabled:!f.trim()||m,"aria-label":`Send reply`,children:(0,l.jsx)(i.Send,{className:`h-3 w-3`})})]})]})},Le=({subscription:e,onToggle:t,className:a})=>{let{t:o}=D(),[s,c]=n.useState(!1),u=n.useCallback(async()=>{if(t){c(!0);try{await t(!e.subscribed)}finally{c(!1)}}},[t,e.subscribed]);return(0,l.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:(0,r.cn)(`h-8 w-8`,a),onClick:u,disabled:s||!t,"aria-label":e.subscribed?o(`detail.unsubscribeAriaLabel`):o(`detail.subscribeAriaLabel`),title:e.subscribed?o(`detail.subscribedTooltip`):o(`detail.unsubscribedTooltip`),children:e.subscribed?(0,l.jsx)(i.Bell,{className:`h-4 w-4 text-primary`}):(0,l.jsx)(i.BellOff,{className:`h-4 w-4 text-muted-foreground`})})};function Re(e){let t=e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/```([\s\S]*?)```/g,`<pre class="bg-muted rounded p-2 text-xs font-mono my-1 overflow-x-auto">$1</pre>`).replace(/`([^`]+)`/g,`<code class="bg-muted rounded px-1 py-0.5 text-xs font-mono">$1</code>`).replace(/\*\*(.+?)\*\*/g,`<strong>$1</strong>`).replace(/\*(.+?)\*/g,`<em>$1</em>`).replace(/@(\w+)/g,`<span class="text-primary font-medium">@$1</span>`).replace(/^- (.+)$/gm,`<li class="ml-4 list-disc">$1</li>`).replace(/\n/g,`<br/>`);return t=t.replace(/(<li[^>]*>.*?<\/li>(?:<br\/>)?)+/g,e=>`<ul class="my-1">${e.replace(/<br\/>/g,``)}</ul>`),t}var ze=({value:e,onChange:t,onSubmit:a,mentionSuggestions:o=[],placeholder:s,className:c,disabled:u=!1,extraSlot:d,canSubmitEmpty:f=!1})=>{let{t:p}=D(),[m,h]=n.useState(!1),[g,_]=n.useState(!1),[v,y]=n.useState(``),[b,x]=n.useState(0),S=n.useRef(null),C=n.useMemo(()=>{if(!v)return o;let e=v.toLowerCase();return o.filter(t=>t.label.toLowerCase().includes(e))},[v,o]),w=n.useCallback((n,r=``)=>{let i=S.current;if(!i)return;let a=i.selectionStart,o=i.selectionEnd,s=e.slice(a,o);t(e.slice(0,a)+n+s+r+e.slice(o)),requestAnimationFrame(()=>{i.focus();let e=a+n.length+s.length;i.setSelectionRange(e,e)})},[e,t]),T=n.useCallback(()=>w(`**`,`**`),[w]),E=n.useCallback(()=>w(`*`,`*`),[w]),O=n.useCallback(()=>w(`
2
- - `,``),[w]),k=n.useCallback(()=>w("`","`"),[w]),A=n.useCallback(()=>{w(`@`,``),_(!0),y(``),x(0)},[w]),j=n.useCallback(n=>{let r=S.current;if(!r)return;let i=r.selectionStart,a=e.slice(0,i).lastIndexOf(`@`);a!==-1&&t(e.slice(0,a)+`@${n.label} `+e.slice(i)),_(!1),y(``),requestAnimationFrame(()=>r.focus())},[e,t]),M=n.useCallback(e=>{let n=e.target.value;t(n);let r=e.target.selectionStart,i=n.slice(0,r),a=i.lastIndexOf(`@`);if(a!==-1){let e=i.slice(a+1),t=a>0?i[a-1]:` `;if(/\s/.test(t)&&!/\s/.test(e)){_(!0),y(e),x(0);return}}_(!1)},[t]),N=n.useCallback(e=>{if(g&&C.length>0){if(e.key===`ArrowDown`){e.preventDefault(),x(e=>e<C.length-1?e+1:0);return}if(e.key===`ArrowUp`){e.preventDefault(),x(e=>e>0?e-1:C.length-1);return}if(e.key===`Enter`||e.key===`Tab`){e.preventDefault(),j(C[b]);return}if(e.key===`Escape`){_(!1);return}}e.key===`Enter`&&(e.ctrlKey||e.metaKey)&&(e.preventDefault(),a?.())},[g,C,b,j,a]);return(0,l.jsxs)(`div`,{className:(0,r.cn)(`border rounded-md`,c),children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-0.5 px-2 py-1.5 border-b bg-muted/30`,children:[(0,l.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:T,disabled:u||m,title:p(`detail.bold`),children:(0,l.jsx)(i.Bold,{className:`h-3.5 w-3.5`})}),(0,l.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:E,disabled:u||m,title:p(`detail.italic`),children:(0,l.jsx)(i.Italic,{className:`h-3.5 w-3.5`})}),(0,l.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:O,disabled:u||m,title:p(`detail.listFormat`),children:(0,l.jsx)(i.List,{className:`h-3.5 w-3.5`})}),(0,l.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:k,disabled:u||m,title:p(`detail.inlineCode`),children:(0,l.jsx)(i.Code,{className:`h-3.5 w-3.5`})}),(0,l.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:A,disabled:u||m,title:p(`detail.mentionSomeone`),children:(0,l.jsx)(i.AtSign,{className:`h-3.5 w-3.5`})}),(0,l.jsx)(`div`,{className:`flex-1`}),(0,l.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:()=>h(!m),title:p(m?`detail.edit`:`detail.preview`),children:m?(0,l.jsx)(i.Edit,{className:`h-3.5 w-3.5`}):(0,l.jsx)(i.Eye,{className:`h-3.5 w-3.5`})}),a&&(0,l.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:a,disabled:u||!f&&!e.trim(),title:p(`detail.submitComment`),children:(0,l.jsx)(i.Send,{className:`h-3.5 w-3.5`})})]}),(0,l.jsx)(`div`,{className:`relative`,children:m?(0,l.jsx)(`div`,{className:`min-h-[80px] px-3 py-2 text-sm prose prose-sm max-w-none`,dangerouslySetInnerHTML:{__html:Re(e)}}):(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`textarea`,{ref:S,className:`w-full min-h-[80px] px-3 py-2 text-sm bg-transparent resize-none focus:outline-none placeholder:text-muted-foreground`,placeholder:s??p(`detail.writeComment`),value:e,onChange:M,onKeyDown:N,disabled:u}),g&&C.length>0&&(0,l.jsx)(`div`,{className:`absolute left-2 bottom-full mb-1 w-56 bg-popover border rounded-md shadow-md z-50 max-h-40 overflow-y-auto`,children:C.map((e,t)=>(0,l.jsxs)(`button`,{type:`button`,className:(0,r.cn)(`w-full text-left px-3 py-1.5 text-sm flex items-center gap-2 hover:bg-accent transition-colors`,t===b&&`bg-accent`),onMouseDown:t=>{t.preventDefault(),j(e)},children:[e.avatarUrl?(0,l.jsx)(`img`,{src:e.avatarUrl,alt:e.label,className:`h-5 w-5 rounded-full object-cover`}):(0,l.jsx)(`div`,{className:`h-5 w-5 rounded-full bg-muted flex items-center justify-center text-[10px] font-medium`,children:e.label.charAt(0).toUpperCase()}),(0,l.jsx)(`span`,{children:e.label})]},e.id))})]})}),d&&(0,l.jsx)(`div`,{className:`border-t px-2 py-2 bg-muted/20`,children:d})]})};function Be(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function Ve(e){return e.startsWith(`image/`)}function He(e){return Ve(e)?i.Image:e.includes(`pdf`)||e.includes(`document`)||e.includes(`text`)?i.FileText:e.includes(`zip`)||e.includes(`archive`)||e.includes(`compressed`)?i.FileArchive:i.File}var Ue=({attachments:e,onUpload:t,onRemove:a,className:o,readOnly:s=!1})=>{let{t:c}=D(),[u,d]=n.useState(!1),f=n.useRef(null),p=n.useCallback(e=>{e.preventDefault(),e.stopPropagation(),d(!0)},[]),m=n.useCallback(e=>{e.preventDefault(),e.stopPropagation(),d(!1)},[]),h=n.useCallback(e=>{e.preventDefault(),e.stopPropagation(),d(!1),t&&e.dataTransfer.files.length>0&&t(e.dataTransfer.files)},[t]),g=n.useCallback(e=>{t&&e.target.files&&e.target.files.length>0&&(t(e.target.files),e.target.value=``)},[t]);return(0,l.jsxs)(`div`,{className:(0,r.cn)(`space-y-2`,o),children:[t&&!s&&(0,l.jsxs)(`div`,{className:(0,r.cn)(`border-2 border-dashed rounded-md px-4 py-3 text-center transition-colors cursor-pointer`,u?`border-primary bg-primary/5`:`border-muted-foreground/25 hover:border-muted-foreground/40`),onDragOver:p,onDragLeave:m,onDrop:h,onClick:()=>f.current?.click(),role:`button`,tabIndex:0,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),f.current?.click())},children:[(0,l.jsx)(i.Upload,{className:`h-5 w-5 mx-auto text-muted-foreground mb-1`}),(0,l.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:c(`detail.dropFilesToUpload`)}),(0,l.jsx)(`input`,{ref:f,type:`file`,multiple:!0,className:`hidden`,onChange:g})]}),e.length>0&&(0,l.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,l.jsx)(i.Paperclip,{className:`h-3 w-3`}),(0,l.jsx)(`span`,{children:e.length===1?c(`detail.attachmentCount`,{count:e.length}):c(`detail.attachmentCountPlural`,{count:e.length})})]}),(0,l.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2`,children:e.map(e=>{let t=Ve(e.type),n=He(e.type);return(0,l.jsxs)(`div`,{className:`flex items-center gap-2 rounded-md border px-2.5 py-2 bg-muted/30 group`,children:[t&&(e.thumbnailUrl||e.url)?(0,l.jsx)(`img`,{src:e.thumbnailUrl||e.url,alt:e.name,className:`h-10 w-10 rounded object-cover shrink-0`}):(0,l.jsx)(`div`,{className:`h-10 w-10 rounded bg-muted flex items-center justify-center shrink-0`,children:(0,l.jsx)(n,{className:`h-5 w-5 text-muted-foreground`})}),(0,l.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,l.jsx)(`p`,{className:`text-xs font-medium truncate`,children:e.name}),(0,l.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:Be(e.size)})]}),a&&!s&&(0,l.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-6 w-6 shrink-0 opacity-0 group-hover:opacity-100 transition-opacity`,onClick:()=>a(e.id),title:c(`detail.removeAttachment`),children:(0,l.jsx)(i.X,{className:`h-3.5 w-3.5`})})]},e.id)})})]})]})},We={comment:i.MessageSquare,field_change:i.Edit,task:i.CheckSquare,event:i.Calendar,system:i.Zap,email:i.Mail,call:i.Phone,note:i.StickyNote,file:i.FileText,sharing:i.Share2,record_create:i.PlusCircle,record_delete:i.Trash2,approval:i.BadgeCheck},Ge={comment:`bg-purple-100 text-purple-600`,field_change:`bg-blue-100 text-blue-600`,task:`bg-green-100 text-green-600`,event:`bg-amber-100 text-amber-600`,system:`bg-gray-100 text-gray-600`,email:`bg-indigo-100 text-indigo-600`,call:`bg-teal-100 text-teal-600`,note:`bg-yellow-100 text-yellow-700`,file:`bg-slate-100 text-slate-600`,sharing:`bg-sky-100 text-sky-600`,record_create:`bg-emerald-100 text-emerald-600`,record_delete:`bg-red-100 text-red-600`,approval:`bg-violet-100 text-violet-600`};function Ke(e){return[{value:`all`,label:e(`detail.allActivity`)},{value:`comments_only`,label:e(`detail.commentsOnly`)},{value:`changes_only`,label:e(`detail.fieldChangesFilter`)},{value:`tasks_only`,label:e(`detail.tasksOnly`)}]}function qe(e,t){try{let n=new Date(e),r=new Date().getTime()-n.getTime(),i=Math.floor(r/6e4);if(i<1)return t(`detail.justNow`);if(i<60)return t(`detail.minutesAgo`,{count:i});let a=Math.floor(i/60);if(a<24)return t(`detail.hoursAgo`,{count:a});let o=Math.floor(a/24);return o<7?t(`detail.daysAgo`,{count:o}):n.toLocaleDateString()}catch{return e}}function Je(e,t){switch(t){case`comments_only`:return e.filter(e=>e.type===`comment`);case`changes_only`:return e.filter(e=>e.type===`field_change`);case`tasks_only`:return e.filter(e=>e.type===`task`);default:return e}}var Ye=({items:e,config:t,filterMode:a,onFilterChange:o,hasMore:s=!1,onLoadMore:c,loading:u=!1,onAddComment:d,onAddReply:f,onToggleReaction:p,subscription:m,onToggleSubscription:h,collapseWhenEmpty:g=!1,mentionSuggestions:_,onUploadAttachments:v,titleLabel:y,emptyLabel:b,className:x})=>{let{t:S}=D(),[C,w]=n.useState(`all`),[T,E]=n.useState(``),[O,k]=n.useState(!1),[A,j]=n.useState(!1),[M,N]=n.useState([]),[ee,P]=n.useState(!1),F=a??C,te=t?.showFilterToggle!==!1,I=t?.showCommentInput!==!1&&!!d,L=t?.enableReactions??!1,R=t?.enableThreading??!1,ne=t?.showSubscriptionToggle??!1,re=n.useMemo(()=>Je(e,F),[e,F]),ie=n.useMemo(()=>R?re.filter(e=>!e.parentId):re,[re,R]),z=n.useMemo(()=>{if(!R)return new Map;let e=new Map;for(let t of re)if(t.parentId){let n=e.get(t.parentId)??[];n.push(t),e.set(t.parentId,n)}return e},[re,R]),B=n.useCallback(e=>{o?o(e):w(e)},[o]),V=n.useCallback(async()=>{let e=T.trim();if(d&&!(!e&&M.length===0)){k(!0);try{await d(e,M.length>0?M:void 0),E(``),N([])}finally{k(!1)}}},[T,M,d]),H=n.useCallback(async e=>{if(!(!v||e.length===0)){P(!0);try{let t=await v(e);Array.isArray(t)&&t.length>0&&N(e=>[...e,...t])}finally{P(!1)}}},[v]),U=n.useCallback(e=>{N(t=>t.filter(t=>t.id!==e))},[]),W=n.useCallback(async()=>{if(c){j(!0);try{await c()}finally{j(!1)}}},[c]);return(0,l.jsxs)(`section`,{className:(0,r.cn)(`border-t border-border/60 pt-5`,x),"aria-label":`Discussion`,children:[(0,l.jsx)(`header`,{className:`mb-4`,children:(0,l.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,l.jsxs)(`h2`,{className:`flex items-center gap-2 text-base font-semibold leading-none tracking-tight`,children:[(0,l.jsx)(i.Activity,{className:`h-4 w-4`}),y??S(`detail.activity`),(0,l.jsxs)(`span`,{className:`text-sm font-normal text-muted-foreground`,children:[`(`,re.length,`)`]})]}),(0,l.jsx)(`div`,{className:`flex items-center gap-1`,children:ne&&m&&(0,l.jsx)(Le,{subscription:m,onToggle:h})})]})}),(0,l.jsxs)(`div`,{className:`space-y-4`,children:[te&&(0,l.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,l.jsxs)(r.Select,{value:F,onValueChange:e=>B(e),children:[(0,l.jsx)(r.SelectTrigger,{"aria-label":S(`detail.filterActivity`),className:`h-8 w-auto min-w-[140px] py-1 text-sm`,children:(0,l.jsx)(r.SelectValue,{})}),(0,l.jsx)(r.SelectContent,{children:Ke(S).map(e=>(0,l.jsx)(r.SelectItem,{value:e.value,children:e.label},e.value))})]})}),I&&(0,l.jsx)(ze,{value:T,onChange:E,onSubmit:V,mentionSuggestions:_,placeholder:S(`detail.leaveCommentPlaceholder`),disabled:O,canSubmitEmpty:M.length>0,extraSlot:v?(0,l.jsx)(Ue,{attachments:M,onUpload:H,onRemove:U,readOnly:O||ee}):M.length>0?(0,l.jsx)(Ue,{attachments:M,onRemove:U,readOnly:O}):void 0}),re.length===0?g?null:(0,l.jsx)(r.DataEmptyState,{title:b??S(`detail.noActivity`),className:`py-6`}):(0,l.jsxs)(`div`,{className:`relative`,children:[(0,l.jsx)(`div`,{className:`absolute left-4 top-2 bottom-2 w-px bg-border`}),(0,l.jsx)(`div`,{className:`space-y-4`,children:ie.map(e=>{let t=We[e.type]||i.Zap,n=Ge[e.type]||`bg-gray-100 text-gray-600`,a=z.get(e.id)??[];return(0,l.jsxs)(`div`,{children:[(0,l.jsxs)(`div`,{className:`flex gap-3 relative`,children:[(0,l.jsx)(`div`,{className:(0,r.cn)(`shrink-0 h-8 w-8 rounded-full flex items-center justify-center z-10`,n),children:e.actorAvatarUrl?(0,l.jsx)(`img`,{src:e.actorAvatarUrl,alt:e.actor,className:`h-8 w-8 rounded-full object-cover`}):(0,l.jsx)(t,{className:`h-3.5 w-3.5`})}),(0,l.jsxs)(`div`,{className:`flex-1 min-w-0 pt-1`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2 mb-0.5`,children:[(0,l.jsx)(`span`,{className:`text-sm font-medium`,children:e.actor}),e.source&&(0,l.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:S(`detail.via`,{source:e.source})}),(0,l.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:qe(e.createdAt,S)}),e.edited&&(0,l.jsx)(`span`,{className:`text-xs text-muted-foreground italic`,children:S(`detail.edited`)}),e.pinned&&(0,l.jsxs)(`span`,{className:`text-xs text-amber-600`,children:[`📌 `,S(`detail.pinned`)]})]}),e.body&&(0,l.jsx)(`p`,{className:`text-sm whitespace-pre-wrap break-words text-muted-foreground`,children:e.body}),e.sourceObject&&e.sourceId!=null&&(0,l.jsxs)(`a`,{href:`/objects/${e.sourceObject}/${e.sourceId}`,className:`mt-1 inline-flex items-center gap-1 text-xs text-primary hover:underline`,"data-testid":`activity-source-link`,children:[S(`detail.viewSource`),(0,l.jsx)(`span`,{"aria-hidden":!0,children:`→`})]}),e.type===`field_change`&&e.fieldChanges&&(0,l.jsx)(`div`,{className:`space-y-1 mt-1`,children:e.fieldChanges.map((e,t)=>(0,l.jsx)(Me,{change:e},t))}),L&&e.reactions&&e.reactions.length>0&&(0,l.jsx)(`div`,{className:`mt-1.5`,children:(0,l.jsx)(Pe,{reactions:e.reactions,onToggleReaction:p?t=>p(e.id,t):void 0})}),L&&(!e.reactions||e.reactions.length===0)&&p&&(0,l.jsx)(`div`,{className:`mt-1.5`,children:(0,l.jsx)(Pe,{reactions:[],onToggleReaction:t=>p(e.id,t)})})]})]}),R&&(e.replyCount??0)>0&&(0,l.jsx)(Ie,{parentItem:e,replies:a,onAddReply:f,showReplyInput:!!f})]},e.id)})})]}),s&&(0,l.jsx)(`div`,{className:`text-center pt-2`,children:(0,l.jsxs)(r.Button,{variant:`ghost`,size:`sm`,onClick:W,disabled:A,"aria-label":S(`detail.loadMore`),children:[A?(0,l.jsx)(i.Loader2,{className:`h-4 w-4 animate-spin mr-1`}):(0,l.jsx)(i.ChevronDown,{className:`h-4 w-4 mr-1`}),S(`detail.loadMore`)]})})]})]})},Xe=e=>{let{"data-obj-id":t,"data-obj-type":n,style:r,...i}=e||{};return{designer:{"data-obj-id":t,"data-obj-type":n,style:r},rest:i}},Ze=({schema:e={},className:t,...n})=>{(0,a.useRecordContext)();let{designer:r}=Xe(n);return(0,l.jsx)(`div`,{className:t,...r,children:(0,l.jsx)(Ye,{items:[],config:e})})},Qe=({config:e,items:t,hasMore:a,onLoadMore:o,loading:s,onAddComment:c,onAddReply:u,onToggleReaction:d,subscription:f,onToggleSubscription:p,filterMode:m,onFilterChange:h,collapseWhenEmpty:g=!1,mentionSuggestions:_,onUploadAttachments:v,className:y})=>{let b=e?.position??`right`,x=e?.width??`360px`,S=e?.collapsible??!0,C=g&&t.length===0||(e?.defaultCollapsed??!1),{t:w}=D(),[T,E]=n.useState(C);return b===`right`||b===`left`?T&&S?(0,l.jsx)(`div`,{className:(0,r.cn)(`flex items-start pt-4`,b===`right`?`border-l`:`border-r`,y),children:(0,l.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-8 w-8 mx-1`,onClick:()=>E(!1),"aria-label":w(`detail.openDiscussion`),children:(0,l.jsx)(i.PanelRightOpen,{className:`h-4 w-4`})})}):(0,l.jsxs)(`div`,{className:(0,r.cn)(`flex flex-col overflow-hidden`,b===`right`?`border-l`:`border-r`,y),style:{width:x,minWidth:x},children:[(0,l.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(i.MessageSquare,{className:`h-4 w-4`}),(0,l.jsx)(`span`,{className:`text-sm font-medium`,children:w(`detail.discussion`)})]}),S&&(0,l.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:()=>E(!0),"aria-label":w(`detail.closeDiscussion`),children:(0,l.jsx)(i.X,{className:`h-3.5 w-3.5`})})]}),(0,l.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:(0,l.jsx)(Ye,{items:t,config:e?.feed,hasMore:a,onLoadMore:o,loading:s,onAddComment:c,onAddReply:u,onToggleReaction:d,subscription:f,onToggleSubscription:p,filterMode:m,onFilterChange:h,collapseWhenEmpty:g,mentionSuggestions:_,onUploadAttachments:v,titleLabel:w(`detail.discussion`),emptyLabel:w(`detail.noCommentsYet`),className:`border-0 shadow-none`})})]}):(0,l.jsx)(`div`,{className:(0,r.cn)(``,y),children:S&&T?(0,l.jsxs)(r.Button,{variant:`ghost`,className:`w-full justify-start gap-2 text-muted-foreground`,onClick:()=>E(!1),"aria-label":w(`detail.showDiscussion`,{count:t.length}),children:[(0,l.jsx)(i.MessageSquare,{className:`h-4 w-4`}),(0,l.jsx)(`span`,{children:w(`detail.showDiscussion`,{count:t.length})})]}):(0,l.jsxs)(`div`,{children:[S&&(0,l.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium`,children:[(0,l.jsx)(i.MessageSquare,{className:`h-4 w-4`}),w(`detail.discussion`)]}),(0,l.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:()=>E(!0),"aria-label":w(`detail.hideDiscussion`),children:(0,l.jsx)(i.PanelRightClose,{className:`h-3.5 w-3.5`})})]}),(0,l.jsx)(Ye,{items:t,config:e?.feed,hasMore:a,onLoadMore:o,loading:s,onAddComment:c,onAddReply:u,onToggleReaction:d,subscription:f,onToggleSubscription:p,filterMode:m,onFilterChange:h,collapseWhenEmpty:g,mentionSuggestions:_,onUploadAttachments:v,titleLabel:w(`detail.discussion`),emptyLabel:w(`detail.noCommentsYet`)})]})})},$e=e=>{let{"data-obj-id":t,"data-obj-type":n,style:r,...i}=e||{};return{designer:{"data-obj-id":t,"data-obj-type":n,style:r},rest:i}},et=({schema:e={},className:t,...n})=>{(0,a.useRecordContext)();let r=(0,a.useDiscussionContext)(),{designer:i}=$e(n),o={position:`bottom`,collapsible:!1,feed:{enableReactions:!0,enableThreading:!0,showCommentInput:!0},...e};return(0,l.jsx)(`div`,{className:t,...i,children:(0,l.jsx)(Qe,{items:r?.items||[],config:o,onAddComment:r?.onAddComment,onAddReply:r?.onAddReply,onToggleReaction:r?.onToggleReaction,mentionSuggestions:r?.mentionSuggestions,onUploadAttachments:r?.onUploadAttachments})})},tt=e=>{let{"data-obj-id":t,"data-obj-type":n,style:r,...i}=e||{};return{designer:{"data-obj-id":t,"data-obj-type":n,style:r},rest:i}},nt=({schema:e={},className:t,...i})=>{let o=(0,a.useRecordContext)(),{translateOptions:s}=(0,a.useSafeFieldLabel)(),{designer:c}=tt(i),u=Array.isArray(e.stages)?e.stages:[],d=e.statusField,f=n.default.useMemo(()=>{if(u.length===0||!d||!o?.objectName)return u;let e=s(o.objectName,d,u);return Array.isArray(e)&&e.length===u.length?u.map((t,n)=>({...t,label:e[n]?.label??t.label})):u},[u,d,o?.objectName,s]),p=d&&o?.data?o.data[d]:void 0,m=/(^|[_-\s])(closed_)?(lost|failed?|cancell?ed|失败|流失|丢单|败)([_-\s]|$)/i,h=/(^|[_-\s])(closed_)?(won|success|成交|赢|完成)([_-\s]|$)/i,g=f.map(e=>{if(e.terminal)return e.terminal;let t=`${String(e.value??``)} ${String(e.label??``)}`;if(m.test(t))return`lost`;if(h.test(t))return`won`}),_=g.findIndex(e=>e===`lost`),v=_===-1?f:f.slice(0,_),y=_===-1?[]:f.slice(_),b=_===-1?g:g.slice(0,_),x=f.findIndex(e=>e.value===p);x<0&&(x=-1);let S=_!==-1&&x>=_;if(f.length===0)return(0,l.jsx)(`div`,{className:t,...c,children:(0,l.jsx)(`div`,{className:`text-xs text-muted-foreground italic px-3 py-2 border border-dashed rounded`,children:`record:path — no stages configured`})});let C=v.length-1;return(0,l.jsxs)(`div`,{className:(0,r.cn)(`w-full`,t),...c,children:[(0,l.jsxs)(`div`,{className:`hidden sm:flex w-full items-stretch gap-2`,role:`list`,"aria-label":e.aria?.label||`Record path`,children:[(0,l.jsx)(`div`,{className:`flex flex-1 items-stretch gap-1.5`,children:v.map((e,t)=>{let n=!S&&x>=0&&t<x,i=!S&&t===x,a=b[t]===`won`&&t===C;return(0,l.jsx)(`div`,{role:`listitem`,"aria-current":i?`step`:void 0,className:(0,r.cn)(`relative flex-1 min-w-0 px-4 py-2 text-xs font-medium text-center rounded-xl`,i&&`bg-primary text-primary-foreground shadow-sm`,n&&`bg-emerald-500/15 text-emerald-800 dark:text-emerald-200`,!i&&!n&&a&&`bg-emerald-500/10 text-emerald-700/85 dark:text-emerald-300/85`,!i&&!n&&!a&&`bg-muted text-muted-foreground`),children:(0,l.jsxs)(`span`,{className:`inline-flex items-center justify-center gap-1.5 truncate`,children:[n&&(0,l.jsx)(`span`,{"aria-hidden":!0,className:`text-emerald-600 dark:text-emerald-400 font-semibold`,children:`✓`}),a&&!i&&(0,l.jsx)(`span`,{"aria-hidden":!0,className:`opacity-70`,children:`🏆`}),e.label]})},`${e.value}-${t}`)})}),y.length>0&&(0,l.jsx)(`div`,{className:`flex items-stretch gap-1 pl-2 border-l border-border/40`,"aria-label":`Alternative terminal stages`,children:y.map((e,t)=>{let n=_+t===x;return(0,l.jsx)(`div`,{role:`listitem`,"aria-current":n?`step`:void 0,className:(0,r.cn)(`shrink-0 px-3 py-2 text-xs font-medium rounded-md border whitespace-nowrap`,n&&`bg-destructive text-destructive-foreground border-destructive shadow-sm ring-1 ring-destructive/40`,!n&&`bg-destructive/5 text-destructive/85 border-destructive/20`),children:(0,l.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,l.jsx)(`span`,{"aria-hidden":!0,className:`opacity-70`,children:`✗`}),e.label]})},`${e.value}-lost-${t}`)})})]}),(0,l.jsx)(`div`,{className:`flex sm:hidden w-full items-stretch gap-1 overflow-x-auto pb-1 -mx-1 px-1 [-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden`,role:`list`,"aria-label":e.aria?.label||`Record path`,children:f.map((e,t)=>{let n=g[t]===`lost`,i=!n&&!S&&x>=0&&t<x,a=t===x;return(0,l.jsx)(`div`,{role:`listitem`,"aria-current":a?`step`:void 0,className:(0,r.cn)(`shrink-0 px-3 py-1.5 rounded-full text-xs font-medium border whitespace-nowrap`,n&&a&&`bg-destructive text-destructive-foreground border-destructive shadow-sm`,n&&!a&&`bg-destructive/5 text-destructive/85 border-destructive/20`,!n&&a&&`bg-primary text-primary-foreground border-primary shadow-sm ring-1 ring-primary/40`,!n&&i&&`bg-emerald-500/15 text-emerald-800 dark:text-emerald-200 border-emerald-500/30`,!n&&!a&&!i&&`bg-background text-foreground/85 border-border/60`),children:(0,l.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[n&&(0,l.jsx)(`span`,{"aria-hidden":!0,className:`opacity-70`,children:`✗`}),!n&&i&&(0,l.jsx)(`span`,{"aria-hidden":!0,className:`text-emerald-600 dark:text-emerald-400 font-semibold`,children:`✓`}),e.label]})},`${e.value}-${t}-m`)})})]})},rt=e=>{let{"data-obj-id":t,"data-obj-type":n,style:r,...i}=e||{};return{designer:{"data-obj-id":t,"data-obj-type":n,style:r},rest:i}},it=({schema:e={},className:t,...n})=>{let i=(0,a.useRecordContext)(),{designer:o}=rt(n),c=(0,u.usePermissions)(),{language:d}=(0,s.useObjectTranslation)(),f=(0,a.useSafeFieldLabel)(),p=Array.isArray(e.actions)?e.actions:Array.isArray(e.properties?.actions)?e.properties.actions:[],m=Array.isArray(e.actionNames)?e.actionNames:Array.isArray(e.properties?.actionNames)?e.properties.actionNames:[],h=i?.objectName||``,g=m.length>0?m:Array.isArray(p)&&p.every(e=>typeof e==`string`)?p:[],_=g.length>0&&!!h,{item:v}=(0,a.useMetadataItem)(`object`,_?h:null),y=_?(()=>{let e=Array.isArray(v?.actions)?v.actions:[],t=new Map(e.map(e=>[e.name,e]));return g.map(e=>t.get(e)).filter(e=>!!e)})():Array.isArray(p)?p:[],b=Array.isArray(e.requiredPermissions)?e.requiredPermissions:[],x=e.location||`record_header`,{getActionsForLocation:S,executeAction:C}=(0,a.useActionEngine)({actions:y,context:{record:i?.data,recordId:i?.recordId,objectName:i?.objectName}});if(b.length>0&&h&&!b.every(e=>c.can(h,e)))return(0,l.jsx)(`div`,{className:t,...o,role:`status`,"aria-live":`polite`,children:(0,l.jsx)(`p`,{className:`text-sm text-muted-foreground italic`,children:`Insufficient permissions to view quick actions.`})});let w=y.length>0?S(x):[];if(w.length===0)return(0,l.jsx)(`div`,{className:t,...o,children:(0,l.jsx)(`div`,{className:`text-xs text-muted-foreground italic px-3 py-2 border border-dashed rounded`,children:`record:quick_actions — no actions configured`})});let T=e.align||`end`,E=T===`start`?`justify-start`:T===`center`?`justify-center`:`justify-end`;return(0,l.jsx)(`div`,{className:(0,r.cn)(`flex flex-wrap items-center gap-2`,x===`record_header`&&!e.inline&&`-mt-12 sm:-mt-14 mb-2 relative z-10`,E,t),role:`toolbar`,"aria-label":e.aria?.label||`Quick actions`,...o,children:w.map((t,n)=>(0,l.jsx)(at,{action:t,record:i?.data,variant:t.variant||e.variant||`default`,size:t.size||e.size||`sm`,label:(()=>{let e=(0,s.pickLocalized)(t.label,d)||t.name||`Action ${n+1}`;return t.name?f.actionLabel(h||void 0,t.name,e):e})(),onRun:async()=>{typeof t.onClick==`function`?await t.onClick():t.name&&await C(t.name)}},t.name||`qa-${n}`))})};function at({action:e,record:t,variant:o,size:s,label:c,onRun:u}){let[d,f]=n.default.useState(!1),p=n.default.useMemo(()=>({record:t||{}}),[t]),m=(0,a.useCondition)((0,a.toPredicateInput)(e.disabled),p);return(0,l.jsxs)(r.Button,{variant:o,size:s,disabled:e.disabled!=null&&m||d,onClick:async()=>{f(!0);try{await u()}finally{f(!1)}},children:[d&&(0,l.jsx)(i.Loader2,{className:`mr-2 h-4 w-4 animate-spin`}),c]})}var ot=e=>{let{"data-obj-id":t,"data-obj-type":n,style:r,...i}=e||{};return{designer:{"data-obj-id":t,"data-obj-type":n,style:r},rest:i}},st=new Set([`created`,`updated`,`assigned`,`shared`,`deleted`]),ct=({schema:e={},className:t,...r})=>{let{designer:i}=ot(r),o=(0,a.useRecordContext)(),s=Array.isArray(e.entries)?e.entries:Array.isArray(e.properties?.entries)?e.properties.entries:void 0,c=e.loading??e.properties?.loading,u=e.emptyText??e.properties?.emptyText,d=e.unknownUserText??e.properties?.unknownUserText,f=Number(e.limit??e.properties?.limit??50)||50,p=o?.objectName,m=o?.data?.id??o?.data?._id??o?.recordId,h=o?.dataSource,g=s===void 0&&!!h?.find&&!!p&&m!=null,[_,v]=n.default.useState(null),[y,b]=n.default.useState(!1);n.default.useEffect(()=>{if(!g)return;let e=!1;return b(!0),Promise.resolve(h.find(`sys_activity`,{$filter:{object_name:p,record_id:m},$orderby:{timestamp:`desc`},$top:Math.max(1,f)})).then(t=>{if(e)return;let n=(t?.data??t?.records??[]).filter(e=>st.has(e?.type)).map(e=>{let t=e.timestamp;return(!t||t===`NOW()`||Number.isNaN(Date.parse(t)))&&(t=e.created_at),{id:e.id,created_at:t,action:e.type,user_name:e.actor_name??null,user_avatar:e.actor_avatar_url??null,summary:e.summary??null}});v(n)}).catch(()=>{e||v([])}).finally(()=>{e||b(!1)}),()=>{e=!0}},[g,h,p,m,f]);let x=s??_??[],S=c??(g&&_===null?y||!0:!1);return(0,l.jsx)(`div`,{className:t,...i,children:(0,l.jsx)(de,{entries:x,loading:S,emptyText:u,unknownUserText:d})})},lt=e=>{let{"data-obj-id":t,"data-obj-type":n,style:r,...i}=e||{};return{designer:{"data-obj-id":t,"data-obj-type":n,style:r},rest:i}},ut=e=>e.replace(/[_-]+/g,` `).replace(/\b\w/g,e=>e.toUpperCase()).trim(),dt=(e,t)=>t&&e?.[t]!=null&&e[t]!==``?String(e[t]):e?.name||e?.title||e?.subject||e?.label||e?.email||e?.username||e?.code||e?.slug||e?.provider_id||e?.user_agent||e?.ip_address||e?.id||`—`,ft=({schema:e={},className:t,...o})=>{let s=(0,a.useRecordContext)(),u=(0,a.useSafeFieldLabel)(),{t:d}=D(),{designer:f}=lt(o),p=(0,c.useParams)().appName,m=Array.isArray(e.entries)?e.entries:Array.isArray(e.properties?.entries)?e.properties.entries:[],h=s?.recordId,g=s?.dataSource,[_,v]=n.default.useState({}),y=n.default.useRef(null),[b,x]=n.default.useState(!1),S=n.default.useRef(!0);n.default.useEffect(()=>(S.current=!0,()=>{S.current=!1}),[]);let C=n.default.useRef(``);n.default.useEffect(()=>{if(b)return;let e=y.current;if(!e||typeof IntersectionObserver>`u`){x(!0);return}let t=new IntersectionObserver(e=>{e.some(e=>e.isIntersecting)&&x(!0)},{rootMargin:`200px`});return t.observe(e),()=>t.disconnect()},[b]);let w=JSON.stringify(m.map(e=>`${e.objectName}:${e.relationshipField}:${e.limit??3}`));n.default.useEffect(()=>{if(!b||!g?.find||!h||m.length===0)return;let e=`${h}::${w}`;if(C.current===e)return;C.current=e,v(e=>{let t={...e};for(let n of m)t[n.objectName]={loading:!0,total:0,items:e[n.objectName]?.items||[]};return t});let t=async e=>{let t=e.objectName;try{let n=await g.find(e.objectName,{$filter:{[e.relationshipField]:h},$top:e.limit??3,$count:!0});if(!S.current)return;let r=Array.isArray(n)?n:n?.data||[],i=typeof n?.total==`number`?n.total:typeof n?.count==`number`?n.count:r.length;v(e=>({...e,[t]:{loading:!1,total:i,items:r}}))}catch(e){if(!S.current)return;v(n=>({...n,[t]:{loading:!1,total:0,items:[],error:String(e?.message||e)}}))}},n=[...m],r=async()=>{for(;S.current;){let e=n.shift();if(!e)return;await t(e)}},i=Array.from({length:Math.min(3,n.length)},()=>r());Promise.all(i)},[b,g,h,w]);let[T,E]=n.default.useState(!1);if(m.length===0)return null;let O=e.hideEmpty!==!1,k=new Set(m.filter(e=>{let t=_[e.objectName];return O&&t&&!t.loading&&!t.error&&t.total===0}).map(e=>e.objectName)),A=m.filter(e=>T||!k.has(e.objectName)),j=m.filter(e=>k.has(e.objectName)).map(e=>e.title||(u?.objectLabel?u.objectLabel({name:e.objectName,label:ut(e.objectName)}):ut(e.objectName)));return(0,l.jsxs)(`div`,{ref:y,className:(0,r.cn)(`flex flex-col gap-3`,e.className,t),...f,children:[A.map(e=>{let t=e.objectName,n=_[t]||{loading:!0,total:0,items:[]};return(0,l.jsxs)(r.Card,{className:`overflow-hidden`,children:[(0,l.jsxs)(r.CardHeader,{className:`flex flex-row items-center justify-between gap-2 py-3 px-4 space-y-0 border-b`,children:[(0,l.jsx)(r.CardTitle,{className:`text-sm font-semibold tracking-tight truncate`,children:e.title||(u?.objectLabel?u.objectLabel({name:e.objectName,label:ut(e.objectName)}):ut(e.objectName))}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[!n.loading&&(0,l.jsx)(r.Badge,{variant:`secondary`,className:`tabular-nums`,children:n.total}),p&&h&&(0,l.jsx)(c.Link,{to:`/apps/${p}/${e.objectName}?filter%5B${e.relationshipField}%5D=${encodeURIComponent(String(h))}`,className:`text-[11px] font-medium text-muted-foreground hover:text-foreground transition-colors`,title:d(`detail.viewAll`,{defaultValue:`View all`}),children:d(`detail.viewAll`,{defaultValue:`View all`})})]})]}),(0,l.jsx)(r.CardContent,{className:`p-0`,children:n.loading?(0,l.jsxs)(`div`,{className:`space-y-1.5 p-3`,children:[(0,l.jsx)(r.Skeleton,{className:`h-3.5 w-4/5`}),(0,l.jsx)(r.Skeleton,{className:`h-3.5 w-3/5`}),(0,l.jsx)(r.Skeleton,{className:`h-3.5 w-2/3`})]}):n.items.length===0?(0,l.jsx)(`p`,{className:`px-4 py-3 text-xs text-muted-foreground`,children:d(`detail.noRecords`)}):(0,l.jsx)(`ul`,{className:`divide-y`,children:n.items.map(t=>{let n=t.id||t._id,r=dt(t,e.displayField),a=n?`../${e.objectName}/record/${encodeURIComponent(String(n))}`:void 0;return(0,l.jsx)(`li`,{className:`px-4 py-2`,children:a?(0,l.jsxs)(c.Link,{to:a,className:`group flex items-center justify-between gap-2 text-xs hover:text-foreground text-muted-foreground transition-colors`,children:[(0,l.jsx)(`span`,{className:`truncate`,children:r}),(0,l.jsx)(i.ChevronRight,{className:`h-3 w-3 shrink-0 opacity-0 group-hover:opacity-100 transition-opacity`})]}):(0,l.jsx)(`span`,{className:`block truncate text-xs text-muted-foreground`,children:r})},String(n||r))})})})]},t)}),!T&&j.length>0&&(0,l.jsxs)(`button`,{type:`button`,onClick:()=>E(!0),className:`self-start inline-flex items-center gap-1.5 text-[11px] text-muted-foreground hover:text-foreground transition-colors px-2.5 py-1 rounded-md border border-dashed border-border/60 hover:border-border bg-background`,title:j.join(` · `),children:[(0,l.jsx)(`span`,{children:d(`detail.showEmptyRelated`,{defaultValue:`+ {{count}} empty`,count:j.length})}),(0,l.jsxs)(`span`,{className:`truncate max-w-[180px] text-muted-foreground/70`,children:[`(`,j.join(` · `),`)`]})]})]})},pt={info:{wrap:`border-blue-300/60 bg-blue-50 text-blue-900 dark:border-blue-700/40 dark:bg-blue-950/30 dark:text-blue-100 [&>svg]:text-blue-600 dark:[&>svg]:text-blue-300`,icon:`Info`},warning:{wrap:`border-amber-300/60 bg-amber-50 text-amber-900 dark:border-amber-700/40 dark:bg-amber-950/30 dark:text-amber-100 [&>svg]:text-amber-600 dark:[&>svg]:text-amber-300`,icon:`AlertTriangle`},error:{wrap:`border-destructive/60 bg-destructive/10 text-destructive dark:bg-destructive/20 [&>svg]:text-destructive`,icon:`AlertCircle`},success:{wrap:`border-emerald-300/60 bg-emerald-50 text-emerald-900 dark:border-emerald-700/40 dark:bg-emerald-950/30 dark:text-emerald-100 [&>svg]:text-emerald-600 dark:[&>svg]:text-emerald-300`,icon:`CheckCircle2`}};function mt(e){let t=e?.properties??{};return{...e,...t}}var ht=({schema:e={},className:t})=>{let i=mt(e),o=(0,a.useRecordContext)(),c=o?.data,u=o?.objectName||``,d=o?.recordId??c?.id,{language:f}=(0,s.useObjectTranslation)(),p=(0,s.pickLocalized)(i.title,f),m=(0,s.pickLocalized)(i.body,f),h=(0,s.pickLocalized)(i.action?.label,f),g=[`info`,`warning`,`error`,`success`].includes(i.severity)?i.severity:`info`,_=pt[g],v=i.icon||_.icon,y=(0,a.toPredicateInput)(i.visible),b=(0,a.useCondition)(y,{record:c}),x=n.useMemo(()=>{if(!i.dismissible)return null;let e=i.dismissKey||(0,s.pickLocalized)(i.title,`en`)||g;return`os.record-alert:${u}:${d??`_`}:${e}`},[i.dismissible,i.dismissKey,i.title,g,u,d]),[S,C]=n.useState(()=>{if(!x||typeof window>`u`)return!1;try{return window.localStorage.getItem(x)===`1`}catch{return!1}}),w=i.action?.actionName,{item:T}=(0,a.useMetadataItem)(`object`,w&&u?u:null),E=n.useMemo(()=>{if(!(!w||!T?.actions))return T.actions.find(e=>e.name===w)},[w,T]),{executeAction:D}=(0,a.useActionEngine)({actions:n.useMemo(()=>E?[E]:[],[E]),context:{record:c,recordId:d,objectName:u}});return S||!c||Object.keys(c).length===0||y!==void 0&&!b?null:(0,l.jsxs)(r.Alert,{className:(0,r.cn)(`relative pr-12`,_.wrap,t),role:g===`error`?`alert`:`status`,"aria-live":g===`error`?`assertive`:`polite`,children:[(0,l.jsx)(r.LazyIcon,{name:v,className:`h-4 w-4`,"aria-hidden":`true`}),p?(0,l.jsx)(r.AlertTitle,{children:p}):null,m||E?(0,l.jsxs)(r.AlertDescription,{children:[m?(0,l.jsx)(`p`,{className:`mb-2 last:mb-0`,children:m}):null,E?(0,l.jsx)(r.Button,{size:`sm`,variant:i.action?.variant||(g===`error`?`destructive`:`default`),onClick:()=>{E?.name&&D(E.name)},children:h||E.label||E.name}):null]}):null,i.dismissible?(0,l.jsx)(`button`,{type:`button`,onClick:()=>{if(C(!0),x)try{window.localStorage.setItem(x,`1`)}catch{}},"aria-label":`Dismiss`,className:`absolute right-3 top-3 inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground/80 hover:bg-foreground/5 hover:text-foreground focus:outline-none focus:ring-2 focus:ring-ring`,children:(0,l.jsx)(r.LazyIcon,{name:`X`,className:`h-4 w-4`,"aria-hidden":`true`})}):null]})},gt=e=>{if(e==null)return`—`;if(typeof e==`string`)return e.length>0?e:`""`;if(typeof e==`number`||typeof e==`boolean`)return String(e);try{return JSON.stringify(e)}catch{return String(e)}},_t=e=>{if(typeof e!=`string`||e.length===0)return null;let t=/\d{4}-\d{2}-\d{2}[ T]/.test(e)?e.replace(` `,`T`):e,n=new Date(t);if(Number.isNaN(n.getTime()))return null;try{return n.toLocaleString()}catch{return n.toISOString()}},vt=({open:e,conflict:t,onReload:n,onOverwrite:a,onCancel:o,busy:s=!1})=>{let{t:c}=D(),u=t?.label||t?.field||``,d=t?gt(t.pendingValue):``,f=t?gt(t.currentValue):``,p=t?.currentRecord??{},m=(()=>{let e=[p.updated_by_name,p.updated_by_label];for(let t of e)if(typeof t==`string`&&t.length>0)return t;let t=p.updated_by;return typeof t!=`string`||t.length===0||t.length>=16&&!/\s/.test(t)&&/^[A-Za-z0-9_-]+$/.test(t)?null:t})(),h=_t(p.updated_at??t?.currentVersion),[g,_]=c(`detail.concurrentUpdateDescription`,{field:`{{field}}`}).split(`{{field}}`);return(0,l.jsx)(r.AlertDialog,{open:e,onOpenChange:e=>{!e&&!s&&o()},children:(0,l.jsxs)(r.AlertDialogContent,{className:`max-w-lg`,children:[(0,l.jsx)(r.AlertDialogHeader,{children:(0,l.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,l.jsx)(`span`,{className:`inline-flex h-9 w-9 flex-none items-center justify-center rounded-full bg-amber-100 text-amber-700 dark:bg-amber-500/20 dark:text-amber-300`,"aria-hidden":`true`,children:(0,l.jsx)(i.AlertTriangle,{className:`h-5 w-5`})}),(0,l.jsxs)(`div`,{className:`flex-1`,children:[(0,l.jsx)(r.AlertDialogTitle,{children:c(`detail.concurrentUpdateTitle`)}),(0,l.jsxs)(r.AlertDialogDescription,{className:`mt-1`,children:[g,(0,l.jsx)(`strong`,{className:`font-semibold`,children:u}),_]})]})]})}),(0,l.jsxs)(`div`,{className:`space-y-2 text-sm`,children:[(0,l.jsxs)(`div`,{className:`rounded-md border border-amber-200/70 bg-amber-50/60 p-3 dark:border-amber-500/30 dark:bg-amber-500/10`,children:[(0,l.jsx)(`div`,{className:`text-xs font-medium uppercase tracking-wide text-amber-800 dark:text-amber-300`,children:c(`detail.concurrentUpdateYourEdit`)}),(0,l.jsx)(`div`,{className:`mt-1 break-all font-mono text-foreground`,children:d})]}),(0,l.jsxs)(`div`,{className:`rounded-md border border-sky-200/70 bg-sky-50/60 p-3 dark:border-sky-500/30 dark:bg-sky-500/10`,children:[(0,l.jsxs)(`div`,{className:`flex items-baseline justify-between gap-2`,children:[(0,l.jsx)(`div`,{className:`text-xs font-medium uppercase tracking-wide text-sky-800 dark:text-sky-300`,children:c(`detail.concurrentUpdateCurrentValue`)}),(m||h)&&(0,l.jsxs)(`div`,{className:`text-[11px] text-muted-foreground`,children:[m&&(0,l.jsx)(`span`,{children:c(`detail.concurrentUpdateUpdatedBy`,{name:m})}),m&&h&&(0,l.jsx)(`span`,{children:` · `}),h&&(0,l.jsx)(`span`,{children:c(`detail.concurrentUpdateUpdatedAt`,{when:h})})]})]}),(0,l.jsx)(`div`,{className:`mt-1 break-all font-mono text-foreground`,children:f})]})]}),(0,l.jsxs)(r.AlertDialogFooter,{className:`gap-2 sm:gap-2`,children:[(0,l.jsx)(`button`,{type:`button`,disabled:s,onClick:o,className:(0,r.cn)((0,r.buttonVariants)({variant:`ghost`}),`mt-2 sm:mt-0`),children:c(`detail.concurrentUpdateCancel`)}),(0,l.jsx)(`button`,{type:`button`,disabled:s,onClick:a,className:(0,r.cn)((0,r.buttonVariants)({variant:`outline`}),`mt-2 sm:mt-0 text-destructive border-destructive/40 hover:bg-destructive/10 hover:text-destructive`),children:c(`detail.concurrentUpdateOverwrite`)}),(0,l.jsx)(`button`,{type:`button`,disabled:s,onClick:n,autoFocus:!0,className:(0,r.cn)((0,r.buttonVariants)({variant:`default`}),`mt-2 sm:mt-0`),children:c(`detail.concurrentUpdateReload`)})]})]})})};function yt(e){if(!e||typeof e!=`object`)return!1;let t=e;return t.code===`CONCURRENT_UPDATE`||t.name===`ConcurrentUpdateError`}function bt(e){let t=e?.message||e?.error||String(e??`Save failed`);return String(t).replace(/^\[[^\]]+\]\s*/,``).replace(/^[A-Z][A-Z0-9_]+:\s*/,``)}async function xt(e,t,n,r,i){if(typeof e?.update==`function`)await e.update(t,n,r,i);else if(typeof e?.updateOne==`function`)await e.updateOne(t,n,r,i);else if(typeof e?.patch==`function`)await e.patch(t,n,r,i);else throw Error(`[InlineEditSaveBar] DataSource exposes no update/updateOne/patch method; cannot persist inline edit`)}var St=({dataSource:e,objectName:t,recordId:o,data:s,refresh:c,fieldLabelFor:u,onFieldSave:d,locked:f=!1,lockedHint:p,className:m})=>{let{t:h}=D(),g=(0,a.useInlineEdit)(),[_,v]=n.useState(null),[y,b]=n.useState(!1),x=!!e&&!!t&&o!=null,S=n.useCallback((e,t)=>{let n=Object.keys(e),r=t?.currentRecord??null;if(n.length===1){let i=n[0];return{field:i,label:u?.(i),pendingValue:e[i],currentValue:r?r[i]:void 0,currentVersion:t?.currentVersion,currentRecord:r}}let i=r?Object.fromEntries(n.map(e=>[e,r[e]])):void 0;return{field:n.join(`, `),label:h(`detail.concurrentUpdateRecordLabel`,{defaultValue:`this record`}),pendingValue:e,currentValue:i,currentVersion:t?.currentVersion,currentRecord:r}},[u,h]),C=n.useCallback(async()=>{if(!g)return;let n=g.draft,r=Object.entries(n);if(r.length===0){g.reset();return}g.setSaving(!0),g.setError(null);try{if(d)for(let[e,t]of r)await d(e,t);else if(x){let r=typeof s?.updated_at==`string`?s.updated_at:void 0;await xt(e,t,o,n,r?{ifMatch:r}:void 0),await c?.()}g.reset()}catch(e){yt(e)&&x?v(S(n,e)):g.setError(bt(e))}finally{g.setSaving(!1)}},[g,d,x,s,e,t,o,c,S]),w=n.useCallback(()=>{v(null),b(!1)},[]),T=n.useCallback(async()=>{b(!0);try{await c?.()}finally{g?.reset(),w()}},[c,g,w]),E=n.useCallback(async()=>{if(!_||!x){w();return}b(!0);try{await xt(e,t,o,g?.draft??{},_.currentVersion?{ifMatch:_.currentVersion}:void 0),await c?.(),g?.reset()}catch(e){g?.setError(bt(e))}finally{w()}},[_,x,g,e,t,o,c,w]),O=!!g?.editing,k=!!g?.saving,A=g?.cancel,j=!!_;return n.useEffect(()=>{if(!O)return;let e=e=>{if(e.key===`Enter`&&(e.metaKey||e.ctrlKey)){if(k||f||j)return;e.preventDefault(),C();return}if(e.key===`Escape`){if(e.defaultPrevented||k||j||document.querySelector(`[data-radix-popper-content-wrapper], [role="dialog"][data-state="open"], [role="alertdialog"][data-state="open"]`))return;e.preventDefault(),A?.()}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[O,k,f,j,C,A]),!g||!g.editing?null:(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(`div`,{className:(0,r.cn)(`sticky bottom-0 z-30 mt-4 flex flex-wrap items-center justify-end gap-2 rounded-md border bg-background/95 px-3 py-2 shadow-sm backdrop-blur supports-[backdrop-filter]:bg-background/80`,m),role:`region`,"aria-label":h(`detail.editFieldsInline`),children:[g.error&&(0,l.jsx)(`div`,{role:`alert`,className:`mr-auto max-w-md rounded-md border border-destructive/20 bg-destructive/10 px-2 py-1 text-xs text-destructive`,children:g.error}),(0,l.jsxs)(r.Button,{variant:`ghost`,size:`sm`,onClick:g.cancel,disabled:g.saving,className:`gap-2`,children:[(0,l.jsx)(i.X,{className:`h-4 w-4`}),(0,l.jsx)(`span`,{children:h(`detail.cancel`)})]}),(0,l.jsxs)(r.Button,{variant:`default`,size:`sm`,onClick:C,disabled:g.saving||f,className:`gap-2`,title:f?p:void 0,children:[g.saving?(0,l.jsx)(i.Loader2,{className:`h-4 w-4 animate-spin`}):(0,l.jsx)(i.Check,{className:`h-4 w-4`}),(0,l.jsx)(`span`,{children:g.saving?h(`detail.saving`):h(`detail.save`)})]})]}),(0,l.jsx)(vt,{open:!!_,conflict:_,busy:y,onCancel:w,onReload:T,onOverwrite:E})]})},Ct=new Set(d.SYSTEM_MANAGED_FIELD_NAMES),wt=480,Tt=95;function Et({open:e,onClose:t,title:i,record:o,objectName:s,recordId:c,dataSource:u,objectSchema:d,width:f=`min(960px, 60vw)`,columns:p=2,systemFields:m=Ct,onFieldSave:h,onDelete:g,resizable:_=!0,fullPageHref:v}){let{t:y}=D(),b=`objectui.drawerWidth.${s}`,[x,S]=n.default.useState(()=>{if(typeof window>`u`||!_)return null;try{let e=window.localStorage.getItem(b);if(e){let t=parseInt(e,10);if(Number.isFinite(t)&&t>=wt)return t}}catch{}return null}),C=n.default.useMemo(()=>_&&x!=null?`${x}px`:typeof f==`number`?`${f}px`:f,[_,x,f]),w=C?{width:C,maxWidth:C}:void 0,T=n.default.useRef(null),E=n.default.useCallback(e=>{if(!_)return;e.preventDefault();let t=x??(typeof window<`u`?Math.min(window.innerWidth*.6,960):720);T.current={startX:e.clientX,startWidth:t};let n=e=>{let t=T.current;if(!t)return;let n=t.startX-e.clientX,r=typeof window<`u`?window.innerWidth*Tt/100:1600,i=Math.min(r,Math.max(wt,t.startWidth+n));S(Math.round(i))},r=()=>{T.current,T.current=null,window.removeEventListener(`pointermove`,n),window.removeEventListener(`pointerup`,r),window.removeEventListener(`pointercancel`,r);try{S(e=>(e!=null&&window.localStorage.setItem(b,String(e)),e))}catch{}};window.addEventListener(`pointermove`,n),window.addEventListener(`pointerup`,r),window.addEventListener(`pointercancel`,r)},[_,x,b]),O=d?.fields??{},k=(Object.keys(O).length?Object.keys(O):Object.keys(o)).filter(e=>!m.has(e)&&!e.startsWith(`__`)).filter(e=>e in o).filter(e=>!O[e]?.hidden).map(e=>{let t=O[e]||{},n=t.type===`lookup`||t.type===`master_detail`||t.type===`reference`;return{name:e,label:t.label,type:t.type,readonly:!!t.readonly||n,options:t.options,currency:t.currency,precision:t.precision,scale:t.scale,format:t.format,reference_to:t.reference_to??t.reference??t.referenceTo??t.target,reference_field:t.reference_field??t.referenceField,required:t.required,validation:t.validation,placeholder:t.placeholder,description:t.description}});return(0,l.jsx)(r.Sheet,{open:e,onOpenChange:e=>{e||t()},children:(0,l.jsxs)(r.SheetContent,{side:`right`,className:`w-full overflow-y-auto p-0 sm:!max-w-none`,style:w,onOpenAutoFocus:e=>e.preventDefault(),children:[_&&(0,l.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize drawer`,onPointerDown:E,className:`hidden sm:block absolute left-0 top-0 h-full w-1.5 cursor-col-resize select-none bg-transparent hover:bg-primary/30 active:bg-primary/50 transition-colors z-10`}),(0,l.jsx)(r.SheetHeader,{className:`sr-only`,children:(0,l.jsx)(r.SheetTitle,{children:i})}),(0,l.jsx)(`div`,{className:`px-6 pt-6 pb-6`,children:(0,l.jsxs)(a.InlineEditProvider,{canEdit:!!h,children:[(0,l.jsx)(Q,{dataSource:u,inlineEdit:!!h,schema:{type:`detail-view`,objectName:s,resourceId:String(c),data:o,showDelete:!!g,columns:p,fields:k,actions:v?[{type:`action:bar`,location:`record_header`,systemActions:[{name:`sys_open_new_tab`,label:y(`detail.openInNewTab`),icon:`external-link`,type:`script`,onClick:()=>window.open(v,`_blank`,`noopener`)}]}]:void 0},onDelete:g?async()=>{try{await g(),t()}catch(e){console.error(`[RecordDetailDrawer] delete failed:`,e)}}:void 0}),(0,l.jsx)(St,{onFieldSave:h?async(e,t)=>{try{await h(e,t)}catch(e){throw console.error(`[RecordDetailDrawer] inline field save failed:`,e),e}}:void 0})]})})]})})}function Dt(e,t){if(typeof window>`u`)return null;let n=window.location.pathname,r=`/${e}`,i=n.indexOf(r);return`${i>=0?n.slice(0,i):n.replace(/\/$/,``)}/${e}/record/${encodeURIComponent(String(t))}`}var Ot=({objectName:e,relationshipField:t,fields:a,onCreateRecord:o,onLinkRecord:s,onSearch:c,existingRecords:u=[],className:d})=>{let[f,p]=n.useState(!1),[m,h]=n.useState(`create`),[g,_]=n.useState({}),[v,y]=n.useState(``),[b,x]=n.useState(u),[S,C]=n.useState(!1),[w,T]=n.useState(!1),E=n.useMemo(()=>{if(!v.trim())return b;let e=v.toLowerCase();return b.filter(t=>t.label.toLowerCase().includes(e)||t.description?.toLowerCase().includes(e))},[v,b]),D=n.useCallback(async e=>{if(y(e),c&&e.trim().length>=2){T(!0);try{let t=await c(e);x(t)}finally{T(!1)}}},[c]),O=n.useCallback((e,t)=>{_(n=>({...n,[e]:t}))},[]),k=n.useCallback(async()=>{if(o){C(!0);try{await o({...g,[t]:!0}),_({}),p(!1)}finally{C(!1)}}},[o,g,t]),A=n.useCallback(async e=>{if(s){C(!0);try{await s(e),y(``),p(!1)}finally{C(!1)}}},[s]),j=n.useMemo(()=>a.filter(e=>e.required).every(e=>g[e.name]?.toString().trim()),[a,g]);return f?(0,l.jsxs)(r.Card,{className:(0,r.cn)(``,d),children:[(0,l.jsx)(r.CardHeader,{className:`pb-3`,children:(0,l.jsxs)(r.CardTitle,{className:`flex items-center justify-between text-sm`,children:[(0,l.jsxs)(`span`,{children:[m===`create`?`Create`:`Link`,` `,e]}),(0,l.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-6 w-6`,onClick:()=>p(!1),children:(0,l.jsx)(i.X,{className:`h-3.5 w-3.5`})})]})}),(0,l.jsx)(r.CardContent,{children:(0,l.jsxs)(r.Tabs,{value:m,onValueChange:h,children:[(0,l.jsxs)(r.TabsList,{className:`mb-3 w-full`,children:[o&&(0,l.jsxs)(r.TabsTrigger,{value:`create`,className:`flex-1 gap-1.5`,children:[(0,l.jsx)(i.Plus,{className:`h-3.5 w-3.5`}),`Create New`]}),s&&(0,l.jsxs)(r.TabsTrigger,{value:`link`,className:`flex-1 gap-1.5`,children:[(0,l.jsx)(i.Link,{className:`h-3.5 w-3.5`}),`Link Existing`]})]}),o&&(0,l.jsxs)(r.TabsContent,{value:`create`,className:`space-y-3 mt-0`,children:[a.map(e=>(0,l.jsxs)(`div`,{children:[(0,l.jsxs)(`label`,{className:`text-xs font-medium text-muted-foreground mb-1 block`,children:[e.label,e.required&&(0,l.jsx)(`span`,{className:`text-destructive ml-0.5`,children:`*`})]}),(0,l.jsx)(r.Input,{type:e.type===`number`?`number`:e.type===`date`?`date`:`text`,placeholder:e.placeholder||`Enter ${e.label.toLowerCase()}`,value:g[e.name]||``,onChange:t=>O(e.name,t.target.value),className:`h-8 text-sm`})]},e.name)),(0,l.jsxs)(`div`,{className:`flex justify-end gap-2 pt-1`,children:[(0,l.jsx)(r.Button,{variant:`ghost`,size:`sm`,onClick:()=>p(!1),children:`Cancel`}),(0,l.jsxs)(r.Button,{size:`sm`,onClick:k,disabled:!j||S,className:`gap-1.5`,children:[S&&(0,l.jsx)(i.Loader2,{className:`h-3.5 w-3.5 animate-spin`}),`Create`]})]})]}),s&&(0,l.jsxs)(r.TabsContent,{value:`link`,className:`space-y-3 mt-0`,children:[(0,l.jsxs)(`div`,{className:`relative`,children:[(0,l.jsx)(i.Search,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,l.jsx)(r.Input,{placeholder:`Search ${e}…`,value:v,onChange:e=>D(e.target.value),className:`h-8 text-sm pl-8`})]}),(0,l.jsx)(`div`,{className:`max-h-48 overflow-y-auto space-y-1`,children:w?(0,l.jsxs)(`div`,{className:`flex items-center justify-center py-4 text-sm text-muted-foreground`,children:[(0,l.jsx)(i.Loader2,{className:`h-4 w-4 animate-spin mr-2`}),`Searching…`]}):E.length===0?(0,l.jsx)(`p`,{className:`text-sm text-muted-foreground text-center py-4`,children:v?`No records found`:`Type to search records`}):E.map(e=>(0,l.jsxs)(`button`,{type:`button`,className:`w-full text-left px-3 py-2 rounded-md hover:bg-accent text-sm transition-colors`,onClick:()=>A(e.id),disabled:S,children:[(0,l.jsx)(`span`,{className:`font-medium`,children:e.label}),e.description&&(0,l.jsx)(`span`,{className:`block text-xs text-muted-foreground mt-0.5`,children:e.description})]},e.id))})]})]})})]}):(0,l.jsxs)(`div`,{className:(0,r.cn)(`flex gap-2`,d),children:[o&&(0,l.jsxs)(r.Button,{variant:`outline`,size:`sm`,onClick:()=>{h(`create`),p(!0)},className:`gap-1.5`,children:[(0,l.jsx)(i.Plus,{className:`h-3.5 w-3.5`}),`New `,e]}),s&&(0,l.jsxs)(r.Button,{variant:`outline`,size:`sm`,onClick:()=>{h(`link`),p(!0)},className:`gap-1.5`,children:[(0,l.jsx)(i.Link,{className:`h-3.5 w-3.5`}),`Link Existing`]})]})};function kt(e,t){if(e==null)return[`(empty)`];switch(t){case`json`:try{let t=typeof e==`string`?JSON.parse(e):e;return JSON.stringify(t,null,2).split(`
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@object-ui/core"),require("@object-ui/fields"),require("react"),require("@object-ui/components"),require("lucide-react"),require("@object-ui/react"),require("@object-ui/i18n"),require("react-router-dom"),require("react/jsx-runtime"),require("@object-ui/permissions"),require("@object-ui/types"),require("@objectstack/spec/data")):typeof define==`function`&&define.amd?define([`exports`,`@object-ui/core`,`@object-ui/fields`,`react`,`@object-ui/components`,`lucide-react`,`@object-ui/react`,`@object-ui/i18n`,`react-router-dom`,`react/jsx-runtime`,`@object-ui/permissions`,`@object-ui/types`,`@objectstack/spec/data`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ObjectUIPluginDetail={},e.ObjectUICore,e.ObjectUIFields,e.React,e.ObjectUIComponents,e.LucideReact,e.ObjectUIReact,e._object_ui_i18n,e.react_router_dom,e.jsxRuntime,e._object_ui_permissions,e.ObjectUITypes,e._objectstack_spec_data))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d,f){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var p=Object.create,m=Object.defineProperty,h=Object.getOwnPropertyDescriptor,g=Object.getOwnPropertyNames,_=Object.getPrototypeOf,v=Object.prototype.hasOwnProperty,y=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=g(t),a=0,o=i.length,s;a<o;a++)s=i[a],!v.call(e,s)&&s!==n&&m(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=h(t,s))||r.enumerable});return e};r=((e,t,n)=>(n=e==null?{}:p(_(e)),y(t||!e||!e.__esModule||!v.call(e,`default`)?m(n,`default`,{value:e,enumerable:!0}):n,e)))(r,1);var b=new Set([`textarea`,`markdown`,`html`,`grid`,`rich-text`,`field:textarea`,`field:markdown`,`field:html`,`field:grid`,`field:rich-text`]);function x(e){return b.has(e)}function S(e,t){let n;return n=e<=3?1:e<=8?2:e<=15?3:4,t!==void 0&&t<640?Math.min(n,1):n}function C(e,t){return t<=1?e:e.map(e=>e.span===void 0&&e.type&&x(e.type)?{...e,span:t}:e)}function w(e,t,n){if(t!==void 0)return{fields:C(e,t),columns:t};let r=S(e.length,n);return{fields:C(e,r),columns:r}}var T=s.createSafeTranslation,E={"common.resizeDrawer":`Resize drawer`,"detail.back":`Back`,"detail.edit":`Edit`,"detail.editInline":`Edit`,"detail.save":`Save`,"detail.saveChanges":`Save changes`,"detail.editFieldsInline":`Edit fields inline`,"detail.editInlineHint":`Double-click to edit`,"detail.cancel":`Cancel`,"detail.cancelEdit":`Discard changes`,"detail.openInNewTab":`Open in new tab`,"detail.share":`Share`,"detail.duplicate":`Duplicate`,"detail.export":`Export`,"detail.viewHistory":`View history`,"detail.delete":`Delete`,"detail.moreActions":`More actions`,"detail.addReaction":`Add reaction`,"detail.emojiPicker":`Emoji picker`,"detail.reactionCount":`{{emoji}} {{count}} reactions`,"detail.reactionCountOne":`{{emoji}} {{count}} reaction`,"detail.addToFavorites":`Add to favorites`,"detail.removeFromFavorites":`Remove from favorites`,"detail.previousRecord":`Previous record`,"detail.nextRecord":`Next record`,"detail.recordOf":`{{current}} of {{total}}`,"detail.recordNotFound":`Record not found`,"detail.recordNotFoundDescription":`The record you are looking for does not exist or may have been deleted.`,"detail.goBack":`Go back`,"detail.details":`Details`,"detail.related":`Related`,"detail.relatedRecords":`{{count}} records`,"detail.relatedRecordOne":`{{count}} record`,"detail.noRelatedRecords":`No related records found`,"detail.loading":`Loading...`,"detail.copyToClipboard":`Copy to clipboard`,"detail.copied":`Copied!`,"detail.deleteConfirmation":`Are you sure you want to delete this record?`,"detail.editRecord":`Edit record`,"detail.viewAll":`View All`,"detail.new":`New`,"detail.emptyValue":`—`,"detail.noValue":`No value`,"detail.activity":`Activity`,"detail.copyRecordId":`Copy record ID`,"detail.showEmptyFields":`Show {{count}} empty fields`,"detail.hideEmptyFields":`Hide empty fields`,"detail.editRow":`Edit`,"detail.deleteRow":`Delete`,"detail.deleteRowConfirmation":`Are you sure you want to delete this record?`,"detail.actions":`Actions`,"detail.previousPage":`Previous`,"detail.nextPage":`Next`,"detail.pageOf":`Page {{current}} of {{total}}`,"detail.sortBy":`Sort by`,"detail.filterPlaceholder":`Filter...`,"detail.highlightFields":`Key Fields`,"detail.comments":`Comments`,"detail.searchComments":`Search comments…`,"detail.addCommentPlaceholder":`Add a comment… (Ctrl+Enter to submit)`,"detail.noMatchingComments":`No matching comments`,"detail.noCommentsYet":`No comments yet`,"detail.pinned":`Pinned`,"detail.pin":`Pin`,"detail.unpin":`Unpin`,"detail.justNow":`just now`,"detail.minutesAgo":`{{count}}m ago`,"detail.hoursAgo":`{{count}}h ago`,"detail.daysAgo":`{{count}}d ago`,"detail.createdBy":`Created by`,"detail.updatedBy":`Updated by`,"detail.created":`Created`,"detail.updated":`Updated`,"detail.dropFilesToUpload":`Drop files here or click to upload`,"detail.attachmentCount":`{{count}} attachment`,"detail.attachmentCountPlural":`{{count}} attachments`,"detail.removeAttachment":`Remove attachment`,"detail.unifiedDiff":`Unified diff`,"detail.sideBySideDiff":`Side-by-side diff`,"detail.noChanges":`No changes`,"detail.previousVersion":`Previous`,"detail.currentVersion":`Current`,"detail.discussion":`Discussion`,"detail.showDiscussion":`Show Discussion ({{count}})`,"detail.hideDiscussion":`Hide discussion`,"detail.bold":`Bold (Ctrl+B)`,"detail.italic":`Italic (Ctrl+I)`,"detail.listFormat":`List`,"detail.inlineCode":`Inline code`,"detail.mentionSomeone":`Mention someone`,"detail.preview":`Preview`,"detail.submitComment":`Submit (Ctrl+Enter)`,"detail.sendComment":`Send`,"detail.writeComment":`Write a comment…`,"detail.subscribedTooltip":`Subscribed — click to unsubscribe`,"detail.unsubscribedTooltip":`Subscribe to notifications`,"detail.firstRecord":`First record (Home)`,"detail.previousRecordKey":`Previous record (←)`,"detail.nextRecordKey":`Next record (→)`,"detail.lastRecord":`Last record (End)`,"detail.noRecords":`No records`,"detail.showEmptyRelated_one":`+ {{count}} empty`,"detail.showEmptyRelated_other":`+ {{count}} empty`,"detail.searchWhileNavigating":`Search while navigating`,"detail.searchRecords":`Search records…`,"detail.allActivity":`All Activity`,"detail.commentsOnly":`Comments Only`,"detail.fieldChangesFilter":`Field Changes`,"detail.tasksOnly":`Tasks Only`,"detail.leaveCommentPlaceholder":`Leave a comment… (Ctrl+Enter to submit)`,"detail.noActivity":`No activity recorded`,"detail.loadMore":`Load more`,"detail.edited":`(edited)`,"detail.via":`via {{source}}`,"detail.viewSource":`View source`,"detail.replyCount":`{{count}} reply`,"detail.replyCountPlural":`{{count}} replies`,"detail.replyPlaceholder":`Reply…`,"detail.filterActivity":`Filter activity`,"detail.openDiscussion":`Open discussion panel`,"detail.closeDiscussion":`Close discussion panel`,"detail.subscribeAriaLabel":`Subscribe to notifications`,"detail.unsubscribeAriaLabel":`Unsubscribe from notifications`,"detail.clearSearch":`Clear search`,"detail.concurrentUpdateTitle":`This record was modified by someone else`,"detail.concurrentUpdateDescription":`Another user saved a newer version of {{field}} while you were editing. To prevent silently overwriting their change, please choose how to resolve the conflict.`,"detail.concurrentUpdateYourEdit":`Your edit`,"detail.concurrentUpdateCurrentValue":`Current value`,"detail.concurrentUpdateUpdatedBy":`Updated by {{name}}`,"detail.concurrentUpdateUpdatedAt":`Updated at {{when}}`,"detail.concurrentUpdateReload":`Reload latest`,"detail.concurrentUpdateOverwrite":`Overwrite anyway`,"detail.concurrentUpdateCancel":`Cancel`,"detail.lockedByApproval":`Locked for approval`,"detail.lockedTooltip":`This record has a pending approval request; editing is locked`,"detail.approvalPendingEditable":`In approval · editable`,"detail.approvalPendingTooltip":`This record has a pending approval request; this step still allows editing`,"detail.approvalProgress":`Approvals — {{got}} of {{need}}`,"detail.approvalProgressGroups":`Sign-off — {{got}} of {{need}} groups`,"detail.approvalProgressLabel":`Approval progress`,"detail.cancelApproval":`Recall approval`,"detail.cancelApprovalInFlight":`Recalling…`,"detail.cancelApprovalTooltip":`Recall the pending approval request to unlock this record`,"detail.cancelApprovalTooltipUnlocked":`Recall the pending approval request`,"detail.cancelApprovalFailed":`Failed to recall approval`,"detail.cancelApprovalUnavailable":`Recalling approvals is not supported on this data source`},D=T(E,`detail.back`);function O(e){if(typeof e==`string`){let t=e.trim();if(!t)return null;try{return JSON.parse(t)}catch{return t}}return e??null}function k(e){let t=O(e);return t==null||t===``?0:Array.isArray(t)?t.length:typeof t==`object`?Object.keys(t).length:1}function A({value:e,field:t}){let{t:r}=D(),a=(0,o.useRecordContext)(),{appName:s}=(0,c.useParams)(),u=t?.name||``,d=a?.data?.name,f=s&&d?`/apps/${s}/metadata/permission/${encodeURIComponent(String(d))}`:null,p=k(e),m=p===0,h=(()=>{if(m)return(0,l.jsx)(`span`,{className:`text-muted-foreground`,children:r(`perm.facet.none`,{defaultValue:`None`})});if(u===`system_permissions`){let t=(0,n.parseCapabilityNames)(e),a=t.slice(0,6),o=t.length-a.length;return(0,l.jsxs)(`span`,{className:`inline-flex flex-wrap items-center gap-1`,children:[a.map(e=>(0,l.jsx)(i.Badge,{variant:`outline`,children:e},e)),o>0&&(0,l.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:r(`perm.facet.more`,{count:o,defaultValue:`+${o} more`})})]})}let t=(()=>{switch(u){case`object_permissions`:return r(`perm.facet.objects`,{count:p,defaultValue:`${p} object${p===1?``:`s`}`});case`field_permissions`:return r(`perm.facet.fields`,{count:p,defaultValue:`${p} field rule${p===1?``:`s`}`});case`row_level_security`:return r(`perm.facet.rls`,{count:p,defaultValue:`${p} RLS polic${p===1?`y`:`ies`}`});case`tab_permissions`:return r(`perm.facet.tabs`,{count:p,defaultValue:`${p} tab rule${p===1?``:`s`}`});case`admin_scope`:return r(`perm.facet.adminScope`,{defaultValue:`Delegated admin configured`});default:return String(p)}})();return(0,l.jsx)(`span`,{className:`text-foreground`,children:t})})();return(0,l.jsxs)(`span`,{className:`inline-flex flex-wrap items-center gap-x-2 gap-y-1 text-sm`,children:[h,f?(0,l.jsx)(c.Link,{to:f,className:`text-primary hover:underline whitespace-nowrap`,children:r(`perm.facet.designInStudio`,{defaultValue:`Design in Studio →`})}):(0,l.jsx)(`span`,{className:`text-muted-foreground/60 whitespace-nowrap`,children:r(`perm.facet.designInStudioHint`,{defaultValue:`Design in Studio`})})]})}var j=new Set([`id`,`_id`,`__v`,`created`,`created_at`,`createdAt`,`created_by`,`modified`,`modified_by`,`updated_at`,`updatedAt`,`updated_by`,`deleted_at`,`is_deleted`,`deleted`,`instance_state`]),M=new Set([`formula`,`summary`,`rollup`,`auto_number`]);function N(e,t){return M.has(e)||M.has(t)}var P=`options.currency.currencyConfig.precision.scale.min.max.step.format.widget.dueLike.multiple.reference_field.display_field.displayField.description_field.descriptionField.id_field.allow_create.allowCreate.lookup_columns.lookupColumns.lookup_page_size.lookupPageSize.lookup_filters.lookupFilters.picker.subtitle.avatar_field.avatarField.depends_on.dependsOn`.split(`.`);function F(e,t){let n={...e};if(!t)return n;!n.type&&t.type&&(n.type=t.type);for(let e of P){let r=t[e];r!==void 0&&n[e]===void 0&&(n[e]=r)}let r=t.reference_to||t.reference;return r&&n.reference_to===void 0&&(n.reference_to=r),n}function I(e){if(e==null)return e;if(Array.isArray(e))return e.map(I);if(typeof e==`object`){let t=e;return t.id??t._id??t.value??``}return e}var ee=({field:e,value:t,onChange:r,dataSource:i,autoFocus:a})=>{let o=e.type,s=e.widget;if(s===`permission-facet-link`)return(0,l.jsx)(A,{value:t,field:e});if(s===`capability-multiselect`)return(0,l.jsx)(n.CapabilityMultiSelectField,{value:t,onChange:e=>r(e),field:e,dataSource:i});let c=o===`multiselect`||!!e.multiple;if((o===`select`||o===`multiselect`)&&Array.isArray(e.options)&&e.options.length>0)return c?(0,l.jsx)(n.SelectField,{field:{...e,multiple:!0},value:Array.isArray(t)?t:t==null||t===``?[]:[t],onChange:e=>r(e)}):(0,l.jsx)(n.SelectField,{field:e,value:t==null?``:String(t),onChange:e=>r(e)});if(o===`boolean`)return(0,l.jsx)(n.BooleanField,{field:e,value:!!t,onChange:e=>r(e)});if(o===`image`)return(0,l.jsx)(n.ImageField,{field:e,value:t,onChange:e=>r(e)});if(o===`avatar`)return(0,l.jsx)(n.AvatarField,{field:e,value:t,onChange:e=>r(e)});if(o===`signature`)return(0,l.jsx)(n.SignatureField,{field:e,value:t,onChange:e=>r(e)});if(o===`file`||o===`video`||o===`audio`)return(0,l.jsx)(n.FileField,{field:e,value:t,onChange:e=>r(e)});let u=o===`user`||o===`owner`,d=o===`lookup`||o===`master_detail`||o===`tree`||!!e.reference_to&&!M.has(o);if(u||d)return(0,l.jsx)(u?n.UserField:n.LookupField,{field:e,value:t,onChange:e=>r(e),dataSource:i});if(o===`number`)return(0,l.jsx)(n.NumberField,{field:e,value:t,onChange:e=>r(e),autoFocus:a});if(o===`currency`)return(0,l.jsx)(n.CurrencyField,{field:e,value:t,onChange:e=>r(e),autoFocus:a});if(o===`percent`)return(0,l.jsx)(n.PercentField,{field:e,value:t,onChange:e=>r(e),autoFocus:a});let f=o===`date`||o===`datetime`,p=f?`date`:`text`,m=t==null?``:f?(()=>{let e=String(t);if(/^\d{4}-\d{2}-\d{2}/.test(e))return e.slice(0,10);let n=new Date(e);return isNaN(n.getTime())?``:n.toLocaleDateString(`en-CA`)})():String(typeof t==`object`?(0,n.coerceToSafeValue)(t)??``:t);return(0,l.jsx)(`input`,{type:p,autoFocus:a,className:`w-full px-2 py-1.5 text-sm border rounded-md bg-background focus:outline-none focus:ring-2 focus:ring-ring`,value:m,onChange:e=>{let t=e.target.value;r(f&&t?new Date(t+`T00:00:00`).toISOString():t)}})},L=({name:e})=>/^[a-z0-9][a-z0-9-]*$/i.test(e)?(0,l.jsx)(i.LazyIcon,{name:e,className:`h-4 w-4 shrink-0 text-muted-foreground`,"aria-hidden":!0}):(0,l.jsx)(`span`,{className:`text-muted-foreground`,children:e});function te(e,t){return!e||e<=1||t<=1?``:t===2?e>=2?`md:col-span-2`:``:t===3?e===2?`md:col-span-2`:e>=3?`md:col-span-2 lg:col-span-3`:``:e===2?`md:col-span-2`:e===3?`md:col-span-2 lg:col-span-3`:e>=4?`md:col-span-2 lg:col-span-3 xl:col-span-4`:``}var R=({section:e,data:t,className:s,objectSchema:c,objectName:u,isEditing:d=!1,onFieldChange:f,onEnterInlineEdit:p,autoFocusField:m,dataSource:h,virtualScroll:g})=>{let[_,v]=r.useState(e.defaultCollapsed??!1),[y,b]=r.useState(null),[x,S]=r.useState(void 0),[C,T]=r.useState(!1),{t:E}=D(),{fieldLabel:O,translateOptions:k}=(0,o.useSafeFieldLabel)(),M=r.useCallback((e,t)=>{let n=t==null?``:String(t);navigator.clipboard.writeText(n).then(()=>{b(e),setTimeout(()=>b(null),2e3)})},[]),P=r.useCallback(e=>{let n=t?.[e.name]??e.value;return n==null||n===``},[t]),I=r.useMemo(()=>e.fields.filter(P).length,[e.fields,P]),R=(0,i.useIsMobile)(),ne=R?3:4,z=R?.2:.25,re=e.fields.length-I,ie=!e.hideEmpty&&!d&&e.fields.length>=ne&&I/e.fields.length>=z&&re>0,ae=!C&&(e.hideEmpty||ie)?e.fields.filter(e=>!P(e)):e.fields,{fields:B,columns:V}=w(ae,e.columns),H=Math.min(V,Math.max(1,ae.length)),U=e=>{let r=t?.[e.name]??e.value;if(e.render)return(0,l.jsx)(o.SchemaRenderer,{schema:e.render,data:{...t,value:r}});let s=te(e.span,H),g=c?.fields?.[e.name],_=F(e,g);u&&Array.isArray(_.options)&&_.options.length>0&&(_.options=k(u,e.name,_.options));let v=N(e.type,g?.type),b=e.readonly===!0||g?.readonly===!0,x=j.has(e.name),S=!b&&!v&&!x,C=S&&!!p,w=(()=>{if((_.widget||e.widget)===`permission-facet-link`)return(0,l.jsx)(A,{value:r,field:_});if(r==null||r===``)return(0,l.jsx)(`span`,{className:`text-muted-foreground/60 text-sm select-none`,"aria-label":E(`detail.noValue`,{defaultValue:`No value`}),title:E(`detail.noValue`,{defaultValue:`No value`}),children:`—`});let t=(0,n.resolveCellRendererType)(_)||e.type;if(t){let e=(0,n.getCellRenderer)(t);if(e)return(0,l.jsx)(e,{value:r,field:_})}return String(r)})(),T=r!=null&&r!==``,D=T&&!C,P=y===e.name,I=O(u||``,e.name,e.label||e.name);return R&&!(d&&S)?(0,l.jsxs)(`div`,{className:(0,i.cn)(`flex items-baseline justify-between gap-4 py-2.5 min-h-[44px] group`,T&&`cursor-pointer active:bg-muted/40 transition-colors`),onClick:T?()=>M(e.name,r):void 0,onKeyDown:T?t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),M(e.name,r))}:void 0,role:T?`button`:void 0,tabIndex:T?0:void 0,children:[(0,l.jsx)(`span`,{className:`text-[15px] text-muted-foreground shrink-0`,children:I}),(0,l.jsx)(`span`,{className:`text-[15px] text-foreground text-right break-words min-w-0 leading-snug`,children:w})]},e.name):(0,l.jsxs)(`div`,{className:(0,i.cn)(`space-y-1.5 group min-w-0`,s),children:[(0,l.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:O(u||``,e.name,e.label||e.name)}),d&&S?(0,l.jsx)(`div`,{className:`min-h-[44px] sm:min-h-0`,children:(0,l.jsx)(ee,{field:_,value:r,onChange:t=>f?.(e.name,t),dataSource:h,autoFocus:m===e.name})}):(0,l.jsxs)(`div`,{className:(0,i.cn)(`flex items-start justify-between gap-2 min-h-[44px] sm:min-h-0 rounded-md`,D&&`cursor-pointer active:bg-muted/60 transition-colors`,C&&`cursor-pointer hover:bg-muted/40 transition-colors -mx-1.5 px-1.5`),onClick:D?()=>M(e.name,r):void 0,onDoubleClick:C?()=>p?.(e.name):void 0,onKeyDown:D?t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),M(e.name,r))}:void 0,role:D?`button`:void 0,tabIndex:D?0:void 0,title:C?E(`detail.editInlineHint`):void 0,children:[(0,l.jsx)(`div`,{className:`text-sm flex-1 min-w-0 break-words py-1`,children:w}),C?(0,l.jsx)(i.TooltipProvider,{children:(0,l.jsxs)(i.Tooltip,{children:[(0,l.jsx)(i.TooltipTrigger,{asChild:!0,children:(0,l.jsx)(i.Button,{variant:`ghost`,size:`icon`,className:`h-6 w-6 opacity-0 group-hover:opacity-100 transition-opacity shrink-0`,"aria-label":E(`detail.editInlineHint`),onClick:t=>{t.stopPropagation(),p?.(e.name)},children:(0,l.jsx)(a.Pencil,{className:`h-3 w-3`})})}),(0,l.jsx)(i.TooltipContent,{children:E(`detail.editInlineHint`)})]})}):T?(0,l.jsx)(i.TooltipProvider,{children:(0,l.jsxs)(i.Tooltip,{children:[(0,l.jsx)(i.TooltipTrigger,{asChild:!0,children:(0,l.jsx)(i.Button,{variant:`ghost`,size:`icon`,className:`h-6 w-6 opacity-0 group-hover:opacity-100 transition-opacity shrink-0`,onClick:t=>{t.stopPropagation(),M(e.name,r)},children:P?(0,l.jsx)(a.Check,{className:`h-3 w-3 text-green-600`}):(0,l.jsx)(a.Copy,{className:`h-3 w-3`})})}),(0,l.jsx)(i.TooltipContent,{children:E(P?`detail.copied`:`detail.copyToClipboard`)})]})}):null]})]},e.name)},W=g?.enabled===!0,oe=g?.batchSize??20;if(r.useEffect(()=>{if(!W){S(void 0);return}if(B.length<=oe){S(void 0);return}S(oe);let e=setTimeout(()=>S(void 0),100);return()=>clearTimeout(e)},[W,B.length,oe]),ae.length===0&&I===e.fields.length)return null;let G=x===void 0?B:B.slice(0,x),se=I>0&&(e.hideEmpty||ie),K=(0,l.jsxs)(l.Fragment,{children:[R?(0,l.jsx)(`div`,{className:`flex flex-col divide-y divide-border/60`,children:G.map(U)}):(0,l.jsx)(`div`,{className:(0,i.cn)(`grid gap-3 sm:gap-4`,H===1?`grid-cols-1`:H===2?`grid-cols-1 md:grid-cols-2`:H===3?`grid-cols-1 md:grid-cols-2 lg:grid-cols-3`:`grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4`),children:G.map(U)}),se&&(0,l.jsx)(`div`,{className:`mt-3 -ml-2`,children:(0,l.jsxs)(i.Button,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>T(e=>!e),className:`h-7 px-2 text-xs text-muted-foreground hover:text-foreground`,children:[C?(0,l.jsx)(a.EyeOff,{className:`h-3.5 w-3.5 mr-1.5`}):(0,l.jsx)(a.Eye,{className:`h-3.5 w-3.5 mr-1.5`}),C?E(`detail.hideEmptyFields`,{defaultValue:`Hide empty fields`}):E(`detail.showEmptyFields`,{count:I,defaultValue:`Show ${I} empty field${I===1?``:`s`}`})]})})]});return!e.title&&!e.collapsible&&e.showBorder===!1?(0,l.jsx)(`div`,{className:(0,i.cn)(s),children:K}):e.collapsible?(0,l.jsx)(i.Collapsible,{open:!_,onOpenChange:e=>v(!e),className:s,children:(0,l.jsxs)(i.Card,{children:[(0,l.jsx)(i.CollapsibleTrigger,{asChild:!0,children:(0,l.jsxs)(i.CardHeader,{className:(0,i.cn)(`py-3 px-4 sm:py-4 sm:px-6 cursor-pointer hover:bg-muted/50 transition-colors`,e.headerColor&&`bg-${e.headerColor}`),children:[(0,l.jsxs)(i.CardTitle,{className:`flex items-center justify-between text-base font-semibold tracking-tight`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.icon&&(0,l.jsx)(L,{name:e.icon}),(0,l.jsx)(`span`,{children:e.title})]}),(0,l.jsx)(`div`,{className:`flex items-center gap-2`,children:_?(0,l.jsx)(a.ChevronRight,{className:`h-4 w-4 text-muted-foreground`}):(0,l.jsx)(a.ChevronDown,{className:`h-4 w-4 text-muted-foreground`})})]}),e.description&&!_&&(0,l.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:e.description})]})}),(0,l.jsx)(i.CollapsibleContent,{children:(0,l.jsx)(i.CardContent,{className:`pt-3 sm:pt-4 px-3 sm:px-6 pb-4 sm:pb-5`,children:K})})]})}):(0,l.jsxs)(i.Card,{className:(0,i.cn)(e.showBorder===!1?`border-none shadow-none`:``,s),children:[e.title&&(0,l.jsxs)(i.CardHeader,{className:(0,i.cn)(`py-3 px-4 sm:py-4 sm:px-6`,e.headerColor&&`bg-${e.headerColor}`),children:[(0,l.jsx)(i.CardTitle,{className:`flex items-center justify-between text-base font-semibold tracking-tight`,children:(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.icon&&(0,l.jsx)(L,{name:e.icon}),(0,l.jsx)(`span`,{children:e.title})]})}),e.description&&(0,l.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:e.description})]}),(0,l.jsx)(i.CardContent,{className:`pt-3 sm:pt-4 px-3 sm:px-6 pb-4 sm:pb-5`,children:K})]})},ne=({tabs:e,data:t,className:n})=>{let[a,s]=r.useState(e[0]?.key),c=e.filter(e=>typeof e.visible==`boolean`?e.visible:(e.visible,!0));return(0,l.jsxs)(i.Tabs,{value:a,onValueChange:s,className:n,children:[(0,l.jsx)(i.TabsList,{className:`w-full justify-start border-b rounded-none bg-transparent p-0`,children:c.map(e=>(0,l.jsx)(i.TabsTrigger,{value:e.key,className:`relative rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent`,children:(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.icon&&(0,l.jsx)(`span`,{children:e.icon}),(0,l.jsx)(`span`,{children:e.label}),e.badge&&(0,l.jsx)(i.Badge,{variant:`secondary`,className:`ml-1`,children:e.badge})]})},e.key))}),c.map(e=>(0,l.jsx)(i.TabsContent,{value:e.key,className:`mt-4 motion-safe:data-[state=active]:animate-in motion-safe:data-[state=active]:fade-in-0 motion-safe:duration-150`,children:(0,l.jsx)(r.Suspense,{fallback:null,children:Array.isArray(e.content)?(0,l.jsx)(`div`,{className:`space-y-4`,children:e.content.map((e,n)=>(0,l.jsx)(o.SchemaRenderer,{schema:e,data:t},n))}):(0,l.jsx)(o.SchemaRenderer,{schema:e.content,data:t})})},e.key))]})};function z(e){if(!e)return a.Inbox;let t=e.split(/[-_\s]/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``);return a.icons[t]||a.Inbox}function re(e,n){let r=e?.id??e?._id;if(n){let i=(0,t.getRecordDisplayName)(n,e),a=i===`Untitled`||r!=null&&i===`Record #${r}`;if(i&&!a)return i}return e?.full_name||e?.fullname||e?.display_name||e?.name||e?.subject||e?.title||e?.label||e?.code||e?.email||(r==null?void 0:String(r))}function ie(e){if(!e)return[];if(typeof e==`string`){let t=e.trim();return t?t.startsWith(`-`)?[{field:t.slice(1),order:`desc`}]:[{field:t,order:`asc`}]:[]}return e.filter(e=>!!e?.field)}var ae=({action:e,onToolbarAction:t})=>{let n=e.visible,r=(0,o.useCondition)((0,o.toPredicateInput)(n));if(n&&!r)return null;let a=e.icon?z(e.icon):null;return(0,l.jsxs)(i.Button,{variant:e.variant===`primary`?`default`:`outline`,size:`sm`,onClick:n=>{n.stopPropagation(),t(e)},className:`gap-1 h-9 sm:h-7 text-xs shadow-none`,"data-testid":`related-toolbar-action-${e.name}`,children:[a&&(0,l.jsx)(a,{className:`h-3.5 w-3.5`}),e.label||e.name]})},B=({title:e,type:s,api:c,data:d,schema:f,columns:p,className:m,dataSource:h,objectName:g,onNew:_,onViewAll:v,onRowEdit:y,onRowDelete:b,onRowClick:x,rowActions:S,onRowAction:C,toolbarActions:w,onToolbarAction:T,add:E,maxColumns:O=6,pageSize:k,defaultSort:A,sortable:j=!1,filterable:M=!1,collapsible:N=!1,defaultCollapsed:P=!1,referenceField:F,parentId:I,icon:ee})=>{let L=d!==void 0,te=d??[],[R,ne]=r.useState(te),[B,V]=r.useState(()=>!!c&&!L),[H,U]=r.useState(0),[W,oe]=r.useState(null),[G,se]=r.useState(`asc`),[K,ce]=r.useState(``),[le,ue]=r.useState(null),[de,fe]=r.useState(!1),[q,pe]=r.useState(null),[J,me]=r.useState(P),[he,ge]=r.useState(!1),[_e,ve]=r.useState(!1),[ye,be]=r.useState(null),[xe,Y]=r.useState(0),[Se,Ce]=r.useState({}),{t:X}=D(),{fieldLabel:we}=(0,o.useSafeFieldLabel)(),Z=k&&k>0?k:0,Te=M&&K!==``,Q=!L&&!!c&&Z>0&&!!h&&typeof h.find==`function`&&!Te,Ee=Q?H:0,De=Q?W:null,Oe=Q?G:`asc`,ke=JSON.stringify(A??null),Ae=r.useMemo(()=>ie(A),[ke]);r.useEffect(()=>{L&&ne(d??[])},[d,L]),r.useEffect(()=>{c&&h?.getObjectSchema&&h.getObjectSchema(c).then(pe).catch(e=>{console.warn(`[RelatedList] Failed to fetch schema for ${c}:`,e)})},[c,h]);let je=E?.picker?.object,[Me,Ne]=r.useState(null);r.useEffect(()=>{if(!he||!je||Me||!h?.getObjectSchema)return;let e=!1;return h.getObjectSchema(je).then(t=>{e||Ne(t)}).catch(e=>{console.warn(`[RelatedList] Failed to fetch schema for ${je}:`,e)}),()=>{e=!0}},[he,je,Me,h]);let Pe=E?.picker?.labelField||`name`,Fe=r.useMemo(()=>{let e=(0,n.deriveLookupColumns)(Me,{displayField:Pe});return e.length>0?e:void 0},[Me,Pe]);r.useEffect(()=>{let e=!1;if(c&&!L){if(!(F&&I!=null&&I!==``)){c&&(I==null||I===``)&&!F&&console.warn(`[RelatedList] "${c}" has no referenceField/parentId — refusing to fetch all rows. Pass relationshipField + parentId to scope the query.`),ne([]),ue(null),fe(!1),V(!1);return}V(!0);let t={[F]:I};if(h&&typeof h.find==`function`){let n={$filter:t};if(Q){n.$top=Z,n.$skip=Ee*Z;let e=De?[{field:De,order:Oe}]:Ae;e.length>0&&(n.$orderby=e)}h.find(c,n).then(t=>{if(e)return;let n=Array.isArray(t),r=n?t:Array.isArray(t?.data)?t.data:[];if(ne(r),Q){let e=!n&&typeof t?.total==`number`?t.total:null;ue(e),fe(!n&&typeof t?.hasMore==`boolean`?t.hasMore:r.length===Z)}else ue(null),fe(!1);V(!1)}).catch(t=>{console.error(`Failed to fetch related data:`,t),e||V(!1)})}else{let t=new URLSearchParams({[`filter[${F}]`]:String(I)}).toString();fetch(`${c}?${t}`).then(e=>e.json()).then(t=>{if(e)return;let n=Array.isArray(t)?t:t?.data||[];ne(n),ue(null),fe(!1)}).catch(e=>{console.error(`Failed to fetch related data:`,e)}).finally(()=>{e||V(!1)})}}return()=>{e=!0}},[c,L,h,F,I,xe,Q,Z,Ee,De,Oe,Ae]),r.useEffect(()=>{!Q||B||H>0&&R.length===0&&U(e=>Math.max(0,e-1))},[Q,B,R,H]),r.useEffect(()=>{U(0)},[c,F,I]),r.useEffect(()=>{if(!c||L)return;let e=e=>{let t=e.detail||{};t.objectName&&t.objectName!==c||Y(e=>e+1)};return window.addEventListener(`objectui:related-changed`,e),()=>window.removeEventListener(`objectui:related-changed`,e)},[c,L]),r.useEffect(()=>{if(!h?.find||!q?.fields||!R.length)return;let e=q.fields,t=[];for(let[n,r]of Object.entries(e)){if(!r||r.type!==`lookup`&&r.type!==`master_detail`)continue;let e=r.reference_to||r.reference;if(!e)continue;let i=new Set;for(let e of R){let t=e?.[n];t!=null&&(typeof t==`string`&&t?i.add(t):typeof t==`number`&&i.add(String(t)))}let a=Se[n]||{},o=Array.from(i).filter(e=>!(e in a));o.length>0&&t.push({fieldName:n,target:e,ids:o})}if(t.length===0)return;let n=!1;return Promise.all(t.map(({fieldName:e,target:t,ids:n})=>Promise.all([h.find(t,{$filter:{id:{$in:n}},$top:n.length}),typeof h.getObjectSchema==`function`?h.getObjectSchema(t).catch(()=>void 0):Promise.resolve(void 0)]).then(([t,n])=>{let r=Array.isArray(t)?t:t?.data||[],i={};for(let e of r){let t=e?.id||e?._id;t&&(i[String(t)]=re(e,n)??String(t))}return{fieldName:e,map:i}}).catch(t=>(console.warn(`[RelatedList] Failed to resolve lookups for ${e}:`,t),{fieldName:e,map:{}})))).then(e=>{n||Ce(t=>{let n={...t};for(let{fieldName:t,map:r}of e)n[t]={...n[t]||{},...r};return n})}),()=>{n=!0}},[h,q,R]);let Ie=r.useMemo(()=>{if(Q||!K)return R;let e=K.toLowerCase();return R.filter(t=>Object.values(t).some(t=>t!=null&&String(t).toLowerCase().includes(e)))},[R,K,Q]),Le=r.useMemo(()=>{if(Q||!W)return Ie;let e=Se[W],n=Ie.map(n=>({row:n,key:(0,t.getSortValue)(n[W],{labels:e})}));return n.sort((e,n)=>{let r=(0,t.compareSortValues)(e.key,n.key);return G===`asc`?r:-r}),n.map(e=>e.row)},[Ie,W,G,Q,Se]),Re=Z&&!Q?Le.slice(H*Z,(H+1)*Z):Le,ze=Z?Q?le==null?H+(de?2:1):Math.max(1,Math.ceil(le/Z)):Math.max(1,Math.ceil(Le.length/Z)):1,Be=Q?le==null?de:(H+1)*Z<le:H<ze-1,Ve=Z>0&&(Q?H>0||Be:Le.length>Z);r.useEffect(()=>{U(0)},[K,W,G]);let He=r.useCallback(e=>{U(0),W===e?se(e=>e===`asc`?`desc`:`asc`):(oe(e),se(`asc`))},[W]),Ue=r.useMemo(()=>W?[{field:W,order:G}]:Ae,[W,G,Ae]),We=r.useCallback(e=>{let t=e[0];t&&(U(0),oe(t.field),se(t.order))},[]),[Ge,Ke]=r.useState(null),qe=r.useCallback(e=>{Ke(e)},[]),Je=r.useCallback(async()=>{if(Ge)try{await b?.(Ge),Y(e=>e+1)}catch(e){console.error(`[RelatedList] remove failed`,e)}Ke(null)},[Ge,b]),Ye=r.useCallback(async e=>{if(!E||!h||!c||F==null||I==null)return;let t=E.picker.valueField||`id`;ve(!0),be(null);try{for(let n of e||[]){let e=n?.[t]??n?.id;e!=null&&(E.linkField?await h.create?.(c,{[F]:I,[E.linkField]:e}):await h.update?.(E.picker.object,String(e),{[F]:I}))}Y(e=>e+1)}catch(e){let t=e?.body?.error??e?.error??e?.message??String(e);be(typeof t==`string`?t:`Failed to add`)}finally{ve(!1),ge(!1)}},[E,h,c,F,I]),Xe=(0,u.usePermissions)(),$=r.useMemo(()=>{let e=g||c||``,i=n=>!Xe?.isLoaded||!e?n:n.filter(n=>{let r=n?.accessorKey||(0,t.columnIdentity)(n);return!r||Xe.checkField(e,String(r),`read`)}),a=e=>F?e.filter(e=>(e?.accessorKey||(0,t.columnIdentity)(e))!==F):e,o=e=>e==null||typeof e==`string`&&e.trim()===``||Array.isArray(e)&&e.length===0,s=e=>R.length?e.filter(e=>{let n=e?.accessorKey||(0,t.columnIdentity)(e);return!n||R.some(e=>!o(e?.[n]))}):e,l=(e,t)=>{if(!t?.type)return;let i=(0,n.resolveCellRendererType)({type:t.type,format:t.format})||t.type,a=(0,n.getCellRenderer)(i);if(!a)return;let o=t.type===`lookup`||t.type===`master_detail`?Se[e]:void 0,s=o&&Object.keys(o).length>0?Object.entries(o).map(([e,t])=>({value:e,label:t})):void 0,c={name:e,label:t.label||e,type:t.type,...(s||t.options)&&{options:s||t.options},...t.currency&&{currency:t.currency},...t.precision!==void 0&&{precision:t.precision},...t.scale!==void 0&&{scale:t.scale},...t.format&&{format:t.format},...(t.reference_to||t.reference)&&{reference_to:t.reference_to||t.reference},...t.reference_field&&{reference_field:t.reference_field}};return e=>e==null?r.createElement(`span`,{className:`text-muted-foreground/50 text-xs italic`},`—`):r.createElement(a,{value:e,field:c})},u=n=>{if(typeof n!=`string`){let e=n?.accessorKey||(0,t.columnIdentity)(n);if(n&&!n.cell&&!n.render&&e){let t=q?.fields?.[e],r=t?l(String(e),t):void 0;if(r)return{...n,cell:r}}return n}let r=q?.fields?.[n],i={accessorKey:n,header:r?.label||we(e,n,r)||n,fieldDef:r,fieldType:r?.type},a=r?l(n,r):void 0;return a&&(i.cell=a),i};if(p&&p.length>0)return s(i(a(p.map(u))));if(!q?.fields)return[];let d=Array.isArray(q.highlightFields)?q.highlightFields.filter(e=>typeof e==`string`&&e.length>0):[];if(d.length>0){let e=s(i(a(d.map(u))));if(e.length>0)return e.slice(0,Math.max(1,O))}let f=e,m=new Set([`rich_text`,`html`,`json`]),h=[`name`,`full_name`,`fullname`,`title`,`subject`,`label`,`code`,`number`],_=Object.entries(q.fields).filter(([e,t])=>!(e.startsWith(`_`)||e===`id`||e===F||t?.hidden||t?.type&&m.has(t.type)||Xe?.isLoaded&&f&&!Xe.checkField(f,e,`read`))),v=new Set([`created_at`,`updated_at`,`created_by`,`updated_by`,`owner_id`,`organization_id`]);return _.sort(([e,t],[n,r])=>{let i=v.has(e);if(i!==v.has(n))return i?1:-1;let a=h.indexOf(e),o=h.indexOf(n),s=a>=0?a:100,c=o>=0?o:100;if(s!==c)return s-c;let l=t?.type===`select`||e.includes(`status`);return l===(r?.type===`select`||n.includes(`status`))?0:l?-1:1}),s(_.map(([e,t])=>{let n={accessorKey:e,header:we(f,e,t.label||e)};if(t.type){let r=l(e,t);r&&(n.cell=r)}return n})).slice(0,Math.max(1,O))},[p,q,g,c,we,F,R,O,Se,Xe]),Ze=r.useMemo(()=>Q?$.map(e=>{let n=e.accessorKey||(0,t.columnIdentity)(e);return n&&(0,t.isExpandableFieldType)(q?.fields?.[n])?{...e,sortable:!1}:e}):$,[$,Q,q]),Qe=!f&&(s===`grid`||s===`table`),$e=Array.isArray(S)&&S.length>0,et=!!y||!!b||$e,tt=(0,i.useIsMobile)(),nt=r.useMemo(()=>{if(f)return f;if(tt&&(s===`grid`||s===`table`)){let e=$[0]?.accessorKey||(0,t.columnIdentity)($[0]),n=$.slice(1,4).map(e=>e.accessorKey||(0,t.columnIdentity)(e)).filter(Boolean);return{type:`object-gallery`,data:Re,objectName:c,gallery:{titleField:e||`name`,visibleFields:n,cardSize:`medium`},onRowClick:x}}let e=(0,t.userActionPredicates)(q?.userActions?.edit),n=(0,t.userActionPredicates)(q?.userActions?.delete);switch(s){case`grid`:case`table`:return{type:`data-table`,data:Re,columns:Ze,pagination:!1,pageSize:Z||10,searchable:!1,exportable:!1,manualSorting:!0,sort:Ue,onSortChange:We,rowActions:et,onRowEdit:y,onRowDelete:b?qe:void 0,rowEditPredicates:e,rowDeletePredicates:n,onRowClick:x,rowActionDefs:$e?S:void 0,onRowActionDef:$e?C:void 0};case`list`:return{type:`data-list`,data:Re};default:return{type:`div`,children:`No view configured`}}},[s,Re,Ze,$,f,Z,et,$e,S,C,y,b,qe,x,tt,c,q,Ue,We]),rt=N?`cursor-pointer select-none`:void 0,it=N?()=>me(e=>!e):void 0,at=z(ee),ot=Q&&le!=null?le:R.length,st=!B&&R.length===0&&(!Q||H===0),ct=M;return(0,l.jsxs)(i.Card,{className:(0,i.cn)(`shadow-none border-border/60 bg-transparent`,st&&`bg-muted/10`,m),children:[(0,l.jsx)(i.CardHeader,{className:(0,i.cn)(`py-3 px-4 sm:py-3 min-h-12 sm:min-h-0`,rt),onClick:it,children:(0,l.jsxs)(i.CardTitle,{className:`flex items-center justify-between gap-2 text-sm font-semibold`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[N&&(J?(0,l.jsx)(a.ChevronRight,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}):(0,l.jsx)(a.ChevronDown,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`})),(0,l.jsx)(at,{className:`h-4 w-4 text-muted-foreground shrink-0`,"aria-hidden":!0}),(0,l.jsx)(`span`,{className:(0,i.cn)(`truncate`,st&&`text-muted-foreground font-medium`),children:e}),(0,l.jsx)(i.Badge,{variant:`secondary`,className:(0,i.cn)(`text-xs font-normal h-5 px-1.5`,ot===0&&`bg-muted text-muted-foreground`),"aria-label":`${ot} records`,children:ot}),st&&(0,l.jsx)(`span`,{className:`text-xs text-muted-foreground/70 italic ml-1 truncate`,children:X(`detail.noRelatedRecords`)})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[T&&(w??[]).map(e=>(0,l.jsx)(ae,{action:e,onToolbarAction:T},e.name)),E&&(0,l.jsxs)(i.Button,{variant:st?`ghost`:`outline`,size:`sm`,disabled:_e,onClick:e=>{e.stopPropagation(),be(null),ge(!0)},className:`gap-1 h-9 sm:h-7 text-xs shadow-none`,children:[(0,l.jsx)(a.Plus,{className:`h-3.5 w-3.5`}),E.label||X(`detail.add`,{defaultValue:`Add`})]}),_&&(0,l.jsxs)(i.Button,{variant:st?`ghost`:`outline`,size:`sm`,onClick:e=>{e.stopPropagation(),_()},className:`gap-1 h-9 sm:h-7 text-xs shadow-none`,children:[(0,l.jsx)(a.Plus,{className:`h-3.5 w-3.5`}),X(`detail.new`)]})]})]})}),!J&&!st&&(0,l.jsxs)(i.CardContent,{className:(0,i.cn)(`pt-0 pb-4 px-4`),children:[ct&&(0,l.jsx)(`div`,{className:`mb-3`,children:(0,l.jsx)(i.Input,{placeholder:X(`detail.filterPlaceholder`),value:K,onChange:e=>ce(e.target.value),className:`h-8 text-sm`})}),j&&!Qe&&$&&$.length>0&&R.length>0&&(0,l.jsx)(`div`,{className:`flex flex-wrap gap-1 mb-3`,children:$.map(e=>{let n=e.accessorKey||(0,t.columnIdentity)(e);if(!n||Q&&(0,t.isExpandableFieldType)(q?.fields?.[n]))return null;let r=e.header||e.label||n,o=W===n;return(0,l.jsxs)(i.Button,{variant:o?`secondary`:`ghost`,size:`sm`,className:`gap-1 h-7 text-xs`,onClick:()=>He(n),children:[(0,l.jsx)(a.ArrowUpDown,{className:`h-3 w-3`}),r,o&&(G===`asc`?` ↑`:` ↓`)]},n)})}),B&&R.length===0?(0,l.jsx)(`div`,{className:`flex items-center justify-center py-6 text-muted-foreground text-sm`,children:X(`detail.loading`)}):(0,l.jsx)(`div`,{className:(0,i.cn)(B&&`opacity-60 pointer-events-none transition-opacity`),children:(0,l.jsx)(o.SchemaRenderer,{schema:nt})}),Ve&&(0,l.jsxs)(`div`,{className:`flex items-center justify-between mt-3 pt-3 border-t`,children:[(0,l.jsxs)(i.Button,{variant:`outline`,size:`sm`,className:`h-7 text-xs gap-1`,disabled:H===0,onClick:()=>U(e=>Math.max(0,e-1)),children:[(0,l.jsx)(a.ChevronLeft,{className:`h-3 w-3`}),X(`detail.previousPage`)]}),(0,l.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:X(`detail.pageOf`,{current:H+1,total:ze})}),(0,l.jsxs)(i.Button,{variant:`outline`,size:`sm`,className:`h-7 text-xs gap-1`,disabled:!Be,onClick:()=>U(e=>Be?e+1:e),children:[X(`detail.nextPage`),(0,l.jsx)(a.ChevronRight,{className:`h-3 w-3`})]})]}),v&&!st&&Ve&&(0,l.jsx)(`div`,{className:`mt-3 pt-3 border-t flex justify-center`,children:(0,l.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),v()},className:`text-xs text-muted-foreground hover:text-foreground inline-flex items-center gap-1 transition-colors`,children:[X(`detail.viewAll`),(0,l.jsx)(a.ExternalLink,{className:`h-3 w-3`})]})})]}),(0,l.jsx)(i.AlertDialog,{open:Ge!==null,onOpenChange:e=>{e||Ke(null)},children:(0,l.jsxs)(i.AlertDialogContent,{children:[(0,l.jsxs)(i.AlertDialogHeader,{children:[(0,l.jsx)(i.AlertDialogTitle,{children:X(`detail.deleteRowTitle`,{defaultValue:`Delete record`})}),(0,l.jsx)(i.AlertDialogDescription,{children:X(`detail.deleteRowConfirmation`)})]}),(0,l.jsxs)(i.AlertDialogFooter,{children:[(0,l.jsx)(i.AlertDialogCancel,{children:X(`detail.cancel`,{defaultValue:`Cancel`})}),(0,l.jsx)(i.AlertDialogAction,{onClick:Je,className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:X(`detail.delete`,{defaultValue:`Delete`})})]})]})}),ye&&(0,l.jsx)(`div`,{className:`mx-4 mb-3 rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,role:`alert`,children:ye}),E&&h&&(0,l.jsx)(n.RecordPickerDialog,{open:he,onOpenChange:e=>ge(e),multiple:!0,dataSource:h,objectName:E.picker.object,title:E.label||X(`detail.add`,{defaultValue:`Add`}),displayField:Pe,columns:Fe,cellRenderer:n.getCellRenderer,fieldsMeta:Me?.fields,onSelect:()=>{},onSelectRecords:e=>{Ye(e)}})]})},V=({group:e,data:t,className:n,objectSchema:o,objectName:s,isEditing:c=!1,onFieldChange:u,onEnterInlineEdit:d,autoFocusField:f,dataSource:p})=>{let m=e.collapsible??!0,[h,g]=r.useState(e.defaultCollapsed??!1),_=(0,l.jsx)(`div`,{className:`space-y-3 sm:space-y-4`,children:e.sections.map((e,n)=>(0,l.jsx)(R,{section:e,data:t,objectSchema:o,objectName:s,isEditing:c,onFieldChange:u,onEnterInlineEdit:d,autoFocusField:f,dataSource:p},n))});return m?(0,l.jsxs)(i.Collapsible,{open:!h,onOpenChange:e=>g(!e),className:n,children:[(0,l.jsx)(i.CollapsibleTrigger,{asChild:!0,children:(0,l.jsxs)(`div`,{className:`flex items-center gap-2 pb-2 border-b cursor-pointer hover:bg-muted/50 transition-colors rounded-t-md px-2 py-1.5`,children:[h?(0,l.jsx)(a.ChevronRight,{className:`h-4 w-4 text-muted-foreground shrink-0`}):(0,l.jsx)(a.ChevronDown,{className:`h-4 w-4 text-muted-foreground shrink-0`}),e.icon&&(0,l.jsx)(`span`,{className:`text-muted-foreground`,children:e.icon}),(0,l.jsx)(`h3`,{className:`text-lg font-semibold`,children:e.title})]})}),e.description&&!h&&(0,l.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:e.description}),(0,l.jsx)(i.CollapsibleContent,{children:(0,l.jsx)(`div`,{className:`mt-3`,children:_})})]}):(0,l.jsxs)(`div`,{className:(0,i.cn)(`space-y-3`,n),children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2 pb-2 border-b`,children:[e.icon&&(0,l.jsx)(`span`,{className:`text-muted-foreground`,children:e.icon}),(0,l.jsx)(`h3`,{className:`text-lg font-semibold`,children:e.title})]}),e.description&&(0,l.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e.description}),_]})},H=({fields:e,data:t,className:r,objectName:s,objectSchema:c,dataSource:u})=>{let{fieldLabel:d}=(0,o.useSafeFieldLabel)(),{t:f}=D(),p=(0,o.useInlineEdit)(),m=p?.editing??!1,h=p?.canEdit??!1;if(!e.length||!t)return null;let g=m?e:e.filter(e=>{let n=t?.[e.name];return n!=null&&n!==``});return g.length===0?null:(0,l.jsx)(i.TooltipProvider,{children:(0,l.jsx)(`section`,{className:(0,i.cn)(`@container border-b border-border/60 pb-4`,r),"aria-label":`Record highlights`,children:(0,l.jsx)(`div`,{className:(0,i.cn)(`flex flex-wrap gap-y-4`),children:g.map(e=>{let r=t[e.name],o=c?.fields?.[e.name],g=e.type||o?.type,_=F({name:e.name,label:e.label,type:g||`text`},o),v=p?.draft?.[e.name],y=v===void 0?r:v,b=N(e.type,o?.type),x=e.readonly===!0||o?.readonly===!0,S=j.has(e.name),C=h&&!b&&!x&&!S,w=m&&C,T=(0,n.getCellRenderer)((0,n.resolveCellRendererType)(_)||g||`text`),E=g===`number`||g===`integer`||g===`currency`||g===`percent`||g===`decimal`,D=g===`email`||g===`url`||g===`textarea`||g===`reference`||g===`lookup`||g===`master_detail`,O=g===`boolean`,k=y==null||y===``;return(0,l.jsxs)(`div`,{className:(0,i.cn)(`group flex flex-col gap-1 min-w-[7rem] px-5 border-l border-border/60 first:border-l-0 first:pl-0`,D||w?`basis-[16rem] max-w-[24rem]`:`basis-[9rem] max-w-[16rem]`),children:[(0,l.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:d(s||``,e.name,e.label)}),w?(0,l.jsx)(ee,{field:_,value:y,onChange:t=>p.setField(e.name,t),dataSource:u,autoFocus:p.autoFocusField===e.name}):(0,l.jsxs)(`div`,{className:(0,i.cn)(`flex items-start justify-between gap-1`,C&&`cursor-pointer rounded-md -mx-1.5 px-1.5 hover:bg-muted/40 transition-colors`),onDoubleClick:C?()=>p.enter(e.name):void 0,title:C?f(`detail.editInlineHint`):void 0,children:[(0,l.jsx)(`div`,{className:`min-w-0 flex-1`,children:O?y?(0,l.jsxs)(`span`,{className:`inline-flex items-center gap-1 self-start rounded-full bg-emerald-500/10 px-2 py-0.5 text-xs font-medium text-emerald-600 ring-1 ring-inset ring-emerald-500/30 dark:text-emerald-400`,children:[(0,l.jsx)(a.Check,{className:`h-3 w-3`,"aria-hidden":!0}),`Yes`]}):(0,l.jsxs)(`span`,{className:`inline-flex items-center gap-1 self-start rounded-full bg-amber-500/10 px-2 py-0.5 text-xs font-medium text-amber-700 ring-1 ring-inset ring-amber-500/30 dark:text-amber-400`,children:[(0,l.jsx)(a.X,{className:`h-3 w-3`,"aria-hidden":!0}),`No`]}):k?(0,l.jsx)(`span`,{className:`block text-sm text-muted-foreground/60 select-none`,"aria-label":f(`detail.noValue`,{defaultValue:`No value`}),children:`—`}):(0,l.jsx)(`span`,{title:(Array.isArray(_.options)?_.options.find(e=>e?.value===y)?.label:void 0)??(typeof y==`string`||typeof y==`number`?String(y):void 0),className:(0,i.cn)(`block min-w-0 truncate text-sm font-semibold`,E&&`tabular-nums tracking-tight`),children:(0,l.jsx)(T,{value:y,field:_})})}),C&&(0,l.jsxs)(i.Tooltip,{children:[(0,l.jsx)(i.TooltipTrigger,{asChild:!0,children:(0,l.jsx)(i.Button,{variant:`ghost`,size:`icon`,className:`h-5 w-5 shrink-0 opacity-0 group-hover:opacity-100 transition-opacity`,"aria-label":f(`detail.editInlineHint`),onClick:t=>{t.stopPropagation(),p.enter(e.name)},children:(0,l.jsx)(a.Pencil,{className:`h-3 w-3`})})}),(0,l.jsx)(i.TooltipContent,{children:f(`detail.editInlineHint`)})]})]})]},e.name)})})})})};function U(e){try{let t=new Date(e),n=new Date().getTime()-t.getTime(),r=Math.floor(n/6e4);if(r<1)return`just now`;if(r<60)return`${r}m ago`;let i=Math.floor(r/60);if(i<24)return`${i}h ago`;let a=Math.floor(i/24);return a<7?`${a}d ago`:t.toLocaleDateString()}catch{return e}}var W=({comments:e,onAddComment:t,onTogglePin:n,searchable:o=!1,className:s})=>{let{t:c}=D(),[u,d]=r.useState(``),[f,p]=r.useState(!1),[m,h]=r.useState(``),g=r.useCallback(async()=>{let e=u.trim();if(!(!e||!t)){p(!0);try{await t(e),d(``)}finally{p(!1)}}},[u,t]),_=r.useCallback(e=>{e.key===`Enter`&&(e.ctrlKey||e.metaKey)&&(e.preventDefault(),g())},[g]),v=r.useMemo(()=>[...m.trim()?e.filter(e=>{let t=m.trim().toLowerCase();return e.text.toLowerCase().includes(t)||e.author.toLowerCase().includes(t)}):e].sort((e,t)=>e.pinned&&!t.pinned?-1:!e.pinned&&t.pinned?1:0),[e,m]);return(0,l.jsxs)(i.Card,{className:(0,i.cn)(``,s),children:[(0,l.jsx)(i.CardHeader,{children:(0,l.jsxs)(i.CardTitle,{className:`flex items-center gap-2 text-base`,children:[(0,l.jsx)(a.MessageSquare,{className:`h-4 w-4`}),c(`detail.comments`),(0,l.jsxs)(`span`,{className:`text-sm font-normal text-muted-foreground`,children:[`(`,e.length,`)`]})]})}),(0,l.jsxs)(i.CardContent,{className:`space-y-4`,children:[o&&(0,l.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,l.jsxs)(`div`,{className:`relative flex-1`,children:[(0,l.jsx)(a.Search,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,l.jsx)(`input`,{className:`w-full rounded-md border border-input bg-background pl-8 pr-8 py-1.5 text-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`,placeholder:c(`detail.searchComments`),value:m,onChange:e=>h(e.target.value),"aria-label":c(`detail.searchComments`)}),m&&(0,l.jsx)(`button`,{className:`absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground`,onClick:()=>h(``),"aria-label":c(`detail.clearSearch`),type:`button`,children:(0,l.jsx)(a.X,{className:`h-3.5 w-3.5`})})]})}),t&&(0,l.jsxs)(`div`,{className:`flex gap-2`,children:[(0,l.jsx)(`textarea`,{className:`flex-1 min-h-[60px] rounded-md border border-input bg-background px-3 py-2 text-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring resize-none`,placeholder:c(`detail.addCommentPlaceholder`),value:u,onChange:e=>d(e.target.value),onKeyDown:_,disabled:f}),(0,l.jsx)(i.Button,{size:`icon`,variant:`default`,onClick:g,disabled:!u.trim()||f,className:`shrink-0 self-end`,children:(0,l.jsx)(a.Send,{className:`h-4 w-4`})})]}),v.length===0?(0,l.jsx)(`p`,{className:`text-sm text-muted-foreground text-center py-4`,children:m.trim()?c(`detail.noMatchingComments`):c(`detail.noCommentsYet`)}):(0,l.jsx)(`div`,{className:`space-y-3`,children:v.map(e=>(0,l.jsxs)(`div`,{className:(0,i.cn)(`flex gap-3`,e.pinned&&`bg-muted/40 rounded-md p-2 -mx-2`),children:[(0,l.jsx)(`div`,{className:`shrink-0`,children:e.avatarUrl?(0,l.jsx)(`img`,{src:e.avatarUrl,alt:e.author,className:`h-8 w-8 rounded-full object-cover`}):(0,l.jsx)(`div`,{className:`h-8 w-8 rounded-full bg-muted flex items-center justify-center text-xs font-medium text-muted-foreground`,children:e.author.charAt(0).toUpperCase()})}),(0,l.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2 mb-0.5`,children:[(0,l.jsx)(`span`,{className:`text-sm font-medium truncate`,children:e.author}),(0,l.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:U(e.createdAt)}),e.pinned&&(0,l.jsxs)(`span`,{className:`text-xs text-amber-600 flex items-center gap-0.5`,children:[(0,l.jsx)(a.Pin,{className:`h-3 w-3`}),c(`detail.pinned`)]})]}),(0,l.jsx)(`p`,{className:`text-sm whitespace-pre-wrap break-words`,children:e.text}),n&&(0,l.jsxs)(`button`,{type:`button`,className:`mt-1 text-xs text-muted-foreground hover:text-foreground flex items-center gap-1`,onClick:()=>n(e.id),"aria-label":e.pinned?c(`detail.unpin`):c(`detail.pin`),children:[(0,l.jsx)(a.Pin,{className:`h-3 w-3`}),e.pinned?c(`detail.unpin`):c(`detail.pin`)]})]})]},e.id))})]})]})},oe={field_change:a.Edit,create:a.PlusCircle,delete:a.Trash2,comment:a.MessageSquare,status_change:a.ArrowRightLeft},G={field_change:`bg-blue-100 text-blue-600`,create:`bg-green-100 text-green-600`,delete:`bg-red-100 text-red-600`,comment:`bg-purple-100 text-purple-600`,status_change:`bg-amber-100 text-amber-600`};function se(e){try{let t=new Date(e),n=new Date().getTime()-t.getTime(),r=Math.floor(n/6e4);if(r<1)return`just now`;if(r<60)return`${r}m ago`;let i=Math.floor(r/60);if(i<24)return`${i}h ago`;let a=Math.floor(i/24);return a<7?`${a}d ago`:t.toLocaleDateString()}catch{return e}}function K(e){return e.description?e.description:e.type===`field_change`&&e.field?`Changed ${e.field.charAt(0).toUpperCase()+e.field.slice(1).replace(/_/g,` `)} from "${e.oldValue==null?`(empty)`:String(e.oldValue)}" to "${e.newValue==null?`(empty)`:String(e.newValue)}"`:e.type===`create`?`Created this record`:e.type===`delete`?`Deleted this record`:e.type===`status_change`&&e.field?`Changed status to "${e.newValue==null?`(empty)`:String(e.newValue)}"`:`Updated record`}var ce={all:`All`,field_change:`Field Changes`,create:`Creates`,delete:`Deletes`,comment:`Comments`,status_change:`Status Changes`},le=({activities:e,filterable:t=!1,defaultFilter:n=`all`,className:o})=>{let[s,c]=r.useState(n),u=r.useMemo(()=>s===`all`?e:e.filter(e=>e.type===s),[e,s]);return(0,l.jsxs)(i.Card,{className:(0,i.cn)(``,o),children:[(0,l.jsx)(i.CardHeader,{children:(0,l.jsxs)(i.CardTitle,{className:`flex items-center gap-2 text-base`,children:[(0,l.jsx)(a.Activity,{className:`h-4 w-4`}),`Activity`,(0,l.jsxs)(`span`,{className:`text-sm font-normal text-muted-foreground`,children:[`(`,u.length,`)`]})]})}),(0,l.jsxs)(i.CardContent,{children:[t&&(0,l.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mb-4`,role:`group`,"aria-label":`Activity type filter`,children:Object.keys(ce).map(e=>(0,l.jsxs)(`button`,{type:`button`,className:(0,i.cn)(`inline-flex items-center gap-1 rounded-full px-2.5 py-0.5 text-xs font-medium transition-colors`,s===e?`bg-primary text-primary-foreground`:`bg-muted text-muted-foreground hover:bg-muted/80`),onClick:()=>c(e),"aria-pressed":s===e,children:[e!==`all`&&r.createElement(oe[e]||a.Edit,{className:`h-3 w-3`}),ce[e]]},e))}),u.length===0?(0,l.jsx)(i.DataEmptyState,{title:`No activity recorded`,className:`py-6`}):(0,l.jsxs)(`div`,{className:`relative`,children:[(0,l.jsx)(`div`,{className:`absolute left-4 top-2 bottom-2 w-px bg-border`}),(0,l.jsx)(`div`,{className:`space-y-4`,children:u.map(e=>{let t=oe[e.type]||a.Edit,n=G[e.type]||`bg-gray-100 text-gray-600`;return(0,l.jsxs)(`div`,{className:`flex gap-3 relative`,children:[(0,l.jsx)(`div`,{className:(0,i.cn)(`shrink-0 h-8 w-8 rounded-full flex items-center justify-center z-10`,n),children:(0,l.jsx)(t,{className:`h-3.5 w-3.5`})}),(0,l.jsxs)(`div`,{className:`flex-1 min-w-0 pt-1`,children:[(0,l.jsxs)(`p`,{className:`text-sm`,children:[(0,l.jsx)(`span`,{className:`font-medium`,children:e.user}),` `,(0,l.jsx)(`span`,{className:`text-muted-foreground`,children:K(e)})]}),(0,l.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:se(e.timestamp)})]})]},e.id)})})]})]})]})},ue={create:`default`,update:`secondary`,delete:`destructive`,restore:`outline`,login:`outline`,logout:`outline`,permission_change:`secondary`,config_change:`secondary`,export:`outline`,import:`outline`};function de(e){if(!e)return``;let t=e instanceof Date?e:new Date(e);return Number.isNaN(t.getTime())?String(e):t.toLocaleString()}var fe=[[60,`second`],[60,`minute`],[24,`hour`],[7,`day`],[4.34524,`week`],[12,`month`],[1/0,`year`]];function q(e,t){if(!e)return``;let n=e instanceof Date?e:new Date(e);if(Number.isNaN(n.getTime()))return String(e);let r=(n.getTime()-Date.now())/1e3;for(let[n,i]of fe){if(Math.abs(r)<n)try{return new Intl.RelativeTimeFormat(t,{numeric:`auto`}).format(Math.round(r),i)}catch{return de(e)}r/=n}return de(e)}function pe(e){if(!e)return`?`;let t=e.trim().split(/\s+/).filter(Boolean).slice(0,2);return t.length===0?`?`:t.map(e=>e.charAt(0).toUpperCase()).join(``)}function J(e){if(e==null||e===``)return`—`;if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`boolean`)return String(e);try{return JSON.stringify(e)}catch{return String(e)}}function me({entries:e,loading:t,emptyText:n,unknownUserText:r,className:a,locale:o}){return t?(0,l.jsx)(`div`,{className:(0,i.cn)(`space-y-3`,a),children:Array.from({length:4}).map((e,t)=>(0,l.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,l.jsx)(i.Skeleton,{className:`h-8 w-8 rounded-full`}),(0,l.jsxs)(`div`,{className:`flex-1 space-y-2`,children:[(0,l.jsx)(i.Skeleton,{className:`h-4 w-1/3`}),(0,l.jsx)(i.Skeleton,{className:`h-3 w-1/2`})]})]},t))}):!e||e.length===0?(0,l.jsx)(`div`,{className:(0,i.cn)(`flex items-center justify-center rounded-md border border-dashed py-10 text-sm text-muted-foreground`,a),children:n??`No history yet`}):(0,l.jsx)(i.TooltipProvider,{delayDuration:150,children:(0,l.jsx)(`ol`,{className:(0,i.cn)(`space-y-4`,a),children:e.map((e,t)=>{let n=(e.action??``).toLowerCase(),a=ue[n]??`outline`,s=typeof e.user_name==`string`&&e.user_name.trim()||r||`Unknown user`,c=de(e.created_at),u=q(e.created_at,o),d=typeof e.user_avatar==`string`?e.user_avatar:void 0;return(0,l.jsxs)(`li`,{className:`flex items-start gap-3`,children:[(0,l.jsxs)(i.Avatar,{className:`h-8 w-8 mt-0.5 shrink-0`,children:[d?(0,l.jsx)(i.AvatarImage,{src:d,alt:s}):null,(0,l.jsx)(i.AvatarFallback,{className:`text-[10px] font-medium`,children:pe(e.user_name)})]}),(0,l.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,l.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2 gap-y-1`,children:[(0,l.jsx)(`span`,{className:`text-sm font-medium text-foreground`,children:s}),e.action&&(0,l.jsx)(i.Badge,{variant:a,className:`text-[10px] uppercase tracking-wide`,children:e.action}),c&&(0,l.jsxs)(i.Tooltip,{children:[(0,l.jsx)(i.TooltipTrigger,{asChild:!0,children:(0,l.jsx)(`span`,{className:`text-xs text-muted-foreground cursor-help`,"aria-label":c,children:u||c})}),(0,l.jsx)(i.TooltipContent,{children:c})]})]}),e.summary&&(0,l.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:e.summary}),e.changes&&e.changes.length>0&&(n===`create`?(0,l.jsxs)(`details`,{className:`mt-1 group`,children:[(0,l.jsxs)(`summary`,{className:`cursor-pointer list-none text-xs text-muted-foreground hover:text-foreground inline-flex items-center gap-1 select-none`,children:[(0,l.jsx)(`span`,{className:`transition-transform group-open:rotate-90`,children:`▸`}),(0,l.jsx)(`span`,{children:e.changes.length===1?`1 field populated`:`${e.changes.length} fields populated`})]}),(0,l.jsx)(`ul`,{className:`mt-1.5 space-y-0.5 text-xs text-muted-foreground pl-4`,children:e.changes.map(e=>(0,l.jsxs)(`li`,{className:`leading-relaxed`,children:[(0,l.jsx)(`span`,{className:`font-medium text-foreground`,children:e.label||e.field}),`: `,(0,l.jsx)(`span`,{className:`text-foreground`,children:J(e.to)})]},e.field))})]}):(0,l.jsx)(`ul`,{className:`mt-1.5 space-y-0.5 text-xs text-muted-foreground`,children:e.changes.map(e=>(0,l.jsxs)(`li`,{className:`leading-relaxed`,children:[(0,l.jsx)(`span`,{className:`font-medium text-foreground`,children:e.label||e.field}),`: `,(0,l.jsx)(`span`,{className:`line-through opacity-70`,children:J(e.from)}),` → `,(0,l.jsx)(`span`,{className:`text-foreground`,children:J(e.to)})]},e.field))}))]})]},e.id??t)})})})}var he=d.AUDIT_FIELD_BY_ROLE;function ge(e){if(!e)return null;if(e instanceof Date)return isNaN(e.getTime())?null:e;if(typeof e==`string`||typeof e==`number`){let t=new Date(e);return isNaN(t.getTime())?null:t}return null}function _e(e,t){let n=Date.now()-e.getTime(),r=Math.max(0,Math.floor(n/1e3));if(r<60)return t(`detail.justNow`);let i=Math.floor(r/60);if(i<60)return t(`detail.minutesAgo`,{count:i});let a=Math.floor(i/60);return a<24?t(`detail.hoursAgo`,{count:a}):t(`detail.daysAgo`,{count:Math.floor(a/24)})}function ve(e){try{return new Intl.DateTimeFormat(void 0,{dateStyle:`medium`,timeStyle:`short`}).format(e)}catch{return e.toISOString()}}var ye=({value:e,objectSchema:t,fieldName:i})=>{if(e==null||e===``)return null;let a=t?.fields?.[i],o=a?.reference_to||a?.reference||`sys_user`,s={name:i,type:a?.type||`lookup`,reference_to:o,...a?.reference_field&&{reference_field:a.reference_field}},c=(0,n.resolveCellRendererType)(s)||s.type;if(c){let t=(0,n.getCellRenderer)(c);if(t)return(0,l.jsx)(`span`,{className:`inline-flex items-center [&_a]:text-inherit [&_a]:hover:underline`,children:r.createElement(t,{value:e,field:s})})}return(0,l.jsx)(`span`,{children:String(e)})},be=({label:e,user:t,date:n,objectSchema:r,userField:a,t:o})=>{if(!t&&!n)return null;let s=n?(0,l.jsx)(i.TooltipProvider,{delayDuration:200,children:(0,l.jsxs)(i.Tooltip,{children:[(0,l.jsx)(i.TooltipTrigger,{asChild:!0,children:(0,l.jsx)(`time`,{dateTime:n.toISOString(),className:`cursor-default underline decoration-dotted decoration-muted-foreground/40 underline-offset-2`,children:_e(n,o)})}),(0,l.jsx)(i.TooltipContent,{side:`top`,children:ve(n)})]})}):null;return(0,l.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,l.jsx)(`span`,{className:`text-muted-foreground/70`,children:e}),t?(0,l.jsx)(ye,{value:t,objectSchema:r,fieldName:a}):null,t&&s?(0,l.jsx)(`span`,{className:`text-muted-foreground/40`,children:`·`}):null,s]})},xe=({data:e,objectSchema:t,objectName:n,className:r})=>{let{t:a}=D();if(!e)return null;let o=ge(e[he.createdAt]),s=ge(e[he.updatedAt]),c=e[he.createdBy],u=e[he.updatedBy],d=!!(o||c),f=o&&s&&Math.abs(s.getTime()-o.getTime())<2e3,p=!!(s||u)&&!(f&&(c!=null&&u!=null&&String(c)===String(u)||!u));return!d&&!p?null:(0,l.jsxs)(`div`,{className:(0,i.cn)(`mt-6 pt-3 border-t border-border/40`,`flex flex-wrap items-center gap-x-4 gap-y-1`,`text-xs text-muted-foreground`,r),"data-testid":`record-meta-footer`,children:[d&&(0,l.jsx)(be,{label:a(c?`detail.createdBy`:`detail.created`),user:c,date:o,objectSchema:t,userField:he.createdBy,t:a}),p&&(0,l.jsx)(be,{label:a(u?`detail.updatedBy`:`detail.updated`),user:u,date:s,objectSchema:t,userField:he.updatedBy,t:a})]})},Y=new Map;function Se(e,t,n=`update`,i=!0){let a=e&&t?`${e}:${t}:${n}`:``,[s,c]=r.useState(()=>a&&Y.has(a)?Y.get(a):!0),l=r.useContext(o.SchemaRendererContext)?.apiFetch;return r.useEffect(()=>{if(!i||!a){c(!0);return}if(Y.has(a)){c(Y.get(a));return}let r=!1;return(async()=>{try{let i=await(l??fetch)(`/api/v1/security/explain`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`include`,body:JSON.stringify({object:e,operation:n,recordId:t})});if(!i.ok)return;let o=(await i.json())?.record?.visible;if(typeof o!=`boolean`)return;Y.set(a,o),r||c(o)}catch{}})(),()=>{r=!0}},[a,e,t,n,i,l]),s}function Ce(){Y.clear()}var X=5,we={};function Z(e,n,r,i){if(e&&typeof e==`object`){if(n.primaryField){let t=e[n.primaryField];if(t!=null&&t!==``)return String(t)}let i=(0,t.formatTitleTemplate)(r?.titleFormat,e);if(i)return i}if(e&&typeof e==`object`){let n=e.id??e._id,i=(0,t.getRecordDisplayName)(r,e,{deriveFromRecordKeys:!1});if(!(i===`Untitled`||n!=null&&i===`Record #${n}`))return i}if(n.title)return n.title;if(e&&typeof e==`object`){let n=e.id??e._id,i=(0,t.getRecordDisplayName)(r,e);if(!(i===`Untitled`||n!=null&&i===`Record #${n}`))return i}if(e&&typeof e==`object`){let t=e.id??e._id;if(t!=null&&String(t).trim()!==``)return`Record #${t}`}return i}var Te=({schema:e,dataSource:n,className:c,onEdit:d,onDelete:f,onBack:p,inlineEdit:m=!1,discussionSlot:h,rightRail:g,objectLabel:_,onDataLoaded:v,isFavorite:y,onToggleFavorite:b})=>{let[x,S]=r.useState(e.data),[C,w]=r.useState(!e.data&&!!(e.api&&e.resourceId||n&&e.objectName&&e.resourceId)),[T,E]=r.useState(!1),O=y??T,k=(0,o.useInlineEdit)(),A=k?.editing??!1,j=k?.draft??we,M=k?.autoFocusField??null,[N,P]=r.useState(null),[F,I]=r.useState(null),[ee,L]=r.useState(!1),[te,z]=r.useState(0),re=(0,o.useDataInvalidation)(e.objectName||void 0,e.resourceId==null?void 0:String(e.resourceId)),[ie,ae]=r.useState(!1),{t:U}=D(),{currency:oe}=(0,s.useLocalization)(),{fieldOptionLabel:G}=(0,o.useSafeFieldLabel)(),se=(0,i.useIsMobile)(),K=(0,u.usePermissions)(),ce=r.useMemo(()=>{if(!K?.isLoaded||!e.objectName)return e;let t=t=>K.checkField(e.objectName,t,`read`),n=e=>e&&e.filter(e=>{let n=typeof e==`string`?e:e?.name;return!n||t(n)});return{...e,fields:n(e.fields),sections:e.sections?.map(e=>({...e,fields:n(e.fields)})),summaryFields:n(e.summaryFields)}},[e,K]),ue=r.useMemo(()=>!K?.isLoaded||!e.objectName||K.can(e.objectName,`update`),[K,e.objectName]),de=r.useMemo(()=>!K?.isLoaded||!e.objectName||K.can(e.objectName,`delete`),[K,e.objectName]),fe=e.resourceId==null?void 0:String(e.resourceId),q=Se(e.objectName,fe,`update`,ue),pe=Se(e.objectName,fe,`delete`,de),J=r.useMemo(()=>({...ce,showEdit:ce.showEdit&&ue&&q,showDelete:ce.showDelete&&de&&pe}),[ce,ue,q,de,pe]);r.useEffect(()=>{x&&v&&v(x)},[x,v]);let he=r.useMemo(()=>{if(J.summaryFields&&J.summaryFields.length>0)return[];let e=[...J.sections?.flatMap(e=>e.fields)||[],...J.fields||[]],t={};for(let n of e)t[n.name]||(t[n.name]=n);if(F?.fields)for(let[e,n]of Object.entries(F.fields))t[e]={...t[e]||{},...n,name:e};let n=e=>x?.[e]!==void 0&&x?.[e]!==null&&x?.[e]!==``,r=[],i=[`status`,`stage`,`state`,`phase`].find(e=>t[e]&&n(e))||Object.keys(t).find(e=>t[e]?.type===`select`&&n(e));i&&r.push(i);let a=Object.keys(t).find(e=>(t[e]?.type===`currency`||/amount|revenue|value|total|price/i.test(e))&&n(e));a&&!r.includes(a)&&r.push(a);let o=Object.keys(t).find(e=>(t[e]?.type===`date`||t[e]?.type===`datetime`)&&/close|due|start|end|expected/i.test(e)&&n(e));return o&&!r.includes(o)&&r.push(o),r},[J.summaryFields,J.sections,J.fields,F,x]),ge=J.summaryFields&&J.summaryFields.length>0?J.summaryFields:he,_e=r.useCallback(()=>{J.resourceId&&navigator.clipboard.writeText(String(J.resourceId)).then(()=>{L(!0),setTimeout(()=>L(!1),1500)})},[J.resourceId]);r.useEffect(()=>{let e=!0;if(J.data)return S(J.data),w(!1),n?.getObjectSchema&&J.objectName&&n.getObjectSchema(J.objectName).then(t=>{e&&I(t)}).catch(()=>{}),()=>{e=!1};if(n&&J.objectName&&J.resourceId){w(!0),I(null),S(null);let r=J.objectName,i=J.resourceId,a=`${r}-`,o=[...J.sections?.flatMap(e=>e.fields)||[],...J.fields||[]];(n.getObjectSchema?n.getObjectSchema(r).catch(()=>null):Promise.resolve(null)).then(s=>{if(!e)return;I(s);let c=(0,t.buildExpandFields)(s?.fields,o),l=c.length>0?{$expand:c}:void 0,u=l?n.findOne(r,i,l):n.findOne(r,i),d=()=>{let t=String(i),o=t.startsWith(a)?t.slice(a.length):`${a}${t}`;return(l?n.findOne(r,o,l):n.findOne(r,o)).then(t=>{e&&(S(t),w(!1))}).catch(()=>{e&&(S(null),w(!1))})};return u.catch(()=>null).then(t=>{if(e){if(t){S(t),w(!1);return}return d()}})}).catch(t=>{e&&(console.error(`Failed to fetch detail data:`,t),w(!1))})}else J.api&&J.resourceId&&(w(!0),fetch(`${J.api}/${J.resourceId}`).then(e=>e.json()).then(t=>{e&&S(t?.data||t)}).catch(e=>{console.error(`Failed to fetch detail data:`,e)}).finally(()=>{e&&w(!1)}));return()=>{e=!1}},[J.api,J.resourceId,J.objectName,n,J.sections,J.fields,te,re]);let ve=r.useCallback(()=>{if(p)p();else if(J.onNavigate){let e=J.backUrl||(J.objectName?`/${J.objectName}`:`/`);J.onNavigate(e,{replace:!0})}else J.backUrl?window.location.href=J.backUrl:window.history.back()},[p,J]),ye=r.useCallback(()=>{d?d():J.onNavigate&&J.editUrl?J.onNavigate(J.editUrl):J.onNavigate&&J.objectName&&J.resourceId?J.onNavigate(`/${J.objectName}/${J.resourceId}/edit`):J.editUrl&&(window.location.href=J.editUrl)},[d,J]),be=r.useCallback(async()=>{if(!n?.cancelPendingApproval||!J.objectName||!J.resourceId){P(U(`detail.cancelApprovalUnavailable`));return}ae(!0),P(null);try{if(await n.cancelPendingApproval(String(J.objectName),String(J.resourceId)),n.findOne)try{let e=await n.findOne(String(J.objectName),String(J.resourceId));e&&S(e)}catch{}z(e=>e+1);try{window.dispatchEvent(new CustomEvent(`objectui:record-changed`,{detail:{objectName:String(J.objectName),recordId:String(J.resourceId),reason:`approval-recalled`}}))}catch{}}catch(e){let t=(e?.message||e?.error||String(e??`Cancel failed`)).replace(/^\[[^\]]+\]\s*/,``).replace(/^[A-Z][A-Z0-9_]+:\s*/,``);P(`${U(`detail.cancelApprovalFailed`)}: ${t}`)}finally{ae(!1)}},[n,J.objectName,J.resourceId,U]),Y=r.useCallback(()=>{let e=J.deleteConfirmation||U(`detail.deleteConfirmation`);window.confirm(e)&&(f?.(),J.onNavigate&&J.objectName&&J.onNavigate(`/${J.objectName}`,{replace:!0}))},[f,J]),Ce=r.useCallback(()=>{navigator.share&&J.objectName&&J.resourceId?navigator.share({title:J.title||U(`detail.details`),text:`${J.objectName} #${J.resourceId}`,url:window.location.href}).catch(e=>console.log(`Share failed:`,e)):navigator.clipboard.writeText(window.location.href).then(()=>{console.log(`Link copied to clipboard`)})},[J]),Te=r.useCallback(()=>{let e=!O;b&&b(e),y===void 0&&E(e)},[O,y,b]),Q=k?.setField,Ee=k&&k.canEdit?k.enter:void 0;r.useEffect(()=>{if(!J.recordNavigation)return;let e=J.recordNavigation,t=t=>{let n=t.target?.tagName;n===`INPUT`||n===`TEXTAREA`||t.target?.isContentEditable||(t.key===`ArrowLeft`&&e.currentIndex>0?(t.preventDefault(),e.onNavigate(e.recordIds[e.currentIndex-1])):t.key===`ArrowRight`&&e.currentIndex<e.recordIds.length-1&&(t.preventDefault(),e.onNavigate(e.recordIds[e.currentIndex+1])))};return document.addEventListener(`keydown`,t),()=>document.removeEventListener(`keydown`,t)},[J.recordNavigation]);let De=r.useMemo(()=>J.related??[],[J.related]),Oe=r.useMemo(()=>{let e=[];return e.push({name:`sys_share`,label:U(`detail.share`),icon:`share-2`,type:`script`,onClick:Ce}),J.showEdit&&e.push({name:`sys_edit_mobile`,label:U(`detail.edit`),icon:`edit`,type:`script`,className:`sm:hidden`,onClick:ye}),J.showDelete&&e.push({name:`sys_delete`,label:U(`detail.delete`),icon:`trash-2`,type:`script`,variant:`destructive`,tags:[`separator-before`],onClick:Y}),e},[U,J.showEdit,J.showDelete,Ce,ye,Y]),ke=r.useMemo(()=>{let e=J.actions??[];if(Oe.length===0)return e;let t=!1,n=e.map(e=>{let n=e;if(n&&typeof n==`object`&&n.type===`action:bar`&&(!n.location||n.location===`record_header`)){t=!0;let e=Array.isArray(n.systemActions)?n.systemActions:[];return{...n,systemActions:[...e,...Oe]}}return e});return t||n.push({type:`action:bar`,location:`record_header`,systemActions:Oe}),n},[J.actions,Oe]);return C||J.loading?(0,l.jsxs)(`div`,{className:(0,i.cn)(`space-y-4`,c),children:[(0,l.jsx)(i.Skeleton,{className:`h-10 w-full`}),(0,l.jsx)(i.Skeleton,{className:`h-64 w-full`}),(0,l.jsx)(i.Skeleton,{className:`h-48 w-full`})]}):!x&&!J.data?(0,l.jsxs)(`div`,{className:(0,i.cn)(`flex flex-col items-center justify-center py-16 text-center`,c),children:[(0,l.jsx)(`p`,{className:`text-lg font-semibold`,children:U(`detail.recordNotFound`)}),(0,l.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:U(`detail.recordNotFoundDescription`)}),(J.showBack??!0)&&(0,l.jsxs)(i.Button,{variant:`outline`,size:`sm`,onClick:ve,className:`mt-4 gap-2`,children:[(0,l.jsx)(a.ArrowLeft,{className:`h-4 w-4`}),U(`detail.goBack`)]})]}):(0,l.jsx)(i.TooltipProvider,{children:(0,l.jsxs)(`div`,{className:(0,i.cn)(`space-y-6`,c),children:[J.showHeader!==!1&&(0,l.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start justify-between gap-3 sm:gap-4 pb-4 border-b`,children:[(0,l.jsxs)(`div`,{className:`flex items-start gap-2 sm:gap-3 flex-1 min-w-0`,children:[(J.showBack??!0)&&(0,l.jsxs)(i.Tooltip,{children:[(0,l.jsx)(i.TooltipTrigger,{asChild:!0,children:(0,l.jsx)(i.Button,{variant:`ghost`,size:`icon`,onClick:ve,className:`shrink-0 mt-1`,children:(0,l.jsx)(a.ArrowLeft,{className:`h-4 w-4`})})}),(0,l.jsx)(i.TooltipContent,{children:U(`detail.back`)})]}),(0,l.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,l.jsx)(`h1`,{className:`text-xl sm:text-2xl font-bold truncate`,children:Z(x,J,F,U(`detail.details`))}),ge.map(e=>{let t=x?.[e];if(t==null||t===``)return null;let n=(J.sections||[]).flatMap(e=>e.fields).concat(J.fields||[]).find(t=>t.name===e),r=F?.fields?.[e],a=n?.type||r?.type,o=String(t),c=null;try{if(a===`currency`){let e=Number(t);if(!Number.isNaN(e)){let t=(0,s.resolveFieldCurrency)({...r,...n},oe);o=t?new Intl.NumberFormat(void 0,{style:`currency`,currency:t,maximumFractionDigits:0}).format(e):new Intl.NumberFormat(void 0,{maximumFractionDigits:0}).format(e)}}else if(a===`date`||a===`datetime`){let e=new Date(t);Number.isNaN(e.getTime())||(o=a===`datetime`?e.toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`}):e.toLocaleDateString(void 0,{dateStyle:`medium`}))}else if(a===`percent`){let e=Number(t);if(!Number.isNaN(e)){o=`${e}%`;let t=e<=1?e*100:e;c=Math.max(0,Math.min(100,t))}}else if(a===`select`||a===`status`||a===`multiselect`){let i=n?.options||r?.options,a=String(t);if(Array.isArray(i)){let e=i.find(e=>String(e?.value??e)===String(t));e?.label&&(a=e.label)}else if(i&&typeof i==`object`){let e=i[String(t)];e?.label&&(a=e.label)}o=J.objectName?G(J.objectName,e,String(t),a):a}}catch{}return c===null?(0,l.jsx)(i.Badge,{variant:`secondary`,className:`text-xs bg-primary/10 text-primary border-transparent hover:bg-primary/15`,"aria-label":`${e}: ${o}`,children:o},e):(0,l.jsxs)(i.Badge,{variant:`secondary`,className:`text-xs bg-primary/10 text-primary border-transparent hover:bg-primary/15 gap-1.5 pl-2 pr-2`,"aria-label":`${e}: ${o}`,children:[(0,l.jsx)(`span`,{className:`relative inline-block h-1.5 w-12 rounded-full bg-primary/20 overflow-hidden`,"aria-hidden":!0,children:(0,l.jsx)(`span`,{className:`absolute inset-y-0 left-0 rounded-full bg-primary`,style:{width:`${c}%`}})}),o]},e)}),(0,l.jsxs)(i.Tooltip,{children:[(0,l.jsx)(i.TooltipTrigger,{asChild:!0,children:(0,l.jsx)(i.Button,{variant:`ghost`,size:`icon`,className:`h-6 w-6 shrink-0`,onClick:Te,"aria-label":U(O?`detail.removeFromFavorites`:`detail.addToFavorites`),children:O?(0,l.jsx)(a.Star,{className:`h-4 w-4 fill-yellow-400 text-yellow-400`}):(0,l.jsx)(a.Star,{className:`h-4 w-4 text-muted-foreground`})})}),(0,l.jsx)(i.TooltipContent,{children:U(O?`detail.removeFromFavorites`:`detail.addToFavorites`)})]})]}),J.objectName&&(0,l.jsxs)(`p`,{className:`text-sm text-muted-foreground mt-1 flex items-center gap-1`,children:[(0,l.jsx)(`span`,{className:`font-medium`,children:_||J.objectName}),J.resourceId&&(0,l.jsxs)(i.Tooltip,{children:[(0,l.jsx)(i.TooltipTrigger,{asChild:!0,children:(0,l.jsx)(i.Button,{variant:`ghost`,size:`icon`,className:`h-5 w-5 shrink-0 text-muted-foreground/60 hover:text-foreground`,onClick:_e,"aria-label":U(`detail.copyRecordId`,{defaultValue:`Copy record ID`}),children:ee?(0,l.jsx)(a.Check,{className:`h-3 w-3 text-green-600`}):(0,l.jsx)(a.Copy,{className:`h-3 w-3`})})}),(0,l.jsx)(i.TooltipContent,{children:ee?U(`detail.copied`,{defaultValue:`Copied`}):U(`detail.copyRecordId`,{defaultValue:`Copy record ID`})})]})]})]})]}),(0,l.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 shrink-0 w-full sm:w-auto`,children:[J.recordNavigation&&(0,l.jsxs)(`div`,{className:`flex items-center gap-1 mr-2`,children:[(0,l.jsxs)(i.Tooltip,{children:[(0,l.jsx)(i.TooltipTrigger,{asChild:!0,children:(0,l.jsx)(i.Button,{variant:`outline`,size:`icon`,className:`h-8 w-8`,disabled:J.recordNavigation.currentIndex<=0,onClick:()=>{let e=J.recordNavigation;e.currentIndex>0&&e.onNavigate(e.recordIds[e.currentIndex-1])},children:(0,l.jsx)(a.ChevronLeft,{className:`h-4 w-4`})})}),(0,l.jsx)(i.TooltipContent,{children:U(`detail.previousRecord`)})]}),(0,l.jsx)(`span`,{className:`text-xs text-muted-foreground whitespace-nowrap px-1`,children:U(`detail.recordOf`,{current:J.recordNavigation.currentIndex+1,total:J.recordNavigation.recordIds.length})}),(0,l.jsxs)(i.Tooltip,{children:[(0,l.jsx)(i.TooltipTrigger,{asChild:!0,children:(0,l.jsx)(i.Button,{variant:`outline`,size:`icon`,className:`h-8 w-8`,disabled:J.recordNavigation.currentIndex>=J.recordNavigation.recordIds.length-1,onClick:()=>{let e=J.recordNavigation;e.currentIndex<e.recordIds.length-1&&e.onNavigate(e.recordIds[e.currentIndex+1])},children:(0,l.jsx)(a.ChevronRight,{className:`h-4 w-4`})})}),(0,l.jsx)(i.TooltipContent,{children:U(`detail.nextRecord`)})]})]}),J.showEdit&&(0,l.jsxs)(i.Tooltip,{children:[(0,l.jsx)(i.TooltipTrigger,{asChild:!0,children:(0,l.jsxs)(i.Button,{variant:`default`,onClick:ye,className:`gap-2 hidden sm:inline-flex`,children:[(0,l.jsx)(a.Edit,{className:`h-4 w-4`}),(0,l.jsx)(`span`,{className:`hidden sm:inline`,children:U(`detail.edit`)})]})}),(0,l.jsx)(i.TooltipContent,{children:U(`detail.editRecord`)})]}),ke.map((e,t)=>(0,l.jsx)(o.SchemaRenderer,{schema:e,data:x},`header-action-${t}`))]})]}),J.header&&(0,l.jsx)(`div`,{children:(0,l.jsx)(o.SchemaRenderer,{schema:J.header,data:x})}),J.highlightFields&&J.highlightFields.length>0&&(0,l.jsx)(H,{fields:J.highlightFields,data:x,objectName:J.objectName,objectSchema:F}),m&&J.showHeader===!1&&(()=>{let e=x?.approval_status,t=e===`pending`||e===`in_approval`,r=k?.approvalPending??!1,o=r&&!(k?.locked??!1)?!1:(k?.locked??!1)||t,s=o||r||t,c=s?k?.approvalProgress:void 0,u=!!c&&c.need>0&&c.need<=12;return!s&&!N?null:(0,l.jsxs)(`div`,{className:`flex flex-col items-end gap-1`,children:[s&&(0,l.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[(0,l.jsxs)(`span`,{role:`status`,className:o?`inline-flex items-center gap-1 rounded-md border border-amber-300 bg-amber-50 px-2 py-1 text-xs text-amber-800`:`inline-flex items-center gap-1 rounded-md border border-sky-300 bg-sky-50 px-2 py-1 text-xs text-sky-800`,title:o?k?.lockedReason??U(`detail.lockedTooltip`):U(`detail.approvalPendingTooltip`),children:[o?(0,l.jsx)(a.Lock,{className:`h-3 w-3`}):(0,l.jsx)(a.Clock,{className:`h-3 w-3`}),(0,l.jsx)(`span`,{children:U(o?`detail.lockedByApproval`:`detail.approvalPendingEditable`)})]}),n?.cancelPendingApproval&&(0,l.jsxs)(i.Button,{variant:`outline`,size:`sm`,onClick:be,disabled:ie,className:o?`gap-2 border-amber-300 text-amber-800 hover:bg-amber-50`:`gap-2 border-sky-300 text-sky-800 hover:bg-sky-50`,title:U(o?`detail.cancelApprovalTooltip`:`detail.cancelApprovalTooltipUnlocked`),children:[(0,l.jsx)(a.X,{className:`h-4 w-4`}),(0,l.jsx)(`span`,{children:U(ie?`detail.cancelApprovalInFlight`:`detail.cancelApproval`)})]})]}),c&&(0,l.jsxs)(`div`,{className:`flex flex-col items-end gap-1 max-w-[16rem]`,children:[(0,l.jsxs)(`div`,{role:`progressbar`,"aria-valuemin":0,"aria-valuemax":c.need,"aria-valuenow":Math.min(c.got,c.need),"aria-label":U(`detail.approvalProgressLabel`),className:`flex items-center gap-2 w-full justify-end`,children:[(0,l.jsx)(`span`,{className:`text-[11px] text-muted-foreground whitespace-nowrap`,children:c.behavior===`per_group`?U(`detail.approvalProgressGroups`,{got:c.got,need:c.need}):U(`detail.approvalProgress`,{got:c.got,need:c.need})}),u&&(0,l.jsx)(`span`,{className:`flex items-center gap-1 w-20 shrink-0`,children:Array.from({length:c.need}).map((e,t)=>(0,l.jsx)(`span`,{"aria-hidden":`true`,className:(0,i.cn)(`h-1.5 flex-1 rounded-full`,t<c.got?`bg-emerald-500`:`bg-muted`)},t))})]}),c.groups&&c.groups.length>0&&(0,l.jsx)(`div`,{className:`flex flex-wrap justify-end gap-1`,children:c.groups.map(e=>(0,l.jsxs)(`span`,{title:`${e.got}/${e.need}`,className:(0,i.cn)(`inline-flex items-center gap-1 rounded-md border px-1.5 py-0.5 text-[11px]`,e.satisfied?`border-emerald-300 text-emerald-700`:`border-border text-muted-foreground`),children:[e.satisfied?(0,l.jsx)(a.Check,{className:`h-3 w-3`}):(0,l.jsx)(a.Circle,{className:`h-2.5 w-2.5`}),(0,l.jsx)(`span`,{children:`${e.group} ${e.got}/${e.need}`})]},e.group))})]}),N&&(0,l.jsx)(`div`,{role:`alert`,className:`text-xs text-destructive bg-destructive/10 border border-destructive/20 rounded-md px-2 py-1 max-w-md text-right`,children:N})]})})(),J.autoTabs&&!J.tabs?.length?(()=>{let e=De.length>0,t=!!J.activities&&J.activities.length>0,r=!!h,a=!!J.history,o=[`details`,...e?[`related`]:[],...t?[`activity`]:[],...r?[`discussion`]:[],...a?[`history`]:[]],s=J.defaultTab,c=s&&o.includes(s)?s:`details`,u=J.onTabChange,d=(0,l.jsxs)(`div`,{className:`space-y-3 sm:space-y-4`,children:[J.sectionGroups&&J.sectionGroups.length>0&&J.sectionGroups.map((e,t)=>(0,l.jsx)(V,{group:e,data:{...x,...j},objectSchema:F,objectName:J.objectName,isEditing:A,onFieldChange:Q,onEnterInlineEdit:m?Ee:void 0,autoFocusField:M,dataSource:n},t)),J.sections&&J.sections.length>0&&J.sections.map((e,t)=>(0,l.jsx)(R,{section:e,data:{...x,...j},objectSchema:F,objectName:J.objectName,isEditing:A,onFieldChange:Q,onEnterInlineEdit:m?Ee:void 0,autoFocusField:M,dataSource:n},t)),J.fields&&J.fields.length>0&&!J.sections?.length&&(0,l.jsx)(R,{section:{fields:J.fields,columns:J.columns},data:{...x,...j},objectSchema:F,objectName:J.objectName,isEditing:A,onFieldChange:Q,onEnterInlineEdit:m?Ee:void 0,autoFocusField:M,dataSource:n}),J.comments&&(0,l.jsx)(W,{comments:J.comments,onAddComment:J.onAddComment})]});return!e&&!t&&!r&&!a?(0,l.jsx)(`div`,{className:`mt-2`,children:d}):(0,l.jsxs)(i.Tabs,{defaultValue:c,onValueChange:u,className:`w-full`,children:[(0,l.jsxs)(i.TabsList,{className:`w-full justify-start border-b rounded-none bg-transparent p-0`,children:[(0,l.jsx)(i.TabsTrigger,{value:`details`,className:`relative rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent`,children:U(`detail.details`)}),e&&(0,l.jsx)(i.TabsTrigger,{value:`related`,className:`relative rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent`,children:(0,l.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[U(`detail.related`),(0,l.jsx)(i.Badge,{variant:`secondary`,className:`text-xs bg-primary/10 text-primary border-transparent`,children:De.length})]})}),t&&(0,l.jsx)(i.TabsTrigger,{value:`activity`,className:`relative rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent`,children:(0,l.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[U(`detail.activity`),(0,l.jsx)(i.Badge,{variant:`secondary`,className:`text-xs bg-primary/10 text-primary border-transparent`,children:J.activities.length})]})}),r&&(0,l.jsx)(i.TabsTrigger,{value:`discussion`,className:`relative rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent`,children:U(`detail.discussion`,{defaultValue:`Discussion`})}),a&&(0,l.jsx)(i.TabsTrigger,{value:`history`,className:`relative rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent`,children:(0,l.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[U(`detail.history`,{defaultValue:`History`}),!J.history.loading&&J.history.entries.length>0&&(0,l.jsx)(i.Badge,{variant:`secondary`,className:`text-xs bg-primary/10 text-primary border-transparent`,children:J.history.entries.length})]})})]}),(0,l.jsx)(i.TabsContent,{value:`details`,className:`mt-4 motion-safe:data-[state=active]:animate-in motion-safe:data-[state=active]:fade-in-0 motion-safe:duration-150`,children:d}),e&&(0,l.jsx)(i.TabsContent,{value:`related`,className:`mt-4 motion-safe:data-[state=active]:animate-in motion-safe:data-[state=active]:fade-in-0 motion-safe:duration-150`,children:(0,l.jsx)(`div`,{className:`space-y-3`,children:De.map((e,t)=>(0,l.jsx)(B,{title:e.title,type:e.type,api:e.api,data:e.data,columns:e.columns,dataSource:n,objectName:e.api,referenceField:e.referenceField,icon:e.icon,onNew:e.onNew,onViewAll:e.onViewAll,onRowClick:e.onRowClick,onRowEdit:e.onRowEdit,onRowDelete:e.onRowDelete,collapsible:!0,defaultCollapsed:se&&t>0,pageSize:X},t))})}),t&&(0,l.jsx)(i.TabsContent,{value:`activity`,className:`mt-4 motion-safe:data-[state=active]:animate-in motion-safe:data-[state=active]:fade-in-0 motion-safe:duration-150`,children:(0,l.jsx)(le,{activities:J.activities})}),r&&(0,l.jsx)(i.TabsContent,{value:`discussion`,className:`mt-4 motion-safe:data-[state=active]:animate-in motion-safe:data-[state=active]:fade-in-0 motion-safe:duration-150`,children:h}),a&&(0,l.jsx)(i.TabsContent,{value:`history`,className:`mt-4 motion-safe:data-[state=active]:animate-in motion-safe:data-[state=active]:fade-in-0 motion-safe:duration-150`,children:(0,l.jsx)(me,{entries:J.history.entries,loading:J.history.loading,emptyText:J.history.emptyText??U(`detail.historyEmpty`,{defaultValue:`No history yet`})})})]})})():(0,l.jsxs)(l.Fragment,{children:[J.sectionGroups&&J.sectionGroups.length>0&&(0,l.jsx)(`div`,{className:`space-y-3 sm:space-y-4`,children:J.sectionGroups.map((e,t)=>(0,l.jsx)(V,{group:e,data:{...x,...j},objectSchema:F,objectName:J.objectName,isEditing:A,onFieldChange:Q,onEnterInlineEdit:m?Ee:void 0,autoFocusField:M,dataSource:n},t))}),J.sections&&J.sections.length>0&&(0,l.jsx)(`div`,{className:`space-y-3 sm:space-y-4`,children:J.sections.map((e,t)=>(0,l.jsx)(R,{section:e,data:{...x,...j},objectSchema:F,objectName:J.objectName,isEditing:A,onFieldChange:Q,onEnterInlineEdit:m?Ee:void 0,autoFocusField:M,dataSource:n},t))}),J.fields&&J.fields.length>0&&!J.sections?.length&&(0,l.jsx)(R,{section:{fields:J.fields,columns:J.columns},data:{...x,...j},objectSchema:F,objectName:J.objectName,isEditing:A,onFieldChange:Q,onEnterInlineEdit:m?Ee:void 0,autoFocusField:M,dataSource:n}),J.tabs&&J.tabs.length>0&&(0,l.jsx)(ne,{tabs:J.tabs,data:x}),De.length>0&&(0,l.jsxs)(`div`,{className:`space-y-3`,children:[(0,l.jsx)(`h2`,{className:`text-lg font-semibold`,children:U(`detail.related`)}),De.map((e,t)=>(0,l.jsx)(B,{title:e.title,type:e.type,api:e.api,data:e.data,columns:e.columns,dataSource:n,objectName:e.api,referenceField:e.referenceField,icon:e.icon,onNew:e.onNew,onViewAll:e.onViewAll,onRowClick:e.onRowClick,onRowEdit:e.onRowEdit,onRowDelete:e.onRowDelete,collapsible:!0,defaultCollapsed:se&&t>0,pageSize:X},t))]}),J.comments&&(0,l.jsx)(W,{comments:J.comments,onAddComment:J.onAddComment}),J.activities&&J.activities.length>0&&(0,l.jsx)(le,{activities:J.activities})]}),(0,l.jsx)(xe,{data:{...x,...j},objectSchema:F,objectName:J.objectName}),J.footer&&(0,l.jsx)(`div`,{children:(0,l.jsx)(o.SchemaRenderer,{schema:J.footer,data:x})})]})})},Q=e=>(0,t.columnIdentity)(e)??null,Ee=e=>{let{"data-obj-id":t,"data-obj-type":n,style:r,...i}=e||{};return{designer:{"data-obj-id":t,"data-obj-type":n,style:r},rest:i}},De=({schema:e={},className:n,...r})=>{let i=(0,o.useRecordContext)(),{designer:a}=Ee(r),c=i?.objectName||``,d=(0,u.usePermissions)(),{readableFields:f}=(0,u.useFieldPermissions)(c),{sectionLabel:p}=(0,o.useSafeFieldLabel)(),{language:m}=(0,s.useObjectTranslation)(),h=(0,o.useHighlightFieldNames)();if(!i)return(0,l.jsx)(`div`,{className:n,"data-record-details-placeholder":!0,...a,children:(0,l.jsx)(`div`,{className:`text-xs text-muted-foreground italic px-3 py-2 border border-dashed rounded`,children:`record:details — bind a record to preview`})});let g=Array.isArray(e.requiredPermissions)?e.requiredPermissions:[];if(g.length>0&&c&&!g.every(e=>d.can(c,e)))return(0,l.jsx)(`div`,{className:n,...a,role:`status`,"aria-live":`polite`,children:(0,l.jsx)(`p`,{className:`text-sm text-muted-foreground italic`,children:`Insufficient permissions to view details.`})});let _=e.layout===`inline`||e.layout===`compact`?`horizontal`:`vertical`,v=e.enforceFieldSecurity===!0,y=Array.isArray(e.redactFields)?e.redactFields:[],b=e=>{if(!e||!v&&y.length===0)return e;let t=e.map(Q).filter(e=>!!e),n=new Set((v&&c?f(t):t).filter(e=>!y.includes(e)));return e.filter(e=>{let t=Q(e);return!t||n.has(t)})},x=e=>typeof e==`string`?{name:e}:e&&typeof e==`object`&&!e.name&&e.field?{...e,name:e.field}:e,S=e=>Array.isArray(e)?e.map(x):e,C=new Set((Array.isArray(e.hideFields)?e.hideFields:[]).map(e=>typeof e==`string`?e:Q(e)).filter(e=>!!e));for(let e of h)C.add(e);let w=i.objectSchema,T=i.data??{},E=[w?.primaryField,`name`,`full_name`,`title`,`subject`,`display_name`,`label`].filter(e=>typeof e==`string`&&e.length>0);for(let e of E)if(T[e]!==void 0&&T[e]!==null&&T[e]!==``){C.add(e);break}let D=e=>!e||C.size===0?e:e.filter(e=>{let t=Q(e);return!t||!C.has(t)}),O=D(S(b(e.fields))),k=Array.isArray(e.sections)?e.sections.map(e=>{let t=e.title??e.label,n=t==null?void 0:(0,s.pickLocalized)(t,m),r=e.name&&c?p(c,e.name,n??e.name):n;return{...e,title:r,showBorder:e.showBorder??!!r,hideEmpty:e.hideEmpty??!0,fields:D(S(b(e.fields)))}}):e.sections,A=(0,t.isObjectInlineEditable)(w,d?.getObjectApiOperations?.(c)),j=(e.inlineEdit??!0)&&A,M={type:`detail-view`,objectName:i.objectName,resourceId:i.recordId,data:i.data,layout:_,columns:e.columns,sections:k,fields:O,showBack:!1,showHeader:e.showHeader??!1,inlineEdit:j};return(0,l.jsx)(`div`,{className:n,...a,children:(0,l.jsx)(Te,{schema:M,dataSource:i.dataSource,inlineEdit:j})})},Oe=e=>(0,t.columnIdentity)(e)||(e&&typeof e==`object`?e.key:null)||null,ke=e=>e?.id??e?._id??null,Ae=5,je=e=>{let{"data-obj-id":t,"data-obj-type":n,style:r,...i}=e||{};return{designer:{"data-obj-id":t,"data-obj-type":n,style:r},rest:i}},Me=({schema:e={},className:t,...i})=>{let a=(0,o.useRecordContext)(),{designer:c}=je(i),d=(0,o.useSafeFieldLabel)(),{language:f}=(0,s.useObjectTranslation)(),p=e.objectName,m=p&&d.objectLabel?d.objectLabel({name:p,label:(0,n.humanizeLabel)(p)}):p?(0,n.humanizeLabel)(p):``,h=(0,s.pickLocalized)(e.title,f)||m||`Related`,g=(0,u.usePermissions)(),{readableFields:_}=(0,u.useFieldPermissions)(p||``),v=e.relationshipValueField||`id`,y=v===`id`?a?.recordId??null:a?.data?.[v]??null,b=(0,o.useRelatedRecordActions)(),x=r.default.useMemo(()=>b?.resolve({objectName:p,relationshipField:e.relationshipField,parentId:y})??null,[b,p,e.relationshipField,y]);if(!p)return(0,l.jsx)(`div`,{className:t,...c,children:(0,l.jsx)(`div`,{className:`text-xs text-muted-foreground italic px-3 py-2 border border-dashed rounded`,children:`record:related_list — missing objectName`})});if(g.isLoaded&&!g.can(p,`read`))return null;let S=Array.isArray(e.requiredPermissions)?e.requiredPermissions:[];if(S.length>0&&!S.every(e=>g.can(p,e)))return(0,l.jsx)(`div`,{className:t,...c,role:`status`,"aria-live":`polite`,children:(0,l.jsx)(`p`,{className:`text-sm text-muted-foreground italic`,children:`Insufficient permissions to view related list.`})});let C=e.enforceFieldSecurity===!0,w=Array.isArray(e.redactFields)?e.redactFields:[],T=Array.isArray(e.columns)?e.columns:[],E=T;if(C||w.length>0){let e=T.map(Oe).filter(e=>!!e),t=new Set((C?_(e):e).filter(e=>!w.includes(e)));E=T.filter(e=>{let n=Oe(e);return!n||t.has(n)})}return(0,l.jsx)(`div`,{className:t,...c,children:(0,l.jsx)(B,{title:h,type:`table`,api:p,objectName:p,referenceField:e.relationshipField,parentId:y,columns:E,pageSize:typeof e.limit==`number`&&e.limit>0?e.limit:Ae,defaultSort:e.sort,dataSource:a?.dataSource,add:e.add?{...e.add,label:(0,s.pickLocalized)(e.add.label,f)||void 0}:void 0,rowActions:x?.rowActions,onRowAction:x?.onRowAction,toolbarActions:x?.toolbarActions,onToolbarAction:x?.onToolbarAction,onNew:x?.onCreate,onRowClick:x?.onView?e=>{let t=ke(e);t!=null&&x.onView(t,e)}:void 0,onRowEdit:x?.onEdit?e=>{let t=ke(e);t!=null&&x.onEdit(t,e)}:void 0,onRowDelete:x?.onDelete?e=>{let t=ke(e);if(t!=null)return x.onDelete(t,e)}:e.add&&a?.dataSource?async e=>{let t=e?.id??e?._id;t!=null&&await a.dataSource.delete?.(p,String(t))}:void 0})})},Ne=e=>{let{"data-obj-id":t,"data-obj-type":n,style:r,...i}=e||{};return{designer:{"data-obj-id":t,"data-obj-type":n,style:r},rest:i}},Pe=({schema:e={},className:t,...n})=>{let i=(0,o.useRecordContext)(),{designer:a}=Ne(n),s=i?.objectName||``,c=(0,u.usePermissions)(),{readableFields:d}=(0,u.useFieldPermissions)(s),f=Array.isArray(e.requiredPermissions)?e.requiredPermissions:[],p=!(f.length>0&&s)||f.every(e=>c.can(s,e)),m=(Array.isArray(e.fields)?e.fields:[]).map(e=>typeof e==`string`?{name:e}:{name:e?.name,label:e?.label,icon:e?.icon,type:e?.type,readonly:e?.readonly===!0}).filter(e=>typeof e.name==`string`&&e.name.length>0),h=e.enforceFieldSecurity===!0,g=Array.isArray(e.redactFields)?e.redactFields:[],_=h&&s?new Set(d(m.map(e=>e.name))):null,v=m.filter(e=>!(g.includes(e.name)||_&&!_.has(e.name))),y=r.default.useId();return(0,o.useRegisterHighlightFields)(y,p?v.map(e=>e.name):[]),p?(0,l.jsx)(`div`,{className:t,...a,children:(0,l.jsx)(H,{fields:v,data:i?.data,objectName:i?.objectName,objectSchema:i?.objectSchema,dataSource:i?.dataSource})}):(0,l.jsx)(`div`,{className:t,...a,role:`status`,"aria-live":`polite`,children:(0,l.jsx)(`p`,{className:`text-sm text-muted-foreground italic`,children:`Insufficient permissions to view highlights.`})})},Fe=({change:e,className:t})=>{let n=e.fieldLabel??e.field.charAt(0).toUpperCase()+e.field.slice(1).replace(/_/g,` `),r=e.oldDisplayValue??(e.oldValue==null?`(empty)`:String(e.oldValue)),o=e.newDisplayValue??(e.newValue==null?`(empty)`:String(e.newValue));return(0,l.jsxs)(`div`,{className:(0,i.cn)(`flex items-center gap-1.5 text-sm flex-wrap`,t),children:[(0,l.jsx)(`span`,{className:`font-medium text-foreground`,children:n}),(0,l.jsx)(`span`,{className:`text-muted-foreground line-through`,children:r}),(0,l.jsx)(a.ArrowRight,{className:`h-3 w-3 text-muted-foreground shrink-0`}),(0,l.jsx)(`span`,{className:`text-foreground`,children:o})]})},Ie=[`👍`,`❤️`,`🎉`,`😂`,`😮`,`😢`],Le=({reactions:e,onToggleReaction:t,emojiOptions:n=Ie,className:o})=>{let[s,c]=r.useState(!1),{t:u}=D(),d=r.useCallback(e=>{t?.(e),c(!1)},[t]);return(0,l.jsxs)(`div`,{className:(0,i.cn)(`flex items-center gap-1 flex-wrap`,o),children:[e.map(e=>{let n=u(e.count===1?`detail.reactionCountOne`:`detail.reactionCount`,{emoji:e.emoji,count:e.count});return(0,l.jsxs)(`button`,{type:`button`,className:(0,i.cn)(`inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-xs border transition-colors`,e.reacted?`bg-primary/10 border-primary/30 text-primary`:`bg-muted border-border text-muted-foreground hover:bg-muted/80`),onClick:()=>d(e.emoji),disabled:!t,"aria-label":n,children:[(0,l.jsx)(`span`,{children:e.emoji}),(0,l.jsx)(`span`,{children:e.count})]},e.emoji)}),t&&(0,l.jsxs)(`div`,{className:`relative`,children:[(0,l.jsx)(i.Button,{variant:`ghost`,size:`icon`,className:`h-6 w-6`,onClick:()=>c(!s),"aria-label":u(`detail.addReaction`),children:(0,l.jsx)(a.SmilePlus,{className:`h-3.5 w-3.5`})}),s&&(0,l.jsx)(`div`,{className:`absolute bottom-full mb-1 left-0 bg-popover border rounded-md shadow-md z-50 p-1.5 flex gap-1`,role:`listbox`,"aria-label":u(`detail.emojiPicker`),children:n.map(t=>(0,l.jsx)(`button`,{type:`button`,className:`hover:bg-accent rounded p-1 text-base transition-colors`,onClick:()=>d(t),role:`option`,"aria-selected":e.some(e=>e.emoji===t&&e.reacted),children:t},t))})]})]})};function Re(e,t){try{let n=new Date(e),r=new Date().getTime()-n.getTime(),i=Math.floor(r/6e4);if(i<1)return t(`detail.justNow`);if(i<60)return t(`detail.minutesAgo`,{count:i});let a=Math.floor(i/60);if(a<24)return t(`detail.hoursAgo`,{count:a});let o=Math.floor(a/24);return o<7?t(`detail.daysAgo`,{count:o}):n.toLocaleDateString()}catch{return e}}var ze=({parentItem:e,replies:t,onAddReply:n,showReplyInput:o=!0,className:s})=>{let{t:c}=D(),[u,d]=r.useState(!1),[f,p]=r.useState(``),[m,h]=r.useState(!1),g=r.useCallback(async()=>{let t=f.trim();if(!(!t||!n)){h(!0);try{await n(e.id,t),p(``)}finally{h(!1)}}},[f,n,e.id]),_=r.useCallback(e=>{e.key===`Enter`&&(e.ctrlKey||e.metaKey)&&(e.preventDefault(),g())},[g]);return t.length===0&&!o?null:(0,l.jsxs)(`div`,{className:(0,i.cn)(`ml-10 mt-1`,s),children:[t.length>0&&(0,l.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors mb-1`,onClick:()=>d(!u),"aria-expanded":u,children:[u?(0,l.jsx)(a.ChevronDown,{className:`h-3 w-3`}):(0,l.jsx)(a.ChevronRight,{className:`h-3 w-3`}),(0,l.jsx)(a.MessageSquare,{className:`h-3 w-3`}),(0,l.jsx)(`span`,{children:t.length===1?c(`detail.replyCount`,{count:t.length}):c(`detail.replyCountPlural`,{count:t.length})})]}),u&&(0,l.jsx)(`div`,{className:`space-y-2 border-l-2 border-border pl-3`,children:t.map(e=>(0,l.jsxs)(`div`,{className:`flex gap-2`,children:[(0,l.jsx)(`div`,{className:`shrink-0`,children:e.actorAvatarUrl?(0,l.jsx)(`img`,{src:e.actorAvatarUrl,alt:e.actor,className:`h-6 w-6 rounded-full object-cover`}):(0,l.jsx)(`div`,{className:`h-6 w-6 rounded-full bg-muted flex items-center justify-center text-[10px] font-medium text-muted-foreground`,children:e.actor.charAt(0).toUpperCase()})}),(0,l.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,l.jsx)(`span`,{className:`text-xs font-medium`,children:e.actor}),(0,l.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:Re(e.createdAt,c)})]}),(0,l.jsx)(`p`,{className:`text-xs whitespace-pre-wrap break-words`,children:e.body})]})]},e.id))}),o&&n&&(0,l.jsxs)(`div`,{className:`flex gap-1.5 mt-1.5`,children:[(0,l.jsx)(`input`,{className:`flex-1 rounded-md border border-input bg-background px-2 py-1 text-xs placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`,placeholder:c(`detail.replyPlaceholder`),value:f,onChange:e=>p(e.target.value),onKeyDown:_,disabled:m}),(0,l.jsx)(i.Button,{variant:`ghost`,size:`icon`,className:`h-6 w-6 shrink-0`,onClick:g,disabled:!f.trim()||m,"aria-label":`Send reply`,children:(0,l.jsx)(a.Send,{className:`h-3 w-3`})})]})]})},Be=({subscription:e,onToggle:t,className:n})=>{let{t:o}=D(),[s,c]=r.useState(!1),u=r.useCallback(async()=>{if(t){c(!0);try{await t(!e.subscribed)}finally{c(!1)}}},[t,e.subscribed]);return(0,l.jsx)(i.Button,{variant:`ghost`,size:`icon`,className:(0,i.cn)(`h-8 w-8`,n),onClick:u,disabled:s||!t,"aria-label":e.subscribed?o(`detail.unsubscribeAriaLabel`):o(`detail.subscribeAriaLabel`),title:e.subscribed?o(`detail.subscribedTooltip`):o(`detail.unsubscribedTooltip`),children:e.subscribed?(0,l.jsx)(a.Bell,{className:`h-4 w-4 text-primary`}):(0,l.jsx)(a.BellOff,{className:`h-4 w-4 text-muted-foreground`})})};function Ve(e){let t=e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/```([\s\S]*?)```/g,`<pre class="bg-muted rounded p-2 text-xs font-mono my-1 overflow-x-auto">$1</pre>`).replace(/`([^`]+)`/g,`<code class="bg-muted rounded px-1 py-0.5 text-xs font-mono">$1</code>`).replace(/\*\*(.+?)\*\*/g,`<strong>$1</strong>`).replace(/\*(.+?)\*/g,`<em>$1</em>`).replace(/@(\w+)/g,`<span class="text-primary font-medium">@$1</span>`).replace(/^- (.+)$/gm,`<li class="ml-4 list-disc">$1</li>`).replace(/\n/g,`<br/>`);return t=t.replace(/(<li[^>]*>.*?<\/li>(?:<br\/>)?)+/g,e=>`<ul class="my-1">${e.replace(/<br\/>/g,``)}</ul>`),t}var He=({value:e,onChange:t,onSubmit:n,mentionSuggestions:o=[],placeholder:s,className:c,disabled:u=!1,extraSlot:d,canSubmitEmpty:f=!1})=>{let{t:p}=D(),[m,h]=r.useState(!1),[g,_]=r.useState(!1),[v,y]=r.useState(``),[b,x]=r.useState(0),S=r.useRef(null),C=r.useMemo(()=>{if(!v)return o;let e=v.toLowerCase();return o.filter(t=>t.label.toLowerCase().includes(e))},[v,o]),w=r.useCallback((n,r=``)=>{let i=S.current;if(!i)return;let a=i.selectionStart,o=i.selectionEnd,s=e.slice(a,o);t(e.slice(0,a)+n+s+r+e.slice(o)),requestAnimationFrame(()=>{i.focus();let e=a+n.length+s.length;i.setSelectionRange(e,e)})},[e,t]),T=r.useCallback(()=>w(`**`,`**`),[w]),E=r.useCallback(()=>w(`*`,`*`),[w]),O=r.useCallback(()=>w(`
2
+ - `,``),[w]),k=r.useCallback(()=>w("`","`"),[w]),A=r.useCallback(()=>{w(`@`,``),_(!0),y(``),x(0)},[w]),j=r.useCallback(n=>{let r=S.current;if(!r)return;let i=r.selectionStart,a=e.slice(0,i).lastIndexOf(`@`);a!==-1&&t(e.slice(0,a)+`@${n.label} `+e.slice(i)),_(!1),y(``),requestAnimationFrame(()=>r.focus())},[e,t]),M=r.useCallback(e=>{let n=e.target.value;t(n);let r=e.target.selectionStart,i=n.slice(0,r),a=i.lastIndexOf(`@`);if(a!==-1){let e=i.slice(a+1),t=a>0?i[a-1]:` `;if(/\s/.test(t)&&!/\s/.test(e)){_(!0),y(e),x(0);return}}_(!1)},[t]),N=r.useCallback(e=>{if(g&&C.length>0){if(e.key===`ArrowDown`){e.preventDefault(),x(e=>e<C.length-1?e+1:0);return}if(e.key===`ArrowUp`){e.preventDefault(),x(e=>e>0?e-1:C.length-1);return}if(e.key===`Enter`||e.key===`Tab`){e.preventDefault(),j(C[b]);return}if(e.key===`Escape`){_(!1);return}}e.key===`Enter`&&(e.ctrlKey||e.metaKey)&&(e.preventDefault(),n?.())},[g,C,b,j,n]);return(0,l.jsxs)(`div`,{className:(0,i.cn)(`border rounded-md`,c),children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-0.5 px-2 py-1.5 border-b bg-muted/30`,children:[(0,l.jsx)(i.Button,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:T,disabled:u||m,title:p(`detail.bold`),children:(0,l.jsx)(a.Bold,{className:`h-3.5 w-3.5`})}),(0,l.jsx)(i.Button,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:E,disabled:u||m,title:p(`detail.italic`),children:(0,l.jsx)(a.Italic,{className:`h-3.5 w-3.5`})}),(0,l.jsx)(i.Button,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:O,disabled:u||m,title:p(`detail.listFormat`),children:(0,l.jsx)(a.List,{className:`h-3.5 w-3.5`})}),(0,l.jsx)(i.Button,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:k,disabled:u||m,title:p(`detail.inlineCode`),children:(0,l.jsx)(a.Code,{className:`h-3.5 w-3.5`})}),(0,l.jsx)(i.Button,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:A,disabled:u||m,title:p(`detail.mentionSomeone`),children:(0,l.jsx)(a.AtSign,{className:`h-3.5 w-3.5`})}),(0,l.jsx)(`div`,{className:`flex-1`}),(0,l.jsx)(i.Button,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:()=>h(!m),title:p(m?`detail.edit`:`detail.preview`),children:m?(0,l.jsx)(a.Edit,{className:`h-3.5 w-3.5`}):(0,l.jsx)(a.Eye,{className:`h-3.5 w-3.5`})}),n&&(0,l.jsx)(i.Button,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:n,disabled:u||!f&&!e.trim(),title:p(`detail.submitComment`),children:(0,l.jsx)(a.Send,{className:`h-3.5 w-3.5`})})]}),(0,l.jsx)(`div`,{className:`relative`,children:m?(0,l.jsx)(`div`,{className:`min-h-[80px] px-3 py-2 text-sm prose prose-sm max-w-none`,dangerouslySetInnerHTML:{__html:Ve(e)}}):(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`textarea`,{ref:S,className:`w-full min-h-[80px] px-3 py-2 text-sm bg-transparent resize-none focus:outline-none placeholder:text-muted-foreground`,placeholder:s??p(`detail.writeComment`),value:e,onChange:M,onKeyDown:N,disabled:u}),g&&C.length>0&&(0,l.jsx)(`div`,{className:`absolute left-2 bottom-full mb-1 w-56 bg-popover border rounded-md shadow-md z-50 max-h-40 overflow-y-auto`,children:C.map((e,t)=>(0,l.jsxs)(`button`,{type:`button`,className:(0,i.cn)(`w-full text-left px-3 py-1.5 text-sm flex items-center gap-2 hover:bg-accent transition-colors`,t===b&&`bg-accent`),onMouseDown:t=>{t.preventDefault(),j(e)},children:[e.avatarUrl?(0,l.jsx)(`img`,{src:e.avatarUrl,alt:e.label,className:`h-5 w-5 rounded-full object-cover`}):(0,l.jsx)(`div`,{className:`h-5 w-5 rounded-full bg-muted flex items-center justify-center text-[10px] font-medium`,children:e.label.charAt(0).toUpperCase()}),(0,l.jsx)(`span`,{children:e.label})]},e.id))})]})}),d&&(0,l.jsx)(`div`,{className:`border-t px-2 py-2 bg-muted/20`,children:d})]})};function Ue(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}function We(e){return e.startsWith(`image/`)}function Ge(e){return We(e)?a.Image:e.includes(`pdf`)||e.includes(`document`)||e.includes(`text`)?a.FileText:e.includes(`zip`)||e.includes(`archive`)||e.includes(`compressed`)?a.FileArchive:a.File}var Ke=({attachments:e,onUpload:t,onRemove:n,className:o,readOnly:s=!1})=>{let{t:c}=D(),[u,d]=r.useState(!1),f=r.useRef(null),p=r.useCallback(e=>{e.preventDefault(),e.stopPropagation(),d(!0)},[]),m=r.useCallback(e=>{e.preventDefault(),e.stopPropagation(),d(!1)},[]),h=r.useCallback(e=>{e.preventDefault(),e.stopPropagation(),d(!1),t&&e.dataTransfer.files.length>0&&t(e.dataTransfer.files)},[t]),g=r.useCallback(e=>{t&&e.target.files&&e.target.files.length>0&&(t(e.target.files),e.target.value=``)},[t]);return(0,l.jsxs)(`div`,{className:(0,i.cn)(`space-y-2`,o),children:[t&&!s&&(0,l.jsxs)(`div`,{className:(0,i.cn)(`border-2 border-dashed rounded-md px-4 py-3 text-center transition-colors cursor-pointer`,u?`border-primary bg-primary/5`:`border-muted-foreground/25 hover:border-muted-foreground/40`),onDragOver:p,onDragLeave:m,onDrop:h,onClick:()=>f.current?.click(),role:`button`,tabIndex:0,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),f.current?.click())},children:[(0,l.jsx)(a.Upload,{className:`h-5 w-5 mx-auto text-muted-foreground mb-1`}),(0,l.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:c(`detail.dropFilesToUpload`)}),(0,l.jsx)(`input`,{ref:f,type:`file`,multiple:!0,className:`hidden`,onChange:g})]}),e.length>0&&(0,l.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,l.jsx)(a.Paperclip,{className:`h-3 w-3`}),(0,l.jsx)(`span`,{children:e.length===1?c(`detail.attachmentCount`,{count:e.length}):c(`detail.attachmentCountPlural`,{count:e.length})})]}),(0,l.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2`,children:e.map(e=>{let t=We(e.type),r=Ge(e.type);return(0,l.jsxs)(`div`,{className:`flex items-center gap-2 rounded-md border px-2.5 py-2 bg-muted/30 group`,children:[t&&(e.thumbnailUrl||e.url)?(0,l.jsx)(`img`,{src:e.thumbnailUrl||e.url,alt:e.name,className:`h-10 w-10 rounded object-cover shrink-0`}):(0,l.jsx)(`div`,{className:`h-10 w-10 rounded bg-muted flex items-center justify-center shrink-0`,children:(0,l.jsx)(r,{className:`h-5 w-5 text-muted-foreground`})}),(0,l.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,l.jsx)(`p`,{className:`text-xs font-medium truncate`,children:e.name}),(0,l.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:Ue(e.size)})]}),n&&!s&&(0,l.jsx)(i.Button,{variant:`ghost`,size:`icon`,className:`h-6 w-6 shrink-0 opacity-0 group-hover:opacity-100 transition-opacity`,onClick:()=>n(e.id),title:c(`detail.removeAttachment`),children:(0,l.jsx)(a.X,{className:`h-3.5 w-3.5`})})]},e.id)})})]})]})},qe={comment:a.MessageSquare,field_change:a.Edit,task:a.CheckSquare,event:a.Calendar,system:a.Zap,email:a.Mail,call:a.Phone,note:a.StickyNote,file:a.FileText,sharing:a.Share2,record_create:a.PlusCircle,record_delete:a.Trash2,approval:a.BadgeCheck},Je={comment:`bg-purple-100 text-purple-600`,field_change:`bg-blue-100 text-blue-600`,task:`bg-green-100 text-green-600`,event:`bg-amber-100 text-amber-600`,system:`bg-gray-100 text-gray-600`,email:`bg-indigo-100 text-indigo-600`,call:`bg-teal-100 text-teal-600`,note:`bg-yellow-100 text-yellow-700`,file:`bg-slate-100 text-slate-600`,sharing:`bg-sky-100 text-sky-600`,record_create:`bg-emerald-100 text-emerald-600`,record_delete:`bg-red-100 text-red-600`,approval:`bg-violet-100 text-violet-600`};function Ye(e){return[{value:`all`,label:e(`detail.allActivity`)},{value:`comments_only`,label:e(`detail.commentsOnly`)},{value:`changes_only`,label:e(`detail.fieldChangesFilter`)},{value:`tasks_only`,label:e(`detail.tasksOnly`)}]}function Xe(e,t){try{let n=new Date(e),r=new Date().getTime()-n.getTime(),i=Math.floor(r/6e4);if(i<1)return t(`detail.justNow`);if(i<60)return t(`detail.minutesAgo`,{count:i});let a=Math.floor(i/60);if(a<24)return t(`detail.hoursAgo`,{count:a});let o=Math.floor(a/24);return o<7?t(`detail.daysAgo`,{count:o}):n.toLocaleDateString()}catch{return e}}function $(e,t){switch(t){case`comments_only`:return e.filter(e=>e.type===`comment`);case`changes_only`:return e.filter(e=>e.type===`field_change`);case`tasks_only`:return e.filter(e=>e.type===`task`);default:return e}}var Ze=({items:e,config:t,filterMode:n,onFilterChange:o,hasMore:s=!1,onLoadMore:c,loading:u=!1,onAddComment:d,onAddReply:f,onToggleReaction:p,subscription:m,onToggleSubscription:h,collapseWhenEmpty:g=!1,mentionSuggestions:_,onUploadAttachments:v,titleLabel:y,emptyLabel:b,className:x})=>{let{t:S}=D(),[C,w]=r.useState(`all`),[T,E]=r.useState(``),[O,k]=r.useState(!1),[A,j]=r.useState(!1),[M,N]=r.useState([]),[P,F]=r.useState(!1),I=n??C,ee=t?.showFilterToggle!==!1,L=t?.showCommentInput!==!1&&!!d,te=t?.enableReactions??!1,R=t?.enableThreading??!1,ne=t?.showSubscriptionToggle??!1,z=r.useMemo(()=>$(e,I),[e,I]),re=r.useMemo(()=>R?z.filter(e=>!e.parentId):z,[z,R]),ie=r.useMemo(()=>{if(!R)return new Map;let e=new Map;for(let t of z)if(t.parentId){let n=e.get(t.parentId)??[];n.push(t),e.set(t.parentId,n)}return e},[z,R]),ae=r.useCallback(e=>{o?o(e):w(e)},[o]),B=r.useCallback(async()=>{let e=T.trim();if(d&&!(!e&&M.length===0)){k(!0);try{await d(e,M.length>0?M:void 0),E(``),N([])}finally{k(!1)}}},[T,M,d]),V=r.useCallback(async e=>{if(!(!v||e.length===0)){F(!0);try{let t=await v(e);Array.isArray(t)&&t.length>0&&N(e=>[...e,...t])}finally{F(!1)}}},[v]),H=r.useCallback(e=>{N(t=>t.filter(t=>t.id!==e))},[]),U=r.useCallback(async()=>{if(c){j(!0);try{await c()}finally{j(!1)}}},[c]);return(0,l.jsxs)(`section`,{className:(0,i.cn)(`border-t border-border/60 pt-5`,x),"aria-label":`Discussion`,children:[(0,l.jsx)(`header`,{className:`mb-4`,children:(0,l.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,l.jsxs)(`h2`,{className:`flex items-center gap-2 text-base font-semibold leading-none tracking-tight`,children:[(0,l.jsx)(a.Activity,{className:`h-4 w-4`}),y??S(`detail.activity`),(0,l.jsxs)(`span`,{className:`text-sm font-normal text-muted-foreground`,children:[`(`,z.length,`)`]})]}),(0,l.jsx)(`div`,{className:`flex items-center gap-1`,children:ne&&m&&(0,l.jsx)(Be,{subscription:m,onToggle:h})})]})}),(0,l.jsxs)(`div`,{className:`space-y-4`,children:[ee&&(0,l.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,l.jsxs)(i.Select,{value:I,onValueChange:e=>ae(e),children:[(0,l.jsx)(i.SelectTrigger,{"aria-label":S(`detail.filterActivity`),className:`h-8 w-auto min-w-[140px] py-1 text-sm`,children:(0,l.jsx)(i.SelectValue,{})}),(0,l.jsx)(i.SelectContent,{children:Ye(S).map(e=>(0,l.jsx)(i.SelectItem,{value:e.value,children:e.label},e.value))})]})}),L&&(0,l.jsx)(He,{value:T,onChange:E,onSubmit:B,mentionSuggestions:_,placeholder:S(`detail.leaveCommentPlaceholder`),disabled:O,canSubmitEmpty:M.length>0,extraSlot:v?(0,l.jsx)(Ke,{attachments:M,onUpload:V,onRemove:H,readOnly:O||P}):M.length>0?(0,l.jsx)(Ke,{attachments:M,onRemove:H,readOnly:O}):void 0}),u&&z.length===0?(0,l.jsxs)(`div`,{role:`status`,"aria-live":`polite`,"data-testid":`activity-loading`,className:`flex items-center justify-center gap-2 py-6 text-sm text-muted-foreground`,children:[(0,l.jsx)(a.Loader2,{className:`h-4 w-4 animate-spin`}),(0,l.jsx)(`span`,{children:S(`detail.loading`)})]}):z.length===0?g?null:(0,l.jsx)(i.DataEmptyState,{title:b??S(`detail.noActivity`),className:`py-6`}):(0,l.jsxs)(`div`,{className:`relative`,children:[(0,l.jsx)(`div`,{className:`absolute left-4 top-2 bottom-2 w-px bg-border`}),(0,l.jsx)(`div`,{className:`space-y-4`,children:re.map(e=>{let t=qe[e.type]||a.Zap,n=Je[e.type]||`bg-gray-100 text-gray-600`,r=ie.get(e.id)??[];return(0,l.jsxs)(`div`,{children:[(0,l.jsxs)(`div`,{className:`flex gap-3 relative`,children:[(0,l.jsx)(`div`,{className:(0,i.cn)(`shrink-0 h-8 w-8 rounded-full flex items-center justify-center z-10`,n),children:e.actorAvatarUrl?(0,l.jsx)(`img`,{src:e.actorAvatarUrl,alt:e.actor,className:`h-8 w-8 rounded-full object-cover`}):(0,l.jsx)(t,{className:`h-3.5 w-3.5`})}),(0,l.jsxs)(`div`,{className:`flex-1 min-w-0 pt-1`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2 mb-0.5`,children:[(0,l.jsx)(`span`,{className:`text-sm font-medium`,children:e.actor}),e.source&&(0,l.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:S(`detail.via`,{source:e.source})}),(0,l.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:Xe(e.createdAt,S)}),e.edited&&(0,l.jsx)(`span`,{className:`text-xs text-muted-foreground italic`,children:S(`detail.edited`)}),e.pinned&&(0,l.jsxs)(`span`,{className:`text-xs text-amber-600`,children:[`📌 `,S(`detail.pinned`)]})]}),e.body&&(0,l.jsx)(`p`,{className:`text-sm whitespace-pre-wrap break-words text-muted-foreground`,children:e.body}),e.sourceObject&&e.sourceId!=null&&(0,l.jsxs)(`a`,{href:`/objects/${e.sourceObject}/${e.sourceId}`,className:`mt-1 inline-flex items-center gap-1 text-xs text-primary hover:underline`,"data-testid":`activity-source-link`,children:[S(`detail.viewSource`),(0,l.jsx)(`span`,{"aria-hidden":!0,children:`→`})]}),e.type===`field_change`&&e.fieldChanges&&(0,l.jsx)(`div`,{className:`space-y-1 mt-1`,children:e.fieldChanges.map((e,t)=>(0,l.jsx)(Fe,{change:e},t))}),te&&e.reactions&&e.reactions.length>0&&(0,l.jsx)(`div`,{className:`mt-1.5`,children:(0,l.jsx)(Le,{reactions:e.reactions,onToggleReaction:p?t=>p(e.id,t):void 0})}),te&&(!e.reactions||e.reactions.length===0)&&p&&(0,l.jsx)(`div`,{className:`mt-1.5`,children:(0,l.jsx)(Le,{reactions:[],onToggleReaction:t=>p(e.id,t)})})]})]}),R&&(e.replyCount??0)>0&&(0,l.jsx)(ze,{parentItem:e,replies:r,onAddReply:f,showReplyInput:!!f})]},e.id)})})]}),s&&(0,l.jsx)(`div`,{className:`text-center pt-2`,children:(0,l.jsxs)(i.Button,{variant:`ghost`,size:`sm`,onClick:U,disabled:A,"aria-label":S(`detail.loadMore`),children:[A?(0,l.jsx)(a.Loader2,{className:`h-4 w-4 animate-spin mr-1`}):(0,l.jsx)(a.ChevronDown,{className:`h-4 w-4 mr-1`}),S(`detail.loadMore`)]})})]})]})},Qe=f.FeedFilterMode.options,$e=f.FeedItemType.options,et={created:`field_change`,updated:`field_change`,deleted:`field_change`,assigned:`field_change`,shared:`field_change`,system:`system`,completed:`task`,commented:void 0,mentioned:void 0,login:void 0,logout:void 0},tt=new Set([`task`]);function nt(e){return typeof e==`string`&&Qe.includes(e)?e:`all`}function rt(e){if(!Array.isArray(e))return;let t=e.filter(e=>typeof e==`string`&&$e.includes(e));return t.length>0?t:void 0}function it(e){let t=Math.floor(Number(e));return Number.isFinite(t)&&t>0?t:20}function at(e){let t=e.timestamp;return String(!t||t===`NOW()`||Number.isNaN(Date.parse(String(t)))?e.created_at??``:t)}function ot(e,t){let n=et[String(e?.type)];return n?{id:e.id,type:n,actor:e.actor_name??t,actorAvatarUrl:e.actor_avatar_url??void 0,body:e.summary??``,createdAt:at(e),sourceObject:e.source_object??void 0,sourceId:e.source_id??void 0}:null}function st(e,t,n){let r=e.slice();t.unifiedTimeline===!1&&(r=r.filter(e=>e.type!==`field_change`)),t.showCompleted!==!0&&(r=r.filter(e=>!tt.has(e.type)));let i=rt(t.types);if(i){let e=new Set(i);r=r.filter(t=>e.has(t.type))}let a=r.length,o=Math.max(1,Math.floor(n)||20);return{items:a>o?r.slice(a-o):r,total:a,hasMore:a>o}}function ct(...e){let t=new Map;for(let n of e)for(let e of n)t.set(String(e.id),e);return Array.from(t.values()).sort((e,t)=>{let n=e.createdAt?Date.parse(e.createdAt):0,r=t.createdAt?Date.parse(t.createdAt):0;return(Number.isNaN(n)?0:n)-(Number.isNaN(r)?0:r)})}var lt=e=>{let{"data-obj-id":t,"data-obj-type":n,style:r,...i}=e||{};return{designer:{"data-obj-id":t,"data-obj-type":n,style:r},rest:i}},ut=({schema:e={},className:t,...n})=>{let{designer:i}=lt(n),a=(0,o.useRecordContext)(),c=(0,o.useDiscussionContext)(),u=(0,s.useSafeTranslate)(),d=e.properties??{},f=t=>e[t]??d[t],p=it(f(`limit`)),m=nt(f(`filterMode`)),h=f(`types`),g=f(`showCompleted`),_=f(`unifiedTimeline`),v={types:h,filterMode:m,showFilterToggle:f(`showFilterToggle`),limit:p,showCompleted:g,unifiedTimeline:_,showCommentInput:f(`showCommentInput`),enableMentions:f(`enableMentions`),enableReactions:f(`enableReactions`),enableThreading:f(`enableThreading`),showSubscriptionToggle:f(`showSubscriptionToggle`)},y=Array.isArray(e.items)?e.items:Array.isArray(d.items)?d.items:void 0,b=e.loading??d.loading,x=a?.objectName,S=a?.data?.id??a?.data?._id??a?.recordId,C=a?.dataSource,w=y===void 0&&!c&&typeof C?.find==`function`&&!!x&&S!=null,[T,E]=r.default.useState(0),D=p*(T+1),[O,k]=r.default.useState(null),[A,j]=r.default.useState(!1),[M,N]=r.default.useState(!1),P=u(`detail.systemActor`,`System`);r.default.useEffect(()=>{if(!w)return;let e=!1;return N(!0),Promise.resolve(C.find(`sys_activity`,{$filter:{object_name:x,record_id:S},$orderby:{timestamp:`desc`},$top:Math.max(1,D)+1})).then(t=>{if(e)return;let n=t?.data??t?.records??[],r=Array.isArray(n)?n:[],i=[];for(let e of r){let t=ot(e,P);t&&i.push(t)}j(r.length>Math.max(1,D)),k(ct(i))}).catch(()=>{e||(k([]),j(!1))}).finally(()=>{e||N(!1)}),()=>{e=!0}},[w,C,x,S,D,P]);let F=c?.items,I=r.default.useMemo(()=>st(y??F??O??[],{types:h,showCompleted:g,unifiedTimeline:_},D),[y,F,O,h,g,_,D]),ee=I.items,L=I.hasMore||w&&A,te=b??c?.loading??(w&&O===null?!0:M),[R,ne]=r.default.useState(m);r.default.useEffect(()=>{ne(m)},[m]);let z=r.default.useCallback(()=>{E(e=>e+1)},[]),re=v.enableMentions!==!1;return(0,l.jsx)(`div`,{className:t,...i,children:(0,l.jsx)(Ze,{items:ee,config:v,loading:te,filterMode:R,onFilterChange:ne,hasMore:L,onLoadMore:z,onAddComment:c?.onAddComment,onAddReply:c?.onAddReply,onToggleReaction:c?.onToggleReaction,mentionSuggestions:re?c?.mentionSuggestions:void 0,onUploadAttachments:c?.onUploadAttachments})})},dt=({config:e,items:t,hasMore:n,onLoadMore:o,loading:s,onAddComment:c,onAddReply:u,onToggleReaction:d,subscription:f,onToggleSubscription:p,filterMode:m,onFilterChange:h,collapseWhenEmpty:g=!1,mentionSuggestions:_,onUploadAttachments:v,className:y})=>{let b=e?.position??`right`,x=e?.width??`360px`,S=e?.collapsible??!0,C=g&&t.length===0||(e?.defaultCollapsed??!1),{t:w}=D(),[T,E]=r.useState(C);return b===`right`||b===`left`?T&&S?(0,l.jsx)(`div`,{className:(0,i.cn)(`flex items-start pt-4`,b===`right`?`border-l`:`border-r`,y),children:(0,l.jsx)(i.Button,{variant:`ghost`,size:`icon`,className:`h-8 w-8 mx-1`,onClick:()=>E(!1),"aria-label":w(`detail.openDiscussion`),children:(0,l.jsx)(a.PanelRightOpen,{className:`h-4 w-4`})})}):(0,l.jsxs)(`div`,{className:(0,i.cn)(`flex flex-col overflow-hidden`,b===`right`?`border-l`:`border-r`,y),style:{width:x,minWidth:x},children:[(0,l.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(a.MessageSquare,{className:`h-4 w-4`}),(0,l.jsx)(`span`,{className:`text-sm font-medium`,children:w(`detail.discussion`)})]}),S&&(0,l.jsx)(i.Button,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:()=>E(!0),"aria-label":w(`detail.closeDiscussion`),children:(0,l.jsx)(a.X,{className:`h-3.5 w-3.5`})})]}),(0,l.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:(0,l.jsx)(Ze,{items:t,config:e?.feed,hasMore:n,onLoadMore:o,loading:s,onAddComment:c,onAddReply:u,onToggleReaction:d,subscription:f,onToggleSubscription:p,filterMode:m,onFilterChange:h,collapseWhenEmpty:g,mentionSuggestions:_,onUploadAttachments:v,titleLabel:w(`detail.discussion`),emptyLabel:w(`detail.noCommentsYet`),className:`border-0 shadow-none`})})]}):(0,l.jsx)(`div`,{className:(0,i.cn)(``,y),children:S&&T?(0,l.jsxs)(i.Button,{variant:`ghost`,className:`w-full justify-start gap-2 text-muted-foreground`,onClick:()=>E(!1),"aria-label":w(`detail.showDiscussion`,{count:t.length}),children:[(0,l.jsx)(a.MessageSquare,{className:`h-4 w-4`}),(0,l.jsx)(`span`,{children:w(`detail.showDiscussion`,{count:t.length})})]}):(0,l.jsxs)(`div`,{children:[S&&(0,l.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium`,children:[(0,l.jsx)(a.MessageSquare,{className:`h-4 w-4`}),w(`detail.discussion`)]}),(0,l.jsx)(i.Button,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:()=>E(!0),"aria-label":w(`detail.hideDiscussion`),children:(0,l.jsx)(a.PanelRightClose,{className:`h-3.5 w-3.5`})})]}),(0,l.jsx)(Ze,{items:t,config:e?.feed,hasMore:n,onLoadMore:o,loading:s,onAddComment:c,onAddReply:u,onToggleReaction:d,subscription:f,onToggleSubscription:p,filterMode:m,onFilterChange:h,collapseWhenEmpty:g,mentionSuggestions:_,onUploadAttachments:v,titleLabel:w(`detail.discussion`),emptyLabel:w(`detail.noCommentsYet`)})]})})},ft=e=>{let{"data-obj-id":t,"data-obj-type":n,style:r,...i}=e||{};return{designer:{"data-obj-id":t,"data-obj-type":n,style:r},rest:i}},pt=({schema:e={},className:t,...n})=>{(0,o.useRecordContext)();let r=(0,o.useDiscussionContext)(),{designer:i}=ft(n),a={position:`bottom`,collapsible:!1,feed:{enableReactions:!0,enableThreading:!0,showCommentInput:!0},...e};return(0,l.jsx)(`div`,{className:t,...i,children:(0,l.jsx)(dt,{items:r?.items||[],config:a,loading:r?.loading,onAddComment:r?.onAddComment,onAddReply:r?.onAddReply,onToggleReaction:r?.onToggleReaction,mentionSuggestions:r?.mentionSuggestions,onUploadAttachments:r?.onUploadAttachments})})},mt=e=>{let{"data-obj-id":t,"data-obj-type":n,style:r,...i}=e||{};return{designer:{"data-obj-id":t,"data-obj-type":n,style:r},rest:i}},ht=({schema:e={},className:t,...n})=>{let a=(0,o.useRecordContext)(),{translateOptions:s}=(0,o.useSafeFieldLabel)(),{designer:c}=mt(n),u=Array.isArray(e.stages)?e.stages:[],d=e.statusField,f=r.default.useMemo(()=>{if(u.length===0||!d||!a?.objectName)return u;let e=s(a.objectName,d,u);return Array.isArray(e)&&e.length===u.length?u.map((t,n)=>({...t,label:e[n]?.label??t.label})):u},[u,d,a?.objectName,s]),p=d&&a?.data?a.data[d]:void 0,m=/(^|[_-\s])(closed_)?(lost|failed?|cancell?ed|失败|流失|丢单|败)([_-\s]|$)/i,h=/(^|[_-\s])(closed_)?(won|success|成交|赢|完成)([_-\s]|$)/i,g=f.map(e=>{if(e.terminal)return e.terminal;let t=`${String(e.value??``)} ${String(e.label??``)}`;if(m.test(t))return`lost`;if(h.test(t))return`won`}),_=g.findIndex(e=>e===`lost`),v=_===-1?f:f.slice(0,_),y=_===-1?[]:f.slice(_),b=_===-1?g:g.slice(0,_),x=f.findIndex(e=>e.value===p);x<0&&(x=-1);let S=_!==-1&&x>=_;if(f.length===0)return(0,l.jsx)(`div`,{className:t,...c,children:(0,l.jsx)(`div`,{className:`text-xs text-muted-foreground italic px-3 py-2 border border-dashed rounded`,children:`record:path — no stages configured`})});let C=v.length-1;return(0,l.jsxs)(`div`,{className:(0,i.cn)(`w-full`,t),...c,children:[(0,l.jsxs)(`div`,{className:`hidden sm:flex w-full items-stretch gap-2`,role:`list`,"aria-label":e.aria?.label||`Record path`,children:[(0,l.jsx)(`div`,{className:`flex flex-1 items-stretch gap-1.5`,children:v.map((e,t)=>{let n=!S&&x>=0&&t<x,r=!S&&t===x,a=b[t]===`won`&&t===C;return(0,l.jsx)(`div`,{role:`listitem`,"aria-current":r?`step`:void 0,className:(0,i.cn)(`relative flex-1 min-w-0 px-4 py-2 text-xs font-medium text-center rounded-xl`,r&&`bg-primary text-primary-foreground shadow-sm`,n&&`bg-emerald-500/15 text-emerald-800 dark:text-emerald-200`,!r&&!n&&a&&`bg-emerald-500/10 text-emerald-700/85 dark:text-emerald-300/85`,!r&&!n&&!a&&`bg-muted text-muted-foreground`),children:(0,l.jsxs)(`span`,{className:`inline-flex items-center justify-center gap-1.5 truncate`,children:[n&&(0,l.jsx)(`span`,{"aria-hidden":!0,className:`text-emerald-600 dark:text-emerald-400 font-semibold`,children:`✓`}),a&&!r&&(0,l.jsx)(`span`,{"aria-hidden":!0,className:`opacity-70`,children:`🏆`}),e.label]})},`${e.value}-${t}`)})}),y.length>0&&(0,l.jsx)(`div`,{className:`flex items-stretch gap-1 pl-2 border-l border-border/40`,"aria-label":`Alternative terminal stages`,children:y.map((e,t)=>{let n=_+t===x;return(0,l.jsx)(`div`,{role:`listitem`,"aria-current":n?`step`:void 0,className:(0,i.cn)(`shrink-0 px-3 py-2 text-xs font-medium rounded-md border whitespace-nowrap`,n&&`bg-destructive text-destructive-foreground border-destructive shadow-sm ring-1 ring-destructive/40`,!n&&`bg-destructive/5 text-destructive/85 border-destructive/20`),children:(0,l.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,l.jsx)(`span`,{"aria-hidden":!0,className:`opacity-70`,children:`✗`}),e.label]})},`${e.value}-lost-${t}`)})})]}),(0,l.jsx)(`div`,{className:`flex sm:hidden w-full items-stretch gap-1 overflow-x-auto pb-1 -mx-1 px-1 [-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden`,role:`list`,"aria-label":e.aria?.label||`Record path`,children:f.map((e,t)=>{let n=g[t]===`lost`,r=!n&&!S&&x>=0&&t<x,a=t===x;return(0,l.jsx)(`div`,{role:`listitem`,"aria-current":a?`step`:void 0,className:(0,i.cn)(`shrink-0 px-3 py-1.5 rounded-full text-xs font-medium border whitespace-nowrap`,n&&a&&`bg-destructive text-destructive-foreground border-destructive shadow-sm`,n&&!a&&`bg-destructive/5 text-destructive/85 border-destructive/20`,!n&&a&&`bg-primary text-primary-foreground border-primary shadow-sm ring-1 ring-primary/40`,!n&&r&&`bg-emerald-500/15 text-emerald-800 dark:text-emerald-200 border-emerald-500/30`,!n&&!a&&!r&&`bg-background text-foreground/85 border-border/60`),children:(0,l.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[n&&(0,l.jsx)(`span`,{"aria-hidden":!0,className:`opacity-70`,children:`✗`}),!n&&r&&(0,l.jsx)(`span`,{"aria-hidden":!0,className:`text-emerald-600 dark:text-emerald-400 font-semibold`,children:`✓`}),e.label]})},`${e.value}-${t}-m`)})})]})},gt=e=>{let{"data-obj-id":t,"data-obj-type":n,style:r,...i}=e||{};return{designer:{"data-obj-id":t,"data-obj-type":n,style:r},rest:i}},_t=({schema:e={},className:t,...n})=>{let r=(0,o.useRecordContext)(),{designer:a}=gt(n),c=(0,u.usePermissions)(),{language:d}=(0,s.useObjectTranslation)(),f=(0,o.useSafeFieldLabel)(),p=Array.isArray(e.actions)?e.actions:Array.isArray(e.properties?.actions)?e.properties.actions:[],m=Array.isArray(e.actionNames)?e.actionNames:Array.isArray(e.properties?.actionNames)?e.properties.actionNames:[],h=r?.objectName||``,g=m.length>0?m:Array.isArray(p)&&p.every(e=>typeof e==`string`)?p:[],_=g.length>0&&!!h,{item:v}=(0,o.useMetadataItem)(`object`,_?h:null),y=_?(()=>{let e=Array.isArray(v?.actions)?v.actions:[],t=new Map(e.map(e=>[e.name,e]));return g.map(e=>t.get(e)).filter(e=>!!e)})():Array.isArray(p)?p:[],b=Array.isArray(e.requiredPermissions)?e.requiredPermissions:[],x=e.location||`record_header`,{getActionsForLocation:S,executeAction:C}=(0,o.useActionEngine)({actions:y,context:{record:r?.data,recordId:r?.recordId,objectName:r?.objectName}});if(b.length>0&&h&&!b.every(e=>c.can(h,e)))return(0,l.jsx)(`div`,{className:t,...a,role:`status`,"aria-live":`polite`,children:(0,l.jsx)(`p`,{className:`text-sm text-muted-foreground italic`,children:`Insufficient permissions to view quick actions.`})});let w=y.length>0?S(x):[];if(w.length===0)return(0,l.jsx)(`div`,{className:t,...a,children:(0,l.jsx)(`div`,{className:`text-xs text-muted-foreground italic px-3 py-2 border border-dashed rounded`,children:`record:quick_actions — no actions configured`})});let T=e.align||`end`,E=T===`start`?`justify-start`:T===`center`?`justify-center`:`justify-end`,D=x===`record_header`&&!e.inline;return(0,l.jsx)(`div`,{className:(0,i.cn)(`flex flex-wrap items-center gap-2`,D&&`-mt-12 sm:-mt-14 mb-2 relative z-10`,E,t),role:`toolbar`,"aria-label":e.aria?.label||`Quick actions`,...a,children:w.map((t,n)=>(0,l.jsx)(vt,{action:t,record:r?.data,variant:t.variant||e.variant||`default`,size:t.size||e.size||`sm`,label:(()=>{let e=(0,s.pickLocalized)(t.label,d)||t.name||`Action ${n+1}`;return t.name?f.actionLabel(h||void 0,t.name,e):e})(),onRun:async()=>{typeof t.onClick==`function`?await t.onClick():t.name&&await C(t.name)}},t.name||`qa-${n}`))})};function vt({action:e,record:t,variant:n,size:s,label:c,onRun:u}){let[d,f]=r.default.useState(!1),p=r.default.useMemo(()=>({record:t||{}}),[t]),m=(0,o.useCondition)((0,o.toPredicateInput)(e.disabled),p),h=e.disabled!=null&&m||d;return(0,l.jsxs)(i.Button,{variant:n,size:s,disabled:h,onClick:async()=>{f(!0);try{await u()}finally{f(!1)}},children:[d&&(0,l.jsx)(a.Loader2,{className:`mr-2 h-4 w-4 animate-spin`}),c]})}var yt=e=>{let{"data-obj-id":t,"data-obj-type":n,style:r,...i}=e||{};return{designer:{"data-obj-id":t,"data-obj-type":n,style:r},rest:i}},bt=new Set([`created`,`updated`,`assigned`,`shared`,`deleted`]),xt=({schema:e={},className:t,...n})=>{let{designer:i}=yt(n),a=(0,o.useRecordContext)(),s=Array.isArray(e.entries)?e.entries:Array.isArray(e.properties?.entries)?e.properties.entries:void 0,c=e.loading??e.properties?.loading,u=e.emptyText??e.properties?.emptyText,d=e.unknownUserText??e.properties?.unknownUserText,f=Number(e.limit??e.properties?.limit??50)||50,p=a?.objectName,m=a?.data?.id??a?.data?._id??a?.recordId,h=a?.dataSource,g=s===void 0&&!!h?.find&&!!p&&m!=null,[_,v]=r.default.useState(null),[y,b]=r.default.useState(!1);r.default.useEffect(()=>{if(!g)return;let e=!1;return b(!0),Promise.resolve(h.find(`sys_activity`,{$filter:{object_name:p,record_id:m},$orderby:{timestamp:`desc`},$top:Math.max(1,f)})).then(t=>{if(e)return;let n=(t?.data??t?.records??[]).filter(e=>bt.has(e?.type)).map(e=>{let t=e.timestamp;return(!t||t===`NOW()`||Number.isNaN(Date.parse(t)))&&(t=e.created_at),{id:e.id,created_at:t,action:e.type,user_name:e.actor_name??null,user_avatar:e.actor_avatar_url??null,summary:e.summary??null}});v(n)}).catch(()=>{e||v([])}).finally(()=>{e||b(!1)}),()=>{e=!0}},[g,h,p,m,f]);let x=s??_??[],S=c??(g&&_===null?y||!0:!1);return(0,l.jsx)(`div`,{className:t,...i,children:(0,l.jsx)(me,{entries:x,loading:S,emptyText:u,unknownUserText:d})})},St=e=>{let{"data-obj-id":t,"data-obj-type":n,style:r,...i}=e||{};return{designer:{"data-obj-id":t,"data-obj-type":n,style:r},rest:i}},Ct=e=>e.replace(/[_-]+/g,` `).replace(/\b\w/g,e=>e.toUpperCase()).trim(),wt=(e,t)=>t&&e?.[t]!=null&&e[t]!==``?String(e[t]):e?.name||e?.title||e?.subject||e?.label||e?.email||e?.username||e?.code||e?.slug||e?.provider_id||e?.user_agent||e?.ip_address||e?.id||`—`,Tt=({schema:e={},className:t,...n})=>{let s=(0,o.useRecordContext)(),u=(0,o.useSafeFieldLabel)(),{t:d}=D(),{designer:f}=St(n),p=(0,c.useParams)().appName,m=Array.isArray(e.entries)?e.entries:Array.isArray(e.properties?.entries)?e.properties.entries:[],h=s?.recordId,g=s?.dataSource,[_,v]=r.default.useState({}),y=r.default.useRef(null),[b,x]=r.default.useState(!1),S=r.default.useRef(!0);r.default.useEffect(()=>(S.current=!0,()=>{S.current=!1}),[]);let C=r.default.useRef(``);r.default.useEffect(()=>{if(b)return;let e=y.current;if(!e||typeof IntersectionObserver>`u`){x(!0);return}let t=new IntersectionObserver(e=>{e.some(e=>e.isIntersecting)&&x(!0)},{rootMargin:`200px`});return t.observe(e),()=>t.disconnect()},[b]);let w=JSON.stringify(m.map(e=>`${e.objectName}:${e.relationshipField}:${e.limit??3}`));r.default.useEffect(()=>{if(!b||!g?.find||!h||m.length===0)return;let e=`${h}::${w}`;if(C.current===e)return;C.current=e,v(e=>{let t={...e};for(let n of m)t[n.objectName]={loading:!0,total:0,items:e[n.objectName]?.items||[]};return t});let t=async e=>{let t=e.objectName;try{let n=await g.find(e.objectName,{$filter:{[e.relationshipField]:h},$top:e.limit??3,$count:!0});if(!S.current)return;let r=Array.isArray(n)?n:n?.data||[],i=typeof n?.total==`number`?n.total:typeof n?.count==`number`?n.count:r.length;v(e=>({...e,[t]:{loading:!1,total:i,items:r}}))}catch(e){if(!S.current)return;v(n=>({...n,[t]:{loading:!1,total:0,items:[],error:String(e?.message||e)}}))}},n=[...m],r=async()=>{for(;S.current;){let e=n.shift();if(!e)return;await t(e)}},i=Array.from({length:Math.min(3,n.length)},()=>r());Promise.all(i)},[b,g,h,w]);let[T,E]=r.default.useState(!1);if(m.length===0)return null;let O=e.hideEmpty!==!1,k=new Set(m.filter(e=>{let t=_[e.objectName];return O&&t&&!t.loading&&!t.error&&t.total===0}).map(e=>e.objectName)),A=m.filter(e=>T||!k.has(e.objectName)),j=m.filter(e=>k.has(e.objectName)).map(e=>e.title||(u?.objectLabel?u.objectLabel({name:e.objectName,label:Ct(e.objectName)}):Ct(e.objectName)));return(0,l.jsxs)(`div`,{ref:y,className:(0,i.cn)(`flex flex-col gap-3`,e.className,t),...f,children:[A.map(e=>{let t=e.objectName,n=_[t]||{loading:!0,total:0,items:[]},r=e.title||(u?.objectLabel?u.objectLabel({name:e.objectName,label:Ct(e.objectName)}):Ct(e.objectName));return(0,l.jsxs)(i.Card,{className:`overflow-hidden`,children:[(0,l.jsxs)(i.CardHeader,{className:`flex flex-row items-center justify-between gap-2 py-3 px-4 space-y-0 border-b`,children:[(0,l.jsx)(i.CardTitle,{className:`text-sm font-semibold tracking-tight truncate`,children:r}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[!n.loading&&(0,l.jsx)(i.Badge,{variant:`secondary`,className:`tabular-nums`,children:n.total}),p&&h&&(0,l.jsx)(c.Link,{to:`/apps/${p}/${e.objectName}?filter%5B${e.relationshipField}%5D=${encodeURIComponent(String(h))}`,className:`text-[11px] font-medium text-muted-foreground hover:text-foreground transition-colors`,title:d(`detail.viewAll`,{defaultValue:`View all`}),children:d(`detail.viewAll`,{defaultValue:`View all`})})]})]}),(0,l.jsx)(i.CardContent,{className:`p-0`,children:n.loading?(0,l.jsxs)(`div`,{className:`space-y-1.5 p-3`,children:[(0,l.jsx)(i.Skeleton,{className:`h-3.5 w-4/5`}),(0,l.jsx)(i.Skeleton,{className:`h-3.5 w-3/5`}),(0,l.jsx)(i.Skeleton,{className:`h-3.5 w-2/3`})]}):n.items.length===0?(0,l.jsx)(`p`,{className:`px-4 py-3 text-xs text-muted-foreground`,children:d(`detail.noRecords`)}):(0,l.jsx)(`ul`,{className:`divide-y`,children:n.items.map(t=>{let n=t.id||t._id,r=wt(t,e.displayField),i=n?`../${e.objectName}/record/${encodeURIComponent(String(n))}`:void 0;return(0,l.jsx)(`li`,{className:`px-4 py-2`,children:i?(0,l.jsxs)(c.Link,{to:i,className:`group flex items-center justify-between gap-2 text-xs hover:text-foreground text-muted-foreground transition-colors`,children:[(0,l.jsx)(`span`,{className:`truncate`,children:r}),(0,l.jsx)(a.ChevronRight,{className:`h-3 w-3 shrink-0 opacity-0 group-hover:opacity-100 transition-opacity`})]}):(0,l.jsx)(`span`,{className:`block truncate text-xs text-muted-foreground`,children:r})},String(n||r))})})})]},t)}),!T&&j.length>0&&(0,l.jsxs)(`button`,{type:`button`,onClick:()=>E(!0),className:`self-start inline-flex items-center gap-1.5 text-[11px] text-muted-foreground hover:text-foreground transition-colors px-2.5 py-1 rounded-md border border-dashed border-border/60 hover:border-border bg-background`,title:j.join(` · `),children:[(0,l.jsx)(`span`,{children:d(`detail.showEmptyRelated`,{defaultValue:`+ {{count}} empty`,count:j.length})}),(0,l.jsxs)(`span`,{className:`truncate max-w-[180px] text-muted-foreground/70`,children:[`(`,j.join(` · `),`)`]})]})]})},Et={info:{wrap:`border-blue-300/60 bg-blue-50 text-blue-900 dark:border-blue-700/40 dark:bg-blue-950/30 dark:text-blue-100 [&>svg]:text-blue-600 dark:[&>svg]:text-blue-300`,icon:`Info`},warning:{wrap:`border-amber-300/60 bg-amber-50 text-amber-900 dark:border-amber-700/40 dark:bg-amber-950/30 dark:text-amber-100 [&>svg]:text-amber-600 dark:[&>svg]:text-amber-300`,icon:`AlertTriangle`},error:{wrap:`border-destructive/60 bg-destructive/10 text-destructive dark:bg-destructive/20 [&>svg]:text-destructive`,icon:`AlertCircle`},success:{wrap:`border-emerald-300/60 bg-emerald-50 text-emerald-900 dark:border-emerald-700/40 dark:bg-emerald-950/30 dark:text-emerald-100 [&>svg]:text-emerald-600 dark:[&>svg]:text-emerald-300`,icon:`CheckCircle2`}};function Dt(e){let t=e?.properties??{};return{...e,...t}}var Ot=({schema:e={},className:t})=>{let n=Dt(e),a=(0,o.useRecordContext)(),c=a?.data,u=a?.objectName||``,d=a?.recordId??c?.id,{language:f}=(0,s.useObjectTranslation)(),p=(0,s.pickLocalized)(n.title,f),m=(0,s.pickLocalized)(n.body,f),h=(0,s.pickLocalized)(n.action?.label,f),g=[`info`,`warning`,`error`,`success`].includes(n.severity)?n.severity:`info`,_=Et[g],v=n.icon||_.icon,y=(0,o.toPredicateInput)(n.visible),b=(0,o.useCondition)(y,{record:c}),x=r.useMemo(()=>{if(!n.dismissible)return null;let e=n.dismissKey||(0,s.pickLocalized)(n.title,`en`)||g;return`os.record-alert:${u}:${d??`_`}:${e}`},[n.dismissible,n.dismissKey,n.title,g,u,d]),[S,C]=r.useState(()=>{if(!x||typeof window>`u`)return!1;try{return window.localStorage.getItem(x)===`1`}catch{return!1}}),w=n.action?.actionName,{item:T}=(0,o.useMetadataItem)(`object`,w&&u?u:null),E=r.useMemo(()=>{if(!(!w||!T?.actions))return T.actions.find(e=>e.name===w)},[w,T]),D=r.useMemo(()=>E?[E]:[],[E]),{executeAction:O}=(0,o.useActionEngine)({actions:D,context:{record:c,recordId:d,objectName:u}});return S||!c||Object.keys(c).length===0||y!==void 0&&!b?null:(0,l.jsxs)(i.Alert,{className:(0,i.cn)(`relative pr-12`,_.wrap,t),role:g===`error`?`alert`:`status`,"aria-live":g===`error`?`assertive`:`polite`,children:[(0,l.jsx)(i.LazyIcon,{name:v,className:`h-4 w-4`,"aria-hidden":`true`}),p?(0,l.jsx)(i.AlertTitle,{children:p}):null,m||E?(0,l.jsxs)(i.AlertDescription,{children:[m?(0,l.jsx)(`p`,{className:`mb-2 last:mb-0`,children:m}):null,E?(0,l.jsx)(i.Button,{size:`sm`,variant:n.action?.variant||(g===`error`?`destructive`:`default`),onClick:()=>{E?.name&&O(E.name)},children:h||E.label||E.name}):null]}):null,n.dismissible?(0,l.jsx)(`button`,{type:`button`,onClick:()=>{if(C(!0),x)try{window.localStorage.setItem(x,`1`)}catch{}},"aria-label":`Dismiss`,className:`absolute right-3 top-3 inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground/80 hover:bg-foreground/5 hover:text-foreground focus:outline-none focus:ring-2 focus:ring-ring`,children:(0,l.jsx)(i.LazyIcon,{name:`X`,className:`h-4 w-4`,"aria-hidden":`true`})}):null]})},kt=e=>{if(e==null)return`—`;if(typeof e==`string`)return e.length>0?e:`""`;if(typeof e==`number`||typeof e==`boolean`)return String(e);try{return JSON.stringify(e)}catch{return String(e)}},At=e=>{if(typeof e!=`string`||e.length===0)return null;let t=/\d{4}-\d{2}-\d{2}[ T]/.test(e)?e.replace(` `,`T`):e,n=new Date(t);if(Number.isNaN(n.getTime()))return null;try{return n.toLocaleString()}catch{return n.toISOString()}},jt=({open:e,conflict:t,onReload:n,onOverwrite:r,onCancel:o,busy:s=!1})=>{let{t:c}=D(),u=t?.label||t?.field||``,d=t?kt(t.pendingValue):``,f=t?kt(t.currentValue):``,p=t?.currentRecord??{},m=(()=>{let e=[p.updated_by_name,p.updated_by_label];for(let t of e)if(typeof t==`string`&&t.length>0)return t;let t=p.updated_by;return typeof t!=`string`||t.length===0||t.length>=16&&!/\s/.test(t)&&/^[A-Za-z0-9_-]+$/.test(t)?null:t})(),h=At(p.updated_at??t?.currentVersion),[g,_]=c(`detail.concurrentUpdateDescription`,{field:`{{field}}`}).split(`{{field}}`);return(0,l.jsx)(i.AlertDialog,{open:e,onOpenChange:e=>{!e&&!s&&o()},children:(0,l.jsxs)(i.AlertDialogContent,{className:`max-w-lg`,children:[(0,l.jsx)(i.AlertDialogHeader,{children:(0,l.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,l.jsx)(`span`,{className:`inline-flex h-9 w-9 flex-none items-center justify-center rounded-full bg-amber-100 text-amber-700 dark:bg-amber-500/20 dark:text-amber-300`,"aria-hidden":`true`,children:(0,l.jsx)(a.AlertTriangle,{className:`h-5 w-5`})}),(0,l.jsxs)(`div`,{className:`flex-1`,children:[(0,l.jsx)(i.AlertDialogTitle,{children:c(`detail.concurrentUpdateTitle`)}),(0,l.jsxs)(i.AlertDialogDescription,{className:`mt-1`,children:[g,(0,l.jsx)(`strong`,{className:`font-semibold`,children:u}),_]})]})]})}),(0,l.jsxs)(`div`,{className:`space-y-2 text-sm`,children:[(0,l.jsxs)(`div`,{className:`rounded-md border border-amber-200/70 bg-amber-50/60 p-3 dark:border-amber-500/30 dark:bg-amber-500/10`,children:[(0,l.jsx)(`div`,{className:`text-xs font-medium uppercase tracking-wide text-amber-800 dark:text-amber-300`,children:c(`detail.concurrentUpdateYourEdit`)}),(0,l.jsx)(`div`,{className:`mt-1 break-all font-mono text-foreground`,children:d})]}),(0,l.jsxs)(`div`,{className:`rounded-md border border-sky-200/70 bg-sky-50/60 p-3 dark:border-sky-500/30 dark:bg-sky-500/10`,children:[(0,l.jsxs)(`div`,{className:`flex items-baseline justify-between gap-2`,children:[(0,l.jsx)(`div`,{className:`text-xs font-medium uppercase tracking-wide text-sky-800 dark:text-sky-300`,children:c(`detail.concurrentUpdateCurrentValue`)}),(m||h)&&(0,l.jsxs)(`div`,{className:`text-[11px] text-muted-foreground`,children:[m&&(0,l.jsx)(`span`,{children:c(`detail.concurrentUpdateUpdatedBy`,{name:m})}),m&&h&&(0,l.jsx)(`span`,{children:` · `}),h&&(0,l.jsx)(`span`,{children:c(`detail.concurrentUpdateUpdatedAt`,{when:h})})]})]}),(0,l.jsx)(`div`,{className:`mt-1 break-all font-mono text-foreground`,children:f})]})]}),(0,l.jsxs)(i.AlertDialogFooter,{className:`gap-2 sm:gap-2`,children:[(0,l.jsx)(`button`,{type:`button`,disabled:s,onClick:o,className:(0,i.cn)((0,i.buttonVariants)({variant:`ghost`}),`mt-2 sm:mt-0`),children:c(`detail.concurrentUpdateCancel`)}),(0,l.jsx)(`button`,{type:`button`,disabled:s,onClick:r,className:(0,i.cn)((0,i.buttonVariants)({variant:`outline`}),`mt-2 sm:mt-0 text-destructive border-destructive/40 hover:bg-destructive/10 hover:text-destructive`),children:c(`detail.concurrentUpdateOverwrite`)}),(0,l.jsx)(`button`,{type:`button`,disabled:s,onClick:n,autoFocus:!0,className:(0,i.cn)((0,i.buttonVariants)({variant:`default`}),`mt-2 sm:mt-0`),children:c(`detail.concurrentUpdateReload`)})]})]})})};function Mt(e){if(!e||typeof e!=`object`)return!1;let t=e;return t.code===`CONCURRENT_UPDATE`||t.name===`ConcurrentUpdateError`}function Nt(e){let t=e?.message||e?.error||String(e??`Save failed`);return String(t).replace(/^\[[^\]]+\]\s*/,``).replace(/^[A-Z][A-Z0-9_]+:\s*/,``)}async function Pt(e,t,n,r,i){if(typeof e?.update==`function`)await e.update(t,n,r,i);else if(typeof e?.updateOne==`function`)await e.updateOne(t,n,r,i);else if(typeof e?.patch==`function`)await e.patch(t,n,r,i);else throw Error(`[InlineEditSaveBar] DataSource exposes no update/updateOne/patch method; cannot persist inline edit`)}var Ft=({dataSource:e,objectName:t,recordId:n,data:s,refresh:c,fieldLabelFor:u,onFieldSave:d,locked:f=!1,lockedHint:p,className:m})=>{let{t:h}=D(),g=(0,o.useInlineEdit)(),[_,v]=r.useState(null),[y,b]=r.useState(!1),x=!!e&&!!t&&n!=null,S=r.useCallback((e,t)=>{let n=Object.keys(e),r=t?.currentRecord??null;if(n.length===1){let i=n[0];return{field:i,label:u?.(i),pendingValue:e[i],currentValue:r?r[i]:void 0,currentVersion:t?.currentVersion,currentRecord:r}}let i=r?Object.fromEntries(n.map(e=>[e,r[e]])):void 0;return{field:n.join(`, `),label:h(`detail.concurrentUpdateRecordLabel`,{defaultValue:`this record`}),pendingValue:e,currentValue:i,currentVersion:t?.currentVersion,currentRecord:r}},[u,h]),C=r.useCallback(async()=>{if(!g)return;let r=g.draft,i=Object.entries(r);if(i.length===0){g.reset();return}g.setSaving(!0),g.setError(null);try{if(d)for(let[e,t]of i)await d(e,t);else if(x){let i=typeof s?.updated_at==`string`?s.updated_at:void 0;await Pt(e,t,n,r,i?{ifMatch:i}:void 0),await c?.()}g.reset()}catch(e){Mt(e)&&x?v(S(r,e)):g.setError(Nt(e))}finally{g.setSaving(!1)}},[g,d,x,s,e,t,n,c,S]),w=r.useCallback(()=>{v(null),b(!1)},[]),T=r.useCallback(async()=>{b(!0);try{await c?.()}finally{g?.reset(),w()}},[c,g,w]),E=r.useCallback(async()=>{if(!_||!x){w();return}b(!0);try{await Pt(e,t,n,g?.draft??{},_.currentVersion?{ifMatch:_.currentVersion}:void 0),await c?.(),g?.reset()}catch(e){g?.setError(Nt(e))}finally{w()}},[_,x,g,e,t,n,c,w]),O=!!g?.editing,k=!!g?.saving,A=g?.cancel,j=!!_;return r.useEffect(()=>{if(!O)return;let e=e=>{if(e.key===`Enter`&&(e.metaKey||e.ctrlKey)){if(k||f||j)return;e.preventDefault(),C();return}if(e.key===`Escape`){if(e.defaultPrevented||k||j||document.querySelector(`[data-radix-popper-content-wrapper], [role="dialog"][data-state="open"], [role="alertdialog"][data-state="open"]`))return;e.preventDefault(),A?.()}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[O,k,f,j,C,A]),!g||!g.editing?null:(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(`div`,{className:(0,i.cn)(`sticky bottom-0 z-30 mt-4 flex flex-wrap items-center justify-end gap-2 rounded-md border bg-background/95 px-3 py-2 shadow-sm backdrop-blur supports-[backdrop-filter]:bg-background/80`,m),role:`region`,"aria-label":h(`detail.editFieldsInline`),children:[g.error&&(0,l.jsx)(`div`,{role:`alert`,className:`mr-auto max-w-md rounded-md border border-destructive/20 bg-destructive/10 px-2 py-1 text-xs text-destructive`,children:g.error}),(0,l.jsxs)(i.Button,{variant:`ghost`,size:`sm`,onClick:g.cancel,disabled:g.saving,className:`gap-2`,children:[(0,l.jsx)(a.X,{className:`h-4 w-4`}),(0,l.jsx)(`span`,{children:h(`detail.cancel`)})]}),(0,l.jsxs)(i.Button,{variant:`default`,size:`sm`,onClick:C,disabled:g.saving||f,className:`gap-2`,title:f?p:void 0,children:[g.saving?(0,l.jsx)(a.Loader2,{className:`h-4 w-4 animate-spin`}):(0,l.jsx)(a.Check,{className:`h-4 w-4`}),(0,l.jsx)(`span`,{children:g.saving?h(`detail.saving`):h(`detail.save`)})]})]}),(0,l.jsx)(jt,{open:!!_,conflict:_,busy:y,onCancel:w,onReload:T,onOverwrite:E})]})},It=new Set(d.SYSTEM_MANAGED_FIELD_NAMES),Lt=480,Rt=95;function zt({open:e,onClose:t,title:n,record:a,objectName:s,recordId:c,dataSource:u,objectSchema:d,width:f=`min(960px, 60vw)`,columns:p=2,systemFields:m=It,onFieldSave:h,onDelete:g,resizable:_=!0,fullPageHref:v}){let{t:y}=D(),b=`objectui.drawerWidth.${s}`,[x,S]=r.default.useState(()=>{if(typeof window>`u`||!_)return null;try{let e=window.localStorage.getItem(b);if(e){let t=parseInt(e,10);if(Number.isFinite(t)&&t>=Lt)return t}}catch{}return null}),C=r.default.useMemo(()=>_&&x!=null?`${x}px`:typeof f==`number`?`${f}px`:f,[_,x,f]),w=C?{width:C,maxWidth:C}:void 0,T=r.default.useRef(null),E=r.default.useCallback(e=>{if(!_)return;e.preventDefault();let t=x??(typeof window<`u`?Math.min(window.innerWidth*.6,960):720);T.current={startX:e.clientX,startWidth:t};let n=e=>{let t=T.current;if(!t)return;let n=t.startX-e.clientX,r=typeof window<`u`?window.innerWidth*Rt/100:1600,i=Math.min(r,Math.max(Lt,t.startWidth+n));S(Math.round(i))},r=()=>{T.current,T.current=null,window.removeEventListener(`pointermove`,n),window.removeEventListener(`pointerup`,r),window.removeEventListener(`pointercancel`,r);try{S(e=>(e!=null&&window.localStorage.setItem(b,String(e)),e))}catch{}};window.addEventListener(`pointermove`,n),window.addEventListener(`pointerup`,r),window.addEventListener(`pointercancel`,r)},[_,x,b]),O=d?.fields??{},k=(Object.keys(O).length?Object.keys(O):Object.keys(a)).filter(e=>!m.has(e)&&!e.startsWith(`__`)).filter(e=>e in a).filter(e=>!O[e]?.hidden).map(e=>{let t=O[e]||{},n=t.type===`lookup`||t.type===`master_detail`||t.type===`reference`;return{name:e,label:t.label,type:t.type,readonly:!!t.readonly||n,options:t.options,currency:t.currency,precision:t.precision,scale:t.scale,format:t.format,reference_to:t.reference_to??t.reference??t.referenceTo??t.target,reference_field:t.reference_field??t.referenceField,required:t.required,validation:t.validation,placeholder:t.placeholder,description:t.description}});return(0,l.jsx)(i.Sheet,{open:e,onOpenChange:e=>{e||t()},children:(0,l.jsxs)(i.SheetContent,{side:`right`,className:`w-full overflow-y-auto p-0 sm:!max-w-none`,style:w,onOpenAutoFocus:e=>e.preventDefault(),children:[_&&(0,l.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":y(`common.resizeDrawer`),onPointerDown:E,className:`hidden sm:block absolute left-0 top-0 h-full w-1.5 cursor-col-resize select-none bg-transparent hover:bg-primary/30 active:bg-primary/50 transition-colors z-10`}),(0,l.jsx)(i.SheetHeader,{className:`sr-only`,children:(0,l.jsx)(i.SheetTitle,{children:n})}),(0,l.jsx)(`div`,{className:`px-6 pt-6 pb-6`,children:(0,l.jsxs)(o.InlineEditProvider,{canEdit:!!h,children:[(0,l.jsx)(Te,{dataSource:u,inlineEdit:!!h,schema:{type:`detail-view`,objectName:s,resourceId:String(c),data:a,showDelete:!!g,columns:p,fields:k,actions:v?[{type:`action:bar`,location:`record_header`,systemActions:[{name:`sys_open_new_tab`,label:y(`detail.openInNewTab`),icon:`external-link`,type:`script`,onClick:()=>window.open(v,`_blank`,`noopener`)}]}]:void 0},onDelete:g?async()=>{try{await g(),t()}catch(e){console.error(`[RecordDetailDrawer] delete failed:`,e)}}:void 0}),(0,l.jsx)(Ft,{onFieldSave:h?async(e,t)=>{try{await h(e,t)}catch(e){throw console.error(`[RecordDetailDrawer] inline field save failed:`,e),e}}:void 0})]})})]})})}function Bt(e,t){if(typeof window>`u`)return null;let n=window.location.pathname,r=`/${e}`,i=n.indexOf(r);return`${i>=0?n.slice(0,i):n.replace(/\/$/,``)}/${e}/record/${encodeURIComponent(String(t))}`}var Vt=({objectName:e,relationshipField:t,fields:n,onCreateRecord:o,onLinkRecord:s,onSearch:c,existingRecords:u=[],className:d})=>{let[f,p]=r.useState(!1),[m,h]=r.useState(`create`),[g,_]=r.useState({}),[v,y]=r.useState(``),[b,x]=r.useState(u),[S,C]=r.useState(!1),[w,T]=r.useState(!1),E=r.useId(),D=r.useCallback(e=>`inline-create-${E}-${e}`,[E]),O=`inline-create-${E}-link-search`,k=`Search ${e}`,A=r.useMemo(()=>{if(!v.trim())return b;let e=v.toLowerCase();return b.filter(t=>t.label.toLowerCase().includes(e)||t.description?.toLowerCase().includes(e))},[v,b]),j=r.useCallback(async e=>{if(y(e),c&&e.trim().length>=2){T(!0);try{let t=await c(e);x(t)}finally{T(!1)}}},[c]),M=r.useCallback((e,t)=>{_(n=>({...n,[e]:t}))},[]),N=r.useCallback(async()=>{if(o){C(!0);try{await o({...g,[t]:!0}),_({}),p(!1)}finally{C(!1)}}},[o,g,t]),P=r.useCallback(async e=>{if(s){C(!0);try{await s(e),y(``),p(!1)}finally{C(!1)}}},[s]),F=r.useMemo(()=>n.filter(e=>e.required).every(e=>g[e.name]?.toString().trim()),[n,g]);return f?(0,l.jsxs)(i.Card,{className:(0,i.cn)(``,d),children:[(0,l.jsx)(i.CardHeader,{className:`pb-3`,children:(0,l.jsxs)(i.CardTitle,{className:`flex items-center justify-between text-sm`,children:[(0,l.jsxs)(`span`,{children:[m===`create`?`Create`:`Link`,` `,e]}),(0,l.jsx)(i.Button,{variant:`ghost`,size:`icon`,className:`h-6 w-6`,"aria-label":`Close`,onClick:()=>p(!1),children:(0,l.jsx)(a.X,{"aria-hidden":`true`,className:`h-3.5 w-3.5`})})]})}),(0,l.jsx)(i.CardContent,{children:(0,l.jsxs)(i.Tabs,{value:m,onValueChange:h,children:[(0,l.jsxs)(i.TabsList,{className:`mb-3 w-full`,children:[o&&(0,l.jsxs)(i.TabsTrigger,{value:`create`,className:`flex-1 gap-1.5`,children:[(0,l.jsx)(a.Plus,{className:`h-3.5 w-3.5`}),`Create New`]}),s&&(0,l.jsxs)(i.TabsTrigger,{value:`link`,className:`flex-1 gap-1.5`,children:[(0,l.jsx)(a.Link,{className:`h-3.5 w-3.5`}),`Link Existing`]})]}),o&&(0,l.jsxs)(i.TabsContent,{value:`create`,className:`space-y-3 mt-0`,children:[n.map(e=>(0,l.jsxs)(`div`,{children:[(0,l.jsxs)(`label`,{htmlFor:D(e.name),className:`text-xs font-medium text-muted-foreground mb-1 block`,children:[e.label,e.required&&(0,l.jsx)(`span`,{className:`text-destructive ml-0.5`,"aria-hidden":`true`,children:`*`})]}),(0,l.jsx)(i.Input,{id:D(e.name),"aria-required":e.required||void 0,type:e.type===`number`?`number`:e.type===`date`?`date`:`text`,placeholder:e.placeholder||`Enter ${e.label.toLowerCase()}`,value:g[e.name]||``,onChange:t=>M(e.name,t.target.value),className:`h-8 text-sm`})]},e.name)),(0,l.jsxs)(`div`,{className:`flex justify-end gap-2 pt-1`,children:[(0,l.jsx)(i.Button,{variant:`ghost`,size:`sm`,onClick:()=>p(!1),children:`Cancel`}),(0,l.jsxs)(i.Button,{size:`sm`,onClick:N,disabled:!F||S,className:`gap-1.5`,children:[S&&(0,l.jsx)(a.Loader2,{className:`h-3.5 w-3.5 animate-spin`}),`Create`]})]})]}),s&&(0,l.jsxs)(i.TabsContent,{value:`link`,className:`space-y-3 mt-0`,children:[(0,l.jsxs)(`div`,{className:`relative`,children:[(0,l.jsx)(`label`,{htmlFor:O,className:`sr-only`,children:k}),(0,l.jsx)(a.Search,{"aria-hidden":`true`,className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,l.jsx)(i.Input,{id:O,placeholder:`${k}…`,value:v,onChange:e=>j(e.target.value),className:`h-8 text-sm pl-8`})]}),(0,l.jsx)(`div`,{className:`max-h-48 overflow-y-auto space-y-1`,children:w?(0,l.jsxs)(`div`,{className:`flex items-center justify-center py-4 text-sm text-muted-foreground`,children:[(0,l.jsx)(a.Loader2,{className:`h-4 w-4 animate-spin mr-2`}),`Searching…`]}):A.length===0?(0,l.jsx)(`p`,{className:`text-sm text-muted-foreground text-center py-4`,children:v?`No records found`:`Type to search records`}):A.map(e=>(0,l.jsxs)(`button`,{type:`button`,className:`w-full text-left px-3 py-2 rounded-md hover:bg-accent text-sm transition-colors`,onClick:()=>P(e.id),disabled:S,children:[(0,l.jsx)(`span`,{className:`font-medium`,children:e.label}),e.description&&(0,l.jsx)(`span`,{className:`block text-xs text-muted-foreground mt-0.5`,children:e.description})]},e.id))})]})]})})]}):(0,l.jsxs)(`div`,{className:(0,i.cn)(`flex gap-2`,d),children:[o&&(0,l.jsxs)(i.Button,{variant:`outline`,size:`sm`,onClick:()=>{h(`create`),p(!0)},className:`gap-1.5`,children:[(0,l.jsx)(a.Plus,{className:`h-3.5 w-3.5`}),`New `,e]}),s&&(0,l.jsxs)(i.Button,{variant:`outline`,size:`sm`,onClick:()=>{h(`link`),p(!0)},className:`gap-1.5`,children:[(0,l.jsx)(a.Link,{className:`h-3.5 w-3.5`}),`Link Existing`]})]})};function Ht(e,t){if(e==null)return[`(empty)`];switch(t){case`json`:try{let t=typeof e==`string`?JSON.parse(e):e;return JSON.stringify(t,null,2).split(`
3
3
  `)}catch{return String(e).split(`
4
4
  `)}case`boolean`:return[String(!!e)];case`number`:return[String(e)];case`date`:try{return[new Date(e).toLocaleString()]}catch{return[String(e)]}default:return String(e).split(`
5
- `)}}function At(e,t){let n=[],r=Math.max(e.length,t.length);for(let i=0;i<r;i++){let r=i<e.length?e[i]:void 0,a=i<t.length?t[i]:void 0;r===a?n.push({type:`unchanged`,value:r}):(r!==void 0&&n.push({type:`removed`,value:r}),a!==void 0&&n.push({type:`added`,value:a}))}return n}var jt={added:`bg-green-50 text-green-800 dark:bg-green-950/30 dark:text-green-300`,removed:`bg-red-50 text-red-800 dark:bg-red-950/30 dark:text-red-300`,unchanged:`text-muted-foreground`},Mt={added:`+`,removed:`-`,unchanged:` `},Nt=({oldValue:e,newValue:t,fieldName:a,fieldType:o=`string`,mode:s=`unified`,className:c})=>{let{t:u}=D(),[d,f]=n.useState(s),p=n.useMemo(()=>kt(e,o),[e,o]),m=n.useMemo(()=>kt(t,o),[t,o]),h=n.useMemo(()=>At(p,m),[p,m]),g=h.some(e=>e.type!==`unchanged`),_=n.useMemo(()=>{if(d!==`side-by-side`)return[];let e=[],t=0;for(;t<h.length;){let n=h[t];if(n.type===`unchanged`)e.push({left:n,right:n}),t++;else if(n.type===`removed`){let r=t+1<h.length?h[t+1]:null;r&&r.type===`added`?(e.push({left:n,right:r}),t+=2):(e.push({left:n,right:null}),t++)}else e.push({left:null,right:n}),t++}return e},[d,h]);return(0,l.jsxs)(r.Card,{className:(0,r.cn)(`overflow-hidden`,c),children:[(0,l.jsx)(r.CardHeader,{className:`pb-2`,children:(0,l.jsxs)(r.CardTitle,{className:`flex items-center justify-between text-sm`,children:[(0,l.jsx)(`span`,{className:`font-medium`,children:a}),(0,l.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,l.jsx)(r.Button,{variant:d===`unified`?`secondary`:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:()=>f(`unified`),title:u(`detail.unifiedDiff`),children:(0,l.jsx)(i.Rows3,{className:`h-3.5 w-3.5`})}),(0,l.jsx)(r.Button,{variant:d===`side-by-side`?`secondary`:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:()=>f(`side-by-side`),title:u(`detail.sideBySideDiff`),children:(0,l.jsx)(i.Columns2,{className:`h-3.5 w-3.5`})})]})]})}),(0,l.jsx)(r.CardContent,{className:`p-0`,children:g?d===`unified`?(0,l.jsx)(`div`,{className:`font-mono text-xs overflow-x-auto`,children:h.map((e,t)=>(0,l.jsxs)(`div`,{className:(0,r.cn)(`px-4 py-0.5 whitespace-pre-wrap border-l-2`,jt[e.type],e.type===`added`&&`border-l-green-500`,e.type===`removed`&&`border-l-red-500`,e.type===`unchanged`&&`border-l-transparent`),children:[(0,l.jsx)(`span`,{className:`select-none mr-2 inline-block w-3 text-center opacity-60`,children:Mt[e.type]}),e.value]},t))}):(0,l.jsx)(`div`,{className:`overflow-x-auto`,children:(0,l.jsxs)(`div`,{className:`grid grid-cols-2 divide-x font-mono text-xs min-w-0`,children:[(0,l.jsx)(`div`,{className:`px-3 py-1.5 text-xs font-medium text-muted-foreground bg-muted/50`,children:u(`detail.previousVersion`)}),(0,l.jsx)(`div`,{className:`px-3 py-1.5 text-xs font-medium text-muted-foreground bg-muted/50`,children:u(`detail.currentVersion`)}),_.map((e,t)=>(0,l.jsxs)(n.Fragment,{children:[(0,l.jsx)(`div`,{className:(0,r.cn)(`px-3 py-0.5 whitespace-pre-wrap min-h-[1.5em]`,e.left?jt[e.left.type]:`bg-muted/20`),children:e.left?.value??``}),(0,l.jsx)(`div`,{className:(0,r.cn)(`px-3 py-0.5 whitespace-pre-wrap min-h-[1.5em]`,e.right?jt[e.right.type]:`bg-muted/20`),children:e.right?.value??``})]},t))]})}):(0,l.jsx)(`p`,{className:`px-4 py-3 text-sm text-muted-foreground`,children:u(`detail.noChanges`)})})]})},Pt=({currentIndex:e,totalRecords:t,recordIds:a,onNavigate:o,onSearch:s,className:c})=>{let{t:u}=D(),[d,f]=n.useState(``),[p,m]=n.useState(!1),h=n.useRef(null),g=e>0,_=e>0,v=e<t-1,y=e<t-1,b=n.useCallback(()=>{g&&o(a[0])},[g,o,a]),x=n.useCallback(()=>{_&&o(a[e-1])},[_,o,a,e]),S=n.useCallback(()=>{v&&o(a[e+1])},[v,o,a,e]),C=n.useCallback(()=>{y&&o(a[a.length-1])},[y,o,a]),w=n.useCallback(e=>{let t=e.target.value;f(t),s?.(t)},[s]),T=n.useCallback(()=>{m(e=>(e?(f(``),s?.(``)):requestAnimationFrame(()=>h.current?.focus()),!e))},[s]);return n.useEffect(()=>{let t=t=>{let n=t.target?.tagName;if(!((n===`INPUT`||n===`TEXTAREA`||t.target?.isContentEditable)&&t.target!==h.current)){if(t.target===h.current){t.key===`Escape`&&(t.preventDefault(),m(!1),f(``),s?.(``),t.target.blur());return}switch(t.key){case`Home`:t.preventDefault(),g&&o(a[0]);break;case`End`:t.preventDefault(),y&&o(a[a.length-1]);break;case`ArrowLeft`:t.preventDefault(),_&&o(a[e-1]);break;case`ArrowRight`:t.preventDefault(),v&&o(a[e+1]);break}}};return document.addEventListener(`keydown`,t),()=>document.removeEventListener(`keydown`,t)},[e,a,g,_,v,y,o,s]),(0,l.jsxs)(`div`,{className:(0,r.cn)(`flex items-center gap-1.5`,c),children:[(0,l.jsx)(r.Button,{variant:`outline`,size:`icon`,className:`h-8 w-8`,disabled:!g,onClick:b,title:u(`detail.firstRecord`),children:(0,l.jsx)(i.ChevronsLeft,{className:`h-4 w-4`})}),(0,l.jsx)(r.Button,{variant:`outline`,size:`icon`,className:`h-8 w-8`,disabled:!_,onClick:x,title:u(`detail.previousRecordKey`),children:(0,l.jsx)(i.ChevronLeft,{className:`h-4 w-4`})}),(0,l.jsx)(`span`,{className:`text-xs text-muted-foreground whitespace-nowrap px-1.5 tabular-nums`,children:t>0?u(`detail.recordOf`,{current:e+1,total:t}):u(`detail.noRecords`)}),(0,l.jsx)(r.Button,{variant:`outline`,size:`icon`,className:`h-8 w-8`,disabled:!v,onClick:S,title:u(`detail.nextRecordKey`),children:(0,l.jsx)(i.ChevronRight,{className:`h-4 w-4`})}),(0,l.jsx)(r.Button,{variant:`outline`,size:`icon`,className:`h-8 w-8`,disabled:!y,onClick:C,title:u(`detail.lastRecord`),children:(0,l.jsx)(i.ChevronsRight,{className:`h-4 w-4`})}),s&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(r.Button,{variant:p?`secondary`:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:T,title:u(`detail.searchWhileNavigating`),children:(0,l.jsx)(i.Search,{className:`h-4 w-4`})}),p&&(0,l.jsx)(`div`,{className:`relative`,children:(0,l.jsx)(r.Input,{ref:h,type:`text`,placeholder:u(`detail.searchRecords`),value:d,onChange:w,className:`h-8 w-48 text-sm`})})]})]})},Ft=28,It=[`fill-primary stroke-primary`,`fill-blue-500 stroke-blue-500`,`fill-emerald-500 stroke-emerald-500`,`fill-amber-500 stroke-amber-500`],Lt=[`fill-primary-foreground`,`fill-white`,`fill-white`,`fill-white`];function Rt(e,t,n,r,i){let a=[],o=[],s=new Set,c=r/2,l=i/2;a.push({id:e.id,label:e.label,type:e.type,x:c,y:l,level:0}),s.add(e.id);let u=Math.min(r,i)*.32,d=t.filter(e=>!s.has(e.id));if(d.forEach((t,n)=>{let r=2*Math.PI*n/d.length-Math.PI/2,i=c+u*Math.cos(r),f=l+u*Math.sin(r);a.push({id:t.id,label:t.label,type:t.type,x:i,y:f,level:1}),o.push({fromId:e.id,toId:t.id,fromX:c,fromY:l,toX:i,toY:f}),s.add(t.id)}),n>=2){let e=Math.min(r,i)*.46,t=[];d.forEach(e=>{let n=a.find(t=>t.id===e.id);n&&(e.relatedRecords||[]).filter(e=>!s.has(e.id)).forEach(r=>{t.push({node:r,parentX:n.x,parentY:n.y,parentId:e.id}),s.add(r.id)})}),t.forEach((n,r)=>{let i=2*Math.PI*r/Math.max(t.length,1)-Math.PI/2,s=c+e*Math.cos(i),u=l+e*Math.sin(i);a.push({id:n.node.id,label:n.node.label,type:n.node.type,x:s,y:u,level:2}),o.push({fromId:n.parentId,toId:n.node.id,fromX:n.parentX,fromY:n.parentY,toX:s,toY:u})})}return{nodes:a,edges:o}}function zt(e,t=6){return e.length<=t?e:e.slice(0,t-1)+`…`}var Bt=({record:e,relatedRecords:t,levels:a=1,onNodeClick:o,className:s})=>{let c=n.useRef(null),[u,d]=n.useState({width:500,height:400}),[f,p]=n.useState(null);n.useEffect(()=>{let e=c.current;if(!e)return;let t=e.parentElement;if(!t)return;let n=new ResizeObserver(e=>{for(let t of e){let{width:e}=t.contentRect;e>0&&d({width:e,height:Math.max(300,e*.7)})}});return n.observe(t),()=>n.disconnect()},[]);let{nodes:m,edges:h}=n.useMemo(()=>Rt(e,t,a,u.width,u.height),[e,t,a,u]);return(0,l.jsxs)(r.Card,{className:(0,r.cn)(`overflow-hidden`,s),children:[(0,l.jsx)(r.CardHeader,{className:`pb-2`,children:(0,l.jsxs)(r.CardTitle,{className:`flex items-center gap-2 text-base`,children:[(0,l.jsx)(i.Network,{className:`h-4 w-4`}),`Relationships`,(0,l.jsxs)(`span`,{className:`text-sm font-normal text-muted-foreground`,children:[`(`,t.length,` related)`]})]})}),(0,l.jsx)(r.CardContent,{className:`p-0`,children:(0,l.jsxs)(`svg`,{ref:c,width:`100%`,height:u.height,viewBox:`0 0 ${u.width} ${u.height}`,className:`select-none`,children:[h.map((e,t)=>(0,l.jsx)(`line`,{x1:e.fromX,y1:e.fromY,x2:e.toX,y2:e.toY,className:`stroke-border`,strokeWidth:1.5,strokeOpacity:.5},`edge-${t}`)),m.map(e=>{let t=f===e.id,n=It[Math.min(e.level,It.length-1)],i=Lt[Math.min(e.level,Lt.length-1)],a=e.level===0?34:Ft;return(0,l.jsxs)(`g`,{className:(0,r.cn)(`cursor-pointer transition-transform`,o&&`hover:opacity-80`),onClick:()=>o?.(e.id),onMouseEnter:()=>p(e.id),onMouseLeave:()=>p(null),children:[(0,l.jsx)(`circle`,{cx:e.x,cy:e.y,r:t?a+3:a,className:n,fillOpacity:e.level===0?1:.85,strokeWidth:2,strokeOpacity:.3}),(0,l.jsx)(`text`,{x:e.x,y:e.y,textAnchor:`middle`,dominantBaseline:`central`,className:(0,r.cn)(`text-[10px] font-medium pointer-events-none`,i),children:zt(e.label)}),e.type&&(0,l.jsx)(`text`,{x:e.x,y:e.y+a+12,textAnchor:`middle`,className:`fill-muted-foreground text-[9px] pointer-events-none`,children:e.type}),t&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`rect`,{x:e.x-50,y:e.y-a-28,width:100,height:20,rx:4,className:`fill-popover stroke-border`,strokeWidth:1}),(0,l.jsx)(`text`,{x:e.x,y:e.y-a-16,textAnchor:`middle`,dominantBaseline:`central`,className:`fill-popover-foreground text-[10px] pointer-events-none`,children:e.label})]})]},e.id)})]})})]})};function Vt(e){try{let t=new Date(e),n=new Date().getTime()-t.getTime(),r=Math.floor(n/6e4);if(r<1)return`just now`;if(r<60)return`${r}m ago`;let i=Math.floor(r/60);return i<24?`${i}h ago`:t.toLocaleString()}catch{return e}}var Ht=({recordId:e,revisions:t,onRestore:a,className:o})=>{let[s,c]=n.useState(null),[u,d]=n.useState(!1),[f,p]=n.useState(!1),m=n.useMemo(()=>t.find(e=>e.id===s)??null,[t,s]),h=n.useCallback(async()=>{if(!(!m||!a)){if(!u){d(!0);return}p(!0);try{let e=m.snapshot??{};await a(m.id,e),d(!1),c(null)}finally{p(!1)}}},[m,a,u]),g=n.useCallback(()=>{d(!1)},[]);return(0,l.jsxs)(r.Card,{className:(0,r.cn)(``,o),children:[(0,l.jsx)(r.CardHeader,{className:`pb-3`,children:(0,l.jsxs)(r.CardTitle,{className:`flex items-center gap-2 text-base`,children:[(0,l.jsx)(i.History,{className:`h-4 w-4`}),`Revision History`,(0,l.jsxs)(`span`,{className:`text-sm font-normal text-muted-foreground`,children:[`(`,t.length,`)`]})]})}),(0,l.jsx)(r.CardContent,{children:t.length===0?(0,l.jsx)(`p`,{className:`text-sm text-muted-foreground text-center py-4`,children:`No revisions recorded`}):(0,l.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-4`,children:[(0,l.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,l.jsxs)(`div`,{className:`relative`,children:[(0,l.jsx)(`div`,{className:`absolute left-3 top-2 bottom-2 w-px bg-border`}),(0,l.jsx)(`div`,{className:`space-y-1`,children:t.map(e=>{let t=e.id===s;return(0,l.jsxs)(`button`,{type:`button`,className:(0,r.cn)(`w-full text-left flex items-start gap-3 py-2 px-2 rounded-md transition-colors relative`,t?`bg-accent`:`hover:bg-accent/50`),onClick:()=>{c(e.id),d(!1)},children:[(0,l.jsx)(`div`,{className:(0,r.cn)(`shrink-0 h-6 w-6 rounded-full border-2 flex items-center justify-center z-10 mt-0.5`,t?`border-primary bg-primary`:`border-border bg-background`),children:t&&(0,l.jsx)(i.ChevronRight,{className:`h-3 w-3 text-primary-foreground`})}),(0,l.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(`span`,{className:`text-sm font-medium`,children:e.user}),(0,l.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:Vt(e.timestamp)})]}),(0,l.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:[e.changes.length,` field`,e.changes.length===1?``:`s`,` `,`changed`]})]})]},e.id)})})]})}),m&&(0,l.jsxs)(`div`,{className:`lg:w-80 border rounded-md p-3 space-y-3`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium`,children:[(0,l.jsx)(i.Eye,{className:`h-4 w-4 text-muted-foreground`}),`Revision Preview`]}),(0,l.jsx)(`div`,{className:`space-y-2`,children:m.changes.map((e,t)=>(0,l.jsxs)(`div`,{className:`text-xs`,children:[(0,l.jsx)(`span`,{className:`font-medium text-muted-foreground`,children:e.field}),(0,l.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-0.5`,children:[(0,l.jsx)(`span`,{className:`line-through text-red-600 dark:text-red-400 truncate max-w-[120px]`,children:e.oldValue==null?`(empty)`:String(e.oldValue)}),(0,l.jsx)(i.ChevronRight,{className:`h-3 w-3 text-muted-foreground shrink-0`}),(0,l.jsx)(`span`,{className:`text-green-600 dark:text-green-400 truncate max-w-[120px]`,children:e.newValue==null?`(empty)`:String(e.newValue)})]})]},t))}),m.snapshot&&(0,l.jsxs)(`div`,{className:`border-t pt-2 space-y-1`,children:[(0,l.jsx)(`p`,{className:`text-xs font-medium text-muted-foreground`,children:`Record state at this point`}),(0,l.jsx)(`div`,{className:`max-h-40 overflow-y-auto space-y-1`,children:Object.entries(m.snapshot).map(([e,t])=>(0,l.jsxs)(`div`,{className:`flex justify-between text-xs gap-2`,children:[(0,l.jsx)(`span`,{className:`text-muted-foreground truncate`,children:e}),(0,l.jsx)(`span`,{className:`font-mono truncate max-w-[140px]`,children:t==null?`–`:String(t)})]},e))})]}),a&&(0,l.jsx)(`div`,{className:`pt-1 space-y-2`,children:u?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(`p`,{className:`text-xs text-amber-600 dark:text-amber-400`,children:[`This will restore the record to its state at`,` `,Vt(m.timestamp),`. Continue?`]}),(0,l.jsxs)(`div`,{className:`flex gap-2`,children:[(0,l.jsxs)(r.Button,{variant:`destructive`,size:`sm`,className:`gap-1.5 flex-1`,onClick:h,disabled:f,children:[(0,l.jsx)(i.RotateCcw,{className:`h-3.5 w-3.5`}),f?`Restoring…`:`Confirm Restore`]}),(0,l.jsx)(r.Button,{variant:`ghost`,size:`sm`,onClick:g,disabled:f,children:`Cancel`})]})]}):(0,l.jsxs)(r.Button,{variant:`outline`,size:`sm`,className:`w-full gap-1.5`,onClick:h,children:[(0,l.jsx)(i.RotateCcw,{className:`h-3.5 w-3.5`}),`Restore to this point`]})})]})]})})]})},Ut=({onSubmit:e,placeholder:t=`Leave a comment…`,disabled:a=!1,className:o})=>{let[s,c]=n.useState(``),[u,d]=n.useState(!1),f=n.useCallback(async()=>{let t=s.trim();if(t){d(!0);try{await e(t),c(``)}finally{d(!1)}}},[s,e]),p=n.useCallback(e=>{e.key===`Enter`&&(e.ctrlKey||e.metaKey)&&(e.preventDefault(),f())},[f]);return(0,l.jsxs)(`div`,{className:(0,r.cn)(`flex gap-2`,o),children:[(0,l.jsx)(`textarea`,{className:`flex-1 min-h-[60px] rounded-md border border-input bg-background px-3 py-2 text-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring resize-none`,placeholder:t,value:s,onChange:e=>c(e.target.value),onKeyDown:p,disabled:a||u}),(0,l.jsx)(r.Button,{size:`icon`,variant:`default`,onClick:f,disabled:!s.trim()||u||a,className:`shrink-0 self-end`,"aria-label":`Submit comment`,children:(0,l.jsx)(i.Send,{className:`h-4 w-4`})})]})},Wt=({query:e,suggestions:t,onSelect:i,visible:a=!0,activeIndex:o=0,className:s})=>{let c=n.useMemo(()=>{if(!e)return t;let n=e.toLowerCase();return t.filter(e=>e.name.toLowerCase().includes(n)||e.id.toLowerCase().includes(n))},[e,t]);return!a||c.length===0?null:(0,l.jsx)(`div`,{className:(0,r.cn)(`bg-popover border rounded-md shadow-md z-50 max-h-48 overflow-y-auto w-56`,s),role:`listbox`,"aria-label":`Mention suggestions`,children:c.map((e,t)=>(0,l.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":t===o,className:(0,r.cn)(`w-full text-left px-3 py-1.5 text-sm flex items-center gap-2 hover:bg-accent transition-colors`,t===o&&`bg-accent`),onMouseDown:t=>{t.preventDefault(),i(e)},children:[e.avatarUrl?(0,l.jsx)(`img`,{src:e.avatarUrl,alt:e.name,className:`h-5 w-5 rounded-full object-cover`}):(0,l.jsx)(`div`,{className:`h-5 w-5 rounded-full bg-muted flex items-center justify-center text-[10px] font-medium`,children:e.name.charAt(0).toUpperCase()}),(0,l.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,l.jsx)(`span`,{className:`truncate`,children:e.name}),e.type!==`user`&&(0,l.jsxs)(`span`,{className:`ml-1 text-xs text-muted-foreground capitalize`,children:[`(`,e.type,`)`]})]})]},e.id))})};function Gt(e,t,n){return{type:e.type,id:e.id,name:e.name,offset:t,length:n}}function Kt(e,t){if(!e||!t.length)return[];let n=[...t].sort((e,t)=>t.label.length-e.label.length),r=e,i=new Set;for(let e of n){if(!e.label)continue;let t=e.label.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),n=RegExp(`@${t}(?![\\p{L}\\p{N}_])`,`gu`);n.test(r)&&(i.add(e.id),r=r.replace(n,e=>` `.repeat(e.length)))}return[...i]}function qt(e){return e==null?[]:Array.isArray(e)?e.filter(e=>e!=null):[e]}function Jt(e,t){if(!e||!t)return null;let n=e.fields?.[t]?.options;return!Array.isArray(n)||n.length===0?null:n.map(e=>({value:e.value,label:e.label}))}function Yt(e){if(!e)return null;let t=e.fields||{};for(let n of[e.primaryField,e.nameField,e.displayNameField])if(typeof n==`string`&&n.length>0&&n in t)return n;for(let e of[`name`,`full_name`,`title`,`subject`,`display_name`])if(e in t)return e;return null}function Xt(e,t,n=4){if(!e)return[];let r=Array.isArray(e.highlightFields)&&e.highlightFields.length>0?e.highlightFields:null;if(r){let t=Yt(e);return r.filter(e=>typeof e==`string`&&e.length>0&&e!==t).slice(0,n)}let i=new Set([`id`,`_id`,`created_at`,`updated_at`,`deleted_at`,`created_by`,`updated_by`,`deleted_by`,`organization_id`,`workspace_id`,`tenant_id`,`org_id`]);t&&i.add(t),e.primaryField&&i.add(e.primaryField),e.nameField&&i.add(e.nameField),e.displayNameField&&i.add(e.displayNameField);for(let t of[`name`,`full_name`,`title`,`subject`,`display_name`])t in(e.fields||{})&&i.add(t);let a=[`owner`,`owner_id`,`amount`,`rating`,`source`,`priority`,`industry`,`phone`,`email`,`close_date`,`due_date`,`start_date`,`expected_close_date`,`account`,`account_id`,`contact`,`contact_id`],o=new Set([`currency`,`number`,`integer`,`decimal`,`percent`,`date`,`datetime`,`time`,`reference`,`lookup`,`user`,`owner`,`select`,`enum`,`multiselect`,`status`,`email`,`phone`,`url`,`text`,`string`]),s=[],c=e.fields||{};for(let e of a)if(e in c&&!i.has(e)&&s.push(e),s.length>=n)return s;for(let e of Object.keys(c)){if(s.includes(e)||i.has(e))continue;let t=c[e]?.type;if(!(t&&!o.has(t))&&(s.push(e),s.length>=n))break}return s}function Zt(e,t={}){return{type:`page:header`,recordChrome:t.recordChrome!==!1,...Array.isArray(t.actions)&&t.actions.length>0?{actions:t.actions}:{}}}function Qt(e,t){return!Array.isArray(t)||t.length===0?null:{type:`record:quick_actions`,actions:t,location:`record_header`}}function $t(e,t={}){let n=t.statusField??(0,d.detectStatusField)(e),r=t.stages??(n?Jt(e,n):null),i=t.highlightFields??Xt(e,n),a=[];return!t.hideHighlights&&i.length>0&&a.push({type:`record:highlights`,fields:i}),!t.hidePath&&n&&r&&r.length>0&&a.push({type:`record:path`,statusField:n,stages:r}),a}function en(e){if(!e)return null;let t=(0,f.deriveFieldGroupLayout)(e);if(!t)return null;let n=e.fields||{},r=e=>{let t=n[e]||{};return{name:e,label:t.label||e,type:t.type||`text`,...t.options?{options:t.options}:{},...t.reference_to||t.reference?{reference_to:t.reference_to||t.reference}:{},...t.reference_field?{reference_field:t.reference_field}:{},...t.currency?{currency:t.currency}:{},...t.currencyConfig?{currencyConfig:t.currencyConfig}:{}}},i=S(t.reduce((e,t)=>e+t.fields.length,0));return t.map(e=>({...e.key===void 0?{}:{name:e.key,title:e.label??e.key},...e.icon?{icon:e.icon}:{},...e.description?{description:e.description}:{},...e.collapse===`none`?{}:{collapsible:!0},...e.collapse===`collapsed`?{defaultCollapsed:!0}:{},columns:i,fields:e.fields.map(r)}))}function tn(e,t){return Array.isArray(t)&&t.length>0?t:en(e)??void 0}function nn(e,t,n){return{type:`record:details`,sections:tn(e,t),...n&&n.length>0?{hideFields:n}:{}}}function rn(e,t={}){let n=t.statusField??(0,d.detectStatusField)(e),r=t.highlightFields??Xt(e,n),i=[{label:`Details`,value:`details`,children:[nn(e,t.sections,r)]}];if(!t.hideRelatedTab&&Array.isArray(t.related)&&t.related.length>0){let e=e=>({type:`record:related_list`,title:e.title,objectName:e.objectName,relationshipField:e.relationshipField,...e.columns?{columns:e.columns}:{},...e.limit?{limit:e.limit}:{},...e.icon?{icon:e.icon}:{}}),n=t=>({label:t.title||t.objectName,value:`related:${t.objectName}`,...t.icon?{icon:t.icon}:{},children:[e(t)]});if(t.relatedLayout===`tabs`)for(let e of t.related)i.push(n(e));else if(t.relatedLayout===`stack`)i.push({label:`Related`,value:`related`,children:t.related.map(e)});else{let r=t.related.filter(e=>e.isPrimary),a=t.related.filter(e=>!e.isPrimary);for(let e of r)i.push(n(e));a.length>0&&i.push({label:`Related`,value:`related`,children:a.map(e)})}}return e?.enable?.files===!0&&!t.hideAttachments&&i.push({label:`Attachments`,value:`attachments`,children:[on()]}),t.showActivity&&i.push({label:`Activity`,value:`activity`,children:[{type:`record:activity`}]}),t.history&&i.push({label:`History`,value:`history`,children:[{type:`record:history`,entries:t.history.entries,loading:t.history.loading,emptyText:t.history.emptyText,unknownUserText:t.history.unknownUserText}]}),{type:`page:tabs`,items:i}}function an(){return{type:`record:discussion`}}function on(){return{type:`record:attachments`}}function sn(e,t={}){let n=t.slots||{},r=[];`header`in n&&n.header!==void 0?r.push(...qt(n.header)):r.push(Zt(e,{recordChrome:t.recordChrome,actions:t.headerActions})),`actions`in n&&n.actions!==void 0&&r.push(...qt(n.actions)),`alerts`in n&&n.alerts!==void 0&&r.push(...qt(n.alerts)),`highlights`in n&&n.highlights!==void 0?r.push(...qt(n.highlights)):r.push(...$t(e,{highlightFields:t.highlightFields,statusField:t.statusField,stages:t.stages,hideHighlights:t.hideHighlights,hidePath:t.hidePath}));let i=t.showReferenceRail===!0&&!t.hideReferenceRail&&Array.isArray(t.related)&&t.related.length>=2,a=t.hideRelatedTab??i;if(`tabs`in n&&n.tabs!==void 0)r.push(...qt(n.tabs));else if(`details`in n&&n.details!==void 0){let i=qt(n.details),o=rn(e,{sections:t.sections,related:t.related,showActivity:t.showActivity,history:t.history,highlightFields:t.highlightFields,statusField:t.statusField,hideRelatedTab:a,relatedLayout:t.relatedLayout,hideAttachments:t.hideAttachments});Array.isArray(o.items)&&o.items.length>0&&(o.items[0]={...o.items[0],children:i}),r.push(o)}else r.push(rn(e,{sections:t.sections,related:t.related,showActivity:t.showActivity,history:t.history,highlightFields:t.highlightFields,statusField:t.statusField,hideRelatedTab:a,relatedLayout:t.relatedLayout,hideAttachments:t.hideAttachments}));`discussion`in n&&n.discussion!==void 0?r.push(...qt(n.discussion)):t.hideDiscussion||r.push(an());let o=[{name:`main`,width:`full`,components:r}],s=qt(n.rightRail);if(i||s.length>0){let e=[];i&&e.push({type:`record:reference_rail`,entries:t.related.map(e=>({objectName:e.objectName,relationshipField:e.relationshipField,title:e.title,icon:e.icon,displayField:e.displayField,limit:3}))}),s.length>0&&e.push(...s),o.push({name:`aside`,width:`small`,className:`hidden xl:flex flex-col gap-4`,components:e})}return{type:`record`,pageType:`record`,object:e?.name,template:`full-width`,regions:o}}t.ComponentRegistry.register(`detail-view`,Q,{namespace:`plugin-detail`,label:`Detail View`,category:`Views`,icon:`FileText`,inputs:[{name:`title`,type:`string`,label:`Title`},{name:`objectName`,type:`string`,label:`Object Name`},{name:`resourceId`,type:`string`,label:`Resource ID`},{name:`api`,type:`string`,label:`API Endpoint`},{name:`data`,type:`object`,label:`Data`},{name:`layout`,type:`enum`,label:`Layout Mode`,enum:[`vertical`,`horizontal`,`grid`]},{name:`columns`,type:`number`,label:`Grid Columns`},{name:`sections`,type:`array`,label:`Sections`},{name:`fields`,type:`array`,label:`Fields`},{name:`tabs`,type:`array`,label:`Tabs`},{name:`related`,type:`array`,label:`Related Lists`},{name:`actions`,type:`array`,label:`Actions`},{name:`showBack`,type:`boolean`,label:`Show Back Button`,defaultValue:!0},{name:`backUrl`,type:`string`,label:`Back URL`},{name:`showEdit`,type:`boolean`,label:`Show Edit Button`,defaultValue:!1},{name:`editUrl`,type:`string`,label:`Edit URL`},{name:`showDelete`,type:`boolean`,label:`Show Delete Button`,defaultValue:!1},{name:`deleteConfirmation`,type:`string`,label:`Delete Confirmation Message`},{name:`loading`,type:`boolean`,label:`Show Loading State`},{name:`header`,type:`object`,label:`Custom Header`},{name:`footer`,type:`object`,label:`Custom Footer`}],defaultProps:{title:`Detail View`,showBack:!0,showEdit:!1,showDelete:!1,sections:[],fields:[],tabs:[],related:[]}}),t.ComponentRegistry.register(`detail-section`,L,{namespace:`plugin-detail`,label:`Detail Section`,category:`Detail Components`,inputs:[{name:`title`,type:`string`,label:`Title`},{name:`description`,type:`string`,label:`Description`},{name:`fields`,type:`array`,label:`Fields`,required:!0},{name:`collapsible`,type:`boolean`,label:`Collapsible`,defaultValue:!1},{name:`defaultCollapsed`,type:`boolean`,label:`Default Collapsed`,defaultValue:!1},{name:`columns`,type:`number`,label:`Columns`,defaultValue:2},{name:`showBorder`,type:`boolean`,label:`Show Border`,defaultValue:!0},{name:`headerColor`,type:`string`,label:`Header Color`}]}),t.ComponentRegistry.register(`related-list`,z,{namespace:`plugin-detail`,label:`Related List`,category:`Detail Components`,inputs:[{name:`title`,type:`string`,label:`Title`,required:!0},{name:`type`,type:`enum`,label:`Type`,enum:[{label:`List`,value:`list`},{label:`Grid`,value:`grid`},{label:`Table`,value:`table`}],defaultValue:`table`},{name:`api`,type:`string`,label:`API Endpoint`},{name:`data`,type:`array`,label:`Data`},{name:`columns`,type:`array`,label:`Columns`}]}),t.ComponentRegistry.register(`detail`,Q,{namespace:`view`,category:`view`,label:`Detail`,icon:`FileText`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`recordId`,type:`string`,label:`Record ID`},{name:`fields`,type:`array`,label:`Fields`}]}),t.ComponentRegistry.register(`details`,we,{namespace:`record`,skipFallback:!0,category:`record`,label:`Record Details`,icon:`FileText`,inputs:[{name:`columns`,type:`enum`,label:`Columns`,enum:[`1`,`2`,`3`,`4`],defaultValue:`2`,description:`Number of columns for field layout (1-4)`},{name:`layout`,type:`enum`,label:`Layout`,enum:[`auto`,`custom`],defaultValue:`auto`,description:`auto uses the object highlightFields; custom uses explicit sections`},{name:`sections`,type:`array`,label:`Sections`,description:`Section IDs to show (required when layout is "custom")`},{name:`fields`,type:`array`,label:`Fields`,description:`Explicit field list (overrides highlightFields)`}]}),t.ComponentRegistry.register(`related_list`,ke,{namespace:`record`,skipFallback:!0,category:`record`,label:`Related List`,icon:`List`,inputs:[{name:`objectName`,type:`string`,label:`Related Object`,required:!0,description:`Related object name (e.g. "task")`},{name:`relationshipField`,type:`string`,label:`Relationship Field`,required:!0,description:`Field on the related object pointing back to this record`},{name:`columns`,type:`array`,label:`Columns`,required:!0,description:`Fields to display in the related list`},{name:`sort`,type:`array`,label:`Sort`},{name:`limit`,type:`number`,label:`Limit`,defaultValue:5,description:`Records to display initially`},{name:`filter`,type:`array`,label:`Filter`,description:`Additional filter criteria`},{name:`title`,type:`string`,label:`Title`},{name:`showViewAll`,type:`boolean`,label:`Show "View All"`,defaultValue:!0},{name:`actions`,type:`array`,label:`Actions`,description:`Action IDs available for related records`}]}),t.ComponentRegistry.register(`highlights`,je,{namespace:`record`,skipFallback:!0,category:`record`,label:`Highlights Panel`,icon:`Star`,inputs:[{name:`fields`,type:`array`,label:`Fields`,required:!0,description:`Key fields to highlight (1-7), bare names or {name,label?,icon?,type?}`},{name:`layout`,type:`enum`,label:`Layout`,enum:[`horizontal`,`vertical`],defaultValue:`horizontal`,description:`Layout orientation for highlight fields`}]}),t.ComponentRegistry.register(`activity`,Ze,{namespace:`record`,skipFallback:!0,category:`record`,label:`Activity Timeline`,icon:`Activity`,inputs:[{name:`types`,type:`array`,label:`Activity Types`,description:`Activity types to display (e.g. task, event, call, comment)`},{name:`filterMode`,type:`string`,label:`Filter Mode`,description:`How the type filter combines with the feed query`},{name:`showFilterToggle`,type:`boolean`,label:`Show Filter Toggle`,description:`Expose the activity-type filter UI`},{name:`limit`,type:`number`,label:`Limit`,description:`Maximum activities to display`},{name:`showCompleted`,type:`boolean`,label:`Show Completed`,description:`Include completed/resolved activities`},{name:`unifiedTimeline`,type:`boolean`,label:`Unified Timeline`,description:`Merge all activity types into one timeline`},{name:`showCommentInput`,type:`boolean`,label:`Show Comment Input`},{name:`enableMentions`,type:`boolean`,label:`Enable @mentions`},{name:`enableReactions`,type:`boolean`,label:`Enable Reactions`},{name:`enableThreading`,type:`boolean`,label:`Enable Threaded Replies`},{name:`showSubscriptionToggle`,type:`boolean`,label:`Show Subscribe Toggle`}]});var cn=[{name:`position`,type:`enum`,label:`Position`,enum:[`bottom`,`right`,`left`],defaultValue:`bottom`,description:`Where the panel docks relative to the record body`},{name:`width`,type:`string`,label:`Width`,description:`Panel width as a CSS value (side positions only)`},{name:`collapsible`,type:`boolean`,label:`Collapsible`,defaultValue:!1},{name:`defaultCollapsed`,type:`boolean`,label:`Start Collapsed`},{name:`feed`,type:`object`,label:`Feed Options`,description:`Activity-feed config nested inside the panel — same shape as record:activity`}];t.ComponentRegistry.register(`chatter`,et,{namespace:`record`,skipFallback:!0,category:`record`,label:`Chatter Feed`,icon:`MessageSquare`,inputs:cn}),t.ComponentRegistry.register(`discussion`,et,{namespace:`record`,skipFallback:!0,category:`record`,label:`Discussion`,icon:`MessageSquare`,inputs:cn}),t.ComponentRegistry.register(`path`,nt,{namespace:`record`,skipFallback:!0,category:`record`,label:`Path / Stepper`,icon:`GitBranch`,inputs:[{name:`statusField`,type:`string`,label:`Status Field`,required:!0,description:`Field representing the current status/stage`},{name:`stages`,type:`array`,label:`Stages`,description:`Explicit stage definitions [{ value, label }] (else derived from field metadata)`}]}),t.ComponentRegistry.register(`quick_actions`,it,{namespace:`record`,skipFallback:!0,category:`record`,label:`Quick Actions`,icon:`Zap`,inputs:[{name:`actionNames`,type:`array`,label:`Actions`,description:`Action names to expose, in order (else every action declared for the object at this location)`},{name:`requiredPermissions`,type:`array`,label:`Required Permissions`,description:`Hide the whole bar unless the user holds these permissions`},{name:`location`,type:`enum`,label:`Location`,enum:[...d.ACTION_LOCATIONS],defaultValue:`record_header`,description:`Which declared action location this bar renders`},{name:`align`,type:`enum`,label:`Align`,enum:[`start`,`center`,`end`],defaultValue:`end`},{name:`inline`,type:`boolean`,label:`Inline`,description:`Render in the flow instead of folding into the record header`},{name:`variant`,type:`string`,label:`Button Variant`,defaultValue:`default`,description:`Passed to the Button primitive; a per-action variant overrides it`},{name:`size`,type:`string`,label:`Button Size`,defaultValue:`sm`,description:`Passed to the Button primitive; a per-action size overrides it`}]}),t.ComponentRegistry.register(`history`,ct,{namespace:`record`,skipFallback:!0,category:`record`,label:`History Timeline`,icon:`Clock`,inputs:[{name:`limit`,type:`number`,label:`Limit`,defaultValue:50,description:`Maximum history entries to display`},{name:`emptyText`,type:`string`,label:`Empty Text`,description:`Copy shown when the record has no history`},{name:`unknownUserText`,type:`string`,label:`Unknown User Text`,description:`Copy substituted when an entry has no resolvable actor`}]}),t.ComponentRegistry.register(`reference_rail`,ft,{namespace:`record`,skipFallback:!0,category:`record`,label:`Reference Rail`,icon:`PanelRight`,inputs:[{name:`hideEmpty`,type:`boolean`,label:`Hide When Empty`,defaultValue:!0,description:`Drop the rail entirely when no entries resolve`}]}),t.ComponentRegistry.register(`alert`,ht,{namespace:`record`,skipFallback:!0,category:`record`,label:`Alert Banner`,icon:`AlertTriangle`,inputs:[{name:`severity`,type:`enum`,label:`Severity`,enum:[`info`,`warning`,`error`,`success`],defaultValue:`info`},{name:`title`,type:`string`,label:`Title`,description:`Accepts an inline translation map ({ en, "zh-CN", … })`},{name:`body`,type:`string`,label:`Body`,description:`Accepts an inline translation map ({ en, "zh-CN", … })`},{name:`visible`,type:`string`,label:`Visible When`,description:`Expression gating the banner against the current record`},{name:`icon`,type:`string`,label:`Icon`,description:`Lucide icon name; defaults to the severity icon`},{name:`action`,type:`object`,label:`Call to Action`,description:`{ actionName, label?, variant? } — the action the banner offers`},{name:`dismissible`,type:`boolean`,label:`Dismissible`},{name:`dismissKey`,type:`string`,label:`Dismiss Key`,description:`Stable key the dismissal is remembered under`}]}),t.ComponentRegistry.register(`permission-facet-link`,A,{namespace:`field`,skipFallback:!0}),e.ActivityTimeline=oe,e.CommentAttachment=Ue,e.CommentInput=Ut,e.ConcurrentUpdateDialog=vt,e.DETAIL_DEFAULT_TRANSLATIONS=E,e.DetailSection=L,e.DetailTabs=R,e.DetailView=Q,e.DiffView=Nt,e.FieldChangeItem=Me,e.HeaderHighlight=V,e.HistoryTimeline=de,e.InlineCreateRelated=Ot,e.InlineEditSaveBar=St,e.InlineFieldInput=ee,e.MentionAutocomplete=Wt,e.PointInTimeRestore=Ht,e.ReactionPicker=Pe,e.RecordActivityRenderer=Ze,e.RecordActivityTimeline=Ye,e.RecordAlertRenderer=ht,e.RecordChatterPanel=Qe,e.RecordChatterRenderer=et,e.RecordComments=U,e.RecordDetailDrawer=Et,e.RecordDetailsRenderer=we,e.RecordHighlightsRenderer=je,e.RecordHistoryRenderer=ct,e.RecordMetaFooter=_e,e.RecordNavigationEnhanced=Pt,e.RecordPathRenderer=nt,e.RecordQuickActionsRenderer=it,e.RecordReferenceRailRenderer=ft,e.RecordRelatedListRenderer=ke,e.RelatedList=z,e.RelationshipGraph=Bt,e.RichTextCommentInput=ze,e.SectionGroup=B,e.SubscriptionToggle=Le,e.TEXTUAL_REF_FALLBACK_TYPES=M,e.ThreadedReplies=Ie,e.__clearRecordEditableCache=be,e.applyAutoSpan=C,e.applyDetailAutoLayout=w,e.buildDefaultActions=Qt,e.buildDefaultDetails=nn,e.buildDefaultDiscussion=an,e.buildDefaultHeader=Zt,e.buildDefaultHighlights=$t,e.buildDefaultPageSchema=sn,e.buildDefaultTabs=rn,e.createMentionFromSuggestion=Gt,e.createSafeTranslationHook=T,e.deriveFieldGroupDetailSections=en,e.deriveHighlightFields=Xt,e.deriveRecordPageHref=Dt,e.deriveStages=Jt,e.detectStatusField=d.detectStatusField,e.extractLookupId=N,e.extractMentions=Kt,e.inferDetailColumns=S,e.isConcurrentUpdateError=yt,e.isWideFieldType=x,e.resolveDetailSections=tn,e.resolveTitleField=Yt,e.useDetailTranslation=D,e.useRecordEditable=ye});
5
+ `)}}function Ut(e,t){let n=[],r=Math.max(e.length,t.length);for(let i=0;i<r;i++){let r=i<e.length?e[i]:void 0,a=i<t.length?t[i]:void 0;r===a?n.push({type:`unchanged`,value:r}):(r!==void 0&&n.push({type:`removed`,value:r}),a!==void 0&&n.push({type:`added`,value:a}))}return n}var Wt={added:`bg-green-50 text-green-800 dark:bg-green-950/30 dark:text-green-300`,removed:`bg-red-50 text-red-800 dark:bg-red-950/30 dark:text-red-300`,unchanged:`text-muted-foreground`},Gt={added:`+`,removed:`-`,unchanged:` `},Kt=({oldValue:e,newValue:t,fieldName:n,fieldType:o=`string`,mode:s=`unified`,className:c})=>{let{t:u}=D(),[d,f]=r.useState(s),p=r.useMemo(()=>Ht(e,o),[e,o]),m=r.useMemo(()=>Ht(t,o),[t,o]),h=r.useMemo(()=>Ut(p,m),[p,m]),g=h.some(e=>e.type!==`unchanged`),_=r.useMemo(()=>{if(d!==`side-by-side`)return[];let e=[],t=0;for(;t<h.length;){let n=h[t];if(n.type===`unchanged`)e.push({left:n,right:n}),t++;else if(n.type===`removed`){let r=t+1<h.length?h[t+1]:null;r&&r.type===`added`?(e.push({left:n,right:r}),t+=2):(e.push({left:n,right:null}),t++)}else e.push({left:null,right:n}),t++}return e},[d,h]);return(0,l.jsxs)(i.Card,{className:(0,i.cn)(`overflow-hidden`,c),children:[(0,l.jsx)(i.CardHeader,{className:`pb-2`,children:(0,l.jsxs)(i.CardTitle,{className:`flex items-center justify-between text-sm`,children:[(0,l.jsx)(`span`,{className:`font-medium`,children:n}),(0,l.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,l.jsx)(i.Button,{variant:d===`unified`?`secondary`:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:()=>f(`unified`),title:u(`detail.unifiedDiff`),children:(0,l.jsx)(a.Rows3,{className:`h-3.5 w-3.5`})}),(0,l.jsx)(i.Button,{variant:d===`side-by-side`?`secondary`:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:()=>f(`side-by-side`),title:u(`detail.sideBySideDiff`),children:(0,l.jsx)(a.Columns2,{className:`h-3.5 w-3.5`})})]})]})}),(0,l.jsx)(i.CardContent,{className:`p-0`,children:g?d===`unified`?(0,l.jsx)(`div`,{className:`font-mono text-xs overflow-x-auto`,children:h.map((e,t)=>(0,l.jsxs)(`div`,{className:(0,i.cn)(`px-4 py-0.5 whitespace-pre-wrap border-l-2`,Wt[e.type],e.type===`added`&&`border-l-green-500`,e.type===`removed`&&`border-l-red-500`,e.type===`unchanged`&&`border-l-transparent`),children:[(0,l.jsx)(`span`,{className:`select-none mr-2 inline-block w-3 text-center opacity-60`,children:Gt[e.type]}),e.value]},t))}):(0,l.jsx)(`div`,{className:`overflow-x-auto`,children:(0,l.jsxs)(`div`,{className:`grid grid-cols-2 divide-x font-mono text-xs min-w-0`,children:[(0,l.jsx)(`div`,{className:`px-3 py-1.5 text-xs font-medium text-muted-foreground bg-muted/50`,children:u(`detail.previousVersion`)}),(0,l.jsx)(`div`,{className:`px-3 py-1.5 text-xs font-medium text-muted-foreground bg-muted/50`,children:u(`detail.currentVersion`)}),_.map((e,t)=>(0,l.jsxs)(r.Fragment,{children:[(0,l.jsx)(`div`,{className:(0,i.cn)(`px-3 py-0.5 whitespace-pre-wrap min-h-[1.5em]`,e.left?Wt[e.left.type]:`bg-muted/20`),children:e.left?.value??``}),(0,l.jsx)(`div`,{className:(0,i.cn)(`px-3 py-0.5 whitespace-pre-wrap min-h-[1.5em]`,e.right?Wt[e.right.type]:`bg-muted/20`),children:e.right?.value??``})]},t))]})}):(0,l.jsx)(`p`,{className:`px-4 py-3 text-sm text-muted-foreground`,children:u(`detail.noChanges`)})})]})},qt=({currentIndex:e,totalRecords:t,recordIds:n,onNavigate:o,onSearch:s,className:c})=>{let{t:u}=D(),[d,f]=r.useState(``),[p,m]=r.useState(!1),h=r.useRef(null),g=e>0,_=e>0,v=e<t-1,y=e<t-1,b=r.useCallback(()=>{g&&o(n[0])},[g,o,n]),x=r.useCallback(()=>{_&&o(n[e-1])},[_,o,n,e]),S=r.useCallback(()=>{v&&o(n[e+1])},[v,o,n,e]),C=r.useCallback(()=>{y&&o(n[n.length-1])},[y,o,n]),w=r.useCallback(e=>{let t=e.target.value;f(t),s?.(t)},[s]),T=r.useCallback(()=>{m(e=>(e?(f(``),s?.(``)):requestAnimationFrame(()=>h.current?.focus()),!e))},[s]);return r.useEffect(()=>{let t=t=>{let r=t.target?.tagName;if(!((r===`INPUT`||r===`TEXTAREA`||t.target?.isContentEditable)&&t.target!==h.current)){if(t.target===h.current){t.key===`Escape`&&(t.preventDefault(),m(!1),f(``),s?.(``),t.target.blur());return}switch(t.key){case`Home`:t.preventDefault(),g&&o(n[0]);break;case`End`:t.preventDefault(),y&&o(n[n.length-1]);break;case`ArrowLeft`:t.preventDefault(),_&&o(n[e-1]);break;case`ArrowRight`:t.preventDefault(),v&&o(n[e+1])}}};return document.addEventListener(`keydown`,t),()=>document.removeEventListener(`keydown`,t)},[e,n,g,_,v,y,o,s]),(0,l.jsxs)(`div`,{className:(0,i.cn)(`flex items-center gap-1.5`,c),children:[(0,l.jsx)(i.Button,{variant:`outline`,size:`icon`,className:`h-8 w-8`,disabled:!g,onClick:b,title:u(`detail.firstRecord`),children:(0,l.jsx)(a.ChevronsLeft,{className:`h-4 w-4`})}),(0,l.jsx)(i.Button,{variant:`outline`,size:`icon`,className:`h-8 w-8`,disabled:!_,onClick:x,title:u(`detail.previousRecordKey`),children:(0,l.jsx)(a.ChevronLeft,{className:`h-4 w-4`})}),(0,l.jsx)(`span`,{className:`text-xs text-muted-foreground whitespace-nowrap px-1.5 tabular-nums`,children:t>0?u(`detail.recordOf`,{current:e+1,total:t}):u(`detail.noRecords`)}),(0,l.jsx)(i.Button,{variant:`outline`,size:`icon`,className:`h-8 w-8`,disabled:!v,onClick:S,title:u(`detail.nextRecordKey`),children:(0,l.jsx)(a.ChevronRight,{className:`h-4 w-4`})}),(0,l.jsx)(i.Button,{variant:`outline`,size:`icon`,className:`h-8 w-8`,disabled:!y,onClick:C,title:u(`detail.lastRecord`),children:(0,l.jsx)(a.ChevronsRight,{className:`h-4 w-4`})}),s&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(i.Button,{variant:p?`secondary`:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:T,title:u(`detail.searchWhileNavigating`),children:(0,l.jsx)(a.Search,{className:`h-4 w-4`})}),p&&(0,l.jsx)(`div`,{className:`relative`,children:(0,l.jsx)(i.Input,{ref:h,type:`text`,placeholder:u(`detail.searchRecords`),value:d,onChange:w,className:`h-8 w-48 text-sm`})})]})]})},Jt=28,Yt=[`fill-primary stroke-primary`,`fill-blue-500 stroke-blue-500`,`fill-emerald-500 stroke-emerald-500`,`fill-amber-500 stroke-amber-500`],Xt=[`fill-primary-foreground`,`fill-white`,`fill-white`,`fill-white`];function Zt(e,t,n,r,i){let a=[],o=[],s=new Set,c=r/2,l=i/2;a.push({id:e.id,label:e.label,type:e.type,x:c,y:l,level:0}),s.add(e.id);let u=Math.min(r,i)*.32,d=t.filter(e=>!s.has(e.id));if(d.forEach((t,n)=>{let r=2*Math.PI*n/d.length-Math.PI/2,i=c+u*Math.cos(r),f=l+u*Math.sin(r);a.push({id:t.id,label:t.label,type:t.type,x:i,y:f,level:1}),o.push({fromId:e.id,toId:t.id,fromX:c,fromY:l,toX:i,toY:f}),s.add(t.id)}),n>=2){let e=Math.min(r,i)*.46,t=[];d.forEach(e=>{let n=a.find(t=>t.id===e.id);n&&(e.relatedRecords||[]).filter(e=>!s.has(e.id)).forEach(r=>{t.push({node:r,parentX:n.x,parentY:n.y,parentId:e.id}),s.add(r.id)})}),t.forEach((n,r)=>{let i=2*Math.PI*r/Math.max(t.length,1)-Math.PI/2,s=c+e*Math.cos(i),u=l+e*Math.sin(i);a.push({id:n.node.id,label:n.node.label,type:n.node.type,x:s,y:u,level:2}),o.push({fromId:n.parentId,toId:n.node.id,fromX:n.parentX,fromY:n.parentY,toX:s,toY:u})})}return{nodes:a,edges:o}}function Qt(e,t=6){return e.length<=t?e:e.slice(0,t-1)+`…`}var $t=({record:e,relatedRecords:t,levels:n=1,onNodeClick:o,className:s})=>{let c=r.useRef(null),[u,d]=r.useState({width:500,height:400}),[f,p]=r.useState(null);r.useEffect(()=>{let e=c.current;if(!e)return;let t=e.parentElement;if(!t)return;let n=new ResizeObserver(e=>{for(let t of e){let{width:e}=t.contentRect;e>0&&d({width:e,height:Math.max(300,e*.7)})}});return n.observe(t),()=>n.disconnect()},[]);let{nodes:m,edges:h}=r.useMemo(()=>Zt(e,t,n,u.width,u.height),[e,t,n,u]);return(0,l.jsxs)(i.Card,{className:(0,i.cn)(`overflow-hidden`,s),children:[(0,l.jsx)(i.CardHeader,{className:`pb-2`,children:(0,l.jsxs)(i.CardTitle,{className:`flex items-center gap-2 text-base`,children:[(0,l.jsx)(a.Network,{className:`h-4 w-4`}),`Relationships`,(0,l.jsxs)(`span`,{className:`text-sm font-normal text-muted-foreground`,children:[`(`,t.length,` related)`]})]})}),(0,l.jsx)(i.CardContent,{className:`p-0`,children:(0,l.jsxs)(`svg`,{ref:c,width:`100%`,height:u.height,viewBox:`0 0 ${u.width} ${u.height}`,className:`select-none`,children:[h.map((e,t)=>(0,l.jsx)(`line`,{x1:e.fromX,y1:e.fromY,x2:e.toX,y2:e.toY,className:`stroke-border`,strokeWidth:1.5,strokeOpacity:.5},`edge-${t}`)),m.map(e=>{let t=f===e.id,n=Yt[Math.min(e.level,Yt.length-1)],r=Xt[Math.min(e.level,Xt.length-1)],a=e.level===0?34:Jt;return(0,l.jsxs)(`g`,{className:(0,i.cn)(`cursor-pointer transition-transform`,o&&`hover:opacity-80`),onClick:()=>o?.(e.id),onMouseEnter:()=>p(e.id),onMouseLeave:()=>p(null),children:[(0,l.jsx)(`circle`,{cx:e.x,cy:e.y,r:t?a+3:a,className:n,fillOpacity:e.level===0?1:.85,strokeWidth:2,strokeOpacity:.3}),(0,l.jsx)(`text`,{x:e.x,y:e.y,textAnchor:`middle`,dominantBaseline:`central`,className:(0,i.cn)(`text-[10px] font-medium pointer-events-none`,r),children:Qt(e.label)}),e.type&&(0,l.jsx)(`text`,{x:e.x,y:e.y+a+12,textAnchor:`middle`,className:`fill-muted-foreground text-[9px] pointer-events-none`,children:e.type}),t&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`rect`,{x:e.x-50,y:e.y-a-28,width:100,height:20,rx:4,className:`fill-popover stroke-border`,strokeWidth:1}),(0,l.jsx)(`text`,{x:e.x,y:e.y-a-16,textAnchor:`middle`,dominantBaseline:`central`,className:`fill-popover-foreground text-[10px] pointer-events-none`,children:e.label})]})]},e.id)})]})})]})};function en(e){try{let t=new Date(e),n=new Date().getTime()-t.getTime(),r=Math.floor(n/6e4);if(r<1)return`just now`;if(r<60)return`${r}m ago`;let i=Math.floor(r/60);return i<24?`${i}h ago`:t.toLocaleString()}catch{return e}}var tn=({recordId:e,revisions:t,onRestore:n,className:o})=>{let[s,c]=r.useState(null),[u,d]=r.useState(!1),[f,p]=r.useState(!1),m=r.useMemo(()=>t.find(e=>e.id===s)??null,[t,s]),h=r.useCallback(async()=>{if(!(!m||!n)){if(!u){d(!0);return}p(!0);try{let e=m.snapshot??{};await n(m.id,e),d(!1),c(null)}finally{p(!1)}}},[m,n,u]),g=r.useCallback(()=>{d(!1)},[]);return(0,l.jsxs)(i.Card,{className:(0,i.cn)(``,o),children:[(0,l.jsx)(i.CardHeader,{className:`pb-3`,children:(0,l.jsxs)(i.CardTitle,{className:`flex items-center gap-2 text-base`,children:[(0,l.jsx)(a.History,{className:`h-4 w-4`}),`Revision History`,(0,l.jsxs)(`span`,{className:`text-sm font-normal text-muted-foreground`,children:[`(`,t.length,`)`]})]})}),(0,l.jsx)(i.CardContent,{children:t.length===0?(0,l.jsx)(`p`,{className:`text-sm text-muted-foreground text-center py-4`,children:`No revisions recorded`}):(0,l.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-4`,children:[(0,l.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,l.jsxs)(`div`,{className:`relative`,children:[(0,l.jsx)(`div`,{className:`absolute left-3 top-2 bottom-2 w-px bg-border`}),(0,l.jsx)(`div`,{className:`space-y-1`,children:t.map(e=>{let t=e.id===s;return(0,l.jsxs)(`button`,{type:`button`,className:(0,i.cn)(`w-full text-left flex items-start gap-3 py-2 px-2 rounded-md transition-colors relative`,t?`bg-accent`:`hover:bg-accent/50`),onClick:()=>{c(e.id),d(!1)},children:[(0,l.jsx)(`div`,{className:(0,i.cn)(`shrink-0 h-6 w-6 rounded-full border-2 flex items-center justify-center z-10 mt-0.5`,t?`border-primary bg-primary`:`border-border bg-background`),children:t&&(0,l.jsx)(a.ChevronRight,{className:`h-3 w-3 text-primary-foreground`})}),(0,l.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(`span`,{className:`text-sm font-medium`,children:e.user}),(0,l.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:en(e.timestamp)})]}),(0,l.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:[e.changes.length,` field`,e.changes.length===1?``:`s`,` `,`changed`]})]})]},e.id)})})]})}),m&&(0,l.jsxs)(`div`,{className:`lg:w-80 border rounded-md p-3 space-y-3`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium`,children:[(0,l.jsx)(a.Eye,{className:`h-4 w-4 text-muted-foreground`}),`Revision Preview`]}),(0,l.jsx)(`div`,{className:`space-y-2`,children:m.changes.map((e,t)=>(0,l.jsxs)(`div`,{className:`text-xs`,children:[(0,l.jsx)(`span`,{className:`font-medium text-muted-foreground`,children:e.field}),(0,l.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-0.5`,children:[(0,l.jsx)(`span`,{className:`line-through text-red-600 dark:text-red-400 truncate max-w-[120px]`,children:e.oldValue==null?`(empty)`:String(e.oldValue)}),(0,l.jsx)(a.ChevronRight,{className:`h-3 w-3 text-muted-foreground shrink-0`}),(0,l.jsx)(`span`,{className:`text-green-600 dark:text-green-400 truncate max-w-[120px]`,children:e.newValue==null?`(empty)`:String(e.newValue)})]})]},t))}),m.snapshot&&(0,l.jsxs)(`div`,{className:`border-t pt-2 space-y-1`,children:[(0,l.jsx)(`p`,{className:`text-xs font-medium text-muted-foreground`,children:`Record state at this point`}),(0,l.jsx)(`div`,{className:`max-h-40 overflow-y-auto space-y-1`,children:Object.entries(m.snapshot).map(([e,t])=>(0,l.jsxs)(`div`,{className:`flex justify-between text-xs gap-2`,children:[(0,l.jsx)(`span`,{className:`text-muted-foreground truncate`,children:e}),(0,l.jsx)(`span`,{className:`font-mono truncate max-w-[140px]`,children:t==null?`–`:String(t)})]},e))})]}),n&&(0,l.jsx)(`div`,{className:`pt-1 space-y-2`,children:u?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(`p`,{className:`text-xs text-amber-600 dark:text-amber-400`,children:[`This will restore the record to its state at`,` `,en(m.timestamp),`. Continue?`]}),(0,l.jsxs)(`div`,{className:`flex gap-2`,children:[(0,l.jsxs)(i.Button,{variant:`destructive`,size:`sm`,className:`gap-1.5 flex-1`,onClick:h,disabled:f,children:[(0,l.jsx)(a.RotateCcw,{className:`h-3.5 w-3.5`}),f?`Restoring…`:`Confirm Restore`]}),(0,l.jsx)(i.Button,{variant:`ghost`,size:`sm`,onClick:g,disabled:f,children:`Cancel`})]})]}):(0,l.jsxs)(i.Button,{variant:`outline`,size:`sm`,className:`w-full gap-1.5`,onClick:h,children:[(0,l.jsx)(a.RotateCcw,{className:`h-3.5 w-3.5`}),`Restore to this point`]})})]})]})})]})},nn=({onSubmit:e,placeholder:t=`Leave a comment…`,disabled:n=!1,className:o})=>{let[s,c]=r.useState(``),[u,d]=r.useState(!1),f=r.useCallback(async()=>{let t=s.trim();if(t){d(!0);try{await e(t),c(``)}finally{d(!1)}}},[s,e]),p=r.useCallback(e=>{e.key===`Enter`&&(e.ctrlKey||e.metaKey)&&(e.preventDefault(),f())},[f]);return(0,l.jsxs)(`div`,{className:(0,i.cn)(`flex gap-2`,o),children:[(0,l.jsx)(`textarea`,{className:`flex-1 min-h-[60px] rounded-md border border-input bg-background px-3 py-2 text-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring resize-none`,placeholder:t,value:s,onChange:e=>c(e.target.value),onKeyDown:p,disabled:n||u}),(0,l.jsx)(i.Button,{size:`icon`,variant:`default`,onClick:f,disabled:!s.trim()||u||n,className:`shrink-0 self-end`,"aria-label":`Submit comment`,children:(0,l.jsx)(a.Send,{className:`h-4 w-4`})})]})},rn=({query:e,suggestions:t,onSelect:n,visible:a=!0,activeIndex:o=0,className:s})=>{let c=r.useMemo(()=>{if(!e)return t;let n=e.toLowerCase();return t.filter(e=>e.name.toLowerCase().includes(n)||e.id.toLowerCase().includes(n))},[e,t]);return!a||c.length===0?null:(0,l.jsx)(`div`,{className:(0,i.cn)(`bg-popover border rounded-md shadow-md z-50 max-h-48 overflow-y-auto w-56`,s),role:`listbox`,"aria-label":`Mention suggestions`,children:c.map((e,t)=>(0,l.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":t===o,className:(0,i.cn)(`w-full text-left px-3 py-1.5 text-sm flex items-center gap-2 hover:bg-accent transition-colors`,t===o&&`bg-accent`),onMouseDown:t=>{t.preventDefault(),n(e)},children:[e.avatarUrl?(0,l.jsx)(`img`,{src:e.avatarUrl,alt:e.name,className:`h-5 w-5 rounded-full object-cover`}):(0,l.jsx)(`div`,{className:`h-5 w-5 rounded-full bg-muted flex items-center justify-center text-[10px] font-medium`,children:e.name.charAt(0).toUpperCase()}),(0,l.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,l.jsx)(`span`,{className:`truncate`,children:e.name}),e.type!==`user`&&(0,l.jsxs)(`span`,{className:`ml-1 text-xs text-muted-foreground capitalize`,children:[`(`,e.type,`)`]})]})]},e.id))})};function an(e,t,n){return{type:e.type,id:e.id,name:e.name,offset:t,length:n}}function on(e,t){if(!e||!t.length)return[];let n=[...t].sort((e,t)=>t.label.length-e.label.length),r=e,i=new Set;for(let e of n){if(!e.label)continue;let t=e.label.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),n=RegExp(`@${t}(?![\\p{L}\\p{N}_])`,`gu`);n.test(r)&&(i.add(e.id),r=r.replace(n,e=>` `.repeat(e.length)))}return[...i]}function sn(e){return e==null?[]:Array.isArray(e)?e.filter(e=>e!=null):[e]}function cn(e,t){if(!e||!t)return null;let n=e.fields?.[t]?.options;return!Array.isArray(n)||n.length===0?null:n.map(e=>({value:e.value,label:e.label}))}function ln(e){if(!e)return null;let t=e.fields||{};for(let n of[e.primaryField,e.nameField,e.displayNameField])if(typeof n==`string`&&n.length>0&&n in t)return n;for(let e of[`name`,`full_name`,`title`,`subject`,`display_name`])if(e in t)return e;return null}function un(e,t,n=4){if(!e)return[];let r=Array.isArray(e.highlightFields)&&e.highlightFields.length>0?e.highlightFields:null;if(r){let t=ln(e);return r.filter(e=>typeof e==`string`&&e.length>0&&e!==t).slice(0,n)}let i=new Set([`id`,`_id`,`created_at`,`updated_at`,`deleted_at`,`created_by`,`updated_by`,`deleted_by`,`organization_id`,`workspace_id`,`tenant_id`,`org_id`]);t&&i.add(t),e.primaryField&&i.add(e.primaryField),e.nameField&&i.add(e.nameField),e.displayNameField&&i.add(e.displayNameField);for(let t of[`name`,`full_name`,`title`,`subject`,`display_name`])t in(e.fields||{})&&i.add(t);let a=[`owner`,`owner_id`,`amount`,`rating`,`source`,`priority`,`industry`,`phone`,`email`,`close_date`,`due_date`,`start_date`,`expected_close_date`,`account`,`account_id`,`contact`,`contact_id`],o=new Set([`currency`,`number`,`integer`,`decimal`,`percent`,`date`,`datetime`,`time`,`reference`,`lookup`,`user`,`owner`,`select`,`enum`,`multiselect`,`status`,`email`,`phone`,`url`,`text`,`string`]),s=[],c=e.fields||{};for(let e of a)if(e in c&&!i.has(e)&&s.push(e),s.length>=n)return s;for(let e of Object.keys(c)){if(s.includes(e)||i.has(e))continue;let t=c[e]?.type;if(!(t&&!o.has(t))&&(s.push(e),s.length>=n))break}return s}function dn(e,t={}){return{type:`page:header`,recordChrome:t.recordChrome!==!1,...Array.isArray(t.actions)&&t.actions.length>0?{actions:t.actions}:{}}}function fn(e,t){return!Array.isArray(t)||t.length===0?null:{type:`record:quick_actions`,actions:t,location:`record_header`}}function pn(e,t={}){let n=t.statusField??(0,d.detectStatusField)(e),r=t.stages??(n?cn(e,n):null),i=t.highlightFields??un(e,n),a=[];return!t.hideHighlights&&i.length>0&&a.push({type:`record:highlights`,fields:i}),!t.hidePath&&n&&r&&r.length>0&&a.push({type:`record:path`,statusField:n,stages:r}),a}function mn(e){if(!e)return null;let t=(0,f.deriveFieldGroupLayout)(e);if(!t)return null;let n=e.fields||{},r=e=>{let t=n[e]||{};return{name:e,label:t.label||e,type:t.type||`text`,...t.options?{options:t.options}:{},...t.reference_to||t.reference?{reference_to:t.reference_to||t.reference}:{},...t.reference_field?{reference_field:t.reference_field}:{},...t.currency?{currency:t.currency}:{},...t.currencyConfig?{currencyConfig:t.currencyConfig}:{}}},i=S(t.reduce((e,t)=>e+t.fields.length,0));return t.map(e=>({...e.key===void 0?{}:{name:e.key,title:e.label??e.key},...e.icon?{icon:e.icon}:{},...e.description?{description:e.description}:{},...e.collapse===`none`?{}:{collapsible:!0},...e.collapse===`collapsed`?{defaultCollapsed:!0}:{},columns:i,fields:e.fields.map(r)}))}function hn(e,t){return Array.isArray(t)&&t.length>0?t:mn(e)??void 0}function gn(e,t,n){return{type:`record:details`,sections:hn(e,t),...n&&n.length>0?{hideFields:n}:{}}}function _n(e,t={}){let n=t.statusField??(0,d.detectStatusField)(e),r=t.highlightFields??un(e,n),i=[{label:`Details`,value:`details`,children:[gn(e,t.sections,r)]}];if(!t.hideRelatedTab&&Array.isArray(t.related)&&t.related.length>0){let e=e=>({type:`record:related_list`,title:e.title,objectName:e.objectName,relationshipField:e.relationshipField,...e.columns?{columns:e.columns}:{},...e.limit?{limit:e.limit}:{},...e.icon?{icon:e.icon}:{}}),n=t=>({label:t.title||t.objectName,value:`related:${t.objectName}`,...t.icon?{icon:t.icon}:{},children:[e(t)]});if(t.relatedLayout===`tabs`)for(let e of t.related)i.push(n(e));else if(t.relatedLayout===`stack`)i.push({label:`Related`,value:`related`,children:t.related.map(e)});else{let r=t.related.filter(e=>e.isPrimary),a=t.related.filter(e=>!e.isPrimary);for(let e of r)i.push(n(e));a.length>0&&i.push({label:`Related`,value:`related`,children:a.map(e)})}}return t.approvals&&i.push({label:`Approvals`,value:`approvals`,...t.approvals.count==null?{}:{count:t.approvals.count},children:[{type:`record:approvals`,...t.approvals.node||{}}]}),e?.enable?.files===!0&&!t.hideAttachments&&i.push({label:`Attachments`,value:`attachments`,children:[yn()]}),t.showActivity&&i.push({label:`Activity`,value:`activity`,children:[{type:`record:activity`}]}),t.history&&i.push({label:`History`,value:`history`,children:[{type:`record:history`,entries:t.history.entries,loading:t.history.loading,emptyText:t.history.emptyText,unknownUserText:t.history.unknownUserText}]}),{type:`page:tabs`,items:i}}function vn(){return{type:`record:discussion`}}function yn(){return{type:`record:attachments`}}function bn(e,t={}){let n=t.slots||{},r=[];`header`in n&&n.header!==void 0?r.push(...sn(n.header)):r.push(dn(e,{recordChrome:t.recordChrome,actions:t.headerActions})),`actions`in n&&n.actions!==void 0&&r.push(...sn(n.actions)),`alerts`in n&&n.alerts!==void 0&&r.push(...sn(n.alerts)),`highlights`in n&&n.highlights!==void 0?r.push(...sn(n.highlights)):r.push(...pn(e,{highlightFields:t.highlightFields,statusField:t.statusField,stages:t.stages,hideHighlights:t.hideHighlights,hidePath:t.hidePath}));let i=t.showReferenceRail===!0&&!t.hideReferenceRail&&Array.isArray(t.related)&&t.related.length>=2,a=t.hideRelatedTab??i;if(`tabs`in n&&n.tabs!==void 0)r.push(...sn(n.tabs));else if(`details`in n&&n.details!==void 0){let i=sn(n.details),o=_n(e,{sections:t.sections,related:t.related,showActivity:t.showActivity,history:t.history,approvals:t.approvals,highlightFields:t.highlightFields,statusField:t.statusField,hideRelatedTab:a,relatedLayout:t.relatedLayout,hideAttachments:t.hideAttachments});Array.isArray(o.items)&&o.items.length>0&&(o.items[0]={...o.items[0],children:i}),r.push(o)}else r.push(_n(e,{sections:t.sections,related:t.related,showActivity:t.showActivity,history:t.history,approvals:t.approvals,highlightFields:t.highlightFields,statusField:t.statusField,hideRelatedTab:a,relatedLayout:t.relatedLayout,hideAttachments:t.hideAttachments}));`discussion`in n&&n.discussion!==void 0?r.push(...sn(n.discussion)):t.hideDiscussion||r.push(vn());let o=[{name:`main`,width:`full`,components:r}],s=sn(n.rightRail);if(i||s.length>0){let e=[];i&&e.push({type:`record:reference_rail`,entries:t.related.map(e=>({objectName:e.objectName,relationshipField:e.relationshipField,title:e.title,icon:e.icon,displayField:e.displayField,limit:3}))}),s.length>0&&e.push(...s),o.push({name:`aside`,width:`small`,className:`hidden xl:flex flex-col gap-4`,components:e})}return{type:`record`,pageType:`record`,object:e?.name,template:`full-width`,regions:o}}t.ComponentRegistry.register(`detail-view`,Te,{namespace:`plugin-detail`,label:`Detail View`,category:`Views`,icon:`FileText`,inputs:[{name:`title`,type:`string`,label:`Title`},{name:`objectName`,type:`string`,label:`Object Name`},{name:`resourceId`,type:`string`,label:`Resource ID`},{name:`api`,type:`string`,label:`API Endpoint`},{name:`data`,type:`object`,label:`Data`},{name:`layout`,type:`enum`,label:`Layout Mode`,enum:[`vertical`,`horizontal`,`grid`]},{name:`columns`,type:`number`,label:`Grid Columns`},{name:`sections`,type:`array`,label:`Sections`},{name:`fields`,type:`array`,label:`Fields`},{name:`tabs`,type:`array`,label:`Tabs`},{name:`related`,type:`array`,label:`Related Lists`},{name:`actions`,type:`array`,label:`Actions`},{name:`showBack`,type:`boolean`,label:`Show Back Button`,defaultValue:!0},{name:`backUrl`,type:`string`,label:`Back URL`},{name:`showEdit`,type:`boolean`,label:`Show Edit Button`,defaultValue:!1},{name:`editUrl`,type:`string`,label:`Edit URL`},{name:`showDelete`,type:`boolean`,label:`Show Delete Button`,defaultValue:!1},{name:`deleteConfirmation`,type:`string`,label:`Delete Confirmation Message`},{name:`loading`,type:`boolean`,label:`Show Loading State`},{name:`header`,type:`object`,label:`Custom Header`},{name:`footer`,type:`object`,label:`Custom Footer`}],defaultProps:{title:`Detail View`,showBack:!0,showEdit:!1,showDelete:!1,sections:[],fields:[],tabs:[],related:[]}}),t.ComponentRegistry.register(`detail-section`,R,{namespace:`plugin-detail`,label:`Detail Section`,category:`Detail Components`,inputs:[{name:`title`,type:`string`,label:`Title`},{name:`description`,type:`string`,label:`Description`},{name:`fields`,type:`array`,label:`Fields`,required:!0},{name:`collapsible`,type:`boolean`,label:`Collapsible`,defaultValue:!1},{name:`defaultCollapsed`,type:`boolean`,label:`Default Collapsed`,defaultValue:!1},{name:`columns`,type:`number`,label:`Columns`,defaultValue:2},{name:`showBorder`,type:`boolean`,label:`Show Border`,defaultValue:!0},{name:`headerColor`,type:`string`,label:`Header Color`}]}),t.ComponentRegistry.register(`related-list`,B,{namespace:`plugin-detail`,label:`Related List`,category:`Detail Components`,inputs:[{name:`title`,type:`string`,label:`Title`,required:!0},{name:`type`,type:`enum`,label:`Type`,enum:[{label:`List`,value:`list`},{label:`Grid`,value:`grid`},{label:`Table`,value:`table`}],defaultValue:`table`},{name:`api`,type:`string`,label:`API Endpoint`},{name:`data`,type:`array`,label:`Data`},{name:`columns`,type:`array`,label:`Columns`}]}),t.ComponentRegistry.register(`detail`,Te,{namespace:`view`,category:`view`,label:`Detail`,icon:`FileText`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`recordId`,type:`string`,label:`Record ID`},{name:`fields`,type:`array`,label:`Fields`}]}),t.ComponentRegistry.register(`details`,De,{namespace:`record`,skipFallback:!0,category:`record`,label:`Record Details`,icon:`FileText`,inputs:[{name:`columns`,type:`enum`,label:`Columns`,enum:[`1`,`2`,`3`,`4`],defaultValue:`2`,description:`Number of columns for field layout (1-4)`},{name:`layout`,type:`enum`,label:`Layout`,enum:[`auto`,`custom`],defaultValue:`auto`,description:`auto uses the object highlightFields; custom uses explicit sections`},{name:`sections`,type:`array`,label:`Sections`,description:`Section IDs to show (required when layout is "custom")`},{name:`fields`,type:`array`,label:`Fields`,description:`Explicit field list (overrides highlightFields)`}]}),t.ComponentRegistry.register(`related_list`,Me,{namespace:`record`,skipFallback:!0,category:`record`,label:`Related List`,icon:`List`,inputs:[{name:`objectName`,type:`string`,label:`Related Object`,required:!0,description:`Related object name (e.g. "task")`},{name:`relationshipField`,type:`string`,label:`Relationship Field`,required:!0,description:`Field on the related object pointing back to this record`},{name:`columns`,type:`array`,label:`Columns`,required:!0,description:`Fields to display in the related list`},{name:`sort`,type:`array`,label:`Sort`},{name:`limit`,type:`number`,label:`Limit`,defaultValue:5,description:`Records to display initially`},{name:`filter`,type:`array`,label:`Filter`,description:`Additional filter criteria`},{name:`title`,type:`string`,label:`Title`},{name:`showViewAll`,type:`boolean`,label:`Show "View All"`,defaultValue:!0},{name:`actions`,type:`array`,label:`Actions`,description:`Action IDs available for related records`}]}),t.ComponentRegistry.register(`highlights`,Pe,{namespace:`record`,skipFallback:!0,category:`record`,label:`Highlights Panel`,icon:`Star`,inputs:[{name:`fields`,type:`array`,label:`Fields`,required:!0,description:`Key fields to highlight (1-7), bare names or {name,label?,icon?,type?}`},{name:`layout`,type:`enum`,label:`Layout`,enum:[`horizontal`,`vertical`],defaultValue:`horizontal`,description:`Layout orientation for highlight fields`}]}),t.ComponentRegistry.register(`activity`,ut,{namespace:`record`,skipFallback:!0,category:`record`,label:`Activity Timeline`,icon:`Activity`,inputs:[{name:`types`,type:`array`,label:`Activity Types`,description:`Allow-list of feed item types to show (comment, field_change, task, event, email, call, note, file, record_create, record_delete, approval, sharing, system). Omit for all; unrecognised entries are ignored.`},{name:`filterMode`,type:`enum`,label:`Filter Mode`,enum:[`all`,`comments_only`,`changes_only`,`tasks_only`],defaultValue:`all`,description:`Filter the timeline dropdown starts on. The user can still change it; an unrecognised value falls back to "all".`},{name:`showFilterToggle`,type:`boolean`,label:`Show Filter Toggle`,defaultValue:!0,description:`Expose the activity-type filter dropdown in the panel header`},{name:`limit`,type:`number`,label:`Limit`,defaultValue:20,description:`Items per page. Also caps the scoped sys_activity read; "Load more" grows the window by this much.`},{name:`showCompleted`,type:`boolean`,label:`Show Completed`,defaultValue:!1,description:`Include completed activities (sys_activity type "completed", which surfaces as a task item). Off by default.`},{name:`unifiedTimeline`,type:`boolean`,label:`Unified Timeline`,defaultValue:!0,description:`Mix field changes and comments in one timeline (Airtable style). Off keeps the panel a discussion stream — field changes stay in record:history.`},{name:`showCommentInput`,type:`boolean`,label:`Show Comment Input`,defaultValue:!0,description:`Show the composer. Requires a host discussion context to persist the comment (record detail pages provide one); without it the feed is read-only.`},{name:`enableMentions`,type:`boolean`,label:`Enable @mentions`,defaultValue:!0,description:`Offer @-mention autocomplete in the composer, from the host discussion context's user list. Off withholds the suggestions.`},{name:`enableReactions`,type:`boolean`,label:`Enable Reactions`,defaultValue:!1,description:`Show emoji reactions on feed items. Toggling one requires a host discussion context; without it existing reactions still render, read-only.`},{name:`enableThreading`,type:`boolean`,label:`Enable Threaded Replies`,defaultValue:!1,description:`Group replies under their parent comment. Posting a reply requires a host discussion context.`},{name:`showSubscriptionToggle`,type:`boolean`,label:`Show Subscribe Toggle`,description:`NOT IMPLEMENTED — no record-subscription backend exists yet, so this renders nothing whatever it is set to. Declared for spec parity only (objectui#3165).`}]});var xn=[{name:`position`,type:`enum`,label:`Position`,enum:[`bottom`,`right`,`left`],defaultValue:`bottom`,description:`Where the panel docks relative to the record body`},{name:`width`,type:`string`,label:`Width`,description:`Panel width as a CSS value (side positions only)`},{name:`collapsible`,type:`boolean`,label:`Collapsible`,defaultValue:!1},{name:`defaultCollapsed`,type:`boolean`,label:`Start Collapsed`},{name:`feed`,type:`object`,label:`Feed Options`,description:`Activity-feed config nested inside the panel — same shape as record:activity`}];t.ComponentRegistry.register(`chatter`,pt,{namespace:`record`,skipFallback:!0,category:`record`,label:`Chatter Feed`,icon:`MessageSquare`,inputs:xn}),t.ComponentRegistry.register(`discussion`,pt,{namespace:`record`,skipFallback:!0,category:`record`,label:`Discussion`,icon:`MessageSquare`,inputs:xn}),t.ComponentRegistry.register(`path`,ht,{namespace:`record`,skipFallback:!0,category:`record`,label:`Path / Stepper`,icon:`GitBranch`,inputs:[{name:`statusField`,type:`string`,label:`Status Field`,required:!0,description:`Field representing the current status/stage`},{name:`stages`,type:`array`,label:`Stages`,description:`Explicit stage definitions [{ value, label }] (else derived from field metadata)`}]}),t.ComponentRegistry.register(`quick_actions`,_t,{namespace:`record`,skipFallback:!0,category:`record`,label:`Quick Actions`,icon:`Zap`,inputs:[{name:`actionNames`,type:`array`,label:`Actions`,description:`Action names to expose, in order (else every action declared for the object at this location)`},{name:`requiredPermissions`,type:`array`,label:`Required Permissions`,description:`Hide the whole bar unless the user holds these permissions`},{name:`location`,type:`enum`,label:`Location`,enum:[...d.ACTION_LOCATIONS],defaultValue:`record_header`,description:`Which declared action location this bar renders`},{name:`align`,type:`enum`,label:`Align`,enum:[`start`,`center`,`end`],defaultValue:`end`},{name:`inline`,type:`boolean`,label:`Inline`,description:`Render in the flow instead of folding into the record header`},{name:`variant`,type:`string`,label:`Button Variant`,defaultValue:`default`,description:`Passed to the Button primitive; a per-action variant overrides it`},{name:`size`,type:`string`,label:`Button Size`,defaultValue:`sm`,description:`Passed to the Button primitive; a per-action size overrides it`}]}),t.ComponentRegistry.register(`history`,xt,{namespace:`record`,skipFallback:!0,category:`record`,label:`History Timeline`,icon:`Clock`,inputs:[{name:`limit`,type:`number`,label:`Limit`,defaultValue:50,description:`Maximum history entries to display`},{name:`emptyText`,type:`string`,label:`Empty Text`,description:`Copy shown when the record has no history`},{name:`unknownUserText`,type:`string`,label:`Unknown User Text`,description:`Copy substituted when an entry has no resolvable actor`}]}),t.ComponentRegistry.register(`reference_rail`,Tt,{namespace:`record`,skipFallback:!0,category:`record`,label:`Reference Rail`,icon:`PanelRight`,inputs:[{name:`hideEmpty`,type:`boolean`,label:`Hide When Empty`,defaultValue:!0,description:`Drop the rail entirely when no entries resolve`}]}),t.ComponentRegistry.register(`alert`,Ot,{namespace:`record`,skipFallback:!0,category:`record`,label:`Alert Banner`,icon:`AlertTriangle`,inputs:[{name:`severity`,type:`enum`,label:`Severity`,enum:[`info`,`warning`,`error`,`success`],defaultValue:`info`},{name:`title`,type:`string`,label:`Title`,description:`Accepts an inline translation map ({ en, "zh-CN", … })`},{name:`body`,type:`string`,label:`Body`,description:`Accepts an inline translation map ({ en, "zh-CN", … })`},{name:`visible`,type:`string`,label:`Visible When`,description:`Expression gating the banner against the current record`},{name:`icon`,type:`string`,label:`Icon`,description:`Lucide icon name; defaults to the severity icon`},{name:`action`,type:`object`,label:`Call to Action`,description:`{ actionName, label?, variant? } — the action the banner offers`},{name:`dismissible`,type:`boolean`,label:`Dismissible`},{name:`dismissKey`,type:`string`,label:`Dismiss Key`,description:`Stable key the dismissal is remembered under`}]}),t.ComponentRegistry.register(`permission-facet-link`,(0,n.withFieldCarrier)(A),{namespace:`field`,skipFallback:!0}),e.ActivityTimeline=le,e.CommentAttachment=Ke,e.CommentInput=nn,e.ConcurrentUpdateDialog=jt,e.DETAIL_DEFAULT_TRANSLATIONS=E,e.DetailSection=R,e.DetailTabs=ne,e.DetailView=Te,e.DiffView=Kt,e.FieldChangeItem=Fe,e.HeaderHighlight=H,e.HistoryTimeline=me,e.InlineCreateRelated=Vt,e.InlineEditSaveBar=Ft,e.InlineFieldInput=ee,e.MentionAutocomplete=rn,e.PointInTimeRestore=tn,e.ReactionPicker=Le,e.RecordActivityRenderer=ut,e.RecordActivityTimeline=Ze,e.RecordAlertRenderer=Ot,e.RecordChatterPanel=dt,e.RecordChatterRenderer=pt,e.RecordComments=W,e.RecordDetailDrawer=zt,e.RecordDetailsRenderer=De,e.RecordHighlightsRenderer=Pe,e.RecordHistoryRenderer=xt,e.RecordMetaFooter=xe,e.RecordNavigationEnhanced=qt,e.RecordPathRenderer=ht,e.RecordQuickActionsRenderer=_t,e.RecordReferenceRailRenderer=Tt,e.RecordRelatedListRenderer=Me,e.RelatedList=B,e.RelationshipGraph=$t,e.RichTextCommentInput=He,e.SectionGroup=V,e.SubscriptionToggle=Be,e.TEXTUAL_REF_FALLBACK_TYPES=M,e.ThreadedReplies=ze,e.__clearRecordEditableCache=Ce,e.applyAutoSpan=C,e.applyDetailAutoLayout=w,e.buildDefaultActions=fn,e.buildDefaultDetails=gn,e.buildDefaultDiscussion=vn,e.buildDefaultHeader=dn,e.buildDefaultHighlights=pn,e.buildDefaultPageSchema=bn,e.buildDefaultTabs=_n,e.createMentionFromSuggestion=an,e.createSafeTranslationHook=T,e.deriveFieldGroupDetailSections=mn,e.deriveHighlightFields=un,e.deriveRecordPageHref=Bt,e.deriveStages=cn,e.detectStatusField=d.detectStatusField,e.extractLookupId=I,e.extractMentions=on,e.inferDetailColumns=S,e.isConcurrentUpdateError=Mt,e.isWideFieldType=x,e.resolveDetailSections=hn,e.resolveTitleField=ln,e.useDetailTranslation=D,e.useRecordEditable=Se});