@objectstack/console 14.8.0 → 15.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/dist/.objectui-sha +1 -1
  2. package/dist/assets/{AdapterProvider-BzVT9qYv.js → AdapterProvider-CSP_T07G.js} +1 -1
  3. package/dist/assets/{AiPendingActionsPage-B4I03oil.js → AiPendingActionsPage-BNh8Cf9P.js} +1 -1
  4. package/dist/assets/{ApiConsolePage-_wjPZg_8.js → ApiConsolePage-Btr9hRka.js} +1 -1
  5. package/dist/assets/{AppDocsIndex-B3Y96Lvd.js → AppDocsIndex-DFB1tmTx.js} +1 -1
  6. package/dist/assets/{AppManagementPage-DxZABvOm.js → AppManagementPage-D2jMv3L-.js} +1 -1
  7. package/dist/assets/{ApprovalsInboxPage-DAjFkDy9.js → ApprovalsInboxPage-CT4IXwpE.js} +1 -1
  8. package/dist/assets/{AuditLogPage-CuKdhFr9.js → AuditLogPage-BdYvwcAH.js} +1 -1
  9. package/dist/assets/{ComponentNavView-DebBry51.js → ComponentNavView-C8ngAwyN.js} +1 -1
  10. package/dist/assets/{CreateViewDialog-BCEk3ESW.js → CreateViewDialog-DcjN_AhY.js} +1 -1
  11. package/dist/assets/{DashboardView-Bi_ea9x6.js → DashboardView-CLJM8Cfl.js} +1 -1
  12. package/dist/assets/{DeveloperHubPage-CEFVU_4t.js → DeveloperHubPage-VBsID8Fk.js} +1 -1
  13. package/dist/assets/{DocShell-C09YMyAT.js → DocShell-ChTlUxMm.js} +1 -1
  14. package/dist/assets/{ExpressionProvider-gKUl8r3a.js → ExpressionProvider-CHaGm5wf.js} +1 -1
  15. package/dist/assets/{FlowRunsPage-Of98wriv.js → FlowRunsPage-DdOav-6T.js} +1 -1
  16. package/dist/assets/{IntegrationsPage-D2Eh-wKl.js → IntegrationsPage-BR2TkAoB.js} +1 -1
  17. package/dist/assets/{InterfaceListPage-BuAQSxuZ.js → InterfaceListPage-Ca4VNsGg.js} +1 -1
  18. package/dist/assets/{ManagedByBadge-3xVjmTY7.js → ManagedByBadge-Cdy82I7A.js} +1 -1
  19. package/dist/assets/{MarketplaceAccessDenied-YG6RAG6U.js → MarketplaceAccessDenied-B6Tg5g6l.js} +1 -1
  20. package/dist/assets/{MarketplaceInstalledPage-BFESaZWD.js → MarketplaceInstalledPage-DBmVXCVz.js} +1 -1
  21. package/dist/assets/{MarketplacePackagePage-Vy7JiFQ0.js → MarketplacePackagePage-Mt1pHE8U.js} +1 -1
  22. package/dist/assets/{MarketplacePage-C9kQ9UzP.js → MarketplacePage-D9CLlhnk.js} +1 -1
  23. package/dist/assets/{MetadataInspector-Dc5CNMYV.js → MetadataInspector-Bqe7rY0S.js} +1 -1
  24. package/dist/assets/{MetadataProvider-Bkb-vkjJ.js → MetadataProvider-DqPZ6rV2.js} +1 -1
  25. package/dist/assets/{ObjectDataPage-B_qdf_tA.js → ObjectDataPage-Cz_pMsIv.js} +1 -1
  26. package/dist/assets/{PageView-CO7Yco3U.js → PageView-CLvQYEdi.js} +1 -1
  27. package/dist/assets/{ProfilePage--OycjBXX.js → ProfilePage-BDJLPRAf.js} +1 -1
  28. package/dist/assets/{PublicFormsPage-CI1LZQKt.js → PublicFormsPage-BRflG64R.js} +1 -1
  29. package/dist/assets/{RecordDetailView-BQzH8bIG.js → RecordDetailView-w6IBQ1cm.js} +1 -1
  30. package/dist/assets/{RecordFormPage-D3fuaSOR.js → RecordFormPage-inJKFR63.js} +1 -1
  31. package/dist/assets/{ReportDefaultInspector-DfAMgr8D.js → ReportDefaultInspector-BZaG6IPJ.js} +1 -1
  32. package/dist/assets/{ReportView-DyMm1CCA.js → ReportView-CSAIx2AR.js} +1 -1
  33. package/dist/assets/{SearchResultsPage-CVsVjc9k.js → SearchResultsPage-DsnzRV3B.js} +1 -1
  34. package/dist/assets/{SettingsHub-DTr02Vxf.js → SettingsHub-Begm6jy7.js} +1 -1
  35. package/dist/assets/{SettingsView-BN_M8m7j.js → SettingsView-C4UULiJk.js} +1 -1
  36. package/dist/assets/{SystemHubPage-DGggPmsC.js → SystemHubPage-C4J7Le-p.js} +1 -1
  37. package/dist/assets/data-adapter-Mo_lVy1U.js +7 -0
  38. package/dist/assets/{framework-DUXRLJaF.js → framework-BL3BtpKU.js} +2 -2
  39. package/dist/assets/{getIcon-PwXhgLNw.js → getIcon-BZsP3YSU.js} +1 -1
  40. package/dist/assets/{highlighted-body-OFNGDK62-Cdc_XtSh.js → highlighted-body-OFNGDK62-BPN_aS-T.js} +1 -1
  41. package/dist/assets/i18n-BsjEVcp4.js +9 -0
  42. package/dist/assets/{index-C_G40cue.js → index-CRgNx-tU.js} +1 -1
  43. package/dist/assets/index-D1n9Ue1P.css +2 -0
  44. package/dist/assets/mermaid-GHXKKRXX-BBQimMyN.js +1 -0
  45. package/dist/assets/{metadata-admin-DYtDZDTS.js → metadata-admin-DHwo5kSi.js} +4 -4
  46. package/dist/assets/{plugin-calendar-C5OJe0lx.js → plugin-calendar-BTCkHFNk.js} +1 -1
  47. package/dist/assets/{plugin-charts-C4pZYso-.js → plugin-charts-DugftiGR.js} +1 -1
  48. package/dist/assets/{plugin-chatbot-B6HiHZjD.js → plugin-chatbot-Cq19aZcF.js} +44 -44
  49. package/dist/assets/{plugin-dashboard-BMm8A0um.js → plugin-dashboard-CaQs1s4M.js} +1 -1
  50. package/dist/assets/{plugin-form-zDPLpTAc.js → plugin-form-6ug8Woph.js} +1 -1
  51. package/dist/assets/{plugin-gantt-Bdm-Yvii.js → plugin-gantt-SwenNrGL.js} +1 -1
  52. package/dist/assets/{plugin-grid-BJGu5-41.js → plugin-grid-a0e-qAUn.js} +2 -2
  53. package/dist/assets/{plugin-kanban-BN37MzOm.js → plugin-kanban-B9xzSYs9.js} +1 -1
  54. package/dist/assets/{plugin-map-Bamjhlg6.js → plugin-map-DnfptTJp.js} +1 -1
  55. package/dist/assets/{plugin-markdown-Cg477jm9.js → plugin-markdown-DgBcCCgO.js} +1 -1
  56. package/dist/assets/{plugin-report-9ivqW5g0.js → plugin-report-Dny_M7U-.js} +1 -1
  57. package/dist/assets/{plugin-timeline-C9C1_Un7.js → plugin-timeline-8zgO0jxJ.js} +1 -1
  58. package/dist/assets/{plugin-tree-BDrBkDUi.js → plugin-tree-Bzgro7b4.js} +1 -1
  59. package/dist/assets/{plugin-view-YLoG5wfy.js → plugin-view-DfJ5SCdu.js} +1 -1
  60. package/dist/assets/{plugins-views-DyIUCjnC.js → plugins-views-CoobEMX4.js} +1 -1
  61. package/dist/assets/{skeletons-CnYUdj-X.js → skeletons-Bf9TL3pG.js} +1 -1
  62. package/dist/assets/{src-LTygtqhe.js → src-BMWmj9Zz.js} +1 -1
  63. package/dist/assets/{src--kVwJFRS.js → src-C6-lrmoQ.js} +1 -1
  64. package/dist/assets/src-CQwyy7m_.js +18 -0
  65. package/dist/assets/{types-KTMf42UB.js → types-033eBMjb.js} +1 -1
  66. package/dist/assets/{ui-components-t1CVb1Ox.js → ui-components-Y3D5-fgK.js} +1 -1
  67. package/dist/assets/{ui-layout-C7dEpbqb.js → ui-layout-FqyUicdD.js} +1 -1
  68. package/dist/assets/{use-book-data-Ddcv6p9p.js → use-book-data-BThfYUpK.js} +1 -1
  69. package/dist/assets/{useMetadata-Ca0oaT4_.js → useMetadata-D5f_5ULL.js} +1 -1
  70. package/dist/index.html +4 -4
  71. package/package.json +1 -1
  72. package/dist/assets/data-adapter-CCueB_gY.js +0 -7
  73. package/dist/assets/i18n-DALEd5g8.js +0 -9
  74. package/dist/assets/index-BCvtzf7n.css +0 -2
  75. package/dist/assets/mermaid-GHXKKRXX-D6paxo1u.js +0 -1
  76. package/dist/assets/src-DD4w6yW2.js +0 -18
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{r as t,y as n}from"./vendor-react-BKSb6vFP.js";import{L as r}from"./framework-DUXRLJaF.js";import{Cr as i,Gn as a,Jn as o,Kn as s,Qi as ee,Wi as te,Xn as c,Ya as ne,Yn as l,Yo as u,_t as d,ar as re,ds as ie,gt as f,ht as ae,ir as p,ki as oe,ln as m,mt as se,nr as ce,pn as h,qi as le,qn as g,rr as ue,sr as de,ss as fe,tr as pe,vt as me,yt as _}from"./ui-components-t1CVb1Ox.js";import{r as v}from"./vendor-ui-utils-D-WJ115h.js";import"./src-DD4w6yW2.js";var y=e(n(),1),b=t();function he(e){return e?e.replace(/^\/+/,``).match(/^forms\/([^/?#]+)/i)?.[1]??null:null}function x(e){return e.trim().toLowerCase().replace(/[^a-z0-9-_]+/g,`-`).replace(/^-+|-+$/g,``)}function S(){let e=r()?.getClient?.(),[t,n]=(0,y.useState)([]),[S,ge]=(0,y.useState)([]),[C,w]=(0,y.useState)(!0),[T,E]=(0,y.useState)(null),[_e,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(``),[A,j]=(0,y.useState)(``),[M,N]=(0,y.useState)(!1),[ve,P]=(0,y.useState)(!1),[F,I]=(0,y.useState)(null),[L,R]=(0,y.useState)(``),[z,B]=(0,y.useState)(`thank-you`),[V,H]=(0,y.useState)(``),[U,W]=(0,y.useState)(``),[G,K]=(0,y.useState)(``),[q,J]=(0,y.useState)(!1),Y=async()=>{if(!e?.meta?.getItems){E(`meta.getItems is not available on this client`),w(!1);return}w(!0),E(null);try{let t=await e.meta.getItems(`view`),r=Array.isArray(t)?t:Array.isArray(t?.items)?t.items:Array.isArray(t?.value)?t.value:[],i=[],a=[];for(let e of r){let t=e?.spec??e;if(!(t?.sections||t?.groups||t?.form||t?.type===`simple`||t?.type===`tabbed`||t?.type===`wizard`||t?.viewType===`form`))continue;let n=t?.sharing,r=n?.publicLink,o=he(r);n?.allowAnonymous&&o&&r?i.push({name:t?.name??e?.name,label:t?.label,object:t?.object,slug:o,publicLink:r,updatedAt:e?.updatedAt??e?.updated_at,spec:t}):a.push({name:t?.name??e?.name,label:t?.label,object:t?.object,spec:t})}n(i),ge(a)}catch(e){E(e?.message??String(e))}finally{w(!1)}};(0,y.useEffect)(()=>{Y()},[]);let X=typeof window<`u`?window.location.origin:``,Z=e=>`${X}/console/f/${e}`,ye=e=>`<iframe src="${Z(e)}" width="100%" height="640" frameborder="0" style="border:0;"></iframe>`,be=e=>`<iframe\n src={\`${Z(e)}\`}\n title="Public form"\n style={{ width: '100%', height: 640, border: 0 }}\n/>`,Q=async(e,t)=>{try{await navigator.clipboard.writeText(t),v.success(`Copied ${e}`)}catch{v.error(`Clipboard unavailable`)}},xe=async()=>{if(!O||!A)return;let t=S.find(e=>e.name===O);if(!t)return;let n=x(A);if(!n){v.error(`Invalid slug`);return}let r={...t.spec,sharing:{...t.spec.sharing??{},enabled:!0,allowAnonymous:!0,publicLink:`/forms/${n}`}};N(!0);try{await e.meta.saveItem(`view`,t.name,r),v.success(`Published ${t.name}`),D(!1),k(``),j(``),await Y()}catch(e){v.error(`Publish failed: ${e?.message??e}`)}finally{N(!1)}},Se=e=>{I(e),R(e.slug);let t=e.spec?.submitBehavior,n=t?.kind??`thank-you`;B(n),H(t?.title??``),W(t?.message??``),K(t?.url??``),P(!0)},Ce=async()=>{if(!F)return;let t=x(L);if(!t){v.error(`Invalid slug`);return}let n;switch(z){case`thank-you`:n={kind:`thank-you`},V&&(n.title=V),U&&(n.message=U);break;case`redirect`:if(!G){v.error(`Redirect URL is required`);return}n={kind:`redirect`,url:G};break;case`continue`:case`next-record`:n={kind:z};break}let r={...F.spec,sharing:{...F.spec.sharing??{},enabled:!0,allowAnonymous:!0,publicLink:`/forms/${t}`},submitBehavior:n};J(!0);try{await e.meta.saveItem(`view`,F.name,r),v.success(`Saved ${F.name}`),P(!1),I(null),await Y()}catch(e){v.error(`Save failed: ${e?.message??e}`)}finally{J(!1)}},$=t.length>0;return(0,b.jsxs)(`div`,{className:`flex flex-1 flex-col gap-4 p-4 md:p-6 overflow-auto`,children:[(0,b.jsxs)(pe,{children:[(0,b.jsxs)(p,{className:`flex flex-row items-start justify-between gap-4 space-y-0`,children:[(0,b.jsxs)(`div`,{children:[(0,b.jsxs)(re,{className:`flex items-center gap-2`,children:[(0,b.jsx)(le,{className:`h-4 w-4`}),`Public Forms`]}),(0,b.jsx)(ue,{children:`Forms anyone can fill out — no login required. Publish a form to get a shareable link; submissions land directly in the bound object.`})]}),(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsxs)(i,{variant:`default`,size:`sm`,onClick:()=>D(!0),disabled:S.length===0,title:S.length===0?`No non-public FormViews available`:`Publish a FormView`,children:[(0,b.jsx)(ee,{className:`h-3.5 w-3.5`}),(0,b.jsx)(`span`,{className:`ml-1.5`,children:`Publish form…`})]}),(0,b.jsxs)(i,{variant:`outline`,size:`sm`,onClick:Y,disabled:C,children:[(0,b.jsx)(te,{className:`h-3.5 w-3.5 ${C?`animate-spin`:``}`}),(0,b.jsx)(`span`,{className:`ml-1.5`,children:`Refresh`})]})]})]}),(0,b.jsxs)(ce,{children:[T&&(0,b.jsx)(`div`,{className:`mb-3 rounded-md border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive`,children:T}),!C&&!$&&(0,b.jsxs)(`div`,{className:`rounded-md border border-dashed p-6 text-center text-sm text-muted-foreground`,children:[(0,b.jsx)(`p`,{className:`font-medium text-foreground`,children:`No public forms yet`}),(0,b.jsxs)(`p`,{className:`mt-1`,children:[`Click `,(0,b.jsx)(`strong`,{children:`Publish form…`}),` above to share an existing form, or build a new one in Views & Apps and mark it public.`]})]}),$&&(0,b.jsxs)(se,{children:[(0,b.jsx)(me,{children:(0,b.jsxs)(_,{children:[(0,b.jsx)(d,{children:`Name`}),(0,b.jsx)(d,{children:`Object`}),(0,b.jsx)(d,{children:`Slug`}),(0,b.jsx)(d,{children:`Public URL`}),(0,b.jsx)(d,{className:`text-right`,children:`Actions`})]})}),(0,b.jsx)(ae,{children:t.map(e=>{let t=Z(e.slug);return(0,b.jsxs)(_,{children:[(0,b.jsx)(f,{children:(0,b.jsxs)(`div`,{className:`flex flex-col`,children:[(0,b.jsx)(`span`,{className:`font-medium`,children:e.label??e.name}),(0,b.jsx)(`code`,{className:`text-xs text-muted-foreground`,children:e.name})]})}),(0,b.jsx)(f,{children:e.object?(0,b.jsx)(de,{variant:`secondary`,children:e.object}):(0,b.jsx)(`span`,{className:`text-muted-foreground`,children:`—`})}),(0,b.jsx)(f,{children:(0,b.jsx)(`code`,{className:`text-xs`,children:e.slug})}),(0,b.jsx)(f,{children:(0,b.jsxs)(`a`,{href:t,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-xs text-primary underline-offset-2 hover:underline`,children:[t,(0,b.jsx)(u,{className:`h-3 w-3`})]})}),(0,b.jsx)(f,{className:`text-right`,children:(0,b.jsxs)(`div`,{className:`inline-flex gap-1`,children:[(0,b.jsx)(i,{variant:`ghost`,size:`sm`,title:`Copy URL`,onClick:()=>Q(`URL`,t),children:(0,b.jsx)(ne,{className:`h-3.5 w-3.5`})}),(0,b.jsx)(i,{variant:`ghost`,size:`sm`,title:`Copy <iframe> embed`,onClick:()=>Q(`iframe snippet`,ye(e.slug)),children:(0,b.jsx)(ie,{className:`h-3.5 w-3.5`})}),(0,b.jsx)(i,{variant:`ghost`,size:`sm`,title:`Copy React snippet`,onClick:()=>Q(`React snippet`,be(e.slug)),children:(0,b.jsx)(fe,{className:`h-3.5 w-3.5`})}),(0,b.jsx)(i,{variant:`ghost`,size:`sm`,title:`Edit sharing & post-submit behavior`,onClick:()=>Se(e),children:(0,b.jsx)(oe,{className:`h-3.5 w-3.5`})})]})})]},e.name)})})]})]})]}),(0,b.jsx)(a,{open:_e,onOpenChange:D,children:(0,b.jsxs)(s,{className:`sm:max-w-md`,children:[(0,b.jsxs)(l,{children:[(0,b.jsx)(c,{children:`Publish a FormView`}),(0,b.jsxs)(g,{children:[`Pick an existing FormView and turn it into a public form by enabling `,(0,b.jsx)(`code`,{className:`text-xs`,children:`sharing.allowAnonymous`}),` `,`and setting `,(0,b.jsx)(`code`,{className:`text-xs`,children:`publicLink`}),`.`]})]}),(0,b.jsxs)(`div`,{className:`space-y-3`,children:[(0,b.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,b.jsx)(h,{htmlFor:`publish-view`,children:`FormView`}),(0,b.jsxs)(`select`,{id:`publish-view`,className:`flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm`,value:O,onChange:e=>k(e.target.value),children:[(0,b.jsx)(`option`,{value:``,children:`— Select a FormView —`}),S.map(e=>(0,b.jsxs)(`option`,{value:e.name,children:[e.label??e.name,` (`,e.name,`) `,e.object?`· ${e.object}`:``]},e.name))]})]}),(0,b.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,b.jsx)(h,{htmlFor:`publish-slug`,children:`URL slug`}),(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsx)(`span`,{className:`text-xs text-muted-foreground whitespace-nowrap`,children:`/console/f/`}),(0,b.jsx)(m,{id:`publish-slug`,placeholder:`contact-us`,value:A,onChange:e=>j(e.target.value)})]}),(0,b.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Lowercase letters, digits, dashes and underscores only.`})]})]}),(0,b.jsxs)(o,{children:[(0,b.jsx)(i,{variant:`ghost`,onClick:()=>D(!1),disabled:M,children:`Cancel`}),(0,b.jsx)(i,{onClick:xe,disabled:M||!O||!A,children:M?`Publishing…`:`Publish`})]})]})}),(0,b.jsx)(a,{open:ve,onOpenChange:P,children:(0,b.jsxs)(s,{className:`sm:max-w-lg`,children:[(0,b.jsxs)(l,{children:[(0,b.jsx)(c,{children:F?`Edit ${F.label??F.name}`:`Edit form`}),(0,b.jsx)(g,{children:`Configure the public URL and what happens after submit.`})]}),(0,b.jsxs)(`div`,{className:`space-y-3`,children:[(0,b.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,b.jsx)(h,{htmlFor:`edit-slug`,children:`URL slug`}),(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsx)(`span`,{className:`text-xs text-muted-foreground whitespace-nowrap`,children:`/console/f/`}),(0,b.jsx)(m,{id:`edit-slug`,value:L,onChange:e=>R(e.target.value)})]})]}),(0,b.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,b.jsx)(h,{htmlFor:`edit-behavior`,children:`After submit`}),(0,b.jsxs)(`select`,{id:`edit-behavior`,className:`flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm`,value:z,onChange:e=>B(e.target.value),children:[(0,b.jsx)(`option`,{value:`thank-you`,children:`Show a thank-you panel`}),(0,b.jsx)(`option`,{value:`redirect`,children:`Redirect to a URL`}),(0,b.jsx)(`option`,{value:`continue`,children:`Reset for another response`}),(0,b.jsx)(`option`,{value:`next-record`,children:`Advance to next record (internal queues)`})]})]}),z===`thank-you`&&(0,b.jsxs)(b.Fragment,{children:[(0,b.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,b.jsx)(h,{htmlFor:`edit-tytitle`,children:`Title`}),(0,b.jsx)(m,{id:`edit-tytitle`,placeholder:`Thanks!`,value:V,onChange:e=>H(e.target.value)})]}),(0,b.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,b.jsx)(h,{htmlFor:`edit-tymsg`,children:`Message`}),(0,b.jsx)(m,{id:`edit-tymsg`,placeholder:`Your submission has been received.`,value:U,onChange:e=>W(e.target.value)})]})]}),z===`redirect`&&(0,b.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,b.jsx)(h,{htmlFor:`edit-url`,children:`Redirect URL`}),(0,b.jsx)(m,{id:`edit-url`,type:`url`,placeholder:`https://example.com/thanks`,value:G,onChange:e=>K(e.target.value)})]})]}),(0,b.jsxs)(o,{children:[(0,b.jsx)(i,{variant:`ghost`,onClick:()=>P(!1),disabled:q,children:`Cancel`}),(0,b.jsx)(i,{onClick:Ce,disabled:q||!L,children:q?`Saving…`:`Save`})]})]})})]})}export{S as PublicFormsPage};
1
+ import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{r as t,y as n}from"./vendor-react-BKSb6vFP.js";import{L as r}from"./framework-BL3BtpKU.js";import{Cr as i,Gn as a,Jn as o,Kn as s,Qi as ee,Wi as te,Xn as c,Ya as ne,Yn as l,Yo as u,_t as d,ar as re,ds as ie,gt as f,ht as ae,ir as p,ki as oe,ln as m,mt as se,nr as ce,pn as h,qi as le,qn as g,rr as ue,sr as de,ss as fe,tr as pe,vt as me,yt as _}from"./ui-components-Y3D5-fgK.js";import{r as v}from"./vendor-ui-utils-D-WJ115h.js";import"./src-CQwyy7m_.js";var y=e(n(),1),b=t();function he(e){return e?e.replace(/^\/+/,``).match(/^forms\/([^/?#]+)/i)?.[1]??null:null}function x(e){return e.trim().toLowerCase().replace(/[^a-z0-9-_]+/g,`-`).replace(/^-+|-+$/g,``)}function S(){let e=r()?.getClient?.(),[t,n]=(0,y.useState)([]),[S,ge]=(0,y.useState)([]),[C,w]=(0,y.useState)(!0),[T,E]=(0,y.useState)(null),[_e,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(``),[A,j]=(0,y.useState)(``),[M,N]=(0,y.useState)(!1),[ve,P]=(0,y.useState)(!1),[F,I]=(0,y.useState)(null),[L,R]=(0,y.useState)(``),[z,B]=(0,y.useState)(`thank-you`),[V,H]=(0,y.useState)(``),[U,W]=(0,y.useState)(``),[G,K]=(0,y.useState)(``),[q,J]=(0,y.useState)(!1),Y=async()=>{if(!e?.meta?.getItems){E(`meta.getItems is not available on this client`),w(!1);return}w(!0),E(null);try{let t=await e.meta.getItems(`view`),r=Array.isArray(t)?t:Array.isArray(t?.items)?t.items:Array.isArray(t?.value)?t.value:[],i=[],a=[];for(let e of r){let t=e?.spec??e;if(!(t?.sections||t?.groups||t?.form||t?.type===`simple`||t?.type===`tabbed`||t?.type===`wizard`||t?.viewType===`form`))continue;let n=t?.sharing,r=n?.publicLink,o=he(r);n?.allowAnonymous&&o&&r?i.push({name:t?.name??e?.name,label:t?.label,object:t?.object,slug:o,publicLink:r,updatedAt:e?.updatedAt??e?.updated_at,spec:t}):a.push({name:t?.name??e?.name,label:t?.label,object:t?.object,spec:t})}n(i),ge(a)}catch(e){E(e?.message??String(e))}finally{w(!1)}};(0,y.useEffect)(()=>{Y()},[]);let X=typeof window<`u`?window.location.origin:``,Z=e=>`${X}/console/f/${e}`,ye=e=>`<iframe src="${Z(e)}" width="100%" height="640" frameborder="0" style="border:0;"></iframe>`,be=e=>`<iframe\n src={\`${Z(e)}\`}\n title="Public form"\n style={{ width: '100%', height: 640, border: 0 }}\n/>`,Q=async(e,t)=>{try{await navigator.clipboard.writeText(t),v.success(`Copied ${e}`)}catch{v.error(`Clipboard unavailable`)}},xe=async()=>{if(!O||!A)return;let t=S.find(e=>e.name===O);if(!t)return;let n=x(A);if(!n){v.error(`Invalid slug`);return}let r={...t.spec,sharing:{...t.spec.sharing??{},enabled:!0,allowAnonymous:!0,publicLink:`/forms/${n}`}};N(!0);try{await e.meta.saveItem(`view`,t.name,r),v.success(`Published ${t.name}`),D(!1),k(``),j(``),await Y()}catch(e){v.error(`Publish failed: ${e?.message??e}`)}finally{N(!1)}},Se=e=>{I(e),R(e.slug);let t=e.spec?.submitBehavior,n=t?.kind??`thank-you`;B(n),H(t?.title??``),W(t?.message??``),K(t?.url??``),P(!0)},Ce=async()=>{if(!F)return;let t=x(L);if(!t){v.error(`Invalid slug`);return}let n;switch(z){case`thank-you`:n={kind:`thank-you`},V&&(n.title=V),U&&(n.message=U);break;case`redirect`:if(!G){v.error(`Redirect URL is required`);return}n={kind:`redirect`,url:G};break;case`continue`:case`next-record`:n={kind:z};break}let r={...F.spec,sharing:{...F.spec.sharing??{},enabled:!0,allowAnonymous:!0,publicLink:`/forms/${t}`},submitBehavior:n};J(!0);try{await e.meta.saveItem(`view`,F.name,r),v.success(`Saved ${F.name}`),P(!1),I(null),await Y()}catch(e){v.error(`Save failed: ${e?.message??e}`)}finally{J(!1)}},$=t.length>0;return(0,b.jsxs)(`div`,{className:`flex flex-1 flex-col gap-4 p-4 md:p-6 overflow-auto`,children:[(0,b.jsxs)(pe,{children:[(0,b.jsxs)(p,{className:`flex flex-row items-start justify-between gap-4 space-y-0`,children:[(0,b.jsxs)(`div`,{children:[(0,b.jsxs)(re,{className:`flex items-center gap-2`,children:[(0,b.jsx)(le,{className:`h-4 w-4`}),`Public Forms`]}),(0,b.jsx)(ue,{children:`Forms anyone can fill out — no login required. Publish a form to get a shareable link; submissions land directly in the bound object.`})]}),(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsxs)(i,{variant:`default`,size:`sm`,onClick:()=>D(!0),disabled:S.length===0,title:S.length===0?`No non-public FormViews available`:`Publish a FormView`,children:[(0,b.jsx)(ee,{className:`h-3.5 w-3.5`}),(0,b.jsx)(`span`,{className:`ml-1.5`,children:`Publish form…`})]}),(0,b.jsxs)(i,{variant:`outline`,size:`sm`,onClick:Y,disabled:C,children:[(0,b.jsx)(te,{className:`h-3.5 w-3.5 ${C?`animate-spin`:``}`}),(0,b.jsx)(`span`,{className:`ml-1.5`,children:`Refresh`})]})]})]}),(0,b.jsxs)(ce,{children:[T&&(0,b.jsx)(`div`,{className:`mb-3 rounded-md border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive`,children:T}),!C&&!$&&(0,b.jsxs)(`div`,{className:`rounded-md border border-dashed p-6 text-center text-sm text-muted-foreground`,children:[(0,b.jsx)(`p`,{className:`font-medium text-foreground`,children:`No public forms yet`}),(0,b.jsxs)(`p`,{className:`mt-1`,children:[`Click `,(0,b.jsx)(`strong`,{children:`Publish form…`}),` above to share an existing form, or build a new one in Views & Apps and mark it public.`]})]}),$&&(0,b.jsxs)(se,{children:[(0,b.jsx)(me,{children:(0,b.jsxs)(_,{children:[(0,b.jsx)(d,{children:`Name`}),(0,b.jsx)(d,{children:`Object`}),(0,b.jsx)(d,{children:`Slug`}),(0,b.jsx)(d,{children:`Public URL`}),(0,b.jsx)(d,{className:`text-right`,children:`Actions`})]})}),(0,b.jsx)(ae,{children:t.map(e=>{let t=Z(e.slug);return(0,b.jsxs)(_,{children:[(0,b.jsx)(f,{children:(0,b.jsxs)(`div`,{className:`flex flex-col`,children:[(0,b.jsx)(`span`,{className:`font-medium`,children:e.label??e.name}),(0,b.jsx)(`code`,{className:`text-xs text-muted-foreground`,children:e.name})]})}),(0,b.jsx)(f,{children:e.object?(0,b.jsx)(de,{variant:`secondary`,children:e.object}):(0,b.jsx)(`span`,{className:`text-muted-foreground`,children:`—`})}),(0,b.jsx)(f,{children:(0,b.jsx)(`code`,{className:`text-xs`,children:e.slug})}),(0,b.jsx)(f,{children:(0,b.jsxs)(`a`,{href:t,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-xs text-primary underline-offset-2 hover:underline`,children:[t,(0,b.jsx)(u,{className:`h-3 w-3`})]})}),(0,b.jsx)(f,{className:`text-right`,children:(0,b.jsxs)(`div`,{className:`inline-flex gap-1`,children:[(0,b.jsx)(i,{variant:`ghost`,size:`sm`,title:`Copy URL`,onClick:()=>Q(`URL`,t),children:(0,b.jsx)(ne,{className:`h-3.5 w-3.5`})}),(0,b.jsx)(i,{variant:`ghost`,size:`sm`,title:`Copy <iframe> embed`,onClick:()=>Q(`iframe snippet`,ye(e.slug)),children:(0,b.jsx)(ie,{className:`h-3.5 w-3.5`})}),(0,b.jsx)(i,{variant:`ghost`,size:`sm`,title:`Copy React snippet`,onClick:()=>Q(`React snippet`,be(e.slug)),children:(0,b.jsx)(fe,{className:`h-3.5 w-3.5`})}),(0,b.jsx)(i,{variant:`ghost`,size:`sm`,title:`Edit sharing & post-submit behavior`,onClick:()=>Se(e),children:(0,b.jsx)(oe,{className:`h-3.5 w-3.5`})})]})})]},e.name)})})]})]})]}),(0,b.jsx)(a,{open:_e,onOpenChange:D,children:(0,b.jsxs)(s,{className:`sm:max-w-md`,children:[(0,b.jsxs)(l,{children:[(0,b.jsx)(c,{children:`Publish a FormView`}),(0,b.jsxs)(g,{children:[`Pick an existing FormView and turn it into a public form by enabling `,(0,b.jsx)(`code`,{className:`text-xs`,children:`sharing.allowAnonymous`}),` `,`and setting `,(0,b.jsx)(`code`,{className:`text-xs`,children:`publicLink`}),`.`]})]}),(0,b.jsxs)(`div`,{className:`space-y-3`,children:[(0,b.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,b.jsx)(h,{htmlFor:`publish-view`,children:`FormView`}),(0,b.jsxs)(`select`,{id:`publish-view`,className:`flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm`,value:O,onChange:e=>k(e.target.value),children:[(0,b.jsx)(`option`,{value:``,children:`— Select a FormView —`}),S.map(e=>(0,b.jsxs)(`option`,{value:e.name,children:[e.label??e.name,` (`,e.name,`) `,e.object?`· ${e.object}`:``]},e.name))]})]}),(0,b.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,b.jsx)(h,{htmlFor:`publish-slug`,children:`URL slug`}),(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsx)(`span`,{className:`text-xs text-muted-foreground whitespace-nowrap`,children:`/console/f/`}),(0,b.jsx)(m,{id:`publish-slug`,placeholder:`contact-us`,value:A,onChange:e=>j(e.target.value)})]}),(0,b.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Lowercase letters, digits, dashes and underscores only.`})]})]}),(0,b.jsxs)(o,{children:[(0,b.jsx)(i,{variant:`ghost`,onClick:()=>D(!1),disabled:M,children:`Cancel`}),(0,b.jsx)(i,{onClick:xe,disabled:M||!O||!A,children:M?`Publishing…`:`Publish`})]})]})}),(0,b.jsx)(a,{open:ve,onOpenChange:P,children:(0,b.jsxs)(s,{className:`sm:max-w-lg`,children:[(0,b.jsxs)(l,{children:[(0,b.jsx)(c,{children:F?`Edit ${F.label??F.name}`:`Edit form`}),(0,b.jsx)(g,{children:`Configure the public URL and what happens after submit.`})]}),(0,b.jsxs)(`div`,{className:`space-y-3`,children:[(0,b.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,b.jsx)(h,{htmlFor:`edit-slug`,children:`URL slug`}),(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsx)(`span`,{className:`text-xs text-muted-foreground whitespace-nowrap`,children:`/console/f/`}),(0,b.jsx)(m,{id:`edit-slug`,value:L,onChange:e=>R(e.target.value)})]})]}),(0,b.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,b.jsx)(h,{htmlFor:`edit-behavior`,children:`After submit`}),(0,b.jsxs)(`select`,{id:`edit-behavior`,className:`flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm`,value:z,onChange:e=>B(e.target.value),children:[(0,b.jsx)(`option`,{value:`thank-you`,children:`Show a thank-you panel`}),(0,b.jsx)(`option`,{value:`redirect`,children:`Redirect to a URL`}),(0,b.jsx)(`option`,{value:`continue`,children:`Reset for another response`}),(0,b.jsx)(`option`,{value:`next-record`,children:`Advance to next record (internal queues)`})]})]}),z===`thank-you`&&(0,b.jsxs)(b.Fragment,{children:[(0,b.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,b.jsx)(h,{htmlFor:`edit-tytitle`,children:`Title`}),(0,b.jsx)(m,{id:`edit-tytitle`,placeholder:`Thanks!`,value:V,onChange:e=>H(e.target.value)})]}),(0,b.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,b.jsx)(h,{htmlFor:`edit-tymsg`,children:`Message`}),(0,b.jsx)(m,{id:`edit-tymsg`,placeholder:`Your submission has been received.`,value:U,onChange:e=>W(e.target.value)})]})]}),z===`redirect`&&(0,b.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,b.jsx)(h,{htmlFor:`edit-url`,children:`Redirect URL`}),(0,b.jsx)(m,{id:`edit-url`,type:`url`,placeholder:`https://example.com/thanks`,value:G,onChange:e=>K(e.target.value)})]})]}),(0,b.jsxs)(o,{children:[(0,b.jsx)(i,{variant:`ghost`,onClick:()=>P(!1),disabled:q,children:`Cancel`}),(0,b.jsx)(i,{onClick:Ce,disabled:q||!L,children:q?`Saving…`:`Save`})]})]})})]})}export{S as PublicFormsPage};
@@ -1,2 +1,2 @@
1
- import{o as e,r as t}from"./rolldown-runtime-DAXXjFlN.js";import{a as n,d as r,f as i,h as a,m as o,r as s,y as c}from"./vendor-react-BKSb6vFP.js";import{h as l,p as u}from"./infrastructure-Bc4DRENl.js";import{A as d,H as f,Kt as p,L as m,N as h,O as g,R as _,U as v,Wt as y,Y as b,b as x,i as ee,j as te,l as S,n as ne,nt as re,ut as ie,v as ae,w as oe}from"./framework-DUXRLJaF.js";import{$o as C,Ar as se,C as w,Cr as T,D as ce,Dn as le,En as ue,Gn as E,Gt as de,Ha as D,Hr as O,Hs as fe,Ht as pe,Jn as me,Jo as he,Jt as ge,K as _e,Kn as ve,Kt as ye,Nc as be,Ns as xe,O as Se,Oc as k,On as Ce,Pc as we,Qi as Te,Qt as Ee,Rr as De,Tn as Oe,Ut as ke,Vs as Ae,Wt as je,X as Me,Xn as A,Xt as j,Yn as Ne,Yr as Pe,Yt as M,Zt as Fe,_r as Ie,br as Le,er as Re,gr as ze,hr as Be,ln as N,lt as Ve,mr as P,pn as F,q as He,qn as Ue,qo as I,rs as We,sa as Ge,ss as L,tr as Ke,vr as qe,wn as Je,xr as R,yr as Ye}from"./ui-components-t1CVb1Ox.js";import{r as z}from"./vendor-ui-utils-D-WJ115h.js";import{n as Xe,t as B}from"./plugin-form-zDPLpTAc.js";import{n as V}from"./plugin-gantt-Bdm-Yvii.js";import"./utils-Bxty7IIa.js";import{c as Ze,i as Qe,n as $e,r as et,s as tt}from"./plugins-views-DyIUCjnC.js";import{n as nt,t as rt}from"./MetadataInspector-Dc5CNMYV.js";import{t as it}from"./i18n-DALEd5g8.js";import{t as at}from"./ManagedByBadge-3xVjmTY7.js";import{t as ot}from"./skeletons-CnYUdj-X.js";var H=e(c(),1),U=s(),st=(0,H.createContext)({favorites:null,recent:null}),W=(0,H.createContext)(null);function ct({children:e}){let[t,n]=(0,H.useState)({favorites:null,recent:null}),r=(0,H.useRef)({attach:(e,t)=>{n(n=>n[e]===t?n:{...n,[e]:t})}});return(0,U.jsx)(W.Provider,{value:r.current,children:(0,U.jsx)(st.Provider,{value:t,children:e})})}function lt(e){return(0,H.useContext)(st)[e]}function ut(){let e=(0,H.useContext)(W);return(0,H.useCallback)((t,n)=>{e?.attach(t,n)},[e])}function G(e,t){return t?`${e}:u:${t}`:e}function dt(e,t){let n=(0,H.useRef)(t);n.current=t,(0,H.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 ft(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 pt=`objectui-recent-items`,mt=8;function ht(e){try{let t=localStorage.getItem(G(pt,e));return t?JSON.parse(t):[]}catch{return[]}}function gt(e,t){try{localStorage.setItem(G(pt,t),JSON.stringify(e))}catch{}}var _t=(0,H.createContext)(null);function vt({children:e}){let{user:t}=u(),n=t?.id??null,r=lt(`recent`),[i,a]=(0,H.useState)(()=>ht(n));(0,H.useEffect)(()=>{a(ht(n))},[n]),dt(G(pt,n),e=>{a(Array.isArray(e)?e.filter(e=>e&&typeof e.id==`string`).slice(0,mt):[])});let o=(0,H.useRef)(0);(0,H.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,mt);a(s),gt(s,n)}catch{}})(),()=>{t=!0}},[r,n]);let s=(0,H.useMemo)(()=>ft(async e=>{r&&await r.save(e)},500),[r]);(0,H.useEffect)(()=>()=>{s.flush()},[s]);let c=(0,H.useCallback)(e=>{gt(e,n),r&&s.schedule(e)},[n,r,s]),l=(0,H.useCallback)(e=>{a(t=>{let n=t.filter(t=>t.id!==e.id),r=[{...e,visitedAt:new Date().toISOString()},...n].slice(0,mt);return c(r),r})},[c]),d=(0,H.useCallback)(()=>{a([]),c([])},[c]),f=(0,H.useMemo)(()=>({recentItems:i,addRecentItem:l,clearRecentItems:d}),[i,l,d]);return(0,U.jsx)(_t.Provider,{value:f,children:e})}function yt(){return(0,H.useContext)(_t)||{recentItems:[],addRecentItem:()=>{},clearRecentItems:()=>{}}}function K(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 bt(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 xt(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 St(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 Ct(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 wt={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`},Tt={lg:`sm:max-w-2xl`,xl:`sm:max-w-3xl`,full:`sm:max-w-[95vw]`};function q(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 Et(e){let[t,n]=(0,H.useState)(null),{objects:r}=_(),i=(0,H.useCallback)(e=>{n(t=>(t?.resolve(e),null))},[]),a=(0,H.useCallback)(e=>new Promise(t=>{n({d:q(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?{}:bt(r.find(e=>e?.name===n.objectName));o=(0,U.jsx)(Xe,{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,U.jsx)(b,{schema:n.content}):n.description?(0,U.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:n.description}):null;o=e===`side`?(0,U.jsx)(pe,{open:!0,onOpenChange:a,children:(0,U.jsxs)(ke,{side:n.side||`right`,className:k(`w-full overflow-y-auto`,Tt[n.size||`default`]),children:[n.title&&(0,U.jsxs)(de,{children:[(0,U.jsx)(ye,{children:n.title}),n.description&&(0,U.jsx)(je,{children:n.description})]}),(0,U.jsx)(`div`,{className:`py-3`,children:t})]})}):e===`bottom`?(0,U.jsx)(Je,{open:!0,onOpenChange:a,children:(0,U.jsxs)(Oe,{children:[n.title&&(0,U.jsxs)(le,{children:[(0,U.jsx)(Ce,{children:n.title}),n.description&&(0,U.jsx)(ue,{children:n.description})]}),(0,U.jsx)(`div`,{className:`max-h-[75vh] overflow-y-auto px-4 pb-6`,children:t})]})}):(0,U.jsx)(E,{open:!0,onOpenChange:a,children:(0,U.jsxs)(ve,{className:k(e===`fullscreen`?`h-[95vh] w-full max-w-[98vw] overflow-y-auto`:wt[n.size||`default`]),children:[n.title&&(0,U.jsxs)(Ne,{children:[(0,U.jsx)(A,{children:n.title}),n.description&&(0,U.jsx)(Ue,{children:n.description})]}),(0,U.jsx)(`div`,{children:t}),!n.content&&(0,U.jsx)(`div`,{className:`flex justify-end`,children:(0,U.jsx)(T,{onClick:()=>i({success:!0}),children:`OK`})})]})})}}return{modalHandler:a,modalElement:o,closeModal:i}}var Dt=(0,H.createContext)(void 0);function Ot({children:e}){let[t,n]=(0,H.useState)(`home`),[r,i]=(0,H.useState)(),[a,o]=(0,H.useState)(),s=(0,H.useMemo)(()=>({context:t,setContext:n,currentAppName:r,setCurrentAppName:i,recordTitle:a,setRecordTitle:o}),[t,r,a]);return(0,U.jsx)(Dt.Provider,{value:s,children:e})}function J(){return(0,H.useContext)(Dt)||{context:`app`,setContext:()=>{},currentAppName:void 0,setCurrentAppName:()=>{},recordTitle:void 0,setRecordTitle:()=>{}}}function kt(e){let{setRecordTitle:t}=J();(0,H.useEffect)(()=>(t(e),()=>t(void 0)),[e,t])}var Y=`objectui-favorites`,X=`objectui-nav-pins`,At=20,jt=20;function Z(e){let t=0,n=0,r=!1;for(let i of e)i.type===`nav`?(n++,n>jt&&(r=!0)):(t++,t>At&&(r=!0));if(!r)return e;let i=[],a=0,o=0;for(let t of e)t.type===`nav`?o<jt&&(i.push(t),o++):a<At&&(i.push(t),a++);return i}function Mt(e){try{let t=localStorage.getItem(G(Y,e));return t?JSON.parse(t):[]}catch{return[]}}function Nt(e,t){try{localStorage.setItem(G(Y,t),JSON.stringify(e))}catch{}}function Pt(e){let t;try{t=localStorage.getItem(X)}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(X)}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 Q=(0,H.createContext)(null);function Ft({children:e}){let{user:t}=u(),n=t?.id??null,r=lt(`favorites`),[i,a]=(0,H.useState)(()=>Mt(n));(0,H.useEffect)(()=>{a(Mt(n))},[n]),dt(G(Y,n),e=>{a(Array.isArray(e)?Z(e.filter(e=>e&&typeof e.id==`string`)):[])});let o=(0,H.useRef)(0);(0,H.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=Z((Array.isArray(i)?i:[]).filter(e=>e&&typeof e.id==`string`)),l=Mt(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=Z([...c,...d]),p=!0);let{migrated:m,didMigrate:h}=Pt(f);h&&(f=Z(m),p=!0),a(f),Nt(f,n),p&&s.schedule(f)}catch{}})(),()=>{t=!0}},[r,n]),(0,H.useEffect)(()=>{r||a(e=>{let{migrated:t,didMigrate:r}=Pt(e);if(!r)return e;let i=Z(t);return Nt(i,n),i})},[r,n]);let s=(0,H.useMemo)(()=>ft(async e=>{r&&await r.save(e)},500),[r]);(0,H.useEffect)(()=>()=>{s.flush()},[s]);let c=(0,H.useCallback)(e=>{Nt(e,n),r&&s.schedule(e)},[n,r,s]),l=(0,H.useCallback)(e=>{a(t=>{if(t.some(t=>t.id===e.id))return t;let n=Z([{...e,favoritedAt:new Date().toISOString()},...t]);return c(n),n})},[c]),d=(0,H.useCallback)(e=>{a(t=>{let n=t.filter(t=>t.id!==e);return c(n),n})},[c]),f=(0,H.useCallback)(e=>{a(t=>{let n=t.some(t=>t.id===e.id)?t.filter(t=>t.id!==e.id):Z([{...e,favoritedAt:new Date().toISOString()},...t]);return c(n),n})},[c]),p=(0,H.useCallback)(()=>{a([]),c([])},[c]),m=(0,H.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,H.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,H.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:d,toggleFavorite:f,isFavorite:e=>i.some(t=>t.id===e),clearFavorites:p,refreshLabel:m,setPinned:h,isPinned:e=>i.some(t=>t.id===e&&!!t.pinned),pinnedNavIds:e}},[i,l,d,f,p,m,h]);return(0,U.jsx)(Q.Provider,{value:g,children:e})}function It(){return(0,H.useContext)(Q)||{favorites:[],addFavorite:()=>{},removeFavorite:()=>{},toggleFavorite:()=>{},isFavorite:()=>!1,clearFavorites:()=>{},refreshLabel:()=>{},setPinned:()=>{},isPinned:()=>!1,pinnedNavIds:new Set}}var Lt=new Set([`created_by`,`updated_by`,`owner_id`]);function Rt(e){return e?Array.isArray(e)?e.filter(e=>e&&e.name!=null).map(e=>[String(e.name),e]):Object.entries(e):[]}function zt(e,t){if(!e?.name||!Array.isArray(t)||t.length===0)return[];let n=e.name,r=[],i=[];for(let e of t)if(e?.name)for(let[t,a]of Rt(e.fields)){if(!a)continue;let o=a.type;if(o!==`lookup`&&o!==`master_detail`||(a.reference_to||a.reference)!==n||Lt.has(t)||a.relatedList===!1)continue;let s={childObject:e.name,childLabel:e.label||e.name,referenceField:t,isOwned:o===`master_detail`,isPrimary:a.relatedList===`primary`,_fkLabel:typeof a.label==`string`&&a.label||t,...typeof a.relatedListTitle==`string`&&a.relatedListTitle?{title:a.relatedListTitle}:{},...Array.isArray(a.relatedListColumns)&&a.relatedListColumns.length>0?{columns:a.relatedListColumns}:{}};(s.isOwned?r:i).push(s)}let a=[...r,...i],o={};for(let e of a)o[e.childObject]=(o[e.childObject]||0)+1;return a.map(({_fkLabel:e,...t})=>!t.title&&o[t.childObject]>1?{...t,title:`${t.childLabel} · ${e}`}:t)}function Bt(e){let{url:t,channel:n,autoReconnect:r=!0,reconnectInterval:i=1e3,maxReconnectAttempts:a=10,authToken:o}=e,[s,c]=(0,H.useState)(`disconnected`),[l,u]=(0,H.useState)(null),[d,f]=(0,H.useState)([]),[p,m]=(0,H.useState)(null),h=(0,H.useRef)(null),g=(0,H.useRef)(0),_=(0,H.useRef)(null),v=(0,H.useRef)(new Map),y=(0,H.useRef)([]),b=(0,H.useRef)(!0),x=(0,H.useRef)(!1),ee=(0,H.useCallback)(()=>{_.current!==null&&(clearTimeout(_.current),_.current=null)},[]),te=(0,H.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]),S=(0,H.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,te(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&&S()},e)}else c(`disconnected`)}}},[t,n,o,r,i,a,te]),ne=(0,H.useCallback)(()=>{ee(),x.current=!0,g.current=0,h.current&&=(h.current.close(),null),c(`disconnected`)},[ee]),re=(0,H.useCallback)(()=>{ee(),g.current=0,S()},[S,ee]),ie=(0,H.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]),ae=(0,H.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,H.useEffect)(()=>(b.current=!0,t&&S(),()=>{b.current=!1,ee(),x.current=!0,h.current&&=(h.current.close(),null)}),[t,n,o]),{connectionState:s,isConnected:s===`connected`,lastMessage:l,messages:d,send:ie,subscribe:ae,disconnect:ne,reconnect:re,error:p}}var Vt=0;function Ht(){return Vt+=1,`conflict-${Date.now()}-${Vt}`}var Ut=0;function Wt(){return Ut+=1,`ver-${Date.now()}-${Ut}`}function Gt(e,t,n){let[r,i]=(0,H.useState)([]),[a,o]=(0,H.useState)([]);return{versions:r,currentVersion:(0,H.useMemo)(()=>r.length===0?0:r[r.length-1].version,[r]),conflicts:a,hasConflicts:a.length>0,recordVersion:(0,H.useCallback)((n,r)=>{i(i=>{let a=i.length===0?1:i[i.length-1].version+1,o={id:Wt(),version:a,timestamp:new Date().toISOString(),userId:e,userName:t,changes:n,message:r};return[...i,o]})},[e,t]),resolveConflict:(0,H.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:Wt(),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,H.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:Wt(),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,H.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:Wt(),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,H.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,H.useCallback)(e=>{let t={...e,id:Ht()};o(e=>[...e,t])},[]),clearHistory:(0,H.useCallback)(()=>{i([]),o([])},[])}}var Kt={sm:24,md:32,lg:40},qt={active:`#22c55e`,idle:`#f59e0b`,away:`#94a3b8`};function Jt(e){return e.split(` `).map(e=>e[0]).join(``).toUpperCase().slice(0,2)}function Yt({users:e,maxVisible:t=5,size:n=`md`,showStatus:r=!0,className:i}){let a=Kt[n],o=Math.round(a*.3),s=Math.round(a*.35),c=Math.max(8,Math.round(a*.28)),l=(0,H.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,H.useMemo)(()=>[...l].reverse(),[l]);return H.createElement(`div`,{style:d,className:i,role:`group`,"aria-label":`${e.length} user${e.length===1?``:`s`} present`},u>0&&H.createElement(`div`,{key:`overflow`,style:p,title:`${u} more user${u===1?``:`s`}`},`+${u}`),h.map((e,t)=>H.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?H.createElement(`img`,{src:e.avatar,alt:e.userName,style:{width:`100%`,height:`100%`,objectFit:`cover`}}):Jt(e.userName),r&&H.createElement(`span`,{style:{...m,backgroundColor:qt[e.status]}}))))}var Xt=H.createContext({});function Zt(){let e=H.useContext(Xt),[t,n]=H.useState([]);return H.useEffect(()=>{if(!e.subscribeTenant){n([]);return}return e.subscribeTenant(e=>{n(Array.isArray(e)?e:[])})},[e]),t}function Qt(e,t){let n=H.useContext(Xt),[r,i]=H.useState([]);return H.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 $t=V(),en=`recordId`,tn=`form`,nn=`formObject`,rn=`formLink`,an=`palette`,on=`shortcuts`,$=`from`,sn=48;function cn(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,sn)}:{}})):[]}catch{return[]}}function ln(e){return JSON.stringify(e.slice(-8))}function un(e,t){let n=cn(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,sn)}:{}}),ln(n)}function dn(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($,ln(n)),`${r}?${i.toString()}`}function fn(){return`${``.replace(/\/$/,``)}/api/v1`}async function pn(e,t){let n=await fetch(`${fn()}${e}`,{credentials:`include`,headers:{"Content-Type":`application/json`,...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 mn(e,t,n){let[r,i]=(0,H.useState)(!1),[a,o]=(0,H.useState)(!0),[s,c]=(0,H.useState)([]),l=(0,H.useRef)(!1),u=(0,H.useCallback)(async()=>{if(!(!e||!t)&&!l.current){i(!0);try{let n=await pn(`/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,H.useEffect)(()=>{if(!e||!t){c([]);return}u()},[e,t,u]);let d=(0,H.useMemo)(()=>s.find(e=>e.status===`pending`)??null,[s]),f=(0,H.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,H.useCallback)(async(e,t)=>{if(!d)throw Error(`No pending request`);let r=await pn(`/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,H.useCallback)(e=>m(`approve`,e),[m]),reject:(0,H.useCallback)(e=>m(`reject`,e),[m]),refresh:u}}var hn={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 gn(e){let t=hn[e?.managedBy??`platform`]??hn.platform,n=e?.userActions??{};return{create:n.create??t.create,import:n.import??t.import,edit:n.edit??t.edit,delete:n.delete??t.delete,exportCsv:n.exportCsv??t.exportCsv}}var _n=new Set([`record:discussion`,`record:chatter`]);function vn(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 yn({state:e,onOpenChange:t}){let{t:n}=S(),r=()=>{e.resolve?.(!0),t(!1)},i=()=>{e.resolve?.(!1),t(!1)};return(0,U.jsx)(P,{open:e.open,onOpenChange:e=>{e||i()},children:(0,U.jsxs)(Ie,{children:[(0,U.jsxs)(Le,{children:[(0,U.jsx)(R,{children:e.options?.title||n(`actionConfirm.title`)}),(0,U.jsx)(qe,{children:e.message})]}),(0,U.jsxs)(Ye,{children:[(0,U.jsx)(ze,{onClick:i,children:e.options?.cancelText||n(`actionConfirm.cancel`)}),(0,U.jsx)(Be,{onClick:r,children:e.options?.confirmText||n(`actionConfirm.confirm`)})]})]})})}function bn(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 xn({state:e,onOpenChange:t}){let{t:n,language:r}=S(),[i,a]=(0,H.useState)({}),[o,s]=(0,H.useState)({}),c=re(),l=(0,H.useMemo)(()=>bn(e.params,c),[e.params,c]);(0,H.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,U.jsx)(E,{open:e.open,onOpenChange:e=>{e||f()},children:(0,U.jsxs)(ve,{children:[(0,U.jsxs)(Ne,{children:[(0,U.jsx)(A,{children:e.title||n(`actionDialog.title`)}),(0,U.jsx)(Ue,{children:e.description||n(`actionDialog.description`)})]}),(0,U.jsx)(`div`,{className:`grid gap-4 py-4`,children:l.map(e=>{let t={...e,label:be(e.label,r),helpText:e.helpText==null?e.helpText:be(e.helpText,r),options:e.options?.map(e=>({...e,label:be(e.label,r)}))};if(t.type===`boolean`||t.type===`checkbox`){let e=i[t.name]===!0;return(0,U.jsxs)(`div`,{className:`grid gap-1`,children:[(0,U.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,U.jsx)(Re,{id:t.name,checked:e,onCheckedChange:e=>p(t.name,e===!0),className:`mt-0.5`}),(0,U.jsxs)(F,{htmlFor:t.name,className:`font-normal cursor-pointer`,children:[t.label,t.required&&(0,U.jsx)(`span`,{className:`text-destructive ml-1`,children:`*`})]})]}),o[t.name]&&(0,U.jsx)(`p`,{className:`text-xs text-destructive ml-6`,children:n(`actionDialog.requiredError`,{label:t.label})}),t.helpText&&(0,U.jsx)(`p`,{className:`text-xs text-muted-foreground ml-6`,children:t.helpText})]},t.name)}let a=t.type===`lookup`||t.type===`reference`;return(0,U.jsxs)(`div`,{className:`grid gap-2`,children:[(0,U.jsxs)(F,{htmlFor:t.name,children:[t.label,t.required&&(0,U.jsx)(`span`,{className:`text-destructive ml-1`,children:`*`})]}),t.type===`select`&&t.options?(0,U.jsxs)(ge,{value:i[t.name]??``,onValueChange:e=>p(t.name,e),children:[(0,U.jsx)(Fe,{id:t.name,className:o[t.name]?`border-destructive`:``,children:(0,U.jsx)(Ee,{placeholder:t.placeholder||n(`actionDialog.selectPlaceholder`,{label:t.label})})}),(0,U.jsx)(M,{children:t.options.map(e=>(0,U.jsx)(j,{value:e.value,children:e.label},e.value))})]}):a&&t.referenceTo?(0,U.jsx)(ce,{value:i[t.name]??null,onChange:e=>p(t.name,e),field:{name:t.name,type:`lookup`,reference_to:t.referenceTo,display_field:t.displayField,id_field:t.idField,description_field:t.descriptionField,multiple:t.multiple,title_format:t.titleFormat,lookup_columns:t.lookupColumns,lookup_filters:t.lookupFilters,lookup_page_size:t.lookupPageSize,depends_on:t.dependsOn,placeholder:t.placeholder}}):t.type===`textarea`?(0,U.jsx)(Ve,{id:t.name,value:i[t.name]??``,onChange:e=>p(t.name,e.target.value),placeholder:t.placeholder,className:o[t.name]?`border-destructive`:``}):t.type===`number`?(0,U.jsx)(N,{id:t.name,type:`number`,value:i[t.name]??``,onChange:e=>p(t.name,e.target.value===``?void 0:e.target.valueAsNumber),placeholder:t.placeholder,className:o[t.name]?`border-destructive`:``}):(0,U.jsx)(N,{id:t.name,type:[`email`,`url`,`date`,`datetime-local`,`time`,`password`].includes(t.type)?t.type:`text`,value:i[t.name]??``,onChange:e=>p(t.name,e.target.value),placeholder:t.placeholder||(a?n(`actionDialog.lookupPlaceholder`,{label:t.label}):void 0),className:o[t.name]?`border-destructive`:``}),o[t.name]&&(0,U.jsx)(`p`,{className:`text-xs text-destructive`,children:n(`actionDialog.requiredError`,{label:t.label})}),t.helpText&&(0,U.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:t.helpText}),a&&!t.helpText&&(0,U.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`actionDialog.lookupHelpText`)})]},t.name)})}),(0,U.jsxs)(me,{children:[(0,U.jsx)(T,{variant:`outline`,onClick:f,children:n(`actionDialog.cancel`)}),(0,U.jsx)(T,{onClick:d,children:n(`actionDialog.confirm`)})]})]})})}function Sn(e,t){if(e!=null)return t.split(`.`).reduce((e,t)=>{if(e!=null)return e[t]},e)}function Cn({state:e,onAcknowledge:t}){let{t:n}=S(),{spec:r,data:i}=e,a=(0,H.useMemo)(()=>r?.fields&&r.fields.length>0?r.fields:[{path:``,label:void 0,format:r?.format??`json`}],[r]);return(0,U.jsx)(E,{open:e.open,onOpenChange:e=>{},children:(0,U.jsxs)(ve,{onPointerDownOutside:e=>e.preventDefault(),onEscapeKeyDown:e=>e.preventDefault(),className:`max-w-lg`,children:[(0,U.jsxs)(Ne,{children:[(0,U.jsx)(A,{children:r?.title||n(`actions.resultDialog.defaultTitle`)||`Save this value now`}),r?.description?(0,U.jsx)(Ue,{children:r.description}):null]}),(0,U.jsx)(`div`,{className:`space-y-4 py-2`,children:a.map((e,t)=>(0,U.jsx)(wn,{field:e,value:e.path===``?i:Sn(i,e.path),defaultFormat:r?.format},`${e.path}-${t}`))}),(0,U.jsx)(me,{children:(0,U.jsx)(T,{onClick:t,children:r?.acknowledge||n(`actions.resultDialog.acknowledge`)||`I have saved this`})})]})})}function wn({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,U.jsxs)(`div`,{className:`space-y-1.5`,children:[i?(0,U.jsx)(`div`,{className:`text-sm font-medium text-foreground/80`,children:i}):null,a===`qrcode`?(0,U.jsx)(Dn,{value:t}):null,a===`code-list`?(0,U.jsx)(On,{value:t}):null,a===`secret`?(0,U.jsx)(kn,{value:t}):null,a===`text`?(0,U.jsx)(An,{value:t}):null,a===`json`?(0,U.jsx)(jn,{value:t}):null]})}function Tn(e){let[t,n]=(0,H.useState)(!1);return(0,H.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 En({value:e,label:t}){let{copy:n,copied:r}=Tn(e);return(0,U.jsxs)(T,{type:`button`,variant:`outline`,size:`sm`,onClick:n,children:[r?(0,U.jsx)(fe,{className:`w-4 h-4`}):(0,U.jsx)(L,{className:`w-4 h-4`}),t?(0,U.jsx)(`span`,{className:`ml-2`,children:t}):null]})}function Dn({value:e}){let[t,n]=(0,H.useState)(null);return(0,U.jsxs)(`div`,{className:`space-y-2`,children:[(0,U.jsx)(`div`,{className:`flex justify-center rounded-md border bg-white p-3`,children:t?(0,U.jsx)(`span`,{className:`text-sm text-destructive`,children:t}):(0,U.jsx)(`canvas`,{ref:t=>{!t||!e||(0,$t.toCanvas)(t,e,{width:200,margin:1},e=>{e&&n(e.message)})}})}),(0,U.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,U.jsx)(`code`,{className:`flex-1 truncate rounded bg-muted px-2 py-1 text-xs font-mono`,children:e}),(0,U.jsx)(En,{value:e})]})]})}function On({value:e}){let t=e.join(`
1
+ import{o as e,r as t}from"./rolldown-runtime-DAXXjFlN.js";import{a as n,d as r,f as i,h as a,m as o,r as s,y as c}from"./vendor-react-BKSb6vFP.js";import{h as l,p as u}from"./infrastructure-Bc4DRENl.js";import{A as d,H as f,Kt as p,L as m,N as h,O as g,R as _,U as v,Wt as y,Y as b,b as x,i as ee,j as te,l as S,n as ne,nt as re,ut as ie,v as ae,w as oe}from"./framework-BL3BtpKU.js";import{$o as C,Ar as se,C as w,Cr as T,D as ce,Dn as le,En as ue,Gn as E,Gt as de,Ha as D,Hr as O,Hs as fe,Ht as pe,Jn as me,Jo as he,Jt as ge,K as _e,Kn as ve,Kt as ye,Nc as be,Ns as xe,O as Se,Oc as k,On as Ce,Pc as we,Qi as Te,Qt as Ee,Rr as De,Tn as Oe,Ut as ke,Vs as Ae,Wt as je,X as Me,Xn as A,Xt as j,Yn as Ne,Yr as Pe,Yt as M,Zt as Fe,_r as Ie,br as Le,er as Re,gr as ze,hr as Be,ln as N,lt as Ve,mr as P,pn as F,q as He,qn as Ue,qo as I,rs as We,sa as Ge,ss as L,tr as Ke,vr as qe,wn as Je,xr as R,yr as Ye}from"./ui-components-Y3D5-fgK.js";import{r as z}from"./vendor-ui-utils-D-WJ115h.js";import{n as Xe,t as B}from"./plugin-form-6ug8Woph.js";import{n as V}from"./plugin-gantt-SwenNrGL.js";import"./utils-Bxty7IIa.js";import{c as Ze,i as Qe,n as $e,r as et,s as tt}from"./plugins-views-CoobEMX4.js";import{n as nt,t as rt}from"./MetadataInspector-Bqe7rY0S.js";import{t as it}from"./i18n-BsjEVcp4.js";import{t as at}from"./ManagedByBadge-Cdy82I7A.js";import{t as ot}from"./skeletons-Bf9TL3pG.js";var H=e(c(),1),U=s(),st=(0,H.createContext)({favorites:null,recent:null}),W=(0,H.createContext)(null);function ct({children:e}){let[t,n]=(0,H.useState)({favorites:null,recent:null}),r=(0,H.useRef)({attach:(e,t)=>{n(n=>n[e]===t?n:{...n,[e]:t})}});return(0,U.jsx)(W.Provider,{value:r.current,children:(0,U.jsx)(st.Provider,{value:t,children:e})})}function lt(e){return(0,H.useContext)(st)[e]}function ut(){let e=(0,H.useContext)(W);return(0,H.useCallback)((t,n)=>{e?.attach(t,n)},[e])}function G(e,t){return t?`${e}:u:${t}`:e}function dt(e,t){let n=(0,H.useRef)(t);n.current=t,(0,H.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 ft(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 pt=`objectui-recent-items`,mt=8;function ht(e){try{let t=localStorage.getItem(G(pt,e));return t?JSON.parse(t):[]}catch{return[]}}function gt(e,t){try{localStorage.setItem(G(pt,t),JSON.stringify(e))}catch{}}var _t=(0,H.createContext)(null);function vt({children:e}){let{user:t}=u(),n=t?.id??null,r=lt(`recent`),[i,a]=(0,H.useState)(()=>ht(n));(0,H.useEffect)(()=>{a(ht(n))},[n]),dt(G(pt,n),e=>{a(Array.isArray(e)?e.filter(e=>e&&typeof e.id==`string`).slice(0,mt):[])});let o=(0,H.useRef)(0);(0,H.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,mt);a(s),gt(s,n)}catch{}})(),()=>{t=!0}},[r,n]);let s=(0,H.useMemo)(()=>ft(async e=>{r&&await r.save(e)},500),[r]);(0,H.useEffect)(()=>()=>{s.flush()},[s]);let c=(0,H.useCallback)(e=>{gt(e,n),r&&s.schedule(e)},[n,r,s]),l=(0,H.useCallback)(e=>{a(t=>{let n=t.filter(t=>t.id!==e.id),r=[{...e,visitedAt:new Date().toISOString()},...n].slice(0,mt);return c(r),r})},[c]),d=(0,H.useCallback)(()=>{a([]),c([])},[c]),f=(0,H.useMemo)(()=>({recentItems:i,addRecentItem:l,clearRecentItems:d}),[i,l,d]);return(0,U.jsx)(_t.Provider,{value:f,children:e})}function yt(){return(0,H.useContext)(_t)||{recentItems:[],addRecentItem:()=>{},clearRecentItems:()=>{}}}function K(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 bt(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 xt(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 St(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 Ct(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 wt={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`},Tt={lg:`sm:max-w-2xl`,xl:`sm:max-w-3xl`,full:`sm:max-w-[95vw]`};function q(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 Et(e){let[t,n]=(0,H.useState)(null),{objects:r}=_(),i=(0,H.useCallback)(e=>{n(t=>(t?.resolve(e),null))},[]),a=(0,H.useCallback)(e=>new Promise(t=>{n({d:q(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?{}:bt(r.find(e=>e?.name===n.objectName));o=(0,U.jsx)(Xe,{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,U.jsx)(b,{schema:n.content}):n.description?(0,U.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:n.description}):null;o=e===`side`?(0,U.jsx)(pe,{open:!0,onOpenChange:a,children:(0,U.jsxs)(ke,{side:n.side||`right`,className:k(`w-full overflow-y-auto`,Tt[n.size||`default`]),children:[n.title&&(0,U.jsxs)(de,{children:[(0,U.jsx)(ye,{children:n.title}),n.description&&(0,U.jsx)(je,{children:n.description})]}),(0,U.jsx)(`div`,{className:`py-3`,children:t})]})}):e===`bottom`?(0,U.jsx)(Je,{open:!0,onOpenChange:a,children:(0,U.jsxs)(Oe,{children:[n.title&&(0,U.jsxs)(le,{children:[(0,U.jsx)(Ce,{children:n.title}),n.description&&(0,U.jsx)(ue,{children:n.description})]}),(0,U.jsx)(`div`,{className:`max-h-[75vh] overflow-y-auto px-4 pb-6`,children:t})]})}):(0,U.jsx)(E,{open:!0,onOpenChange:a,children:(0,U.jsxs)(ve,{className:k(e===`fullscreen`?`h-[95vh] w-full max-w-[98vw] overflow-y-auto`:wt[n.size||`default`]),children:[n.title&&(0,U.jsxs)(Ne,{children:[(0,U.jsx)(A,{children:n.title}),n.description&&(0,U.jsx)(Ue,{children:n.description})]}),(0,U.jsx)(`div`,{children:t}),!n.content&&(0,U.jsx)(`div`,{className:`flex justify-end`,children:(0,U.jsx)(T,{onClick:()=>i({success:!0}),children:`OK`})})]})})}}return{modalHandler:a,modalElement:o,closeModal:i}}var Dt=(0,H.createContext)(void 0);function Ot({children:e}){let[t,n]=(0,H.useState)(`home`),[r,i]=(0,H.useState)(),[a,o]=(0,H.useState)(),s=(0,H.useMemo)(()=>({context:t,setContext:n,currentAppName:r,setCurrentAppName:i,recordTitle:a,setRecordTitle:o}),[t,r,a]);return(0,U.jsx)(Dt.Provider,{value:s,children:e})}function J(){return(0,H.useContext)(Dt)||{context:`app`,setContext:()=>{},currentAppName:void 0,setCurrentAppName:()=>{},recordTitle:void 0,setRecordTitle:()=>{}}}function kt(e){let{setRecordTitle:t}=J();(0,H.useEffect)(()=>(t(e),()=>t(void 0)),[e,t])}var Y=`objectui-favorites`,X=`objectui-nav-pins`,At=20,jt=20;function Z(e){let t=0,n=0,r=!1;for(let i of e)i.type===`nav`?(n++,n>jt&&(r=!0)):(t++,t>At&&(r=!0));if(!r)return e;let i=[],a=0,o=0;for(let t of e)t.type===`nav`?o<jt&&(i.push(t),o++):a<At&&(i.push(t),a++);return i}function Mt(e){try{let t=localStorage.getItem(G(Y,e));return t?JSON.parse(t):[]}catch{return[]}}function Nt(e,t){try{localStorage.setItem(G(Y,t),JSON.stringify(e))}catch{}}function Pt(e){let t;try{t=localStorage.getItem(X)}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(X)}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 Q=(0,H.createContext)(null);function Ft({children:e}){let{user:t}=u(),n=t?.id??null,r=lt(`favorites`),[i,a]=(0,H.useState)(()=>Mt(n));(0,H.useEffect)(()=>{a(Mt(n))},[n]),dt(G(Y,n),e=>{a(Array.isArray(e)?Z(e.filter(e=>e&&typeof e.id==`string`)):[])});let o=(0,H.useRef)(0);(0,H.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=Z((Array.isArray(i)?i:[]).filter(e=>e&&typeof e.id==`string`)),l=Mt(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=Z([...c,...d]),p=!0);let{migrated:m,didMigrate:h}=Pt(f);h&&(f=Z(m),p=!0),a(f),Nt(f,n),p&&s.schedule(f)}catch{}})(),()=>{t=!0}},[r,n]),(0,H.useEffect)(()=>{r||a(e=>{let{migrated:t,didMigrate:r}=Pt(e);if(!r)return e;let i=Z(t);return Nt(i,n),i})},[r,n]);let s=(0,H.useMemo)(()=>ft(async e=>{r&&await r.save(e)},500),[r]);(0,H.useEffect)(()=>()=>{s.flush()},[s]);let c=(0,H.useCallback)(e=>{Nt(e,n),r&&s.schedule(e)},[n,r,s]),l=(0,H.useCallback)(e=>{a(t=>{if(t.some(t=>t.id===e.id))return t;let n=Z([{...e,favoritedAt:new Date().toISOString()},...t]);return c(n),n})},[c]),d=(0,H.useCallback)(e=>{a(t=>{let n=t.filter(t=>t.id!==e);return c(n),n})},[c]),f=(0,H.useCallback)(e=>{a(t=>{let n=t.some(t=>t.id===e.id)?t.filter(t=>t.id!==e.id):Z([{...e,favoritedAt:new Date().toISOString()},...t]);return c(n),n})},[c]),p=(0,H.useCallback)(()=>{a([]),c([])},[c]),m=(0,H.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,H.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,H.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:d,toggleFavorite:f,isFavorite:e=>i.some(t=>t.id===e),clearFavorites:p,refreshLabel:m,setPinned:h,isPinned:e=>i.some(t=>t.id===e&&!!t.pinned),pinnedNavIds:e}},[i,l,d,f,p,m,h]);return(0,U.jsx)(Q.Provider,{value:g,children:e})}function It(){return(0,H.useContext)(Q)||{favorites:[],addFavorite:()=>{},removeFavorite:()=>{},toggleFavorite:()=>{},isFavorite:()=>!1,clearFavorites:()=>{},refreshLabel:()=>{},setPinned:()=>{},isPinned:()=>!1,pinnedNavIds:new Set}}var Lt=new Set([`created_by`,`updated_by`,`owner_id`]);function Rt(e){return e?Array.isArray(e)?e.filter(e=>e&&e.name!=null).map(e=>[String(e.name),e]):Object.entries(e):[]}function zt(e,t){if(!e?.name||!Array.isArray(t)||t.length===0)return[];let n=e.name,r=[],i=[];for(let e of t)if(e?.name)for(let[t,a]of Rt(e.fields)){if(!a)continue;let o=a.type;if(o!==`lookup`&&o!==`master_detail`||(a.reference_to||a.reference)!==n||Lt.has(t)||a.relatedList===!1)continue;let s={childObject:e.name,childLabel:e.label||e.name,referenceField:t,isOwned:o===`master_detail`,isPrimary:a.relatedList===`primary`,_fkLabel:typeof a.label==`string`&&a.label||t,...typeof a.relatedListTitle==`string`&&a.relatedListTitle?{title:a.relatedListTitle}:{},...Array.isArray(a.relatedListColumns)&&a.relatedListColumns.length>0?{columns:a.relatedListColumns}:{}};(s.isOwned?r:i).push(s)}let a=[...r,...i],o={};for(let e of a)o[e.childObject]=(o[e.childObject]||0)+1;return a.map(({_fkLabel:e,...t})=>!t.title&&o[t.childObject]>1?{...t,title:`${t.childLabel} · ${e}`}:t)}function Bt(e){let{url:t,channel:n,autoReconnect:r=!0,reconnectInterval:i=1e3,maxReconnectAttempts:a=10,authToken:o}=e,[s,c]=(0,H.useState)(`disconnected`),[l,u]=(0,H.useState)(null),[d,f]=(0,H.useState)([]),[p,m]=(0,H.useState)(null),h=(0,H.useRef)(null),g=(0,H.useRef)(0),_=(0,H.useRef)(null),v=(0,H.useRef)(new Map),y=(0,H.useRef)([]),b=(0,H.useRef)(!0),x=(0,H.useRef)(!1),ee=(0,H.useCallback)(()=>{_.current!==null&&(clearTimeout(_.current),_.current=null)},[]),te=(0,H.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]),S=(0,H.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,te(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&&S()},e)}else c(`disconnected`)}}},[t,n,o,r,i,a,te]),ne=(0,H.useCallback)(()=>{ee(),x.current=!0,g.current=0,h.current&&=(h.current.close(),null),c(`disconnected`)},[ee]),re=(0,H.useCallback)(()=>{ee(),g.current=0,S()},[S,ee]),ie=(0,H.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]),ae=(0,H.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,H.useEffect)(()=>(b.current=!0,t&&S(),()=>{b.current=!1,ee(),x.current=!0,h.current&&=(h.current.close(),null)}),[t,n,o]),{connectionState:s,isConnected:s===`connected`,lastMessage:l,messages:d,send:ie,subscribe:ae,disconnect:ne,reconnect:re,error:p}}var Vt=0;function Ht(){return Vt+=1,`conflict-${Date.now()}-${Vt}`}var Ut=0;function Wt(){return Ut+=1,`ver-${Date.now()}-${Ut}`}function Gt(e,t,n){let[r,i]=(0,H.useState)([]),[a,o]=(0,H.useState)([]);return{versions:r,currentVersion:(0,H.useMemo)(()=>r.length===0?0:r[r.length-1].version,[r]),conflicts:a,hasConflicts:a.length>0,recordVersion:(0,H.useCallback)((n,r)=>{i(i=>{let a=i.length===0?1:i[i.length-1].version+1,o={id:Wt(),version:a,timestamp:new Date().toISOString(),userId:e,userName:t,changes:n,message:r};return[...i,o]})},[e,t]),resolveConflict:(0,H.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:Wt(),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,H.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:Wt(),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,H.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:Wt(),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,H.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,H.useCallback)(e=>{let t={...e,id:Ht()};o(e=>[...e,t])},[]),clearHistory:(0,H.useCallback)(()=>{i([]),o([])},[])}}var Kt={sm:24,md:32,lg:40},qt={active:`#22c55e`,idle:`#f59e0b`,away:`#94a3b8`};function Jt(e){return e.split(` `).map(e=>e[0]).join(``).toUpperCase().slice(0,2)}function Yt({users:e,maxVisible:t=5,size:n=`md`,showStatus:r=!0,className:i}){let a=Kt[n],o=Math.round(a*.3),s=Math.round(a*.35),c=Math.max(8,Math.round(a*.28)),l=(0,H.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,H.useMemo)(()=>[...l].reverse(),[l]);return H.createElement(`div`,{style:d,className:i,role:`group`,"aria-label":`${e.length} user${e.length===1?``:`s`} present`},u>0&&H.createElement(`div`,{key:`overflow`,style:p,title:`${u} more user${u===1?``:`s`}`},`+${u}`),h.map((e,t)=>H.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?H.createElement(`img`,{src:e.avatar,alt:e.userName,style:{width:`100%`,height:`100%`,objectFit:`cover`}}):Jt(e.userName),r&&H.createElement(`span`,{style:{...m,backgroundColor:qt[e.status]}}))))}var Xt=H.createContext({});function Zt(){let e=H.useContext(Xt),[t,n]=H.useState([]);return H.useEffect(()=>{if(!e.subscribeTenant){n([]);return}return e.subscribeTenant(e=>{n(Array.isArray(e)?e:[])})},[e]),t}function Qt(e,t){let n=H.useContext(Xt),[r,i]=H.useState([]);return H.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 $t=V(),en=`recordId`,tn=`form`,nn=`formObject`,rn=`formLink`,an=`palette`,on=`shortcuts`,$=`from`,sn=48;function cn(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,sn)}:{}})):[]}catch{return[]}}function ln(e){return JSON.stringify(e.slice(-8))}function un(e,t){let n=cn(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,sn)}:{}}),ln(n)}function dn(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($,ln(n)),`${r}?${i.toString()}`}function fn(){return`${``.replace(/\/$/,``)}/api/v1`}async function pn(e,t){let n=await fetch(`${fn()}${e}`,{credentials:`include`,headers:{"Content-Type":`application/json`,...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 mn(e,t,n){let[r,i]=(0,H.useState)(!1),[a,o]=(0,H.useState)(!0),[s,c]=(0,H.useState)([]),l=(0,H.useRef)(!1),u=(0,H.useCallback)(async()=>{if(!(!e||!t)&&!l.current){i(!0);try{let n=await pn(`/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,H.useEffect)(()=>{if(!e||!t){c([]);return}u()},[e,t,u]);let d=(0,H.useMemo)(()=>s.find(e=>e.status===`pending`)??null,[s]),f=(0,H.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,H.useCallback)(async(e,t)=>{if(!d)throw Error(`No pending request`);let r=await pn(`/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,H.useCallback)(e=>m(`approve`,e),[m]),reject:(0,H.useCallback)(e=>m(`reject`,e),[m]),refresh:u}}var hn={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 gn(e){let t=hn[e?.managedBy??`platform`]??hn.platform,n=e?.userActions??{};return{create:n.create??t.create,import:n.import??t.import,edit:n.edit??t.edit,delete:n.delete??t.delete,exportCsv:n.exportCsv??t.exportCsv}}var _n=new Set([`record:discussion`,`record:chatter`]);function vn(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 yn({state:e,onOpenChange:t}){let{t:n}=S(),r=()=>{e.resolve?.(!0),t(!1)},i=()=>{e.resolve?.(!1),t(!1)};return(0,U.jsx)(P,{open:e.open,onOpenChange:e=>{e||i()},children:(0,U.jsxs)(Ie,{children:[(0,U.jsxs)(Le,{children:[(0,U.jsx)(R,{children:e.options?.title||n(`actionConfirm.title`)}),(0,U.jsx)(qe,{children:e.message})]}),(0,U.jsxs)(Ye,{children:[(0,U.jsx)(ze,{onClick:i,children:e.options?.cancelText||n(`actionConfirm.cancel`)}),(0,U.jsx)(Be,{onClick:r,children:e.options?.confirmText||n(`actionConfirm.confirm`)})]})]})})}function bn(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 xn({state:e,onOpenChange:t}){let{t:n,language:r}=S(),[i,a]=(0,H.useState)({}),[o,s]=(0,H.useState)({}),c=re(),l=(0,H.useMemo)(()=>bn(e.params,c),[e.params,c]);(0,H.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,U.jsx)(E,{open:e.open,onOpenChange:e=>{e||f()},children:(0,U.jsxs)(ve,{children:[(0,U.jsxs)(Ne,{children:[(0,U.jsx)(A,{children:e.title||n(`actionDialog.title`)}),(0,U.jsx)(Ue,{children:e.description||n(`actionDialog.description`)})]}),(0,U.jsx)(`div`,{className:`grid gap-4 py-4`,children:l.map(e=>{let t={...e,label:be(e.label,r),helpText:e.helpText==null?e.helpText:be(e.helpText,r),options:e.options?.map(e=>({...e,label:be(e.label,r)}))};if(t.type===`boolean`||t.type===`checkbox`){let e=i[t.name]===!0;return(0,U.jsxs)(`div`,{className:`grid gap-1`,children:[(0,U.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,U.jsx)(Re,{id:t.name,checked:e,onCheckedChange:e=>p(t.name,e===!0),className:`mt-0.5`}),(0,U.jsxs)(F,{htmlFor:t.name,className:`font-normal cursor-pointer`,children:[t.label,t.required&&(0,U.jsx)(`span`,{className:`text-destructive ml-1`,children:`*`})]})]}),o[t.name]&&(0,U.jsx)(`p`,{className:`text-xs text-destructive ml-6`,children:n(`actionDialog.requiredError`,{label:t.label})}),t.helpText&&(0,U.jsx)(`p`,{className:`text-xs text-muted-foreground ml-6`,children:t.helpText})]},t.name)}let a=t.type===`lookup`||t.type===`reference`;return(0,U.jsxs)(`div`,{className:`grid gap-2`,children:[(0,U.jsxs)(F,{htmlFor:t.name,children:[t.label,t.required&&(0,U.jsx)(`span`,{className:`text-destructive ml-1`,children:`*`})]}),t.type===`select`&&t.options?(0,U.jsxs)(ge,{value:i[t.name]??``,onValueChange:e=>p(t.name,e),children:[(0,U.jsx)(Fe,{id:t.name,className:o[t.name]?`border-destructive`:``,children:(0,U.jsx)(Ee,{placeholder:t.placeholder||n(`actionDialog.selectPlaceholder`,{label:t.label})})}),(0,U.jsx)(M,{children:t.options.map(e=>(0,U.jsx)(j,{value:e.value,children:e.label},e.value))})]}):a&&t.referenceTo?(0,U.jsx)(ce,{value:i[t.name]??null,onChange:e=>p(t.name,e),field:{name:t.name,type:`lookup`,reference_to:t.referenceTo,display_field:t.displayField,id_field:t.idField,description_field:t.descriptionField,multiple:t.multiple,title_format:t.titleFormat,lookup_columns:t.lookupColumns,lookup_filters:t.lookupFilters,lookup_page_size:t.lookupPageSize,depends_on:t.dependsOn,placeholder:t.placeholder}}):t.type===`textarea`?(0,U.jsx)(Ve,{id:t.name,value:i[t.name]??``,onChange:e=>p(t.name,e.target.value),placeholder:t.placeholder,className:o[t.name]?`border-destructive`:``}):t.type===`number`?(0,U.jsx)(N,{id:t.name,type:`number`,value:i[t.name]??``,onChange:e=>p(t.name,e.target.value===``?void 0:e.target.valueAsNumber),placeholder:t.placeholder,className:o[t.name]?`border-destructive`:``}):(0,U.jsx)(N,{id:t.name,type:[`email`,`url`,`date`,`datetime-local`,`time`,`password`].includes(t.type)?t.type:`text`,value:i[t.name]??``,onChange:e=>p(t.name,e.target.value),placeholder:t.placeholder||(a?n(`actionDialog.lookupPlaceholder`,{label:t.label}):void 0),className:o[t.name]?`border-destructive`:``}),o[t.name]&&(0,U.jsx)(`p`,{className:`text-xs text-destructive`,children:n(`actionDialog.requiredError`,{label:t.label})}),t.helpText&&(0,U.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:t.helpText}),a&&!t.helpText&&(0,U.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`actionDialog.lookupHelpText`)})]},t.name)})}),(0,U.jsxs)(me,{children:[(0,U.jsx)(T,{variant:`outline`,onClick:f,children:n(`actionDialog.cancel`)}),(0,U.jsx)(T,{onClick:d,children:n(`actionDialog.confirm`)})]})]})})}function Sn(e,t){if(e!=null)return t.split(`.`).reduce((e,t)=>{if(e!=null)return e[t]},e)}function Cn({state:e,onAcknowledge:t}){let{t:n}=S(),{spec:r,data:i}=e,a=(0,H.useMemo)(()=>r?.fields&&r.fields.length>0?r.fields:[{path:``,label:void 0,format:r?.format??`json`}],[r]);return(0,U.jsx)(E,{open:e.open,onOpenChange:e=>{},children:(0,U.jsxs)(ve,{onPointerDownOutside:e=>e.preventDefault(),onEscapeKeyDown:e=>e.preventDefault(),className:`max-w-lg`,children:[(0,U.jsxs)(Ne,{children:[(0,U.jsx)(A,{children:r?.title||n(`actions.resultDialog.defaultTitle`)||`Save this value now`}),r?.description?(0,U.jsx)(Ue,{children:r.description}):null]}),(0,U.jsx)(`div`,{className:`space-y-4 py-2`,children:a.map((e,t)=>(0,U.jsx)(wn,{field:e,value:e.path===``?i:Sn(i,e.path),defaultFormat:r?.format},`${e.path}-${t}`))}),(0,U.jsx)(me,{children:(0,U.jsx)(T,{onClick:t,children:r?.acknowledge||n(`actions.resultDialog.acknowledge`)||`I have saved this`})})]})})}function wn({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,U.jsxs)(`div`,{className:`space-y-1.5`,children:[i?(0,U.jsx)(`div`,{className:`text-sm font-medium text-foreground/80`,children:i}):null,a===`qrcode`?(0,U.jsx)(Dn,{value:t}):null,a===`code-list`?(0,U.jsx)(On,{value:t}):null,a===`secret`?(0,U.jsx)(kn,{value:t}):null,a===`text`?(0,U.jsx)(An,{value:t}):null,a===`json`?(0,U.jsx)(jn,{value:t}):null]})}function Tn(e){let[t,n]=(0,H.useState)(!1);return(0,H.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 En({value:e,label:t}){let{copy:n,copied:r}=Tn(e);return(0,U.jsxs)(T,{type:`button`,variant:`outline`,size:`sm`,onClick:n,children:[r?(0,U.jsx)(fe,{className:`w-4 h-4`}):(0,U.jsx)(L,{className:`w-4 h-4`}),t?(0,U.jsx)(`span`,{className:`ml-2`,children:t}):null]})}function Dn({value:e}){let[t,n]=(0,H.useState)(null);return(0,U.jsxs)(`div`,{className:`space-y-2`,children:[(0,U.jsx)(`div`,{className:`flex justify-center rounded-md border bg-white p-3`,children:t?(0,U.jsx)(`span`,{className:`text-sm text-destructive`,children:t}):(0,U.jsx)(`canvas`,{ref:t=>{!t||!e||(0,$t.toCanvas)(t,e,{width:200,margin:1},e=>{e&&n(e.message)})}})}),(0,U.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,U.jsx)(`code`,{className:`flex-1 truncate rounded bg-muted px-2 py-1 text-xs font-mono`,children:e}),(0,U.jsx)(En,{value:e})]})]})}function On({value:e}){let t=e.join(`
2
2
  `);return(0,U.jsxs)(`div`,{className:`space-y-2`,children:[(0,U.jsx)(`div`,{className:`rounded-md border bg-muted/40 p-2`,children:(0,U.jsx)(`ul`,{className:`space-y-1`,children:e.map((e,t)=>(0,U.jsxs)(`li`,{className:`flex items-center gap-2`,children:[(0,U.jsx)(`code`,{className:`flex-1 rounded bg-background px-2 py-1 text-sm font-mono`,children:e}),(0,U.jsx)(En,{value:e})]},`${t}-${e}`))})}),(0,U.jsx)(`div`,{className:`flex justify-end`,children:(0,U.jsx)(En,{value:t,label:`Copy all`})})]})}function kn({value:e}){let[t,n]=(0,H.useState)(!1);return(0,U.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,U.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,U.jsx)(T,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>n(e=>!e),children:t?(0,U.jsx)(he,{className:`w-4 h-4`}):(0,U.jsx)(I,{className:`w-4 h-4`})}),(0,U.jsx)(En,{value:e})]})}function An({value:e}){return(0,U.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,U.jsx)(`code`,{className:`flex-1 rounded bg-muted px-2 py-1 text-sm font-mono break-all`,children:e}),(0,U.jsx)(En,{value:e})]})}function jn({value:e}){let t=(0,H.useMemo)(()=>{try{return JSON.stringify(e,null,2)}catch{return String(e)}},[e]);return(0,U.jsxs)(`div`,{className:`space-y-2`,children:[(0,U.jsx)(`pre`,{className:`max-h-80 overflow-auto rounded-md border bg-muted/40 p-3 text-xs font-mono`,children:t}),(0,U.jsx)(`div`,{className:`flex justify-end`,children:(0,U.jsx)(En,{value:t})})]})}function Mn(e){return e.kind===`object-form`&&!!e.objectName}function Nn(e){let t={};for(let n of e.fields)n.defaultValue!==void 0&&(t[n.name]=n.defaultValue);return t}function Pn({screen:e,values:t,onValueChange:n,dataSource:r,objects:i,objectForm:a,className:o}){if(Mn(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,U.jsx)(`div`,{className:k(`py-2`,o),children:r?(0,U.jsx)(B,{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,U.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,U.jsx)(`div`,{className:k(`space-y-4 py-2`,o),children:e.fields.map(e=>(0,U.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,U.jsxs)(F,{htmlFor:`ff-${e.name}`,className:`text-sm`,children:[e.label||e.name,e.required&&(0,U.jsx)(`span`,{className:`text-destructive`,children:` *`})]}),(0,U.jsx)(Fn,{field:e,value:t[e.name],onChange:t=>n(e.name,t)})]},e.name))})}function Fn({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,U.jsxs)(ge,{value:t==null?void 0:String(t),onValueChange:e=>n(e),children:[(0,U.jsx)(Fe,{id:r,children:(0,U.jsx)(Ee,{placeholder:e.placeholder||`Select…`})}),(0,U.jsx)(M,{children:e.options.map((e,t)=>(0,U.jsx)(j,{value:String(e.value),children:e.label},t))})]});if(i===`boolean`||i===`checkbox`)return(0,U.jsx)(Re,{id:r,checked:t===!0,onCheckedChange:e=>n(e===!0)});if(i===`textarea`||i===`markdown`)return(0,U.jsx)(Ve,{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,U.jsx)(N,{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 In({state:e,authFetch:t,baseUrl:n,onClose:r,onComplete:i,dataSource:a,objects:o}){let[s,c]=(0,H.useState)(null),[l,u]=(0,H.useState)(``),[d,f]=(0,H.useState)(``),[p,m]=(0,H.useState)({}),[h,g]=(0,H.useState)(!1);if((0,H.useEffect)(()=>{e&&(c(e.screen),u(e.runId),f(e.flowName),m(Nn(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){z.error(o?.error||`Resume failed (HTTP ${a.status})`);return}let s=o?.data??{};if(s.success===!1||s.status===`failed`){z.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(Nn(s.screen)),z.success(`Saved — next step`)):(z.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){z.error(`Please fill: ${e.map(e=>e.label||e.name).join(`, `)}`);return}g(!0);try{await v(p)}catch(e){z.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){z.error(e.message)}finally{g(!1)}},x=Mn(s);return(0,U.jsx)(E,{open:!0,onOpenChange:e=>{!e&&!h&&r()},children:(0,U.jsxs)(ve,{className:x?`sm:max-w-3xl max-h-[90vh] overflow-y-auto`:`sm:max-w-md`,children:[(0,U.jsxs)(Ne,{children:[(0,U.jsx)(A,{children:s.title||`Input`}),s.description&&(0,U.jsx)(Ue,{children:s.description})]}),(0,U.jsx)(Pn,{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,U.jsxs)(me,{children:[(0,U.jsx)(T,{variant:`outline`,onClick:r,disabled:h,children:`Cancel`}),(0,U.jsx)(T,{onClick:y,disabled:h,children:h?`Submitting…`:`Submit`})]})]})})}function Ln(e){ne({objectName:e})}function Rn(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 zn({appName:e,objects:t,dataSource:n,actionLabel:r,parentObjectName:o,parentRecordId:s,parentTitle:c,children:l}){let u=i(),{execute:d}=v(),[,f]=a(),p=e?`/apps/${e}`:``,m=(0,H.useCallback)(e=>{let t=new URLSearchParams(window.location.search);t.set(tn,e.recordId??`new`),t.set(nn,e.objectName),e.link?t.set(rn,`${e.link.field}:${e.link.parentId}`):t.delete(rn),f(t)},[f]),h=(0,H.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&&Ln(e)},[d]);return(0,U.jsx)(oe,{value:(0,H.useMemo)(()=>({resolve:({objectName:e,relationshipField:i,parentId:a})=>{let l=t.find(t=>t?.name===e);if(!l||!p)return{};let d=gn(l),f=t=>{let n=`${p}/${e}/record/${encodeURIComponent(String(t))}`;if(o&&s){let e=un(new URLSearchParams(window.location.search).get($),{o,i:s,...c?{t:c}:{}}),t=new URLSearchParams;return t.set($,e),`${n}?${t.toString()}`}return n},g={onView:e=>u(f(e))};d.create&&(g.onCreate=()=>{m({objectName:e,link:i&&a!=null&&a!==``?{field:i,parentId:a}: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 _=Rn(l,r,`list_item`);_.length>0&&(g.rowActions=_,g.onRowAction=(t,n)=>h(e,n,t));let v=Rn(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,o,s,c]),children:l})}var Bn=[`regions`,`components`,`children`];function Vn(e,t){if(Array.isArray(e)){let n=null;return e.forEach((r,i)=>{let a=Vn(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 Bn){let i=(r??n)[e];if(i==null)continue;let a=Vn(i,t);a!==i&&(r??={...n},r[e]=a)}return r??e}function Hn(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 Un(e){if(typeof e==`string`)return e||void 0;if(e&&typeof e==`object`&&typeof e.source==`string`)return e.source||void 0}function Wn(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:Un(e.visible)};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:Un(e.visible)};let o=e.type??a.type??`text`,s=e.options??Hn(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,multiple:a.multiple,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:Un(e.visible),...l}}function Gn(e,t){return Array.isArray(e)?e.map(e=>Wn(e,t)):[]}function Kn(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 qn=({objectName:e,recordId:t,dataSource:n,currentUserId:r,className:i})=>{let{t:a}=S(),[o,s]=H.useState([]),[c,l]=H.useState(!1),[u,d]=H.useState(!1),[f,p]=H.useState(null),m=H.useRef(null),h=H.useMemo(()=>w({baseUrl:``,scope:`attachments`}),[``]),g=H.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]);H.useEffect(()=>{g()},[g]);let _=H.useCallback(async i=>{if(!(!i||i.length===0||!n)){d(!0),p(null);try{for(let a of Array.from(i)){let i=await h.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 g()}catch(e){p(String(e?.message??e))}finally{d(!1),m.current&&(m.current.value=``)}}},[h,n,e,t,r,g]),v=H.useCallback(async e=>{if(n){p(null);try{await n.delete(`sys_attachment`,e.id),s(t=>t.filter(t=>t.id!==e.id))}catch(e){p(String(e?.message??e))}}},[n]);return(0,U.jsxs)(`div`,{className:k(`rounded-lg border bg-card`,i),"data-testid":`record-attachments-panel`,children:[(0,U.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b`,children:[(0,U.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium`,children:[(0,U.jsx)(Ge,{className:`h-4 w-4 text-muted-foreground`}),(0,U.jsx)(`span`,{children:a(`detail.attachments`,{defaultValue:`Attachments`})}),o.length>0&&(0,U.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`(`,o.length,`)`]})]}),(0,U.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,U.jsx)(`input`,{ref:m,type:`file`,multiple:!0,className:`hidden`,onChange:e=>void _(e.target.files)}),(0,U.jsxs)(T,{variant:`outline`,size:`sm`,disabled:u,onClick:()=>m.current?.click(),children:[u?(0,U.jsx)(D,{className:`h-4 w-4 mr-1 animate-spin`}):(0,U.jsx)(O,{className:`h-4 w-4 mr-1`}),a(`detail.uploadAttachment`,{defaultValue:`Upload`})]})]})]}),f&&(0,U.jsx)(`div`,{className:`px-4 py-2 text-xs text-destructive border-b`,role:`alert`,children:f}),c&&o.length===0?(0,U.jsxs)(`div`,{className:`px-4 py-6 text-sm text-muted-foreground flex items-center gap-2`,children:[(0,U.jsx)(D,{className:`h-4 w-4 animate-spin`}),a(`detail.loadingAttachments`,{defaultValue:`Loading attachments…`})]}):o.length===0?(0,U.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,U.jsx)(`ul`,{className:`divide-y`,children:o.map(e=>(0,U.jsxs)(`li`,{className:`flex items-center gap-3 px-4 py-2.5`,children:[(0,U.jsx)(Ge,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,U.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,U.jsx)(`div`,{className:`truncate text-sm`,children:e.file_name||e.file_id}),(0,U.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:[Kn(e.size),e.mime_type||void 0].filter(Boolean).join(` · `)})]}),(0,U.jsx)(`a`,{href:`/api/v1/storage/files/${encodeURIComponent(e.file_id)}`,target:`_blank`,rel:`noreferrer`,className:`inline-flex`,"aria-label":a(`detail.downloadAttachment`,{defaultValue:`Download`}),children:(0,U.jsx)(T,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,children:(0,U.jsx)(C,{className:`h-4 w-4`})})}),(0,U.jsx)(T,{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 v(e),children:(0,U.jsx)(Pe,{className:`h-4 w-4`})})]},e.id))})]})};function Jn(){let e=H.useMemo(()=>it().toLowerCase().startsWith(`zh`),[]);return H.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 Yn=e=>Array.isArray(e)?e:e?.records??e?.items??e?.data??[],Xn=e=>e?.full_name||e?.name||e?.display_name||e?.email||String(e?.id??``);function Zn({permissionSetName:e}){let t=m(),n=Jn(),[r,i]=H.useState(null),[a,o]=H.useState([]),[s,c]=H.useState(!1),[l,u]=H.useState(!0),[d,f]=H.useState(!1),[p,h]=H.useState(!1),[g,_]=H.useState(null),v=H.useCallback(async()=>{u(!0);try{let n=Yn(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=Yn(await t.find(`sys_user_permission_set`,{$filter:{permission_set_id:r},$top:500})),s=[],l=!1;try{let e=Yn(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=Yn(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?Yn(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?Yn(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?Xn(t):e,email:t?.email??``,via:d.get(e)??[]}})),c(l)}catch{o([]),c(!1)}finally{u(!1)}},[t,e]);H.useEffect(()=>{v()},[v]);let y=H.useMemo(()=>new Set(a.map(e=>e.userId)),[a]),b=H.useCallback(async e=>{if(r){h(!0),_(null);try{for(let n of e||[]){let e=n?.id==null?null:String(n.id);!e||y.has(e)||await t.create(`sys_user_permission_set`,{permission_set_id:r,user_id:e})}await v()}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))_(n.seatFull(r?Number(r[2]):a.length));else{let e=t.replace(/^\s*\[[^\]]*\]\s*/,``).trim();_(e||n.addFailed)}}finally{h(!1),f(!1)}}},[t,r,y,v,a.length,n]),x=H.useCallback(async e=>{_(null);try{await t.delete(`sys_user_permission_set`,e),await v()}catch{}},[t,v]);return(0,U.jsxs)(`div`,{className:`px-4 py-4`,children:[(0,U.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,U.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium`,children:[(0,U.jsx)(De,{className:`h-4 w-4 text-muted-foreground`}),(0,U.jsx)(`span`,{children:n.title}),!l&&(0,U.jsx)(`span`,{className:`text-xs text-muted-foreground font-normal`,children:n.countOf(a.length)})]}),(0,U.jsxs)(T,{variant:`outline`,size:`sm`,disabled:p||!r,onClick:()=>{_(null),f(!0)},className:`gap-1 h-8 text-xs`,children:[p?(0,U.jsx)(D,{className:`h-3.5 w-3.5 animate-spin`}):(0,U.jsx)(Te,{className:`h-3.5 w-3.5`}),n.add]})]}),g&&(0,U.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,U.jsx)(xe,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,U.jsx)(`span`,{children:g})]}),s&&(0,U.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,U.jsx)(De,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,U.jsx)(`span`,{children:n.everyoneNote})]}),l?(0,U.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground py-3`,children:[(0,U.jsx)(D,{className:`h-3.5 w-3.5 animate-spin`}),n.loading]}):a.length===0?!s&&(0,U.jsx)(`div`,{className:`text-xs text-muted-foreground italic py-3`,children:n.empty}):(0,U.jsx)(`ul`,{className:`divide-y rounded-md border`,children:a.map(e=>(0,U.jsxs)(`li`,{className:`flex items-center gap-3 px-3 py-2`,children:[(0,U.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,U.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,U.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,U.jsx)(`span`,{className:`text-sm truncate`,children:e.name}),e.via.map((e,t)=>(0,U.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,U.jsx)(`div`,{className:`text-xs text-muted-foreground truncate`,children:e.email})]}),e.grantId?(0,U.jsx)(T,{variant:`ghost`,size:`sm`,onClick:()=>void x(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,U.jsx)(se,{className:`h-4 w-4`})}):(0,U.jsx)(`span`,{className:`shrink-0 text-[10px] text-muted-foreground/70`,title:n.positionHeldHint,children:`—`})]},e.userId))}),r&&(0,U.jsx)(Se,{open:d,onOpenChange:e=>f(e),multiple:!0,dataSource:t,objectName:`sys_user`,title:n.pickTitle,onSelect:()=>{},onSelectRecords:e=>void b(e)})]})}function Qn(){let e=h()?.data?.name;return!e||typeof e!=`string`?null:(0,U.jsx)(Ke,{className:`overflow-hidden`,children:(0,U.jsx)(Zn,{permissionSetName:e})})}var $n=t({RecordDetailView:()=>or}),er={id:`current-user`,name:`Demo User`},tr=new Set([`created_at`,`created_by`,`updated_at`,`updated_by`]),nr=new Set([`organization_id`,`tenant_id`,`is_deleted`,`deleted_at`]),rr=[`description`,`notes`,`note`,`remark`,`remarks`,`comments`],ir=new Set([`textarea`,`markdown`,`html`,`rich-text`,`json`,`code`]);function ar(e,t){if(ir.has(t?.type))return!0;let n=e.toLowerCase();return rr.some(e=>n===e||n.endsWith(`_${e}`))}function or({dataSource:e,objects:t,onEdit:s,objectNameOverride:c,recordIdOverride:m,embedded:h}){let _=o(),v=_.appName,y=c??_.objectName,re=m??_.recordId,{showDebug:oe}=nt(),{user:C,activeOrganization:se}=u(),w=i(),[T,ce]=a(),le=T.get(`tab`)??void 0,ue=(0,H.useCallback)(e=>{let t=new URLSearchParams(window.location.search);t.get(`tab`)!==e&&(t.set(`tab`,e),ce(t,{replace:!0}))},[ce]),E=r(),de=E.state?.from,D=(0,H.useMemo)(()=>{if(de?.pathname&&de?.label)return de;let e=cn(new URLSearchParams(E.search).get($)),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:dn(n,t,e.slice(0,-1)),label:t.t||`#${r}`}},[de,E.search,v]),{t:O}=S(),{objectLabel:fe,viewLabel:pe,sectionLabel:me,actionLabel:he,actionConfirm:ge,actionSuccess:ve,actionParamText:ye,actionParamOptionLabel:be,actionDescription:xe,fieldLabel:Se,fieldOptionLabel:k}=we(),{isFavorite:Ce,toggleFavorite:Te,refreshLabel:Ee}=It(),{addRecentItem:De}=yt(),[Oe,ke]=(0,H.useState)(!0),[je,A]=(0,H.useState)([]),[j,Ne]=(0,H.useState)([]),[Pe,M]=(0,H.useState)(null),[Fe,Ie]=(0,H.useState)({}),[Le,Re]=(0,H.useState)(null),[ze,Be]=(0,H.useState)(!1),[N,Ve]=(0,H.useState)(),P=t.find(e=>e.name===y);kt(h?void 0:N);let F=re,Ue=ee(y||void 0,F||void 0),I=(0,H.useCallback)(()=>{y&&ne({objectName:y,recordId:F||void 0})},[y,F]),Ge=Qt(y,F),L=(0,H.useMemo)(()=>!y||!F?null:{id:`record:${y}:${F}`,label:N||F||``,href:`/apps/${v}/${y}/record/${F}`,type:`record`},[v,y,F,N]),Ke=L?Ce(L.id):!1,qe=(0,H.useCallback)(()=>{L&&Te(L)},[L,Te]),{page:Je,slots:R}=ae(y),Ye=(0,H.useMemo)(()=>{if(typeof window<`u`)try{let e=new URLSearchParams(window.location.search).get(`renderViaSchema`);if(e===`0`||e===`false`)return!1;if(e===`1`||e===`true`)return!0}catch{}return P?.detail?.renderViaSchema!==!1},[P]),Xe=(0,H.useMemo)(()=>Je||!P||!Ye&&!R?null:$e(P,R?{slots:R}:void 0),[Ye,Je,R,P]),B=Je||Xe,[V,it]=(0,H.useState)(null),[st,W]=(0,H.useState)(`idle`);(0,H.useEffect)(()=>{let t=!1;if(!B||!F||!y||!e?.findOne){it(null),W(`idle`);return}let n=p(P?.fields),r=n.length>0?{$expand:n}:void 0,i=()=>{W(`loading`),(r?e.findOne(y,F,r):e.findOne(y,F)).then(e=>{t||(e&&typeof e==`object`?(it(e),W(`loaded`)):(it(null),W(`missing`)))}).catch(()=>{t||(it(null),W(`missing`))})};i();let a=e=>{let t=e.detail||{};t.objectName!==y||String(t.recordId)!==String(F)||i()};return window.addEventListener(`objectui:record-changed`,a),()=>{t=!0,window.removeEventListener(`objectui:record-changed`,a)}},[B,y,F,e,P,Ue]),(0,H.useEffect)(()=>{if(!V||typeof V!=`object`||!P)return;let e=ie(P,V);e&&e!==`Untitled`&&e!==N&&Ve(e)},[V,P,N]),(0,H.useEffect)(()=>{if(!y||!F||!v||!N)return;let e=`record:${y}:${F}`,t=`/apps/${v}/${y}/record/${F}`;De({id:e,label:N,href:t,type:`record`}),Ee(e,N)},[v,y,F,N,De,Ee]);let[ct,lt]=(0,H.useState)({open:!1,message:``}),[ut,G]=(0,H.useState)({open:!1,params:[]}),[dt,ft]=(0,H.useState)({open:!1}),pt=(0,H.useCallback)((e,t)=>new Promise(n=>{ft({open:!0,spec:e,data:t,resolve:n})}),[]),mt=(0,H.useCallback)((e,t)=>new Promise(n=>{lt({open:!0,message:e,options:t,resolve:n})}),[]),ht=(0,H.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=Gn(e,{objectName:i||y||P?.name||``,objects:t||[],fieldLabel:Se,fieldOptionLabel:k,row:a}),s=i||y||P?.name,c=o.map(e=>({...e,label:ye(s,n?.name,e.name,`label`,e.label)??e.label,placeholder:ye(s,n?.name,e.name,`placeholder`,e.placeholder)??e.placeholder,helpText:ye(s,n?.name,e.name,`helpText`,e.helpText)??e.helpText,options:Array.isArray(e.options)?e.options.map(t=>({...t,label:be(s,n?.name,e.name,t.value,t.label)})):e.options}));G({open:!0,params:c,title:n?.label||n?.title,description:xe(s,n?.name,n?.description),resolve:r})}),[y,P,t,Se,k,ye,be]),gt=x({dataSource:e,onUndo:e=>{e?.objectName?ne({objectName:e.objectName,recordId:e.recordId}):I(),z.success(`Change undone`)}}),_t=(0,H.useCallback)((e,t)=>{if(t?.type===`error`){z.error(e);return}if(t?.undo){z.success(e,{duration:t.duration,action:{label:t.undo.label||`Undo`,onClick:()=>{gt.undo()}}});return}z.success(e,{duration:t?.duration})},[gt]),vt=(0,H.useCallback)((e,t)=>{t?.external||t?.newTab?window.open(e,`_blank`,`noopener,noreferrer`):w(e)},[w]),K=(0,H.useMemo)(()=>l(),[]),bt=(0,H.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?V?.[e]:void 0);n!=null&&(s[t.recordIdParam]=n)}/\/api\/v1\/auth\//.test(e)&&!s.organizationId&&se?.id&&(s.organizationId=se.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,F,{stage:i.new_stage});break;case`opportunity_mark_won`:await e.update(y,F,{stage:`closed_won`});break;case`opportunity_mark_lost`:await e.update(y,F,{stage:`closed_lost`,loss_reason:i.loss_reason});break;default:{let n=t.objectName??y,r=t.recordId??F,a=n===y&&String(r)===String(F);if(Object.keys(i).length>0&&n&&r!=null){if(t.undoable&&a&&V){let e={};for(let t of Object.keys(i))e[t]=V[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,F,V,K,se]),{modalHandler:xt,modalElement:St}=Et(e),Ct=(0,H.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??F,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 M({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,F,y]),wt=(0,H.useRef)(new Set),Tt=(0,H.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}:${F??``}`;if(wt.current.has(r))return{success:!1,error:`Action already in progress`};wt.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(F==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(F)))}`;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||z(`浏览器拦截了弹窗 / 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??F,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||z(`浏览器拦截了弹窗 / 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{wt.current.delete(r)}},[K,F,y]),q=mn(y,F,C?.id),Dt=(0,H.useRef)(q);Dt.current=q;let Ot=(0,H.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)}}},[]),J=(0,H.useMemo)(()=>zt(P,t),[P,t]);(0,H.useEffect)(()=>{if(B||!e||!F||J.length===0)return;let t=!1;return Promise.all(J.map(({childObject:t,referenceField:n})=>e.find(t,{$filter:{[n]:F}}).then(e=>({childObject:t,items:Array.isArray(e)?e:e?.data||[]})).catch(e=>(console.warn(`[RecordDetailView] Failed to fetch related ${t}:`,e),{childObject:t,items:[]})))).then(e=>{if(t)return;let n={};for(let{childObject:t,items:r}of e)n[t]=r;Ie(n)}),()=>{t=!0}},[e,F,J,P,B]);let Y=(0,H.useMemo)(()=>!P||P.name===`sys_audit_log`||P.enable?.trackHistory!==!0?!1:t.some(e=>e.name===`sys_audit_log`),[P,t]),X=P?.enable?.feeds!==!1,At=P?.enable?.activities!==!1,jt=P?.enable?.files===!0;(0,H.useEffect)(()=>{if(!e||!F||!P||!Y){Re(null);return}let t=!1;return Be(!0),e.find(`sys_audit_log`,{$filter:{record_id:F,object_name:P.name},$orderby:{created_at:`desc`},$top:50,$select:[`id`,`created_at`,`action`,`user_id`,`old_value`,`new_value`]}).then(async n=>{if(t)return;let r=Array.isArray(n)?n:n?.data||[],i=Array.from(new Set(r.map(e=>e?.user_id).filter(e=>typeof e==`string`&&e.length>0))),a=new Map;if(i.length>0)try{let t=await e.find(`sys_user`,{$filter:{id:{$in:i}},$top:i.length,$select:[`id`,`name`,`email`,`image`]}),n=Array.isArray(t)?t:t?.data||[];a=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 o={};for(let[e,t]of Object.entries(P.fields||{}))t?.label&&(o[e]=t.label);let s=e=>{if(!e)return null;if(typeof e==`object`)return e;if(typeof e==`string`)try{return JSON.parse(e)}catch{return null}return null},c=r.map(e=>{let t=e?.user_id?a.get(e.user_id):void 0,n=s(e?.old_value)||{},r=s(e?.new_value)||{},i=new Set([...Object.keys(n),...Object.keys(r)]),c=Array.from(i).filter(e=>JSON.stringify(n[e])!==JSON.stringify(r[e])).map(e=>({field:e,label:o[e]||e,from:n[e],to:r[e]}));return{...e,user_name:t?.name??null,user_avatar:t?.image??null,changes:c.length>0?c:void 0}});Re(c)}).catch(e=>{t||(console.warn(`[RecordDetailView] Failed to fetch sys_audit_log:`,e),Re([]))}).finally(()=>{t||Be(!1)}),()=>{t=!0}},[e,F,P,Y]),(0,H.useEffect)(()=>{if(!e)return;let t=!1,n=C?[{id:String(C.id),label:C.name||C.email||String(C.id),avatarUrl:C.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))];Ne(o.length>0?o:n)}catch{if(t)return;Ne(n)}})(),()=>{t=!0}},[e,C?.id,C?.name,C?.email]);let Z=(0,H.useMemo)(()=>C?{id:C.id,name:C.name,avatar:C.image}:er,[C?.id,C?.name,C?.image]);(0,H.useEffect)(()=>{if(!e||!y||!F)return;let t=`${y}:${F}`,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(Z.id)}))};X&&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??O(`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)}));A(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};At&&e.find(`sys_activity`,{$filter:{object_name:y,record_id:F},$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??O(`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&&A(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,F,Z,X,At]);let Mt=(0,H.useCallback)(async t=>{let n={id:crypto.randomUUID(),type:`comment`,actor:Z.name,actorAvatarUrl:`avatar`in Z?Z.avatar:void 0,body:t,createdAt:new Date().toISOString()};if(A(e=>[...e,n]),e){let r=`${y}:${F}`,i=Qe(t,j);e.create(`sys_comment`,{id:n.id,thread_id:r,author_id:Z.id,author_name:Z.name,author_avatar_url:`avatar`in Z?Z.avatar:void 0,body:t,mentions:JSON.stringify(i),created_at:n.createdAt}).catch(()=>{})}},[Z,e,y,F,j]),Nt=(0,H.useCallback)(async(t,n)=>{let r={id:crypto.randomUUID(),type:`comment`,actor:Z.name,actorAvatarUrl:`avatar`in Z?Z.avatar:void 0,body:n,createdAt:new Date().toISOString(),parentId:t};if(A(e=>[...e,r].map(e=>e.id===t?{...e,replyCount:(e.replyCount??0)+1}:e)),e){let i=`${y}:${F}`,a=Qe(n,j);e.create(`sys_comment`,{id:r.id,thread_id:i,author_id:Z.id,author_name:Z.name,author_avatar_url:`avatar`in Z?Z.avatar:void 0,body:n,mentions:JSON.stringify(a),created_at:r.createdAt,parent_id:t}).catch(()=>{})}},[Z,e,y,F,j]),Pt=(0,H.useCallback)((t,n)=>{A(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=Z.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}))},[Z.id,e]);(0,H.useEffect)(()=>{ke(!0),queueMicrotask(()=>ke(!1))},[y,re]);let Q=(0,H.useMemo)(()=>{if(!P)return{type:`detail-view`};let n=P.primaryField||P.nameField||P.displayNameField||Object.keys(P.fields||{}).find(e=>e===`name`||e===`title`),r=(()=>{let e=e=>{let t=P.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=>!ar(e,P.fields[e])),r=t.filter(e=>ar(e,P.fields[e]));return r.length===0||n.length===0?[{showBorder:!1,fields:t.map(e)}]:[{showBorder:!1,fields:n.map(e)},{name:`details`,title:me(P.name,`details`,O(`detail.sectionMoreDetails`,`More details`)),collapsible:!0,defaultCollapsed:!1,showBorder:!0,fields:r.map(e)}]},n=et(P);return n?n.flatMap(e=>e.name?[{...e,title:me(P.name,e.name,e.title),showBorder:!0}]:t(e.fields.map(e=>e.name))):t(Object.keys(P.fields||{}).filter(e=>!tr.has(e)&&!nr.has(e)&&!P.fields[e]?.hidden))})(),i=(()=>{let e=new Set,t=(P.actions||[]).filter(t=>t.locations?.includes(`record_header`)?t.name?e.has(t.name)?!1:(e.add(t.name),!0):!0:!1).map(e=>({...e,label:he(P.name,e.name,e.label||e.name),...e.confirmText!==void 0&&{confirmText:ge(P.name,e.name,e.confirmText)},...e.successMessage!==void 0&&{successMessage:ve(P.name,e.name,e.successMessage)}}));if(q.available&&q.canDecide){let e={name:`comment`,label:O(`approvals.comment`,{defaultValue:`Comment (optional)`}),type:`text`,multiline:!0};t.push({name:`approve_request`,type:`approval`,target:`approve_request`,label:O(`approvals.approve`,{defaultValue:`Approve`}),icon:`check`,variant:`primary`,order:-100,locations:[`record_header`],refreshAfter:!0,collectParams:[e],successMessage:O(`approvals.approveSuccess`,{defaultValue:`Approved`})}),t.push({name:`reject_request`,type:`approval`,target:`reject_request`,label:O(`approvals.reject`,{defaultValue:`Reject`}),icon:`x`,variant:`destructive`,order:-99,locations:[`record_header`],refreshAfter:!0,confirmText:O(`approvals.rejectConfirm`,{defaultValue:`Reject this approval request?`}),collectParams:[e],successMessage:O(`approvals.rejectSuccess`,{defaultValue:`Rejected`})})}return t})(),a=P.highlightFields??[],o=(Array.isArray(a)?a:[]).map(e=>{let t=typeof e==`string`?e:e?.name;if(!t)return null;let n=P.fields?.[t];return{name:t,label:n?.label||t,...n?.type?{type:n.type}:{}}}).filter(e=>!!e),s=v?`/apps/${v}`:``,c=J.map(({childObject:n,childLabel:r,referenceField:i,title:a,columns:o})=>{let c=t.find(e=>e.name===n),l=F||``,u=a||(c?fe({name:c.name,label:c.label||r}):r),d=()=>{let e=new URLSearchParams({[i]:l}).toString();return`${s}/${n}/new${e?`?${e}`:``}`},f=()=>{let e=new URLSearchParams({[`filter[${i}]`]:l}).toString();return`${s}/${n}${e?`?${e}`:``}`},p=e=>{let t=e?.id||e?._id;return t?`${s}/${n}/record/${encodeURIComponent(String(t))}/edit`:null},m=e=>{let t=e?.id||e?._id;if(!t)return null;let r=`${s}/${n}/record/${encodeURIComponent(String(t))}`;if(y&&F){let e=un(new URLSearchParams(window.location.search).get($),{o:y,i:F,...N?{t:N}:{}}),t=new URLSearchParams;return t.set($,e),`${r}?${t.toString()}`}return r},h=s?()=>w(d()):void 0,g=s?()=>w(f()):void 0,_=s?e=>{let t=m(e);t&&w(t)}:void 0,v=s?e=>{let t=p(e);t&&w(t)}:void 0,b=e&&l?async t=>{let r=t?.id||t?._id;if(r)try{await e.delete(n,r),z.success(O(`detail.deleteSuccess`,{defaultValue:`Deleted`})),Ie(e=>({...e,[n]:(e[n]||[]).filter(e=>(e.id||e._id)!==r)}))}catch(e){z.error(e?.message||O(`detail.deleteError`,{defaultValue:`Delete failed`}))}}:void 0;return{title:u,type:`table`,api:n,data:Fe[n]||[],referenceField:i,...Array.isArray(o)&&o.length>0?{columns:o}:{},icon:c?.icon,displayField:c?.nameField||c?.displayNameField||(Array.isArray(c?.highlightFields)?c.highlightFields[0]:void 0),onNew:h,onViewAll:g,onRowClick:_,onRowEdit:v,onRowDelete:b}}),l=gn(P);return{type:`detail-view`,objectName:P.name,resourceId:F,showBack:!h,onBack:`history`,showEdit:l.edit,title:P.label,primaryField:n,sections:r,autoTabs:!0,defaultTab:le,onTabChange:ue,autoDiscoverRelated:!0,...Y&&{history:{entries:Le??[],loading:ze&&Le===null}},...c.length>0&&{related:c},...o.length>0&&{highlightFields:o},...i.length>0&&{actions:[{type:`action:bar`,location:`record_header`,actions:i}]}}},[P?.name,F,Fe,v,w,e,O,fe,t,Y,Le,ze,q.available,q.canDecide,q.pendingRequest,q.latestRequest,h,le,ue]);if(Oe)return(0,U.jsx)(ot,{});if(!P)return(0,U.jsx)(`div`,{className:`flex h-full items-center justify-center p-4`,children:(0,U.jsxs)(_e,{children:[(0,U.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,U.jsx)(We,{className:`h-6 w-6 text-muted-foreground`})}),(0,U.jsx)(Me,{children:O(`empty.objectNotFound`)}),(0,U.jsx)(He,{children:O(`empty.objectNotFoundDescription`,{name:y})})]})});if(B&&st===`missing`)return(0,U.jsx)(`div`,{className:`flex h-full items-center justify-center p-4`,children:(0,U.jsxs)(_e,{children:[(0,U.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,U.jsx)(We,{className:`h-6 w-6 text-muted-foreground`})}),(0,U.jsx)(Me,{children:O(`empty.recordNotFound`,{defaultValue:`Record not found`})}),(0,U.jsx)(He,{children:O(`empty.recordNotFoundDescription`,{defaultValue:`The record you are looking for does not exist or may have been deleted.`})})]})});if(B){let r=B?.disableDiscussion===!0,i=vn(B),a=!r&&!i&&X,o=(()=>{let e=Q.actions;if(!Array.isArray(e))return[];let t=e.find(e=>Array.isArray(e?.actions))?.actions??e;return Array.isArray(t)?t:[]})(),c=(()=>{let t=gn(P),n=[];return t.edit&&n.push({name:`sys_edit`,label:O(`detail.edit`,{defaultValue:`Edit`}),type:`script`,locations:[`record_header`],variant:`default`,onClick:()=>s({id:F})}),n.push({name:`sys_share`,label:O(`detail.share`,{defaultValue:`Share`}),type:`script`,locations:[`record_header`],variant:`outline`,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),z.success(O(`detail.linkCopied`,{defaultValue:`Link copied`}))}catch(e){z.error(O(`detail.linkCopyFailed`,{defaultValue:`Failed to copy link`})+(e?.message?`: ${e.message}`:``))}}}),t.delete&&n.push({name:`sys_delete`,label:O(`detail.delete`,{defaultValue:`Delete`}),type:`script`,locations:[`record_header`],variant:`destructive`,onClick:async()=>{let t=O(`detail.deleteConfirmation`,{defaultValue:`Are you sure you want to delete this record?`});if(window.confirm(t))try{await e.delete(y,F),z.success(O(`detail.deleted`,{defaultValue:`Record deleted`}));let t=v?`/apps/${v}`:``;w(`${t}/${y}`,{replace:!0})}catch(e){z.error(e?.message||`Delete failed`)}}}),n})(),l=o.length>0?o:void 0,u=Array.isArray(Q.related)?Q.related.filter(e=>e?.api&&e?.referenceField).map(e=>{let t=J.find(t=>t.childObject===e.api&&t.referenceField===e.referenceField);return{title:e.title,objectName:e.api,relationshipField:e.referenceField,...Array.isArray(e.columns)?{columns:e.columns}:{},...typeof e.pageSize==`number`?{limit:e.pageSize}:{},...e.icon?{icon:e.icon}:{},...t?.isPrimary?{isPrimary:!0}:{}}}):void 0,p=Q.history?{entries:Q.history.entries??[],loading:!!Q.history.loading,emptyText:Q.history.emptyText}:void 0,m=Je?B:$e(P,{sections:Q.sections,highlightFields:Array.isArray(Q.highlightFields)?Q.highlightFields.map(e=>typeof e==`string`?e:e?.name).filter(e=>!!e):void 0,headerActions:l,related:u,history:p,...R?{slots:R}:{}});return(0,U.jsxs)(`div`,{className:`h-full bg-background overflow-hidden flex flex-col relative`,children:[(0,U.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,U.jsx)(Yt,{users:Ge,size:`sm`,maxVisible:3,showStatus:!0}),(0,U.jsx)(at,{managedBy:P?.managedBy})]}),(0,U.jsx)(te,{objectName:y,recordId:F,data:V,objectSchema:P,dataSource:e,embedded:h,headerSystemActions:c,isFavorite:Ke,onToggleFavorite:L?qe:void 0,children:(0,U.jsx)(d,{children:(0,U.jsx)(g,{items:je,onAddComment:Mt,onAddReply:Nt,onToggleReaction:Pt,mentionSuggestions:j,children:(0,U.jsxs)(f,{context:{record:V||{},objectName:y,user:Z},onConfirm:mt,onToast:_t,onNavigate:vt,onParamCollection:ht,onResultDialog:pt,onModal:xt,handlers:{api:bt,flow:Ct,script:Tt,approval:Ot},children:[(0,U.jsxs)(`div`,{className:`flex-1 overflow-hidden flex flex-row`,children:[(0,U.jsxs)(`div`,{className:`flex-1 overflow-auto p-3 sm:p-4 lg:p-6 scroll-pb-48`,children:[D?.pathname&&D?.label&&(0,U.jsxs)(n,{to:D.pathname,className:`inline-flex items-center gap-1 mb-3 text-sm text-muted-foreground hover:text-foreground transition-colors`,children:[(0,U.jsx)(Ae,{className:`h-4 w-4`}),(0,U.jsx)(`span`,{children:D.label})]}),(0,U.jsx)(zn,{appName:v,objects:t,dataSource:e,actionLabel:he,parentObjectName:y,parentRecordId:F??void 0,parentTitle:N,children:(0,U.jsx)(b,{schema:Vn(m,{defaultTab:le,onTabChange:ue})})}),y===`sys_permission_set`&&F&&(0,U.jsx)(`div`,{className:`mt-6`,children:(0,U.jsx)(Qn,{})}),jt&&F&&(0,U.jsx)(`div`,{className:`mt-6`,children:(0,U.jsx)(qn,{objectName:y,recordId:F,dataSource:e,currentUserId:Z?.id})}),a&&(0,U.jsx)(`div`,{className:`mt-6`,children:(0,U.jsx)(tt,{config:{position:`bottom`,collapsible:!1,feed:{enableReactions:!0,enableThreading:!0,showCommentInput:!0}},items:je,onAddComment:Mt,onAddReply:Nt,onToggleReaction:Pt,mentionSuggestions:j})})]}),(0,U.jsx)(rt,{open:oe,sections:[{title:`Page Schema`,data:m}]})]}),St]})})})}),(0,U.jsx)(yn,{state:ct,onOpenChange:e=>{e||lt(e=>({...e,open:!1}))}}),(0,U.jsx)(xn,{state:ut,onOpenChange:e=>{e||G(e=>({...e,open:!1}))}}),(0,U.jsx)(Cn,{state:dt,onAcknowledge:()=>{dt.resolve?.(),ft({open:!1})}}),(0,U.jsx)(In,{state:Pe,authFetch:K,baseUrl:``,dataSource:e,objects:t,onClose:()=>M(null),onComplete:()=>{M(null),I()}})]})}return(0,U.jsxs)(`div`,{className:`h-full bg-background overflow-hidden flex flex-col relative`,children:[(0,U.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,U.jsx)(Yt,{users:Ge,size:`sm`,maxVisible:3,showStatus:!0}),(0,U.jsx)(at,{managedBy:P?.managedBy})]}),(0,U.jsxs)(`div`,{className:`flex-1 overflow-hidden flex flex-row`,children:[(0,U.jsx)(`div`,{className:`flex-1 overflow-auto p-3 sm:p-4 lg:p-6 scroll-pb-48`,children:(0,U.jsx)(`div`,{className:`mx-auto w-full max-w-[1400px]`,children:(0,U.jsxs)(f,{context:{record:{},objectName:y,user:Z},onConfirm:mt,onToast:_t,onNavigate:vt,onParamCollection:ht,onResultDialog:pt,onModal:xt,handlers:{api:bt,flow:Ct,script:Tt,approval:Ot},children:[(0,U.jsx)(Ze,{schema:Q,dataSource:e,objectLabel:fe({name:P.name,label:P.label}),isFavorite:Ke,onToggleFavorite:L?qe:void 0,onDataLoaded:e=>{if(!e||typeof e!=`object`)return;let t=ie(P,e);t&&t!==N&&t!==`Untitled`&&Ve(t)},onEdit:()=>{s({id:F})},discussionSlot:X||jt?(0,U.jsxs)(`div`,{className:`space-y-4`,children:[jt&&F&&(0,U.jsx)(qn,{objectName:y,recordId:F,dataSource:e,currentUserId:Z?.id}),X&&(0,U.jsx)(tt,{config:{position:`bottom`,collapsible:!1,feed:{enableReactions:!0,enableThreading:!0,showCommentInput:!0}},items:je,onAddComment:Mt,onAddReply:Nt,onToggleReaction:Pt})]}):void 0}),St]})})}),(0,U.jsx)(rt,{open:oe,sections:[{title:`View Schema`,data:Q}]})]}),(0,U.jsx)(yn,{state:ct,onOpenChange:e=>{e||lt(e=>({...e,open:!1}))}}),(0,U.jsx)(xn,{state:ut,onOpenChange:e=>{e||G(e=>({...e,open:!1}))}}),(0,U.jsx)(Cn,{state:dt,onAcknowledge:()=>{dt.resolve?.(),ft({open:!1})}}),(0,U.jsx)(In,{state:Pe,authFetch:K,baseUrl:``,dataSource:e,objects:t,onClose:()=>M(null),onComplete:()=>{M(null),I()}})]})}export{bt as A,Gt as C,Ot as D,It as E,vt as F,yt as I,ct as L,Ct as M,xt as N,J as O,K as P,ut as R,Yt as S,Ft as T,tn as _,Pn as a,cn as b,Cn as c,gn as d,an as f,nn as g,rn as h,In as i,St as j,Et as k,xn as l,en as m,$n as n,Nn as o,on as p,Gn as r,Mn as s,or as t,yn as u,$ as v,Bt as w,Zt as x,dn as y};
@@ -1 +1 @@
1
- import{o as e,r as t}from"./rolldown-runtime-DAXXjFlN.js";import{a as n,f as r,h as i,m as a,r as o,y as s}from"./vendor-react-BKSb6vFP.js";import{p as c}from"./infrastructure-Bc4DRENl.js";import{L as l,R as u,Wt as d,l as f}from"./framework-DUXRLJaF.js";import{Cr as p,K as m,Pc as h,Sc as g,X as _,q as v,rs as y}from"./ui-components-t1CVb1Ox.js";import{r as b}from"./vendor-ui-utils-D-WJ115h.js";import"./AdapterProvider-BzVT9qYv.js";import{t as x}from"./plugin-form-zDPLpTAc.js";import"./MetadataProvider-Bkb-vkjJ.js";import{n as S,t as C}from"./ExpressionProvider-gKUl8r3a.js";import{t as w}from"./ManagedByBadge-3xVjmTY7.js";import{t as T}from"./skeletons-CnYUdj-X.js";var E=t({RecordFormPage:()=>k}),D=e(s(),1),O=o();function k({mode:e}){let{appName:t,objectName:o,recordId:s}=a(),E=r(),[k]=i(),A=l(),{objects:j,loading:M}=u(),{t:N}=f(),{objectLabel:P}=h(),{user:F,getAuthConfig:I}=c(),[L,R]=(0,D.useState)({});(0,D.useEffect)(()=>{let e=!1;return I().then(t=>{e||R(t?.features??{})}).catch(()=>{}),()=>{e=!0}},[I]);let z=(0,D.useMemo)(()=>{if(e!==`create`)return;let t=[];for(let[e,n]of k.entries())e&&n&&t.push([e,n]);return t.length>0?Object.fromEntries(t):void 0},[e,k.toString()]),B=(0,D.useMemo)(()=>j.find(e=>e.name===o),[j,o]),V=`/apps/${t}`,H=`${V}/${o}`,U=e===`edit`&&s?`${V}/${o}/record/${encodeURIComponent(s)}`:H,W=(0,D.useCallback)(()=>{typeof window<`u`&&window.history.length>1?E(-1):E(U,{replace:!0})},[E,U]),G=B?P(B):o??``,K=e===`create`?N(`form.createTitle`,{object:G,defaultValue:`New ${G}`}):N(`form.editTitle`,{object:G,defaultValue:`Edit ${G}`}),q=(0,D.useCallback)(()=>{b.success(e===`create`?N(`form.createSuccess`,{object:G,defaultValue:`${G} created successfully`}):N(`form.updateSuccess`,{object:G,defaultValue:`${G} updated successfully`})),W()},[e,N,G,W]),J=(0,D.useCallback)(()=>{W()},[W]),Y=(0,D.useMemo)(()=>F?{name:F.name,email:F.email,role:F.role??`user`}:{name:`Anonymous`,email:``,role:`guest`},[F]),X=(0,D.useMemo)(()=>new d({user:Y,app:{name:t},data:{}}),[Y,t]),Z=(0,D.useMemo)(()=>B?.fields?Array.isArray(B.fields)?B.fields.filter(e=>typeof e==`string`||S(e.visible,X)).map(e=>typeof e==`string`?e:e.name):Object.entries(B.fields).filter(([,e])=>S(e.visible,X)).map(([e])=>e):[],[B,X]);if(M)return(0,O.jsx)(T,{});if(!B)return(0,O.jsx)(`div`,{className:`flex h-full items-center justify-center p-4`,children:(0,O.jsxs)(m,{children:[(0,O.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,O.jsx)(y,{className:`h-6 w-6 text-muted-foreground`})}),(0,O.jsx)(_,{children:N(`empty.objectNotFound`)}),(0,O.jsx)(v,{children:N(`empty.objectNotFoundDescription`,{name:o})}),(0,O.jsx)(`div`,{className:`mt-4`,children:(0,O.jsxs)(p,{variant:`outline`,onClick:()=>E(V),children:[(0,O.jsx)(g,{className:`mr-2 h-4 w-4`}),N(`empty.back`)]})})]})});let Q=B.form??B.formViews?.default??{},$=[`tabbed`,`wizard`,`split`].includes(Q.type)?Q.type:`simple`,ee=Array.isArray(Q.sections)&&Q.sections.length>0?{sections:Q.sections,defaultTab:Q.defaultTab,tabPosition:Q.tabPosition,allowSkip:Q.allowSkip,showStepIndicator:Q.showStepIndicator,splitDirection:Q.splitDirection,splitSize:Q.splitSize,splitResizable:Q.splitResizable}:{};return(0,O.jsx)(C,{user:Y,app:{name:t},data:{},features:L,children:(0,O.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden bg-background`,"data-testid":`record-form-page`,"data-mode":e,children:[(0,O.jsxs)(`header`,{className:`sticky top-0 z-10 flex items-center gap-3 border-b bg-background px-4 py-3 sm:px-6`,children:[(0,O.jsx)(p,{variant:`ghost`,size:`sm`,onClick:W,"data-testid":`record-form-page-back`,"aria-label":N(`common.back`,{defaultValue:`Back`}),children:(0,O.jsx)(g,{className:`h-4 w-4`})}),(0,O.jsxs)(`nav`,{"aria-label":`Breadcrumb`,className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,O.jsx)(n,{to:H,className:`hover:text-foreground transition-colors`,children:G}),(0,O.jsx)(`span`,{"aria-hidden":`true`,children:`/`}),(0,O.jsx)(`span`,{className:`text-foreground font-medium`,"data-testid":`record-form-page-title`,children:K}),(0,O.jsx)(w,{managedBy:B?.managedBy,className:`ml-1`})]})]}),(0,O.jsx)(`div`,{className:`flex-1 overflow-auto p-4 sm:p-6`,children:(0,O.jsx)(`div`,{className:`mx-auto max-w-4xl`,children:(0,O.jsx)(x,{schema:{type:`object-form`,formType:$,...ee,objectName:B.name,mode:e,recordId:e===`edit`?s:void 0,...z&&{initialValues:z},title:K,description:e===`create`?N(`form.createDescription`,{object:G,defaultValue:`Create a new ${G}.`}):N(`form.editDescription`,{object:G,defaultValue:`Edit this ${G}.`}),layout:`vertical`,fields:Z,subforms:B.form?.subforms??B.formViews?.default?.subforms,onSuccess:q,onCancel:J,showSubmit:!0,showCancel:!0,submitText:N(`form.saveRecord`,{defaultValue:`Save`}),cancelText:N(`common.cancel`,{defaultValue:`Cancel`})},dataSource:A??void 0},`${e}:${o}:${s??`new`}`)})})]})})}export{E as t};
1
+ import{o as e,r as t}from"./rolldown-runtime-DAXXjFlN.js";import{a as n,f as r,h as i,m as a,r as o,y as s}from"./vendor-react-BKSb6vFP.js";import{p as c}from"./infrastructure-Bc4DRENl.js";import{L as l,R as u,Wt as d,l as f}from"./framework-BL3BtpKU.js";import{Cr as p,K as m,Pc as h,Sc as g,X as _,q as v,rs as y}from"./ui-components-Y3D5-fgK.js";import{r as b}from"./vendor-ui-utils-D-WJ115h.js";import"./AdapterProvider-CSP_T07G.js";import{t as x}from"./plugin-form-6ug8Woph.js";import"./MetadataProvider-DqPZ6rV2.js";import{n as S,t as C}from"./ExpressionProvider-CHaGm5wf.js";import{t as w}from"./ManagedByBadge-Cdy82I7A.js";import{t as T}from"./skeletons-Bf9TL3pG.js";var E=t({RecordFormPage:()=>k}),D=e(s(),1),O=o();function k({mode:e}){let{appName:t,objectName:o,recordId:s}=a(),E=r(),[k]=i(),A=l(),{objects:j,loading:M}=u(),{t:N}=f(),{objectLabel:P}=h(),{user:F,getAuthConfig:I}=c(),[L,R]=(0,D.useState)({});(0,D.useEffect)(()=>{let e=!1;return I().then(t=>{e||R(t?.features??{})}).catch(()=>{}),()=>{e=!0}},[I]);let z=(0,D.useMemo)(()=>{if(e!==`create`)return;let t=[];for(let[e,n]of k.entries())e&&n&&t.push([e,n]);return t.length>0?Object.fromEntries(t):void 0},[e,k.toString()]),B=(0,D.useMemo)(()=>j.find(e=>e.name===o),[j,o]),V=`/apps/${t}`,H=`${V}/${o}`,U=e===`edit`&&s?`${V}/${o}/record/${encodeURIComponent(s)}`:H,W=(0,D.useCallback)(()=>{typeof window<`u`&&window.history.length>1?E(-1):E(U,{replace:!0})},[E,U]),G=B?P(B):o??``,K=e===`create`?N(`form.createTitle`,{object:G,defaultValue:`New ${G}`}):N(`form.editTitle`,{object:G,defaultValue:`Edit ${G}`}),q=(0,D.useCallback)(()=>{b.success(e===`create`?N(`form.createSuccess`,{object:G,defaultValue:`${G} created successfully`}):N(`form.updateSuccess`,{object:G,defaultValue:`${G} updated successfully`})),W()},[e,N,G,W]),J=(0,D.useCallback)(()=>{W()},[W]),Y=(0,D.useMemo)(()=>F?{name:F.name,email:F.email,role:F.role??`user`}:{name:`Anonymous`,email:``,role:`guest`},[F]),X=(0,D.useMemo)(()=>new d({user:Y,app:{name:t},data:{}}),[Y,t]),Z=(0,D.useMemo)(()=>B?.fields?Array.isArray(B.fields)?B.fields.filter(e=>typeof e==`string`||S(e.visible,X)).map(e=>typeof e==`string`?e:e.name):Object.entries(B.fields).filter(([,e])=>S(e.visible,X)).map(([e])=>e):[],[B,X]);if(M)return(0,O.jsx)(T,{});if(!B)return(0,O.jsx)(`div`,{className:`flex h-full items-center justify-center p-4`,children:(0,O.jsxs)(m,{children:[(0,O.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,O.jsx)(y,{className:`h-6 w-6 text-muted-foreground`})}),(0,O.jsx)(_,{children:N(`empty.objectNotFound`)}),(0,O.jsx)(v,{children:N(`empty.objectNotFoundDescription`,{name:o})}),(0,O.jsx)(`div`,{className:`mt-4`,children:(0,O.jsxs)(p,{variant:`outline`,onClick:()=>E(V),children:[(0,O.jsx)(g,{className:`mr-2 h-4 w-4`}),N(`empty.back`)]})})]})});let Q=B.form??B.formViews?.default??{},$=[`tabbed`,`wizard`,`split`].includes(Q.type)?Q.type:`simple`,ee=Array.isArray(Q.sections)&&Q.sections.length>0?{sections:Q.sections,defaultTab:Q.defaultTab,tabPosition:Q.tabPosition,allowSkip:Q.allowSkip,showStepIndicator:Q.showStepIndicator,splitDirection:Q.splitDirection,splitSize:Q.splitSize,splitResizable:Q.splitResizable}:{};return(0,O.jsx)(C,{user:Y,app:{name:t},data:{},features:L,children:(0,O.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden bg-background`,"data-testid":`record-form-page`,"data-mode":e,children:[(0,O.jsxs)(`header`,{className:`sticky top-0 z-10 flex items-center gap-3 border-b bg-background px-4 py-3 sm:px-6`,children:[(0,O.jsx)(p,{variant:`ghost`,size:`sm`,onClick:W,"data-testid":`record-form-page-back`,"aria-label":N(`common.back`,{defaultValue:`Back`}),children:(0,O.jsx)(g,{className:`h-4 w-4`})}),(0,O.jsxs)(`nav`,{"aria-label":`Breadcrumb`,className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,O.jsx)(n,{to:H,className:`hover:text-foreground transition-colors`,children:G}),(0,O.jsx)(`span`,{"aria-hidden":`true`,children:`/`}),(0,O.jsx)(`span`,{className:`text-foreground font-medium`,"data-testid":`record-form-page-title`,children:K}),(0,O.jsx)(w,{managedBy:B?.managedBy,className:`ml-1`})]})]}),(0,O.jsx)(`div`,{className:`flex-1 overflow-auto p-4 sm:p-6`,children:(0,O.jsx)(`div`,{className:`mx-auto max-w-4xl`,children:(0,O.jsx)(x,{schema:{type:`object-form`,formType:$,...ee,objectName:B.name,mode:e,recordId:e===`edit`?s:void 0,...z&&{initialValues:z},title:K,description:e===`create`?N(`form.createDescription`,{object:G,defaultValue:`Create a new ${G}.`}):N(`form.editDescription`,{object:G,defaultValue:`Edit this ${G}.`}),layout:`vertical`,fields:Z,subforms:B.form?.subforms??B.formViews?.default?.subforms,onSuccess:q,onCancel:J,showSubmit:!0,showCancel:!0,submitText:N(`form.saveRecord`,{defaultValue:`Save`}),cancelText:N(`common.cancel`,{defaultValue:`Cancel`})},dataSource:A??void 0},`${e}:${o}:${s??`new`}`)})})]})})}export{E as t};