@objectstack/console 16.0.0-rc.0 → 16.0.0-rc.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.
Files changed (95) hide show
  1. package/dist/.objectui-sha +1 -1
  2. package/dist/assets/{AdapterProvider-DaQhp5MR.js → AdapterProvider-DkXaFA1A.js} +1 -1
  3. package/dist/assets/{AiPendingActionsPage-9UZ4_qZW.js → AiPendingActionsPage-C1pkyzWu.js} +1 -1
  4. package/dist/assets/{ApiConsolePage-DVnQPvbh.js → ApiConsolePage-BCujjvCA.js} +1 -1
  5. package/dist/assets/{AppDocsIndex-RWbVdvGq.js → AppDocsIndex-DwtDfwnR.js} +1 -1
  6. package/dist/assets/{AppManagementPage-JlGIV3AH.js → AppManagementPage-KPrmIA-f.js} +1 -1
  7. package/dist/assets/ApprovalsInboxPage-DFQUv0F_.js +1 -0
  8. package/dist/assets/{AuditLogPage-C6SMCaHa.js → AuditLogPage-BNkFvefV.js} +1 -1
  9. package/dist/assets/{ComponentNavView-DpWz8z8w.js → ComponentNavView-FTFk3uvC.js} +1 -1
  10. package/dist/assets/{CreateViewDialog-DQqqIAwO.js → CreateViewDialog-DTzKynzF.js} +1 -1
  11. package/dist/assets/{DashboardView-BTS9ygDI.js → DashboardView-Y6nIjjJB.js} +1 -1
  12. package/dist/assets/{DeveloperHubPage-CX3urxAq.js → DeveloperHubPage-CYPM3AvL.js} +1 -1
  13. package/dist/assets/{DocShell-CXBgEZhg.js → DocShell-DnXj6ocC.js} +1 -1
  14. package/dist/assets/{ExpressionProvider-C26LCaQj.js → ExpressionProvider-BrbZIz2M.js} +1 -1
  15. package/dist/assets/{FlowRunsPage-DKnUh_Ec.js → FlowRunsPage-BAbmqrqx.js} +1 -1
  16. package/dist/assets/{IntegrationsPage-BvyX5vIh.js → IntegrationsPage-CyD9iolE.js} +1 -1
  17. package/dist/assets/InterfaceListPage-DdaX7c_c.js +1 -0
  18. package/dist/assets/ManagedByBadge-DbYycO1m.js +1 -0
  19. package/dist/assets/{MarketplaceAccessDenied-DFaKQ3Ws.js → MarketplaceAccessDenied-Csr3Jh7C.js} +1 -1
  20. package/dist/assets/{MarketplaceInstalledPage-CKmxuBaG.js → MarketplaceInstalledPage-BtD9NMRl.js} +1 -1
  21. package/dist/assets/{MarketplacePackagePage-BjhnLR61.js → MarketplacePackagePage-DHrjr3jY.js} +1 -1
  22. package/dist/assets/{MarketplacePage-BWLFbDxW.js → MarketplacePage-Dw2yHsdE.js} +1 -1
  23. package/dist/assets/{MetadataInspector-B9z7wtJS.js → MetadataInspector-C6pU5_lx.js} +1 -1
  24. package/dist/assets/{MetadataProvider-Dq7I7eh-.js → MetadataProvider-BnfG1pyl.js} +1 -1
  25. package/dist/assets/{ObjectDataPage-Bm9tSz-w.js → ObjectDataPage-BA93ldBf.js} +1 -1
  26. package/dist/assets/PageView-jtsz_IPE.js +1 -0
  27. package/dist/assets/{ProfilePage-DAkDEioN.js → ProfilePage-BhlwjGUP.js} +1 -1
  28. package/dist/assets/{PublicFormsPage-CRNSj35t.js → PublicFormsPage-D5kg7qJa.js} +1 -1
  29. package/dist/assets/RecordDetailView-F0k3QMTV.js +9 -0
  30. package/dist/assets/{RecordFormPage-Cye1lcxq.js → RecordFormPage-BRDfPdPg.js} +1 -1
  31. package/dist/assets/{ReportDefaultInspector-B0nTPIZ8.js → ReportDefaultInspector-CYCJDOVb.js} +1 -1
  32. package/dist/assets/{ReportView-BeL2GZLl.js → ReportView-Dtz9IJbH.js} +1 -1
  33. package/dist/assets/{SearchResultsPage-XP2cdAyq.js → SearchResultsPage-0pCQZ9_u.js} +1 -1
  34. package/dist/assets/{SettingsHub-yoHgXGvm.js → SettingsHub-DqS8nfs-.js} +1 -1
  35. package/dist/assets/{SettingsView-BO0qYMbW.js → SettingsView-DHrrHsbU.js} +1 -1
  36. package/dist/assets/{SystemHubPage-qOFiW2Jq.js → SystemHubPage-BWPXrnc9.js} +1 -1
  37. package/dist/assets/data-adapter-BR5P3Htq.js +9 -0
  38. package/dist/assets/framework-brxTxzwx.js +8 -0
  39. package/dist/assets/{getIcon-CBdepA3t.js → getIcon-EzAarNT8.js} +1 -1
  40. package/dist/assets/{highlighted-body-OFNGDK62-CYfwZSTb.js → highlighted-body-OFNGDK62-3tGE6imP.js} +1 -1
  41. package/dist/assets/{i18n-grFi0A0v.js → i18n-CWIk44wT.js} +1 -1
  42. package/dist/assets/index-LuGaXtX0.js +2 -0
  43. package/dist/assets/infrastructure-C6pQBkbt.js +3 -0
  44. package/dist/assets/mermaid-GHXKKRXX-btdeklf1.js +1 -0
  45. package/dist/assets/{metadata-admin-D3yD8v_g.js → metadata-admin-Buf34qxl.js} +7 -7
  46. package/dist/assets/plugin-calendar-Bx_Bsdae.js +1 -0
  47. package/dist/assets/plugin-charts-DqND8tT3.js +7 -0
  48. package/dist/assets/plugin-chatbot-DwbSyUax.js +120 -0
  49. package/dist/assets/plugin-dashboard-D2VhHDxA.js +6 -0
  50. package/dist/assets/plugin-form-HMQsT2Tp.js +1 -0
  51. package/dist/assets/plugin-gantt-CMpG3oO4.js +63 -0
  52. package/dist/assets/plugin-grid-Dz4WW_sQ.js +8 -0
  53. package/dist/assets/plugin-kanban-fgScBnfP.js +1 -0
  54. package/dist/assets/{plugin-map-fMpIp7jh.js → plugin-map-zagD7Zuk.js} +1 -1
  55. package/dist/assets/{plugin-markdown-wZpqyjok.js → plugin-markdown-DtcSX8M_.js} +1 -1
  56. package/dist/assets/{plugin-report-kGtO0FOF.js → plugin-report-BRs6v5vb.js} +3 -3
  57. package/dist/assets/{plugin-timeline-DZNEy3Y1.js → plugin-timeline-Cl8J9HYj.js} +1 -1
  58. package/dist/assets/{plugin-tree-CZRX9ChE.js → plugin-tree-B3zTpUOf.js} +1 -1
  59. package/dist/assets/plugin-view-BDYhOlHx.js +1 -0
  60. package/dist/assets/plugins-views-Dc4ARhcP.js +4 -0
  61. package/dist/assets/{skeletons-CX6Ch5Lg.js → skeletons-CPF9cI6N.js} +1 -1
  62. package/dist/assets/{src-DNd8fJOE.js → src-A4S4Zx5p.js} +1 -1
  63. package/dist/assets/{src-CIr5NcaF.js → src-By-rFjBo.js} +1 -1
  64. package/dist/assets/src-CRFYUj2Z.js +19 -0
  65. package/dist/assets/{types-C0F-S2Id.js → types-CtGENai_.js} +1 -1
  66. package/dist/assets/ui-components-D1psd5qA.js +72 -0
  67. package/dist/assets/{ui-layout-CmmmekN3.js → ui-layout-UgL2qgLW.js} +1 -1
  68. package/dist/assets/{use-book-data-DyDHAzga.js → use-book-data-CWCLCSUn.js} +1 -1
  69. package/dist/assets/{useMetadata-BMHVJNxp.js → useMetadata-Byeqylbl.js} +1 -1
  70. package/dist/assets/vendor-objectstack-CjHQG7Oa.js +114 -0
  71. package/dist/index.html +3 -3
  72. package/package.json +1 -1
  73. package/dist/assets/ApprovalsInboxPage-DMfSM-B7.js +0 -1
  74. package/dist/assets/InterfaceListPage-D00ihpcS.js +0 -1
  75. package/dist/assets/ManagedByBadge-B4O4Jy3c.js +0 -1
  76. package/dist/assets/PageView-BTHYu8Z9.js +0 -1
  77. package/dist/assets/RecordDetailView-C6UiMORv.js +0 -9
  78. package/dist/assets/data-adapter-CS4onYGf.js +0 -9
  79. package/dist/assets/framework-Oi7uo_kE.js +0 -8
  80. package/dist/assets/index-D_-Sh_Rw.js +0 -2
  81. package/dist/assets/infrastructure-CQFJ5N6p.js +0 -3
  82. package/dist/assets/mermaid-GHXKKRXX-DtO0m-Vl.js +0 -1
  83. package/dist/assets/plugin-calendar-Bm0-Kkhu.js +0 -1
  84. package/dist/assets/plugin-charts-BHxVdXp7.js +0 -7
  85. package/dist/assets/plugin-chatbot-BRbgUPLw.js +0 -120
  86. package/dist/assets/plugin-dashboard-ARn_CaB3.js +0 -6
  87. package/dist/assets/plugin-form-C969LzWi.js +0 -1
  88. package/dist/assets/plugin-gantt-DrEbvyAE.js +0 -63
  89. package/dist/assets/plugin-grid-CnxMz-9O.js +0 -8
  90. package/dist/assets/plugin-kanban-C-mR5I0H.js +0 -1
  91. package/dist/assets/plugin-view-BhPeq9o5.js +0 -1
  92. package/dist/assets/plugins-views-DCG6qMPm.js +0 -4
  93. package/dist/assets/src-CB6vSDbd.js +0 -19
  94. package/dist/assets/ui-components-BluZyuZX.js +0 -72
  95. package/dist/assets/vendor-objectstack-DxPvmbmF.js +0 -114
package/dist/index.html CHANGED
@@ -46,12 +46,12 @@
46
46
  <script>
47
47
  window.process = window.process || { env: { NODE_ENV: 'development' }, version: '', platform: 'browser' };
48
48
  </script>
49
- <script type="module" crossorigin src="./assets/index-D_-Sh_Rw.js"></script>
49
+ <script type="module" crossorigin src="./assets/index-LuGaXtX0.js"></script>
50
50
  <link rel="stylesheet" crossorigin href="./assets/ui-components-BL3SEdAz.css">
51
51
  <link rel="stylesheet" crossorigin href="./assets/plugin-dashboard-DnNKJB60.css">
52
52
  <link rel="stylesheet" crossorigin href="./assets/index-D3TWmLHH.css">
53
- <link rel="modulepreload" href="./assets/framework-Oi7uo_kE.js" />
54
- <link rel="modulepreload" href="./assets/ui-components-BluZyuZX.js" />
53
+ <link rel="modulepreload" href="./assets/framework-brxTxzwx.js" />
54
+ <link rel="modulepreload" href="./assets/ui-components-D1psd5qA.js" />
55
55
  <link rel="modulepreload" href="./assets/vendor-radix-CWCRv2pn.js" />
56
56
  <link rel="modulepreload" href="./assets/vendor-react-BKSb6vFP.js" />
57
57
  </head>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@objectstack/console",
3
- "version": "16.0.0-rc.0",
3
+ "version": "16.0.0-rc.1",
4
4
  "description": "Prebuilt Console SPA pinned to this @objectstack/framework release. Source of truth: @object-ui/console (https://github.com/objectstack-ai/objectui).",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/objectstack-ai/framework/tree/main/packages/console",
