@object-ui/plugin-detail 11.5.0 → 13.1.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.
- package/CHANGELOG.md +56 -0
- package/dist/DetailSection.d.ts +5 -1
- package/dist/DetailSection.d.ts.map +1 -1
- package/dist/RelatedList.d.ts +8 -0
- package/dist/RelatedList.d.ts.map +1 -1
- package/dist/autoLayout.d.ts +5 -4
- package/dist/autoLayout.d.ts.map +1 -1
- package/dist/index.js +580 -557
- package/dist/index.umd.cjs +3 -3
- package/dist/renderers/record-related-list.d.ts.map +1 -1
- package/dist/synth/buildDefaultPageSchema.d.ts.map +1 -1
- package/package.json +16 -16
package/dist/index.umd.cjs
CHANGED
|
@@ -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("react/jsx-runtime"),require("@object-ui/permissions"),require("@object-ui/i18n"),require("react-router-dom"),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`,`react/jsx-runtime`,`@object-ui/permissions`,`@object-ui/i18n`,`react-router-dom`,`@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.jsxRuntime,e._object_ui_permissions,e._object_ui_i18n,e.react_router_dom,e._objectstack_spec_data))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var f=Object.create,p=Object.defineProperty,m=Object.getOwnPropertyDescriptor,h=Object.getOwnPropertyNames,g=Object.getPrototypeOf,_=Object.prototype.hasOwnProperty,v=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=h(t),a=0,o=i.length,s;a<o;a++)s=i[a],!_.call(e,s)&&s!==n&&p(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=m(t,s))||r.enumerable});return e};n=((e,t,n)=>(n=e==null?{}:f(g(e)),v(t||!e||!e.__esModule?p(n,`default`,{value:e,enumerable:!0}):n,e)))(n,1);var y=new Set([`textarea`,`markdown`,`html`,`grid`,`rich-text`,`field:textarea`,`field:markdown`,`field:html`,`field:grid`,`field:rich-text`]);function b(e){return y.has(e)}function x(e,t){let n;return n=e<=3?1:2,t!==void 0&&t<640?Math.min(n,1):n}function S(e,t){return t<=1?e:e.map(e=>e.span===void 0&&e.type&&b(e.type)?{...e,span:t}:e)}function C(e,t,n){if(t!==void 0)return{fields:S(e,t),columns:t};let r=x(e.length,n);return{fields:S(e,r),columns:r}}function w(e,t){return function(){try{let n=(0,a.useObjectTranslation)();return n.t(t)===t?{t:(t,n)=>{let r=e[t]||t;if(n)for(let[e,t]of Object.entries(n))r=r.replace(`{{${e}}}`,String(t));return r}}:{t:n.t}}catch{return{t:(t,n)=>{let r=e[t]||t;if(n)for(let[e,t]of Object.entries(n))r=r.replace(`{{${e}}}`,String(t));return r}}}}}var T={"detail.back":`Back`,"detail.edit":`Edit`,"detail.editInline":`Edit`,"detail.save":`Save`,"detail.saveChanges":`Save changes`,"detail.editFieldsInline":`Edit fields inline`,"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.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`},E=w(T,`detail.back`);function D(e,t){return!e||e<=1||t<=1?``:t===2?e>=2?`md:col-span-2`:``:e===2?`md:col-span-2`:e>=3?`md:col-span-2 lg:col-span-3`:``}var O=new Set([`formula`,`summary`,`rollup`,`auto_number`]);function k(e){if(e==null)return e;if(Array.isArray(e))return e.map(k);if(typeof e==`object`){let t=e;return t.id??t._id??t.value??``}return e}var A=({section:e,data:t,className:c,objectSchema:l,objectName:u,isEditing:d=!1,onFieldChange:f,dataSource:p,virtualScroll:m})=>{let[h,g]=n.useState(e.defaultCollapsed??!1),[_,v]=n.useState(null),[y,b]=n.useState(void 0),[x,S]=n.useState(!1),{t:w}=E(),{fieldLabel:T,translateOptions:A}=(0,a.useSafeFieldLabel)(),j=n.useCallback((e,t)=>{let n=t==null?``:String(t);navigator.clipboard.writeText(n).then(()=>{v(e),setTimeout(()=>v(null),2e3)})},[]),M=n.useCallback(e=>{let n=t?.[e.name]??e.value;return n==null||n===``},[t]),N=n.useMemo(()=>e.fields.filter(M).length,[e.fields,M]),P=(0,r.useIsMobile)(),F=P?3:4,I=P?.2:.25,L=e.fields.length-N,R=!e.hideEmpty&&!d&&e.fields.length>=F&&N/e.fields.length>=I&&L>0,z=!x&&(e.hideEmpty||R)?e.fields.filter(e=>!M(e)):e.fields;if(z.length===0&&N===e.fields.length)return null;let{fields:B,columns:V}=C(z,e.columns),H=e=>{let n=t?.[e.name]??e.value;if(e.render)return(0,s.jsx)(a.SchemaRenderer,{schema:e.render,data:{...t,value:n}});let c=D(e.span,V),m=l?.fields?.[e.name],h={...e};if(m){!e.type&&m.type&&(h.type=m.type),m.options&&!h.options&&(h.options=m.options),m.currency&&!h.currency&&(h.currency=m.currency),m.precision!==void 0&&h.precision===void 0&&(h.precision=m.precision),m.scale!==void 0&&h.scale===void 0&&(h.scale=m.scale),m.format&&!h.format&&(h.format=m.format);let t=m.reference_to||m.reference;t&&!h.reference_to&&(h.reference_to=t),m.reference_field&&!h.reference_field&&(h.reference_field=m.reference_field),m.dueLike!==void 0&&h.dueLike===void 0&&(h.dueLike=m.dueLike)}u&&Array.isArray(h.options)&&h.options.length>0&&(h.options=A(u,e.name,h.options));let g=(()=>{if(n==null||n===``)return(0,s.jsx)(`span`,{className:`text-muted-foreground/60 text-sm select-none`,"aria-label":w(`detail.noValue`,{defaultValue:`No value`}),title:w(`detail.noValue`,{defaultValue:`No value`}),children:`—`});let t=(0,o.resolveCellRendererType)(h)||e.type;if(t){let e=(0,o.getCellRenderer)(t);if(e)return(0,s.jsx)(e,{value:n,field:h})}return String(n)})(),v=n!=null&&n!==``,y=_===e.name,b=T(u||``,e.name,e.label||e.name);return P&&!(d&&!e.readonly)?(0,s.jsxs)(`div`,{className:(0,r.cn)(`flex items-baseline justify-between gap-4 py-2.5 min-h-[44px] group`,v&&`cursor-pointer active:bg-muted/40 transition-colors`),onClick:v?()=>j(e.name,n):void 0,onKeyDown:v?t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),j(e.name,n))}:void 0,role:v?`button`:void 0,tabIndex:v?0:void 0,children:[(0,s.jsx)(`span`,{className:`text-[15px] text-muted-foreground shrink-0`,children:b}),(0,s.jsx)(`span`,{className:`text-[15px] text-foreground text-right break-words min-w-0 leading-snug`,children:g})]},e.name):(0,s.jsxs)(`div`,{className:(0,r.cn)(`space-y-1.5 group`,c),children:[(0,s.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:T(u||``,e.name,e.label||e.name)}),d&&!e.readonly?(0,s.jsx)(`div`,{className:`min-h-[44px] sm:min-h-0`,children:(()=>{let t=h.type||e.type;if(t===`select`&&Array.isArray(h.options)&&h.options.length>0)return(0,s.jsx)(o.SelectField,{field:h,value:n==null?``:String(n),onChange:t=>f?.(e.name,t)});if(t===`boolean`)return(0,s.jsx)(o.BooleanField,{field:h,value:!!n,onChange:t=>f?.(e.name,t)});let r=t===`user`||t===`owner`,i=t===`lookup`||t===`master_detail`||t===`tree`||!!h.reference_to&&!O.has(t);if(r||i)return(0,s.jsx)(r?o.UserField:o.LookupField,{field:h,value:k(n),onChange:t=>f?.(e.name,t),dataSource:p});let a=t===`date`||t===`datetime`;return(0,s.jsx)(`input`,{type:t===`number`?`number`:a?`date`:`text`,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:n==null?``:a?(()=>{let e=String(n);if(/^\d{4}-\d{2}-\d{2}/.test(e))return e.slice(0,10);let t=new Date(e);return isNaN(t.getTime())?``:t.toLocaleDateString(`en-CA`)})():String(typeof n==`object`?(0,o.coerceToSafeValue)(n)??``:n),onChange:t=>{let n=t.target.value;if(a&&n){let t=new Date(n+`T00:00:00`).toISOString();f?.(e.name,t)}else f?.(e.name,n)}})})()}):(0,s.jsxs)(`div`,{className:(0,r.cn)(`flex items-start justify-between gap-2 min-h-[44px] sm:min-h-0 rounded-md`,v&&`cursor-pointer active:bg-muted/60 transition-colors`),onClick:v?()=>j(e.name,n):void 0,onKeyDown:v?t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),j(e.name,n))}:void 0,role:v?`button`:void 0,tabIndex:v?0:void 0,children:[(0,s.jsx)(`div`,{className:`text-sm flex-1 break-words py-1`,children:g}),v&&(0,s.jsx)(r.TooltipProvider,{children:(0,s.jsxs)(r.Tooltip,{children:[(0,s.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,s.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(),j(e.name,n)},children:y?(0,s.jsx)(i.Check,{className:`h-3 w-3 text-green-600`}):(0,s.jsx)(i.Copy,{className:`h-3 w-3`})})}),(0,s.jsx)(r.TooltipContent,{children:w(y?`detail.copied`:`detail.copyToClipboard`)})]})})]})]},e.name)},U=m?.enabled===!0,W=m?.batchSize??20;n.useEffect(()=>{if(!U){b(void 0);return}if(B.length<=W){b(void 0);return}b(W);let e=setTimeout(()=>b(void 0),100);return()=>clearTimeout(e)},[U,B.length,W]);let G=y===void 0?B:B.slice(0,y),ee=N>0&&(e.hideEmpty||R),K=(0,s.jsxs)(s.Fragment,{children:[P?(0,s.jsx)(`div`,{className:`flex flex-col divide-y divide-border/60`,children:G.map(H)}):(0,s.jsx)(`div`,{className:(0,r.cn)(`grid gap-3 sm:gap-4`,V===1?`grid-cols-1`:V===2?`grid-cols-1 md:grid-cols-2`:`grid-cols-1 md:grid-cols-2 lg:grid-cols-3`),children:G.map(H)}),ee&&(0,s.jsx)(`div`,{className:`mt-3 -ml-2`,children:(0,s.jsxs)(r.Button,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>S(e=>!e),className:`h-7 px-2 text-xs text-muted-foreground hover:text-foreground`,children:[x?(0,s.jsx)(i.EyeOff,{className:`h-3.5 w-3.5 mr-1.5`}):(0,s.jsx)(i.Eye,{className:`h-3.5 w-3.5 mr-1.5`}),x?w(`detail.hideEmptyFields`,{defaultValue:`Hide empty fields`}):w(`detail.showEmptyFields`,{count:N,defaultValue:`Show ${N} empty field${N===1?``:`s`}`})]})})]});return!e.title&&!e.collapsible&&e.showBorder===!1?(0,s.jsx)(`div`,{className:(0,r.cn)(c),children:K}):e.collapsible?(0,s.jsx)(r.Collapsible,{open:!h,onOpenChange:e=>g(!e),className:c,children:(0,s.jsxs)(r.Card,{children:[(0,s.jsx)(r.CollapsibleTrigger,{asChild:!0,children:(0,s.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,s.jsxs)(r.CardTitle,{className:`flex items-center justify-between text-base font-semibold tracking-tight`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.icon&&(0,s.jsx)(`span`,{className:`text-muted-foreground`,children:e.icon}),(0,s.jsx)(`span`,{children:e.title})]}),(0,s.jsx)(`div`,{className:`flex items-center gap-2`,children:h?(0,s.jsx)(i.ChevronRight,{className:`h-4 w-4 text-muted-foreground`}):(0,s.jsx)(i.ChevronDown,{className:`h-4 w-4 text-muted-foreground`})})]}),e.description&&!h&&(0,s.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:e.description})]})}),(0,s.jsx)(r.CollapsibleContent,{children:(0,s.jsx)(r.CardContent,{className:`pt-3 sm:pt-4 px-3 sm:px-6 pb-4 sm:pb-5`,children:K})})]})}):(0,s.jsxs)(r.Card,{className:(0,r.cn)(e.showBorder===!1?`border-none shadow-none`:``,c),children:[e.title&&(0,s.jsxs)(r.CardHeader,{className:(0,r.cn)(`py-3 px-4 sm:py-4 sm:px-6`,e.headerColor&&`bg-${e.headerColor}`),children:[(0,s.jsx)(r.CardTitle,{className:`flex items-center justify-between text-base font-semibold tracking-tight`,children:(0,s.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.icon&&(0,s.jsx)(`span`,{className:`text-muted-foreground`,children:e.icon}),(0,s.jsx)(`span`,{children:e.title})]})}),e.description&&(0,s.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:e.description})]}),(0,s.jsx)(r.CardContent,{className:`pt-3 sm:pt-4 px-3 sm:px-6 pb-4 sm:pb-5`,children:K})]})},j=({tabs:e,data:t,className:i})=>{let[o,c]=n.useState(e[0]?.key),l=e.filter(e=>typeof e.visible==`boolean`?e.visible:(e.visible,!0));return(0,s.jsxs)(r.Tabs,{value:o,onValueChange:c,className:i,children:[(0,s.jsx)(r.TabsList,{className:`w-full justify-start border-b rounded-none bg-transparent p-0`,children:l.map(e=>(0,s.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,s.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.icon&&(0,s.jsx)(`span`,{children:e.icon}),(0,s.jsx)(`span`,{children:e.label}),e.badge&&(0,s.jsx)(r.Badge,{variant:`secondary`,className:`ml-1`,children:e.badge})]})},e.key))}),l.map(e=>(0,s.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,s.jsx)(n.Suspense,{fallback:null,children:Array.isArray(e.content)?(0,s.jsx)(`div`,{className:`space-y-4`,children:e.content.map((e,n)=>(0,s.jsx)(a.SchemaRenderer,{schema:e,data:t},n))}):(0,s.jsx)(a.SchemaRenderer,{schema:e.content,data:t})})},e.key))]})};function M(e){return e&&i.icons[e.split(/[-_\s]/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``)]||i.Inbox}var N=({title:e,type:t,api:l,data:u,schema:d,columns:f,className:p,dataSource:m,objectName:h,onNew:g,onViewAll:_,onRowEdit:v,onRowDelete:y,onRowClick:b,rowActions:x,onRowAction:S,add:C,maxColumns:w=6,pageSize:T,sortable:D=!1,filterable:O=!1,collapsible:k=!1,defaultCollapsed:A=!1,referenceField:j,parentId:N,icon:P})=>{let F=u!==void 0,I=u??[],[L,R]=n.useState(I),[z,B]=n.useState(()=>!!l&&!F),[V,H]=n.useState(0),[U,W]=n.useState(null),[G,ee]=n.useState(`asc`),[K,te]=n.useState(``),[q,ne]=n.useState(null),[re,ie]=n.useState(A),[ae,oe]=n.useState(!1),[J,se]=n.useState(!1),[ce,le]=n.useState(null),[ue,de]=n.useState(0),[fe,pe]=n.useState({}),{t:Y}=E(),{fieldLabel:me}=(0,a.useSafeFieldLabel)();n.useEffect(()=>{F&&R(u??[])},[u,F]),n.useEffect(()=>{l&&m?.getObjectSchema&&m.getObjectSchema(l).then(ne).catch(e=>{console.warn(`[RelatedList] Failed to fetch schema for ${l}:`,e)})},[l,m]),n.useEffect(()=>{if(l&&!F){if(!(j&&N!=null&&N!==``)){l&&(N==null||N===``)&&!j&&console.warn(`[RelatedList] "${l}" has no referenceField/parentId — refusing to fetch all rows. Pass relationshipField + parentId to scope the query.`),R([]),B(!1);return}B(!0);let e={[j]:N};if(m&&typeof m.find==`function`)m.find(l,{$filter:e}).then(e=>{R(Array.isArray(e)?e:Array.isArray(e?.data)?e.data:[]),B(!1)}).catch(e=>{console.error(`Failed to fetch related data:`,e),B(!1)});else{let e=new URLSearchParams({[`filter[${j}]`]:String(N)}).toString();fetch(`${l}?${e}`).then(e=>e.json()).then(e=>{R(Array.isArray(e)?e:e?.data||[])}).catch(e=>{console.error(`Failed to fetch related data:`,e)}).finally(()=>B(!1))}}},[l,F,m,j,N,ue]),n.useEffect(()=>{if(!l||F)return;let e=e=>{let t=e.detail||{};t.objectName&&t.objectName!==l||de(e=>e+1)};return window.addEventListener(`objectui:related-changed`,e),()=>window.removeEventListener(`objectui:related-changed`,e)},[l,F]),n.useEffect(()=>{if(!m?.find||!q?.fields||!L.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 L){let t=e?.[n];t!=null&&(typeof t==`string`&&t?i.add(t):typeof t==`number`&&i.add(String(t)))}let a=fe[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})=>m.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||pe(t=>{let n={...t};for(let{fieldName:t,map:r}of e)n[t]={...n[t]||{},...r};return n})}),()=>{n=!0}},[m,q,L]);let he=n.useMemo(()=>{if(!K)return L;let e=K.toLowerCase();return L.filter(t=>Object.values(t).some(t=>t!=null&&String(t).toLowerCase().includes(e)))},[L,K]),ge=n.useMemo(()=>U?[...he].sort((e,t)=>{let n=e[U],r=t[U];if(n==null&&r==null)return 0;if(n==null)return 1;if(r==null)return-1;let i=String(n).localeCompare(String(r),void 0,{numeric:!0});return G===`asc`?i:-i}):he,[he,U,G]),X=T&&T>0?T:0,_e=X?Math.max(1,Math.ceil(ge.length/X)):1,ve=X?ge.slice(V*X,(V+1)*X):ge;n.useEffect(()=>{H(0)},[K,U,G]);let ye=n.useCallback(e=>{U===e?ee(e=>e===`asc`?`desc`:`asc`):(W(e),ee(`asc`))},[U]),[be,xe]=n.useState(null),Z=n.useCallback(e=>{xe(e)},[]),Se=n.useCallback(async()=>{if(be)try{await y?.(be),de(e=>e+1)}catch(e){console.error(`[RelatedList] remove failed`,e)}xe(null)},[be,y]),Ce=n.useCallback(async e=>{if(!C||!m||!l||j==null||N==null)return;let t=C.picker.valueField||`id`;se(!0),le(null);try{for(let n of e||[]){let e=n?.[t]??n?.id;e!=null&&(C.linkField?await m.create?.(l,{[j]:N,[C.linkField]:e}):await m.update?.(C.picker.object,String(e),{[j]:N}))}de(e=>e+1)}catch(e){let t=e?.body?.error??e?.error??e?.message??String(e);le(typeof t==`string`?t:`Failed to add`)}finally{se(!1),oe(!1)}},[C,m,l,j,N]),Q=(0,c.usePermissions)(),$=n.useMemo(()=>{let e=h||l||``,t=t=>!Q?.isLoaded||!e?t:t.filter(t=>{let n=t?.accessorKey||t?.field||t?.name;return n?Q.checkField(e,String(n),`read`):!0}),r=e=>j?e.filter(e=>(e?.accessorKey||e?.field||e?.name)!==j):e,i=e=>e==null||typeof e==`string`&&e.trim()===``||Array.isArray(e)&&e.length===0,a=e=>L.length?e.filter(e=>{let t=e?.accessorKey||e?.field||e?.name;return t?L.some(e=>!i(e?.[t])):!0}):e,s=(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`?fe[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})},c=t=>{if(typeof t!=`string`){let e=t?.accessorKey||t?.field||t?.name;if(t&&!t.cell&&!t.render&&e){let n=q?.fields?.[e],r=n?s(String(e),n):void 0;if(r)return{...t,cell:r}}return t}let n=q?.fields?.[t],r={accessorKey:t,header:n?.label||me(e,t,n)||t,fieldDef:n,fieldType:n?.type},i=n?s(t,n):void 0;return i&&(r.cell=i),r};if(f&&f.length>0)return a(t(r(f.map(c))));if(!q?.fields)return[];let u=Array.isArray(q.highlightFields)?q.highlightFields.filter(e=>typeof e==`string`&&e.length>0):[];if(u.length>0){let e=a(t(r(u.map(c))));if(e.length>0)return e.slice(0,Math.max(1,w))}let d=e,p=new Set([`image`,`file`,`attachment`,`rich_text`,`html`,`json`]),m=[`name`,`full_name`,`fullname`,`title`,`subject`,`label`,`code`,`number`],g=Object.entries(q.fields).filter(([e,t])=>!(e.startsWith(`_`)||e===`id`||e===j||t?.hidden||t?.type&&p.has(t.type)||Q?.isLoaded&&d&&!Q.checkField(d,e,`read`))),_=new Set([`created_at`,`updated_at`,`created_by`,`updated_by`,`owner_id`,`organization_id`]);return g.sort(([e,t],[n,r])=>{let i=_.has(e);if(i!==_.has(n))return i?1:-1;let a=m.indexOf(e),o=m.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}),a(g.map(([e,t])=>{let n={accessorKey:e,header:me(d,e,t.label||e)};if(t.type){let r=s(e,t);r&&(n.cell=r)}return n})).slice(0,Math.max(1,w))},[f,q,h,l,me,j,L,w,fe,Q]),we=Array.isArray(x)&&x.length>0,Te=!!v||!!y||we,Ee=(0,r.useIsMobile)(),De=n.useMemo(()=>{if(d)return d;if(Ee&&(t===`grid`||t===`table`)){let e=$[0]?.accessorKey||$[0]?.field||$[0]?.name,t=$.slice(1,4).map(e=>e.accessorKey||e.field||e.name).filter(Boolean);return{type:`object-gallery`,data:ve,objectName:l,gallery:{titleField:e||`name`,visibleFields:t,cardSize:`medium`},onRowClick:b}}switch(t){case`grid`:case`table`:return{type:`data-table`,data:ve,columns:$,pagination:!1,pageSize:X||10,searchable:!1,exportable:!1,rowActions:Te,onRowEdit:v,onRowDelete:y?Z:void 0,onRowClick:b,rowActionDefs:we?x:void 0,onRowActionDef:we?S:void 0};case`list`:return{type:`data-list`,data:ve};default:return{type:`div`,children:`No view configured`}}},[t,ve,$,d,X,Te,we,x,S,v,y,Z,b,Ee,l]),Oe=k?`cursor-pointer select-none`:void 0,ke=k?()=>ie(e=>!e):void 0,Ae=M(P),je=!z&&L.length===0,Me=O;return(0,s.jsxs)(r.Card,{className:(0,r.cn)(`shadow-none border-border/60 bg-transparent`,je&&`bg-muted/10`,p),children:[(0,s.jsx)(r.CardHeader,{className:(0,r.cn)(`py-3 px-4 sm:py-3 min-h-12 sm:min-h-0`,Oe),onClick:ke,children:(0,s.jsxs)(r.CardTitle,{className:`flex items-center justify-between gap-2 text-sm font-semibold`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[k&&(re?(0,s.jsx)(i.ChevronRight,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}):(0,s.jsx)(i.ChevronDown,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`})),(0,s.jsx)(Ae,{className:`h-4 w-4 text-muted-foreground shrink-0`,"aria-hidden":!0}),(0,s.jsx)(`span`,{className:(0,r.cn)(`truncate`,je&&`text-muted-foreground font-medium`),children:e}),(0,s.jsx)(r.Badge,{variant:`secondary`,className:(0,r.cn)(`text-xs font-normal h-5 px-1.5`,L.length===0&&`bg-muted text-muted-foreground`),"aria-label":`${L.length} records`,children:L.length}),je&&(0,s.jsx)(`span`,{className:`text-xs text-muted-foreground/70 italic ml-1 truncate`,children:Y(`detail.noRelatedRecords`)})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[C&&(0,s.jsxs)(r.Button,{variant:je?`ghost`:`outline`,size:`sm`,disabled:J,onClick:e=>{e.stopPropagation(),le(null),oe(!0)},className:`gap-1 h-9 sm:h-7 text-xs shadow-none`,children:[(0,s.jsx)(i.Plus,{className:`h-3.5 w-3.5`}),C.label||Y(`detail.add`,{defaultValue:`Add`})]}),g&&(0,s.jsxs)(r.Button,{variant:je?`ghost`:`outline`,size:`sm`,onClick:e=>{e.stopPropagation(),g()},className:`gap-1 h-9 sm:h-7 text-xs shadow-none`,children:[(0,s.jsx)(i.Plus,{className:`h-3.5 w-3.5`}),Y(`detail.new`)]})]})]})}),!re&&!je&&(0,s.jsxs)(r.CardContent,{className:(0,r.cn)(`pt-0 pb-4 px-4`),children:[Me&&(0,s.jsx)(`div`,{className:`mb-3`,children:(0,s.jsx)(r.Input,{placeholder:Y(`detail.filterPlaceholder`),value:K,onChange:e=>te(e.target.value),className:`h-8 text-sm`})}),D&&$&&$.length>0&&L.length>0&&(0,s.jsx)(`div`,{className:`flex flex-wrap gap-1 mb-3`,children:$.map(e=>{let t=e.accessorKey||e.field||e.name;if(!t)return null;let n=e.header||e.label||t,a=U===t;return(0,s.jsxs)(r.Button,{variant:a?`secondary`:`ghost`,size:`sm`,className:`gap-1 h-7 text-xs`,onClick:()=>ye(t),children:[(0,s.jsx)(i.ArrowUpDown,{className:`h-3 w-3`}),n,a&&(G===`asc`?` ↑`:` ↓`)]},t)})}),z?(0,s.jsx)(`div`,{className:`flex items-center justify-center py-6 text-muted-foreground text-sm`,children:Y(`detail.loading`)}):(0,s.jsx)(a.SchemaRenderer,{schema:De}),X>0&&ge.length>X&&(0,s.jsxs)(`div`,{className:`flex items-center justify-between mt-3 pt-3 border-t`,children:[(0,s.jsxs)(r.Button,{variant:`outline`,size:`sm`,className:`h-7 text-xs gap-1`,disabled:V===0,onClick:()=>H(e=>Math.max(0,e-1)),children:[(0,s.jsx)(i.ChevronLeft,{className:`h-3 w-3`}),Y(`detail.previousPage`)]}),(0,s.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:Y(`detail.pageOf`,{current:V+1,total:_e})}),(0,s.jsxs)(r.Button,{variant:`outline`,size:`sm`,className:`h-7 text-xs gap-1`,disabled:V>=_e-1,onClick:()=>H(e=>Math.min(_e-1,e+1)),children:[Y(`detail.nextPage`),(0,s.jsx)(i.ChevronRight,{className:`h-3 w-3`})]})]}),_&&!je&&X>0&&ge.length>X&&(0,s.jsx)(`div`,{className:`mt-3 pt-3 border-t flex justify-center`,children:(0,s.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),_()},className:`text-xs text-muted-foreground hover:text-foreground inline-flex items-center gap-1 transition-colors`,children:[Y(`detail.viewAll`),(0,s.jsx)(i.ExternalLink,{className:`h-3 w-3`})]})})]}),(0,s.jsx)(r.AlertDialog,{open:be!==null,onOpenChange:e=>{e||xe(null)},children:(0,s.jsxs)(r.AlertDialogContent,{children:[(0,s.jsxs)(r.AlertDialogHeader,{children:[(0,s.jsx)(r.AlertDialogTitle,{children:Y(`detail.deleteRowTitle`,{defaultValue:`Delete record`})}),(0,s.jsx)(r.AlertDialogDescription,{children:Y(`detail.deleteRowConfirmation`)})]}),(0,s.jsxs)(r.AlertDialogFooter,{children:[(0,s.jsx)(r.AlertDialogCancel,{children:Y(`detail.cancel`,{defaultValue:`Cancel`})}),(0,s.jsx)(r.AlertDialogAction,{onClick:Se,className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:Y(`detail.delete`,{defaultValue:`Delete`})})]})]})}),ce&&(0,s.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:ce}),C&&m&&(0,s.jsx)(o.RecordPickerDialog,{open:ae,onOpenChange:e=>oe(e),multiple:!0,dataSource:m,objectName:C.picker.object,title:C.label||Y(`detail.add`,{defaultValue:`Add`}),onSelect:()=>{},onSelectRecords:e=>{Ce(e)}})]})},P=({group:e,data:t,className:a,objectSchema:o,objectName:c,isEditing:l=!1,onFieldChange:u,dataSource:d})=>{let f=e.collapsible??!0,[p,m]=n.useState(e.defaultCollapsed??!1),h=(0,s.jsx)(`div`,{className:`space-y-3 sm:space-y-4`,children:e.sections.map((e,n)=>(0,s.jsx)(A,{section:e,data:t,objectSchema:o,objectName:c,isEditing:l,onFieldChange:u,dataSource:d},n))});return f?(0,s.jsxs)(r.Collapsible,{open:!p,onOpenChange:e=>m(!e),className:a,children:[(0,s.jsx)(r.CollapsibleTrigger,{asChild:!0,children:(0,s.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:[p?(0,s.jsx)(i.ChevronRight,{className:`h-4 w-4 text-muted-foreground shrink-0`}):(0,s.jsx)(i.ChevronDown,{className:`h-4 w-4 text-muted-foreground shrink-0`}),e.icon&&(0,s.jsx)(`span`,{className:`text-muted-foreground`,children:e.icon}),(0,s.jsx)(`h3`,{className:`text-lg font-semibold`,children:e.title})]})}),e.description&&!p&&(0,s.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:e.description}),(0,s.jsx)(r.CollapsibleContent,{children:(0,s.jsx)(`div`,{className:`mt-3`,children:h})})]}):(0,s.jsxs)(`div`,{className:(0,r.cn)(`space-y-3`,a),children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-2 pb-2 border-b`,children:[e.icon&&(0,s.jsx)(`span`,{className:`text-muted-foreground`,children:e.icon}),(0,s.jsx)(`h3`,{className:`text-lg font-semibold`,children:e.title})]}),e.description&&(0,s.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e.description}),h]})},F=({fields:e,data:t,className:n,objectName:c,objectSchema:l})=>{let{fieldLabel:u}=(0,a.useSafeFieldLabel)();if(!e.length||!t)return null;let d=e.filter(e=>{let n=t?.[e.name];return n!=null&&n!==``});return d.length===0?null:(0,s.jsx)(`section`,{className:(0,r.cn)(`@container border-b border-border/60 pb-4`,n),"aria-label":`Record highlights`,children:(0,s.jsx)(`div`,{className:(0,r.cn)(`flex flex-wrap gap-y-4`),children:d.map(e=>{let n=t[e.name],a=l?.fields?.[e.name],d=e.type||a?.type,f={name:e.name,label:e.label,type:d||`text`,...a?.options&&{options:a.options},...a?.currency&&{currency:a.currency},...a?.precision!==void 0&&{precision:a.precision},...a?.scale!==void 0&&{scale:a.scale},...a?.format&&{format:a.format}},p=(0,o.getCellRenderer)((0,o.resolveCellRendererType)(f)||d||`text`),m=d===`number`||d===`integer`||d===`currency`||d===`percent`||d===`decimal`,h=d===`email`||d===`url`||d===`textarea`||d===`reference`||d===`lookup`||d===`master_detail`,g=d===`boolean`;return(0,s.jsxs)(`div`,{className:(0,r.cn)(`flex flex-col gap-1 min-w-[7rem] px-5 border-l border-border/60 first:border-l-0 first:pl-0`,h?`basis-[16rem] max-w-[24rem]`:`basis-[9rem] max-w-[16rem]`),children:[(0,s.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:u(c||``,e.name,e.label)}),g?n?(0,s.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,s.jsx)(i.Check,{className:`h-3 w-3`,"aria-hidden":!0}),`Yes`]}):(0,s.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,s.jsx)(i.X,{className:`h-3 w-3`,"aria-hidden":!0}),`No`]}):(0,s.jsx)(`span`,{title:typeof n==`string`?n:void 0,className:(0,r.cn)(`block min-w-0 truncate text-sm font-semibold`,m&&`tabular-nums tracking-tight`),children:(0,s.jsx)(p,{value:n,field:f})})]},e.name)})})})};function I(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 L=({comments:e,onAddComment:t,onTogglePin:a,searchable:o=!1,className:c})=>{let{t:l}=E(),[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,s.jsxs)(r.Card,{className:(0,r.cn)(``,c),children:[(0,s.jsx)(r.CardHeader,{children:(0,s.jsxs)(r.CardTitle,{className:`flex items-center gap-2 text-base`,children:[(0,s.jsx)(i.MessageSquare,{className:`h-4 w-4`}),l(`detail.comments`),(0,s.jsxs)(`span`,{className:`text-sm font-normal text-muted-foreground`,children:[`(`,e.length,`)`]})]})}),(0,s.jsxs)(r.CardContent,{className:`space-y-4`,children:[o&&(0,s.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,s.jsxs)(`div`,{className:`relative flex-1`,children:[(0,s.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,s.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:l(`detail.searchComments`),value:m,onChange:e=>h(e.target.value),"aria-label":l(`detail.searchComments`)}),m&&(0,s.jsx)(`button`,{className:`absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground`,onClick:()=>h(``),"aria-label":l(`detail.clearSearch`),type:`button`,children:(0,s.jsx)(i.X,{className:`h-3.5 w-3.5`})})]})}),t&&(0,s.jsxs)(`div`,{className:`flex gap-2`,children:[(0,s.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:l(`detail.addCommentPlaceholder`),value:u,onChange:e=>d(e.target.value),onKeyDown:_,disabled:f}),(0,s.jsx)(r.Button,{size:`icon`,variant:`default`,onClick:g,disabled:!u.trim()||f,className:`shrink-0 self-end`,children:(0,s.jsx)(i.Send,{className:`h-4 w-4`})})]}),v.length===0?(0,s.jsx)(`p`,{className:`text-sm text-muted-foreground text-center py-4`,children:m.trim()?l(`detail.noMatchingComments`):l(`detail.noCommentsYet`)}):(0,s.jsx)(`div`,{className:`space-y-3`,children:v.map(e=>(0,s.jsxs)(`div`,{className:(0,r.cn)(`flex gap-3`,e.pinned&&`bg-muted/40 rounded-md p-2 -mx-2`),children:[(0,s.jsx)(`div`,{className:`shrink-0`,children:e.avatarUrl?(0,s.jsx)(`img`,{src:e.avatarUrl,alt:e.author,className:`h-8 w-8 rounded-full object-cover`}):(0,s.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,s.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-2 mb-0.5`,children:[(0,s.jsx)(`span`,{className:`text-sm font-medium truncate`,children:e.author}),(0,s.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:I(e.createdAt)}),e.pinned&&(0,s.jsxs)(`span`,{className:`text-xs text-amber-600 flex items-center gap-0.5`,children:[(0,s.jsx)(i.Pin,{className:`h-3 w-3`}),l(`detail.pinned`)]})]}),(0,s.jsx)(`p`,{className:`text-sm whitespace-pre-wrap break-words`,children:e.text}),a&&(0,s.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?l(`detail.unpin`):l(`detail.pin`),children:[(0,s.jsx)(i.Pin,{className:`h-3 w-3`}),e.pinned?l(`detail.unpin`):l(`detail.pin`)]})]})]},e.id))})]})]})},R={field_change:i.Edit,create:i.PlusCircle,delete:i.Trash2,comment:i.MessageSquare,status_change:i.ArrowRightLeft},z={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 B(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 V(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 H={all:`All`,field_change:`Field Changes`,create:`Creates`,delete:`Deletes`,comment:`Comments`,status_change:`Status Changes`},U=({activities:e,filterable:t=!1,defaultFilter:a=`all`,className:o})=>{let[c,l]=n.useState(a),u=n.useMemo(()=>c===`all`?e:e.filter(e=>e.type===c),[e,c]);return(0,s.jsxs)(r.Card,{className:(0,r.cn)(``,o),children:[(0,s.jsx)(r.CardHeader,{children:(0,s.jsxs)(r.CardTitle,{className:`flex items-center gap-2 text-base`,children:[(0,s.jsx)(i.Activity,{className:`h-4 w-4`}),`Activity`,(0,s.jsxs)(`span`,{className:`text-sm font-normal text-muted-foreground`,children:[`(`,u.length,`)`]})]})}),(0,s.jsxs)(r.CardContent,{children:[t&&(0,s.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mb-4`,role:`group`,"aria-label":`Activity type filter`,children:Object.keys(H).map(e=>(0,s.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`,c===e?`bg-primary text-primary-foreground`:`bg-muted text-muted-foreground hover:bg-muted/80`),onClick:()=>l(e),"aria-pressed":c===e,children:[e!==`all`&&n.createElement(R[e]||i.Edit,{className:`h-3 w-3`}),H[e]]},e))}),u.length===0?(0,s.jsx)(r.DataEmptyState,{title:`No activity recorded`,className:`py-6`}):(0,s.jsxs)(`div`,{className:`relative`,children:[(0,s.jsx)(`div`,{className:`absolute left-4 top-2 bottom-2 w-px bg-border`}),(0,s.jsx)(`div`,{className:`space-y-4`,children:u.map(e=>{let t=R[e.type]||i.Edit;return(0,s.jsxs)(`div`,{className:`flex gap-3 relative`,children:[(0,s.jsx)(`div`,{className:(0,r.cn)(`shrink-0 h-8 w-8 rounded-full flex items-center justify-center z-10`,z[e.type]||`bg-gray-100 text-gray-600`),children:(0,s.jsx)(t,{className:`h-3.5 w-3.5`})}),(0,s.jsxs)(`div`,{className:`flex-1 min-w-0 pt-1`,children:[(0,s.jsxs)(`p`,{className:`text-sm`,children:[(0,s.jsx)(`span`,{className:`font-medium`,children:e.user}),` `,(0,s.jsx)(`span`,{className:`text-muted-foreground`,children:V(e)})]}),(0,s.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:B(e.timestamp)})]})]},e.id)})})]})]})]})},W={create:`default`,update:`secondary`,delete:`destructive`,restore:`outline`,login:`outline`,logout:`outline`,permission_change:`secondary`,config_change:`secondary`,export:`outline`,import:`outline`};function G(e){if(!e)return``;let t=e instanceof Date?e:new Date(e);return Number.isNaN(t.getTime())?String(e):t.toLocaleString()}var ee=[[60,`second`],[60,`minute`],[24,`hour`],[7,`day`],[4.34524,`week`],[12,`month`],[1/0,`year`]];function K(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 ee){if(Math.abs(r)<n)try{return new Intl.RelativeTimeFormat(t,{numeric:`auto`}).format(Math.round(r),i)}catch{return G(e)}r/=n}return G(e)}function te(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 q(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 ne({entries:e,loading:t,emptyText:n,className:i,locale:a}){return t?(0,s.jsx)(`div`,{className:(0,r.cn)(`space-y-3`,i),children:Array.from({length:4}).map((e,t)=>(0,s.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,s.jsx)(r.Skeleton,{className:`h-8 w-8 rounded-full`}),(0,s.jsxs)(`div`,{className:`flex-1 space-y-2`,children:[(0,s.jsx)(r.Skeleton,{className:`h-4 w-1/3`}),(0,s.jsx)(r.Skeleton,{className:`h-3 w-1/2`})]})]},t))}):!e||e.length===0?(0,s.jsx)(`div`,{className:(0,r.cn)(`flex items-center justify-center rounded-md border border-dashed py-10 text-sm text-muted-foreground`,i),children:n??`No history yet`}):(0,s.jsx)(r.TooltipProvider,{delayDuration:150,children:(0,s.jsx)(`ol`,{className:(0,r.cn)(`space-y-4`,i),children:e.map((e,t)=>{let n=(e.action??``).toLowerCase(),i=W[n]??`outline`,o=typeof e.user_name==`string`&&e.user_name.trim()||`Unknown user`,c=G(e.created_at),l=K(e.created_at,a),u=typeof e.user_avatar==`string`?e.user_avatar:void 0;return(0,s.jsxs)(`li`,{className:`flex items-start gap-3`,children:[(0,s.jsxs)(r.Avatar,{className:`h-8 w-8 mt-0.5 shrink-0`,children:[u?(0,s.jsx)(r.AvatarImage,{src:u,alt:o}):null,(0,s.jsx)(r.AvatarFallback,{className:`text-[10px] font-medium`,children:te(e.user_name)})]}),(0,s.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,s.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2 gap-y-1`,children:[(0,s.jsx)(`span`,{className:`text-sm font-medium text-foreground`,children:o}),e.action&&(0,s.jsx)(r.Badge,{variant:i,className:`text-[10px] uppercase tracking-wide`,children:e.action}),c&&(0,s.jsxs)(r.Tooltip,{children:[(0,s.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,s.jsx)(`span`,{className:`text-xs text-muted-foreground cursor-help`,"aria-label":c,children:l||c})}),(0,s.jsx)(r.TooltipContent,{children:c})]})]}),e.summary&&(0,s.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:e.summary}),e.changes&&e.changes.length>0&&(n===`create`?(0,s.jsxs)(`details`,{className:`mt-1 group`,children:[(0,s.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,s.jsx)(`span`,{className:`transition-transform group-open:rotate-90`,children:`▸`}),(0,s.jsx)(`span`,{children:e.changes.length===1?`1 field populated`:`${e.changes.length} fields populated`})]}),(0,s.jsx)(`ul`,{className:`mt-1.5 space-y-0.5 text-xs text-muted-foreground pl-4`,children:e.changes.map(e=>(0,s.jsxs)(`li`,{className:`leading-relaxed`,children:[(0,s.jsx)(`span`,{className:`font-medium text-foreground`,children:e.label||e.field}),`: `,(0,s.jsx)(`span`,{className:`text-foreground`,children:q(e.to)})]},e.field))})]}):(0,s.jsx)(`ul`,{className:`mt-1.5 space-y-0.5 text-xs text-muted-foreground`,children:e.changes.map(e=>(0,s.jsxs)(`li`,{className:`leading-relaxed`,children:[(0,s.jsx)(`span`,{className:`font-medium text-foreground`,children:e.label||e.field}),`: `,(0,s.jsx)(`span`,{className:`line-through opacity-70`,children:q(e.from)}),` → `,(0,s.jsx)(`span`,{className:`text-foreground`,children:q(e.to)})]},e.field))}))]})]},e.id??t)})})})}var re={createdAt:`created_at`,createdBy:`created_by`,updatedAt:`updated_at`,updatedBy:`updated_by`};function ie(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 ae(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 oe(e){try{return new Intl.DateTimeFormat(void 0,{dateStyle:`medium`,timeStyle:`short`}).format(e)}catch{return e.toISOString()}}var J=({value:e,objectSchema:t,fieldName:n})=>{if(e==null||e===``)return null;let r=t?.fields?.[n],i=r?.reference_to||r?.reference,a={name:n,type:r?.type||(i?`lookup`:`text`),...i&&{reference_to:i},...r?.reference_field&&{reference_field:r.reference_field}},c=(0,o.resolveCellRendererType)(a)||a.type;if(c){let t=(0,o.getCellRenderer)(c);if(t)return(0,s.jsx)(`span`,{className:`inline-flex items-center [&_a]:text-inherit [&_a]:hover:underline`,children:(0,s.jsx)(t,{value:e,field:a})})}return(0,s.jsx)(`span`,{children:String(e)})},se=({label:e,user:t,date:n,objectSchema:i,userField:a,t:o})=>{if(!t&&!n)return null;let c=n?(0,s.jsx)(r.TooltipProvider,{delayDuration:200,children:(0,s.jsxs)(r.Tooltip,{children:[(0,s.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,s.jsx)(`time`,{dateTime:n.toISOString(),className:`cursor-default underline decoration-dotted decoration-muted-foreground/40 underline-offset-2`,children:ae(n,o)})}),(0,s.jsx)(r.TooltipContent,{side:`top`,children:oe(n)})]})}):null;return(0,s.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,s.jsx)(`span`,{className:`text-muted-foreground/70`,children:e}),t?(0,s.jsx)(J,{value:t,objectSchema:i,fieldName:a}):null,t&&c?(0,s.jsx)(`span`,{className:`text-muted-foreground/40`,children:`·`}):null,c]})},ce=({data:e,objectSchema:t,objectName:n,className:i})=>{let{t:a}=E();if(!e)return null;let o=ie(e[re.createdAt]),c=ie(e[re.updatedAt]),l=e[re.createdBy],u=e[re.updatedBy],d=!!(o||l),f=o&&c&&Math.abs(c.getTime()-o.getTime())<2e3,p=!!(c||u)&&!(f&&(l!=null&&u!=null&&String(l)===String(u)||!u));return!d&&!p?null:(0,s.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,s.jsx)(se,{label:a(`detail.createdBy`),user:l,date:o,objectSchema:t,userField:re.createdBy,t:a}),p&&(0,s.jsx)(se,{label:a(`detail.updatedBy`),user:u,date:c,objectSchema:t,userField:re.updatedBy,t:a})]})},le=5;function ue(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 t=e.id??e._id;if(t!=null&&String(t).trim()!==``)return`Record #${t}`}return i}var de=({schema:e,dataSource:o,className:u,onEdit:d,onDelete:f,onBack:p,inlineEdit:m=!1,onFieldSave:h,discussionSlot:g,rightRail:_,objectLabel:v,onDataLoaded:y,isFavorite:b,onToggleFavorite:x})=>{let[S,C]=n.useState(e.data),[w,T]=n.useState(!e.data&&!!(e.api&&e.resourceId||o&&e.objectName&&e.resourceId)),[D,O]=n.useState(!1),k=b??D,[M,I]=n.useState(!1),[R,z]=n.useState({}),[B,V]=n.useState(!1),[H,W]=n.useState(null),[G,ee]=n.useState(null),[K,te]=n.useState(!1),[q,re]=n.useState(0),ie=(0,a.useDataInvalidation)(e.objectName||void 0,e.resourceId==null?void 0:String(e.resourceId)),[ae,oe]=n.useState(!1),{t:J}=E(),{currency:se}=(0,l.useLocalization)(),{fieldOptionLabel:de}=(0,a.useSafeFieldLabel)(),fe=(0,r.useIsMobile)(),pe=(0,c.usePermissions)(),Y=n.useMemo(()=>{if(!pe?.isLoaded||!e.objectName)return e;let t=t=>pe.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,pe]);n.useEffect(()=>{S&&y&&y(S)},[S,y]);let me=n.useMemo(()=>{if(Y.summaryFields&&Y.summaryFields.length>0)return[];let e=[...Y.sections?.flatMap(e=>e.fields)||[],...Y.fields||[]],t={};for(let n of e)t[n.name]||(t[n.name]=n);if(G?.fields)for(let[e,n]of Object.entries(G.fields))t[e]={...t[e]||{},...n,name:e};let n=e=>S?.[e]!==void 0&&S?.[e]!==null&&S?.[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},[Y.summaryFields,Y.sections,Y.fields,G,S]),he=Y.summaryFields&&Y.summaryFields.length>0?Y.summaryFields:me,ge=n.useCallback(()=>{Y.resourceId&&navigator.clipboard.writeText(String(Y.resourceId)).then(()=>{te(!0),setTimeout(()=>te(!1),1500)})},[Y.resourceId]);n.useEffect(()=>{let e=!0;if(Y.data)return C(Y.data),T(!1),o?.getObjectSchema&&Y.objectName&&o.getObjectSchema(Y.objectName).then(t=>{e&&ee(t)}).catch(()=>{}),()=>{e=!1};if(o&&Y.objectName&&Y.resourceId){T(!0),ee(null),C(null);let n=Y.objectName,r=Y.resourceId,i=`${n}-`,a=[...Y.sections?.flatMap(e=>e.fields)||[],...Y.fields||[]];(o.getObjectSchema?o.getObjectSchema(n).catch(()=>null):Promise.resolve(null)).then(s=>{if(!e)return;ee(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&&(C(t),T(!1))}).catch(()=>{e&&(C(null),T(!1))})};return u.catch(()=>null).then(t=>{if(e){if(t){C(t),T(!1);return}return d()}})}).catch(t=>{e&&(console.error(`Failed to fetch detail data:`,t),T(!1))})}else Y.api&&Y.resourceId&&(T(!0),fetch(`${Y.api}/${Y.resourceId}`).then(e=>e.json()).then(t=>{e&&C(t?.data||t)}).catch(e=>{console.error(`Failed to fetch detail data:`,e)}).finally(()=>{e&&T(!1)}));return()=>{e=!1}},[Y.api,Y.resourceId,Y.objectName,o,Y.sections,Y.fields,q,ie]);let X=n.useCallback(()=>{if(p)p();else if(Y.onNavigate){let e=Y.backUrl||(Y.objectName?`/${Y.objectName}`:`/`);Y.onNavigate(e,{replace:!0})}else Y.backUrl?window.location.href=Y.backUrl:window.history.back()},[p,Y]),_e=n.useCallback(()=>{d?d():Y.onNavigate&&Y.editUrl?Y.onNavigate(Y.editUrl):Y.onNavigate&&Y.objectName&&Y.resourceId?Y.onNavigate(`/${Y.objectName}/${Y.resourceId}/edit`):Y.editUrl&&(window.location.href=Y.editUrl)},[d,Y]),ve=n.useCallback(async()=>{if(!o?.cancelPendingApproval||!Y.objectName||!Y.resourceId){W(J(`detail.cancelApprovalUnavailable`));return}oe(!0),W(null);try{if(await o.cancelPendingApproval(String(Y.objectName),String(Y.resourceId)),o.findOne)try{let e=await o.findOne(String(Y.objectName),String(Y.resourceId));e&&C(e)}catch{}re(e=>e+1);try{window.dispatchEvent(new CustomEvent(`objectui:record-changed`,{detail:{objectName:String(Y.objectName),recordId:String(Y.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*/,``);W(`${J(`detail.cancelApprovalFailed`)}: ${t}`)}finally{oe(!1)}},[o,Y.objectName,Y.resourceId,J]),ye=n.useCallback(()=>{let e=Y.deleteConfirmation||J(`detail.deleteConfirmation`);window.confirm(e)&&(f?.(),Y.onNavigate&&Y.objectName&&Y.onNavigate(`/${Y.objectName}`,{replace:!0}))},[f,Y]),be=n.useCallback(()=>{navigator.share&&Y.objectName&&Y.resourceId?navigator.share({title:Y.title||J(`detail.details`),text:`${Y.objectName} #${Y.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`)})},[Y]),xe=n.useCallback(()=>{let e=!k;x&&x(e),b===void 0&&O(e)},[k,b,x]),Z=n.useCallback(async()=>{if(M){let e=Object.entries(R);if(e.length>0){let t=S,n={...S,...R};C(n),W(null),V(!0);try{if(h)for(let[t,r]of e)await h(t,r,n);z({}),I(!1)}catch(e){C(t),W((e?.message||e?.error||String(e??`Save failed`)).replace(/^\[[^\]]+\]\s*/,``).replace(/^[A-Z][A-Z0-9_]+:\s*/,``))}finally{V(!1)}return}z({})}I(!M),W(null)},[M,R,S,h]),Se=n.useCallback(()=>{z({}),I(!1),W(null)},[]),Ce=n.useCallback((e,t)=>{z(n=>({...n,[e]:t}))},[]);n.useEffect(()=>{if(!Y.recordNavigation)return;let e=Y.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)},[Y.recordNavigation]),n.useEffect(()=>{if(!m||Y.showHeader!==!1)return;let e=`objectui:record:inline-edit-toggle`,t=e=>{let t=e.detail;t?.recordId&&Y.recordId&&t.recordId!==Y.recordId||t?.objectName&&Y.objectName&&t.objectName!==Y.objectName||Z()};return window.addEventListener(e,t),()=>window.removeEventListener(e,t)},[m,Y.showHeader,Y.recordId,Y.objectName,Z]);let Q=n.useMemo(()=>Y.related??[],[Y.related]),$=n.useMemo(()=>{let e=[];return e.push({name:`sys_share`,label:J(`detail.share`),icon:`share-2`,type:`script`,onClick:be}),Y.showEdit&&e.push({name:`sys_edit_mobile`,label:J(`detail.edit`),icon:`edit`,type:`script`,className:`sm:hidden`,onClick:_e}),m&&e.push({name:`sys_toggle_inline_edit_mobile`,label:J(M?`detail.save`:`detail.editInline`),icon:`edit`,type:`script`,className:`sm:hidden`,onClick:Z}),Y.showDelete&&e.push({name:`sys_delete`,label:J(`detail.delete`),icon:`trash-2`,type:`script`,variant:`destructive`,tags:[`separator-before`],onClick:ye}),e},[J,Y.showEdit,Y.showDelete,m,M,be,_e,Z,ye]),we=n.useMemo(()=>{let e=Y.actions??[];if($.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,...$]}}return e});return t||n.push({type:`action:bar`,location:`record_header`,systemActions:$}),n},[Y.actions,$]);return w||Y.loading?(0,s.jsxs)(`div`,{className:(0,r.cn)(`space-y-4`,u),children:[(0,s.jsx)(r.Skeleton,{className:`h-10 w-full`}),(0,s.jsx)(r.Skeleton,{className:`h-64 w-full`}),(0,s.jsx)(r.Skeleton,{className:`h-48 w-full`})]}):!S&&!Y.data?(0,s.jsxs)(`div`,{className:(0,r.cn)(`flex flex-col items-center justify-center py-16 text-center`,u),children:[(0,s.jsx)(`p`,{className:`text-lg font-semibold`,children:J(`detail.recordNotFound`)}),(0,s.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:J(`detail.recordNotFoundDescription`)}),(Y.showBack??!0)&&(0,s.jsxs)(r.Button,{variant:`outline`,size:`sm`,onClick:X,className:`mt-4 gap-2`,children:[(0,s.jsx)(i.ArrowLeft,{className:`h-4 w-4`}),J(`detail.goBack`)]})]}):(0,s.jsx)(r.TooltipProvider,{children:(0,s.jsxs)(`div`,{className:(0,r.cn)(`space-y-6`,u),children:[Y.showHeader!==!1&&(0,s.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start justify-between gap-3 sm:gap-4 pb-4 border-b`,children:[(0,s.jsxs)(`div`,{className:`flex items-start gap-2 sm:gap-3 flex-1 min-w-0`,children:[(Y.showBack??!0)&&(0,s.jsxs)(r.Tooltip,{children:[(0,s.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,s.jsx)(r.Button,{variant:`ghost`,size:`icon`,onClick:X,className:`shrink-0 mt-1`,children:(0,s.jsx)(i.ArrowLeft,{className:`h-4 w-4`})})}),(0,s.jsx)(r.TooltipContent,{children:J(`detail.back`)})]}),(0,s.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,s.jsx)(`h1`,{className:`text-xl sm:text-2xl font-bold truncate`,children:ue(S,Y,G,J(`detail.details`))}),he.map(e=>{let t=S?.[e];if(t==null||t===``)return null;let n=(Y.sections||[]).flatMap(e=>e.fields).concat(Y.fields||[]).find(t=>t.name===e),i=G?.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,l.resolveFieldCurrency)({...i,...n},se);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=Y.objectName?de(Y.objectName,e,String(t),a):a}}catch{}return c===null?(0,s.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,s.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,s.jsx)(`span`,{className:`relative inline-block h-1.5 w-12 rounded-full bg-primary/20 overflow-hidden`,"aria-hidden":!0,children:(0,s.jsx)(`span`,{className:`absolute inset-y-0 left-0 rounded-full bg-primary`,style:{width:`${c}%`}})}),o]},e)}),(0,s.jsxs)(r.Tooltip,{children:[(0,s.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,s.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-6 w-6 shrink-0`,onClick:xe,"aria-label":J(k?`detail.removeFromFavorites`:`detail.addToFavorites`),children:k?(0,s.jsx)(i.Star,{className:`h-4 w-4 fill-yellow-400 text-yellow-400`}):(0,s.jsx)(i.Star,{className:`h-4 w-4 text-muted-foreground`})})}),(0,s.jsx)(r.TooltipContent,{children:J(k?`detail.removeFromFavorites`:`detail.addToFavorites`)})]})]}),Y.objectName&&(0,s.jsxs)(`p`,{className:`text-sm text-muted-foreground mt-1 flex items-center gap-1`,children:[(0,s.jsx)(`span`,{className:`font-medium`,children:v||Y.objectName}),Y.resourceId&&(0,s.jsxs)(r.Tooltip,{children:[(0,s.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,s.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-5 w-5 shrink-0 text-muted-foreground/60 hover:text-foreground`,onClick:ge,"aria-label":J(`detail.copyRecordId`,{defaultValue:`Copy record ID`}),children:K?(0,s.jsx)(i.Check,{className:`h-3 w-3 text-green-600`}):(0,s.jsx)(i.Copy,{className:`h-3 w-3`})})}),(0,s.jsx)(r.TooltipContent,{children:K?J(`detail.copied`,{defaultValue:`Copied`}):J(`detail.copyRecordId`,{defaultValue:`Copy record ID`})})]})]})]})]}),(0,s.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 shrink-0 w-full sm:w-auto`,children:[Y.recordNavigation&&(0,s.jsxs)(`div`,{className:`flex items-center gap-1 mr-2`,children:[(0,s.jsxs)(r.Tooltip,{children:[(0,s.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,s.jsx)(r.Button,{variant:`outline`,size:`icon`,className:`h-8 w-8`,disabled:Y.recordNavigation.currentIndex<=0,onClick:()=>{let e=Y.recordNavigation;e.currentIndex>0&&e.onNavigate(e.recordIds[e.currentIndex-1])},children:(0,s.jsx)(i.ChevronLeft,{className:`h-4 w-4`})})}),(0,s.jsx)(r.TooltipContent,{children:J(`detail.previousRecord`)})]}),(0,s.jsx)(`span`,{className:`text-xs text-muted-foreground whitespace-nowrap px-1`,children:J(`detail.recordOf`,{current:Y.recordNavigation.currentIndex+1,total:Y.recordNavigation.recordIds.length})}),(0,s.jsxs)(r.Tooltip,{children:[(0,s.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,s.jsx)(r.Button,{variant:`outline`,size:`icon`,className:`h-8 w-8`,disabled:Y.recordNavigation.currentIndex>=Y.recordNavigation.recordIds.length-1,onClick:()=>{let e=Y.recordNavigation;e.currentIndex<e.recordIds.length-1&&e.onNavigate(e.recordIds[e.currentIndex+1])},children:(0,s.jsx)(i.ChevronRight,{className:`h-4 w-4`})})}),(0,s.jsx)(r.TooltipContent,{children:J(`detail.nextRecord`)})]})]}),m&&(0,s.jsxs)(s.Fragment,{children:[M&&(0,s.jsxs)(r.Tooltip,{children:[(0,s.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,s.jsxs)(r.Button,{variant:`ghost`,size:`sm`,onClick:Se,className:`gap-2 hidden sm:inline-flex`,children:[(0,s.jsx)(i.X,{className:`h-4 w-4`}),(0,s.jsx)(`span`,{className:`hidden sm:inline`,children:J(`detail.cancel`)})]})}),(0,s.jsx)(r.TooltipContent,{children:J(`detail.cancelEdit`)})]}),(0,s.jsxs)(r.Tooltip,{children:[(0,s.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,s.jsx)(r.Button,{variant:M?`default`:`outline`,size:`sm`,onClick:Z,className:`gap-2 hidden sm:inline-flex`,children:M?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(i.Check,{className:`h-4 w-4`}),(0,s.jsx)(`span`,{className:`hidden sm:inline`,children:J(`detail.save`)})]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(i.Edit,{className:`h-4 w-4`}),(0,s.jsx)(`span`,{className:`hidden sm:inline`,children:J(`detail.editInline`)})]})})}),(0,s.jsx)(r.TooltipContent,{children:J(M?`detail.saveChanges`:`detail.editFieldsInline`)})]})]}),Y.showEdit&&(0,s.jsxs)(r.Tooltip,{children:[(0,s.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,s.jsxs)(r.Button,{variant:`default`,onClick:_e,className:`gap-2 hidden sm:inline-flex`,children:[(0,s.jsx)(i.Edit,{className:`h-4 w-4`}),(0,s.jsx)(`span`,{className:`hidden sm:inline`,children:J(`detail.edit`)})]})}),(0,s.jsx)(r.TooltipContent,{children:J(`detail.editRecord`)})]}),we.map((e,t)=>(0,s.jsx)(a.SchemaRenderer,{schema:e,data:S},`header-action-${t}`))]})]}),Y.header&&(0,s.jsx)(`div`,{children:(0,s.jsx)(a.SchemaRenderer,{schema:Y.header,data:S})}),Y.highlightFields&&Y.highlightFields.length>0&&(0,s.jsx)(F,{fields:Y.highlightFields,data:S,objectName:Y.objectName,objectSchema:G}),m&&Y.showHeader===!1&&(()=>{let e=S?.approval_status,t=e===`pending`||e===`in_approval`;return!M&&!B&&!H&&!t?null:(0,s.jsxs)(`div`,{className:`flex flex-col items-end gap-1`,children:[(0,s.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[t&&!M&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(`span`,{role:`status`,className:`inline-flex items-center gap-1 rounded-md border border-amber-300 bg-amber-50 px-2 py-1 text-xs text-amber-800`,title:J(`detail.lockedTooltip`),children:[(0,s.jsx)(i.Lock,{className:`h-3 w-3`}),(0,s.jsx)(`span`,{children:J(`detail.lockedByApproval`)})]}),o?.cancelPendingApproval&&(0,s.jsxs)(r.Button,{variant:`outline`,size:`sm`,onClick:ve,disabled:ae,className:`gap-2 border-amber-300 text-amber-800 hover:bg-amber-50`,title:J(`detail.cancelApprovalTooltip`),children:[(0,s.jsx)(i.X,{className:`h-4 w-4`}),(0,s.jsx)(`span`,{children:J(ae?`detail.cancelApprovalInFlight`:`detail.cancelApproval`)})]})]}),M&&(0,s.jsxs)(r.Button,{variant:`ghost`,size:`sm`,onClick:Se,className:`gap-2`,disabled:B,children:[(0,s.jsx)(i.X,{className:`h-4 w-4`}),(0,s.jsx)(`span`,{children:J(`detail.cancel`)})]}),(0,s.jsxs)(r.Button,{variant:M?`default`:`outline`,size:`sm`,onClick:Z,className:`gap-2`,disabled:B||t&&!M,title:t&&!M?J(`detail.lockedTooltip`):void 0,children:[M?(0,s.jsx)(i.Check,{className:`h-4 w-4`}):(0,s.jsx)(i.Edit,{className:`h-4 w-4`}),(0,s.jsx)(`span`,{children:J(B?`detail.saving`:M?`detail.save`:`detail.editFieldsInline`)})]})]}),H&&(0,s.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:H})]})})(),Y.autoTabs&&!Y.tabs?.length?(()=>{let e=Q.length>0,t=!!Y.activities&&Y.activities.length>0,n=!!g,i=!!Y.history,a=[`details`,...e?[`related`]:[],...t?[`activity`]:[],...n?[`discussion`]:[],...i?[`history`]:[]],c=Y.defaultTab,l=c&&a.includes(c)?c:`details`,u=Y.onTabChange,d=(0,s.jsxs)(`div`,{className:`space-y-3 sm:space-y-4`,children:[Y.sectionGroups&&Y.sectionGroups.length>0&&Y.sectionGroups.map((e,t)=>(0,s.jsx)(P,{group:e,data:{...S,...R},objectSchema:G,objectName:Y.objectName,isEditing:M,onFieldChange:Ce,dataSource:o},t)),Y.sections&&Y.sections.length>0&&Y.sections.map((e,t)=>(0,s.jsx)(A,{section:e,data:{...S,...R},objectSchema:G,objectName:Y.objectName,isEditing:M,onFieldChange:Ce,dataSource:o},t)),Y.fields&&Y.fields.length>0&&!Y.sections?.length&&(0,s.jsx)(A,{section:{fields:Y.fields,columns:Y.columns},data:{...S,...R},objectSchema:G,objectName:Y.objectName,isEditing:M,onFieldChange:Ce,dataSource:o}),Y.comments&&(0,s.jsx)(L,{comments:Y.comments,onAddComment:Y.onAddComment})]});return!e&&!t&&!n&&!i?(0,s.jsx)(`div`,{className:`mt-2`,children:d}):(0,s.jsxs)(r.Tabs,{defaultValue:l,onValueChange:u,className:`w-full`,children:[(0,s.jsxs)(r.TabsList,{className:`w-full justify-start border-b rounded-none bg-transparent p-0`,children:[(0,s.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:J(`detail.details`)}),e&&(0,s.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,s.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[J(`detail.related`),(0,s.jsx)(r.Badge,{variant:`secondary`,className:`text-xs bg-primary/10 text-primary border-transparent`,children:Q.length})]})}),t&&(0,s.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,s.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[J(`detail.activity`),(0,s.jsx)(r.Badge,{variant:`secondary`,className:`text-xs bg-primary/10 text-primary border-transparent`,children:Y.activities.length})]})}),n&&(0,s.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:J(`detail.discussion`,{defaultValue:`Discussion`})}),i&&(0,s.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,s.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[J(`detail.history`,{defaultValue:`History`}),!Y.history.loading&&Y.history.entries.length>0&&(0,s.jsx)(r.Badge,{variant:`secondary`,className:`text-xs bg-primary/10 text-primary border-transparent`,children:Y.history.entries.length})]})})]}),(0,s.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,s.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,s.jsx)(`div`,{className:`space-y-3`,children:Q.map((e,t)=>(0,s.jsx)(N,{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:fe&&t>0,pageSize:le},t))})}),t&&(0,s.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,s.jsx)(U,{activities:Y.activities})}),n&&(0,s.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:g}),i&&(0,s.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,s.jsx)(ne,{entries:Y.history.entries,loading:Y.history.loading,emptyText:Y.history.emptyText??J(`detail.historyEmpty`,{defaultValue:`No history yet`})})})]})})():(0,s.jsxs)(s.Fragment,{children:[Y.sectionGroups&&Y.sectionGroups.length>0&&(0,s.jsx)(`div`,{className:`space-y-3 sm:space-y-4`,children:Y.sectionGroups.map((e,t)=>(0,s.jsx)(P,{group:e,data:{...S,...R},objectSchema:G,objectName:Y.objectName,isEditing:M,onFieldChange:Ce,dataSource:o},t))}),Y.sections&&Y.sections.length>0&&(0,s.jsx)(`div`,{className:`space-y-3 sm:space-y-4`,children:Y.sections.map((e,t)=>(0,s.jsx)(A,{section:e,data:{...S,...R},objectSchema:G,objectName:Y.objectName,isEditing:M,onFieldChange:Ce,dataSource:o},t))}),Y.fields&&Y.fields.length>0&&!Y.sections?.length&&(0,s.jsx)(A,{section:{fields:Y.fields,columns:Y.columns},data:{...S,...R},objectSchema:G,objectName:Y.objectName,isEditing:M,onFieldChange:Ce,dataSource:o}),Y.tabs&&Y.tabs.length>0&&(0,s.jsx)(j,{tabs:Y.tabs,data:S}),Q.length>0&&(0,s.jsxs)(`div`,{className:`space-y-3`,children:[(0,s.jsx)(`h2`,{className:`text-lg font-semibold`,children:J(`detail.related`)}),Q.map((e,t)=>(0,s.jsx)(N,{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:fe&&t>0,pageSize:le},t))]}),Y.comments&&(0,s.jsx)(L,{comments:Y.comments,onAddComment:Y.onAddComment}),Y.activities&&Y.activities.length>0&&(0,s.jsx)(U,{activities:Y.activities})]}),(0,s.jsx)(ce,{data:{...S,...R},objectSchema:G,objectName:Y.objectName}),Y.footer&&(0,s.jsx)(`div`,{children:(0,s.jsx)(a.SchemaRenderer,{schema:Y.footer,data:S})})]})})},fe=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)}},pe=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()}},Y=({open:e,conflict:t,onReload:n,onOverwrite:a,onCancel:o,busy:c=!1})=>{let{t:l}=E(),u=t?.label||t?.field||``,d=t?fe(t.pendingValue):``,f=t?fe(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=pe(p.updated_at??t?.currentVersion),[g,_]=l(`detail.concurrentUpdateDescription`,{field:`{{field}}`}).split(`{{field}}`);return(0,s.jsx)(r.AlertDialog,{open:e,onOpenChange:e=>{!e&&!c&&o()},children:(0,s.jsxs)(r.AlertDialogContent,{className:`max-w-lg`,children:[(0,s.jsx)(r.AlertDialogHeader,{children:(0,s.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,s.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,s.jsx)(i.AlertTriangle,{className:`h-5 w-5`})}),(0,s.jsxs)(`div`,{className:`flex-1`,children:[(0,s.jsx)(r.AlertDialogTitle,{children:l(`detail.concurrentUpdateTitle`)}),(0,s.jsxs)(r.AlertDialogDescription,{className:`mt-1`,children:[g,(0,s.jsx)(`strong`,{className:`font-semibold`,children:u}),_]})]})]})}),(0,s.jsxs)(`div`,{className:`space-y-2 text-sm`,children:[(0,s.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,s.jsx)(`div`,{className:`text-xs font-medium uppercase tracking-wide text-amber-800 dark:text-amber-300`,children:l(`detail.concurrentUpdateYourEdit`)}),(0,s.jsx)(`div`,{className:`mt-1 break-all font-mono text-foreground`,children:d})]}),(0,s.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,s.jsxs)(`div`,{className:`flex items-baseline justify-between gap-2`,children:[(0,s.jsx)(`div`,{className:`text-xs font-medium uppercase tracking-wide text-sky-800 dark:text-sky-300`,children:l(`detail.concurrentUpdateCurrentValue`)}),(m||h)&&(0,s.jsxs)(`div`,{className:`text-[11px] text-muted-foreground`,children:[m&&(0,s.jsx)(`span`,{children:l(`detail.concurrentUpdateUpdatedBy`,{name:m})}),m&&h&&(0,s.jsx)(`span`,{children:` · `}),h&&(0,s.jsx)(`span`,{children:l(`detail.concurrentUpdateUpdatedAt`,{when:h})})]})]}),(0,s.jsx)(`div`,{className:`mt-1 break-all font-mono text-foreground`,children:f})]})]}),(0,s.jsxs)(r.AlertDialogFooter,{className:`gap-2 sm:gap-2`,children:[(0,s.jsx)(`button`,{type:`button`,disabled:c,onClick:o,className:(0,r.cn)((0,r.buttonVariants)({variant:`ghost`}),`mt-2 sm:mt-0`),children:l(`detail.concurrentUpdateCancel`)}),(0,s.jsx)(`button`,{type:`button`,disabled:c,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:l(`detail.concurrentUpdateOverwrite`)}),(0,s.jsx)(`button`,{type:`button`,disabled:c,onClick:n,autoFocus:!0,className:(0,r.cn)((0,r.buttonVariants)({variant:`default`}),`mt-2 sm:mt-0`),children:l(`detail.concurrentUpdateReload`)})]})]})})};function me(e){if(!e||typeof e!=`object`)return!1;let t=e;return t.code===`CONCURRENT_UPDATE`||t.name===`ConcurrentUpdateError`}var he=e=>typeof e==`string`?e:e&&typeof e==`object`&&(e.field||e.name)||null,ge=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}},X=({schema:e={},className:t,...r})=>{let i=(0,a.useRecordContext)(),{designer:o}=ge(r),l=i?.objectName||``,u=(0,c.usePermissions)(),{readableFields:d}=(0,c.useFieldPermissions)(l),{sectionLabel:f}=(0,a.useSafeFieldLabel)(),p=(0,a.useHighlightFieldNames)(),[m,h]=n.default.useState(null),[g,_]=n.default.useState(!1),v=n.default.useCallback(t=>{let n=[...Array.isArray(e.fields)?e.fields:[],...(Array.isArray(e.sections)?e.sections:[]).flatMap(e=>Array.isArray(e?.fields)?e.fields:[])];for(let e of n)if((typeof e==`string`?e:e?.name||e?.field)===t)return typeof e==`object`?e?.label:void 0},[e.fields,e.sections]),y=n.default.useCallback(async(e,t)=>{let n=i?.dataSource,r=i?.recordId,a=i?.objectName;if(!n||!r||!a)return;let o=typeof i?.data?.updated_at==`string`?(i?.data).updated_at:void 0,s=o?{ifMatch:o}:void 0;try{if(typeof n.update==`function`)await n.update(a,r,{[e]:t},s);else if(typeof n.updateOne==`function`)await n.updateOne(a,r,{[e]:t},s);else if(typeof n.patch==`function`)await n.patch(a,r,{[e]:t},s);else{console.warn(`[record:details] DataSource exposes no update/updateOne/patch method; cannot persist inline edit`);return}typeof i?.refresh==`function`&&await i.refresh()}catch(n){if(me(n)){let r=n.currentRecord??null;throw h({field:e,label:v(e),pendingValue:t,currentValue:r?r[e]:void 0,currentVersion:n.currentVersion,currentRecord:r}),n}throw console.error(`[record:details] Inline-edit save failed`,n),n}},[i?.dataSource,i?.recordId,i?.objectName,i?.data,i?.refresh,v]),b=n.default.useCallback(()=>{h(null),_(!1)},[]),x=n.default.useCallback(async()=>{_(!0);try{typeof i?.refresh==`function`&&await i.refresh()}finally{b()}},[i?.refresh,b]),S=n.default.useCallback(async()=>{if(!m){b();return}let e=i?.dataSource,t=i?.recordId,n=i?.objectName;if(!e||!t||!n){b();return}_(!0);try{let r=m.currentVersion?{ifMatch:m.currentVersion}:void 0;typeof e.update==`function`?await e.update(n,t,{[m.field]:m.pendingValue},r):typeof e.updateOne==`function`?await e.updateOne(n,t,{[m.field]:m.pendingValue},r):typeof e.patch==`function`&&await e.patch(n,t,{[m.field]:m.pendingValue},r),typeof i?.refresh==`function`&&await i.refresh()}catch(e){console.error(`[record:details] Overwrite-on-conflict failed`,e)}finally{b()}},[m,i?.dataSource,i?.recordId,i?.objectName,i?.refresh,b]);if(!i)return(0,s.jsx)(`div`,{className:t,"data-record-details-placeholder":!0,...o,children:(0,s.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 C=Array.isArray(e.requiredPermissions)?e.requiredPermissions:[];if(C.length>0&&l&&!C.every(e=>u.can(l,e)))return(0,s.jsx)(`div`,{className:t,...o,role:`status`,"aria-live":`polite`,children:(0,s.jsx)(`p`,{className:`text-sm text-muted-foreground italic`,children:`Insufficient permissions to view details.`})});let w=e.layout===`inline`||e.layout===`compact`?`horizontal`:`vertical`,T=e.enforceFieldSecurity===!0,E=Array.isArray(e.redactFields)?e.redactFields:[],D=e=>{if(!e||!T&&E.length===0)return e;let t=e.map(he).filter(e=>!!e),n=new Set((T&&l?d(t):t).filter(e=>!E.includes(e)));return e.filter(e=>{let t=he(e);return t?n.has(t):!0})},O=e=>typeof e==`string`?{name:e}:e&&typeof e==`object`&&!e.name&&e.field?{...e,name:e.field}:e,k=e=>Array.isArray(e)?e.map(O):e,A=new Set((Array.isArray(e.hideFields)?e.hideFields:[]).map(e=>typeof e==`string`?e:he(e)).filter(e=>!!e));for(let e of p)A.add(e);let j=i.objectSchema,M=i.data??{},N=[j?.primaryField,`name`,`full_name`,`title`,`subject`,`display_name`,`label`].filter(e=>typeof e==`string`&&e.length>0);for(let e of N)if(M[e]!==void 0&&M[e]!==null&&M[e]!==``){A.add(e);break}let P=e=>!e||A.size===0?e:e.filter(e=>{let t=he(e);return t?!A.has(t):!0}),F=P(k(D(e.fields))),I=Array.isArray(e.sections)?e.sections.map(e=>{let t=e.title??e.label,n=e.name&&l?f(l,e.name,t??e.name):t;return{...e,title:n,showBorder:e.showBorder??!!n,hideEmpty:e.hideEmpty??!0,fields:P(k(D(e.fields)))}}):e.sections,L=e.inlineEdit??!0,R={type:`detail-view`,objectName:i.objectName,resourceId:i.recordId,data:i.data,layout:w,columns:e.columns,sections:I,fields:F,showBack:!1,showHeader:e.showHeader??!1,inlineEdit:L};return(0,s.jsxs)(`div`,{className:t,...o,children:[(0,s.jsx)(de,{schema:R,dataSource:i.dataSource,inlineEdit:L,onFieldSave:y}),(0,s.jsx)(Y,{open:!!m,conflict:m,busy:g,onCancel:b,onReload:x,onOverwrite:S})]})},_e=e=>typeof e==`string`?e:e&&typeof e==`object`&&(e.field||e.name||e.key)||null,ve=e=>e?.id??e?._id??null,ye=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}},be=({schema:e={},className:t,...r})=>{let i=(0,a.useRecordContext)(),{designer:l}=ye(r),u=(0,a.useSafeFieldLabel)(),d=e.objectName,f=d&&u.objectLabel?u.objectLabel({name:d,label:(0,o.humanizeLabel)(d)}):d?(0,o.humanizeLabel)(d):``,p=e.title||f||`Related`;if(!d)return(0,s.jsx)(`div`,{className:t,...l,children:(0,s.jsx)(`div`,{className:`text-xs text-muted-foreground italic px-3 py-2 border border-dashed rounded`,children:`record:related_list — missing objectName`})});let m=(0,c.usePermissions)(),{readableFields:h}=(0,c.useFieldPermissions)(d),g=(0,a.useRelatedRecordActions)(),_=n.default.useMemo(()=>g?.resolve({objectName:d,relationshipField:e.relationshipField,parentId:i?.recordId??null})??null,[g,d,e.relationshipField,i?.recordId]),v=Array.isArray(e.requiredPermissions)?e.requiredPermissions:[];if(v.length>0&&!v.every(e=>m.can(d,e)))return(0,s.jsx)(`div`,{className:t,...l,role:`status`,"aria-live":`polite`,children:(0,s.jsx)(`p`,{className:`text-sm text-muted-foreground italic`,children:`Insufficient permissions to view related list.`})});let y=e.enforceFieldSecurity===!0,b=Array.isArray(e.redactFields)?e.redactFields:[],x=Array.isArray(e.columns)?e.columns:[],S=x;if(y||b.length>0){let e=x.map(_e).filter(e=>!!e),t=new Set((y?h(e):e).filter(e=>!b.includes(e)));S=x.filter(e=>{let n=_e(e);return n?t.has(n):!0})}return(0,s.jsx)(`div`,{className:t,...l,children:(0,s.jsx)(N,{title:p,type:`table`,api:d,objectName:d,referenceField:e.relationshipField,parentId:i?.recordId,columns:S,pageSize:e.limit,dataSource:i?.dataSource,add:e.add,rowActions:_?.rowActions,onRowAction:_?.onRowAction,onNew:_?.onCreate,onRowClick:_?.onView?e=>{let t=ve(e);t!=null&&_.onView(t,e)}:void 0,onRowEdit:_?.onEdit?e=>{let t=ve(e);t!=null&&_.onEdit(t,e)}:void 0,onRowDelete:_?.onDelete?e=>{let t=ve(e);if(t!=null)return _.onDelete(t,e)}:e.add&&i?.dataSource?async e=>{let t=e?.id??e?._id;t!=null&&await i.dataSource.delete?.(d,String(t))}:void 0})})},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}},Z=({schema:e={},className:t,...r})=>{let i=(0,a.useRecordContext)(),{designer:o}=xe(r),l=i?.objectName||``,u=(0,c.usePermissions)(),{readableFields:d}=(0,c.useFieldPermissions)(l),f=Array.isArray(e.requiredPermissions)?e.requiredPermissions:[];if(f.length>0&&l&&!f.every(e=>u.can(l,e)))return(0,s.jsx)(`div`,{className:t,...o,role:`status`,"aria-live":`polite`,children:(0,s.jsx)(`p`,{className:`text-sm text-muted-foreground italic`,children:`Insufficient permissions to view highlights.`})});let p=(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),m=e.enforceFieldSecurity===!0,h=Array.isArray(e.redactFields)?e.redactFields:[],g=m&&l?new Set(d(p.map(e=>e.name))):null,_=p.filter(e=>!(h.includes(e.name)||g&&!g.has(e.name)));return(0,a.useRegisterHighlightFields)(n.default.useId(),_.map(e=>e.name)),(0,s.jsx)(`div`,{className:t,...o,children:(0,s.jsx)(F,{fields:_,data:i?.data,objectName:i?.objectName,objectSchema:i?.objectSchema})})},Se=({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,s.jsxs)(`div`,{className:(0,r.cn)(`flex items-center gap-1.5 text-sm flex-wrap`,t),children:[(0,s.jsx)(`span`,{className:`font-medium text-foreground`,children:n}),(0,s.jsx)(`span`,{className:`text-muted-foreground line-through`,children:a}),(0,s.jsx)(i.ArrowRight,{className:`h-3 w-3 text-muted-foreground shrink-0`}),(0,s.jsx)(`span`,{className:`text-foreground`,children:o})]})},Ce=[`👍`,`❤️`,`🎉`,`😂`,`😮`,`😢`],Q=({reactions:e,onToggleReaction:t,emojiOptions:a=Ce,className:o})=>{let[c,l]=n.useState(!1),u=n.useCallback(e=>{t?.(e),l(!1)},[t]);return(0,s.jsxs)(`div`,{className:(0,r.cn)(`flex items-center gap-1 flex-wrap`,o),children:[e.map(e=>(0,s.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,s.jsx)(`span`,{children:e.emoji}),(0,s.jsx)(`span`,{children:e.count})]},e.emoji)),t&&(0,s.jsxs)(`div`,{className:`relative`,children:[(0,s.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-6 w-6`,onClick:()=>l(!c),"aria-label":`Add reaction`,children:(0,s.jsx)(i.SmilePlus,{className:`h-3.5 w-3.5`})}),c&&(0,s.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,s.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 $(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 we=({parentItem:e,replies:t,onAddReply:a,showReplyInput:o=!0,className:c})=>{let{t:l}=E(),[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,s.jsxs)(`div`,{className:(0,r.cn)(`ml-10 mt-1`,c),children:[t.length>0&&(0,s.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,s.jsx)(i.ChevronDown,{className:`h-3 w-3`}):(0,s.jsx)(i.ChevronRight,{className:`h-3 w-3`}),(0,s.jsx)(i.MessageSquare,{className:`h-3 w-3`}),(0,s.jsx)(`span`,{children:t.length===1?l(`detail.replyCount`,{count:t.length}):l(`detail.replyCountPlural`,{count:t.length})})]}),u&&(0,s.jsx)(`div`,{className:`space-y-2 border-l-2 border-border pl-3`,children:t.map(e=>(0,s.jsxs)(`div`,{className:`flex gap-2`,children:[(0,s.jsx)(`div`,{className:`shrink-0`,children:e.actorAvatarUrl?(0,s.jsx)(`img`,{src:e.actorAvatarUrl,alt:e.actor,className:`h-6 w-6 rounded-full object-cover`}):(0,s.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,s.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,s.jsx)(`span`,{className:`text-xs font-medium`,children:e.actor}),(0,s.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:$(e.createdAt,l)})]}),(0,s.jsx)(`p`,{className:`text-xs whitespace-pre-wrap break-words`,children:e.body})]})]},e.id))}),o&&a&&(0,s.jsxs)(`div`,{className:`flex gap-1.5 mt-1.5`,children:[(0,s.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:l(`detail.replyPlaceholder`),value:f,onChange:e=>p(e.target.value),onKeyDown:_,disabled:m}),(0,s.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,s.jsx)(i.Send,{className:`h-3 w-3`})})]})]})},Te=({subscription:e,onToggle:t,className:a})=>{let{t:o}=E(),[c,l]=n.useState(!1),u=n.useCallback(async()=>{if(t){l(!0);try{await t(!e.subscribed)}finally{l(!1)}}},[t,e.subscribed]);return(0,s.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:(0,r.cn)(`h-8 w-8`,a),onClick:u,disabled:c||!t,"aria-label":e.subscribed?o(`detail.unsubscribeAriaLabel`):o(`detail.subscribeAriaLabel`),title:e.subscribed?o(`detail.subscribedTooltip`):o(`detail.unsubscribedTooltip`),children:e.subscribed?(0,s.jsx)(i.Bell,{className:`h-4 w-4 text-primary`}):(0,s.jsx)(i.BellOff,{className:`h-4 w-4 text-muted-foreground`})})};function Ee(e){let t=e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).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 De=({value:e,onChange:t,onSubmit:a,mentionSuggestions:o=[],placeholder:c,className:l,disabled:u=!1,extraSlot:d,canSubmitEmpty:f=!1})=>{let{t:p}=E(),[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]),D=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,s.jsxs)(`div`,{className:(0,r.cn)(`border rounded-md`,l),children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-0.5 px-2 py-1.5 border-b bg-muted/30`,children:[(0,s.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:T,disabled:u||m,title:p(`detail.bold`),children:(0,s.jsx)(i.Bold,{className:`h-3.5 w-3.5`})}),(0,s.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:D,disabled:u||m,title:p(`detail.italic`),children:(0,s.jsx)(i.Italic,{className:`h-3.5 w-3.5`})}),(0,s.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:O,disabled:u||m,title:p(`detail.listFormat`),children:(0,s.jsx)(i.List,{className:`h-3.5 w-3.5`})}),(0,s.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:k,disabled:u||m,title:p(`detail.inlineCode`),children:(0,s.jsx)(i.Code,{className:`h-3.5 w-3.5`})}),(0,s.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:A,disabled:u||m,title:p(`detail.mentionSomeone`),children:(0,s.jsx)(i.AtSign,{className:`h-3.5 w-3.5`})}),(0,s.jsx)(`div`,{className:`flex-1`}),(0,s.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,s.jsx)(i.Edit,{className:`h-3.5 w-3.5`}):(0,s.jsx)(i.Eye,{className:`h-3.5 w-3.5`})}),a&&(0,s.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,s.jsx)(i.Send,{className:`h-3.5 w-3.5`})})]}),(0,s.jsx)(`div`,{className:`relative`,children:m?(0,s.jsx)(`div`,{className:`min-h-[80px] px-3 py-2 text-sm prose prose-sm max-w-none`,dangerouslySetInnerHTML:{__html:Ee(e)}}):(0,s.jsxs)(s.Fragment,{children:[(0,s.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:c??p(`detail.writeComment`),value:e,onChange:M,onKeyDown:N,disabled:u}),g&&C.length>0&&(0,s.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,s.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,s.jsx)(`img`,{src:e.avatarUrl,alt:e.label,className:`h-5 w-5 rounded-full object-cover`}):(0,s.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,s.jsx)(`span`,{children:e.label})]},e.id))})]})}),d&&(0,s.jsx)(`div`,{className:`border-t px-2 py-2 bg-muted/20`,children:d})]})};function Oe(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function ke(e){return e.startsWith(`image/`)}function Ae(e){return ke(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 je=({attachments:e,onUpload:t,onRemove:a,className:o,readOnly:c=!1})=>{let{t:l}=E(),[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,s.jsxs)(`div`,{className:(0,r.cn)(`space-y-2`,o),children:[t&&!c&&(0,s.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,s.jsx)(i.Upload,{className:`h-5 w-5 mx-auto text-muted-foreground mb-1`}),(0,s.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:l(`detail.dropFilesToUpload`)}),(0,s.jsx)(`input`,{ref:f,type:`file`,multiple:!0,className:`hidden`,onChange:g})]}),e.length>0&&(0,s.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,s.jsx)(i.Paperclip,{className:`h-3 w-3`}),(0,s.jsx)(`span`,{children:e.length===1?l(`detail.attachmentCount`,{count:e.length}):l(`detail.attachmentCountPlural`,{count:e.length})})]}),(0,s.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2`,children:e.map(e=>{let t=ke(e.type),n=Ae(e.type);return(0,s.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,s.jsx)(`img`,{src:e.thumbnailUrl||e.url,alt:e.name,className:`h-10 w-10 rounded object-cover shrink-0`}):(0,s.jsx)(`div`,{className:`h-10 w-10 rounded bg-muted flex items-center justify-center shrink-0`,children:(0,s.jsx)(n,{className:`h-5 w-5 text-muted-foreground`})}),(0,s.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,s.jsx)(`p`,{className:`text-xs font-medium truncate`,children:e.name}),(0,s.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:Oe(e.size)})]}),a&&!c&&(0,s.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:l(`detail.removeAttachment`),children:(0,s.jsx)(i.X,{className:`h-3.5 w-3.5`})})]},e.id)})})]})]})},Me={comment:i.MessageSquare,field_change:i.Edit,task:i.CheckSquare,event:i.Calendar,system:i.Zap,email:i.Mail,call:i.Phone},Ne={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`};function Pe(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 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}}function Ie(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 Le=({items:e,config:t,filterMode:a,onFilterChange:o,hasMore:c=!1,onLoadMore:l,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}=E(),[C,w]=n.useState(`all`),[T,D]=n.useState(``),[O,k]=n.useState(!1),[A,j]=n.useState(!1),[M,N]=n.useState([]),[P,F]=n.useState(!1),I=a??C,L=t?.showFilterToggle!==!1,R=t?.showCommentInput!==!1&&!!d,z=t?.enableReactions??!1,B=t?.enableThreading??!1,V=t?.showSubscriptionToggle??!1,H=n.useMemo(()=>Ie(e,I),[e,I]),U=n.useMemo(()=>B?H.filter(e=>!e.parentId):H,[H,B]),W=n.useMemo(()=>{if(!B)return new Map;let e=new Map;for(let t of H)if(t.parentId){let n=e.get(t.parentId)??[];n.push(t),e.set(t.parentId,n)}return e},[H,B]),G=n.useCallback(e=>{o?o(e):w(e)},[o]),ee=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),D(``),N([])}finally{k(!1)}}},[T,M,d]),K=n.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]),te=n.useCallback(e=>{N(t=>t.filter(t=>t.id!==e))},[]),q=n.useCallback(async()=>{if(l){j(!0);try{await l()}finally{j(!1)}}},[l]);return(0,s.jsxs)(`section`,{className:(0,r.cn)(`border-t border-border/60 pt-5`,x),"aria-label":`Discussion`,children:[(0,s.jsx)(`header`,{className:`mb-4`,children:(0,s.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,s.jsxs)(`h2`,{className:`flex items-center gap-2 text-base font-semibold leading-none tracking-tight`,children:[(0,s.jsx)(i.Activity,{className:`h-4 w-4`}),y??S(`detail.activity`),(0,s.jsxs)(`span`,{className:`text-sm font-normal text-muted-foreground`,children:[`(`,H.length,`)`]})]}),(0,s.jsx)(`div`,{className:`flex items-center gap-1`,children:V&&m&&(0,s.jsx)(Te,{subscription:m,onToggle:h})})]})}),(0,s.jsxs)(`div`,{className:`space-y-4`,children:[L&&(0,s.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,s.jsxs)(r.Select,{value:I,onValueChange:e=>G(e),children:[(0,s.jsx)(r.SelectTrigger,{"aria-label":S(`detail.filterActivity`),className:`h-8 w-auto min-w-[140px] py-1 text-sm`,children:(0,s.jsx)(r.SelectValue,{})}),(0,s.jsx)(r.SelectContent,{children:Pe(S).map(e=>(0,s.jsx)(r.SelectItem,{value:e.value,children:e.label},e.value))})]})}),R&&(0,s.jsx)(De,{value:T,onChange:D,onSubmit:ee,mentionSuggestions:_,placeholder:S(`detail.leaveCommentPlaceholder`),disabled:O,canSubmitEmpty:M.length>0,extraSlot:v?(0,s.jsx)(je,{attachments:M,onUpload:K,onRemove:te,readOnly:O||P}):M.length>0?(0,s.jsx)(je,{attachments:M,onRemove:te,readOnly:O}):void 0}),H.length===0?g?null:(0,s.jsx)(r.DataEmptyState,{title:b??S(`detail.noActivity`),className:`py-6`}):(0,s.jsxs)(`div`,{className:`relative`,children:[(0,s.jsx)(`div`,{className:`absolute left-4 top-2 bottom-2 w-px bg-border`}),(0,s.jsx)(`div`,{className:`space-y-4`,children:U.map(e=>{let t=Me[e.type]||i.Zap,n=Ne[e.type]||`bg-gray-100 text-gray-600`,a=W.get(e.id)??[];return(0,s.jsxs)(`div`,{children:[(0,s.jsxs)(`div`,{className:`flex gap-3 relative`,children:[(0,s.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,s.jsx)(`img`,{src:e.actorAvatarUrl,alt:e.actor,className:`h-8 w-8 rounded-full object-cover`}):(0,s.jsx)(t,{className:`h-3.5 w-3.5`})}),(0,s.jsxs)(`div`,{className:`flex-1 min-w-0 pt-1`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-2 mb-0.5`,children:[(0,s.jsx)(`span`,{className:`text-sm font-medium`,children:e.actor}),e.source&&(0,s.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:S(`detail.via`,{source:e.source})}),(0,s.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:Fe(e.createdAt,S)}),e.edited&&(0,s.jsx)(`span`,{className:`text-xs text-muted-foreground italic`,children:S(`detail.edited`)}),e.pinned&&(0,s.jsxs)(`span`,{className:`text-xs text-amber-600`,children:[`📌 `,S(`detail.pinned`)]})]}),e.body&&(0,s.jsx)(`p`,{className:`text-sm whitespace-pre-wrap break-words text-muted-foreground`,children:e.body}),e.sourceObject&&e.sourceId!=null&&(0,s.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,s.jsx)(`span`,{"aria-hidden":!0,children:`→`})]}),e.type===`field_change`&&e.fieldChanges&&(0,s.jsx)(`div`,{className:`space-y-1 mt-1`,children:e.fieldChanges.map((e,t)=>(0,s.jsx)(Se,{change:e},t))}),z&&e.reactions&&e.reactions.length>0&&(0,s.jsx)(`div`,{className:`mt-1.5`,children:(0,s.jsx)(Q,{reactions:e.reactions,onToggleReaction:p?t=>p(e.id,t):void 0})}),z&&(!e.reactions||e.reactions.length===0)&&p&&(0,s.jsx)(`div`,{className:`mt-1.5`,children:(0,s.jsx)(Q,{reactions:[],onToggleReaction:t=>p(e.id,t)})})]})]}),B&&(e.replyCount??0)>0&&(0,s.jsx)(we,{parentItem:e,replies:a,onAddReply:f,showReplyInput:!!f})]},e.id)})})]}),c&&(0,s.jsx)(`div`,{className:`text-center pt-2`,children:(0,s.jsxs)(r.Button,{variant:`ghost`,size:`sm`,onClick:q,disabled:A,"aria-label":S(`detail.loadMore`),children:[A?(0,s.jsx)(i.Loader2,{className:`h-4 w-4 animate-spin mr-1`}):(0,s.jsx)(i.ChevronDown,{className:`h-4 w-4 mr-1`}),S(`detail.loadMore`)]})})]})]})},Re=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}=Re(n);return(0,s.jsx)(`div`,{className:t,...r,children:(0,s.jsx)(Le,{items:[],config:e})})},Be=({config:e,items:t,hasMore:a,onLoadMore:o,loading:c,onAddComment:l,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}=E(),[T,D]=n.useState(C);return b===`right`||b===`left`?T&&S?(0,s.jsx)(`div`,{className:(0,r.cn)(`flex items-start pt-4`,b===`right`?`border-l`:`border-r`,y),children:(0,s.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-8 w-8 mx-1`,onClick:()=>D(!1),"aria-label":w(`detail.openDiscussion`),children:(0,s.jsx)(i.PanelRightOpen,{className:`h-4 w-4`})})}):(0,s.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,s.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,s.jsx)(i.MessageSquare,{className:`h-4 w-4`}),(0,s.jsx)(`span`,{className:`text-sm font-medium`,children:w(`detail.discussion`)})]}),S&&(0,s.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:()=>D(!0),"aria-label":w(`detail.closeDiscussion`),children:(0,s.jsx)(i.X,{className:`h-3.5 w-3.5`})})]}),(0,s.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:(0,s.jsx)(Le,{items:t,config:e?.feed,hasMore:a,onLoadMore:o,loading:c,onAddComment:l,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,s.jsx)(`div`,{className:(0,r.cn)(``,y),children:S&&T?(0,s.jsxs)(r.Button,{variant:`ghost`,className:`w-full justify-start gap-2 text-muted-foreground`,onClick:()=>D(!1),"aria-label":w(`detail.showDiscussion`,{count:t.length}),children:[(0,s.jsx)(i.MessageSquare,{className:`h-4 w-4`}),(0,s.jsx)(`span`,{children:w(`detail.showDiscussion`,{count:t.length})})]}):(0,s.jsxs)(`div`,{children:[S&&(0,s.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium`,children:[(0,s.jsx)(i.MessageSquare,{className:`h-4 w-4`}),w(`detail.discussion`)]}),(0,s.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:()=>D(!0),"aria-label":w(`detail.hideDiscussion`),children:(0,s.jsx)(i.PanelRightClose,{className:`h-3.5 w-3.5`})})]}),(0,s.jsx)(Le,{items:t,config:e?.feed,hasMore:a,onLoadMore:o,loading:c,onAddComment:l,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`)})]})})},Ve=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}},He=({schema:e={},className:t,...n})=>{(0,a.useRecordContext)();let r=(0,a.useDiscussionContext)(),{designer:i}=Ve(n),o={position:`bottom`,collapsible:!1,feed:{enableReactions:!0,enableThreading:!0,showCommentInput:!0},...e};return(0,s.jsx)(`div`,{className:t,...i,children:(0,s.jsx)(Be,{items:r?.items||[],config:o,onAddComment:r?.onAddComment,onAddReply:r?.onAddReply,onToggleReaction:r?.onToggleReaction,mentionSuggestions:r?.mentionSuggestions,onUploadAttachments:r?.onUploadAttachments})})},Ue=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:t,...i})=>{let o=(0,a.useRecordContext)(),{translateOptions:c}=(0,a.useSafeFieldLabel)(),{designer:l}=Ue(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=c(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,c]),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,s.jsx)(`div`,{className:t,...l,children:(0,s.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,s.jsxs)(`div`,{className:(0,r.cn)(`w-full`,t),...l,children:[(0,s.jsxs)(`div`,{className:`hidden sm:flex w-full items-stretch gap-2`,role:`list`,"aria-label":e.aria?.label||`Record path`,children:[(0,s.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,s.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,s.jsxs)(`span`,{className:`inline-flex items-center justify-center gap-1.5 truncate`,children:[n&&(0,s.jsx)(`span`,{"aria-hidden":!0,className:`text-emerald-600 dark:text-emerald-400 font-semibold`,children:`✓`}),a&&!i&&(0,s.jsx)(`span`,{"aria-hidden":!0,className:`opacity-70`,children:`🏆`}),e.label]})},`${e.value}-${t}`)})}),y.length>0&&(0,s.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,s.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,s.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,s.jsx)(`span`,{"aria-hidden":!0,className:`opacity-70`,children:`✗`}),e.label]})},`${e.value}-lost-${t}`)})})]}),(0,s.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,s.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,s.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[n&&(0,s.jsx)(`span`,{"aria-hidden":!0,className:`opacity-70`,children:`✗`}),!n&&i&&(0,s.jsx)(`span`,{"aria-hidden":!0,className:`text-emerald-600 dark:text-emerald-400 font-semibold`,children:`✓`}),e.label]})},`${e.value}-${t}-m`)})})]})},Ge=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,...n})=>{let i=(0,a.useRecordContext)(),{designer:o}=Ge(n),l=(0,c.usePermissions)(),u=Array.isArray(e.actions)?e.actions:Array.isArray(e.properties?.actions)?e.properties.actions:[],d=Array.isArray(e.actionNames)?e.actionNames:Array.isArray(e.properties?.actionNames)?e.properties.actionNames:[],f=i?.objectName||``,p=d.length>0?d:Array.isArray(u)&&u.every(e=>typeof e==`string`)?u:[],m=p.length>0&&!!f,{item:h}=(0,a.useMetadataItem)(`object`,m?f:null),g=m?(()=>{let e=Array.isArray(h?.actions)?h.actions:[],t=new Map(e.map(e=>[e.name,e]));return p.map(e=>t.get(e)).filter(e=>!!e)})():Array.isArray(u)?u:[],_=Array.isArray(e.requiredPermissions)?e.requiredPermissions:[];if(_.length>0&&f&&!_.every(e=>l.can(f,e)))return(0,s.jsx)(`div`,{className:t,...o,role:`status`,"aria-live":`polite`,children:(0,s.jsx)(`p`,{className:`text-sm text-muted-foreground italic`,children:`Insufficient permissions to view quick actions.`})});let v=e.location||`record_header`,{getActionsForLocation:y,executeAction:b}=(0,a.useActionEngine)({actions:g,context:{record:i?.data,recordId:i?.recordId,objectName:i?.objectName}}),x=g.length>0?y(v):[];if(x.length===0)return(0,s.jsx)(`div`,{className:t,...o,children:(0,s.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 S=e.align||`end`,C=S===`start`?`justify-start`:S===`center`?`justify-center`:`justify-end`;return(0,s.jsx)(`div`,{className:(0,r.cn)(`flex flex-wrap items-center gap-2`,v===`record_header`&&!e.inline&&`-mt-12 sm:-mt-14 mb-2 relative z-10`,C,t),role:`toolbar`,"aria-label":e.aria?.label||`Quick actions`,...o,children:x.map((t,n)=>(0,s.jsx)(qe,{action:t,record:i?.data,variant:t.variant||e.variant||`default`,size:t.size||e.size||`sm`,label:t.label||t.name||`Action ${n+1}`,onRun:async()=>{typeof t.onClick==`function`?await t.onClick():t.name&&await b(t.name)}},t.name||`qa-${n}`))})};function qe({action:e,record:t,variant:o,size:c,label:l,onRun:u}){let[d,f]=n.default.useState(!1),p=n.default.useMemo(()=>({record:t||{}}),[t]),m=(0,a.toPredicateInput)(e.disabled),h=(0,a.useCondition)(typeof m==`string`?m:void 0,p);return(0,s.jsxs)(r.Button,{variant:o,size:c,disabled:(typeof m==`string`?h:m===!0)||d,onClick:async()=>{f(!0);try{await u()}finally{f(!1)}},children:[d&&(0,s.jsx)(i.Loader2,{className:`mr-2 h-4 w-4 animate-spin`}),l]})}var 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}},Ye=new Set([`created`,`updated`,`assigned`,`shared`,`deleted`]),Xe=({schema:e={},className:t,...r})=>{let{designer:i}=Je(r),o=(0,a.useRecordContext)(),c=Array.isArray(e.entries)?e.entries:Array.isArray(e.properties?.entries)?e.properties.entries:void 0,l=e.loading??e.properties?.loading,u=e.emptyText??e.properties?.emptyText,d=Number(e.limit??e.properties?.limit??50)||50,f=o?.objectName,p=o?.data?.id??o?.data?._id??o?.recordId,m=o?.dataSource,h=c===void 0&&!!m?.find&&!!f&&p!=null,[g,_]=n.default.useState(null),[v,y]=n.default.useState(!1);n.default.useEffect(()=>{if(!h)return;let e=!1;return y(!0),Promise.resolve(m.find(`sys_activity`,{$filter:{object_name:f,record_id:p},$orderby:{timestamp:`desc`},$top:Math.max(1,d)})).then(t=>{e||_((t?.data??t?.records??[]).filter(e=>Ye.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}}))}).catch(()=>{e||_([])}).finally(()=>{e||y(!1)}),()=>{e=!0}},[h,m,f,p,d]);let b=c??g??[],x=l??(h&&g===null?v||!0:!1);return(0,s.jsx)(`div`,{className:t,...i,children:(0,s.jsx)(ne,{entries:b,loading:x,emptyText:u})})},Ze=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}},Qe=e=>e.replace(/[_-]+/g,` `).replace(/\b\w/g,e=>e.toUpperCase()).trim(),$e=(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||`—`,et=({schema:e={},className:t,...o})=>{let c=(0,a.useRecordContext)(),l=(0,a.useSafeFieldLabel)(),{t:d}=E(),{designer:f}=Ze(o),p=(0,u.useParams)().appName,m=Array.isArray(e.entries)?e.entries:Array.isArray(e.properties?.entries)?e.properties.entries:[],h=c?.recordId,g=c?.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}`));if(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]),m.length===0)return null;let T=e.hideEmpty!==!1,[D,O]=n.default.useState(!1),k=new Set(m.filter(e=>{let t=_[e.objectName];return T&&t&&!t.loading&&!t.error&&t.total===0}).map(e=>e.objectName)),A=m.filter(e=>D||!k.has(e.objectName)),j=m.filter(e=>k.has(e.objectName)).map(e=>e.title||(l?.objectLabel?l.objectLabel({name:e.objectName,label:Qe(e.objectName)}):Qe(e.objectName)));return(0,s.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,s.jsxs)(r.Card,{className:`overflow-hidden`,children:[(0,s.jsxs)(r.CardHeader,{className:`flex flex-row items-center justify-between gap-2 py-3 px-4 space-y-0 border-b`,children:[(0,s.jsx)(r.CardTitle,{className:`text-sm font-semibold tracking-tight truncate`,children:e.title||(l?.objectLabel?l.objectLabel({name:e.objectName,label:Qe(e.objectName)}):Qe(e.objectName))}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[!n.loading&&(0,s.jsx)(r.Badge,{variant:`secondary`,className:`tabular-nums`,children:n.total}),p&&h&&(0,s.jsx)(u.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,s.jsx)(r.CardContent,{className:`p-0`,children:n.loading?(0,s.jsxs)(`div`,{className:`space-y-1.5 p-3`,children:[(0,s.jsx)(r.Skeleton,{className:`h-3.5 w-4/5`}),(0,s.jsx)(r.Skeleton,{className:`h-3.5 w-3/5`}),(0,s.jsx)(r.Skeleton,{className:`h-3.5 w-2/3`})]}):n.items.length===0?(0,s.jsx)(`p`,{className:`px-4 py-3 text-xs text-muted-foreground`,children:d(`detail.noRecords`)}):(0,s.jsx)(`ul`,{className:`divide-y`,children:n.items.map(t=>{let n=t.id||t._id,r=$e(t,e.displayField),a=n?`../${e.objectName}/record/${encodeURIComponent(String(n))}`:void 0;return(0,s.jsx)(`li`,{className:`px-4 py-2`,children:a?(0,s.jsxs)(u.Link,{to:a,className:`group flex items-center justify-between gap-2 text-xs hover:text-foreground text-muted-foreground transition-colors`,children:[(0,s.jsx)(`span`,{className:`truncate`,children:r}),(0,s.jsx)(i.ChevronRight,{className:`h-3 w-3 shrink-0 opacity-0 group-hover:opacity-100 transition-opacity`})]}):(0,s.jsx)(`span`,{className:`block truncate text-xs text-muted-foreground`,children:r})},String(n||r))})})})]},t)}),!D&&j.length>0&&(0,s.jsxs)(`button`,{type:`button`,onClick:()=>O(!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,s.jsx)(`span`,{children:d(`detail.showEmptyRelated`,{defaultValue:`+ {{count}} empty`,count:j.length})}),(0,s.jsxs)(`span`,{className:`truncate max-w-[180px] text-muted-foreground/70`,children:[`(`,j.join(` · `),`)`]})]})]})},tt={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 nt(e){let t=e?.properties??{};return{...e,...t}}var rt=({schema:e={},className:t})=>{let i=nt(e),o=(0,a.useRecordContext)(),c=o?.data,l=o?.objectName||``,u=o?.recordId??c?.id,d=[`info`,`warning`,`error`,`success`].includes(i.severity)?i.severity:`info`,f=tt[d],p=i.icon||f.icon,m=(0,a.toPredicateInput)(i.visible),h=(0,a.useCondition)(m,{record:c}),g=n.useMemo(()=>{if(!i.dismissible)return null;let e=i.dismissKey||i.title||d;return`os.record-alert:${l}:${u??`_`}:${e}`},[i.dismissible,i.dismissKey,i.title,d,l,u]),[_,v]=n.useState(()=>{if(!g||typeof window>`u`)return!1;try{return window.localStorage.getItem(g)===`1`}catch{return!1}}),y=i.action?.actionName,{item:b}=(0,a.useMetadataItem)(`object`,y&&l?l:null),x=n.useMemo(()=>{if(!(!y||!b?.actions))return b.actions.find(e=>e.name===y)},[y,b]),{executeAction:S}=(0,a.useActionEngine)({actions:n.useMemo(()=>x?[x]:[],[x]),context:{record:c,recordId:u,objectName:l}});return _||!c||Object.keys(c).length===0||m!==void 0&&!h?null:(0,s.jsxs)(r.Alert,{className:(0,r.cn)(`relative pr-12`,f.wrap,t),role:d===`error`?`alert`:`status`,"aria-live":d===`error`?`assertive`:`polite`,children:[(0,s.jsx)(r.LazyIcon,{name:p,className:`h-4 w-4`,"aria-hidden":`true`}),i.title?(0,s.jsx)(r.AlertTitle,{children:i.title}):null,i.body||x?(0,s.jsxs)(r.AlertDescription,{children:[i.body?(0,s.jsx)(`p`,{className:`mb-2 last:mb-0`,children:i.body}):null,x?(0,s.jsx)(r.Button,{size:`sm`,variant:i.action?.variant||(d===`error`?`destructive`:`default`),onClick:()=>{x?.name&&S(x.name)},children:i.action?.label||x.label||x.name}):null]}):null,i.dismissible?(0,s.jsx)(`button`,{type:`button`,onClick:()=>{if(v(!0),g)try{window.localStorage.setItem(g,`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,s.jsx)(r.LazyIcon,{name:`X`,className:`h-4 w-4`,"aria-hidden":`true`})}):null]})},it=new Set([`id`,`_id`,`__v`,`created_at`,`updated_at`,`createdAt`,`updatedAt`,`created_by`,`updated_by`,`organization_id`,`tenant_id`,`owner_id`,`deleted_at`,`is_deleted`]),at=480,ot=95;function st({open:e,onClose:t,title:i,record:a,objectName:o,recordId:c,dataSource:l,objectSchema:u,width:d=`min(960px, 60vw)`,columns:f=2,systemFields:p=it,onFieldSave:m,onDelete:h,resizable:g=!0,fullPageHref:_}){let{t:v}=E(),y=`objectui.drawerWidth.${o}`,[b,x]=n.default.useState(()=>{if(typeof window>`u`||!g)return null;try{let e=window.localStorage.getItem(y);if(e){let t=parseInt(e,10);if(Number.isFinite(t)&&t>=at)return t}}catch{}return null}),S=n.default.useMemo(()=>g&&b!=null?`${b}px`:typeof d==`number`?`${d}px`:d,[g,b,d]),C=S?{width:S,maxWidth:S}:void 0,w=n.default.useRef(null),T=n.default.useCallback(e=>{if(!g)return;e.preventDefault();let t=b??(typeof window<`u`?Math.min(window.innerWidth*.6,960):720);w.current={startX:e.clientX,startWidth:t};let n=e=>{let t=w.current;if(!t)return;let n=t.startX-e.clientX,r=typeof window<`u`?window.innerWidth*ot/100:1600,i=Math.min(r,Math.max(at,t.startWidth+n));x(Math.round(i))},r=()=>{w.current,w.current=null,window.removeEventListener(`pointermove`,n),window.removeEventListener(`pointerup`,r),window.removeEventListener(`pointercancel`,r);try{x(e=>(e!=null&&window.localStorage.setItem(y,String(e)),e))}catch{}};window.addEventListener(`pointermove`,n),window.addEventListener(`pointerup`,r),window.addEventListener(`pointercancel`,r)},[g,b,y]),D=u?.fields??{},O=(Object.keys(D).length?Object.keys(D):Object.keys(a)).filter(e=>!p.has(e)&&!e.startsWith(`__`)).filter(e=>e in a).filter(e=>!D[e]?.hidden).map(e=>{let t=D[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.referenceTo??t.target,reference_field:t.reference_field??t.referenceField,required:t.required,validation:t.validation,placeholder:t.placeholder,description:t.description}});return(0,s.jsx)(r.Sheet,{open:e,onOpenChange:e=>{e||t()},children:(0,s.jsxs)(r.SheetContent,{side:`right`,className:`w-full overflow-y-auto p-0 sm:!max-w-none`,style:C,onOpenAutoFocus:e=>e.preventDefault(),children:[g&&(0,s.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize drawer`,onPointerDown:T,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,s.jsx)(r.SheetHeader,{className:`sr-only`,children:(0,s.jsx)(r.SheetTitle,{children:i})}),(0,s.jsx)(`div`,{className:`px-6 pt-6 pb-6`,children:(0,s.jsx)(de,{dataSource:l,inlineEdit:!0,schema:{type:`detail-view`,objectName:o,resourceId:String(c),data:a,showDelete:!0,columns:f,fields:O,actions:_?[{type:`action:bar`,location:`record_header`,systemActions:[{name:`sys_open_new_tab`,label:v(`detail.openInNewTab`),icon:`external-link`,type:`script`,onClick:()=>window.open(_,`_blank`,`noopener`)}]}]:void 0},onFieldSave:async(e,t)=>{try{await m?.(e,t)}catch(e){console.error(`[RecordDetailDrawer] inline field save failed:`,e)}},onDelete:async()=>{try{await h?.(),t()}catch(e){console.error(`[RecordDetailDrawer] delete failed:`,e)}}})})]})})}function ct(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 lt=({objectName:e,relationshipField:t,fields:a,onCreateRecord:o,onLinkRecord:c,onSearch:l,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),l&&e.trim().length>=2){T(!0);try{x(await l(e))}finally{T(!1)}}},[l]),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(c){C(!0);try{await c(e),y(``),p(!1)}finally{C(!1)}}},[c]),j=n.useMemo(()=>a.filter(e=>e.required).every(e=>g[e.name]?.toString().trim()),[a,g]);return f?(0,s.jsxs)(r.Card,{className:(0,r.cn)(``,d),children:[(0,s.jsx)(r.CardHeader,{className:`pb-3`,children:(0,s.jsxs)(r.CardTitle,{className:`flex items-center justify-between text-sm`,children:[(0,s.jsxs)(`span`,{children:[m===`create`?`Create`:`Link`,` `,e]}),(0,s.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-6 w-6`,onClick:()=>p(!1),children:(0,s.jsx)(i.X,{className:`h-3.5 w-3.5`})})]})}),(0,s.jsx)(r.CardContent,{children:(0,s.jsxs)(r.Tabs,{value:m,onValueChange:h,children:[(0,s.jsxs)(r.TabsList,{className:`mb-3 w-full`,children:[o&&(0,s.jsxs)(r.TabsTrigger,{value:`create`,className:`flex-1 gap-1.5`,children:[(0,s.jsx)(i.Plus,{className:`h-3.5 w-3.5`}),`Create New`]}),c&&(0,s.jsxs)(r.TabsTrigger,{value:`link`,className:`flex-1 gap-1.5`,children:[(0,s.jsx)(i.Link,{className:`h-3.5 w-3.5`}),`Link Existing`]})]}),o&&(0,s.jsxs)(r.TabsContent,{value:`create`,className:`space-y-3 mt-0`,children:[a.map(e=>(0,s.jsxs)(`div`,{children:[(0,s.jsxs)(`label`,{className:`text-xs font-medium text-muted-foreground mb-1 block`,children:[e.label,e.required&&(0,s.jsx)(`span`,{className:`text-destructive ml-0.5`,children:`*`})]}),(0,s.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,s.jsxs)(`div`,{className:`flex justify-end gap-2 pt-1`,children:[(0,s.jsx)(r.Button,{variant:`ghost`,size:`sm`,onClick:()=>p(!1),children:`Cancel`}),(0,s.jsxs)(r.Button,{size:`sm`,onClick:k,disabled:!j||S,className:`gap-1.5`,children:[S&&(0,s.jsx)(i.Loader2,{className:`h-3.5 w-3.5 animate-spin`}),`Create`]})]})]}),c&&(0,s.jsxs)(r.TabsContent,{value:`link`,className:`space-y-3 mt-0`,children:[(0,s.jsxs)(`div`,{className:`relative`,children:[(0,s.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,s.jsx)(r.Input,{placeholder:`Search ${e}…`,value:v,onChange:e=>D(e.target.value),className:`h-8 text-sm pl-8`})]}),(0,s.jsx)(`div`,{className:`max-h-48 overflow-y-auto space-y-1`,children:w?(0,s.jsxs)(`div`,{className:`flex items-center justify-center py-4 text-sm text-muted-foreground`,children:[(0,s.jsx)(i.Loader2,{className:`h-4 w-4 animate-spin mr-2`}),`Searching…`]}):E.length===0?(0,s.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,s.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,s.jsx)(`span`,{className:`font-medium`,children:e.label}),e.description&&(0,s.jsx)(`span`,{className:`block text-xs text-muted-foreground mt-0.5`,children:e.description})]},e.id))})]})]})})]}):(0,s.jsxs)(`div`,{className:(0,r.cn)(`flex gap-2`,d),children:[o&&(0,s.jsxs)(r.Button,{variant:`outline`,size:`sm`,onClick:()=>{h(`create`),p(!0)},className:`gap-1.5`,children:[(0,s.jsx)(i.Plus,{className:`h-3.5 w-3.5`}),`New `,e]}),c&&(0,s.jsxs)(r.Button,{variant:`outline`,size:`sm`,onClick:()=>{h(`link`),p(!0)},className:`gap-1.5`,children:[(0,s.jsx)(i.Link,{className:`h-3.5 w-3.5`}),`Link Existing`]})]})};function ut(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("react"),require("@object-ui/components"),require("lucide-react"),require("@object-ui/react"),require("@object-ui/fields"),require("react/jsx-runtime"),require("@object-ui/permissions"),require("@object-ui/i18n"),require("react-router-dom"),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`,`react/jsx-runtime`,`@object-ui/permissions`,`@object-ui/i18n`,`react-router-dom`,`@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.jsxRuntime,e._object_ui_permissions,e._object_ui_i18n,e.react_router_dom,e._objectstack_spec_data))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var f=Object.create,p=Object.defineProperty,m=Object.getOwnPropertyDescriptor,h=Object.getOwnPropertyNames,g=Object.getPrototypeOf,_=Object.prototype.hasOwnProperty,v=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=h(t),a=0,o=i.length,s;a<o;a++)s=i[a],!_.call(e,s)&&s!==n&&p(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=m(t,s))||r.enumerable});return e};n=((e,t,n)=>(n=e==null?{}:f(g(e)),v(t||!e||!e.__esModule?p(n,`default`,{value:e,enumerable:!0}):n,e)))(n,1);var y=new Set([`textarea`,`markdown`,`html`,`grid`,`rich-text`,`field:textarea`,`field:markdown`,`field:html`,`field:grid`,`field:rich-text`]);function b(e){return y.has(e)}function x(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 S(e,t){return t<=1?e:e.map(e=>e.span===void 0&&e.type&&b(e.type)?{...e,span:t}:e)}function C(e,t,n){if(t!==void 0)return{fields:S(e,t),columns:t};let r=x(e.length,n);return{fields:S(e,r),columns:r}}function w(e,t){return function(){try{let n=(0,a.useObjectTranslation)();return n.t(t)===t?{t:(t,n)=>{let r=e[t]||t;if(n)for(let[e,t]of Object.entries(n))r=r.replace(`{{${e}}}`,String(t));return r}}:{t:n.t}}catch{return{t:(t,n)=>{let r=e[t]||t;if(n)for(let[e,t]of Object.entries(n))r=r.replace(`{{${e}}}`,String(t));return r}}}}}var T={"detail.back":`Back`,"detail.edit":`Edit`,"detail.editInline":`Edit`,"detail.save":`Save`,"detail.saveChanges":`Save changes`,"detail.editFieldsInline":`Edit fields inline`,"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.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`},E=w(T,`detail.back`);function D(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 O=new Set([`formula`,`summary`,`rollup`,`auto_number`]);function k(e){if(e==null)return e;if(Array.isArray(e))return e.map(k);if(typeof e==`object`){let t=e;return t.id??t._id??t.value??``}return e}var A=({section:e,data:t,className:c,objectSchema:l,objectName:u,isEditing:d=!1,onFieldChange:f,dataSource:p,virtualScroll:m})=>{let[h,g]=n.useState(e.defaultCollapsed??!1),[_,v]=n.useState(null),[y,b]=n.useState(void 0),[x,S]=n.useState(!1),{t:w}=E(),{fieldLabel:T,translateOptions:A}=(0,a.useSafeFieldLabel)(),j=n.useCallback((e,t)=>{let n=t==null?``:String(t);navigator.clipboard.writeText(n).then(()=>{v(e),setTimeout(()=>v(null),2e3)})},[]),M=n.useCallback(e=>{let n=t?.[e.name]??e.value;return n==null||n===``},[t]),N=n.useMemo(()=>e.fields.filter(M).length,[e.fields,M]),P=(0,r.useIsMobile)(),F=P?3:4,I=P?.2:.25,L=e.fields.length-N,R=!e.hideEmpty&&!d&&e.fields.length>=F&&N/e.fields.length>=I&&L>0,z=!x&&(e.hideEmpty||R)?e.fields.filter(e=>!M(e)):e.fields,{fields:B,columns:ee}=C(z,e.columns),V=Math.min(ee,Math.max(1,z.length)),H=e=>{let n=t?.[e.name]??e.value;if(e.render)return(0,s.jsx)(a.SchemaRenderer,{schema:e.render,data:{...t,value:n}});let c=D(e.span,V),m=l?.fields?.[e.name],h={...e};if(m){!e.type&&m.type&&(h.type=m.type),m.options&&!h.options&&(h.options=m.options),m.currency&&!h.currency&&(h.currency=m.currency),m.precision!==void 0&&h.precision===void 0&&(h.precision=m.precision),m.scale!==void 0&&h.scale===void 0&&(h.scale=m.scale),m.format&&!h.format&&(h.format=m.format);let t=m.reference_to||m.reference;t&&!h.reference_to&&(h.reference_to=t),m.reference_field&&!h.reference_field&&(h.reference_field=m.reference_field),m.dueLike!==void 0&&h.dueLike===void 0&&(h.dueLike=m.dueLike)}u&&Array.isArray(h.options)&&h.options.length>0&&(h.options=A(u,e.name,h.options));let g=(()=>{if(n==null||n===``)return(0,s.jsx)(`span`,{className:`text-muted-foreground/60 text-sm select-none`,"aria-label":w(`detail.noValue`,{defaultValue:`No value`}),title:w(`detail.noValue`,{defaultValue:`No value`}),children:`—`});let t=(0,o.resolveCellRendererType)(h)||e.type;if(t){let e=(0,o.getCellRenderer)(t);if(e)return(0,s.jsx)(e,{value:n,field:h})}return String(n)})(),v=n!=null&&n!==``,y=_===e.name,b=T(u||``,e.name,e.label||e.name);return P&&!(d&&!e.readonly)?(0,s.jsxs)(`div`,{className:(0,r.cn)(`flex items-baseline justify-between gap-4 py-2.5 min-h-[44px] group`,v&&`cursor-pointer active:bg-muted/40 transition-colors`),onClick:v?()=>j(e.name,n):void 0,onKeyDown:v?t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),j(e.name,n))}:void 0,role:v?`button`:void 0,tabIndex:v?0:void 0,children:[(0,s.jsx)(`span`,{className:`text-[15px] text-muted-foreground shrink-0`,children:b}),(0,s.jsx)(`span`,{className:`text-[15px] text-foreground text-right break-words min-w-0 leading-snug`,children:g})]},e.name):(0,s.jsxs)(`div`,{className:(0,r.cn)(`space-y-1.5 group min-w-0`,c),children:[(0,s.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:T(u||``,e.name,e.label||e.name)}),d&&!e.readonly?(0,s.jsx)(`div`,{className:`min-h-[44px] sm:min-h-0`,children:(()=>{let t=h.type||e.type;if(t===`select`&&Array.isArray(h.options)&&h.options.length>0)return(0,s.jsx)(o.SelectField,{field:h,value:n==null?``:String(n),onChange:t=>f?.(e.name,t)});if(t===`boolean`)return(0,s.jsx)(o.BooleanField,{field:h,value:!!n,onChange:t=>f?.(e.name,t)});let r=t===`user`||t===`owner`,i=t===`lookup`||t===`master_detail`||t===`tree`||!!h.reference_to&&!O.has(t);if(r||i)return(0,s.jsx)(r?o.UserField:o.LookupField,{field:h,value:k(n),onChange:t=>f?.(e.name,t),dataSource:p});let a=t===`date`||t===`datetime`;return(0,s.jsx)(`input`,{type:t===`number`?`number`:a?`date`:`text`,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:n==null?``:a?(()=>{let e=String(n);if(/^\d{4}-\d{2}-\d{2}/.test(e))return e.slice(0,10);let t=new Date(e);return isNaN(t.getTime())?``:t.toLocaleDateString(`en-CA`)})():String(typeof n==`object`?(0,o.coerceToSafeValue)(n)??``:n),onChange:t=>{let n=t.target.value;if(a&&n){let t=new Date(n+`T00:00:00`).toISOString();f?.(e.name,t)}else f?.(e.name,n)}})})()}):(0,s.jsxs)(`div`,{className:(0,r.cn)(`flex items-start justify-between gap-2 min-h-[44px] sm:min-h-0 rounded-md`,v&&`cursor-pointer active:bg-muted/60 transition-colors`),onClick:v?()=>j(e.name,n):void 0,onKeyDown:v?t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),j(e.name,n))}:void 0,role:v?`button`:void 0,tabIndex:v?0:void 0,children:[(0,s.jsx)(`div`,{className:`text-sm flex-1 min-w-0 break-words py-1`,children:g}),v&&(0,s.jsx)(r.TooltipProvider,{children:(0,s.jsxs)(r.Tooltip,{children:[(0,s.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,s.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(),j(e.name,n)},children:y?(0,s.jsx)(i.Check,{className:`h-3 w-3 text-green-600`}):(0,s.jsx)(i.Copy,{className:`h-3 w-3`})})}),(0,s.jsx)(r.TooltipContent,{children:w(y?`detail.copied`:`detail.copyToClipboard`)})]})})]})]},e.name)},U=m?.enabled===!0,W=m?.batchSize??20;if(n.useEffect(()=>{if(!U){b(void 0);return}if(B.length<=W){b(void 0);return}b(W);let e=setTimeout(()=>b(void 0),100);return()=>clearTimeout(e)},[U,B.length,W]),z.length===0&&N===e.fields.length)return null;let te=y===void 0?B:B.slice(0,y),ne=N>0&&(e.hideEmpty||R),G=(0,s.jsxs)(s.Fragment,{children:[P?(0,s.jsx)(`div`,{className:`flex flex-col divide-y divide-border/60`,children:te.map(H)}):(0,s.jsx)(`div`,{className:(0,r.cn)(`grid gap-3 sm:gap-4`,V===1?`grid-cols-1`:V===2?`grid-cols-1 md:grid-cols-2`:V===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:te.map(H)}),ne&&(0,s.jsx)(`div`,{className:`mt-3 -ml-2`,children:(0,s.jsxs)(r.Button,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>S(e=>!e),className:`h-7 px-2 text-xs text-muted-foreground hover:text-foreground`,children:[x?(0,s.jsx)(i.EyeOff,{className:`h-3.5 w-3.5 mr-1.5`}):(0,s.jsx)(i.Eye,{className:`h-3.5 w-3.5 mr-1.5`}),x?w(`detail.hideEmptyFields`,{defaultValue:`Hide empty fields`}):w(`detail.showEmptyFields`,{count:N,defaultValue:`Show ${N} empty field${N===1?``:`s`}`})]})})]});return!e.title&&!e.collapsible&&e.showBorder===!1?(0,s.jsx)(`div`,{className:(0,r.cn)(c),children:G}):e.collapsible?(0,s.jsx)(r.Collapsible,{open:!h,onOpenChange:e=>g(!e),className:c,children:(0,s.jsxs)(r.Card,{children:[(0,s.jsx)(r.CollapsibleTrigger,{asChild:!0,children:(0,s.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,s.jsxs)(r.CardTitle,{className:`flex items-center justify-between text-base font-semibold tracking-tight`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.icon&&(0,s.jsx)(`span`,{className:`text-muted-foreground`,children:e.icon}),(0,s.jsx)(`span`,{children:e.title})]}),(0,s.jsx)(`div`,{className:`flex items-center gap-2`,children:h?(0,s.jsx)(i.ChevronRight,{className:`h-4 w-4 text-muted-foreground`}):(0,s.jsx)(i.ChevronDown,{className:`h-4 w-4 text-muted-foreground`})})]}),e.description&&!h&&(0,s.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:e.description})]})}),(0,s.jsx)(r.CollapsibleContent,{children:(0,s.jsx)(r.CardContent,{className:`pt-3 sm:pt-4 px-3 sm:px-6 pb-4 sm:pb-5`,children:G})})]})}):(0,s.jsxs)(r.Card,{className:(0,r.cn)(e.showBorder===!1?`border-none shadow-none`:``,c),children:[e.title&&(0,s.jsxs)(r.CardHeader,{className:(0,r.cn)(`py-3 px-4 sm:py-4 sm:px-6`,e.headerColor&&`bg-${e.headerColor}`),children:[(0,s.jsx)(r.CardTitle,{className:`flex items-center justify-between text-base font-semibold tracking-tight`,children:(0,s.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.icon&&(0,s.jsx)(`span`,{className:`text-muted-foreground`,children:e.icon}),(0,s.jsx)(`span`,{children:e.title})]})}),e.description&&(0,s.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:e.description})]}),(0,s.jsx)(r.CardContent,{className:`pt-3 sm:pt-4 px-3 sm:px-6 pb-4 sm:pb-5`,children:G})]})},j=({tabs:e,data:t,className:i})=>{let[o,c]=n.useState(e[0]?.key),l=e.filter(e=>typeof e.visible==`boolean`?e.visible:(e.visible,!0));return(0,s.jsxs)(r.Tabs,{value:o,onValueChange:c,className:i,children:[(0,s.jsx)(r.TabsList,{className:`w-full justify-start border-b rounded-none bg-transparent p-0`,children:l.map(e=>(0,s.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,s.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.icon&&(0,s.jsx)(`span`,{children:e.icon}),(0,s.jsx)(`span`,{children:e.label}),e.badge&&(0,s.jsx)(r.Badge,{variant:`secondary`,className:`ml-1`,children:e.badge})]})},e.key))}),l.map(e=>(0,s.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,s.jsx)(n.Suspense,{fallback:null,children:Array.isArray(e.content)?(0,s.jsx)(`div`,{className:`space-y-4`,children:e.content.map((e,n)=>(0,s.jsx)(a.SchemaRenderer,{schema:e,data:t},n))}):(0,s.jsx)(a.SchemaRenderer,{schema:e.content,data:t})})},e.key))]})};function M(e){return e&&i.icons[e.split(/[-_\s]/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``)]||i.Inbox}var N=({title:e,type:t,api:l,data:u,schema:d,columns:f,className:p,dataSource:m,objectName:h,onNew:g,onViewAll:_,onRowEdit:v,onRowDelete:y,onRowClick:b,rowActions:x,onRowAction:S,toolbarActions:C,onToolbarAction:w,add:T,maxColumns:D=6,pageSize:O,sortable:k=!1,filterable:A=!1,collapsible:j=!1,defaultCollapsed:N=!1,referenceField:P,parentId:F,icon:I})=>{let L=u!==void 0,R=u??[],[z,B]=n.useState(R),[ee,V]=n.useState(()=>!!l&&!L),[H,U]=n.useState(0),[W,te]=n.useState(null),[ne,G]=n.useState(`asc`),[re,ie]=n.useState(``),[K,ae]=n.useState(null),[oe,se]=n.useState(N),[q,ce]=n.useState(!1),[le,ue]=n.useState(!1),[de,fe]=n.useState(null),[pe,me]=n.useState(0),[J,he]=n.useState({}),{t:Y}=E(),{fieldLabel:ge}=(0,a.useSafeFieldLabel)();n.useEffect(()=>{L&&B(u??[])},[u,L]),n.useEffect(()=>{l&&m?.getObjectSchema&&m.getObjectSchema(l).then(ae).catch(e=>{console.warn(`[RelatedList] Failed to fetch schema for ${l}:`,e)})},[l,m]),n.useEffect(()=>{if(l&&!L){if(!(P&&F!=null&&F!==``)){l&&(F==null||F===``)&&!P&&console.warn(`[RelatedList] "${l}" has no referenceField/parentId — refusing to fetch all rows. Pass relationshipField + parentId to scope the query.`),B([]),V(!1);return}V(!0);let e={[P]:F};if(m&&typeof m.find==`function`)m.find(l,{$filter:e}).then(e=>{let t=Array.isArray(e)?e:Array.isArray(e?.data)?e.data:[];B(t),V(!1)}).catch(e=>{console.error(`Failed to fetch related data:`,e),V(!1)});else{let e=new URLSearchParams({[`filter[${P}]`]:String(F)}).toString();fetch(`${l}?${e}`).then(e=>e.json()).then(e=>{let t=Array.isArray(e)?e:e?.data||[];B(t)}).catch(e=>{console.error(`Failed to fetch related data:`,e)}).finally(()=>V(!1))}}},[l,L,m,P,F,pe]),n.useEffect(()=>{if(!l||L)return;let e=e=>{let t=e.detail||{};t.objectName&&t.objectName!==l||me(e=>e+1)};return window.addEventListener(`objectui:related-changed`,e),()=>window.removeEventListener(`objectui:related-changed`,e)},[l,L]),n.useEffect(()=>{if(!m?.find||!K?.fields||!z.length)return;let e=K.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 z){let t=e?.[n];t!=null&&(typeof t==`string`&&t?i.add(t):typeof t==`number`&&i.add(String(t)))}let a=J[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})=>m.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||he(t=>{let n={...t};for(let{fieldName:t,map:r}of e)n[t]={...n[t]||{},...r};return n})}),()=>{n=!0}},[m,K,z]);let _e=n.useMemo(()=>{if(!re)return z;let e=re.toLowerCase();return z.filter(t=>Object.values(t).some(t=>t!=null&&String(t).toLowerCase().includes(e)))},[z,re]),X=n.useMemo(()=>W?[..._e].sort((e,t)=>{let n=e[W],r=t[W];if(n==null&&r==null)return 0;if(n==null)return 1;if(r==null)return-1;let i=String(n).localeCompare(String(r),void 0,{numeric:!0});return ne===`asc`?i:-i}):_e,[_e,W,ne]),Z=O&&O>0?O:0,ve=Z?Math.max(1,Math.ceil(X.length/Z)):1,ye=Z?X.slice(H*Z,(H+1)*Z):X;n.useEffect(()=>{U(0)},[re,W,ne]);let be=n.useCallback(e=>{W===e?G(e=>e===`asc`?`desc`:`asc`):(te(e),G(`asc`))},[W]),[Q,xe]=n.useState(null),Se=n.useCallback(e=>{xe(e)},[]),Ce=n.useCallback(async()=>{if(Q)try{await y?.(Q),me(e=>e+1)}catch(e){console.error(`[RelatedList] remove failed`,e)}xe(null)},[Q,y]),we=n.useCallback(async e=>{if(!T||!m||!l||P==null||F==null)return;let t=T.picker.valueField||`id`;ue(!0),fe(null);try{for(let n of e||[]){let e=n?.[t]??n?.id;e!=null&&(T.linkField?await m.create?.(l,{[P]:F,[T.linkField]:e}):await m.update?.(T.picker.object,String(e),{[P]:F}))}me(e=>e+1)}catch(e){let t=e?.body?.error??e?.error??e?.message??String(e);fe(typeof t==`string`?t:`Failed to add`)}finally{ue(!1),ce(!1)}},[T,m,l,P,F]),Te=(0,c.usePermissions)(),$=n.useMemo(()=>{let e=h||l||``,t=t=>!Te?.isLoaded||!e?t:t.filter(t=>{let n=t?.accessorKey||t?.field||t?.name;return n?Te.checkField(e,String(n),`read`):!0}),r=e=>P?e.filter(e=>(e?.accessorKey||e?.field||e?.name)!==P):e,i=e=>e==null||typeof e==`string`&&e.trim()===``||Array.isArray(e)&&e.length===0,a=e=>z.length?e.filter(e=>{let t=e?.accessorKey||e?.field||e?.name;return t?z.some(e=>!i(e?.[t])):!0}):e,s=(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`?J[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})},c=t=>{if(typeof t!=`string`){let e=t?.accessorKey||t?.field||t?.name;if(t&&!t.cell&&!t.render&&e){let n=K?.fields?.[e],r=n?s(String(e),n):void 0;if(r)return{...t,cell:r}}return t}let n=K?.fields?.[t],r={accessorKey:t,header:n?.label||ge(e,t,n)||t,fieldDef:n,fieldType:n?.type},i=n?s(t,n):void 0;return i&&(r.cell=i),r};if(f&&f.length>0)return a(t(r(f.map(c))));if(!K?.fields)return[];let u=Array.isArray(K.highlightFields)?K.highlightFields.filter(e=>typeof e==`string`&&e.length>0):[];if(u.length>0){let e=a(t(r(u.map(c))));if(e.length>0)return e.slice(0,Math.max(1,D))}let d=e,p=new Set([`image`,`file`,`attachment`,`rich_text`,`html`,`json`]),m=[`name`,`full_name`,`fullname`,`title`,`subject`,`label`,`code`,`number`],g=Object.entries(K.fields).filter(([e,t])=>!(e.startsWith(`_`)||e===`id`||e===P||t?.hidden||t?.type&&p.has(t.type)||Te?.isLoaded&&d&&!Te.checkField(d,e,`read`))),_=new Set([`created_at`,`updated_at`,`created_by`,`updated_by`,`owner_id`,`organization_id`]);return g.sort(([e,t],[n,r])=>{let i=_.has(e);if(i!==_.has(n))return i?1:-1;let a=m.indexOf(e),o=m.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}),a(g.map(([e,t])=>{let n={accessorKey:e,header:ge(d,e,t.label||e)};if(t.type){let r=s(e,t);r&&(n.cell=r)}return n})).slice(0,Math.max(1,D))},[f,K,h,l,ge,P,z,D,J,Te]),Ee=Array.isArray(x)&&x.length>0,De=!!v||!!y||Ee,Oe=(0,r.useIsMobile)(),ke=n.useMemo(()=>{if(d)return d;if(Oe&&(t===`grid`||t===`table`)){let e=$[0]?.accessorKey||$[0]?.field||$[0]?.name,t=$.slice(1,4).map(e=>e.accessorKey||e.field||e.name).filter(Boolean);return{type:`object-gallery`,data:ye,objectName:l,gallery:{titleField:e||`name`,visibleFields:t,cardSize:`medium`},onRowClick:b}}switch(t){case`grid`:case`table`:return{type:`data-table`,data:ye,columns:$,pagination:!1,pageSize:Z||10,searchable:!1,exportable:!1,rowActions:De,onRowEdit:v,onRowDelete:y?Se:void 0,onRowClick:b,rowActionDefs:Ee?x:void 0,onRowActionDef:Ee?S:void 0};case`list`:return{type:`data-list`,data:ye};default:return{type:`div`,children:`No view configured`}}},[t,ye,$,d,Z,De,Ee,x,S,v,y,Se,b,Oe,l]),Ae=j?`cursor-pointer select-none`:void 0,je=j?()=>se(e=>!e):void 0,Me=M(I),Ne=!ee&&z.length===0,Pe=A;return(0,s.jsxs)(r.Card,{className:(0,r.cn)(`shadow-none border-border/60 bg-transparent`,Ne&&`bg-muted/10`,p),children:[(0,s.jsx)(r.CardHeader,{className:(0,r.cn)(`py-3 px-4 sm:py-3 min-h-12 sm:min-h-0`,Ae),onClick:je,children:(0,s.jsxs)(r.CardTitle,{className:`flex items-center justify-between gap-2 text-sm font-semibold`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[j&&(oe?(0,s.jsx)(i.ChevronRight,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}):(0,s.jsx)(i.ChevronDown,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`})),(0,s.jsx)(Me,{className:`h-4 w-4 text-muted-foreground shrink-0`,"aria-hidden":!0}),(0,s.jsx)(`span`,{className:(0,r.cn)(`truncate`,Ne&&`text-muted-foreground font-medium`),children:e}),(0,s.jsx)(r.Badge,{variant:`secondary`,className:(0,r.cn)(`text-xs font-normal h-5 px-1.5`,z.length===0&&`bg-muted text-muted-foreground`),"aria-label":`${z.length} records`,children:z.length}),Ne&&(0,s.jsx)(`span`,{className:`text-xs text-muted-foreground/70 italic ml-1 truncate`,children:Y(`detail.noRelatedRecords`)})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[w&&(C??[]).map(e=>{let t=e.icon?M(e.icon):null;return(0,s.jsxs)(r.Button,{variant:e.variant===`primary`?`default`:`outline`,size:`sm`,onClick:t=>{t.stopPropagation(),w(e)},className:`gap-1 h-9 sm:h-7 text-xs shadow-none`,children:[t&&(0,s.jsx)(t,{className:`h-3.5 w-3.5`}),e.label||e.name]},e.name)}),T&&(0,s.jsxs)(r.Button,{variant:Ne?`ghost`:`outline`,size:`sm`,disabled:le,onClick:e=>{e.stopPropagation(),fe(null),ce(!0)},className:`gap-1 h-9 sm:h-7 text-xs shadow-none`,children:[(0,s.jsx)(i.Plus,{className:`h-3.5 w-3.5`}),T.label||Y(`detail.add`,{defaultValue:`Add`})]}),g&&(0,s.jsxs)(r.Button,{variant:Ne?`ghost`:`outline`,size:`sm`,onClick:e=>{e.stopPropagation(),g()},className:`gap-1 h-9 sm:h-7 text-xs shadow-none`,children:[(0,s.jsx)(i.Plus,{className:`h-3.5 w-3.5`}),Y(`detail.new`)]})]})]})}),!oe&&!Ne&&(0,s.jsxs)(r.CardContent,{className:(0,r.cn)(`pt-0 pb-4 px-4`),children:[Pe&&(0,s.jsx)(`div`,{className:`mb-3`,children:(0,s.jsx)(r.Input,{placeholder:Y(`detail.filterPlaceholder`),value:re,onChange:e=>ie(e.target.value),className:`h-8 text-sm`})}),k&&$&&$.length>0&&z.length>0&&(0,s.jsx)(`div`,{className:`flex flex-wrap gap-1 mb-3`,children:$.map(e=>{let t=e.accessorKey||e.field||e.name;if(!t)return null;let n=e.header||e.label||t,a=W===t;return(0,s.jsxs)(r.Button,{variant:a?`secondary`:`ghost`,size:`sm`,className:`gap-1 h-7 text-xs`,onClick:()=>be(t),children:[(0,s.jsx)(i.ArrowUpDown,{className:`h-3 w-3`}),n,a&&(ne===`asc`?` ↑`:` ↓`)]},t)})}),ee?(0,s.jsx)(`div`,{className:`flex items-center justify-center py-6 text-muted-foreground text-sm`,children:Y(`detail.loading`)}):(0,s.jsx)(a.SchemaRenderer,{schema:ke}),Z>0&&X.length>Z&&(0,s.jsxs)(`div`,{className:`flex items-center justify-between mt-3 pt-3 border-t`,children:[(0,s.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,s.jsx)(i.ChevronLeft,{className:`h-3 w-3`}),Y(`detail.previousPage`)]}),(0,s.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:Y(`detail.pageOf`,{current:H+1,total:ve})}),(0,s.jsxs)(r.Button,{variant:`outline`,size:`sm`,className:`h-7 text-xs gap-1`,disabled:H>=ve-1,onClick:()=>U(e=>Math.min(ve-1,e+1)),children:[Y(`detail.nextPage`),(0,s.jsx)(i.ChevronRight,{className:`h-3 w-3`})]})]}),_&&!Ne&&Z>0&&X.length>Z&&(0,s.jsx)(`div`,{className:`mt-3 pt-3 border-t flex justify-center`,children:(0,s.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),_()},className:`text-xs text-muted-foreground hover:text-foreground inline-flex items-center gap-1 transition-colors`,children:[Y(`detail.viewAll`),(0,s.jsx)(i.ExternalLink,{className:`h-3 w-3`})]})})]}),(0,s.jsx)(r.AlertDialog,{open:Q!==null,onOpenChange:e=>{e||xe(null)},children:(0,s.jsxs)(r.AlertDialogContent,{children:[(0,s.jsxs)(r.AlertDialogHeader,{children:[(0,s.jsx)(r.AlertDialogTitle,{children:Y(`detail.deleteRowTitle`,{defaultValue:`Delete record`})}),(0,s.jsx)(r.AlertDialogDescription,{children:Y(`detail.deleteRowConfirmation`)})]}),(0,s.jsxs)(r.AlertDialogFooter,{children:[(0,s.jsx)(r.AlertDialogCancel,{children:Y(`detail.cancel`,{defaultValue:`Cancel`})}),(0,s.jsx)(r.AlertDialogAction,{onClick:Ce,className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:Y(`detail.delete`,{defaultValue:`Delete`})})]})]})}),de&&(0,s.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:de}),T&&m&&(0,s.jsx)(o.RecordPickerDialog,{open:q,onOpenChange:e=>ce(e),multiple:!0,dataSource:m,objectName:T.picker.object,title:T.label||Y(`detail.add`,{defaultValue:`Add`}),onSelect:()=>{},onSelectRecords:e=>{we(e)}})]})},P=({group:e,data:t,className:a,objectSchema:o,objectName:c,isEditing:l=!1,onFieldChange:u,dataSource:d})=>{let f=e.collapsible??!0,[p,m]=n.useState(e.defaultCollapsed??!1),h=(0,s.jsx)(`div`,{className:`space-y-3 sm:space-y-4`,children:e.sections.map((e,n)=>(0,s.jsx)(A,{section:e,data:t,objectSchema:o,objectName:c,isEditing:l,onFieldChange:u,dataSource:d},n))});return f?(0,s.jsxs)(r.Collapsible,{open:!p,onOpenChange:e=>m(!e),className:a,children:[(0,s.jsx)(r.CollapsibleTrigger,{asChild:!0,children:(0,s.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:[p?(0,s.jsx)(i.ChevronRight,{className:`h-4 w-4 text-muted-foreground shrink-0`}):(0,s.jsx)(i.ChevronDown,{className:`h-4 w-4 text-muted-foreground shrink-0`}),e.icon&&(0,s.jsx)(`span`,{className:`text-muted-foreground`,children:e.icon}),(0,s.jsx)(`h3`,{className:`text-lg font-semibold`,children:e.title})]})}),e.description&&!p&&(0,s.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:e.description}),(0,s.jsx)(r.CollapsibleContent,{children:(0,s.jsx)(`div`,{className:`mt-3`,children:h})})]}):(0,s.jsxs)(`div`,{className:(0,r.cn)(`space-y-3`,a),children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-2 pb-2 border-b`,children:[e.icon&&(0,s.jsx)(`span`,{className:`text-muted-foreground`,children:e.icon}),(0,s.jsx)(`h3`,{className:`text-lg font-semibold`,children:e.title})]}),e.description&&(0,s.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e.description}),h]})},F=({fields:e,data:t,className:n,objectName:c,objectSchema:l})=>{let{fieldLabel:u}=(0,a.useSafeFieldLabel)();if(!e.length||!t)return null;let d=e.filter(e=>{let n=t?.[e.name];return n!=null&&n!==``});return d.length===0?null:(0,s.jsx)(`section`,{className:(0,r.cn)(`@container border-b border-border/60 pb-4`,n),"aria-label":`Record highlights`,children:(0,s.jsx)(`div`,{className:(0,r.cn)(`flex flex-wrap gap-y-4`),children:d.map(e=>{let n=t[e.name],a=l?.fields?.[e.name],d=e.type||a?.type,f={name:e.name,label:e.label,type:d||`text`,...a?.options&&{options:a.options},...a?.currency&&{currency:a.currency},...a?.precision!==void 0&&{precision:a.precision},...a?.scale!==void 0&&{scale:a.scale},...a?.format&&{format:a.format}},p=(0,o.getCellRenderer)((0,o.resolveCellRendererType)(f)||d||`text`),m=d===`number`||d===`integer`||d===`currency`||d===`percent`||d===`decimal`,h=d===`email`||d===`url`||d===`textarea`||d===`reference`||d===`lookup`||d===`master_detail`,g=d===`boolean`;return(0,s.jsxs)(`div`,{className:(0,r.cn)(`flex flex-col gap-1 min-w-[7rem] px-5 border-l border-border/60 first:border-l-0 first:pl-0`,h?`basis-[16rem] max-w-[24rem]`:`basis-[9rem] max-w-[16rem]`),children:[(0,s.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:u(c||``,e.name,e.label)}),g?n?(0,s.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,s.jsx)(i.Check,{className:`h-3 w-3`,"aria-hidden":!0}),`Yes`]}):(0,s.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,s.jsx)(i.X,{className:`h-3 w-3`,"aria-hidden":!0}),`No`]}):(0,s.jsx)(`span`,{title:typeof n==`string`?n:void 0,className:(0,r.cn)(`block min-w-0 truncate text-sm font-semibold`,m&&`tabular-nums tracking-tight`),children:(0,s.jsx)(p,{value:n,field:f})})]},e.name)})})})};function I(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 L=({comments:e,onAddComment:t,onTogglePin:a,searchable:o=!1,className:c})=>{let{t:l}=E(),[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,s.jsxs)(r.Card,{className:(0,r.cn)(``,c),children:[(0,s.jsx)(r.CardHeader,{children:(0,s.jsxs)(r.CardTitle,{className:`flex items-center gap-2 text-base`,children:[(0,s.jsx)(i.MessageSquare,{className:`h-4 w-4`}),l(`detail.comments`),(0,s.jsxs)(`span`,{className:`text-sm font-normal text-muted-foreground`,children:[`(`,e.length,`)`]})]})}),(0,s.jsxs)(r.CardContent,{className:`space-y-4`,children:[o&&(0,s.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,s.jsxs)(`div`,{className:`relative flex-1`,children:[(0,s.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,s.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:l(`detail.searchComments`),value:m,onChange:e=>h(e.target.value),"aria-label":l(`detail.searchComments`)}),m&&(0,s.jsx)(`button`,{className:`absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground`,onClick:()=>h(``),"aria-label":l(`detail.clearSearch`),type:`button`,children:(0,s.jsx)(i.X,{className:`h-3.5 w-3.5`})})]})}),t&&(0,s.jsxs)(`div`,{className:`flex gap-2`,children:[(0,s.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:l(`detail.addCommentPlaceholder`),value:u,onChange:e=>d(e.target.value),onKeyDown:_,disabled:f}),(0,s.jsx)(r.Button,{size:`icon`,variant:`default`,onClick:g,disabled:!u.trim()||f,className:`shrink-0 self-end`,children:(0,s.jsx)(i.Send,{className:`h-4 w-4`})})]}),v.length===0?(0,s.jsx)(`p`,{className:`text-sm text-muted-foreground text-center py-4`,children:m.trim()?l(`detail.noMatchingComments`):l(`detail.noCommentsYet`)}):(0,s.jsx)(`div`,{className:`space-y-3`,children:v.map(e=>(0,s.jsxs)(`div`,{className:(0,r.cn)(`flex gap-3`,e.pinned&&`bg-muted/40 rounded-md p-2 -mx-2`),children:[(0,s.jsx)(`div`,{className:`shrink-0`,children:e.avatarUrl?(0,s.jsx)(`img`,{src:e.avatarUrl,alt:e.author,className:`h-8 w-8 rounded-full object-cover`}):(0,s.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,s.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-2 mb-0.5`,children:[(0,s.jsx)(`span`,{className:`text-sm font-medium truncate`,children:e.author}),(0,s.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:I(e.createdAt)}),e.pinned&&(0,s.jsxs)(`span`,{className:`text-xs text-amber-600 flex items-center gap-0.5`,children:[(0,s.jsx)(i.Pin,{className:`h-3 w-3`}),l(`detail.pinned`)]})]}),(0,s.jsx)(`p`,{className:`text-sm whitespace-pre-wrap break-words`,children:e.text}),a&&(0,s.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?l(`detail.unpin`):l(`detail.pin`),children:[(0,s.jsx)(i.Pin,{className:`h-3 w-3`}),e.pinned?l(`detail.unpin`):l(`detail.pin`)]})]})]},e.id))})]})]})},R={field_change:i.Edit,create:i.PlusCircle,delete:i.Trash2,comment:i.MessageSquare,status_change:i.ArrowRightLeft},z={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 B(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 ee(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 V={all:`All`,field_change:`Field Changes`,create:`Creates`,delete:`Deletes`,comment:`Comments`,status_change:`Status Changes`},H=({activities:e,filterable:t=!1,defaultFilter:a=`all`,className:o})=>{let[c,l]=n.useState(a),u=n.useMemo(()=>c===`all`?e:e.filter(e=>e.type===c),[e,c]);return(0,s.jsxs)(r.Card,{className:(0,r.cn)(``,o),children:[(0,s.jsx)(r.CardHeader,{children:(0,s.jsxs)(r.CardTitle,{className:`flex items-center gap-2 text-base`,children:[(0,s.jsx)(i.Activity,{className:`h-4 w-4`}),`Activity`,(0,s.jsxs)(`span`,{className:`text-sm font-normal text-muted-foreground`,children:[`(`,u.length,`)`]})]})}),(0,s.jsxs)(r.CardContent,{children:[t&&(0,s.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mb-4`,role:`group`,"aria-label":`Activity type filter`,children:Object.keys(V).map(e=>(0,s.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`,c===e?`bg-primary text-primary-foreground`:`bg-muted text-muted-foreground hover:bg-muted/80`),onClick:()=>l(e),"aria-pressed":c===e,children:[e!==`all`&&n.createElement(R[e]||i.Edit,{className:`h-3 w-3`}),V[e]]},e))}),u.length===0?(0,s.jsx)(r.DataEmptyState,{title:`No activity recorded`,className:`py-6`}):(0,s.jsxs)(`div`,{className:`relative`,children:[(0,s.jsx)(`div`,{className:`absolute left-4 top-2 bottom-2 w-px bg-border`}),(0,s.jsx)(`div`,{className:`space-y-4`,children:u.map(e=>{let t=R[e.type]||i.Edit;return(0,s.jsxs)(`div`,{className:`flex gap-3 relative`,children:[(0,s.jsx)(`div`,{className:(0,r.cn)(`shrink-0 h-8 w-8 rounded-full flex items-center justify-center z-10`,z[e.type]||`bg-gray-100 text-gray-600`),children:(0,s.jsx)(t,{className:`h-3.5 w-3.5`})}),(0,s.jsxs)(`div`,{className:`flex-1 min-w-0 pt-1`,children:[(0,s.jsxs)(`p`,{className:`text-sm`,children:[(0,s.jsx)(`span`,{className:`font-medium`,children:e.user}),` `,(0,s.jsx)(`span`,{className:`text-muted-foreground`,children:ee(e)})]}),(0,s.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:B(e.timestamp)})]})]},e.id)})})]})]})]})},U={create:`default`,update:`secondary`,delete:`destructive`,restore:`outline`,login:`outline`,logout:`outline`,permission_change:`secondary`,config_change:`secondary`,export:`outline`,import:`outline`};function W(e){if(!e)return``;let t=e instanceof Date?e:new Date(e);return Number.isNaN(t.getTime())?String(e):t.toLocaleString()}var te=[[60,`second`],[60,`minute`],[24,`hour`],[7,`day`],[4.34524,`week`],[12,`month`],[1/0,`year`]];function ne(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 te){if(Math.abs(r)<n)try{return new Intl.RelativeTimeFormat(t,{numeric:`auto`}).format(Math.round(r),i)}catch{return W(e)}r/=n}return W(e)}function G(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 re(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 ie({entries:e,loading:t,emptyText:n,className:i,locale:a}){return t?(0,s.jsx)(`div`,{className:(0,r.cn)(`space-y-3`,i),children:Array.from({length:4}).map((e,t)=>(0,s.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,s.jsx)(r.Skeleton,{className:`h-8 w-8 rounded-full`}),(0,s.jsxs)(`div`,{className:`flex-1 space-y-2`,children:[(0,s.jsx)(r.Skeleton,{className:`h-4 w-1/3`}),(0,s.jsx)(r.Skeleton,{className:`h-3 w-1/2`})]})]},t))}):!e||e.length===0?(0,s.jsx)(`div`,{className:(0,r.cn)(`flex items-center justify-center rounded-md border border-dashed py-10 text-sm text-muted-foreground`,i),children:n??`No history yet`}):(0,s.jsx)(r.TooltipProvider,{delayDuration:150,children:(0,s.jsx)(`ol`,{className:(0,r.cn)(`space-y-4`,i),children:e.map((e,t)=>{let n=(e.action??``).toLowerCase(),i=U[n]??`outline`,o=typeof e.user_name==`string`&&e.user_name.trim()||`Unknown user`,c=W(e.created_at),l=ne(e.created_at,a),u=typeof e.user_avatar==`string`?e.user_avatar:void 0;return(0,s.jsxs)(`li`,{className:`flex items-start gap-3`,children:[(0,s.jsxs)(r.Avatar,{className:`h-8 w-8 mt-0.5 shrink-0`,children:[u?(0,s.jsx)(r.AvatarImage,{src:u,alt:o}):null,(0,s.jsx)(r.AvatarFallback,{className:`text-[10px] font-medium`,children:G(e.user_name)})]}),(0,s.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,s.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2 gap-y-1`,children:[(0,s.jsx)(`span`,{className:`text-sm font-medium text-foreground`,children:o}),e.action&&(0,s.jsx)(r.Badge,{variant:i,className:`text-[10px] uppercase tracking-wide`,children:e.action}),c&&(0,s.jsxs)(r.Tooltip,{children:[(0,s.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,s.jsx)(`span`,{className:`text-xs text-muted-foreground cursor-help`,"aria-label":c,children:l||c})}),(0,s.jsx)(r.TooltipContent,{children:c})]})]}),e.summary&&(0,s.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:e.summary}),e.changes&&e.changes.length>0&&(n===`create`?(0,s.jsxs)(`details`,{className:`mt-1 group`,children:[(0,s.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,s.jsx)(`span`,{className:`transition-transform group-open:rotate-90`,children:`▸`}),(0,s.jsx)(`span`,{children:e.changes.length===1?`1 field populated`:`${e.changes.length} fields populated`})]}),(0,s.jsx)(`ul`,{className:`mt-1.5 space-y-0.5 text-xs text-muted-foreground pl-4`,children:e.changes.map(e=>(0,s.jsxs)(`li`,{className:`leading-relaxed`,children:[(0,s.jsx)(`span`,{className:`font-medium text-foreground`,children:e.label||e.field}),`: `,(0,s.jsx)(`span`,{className:`text-foreground`,children:re(e.to)})]},e.field))})]}):(0,s.jsx)(`ul`,{className:`mt-1.5 space-y-0.5 text-xs text-muted-foreground`,children:e.changes.map(e=>(0,s.jsxs)(`li`,{className:`leading-relaxed`,children:[(0,s.jsx)(`span`,{className:`font-medium text-foreground`,children:e.label||e.field}),`: `,(0,s.jsx)(`span`,{className:`line-through opacity-70`,children:re(e.from)}),` → `,(0,s.jsx)(`span`,{className:`text-foreground`,children:re(e.to)})]},e.field))}))]})]},e.id??t)})})})}var K={createdAt:`created_at`,createdBy:`created_by`,updatedAt:`updated_at`,updatedBy:`updated_by`};function ae(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 oe(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 se(e){try{return new Intl.DateTimeFormat(void 0,{dateStyle:`medium`,timeStyle:`short`}).format(e)}catch{return e.toISOString()}}var q=({value:e,objectSchema:t,fieldName:n})=>{if(e==null||e===``)return null;let r=t?.fields?.[n],i=r?.reference_to||r?.reference,a={name:n,type:r?.type||(i?`lookup`:`text`),...i&&{reference_to:i},...r?.reference_field&&{reference_field:r.reference_field}},c=(0,o.resolveCellRendererType)(a)||a.type;if(c){let t=(0,o.getCellRenderer)(c);if(t)return(0,s.jsx)(`span`,{className:`inline-flex items-center [&_a]:text-inherit [&_a]:hover:underline`,children:(0,s.jsx)(t,{value:e,field:a})})}return(0,s.jsx)(`span`,{children:String(e)})},ce=({label:e,user:t,date:n,objectSchema:i,userField:a,t:o})=>{if(!t&&!n)return null;let c=n?(0,s.jsx)(r.TooltipProvider,{delayDuration:200,children:(0,s.jsxs)(r.Tooltip,{children:[(0,s.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,s.jsx)(`time`,{dateTime:n.toISOString(),className:`cursor-default underline decoration-dotted decoration-muted-foreground/40 underline-offset-2`,children:oe(n,o)})}),(0,s.jsx)(r.TooltipContent,{side:`top`,children:se(n)})]})}):null;return(0,s.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,s.jsx)(`span`,{className:`text-muted-foreground/70`,children:e}),t?(0,s.jsx)(q,{value:t,objectSchema:i,fieldName:a}):null,t&&c?(0,s.jsx)(`span`,{className:`text-muted-foreground/40`,children:`·`}):null,c]})},le=({data:e,objectSchema:t,objectName:n,className:i})=>{let{t:a}=E();if(!e)return null;let o=ae(e[K.createdAt]),c=ae(e[K.updatedAt]),l=e[K.createdBy],u=e[K.updatedBy],d=!!(o||l),f=o&&c&&Math.abs(c.getTime()-o.getTime())<2e3,p=!!(c||u)&&!(f&&(l!=null&&u!=null&&String(l)===String(u)||!u));return!d&&!p?null:(0,s.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,s.jsx)(ce,{label:a(`detail.createdBy`),user:l,date:o,objectSchema:t,userField:K.createdBy,t:a}),p&&(0,s.jsx)(ce,{label:a(`detail.updatedBy`),user:u,date:c,objectSchema:t,userField:K.updatedBy,t:a})]})},ue=5;function de(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 t=e.id??e._id;if(t!=null&&String(t).trim()!==``)return`Record #${t}`}return i}var fe=({schema:e,dataSource:o,className:u,onEdit:d,onDelete:f,onBack:p,inlineEdit:m=!1,onFieldSave:h,discussionSlot:g,rightRail:_,objectLabel:v,onDataLoaded:y,isFavorite:b,onToggleFavorite:x})=>{let[S,C]=n.useState(e.data),[w,T]=n.useState(!e.data&&!!(e.api&&e.resourceId||o&&e.objectName&&e.resourceId)),[D,O]=n.useState(!1),k=b??D,[M,I]=n.useState(!1),[R,z]=n.useState({}),[B,ee]=n.useState(!1),[V,U]=n.useState(null),[W,te]=n.useState(null),[ne,G]=n.useState(!1),[re,K]=n.useState(0),ae=(0,a.useDataInvalidation)(e.objectName||void 0,e.resourceId==null?void 0:String(e.resourceId)),[oe,se]=n.useState(!1),{t:q}=E(),{currency:ce}=(0,l.useLocalization)(),{fieldOptionLabel:fe}=(0,a.useSafeFieldLabel)(),pe=(0,r.useIsMobile)(),me=(0,c.usePermissions)(),J=n.useMemo(()=>{if(!me?.isLoaded||!e.objectName)return e;let t=t=>me.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,me]);n.useEffect(()=>{S&&y&&y(S)},[S,y]);let he=n.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(W?.fields)for(let[e,n]of Object.entries(W.fields))t[e]={...t[e]||{},...n,name:e};let n=e=>S?.[e]!==void 0&&S?.[e]!==null&&S?.[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,W,S]),Y=J.summaryFields&&J.summaryFields.length>0?J.summaryFields:he,ge=n.useCallback(()=>{J.resourceId&&navigator.clipboard.writeText(String(J.resourceId)).then(()=>{G(!0),setTimeout(()=>G(!1),1500)})},[J.resourceId]);n.useEffect(()=>{let e=!0;if(J.data)return C(J.data),T(!1),o?.getObjectSchema&&J.objectName&&o.getObjectSchema(J.objectName).then(t=>{e&&te(t)}).catch(()=>{}),()=>{e=!1};if(o&&J.objectName&&J.resourceId){T(!0),te(null),C(null);let n=J.objectName,r=J.resourceId,i=`${n}-`,a=[...J.sections?.flatMap(e=>e.fields)||[],...J.fields||[]];(o.getObjectSchema?o.getObjectSchema(n).catch(()=>null):Promise.resolve(null)).then(s=>{if(!e)return;te(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&&(C(t),T(!1))}).catch(()=>{e&&(C(null),T(!1))})};return u.catch(()=>null).then(t=>{if(e){if(t){C(t),T(!1);return}return d()}})}).catch(t=>{e&&(console.error(`Failed to fetch detail data:`,t),T(!1))})}else J.api&&J.resourceId&&(T(!0),fetch(`${J.api}/${J.resourceId}`).then(e=>e.json()).then(t=>{e&&C(t?.data||t)}).catch(e=>{console.error(`Failed to fetch detail data:`,e)}).finally(()=>{e&&T(!1)}));return()=>{e=!1}},[J.api,J.resourceId,J.objectName,o,J.sections,J.fields,re,ae]);let _e=n.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]),X=n.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]),Z=n.useCallback(async()=>{if(!o?.cancelPendingApproval||!J.objectName||!J.resourceId){U(q(`detail.cancelApprovalUnavailable`));return}se(!0),U(null);try{if(await o.cancelPendingApproval(String(J.objectName),String(J.resourceId)),o.findOne)try{let e=await o.findOne(String(J.objectName),String(J.resourceId));e&&C(e)}catch{}K(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*/,``);U(`${q(`detail.cancelApprovalFailed`)}: ${t}`)}finally{se(!1)}},[o,J.objectName,J.resourceId,q]),ve=n.useCallback(()=>{let e=J.deleteConfirmation||q(`detail.deleteConfirmation`);window.confirm(e)&&(f?.(),J.onNavigate&&J.objectName&&J.onNavigate(`/${J.objectName}`,{replace:!0}))},[f,J]),ye=n.useCallback(()=>{navigator.share&&J.objectName&&J.resourceId?navigator.share({title:J.title||q(`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]),be=n.useCallback(()=>{let e=!k;x&&x(e),b===void 0&&O(e)},[k,b,x]),Q=n.useCallback(async()=>{if(M){let e=Object.entries(R);if(e.length>0){let t=S,n={...S,...R};C(n),U(null),ee(!0);try{if(h)for(let[t,r]of e)await h(t,r,n);z({}),I(!1)}catch(e){C(t);let n=(e?.message||e?.error||String(e??`Save failed`)).replace(/^\[[^\]]+\]\s*/,``).replace(/^[A-Z][A-Z0-9_]+:\s*/,``);U(n)}finally{ee(!1)}return}z({})}I(!M),U(null)},[M,R,S,h]),xe=n.useCallback(()=>{z({}),I(!1),U(null)},[]),Se=n.useCallback((e,t)=>{z(n=>({...n,[e]:t}))},[]);n.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]),n.useEffect(()=>{if(!m||J.showHeader!==!1)return;let e=`objectui:record:inline-edit-toggle`,t=e=>{let t=e.detail;t?.recordId&&J.recordId&&t.recordId!==J.recordId||t?.objectName&&J.objectName&&t.objectName!==J.objectName||Q()};return window.addEventListener(e,t),()=>window.removeEventListener(e,t)},[m,J.showHeader,J.recordId,J.objectName,Q]);let Ce=n.useMemo(()=>J.related??[],[J.related]),we=n.useMemo(()=>{let e=[];return e.push({name:`sys_share`,label:q(`detail.share`),icon:`share-2`,type:`script`,onClick:ye}),J.showEdit&&e.push({name:`sys_edit_mobile`,label:q(`detail.edit`),icon:`edit`,type:`script`,className:`sm:hidden`,onClick:X}),m&&e.push({name:`sys_toggle_inline_edit_mobile`,label:q(M?`detail.save`:`detail.editInline`),icon:`edit`,type:`script`,className:`sm:hidden`,onClick:Q}),J.showDelete&&e.push({name:`sys_delete`,label:q(`detail.delete`),icon:`trash-2`,type:`script`,variant:`destructive`,tags:[`separator-before`],onClick:ve}),e},[q,J.showEdit,J.showDelete,m,M,ye,X,Q,ve]),Te=n.useMemo(()=>{let e=J.actions??[];if(we.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,...we]}}return e});return t||n.push({type:`action:bar`,location:`record_header`,systemActions:we}),n},[J.actions,we]);return w||J.loading?(0,s.jsxs)(`div`,{className:(0,r.cn)(`space-y-4`,u),children:[(0,s.jsx)(r.Skeleton,{className:`h-10 w-full`}),(0,s.jsx)(r.Skeleton,{className:`h-64 w-full`}),(0,s.jsx)(r.Skeleton,{className:`h-48 w-full`})]}):!S&&!J.data?(0,s.jsxs)(`div`,{className:(0,r.cn)(`flex flex-col items-center justify-center py-16 text-center`,u),children:[(0,s.jsx)(`p`,{className:`text-lg font-semibold`,children:q(`detail.recordNotFound`)}),(0,s.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:q(`detail.recordNotFoundDescription`)}),(J.showBack??!0)&&(0,s.jsxs)(r.Button,{variant:`outline`,size:`sm`,onClick:_e,className:`mt-4 gap-2`,children:[(0,s.jsx)(i.ArrowLeft,{className:`h-4 w-4`}),q(`detail.goBack`)]})]}):(0,s.jsx)(r.TooltipProvider,{children:(0,s.jsxs)(`div`,{className:(0,r.cn)(`space-y-6`,u),children:[J.showHeader!==!1&&(0,s.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start justify-between gap-3 sm:gap-4 pb-4 border-b`,children:[(0,s.jsxs)(`div`,{className:`flex items-start gap-2 sm:gap-3 flex-1 min-w-0`,children:[(J.showBack??!0)&&(0,s.jsxs)(r.Tooltip,{children:[(0,s.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,s.jsx)(r.Button,{variant:`ghost`,size:`icon`,onClick:_e,className:`shrink-0 mt-1`,children:(0,s.jsx)(i.ArrowLeft,{className:`h-4 w-4`})})}),(0,s.jsx)(r.TooltipContent,{children:q(`detail.back`)})]}),(0,s.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,s.jsx)(`h1`,{className:`text-xl sm:text-2xl font-bold truncate`,children:de(S,J,W,q(`detail.details`))}),Y.map(e=>{let t=S?.[e];if(t==null||t===``)return null;let n=(J.sections||[]).flatMap(e=>e.fields).concat(J.fields||[]).find(t=>t.name===e),i=W?.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,l.resolveFieldCurrency)({...i,...n},ce);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=J.objectName?fe(J.objectName,e,String(t),a):a}}catch{}return c===null?(0,s.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,s.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,s.jsx)(`span`,{className:`relative inline-block h-1.5 w-12 rounded-full bg-primary/20 overflow-hidden`,"aria-hidden":!0,children:(0,s.jsx)(`span`,{className:`absolute inset-y-0 left-0 rounded-full bg-primary`,style:{width:`${c}%`}})}),o]},e)}),(0,s.jsxs)(r.Tooltip,{children:[(0,s.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,s.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-6 w-6 shrink-0`,onClick:be,"aria-label":q(k?`detail.removeFromFavorites`:`detail.addToFavorites`),children:k?(0,s.jsx)(i.Star,{className:`h-4 w-4 fill-yellow-400 text-yellow-400`}):(0,s.jsx)(i.Star,{className:`h-4 w-4 text-muted-foreground`})})}),(0,s.jsx)(r.TooltipContent,{children:q(k?`detail.removeFromFavorites`:`detail.addToFavorites`)})]})]}),J.objectName&&(0,s.jsxs)(`p`,{className:`text-sm text-muted-foreground mt-1 flex items-center gap-1`,children:[(0,s.jsx)(`span`,{className:`font-medium`,children:v||J.objectName}),J.resourceId&&(0,s.jsxs)(r.Tooltip,{children:[(0,s.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,s.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-5 w-5 shrink-0 text-muted-foreground/60 hover:text-foreground`,onClick:ge,"aria-label":q(`detail.copyRecordId`,{defaultValue:`Copy record ID`}),children:ne?(0,s.jsx)(i.Check,{className:`h-3 w-3 text-green-600`}):(0,s.jsx)(i.Copy,{className:`h-3 w-3`})})}),(0,s.jsx)(r.TooltipContent,{children:ne?q(`detail.copied`,{defaultValue:`Copied`}):q(`detail.copyRecordId`,{defaultValue:`Copy record ID`})})]})]})]})]}),(0,s.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 shrink-0 w-full sm:w-auto`,children:[J.recordNavigation&&(0,s.jsxs)(`div`,{className:`flex items-center gap-1 mr-2`,children:[(0,s.jsxs)(r.Tooltip,{children:[(0,s.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,s.jsx)(r.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,s.jsx)(i.ChevronLeft,{className:`h-4 w-4`})})}),(0,s.jsx)(r.TooltipContent,{children:q(`detail.previousRecord`)})]}),(0,s.jsx)(`span`,{className:`text-xs text-muted-foreground whitespace-nowrap px-1`,children:q(`detail.recordOf`,{current:J.recordNavigation.currentIndex+1,total:J.recordNavigation.recordIds.length})}),(0,s.jsxs)(r.Tooltip,{children:[(0,s.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,s.jsx)(r.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,s.jsx)(i.ChevronRight,{className:`h-4 w-4`})})}),(0,s.jsx)(r.TooltipContent,{children:q(`detail.nextRecord`)})]})]}),m&&(0,s.jsxs)(s.Fragment,{children:[M&&(0,s.jsxs)(r.Tooltip,{children:[(0,s.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,s.jsxs)(r.Button,{variant:`ghost`,size:`sm`,onClick:xe,className:`gap-2 hidden sm:inline-flex`,children:[(0,s.jsx)(i.X,{className:`h-4 w-4`}),(0,s.jsx)(`span`,{className:`hidden sm:inline`,children:q(`detail.cancel`)})]})}),(0,s.jsx)(r.TooltipContent,{children:q(`detail.cancelEdit`)})]}),(0,s.jsxs)(r.Tooltip,{children:[(0,s.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,s.jsx)(r.Button,{variant:M?`default`:`outline`,size:`sm`,onClick:Q,className:`gap-2 hidden sm:inline-flex`,children:M?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(i.Check,{className:`h-4 w-4`}),(0,s.jsx)(`span`,{className:`hidden sm:inline`,children:q(`detail.save`)})]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(i.Edit,{className:`h-4 w-4`}),(0,s.jsx)(`span`,{className:`hidden sm:inline`,children:q(`detail.editInline`)})]})})}),(0,s.jsx)(r.TooltipContent,{children:q(M?`detail.saveChanges`:`detail.editFieldsInline`)})]})]}),J.showEdit&&(0,s.jsxs)(r.Tooltip,{children:[(0,s.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,s.jsxs)(r.Button,{variant:`default`,onClick:X,className:`gap-2 hidden sm:inline-flex`,children:[(0,s.jsx)(i.Edit,{className:`h-4 w-4`}),(0,s.jsx)(`span`,{className:`hidden sm:inline`,children:q(`detail.edit`)})]})}),(0,s.jsx)(r.TooltipContent,{children:q(`detail.editRecord`)})]}),Te.map((e,t)=>(0,s.jsx)(a.SchemaRenderer,{schema:e,data:S},`header-action-${t}`))]})]}),J.header&&(0,s.jsx)(`div`,{children:(0,s.jsx)(a.SchemaRenderer,{schema:J.header,data:S})}),J.highlightFields&&J.highlightFields.length>0&&(0,s.jsx)(F,{fields:J.highlightFields,data:S,objectName:J.objectName,objectSchema:W}),m&&J.showHeader===!1&&(()=>{let e=S?.approval_status,t=e===`pending`||e===`in_approval`;return!M&&!B&&!V&&!t?null:(0,s.jsxs)(`div`,{className:`flex flex-col items-end gap-1`,children:[(0,s.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[t&&!M&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(`span`,{role:`status`,className:`inline-flex items-center gap-1 rounded-md border border-amber-300 bg-amber-50 px-2 py-1 text-xs text-amber-800`,title:q(`detail.lockedTooltip`),children:[(0,s.jsx)(i.Lock,{className:`h-3 w-3`}),(0,s.jsx)(`span`,{children:q(`detail.lockedByApproval`)})]}),o?.cancelPendingApproval&&(0,s.jsxs)(r.Button,{variant:`outline`,size:`sm`,onClick:Z,disabled:oe,className:`gap-2 border-amber-300 text-amber-800 hover:bg-amber-50`,title:q(`detail.cancelApprovalTooltip`),children:[(0,s.jsx)(i.X,{className:`h-4 w-4`}),(0,s.jsx)(`span`,{children:q(oe?`detail.cancelApprovalInFlight`:`detail.cancelApproval`)})]})]}),M&&(0,s.jsxs)(r.Button,{variant:`ghost`,size:`sm`,onClick:xe,className:`gap-2`,disabled:B,children:[(0,s.jsx)(i.X,{className:`h-4 w-4`}),(0,s.jsx)(`span`,{children:q(`detail.cancel`)})]}),(0,s.jsxs)(r.Button,{variant:M?`default`:`outline`,size:`sm`,onClick:Q,className:`gap-2`,disabled:B||t&&!M,title:t&&!M?q(`detail.lockedTooltip`):void 0,children:[M?(0,s.jsx)(i.Check,{className:`h-4 w-4`}):(0,s.jsx)(i.Edit,{className:`h-4 w-4`}),(0,s.jsx)(`span`,{children:q(B?`detail.saving`:M?`detail.save`:`detail.editFieldsInline`)})]})]}),V&&(0,s.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:V})]})})(),J.autoTabs&&!J.tabs?.length?(()=>{let e=Ce.length>0,t=!!J.activities&&J.activities.length>0,n=!!g,i=!!J.history,a=[`details`,...e?[`related`]:[],...t?[`activity`]:[],...n?[`discussion`]:[],...i?[`history`]:[]],c=J.defaultTab,l=c&&a.includes(c)?c:`details`,u=J.onTabChange,d=(0,s.jsxs)(`div`,{className:`space-y-3 sm:space-y-4`,children:[J.sectionGroups&&J.sectionGroups.length>0&&J.sectionGroups.map((e,t)=>(0,s.jsx)(P,{group:e,data:{...S,...R},objectSchema:W,objectName:J.objectName,isEditing:M,onFieldChange:Se,dataSource:o},t)),J.sections&&J.sections.length>0&&J.sections.map((e,t)=>(0,s.jsx)(A,{section:e,data:{...S,...R},objectSchema:W,objectName:J.objectName,isEditing:M,onFieldChange:Se,dataSource:o},t)),J.fields&&J.fields.length>0&&!J.sections?.length&&(0,s.jsx)(A,{section:{fields:J.fields,columns:J.columns},data:{...S,...R},objectSchema:W,objectName:J.objectName,isEditing:M,onFieldChange:Se,dataSource:o}),J.comments&&(0,s.jsx)(L,{comments:J.comments,onAddComment:J.onAddComment})]});return!e&&!t&&!n&&!i?(0,s.jsx)(`div`,{className:`mt-2`,children:d}):(0,s.jsxs)(r.Tabs,{defaultValue:l,onValueChange:u,className:`w-full`,children:[(0,s.jsxs)(r.TabsList,{className:`w-full justify-start border-b rounded-none bg-transparent p-0`,children:[(0,s.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:q(`detail.details`)}),e&&(0,s.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,s.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[q(`detail.related`),(0,s.jsx)(r.Badge,{variant:`secondary`,className:`text-xs bg-primary/10 text-primary border-transparent`,children:Ce.length})]})}),t&&(0,s.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,s.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[q(`detail.activity`),(0,s.jsx)(r.Badge,{variant:`secondary`,className:`text-xs bg-primary/10 text-primary border-transparent`,children:J.activities.length})]})}),n&&(0,s.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:q(`detail.discussion`,{defaultValue:`Discussion`})}),i&&(0,s.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,s.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[q(`detail.history`,{defaultValue:`History`}),!J.history.loading&&J.history.entries.length>0&&(0,s.jsx)(r.Badge,{variant:`secondary`,className:`text-xs bg-primary/10 text-primary border-transparent`,children:J.history.entries.length})]})})]}),(0,s.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,s.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,s.jsx)(`div`,{className:`space-y-3`,children:Ce.map((e,t)=>(0,s.jsx)(N,{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:pe&&t>0,pageSize:ue},t))})}),t&&(0,s.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,s.jsx)(H,{activities:J.activities})}),n&&(0,s.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:g}),i&&(0,s.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,s.jsx)(ie,{entries:J.history.entries,loading:J.history.loading,emptyText:J.history.emptyText??q(`detail.historyEmpty`,{defaultValue:`No history yet`})})})]})})():(0,s.jsxs)(s.Fragment,{children:[J.sectionGroups&&J.sectionGroups.length>0&&(0,s.jsx)(`div`,{className:`space-y-3 sm:space-y-4`,children:J.sectionGroups.map((e,t)=>(0,s.jsx)(P,{group:e,data:{...S,...R},objectSchema:W,objectName:J.objectName,isEditing:M,onFieldChange:Se,dataSource:o},t))}),J.sections&&J.sections.length>0&&(0,s.jsx)(`div`,{className:`space-y-3 sm:space-y-4`,children:J.sections.map((e,t)=>(0,s.jsx)(A,{section:e,data:{...S,...R},objectSchema:W,objectName:J.objectName,isEditing:M,onFieldChange:Se,dataSource:o},t))}),J.fields&&J.fields.length>0&&!J.sections?.length&&(0,s.jsx)(A,{section:{fields:J.fields,columns:J.columns},data:{...S,...R},objectSchema:W,objectName:J.objectName,isEditing:M,onFieldChange:Se,dataSource:o}),J.tabs&&J.tabs.length>0&&(0,s.jsx)(j,{tabs:J.tabs,data:S}),Ce.length>0&&(0,s.jsxs)(`div`,{className:`space-y-3`,children:[(0,s.jsx)(`h2`,{className:`text-lg font-semibold`,children:q(`detail.related`)}),Ce.map((e,t)=>(0,s.jsx)(N,{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:pe&&t>0,pageSize:ue},t))]}),J.comments&&(0,s.jsx)(L,{comments:J.comments,onAddComment:J.onAddComment}),J.activities&&J.activities.length>0&&(0,s.jsx)(H,{activities:J.activities})]}),(0,s.jsx)(le,{data:{...S,...R},objectSchema:W,objectName:J.objectName}),J.footer&&(0,s.jsx)(`div`,{children:(0,s.jsx)(a.SchemaRenderer,{schema:J.footer,data:S})})]})})},pe=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)}},me=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()}},J=({open:e,conflict:t,onReload:n,onOverwrite:a,onCancel:o,busy:c=!1})=>{let{t:l}=E(),u=t?.label||t?.field||``,d=t?pe(t.pendingValue):``,f=t?pe(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=me(p.updated_at??t?.currentVersion),[g,_]=l(`detail.concurrentUpdateDescription`,{field:`{{field}}`}).split(`{{field}}`);return(0,s.jsx)(r.AlertDialog,{open:e,onOpenChange:e=>{!e&&!c&&o()},children:(0,s.jsxs)(r.AlertDialogContent,{className:`max-w-lg`,children:[(0,s.jsx)(r.AlertDialogHeader,{children:(0,s.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,s.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,s.jsx)(i.AlertTriangle,{className:`h-5 w-5`})}),(0,s.jsxs)(`div`,{className:`flex-1`,children:[(0,s.jsx)(r.AlertDialogTitle,{children:l(`detail.concurrentUpdateTitle`)}),(0,s.jsxs)(r.AlertDialogDescription,{className:`mt-1`,children:[g,(0,s.jsx)(`strong`,{className:`font-semibold`,children:u}),_]})]})]})}),(0,s.jsxs)(`div`,{className:`space-y-2 text-sm`,children:[(0,s.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,s.jsx)(`div`,{className:`text-xs font-medium uppercase tracking-wide text-amber-800 dark:text-amber-300`,children:l(`detail.concurrentUpdateYourEdit`)}),(0,s.jsx)(`div`,{className:`mt-1 break-all font-mono text-foreground`,children:d})]}),(0,s.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,s.jsxs)(`div`,{className:`flex items-baseline justify-between gap-2`,children:[(0,s.jsx)(`div`,{className:`text-xs font-medium uppercase tracking-wide text-sky-800 dark:text-sky-300`,children:l(`detail.concurrentUpdateCurrentValue`)}),(m||h)&&(0,s.jsxs)(`div`,{className:`text-[11px] text-muted-foreground`,children:[m&&(0,s.jsx)(`span`,{children:l(`detail.concurrentUpdateUpdatedBy`,{name:m})}),m&&h&&(0,s.jsx)(`span`,{children:` · `}),h&&(0,s.jsx)(`span`,{children:l(`detail.concurrentUpdateUpdatedAt`,{when:h})})]})]}),(0,s.jsx)(`div`,{className:`mt-1 break-all font-mono text-foreground`,children:f})]})]}),(0,s.jsxs)(r.AlertDialogFooter,{className:`gap-2 sm:gap-2`,children:[(0,s.jsx)(`button`,{type:`button`,disabled:c,onClick:o,className:(0,r.cn)((0,r.buttonVariants)({variant:`ghost`}),`mt-2 sm:mt-0`),children:l(`detail.concurrentUpdateCancel`)}),(0,s.jsx)(`button`,{type:`button`,disabled:c,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:l(`detail.concurrentUpdateOverwrite`)}),(0,s.jsx)(`button`,{type:`button`,disabled:c,onClick:n,autoFocus:!0,className:(0,r.cn)((0,r.buttonVariants)({variant:`default`}),`mt-2 sm:mt-0`),children:l(`detail.concurrentUpdateReload`)})]})]})})};function he(e){if(!e||typeof e!=`object`)return!1;let t=e;return t.code===`CONCURRENT_UPDATE`||t.name===`ConcurrentUpdateError`}var Y=e=>typeof e==`string`?e:e&&typeof e==`object`&&(e.field||e.name)||null,ge=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}},_e=({schema:e={},className:t,...r})=>{let i=(0,a.useRecordContext)(),{designer:o}=ge(r),l=i?.objectName||``,u=(0,c.usePermissions)(),{readableFields:d}=(0,c.useFieldPermissions)(l),{sectionLabel:f}=(0,a.useSafeFieldLabel)(),p=(0,a.useHighlightFieldNames)(),[m,h]=n.default.useState(null),[g,_]=n.default.useState(!1),v=n.default.useCallback(t=>{let n=[...Array.isArray(e.fields)?e.fields:[],...(Array.isArray(e.sections)?e.sections:[]).flatMap(e=>Array.isArray(e?.fields)?e.fields:[])];for(let e of n)if((typeof e==`string`?e:e?.name||e?.field)===t)return typeof e==`object`?e?.label:void 0},[e.fields,e.sections]),y=n.default.useCallback(async(e,t)=>{let n=i?.dataSource,r=i?.recordId,a=i?.objectName;if(!n||!r||!a)return;let o=typeof i?.data?.updated_at==`string`?(i?.data).updated_at:void 0,s=o?{ifMatch:o}:void 0;try{if(typeof n.update==`function`)await n.update(a,r,{[e]:t},s);else if(typeof n.updateOne==`function`)await n.updateOne(a,r,{[e]:t},s);else if(typeof n.patch==`function`)await n.patch(a,r,{[e]:t},s);else{console.warn(`[record:details] DataSource exposes no update/updateOne/patch method; cannot persist inline edit`);return}typeof i?.refresh==`function`&&await i.refresh()}catch(n){if(he(n)){let r=n.currentRecord??null;throw h({field:e,label:v(e),pendingValue:t,currentValue:r?r[e]:void 0,currentVersion:n.currentVersion,currentRecord:r}),n}throw console.error(`[record:details] Inline-edit save failed`,n),n}},[i?.dataSource,i?.recordId,i?.objectName,i?.data,i?.refresh,v]),b=n.default.useCallback(()=>{h(null),_(!1)},[]),x=n.default.useCallback(async()=>{_(!0);try{typeof i?.refresh==`function`&&await i.refresh()}finally{b()}},[i?.refresh,b]),S=n.default.useCallback(async()=>{if(!m){b();return}let e=i?.dataSource,t=i?.recordId,n=i?.objectName;if(!e||!t||!n){b();return}_(!0);try{let r=m.currentVersion?{ifMatch:m.currentVersion}:void 0;typeof e.update==`function`?await e.update(n,t,{[m.field]:m.pendingValue},r):typeof e.updateOne==`function`?await e.updateOne(n,t,{[m.field]:m.pendingValue},r):typeof e.patch==`function`&&await e.patch(n,t,{[m.field]:m.pendingValue},r),typeof i?.refresh==`function`&&await i.refresh()}catch(e){console.error(`[record:details] Overwrite-on-conflict failed`,e)}finally{b()}},[m,i?.dataSource,i?.recordId,i?.objectName,i?.refresh,b]);if(!i)return(0,s.jsx)(`div`,{className:t,"data-record-details-placeholder":!0,...o,children:(0,s.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 C=Array.isArray(e.requiredPermissions)?e.requiredPermissions:[];if(C.length>0&&l&&!C.every(e=>u.can(l,e)))return(0,s.jsx)(`div`,{className:t,...o,role:`status`,"aria-live":`polite`,children:(0,s.jsx)(`p`,{className:`text-sm text-muted-foreground italic`,children:`Insufficient permissions to view details.`})});let w=e.layout===`inline`||e.layout===`compact`?`horizontal`:`vertical`,T=e.enforceFieldSecurity===!0,E=Array.isArray(e.redactFields)?e.redactFields:[],D=e=>{if(!e||!T&&E.length===0)return e;let t=e.map(Y).filter(e=>!!e),n=new Set((T&&l?d(t):t).filter(e=>!E.includes(e)));return e.filter(e=>{let t=Y(e);return t?n.has(t):!0})},O=e=>typeof e==`string`?{name:e}:e&&typeof e==`object`&&!e.name&&e.field?{...e,name:e.field}:e,k=e=>Array.isArray(e)?e.map(O):e,A=new Set((Array.isArray(e.hideFields)?e.hideFields:[]).map(e=>typeof e==`string`?e:Y(e)).filter(e=>!!e));for(let e of p)A.add(e);let j=i.objectSchema,M=i.data??{},N=[j?.primaryField,`name`,`full_name`,`title`,`subject`,`display_name`,`label`].filter(e=>typeof e==`string`&&e.length>0);for(let e of N)if(M[e]!==void 0&&M[e]!==null&&M[e]!==``){A.add(e);break}let P=e=>!e||A.size===0?e:e.filter(e=>{let t=Y(e);return t?!A.has(t):!0}),F=P(k(D(e.fields))),I=Array.isArray(e.sections)?e.sections.map(e=>{let t=e.title??e.label,n=e.name&&l?f(l,e.name,t??e.name):t;return{...e,title:n,showBorder:e.showBorder??!!n,hideEmpty:e.hideEmpty??!0,fields:P(k(D(e.fields)))}}):e.sections,L=e.inlineEdit??!0,R={type:`detail-view`,objectName:i.objectName,resourceId:i.recordId,data:i.data,layout:w,columns:e.columns,sections:I,fields:F,showBack:!1,showHeader:e.showHeader??!1,inlineEdit:L};return(0,s.jsxs)(`div`,{className:t,...o,children:[(0,s.jsx)(fe,{schema:R,dataSource:i.dataSource,inlineEdit:L,onFieldSave:y}),(0,s.jsx)(J,{open:!!m,conflict:m,busy:g,onCancel:b,onReload:x,onOverwrite:S})]})},X=e=>typeof e==`string`?e:e&&typeof e==`object`&&(e.field||e.name||e.key)||null,Z=e=>e?.id??e?._id??null,ve=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}},ye=({schema:e={},className:t,...r})=>{let i=(0,a.useRecordContext)(),{designer:l}=ve(r),u=(0,a.useSafeFieldLabel)(),d=e.objectName,f=d&&u.objectLabel?u.objectLabel({name:d,label:(0,o.humanizeLabel)(d)}):d?(0,o.humanizeLabel)(d):``,p=e.title||f||`Related`;if(!d)return(0,s.jsx)(`div`,{className:t,...l,children:(0,s.jsx)(`div`,{className:`text-xs text-muted-foreground italic px-3 py-2 border border-dashed rounded`,children:`record:related_list — missing objectName`})});let m=(0,c.usePermissions)(),{readableFields:h}=(0,c.useFieldPermissions)(d),g=(0,a.useRelatedRecordActions)(),_=n.default.useMemo(()=>g?.resolve({objectName:d,relationshipField:e.relationshipField,parentId:i?.recordId??null})??null,[g,d,e.relationshipField,i?.recordId]),v=Array.isArray(e.requiredPermissions)?e.requiredPermissions:[];if(v.length>0&&!v.every(e=>m.can(d,e)))return(0,s.jsx)(`div`,{className:t,...l,role:`status`,"aria-live":`polite`,children:(0,s.jsx)(`p`,{className:`text-sm text-muted-foreground italic`,children:`Insufficient permissions to view related list.`})});let y=e.enforceFieldSecurity===!0,b=Array.isArray(e.redactFields)?e.redactFields:[],x=Array.isArray(e.columns)?e.columns:[],S=x;if(y||b.length>0){let e=x.map(X).filter(e=>!!e),t=new Set((y?h(e):e).filter(e=>!b.includes(e)));S=x.filter(e=>{let n=X(e);return n?t.has(n):!0})}return(0,s.jsx)(`div`,{className:t,...l,children:(0,s.jsx)(N,{title:p,type:`table`,api:d,objectName:d,referenceField:e.relationshipField,parentId:i?.recordId,columns:S,pageSize:e.limit,dataSource:i?.dataSource,add:e.add,rowActions:_?.rowActions,onRowAction:_?.onRowAction,toolbarActions:_?.toolbarActions,onToolbarAction:_?.onToolbarAction,onNew:_?.onCreate,onRowClick:_?.onView?e=>{let t=Z(e);t!=null&&_.onView(t,e)}:void 0,onRowEdit:_?.onEdit?e=>{let t=Z(e);t!=null&&_.onEdit(t,e)}:void 0,onRowDelete:_?.onDelete?e=>{let t=Z(e);if(t!=null)return _.onDelete(t,e)}:e.add&&i?.dataSource?async e=>{let t=e?.id??e?._id;t!=null&&await i.dataSource.delete?.(d,String(t))}:void 0})})},be=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}},Q=({schema:e={},className:t,...r})=>{let i=(0,a.useRecordContext)(),{designer:o}=be(r),l=i?.objectName||``,u=(0,c.usePermissions)(),{readableFields:d}=(0,c.useFieldPermissions)(l),f=Array.isArray(e.requiredPermissions)?e.requiredPermissions:[];if(f.length>0&&l&&!f.every(e=>u.can(l,e)))return(0,s.jsx)(`div`,{className:t,...o,role:`status`,"aria-live":`polite`,children:(0,s.jsx)(`p`,{className:`text-sm text-muted-foreground italic`,children:`Insufficient permissions to view highlights.`})});let p=(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),m=e.enforceFieldSecurity===!0,h=Array.isArray(e.redactFields)?e.redactFields:[],g=m&&l?new Set(d(p.map(e=>e.name))):null,_=p.filter(e=>!(h.includes(e.name)||g&&!g.has(e.name)));return(0,a.useRegisterHighlightFields)(n.default.useId(),_.map(e=>e.name)),(0,s.jsx)(`div`,{className:t,...o,children:(0,s.jsx)(F,{fields:_,data:i?.data,objectName:i?.objectName,objectSchema:i?.objectSchema})})},xe=({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,s.jsxs)(`div`,{className:(0,r.cn)(`flex items-center gap-1.5 text-sm flex-wrap`,t),children:[(0,s.jsx)(`span`,{className:`font-medium text-foreground`,children:n}),(0,s.jsx)(`span`,{className:`text-muted-foreground line-through`,children:a}),(0,s.jsx)(i.ArrowRight,{className:`h-3 w-3 text-muted-foreground shrink-0`}),(0,s.jsx)(`span`,{className:`text-foreground`,children:o})]})},Se=[`👍`,`❤️`,`🎉`,`😂`,`😮`,`😢`],Ce=({reactions:e,onToggleReaction:t,emojiOptions:a=Se,className:o})=>{let[c,l]=n.useState(!1),u=n.useCallback(e=>{t?.(e),l(!1)},[t]);return(0,s.jsxs)(`div`,{className:(0,r.cn)(`flex items-center gap-1 flex-wrap`,o),children:[e.map(e=>(0,s.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,s.jsx)(`span`,{children:e.emoji}),(0,s.jsx)(`span`,{children:e.count})]},e.emoji)),t&&(0,s.jsxs)(`div`,{className:`relative`,children:[(0,s.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-6 w-6`,onClick:()=>l(!c),"aria-label":`Add reaction`,children:(0,s.jsx)(i.SmilePlus,{className:`h-3.5 w-3.5`})}),c&&(0,s.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,s.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 we(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 Te=({parentItem:e,replies:t,onAddReply:a,showReplyInput:o=!0,className:c})=>{let{t:l}=E(),[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,s.jsxs)(`div`,{className:(0,r.cn)(`ml-10 mt-1`,c),children:[t.length>0&&(0,s.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,s.jsx)(i.ChevronDown,{className:`h-3 w-3`}):(0,s.jsx)(i.ChevronRight,{className:`h-3 w-3`}),(0,s.jsx)(i.MessageSquare,{className:`h-3 w-3`}),(0,s.jsx)(`span`,{children:t.length===1?l(`detail.replyCount`,{count:t.length}):l(`detail.replyCountPlural`,{count:t.length})})]}),u&&(0,s.jsx)(`div`,{className:`space-y-2 border-l-2 border-border pl-3`,children:t.map(e=>(0,s.jsxs)(`div`,{className:`flex gap-2`,children:[(0,s.jsx)(`div`,{className:`shrink-0`,children:e.actorAvatarUrl?(0,s.jsx)(`img`,{src:e.actorAvatarUrl,alt:e.actor,className:`h-6 w-6 rounded-full object-cover`}):(0,s.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,s.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,s.jsx)(`span`,{className:`text-xs font-medium`,children:e.actor}),(0,s.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:we(e.createdAt,l)})]}),(0,s.jsx)(`p`,{className:`text-xs whitespace-pre-wrap break-words`,children:e.body})]})]},e.id))}),o&&a&&(0,s.jsxs)(`div`,{className:`flex gap-1.5 mt-1.5`,children:[(0,s.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:l(`detail.replyPlaceholder`),value:f,onChange:e=>p(e.target.value),onKeyDown:_,disabled:m}),(0,s.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,s.jsx)(i.Send,{className:`h-3 w-3`})})]})]})},$=({subscription:e,onToggle:t,className:a})=>{let{t:o}=E(),[c,l]=n.useState(!1),u=n.useCallback(async()=>{if(t){l(!0);try{await t(!e.subscribed)}finally{l(!1)}}},[t,e.subscribed]);return(0,s.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:(0,r.cn)(`h-8 w-8`,a),onClick:u,disabled:c||!t,"aria-label":e.subscribed?o(`detail.unsubscribeAriaLabel`):o(`detail.subscribeAriaLabel`),title:e.subscribed?o(`detail.subscribedTooltip`):o(`detail.unsubscribedTooltip`),children:e.subscribed?(0,s.jsx)(i.Bell,{className:`h-4 w-4 text-primary`}):(0,s.jsx)(i.BellOff,{className:`h-4 w-4 text-muted-foreground`})})};function Ee(e){let t=e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).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 De=({value:e,onChange:t,onSubmit:a,mentionSuggestions:o=[],placeholder:c,className:l,disabled:u=!1,extraSlot:d,canSubmitEmpty:f=!1})=>{let{t:p}=E(),[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]),D=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,s.jsxs)(`div`,{className:(0,r.cn)(`border rounded-md`,l),children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-0.5 px-2 py-1.5 border-b bg-muted/30`,children:[(0,s.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:T,disabled:u||m,title:p(`detail.bold`),children:(0,s.jsx)(i.Bold,{className:`h-3.5 w-3.5`})}),(0,s.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:D,disabled:u||m,title:p(`detail.italic`),children:(0,s.jsx)(i.Italic,{className:`h-3.5 w-3.5`})}),(0,s.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:O,disabled:u||m,title:p(`detail.listFormat`),children:(0,s.jsx)(i.List,{className:`h-3.5 w-3.5`})}),(0,s.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:k,disabled:u||m,title:p(`detail.inlineCode`),children:(0,s.jsx)(i.Code,{className:`h-3.5 w-3.5`})}),(0,s.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:A,disabled:u||m,title:p(`detail.mentionSomeone`),children:(0,s.jsx)(i.AtSign,{className:`h-3.5 w-3.5`})}),(0,s.jsx)(`div`,{className:`flex-1`}),(0,s.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,s.jsx)(i.Edit,{className:`h-3.5 w-3.5`}):(0,s.jsx)(i.Eye,{className:`h-3.5 w-3.5`})}),a&&(0,s.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,s.jsx)(i.Send,{className:`h-3.5 w-3.5`})})]}),(0,s.jsx)(`div`,{className:`relative`,children:m?(0,s.jsx)(`div`,{className:`min-h-[80px] px-3 py-2 text-sm prose prose-sm max-w-none`,dangerouslySetInnerHTML:{__html:Ee(e)}}):(0,s.jsxs)(s.Fragment,{children:[(0,s.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:c??p(`detail.writeComment`),value:e,onChange:M,onKeyDown:N,disabled:u}),g&&C.length>0&&(0,s.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,s.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,s.jsx)(`img`,{src:e.avatarUrl,alt:e.label,className:`h-5 w-5 rounded-full object-cover`}):(0,s.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,s.jsx)(`span`,{children:e.label})]},e.id))})]})}),d&&(0,s.jsx)(`div`,{className:`border-t px-2 py-2 bg-muted/20`,children:d})]})};function Oe(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function ke(e){return e.startsWith(`image/`)}function Ae(e){return ke(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 je=({attachments:e,onUpload:t,onRemove:a,className:o,readOnly:c=!1})=>{let{t:l}=E(),[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,s.jsxs)(`div`,{className:(0,r.cn)(`space-y-2`,o),children:[t&&!c&&(0,s.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,s.jsx)(i.Upload,{className:`h-5 w-5 mx-auto text-muted-foreground mb-1`}),(0,s.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:l(`detail.dropFilesToUpload`)}),(0,s.jsx)(`input`,{ref:f,type:`file`,multiple:!0,className:`hidden`,onChange:g})]}),e.length>0&&(0,s.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,s.jsx)(i.Paperclip,{className:`h-3 w-3`}),(0,s.jsx)(`span`,{children:e.length===1?l(`detail.attachmentCount`,{count:e.length}):l(`detail.attachmentCountPlural`,{count:e.length})})]}),(0,s.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2`,children:e.map(e=>{let t=ke(e.type),n=Ae(e.type);return(0,s.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,s.jsx)(`img`,{src:e.thumbnailUrl||e.url,alt:e.name,className:`h-10 w-10 rounded object-cover shrink-0`}):(0,s.jsx)(`div`,{className:`h-10 w-10 rounded bg-muted flex items-center justify-center shrink-0`,children:(0,s.jsx)(n,{className:`h-5 w-5 text-muted-foreground`})}),(0,s.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,s.jsx)(`p`,{className:`text-xs font-medium truncate`,children:e.name}),(0,s.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:Oe(e.size)})]}),a&&!c&&(0,s.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:l(`detail.removeAttachment`),children:(0,s.jsx)(i.X,{className:`h-3.5 w-3.5`})})]},e.id)})})]})]})},Me={comment:i.MessageSquare,field_change:i.Edit,task:i.CheckSquare,event:i.Calendar,system:i.Zap,email:i.Mail,call:i.Phone},Ne={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`};function Pe(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 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}}function Ie(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 Le=({items:e,config:t,filterMode:a,onFilterChange:o,hasMore:c=!1,onLoadMore:l,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}=E(),[C,w]=n.useState(`all`),[T,D]=n.useState(``),[O,k]=n.useState(!1),[A,j]=n.useState(!1),[M,N]=n.useState([]),[P,F]=n.useState(!1),I=a??C,L=t?.showFilterToggle!==!1,R=t?.showCommentInput!==!1&&!!d,z=t?.enableReactions??!1,B=t?.enableThreading??!1,ee=t?.showSubscriptionToggle??!1,V=n.useMemo(()=>Ie(e,I),[e,I]),H=n.useMemo(()=>B?V.filter(e=>!e.parentId):V,[V,B]),U=n.useMemo(()=>{if(!B)return new Map;let e=new Map;for(let t of V)if(t.parentId){let n=e.get(t.parentId)??[];n.push(t),e.set(t.parentId,n)}return e},[V,B]),W=n.useCallback(e=>{o?o(e):w(e)},[o]),te=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),D(``),N([])}finally{k(!1)}}},[T,M,d]),ne=n.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]),G=n.useCallback(e=>{N(t=>t.filter(t=>t.id!==e))},[]),re=n.useCallback(async()=>{if(l){j(!0);try{await l()}finally{j(!1)}}},[l]);return(0,s.jsxs)(`section`,{className:(0,r.cn)(`border-t border-border/60 pt-5`,x),"aria-label":`Discussion`,children:[(0,s.jsx)(`header`,{className:`mb-4`,children:(0,s.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,s.jsxs)(`h2`,{className:`flex items-center gap-2 text-base font-semibold leading-none tracking-tight`,children:[(0,s.jsx)(i.Activity,{className:`h-4 w-4`}),y??S(`detail.activity`),(0,s.jsxs)(`span`,{className:`text-sm font-normal text-muted-foreground`,children:[`(`,V.length,`)`]})]}),(0,s.jsx)(`div`,{className:`flex items-center gap-1`,children:ee&&m&&(0,s.jsx)($,{subscription:m,onToggle:h})})]})}),(0,s.jsxs)(`div`,{className:`space-y-4`,children:[L&&(0,s.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,s.jsxs)(r.Select,{value:I,onValueChange:e=>W(e),children:[(0,s.jsx)(r.SelectTrigger,{"aria-label":S(`detail.filterActivity`),className:`h-8 w-auto min-w-[140px] py-1 text-sm`,children:(0,s.jsx)(r.SelectValue,{})}),(0,s.jsx)(r.SelectContent,{children:Pe(S).map(e=>(0,s.jsx)(r.SelectItem,{value:e.value,children:e.label},e.value))})]})}),R&&(0,s.jsx)(De,{value:T,onChange:D,onSubmit:te,mentionSuggestions:_,placeholder:S(`detail.leaveCommentPlaceholder`),disabled:O,canSubmitEmpty:M.length>0,extraSlot:v?(0,s.jsx)(je,{attachments:M,onUpload:ne,onRemove:G,readOnly:O||P}):M.length>0?(0,s.jsx)(je,{attachments:M,onRemove:G,readOnly:O}):void 0}),V.length===0?g?null:(0,s.jsx)(r.DataEmptyState,{title:b??S(`detail.noActivity`),className:`py-6`}):(0,s.jsxs)(`div`,{className:`relative`,children:[(0,s.jsx)(`div`,{className:`absolute left-4 top-2 bottom-2 w-px bg-border`}),(0,s.jsx)(`div`,{className:`space-y-4`,children:H.map(e=>{let t=Me[e.type]||i.Zap,n=Ne[e.type]||`bg-gray-100 text-gray-600`,a=U.get(e.id)??[];return(0,s.jsxs)(`div`,{children:[(0,s.jsxs)(`div`,{className:`flex gap-3 relative`,children:[(0,s.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,s.jsx)(`img`,{src:e.actorAvatarUrl,alt:e.actor,className:`h-8 w-8 rounded-full object-cover`}):(0,s.jsx)(t,{className:`h-3.5 w-3.5`})}),(0,s.jsxs)(`div`,{className:`flex-1 min-w-0 pt-1`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-2 mb-0.5`,children:[(0,s.jsx)(`span`,{className:`text-sm font-medium`,children:e.actor}),e.source&&(0,s.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:S(`detail.via`,{source:e.source})}),(0,s.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:Fe(e.createdAt,S)}),e.edited&&(0,s.jsx)(`span`,{className:`text-xs text-muted-foreground italic`,children:S(`detail.edited`)}),e.pinned&&(0,s.jsxs)(`span`,{className:`text-xs text-amber-600`,children:[`📌 `,S(`detail.pinned`)]})]}),e.body&&(0,s.jsx)(`p`,{className:`text-sm whitespace-pre-wrap break-words text-muted-foreground`,children:e.body}),e.sourceObject&&e.sourceId!=null&&(0,s.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,s.jsx)(`span`,{"aria-hidden":!0,children:`→`})]}),e.type===`field_change`&&e.fieldChanges&&(0,s.jsx)(`div`,{className:`space-y-1 mt-1`,children:e.fieldChanges.map((e,t)=>(0,s.jsx)(xe,{change:e},t))}),z&&e.reactions&&e.reactions.length>0&&(0,s.jsx)(`div`,{className:`mt-1.5`,children:(0,s.jsx)(Ce,{reactions:e.reactions,onToggleReaction:p?t=>p(e.id,t):void 0})}),z&&(!e.reactions||e.reactions.length===0)&&p&&(0,s.jsx)(`div`,{className:`mt-1.5`,children:(0,s.jsx)(Ce,{reactions:[],onToggleReaction:t=>p(e.id,t)})})]})]}),B&&(e.replyCount??0)>0&&(0,s.jsx)(Te,{parentItem:e,replies:a,onAddReply:f,showReplyInput:!!f})]},e.id)})})]}),c&&(0,s.jsx)(`div`,{className:`text-center pt-2`,children:(0,s.jsxs)(r.Button,{variant:`ghost`,size:`sm`,onClick:re,disabled:A,"aria-label":S(`detail.loadMore`),children:[A?(0,s.jsx)(i.Loader2,{className:`h-4 w-4 animate-spin mr-1`}):(0,s.jsx)(i.ChevronDown,{className:`h-4 w-4 mr-1`}),S(`detail.loadMore`)]})})]})]})},Re=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}=Re(n);return(0,s.jsx)(`div`,{className:t,...r,children:(0,s.jsx)(Le,{items:[],config:e})})},Be=({config:e,items:t,hasMore:a,onLoadMore:o,loading:c,onAddComment:l,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}=E(),[T,D]=n.useState(C);return b===`right`||b===`left`?T&&S?(0,s.jsx)(`div`,{className:(0,r.cn)(`flex items-start pt-4`,b===`right`?`border-l`:`border-r`,y),children:(0,s.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-8 w-8 mx-1`,onClick:()=>D(!1),"aria-label":w(`detail.openDiscussion`),children:(0,s.jsx)(i.PanelRightOpen,{className:`h-4 w-4`})})}):(0,s.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,s.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,s.jsx)(i.MessageSquare,{className:`h-4 w-4`}),(0,s.jsx)(`span`,{className:`text-sm font-medium`,children:w(`detail.discussion`)})]}),S&&(0,s.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:()=>D(!0),"aria-label":w(`detail.closeDiscussion`),children:(0,s.jsx)(i.X,{className:`h-3.5 w-3.5`})})]}),(0,s.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:(0,s.jsx)(Le,{items:t,config:e?.feed,hasMore:a,onLoadMore:o,loading:c,onAddComment:l,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,s.jsx)(`div`,{className:(0,r.cn)(``,y),children:S&&T?(0,s.jsxs)(r.Button,{variant:`ghost`,className:`w-full justify-start gap-2 text-muted-foreground`,onClick:()=>D(!1),"aria-label":w(`detail.showDiscussion`,{count:t.length}),children:[(0,s.jsx)(i.MessageSquare,{className:`h-4 w-4`}),(0,s.jsx)(`span`,{children:w(`detail.showDiscussion`,{count:t.length})})]}):(0,s.jsxs)(`div`,{children:[S&&(0,s.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium`,children:[(0,s.jsx)(i.MessageSquare,{className:`h-4 w-4`}),w(`detail.discussion`)]}),(0,s.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:()=>D(!0),"aria-label":w(`detail.hideDiscussion`),children:(0,s.jsx)(i.PanelRightClose,{className:`h-3.5 w-3.5`})})]}),(0,s.jsx)(Le,{items:t,config:e?.feed,hasMore:a,onLoadMore:o,loading:c,onAddComment:l,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`)})]})})},Ve=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}},He=({schema:e={},className:t,...n})=>{(0,a.useRecordContext)();let r=(0,a.useDiscussionContext)(),{designer:i}=Ve(n),o={position:`bottom`,collapsible:!1,feed:{enableReactions:!0,enableThreading:!0,showCommentInput:!0},...e};return(0,s.jsx)(`div`,{className:t,...i,children:(0,s.jsx)(Be,{items:r?.items||[],config:o,onAddComment:r?.onAddComment,onAddReply:r?.onAddReply,onToggleReaction:r?.onToggleReaction,mentionSuggestions:r?.mentionSuggestions,onUploadAttachments:r?.onUploadAttachments})})},Ue=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:t,...i})=>{let o=(0,a.useRecordContext)(),{translateOptions:c}=(0,a.useSafeFieldLabel)(),{designer:l}=Ue(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=c(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,c]),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,s.jsx)(`div`,{className:t,...l,children:(0,s.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,s.jsxs)(`div`,{className:(0,r.cn)(`w-full`,t),...l,children:[(0,s.jsxs)(`div`,{className:`hidden sm:flex w-full items-stretch gap-2`,role:`list`,"aria-label":e.aria?.label||`Record path`,children:[(0,s.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,s.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,s.jsxs)(`span`,{className:`inline-flex items-center justify-center gap-1.5 truncate`,children:[n&&(0,s.jsx)(`span`,{"aria-hidden":!0,className:`text-emerald-600 dark:text-emerald-400 font-semibold`,children:`✓`}),a&&!i&&(0,s.jsx)(`span`,{"aria-hidden":!0,className:`opacity-70`,children:`🏆`}),e.label]})},`${e.value}-${t}`)})}),y.length>0&&(0,s.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,s.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,s.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,s.jsx)(`span`,{"aria-hidden":!0,className:`opacity-70`,children:`✗`}),e.label]})},`${e.value}-lost-${t}`)})})]}),(0,s.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,s.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,s.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[n&&(0,s.jsx)(`span`,{"aria-hidden":!0,className:`opacity-70`,children:`✗`}),!n&&i&&(0,s.jsx)(`span`,{"aria-hidden":!0,className:`text-emerald-600 dark:text-emerald-400 font-semibold`,children:`✓`}),e.label]})},`${e.value}-${t}-m`)})})]})},Ge=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,...n})=>{let i=(0,a.useRecordContext)(),{designer:o}=Ge(n),l=(0,c.usePermissions)(),u=Array.isArray(e.actions)?e.actions:Array.isArray(e.properties?.actions)?e.properties.actions:[],d=Array.isArray(e.actionNames)?e.actionNames:Array.isArray(e.properties?.actionNames)?e.properties.actionNames:[],f=i?.objectName||``,p=d.length>0?d:Array.isArray(u)&&u.every(e=>typeof e==`string`)?u:[],m=p.length>0&&!!f,{item:h}=(0,a.useMetadataItem)(`object`,m?f:null),g=m?(()=>{let e=Array.isArray(h?.actions)?h.actions:[],t=new Map(e.map(e=>[e.name,e]));return p.map(e=>t.get(e)).filter(e=>!!e)})():Array.isArray(u)?u:[],_=Array.isArray(e.requiredPermissions)?e.requiredPermissions:[];if(_.length>0&&f&&!_.every(e=>l.can(f,e)))return(0,s.jsx)(`div`,{className:t,...o,role:`status`,"aria-live":`polite`,children:(0,s.jsx)(`p`,{className:`text-sm text-muted-foreground italic`,children:`Insufficient permissions to view quick actions.`})});let v=e.location||`record_header`,{getActionsForLocation:y,executeAction:b}=(0,a.useActionEngine)({actions:g,context:{record:i?.data,recordId:i?.recordId,objectName:i?.objectName}}),x=g.length>0?y(v):[];if(x.length===0)return(0,s.jsx)(`div`,{className:t,...o,children:(0,s.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 S=e.align||`end`,C=S===`start`?`justify-start`:S===`center`?`justify-center`:`justify-end`;return(0,s.jsx)(`div`,{className:(0,r.cn)(`flex flex-wrap items-center gap-2`,v===`record_header`&&!e.inline&&`-mt-12 sm:-mt-14 mb-2 relative z-10`,C,t),role:`toolbar`,"aria-label":e.aria?.label||`Quick actions`,...o,children:x.map((t,n)=>(0,s.jsx)(qe,{action:t,record:i?.data,variant:t.variant||e.variant||`default`,size:t.size||e.size||`sm`,label:t.label||t.name||`Action ${n+1}`,onRun:async()=>{typeof t.onClick==`function`?await t.onClick():t.name&&await b(t.name)}},t.name||`qa-${n}`))})};function qe({action:e,record:t,variant:o,size:c,label:l,onRun:u}){let[d,f]=n.default.useState(!1),p=n.default.useMemo(()=>({record:t||{}}),[t]),m=(0,a.toPredicateInput)(e.disabled),h=(0,a.useCondition)(typeof m==`string`?m:void 0,p);return(0,s.jsxs)(r.Button,{variant:o,size:c,disabled:(typeof m==`string`?h:m===!0)||d,onClick:async()=>{f(!0);try{await u()}finally{f(!1)}},children:[d&&(0,s.jsx)(i.Loader2,{className:`mr-2 h-4 w-4 animate-spin`}),l]})}var 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}},Ye=new Set([`created`,`updated`,`assigned`,`shared`,`deleted`]),Xe=({schema:e={},className:t,...r})=>{let{designer:i}=Je(r),o=(0,a.useRecordContext)(),c=Array.isArray(e.entries)?e.entries:Array.isArray(e.properties?.entries)?e.properties.entries:void 0,l=e.loading??e.properties?.loading,u=e.emptyText??e.properties?.emptyText,d=Number(e.limit??e.properties?.limit??50)||50,f=o?.objectName,p=o?.data?.id??o?.data?._id??o?.recordId,m=o?.dataSource,h=c===void 0&&!!m?.find&&!!f&&p!=null,[g,_]=n.default.useState(null),[v,y]=n.default.useState(!1);n.default.useEffect(()=>{if(!h)return;let e=!1;return y(!0),Promise.resolve(m.find(`sys_activity`,{$filter:{object_name:f,record_id:p},$orderby:{timestamp:`desc`},$top:Math.max(1,d)})).then(t=>{if(e)return;let n=(t?.data??t?.records??[]).filter(e=>Ye.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}});_(n)}).catch(()=>{e||_([])}).finally(()=>{e||y(!1)}),()=>{e=!0}},[h,m,f,p,d]);let b=c??g??[],x=l??(h&&g===null?v||!0:!1);return(0,s.jsx)(`div`,{className:t,...i,children:(0,s.jsx)(ie,{entries:b,loading:x,emptyText:u})})},Ze=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}},Qe=e=>e.replace(/[_-]+/g,` `).replace(/\b\w/g,e=>e.toUpperCase()).trim(),$e=(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||`—`,et=({schema:e={},className:t,...o})=>{let c=(0,a.useRecordContext)(),l=(0,a.useSafeFieldLabel)(),{t:d}=E(),{designer:f}=Ze(o),p=(0,u.useParams)().appName,m=Array.isArray(e.entries)?e.entries:Array.isArray(e.properties?.entries)?e.properties.entries:[],h=c?.recordId,g=c?.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}`));if(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]),m.length===0)return null;let T=e.hideEmpty!==!1,[D,O]=n.default.useState(!1),k=new Set(m.filter(e=>{let t=_[e.objectName];return T&&t&&!t.loading&&!t.error&&t.total===0}).map(e=>e.objectName)),A=m.filter(e=>D||!k.has(e.objectName)),j=m.filter(e=>k.has(e.objectName)).map(e=>e.title||(l?.objectLabel?l.objectLabel({name:e.objectName,label:Qe(e.objectName)}):Qe(e.objectName)));return(0,s.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,s.jsxs)(r.Card,{className:`overflow-hidden`,children:[(0,s.jsxs)(r.CardHeader,{className:`flex flex-row items-center justify-between gap-2 py-3 px-4 space-y-0 border-b`,children:[(0,s.jsx)(r.CardTitle,{className:`text-sm font-semibold tracking-tight truncate`,children:e.title||(l?.objectLabel?l.objectLabel({name:e.objectName,label:Qe(e.objectName)}):Qe(e.objectName))}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[!n.loading&&(0,s.jsx)(r.Badge,{variant:`secondary`,className:`tabular-nums`,children:n.total}),p&&h&&(0,s.jsx)(u.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,s.jsx)(r.CardContent,{className:`p-0`,children:n.loading?(0,s.jsxs)(`div`,{className:`space-y-1.5 p-3`,children:[(0,s.jsx)(r.Skeleton,{className:`h-3.5 w-4/5`}),(0,s.jsx)(r.Skeleton,{className:`h-3.5 w-3/5`}),(0,s.jsx)(r.Skeleton,{className:`h-3.5 w-2/3`})]}):n.items.length===0?(0,s.jsx)(`p`,{className:`px-4 py-3 text-xs text-muted-foreground`,children:d(`detail.noRecords`)}):(0,s.jsx)(`ul`,{className:`divide-y`,children:n.items.map(t=>{let n=t.id||t._id,r=$e(t,e.displayField),a=n?`../${e.objectName}/record/${encodeURIComponent(String(n))}`:void 0;return(0,s.jsx)(`li`,{className:`px-4 py-2`,children:a?(0,s.jsxs)(u.Link,{to:a,className:`group flex items-center justify-between gap-2 text-xs hover:text-foreground text-muted-foreground transition-colors`,children:[(0,s.jsx)(`span`,{className:`truncate`,children:r}),(0,s.jsx)(i.ChevronRight,{className:`h-3 w-3 shrink-0 opacity-0 group-hover:opacity-100 transition-opacity`})]}):(0,s.jsx)(`span`,{className:`block truncate text-xs text-muted-foreground`,children:r})},String(n||r))})})})]},t)}),!D&&j.length>0&&(0,s.jsxs)(`button`,{type:`button`,onClick:()=>O(!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,s.jsx)(`span`,{children:d(`detail.showEmptyRelated`,{defaultValue:`+ {{count}} empty`,count:j.length})}),(0,s.jsxs)(`span`,{className:`truncate max-w-[180px] text-muted-foreground/70`,children:[`(`,j.join(` · `),`)`]})]})]})},tt={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 nt(e){let t=e?.properties??{};return{...e,...t}}var rt=({schema:e={},className:t})=>{let i=nt(e),o=(0,a.useRecordContext)(),c=o?.data,l=o?.objectName||``,u=o?.recordId??c?.id,d=[`info`,`warning`,`error`,`success`].includes(i.severity)?i.severity:`info`,f=tt[d],p=i.icon||f.icon,m=(0,a.toPredicateInput)(i.visible),h=(0,a.useCondition)(m,{record:c}),g=n.useMemo(()=>{if(!i.dismissible)return null;let e=i.dismissKey||i.title||d;return`os.record-alert:${l}:${u??`_`}:${e}`},[i.dismissible,i.dismissKey,i.title,d,l,u]),[_,v]=n.useState(()=>{if(!g||typeof window>`u`)return!1;try{return window.localStorage.getItem(g)===`1`}catch{return!1}}),y=i.action?.actionName,{item:b}=(0,a.useMetadataItem)(`object`,y&&l?l:null),x=n.useMemo(()=>{if(!(!y||!b?.actions))return b.actions.find(e=>e.name===y)},[y,b]),{executeAction:S}=(0,a.useActionEngine)({actions:n.useMemo(()=>x?[x]:[],[x]),context:{record:c,recordId:u,objectName:l}});return _||!c||Object.keys(c).length===0||m!==void 0&&!h?null:(0,s.jsxs)(r.Alert,{className:(0,r.cn)(`relative pr-12`,f.wrap,t),role:d===`error`?`alert`:`status`,"aria-live":d===`error`?`assertive`:`polite`,children:[(0,s.jsx)(r.LazyIcon,{name:p,className:`h-4 w-4`,"aria-hidden":`true`}),i.title?(0,s.jsx)(r.AlertTitle,{children:i.title}):null,i.body||x?(0,s.jsxs)(r.AlertDescription,{children:[i.body?(0,s.jsx)(`p`,{className:`mb-2 last:mb-0`,children:i.body}):null,x?(0,s.jsx)(r.Button,{size:`sm`,variant:i.action?.variant||(d===`error`?`destructive`:`default`),onClick:()=>{x?.name&&S(x.name)},children:i.action?.label||x.label||x.name}):null]}):null,i.dismissible?(0,s.jsx)(`button`,{type:`button`,onClick:()=>{if(v(!0),g)try{window.localStorage.setItem(g,`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,s.jsx)(r.LazyIcon,{name:`X`,className:`h-4 w-4`,"aria-hidden":`true`})}):null]})},it=new Set([`id`,`_id`,`__v`,`created_at`,`updated_at`,`createdAt`,`updatedAt`,`created_by`,`updated_by`,`organization_id`,`tenant_id`,`owner_id`,`deleted_at`,`is_deleted`]),at=480,ot=95;function st({open:e,onClose:t,title:i,record:a,objectName:o,recordId:c,dataSource:l,objectSchema:u,width:d=`min(960px, 60vw)`,columns:f=2,systemFields:p=it,onFieldSave:m,onDelete:h,resizable:g=!0,fullPageHref:_}){let{t:v}=E(),y=`objectui.drawerWidth.${o}`,[b,x]=n.default.useState(()=>{if(typeof window>`u`||!g)return null;try{let e=window.localStorage.getItem(y);if(e){let t=parseInt(e,10);if(Number.isFinite(t)&&t>=at)return t}}catch{}return null}),S=n.default.useMemo(()=>g&&b!=null?`${b}px`:typeof d==`number`?`${d}px`:d,[g,b,d]),C=S?{width:S,maxWidth:S}:void 0,w=n.default.useRef(null),T=n.default.useCallback(e=>{if(!g)return;e.preventDefault();let t=b??(typeof window<`u`?Math.min(window.innerWidth*.6,960):720);w.current={startX:e.clientX,startWidth:t};let n=e=>{let t=w.current;if(!t)return;let n=t.startX-e.clientX,r=typeof window<`u`?window.innerWidth*ot/100:1600,i=Math.min(r,Math.max(at,t.startWidth+n));x(Math.round(i))},r=()=>{w.current,w.current=null,window.removeEventListener(`pointermove`,n),window.removeEventListener(`pointerup`,r),window.removeEventListener(`pointercancel`,r);try{x(e=>(e!=null&&window.localStorage.setItem(y,String(e)),e))}catch{}};window.addEventListener(`pointermove`,n),window.addEventListener(`pointerup`,r),window.addEventListener(`pointercancel`,r)},[g,b,y]),D=u?.fields??{},O=(Object.keys(D).length?Object.keys(D):Object.keys(a)).filter(e=>!p.has(e)&&!e.startsWith(`__`)).filter(e=>e in a).filter(e=>!D[e]?.hidden).map(e=>{let t=D[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.referenceTo??t.target,reference_field:t.reference_field??t.referenceField,required:t.required,validation:t.validation,placeholder:t.placeholder,description:t.description}});return(0,s.jsx)(r.Sheet,{open:e,onOpenChange:e=>{e||t()},children:(0,s.jsxs)(r.SheetContent,{side:`right`,className:`w-full overflow-y-auto p-0 sm:!max-w-none`,style:C,onOpenAutoFocus:e=>e.preventDefault(),children:[g&&(0,s.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize drawer`,onPointerDown:T,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,s.jsx)(r.SheetHeader,{className:`sr-only`,children:(0,s.jsx)(r.SheetTitle,{children:i})}),(0,s.jsx)(`div`,{className:`px-6 pt-6 pb-6`,children:(0,s.jsx)(fe,{dataSource:l,inlineEdit:!0,schema:{type:`detail-view`,objectName:o,resourceId:String(c),data:a,showDelete:!0,columns:f,fields:O,actions:_?[{type:`action:bar`,location:`record_header`,systemActions:[{name:`sys_open_new_tab`,label:v(`detail.openInNewTab`),icon:`external-link`,type:`script`,onClick:()=>window.open(_,`_blank`,`noopener`)}]}]:void 0},onFieldSave:async(e,t)=>{try{await m?.(e,t)}catch(e){console.error(`[RecordDetailDrawer] inline field save failed:`,e)}},onDelete:async()=>{try{await h?.(),t()}catch(e){console.error(`[RecordDetailDrawer] delete failed:`,e)}}})})]})})}function ct(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 lt=({objectName:e,relationshipField:t,fields:a,onCreateRecord:o,onLinkRecord:c,onSearch:l,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),l&&e.trim().length>=2){T(!0);try{let t=await l(e);x(t)}finally{T(!1)}}},[l]),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(c){C(!0);try{await c(e),y(``),p(!1)}finally{C(!1)}}},[c]),j=n.useMemo(()=>a.filter(e=>e.required).every(e=>g[e.name]?.toString().trim()),[a,g]);return f?(0,s.jsxs)(r.Card,{className:(0,r.cn)(``,d),children:[(0,s.jsx)(r.CardHeader,{className:`pb-3`,children:(0,s.jsxs)(r.CardTitle,{className:`flex items-center justify-between text-sm`,children:[(0,s.jsxs)(`span`,{children:[m===`create`?`Create`:`Link`,` `,e]}),(0,s.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-6 w-6`,onClick:()=>p(!1),children:(0,s.jsx)(i.X,{className:`h-3.5 w-3.5`})})]})}),(0,s.jsx)(r.CardContent,{children:(0,s.jsxs)(r.Tabs,{value:m,onValueChange:h,children:[(0,s.jsxs)(r.TabsList,{className:`mb-3 w-full`,children:[o&&(0,s.jsxs)(r.TabsTrigger,{value:`create`,className:`flex-1 gap-1.5`,children:[(0,s.jsx)(i.Plus,{className:`h-3.5 w-3.5`}),`Create New`]}),c&&(0,s.jsxs)(r.TabsTrigger,{value:`link`,className:`flex-1 gap-1.5`,children:[(0,s.jsx)(i.Link,{className:`h-3.5 w-3.5`}),`Link Existing`]})]}),o&&(0,s.jsxs)(r.TabsContent,{value:`create`,className:`space-y-3 mt-0`,children:[a.map(e=>(0,s.jsxs)(`div`,{children:[(0,s.jsxs)(`label`,{className:`text-xs font-medium text-muted-foreground mb-1 block`,children:[e.label,e.required&&(0,s.jsx)(`span`,{className:`text-destructive ml-0.5`,children:`*`})]}),(0,s.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,s.jsxs)(`div`,{className:`flex justify-end gap-2 pt-1`,children:[(0,s.jsx)(r.Button,{variant:`ghost`,size:`sm`,onClick:()=>p(!1),children:`Cancel`}),(0,s.jsxs)(r.Button,{size:`sm`,onClick:k,disabled:!j||S,className:`gap-1.5`,children:[S&&(0,s.jsx)(i.Loader2,{className:`h-3.5 w-3.5 animate-spin`}),`Create`]})]})]}),c&&(0,s.jsxs)(r.TabsContent,{value:`link`,className:`space-y-3 mt-0`,children:[(0,s.jsxs)(`div`,{className:`relative`,children:[(0,s.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,s.jsx)(r.Input,{placeholder:`Search ${e}…`,value:v,onChange:e=>D(e.target.value),className:`h-8 text-sm pl-8`})]}),(0,s.jsx)(`div`,{className:`max-h-48 overflow-y-auto space-y-1`,children:w?(0,s.jsxs)(`div`,{className:`flex items-center justify-center py-4 text-sm text-muted-foreground`,children:[(0,s.jsx)(i.Loader2,{className:`h-4 w-4 animate-spin mr-2`}),`Searching…`]}):E.length===0?(0,s.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,s.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,s.jsx)(`span`,{className:`font-medium`,children:e.label}),e.description&&(0,s.jsx)(`span`,{className:`block text-xs text-muted-foreground mt-0.5`,children:e.description})]},e.id))})]})]})})]}):(0,s.jsxs)(`div`,{className:(0,r.cn)(`flex gap-2`,d),children:[o&&(0,s.jsxs)(r.Button,{variant:`outline`,size:`sm`,onClick:()=>{h(`create`),p(!0)},className:`gap-1.5`,children:[(0,s.jsx)(i.Plus,{className:`h-3.5 w-3.5`}),`New `,e]}),c&&(0,s.jsxs)(r.Button,{variant:`outline`,size:`sm`,onClick:()=>{h(`link`),p(!0)},className:`gap-1.5`,children:[(0,s.jsx)(i.Link,{className:`h-3.5 w-3.5`}),`Link Existing`]})]})};function ut(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 dt(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 ft={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`},pt={added:`+`,removed:`-`,unchanged:` `},mt=({oldValue:e,newValue:t,fieldName:a,fieldType:o=`string`,mode:c=`unified`,className:l})=>{let{t:u}=E(),[d,f]=n.useState(c),p=n.useMemo(()=>ut(e,o),[e,o]),m=n.useMemo(()=>ut(t,o),[t,o]),h=n.useMemo(()=>dt(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,s.jsxs)(r.Card,{className:(0,r.cn)(`overflow-hidden`,l),children:[(0,s.jsx)(r.CardHeader,{className:`pb-2`,children:(0,s.jsxs)(r.CardTitle,{className:`flex items-center justify-between text-sm`,children:[(0,s.jsx)(`span`,{className:`font-medium`,children:a}),(0,s.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,s.jsx)(r.Button,{variant:d===`unified`?`secondary`:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:()=>f(`unified`),title:u(`detail.unifiedDiff`),children:(0,s.jsx)(i.Rows3,{className:`h-3.5 w-3.5`})}),(0,s.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,s.jsx)(i.Columns2,{className:`h-3.5 w-3.5`})})]})]})}),(0,s.jsx)(r.CardContent,{className:`p-0`,children:g?d===`unified`?(0,s.jsx)(`div`,{className:`font-mono text-xs overflow-x-auto`,children:h.map((e,t)=>(0,s.jsxs)(`div`,{className:(0,r.cn)(`px-4 py-0.5 whitespace-pre-wrap border-l-2`,ft[e.type],e.type===`added`&&`border-l-green-500`,e.type===`removed`&&`border-l-red-500`,e.type===`unchanged`&&`border-l-transparent`),children:[(0,s.jsx)(`span`,{className:`select-none mr-2 inline-block w-3 text-center opacity-60`,children:pt[e.type]}),e.value]},t))}):(0,s.jsx)(`div`,{className:`overflow-x-auto`,children:(0,s.jsxs)(`div`,{className:`grid grid-cols-2 divide-x font-mono text-xs min-w-0`,children:[(0,s.jsx)(`div`,{className:`px-3 py-1.5 text-xs font-medium text-muted-foreground bg-muted/50`,children:u(`detail.previousVersion`)}),(0,s.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,s.jsxs)(n.Fragment,{children:[(0,s.jsx)(`div`,{className:(0,r.cn)(`px-3 py-0.5 whitespace-pre-wrap min-h-[1.5em]`,e.left?ft[e.left.type]:`bg-muted/20`),children:e.left?.value??``}),(0,s.jsx)(`div`,{className:(0,r.cn)(`px-3 py-0.5 whitespace-pre-wrap min-h-[1.5em]`,e.right?ft[e.right.type]:`bg-muted/20`),children:e.right?.value??``})]},t))]})}):(0,s.jsx)(`p`,{className:`px-4 py-3 text-sm text-muted-foreground`,children:u(`detail.noChanges`)})})]})},ht=({currentIndex:e,totalRecords:t,recordIds:a,onNavigate:o,onSearch:c,className:l})=>{let{t:u}=E(),[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),c?.(t)},[c]),T=n.useCallback(()=>{m(e=>(e?(f(``),c?.(``)):requestAnimationFrame(()=>h.current?.focus()),!e))},[c]);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(``),c?.(``),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,c]),(0,s.jsxs)(`div`,{className:(0,r.cn)(`flex items-center gap-1.5`,l),children:[(0,s.jsx)(r.Button,{variant:`outline`,size:`icon`,className:`h-8 w-8`,disabled:!g,onClick:b,title:u(`detail.firstRecord`),children:(0,s.jsx)(i.ChevronsLeft,{className:`h-4 w-4`})}),(0,s.jsx)(r.Button,{variant:`outline`,size:`icon`,className:`h-8 w-8`,disabled:!_,onClick:x,title:u(`detail.previousRecordKey`),children:(0,s.jsx)(i.ChevronLeft,{className:`h-4 w-4`})}),(0,s.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,s.jsx)(r.Button,{variant:`outline`,size:`icon`,className:`h-8 w-8`,disabled:!v,onClick:S,title:u(`detail.nextRecordKey`),children:(0,s.jsx)(i.ChevronRight,{className:`h-4 w-4`})}),(0,s.jsx)(r.Button,{variant:`outline`,size:`icon`,className:`h-8 w-8`,disabled:!y,onClick:C,title:u(`detail.lastRecord`),children:(0,s.jsx)(i.ChevronsRight,{className:`h-4 w-4`})}),c&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(r.Button,{variant:p?`secondary`:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:T,title:u(`detail.searchWhileNavigating`),children:(0,s.jsx)(i.Search,{className:`h-4 w-4`})}),p&&(0,s.jsx)(`div`,{className:`relative`,children:(0,s.jsx)(r.Input,{ref:h,type:`text`,placeholder:u(`detail.searchRecords`),value:d,onChange:w,className:`h-8 w-48 text-sm`})})]})]})},gt=28,_t=[`fill-primary stroke-primary`,`fill-blue-500 stroke-blue-500`,`fill-emerald-500 stroke-emerald-500`,`fill-amber-500 stroke-amber-500`],vt=[`fill-primary-foreground`,`fill-white`,`fill-white`,`fill-white`];function yt(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 bt(e,t=6){return e.length<=t?e:e.slice(0,t-1)+`…`}var xt=({record:e,relatedRecords:t,levels:a=1,onNodeClick:o,className:c})=>{let l=n.useRef(null),[u,d]=n.useState({width:500,height:400}),[f,p]=n.useState(null);n.useEffect(()=>{let e=l.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(()=>yt(e,t,a,u.width,u.height),[e,t,a,u]);return(0,s.jsxs)(r.Card,{className:(0,r.cn)(`overflow-hidden`,c),children:[(0,s.jsx)(r.CardHeader,{className:`pb-2`,children:(0,s.jsxs)(r.CardTitle,{className:`flex items-center gap-2 text-base`,children:[(0,s.jsx)(i.Network,{className:`h-4 w-4`}),`Relationships`,(0,s.jsxs)(`span`,{className:`text-sm font-normal text-muted-foreground`,children:[`(`,t.length,` related)`]})]})}),(0,s.jsx)(r.CardContent,{className:`p-0`,children:(0,s.jsxs)(`svg`,{ref:l,width:`100%`,height:u.height,viewBox:`0 0 ${u.width} ${u.height}`,className:`select-none`,children:[h.map((e,t)=>(0,s.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=_t[Math.min(e.level,_t.length-1)],i=vt[Math.min(e.level,vt.length-1)],a=e.level===0?34:gt;return(0,s.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,s.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,s.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:bt(e.label)}),e.type&&(0,s.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,s.jsxs)(s.Fragment,{children:[(0,s.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,s.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 St(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 Ct=({recordId:e,revisions:t,onRestore:a,className:o})=>{let[c,l]=n.useState(null),[u,d]=n.useState(!1),[f,p]=n.useState(!1),m=n.useMemo(()=>t.find(e=>e.id===c)??null,[t,c]),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),l(null)}finally{p(!1)}}},[m,a,u]),g=n.useCallback(()=>{d(!1)},[]);return(0,s.jsxs)(r.Card,{className:(0,r.cn)(``,o),children:[(0,s.jsx)(r.CardHeader,{className:`pb-3`,children:(0,s.jsxs)(r.CardTitle,{className:`flex items-center gap-2 text-base`,children:[(0,s.jsx)(i.History,{className:`h-4 w-4`}),`Revision History`,(0,s.jsxs)(`span`,{className:`text-sm font-normal text-muted-foreground`,children:[`(`,t.length,`)`]})]})}),(0,s.jsx)(r.CardContent,{children:t.length===0?(0,s.jsx)(`p`,{className:`text-sm text-muted-foreground text-center py-4`,children:`No revisions recorded`}):(0,s.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-4`,children:[(0,s.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,s.jsxs)(`div`,{className:`relative`,children:[(0,s.jsx)(`div`,{className:`absolute left-3 top-2 bottom-2 w-px bg-border`}),(0,s.jsx)(`div`,{className:`space-y-1`,children:t.map(e=>{let t=e.id===c;return(0,s.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:()=>{l(e.id),d(!1)},children:[(0,s.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,s.jsx)(i.ChevronRight,{className:`h-3 w-3 text-primary-foreground`})}),(0,s.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,s.jsx)(`span`,{className:`text-sm font-medium`,children:e.user}),(0,s.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:St(e.timestamp)})]}),(0,s.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,s.jsxs)(`div`,{className:`lg:w-80 border rounded-md p-3 space-y-3`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium`,children:[(0,s.jsx)(i.Eye,{className:`h-4 w-4 text-muted-foreground`}),`Revision Preview`]}),(0,s.jsx)(`div`,{className:`space-y-2`,children:m.changes.map((e,t)=>(0,s.jsxs)(`div`,{className:`text-xs`,children:[(0,s.jsx)(`span`,{className:`font-medium text-muted-foreground`,children:e.field}),(0,s.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-0.5`,children:[(0,s.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,s.jsx)(i.ChevronRight,{className:`h-3 w-3 text-muted-foreground shrink-0`}),(0,s.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,s.jsxs)(`div`,{className:`border-t pt-2 space-y-1`,children:[(0,s.jsx)(`p`,{className:`text-xs font-medium text-muted-foreground`,children:`Record state at this point`}),(0,s.jsx)(`div`,{className:`max-h-40 overflow-y-auto space-y-1`,children:Object.entries(m.snapshot).map(([e,t])=>(0,s.jsxs)(`div`,{className:`flex justify-between text-xs gap-2`,children:[(0,s.jsx)(`span`,{className:`text-muted-foreground truncate`,children:e}),(0,s.jsx)(`span`,{className:`font-mono truncate max-w-[140px]`,children:t==null?`–`:String(t)})]},e))})]}),a&&(0,s.jsx)(`div`,{className:`pt-1 space-y-2`,children:u?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(`p`,{className:`text-xs text-amber-600 dark:text-amber-400`,children:[`This will restore the record to its state at`,` `,St(m.timestamp),`. Continue?`]}),(0,s.jsxs)(`div`,{className:`flex gap-2`,children:[(0,s.jsxs)(r.Button,{variant:`destructive`,size:`sm`,className:`gap-1.5 flex-1`,onClick:h,disabled:f,children:[(0,s.jsx)(i.RotateCcw,{className:`h-3.5 w-3.5`}),f?`Restoring…`:`Confirm Restore`]}),(0,s.jsx)(r.Button,{variant:`ghost`,size:`sm`,onClick:g,disabled:f,children:`Cancel`})]})]}):(0,s.jsxs)(r.Button,{variant:`outline`,size:`sm`,className:`w-full gap-1.5`,onClick:h,children:[(0,s.jsx)(i.RotateCcw,{className:`h-3.5 w-3.5`}),`Restore to this point`]})})]})]})})]})},wt=({onSubmit:e,placeholder:t=`Leave a comment…`,disabled:a=!1,className:o})=>{let[c,l]=n.useState(``),[u,d]=n.useState(!1),f=n.useCallback(async()=>{let t=c.trim();if(t){d(!0);try{await e(t),l(``)}finally{d(!1)}}},[c,e]),p=n.useCallback(e=>{e.key===`Enter`&&(e.ctrlKey||e.metaKey)&&(e.preventDefault(),f())},[f]);return(0,s.jsxs)(`div`,{className:(0,r.cn)(`flex gap-2`,o),children:[(0,s.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:c,onChange:e=>l(e.target.value),onKeyDown:p,disabled:a||u}),(0,s.jsx)(r.Button,{size:`icon`,variant:`default`,onClick:f,disabled:!c.trim()||u||a,className:`shrink-0 self-end`,"aria-label":`Submit comment`,children:(0,s.jsx)(i.Send,{className:`h-4 w-4`})})]})},Tt=({query:e,suggestions:t,onSelect:i,visible:a=!0,activeIndex:o=0,className:c})=>{let l=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||l.length===0?null:(0,s.jsx)(`div`,{className:(0,r.cn)(`bg-popover border rounded-md shadow-md z-50 max-h-48 overflow-y-auto w-56`,c),role:`listbox`,"aria-label":`Mention suggestions`,children:l.map((e,t)=>(0,s.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,s.jsx)(`img`,{src:e.avatarUrl,alt:e.name,className:`h-5 w-5 rounded-full object-cover`}):(0,s.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,s.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,s.jsx)(`span`,{className:`truncate`,children:e.name}),e.type!==`user`&&(0,s.jsxs)(`span`,{className:`ml-1 text-xs text-muted-foreground capitalize`,children:[`(`,e.type,`)`]})]})]},e.id))})};function Et(e,t,n){return{type:e.type,id:e.id,name:e.name,offset:t,length:n}}function Dt(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 Ot(e){return e==null?[]:Array.isArray(e)?e.filter(e=>e!=null):[e]}function kt(e){if(!e)return null;let t=e.stageField;if(t===!1)return null;if(typeof t==`string`&&t)return t;let n=e.fields||{};for(let e of[`status`,`stage`,`state`,`phase`])if(e in n)return e;for(let[e,t]of Object.entries(n)){let n=(t?.type||``).toLowerCase();if(n===`status`||n===`stage`)return e}return null}function At(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 jt(e,t,n=4){if(!e)return[];let r=Array.isArray(e.highlightFields)&&e.highlightFields.length>0?e.highlightFields:null;if(r)return r.filter(e=>typeof e==`string`&&e.length>0).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 Mt(e,t={}){return{type:`page:header`,recordChrome:t.recordChrome!==!1,...Array.isArray(t.actions)&&t.actions.length>0?{actions:t.actions}:{}}}function Nt(e,t){return!Array.isArray(t)||t.length===0?null:{type:`record:quick_actions`,actions:t,location:`record_header`}}function Pt(e,t={}){let n=t.statusField??kt(e),r=t.stages??(n?At(e,n):null),i=t.highlightFields??jt(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 Ft(e){if(!e)return null;let t=(0,d.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}:{}}};return t.map(e=>({...e.key===void 0?{}:{name:e.key,title:e.label??e.key},...e.collapse===`none`?{}:{collapsible:!0},...e.collapse===`collapsed`?{defaultCollapsed:!0}:{},fields:e.fields.map(r)}))}function It(e,t){return Array.isArray(t)&&t.length>0?t:Ft(e)??void 0}function Lt(e,t,n){return{type:`record:details`,sections:It(e,t),...n&&n.length>0?{hideFields:n}:{}}}function Rt(e,t={}){let n=t.statusField??kt(e),r=t.highlightFields??jt(e,n),i=[{label:`Details`,value:`details`,children:[Lt(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.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}]}),{type:`page:tabs`,items:i}}function zt(){return{type:`record:discussion`}}function Bt(e,t={}){let n=t.slots||{},r=[];`header`in n&&n.header!==void 0?r.push(...Ot(n.header)):r.push(Mt(e,{recordChrome:t.recordChrome,actions:t.headerActions})),`actions`in n&&n.actions!==void 0&&r.push(...Ot(n.actions)),`alerts`in n&&n.alerts!==void 0&&r.push(...Ot(n.alerts)),`highlights`in n&&n.highlights!==void 0?r.push(...Ot(n.highlights)):r.push(...Pt(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(...Ot(n.tabs));else if(`details`in n&&n.details!==void 0){let i=Ot(n.details),o=Rt(e,{sections:t.sections,related:t.related,showActivity:t.showActivity,history:t.history,highlightFields:t.highlightFields,statusField:t.statusField,hideRelatedTab:a,relatedLayout:t.relatedLayout});Array.isArray(o.items)&&o.items.length>0&&(o.items[0]={...o.items[0],children:i}),r.push(o)}else r.push(Rt(e,{sections:t.sections,related:t.related,showActivity:t.showActivity,history:t.history,highlightFields:t.highlightFields,statusField:t.statusField,hideRelatedTab:a,relatedLayout:t.relatedLayout}));`discussion`in n&&n.discussion!==void 0?r.push(...Ot(n.discussion)):t.hideDiscussion||r.push(zt());let o=[{name:`main`,width:`full`,components:r}],s=Ot(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`,de,{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`,A,{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`,N,{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`,de,{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(`record:details`,X,{namespace:`record`,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(`record:related_list`,be,{namespace:`record`,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(`record:highlights`,Z,{namespace:`record`,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(`record:activity`,ze,{namespace:`record`,category:`record`,label:`Activity Timeline`,icon:`Activity`}),t.ComponentRegistry.register(`record:chatter`,He,{namespace:`record`,category:`record`,label:`Chatter Feed`,icon:`MessageSquare`}),t.ComponentRegistry.register(`record:discussion`,He,{namespace:`record`,category:`record`,label:`Discussion`,icon:`MessageSquare`}),t.ComponentRegistry.register(`record:path`,We,{namespace:`record`,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(`record:quick_actions`,Ke,{namespace:`record`,category:`record`,label:`Quick Actions`,icon:`Zap`}),t.ComponentRegistry.register(`record:history`,Xe,{namespace:`record`,category:`record`,label:`History Timeline`,icon:`Clock`}),t.ComponentRegistry.register(`record:reference_rail`,et,{namespace:`record`,category:`record`,label:`Reference Rail`,icon:`PanelRight`}),t.ComponentRegistry.register(`record:alert`,rt,{namespace:`record`,category:`record`,label:`Alert Banner`,icon:`AlertTriangle`}),e.ActivityTimeline=U,e.CommentAttachment=je,e.CommentInput=wt,e.ConcurrentUpdateDialog=Y,e.DETAIL_DEFAULT_TRANSLATIONS=T,e.DetailSection=A,e.DetailTabs=j,e.DetailView=de,e.DiffView=mt,e.FieldChangeItem=Se,e.HeaderHighlight=F,e.HistoryTimeline=ne,e.InlineCreateRelated=lt,e.MentionAutocomplete=Tt,e.PointInTimeRestore=Ct,e.ReactionPicker=Q,e.RecordActivityRenderer=ze,e.RecordActivityTimeline=Le,e.RecordAlertRenderer=rt,e.RecordChatterPanel=Be,e.RecordChatterRenderer=He,e.RecordComments=L,e.RecordDetailDrawer=st,e.RecordDetailsRenderer=X,e.RecordHighlightsRenderer=Z,e.RecordHistoryRenderer=Xe,e.RecordMetaFooter=ce,e.RecordNavigationEnhanced=ht,e.RecordPathRenderer=We,e.RecordQuickActionsRenderer=Ke,e.RecordReferenceRailRenderer=et,e.RecordRelatedListRenderer=be,e.RelatedList=N,e.RelationshipGraph=xt,e.RichTextCommentInput=De,e.SectionGroup=P,e.SubscriptionToggle=Te,e.ThreadedReplies=we,e.applyAutoSpan=S,e.applyDetailAutoLayout=C,e.buildDefaultActions=Nt,e.buildDefaultDetails=Lt,e.buildDefaultDiscussion=zt,e.buildDefaultHeader=Mt,e.buildDefaultHighlights=Pt,e.buildDefaultPageSchema=Bt,e.buildDefaultTabs=Rt,e.createMentionFromSuggestion=Et,e.createSafeTranslationHook=w,e.deriveFieldGroupDetailSections=Ft,e.deriveHighlightFields=jt,e.deriveRecordPageHref=ct,e.deriveStages=At,e.detectStatusField=kt,e.extractMentions=Dt,e.inferDetailColumns=x,e.isConcurrentUpdateError=me,e.isWideFieldType=b,e.resolveDetailSections=It,e.useDetailTranslation=E});
|
|
5
|
+
`)}}function dt(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 ft={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`},pt={added:`+`,removed:`-`,unchanged:` `},mt=({oldValue:e,newValue:t,fieldName:a,fieldType:o=`string`,mode:c=`unified`,className:l})=>{let{t:u}=E(),[d,f]=n.useState(c),p=n.useMemo(()=>ut(e,o),[e,o]),m=n.useMemo(()=>ut(t,o),[t,o]),h=n.useMemo(()=>dt(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,s.jsxs)(r.Card,{className:(0,r.cn)(`overflow-hidden`,l),children:[(0,s.jsx)(r.CardHeader,{className:`pb-2`,children:(0,s.jsxs)(r.CardTitle,{className:`flex items-center justify-between text-sm`,children:[(0,s.jsx)(`span`,{className:`font-medium`,children:a}),(0,s.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,s.jsx)(r.Button,{variant:d===`unified`?`secondary`:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:()=>f(`unified`),title:u(`detail.unifiedDiff`),children:(0,s.jsx)(i.Rows3,{className:`h-3.5 w-3.5`})}),(0,s.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,s.jsx)(i.Columns2,{className:`h-3.5 w-3.5`})})]})]})}),(0,s.jsx)(r.CardContent,{className:`p-0`,children:g?d===`unified`?(0,s.jsx)(`div`,{className:`font-mono text-xs overflow-x-auto`,children:h.map((e,t)=>(0,s.jsxs)(`div`,{className:(0,r.cn)(`px-4 py-0.5 whitespace-pre-wrap border-l-2`,ft[e.type],e.type===`added`&&`border-l-green-500`,e.type===`removed`&&`border-l-red-500`,e.type===`unchanged`&&`border-l-transparent`),children:[(0,s.jsx)(`span`,{className:`select-none mr-2 inline-block w-3 text-center opacity-60`,children:pt[e.type]}),e.value]},t))}):(0,s.jsx)(`div`,{className:`overflow-x-auto`,children:(0,s.jsxs)(`div`,{className:`grid grid-cols-2 divide-x font-mono text-xs min-w-0`,children:[(0,s.jsx)(`div`,{className:`px-3 py-1.5 text-xs font-medium text-muted-foreground bg-muted/50`,children:u(`detail.previousVersion`)}),(0,s.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,s.jsxs)(n.Fragment,{children:[(0,s.jsx)(`div`,{className:(0,r.cn)(`px-3 py-0.5 whitespace-pre-wrap min-h-[1.5em]`,e.left?ft[e.left.type]:`bg-muted/20`),children:e.left?.value??``}),(0,s.jsx)(`div`,{className:(0,r.cn)(`px-3 py-0.5 whitespace-pre-wrap min-h-[1.5em]`,e.right?ft[e.right.type]:`bg-muted/20`),children:e.right?.value??``})]},t))]})}):(0,s.jsx)(`p`,{className:`px-4 py-3 text-sm text-muted-foreground`,children:u(`detail.noChanges`)})})]})},ht=({currentIndex:e,totalRecords:t,recordIds:a,onNavigate:o,onSearch:c,className:l})=>{let{t:u}=E(),[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),c?.(t)},[c]),T=n.useCallback(()=>{m(e=>(e?(f(``),c?.(``)):requestAnimationFrame(()=>h.current?.focus()),!e))},[c]);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(``),c?.(``),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,c]),(0,s.jsxs)(`div`,{className:(0,r.cn)(`flex items-center gap-1.5`,l),children:[(0,s.jsx)(r.Button,{variant:`outline`,size:`icon`,className:`h-8 w-8`,disabled:!g,onClick:b,title:u(`detail.firstRecord`),children:(0,s.jsx)(i.ChevronsLeft,{className:`h-4 w-4`})}),(0,s.jsx)(r.Button,{variant:`outline`,size:`icon`,className:`h-8 w-8`,disabled:!_,onClick:x,title:u(`detail.previousRecordKey`),children:(0,s.jsx)(i.ChevronLeft,{className:`h-4 w-4`})}),(0,s.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,s.jsx)(r.Button,{variant:`outline`,size:`icon`,className:`h-8 w-8`,disabled:!v,onClick:S,title:u(`detail.nextRecordKey`),children:(0,s.jsx)(i.ChevronRight,{className:`h-4 w-4`})}),(0,s.jsx)(r.Button,{variant:`outline`,size:`icon`,className:`h-8 w-8`,disabled:!y,onClick:C,title:u(`detail.lastRecord`),children:(0,s.jsx)(i.ChevronsRight,{className:`h-4 w-4`})}),c&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(r.Button,{variant:p?`secondary`:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:T,title:u(`detail.searchWhileNavigating`),children:(0,s.jsx)(i.Search,{className:`h-4 w-4`})}),p&&(0,s.jsx)(`div`,{className:`relative`,children:(0,s.jsx)(r.Input,{ref:h,type:`text`,placeholder:u(`detail.searchRecords`),value:d,onChange:w,className:`h-8 w-48 text-sm`})})]})]})},gt=28,_t=[`fill-primary stroke-primary`,`fill-blue-500 stroke-blue-500`,`fill-emerald-500 stroke-emerald-500`,`fill-amber-500 stroke-amber-500`],vt=[`fill-primary-foreground`,`fill-white`,`fill-white`,`fill-white`];function yt(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 bt(e,t=6){return e.length<=t?e:e.slice(0,t-1)+`…`}var xt=({record:e,relatedRecords:t,levels:a=1,onNodeClick:o,className:c})=>{let l=n.useRef(null),[u,d]=n.useState({width:500,height:400}),[f,p]=n.useState(null);n.useEffect(()=>{let e=l.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(()=>yt(e,t,a,u.width,u.height),[e,t,a,u]);return(0,s.jsxs)(r.Card,{className:(0,r.cn)(`overflow-hidden`,c),children:[(0,s.jsx)(r.CardHeader,{className:`pb-2`,children:(0,s.jsxs)(r.CardTitle,{className:`flex items-center gap-2 text-base`,children:[(0,s.jsx)(i.Network,{className:`h-4 w-4`}),`Relationships`,(0,s.jsxs)(`span`,{className:`text-sm font-normal text-muted-foreground`,children:[`(`,t.length,` related)`]})]})}),(0,s.jsx)(r.CardContent,{className:`p-0`,children:(0,s.jsxs)(`svg`,{ref:l,width:`100%`,height:u.height,viewBox:`0 0 ${u.width} ${u.height}`,className:`select-none`,children:[h.map((e,t)=>(0,s.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=_t[Math.min(e.level,_t.length-1)],i=vt[Math.min(e.level,vt.length-1)],a=e.level===0?34:gt;return(0,s.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,s.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,s.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:bt(e.label)}),e.type&&(0,s.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,s.jsxs)(s.Fragment,{children:[(0,s.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,s.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 St(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 Ct=({recordId:e,revisions:t,onRestore:a,className:o})=>{let[c,l]=n.useState(null),[u,d]=n.useState(!1),[f,p]=n.useState(!1),m=n.useMemo(()=>t.find(e=>e.id===c)??null,[t,c]),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),l(null)}finally{p(!1)}}},[m,a,u]),g=n.useCallback(()=>{d(!1)},[]);return(0,s.jsxs)(r.Card,{className:(0,r.cn)(``,o),children:[(0,s.jsx)(r.CardHeader,{className:`pb-3`,children:(0,s.jsxs)(r.CardTitle,{className:`flex items-center gap-2 text-base`,children:[(0,s.jsx)(i.History,{className:`h-4 w-4`}),`Revision History`,(0,s.jsxs)(`span`,{className:`text-sm font-normal text-muted-foreground`,children:[`(`,t.length,`)`]})]})}),(0,s.jsx)(r.CardContent,{children:t.length===0?(0,s.jsx)(`p`,{className:`text-sm text-muted-foreground text-center py-4`,children:`No revisions recorded`}):(0,s.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-4`,children:[(0,s.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,s.jsxs)(`div`,{className:`relative`,children:[(0,s.jsx)(`div`,{className:`absolute left-3 top-2 bottom-2 w-px bg-border`}),(0,s.jsx)(`div`,{className:`space-y-1`,children:t.map(e=>{let t=e.id===c;return(0,s.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:()=>{l(e.id),d(!1)},children:[(0,s.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,s.jsx)(i.ChevronRight,{className:`h-3 w-3 text-primary-foreground`})}),(0,s.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,s.jsx)(`span`,{className:`text-sm font-medium`,children:e.user}),(0,s.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:St(e.timestamp)})]}),(0,s.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,s.jsxs)(`div`,{className:`lg:w-80 border rounded-md p-3 space-y-3`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium`,children:[(0,s.jsx)(i.Eye,{className:`h-4 w-4 text-muted-foreground`}),`Revision Preview`]}),(0,s.jsx)(`div`,{className:`space-y-2`,children:m.changes.map((e,t)=>(0,s.jsxs)(`div`,{className:`text-xs`,children:[(0,s.jsx)(`span`,{className:`font-medium text-muted-foreground`,children:e.field}),(0,s.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-0.5`,children:[(0,s.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,s.jsx)(i.ChevronRight,{className:`h-3 w-3 text-muted-foreground shrink-0`}),(0,s.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,s.jsxs)(`div`,{className:`border-t pt-2 space-y-1`,children:[(0,s.jsx)(`p`,{className:`text-xs font-medium text-muted-foreground`,children:`Record state at this point`}),(0,s.jsx)(`div`,{className:`max-h-40 overflow-y-auto space-y-1`,children:Object.entries(m.snapshot).map(([e,t])=>(0,s.jsxs)(`div`,{className:`flex justify-between text-xs gap-2`,children:[(0,s.jsx)(`span`,{className:`text-muted-foreground truncate`,children:e}),(0,s.jsx)(`span`,{className:`font-mono truncate max-w-[140px]`,children:t==null?`–`:String(t)})]},e))})]}),a&&(0,s.jsx)(`div`,{className:`pt-1 space-y-2`,children:u?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(`p`,{className:`text-xs text-amber-600 dark:text-amber-400`,children:[`This will restore the record to its state at`,` `,St(m.timestamp),`. Continue?`]}),(0,s.jsxs)(`div`,{className:`flex gap-2`,children:[(0,s.jsxs)(r.Button,{variant:`destructive`,size:`sm`,className:`gap-1.5 flex-1`,onClick:h,disabled:f,children:[(0,s.jsx)(i.RotateCcw,{className:`h-3.5 w-3.5`}),f?`Restoring…`:`Confirm Restore`]}),(0,s.jsx)(r.Button,{variant:`ghost`,size:`sm`,onClick:g,disabled:f,children:`Cancel`})]})]}):(0,s.jsxs)(r.Button,{variant:`outline`,size:`sm`,className:`w-full gap-1.5`,onClick:h,children:[(0,s.jsx)(i.RotateCcw,{className:`h-3.5 w-3.5`}),`Restore to this point`]})})]})]})})]})},wt=({onSubmit:e,placeholder:t=`Leave a comment…`,disabled:a=!1,className:o})=>{let[c,l]=n.useState(``),[u,d]=n.useState(!1),f=n.useCallback(async()=>{let t=c.trim();if(t){d(!0);try{await e(t),l(``)}finally{d(!1)}}},[c,e]),p=n.useCallback(e=>{e.key===`Enter`&&(e.ctrlKey||e.metaKey)&&(e.preventDefault(),f())},[f]);return(0,s.jsxs)(`div`,{className:(0,r.cn)(`flex gap-2`,o),children:[(0,s.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:c,onChange:e=>l(e.target.value),onKeyDown:p,disabled:a||u}),(0,s.jsx)(r.Button,{size:`icon`,variant:`default`,onClick:f,disabled:!c.trim()||u||a,className:`shrink-0 self-end`,"aria-label":`Submit comment`,children:(0,s.jsx)(i.Send,{className:`h-4 w-4`})})]})},Tt=({query:e,suggestions:t,onSelect:i,visible:a=!0,activeIndex:o=0,className:c})=>{let l=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||l.length===0?null:(0,s.jsx)(`div`,{className:(0,r.cn)(`bg-popover border rounded-md shadow-md z-50 max-h-48 overflow-y-auto w-56`,c),role:`listbox`,"aria-label":`Mention suggestions`,children:l.map((e,t)=>(0,s.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,s.jsx)(`img`,{src:e.avatarUrl,alt:e.name,className:`h-5 w-5 rounded-full object-cover`}):(0,s.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,s.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,s.jsx)(`span`,{className:`truncate`,children:e.name}),e.type!==`user`&&(0,s.jsxs)(`span`,{className:`ml-1 text-xs text-muted-foreground capitalize`,children:[`(`,e.type,`)`]})]})]},e.id))})};function Et(e,t,n){return{type:e.type,id:e.id,name:e.name,offset:t,length:n}}function Dt(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 Ot(e){return e==null?[]:Array.isArray(e)?e.filter(e=>e!=null):[e]}function kt(e){if(!e)return null;let t=e.stageField;if(t===!1)return null;if(typeof t==`string`&&t)return t;let n=e.fields||{};for(let e of[`status`,`stage`,`state`,`phase`])if(e in n)return e;for(let[e,t]of Object.entries(n)){let n=(t?.type||``).toLowerCase();if(n===`status`||n===`stage`)return e}return null}function At(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 jt(e,t,n=4){if(!e)return[];let r=Array.isArray(e.highlightFields)&&e.highlightFields.length>0?e.highlightFields:null;if(r)return r.filter(e=>typeof e==`string`&&e.length>0).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 Mt(e,t={}){return{type:`page:header`,recordChrome:t.recordChrome!==!1,...Array.isArray(t.actions)&&t.actions.length>0?{actions:t.actions}:{}}}function Nt(e,t){return!Array.isArray(t)||t.length===0?null:{type:`record:quick_actions`,actions:t,location:`record_header`}}function Pt(e,t={}){let n=t.statusField??kt(e),r=t.stages??(n?At(e,n):null),i=t.highlightFields??jt(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 Ft(e){if(!e)return null;let t=(0,d.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}:{}}},i=x(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.collapse===`none`?{}:{collapsible:!0},...e.collapse===`collapsed`?{defaultCollapsed:!0}:{},columns:i,fields:e.fields.map(r)}))}function It(e,t){return Array.isArray(t)&&t.length>0?t:Ft(e)??void 0}function Lt(e,t,n){return{type:`record:details`,sections:It(e,t),...n&&n.length>0?{hideFields:n}:{}}}function Rt(e,t={}){let n=t.statusField??kt(e),r=t.highlightFields??jt(e,n),i=[{label:`Details`,value:`details`,children:[Lt(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.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}]}),{type:`page:tabs`,items:i}}function zt(){return{type:`record:discussion`}}function Bt(e,t={}){let n=t.slots||{},r=[];`header`in n&&n.header!==void 0?r.push(...Ot(n.header)):r.push(Mt(e,{recordChrome:t.recordChrome,actions:t.headerActions})),`actions`in n&&n.actions!==void 0&&r.push(...Ot(n.actions)),`alerts`in n&&n.alerts!==void 0&&r.push(...Ot(n.alerts)),`highlights`in n&&n.highlights!==void 0?r.push(...Ot(n.highlights)):r.push(...Pt(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(...Ot(n.tabs));else if(`details`in n&&n.details!==void 0){let i=Ot(n.details),o=Rt(e,{sections:t.sections,related:t.related,showActivity:t.showActivity,history:t.history,highlightFields:t.highlightFields,statusField:t.statusField,hideRelatedTab:a,relatedLayout:t.relatedLayout});Array.isArray(o.items)&&o.items.length>0&&(o.items[0]={...o.items[0],children:i}),r.push(o)}else r.push(Rt(e,{sections:t.sections,related:t.related,showActivity:t.showActivity,history:t.history,highlightFields:t.highlightFields,statusField:t.statusField,hideRelatedTab:a,relatedLayout:t.relatedLayout}));`discussion`in n&&n.discussion!==void 0?r.push(...Ot(n.discussion)):t.hideDiscussion||r.push(zt());let o=[{name:`main`,width:`full`,components:r}],s=Ot(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`,fe,{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`,A,{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`,N,{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`,fe,{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(`record:details`,_e,{namespace:`record`,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(`record:related_list`,ye,{namespace:`record`,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(`record:highlights`,Q,{namespace:`record`,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(`record:activity`,ze,{namespace:`record`,category:`record`,label:`Activity Timeline`,icon:`Activity`}),t.ComponentRegistry.register(`record:chatter`,He,{namespace:`record`,category:`record`,label:`Chatter Feed`,icon:`MessageSquare`}),t.ComponentRegistry.register(`record:discussion`,He,{namespace:`record`,category:`record`,label:`Discussion`,icon:`MessageSquare`}),t.ComponentRegistry.register(`record:path`,We,{namespace:`record`,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(`record:quick_actions`,Ke,{namespace:`record`,category:`record`,label:`Quick Actions`,icon:`Zap`}),t.ComponentRegistry.register(`record:history`,Xe,{namespace:`record`,category:`record`,label:`History Timeline`,icon:`Clock`}),t.ComponentRegistry.register(`record:reference_rail`,et,{namespace:`record`,category:`record`,label:`Reference Rail`,icon:`PanelRight`}),t.ComponentRegistry.register(`record:alert`,rt,{namespace:`record`,category:`record`,label:`Alert Banner`,icon:`AlertTriangle`}),e.ActivityTimeline=H,e.CommentAttachment=je,e.CommentInput=wt,e.ConcurrentUpdateDialog=J,e.DETAIL_DEFAULT_TRANSLATIONS=T,e.DetailSection=A,e.DetailTabs=j,e.DetailView=fe,e.DiffView=mt,e.FieldChangeItem=xe,e.HeaderHighlight=F,e.HistoryTimeline=ie,e.InlineCreateRelated=lt,e.MentionAutocomplete=Tt,e.PointInTimeRestore=Ct,e.ReactionPicker=Ce,e.RecordActivityRenderer=ze,e.RecordActivityTimeline=Le,e.RecordAlertRenderer=rt,e.RecordChatterPanel=Be,e.RecordChatterRenderer=He,e.RecordComments=L,e.RecordDetailDrawer=st,e.RecordDetailsRenderer=_e,e.RecordHighlightsRenderer=Q,e.RecordHistoryRenderer=Xe,e.RecordMetaFooter=le,e.RecordNavigationEnhanced=ht,e.RecordPathRenderer=We,e.RecordQuickActionsRenderer=Ke,e.RecordReferenceRailRenderer=et,e.RecordRelatedListRenderer=ye,e.RelatedList=N,e.RelationshipGraph=xt,e.RichTextCommentInput=De,e.SectionGroup=P,e.SubscriptionToggle=$,e.ThreadedReplies=Te,e.applyAutoSpan=S,e.applyDetailAutoLayout=C,e.buildDefaultActions=Nt,e.buildDefaultDetails=Lt,e.buildDefaultDiscussion=zt,e.buildDefaultHeader=Mt,e.buildDefaultHighlights=Pt,e.buildDefaultPageSchema=Bt,e.buildDefaultTabs=Rt,e.createMentionFromSuggestion=Et,e.createSafeTranslationHook=w,e.deriveFieldGroupDetailSections=Ft,e.deriveHighlightFields=jt,e.deriveRecordPageHref=ct,e.deriveStages=At,e.detectStatusField=kt,e.extractMentions=Dt,e.inferDetailColumns=x,e.isConcurrentUpdateError=he,e.isWideFieldType=b,e.resolveDetailSections=It,e.useDetailTranslation=E});
|