@object-ui/plugin-detail 5.0.1 → 5.1.1
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 +166 -0
- package/README.md +74 -0
- package/dist/index.js +1742 -1211
- package/dist/index.umd.cjs +3 -3
- package/dist/packages/plugin-detail/src/ActivityTimeline.d.ts.map +1 -1
- package/dist/packages/plugin-detail/src/ConcurrentUpdateDialog.d.ts +43 -0
- package/dist/packages/plugin-detail/src/ConcurrentUpdateDialog.d.ts.map +1 -0
- package/dist/packages/plugin-detail/src/DetailSection.d.ts.map +1 -1
- package/dist/packages/plugin-detail/src/DetailView.d.ts +10 -0
- package/dist/packages/plugin-detail/src/DetailView.d.ts.map +1 -1
- package/dist/packages/plugin-detail/src/HeaderHighlight.d.ts.map +1 -1
- package/dist/packages/plugin-detail/src/RecordActivityTimeline.d.ts +11 -1
- package/dist/packages/plugin-detail/src/RecordActivityTimeline.d.ts.map +1 -1
- package/dist/packages/plugin-detail/src/RecordChatterPanel.d.ts +17 -0
- package/dist/packages/plugin-detail/src/RecordChatterPanel.d.ts.map +1 -1
- package/dist/packages/plugin-detail/src/RichTextCommentInput.d.ts +7 -0
- package/dist/packages/plugin-detail/src/RichTextCommentInput.d.ts.map +1 -1
- package/dist/packages/plugin-detail/src/index.d.ts +4 -1
- package/dist/packages/plugin-detail/src/index.d.ts.map +1 -1
- package/dist/packages/plugin-detail/src/renderers/record-chatter.d.ts.map +1 -1
- package/dist/packages/plugin-detail/src/renderers/record-details.d.ts.map +1 -1
- package/dist/packages/plugin-detail/src/renderers/record-reference-rail.d.ts +25 -0
- package/dist/packages/plugin-detail/src/renderers/record-reference-rail.d.ts.map +1 -0
- package/dist/packages/plugin-detail/src/renderers/record-related-list.d.ts.map +1 -1
- package/dist/packages/plugin-detail/src/synth/buildDefaultPageSchema.d.ts +14 -1
- package/dist/packages/plugin-detail/src/synth/buildDefaultPageSchema.d.ts.map +1 -1
- package/dist/packages/plugin-detail/src/useDetailTranslation.d.ts.map +1 -1
- package/package.json +12 -12
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`)):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`],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))})(this,function(e,t,n,r,i,a,o,s,c){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var l=Object.create,u=Object.defineProperty,d=Object.getOwnPropertyDescriptor,f=Object.getOwnPropertyNames,p=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty,h=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=f(t),a=0,o=i.length,s;a<o;a++)s=i[a],!m.call(e,s)&&s!==n&&u(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=d(t,s))||r.enumerable});return e};n=((e,t,n)=>(n=e==null?{}:l(p(e)),h(t||!e||!e.__esModule?u(n,`default`,{value:e,enumerable:!0}):n,e)))(n,1);var g=new Set([`textarea`,`markdown`,`html`,`grid`,`rich-text`,`field:textarea`,`field:markdown`,`field:html`,`field:grid`,`field:rich-text`]);function _(e){return g.has(e)}function v(e,t){let n;return n=e<=3?1:2,t!==void 0&&t<640?Math.min(n,1):n}function y(e,t){return t<=1?e:e.map(e=>e.span===void 0&&e.type&&_(e.type)?{...e,span:t}:e)}function b(e,t,n){if(t!==void 0)return{fields:y(e,t),columns:t};let r=v(e.length,n);return{fields:y(e,r),columns:r}}function x(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 S={"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.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.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.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`},C=x(S,`detail.back`);function w(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 T=({section:e,data:t,className:c,objectSchema:l,objectName:u,isEditing:d=!1,onFieldChange:f,virtualScroll:p})=>{let[m,h]=n.useState(e.defaultCollapsed??!1),[g,_]=n.useState(null),[v,y]=n.useState(void 0),[x,S]=n.useState(!1),{t:T}=C(),{fieldLabel:E,translateOptions:D}=(0,a.useSafeFieldLabel)(),O=n.useCallback((e,t)=>{let n=t==null?``:String(t);navigator.clipboard.writeText(n).then(()=>{_(e),setTimeout(()=>_(null),2e3)})},[]),k=n.useCallback(e=>{let n=t?.[e.name]??e.value;return n==null||n===``},[t]),A=n.useMemo(()=>e.fields.filter(k).length,[e.fields,k]),j=(0,r.useIsMobile)(),M=j?3:4,N=j?.2:.25,P=e.fields.length-A,F=!e.hideEmpty&&!d&&e.fields.length>=M&&A/e.fields.length>=N&&P>0,I=!x&&(e.hideEmpty||F)?e.fields.filter(e=>!k(e)):e.fields;if(I.length===0&&A===e.fields.length)return null;let{fields:L,columns:R}=b(I,e.columns),z=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=w(e.span,R),p=l?.fields?.[e.name],m={...e};if(p){!e.type&&p.type&&(m.type=p.type),p.options&&!m.options&&(m.options=p.options),p.currency&&!m.currency&&(m.currency=p.currency),p.precision!==void 0&&m.precision===void 0&&(m.precision=p.precision),p.format&&!m.format&&(m.format=p.format);let t=p.reference_to||p.reference;t&&!m.reference_to&&(m.reference_to=t),p.reference_field&&!m.reference_field&&(m.reference_field=p.reference_field)}u&&Array.isArray(m.options)&&m.options.length>0&&(m.options=D(u,e.name,m.options));let h=(()=>{if(n==null)return(0,s.jsx)(`span`,{className:`text-muted-foreground/50 text-xs italic`,children:`—`});let t=(0,o.resolveCellRendererType)(m)||e.type;if(t){let e=(0,o.getCellRenderer)(t);if(e)return(0,s.jsx)(e,{value:n,field:m})}return String(n)})(),_=n!=null&&n!==``,v=g===e.name;return(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:E(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=m.type||e.type;if(t===`select`&&Array.isArray(m.options)&&m.options.length>0)return(0,s.jsx)(o.SelectField,{field:m,value:n==null?``:String(n),onChange:t=>f?.(e.name,t)});if(t===`boolean`)return(0,s.jsx)(o.BooleanField,{field:m,value:!!n,onChange:t=>f?.(e.name,t)});let r=t===`date`||t===`datetime`;return(0,s.jsx)(`input`,{type:t===`number`?`number`:r?`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?``:r?(()=>{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(n),onChange:t=>{let n=t.target.value;if(r&&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`,_&&`cursor-pointer active:bg-muted/60 transition-colors`),onClick:_?()=>O(e.name,n):void 0,onKeyDown:_?t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),O(e.name,n))}:void 0,role:_?`button`:void 0,tabIndex:_?0:void 0,children:[(0,s.jsx)(`div`,{className:`text-sm flex-1 break-words py-1`,children:h}),_&&(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(),O(e.name,n)},children:v?(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:T(v?`detail.copied`:`detail.copyToClipboard`)})]})})]})]},e.name)},B=p?.enabled===!0,V=p?.batchSize??20;n.useEffect(()=>{if(!B){y(void 0);return}if(L.length<=V){y(void 0);return}y(V);let e=setTimeout(()=>y(void 0),100);return()=>clearTimeout(e)},[B,L.length,V]);let H=v===void 0?L:L.slice(0,v),ee=A>0&&(e.hideEmpty||F),U=(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`div`,{className:(0,r.cn)(`grid gap-3 sm:gap-4`,R===1?`grid-cols-1`:R===2?`grid-cols-1 md:grid-cols-2`:`grid-cols-1 md:grid-cols-2 lg:grid-cols-3`),children:H.map(z)}),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?T(`detail.hideEmptyFields`,{defaultValue:`Hide empty fields`}):T(`detail.showEmptyFields`,{count:A,defaultValue:`Show ${A} empty field${A===1?``:`s`}`})]})})]});return!e.title&&!e.collapsible&&e.showBorder===!1?(0,s.jsx)(`div`,{className:(0,r.cn)(c),children:U}):e.collapsible?(0,s.jsx)(r.Collapsible,{open:!m,onOpenChange:e=>h(!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)(`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`,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.fields&&(0,s.jsx)(r.Badge,{variant:`secondary`,className:`ml-2 text-xs`,children:e.fields.length})]}),(0,s.jsx)(`div`,{className:`flex items-center gap-2`,children:m?(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&&!m&&(0,s.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1.5`,children:e.description})]})}),(0,s.jsx)(r.CollapsibleContent,{children:(0,s.jsx)(r.CardContent,{className:`pt-4 sm:pt-6 px-3 sm:px-6`,children:U})})]})}):(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)(e.headerColor&&`bg-${e.headerColor}`),children:[(0,s.jsx)(r.CardTitle,{className:`flex items-center justify-between`,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-sm text-muted-foreground mt-1.5`,children:e.description})]}),(0,s.jsx)(r.CardContent,{className:`pt-4 sm:pt-6 px-3 sm:px-6`,children:U})]})},E=({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`,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 D(e){return e&&i.icons[e.split(/[-_\s]/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``)]||i.Inbox}var O=({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,maxColumns:x=6,pageSize:S,sortable:w=!1,filterable:T=!1,collapsible:E=!1,defaultCollapsed:O=!1,referenceField:k,parentId:A,icon:j})=>{let M=u!==void 0,N=u??[],[P,F]=n.useState(N),[I,L]=n.useState(()=>!!l&&!M),[R,z]=n.useState(0),[B,V]=n.useState(null),[H,ee]=n.useState(`asc`),[U,te]=n.useState(``),[W,ne]=n.useState(null),[re,ie]=n.useState(O),[ae,oe]=n.useState({}),{t:G}=C(),{fieldLabel:se}=(0,a.useSafeFieldLabel)();n.useEffect(()=>{M&&F(u??[])},[u,M]),n.useEffect(()=>{l&&m?.getObjectSchema&&!f?.length&&m.getObjectSchema(l).then(ne).catch(e=>{console.warn(`[RelatedList] Failed to fetch schema for ${l}:`,e)})},[l,m,f]),n.useEffect(()=>{if(l&&!M){if(!(k&&A!=null&&A!==``)){l&&(A==null||A===``)&&!k&&console.warn(`[RelatedList] "${l}" has no referenceField/parentId — refusing to fetch all rows. Pass relationshipField + parentId to scope the query.`),F([]),L(!1);return}L(!0);let e={[k]:A};if(m&&typeof m.find==`function`)m.find(l,{$filter:e}).then(e=>{F(Array.isArray(e)?e:Array.isArray(e?.data)?e.data:[]),L(!1)}).catch(e=>{console.error(`Failed to fetch related data:`,e),L(!1)});else{let e=new URLSearchParams({[`filter[${k}]`]:String(A)}).toString();fetch(`${l}?${e}`).then(e=>e.json()).then(e=>{F(Array.isArray(e)?e:e?.data||[])}).catch(e=>{console.error(`Failed to fetch related data:`,e)}).finally(()=>L(!1))}}},[l,M,m,k,A]),n.useEffect(()=>{if(!m?.find||!W?.fields||!P.length)return;let e=W.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 P){let t=e?.[n];t!=null&&(typeof t==`string`&&t?i.add(t):typeof t==`number`&&i.add(String(t)))}let a=ae[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||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||oe(t=>{let n={...t};for(let{fieldName:t,map:r}of e)n[t]={...n[t]||{},...r};return n})}),()=>{n=!0}},[m,W,P]);let ce=n.useMemo(()=>{if(!U)return P;let e=U.toLowerCase();return P.filter(t=>Object.values(t).some(t=>t!=null&&String(t).toLowerCase().includes(e)))},[P,U]),K=n.useMemo(()=>B?[...ce].sort((e,t)=>{let n=e[B],r=t[B];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 H===`asc`?i:-i}):ce,[ce,B,H]),q=S&&S>0?S:0,le=q?Math.max(1,Math.ceil(K.length/q)):1,J=q?K.slice(R*q,(R+1)*q):K;n.useEffect(()=>{z(0)},[U,B,H]);let ue=n.useCallback(e=>{B===e?ee(e=>e===`asc`?`desc`:`asc`):(V(e),ee(`asc`))},[B]),[Y,X]=n.useState(null),Z=n.useCallback(e=>{X(e)},[]),de=n.useCallback(()=>{Y&&y?.(Y),X(null)},[Y,y]),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=>k?e.filter(e=>(e?.accessorKey||e?.field||e?.name)!==k):e,i=e=>e==null||typeof e==`string`&&e.trim()===``||Array.isArray(e)&&e.length===0,a=e=>P.length?e.filter(e=>{let t=e?.accessorKey||e?.field||e?.name;return t?P.some(e=>!i(e?.[t])):!0}):e;if(f&&f.length>0)return a(t(r(f)));if(!W?.fields)return[];let s=e,c=new Set([`image`,`file`,`attachment`,`rich_text`,`html`,`json`]),u=[`name`,`full_name`,`fullname`,`title`,`subject`,`label`,`code`,`number`],d=Object.entries(W.fields).filter(([e,t])=>!(e.startsWith(`_`)||e===`id`||e===k||t?.hidden||t?.type&&c.has(t.type)||Q?.isLoaded&&s&&!Q.checkField(s,e,`read`)));return d.sort(([e,t],[n,r])=>{let i=u.indexOf(e),a=u.indexOf(n),o=i>=0?i:100,s=a>=0?a:100;if(o!==s)return o-s;let c=t?.type===`select`||e.includes(`status`);return c===(r?.type===`select`||n.includes(`status`))?0:c?-1:1}),a(d.map(([e,t])=>{let r={accessorKey:e,header:se(s,e,t.label||e)};if(t.type){let i=(0,o.getCellRenderer)((0,o.resolveCellRendererType)({type:t.type,format:t.format})||t.type);if(i){let a=t.type===`lookup`||t.type===`master_detail`?ae[e]:void 0,o=a&&Object.keys(a).length>0?Object.entries(a).map(([e,t])=>({value:e,label:t})):void 0,s={name:e,label:t.label||e,type:t.type,...(o||t.options)&&{options:o||t.options},...t.currency&&{currency:t.currency},...t.precision!==void 0&&{precision:t.precision},...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}};r.cell=e=>e==null?n.createElement(`span`,{className:`text-muted-foreground/50 text-xs italic`},`—`):n.createElement(i,{value:e,field:s})}}return r})).slice(0,Math.max(1,x))},[f,W,h,l,se,k,P,x,ae,Q]),fe=!!v||!!y,pe=(0,r.useIsMobile)(),me=n.useMemo(()=>{if(d)return d;if(pe&&(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:J,objectName:l,gallery:{titleField:e||`name`,visibleFields:t,cardSize:`medium`},onRowClick:b}}switch(t){case`grid`:case`table`:return{type:`data-table`,data:J,columns:$,pagination:!1,pageSize:q||10,searchable:!1,exportable:!1,rowActions:fe,onRowEdit:v,onRowDelete:y?Z:void 0,onRowClick:b};case`list`:return{type:`data-list`,data:J};default:return{type:`div`,children:`No view configured`}}},[t,J,$,d,q,fe,v,y,Z,b,pe,l]),he=E?`cursor-pointer select-none`:void 0,ge=E?()=>ie(e=>!e):void 0,_e=D(j),ve=!I&&P.length===0,ye=T;return(0,s.jsxs)(r.Card,{className:(0,r.cn)(`shadow-none border-border/60 bg-transparent`,ve&&`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`,he),onClick:ge,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:[E&&(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)(_e,{className:`h-4 w-4 text-muted-foreground shrink-0`,"aria-hidden":!0}),(0,s.jsx)(`span`,{className:(0,r.cn)(`truncate`,ve&&`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`,P.length===0&&`bg-muted text-muted-foreground`),"aria-label":`${P.length} records`,children:P.length}),ve&&(0,s.jsx)(`span`,{className:`text-xs text-muted-foreground/70 italic ml-1 truncate`,children:G(`detail.noRelatedRecords`)})]}),(0,s.jsx)(`div`,{className:`flex items-center gap-1 shrink-0`,children:g&&(0,s.jsxs)(r.Button,{variant:ve?`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`}),G(`detail.new`)]})})]})}),!re&&!ve&&(0,s.jsxs)(r.CardContent,{className:(0,r.cn)(`pt-0 pb-4 px-4`),children:[ye&&(0,s.jsx)(`div`,{className:`mb-3`,children:(0,s.jsx)(r.Input,{placeholder:G(`detail.filterPlaceholder`),value:U,onChange:e=>te(e.target.value),className:`h-8 text-sm`})}),w&&$&&$.length>0&&P.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=B===t;return(0,s.jsxs)(r.Button,{variant:a?`secondary`:`ghost`,size:`sm`,className:`gap-1 h-7 text-xs`,onClick:()=>ue(t),children:[(0,s.jsx)(i.ArrowUpDown,{className:`h-3 w-3`}),n,a&&(H===`asc`?` ↑`:` ↓`)]},t)})}),I?(0,s.jsx)(`div`,{className:`flex items-center justify-center py-6 text-muted-foreground text-sm`,children:G(`detail.loading`)}):(0,s.jsx)(a.SchemaRenderer,{schema:me}),q>0&&K.length>q&&(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:R===0,onClick:()=>z(e=>Math.max(0,e-1)),children:[(0,s.jsx)(i.ChevronLeft,{className:`h-3 w-3`}),G(`detail.previousPage`)]}),(0,s.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:G(`detail.pageOf`,{current:R+1,total:le})}),(0,s.jsxs)(r.Button,{variant:`outline`,size:`sm`,className:`h-7 text-xs gap-1`,disabled:R>=le-1,onClick:()=>z(e=>Math.min(le-1,e+1)),children:[G(`detail.nextPage`),(0,s.jsx)(i.ChevronRight,{className:`h-3 w-3`})]})]}),_&&!ve&&q>0&&K.length>q&&(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:[G(`detail.viewAll`),(0,s.jsx)(i.ExternalLink,{className:`h-3 w-3`})]})})]}),(0,s.jsx)(r.AlertDialog,{open:Y!==null,onOpenChange:e=>{e||X(null)},children:(0,s.jsxs)(r.AlertDialogContent,{children:[(0,s.jsxs)(r.AlertDialogHeader,{children:[(0,s.jsx)(r.AlertDialogTitle,{children:G(`detail.deleteRowTitle`,{defaultValue:`Delete record`})}),(0,s.jsx)(r.AlertDialogDescription,{children:G(`detail.deleteRowConfirmation`)})]}),(0,s.jsxs)(r.AlertDialogFooter,{children:[(0,s.jsx)(r.AlertDialogCancel,{children:G(`detail.cancel`,{defaultValue:`Cancel`})}),(0,s.jsx)(r.AlertDialogAction,{onClick:de,className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:G(`detail.delete`,{defaultValue:`Delete`})})]})]})})]})},k=({group:e,data:t,className:a,objectSchema:o,objectName:c,isEditing:l=!1,onFieldChange:u})=>{let d=e.collapsible??!0,[f,p]=n.useState(e.defaultCollapsed??!1),m=(0,s.jsx)(`div`,{className:`space-y-3 sm:space-y-4`,children:e.sections.map((e,n)=>(0,s.jsx)(T,{section:e,data:t,objectSchema:o,objectName:c,isEditing:l,onFieldChange:u},n))});return d?(0,s.jsxs)(r.Collapsible,{open:!f,onOpenChange:e=>p(!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:[f?(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&&!f&&(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:m})})]}):(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}),m]})},A=({fields:e,data:t,className:n,objectName:i,objectSchema:c})=>{let{fieldLabel:l}=(0,a.useSafeFieldLabel)();if(!e.length||!t)return null;let u=e.filter(e=>{let n=t?.[e.name];return n!=null&&n!==``});return u.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-x-8 gap-y-3`),children:u.map(e=>{let n=t[e.name],r=c?.fields?.[e.name],a=e.type||r?.type,u={name:e.name,label:e.label,type:a||`text`,...r?.options&&{options:r.options},...r?.currency&&{currency:r.currency},...r?.precision!==void 0&&{precision:r.precision},...r?.format&&{format:r.format}},d=(0,o.getCellRenderer)((0,o.resolveCellRendererType)(u)||a||`text`);return(0,s.jsxs)(`div`,{className:`flex min-w-[8rem] max-w-[16rem] basis-[10rem] flex-col gap-0.5`,children:[(0,s.jsxs)(`span`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:[e.icon&&(0,s.jsx)(`span`,{className:`mr-1`,children:e.icon}),l(i||``,e.name,e.label)]}),(0,s.jsx)(`span`,{className:`block min-w-0 truncate text-sm font-semibold`,children:(0,s.jsx)(d,{value:n,field:u})})]},e.name)})})})};function j(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 M=({comments:e,onAddComment:t,onTogglePin:a,searchable:o=!1,className:c})=>{let{t:l}=C(),[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:j(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))})]})]})},N={field_change:i.Edit,create:i.PlusCircle,delete:i.Trash2,comment:i.MessageSquare,status_change:i.ArrowRightLeft},P={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 F(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 I(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 L={all:`All`,field_change:`Field Changes`,create:`Creates`,delete:`Deletes`,comment:`Comments`,status_change:`Status Changes`},R=({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(L).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(N[e]||i.Edit,{className:`h-3 w-3`}),L[e]]},e))}),u.length===0?(0,s.jsx)(`p`,{className:`text-sm text-muted-foreground text-center py-4`,children:`No activity recorded`}):(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=N[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`,P[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:I(e)})]}),(0,s.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:F(e.timestamp)})]})]},e.id)})})]})]})]})},z={create:`default`,update:`secondary`,delete:`destructive`,restore:`outline`,login:`outline`,logout:`outline`,permission_change:`secondary`,config_change:`secondary`,export:`outline`,import:`outline`};function B(e){if(!e)return``;let t=e instanceof Date?e:new Date(e);return Number.isNaN(t.getTime())?String(e):t.toLocaleString()}var V=[[60,`second`],[60,`minute`],[24,`hour`],[7,`day`],[4.34524,`week`],[12,`month`],[1/0,`year`]];function H(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 V){if(Math.abs(r)<n)try{return new Intl.RelativeTimeFormat(t,{numeric:`auto`}).format(Math.round(r),i)}catch{return B(e)}r/=n}return B(e)}function ee(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 U(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 te({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=z[n]??`outline`,o=typeof e.user_name==`string`&&e.user_name.trim()||`Unknown user`,c=B(e.created_at),l=H(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:ee(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:U(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:U(e.from)}),` → `,(0,s.jsx)(`span`,{className:`text-foreground`,children:U(e.to)})]},e.field))}))]})]},e.id??t)})})})}var W={createdAt:`created_at`,createdBy:`created_by`,updatedAt:`updated_at`,updatedBy:`updated_by`};function ne(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 re(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 ie(e){try{return new Intl.DateTimeFormat(void 0,{dateStyle:`medium`,timeStyle:`short`}).format(e)}catch{return e.toISOString()}}var ae=({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)})},oe=({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:re(n,o)})}),(0,s.jsx)(r.TooltipContent,{side:`top`,children:ie(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)(ae,{value:t,objectSchema:i,fieldName:a}):null,t&&c?(0,s.jsx)(`span`,{className:`text-muted-foreground/40`,children:`·`}):null,c]})},G=({data:e,objectSchema:t,objectName:n,className:i})=>{let{t:a}=C();if(!e)return null;let o=ne(e[W.createdAt]),c=ne(e[W.updatedAt]),l=e[W.createdBy],u=e[W.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)(oe,{label:a(`detail.createdBy`),user:l,date:o,objectSchema:t,userField:W.createdBy,t:a}),p&&(0,s.jsx)(oe,{label:a(`detail.updatedBy`),user:u,date:c,objectSchema:t,userField:W.updatedBy,t:a})]})},se=5;function ce(e,t,n,r){if(e&&typeof e==`object`){if(t.primaryField){let n=e[t.primaryField];if(n!=null&&n!==``)return String(n)}let r=n?.titleFormat,i=typeof r==`string`?r:r&&typeof r==`object`&&typeof r.source==`string`?r.source:void 0;if(i){let t=`[-\\u2013\\u2014|/·,:]`,n=!1,r=i.replace(/\{([^{}]+)\}/g,(t,r)=>{let i=String(r).trim().split(`.`),a=e;for(let e of i){if(a==null)break;a=a[e]}if(a&&typeof a==`object`){let e=a,t=e.name??e.full_name??e.display_name??e.label??e.title??e.subject??null;(t==null||typeof t==`string`&&!t.trim())&&(t=[e.salutation,e.first_name,e.last_name].filter(e=>typeof e==`string`&&e.trim()).map(e=>e.trim()).join(` `)||(typeof e.email==`string`&&e.email.trim()?e.email.trim():null)),a=t}return a!=null&&a!==``?(n=!0,String(a)):`\0`});if(n){let e=r.replace(RegExp(`\\s*${t}\\s*`,`g`),``).replace(RegExp(`\\s*${t}\\s*`,`g`),``).replace(RegExp(`\0`,`g`),``).replace(/\s+/g,` `).trim();if(e)return e}}}if(t.title)return t.title;if(e&&typeof e==`object`)for(let t of[`name`,`full_name`,`fullName`,`title`,`subject`,`label`,`display_name`,`displayName`]){let n=e[t];if(typeof n==`string`&&n.trim())return n.trim();if(n!=null&&n!==``)return String(n)}return r}var K=({schema:e,dataSource:o,className:l,onEdit:u,onDelete:d,onBack:f,inlineEdit:p=!1,onFieldSave:m,discussionSlot:h,rightRail:g,objectLabel:_,onDataLoaded:v})=>{let[y,b]=n.useState(e.data),[x,S]=n.useState(!e.data&&!!(e.api&&e.resourceId||o&&e.objectName&&e.resourceId)),[w,D]=n.useState(!1),[j,N]=n.useState(!1),[P,F]=n.useState({}),[I,L]=n.useState(null),[z,B]=n.useState(!1),{t:V}=C(),{fieldOptionLabel:H}=(0,a.useSafeFieldLabel)(),ee=(0,r.useIsMobile)(),U=(0,c.usePermissions)(),W=n.useMemo(()=>{if(!U?.isLoaded||!e.objectName)return e;let t=t=>U.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,U]);n.useEffect(()=>{y&&v&&v(y)},[y,v]);let ne=n.useMemo(()=>{if(W.summaryFields&&W.summaryFields.length>0)return[];let e=[...W.sections?.flatMap(e=>e.fields)||[],...W.fields||[]],t={};for(let n of e)t[n.name]||(t[n.name]=n);if(I?.fields)for(let[e,n]of Object.entries(I.fields))t[e]={...t[e]||{},...n,name:e};let n=e=>y?.[e]!==void 0&&y?.[e]!==null&&y?.[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},[W.summaryFields,W.sections,W.fields,I,y]),re=W.summaryFields&&W.summaryFields.length>0?W.summaryFields:ne,ie=n.useCallback(()=>{W.resourceId&&navigator.clipboard.writeText(String(W.resourceId)).then(()=>{B(!0),setTimeout(()=>B(!1),1500)})},[W.resourceId]);n.useEffect(()=>{let e=!0;if(W.data){b(W.data),S(!1);return}if(o&&W.objectName&&W.resourceId){S(!0),L(null),b(null);let n=W.objectName,r=W.resourceId,i=`${n}-`,a=[...W.sections?.flatMap(e=>e.fields)||[],...W.fields||[]];(o.getObjectSchema?o.getObjectSchema(n).catch(()=>null):Promise.resolve(null)).then(s=>{if(!e)return;L(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&&(b(t),S(!1))}).catch(()=>{e&&(b(null),S(!1))})};return u.catch(()=>null).then(t=>{if(e){if(t){b(t),S(!1);return}return d()}})}).catch(t=>{e&&(console.error(`Failed to fetch detail data:`,t),S(!1))})}else W.api&&W.resourceId&&(S(!0),fetch(`${W.api}/${W.resourceId}`).then(e=>e.json()).then(t=>{e&&b(t?.data||t)}).catch(e=>{console.error(`Failed to fetch detail data:`,e)}).finally(()=>{e&&S(!1)}));return()=>{e=!1}},[W.api,W.resourceId,W.objectName,o,W.sections,W.fields]);let ae=n.useCallback(()=>{if(f)f();else if(W.onNavigate){let e=W.backUrl||(W.objectName?`/${W.objectName}`:`/`);W.onNavigate(e,{replace:!0})}else W.backUrl?window.location.href=W.backUrl:window.history.back()},[f,W]),oe=n.useCallback(()=>{u?u():W.onNavigate&&W.editUrl?W.onNavigate(W.editUrl):W.onNavigate&&W.objectName&&W.resourceId?W.onNavigate(`/${W.objectName}/${W.resourceId}/edit`):W.editUrl&&(window.location.href=W.editUrl)},[u,W]),K=n.useCallback(()=>{let e=W.deleteConfirmation||V(`detail.deleteConfirmation`);window.confirm(e)&&(d?.(),W.onNavigate&&W.objectName&&W.onNavigate(`/${W.objectName}`,{replace:!0}))},[d,W]),q=n.useCallback(()=>{navigator.share&&W.objectName&&W.resourceId?navigator.share({title:W.title||V(`detail.details`),text:`${W.objectName} #${W.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`)})},[W]),le=n.useCallback(()=>{D(!w)},[w]),J=n.useCallback(()=>{if(j){let e=Object.entries(P);if(e.length>0){let t={...y,...P};b(t),e.forEach(([e,n])=>{m?.(e,n,t)})}F({})}N(!j)},[j,P,y,m]),ue=n.useCallback(()=>{F({}),N(!1)},[]),Y=n.useCallback((e,t)=>{F(n=>({...n,[e]:t}))},[]);n.useEffect(()=>{if(!W.recordNavigation)return;let e=W.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)},[W.recordNavigation]);let X=n.useMemo(()=>W.related??[],[W.related]),Z=n.useMemo(()=>{let e=[];return e.push({name:`sys_share`,label:V(`detail.share`),icon:`share-2`,type:`script`,onClick:q}),W.showEdit&&e.push({name:`sys_edit_mobile`,label:V(`detail.edit`),icon:`edit`,type:`script`,className:`sm:hidden`,onClick:oe}),p&&e.push({name:`sys_toggle_inline_edit_mobile`,label:V(j?`detail.save`:`detail.editInline`),icon:`edit`,type:`script`,className:`sm:hidden`,onClick:J}),W.showDelete&&e.push({name:`sys_delete`,label:V(`detail.delete`),icon:`trash-2`,type:`script`,variant:`destructive`,tags:[`separator-before`],onClick:K}),e},[V,W.showEdit,W.showDelete,p,j,q,oe,J,K]),de=n.useMemo(()=>{let e=W.actions??[];if(Z.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,...Z]}}return e});return t||n.push({type:`action:bar`,location:`record_header`,systemActions:Z}),n},[W.actions,Z]);return x||W.loading?(0,s.jsxs)(`div`,{className:(0,r.cn)(`space-y-4`,l),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`})]}):!y&&!W.data?(0,s.jsxs)(`div`,{className:(0,r.cn)(`flex flex-col items-center justify-center py-16 text-center`,l),children:[(0,s.jsx)(`p`,{className:`text-lg font-semibold`,children:V(`detail.recordNotFound`)}),(0,s.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:V(`detail.recordNotFoundDescription`)}),(W.showBack??!0)&&(0,s.jsxs)(r.Button,{variant:`outline`,size:`sm`,onClick:ae,className:`mt-4 gap-2`,children:[(0,s.jsx)(i.ArrowLeft,{className:`h-4 w-4`}),V(`detail.goBack`)]})]}):(0,s.jsx)(r.TooltipProvider,{children:(0,s.jsxs)(`div`,{className:(0,r.cn)(`space-y-6`,l),children:[W.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:[(W.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:ae,className:`shrink-0 mt-1`,children:(0,s.jsx)(i.ArrowLeft,{className:`h-4 w-4`})})}),(0,s.jsx)(r.TooltipContent,{children:V(`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:ce(y,W,I,V(`detail.details`))}),re.map(e=>{let t=y?.[e];if(t==null||t===``)return null;let n=(W.sections||[]).flatMap(e=>e.fields).concat(W.fields||[]).find(t=>t.name===e),i=I?.fields?.[e],a=n?.type||i?.type,o=String(t),c=null;try{if(a===`currency`){let e=Number(t);Number.isNaN(e)||(o=new Intl.NumberFormat(void 0,{style:`currency`,currency:n?.currency||i?.currency||`USD`,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=W.objectName?H(W.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:le,"aria-label":V(w?`detail.removeFromFavorites`:`detail.addToFavorites`),children:w?(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:V(w?`detail.removeFromFavorites`:`detail.addToFavorites`)})]})]}),W.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:_||W.objectName}),W.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:ie,"aria-label":V(`detail.copyRecordId`,{defaultValue:`Copy record ID`}),children:z?(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:z?V(`detail.copied`,{defaultValue:`Copied`}):V(`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:[W.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:W.recordNavigation.currentIndex<=0,onClick:()=>{let e=W.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:V(`detail.previousRecord`)})]}),(0,s.jsx)(`span`,{className:`text-xs text-muted-foreground whitespace-nowrap px-1`,children:V(`detail.recordOf`,{current:W.recordNavigation.currentIndex+1,total:W.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:W.recordNavigation.currentIndex>=W.recordNavigation.recordIds.length-1,onClick:()=>{let e=W.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:V(`detail.nextRecord`)})]})]}),p&&(0,s.jsxs)(s.Fragment,{children:[j&&(0,s.jsxs)(r.Tooltip,{children:[(0,s.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,s.jsxs)(r.Button,{variant:`ghost`,size:`sm`,onClick:ue,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:V(`detail.cancel`)})]})}),(0,s.jsx)(r.TooltipContent,{children:V(`detail.cancelEdit`)})]}),(0,s.jsxs)(r.Tooltip,{children:[(0,s.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,s.jsx)(r.Button,{variant:j?`default`:`outline`,size:`sm`,onClick:J,className:`gap-2 hidden sm:inline-flex`,children:j?(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:V(`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:V(`detail.editInline`)})]})})}),(0,s.jsx)(r.TooltipContent,{children:V(j?`detail.saveChanges`:`detail.editFieldsInline`)})]})]}),W.showEdit&&(0,s.jsxs)(r.Tooltip,{children:[(0,s.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,s.jsxs)(r.Button,{variant:`default`,onClick:oe,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:V(`detail.edit`)})]})}),(0,s.jsx)(r.TooltipContent,{children:V(`detail.editRecord`)})]}),de.map((e,t)=>(0,s.jsx)(a.SchemaRenderer,{schema:e,data:y},`header-action-${t}`))]})]}),W.header&&(0,s.jsx)(`div`,{children:(0,s.jsx)(a.SchemaRenderer,{schema:W.header,data:y})}),W.highlightFields&&W.highlightFields.length>0&&(0,s.jsx)(A,{fields:W.highlightFields,data:y,objectName:W.objectName,objectSchema:I}),W.autoTabs&&!W.tabs?.length?(()=>{let e=X.length>0,t=!!W.activities&&W.activities.length>0,n=!!h,i=!!W.history,a=(0,s.jsxs)(`div`,{className:`space-y-3 sm:space-y-4`,children:[W.sectionGroups&&W.sectionGroups.length>0&&W.sectionGroups.map((e,t)=>(0,s.jsx)(k,{group:e,data:{...y,...P},objectSchema:I,objectName:W.objectName,isEditing:j,onFieldChange:Y},t)),W.sections&&W.sections.length>0&&W.sections.map((e,t)=>(0,s.jsx)(T,{section:e,data:{...y,...P},objectSchema:I,objectName:W.objectName,isEditing:j,onFieldChange:Y},t)),W.fields&&W.fields.length>0&&!W.sections?.length&&(0,s.jsx)(T,{section:{fields:W.fields,columns:W.columns},data:{...y,...P},objectSchema:I,objectName:W.objectName,isEditing:j,onFieldChange:Y}),W.comments&&(0,s.jsx)(M,{comments:W.comments,onAddComment:W.onAddComment})]});return!e&&!t&&!n&&!i?(0,s.jsx)(`div`,{className:`mt-2`,children:a}):(0,s.jsxs)(r.Tabs,{defaultValue:`details`,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:V(`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:[V(`detail.related`),(0,s.jsx)(r.Badge,{variant:`secondary`,className:`text-xs bg-primary/10 text-primary border-transparent`,children:X.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:[V(`detail.activity`),(0,s.jsx)(r.Badge,{variant:`secondary`,className:`text-xs bg-primary/10 text-primary border-transparent`,children:W.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:V(`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:[V(`detail.history`,{defaultValue:`History`}),!W.history.loading&&W.history.entries.length>0&&(0,s.jsx)(r.Badge,{variant:`secondary`,className:`text-xs bg-primary/10 text-primary border-transparent`,children:W.history.entries.length})]})})]}),(0,s.jsx)(r.TabsContent,{value:`details`,className:`mt-4`,children:a}),e&&(0,s.jsx)(r.TabsContent,{value:`related`,className:`mt-4`,children:(0,s.jsx)(`div`,{className:`space-y-3`,children:X.map((e,t)=>(0,s.jsx)(O,{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:ee&&t>0,pageSize:se},t))})}),t&&(0,s.jsx)(r.TabsContent,{value:`activity`,className:`mt-4`,children:(0,s.jsx)(R,{activities:W.activities})}),n&&(0,s.jsx)(r.TabsContent,{value:`discussion`,className:`mt-4`,children:h}),i&&(0,s.jsx)(r.TabsContent,{value:`history`,className:`mt-4`,children:(0,s.jsx)(te,{entries:W.history.entries,loading:W.history.loading,emptyText:W.history.emptyText??V(`detail.historyEmpty`,{defaultValue:`No history yet`})})})]})})():(0,s.jsxs)(s.Fragment,{children:[W.sectionGroups&&W.sectionGroups.length>0&&(0,s.jsx)(`div`,{className:`space-y-3 sm:space-y-4`,children:W.sectionGroups.map((e,t)=>(0,s.jsx)(k,{group:e,data:{...y,...P},objectSchema:I,objectName:W.objectName,isEditing:j,onFieldChange:Y},t))}),W.sections&&W.sections.length>0&&(0,s.jsx)(`div`,{className:`space-y-3 sm:space-y-4`,children:W.sections.map((e,t)=>(0,s.jsx)(T,{section:e,data:{...y,...P},objectSchema:I,objectName:W.objectName,isEditing:j,onFieldChange:Y},t))}),W.fields&&W.fields.length>0&&!W.sections?.length&&(0,s.jsx)(T,{section:{fields:W.fields,columns:W.columns},data:{...y,...P},objectSchema:I,objectName:W.objectName,isEditing:j,onFieldChange:Y}),W.tabs&&W.tabs.length>0&&(0,s.jsx)(E,{tabs:W.tabs,data:y}),X.length>0&&(0,s.jsxs)(`div`,{className:`space-y-3`,children:[(0,s.jsx)(`h2`,{className:`text-lg font-semibold`,children:V(`detail.related`)}),X.map((e,t)=>(0,s.jsx)(O,{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:ee&&t>0,pageSize:se},t))]}),W.comments&&(0,s.jsx)(M,{comments:W.comments,onAddComment:W.onAddComment}),W.activities&&W.activities.length>0&&(0,s.jsx)(R,{activities:W.activities})]}),(0,s.jsx)(G,{data:{...y,...P},objectSchema:I,objectName:W.objectName}),W.footer&&(0,s.jsx)(`div`,{children:(0,s.jsx)(a.SchemaRenderer,{schema:W.footer,data:y})})]})})},q=e=>typeof e==`string`?e:e&&typeof e==`object`&&(e.field||e.name)||null,le=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}},J=({schema:e={},className:t,...n})=>{let r=(0,a.useRecordContext)(),{designer:i}=le(n);if(!r)return(0,s.jsx)(`div`,{className:t,"data-record-details-placeholder":!0,...i,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 o=e.layout===`inline`||e.layout===`compact`?`horizontal`:`vertical`,l=r.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,...i,role:`status`,"aria-live":`polite`,children:(0,s.jsx)(`p`,{className:`text-sm text-muted-foreground italic`,children:`Insufficient permissions to view details.`})});let p=e.enforceFieldSecurity===!0,m=Array.isArray(e.redactFields)?e.redactFields:[],h=e=>{if(!e||!p&&m.length===0)return e;let t=e.map(q).filter(e=>!!e),n=new Set((p&&l?d(t):t).filter(e=>!m.includes(e)));return e.filter(e=>{let t=q(e);return t?n.has(t):!0})},g=e=>typeof e==`string`?{name:e}:e&&typeof e==`object`&&!e.name&&e.field?{...e,name:e.field}:e,_=e=>Array.isArray(e)?e.map(g):e,v=(0,a.useHighlightFieldNames)(),y=new Set((Array.isArray(e.hideFields)?e.hideFields:[]).map(e=>typeof e==`string`?e:q(e)).filter(e=>!!e));for(let e of v)y.add(e);let b=r.objectSchema,x=r.data??{},S=[b?.primaryField,`name`,`full_name`,`title`,`subject`,`display_name`,`label`].filter(e=>typeof e==`string`&&e.length>0);for(let e of S)if(x[e]!==void 0&&x[e]!==null&&x[e]!==``){y.add(e);break}let C=e=>!e||y.size===0?e:e.filter(e=>{let t=q(e);return t?!y.has(t):!0}),w=C(_(h(e.fields))),T=Array.isArray(e.sections)?e.sections.map(e=>({...e,title:e.title??e.label,showBorder:e.showBorder??!1,hideEmpty:e.hideEmpty??!0,fields:C(_(h(e.fields)))})):e.sections,E=e.inlineEdit??!0,D={type:`detail-view`,objectName:r.objectName,resourceId:r.recordId,data:r.data,layout:o,columns:e.columns,sections:T,fields:w,showBack:!1,showHeader:e.showHeader??!1,inlineEdit:E};return(0,s.jsx)(`div`,{className:t,...i,children:(0,s.jsx)(K,{schema:D,dataSource:r.dataSource,inlineEdit:E})})},ue=e=>typeof e==`string`?e:e&&typeof e==`object`&&(e.field||e.name||e.key)||null,Y=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,...n})=>{let r=(0,a.useRecordContext)(),{designer:i}=Y(n),o=e.title||e.objectName||`Related`,l=e.objectName;if(!l)return(0,s.jsx)(`div`,{className:t,...i,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 u=(0,c.usePermissions)(),{readableFields:d}=(0,c.useFieldPermissions)(l),f=Array.isArray(e.requiredPermissions)?e.requiredPermissions:[];if(f.length>0&&!f.every(e=>u.can(l,e)))return(0,s.jsx)(`div`,{className:t,...i,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 p=e.enforceFieldSecurity===!0,m=Array.isArray(e.redactFields)?e.redactFields:[],h=Array.isArray(e.columns)?e.columns:[],g=h;if(p||m.length>0){let e=h.map(ue).filter(e=>!!e),t=new Set((p?d(e):e).filter(e=>!m.includes(e)));g=h.filter(e=>{let n=ue(e);return n?t.has(n):!0})}return(0,s.jsx)(`div`,{className:t,...i,children:(0,s.jsx)(O,{title:o,type:`table`,api:l,objectName:l,referenceField:e.relationshipField,parentId:r?.recordId,columns:g,pageSize:e.limit,dataSource:r?.dataSource})})},Z=e=>{let{"data-obj-id":t,"data-obj-type":n,style:r,...i}=e||{};return{designer:{"data-obj-id":t,"data-obj-type":n,style:r},rest:i}},de=({schema:e={},className:t,...r})=>{let i=(0,a.useRecordContext)(),{designer:o}=Z(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)(A,{fields:_,data:i?.data,objectName:i?.objectName,objectSchema:i?.objectSchema})})},Q=({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})]})},$=[`👍`,`❤️`,`🎉`,`😂`,`😮`,`😢`],fe=({reactions:e,onToggleReaction:t,emojiOptions:a=$,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 pe(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 me=({parentItem:e,replies:t,onAddReply:a,showReplyInput:o=!0,className:c})=>{let{t:l}=C(),[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:pe(e.createdAt)})]}),(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`})})]})]})},he=({subscription:e,onToggle:t,className:a})=>{let{t:o}=C(),[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`})})},ge={comment:i.MessageSquare,field_change:i.Edit,task:i.CheckSquare,event:i.Calendar,system:i.Zap,email:i.Mail,call:i.Phone},_e={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 ve(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 ye(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 be(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 xe=({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,titleLabel:_,emptyLabel:v,className:y})=>{let{t:b}=C(),[x,S]=n.useState(`all`),[w,T]=n.useState(``),[E,D]=n.useState(!1),[O,k]=n.useState(!1),A=a??x,j=t?.showFilterToggle!==!1,M=t?.showCommentInput!==!1&&!!d,N=t?.enableReactions??!1,P=t?.enableThreading??!1,F=t?.showSubscriptionToggle??!1,I=n.useMemo(()=>be(e,A),[e,A]),L=n.useMemo(()=>P?I.filter(e=>!e.parentId):I,[I,P]),R=n.useMemo(()=>{if(!P)return new Map;let e=new Map;for(let t of I)if(t.parentId){let n=e.get(t.parentId)??[];n.push(t),e.set(t.parentId,n)}return e},[I,P]),z=n.useCallback(e=>{o?o(e):S(e)},[o]),B=n.useCallback(async()=>{let e=w.trim();if(!(!e||!d)){D(!0);try{await d(e),T(``)}finally{D(!1)}}},[w,d]),V=n.useCallback(e=>{e.key===`Enter`&&(e.ctrlKey||e.metaKey)&&(e.preventDefault(),B())},[B]),H=n.useCallback(async()=>{if(l){k(!0);try{await l()}finally{k(!1)}}},[l]);return(0,s.jsxs)(`section`,{className:(0,r.cn)(`border-t border-border/60 pt-5`,y),"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`}),_??b(`detail.activity`),(0,s.jsxs)(`span`,{className:`text-sm font-normal text-muted-foreground`,children:[`(`,I.length,`)`]})]}),(0,s.jsx)(`div`,{className:`flex items-center gap-1`,children:F&&m&&(0,s.jsx)(he,{subscription:m,onToggle:h})})]})}),(0,s.jsxs)(`div`,{className:`space-y-4`,children:[j&&(0,s.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,s.jsx)(`select`,{className:`rounded-md border border-input bg-background px-2.5 py-1.5 text-sm focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`,value:A,onChange:e=>z(e.target.value),"aria-label":b(`detail.filterActivity`),children:ve(b).map(e=>(0,s.jsx)(`option`,{value:e.value,children:e.label},e.value))})}),M&&(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:b(`detail.leaveCommentPlaceholder`),value:w,onChange:e=>T(e.target.value),onKeyDown:V,disabled:E}),(0,s.jsxs)(r.Button,{variant:`default`,onClick:B,disabled:!w.trim()||E,className:`shrink-0 self-end gap-1.5`,"aria-label":b(`detail.submitComment`),title:b(`detail.submitComment`),children:[(0,s.jsx)(i.Send,{className:`h-4 w-4`}),(0,s.jsx)(`span`,{children:b(`detail.sendComment`)})]})]}),I.length===0?g?null:(0,s.jsx)(`p`,{className:`text-sm text-muted-foreground text-center py-4`,children:v??b(`detail.noActivity`)}):(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:L.map(e=>{let t=ge[e.type]||i.Zap,n=_e[e.type]||`bg-gray-100 text-gray-600`,a=R.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:b(`detail.via`,{source:e.source})}),(0,s.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:ye(e.createdAt)}),e.edited&&(0,s.jsx)(`span`,{className:`text-xs text-muted-foreground italic`,children:b(`detail.edited`)}),e.pinned&&(0,s.jsxs)(`span`,{className:`text-xs text-amber-600`,children:[`📌 `,b(`detail.pinned`)]})]}),e.body&&(0,s.jsx)(`p`,{className:`text-sm whitespace-pre-wrap break-words text-muted-foreground`,children:e.body}),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)(Q,{change:e},t))}),N&&e.reactions&&e.reactions.length>0&&(0,s.jsx)(`div`,{className:`mt-1.5`,children:(0,s.jsx)(fe,{reactions:e.reactions,onToggleReaction:p?t=>p(e.id,t):void 0})}),N&&(!e.reactions||e.reactions.length===0)&&p&&(0,s.jsx)(`div`,{className:`mt-1.5`,children:(0,s.jsx)(fe,{reactions:[],onToggleReaction:t=>p(e.id,t)})})]})]}),P&&(e.replyCount??0)>0&&(0,s.jsx)(me,{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:H,disabled:O,"aria-label":b(`detail.loadMore`),children:[O?(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`}),b(`detail.loadMore`)]})})]})]})},Se=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}},Ce=({schema:e={},className:t,...n})=>{(0,a.useRecordContext)();let{designer:r}=Se(n);return(0,s.jsx)(`div`,{className:t,...r,children:(0,s.jsx)(xe,{items:[],config:e})})},we=({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,className:_})=>{let v=e?.position??`right`,y=e?.width??`360px`,b=e?.collapsible??!0,x=g&&t.length===0||(e?.defaultCollapsed??!1),{t:S}=C(),[w,T]=n.useState(x);return v===`right`||v===`left`?w&&b?(0,s.jsx)(`div`,{className:(0,r.cn)(`flex items-start pt-4`,v===`right`?`border-l`:`border-r`,_),children:(0,s.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-8 w-8 mx-1`,onClick:()=>T(!1),"aria-label":S(`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`,v===`right`?`border-l`:`border-r`,_),style:{width:y,minWidth:y},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:S(`detail.discussion`)})]}),b&&(0,s.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:()=>T(!0),"aria-label":S(`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)(xe,{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,titleLabel:S(`detail.discussion`),emptyLabel:S(`detail.noCommentsYet`),className:`border-0 shadow-none`})})]}):(0,s.jsx)(`div`,{className:(0,r.cn)(``,_),children:b&&w?(0,s.jsxs)(r.Button,{variant:`ghost`,className:`w-full justify-start gap-2 text-muted-foreground`,onClick:()=>T(!1),"aria-label":S(`detail.showDiscussion`,{count:t.length}),children:[(0,s.jsx)(i.MessageSquare,{className:`h-4 w-4`}),(0,s.jsx)(`span`,{children:S(`detail.showDiscussion`,{count:t.length})})]}):(0,s.jsxs)(`div`,{children:[b&&(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`}),S(`detail.discussion`)]}),(0,s.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:()=>T(!0),"aria-label":S(`detail.hideDiscussion`),children:(0,s.jsx)(i.PanelRightClose,{className:`h-3.5 w-3.5`})})]}),(0,s.jsx)(xe,{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,titleLabel:S(`detail.discussion`),emptyLabel:S(`detail.noCommentsYet`)})]})})},Te=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}},Ee=({schema:e={},className:t,...n})=>{(0,a.useRecordContext)();let r=(0,a.useDiscussionContext)(),{designer:i}=Te(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)(we,{items:r?.items||[],config:o,onAddComment:r?.onAddComment,onAddReply:r?.onAddReply,onToggleReaction:r?.onToggleReaction})})},De=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}},Oe=({schema:e={},className:t,...i})=>{let o=(0,a.useRecordContext)(),{translateOptions:c}=(0,a.useSafeFieldLabel)(),{designer:l}=De(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?e:u},[u,d,o?.objectName,c]),p=d&&o?.data?o.data[d]:void 0,m=f.findIndex(e=>e.value===p);if(m<0&&(m=-1),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 h=(e,t)=>{if(f.length!==1)return e===0?`polygon(0 0, calc(100% - 14px) 0, 100% 50%, calc(100% - 14px) 100%, 0 100%)`:e===t?`polygon(0 0, 100% 0, 100% 100%, 0 100%, 14px 50%)`:`polygon(0 0, calc(100% - 14px) 0, 100% 50%, calc(100% - 14px) 100%, 0 100%, 14px 50%)`},g=f.length-1;return(0,s.jsxs)(`div`,{className:(0,r.cn)(`w-full`,t),...l,children:[(0,s.jsx)(`div`,{className:`hidden sm:flex w-full items-stretch`,role:`list`,"aria-label":e.aria?.label||`Record path`,children:f.map((e,t)=>{let n=m>=0&&t<m,i=t===m,a=h(t,g);return(0,s.jsx)(`div`,{role:`listitem`,"aria-current":i?`step`:void 0,style:a?{clipPath:a,WebkitClipPath:a}:void 0,className:(0,r.cn)(`relative flex-1 min-w-0 px-5 py-2 text-xs font-medium text-center`,t>0&&`-ml-2`,f.length===1&&`rounded-md border`,i&&`bg-primary text-primary-foreground shadow-sm ring-1 ring-primary/40`,n&&`bg-muted text-muted-foreground`,!i&&!n&&`bg-background text-foreground/70 border border-border/60`),children:(0,s.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 truncate`,style:{paddingLeft:t===0?0:`${14/2}px`,paddingRight:t===g?0:`${14/2}px`},children:[n&&(0,s.jsx)(`span`,{"aria-hidden":!0,children:`✓`}),e.label]})},`${e.value}-${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=m>=0&&t<m,i=t===m;return(0,s.jsx)(`div`,{role:`listitem`,"aria-current":i?`step`:void 0,className:(0,r.cn)(`shrink-0 px-3 py-1.5 rounded-full text-xs font-medium border whitespace-nowrap`,i&&`bg-primary text-primary-foreground border-primary shadow-sm ring-1 ring-primary/40`,n&&`bg-muted text-muted-foreground border-transparent`,!i&&!n&&`bg-background text-foreground/70 border-border/60`),children:(0,s.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[n&&(0,s.jsx)(`span`,{"aria-hidden":!0,children:`✓`}),e.label]})},`${e.value}-${t}-m`)})})]})},ke=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}},Ae=({schema:e={},className:t,...n})=>{let i=(0,a.useRecordContext)(),{designer:o}=ke(n),l=(0,c.usePermissions)(),u=Array.isArray(e.actions)?e.actions:Array.isArray(e.properties?.actions)?e.properties.actions:[],d=i?.objectName||``,f=Array.isArray(e.requiredPermissions)?e.requiredPermissions:[];if(f.length>0&&d&&!f.every(e=>l.can(d,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 p=e.location||`record_header`,{getActionsForLocation:m,executeAction:h}=(0,a.useActionEngine)({actions:u,context:{record:i?.data,recordId:i?.recordId,objectName:i?.objectName}}),g=u.length>0?m(p):[];if(g.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 _=e.align||`end`,v=_===`start`?`justify-start`:_===`center`?`justify-center`:`justify-end`;return(0,s.jsx)(`div`,{className:(0,r.cn)(`flex flex-wrap items-center gap-2`,p===`record_header`&&!e.inline&&`-mt-12 sm:-mt-14 mb-2 relative z-10`,v,t),role:`toolbar`,"aria-label":e.aria?.label||`Quick actions`,...o,children:g.map((t,n)=>{let i=t.label||t.name||`Action ${n+1}`;return(0,s.jsx)(r.Button,{variant:t.variant||e.variant||`default`,size:t.size||e.size||`sm`,disabled:typeof t.disabled==`boolean`?t.disabled:void 0,onClick:()=>{if(typeof t.onClick==`function`){t.onClick();return}t.name&&h(t.name)},children:i},t.name||`qa-${n}`)})})},je=e=>{let{"data-obj-id":t,"data-obj-type":n,style:r,...i}=e||{};return{designer:{"data-obj-id":t,"data-obj-type":n,style:r},rest:i}},Me=({schema:e={},className:t,...n})=>{let{designer:r}=je(n),i=Array.isArray(e.entries)?e.entries:Array.isArray(e.properties?.entries)?e.properties.entries:[],a=e.loading??e.properties?.loading??!1,o=e.emptyText??e.properties?.emptyText;return(0,s.jsx)(`div`,{className:t,...r,children:(0,s.jsx)(te,{entries:i,loading:a,emptyText:o})})},Ne=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`]),Pe=480,Fe=95;function Ie({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=Ne,onFieldSave:m,onDelete:h,resizable:g=!0,fullPageHref:_}){let{t:v}=C(),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>=Pe)return t}}catch{}return null}),S=n.default.useMemo(()=>g&&b!=null?`${b}px`:typeof d==`number`?`${d}px`:d,[g,b,d]),w=S?{width:S,maxWidth:S}:void 0,T=n.default.useRef(null),E=n.default.useCallback(e=>{if(!g)return;e.preventDefault();let t=b??(typeof window<`u`?Math.min(window.innerWidth*.6,960):720);T.current={startX:e.clientX,startWidth:t};let n=e=>{let t=T.current;if(!t)return;let n=t.startX-e.clientX,r=typeof window<`u`?window.innerWidth*Fe/100:1600,i=Math.min(r,Math.max(Pe,t.startWidth+n));x(Math.round(i))},r=()=>{T.current,T.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,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:w,onOpenAutoFocus:e=>e.preventDefault(),children:[g&&(0,s.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize drawer`,onPointerDown:E,className:`hidden sm:block absolute left-0 top-0 h-full w-1.5 cursor-col-resize select-none bg-transparent hover:bg-primary/30 active:bg-primary/50 transition-colors z-10`}),(0,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)(K,{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 Le(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 Re=({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 ze(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 Be=({value:e,onChange:t,onSubmit:a,mentionSuggestions:o=[],placeholder:c,className:l,disabled:u=!1})=>{let{t:d}=C(),[f,p]=n.useState(!1),[m,h]=n.useState(!1),[g,_]=n.useState(``),[v,y]=n.useState(0),b=n.useRef(null),x=n.useMemo(()=>{if(!g)return o;let e=g.toLowerCase();return o.filter(t=>t.label.toLowerCase().includes(e))},[g,o]),S=n.useCallback((n,r=``)=>{let i=b.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]),w=n.useCallback(()=>S(`**`,`**`),[S]),T=n.useCallback(()=>S(`*`,`*`),[S]),E=n.useCallback(()=>S(`
|
|
2
|
-
- `,``),[S]),D=n.useCallback(()=>S("`","`"),[S]),O=n.useCallback(()=>{S(`@`,``),h(!0),_(``),y(0)},[S]),k=n.useCallback(n=>{let r=b.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)),h(!1),_(``),requestAnimationFrame(()=>r.focus())},[e,t]),A=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)){h(!0),_(e),y(0);return}}h(!1)},[t]),j=n.useCallback(e=>{if(m&&x.length>0){if(e.key===`ArrowDown`){e.preventDefault(),y(e=>e<x.length-1?e+1:0);return}if(e.key===`ArrowUp`){e.preventDefault(),y(e=>e>0?e-1:x.length-1);return}if(e.key===`Enter`||e.key===`Tab`){e.preventDefault(),k(x[v]);return}if(e.key===`Escape`){h(!1);return}}e.key===`Enter`&&(e.ctrlKey||e.metaKey)&&(e.preventDefault(),a?.())},[m,x,v,k,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:w,disabled:u||f,title:d(`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:T,disabled:u||f,title:d(`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:E,disabled:u||f,title:d(`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:D,disabled:u||f,title:d(`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:O,disabled:u||f,title:d(`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:()=>p(!f),title:d(f?`detail.edit`:`detail.preview`),children:f?(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||!e.trim(),title:d(`detail.submitComment`),children:(0,s.jsx)(i.Send,{className:`h-3.5 w-3.5`})})]}),(0,s.jsx)(`div`,{className:`relative`,children:f?(0,s.jsx)(`div`,{className:`min-h-[80px] px-3 py-2 text-sm prose prose-sm max-w-none`,dangerouslySetInnerHTML:{__html:ze(e)}}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`textarea`,{ref:b,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??d(`detail.writeComment`),value:e,onChange:A,onKeyDown:j,disabled:u}),m&&x.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:x.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===v&&`bg-accent`),onMouseDown:t=>{t.preventDefault(),k(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))})]})})]})};function Ve(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(`react-router-dom`)):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`,`react-router-dom`],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.react_router_dom))})(this,function(e,t,n,r,i,a,o,s,c,l){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var u=Object.create,d=Object.defineProperty,f=Object.getOwnPropertyDescriptor,p=Object.getOwnPropertyNames,m=Object.getPrototypeOf,h=Object.prototype.hasOwnProperty,g=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=p(t),a=0,o=i.length,s;a<o;a++)s=i[a],!h.call(e,s)&&s!==n&&d(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=f(t,s))||r.enumerable});return e};n=((e,t,n)=>(n=e==null?{}:u(m(e)),g(t||!e||!e.__esModule?d(n,`default`,{value:e,enumerable:!0}):n,e)))(n,1);var _=new Set([`textarea`,`markdown`,`html`,`grid`,`rich-text`,`field:textarea`,`field:markdown`,`field:html`,`field:grid`,`field:rich-text`]);function v(e){return _.has(e)}function y(e,t){let n;return n=e<=3?1:2,t!==void 0&&t<640?Math.min(n,1):n}function b(e,t){return t<=1?e:e.map(e=>e.span===void 0&&e.type&&v(e.type)?{...e,span:t}:e)}function x(e,t,n){if(t!==void 0)return{fields:b(e,t),columns:t};let r=y(e.length,n);return{fields:b(e,r),columns:r}}function S(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 C={"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.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.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`},w=S(C,`detail.back`);function T(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 E=({section:e,data:t,className:c,objectSchema:l,objectName:u,isEditing:d=!1,onFieldChange:f,virtualScroll:p})=>{let[m,h]=n.useState(e.defaultCollapsed??!1),[g,_]=n.useState(null),[v,y]=n.useState(void 0),[b,S]=n.useState(!1),{t:C}=w(),{fieldLabel:E,translateOptions:D}=(0,a.useSafeFieldLabel)(),O=n.useCallback((e,t)=>{let n=t==null?``:String(t);navigator.clipboard.writeText(n).then(()=>{_(e),setTimeout(()=>_(null),2e3)})},[]),k=n.useCallback(e=>{let n=t?.[e.name]??e.value;return n==null||n===``},[t]),A=n.useMemo(()=>e.fields.filter(k).length,[e.fields,k]),j=(0,r.useIsMobile)(),M=j?3:4,N=j?.2:.25,P=e.fields.length-A,F=!e.hideEmpty&&!d&&e.fields.length>=M&&A/e.fields.length>=N&&P>0,I=!b&&(e.hideEmpty||F)?e.fields.filter(e=>!k(e)):e.fields;if(I.length===0&&A===e.fields.length)return null;let{fields:L,columns:R}=x(I,e.columns),z=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=T(e.span,R),p=l?.fields?.[e.name],m={...e};if(p){!e.type&&p.type&&(m.type=p.type),p.options&&!m.options&&(m.options=p.options),p.currency&&!m.currency&&(m.currency=p.currency),p.precision!==void 0&&m.precision===void 0&&(m.precision=p.precision),p.format&&!m.format&&(m.format=p.format);let t=p.reference_to||p.reference;t&&!m.reference_to&&(m.reference_to=t),p.reference_field&&!m.reference_field&&(m.reference_field=p.reference_field)}u&&Array.isArray(m.options)&&m.options.length>0&&(m.options=D(u,e.name,m.options));let h=(()=>{if(n==null||n===``)return(0,s.jsx)(`span`,{className:`text-muted-foreground/60 text-sm select-none`,"aria-label":C(`detail.noValue`,{defaultValue:`No value`}),title:C(`detail.noValue`,{defaultValue:`No value`}),children:`—`});let t=(0,o.resolveCellRendererType)(m)||e.type;if(t){let e=(0,o.getCellRenderer)(t);if(e)return(0,s.jsx)(e,{value:n,field:m})}return String(n)})(),_=n!=null&&n!==``,v=g===e.name;return(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:E(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=m.type||e.type;if(t===`select`&&Array.isArray(m.options)&&m.options.length>0)return(0,s.jsx)(o.SelectField,{field:m,value:n==null?``:String(n),onChange:t=>f?.(e.name,t)});if(t===`boolean`)return(0,s.jsx)(o.BooleanField,{field:m,value:!!n,onChange:t=>f?.(e.name,t)});let r=t===`date`||t===`datetime`;return(0,s.jsx)(`input`,{type:t===`number`?`number`:r?`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?``:r?(()=>{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(n),onChange:t=>{let n=t.target.value;if(r&&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`,_&&`cursor-pointer active:bg-muted/60 transition-colors`),onClick:_?()=>O(e.name,n):void 0,onKeyDown:_?t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),O(e.name,n))}:void 0,role:_?`button`:void 0,tabIndex:_?0:void 0,children:[(0,s.jsx)(`div`,{className:`text-sm flex-1 break-words py-1`,children:h}),_&&(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(),O(e.name,n)},children:v?(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:C(v?`detail.copied`:`detail.copyToClipboard`)})]})})]})]},e.name)},B=p?.enabled===!0,V=p?.batchSize??20;n.useEffect(()=>{if(!B){y(void 0);return}if(L.length<=V){y(void 0);return}y(V);let e=setTimeout(()=>y(void 0),100);return()=>clearTimeout(e)},[B,L.length,V]);let H=v===void 0?L:L.slice(0,v),U=A>0&&(e.hideEmpty||F),W=(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`div`,{className:(0,r.cn)(`grid gap-3 sm:gap-4`,R===1?`grid-cols-1`:R===2?`grid-cols-1 md:grid-cols-2`:`grid-cols-1 md:grid-cols-2 lg:grid-cols-3`),children:H.map(z)}),U&&(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:[b?(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`}),b?C(`detail.hideEmptyFields`,{defaultValue:`Hide empty fields`}):C(`detail.showEmptyFields`,{count:A,defaultValue:`Show ${A} empty field${A===1?``:`s`}`})]})})]});return!e.title&&!e.collapsible&&e.showBorder===!1?(0,s.jsx)(`div`,{className:(0,r.cn)(c),children:W}):e.collapsible?(0,s.jsx)(r.Collapsible,{open:!m,onOpenChange:e=>h(!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:m?(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&&!m&&(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:W})})]})}):(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:W})]})},D=({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`,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 O(e){return e&&i.icons[e.split(/[-_\s]/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``)]||i.Inbox}var k=({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,maxColumns:x=6,pageSize:S,sortable:C=!1,filterable:T=!1,collapsible:E=!1,defaultCollapsed:D=!1,referenceField:k,parentId:A,icon:j})=>{let M=u!==void 0,N=u??[],[P,F]=n.useState(N),[I,L]=n.useState(()=>!!l&&!M),[R,z]=n.useState(0),[B,V]=n.useState(null),[H,U]=n.useState(`asc`),[W,ee]=n.useState(``),[G,K]=n.useState(null),[q,te]=n.useState(D),[ne,re]=n.useState({}),{t:J}=w(),{fieldLabel:ie}=(0,a.useSafeFieldLabel)();n.useEffect(()=>{M&&F(u??[])},[u,M]),n.useEffect(()=>{l&&m?.getObjectSchema&&!f?.length&&m.getObjectSchema(l).then(K).catch(e=>{console.warn(`[RelatedList] Failed to fetch schema for ${l}:`,e)})},[l,m,f]),n.useEffect(()=>{if(l&&!M){if(!(k&&A!=null&&A!==``)){l&&(A==null||A===``)&&!k&&console.warn(`[RelatedList] "${l}" has no referenceField/parentId — refusing to fetch all rows. Pass relationshipField + parentId to scope the query.`),F([]),L(!1);return}L(!0);let e={[k]:A};if(m&&typeof m.find==`function`)m.find(l,{$filter:e}).then(e=>{F(Array.isArray(e)?e:Array.isArray(e?.data)?e.data:[]),L(!1)}).catch(e=>{console.error(`Failed to fetch related data:`,e),L(!1)});else{let e=new URLSearchParams({[`filter[${k}]`]:String(A)}).toString();fetch(`${l}?${e}`).then(e=>e.json()).then(e=>{F(Array.isArray(e)?e:e?.data||[])}).catch(e=>{console.error(`Failed to fetch related data:`,e)}).finally(()=>L(!1))}}},[l,M,m,k,A]),n.useEffect(()=>{if(!m?.find||!G?.fields||!P.length)return;let e=G.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 P){let t=e?.[n];t!=null&&(typeof t==`string`&&t?i.add(t):typeof t==`number`&&i.add(String(t)))}let a=ne[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||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||re(t=>{let n={...t};for(let{fieldName:t,map:r}of e)n[t]={...n[t]||{},...r};return n})}),()=>{n=!0}},[m,G,P]);let ae=n.useMemo(()=>{if(!W)return P;let e=W.toLowerCase();return P.filter(t=>Object.values(t).some(t=>t!=null&&String(t).toLowerCase().includes(e)))},[P,W]),oe=n.useMemo(()=>B?[...ae].sort((e,t)=>{let n=e[B],r=t[B];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 H===`asc`?i:-i}):ae,[ae,B,H]),Y=S&&S>0?S:0,se=Y?Math.max(1,Math.ceil(oe.length/Y)):1,ce=Y?oe.slice(R*Y,(R+1)*Y):oe;n.useEffect(()=>{z(0)},[W,B,H]);let le=n.useCallback(e=>{B===e?U(e=>e===`asc`?`desc`:`asc`):(V(e),U(`asc`))},[B]),[X,ue]=n.useState(null),de=n.useCallback(e=>{ue(e)},[]),fe=n.useCallback(()=>{X&&y?.(X),ue(null)},[X,y]),Z=(0,c.usePermissions)(),Q=n.useMemo(()=>{let e=h||l||``,t=t=>!Z?.isLoaded||!e?t:t.filter(t=>{let n=t?.accessorKey||t?.field||t?.name;return n?Z.checkField(e,String(n),`read`):!0}),r=e=>k?e.filter(e=>(e?.accessorKey||e?.field||e?.name)!==k):e,i=e=>e==null||typeof e==`string`&&e.trim()===``||Array.isArray(e)&&e.length===0,a=e=>P.length?e.filter(e=>{let t=e?.accessorKey||e?.field||e?.name;return t?P.some(e=>!i(e?.[t])):!0}):e;if(f&&f.length>0)return a(t(r(f)));if(!G?.fields)return[];let s=e,c=new Set([`image`,`file`,`attachment`,`rich_text`,`html`,`json`]),u=[`name`,`full_name`,`fullname`,`title`,`subject`,`label`,`code`,`number`],d=Object.entries(G.fields).filter(([e,t])=>!(e.startsWith(`_`)||e===`id`||e===k||t?.hidden||t?.type&&c.has(t.type)||Z?.isLoaded&&s&&!Z.checkField(s,e,`read`)));return d.sort(([e,t],[n,r])=>{let i=u.indexOf(e),a=u.indexOf(n),o=i>=0?i:100,s=a>=0?a:100;if(o!==s)return o-s;let c=t?.type===`select`||e.includes(`status`);return c===(r?.type===`select`||n.includes(`status`))?0:c?-1:1}),a(d.map(([e,t])=>{let r={accessorKey:e,header:ie(s,e,t.label||e)};if(t.type){let i=(0,o.getCellRenderer)((0,o.resolveCellRendererType)({type:t.type,format:t.format})||t.type);if(i){let a=t.type===`lookup`||t.type===`master_detail`?ne[e]:void 0,o=a&&Object.keys(a).length>0?Object.entries(a).map(([e,t])=>({value:e,label:t})):void 0,s={name:e,label:t.label||e,type:t.type,...(o||t.options)&&{options:o||t.options},...t.currency&&{currency:t.currency},...t.precision!==void 0&&{precision:t.precision},...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}};r.cell=e=>e==null?n.createElement(`span`,{className:`text-muted-foreground/50 text-xs italic`},`—`):n.createElement(i,{value:e,field:s})}}return r})).slice(0,Math.max(1,x))},[f,G,h,l,ie,k,P,x,ne,Z]),pe=!!v||!!y,me=(0,r.useIsMobile)(),he=n.useMemo(()=>{if(d)return d;if(me&&(t===`grid`||t===`table`)){let e=Q[0]?.accessorKey||Q[0]?.field||Q[0]?.name,t=Q.slice(1,4).map(e=>e.accessorKey||e.field||e.name).filter(Boolean);return{type:`object-gallery`,data:ce,objectName:l,gallery:{titleField:e||`name`,visibleFields:t,cardSize:`medium`},onRowClick:b}}switch(t){case`grid`:case`table`:return{type:`data-table`,data:ce,columns:Q,pagination:!1,pageSize:Y||10,searchable:!1,exportable:!1,rowActions:pe,onRowEdit:v,onRowDelete:y?de:void 0,onRowClick:b};case`list`:return{type:`data-list`,data:ce};default:return{type:`div`,children:`No view configured`}}},[t,ce,Q,d,Y,pe,v,y,de,b,me,l]),ge=E?`cursor-pointer select-none`:void 0,_e=E?()=>te(e=>!e):void 0,ve=O(j),$=!I&&P.length===0,ye=T;return(0,s.jsxs)(r.Card,{className:(0,r.cn)(`shadow-none border-border/60 bg-transparent`,$&&`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`,ge),onClick:_e,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:[E&&(q?(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)(ve,{className:`h-4 w-4 text-muted-foreground shrink-0`,"aria-hidden":!0}),(0,s.jsx)(`span`,{className:(0,r.cn)(`truncate`,$&&`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`,P.length===0&&`bg-muted text-muted-foreground`),"aria-label":`${P.length} records`,children:P.length}),$&&(0,s.jsx)(`span`,{className:`text-xs text-muted-foreground/70 italic ml-1 truncate`,children:J(`detail.noRelatedRecords`)})]}),(0,s.jsx)(`div`,{className:`flex items-center gap-1 shrink-0`,children:g&&(0,s.jsxs)(r.Button,{variant:$?`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`}),J(`detail.new`)]})})]})}),!q&&!$&&(0,s.jsxs)(r.CardContent,{className:(0,r.cn)(`pt-0 pb-4 px-4`),children:[ye&&(0,s.jsx)(`div`,{className:`mb-3`,children:(0,s.jsx)(r.Input,{placeholder:J(`detail.filterPlaceholder`),value:W,onChange:e=>ee(e.target.value),className:`h-8 text-sm`})}),C&&Q&&Q.length>0&&P.length>0&&(0,s.jsx)(`div`,{className:`flex flex-wrap gap-1 mb-3`,children:Q.map(e=>{let t=e.accessorKey||e.field||e.name;if(!t)return null;let n=e.header||e.label||t,a=B===t;return(0,s.jsxs)(r.Button,{variant:a?`secondary`:`ghost`,size:`sm`,className:`gap-1 h-7 text-xs`,onClick:()=>le(t),children:[(0,s.jsx)(i.ArrowUpDown,{className:`h-3 w-3`}),n,a&&(H===`asc`?` ↑`:` ↓`)]},t)})}),I?(0,s.jsx)(`div`,{className:`flex items-center justify-center py-6 text-muted-foreground text-sm`,children:J(`detail.loading`)}):(0,s.jsx)(a.SchemaRenderer,{schema:he}),Y>0&&oe.length>Y&&(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:R===0,onClick:()=>z(e=>Math.max(0,e-1)),children:[(0,s.jsx)(i.ChevronLeft,{className:`h-3 w-3`}),J(`detail.previousPage`)]}),(0,s.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:J(`detail.pageOf`,{current:R+1,total:se})}),(0,s.jsxs)(r.Button,{variant:`outline`,size:`sm`,className:`h-7 text-xs gap-1`,disabled:R>=se-1,onClick:()=>z(e=>Math.min(se-1,e+1)),children:[J(`detail.nextPage`),(0,s.jsx)(i.ChevronRight,{className:`h-3 w-3`})]})]}),_&&!$&&Y>0&&oe.length>Y&&(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:[J(`detail.viewAll`),(0,s.jsx)(i.ExternalLink,{className:`h-3 w-3`})]})})]}),(0,s.jsx)(r.AlertDialog,{open:X!==null,onOpenChange:e=>{e||ue(null)},children:(0,s.jsxs)(r.AlertDialogContent,{children:[(0,s.jsxs)(r.AlertDialogHeader,{children:[(0,s.jsx)(r.AlertDialogTitle,{children:J(`detail.deleteRowTitle`,{defaultValue:`Delete record`})}),(0,s.jsx)(r.AlertDialogDescription,{children:J(`detail.deleteRowConfirmation`)})]}),(0,s.jsxs)(r.AlertDialogFooter,{children:[(0,s.jsx)(r.AlertDialogCancel,{children:J(`detail.cancel`,{defaultValue:`Cancel`})}),(0,s.jsx)(r.AlertDialogAction,{onClick:fe,className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:J(`detail.delete`,{defaultValue:`Delete`})})]})]})})]})},A=({group:e,data:t,className:a,objectSchema:o,objectName:c,isEditing:l=!1,onFieldChange:u})=>{let d=e.collapsible??!0,[f,p]=n.useState(e.defaultCollapsed??!1),m=(0,s.jsx)(`div`,{className:`space-y-3 sm:space-y-4`,children:e.sections.map((e,n)=>(0,s.jsx)(E,{section:e,data:t,objectSchema:o,objectName:c,isEditing:l,onFieldChange:u},n))});return d?(0,s.jsxs)(r.Collapsible,{open:!f,onOpenChange:e=>p(!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:[f?(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&&!f&&(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:m})})]}):(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}),m]})},j=({fields:e,data:t,className:n,objectName:i,objectSchema:c})=>{let{fieldLabel:l}=(0,a.useSafeFieldLabel)();if(!e.length||!t)return null;let u=e.filter(e=>{let n=t?.[e.name];return n!=null&&n!==``});return u.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-x-8 gap-y-3`),children:u.map(e=>{let n=t[e.name],a=c?.fields?.[e.name],u=e.type||a?.type,d={name:e.name,label:e.label,type:u||`text`,...a?.options&&{options:a.options},...a?.currency&&{currency:a.currency},...a?.precision!==void 0&&{precision:a.precision},...a?.format&&{format:a.format}},f=(0,o.getCellRenderer)((0,o.resolveCellRendererType)(d)||u||`text`),p=u===`number`||u===`integer`||u===`currency`||u===`percent`||u===`decimal`;return(0,s.jsxs)(`div`,{className:`flex min-w-[8rem] max-w-[16rem] basis-[10rem] flex-col gap-0.5`,children:[(0,s.jsxs)(`span`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:[e.icon&&(0,s.jsx)(`span`,{className:`mr-1`,children:e.icon}),l(i||``,e.name,e.label)]}),(0,s.jsx)(`span`,{className:(0,r.cn)(`block min-w-0 truncate`,p?`text-xl md:text-2xl font-semibold leading-tight tabular-nums tracking-tight`:`text-sm font-semibold`),children:(0,s.jsx)(f,{value:n,field:d})})]},e.name)})})})};function M(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 N=({comments:e,onAddComment:t,onTogglePin:a,searchable:o=!1,className:c})=>{let{t:l}=w(),[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:M(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))})]})]})},P={field_change:i.Edit,create:i.PlusCircle,delete:i.Trash2,comment:i.MessageSquare,status_change:i.ArrowRightLeft},F={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 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}}function L(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 R={all:`All`,field_change:`Field Changes`,create:`Creates`,delete:`Deletes`,comment:`Comments`,status_change:`Status Changes`},z=({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(R).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(P[e]||i.Edit,{className:`h-3 w-3`}),R[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=P[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`,F[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:L(e)})]}),(0,s.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:I(e.timestamp)})]})]},e.id)})})]})]})]})},B={create:`default`,update:`secondary`,delete:`destructive`,restore:`outline`,login:`outline`,logout:`outline`,permission_change:`secondary`,config_change:`secondary`,export:`outline`,import:`outline`};function V(e){if(!e)return``;let t=e instanceof Date?e:new Date(e);return Number.isNaN(t.getTime())?String(e):t.toLocaleString()}var H=[[60,`second`],[60,`minute`],[24,`hour`],[7,`day`],[4.34524,`week`],[12,`month`],[1/0,`year`]];function U(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 H){if(Math.abs(r)<n)try{return new Intl.RelativeTimeFormat(t,{numeric:`auto`}).format(Math.round(r),i)}catch{return V(e)}r/=n}return V(e)}function W(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 ee(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 G({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=B[n]??`outline`,o=typeof e.user_name==`string`&&e.user_name.trim()||`Unknown user`,c=V(e.created_at),l=U(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:W(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:ee(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:ee(e.from)}),` → `,(0,s.jsx)(`span`,{className:`text-foreground`,children:ee(e.to)})]},e.field))}))]})]},e.id??t)})})})}var K={createdAt:`created_at`,createdBy:`created_by`,updatedAt:`updated_at`,updatedBy:`updated_by`};function q(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 te(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 ne(e){try{return new Intl.DateTimeFormat(void 0,{dateStyle:`medium`,timeStyle:`short`}).format(e)}catch{return e.toISOString()}}var re=({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)})},J=({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:te(n,o)})}),(0,s.jsx)(r.TooltipContent,{side:`top`,children:ne(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)(re,{value:t,objectSchema:i,fieldName:a}):null,t&&c?(0,s.jsx)(`span`,{className:`text-muted-foreground/40`,children:`·`}):null,c]})},ie=({data:e,objectSchema:t,objectName:n,className:i})=>{let{t:a}=w();if(!e)return null;let o=q(e[K.createdAt]),c=q(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)(J,{label:a(`detail.createdBy`),user:l,date:o,objectSchema:t,userField:K.createdBy,t:a}),p&&(0,s.jsx)(J,{label:a(`detail.updatedBy`),user:u,date:c,objectSchema:t,userField:K.updatedBy,t:a})]})},ae=5;function oe(e,t,n,r){if(e&&typeof e==`object`){if(t.primaryField){let n=e[t.primaryField];if(n!=null&&n!==``)return String(n)}let r=n?.titleFormat,i=typeof r==`string`?r:r&&typeof r==`object`&&typeof r.source==`string`?r.source:void 0;if(i){let t=`[-\\u2013\\u2014|/·,:]`,n=!1,r=i.replace(/\{([^{}]+)\}/g,(t,r)=>{let i=String(r).trim().split(`.`),a=e;for(let e of i){if(a==null)break;a=a[e]}if(a&&typeof a==`object`){let e=a,t=e.name??e.full_name??e.display_name??e.label??e.title??e.subject??null;(t==null||typeof t==`string`&&!t.trim())&&(t=[e.salutation,e.first_name,e.last_name].filter(e=>typeof e==`string`&&e.trim()).map(e=>e.trim()).join(` `)||(typeof e.email==`string`&&e.email.trim()?e.email.trim():null)),a=t}return a!=null&&a!==``?(n=!0,String(a)):`\0`});if(n){let e=r.replace(RegExp(`\\s*${t}\\s*`,`g`),``).replace(RegExp(`\\s*${t}\\s*`,`g`),``).replace(RegExp(`\0`,`g`),``).replace(/\s+/g,` `).trim();if(e)return e}}}if(t.title)return t.title;if(e&&typeof e==`object`)for(let t of[`name`,`full_name`,`fullName`,`title`,`subject`,`label`,`display_name`,`displayName`]){let n=e[t];if(typeof n==`string`&&n.trim())return n.trim();if(n!=null&&n!==``)return String(n)}return r}var Y=({schema:e,dataSource:o,className:l,onEdit:u,onDelete:d,onBack:f,inlineEdit:p=!1,onFieldSave:m,discussionSlot:h,rightRail:g,objectLabel:_,onDataLoaded:v,isFavorite:y,onToggleFavorite:b})=>{let[x,S]=n.useState(e.data),[C,T]=n.useState(!e.data&&!!(e.api&&e.resourceId||o&&e.objectName&&e.resourceId)),[O,M]=n.useState(!1),P=y??O,[F,I]=n.useState(!1),[L,R]=n.useState({}),[B,V]=n.useState(!1),[H,U]=n.useState(null),[W,ee]=n.useState(null),[K,q]=n.useState(!1),[te,ne]=n.useState(0),[re,J]=n.useState(!1),{t:Y}=w(),{fieldOptionLabel:se}=(0,a.useSafeFieldLabel)(),ce=(0,r.useIsMobile)(),le=(0,c.usePermissions)(),X=n.useMemo(()=>{if(!le?.isLoaded||!e.objectName)return e;let t=t=>le.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,le]);n.useEffect(()=>{x&&v&&v(x)},[x,v]);let ue=n.useMemo(()=>{if(X.summaryFields&&X.summaryFields.length>0)return[];let e=[...X.sections?.flatMap(e=>e.fields)||[],...X.fields||[]],t={};for(let n of e)t[n.name]||(t[n.name]=n);if(W?.fields)for(let[e,n]of Object.entries(W.fields))t[e]={...t[e]||{},...n,name:e};let n=e=>x?.[e]!==void 0&&x?.[e]!==null&&x?.[e]!==``,r=[],i=[`status`,`stage`,`state`,`phase`].find(e=>t[e]&&n(e))||Object.keys(t).find(e=>t[e]?.type===`select`&&n(e));i&&r.push(i);let a=Object.keys(t).find(e=>(t[e]?.type===`currency`||/amount|revenue|value|total|price/i.test(e))&&n(e));a&&!r.includes(a)&&r.push(a);let o=Object.keys(t).find(e=>(t[e]?.type===`date`||t[e]?.type===`datetime`)&&/close|due|start|end|expected/i.test(e)&&n(e));return o&&!r.includes(o)&&r.push(o),r},[X.summaryFields,X.sections,X.fields,W,x]),de=X.summaryFields&&X.summaryFields.length>0?X.summaryFields:ue,fe=n.useCallback(()=>{X.resourceId&&navigator.clipboard.writeText(String(X.resourceId)).then(()=>{q(!0),setTimeout(()=>q(!1),1500)})},[X.resourceId]);n.useEffect(()=>{let e=!0;if(X.data)return S(X.data),T(!1),o?.getObjectSchema&&X.objectName&&o.getObjectSchema(X.objectName).then(t=>{e&&ee(t)}).catch(()=>{}),()=>{e=!1};if(o&&X.objectName&&X.resourceId){T(!0),ee(null),S(null);let n=X.objectName,r=X.resourceId,i=`${n}-`,a=[...X.sections?.flatMap(e=>e.fields)||[],...X.fields||[]];(o.getObjectSchema?o.getObjectSchema(n).catch(()=>null):Promise.resolve(null)).then(s=>{if(!e)return;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&&(S(t),T(!1))}).catch(()=>{e&&(S(null),T(!1))})};return u.catch(()=>null).then(t=>{if(e){if(t){S(t),T(!1);return}return d()}})}).catch(t=>{e&&(console.error(`Failed to fetch detail data:`,t),T(!1))})}else X.api&&X.resourceId&&(T(!0),fetch(`${X.api}/${X.resourceId}`).then(e=>e.json()).then(t=>{e&&S(t?.data||t)}).catch(e=>{console.error(`Failed to fetch detail data:`,e)}).finally(()=>{e&&T(!1)}));return()=>{e=!1}},[X.api,X.resourceId,X.objectName,o,X.sections,X.fields,te]);let Z=n.useCallback(()=>{if(f)f();else if(X.onNavigate){let e=X.backUrl||(X.objectName?`/${X.objectName}`:`/`);X.onNavigate(e,{replace:!0})}else X.backUrl?window.location.href=X.backUrl:window.history.back()},[f,X]),Q=n.useCallback(()=>{u?u():X.onNavigate&&X.editUrl?X.onNavigate(X.editUrl):X.onNavigate&&X.objectName&&X.resourceId?X.onNavigate(`/${X.objectName}/${X.resourceId}/edit`):X.editUrl&&(window.location.href=X.editUrl)},[u,X]),pe=n.useCallback(async()=>{if(!o?.cancelPendingApproval||!X.objectName||!X.resourceId){U(Y(`detail.cancelApprovalUnavailable`));return}J(!0),U(null);try{if(await o.cancelPendingApproval(String(X.objectName),String(X.resourceId)),o.findOne)try{let e=await o.findOne(String(X.objectName),String(X.resourceId));e&&S(e)}catch{}ne(e=>e+1);try{window.dispatchEvent(new CustomEvent(`objectui:record-changed`,{detail:{objectName:String(X.objectName),recordId:String(X.resourceId),reason:`approval-recalled`}}))}catch{}}catch(e){let t=(e?.message||e?.error||String(e??`Cancel failed`)).replace(/^\[[^\]]+\]\s*/,``).replace(/^[A-Z][A-Z0-9_]+:\s*/,``);U(`${Y(`detail.cancelApprovalFailed`)}: ${t}`)}finally{J(!1)}},[o,X.objectName,X.resourceId,Y]),me=n.useCallback(()=>{let e=X.deleteConfirmation||Y(`detail.deleteConfirmation`);window.confirm(e)&&(d?.(),X.onNavigate&&X.objectName&&X.onNavigate(`/${X.objectName}`,{replace:!0}))},[d,X]),he=n.useCallback(()=>{navigator.share&&X.objectName&&X.resourceId?navigator.share({title:X.title||Y(`detail.details`),text:`${X.objectName} #${X.resourceId}`,url:window.location.href}).catch(e=>console.log(`Share failed:`,e)):navigator.clipboard.writeText(window.location.href).then(()=>{console.log(`Link copied to clipboard`)})},[X]),ge=n.useCallback(()=>{let e=!P;b&&b(e),y===void 0&&M(e)},[P,y,b]),_e=n.useCallback(async()=>{if(F){let e=Object.entries(L);if(e.length>0){let t=x,n={...x,...L};S(n),U(null),V(!0);try{if(m)for(let[t,r]of e)await m(t,r,n);R({}),I(!1)}catch(e){S(t),U((e?.message||e?.error||String(e??`Save failed`)).replace(/^\[[^\]]+\]\s*/,``).replace(/^[A-Z][A-Z0-9_]+:\s*/,``))}finally{V(!1)}return}R({})}I(!F),U(null)},[F,L,x,m]),ve=n.useCallback(()=>{R({}),I(!1),U(null)},[]),$=n.useCallback((e,t)=>{R(n=>({...n,[e]:t}))},[]);n.useEffect(()=>{if(!X.recordNavigation)return;let e=X.recordNavigation,t=t=>{let n=t.target?.tagName;n===`INPUT`||n===`TEXTAREA`||t.target?.isContentEditable||(t.key===`ArrowLeft`&&e.currentIndex>0?(t.preventDefault(),e.onNavigate(e.recordIds[e.currentIndex-1])):t.key===`ArrowRight`&&e.currentIndex<e.recordIds.length-1&&(t.preventDefault(),e.onNavigate(e.recordIds[e.currentIndex+1])))};return document.addEventListener(`keydown`,t),()=>document.removeEventListener(`keydown`,t)},[X.recordNavigation]),n.useEffect(()=>{if(!p||X.showHeader!==!1)return;let e=`objectui:record:inline-edit-toggle`,t=e=>{let t=e.detail;t?.recordId&&X.recordId&&t.recordId!==X.recordId||t?.objectName&&X.objectName&&t.objectName!==X.objectName||_e()};return window.addEventListener(e,t),()=>window.removeEventListener(e,t)},[p,X.showHeader,X.recordId,X.objectName,_e]);let ye=n.useMemo(()=>X.related??[],[X.related]),be=n.useMemo(()=>{let e=[];return e.push({name:`sys_share`,label:Y(`detail.share`),icon:`share-2`,type:`script`,onClick:he}),X.showEdit&&e.push({name:`sys_edit_mobile`,label:Y(`detail.edit`),icon:`edit`,type:`script`,className:`sm:hidden`,onClick:Q}),p&&e.push({name:`sys_toggle_inline_edit_mobile`,label:Y(F?`detail.save`:`detail.editInline`),icon:`edit`,type:`script`,className:`sm:hidden`,onClick:_e}),X.showDelete&&e.push({name:`sys_delete`,label:Y(`detail.delete`),icon:`trash-2`,type:`script`,variant:`destructive`,tags:[`separator-before`],onClick:me}),e},[Y,X.showEdit,X.showDelete,p,F,he,Q,_e,me]),xe=n.useMemo(()=>{let e=X.actions??[];if(be.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,...be]}}return e});return t||n.push({type:`action:bar`,location:`record_header`,systemActions:be}),n},[X.actions,be]);return C||X.loading?(0,s.jsxs)(`div`,{className:(0,r.cn)(`space-y-4`,l),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`})]}):!x&&!X.data?(0,s.jsxs)(`div`,{className:(0,r.cn)(`flex flex-col items-center justify-center py-16 text-center`,l),children:[(0,s.jsx)(`p`,{className:`text-lg font-semibold`,children:Y(`detail.recordNotFound`)}),(0,s.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:Y(`detail.recordNotFoundDescription`)}),(X.showBack??!0)&&(0,s.jsxs)(r.Button,{variant:`outline`,size:`sm`,onClick:Z,className:`mt-4 gap-2`,children:[(0,s.jsx)(i.ArrowLeft,{className:`h-4 w-4`}),Y(`detail.goBack`)]})]}):(0,s.jsx)(r.TooltipProvider,{children:(0,s.jsxs)(`div`,{className:(0,r.cn)(`space-y-6`,l),children:[X.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:[(X.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:Z,className:`shrink-0 mt-1`,children:(0,s.jsx)(i.ArrowLeft,{className:`h-4 w-4`})})}),(0,s.jsx)(r.TooltipContent,{children:Y(`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:oe(x,X,W,Y(`detail.details`))}),de.map(e=>{let t=x?.[e];if(t==null||t===``)return null;let n=(X.sections||[]).flatMap(e=>e.fields).concat(X.fields||[]).find(t=>t.name===e),i=W?.fields?.[e],a=n?.type||i?.type,o=String(t),c=null;try{if(a===`currency`){let e=Number(t);Number.isNaN(e)||(o=new Intl.NumberFormat(void 0,{style:`currency`,currency:n?.currency||i?.currency||`USD`,maximumFractionDigits:0}).format(e))}else if(a===`date`||a===`datetime`){let e=new Date(t);Number.isNaN(e.getTime())||(o=a===`datetime`?e.toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`}):e.toLocaleDateString(void 0,{dateStyle:`medium`}))}else if(a===`percent`){let e=Number(t);if(!Number.isNaN(e)){o=`${e}%`;let t=e<=1?e*100:e;c=Math.max(0,Math.min(100,t))}}else if(a===`select`||a===`status`||a===`multiselect`){let r=n?.options||i?.options,a=String(t);if(Array.isArray(r)){let e=r.find(e=>String(e?.value??e)===String(t));e?.label&&(a=e.label)}else if(r&&typeof r==`object`){let e=r[String(t)];e?.label&&(a=e.label)}o=X.objectName?se(X.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:ge,"aria-label":Y(P?`detail.removeFromFavorites`:`detail.addToFavorites`),children:P?(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:Y(P?`detail.removeFromFavorites`:`detail.addToFavorites`)})]})]}),X.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:_||X.objectName}),X.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:fe,"aria-label":Y(`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?Y(`detail.copied`,{defaultValue:`Copied`}):Y(`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:[X.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:X.recordNavigation.currentIndex<=0,onClick:()=>{let e=X.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:Y(`detail.previousRecord`)})]}),(0,s.jsx)(`span`,{className:`text-xs text-muted-foreground whitespace-nowrap px-1`,children:Y(`detail.recordOf`,{current:X.recordNavigation.currentIndex+1,total:X.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:X.recordNavigation.currentIndex>=X.recordNavigation.recordIds.length-1,onClick:()=>{let e=X.recordNavigation;e.currentIndex<e.recordIds.length-1&&e.onNavigate(e.recordIds[e.currentIndex+1])},children:(0,s.jsx)(i.ChevronRight,{className:`h-4 w-4`})})}),(0,s.jsx)(r.TooltipContent,{children:Y(`detail.nextRecord`)})]})]}),p&&(0,s.jsxs)(s.Fragment,{children:[F&&(0,s.jsxs)(r.Tooltip,{children:[(0,s.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,s.jsxs)(r.Button,{variant:`ghost`,size:`sm`,onClick:ve,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:Y(`detail.cancel`)})]})}),(0,s.jsx)(r.TooltipContent,{children:Y(`detail.cancelEdit`)})]}),(0,s.jsxs)(r.Tooltip,{children:[(0,s.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,s.jsx)(r.Button,{variant:F?`default`:`outline`,size:`sm`,onClick:_e,className:`gap-2 hidden sm:inline-flex`,children:F?(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:Y(`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:Y(`detail.editInline`)})]})})}),(0,s.jsx)(r.TooltipContent,{children:Y(F?`detail.saveChanges`:`detail.editFieldsInline`)})]})]}),X.showEdit&&(0,s.jsxs)(r.Tooltip,{children:[(0,s.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,s.jsxs)(r.Button,{variant:`default`,onClick:Q,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:Y(`detail.edit`)})]})}),(0,s.jsx)(r.TooltipContent,{children:Y(`detail.editRecord`)})]}),xe.map((e,t)=>(0,s.jsx)(a.SchemaRenderer,{schema:e,data:x},`header-action-${t}`))]})]}),X.header&&(0,s.jsx)(`div`,{children:(0,s.jsx)(a.SchemaRenderer,{schema:X.header,data:x})}),X.highlightFields&&X.highlightFields.length>0&&(0,s.jsx)(j,{fields:X.highlightFields,data:x,objectName:X.objectName,objectSchema:W}),p&&X.showHeader===!1&&(()=>{let e=x?.approval_status,t=e===`pending`||e===`in_approval`;return!F&&!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&&!F&&(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:Y(`detail.lockedTooltip`),children:[(0,s.jsx)(i.Lock,{className:`h-3 w-3`}),(0,s.jsx)(`span`,{children:Y(`detail.lockedByApproval`)})]}),o?.cancelPendingApproval&&(0,s.jsxs)(r.Button,{variant:`outline`,size:`sm`,onClick:pe,disabled:re,className:`gap-2 border-amber-300 text-amber-800 hover:bg-amber-50`,title:Y(`detail.cancelApprovalTooltip`),children:[(0,s.jsx)(i.X,{className:`h-4 w-4`}),(0,s.jsx)(`span`,{children:Y(re?`detail.cancelApprovalInFlight`:`detail.cancelApproval`)})]})]}),F&&(0,s.jsxs)(r.Button,{variant:`ghost`,size:`sm`,onClick:ve,className:`gap-2`,disabled:B,children:[(0,s.jsx)(i.X,{className:`h-4 w-4`}),(0,s.jsx)(`span`,{children:Y(`detail.cancel`)})]}),(0,s.jsxs)(r.Button,{variant:F?`default`:`outline`,size:`sm`,onClick:_e,className:`gap-2`,disabled:B||t&&!F,title:t&&!F?Y(`detail.lockedTooltip`):void 0,children:[F?(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:Y(B?`detail.saving`:F?`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})]})})(),X.autoTabs&&!X.tabs?.length?(()=>{let e=ye.length>0,t=!!X.activities&&X.activities.length>0,n=!!h,i=!!X.history,a=(0,s.jsxs)(`div`,{className:`space-y-3 sm:space-y-4`,children:[X.sectionGroups&&X.sectionGroups.length>0&&X.sectionGroups.map((e,t)=>(0,s.jsx)(A,{group:e,data:{...x,...L},objectSchema:W,objectName:X.objectName,isEditing:F,onFieldChange:$},t)),X.sections&&X.sections.length>0&&X.sections.map((e,t)=>(0,s.jsx)(E,{section:e,data:{...x,...L},objectSchema:W,objectName:X.objectName,isEditing:F,onFieldChange:$},t)),X.fields&&X.fields.length>0&&!X.sections?.length&&(0,s.jsx)(E,{section:{fields:X.fields,columns:X.columns},data:{...x,...L},objectSchema:W,objectName:X.objectName,isEditing:F,onFieldChange:$}),X.comments&&(0,s.jsx)(N,{comments:X.comments,onAddComment:X.onAddComment})]});return!e&&!t&&!n&&!i?(0,s.jsx)(`div`,{className:`mt-2`,children:a}):(0,s.jsxs)(r.Tabs,{defaultValue:`details`,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:Y(`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:[Y(`detail.related`),(0,s.jsx)(r.Badge,{variant:`secondary`,className:`text-xs bg-primary/10 text-primary border-transparent`,children:ye.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:[Y(`detail.activity`),(0,s.jsx)(r.Badge,{variant:`secondary`,className:`text-xs bg-primary/10 text-primary border-transparent`,children:X.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:Y(`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:[Y(`detail.history`,{defaultValue:`History`}),!X.history.loading&&X.history.entries.length>0&&(0,s.jsx)(r.Badge,{variant:`secondary`,className:`text-xs bg-primary/10 text-primary border-transparent`,children:X.history.entries.length})]})})]}),(0,s.jsx)(r.TabsContent,{value:`details`,className:`mt-4`,children:a}),e&&(0,s.jsx)(r.TabsContent,{value:`related`,className:`mt-4`,children:(0,s.jsx)(`div`,{className:`space-y-3`,children:ye.map((e,t)=>(0,s.jsx)(k,{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:ce&&t>0,pageSize:ae},t))})}),t&&(0,s.jsx)(r.TabsContent,{value:`activity`,className:`mt-4`,children:(0,s.jsx)(z,{activities:X.activities})}),n&&(0,s.jsx)(r.TabsContent,{value:`discussion`,className:`mt-4`,children:h}),i&&(0,s.jsx)(r.TabsContent,{value:`history`,className:`mt-4`,children:(0,s.jsx)(G,{entries:X.history.entries,loading:X.history.loading,emptyText:X.history.emptyText??Y(`detail.historyEmpty`,{defaultValue:`No history yet`})})})]})})():(0,s.jsxs)(s.Fragment,{children:[X.sectionGroups&&X.sectionGroups.length>0&&(0,s.jsx)(`div`,{className:`space-y-3 sm:space-y-4`,children:X.sectionGroups.map((e,t)=>(0,s.jsx)(A,{group:e,data:{...x,...L},objectSchema:W,objectName:X.objectName,isEditing:F,onFieldChange:$},t))}),X.sections&&X.sections.length>0&&(0,s.jsx)(`div`,{className:`space-y-3 sm:space-y-4`,children:X.sections.map((e,t)=>(0,s.jsx)(E,{section:e,data:{...x,...L},objectSchema:W,objectName:X.objectName,isEditing:F,onFieldChange:$},t))}),X.fields&&X.fields.length>0&&!X.sections?.length&&(0,s.jsx)(E,{section:{fields:X.fields,columns:X.columns},data:{...x,...L},objectSchema:W,objectName:X.objectName,isEditing:F,onFieldChange:$}),X.tabs&&X.tabs.length>0&&(0,s.jsx)(D,{tabs:X.tabs,data:x}),ye.length>0&&(0,s.jsxs)(`div`,{className:`space-y-3`,children:[(0,s.jsx)(`h2`,{className:`text-lg font-semibold`,children:Y(`detail.related`)}),ye.map((e,t)=>(0,s.jsx)(k,{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:ce&&t>0,pageSize:ae},t))]}),X.comments&&(0,s.jsx)(N,{comments:X.comments,onAddComment:X.onAddComment}),X.activities&&X.activities.length>0&&(0,s.jsx)(z,{activities:X.activities})]}),(0,s.jsx)(ie,{data:{...x,...L},objectSchema:W,objectName:X.objectName}),X.footer&&(0,s.jsx)(`div`,{children:(0,s.jsx)(a.SchemaRenderer,{schema:X.footer,data:x})})]})})},se=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)}},ce=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()}},le=({open:e,conflict:t,onReload:n,onOverwrite:a,onCancel:o,busy:c=!1})=>{let{t:l}=w(),u=t?.label||t?.field||``,d=t?se(t.pendingValue):``,f=t?se(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=ce(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 X(e){if(!e||typeof e!=`object`)return!1;let t=e;return t.code===`CONCURRENT_UPDATE`||t.name===`ConcurrentUpdateError`}var ue=e=>typeof e==`string`?e:e&&typeof e==`object`&&(e.field||e.name)||null,de=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}},fe=({schema:e={},className:t,...r})=>{let i=(0,a.useRecordContext)(),{designer:o}=de(r);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 l=e.layout===`inline`||e.layout===`compact`?`horizontal`:`vertical`,u=i.objectName||``,d=(0,c.usePermissions)(),{readableFields:f}=(0,c.useFieldPermissions)(u),{sectionLabel:p}=(0,a.useSafeFieldLabel)(),m=Array.isArray(e.requiredPermissions)?e.requiredPermissions:[];if(m.length>0&&u&&!m.every(e=>d.can(u,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 h=e.enforceFieldSecurity===!0,g=Array.isArray(e.redactFields)?e.redactFields:[],_=e=>{if(!e||!h&&g.length===0)return e;let t=e.map(ue).filter(e=>!!e),n=new Set((h&&u?f(t):t).filter(e=>!g.includes(e)));return e.filter(e=>{let t=ue(e);return t?n.has(t):!0})},v=e=>typeof e==`string`?{name:e}:e&&typeof e==`object`&&!e.name&&e.field?{...e,name:e.field}:e,y=e=>Array.isArray(e)?e.map(v):e,b=(0,a.useHighlightFieldNames)(),x=new Set((Array.isArray(e.hideFields)?e.hideFields:[]).map(e=>typeof e==`string`?e:ue(e)).filter(e=>!!e));for(let e of b)x.add(e);let S=i.objectSchema,C=i.data??{},w=[S?.primaryField,`name`,`full_name`,`title`,`subject`,`display_name`,`label`].filter(e=>typeof e==`string`&&e.length>0);for(let e of w)if(C[e]!==void 0&&C[e]!==null&&C[e]!==``){x.add(e);break}let T=e=>!e||x.size===0?e:e.filter(e=>{let t=ue(e);return t?!x.has(t):!0}),E=T(y(_(e.fields))),D=Array.isArray(e.sections)?e.sections.map(e=>{let t=e.title??e.label,n=e.name&&u?p(u,e.name,t??e.name):t;return{...e,title:n,showBorder:e.showBorder??!!n,hideEmpty:e.hideEmpty??!0,fields:T(y(_(e.fields)))}}):e.sections,O=e.inlineEdit??!0,[k,A]=n.default.useState(null),[j,M]=n.default.useState(!1),N=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]),P=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(X(n)){let r=n.currentRecord??null;throw A({field:e,label:N(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,N]),F=n.default.useCallback(()=>{A(null),M(!1)},[]),I=n.default.useCallback(async()=>{M(!0);try{typeof i.refresh==`function`&&await i.refresh()}finally{F()}},[i.refresh,F]),L=n.default.useCallback(async()=>{if(!k){F();return}let e=i.dataSource,t=i.recordId,n=i.objectName;if(!e||!t||!n){F();return}M(!0);try{let r=k.currentVersion?{ifMatch:k.currentVersion}:void 0;typeof e.update==`function`?await e.update(n,t,{[k.field]:k.pendingValue},r):typeof e.updateOne==`function`?await e.updateOne(n,t,{[k.field]:k.pendingValue},r):typeof e.patch==`function`&&await e.patch(n,t,{[k.field]:k.pendingValue},r),typeof i.refresh==`function`&&await i.refresh()}catch(e){console.error(`[record:details] Overwrite-on-conflict failed`,e)}finally{F()}},[k,i.dataSource,i.recordId,i.objectName,i.refresh,F]),R={type:`detail-view`,objectName:i.objectName,resourceId:i.recordId,data:i.data,layout:l,columns:e.columns,sections:D,fields:E,showBack:!1,showHeader:e.showHeader??!1,inlineEdit:O};return(0,s.jsxs)(`div`,{className:t,...o,children:[(0,s.jsx)(Y,{schema:R,dataSource:i.dataSource,inlineEdit:O,onFieldSave:P}),(0,s.jsx)(le,{open:!!k,conflict:k,busy:j,onCancel:F,onReload:I,onOverwrite:L})]})},Z=e=>typeof e==`string`?e:e&&typeof e==`object`&&(e.field||e.name||e.key)||null,Q=e=>{let{"data-obj-id":t,"data-obj-type":n,style:r,...i}=e||{};return{designer:{"data-obj-id":t,"data-obj-type":n,style:r},rest:i}},pe=({schema:e={},className:t,...n})=>{let r=(0,a.useRecordContext)(),{designer:i}=Q(n),l=(0,a.useSafeFieldLabel)(),u=e.objectName,d=u&&l.objectLabel?l.objectLabel({name:u,label:(0,o.humanizeLabel)(u)}):u?(0,o.humanizeLabel)(u):``,f=e.title||d||`Related`;if(!u)return(0,s.jsx)(`div`,{className:t,...i,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 p=(0,c.usePermissions)(),{readableFields:m}=(0,c.useFieldPermissions)(u),h=Array.isArray(e.requiredPermissions)?e.requiredPermissions:[];if(h.length>0&&!h.every(e=>p.can(u,e)))return(0,s.jsx)(`div`,{className:t,...i,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 g=e.enforceFieldSecurity===!0,_=Array.isArray(e.redactFields)?e.redactFields:[],v=Array.isArray(e.columns)?e.columns:[],y=v;if(g||_.length>0){let e=v.map(Z).filter(e=>!!e),t=new Set((g?m(e):e).filter(e=>!_.includes(e)));y=v.filter(e=>{let n=Z(e);return n?t.has(n):!0})}return(0,s.jsx)(`div`,{className:t,...i,children:(0,s.jsx)(k,{title:f,type:`table`,api:u,objectName:u,referenceField:e.relationshipField,parentId:r?.recordId,columns:y,pageSize:e.limit,dataSource:r?.dataSource})})},me=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,...r})=>{let i=(0,a.useRecordContext)(),{designer:o}=me(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)(j,{fields:_,data:i?.data,objectName:i?.objectName,objectSchema:i?.objectSchema})})},ge=({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})]})},_e=[`👍`,`❤️`,`🎉`,`😂`,`😮`,`😢`],ve=({reactions:e,onToggleReaction:t,emojiOptions:a=_e,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){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 ye=({parentItem:e,replies:t,onAddReply:a,showReplyInput:o=!0,className:c})=>{let{t:l}=w(),[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)})]}),(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`})})]})]})},be=({subscription:e,onToggle:t,className:a})=>{let{t:o}=w(),[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 xe(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 Se=({value:e,onChange:t,onSubmit:a,mentionSuggestions:o=[],placeholder:c,className:l,disabled:u=!1,extraSlot:d,canSubmitEmpty:f=!1})=>{let{t:p}=w(),[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]),T=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]),E=n.useCallback(()=>T(`**`,`**`),[T]),D=n.useCallback(()=>T(`*`,`*`),[T]),O=n.useCallback(()=>T(`
|
|
2
|
+
- `,``),[T]),k=n.useCallback(()=>T("`","`"),[T]),A=n.useCallback(()=>{T(`@`,``),_(!0),y(``),x(0)},[T]),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:E,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:xe(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 Ce(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function we(e){return e.startsWith(`image/`)}function Te(e){return we(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 Ee=({attachments:e,onUpload:t,onRemove:a,className:o,readOnly:c=!1})=>{let{t:l}=w(),[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=we(e.type),n=Te(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:Ce(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)})})]})]})},De={comment:i.MessageSquare,field_change:i.Edit,task:i.CheckSquare,event:i.Calendar,system:i.Zap,email:i.Mail,call:i.Phone},Oe={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 ke(e){return[{value:`all`,label:e(`detail.allActivity`)},{value:`comments_only`,label:e(`detail.commentsOnly`)},{value:`changes_only`,label:e(`detail.fieldChangesFilter`)},{value:`tasks_only`,label:e(`detail.tasksOnly`)}]}function Ae(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 je(e,t){switch(t){case`comments_only`:return e.filter(e=>e.type===`comment`);case`changes_only`:return e.filter(e=>e.type===`field_change`);case`tasks_only`:return e.filter(e=>e.type===`task`);default:return e}}var Me=({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}=w(),[C,T]=n.useState(`all`),[E,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(()=>je(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]),ee=n.useCallback(e=>{o?o(e):T(e)},[o]),G=n.useCallback(async()=>{let e=E.trim();if(d&&!(!e&&M.length===0)){k(!0);try{await d(e,M.length>0?M:void 0),D(``),N([])}finally{k(!1)}}},[E,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]),q=n.useCallback(e=>{N(t=>t.filter(t=>t.id!==e))},[]),te=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)(be,{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=>ee(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:ke(S).map(e=>(0,s.jsx)(r.SelectItem,{value:e.value,children:e.label},e.value))})]})}),R&&(0,s.jsx)(Se,{value:E,onChange:D,onSubmit:G,mentionSuggestions:_,placeholder:S(`detail.leaveCommentPlaceholder`),disabled:O,canSubmitEmpty:M.length>0,extraSlot:v?(0,s.jsx)(Ee,{attachments:M,onUpload:K,onRemove:q,readOnly:O||P}):M.length>0?(0,s.jsx)(Ee,{attachments:M,onRemove:q,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=De[e.type]||i.Zap,n=Oe[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:Ae(e.createdAt)}),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.type===`field_change`&&e.fieldChanges&&(0,s.jsx)(`div`,{className:`space-y-1 mt-1`,children:e.fieldChanges.map((e,t)=>(0,s.jsx)(ge,{change:e},t))}),z&&e.reactions&&e.reactions.length>0&&(0,s.jsx)(`div`,{className:`mt-1.5`,children:(0,s.jsx)(ve,{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)(ve,{reactions:[],onToggleReaction:t=>p(e.id,t)})})]})]}),B&&(e.replyCount??0)>0&&(0,s.jsx)(ye,{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:te,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`)]})})]})]})},Ne=e=>{let{"data-obj-id":t,"data-obj-type":n,style:r,...i}=e||{};return{designer:{"data-obj-id":t,"data-obj-type":n,style:r},rest:i}},Pe=({schema:e={},className:t,...n})=>{(0,a.useRecordContext)();let{designer:r}=Ne(n);return(0,s.jsx)(`div`,{className:t,...r,children:(0,s.jsx)(Me,{items:[],config:e})})},Fe=({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:T}=w(),[E,D]=n.useState(C);return b===`right`||b===`left`?E&&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":T(`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:T(`detail.discussion`)})]}),S&&(0,s.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:()=>D(!0),"aria-label":T(`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)(Me,{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:T(`detail.discussion`),emptyLabel:T(`detail.noCommentsYet`),className:`border-0 shadow-none`})})]}):(0,s.jsx)(`div`,{className:(0,r.cn)(``,y),children:S&&E?(0,s.jsxs)(r.Button,{variant:`ghost`,className:`w-full justify-start gap-2 text-muted-foreground`,onClick:()=>D(!1),"aria-label":T(`detail.showDiscussion`,{count:t.length}),children:[(0,s.jsx)(i.MessageSquare,{className:`h-4 w-4`}),(0,s.jsx)(`span`,{children:T(`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`}),T(`detail.discussion`)]}),(0,s.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:()=>D(!0),"aria-label":T(`detail.hideDiscussion`),children:(0,s.jsx)(i.PanelRightClose,{className:`h-3.5 w-3.5`})})]}),(0,s.jsx)(Me,{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:T(`detail.discussion`),emptyLabel:T(`detail.noCommentsYet`)})]})})},Ie=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}},Le=({schema:e={},className:t,...n})=>{(0,a.useRecordContext)();let r=(0,a.useDiscussionContext)(),{designer:i}=Ie(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)(Fe,{items:r?.items||[],config:o,onAddComment:r?.onAddComment,onAddReply:r?.onAddReply,onToggleReaction:r?.onToggleReaction,mentionSuggestions:r?.mentionSuggestions,onUploadAttachments:r?.onUploadAttachments})})},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,...i})=>{let o=(0,a.useRecordContext)(),{translateOptions:c}=(0,a.useSafeFieldLabel)(),{designer:l}=Re(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?e:u},[u,d,o?.objectName,c]),p=d&&o?.data?o.data[d]:void 0,m=f.findIndex(e=>e.value===p);if(m<0&&(m=-1),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 h=(e,t)=>{if(f.length!==1)return e===0?`polygon(0 0, calc(100% - 14px) 0, 100% 50%, calc(100% - 14px) 100%, 0 100%)`:e===t?`polygon(0 0, 100% 0, 100% 100%, 0 100%, 14px 50%)`:`polygon(0 0, calc(100% - 14px) 0, 100% 50%, calc(100% - 14px) 100%, 0 100%, 14px 50%)`},g=f.length-1;return(0,s.jsxs)(`div`,{className:(0,r.cn)(`w-full`,t),...l,children:[(0,s.jsx)(`div`,{className:`hidden sm:flex w-full items-stretch`,role:`list`,"aria-label":e.aria?.label||`Record path`,children:f.map((e,t)=>{let n=m>=0&&t<m,i=t===m,a=h(t,g);return(0,s.jsx)(`div`,{role:`listitem`,"aria-current":i?`step`:void 0,style:a?{clipPath:a,WebkitClipPath:a}:void 0,className:(0,r.cn)(`relative flex-1 min-w-0 px-5 py-2 text-xs font-medium text-center`,t>0&&`-ml-2`,f.length===1&&`rounded-md border`,i&&`bg-primary text-primary-foreground shadow-sm ring-1 ring-primary/40`,n&&`bg-muted text-muted-foreground`,!i&&!n&&`bg-background text-foreground/70 border border-border/60`),children:(0,s.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 truncate`,style:{paddingLeft:t===0?0:`${14/2}px`,paddingRight:t===g?0:`${14/2}px`},children:[n&&(0,s.jsx)(`span`,{"aria-hidden":!0,children:`✓`}),e.label]})},`${e.value}-${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=m>=0&&t<m,i=t===m;return(0,s.jsx)(`div`,{role:`listitem`,"aria-current":i?`step`:void 0,className:(0,r.cn)(`shrink-0 px-3 py-1.5 rounded-full text-xs font-medium border whitespace-nowrap`,i&&`bg-primary text-primary-foreground border-primary shadow-sm ring-1 ring-primary/40`,n&&`bg-muted text-muted-foreground border-transparent`,!i&&!n&&`bg-background text-foreground/70 border-border/60`),children:(0,s.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[n&&(0,s.jsx)(`span`,{"aria-hidden":!0,children:`✓`}),e.label]})},`${e.value}-${t}-m`)})})]})},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}},Ve=({schema:e={},className:t,...n})=>{let i=(0,a.useRecordContext)(),{designer:o}=Be(n),l=(0,c.usePermissions)(),u=Array.isArray(e.actions)?e.actions:Array.isArray(e.properties?.actions)?e.properties.actions:[],d=i?.objectName||``,f=Array.isArray(e.requiredPermissions)?e.requiredPermissions:[];if(f.length>0&&d&&!f.every(e=>l.can(d,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 p=e.location||`record_header`,{getActionsForLocation:m,executeAction:h}=(0,a.useActionEngine)({actions:u,context:{record:i?.data,recordId:i?.recordId,objectName:i?.objectName}}),g=u.length>0?m(p):[];if(g.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 _=e.align||`end`,v=_===`start`?`justify-start`:_===`center`?`justify-center`:`justify-end`;return(0,s.jsx)(`div`,{className:(0,r.cn)(`flex flex-wrap items-center gap-2`,p===`record_header`&&!e.inline&&`-mt-12 sm:-mt-14 mb-2 relative z-10`,v,t),role:`toolbar`,"aria-label":e.aria?.label||`Quick actions`,...o,children:g.map((t,n)=>{let i=t.label||t.name||`Action ${n+1}`;return(0,s.jsx)(r.Button,{variant:t.variant||e.variant||`default`,size:t.size||e.size||`sm`,disabled:typeof t.disabled==`boolean`?t.disabled:void 0,onClick:()=>{if(typeof t.onClick==`function`){t.onClick();return}t.name&&h(t.name)},children:i},t.name||`qa-${n}`)})})},He=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}},Ue=({schema:e={},className:t,...n})=>{let{designer:r}=He(n),i=Array.isArray(e.entries)?e.entries:Array.isArray(e.properties?.entries)?e.properties.entries:[],a=e.loading??e.properties?.loading??!1,o=e.emptyText??e.properties?.emptyText;return(0,s.jsx)(`div`,{className:t,...r,children:(0,s.jsx)(G,{entries:i,loading:a,emptyText:o})})},We=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}},Ge=e=>e.replace(/[_-]+/g,` `).replace(/\b\w/g,e=>e.toUpperCase()).trim(),Ke=e=>e?.name||e?.title||e?.subject||e?.label||e?.id||`—`,qe=({schema:e={},className:t,...o})=>{let c=(0,a.useRecordContext)(),u=(0,a.useSafeFieldLabel)(),{t:d}=w(),{designer:f}=We(o),p=(0,l.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({});return n.default.useEffect(()=>{if(!g?.find||!h||m.length===0)return;let e=!1;return m.forEach(t=>{let n=t.objectName;v(e=>({...e,[n]:{loading:!0,total:0,items:e[n]?.items||[]}})),g.find(t.objectName,{$filter:{[t.relationshipField]:h},$top:t.limit??3,$count:!0}).then(t=>{if(e)return;let r=Array.isArray(t)?t:t?.data||[],i=typeof t?.total==`number`?t.total:typeof t?.count==`number`?t.count:r.length;v(e=>({...e,[n]:{loading:!1,total:i,items:r}}))}).catch(t=>{e||v(e=>({...e,[n]:{loading:!1,total:0,items:[],error:String(t?.message||t)}}))})}),()=>{e=!0}},[g,h,JSON.stringify(m.map(e=>`${e.objectName}:${e.relationshipField}:${e.limit??3}`))]),m.length===0?null:(0,s.jsx)(`div`,{className:(0,r.cn)(`flex flex-col gap-3`,e.className,t),...f,children:m.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||(u?.objectLabel?u.objectLabel({name:e.objectName,label:Ge(e.objectName)}):Ge(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)(l.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=Ke(t),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)(l.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)})})},Je=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`]),Ye=480,Xe=95;function Ze({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=Je,onFieldSave:m,onDelete:h,resizable:g=!0,fullPageHref:_}){let{t:v}=w(),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>=Ye)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,T=n.default.useRef(null),E=n.default.useCallback(e=>{if(!g)return;e.preventDefault();let t=b??(typeof window<`u`?Math.min(window.innerWidth*.6,960):720);T.current={startX:e.clientX,startWidth:t};let n=e=>{let t=T.current;if(!t)return;let n=t.startX-e.clientX,r=typeof window<`u`?window.innerWidth*Xe/100:1600,i=Math.min(r,Math.max(Ye,t.startWidth+n));x(Math.round(i))},r=()=>{T.current,T.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,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:E,className:`hidden sm:block absolute left-0 top-0 h-full w-1.5 cursor-col-resize select-none bg-transparent hover:bg-primary/30 active:bg-primary/50 transition-colors z-10`}),(0,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)(Y,{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 Qe(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 $e=({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 et(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 He(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 Ue={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`},We={added:`+`,removed:`-`,unchanged:` `},Ge=({oldValue:e,newValue:t,fieldName:a,fieldType:o=`string`,mode:c=`unified`,className:l})=>{let{t:u}=C(),[d,f]=n.useState(c),p=n.useMemo(()=>Ve(e,o),[e,o]),m=n.useMemo(()=>Ve(t,o),[t,o]),h=n.useMemo(()=>He(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`,Ue[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:We[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?Ue[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?Ue[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`)})})]})},Ke=({currentIndex:e,totalRecords:t,recordIds:a,onNavigate:o,onSearch:c,className:l})=>{let{t:u}=C(),[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]),w=n.useCallback(()=>{y&&o(a[a.length-1])},[y,o,a]),T=n.useCallback(e=>{let t=e.target.value;f(t),c?.(t)},[c]),E=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:w,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:E,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:T,className:`h-8 w-48 text-sm`})})]})]})},qe=28,Je=[`fill-primary stroke-primary`,`fill-blue-500 stroke-blue-500`,`fill-emerald-500 stroke-emerald-500`,`fill-amber-500 stroke-amber-500`],Ye=[`fill-primary-foreground`,`fill-white`,`fill-white`,`fill-white`];function Xe(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 Ze(e,t=6){return e.length<=t?e:e.slice(0,t-1)+`…`}var Qe=({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(()=>Xe(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=Je[Math.min(e.level,Je.length-1)],i=Ye[Math.min(e.level,Ye.length-1)],a=e.level===0?qe+6:qe;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:Ze(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 $e(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function et(e){return e.startsWith(`image/`)}function tt(e){return et(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 nt=({attachments:e,onUpload:t,onRemove:a,className:o,readOnly:c=!1})=>{let{t:l}=C(),[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=et(e.type),n=tt(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:$e(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)})})]})]})};function rt(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 it=({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:rt(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`,` `,rt(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`]})})]})]})})]})},at=({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`})})]})},ot=({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 st(e,t,n){return{type:e.type,id:e.id,name:e.name,offset:t,length:n}}function ct(e){return e==null?[]:Array.isArray(e)?e.filter(e=>e!=null):[e]}function lt(e){if(!e)return null;if(e.stageField)return e.stageField;let t=e.fields||{};for(let e of[`status`,`stage`,`state`,`phase`])if(e in t)return e;for(let[e,n]of Object.entries(t)){let t=(n?.type||``).toLowerCase();if(t===`status`||t===`stage`)return e}return null}function ut(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 dt(e,t,n=4){if(!e)return[];if(Array.isArray(e.highlightFields)&&e.highlightFields.length>0)return e.highlightFields.slice(0,n);let r=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&&r.add(t),e.primaryField&&r.add(e.primaryField);for(let t of[`name`,`full_name`,`title`,`subject`,`display_name`])t in(e.fields||{})&&r.add(t);let i=[`owner`,`owner_id`,`amount`,`rating`,`source`,`priority`,`industry`,`phone`,`email`],a=[],o=e.fields||{};for(let e of i)if(e in o&&!r.has(e)&&a.push(e),a.length>=n)return a;for(let e of Object.keys(o))if(!(a.includes(e)||r.has(e))&&(a.push(e),a.length>=n))break;return a}function ft(e,t={}){return{type:`page:header`,recordChrome:t.recordChrome!==!1,...Array.isArray(t.actions)&&t.actions.length>0?{actions:t.actions}:{}}}function pt(e,t){return!Array.isArray(t)||t.length===0?null:{type:`record:quick_actions`,actions:t,location:`record_header`}}function mt(e,t={}){let n=t.statusField??lt(e),r=t.stages??(n?ut(e,n):null),i=t.highlightFields??dt(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 ht(e,t,n){return{type:`record:details`,sections:t,...n&&n.length>0?{hideFields:n}:{}}}function gt(e,t={}){let n=t.statusField??lt(e),r=t.highlightFields??dt(e,n),i=[{label:`Details`,children:[ht(e,t.sections,r)]}];return Array.isArray(t.related)&&t.related.length>0&&i.push({label:`Related`,children:t.related.map(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}:{}}))}),t.showActivity&&i.push({label:`Activity`,children:[{type:`record:activity`}]}),t.history&&i.push({label:`History`,children:[{type:`record:history`,entries:t.history.entries,loading:t.history.loading,emptyText:t.history.emptyText}]}),{type:`page:tabs`,items:i}}function _t(){return{type:`record:discussion`}}function vt(e,t={}){let n=t.slots||{},r=[];if(`header`in n&&n.header!==void 0?r.push(...ct(n.header)):r.push(ft(e,{recordChrome:t.recordChrome,actions:t.headerActions})),`actions`in n&&n.actions!==void 0&&r.push(...ct(n.actions)),`highlights`in n&&n.highlights!==void 0?r.push(...ct(n.highlights)):r.push(...mt(e,{highlightFields:t.highlightFields,statusField:t.statusField,stages:t.stages,hideHighlights:t.hideHighlights,hidePath:t.hidePath})),`tabs`in n&&n.tabs!==void 0)r.push(...ct(n.tabs));else if(`details`in n&&n.details!==void 0){let i=ct(n.details),a=gt(e,{sections:t.sections,related:t.related,showActivity:t.showActivity,history:t.history,highlightFields:t.highlightFields,statusField:t.statusField});Array.isArray(a.items)&&a.items.length>0&&(a.items[0]={...a.items[0],children:i}),r.push(a)}else r.push(gt(e,{sections:t.sections,related:t.related,showActivity:t.showActivity,history:t.history,highlightFields:t.highlightFields,statusField:t.statusField}));return`discussion`in n&&n.discussion!==void 0?r.push(...ct(n.discussion)):t.hideDiscussion||r.push(_t()),{type:`record`,pageType:`record`,object:e?.name,template:`full-width`,regions:[{name:`main`,width:`full`,components:r}]}}t.ComponentRegistry.register(`detail-view`,K,{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`,T,{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`,O,{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`,K,{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`,J,{namespace:`record`,category:`record`,label:`Record Details`,icon:`FileText`}),t.ComponentRegistry.register(`record:related_list`,X,{namespace:`record`,category:`record`,label:`Related List`,icon:`List`}),t.ComponentRegistry.register(`record:highlights`,de,{namespace:`record`,category:`record`,label:`Highlights Panel`,icon:`Star`}),t.ComponentRegistry.register(`record:activity`,Ce,{namespace:`record`,category:`record`,label:`Activity Timeline`,icon:`Activity`}),t.ComponentRegistry.register(`record:chatter`,Ee,{namespace:`record`,category:`record`,label:`Chatter Feed`,icon:`MessageSquare`}),t.ComponentRegistry.register(`record:discussion`,Ee,{namespace:`record`,category:`record`,label:`Discussion`,icon:`MessageSquare`}),t.ComponentRegistry.register(`record:path`,Oe,{namespace:`record`,category:`record`,label:`Path / Stepper`,icon:`GitBranch`}),t.ComponentRegistry.register(`record:quick_actions`,Ae,{namespace:`record`,category:`record`,label:`Quick Actions`,icon:`Zap`}),t.ComponentRegistry.register(`record:history`,Me,{namespace:`record`,category:`record`,label:`History Timeline`,icon:`Clock`}),e.ActivityTimeline=R,e.CommentAttachment=nt,e.CommentInput=at,e.DETAIL_DEFAULT_TRANSLATIONS=S,e.DetailSection=T,e.DetailTabs=E,e.DetailView=K,e.DiffView=Ge,e.FieldChangeItem=Q,e.HeaderHighlight=A,e.HistoryTimeline=te,e.InlineCreateRelated=Re,e.MentionAutocomplete=ot,e.PointInTimeRestore=it,e.ReactionPicker=fe,e.RecordActivityRenderer=Ce,e.RecordActivityTimeline=xe,e.RecordChatterPanel=we,e.RecordChatterRenderer=Ee,e.RecordComments=M,e.RecordDetailDrawer=Ie,e.RecordDetailsRenderer=J,e.RecordHighlightsRenderer=de,e.RecordHistoryRenderer=Me,e.RecordMetaFooter=G,e.RecordNavigationEnhanced=Ke,e.RecordPathRenderer=Oe,e.RecordQuickActionsRenderer=Ae,e.RecordRelatedListRenderer=X,e.RelatedList=O,e.RelationshipGraph=Qe,e.RichTextCommentInput=Be,e.SectionGroup=k,e.SubscriptionToggle=he,e.ThreadedReplies=me,e.applyAutoSpan=y,e.applyDetailAutoLayout=b,e.buildDefaultActions=pt,e.buildDefaultDetails=ht,e.buildDefaultDiscussion=_t,e.buildDefaultHeader=ft,e.buildDefaultHighlights=mt,e.buildDefaultPageSchema=vt,e.buildDefaultTabs=gt,e.createMentionFromSuggestion=st,e.createSafeTranslationHook=x,e.deriveHighlightFields=dt,e.deriveRecordPageHref=Le,e.deriveStages=ut,e.detectStatusField=lt,e.inferDetailColumns=v,e.isWideFieldType=_,e.useDetailTranslation=C});
|
|
5
|
+
`)}}function tt(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 nt={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`},rt={added:`+`,removed:`-`,unchanged:` `},it=({oldValue:e,newValue:t,fieldName:a,fieldType:o=`string`,mode:c=`unified`,className:l})=>{let{t:u}=w(),[d,f]=n.useState(c),p=n.useMemo(()=>et(e,o),[e,o]),m=n.useMemo(()=>et(t,o),[t,o]),h=n.useMemo(()=>tt(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`,nt[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:rt[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?nt[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?nt[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`)})})]})},at=({currentIndex:e,totalRecords:t,recordIds:a,onNavigate:o,onSearch:c,className:l})=>{let{t:u}=w(),[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]),T=n.useCallback(e=>{let t=e.target.value;f(t),c?.(t)},[c]),E=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:E,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:T,className:`h-8 w-48 text-sm`})})]})]})},ot=28,st=[`fill-primary stroke-primary`,`fill-blue-500 stroke-blue-500`,`fill-emerald-500 stroke-emerald-500`,`fill-amber-500 stroke-amber-500`],ct=[`fill-primary-foreground`,`fill-white`,`fill-white`,`fill-white`];function lt(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 ut(e,t=6){return e.length<=t?e:e.slice(0,t-1)+`…`}var dt=({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(()=>lt(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=st[Math.min(e.level,st.length-1)],i=ct[Math.min(e.level,ct.length-1)],a=e.level===0?ot+6:ot;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:ut(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 ft(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 pt=({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:ft(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`,` `,ft(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`]})})]})]})})]})},mt=({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`})})]})},ht=({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 gt(e,t,n){return{type:e.type,id:e.id,name:e.name,offset:t,length:n}}function _t(e){return e==null?[]:Array.isArray(e)?e.filter(e=>e!=null):[e]}function vt(e){if(!e)return null;if(e.stageField)return e.stageField;let t=e.fields||{};for(let e of[`status`,`stage`,`state`,`phase`])if(e in t)return e;for(let[e,n]of Object.entries(t)){let t=(n?.type||``).toLowerCase();if(t===`status`||t===`stage`)return e}return null}function yt(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 bt(e,t,n=4){if(!e)return[];if(Array.isArray(e.highlightFields)&&e.highlightFields.length>0)return e.highlightFields.slice(0,n);let r=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&&r.add(t),e.primaryField&&r.add(e.primaryField);for(let t of[`name`,`full_name`,`title`,`subject`,`display_name`])t in(e.fields||{})&&r.add(t);let i=[`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`],a=new Set([`currency`,`number`,`integer`,`decimal`,`percent`,`date`,`datetime`,`time`,`reference`,`lookup`,`user`,`owner`,`select`,`enum`,`multiselect`,`status`,`email`,`phone`,`url`,`text`,`string`]),o=[],s=e.fields||{};for(let e of i)if(e in s&&!r.has(e)&&o.push(e),o.length>=n)return o;for(let e of Object.keys(s)){if(o.includes(e)||r.has(e))continue;let t=s[e]?.type;if(!(t&&!a.has(t))&&(o.push(e),o.length>=n))break}return o}function xt(e,t={}){return{type:`page:header`,recordChrome:t.recordChrome!==!1,...Array.isArray(t.actions)&&t.actions.length>0?{actions:t.actions}:{}}}function St(e,t){return!Array.isArray(t)||t.length===0?null:{type:`record:quick_actions`,actions:t,location:`record_header`}}function Ct(e,t={}){let n=t.statusField??vt(e),r=t.stages??(n?yt(e,n):null),i=t.highlightFields??bt(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 wt(e,t,n){return{type:`record:details`,sections:t,...n&&n.length>0?{hideFields:n}:{}}}function Tt(e,t={}){let n=t.statusField??vt(e),r=t.highlightFields??bt(e,n),i=[{label:`Details`,children:[wt(e,t.sections,r)]}];return!t.hideRelatedTab&&Array.isArray(t.related)&&t.related.length>0&&i.push({label:`Related`,children:t.related.map(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}:{}}))}),t.showActivity&&i.push({label:`Activity`,children:[{type:`record:activity`}]}),t.history&&i.push({label:`History`,children:[{type:`record:history`,entries:t.history.entries,loading:t.history.loading,emptyText:t.history.emptyText}]}),{type:`page:tabs`,items:i}}function Et(){return{type:`record:discussion`}}function Dt(e,t={}){let n=t.slots||{},r=[];`header`in n&&n.header!==void 0?r.push(..._t(n.header)):r.push(xt(e,{recordChrome:t.recordChrome,actions:t.headerActions})),`actions`in n&&n.actions!==void 0&&r.push(..._t(n.actions)),`highlights`in n&&n.highlights!==void 0?r.push(..._t(n.highlights)):r.push(...Ct(e,{highlightFields:t.highlightFields,statusField:t.statusField,stages:t.stages,hideHighlights:t.hideHighlights,hidePath:t.hidePath}));let i=!t.hideReferenceRail&&Array.isArray(t.related)&&t.related.length>=2,a=t.hideRelatedTab??i;if(`tabs`in n&&n.tabs!==void 0)r.push(..._t(n.tabs));else if(`details`in n&&n.details!==void 0){let i=_t(n.details),o=Tt(e,{sections:t.sections,related:t.related,showActivity:t.showActivity,history:t.history,highlightFields:t.highlightFields,statusField:t.statusField,hideRelatedTab:a});Array.isArray(o.items)&&o.items.length>0&&(o.items[0]={...o.items[0],children:i}),r.push(o)}else r.push(Tt(e,{sections:t.sections,related:t.related,showActivity:t.showActivity,history:t.history,highlightFields:t.highlightFields,statusField:t.statusField,hideRelatedTab:a}));`discussion`in n&&n.discussion!==void 0?r.push(..._t(n.discussion)):t.hideDiscussion||r.push(Et());let o=[{name:`main`,width:`full`,components:r}];return i&&o.push({name:`aside`,width:`small`,className:`hidden xl:flex flex-col gap-4`,components:[{type:`record:reference_rail`,entries:t.related.map(e=>({objectName:e.objectName,relationshipField:e.relationshipField,title:e.title,icon:e.icon,limit:3}))}]}),{type:`record`,pageType:`record`,object:e?.name,template:`full-width`,regions:o}}t.ComponentRegistry.register(`detail-view`,Y,{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`,E,{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`,k,{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`,Y,{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`,fe,{namespace:`record`,category:`record`,label:`Record Details`,icon:`FileText`}),t.ComponentRegistry.register(`record:related_list`,pe,{namespace:`record`,category:`record`,label:`Related List`,icon:`List`}),t.ComponentRegistry.register(`record:highlights`,he,{namespace:`record`,category:`record`,label:`Highlights Panel`,icon:`Star`}),t.ComponentRegistry.register(`record:activity`,Pe,{namespace:`record`,category:`record`,label:`Activity Timeline`,icon:`Activity`}),t.ComponentRegistry.register(`record:chatter`,Le,{namespace:`record`,category:`record`,label:`Chatter Feed`,icon:`MessageSquare`}),t.ComponentRegistry.register(`record:discussion`,Le,{namespace:`record`,category:`record`,label:`Discussion`,icon:`MessageSquare`}),t.ComponentRegistry.register(`record:path`,ze,{namespace:`record`,category:`record`,label:`Path / Stepper`,icon:`GitBranch`}),t.ComponentRegistry.register(`record:quick_actions`,Ve,{namespace:`record`,category:`record`,label:`Quick Actions`,icon:`Zap`}),t.ComponentRegistry.register(`record:history`,Ue,{namespace:`record`,category:`record`,label:`History Timeline`,icon:`Clock`}),t.ComponentRegistry.register(`record:reference_rail`,qe,{namespace:`record`,category:`record`,label:`Reference Rail`,icon:`PanelRight`}),e.ActivityTimeline=z,e.CommentAttachment=Ee,e.CommentInput=mt,e.ConcurrentUpdateDialog=le,e.DETAIL_DEFAULT_TRANSLATIONS=C,e.DetailSection=E,e.DetailTabs=D,e.DetailView=Y,e.DiffView=it,e.FieldChangeItem=ge,e.HeaderHighlight=j,e.HistoryTimeline=G,e.InlineCreateRelated=$e,e.MentionAutocomplete=ht,e.PointInTimeRestore=pt,e.ReactionPicker=ve,e.RecordActivityRenderer=Pe,e.RecordActivityTimeline=Me,e.RecordChatterPanel=Fe,e.RecordChatterRenderer=Le,e.RecordComments=N,e.RecordDetailDrawer=Ze,e.RecordDetailsRenderer=fe,e.RecordHighlightsRenderer=he,e.RecordHistoryRenderer=Ue,e.RecordMetaFooter=ie,e.RecordNavigationEnhanced=at,e.RecordPathRenderer=ze,e.RecordQuickActionsRenderer=Ve,e.RecordReferenceRailRenderer=qe,e.RecordRelatedListRenderer=pe,e.RelatedList=k,e.RelationshipGraph=dt,e.RichTextCommentInput=Se,e.SectionGroup=A,e.SubscriptionToggle=be,e.ThreadedReplies=ye,e.applyAutoSpan=b,e.applyDetailAutoLayout=x,e.buildDefaultActions=St,e.buildDefaultDetails=wt,e.buildDefaultDiscussion=Et,e.buildDefaultHeader=xt,e.buildDefaultHighlights=Ct,e.buildDefaultPageSchema=Dt,e.buildDefaultTabs=Tt,e.createMentionFromSuggestion=gt,e.createSafeTranslationHook=S,e.deriveHighlightFields=bt,e.deriveRecordPageHref=Qe,e.deriveStages=yt,e.detectStatusField=vt,e.inferDetailColumns=y,e.isConcurrentUpdateError=X,e.isWideFieldType=v,e.useDetailTranslation=w});
|