@@ -1 +0,0 @@
1
- import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{a as t,h as n,m as r,r as i,y as a}from"./vendor-react-BKSb6vFP.js";import{f as ee,g as te,h as ne,p as re}from"./infrastructure-CQFJ5N6p.js";import{$t as ie,Cr as ae,Ct as oe,Dr as se,Er as ce,Es as le,Fi as ue,Fr as de,Fs as fe,Gt as o,Ii as pe,Jt as me,Ks as he,Mc as s,Or as c,Q as ge,Qt as _e,Rs as ve,Sr as ye,St as l,T as be,Tr as xe,Uc as Se,Wr as Ce,Ws as we,Xt as Te,Yi as Ee,Yt as De,Z as Oe,Zt as ke,_r as Ae,_t as je,ar as Me,bi as Ne,br as Pe,bs as Fe,bt as Ie,en as Le,fa as Re,fr as u,fs as ze,gr as Be,gt as Ve,ht as He,mn as Ue,mt as We,nn as Ge,or as Ke,qs as qe,qt as Je,rn as Ye,sr as Xe,tn as d,ts as Ze,tt as Qe,vn as $e,vt as et,wr as tt,wt as nt,xr as rt,xt as f,yr as it,yt as at}from"./ui-components-BluZyuZX.js";import{r as p}from"./vendor-ui-utils-D-WJ115h.js";import{p as ot}from"./src-CB6vSDbd.js";import{u as st}from"./plugins-views-DCG6qMPm.js";var m=e(a(),1),ct=`${``.replace(/\/$/,``)}/api/v1`;async function h(e,t){let n=te.get(),r=await fetch(`${ct}${e}`,{credentials:`include`,headers:{"Content-Type":`application/json`,...n?{Authorization:`Bearer ${n}`}:{},...t?.headers||{}},...t}),i=null;try{i=await r.json()}catch{}if(!r.ok){let e=i?.code??`HTTP_${r.status}`,t=i?.message??i?.error??r.statusText,n=Error(`${e}: ${t}`);throw n.code=e,n.status=r.status,n.details=i,n}return i}var g={listProcesses(e={}){let t=new URLSearchParams;e.object&&t.set(`object`,e.object),e.activeOnly&&t.set(`activeOnly`,`true`);let n=t.toString();return h(`/approvals/processes${n?`?${n}`:``}`)},listRequests(e={}){let t=new URLSearchParams;e.status&&t.set(`status`,e.status),e.object&&t.set(`object`,e.object),e.recordId&&t.set(`recordId`,e.recordId);let n=Array.isArray(e.approverId)?e.approverId.filter(Boolean).join(`,`):e.approverId;n&&t.set(`approverId`,n),e.submitterId&&t.set(`submitterId`,e.submitterId),e.q?.trim()&&t.set(`q`,e.q.trim()),e.limit!=null&&t.set(`limit`,String(e.limit)),e.offset!=null&&t.set(`offset`,String(e.offset));let r=t.toString();return h(`/approvals/requests${r?`?${r}`:``}`)},async getRequest(e){return{data:await h(`/approvals/requests/${encodeURIComponent(e)}`)}},listActions(e){return h(`/approvals/requests/${encodeURIComponent(e)}/actions`)},async approve(e,t){let n=await h(`/approvals/requests/${encodeURIComponent(e)}/approve`,{method:`POST`,body:JSON.stringify(t)});return{data:n.request,finalized:n.finalized}},async reject(e,t){let n=await h(`/approvals/requests/${encodeURIComponent(e)}/reject`,{method:`POST`,body:JSON.stringify(t)});return{data:n.request,finalized:n.finalized}},async recall(e,t){return{data:(await h(`/approvals/requests/${encodeURIComponent(e)}/recall`,{method:`POST`,body:JSON.stringify(t)})).request,finalized:!0}},async reassign(e,t){return{data:(await h(`/approvals/requests/${encodeURIComponent(e)}/reassign`,{method:`POST`,body:JSON.stringify(t)})).request}},async remind(e,t={}){let n=await h(`/approvals/requests/${encodeURIComponent(e)}/remind`,{method:`POST`,body:JSON.stringify(t)});return{data:n.request,notified:n.notified}},async requestInfo(e,t){return{data:(await h(`/approvals/requests/${encodeURIComponent(e)}/request-info`,{method:`POST`,body:JSON.stringify(t)})).request}},async sendBack(e,t){let n=await h(`/approvals/requests/${encodeURIComponent(e)}/revise`,{method:`POST`,body:JSON.stringify(t)});return{data:n.request,autoRejected:n.autoRejected===!0}},async resubmit(e,t={}){let n=await h(`/approvals/requests/${encodeURIComponent(e)}/resubmit`,{method:`POST`,body:JSON.stringify(t)});return{data:n.request,resumed:n.resumed===!0}},async comment(e,t){return{data:(await h(`/approvals/requests/${encodeURIComponent(e)}/comment`,{method:`POST`,body:JSON.stringify(t)})).request}},async submit(e){return h(`/approvals/requests`,{method:`POST`,body:JSON.stringify(e)})}};function lt(e){if(!e)return[];let t=new Set;e.id&&t.add(e.id),e.email&&t.add(e.email);let n=[...e.roles||[],...typeof e.role==`string`?e.role.split(`,`):[]];for(let e of n){let n=String(e).trim();n&&t.add(`role:${n}`)}return Array.from(t)}var _=i(),ut=50,dt={pending:`border-amber-200 bg-amber-50 text-amber-700 dark:border-amber-500/30 dark:bg-amber-500/10 dark:text-amber-400`,approved:`border-emerald-200 bg-emerald-50 text-emerald-700 dark:border-emerald-500/30 dark:bg-emerald-500/10 dark:text-emerald-400`,rejected:`border-red-200 bg-red-50 text-red-700 dark:border-red-500/30 dark:bg-red-500/10 dark:text-red-400`,recalled:`border-border bg-muted text-muted-foreground`,returned:`border-violet-200 bg-violet-50 text-violet-700 dark:border-violet-500/30 dark:bg-violet-500/10 dark:text-violet-400`};function ft(e){if(!e)return`—`;try{return new Date(e).toLocaleString()}catch{return e}}function v(e){return e?e.includes(`@`)?e:e.startsWith(`role:`)?`Role: ${e.slice(5)}`:e.length>14?`${e.slice(0,6)}…${e.slice(-4)}`:e:`—`}function pt(e){return e&&String(e).replace(/^flow:/,``).trim().split(/[_\-\s]+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `)||`—`}function y(e){return e.process_label||pt(e.process_name)}function mt(e){return e.step_label?e.step_label:e.current_step?pt(e.current_step):null}function ht(e){return e.submitter_name||v(e.submitter_id)}function gt(e,t){return t.pending_approver_names?.[e]||v(e)}function _t(e){return e.object_label||e.object_name}function b(e){return e.submitted_at||e.created_at||void 0}function x(e){let t=b(e);if(!t)return null;let n=Date.parse(t);return Number.isNaN(n)?null:(Date.now()-n)/36e5}function vt(e){if(e.status!==`pending`)return`text-muted-foreground`;let t=x(e);return t==null?`text-muted-foreground`:t>72?`text-red-600 dark:text-red-400 font-medium`:t>24?`text-amber-600 dark:text-amber-400`:`text-muted-foreground`}function yt(e){let t=Math.max(1,Math.round(Math.abs(e)/36e5));return t<48?`${t}h`:`${Math.round(t/24)}d`}var S=new Set([`id`,`created_at`,`updated_at`,`created_by`,`updated_by`,`organization_id`]);function C(e){return e.split(`_`).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `)}function w(e,t){if(typeof t==`boolean`)return t?`✓`:`—`;if(typeof t==`number`){if(t>0xe8d4a51000&&/(_at$|_date$|^date_|_time$)/.test(e))try{return new Date(t).toLocaleDateString()}catch{}return t.toLocaleString()}let n=String(t);if(/^\d{4}-\d{2}-\d{2}T\d{2}/.test(n))try{return new Date(n).toLocaleString()}catch{}return n}var T=/^[A-Za-z0-9_-]{15,}$/;function bt(e,t,n=6){if(!e||typeof e!=`object`||Array.isArray(e))return[];let r=[];for(let[i,a]of Object.entries(e)){if(S.has(i)||a==null||typeof a==`object`||String(a).trim()===``)continue;let e=t?.[i];if(!(!e&&typeof a==`string`&&T.test(a.trim())&&!/^\d+$/.test(a.trim()))&&(r.push([C(i),e??w(i,a)]),r.length>=n))break}return r}function xt(){let{t:e,language:i}=Se(),{user:a}=re(),te=ee(),{appName:ct}=r(),[h,pt]=n(),x=(0,m.useMemo)(()=>lt(a),[a]),S=(0,m.useCallback)((t,n,r)=>String(e(`approvalsInbox.${t}`,{defaultValue:n,...r})),[e]),C=(0,m.useCallback)(e=>{if(!e)return`—`;let t=Date.parse(e);if(Number.isNaN(t))return e;let n=Math.round((Date.now()-t)/1e3);if(n<45)return S(`justNow`,`just now`);let r=Math.round(n/60);if(r<60)return S(`minutesAgo`,`{{count}}m ago`,{count:r});let a=Math.round(r/60);if(a<24)return S(`hoursAgo`,`{{count}}h ago`,{count:a});let ee=Math.round(a/24);if(ee<30)return S(`daysAgo`,`{{count}}d ago`,{count:ee});try{return new Date(e).toLocaleDateString(i)}catch{return e}},[S,i]),w=(0,m.useCallback)(e=>{switch(e){case`pending`:return S(`statusPending`,`Pending`);case`approved`:return S(`statusApproved`,`Approved`);case`rejected`:return S(`statusRejected`,`Rejected`);case`recalled`:return S(`statusRecalled`,`Recalled`);case`returned`:return S(`statusReturned`,`Returned for revision`);default:return e}},[S]),T=(0,m.useCallback)((e,t)=>{let n=e?.code??``,r=e?.status??0;return n===`NOT_IMPLEMENTED`||r===501?S(`recallUnavailable`,`Recall is not available on this deployment.`):n===`THROTTLED`||r===429?S(`remindThrottled`,`A reminder was sent recently — try again later.`):r===404?S(`requestGone`,`This request no longer exists. Refresh the list.`):n===`FORBIDDEN`||r===403?S(`notAllowed`,`You are not allowed to perform this action.`):n===`INVALID_STATE`||r===409?S(`alreadyDecided`,`This request was already decided. Refresh the list.`):e?.message||t},[S]);function xt({status:e}){return(0,_.jsx)(u,{variant:`outline`,className:s(`font-medium`,dt[e]??``),children:w(e)})}let St=(0,m.useCallback)(e=>`/apps/${ct||`setup`}/${encodeURIComponent(e.object_name)}/record/${encodeURIComponent(e.record_id)}`,[ct]),[E,Ct]=(0,m.useState)(`pending`),[D,wt]=(0,m.useState)([]),[Tt,Et]=(0,m.useState)(!1),[Dt,Ot]=(0,m.useState)(!1),[kt,O]=(0,m.useState)(null),[At,jt]=(0,m.useState)(null),[Mt,Nt]=(0,m.useState)(0),[k,Pt]=(0,m.useState)(null),[A,j]=(0,m.useState)(null),[Ft,M]=(0,m.useState)([]),[It,Lt]=(0,m.useState)(!1),[Rt,N]=(0,m.useState)(``),[P,zt]=(0,m.useState)(``),[Bt,Vt]=(0,m.useState)(null),[Ht,F]=(0,m.useState)([]),[Ut,I]=(0,m.useState)(null),L=(0,m.useMemo)(()=>ne(),[]),Wt=(0,m.useMemo)(()=>be({baseUrl:``.replace(/\/$/,``),scope:`attachments`,fetchImpl:L}),[L]),Gt=(0,m.useCallback)(async e=>{I(null);for(let t of Array.from(e))try{let e=await Wt.upload(t),n=String(e.meta?.fileId??``);if(!n)throw Error(`upload returned no fileId`);F(t=>[...t,{id:n,name:e.name,size:e.size,type:e.mimeType,url:e.url}])}catch(e){I(e?.message??String(e))}},[Wt]),Kt=(0,m.useCallback)(e=>{F(t=>t.filter(t=>t.id!==e))},[]),[qt,Jt]=(0,m.useState)({});(0,m.useEffect)(()=>{let e=new Set;for(let t of Ft)for(let n of t.attachments??[])n&&qt[n]===void 0&&e.add(n);if(!e.size)return;let t=``.replace(/\/$/,``),n=!1;return(async()=>{let r={};await Promise.all(Array.from(e).map(async e=>{try{let n=await L(`${t}/api/v1/data/sys_file/${encodeURIComponent(e)}`);if(!n.ok){r[e]=``;return}let i=await n.json().catch(()=>null);r[e]=String(i?.record?.name??i?.data?.name??i?.name??``)}catch{r[e]=``}})),n||Jt(e=>({...e,...r}))})(),()=>{n=!0}},[Ft,L]);let Yt=(0,m.useCallback)(async e=>{try{let t=``.replace(/\/$/,``),n=await L(`${t}/api/v1/storage/files/${encodeURIComponent(e)}/url`);if(!n.ok)throw Error(`HTTP_${n.status}`);let r=await n.json().catch(()=>null),i=r?.data?.url??r?.url;i&&window.open(i,`_blank`,`noopener`)}catch{}},[L]),[R,Xt]=(0,m.useState)(``),[z,Zt]=(0,m.useState)(``),[B,Qt]=(0,m.useState)(`all`),[V,$t]=(0,m.useState)(`all`),[H,en]=(0,m.useState)(`all`),[U,tn]=(0,m.useState)(new Set),[nn,rn]=(0,m.useState)(!1),[W,an]=(0,m.useState)(null),[on,sn]=(0,m.useState)(null),[G,cn]=(0,m.useState)(``),[ln,un]=(0,m.useState)(!1),[dn,fn]=(0,m.useState)(-1);(0,m.useEffect)(()=>{if(E===`pending`)return;let e=window.setTimeout(()=>Zt(R),350);return()=>window.clearTimeout(e)},[R,E]);let K=(0,m.useCallback)(async()=>{Et(!0),jt(null);try{let e=[];if(E===`pending`)e=x.length?(await g.listRequests({status:`pending`,approverId:x})).data:[],Nt(e.length),O(null);else{let t={q:z||void 0,status:H===`all`?void 0:H,limit:ut,offset:0};if(E===`submitted`){let n=a?.id;if(n){let r=await g.listRequests({submitterId:n,...t});e=r.data,O(r.total??r.data.length)}else e=[],O(0)}else{let n=await g.listRequests(t);e=n.data,O(n.total??n.data.length)}x.length&&g.listRequests({status:`pending`,approverId:x}).then(e=>Nt(e.data.length)).catch(()=>{})}e.sort((e,t)=>(b(t)||``).localeCompare(b(e)||``)),wt(e)}catch(e){jt(e?.message||String(e)),wt([])}finally{Et(!1)}},[E,x,a?.id,z,H]);(0,m.useEffect)(()=>{K()},[K]);let pn=(0,m.useCallback)(async()=>{if(!(E===`pending`||Dt)){Ot(!0);try{let e=await g.listRequests({submitterId:E===`submitted`?a?.id??void 0:void 0,q:z||void 0,status:H===`all`?void 0:H,limit:ut,offset:D.length});wt(t=>{let n=new Set(t.map(e=>e.id));return[...t,...e.data.filter(e=>!n.has(e.id))]}),e.total!=null&&O(e.total)}catch(e){p.error(T(e,S(`loadFailed`,`Failed to load request`)))}finally{Ot(!1)}}},[E,Dt,a?.id,z,H,D.length,T,S]),q=(0,m.useCallback)(async e=>{Pt(e),Lt(!0),N(``),zt(``),F([]),I(null);try{let[t,n]=await Promise.all([g.getRequest(e),g.listActions(e)]);j(t.data),M(n.data)}catch(e){p.error(T(e,S(`loadFailed`,`Failed to load request`))),j(null),M([])}finally{Lt(!1)}},[T,S]),mn=()=>{Pt(null),j(null),M([]),N(``),zt(``),F([]),I(null)};(0,m.useEffect)(()=>{let e=h.get(`request`);e&&(pt(e=>{let t=new URLSearchParams(e);return t.delete(`request`),t},{replace:!0}),q(e))},[h]);let hn=(0,m.useCallback)(e=>{if(P.trim())return P.trim();if(!e)return a?.id||``;let t=new Set(e.pending_approvers||[]);for(let e of x)if(t.has(e))return e;return a?.id||``},[P,x,a?.id]),J=(0,m.useCallback)(()=>{x.length&&g.listRequests({status:`pending`,approverId:x}).then(e=>Nt(e.data.length)).catch(()=>{})},[x]),gn=(0,m.useCallback)(async e=>{if(!A)return;let t=e===`recall`&&a?.id||hn(A);if(!t){p.error(S(`noActor`,`Cannot determine the acting identity`));return}Vt(e);try{let n={actor_id:t,comment:Rt.trim()||void 0,...e!==`recall`&&Ht.length?{attachments:Ht.map(e=>e.id)}:{}},r=await(e===`approve`?g.approve:e===`reject`?g.reject:g.recall)(A.id,n);if(p.success(e===`approve`?r.finalized?S(`approvedFinal`,`Approved`):S(`approvedWaiting`,`Approved — waiting on the remaining approvers`):e===`reject`?S(`rejectedToast`,`Rejected`):S(`recalledToast`,`Request recalled`)),N(``),F([]),I(null),e!==`recall`&&E===`pending`){let e=An.current,t=e.findIndex(e=>e.id===A.id),n=e[t+1]??e[t-1];K(),n&&n.id!==A.id?q(n.id):mn();return}let[i,a]=await Promise.all([g.getRequest(A.id),g.listActions(A.id)]);j(i.data),M(a.data),K()}catch(e){p.error(T(e,S(`actionFailed`,`Action failed`)))}finally{Vt(null)}},[A,hn,Rt,Ht,K,a?.id,T,S,E,q]),_n=(0,m.useCallback)(async e=>{let[t,n]=await Promise.all([g.getRequest(e),g.listActions(e)]);j(t.data),M(n.data),K()},[K]),vn=(0,m.useCallback)(async()=>{if(!(!A||!G.trim())){un(!0);try{await g.comment(A.id,{actor_id:a?.id,comment:G.trim()}),cn(``),await _n(A.id)}catch(e){p.error(T(e,S(`actionFailed`,`Action failed`)))}finally{un(!1)}}},[A,G,a?.id,_n,T,S]),yn=(0,m.useMemo)(()=>{if(!A||A.status!==`pending`)return!1;let e=new Set(A.pending_approvers||[]);return x.some(t=>e.has(t))||P.trim().length>0},[A,x,P]),bn=(0,m.useMemo)(()=>!A||A.status!==`pending`?!1:A.submitter_id===a?.id||P.trim().length>0,[A,a?.id,P]),xn=(0,m.useMemo)(()=>!A||A.status!==`returned`?!1:A.submitter_id===a?.id||P.trim().length>0,[A,a?.id,P]),Sn=(0,m.useMemo)(()=>{let e=new Set;for(let t of D)e.add(y(t));return Array.from(e).sort()},[D]),Cn=(0,m.useMemo)(()=>{let e=new Set;for(let t of D)t.object_name&&e.add(t.object_name);return Array.from(e).sort()},[D]),Y=(0,m.useMemo)(()=>{let e=R.trim().toLowerCase();return D.filter(t=>B!==`all`&&y(t)!==B||V!==`all`&&t.object_name!==V||H!==`all`&&t.status!==H?!1:E!==`pending`||!e||[t.process_name,t.process_label,t.step_label,t.object_name,t.record_id,t.record_title,t.submitter_id,t.submitter_name,...t.pending_approvers||[]].filter(Boolean).join(` `).toLowerCase().includes(e))},[D,R,B,V,H,E]),X=(0,m.useMemo)(()=>k?Y.findIndex(e=>e.id===k):-1,[Y,k]);(0,m.useEffect)(()=>{if(U.size===0)return;let e=new Set(Y.map(e=>e.id)),t=!1,n=new Set;for(let r of U)e.has(r)?n.add(r):t=!0;t&&tn(n)},[Y,U]),(0,m.useEffect)(()=>{dn>=Y.length&&fn(Y.length-1)},[Y.length,dn]);let Z=(0,m.useCallback)(e=>{if(e.status!==`pending`)return!1;let t=new Set(x);return(e.pending_approvers||[]).some(e=>t.has(e))},[x]),Q=(0,m.useMemo)(()=>Y.filter(e=>U.has(e.id)&&Z(e)),[Y,U,Z]),$=Y.filter(e=>e.status===`pending`),wn=$.length>0&&$.every(e=>U.has(e.id)),Tn=(0,m.useCallback)(()=>{tn(e=>{if(wn)return new Set;let t=new Set(e);for(let e of $)t.add(e.id);return t})},[wn,$]),En=(0,m.useCallback)(e=>{tn(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),Dn=(0,m.useCallback)(async e=>{let t=Q;if(t.length===0)return;rn(!0);let n=0,r=[];for(let i of t){let t=new Set(i.pending_approvers||[]),ee=x.find(e=>t.has(e))||a?.id||``;try{await(e===`approve`?g.approve:g.reject)(i.id,{actor_id:ee}),n++}catch{r.push(i.record_title||v(i.record_id))}}if(rn(!1),tn(new Set),r.length===0)p.success(e===`approve`?S(`bulkApproved`,`Approved {{count}} requests`,{count:n}):S(`bulkRejected`,`Rejected {{count}} requests`,{count:n}));else{let e=r.slice(0,3).join(`, `);p.error(S(`bulkPartial`,`{{ok}} succeeded, {{fail}} failed: {{which}}`,{ok:n,fail:r.length,which:e+(r.length>3?`…`:``)}))}K(),J()},[Q,x,a?.id,K,J,S]),On=(0,m.useCallback)(async e=>{if(!Z(e)||on)return;let t=new Set(e.pending_approvers||[]),n=x.find(e=>t.has(e))||a?.id||``;sn(e.id);try{let t=await g.approve(e.id,{actor_id:n});p.success(t.finalized?S(`inlineApproved`,`Approved "{{title}}"`,{title:e.record_title||v(e.record_id)}):S(`approvedWaiting`,`Approved — waiting on the remaining approvers`)),K(),J()}catch(e){p.error(T(e,S(`actionFailed`,`Action failed`)))}finally{sn(null)}},[Z,on,x,a?.id,K,J,T,S]),kn=(0,m.useCallback)(async()=>{let e=W;if(!e)return;let t=new Set(e.pending_approvers||[]),n=x.find(e=>t.has(e))||a?.id||``;sn(e.id),an(null);try{await g.reject(e.id,{actor_id:n}),p.success(S(`inlineRejected`,`Rejected "{{title}}"`,{title:e.record_title||v(e.record_id)})),K(),J()}catch(e){p.error(T(e,S(`actionFailed`,`Action failed`)))}finally{sn(null)}},[W,x,a?.id,K,J,T,S]),An=(0,m.useRef)(Y);An.current=Y;let jn=(0,m.useRef)(dn);jn.current=dn,(0,m.useEffect)(()=>{let e=e=>{if(k||W)return;let t=e.target,n=t?.tagName;if(n===`INPUT`||n===`TEXTAREA`||n===`SELECT`||t?.isContentEditable||document.querySelector(`[role="alertdialog"]`))return;let r=An.current;if(!r.length)return;let i=jn.current;e.key===`j`||e.key===`ArrowDown`?(e.preventDefault(),fn(Math.min(i+1,r.length-1))):e.key===`k`||e.key===`ArrowUp`?(e.preventDefault(),fn(Math.max(i-1,0))):e.key===`Enter`&&i>=0&&r[i]?(e.preventDefault(),q(r[i].id)):(e.key===`x`||e.key===` `)&&i>=0&&r[i]&&E===`pending`?(e.preventDefault(),En(r[i].id)):e.key===`a`&&i>=0&&r[i]?(e.preventDefault(),On(r[i])):e.key===`r`&&i>=0&&r[i]&&Z(r[i])&&(e.preventDefault(),an(r[i]))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[k,W,E,q,En,On,Z]),(0,m.useEffect)(()=>{if(!k)return;let e=e=>{if(e.key!==`ArrowLeft`&&e.key!==`ArrowRight`)return;let t=e.target,n=t?.tagName;if(n===`INPUT`||n===`TEXTAREA`||n===`SELECT`||t?.isContentEditable||document.querySelector(`[role="alertdialog"]`))return;let r=An.current,i=r.findIndex(e=>e.id===k);if(i<0)return;let a=e.key===`ArrowLeft`?r[i-1]:r[i+1];a&&(e.preventDefault(),q(a.id))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[k,q]);let Mn=!!R||B!==`all`||V!==`all`||H!==`all`,Nn=e=>{Ct(e),en(`all`),Qt(`all`),$t(`all`),Xt(``),fn(-1)};function Pn({r:e}){return(0,_.jsxs)(`div`,{className:`min-w-0`,children:[(0,_.jsx)(`div`,{className:`font-medium truncate`,children:y(e)}),(0,_.jsxs)(`div`,{className:`text-xs text-muted-foreground truncate`,children:[mt(e)||`—`,(e.round??1)>1&&(0,_.jsx)(`span`,{className:`ml-1.5 text-violet-600 dark:text-violet-400`,children:S(`roundChip`,`Round {{n}}`,{n:e.round})})]})]})}function Fn({r:e}){return(0,_.jsxs)(`div`,{className:`min-w-0`,children:[(0,_.jsxs)(t,{to:St(e),onClick:e=>e.stopPropagation(),className:`inline-flex items-center gap-1 text-sm hover:underline truncate max-w-full`,title:e.record_id,children:[(0,_.jsx)(`span`,{className:`truncate`,children:e.record_title||v(e.record_id)}),(0,_.jsx)(Ze,{className:`h-3 w-3 shrink-0 text-muted-foreground`})]}),(0,_.jsx)(`div`,{className:`text-xs text-muted-foreground truncate`,children:_t(e)})]})}function In({r:e}){if(!Z(e))return null;let t=on===e.id;return(0,_.jsxs)(`div`,{className:`flex items-center gap-1 opacity-0 group-hover:opacity-100 focus-within:opacity-100 transition-opacity`,onClick:e=>e.stopPropagation(),children:[(0,_.jsx)(c,{size:`sm`,variant:`ghost`,className:`h-7 px-2 text-emerald-700 hover:text-emerald-800 hover:bg-emerald-50 dark:text-emerald-400`,disabled:t,onClick:()=>void On(e),"aria-label":S(`approve`,`Approve`),children:(0,_.jsx)(fe,{className:`h-4 w-4`})}),(0,_.jsx)(c,{size:`sm`,variant:`ghost`,className:`h-7 px-2 text-red-600 hover:text-red-700 hover:bg-red-50 dark:text-red-400`,disabled:t,onClick:()=>an(e),"aria-label":S(`reject`,`Reject`),children:(0,_.jsx)(le,{className:`h-4 w-4`})})]})}return(0,_.jsxs)(`div`,{className:`flex flex-col gap-4 sm:gap-6 p-4 sm:p-6 max-w-6xl`,children:[(0,_.jsxs)(`header`,{className:`flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2`,children:[(0,_.jsxs)(`div`,{children:[(0,_.jsxs)(`h1`,{className:`text-2xl font-semibold flex items-center gap-2`,children:[(0,_.jsx)(Ne,{className:`h-6 w-6`}),S(`title`,`Approvals Inbox`)]}),(0,_.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:S(`subtitle`,`Review and act on approval requests.`)})]}),(0,_.jsxs)(c,{variant:`outline`,size:`sm`,onClick:K,disabled:Tt,className:`self-start sm:self-auto`,children:[(0,_.jsx)(Ee,{className:`h-4 w-4 mr-2 ${Tt?`animate-spin`:``}`}),S(`refresh`,`Refresh`)]})]}),At&&(0,_.jsxs)(Be,{variant:`destructive`,children:[(0,_.jsx)(ve,{className:`h-4 w-4`}),(0,_.jsx)(Ae,{children:At})]}),(0,_.jsxs)(He,{value:E,onValueChange:Nn,children:[(0,_.jsxs)(je,{children:[(0,_.jsxs)(et,{value:`pending`,children:[S(`tabMyPending`,`My Pending`),Mt>0&&(0,_.jsx)(u,{variant:`secondary`,className:`ml-2`,children:Mt})]}),(0,_.jsx)(et,{value:`submitted`,children:S(`tabSubmitted`,`Submitted by me`)}),(0,_.jsx)(et,{value:`all`,children:S(`tabAll`,`All`)})]}),(0,_.jsxs)(Ve,{value:E,className:`mt-4 space-y-3`,children:[!Tt&&(D.length>0||E!==`pending`&&(z||H!==`all`))&&(0,_.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,_.jsxs)(`div`,{className:`relative flex-1 min-w-[200px] max-w-sm`,children:[(0,_.jsx)(pe,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,_.jsx)(Ue,{value:R,onChange:e=>Xt(e.target.value),placeholder:S(`searchPlaceholder`,`Search record, process, requester…`),className:`pl-8 h-8 text-sm`}),R&&(0,_.jsx)(`button`,{type:`button`,onClick:()=>Xt(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground`,"aria-label":S(`clearSearch`,`Clear search`),children:(0,_.jsx)(de,{className:`h-3.5 w-3.5`})})]}),E!==`pending`&&(0,_.jsxs)(ie,{value:H,onValueChange:en,children:[(0,_.jsx)(Ge,{className:`h-8 w-auto min-w-[130px] text-sm`,children:(0,_.jsx)(Ye,{placeholder:S(`statusFilter`,`Status`)})}),(0,_.jsxs)(Le,{children:[(0,_.jsx)(d,{value:`all`,children:S(`allStatuses`,`All statuses`)}),(0,_.jsx)(d,{value:`pending`,children:w(`pending`)}),(0,_.jsx)(d,{value:`approved`,children:w(`approved`)}),(0,_.jsx)(d,{value:`rejected`,children:w(`rejected`)}),(0,_.jsx)(d,{value:`recalled`,children:w(`recalled`)}),(0,_.jsx)(d,{value:`returned`,children:w(`returned`)})]})]}),Sn.length>1&&(0,_.jsxs)(ie,{value:B,onValueChange:Qt,children:[(0,_.jsx)(Ge,{className:`h-8 w-auto min-w-[140px] text-sm`,children:(0,_.jsx)(Ye,{placeholder:S(`processFilter`,`Process`)})}),(0,_.jsxs)(Le,{children:[(0,_.jsx)(d,{value:`all`,children:S(`allProcesses`,`All processes`)}),Sn.map(e=>(0,_.jsx)(d,{value:e,children:e},e))]})]}),Cn.length>1&&(0,_.jsxs)(ie,{value:V,onValueChange:$t,children:[(0,_.jsx)(Ge,{className:`h-8 w-auto min-w-[140px] text-sm`,children:(0,_.jsx)(Ye,{placeholder:S(`objectFilter`,`Object`)})}),(0,_.jsxs)(Le,{children:[(0,_.jsx)(d,{value:`all`,children:S(`allObjects`,`All objects`)}),Cn.map(e=>(0,_.jsx)(d,{value:e,children:e},e))]})]}),Mn&&(0,_.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:S(`filterCount`,`{{shown}} of {{total}}`,{shown:Y.length,total:D.length})})]}),E===`pending`&&U.size>0&&(0,_.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-3 py-2 rounded-md border bg-accent/30 text-sm`,children:[(0,_.jsxs)(`span`,{children:[(0,_.jsx)(`strong`,{children:U.size}),` `,S(`selected`,`selected`),Q.length!==U.size&&(0,_.jsx)(`span`,{className:`text-muted-foreground ml-1`,children:S(`actionableCount`,`({{count}} actionable)`,{count:Q.length})})]}),(0,_.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,_.jsxs)(it,{children:[(0,_.jsx)(se,{asChild:!0,children:(0,_.jsxs)(c,{size:`sm`,disabled:nn||Q.length===0,children:[(0,_.jsx)(fe,{className:`h-3.5 w-3.5 mr-1`}),S(`approveN`,`Approve {{count}}`,{count:Q.length||``})]})}),(0,_.jsxs)(ye,{children:[(0,_.jsxs)(xe,{children:[(0,_.jsx)(ce,{children:S(`bulkApproveTitle`,`Approve {{count}} requests?`,{count:Q.length})}),(0,_.jsx)(ae,{children:S(`bulkApproveBody`,`Each request is approved with your identity and its flow continues down the approve branch.`)})]}),(0,_.jsxs)(tt,{children:[(0,_.jsx)(rt,{children:S(`cancel`,`Cancel`)}),(0,_.jsx)(Pe,{onClick:()=>Dn(`approve`),children:S(`approveN`,`Approve {{count}}`,{count:Q.length})})]})]})]}),(0,_.jsxs)(it,{children:[(0,_.jsx)(se,{asChild:!0,children:(0,_.jsxs)(c,{size:`sm`,variant:`outline`,disabled:nn||Q.length===0,className:`border-destructive text-destructive hover:bg-destructive hover:text-destructive-foreground`,children:[(0,_.jsx)(le,{className:`h-3.5 w-3.5 mr-1`}),S(`rejectN`,`Reject {{count}}`,{count:Q.length||``})]})}),(0,_.jsxs)(ye,{children:[(0,_.jsxs)(xe,{children:[(0,_.jsx)(ce,{children:S(`bulkRejectTitle`,`Reject {{count}} requests?`,{count:Q.length})}),(0,_.jsx)(ae,{children:S(`bulkRejectBody`,`This rejects the selected requests and notifies their submitters.`)})]}),(0,_.jsxs)(tt,{children:[(0,_.jsx)(rt,{children:S(`cancel`,`Cancel`)}),(0,_.jsx)(Pe,{onClick:()=>Dn(`reject`),className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:S(`rejectN`,`Reject {{count}}`,{count:Q.length})})]})]})]}),(0,_.jsx)(c,{size:`sm`,variant:`ghost`,onClick:()=>tn(new Set),disabled:nn,children:S(`clear`,`Clear`)})]})]}),Tt?(0,_.jsxs)(`div`,{className:`space-y-2`,children:[(0,_.jsx)(o,{className:`h-10 w-full`}),(0,_.jsx)(o,{className:`h-10 w-full`}),(0,_.jsx)(o,{className:`h-10 w-full`})]}):D.length===0?(0,_.jsx)(`div`,{className:`flex items-center justify-center min-h-[240px] rounded-md border border-dashed`,children:(0,_.jsxs)(Oe,{children:[(0,_.jsx)(Qe,{children:S(`emptyTitle`,`No requests`)}),(0,_.jsx)(ge,{children:E===`pending`?S(`emptyPending`,`You're all caught up — nothing is waiting on you.`):S(`emptyOther`,`Nothing here yet.`)}),E===`pending`&&(0,_.jsx)(c,{variant:`link`,size:`sm`,className:`mt-1`,onClick:()=>Nn(`all`),children:S(`emptyViewAll`,`Browse all requests`)})]})}):Y.length===0?(0,_.jsx)(`div`,{className:`flex items-center justify-center min-h-[160px] rounded-md border border-dashed text-sm text-muted-foreground`,children:S(`noMatches`,`No matches for current filters.`)}):(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)(Ke,{className:`hidden md:block`,children:(0,_.jsx)(Xe,{className:`p-0`,children:(0,_.jsxs)(at,{children:[(0,_.jsx)(oe,{children:(0,_.jsxs)(nt,{children:[E===`pending`&&(0,_.jsx)(l,{className:`w-10`,children:(0,_.jsx)(Me,{checked:wn,onCheckedChange:Tn,"aria-label":S(`selectAll`,`Select all`),disabled:$.length===0})}),(0,_.jsx)(l,{children:S(`colRequest`,`Request`)}),(0,_.jsx)(l,{children:S(`colRecord`,`Record`)}),(0,_.jsx)(l,{children:S(`colRequester`,`Requester`)}),(0,_.jsx)(l,{children:S(`colStatus`,`Status`)}),(0,_.jsx)(l,{children:S(`colWaiting`,`Submitted`)}),(0,_.jsx)(l,{className:`w-20`,"aria-label":S(`colActions`,`Actions`)})]})}),(0,_.jsx)(Ie,{children:Y.map((e,t)=>(0,_.jsxs)(nt,{className:s(`group cursor-pointer hover:bg-accent/50`,dn===t&&`ring-2 ring-inset ring-ring bg-accent/30`),onClick:()=>{fn(t),q(e.id)},children:[E===`pending`&&(0,_.jsx)(f,{className:`w-10`,onClick:e=>e.stopPropagation(),children:(0,_.jsx)(Me,{checked:U.has(e.id),onCheckedChange:()=>En(e.id),disabled:e.status!==`pending`,"aria-label":S(`selectRow`,`Select request`)})}),(0,_.jsx)(f,{children:(0,_.jsx)(Pn,{r:e})}),(0,_.jsx)(f,{children:(0,_.jsx)(Fn,{r:e})}),(0,_.jsx)(f,{children:(0,_.jsxs)(`div`,{className:`flex items-center gap-1.5 text-sm`,children:[(0,_.jsx)(Ce,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}),(0,_.jsx)(`span`,{className:`truncate`,title:e.submitter_id||``,children:ht(e)})]})}),(0,_.jsx)(f,{children:(0,_.jsx)(xt,{status:e.status})}),(0,_.jsxs)(f,{className:s(`text-xs whitespace-nowrap`,vt(e)),title:ft(b(e)),children:[(0,_.jsx)(Fe,{className:`h-3 w-3 inline mr-1`}),C(b(e)),e.status===`pending`&&e.sla_due_at&&(0,_.jsx)(`div`,{className:s(`mt-0.5 text-[10px] font-medium`,Date.parse(e.sla_due_at)<Date.now()?`text-red-600 dark:text-red-400`:`text-muted-foreground`),children:Date.parse(e.sla_due_at)<Date.now()?S(`slaOverdue`,`SLA overdue {{dur}}`,{dur:yt(Date.now()-Date.parse(e.sla_due_at))}):S(`slaRemaining`,`SLA {{dur}} left`,{dur:yt(Date.parse(e.sla_due_at)-Date.now())})})]}),(0,_.jsx)(f,{className:`w-20`,children:(0,_.jsx)(In,{r:e})})]},e.id))})]})})}),(0,_.jsx)(`div`,{className:`md:hidden space-y-2`,children:Y.map(e=>(0,_.jsx)(Ke,{className:`cursor-pointer active:bg-accent/50`,onClick:()=>void q(e.id),children:(0,_.jsxs)(Xe,{className:`p-3 space-y-1.5`,children:[(0,_.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,_.jsx)(`div`,{className:`font-medium text-sm truncate`,children:y(e)}),(0,_.jsx)(xt,{status:e.status})]}),(0,_.jsxs)(`div`,{className:`text-sm truncate`,children:[e.record_title||v(e.record_id),(0,_.jsx)(`span`,{className:`text-muted-foreground text-xs ml-1.5`,children:_t(e)})]}),(0,_.jsxs)(`div`,{className:`flex items-center justify-between text-xs text-muted-foreground`,children:[(0,_.jsxs)(`span`,{className:`inline-flex items-center gap-1 truncate`,children:[(0,_.jsx)(Ce,{className:`h-3 w-3`}),ht(e)]}),(0,_.jsxs)(`span`,{className:s(`inline-flex items-center gap-1 whitespace-nowrap`,vt(e)),children:[(0,_.jsx)(Fe,{className:`h-3 w-3`}),C(b(e))]})]}),Z(e)&&(0,_.jsxs)(`div`,{className:`flex gap-2 pt-1`,onClick:e=>e.stopPropagation(),children:[(0,_.jsxs)(c,{size:`sm`,className:`h-7 flex-1`,disabled:on===e.id,onClick:()=>void On(e),children:[(0,_.jsx)(fe,{className:`h-3.5 w-3.5 mr-1`}),S(`approve`,`Approve`)]}),(0,_.jsxs)(c,{size:`sm`,variant:`outline`,className:`h-7 flex-1 border-destructive text-destructive`,disabled:on===e.id,onClick:()=>an(e),children:[(0,_.jsx)(le,{className:`h-3.5 w-3.5 mr-1`}),S(`reject`,`Reject`)]})]})]})},e.id))}),E!==`pending`&&kt!=null&&(0,_.jsxs)(`div`,{className:`flex items-center justify-center gap-3 py-1`,children:[(0,_.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:S(`loadedOf`,`Loaded {{loaded}} of {{total}}`,{loaded:D.length,total:kt})}),D.length<kt&&(0,_.jsx)(c,{size:`sm`,variant:`outline`,disabled:Dt,onClick:()=>void pn(),children:Dt?S(`loadingMore`,`Loading…`):S(`loadMore`,`Load more`)})]}),(0,_.jsx)(`div`,{className:`hidden md:block text-[11px] text-muted-foreground`,children:S(`keyboardHint`,`Keyboard: j/k move · Enter open · x select · a approve · r reject`)})]})]})]}),(0,_.jsx)(it,{open:!!W,onOpenChange:e=>!e&&an(null),children:(0,_.jsxs)(ye,{children:[(0,_.jsxs)(xe,{children:[(0,_.jsx)(ce,{children:S(`rejectOneTitle`,`Reject "{{title}}"?`,{title:W?W.record_title||v(W.record_id):``})}),(0,_.jsx)(ae,{children:S(`rejectOneBody`,`This rejects the request and notifies the submitter.`)})]}),(0,_.jsxs)(tt,{children:[(0,_.jsx)(rt,{children:S(`cancel`,`Cancel`)}),(0,_.jsx)(Pe,{onClick:()=>void kn(),className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:S(`reject`,`Reject`)})]})]})}),(0,_.jsx)(Je,{open:!!k,onOpenChange:e=>!e&&mn(),children:(0,_.jsxs)(me,{className:`w-full sm:max-w-xl overflow-y-auto`,children:[(0,_.jsxs)(Te,{children:[(0,_.jsx)(ke,{children:A?y(A):S(`drawerTitle`,`Approval Request`)}),(0,_.jsx)(De,{children:A?mt(A)||_t(A):``})]}),A&&X>=0&&Y.length>1&&(0,_.jsxs)(`div`,{className:`flex items-center justify-between mt-2 text-xs text-muted-foreground`,children:[(0,_.jsxs)(c,{variant:`ghost`,size:`sm`,className:`h-7 px-2`,disabled:X<=0,onClick:()=>{let e=Y[X-1];e&&q(e.id)},children:[(0,_.jsx)(he,{className:`h-4 w-4 mr-0.5`}),S(`prevRequest`,`Previous`)]}),(0,_.jsx)(`span`,{children:S(`positionOf`,`{{index}} of {{total}}`,{index:X+1,total:Y.length})}),(0,_.jsxs)(c,{variant:`ghost`,size:`sm`,className:`h-7 px-2`,disabled:X>=Y.length-1,onClick:()=>{let e=Y[X+1];e&&q(e.id)},children:[S(`nextRequest`,`Next`),(0,_.jsx)(we,{className:`h-4 w-4 ml-0.5`})]})]}),It?(0,_.jsxs)(`div`,{className:`space-y-2 mt-6`,children:[(0,_.jsx)(o,{className:`h-6 w-3/4`}),(0,_.jsx)(o,{className:`h-6 w-1/2`}),(0,_.jsx)(o,{className:`h-20 w-full`})]}):A?(0,_.jsxs)(`div`,{className:`space-y-4 mt-6`,children:[(0,_.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-xs text-muted-foreground`,children:[(0,_.jsx)(xt,{status:A.status}),(A.round??1)>1&&(0,_.jsx)(u,{variant:`outline`,className:`text-[10px] border-violet-200 text-violet-700 dark:border-violet-500/30 dark:text-violet-400`,children:S(`roundChip`,`Round {{n}}`,{n:A.round})}),(0,_.jsxs)(`span`,{className:`inline-flex items-center gap-1`,title:ft(b(A)),children:[(0,_.jsx)(Fe,{className:`h-3 w-3`}),S(`submittedAgo`,`Submitted {{when}}`,{when:C(b(A))})]}),A.completed_at&&(0,_.jsxs)(`span`,{children:[`· `,S(`completedAt`,`Completed {{when}}`,{when:C(A.completed_at)})]}),A.status===`pending`&&A.sla_due_at&&(0,_.jsx)(u,{variant:`outline`,className:s(`text-[10px]`,Date.parse(A.sla_due_at)<Date.now()?`border-red-200 bg-red-50 text-red-700 dark:border-red-500/30 dark:bg-red-500/10 dark:text-red-400`:`border-border text-muted-foreground`),children:Date.parse(A.sla_due_at)<Date.now()?S(`slaOverdue`,`SLA overdue {{dur}}`,{dur:yt(Date.now()-Date.parse(A.sla_due_at))}):S(`slaRemaining`,`SLA {{dur}} left`,{dur:yt(Date.parse(A.sla_due_at)-Date.now())})})]}),(0,_.jsx)(Ke,{children:(0,_.jsxs)(Xe,{className:`p-4 space-y-3`,children:[(0,_.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,_.jsxs)(`div`,{className:`min-w-0`,children:[(0,_.jsxs)(t,{to:St(A),className:`text-base font-semibold hover:underline inline-flex items-center gap-1.5`,children:[(0,_.jsx)(`span`,{className:`truncate`,children:A.record_title||v(A.record_id)}),(0,_.jsx)(Ze,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`})]}),(0,_.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:_t(A)})]}),(0,_.jsx)(`div`,{className:`text-right text-xs text-muted-foreground shrink-0`,children:(0,_.jsxs)(`div`,{className:`inline-flex items-center gap-1`,children:[(0,_.jsx)(Ce,{className:`h-3 w-3`}),(0,_.jsx)(`span`,{title:A.submitter_id||``,children:ht(A)})]})})]}),bt(A.payload,A.payload_display).length>0&&(0,_.jsx)(`div`,{className:`grid grid-cols-2 gap-x-4 gap-y-2 text-sm border-t pt-3`,children:bt(A.payload,A.payload_display).map(([e,t])=>(0,_.jsxs)(`div`,{className:`min-w-0`,children:[(0,_.jsx)(`div`,{className:`text-[11px] text-muted-foreground`,children:e}),(0,_.jsx)(`div`,{className:`truncate`,title:t,children:t})]},e))}),A.decision_progress&&(0,_.jsxs)(`div`,{className:`border-t pt-3`,children:[(0,_.jsx)(`div`,{className:`text-[11px] text-muted-foreground mb-1`,children:A.decision_progress.behavior===`per_group`?S(`progressGroups`,`Sign-off progress — {{got}} of {{need}} groups`,{got:A.decision_progress.got,need:A.decision_progress.need}):S(`progressApprovals`,`Approvals — {{got}} of {{need}}`,{got:A.decision_progress.got,need:A.decision_progress.need})}),A.decision_progress.groups&&(0,_.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:A.decision_progress.groups.map(e=>(0,_.jsxs)(u,{variant:`outline`,className:s(`text-[11px] gap-1`,e.satisfied?`border-emerald-300 text-emerald-700 dark:border-emerald-700 dark:text-emerald-400`:`text-muted-foreground`),title:`${e.got}/${e.need}`,children:[e.satisfied?(0,_.jsx)(qe,{className:`h-3 w-3`}):null,e.group,` `,e.got,`/`,e.need]},e.group))})]}),A.status===`pending`&&(A.pending_approvers||[]).length>0&&(0,_.jsxs)(`div`,{className:`border-t pt-3`,children:[(0,_.jsx)(`div`,{className:`text-[11px] text-muted-foreground mb-1`,children:S(`waitingOn`,`Waiting on`)}),(0,_.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:(A.pending_approvers||[]).map((e,t)=>(0,_.jsx)(u,{variant:`outline`,className:`text-[11px]`,title:e,children:gt(e,A)},t))})]})]})}),(A.flow_steps?.length??0)>1&&(0,_.jsx)(`div`,{className:`flex items-center px-1`,"aria-label":S(`stepProgress`,`Approval steps`),children:A.flow_steps.map((e,t)=>(0,_.jsxs)(m.Fragment,{children:[t>0&&(0,_.jsx)(`div`,{className:s(`h-px flex-1 mx-2`,e.state===`done`||e.state===`current`?`bg-emerald-300 dark:bg-emerald-700`:`bg-border`)}),(0,_.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0`,children:[(0,_.jsx)(`span`,{className:s(`flex items-center justify-center h-5 w-5 rounded-full text-[10px] font-semibold`,e.state===`done`&&`bg-emerald-500 text-white`,e.state===`current`&&`bg-amber-500 text-white ring-2 ring-amber-200 dark:ring-amber-500/30`,e.state===`upcoming`&&`bg-muted text-muted-foreground border`),children:e.state===`done`?(0,_.jsx)(qe,{className:`h-3 w-3`}):t+1}),(0,_.jsx)(`span`,{className:s(`text-xs`,e.state===`current`?`font-medium`:`text-muted-foreground`),children:e.label})]})]},e.id))}),(0,_.jsxs)(`div`,{children:[(0,_.jsx)(`h3`,{className:`text-sm font-semibold mb-3`,children:S(`history`,`Activity`)}),Ft.length===0?(0,_.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:S(`noActions`,`No actions yet.`)}):(0,_.jsx)(`ol`,{className:`relative space-y-3 pl-5 before:absolute before:left-[7px] before:top-1 before:bottom-1 before:w-px before:bg-border`,children:Ft.map(e=>{let t=e.action===`approve`?`bg-emerald-500`:e.action===`reject`?`bg-destructive`:e.action===`submit`?`bg-blue-500`:e.action===`reassign`?`bg-indigo-500`:e.action===`remind`||e.action===`request_info`?`bg-amber-500`:e.action===`comment`?`bg-slate-400`:e.action===`escalate`?`bg-red-500`:e.action===`revise`?`bg-violet-500`:e.action===`resubmit`?`bg-blue-500`:`bg-muted-foreground`,n=e.actor_id===`system:sla`?S(`systemSlaActor`,`System (SLA)`):e.actor_name??(e.actor_id&&e.actor_id===A.submitter_id?ht(A):v(e.actor_id)),r=e.action===`submit`?S(`actSubmit`,`Submitted`):e.action===`approve`?S(`actApprove`,`Approved`):e.action===`reject`?S(`actReject`,`Rejected`):e.action===`recall`?S(`actRecall`,`Recalled`):e.action===`reassign`?S(`actReassign`,`Reassigned`):e.action===`remind`?S(`actRemind`,`Reminder sent`):e.action===`request_info`?S(`actRequestInfo`,`Requested more info`):e.action===`comment`?S(`actComment`,`Commented`):e.action===`escalate`?S(`actEscalate`,`SLA escalated`):e.action===`revise`?S(`actRevise`,`Sent back for revision`):e.action===`resubmit`?S(`actResubmit`,`Resubmitted`):e.action;return(0,_.jsxs)(`li`,{className:`relative text-xs`,children:[(0,_.jsx)(`span`,{className:`absolute -left-[18px] top-1 h-3 w-3 rounded-full ring-2 ring-background ${t}`,"aria-hidden":!0}),(0,_.jsxs)(`div`,{className:`flex items-baseline gap-1.5 flex-wrap`,children:[(0,_.jsx)(`span`,{className:`font-medium`,children:r}),(0,_.jsx)(`span`,{className:`text-muted-foreground`,children:`·`}),(0,_.jsx)(`span`,{title:e.actor_id||``,children:n}),(0,_.jsx)(`span`,{className:`ml-auto text-muted-foreground text-[10px]`,title:ft(e.created_at),children:C(e.created_at)})]}),e.comment&&(0,_.jsxs)(`div`,{className:`text-muted-foreground italic mt-0.5`,children:[`"`,e.comment,`"`]}),Array.isArray(e.attachments)&&e.attachments.length>0&&(0,_.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mt-1`,children:e.attachments.map((t,n)=>(0,_.jsxs)(`button`,{type:`button`,onClick:()=>void Yt(t),className:`inline-flex items-center gap-1 text-[11px] px-2 py-0.5 rounded-full border text-muted-foreground hover:text-foreground hover:bg-accent transition-colors`,title:t,children:[(0,_.jsx)(Re,{className:`h-3 w-3`}),qt[t]||`${S(`attachmentChip`,`Attachment`)}${e.attachments.length>1?` ${n+1}`:``}`]},t))})]},e.id)})}),A.status===`pending`&&(yn||bn)&&(0,_.jsxs)(`div`,{className:`flex items-center gap-2 mt-3`,children:[(0,_.jsx)(Ue,{value:G,onChange:e=>cn(e.target.value),onKeyDown:e=>{e.key===`Enter`&&G.trim()&&(e.preventDefault(),vn())},placeholder:S(`replyPlaceholder`,`Reply on this request…`),className:`h-8 text-sm`}),(0,_.jsx)(c,{size:`sm`,variant:`outline`,className:`h-8 px-2 shrink-0`,disabled:!G.trim()||ln,onClick:()=>void vn(),children:(0,_.jsx)(ue,{className:`h-3.5 w-3.5`})})]})]}),A.payload!=null&&(0,_.jsxs)(`details`,{className:`group`,children:[(0,_.jsx)(`summary`,{className:`cursor-pointer text-xs text-muted-foreground hover:text-foreground select-none`,children:S(`rawData`,`Raw data (JSON)`)}),(0,_.jsxs)(`div`,{className:`mt-2`,children:[(0,_.jsx)(`div`,{className:`flex justify-end`,children:(0,_.jsxs)(`button`,{type:`button`,onClick:async()=>{try{await navigator.clipboard.writeText(JSON.stringify(A.payload,null,2)),p.success(S(`copied`,`Copied`))}catch{p.error(S(`copyFailed`,`Copy failed`))}},className:`text-[10px] text-muted-foreground hover:text-foreground inline-flex items-center gap-1`,children:[(0,_.jsx)(ze,{className:`h-3 w-3`}),S(`copy`,`Copy`)]})}),(0,_.jsx)(`pre`,{className:`text-[11px] bg-muted/50 rounded p-2 overflow-auto max-h-48 mt-1`,children:JSON.stringify(A.payload,null,2)})]})]}),A.status===`pending`&&(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)(_e,{}),(0,_.jsxs)(`div`,{className:`space-y-3`,children:[te&&(0,_.jsxs)(`details`,{className:`group`,children:[(0,_.jsx)(`summary`,{className:`cursor-pointer text-xs text-muted-foreground hover:text-foreground select-none`,children:S(`overrideActor`,`Act as another identity (admin)`)}),(0,_.jsxs)(`div`,{className:`mt-2`,children:[(0,_.jsx)($e,{htmlFor:`actor-override`,className:`text-xs`,children:S(`actor`,`Actor`)}),(0,_.jsx)(`input`,{id:`actor-override`,type:`text`,value:P,onChange:e=>zt(e.target.value),placeholder:`${S(`auto`,`Auto`)}: ${hn(A)||`—`}`,className:`w-full mt-1 px-3 py-2 text-sm border rounded-md bg-background`}),(0,_.jsx)(`div`,{className:`text-[10px] text-muted-foreground mt-1`,children:S(`overrideHint`,`e.g. role:sales_manager. Leave blank to use the auto-detected identity.`)})]})]}),(0,_.jsxs)(`div`,{children:[(0,_.jsx)($e,{htmlFor:`comment`,className:`text-xs`,children:S(`comment`,`Comment (optional)`)}),(0,_.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mt-1.5`,children:[S(`quickPhrase1`,`Approved — meets requirements.`),S(`quickPhrase2`,`Approved with conditions — please monitor execution.`),S(`quickPhrase3`,`Please add supporting material and resubmit.`)].map(e=>(0,_.jsx)(`button`,{type:`button`,onClick:()=>N(e),className:`text-[11px] px-2 py-0.5 rounded-full border text-muted-foreground hover:text-foreground hover:bg-accent transition-colors`,children:e},e))}),(0,_.jsx)(We,{id:`comment`,value:Rt,onChange:e=>N(e.target.value),rows:2,className:`mt-1`}),(0,_.jsx)(st,{className:`mt-2`,attachments:Ht,onUpload:Gt,onRemove:Kt}),Ut&&(0,_.jsx)(`div`,{className:`text-xs text-destructive mt-1`,children:Ut})]}),(0,_.jsxs)(`div`,{className:`flex gap-2 flex-wrap`,children:[(0,_.jsxs)(c,{size:`sm`,onClick:()=>gn(`approve`),disabled:!yn||Bt!==null,children:[(0,_.jsx)(fe,{className:`h-4 w-4 mr-1`}),Bt===`approve`?S(`approving`,`Approving…`):S(`approve`,`Approve`)]}),(0,_.jsxs)(it,{children:[(0,_.jsx)(se,{asChild:!0,children:(0,_.jsxs)(c,{size:`sm`,variant:`outline`,disabled:!yn||Bt!==null,className:`border-destructive text-destructive hover:bg-destructive hover:text-destructive-foreground`,children:[(0,_.jsx)(le,{className:`h-4 w-4 mr-1`}),Bt===`reject`?S(`rejecting`,`Rejecting…`):S(`reject`,`Reject`)]})}),(0,_.jsxs)(ye,{children:[(0,_.jsxs)(xe,{children:[(0,_.jsx)(ce,{children:S(`rejectTitle`,`Reject this request?`)}),(0,_.jsx)(ae,{children:S(`rejectBody`,`This marks the request as rejected and notifies the submitter.`)})]}),(0,_.jsxs)(tt,{children:[(0,_.jsx)(rt,{children:S(`cancel`,`Cancel`)}),(0,_.jsx)(Pe,{onClick:()=>gn(`reject`),className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:S(`reject`,`Reject`)})]})]})]})]}),!yn&&(0,_.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:bn?S(`whyDisabledSubmitter`,`You submitted this request, so you can recall it — but only the assigned approvers can approve or reject.`):S(`whyDisabled`,`Only the assigned approvers can act on this request. It is waiting on: {{who}}.`,{who:(A.pending_approvers||[]).map(e=>gt(e,A)).join(`, `)||`—`})}),(0,_.jsx)(ot,{objectName:`sys_approval_request`,record:A,location:`record_section`,exclude:[`approval_approve`,`approval_reject`],label:S(`declaredActions`,`More actions`),onDone:()=>{_n(A.id),K()}})]})]}),xn&&(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)(_e,{}),(0,_.jsxs)(`div`,{className:`space-y-3`,children:[(0,_.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:S(`returnedHint`,`An approver sent this back to you. The record is unlocked — fix the data, then resubmit to start a new approval round.`)}),(0,_.jsxs)(`div`,{className:`flex gap-2 flex-wrap items-center`,children:[(0,_.jsx)(c,{asChild:!0,size:`sm`,variant:`outline`,children:(0,_.jsxs)(t,{to:St(A),children:[(0,_.jsx)(Ze,{className:`h-4 w-4 mr-1`}),S(`editRecordBtn`,`Edit record`)]})}),(0,_.jsx)(ot,{objectName:`sys_approval_request`,record:A,location:`record_section`,exclude:[`approval_approve`,`approval_reject`],onDone:()=>{_n(A.id),K()}})]})]})]})]}):null]})})]})}export{xt as ApprovalsInboxPage};
@@ -1 +0,0 @@
1
- import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{f as t,h as n,r,y as i}from"./vendor-react-BKSb6vFP.js";import{A as a,B as o,H as s,k as c,zt as l}from"./framework-Oi7uo_kE.js";import{J as u,Q as d,Uc as f,Z as p,ls as m,tt as h}from"./ui-components-BluZyuZX.js";import"./MetadataProvider-Dq7I7eh-.js";import{t as g}from"./RecordDetailView-C6UiMORv.js";import{d as _}from"./plugins-views-DCG6qMPm.js";var v=e(i(),1),y=`uf_`;function b(e){let t={};return e.forEach((e,n)=>{if(n.startsWith(y)&&e!==``){let r=n.slice(3);t[r]=e.split(`,`).map(e=>{try{return decodeURIComponent(e)}catch{return e}})}}),Object.keys(t).length>0?t:void 0}function x(e,t){let n=new URLSearchParams(e);for(let[e,r]of Object.entries(t)){let t=y+e;r&&r.length>0?n.set(t,r.map(e=>encodeURIComponent(String(e))).join(`,`)):n.delete(t)}return n}var S=r();function C(e){return Array.isArray(e?.columns)&&e.columns.length>0}function w(e,t){let n=e?.listViews||e?.list_views||{},r=(t?[n[`${e?.name}.${t}`],n[t],...t==="default"||t===`list`?[e?.list]:[]]:[e?.list,...Object.values(n)]).filter(Boolean);return r.find(C)??r[0]}function T(e){let t=e?.highlightFields;if(Array.isArray(t)&&t.length>0)return t.filter(t=>e.fields?.[t]);let n=e?.fields;return n&&typeof n==`object`?Object.entries(n).filter(([e,t])=>t&&!t.hidden&&!l(e,t)).map(([e])=>e).slice(0,6):[]}function E(e,t){let n=e?.fields;if(!(!n||typeof n!=`object`))return Object.entries(n).find(([e,n])=>n&&!n.hidden&&!l(e,n)&&t(e,n))?.[0]}var D=new Set([`select`,`multiselect`,`radio`,`enum`,`boolean`]),O=new Set([`date`,`datetime`,`time`]),k=new Set([`image`,`file`,`attachment`,`avatar`,`photo`]);function A(e){let t=E(e,(e,t)=>D.has(t.type))??E(e,e=>/status|stage|state|priority|category|kind/i.test(e));return t?{groupField:t,groupByField:t}:void 0}function j(e){return E(e,(e,t)=>O.has(t.type))??E(e,e=>/date|due|start|end|deadline|schedule/i.test(e))}function M(e){let t=j(e);return t?{startDateField:t}:void 0}function N(e){let t=E(e,(e,t)=>k.has(t.type));return t?{coverField:t}:void 0}var P=new Set([`location`,`geo`,`geolocation`,`geopoint`,`point`]);function F(e){let t=E(e,(e,t)=>O.has(t.type)&&/start|begin|kickoff/i.test(e))??E(e,(e,t)=>O.has(t.type));if(!t)return;let n=E(e,(e,n)=>O.has(n.type)&&e!==t&&/end|due|finish|deadline|close/i.test(e))??E(e,(e,n)=>O.has(n.type)&&e!==t);if(!n)return;let r=E(e,(e,t)=>(t.type===`number`||t.type===`percent`)&&/progress|percent|complete/i.test(e));return{startDateField:t,endDateField:n,...r?{progressField:r}:{}}}function I(e){let t=E(e,(e,t)=>P.has(t.type))??E(e,e=>/location|address|geo|coords?|place|venue/i.test(e));return t?{locationField:t}:void 0}function L({page:e,className:r,onConfigChange:i,reserveEditAffordance:l}){let{t:y}=f(),{objects:E}=a(),D=c(),O=t(),[k,j]=n(),[P]=v.useState(()=>b(new URLSearchParams(window.location.search))),L=v.useCallback(e=>{j(t=>x(t,e),{replace:!0})},[j]),R=e?.interfaceConfig||{},z=v.useMemo(()=>(E||[]).find(e=>e.name===R.source),[E,R.source]),B=v.useMemo(()=>w(z,R.sourceView),[z,R.sourceView]),V=R.recordAction===`page`||R.recordAction===`modal`||R.recordAction===`none`?R.recordAction:`drawer`,H=v.useCallback(e=>`/apps/${window.location.pathname.split(`/`)[2]||``}/${R.source}/record/${encodeURIComponent(String(e))}`,[R.source]),U=o({navigation:{mode:V===`none`?`none`:V},objectName:R.source,onNavigate:e=>O(H(e))}),W=k.get(`recordId`),G=v.useCallback((e,t)=>{if(V===`none`)return;let n=e?.id??e?._id;if(t&&(t.metaKey||t.ctrlKey||t.button===1)&&n!=null){window.open(H(n),`_blank`);return}if((V===`drawer`||V===`modal`)&&n!=null){j(e=>{let t=new URLSearchParams(e);return t.set(`recordId`,String(n)),t});return}U.handleClick(e,t)},[V,H,U,j]),ee=v.useCallback(()=>{j(e=>{let t=new URLSearchParams(e);return t.delete(`recordId`),t})},[j]);v.useEffect(()=>{W&&!U.isOpen?U.open({id:W}):!W&&U.isOpen&&U.close()},[W]);let K=z?.name,q=!!B&&!C(B),J=B?.name??(R.sourceView?`${R.source}.${R.sourceView}`:void 0),[Y,X]=v.useState(null);v.useEffect(()=>{let e=!1;if(X(null),!(!K||!R.source||!q||!J))return(async()=>{try{let t=D,n=null;typeof t?.listViewOverrides==`function`&&(n=(await t.listViewOverrides(R.source))?.[J]??null),!C(n)&&typeof t?.getView==`function`&&(n=await t.getView(R.source,J)),!e&&n&&typeof n==`object`&&X(n)}catch{}})(),()=>{e=!0}},[K,R.source,R.sourceView,q,J,D]);let Z=v.useMemo(()=>Y?{...B,...Y}:B,[B,Y]),te=JSON.stringify(Z??null),Q=v.useMemo(()=>{if(!z)return;let e=Z||{},t=R.appearance??e.appearance,n=t?.allowedVisualizations||[],r=new Set(n),i=R.userActions||{},a=e.kanban??(r.has(`kanban`)?A(z):void 0),o=e.calendar??(r.has(`calendar`)?M(z):void 0),s=e.timeline??(r.has(`timeline`)?M(z):void 0),c=e.gallery??(r.has(`gallery`)?N(z):void 0),l=e.gantt??(r.has(`gantt`)?F(z):void 0),u=e.options?.map??(r.has(`map`)?I(z):void 0),d=[...Array.isArray(e.filter)?e.filter:[],...Array.isArray(R.filterBy)?R.filterBy:[]],f=C(R)?R.columns:C(e)?e.columns:T(z),p=Array.isArray(R.sort)&&R.sort.length?R.sort:e.sort;return{type:`list-view`,objectName:z.name,viewType:n[0]??e.type??`grid`,fields:f,...d.length?{filters:d}:{},...p?.length?{sort:p}:{},grouping:e.grouping,rowColor:e.rowColor,pagination:e.pagination,searchableFields:e.searchableFields,emptyState:e.emptyState,kanban:a,calendar:o,gallery:c,timeline:s,gantt:l,...u||e.options?{options:{...e.options??{},...u?{map:u}:{}}}:{},userFilters:R.userFilters??e.userFilters,appearance:t,showViewSwitcher:n.length>1,showRecordCount:R.showRecordCount,addRecord:R.addRecord,showSearch:i.search!==!1,showSort:i.sort!==!1,showFilters:i.filter===!0,showDensity:i.rowHeight===!0,showHideFields:!1,showGroup:!1,showColor:!1,allowExport:!1,inlineEdit:i.editInline===!0}},[K,te,R]);if(!z||!Q)return(0,S.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,S.jsxs)(p,{children:[(0,S.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,S.jsx)(m,{className:`h-6 w-6 text-muted-foreground`})}),(0,S.jsx)(h,{children:y(`empty.objectNotFound`,{defaultValue:`Source object not found`})}),(0,S.jsx)(d,{children:y(`empty.interfacePageSourceMissing`,{defaultValue:`This interface page references "{{name}}", which is not available.`,name:R.source||`?`})})]})});let $=Array.isArray(R.buttons)&&R.buttons.length?R.buttons.map(e=>(z.actions||[]).find(t=>t?.name===e)).filter(Boolean).map(e=>({...e,locations:[`list_toolbar`]})):[];return(0,S.jsxs)(`div`,{className:r??`h-full flex flex-col`,"data-testid":`interface-list-page`,children:[(0,S.jsxs)(`div`,{className:`pl-4 pt-4 pb-2 shrink-0 flex items-start justify-between gap-3 ${l?`pr-12`:`pr-4`}`,children:[(0,S.jsxs)(`div`,{className:`min-w-0`,children:[(0,S.jsx)(`h1`,{className:`text-lg font-semibold leading-tight`,children:typeof e.label==`string`?e.label:e.name}),typeof e.description==`string`&&e.description&&(0,S.jsx)(`p`,{className:`text-sm text-muted-foreground mt-0.5`,children:e.description})]}),$.length>0&&(0,S.jsx)(`div`,{className:`shrink-0`,"data-testid":`interface-page-buttons`,children:(0,S.jsx)(s,{schema:{type:`action:bar`,location:`list_toolbar`,actions:$,size:`sm`,variant:`outline`}})})]}),(0,S.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto`,children:(0,S.jsx)(_,{schema:Q,dataSource:D,userFilterSelections:P,onUserFilterSelectionsChange:L,onSortChange:i?e=>i({sort:e}):void 0,onColumnStateChange:i?e=>{e?.order?.length&&i({columns:e.order})}:void 0,onRowClick:V===`none`?void 0:G})}),U.isOverlay&&(0,S.jsx)(u,{...U,setIsOpen:e=>{e||ee()},title:typeof e.label==`string`?e.label:R.source||`Record`,children:e=>(0,S.jsx)(g,{objectNameOverride:R.source,recordIdOverride:String(e?.id??e?._id??W??``),embedded:!0,dataSource:D,objects:E,onEdit:()=>{}})})]})}export{A as a,N as i,M as n,x as o,T as r,b as s,L as t};
@@ -1 +0,0 @@
1
- import{r as e}from"./vendor-react-BKSb6vFP.js";import{Ht as t,Ka as n,Mc as r,Oc as i,Pi as a,Uc as o,Ut as s,Vt as c,Wt as l,fr as u,ji as d}from"./ui-components-BluZyuZX.js";var f=e();function p(e){return e===!0||typeof e==`object`&&!!e&&e.enabled===!0}var m={config:{icon:a,i18nKey:`config`,short:`Admin config`,title:`Administrator configuration`,body:()=>`These rows define how the platform behaves at runtime. Author them here; the runtime data they produce lives in a separate table.`,tone:`border-sky-300/60 bg-sky-50 text-sky-900 hover:bg-sky-100 dark:border-sky-500/40 dark:bg-sky-950/40 dark:text-sky-100`},system:{icon:n,i18nKey:`system`,short:`System-managed`,title:`Managed by the platform`,body:()=>`Rows here are created automatically when actions run on the source record. The list below is a read-only monitoring surface — row-level actions (Approve, Recall, Resend, …) live on each row.`,tone:`border-slate-300/60 bg-slate-50 text-slate-900 hover:bg-slate-100 dark:border-slate-500/40 dark:bg-slate-950/40 dark:text-slate-100`},"system-writable":{icon:a,i18nKey:`systemWritable`,short:`Platform schema`,title:`Platform-defined, admin-writable`,body:()=>`This object's schema is defined by the platform, but its rows are yours to create and edit here. Who may write is governed by delegated administration and record-level security, not by this badge.`,tone:`border-slate-300/60 bg-slate-50 text-slate-900 hover:bg-slate-100 dark:border-slate-500/40 dark:bg-slate-950/40 dark:text-slate-100`},"append-only":{icon:i,i18nKey:`appendOnly`,short:`Read-only · Audit log`,title:`Read-only historical record`,body:()=>`Immutable audit log. Rows cannot be created, edited, or deleted from the UI — they're written by the platform when events occur. Use Export to download for compliance review.`,tone:`border-zinc-300/60 bg-zinc-50 text-zinc-900 hover:bg-zinc-100 dark:border-zinc-500/40 dark:bg-zinc-950/40 dark:text-zinc-100`},"better-auth":{icon:d,i18nKey:`betterAuth`,short:`Identity`,title:`Managed by the identity provider`,body:e=>`This object's schema is owned by ${e}. Direct edits bypass password hashing, session validation, two-factor checks, and audit hooks. Manage these records through your authentication provider's sign-in, invitation, and security flows instead.`,tone:`border-amber-300/60 bg-amber-50 text-amber-900 hover:bg-amber-100 dark:border-amber-500/40 dark:bg-amber-950/40 dark:text-amber-100`}};function h({managedBy:e,userActions:n,label:i,className:a}){let{t:d}=o();if(!e||e===`platform`)return null;let h=n??void 0,g=m[e===`system`&&(h?.create===!0||p(h?.edit)||p(h?.delete))?`system-writable`:e];if(!g)return null;let _=g.icon,v=i??`better-auth`,y=d(`managedByBadge.${g.i18nKey}.short`,{defaultValue:g.short}),b=d(`managedByBadge.${g.i18nKey}.title`,{defaultValue:g.title}),x=d(`managedByBadge.${g.i18nKey}.body`,{defaultValue:g.body(v),provider:v});return(0,f.jsx)(s,{delayDuration:200,children:(0,f.jsxs)(c,{children:[(0,f.jsx)(l,{asChild:!0,children:(0,f.jsxs)(u,{variant:`outline`,"data-testid":`managed-by-badge`,"data-bucket":e,className:r(`gap-1 font-normal text-[11px] leading-none py-0.5 px-1.5 cursor-help`,g.tone,a),children:[(0,f.jsx)(_,{className:`h-3 w-3`,"aria-hidden":`true`}),(0,f.jsx)(`span`,{children:y})]})}),(0,f.jsxs)(t,{side:`bottom`,align:`start`,className:`max-w-xs text-xs leading-relaxed`,children:[(0,f.jsx)(`p`,{className:`font-semibold mb-1`,children:b}),(0,f.jsx)(`p`,{className:`text-muted-foreground`,children:x})]})]})})}export{h as t};
@@ -1 +0,0 @@
1
- import{o as e,r as t}from"./rolldown-runtime-DAXXjFlN.js";import{d as n,f as r,h as i,m as a,r as o,y as s}from"./vendor-react-BKSb6vFP.js";import{f as c,h as l,n as u,p as d}from"./infrastructure-CQFJ5N6p.js";import{A as f,F as p,H as m,k as h,l as g}from"./framework-Oi7uo_kE.js";import{Cr as _,Er as v,Ho as y,Or as b,Q as x,Rc as S,Sr as C,Tr as w,Uc as T,Z as E,q as D,tt as O,ua as k,wr as A,xr as j,yr as M}from"./ui-components-BluZyuZX.js";import{r as N}from"./vendor-ui-utils-D-WJ115h.js";import"./MetadataProvider-Dq7I7eh-.js";import{r as P}from"./ExpressionProvider-C26LCaQj.js";import{c as ee,i as te,l as ne,r as re,u as ie}from"./RecordDetailView-C6UiMORv.js";import{t as F}from"./preferLocal-CKqyhTP9.js";import{t as I}from"./InterfaceListPage-D00ihpcS.js";import{n as L,t as R}from"./MetadataInspector-B9z7wtJS.js";var z=e(s(),1),B=o();function V(e,t){if(/^https?:\/\//i.test(e)||e.startsWith(`mailto:`))return{href:e,external:!e.startsWith(`mailto:`)};let n=(t||``).replace(/\/+$/,``);return{href:`${n}${e}`,external:!!n}}function H({cta:e,apiBase:t,primary:n,onNavigate:r}){let{href:i,external:a}=V(e.url,t);return(0,B.jsx)(b,{asChild:!0,variant:n?`default`:`outline`,size:`sm`,children:(0,B.jsx)(`a`,{href:i,onClick:r,...a?{target:`_blank`,rel:`noopener noreferrer`}:{},"data-testid":`entitlement-cta-${n?`primary`:`secondary`}`,children:e.label})})}function ae({state:e,apiBase:t,onOpenChange:n}){let r=e.spec;return(0,B.jsx)(M,{open:e.open,onOpenChange:e=>{e||n(!1)},children:(0,B.jsxs)(C,{"data-testid":`environment-entitlement-dialog`,children:[(0,B.jsxs)(w,{children:[(0,B.jsx)(v,{children:r?.title}),(0,B.jsx)(_,{children:r?.message})]}),(0,B.jsxs)(A,{children:[(0,B.jsx)(j,{children:`Close`}),r?.secondaryCta&&(0,B.jsx)(H,{cta:r.secondaryCta,apiBase:t,primary:!1,onNavigate:()=>n(!1)}),r?.cta&&(0,B.jsx)(H,{cta:r.cta,apiBase:t,primary:!0,onNavigate:()=>n(!1)})]})]})})}var U=new Set([`DEV_ENV_PLAN_LOCKED`,`DEV_ENV_LIMIT`,`PRODUCTION_ENV_LIMIT`]);function W(e){return typeof e==`string`&&U.has(e)}var G=`/settings/billing`;function oe(e){let t=e?.code;if(!W(t))return null;let n=typeof e?.error==`string`&&e.error?e.error:typeof e?.message==`string`?e.message:``,r=typeof e?.upgrade_url==`string`&&e.upgrade_url?e.upgrade_url:G,i=typeof e?.contact_url==`string`&&e.contact_url?e.contact_url:``;return t===`PRODUCTION_ENV_LIMIT`?{code:t,title:`You already have your production environment`,message:n||`Each organization includes exactly one production environment. Create a separate organization for another, or contact us about an Enterprise arrangement.`,cta:i?{label:`Contact sales`,url:i}:void 0}:{code:t,title:t===`DEV_ENV_PLAN_LOCKED`?`Development environments are a paid feature`:`Development environment limit reached`,message:n||(t===`DEV_ENV_PLAN_LOCKED`?`Your free plan includes one production environment. Upgrade to add development environments — build in dev, then publish to production.`:`Capacity scales with AI seats. Add an AI seat, or archive an unused development environment to free one up.`),cta:{label:`Upgrade plan`,url:r}}}function K(e){return e.hasProductionEnv?e.canCreateDevelopmentEnv===!1?`upgrade_for_development`:`add_development`:`setup_production`}function q(e){return{code:`DEV_ENV_PLAN_LOCKED`,title:`Development environments are a paid feature`,message:`${e.plan&&e.plan!==`free`?`your ${e.plan} plan`:`your free plan`} includes one production environment. Upgrade to add development environments — build in dev, then publish to production.`,cta:{label:`Upgrade plan`,url:e.upgradeUrl||`/settings/billing`}}}var J=/^\s*\{\{\s*page\.([A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*)\s*\}\}\s*$/;function Y(e,t){let n=t;for(let t of e.split(`.`)){if(n==null)return;n=n[t]}return n}function se(e,t){if(!e.includes(`{{`))return e;let n=e.match(J);if(n){let e=Y(n[1],t);return e===void 0?``:e}return e.replace(/\{\{\s*page\.([A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*)\s*\}\}/g,(e,n)=>{let r=Y(n,t);return r==null?``:String(r)})}function X(e,t){if(typeof e==`string`)return se(e,t);if(Array.isArray(e))return e.map(e=>X(e,t));if(e&&typeof e==`object`){let n={};for(let[r,i]of Object.entries(e))n[r]=X(i,t);return n}return e}function Z(e,t){return t?X(e,t):e}var ce={id:`current-user`,name:`Demo User`,isPlatformAdmin:!1};function Q(e){let t=e.locations;return Array.isArray(t)?t.some(e=>e===`list_item`||e===`record_header`||e===`record_more`||e===`record_section`):!1}function $(e,t){let n=e,r=n?.error;if(typeof r==`string`&&r.length>0)return r;let i=r?.message;return typeof i==`string`&&i.length>0?i:typeof n?.message==`string`&&n.message.length>0?n.message:t}function le(e){let{dataSource:t,objects:n,objectName:i,onRefresh:a}=e,o=r(),{user:s,activeOrganization:c}=d(),{systemPermissions:f}=u(),{fieldLabel:p,fieldOptionLabel:m,actionParamText:h,actionParamOptionLabel:_,actionDescription:v}=S(),y=(0,z.useMemo)(()=>i?n?.find(e=>e.name===i):void 0,[n,i]),b=i||y?.name,x=(0,z.useCallback)(()=>{a?.()},[a]),C=g({dataSource:t,onUndo:()=>{x(),N.success(`Change undone`)}}),[w,T]=(0,z.useState)({open:!1,message:``}),[E,D]=(0,z.useState)({open:!1,params:[]}),[O,k]=(0,z.useState)({open:!1}),[A,j]=(0,z.useState)(null),[M,P]=(0,z.useState)({open:!1}),F=(0,z.useRef)(new Set),I=(0,z.useCallback)((e,t)=>new Promise(n=>{k({open:!0,spec:e,data:t,resolve:n})}),[]),L=(0,z.useCallback)((e,t)=>new Promise(n=>{T({open:!0,message:e,options:t,resolve:n})}),[]),R=(0,z.useCallback)((e,t)=>new Promise(r=>{let a=t?.params&&!Array.isArray(t.params)?t.params._rowRecord:void 0,o=typeof t?.objectName==`string`&&t.objectName?t.objectName:void 0,s=re(e,{objectName:o||i||y?.name||``,objects:n||[],fieldLabel:p,fieldOptionLabel:m,row:a}),c=o||i||y?.name,l=s.map(e=>({...e,label:h(c,t?.name,e.name,`label`,e.label)??e.label,placeholder:h(c,t?.name,e.name,`placeholder`,e.placeholder)??e.placeholder,helpText:h(c,t?.name,e.name,`helpText`,e.helpText)??e.helpText,options:Array.isArray(e.options)?e.options.map(n=>({...n,label:_(c,t?.name,e.name,n.value,n.label)})):e.options}));D({open:!0,params:l,title:t?.label||t?.title,description:v(c,t?.name,t?.description),resolve:r})}),[i,y,n,p,m,h,_]),V=s?{id:s.id,name:s.name,avatar:s.image,isPlatformAdmin:s?.isPlatformAdmin??!1,systemPermissions:f??[]}:{...ce,systemPermissions:f??[]},H=(0,z.useCallback)((e,t)=>{if(t?.type===`error`){N.error(e);return}if(t?.undo){N.success(e,{duration:t.duration,action:{label:t.undo.label||`Undo`,onClick:()=>{C.undo()}}});return}N.success(e,{duration:t?.duration})},[C]),U=(0,z.useCallback)((e,t)=>{t?.external||t?.newTab?window.open(e,`_blank`,`noopener,noreferrer`):o(e)},[o]),W=(0,z.useMemo)(()=>l(),[]),G=(0,z.useCallback)(e=>{P({open:!0,spec:e})},[]),K=(0,z.useCallback)(async(e,n)=>{try{let r=e.target||e.name,i=e.params||{},a=typeof r==`string`?r:``;if(a.startsWith(`/`)||/^https?:\/\//i.test(a)){let t={...i},r=t._rowRecord;delete t._rowRecord;let o=n?.pageVariables??void 0,s=Z(t,o),l=a;r&&/\{[a-z_][a-z0-9_]*\}/i.test(l)&&(l=l.replace(/\{([a-z_][a-z0-9_]*)\}/gi,(e,t)=>{let n=r[t];return n==null?``:encodeURIComponent(String(n))}));let u=l.startsWith(`http`)?l:`${l}`,d=e.bodyShape&&typeof e.bodyShape==`object`&&e.bodyShape.wrap?e.bodyShape.wrap:void 0,f=d?{[d]:s}:{...s};if(r&&e.recordIdParam){let t=r[e.recordIdField||`id`];t!=null&&(f[e.recordIdParam]=t)}/\/api\/v1\/auth\//.test(l)&&!f.organizationId&&c?.id&&(f.organizationId=c.id),e.bodyExtra&&typeof e.bodyExtra==`object`&&Object.assign(f,Z(e.bodyExtra,o));let p=(e.method||`POST`).toUpperCase(),m={method:p,headers:{"Content-Type":`application/json`},credentials:`include`};p!==`GET`&&p!==`DELETE`&&(m.body=JSON.stringify(f));let h=await W(u,m);if(!h.ok){let e=null;try{e=await h.json()}catch{}let t=oe(e);return t?(G(t),{success:!1}):{success:!1,error:$(e,`HTTP ${h.status}`)}}let g=await h.json().catch(()=>({}));return e.refreshAfter!==!1&&x(),{success:!0,data:g&&typeof g==`object`&&!Array.isArray(g)&&`data`in g?g.data:g,reload:e.refreshAfter!==!1}}let o=e.objectName||b,s=i._rowRecord,l={...i};delete l._rowRecord;let u=l.recordId??s?.[e.recordIdField||`id`];delete l.recordId,e.bodyExtra&&typeof e.bodyExtra==`object`&&Object.assign(l,e.bodyExtra),o&&typeof t?.execute==`function`?await t.execute(o,r,l):o&&u&&Object.keys(l).length>0&&typeof t?.update==`function`&&await t.update(o,u,l);let d;if(e.undoable&&o&&u&&s&&Object.keys(l).length>0&&typeof t?.update==`function`){let t={};for(let e of Object.keys(l))t[e]=s[e]??null;d={id:`undo-${o}-${u}-${Date.now()}`,type:`update`,objectName:o,recordId:String(u),timestamp:Date.now(),description:e.label||`Undo ${o}`,undoData:t,redoData:{...l}}}let f=e.refreshAfter!==!1;return f&&x(),{success:!0,reload:f,undo:d}}catch(e){return{success:!1,error:e.message}}},[t,b,W,c,x,G]),q=(0,z.useCallback)(async(e,t)=>{let n=e.target||e.name;if(!n)return{success:!1,error:`No flow target provided for flow action`};try{let r={...e.params||{}},i=r._rowRecord;delete r._rowRecord;let a=r.recordId??i?.id;if(a==null){let n=Array.isArray(t?.selectedRecords)?t.selectedRecords:[];if(n.length===1)a=n[0]?.id;else if(n.length>1)return{success:!1,error:`This flow runs on a single record — select exactly one row.`};else if(Q(e))return{success:!1,error:`This flow runs on a single record — select a row first.`}}a!=null&&r.recordId==null&&(r.recordId=a);let o=await W(`/api/v1/automation/${encodeURIComponent(n)}/trigger`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({recordId:a,objectName:e.objectName||b,params:r})}),s=await o.json().catch(()=>null);if(!o.ok||s&&s.success===!1)return{success:!1,error:$(s,`Flow "${n}" failed (HTTP ${o.status})`)};let c=s?.data??{};if(c.status===`paused`&&c.screen)return j({flowName:n,runId:c.runId,screen:c.screen}),{success:!0,silent:!0};let l=e.refreshAfter!==!1;return l&&x(),{success:!0,data:s?.data,reload:l}}catch(e){return{success:!1,error:e.message}}},[W,b,x]),J=(0,z.useCallback)(async(e,t)=>{let n=e.target||e.name;if(!n)return{success:!1,error:`No action target provided`};let r=e.params&&!Array.isArray(e.params)?{...e.params}:{},i=r._rowRecord;delete r._rowRecord;let a=e.recordIdField||`id`,o=r.recordId??i?.[a];if(o==null){let n=Array.isArray(t?.selectedRecords)?t.selectedRecords:[];if(n.length===1)o=n[0]?.[a];else if(n.length>1)return{success:!1,error:`This action runs on a single record — select exactly one row.`};else if(Q(e))return{success:!1,error:`This action runs on a single record — select a row first.`}}let s=`${n}:${o??``}`;if(F.current.has(s))return{success:!1,error:`Action already in progress`};F.current.add(s);let c=null;if(e.opensInNewTab)try{c=window.open(`about:blank`,`_blank`),c&&(c.document.write(`<!doctype html><meta charset="utf-8"><title>正在打开… Opening…</title><body style="margin:0;font-family:system-ui,sans-serif;display:flex;flex-direction:column;align-items:center;justify-content:center;height:100vh;gap:16px;color:#4b5563"><div style="width:28px;height:28px;border:3px solid #e5e7eb;border-top-color:#6366f1;border-radius:50%;animation:s .8s linear infinite"></div><div>正在为你打开环境…</div><style>@keyframes s{to{transform:rotate(360deg)}}</style></body>`),c.document.close())}catch{c=null}try{let t=typeof e.newTabUrl==`string`?e.newTabUrl:``;if(e.opensInNewTab&&t){if(o==null){if(c)try{c.close()}catch{}return{success:!1,error:`This action runs on a single record — no record id available.`}}let n=`${window.location.origin}${t.replace(`{recordId}`,encodeURIComponent(String(o)))}`;if(c)try{c.location.href=n}catch{try{c.close()}catch{}window.location.href=n}else{let e=null;try{e=window.open(n,`_blank`)}catch{e=null}e||N(`浏览器拦截了弹窗 / Popup blocked`,{description:`点击在新标签页打开环境`,action:{label:`打开环境`,onClick:()=>{try{window.open(n,`_blank`)}catch{window.location.href=n}}},duration:1e4})}return e.refreshAfter===!0&&x(),{success:!0}}let i=e.objectName||b||`global`,a=await W(`/api/v1/actions/${encodeURIComponent(i)}/${encodeURIComponent(n)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({recordId:o,params:r})}),s=await a.json().catch(()=>null);if(!a.ok||s&&s.success===!1){let e=$(s,`Action "${n}" failed (HTTP ${a.status})`);if(c)try{c.close()}catch{}return{success:!1,error:e}}let l=e.refreshAfter!==!1;l&&x();let u=s?.data,d=u&&typeof u==`object`&&typeof u.redirectUrl==`string`?u.redirectUrl:null;if(d)if(c)try{c.location.href=d}catch{try{c.close()}catch{}window.location.href=d}else{let e=null;try{e=window.open(d,`_blank`)}catch{e=null}e||N(`浏览器拦截了弹窗 / Popup blocked`,{description:`点击在新标签页打开环境`,action:{label:`打开环境`,onClick:()=>{try{window.open(d,`_blank`)}catch{window.location.href=d}}},duration:1e4})}else if(c)try{c.close()}catch{}return{success:!0,data:u,reload:l}}catch(e){if(c)try{c.close()}catch{}return{success:!1,error:e.message}}finally{F.current.delete(s)}},[W,b,x]);return{confirmHandler:L,toastHandler:H,navigateHandler:U,paramCollectionHandler:R,resultDialogHandler:I,apiHandler:K,flowHandler:q,serverActionHandler:J,authFetch:W,openEntitlementDialog:G,actionProviderProps:(0,z.useMemo)(()=>({context:{...i?{objectName:i}:{},user:V,apiBase:``,activeOrganization:c?{id:c.id,slug:c.slug,name:c.name}:null},onConfirm:L,onToast:H,onNavigate:U,onParamCollection:R,onResultDialog:I,handlers:{api:K,flow:q,script:J,modal:J}}),[i,V,c,L,H,U,R,I,K,q,J]),dialogs:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(ie,{state:w,onOpenChange:e=>{e||T({open:!1,message:``})}}),(0,B.jsx)(ne,{state:E,onOpenChange:e=>{e||D({open:!1,params:[]})}}),(0,B.jsx)(ee,{state:O,onAcknowledge:()=>{O.resolve?.(),k({open:!1})}}),(0,B.jsx)(te,{state:A,authFetch:W,baseUrl:``,dataSource:t,objects:n,onClose:()=>j(null),onComplete:()=>{j(null),x()}}),(0,B.jsx)(ae,{state:M,apiBase:``,onOpenChange:e=>{e||P({open:!1})}})]})}}function ue({children:e,...t}){let n=le(t);return(0,B.jsxs)(p,{...n.actionProviderProps,children:[e,n.dialogs]})}var de=t({PageView:()=>fe});function fe(){let{t:e}=T(),{pageName:t}=a(),[o]=i(),{showDebug:s}=L(),l=r(),u=n(),d=c(),{pages:p,objects:g,getTypeStatus:_}=f(),{app:v}=P(),b=h(),[S,C]=(0,z.useState)(0),w=F(p,t,v?._packageId);if(!w){let n=_?.(`page`);return n===`idle`||n===`loading`?(0,B.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,"data-testid":`page-loading`,children:(0,B.jsx)(D,{className:`h-5 w-5 text-muted-foreground`})}):(0,B.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,B.jsxs)(E,{children:[(0,B.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,B.jsx)(y,{className:`h-6 w-6 text-muted-foreground`})}),(0,B.jsx)(O,{children:e(`empty.pageNotFound`)}),(0,B.jsx)(x,{children:e(`empty.pageNotFoundDescription`,{name:t})})]})})}let A=Object.fromEntries(o.entries()),j=u.pathname.match(/\/apps\/([^/]+)/)?.[1],M=d&&!!j&&!!t;return(0,B.jsx)(ue,{dataSource:b,objects:g,onRefresh:()=>C(e=>e+1),children:(0,B.jsxs)(`div`,{className:`flex flex-row h-full w-full overflow-hidden relative`,children:[(0,B.jsxs)(`div`,{className:`flex-1 overflow-auto h-full relative`,children:[M&&(0,B.jsx)(`button`,{type:`button`,onClick:()=>{M&&l(`/apps/${j}/metadata/page/${encodeURIComponent(t)}`)},className:`absolute right-3 top-3 z-30 inline-flex h-7 w-7 items-center justify-center rounded-md border border-input bg-background/90 text-muted-foreground shadow-sm backdrop-blur hover:bg-accent hover:text-accent-foreground`,"data-testid":`page-edit-in-studio-button`,title:e(`common.editInStudio`,{defaultValue:`Edit in studio`}),"aria-label":e(`common.editInStudio`,{defaultValue:`Edit in studio`}),children:(0,B.jsx)(k,{className:`h-3.5 w-3.5`})}),w.interfaceConfig?.source?(0,B.jsx)(I,{page:w,reserveEditAffordance:M},S):(0,B.jsx)(m,{schema:{...w,type:w.type||`page`,context:{...w.context,params:A,refreshKey:S}}},S)]}),(0,B.jsx)(R,{open:s,sections:[{title:`Page Configuration`,data:w}]})]})})}export{q as a,K as i,le as n,G as r,de as t};
@@ -1,9 +0,0 @@
1
- import{o as e,r as t,t as n}from"./rolldown-runtime-DAXXjFlN.js";import{a as r,d as i,f as a,h as o,m as s,r as c,y as l}from"./vendor-react-BKSb6vFP.js";import{g as u,h as d,n as f,p}from"./infrastructure-CQFJ5N6p.js";import{A as m,C as h,F as g,H as _,I as v,Jt as y,S as b,T as x,X as S,Zt as C,b as ee,i as te,k as w,l as ne,m as re,n as ie,ot as ae,s as oe,v as se}from"./framework-Oi7uo_kE.js";import{$n as ce,$o as le,$t as ue,An as de,Cr as fe,Er as pe,Fr as me,Jt as he,Ks as ge,Lc as T,Mc as E,Mn as _e,Nn as ve,Or as D,Q as ye,Qn as O,Rc as be,Rs as xe,Sr as Se,T as Ce,Tr as we,Uc as Te,Ur as Ee,Xn as k,Xt as De,Yt as Oe,Z as ke,Zn as A,Zt as Ae,ar as je,as as Me,br as Ne,ei as Pe,en as Fe,er as j,es as Ie,f as Le,fa as Re,fs as ze,j as Be,jn as Ve,kn as He,ls as Ue,mn as M,mt as We,nn as N,or as P,qa as F,qr as I,qs as Ge,qt as L,ra as Ke,rn as qe,tn as Je,tr as R,tt as Ye,v as Xe,vn as z,wr as B,xr as Ze,yr as Qe}from"./ui-components-BluZyuZX.js";import{r as V}from"./vendor-ui-utils-D-WJ115h.js";import{n as H,t as $e}from"./plugin-form-C969LzWi.js";import"./utils-Bxty7IIa.js";import{o as et}from"./i18n-grFi0A0v.js";import{a as tt,c as nt,i as rt,l as it,n as at,r as ot}from"./plugins-views-DCG6qMPm.js";import{n as st,t as ct}from"./MetadataInspector-B9z7wtJS.js";import{t as lt}from"./ManagedByBadge-B4O4Jy3c.js";import{t as ut}from"./skeletons-CX6Ch5Lg.js";var U=e(l(),1),W=c(),dt=(0,U.createContext)({favorites:null,recent:null,flowPaletteRecents:null}),ft=(0,U.createContext)(null);function pt({children:e}){let[t,n]=(0,U.useState)({favorites:null,recent:null,flowPaletteRecents:null}),r=(0,U.useRef)({attach:(e,t)=>{n(n=>n[e]===t?n:{...n,[e]:t})}});return(0,W.jsx)(ft.Provider,{value:r.current,children:(0,W.jsx)(dt.Provider,{value:t,children:e})})}function mt(e){return(0,U.useContext)(dt)[e]}function ht(){let e=(0,U.useContext)(ft);return(0,U.useCallback)((t,n)=>{e?.attach(t,n)},[e])}function G(e,t){return t?`${e}:u:${t}`:e}function gt(e,t){let n=(0,U.useRef)(t);n.current=t,(0,U.useEffect)(()=>{if(typeof window>`u`)return;let t=t=>{if(!(t.key!==e||t.storageArea!==localStorage)){if(t.newValue==null){n.current(null);return}try{n.current(JSON.parse(t.newValue))}catch{n.current(null)}}};return window.addEventListener(`storage`,t),()=>window.removeEventListener(`storage`,t)},[e])}function _t(e,t=500){let n=null,r=null,i=!1,a=async()=>{if(n&&=(clearTimeout(n),null),!i)return;let t=r;i=!1,r=null;try{await e(t)}catch{}};return{schedule:e=>{r=e,i=!0,n&&clearTimeout(n),n=setTimeout(()=>{n=null,a()},t)},flush:a,cancel:()=>{n&&clearTimeout(n),n=null,i=!1,r=null}}}var vt=`objectui-recent-items`,yt=8;function K(e){try{let t=localStorage.getItem(G(vt,e));return t?JSON.parse(t):[]}catch{return[]}}function bt(e,t){try{localStorage.setItem(G(vt,t),JSON.stringify(e))}catch{}}var xt=(0,U.createContext)(null);function St({children:e}){let{user:t}=p(),n=t?.id??null,r=mt(`recent`),[i,a]=(0,U.useState)(()=>K(n));(0,U.useEffect)(()=>{a(K(n))},[n]),gt(G(vt,n),e=>{a(Array.isArray(e)?e.filter(e=>e&&typeof e.id==`string`).slice(0,yt):[])});let o=(0,U.useRef)(0);(0,U.useEffect)(()=>{if(!r)return;let e=++o.current,t=!1;return(async()=>{try{let i=await r.load();if(t||e!==o.current)return;let s=(Array.isArray(i)?i:[]).filter(e=>e&&typeof e.id==`string`).slice(0,yt);a(s),bt(s,n)}catch{}})(),()=>{t=!0}},[r,n]);let s=(0,U.useMemo)(()=>_t(async e=>{r&&await r.save(e)},500),[r]);(0,U.useEffect)(()=>()=>{s.flush()},[s]);let c=(0,U.useCallback)(e=>{bt(e,n),r&&s.schedule(e)},[n,r,s]),l=(0,U.useCallback)(e=>{a(t=>{let n=t.filter(t=>t.id!==e.id),r=[{...e,visitedAt:new Date().toISOString()},...n].slice(0,yt);return c(r),r})},[c]),u=(0,U.useCallback)(()=>{a([]),c([])},[c]),d=(0,U.useMemo)(()=>({recentItems:i,addRecentItem:l,clearRecentItems:u}),[i,l,u]);return(0,W.jsx)(xt.Provider,{value:d,children:e})}function Ct(){return(0,U.useContext)(xt)||{recentItems:[],addRecentItem:()=>{},clearRecentItems:()=>{}}}function wt(e){let{objectDef:t,baseUrl:n,record:r}=e;if(!t?.name||t.editMode!==`page`)return{kind:`modal`};let i=r?.id??r?._id;if(r&&i!=null&&i!==``){let e=encodeURIComponent(String(i));return{kind:`page`,url:`${n}/${t.name}/record/${e}/edit`}}return{kind:`page`,url:`${n}/${t.name}/new`}}function Tt(e){let t=e?.form??e?.formViews?.default;if(!t)return{};let n={};return Array.isArray(t.sections)&&t.sections.length>0&&(n.sections=t.sections,t.type===`tabbed`&&(n.contentLayout=`tabbed`)),Array.isArray(t.subforms)&&t.subforms.length>0&&(n.subforms=t.subforms),n}function Et(e){let{objectName:t,baseUrl:n,pathname:r,search:i,surface:a,recordId:o}=e;if(o==null||o===``||!t)return{kind:`none`};let s=encodeURIComponent(String(o));if(a===`page`)return{kind:`detail-page`,url:`${n}/${t}/record/${s}`};let c=new URLSearchParams(i??``);return c.delete(`form`),c.set(`recordId`,String(o)),{kind:`detail-drawer`,url:`${r}?${c.toString()}`}}function q(e){let{action:t,context:n={},defaultBaseUrl:r}=e,i=t.params?.objectName??t.objectName??n.objectName,a=n.baseUrl??r;return i?{success:!0,url:`${a}/${i}/new`}:{success:!1,error:`navigate_create: objectName is required`}}function Dt(e){let{action:t,context:n={},defaultBaseUrl:r}=e,i=t.params?.objectName??t.objectName??n.objectName,a=t.params?.recordId??t.recordId,o=n.baseUrl??r;return!i||a==null||a===``?{success:!1,error:`navigate_edit: objectName and recordId are required`}:{success:!0,url:`${o}/${i}/record/${encodeURIComponent(String(a))}/edit`}}var Ot={sm:`sm:max-w-sm`,default:`sm:max-w-lg`,lg:`sm:max-w-2xl`,xl:`sm:max-w-5xl`,full:`sm:max-w-[95vw] sm:w-full`},kt={lg:`sm:max-w-2xl`,xl:`sm:max-w-3xl`,full:`sm:max-w-[95vw]`};function At(e){if(typeof e==`string`){let t=e.match(/^(create|new|add|edit|update)_(.+)$/);return t?{objectName:t[2],mode:t[1]===`edit`||t[1]===`update`?`edit`:`create`}:{objectName:e,mode:`create`}}return e&&typeof e==`object`?e.type&&!e.content&&!e.objectName&&!e.placement?{content:e}:e:{}}function jt(e){let[t,n]=(0,U.useState)(null),{objects:r}=m(),i=(0,U.useCallback)(e=>{n(t=>(t?.resolve(e),null))},[]),a=(0,U.useCallback)(e=>new Promise(t=>{n({d:At(e),resolve:t})}),[]),o=null;if(t){let n=t.d,a=e=>{e||i({success:!1})};if(n.objectName&&!n.content){let t=n.fields||n.sections?{}:Tt(r.find(e=>e?.name===n.objectName));o=(0,W.jsx)(H,{schema:{type:`object-form`,formType:`modal`,objectName:n.objectName,mode:n.mode||`create`,recordId:n.recordId,title:n.title,description:n.description,fields:n.fields,...t,modalSize:n.size,open:!0,onOpenChange:a,onSuccess:e=>i({success:!0,reload:!0,data:e}),onCancel:()=>i({success:!1}),showSubmit:!0,showCancel:!0},dataSource:e})}else{let e=n.placement||`center`,t=n.content?(0,W.jsx)(_,{schema:n.content}):n.description?(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:n.description}):null;o=e===`side`?(0,W.jsx)(L,{open:!0,onOpenChange:a,children:(0,W.jsxs)(he,{side:n.side||`right`,className:E(`w-full overflow-y-auto`,kt[n.size||`default`]),children:[n.title&&(0,W.jsxs)(De,{children:[(0,W.jsx)(Ae,{children:n.title}),n.description&&(0,W.jsx)(Oe,{children:n.description})]}),(0,W.jsx)(`div`,{className:`py-3`,children:t})]})}):e===`bottom`?(0,W.jsx)(He,{open:!0,onOpenChange:a,children:(0,W.jsxs)(de,{children:[n.title&&(0,W.jsxs)(_e,{children:[(0,W.jsx)(ve,{children:n.title}),n.description&&(0,W.jsx)(Ve,{children:n.description})]}),(0,W.jsx)(`div`,{className:`max-h-[75vh] overflow-y-auto px-4 pb-6`,children:t})]})}):(0,W.jsx)(k,{open:!0,onOpenChange:a,children:(0,W.jsxs)(A,{className:E(e===`fullscreen`?`h-[95vh] w-full max-w-[98vw] overflow-y-auto`:Ot[n.size||`default`]),children:[n.title&&(0,W.jsxs)(j,{children:[(0,W.jsx)(R,{children:n.title}),n.description&&(0,W.jsx)(O,{children:n.description})]}),(0,W.jsx)(`div`,{children:t}),!n.content&&(0,W.jsx)(`div`,{className:`flex justify-end`,children:(0,W.jsx)(D,{onClick:()=>i({success:!0}),children:`OK`})})]})})}}return{modalHandler:a,modalElement:o,closeModal:i}}var Mt=(0,U.createContext)(void 0);function Nt({children:e}){let[t,n]=(0,U.useState)(`home`),[r,i]=(0,U.useState)(),[a,o]=(0,U.useState)(),s=(0,U.useMemo)(()=>({context:t,setContext:n,currentAppName:r,setCurrentAppName:i,recordTitle:a,setRecordTitle:o}),[t,r,a]);return(0,W.jsx)(Mt.Provider,{value:s,children:e})}function Pt(){return(0,U.useContext)(Mt)||{context:`app`,setContext:()=>{},currentAppName:void 0,setCurrentAppName:()=>{},recordTitle:void 0,setRecordTitle:()=>{}}}function Ft(e){let{setRecordTitle:t}=Pt();(0,U.useEffect)(()=>(t(e),()=>t(void 0)),[e,t])}var J=`objectui-favorites`,It=`objectui-nav-pins`,Lt=20,Rt=20;function Y(e){let t=0,n=0,r=!1;for(let i of e)i.type===`nav`?(n++,n>Rt&&(r=!0)):(t++,t>Lt&&(r=!0));if(!r)return e;let i=[],a=0,o=0;for(let t of e)t.type===`nav`?o<Rt&&(i.push(t),o++):a<Lt&&(i.push(t),a++);return i}function zt(e){try{let t=localStorage.getItem(G(J,e));return t?JSON.parse(t):[]}catch{return[]}}function Bt(e,t){try{localStorage.setItem(G(J,t),JSON.stringify(e))}catch{}}function Vt(e){let t;try{t=localStorage.getItem(It)}catch{return{migrated:e,didMigrate:!1}}if(!t)return{migrated:e,didMigrate:!1};let n=[];try{let e=JSON.parse(t);Array.isArray(e)&&(n=e.filter(e=>typeof e==`string`))}catch{}try{localStorage.removeItem(It)}catch{}if(n.length===0)return{migrated:e,didMigrate:!1};let r=new Set(e.filter(e=>e.type===`nav`&&e.navId).map(e=>e.navId)),i=new Date().toISOString(),a=[];for(let e of n)r.has(e)||a.push({id:`nav:${e}`,label:e,href:``,type:`nav`,navId:e,pinned:!0,favoritedAt:i});return a.length===0?{migrated:e,didMigrate:!0}:{migrated:[...e,...a],didMigrate:!0}}var X=(0,U.createContext)(null);function Ht({children:e}){let{user:t}=p(),n=t?.id??null,r=mt(`favorites`),[i,a]=(0,U.useState)(()=>zt(n));(0,U.useEffect)(()=>{a(zt(n))},[n]),gt(G(J,n),e=>{a(Array.isArray(e)?Y(e.filter(e=>e&&typeof e.id==`string`)):[])});let o=(0,U.useRef)(0);(0,U.useEffect)(()=>{if(!r)return;let e=++o.current,t=!1;return(async()=>{try{let i=await r.load();if(t||e!==o.current)return;let c=Y((Array.isArray(i)?i:[]).filter(e=>e&&typeof e.id==`string`)),l=zt(n),u=new Set(c.filter(e=>e.type===`nav`&&e.navId).map(e=>e.navId)),d=l.filter(e=>e.type===`nav`&&e.navId&&!u.has(e.navId)),f=c,p=!1;d.length>0&&(f=Y([...c,...d]),p=!0);let{migrated:m,didMigrate:h}=Vt(f);h&&(f=Y(m),p=!0),a(f),Bt(f,n),p&&s.schedule(f)}catch{}})(),()=>{t=!0}},[r,n]),(0,U.useEffect)(()=>{r||a(e=>{let{migrated:t,didMigrate:r}=Vt(e);if(!r)return e;let i=Y(t);return Bt(i,n),i})},[r,n]);let s=(0,U.useMemo)(()=>_t(async e=>{r&&await r.save(e)},500),[r]);(0,U.useEffect)(()=>()=>{s.flush()},[s]);let c=(0,U.useCallback)(e=>{Bt(e,n),r&&s.schedule(e)},[n,r,s]),l=(0,U.useCallback)(e=>{a(t=>{if(t.some(t=>t.id===e.id))return t;let n=Y([{...e,favoritedAt:new Date().toISOString()},...t]);return c(n),n})},[c]),u=(0,U.useCallback)(e=>{a(t=>{let n=t.filter(t=>t.id!==e);return c(n),n})},[c]),d=(0,U.useCallback)(e=>{a(t=>{let n=t.some(t=>t.id===e.id)?t.filter(t=>t.id!==e.id):Y([{...e,favoritedAt:new Date().toISOString()},...t]);return c(n),n})},[c]),f=(0,U.useCallback)(()=>{a([]),c([])},[c]),m=(0,U.useCallback)((e,t)=>{!e||!t||a(n=>{let r=!1,i=n.map(n=>n.id===e&&n.label!==t?(r=!0,{...n,label:t}):n);return r?(c(i),i):n})},[c]),h=(0,U.useCallback)((e,t)=>{a(n=>{let r=!1,i=n.map(n=>n.id!==e||!!n.pinned===t?n:(r=!0,{...n,pinned:t}));return r?(c(i),i):n})},[c]),g=(0,U.useMemo)(()=>{let e=new Set;for(let t of i)t.pinned&&t.type===`nav`&&t.navId&&e.add(t.navId);return{favorites:i,addFavorite:l,removeFavorite:u,toggleFavorite:d,isFavorite:e=>i.some(t=>t.id===e),clearFavorites:f,refreshLabel:m,setPinned:h,isPinned:e=>i.some(t=>t.id===e&&!!t.pinned),pinnedNavIds:e}},[i,l,u,d,f,m,h]);return(0,W.jsx)(X.Provider,{value:g,children:e})}function Ut(){return(0,U.useContext)(X)||{favorites:[],addFavorite:()=>{},removeFavorite:()=>{},toggleFavorite:()=>{},isFavorite:()=>!1,clearFavorites:()=>{},refreshLabel:()=>{},setPinned:()=>{},isPinned:()=>!1,pinnedNavIds:new Set}}var Wt=n(((e,t)=>{t.exports=function(){return typeof Promise==`function`&&Promise.prototype&&Promise.prototype.then}})),Z=n((e=>{var t,n=[0,26,44,70,100,134,172,196,242,292,346,404,466,532,581,655,733,815,901,991,1085,1156,1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,2611,2761,2876,3034,3196,3362,3532,3706];e.getSymbolSize=function(e){if(!e)throw Error(`"version" cannot be null or undefined`);if(e<1||e>40)throw Error(`"version" should be in range from 1 to 40`);return e*4+17},e.getSymbolTotalCodewords=function(e){return n[e]},e.getBCHDigit=function(e){let t=0;for(;e!==0;)t++,e>>>=1;return t},e.setToSJISFunction=function(e){if(typeof e!=`function`)throw Error(`"toSJISFunc" is not a valid function.`);t=e},e.isKanjiModeEnabled=function(){return t!==void 0},e.toSJIS=function(e){return t(e)}})),Gt=n((e=>{e.L={bit:1},e.M={bit:0},e.Q={bit:3},e.H={bit:2};function t(t){if(typeof t!=`string`)throw Error(`Param is not a string`);switch(t.toLowerCase()){case`l`:case`low`:return e.L;case`m`:case`medium`:return e.M;case`q`:case`quartile`:return e.Q;case`h`:case`high`:return e.H;default:throw Error(`Unknown EC Level: `+t)}}e.isValid=function(e){return e&&e.bit!==void 0&&e.bit>=0&&e.bit<4},e.from=function(n,r){if(e.isValid(n))return n;try{return t(n)}catch{return r}}})),Kt=n(((e,t)=>{function n(){this.buffer=[],this.length=0}n.prototype={get:function(e){let t=Math.floor(e/8);return(this.buffer[t]>>>7-e%8&1)==1},put:function(e,t){for(let n=0;n<t;n++)this.putBit((e>>>t-n-1&1)==1)},getLengthInBits:function(){return this.length},putBit:function(e){let t=Math.floor(this.length/8);this.buffer.length<=t&&this.buffer.push(0),e&&(this.buffer[t]|=128>>>this.length%8),this.length++}},t.exports=n})),qt=n(((e,t)=>{function n(e){if(!e||e<1)throw Error(`BitMatrix size must be defined and greater than 0`);this.size=e,this.data=new Uint8Array(e*e),this.reservedBit=new Uint8Array(e*e)}n.prototype.set=function(e,t,n,r){let i=e*this.size+t;this.data[i]=n,r&&(this.reservedBit[i]=!0)},n.prototype.get=function(e,t){return this.data[e*this.size+t]},n.prototype.xor=function(e,t,n){this.data[e*this.size+t]^=n},n.prototype.isReserved=function(e,t){return this.reservedBit[e*this.size+t]},t.exports=n})),Jt=n((e=>{var t=Z().getSymbolSize;e.getRowColCoords=function(e){if(e===1)return[];let n=Math.floor(e/7)+2,r=t(e),i=r===145?26:Math.ceil((r-13)/(2*n-2))*2,a=[r-7];for(let e=1;e<n-1;e++)a[e]=a[e-1]-i;return a.push(6),a.reverse()},e.getPositions=function(t){let n=[],r=e.getRowColCoords(t),i=r.length;for(let e=0;e<i;e++)for(let t=0;t<i;t++)e===0&&t===0||e===0&&t===i-1||e===i-1&&t===0||n.push([r[e],r[t]]);return n}})),Yt=n((e=>{var t=Z().getSymbolSize,n=7;e.getPositions=function(e){let r=t(e);return[[0,0],[r-n,0],[0,r-n]]}})),Xt=n((e=>{e.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};var t={N1:3,N2:3,N3:40,N4:10};e.isValid=function(e){return e!=null&&e!==``&&!isNaN(e)&&e>=0&&e<=7},e.from=function(t){return e.isValid(t)?parseInt(t,10):void 0},e.getPenaltyN1=function(e){let n=e.size,r=0,i=0,a=0,o=null,s=null;for(let c=0;c<n;c++){i=a=0,o=s=null;for(let l=0;l<n;l++){let n=e.get(c,l);n===o?i++:(i>=5&&(r+=t.N1+(i-5)),o=n,i=1),n=e.get(l,c),n===s?a++:(a>=5&&(r+=t.N1+(a-5)),s=n,a=1)}i>=5&&(r+=t.N1+(i-5)),a>=5&&(r+=t.N1+(a-5))}return r},e.getPenaltyN2=function(e){let n=e.size,r=0;for(let t=0;t<n-1;t++)for(let i=0;i<n-1;i++){let n=e.get(t,i)+e.get(t,i+1)+e.get(t+1,i)+e.get(t+1,i+1);(n===4||n===0)&&r++}return r*t.N2},e.getPenaltyN3=function(e){let n=e.size,r=0,i=0,a=0;for(let t=0;t<n;t++){i=a=0;for(let o=0;o<n;o++)i=i<<1&2047|e.get(t,o),o>=10&&(i===1488||i===93)&&r++,a=a<<1&2047|e.get(o,t),o>=10&&(a===1488||a===93)&&r++}return r*t.N3},e.getPenaltyN4=function(e){let n=0,r=e.data.length;for(let t=0;t<r;t++)n+=e.data[t];return Math.abs(Math.ceil(n*100/r/5)-10)*t.N4};function n(t,n,r){switch(t){case e.Patterns.PATTERN000:return(n+r)%2==0;case e.Patterns.PATTERN001:return n%2==0;case e.Patterns.PATTERN010:return r%3==0;case e.Patterns.PATTERN011:return(n+r)%3==0;case e.Patterns.PATTERN100:return(Math.floor(n/2)+Math.floor(r/3))%2==0;case e.Patterns.PATTERN101:return n*r%2+n*r%3==0;case e.Patterns.PATTERN110:return(n*r%2+n*r%3)%2==0;case e.Patterns.PATTERN111:return(n*r%3+(n+r)%2)%2==0;default:throw Error(`bad maskPattern:`+t)}}e.applyMask=function(e,t){let r=t.size;for(let i=0;i<r;i++)for(let a=0;a<r;a++)t.isReserved(a,i)||t.xor(a,i,n(e,a,i))},e.getBestMask=function(t,n){let r=Object.keys(e.Patterns).length,i=0,a=1/0;for(let o=0;o<r;o++){n(o),e.applyMask(o,t);let r=e.getPenaltyN1(t)+e.getPenaltyN2(t)+e.getPenaltyN3(t)+e.getPenaltyN4(t);e.applyMask(o,t),r<a&&(a=r,i=o)}return i}})),Zt=n((e=>{var t=Gt(),n=[1,1,1,1,1,1,1,1,1,1,2,2,1,2,2,4,1,2,4,4,2,4,4,4,2,4,6,5,2,4,6,6,2,5,8,8,4,5,8,8,4,5,8,11,4,8,10,11,4,9,12,16,4,9,16,16,6,10,12,18,6,10,17,16,6,11,16,19,6,13,18,21,7,14,21,25,8,16,20,25,8,17,23,25,9,17,23,34,9,18,25,30,10,20,27,32,12,21,29,35,12,23,34,37,12,25,34,40,13,26,35,42,14,28,38,45,15,29,40,48,16,31,43,51,17,33,45,54,18,35,48,57,19,37,51,60,19,38,53,63,20,40,56,66,21,43,59,70,22,45,62,74,24,47,65,77,25,49,68,81],r=[7,10,13,17,10,16,22,28,15,26,36,44,20,36,52,64,26,48,72,88,36,64,96,112,40,72,108,130,48,88,132,156,60,110,160,192,72,130,192,224,80,150,224,264,96,176,260,308,104,198,288,352,120,216,320,384,132,240,360,432,144,280,408,480,168,308,448,532,180,338,504,588,196,364,546,650,224,416,600,700,224,442,644,750,252,476,690,816,270,504,750,900,300,560,810,960,312,588,870,1050,336,644,952,1110,360,700,1020,1200,390,728,1050,1260,420,784,1140,1350,450,812,1200,1440,480,868,1290,1530,510,924,1350,1620,540,980,1440,1710,570,1036,1530,1800,570,1064,1590,1890,600,1120,1680,1980,630,1204,1770,2100,660,1260,1860,2220,720,1316,1950,2310,750,1372,2040,2430];e.getBlocksCount=function(e,r){switch(r){case t.L:return n[(e-1)*4+0];case t.M:return n[(e-1)*4+1];case t.Q:return n[(e-1)*4+2];case t.H:return n[(e-1)*4+3];default:return}},e.getTotalCodewordsCount=function(e,n){switch(n){case t.L:return r[(e-1)*4+0];case t.M:return r[(e-1)*4+1];case t.Q:return r[(e-1)*4+2];case t.H:return r[(e-1)*4+3];default:return}}})),Qt=n((e=>{var t=new Uint8Array(512),n=new Uint8Array(256);(function(){let e=1;for(let r=0;r<255;r++)t[r]=e,n[e]=r,e<<=1,e&256&&(e^=285);for(let e=255;e<512;e++)t[e]=t[e-255]})(),e.log=function(e){if(e<1)throw Error(`log(`+e+`)`);return n[e]},e.exp=function(e){return t[e]},e.mul=function(e,r){return e===0||r===0?0:t[n[e]+n[r]]}})),$t=n((e=>{var t=Qt();e.mul=function(e,n){let r=new Uint8Array(e.length+n.length-1);for(let i=0;i<e.length;i++)for(let a=0;a<n.length;a++)r[i+a]^=t.mul(e[i],n[a]);return r},e.mod=function(e,n){let r=new Uint8Array(e);for(;r.length-n.length>=0;){let e=r[0];for(let i=0;i<n.length;i++)r[i]^=t.mul(n[i],e);let i=0;for(;i<r.length&&r[i]===0;)i++;r=r.slice(i)}return r},e.generateECPolynomial=function(n){let r=new Uint8Array([1]);for(let i=0;i<n;i++)r=e.mul(r,new Uint8Array([1,t.exp(i)]));return r}})),en=n(((e,t)=>{var n=$t();function r(e){this.genPoly=void 0,this.degree=e,this.degree&&this.initialize(this.degree)}r.prototype.initialize=function(e){this.degree=e,this.genPoly=n.generateECPolynomial(this.degree)},r.prototype.encode=function(e){if(!this.genPoly)throw Error(`Encoder not initialized`);let t=new Uint8Array(e.length+this.degree);t.set(e);let r=n.mod(t,this.genPoly),i=this.degree-r.length;if(i>0){let e=new Uint8Array(this.degree);return e.set(r,i),e}return r},t.exports=r})),tn=n((e=>{e.isValid=function(e){return!isNaN(e)&&e>=1&&e<=40}})),nn=n((e=>{var t=`[0-9]+`,n=`[A-Z $%*+\\-./:]+`,r=`(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+`;r=r.replace(/u/g,`\\u`);var i=`(?:(?![A-Z0-9 $%*+\\-./:]|`+r+`)(?:.|[\r
2
- ]))+`;e.KANJI=new RegExp(r,`g`),e.BYTE_KANJI=RegExp(`[^A-Z0-9 $%*+\\-./:]+`,`g`),e.BYTE=new RegExp(i,`g`),e.NUMERIC=new RegExp(t,`g`),e.ALPHANUMERIC=new RegExp(n,`g`);var a=RegExp(`^`+r+`$`),o=RegExp(`^[0-9]+$`),s=RegExp(`^[A-Z0-9 $%*+\\-./:]+$`);e.testKanji=function(e){return a.test(e)},e.testNumeric=function(e){return o.test(e)},e.testAlphanumeric=function(e){return s.test(e)}})),Q=n((e=>{var t=tn(),n=nn();e.NUMERIC={id:`Numeric`,bit:1,ccBits:[10,12,14]},e.ALPHANUMERIC={id:`Alphanumeric`,bit:2,ccBits:[9,11,13]},e.BYTE={id:`Byte`,bit:4,ccBits:[8,16,16]},e.KANJI={id:`Kanji`,bit:8,ccBits:[8,10,12]},e.MIXED={bit:-1},e.getCharCountIndicator=function(e,n){if(!e.ccBits)throw Error(`Invalid mode: `+e);if(!t.isValid(n))throw Error(`Invalid version: `+n);return n>=1&&n<10?e.ccBits[0]:n<27?e.ccBits[1]:e.ccBits[2]},e.getBestModeForData=function(t){return n.testNumeric(t)?e.NUMERIC:n.testAlphanumeric(t)?e.ALPHANUMERIC:n.testKanji(t)?e.KANJI:e.BYTE},e.toString=function(e){if(e&&e.id)return e.id;throw Error(`Invalid mode`)},e.isValid=function(e){return e&&e.bit&&e.ccBits};function r(t){if(typeof t!=`string`)throw Error(`Param is not a string`);switch(t.toLowerCase()){case`numeric`:return e.NUMERIC;case`alphanumeric`:return e.ALPHANUMERIC;case`kanji`:return e.KANJI;case`byte`:return e.BYTE;default:throw Error(`Unknown mode: `+t)}}e.from=function(t,n){if(e.isValid(t))return t;try{return r(t)}catch{return n}}})),rn=n((e=>{var t=Z(),n=Zt(),r=Gt(),i=Q(),a=tn(),o=7973,s=t.getBCHDigit(o);function c(t,n,r){for(let i=1;i<=40;i++)if(n<=e.getCapacity(i,r,t))return i}function l(e,t){return i.getCharCountIndicator(e,t)+4}function u(e,t){let n=0;return e.forEach(function(e){let r=l(e.mode,t);n+=r+e.getBitsLength()}),n}function d(t,n){for(let r=1;r<=40;r++)if(u(t,r)<=e.getCapacity(r,n,i.MIXED))return r}e.from=function(e,t){return a.isValid(e)?parseInt(e,10):t},e.getCapacity=function(e,r,o){if(!a.isValid(e))throw Error(`Invalid QR Code version`);o===void 0&&(o=i.BYTE);let s=(t.getSymbolTotalCodewords(e)-n.getTotalCodewordsCount(e,r))*8;if(o===i.MIXED)return s;let c=s-l(o,e);switch(o){case i.NUMERIC:return Math.floor(c/10*3);case i.ALPHANUMERIC:return Math.floor(c/11*2);case i.KANJI:return Math.floor(c/13);case i.BYTE:default:return Math.floor(c/8)}},e.getBestVersionForData=function(e,t){let n,i=r.from(t,r.M);if(Array.isArray(e)){if(e.length>1)return d(e,i);if(e.length===0)return 1;n=e[0]}else n=e;return c(n.mode,n.getLength(),i)},e.getEncodedBits=function(e){if(!a.isValid(e)||e<7)throw Error(`Invalid QR Code version`);let n=e<<12;for(;t.getBCHDigit(n)-s>=0;)n^=o<<t.getBCHDigit(n)-s;return e<<12|n}})),an=n((e=>{var t=Z(),n=1335,r=21522,i=t.getBCHDigit(n);e.getEncodedBits=function(e,a){let o=e.bit<<3|a,s=o<<10;for(;t.getBCHDigit(s)-i>=0;)s^=n<<t.getBCHDigit(s)-i;return(o<<10|s)^r}})),on=n(((e,t)=>{var n=Q();function r(e){this.mode=n.NUMERIC,this.data=e.toString()}r.getBitsLength=function(e){return 10*Math.floor(e/3)+(e%3?e%3*3+1:0)},r.prototype.getLength=function(){return this.data.length},r.prototype.getBitsLength=function(){return r.getBitsLength(this.data.length)},r.prototype.write=function(e){let t,n,r;for(t=0;t+3<=this.data.length;t+=3)n=this.data.substr(t,3),r=parseInt(n,10),e.put(r,10);let i=this.data.length-t;i>0&&(n=this.data.substr(t),r=parseInt(n,10),e.put(r,i*3+1))},t.exports=r})),sn=n(((e,t)=>{var n=Q(),r=`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:`.split(``);function i(e){this.mode=n.ALPHANUMERIC,this.data=e}i.getBitsLength=function(e){return 11*Math.floor(e/2)+e%2*6},i.prototype.getLength=function(){return this.data.length},i.prototype.getBitsLength=function(){return i.getBitsLength(this.data.length)},i.prototype.write=function(e){let t;for(t=0;t+2<=this.data.length;t+=2){let n=r.indexOf(this.data[t])*45;n+=r.indexOf(this.data[t+1]),e.put(n,11)}this.data.length%2&&e.put(r.indexOf(this.data[t]),6)},t.exports=i})),cn=n(((e,t)=>{var n=Q();function r(e){this.mode=n.BYTE,typeof e==`string`?this.data=new TextEncoder().encode(e):this.data=new Uint8Array(e)}r.getBitsLength=function(e){return e*8},r.prototype.getLength=function(){return this.data.length},r.prototype.getBitsLength=function(){return r.getBitsLength(this.data.length)},r.prototype.write=function(e){for(let t=0,n=this.data.length;t<n;t++)e.put(this.data[t],8)},t.exports=r})),ln=n(((e,t)=>{var n=Q(),r=Z();function i(e){this.mode=n.KANJI,this.data=e}i.getBitsLength=function(e){return e*13},i.prototype.getLength=function(){return this.data.length},i.prototype.getBitsLength=function(){return i.getBitsLength(this.data.length)},i.prototype.write=function(e){let t;for(t=0;t<this.data.length;t++){let n=r.toSJIS(this.data[t]);if(n>=33088&&n<=40956)n-=33088;else if(n>=57408&&n<=60351)n-=49472;else throw Error(`Invalid SJIS character: `+this.data[t]+`
3
- Make sure your charset is UTF-8`);n=(n>>>8&255)*192+(n&255),e.put(n,13)}},t.exports=i})),un=n(((e,t)=>{var n={single_source_shortest_paths:function(e,t,r){var i={},a={};a[t]=0;var o=n.PriorityQueue.make();o.push(t,0);for(var s,c,l,u,d,f,p,m,h;!o.empty();)for(l in s=o.pop(),c=s.value,u=s.cost,d=e[c]||{},d)d.hasOwnProperty(l)&&(f=d[l],p=u+f,m=a[l],h=a[l]===void 0,(h||m>p)&&(a[l]=p,o.push(l,p),i[l]=c));if(r!==void 0&&a[r]===void 0){var g=[`Could not find a path from `,t,` to `,r,`.`].join(``);throw Error(g)}return i},extract_shortest_path_from_predecessor_list:function(e,t){for(var n=[],r=t;r;)n.push(r),e[r],r=e[r];return n.reverse(),n},find_path:function(e,t,r){var i=n.single_source_shortest_paths(e,t,r);return n.extract_shortest_path_from_predecessor_list(i,r)},PriorityQueue:{make:function(e){var t=n.PriorityQueue,r={},i;for(i in e||={},t)t.hasOwnProperty(i)&&(r[i]=t[i]);return r.queue=[],r.sorter=e.sorter||t.default_sorter,r},default_sorter:function(e,t){return e.cost-t.cost},push:function(e,t){var n={value:e,cost:t};this.queue.push(n),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return this.queue.length===0}}};t!==void 0&&(t.exports=n)})),dn=n((e=>{var t=Q(),n=on(),r=sn(),i=cn(),a=ln(),o=nn(),s=Z(),c=un();function l(e){return unescape(encodeURIComponent(e)).length}function u(e,t,n){let r=[],i;for(;(i=e.exec(n))!==null;)r.push({data:i[0],index:i.index,mode:t,length:i[0].length});return r}function d(e){let n=u(o.NUMERIC,t.NUMERIC,e),r=u(o.ALPHANUMERIC,t.ALPHANUMERIC,e),i,a;return s.isKanjiModeEnabled()?(i=u(o.BYTE,t.BYTE,e),a=u(o.KANJI,t.KANJI,e)):(i=u(o.BYTE_KANJI,t.BYTE,e),a=[]),n.concat(r,i,a).sort(function(e,t){return e.index-t.index}).map(function(e){return{data:e.data,mode:e.mode,length:e.length}})}function f(e,o){switch(o){case t.NUMERIC:return n.getBitsLength(e);case t.ALPHANUMERIC:return r.getBitsLength(e);case t.KANJI:return a.getBitsLength(e);case t.BYTE:return i.getBitsLength(e)}}function p(e){return e.reduce(function(e,t){let n=e.length-1>=0?e[e.length-1]:null;return n&&n.mode===t.mode?(e[e.length-1].data+=t.data,e):(e.push(t),e)},[])}function m(e){let n=[];for(let r=0;r<e.length;r++){let i=e[r];switch(i.mode){case t.NUMERIC:n.push([i,{data:i.data,mode:t.ALPHANUMERIC,length:i.length},{data:i.data,mode:t.BYTE,length:i.length}]);break;case t.ALPHANUMERIC:n.push([i,{data:i.data,mode:t.BYTE,length:i.length}]);break;case t.KANJI:n.push([i,{data:i.data,mode:t.BYTE,length:l(i.data)}]);break;case t.BYTE:n.push([{data:i.data,mode:t.BYTE,length:l(i.data)}])}}return n}function h(e,n){let r={},i={start:{}},a=[`start`];for(let o=0;o<e.length;o++){let s=e[o],c=[];for(let e=0;e<s.length;e++){let l=s[e],u=``+o+e;c.push(u),r[u]={node:l,lastCount:0},i[u]={};for(let e=0;e<a.length;e++){let o=a[e];r[o]&&r[o].node.mode===l.mode?(i[o][u]=f(r[o].lastCount+l.length,l.mode)-f(r[o].lastCount,l.mode),r[o].lastCount+=l.length):(r[o]&&(r[o].lastCount=l.length),i[o][u]=f(l.length,l.mode)+4+t.getCharCountIndicator(l.mode,n))}}a=c}for(let e=0;e<a.length;e++)i[a[e]].end=0;return{map:i,table:r}}function g(e,o){let c,l=t.getBestModeForData(e);if(c=t.from(o,l),c!==t.BYTE&&c.bit<l.bit)throw Error(`"`+e+`" cannot be encoded with mode `+t.toString(c)+`.
4
- Suggested mode is: `+t.toString(l));switch(c===t.KANJI&&!s.isKanjiModeEnabled()&&(c=t.BYTE),c){case t.NUMERIC:return new n(e);case t.ALPHANUMERIC:return new r(e);case t.KANJI:return new a(e);case t.BYTE:return new i(e)}}e.fromArray=function(e){return e.reduce(function(e,t){return typeof t==`string`?e.push(g(t,null)):t.data&&e.push(g(t.data,t.mode)),e},[])},e.fromString=function(t,n){let r=h(m(d(t,s.isKanjiModeEnabled())),n),i=c.find_path(r.map,`start`,`end`),a=[];for(let e=1;e<i.length-1;e++)a.push(r.table[i[e]].node);return e.fromArray(p(a))},e.rawSplit=function(t){return e.fromArray(d(t,s.isKanjiModeEnabled()))}})),fn=n((e=>{var t=Z(),n=Gt(),r=Kt(),i=qt(),a=Jt(),o=Yt(),s=Xt(),c=Zt(),l=en(),u=rn(),d=an(),f=Q(),p=dn();function m(e,t){let n=e.size,r=o.getPositions(t);for(let t=0;t<r.length;t++){let i=r[t][0],a=r[t][1];for(let t=-1;t<=7;t++)if(!(i+t<=-1||n<=i+t))for(let r=-1;r<=7;r++)a+r<=-1||n<=a+r||(t>=0&&t<=6&&(r===0||r===6)||r>=0&&r<=6&&(t===0||t===6)||t>=2&&t<=4&&r>=2&&r<=4?e.set(i+t,a+r,!0,!0):e.set(i+t,a+r,!1,!0))}}function h(e){let t=e.size;for(let n=8;n<t-8;n++){let t=n%2==0;e.set(n,6,t,!0),e.set(6,n,t,!0)}}function g(e,t){let n=a.getPositions(t);for(let t=0;t<n.length;t++){let r=n[t][0],i=n[t][1];for(let t=-2;t<=2;t++)for(let n=-2;n<=2;n++)t===-2||t===2||n===-2||n===2||t===0&&n===0?e.set(r+t,i+n,!0,!0):e.set(r+t,i+n,!1,!0)}}function _(e,t){let n=e.size,r=u.getEncodedBits(t),i,a,o;for(let t=0;t<18;t++)i=Math.floor(t/3),a=t%3+n-8-3,o=(r>>t&1)==1,e.set(i,a,o,!0),e.set(a,i,o,!0)}function v(e,t,n){let r=e.size,i=d.getEncodedBits(t,n),a,o;for(a=0;a<15;a++)o=(i>>a&1)==1,a<6?e.set(a,8,o,!0):a<8?e.set(a+1,8,o,!0):e.set(r-15+a,8,o,!0),a<8?e.set(8,r-a-1,o,!0):a<9?e.set(8,15-a-1+1,o,!0):e.set(8,15-a-1,o,!0);e.set(r-8,8,1,!0)}function y(e,t){let n=e.size,r=-1,i=n-1,a=7,o=0;for(let s=n-1;s>0;s-=2)for(s===6&&s--;;){for(let n=0;n<2;n++)if(!e.isReserved(i,s-n)){let r=!1;o<t.length&&(r=(t[o]>>>a&1)==1),e.set(i,s-n,r),a--,a===-1&&(o++,a=7)}if(i+=r,i<0||n<=i){i-=r,r=-r;break}}}function b(e,n,i){let a=new r;i.forEach(function(t){a.put(t.mode.bit,4),a.put(t.getLength(),f.getCharCountIndicator(t.mode,e)),t.write(a)});let o=(t.getSymbolTotalCodewords(e)-c.getTotalCodewordsCount(e,n))*8;for(a.getLengthInBits()+4<=o&&a.put(0,4);a.getLengthInBits()%8!=0;)a.putBit(0);let s=(o-a.getLengthInBits())/8;for(let e=0;e<s;e++)a.put(e%2?17:236,8);return x(a,e,n)}function x(e,n,r){let i=t.getSymbolTotalCodewords(n),a=i-c.getTotalCodewordsCount(n,r),o=c.getBlocksCount(n,r),s=o-i%o,u=Math.floor(i/o),d=Math.floor(a/o),f=d+1,p=u-d,m=new l(p),h=0,g=Array(o),_=Array(o),v=0,y=new Uint8Array(e.buffer);for(let e=0;e<o;e++){let t=e<s?d:f;g[e]=y.slice(h,h+t),_[e]=m.encode(g[e]),h+=t,v=Math.max(v,t)}let b=new Uint8Array(i),x=0,S,C;for(S=0;S<v;S++)for(C=0;C<o;C++)S<g[C].length&&(b[x++]=g[C][S]);for(S=0;S<p;S++)for(C=0;C<o;C++)b[x++]=_[C][S];return b}function S(e,n,r,a){let o;if(Array.isArray(e))o=p.fromArray(e);else if(typeof e==`string`){let t=n;if(!t){let n=p.rawSplit(e);t=u.getBestVersionForData(n,r)}o=p.fromString(e,t||40)}else throw Error(`Invalid data`);let c=u.getBestVersionForData(o,r);if(!c)throw Error(`The amount of data is too big to be stored in a QR Code`);if(!n)n=c;else if(n<c)throw Error(`
5
- The chosen QR Code version cannot contain this amount of data.
6
- Minimum version required to store current data is: `+c+`.
7
- `);let l=b(n,r,o),d=new i(t.getSymbolSize(n));return m(d,n),h(d),g(d,n),v(d,r,0),n>=7&&_(d,n),y(d,l),isNaN(a)&&(a=s.getBestMask(d,v.bind(null,d,r))),s.applyMask(a,d),v(d,r,a),{modules:d,version:n,errorCorrectionLevel:r,maskPattern:a,segments:o}}e.create=function(e,r){if(e===void 0||e===``)throw Error(`No input text`);let i=n.M,a,o;return r!==void 0&&(i=n.from(r.errorCorrectionLevel,n.M),a=u.from(r.version),o=s.from(r.maskPattern),r.toSJISFunc&&t.setToSJISFunction(r.toSJISFunc)),S(e,a,i,o)}})),pn=n((e=>{function t(e){if(typeof e==`number`&&(e=e.toString()),typeof e!=`string`)throw Error(`Color should be defined as hex string`);let t=e.slice().replace(`#`,``).split(``);if(t.length<3||t.length===5||t.length>8)throw Error(`Invalid hex color: `+e);(t.length===3||t.length===4)&&(t=Array.prototype.concat.apply([],t.map(function(e){return[e,e]}))),t.length===6&&t.push(`F`,`F`);let n=parseInt(t.join(``),16);return{r:n>>24&255,g:n>>16&255,b:n>>8&255,a:n&255,hex:`#`+t.slice(0,6).join(``)}}e.getOptions=function(e){e||={},e.color||={};let n=e.margin===void 0||e.margin===null||e.margin<0?4:e.margin,r=e.width&&e.width>=21?e.width:void 0,i=e.scale||4;return{width:r,scale:r?4:i,margin:n,color:{dark:t(e.color.dark||`#000000ff`),light:t(e.color.light||`#ffffffff`)},type:e.type,rendererOpts:e.rendererOpts||{}}},e.getScale=function(e,t){return t.width&&t.width>=e+t.margin*2?t.width/(e+t.margin*2):t.scale},e.getImageWidth=function(t,n){let r=e.getScale(t,n);return Math.floor((t+n.margin*2)*r)},e.qrToImageData=function(t,n,r){let i=n.modules.size,a=n.modules.data,o=e.getScale(i,r),s=Math.floor((i+r.margin*2)*o),c=r.margin*o,l=[r.color.light,r.color.dark];for(let e=0;e<s;e++)for(let n=0;n<s;n++){let u=(e*s+n)*4,d=r.color.light;if(e>=c&&n>=c&&e<s-c&&n<s-c){let t=Math.floor((e-c)/o),r=Math.floor((n-c)/o);d=l[+!!a[t*i+r]]}t[u++]=d.r,t[u++]=d.g,t[u++]=d.b,t[u]=d.a}}})),mn=n((e=>{var t=pn();function n(e,t,n){e.clearRect(0,0,t.width,t.height),t.style||={},t.height=n,t.width=n,t.style.height=n+`px`,t.style.width=n+`px`}function r(){try{return document.createElement(`canvas`)}catch{throw Error(`You need to specify a canvas element`)}}e.render=function(e,i,a){let o=a,s=i;o===void 0&&(!i||!i.getContext)&&(o=i,i=void 0),i||(s=r()),o=t.getOptions(o);let c=t.getImageWidth(e.modules.size,o),l=s.getContext(`2d`),u=l.createImageData(c,c);return t.qrToImageData(u.data,e,o),n(l,s,c),l.putImageData(u,0,0),s},e.renderToDataURL=function(t,n,r){let i=r;i===void 0&&(!n||!n.getContext)&&(i=n,n=void 0),i||={};let a=e.render(t,n,i),o=i.type||`image/png`,s=i.rendererOpts||{};return a.toDataURL(o,s.quality)}})),hn=n((e=>{var t=pn();function n(e,t){let n=e.a/255,r=t+`="`+e.hex+`"`;return n<1?r+` `+t+`-opacity="`+n.toFixed(2).slice(1)+`"`:r}function r(e,t,n){let r=e+t;return n!==void 0&&(r+=` `+n),r}function i(e,t,n){let i=``,a=0,o=!1,s=0;for(let c=0;c<e.length;c++){let l=Math.floor(c%t),u=Math.floor(c/t);!l&&!o&&(o=!0),e[c]?(s++,c>0&&l>0&&e[c-1]||(i+=o?r(`M`,l+n,.5+u+n):r(`m`,a,0),a=0,o=!1),l+1<t&&e[c+1]||(i+=r(`h`,s),s=0)):a++}return i}e.render=function(e,r,a){let o=t.getOptions(r),s=e.modules.size,c=e.modules.data,l=s+o.margin*2,u=o.color.light.a?`<path `+n(o.color.light,`fill`)+` d="M0 0h`+l+`v`+l+`H0z"/>`:``,d=`<path `+n(o.color.dark,`stroke`)+` d="`+i(c,s,o.margin)+`"/>`,f=`viewBox="0 0 `+l+` `+l+`"`,p=`<svg xmlns="http://www.w3.org/2000/svg" `+(o.width?`width="`+o.width+`" height="`+o.width+`" `:``)+f+` shape-rendering="crispEdges">`+u+d+`</svg>
8
- `;return typeof a==`function`&&a(null,p),p}})),gn=n((e=>{var t=Wt(),n=fn(),r=mn(),i=hn();function a(e,r,i,a,o){let s=[].slice.call(arguments,1),c=s.length,l=typeof s[c-1]==`function`;if(!l&&!t())throw Error(`Callback required as last argument`);if(l){if(c<2)throw Error(`Too few arguments provided`);c===2?(o=i,i=r,r=a=void 0):c===3&&(r.getContext&&o===void 0?(o=a,a=void 0):(o=a,a=i,i=r,r=void 0))}else{if(c<1)throw Error(`Too few arguments provided`);return c===1?(i=r,r=a=void 0):c===2&&!r.getContext&&(a=i,i=r,r=void 0),new Promise(function(t,o){try{t(e(n.create(i,a),r,a))}catch(e){o(e)}})}try{let t=n.create(i,a);o(null,e(t,r,a))}catch(e){o(e)}}e.create=n.create,e.toCanvas=a.bind(null,r.render),e.toDataURL=a.bind(null,r.renderToDataURL),e.toString=a.bind(null,function(e,t,n){return i.render(e,n)})})),_n=new Set([`created_by`,`updated_by`,`owner_id`]);function vn(e){return e?Array.isArray(e)?e.filter(e=>e&&e.name!=null).map(e=>[String(e.name),e]):Object.entries(e):[]}function yn(e,t,n){if(!e?.name||!Array.isArray(t)||t.length===0)return[];let r=e.name,i=[],a=[],o=n?.canRead;for(let e of t)if(e?.name&&!(o&&!o(e.name)))for(let[t,n]of vn(e.fields)){if(!n)continue;let o=n.type;if(o!==`lookup`&&o!==`master_detail`||(n.reference_to||n.reference)!==r||_n.has(t)||n.relatedList===!1)continue;let s={childObject:e.name,childLabel:e.label||e.name,referenceField:t,isOwned:o===`master_detail`,isPrimary:n.relatedList===`primary`,_fkLabel:typeof n.label==`string`&&n.label||t,...typeof n.relatedListTitle==`string`&&n.relatedListTitle?{title:n.relatedListTitle}:{},...Array.isArray(n.relatedListColumns)&&n.relatedListColumns.length>0?{columns:n.relatedListColumns}:{}};(s.isOwned?i:a).push(s)}let s=[...i,...a],c={};for(let e of s)c[e.childObject]=(c[e.childObject]||0)+1;return s.map(({_fkLabel:e,...t})=>!t.title&&c[t.childObject]>1?{...t,title:`${t.childLabel} · ${e}`}:t)}function bn(e){let{url:t,channel:n,autoReconnect:r=!0,reconnectInterval:i=1e3,maxReconnectAttempts:a=10,authToken:o}=e,[s,c]=(0,U.useState)(`disconnected`),[l,u]=(0,U.useState)(null),[d,f]=(0,U.useState)([]),[p,m]=(0,U.useState)(null),h=(0,U.useRef)(null),g=(0,U.useRef)(0),_=(0,U.useRef)(null),v=(0,U.useRef)(new Map),y=(0,U.useRef)([]),b=(0,U.useRef)(!0),x=(0,U.useRef)(!1),S=(0,U.useCallback)(()=>{_.current!==null&&(clearTimeout(_.current),_.current=null)},[]),C=(0,U.useCallback)(e=>{for(;y.current.length>0;){let t=y.current.shift(),r={type:t.type,channel:n,data:t.data,timestamp:new Date().toISOString()};e.send(JSON.stringify(r))}},[n]),ee=(0,U.useCallback)(()=>{if(typeof WebSocket>`u`){m(Error(`WebSocket is not available in this environment`)),c(`error`);return}if(!t){m(Error(`WebSocket URL is required`)),c(`error`);return}try{let e=new URL(t);if(e.protocol!==`ws:`&&e.protocol!==`wss:`){m(Error(`WebSocket URL must use ws: or wss: protocol`)),c(`error`);return}}catch{m(Error(`Invalid WebSocket URL`)),c(`error`);return}h.current&&=(x.current=!0,h.current.close(),null),x.current=!1,c(`connecting`),m(null);let e=o?`${t}?token=${encodeURIComponent(o)}&channel=${encodeURIComponent(n)}`:`${t}?channel=${encodeURIComponent(n)}`,s;try{s=new WebSocket(e)}catch(e){if(!b.current)return;let t=e instanceof Error?e:Error(`Failed to create WebSocket connection`);m(t),c(`error`);return}h.current=s,s.onopen=()=>{b.current&&(c(`connected`),m(null),g.current=0,C(s))},s.onmessage=e=>{if(b.current)try{let t=JSON.parse(String(e.data));if(t.channel!==n)return;u(t),f(e=>[...e,t]);let r=v.current.get(t.type);r&&r.forEach(e=>e(t.data))}catch{}},s.onerror=()=>{b.current&&(m(Error(`WebSocket connection error`)),c(`error`))},s.onclose=()=>{if(b.current){if(h.current=null,x.current){c(`disconnected`);return}if(r&&g.current<a){c(`reconnecting`);let e=Math.min(i*2**g.current,3e4);g.current+=1,_.current=setTimeout(()=>{b.current&&ee()},e)}else c(`disconnected`)}}},[t,n,o,r,i,a,C]),te=(0,U.useCallback)(()=>{S(),x.current=!0,g.current=0,h.current&&=(h.current.close(),null),c(`disconnected`)},[S]),w=(0,U.useCallback)(()=>{S(),g.current=0,ee()},[ee,S]),ne=(0,U.useCallback)((e,t)=>{let r=h.current;if(r&&r.readyState===WebSocket.OPEN){let i={type:e,channel:n,data:t,timestamp:new Date().toISOString()};r.send(JSON.stringify(i))}else y.current.push({type:e,data:t})},[n]),re=(0,U.useCallback)((e,t)=>(v.current.has(e)||v.current.set(e,new Set),v.current.get(e).add(t),()=>{let n=v.current.get(e);n&&(n.delete(t),n.size===0&&v.current.delete(e))}),[]);return(0,U.useEffect)(()=>(b.current=!0,t&&ee(),()=>{b.current=!1,S(),x.current=!0,h.current&&=(h.current.close(),null)}),[t,n,o]),{connectionState:s,isConnected:s===`connected`,lastMessage:l,messages:d,send:ne,subscribe:re,disconnect:te,reconnect:w,error:p}}var xn=0;function Sn(){return xn+=1,`conflict-${Date.now()}-${xn}`}var Cn=0;function wn(){return Cn+=1,`ver-${Date.now()}-${Cn}`}function Tn(e,t,n){let[r,i]=(0,U.useState)([]),[a,o]=(0,U.useState)([]);return{versions:r,currentVersion:(0,U.useMemo)(()=>r.length===0?0:r[r.length-1].version,[r]),conflicts:a,hasConflicts:a.length>0,recordVersion:(0,U.useCallback)((n,r)=>{i(i=>{let a=i.length===0?1:i[i.length-1].version+1,o={id:wn(),version:a,timestamp:new Date().toISOString(),userId:e,userName:t,changes:n,message:r};return[...i,o]})},[e,t]),resolveConflict:(0,U.useCallback)((n,r,a)=>{o(o=>{let s=o.find(e=>e.id===n);if(!s)return o;let c;switch(r){case`local`:c=s.localValue;break;case`remote`:c=s.remoteValue;break;case`merge`:c=a??s.localValue;break}return i(n=>{let i=n.length===0?1:n[n.length-1].version+1,a={id:wn(),version:i,timestamp:new Date().toISOString(),userId:e,userName:t,changes:{[s.field]:{before:s.baseValue,after:c}},message:`Resolved conflict on "${s.field}" using ${r} strategy`};return[...n,a]}),o.filter(e=>e.id!==n)})},[e,t]),resolveAllConflicts:(0,U.useCallback)(n=>{o(r=>{if(r.length===0)return r;let a={};for(let e of r)a[e.field]={before:e.baseValue,after:n===`local`?e.localValue:e.remoteValue};return i(r=>{let i=r.length===0?1:r[r.length-1].version+1,o={id:wn(),version:i,timestamp:new Date().toISOString(),userId:e,userName:t,changes:a,message:`Resolved all conflicts using ${n} strategy`};return[...r,o]}),[]})},[e,t]),revertToVersion:(0,U.useCallback)(n=>{let a=r.findIndex(e=>e.id===n);if(a===-1)return null;let o={};for(let e=0;e<=a;e++){let t=r[e];for(let[e,n]of Object.entries(t.changes))o[e]=n.after}let s={},c={};for(let e of r)for(let[t,n]of Object.entries(e.changes))c[t]=n.after;for(let[e,t]of Object.entries(o))c[e]!==t&&(s[e]={before:c[e],after:t});return Object.keys(s).length>0&&i(n=>{let i=n.length===0?1:n[n.length-1].version+1,o={id:wn(),version:i,timestamp:new Date().toISOString(),userId:e,userName:t,changes:s,message:`Reverted to version ${r[a].version}`};return[...n,o]}),o},[r,e,t]),compareVersions:(0,U.useCallback)((e,t)=>{let n=r.findIndex(t=>t.id===e),i=r.findIndex(e=>e.id===t);if(n===-1||i===-1)return null;let[a,o]=n<i?[n,i]:[i,n],s=e=>{let t={};for(let n=0;n<=e;n++)for(let[e,i]of Object.entries(r[n].changes))t[e]=i.after;return t},c=s(a),l=s(o),u=new Set([...Object.keys(c),...Object.keys(l)]),d={};for(let e of u){let t=c[e],n=l[e];t!==n&&(d[e]={before:t,after:n})}return d},[r]),addConflict:(0,U.useCallback)(e=>{let t={...e,id:Sn()};o(e=>[...e,t])},[]),clearHistory:(0,U.useCallback)(()=>{i([]),o([])},[])}}var En={sm:24,md:32,lg:40},Dn={active:`#22c55e`,idle:`#f59e0b`,away:`#94a3b8`};function On(e){return e.split(` `).map(e=>e[0]).join(``).toUpperCase().slice(0,2)}function kn({users:e,maxVisible:t=5,size:n=`md`,showStatus:r=!0,className:i}){let a=En[n],o=Math.round(a*.3),s=Math.round(a*.35),c=Math.max(8,Math.round(a*.28)),l=(0,U.useMemo)(()=>e.slice(0,t),[e,t]),u=Math.max(0,e.length-t),d={display:`inline-flex`,alignItems:`center`,flexDirection:`row-reverse`,fontFamily:`-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`},f={width:`${a}px`,height:`${a}px`,borderRadius:`50%`,border:`2px solid #fff`,display:`flex`,alignItems:`center`,justifyContent:`center`,fontSize:`${s}px`,fontWeight:600,color:`#fff`,position:`relative`,flexShrink:0,overflow:`hidden`,boxSizing:`border-box`},p={...f,backgroundColor:`#e2e8f0`,color:`#475569`,marginLeft:`-${o}px`},m={position:`absolute`,bottom:`-1px`,right:`-1px`,width:`${c}px`,height:`${c}px`,borderRadius:`50%`,border:`2px solid #fff`,boxSizing:`border-box`},h=(0,U.useMemo)(()=>[...l].reverse(),[l]);return U.createElement(`div`,{style:d,className:i,role:`group`,"aria-label":`${e.length} user${e.length===1?``:`s`} present`},u>0&&U.createElement(`div`,{key:`overflow`,style:p,title:`${u} more user${u===1?``:`s`}`},`+${u}`),h.map((e,t)=>U.createElement(`div`,{key:e.userId,style:{...f,backgroundColor:e.color,marginLeft:t>0||u>0?`-${o}px`:`0`},title:`${e.userName} (${e.status})`},e.avatar?U.createElement(`img`,{src:e.avatar,alt:e.userName,style:{width:`100%`,height:`100%`,objectFit:`cover`}}):On(e.userName),r&&U.createElement(`span`,{style:{...m,backgroundColor:Dn[e.status]}}))))}var An=U.createContext({});function jn(){let e=U.useContext(An),[t,n]=U.useState([]);return U.useEffect(()=>{if(!e.subscribeTenant){n([]);return}return e.subscribeTenant(e=>{n(Array.isArray(e)?e:[])})},[e]),t}function Mn(e,t){let n=U.useContext(An),[r,i]=U.useState([]);return U.useEffect(()=>{if(!n.subscribeRecord||!e||!t){i([]);return}return n.subscribeRecord({objectName:e,recordId:t},e=>{i(Array.isArray(e)?e:[])})},[n,e,t]),r}var Nn=gn();function Pn(){try{let e=u.get();return e?{Authorization:`Bearer ${e}`}:{}}catch{return{}}}var Fn=`recordId`,In=`form`,Ln=`formObject`,Rn=`formLink`,zn=`palette`,Bn=`shortcuts`,Vn=`from`,Hn=48;function Un(e){if(!e)return[];try{let t=JSON.parse(e);return Array.isArray(t)?t.filter(e=>!!e&&typeof e.o==`string`&&e.o.length>0&&typeof e.i==`string`&&e.i.length>0).slice(-8).map(e=>({o:e.o,i:e.i,...typeof e.t==`string`&&e.t.trim()?{t:e.t.trim().slice(0,Hn)}:{}})):[]}catch{return[]}}function Wn(e){return JSON.stringify(e.slice(-8))}function Gn(e,t){let n=Un(e),r=n[n.length-1];return(!r||r.o!==t.o||r.i!==t.i)&&n.push({o:t.o,i:t.i,...t.t&&t.t.trim()?{t:t.t.trim().slice(0,Hn)}:{}}),Wn(n)}function Kn(e,t,n){let r=`${e}/${t.o}/record/${encodeURIComponent(t.i)}`;if(n.length===0)return r;let i=new URLSearchParams;return i.set(Vn,Wn(n)),`${r}?${i.toString()}`}function qn(){return`${``.replace(/\/$/,``)}/api/v1`}async function Jn(e,t){let n=await fetch(`${qn()}${e}`,{credentials:`include`,headers:{"Content-Type":`application/json`,...Pn(),...t?.headers||{}},...t}),r=null;try{r=await n.json()}catch{}if(!n.ok){let e=Error(r?.error||`HTTP ${n.status}`);throw e.code=r?.code??`HTTP_${n.status}`,e.status=n.status,e}return r}function Yn(e,t,n){let[r,i]=(0,U.useState)(!1),[a,o]=(0,U.useState)(!0),[s,c]=(0,U.useState)([]),l=(0,U.useRef)(!1),u=(0,U.useCallback)(async()=>{if(!(!e||!t)&&!l.current){i(!0);try{let n=await Jn(`/approvals/requests?object=${encodeURIComponent(e)}&recordId=${encodeURIComponent(t)}`);c(n?.data??[]),o(!0)}catch(e){(e?.status===404||e?.status===501)&&(l.current=!0,o(!1))}finally{i(!1)}}},[e,t]);(0,U.useEffect)(()=>{if(!e||!t){c([]);return}u()},[e,t,u]);let d=(0,U.useMemo)(()=>s.find(e=>e.status===`pending`)??null,[s]),f=(0,U.useMemo)(()=>s.length===0?null:[...s].sort((e,t)=>{let n=e.submitted_at||e.completed_at||``;return(t.submitted_at||t.completed_at||``).localeCompare(n)})[0]??null,[s]),p=!!d&&!!n&&(d.pending_approvers??[]).includes(n),m=(0,U.useCallback)(async(e,t)=>{if(!d)throw Error(`No pending request`);let r=await Jn(`/approvals/requests/${encodeURIComponent(d.id)}/${e}`,{method:`POST`,body:JSON.stringify({...n?{actorId:n}:{},...t?.comment?{comment:t.comment}:{}})});return await u(),r?.request},[d,n,u]);return{loading:r,available:a,pendingRequest:d,latestRequest:f,canDecide:p,approve:(0,U.useCallback)(e=>m(`approve`,e),[m]),reject:(0,U.useCallback)(e=>m(`reject`,e),[m]),refresh:u}}var Xn={platform:{create:!0,import:!0,edit:!0,delete:!0,exportCsv:!0},config:{create:!0,import:!1,edit:!0,delete:!0,exportCsv:!0},system:{create:!1,import:!1,edit:!1,delete:!1,exportCsv:!0},"append-only":{create:!1,import:!1,edit:!1,delete:!1,exportCsv:!0},"better-auth":{create:!1,import:!1,edit:!1,delete:!1,exportCsv:!0}};function Zn(e,t){if(e==null)return{enabled:t};if(typeof e==`boolean`)return{enabled:e};let n=e.enabled??t;if(e.visibleWhen==null&&e.disabledWhen==null)return{enabled:n};let r={};return e.visibleWhen!=null&&(r.visibleWhen=e.visibleWhen),e.disabledWhen!=null&&(r.disabledWhen=e.disabledWhen),{enabled:n,predicates:r}}function Qn(e){let t=Xn[e?.managedBy??`platform`]??Xn.platform,n=e?.userActions??{},r=Zn(n.edit,t.edit),i=Zn(n.delete,t.delete),a={create:n.create??t.create,import:n.import??t.import,edit:r.enabled,delete:i.enabled,exportCsv:n.exportCsv??t.exportCsv};return r.predicates&&(a.editPredicates=r.predicates),i.predicates&&(a.deletePredicates=i.predicates),a}var $n=new Set([`record:discussion`,`record:chatter`]);function er(e){let t=new WeakSet,n=e=>{if(!e||typeof e!=`object`||t.has(e))return!1;if(t.add(e),Array.isArray(e))return e.some(n);let r=e?.type;return typeof r==`string`&&$n.has(r)?!0:[e.children,e.items,e.body,e.components,e.properties?.children,e.properties?.items,e.regions].some(n)};return n(e)}function tr({state:e,onOpenChange:t}){let{t:n}=Te(),r=()=>{e.resolve?.(!0),t(!1)},i=()=>{e.resolve?.(!1),t(!1)};return(0,W.jsx)(Qe,{open:e.open,onOpenChange:e=>{e||i()},children:(0,W.jsxs)(Se,{children:[(0,W.jsxs)(we,{children:[(0,W.jsx)(pe,{children:e.options?.title||n(`actionConfirm.title`)}),(0,W.jsx)(fe,{children:e.message})]}),(0,W.jsxs)(B,{children:[(0,W.jsx)(Ze,{onClick:i,children:e.options?.cancelText||n(`actionConfirm.cancel`)}),(0,W.jsx)(Ne,{onClick:r,children:e.options?.confirmText||n(`actionConfirm.confirm`)})]})]})})}var nr={checkbox:`boolean`,reference:`lookup`,"datetime-local":`datetime`,autonumber:`auto_number`};function rr(e){return Xe(nr[e]??e)}var ir=new Set([`lookup`,`master_detail`]);function ar(e){let t=rr(e.type);ir.has(t)&&!e.referenceTo&&(t=`text`);let n={name:e.name,label:e.label,type:t,required:e.required,placeholder:e.placeholder,options:e.options,multiple:e.multiple,accept:e.accept,maxSize:e.maxSize};return t===`boolean`&&(n.widget=`checkbox`),(ir.has(t)||t===`user`||t===`owner`)&&Object.assign(n,{reference_to:e.referenceTo,display_field:e.displayField,id_field:e.idField,description_field:e.descriptionField,title_format:e.titleFormat,lookup_columns:e.lookupColumns,lookup_filters:e.lookupFilters,lookup_page_size:e.lookupPageSize,depends_on:e.dependsOn}),n}function or(e,t){let n=new y(t);return e.filter(e=>{if(!e.visible)return!0;try{return n.evaluateCondition(e.visible)}catch{return!0}})}function sr(){return(0,W.jsx)(`div`,{className:`h-9 w-full animate-pulse rounded-md bg-muted`,"aria-hidden":`true`})}function cr({state:e,onOpenChange:t}){let{t:n,language:r}=Te(),[i,a]=(0,U.useState)({}),[o,s]=(0,U.useState)({}),c=S(),l=(0,U.useMemo)(()=>or(e.params,c),[e.params,c]);(0,U.useEffect)(()=>{if(e.open){let e={};for(let t of l)t.defaultValue!==void 0&&(e[t.name]=t.defaultValue);a(e),s({})}},[e.open,l]);let u=e=>e==null?!0:typeof e==`string`?e.trim()===``:Array.isArray(e)?e.length===0:!1,d=()=>{let n={};for(let e of l)e.required&&u(i[e.name])&&(n[e.name]=!0);if(Object.keys(n).length>0){s(n);return}e.resolve?.(i),t(!1)},f=()=>{e.resolve?.(null),t(!1)},p=(e,t)=>{a(n=>({...n,[e]:t})),s(t=>({...t,[e]:!1}))};return(0,W.jsx)(k,{open:e.open,onOpenChange:e=>{e||f()},children:(0,W.jsxs)(A,{children:[(0,W.jsxs)(j,{children:[(0,W.jsx)(R,{children:e.title||n(`actionDialog.title`)}),(0,W.jsx)(O,{children:e.description||n(`actionDialog.description`)})]}),(0,W.jsx)(`div`,{className:`grid gap-4 py-4`,children:l.map(e=>{let t={...e,label:T(e.label,r),helpText:e.helpText==null?e.helpText:T(e.helpText,r),options:e.options?.map(e=>({...e,label:T(e.label,r)}))},a=ar(t),s=Le(a.type),c=t.type===`lookup`||t.type===`reference`;return a.type===`select`&&!a.placeholder&&(a.placeholder=n(`actionDialog.selectPlaceholder`,{label:t.label})),c&&a.type===`text`&&!a.placeholder&&(a.placeholder=n(`actionDialog.lookupPlaceholder`,{label:t.label})),a.type===`boolean`?(0,W.jsxs)(`div`,{className:`grid gap-1`,children:[(0,W.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,W.jsx)(U.Suspense,{fallback:(0,W.jsx)(`div`,{className:`size-4 mt-0.5 animate-pulse rounded-sm bg-muted`,"aria-hidden":`true`}),children:(0,W.jsx)(s,{value:i[t.name]===!0,onChange:e=>p(t.name,e===!0),field:a,className:`mt-0.5`})}),(0,W.jsxs)(z,{htmlFor:t.name,className:`font-normal cursor-pointer`,children:[t.label,t.required&&(0,W.jsx)(`span`,{className:`text-destructive ml-1`,children:`*`})]})]}),o[t.name]&&(0,W.jsx)(`p`,{className:`text-xs text-destructive ml-6`,children:n(`actionDialog.requiredError`,{label:t.label})}),t.helpText&&(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground ml-6`,children:t.helpText})]},t.name):(0,W.jsxs)(`div`,{className:`grid gap-2`,children:[(0,W.jsxs)(z,{htmlFor:t.name,children:[t.label,t.required&&(0,W.jsx)(`span`,{className:`text-destructive ml-1`,children:`*`})]}),(0,W.jsx)(U.Suspense,{fallback:(0,W.jsx)(sr,{}),children:(0,W.jsx)(s,{id:t.name,value:i[t.name]??null,onChange:e=>p(t.name,e),field:a,className:o[t.name]?`border-destructive`:``})}),o[t.name]&&(0,W.jsx)(`p`,{className:`text-xs text-destructive`,children:n(`actionDialog.requiredError`,{label:t.label})}),t.helpText&&(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:t.helpText}),c&&!t.helpText&&(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`actionDialog.lookupHelpText`)})]},t.name)})}),(0,W.jsxs)(ce,{children:[(0,W.jsx)(D,{variant:`outline`,onClick:f,children:n(`actionDialog.cancel`)}),(0,W.jsx)(D,{onClick:d,children:n(`actionDialog.confirm`)})]})]})})}function lr(e,t){if(e!=null)return t.split(`.`).reduce((e,t)=>{if(e!=null)return e[t]},e)}function ur({state:e,onAcknowledge:t}){let{t:n}=Te(),{spec:r,data:i}=e,a=(0,U.useMemo)(()=>(r?.fields&&r.fields.length>0?r.fields:[{path:``,label:void 0,format:r?.format??`json`}]).map(e=>({field:e,value:e.path===``?i:lr(i,e.path)})).filter(({field:e,value:t})=>e.path===``||t!==void 0),[r,i]);return(0,W.jsx)(k,{open:e.open,onOpenChange:e=>{},children:(0,W.jsxs)(A,{onPointerDownOutside:e=>e.preventDefault(),onEscapeKeyDown:e=>e.preventDefault(),className:`max-w-lg`,children:[(0,W.jsxs)(j,{children:[(0,W.jsx)(R,{children:r?.title||n(`actions.resultDialog.defaultTitle`)||`Save this value now`}),r?.description?(0,W.jsx)(O,{children:r.description}):null]}),(0,W.jsx)(`div`,{className:`space-y-4 py-2`,children:a.map(({field:e,value:t},n)=>(0,W.jsx)(dr,{field:e,value:t,defaultFormat:r?.format},`${e.path}-${n}`))}),(0,W.jsx)(ce,{children:(0,W.jsx)(D,{onClick:t,children:r?.acknowledge||n(`actions.resultDialog.acknowledge`)||`I have saved this`})})]})})}function dr({field:e,value:t,defaultFormat:n}){let r=e.format??n??`json`,i=e.label,a=r===`qrcode`&&typeof t!=`string`||r===`code-list`&&!Array.isArray(t)||(r===`secret`||r===`text`)&&typeof t!=`string`?`json`:r;return(0,W.jsxs)(`div`,{className:`space-y-1.5`,children:[i?(0,W.jsx)(`div`,{className:`text-sm font-medium text-foreground/80`,children:i}):null,a===`qrcode`?(0,W.jsx)(mr,{value:t}):null,a===`code-list`?(0,W.jsx)(hr,{value:t}):null,a===`secret`?(0,W.jsx)(gr,{value:t}):null,a===`text`?(0,W.jsx)(_r,{value:t}):null,a===`json`?(0,W.jsx)(vr,{value:t}):null]})}function fr(e){let[t,n]=(0,U.useState)(!1);return(0,U.useEffect)(()=>{if(!t)return;let e=setTimeout(()=>n(!1),1500);return()=>clearTimeout(e)},[t]),{copy:async()=>{if(e!=null)try{await navigator.clipboard.writeText(e),n(!0)}catch{}},copied:t}}function pr({value:e,label:t}){let{copy:n,copied:r}=fr(e);return(0,W.jsxs)(D,{type:`button`,variant:`outline`,size:`sm`,onClick:n,children:[r?(0,W.jsx)(Ge,{className:`w-4 h-4`}):(0,W.jsx)(ze,{className:`w-4 h-4`}),t?(0,W.jsx)(`span`,{className:`ml-2`,children:t}):null]})}function mr({value:e}){let[t,n]=(0,U.useState)(null);return(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(`div`,{className:`flex justify-center rounded-md border bg-white p-3`,children:t?(0,W.jsx)(`span`,{className:`text-sm text-destructive`,children:t}):(0,W.jsx)(`canvas`,{ref:t=>{!t||!e||(0,Nn.toCanvas)(t,e,{width:200,margin:1},e=>{e&&n(e.message)})}})}),(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`code`,{className:`flex-1 truncate rounded bg-muted px-2 py-1 text-xs font-mono`,children:e}),(0,W.jsx)(pr,{value:e})]})]})}function hr({value:e}){let t=e.join(`
9
- `);return(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(`div`,{className:`rounded-md border bg-muted/40 p-2`,children:(0,W.jsx)(`ul`,{className:`space-y-1`,children:e.map((e,t)=>(0,W.jsxs)(`li`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`code`,{className:`flex-1 rounded bg-background px-2 py-1 text-sm font-mono`,children:e}),(0,W.jsx)(pr,{value:e})]},`${t}-${e}`))})}),(0,W.jsx)(`div`,{className:`flex justify-end`,children:(0,W.jsx)(pr,{value:t,label:`Copy all`})})]})}function gr({value:e}){let[t,n]=(0,U.useState)(!1);return(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`code`,{className:`flex-1 rounded bg-muted px-2 py-1 text-sm font-mono break-all`,children:t?e:e.replace(/./g,`•`)}),(0,W.jsx)(D,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>n(e=>!e),children:t?(0,W.jsx)(Ie,{className:`w-4 h-4`}):(0,W.jsx)(le,{className:`w-4 h-4`})}),(0,W.jsx)(pr,{value:e})]})}function _r({value:e}){return(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`code`,{className:`flex-1 rounded bg-muted px-2 py-1 text-sm font-mono break-all`,children:e}),(0,W.jsx)(pr,{value:e})]})}function vr({value:e}){let t=(0,U.useMemo)(()=>{try{return JSON.stringify(e,null,2)}catch{return String(e)}},[e]);return(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(`pre`,{className:`max-h-80 overflow-auto rounded-md border bg-muted/40 p-3 text-xs font-mono`,children:t}),(0,W.jsx)(`div`,{className:`flex justify-end`,children:(0,W.jsx)(pr,{value:t})})]})}function yr(e){return e.kind===`object-form`&&!!e.objectName}function br(e){let t={};for(let n of e.fields)n.defaultValue!==void 0&&(t[n.name]=n.defaultValue);return t}function xr({screen:e,values:t,onValueChange:n,dataSource:r,objects:i,objectForm:a,className:o}){if(yr(e)){let t=Array.isArray(i)?i.find(t=>t?.name===e.objectName):void 0,n=t?t.form?.subforms??t.formViews?.default?.subforms:void 0;return(0,W.jsx)(`div`,{className:E(`py-2`,o),children:r?(0,W.jsx)($e,{schema:{type:`object-form`,formType:`simple`,objectName:e.objectName,mode:e.mode===`edit`?`edit`:`create`,recordId:e.mode===`edit`?e.recordId:void 0,...e.defaults?{initialValues:e.defaults}:{},layout:`vertical`,subforms:n,onSuccess:a?.onSuccess,onCancel:a?.onCancel,showSubmit:a?.showSubmit??!0,showCancel:a?.showCancel??!0,submitText:a?.submitText??`Save & Continue`,cancelText:a?.cancelText??`Cancel`},dataSource:r},e.nodeId):(0,W.jsx)(`div`,{className:`text-sm text-destructive py-4`,children:a?.noDataSourceMessage??`This step renders an object form but no data source is available.`})})}return(0,W.jsx)(`div`,{className:E(`space-y-4 py-2`,o),children:e.fields.map(e=>(0,W.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,W.jsxs)(z,{htmlFor:`ff-${e.name}`,className:`text-sm`,children:[e.label||e.name,e.required&&(0,W.jsx)(`span`,{className:`text-destructive`,children:` *`})]}),(0,W.jsx)(Sr,{field:e,value:t[e.name],onChange:t=>n(e.name,t)})]},e.name))})}function Sr({field:e,value:t,onChange:n}){let r=`ff-${e.name}`,i=(e.type||`text`).toLowerCase();if(Array.isArray(e.options)&&e.options.length>0)return(0,W.jsxs)(ue,{value:t==null?void 0:String(t),onValueChange:e=>n(e),children:[(0,W.jsx)(N,{id:r,children:(0,W.jsx)(qe,{placeholder:e.placeholder||`Select…`})}),(0,W.jsx)(Fe,{children:e.options.map((e,t)=>(0,W.jsx)(Je,{value:String(e.value),children:e.label},t))})]});if(i===`boolean`||i===`checkbox`)return(0,W.jsx)(je,{id:r,checked:t===!0,onCheckedChange:e=>n(e===!0)});if(i===`textarea`||i===`markdown`)return(0,W.jsx)(We,{id:r,value:t??``,placeholder:e.placeholder,onChange:e=>n(e.target.value)});let a=i===`number`||i===`currency`?`number`:i===`email`?`email`:i===`date`?`date`:`text`;return(0,W.jsx)(M,{id:r,type:a,value:t??``,placeholder:e.placeholder,onChange:e=>n(a===`number`?e.target.value===``?void 0:Number(e.target.value):e.target.value)})}function Cr({state:e,authFetch:t,baseUrl:n,onClose:r,onComplete:i,dataSource:a,objects:o}){let[s,c]=(0,U.useState)(null),[l,u]=(0,U.useState)(``),[d,f]=(0,U.useState)(``),[p,m]=(0,U.useState)({}),[h,g]=(0,U.useState)(!1);if((0,U.useEffect)(()=>{e&&(c(e.screen),u(e.runId),f(e.flowName),m(br(e.screen)))},[e]),!e||!s)return null;let _=(e,t)=>m(n=>({...n,[e]:t})),v=async e=>{let a=await t(`${n}/api/v1/automation/${encodeURIComponent(d)}/runs/${encodeURIComponent(l)}/resume`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({inputs:e})}),o=await a.json().catch(()=>null);if(!a.ok||o?.success===!1){V.error(o?.error||`Resume failed (HTTP ${a.status})`);return}let s=o?.data??{};if(s.success===!1||s.status===`failed`){V.error(s.errorMessage||s.error||`The flow failed to complete.`),r();return}s.status===`paused`&&s.screen?(c(s.screen),u(s.runId||l),m(br(s.screen)),V.success(`Saved — next step`)):(V.success(s.successMessage||`Done`),i())},y=async()=>{let e=s.fields.filter(e=>e.required&&(p[e.name]===void 0||p[e.name]===``||p[e.name]===null));if(e.length){V.error(`Please fill: ${e.map(e=>e.label||e.name).join(`, `)}`);return}g(!0);try{await v(p)}catch(e){V.error(e.message)}finally{g(!1)}},b=async e=>{let t=e?.id??e?.data?.id??e?.record?.id,n=s.idVariable&&t!=null?{[s.idVariable]:t}:{};g(!0);try{await v(n)}catch(e){V.error(e.message)}finally{g(!1)}},x=yr(s);return(0,W.jsx)(k,{open:!0,onOpenChange:e=>{!e&&!h&&r()},children:(0,W.jsxs)(A,{className:x?`sm:max-w-3xl max-h-[90vh] overflow-y-auto`:`sm:max-w-md`,children:[(0,W.jsxs)(j,{children:[(0,W.jsx)(R,{children:s.title||`Input`}),s.description&&(0,W.jsx)(O,{children:s.description})]}),(0,W.jsx)(xr,{screen:s,values:p,onValueChange:_,dataSource:a,objects:o,objectForm:{onSuccess:b,onCancel:r,showSubmit:!0,showCancel:!0,submitText:`Save & Continue`,cancelText:`Cancel`}}),!x&&(0,W.jsxs)(ce,{children:[(0,W.jsx)(D,{variant:`outline`,onClick:r,disabled:h,children:`Cancel`}),(0,W.jsx)(D,{onClick:y,disabled:h,children:h?`Submitting…`:`Submit`})]})]})})}function wr(e){ie({objectName:e})}function Tr(e,t,n){return(Array.isArray(e?.actions)?e.actions:[]).filter(e=>Array.isArray(e?.locations)&&e.locations.includes(n)).map(n=>({...n,label:t(e.name,n.name,n.label||n.name)}))}function Er({appName:e,objects:t,dataSource:n,actionLabel:r,parentObjectName:i,parentRecordId:s,parentTitle:c,children:l}){let u=a(),{execute:d}=v(),[,f]=o(),p=e?`/apps/${e}`:``,m=(0,U.useCallback)(e=>{let t=new URLSearchParams(window.location.search);t.set(In,e.recordId??`new`),t.set(Ln,e.objectName),e.link?t.set(Rn,`${e.link.field}:${e.link.parentId}`):t.delete(Rn),f(t)},[f]),h=(0,U.useCallback)(async(e,t,n)=>{let r=t?.id??t?._id,{params:i,...a}=n,o={...a,objectName:e,...r==null?{}:{recordId:String(r)},params:{_rowRecord:t}};Array.isArray(i)&&i.length>0&&(o.actionParams=i),(await d(o))?.success&&wr(e)},[d]);return(0,W.jsx)(re,{value:(0,U.useMemo)(()=>({resolve:({objectName:e,relationshipField:a,parentId:o})=>{let l=t.find(t=>t?.name===e);if(!l||!p)return{};let d=Qn(l),f=t=>{let n=`${p}/${e}/record/${encodeURIComponent(String(t))}`;if(i&&s){let e=Gn(new URLSearchParams(window.location.search).get(Vn),{o:i,i:s,...c?{t:c}:{}}),t=new URLSearchParams;return t.set(Vn,e),`${n}?${t.toString()}`}return n},g={onView:e=>u(f(e))};d.create&&(g.onCreate=()=>{m({objectName:e,link:a&&o!=null&&o!==``?{field:a,parentId:o}:void 0})}),d.edit&&(g.onEdit=t=>m({objectName:e,recordId:String(t)})),d.delete&&(g.onDelete=async t=>{await n?.delete?.(e,String(t))});let _=Tr(l,r,`list_item`);_.length>0&&(g.rowActions=_,g.onRowAction=(t,n)=>h(e,n,t));let v=Tr(l,r,`list_toolbar`);return v.length>0&&(g.toolbarActions=v,g.onToolbarAction=t=>h(e,void 0,t)),g}}),[t,p,u,n,r,h,m,i,s,c]),children:l})}var Dr=[`regions`,`components`,`children`];function Or(e,t){if(Array.isArray(e)){let n=null;return e.forEach((r,i)=>{let a=Or(r,t);a!==r&&(n??=e.slice(),n[i]=a)}),n??e}if(!e||typeof e!=`object`)return e;let n=e,r=null;n.type===`page:tabs`&&(r={...n},t.defaultTab!==void 0&&(r.defaultTab=t.defaultTab),t.onTabChange&&(r.onTabChange=t.onTabChange));for(let e of Dr){let i=(r??n)[e];if(i==null)continue;let a=Or(i,t);a!==i&&(r??={...n},r[e]=a)}return r??e}function kr(e,t,n,r){if(!(!Array.isArray(e)||e.length===0))return e.map(e=>{let i=typeof e==`string`?{label:e,value:e}:e;return{label:r?r(t,n,i.value,i.label):i.label,value:i.value}})}function Ar(e){if(typeof e==`string`)return e||void 0;if(e&&typeof e==`object`&&typeof e.source==`string`)return e.source||void 0}function jr(e,t){let n=e.field??e.name,r=e.defaultFromRow&&t.row&&n!=null&&Object.prototype.hasOwnProperty.call(t.row,n)?t.row[n]:void 0;if(!e.field)return{name:e.name??``,label:e.label??e.name??``,type:e.type??`text`,required:e.required??!1,options:e.options,placeholder:e.placeholder,helpText:e.helpText,defaultValue:r??e.defaultValue,visible:Ar(e.visible),multiple:e.multiple,accept:e.accept,maxSize:e.maxSize};let i=e.objectOverride??t.objectName,a=t.objects.find(e=>e?.name===i)?.fields?.[e.field];if(!a)return{name:e.name??e.field,label:e.label??t.fieldLabel(i,e.field,e.field),type:e.type??`text`,required:e.required??!1,options:e.options,placeholder:e.placeholder,helpText:e.helpText,defaultValue:r??e.defaultValue,visible:Ar(e.visible),multiple:e.multiple,accept:e.accept,maxSize:e.maxSize};let o=e.type??a.type??`text`,s=e.options??kr(a.options,i,e.field,t.fieldOptionLabel),c=e.label??t.fieldLabel(i,e.field,a.label??e.field),l=o===`lookup`||o===`reference`?{referenceTo:a.reference_to??a.reference,displayField:a.display_field??a.reference_field,idField:a.id_field,descriptionField:a.description_field,titleFormat:a.title_format,lookupColumns:a.lookup_columns,lookupFilters:a.lookup_filters,lookupPageSize:a.lookup_page_size,dependsOn:a.depends_on}:{};return{name:e.name??e.field,label:c,type:o,required:e.required??a.required??!1,options:s,placeholder:e.placeholder??a.placeholder,helpText:e.helpText??a.help??a.description,defaultValue:r??e.defaultValue??a.defaultValue,visible:Ar(e.visible),multiple:e.multiple??a.multiple,accept:e.accept??a.accept,maxSize:e.maxSize??a.maxSize,...l}}function Mr(e,t){return Array.isArray(e)?e.map(e=>jr(e,t)):[]}function Nr(e){return e==null||!Number.isFinite(e)?``:e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}var Pr=({objectName:e,recordId:t,dataSource:n,currentUserId:r,className:i})=>{let{t:a}=Te(),[o,s]=U.useState([]),[c,l]=U.useState(!1),[u,f]=U.useState(!1),[p,m]=U.useState(null),h=U.useRef(null),g=U.useMemo(()=>d(),[]),_=U.useMemo(()=>Ce({baseUrl:``,scope:`attachments`,fetchImpl:g}),[``,g]),v=U.useCallback(e=>{let t=e,n=String(t?.message??e??``),r=e=>t?.code===e||n.includes(e);return r(`ATTACHMENT_DELETE_DENIED`)?a(`detail.attachmentDeleteDenied`,{defaultValue:`Only the uploader or someone who can edit this record may delete this attachment.`}):r(`ATTACHMENT_PARENT_ACCESS`)?a(`detail.attachmentParentAccessDenied`,{defaultValue:`You don't have access to attach files to this record.`}):r(`ATTACHMENT_DOWNLOAD_DENIED`)?a(`detail.attachmentDownloadDenied`,{defaultValue:`You don't have access to download this attachment.`}):r(`AUTH_REQUIRED`)?a(`detail.attachmentAuthRequired`,{defaultValue:`Please sign in to download this attachment.`}):r(`PERMISSION_DENIED`)?a(`detail.attachmentPermissionDenied`,{defaultValue:`You don't have permission to do that.`}):n},[a]),y=U.useCallback(async()=>{if(!(!n||!e||!t)){l(!0);try{let r=await n.find(`sys_attachment`,{$filter:{parent_object:e,parent_id:t},$orderby:{created_at:`desc`},$top:100}),i=Array.isArray(r)?r:r?.data??[];s(i)}catch{s([])}finally{l(!1)}}},[n,e,t]);U.useEffect(()=>{y()},[y]);let b=U.useCallback(async i=>{if(!(!i||i.length===0||!n)){f(!0),m(null);try{for(let a of Array.from(i)){let i=await _.upload(a),o=i.meta?.fileId;if(!o)throw Error(`Upload did not return a fileId`);await n.create(`sys_attachment`,{parent_object:e,parent_id:t,file_id:o,file_name:i.name??a.name,mime_type:i.mimeType??a.type,size:i.size??a.size,...r?{uploaded_by:r}:{}})}await y()}catch(e){m(v(e))}finally{f(!1),h.current&&(h.current.value=``)}}},[_,n,e,t,r,y]),x=U.useCallback(async e=>{if(n){m(null);try{await n.delete(`sys_attachment`,e.id),s(t=>t.filter(t=>t.id!==e.id))}catch(e){m(v(e))}}},[n,v]),S=U.useCallback(async e=>{m(null);try{let t=await g(`/api/v1/storage/files/${encodeURIComponent(e.file_id)}/url`);if(!t.ok){let e;try{e=(await t.json())?.code}catch{}throw Object.assign(Error(e??`Download failed (${t.status})`),{code:e})}let n=await t.json(),r=n?.url??n?.data?.url;if(!r)throw Error(`Download URL missing from response`);let i=/^https?:/i.test(r)?r:`${r}`;window.open(i,`_blank`,`noopener,noreferrer`)}catch(e){m(v(e))}},[g,``,v]);return(0,W.jsxs)(`div`,{className:E(`rounded-lg border bg-card`,i),"data-testid":`record-attachments-panel`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium`,children:[(0,W.jsx)(Re,{className:`h-4 w-4 text-muted-foreground`}),(0,W.jsx)(`span`,{children:a(`detail.attachments`,{defaultValue:`Attachments`})}),o.length>0&&(0,W.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`(`,o.length,`)`]})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`input`,{ref:h,type:`file`,multiple:!0,className:`hidden`,onChange:e=>void b(e.target.files)}),(0,W.jsxs)(D,{variant:`outline`,size:`sm`,disabled:u,onClick:()=>h.current?.click(),children:[u?(0,W.jsx)(F,{className:`h-4 w-4 mr-1 animate-spin`}):(0,W.jsx)(I,{className:`h-4 w-4 mr-1`}),a(`detail.uploadAttachment`,{defaultValue:`Upload`})]})]})]}),p&&(0,W.jsx)(`div`,{className:`px-4 py-2 text-xs text-destructive border-b`,role:`alert`,children:p}),c&&o.length===0?(0,W.jsxs)(`div`,{className:`px-4 py-6 text-sm text-muted-foreground flex items-center gap-2`,children:[(0,W.jsx)(F,{className:`h-4 w-4 animate-spin`}),a(`detail.loadingAttachments`,{defaultValue:`Loading attachments…`})]}):o.length===0?(0,W.jsx)(`div`,{className:`px-4 py-6 text-sm text-muted-foreground`,children:a(`detail.noAttachments`,{defaultValue:`No attachments yet. Upload a file to get started.`})}):(0,W.jsx)(`ul`,{className:`divide-y`,children:o.map(e=>(0,W.jsxs)(`li`,{className:`flex items-center gap-3 px-4 py-2.5`,children:[(0,W.jsx)(Re,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,W.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,W.jsx)(`div`,{className:`truncate text-sm`,children:e.file_name||e.file_id}),(0,W.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:[Nr(e.size),e.mime_type||void 0].filter(Boolean).join(` · `)})]}),(0,W.jsx)(D,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,"aria-label":a(`detail.downloadAttachment`,{defaultValue:`Download`}),onClick:()=>void S(e),children:(0,W.jsx)(Me,{className:`h-4 w-4`})}),(0,W.jsx)(D,{variant:`ghost`,size:`icon`,className:`h-8 w-8 text-muted-foreground hover:text-destructive`,"aria-label":a(`detail.deleteAttachment`,{defaultValue:`Delete attachment`}),onClick:()=>void x(e),children:(0,W.jsx)(Pe,{className:`h-4 w-4`})})]},e.id))})]})};function Fr(){let e=et()===`zh-CN`;return U.useMemo(()=>e?{title:`已分配用户`,add:`添加用户`,remove:`移除`,empty:`还没有分配任何用户。点击「添加用户」来分配。`,loading:`加载中…`,pickTitle:`选择要分配的用户`,seatFull:e=>`AI 席位已用完(`+e+`/`+e+`)。请先移除一个用户,或在许可证中提升席位上限,再分配新用户。`,addFailed:`分配失败,请重试。`,countOf:e=>e+` 人`,direct:`直授`,viaPosition:e=>`经岗位 `+e,everyoneNote:`已绑定到 everyone 锚点 — 所有登录成员都持有此权限集。`,positionHeldHint:`经岗位持有 — 在岗位的指派中移除。`}:{title:`Assigned Users`,add:`Add user`,remove:`Remove`,empty:`No users assigned yet. Click "Add user" to assign.`,loading:`Loading…`,pickTitle:`Select users to assign`,seatFull:e=>`All `+e+` AI seat(s) are in use. Remove a user or raise the license cap before assigning another.`,addFailed:`Failed to assign. Please try again.`,countOf:e=>String(e),direct:`direct`,viaPosition:e=>`via position `+e,everyoneNote:`Bound to the everyone anchor — every signed-in member holds this set.`,positionHeldHint:`Held via a position — remove it on the position’s assignments.`},[e])}var $=e=>Array.isArray(e)?e:e?.records??e?.items??e?.data??[],Ir=e=>e?.full_name||e?.name||e?.display_name||e?.email||String(e?.id??``);function Lr({permissionSetName:e}){let t=w(),n=Fr(),[r,i]=U.useState(null),[a,o]=U.useState([]),[s,c]=U.useState(!1),[l,u]=U.useState(!0),[d,f]=U.useState(!1),[p,m]=U.useState(!1),[h,g]=U.useState(null),_=U.useCallback(async()=>{u(!0);try{let n=$(await t.find(`sys_permission_set`,{$filter:{name:e},limit:1})),r=n[0]?.id?String(n[0].id):null;if(i(r),!r){o([]),c(!1);return}let a=$(await t.find(`sys_user_permission_set`,{$filter:{permission_set_id:r},$top:500})),s=[],l=!1;try{let e=$(await t.find(`sys_position_permission_set`,{$filter:{permission_set_id:r},$top:200})),n=[...new Set(e.map(e=>e.position_id).filter(Boolean).map(String))];if(n.length){let e=$(await t.find(`sys_position`,{$filter:{id:{$in:n}},$top:200})).map(e=>String(e.name??``)).filter(Boolean);l=e.includes(`everyone`),s=e.filter(e=>e!==`everyone`&&e!==`guest`)}}catch{}let u=s.length?$(await t.find(`sys_user_position`,{$filter:{position:{$in:s}},$top:1e3})):[],d=new Map,f=new Map;for(let e of a){if(!e?.user_id)continue;let t=String(e.user_id);f.set(t,String(e.id)),d.set(t,[...d.get(t)??[],{kind:`direct`}])}for(let e of u){if(!e?.user_id||!e?.position)continue;let t=String(e.user_id);d.set(t,[...d.get(t)??[],{kind:`position`,position:String(e.position)}])}let p=[...d.keys()],m=p.length?$(await t.find(`sys_user`,{$filter:{id:{$in:p}},$top:1e3})):[],h=new Map(m.map(e=>[String(e.id),e]));o(p.map(e=>{let t=h.get(e);return{grantId:f.get(e)??null,userId:e,name:t?Ir(t):e,email:t?.email??``,via:d.get(e)??[]}})),c(l)}catch{o([]),c(!1)}finally{u(!1)}},[t,e]);U.useEffect(()=>{_()},[_]);let v=U.useMemo(()=>new Set(a.map(e=>e.userId)),[a]),y=U.useCallback(async e=>{if(r){m(!0),g(null);try{for(let n of e||[]){let e=n?.id==null?null:String(n.id);!e||v.has(e)||await t.create(`sys_user_permission_set`,{permission_set_id:r,user_id:e})}await _()}catch(e){let t=String(e?.body?.error??e?.error??e?.message??``),r=t.match(/(\d+)\s*of\s*(\d+)\s*seat/i);if(/cap reached|seat cap|ai[-_ ]?seat/i.test(t))g(n.seatFull(r?Number(r[2]):a.length));else{let e=t.replace(/^\s*\[[^\]]*\]\s*/,``).trim();g(e||n.addFailed)}}finally{m(!1),f(!1)}}},[t,r,v,_,a.length,n]),b=U.useCallback(async e=>{g(null);try{await t.delete(`sys_user_permission_set`,e),await _()}catch{}},[t,_]);return(0,W.jsxs)(`div`,{className:`px-4 py-4`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium`,children:[(0,W.jsx)(Ee,{className:`h-4 w-4 text-muted-foreground`}),(0,W.jsx)(`span`,{children:n.title}),!l&&(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground font-normal`,children:n.countOf(a.length)})]}),(0,W.jsxs)(D,{variant:`outline`,size:`sm`,disabled:p||!r,onClick:()=>{g(null),f(!0)},className:`gap-1 h-8 text-xs`,children:[p?(0,W.jsx)(F,{className:`h-3.5 w-3.5 animate-spin`}):(0,W.jsx)(Ke,{className:`h-3.5 w-3.5`}),n.add]})]}),h&&(0,W.jsxs)(`div`,{className:`mb-3 flex items-start gap-2 rounded-md border border-amber-300/60 bg-amber-50 dark:bg-amber-950/30 px-3 py-2 text-xs text-amber-800 dark:text-amber-200`,role:`alert`,children:[(0,W.jsx)(xe,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,W.jsx)(`span`,{children:h})]}),s&&(0,W.jsxs)(`div`,{className:`mb-3 flex items-start gap-2 rounded-md border bg-muted/40 px-3 py-2 text-xs text-muted-foreground`,children:[(0,W.jsx)(Ee,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,W.jsx)(`span`,{children:n.everyoneNote})]}),l?(0,W.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground py-3`,children:[(0,W.jsx)(F,{className:`h-3.5 w-3.5 animate-spin`}),n.loading]}):a.length===0?!s&&(0,W.jsx)(`div`,{className:`text-xs text-muted-foreground italic py-3`,children:n.empty}):(0,W.jsx)(`ul`,{className:`divide-y rounded-md border`,children:a.map(e=>(0,W.jsxs)(`li`,{className:`flex items-center gap-3 px-3 py-2`,children:[(0,W.jsx)(`div`,{className:`flex h-7 w-7 items-center justify-center rounded-full bg-primary/10 text-primary text-xs font-medium shrink-0`,children:(e.name||`?`).slice(0,1).toUpperCase()}),(0,W.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,W.jsx)(`span`,{className:`text-sm truncate`,children:e.name}),e.via.map((e,t)=>(0,W.jsx)(`span`,{className:`shrink-0 rounded border bg-muted/40 px-1.5 py-0.5 text-[10px] leading-none text-muted-foreground`,children:e.kind===`direct`?n.direct:n.viaPosition(e.position)},t))]}),e.email&&e.email!==e.name&&(0,W.jsx)(`div`,{className:`text-xs text-muted-foreground truncate`,children:e.email})]}),e.grantId?(0,W.jsx)(D,{variant:`ghost`,size:`sm`,onClick:()=>void b(e.grantId),"aria-label":n.remove,title:n.remove,className:`h-7 w-7 p-0 text-muted-foreground hover:text-destructive shrink-0`,children:(0,W.jsx)(me,{className:`h-4 w-4`})}):(0,W.jsx)(`span`,{className:`shrink-0 text-[10px] text-muted-foreground/70`,title:n.positionHeldHint,children:`—`})]},e.userId))}),r&&(0,W.jsx)(Be,{open:d,onOpenChange:e=>f(e),multiple:!0,dataSource:t,objectName:`sys_user`,title:n.pickTitle,onSelect:()=>{},onSelectRecords:e=>void y(e)})]})}function Rr(){let e=x()?.data?.name;return!e||typeof e!=`string`?null:(0,W.jsx)(P,{className:`overflow-hidden`,children:(0,W.jsx)(Lr,{permissionSetName:e})})}var zr=new Set([`id`,`_id`,`created_at`,`created_by`,`updated_at`,`updated_by`]),Br=new Set([`organization_id`,`tenant_id`,`is_deleted`,`deleted_at`,`space`]),Vr=new Set([`formula`,`summary`,`rollup`,`autonumber`,`auto_number`]),Hr=e=>e==null||e===``||Array.isArray(e)&&e.length===0,Ur=e=>{try{return JSON.stringify(e)??`undefined`}catch{return String(e)}};function Wr(e){if(!e)return null;if(typeof e==`object`)return e;if(typeof e==`string`)try{let t=JSON.parse(e);return t&&typeof t==`object`?t:null}catch{return null}return null}function Gr(e,t,n){let r=new Set([...Object.keys(e??{}),...Object.keys(t??{})]),i=[];for(let a of r){if(zr.has(a)||Br.has(a))continue;let r=n?.[a];if(r&&(r.hidden===!0||typeof r.type==`string`&&Vr.has(r.type)))continue;let o=e?.[a],s=t?.[a];Hr(o)&&Hr(s)||Ur(o)!==Ur(s)&&i.push({field:a,from:o,to:s})}return i}function Kr(e){let t=e?.reference_to??e?.reference;return typeof t==`string`&&t.length>0?t:null}var qr=e=>e==null||e===``?[]:(Array.isArray(e)?e:[e]).map(e=>typeof e==`string`||typeof e==`number`?String(e):typeof e==`object`&&e&&`id`in e?String(e.id):null).filter(e=>!!e);function Jr(e,t){let n=new Map;for(let r of e){let e=Kr(t?.[r.field]);if(!e)continue;let i=[...qr(r.from),...qr(r.to)];if(i.length===0)continue;let a=n.get(e);a||n.set(e,a=new Set);for(let e of i)a.add(e)}return n}function Yr(e,t,n){let r=e?.type;if(r===`boolean`||typeof t==`boolean`){let e=t===!0||t===`true`||t===1,r=e?`common.yes`:`common.no`,i=e?`Yes`:`No`;return n.t?n.t(r,{defaultValue:i}):i}if(r===`date`||r===`datetime`){let e=new Date(t);if(!Number.isNaN(e.getTime()))try{return r===`date`?e.toLocaleDateString(n.locale):e.toLocaleString(n.locale,{dateStyle:`medium`,timeStyle:`short`})}catch{return String(t)}return String(t)}if(Array.isArray(e?.options))for(let n of e.options){let e=n&&typeof n==`object`?n.value??n.name:n;if(e===t||String(e)===String(t)){let t=n&&typeof n==`object`?n.label??n.name??e:n;return String(t)}}let i=Kr(e);if(i){let e=n.lookupLabels?.get(i)?.get(String(t));if(e)return e}return typeof t==`object`&&t?Ur(t):String(t)}function Xr(e,t,n={}){return Hr(t)?``:Array.isArray(t)?t.map(t=>Yr(e,t,n)).join(`, `):Yr(e,t,n)}var Zr=t({RecordDetailView:()=>ii}),Qr={id:`current-user`,name:`Demo User`},$r=new Set([`created_at`,`created_by`,`updated_at`,`updated_by`]),ei=new Set([`organization_id`,`tenant_id`,`is_deleted`,`deleted_at`]),ti=[`description`,`notes`,`note`,`remark`,`remarks`,`comments`],ni=new Set([`textarea`,`markdown`,`html`,`rich-text`,`json`,`code`]);function ri(e,t){if(ni.has(t?.type))return!0;let n=e.toLowerCase();return ti.some(e=>n===e||n.endsWith(`_${e}`))}function ii({dataSource:e,objects:t,onEdit:n,objectNameOverride:c,recordIdOverride:l,embedded:u}){let m=s(),v=m.appName,y=c??m.objectName,x=l??m.recordId,{showDebug:S}=st(),{user:w,activeOrganization:re}=p(),ce=a(),[le,ue]=o(),de=le.get(`tab`)??void 0,fe=(0,U.useCallback)(e=>{let t=new URLSearchParams(window.location.search);t.get(`tab`)!==e&&(t.set(`tab`,e),ue(t,{replace:!0}))},[ue]),pe=i(),me=pe.state?.from,he=(0,U.useMemo)(()=>{if(me?.pathname&&me?.label)return me;let e=Un(new URLSearchParams(pe.search).get(Vn)),t=e[e.length-1];if(!t)return;let n=v?`/apps/${v}`:``,r=t.i.length>12?`${t.i.slice(0,8)}…`:t.i;return{pathname:Kn(n,t,e.slice(0,-1)),label:t.t||`#${r}`}},[me,pe.search,v]),{t:T,language:E}=Te(),{objectLabel:_e,viewLabel:ve,sectionLabel:D,actionLabel:O,actionConfirm:xe,actionSuccess:Se,actionParamText:Ce,actionParamOptionLabel:we,actionDescription:Ee,fieldLabel:k,fieldOptionLabel:De}=be(),{isFavorite:Oe,toggleFavorite:A,refreshLabel:Ae}=Ut(),{addRecentItem:je}=Ct(),[Me,Ne]=(0,U.useState)(!0),[Pe,Fe]=(0,U.useState)([]),[j,Ie]=(0,U.useState)([]),[Le,Re]=(0,U.useState)(null),[ze,Be]=(0,U.useState)(null),[Ve,He]=(0,U.useState)(!1),[M,We]=(0,U.useState)(),N=t.find(e=>e.name===y);Ft(u?void 0:M);let P=x,F=te(y||void 0,P||void 0),I=(0,U.useCallback)(()=>{y&&ie({objectName:y,recordId:P||void 0})},[y,P]),Ge=Mn(y,P),L=(0,U.useMemo)(()=>!y||!P?null:{id:`record:${y}:${P}`,label:M||P||``,href:`/apps/${v}/${y}/record/${P}`,type:`record`},[v,y,P,M]),Ke=L?Oe(L.id):!1,qe=(0,U.useCallback)(()=>{L&&A(L)},[L,A]),{page:Je,slots:R}=oe(y),Xe=(0,U.useMemo)(()=>Je||!N?null:at(N,R?{slots:R}:void 0),[Je,R,N]),z=Je||Xe,[B,Ze]=(0,U.useState)(null),[Qe,H]=(0,U.useState)(`idle`);(0,U.useEffect)(()=>{let t=!1;if(!z||!P||!y||!e?.findOne){Ze(null),H(`idle`);return}let n=C(N?.fields),r=n.length>0?{$expand:n}:void 0,i=()=>{H(`loading`),(r?e.findOne(y,P,r):e.findOne(y,P)).then(e=>{t||(e&&typeof e==`object`?(Ze(e),H(`loaded`)):(Ze(null),H(`missing`)))}).catch(()=>{t||(Ze(null),H(`missing`))})};i();let a=e=>{let t=e.detail||{};t.objectName!==y||String(t.recordId)!==String(P)||i()};return window.addEventListener(`objectui:record-changed`,a),()=>{t=!0,window.removeEventListener(`objectui:record-changed`,a)}},[z,y,P,e,N,F]),(0,U.useEffect)(()=>{if(!B||typeof B!=`object`||!N)return;let e=ae(N,B);e&&e!==`Untitled`&&e!==M&&We(e)},[B,N,M]),(0,U.useEffect)(()=>{if(!y||!P||!v||!M)return;let e=`record:${y}:${P}`,t=`/apps/${v}/${y}/record/${P}`;je({id:e,label:M,href:t,type:`record`}),Ae(e,M)},[v,y,P,M,je,Ae]);let[$e,et]=(0,U.useState)({open:!1,message:``}),[dt,ft]=(0,U.useState)({open:!1,params:[]}),[pt,mt]=(0,U.useState)({open:!1}),ht=(0,U.useCallback)((e,t)=>new Promise(n=>{mt({open:!0,spec:e,data:t,resolve:n})}),[]),G=(0,U.useCallback)((e,t)=>new Promise(n=>{et({open:!0,message:e,options:t,resolve:n})}),[]),gt=(0,U.useCallback)((e,n)=>new Promise(r=>{let i=typeof n?.objectName==`string`&&n.objectName?n.objectName:void 0,a=n?.params&&!Array.isArray(n.params)?n.params._rowRecord:void 0,o=Mr(e,{objectName:i||y||N?.name||``,objects:t||[],fieldLabel:k,fieldOptionLabel:De,row:a}),s=i||y||N?.name,c=o.map(e=>({...e,label:Ce(s,n?.name,e.name,`label`,e.label)??e.label,placeholder:Ce(s,n?.name,e.name,`placeholder`,e.placeholder)??e.placeholder,helpText:Ce(s,n?.name,e.name,`helpText`,e.helpText)??e.helpText,options:Array.isArray(e.options)?e.options.map(t=>({...t,label:we(s,n?.name,e.name,t.value,t.label)})):e.options}));ft({open:!0,params:c,title:n?.label||n?.title,description:Ee(s,n?.name,n?.description),resolve:r})}),[y,N,t,k,De,Ce,we]),_t=ne({dataSource:e,onUndo:e=>{e?.objectName?ie({objectName:e.objectName,recordId:e.recordId}):I(),V.success(`Change undone`)}}),vt=(0,U.useCallback)((e,t)=>{if(t?.type===`error`){V.error(e);return}if(t?.undo){V.success(e,{duration:t.duration,action:{label:t.undo.label||`Undo`,onClick:()=>{_t.undo()}}});return}V.success(e,{duration:t?.duration})},[_t]),yt=(0,U.useCallback)((e,t)=>{t?.external||t?.newTab?window.open(e,`_blank`,`noopener,noreferrer`):ce(e)},[ce]),K=(0,U.useMemo)(()=>d(),[]),bt=(0,U.useCallback)(async t=>{try{let n=t.target||t.name,r=t.params&&!Array.isArray(t.params)?t.params._rowRecord:void 0,i={...t.params||{}};delete i._rowRecord;let a=typeof n==`string`?n:``;if(a.startsWith(`/`)||/^https?:\/\//i.test(a)){let e=a;r&&/\{[a-z_][a-z0-9_]*\}/i.test(e)&&(e=e.replace(/\{([a-z_][a-z0-9_]*)\}/gi,(e,t)=>{let n=r[t];return n==null?``:encodeURIComponent(String(n))}));let n=e.startsWith(`http`)?e:`${e}`,o=t.bodyShape&&typeof t.bodyShape==`object`&&t.bodyShape.wrap?t.bodyShape.wrap:void 0,s=o?{[o]:i}:{...i};if(t.recordIdParam){let e=t.recordIdField||`id`,n=r?.[e]??t.recordId??(!t.objectName||t.objectName===y?B?.[e]:void 0);n!=null&&(s[t.recordIdParam]=n)}/\/api\/v1\/auth\//.test(e)&&!s.organizationId&&re?.id&&(s.organizationId=re.id),t.bodyExtra&&typeof t.bodyExtra==`object`&&Object.assign(s,t.bodyExtra);let c=(t.method||`POST`).toUpperCase(),l={method:c,headers:{"Content-Type":`application/json`},credentials:`include`};c!==`GET`&&c!==`DELETE`&&(l.body=JSON.stringify(s));let u=await K(n,l);if(!u.ok){let e=null;try{e=await u.json()}catch{}let t=e?.error?.message||e?.error||e?.message||`HTTP ${u.status}`;return{success:!1,error:typeof t==`string`?t:`HTTP ${u.status}`}}let d=await u.json().catch(()=>({}));return t.refreshAfter===!0&&I(),{success:!0,data:d,reload:t.refreshAfter===!0}}t.bodyExtra&&typeof t.bodyExtra==`object`&&Object.assign(i,t.bodyExtra);let o;switch(n){case`opportunity_change_stage`:await e.update(y,P,{stage:i.new_stage});break;case`opportunity_mark_won`:await e.update(y,P,{stage:`closed_won`});break;case`opportunity_mark_lost`:await e.update(y,P,{stage:`closed_lost`,loss_reason:i.loss_reason});break;default:{let n=t.objectName??y,r=t.recordId??P,a=n===y&&String(r)===String(P);if(Object.keys(i).length>0&&n&&r!=null){if(t.undoable&&a&&B){let e={};for(let t of Object.keys(i))e[t]=B[t]??null;o={id:`undo-${n}-${r}-${Date.now()}`,type:`update`,objectName:n,recordId:String(r),timestamp:Date.now(),description:t.label||`Undo ${n}`,undoData:e,redoData:{...i}}}await e.update(n,String(r),i)}break}}let s=t.refreshAfter===!0;return(s||o)&&I(),{success:!0,reload:s,undo:o}}catch(e){return{success:!1,error:e.message}}},[e,y,P,B,K,re]),{modalHandler:xt,modalElement:St}=jt(e),wt=(0,U.useCallback)(async e=>{let t=e.target||e.name;if(!t)return{success:!1,error:`No flow target provided for flow action`};try{let n=await K(`/api/v1/automation/${encodeURIComponent(t)}/trigger`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({recordId:e.recordId??P,objectName:e.objectName??y,params:e.params??{}})}),r=await n.json().catch(()=>null);if(!n.ok||r&&r.success===!1)return{success:!1,error:r?.error||`Flow "${t}" failed (HTTP ${n.status})`};let i=r?.data??{};if(i.status===`paused`&&i.screen)return Re({flowName:t,runId:i.runId,screen:i.screen}),{success:!0,silent:!0};let a=e.refreshAfter!==!1;return a&&I(),{success:!0,data:r?.data,reload:a}}catch(e){return{success:!1,error:e.message}}},[K,P,y]),Tt=(0,U.useRef)(new Set),Et=(0,U.useCallback)(async e=>{let t=e.target||e.name;if(!t)return{success:!1,error:`No action target provided`};let n=e.params&&!Array.isArray(e.params)?e.params:{},r=`${t}:${P??``}`;if(Tt.current.has(r))return{success:!1,error:`Action already in progress`};Tt.current.add(r);let i=null;if(e.opensInNewTab)try{i=window.open(`about:blank`,`_blank`),i&&(i.document.write(`<!doctype html><meta charset="utf-8"><title>正在打开… Opening…</title><body style="margin:0;font-family:system-ui,sans-serif;display:flex;flex-direction:column;align-items:center;justify-content:center;height:100vh;gap:16px;color:#4b5563"><div style="width:28px;height:28px;border:3px solid #e5e7eb;border-top-color:#6366f1;border-radius:50%;animation:s .8s linear infinite"></div><div>正在为你打开环境…</div><style>@keyframes s{to{transform:rotate(360deg)}}</style></body>`),i.document.close())}catch{i=null}try{let r=typeof e.newTabUrl==`string`?e.newTabUrl:``;if(e.opensInNewTab&&r){if(P==null){if(i)try{i.close()}catch{}return{success:!1,error:`This action runs on a single record — no record id available.`}}let t=`${window.location.origin}${r.replace(`{recordId}`,encodeURIComponent(String(P)))}`;if(i)try{i.location.href=t}catch{try{i.close()}catch{}window.location.href=t}else{let e=null;try{e=window.open(t,`_blank`)}catch{e=null}e||V(`浏览器拦截了弹窗 / Popup blocked`,{description:`点击在新标签页打开环境`,action:{label:`打开环境`,onClick:()=>{try{window.open(t,`_blank`)}catch{window.location.href=t}}},duration:1e4})}return e.refreshAfter===!0&&I(),{success:!0}}let a=e.objectName||y||`global`,o=await K(`/api/v1/actions/${encodeURIComponent(a)}/${encodeURIComponent(t)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({recordId:e.recordId??P,params:n})}),s=await o.json().catch(()=>null),c=s?.data,l=c&&typeof c==`object`&&c.success===!1;if(!o.ok||s&&s.success===!1||l){let e=l&&c.error||s?.error||`Action "${t}" failed (HTTP ${o.status})`;if(i)try{i.close()}catch{}return{success:!1,error:e}}let u=e.refreshAfter!==!1;u&&I();let d=s?.data;if(d&&typeof d==`object`&&typeof d.redirectUrl==`string`){let e=d.redirectUrl;if(i)try{i.location.href=e}catch{try{i.close()}catch{}window.location.href=e}else{let t=null;try{t=window.open(e,`_blank`)}catch{t=null}t||V(`浏览器拦截了弹窗 / Popup blocked`,{description:`点击在新标签页打开环境`,action:{label:`打开环境`,onClick:()=>{try{window.open(e,`_blank`)}catch{window.location.href=e}}},duration:1e4})}}else if(i)try{i.close()}catch{}return{success:!0,data:d,reload:u}}catch(e){if(i)try{i.close()}catch{}return{success:!1,error:e.message}}finally{Tt.current.delete(r)}},[K,P,y]),q=Yn(y,P,w?.id),Dt=(0,U.useRef)(q);Dt.current=q;let Ot=(0,U.useRef)(!1);(0,U.useEffect)(()=>{if(!Ot.current){Ot.current=!0;return}Dt.current.refresh()},[F]);let kt=B?.approval_status===`pending`||B?.approval_status===`in_approval`||!!q.pendingRequest,At=(0,U.useCallback)(async e=>{let t=e.target||e.name,n=e.params&&!Array.isArray(e.params)?e.params:{};try{if(t===`approve_request`)await Dt.current.approve({comment:n.comment});else if(t===`reject_request`)await Dt.current.reject({comment:n.comment});else return{success:!1,error:`Unknown approval target: ${t}`};return I(),{success:!0,reload:!0}}catch(e){return{success:!1,error:e?.message||String(e)}}},[]),{can:Mt,isLoaded:Nt}=f(),Pt=(0,U.useMemo)(()=>yn(N,t,{canRead:Nt?e=>Mt(e,`read`):void 0}),[N,t,Mt,Nt]),J=(0,U.useMemo)(()=>!N||N.name===`sys_audit_log`||N.enable?.trackHistory!==!0?!1:t.some(e=>e.name===`sys_audit_log`),[N,t]),It=N?.enable?.feeds!==!1,Lt=N?.enable?.activities!==!1,Rt=N?.enable?.files===!0;(0,U.useEffect)(()=>{if(!e||!P||!N||!J){Be(null);return}let n=!1;He(!0);let r=!!t.find(e=>e.name===`sys_audit_log`)?.fields?.actor;return e.find(`sys_audit_log`,{$filter:{record_id:P,object_name:N.name},$orderby:{created_at:`desc`},$top:50,$select:[`id`,`created_at`,`action`,`user_id`,...r?[`actor`]:[],`old_value`,`new_value`]}).then(async r=>{if(n)return;let i=Array.isArray(r)?r:r?.data||[],a=Array.from(new Set(i.map(e=>e?.user_id).filter(e=>typeof e==`string`&&e.length>0))),o=new Map;if(a.length>0)try{let t=await e.find(`sys_user`,{$filter:{id:{$in:a}},$top:a.length,$select:[`id`,`name`,`email`,`image`]}),n=Array.isArray(t)?t:t?.data||[];o=new Map(n.map(e=>[e.id,{name:e.name||e.email||null,image:e.image||null}]))}catch(e){console.warn(`[RecordDetailView] Failed to resolve audit user names:`,e)}let s={};for(let[e,t]of Object.entries(N.fields||{}))t?.label&&(s[e]=t.label);let c=i.map(e=>Gr(Wr(e?.old_value),Wr(e?.new_value),N.fields)),l=Jr(c.flat(),N.fields),u=new Map;if(await Promise.all(Array.from(l.entries()).map(async([n,r])=>{let i=rt(t.find(e=>e.name===n))??`name`;try{let t=await e.find(n,{$filter:{id:{$in:Array.from(r)}},$top:r.size,$select:[`id`,i]}),a=Array.isArray(t)?t:t?.data||[];u.set(n,new Map(a.filter(e=>e?.id!=null&&typeof e?.[i]==`string`&&e[i]).map(e=>[String(e.id),e[i]])))}catch(e){console.warn(`[RecordDetailView] Failed to resolve audit lookup labels for ${n}:`,e)}})),n)return;let d={t:T,locale:E,lookupLabels:u},f=i.map((e,t)=>{let n=e?.user_id?o.get(e.user_id):void 0,r=typeof e?.actor==`string`&&e.actor.trim()&&e.actor!==e?.user_id?e.actor.trim():null,i=c[t].map(e=>({field:e.field,label:s[e.field]||e.field,from:Xr(N.fields?.[e.field],e.from,d),to:Xr(N.fields?.[e.field],e.to,d)}));return{...e,user_name:n?.name??r,user_avatar:n?.image??null,changes:i.length>0?i:void 0}});Be(f)}).catch(e=>{n||(console.warn(`[RecordDetailView] Failed to fetch sys_audit_log:`,e),Be([]))}).finally(()=>{n||He(!1)}),()=>{n=!0}},[e,P,N,J,t,E]),(0,U.useEffect)(()=>{if(!e)return;let t=!1,n=w?[{id:String(w.id),label:w.name||w.email||String(w.id),avatarUrl:w.image||void 0}]:[];return(async()=>{try{let r=await e.find(`sys_user`,{$top:50,$select:[`id`,`name`,`email`,`image`]});if(t)return;let i=(Array.isArray(r)?r:r?.data||[]).map(e=>({id:String(e.id),label:e.name||e.email||String(e.id),avatarUrl:e.image||void 0})).filter(e=>e.label),a=new Set(n.map(e=>e.id)),o=[...n,...i.filter(e=>!a.has(e.id))];Ie(o.length>0?o:n)}catch{if(t)return;Ie(n)}})(),()=>{t=!0}},[e,w?.id,w?.name,w?.email]);let Y=(0,U.useMemo)(()=>w?{id:w.id,name:w.name,avatar:w.image}:Qr,[w?.id,w?.name,w?.image]);(0,U.useEffect)(()=>{if(!e||!y||!P)return;let t=`${y}:${P}`,n=e=>{if(!e)return;let t;if(typeof e==`string`)try{t=JSON.parse(e)}catch{return}else typeof e==`object`&&(t=e);if(t)return Object.entries(t).map(([e,t])=>({emoji:e,count:Array.isArray(t)?t.length:0,reacted:Array.isArray(t)&&t.includes(Y.id)}))};It&&e.find(`sys_comment`,{$filter:{thread_id:t},$orderby:{created_at:`asc`}}).then(e=>{if(!e?.data?.length)return;let t=e.data.map(e=>({id:e.id,type:`comment`,actor:e.author_name??T(`detail.unknownUser`,{defaultValue:`Unknown`}),actorAvatarUrl:e.author_avatar_url??void 0,body:e.body??``,createdAt:e.created_at,updatedAt:e.updated_at,parentId:e.parent_id??void 0,reactions:n(e.reactions)}));Fe(e=>{let n=new Map;for(let r of[...e,...t])n.set(String(r.id),r);return Array.from(n.values()).sort((e,t)=>(e.createdAt?Date.parse(e.createdAt):0)-(t.createdAt?Date.parse(t.createdAt):0))})}).catch(()=>{});let r={created:`field_change`,updated:`field_change`,deleted:`field_change`,assigned:`field_change`,shared:`field_change`,system:`system`,completed:`task`,commented:void 0,mentioned:void 0,login:void 0,logout:void 0};Lt&&e.find(`sys_activity`,{$filter:{object_name:y,record_id:P},$orderby:{timestamp:`asc`},$top:200}).then(e=>{if(!e?.data?.length)return;let t=[];for(let n of e.data){let e=r[n.type];if(!e)continue;let i=n.timestamp;(!i||i===`NOW()`||Number.isNaN(Date.parse(i)))&&(i=n.created_at),t.push({id:n.id,type:e,actor:n.actor_name??T(`detail.systemActor`,{defaultValue:`System`}),actorAvatarUrl:n.actor_avatar_url??void 0,body:n.summary??``,createdAt:i,sourceObject:n.source_object??void 0,sourceId:n.source_id??void 0})}t.length&&Fe(e=>{let n=new Map;for(let r of[...e,...t])n.set(String(r.id),r);return Array.from(n.values()).sort((e,t)=>(e.createdAt?Date.parse(e.createdAt):0)-(t.createdAt?Date.parse(t.createdAt):0))})}).catch(()=>{})},[e,y,P,Y,It,Lt]);let zt=(0,U.useCallback)(async t=>{let n={id:crypto.randomUUID(),type:`comment`,actor:Y.name,actorAvatarUrl:`avatar`in Y?Y.avatar:void 0,body:t,createdAt:new Date().toISOString()};if(Fe(e=>[...e,n]),e){let r=`${y}:${P}`,i=tt(t,j);e.create(`sys_comment`,{id:n.id,thread_id:r,author_id:Y.id,author_name:Y.name,author_avatar_url:`avatar`in Y?Y.avatar:void 0,body:t,mentions:JSON.stringify(i),created_at:n.createdAt}).catch(()=>{})}},[Y,e,y,P,j]),Bt=(0,U.useCallback)(async(t,n)=>{let r={id:crypto.randomUUID(),type:`comment`,actor:Y.name,actorAvatarUrl:`avatar`in Y?Y.avatar:void 0,body:n,createdAt:new Date().toISOString(),parentId:t};if(Fe(e=>[...e,r].map(e=>e.id===t?{...e,replyCount:(e.replyCount??0)+1}:e)),e){let i=`${y}:${P}`,a=tt(n,j);e.create(`sys_comment`,{id:r.id,thread_id:i,author_id:Y.id,author_name:Y.name,author_avatar_url:`avatar`in Y?Y.avatar:void 0,body:n,mentions:JSON.stringify(a),created_at:r.createdAt,parent_id:t}).catch(()=>{})}},[Y,e,y,P,j]),Vt=(0,U.useCallback)((t,n)=>{Fe(r=>r.map(r=>{if(r.id!==t)return r;let i=[...r.reactions??[]],a=i.findIndex(e=>e.emoji===n);if(a>=0){let e=i[a];e.reacted?e.count<=1?i.splice(a,1):i[a]={...e,count:e.count-1,reacted:!1}:i[a]={...e,count:e.count+1,reacted:!0}}else i.push({emoji:n,count:1,reacted:!0});let o={...r,reactions:i};if(e){let n=Y.id,r={};for(let e of i){let t=[];for(e.reacted&&t.push(n);t.length<e.count;)t.push(`__other__`);r[e.emoji]=t}e.update(`sys_comment`,String(t),{reactions:JSON.stringify(r)}).catch(()=>{})}return o}))},[Y.id,e]);(0,U.useEffect)(()=>{Ne(!0),queueMicrotask(()=>Ne(!1))},[y,x]);let X=(0,U.useMemo)(()=>{if(!N)return{};let e=(()=>{let e=e=>{let t=N.fields[e],n=t.reference_to||t.reference;return{name:e,label:t.label||e,type:t.type||`text`,...t.options&&{options:t.options},...n&&{reference_to:n},...t.reference_field&&{reference_field:t.reference_field},...t.currency&&{currency:t.currency}}},t=t=>{let n=t.filter(e=>!ri(e,N.fields[e])),r=t.filter(e=>ri(e,N.fields[e]));return r.length===0||n.length===0?[{showBorder:!1,fields:t.map(e)}]:[{showBorder:!1,fields:n.map(e)},{name:`details`,title:D(N.name,`details`,T(`detail.sectionMoreDetails`,`More details`)),collapsible:!0,defaultCollapsed:!1,showBorder:!0,fields:r.map(e)}]},n=ot(N);return n?n.flatMap(e=>e.name?[{...e,title:D(N.name,e.name,e.title),showBorder:!0}]:t(e.fields.map(e=>e.name))):t(Object.keys(N.fields||{}).filter(e=>!$r.has(e)&&!ei.has(e)&&!N.fields[e]?.hidden))})(),n=(()=>{let e=new Set,t=(N.actions||[]).filter(t=>!t.locations?.includes(`record_header`)&&!t.locations?.includes(`record_more`)?!1:t.name?e.has(t.name)?!1:(e.add(t.name),!0):!0).map(e=>({...e,label:O(N.name,e.name,e.label||e.name),...e.confirmText!==void 0&&{confirmText:xe(N.name,e.name,e.confirmText)},...e.successMessage!==void 0&&{successMessage:Se(N.name,e.name,e.successMessage)}}));if(q.available&&q.canDecide){let e={name:`comment`,label:T(`approvals.comment`,{defaultValue:`Comment (optional)`}),type:`text`,multiline:!0};t.push({name:`approve_request`,type:`approval`,target:`approve_request`,label:T(`approvals.approve`,{defaultValue:`Approve`}),icon:`check`,variant:`primary`,order:-100,locations:[`record_header`],refreshAfter:!0,collectParams:[e],successMessage:T(`approvals.approveSuccess`,{defaultValue:`Approved`})}),t.push({name:`reject_request`,type:`approval`,target:`reject_request`,label:T(`approvals.reject`,{defaultValue:`Reject`}),icon:`x`,variant:`destructive`,order:-99,locations:[`record_header`],refreshAfter:!0,confirmText:T(`approvals.rejectConfirm`,{defaultValue:`Reject this approval request?`}),collectParams:[e],successMessage:T(`approvals.rejectSuccess`,{defaultValue:`Rejected`})})}return t})(),r=N.highlightFields??[],i=rt(N),a=(Array.isArray(r)?r:[]).map(e=>typeof e==`string`?e:e?.name).filter(e=>typeof e==`string`&&e.length>0&&e!==i),o=Pt.map(({childObject:e,childLabel:n,referenceField:r,title:i,columns:a,isPrimary:o})=>{let s=t.find(t=>t.name===e);return{title:i||(s?_e({name:s.name,label:s.label||n}):n),objectName:e,relationshipField:r,...Array.isArray(a)&&a.length>0?{columns:a}:{},...s?.icon?{icon:s.icon}:{},...o?{isPrimary:!0}:{}}});return{sections:e,highlightFields:a.length>0?a:void 0,headerActions:n.length>0?n:void 0,related:o.length>0?o:void 0,...J&&{history:{entries:ze??[],loading:Ve&&ze===null,unknownUserText:T(`detail.unknownUser`,{defaultValue:`Unknown user`})}}}},[N?.name,Pt,T,_e,t,J,ze,Ve,q.available,q.canDecide]);if(Me)return(0,W.jsx)(ut,{});if(!N)return(0,W.jsx)(`div`,{className:`flex h-full items-center justify-center p-4`,children:(0,W.jsxs)(ke,{children:[(0,W.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,W.jsx)(Ue,{className:`h-6 w-6 text-muted-foreground`})}),(0,W.jsx)(Ye,{children:T(`empty.objectNotFound`)}),(0,W.jsx)(ye,{children:T(`empty.objectNotFoundDescription`,{name:y})})]})});if(Qe===`missing`)return(0,W.jsx)(`div`,{className:`flex h-full items-center justify-center p-4`,children:(0,W.jsxs)(ke,{children:[(0,W.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,W.jsx)(Ue,{className:`h-6 w-6 text-muted-foreground`})}),(0,W.jsx)(Ye,{children:T(`empty.recordNotFound`,{defaultValue:`Record not found`})}),(0,W.jsx)(ye,{children:T(`empty.recordNotFoundDescription`,{defaultValue:`The record you are looking for does not exist or may have been deleted.`})})]})});let Ht=z?.disableDiscussion===!0,Wt=er(z),Z=!Ht&&!Wt&&It,Gt=(()=>{let t=Qn(N),r=[];return t.edit&&r.push({name:`sys_edit`,label:T(`detail.edit`,{defaultValue:`Edit`}),type:`script`,locations:[`record_header`],variant:`default`,order:100,disableDuringInlineEdit:!0,onClick:()=>n({id:P})}),r.push({name:`sys_share`,label:T(`detail.share`,{defaultValue:`Share`}),type:`script`,locations:[`record_header`],variant:`outline`,order:110,component:`action:menu`,onClick:async()=>{try{if(navigator.share){await navigator.share({title:document.title,url:window.location.href});return}}catch{return}try{await navigator.clipboard.writeText(window.location.href),V.success(T(`detail.linkCopied`,{defaultValue:`Link copied`}))}catch(e){V.error(T(`detail.linkCopyFailed`,{defaultValue:`Failed to copy link`})+(e?.message?`: ${e.message}`:``))}}}),t.delete&&r.push({name:`sys_delete`,label:T(`detail.delete`,{defaultValue:`Delete`}),type:`script`,locations:[`record_header`],variant:`destructive`,order:120,component:`action:menu`,onClick:async()=>{let t=T(`detail.deleteConfirmation`,{defaultValue:`Are you sure you want to delete this record?`});if(window.confirm(t))try{await e.delete(y,P),V.success(T(`detail.deleted`,{defaultValue:`Record deleted`}));let t=v?`/apps/${v}`:``;ce(`${t}/${y}`,{replace:!0})}catch(e){V.error(e?.message||`Delete failed`)}}}),r})(),Kt=Je?z:at(N,{sections:X.sections,highlightFields:X.highlightFields,headerActions:X.headerActions,related:X.related,history:X.history,...R?{slots:R}:{}});return(0,W.jsxs)(`div`,{className:`h-full bg-background overflow-hidden flex flex-col relative`,children:[(0,W.jsxs)(`div`,{className:`absolute top-2 sm:top-4 right-2 sm:right-4 z-50 flex items-center gap-2`,children:[Ge.length>0&&(0,W.jsx)(kn,{users:Ge,size:`sm`,maxVisible:3,showStatus:!0}),(0,W.jsx)(lt,{managedBy:N?.managedBy,userActions:N?.userActions})]}),(0,W.jsx)(h,{objectName:y,recordId:P,data:B,objectSchema:N,dataSource:e,embedded:u,headerSystemActions:Gt,isFavorite:Ke,onToggleFavorite:L?qe:void 0,children:(0,W.jsx)(ee,{canEdit:Qn(N).edit&&!kt,locked:kt,lockedReason:T(`detail.lockedTooltip`,{defaultValue:`This record has a pending approval request; editing is locked`}),children:(0,W.jsx)(b,{children:(0,W.jsx)(se,{items:Pe,onAddComment:zt,onAddReply:Bt,onToggleReaction:Vt,mentionSuggestions:j,children:(0,W.jsxs)(g,{context:{record:B||{},objectName:y,user:Y},onConfirm:G,onToast:vt,onNavigate:yt,onParamCollection:gt,onResultDialog:ht,onModal:xt,handlers:{api:bt,flow:wt,script:Et,approval:At},children:[(0,W.jsxs)(`div`,{className:`flex-1 overflow-hidden flex flex-row`,children:[(0,W.jsxs)(`div`,{className:`flex-1 overflow-auto p-3 sm:p-4 lg:p-6 scroll-pb-48`,children:[he?.pathname&&he?.label&&(0,W.jsxs)(r,{to:he.pathname,className:`inline-flex items-center gap-1 mb-3 text-sm text-muted-foreground hover:text-foreground transition-colors`,children:[(0,W.jsx)(ge,{className:`h-4 w-4`}),(0,W.jsx)(`span`,{children:he.label})]}),(0,W.jsx)(Er,{appName:v,objects:t,dataSource:e,actionLabel:O,parentObjectName:y,parentRecordId:P??void 0,parentTitle:M,children:(0,W.jsx)(_,{schema:Or(Kt,{defaultTab:de,onTabChange:fe})})}),y===`sys_permission_set`&&P&&(0,W.jsx)(`div`,{className:`mt-6`,children:(0,W.jsx)(Rr,{})}),Rt&&P&&(0,W.jsx)(`div`,{className:`mt-6`,children:(0,W.jsx)(Pr,{objectName:y,recordId:P,dataSource:e,currentUserId:Y?.id})}),Z&&(0,W.jsx)(`div`,{className:`mt-6`,children:(0,W.jsx)(it,{config:{position:`bottom`,collapsible:!1,feed:{enableReactions:!0,enableThreading:!0,showCommentInput:!0}},items:Pe,onAddComment:zt,onAddReply:Bt,onToggleReaction:Vt,mentionSuggestions:j})}),(0,W.jsx)(nt,{dataSource:e,objectName:y,recordId:P,data:B,refresh:I,fieldLabelFor:e=>N?.fields?.[e]?.label||k(y||``,e,e),locked:kt,lockedHint:T(`detail.lockedTooltip`,{defaultValue:`This record has a pending approval request; editing is locked`})})]}),(0,W.jsx)(ct,{open:S,sections:[{title:`Page Schema`,data:Kt}]})]}),St]})})})})}),(0,W.jsx)(tr,{state:$e,onOpenChange:e=>{e||et(e=>({...e,open:!1}))}}),(0,W.jsx)(cr,{state:dt,onOpenChange:e=>{e||ft(e=>({...e,open:!1}))}}),(0,W.jsx)(ur,{state:pt,onAcknowledge:()=>{pt.resolve?.(),mt({open:!1})}}),(0,W.jsx)(Cr,{state:Le,authFetch:K,baseUrl:``,dataSource:e,objects:t,onClose:()=>Re(null),onComplete:()=>{Re(null),I()}})]})}export{Pt as A,_t as B,kn as C,Ht as D,gn as E,Et as F,ht as H,wt as I,St as L,Tt as M,q as N,Ut as O,Dt as P,Ct as R,jn as S,bn as T,gt as U,G as V,mt as W,In as _,xr as a,Un as b,ur as c,Qn as d,zn as f,Ln as g,Rn as h,Cr as i,jt as j,Nt as k,cr as l,Fn as m,Zr as n,br as o,Bn as p,Mr as r,yr as s,ii as t,tr as u,Vn as v,Tn as w,Pn as x,Kn as y,pt as z};