@protobase/ui 0.112.1 → 0.112.2

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 (107) hide show
  1. package/dist/account/messages.d.ts +2 -2
  2. package/dist/app/app.js +4 -3
  3. package/dist/app/charts/messages.d.ts +2 -2
  4. package/dist/app/confirm-sign-in-messages.d.ts +2 -2
  5. package/dist/app/create/messages.d.ts +2 -2
  6. package/dist/app/delete/messages.d.ts +2 -2
  7. package/dist/app/displays/messages.d.ts +2 -2
  8. package/dist/app/embedded-list/messages.d.ts +2 -2
  9. package/dist/app/export/messages.d.ts +2 -2
  10. package/dist/app/field-messages.d.ts +2 -2
  11. package/dist/app/field-types/json/messages.d.ts +2 -2
  12. package/dist/app/field-types/workflow/definition.d.ts +1 -1
  13. package/dist/app/field-types/workflow/messages.d.ts +2 -2
  14. package/dist/app/field-types/workflow-page/messages.d.ts +2 -2
  15. package/dist/app/field-types/workflow-run/messages.d.ts +2 -2
  16. package/dist/app/focus/messages.d.ts +2 -2
  17. package/dist/app/gallery/gallery-layout.d.ts +2 -2
  18. package/dist/app/gallery/messages.d.ts +2 -2
  19. package/dist/app/hand-order/messages.d.ts +2 -2
  20. package/dist/app/history/messages.d.ts +2 -2
  21. package/dist/app/hold-start-for-first-loads.d.ts +12 -0
  22. package/dist/app/hold-start-for-first-loads.js +43 -0
  23. package/dist/app/import/messages.d.ts +2 -2
  24. package/dist/app/index.html +17 -0
  25. package/dist/app/list-messages.d.ts +2 -2
  26. package/dist/app/messages.d.ts +2 -2
  27. package/dist/app/pages/messages.d.ts +2 -2
  28. package/dist/app/record-chart/messages.d.ts +2 -2
  29. package/dist/app/record-messages.d.ts +2 -2
  30. package/dist/app/record-mode/shown-layout.d.ts +1 -1
  31. package/dist/app/related-cards/messages.d.ts +2 -2
  32. package/dist/app/runtime/messages.d.ts +2 -2
  33. package/dist/app/saved/messages.d.ts +2 -2
  34. package/dist/app/search/messages.d.ts +2 -2
  35. package/dist/app/searches/messages.d.ts +2 -2
  36. package/dist/app/splash-hold.d.ts +1 -0
  37. package/dist/app/splash-hold.js +1 -1
  38. package/dist/app/start-screen.d.ts +9 -0
  39. package/dist/app/start-screen.js +10 -1
  40. package/dist/app-shell/messages.d.ts +2 -2
  41. package/dist/assistant-dock/messages.d.ts +2 -2
  42. package/dist/auth/messages.d.ts +2 -2
  43. package/dist/calls/messages.d.ts +2 -2
  44. package/dist/compact-table/messages.d.ts +2 -2
  45. package/dist/data-grid/column-spec.d.ts +1 -1
  46. package/dist/data-grid/messages.d.ts +2 -2
  47. package/dist/filter-panel/messages.d.ts +2 -2
  48. package/dist/format/messages.d.ts +2 -2
  49. package/dist/forms/messages.d.ts +2 -2
  50. package/dist/inline-child-table/messages.d.ts +2 -2
  51. package/dist/live/messages.d.ts +2 -2
  52. package/dist/markdown/messages.d.ts +2 -2
  53. package/dist/mocks/customers.d.ts +1 -1
  54. package/dist/mocks/invoices.d.ts +2 -2
  55. package/dist/mocks/orders.d.ts +2 -2
  56. package/dist/notifications/bell/messages.d.ts +2 -2
  57. package/dist/organizations/messages.d.ts +2 -2
  58. package/dist/package.js +1 -1
  59. package/dist/primitives/messages.d.ts +2 -2
  60. package/dist/record-view/messages.d.ts +2 -2
  61. package/dist/record-view/use-autosave.d.ts +1 -1
  62. package/dist/shell/assets/app-BbB79rGo.js +16 -0
  63. package/dist/shell/assets/{graph-view-Dky1whXD.js → graph-view-DkLJGbAM.js} +2 -2
  64. package/dist/shell/assets/{html-viewer-lp3H6iV2.js → html-viewer-CFhG0dfK.js} +2 -2
  65. package/dist/shell/assets/{in-place-form-B-GQA4qE.js → in-place-form-CSZ6XQwe.js} +2 -2
  66. package/dist/shell/assets/{index-VlTh9QjU.js → index-CGHo79rF.js} +2 -2
  67. package/dist/shell/assets/{maplibre-DjGuR3NM.js → maplibre-CU0FwYOr.js} +2 -2
  68. package/dist/shell/assets/{markdown-content-C_I33tF1.js → markdown-content-HfXJkQCt.js} +2 -2
  69. package/dist/shell/assets/{record-map-0rx4A_p3.js → record-map-BSsmZmbf.js} +2 -2
  70. package/dist/shell/assets/{records-map-8Od0n3e7.js → records-map-CCHa0cjg.js} +2 -2
  71. package/dist/shell/assets/{run-trace-view-5Xia2z2X.js → run-trace-view-ovkKBP1m.js} +2 -2
  72. package/dist/shell/assets/{search-picker-BeTUduFk.js → search-picker-DuhRI954.js} +2 -2
  73. package/dist/shell/assets/{shared-protobase-ui-vMThpYOB.js → shared-protobase-ui-Mk2r7Wf4.js} +2 -2
  74. package/dist/shell/assets/{step-catalog-Aw0TBmFO.js → step-catalog-DxGx8yvI.js} +2 -2
  75. package/dist/shell/assets/{step-panel-BbMJ5sl9.js → step-panel-BLv6M8fk.js} +2 -2
  76. package/dist/shell/assets/{use-app-address-D50fN1nP.js → use-app-address-B6k3dkV0.js} +2 -2
  77. package/dist/shell/assets/{use-sibling-page-CaUyRcwf.js → use-sibling-page-DLjl_l8i.js} +2 -2
  78. package/dist/shell/assets/{workflow-canvas-vb0Tlov2.js → workflow-canvas-DLDb_g1s.js} +2 -2
  79. package/dist/shell/assets/{workflow-graph-editor-_fE7qonR.js → workflow-graph-editor-DZHTqa3R.js} +2 -2
  80. package/dist/shell/assets/{workflow-workbench-C_m8akk8.js → workflow-workbench-CG8xTDx0.js} +2 -2
  81. package/dist/shell/index.html +8 -5
  82. package/dist/shell/protobase.shell.json +2 -2
  83. package/dist/shell/protobase.sw.js +2 -2
  84. package/dist/shell-source-maps/assets/app-BbB79rGo.js.map +1 -0
  85. package/dist/shell-source-maps/assets/{graph-view-Dky1whXD.js.map → graph-view-DkLJGbAM.js.map} +1 -1
  86. package/dist/shell-source-maps/assets/{html-viewer-lp3H6iV2.js.map → html-viewer-CFhG0dfK.js.map} +1 -1
  87. package/dist/shell-source-maps/assets/{in-place-form-B-GQA4qE.js.map → in-place-form-CSZ6XQwe.js.map} +1 -1
  88. package/dist/shell-source-maps/assets/{index-VlTh9QjU.js.map → index-CGHo79rF.js.map} +1 -1
  89. package/dist/shell-source-maps/assets/{maplibre-DjGuR3NM.js.map → maplibre-CU0FwYOr.js.map} +1 -1
  90. package/dist/shell-source-maps/assets/{markdown-content-C_I33tF1.js.map → markdown-content-HfXJkQCt.js.map} +1 -1
  91. package/dist/shell-source-maps/assets/{record-map-0rx4A_p3.js.map → record-map-BSsmZmbf.js.map} +1 -1
  92. package/dist/shell-source-maps/assets/{records-map-8Od0n3e7.js.map → records-map-CCHa0cjg.js.map} +1 -1
  93. package/dist/shell-source-maps/assets/{run-trace-view-5Xia2z2X.js.map → run-trace-view-ovkKBP1m.js.map} +1 -1
  94. package/dist/shell-source-maps/assets/{search-picker-BeTUduFk.js.map → search-picker-DuhRI954.js.map} +1 -1
  95. package/dist/shell-source-maps/assets/{shared-protobase-ui-vMThpYOB.js.map → shared-protobase-ui-Mk2r7Wf4.js.map} +1 -1
  96. package/dist/shell-source-maps/assets/{step-catalog-Aw0TBmFO.js.map → step-catalog-DxGx8yvI.js.map} +1 -1
  97. package/dist/shell-source-maps/assets/{step-panel-BbMJ5sl9.js.map → step-panel-BLv6M8fk.js.map} +1 -1
  98. package/dist/shell-source-maps/assets/{use-app-address-D50fN1nP.js.map → use-app-address-B6k3dkV0.js.map} +1 -1
  99. package/dist/shell-source-maps/assets/{use-sibling-page-CaUyRcwf.js.map → use-sibling-page-DLjl_l8i.js.map} +1 -1
  100. package/dist/shell-source-maps/assets/{workflow-canvas-vb0Tlov2.js.map → workflow-canvas-DLDb_g1s.js.map} +1 -1
  101. package/dist/shell-source-maps/assets/{workflow-graph-editor-_fE7qonR.js.map → workflow-graph-editor-DZHTqa3R.js.map} +1 -1
  102. package/dist/shell-source-maps/assets/{workflow-workbench-C_m8akk8.js.map → workflow-workbench-CG8xTDx0.js.map} +1 -1
  103. package/dist/status/messages.d.ts +2 -2
  104. package/dist/users/messages.d.ts +2 -2
  105. package/package.json +5 -5
  106. package/dist/shell/assets/app-4qlxuQdl.js +0 -16
  107. package/dist/shell-source-maps/assets/app-4qlxuQdl.js.map +0 -1
@@ -0,0 +1,16 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/lib-sentry-browser-rsfK9tDJ.js","assets/rolldown-runtime-DFwUHQ4A.js","assets/workflow-graph-editor-DZHTqa3R.js","assets/react-CuiNlnus.js","assets/api-provider-CcDtTh0D.js","assets/vendor-WWp_xlp2.js","assets/messages-ClKBpZlk.js","assets/call-guests-MJxXvcx-.js","assets/cn-B1sdg8aY.js","assets/step-catalog-DxGx8yvI.js","assets/use-meta-BqEqOLNe.js","assets/checkbox-COOOlJPG.js","assets/workflows-start-kl7rSSay.js","assets/workflow-canvas-DLDb_g1s.js","assets/guarded-D7vqlAj1.js","assets/badge-ChHXC28D.js","assets/workflows-Bku4o2su.js","assets/lib-xyflow-react-DGg_5r7u.js","assets/lib-d3-interpolate-Cl0dHO4f.js","assets/lib-classcat-otpLnDWv.js","assets/lib-d3-drag-DWHgnkJb.js","assets/lib-d3-dispatch-Bjkn7q4t.js","assets/lib-d3-zoom-gQh2osrj.js","assets/lib-d3-transition-DUHAGQ8z.js","assets/lib-d3-timer-CduGpaSm.js","assets/lib-d3-ease-ouQSXgQM.js","assets/lib-xyflow-react-DLioOiRN.css","assets/use-elk-u1Ql5AOs.js","assets/lib-elkjs-ylMkguT9.js","assets/workflow-canvas-C5ExDFGN.css","assets/search-picker-DuhRI954.js","assets/graph-frame-PVfWqgbJ.js","assets/workflow-workbench-CG8xTDx0.js","assets/use-app-address-B6k3dkV0.js","assets/display-value-fDiKbfJO.js","assets/intl-cache-bXVNV0Yq.js","assets/value-badge-BKLV4otJ.js","assets/in-place-form-CSZ6XQwe.js","assets/step-panel-BLv6M8fk.js","assets/run-trace-view-ovkKBP1m.js","assets/markdown-content-HfXJkQCt.js","assets/lib-dompurify-Dr60P-Rn.js","assets/lib-marked-Bg9_sE-m.js","assets/html-viewer-CFhG0dfK.js","assets/use-sibling-page-DLjl_l8i.js","assets/graph-view-DkLJGbAM.js","assets/field-badge-3QmjR1r3.js","assets/records-map-CCHa0cjg.js","assets/maplibre-CU0FwYOr.js","assets/lib-maplibre-gl-CFGgq6sa.js","assets/lib-maplibre-gl-DBE96hFo.css","assets/lib-vis.gl-react-maplibre-CU7gWYjg.js","assets/lib-pmtiles-G7iEFxNu.js","assets/lib-fflate-HbhbPPwS.js","assets/calls-BQqt6R-b.js","assets/record-map-BSsmZmbf.js"])))=>i.map(i=>d[i]);
2
+ (function(){try{var e=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:typeof self<`u`?self:{};e._sentryModuleMetadata=e._sentryModuleMetadata||{},e._sentryModuleMetadata[new e.Error().stack]=function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];if(n!=null)for(var r in n)n.hasOwnProperty(r)&&(e[r]=n[r])}return e}({},e._sentryModuleMetadata[new e.Error().stack],{"_sentryBundlerPluginAppKey:protobase-app":!0})}catch{}})();import{o as e}from"./rolldown-runtime-DFwUHQ4A.js";import{i as t,r as n,t as r}from"./react-CuiNlnus.js";import{t as i}from"./guarded-D7vqlAj1.js";import{$ as a,A as o,At as s,B as c,C as l,Ct as u,D as d,Dt as f,E as p,Et as m,F as h,G as g,H as _,I as v,J as y,K as b,L as x,M as S,N as C,O as w,Ot as T,P as E,Q as D,R as O,S as k,St as ee,T as A,Tt as te,U as ne,V as re,W as j,X as ie,Y as M,Z as ae,_ as oe,_t as se,a as ce,at as le,b as ue,bt as de,c as fe,ct as pe,d as me,dt as he,et as ge,f as _e,ft as ve,g as ye,gt as be,h as xe,ht as Se,i as Ce,it as we,j as N,jt as Te,k as Ee,kt as De,l as Oe,lt as ke,m as Ae,mt as je,n as Me,nt as Ne,o as Pe,ot as Fe,p as Ie,pt as Le,q as Re,r as ze,rt as Be,s as Ve,st as He,t as Ue,tt as We,u as Ge,ut as Ke,v as qe,vt as Je,w as Ye,wt as Xe,x as Ze,xt as Qe,y as $e,yt as et,z as tt}from"./use-app-address-B6k3dkV0.js";import{$ as nt,A as rt,At as it,C as at,Ct as ot,D as st,E as ct,F as lt,G as ut,H as dt,I as ft,J as pt,K as mt,M as ht,N as gt,O as _t,P as vt,Q as yt,S as bt,St as xt,T as St,Tt as Ct,X as wt,Y as Tt,_ as Et,_t as Dt,a as Ot,at as kt,b as At,bt as jt,c as Mt,ct as Nt,d as Pt,dt as Ft,f as It,g as Lt,gt as Rt,h as zt,ht as Bt,i as Vt,it as Ht,j as Ut,k as Wt,kt as Gt,l as Kt,lt as qt,m as Jt,mt as Yt,n as Xt,o as Zt,ot as Qt,p as $t,q as en,r as tn,rt as nn,s as rn,st as an,t as on,tt as sn,u as cn,ut as ln,v as un,vt as dn,w as fn,wt as pn,x as mn,xt as hn,y as gn,yt as _n}from"./vendor-WWp_xlp2.js";import{A as vn,C as yn,D as bn,E as xn,M as Sn,O as Cn,S as wn,_ as Tn,a as En,b as P,d as Dn,f as On,g as kn,h as An,i as jn,j as Mn,k as Nn,l as Pn,m as Fn,p as In,r as F,t as Ln,u as I,v as Rn,x as zn,y as Bn}from"./api-provider-CcDtTh0D.js";import{$ as Vn,A as Hn,B as L,C as Un,D as Wn,E as Gn,F as R,G as Kn,H as qn,I as Jn,J as Yn,L as Xn,M as Zn,N as Qn,O as $n,P as er,Q as tr,R as nr,S as rr,T as ir,U as ar,V as or,W as sr,X as cr,Y as lr,Z as ur,_ as dr,a as fr,at as pr,b as mr,c as hr,d as gr,et as _r,f as vr,g as yr,h as br,i as xr,it as Sr,j as Cr,k as wr,l as Tr,m as Er,n as Dr,nt as Or,o as kr,ot as Ar,p as jr,q as Mr,r as Nr,rt as Pr,s as Fr,st as Ir,t as Lr,tt as Rr,u as zr,v as Br,w as Vr,x as Hr,y as Ur,z as Wr}from"./display-value-fDiKbfJO.js";import{a as Gr,c as Kr,d as qr,f as Jr,h as Yr,i as Xr,l as Zr,m as Qr,n as z,o as $r,p as ei,r as ti,s as ni,t as ri,u as ii}from"./value-badge-BKLV4otJ.js";import{c as ai,i as oi,l as si,n as B,o as ci,r as V}from"./messages-ClKBpZlk.js";import{a as H,i as li,n as ui,r as di,t as fi}from"./use-meta-BqEqOLNe.js";import{t as pi}from"./call-guests-MJxXvcx-.js";import{t as U}from"./cn-B1sdg8aY.js";import{A as mi,C as hi,D as gi,E as _i,M as vi,N as yi,O as bi,P as xi,_ as Si,j as Ci,k as wi,n as Ti,o as Ei,t as Di,v as Oi,w as ki,y as Ai}from"./checkbox-COOOlJPG.js";import{n as ji,r as Mi,t as Ni}from"./badge-ChHXC28D.js";import{t as Pi}from"./intl-cache-bXVNV0Yq.js";import{t as Fi}from"./workflows-start-kl7rSSay.js";var Ii=/^[\d\s+\-().\/]+$/,Li=e=>Ii.test(e)?e.replace(/\D/g,``):``,Ri=e=>{let t=e.split(/\s+/).filter(Boolean).map(e=>({text:e,digits:Li(e),whole:!1})),n=t.length>1?Li(e.trim()):``;return n?[{text:e.trim(),digits:n,whole:!0},...t]:t},zi=(e,t,n)=>e==null?!1:n===`digitsEnd`?t.digits!==``&&String(e).replace(/\D/g,``).endsWith(t.digits):!t.whole&&String(e).toLowerCase().includes(t.text.toLowerCase()),Bi=(e,t,n)=>(e.search??[]).filter(r=>zi(t[r],n,e.searchMatch?.[r])),Vi=(e,t,n)=>{let r=Ri(n),i=r.filter(e=>!e.whole),a=r.find(e=>e.whole);return a&&Bi(e,t,a).length>0?!0:i.length>0&&i.every(n=>Bi(e,t,n).length>0)},Hi=(e,t,n,r)=>{for(let i of Ri(n)){let n=Bi(e,t,i);if(n.length>0&&!n.some(e=>r.includes(e)))return n[0]}},Ui=e=>()=>{throw Error(`Not implemented: ${e}() needs the database (the resource's search fields, trigram matching), so it cannot be evaluated against a record`)},Wi=(e,t,n)=>({...Sn,search:{...Sn.search,evaluate:n?e=>Vi(n,t,e):Ui(`search`)},similar:{...Sn.similar,evaluate:Ui(`similar`)},regex:{...Sn.regex,evaluate:(e,t)=>e.some(e=>typeof e==`string`&&new RegExp(t).test(e))},now:{...Sn.now,evaluate:e}}),Gi=(e,t,n={})=>Gt(Mn(e,{expand:!0}),t,{functions:Wi(n.now??(()=>new Date),t,n.search)}),Ki=/^-?\d+$/,qi=-(2n**63n),Ji=2n**63n-1n,Yi={type:`bigint`,constraints:[],build:()=>xt().refine(e=>Ki.test(e)&&BigInt(e)>=qi&&BigInt(e)<=Ji,{message:`Expected a 64-bit integer as a string`})},Xi={type:`boolean`,constraints:[],build:()=>dn()},Zi={type:`country`,constraints:[],build:()=>xt().regex(/^[A-Z]{2}$/,`Expected an ISO 3166-1 alpha-2 country code`)},Qi={type:`currency`,constraints:[],build:()=>xt().regex(/^[A-Z]{3}$/,`Expected an ISO 4217 currency code`)},$i={type:`date`,constraints:[],build:()=>Bt()},ea=/^-?(\d*)(?:\.(\d+))?$/,ta={type:`decimal`,constraints:[],build:e=>{if(e.precision===void 0||e.scale===void 0)throw Error(`f.decimal requires precision and scale`);let t=e.precision-e.scale,n=e.scale;return xt().refine(e=>{let r=ea.exec(e);if(!r)return!1;let i=(r[1]??``).replace(/^0+/,``),a=r[2]??``;return r[1]||a?i.length<=t&&a.length<=n:!1},{message:`Expected a decimal string with at most ${e.precision} digits, ${e.scale} after the point`,params:{precision:e.precision,scale:e.scale}})}},na={type:`enum`,constraints:[],build:e=>{if(!e.enumValues?.length)throw Error(`f.enum requires at least one value`);return Dt(e.enumValues)}},ra={type:`file`,constraints:[],build:()=>xt().min(1).max(4096)},ia={type:`integer`,constraints:[`min`,`max`],build:e=>{let t=_n();return e.min!==void 0&&(t=t.min(e.min)),e.max!==void 0&&(t=t.max(e.max)),t}},aa=(e,t=256)=>{let n=[[e,0]];for(;n.length>0;){let[e,r]=n.pop();if(typeof e==`object`&&e){if(r+1>t)return!1;for(let t of Object.values(e))n.push([t,r+1])}}return!0},oa={type:`json`,constraints:[],build:()=>hn((e,t)=>(aa(e)||t.addIssue({code:`custom`,message:`Nested deeper than 256 levels`,params:{max_depth:256}}),e),jt())},sa={type:`relation`,constraints:[],build:()=>ot([xt(),_n()])},ca={type:`text`,constraints:[`min`,`max`,`regex`],build:e=>{let t=xt();return e.min!==void 0&&(t=t.min(e.min)),e.max!==void 0&&(t=t.max(e.max)),e.regex&&(t=t.regex(e.regex.re,e.regex.message)),t}},la={type:`timestamp`,constraints:[],build:()=>Rt({offset:!0})},ua={type:`uuid`,constraints:[],build:()=>pn()},da=e=>_r(e),fa=e=>da(e).length===0?`its prompt must name at least one {{field}} of the record`:void 0,pa=/\s*(?:(\d+(?:\.\d+)?)|([A-Za-z_][A-Za-z0-9_]*)|([-+*/(),]))/y,ma=e=>{let t=[];for(pa.lastIndex=0;pa.lastIndex<e.length;){let n=pa.lastIndex,r=pa.exec(e);if(!r){let t=e.slice(n);if(t.trim()===``)break;let r=t.length-t.trimStart().length;throw Error(`Formula "${e}": unexpected "${t[r]}" at ${n+r+1}`)}let[i,a,o,s]=r,c=a??o??s;t.push({kind:a===void 0?o===void 0?`symbol`:`name`:`number`,text:c,at:n+i.length-c.length})}return t},ha=e=>{let t=ma(e),n=0,r=r=>{let i=t[n];throw Error(`Formula "${e}": ${r}${i?` at ${i.at+1}, found "${i.text}"`:` at the end`}`)},i=e=>t[n]?.kind===`symbol`&&t[n].text===e,a=e=>{i(e)||r(`expected "${e}"`),n+=1},o=()=>{a(`(`);let e=[u()];for(;i(`,`);)n+=1,e.push(u());return a(`)`),e},s=e=>{if(e===`coalesce`){let e=o();return e.length<2&&r(`coalesce() takes at least two values`),{kind:`coalesce`,args:e}}let t=o(),[n,i]=t;return t.length>2&&r(`round() takes a value and at most a number of digits`),i===void 0?{kind:`round`,value:n}:((i.kind!==`number`||i.value.includes(`.`))&&r(`round()'s digits must be a whole number`),{kind:`round`,value:n,digits:Number(i.value)})},c=()=>{let e=t[n];if(!e)return r(`expected a number, a field or "("`);if(e.kind===`number`)return n+=1,{kind:`number`,value:e.text};if(e.kind===`name`)return n+=1,i(`(`)?e.text!==`coalesce`&&e.text!==`round`?(--n,r(`unknown function "${e.text}", only coalesce() and round()`)):s(e.text):{kind:`field`,name:e.text};if(e.text===`-`)return n+=1,{kind:`negate`,operand:c()};if(e.text===`(`){n+=1;let e=u();return a(`)`),e}return r(`expected a number, a field or "("`)},l=()=>{let e=c();for(;i(`*`)||i(`/`);){let r=t[n].text;n+=1,e={kind:`binary`,op:r,left:e,right:c()}}return e},u=()=>{let e=l();for(;i(`+`)||i(`-`);){let r=t[n].text;n+=1,e={kind:`binary`,op:r,left:e,right:l()}}return e},d=u();return n<t.length&&r(`expected an operator`),d},ga=Ct(),_a=class e{def;meta;schema;constructor(e,t){this.def=e,this.meta=t;let n=e.build(t);t.nullable&&(n=n.nullable()),t.hasDefault&&(n=n.default(t.defaultValue)),this.schema=n.register(ga,t)}column(e){return this.with({column:e})}readOnly(){return this.with({readOnly:!0})}optional(){return this.with({nullable:!0})}default(e){return this.with({hasDefault:!0,defaultValue:e})}access(e){return this.with({access:{...this.meta.access,...e}})}sensitive(){return this.with({sensitive:!0})}encrypted(){if(this.meta.type!==`text`)throw Error(`.encrypted() takes only f.text() fields`);return this.with({encrypted:!0,sensitive:!0})}strongSignIn(e={}){let t=e.minutes??15;if(!Number.isInteger(t)||t<1)throw Error(`.strongSignIn(): minutes must be a whole number of at least 1`);return this.with({strongSignIn:{minutes:t},sensitive:!0})}dbDefault(){return this.with({dbDefault:!0})}alias(...e){return this.with({aliases:[...this.meta.aliases,...e]})}filterable(){return this.with({filterable:!0})}sortable(){return this.with({sortable:!0})}regex(e,t){return this.constrain(`regex`,{regex:{re:e,message:t}})}min(e){return this.constrain(`min`,{min:e})}max(e){return this.constrain(`max`,{max:e})}ai(e){let t=fa(e.prompt);if(t)throw Error(`.ai(): ${t}`);return this.with({ai:{prompt:e.prompt}})}rollup(e){return this.with({rollup:{...e},readOnly:!0})}formula(e){return ha(e),this.with({formula:e,readOnly:!0})}with(t){return new e(this.def,{...this.meta,...t})}constrain(e,t){if(!this.def.constraints.includes(e))throw Error(`f.${this.def.type} does not support .${e}()`);return this.with(t)}},va=class extends _a{columns(e){return this.with({relation:{resource:this.meta.relation.resource,columns:e}})}},ya=[`webp`,`avif`,`jpeg`,`png`],ba=5e7,xa={b:1,kb:1e3,mb:1e6,gb:1e9,kib:1024,mib:1024**2,gib:1024**3},Sa=e=>{if(typeof e==`number`){if(!Number.isSafeInteger(e)||e<=0)throw Error(`A file size must be a positive whole number of bytes, not ${e}`);return e}let t=/^\s*(\d+(?:\.\d+)?)\s*([a-z]+)?\s*$/i.exec(e),n=xa[(t?.[2]??`b`).toLowerCase()];if(!t||!n)throw Error(`"${e}" is not a size; write it like "10 MB" or "512 KiB"`);return Sa(Math.round(Number(t[1])*n))},Ca=/^(?:\*\/\*|[a-z0-9][a-z0-9!#$&^_.+-]*\/(?:\*|[a-z0-9][a-z0-9!#$&^_.+-]*))$/,wa=e=>e.map(e=>{let t=e.trim().toLowerCase();if(!Ca.test(t))throw Error(`"${e}" is not a media type or a type/* wildcard`);return t}),Ta=/^[a-z][a-z0-9-]{0,31}$/,Ea=new Set([`http`,`https`,`data`,`blob`,`file`,`javascript`,`mailto`]),Da=e=>{if(!Ta.test(e))throw Error(`"${e}" is not a file provider name: lowercase letters, digits and dashes, starting with a letter`);if(Ea.has(e))throw Error(`"${e}" cannot name a file provider: stored values would read as ${e}: links`);return e},Oa=/^[a-z][a-z0-9_]{0,31}$/,ka=[`inside`,`cover`],Aa=(e,t)=>{if(t!==void 0&&(!Number.isSafeInteger(t)||t<1||t>16384))throw Error(`${e} must be a whole number of pixels from 1 to 16384, not ${t}`)},ja=(e,t)=>{if(!ya.includes(t.format))throw Error(`${e}: "${t.format}" is not an image format; use ${ya.join(`, `)}`);if(t.fit!==void 0&&!ka.includes(t.fit))throw Error(`${e}: fit is "inside" or "cover", not "${t.fit}"`);if(t.fit===`cover`&&(t.width===void 0||t.height===void 0))throw Error(`${e}: fit "cover" needs both a width and a height`);if(Aa(`${e}: width`,t.width),Aa(`${e}: height`,t.height),t.quality!==void 0&&(!Number.isSafeInteger(t.quality)||t.quality<1||t.quality>100))throw Error(`${e}: quality must be a whole number from 1 to 100, not ${t.quality}`);return{...t}},Ma=e=>Object.fromEntries(Object.entries(e).map(([e,t])=>{if(!Oa.test(e))throw Error(`"${e}" cannot name an image variant: lowercase letters, digits and underscores, starting with a letter`);return[e,ja(`Image variant "${e}"`,t)]})),Na=class e extends _a{accept(e){return this.withFile({accept:wa(e)})}maxSize(e){return this.withFile({maxSize:Sa(e)})}public(){return this.storage(`public`)}storage(e){return this.withFile({provider:Da(e)})}derive(e){return this.withFile({derive:{...this.meta.file.derive,...e}})}placeholder(e){return this.withFile({placeholder:e})}typeField(e){return this.withFile({typeField:e})}sizeField(e){return this.withFile({sizeField:e})}variants(e,t={}){return this.withFile({variants:{...this.meta.file.variants,...Ma(e)},...t.original&&{original:ja(`The original`,t.original)}})}externalUrls(){return this.withFile({external:!0})}optional(){return this.with({nullable:!0})}readOnly(){return this.with({readOnly:!0})}column(e){return this.with({column:e})}access(e){return this.with({access:{...this.meta.access,...e}})}with(t){return new e(this.def,{...this.meta,...t})}withFile(e){return this.with({file:{...this.meta.file,...e}})}},Pa=e=>({type:e.type,nullable:!1,readOnly:!1,filterable:!1,sortable:!1,aliases:[],hasDefault:!1}),Fa=(e,t={})=>new _a(e,{...Pa(e),...t}),Ia={text:()=>Fa(ca),integer:()=>Fa(ia),bigint:()=>Fa(Yi),decimal:e=>Fa(ta,e),boolean:()=>Fa(Xi),date:()=>Fa($i),timestamp:()=>Fa(la),uuid:()=>Fa(ua),enum:e=>Fa(na,{enumValues:[...e]}),json:()=>Fa(oa),relation:e=>new va(sa,{...Pa(sa),relation:{resource:e}}),file:()=>new Na(ra,{...Pa(ra),file:{accept:[],maxSize:ba,provider:`private`}}),currency:()=>Fa(Qi),country:()=>Fa(Zi)},La=/^[a-z0-9][a-z0-9_-]*$/,Ra=e=>{if(!e.startsWith(`/-/forms/`))return;let t=e.slice(9);return La.test(t)?{name:t}:void 0},za=e=>e.flatMap(e=>e.kind===`group`||e.kind===`tab`?za(e.items):e.kind===`custom`?[e,...za(e.fallback??[])]:[e]),Ba=e=>/^(https?:\/\/|mailto:)/i.test(e),Va=[`neutral`,`info`,`success`,`warning`,`danger`],Ha=20,Ua=(e,t)=>{let n=Te(t);if(!n.ok)return n.errors;if(!n.ast)return[];let r=s(e,n.ast);return r.ok?[]:r.errors},Wa=(e,t)=>{let n=De(t);if(!n.ok)return n.errors;let r=T(e,n.items);return r.ok?[]:r.errors},Ga=(e,t)=>[...e.status===void 0||Object.hasOwn(t.fields,e.status)?[]:[`status field "${e.status}" does not exist`],...e.status===void 0&&e.pulse!==void 0?[`pulse needs a status field`]:[],...Object.entries(e.tones??{}).filter(([,e])=>!Va.includes(e)).map(([e,t])=>`tone "${t}" for "${e}" is not one of ${Va.join(`, `)}`),...e.limit===void 0||Number.isInteger(e.limit)&&e.limit>=1&&e.limit<=Ha?[]:[`limit must be a whole number from 1 to ${Ha}`],...e.filter===void 0?[]:Ua(t,e.filter).map(e=>`filter: ${e.message}`),...e.orderBy===void 0?[]:Wa(t,e.orderBy).map(e=>`orderBy: ${e.message}`),...e.marks===void 0||typeof e.marks==`string`&&e.marks!==``?[]:[`marks needs the name of a hook in the project UI's marks`]],Ka=(e,t,n,r={})=>({name:e,kind:t,label:n.label,required:t!==`boolean`&&!n.optional,...n.help!==void 0&&{help:n.help},...n.when!==void 0&&{when:n.when},...n.default!==void 0&&{default:n.default},...r}),qa={text:(e,t)=>Ka(e,`text`,t,{...t.multiline&&{multiline:!0},...t.max!==void 0&&{max:t.max}}),integer:(e,t)=>Ka(e,`integer`,t),decimal:(e,t)=>Ka(e,`decimal`,t),boolean:(e,t)=>Ka(e,`boolean`,t),secret:(e,t)=>Ka(e,`secret`,t),date:(e,t)=>Ka(e,`date`,t),choice:(e,t)=>Ka(e,`choice`,t,`options`in t?{options:t.options.map(({value:e,label:t})=>({value:e,label:t}))}:{resource:t.resource}),checklist:(e,t)=>Ka(e,`checklist`,t,{...`items`in t&&{items:[...t.items]},...`from`in t&&{from:t.from}}),custom:(e,t)=>Ka(e,`custom`,t,{component:t.component,...t.props!==void 0&&{props:t.props}})},Ja={text:`text`,integer:`integer`,decimal:`decimal`,boolean:`boolean`,date:`date`,choice:`text`,secret:`text`,checklist:`json`,custom:`json`},Ya=e=>({name:e.name,column:e.name,type:e.options?`enum`:Ja[e.kind],nullable:!0,readOnly:!1,filterable:e.kind!==`custom`&&e.kind!==`checklist`&&e.kind!==`secret`,sortable:!1,aliases:[],...e.options&&{enumValues:e.options.map(e=>e.value)}}),Xa=e=>({name:`inputs`,table:{name:`inputs`},fields:Object.fromEntries(e.map(e=>[e.name,Ya(e)])),primaryKey:[]}),Za=(e,t)=>{let n=e[t].when;if(n===void 0)return;let r=Te(n);if(!r.ok)return r.errors.map(e=>e.message).join(`; `);if(!r.ast)return`it is empty`;let i=s(Xa(e.slice(0,t)),r.ast);return i.ok?i.filter:i.errors.map(e=>e.message).join(`; `)},Qa=e=>e.kind===`checklist`?e.items===void 0==(e.from===void 0)?[`input "${e.name}": a checklist takes either "items" or "from"`]:e.items&&e.items.length===0?[`input "${e.name}": a checklist needs at least one item`]:[]:[],$a=e=>e.flatMap((t,n)=>{let r=[];e.findIndex(e=>e.name===t.name)!==n&&r.push(`input "${t.name}" is declared twice`),t.kind===`secret`&&t.default!==void 0&&r.push(`input "${t.name}": a secret takes no default`),t.kind!==`secret`&&t.options&&t.default!==void 0&&!t.options.some(e=>e.value===t.default)&&r.push(`input "${t.name}": default "${String(t.default)}" is not one of its options`);let i=Za(e,n);return typeof i==`string`&&r.push(`input "${t.name}": "when" is not a valid condition over the inputs before it: ${i}`),[...r,...Qa(t)]}),eo=(e,t)=>{let n=new Set,r={};return e.forEach((i,a)=>{let o=Za(e,a);if(typeof o==`string`)throw Error(`Input "${i.name}": ${o}`);let s=o===void 0||Gi(o,r)===!0;s&&n.add(i.name),r[i.name]=s?t[i.name]??null:null}),n},to=(e,t=[])=>Object.entries(e).flatMap(([e,n])=>{let r=typeof n==`string`?Vn(n):void 0;if(r===void 0)return[];let i=t.find(e=>e.name===r);return i?i.kind===`secret`?[`set "${e}" names secret input "${r}", which an update never writes; take it in an action's handler`]:[]:[`set "${e}" names input "${r}", which it does not ask for`]}),no=(e,t)=>Object.fromEntries(Object.entries(e).flatMap(([e,n])=>{let r=typeof n==`string`?Vn(n):void 0;return r===void 0?[[e,n]]:Object.hasOwn(t,r)?[[e,t[r]]]:[]})),ro=e=>e.when===void 0?e.otherwise!==void 0||e.reason!==void 0?`"otherwise" and "reason" need a "when" condition`:void 0:e.when.trim()===``?`"when" is empty`:e.otherwise===`disable`?e.reason?void 0:`a button disabled by "when" needs a "reason"`:e.reason===void 0?void 0:`"reason" shows only with otherwise: 'disable'`,io=(e,t)=>{let n=ro(t);if(n)throw Error(`Action "${e}": ${n}`);return{name:e,label:t.label,bulk:t.bulk??!1,...t.icon!==void 0&&{icon:t.icon},...t.confirm!==void 0&&{confirm:t.confirm},...t.when!==void 0&&{when:t.when},...t.otherwise===`disable`&&{otherwise:t.otherwise,reason:t.reason},...t.variant!==void 0&&{variant:t.variant}}},ao=(e,t)=>{if(!t)return{};let n=t(qa),r=$a(n);if(r.length>0)throw Error(`Action "${e}": ${r.join(`; `)}`);return{inputs:n}},oo={action:(e,t)=>({...io(e,t),...ao(e,t.inputs),...t.mailbox&&{mailbox:!0}}),update:(e,t)=>{let n=ao(e,t.inputs),r=to(t.set,n.inputs);if(r.length>0)throw Error(`Action "${e}": ${r.join(`; `)}`);return{...io(e,t),...n,run:{kind:`update`,values:t.set}}},remove:(e,t)=>({...io(e,t),run:{kind:`delete`}}),link:(e,t)=>{let n=Rr(t.label,t);if(n)throw Error(`Action "${e}": ${n}`);return`to`in t?{...io(e,t),run:{kind:`link`,to:structuredClone(t.to)}}:{...io(e,t),run:{kind:`link`,href:t.href}}},ai:(e,t)=>{let n=fa(t.prompt)??(t.writes===``?`it writes no field`:void 0);if(n)throw Error(`Action "${e}": ${n}`);return{...io(e,t),run:{kind:`ai`,prompt:t.prompt,writes:t.writes}}}},so=10,co=e=>{if(!(`groupBy`in e))return{field:e.field.name,range:e.range,granularity:e.granularity};if(e.sum&&e.average)throw Error(`A chart takes sum or average, not both`);let t=e.limit??so;if(!Number.isInteger(t)||t<1)throw Error(`A chart's limit must be a positive whole number, not ${t}`);return{groupBy:e.groupBy.name,type:e.type??`bar`,...e.sum&&{sum:e.sum.name},...e.average&&{average:e.average.name},limit:t}},lo=e=>`groupBy`in e,uo=e=>{let{name:t,title:n,fields:r,thanks:i}=e;if(!La.test(t))throw Error(`A form's name goes in its address, so it takes lowercase letters, digits, - and _, not "${t}"`);if(r.length===0)throw Error(`Form "${t}" has no fields`);let a=r.map(e=>e.name),o=a.find((e,t)=>a.indexOf(e)!==t);if(o!==void 0)throw Error(`Form "${t}" lists the field "${o}" twice`);if(i.trim()===``)throw Error(`Form "${t}" needs a thanks text, shown once a visitor sends it`);if(n!==void 0&&n.trim()===``)throw Error(`Form "${t}" has an empty title; leave it out for the view's name`);let s=e.perMinute??5;if(!Number.isInteger(s)||s<1)throw Error(`Form "${t}" takes perMinute as a positive whole number, not ${s}`);return{name:t,...n!==void 0&&{title:n},fields:a,thanks:i,perMinute:s}},fo=e=>typeof e==`object`&&!!e&&e.kind===`related`,po={related:(e,t)=>({kind:`related`,name:e,...structuredClone(t)})},mo=/^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i,ho=/^[A-Z]{3}$/,go=class e{name;props;constructor(e,t={}){this.name=e,this.props=t}label(e){return this.with({label:e})}help(e,t={}){return this.with({help:e,...t.when!==void 0&&{helpWhen:t.when}})}when(e){return this.with({when:e})}notOnCreate(){return this.with({notOnCreate:!0})}confirm(e){if(e.trim()===``)throw Error(`Field "${this.name}": .confirm() needs the question to ask`);return this.with({confirm:e})}format(t,n={}){if(n.text===void 0&&t===`url`)return this.with({format:t});if(n.text===void 0){let{linkText:n,...r}=this.props;return new e(this.name,{...r,format:t})}if(t!==`url`)throw Error(`Field "${this.name}": only format('url') takes a link text`);if(n.text.trim()===``)throw Error(`Field "${this.name}": format('url') needs a link text that is not empty`);return this.with({format:t,linkText:n.text})}multiline(){return this.with({multiline:!0})}markdown(){return this.with({markdown:!0})}prefix(e){return this.with({prefix:e})}currency(e){if(!ho.test(e))throw Error(`Field "${this.name}": currency "${e}" is not an ISO 4217 code such as EUR`);return this.with({currency:e})}suffix(e){return this.with({suffix:e})}decimals(e){return this.with({decimals:e})}valueLabels(e){return this.with({valueLabels:{...this.props.valueLabels,...e}})}valueColors(e){let t=Object.entries(e),n=t.find(([,e])=>!Yr(e)&&!mo.test(e));if(n)throw Error(`Field "${this.name}": value colour "${n[1]}" of "${n[0]}" is not a tone (${Qr.join(`, `)}) or a hex colour such as #00a651`);return this.with({valueColors:{...this.props.valueColors,...Object.fromEntries(t)}})}waitingValues(e){return this.with({waitingValues:[...e]})}badgeShape(e){return this.with({badgeShape:e})}icon(e){return this.with({icon:e})}widget(e,t){return this.with({widget:{name:e,...t&&{props:t}}})}with(t){return new e(this.name,{...this.props,...t})}},_o={range:(e,t={})=>({kind:`range`,field:e.name,histogram:t.histogram??!1,...t.secondary&&{secondary:!0}}),facets:(e,t={})=>({kind:`facets`,field:e.name,search:t.search??!1,...t.secondary&&{secondary:!0}}),dateRange:(e,t={})=>({kind:`dateRange`,field:e.name,presets:t.presets??[],...t.secondary&&{secondary:!0}}),toggle:(e,t={})=>({kind:`toggle`,field:e.name,...t.secondary&&{secondary:!0}}),flags:(e,t)=>({kind:`flags`,fields:e.map(e=>e.name),label:t.label,...t.secondary&&{secondary:!0}})},vo=new Set([`resource`,`names`,`nav`,`help`,`list`,`filters`,`chart`]),yo=(e,t)=>{let n=(e,n,r)=>n===void 0||t.fields[n]?.type===r?[]:[`${e} "${n}" is not a ${r} field of the resource`];return[...n(`filter`,e.filter,`text`),...n(`name`,e.name,`text`),...n(`unseen.seenAt`,e.unseen?.seenAt,`timestamp`),...(e.controls??[]).flatMap(e=>[`enum`,`boolean`].includes(t.fields[e]?.type??``)?[]:[`control "${e}" is not an enum or boolean field of the resource`]),...e.limit===void 0||Number.isInteger(e.limit)&&e.limit>0?[]:[`limit must be a positive whole number`]]},bo=class e{state;constructor(e){this.state=e}names(e){return this.next({names:e})}icon(e){return this.next({icon:e})}forRoles(e){return this.next({roles:e})}title(e){return this.next({title:e(this.refs()).name})}titleFrom(e,t){let n=t(this.refs()).map(e=>e.name);if(e===``)throw Error(`View "${this.state.resource}": titleFrom needs the name of a rule`);if(n.length===0)throw Error(`View "${this.state.resource}": titleFrom "${e}" reads no fields`);return this.next({titleFrom:{rule:e,fields:n}})}searchResult(e){let{title:t,subtitle:n}=e(this.refs()),r=t===void 0?[]:Array.isArray(t)?t:[t];return this.next({searchResult:{...r.length>0&&{title:r.map(e=>e.name)},...n&&{subtitle:n.name}}})}nav(e){return this.next({nav:e})}help(e){return this.next({help:e})}fields(e){let t=e(Xe(e=>new go(e))),n=Object.fromEntries(Object.values(t).map(e=>[e.name,e.props]));return this.next({fields:{...this.state.fields,...n}})}list(e){let{columns:t,sort:n,search:r,filter:i,editable:a,displays:o=[],default:s,drag:c}=e(this.refs(),Qe,po),l=t.filter(fo).map(({kind:e,...t})=>t),u=t.map(e=>e.name),d=u.find((e,t)=>u.indexOf(e)!==t);if(d!==void 0)throw Error(`View "${this.state.resource}": the list has two columns named "${d}"`);let f=a?.find(e=>!u.includes(e.name));if(f)throw Error(`View "${this.state.resource}": editable field "${f.name}" is not among the list's columns`);let p={columns:u,...l.length>0&&{relatedColumns:l},...n&&{sort:n.map(([e,t])=>[e.name,t])},...r&&{search:r.map(e=>e.name)},...i!==void 0&&i!==``&&{filter:i},...a&&a.length>0&&{editable:a.map(e=>e.name)},...o.length>0&&{displays:o},...s!==void 0&&{default:s},...c&&{drag:{...c}}},m=et(p);if(m.length>0)throw Error(`View "${this.state.resource}": ${m.join(`; `)}`);return this.next({list:p})}filters(e){return this.next({filters:e(this.refs(),_o)})}namedList(e,t){let n=`View "${this.state.resource}": named list "${e}"`;if(!La.test(e))throw Error(`${n}: its name goes in its address, so it takes lowercase letters, digits, - and _`);if(this.state.lists?.some(t=>t.name===e))throw Error(`${n} is declared twice`);let r=xo(this.state.resource),{state:i}=t(r),a=Object.keys(i).filter(e=>!vo.has(e)&&i[e]!==r.state[e]);if(a.length>0)throw Error(`${n} sets ${a.join(`, `)}; a named list takes names, nav, help, list, filters and chart`);if(!i.names)throw Error(`${n} needs .names(...), its sidebar entry`);if(i.nav?.recent)throw Error(`${n}: recent records are the view's own, not a named list's`);let o={name:e,names:i.names,filters:i.filters,...i.nav&&{nav:i.nav},...i.help!==void 0&&{help:i.help},...i.list&&{list:i.list},...i.chart&&{chart:i.chart}};return this.next({lists:[...this.state.lists??[],o]})}layout(e){return this.next({layout:e(this.refs())})}chart(e){return this.next({chart:co(e(this.refs()))})}form(e){return this.next({forms:[...this.state.forms??[],uo(e(this.refs()))]})}recordMode(e){return this.next({recordMode:e})}helpWhen(e){return this.next({helpWhen:e})}saveFeedback(e){return this.next({saveFeedback:e})}recordWidth(e){return this.next({recordWidth:e})}titleBadge(e){return this.next({titleBadge:e(this.refs()).name})}import(e){return this.next({import:e})}actions(e){return this.next({actions:e(oo)})}listOf(e){return this.next({listOf:e(this.refs()).name})}signIn(e){if(e.signUp&&!Ba(e.signUp.href))throw Error(`View "${this.state.resource}": signIn signUp.href must start with https://, http:// or mailto:`);return this.next({signIn:structuredClone(e)})}saveSearch(e){return this.next({saveSearch:{...e}})}export(e){if(e&&e.maxRows!==void 0&&!(Number.isInteger(e.maxRows)&&e.maxRows>0))throw Error(`View "${this.state.resource}": export maxRows must be a positive whole number`);return this.next({export:e&&{...e}})}create(e){return this.next({create:{...e}})}record(e){let t=typeof e==`function`?{surface:e(this.refs()).surface.name}:{component:se(e.component,`record component`),...e.focus&&{focus:!0}};return this.next({record:t})}recordOpens(e){return this.next({recordOpens:structuredClone(e)})}createOpens(e){return this.next({createOpens:structuredClone(e)})}searchesOf(e){let{resource:t,filter:n,name:r,controls:i,unseen:a,limit:o}=e(this.refs()),s={resource:t,filter:n.name,...r&&{name:r.name},...i&&{controls:i.map(e=>e.name)},...a&&{unseen:{seenAt:a.seenAt.name,field:a.field}},...o!==void 0&&{limit:o}};return this.next({searchesOf:s})}toModel(t){let{title:n,titleFrom:r,titleBadge:i,nav:a,searchResult:o,list:s,listOf:c}=this.state;if(t&&n!==void 0&&!Object.hasOwn(t.fields,n))throw Error(`View "${this.state.resource}": title field "${n}" does not exist on the resource`);if(t&&i!==void 0&&!Object.hasOwn(t.fields,i))throw Error(`View "${this.state.resource}": title badge field "${i}" does not exist on the resource`);if(t&&i!==void 0&&t.fields[i].type!==`enum`&&this.state.fields[i]?.format!==`badge`)throw Error(`View "${this.state.resource}": title badge field "${i}" is no enum and has no .format('badge'), so it would not fit a badge`);let l=t?r?.fields.find(e=>!Object.hasOwn(t.fields,e)):void 0;if(l!==void 0)throw Error(`View "${this.state.resource}": titleFrom field "${l}" does not exist on the resource`);let u=t?[...o?.title??[],...o?.subtitle?[o.subtitle]:[]].filter(e=>!Object.hasOwn(t.fields,e)):[];if(u.length>0)throw Error(`View "${this.state.resource}": search result field "${u[0]}" does not exist on the resource`);for(let e of t?s?.displays??[]:[]){let n=de(e).find(e=>!Object.hasOwn(t.fields,e));if(n!==void 0)throw Error(`View "${this.state.resource}": display "${e.name}" names field "${n}", which the resource does not have`);if(e.kind===`cards`&&e.image!==void 0&&t.fields[e.image].type!==`file`)throw Error(`View "${this.state.resource}": display "${e.name}" shows "${e.image}" as its image, which is not a file field`);let r=e.kind===`cards`?e.flags?.find(e=>t.fields[e].type!==`boolean`):void 0;if(r!==void 0)throw Error(`View "${this.state.resource}": display "${e.name}" shows "${r}" as a flag, which is not a boolean field`);let i=e.kind===`board`?be(e,t):[];if(i.length>0)throw Error(`View "${this.state.resource}": display "${e.name}": ${i.join(`; `)}`);let a=e.kind===`calendar`||e.kind===`timeline`?Je(e,t):[];if(a.length>0)throw Error(`View "${this.state.resource}": display "${e.name}": ${a.join(`; `)}`)}let d=t?s?.relatedColumns?.find(e=>Object.hasOwn(t.fields,e.name)):void 0;if(d)throw Error(`View "${this.state.resource}": related column "${d.name}" has the name of a field of the resource`);let f=new Set,p=this.state.layout.flatMap((e,t)=>e.kind===`tab`?[{item:e,index:t}]:[]),m=p.find((e,t)=>t>0&&e.index!==p[t-1].index+1);if(m)throw Error(`View "${this.state.resource}": tabs stand together, and "${m.item.title}" is apart from the others`);let h=new Set;for(let{item:e}of p){if(h.has(e.title))throw Error(`View "${this.state.resource}": two tabs are titled "${e.title}"`);h.add(e.title)}for(let e of this.state.layout.flatMap(e=>e.kind===`tab`?e.items:[e]))if(e.kind===`group`){if(f.has(e.title))throw Error(`View "${this.state.resource}": two groups are titled "${e.title}"`);f.add(e.title)}for(let e of t?za(this.state.layout):[])if(e.kind===`gallery`&&e.image!==void 0){if(!Object.hasOwn(t.fields,e.image))throw Error(`View "${this.state.resource}": gallery "${e.title}" names field "${e.image}", which the resource does not have`);if(t.fields[e.image].type!==`file`)throw Error(`View "${this.state.resource}": gallery "${e.title}" shows "${e.image}" as its image, which is not a file field`)}if(t&&c!==void 0&&(!Object.hasOwn(t.fields,c)||t.fields[c].type!==`relation`))throw Error(`View "${this.state.resource}": listOf names "${c}", which is not a relation field of the resource`);let g=t&&this.state.searchesOf?yo(this.state.searchesOf,t):[];if(g.length>0)throw Error(`View "${this.state.resource}": searchesOf ${g.join(`; `)}`);for(let e of t?this.state.forms??[]:[]){let n=e.fields.find(e=>!Object.hasOwn(t.fields,e));if(n!==void 0)throw Error(`View "${this.state.resource}": form "${e.name}" names field "${n}", which the resource does not have`)}if(a?.tenant===`current`&&!s)throw Error(`View "${this.state.resource}": nav.tenant narrows the opening filter of the list, so the view needs .list(...)`);let _=t?.tenant===void 0?void 0:t.fields[t.tenant];if(t&&a?.tenant===`current`&&!_?.filterable)throw Error(`View "${this.state.resource}": nav.tenant opens the list on the current tenant, so the resource needs .tenant() on a .filterable() field`);if(typeof a?.create==`object`&&a.create.label.trim()===``)throw Error(`View "${this.state.resource}": nav.create needs a label, or true for "New <singular>"`);let v=t&&a?.recent?Ga(a.recent,t):[];if(v.length>0)throw Error(`View "${this.state.resource}": nav.recent ${v.join(`; `)}`);let y=t&&this.state.recordOpens?sr(this.state.recordOpens).find(e=>!Object.hasOwn(t.fields,e)):void 0;if(y!==void 0)throw Error(`View "${this.state.resource}": recordOpens names field "${y}", which the resource does not have`);if(this.state.lists?.length&&(c!==void 0||this.state.searchesOf))throw Error(`View "${this.state.resource}": named lists cannot go with listOf or searchesOf, which replace the list page`);for(let n of this.state.lists??[])new e(Se(this.state,n.name)).toModel(t);return structuredClone(this.state)}refs(){return Xe(te)}next(t){return new e({...this.state,...t})}},xo=e=>new bo({resource:e,fields:{},filters:[],layout:[],actions:[]}),So=[`failing`,`unresolved`,`healthy`,`no_runs`,`resolved`,`new_version`],Co={failing:`danger`,unresolved:`warning`,healthy:`success`},wo=[`failing`,`unresolved`],To={read:e=>e.holds?.(`workflow_runs.read`)??!1};Ia.enum(So).readOnly().dbDefault().access(To),Ia.relation(`workflow_runs`).optional().readOnly().access(To),Ia.timestamp().optional().readOnly().access(To),Ia.integer().readOnly().dbDefault().access(To),Ia.timestamp().optional().readOnly(),Ia.text().optional().readOnly(),xo(`workflow_resolutions`).names({singular:`Workflow resolution`,plural:`Workflow resolutions`}).icon(`check`).nav({hidden:!0}).title(e=>e.resolved_at).fields(e=>({workflow_id:e.workflow_id.label(`Workflow`),resolved_by:e.resolved_by.label(`Resolved by`),resolved_at:e.resolved_at.label(`Resolved`)})).list(e=>({columns:[e.workflow_id,e.resolved_by,e.resolved_at],sort:[[e.resolved_at,`desc`]]}));var Eo=e(Yt(),1),Do=e=>{try{return new Eo.default.Comparator(e),!0}catch(e){if(e instanceof TypeError)return!1;throw e}},Oo=(e,t)=>{let n=t.trim().split(/\s+/);if(Eo.default.valid(e)!==null&&t.trim()!==``&&n.every(Do))return Eo.default.satisfies(e,t,{includePrerelease:!0})},ko=(e,t)=>{if(e.api!==t.api)return`it is built for plugin API ${e.api}, and this app has plugin API ${t.api}`;let n=Oo(t.version,e.protobase);if(n===void 0)return`its Protobase range "${e.protobase}" is not one this app reads, such as >=0.12.0`;if(!n)return`it needs Protobase ${e.protobase}, and this app runs ${t.version}`},Ao=`[Filtered]`,jo=/authorization|cookie|passw|secret|token|api[-_]?key|credential|session|csrf|signature|^sig$/i,Mo=new Set([`url`,`query_string`,`from`,`to`]),No=12,Po=e=>e.replace(/(^|&)([^=&]*)=([^&]*)/g,(e,t,n)=>jo.test(n)?`${t}${n}=${Ao}`:e),Fo=e=>{let t=e.indexOf(`?`);if(t===-1)return e;let n=e.indexOf(`#`,t),r=n===-1?e.slice(t+1):e.slice(t+1,n);return`${e.slice(0,t+1)}${Po(r)}${n===-1?``:e.slice(n)}`},Io=(e,t,n)=>jo.test(e)?Ao:typeof t==`string`&&Mo.has(e)?e===`query_string`?Po(t):Fo(t):Lo(t,n+1),Lo=(e,t)=>t>No||typeof e!=`object`||!e?e:Array.isArray(e)?e.map(e=>Array.isArray(e)&&e.length===2&&typeof e[0]==`string`?[e[0],Io(e[0],e[1],t)]:Lo(e,t+1)):Object.fromEntries(Object.entries(e).map(([e,n])=>[e,Io(e,n,t)])),Ro=e=>Lo(e,0),zo=`protobase-app`,Bo={messages:[],replying:!1},Vo=(e,t)=>{let n=e.findIndex(e=>e.id===t.id);return n===-1?[...e,t]:e.map((e,r)=>r===n?t:e)},Ho=(e,t,n)=>{let r=e.find(e=>e.id===t);return Vo(e,r?{...r,parts:Vo(r.parts,n)}:{id:t,from:`assistant`,parts:[n]})},Uo=(e,t)=>{switch(t.type){case`state`:return t.state;case`message`:return{...e,messages:Vo(e.messages,t.message)};case`part`:return{...e,messages:Ho(e.messages,t.messageId,t.part)};case`patch`:{let{replying:n=e.replying,status:r=e.status,placeholder:i=e.placeholder}=t;return{messages:e.messages,replying:n,...r!=null&&{status:r},...i!=null&&{placeholder:i}}}}},Wo={fingerprint:`fingerprint`,shellVersion:`shell_version`},Go=`/api/mobile/release`,Ko=`/api/mobile/releases`,qo=({fingerprint:e,shellVersion:t})=>new URLSearchParams({[Wo.fingerprint]:e,[Wo.shellVersion]:t}).toString(),Jo=`/api/auth`,Yo=`second-step`,Xo={ios:`capacitor://localhost`,android:`https://localhost`},Zo={database:`protobase-push`,store:`registration`,key:`current`},Qo=`protobase.sw.js`,$o=/^[^\s\u0000-\u001f\u007f-\u009f]+$/,es=e=>{if(typeof e!=`string`||e.length>2048||!$o.test(e)||!URL.canParse(e))return;let t=new URL(e);if(t.protocol===`https:`||t.protocol===`http:`)return t.href},ts={json:[`json`],members:[`json`],workflow:[`json`],workflow_run:[`uuid`],workflow_status:[`enum`],custom_step_container:[`json`],runner_install:[`uuid`]},ns=new Set(`all.analyse.analyze.and.any.array.as.asc.asymmetric.both.case.cast.check.collate.column.constraint.create.current_catalog.current_date.current_role.current_time.current_timestamp.current_user.default.deferrable.desc.distinct.do.else.end.except.false.fetch.for.foreign.from.grant.group.having.in.initially.intersect.into.lateral.leading.limit.localtime.localtimestamp.not.null.offset.on.only.or.order.placing.primary.references.returning.select.session_user.some.symmetric.system_user.table.then.to.trailing.true.union.unique.user.using.variadic.when.where.window.with`.split(`.`)),rs=/^[a-z][a-z0-9_]*$/,is=[`id`,`etag`,`organization_id`],as=e=>rs.test(e)&&new TextEncoder().encode(e).length<=63,os=(e,t,n=63)=>{if(typeof e!=`string`||!as(e)||new TextEncoder().encode(e).length>n)return`form`;if(ns.has(e))return`reserved_word`;if(t===`field`&&is.includes(e))return`reserved_field`},ss=e=>typeof e==`number`&&Number.isInteger(e),cs=(e,t,n)=>{let r=0;for(;r<t&&ss(e[r])&&(r===0||e[r]>e[r-1]);)r+=1;let i=e.length;for(;i-1>n&&ss(e[i-1])&&(i===e.length||e[i-1]<e[i]);)--i;let a=Math.min(t,r),o=a===0?1:e[a-1]+1,s=Math.max(n,i-1);for(;s+1<e.length&&e[s+1]<=o+(s-a);)s+=1;return{first:a,last:s,start:o}},W=e(t(),1),ls=e(n(),1),us={name:`@protobase/ui`,version:`0.112.2`,description:`The Protobase admin app and the React hooks and components for custom UI.`,license:`Apache-2.0`,repository:{type:`git`,url:`git+https://github.com/PrototeamHQ/protobase.git`,directory:`packages/ui`},homepage:`https://docs.protobase.net`,type:`module`,protobase:{pluginApi:1},sideEffects:[`*.css`,`./dist/app/main.js`],engines:{node:`>=22.12.0`},exports:{".":`./src/index.ts`,"./theme.css":`./src/theme.css`,"./styles.css":`./src/styles.css`,"./unstable/*":{types:[`./src/*.ts`,`./src/*.tsx`],default:`./src/*`}},types:`./src/index.ts`,files:[`dist`],scripts:{build:`tsdown && protobase build-shell dist/shell --source-maps dist/shell-source-maps`,prepack:`tsdown && protobase build-shell dist/shell --source-maps dist/shell-source-maps`},publishConfig:{access:`public`,exports:{".":`./dist/index.js`,"./theme.css":`./dist/theme.css`,"./styles.css":`./dist/styles.css`,"./unstable/*":`./dist/*.js`},types:`./dist/index.d.ts`},dependencies:{"@dnd-kit/core":`^6.3.1`,"@dnd-kit/sortable":`^10.0.0`,"@protobase/client":`workspace:*`,"@protobase/layout":`workspace:*`,"@protobase/schema":`workspace:*`,"@protobase/workflows":`workspace:*`,"@sentry/browser":`^11.7.0`,"@tanstack/react-query":`^5.104.1`,"@tanstack/react-table":`^9.2.6`,"@xyflow/react":`^12.12.1`,"altcha-lib":`^2.6.0`,dompurify:`^3.4.17`,elkjs:`0.12.1`,fflate:`^0.8.3`,"intl-messageformat":`^12.1.4`,"lucide-react":`^1.52.0`,"maplibre-gl":`^6.14.0`,marked:`^18.1.1`,papaparse:`^5.7.0`,pmtiles:`^4.5.0`,react:`^19.3.0`,"react-dom":`^19.3.0`,"react-map-gl":`^8.1.3`,recharts:`^3.10.1`,tailwindcss:`^4.3.3`,thumbhash:`^0.1.1`,uqr:`^0.1.3`},devDependencies:{"@types/papaparse":`^5.5.2`}},ds=us.protobase.pluginApi,fs=us.version,ps=`session`,ms=`queries`,hs=e=>`user:${e.user.id}`,gs=async(e,t)=>{let[n,r]=await Promise.all([e.read(ps),e.read(ms)]),i=n?.buster===t?n.value:void 0,a=r?.buster===t&&i&&r.value.owner===hs(i)?r.value:void 0,o=[...n&&!i?[ps]:[],...r&&!a?[ms]:[]];return o.length>0&&await e.remove(o),{session:()=>i,queries:e=>a?.owner===e?a:void 0,saveSession:n=>(a&&a.owner!==hs(n)&&(a=void 0),i=n,e.write(ps,{buster:t,value:n})),saveQueries:n=>(a=n,e.write(ms,{buster:t,value:n})),clear:()=>(i=void 0,a=void 0,e.remove([ps,ms]))}},_s=(0,W.createContext)(void 0),vs=_s.Provider,ys=()=>(0,W.useContext)(_s),bs=`protobase.liveUpdate.page`,xs=e=>typeof e==`string`&&e.startsWith(`/`)&&!e.startsWith(`//`),Ss=(e,t,n)=>{let r=n.state,i=typeof r?.protobaseEntry==`string`?r.protobaseEntry:void 0;e.setItem(bs,JSON.stringify({url:`${t.pathname}${t.search}${t.hash}`,entry:i}))},Cs=e=>e.removeItem(bs),ws=e=>e.getItem(bs)!==null,Ts=(e,t)=>{let n=e.getItem(bs);if(n===null)return;Cs(e);let r;try{r=JSON.parse(n)}catch(e){if(e instanceof SyntaxError)return;throw e}if(typeof r!=`object`||!r)return;let{url:i,entry:a}=r;xs(i)&&t.replaceState(typeof a==`string`?{protobaseEntry:a}:null,``,i)},Es=()=>{let e=i(()=>window.sessionStorage,void 0);return e&&{keep:()=>Ss(e,window.location,window.history),forget:()=>Cs(e)}},Ds={name:`archive`,size:24,node:[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8`,key:`1s80jp`}],[`path`,{d:`M10 12h4`,key:`a56b0p`}]]};Ds.node;var Os=V(Ds),ks={name:`arrow-down`,size:24,node:[[`path`,{d:`M12 5v14`,key:`s699le`}],[`path`,{d:`m19 12-7 7-7-7`,key:`1idqje`}]]};ks.node;var As=V(ks),js={name:`arrow-left`,size:24,node:[[`path`,{d:`m12 19-7-7 7-7`,key:`1l729n`}],[`path`,{d:`M19 12H5`,key:`x3x0zl`}]]};js.node;var Ms=V(js),Ns={name:`arrow-right-left`,size:24,node:[[`path`,{d:`m16 3 4 4-4 4`,key:`1x1c3m`}],[`path`,{d:`M20 7H4`,key:`zbl0bi`}],[`path`,{d:`m8 21-4-4 4-4`,key:`h9nckh`}],[`path`,{d:`M4 17h16`,key:`g4d7ey`}]]};Ns.node;var Ps=V(Ns),Fs={name:`arrow-right`,size:24,node:[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`m12 5 7 7-7 7`,key:`xquz4c`}]]};Fs.node;var Is=V(Fs),Ls={name:`arrow-up-down`,size:24,node:[[`path`,{d:`m21 16-4 4-4-4`,key:`f6ql7i`}],[`path`,{d:`M17 20V4`,key:`1ejh1v`}],[`path`,{d:`m3 8 4-4 4 4`,key:`11wl7u`}],[`path`,{d:`M7 4v16`,key:`1glfcx`}]]};Ls.node;var Rs=V(Ls),zs={name:`arrow-up-right`,size:24,node:[[`path`,{d:`M7 7h10v10`,key:`1tivn9`}],[`path`,{d:`M7 17 17 7`,key:`1vkiza`}]]};zs.node;var Bs=V(zs),Vs={name:`arrow-up`,size:24,node:[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]};Vs.node;var Hs=V(Vs),Us={name:`at-sign`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`4`,key:`4exip2`}],[`path`,{d:`M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-4 8`,key:`7n84p3`}]]};Us.node;var Ws=V(Us),Gs={name:`ban`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M4.929 4.929 19.07 19.071`,key:`196cmz`}]]};Gs.node;var Ks=V(Gs),qs={name:`bath`,size:24,node:[[`path`,{d:`M10 4 8 6`,key:`1rru8s`}],[`path`,{d:`M17 19v2`,key:`ts1sot`}],[`path`,{d:`M2 12h20`,key:`9i4pu4`}],[`path`,{d:`M7 19v2`,key:`12npes`}],[`path`,{d:`M9 5 7.621 3.621A2.121 2.121 0 0 0 4 5v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-5`,key:`14ym8i`}]]};qs.node;var Js=V(qs),Ys={name:`bed`,size:24,node:[[`path`,{d:`M2 4v16`,key:`vw9hq8`}],[`path`,{d:`M2 8h18a2 2 0 0 1 2 2v10`,key:`1dgv2r`}],[`path`,{d:`M2 17h20`,key:`18nfp3`}],[`path`,{d:`M6 8v9`,key:`1yriud`}]]};Ys.node;var Xs=V(Ys),Zs={name:`bell-off`,size:24,node:[[`path`,{d:`M10.268 21a2 2 0 0 0 3.464 0`,key:`vwvbt9`}],[`path`,{d:`M17 17H4a1 1 0 0 1-.74-1.673C4.59 13.956 6 12.499 6 8a6 6 0 0 1 .258-1.742`,key:`178tsu`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M8.668 3.01A6 6 0 0 1 18 8c0 2.687.77 4.653 1.707 6.05`,key:`1hqiys`}]]};Zs.node;var Qs=V(Zs),$s={name:`bell-ring`,size:24,node:[[`path`,{d:`M10.268 21a2 2 0 0 0 3.464 0`,key:`vwvbt9`}],[`path`,{d:`M22 8c0-2.3-.8-4.3-2-6`,key:`5bb3ad`}],[`path`,{d:`M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326`,key:`11g9vi`}],[`path`,{d:`M4 2C2.8 3.7 2 5.7 2 8`,key:`tap9e0`}]]};$s.node;var ec=V($s),tc={name:`bell`,size:24,node:[[`path`,{d:`M10.268 21a2 2 0 0 0 3.464 0`,key:`vwvbt9`}],[`path`,{d:`M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326`,key:`11g9vi`}]]};tc.node;var nc=V(tc),rc={name:`book-open`,size:24,node:[[`path`,{d:`M12 5v16`,key:`1f6ucr`}],[`path`,{d:`M20.001 19A2 2 0 0022 17V5a2 2 0 00-1.999-2L16 3.002A5 5 0 0012 5a5 5 0 00-4-2H4a2 2 0 00-2 2v12a2 2 0 001.999 2H8a5 5 0 014 2 5 5 0 014-2z`,key:`1fyvmf`}]]};rc.node;var ic=V(rc),ac={name:`bookmark-check`,size:24,node:[[`path`,{d:`M17 3a2 2 0 0 1 2 2v15a1 1 0 0 1-1.496.868l-4.512-2.578a2 2 0 0 0-1.984 0l-4.512 2.578A1 1 0 0 1 5 20V5a2 2 0 0 1 2-2z`,key:`oz39mx`}],[`path`,{d:`m9 10 2 2 4-4`,key:`1gnqz4`}]]};ac.node;var oc=V(ac),sc={name:`bookmark-plus`,size:24,node:[[`path`,{d:`M12 7v6`,key:`lw1j43`}],[`path`,{d:`M15 10H9`,key:`o6yqo3`}],[`path`,{d:`M17 3a2 2 0 0 1 2 2v15a1 1 0 0 1-1.496.868l-4.512-2.578a2 2 0 0 0-1.984 0l-4.512 2.578A1 1 0 0 1 5 20V5a2 2 0 0 1 2-2z`,key:`oz39mx`}]]};sc.node;var cc=V(sc),lc={name:`bookmark`,size:24,node:[[`path`,{d:`M17 3a2 2 0 0 1 2 2v15a1 1 0 0 1-1.496.868l-4.512-2.578a2 2 0 0 0-1.984 0l-4.512 2.578A1 1 0 0 1 5 20V5a2 2 0 0 1 2-2z`,key:`oz39mx`}]]};lc.node;var uc=V(lc),dc={name:`bot`,size:24,node:[[`path`,{d:`M12 8V4H8`,key:`hb8ula`}],[`rect`,{width:`16`,height:`12`,x:`4`,y:`8`,rx:`2`,key:`enze0r`}],[`path`,{d:`M2 14h2`,key:`vft8re`}],[`path`,{d:`M20 14h2`,key:`4cs60a`}],[`path`,{d:`M15 13v2`,key:`1xurst`}],[`path`,{d:`M9 13v2`,key:`rq6x2g`}]]};dc.node;var fc=V(dc),pc={name:`building-complex`,size:24,node:[[`path`,{d:`M10 12h4`,key:`a56b0p`}],[`path`,{d:`M10 8h4`,key:`1sr2af`}],[`path`,{d:`M14 21v-3a2 2 0 0 0-4 0v3`,key:`1rgiei`}],[`path`,{d:`M6 10H4a2 2 0 0 0-2 2v7a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-2`,key:`secmi2`}],[`path`,{d:`M6 21V5a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v16`,key:`16ra0t`}]],aliases:[`building-2`]};pc.node;var mc=V(pc),hc={name:`calendar`,size:24,node:[[`path`,{d:`M8 2v3`,key:`1ioesn`}],[`path`,{d:`M16 2v3`,key:`otl347`}],[`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,key:`h1oib`}],[`path`,{d:`M3 9h18`,key:`1pudct`}]]};hc.node;var gc=V(hc),_c={name:`camera`,size:24,node:[[`path`,{d:`M13.997 4a2 2 0 0 1 1.76 1.05l.486.9A2 2 0 0 0 18.003 7H20a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V9a2 2 0 0 1 2-2h1.997a2 2 0 0 0 1.759-1.048l.489-.904A2 2 0 0 1 10.004 4z`,key:`18u6gg`}],[`circle`,{cx:`12`,cy:`13`,r:`3`,key:`1vg3eu`}]]};_c.node;var vc=V(_c),yc={name:`chart-gantt`,size:24,node:[[`path`,{d:`M10 6h8`,key:`zvc2xc`}],[`path`,{d:`M12 16h6`,key:`yi5mkt`}],[`path`,{d:`M3 3v16a2 2 0 0 0 2 2h16`,key:`c24i48`}],[`path`,{d:`M8 11h7`,key:`wz2hg0`}]]};yc.node;var bc=V(yc),xc={name:`chevron-down`,size:24,node:[[`path`,{d:`m6 9 6 6 6-6`,key:`qrunsl`}]]};xc.node;var Sc=V(xc),Cc={name:`chevron-left`,size:24,node:[[`path`,{d:`m15 18-6-6 6-6`,key:`1wnfg3`}]]};Cc.node;var wc=V(Cc),Tc={name:`chevrons-up-down`,size:24,node:[[`path`,{d:`m7 15 5 5 5-5`,key:`1hf1tw`}],[`path`,{d:`m7 9 5-5 5 5`,key:`sgt6xg`}]]};Tc.node;var Ec=V(Tc),Dc={name:`circle-arrow-up`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m16 12-4-4-4 4`,key:`177agl`}],[`path`,{d:`M12 16V8`,key:`1sbj14`}]],aliases:[`arrow-up-circle`]};Dc.node;var Oc=V(Dc),kc={name:`circle-check`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m16 9-5.5 5.5L8 12`,key:`xofnsj`}]],aliases:[`check-circle-2`]};kc.node;var Ac=V(kc),jc={name:`circle-dashed`,size:24,node:[[`path`,{d:`M10.1 2.182a10 10 0 0 1 3.8 0`,key:`5ilxe3`}],[`path`,{d:`M13.9 21.818a10 10 0 0 1-3.8 0`,key:`11zvb9`}],[`path`,{d:`M17.609 3.721a10 10 0 0 1 2.69 2.7`,key:`1iw5b2`}],[`path`,{d:`M2.182 13.9a10 10 0 0 1 0-3.8`,key:`c0bmvh`}],[`path`,{d:`M20.279 17.609a10 10 0 0 1-2.7 2.69`,key:`1ruxm7`}],[`path`,{d:`M21.818 10.1a10 10 0 0 1 0 3.8`,key:`qkgqxc`}],[`path`,{d:`M3.721 6.391a10 10 0 0 1 2.7-2.69`,key:`1mcia2`}],[`path`,{d:`M6.391 20.279a10 10 0 0 1-2.69-2.7`,key:`1fvljs`}]]};jc.node;var Mc=V(jc),Nc={name:`circle-minus`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M8 12h8`,key:`1wcyev`}]],aliases:[`minus-circle`]};Nc.node;var Pc=V(Nc),Fc={name:`circle-x`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m15 9-6 6`,key:`1uzhvr`}],[`path`,{d:`m9 9 6 6`,key:`z0biqf`}]],aliases:[`x-circle`]};Fc.node;var Ic=V(Fc),Lc={name:`circle`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]};Lc.node;var Rc=V(Lc),zc={name:`clock`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 6v6l4 2`,key:`mmk7yg`}]]};zc.node;var Bc=V(zc),Vc={name:`columns-3`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}]],aliases:[`panels-left-right`]};Vc.node;var Hc=V(Vc),Uc={name:`copy`,size:24,node:[[`rect`,{width:`14`,height:`14`,x:`8`,y:`8`,rx:`2`,ry:`2`,key:`17jyea`}],[`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`,key:`zix9uf`}]]};Uc.node;var Wc=V(Uc),Gc={name:`cpu`,size:24,node:[[`path`,{d:`M12 20v2`,key:`1lh1kg`}],[`path`,{d:`M12 2v2`,key:`tus03m`}],[`path`,{d:`M17 20v2`,key:`1rnc9c`}],[`path`,{d:`M17 2v2`,key:`11trls`}],[`path`,{d:`M2 12h2`,key:`1t8f8n`}],[`path`,{d:`M2 17h2`,key:`7oei6x`}],[`path`,{d:`M2 7h2`,key:`asdhe0`}],[`path`,{d:`M20 12h2`,key:`1q8mjw`}],[`path`,{d:`M20 17h2`,key:`1fpfkl`}],[`path`,{d:`M20 7h2`,key:`1o8tra`}],[`path`,{d:`M7 20v2`,key:`4gnj0m`}],[`path`,{d:`M7 2v2`,key:`1i4yhu`}],[`rect`,{x:`4`,y:`4`,width:`16`,height:`16`,rx:`2`,key:`1vbyd7`}],[`rect`,{x:`8`,y:`8`,width:`8`,height:`8`,rx:`1`,key:`z9xiuo`}]]};Gc.node;var Kc=V(Gc),qc={name:`credit-card`,size:24,node:[[`rect`,{width:`20`,height:`14`,x:`2`,y:`5`,rx:`2`,key:`ynyp8z`}],[`line`,{x1:`2`,x2:`22`,y1:`10`,y2:`10`,key:`1b3vmo`}],[`path`,{d:`M6 14h2`,key:`mk7k0u`}]]};qc.node;var Jc=V(qc),Yc={name:`door-open`,size:24,node:[[`path`,{d:`M10 21H2`,key:`1sthdo`}],[`path`,{d:`M10 3H7a2 2 0 00-2 2v16`,key:`15gt7x`}],[`path`,{d:`M14 12h.01`,key:`1jfl7z`}],[`path`,{d:`M19 21V5a2 2 0 00-1.675-1.974l-6.163-1.013A1 1 0 0010 3v18a1 1 0 001.124.992z`,key:`tyvg9a`}],[`path`,{d:`M22 21h-3`,key:`1ec3tr`}]]};Yc.node;var Xc=V(Yc),Zc={name:`download`,size:24,node:[[`path`,{d:`M12 15V3`,key:`m9g1x1`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}],[`path`,{d:`m7 10 5 5 5-5`,key:`brsn70`}]]};Zc.node;var Qc=V(Zc),$c={name:`earth`,size:24,node:[[`path`,{d:`M21.54 15H17a2 2 0 0 0-2 2v4.54`,key:`1djwo0`}],[`path`,{d:`M7 3.34V5a3 3 0 0 0 3 3a2 2 0 0 1 2 2c0 1.1.9 2 2 2a2 2 0 0 0 2-2c0-1.1.9-2 2-2h3.17`,key:`1tzkfa`}],[`path`,{d:`M11 21.95V18a2 2 0 0 0-2-2a2 2 0 0 1-2-2v-1a2 2 0 0 0-2-2H2.05`,key:`14pb5j`}],[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]],aliases:[`globe-2`]};$c.node;var el=V($c),tl={name:`ellipsis-vertical`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`12`,cy:`5`,r:`1`,key:`gxeob9`}],[`circle`,{cx:`12`,cy:`19`,r:`1`,key:`lyex9k`}]],aliases:[`more-vertical`]};tl.node;var nl=V(tl),rl={name:`ellipsis`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`19`,cy:`12`,r:`1`,key:`1wjl8i`}],[`circle`,{cx:`5`,cy:`12`,r:`1`,key:`1pcz8c`}]],aliases:[`more-horizontal`]};rl.node;var il=V(rl),al={name:`external-link`,size:24,node:[[`path`,{d:`M15 3h6v6`,key:`1q9fwt`}],[`path`,{d:`M10 14 21 3`,key:`gplh6r`}],[`path`,{d:`M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6`,key:`a6xqqp`}]]};al.node;var ol=V(al),sl={name:`eye-off`,size:24,node:[[`path`,{d:`M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49`,key:`ct8e1f`}],[`path`,{d:`M14.084 14.158a3 3 0 0 1-4.242-4.242`,key:`151rxh`}],[`path`,{d:`M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143`,key:`13bj9a`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]};sl.node;var cl=V(sl),ll={name:`eye`,size:24,node:[[`path`,{d:`M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0`,key:`1nclc0`}],[`circle`,{cx:`12`,cy:`12`,r:`3`,key:`1v7zrd`}]]};ll.node;var ul=V(ll),dl={name:`face-slightly-smiling-plus`,size:24,node:[[`path`,{d:`M13.267 2.08a10 10 0 108.653 8.653`,key:`1wbpyh`}],[`path`,{d:`M15 10V9`,key:`4dkmfx`}],[`path`,{d:`M16 5h6`,key:`1vod17`}],[`path`,{d:`M16.472 15a6 6 0 01-8.943 0`,key:`7qomzy`}],[`path`,{d:`M19 2v6`,key:`4bpg5p`}],[`path`,{d:`M9 10V9`,key:`1lazqi`}]],aliases:[`smile-plus`]};dl.node;var fl=V(dl),pl={name:`file-code-corner`,size:24,node:[[`path`,{d:`M4 12.15V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.706.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2h-3.35`,key:`1wthlu`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`m5 16-3 3 3 3`,key:`331omg`}],[`path`,{d:`m9 22 3-3-3-3`,key:`lsp7cz`}]],aliases:[`file-code-2`]};pl.node;var ml=V(pl),hl={name:`file-spreadsheet`,size:24,node:[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M8 13h2`,key:`yr2amv`}],[`path`,{d:`M14 13h2`,key:`un5t4a`}],[`path`,{d:`M8 17h2`,key:`2yhykz`}],[`path`,{d:`M14 17h2`,key:`10kma7`}]]};hl.node;var gl=V(hl),_l={name:`file-text`,size:24,node:[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M10 9H8`,key:`b1mrlr`}],[`path`,{d:`M16 13H8`,key:`t4e002`}],[`path`,{d:`M16 17H8`,key:`z1uh3a`}]]};_l.node;var vl=V(_l),yl={name:`grip-vertical`,size:24,node:[[`circle`,{cx:`9`,cy:`12`,r:`1`,key:`1vctgf`}],[`circle`,{cx:`9`,cy:`5`,r:`1`,key:`hp0tcf`}],[`circle`,{cx:`9`,cy:`19`,r:`1`,key:`fkjjf6`}],[`circle`,{cx:`15`,cy:`12`,r:`1`,key:`1tmaij`}],[`circle`,{cx:`15`,cy:`5`,r:`1`,key:`19l28e`}],[`circle`,{cx:`15`,cy:`19`,r:`1`,key:`f4zoj3`}]]};yl.node;var bl=V(yl),xl={name:`hard-drive`,size:24,node:[[`path`,{d:`M10 16h.01`,key:`1bzywj`}],[`path`,{d:`M2.212 11.577a2 2 0 0 0-.212.896V18a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-5.527a2 2 0 0 0-.212-.896L18.55 5.11A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z`,key:`18tbho`}],[`path`,{d:`M21.946 12.013H2.054`,key:`zqlbp7`}],[`path`,{d:`M6 16h.01`,key:`1pmjb7`}]]};xl.node;var Sl=V(xl),Cl={name:`heart`,size:24,node:[[`path`,{d:`M2 9.5a5.5 5.5 0 0 1 9.591-3.676.56.56 0 0 0 .818 0A5.49 5.49 0 0 1 22 9.5c0 2.29-1.5 4-3 5.5l-5.492 5.313a2 2 0 0 1-3 .019L5 15c-1.5-1.5-3-3.2-3-5.5`,key:`mvr1a0`}]]};Cl.node;var wl=V(Cl),Tl={name:`house`,size:24,node:[[`path`,{d:`M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8`,key:`5wwlr5`}],[`path`,{d:`M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z`,key:`r6nss1`}]],aliases:[`home`]};Tl.node;var El=V(Tl),Dl={name:`images`,size:24,node:[[`path`,{d:`m22 11-1.296-1.296a2.4 2.4 0 0 0-3.408 0L11 16`,key:`9kzy35`}],[`path`,{d:`M4 8a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2`,key:`1t0f0t`}],[`circle`,{cx:`13`,cy:`7`,r:`1`,fill:`currentColor`,key:`1obus6`}],[`rect`,{x:`8`,y:`2`,width:`14`,height:`14`,rx:`2`,key:`1gvhby`}]]};Dl.node;var Ol=V(Dl),kl={name:`info`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 16v-4`,key:`1dtifu`}],[`path`,{d:`M12 8h.01`,key:`e9boi3`}]]};kl.node;var Al=V(kl),jl={name:`key-round`,size:24,node:[[`path`,{d:`M2.586 17.414A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814a6.5 6.5 0 1 0-4-4z`,key:`1s6t7t`}],[`circle`,{cx:`16.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`w0ekpg`}]]};jl.node;var Ml=V(jl),Nl={name:`key-square`,size:24,node:[[`path`,{d:`M12.4 2.7a2.5 2.5 0 0 1 3.4 0l5.5 5.5a2.5 2.5 0 0 1 0 3.4l-3.7 3.7a2.5 2.5 0 0 1-3.4 0L8.7 9.8a2.5 2.5 0 0 1 0-3.4z`,key:`165ttr`}],[`path`,{d:`m14 7 3 3`,key:`1r5n42`}],[`path`,{d:`m9.4 10.6-6.814 6.814A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814`,key:`1ubxi2`}]]};Nl.node;var Pl=V(Nl),Fl={name:`land-plot`,size:24,node:[[`path`,{d:`m12 8 6-3-6-3v10`,key:`mvpnpy`}],[`path`,{d:`m8 11.99-5.5 3.14a1 1 0 0 0 0 1.74l8.5 4.86a2 2 0 0 0 2 0l8.5-4.86a1 1 0 0 0 0-1.74L16 12`,key:`ek95tt`}],[`path`,{d:`m6.49 12.85 11.02 6.3`,key:`1kt42w`}],[`path`,{d:`M17.51 12.85 6.5 19.15`,key:`v55bdg`}]]};Fl.node;var Il=V(Fl),Ll={name:`laptop`,size:24,node:[[`path`,{d:`M18 5a2 2 0 0 1 2 2v8.526a2 2 0 0 0 .212.897l1.068 2.127a1 1 0 0 1-.9 1.45H3.62a1 1 0 0 1-.9-1.45l1.068-2.127A2 2 0 0 0 4 15.526V7a2 2 0 0 1 2-2z`,key:`1pdavp`}],[`path`,{d:`M20.054 15.987H3.946`,key:`14rxg9`}]]};Ll.node;var Rl=V(Ll),zl={name:`layout-dashboard`,size:24,node:[[`rect`,{width:`7`,height:`9`,x:`3`,y:`3`,rx:`1`,key:`10lvy0`}],[`rect`,{width:`7`,height:`5`,x:`14`,y:`3`,rx:`1`,key:`16une8`}],[`rect`,{width:`7`,height:`9`,x:`14`,y:`12`,rx:`1`,key:`1hutg5`}],[`rect`,{width:`7`,height:`5`,x:`3`,y:`16`,rx:`1`,key:`ldoo1y`}]]};zl.node;var Bl=V(zl),Vl={name:`leaf`,size:24,node:[[`path`,{d:`M11 20a10 10 0 0010-10 25.9 25.9 0 00-1.04-7.281 1 1 0 00-1.755-.325C15.833 5.5 13 5.5 9.8 6.1A7 7 0 0011 20`,key:`1wjnjv`}],[`path`,{d:`M2 21a5 5 0 012.911-4.544C7.613 15.212 8.351 15.24 11 13`,key:`c1ejpn`}]]};Vl.node;var Hl=V(Vl),Ul={name:`life-buoy`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m4.93 4.93 4.24 4.24`,key:`1ymg45`}],[`path`,{d:`m14.83 9.17 4.24-4.24`,key:`1cb5xl`}],[`path`,{d:`m14.83 14.83 4.24 4.24`,key:`q42g0n`}],[`path`,{d:`m9.17 14.83-4.24 4.24`,key:`bqpfvv`}],[`circle`,{cx:`12`,cy:`12`,r:`4`,key:`4exip2`}]]};Ul.node;var Wl=V(Ul),Gl={name:`link-2`,size:24,node:[[`path`,{d:`M9 17H7A5 5 0 0 1 7 7h2`,key:`8i5ue5`}],[`path`,{d:`M15 7h2a5 5 0 1 1 0 10h-2`,key:`1b9ql8`}],[`line`,{x1:`8`,x2:`16`,y1:`12`,y2:`12`,key:`1jonct`}]]};Gl.node;var Kl=V(Gl),ql={name:`list-tree`,size:24,node:[[`path`,{d:`M8 5h13`,key:`1pao27`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}],[`path`,{d:`M3 10a2 2 0 0 0 2 2h3`,key:`1npucw`}],[`path`,{d:`M3 5v12a2 2 0 0 0 2 2h3`,key:`x1gjn2`}]]};ql.node;var Jl=V(ql),Yl={name:`list`,size:24,node:[[`path`,{d:`M3 5h.01`,key:`18ugdj`}],[`path`,{d:`M3 12h.01`,key:`nlz23k`}],[`path`,{d:`M3 19h.01`,key:`noohij`}],[`path`,{d:`M8 5h13`,key:`1pao27`}],[`path`,{d:`M8 12h13`,key:`1za7za`}],[`path`,{d:`M8 19h13`,key:`m83p4d`}]]};Yl.node;var Xl=V(Yl),Zl={name:`lock`,size:24,node:[[`rect`,{width:`18`,height:`11`,x:`3`,y:`11`,rx:`2`,ry:`2`,key:`1w4ew1`}],[`path`,{d:`M7 11V7a5 5 0 0 1 10 0v4`,key:`fwvmzm`}]]};Zl.node;var Ql=V(Zl),$l={name:`log-in`,size:24,node:[[`path`,{d:`m10 17 5-5-5-5`,key:`1bsop3`}],[`path`,{d:`M15 12H3`,key:`6jk70r`}],[`path`,{d:`M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4`,key:`u53s6r`}]]};$l.node;var eu=V($l),tu={name:`log-out`,size:24,node:[[`path`,{d:`m16 17 5-5-5-5`,key:`1bji2h`}],[`path`,{d:`M21 12H9`,key:`dn1m92`}],[`path`,{d:`M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4`,key:`1uf3rs`}]]};tu.node;var nu=V(tu),ru={name:`mail`,size:24,node:[[`path`,{d:`m22 7-8.991 5.727a2 2 0 0 1-2.009 0L2 7`,key:`132q7q`}],[`rect`,{x:`2`,y:`4`,width:`20`,height:`16`,rx:`2`,key:`izxlao`}]]};ru.node;var iu=V(ru),au={name:`map`,size:24,node:[[`path`,{d:`M14.106 5.553a2 2 0 0 0 1.788 0l3.659-1.83A1 1 0 0 1 21 4.619v12.764a1 1 0 0 1-.553.894l-4.553 2.277a2 2 0 0 1-1.788 0l-4.212-2.106a2 2 0 0 0-1.788 0l-3.659 1.83A1 1 0 0 1 3 19.381V6.618a1 1 0 0 1 .553-.894l4.553-2.277a2 2 0 0 1 1.788 0z`,key:`169xi5`}],[`path`,{d:`M15 5.764v15`,key:`1pn4in`}],[`path`,{d:`M9 3.236v15`,key:`1uimfh`}]]};au.node;var ou=V(au),su={name:`memory-stick`,size:24,node:[[`path`,{d:`M12 12v-2`,key:`fwoke6`}],[`path`,{d:`M12 18v-2`,key:`qj6yno`}],[`path`,{d:`M16 12v-2`,key:`heuere`}],[`path`,{d:`M16 18v-2`,key:`s1ct0w`}],[`path`,{d:`M2 11h1.5`,key:`15p63e`}],[`path`,{d:`M20 18v-2`,key:`12ehxp`}],[`path`,{d:`M20.5 11H22`,key:`khsy7a`}],[`path`,{d:`M4 18v-2`,key:`1c3oqr`}],[`path`,{d:`M8 12v-2`,key:`1mwtfd`}],[`path`,{d:`M8 18v-2`,key:`qcmpov`}],[`rect`,{x:`2`,y:`6`,width:`20`,height:`10`,rx:`2`,key:`1qcswk`}]]};su.node;var cu=V(su),lu={name:`menu`,size:24,node:[[`path`,{d:`M4 5h16`,key:`1tepv9`}],[`path`,{d:`M4 12h16`,key:`1lakjw`}],[`path`,{d:`M4 19h16`,key:`1djgab`}]]};lu.node;var uu=V(lu),du={name:`mic-off`,size:24,node:[[`path`,{d:`M12 19v3`,key:`npa21l`}],[`path`,{d:`M15 9.34V5a3 3 0 0 0-5.68-1.33`,key:`1gzdoj`}],[`path`,{d:`M16.95 16.95A7 7 0 0 1 5 12v-2`,key:`cqa7eg`}],[`path`,{d:`M18.89 13.23A7 7 0 0 0 19 12v-2`,key:`16hl24`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M9 9v3a3 3 0 0 0 5.12 2.12`,key:`r2i35w`}]]};du.node;var fu=V(du),pu={name:`mic`,size:24,node:[[`path`,{d:`M12 19v3`,key:`npa21l`}],[`path`,{d:`M19 10v2a7 7 0 0 1-14 0v-2`,key:`1vc78b`}],[`rect`,{x:`9`,y:`2`,width:`6`,height:`13`,rx:`3`,key:`s6n7sd`}]]};pu.node;var mu=V(pu),hu={name:`monitor-up`,size:24,node:[[`path`,{d:`m9 10 3-3 3 3`,key:`11gsxs`}],[`path`,{d:`M12 13V7`,key:`h0r20n`}],[`rect`,{width:`20`,height:`14`,x:`2`,y:`3`,rx:`2`,key:`48i651`}],[`path`,{d:`M12 17v4`,key:`1riwvh`}],[`path`,{d:`M8 21h8`,key:`1ev6f3`}]]};hu.node;var gu=V(hu),_u={name:`monitor-x`,size:24,node:[[`path`,{d:`m14.5 12.5-5-5`,key:`1jahn5`}],[`path`,{d:`m9.5 12.5 5-5`,key:`1k2t7b`}],[`rect`,{width:`20`,height:`14`,x:`2`,y:`3`,rx:`2`,key:`48i651`}],[`path`,{d:`M12 17v4`,key:`1riwvh`}],[`path`,{d:`M8 21h8`,key:`1ev6f3`}]]};_u.node;var vu=V(_u),yu={name:`monitor`,size:24,node:[[`rect`,{width:`20`,height:`14`,x:`2`,y:`3`,rx:`2`,key:`48i651`}],[`line`,{x1:`8`,x2:`16`,y1:`21`,y2:`21`,key:`1svkeh`}],[`line`,{x1:`12`,x2:`12`,y1:`17`,y2:`21`,key:`vw1qmm`}]]};yu.node;var bu=V(yu),xu={name:`moon`,size:24,node:[[`path`,{d:`M20.985 12.486a9 9 0 1 1-9.473-9.472c.405-.022.617.46.402.803a6 6 0 0 0 8.268 8.268c.344-.215.825-.004.803.401`,key:`kfwtm`}]]};xu.node;var Su=V(xu),Cu={name:`network`,size:24,node:[[`rect`,{x:`16`,y:`16`,width:`6`,height:`6`,rx:`1`,key:`4q2zg0`}],[`rect`,{x:`2`,y:`16`,width:`6`,height:`6`,rx:`1`,key:`8cvhb9`}],[`rect`,{x:`9`,y:`2`,width:`6`,height:`6`,rx:`1`,key:`1egb70`}],[`path`,{d:`M5 16v-3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v3`,key:`1jsf9p`}],[`path`,{d:`M12 12V8`,key:`2874zd`}]]};Cu.node;var wu=V(Cu),Tu={name:`package`,size:24,node:[[`path`,{d:`M11 21.73a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73z`,key:`1a0edw`}],[`path`,{d:`M12 22V12`,key:`d0xqtd`}],[`polyline`,{points:`3.29 7 12 12 20.71 7`,key:`ousv84`}],[`path`,{d:`m7.5 4.27 9 5.15`,key:`1c824w`}]]};Tu.node;var Eu=V(Tu),Du={name:`paperclip`,size:24,node:[[`path`,{d:`m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551`,key:`1miecu`}]]};Du.node;var Ou=V(Du),ku={name:`pencil`,size:24,node:[[`path`,{d:`M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z`,key:`1a8usu`}],[`path`,{d:`m15 5 4 4`,key:`1mk7zo`}]]};ku.node;var Au=V(ku),ju={name:`phone-incoming`,size:24,node:[[`path`,{d:`M16 2v6h6`,key:`1mfrl5`}],[`path`,{d:`m22 2-6 6`,key:`6f0sa0`}],[`path`,{d:`M13.832 16.568a1 1 0 0 0 1.213-.303l.355-.465A2 2 0 0 1 17 15h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2A18 18 0 0 1 2 4a2 2 0 0 1 2-2h3a2 2 0 0 1 2 2v3a2 2 0 0 1-.8 1.6l-.468.351a1 1 0 0 0-.292 1.233 14 14 0 0 0 6.392 6.384`,key:`9njp5v`}]]};ju.node;var Mu=V(ju),Nu={name:`phone-off`,size:24,node:[[`path`,{d:`M10.1 13.9a14 14 0 0 0 3.732 2.668 1 1 0 0 0 1.213-.303l.355-.465A2 2 0 0 1 17 15h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2 18 18 0 0 1-12.728-5.272`,key:`1wngk7`}],[`path`,{d:`M22 2 2 22`,key:`y4kqgn`}],[`path`,{d:`M4.76 13.582A18 18 0 0 1 2 4a2 2 0 0 1 2-2h3a2 2 0 0 1 2 2v3a2 2 0 0 1-.8 1.6l-.468.351a1 1 0 0 0-.292 1.233 14 14 0 0 0 .244.473`,key:`10hv5p`}]]};Nu.node;var Pu=V(Nu),Fu={name:`play`,size:24,node:[[`path`,{d:`M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z`,key:`10ikf1`}]]};Fu.node;var Iu=V(Fu),Lu={name:`plug-zap`,size:24,node:[[`path`,{d:`M6.3 20.3a2.4 2.4 0 0 0 3.4 0L12 18l-6-6-2.3 2.3a2.4 2.4 0 0 0 0 3.4Z`,key:`goz73y`}],[`path`,{d:`m2 22 3-3`,key:`19mgm9`}],[`path`,{d:`M7.5 13.5 10 11`,key:`7xgeeb`}],[`path`,{d:`M10.5 16.5 13 14`,key:`10btkg`}],[`path`,{d:`m18 3-4 4h6l-4 4`,key:`16psg9`}]],aliases:[`plug-zap-2`]};Lu.node;var Ru=V(Lu),zu={name:`plug`,size:24,node:[[`path`,{d:`M12 22v-5`,key:`1ega77`}],[`path`,{d:`M15 8V2`,key:`18g5xt`}],[`path`,{d:`M17 8a1 1 0 0 1 1 1v4a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V9a1 1 0 0 1 1-1z`,key:`1xoxul`}],[`path`,{d:`M9 8V2`,key:`14iosj`}]]};zu.node;var Bu=V(zu),Vu={name:`plus`,size:24,node:[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`M12 5v14`,key:`s699le`}]]};Vu.node;var Hu=V(Vu),Uu={name:`power`,size:24,node:[[`path`,{d:`M12 2v10`,key:`mnfbl`}],[`path`,{d:`M18.4 6.6a9 9 0 1 1-12.77.04`,key:`obofu9`}]]};Uu.node;var Wu=V(Uu),Gu={name:`puzzle`,size:24,node:[[`path`,{d:`M15.39 4.39a1 1 0 0 0 1.68-.474 2.5 2.5 0 1 1 3.014 3.015 1 1 0 0 0-.474 1.68l1.683 1.682a2.414 2.414 0 0 1 0 3.414L19.61 15.39a1 1 0 0 1-1.68-.474 2.5 2.5 0 1 0-3.014 3.015 1 1 0 0 1 .474 1.68l-1.683 1.682a2.414 2.414 0 0 1-3.414 0L8.61 19.61a1 1 0 0 0-1.68.474 2.5 2.5 0 1 1-3.014-3.015 1 1 0 0 0 .474-1.68l-1.683-1.682a2.414 2.414 0 0 1 0-3.414L4.39 8.61a1 1 0 0 1 1.68.474 2.5 2.5 0 1 0 3.014-3.015 1 1 0 0 1-.474-1.68l1.683-1.682a2.414 2.414 0 0 1 3.414 0z`,key:`w46dr5`}]]};Gu.node;var Ku=V(Gu),qu={name:`receipt`,size:24,node:[[`path`,{d:`M12 17V7`,key:`pyj7ub`}],[`path`,{d:`M16 8h-6a2 2 0 0 0 0 4h4a2 2 0 0 1 0 4H8`,key:`1elt7d`}],[`path`,{d:`M4 3a1 1 0 0 1 1-1 1.3 1.3 0 0 1 .7.2l.933.6a1.3 1.3 0 0 0 1.4 0l.934-.6a1.3 1.3 0 0 1 1.4 0l.933.6a1.3 1.3 0 0 0 1.4 0l.933-.6a1.3 1.3 0 0 1 1.4 0l.934.6a1.3 1.3 0 0 0 1.4 0l.933-.6A1.3 1.3 0 0 1 19 2a1 1 0 0 1 1 1v18a1 1 0 0 1-1 1 1.3 1.3 0 0 1-.7-.2l-.933-.6a1.3 1.3 0 0 0-1.4 0l-.934.6a1.3 1.3 0 0 1-1.4 0l-.933-.6a1.3 1.3 0 0 0-1.4 0l-.933.6a1.3 1.3 0 0 1-1.4 0l-.934-.6a1.3 1.3 0 0 0-1.4 0l-.933.6a1.3 1.3 0 0 1-.7.2 1 1 0 0 1-1-1z`,key:`ycz6yz`}]]};qu.node;var Ju=V(qu),Yu={name:`refresh-cw`,size:24,node:[[`path`,{d:`M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8`,key:`v9h5vc`}],[`path`,{d:`M21 3v5h-5`,key:`1q7to0`}],[`path`,{d:`M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16`,key:`3uifl3`}],[`path`,{d:`M8 16H3v5`,key:`1cv678`}]]};Yu.node;var Xu=V(Yu),Zu={name:`rotate-ccw-clock`,size:24,node:[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}],[`path`,{d:`M12 7v5l4 2`,key:`1fdv2h`}]],aliases:[`history`]};Zu.node;var Qu=V(Zu),$u={name:`rotate-cw`,size:24,node:[[`path`,{d:`M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8`,key:`1p45f6`}],[`path`,{d:`M21 3v5h-5`,key:`1q7to0`}]]};$u.node;var ed=V($u),td={name:`ruler-dimension-line`,size:24,node:[[`path`,{d:`M10 15v-3`,key:`1pjskw`}],[`path`,{d:`M14 15v-3`,key:`1o1mqj`}],[`path`,{d:`M18 15v-3`,key:`cws6he`}],[`path`,{d:`M2 8V4`,key:`3jv1jz`}],[`path`,{d:`M22 6H2`,key:`1iqbfk`}],[`path`,{d:`M22 8V4`,key:`16f4ou`}],[`path`,{d:`M6 15v-3`,key:`1ij1qe`}],[`rect`,{x:`2`,y:`12`,width:`20`,height:`8`,rx:`2`,key:`1tqiko`}]]};td.node;var nd=V(td),rd={name:`search`,size:24,node:[[`path`,{d:`m21 21-4.34-4.34`,key:`14j7rj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}]]};rd.node;var id=V(rd),ad={name:`send-horizontal`,size:24,node:[[`path`,{d:`M3.714 3.048a.498.498 0 0 0-.683.627l2.843 7.627a2 2 0 0 1 0 1.396l-2.842 7.627a.498.498 0 0 0 .682.627l18-8.5a.5.5 0 0 0 0-.904z`,key:`117uat`}],[`path`,{d:`M6 12h16`,key:`s4cdu5`}]],aliases:[`send-horizonal`]};ad.node;var od=V(ad),sd={name:`send`,size:24,node:[[`path`,{d:`M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z`,key:`1ffxy3`}],[`path`,{d:`m21.854 2.147-10.94 10.939`,key:`12cjpa`}]]};sd.node;var cd=V(sd),ld={name:`server`,size:24,node:[[`rect`,{width:`20`,height:`8`,x:`2`,y:`2`,rx:`2`,ry:`2`,key:`ngkwjq`}],[`rect`,{width:`20`,height:`8`,x:`2`,y:`14`,rx:`2`,ry:`2`,key:`iecqi9`}],[`line`,{x1:`6`,x2:`6.01`,y1:`6`,y2:`6`,key:`16zg32`}],[`line`,{x1:`6`,x2:`6.01`,y1:`18`,y2:`18`,key:`nzw8ys`}]]};ld.node;var ud=V(ld),dd={name:`settings`,size:24,node:[[`path`,{d:`M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915`,key:`1i5ecw`}],[`circle`,{cx:`12`,cy:`12`,r:`3`,key:`1v7zrd`}]]};dd.node;var fd=V(dd),pd={name:`shield-check`,size:24,node:[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`m9 12 2 2 4-4`,key:`dzmm74`}]]};pd.node;var md=V(pd),hd={name:`shield-user`,size:24,node:[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`M6.376 18.91a6 6 0 0 1 11.249.003`,key:`hnjrf2`}],[`circle`,{cx:`12`,cy:`11`,r:`4`,key:`1gt34v`}]]};hd.node;var gd=V(hd),_d={name:`shopping-cart`,size:24,node:[[`path`,{d:`m2.05 2.05 1.099-.028a1 1 0 0 1 1.008.815l2.69 14.347A1 1 0 0 0 7.83 18H18`,key:`uebgi3`}],[`path`,{d:`M4.563 5h16.435a1 1 0 0 1 .981 1.204l-1.026 6.226A2 2 0 0 1 18.962 14H6.25`,key:`1j7c9p`}],[`circle`,{cx:`18`,cy:`20`,r:`2`,key:`t9985n`}],[`circle`,{cx:`8`,cy:`20`,r:`2`,key:`ckkr5m`}]]};_d.node;var vd=V(_d),yd={name:`sliders-horizontal`,size:24,node:[[`path`,{d:`M10 5H3`,key:`1qgfaw`}],[`path`,{d:`M12 19H3`,key:`yhmn1j`}],[`path`,{d:`M14 3v4`,key:`1sua03`}],[`path`,{d:`M16 17v4`,key:`1q0r14`}],[`path`,{d:`M21 12h-9`,key:`1o4lsq`}],[`path`,{d:`M21 19h-5`,key:`1rlt1p`}],[`path`,{d:`M21 5h-7`,key:`1oszz2`}],[`path`,{d:`M8 10v4`,key:`tgpxqk`}],[`path`,{d:`M8 12H3`,key:`a7s4jb`}]]};yd.node;var bd=V(yd),xd={name:`smartphone`,size:24,node:[[`rect`,{width:`14`,height:`20`,x:`5`,y:`2`,rx:`2`,ry:`2`,key:`1yt0o3`}],[`path`,{d:`M12 18h.01`,key:`mhygvu`}]]};xd.node;var Sd=V(xd),Cd={name:`sparkles`,size:24,node:[[`path`,{d:`M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z`,key:`1s2grr`}],[`path`,{d:`M20 2v4`,key:`1rf3ol`}],[`path`,{d:`M22 4h-4`,key:`gwowj6`}],[`circle`,{cx:`4`,cy:`20`,r:`2`,key:`6kqj1y`}]],aliases:[`stars`]};Cd.node;var wd=V(Cd),Td={name:`square-kanban`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M8 7v7`,key:`1x2jlm`}],[`path`,{d:`M12 7v4`,key:`xawao1`}],[`path`,{d:`M16 7v9`,key:`1hp2iy`}]],aliases:[`kanban-square`]};Td.node;var Ed=V(Td),Dd={name:`square`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]};Dd.node;var Od=V(Dd),kd={name:`sun-moon`,size:24,node:[[`path`,{d:`M12 2v2`,key:`tus03m`}],[`path`,{d:`M14.837 16.385a6 6 0 1 1-7.223-7.222c.624-.147.97.66.715 1.248a4 4 0 0 0 5.26 5.259c.589-.255 1.396.09 1.248.715`,key:`xlf6rm`}],[`path`,{d:`M16 12a4 4 0 0 0-4-4`,key:`6vsxu`}],[`path`,{d:`m19 5-1.256 1.256`,key:`1yg6a6`}],[`path`,{d:`M20 12h2`,key:`1q8mjw`}]]};kd.node;var Ad=V(kd),jd={name:`sun`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`4`,key:`4exip2`}],[`path`,{d:`M12 2v2`,key:`tus03m`}],[`path`,{d:`M12 20v2`,key:`1lh1kg`}],[`path`,{d:`m4.93 4.93 1.41 1.41`,key:`149t6j`}],[`path`,{d:`m17.66 17.66 1.41 1.41`,key:`ptbguv`}],[`path`,{d:`M2 12h2`,key:`1t8f8n`}],[`path`,{d:`M20 12h2`,key:`1q8mjw`}],[`path`,{d:`m6.34 17.66-1.41 1.41`,key:`1m8zz5`}],[`path`,{d:`m19.07 4.93-1.41 1.41`,key:`1shlcs`}]]};jd.node;var Md=V(jd),Nd={name:`table-2`,size:24,node:[[`path`,{d:`M3 9h18`,key:`1pudct`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}],[`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,key:`h1oib`}]]};Nd.node;var Pd=V(Nd),Fd={name:`tablet`,size:24,node:[[`rect`,{width:`16`,height:`20`,x:`4`,y:`2`,rx:`2`,ry:`2`,key:`76otgf`}],[`line`,{x1:`12`,x2:`12.01`,y1:`18`,y2:`18`,key:`1dp563`}]]};Fd.node;var Id=V(Fd),Ld={name:`tag`,size:24,node:[[`path`,{d:`M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z`,key:`vktsd0`}],[`circle`,{cx:`7.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`kqv944`}]]};Ld.node;var Rd=V(Ld),zd={name:`tags`,size:24,node:[[`path`,{d:`M13.172 2a2 2 0 0 1 1.414.586l6.71 6.71a2.4 2.4 0 0 1 0 3.408l-4.592 4.592a2.4 2.4 0 0 1-3.408 0l-6.71-6.71A2 2 0 0 1 6 9.172V3a1 1 0 0 1 1-1z`,key:`16rjxf`}],[`path`,{d:`M2 7v6.172a2 2 0 0 0 .586 1.414l6.71 6.71a2.4 2.4 0 0 0 3.191.193`,key:`178nd4`}],[`circle`,{cx:`10.5`,cy:`6.5`,r:`.5`,fill:`currentColor`,key:`12ikhr`}]]};zd.node;var Bd=V(zd),Vd={name:`terminal`,size:24,node:[[`path`,{d:`M12 19h8`,key:`baeox8`}],[`path`,{d:`m4 17 6-6-6-6`,key:`1yngyt`}]]};Vd.node;var Hd=V(Vd),Ud={name:`trash`,size:24,node:[[`path`,{d:`M10 11v6`,key:`nco0om`}],[`path`,{d:`M14 11v6`,key:`outv1u`}],[`path`,{d:`M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6`,key:`miytrc`}],[`path`,{d:`M3 6h18`,key:`d0wm0j`}],[`path`,{d:`M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2`,key:`e791ji`}]],aliases:[`trash-2`]};Ud.node;var Wd=V(Ud),Gd={name:`undo-2`,size:24,node:[[`path`,{d:`M9 14 4 9l5-5`,key:`102s5s`}],[`path`,{d:`M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11`,key:`f3b9sd`}]]};Gd.node;var Kd=V(Gd),qd={name:`upload`,size:24,node:[[`path`,{d:`M12 3v12`,key:`1x0j5s`}],[`path`,{d:`m17 8-5-5-5 5`,key:`7q97r8`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}]]};qd.node;var Jd=V(qd),Yd={name:`user-plus`,size:24,node:[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}],[`line`,{x1:`19`,x2:`19`,y1:`8`,y2:`14`,key:`1bvyxn`}],[`line`,{x1:`22`,x2:`16`,y1:`11`,y2:`11`,key:`1shjgl`}]]};Yd.node;var Xd=V(Yd),Zd={name:`user-round-cog`,size:24,node:[[`path`,{d:`m14.305 19.53.923-.382`,key:`3m78fa`}],[`path`,{d:`m15.228 16.852-.923-.383`,key:`npixar`}],[`path`,{d:`m16.852 15.228-.383-.923`,key:`5xggr7`}],[`path`,{d:`m16.852 20.772-.383.924`,key:`dpfhf9`}],[`path`,{d:`m19.148 15.228.383-.923`,key:`1reyyz`}],[`path`,{d:`m19.53 21.696-.382-.924`,key:`1goivc`}],[`path`,{d:`M2 21a8 8 0 0 1 10.434-7.62`,key:`1yezr2`}],[`path`,{d:`m20.772 16.852.924-.383`,key:`htqkph`}],[`path`,{d:`m20.772 19.148.924.383`,key:`9w9pjp`}],[`circle`,{cx:`10`,cy:`8`,r:`5`,key:`o932ke`}],[`circle`,{cx:`18`,cy:`18`,r:`3`,key:`1xkwt0`}]],aliases:[`user-cog-2`]};Zd.node;var Qd=V(Zd),$d={name:`user-round`,size:24,node:[[`circle`,{cx:`12`,cy:`8`,r:`5`,key:`1hypcn`}],[`path`,{d:`M20 21a8 8 0 0 0-16 0`,key:`rfgkzh`}]],aliases:[`user-2`]};$d.node;var ef=V($d),tf={name:`users`,size:24,node:[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]};tf.node;var nf=V(tf),rf={name:`video-off`,size:24,node:[[`path`,{d:`M10.66 6H14a2 2 0 0 1 2 2v2.5l5.248-3.062A.5.5 0 0 1 22 7.87v8.196`,key:`w8jjjt`}],[`path`,{d:`M16 16a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h2`,key:`1xawa7`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]};rf.node;var af=V(rf),of={name:`video`,size:24,node:[[`path`,{d:`m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5`,key:`ftymec`}],[`rect`,{x:`2`,y:`6`,width:`14`,height:`12`,rx:`2`,key:`158x01`}]]};of.node;var sf=V(of),cf={name:`wallet`,size:24,node:[[`path`,{d:`M19 7V4a1 1 0 0 0-1-1H5a2 2 0 0 0 0 4h15a1 1 0 0 1 1 1v4h-3a2 2 0 0 0 0 4h3a1 1 0 0 0 1-1v-2a1 1 0 0 0-1-1`,key:`18etb6`}],[`path`,{d:`M3 5v14a2 2 0 0 0 2 2h15a1 1 0 0 0 1-1v-4`,key:`xoc0q4`}]]};cf.node;var lf=V(cf),uf={name:`warehouse`,size:24,node:[[`path`,{d:`M18 21V10a1 1 0 0 0-1-1H7a1 1 0 0 0-1 1v11`,key:`pb2vm6`}],[`path`,{d:`M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V8a2 2 0 0 1 1.132-1.803l7.95-3.974a2 2 0 0 1 1.837 0l7.948 3.974A2 2 0 0 1 22 8z`,key:`doq5xv`}],[`path`,{d:`M6 13h12`,key:`yf64js`}],[`path`,{d:`M6 17h12`,key:`1jwigz`}]]};uf.node;var df=V(uf),ff={name:`wifi-off`,size:24,node:[[`path`,{d:`M12 20h.01`,key:`zekei9`}],[`path`,{d:`M8.5 16.429a5 5 0 0 1 7 0`,key:`1bycff`}],[`path`,{d:`M5 12.859a10 10 0 0 1 5.17-2.69`,key:`1dl1wf`}],[`path`,{d:`M19 12.859a10 10 0 0 0-2.007-1.523`,key:`4k23kn`}],[`path`,{d:`M2 8.82a15 15 0 0 1 4.177-2.643`,key:`1grhjp`}],[`path`,{d:`M22 8.82a15 15 0 0 0-11.288-3.764`,key:`z3jwby`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]};ff.node;var pf=V(ff),mf={name:`wrench`,size:24,node:[[`path`,{d:`M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.106-3.105c.32-.322.863-.22.983.218a6 6 0 0 1-8.259 7.057l-7.91 7.91a1 1 0 0 1-2.999-3l7.91-7.91a6 6 0 0 1 7.057-8.259c.438.12.54.662.219.984z`,key:`1ngwbx`}]]};mf.node;var hf=V(mf),gf={name:`zap`,size:24,node:[[`path`,{d:`M15.914 4a1.5 1.5 0 00-2.474-1.561l-9 9A1.5 1.5 0 005.5 14h4.002a.5.5 0 01.471.666L8.086 20a1.5 1.5 0 002.475 1.56l9-9A1.5 1.5 0 0018.5 10h-3.997a.5.5 0 01-.472-.667z`,key:`1v7up4`}]]};gf.node;var _f=V(gf),vf=[`always`,`editing`,`reading`],yf=e=>e!==void 0&&!vf.includes(e),bf={signature:`sig`},xf=e=>{let t=e.startsWith(`?`)?e.slice(1):e;return new URLSearchParams(t).has(bf.signature)?{oauthQuery:t}:{}},Sf=`/-/sign-in`,Cf={step:`step`,next:`next`},wf=[`sign-in`,`forgot-password`,`email-code`,`sign-up`,`sign-up-code`,`sign-up-details`],Tf=e=>wf.includes(e),Ef=e=>{if(!e?.startsWith(`/`))return;let t=new URL(e,`http://local`);if(t.origin===`http://local`&&t.pathname!==`/-/sign-in`)return`${t.pathname}${t.search}`},Df=({step:e=`sign-in`,next:t}={})=>{let n=new URLSearchParams;e!==`sign-in`&&n.set(Cf.step,e);let r=Ef(t);r&&r!==`/`&&n.set(Cf.next,r);let i=n.toString();return i?`${Sf}?${i}`:Sf},Of=(e,t)=>{if(e!==`/-/sign-in`)return;let n=t.get(Cf.step),r=Ef(t.get(Cf.next));return{step:Tf(n)?n:`sign-in`,...r&&{next:r}}},kf=e=>e===null||typeof e==`string`&&e.trim()===``,Af=/^-?(0|[1-9]\d*)$/,jf=/^-?(0|[1-9]\d*)\.\d+$/,Mf=/^(\d{4})-(\d{2})-(\d{2})$/,Nf=/^(\d{4}-\d{2}-\d{2})[T ](\d{2}):(\d{2})(?::(\d{2})(?:\.\d{1,6})?)?(Z|[+-]\d{2}:\d{2})?$/,Pf=e=>{let t=Mf.exec(e);if(!t)return!1;let[n,r,i]=[Number(t[1]),Number(t[2]),Number(t[3])],a=new Date(Date.UTC(n,r-1,i));return a.getUTCFullYear()===n&&a.getUTCMonth()===r-1&&a.getUTCDate()===i},Ff=e=>{if(Af.test(e))return`whole`;if(jf.test(e))return`decimal`;if(/^(true|false)$/i.test(e))return`boolean`;if(Pf(e))return`date`;let t=Nf.exec(e);return!t?.[1]||!Pf(t[1])||Number(t[2])>23||Number(t[3])>59||Number(t[4]??0)>59?`text`:t[5]?`zoned`:`local`},If=e=>typeof e==`boolean`?`boolean`:typeof e==`number`?Number.isInteger(e)?`whole`:`decimal`:typeof e==`string`?Ff(e.trim()):`json`in e?`json`:e.date.includes(`T`)?`local`:`date`,Lf=e=>typeof e==`number`?e.toLocaleString(`en-US`,{useGrouping:!1,maximumFractionDigits:100}):e.trim(),Rf=1e3,zf=2147483647n,Bf={boolean:`boolean`,date:`date`,local:`timestamp`,zoned:`timestamp`,json:`json`},Vf=()=>{let e=new Set,t=1,n=0,r=!1,i=0,a=a=>{if(a===null||kf(a))return;typeof a==`string`&&(i=Math.max(i,a.length));let o=If(a);if(e.add(o),o!==`whole`&&o!==`decimal`)return;let[s=``,c=``]=Lf(a).replace(`-`,``).split(`.`);if(t=Math.max(t,s.length),n=Math.max(n,c.length),o===`whole`&&!r){let e=BigInt(Lf(a));r=(e<0n?-e-1n:e)>zf}},o=()=>{let e=Math.min(Rf,Math.max(t,15)+n);return{type:`decimal`,precision:e,scale:Math.min(n,e)}};return{add:a,type:()=>{if(e.has(`json`))return{type:`json`};let t=e.size===1?[...e][0]:void 0;return t===`whole`?r?o():{type:`integer`}:e.size===2&&e.has(`whole`)&&e.has(`decimal`)||t===`decimal`?o():t&&t!==`text`?{type:Bf[t]}:{type:i>500?`long_text`:`text`}},decimal:o}},Hf=e=>{switch(e){case`integer`:return[`integer`,`decimal`,`text`,`long_text`];case`decimal`:case`boolean`:case`date`:case`timestamp`:return[e,`text`,`long_text`];case`text`:return[`text`,`long_text`];case`long_text`:case`json`:return[e]}},Uf=e=>e.normalize(`NFKD`).replace(/[̀-ͯ]/g,``).toLowerCase().replace(/[^a-z0-9]+/g,`_`).replace(/^_+|_+$/g,``),Wf=(e,t,n)=>(/^[a-z]/.test(e)?e:`${t}_${e}`).slice(0,n).replace(/_+$/,``),Gf=(e,t,n)=>{let r=e;for(let i=2;t.has(r)||ns.has(r);i++){let t=`_${i}`;r=`${e.slice(0,n-t.length).replace(/_+$/,``)}${t}`}return r},Kf=e=>e<26?String.fromCharCode(97+e):Kf(Math.floor(e/26)-1)+Kf(e%26),qf=e=>{let t=new Set(is);return e.map((e,n)=>{let r=Uf(e),i=Gf(r===``?`column_${Kf(n)}`:Wf(r,`column`,63),t,63);return t.add(i),i})},Jf=(e,t=[],n=63)=>{let r=Uf(e.replace(/\.(csv|tsv|txt|xlsx|json)$/i,``));if(r!==``)return Gf(Wf(r,`table`,n),new Set(t),n)},Yf=e=>ge(e,!1),Xf=e=>Yf(e);Xf(`ReferenceManyField`),Xf(`ReferenceArrayField`),Yf(`ArrayField`),Xf(`RecordsIterator`),Xf(`ReferenceField`);var Zf=e=>`${e} desc`,Qf=new Set([`Table`,`Timeline`,`Graph`]),$f=e=>e===`Graph`?`nodes`:`resource`,ep=e=>Array.isArray(e)?e:[e],tp=e=>typeof e==`string`?e:void 0,np=e=>{if(!e.custom){let t=Qf.has(e.type)?tp(e.props.select):void 0;return t===void 0?void 0:{param:t,resource:tp(e.props[$f(e.type)])}}let t=e.reads&&ep(e.reads).find(e=>e.select!==void 0),n=t&&tp(e.props[t.select]);return n===void 0?void 0:{param:n,resource:tp(e.props[t.resource])}},rp={stack:[]},ip=e=>typeof e==`string`?e:void 0,ap=(e,t)=>({stack:[...e.stack,t],...e.root!==void 0&&{root:e.root}}),op=(e,t)=>({...e,list:t}),sp=(e,t)=>{let n=up(e),r=np(e);if(r)return ap(t,{resource:r.resource,repeated:!1,block:n});if(e.custom)return t;switch(e.type){case`RecordCard`:case`CardRow`:return ap(t,{resource:ip(e.props.resource),repeated:e.type===`CardRow`,block:n});case`ReferenceField`:return ap(t,{resource:ip(e.props.reference),repeated:!1,block:n});case`ReferenceManyField`:case`ReferenceArrayField`:return op(t,{resource:ip(e.props.reference),items:!1,block:n});case`ArrayField`:return op(t,{items:!0,block:n});case`RecordsIterator`:return t.list?ap(t,{...t.list.resource!==void 0&&{resource:t.list.resource},repeated:!0,...t.list.items&&{item:!0},block:t.list.block}):t;default:return t}},cp=(e,t)=>e.custom?t:e.type===`RecordCard`?sp(e,t):e.type===`Graph`?ap(t,{resource:ip(e.props.nodes),repeated:!0,block:up(e)}):t,lp=e=>!e.custom&&e.type===`Graph`?[`nodes`]:[`resource`,`reference`,`name`,`source`],up=e=>`<${e.type}${lp(e).map(t=>typeof e.props[t]==`string`?` ${t}="${e.props[t]}"`:``).join(``)}>`,dp=e=>er(e)||Array.isArray(e)&&e.length>0&&e.every(er),fp=(e,t,n={path:up(e),scope:rp})=>{let r=sp(e,n.scope),i=cp(e,n.scope),a=e.children.flatMap(e=>{if(typeof e==`string`)return[e];let i=fp(e,t,{path:`${n.path} › ${up(e)}`,scope:r});return i?[i]:[]}),o=Object.fromEntries(Object.entries(e.props).flatMap(([e,r])=>{if(!dp(r))return[[e,r]];let a=(Array.isArray(r)?r:[r]).flatMap(r=>fp(r,t,{path:`${n.path} ${e}={${up(r)}}`,scope:i})??[]);return a.length===0?[]:[[e,Array.isArray(r)?a:a[0]]]})),s=e.fallback?.flatMap(e=>{if(typeof e==`string`)return[e];let r=fp(e,t,{path:`${n.path} fallback={${up(e)}}`,scope:n.scope});return r?[r]:[]});return t({...e,props:o,children:a,...s&&{fallback:s}},n)},pp=(e,t,n={path:up(e),scope:rp})=>{t(e,n);let r=sp(e,n.scope),i=cp(e,n.scope);for(let i of e.children)typeof i!=`string`&&pp(i,t,{path:`${n.path} › ${up(i)}`,scope:r});for(let[r,a]of Object.entries(e.props))if(dp(a))for(let e of Array.isArray(a)?a:[a])pp(e,t,{path:`${n.path} ${r}={${up(e)}}`,scope:i});for(let r of e.fallback??[])typeof r!=`string`&&pp(r,t,{path:`${n.path} fallback={${up(r)}}`,scope:n.scope})};ge(`SelectInput`,!1);var mp=e=>{let t=new Map;return pp(e,e=>{e.custom||e.type!==`SelectInput`||typeof e.props.source!=`string`||t.has(e.props.source)||t.set(e.props.source,e.props)}),t},hp=(e,t)=>t!==void 0&&t!==``&&(e.choices===void 0||e.choices.some(e=>String(e.id)===t))?t:e.defaultValue===void 0?void 0:String(e.defaultValue),gp=(e,t={})=>{let n={};for(let[r,i]of mp(e)){let e=hp(i,Object.hasOwn(t,r)?t[r]:void 0);e!==void 0&&(n[r]=e)}return n},G=e=>({kind:e}),_p=e=>({kind:e,required:!0}),vp={title:G(`shown`),description:G(`shown`),actions:G(`elements`)},yp={resource:_p(`text`),filter:G(`text`),sort:G(`text`)},bp={resource:`resource`,filter:`filter`,sort:`sort`},xp={sort:G(`sort`),filter:G(`filter`),perPage:G(`integer`)},Sp={source:_p(`text`),emptyText:G(`text`)},Cp={locales:G(`locales`),options:G(`intlOptions`)},wp={Page:{children:!0,props:{title:_p(`shown`),description:G(`shown`),actions:G(`elements`),width:G(`pageWidth`)}},Grid:{children:!0,props:{columns:G(`columns`),span:G(`span`)}},Card:{children:!0,props:{...vp,span:G(`span`)}},Stat:{children:!1,props:{label:_p(`shown`),value:G(`scalar`),resource:G(`text`),filter:G(`text`),field:G(`text`),format:G(`format`),description:G(`shown`),span:G(`span`)},reads:{resource:`resource`,filter:`filter`}},RecordCard:{children:!0,props:{...yp,...vp,recordKey:G(`text`),empty:G(`shown`),span:G(`span`)},reads:bp},Field:{children:!1,props:{source:_p(`text`),label:G(`label`),format:G(`format`)}},Diff:{children:!1,props:Sp},Table:{children:!0,reads:bp,props:{...yp,resource:G(`text`),...vp,columns:G(`tableColumns`),button:G(`rowButton`),bulk:G(`boolean`),limit:G(`integer`),display:G(`text`),empty:G(`shown`),span:G(`span`),select:G(`text`)}},SelectInput:{children:!1,props:{source:_p(`text`),choices:G(`choices`),label:G(`shown`),defaultValue:G(`scalar`)}},CardRow:{children:!0,props:{...yp,...vp,limit:G(`integer`),empty:G(`shown`),span:G(`span`)},reads:bp},RecordRow:{children:!1,props:{...yp,...vp,limit:G(`integer`),display:G(`text`),empty:G(`shown`),span:G(`span`)},reads:bp},RecordCards:{children:!1,reads:{...bp,fields:`fields`},props:{...yp,...vp,layout:G(`cardsLayout`),cardWidth:G(`cardWidth`),fields:G(`texts`),cardActions:G(`texts`),limit:G(`integer`),display:G(`text`),empty:G(`shown`),span:G(`span`)}},Chart:{children:!1,reads:{resource:`resource`,filter:`filter`},props:{...vp,resource:_p(`text`),filter:G(`text`),groupBy:_p(`text`),splitBy:G(`text`),type:G(`chartType`),sum:G(`text`),average:G(`text`),granularity:G(`bucket`),range:G(`range`),limit:G(`integer`),empty:G(`shown`),span:G(`span`)}},Timeline:{children:!0,reads:{resource:`resource`,filter:`filter`},props:{...vp,resource:_p(`text`),filter:G(`text`),lane:_p(`text`),bar:_p(`text`),start:_p(`text`),end:_p(`text`),color:_p(`text`),limit:G(`integer`),empty:G(`shown`),span:G(`span`),select:G(`text`)}},Graph:{children:!0,reads:[{resource:`nodes`,filter:`filter`,fields:[`label`,`group`,`status`,`x`,`y`],select:`select`},{resource:`edges`,filter:`edgeFilter`,fields:[`source`,`target`,`edgeLabel`,`edgeStatus`]}],props:{nodes:_p(`text`),edges:_p(`text`),source:_p(`text`),target:_p(`text`),label:_p(`text`),group:G(`text`),status:G(`text`),node:G(`elements`),filter:G(`text`),edgeFilter:G(`text`),edgeLabel:G(`text`),edgeStatus:G(`text`),animated:G(`text`),dashed:G(`text`),dotted:G(`text`),layout:G(`graphLayout`),direction:G(`graphDirection`),x:G(`text`),y:G(`text`),select:G(`text`),empty:G(`shown`)}},Progress:{children:!1,props:{value:_p(`amount`),max:G(`amount`),label:G(`shown`),span:G(`span`)}},ModalForm:{children:!1,props:{mode:_p(`mode`),label:_p(`shown`),fields:_p(`texts`),resource:G(`text`),recordKey:G(`text`),title:G(`shown`),values:G(`values`),variant:G(`variant`)}},Thread:{children:!1,reads:{resource:`resource`,filter:`filter`},props:{...vp,resource:_p(`text`),filter:G(`text`),sender:G(`text`),time:_p(`text`),text:_p(`text`),status:G(`text`),working:G(`text`),calls:G(`toolCalls`),limit:G(`integer`),empty:G(`shown`),span:G(`span`)}},Composer:{children:!1,props:{resource:_p(`text`),field:_p(`text`),values:G(`values`),placeholder:G(`text`),span:G(`span`)}},Image:{children:!1,props:{function:G(`text`),src:G(`text`),alt:G(`text`),width:G(`integer`),height:G(`integer`),refresh:G(`integer`)}},Action:{children:!1,props:{name:_p(`text`),resource:G(`text`),label:G(`shown`),variant:G(`variant`)}},ReferenceManyField:{children:!0,reads:{resource:`reference`,filter:`filter`,sort:`sort`},props:{reference:_p(`text`),target:_p(`text`),source:G(`text`),...xp,empty:G(`shown`),pagination:G(`pagination`)}},ReferenceArrayField:{children:!0,reads:{resource:`reference`,filter:`filter`,sort:`sort`},props:{source:_p(`text`),reference:_p(`text`),...xp,empty:G(`shown`)}},ArrayField:{children:!0,props:{source:_p(`text`)}},RecordsIterator:{children:!0,props:{}},ReferenceField:{children:!0,reads:{resource:`reference`},props:{source:_p(`text`),reference:_p(`text`),link:G(`referenceLink`),empty:G(`shown`)}},Show:{children:!0,props:{when:_p(`text`),fallback:G(`content`)}},Switch:{children:!0,props:{fallback:G(`content`)}},Match:{children:!0,props:{when:_p(`text`)}},Link:{children:!0,props:{href:G(`text`),to:G(`address`),variant:G(`variant`)}},Tabs:{children:!0,props:{}},Tab:{children:!0,props:{name:_p(`text`),label:_p(`shown`)}},Settings:{children:!1,props:{resource:_p(`text`),fields:G(`texts`),title:G(`shown`),description:G(`shown`),span:G(`span`)}},Users:{children:!1,props:{}},Profile:{children:!1,props:{}},Password:{children:!1,props:{}},Passkeys:{children:!1,props:{}},TwoFactor:{children:!1,props:{}},ConnectedAccounts:{children:!1,props:{}},PersonalMail:{children:!1,props:{}},Connections:{children:!1,props:{}},Devices:{children:!1,props:{}},ConnectedApps:{children:!1,props:{}},PersonalAccessTokens:{children:!1,props:{}},DeleteAccount:{children:!1,props:{}},Box:{children:!0,props:{}},Email:{children:!0,props:{}},Button:{children:!0,props:{href:_p(`text`)}},Divider:{children:!1,props:{}},Row:{children:!0,props:{}},Column:{children:!0,props:{}},Text:{children:!0,props:{as:G(`textAs`)}},Trans:{children:!1,props:{i18nKey:_p(`text`),values:G(`transValues`),components:G(`transComponents`)}},Details:{children:!0,props:{open:G(`boolean`)}},Summary:{children:!0,props:{}},TextField:{children:!1,props:Sp},NumberField:{children:!1,props:{...Sp,...Cp}},DateField:{children:!1,props:{...Sp,...Cp,showDate:G(`boolean`),showTime:G(`boolean`),format:G(`dateFormat`)}},BooleanField:{children:!1,props:{...Sp,valueLabelTrue:G(`text`),valueLabelFalse:G(`text`)}},UrlField:{children:!1,props:{...Sp,content:G(`text`)}},ChipField:{children:!1,props:Sp}},Tp=Object.fromEntries(Object.entries(wp).map(([e,t])=>[e,{...t,props:{...t.props,className:G(`text`)}}])),Ep=[`relative`,`absolute`,`compact`,`percent`,`badge`,`code`],Dp=[`primary`,`secondary`,`danger`,`ghost`],Op=[`bar`,`line`,`donut`],kp=[`hour`,`day`,`week`,`month`,`year`],Ap=[`7d`,`30d`,`90d`,`1y`,`all`],jp=[`stack`,`carousel`],Mp=[`1/4`,`1/3`,`1/2`,`2/3`],Np=[`column`,`full`],Pp=[`p`,`span`,`strong`,`em`,`h1`,`h2`,`h3`,`h4`],Fp=e=>[t=>typeof t==`string`&&e.includes(t),e.join(`, `)];Ep.join(`, `),Dp.join(`, `),Fp(Op),Fp(kp),Fp(Ap),Fp(jp),Fp(Mp),Fp(Np),Fp(Pp),Fp([`relative`]),Fp([`layered`,`force`]),Fp([`down`,`right`]);var Ip=e=>`${e} desc`,Lp=[`done`,`error`,`running`],Rp=e=>`${String(e.props.start)} asc`,zp=e=>`${String(e.props.start)} desc`,Bp=2e4,Vp=e=>typeof e==`object`&&!!e&&e.kind===`member`,Hp=e=>Vp(e)?[e.path.join(`.`)]:typeof e!=`object`||!e?[]:Object.values(e).flatMap(Hp),Up=e=>Vp(e)?{...e,path:[e.path.join(`.`)]}:Array.isArray(e)?e.map(Up):typeof e!=`object`||!e?e:Object.fromEntries(Object.entries(e).map(([e,t])=>[e,Up(t)])),Wp=new Set([`string`,`number`,`boolean`,`duration`,`timestamp`]),Gp=e=>Wp.has(e.kind),Kp=e=>{let[t,...n]=e.args;if(t&&Vp(t)){if(e.name===`isNull`&&n.length===0)return{kind:`not`,arg:{kind:`present`,left:t,span:e.span},span:e.span};if(e.name===`in`&&n.length!==0&&n.every(Gp))return{kind:`or`,args:n.map(n=>({kind:`compare`,op:`=`,left:t,right:n,span:e.span})),span:e.span}}},qp=e=>Array.isArray(e)?e.map(qp):typeof e!=`object`||!e?e:(e.kind===`call`?Kp(e):void 0)||Object.fromEntries(Object.entries(e).map(([e,t])=>[e,qp(t)])),Jp=new Set([`isNull`,`in`,`now`]),Yp=e=>Array.isArray(e)?e.flatMap(Yp):typeof e!=`object`||!e?[]:[...e.kind===`call`?[e.name]:[],...Object.values(e).flatMap(Yp)],Xp={extensions:{arithmetic:`now-offset`,durationUnits:!0}},Zp=e=>{let t=it(e,Xp);if(!t.ok)return{ok:!1,message:t.errors.map(e=>e.message).join(`; `)};if(!t.ast)return{ok:!1,message:`the condition is empty`};let n=Yp(t.ast).find(e=>!Jp.has(e));return n===void 0?{ok:!0,ast:t.ast,paths:[...new Set(Hp(t.ast))]}:{ok:!1,message:`${n}() only works in a list's filter, which the API reads; a condition can call isNull(), in() and now()`}},Qp={s:1e3,m:6e4,h:36e5,d:864e5,w:6048e5},$p=(e,t)=>{if(Array.isArray(e))return e.map(e=>$p(e,t));if(typeof e!=`object`||!e)return e;let n=e;if(n.kind===`call`&&n.name===`now`)return{kind:`string`,value:new Date(t).toISOString()};if(n.kind===`binary`&&n.left?.kind===`call`&&n.left.name===`now`&&n.right?.kind===`duration`){let e=(n.right.amount??0)*Qp[n.right.unit??`s`];return{kind:`string`,value:new Date(n.op===`-`?t-e:t+e).toISOString()}}return Object.fromEntries(Object.entries(e).map(([e,n])=>[e,$p(n,t)]))},em=(e,t,n=Date.now())=>e.ast!==void 0&&Gt(Up(qp($p(e.ast,n))),t),tm=(e,t)=>{let[n,r,...i]=e.split(`.`);return n&&r===`count`&&i.length===0&&!t(n)?n:void 0},nm=e=>typeof e==`object`&&!!e&&!Array.isArray(e),rm=e=>typeof e==`number`||typeof e==`boolean`?String(e):`"${String(e).replace(/\\/g,`\\\\`).replaceAll(`"`,`\\"`)}"`,im=e=>{if(typeof e==`string`)return e;if(nm(e))return e.order===`DESC`?`${e.field} desc`:String(e.field)},am=e=>{if(typeof e==`string`)return e;if(!nm(e))return;let t=Object.entries(e).map(([e,t])=>t===null?`isNull(${e})`:`${e} = ${rm(t)}`);return t.length===0?void 0:t.join(` AND `)},om=(...e)=>{let t=e.filter(e=>e!==void 0&&e.trim()!==``);return t.length<=1?t[0]:t.map(e=>`(${e})`).join(` AND `)},sm=(e,t,n)=>t==null?void 0:om(`${e} = ${rm(t)}`,am(n)),cm=(e,t,n)=>{let r=Array.isArray(t)?t.filter(e=>typeof e==`string`||typeof e==`number`):[];return r.length===0?void 0:om(`in(${e}, ${r.map(rm).join(`, `)})`,am(n))},lm=(e,t,n)=>({filter:sm(e.target,n(e.source??`this.id`),e.filter),sort:im(e.sort)??Zf(t),perPage:e.perPage??25}),um=(e,t,n)=>({filter:cm(t,n(e.source),e.filter),sort:im(e.sort)??Zf(t),perPage:e.perPage??500}),dm=e=>e.part===void 0?e.block:`${e.block}#${e.part}`,fm=e=>typeof e==`string`?e:e.name,pm=e=>typeof e==`string`?void 0:e.priority,mm=({title:e,badge:t})=>e?0:t?1:2,hm=(e,t)=>e.map((e,n)=>({name:fm(e),given:pm(e),derived:mm(t(fm(e))),index:n})).sort((e,t)=>e.given!==void 0&&t.given!==void 0?e.given-t.given||e.index-t.index:e.given===void 0?t.given===void 0?e.derived-t.derived||e.index-t.index:1:-1).map(({name:e})=>e),gm=(e,t)=>{let n=e.filter(e=>pm(e)!==void 0),r=n.length>0?n:e,i=new Set(hm(r,t).slice(0,3));return e.map(fm).filter(e=>i.has(e))},_m=e=>{let t=e.custom?e.reads:Tp[e.type]?.reads;return t?Array.isArray(t)?t.map(e=>({reads:e,part:e.resource})):[{reads:t}]:[]};ge(`TextField`,!1),ge(`NumberField`,!1),ge(`DateField`,!1),ge(`BooleanField`,!1),ge(`UrlField`,!1),ge(`ChipField`,!1);var vm=new Set([`TextField`,`NumberField`,`DateField`,`BooleanField`,`UrlField`,`ChipField`]),ym=e=>typeof e!=`string`&&!e.custom&&vm.has(e.type),bm=e=>typeof e==`string`||ym(e)||!e.custom&&(e.type===`Link`||e.type===`Trans`||e.type===`Text`&&[`span`,`strong`,`em`].includes(String(e.props.as))),xm=(e,t)=>e===`BooleanField`?t!==!0&&t!==!1:e===`NumberField`||e===`UrlField`?t==null:t==null||t===``,Sm=e=>typeof e==`object`&&e?JSON.stringify(e):String(e),Cm=(e,{locales:t,options:n},r)=>{let i=typeof e==`string`&&e!==``&&!Number.isNaN(Number(e))?Number(e):e;return typeof i==`number`?i.toLocaleString(t??r,n):String(i)},wm=(e,t,n)=>{let r=e instanceof Date?e:typeof e==`string`||typeof e==`number`?new Date(e):void 0;if(!r||Number.isNaN(r.getTime()))return``;if(t.format===`relative`)return n.relative(Math.round((n.now-r.getTime())/1e3));let{showDate:i=!0,showTime:a=!1,options:o}=t,s=t.locales??n.locale;if(i&&a)return r.toLocaleString(s,o);if(a)return r.toLocaleTimeString(s,o);let c=o??(typeof e==`string`&&e.length<=10?{timeZone:`UTC`}:void 0);return r.toLocaleDateString(s,c)},Tm=(e,t,n)=>e?t.valueLabelTrue??n.yes:t.valueLabelFalse??n.no,Em=new Set([`http:`,`https:`,`mailto:`,`tel:`]),Dm=e=>{let t=e.replace(/^[\u0000- ]+/,``).replace(/[\t\n\r]/g,``),n=/^([A-Za-z][A-Za-z0-9+.-]*):/.exec(t)?.[1];return n===void 0?t.startsWith(`/`)||!t.includes(`:`)?e:void 0:Em.has(`${n.toLowerCase()}:`)?e:void 0},Om=({layout:e,cardWidth:t})=>({layout:e??`stack`,cardWidth:t??`2/3`}),km=e=>e==null||e===``?void 0:String(e),Am=(e,t)=>e<t?-1:+(e>t),jm=({nodes:e,edges:t,key:n,edgeKey:r,fields:i})=>{let a=new Map,o=new Map;for(let t of e){let e=km(t[n]);if(e===void 0||a.has(e))continue;let r=i.group===void 0?void 0:t[i.group],s=km(r);s!==void 0&&!o.has(s)&&o.set(s,{id:s,value:r}),a.set(e,{id:e,row:t,...s!==void 0&&{group:s}})}let s=t.flatMap(e=>{let t=r.map(t=>km(e[t])),n=t.includes(void 0)?void 0:t.length===1?t[0]:JSON.stringify(t),o=km(e[i.source]),s=km(e[i.target]);return n===void 0||o===void 0||s===void 0||!a.has(o)||!a.has(s)?[]:[{id:n,source:o,target:s,row:e}]});return{groups:[...o.values()].sort((e,t)=>Am(e.id,t.id)),nodes:[...a.values()].sort((e,t)=>Am(e.id,t.id)),edges:s.sort((e,t)=>Am(e.source,t.source)||Am(e.target,t.target)||Am(e.id,t.id))}},Mm=(e,t)=>{if(t===``)return e;let n=e;for(let e of t.slice(1).split(`/`)){let t=e.replaceAll(`~1`,`/`).replaceAll(`~0`,`~`);if(typeof n!=`object`||!n||!Object.hasOwn(n,t))return;n=n[t]}return er(n)?n:void 0},Nm=(e,...t)=>e+t.map(e=>`/${String(e).replaceAll(`~`,`~0`).replaceAll(`/`,`~1`)}`).join(``),Pm=e=>typeof e==`object`&&!!e,Fm=(e,t)=>t.reduce((e,t)=>Pm(e)&&Object.hasOwn(e,t)?e[t]:void 0,e),Im=(e,t)=>{let n=pr(t);if(!n)return;if(n.kind===`data`){if(n.variable===`root`)return e.root===void 0?void 0:Fm(e.root,n.names);if(n.variable===`params`)return e.params&&Object.hasOwn(e.params,n.names[0])?e.params[n.names[0]]:void 0;let t=e.stack.findLast(e=>e.row!==void 0)?.row;return t?n.variable===`index`?t.index:n.variable===`first`?t.index===0:t.index===t.count-1:void 0}let r=[...e.root===void 0?[]:[e.root],...e.stack.map(e=>e.record)];if(n.explicit){let e=r[r.length-1-n.up];return e===void 0?void 0:Fm(e,n.names)}let[i,...a]=n.names,o=r.findLast(e=>Pm(e)&&Object.hasOwn(e,i));return Pm(o)?Fm(o[i],a):void 0},Lm=e=>t=>Im(e,t),Rm=e=>e===void 0?null:typeof e==`string`||typeof e==`number`||typeof e==`boolean`||e===null?e:Sr(e),zm=(e,t)=>Object.fromEntries(Object.entries(e).map(([e,n])=>{let r=typeof n==`string`?Ir(n):void 0;return[e,r===void 0?Hm(n,t):Rm(t(r))]})),Bm=[`title`,`description`,`empty`,`label`,`recordKey`],Vm=[`filter`,`when`,`working`,`edgeFilter`,`animated`,`dashed`,`dotted`],Hm=(e,t)=>typeof e==`string`?cr(e,e=>Sr(t(e))):Array.isArray(e)?e.map(e=>Hm(e,t)):Pm(e)?Object.fromEntries(Object.entries(e).map(([e,n])=>[e,Hm(n,t)])):e,Um=(e,t)=>{if(e.custom||!JSON.stringify(e.props).includes(`{{`))return e;let n=Lm(t),r={...e.props};for(let e of Bm)typeof r[e]==`string`&&(r[e]=cr(r[e],e=>Sr(n(e))));for(let e of Bm){let n=r[e];er(n)&&n.type===`Trans`&&(r[e]=Um(n,t))}for(let e of Vm)typeof r[e]==`string`&&(r[e]=lr(r[e],n));return Pm(r.filter)&&(r.filter=zm(r.filter,n)),r.values!==void 0&&(r.values=Hm(r.values,n)),Pm(r.calls)&&typeof r.calls.filter==`string`&&(r.calls={...r.calls,filter:lr(r.calls.filter,n)}),{...e,props:r}},Wm=(e,t)=>{if(!e.custom||!e.reads)return e;let n=Lm(t),r={...e.props},i=new Set(ep(e.reads).flatMap(({filter:e})=>e===void 0?[]:[e]));for(let t of i){let i=e.props[t];typeof i==`string`?r[t]=lr(i,n):Pm(i)&&(r[t]=zm(i,n))}return{...e,props:r}},Gm=(e,t)=>e.filter===void 0?e:{...e,filter:lr(e.filter,Lm({stack:[],...t}))},Km=(e,t)=>{let n=new Map(t.reads.map(e=>[dm(e),e])),r=[e.resource];for(let t=e.split&&n.get(e.split.parent);t;t=t.split&&n.get(t.split.parent))r.push(t.resource);return r},qm=(e,t,n)=>{if(!e.split)return t;let r=Im(n,e.split.source);if(r==null||r===``)return[];let i=e.kind===`aggregate`?`value`:e.split.field,a=new Set((Array.isArray(r)?r:[r]).map(String));return t.filter(e=>a.has(String(e[i])))},Jm=class extends Error{status;code;constructor(e,t,n){super(e),this.status=t,this.code=n,this.name=`AuthError`}},K=(e,t)=>new Jm(e?.message||t,e?.status??500,e?.code),Ym=e=>new Date(e).toISOString(),Xm=e=>({updateName:async t=>{let{error:n}=await e.updateUser({name:t});if(n)throw K(n,`Could not change your name`)},changePassword:async(t,n)=>{let{error:r}=await e.changePassword({currentPassword:t,newPassword:n,revokeOtherSessions:!0});if(r)throw K(r,`Could not change your password`)},setPassword:async t=>{let{error:n}=await e.$fetch(`/account/set-password`,{method:`POST`,body:{newPassword:t}});if(n)throw K(n,`Could not set your password`)},requestEmailChange:async t=>{let{error:n}=await e.$fetch(`/email-otp/request-email-change`,{method:`POST`,body:{newEmail:t}});if(n)throw K(n,`Could not send the code`)},changeEmail:async(t,n)=>{let{error:r}=await e.$fetch(`/email-otp/change-email`,{method:`POST`,body:{newEmail:t,otp:n}});if(r)throw K(r,`Could not change your address`)},sessions:async()=>{let[t,n]=await Promise.all([e.listSessions(),e.getSession()]);if(t.error||!t.data)throw K(t.error,`Could not read your devices`);let r=n.data?.session.token;return t.data.map(e=>{let t=e.impersonatedBy;return{token:e.token,current:e.token===r,...e.userAgent&&{userAgent:e.userAgent},...e.ipAddress&&{ipAddress:e.ipAddress},createdAt:Ym(e.createdAt),updatedAt:Ym(e.updatedAt),expiresAt:Ym(e.expiresAt),...t&&{staff:t}}})},revokeSession:async t=>{let{error:n}=await e.revokeSession({token:t});if(n)throw K(n,`Could not sign out the device`)},revokeOtherSessions:async()=>{let{error:t}=await e.revokeOtherSessions();if(t)throw K(t,`Could not sign out your other devices`)},deviceLinks:async()=>{let{data:t,error:n}=await e.$fetch(`/account/device-links`,{method:`GET`});if(n||!t)throw K(n,`Could not read your devices`);return t.links},signOutDeviceLink:async t=>{let{error:n}=await e.$fetch(`/account/device-links/sign-out`,{method:`POST`,body:{id:t}});if(n)throw K(n,`Could not sign out the device`)}}),Zm=e=>({signInMethods:async()=>{let{data:t,error:n}=await e.$fetch(`/account/sign-in-methods`);if(n||!t)throw K(n,`Could not read your sign-in methods`);return t},passkeys:async()=>{let{data:t,error:n}=await e.passkey.listUserPasskeys();if(n||!t)throw K(n,`Could not read your passkeys`);return t.map(e=>({id:e.id,backedUp:e.backedUp,...e.name&&{name:e.name},...e.createdAt&&{createdAt:new Date(e.createdAt).toISOString()}}))},addPasskey:async t=>{let{error:n}=await e.passkey.addPasskey(t?{name:t}:{});if(n)throw K(n,`Could not add the passkey`)},renamePasskey:async(t,n)=>{let{error:r}=await e.passkey.updatePasskey({id:t,name:n});if(r)throw K(r,`Could not rename the passkey`)},removePasskey:async t=>{let{error:n}=await e.passkey.deletePasskey({id:t});if(n)throw K(n,`Could not remove the passkey`)},startAuthenticatorApp:async t=>{let{data:n,error:r}=await e.twoFactor.enable({method:`totp`,...t&&{password:t}});if(r||n?.method!==`totp`)throw K(r,`Could not start two-factor authentication`);return{totpURI:n.totpURI,backupCodes:n.backupCodes}},confirmAuthenticatorApp:async t=>{let{error:n}=await e.twoFactor.verifyTotp({code:t});if(n)throw K(n,`The code did not work`)},turnOnEmailedCodes:async t=>{let{error:n}=await e.twoFactor.enable({method:`otp`,...t&&{password:t}});if(n)throw K(n,`Could not turn on two-factor authentication`)},turnOffTwoFactor:async t=>{let{error:n}=await e.twoFactor.disable(t?{password:t}:{});if(n)throw K(n,`Could not turn off two-factor authentication`)},linkedProviders:async()=>{let{data:t,error:n}=await e.listAccounts();if(n||!t)throw K(n,`Could not read your linked accounts`);return[...new Set(t.map(e=>e.providerId).filter(e=>e!==`credential`))]},linkProvider:async(t,n)=>{let{data:r,error:i}=await e.linkSocial({provider:t,callbackURL:n,errorCallbackURL:n,disableRedirect:!0});if(i||!r?.url)throw K(i,`Could not start linking the account`);return r.url},linkedPersonalMail:async t=>{let{data:n,error:r}=await e.listAccounts();if(r||!n)throw K(r,`Could not read your linked accounts`);return t.filter(e=>n.some(t=>t.providerId===e.provider&&e.scopes.every(e=>t.scopes.includes(e)))).map(e=>e.id)},linkPersonalMail:async(t,n)=>{let{data:r,error:i}=await e.linkSocial({provider:t.provider,scopes:t.scopes,additionalParams:t.params,callbackURL:n,errorCallbackURL:n,disableRedirect:!0});if(i||!r?.url)throw K(i,`Could not start linking the mailbox`);return r.url},workflowConnections:async()=>{let{data:t,error:n}=await e.$fetch(`/connections`);if(n?.status===404)return[];if(n||!t)throw K(n,`Could not read your connections`);return t.connections},connectAccount:async(t,n)=>{let{data:r,error:i}=await e.linkSocial({provider:t.provider,scopes:t.scopes,additionalParams:t.link_params,callbackURL:n,errorCallbackURL:n,disableRedirect:!0});if(i||!r?.url)throw K(i,`Could not start connecting the account`);return r.url},disconnectAccount:async t=>{let{data:n,error:r}=await e.$fetch(`/connections/disconnect`,{method:`POST`,body:{accountId:t}});if(r||!n)throw K(r,`Could not disconnect the account`);return n.revocation},connectedApps:async()=>{let{data:t,error:n}=await e.$fetch(`/account/connected-apps`);if(n||!t)throw K(n,`Could not read your connected apps`);return t.apps},disconnectApp:async t=>{let{error:n}=await e.$fetch(`/account/connected-apps/disconnect`,{method:`POST`,body:{clientId:t}});if(n)throw K(n,`Could not disconnect the app`)},sendConfirmationCode:async()=>{let{error:t}=await e.$fetch(`/account/confirmation-code/send`,{method:`POST`});if(t)throw K(t,`Could not email a code`)},confirmWithCode:async t=>{let{error:n}=await e.$fetch(`/account/confirmation-code/verify`,{method:`POST`,body:{code:t}});if(n)throw K(n,`The code did not work`)},confirmWithPassword:async t=>{let{error:n}=await e.$fetch(`/account/confirm-password`,{method:`POST`,body:{password:t}});if(n)throw K(n,`The password did not work`)},newBackupCodes:async t=>{let{data:n,error:r}=await e.twoFactor.generateBackupCodes(t?{password:t}:{});if(r||!n)throw K(r,`Could not make new backup codes`);return n.backupCodes}}),Qm=e=>({mailSenders:async()=>{let{data:t,error:n}=await e.$fetch(`/account/mail-senders`);if(n||!t)throw K(n,`Could not read your From addresses`);return t},addMailSender:async t=>{let{data:n,error:r}=await e.$fetch(`/account/mail-senders/add`,{method:`POST`,body:t});if(r||!n)throw K(r,`Could not add the From address`);return n.sender},updateMailSender:async(t,n)=>{let{data:r,error:i}=await e.$fetch(`/account/mail-senders/update`,{method:`POST`,body:{id:t,...n}});if(i||!r)throw K(i,`Could not change the From address`);return r.sender},removeMailSender:async t=>{let{error:n}=await e.$fetch(`/account/mail-senders/remove`,{method:`POST`,body:{id:t}});if(n)throw K(n,`Could not remove the From address`)}}),$m=e=>({personalAccessTokens:async()=>{let{data:t,error:n}=await e.$fetch(`/account/personal-access-tokens`);if(n||!t)throw K(n,`Could not read your access tokens`);return t.tokens},createPersonalAccessToken:async t=>{let{data:n,error:r}=await e.$fetch(`/account/personal-access-tokens/create`,{method:`POST`,body:t});if(r||!n)throw K(r,`Could not make the access token`);return n},revokePersonalAccessToken:async t=>{let{error:n}=await e.$fetch(`/account/personal-access-tokens/revoke`,{method:`POST`,body:{id:t}});if(n)throw K(n,`Could not revoke the access token`)}}),eh=(e,t)=>new Jm(e?.message||e?.error_description||t,e?.status??500,e?.code??e?.error),th=e=>({client:async t=>{let{data:n,error:r}=await e.$fetch(`/oauth2/public-client`,{query:{client_id:t}});if(r||!n)throw eh(r,`Could not read the app asking`);return n},resume:async t=>{let{data:n,error:r}=await e.$fetch(`/oauth2/continue`,{method:`POST`,body:{postLogin:!0,oauth_query:t}});if(r||!n?.url)throw eh(r,`Could not go on with the request`);return{url:n.url}},answer:async(t,n)=>{let{data:r,error:i}=await e.$fetch(`/oauth2/consent`,{method:`POST`,body:{accept:t,oauth_query:n}});if(i||!r?.url)throw eh(i,`Could not answer the request`);return{url:r.url}}}),nh=(e,t,n)=>qt({baseURL:e,basePath:t,plugins:[Qt(),an(),kt(),Nt()],disableDefaultFetchPlugins:!0,fetchOptions:{customFetchImpl:n}}),rh=e=>Array.isArray(e)?e.filter(e=>typeof e==`string`):typeof e==`string`?JSON.parse(e):[],ih=e=>{let t=e.split(`,`);return t.includes(`owner`)?`owner`:t.includes(`admin`)?`admin`:`member`},ah=e=>({id:e.id,userId:e.userId,name:e.user.name||e.user.email,email:e.user.email,role:ih(e.role),appRoles:rh(e.appRoles),createdAt:new Date(e.createdAt).toISOString()}),oh=e=>({id:e.id,email:e.email,role:ih(e.role),appRoles:rh(e.appRoles),status:e.status,expiresAt:new Date(e.expiresAt).toISOString(),...e.organizationName&&{organizationName:e.organizationName}}),sh=(e,t)=>{let n=async(t,n,r={})=>{let{data:i,error:a}=await e.$fetch(t,{method:r.method??(r.body?`POST`:`GET`),...r.body&&{body:r.body},...r.query&&{query:r.query}});if(a)throw K(a,n);return i},r=async e=>(await t(),e);return{list:async()=>await n(`/organization/list`,`Could not read your organizations`)??[],current:()=>n(`/organization/current`,`Could not read the current organization`),switchTo:async e=>r(await n(`/organization/switch`,`Could not switch the organization`,{body:{organizationId:e}})),search:(e,t=0)=>n(`/organization/search`,`Could not search the organizations`,{query:{query:e,...t>0&&{offset:String(t)}}}),create:async e=>r(await n(`/organization/create`,`Could not create the organization`,{body:e})),rename:(e,t)=>n(`/organization/update`,`Could not change the organization`,{body:{organizationId:e,data:t}}),remove:async e=>r(await n(`/organization/delete`,`Could not delete the organization`,{body:{organizationId:e}})),leave:async e=>r(await n(`/organization/leave`,`Could not leave the organization`,{body:{organizationId:e}})),members:async e=>(await n(`/organization/list-members`,`Could not read the members`,{query:{organizationId:e,limit:`1000`}})).members.map(ah),people:async()=>(await n(`/organization/people`,`Could not read the people`)).people,setRole:(e,t,r)=>n(`/organization/update-member-role`,`Could not change the role`,{body:{organizationId:e,memberId:t,role:r}}),setAppRoles:(e,t)=>n(`/organization/set-app-roles`,`Could not change the app roles`,{body:{memberId:e,appRoles:t}}),removeMember:(e,t)=>n(`/organization/remove-member`,`Could not remove the member`,{body:{organizationId:e,memberIdOrEmail:t}}),transferOwnership:(e,t=`admin`)=>n(`/organization/transfer-ownership`,`Could not hand the organization over`,{body:{memberId:e,keepAs:t}}),invitations:async e=>(await n(`/organization/list-invitations`,`Could not read the invitations`,{query:{organizationId:e}})??[]).map(oh),invite:async(e,t)=>{let r=await n(`/organization/invite-member`,`Could not send the invitation`,{body:{organizationId:e,...t}});return{invitation:oh(r),...r.link&&{link:r.link}}},resend:async(e,t)=>{let r=await n(`/organization/invite-member`,`Could not send the invitation again`,{body:{organizationId:e,email:t.email,role:t.role,resend:!0}});return{invitation:oh(r),...r.link&&{link:r.link}}},revoke:e=>n(`/organization/cancel-invitation`,`Could not revoke the invitation`,{body:{invitationId:e}}),myInvitations:async()=>(await n(`/organization/list-user-invitations`,`Could not read your invitations`)??[]).map(oh),invitation:e=>n(`/invitation`,`This invitation link is not valid`,{query:{token:e}}),accept:async e=>r(await n(`/invitation/accept`,`Could not accept the invitation`,{body:{token:e}})),acceptMine:async e=>r(await n(`/invitation/accept-own`,`Could not accept the invitation`,{body:{invitationId:e}})),signUpFromInvitation:async(e,t)=>r(await n(`/invitation/sign-up`,`Could not create your account`,{body:{token:e,...t}}))}},ch=(e,t)=>({current:async()=>{let{data:t,error:n}=await e.$fetch(`/role/current`,{method:`GET`});if(n)throw K(n,`Could not read your roles`);return t},switchTo:async n=>{let{error:r}=await e.$fetch(`/role/switch`,{method:`POST`,body:{role:n}});if(r)throw K(r,`Could not switch the role`);await t()}}),lh=20,uh=e=>Array.isArray(e)?e:(e??``).split(`,`).map(e=>e.trim()).filter(Boolean),dh=e=>({id:e.id,name:e.name||e.email,email:e.email,roles:uh(e.role),blocked:!!e.banned,createdAt:new Date(e.createdAt).toISOString()}),fh=e=>({id:e.id,email:e.email,roles:e.roles,expiresAt:new Date(e.expiresAt).toISOString()}),ph=e=>({invitation:fh(e),...e.link&&{link:e.link}}),mh=e=>{let t=async(t,n,r={})=>{let{data:i,error:a}=await e.$fetch(t,{method:r.body?`POST`:`GET`,...r.body&&{body:r.body},...r.query&&{query:r.query}});if(a)throw K(a,n);return i};return{search:async(e,n=0)=>{let r=await t(`/admin/list-users`,`Could not read the users`,{query:{limit:String(lh),sortBy:`createdAt`,sortDirection:`asc`,...n>0&&{offset:String(n)},...e&&{searchValue:e,searchField:`email`}}});return{users:r.users.map(dh),total:r.total}},create:async e=>dh((await t(`/admin/create-user`,`Could not create the account`,{body:{email:e.email,name:e.name,role:e.roles,...e.password&&{password:e.password}}})).user),setRoles:(e,n)=>t(`/admin/set-role`,`Could not change the roles`,{body:{userId:e,role:n}}),block:e=>t(`/admin/ban-user`,`Could not block the account`,{body:{userId:e}}),unblock:e=>t(`/admin/unban-user`,`Could not unblock the account`,{body:{userId:e}}),invite:async e=>ph(await t(`/users/invite`,`Could not send the invitation`,{body:e})),invitations:async()=>(await t(`/users/invitations`,`Could not read the invitations`)).invitations.map(fh),revoke:e=>t(`/users/invitations/cancel`,`Could not revoke the invitation`,{body:{id:e}}),roles:()=>t(`/users/roles`,`Could not read the roles`)}},hh=(e,t)=>{let n=async e=>e?.twoFactorRedirect?{kind:`two-factor`,methods:e.twoFactorMethods??[]}:(await t(),{kind:`signed-in`,user:e?.user});return{signIn:async(t,r)=>{let{data:i,error:a}=await e.signIn.email({email:t,password:r});if(a||!i)throw K(a,`Sign-in failed`);return n(i)},sendSignInCode:async t=>{let{error:n}=await e.emailOtp.sendVerificationOtp({email:t,type:`sign-in`});if(n)throw K(n,`Could not send the code`)},signInWithCode:async(t,r)=>{let{data:i,error:a}=await e.signIn.emailOtp({email:t,otp:r});if(a||!i)throw K(a,`Sign-in failed`);return n(i)},sendSignUpCode:async t=>{let{error:n}=await e.$fetch(`/sign-up/send-code`,{method:`POST`,body:{email:t}});if(n)throw K(n,`Could not send the code`)},verifySignUpCode:async(t,n)=>{let{data:r,error:i}=await e.$fetch(`/sign-up/verify-code`,{method:`POST`,body:{email:t,code:n}});if(i||!r)throw K(i,`Could not check the code`);return r.ticket},signUp:async n=>{let{data:r,error:i}=await e.$fetch(`/sign-up/create`,{method:`POST`,body:n});if(i||!r)throw K(i,`Could not create your account`);return await t(),r.user},signInWithPasskey:async n=>{let r=await e.$fetch(`/passkey/generate-authenticate-options`,{method:`GET`,...n&&{query:{rpId:n}}});if(r.error||!r.data)throw K(r.error,`Sign-in failed`);let{clientExtensionResults:i,...a}=await ln({optionsJSON:r.data}).catch(e=>{throw new Jm(`Auth cancelled`,400,e instanceof Ft?e.code:`AUTH_CANCELLED`)}),o=await e.$fetch(`/passkey/verify-authentication`,{method:`POST`,body:{response:a}});if(o.error||!o.data)throw K(o.error,`Sign-in failed`);return await t(),o.data.user},sendTwoFactorCode:async()=>{let{error:t}=await e.twoFactor.sendOtp();if(t)throw K(t,`Could not send the code`)},verifyTwoFactor:async({method:n,code:r,trustDevice:i=!1})=>{let{data:a,error:o}=await(n===`totp`?e.twoFactor.verifyTotp:n===`otp`?e.twoFactor.verifyOtp:e.twoFactor.verifyBackupCode)({code:r,trustDevice:i});if(o||!a)throw K(o,`The code did not work`);return await t(),a.user}}},gh=e=>({read:async()=>{let{data:t,error:n}=await e.$fetch(`/policy/sign-in`);if(n||!t)throw K(n,`Could not read the sign-in policy`);return t},save:async t=>{let{data:n,error:r}=await e.$fetch(`/policy/sign-in`,{method:`POST`,body:t});if(r||!n)throw K(r,`Could not save the sign-in policy`);return n}}),_h=e=>new Date(e).toISOString(),vh=({startedAt:e,expiresAt:t,endedAt:n,...r})=>({...r,startedAt:_h(e),expiresAt:_h(t),...n&&{endedAt:_h(n)}}),yh=e=>({start:async t=>{let{data:n,error:r}=await e.$fetch(`/staff/sign-in`,{method:`POST`,body:t});if(r||!n?.url)throw K(r,`Could not start the staff sign-in`);return n.url},current:async()=>{let{data:t,error:n}=await e.$fetch(`/staff/session`);if(n||!t)throw K(n,`Could not read the session`);return t.staff?vh(t.staff):void 0},stop:async()=>{let{error:t}=await e.$fetch(`/staff/stop`,{method:`POST`,body:{}});if(t)throw K(t,`Could not end the staff session`)},log:async()=>{let{data:t,error:n}=await e.$fetch(`/staff/sign-ins`);if(n||!t)throw K(n,`Could not read the staff sign-ins`);return t.signIns.map(vh)}}),bh=e=>{let t=e.split(`.`)[1];if(!t)throw Error(`Not a JWT`);let n=JSON.parse(atob(t.replace(/-/g,`+`).replace(/_/g,`/`)));if(typeof n.exp!=`number`)throw Error(`The token has no expiry`);return n.exp*1e3},xh=(e={})=>{let t=e.origin??globalThis.location?.origin??`http://localhost`,n=e.basePath??`/api/auth`,r=e.refreshMarginMs??6e4,i=e.fetch??((e,t)=>fetch(e,t)),a=nh(t,n,i),o=yh(a),s,c,l,u=()=>{s=void 0,clearTimeout(l)},d=async()=>{let{data:t}=await a.$fetch(`/token`);if(!t?.token){u();return}return s={token:t.token,expiresAt:bh(t.token)},clearTimeout(l),l=setTimeout(()=>void f({refresh:!0}).then(t=>t||e.onSignedOut?.()),Math.max(1e3,s.expiresAt-Date.now()-r)),s.token},f=async({refresh:e=!1}={})=>!e&&s&&s.expiresAt-Date.now()>r?s.token:(c??=d().finally(()=>{c=void 0}),c);return{token:f,status:async()=>{let e=await i(`${t}${n}/status`);if(e.status===404)throw new Jm(`This server has no sign-in. Is the API URL right?`,404);if(!e.ok)throw new Jm(`Could not read the sign-in status`,e.status);let r=await e.json();return{needsAdmin:!!r.needsAdmin,...r.needsAdmin&&r.firstAdminUrl&&{firstAdminUrl:r.firstAdminUrl},signInMethods:r.signInMethods??[`password`],...r.signInFirst===`emailCode`&&{signInFirst:`emailCode`},passwordReset:!!r.passwordReset,...r.changeEmail&&{changeEmail:!0},...r.accountDeletion&&{accountDeletion:!0},...r.signUp&&{signUp:!0},...r.signUp&&r.signUpFields&&{signUpFields:r.signUpFields},socialProviders:r.socialProviders??[],...r.platformProviders&&{platformProviders:r.platformProviders},...r.deviceLinks&&{deviceLinks:!0},samlProviders:r.samlProviders??[],...r.staffSignIn&&{staffSignIn:r.staffSignIn},...r.passkeyDomains&&{passkeyDomains:r.passkeyDomains},...r.organizations&&{organizations:r.organizations},...r.anonymous&&{anonymous:!0},...r.mcp&&{mcp:{url:r.mcp.url}},...r.personalAccessTokens&&{personalAccessTokens:!0},...r.personalMail&&r.personalMail.length>0&&{personalMail:r.personalMail},...r.plugins&&r.plugins.length>0&&{plugins:r.plugins},...si(r.locale)&&{locale:r.locale}}},session:async()=>{let{data:e,error:t}=await a.getSession();if(t&&t.status!==401)throw K(t,`Could not read your session`);return e?.user},...hh(a,()=>f({refresh:!0})),signInSocial:async(e,t)=>{let{data:n,error:r}=await a.signIn.social({provider:e,callbackURL:t,errorCallbackURL:t,disableRedirect:!0});if(r||!n?.url)throw K(r,`Sign-in failed`);return n.url},signInSaml:async(e,t)=>{let{data:n,error:r}=await a.$fetch(`/sign-in/sso`,{method:`POST`,body:{providerId:e,callbackURL:t,errorCallbackURL:t}});if(r||!n?.url)throw K(r,`Sign-in failed`);return n.url},signOut:async()=>{u(),await a.signOut()},deleteAccount:async e=>{let{error:t}=await a.deleteUser(e?{password:e}:{});if(t)throw K(t,`Could not delete your account`);u()},requestPasswordReset:async(e,t)=>{let{error:n}=await a.requestPasswordReset({email:e,redirectTo:t});if(n)throw K(n,`Could not send the reset link`)},resetPassword:async(e,t)=>{let{error:n}=await a.resetPassword({token:e,newPassword:t});if(n)throw K(n,`Could not set the password`)},account:{...Zm(a),...Xm(a),...$m(a),...Qm(a)},connect:th(a),organizations:sh(a,()=>f({refresh:!0})),roles:ch(a,()=>f({refresh:!0})),signInPolicy:gh(a),users:mh(a),staff:{...o,stop:async()=>{u(),await o.stop()}}}},Sh=e=>Math.min(3e4,1e3*2**e),Ch=(e,t)=>new Promise(n=>{let r=setTimeout(n,e);t.addEventListener(`abort`,()=>{clearTimeout(r),n()},{once:!0})}),wh=`http://same-origin.invalid`,Th=(e,t)=>{let n=new URL(e,wh),r=new URL(t,`${n.href}/`);if(r.origin!==n.origin)throw Error(`${t} is not on the assistant backend's origin`);return n.origin===wh?`${r.pathname}${r.search}`:r.href},Eh=e=>{let t=e.url.replace(/\/+$/,``),n=e.fetch??((e,t)=>fetch(e,t)),r=e.retryDelayMs??Sh,i=async(r,i)=>{let a=await e.token(),o=await n(`${t}${r}`,{method:i.method,headers:{...i.body===void 0?{accept:`text/event-stream`}:{"content-type":`application/json`},...a&&{authorization:`Bearer ${a}`}},body:i.body===void 0?void 0:JSON.stringify(i.body),signal:i.signal});if(!o.ok)throw await Rn(o);return o},a=async(e,t,n)=>{let r=await i(`/events`,{method:`GET`,signal:e});if(!r.body)throw Error(`The assistant backend answered the event stream without a body`);n(),await Cn(r.body,e=>t(JSON.parse(e)),e)};return{connect:(e,t)=>{let n=new AbortController,{signal:i}=n;return(async()=>{let n=0;for(;!i.aborted;){t?.({state:`connecting`});let o=await a(i,e,()=>{n=0,t?.({state:`open`})}).then(()=>void 0,e=>e??Error(`The assistant stream failed`));if(i.aborted)return;t?.({state:`retrying`,...o!==void 0&&{error:o}}),await Ch(r(n++),i)}})(),()=>n.abort()},send:async(e,t)=>{await i(`/messages`,{method:`POST`,body:{text:e,...t&&{page:t}}})},act:async(e,t)=>{await i(`/actions`,{method:`POST`,body:{partId:e,actionId:t}})},fetch:async(r,i={})=>{let a=Th(t,r),o=await e.token(),s=new Headers(i.headers);o&&s.set(`authorization`,`Bearer ${o}`);let c=await n(a,{...i,headers:s});if(!c.ok)throw await Rn(c);return c}}},Dh=e=>typeof e==`object`&&!!e&&`error`in e&&typeof e.error==`object`&&e.error!==null&&`code`in e.error&&`message`in e.error,Oh=async e=>{let t=e.headers.get(`content-type`)?.includes(`json`)??!1?await e.clone().json():void 0;return Dh(t)?new An({type:`urn:protobase:problem:${t.error.code}`,title:e.statusText||`Request failed`,status:e.status,detail:t.error.message}):Rn(e)},kh=e=>{let t=e.url.replace(/\/+$/,``),n=e.fetch??((e,t)=>fetch(e,t)),r=async(r,i)=>{let a=await e.token(),o=await n(`${t}${r}`,{method:i,headers:{accept:`application/json`,...a&&{authorization:`Bearer ${a}`}}});if(!o.ok)throw await Oh(o);return await o.json()};return{status:()=>r(``,`GET`),update:()=>r(`/update`,`POST`)}},q=e(r(),1),Ah=e=>e.Capacitor?.isNativePlatform()?e.Capacitor:void 0,jh=[101,204,205,304],Mh=/%2f|%5c/i,Nh=e=>Object.hasOwn(Xo,e),Ph=(e,t)=>e.origin===t&&!e.username&&!e.password&&e.pathname.startsWith(`/api/auth/`)&&!Mh.test(e.pathname),Fh=({status:e,headers:t,data:n})=>jh.includes(e)?null:Object.entries(t).some(([e,t])=>e.toLowerCase()===`content-type`&&t.startsWith(`application/json`))?JSON.stringify(n):typeof n==`string`?n:JSON.stringify(n),Ih=(e,t)=>{let n=e.getPlatform();if(!Nh(n))throw Error(`Signing in through native HTTP is for iOS and Android, not ${n}`);return async(n,r)=>{let i=new Request(n,r),a=new URL(i.url);if(!Ph(a,t))throw Error(`Native sign-in requests go to ${t}${Jo}/ only, not ${i.url}`);let o=i.method!==`GET`&&i.method!==`HEAD`,s=await e.nativePromise(`ProtobaseAuth`,`request`,{url:a.href,method:i.method,headers:Object.fromEntries(i.headers),...o&&{data:await i.text()}}),c=Object.entries(s.headers).filter(([e])=>e.toLowerCase()!==`set-cookie`);return new Response(Fh(s),{status:s.status,headers:c})}},Lh,Rh,zh=({dsn:e,environment:t})=>(Lh??=Ht(()=>import(`./lib-sentry-browser-rsfK9tDJ.js`).then(e=>e.t).then(n=>{n.init({dsn:e,...t&&{environment:t},integrations:e=>[...e.filter(e=>e.name!==`BrowserSession`),n.thirdPartyErrorFilterIntegration({filterKeys:[zo],behaviour:`drop-error-if-exclusively-contains-third-party-frames`})],beforeSend:e=>Ro(e)}),Rh=(e,t)=>n.captureException(e,t?{contexts:{react:{componentStack:t}}}:void 0)}),__vite__mapDeps([0,1])),Lh),Bh=(e,t)=>Rh?.(e,t??void 0),Vh=e=>Rh?.(e),Hh=class extends Error{reason;constructor(e){super(`The push service gave the app no push token: ${e}`),this.reason=e,this.name=`PushRegistrationError`}},Uh=class extends Error{service;constructor(e,t){super(`The push service gave the app no push token within ${t} ms`),this.service=e}},Wh=class extends Error{constructor(){super(`Push is off, but this device could not store that the user turned it off`)}},Gh=e=>e instanceof Hh?{kind:`registration`,reason:e.reason}:e instanceof Uh?{kind:`no-token`,service:e.service}:e instanceof Wh?{kind:`off-not-stored`}:e instanceof An?{kind:`refused`,reason:e.message}:{kind:`other`,reason:e instanceof Error?e.message:String(e)},Kh=`PushNotifications`,qh=(e,t)=>Promise.race([t,new Promise(t=>setTimeout(t,e))]),Jh=class extends Error{},Yh=(e,t)=>e instanceof An&&e.status===409&&e.slug===t,Xh=({bridge:e,device:t,records:n,choices:r,permissionAsked:i,devices:a,user:o,userAgent:s,waitMs:c=3e3,tokenMs:l=15e3,report:u})=>{let d=(t,n={})=>e.nativePromise(Kh,t,n),f=async()=>(await d(`checkPermissions`)).receive,p=()=>new Promise((t,n)=>{let r=[],i=e=>{clearTimeout(a);for(let e of r)e.remove();r=[],e()},a=setTimeout(()=>i(()=>n(new Uh(e.getPlatform()===`ios`?`apns`:`fcm`,l))),l);r=[e.addListener(Kh,`registration`,e=>i(()=>t(e.value))),e.addListener(Kh,`registrationError`,e=>i(()=>n(new Hh(e.error))))],d(`register`).catch(e=>i(()=>n(e)))}),m=async()=>{await n.clear(),await d(`removeAllDeliveredNotifications`),await d(`unregister`)},h=async e=>{u(e),await m()},g=async e=>{let n=()=>o()?.id===e.id&&o()?.own===!0,r=await p();if(!n())throw new Jh;let i=await a.register({...await t(r),userAgent:s,userId:e.id});if(!n())throw new Jh;return{device:i,token:r}},_=async()=>{let e=await f();if(e===`denied`)return`blocked`;let[t,r]=[o(),await n.read()];return t&&e===`granted`&&r?.userId===t.id?`on`:`off`},v=async()=>{let e=o();if(!e?.own)return _();let t=await f();if((t===`prompt`||t===`prompt-with-rationale`)&&(t=(await d(`requestPermissions`)).receive),t!==`granted`)return _();r.set(e.id,`on`);let i=async()=>{let{device:t,token:r}=await g(e);await n.write({userId:e.id,endpoint:r,deviceId:t.id})};try{await i()}catch(e){if(e instanceof Hh)throw await h(e),e;if(await m(),e instanceof Jh)return`off`;if(!Yh(e,`device-held`))throw e;try{await i()}catch(e){if(e instanceof Hh)throw await h(e),e;if(await m(),e instanceof Jh)return`off`;throw e}}return`on`},y=async({chosen:e=!1}={})=>{let t=o(),i=!e||!t?.own||r.set(t.id,`off`);if(await b(await n.read()),!i)throw new Wh},b=async e=>{await n.clear(),await qh(c,Promise.allSettled([d(`removeAllDeliveredNotifications`),d(`unregister`),e?.deviceId?a.remove(e.deviceId):Promise.resolve()]))},x=async()=>{await n.clear(),await qh(c,Promise.allSettled([d(`removeAllDeliveredNotifications`),d(`unregister`)]))},S=e=>{let t=r.of(e);return t===void 0?i:t===`on`};return{state:_,turnOn:v,turnOff:y,forget:x,adopt:async e=>{let t=await n.read();if(t&&t.userId!==e.id)return m();if(e.own){if(t&&r.of(e.id)===`off`)return b(t);if(t||S(e.id)){if(await f()!==`granted`)return t&&m();try{let{device:r,token:i}=await g(e);await n.write({userId:e.id,endpoint:i,deviceId:r.id}),t?.deviceId&&t.deviceId!==r.id&&await a.remove(t.deviceId)}catch(e){if(e instanceof Jh)return;if(e instanceof Hh)return h(e);if(!Yh(e,`device-held`)&&!Yh(e,`other-user`))throw e;await m()}}}}}},Zh=`ProtobasePush`,Qh=e=>{if(!e.isPluginAvailable(`PushNotifications`))return;let t=e.getPlatform();if(t===`android`)return async e=>({kind:`fcm`,token:e});if(t===`ios`&&e.isPluginAvailable(`ProtobasePush`))return async t=>{let{appId:n,environment:r}=await e.nativePromise(Zh,`apns`,{});return{kind:`apns`,token:t.toLowerCase(),appId:n,environment:r}}},$h=e=>e.replace(/[\u0000-\u001f\u007f]/g,``).slice(0,512),eg=(e=window)=>{let{navigator:t}=e;return{supported:`serviceWorker`in t&&`PushManager`in e&&`Notification`in e&&`userActivation`in t,permission:()=>e.Notification.permission,requestPermission:()=>e.Notification.requestPermission(),activated:()=>t.userActivation.isActive,existingRegistration:()=>t.serviceWorker.getRegistration(`/`),registration:async()=>(await t.serviceWorker.getRegistration(`/`)||await t.serviceWorker.register(`/${Qo}`),t.serviceWorker.ready),clearBadge:async()=>{`clearAppBadge`in t&&await t.clearAppBadge()},userAgent:$h(t.userAgent)}},tg=/\bAndroid (\d+)/,ng=(e,t)=>{if(e===`ios`)return!0;let n=tg.exec(t)?.[1];return e===`android`&&n!==void 0&&Number(n)>=13},rg=`protobase:push-choices`,ig=e=>{let t=new Map,n=()=>{try{let t=JSON.parse(e().getItem(rg)??`{}`);return typeof t==`object`&&t&&!Array.isArray(t)?t:void 0}catch{return}};return{of:e=>{let r=t.get(e);if(r)return r;let i=n();if(!i)return`unknown`;let a=Object.hasOwn(i,e)?i[e]:void 0;return a===`on`||a===`off`?a:void 0},set:(r,i)=>{t.set(r,i);try{return e().setItem(rg,JSON.stringify({...n(),[r]:i})),!0}catch{return!1}}}},ag=(e=indexedDB)=>{let t=(t,n)=>new Promise((r,i)=>{let a=e.open(Zo.database,1);a.onupgradeneeded=()=>a.result.createObjectStore(Zo.store),a.onerror=()=>i(a.error),a.onsuccess=()=>{let e=a.result,o=n(e.transaction(Zo.store,t).objectStore(Zo.store));o.onsuccess=()=>(e.close(),r(o.result)),o.onerror=()=>(e.close(),i(o.error))}});return{read:()=>t(`readonly`,e=>e.get(Zo.key)),write:async e=>void await t(`readwrite`,t=>t.put(e,Zo.key)),clear:async()=>void await t(`readwrite`,e=>e.delete(Zo.key))}},og=e=>Uint8Array.from(atob(e.replace(/-/g,`+`).replace(/_/g,`/`)),e=>e.charCodeAt(0)),sg=(e,t)=>Promise.race([t,new Promise(t=>setTimeout(t,e))]),cg=class extends Error{},lg=(e,t)=>e instanceof An&&e.status===409&&e.slug===t,ug=({browser:e,records:t,devices:n,meta:r,user:i,waitMs:a=3e3})=>{let o,s=()=>o??=r(),c=async n=>{await t.clear();for(let e of n?await n.getNotifications():[])e.close();await e.clearBadge()},l=async e=>{let t=await e?.pushManager.getSubscription();t&&await t.unsubscribe()},u=async e=>{await c(e),await l(e)},d=async(r,i)=>{let a=r.toJSON().keys??{},o=await n.register({kind:`web`,endpoint:r.endpoint,keys:{p256dh:a.p256dh??``,auth:a.auth??``},userAgent:e.userAgent,userId:i.userId});await t.write({...i,deviceId:o.id})},f=async()=>{if(!e.supported||!(await s()).webPushKey)return`unsupported`;if(e.permission()===`denied`)return`blocked`;let n=i(),r=await e.existingRegistration(),[a,o]=await Promise.all([r?.pushManager.getSubscription(),t.read()]);return n&&a&&o?.userId===n.id&&o.endpoint===a.endpoint?`on`:`off`},p=async()=>{let n=i();if(!e.supported||!e.activated()||!n?.own||e.permission()==="default"&&await e.requestPermission()!==`granted`||e.permission()!==`granted`)return f();let{appName:r,webPushKey:a}=await s();if(!a)return`unsupported`;let o=()=>i()?.id===n.id&&i()?.own===!0,c=await e.registration();if(!o())return f();let[l,p]=await Promise.all([c.pushManager.getSubscription(),t.read()]);l&&(p?.userId!==n.id||p.endpoint!==l.endpoint)&&await u(c);let h=async()=>{if(!o())throw new cg;let e=await c.pushManager.getSubscription()??await c.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:og(a)}),i={userId:n.id,endpoint:e.endpoint,appName:r};if(await t.write(i),!o())throw new cg;await d(e,i)};try{await h()}catch(e){if(lg(e,`device-held`))return await u(c),m(c,h);if(await u(c),e instanceof cg||lg(e,`other-user`))return`off`;throw e}return`on`},m=async(e,t)=>{try{await t()}catch(t){if(await u(e),t instanceof cg||lg(t,`device-held`)||lg(t,`other-user`))return`off`;throw t}return`on`};return{state:f,turnOn:p,turnOff:async()=>{if(!e.supported)return;let r=await e.existingRegistration(),i=await t.read();await c(r),await sg(a,Promise.allSettled([l(r),i?.deviceId?n.remove(i.deviceId):Promise.resolve()]))},forget:async()=>{if(!e.supported)return;let t=await e.existingRegistration();await c(t),await sg(a,Promise.allSettled([l(t)]))},adopt:async n=>{if(!e.supported)return;let r=await e.existingRegistration(),[i,a]=await Promise.all([r?.pushManager.getSubscription(),t.read()]);if(!r)return a?t.clear():void 0;if(!a||a.userId!==n.id)return i||a?u(r):void 0;if(!n.own)return;if(!i||e.permission()!==`granted`||a.endpoint!==i.endpoint&&!a.renew)return u(r);let o={userId:a.userId,endpoint:i.endpoint,appName:a.appName};await t.write(o);try{await d(i,o)}catch(e){if(!lg(e,`device-held`)&&!lg(e,`other-user`))throw e;await u(r)}}}},dg={state:async()=>`unsupported`,turnOn:async()=>`unsupported`,turnOff:async()=>{},forget:async()=>{},adopt:async()=>{}},fg=({nativeBridge:e,...t})=>{if(typeof window>`u`)return dg;if(e){let n=Qh(e);if(!n)return dg;let{devices:r,user:i,waitMs:a}=t;return Xh({bridge:e,device:n,records:ag(),choices:ig(()=>localStorage),permissionAsked:ng(e.getPlatform(),navigator.userAgent),devices:r,user:i,userAgent:$h(navigator.userAgent),report:Vh,...a!==void 0&&{waitMs:a}})}let n=eg();return n.supported?ug({...t,browser:n,records:ag()}):dg},pg=e=>e===`http:`||e===`https:`,mg=(e,t=(e,t)=>fetch(e,t))=>{if(pg(e.protocol))return;let n=`${e.protocol}//${e.host}`;return{origin:`https://${e.host}`,fetch:(e,r)=>{let i=new URL(e instanceof Request?e.url:e),a=`${n}${i.pathname}${i.search}`;return e instanceof Request?t(new Request(a,e),r):t(a,r)}}},hg=e=>e!==void 0&&URL.canParse(e)&&pg(new URL(e).protocol),gg=async(e,t)=>{let n=!1;try{n=!!await e?.()}finally{n||await t()}},_g=`sign-in`,vg=`error`,yg=e=>{let t=new URL(e).searchParams;if(!t.has(vg))return t.get(`sign-in`)||void 0},bg=e=>new URL(e).searchParams.get(vg)||void 0,xg=[`totp`,`otp`],Sg=e=>{let t=new URL(e).searchParams.get(Yo);if(t!==null)return t.split(`,`).filter(e=>xg.includes(e))},Cg=e=>{let t=new URL(e);for(let e of[_g,vg,Yo])t.searchParams.delete(e);return`${t.pathname}${t.search}${t.hash}`},wg={github:`GitHub`,gitlab:`GitLab`,google:`Google`,microsoft:`Microsoft`,apple:`Apple`},Tg=(e,t=[])=>t.find(t=>t.provider===e)?.name??wg[e]??e.charAt(0).toUpperCase()+e.slice(1),Eg=e=>e.filter(({linkOnly:e})=>!e),Dg=e=>e.kind===`signed-in`&&!e.staff,Og=(e,t)=>e.kind===`loading`||e.kind===`error`?`leave`:e.kind!==`signed-in`||!Dg(e)?`clear`:t?{save:{user:e.user,status:t}}:`leave`,J=B(`auth`),kg=(0,W.createContext)(null),Ag=[`password`],jg=[],Mg=[],Ng=[],Pg=[],Fg=[],Y=()=>{let e=(0,W.useContext)(kg);if(!e)throw Error(`useAuth must be used inside AuthProvider`);return e},Ig=()=>(0,W.useContext)(kg),Lg=({session:e,origin:t,nativeBridge:n,afterSignIn:r,children:i})=>{let a=ys(),[o]=(0,W.useState)(()=>a?.session()),[s,c]=(0,W.useState)(()=>o?{kind:`signed-in`,user:o.user}:{kind:`loading`}),[l,u]=(0,W.useState)(o?.status),d=l?.signInMethods??Ag,f=l?.signInFirst??`password`,p=!!l?.passwordReset&&!n,m=!!l?.changeEmail,h=!!l?.accountDeletion,g=l?.mcp,_=!!l?.personalAccessTokens,v=!!l?.signUp,y=l?.signUpFields?.includes(`name`)??!0,b=l?.passkeyDomains??jg,x=l?.socialProviders??jg,S=l?.platformProviders??Pg,C=l?.personalMail??Mg,w=l?.samlProviders??Ng,T=l?.staffSignIn,E=!!l?.deviceLinks,D=l?.organizations,O=!!l?.anonymous,k=l?.plugins??Fg,ee=l?.locale,A=(0,W.useMemo)(()=>({...l?.appName&&{appName:l.appName},...l?.appIcon&&{appIcon:l.appIcon},runsOnNote:!!l?.runsOnNote}),[l]),te=(0,W.useCallback)(()=>O?{kind:`visitor`}:{kind:`signed-out`},[O]),ne=(0,W.useRef)(async()=>{}),re=(0,W.useRef)(0),j=(0,W.useCallback)(()=>{re.current+=1,ne.current(),c(e=>e.kind===`signed-in`?{kind:`signed-out`}:e)},[]),ie=(0,W.useRef)(j);ie.current=j;let M=(0,W.useMemo)(()=>{if(e)return e;let r=hg(t)?void 0:mg(window.location),i=r?.origin??t;return xh({...i&&{origin:i},...r&&{fetch:r.fetch},...n&&{fetch:Ih(n,i??window.location.origin)},onSignedOut:()=>ie.current()})},[e,t,n]),ae=(0,W.useRef)(void 0);ae.current=s.kind===`signed-in`?{id:s.user.id,own:!s.staff}:void 0;let oe=(0,W.useMemo)(()=>{let e=Fn({baseUrl:`${t??globalThis.location?.origin??``}/api/v1`,token:({refresh:e})=>M.token({refresh:e})}),r=async()=>{let t=await e.meta();if(t.status!==`modified`)throw Error(`The app answered /meta without its content`);return{appName:t.meta.appName,...t.meta.notifications?.webPushKey&&{webPushKey:t.meta.notifications.webPushKey}}};return fg({...n&&{nativeBridge:n},devices:e.devices,meta:r,user:()=>ae.current})},[M,t,n]);ne.current=oe.forget;let se=(0,W.useRef)(r);se.current=r;let ce=(0,W.useCallback)(async(e,t=re.current)=>{let[{missing:n},r]=await Promise.all([M.account.signInMethods(),M.staff.current()]);re.current===t&&(c(n.length>0?{kind:`setup-required`,user:e,missing:n}:{kind:`signed-in`,user:e,...r&&{staff:r}}),n.length===0&&oe.adopt({id:e.id,own:!r}))},[M,oe]),le=(0,W.useCallback)(async e=>{let t=re.current;await gg(se.current,()=>ce(e,t))},[ce]),ue=(0,W.useCallback)(async e=>e.kind===`two-factor`?c({kind:`two-factor`,methods:e.methods}):le(e.user),[le]),de=(0,W.useCallback)(()=>{let e=re.current;c(e=>e.kind===`signed-in`?e:{kind:`loading`}),M.status().then(async t=>{if(u(t),re.current!==e)return;if(t.needsAdmin)return c({kind:`needs-admin`,...t.firstAdminUrl&&{firstAdminUrl:t.firstAdminUrl}});let n=await M.session();if(re.current!==e)return;if(n)return ce(n,e);let r=Sg(window.location.href);c(r?{kind:`two-factor`,methods:r}:{kind:t.anonymous?`visitor`:`signed-out`})}).catch(t=>{re.current===e&&c(e=>e.kind===`signed-in`?e:{kind:`error`,message:t instanceof Error?t.message:J(`noAnswer`)})})},[M,ce]);(0,W.useEffect)(de,[de]),(0,W.useEffect)(()=>{if(!a)return;let e=Og(s,l);e===`clear`?a.clear():e!==`leave`&&a.saveSession(e.save)},[a,s,l]);let fe=(0,W.useMemo)(()=>({state:s,session:M,signInMethods:d,signInFirst:f,passwordReset:p,changeEmail:m,accountDeletion:h,mcp:g,personalAccessTokens:_,canSignUp:v,signUpAsksName:y,passkeyDomains:b,socialProviders:x,signInProviders:[...x.map(e=>({id:e,name:Tg(e,S),...S.some(t=>t.provider===e&&t.button===!1)&&{linkOnly:!0}})),...w],platformProviders:S,deviceLinks:E,staffSignIn:T,...D&&{organizations:D},markSignedOut:j,recheck:de,beforeSignIn:k,locale:ee,identity:A,adoptSession:async()=>{let e=await M.session();return e?(await le(e),!0):!1},...O&&{browse:()=>{c(e=>e.kind===`signed-out`?{kind:`visitor`}:e)}},signIn:async(e,t)=>ue(await M.signIn(e,t)),sendSignInCode:e=>M.sendSignInCode(e),signInWithCode:async(e,t)=>ue(await M.signInWithCode(e,t)),sendSignUpCode:e=>M.sendSignUpCode(e),verifySignUpCode:(e,t)=>M.verifySignUpCode(e,t),signUp:async e=>le(await M.signUp(e)),signInWithPasskey:async e=>le(await M.signInWithPasskey(e)),verifyTwoFactor:async e=>le(await M.verifyTwoFactor(e)),signInSocial:async e=>{let t=new URL(Cg(window.location.href),window.location.href).href,n=w.some(t=>t.id===e);window.location.assign(await(n?M.signInSaml(e,t):M.signInSocial(e,t)))},linkProvider:async e=>{window.location.assign(await M.account.linkProvider(e,new URL(Cg(window.location.href),window.location.href).href))},personalMail:C,linkPersonalMail:async e=>{window.location.assign(await M.account.linkPersonalMail(e,new URL(Cg(window.location.href),window.location.href).href))},connectAccount:async e=>{window.location.assign(await M.account.connectAccount(e,new URL(Cg(window.location.href),window.location.href).href))},stopStaffSession:async()=>{re.current+=1,await oe.forget(),await M.staff.stop(),c(te())},signOut:async()=>{re.current+=1,await oe.turnOff(),await M.signOut(),c(te())},deleteAccount:async e=>{await M.deleteAccount(e),re.current+=1,await oe.forget(),c(te())},push:oe}),[oe,s,M,d,f,p,m,h,g,_,v,y,b,x,S,E,C,w,T,D,O,k,ee,A,te,j,de,ue,le]);return(0,q.jsx)(kg.Provider,{value:fe,children:i})},Rg=e=>{let t=!1,n=[];return{tap:r=>t?e(r):void n.push(r),settle:r=>{if(t=r,r)for(let t of n.splice(0))e(t)}}},zg=e=>typeof e==`object`&&!!e&&!Array.isArray(e),Bg=(e,{apiOrigin:t,userId:n,basePath:r})=>{if(!zg(e)||n===void 0||e.user!==n)return;let i=es(e.url);if(i===void 0)return;let a=new URL(i);if(a.origin!==t)return{kind:`browser`,url:i};let o=`${a.pathname}${a.search}${a.hash}`;if(o.startsWith(`//`)||new URL(o,t).origin!==t)return;if(r===``)return{kind:`in-app`,path:o};if(a.pathname!==r&&!a.pathname.startsWith(`${r}/`))return;let s=o.slice(r.length);return{kind:`in-app`,path:s.startsWith(`/`)?s:`/${s}`}},Vg=`protobase.push.tap`,Hg=({storage:e,reloading:t})=>({receive:(n,r)=>{if(!t())return r(n);e.setItem(Vg,JSON.stringify(n??null))},resume:t=>{let n=e.getItem(Vg);if(n===null)return;e.removeItem(Vg);let r;try{r=JSON.parse(n)}catch(e){if(e instanceof SyntaxError)return;throw e}t(r)}}),Ug=`ProtobaseExternal`,Wg=async(e,{bridge:t,navigate:n})=>{if(e.kind===`in-app`)return n(e.path);t.isPluginAvailable(Ug)&&await t.nativePromise(Ug,`open`,{url:e.url})},Gg=e=>typeof e==`object`&&e?e.notification?.data:void 0,Kg=({nativeBridge:e,apiOrigin:t})=>{let{state:n}=Y(),{navigate:r,basePath:a}=le(),o=n.kind===`signed-in`?n.user.id:void 0,s=(0,W.useRef)(()=>{});s.current=n=>{let i=Bg(n,{apiOrigin:t,userId:o,basePath:a});i&&Wg(i,{bridge:e,navigate:r})};let[c]=(0,W.useState)(()=>Rg(e=>s.current(e))),[l]=(0,W.useState)(()=>{let e=i(()=>window.sessionStorage,void 0);return e&&Hg({storage:e,reloading:()=>ws(e)})});return(0,W.useEffect)(()=>c.settle(n.kind!==`loading`),[c,n.kind,o]),(0,W.useEffect)(()=>{if(!e.isPluginAvailable(`PushNotifications`))return;let t=e.addListener(Kh,`pushNotificationActionPerformed`,e=>l?l.receive(Gg(e),c.tap):c.tap(Gg(e)));return l?.resume(c.tap),()=>void t.remove()},[e,c,l]),null},X=B(`account`),qg=`/-/account`,Jg=`/-/sign-in-policy`,Yg=e=>{if(e===`/-/account`)return{};if(!e.startsWith(`/-/account/`))return;let t=e.slice(11);if(!(t===``||t.includes(`/`)))try{return{tab:decodeURIComponent(t)}}catch(e){if(e instanceof URIError)return;throw e}},Xg=e=>e?`${qg}/${encodeURIComponent(e)}`:qg,Zg=(e,t,n)=>[{id:`account`,label:X(`account`),icon:ef,href:`${e}${qg}`,active:Yg(t)!==void 0},...n?[{id:`sign-in-policy`,label:X(`signInPolicy`),icon:md,href:`${e}${Jg}`,active:t===Jg}]:[]],Qg=(0,W.createContext)(null),$g=({route:e,children:t})=>(0,q.jsx)(Qg.Provider,{value:e,children:t}),e_=()=>{let e=(0,W.useContext)(Qg);if(!e)throw Error(`Tabs render inside a page that gives them their addresses: a composed page`);return e},t_=e=>e.children.filter(e=>typeof e!=`string`).map(e=>({node:e,...e.props})),n_=e=>{let t=e.children.find(e=>typeof e!=`string`&&!e.custom&&e.type===`Tabs`);return t?t_(t):[]},r_=(e,t)=>t===void 0?e[0]:e.find(e=>e.name===t),i_=24,a_=.3,o_=.5,s_=100,c_=e=>e>=0?e:-24*(1-Math.exp(e/i_)),l_=e=>{let t=e.at(-1);if(!t)return 0;let n=e.find(e=>t.time-e.time<=s_)??t,r=t.time-n.time;return r>0?(t.y-n.y)/r:0},u_=(e,t,n)=>e<=6?!1:n>=o_||e>=t*a_&&n>-.5/2,d_=(e,t,n)=>e<=0&&n>0&&n>Math.abs(t),f_=`cubic-bezier(0.32, 0.72, 0, 1)`,p_=()=>window.matchMedia(`(prefers-reduced-motion: reduce)`).matches,m_=({panel:e,backdrop:t,content:n,open:r,onClose:i})=>{let a=(0,W.useRef)(void 0),o=(0,W.useRef)(!1),s=(0,W.useRef)(i);s.current=i;let c=(0,W.useCallback)((n,r)=>{let i=e.current;if(!i)return;let a=r&&!p_()?`300ms ${f_}`:`none`;i.style.transition=a===`none`?`none`:`transform ${a}`,i.style.transform=n===0?``:`translateY(${n}px)`;let o=t.current;o&&(o.style.transition=a===`none`?`none`:`opacity ${a}`,o.style.opacity=String(1-Math.max(0,n)/Math.max(1,i.offsetHeight)))},[e,t]);(0,W.useLayoutEffect)(()=>{let t=e.current;if(!r||!t||(o.current=!1,p_()))return;c(t.offsetHeight,!1);let n=requestAnimationFrame(()=>c(0,!0));return()=>cancelAnimationFrame(n)},[r,e,c]);let l=(0,W.useCallback)(()=>{let t=e.current;if(!o.current){if(!t||p_())return s.current();o.current=!0,c(t.offsetHeight,!0),setTimeout(()=>s.current(),300)}},[e,c]),u=(e,t,n)=>{a.current={x:e,y:t,samples:[{y:t,time:n}],dragging:!1,scrolling:!1}},d=(e,t)=>{let n=a.current;n&&(n.samples.push({y:e,time:t}),c(c_(e-n.y),!1))},f=()=>{let t=a.current;a.current=void 0;let n=e.current;if(t?.dragging&&n){if(u_(c_(t.samples.at(-1).y-t.y),n.offsetHeight,l_(t.samples)))return l();c(0,!0)}};return(0,W.useEffect)(()=>{let e=n.current;if(!r||!e)return;let t=e=>{let t=e.touches[0];e.touches.length===1&&t&&u(t.clientX,t.clientY,e.timeStamp)},i=t=>{let n=a.current,r=t.touches[0];if(n&&r&&!n.scrolling){if(!n.dragging){let t=r.clientX-n.x,i=r.clientY-n.y;if(Math.abs(t)<6&&Math.abs(i)<6)return;if(!d_(e.scrollTop,t,i)){n.scrolling=!0;return}n.dragging=!0,n.y=r.clientY}t.preventDefault(),d(r.clientY,t.timeStamp)}};return e.addEventListener(`touchstart`,t,{passive:!0}),e.addEventListener(`touchmove`,i,{passive:!1}),e.addEventListener(`touchend`,f),e.addEventListener(`touchcancel`,f),()=>{e.removeEventListener(`touchstart`,t),e.removeEventListener(`touchmove`,i),e.removeEventListener(`touchend`,f),e.removeEventListener(`touchcancel`,f)}}),{dismiss:l,header:{onPointerDown:e=>{if(e.button!==0)return;u(e.clientX,e.clientY,e.timeStamp);let t=t=>{let n=a.current;if(n&&t.pointerId===e.pointerId){if(!n.dragging){if(Math.abs(t.clientY-n.y)<6)return;n.dragging=!0,n.y=t.clientY}d(t.clientY,t.timeStamp)}},n=r=>{if(r.pointerId!==e.pointerId)return;let i=a.current;i&&!i.dragging&&Math.abs(r.clientY-i.y)>=6&&(i.dragging=!0,i.samples.push({y:r.clientY,time:r.timeStamp})),window.removeEventListener(`pointermove`,t),window.removeEventListener(`pointerup`,n),window.removeEventListener(`pointercancel`,n),f()};window.addEventListener(`pointermove`,t),window.addEventListener(`pointerup`,n),window.addEventListener(`pointercancel`,n)}}}},h_=({title:e,open:t,onClose:n,children:r})=>{let i=(0,W.useRef)(null),a=(0,W.useRef)(null),o=(0,W.useRef)(null),{dismiss:s,header:c}=m_({panel:i,backdrop:a,content:o,open:t,onClose:n});return li(i,t,s),t?(0,q.jsxs)(`div`,{className:`fixed inset-0 z-[80]`,children:[(0,q.jsx)(`div`,{ref:a,className:`absolute inset-0 bg-backdrop/40`,onClick:s,"aria-hidden":!0}),(0,q.jsxs)(`div`,{ref:i,role:`dialog`,"aria-modal":`true`,"aria-label":e,tabIndex:-1,className:`absolute inset-x-0 bottom-0 flex max-h-[85vh] flex-col rounded-t-xl border-t bg-background pl-[var(--pb-safe-left)] pr-[var(--pb-safe-right)] shadow-pop outline-none will-change-transform`,children:[(0,q.jsxs)(`header`,{className:`relative flex shrink-0 touch-none select-none items-center justify-between border-b px-4`,...c,children:[(0,q.jsx)(`h2`,{className:`text-base font-semibold`,children:e}),(0,q.jsx)(`button`,{type:`button`,"aria-label":yn(`close`),onClick:s,className:`-mr-2 inline-flex size-11 items-center justify-center rounded-md text-muted-foreground hover:bg-muted`,children:(0,q.jsx)(Ci,{className:`size-5`})}),(0,q.jsx)(`button`,{type:`button`,"aria-label":yn(`dragToClose`),onClick:s,className:`absolute left-1/2 top-0 flex h-4 w-16 -translate-x-1/2 items-start justify-center pt-1.5`,children:(0,q.jsx)(`span`,{className:`h-1 w-9 rounded-full bg-border-strong`})})]}),(0,q.jsx)(`div`,{ref:o,className:`min-h-0 flex-1 overflow-y-auto overscroll-contain px-4 pb-[calc(1.5rem+var(--pb-safe-bottom))]`,children:r})]})]}):null},g_=({title:e,description:t,open:n,onClose:r,actions:i,children:a,wide:o})=>{let s=h();return n?s?(0,q.jsx)(di,{title:e,description:t,onClose:r,actions:i,wide:o,children:a}):(0,q.jsx)(h_,{title:e,open:!0,onClose:r,children:(0,q.jsxs)(`div`,{className:`pt-3`,children:[t&&(0,q.jsx)(`p`,{className:`text-muted-foreground`,children:t}),a&&(0,q.jsx)(`div`,{className:`mt-4`,children:a}),(0,q.jsx)(`div`,{className:`mt-5 flex flex-col-reverse gap-2 [&>*]:min-h-11`,children:i})]})}):null},__={xs:`size-5 text-[0.5625rem]`,sm:`size-6 text-[0.625rem]`,md:`size-8 text-xs`,lg:`size-10 text-base`},v_=({initials:e,hue:t,size:n=`sm`,className:r})=>(0,q.jsx)(`span`,{className:U(`inline-flex shrink-0 select-none items-center justify-center rounded-full font-semibold text-white ring-2 ring-background`,__[n],r),style:{background:`oklch(0.58 0.13 ${t})`},children:e}),y_=({people:e,size:t=`sm`})=>(0,q.jsx)(`span`,{className:`inline-flex -space-x-1`,children:e.map(e=>(0,q.jsx)(v_,{...e,size:t},e.initials))}),b_=B(`record-view`),x_=({collection:e,title:t,badge:n,lastEditedBy:r,presence:i=[],actions:a})=>(0,q.jsxs)(`header`,{className:`flex flex-col gap-4 border-b border-border pb-6 md:flex-row md:items-end md:justify-between md:gap-6`,children:[(0,q.jsxs)(`div`,{children:[e&&(0,q.jsx)(`p`,{className:`mb-1 text-xs text-muted-foreground`,children:e}),(0,q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1`,children:[(0,q.jsx)(`h1`,{className:`text-xl font-semibold tracking-tight text-foreground md:text-2xl`,children:t}),n]}),r&&(0,q.jsx)(`p`,{className:`mt-1.5 text-xs text-muted-foreground`,children:r.name?(0,q.jsxs)(q.Fragment,{children:[b_(`lastEditedBy`),` `,(0,q.jsx)(`span`,{className:`font-medium text-foreground`,children:r.name}),` `,r.ago]}):(0,q.jsx)(q.Fragment,{children:b_(`lastUpdated`,{ago:r.ago})})})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-4`,children:[i.length>0&&(0,q.jsxs)(`span`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,q.jsx)(y_,{people:i,size:`md`}),b_(`viewing`,{count:i.length})]}),a]})]}),S_=(0,W.createContext)(0),C_=()=>(0,W.useContext)(S_),w_={2:`h2`,3:`h3`,4:`h4`,5:`h5`,6:`h6`},T_=()=>Math.min(Math.max(C_(),1)+1,6),E_=({title:e,help:t,actions:n,count:r,level:i,children:a})=>{let o=T_(),s=i??o,c=w_[s],l=e?(0,q.jsxs)(c,{className:`flex items-center gap-2 text-base font-semibold text-foreground`,children:[e,r]}):null,u=!!(l||n||t),d=l?(0,q.jsx)(S_.Provider,{value:s,children:a}):a;return(0,q.jsxs)(q.Fragment,{children:[n?(0,q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-x-4 gap-y-2`,children:[l??(0,q.jsx)(`span`,{}),n]}):l,t&&(0,q.jsx)(`p`,{className:`mt-1 max-w-xl leading-6 text-muted-foreground`,children:t}),u?(0,q.jsx)(`div`,{className:`mt-5`,children:d}):d]})},D_=({title:e,help:t,actions:n,count:r,level:i,children:a})=>(0,q.jsx)(`section`,{className:`py-8 first:pt-8`,children:(0,q.jsx)(E_,{title:e,help:t,actions:n,count:r,level:i,children:a})}),O_=()=>Pi(`grouped`,e=>new Intl.NumberFormat(e)),k_=e=>O_().format(e),A_=e=>e>0?`+${O_().format(e)}`:O_().format(e).replace(`-`,`−`),j_=e=>`${e}%`,M_=e=>{if(e<1e4)return Qn(`rows`,{count:k_(e),n:e});let t=10**(Math.floor(Math.log10(e))-3);return Qn(`aboutRows`,{count:k_(Math.round(e/t)*t)})},N_=(e,t)=>Pi(`money:${e}:${t??``}`,n=>new Intl.NumberFormat(n,{style:`currency`,currency:e,...t!==void 0&&{minimumFractionDigits:t,maximumFractionDigits:t}})),P_=(e,t,n)=>N_(t,n).format(e/100),F_=B(`data-grid`),I_=e=>typeof e==`object`&&e&&`name`in e?String(e.name):String(e),L_=(e,t)=>{if(t==null)return`—`;switch(e.kind){case`text`:case`id`:return String(t);case`money`:if(e.currency===void 0)throw Error(`Money column "${e.id}" has no currency`);return`${P_(Number(t),e.currency,e.decimals)}${e.suffix??``}`;case`date`:return yr(Number(t));case`datetime`:return e.relative?Un(Math.round((Date.now()-Number(t))/1e3)):dr(Number(t));case`number`:return`${e.prefix??``}${k_(Number(t))}${e.suffix??``}`;case`signed`:return`${e.prefix??``}${A_(Number(t))}${e.suffix??``}`;case`percent`:return Number(t)===0?`—`:j_(Number(t));case`status`:return ar(String(t),e.labels);case`relation`:return I_(t);case`boolean`:return t?void 0:F_(`no`);case`file`:return hr(t)?.name??`—`;case`user`:return e.users?.(String(t))?.name??String(t)}},R_=(e,t)=>Math.ceil(e.length*7.2)+24+(t?16:0)+28,z_=e=>Math.ceil(Math.max(0,...e.map(e=>e.length))*7.2)+56,B_={body:7.5,mono:7.2,numeric:8},V_=24,H_=16,U_=new Set([`status`,`money`,`number`,`signed`,`percent`,`date`,`datetime`,`boolean`]),W_=new Set([`money`,`number`,`signed`,`percent`,`date`,`datetime`]),G_=80,K_=400,q_=240,J_=e=>e===`id`?B_.mono:W_.has(e)?B_.numeric:B_.body,Y_=(e,t)=>e.value?e.value(t):t[e.id],X_=(e,t)=>{let n=t.map(t=>L_(e,Y_(e,t)));if(e.kind===`status`)return z_(n.map(e=>e??``));let r=e.kind===`user`||e.kind===`file`?V_:0;return Math.max(0,...n.map(t=>t===void 0?H_:Math.ceil(t.length*J_(e.kind))))+r+24},Z_=(e,t,n)=>Math.min(n,Math.max(t,e)),Q_=(e,t)=>{if(U_.has(e.kind)&&!e.title)return{...e,fixed:!0,width:Math.max(e.minWidth??0,t)};let n={...e,fixed:!1,width:Z_(t,G_,K_)};return e.kind===`id`?{...n,minWidth:Math.max(R_(e.header,e.sortable??!1),Math.min(t,q_))}:n},$_=(e,t)=>{if(!e.fit)return e;let n=Math.max(0,...t.map(e.fit));return{...e,fixed:!0,width:Z_(n,e.minWidth??0,e.maxWidth??1/0)}},ev=(e,t)=>{if(t.length===0)return e;let n=e.map(e=>e.render?$_(e,t):Q_(e,X_(e,t))),r=n.filter((t,n)=>!t.fixed&&!t.title&&!e[n].render).map(e=>e.width),i=Math.max(0,...r);return n.map((t,n)=>t.title&&!e[n].render?{...t,width:Math.max(t.width,i)}:t)},tv=e=>e.charAt(0).toUpperCase()+e.slice(1),nv=[[/^\s*(```|~~~).*$/,``],[/^\s*\[[^\]]+\]:\s+\S.*$/,``],[/^\s*([-*_]\s*){3,}$/,``],[/^\s*\|?(\s*:?-+:?\s*\|)+\s*:?-*:?\s*$/,``],[/^\s*#{1,6}\s+/,``],[/^\s*(>\s?)+/,``],[/^\s*([-*+]|\d+[.)])\s+(\[[ xX]\]\s+)?/,``]],rv=[[/!\[([^\]]*)\]\([^)]*\)/g,`$1`],[/\[([^\]]*)\]\([^)]*\)/g,`$1`],[/\[([^\]]+)\]\[[^\]]*\]/g,`$1`],[/<((?:https?|mailto):[^>\s]+)>/gi,`$1`],[/<\/?[a-z][^>]*>/gi,``],[/`([^`]+)`/g,`$1`],[/(?<!\\)(\*\*|__)(?=\S)(.+?)(?<=\S)\1/g,`$2`],[/(?<![\\\w*])\*(?=\S)(.+?)(?<=\S)\*/g,`$1`],[/(?<![\\\w])_(?=\S)(.+?)(?<=\S)_(?!\w)/g,`$1`],[/(?<!\\)~~(.+?)~~/g,`$1`],[/\s*\|\s*/g,` `],[/\\([\\`*_{}[\]()#+\-.!>~|])/g,`$1`]],iv=200,av=e=>{let t=e.split(/\r?\n/).map(e=>nv.reduce((e,[t,n])=>e.replace(t,n),e)),n=rv.reduce((e,[t,n])=>e.replace(t,n),t.join(`
3
+ `)).replace(/\s+/g,` `).trim();return n.length>iv?`${n.slice(0,199).trimEnd()}…`:n},ov=(e,t)=>e.type===`text`&&!!t?.markdown,sv=new Set([`email`,`phone`,`url`]),cv=e=>e?.format!==void 0&&sv.has(e.format)?e.format:void 0,lv=(e,t)=>{let n=t.trim();if(e===`email`)return/^[^\s@]+@[^\s@]+$/.test(n)?`mailto:${n}`:void 0;if(e===`phone`){let e=n.replace(/[^\d+]/g,``).replace(/(?!^)\+/g,``);return/\d/.test(e)?`tel:${e}`:void 0}return/^https?:\/\/\S+$/i.test(n)?n:void 0},uv=e=>e===`email`?{type:`email`,inputMode:`email`,autoComplete:`email`}:e===`phone`?{type:`tel`,inputMode:`tel`,autoComplete:`tel`}:e===`url`?{type:`url`,inputMode:`url`,autoComplete:`url`}:{},dv=e=>typeof e!=`object`||!e,fv=(e,t)=>e.length>t?`${e.slice(0,t-1)}…`:e,pv=e=>Array.isArray(e)?e.length===0?`[]`:`[…]`:typeof e==`object`&&e?Object.keys(e).length===0?`{}`:`{…}`:e===``?`""`:fv(String(e),40),mv=e=>{let t=``;for(let n of e)if(t=t===``?n:`${t}, ${n}`,t.length>160)break;return fv(t,160)};function*hv(e){let t=e;for(let e in t)dv(t[e])&&(yield`${e}: ${pv(t[e])}`);for(let e in t)dv(t[e])||(yield`${e}: ${pv(t[e])}`)}function*gv(e){for(let t of e)yield pv(t)}var _v=e=>Array.isArray(e)?e.length===0?`[]`:e.every(dv)?mv(gv(e)):Er(`jsonItems`,{count:e.length}):typeof e==`object`&&e?Object.keys(e).length===0?`{}`:mv(hv(e)):fv(String(e),160),vv=e=>e==null||e===``,yv=(e,t,n,r,i)=>{let a=e.fields[n];return a?a.type===`relation`?i[n]??I_(r):Lr(a,r,t?.fields[n]):String(r)},bv=(e,t,n,r,i={})=>{let a=t?.fields[n]?.linkText;if(a===void 0||Pr(a).some(e=>vv(r[e])))return;let o=cr(a,n=>yv(e,t,n,r[n],i)).trim();return o===``?void 0:o},xv={text:200,id:140,money:120,date:110,datetime:170,status:150,relation:200,boolean:64,number:100,signed:110,percent:110,user:130,file:180},Sv=new Set([`datetime`,`date`,`boolean`,`percent`]),Cv=(e,t,n)=>{switch(e.type){case`relation`:return`relation`;case`file`:return`file`;case`enum`:return`status`;case`boolean`:return`boolean`;case`timestamp`:return`datetime`;case`date`:return`date`;case`decimal`:return t?.format===`percent`?`percent`:t?.currency===void 0?`number`:`money`;case`integer`:case`bigint`:return t?.format===`signed`?`signed`:`number`;default:return t?.format===`code`||n===0&&e.name===`id`?`id`:`text`}},wv=e=>Math.round(Number.parseFloat(String(e))*100),Tv=(e,t,n=[],r=He(e,t))=>{let i=Ke(e,t);return r.flatMap((r,a)=>{let o=e.fields[r];if(!o)return[];let s=t?.fields[r],c=Cv(o,s,a),l=Object.fromEntries((o.enumValues??[]).map(e=>[e,ar(e,s?.valueLabels)])),u=(c===`number`||c===`signed`)&&s?.prefix?s.prefix:void 0,d=Math.ceil(((u?.length??0)+(s?.suffix?.length??0))*7.2);return[{id:r,header:s?.label??H(r),kind:c,width:(r===`name`?260:xv[c])+d,sortable:o.sortable,minWidth:Math.max(c===`id`?150:0,R_(s?.label??H(r),o.sortable),c===`status`?z_(Object.values(l)):0,d>0?xv[c]+d:0),...Sv.has(c)&&{fixed:!0},...r===i&&{title:!0},...c===`text`&&r!==i&&cv(s)&&{link:cv(s)},...c===`text`&&r!==i&&s?.linkText!==void 0&&{linkText:n=>bv(e,t,r,n)},...n.includes(r)&&{highlight:!0},...o.type===`enum`&&{tones:Object.fromEntries((o.enumValues??[]).map(e=>[e,ei(s?.valueColors,e)])),labels:l},...o.type===`enum`&&s?.valueColors&&{colors:s.valueColors},...o.type===`enum`&&s?.badgeShape&&{shape:s.badgeShape},...u!==void 0&&{prefix:u},...s?.suffix!==void 0&&{suffix:s.suffix},...c===`datetime`&&s?.format===`relative`&&{relative:!0},...c===`money`&&s?.decimals!==void 0&&{decimals:s.decimals},...c===`money`&&s?.currency!==void 0&&{currency:s.currency,value:e=>e[r]==null?null:wv(e[r])},...(c===`datetime`||c===`date`)&&{value:e=>e[r]==null?null:Date.parse(String(e[r]))},...o.type===`json`&&{value:e=>e[r]==null?null:_v(e[r])},...ov(o,s)&&{value:e=>typeof e[r]==`string`?av(e[r]):e[r]},...(c===`percent`||c===`number`&&o.type===`decimal`)&&{value:e=>e[r]==null?null:Number(e[r])}}]})},Ev=`text-base font-semibold text-foreground`,Dv=({title:e,help:t,count:n,open:r,toggle:i,children:a})=>{let o=(0,W.useId)();return(0,q.jsxs)(`div`,{children:[(0,q.jsxs)(`div`,{className:U(`py-8`,r&&`pb-0`),children:[(0,q.jsxs)(`h2`,{className:`flex items-center gap-2`,children:[i?(0,q.jsxs)(Ue,{to:i,replace:!0,"aria-expanded":r,"aria-controls":o,className:U(`inline-flex items-center gap-1.5`,Ev),children:[(0,q.jsx)(qn,{className:U(`size-4 transition-transform`,r&&`rotate-90`)}),e]}):(0,q.jsx)(`span`,{className:Ev,children:e}),n]}),t&&(0,q.jsx)(`p`,{className:U(`mt-1 max-w-xl leading-6 text-muted-foreground`,i&&`pl-5.5`),children:t})]}),r&&(0,q.jsx)(`div`,{id:o,className:`divide-y divide-border`,children:(0,q.jsx)(S_.Provider,{value:2,children:a})})]})},Ov={sm:{group:`h-7`,option:`px-2.5 text-body`},md:{group:`h-8`,option:`px-3 text-body`}},kv={group:(e=`sm`)=>U(`inline-flex`,Ov[e].group,`rounded-md bg-muted p-0.5`),option:(e,t=`sm`)=>U(`inline-flex items-center gap-1.5 rounded`,Ov[t].option,`font-medium transition-colors`,e?`bg-background text-foreground shadow-sm`:`text-muted-foreground hover:text-foreground`)},Av=({value:e,options:t,onChange:n,label:r,size:i=`sm`,iconOnly:a=!1})=>(0,q.jsx)(`span`,{role:`group`,"aria-label":r,className:kv.group(i),children:t.map(t=>(0,q.jsxs)(`button`,{type:`button`,"aria-pressed":t.value===e,...a&&{"aria-label":t.label,title:t.label},onClick:()=>n(t.value),className:kv.option(t.value===e,i),children:[t.icon&&(0,q.jsx)(t.icon,{className:`size-3.5`}),!a&&t.label]},t.value))}),jv=({tabs:e})=>(0,q.jsx)(`nav`,{"aria-label":b_(`tabs`),className:`overflow-x-auto py-6`,children:(0,q.jsx)(`span`,{className:kv.group(`md`),children:e.map(e=>(0,q.jsx)(Ue,{to:e.to,replace:!0,"aria-current":e.current?`page`:void 0,className:U(kv.option(e.current,`md`),`whitespace-nowrap`),children:e.title},e.title))})}),Mv=({name:e,label:t,required:n,help:r,example:i,error:a,conflict:o,wide:s,readOnly:c,children:l})=>{let u=(0,W.useId)(),d=[r&&`${u}-help`,i&&`${u}-example`,a&&`${u}-error`].filter(Boolean).join(` `)||void 0;return(0,q.jsxs)(`div`,{className:s?`sm:col-span-2`:void 0,children:[(0,q.jsxs)(`div`,{className:`mb-1.5 flex items-center gap-2`,children:[c?(0,q.jsx)(`span`,{className:`font-medium text-foreground`,children:t}):(0,q.jsxs)(`label`,{htmlFor:u,className:`font-medium text-foreground`,children:[t,n&&(0,q.jsx)(`span`,{className:`ml-0.5 text-danger-text`,"aria-hidden":`true`,children:`*`})]}),o&&(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-warning-text`,title:b_(`savedDifferent`,{name:o.user.name}),children:[(0,q.jsx)(Mi,{className:`size-3.5`}),(0,q.jsx)(v_,{initials:o.user.initials,hue:o.user.hue,size:`xs`})]})]}),(0,q.jsx)(wi,{value:{id:u,name:e,describedBy:d,invalid:!!a,required:!!n},children:l}),r&&(0,q.jsx)(`p`,{id:`${u}-help`,className:`mt-1.5 text-xs text-muted-foreground`,children:r}),i&&(0,q.jsxs)(`p`,{id:`${u}-example`,className:`mt-0.5 text-xs text-faint-foreground`,children:[b_(`example`),` `,i]}),a&&(0,q.jsx)(`p`,{id:`${u}-error`,className:`mt-1.5 text-body font-medium text-danger-text`,children:a}),o&&(0,q.jsxs)(`div`,{className:`mt-2 flex items-center justify-between gap-3 rounded-md border border-warning/30 bg-warning-soft px-3 py-2 text-body text-warning-text`,children:[(0,q.jsxs)(`span`,{children:[(0,q.jsx)(`strong`,{children:o.user.name}),` `,b_(`savedThis`,{ago:o.ago}),` `,(0,q.jsx)(`strong`,{children:o.theirValue})]}),(0,q.jsxs)(`span`,{className:`flex gap-1.5`,children:[(0,q.jsx)(P,{size:`sm`,onClick:o.onKeepMine,children:b_(`keepMine`)}),(0,q.jsx)(P,{size:`sm`,onClick:o.onUseTheirs,children:b_(`useTheirs`)})]})]})]})},Nv=({rows:e})=>(0,q.jsx)(`dl`,{className:`border-t border-border`,children:e.map(e=>(0,q.jsxs)(`div`,{className:U(`grid gap-x-4 border-b border-border py-2.5`,e.wide?`grid-cols-1 gap-y-1.5`:`grid-cols-[minmax(0,2fr)_minmax(0,3fr)]`),children:[(0,q.jsxs)(`dt`,{className:`min-w-0 text-muted-foreground`,children:[e.label,e.help&&(0,q.jsx)(`span`,{className:`mt-0.5 block text-xs text-faint-foreground`,children:e.help})]}),(0,q.jsx)(`dd`,{className:`min-w-0 break-words text-foreground`,children:e.value})]},e.label))}),Pv=({facts:e})=>(0,q.jsx)(`dl`,{className:`grid grid-cols-2 gap-x-4 gap-y-5 sm:flex sm:flex-wrap sm:gap-x-10`,children:e.map(({label:e,value:t,icon:n})=>(0,q.jsxs)(`div`,{title:e,className:`flex min-w-0 flex-col gap-1.5`,children:[(0,q.jsx)(`dt`,{className:`text-muted-foreground`,children:n?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(n,{className:`size-5`,"aria-hidden":!0}),(0,q.jsx)(`span`,{className:`sr-only`,children:e})]}):e}),(0,q.jsx)(`dd`,{className:`min-w-0 break-words text-base font-semibold text-foreground`,children:t})]},e))}),Fv=`flex min-h-11 items-center gap-2 rounded-md border border-border-strong px-3 text-left hover:bg-surface disabled:cursor-default disabled:opacity-60 md:min-h-0 md:w-full md:items-start md:gap-3 md:rounded-none md:border-0 md:px-4 md:py-3`,Iv=({actions:e})=>(0,q.jsxs)(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:[(0,q.jsx)(`h2`,{className:`hidden border-b border-border px-4 py-2.5 text-xs font-semibold uppercase tracking-wide text-muted-foreground md:block`,children:b_(`actions`)}),(0,q.jsx)(`ul`,{className:`flex flex-wrap gap-2 p-2 md:block md:divide-y md:divide-border md:p-0`,children:e.map(({name:e,description:t,icon:n,onRun:r,blocked:i,running:a,tone:o,render:s})=>{let c=(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(n,{className:U(`size-4 shrink-0 md:mt-0.5`,o===`danger`?`text-danger-text`:`text-muted-foreground`),"aria-hidden":!0}),(0,q.jsxs)(`span`,{children:[(0,q.jsx)(`span`,{className:U(`block font-medium`,o===`danger`?`text-danger-text`:`text-foreground`),children:e}),t&&(0,q.jsx)(`span`,{className:`mt-0.5 hidden text-xs leading-snug text-muted-foreground md:block`,children:t})]})]});return(0,q.jsx)(`li`,{children:s?s({className:Fv,children:c}):(0,q.jsx)(`button`,{type:`button`,onClick:r,disabled:!!i||a,title:i,className:Fv,children:c})},e)})})]}),Lv=`flex w-full items-center gap-2 px-3 py-2.5 text-left hover:bg-muted disabled:cursor-default disabled:opacity-60`,Rv=(e,t,n)=>Math.min(n-4,Math.max(e,4+t)),zv=e=>e-8,Bv=(e,t,n)=>{let[r,i]=(0,W.useState)();return(0,W.useLayoutEffect)(()=>{if(!e||!t.current||!n.current){i(void 0);return}let r=document.documentElement.clientWidth,a=zv(r);n.current.style.maxWidth=`${a}px`;let o=t.current.getBoundingClientRect().right,s=n.current.getBoundingClientRect().width;i({right:o-Rv(o,s,r),maxWidth:a})},[e]),r},Vv=()=>{let e=window.visualViewport;return e?{top:e.offsetTop,height:e.height}:{top:0,height:window.innerHeight}},Hv=(e,t,n,r)=>{let i=r.top+r.height-4-e.bottom,a=e.top-r.top-4;return n+t>i&&a>i},Uv=(e,t,n,r)=>{let[i,a]=(0,W.useState)(),[o,s]=(0,W.useState)(0);return(0,W.useEffect)(()=>{let t=window.visualViewport;if(!e||!t)return;let n=()=>s(e=>e+1);return t.addEventListener(`resize`,n),()=>t.removeEventListener(`resize`,n)},[e]),(0,W.useLayoutEffect)(()=>{if(!e||!t.current||!n.current){a(void 0);return}let r=t.current.getBoundingClientRect(),i=n.current.getBoundingClientRect().height,o=parseFloat(getComputedStyle(n.current).marginTop);a(Hv(r,i,o,Vv())?-(i+2*o):void 0)},[e,r,o]),i===void 0?void 0:{top:i}},Wv=(e,t,n)=>{let r=e.bottom+4;return{top:r+t.height>window.innerHeight-4?Math.max(4,e.top-4-t.height):r,right:n-Rv(e.right,t.width,n)}},Gv=()=>{let[e,t]=(0,W.useState)(!1),[n,r]=(0,W.useState)(),i=(0,W.useRef)(null),a=(0,W.useRef)(null);return(0,W.useLayoutEffect)(()=>{if(!e||!i.current||!a.current){r(void 0);return}a.current.style.right=`0px`;let t=zv(document.documentElement.clientWidth);a.current.style.maxWidth=`${t}px`;let n=a.current.getBoundingClientRect();r({...Wv(i.current.getBoundingClientRect(),n,n.right),maxWidth:t})},[e]),(0,W.useEffect)(()=>{if(!e)return;let n=e=>e instanceof Node&&!!(i.current?.contains(e)||a.current?.contains(e)),r=e=>{(e instanceof KeyboardEvent?e.key===`Escape`:!n(e.target))&&t(!1)},o=e=>{n(e.target)||t(!1)};return document.addEventListener(`mousedown`,r),document.addEventListener(`keydown`,r),document.addEventListener(`scroll`,o,!0),window.addEventListener(`resize`,o),()=>{document.removeEventListener(`mousedown`,r),document.removeEventListener(`keydown`,r),document.removeEventListener(`scroll`,o,!0),window.removeEventListener(`resize`,o)}},[e]),{open:e,setOpen:t,place:n,button:i,menu:a}},Kv=({actions:e,label:t=b_(`actions`),className:n})=>{let{open:r,setOpen:i,place:a,button:o,menu:s}=Gv();return e.length===0?null:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`button`,{ref:o,type:`button`,"aria-label":t,"aria-haspopup":`menu`,"aria-expanded":r,onClick:()=>i(!r),className:n,children:(0,q.jsx)(nl,{className:`size-5`})}),r&&(0,ls.createPortal)((0,q.jsx)(`ul`,{ref:s,role:`menu`,"aria-label":t,style:a??{visibility:`hidden`},className:`fixed z-50 max-h-[calc(100dvh-1rem)] min-w-48 overflow-y-auto rounded-md border bg-background py-1 shadow-pop`,children:e.map(({name:e,icon:t,onRun:n,blocked:r,running:a,tone:o,render:s})=>{let c=(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(t,{className:U(`size-4 shrink-0`,o===`danger`?`text-danger-text`:`text-muted-foreground`),"aria-hidden":!0}),(0,q.jsxs)(`span`,{className:`min-w-0`,children:[(0,q.jsx)(`span`,{className:U(`block font-medium`,o===`danger`&&`text-danger-text`),children:e}),r&&(0,q.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:r})]})]});return(0,q.jsx)(`li`,{role:`none`,onClick:()=>i(!1),children:s&&!r?s({className:`flex w-full items-center gap-2 px-3 py-2.5 text-left hover:bg-muted disabled:cursor-default disabled:opacity-60`,children:c,role:`menuitem`}):(0,q.jsx)(`button`,{type:`button`,role:`menuitem`,onClick:n,disabled:!!r||a,title:r,className:`flex w-full items-center gap-2 px-3 py-2.5 text-left hover:bg-muted disabled:cursor-default disabled:opacity-60`,children:c})},e)})}),document.body)]})},qv=({rows:e})=>(0,q.jsx)(`dl`,{className:`grid grid-cols-[auto_minmax(0,1fr)] gap-x-4 gap-y-2`,children:e.map(e=>(0,q.jsxs)(`div`,{className:`contents`,children:[(0,q.jsx)(`dt`,{className:`text-muted-foreground`,children:e.label}),(0,q.jsx)(`dd`,{title:e.title,className:`truncate text-right tabular-nums text-foreground`,children:e.value})]},e.label))}),Jv=({title:e,children:t})=>(0,q.jsxs)(`div`,{className:`rounded-lg border border-border bg-background p-4`,children:[(0,q.jsx)(`h2`,{className:`mb-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground`,children:e}),t]}),Yv=({title:e,rows:t})=>t.length===0?null:(0,q.jsx)(Jv,{title:e,children:(0,q.jsx)(qv,{rows:t})}),Xv=(e=ci())=>new Intl.NumberFormat(e).formatToParts(1.5).find(e=>e.type===`decimal`)?.value===`,`?`,`:`.`,Zv=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),Qv=(e,t)=>{let n=`[${Zv(t===`.`?`,`:`.`)}\\s\\u00a0\\u202f']`,r=RegExp(`^([-+]?)(\\d{1,3}(?:${n}\\d{3})+|\\d+)(?:${Zv(t)}(\\d+))?$`).exec(e.trim());if(r)return`${r[1]===`-`?`-`:``}${r[2].replace(/\D/g,``)}${r[3]?`.${r[3]}`:``}`;if(t===`.`&&/^[-+]?\d+(\.\d+)?e[-+]?\d+$/i.test(e.trim()))return String(Number(e.trim()))},$v=e=>e==null?``:typeof e==`object`?JSON.stringify(e):String(e),ey=new Set([`text`,`integer`,`bigint`,`decimal`,`date`,`currency`,`country`]),ty=new Set([`uuid`,`timestamp`,`relation`]),ny=(e,t)=>e.readOnly||ty.has(e.type)?!1:e.type!==`json`||t?.widget!==void 0,ry=e=>!e.readOnly&&!e.nullable&&e.type!==`boolean`,iy=new Set([`integer`,`bigint`,`decimal`]),ay=e=>{try{return JSON.parse(e)}catch(t){if(t instanceof SyntaxError)return e;throw t}},oy=(e,t)=>Qv(e,t)??e,sy=(e,t,n=Xv())=>{if(e.type===`boolean`)return!!t;if(e.type===`file`)return Fr(t);let r=String(t).trim();if(r===``)return e.nullable?null:``;let i=iy.has(e.type)?oy(r,n):r;if(e.type===`integer`)return Number(i);if(e.type===`relation`)return typeof t==`number`?t:i;if(ey.has(e.type)||e.type===`enum`)return i;if(e.type===`json`)return ay(i);throw Error(`Not implemented: editing ${e.type} fields`)},cy=(e,t,n=Xv())=>e.type===`boolean`?!!t:String(t??``).trim()===``?null:sy(e,t,n),ly=(e,t)=>e.type===`boolean`?!!t:$v(t),uy=(e,t,n,r=Xv())=>{if(e.type===`boolean`)return!!t!=!!n;if(e.type===`file`)return kr(t,n);let i=String(t??``).trim(),a=$v(n);return e.type===`decimal`||e.type===`integer`?i===``||a===``?i!==a:Number(oy(i,r))!==Number(a):i!==a},dy=(e,t,n)=>t?e===void 0||e===`edit`||n?{shown:`form`,offersEdit:!1,editing:!0}:{shown:e,offersEdit:t,editing:!1}:{shown:`read`,offersEdit:!1,editing:!1},fy=(e,t,n)=>(e??t?.helpWhen??`always`)===`always`||n,py=(e,t,n)=>e?.help!==void 0&&fy(e.helpWhen,t,n)?e.help:void 0,my=(e,t)=>e===`editing`?t:e!==`reading`||!t,hy=B(`app/create`),gy=e=>typeof e==`object`&&!!e&&`key`in e,_y=(e,t,n)=>t.name!==e.tenant&&!t.readOnly&&!n?.notOnCreate&&(t.type===`relation`||ny(t,n)),vy=(e,t)=>{let n=Object.values(e.fields).filter(n=>_y(e,n,t?.fields[n.name])).map(e=>e.name),r=new Set,i=za(t?.layout??[]).flatMap(e=>{if(e.kind!==`section`||yf(e.when)||!my(e.when,!0))return[];let i=e.fields.filter(e=>n.includes(e)&&!r.has(e)&&my(t?.fields[e]?.when,!0));return i.forEach(e=>r.add(e)),i.length>0?[{title:e.title,help:e.help,fields:i}]:[]}),a=n.filter(t=>!r.has(t)&&!e.fields[t].writeOnly);return a.length===0?i:[...i,{title:i.length===0?hy(`details`):hy(`otherFields`),fields:a}]},yy=(e,t)=>(e?.primaryKey.length===1?e.fields[e.primaryKey[0]]?.type:void 0)===`integer`?Number(t):t,by=(e,t,n)=>Object.fromEntries(Object.entries(n).flatMap(([n,r])=>{let i=e.fields[n];return i?gy(r)?[[n,yy(t[i.relation?.resource??``],r.key)]]:i.type===`boolean`?[[n,!!r]]:i.type===`file`?r?[[n,sy(i,r)]]:[]:String(r).trim()===``?[]:[[n,sy(i,r)]]:[]})),xy=e=>!e.nullable&&!e.default&&e.type!==`boolean`,Sy=(e,t)=>e.type===`relation`?{key:t,label:t}:e.type===`boolean`?t===`true`:t,Cy=new Set([`integer`,`bigint`,`decimal`]),wy=e=>{if(!Cy.has(e.type)||!e.default||!(`value`in e.default))return;let t=e.default.value;return t==null?void 0:String(t)},Ty=(e,t,n={})=>Object.fromEntries(t.flatMap(t=>t.fields.flatMap(t=>{let r=e.fields[t];if(Object.hasOwn(n,t))return[[t,Sy(r,n[t])]];let i=r.default;return wy(r)!==void 0||!i||!(`value`in i)||i.value===null||i.value===void 0?[]:[[t,typeof i.value==`boolean`?i.value:$v(i.value)]]}))),Ey=e=>!!(e.default&&`db`in e.default),Dy=e=>{if(!Tn(e))return[{message:e instanceof Error?e.message:R(`somethingWentWrong`)}];let t=e.errors.map(e=>({message:e.message,hint:e.hint}));return t.length>0?t:[{message:e.message}]},Oy=({error:e,title:t,onRetry:n})=>(0,q.jsxs)(`div`,{role:`alert`,className:`flex gap-2.5 rounded-lg border border-danger/30 bg-danger-soft px-3 py-2 text-danger-text`,children:[(0,q.jsx)(Mi,{className:`mt-0.5 size-4 shrink-0`}),(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsx)(`p`,{className:`font-medium`,children:t}),Dy(e).map(e=>(0,q.jsxs)(`p`,{className:`text-body`,children:[e.message,e.hint&&(0,q.jsxs)(`span`,{className:`text-muted-foreground`,children:[` `,e.hint]})]},e.message))]}),n&&(0,q.jsx)(P,{size:`sm`,onClick:n,children:R(`tryAgain`)})]}),ky=({checked:e,onChange:t,label:n})=>{let r=mi();return(0,q.jsx)(`button`,{type:`button`,role:`switch`,id:r.id,"aria-describedby":r[`aria-describedby`],"aria-checked":e,"aria-label":n,onClick:()=>t?.(!e),className:U(`relative inline-flex h-5 w-9 shrink-0 items-center rounded-full transition-colors`,e?`bg-primary`:`bg-border-strong`),children:(0,q.jsx)(`span`,{className:U(`size-4 rounded-full bg-white shadow transition-transform`,e?`translate-x-[18px]`:`translate-x-0.5`)})})},Ay=e=>{e.style.height=`auto`,e.style.height=`${e.scrollHeight+e.offsetHeight-e.clientHeight}px`},jy=({invalid:e,className:t,rows:n=3,value:r,ref:i,...a})=>{let o=(0,W.useRef)(null),s=(0,W.useCallback)(e=>{o.current=e,typeof i==`function`?i(e):i&&(i.current=e)},[i]),c=mi();return(0,W.useLayoutEffect)(()=>{o.current&&Ay(o.current)},[r]),(0,W.useEffect)(()=>{let e=o.current;if(!e)return;let t=e.clientWidth,n=new ResizeObserver(()=>{e.clientWidth!==t&&(t=e.clientWidth,Ay(e))});return n.observe(e),()=>n.disconnect()},[]),(0,q.jsx)(`textarea`,{ref:s,rows:n,value:r,className:U(`block w-full resize-none overflow-hidden rounded-md border bg-background px-2.5 py-1.5 text-body text-foreground shadow-sm outline-none placeholder:text-faint-foreground focus:border-primary focus:ring-2 focus:ring-primary/20`,e?`border-danger`:`border-border-strong`,t),...c,...e&&{"aria-invalid":!0},...a})},My=(e,t,n)=>{if(!URL.canParse(e,t))return`no-referrer`;let r=new URL(e,t);if((r.protocol===`http:`||r.protocol===`https:`)&&!(r.origin===new URL(t).origin||n.includes(r.hostname)))return`no-referrer`},Ny=e=>URL.canParse(e)?[new URL(e).hostname]:[],Py=()=>{let e=(0,W.useContext)(ui);return(0,W.useMemo)(()=>[...e?.files?.trustedHosts??[],...(e?.sources??[]).flatMap(({source:e})=>Ny(e.url))],[e?.files,e?.sources])},Fy=e=>{let t;try{t=atob(e)}catch(e){if(e instanceof DOMException&&e.name===`InvalidCharacterError`)return;throw e}return ut(Uint8Array.from(t,e=>e.charCodeAt(0)))},Iy=({image:e,alt:t=``,className:n,loading:r})=>{let[i,a]=(0,W.useState)(),o=Py(),s=(0,W.useMemo)(()=>e.placeholder===void 0?void 0:Fy(e.placeholder),[e.placeholder]),c=s!==void 0&&i!==e.url;return(0,q.jsx)(`img`,{src:e.url,alt:t,loading:r,decoding:`async`,referrerPolicy:My(e.url,window.location.href,o),onLoad:()=>a(e.url),className:n,style:c?{backgroundImage:`url("${s}")`,backgroundSize:`cover`,backgroundPosition:`center`}:void 0})},Ly=15e3,Ry=()=>{let e=Ig();return fi().data?.status&&e?.state.kind===`signed-in`?String(e.state.user.id):void 0},zy=()=>{let e=F(),t=Ry();return Tt({queryKey:I.statuses(t??``),enabled:t!==void 0,refetchInterval:Ly,queryFn:()=>e.status.people()})},By=()=>{let e=F(),t=Ry();return Tt({queryKey:I.ownStatus(t??``),enabled:t!==void 0,refetchInterval:Ly,queryFn:()=>e.status.own()})},Vy=(e,t=Date.now())=>e.isSuccess&&!e.isFetching&&t-e.dataUpdatedAt>=1e4,Hy=(e,t)=>{let n=new Map(t.map(e=>[e.userId,e]));return e.map(e=>{let t=n.get(e.id);return t?{...e,status:t}:e})},Uy=()=>{let e=Ig(),t=e?.state.kind===`signed-in`?e.state.user:void 0,n=Tt({queryKey:I.members(t?.id??``),enabled:t!==void 0,queryFn:()=>{if(!e?.organizations)throw Error(`useMembers() needs organizations: turn them on in the auth config.`);return e.session.organizations.people()}}),r=zy().data,i=(0,W.useMemo)(()=>n.data&&(r?Hy(n.data,r):n.data),[n.data,r]),a=(0,W.useMemo)(()=>new Map((i??[]).map(e=>[e.id,e])),[i]),{refetch:o}=n,s=(0,W.useCallback)(e=>{let t=a.get(e);return!t&&Vy(n)&&setTimeout(()=>void o(),0),t},[a,n,o]);return{...n,data:i,member:s}},Wy=e=>e,Gy=e=>e,Ky=(0,W.createContext)({}),qy=()=>(0,W.useContext)(Ky),Jy=(e,t)=>t?.titleFrom?.fields??[],Yy=(e,t)=>(n,r,i,a)=>{let o=r?.titleFrom;if(!o)return ke(n,r,i,a);let s=e[o.rule];return!s||o.unreadable||o.fields.some(e=>i[e]===void 0)?a:s(i,t)||a},Xy=()=>void 0,Zy=(0,W.createContext)(Yy({},{user:void 0,member:Xy})),Qy=()=>(0,W.useContext)(Zy),$y=({rules:e,user:t,children:n})=>{let r=(0,W.useMemo)(()=>Yy(e,{user:t,member:Xy}),[e,t]);return(0,q.jsx)(Zy.Provider,{value:r,children:n})},eb=({rules:e,user:t,children:n})=>{let{member:r}=Uy(),i=(0,W.useMemo)(()=>Yy(e,{user:t,member:r}),[e,t,r]);return(0,q.jsx)(Zy.Provider,{value:i,children:n})},tb=({children:e})=>{let{views:t}=c(),{titles:n}=qy(),r=Ig(),i=r?.state.kind===`signed-in`?r.state.user:void 0,a=n??{};return Object.values(t).some(e=>e.titleFrom!==void 0)&&i&&r?.organizations?(0,q.jsx)(eb,{rules:a,user:i,children:e}):(0,q.jsx)($y,{rules:a,user:i,children:e})},nb=m(),rb=async(e,t,n,r,i)=>{let a=n.primaryKey[0],o=[...new Set(r)].sort();if(o.length===0||n.primaryKey.length!==1)return new Map;let s=pe(n,i),c=await e.fetchQuery({queryKey:I.labels(n.name,o.join(`,`)),staleTime:3e5,queryFn:async()=>(await t.list(n.name,{filter:vn(nb.in(a,o)),fields:[a,s],pageSize:o.length})).items.map(e=>[String(e[a]),String(e[s])])});return new Map(c)},ib=(e,t,n)=>n.flatMap(n=>{let r=t.fields[n],i=r?.type===`relation`&&r.relation?e[r.relation.resource]:void 0;return i?[{name:n,target:i}]:[]}),ab=(e,t,n,r)=>Object.fromEntries(ib(e,n,r).filter(({target:e})=>e.primaryKey.length===1&&!t[e.name]?.titleFrom).map(({name:e,target:n})=>[e,pe(n,t[n.name])])),ob=(e,t,n,r,i={})=>{let a=ib(e,t,n);return r.map(e=>{let t={...e};for(let{name:n}of a)e[n]!=null&&(t[n]={id:e[n],name:i[n]?.[String(e[n])]??String(e[n])});return t})},sb=m(),cb=(e,t)=>{let n=t?.titleFrom;if(n&&!n.unreadable&&e.primaryKey.length===1)return n.fields},lb=(e,t,n)=>I.titleRow(e.name,t,n.join(`,`)),ub=async(e,t,n,r)=>{let i=t.primaryKey[0],a=[...new Set(r)];if(a.length===0)return new Map;let o=await e.list(t.name,{filter:vn(sb.in(i,a)),fields:[i,...n],pageSize:a.length});return new Map(o.items.map(e=>[String(e[i]),e]))},db=async(e,t,n,r,i,a,o)=>{let s=new Map;for(let e of a){let t=i.fields[e],a=t?.type===`relation`&&t.relation?n[t.relation.resource]:void 0;if(!a||!cb(a,r[a.name]))continue;let c=o.flatMap(t=>t[e]==null?[]:[String(t[e])]);s.set(a.name,[...s.get(a.name)??[],...c])}await Promise.all([...s].map(async([i,a])=>{let o=n[i],s=cb(o,r[i]),c=await ub(t,o,s,a);for(let t of new Set(a))e.setQueryData(lb(o,t,s),{row:c.get(t)??null})}))},fb=(e,t,n,r,i)=>{let a=r?.titleFrom;return a?{queryKey:lb(n,i,a.fields),queryFn:async()=>({row:(await ub(t,n,a.fields,[i])).get(i)??null})}:{queryKey:I.relatedLabel(n.name,i),queryFn:async()=>({label:(await rb(e,t,n,[i],r)).get(i)??i})}},pb=(e,t,n,r,i)=>{if(e)return`label`in e?e.label:e.row?t(n,r,e.row,i):i},mb=(e,t,n=!0)=>{let{views:r}=c(),i=F(),a=nn(),o=Qy(),s=r[e.name];return pb(Tt({...fb(a,i,e,s,t),staleTime:3e5,enabled:n}).data,o,e,s,t)},hb=({children:e})=>(0,q.jsx)(`pre`,{className:`whitespace-pre-wrap [overflow-wrap:anywhere] rounded-md bg-muted/60 px-3 py-2 font-mono text-xs text-foreground`,children:e}),gb=e=>{let t=e.split(`
4
+ `);return t.length<=20?{lines:t.length,folded:null}:{lines:t.length,folded:t.slice(0,20).join(`
5
+ `)}},_b=B(`app/field-types/json`),vb=({value:e})=>{let[t,n]=(0,W.useState)(!1),r=JSON.stringify(e,null,2),{lines:i,folded:a}=gb(r);return a===null?(0,q.jsx)(hb,{children:r}):(0,q.jsxs)(`div`,{className:`grid gap-1`,children:[(0,q.jsx)(hb,{children:t?r:a}),(0,q.jsx)(P,{size:`sm`,variant:`ghost`,className:`-ml-2 justify-self-start`,"aria-expanded":t,onClick:()=>n(!t),children:t?_b(`showLess`):_b(`showAll`,{count:i})})]})},yb=e=>t=>{let n=t.currentTarget;n.scrollWidth>Math.ceil(n.getBoundingClientRect().width)?n.title=e:n.removeAttribute(`title`)},bb=({text:e,className:t})=>(0,q.jsx)(`span`,{className:U(`truncate`,t),onMouseEnter:yb(e),children:e}),xb=Symbol(`not JSON`),Sb=e=>{if(e.trim()===``)return null;try{return JSON.parse(e)}catch(e){if(!(e instanceof SyntaxError))throw e;return xb}},Cb=({value:e})=>e===null?(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:`—`}):(0,q.jsx)(vb,{value:e}),wb=({value:e})=>(0,q.jsx)(bb,{text:_v(e)}),Tb=({value:e,onChange:t,invalid:n})=>{let[r,i]=(0,W.useState)(),a=r??(e===null?``:JSON.stringify(e,null,2)),o=r!==void 0&&Sb(r)===xb;return(0,q.jsxs)(`div`,{className:`grid gap-1`,children:[(0,q.jsx)(jy,{value:a,rows:3,invalid:n||o,className:`font-mono text-xs`,onChange:e=>{i(e.target.value);let n=Sb(e.target.value);n!==xb&&t(n)}}),o&&(0,q.jsx)(`p`,{className:`text-xs text-danger-text`,children:_b(`notJson`)})]})},Eb={of:[...ts.json],display:Cb,editor:Tb,cell:wb,wide:!0},Db=e=>[...e].reduce((e,t)=>(e*31+t.charCodeAt(0))%360,7),Ob=e=>e.split(/[\s@.]+/).filter(Boolean).slice(0,2).map(e=>e[0].toUpperCase()).join(``),kb=e=>(e.role??`user`).split(`,`).map(e=>e.trim()),Ab=e=>kb(e).includes(`admin`),jb=e=>tv(e.replace(/[_-]+/g,` `).trim()),Mb=e=>{let t=kb(e),n=t.includes(`admin`);return{name:e.name||e.email,email:e.email,initials:Ob(e.name||e.email)||`?`,hue:Db(e.id||e.email),role:n?J(`admin`):jb(t[0]??`user`),roleTone:n?`violet`:`blue`}},Nb=B(`app/field-types/members`),Pb=({id:e,name:t})=>(0,q.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-1.5`,children:[(0,q.jsx)(v_,{initials:t&&Ob(t)||`?`,hue:Db(e),size:`xs`,className:`ring-0`}),(0,q.jsx)(`span`,{className:t===void 0?`truncate text-muted-foreground`:`truncate`,children:t??Nb(`unknownMember`)})]}),Fb=m(),Ib=e=>e.split(/\s+/).filter(Boolean),Lb=(e,t,n,r=!1)=>{let i=Ib(n);if(i.length===0)return{filter:void 0,local:!1};if(r)return{filter:void 0,local:!0};if(e.search?.length)return{filter:vn(Fb.search(n)),local:!1};let a=e.fields[t];if(a?.type!==`text`||!a.filterable)return{filter:void 0,local:!0};let o=i.map(e=>Fb.eq(t,`*${e.replaceAll(`*`,``)}*`));return{filter:vn(Fb.and(...o)),local:!1}},Rb=(e,t)=>{if(e==null)return!1;let n=String(e).toLowerCase();return Ib(t).every(e=>n.includes(e.toLowerCase()))},zb=e=>Array.isArray(e)?e.filter(e=>typeof e==`string`):[],Bb=(e,t)=>e.includes(t)?e.filter(e=>e!==t):[...e,t],Vb=(e,t)=>e.filter(e=>Rb(e.name,t)).map(e=>({key:e.id,label:e.name})),Hb=()=>{let e=Ig(),t=Uy();return{...t,needsOrganizations:!e?.organizations,failed:t.isError}},Ub=({value:e,line:t})=>{let n=Hb(),r=zb(e);return r.length===0?(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:`—`}):n.needsOrganizations?(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:Nb(`needsOrganizations`)}):n.failed?(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:Nb(`couldNotLoadMembers`)}):n.isLoading?(0,q.jsx)(L,{className:`h-4 w-24`}):(0,q.jsx)(`span`,{className:U(`flex min-w-0 items-center gap-x-3 gap-y-1`,t?`overflow-hidden`:`flex-wrap`),children:r.map(e=>(0,q.jsx)(Pb,{id:e,name:n.member(e)?.name},e))})},Wb=e=>(0,q.jsx)(Ub,{...e,line:!1}),Gb=e=>(0,q.jsx)(Ub,{...e,line:!0}),Kb=({label:e,onRemove:t})=>(0,q.jsxs)(`span`,{className:`inline-flex h-5 max-w-full items-center gap-0.5 rounded bg-primary-soft pl-1.5 pr-0.5 text-xs font-medium text-primary-text`,children:[(0,q.jsx)(`span`,{className:`truncate`,children:e}),(0,q.jsx)(`button`,{type:`button`,"aria-label":yn(`remove`,{label:e}),className:`rounded p-0.5 hover:bg-primary-border/60`,onMouseDown:e=>e.preventDefault(),onClick:t,children:(0,q.jsx)(Ci,{className:`size-3`})})]}),qb=()=>{let[e,t]=(0,W.useState)(``),[n,r]=(0,W.useState)(!1);return{text:e,setText:t,open:n,setOpen:r}},Jb=(e,t,n,r)=>{(0,W.useEffect)(()=>{if(!e||!t||!r)return;let n=new IntersectionObserver(e=>e.some(e=>e.isIntersecting)&&r(),{root:e});return n.observe(t),()=>n.disconnect()},[e,t,n,r])},Yb=({search:e,options:t,chosen:n,several:r,closedText:i,placeholder:a,invalid:o,paging:s,loading:c,failed:l,onChoose:u})=>{let{text:d,setText:f,open:p,setOpen:m}=e,[h,g]=(0,W.useState)(-1),[_,v]=(0,W.useState)(null),[y,b]=(0,W.useState)(null),x=(0,W.useId)(),S=s?.more??!1;Jb(_,y,s?.loaded??0,s?.loadMore);let C=e=>`${x}-${e}`,w=(0,W.useRef)(null);(0,W.useEffect)(()=>{!p&&document.activeElement===w.current&&w.current?.select()},[p]),(0,W.useEffect)(()=>{p&&h>=0&&document.getElementById(C(h))?.scrollIntoView({block:`nearest`})});let T=()=>{f(``),g(-1),m(!1)},E=e=>{if(u(e),!r)return T();f(``),g(-1)};return(0,q.jsxs)(`div`,{className:`relative`,children:[(0,q.jsx)(bi,{ref:w,role:`combobox`,"aria-autocomplete":`list`,"aria-expanded":p,"aria-controls":x,"aria-activedescendant":p&&t[h]?C(h):void 0,invalid:o,placeholder:a,value:p?d:i,onFocus:()=>m(!0),onBlur:T,onKeyDown:e=>{if(e.key===`ArrowDown`||e.key===`ArrowUp`){if(e.preventDefault(),!p)return m(!0);let n=e.key===`ArrowDown`?1:-1;g(e=>Math.min(Math.max(e+n,0),t.length-1));return}if(e.key===`Enter`&&p&&t[h]){e.preventDefault(),E(t[h]);return}e.key===`Escape`&&p&&(e.preventDefault(),e.stopPropagation(),T())},onChange:e=>{f(e.target.value),g(e.target.value.trim()?0:-1),m(!0)}}),p&&(0,q.jsxs)(`ul`,{ref:v,id:x,role:`listbox`,"aria-multiselectable":r||void 0,className:`absolute z-30 mt-1 max-h-60 w-full overflow-y-auto rounded-md border bg-background py-1 shadow-pop`,onMouseDown:e=>e.preventDefault(),children:[t.map((e,t)=>(0,q.jsx)(`li`,{id:C(t),role:`option`,"aria-selected":t===h,className:U(`cursor-pointer truncate px-3 py-1.5`,t===h&&`bg-muted`,n.includes(e.key)&&`font-medium`),onMouseMove:()=>t!==h&&g(t),onClick:()=>E(e),children:e.label},e.key)),S&&(0,q.jsx)(`li`,{ref:b,"aria-hidden":!0,className:`h-px`}),l&&(0,q.jsx)(`li`,{className:`px-3 py-1.5 text-muted-foreground`,children:R(`couldNotLoadOptions`)}),!S&&!c&&!l&&t.length===0&&(0,q.jsx)(`li`,{className:`px-3 py-1.5 text-muted-foreground`,children:R(`noMatches`)}),c&&(0,q.jsx)(`li`,{className:`px-3 py-1.5 text-muted-foreground`,children:R(`loading`)})]})]})},Xb=({value:e,invalid:t,onChange:n})=>{let r=qb(),i=Hb(),a=zb(e);if(i.needsOrganizations)return(0,q.jsx)(`p`,{className:`py-1.5 text-muted-foreground`,children:Nb(`needsOrganizations`)});let o=e=>i.member(e)?.name??Nb(`unknownMember`);return(0,q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,q.jsx)(Yb,{search:r,options:Vb(i.data??[],r.text),chosen:a,several:!0,closedText:``,placeholder:Nb(`searchMembers`),invalid:t,loading:i.isLoading,failed:i.failed,onChoose:e=>n(Bb(a,e.key))}),a.length>0&&(0,q.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:a.map(e=>(0,q.jsx)(Kb,{label:o(e),onRemove:()=>n(a.filter(t=>t!==e))},e))})]})},Zb={of:[...ts.members],display:Wb,editor:Xb,cell:Gb},Qb=(0,W.createContext)(void 0),$b=()=>(0,W.useContext)(Qb),ex=(e,t,{filter:n,orderBy:r,pageSize:i=50,fields:a,labels:o,startToken:s=``})=>{let c=Bn(n)??``;return{queryKey:[...I.list(t,c,r??``,i,s),a?.join(`,`)??``,...o?[o]:[]],initialPageParam:s,queryFn:({pageParam:n})=>e.list(t,{filter:c,orderBy:r,pageSize:i,fields:a,labels:o,pageToken:n}),getNextPageParam:e=>e.nextPageToken||void 0}},tx=(e,{enabled:t=!0,refetchInterval:n,...r}={})=>{let i=mt({...ex(F(),e,r),enabled:t,refetchInterval:n}),a=i.data?.pages??[];return{...i,items:a.flatMap(e=>e.items),totalEstimate:a[0]?.totalSizeEstimate,labels:Object.fromEntries(Object.keys(r.labels??{}).map(e=>[e,Object.assign({},...a.map(t=>t.labels?.[e]??{}))]))}},nx=(e,t,n=!0)=>{let r=F(),i=Nn(t);return Tt({queryKey:I.record(e,i),enabled:n,queryFn:()=>r.get(e,t)})},rx=(e,t,n=!0)=>{let r=F(),i=nn(),a=Nn(t);return Tt({queryKey:I.record(e,a),enabled:n,queryFn:()=>r.get(e,t),placeholderData:()=>i.getQueryData(I.recordPreview(e,a))})},ix=(e,t)=>{let n=new Set,r,i=()=>{r=void 0;let i=new Set(n);n.clear();let a=e=>Dn(e,i);e.invalidateQueries({predicate:e=>a(e.queryKey)&&e.queryKey[0]!==`record`}),e.invalidateQueries({predicate:e=>a(e.queryKey)&&e.queryKey[0]===`record`,refetchType:t()?`none`:`active`})};return{changed:e=>{for(let t of e)n.add(t);n.size>0&&!r&&(r=setTimeout(i,300))},stop:()=>clearTimeout(r)}},ax=1e3,ox=e=>({...e,id:`${e.scope}#${e.seq}`,resume_at:e.resumeAt??null,started_at:e.startedAt,finished_at:e.finishedAt,duration_ms:Date.parse(e.finishedAt)-Date.parse(e.startedAt)}),sx=(e,{from:t,steps:n,revision:r})=>({rows:[...e.slice(0,t),...n.map(ox)],revision:r}),cx=(e,t)=>{let n=F(),r=nn(),i=I.workflowRunTrace(e??``),a=Tt({queryKey:i,queryFn:async()=>{let t=r.getQueryData(i);return sx(t?.rows??[],await n.workflowRunTrace(e,t&&{after:t.rows.length,revision:t.revision}))},select:e=>e.rows,enabled:e!==void 0,refetchInterval:t?ax:!1}),o=(0,W.useRef)(t),{refetch:s}=a;return(0,W.useEffect)(()=>{let n=o.current&&!t;o.current=t,n&&e!==void 0&&s()},[t,e,s]),a},lx=new Set([`queued`,`running`,`waiting`]),ux=e=>{let t=nn();(0,W.useEffect)(()=>{if(!e)return;let n=ix(t,()=>!1),r=setInterval(()=>n.changed([`workflow_runs`]),ax);return()=>{clearInterval(r),n.stop()}},[e,t])},dx=e=>{let t=nn(),n=(0,W.useContext)(On),r=(0,W.useRef)(e);(0,W.useEffect)(()=>{let i=r.current&&!e;r.current=e,i&&ix(t,()=>n?.paused()??!1).changed([`workflows`])},[e,t,n])},fx=(e,t)=>{if(!e)return;let n=typeof t==`string`?hi(e.stateMachine,t):void 0,r=n&&_i(e,n.join(`/`));return n&&r?.Type===`Block`?{within:n,startAt:r.Processor.StartAt}:{within:[],startAt:e.stateMachine.StartAt}},px=e=>{let t=nx(`workflow_runs`,e??``,e!==void 0),n=t.data?.record,r=n?.workflow_id!=null&&n.version!=null,i=nx(`workflow_versions`,[String(n?.workflow_id??``),Number(n?.version??0)],r),a=lx.has(String(n?.status)),o=typeof n?.test_step==`string`?Fi(n.test_step):i.data?ki(i.data.record):void 0,s=cx(e,a);return ux(a),dx(a),{id:e,run:n,stored:t.data,definition:o,place:fx(o,n?.block_state),steps:s.data??[],going:a,error:t.error??i.error??s.error}},mx=`workflows`,hx=({workflow:e,version:t,run:n})=>({kind:`record`,resource:mx,key:e,...t!==void 0&&{version:t},...n&&{run:n}}),gx=(e,t,n)=>hx({workflow:e,...t!==n&&{version:t}}),_x=(e,t,n,r)=>hx({workflow:e,...n!==r&&{version:n},run:t}),vx=({workflow:e,version:t},n)=>t===void 0?hx({workflow:e}):gx(e,t,n),yx=e=>e==null?void 0:Number(e),bx=()=>{let{address:e}=Me(),t=$b();if(t&&e?.kind===`record`)return{workflow:t.key,...e.version!==void 0&&{version:e.version},...e.run&&{run:e.run}}},xx=e=>{let t=nx(mx,e.workflow),n=yx(t.data?.record.version),r=yx(t.data?.record.enabled_version),i=`workflow_id = ${JSON.stringify(e.workflow)}`,a=tx(`workflow_versions`,{filter:i,orderBy:`version desc`,pageSize:100,fields:[`version`,`saved_at`]}),o=tx(`workflow_runs`,{filter:`${i} AND isNull(block_of)`,orderBy:`created_at desc`,pageSize:20,fields:[`id`,`status`,`version`,`created_at`,`duration_ms`,`input`,`started_by`,`rerun_of`,`replay`,`error`]}),s=px(e.run),c=e.version,l=nx(`workflow_versions`,[e.workflow,c??0],c!==void 0);return{latest:n,enabled:r,versions:a.items.map(e=>({version:Number(e.version),savedAt:String(e.saved_at)})),runs:o.items,trace:s,shown:c,pastDefinition:l.data&&ki(l.data.record),pastLayout:l.data&&Ei(l.data.record.layout),versionsError:a.error,runsError:o.error,pastError:l.error}},Sx=()=>{let e=F();return Tt({queryKey:I.workflowTypes,queryFn:()=>e.workflowTypes()})},Cx=(0,W.lazy)(()=>Ht(()=>import(`./workflow-graph-editor-DZHTqa3R.js`).then(e=>({default:e.WorkflowGraphEditor})),__vite__mapDeps([2,1,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31]))),wx=(0,W.lazy)(()=>Ht(()=>import(`./workflow-workbench-CG8xTDx0.js`).then(e=>({default:e.WorkflowWorkbench})),__vite__mapDeps([32,1,3,33,14,5,4,6,7,8,34,35,10,36,15,9,11,12,13,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,37,38]))),Tx=()=>(0,q.jsx)(L,{className:`h-full min-h-[22rem] w-full`}),Ex=[`trigger`,`execution_order`,`connections`,`trace`],Dx=(e,t)=>{let n=$b(),r=e=>{if(!n?.model.fields[e])return null;let t=n.value(e);if(t===``||t===void 0)return null;if(typeof t!=`string`||e!==`trigger`&&e!==`connections`)return t;try{return JSON.parse(t)}catch{return t}},i=n?ki({...Object.fromEntries(Ex.map(e=>[e,r(e)])),state_machine:e}):Oi({stateMachine:e}),a=t&&(e=>{let i=Ai(e);if(t(i.state_machine),n)for(let e of Ex){let t=n.model.fields[e];t&&JSON.stringify(i[e])!==JSON.stringify(r(e))&&n.change(e,ly(t,i[e]))}}),o=n?.model.fields.layout;return{definition:i,change:a,layout:o?Ei(n.value(`layout`)):void 0,changeLayout:t&&o&&(e=>n.change(`layout`,ly(o,e)))}},Ox=({value:e,onChange:t})=>{let n=Sx(),r=bx(),{definition:i,change:a,layout:o,changeLayout:s}=Dx(e,t),c={...o&&{layout:o},...s&&{onLayoutChange:s}};return n.error?(0,q.jsx)(Oy,{title:Ti(`typesFailed`),error:n.error}):n.data?(0,q.jsx)(wi.Provider,{value:void 0,children:(0,q.jsx)(W.Suspense,{fallback:(0,q.jsx)(Tx,{}),children:r?(0,q.jsx)(wx,{view:r,value:i,types:n.data,...a&&{onChange:a},...c}):(0,q.jsx)(Cx,{value:i,types:n.data,...a&&{onChange:a},...c})})}):(0,q.jsx)(Tx,{})},kx=({value:e})=>(0,q.jsx)(Ox,{value:e}),Ax=({value:e,onChange:t})=>(0,q.jsx)(Ox,{value:e,onChange:t}),jx=({value:e})=>(0,q.jsx)(`span`,{className:`tabular-nums`,children:Ti(`stateCount`,{count:Si(Oi({stateMachine:e}).stateMachine).length})}),Mx={of:[...ts.workflow],display:kx,editor:Ax,cell:jx,wide:!0},Nx=(0,W.lazy)(()=>Ht(()=>import(`./run-trace-view-ovkKBP1m.js`).then(e=>({default:e.RunTrace})),__vite__mapDeps([39,1,3,34,6,5,8,35,13,14,4,7,11,12,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,38,33,10,31]))),Px=({value:e})=>e===null?null:(0,q.jsx)(W.Suspense,{fallback:(0,q.jsx)(L,{className:`h-[28rem] w-full max-sm:h-[22rem]`}),children:(0,q.jsx)(Nx,{runId:e})}),Fx=({value:e})=>(0,q.jsx)(`span`,{className:`font-mono text-xs`,children:e}),Ix={of:[...ts.workflow_run],display:Px,cell:Fx,wide:!0},Lx={neutral:`text-faint-foreground`,info:`text-primary`,success:`text-success`,warning:`text-warning`,danger:`text-danger`},Rx={neutral:(0,q.jsx)(`circle`,{cx:`5`,cy:`5`,r:`3.5`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`}),info:(0,q.jsx)(`path`,{d:`M5 0.8 9.2 5 5 9.2 0.8 5Z`,fill:`currentColor`}),success:(0,q.jsx)(`circle`,{cx:`5`,cy:`5`,r:`4`,fill:`currentColor`}),warning:(0,q.jsx)(`path`,{d:`M5 0.6 9.6 9H0.4Z`,fill:`currentColor`,strokeLinejoin:`round`}),danger:(0,q.jsx)(`rect`,{x:`1.2`,y:`1.2`,width:`7.6`,height:`7.6`,rx:`1`,fill:`currentColor`})},zx=({tone:e,pulse:t=!1,className:n})=>(0,q.jsxs)(`span`,{"aria-hidden":!0,className:U(`relative flex size-2.5 shrink-0`,Lx[e],n),"data-tone":e,"data-pulse":t||void 0,children:[t&&(0,q.jsx)(`svg`,{viewBox:`0 0 10 10`,className:`absolute inset-0 size-2.5 animate-ping opacity-60 motion-reduce:animate-none`,children:Rx[e]}),(0,q.jsx)(`svg`,{viewBox:`0 0 10 10`,className:`relative size-2.5`,children:Rx[e]})]}),Bx=B(`app/field-types/workflow-status`),Vx=({id:e})=>(0,q.jsx)(q.Fragment,{children:Uy().member(e)?.name??e}),Hx=({by:e,at:t})=>{let n=Ig(),r=n?.state.kind===`signed-in`&&e!==null&&String(n.state.user.id)===e?Bx(`you`):e===null?`?`:n?.organizations?(0,q.jsx)(Vx,{id:e}):e;return(0,q.jsx)(`p`,{className:`text-body text-muted-foreground`,children:Bx.rich(`resolvedBy`,{who:r,when:dr(Date.parse(t))})})},Ux=e=>So.includes(e),Wx=e=>Co[e]??`neutral`,Gx=e=>{if(Ux(e))return{tone:Wx(e),words:Bx(`label`,{status:e})}},Kx=e=>dr(Date.parse(String(e))),qx=e=>{let t=e.run_status;if(!Ux(t))return;let n={status:t,tone:Wx(t),resolvable:wo.includes(t)},r=e.status_run_id==null?void 0:String(e.status_run_id);return t===`failing`||t===`healthy`?{...n,words:Bx(t,{when:Kx(e.status_run_at),runs:10}),...r&&{run:r}}:t===`unresolved`?{...n,words:Bx(t,{count:Number(e.unresolved_failures),runs:10,when:Kx(e.status_run_at)}),...r&&{run:r}}:{...n,words:Bx(t)}},Jx=B(`toasts`),Yx=`-my-0.5 rounded px-1.5 py-0.5 font-medium text-primary-text hover:bg-primary-soft`,Xx=({action:e})=>{if(`onClick`in e)return(0,q.jsx)(`button`,{type:`button`,onClick:e.onClick,className:Yx,children:e.label});let{href:t,onNavigate:n}=e;return(0,q.jsx)(`a`,{href:t,onClick:e=>{n&&nr(e)&&(e.preventDefault(),n(t))},className:Yx,children:e.label})},Zx={loading:(0,q.jsx)(wn,{className:`text-primary`}),success:(0,q.jsx)(Ac,{className:`size-4 text-success`}),warning:(0,q.jsx)(Mi,{className:`size-4 text-warning`}),error:(0,q.jsx)(Ic,{className:`size-4 text-danger`}),info:(0,q.jsx)(ed,{className:`size-4 text-primary`}),call:(0,q.jsx)(Mu,{className:`size-4 animate-pulse text-success`})},Qx=({state:e,title:t,description:n,action:r,actions:i=[],onDismiss:a})=>(0,q.jsxs)(`div`,{role:e===`error`||e===`call`?`alert`:`status`,className:U(`flex w-full max-w-80 items-start gap-3 rounded-lg border bg-background p-3 shadow-pop [animation:pb-slide-in_160ms_ease-out]`,e===`warning`&&`border-warning/40`,e===`error`&&`border-danger/40`),children:[(0,q.jsx)(`span`,{className:`mt-0.5`,children:Zx[e]}),(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsx)(`p`,{className:`font-medium text-foreground`,children:t}),n&&(0,q.jsx)(`p`,{className:`mt-0.5 text-xs text-muted-foreground`,children:n})]}),r&&(0,q.jsx)(Xx,{action:r}),i.map(e=>(0,q.jsx)(Xx,{action:e},e.label)),a&&(0,q.jsx)(`button`,{type:`button`,"aria-label":Jx(`dismiss`),onClick:a,className:`inline-flex items-center justify-center rounded p-0.5 text-faint-foreground hover:bg-muted hover:text-foreground pointer-coarse:size-9`,children:(0,q.jsx)(Ci,{className:`size-3.5`})})]}),$x={loading:1/0,success:3500,warning:8e3,error:8e3,info:8e3,call:1/0},eS=8e3,tS=(0,W.createContext)(null),nS=()=>{let e=(0,W.useContext)(tS);if(!e)throw Error(`useToast must be used inside ToastProvider`);return e},rS=({children:e})=>{let[t,n]=(0,W.useState)([]),r=(0,W.useRef)(1),i=(0,W.useRef)(new Map),a=(0,W.useRef)(new Set),o=(0,W.useCallback)(e=>{clearTimeout(i.current.get(e)),i.current.delete(e),a.current.delete(e),n(t=>t.filter(t=>t.id!==e))},[]),s=(0,W.useCallback)((e,t,n=!1)=>{if(clearTimeout(i.current.get(e)),a.current.has(e))return;let r=n?eS:$x[t];r!==1/0&&i.current.set(e,setTimeout(()=>o(e),r))},[o]),c=e=>{e.onClose?.(),o(e.id)},l=(0,W.useMemo)(()=>({show:e=>{let t=r.current++;return e.sticky&&a.current.add(t),n(n=>[...n,{...e,id:t}]),s(t,e.state,!!e.action),t},update:(e,t)=>{n(n=>n.map(n=>n.id===e?{...n,...t}:n)),t.state&&s(e,t.state,!!t.action)},dismiss:o}),[o,s]);return(0,q.jsxs)(tS.Provider,{value:l,children:[e,(0,q.jsx)(`div`,{className:`pointer-events-none fixed inset-x-4 bottom-[calc(6rem+var(--pb-safe-bottom))] z-[100] flex flex-col items-end gap-2 md:inset-x-auto md:bottom-[calc(1rem+var(--pb-safe-bottom))] md:right-[calc(1rem+var(--pb-safe-right))]`,children:t.map(e=>(0,q.jsx)(`div`,{className:`pointer-events-auto`,children:(0,q.jsx)(Qx,{state:e.state,title:e.title,description:e.description,action:e.action,...e.actions&&{actions:e.actions},onDismiss:()=>c(e)})},e.id))})]})},iS=(e,t)=>e[t]||e.conditional.includes(t),aS=(e,t)=>e.permissions?.[t]??!0,oS=(e,t)=>e?.fields?e.fields[t]??`hidden`:`edit`,sS=`workflow_resolutions`,cS=(e,t)=>{let n=F(),r=qr(),i=nS(),a=iS(re(`workflow_resolutions`),`create`)&&t,[o,s]=(0,W.useState)(!1);return{permitted:a,busy:o,resolve:async()=>{s(!0),await n.create(sS,{workflow_id:e}).then(async()=>{await Promise.all([r(`workflows`),r(sS)]),i.show({state:`success`,title:Bx(`resolveDone`)})},()=>i.show({state:`error`,title:Bx(`resolveFailed`)})),s(!1)}}},lS=({workflow:e,value:t})=>{let n=nx(mx,e).data,r=n?.record,i=cS(e,n?.permissions?.update!==!1),a=r&&qx({...r,run_status:t});return!r||!a?null:(0,q.jsxs)(`div`,{className:`grid gap-2`,children:[(0,q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-2`,children:[(0,q.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-2 text-body`,"data-status":a.status,children:[(0,q.jsx)(zx,{tone:a.tone}),a.run?(0,q.jsx)(Ue,{to:hx({workflow:e,run:a.run}),className:`font-medium text-primary-text hover:underline`,children:a.words}):(0,q.jsx)(`span`,{children:a.words})]}),a.resolvable&&i.permitted&&(0,q.jsx)(P,{size:`sm`,loading:i.busy,onClick:()=>void i.resolve(),children:Bx(`resolve`)})]}),r.resolved_at!=null&&(0,q.jsx)(Hx,{by:r.resolved_by==null?null:String(r.resolved_by),at:String(r.resolved_at)})]})},uS=({value:e})=>{let t=bx();return e===null||!t?null:(0,q.jsx)(lS,{workflow:t.workflow,value:e})},dS=({value:e})=>{let t=Gx(e);return t?(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,q.jsx)(zx,{tone:t.tone}),t.words]}):null},fS={of:[...ts.workflow_status],display:uS,cell:dS},pS=e=>typeof e==`object`&&!!e&&!Array.isArray(e),mS=e=>{let t=pS(e)?e:{};return{dockerfile:typeof t.dockerfile==`string`?t.dockerfile:``,files:pS(t.files)?Object.entries(t.files).map(([e,t])=>[e,typeof t==`string`?t:JSON.stringify(t)]):[],command:Array.isArray(t.command)?t.command.map(String):[]}},hS=e=>{if(e.trimStart().startsWith(`[`))try{let t=JSON.parse(e);return Array.isArray(t)&&t.every(e=>typeof e==`string`)?t:void 0}catch{return}},gS=e=>hS(e)??e.split(`
6
+ `).filter(e=>e!==``),_S=e=>e.some(e=>e.includes(`
7
+ `))?JSON.stringify(e):e.join(`
8
+ `),vS=({dockerfile:e,files:t,command:n})=>({dockerfile:e,files:Object.fromEntries(t),...n.length>0&&{command:n}}),yS=B(`app/field-types/custom-step-container`),bS=({title:e,children:t})=>(0,q.jsxs)(`div`,{className:`grid gap-1`,children:[(0,q.jsx)(`h5`,{className:`text-xs font-medium text-muted-foreground`,children:e}),t]}),xS=({value:e})=>{if(e===null)return(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:`—`});let t=mS(e);return(0,q.jsxs)(`div`,{className:`grid gap-3`,children:[(0,q.jsx)(bS,{title:yS(`dockerfile`),children:(0,q.jsx)(hb,{children:t.dockerfile})}),t.files.map(([e,t])=>(0,q.jsx)(bS,{title:(0,q.jsx)(`span`,{className:`font-mono`,children:e}),children:(0,q.jsx)(hb,{children:t})},e)),(0,q.jsx)(bS,{title:yS(`command`),children:t.command.length>0?(0,q.jsx)(hb,{children:JSON.stringify(t.command)}):(0,q.jsx)(`p`,{className:`text-body text-muted-foreground`,children:yS(`ownCommand`)})})]})},SS=({value:e})=>{if(e===null)return null;let t=mS(e);return(0,q.jsx)(bb,{text:yS(`summary`,{files:t.files.length,line:t.dockerfile.split(`
9
+ `)[0]??``})})},CS=({value:e,onChange:t,invalid:n})=>{let r=mS(e),i=JSON.stringify(e??null),[a,o]=(0,W.useState)(()=>({seen:i,files:r.files,command:_S(r.command)}));a.seen!==i&&o({seen:i,files:r.files,command:_S(r.command)});let{files:s,command:c}=a,l=(0,W.useId)(),u=e=>{let n={files:e.files??s,command:e.command??c},i=vS({dockerfile:e.dockerfile??r.dockerfile,files:n.files,command:e.command===void 0?r.command:gS(e.command)});o({seen:JSON.stringify(i),...n}),t(i)},d=e=>u({files:e}),f=(e,t)=>e||yS(`fileNumber`,{number:t+1});return(0,q.jsxs)(`div`,{className:`grid gap-3`,children:[(0,q.jsx)(jy,{value:r.dockerfile,rows:6,invalid:n,className:`font-mono text-xs`,spellCheck:!1,onChange:e=>u({dockerfile:e.target.value})}),(0,q.jsxs)(wi.Provider,{value:void 0,children:[s.map(([e,t],n)=>(0,q.jsxs)(`div`,{className:`grid gap-1.5 rounded-md border p-2`,role:`group`,"aria-label":f(e,n),children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(bi,{value:e,"aria-label":yS(`path`),placeholder:yS(`pathExample`),className:`font-mono`,spellCheck:!1,wrapperClassName:`flex-1`,onChange:e=>d(s.map((r,i)=>i===n?[e.target.value,t]:r))}),(0,q.jsx)(P,{type:`button`,size:`icon`,variant:`ghost`,"aria-label":yS(`removeFile`,{path:f(e,n)}),onClick:()=>d(s.filter((e,t)=>t!==n)),children:(0,q.jsx)(Ci,{className:`size-4`})})]}),(0,q.jsx)(jy,{value:t,rows:4,"aria-label":yS(`fileText`,{path:f(e,n)}),className:`font-mono text-xs`,spellCheck:!1,onChange:t=>d(s.map((r,i)=>i===n?[e,t.target.value]:r))})]},n)),(0,q.jsxs)(P,{type:`button`,size:`sm`,className:`justify-self-start`,onClick:()=>d([...s,[``,``]]),children:[(0,q.jsx)(Hu,{className:`size-4`}),yS(`addFile`)]}),(0,q.jsxs)(`div`,{className:`grid gap-1`,children:[(0,q.jsx)(`label`,{htmlFor:`${l}-command`,className:`text-xs font-medium text-muted-foreground`,children:yS(`commandLines`)}),(0,q.jsx)(jy,{id:`${l}-command`,value:c,rows:2,className:`font-mono text-xs`,spellCheck:!1,onChange:e=>u({command:e.target.value})})]})]})]})},wS={of:[...ts.custom_step_container],display:xS,editor:CS,cell:SS,wide:!0},TS=({value:e,copyLabel:t})=>{let[n,r]=(0,W.useState)();return(0,W.useEffect)(()=>{if(n!==`yes`)return;let e=setTimeout(()=>r(void 0),2e3);return()=>clearTimeout(e)},[n]),(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 rounded-md border bg-surface py-1.5 pl-3 pr-1.5`,children:[(0,q.jsx)(`code`,{className:`min-w-0 flex-1 break-all font-mono text-xs`,children:e}),(0,q.jsx)(`button`,{type:`button`,"aria-label":n===`yes`?X(`copied`):t,onClick:()=>{if(!navigator.clipboard)return r(`refused`);navigator.clipboard.writeText(e).then(()=>r(`yes`),e=>{if(!(e instanceof DOMException))throw e;r(`refused`)})},className:`inline-flex size-8 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-muted pointer-coarse:size-11`,children:n===`yes`?(0,q.jsx)(xi,{className:`size-4 text-success`}):(0,q.jsx)(Wc,{className:`size-4`})})]}),n===`refused`&&(0,q.jsx)(`p`,{role:`alert`,className:`mt-1.5 text-xs font-medium text-danger-text`,children:X(`copyRefused`)})]})},ES=B(`app/field-types/runner-install`),DS=e=>e instanceof An?e.slug===`runner-registered`?ES(`registered`):e.slug===`runner-revoked`?ES(`revoked`):e.status===404?ES(`notYours`):ES(`failed`):ES(`failed`),OS=({value:e})=>{let t=F(),[n,r]=(0,W.useState)(),[i,a]=(0,W.useState)(!1),[o,s]=(0,W.useState)();if(e===null)return null;let c=async()=>{a(!0),s(void 0),await t.runnerRegistration(e).then(r,e=>s(DS(e))),a(!1)};return(0,q.jsxs)(`div`,{className:`grid gap-2`,children:[n&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(TS,{value:n.command,copyLabel:ES(`copy`)}),(0,q.jsx)(`p`,{className:`text-body text-muted-foreground`,children:ES(`shownOnce`,{until:dr(Date.parse(n.expires_at))})})]}),o&&(0,q.jsx)(`p`,{role:`alert`,className:`text-body text-danger-text`,children:o}),(0,q.jsx)(P,{size:`sm`,variant:n?`secondary`:`primary`,className:`justify-self-start`,loading:i,onClick:()=>void c(),children:ES(n?`again`:`issue`)})]})},kS={json:Eb,members:Zb,workflow:Mx,workflow_run:Ix,workflow_status:fS,custom_step_container:wS,runner_install:{of:[...ts.runner_install],display:OS,cell:()=>null}},AS=(e,t)=>{if(e&&Object.hasOwn(e,t))return e[t];if(Object.hasOwn(kS,t))return kS[t]},jS=(e,t,n)=>{let r=n?.widget;if(!r||t.sensitive)return;let i=AS(e,r.name);return i?.of.includes(t.type)?{name:r.name,widget:i,props:r.props??{}}:void 0},MS=(e,t)=>jS(qy().fields,e,t),NS=(e,t,n)=>{let r=jS(e,t,n);return!!(n?.multiline||n?.markdown||(r?r.widget.wide:t.type===`json`))},PS=({children:e})=>(0,q.jsx)(`div`,{role:`alert`,className:`rounded-lg border border-dashed border-warning bg-warning-soft p-3 text-warning-text`,children:e}),FS=class extends W.Component{state={failed:!1};static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(e,t){Bh(e,t.componentStack)}componentDidUpdate(e){this.state.failed&&e.resetKey!==this.props.resetKey&&this.setState({failed:!1})}render(){return this.state.failed?this.props.fallback===void 0?(0,q.jsx)(PS,{children:z.rich(`couldNotDraw`,{name:this.props.name})}):this.props.fallback:this.props.children}},IS=B(`app/field-types`),LS=({shown:e,part:t,field:n,value:r,onChange:i,invalid:a=!1})=>{let{widget:o,props:s}=e,c={field:n,value:r??null,props:s};if(t!==`editor`){let e=t===`cell`?o.cell??o.display:o.display;return(0,q.jsx)(e,{...c})}let l=o.editor;return l&&i?(0,q.jsx)(l,{...c,onChange:i,invalid:a}):void 0},RS=({fallback:e,...t})=>{let n=LS(t);return n?(0,q.jsx)(FS,{name:IS(`fieldType`,{name:t.shown.name}),fallback:e,children:n}):e},zS=(0,W.lazy)(()=>Ht(()=>import(`./markdown-content-HfXJkQCt.js`).then(e=>({default:e.MarkdownContent})),__vite__mapDeps([40,1,3,8,41,42]))),BS=e=>(0,q.jsx)(W.Suspense,{fallback:(0,q.jsx)(`div`,{className:U(`whitespace-pre-line break-words`,e.className),children:e.source}),children:(0,q.jsx)(zS,{...e})}),VS=e=>e.stopPropagation(),HS=({format:e,value:t,label:n,className:r})=>{let i=lv(e,t);return i?(0,q.jsx)(`a`,{href:i,...e===`url`?{target:`_blank`,rel:`noreferrer`}:{},onClick:VS,className:U(`font-medium text-primary-text hover:underline`,r),children:n??t}):(0,q.jsx)(`span`,{className:r,children:t})},US=e=>{if(!(!vr(e)||`missing`in e||!e.url))return{uri:e.uri,name:e.name,type:e.type,url:e.url,...e.size!==void 0&&{size:e.size}}},WS=(e,t)=>e&&Object.hasOwn(e,t)?e[t]:void 0,GS=(e,t)=>{if(/^[a-z][a-z0-9+.-]*:/i.test(t)||t.startsWith(`/`)||t.startsWith(`#`))return;let n=t.split(/[?#]/,1)[0],r=n.slice(n.lastIndexOf(`/`)+1);return e.find(e=>e.name===r)},KS=B(`app/file-viewers`),qS=({name:e})=>(0,q.jsxs)(`div`,{className:`space-y-3 px-4 py-6 md:px-10`,"aria-busy":`true`,children:[(0,q.jsx)(`span`,{role:`status`,className:`sr-only`,children:KS(`loading`,{name:e})}),(0,q.jsx)(L,{className:`h-6 w-2/3`}),(0,q.jsx)(L,{className:`h-40`})]}),JS=(0,W.lazy)(()=>Ht(()=>import(`./html-viewer-CFhG0dfK.js`).then(e=>({default:e.HtmlViewer})),__vite__mapDeps([43,1,3,33,14,5,4,6,7,8,34,35,10,44]))),YS={"text/html":{component:e=>(0,q.jsx)(W.Suspense,{fallback:(0,q.jsx)(qS,{name:e.file.name}),children:(0,q.jsx)(JS,{...e})})}},XS=(e,t)=>WS(e.fileViewers,t)??WS(YS,t),ZS=({file:e,className:t})=>(0,q.jsxs)(`a`,{href:e.url,download:e.name,className:U(zn({size:`sm`}),`gap-1.5`,t),children:[(0,q.jsx)(Qc,{className:`size-4`,"aria-hidden":`true`}),KS(`download`)]}),QS=(e,t)=>Object.values(e.fields).filter(n=>n.type===`relation`&&n.filterable&&n.name!==e.tenant&&t[n.name]!=null),$S=e=>typeof e==`object`&&e&&`id`in e?e.id:e,eC=(e,t)=>{let n=QS(e,t);if(n.length!==0)return n.map(e=>`${e.name} = ${JSON.stringify($S(t[e.name]))}`).join(` AND `)},tC=(e,t,n)=>{let r=Object.values(e.fields).filter(e=>e.type===`file`),i=new Map;for(let a of t)for(let t of r){let r=US(a[t.name]);r&&r.uri!==n.uri&&!i.has(r.uri)&&i.set(r.uri,{...r,key:xr(e,a),field:t.name})}return[...i.values()]},nC=100,rC=(e,t)=>t.type===`file`?[t.name,...[t.file?.typeField,t.file?.sizeField].filter(t=>t!==void 0&&Object.hasOwn(e.fields,t))]:[],iC=(e,t,n)=>{let r=eC(e,t),i=[...e.primaryKey,...Object.values(e.fields).flatMap(t=>rC(e,t))],a=tx(e.name,{filter:r,pageSize:nC,fields:i,enabled:r!==void 0});return{siblings:tC(e,r===void 0?[t]:[t,...a.items],n),ready:r===void 0||!a.isPending}},aC=(0,W.createContext)(void 0),oC=()=>{let e=(0,W.useContext)(aC);if(e===void 0)throw Error(`useViewedResource must be used inside a file viewer`);return e},sC=(e,t,n,r)=>{if(t.fields[r]?.type!==`file`)return;let i=US(n[r]);if(!i)return;let a=XS(e,i.type);return a?{field:r,file:i,viewer:a}:{field:r,file:i}},cC=({model:e,record:t,viewed:n,back:r})=>{let{file:i,viewer:a}=n;return(0,q.jsxs)(`div`,{className:`flex flex-1 flex-col`,children:[(0,q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-2 border-b border-border px-4 py-3 md:px-10`,children:[(0,q.jsxs)(Ue,{to:r,className:U(zn({variant:`ghost`,size:`sm`}),`gap-1.5`),children:[(0,q.jsx)(Ms,{className:`size-4`,"aria-hidden":`true`}),KS(`backToRecord`)]}),(0,q.jsxs)(`h1`,{className:`min-w-0 flex-1 truncate font-medium`,title:i.name,children:[i.name,i.size!==void 0&&(0,q.jsx)(`span`,{className:`ml-2 text-xs font-normal text-muted-foreground`,children:Tr(i.size)})]}),(0,q.jsx)(ZS,{file:i})]}),(0,q.jsx)(`div`,{className:`flex-1`,children:a?(0,q.jsx)(lC,{model:e,record:t,file:i,viewer:a}):(0,q.jsx)(uC,{file:i})})]})},lC=({model:e,record:t,file:n,viewer:r})=>{let{siblings:i,ready:a}=iC(e,t,n);if(!a)return(0,q.jsx)(qS,{name:n.name});let o=r.component;return(0,q.jsx)(aC.Provider,{value:e.name,children:(0,q.jsx)(FS,{name:n.type,fallback:(0,q.jsx)(dC,{file:n}),children:(0,q.jsx)(o,{file:n,siblings:i})})})},uC=({file:e})=>(0,q.jsxs)(`div`,{className:`flex flex-col items-start gap-3 px-4 py-6 md:px-10`,role:`status`,children:[(0,q.jsx)(`p`,{children:KS(`noPreview`,{name:e.name})}),(0,q.jsx)(ZS,{file:e})]}),dC=({file:e})=>(0,q.jsxs)(`div`,{className:`flex flex-col items-start gap-3 px-4 py-6 md:px-10`,role:`alert`,children:[(0,q.jsx)(`p`,{children:KS(`couldNotShow`,{name:e.name})}),(0,q.jsx)(ZS,{file:e})]}),fC=({field:e,model:t,record:n,name:r,url:i,className:a})=>{let o=qy(),s=e&&t&&n&&t.primaryKey.every(e=>n[e]!=null)?sC(o,t,n,e):void 0;return s?.viewer&&t&&n?(0,q.jsx)(Ue,{to:{kind:`record`,resource:t.name,key:xr(t,n),file:s.field},className:a,children:r}):(0,q.jsx)(`a`,{href:i,target:`_blank`,rel:`noreferrer`,className:a,children:r})},pC=({target:e,id:t,known:n})=>{let r=mb(e,t,n===void 0);return(0,q.jsx)(Ue,{to:{kind:`record`,resource:e.name,key:t},className:`font-medium text-primary-text hover:underline`,children:n??r??t})},mC=({field:e,value:t,known:n})=>{let{resources:r}=c(),i=e.relation?r[e.relation.resource]:void 0;return i?(0,q.jsx)(pC,{target:i,id:String(t),known:n}):(0,q.jsx)(`span`,{children:String(t)})},hC=()=>(0,q.jsxs)(`span`,{className:`text-muted-foreground`,children:[(0,q.jsx)(`span`,{"aria-hidden":`true`,children:`—`}),(0,q.jsx)(`span`,{className:`sr-only`,children:R(`noValue`)})]}),gC=({field:e,value:t,hints:n,relationLabel:r,linkText:i,model:a,record:o})=>{if(t==null||t===``)return(0,q.jsx)(hC,{});if(e.type===`relation`)return(0,q.jsx)(mC,{field:e,value:t,known:r});let s=e.type===`file`?hr(t):void 0;if(s&&`url`in s&&s.url){let n=jr(t,{width:40,height:40});return(0,q.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-2`,children:[n&&(0,q.jsx)(Iy,{image:n,className:`size-10 shrink-0 rounded border border-border object-cover`}),(0,q.jsx)(fC,{field:e.name,model:a,record:o,name:s.name,url:s.url,className:`truncate font-medium text-primary-text hover:underline`})]})}if(ov(e,n))return(0,q.jsx)(BS,{source:String(t)});if(e.type===`json`)return(0,q.jsx)(vb,{value:t});let c=Lr(e,t,n),l=e.type===`text`?cv(n):void 0;return l?(0,q.jsx)(HS,{format:l,value:c,label:i}):e.type===`enum`||n.format===`badge`?(0,q.jsx)(ri,{value:t,hints:n,children:c}):e.type===`timestamp`||e.type===`date`?(0,q.jsx)(`time`,{dateTime:String(t),title:Dr(e,t,void 0,n),children:c}):(0,q.jsx)(`span`,{title:Dr(e,t,void 0,n),className:U(n.format===`code`&&`font-mono text-xs`,(e.type===`decimal`||e.type===`integer`)&&`tabular-nums`,n.multiline&&`whitespace-pre-line break-words`),children:c})},_C=({model:e,field:t,value:n,format:r,relationLabel:i,record:a,relationLabels:o})=>{let{views:s}=c(),l={...s[e.name]?.fields[t.name],...r&&{format:r}},u=a&&l.format===`url`?bv(e,s[e.name],t.name,a,o):void 0;return(0,q.jsx)(gC,{field:t,value:n,hints:l,relationLabel:i,linkText:u,model:e,record:a})},vC=e=>{let{views:t}=c(),n=MS(e.field,t[e.model.name]?.fields[e.field.name]),r=(0,q.jsx)(_C,{...e});return n?(0,q.jsx)(RS,{shown:n,part:`display`,field:e.field,value:e.value,fallback:r}):r},yC=({target:e,view:t,value:n,label:r,chosen:i=[n],several:a=!1,invalid:o,onChange:s})=>{let c=qb(),l=e.primaryKey[0],u=pe(e,t),[d,f]=(0,W.useState)(!1),p=Qy(),m=Lb(e,u,c.text,d||t?.titleFrom!==void 0&&!e.search?.length),h=[...new Set([l,u,...t?.titleFrom?.fields??[]])],g=n=>t?.titleFrom?p(e,t,n,String(n[l])):String(n[u]),_=tx(e.name,{filter:m.filter,fields:h,enabled:c.open}),v=m.filter!==void 0&&_.error instanceof An&&_.error.slug===`expensive-query`;(0,W.useEffect)(()=>{v&&f(!0)},[v]);let y=m.local?_.items.filter(e=>Rb(g(e),c.text)):_.items,{fetchNextPage:b}=_,x=(0,W.useCallback)(()=>b({cancelRefetch:!1}),[b]);return(0,q.jsx)(Yb,{search:c,options:y.map(e=>({key:String(e[l]),label:g(e)})),chosen:i,several:a,closedText:r??n,placeholder:R(`searchPlural`,{plural:(t?.names?.plural??H(e.name)).toLowerCase()}),invalid:o,paging:{more:!!_.hasNextPage,loaded:_.items.length,loadMore:x},loading:_.isPending||_.isFetchingNextPage,failed:!!_.error&&!v,onChoose:e=>s(e.key,e.label)})},bC=(e,t)=>e.replace(/\D/g,``).slice(0,t),xC=(e,t,n)=>{let r=bC(t??``,n);return r.length===n?r:bC(e,n)},SC=(e,t,n,r)=>{let i=t.replace(/\D/g,``);return i.length>=r?i.slice(0,r):bC(e.slice(0,n)+i+e.slice(n+i.length),r)},CC=({value:e,onChange:t,onComplete:n,length:r=6,invalid:i,disabled:a,className:o,ref:s,onFocus:c,onBlur:l,onSelect:u,onKeyDown:d,onClick:f,onPaste:p,...m})=>{let h=(0,W.useRef)(null),[g,_]=(0,W.useState)(!1),[v,y]=(0,W.useState)(e.length),b=e.slice(0,r),x=Math.min(v,r-1),S=e=>{h.current=e,typeof s==`function`?s(e):s&&(s.current=e)},C=e=>{e!==b&&(t(e),e.length===r&&n?.(e))},w=e=>{let t=h.current;if(!t)return;let n=Math.max(0,Math.min(e,b.length));t.setSelectionRange(n,n<b.length?n+1:n),y(n)},T=e=>{if(d?.(e),e.defaultPrevented||e.shiftKey||e.altKey||e.metaKey||e.ctrlKey)return;let t=e.currentTarget.selectionStart??b.length,n={ArrowLeft:t-1,ArrowRight:t+1,Home:0,End:b.length}[e.key];n!==void 0&&(e.preventDefault(),w(n))},E=e=>{f?.(e);let t=e.currentTarget.getBoundingClientRect();e.clientX<=t.left||e.clientX>=t.right||w(Math.floor((e.clientX-t.left)/t.width*r))};return(0,q.jsxs)(`div`,{className:U(`relative`,a&&`opacity-50`,o),children:[(0,q.jsx)(`div`,{"aria-hidden":!0,className:`flex justify-center gap-2`,children:Array.from({length:r},(e,t)=>{let n=g&&t===x;return(0,q.jsx)(`div`,{"data-slot":t,"data-digit":b[t],className:U(`flex h-12 min-w-0 max-w-12 flex-1 items-center justify-center rounded-md border bg-background font-mono text-xl font-semibold text-foreground shadow-sm transition-colors before:content-[attr(data-digit)]`,i?`border-danger`:n?`border-primary`:`border-border-strong`,n&&(i?`ring-2 ring-danger/20`:`ring-2 ring-primary/20`)),children:b[t]===void 0&&(n?(0,q.jsx)(`span`,{className:`h-6 w-px animate-pulse bg-foreground`}):(0,q.jsx)(`span`,{className:`size-1.5 rounded-full bg-border-strong`}))},t)})}),(0,q.jsx)(`input`,{ref:S,type:`text`,inputMode:`numeric`,autoComplete:`one-time-code`,pattern:`[0-9]{${r}}`,spellCheck:!1,autoCorrect:`off`,autoCapitalize:`off`,"aria-invalid":i||void 0,disabled:a,value:b,className:`absolute inset-0 size-full cursor-text bg-transparent text-transparent caret-transparent outline-none selection:bg-transparent disabled:cursor-not-allowed`,...m,onChange:e=>{let{data:t,dataTransfer:n}=e.nativeEvent;C(xC(e.target.value,t??n?.getData(`text/plain`),r))},onPaste:e=>{if(p?.(e),e.defaultPrevented)return;e.preventDefault();let t=e.currentTarget,n=SC(b,e.clipboardData.getData(`text`),t.selectionStart??b.length,r);C(n),y(n.length)},onSelect:e=>{u?.(e);let t=e.currentTarget,n=t.selectionStart??b.length;n===t.selectionEnd&&n<t.value.length&&t.setSelectionRange(n,n+1),y(n)},onKeyDown:T,onClick:E,onFocus:e=>{_(!0),c?.(e)},onBlur:e=>{_(!1),l?.(e)}})]})},wC=B(`app/confirm-sign-in`),TC=({minutes:e,purpose:t=`show`,withPassword:n=!1,onConfirmed:r})=>{let i=Ig(),[a,o]=(0,W.useState)(``),[s,c]=(0,W.useState)(``),[l,u]=(0,W.useState)(``),[d,f]=(0,W.useState)(!1),p=Tt({queryKey:[`account-sign-in-methods`],queryFn:()=>i.session.account.signInMethods(),enabled:!!i}),m=en({mutationFn:()=>i.signInWithPasskey(),onSuccess:r}),h=en({mutationFn:e=>i.verifyTwoFactor({method:`totp`,code:e}),onSuccess:r}),g=p.data?.account,_=g?g.twoFactor&&!g.authenticatorApp?`second-step`:p.data?.mail&&g.passkeys===0&&!g.twoFactor?`confirmation`:void 0:void 0,v=n&&g!==void 0&&g.password&&g.passkeys===0&&!g.twoFactor,y=en({mutationFn:e=>i.session.account.confirmWithPassword(e),onSuccess:r}),b=en({mutationFn:async e=>{_===`second-step`?await i.verifyTwoFactor({method:`otp`,code:e}):await i.session.account.confirmWithCode(e)},onSuccess:r}),x=en({mutationFn:()=>_===`second-step`?i.session.sendTwoFactorCode():i.session.account.sendConfirmationCode(),onSuccess:()=>{f(!0),u(``),b.reset()}}),S=m.error??h.error??y.error??x.error??b.error??p.error;return(0,q.jsxs)(`section`,{"aria-label":wC(`confirmTitle`),className:`mt-2 flex flex-col gap-2 rounded-md border border-border bg-surface p-3`,children:[(0,q.jsx)(`p`,{className:`font-medium`,children:wC(`confirmTitle`)}),(0,q.jsx)(`p`,{className:`text-muted-foreground`,children:wC(t===`change`?`confirmWhyChange`:`confirmWhy`,{minutes:e})}),g&&g.passkeys>0&&(0,q.jsx)(P,{variant:`primary`,size:`sm`,className:`self-start`,loading:m.isPending,onClick:()=>m.mutate(),children:wC(`usePasskey`)}),g?.authenticatorApp&&(0,q.jsxs)(`form`,{className:`flex flex-wrap items-end gap-2`,onSubmit:e=>{e.preventDefault(),h.mutate(a.trim())},children:[(0,q.jsxs)(`label`,{className:`flex flex-col gap-1.5`,children:[wC(`authenticatorCode`),(0,q.jsx)(CC,{name:`code`,required:!0,value:a,invalid:h.isError,onChange:o,onComplete:e=>h.mutate(e)})]}),(0,q.jsx)(P,{type:`submit`,size:`sm`,loading:h.isPending,children:wC(`confirm`)})]}),v&&(0,q.jsxs)(`form`,{className:`flex flex-wrap items-end gap-2`,onSubmit:e=>{e.preventDefault(),y.mutate(s)},children:[(0,q.jsxs)(`label`,{className:`flex flex-col gap-1.5`,children:[wC(`password`),(0,q.jsx)(bi,{type:`password`,name:`password`,autoComplete:`current-password`,required:!0,value:s,onChange:e=>c(e.target.value)})]}),(0,q.jsx)(P,{type:`submit`,size:`sm`,loading:y.isPending,children:wC(`confirm`)})]}),_&&!d&&(0,q.jsx)(P,{variant:`primary`,size:`sm`,className:`self-start`,loading:x.isPending,onClick:()=>x.mutate(),children:wC(`emailCode`)}),_&&d&&(0,q.jsxs)(`form`,{className:`flex flex-col gap-2`,onSubmit:e=>{e.preventDefault(),b.mutate(l.trim())},children:[(0,q.jsx)(`p`,{className:`text-muted-foreground`,children:wC(`codeSent`,{minutes:10})}),(0,q.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2`,children:[(0,q.jsxs)(`label`,{className:`flex flex-col gap-1.5`,children:[wC(`emailedCode`),(0,q.jsx)(CC,{name:`code`,required:!0,value:l,invalid:b.isError,onChange:u,onComplete:e=>b.mutate(e)})]}),(0,q.jsx)(P,{type:`submit`,size:`sm`,loading:b.isPending,children:wC(`confirm`)}),(0,q.jsx)(P,{size:`sm`,variant:`ghost`,loading:x.isPending,onClick:()=>x.mutate(),children:wC(`emailNewCode`)})]})]}),g&&g.passkeys===0&&!g.authenticatorApp&&_===void 0&&!v&&(0,q.jsx)(`p`,{children:wC(`nothingToConfirmWith`)}),S&&(0,q.jsx)(`p`,{role:`alert`,className:`font-medium text-danger-text`,children:S.message})]})},EC=`••••••••••`,DC=e=>Tn(e)&&e.slug===`strong-sign-in-required`?e.problem.minutes??15:void 0,OC=({field:e,hints:t,value:n,reveal:r,locked:i,invalid:a,placeholder:o,onChange:s})=>{let[c,l]=(0,W.useState)(!1),u=en({mutationFn:async()=>r(),onSuccess:()=>l(!0)}),d=$v(n)!==``,f=t?.label??H(e.name),p=(0,q.jsx)(P,{variant:`ghost`,size:`sm`,className:`-mr-1.5 px-1.5`,"aria-label":R(c?`hide`:`show`,{label:f}),"aria-pressed":c,loading:u.isPending,onClick:()=>{c||d||!r||u.isSuccess?l(!c):u.mutate()},children:!u.isPending&&(c?(0,q.jsx)(cl,{className:`size-3.5`}):(0,q.jsx)(ul,{className:`size-3.5`}))}),m=DC(u.error),h=m===void 0?u.error&&(0,q.jsx)(`div`,{className:`mt-2`,children:(0,q.jsx)(Oy,{title:R(`couldNotShow`,{label:f}),error:u.error})}):(0,q.jsx)(TC,{minutes:m,onConfirmed:()=>u.mutate()});if(i)return(0,q.jsxs)(`div`,{children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 py-1`,children:[(0,q.jsx)(`span`,{className:U(c?t?.format===`code`?`font-mono text-xs`:``:`tracking-widest text-muted-foreground`),children:c?Lr(e,u.data,t):EC}),r&&p]}),h]});let g=d?$v(n):c&&u.isSuccess?$v(u.data):``;return(0,q.jsxs)(`div`,{children:[(0,q.jsx)(bi,{type:c?`text`:`password`,autoComplete:`off`,invalid:a,"aria-label":f,className:U(t?.format===`code`&&`font-mono text-xs`),placeholder:d||!r?o??(e.writeOnly?R(`setNewValue`):void 0):EC,value:g,trailing:p,onChange:e=>s(e.target.value)}),h]})},kC=({value:e})=>{let t=jr(e,{width:40,height:40});return t?(0,q.jsx)(Iy,{image:t,className:`size-10 shrink-0 rounded border border-border object-cover`}):(0,q.jsx)(`span`,{className:`flex size-10 shrink-0 items-center justify-center rounded border border-border bg-muted text-muted-foreground`,children:(0,q.jsx)(vl,{className:`size-4`})})},AC=({value:e,field:t,resource:n,record:r})=>{let i=(0,W.useContext)(ui)?.resources[n],a=hr(e);if(!a)return(0,q.jsx)(`div`,{className:`py-1.5 text-muted-foreground`,children:`—`});if(`missing`in a)return(0,q.jsx)(`div`,{className:`py-1.5 text-danger-text`,children:R(`fileMissing`)});let o=`url`in a?a.url:void 0,s=`corrected`in a?a.corrected:void 0;return(0,q.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3 py-1`,children:[(0,q.jsx)(kC,{value:e}),(0,q.jsxs)(`div`,{className:`min-w-0`,children:[o&&!o.startsWith(`blob:`)?(0,q.jsx)(fC,{field:t,model:i,record:zr(e)?void 0:r,name:a.name,url:o,className:`block truncate font-medium text-primary-text hover:underline`}):(0,q.jsx)(`span`,{className:`block truncate font-medium`,children:a.name}),(0,q.jsxs)(`span`,{className:`block truncate text-xs text-muted-foreground`,children:[a.type,a.size!==void 0&&` · ${Tr(a.size)}`,s&&` · sent as ${s.from}`]})]})]})},jC=({field:e,hints:t,resource:n,record:r,value:i,locked:a,invalid:o,onChange:s})=>{let c=F(),l=(0,W.useRef)(null),[u,d]=(0,W.useState)(),[f,p]=(0,W.useState)(!1),m=t?.label??H(e.name),h=en({mutationFn:async t=>{d(0);let r=await c.upload(n,e.name,t,{onProgress:(e,t)=>d(t>0?e/t:0)});return{uploaded:r,...gr(r.file.type)&&{preview:URL.createObjectURL(t)}}},onSuccess:e=>s(e),onSettled:()=>d(void 0)});if(a||e.readOnly)return(0,q.jsx)(AC,{value:i,field:e.name,resource:n,record:r});let g=e=>{let t=e?.[0];t&&h.mutate(t)},_=e=>{e.preventDefault(),p(!1),g(e.dataTransfer.files)},v=(0,q.jsx)(`input`,{ref:l,type:`file`,hidden:!0,accept:fr(e),"aria-label":R(`chooseFileFor`,{label:m}),onChange:e=>g(e.target.files)}),y=h.error&&(0,q.jsx)(`div`,{className:`mt-2`,children:(0,q.jsx)(Oy,{title:R(`notUploaded`),error:h.error})});return h.isPending?(0,q.jsxs)(`div`,{className:`py-1.5`,role:`status`,"aria-label":R(`uploadingLabel`,{label:m}),children:[(0,q.jsx)(`div`,{className:`h-1.5 overflow-hidden rounded-full bg-muted`,children:(0,q.jsx)(`div`,{className:`h-full rounded-full bg-primary transition-[width]`,style:{width:`${Math.round((u??0)*100)}%`}})}),(0,q.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:R(`uploading`,{percent:Math.round((u??0)*100)})})]}):hr(i)?(0,q.jsxs)(`div`,{children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,q.jsx)(AC,{value:i,field:e.name,resource:n,record:r})}),(0,q.jsx)(P,{size:`sm`,onClick:()=>l.current?.click(),children:R(`replace`)}),e.nullable&&(0,q.jsx)(P,{size:`sm`,variant:`ghost`,onClick:()=>s(null),children:R(`remove`)})]}),v,y]}):(0,q.jsxs)(`div`,{children:[(0,q.jsxs)(`div`,{onDragOver:e=>{e.preventDefault(),p(!0)},onDragLeave:()=>p(!1),onDrop:_,className:U(`flex items-center gap-3 rounded-md border border-dashed px-3 py-2.5 text-muted-foreground`,f?`border-primary bg-primary/5`:o?`border-danger`:`border-border-strong`),children:[(0,q.jsx)(Jd,{className:`size-4 shrink-0`}),(0,q.jsx)(`span`,{className:`flex-1`,children:R(`dropFile`)}),(0,q.jsxs)(P,{size:`sm`,onClick:()=>l.current?.click(),children:[(0,q.jsx)(Ou,{className:`size-3.5`}),R(`chooseFile`)]})]}),v,y]})},MC=B(`markdown`),NC=()=>[{value:`write`,label:MC(`write`)},{value:`preview`,label:MC(`preview`)}],PC=({value:e,onChange:t,label:n,invalid:r,placeholder:i})=>{let[a,o]=(0,W.useState)(`write`);return(0,q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,q.jsx)(`span`,{className:`self-start`,children:(0,q.jsx)(Av,{value:a,options:NC(),onChange:o,label:n})}),a===`write`?(0,q.jsx)(jy,{rows:5,invalid:r,placeholder:i,value:e,onChange:e=>t(e.target.value)}):(0,q.jsx)(`div`,{className:`min-h-[7.5rem] rounded-md border border-border px-2.5 py-1.5`,children:e.trim()===``?(0,q.jsx)(`span`,{className:`text-faint-foreground`,children:MC(`nothingToPreview`)}):(0,q.jsx)(BS,{source:e})})]})},FC=new Set([`integer`,`bigint`,`decimal`]),IC=e=>e===`integer`||e===`bigint`?{inputMode:`numeric`,enterKeyHint:`done`}:e===`decimal`?{inputMode:`decimal`,enterKeyHint:`done`}:{},LC=e=>typeof e==`object`&&e&&`key`in e?e.key:e,RC=(e,t,n,r,i)=>t?.confirm!==void 0&&!uy(e,n,r)&&uy(e,LC(i),r),zC=B(`app/change-confirm`),BC=e=>e instanceof Element&&e.closest(`[data-dialog="change-confirm"]`)!==null,VC=({field:e,hints:t,value:n,stored:r,onChange:i})=>{let[a,o]=(0,W.useState)(),s=a=>{RC(e,t,n,r,a)?o({next:a}):i(a)},c=()=>o(void 0);return{onChange:s,dialog:a&&(0,q.jsx)(di,{name:`change-confirm`,title:zC(`title`,{label:t?.label??H(e.name)}),description:t?.confirm,onClose:c,actions:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(P,{onClick:c,children:zC(`cancel`)}),(0,q.jsx)(P,{variant:`primary`,onClick:()=>{o(void 0),i(a.next)},children:zC(`change`)})]})})}},HC=({field:e,hints:t,value:n,stored:r,relationLabel:i,relationTo:a,relationPicker:o,invalid:s,locked:c,placeholder:l,reveal:u,resource:d,record:f,linkText:p,onChange:m})=>{if(e.type===`file`)return(0,q.jsx)(jC,{field:e,hints:t,resource:d??``,record:f,value:n,locked:c||!d,invalid:s,onChange:m});if(e.sensitive)return(0,q.jsx)(OC,{field:e,hints:t,value:n,reveal:u,locked:c||e.readOnly,invalid:s,placeholder:l,onChange:m});if(e.type===`relation`&&o&&!e.readOnly&&!c){let e=(0,q.jsx)(yC,{target:o.target,view:o.view,value:String(n),label:i,invalid:s,onChange:(e,t)=>m({key:e,label:t})});return a?(0,q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,q.jsx)(`div`,{className:`min-w-0 flex-1`,children:e}),(0,q.jsx)(Ue,{to:a,"aria-label":R(`openLabel`,{label:i??String(n)}),title:R(`open`),className:U(zn({variant:`ghost`}),`w-8 px-0`),children:(0,q.jsx)(Bs,{className:`size-4`})})]}):e}if(e.type===`relation`){if(r==null||r===``)return(0,q.jsx)(`div`,{className:`py-1.5`,children:(0,q.jsx)(gC,{field:e,value:r,hints:t??{}})});let n=i??String(r);return(0,q.jsx)(`div`,{className:`py-1.5`,children:a?(0,q.jsx)(Ue,{to:a,className:`font-medium text-primary-text hover:underline`,children:n}):n})}if(!ny(e)||c)return(0,q.jsx)(`div`,{className:`min-w-0 break-words py-1.5 text-foreground`,children:(0,q.jsx)(gC,{field:e,value:r,hints:t??{},linkText:p})});if(e.type===`boolean`)return(0,q.jsx)(ky,{checked:!!n,onChange:m,label:t?.label??H(e.name)});let h=!!t?.multiline&&e.type===`text`;return ov(e,t)?(0,q.jsx)(PC,{label:t?.label??H(e.name),invalid:s,placeholder:l,value:String(n),onChange:m}):e.type===`enum`?(0,q.jsxs)(gi,{invalid:s,value:String(n),onChange:e=>m(e.target.value),children:[n===``&&(0,q.jsx)(`option`,{value:``,children:R(`choose`)}),(e.enumValues??[]).map(e=>(0,q.jsx)(`option`,{value:e,children:ar(e,t?.valueLabels)},e))]}):h?(0,q.jsx)(jy,{invalid:s,placeholder:l,value:String(n),onChange:e=>m(e.target.value)}):(0,q.jsx)(bi,{invalid:s,leading:t?.prefix?(0,q.jsx)(`span`,{children:t.prefix}):void 0,trailing:t?.suffix?(0,q.jsx)(`span`,{children:t.suffix.trim()}):void 0,placeholder:l,className:U(FC.has(e.type)&&`text-right tabular-nums`),...IC(e.type),...uv(e.type===`text`?cv(t):void 0),value:String(n),onChange:e=>m(e.target.value)})},UC=(e,t,n,r)=>e.sensitive||e.type===`file`?!1:n||e.readOnly?!0:e.type===`relation`?!r:!ny(e,t),WC=e=>{let{field:t,hints:n,value:r,stored:i,invalid:a,locked:o,onChange:s}=e,c=MS(t,n),l=(0,q.jsx)(HC,{...e});return c?o||!ny(t,n)?(0,q.jsx)(RS,{shown:c,part:`display`,field:t,value:i,fallback:l}):t.type===`file`||t.type===`relation`?l:(0,q.jsx)(RS,{shown:c,part:`editor`,field:t,value:cy(t,r),invalid:!!a,onChange:e=>s(ly(t,e)),fallback:l}):l},GC=e=>{let t=VC(e);return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(WC,{...e,onChange:t.onChange}),t.dialog]})},KC=B(`action-card`),qC={neutral:{border:`border-border-strong`,header:`bg-surface text-foreground`},info:{border:`border-primary-border`,header:`bg-primary-soft text-primary-text`},success:{border:`border-success/40`,header:`bg-success-soft text-success-text`},warning:{border:`border-warning/40`,header:`bg-warning-soft text-warning-text`},danger:{border:`border-danger/40`,header:`bg-danger-soft text-danger-text`}},JC=({title:e,tone:t=`neutral`,badge:n,note:r,actions:i=[],onAction:a,children:o,frameless:s=!1})=>{let[c,l]=(0,W.useState)(),u=i.flatMap(e=>e.hint?[e.hint]:[]),d=e=>e.confirm?l(e):a?.(e.id);return(0,q.jsxs)(`section`,{"aria-label":e,className:s?`whitespace-normal text-foreground`:U(`shrink-0 overflow-hidden rounded-lg border bg-background whitespace-normal text-foreground shadow-sm`,qC[t].border),children:[!s&&(0,q.jsxs)(`header`,{className:U(`flex items-center gap-2 px-3 py-2`,qC[t].header),children:[(0,q.jsx)(`h3`,{className:`min-w-0 flex-1 font-semibold`,children:e}),n&&(0,q.jsx)(`span`,{className:`shrink-0 text-xs font-medium`,children:n})]}),(o||r||i.length>0)&&(0,q.jsxs)(`div`,{className:U(`space-y-2.5`,!s&&`px-3 py-2.5`),children:[o,r&&(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r}),i.length>0&&(0,q.jsx)(`div`,{className:`flex flex-wrap gap-2 pt-0.5`,children:i.map(e=>(0,q.jsx)(P,{size:`sm`,variant:e.style??`secondary`,className:U(e.style===`primary`&&`flex-1`),disabled:e.disabled,onClick:()=>d(e),children:e.label},e.id))}),u.map(e=>(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e},e))]}),c&&(0,q.jsx)(di,{title:`${c.label}?`,description:c.confirm,onClose:()=>l(void 0),actions:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(P,{onClick:()=>l(void 0),children:KC(`cancel`)}),(0,q.jsx)(P,{variant:c.style===`danger`?`danger`:`primary`,onClick:()=>{l(void 0),a?.(c.id)},children:c.label})]})})]})},YC=B(`auth/errors`),XC={INVALID_EMAIL_OR_PASSWORD:`wrongEmailOrPassword`,INVALID_PASSWORD:`wrongPassword`,INVALID_OTP:`wrongOrExpiredCode`,OTP_EXPIRED:`codeExpired`,OTP_HAS_EXPIRED:`codeExpired`,TOO_MANY_ATTEMPTS:`tooManyCodes`,INVALID_CODE:`wrongCode`,INVALID_BACKUP_CODE:`wrongBackupCode`,TOO_MANY_ATTEMPTS_REQUEST_NEW_CODE:`tooManyCodesSignIn`,ACCOUNT_TEMPORARILY_LOCKED:`locked`,INVALID_TWO_FACTOR_COOKIE:`tooSlow`,AUTH_CANCELLED:`passkeyClosed`,ERROR_CEREMONY_ABORTED:`passkeyClosed`,REGISTRATION_CANCELLED:`passkeyClosed`,PASSKEY_NOT_FOUND:`passkeyNotFound`,AUTHENTICATION_FAILED:`passkeyFailed`,PREVIOUSLY_REGISTERED:`passkeyAdded`,ERROR_AUTHENTICATOR_PREVIOUSLY_REGISTERED:`passkeyAdded`,PASSWORD_COMPROMISED:`passwordLeaked`,EMAIL_DOMAIN_NOT_ALLOWED:`signUpDomainNotAllowed`,DEVICE_LINK_NOT_FOUND:`deviceLinkNotFound`},ZC=(e,t)=>{let n=t?e[t]:void 0;return n&&YC(n)},QC=e=>ZC(XC,e.code),$C=e=>QC(e)??(e.status===429?YC(`tooManyRequests`):e.message),ew=e=>QC(e)??(e.status===429?YC(`tooManyRequests`):e.status===401?YC(`wrongEmailOrPassword`):e.message),tw={STAFF_PERMISSION_MISSING:`staffPermissionMissing`,STAFF_SIGN_IN_NOT_STRONG:`staffNotStrong`,STAFF_SIGN_IN_STALE:`staffStale`,STAFF_SIGN_IN_EXPIRED:`staffExpired`,STAFF_SIGN_IN_FAILED:`staffProviderFailed`,STAFF_USER_UNAVAILABLE:`staffUserUnavailable`,STAFF_REASON_REQUIRED:`staffReasonRequired`,SIGN_IN_METHOD_FORBIDDEN:`staffForbidden`,INVALID_CALLBACK_URL:`untrustedCallback`},nw=e=>ZC(tw,typeof e==`string`?e:e.code)||(typeof e==`string`?YC(`staffFailed`):e.status===429?YC(`tooManyRequests`):e.message),rw={signup_disabled:e=>YC(`signupDisabled`,{name:e}),account_not_linked:e=>YC(`notLinked`,{name:e}),account_already_linked_to_different_user:e=>YC(`linkedToOther`,{name:e}),unable_to_link_account:e=>YC(`couldNotLink`,{name:e}),access_denied:e=>YC(`accessDenied`,{name:e}),EMAIL_DOMAIN_NOT_ALLOWED:e=>YC(`domainNotAllowed`,{name:e})},iw=(e,t)=>rw[e]?.(t)??YC(`providerFailed`,{name:t}),aw=B(`mailbox`),ow=({offers:e,problem:t,onConnect:n})=>{let r=Ig()?.signInProviders??[],[i,a]=(0,W.useState)(!1),[o,s]=(0,W.useState)(),c=t?.code===`link_expired`,l=e.map(e=>e.link.name),u=e=>r.find(t=>t.id===e)?.name??Tg(e),d=async t=>{a(!0),s(void 0);try{await n(e.find(e=>e.link.id===t))}catch(e){if(!(e instanceof Jm))throw e;s($C(e)),a(!1)}};return(0,q.jsx)(JC,{title:aw(c?`expiredTitle`:`missingTitle`),tone:`warning`,actions:e.map(({link:e,again:t})=>({id:e.id,label:aw(t?`connectAgain`:`connect`,{name:e.name}),style:`primary`,disabled:i})),onAction:e=>void d(e),children:(0,q.jsxs)(`div`,{className:`space-y-1 text-body`,children:[(0,q.jsx)(`p`,{children:aw(c?`expired`:`missing`,{names:l.join(`, `)})}),e.filter(e=>e.signInOnly).map(({link:e})=>(0,q.jsx)(`p`,{children:aw(`signInOnly`,{provider:u(e.provider),name:e.name})},e.id)),o&&(0,q.jsx)(`p`,{role:`alert`,className:`font-medium text-danger-text`,children:o})]})})},sw=new Map([[`personal-mail-not-linked`,`not_linked`],[`personal-mail-link-expired`,`link_expired`]]),cw=e=>{if(!Tn(e))return;let t=sw.get(e.slug);if(!t)return;let{provider:n}=e.problem;return{code:t,...typeof n==`string`&&{provider:n}}},lw=(e,t,n)=>{if(n?.code===`link_expired`){let t=e.filter(e=>e.id===n.provider);return(t.length>0?t:e).map(e=>({link:e,again:!0,signInOnly:!1}))}return!n&&t.mail.length>0?[]:e.map(e=>{let n=t.mail.includes(e.id);return{link:e,again:n,signInOnly:!n&&t.providers.includes(e.provider)}})},uw=(e,t)=>{let n=Ig(),r=n?.personalMail??[],i=n!==null&&r.length>0&&(t||e!==void 0),[a,o]=(0,W.useState)(),[s,c]=(0,W.useState)(),l=n?.session.account;(0,W.useEffect)(()=>{if(!i||!l)return;let e=!0;return Promise.all([l.linkedPersonalMail(r),l.linkedProviders()]).then(([t,n])=>{e&&o({mail:t,providers:n})},t=>{if(!(t instanceof Jm))throw t;e&&c($C(t))}),()=>{e=!1}},[i,l,r]);let u=e=>n.linkPersonalMail(e.link);return i?s?{offers:[],error:s,connect:u}:{offers:a&&lw(r,a,e),connect:u}:{offers:[],connect:u}},dw=(e,t)=>{let n=cw(t),r=e.mailbox===!0,{offers:i,error:a,connect:o}=uw(n,r),s=i!==void 0&&i.length>0;return{notice:s?(0,q.jsx)(ow,{offers:i,problem:n,onConnect:o}):a?(0,q.jsx)(`p`,{role:`alert`,className:`text-body font-medium text-danger-text`,children:a}):void 0,explained:n!==void 0&&s,blocked:s||r&&i===void 0}},fw=(e,t)=>{let n=e.from===void 0?void 0:t?.[e.from];return Array.isArray(n)?n.filter(e=>typeof e==`string`):[]},pw=(e,t)=>e.items?e.items:[...new Set(t.flatMap(t=>fw(e,t)))],mw=(e,t,n)=>Object.fromEntries(Object.entries(t).map(([t,r])=>{let i=e.find(e=>e.name===t);return i?.kind===`checklist`?[t,i.items??fw(i,n)]:[t,r]})),hw=({label:e,boxes:t,ticked:n,onChange:r})=>{let{id:i,"aria-describedby":a,"aria-invalid":o}=mi();if(t.length===0)return(0,q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:z(`nothingToTick`)});let s=(e,t)=>r(t?[...n,e]:n.filter(t=>t!==e));return(0,q.jsx)(`div`,{id:i,role:`group`,"aria-label":e,"aria-describedby":a,"aria-invalid":o,children:(0,q.jsx)(`ul`,{className:`flex flex-col gap-1`,children:t.map(e=>(0,q.jsx)(`li`,{children:(0,q.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-3 rounded py-1.5 text-sm active:opacity-70`,children:[(0,q.jsx)(Di,{checked:n.includes(e),onChange:t=>s(e,t),className:`mt-0.5`}),(0,q.jsx)(`span`,{children:e})]})},e))})})},gw={WebkitTextSecurity:`disc`},_w=({name:e,value:t,invalid:n,onChange:r})=>(0,q.jsx)(bi,{type:`text`,name:e,autoComplete:`off`,style:gw,autoCorrect:`off`,autoCapitalize:`off`,spellCheck:!1,"data-1p-ignore":!0,"data-lpignore":`true`,"data-bwignore":!0,"data-form-type":`other`,"data-gramm":`false`,"data-gramm_editor":`false`,"data-enable-grammarly":`false`,value:t,invalid:n,onChange:e=>r(e.target.value)}),vw=`••••••`,yw=(e,t)=>e.flatMap(e=>{let n=t[e.name];return e.kind===`secret`&&typeof n==`string`&&n!==``?[n]:[]}),bw=(e,t)=>{let n=Array(e.length).fill(!1);for(let r of t)for(let t=e.indexOf(r);t!==-1;t=e.indexOf(r,t+1))n.fill(!0,t,t+r.length);return n},xw=(e,t)=>{let n=bw(e,t.filter(e=>e!==``)),r=``;for(let t=0;t<e.length;t++)n[t]?(t===0||!n[t-1])&&(r+=vw):r+=e[t];return r},Sw=(e,t)=>{if(t.length===0)return e;if(Tn(e)){let n=t.map(e=>JSON.stringify(e).slice(1,-1));return new An(JSON.parse(xw(JSON.stringify(e.problem),n)))}if(!(e instanceof Error))return e;let n=Error(xw(e.message,t));return n.name=e.name,n},Cw=(e,t)=>Object.fromEntries(Object.entries(e).map(([e,n])=>[e,xw(n,t)])),ww={text:`text`,integer:`integer`,decimal:`decimal`,boolean:`boolean`,date:`date`,secret:`text`},Tw=e=>{let t={name:e.name,column:e.name,nullable:!0,readOnly:!1,filterable:!1,sortable:!1,aliases:[]};return e.kind===`custom`||e.kind===`checklist`?{...t,type:`json`}:e.kind===`choice`?e.resource===void 0?{...t,type:`enum`,enumValues:(e.options??[]).map(e=>e.value)}:{...t,type:`relation`,relation:{resource:e.resource,columns:[e.name]}}:{...t,type:ww[e.kind]}},Ew=e=>({label:e.label,...e.multiline&&{multiline:!0},...e.options&&{valueLabels:Object.fromEntries(e.options.map(e=>[e.value,e.label]))}}),Dw=e=>Object.fromEntries(e.map(e=>e.kind===`custom`?[e.name,e.default??null]:e.kind===`checklist`?[e.name,[]]:e.kind===`boolean`?[e.name,!!e.default]:[e.name,$v(e.default)])),Ow=(e,t)=>e.kind===`custom`?t??null:e.kind===`checklist`?Array.isArray(t)?t:[]:e.kind===`secret`?typeof t==`string`&&t!==``?t:null:gy(t)?t.key:e.resource===void 0?sy(Tw(e),t):String(t??``)===``?null:String(t),kw=(e,t)=>{let n=Object.fromEntries(e.map(e=>[e.name,Ow(e,t[e.name])])),r=eo(e,n);return{shown:r,values:Object.fromEntries(Object.entries(n).filter(([e])=>r.has(e)))}},Aw=/^-?\d+(\.\d+)?$/,jw=/^\d{4}-\d{2}-\d{2}$/,Mw=(e,t,n)=>{if(e.kind===`checklist`){let e=n.filter(e=>!(Array.isArray(t)&&t.includes(e))).length;return e===0?void 0:z(`tickEvery`,{count:e})}if(t===null||t===``)return e.required?z(`required`):void 0;if(e.kind===`integer`&&!Number.isInteger(t))return z(`wholeNumber`);if(e.kind===`decimal`&&!Aw.test(String(t)))return z(`number`);if(e.kind===`date`&&!jw.test(String(t)))return z(`dateFormat`);if(e.max!==void 0&&String(t).length>e.max)return z(`atMost`,{max:e.max})},Nw=(e,t,n={})=>Object.fromEntries(e.flatMap(e=>{if(!Object.hasOwn(t,e.name))return[];let r=Mw(e,t[e.name],n[e.name]??[]);return r?[[e.name,r]]:[]})),Pw=class extends Error{errors;constructor(e){super(Object.values(e).join(`; `)),this.errors=e,this.name=`ActionInputError`}},Fw=(e,t)=>{let n=new Set(t.map(e=>e.name)),r=e instanceof Pw?Object.entries(e.errors):Tn(e)?e.errors.flatMap(e=>e.field?[[e.field,e.message]]:[]):[];return Object.fromEntries(r.filter(([e])=>n.has(e)))},Iw=({input:e,held:t,invalid:n,onChange:r,boxes:i})=>{let{resources:a,views:o}=c(),{components:s}=qy();if(e.kind===`custom`){let i=s?.[e.component??``];if(!i)throw Error(`Input "${e.name}": the app has no component "${e.component}"`);return(0,q.jsx)(i,{input:e,value:t??null,onChange:r,invalid:n,props:e.props??{}})}if(e.kind===`checklist`)return(0,q.jsx)(hw,{label:e.label,boxes:i,ticked:Array.isArray(t)?t:[],onChange:r});if(e.kind===`secret`)return(0,q.jsx)(_w,{name:e.name,value:typeof t==`string`?t:``,invalid:n,onChange:r});let l=e.resource===void 0?void 0:a[e.resource];return(0,q.jsx)(GC,{field:Tw(e),hints:Ew(e),value:gy(t)?t.key:t,stored:void 0,relationLabel:gy(t)?t.label:void 0,relationPicker:l?{target:l,view:o[l.name]}:void 0,invalid:n,onChange:r})},Lw=({action:e,label:t,danger:n,records:r=[],names:i=[],onCancel:a,onSubmit:o})=>{let[s,c]=(0,W.useState)(()=>Dw(e.inputs)),[l,u]=(0,W.useState)({}),[d,f]=(0,W.useState)(),[p,m]=(0,W.useState)(!1),h=(0,W.useId)(),{shown:g,values:_}=kw(e.inputs,s),v=dw(e,d),y=Object.fromEntries(e.inputs.filter(e=>e.kind===`checklist`).map(e=>[e.name,pw(e,r)])),b=async()=>{let t=Nw(e.inputs,_,y);if(u(t),f(void 0),Object.keys(t).length>0||v.blocked)return;m(!0);let n=yw(e.inputs,_);await o(_).catch(t=>{u(Cw(Fw(t,e.inputs),n)),f(Sw(t,n))}),m(!1)},x=(e,t)=>{u(({[e]:t,...n})=>n),c(n=>({...n,[e]:t}))};return(0,q.jsx)(g_,{title:t,description:e.confirm,open:!0,onClose:a,actions:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(P,{onClick:a,children:z(`cancel`)}),(0,q.jsx)(P,{variant:n?`danger`:`primary`,type:`submit`,form:h,loading:p,disabled:v.blocked,children:t})]}),children:(0,q.jsxs)(`form`,{id:h,className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),b()},children:[d!==void 0&&Object.keys(l).length===0&&!v.explained&&(0,q.jsx)(Oy,{title:z(`failed`,{label:t}),error:d}),v.notice,i.length>1&&(0,q.jsx)(`p`,{className:`text-sm`,children:z(`forRecords`,{records:i.join(`, `)})}),e.inputs.filter(e=>g.has(e.name)).map(e=>(0,q.jsx)(Mv,{label:e.label,required:e.required,help:e.help,error:l[e.name],children:(0,q.jsx)(Iw,{input:e,held:s[e.name],invalid:!!l[e.name],onChange:t=>x(e.name,t),boxes:y[e.name]??[]})},e.name))]})})},Rw=({action:e,label:t,danger:n,onCancel:r,onConfirm:i})=>{let a=dw(e,void 0);return(0,q.jsx)(di,{title:`${t}?`,description:e.confirm,onClose:r,actions:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(P,{onClick:r,children:z(`cancel`)}),(0,q.jsx)(P,{variant:n?`danger`:`primary`,disabled:a.blocked,onClick:i,children:t})]}),children:a.notice})},zw=e=>e.variant===`danger`||e.run?.kind===`delete`,Bw=e=>!!(e.confirm||e.inputs?.length),Vw=({action:e,label:t,danger:n,records:r,names:i,onCancel:a,onConfirm:o,onSubmit:s})=>{let{inputs:c}=e;return c?.length?(0,q.jsx)(Lw,{action:{...e,inputs:c},label:t,danger:n,records:r,names:i,onCancel:a,onSubmit:s}):(0,q.jsx)(Rw,{action:e,label:t,danger:n,onCancel:a,onConfirm:o})},Hw=({title:e,description:t,actions:n,className:r,bodyClassName:i,children:a})=>(0,q.jsxs)(`section`,{className:U(`flex min-w-0 flex-col rounded-lg border border-border bg-background`,r),"aria-label":e,children:[(e||t||n)&&(0,q.jsxs)(`header`,{className:`flex flex-wrap items-start justify-between gap-x-4 gap-y-2 px-4 pt-4`,children:[(0,q.jsxs)(`div`,{className:`min-w-0`,children:[e&&(0,q.jsx)(`h2`,{className:`text-base font-semibold tracking-tight`,children:e}),t&&(0,q.jsx)(`p`,{className:`mt-0.5 text-muted-foreground`,children:t})]}),n&&(0,q.jsx)(`div`,{className:`flex flex-wrap items-center gap-2`,children:n})]}),(0,q.jsx)(`div`,{className:U(`min-w-0 flex-1 p-4`,i),children:a})]}),Uw=({children:e})=>(0,q.jsx)(`p`,{className:`text-muted-foreground`,children:e}),Ww=(0,W.createContext)(void 0),Gw=({value:e,children:t})=>(0,q.jsx)(Ww.Provider,{value:e,children:t}),Kw=()=>(0,W.useContext)(Ww),qw=({read:e,list:t,empty:n,children:r})=>e.isPending?(0,q.jsx)(L,{className:`h-4 w-full`}):e.error?(0,q.jsx)(Oy,{title:z(`couldNotLoad`),error:e.error}):t.items.length===0&&n!==void 0?(0,q.jsx)(Uw,{children:n}):(0,q.jsxs)(Gw,{value:t,children:[r,t.loadMore&&(0,q.jsx)(P,{size:`sm`,onClick:t.loadMore,loading:t.loadingMore,className:`self-start`,children:z(`loadMore`)})]}),Jw=e=>`item`in e,Yw=(0,W.createContext)(void 0),Xw=(0,W.createContext)([]),Zw=({value:e,row:t,children:n})=>{let r=(0,W.useContext)(Xw),i=t?.index,a=t?.count,o=(0,W.useMemo)(()=>[...r,i===void 0||a===void 0?e:{...e,row:{index:i,count:a}}],[r,e,i,a]);return(0,q.jsx)($w,{stack:o,children:n})},Qw=({value:e,children:t})=>{let n=(0,W.useMemo)(()=>[{...e,root:!0}],[e]);return(0,q.jsx)($w,{stack:n,children:t})},$w=({stack:e,children:t})=>{let n=e.at(-1);return(0,q.jsx)(Xw.Provider,{value:e,children:(0,q.jsx)(Yw.Provider,{value:Jw(n)?void 0:n,children:(0,q.jsx)(Gw,{value:void 0,children:t})})})},eT=()=>(0,W.useContext)(Yw),tT=()=>(0,W.useContext)(Xw),nT=e=>{let t=e[0];return t?.root&&!Jw(t)?t.record:void 0},rT=e=>{let t=nT(e);return{stack:(t?e.slice(1):e).map(e=>({record:Jw(e)?e.item:e.record,...e.row&&{row:e.row}})),...t&&{root:t}}},iT=e=>typeof e==`object`&&!!e,aT=(e,t)=>t.reduce((e,t)=>iT(e)&&Object.hasOwn(e,t)?e[t]:void 0,e),oT=(e,t)=>{let n=pr(t);if(!n)return;let r=e=>{if(e)return Jw(e)?{item:aT(e.item,n.names)}:n.names.length===0?void 0:{frame:e,path:n.names.join(`.`)}};if(n.kind===`data`)return n.variable===`root`&&e[0]?.root?r(e[0]):void 0;if(n.explicit)return r(e[e.length-1-n.up]);let i=n.names[0];return r(e.findLast(e=>Jw(e)?iT(e.item)&&Object.hasOwn(e.item,i):Object.hasOwn(e.model.fields,i))??e.at(-1))},sT=()=>{let e=Ig(),t=nS();return n=>{let r=cw(n),i=e?.personalMail??[];if(!e||!r)return;let a=i.find(e=>e.id===r.provider)??(i.length===1?i[0]:void 0);if(!a)return;let o=async()=>{try{await e.linkPersonalMail(a)}catch(e){if(!(e instanceof Jm))throw e;t.show({state:`error`,title:aw(`connect`,{name:a.name}),description:$C(e)})}};return{label:aw(r.code===`link_expired`?`connectAgain`:`connect`,{name:a.name}),onClick:()=>void o()}}},cT=(e,t)=>{if(e.when===void 0)return!0;if(!t)return!1;let n=Zp(e.when);return n.ok&&em(n,t)},lT=(e,t={})=>cr(e,e=>encodeURIComponent(Sr(Ar(t,e)))),uT=e=>{if(typeof e!=`string`||!URL.canParse(e))return;let t=new URL(e);return t.protocol===`https:`||t.protocol===`http:`?t.href:void 0},dT=(e,t={})=>{let n=Vn(e);return n===void 0?lT(e,t):uT(Ar(t,n))},fT=e=>{e!==void 0&&(/^https?:/i.test(e)?window.open(e,`_blank`,`noopener,noreferrer`):window.location.assign(e))},pT=e=>URL.canParse(e)?new URL(e).hostname.replace(/^www\./,``):``,mT=(e,t)=>Object.entries(t).every(([t,n])=>Object.is(e[t],n)),hT=(e,t,n={})=>{if(!cT(e,t))return e.otherwise===`disable`?e:void 0;let r=e.run;if(r?.kind===`update`)return t&&!e.inputs?.length&&mT(t,r.values)?void 0:e;if(r?.kind===`link`&&`to`in r&&Or(r.to)!==void 0){let i=Mr(r.to,t);return i.kind!==`page`&&Object.hasOwn(n,i.resource)?e:void 0}if(r?.kind!==`link`||!(`href`in r))return e;let i=dT(r.href,t);if(i!==void 0)return e.label.includes(`{{host}}`)?{...e,label:e.label.replaceAll(tr,pT(i))}:e},gT=async(e,t,n,r)=>{let i=e.map(e=>({record:e,verdict:t(e)})),a={done:0,skipped:i.filter(e=>e.verdict===`skip`).length,failed:0,refused:i.flatMap(e=>e.verdict===`refuse`?[e.record]:[])};for(let{record:e}of i.filter(e=>e.verdict===`run`)){let t=await n(e).then(()=>void 0,e=>({error:e}));t?r(t.error)?a.refused.push(e):(a.failed+=1,a.failed===1&&(a.error=t.error)):a.done+=1}return a},_T=e=>`“${e}”`,vT=e=>e instanceof Error?e.message:z(`somethingWrong`),yT=(e,t,n)=>{let{views:r,resources:i}=c(),{actions:a,components:o}=qy(),s=re(e),l=F(),u=jn(e),d=nS(),f=sT(),p=qr(),{go:m}=Me(),h=Qy(),[g,_]=(0,W.useState)(),v=(r[e]?.actions??[]).flatMap(e=>hT(e,t?.record,i)??[]),y=(e,t)=>{let n=e.run?.kind;if((n===`update`||n===`delete`||n===`ai`)&&!t)return z(`needsRecord`);if(!cT(e,t?.record))return e.reason??z(`doesNotApply`);if((n===`update`||n===`ai`)&&(!iS(s,`update`)||t?.permissions?.update===!1)||e.run?.kind===`ai`&&t?.permissions?.fields?.[e.run.writes]===`read`)return z(`cannotChange`);if(n===`delete`&&(!iS(s,`delete`)||t?.permissions?.delete===!1))return z(`cannotDelete`);if(!e.run&&!a?.[e.name])return z(`noHandler`,{name:e.name});let r=e.inputs?.find(e=>e.kind===`custom`&&!o?.[e.component??``]);if(r)return z(`noInputComponent`,{component:String(r.component),input:r.name})},b=e=>y(e,t),x=(e,t)=>{let{run:n}=e,r=n?.kind;return r===`update`||r===`ai`?iS(s,`update`)&&(t.permissions?.update===!1||n?.kind===`ai`&&t.permissions?.fields?.[n.writes]===`read`):r===`delete`&&iS(s,`delete`)&&t.permissions?.delete===!1},S=async(t,n,r)=>{let{run:i}=t;if(i?.kind===`link`){`to`in i?m(Mr(i.to,n?.record)):fT(dT(i.href,n?.record));return}i?.kind===`update`?await l.update(e,n.key,no(i.values,r??{}),n.etag??`*`):i?.kind===`delete`?await l.remove(e,n.key,{etag:n.etag}):i?.kind===`ai`?await l.generate(e,n.key,t.name):await a[t.name]({resource:e,record:n?.record,recordKey:n?.key,etag:n?.etag,client:u,navigate:m,...r&&{values:r}})},C=async(t,r,i)=>{await S(t,r,i),t.run?.kind!==`link`&&(await p(e),d.show({state:`success`,title:z(`done`,{label:t.label})}),n?.(t))},w=async(e,n=t)=>{y(e,n)||(_(e.name),await C(e,n).catch(t=>{let n=f(t);d.show({state:`error`,title:z(`failed`,{label:e.label}),description:vT(t),...n&&{action:n}})}),_(void 0))},T=async(e,n)=>{b(e)||(_(e.name),await C(e,t,mw(e.inputs??[],n,t?.record)).finally(()=>_(void 0)))},E=(e,t)=>hT(e,t.record,i)!==void 0&&!y(e,t),D=(e,t)=>E(e,t)?`run`:hT(e,t.record,i)!==void 0&&cT(e,t.record)&&x(e,t)?`refuse`:`skip`;return{actions:v,blocked:b,blockedOn:y,appliesOn:E,verdictOn:D,running:g,run:w,submit:T,runEach:async(t,i,a=0,o)=>{_(t.name);let s=e=>o?mw(t.inputs??[],o,e.record):void 0,c=await gT(i,e=>D(t,e),e=>S(t,e,s(e)),e=>e instanceof An&&e.status===403);_(void 0),await p(e);let l=c.refused.map(t=>_T(h(t.model,r[e],t.record,t.key))),u=z(`doneOn`,{label:t.label,done:c.done,skipped:c.skipped+a,failed:c.failed,refused:l.length}),f=[l.length>0&&z(`refusedOn`,{records:l.join(`, `),count:l.length}),c.failed>0&&xw(vT(c.error),yw(t.inputs??[],o??{}))].filter(Boolean).join(` `);return d.show({state:c.failed>0||l.length>0?`error`:`success`,title:u,...f&&{description:f}}),c.done>0&&n?.(t),c}}},bT=(e,t,n,r)=>{let i=yT(e,n,r),a=i.actions.find(e=>e.name===t);return{action:a,record:n?.record,blocked:a?i.blocked(a):z(`noAction`,{name:t}),running:i.running===t,run:()=>a?i.run(a):Promise.resolve(),submit:e=>a?i.submit(a,e):Promise.resolve()}},xT=e=>e.props,ST=B(`app/list`),CT=({model:e,items:t,name:n,label:r,variant:i,className:a})=>{let{views:o}=c(),s=yT(e.name,void 0),l=Qy(),[u,d]=(0,W.useState)(!1),f=o[e.name]?.actions?.find(e=>e.name===n);if(!f||f.run?.kind===`link`)return null;let p=t.map(t=>ni(e,t)),m=p.filter(e=>s.verdictOn(f,e)!==`skip`);if(m.length===0)return null;let h=p.length-m.length,g=ST(`actionCount`,{label:r??f.label,count:m.length}),_=e=>s.runEach(f,m,h,e);return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(P,{size:`sm`,variant:i??f.variant??`secondary`,className:a,loading:s.running===n,onClick:()=>Bw(f)?d(!0):void _(),children:g}),u&&(0,q.jsx)(Vw,{action:f,label:g,danger:i===`danger`||i===void 0&&zw(f),records:m.map(e=>e.record),names:m.map(t=>_T(l(e,o[e.name],t.record,t.key))),onCancel:()=>d(!1),onConfirm:()=>{d(!1),_()},onSubmit:async e=>{d(!1),await _(e)}})]})},wT=({name:e,resource:t,label:n,variant:r,className:i,about:a,onRun:o})=>{let s=eT(),c=bT(t??s?.model.name??``,e,t===void 0||t===s?.model.name?s:void 0,e=>o?.(n??e.label)),[l,u]=(0,W.useState)(!1);if(!c.action)return null;let d=n??c.action.label,f=r??c.action.variant??`secondary`;return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(P,{size:`sm`,variant:f,className:i,loading:c.running,disabled:!!c.blocked,title:c.blocked,"aria-label":a===void 0?void 0:`${d}: ${a}`,onClick:()=>Bw(c.action)?u(!0):void c.run(),children:d}),l&&(0,q.jsx)(Vw,{action:c.action,label:d,danger:f===`danger`,records:c.record?[c.record]:[],onCancel:()=>u(!1),onConfirm:()=>{u(!1),c.run()},onSubmit:async e=>{await c.submit(e),u(!1)}})]})},TT=({node:e,className:t})=>{let n=xT(e),r=Kw(),i=r?.model;return i&&(n.resource===void 0||n.resource===i.name)?(0,q.jsx)(CT,{...n,model:i,items:r.items,className:t}):(0,q.jsx)(wT,{...n,className:t})},ET=({node:e,children:t,slots:n,className:r})=>{let{title:i,description:a}=xT(e);return(0,q.jsx)(Hw,{title:i,description:a,actions:n.actions,className:U(`h-full`,r),children:(0,q.jsx)(`div`,{className:`flex flex-col gap-3`,children:t})})},DT=(0,W.createContext)(null),OT={},kT=(e,t={})=>{let n=Object.fromEntries(Object.entries({...e.given,...t}).filter(e=>e[1]!==void 0&&e[1]!==``));return{kind:`page`,page:e.page,...e.tab&&{tab:e.tab},...Object.keys(n).length>0&&{params:n}}},AT=({page:e,tab:t,tree:n,given:r=OT,children:i})=>{let a=(0,W.useMemo)(()=>gp(n,r),[n,r]),o=(0,W.useMemo)(()=>({page:e,...t&&{tab:t},given:r,values:a}),[e,t,r,a]);return(0,q.jsx)(DT.Provider,{value:o,children:i})},jT=()=>(0,W.useContext)(DT)?.values??OT,MT=()=>(0,W.useContext)(DT)?.given??OT,NT=()=>{let e=PT();if(!e)throw Error(`A SelectInput and a select render inside a composed page, whose address holds their values`);return e},PT=()=>{let e=(0,W.useContext)(DT),{go:t,href:n}=Me();return e?{values:e.values,given:e.given,linkTo:r=>{let i=kT(e,r);return{href:n(i),onFollow:()=>t(i,{keepScroll:!0})}}}:void 0},FT=async(e,t,n={})=>{let r=t.filter||void 0,i=t.etag?{}:{etag:!1};if(t.kind===`aggregate`)return{rows:(await e.aggregate(t.resource,{groupBy:t.groupBy[0],filter:r,...t.pageSize!==void 0&&{limit:t.pageSize}})).groups.map(({value:e,count:t})=>({value:e,count:t}))};if(t.kind===`count`){let n=await e.list(t.resource,{filter:r,pageSize:1,count:`exact`,fields:t.fields,...i});return{rows:[],total:n.totalSize??n.totalSizeEstimate}}let a=await e.list(t.resource,{filter:r,orderBy:t.orderBy,pageSize:t.pageSize,fields:t.fields,limitPer:t.limitPer,...n,...i});return{rows:a.items,...a.labels&&{labels:a.labels},...a.photos&&{photos:a.photos}}},IT=({label:e,className:t})=>(0,q.jsx)(`span`,{role:e===void 0?void 0:`img`,"aria-label":e,title:e,className:U(`inline-flex size-4 items-center justify-center rounded-full bg-success-soft text-success-text`,t),children:(0,q.jsx)(xi,{className:`size-3`,strokeWidth:3})}),LT=e=>(0,q.jsx)(`span`,{className:`text-faint-foreground`,children:e}),RT=(e,t,n)=>{if(t==null)return LT(`—`);let r=L_(e,t)??``;switch(e.kind){case`text`:return e.link?(0,q.jsx)(HS,{format:e.link,value:r,label:n&&e.linkText?.(n),className:`block min-w-0 truncate`}):(0,q.jsx)(bb,{text:r});case`id`:return(0,q.jsx)(bb,{text:r,className:`font-mono text-xs text-muted-foreground`});case`money`:return(0,q.jsx)(`span`,{className:`tabular-nums`,children:r});case`date`:return(0,q.jsx)(`span`,{className:`tabular-nums text-muted-foreground`,children:r});case`datetime`:return(0,q.jsx)(`span`,{className:`tabular-nums text-muted-foreground`,title:e.relative?dr(Number(t)):F_(`shownIn`,{zone:Cr(Number(t),Hn())}),children:r});case`number`:return(0,q.jsx)(`span`,{className:`tabular-nums`,children:r});case`signed`:return(0,q.jsx)(`span`,{className:U(`tabular-nums`,Number(t)<0?`text-danger-text`:`text-success-text`),children:r});case`percent`:return Number(t)===0?LT(`—`):(0,q.jsx)(`span`,{className:`tabular-nums`,children:r});case`status`:return(0,q.jsx)(Ni,{tone:e.tones?.[String(t)]??`neutral`,color:Jr(e.colors,t),shape:e.shape,children:r});case`relation`:return(0,q.jsx)(bb,{text:r,className:`font-medium text-primary-text hover:underline`});case`boolean`:return t?(0,q.jsx)(IT,{}):LT(F_(`no`));case`file`:{let e=hr(t);if(!e)return LT(`—`);if(`missing`in e)return(0,q.jsx)(bb,{text:e.name,className:`text-danger-text`});let n=jr(t,{width:20,height:20});return(0,q.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-2`,children:[n?(0,q.jsx)(Iy,{image:n,className:`size-5 shrink-0 rounded-sm object-cover`}):(0,q.jsx)(Ou,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,q.jsx)(bb,{text:e.name})]})}case`user`:{let n=e.users?.(String(t));return n?(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-2 truncate`,children:[(0,q.jsx)(v_,{initials:n.initials,hue:n.hue,size:`xs`,className:`ring-0`}),(0,q.jsx)(bb,{text:n.name,className:`text-muted-foreground`})]}):(0,q.jsx)(bb,{text:r,className:`text-muted-foreground`})}}},zT=(e,t)=>e.type===`relation`&&typeof t==`object`&&t&&`id`in t?t.id:t,BT=(e,t,n,r)=>e.map(e=>{let i=t.fields[e.id],a=i&&jS(r,i,n?.fields[e.id]);return a?{...e,render:t=>(0,q.jsx)(RS,{shown:a,part:`cell`,field:i,value:zT(i,t[e.id]),fallback:RT(e,e.value?e.value(t):t[e.id],t)})}:e}),VT=e=>String(typeof e==`object`&&e&&`id`in e?e.id:e),HT=({target:e,id:t})=>(0,q.jsx)(bb,{text:mb(e,t)??t,className:`font-medium text-primary-text hover:underline`}),UT=(e,t,n,r)=>e.map(e=>{let i=t.fields[e.id],a=i?.type===`relation`&&i.relation?n[i.relation.resource]:void 0;return e.render||!a||!r[a.name]?.titleFrom?e:{...e,render:t=>t[e.id]==null?RT(e,null):(0,q.jsx)(HT,{target:a,id:VT(t[e.id])})}}),WT=(e,t,n)=>{if(!t)return[];let r=a(e,t.model.name,n);return r.ok?r.steps:[]},GT=(e,t,n,r,i)=>({queryKey:I.pathValue(n?.model.name??``,n?.key??``,r),enabled:i.length>1,queryFn:async()=>{let r=n.record;for(let n of i.slice(0,-1)){let i=r[n.field.name];if(i==null)return null;let a=n.field.relation.resource;r=(await t.fetchQuery({queryKey:I.record(a,String(i)),queryFn:()=>e.get(a,String(i))})).record}return r[i.at(-1).field.name]??null}}),KT=(e,t,n)=>{let r=t.at(-1);return!e||!r?{state:`missing`}:t.length===1?{state:`ready`,value:e.record[r.field.name],field:r.field,model:r.model}:n.isPending?{state:`loading`}:{state:`ready`,value:n.data??null,field:r.field,model:r.model}},qT=(e,t)=>{let{resources:n}=c(),r=WT(n,e,t);return KT(e,r,Tt(GT(F(),nn(),e,t,r)))},JT=e=>{let t=oT(tT(),e),n=qT(t&&`frame`in t?t.frame:void 0,t&&`path`in t?t.path:e);return t&&`item`in t?{state:`plain`,value:t.item}:n},YT=e=>{let{resources:t}=c(),n=F(),r=nn(),i=e.map(({scope:e,path:n})=>WT(t,e,n)),a=wt({queries:e.map(({scope:e,path:t},a)=>GT(n,r,e,t,i[a]))});return e.map(({scope:e},t)=>KT(e,i[t],a[t]))},XT=e=>e.includes(`.`),ZT=({model:e,row:t,column:n})=>{let r=qT(ni(e,Ie(e,t).record),n);return r.state===`loading`?(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:`…`}):r.state===`missing`?(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:`—`}):(0,q.jsx)(vC,{model:r.model,field:r.field,value:r.value})},QT=(e,t,{resources:n,views:r})=>{let i=a(n,e.name,t),o=i.ok?i.steps.at(-1):void 0,s=o?.field.name??t;return{id:t,header:r[o?.model.name??e.name]?.fields[s]?.label??H(s),kind:`text`,width:200,render:n=>(0,q.jsx)(ZT,{model:e,row:n,column:t})}},$T=(e,t,n,r)=>{let i=new Map(UT(BT(Tv(e,t,[],n.filter(e=>!XT(e))),e,t,r.fieldTypes),e,r.resources,r.views).map(e=>[e.id,e]));return n.flatMap(t=>XT(t)?[QT(e,t,r)]:i.get(t)??[])},eE=(e,t,{shown:n,opens:r,bulk:i})=>{if(i)return;let a=[...e.primaryKey,...n.map(e=>e.split(`.`)[0]),...r?[r]:[],Ke(e,t),...Jy(e,t)];return[...new Set(a)].filter(t=>Object.hasOwn(e.fields,t))},tE=({model:e,view:t,resources:n,views:r,fieldTypes:i,columns:a,button:o,opens:s,bulk:c,phoneColumns:l,xs:u})=>{let d=$T(e,t,a??He(e,t),{resources:n,views:r,fieldTypes:i}),f=u&&l?l(d):d,p=$e(e,t,[...f.map(e=>e.id),...o?Le(o):[]]);return{specs:f,fields:p,read:eE(e,t,{shown:p,opens:s,bulk:c})}},nE=e=>t=>{let n=new Map(t.map(e=>[e.id,{title:e.title,badge:e.kind===`status`}])),r=(e??t.map(e=>e.id)).filter(e=>n.has(fm(e))),i=new Set(gm(r,e=>n.get(e)));return t.filter(e=>i.has(e.id))},rE=(e,t)=>e.orderBy||t||void 0,iE=(e,t)=>e&&t?[...new Set([...e,...t])].sort():void 0,aE={Table:(e,t,n)=>{let{resource:r,columns:i,button:a,bulk:o=!1}=xT(e),s=r===void 0?void 0:n.resources[r];if(!s)return;let c=n.views[s.name],{fields:l,read:u}=tE({...n,model:s,view:c,columns:i?.map(fm),button:a,bulk:o,phoneColumns:nE(i)}),d=C(c);return{read:{...t,orderBy:rE(t,Pe(s,c)),fields:iE(t.fields,u)},extras:{labels:ab(n.resources,n.views,s,l),...d&&{photos:d}},then:e=>db(n.queryClient,n.client,n.resources,n.views,s,l,e.rows)}},RecordCards:(e,t,n)=>{let r=n.resources[xT(e).resource];if(r)return{read:{...t,orderBy:rE(t,Pe(r,n.views[r.name])),fields:void 0},extras:{}}},Thread:(e,t,n)=>{if(t.part===`calls`)return{read:t,extras:{}};let{resource:r,sender:i}=xT(e),a=n.resources[r];if(a)return{read:t,extras:{labels:ab(n.resources,n.views,a,i===void 0?[]:[i])}}}},oE=(e,t,n)=>{if(t.split&&!e.custom){if(t.part===`total`)return{read:t,extras:{}};if(t.part===void 0||t.part===`calls`)return aE[e.type]?.(e,t,n)}},sE=new Set([`RecordCard`,`CardRow`,`Stat`,`ReferenceManyField`,`ReferenceArrayField`,`ReferenceField`]),cE=(e,t)=>{let n=Mm(e,t.block);return n?.custom?n.reads!==void 0&&t.part!==`chosen`:t.part===void 0&&n!==void 0&&sE.has(n.type)},lE=(e,t,n)=>(n?.reads??[]).flatMap(r=>{let i=Mm(t,r.block),a=i&&oE(i,r,e);if(!a&&!cE(t,r))return[];let o=Gm(a?.read??r,{params:e.params,...e.root&&{root:e.root}}),s=a?.extras??{},c=async()=>{let t=await FT(e.client,o,s);return await a?.then?.(t),t};return[{read:o,queryKey:[...I.planRead(Km(r,n),o),s],queryFn:c}]}),uE=(e,t)=>!e||!t?t:e.isPending===t.isPending&&e.error===t.error&&e.total===t.total&&e.labels===t.labels&&e.photos===t.photos&&e.rows.length===t.rows.length&&e.rows.every((e,n)=>e===t.rows[n])?e:t,dE=(0,W.createContext)(new Map),fE=({tree:e,plan:t,children:n})=>{let r=F(),i=nn(),{resources:a,views:o}=c(),s=qy().fields,l=v(),u=jT(),d=nT(tT()),f=(0,W.useMemo)(()=>lE({client:r,queryClient:i,resources:a,views:o,fieldTypes:s,xs:l,params:u,...d&&{root:d}},e,t),[r,i,a,o,s,l,u,d,e,t]),p=wt({queries:f.map(({queryKey:e,queryFn:t})=>({queryKey:e,queryFn:t}))}),m=new Map(f.map(({read:e},t)=>[dm(e),{read:e,query:p[t]}]));return(0,q.jsx)(dE.Provider,{value:m,children:n})},pE=(e,t,n,r)=>{let i=r===void 0?void 0:e.get(r);if(!i)return;let{read:a,query:o}=i,s=t.at(-1);if(a.split&&!(s&&`model`in s&&s.planned))return;let c=o.data?qm(a,o.data.rows,{...rT(t),params:n}):[],{total:l,labels:u,photos:d}=o.data??{};return{isPending:o.isPending,error:o.error,rows:c,...l!==void 0&&{total:l},...u&&{labels:u},...d&&{photos:d}}},mE=e=>hE([e])[0],hE=e=>{let t=(0,W.useContext)(dE),n=tT(),r=jT(),i=(0,W.useRef)([]),a=e.map((e,a)=>uE(i.current[a],pE(t,n,r,e)));return i.current=a,a},gE=({children:e,wrap:t=(e,t)=>(0,q.jsx)(W.Fragment,{children:e},t)})=>{let n=Kw();if(!n)return null;let{model:r,items:i,planned:a}=n;return i.map((n,o)=>{let s=r?{...ni(r,n),...a&&{planned:a}}:{item:n},c=`key`in s?s.key:o;return t((0,q.jsx)(Zw,{value:s,row:{index:o,count:i.length},children:e}),c)})},_E=({children:e})=>(0,q.jsx)(gE,{children:e}),vE=({model:e,at:t,filter:n,sort:r,limit:i=12,title:a,description:o,empty:s,actions:c,children:l,className:u})=>{let d=mE(t),f=ii(e,{filter:n,sort:r,pageSize:i,enabled:!d}),p=d??f,m=d?d.rows:f.data?.items??[];return(0,q.jsx)(Hw,{title:a,description:o,actions:c,className:u,children:p.isPending?(0,q.jsx)(`div`,{className:`flex gap-3`,children:Array.from({length:3},(e,t)=>(0,q.jsx)(L,{className:`h-24 w-56`},t))}):p.error?(0,q.jsx)(Oy,{title:z(`couldNotLoad`),error:p.error}):m.length===0?(0,q.jsx)(Uw,{children:s??z(`nothingYet`)}):(0,q.jsx)(`ul`,{className:`relative -mx-4 flex snap-x gap-3 overflow-x-auto px-4 pb-1`,children:(0,q.jsx)(Gw,{value:{model:e,items:m,...d&&{planned:!0}},children:(0,q.jsx)(gE,{wrap:(e,t)=>(0,q.jsx)(`li`,{className:`flex w-60 shrink-0 snap-start flex-col gap-2 rounded-lg border border-border bg-surface p-3`,children:e},t),children:l})})})})},yE=({node:e,at:t,children:n,slots:r})=>{let{resource:i,...a}=xT(e),o=c().resources[i];return o?(0,q.jsx)(vE,{...a,model:o,...t!==void 0&&{at:t},actions:r.actions,children:n}):null},bE=(e,t,n,r=!0)=>{let i=F(),a=Bn(n)??``;return Tt({queryKey:I.facets(e,t,a),enabled:r,queryFn:()=>i.facets(e,t,{filter:a,limit:50})})},xE=(e,t,n=!0)=>{let r=F(),i=Bn(t.filter)??``;return Tt({queryKey:I.series(e,t.field,`${t.range??``}${t.from??``}${t.to??``}`,t.granularity??``,i),enabled:n,queryFn:()=>r.series(e,{...t,filter:i})})},SE=(e,t,n,r=20,i=!0)=>{let a=F(),o=Bn(n)??``;return Tt({queryKey:I.histogram(e,t,r,o),enabled:i,queryFn:()=>a.histogram(e,t,{filter:o,buckets:r})})},CE=(e,t,n)=>{let r={...n,filter:Bn(n.filter)??``};return{queryKey:I.aggregate(t,JSON.stringify(r)),queryFn:()=>e.aggregate(t,r)}},wE=(e,t,n=!0)=>Tt({...CE(F(),e,t),enabled:n}),TE=(e,t,n=!0)=>{let r=F();return wt({queries:t.map(t=>{let i={...t,filter:Bn(t.filter)??``};return{queryKey:I.aggregate(e,JSON.stringify(i)),enabled:n,queryFn:()=>r.aggregate(e,i)}})})},EE=B(`app/charts`),DE=m(),OE=e=>e>=0&&e<8?`var(--chart-${e+1})`:`var(--faint-foreground)`,kE=(e,t,n,r)=>{let i=String(n);if(n===null)return`var(--faint-foreground)`;let a=Jr(t?.valueColors,n);return a===void 0?e.type===`enum`?OE(e.enumValues?.indexOf(i)??-1):e.type===`boolean`?OE(+!n):OE(r):a},AE=(e,t,n)=>n.value===null?EE(`notSet`):e.type===`enum`?ar(String(n.value),t?.valueLabels):e.type===`boolean`?n.value?EE(`yes`):EE(`no`):n.label??String(n.value),jE=(e,t,n=``)=>{let r=vn(t===null?DE.isNull(e.name):DE.eq(e.name,t));return n.trim()?`(${n}) AND ${r}`:r},ME=(e,t)=>t.kind===`count`?e.count:e[t.kind]??null,NE=(e,t,n,r,i=``)=>e.map((e,a)=>({key:String(e.value),label:AE(t,n,e),value:ME(e,r),count:e.count,color:kE(t,n,e.value,a),filter:jE(t,e.value,i)})),PE=(e,t)=>e.map(e=>({at:Date.parse(`${String(e.value)}Z`),value:ME(e,t),count:e.count})),FE=(e,t)=>{if(e===null)return`—`;if(t.kind===`count`)return e.toLocaleString(ci());let n=t.hints?.decimals??(Number.isInteger(e)?0:2),r=e.toLocaleString(ci(),{minimumFractionDigits:n,maximumFractionDigits:n});return`${t.hints?.prefix??``}${r}${t.hints?.suffix??``}`},IE=(e,t,n)=>{let r=e?.type===`relation`&&e.relation?t[e.relation.resource]:void 0;return r&&r.primaryKey.length===1?pe(r,n[r.name]):void 0},LE=({model:e,groupBy:t,splitBy:n,sum:r,average:i,filter:a=``,granularity:o=`day`,range:s=`30d`,limit:c=10},l,u)=>{let d=e.fields[t];if(!d)return;let f=d.type===`date`||d.type===`timestamp`,p=IE(d,l,u),m=f&&n!==void 0?e.fields[n]:void 0,h=IE(m,l,u),g=m?{splitBy:m.name,splitLimit:8,...h&&{splitLabel:h}}:{},_=f?{granularity:o,range:s,timeZone:Hn(),...g}:{limit:c,...p&&{label:p}};return{groupBy:t,filter:a,...r&&{sum:r},...i&&{average:i},..._}},RE=(e,t,n)=>n?{kind:`list`,resource:t,filter:n}:e?.list?.filter?{kind:`list`,resource:t,filter:``}:{kind:`list`,resource:t},zE=({resource:e,view:t,slices:n,measure:r})=>{let i=Math.max(0,...n.map(e=>e.value??0));return(0,q.jsx)(`ul`,{className:`flex flex-col gap-1`,children:n.map(n=>{let a=i>0&&n.value!==null?Math.max(0,n.value)/i:0;return(0,q.jsx)(`li`,{children:(0,q.jsxs)(Ue,{to:RE(t,e,n.filter),className:`group grid grid-cols-[minmax(6rem,35%)_1fr_auto] items-center gap-3 rounded-md px-1 py-1 hover:bg-muted`,title:r.kind===`count`?void 0:EE(`records`,{count:FE(n.count,{kind:`count`})}),children:[(0,q.jsx)(`span`,{className:`truncate group-hover:text-primary-text`,children:n.label}),(0,q.jsx)(`span`,{className:`h-3 rounded-r bg-muted`,"aria-hidden":!0,children:(0,q.jsx)(`span`,{className:`block h-full rounded-r`,style:{width:`${a*100}%`,background:`var(--chart-1)`}})}),(0,q.jsx)(`span`,{className:`text-right font-medium tabular-nums`,children:FE(n.value,r)})]})},n.key)})})},BE=`flex items-center gap-2 rounded-md px-1 py-0.5`,VE=({resource:e,view:t,filter:n,color:r,label:i,children:a})=>{let o=(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`span`,{className:`size-2.5 shrink-0 rounded-full`,style:{background:r},"aria-hidden":!0}),(0,q.jsx)(`span`,{className:`min-w-0 flex-1 truncate group-hover:text-primary-text`,children:i}),a]});return(0,q.jsx)(`li`,{children:n===void 0?(0,q.jsx)(`div`,{className:BE,children:o}):(0,q.jsx)(Ue,{to:RE(t,e,n),className:`group ${BE} hover:bg-muted`,children:o})})},HE=(e,t)=>t>0?`${Math.round(e/t*100)}%`:``,UE=({active:e,payload:t,measure:n})=>{let r=t?.[0]?.payload;return!e||!r?null:(0,q.jsxs)(`div`,{className:`rounded-md border bg-background px-2.5 py-1.5 text-xs shadow-pop`,children:[(0,q.jsx)(`div`,{className:`text-muted-foreground`,children:r.label}),(0,q.jsx)(`div`,{className:`font-semibold tabular-nums`,children:FE(r.value,n)})]})},WE=({resource:e,view:t,slices:n,measure:r})=>{let i=n.filter(e=>e.value!==null&&e.value>0),a=i.reduce((e,t)=>e+t.value,0);return(0,q.jsxs)(`div`,{className:`flex flex-col items-center gap-4 sm:flex-row sm:items-center`,children:[(0,q.jsx)(`div`,{className:`size-36 shrink-0`,children:(0,q.jsx)(dt,{width:`100%`,height:`100%`,children:(0,q.jsxs)(ct,{children:[(0,q.jsx)(vt,{data:i,dataKey:`value`,nameKey:`label`,innerRadius:`62%`,outerRadius:`100%`,paddingAngle:+(i.length>1),stroke:`var(--background)`,strokeWidth:2,isAnimationActive:!1,children:i.map(e=>(0,q.jsx)(lt,{fill:e.color},e.key))}),(0,q.jsx)(ft,{content:(0,q.jsx)(UE,{measure:r}),isAnimationActive:!1})]})})}),(0,q.jsx)(`ul`,{className:`flex w-full min-w-0 flex-col gap-0.5`,children:n.map(n=>(0,q.jsxs)(VE,{resource:e,view:t,filter:n.filter,color:n.color,label:n.label,children:[(0,q.jsx)(`span`,{className:`font-medium tabular-nums`,children:FE(n.value,r)}),(0,q.jsx)(`span`,{className:`w-9 text-right text-xs text-muted-foreground tabular-nums`,children:HE(n.value??0,a)})]},n.key))})]})},GE=864e5,KE={day:`numeric`,month:`short`,hour:`2-digit`,minute:`2-digit`,hour12:!1},qE={day:`numeric`,month:`short`,year:`numeric`},JE={day:`numeric`,month:`short`},YE={minute:KE,"5_minutes":KE,"15_minutes":KE,hour:KE,day:qE,year:{year:`numeric`}},XE=e=>Pi(`period:${JSON.stringify(e)}`,t=>new Intl.DateTimeFormat(t,{...e,timeZone:`UTC`})),ZE=(e,t)=>{let n=new Date(e);if(t===`day`)return e+GE;if(t===`week`)return e+7*GE;if(t===`month`)return Date.UTC(n.getUTCFullYear(),n.getUTCMonth()+1,1);if(t===`year`)return Date.UTC(n.getUTCFullYear()+1,0,1)},QE=(e,t,n)=>{let r=ZE(e,t);return e<=n&&r!==void 0&&n<r},$E=(e,t,n)=>{if(QE(e,t,n))return t===`day`?EE(`today`):EE(`toToday`,{start:XE(new Date(e).getUTCFullYear()===new Date(n).getUTCFullYear()?JE:qE).format(e)});let r=YE[t];if(r)return XE(r).format(e);let i=ZE(e,t);if(i===void 0)throw Error(`A ${t} bucket has no period to name`);return XE(qE).formatRange(e,i-GE)},eD=({points:e,measure:t,bucket:n,now:r,series:i})=>{let a=i??[],o=!i||t.kind===`count`||t.kind===`sum`;return(0,q.jsx)(`div`,{className:`sr-only`,children:(0,q.jsxs)(`table`,{children:[(0,q.jsx)(`thead`,{children:(0,q.jsxs)(`tr`,{children:[(0,q.jsx)(`th`,{scope:`col`,children:EE(`period`)}),a.map(e=>(0,q.jsx)(`th`,{scope:`col`,children:e.label},e.key)),o&&(0,q.jsx)(`th`,{scope:`col`,children:EE(t.kind)})]})}),(0,q.jsx)(`tbody`,{children:e.map(e=>(0,q.jsxs)(`tr`,{children:[(0,q.jsx)(`th`,{scope:`row`,children:$E(e.at,n,r)}),a.map(n=>(0,q.jsx)(`td`,{children:FE(e[n.key]??null,n.measure??t)},n.key)),o&&(0,q.jsx)(`td`,{children:FE(e.value,t)})]},e.at))})]})})},tD={hour:`2-digit`,minute:`2-digit`,hour12:!1},nD={day:`numeric`,month:`short`,...tD},rD={minute:tD,"5_minutes":tD,"15_minutes":tD,hour:tD,day:{day:`numeric`,month:`short`},week:{day:`numeric`,month:`short`},month:{month:`short`,year:`2-digit`},year:{year:`numeric`}},iD=e=>{let t=new Intl.DateTimeFormat(ci(),{...e,timeZone:`UTC`});return e=>t.format(e)},aD={fontSize:`0.6875rem`,fill:`var(--muted-foreground)`},oD=864e5,sD=new Set([`minute`,`5_minutes`,`15_minutes`,`hour`]),cD=(e,t)=>{let n=t.length>1?t.at(-1).at-t[0].at:0;return sD.has(e)&&n>=oD?nD:rD[e]},lD=()=>{let e=Date.now();return e+Zn(e,Hn())},uD=({active:e,payload:t,measure:n,bucket:r,now:i,series:a})=>{let o=t?.[0]?.payload;return!e||!o?null:(0,q.jsxs)(`div`,{className:`rounded-md border bg-background px-2.5 py-1.5 text-xs shadow-pop`,children:[(0,q.jsx)(`div`,{className:`text-muted-foreground`,children:$E(o.at,r,i)}),a?.map(e=>(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(`span`,{className:`size-2 shrink-0 rounded-full`,style:{background:e.color},"aria-hidden":!0}),(0,q.jsx)(`span`,{className:`flex-1`,children:e.label}),(0,q.jsx)(`span`,{className:`font-semibold tabular-nums`,children:FE(o[e.key]??null,e.measure??n)})]},e.key)),a&&(n.kind===`count`||n.kind===`sum`)&&(0,q.jsx)(`div`,{className:`mt-0.5 border-t pt-0.5 font-semibold tabular-nums`,children:FE(o.value,n)}),!a&&(0,q.jsx)(`div`,{className:`font-semibold tabular-nums`,children:FE(o.value,n)})]})},dD=e=>({fillOpacity:.35,stroke:e,strokeWidth:1.5,strokeDasharray:`3 2`}),fD=`[&_.recharts-surface]:rounded-sm [&_.recharts-surface:focus-visible]:outline-2 [&_.recharts-surface:focus-visible]:outline-offset-2 [&_.recharts-surface:focus-visible]:outline-primary`,pD=({points:e,measure:t,bucket:n,type:r,series:i,resource:a,view:o,compact:s})=>{let c=x(`(min-width: 640px)`),[l,u]=(0,W.useState)(!1),d=lD(),f=e.findIndex(e=>QE(e.at,n,d)),p=iD(cD(n,e)),m=(0,q.jsx)(gt,{vertical:!1,stroke:`var(--border)`}),h=(0,q.jsx)(rt,{dataKey:`at`,tickFormatter:p,tick:aD,axisLine:!1,tickLine:!1,minTickGap:c?24:40,height:18}),g=(0,q.jsx)(Wt,{width:c?48:36,tick:aD,axisLine:!1,tickLine:!1,tickCount:3,tickFormatter:e=>e.toLocaleString(ci(),{notation:`compact`})}),_=(0,q.jsx)(ft,{...l&&{active:!1},cursor:r===`bar`?{fill:`var(--muted)`}:{stroke:`var(--border-strong)`},content:(0,q.jsx)(uD,{measure:t,bucket:n,now:d,...i&&{series:i}}),isAnimationActive:!1}),v=i??[{key:`value`,label:``,color:`var(--chart-1)`}],y=t=>({cx:n,cy:r,index:i})=>n===void 0||r===void 0?null:i===f?(0,q.jsx)(`circle`,{cx:n,cy:r,r:3.5,fill:`var(--background)`,stroke:t,strokeWidth:2}):e.length<=31?(0,q.jsx)(`circle`,{cx:n,cy:r,r:3,fill:t}):null,b=e=>u(e.key===`Escape`),S=()=>u(!1),C={"aria-label":EE(`chartKeys`)},w=(0,q.jsxs)(`div`,{className:`${s?`h-24`:`h-40`} ${fD}`,onKeyDown:b,onPointerMove:S,onFocus:S,children:[(0,q.jsx)(dt,{width:`100%`,height:`100%`,children:r===`line`?(0,q.jsxs)(_t,{data:e,margin:{top:6,right:6,bottom:0,left:0},...C,children:[m,h,g,_,v.map(e=>(0,q.jsx)(ht,{dataKey:e.key,stroke:e.color,strokeWidth:2,dot:y(e.color),activeDot:{r:4,stroke:`var(--background)`,strokeWidth:2},isAnimationActive:!1},e.key))]}):(0,q.jsxs)(st,{data:e,margin:{top:6,right:0,bottom:0,left:0},barCategoryGap:`22%`,...C,children:[m,h,g,_,v.map((t,n)=>(0,q.jsx)(Ut,{dataKey:t.key,fill:t.color,...i&&{stackId:`split`},radius:n===v.length-1?[4,4,0,0]:0,isAnimationActive:!1,children:e.map((e,n)=>(0,q.jsx)(lt,{...n===f&&dD(t.color)},e.at))},t.key))]})}),(0,q.jsx)(eD,{points:e,measure:t,bucket:n,now:d,...i&&{series:i}})]});return!i||a===void 0?w:(0,q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[w,(0,q.jsx)(`ul`,{className:`flex flex-wrap gap-x-3 gap-y-0.5 text-sm`,children:i.map(e=>(0,q.jsx)(VE,{resource:a,view:o,color:e.color,label:e.label,...e.filter!==void 0&&{filter:e.filter}},e.key))})]})},mD=1e-6,hD=(e,t,n,r,i,a=``)=>{let o=t.map((e,t)=>({key:`s${t}`,label:AE(n,r,e),color:kE(n,r,e.value,t),filter:jE(n,e.value,a)})),s=i.kind===`count`?0:null,c=(e,t)=>{let n=e.splits?.find(e=>e.value===t);return n?i.kind===`count`?n.count:n[i.kind]??null:s},l=PE(e,i).map((n,r)=>{let a=e[r],o=t.map(e=>c(a,e.value)),s=Object.fromEntries(o.map((e,t)=>[`s${t}`,e]));if(i.kind===`average`)return{...n,...s};let l=n.value===null?null:n.value-o.reduce((e,t)=>e+(t??0),0);return{...n,...s,other:l===null?null:l<mD?0:l}});return i.kind!==`average`&&l.some(e=>(e.other??0)>0)?{series:[...o,{key:`other`,label:EE(`other`),color:`var(--border-strong)`}],points:l}:{series:o,points:l.map(({other:e,...t})=>t)}},gD=(e,t,n,r)=>{let i=n??r,a=i===void 0?void 0:e.fields[i];return!a||i===void 0?{kind:`count`}:{kind:n===void 0?`average`:`sum`,field:a,hints:t?.fields[i]}},_D=({model:e,view:t,groupBy:n,splitBy:r,type:i=`bar`,sum:a,average:o,filter:s=``,granularity:l=`day`,range:u=`30d`,limit:d=10,empty:f=EE(`nothingYet`)})=>{let{resources:p,views:m}=c(),h=e.fields[n],g=h?.type===`date`||h?.type===`timestamp`,_=g&&r!==void 0?e.fields[r]:void 0,v=LE({model:e,groupBy:n,splitBy:r,sum:a,average:o,filter:s,granularity:l,range:u,limit:d},p,m),y=wE(e.name,v??{groupBy:n},v!==void 0),b=gD(e,t,a,o);if(!h)return null;if(y.isPending)return(0,q.jsx)(L,{className:`h-36 w-full`});if(y.error)return(0,q.jsx)(`p`,{className:`text-danger-text`,children:EE(`couldNotLoad`)});let{groups:x}=y.data;if(x.every(e=>e.count===0))return(0,q.jsx)(`p`,{className:`text-muted-foreground`,children:f});let S=i===`line`?`line`:`bar`;if(g&&_&&y.data.splits){let{series:n,points:r}=hD(x,y.data.splits,_,t?.fields[_.name],b,s);return(0,q.jsx)(pD,{points:r,measure:b,bucket:l,type:S,series:n,resource:e.name,view:t})}if(g)return(0,q.jsx)(pD,{points:PE(x,b),measure:b,bucket:l,type:S});let C=NE(x,h,t?.fields[n],b,s);return i===`donut`?(0,q.jsx)(WE,{resource:e.name,view:t,slices:C,measure:b}):(0,q.jsx)(zE,{resource:e.name,view:t,slices:C,measure:b})},vD=({node:e,slots:t,className:n})=>{let{resource:r,title:i,description:a,actions:o,span:s,className:l,...u}=xT(e),{resources:d,views:f}=c(),p=d[r];return p?(0,q.jsx)(Hw,{title:i,description:a,actions:t.actions,className:U(`h-full`,n),children:(0,q.jsx)(_D,{model:p,view:f[r],...u})}):null},yD=({model:e,query:t,className:n=`mt-4 border-t pt-4`,children:r})=>{let i=Zr(e,t),a=i.isPending?(0,q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,q.jsx)(L,{className:`h-4 w-1/2`}),(0,q.jsx)(L,{className:`h-4 w-1/3`})]}):i.error?(0,q.jsx)(Oy,{title:z(`couldNotLoad`),error:i.error}):i.data?(0,q.jsx)(Zw,{value:i.data,children:(0,q.jsx)(`div`,{className:`flex flex-col gap-3`,children:r})}):(0,q.jsx)(Uw,{children:z(`nothingYet`)});return(0,q.jsx)(`div`,{className:n,children:a})},bD=e=>{if(typeof e!=`string`&&typeof e!=`number`)return;let t=typeof e==`number`?e:Date.parse(e);return Number.isNaN(t)?void 0:t},xD=e=>e==null?``:String(e),SD=(e,t,n)=>n===0?0:(e-t)/n*100,CD=(e,t,n)=>{let r=new Map;for(let i of e){let e=bD(i[t.start]);if(e===void 0)continue;let a=bD(i[t.end]),o=Math.max(e,a??n),s=r.get(xD(i[t.lane]))??{value:i[t.lane],bars:new Map};r.set(xD(i[t.lane]),s);let c=s.bars.get(xD(i[t.bar]))??{value:i[t.bar],records:[]};s.bars.set(xD(i[t.bar]),c),c.records.push({record:i,start:e,end:o,open:a===void 0})}return r},wD=e=>{let t=[];for(let n of[...e].sort((e,t)=>e.start-t.start)){let e=t.find(e=>e.at(-1).end<=n.start);e?e.push(n):t.push([n])}return t},TD=(e,t,n)=>{let r=CD(e,t,n),i=[...r.values()].flatMap(e=>[...e.bars.values()].flatMap(e=>e.records));if(i.length===0)return{lanes:[],from:n,to:n};let a=Math.min(...i.map(e=>e.start)),o=Math.max(...i.map(e=>e.end)),s=o-a;return{lanes:[...r.entries()].map(([e,n])=>{let r=[...n.bars.entries()].map(([e,r])=>{let i=r.records.sort((e,t)=>e.start-t.start).map(({record:e,start:n,end:r,open:i})=>({record:e,value:e[t.color],start:n,end:r,open:i,left:SD(n,a,s),width:SD(r,a,s)-SD(n,a,s)})),o=i[0].start,c=Math.max(...i.map(e=>e.end));return{key:e,value:r.value,lane:n.value,start:o,end:c,left:SD(o,a,s),width:SD(c,a,s)-SD(o,a,s),segments:i}});return{key:e,value:n.value,rows:wD(r)}}),from:a,to:o}},ED=(e,t)=>{let n=e.end-e.start;return{left:SD(t.start,e.start,n),width:n===0?100:(t.end-t.start)/n*100}},DD=6e4,OD=60*DD,kD=24*OD,AD=[5*DD,15*DD,30*DD,OD,3*OD,6*OD,12*OD,kD,2*kD,7*kD,14*kD,30*kD,90*kD,365*kD],jD=365*kD,MD=(e,t,n,r,i)=>Math.floor((t+i)/n)-Math.ceil((e+r)/n)+1,ND=(e,t,n=()=>0)=>{let r=t-e;if(r<=0)return{daily:!1,ticks:[]};let i=n(e),a=n(t),o=AD.find(n=>MD(e,t,n,i,a)<=6)??Math.ceil(r/5/jD)*jD,s=[];for(let c=Math.ceil((e+i)/o)*o;c<=t+a;c+=o){let a=c-n(c-i);a+n(a)===c&&a>=e&&a<=t&&s.push({at:a,left:SD(a,e,r)})}return{daily:o>=kD,ticks:s}},PD=e=>({lane:xD(e.lane),bar:e.key}),FD=(e,t)=>t?e.lanes.find(e=>e.key===t.lane)?.rows.flat().find(e=>e.key===t.bar)??null:null,ID=(e,t)=>{let n=Object.fromEntries(new Intl.DateTimeFormat(`en-US`,{timeZone:t,hourCycle:`h23`,year:`numeric`,month:`numeric`,day:`numeric`,hour:`numeric`,minute:`numeric`}).formatToParts(e).map(e=>[e.type,e.value]));return Date.UTC(Number(n.year),Number(n.month)-1,Number(n.day),Number(n.hour),Number(n.minute))-Math.floor(e/6e4)*6e4},LD=e=>e<8?`translate-x-0`:e>92?`-translate-x-full`:`-translate-x-1/2`,RD=({from:e,to:t,dated:n})=>{let r=n?`UTC`:Hn(),i=e=>n?0:ID(e,r),{daily:a,ticks:o}=ND(e,t,i);return(0,q.jsx)(`div`,{"aria-hidden":`true`,className:`relative h-5 min-w-0 flex-1 border-b border-border text-xs text-muted-foreground tabular-nums`,children:o.map(e=>(0,q.jsx)(`span`,{className:`absolute bottom-1 whitespace-nowrap ${LD(e.left)}`,style:{left:`${e.left}%`},children:a?Ur(e.at+i(e.at)):Vr(e.at,r)},e.at))})},zD=(e,t,n)=>{let r=String(n),i=t?.waitingValues?.includes(r)??!1,a=t?.valueColors&&Object.hasOwn(t.valueColors,r)?t.valueColors[r]:void 0;return a!==void 0&&Yr(a)?{className:ji[a],striped:i}:{color:kE(e,t,n===void 0?null:n,-1),striped:i}},BD=e=>({...e.color!==void 0&&{backgroundColor:e.color},...e.striped&&{backgroundImage:`repeating-linear-gradient(-45deg, transparent 0 4px, color-mix(in srgb, var(--background) 55%, transparent) 4px 6px)`}}),VD=({bar:e,field:t,hints:n})=>e.segments.map((r,i)=>{let a=zD(t,n,r.value),{left:o,width:s}=ED(e,r);return(0,q.jsx)(`span`,{"aria-hidden":`true`,className:U(`absolute inset-y-0`,a.className),style:{left:`${o}%`,width:`${s}%`,...BD(a)}},i)}),HD=(e,t)=>t?yr(e):dr(e),UD=(e,t,n,r,i)=>{let a=e.fields[t.start]?.type===`date`;return z(`timelineRange`,{from:HD(n,a),to:i?z(`timelineNow`):HD(r,a)})},WD=(e,t,n,r)=>`${Lr(t.fields[r.color],e.value,n?.fields[r.color])}: ${UD(t,r,e.start,e.end,e.open)}`,GD=(e,t,n,r,i)=>{let a=e.segments.some(t=>t.open&&t.end===e.end);return[`${i??Lr(t.fields[r.bar],e.value,n?.fields[r.bar])}: ${UD(t,r,e.start,e.end,a)}`,...e.segments.map(e=>WD(e,t,n,r))].join(`; `)},KD=`absolute inset-y-0 flex overflow-hidden rounded-sm ring-offset-1 ring-offset-background outline-none hover:ring-2 hover:ring-border-strong focus-visible:ring-2 focus-visible:ring-primary`,qD=({bar:e,model:t,view:n,fields:r,point:i,choose:a})=>{let o=c().resources[t.fields[r.bar]?.relation?.resource??``],s=mb(o??t,e.key,o!==void 0),l=GD(e,t,n,r,o?s:void 0),u={onMouseEnter:()=>i.hover(e),onMouseLeave:()=>i.hover(null),onFocus:()=>i.focus(e),onBlur:()=>i.focus(null)},d={left:`${e.left}%`,width:`max(${e.width}%, 4px)`},f=(0,q.jsx)(VD,{bar:e,field:t.fields[r.color],hints:n?.fields[r.color]});if(!a)return(0,q.jsx)(`span`,{role:`img`,tabIndex:0,"aria-label":l,style:d,className:KD,...u,children:f});let p=a.chosen===e.key;return(0,q.jsx)(Jn,{to:a.barTo(e.key),"aria-label":l,"aria-current":p?`true`:void 0,style:d,className:U(KD,p&&`ring-2 ring-foreground`),...u,children:f})},JD=({shape:e,...t})=>{let{model:n,fields:r}=t,i=n.fields[r.lane];return(0,q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,q.jsx)(`div`,{className:`flex sm:pl-40`,children:(0,q.jsx)(RD,{from:e.from,to:e.to,dated:n.fields[r.start]?.type===`date`})}),(0,q.jsx)(`ul`,{className:`flex flex-col gap-3 sm:gap-2`,children:e.lanes.map(e=>(0,q.jsxs)(`li`,{className:`flex flex-col gap-1 sm:flex-row sm:items-center`,children:[(0,q.jsx)(`div`,{className:`min-w-0 truncate text-sm font-medium sm:w-40 sm:shrink-0 sm:pr-3`,children:(0,q.jsx)(vC,{model:n,field:i,value:e.value})}),(0,q.jsx)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-1 border-l border-border pl-px`,children:e.rows.map((e,n)=>(0,q.jsx)(`div`,{className:`relative h-6 overflow-x-clip`,children:e.map(e=>(0,q.jsx)(qD,{bar:e,...t},e.key))},n))})]},e.key))})]})},YD=({model:e,view:t,fields:n,value:r})=>{let i=zD(e.fields[n.color],t?.fields[n.color],r);return(0,q.jsx)(`span`,{"aria-hidden":`true`,className:U(`inline-block size-3 shrink-0 rounded-sm`,i.className),style:BD(i)})},XD=({values:e,...t})=>{let n=t.model.fields[t.fields.color],r=(n.enumValues??[]).filter(t=>e.has(t));return(0,q.jsx)(`ul`,{className:`flex flex-wrap gap-x-4 gap-y-1.5 text-xs text-muted-foreground`,children:r.map(e=>(0,q.jsxs)(`li`,{className:`flex items-center gap-1.5`,children:[(0,q.jsx)(YD,{...t,value:e}),Lr(n,e,t.view?.fields[t.fields.color])]},e))})},ZD=({bar:e,...t})=>{let{model:n,view:r,fields:i}=t;if(!e)return(0,q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:z(`timelinePoint`)});let a=e.segments.some(t=>t.open&&t.end===e.end);return(0,q.jsxs)(`div`,{className:`flex flex-col gap-1 text-sm`,children:[(0,q.jsxs)(`p`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,q.jsx)(`span`,{className:`font-medium`,children:(0,q.jsx)(vC,{model:n,field:n.fields[i.bar],value:e.value})}),(0,q.jsx)(`span`,{className:`text-muted-foreground tabular-nums`,children:UD(n,i,e.start,e.end,a)})]}),(0,q.jsx)(`ul`,{className:`flex flex-col gap-0.5 text-xs text-muted-foreground`,children:e.segments.map((e,a)=>(0,q.jsxs)(`li`,{className:`flex items-center gap-1.5 tabular-nums`,children:[(0,q.jsx)(YD,{...t,value:e.value}),Lr(n.fields[i.color],e.value,r?.fields[i.color]),`: `,UD(n,i,e.start,e.end,e.open)]},a))})]})},QD=500,$D=(e,t,{filter:n=``,sort:r,fields:i,limit:a})=>({queryKey:[...I.list(t.name,n,r,a,`timeline`),i.join(`,`)],queryFn:async()=>{let o=[],s;do{let c=await e.list(t.name,{filter:n||void 0,orderBy:r,pageSize:Math.min(QD,a-o.length),fields:i,etag:!1,...s&&{pageToken:s}});o.push(...c.items),s=c.nextPageToken||void 0}while(s&&o.length<a);return{rows:o.toReversed(),cut:s!==void 0}}}),eO=(e,{enabled:t=!0,...n})=>Tt({...$D(F(),e,n),enabled:t,placeholderData:sn}),tO=({model:e,view:t,fields:n,readSort:r,at:i,filter:a,limit:o=Bp,title:s,description:c,empty:l,actions:u,className:d,choose:f,details:p})=>{let[m,h]=(0,W.useState)(null),[g,_]=(0,W.useState)(null),v=e=>e?PD(e):null,y={hover:e=>h(v(e)),focus:e=>_(v(e))},b=mE(i),x=eO(e,{filter:a,sort:r,fields:[...new Set([...Object.values(n),...e.primaryKey])],limit:o,enabled:!b}),S=b??x,C=b?b.rows:x.data?.rows??[],w=!b&&x.data?.cut===!0,T=TD(C,n,Date.now());return(0,q.jsxs)(Hw,{title:s,description:c,actions:u,className:U(`h-full`,d),children:[(()=>{if(S.isPending)return(0,q.jsx)(`div`,{className:`flex flex-col gap-2`,children:Array.from({length:3},(e,t)=>(0,q.jsx)(L,{className:`h-6`},t))});if(S.error)return(0,q.jsx)(Oy,{title:z(`couldNotLoad`),error:S.error});if(T.lanes.length===0)return(0,q.jsx)(Uw,{children:l??z(`nothingYet`)});let r=new Set(C.map(e=>String(e[n.color])));return(0,q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,q.jsx)(XD,{model:e,view:t,fields:n,values:r}),(0,q.jsx)(JD,{shape:T,model:e,view:t,fields:n,point:y,...f&&{choose:f}}),w&&(0,q.jsx)(Uw,{children:z(`timelineCut`,{count:C.length})}),(0,q.jsx)(`div`,{"aria-live":`polite`,children:(0,q.jsx)(ZD,{bar:FD(T,m)??FD(T,g),model:e,view:t,fields:n})})]})})(),p]})},nO=(e,t)=>e.type===`integer`?Number(t):t,rO=({select:e,children:t,...n})=>{let{given:r,linkTo:i}=NT(),a=r[e],o=t=>i({[e]:t}),s=n.model.fields[n.fields.bar],c=a===void 0?null:(0,q.jsx)(Fe,{name:e,children:(0,q.jsx)(yD,{model:n.model,query:{filter:jE(s,nO(s,a),n.filter),sort:n.sort},children:t},a)});return(0,q.jsx)(tO,{...n,choose:{barTo:o,chosen:a},details:c})},iO=({node:e,at:t,slots:n,children:r,className:i})=>{let{className:a,resource:o,select:s,lane:l,bar:u,start:d,end:f,color:p,children:m,...h}=xT(e),{resources:g,views:_}=c(),v=g[o];if(!v)return null;let y={...h,model:v,view:_[v.name],fields:{lane:l,bar:u,start:d,end:f,color:p},readSort:zp(e),sort:Rp(e),...t!==void 0&&{at:t},actions:n.actions,className:i};return s===void 0?(0,q.jsx)(tO,{...y}):(0,q.jsx)(rO,{...y,select:s,children:r})},aO=(0,W.createContext)(void 0),oO=({node:e,at:t,children:n})=>{let r=(0,W.useMemo)(()=>({node:e,...t!==void 0&&{at:t}}),[e,t]);return(0,q.jsx)(aO.Provider,{value:r,children:n})},sO=(e,t)=>t===void 0?void 0:e.props[t],cO=e=>{let t=(0,W.useContext)(aO);if(!t)throw Error(`${e} is for a custom component in a layout`);return t},lO=()=>{let{node:e,at:t}=cO(`useComponentReads`),n=tT(),r=jT();return uO((0,W.useMemo)(()=>Wm(e,{...rT(n),params:r}),[e,n,r]),t)},uO=(e,t)=>{let{resources:n,views:r}=c(),i=F(),a=_m(e).flatMap(({reads:t,part:r})=>{let i=n[String(sO(e,t.resource))];return i?[{reads:t,part:r,model:i}]:[]}),o=hE(t===void 0?[]:a.map(({part:e})=>dm({block:t,part:e}))),s=wt({queries:a.map(({reads:t,model:n},r)=>{let a=am(sO(e,t.filter))??``,s=im(sO(e,t.sort))??``,c=sO(e,t.limit),l=typeof c==`number`?c:500;return{enabled:o[r]===void 0,queryKey:I.list(n.name,a,s,l,``),queryFn:()=>i.list(n.name,{filter:a||void 0,orderBy:s||void 0,pageSize:l})}})});return Object.fromEntries(a.map(({reads:e,model:t},n)=>{let i=o[n],a=s[n],c=i??{isPending:a.isPending,error:a.error,rows:a.data?.items??[]};return[e.resource,{model:t,view:r[t.name],rows:c.rows,isPending:c.isPending,error:c.error}]}))},dO=()=>{let{node:e}=cO(`useComponentSelect`),t=PT(),n=np(e)?.param;if(n!==void 0&&t)return{chosen:t.given[n],linkTo:e=>t.linkTo({[n]:e})}},fO=({node:e,children:t})=>{let n=np(e),r=PT(),{resources:i}=c();if(!n||!r)return t;let a=r.given[n.param],o=n.resource===void 0?void 0:i[n.resource];return a===void 0||!o?null:(0,q.jsx)(Fe,{name:n.param,children:(0,q.jsx)(yD,{model:o,query:{key:a},className:``,children:t},a)})},pO=(0,W.lazy)(()=>Ht(()=>import(`./graph-view-DkLJGbAM.js`).then(e=>({default:e.GraphView})),__vite__mapDeps([45,1,3,34,6,5,8,35,36,4,7,15,46,17,18,19,20,21,22,23,24,25,26,27,28]))),mO=(0,q.jsx)(`div`,{className:`flex h-64 w-full items-center justify-center`,children:(0,q.jsx)(wn,{})}),hO=({node:e,at:t,slots:n,children:r,className:i})=>{let a=xT(e),o=uO(e,t),s=PT(),c=o.nodes,l=o.edges,{label:u,group:d,status:f,source:p,target:m}=a,h=(0,W.useMemo)(()=>({label:u,source:p,target:m,...d!==void 0&&{group:d},...f!==void 0&&{status:f}}),[u,p,m,d,f]),g=JSON.stringify([c?.rows,l?.rows,h]),_=(0,W.useMemo)(()=>c&&l&&jm({nodes:c.rows,edges:l.rows,key:c.model.primaryKey[0],edgeKey:l.model.primaryKey,fields:h}),[g]);if(!c||!l||!_)return null;let v=c.error??l.error;if(v&&e.fallback)throw v;if(v)return(0,q.jsx)(Oy,{title:z(`couldNotLoad`),error:v});if(c.isPending||l.isPending)return mO;if(_.nodes.length===0)return(0,q.jsx)(Uw,{children:a.empty??z(`nothingYet`)});let y=a.select,b=y!==void 0&&s?{chosen:s.given[y],linkTo:e=>s.linkTo({[y]:e})}:void 0;return(0,q.jsxs)(`div`,{className:U(`flex flex-col gap-4 lg:flex-row`,i),children:[(0,q.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,q.jsx)(W.Suspense,{fallback:mO,children:(0,q.jsx)(pO,{shape:_,nodes:c,edges:l,fields:h,props:a,...b&&{select:b},...a.node!==void 0&&{content:n.node}})})}),r.length>0&&b?.chosen!==void 0&&(0,q.jsx)(`div`,{className:`min-w-0 lg:w-80 lg:shrink-0`,children:(0,q.jsx)(fO,{node:e,children:r})})]})},gO=B(`chat`),_O=e=>new Date(Date.parse(`${e}T00:00:00Z`)-864e5).toISOString().slice(0,10),vO=(e,t,n=Hn())=>Wn(Date.parse(e),n)===Wn(Date.parse(t),n),yO=(e,t=Date.now(),n=Hn())=>{let r=Wn(Date.parse(e),n),i=Wn(t,n);return r===i?gO(`today`):r===_O(i)?gO(`yesterday`):Gn(Date.parse(`${r}T00:00:00Z`))},bO=({tone:e=`day`,label:t})=>{let n=t??gO(`newMessages`),r=U(`h-px flex-1`,e===`new`?`bg-danger`:`bg-border`);return(0,q.jsxs)(`div`,{role:`separator`,"aria-label":n,"data-tone":e,"data-chat-divider":``,className:`flex items-center gap-3 text-xs font-medium`,children:[(0,q.jsx)(`span`,{className:r}),(0,q.jsx)(`span`,{className:e===`new`?`text-danger`:`text-muted-foreground`,children:n}),(0,q.jsx)(`span`,{className:r})]})},xO=({children:e,className:t})=>(0,q.jsx)(`p`,{className:U(`text-xs text-muted-foreground`,t),children:e}),SO=({time:e})=>{let t=Date.parse(e);return(0,q.jsx)(`time`,{dateTime:e,title:dr(t),className:`text-xs text-muted-foreground`,children:Vr(t)})},CO=e=>{let{children:t,footer:n}=e;if(e.author){let{author:r,time:i,avatar:a,continued:o}=e,s=r.name??r.id;return(0,q.jsxs)(`div`,{"data-from":`person`,className:U(`flex min-w-0 gap-3`,o&&`-mt-3`),children:[(0,q.jsx)(`div`,{className:`w-8 shrink-0`,children:!o&&(a??(0,q.jsx)(v_,{initials:Ob(s)||`?`,hue:Db(r.id),size:`md`,className:`ring-0`}))}),(0,q.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-0.5`,children:[!o&&(0,q.jsxs)(`p`,{className:`flex items-baseline gap-2`,children:[(0,q.jsx)(`span`,{className:`font-medium text-foreground`,children:s}),i&&(0,q.jsx)(SO,{time:i})]}),(0,q.jsx)(`div`,{className:`flex min-w-0 flex-col gap-2 whitespace-pre-wrap break-words text-foreground`,children:t}),n&&(0,q.jsx)(xO,{children:n})]})]})}if(e.alone){let{time:r,continued:i}=e;return(0,q.jsxs)(`div`,{"data-from":`person`,className:U(`flex min-w-0 flex-col gap-0.5`,i&&`-mt-3`),children:[!i&&r&&(0,q.jsx)(SO,{time:r}),(0,q.jsx)(`div`,{className:`flex min-w-0 flex-col gap-2 whitespace-pre-wrap break-words text-foreground`,children:t}),n&&(0,q.jsx)(xO,{children:n})]})}let r=(0,q.jsx)(`div`,{"data-from":e.from,className:U(`flex min-w-0 flex-col gap-2 whitespace-pre-wrap break-words`,e.from===`user`?`ml-8 self-end rounded-lg rounded-br-sm bg-primary px-3 py-2 text-primary-foreground shadow-sm`:`mr-4 text-foreground`),children:t});return n?(0,q.jsxs)(`div`,{className:U(`flex min-w-0 flex-col gap-1`,e.from===`user`&&`items-end`),children:[r,(0,q.jsx)(xO,{className:e.from===`user`?`text-right`:void 0,children:n})]}):r},wO=({working:e})=>(0,q.jsx)(`div`,{role:`status`,className:`shrink-0 pl-11`,children:e&&(0,q.jsxs)(`p`,{"data-chat-working":!0,className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,q.jsx)(`span`,{"aria-hidden":!0,className:`flex gap-1`,children:[0,200,400].map(e=>(0,q.jsx)(`span`,{className:`size-1.5 rounded-full bg-muted-foreground [animation:pb-shimmer_1.2s_ease-in-out_infinite]`,style:{animationDelay:`${e}ms`}},e))}),gO(`working`)]})}),TO=e=>e.scrollHeight-e.scrollTop-e.clientHeight<=24,EO=(e,t)=>{if(t.followKey!==e.followKey)return t.scrollHeight;if(e.first===void 0&&t.first!==void 0&&t.newLineTop!==void 0)return Math.max(0,t.scrollTop+t.newLineTop-16);if(e.first!==void 0&&t.first!==e.first&&e.anchor&&t.anchorTop!==void 0)return t.scrollTop+t.anchorTop-e.anchor.top;if(e.atEnd)return t.scrollHeight},DO=(e,t,n)=>{let r=e.getBoundingClientRect().top,i=Array.from(t.children).find(e=>!e.hasAttribute(`data-chat-divider`)&&e.getBoundingClientRect().bottom>r),a=i&&{anchor:{element:i,top:i.getBoundingClientRect().top-r}};return{atEnd:TO(e),first:t.firstElementChild??void 0,followKey:n,...a}},OO=(e,t)=>{let n=(0,W.useRef)({onReadToEnd:e,atEnd:t});(0,W.useLayoutEffect)(()=>{n.current={onReadToEnd:e,atEnd:t}});let r=(0,W.useCallback)(()=>{document.visibilityState===`visible`&&n.current.onReadToEnd?.()},[]);return(0,W.useEffect)(()=>{let e=()=>{n.current.atEnd()&&r()};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[r]),r},kO=e=>e.querySelector(`[data-chat-divider][data-tone="new"]`),AO=({children:e,empty:t,length:n,onLoadEarlier:r,loadingEarlier:i,followKey:a,onReadToEnd:o,working:s})=>{let c=(0,W.useRef)(null),l=(0,W.useRef)(null),u=(0,W.useRef)({atEnd:!0,first:void 0,followKey:a}),d=()=>{c.current&&l.current&&(u.current=DO(c.current,l.current,a))},f=()=>u.current.atEnd&&u.current.first!==void 0,p=OO(o,f),m=()=>{let e=u.current.atEnd;d(),!e&&f()&&p()};(0,W.useLayoutEffect)(()=>{let e=c.current;if(!e||!l.current)return;let t=u.current,n=t.anchor&&t.anchor.element.isConnected?t.anchor.element.getBoundingClientRect().top-e.getBoundingClientRect().top:void 0,r=kO(l.current),i=r?r.getBoundingClientRect().top-e.getBoundingClientRect().top:void 0,o=EO(t,{first:l.current.firstElementChild??void 0,anchorTop:n,scrollTop:e.scrollTop,scrollHeight:e.scrollHeight,followKey:a,newLineTop:i});o!==void 0&&(e.scrollTop=o),d(),f()&&p()},[n,a,s]),(0,W.useEffect)(()=>{let e=c.current;if(!e||!l.current)return;let t=new ResizeObserver(()=>{u.current.atEnd&&(e.scrollTop=e.scrollHeight)});return t.observe(e),t.observe(l.current),()=>t.disconnect()},[]);let h=n===0&&!!t;return(0,q.jsxs)(`div`,{ref:c,onScroll:m,className:`flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto p-4 [overflow-anchor:none]`,children:[r&&(0,q.jsx)(P,{size:`sm`,className:`self-center`,loading:i,onClick:r,children:gO(`loadEarlier`)}),h&&(0,q.jsx)(`div`,{className:`m-auto max-w-60 text-center text-muted-foreground`,children:t}),(0,q.jsx)(`div`,{ref:l,role:`log`,"aria-live":`polite`,className:U(`flex flex-col gap-4`,h&&`hidden`),children:e}),s!==void 0&&(0,q.jsx)(wO,{working:s})]})},jO=(e,t,n)=>{if(n!==0){if(e===`Home`)return 0;if(e===`End`)return n-1;if(e===`ArrowDown`)return t<0?0:(t+1)%n;if(e===`ArrowUp`)return t<0?n-1:(t-1+n)%n}},MO=(e,t)=>{let n=/(?:^|\s)@([^\s@]*)$/.exec(e.slice(0,t));return n?{start:t-n[1].length-1,query:n[1]}:void 0},NO=(e,t,n)=>{let r=e.slice(t.start+1+t.query.length),i=`@${n}${r.startsWith(` `)?``:` `}`;return{text:`${e.slice(0,t.start)}${i}${r}`,caret:t.start+i.length+ +!!r.startsWith(` `)}},PO=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),FO=e=>{let t=[...new Set(e)].filter(Boolean).sort((e,t)=>t.length-e.length);return t.length===0?void 0:RegExp(`(?<![\\p{L}\\p{N}_@])@(${t.map(PO).join(`|`)})(?![\\p{L}\\p{N}_])`,`gu`)},IO=(e,t)=>{let n=FO(t.map(e=>e.name)),r=new Set(n?[...e.matchAll(n)].map(e=>e[1]):[]);return[...new Set(t.filter(e=>r.has(e.name)).map(e=>e.id))]},LO=(e,t)=>{let n=FO(t.flatMap(e=>e.name?[e.name]:[]));if(!n)return[{text:e}];let r=[],i=0;for(let t of e.matchAll(n))t.index>i&&r.push({text:e.slice(i,t.index)}),r.push({mention:t[1]}),i=t.index+t[0].length;return i<e.length&&r.push({text:e.slice(i)}),r},RO=B(`mentions`),zO=({id:e,optionId:t,people:n,active:r,onActive:i,onPick:a,failed:o,at:s})=>(0,q.jsxs)(`ul`,{id:e,role:`listbox`,"aria-label":RO(`peopleToMention`),className:U(`absolute z-30 w-full max-w-sm rounded-md border bg-background py-1 shadow-pop`,s===`above`?`bottom-full mb-1`:`mt-1`),onMouseDown:e=>e.preventDefault(),children:[n.map((e,n)=>(0,q.jsx)(`li`,{id:t(n),role:`option`,"aria-selected":n===r,className:U(`cursor-pointer truncate px-3 py-1.5`,n===r&&`bg-muted`),onMouseMove:()=>n!==r&&i(n),onClick:()=>a(e),children:e.name},e.id)),n.length===0&&(0,q.jsx)(`li`,{className:`px-3 py-1.5 text-muted-foreground`,children:RO(o?`couldNotSearch`:`noOneFound`)})]}),BO=(e,t)=>{let[n,r]=(0,W.useState)(e);return(0,W.useEffect)(()=>{let n=setTimeout(()=>r(e),t);return()=>clearTimeout(n)},[e,t]),n},VO=(e,t)=>{let n=BO(t,150),[r,i]=(0,W.useState)(),a=(0,W.useRef)(e);return a.current=e,(0,W.useEffect)(()=>{let e=a.current;if(n===void 0||!e)return;let t=!0;return e(n).then(e=>t&&i({people:e}),()=>t&&i({failed:!0})),()=>{t=!1}},[n]),t===void 0?void 0:r},HO={text:``,picked:[]},UO=8,WO=({value:e,onChange:t,searchPeople:n,listAt:r=`below`,onKeyDown:i,onFocus:a,onBlur:o,ref:s,...c})=>{let[l,u]=(0,W.useState)(0),[d,f]=(0,W.useState)(!1),[p,m]=(0,W.useState)(0),[h,g]=(0,W.useState)(),_=(0,W.useRef)(null),v=(0,W.useCallback)(e=>{_.current=e,typeof s==`function`?s(e):s&&(s.current=e)},[s]),y=(0,W.useRef)(void 0),b=(0,W.useId)(),x=n?MO(e.text,l):void 0,S=d&&x!==void 0&&x.start!==h,C=VO(n,S?x.query:void 0),w=S&&C&&`people`in C?C.people.slice(0,UO):[],T=S&&C!==void 0,E=e=>`${b}-${e}`;(0,W.useEffect)(()=>m(0),[x?.query]);let D=x?.start;(0,W.useEffect)(()=>{D===void 0&&g(void 0)},[D]),(0,W.useLayoutEffect)(()=>{y.current!==void 0&&_.current&&(_.current.setSelectionRange(y.current,y.current),u(y.current),y.current=void 0)},[e.text]);let O=n=>{if(!x)return;let r=NO(e.text,x,n.name);y.current=r.caret,t({text:r.text,picked:[...e.picked,n]})},k=e=>{if(S){let t=jO(e.key,p,w.length);if(t!==void 0&&(e.key===`ArrowDown`||e.key===`ArrowUp`)){e.preventDefault(),m(t);return}if((e.key===`Enter`||e.key===`Tab`)&&w[p]){e.preventDefault(),O(w[p]);return}if(e.key===`Escape`){e.preventDefault(),e.stopPropagation(),g(x.start);return}}i?.(e)},ee=n&&{role:`combobox`,"aria-multiline":!0,"aria-autocomplete":`list`,"aria-expanded":T,"aria-controls":b,"aria-activedescendant":T&&w[p]?E(p):void 0};return(0,q.jsxs)(`div`,{className:`relative`,children:[(0,q.jsx)(jy,{...c,...ee,ref:v,value:e.text,onChange:n=>{t({...e,text:n.target.value}),u(n.target.selectionStart)},onSelect:e=>u(e.currentTarget.selectionStart),onFocus:e=>{f(!0),a?.(e)},onBlur:e=>{f(!1),o?.(e)},onKeyDown:k}),T&&(0,q.jsx)(zO,{id:b,optionId:E,people:w,active:p,onActive:m,onPick:O,failed:`failed`in C,at:r})]})},GO=({text:e,mentions:t})=>(0,q.jsx)(`p`,{className:`whitespace-pre-wrap break-words`,children:LO(e,t).map((e,t)=>`mention`in e?(0,q.jsxs)(`span`,{className:`font-medium text-primary`,children:[`@`,e.mention]},t):e.text)}),KO=e=>e.types.includes(`Files`),qO=e=>e.types.includes(`text/plain`)?[]:[...e.files],JO=(e,{busy:t,canSendEmpty:n})=>t?!1:e!==``||n===!0,YO=({onSend:e,busy:t,placeholder:n,inputRef:r,searchPeople:i,attachments:a,actions:o,canSendEmpty:s,onFiles:c})=>{let[l,u]=(0,W.useState)(HO),d=l.text.trim(),f=JO(d,{busy:t,canSendEmpty:s}),p=()=>{if(!f)return;let t=e?.(d,IO(d,l.picked));if(!(t instanceof Promise)){u(HO);return}t.then(e=>{e&&u(e=>e.text.trim()===d?HO:e)})};return(0,q.jsxs)(`form`,{className:`flex flex-wrap items-end gap-2`,onSubmit:e=>{e.preventDefault(),p()},onDragOver:e=>{c&&KO(e.dataTransfer)&&e.preventDefault()},onDrop:e=>{c&&KO(e.dataTransfer)&&(e.preventDefault(),c([...e.dataTransfer.files]))},children:[a&&(0,q.jsx)(`div`,{className:`basis-full`,children:a}),o,(0,q.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,q.jsx)(WO,{ref:r,rows:1,"aria-label":gO(`message`),placeholder:n,value:l,onChange:u,searchPeople:i,listAt:`above`,onKeyDown:e=>{e.key!==`Enter`||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),p())},onPaste:e=>{if(!c)return;let t=qO(e.clipboardData);t.length!==0&&(e.preventDefault(),c(t))}})}),(0,q.jsx)(P,{type:`submit`,variant:`primary`,className:`w-8 px-0`,"aria-label":gO(`send`),disabled:!f,children:(0,q.jsx)(od,{className:`size-4`})})]})},XO=B(`app/conversation`),ZO=({resource:e,field:t,values:n,placeholder:r})=>{let{resources:i}=c(),a=F(),o=qr(),s=re(e),[l,u]=(0,W.useState)(!1),[d,f]=(0,W.useState)();return!i[e]||!iS(s,`create`)?null:(0,q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[d!==void 0&&(0,q.jsx)(Oy,{title:XO(`notSent`),error:d}),(0,q.jsx)(YO,{onSend:async r=>{u(!0),f(void 0);let i=await a.create(e,{...n,[t]:r}).then(()=>!0,e=>(f(e),!1));return u(!1),i&&o(e),i},busy:l,placeholder:r})]})},QO=({node:e})=>{let{resource:t,field:n,values:r,placeholder:i}=xT(e);return(0,q.jsx)(ZO,{resource:t,field:n,values:r,placeholder:i})},$O=({node:e,children:t,className:n})=>{let{open:r}=xT(e);return(0,q.jsx)(`details`,{open:r,className:U(`[&[open]>summary]:mb-2`,n),children:t})},ek=({children:e,className:t})=>(0,q.jsx)(`summary`,{className:U(`cursor-pointer font-medium`,t),children:e}),tk=(e,t=1)=>{let n=t,r=t;return e.split(`
10
+ `).map(e=>e.startsWith(`+`)?{kind:`add`,text:e.slice(1),newNo:r++}:e.startsWith(`-`)?{kind:`del`,text:e.slice(1),oldNo:n++}:{kind:`ctx`,text:e.startsWith(` `)?e.slice(1):e,oldNo:n++,newNo:r++})},nk=e=>({added:e.filter(e=>e.kind===`add`).length,removed:e.filter(e=>e.kind===`del`).length}),rk=e=>{let t=[],n=[],r=[],i=()=>{for(let e=0;e<Math.max(n.length,r.length);e++)t.push({kind:`pair`,old:n[e],new:r[e]});n=[],r=[]};for(let a of e){if(a.kind===`del`){r.length>0&&i(),n.push(a);continue}if(a.kind===`add`){r.push(a);continue}i(),t.push(a.kind===`hunk`?{kind:`hunk`,text:a.text}:{kind:`pair`,old:a,new:a})}return i(),t},ik={add:`bg-success-soft text-success-text`,del:`bg-danger-soft text-danger-text`,ctx:`text-muted-foreground`,hunk:`bg-surface text-faint-foreground`},ak={add:`+`,del:`−`,ctx:``,hunk:``},ok=`bg-background py-1 font-mono text-[0.6875rem] leading-[18px]`,sk=({line:e})=>(0,q.jsxs)(`div`,{className:U(`flex min-w-0`,e?ik[e.kind]:`bg-surface`),children:[(0,q.jsx)(`span`,{className:`w-8 shrink-0 select-none pr-2 text-right opacity-60`,children:e?.newNo??e?.oldNo}),(0,q.jsx)(`span`,{className:`w-3 shrink-0 select-none`,children:e&&ak[e.kind]}),(0,q.jsx)(`span`,{className:`min-w-0 whitespace-pre-wrap break-words pr-3`,children:e?.text})]}),ck=({line:e})=>(0,q.jsx)(sk,{line:e&&e.kind===`ctx`?{...e,newNo:void 0}:e}),lk=({lines:e,className:t})=>(0,q.jsx)(`pre`,{className:U(`overflow-x-auto`,ok,t),children:e.map((e,t)=>(0,q.jsx)(sk,{line:e},t))}),uk=({lines:e,className:t})=>(0,q.jsx)(`pre`,{className:U(`grid-cols-2`,ok,t),children:rk(e).map((e,t)=>e.kind===`hunk`?(0,q.jsx)(`div`,{className:U(`col-span-2 px-3`,ik.hunk),children:e.text},t):(0,q.jsxs)(`div`,{className:`contents`,children:[(0,q.jsx)(ck,{line:e.old}),(0,q.jsx)(sk,{line:e.new})]},t))}),dk=({source:e,start:t,path:n,split:r,className:i})=>{let a=typeof e==`string`?tk(e,t):e,o=nk(a);return(0,q.jsxs)(`div`,{className:U(`overflow-hidden`,i),children:[n&&(0,q.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-border bg-surface px-3 py-1.5`,children:[(0,q.jsx)(ml,{className:`size-3.5 text-muted-foreground`}),(0,q.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-[0.6875rem] text-foreground`,children:n}),(0,q.jsxs)(`span`,{className:`text-[0.6875rem] font-medium text-success-text`,children:[`+`,o.added]}),o.removed>0&&(0,q.jsxs)(`span`,{className:`text-[0.6875rem] font-medium text-danger-text`,children:[`−`,o.removed]})]}),a.length>0&&!r&&(0,q.jsx)(lk,{lines:a}),a.length>0&&r&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(lk,{lines:a,className:`md:hidden`}),(0,q.jsx)(uk,{lines:a,className:`hidden md:grid`})]})]})},fk={a:7,b:8,t:9,n:10,v:11,f:12,r:13,'"':34,"\\":92},pk=new TextEncoder,mk=new TextDecoder,hk=e=>{if(!e.startsWith(`"`))return;let t=[],n=1;for(;n<e.length;){let r=String.fromCodePoint(e.codePointAt(n));if(r===`"`)return{path:mk.decode(new Uint8Array(t)),rest:e.slice(n+1)};if(r!==`\\`){t.push(...pk.encode(r)),n+=r.length;continue}let i=/^[0-3][0-7]{2}/.exec(e.slice(n+1));if(i){t.push(parseInt(i[0],8)),n+=4;continue}let a=fk[e[n+1]??``];if(a===void 0)return;t.push(a),n+=2}},gk=/^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/,_k=/^(index |old mode |new mode |deleted file mode |new file mode |similarity index |dissimilarity index |rename from |rename to |copy from |copy to |Binary files )/,vk=e=>{let t=hk(e.slice(4)),n=t?t.path:e.slice(4).split(` `)[0];if(n!==`/dev/null`)return n.replace(/^[ab]\//,``)},yk=(e,t)=>{let n=hk(t);if(n&&n.rest!==``)return;let r=n?n.path:t;if(e.startsWith(`a/`)&&r.startsWith(`b/`))return{old:e.slice(2),new:r.slice(2)}},bk=e=>{if(!e.startsWith(`diff --git `))return;let t=e.slice(11),n=hk(t);if(n)return n.rest.startsWith(` `)?yk(n.path,n.rest.slice(1)):void 0;let r=t.indexOf(` "b/`);if(r!==-1)return yk(t.slice(0,r),t.slice(r+1));let i=[...t.matchAll(/ b\//g)].map(e=>[t.slice(0,e.index),t.slice(e.index+1)]),a=i.find(([e,t])=>e.slice(2)===t.slice(2))??i.at(-1);return a&&yk(...a)},xk=(e,t)=>{let n=t.find(t=>e.startsWith(t));if(n===void 0)return;let r=e.slice(n.length);return hk(r)?.path??r},Sk=(e,t)=>bk(e[t])!==void 0||e[t].startsWith(`--- `)&&e[t+1]?.startsWith(`+++ `)===!0,Ck=e=>{let t=e.replace(/\r\n/g,`
11
+ `).split(`
12
+ `);t.at(-1)===``&&t.pop();let n=0;for(;n<t.length&&!Sk(t,n);)n++;let r=[],i;for(;n<t.length;){let e=t[n],a=r.at(-1);if(e===`-- `)break;let o=bk(e);if(o!==void 0){r.push({path:o.new,lines:[]}),i=o,n++;continue}if(e.startsWith(`--- `)&&t[n+1]?.startsWith(`+++ `)){let a=vk(e),o=vk(t[n+1]);(i===void 0||(a??i.old)!==i.old||(o??i.new)!==i.new)&&r.push({path:o??a??``,lines:[]}),i=void 0,n+=2;continue}if(a&&a.lines.length===0&&_k.test(e)){let t=xk(e,[`rename from `,`copy from `]),r=xk(e,[`rename to `,`copy to `]);i&&t!==void 0&&(i.old=t),i&&r!==void 0&&(i.new=r,a.path=r),n++;continue}let s=gk.exec(e);if(!a||!s)return;i=void 0,a.lines.push({kind:`hunk`,text:e});let c=Number(s[1]),l=Number(s[3]),u=s[2]===void 0?1:Number(s[2]),d=s[4]===void 0?1:Number(s[4]);for(n++;u>0||d>0;){let e=t[n];if(e===void 0)return;if(n++,!e.startsWith(`\\`)){if(e.startsWith(`+`))a.lines.push({kind:`add`,text:e.slice(1),newNo:l++}),d--;else if(e.startsWith(`-`))a.lines.push({kind:`del`,text:e.slice(1),oldNo:c++}),u--;else if(e.startsWith(` `)||e===``)a.lines.push({kind:`ctx`,text:e.slice(1),oldNo:c++,newNo:l++}),u--,d--;else return;if(u<0||d<0)return}}for(;t[n]?.startsWith(`\\`);)n++}return r.length>0?r:void 0},wk=({node:e,className:t})=>{let{source:n,emptyText:r}=xT(e),i=JT(n);if(i.state===`missing`)return null;if(i.state===`loading`)return(0,q.jsx)(L,{className:U(`h-24 w-full`,t)});if(i.value===null||i.value===void 0||i.value===``)return r?(0,q.jsx)(`p`,{className:U(`text-sm text-muted-foreground`,t),children:r}):null;let a=String(i.value),o=Ck(a);return o?(0,q.jsx)(`div`,{className:U(`flex flex-col gap-3`,t),children:o.map((e,t)=>(0,q.jsx)(dk,{source:e.lines,path:e.path,split:!0,className:`rounded-md border border-border`},`${t}-${e.path}`))}):(0,q.jsx)(`pre`,{className:U(`overflow-x-auto whitespace-pre-wrap break-words rounded-md border border-border bg-background p-3 font-mono text-[0.6875rem] leading-[18px]`,t),children:a})},Tk=e=>e==null?``:typeof e==`object`?JSON.stringify(e):String(e),Ek=(e,t)=>{if(t)return t;let n=e.split(`.`).map(e=>H(e).toLowerCase()).join(` `);return n[0].toUpperCase()+n.slice(1)},Dk=({node:e,className:t})=>{let{source:n,label:r,format:i}=xT(e),{views:a}=c(),o=JT(n);if(o.state===`missing`)return null;let s=o.state===`loading`?(0,q.jsx)(L,{className:`h-4 w-24`}):o.state===`plain`?Tk(o.value):(0,q.jsx)(vC,{model:o.model,field:o.field,value:o.value,format:i});if(r===!1)return(0,q.jsx)(`div`,{className:t,children:s});let l=r??Ek(n,o.state===`ready`?a[o.model.name]?.fields[o.field.name]?.label:void 0);return(0,q.jsxs)(`div`,{className:U(`min-w-0`,t),children:[(0,q.jsx)(`div`,{className:`text-body text-muted-foreground`,children:l}),(0,q.jsx)(`div`,{className:`mt-0.5 truncate`,children:s})]})},Ok={1:``,2:`md:grid-cols-2`,3:`md:grid-cols-2 xl:grid-cols-3`,4:`sm:grid-cols-2 xl:grid-cols-4`},kk={1:``,2:`grid-cols-2`,3:`grid-cols-2 xl:grid-cols-3`,4:`grid-cols-2 xl:grid-cols-4`},Ak={1:``,2:`md:col-span-2`,3:`md:col-span-2 xl:col-span-3`,4:`sm:col-span-2 md:col-span-2 xl:col-span-4`},jk=e=>typeof e==`object`&&!e.custom&&e.type===`Stat`,Mk=({node:e,children:t,className:n})=>{let{columns:r=2}=xT(e),i=e.children,a=i.length>0&&i.every(jk);return(0,q.jsx)(`div`,{className:U(`grid grid-cols-1 gap-4`,a?kk[r]:Ok[r],n),children:t.map((e,t)=>{let n=i[t],r=typeof n==`object`?n.props.span:void 0;return(0,q.jsx)(`div`,{className:U(`min-w-0`,r&&Ak[r]),children:e},t)})})},Nk=()=>{let[e,t]=(0,W.useState)(0),n=(0,W.useRef)(void 0);return[(0,W.useCallback)(e=>{n.current?.disconnect(),e&&(t(e.getBoundingClientRect().width),n.current=new ResizeObserver(([e])=>t(e.contentRect.width)),n.current.observe(e))},[]),e]},Pk=[`light`,`dark`,`system`],Fk=`protobase:theme`,Ik=`(prefers-color-scheme: dark)`,Lk=e=>Pk.includes(e),Rk=e=>i(()=>{let t=e.getItem(Fk);return Lk(t)?t:`system`},`system`),zk=(e,t)=>i(()=>t===`system`?e.removeItem(Fk):e.setItem(Fk,t),void 0),Bk=(e,t)=>e===`system`?t?`dark`:`light`:e,Vk=(0,W.createContext)(void 0),Hk=({children:e})=>{let[t,n]=(0,W.useState)(()=>Rk(localStorage)),r=Bk(t,x(Ik));return(0,W.useEffect)(()=>{document.documentElement.dataset.theme=r},[r]),(0,W.useEffect)(()=>{let e=e=>{(e.key===`protobase:theme`||e.key===null)&&n(Rk(localStorage))};return window.addEventListener(`storage`,e),()=>window.removeEventListener(`storage`,e)},[]),(0,q.jsx)(Vk.Provider,{value:{preference:t,theme:r,choose:e=>{zk(localStorage,e),n(e)}},children:e})},Uk=()=>{let e=(0,W.useContext)(Vk);if(!e)throw Error(`useTheme needs a ThemeProvider above it`);return e},Wk=({src:e,alt:t,width:n,height:r,className:i})=>(0,q.jsx)(`img`,{src:e,alt:t??``,width:n,height:r,className:i??`max-w-full`}),Gk=({width:e,height:t,space:n,theme:r})=>{let i=e??Math.ceil(n/100)*100;if(i!==0)return{width:String(i),...t!==void 0&&{height:String(t)},theme:r}},Kk=e=>({staleTime:1/0,refetchOnWindowFocus:!1,...e!==void 0&&{refetchInterval:e*1e3}}),qk=e=>e instanceof Blob&&e.type.startsWith(`image/`),Jk=e=>{let[t,n]=(0,W.useState)();return(0,W.useEffect)(()=>{if(!e)return n(void 0);let t=URL.createObjectURL(e);return n(t),()=>URL.revokeObjectURL(t)},[e]),t},Yk=e=>{let[t,n]=(0,W.useState)();return[t!==void 0&&t===e,()=>n(e)]},Xk=({name:e,alt:t,width:n,height:r,refresh:i,className:a})=>{let o=F(),{theme:s}=Uk(),[c,l]=Nk(),u=Gk({width:n,height:r,space:l,theme:s}),d=Tt({queryKey:I.image(e,u??{}),enabled:u!==void 0,placeholderData:sn,...Kk(i),queryFn:async()=>{let t=await o.invoke(e,{query:u,cache:`no-store`});if(!qk(t))throw Error(`The function "${e}" answered no picture`);return t}}),f=Jk(d.data),[p,m]=Yk(f),h={...n!==void 0&&{width:n},...r!==void 0&&{height:r}};return(0,q.jsx)(`div`,{ref:c,className:U(`min-w-0`,a),children:d.isError||p?t&&(0,q.jsx)(`p`,{className:`text-muted-foreground`,children:t}):f?(0,q.jsx)(`img`,{src:f,alt:t??``,onError:m,style:h,className:n===void 0?`w-full max-w-full object-contain`:`max-w-full object-contain`}):(0,q.jsx)(L,{className:`w-full max-w-full`,style:{height:r??160,...n!==void 0&&{width:n}}})})},Zk=({node:e,className:t})=>{let n=xT(e);return n.src===void 0?(0,q.jsx)(Xk,{name:n.function,alt:n.alt,width:n.width,height:n.height,refresh:n.refresh,className:t}):(0,q.jsx)(Wk,{src:n.src,alt:n.alt,width:n.width,height:n.height,className:t})},Qk=e=>function({node:t,className:n}){let r=xT(t),{views:i}=c(),a=JT(r.source);return a.state===`missing`?null:a.state===`loading`?(0,q.jsx)(L,{className:`inline-block h-3 w-16 align-middle`}):xm(t.type,a.value)?r.emptyText?(0,q.jsx)(`span`,{className:n,children:r.emptyText}):null:a.state===`plain`?(0,q.jsx)(`span`,{className:n,children:e({value:a.value,field:void 0,hints:void 0,props:r})}):(0,q.jsx)(`span`,{className:n,children:e({value:a.value,field:a.field,hints:i[a.model.name]?.fields[a.field.name],props:r})})},$k=({value:e,field:t,hints:n})=>t?.type===`enum`&&typeof e==`string`?ar(e,n?.valueLabels):Sm(e),eA=Qk($k),tA=Qk(({value:e,props:t})=>(0,q.jsx)(`span`,{className:`tabular-nums`,children:Cm(e,t,ci())})),nA=Qk(({value:e,props:t})=>{let n=wm(e,t,{locale:ci(),now:Date.now(),relative:Un});return(0,q.jsx)(`time`,{dateTime:String(e),children:n})}),rA=Qk(({value:e,props:t})=>{let n=Tm(e,t,{yes:Er(`yes`),no:Er(`no`)});return e?(0,q.jsx)(IT,{label:n,className:`align-middle`}):(0,q.jsx)(`span`,{className:`text-faint-foreground`,children:n})}),iA=Qk(({value:e,props:t})=>{let n=String(e),r=t.content??n,i=Dm(n);return i===void 0?r:(0,q.jsx)(`a`,{href:i,className:`font-medium text-primary-text hover:underline`,.../^https?:/i.test(i)&&{target:`_blank`,rel:`noreferrer`},children:r})}),aA=Qk(e=>(0,q.jsx)(ri,{value:e.value,hints:e.hints,children:$k(e)})),oA=`font-medium text-primary-text hover:underline`,sA=({node:e,children:t,className:n})=>{let r=xT(e),i={...rT(tT()),params:jT()},a=r.variant?U(zn({variant:r.variant}),n):n??oA,o=e.children.some(e=>typeof e!=`string`||e.trim()!==``)?t:void 0;if(r.to){let e=Yn(r.to,Lm(i));return(0,q.jsx)(Ue,{to:e,className:a,children:o??We(e)})}let s=r.href??``;return(0,q.jsx)(`a`,{href:s,className:a,...s.startsWith(`http`)&&{target:`_blank`,rel:`noreferrer`},children:o??s})},cA=B(`app/field`),lA=(e,t)=>typeof e?.[t]==`number`?e[t]:void 0,uA=(e,t)=>{let n=lA(t,`min`),r=lA(t,`max`);if(n!==void 0)return cA(`atLeastCharacters`,{label:e,count:k_(n),n});if(r!==void 0)return cA(`atMostCharacters`,{label:e,count:k_(r),n:r})},dA=e=>{let t=lA(e,`min`),n=lA(e,`max`);return t===void 0?n===void 0?cA(`wholeNumber`):cA(`wholeNumberAtMost`,{max:k_(n)}):cA(`wholeNumberAtLeast`,{min:k_(t)})},fA=e=>{let t=lA(e,`precision`),n=lA(e,`scale`);if(t===void 0||n===void 0)return cA(`number`);let r=k_(10**(t-n));return n===0?cA(`wholeNumberBelow`,{below:r}):cA(`decimalsBelow`,{scale:n,below:r})},pA={text:uA,integer:(e,t)=>dA(t),bigint:()=>cA(`wholeNumber`),decimal:(e,t)=>fA(t),date:()=>cA(`date`),timestamp:()=>cA(`timestamp`),country:()=>cA(`country`),currency:()=>cA(`currency`),uuid:()=>cA(`uuid`),enum:()=>cA(`enum`),relation:()=>cA(`relation`),json:()=>cA(`json`)},mA=(e,t,n)=>n.code===`required`?cA(`required`,{label:t}):n.code!==`invalid-value`||!e?n.message:pA[e.type]?.(t,n.params)??n.message,hA=e=>{if(!Tn(e))return{};let t={};for(let n of e.errors)n.field&&n.field!==`_record`&&!Object.hasOwn(t,n.field)&&(t[n.field]=n);return t},gA=e=>{if(e.operation!==void 0)return e.message;let t=new Set(e.errors.flatMap(e=>e.field&&e.field!==`_record`?[e.field]:[])),n=e.errors.flatMap(e=>e.field===`_record`?[e.message]:[]);return t.size===0&&n.length===0?e.message:[...t.size===0?[]:[t.size===1?cA(`checkField`):cA(`checkFields`,{count:t.size})],...n].join(` `)},_A=e=>{let t=(0,W.useRef)(null),n=(0,W.useRef)(!1);return(0,W.useEffect)(()=>{e>0&&(n.current=!0)},[e]),(0,W.useEffect)(()=>{if(!n.current)return;let e=t.current?.querySelector(`[aria-invalid="true"]`);e&&(e.focus(),n.current=!1)}),t},vA=(e,t,n)=>Object.fromEntries(t.map(t=>{let r=e.fields[t];if(r.type===`file`)return[t,n?.[t]??null];if(n)return[t,r.type===`boolean`?!!n[t]:$v(n[t])];let i=r.default&&`value`in r.default?r.default.value:void 0;return[t,r.type===`boolean`?!!i:$v(i)]})),yA=(e,t,n)=>Object.fromEntries(Object.entries(t).flatMap(([t,r])=>{let i=e.fields[t];return gy(r)?r.key===$v(n[t])?[]:[[t,i.type===`integer`?Number(r.key):r.key]]:uy(i,r,n[t])?[[t,sy(i,r)]]:[]})),bA=({model:e,record:t,mode:n,label:r,title:i,fields:a,values:o,onClose:s})=>{let{resources:l,views:u}=c(),d=F(),f=nS(),p=qr(),m=u[e.name],[h,g]=(0,W.useState)(()=>vA(e,a,t?.record)),[_,v]=(0,W.useState)({}),[y,b]=(0,W.useState)(0),x=_A(y),[S,C]=(0,W.useState)(),[w,T]=(0,W.useState)(!1),[E,D]=(0,W.useState)(!1);we(E||w,`input-lost`);let O=async()=>{T(!0),C(void 0),await(n===`create`?d.create(e.name,{...by(e,l,h),...o}):d.update(e.name,t.key,yA(e,h,t.record),t.etag??`*`)).then(async()=>{await p(e.name),f.show({state:`success`,title:z(`saved`,{label:i??r})}),s()},e=>{let t=hA(e);v(t),Object.keys(t).length>0&&b(e=>e+1),C(e)}),T(!1)};return(0,q.jsx)(di,{title:i??r,onClose:s,actions:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(P,{onClick:s,children:z(`cancel`)}),(0,q.jsx)(P,{variant:`primary`,loading:w,onClick:()=>void O(),children:z(n===`create`?`create`:`save`)})]}),children:(0,q.jsxs)(`form`,{ref:x,className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),O()},children:[S!==void 0&&Object.keys(_).length===0&&(0,q.jsx)(Oy,{title:z(`notSaved`),error:S}),a.map(n=>{let r=e.fields[n],i=h[n],a=r.relation?l[r.relation.resource]:void 0,o=m?.fields[n]?.label??H(n),s=_[n];return(0,q.jsx)(Mv,{name:n,label:o,help:m?.fields[n]?.help,error:s&&mA(r,o,s),children:(0,q.jsx)(GC,{field:r,hints:m?.fields[n],value:gy(i)?i.key:i,stored:t?.record[n],relationLabel:gy(i)?i.label:void 0,relationPicker:a?{target:a,view:u[a.name]}:void 0,invalid:!!_[n],resource:e.name,onChange:e=>{v(({[n]:e,...t})=>t),D(!0),g(t=>({...t,[n]:e}))}})},n)})]})})},xA=({model:e,recordKey:t,children:n})=>{let r=Zr(e,{key:t});return(0,q.jsx)(q.Fragment,{children:n(r.data??void 0)})},SA=({node:e})=>{let t=xT(e),n=eT(),{resources:r}=c(),i=r[t.resource??n?.model.name??``],a=re(i?.name??``),[o,s]=(0,W.useState)(!1);if(!i||!(t.mode===`create`?iS(a,`create`):iS(a,`update`)&&n?.permissions?.update!==!1))return null;let l=e=>(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(P,{size:`sm`,variant:t.variant??`secondary`,disabled:t.mode===`edit`&&!e,onClick:()=>s(!0),children:t.label}),o&&(0,q.jsx)(bA,{...t,model:i,record:t.mode===`edit`?e:void 0,onClose:()=>s(!1)})]});return t.mode===`edit`&&t.recordKey!==void 0?(0,q.jsx)(xA,{model:i,recordKey:t.recordKey,children:l}):l(t.mode===`edit`?n:void 0)},CA=e=>e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey,wA=`flex min-h-[49px] min-w-0 flex-1 flex-col items-center justify-center gap-1 pb-1 pt-1.5 text-[0.625rem] font-medium leading-none`,TA=({tabs:e,onNavigate:t,onMore:n,moreOpen:r,moreControls:i,sticky:a,ref:o})=>{let s=!e.some(e=>e.active);return(0,q.jsxs)(q.Fragment,{children:[a&&(0,q.jsx)(`div`,{"aria-hidden":!0,className:`h-[var(--pb-sticky-bottom)] shrink-0 md:hidden`}),(0,q.jsxs)(`nav`,{ref:o,"aria-label":Wr(`tabs`),className:U(`flex shrink-0 border-t bg-background pb-[var(--pb-safe-bottom)] md:hidden`,a&&`fixed bottom-0 left-[var(--pb-safe-left)] right-[var(--pb-safe-right)] z-30`),children:[e.map(e=>{let n=e.icon;return(0,q.jsxs)(`a`,{href:e.href,"aria-current":e.active?`page`:void 0,...e.external?{target:`_blank`,rel:`noreferrer`}:{},onClick:n=>{!e.external&&t&&CA(n)&&(n.preventDefault(),t(e.href))},className:U(wA,e.active?`text-primary-text`:`text-muted-foreground`),children:[(0,q.jsx)(n,{className:`size-6`,strokeWidth:e.active?2.2:1.9,"aria-hidden":!0}),(0,q.jsx)(`span`,{className:`max-w-full truncate px-0.5`,children:e.label})]},e.id)}),(0,q.jsxs)(`button`,{type:`button`,"aria-expanded":r,"aria-controls":i,"data-current":s||void 0,onClick:n,className:U(wA,s?`text-primary-text`:`text-muted-foreground`),children:[(0,q.jsx)(il,{className:`size-6`,strokeWidth:s?2.2:1.9,"aria-hidden":!0}),Wr(`more`)]})]})]})},EA=({id:e,open:t,onClose:n,children:r})=>{let i=(0,W.useRef)(null);return li(i,t,n),t?(0,q.jsxs)(`div`,{className:`fixed inset-0 z-50 md:hidden`,children:[(0,q.jsx)(`div`,{className:`absolute inset-0 bg-backdrop/40`,onClick:n,"aria-hidden":!0}),(0,q.jsx)(`div`,{ref:i,id:e,role:`dialog`,"aria-modal":`true`,"aria-label":Wr(`navigation`),tabIndex:-1,className:`absolute inset-y-0 left-0 flex w-[calc(15rem+var(--pb-safe-left))] max-w-[85vw] bg-sidebar pl-[var(--pb-safe-left)] shadow-pop outline-none`,onClick:e=>e.target.closest(`a`)&&n(),children:r})]}):null},DA=(0,W.createContext)(()=>{}),OA=e=>{let t=(0,W.useContext)(DA);(0,W.useLayoutEffect)(()=>(t(e),()=>t(void 0)),[t,e])},kA=e=>{(0,W.useLayoutEffect)(()=>{if(!e)return;let t=document.documentElement;return t.style.setProperty(`scrollbar-gutter`,`stable`),()=>{t.style.removeProperty(`scrollbar-gutter`)}},[e])},AA=[`--pb-sticky-top`,`--pb-sticky-bottom`,`scroll-padding-top`,`scroll-padding-bottom`],jA=(e,t,n,r)=>{(0,W.useLayoutEffect)(()=>{if(!e)return;let r=document.documentElement,i=()=>{let e=`${t.current?.offsetHeight??0}px`,i=n.current?`${n.current.offsetHeight}px`:`var(--pb-safe-bottom)`;r.style.setProperty(`--pb-sticky-top`,e),r.style.setProperty(`--pb-sticky-bottom`,i),r.style.setProperty(`scroll-padding-top`,e),r.style.setProperty(`scroll-padding-bottom`,i)},a=new ResizeObserver(i);for(let e of[t.current,n.current])e&&a.observe(e);return i(),()=>{a.disconnect();for(let e of AA)r.style.removeProperty(e)}},[e,t,n,r])},MA=`fill-[#ff5a1f] dark:fill-[#ff6a33]`,NA=`fill-[#14161a] dark:fill-[#f1f0ea]`,PA=({className:e})=>(0,q.jsxs)(`svg`,{viewBox:`0 0 32 32`,className:U(`size-7 shrink-0`,e),"aria-hidden":!0,children:[(0,q.jsx)(`path`,{className:MA,fillRule:`evenodd`,d:`M0 5a5 5 0 0 1 5-5h7a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2zM4 5a1 1 0 0 1 1-1h5v6H4z`}),(0,q.jsx)(`path`,{className:NA,d:`M17 0h10a5 5 0 0 1 5 5v22a5 5 0 0 1-5 5H5a5 5 0 0 1-5-5V17h17z`})]}),FA={sm:`size-7`,lg:`size-10`},IA={sm:`md`,lg:`lg`},LA=({appName:e,appIcon:t,size:n=`sm`,className:r})=>t?(0,q.jsx)(`img`,{src:t,alt:``,className:U(FA[n],`shrink-0 object-contain`,r)}):e&&e!==`Protobase`?(0,q.jsx)(v_,{initials:Ob(e).slice(0,1),hue:Db(e),size:IA[n],className:r}):(0,q.jsx)(PA,{className:U(FA[n],r)}),RA=`M312.3 9.9Q257 9.9 217.1 -21.1Q177.3 -52.1 168.4 -108.8L181.1 -110.3V205H54.8V-510H176.7V-404.5L168.3 -407Q179.7 -460.8 221.2 -490.4Q262.7 -520 319.8 -520Q376.2 -520 417 -488.4Q457.8 -456.8 479.8 -398.6Q501.8 -340.5 501.8 -259.9Q501.8 -177.6 478.3 -116.8Q454.9 -55.9 412.5 -23Q370.1 9.9 312.3 9.9ZM274.4 -92.6Q320.2 -92.6 345.8 -133.8Q371.4 -175.1 371.4 -256.4Q371.4 -337.7 345.7 -377.6Q320.1 -417.5 274 -417.5Q228.6 -417.5 202.7 -376.4Q176.9 -335.3 176.9 -254Q176.9 -173.3 202.7 -132.9Q228.4 -92.6 274.4 -92.6Z M549.8 0V-510H671.7V-388.3H676.1V0H549.8ZM676.1 -286.5 661.3 -386.2Q677.9 -455.2 711.8 -487.6Q745.7 -520 794.3 -520Q809 -520 818 -516.6V-394.2Q814.2 -395.6 807.1 -396.1Q800 -396.6 789.4 -396.6Q734.6 -396.6 705.3 -370.5Q676.1 -344.4 676.1 -286.5Z M1043.8 10Q974.7 10 922.6 -23.6Q870.6 -57.2 842.1 -117.5Q813.6 -177.8 813.6 -257Q813.6 -336.5 842.2 -395.5Q870.8 -454.5 922.5 -487.2Q974.2 -520 1043.8 -520Q1113.7 -520 1165.4 -487.2Q1217.1 -454.5 1245.6 -395.5Q1274 -336.5 1274 -257Q1274 -177.8 1245.5 -117.5Q1217 -57.2 1165.3 -23.6Q1113.6 10 1043.8 10ZM1043.8 -90.5Q1073.5 -90.5 1095.9 -108.9Q1118.2 -127.3 1130.9 -164.4Q1143.6 -201.5 1143.6 -257.5Q1143.6 -339.8 1116 -379.7Q1088.4 -419.5 1043.8 -419.5Q999.3 -419.5 971.6 -379.5Q944 -339.5 944 -257.5Q944 -201.5 956.7 -164.4Q969.4 -127.3 991.8 -108.9Q1014.3 -90.5 1043.8 -90.5Z M1509 10.2Q1427.2 10.2 1387.6 -29.2Q1348 -68.6 1348 -147.7V-613.8L1474.2 -666.1V-146.7Q1474.2 -118.4 1489.9 -104.3Q1505.6 -90.3 1539.2 -90.3Q1552 -90.3 1562.7 -92.5Q1573.3 -94.8 1582.5 -98.7V-1.9Q1571.6 4 1552 7.1Q1532.4 10.2 1509 10.2ZM1270.1 -411V-510H1580.6V-411H1270.1Z M1810.8 10Q1741.7 10 1689.6 -23.6Q1637.6 -57.2 1609.1 -117.5Q1580.6 -177.8 1580.6 -257Q1580.6 -336.5 1609.2 -395.5Q1637.8 -454.5 1689.5 -487.2Q1741.2 -520 1810.8 -520Q1880.7 -520 1932.4 -487.2Q1984.1 -454.5 2012.6 -395.5Q2041 -336.5 2041 -257Q2041 -177.8 2012.5 -117.5Q1984 -57.2 1932.3 -23.6Q1880.6 10 1810.8 10ZM1810.8 -90.5Q1840.5 -90.5 1862.9 -108.9Q1885.2 -127.3 1897.9 -164.4Q1910.6 -201.5 1910.6 -257.5Q1910.6 -339.8 1883 -379.7Q1855.4 -419.5 1810.8 -419.5Q1766.3 -419.5 1738.6 -379.5Q1711 -339.5 1711 -257.5Q1711 -201.5 1723.7 -164.4Q1736.4 -127.3 1758.8 -108.9Q1781.3 -90.5 1810.8 -90.5Z M2343.3 9.9Q2288 9.9 2247.7 -21.1Q2207.4 -52.1 2198.5 -108.8L2205.8 -110.3V0H2085.8V-720H2212.1V-404.5L2203.7 -407Q2215.1 -460.8 2255.6 -490.4Q2296.2 -520 2351 -520Q2407.3 -520 2448 -488.4Q2488.8 -456.8 2510.8 -398.6Q2532.8 -340.5 2532.8 -259.9Q2532.8 -177.6 2509.3 -116.8Q2485.9 -55.9 2443.5 -23Q2401.1 9.9 2343.3 9.9ZM2305.4 -92.6Q2350.7 -92.6 2376.6 -133.8Q2402.4 -175.1 2402.4 -256.4Q2402.4 -337.7 2376.5 -377.6Q2350.6 -417.5 2305 -417.5Q2260.5 -417.5 2234.2 -376.4Q2207.9 -335.3 2207.9 -254Q2207.9 -173.3 2234.1 -132.9Q2260.3 -92.6 2305.4 -92.6Z M2834 0Q2828 -19.1 2825.7 -41.7Q2823.3 -64.2 2823.3 -91.8H2818.6V-356Q2818.6 -391.9 2803.1 -409.1Q2787.5 -426.3 2756.2 -426.3Q2724.2 -426.3 2706.4 -408.7Q2688.7 -391.2 2686.3 -358.9H2571.2Q2574.6 -429.6 2625.4 -474.8Q2676.1 -520 2763.5 -520Q2850.2 -520 2896.1 -476.5Q2941.9 -432.9 2941.9 -352.2V-91.8Q2941.9 -69.5 2944.7 -46.7Q2947.5 -23.8 2954.1 0H2834ZM2690.6 10Q2631.9 10 2595.4 -26.3Q2558.9 -62.5 2558.9 -124.5Q2558.9 -185 2594.3 -224Q2629.8 -263 2704.5 -287.6L2845.4 -337.4V-248.7L2753.4 -219.3Q2716.5 -206.1 2699.3 -186.6Q2682.2 -167.2 2682.2 -139Q2682.2 -112.4 2697.5 -98.4Q2712.9 -84.3 2739.4 -84.3Q2773.2 -84.3 2795.9 -104.1Q2818.6 -123.9 2818.6 -153.1L2829.9 -85.8Q2812.6 -37.4 2776.8 -13.7Q2741 10 2690.6 10Z M3168 10Q3080.6 10 3030.1 -34.2Q2979.6 -78.4 2974.7 -158.1H3082.4Q3086.3 -120 3108.9 -100.5Q3131.5 -80.9 3169.8 -80.9Q3202 -80.9 3218.9 -93.9Q3235.8 -106.9 3235.8 -131.3Q3235.8 -151.1 3224.3 -165.6Q3212.9 -180.1 3178.9 -195.4L3111.2 -224.8Q3053 -247.7 3023.8 -284.2Q2994.5 -320.8 2994.5 -373.9Q2994.5 -440.1 3040.1 -480Q3085.7 -520 3162.8 -520Q3242.2 -520 3288.4 -480Q3334.6 -440 3339.5 -367.9H3231.8Q3228.6 -399.7 3211.3 -414.4Q3194 -429.1 3164 -429.1Q3136.1 -429.1 3120.5 -417Q3104.8 -405 3104.8 -382.7Q3104.8 -364.2 3117.7 -349.8Q3130.6 -335.5 3162.4 -321.6L3236.6 -289.6Q3288.6 -269.2 3317.4 -229.2Q3346.1 -189.1 3346.1 -136.9Q3346.1 -69 3299.2 -29.5Q3252.3 10 3168 10Z M3587.8 10Q3520 10 3469.2 -23.3Q3418.5 -56.6 3390.5 -116.5Q3362.6 -176.3 3362.6 -255.8Q3362.6 -336.4 3390.9 -395.7Q3419.3 -454.9 3470.7 -487.5Q3522 -520 3591.1 -520Q3656.6 -520 3702.7 -489.8Q3748.8 -459.7 3773.7 -403.1Q3798.6 -346.5 3798.6 -266.5Q3798.6 -253.7 3798 -242.5Q3797.5 -231.3 3795.8 -221.4H3440V-306.9H3709L3681.8 -277.9Q3681.6 -355.2 3657.7 -390.7Q3633.8 -426.3 3589.3 -426.3Q3541.7 -426.3 3515.6 -384Q3489.5 -341.7 3489.5 -255Q3489.5 -168.4 3515 -126.1Q3540.5 -83.7 3590.6 -83.7Q3623.7 -83.7 3644.6 -102Q3665.5 -120.3 3673.8 -156.3H3788.9Q3772.2 -81.6 3721.5 -35.8Q3670.8 10 3587.8 10Z`,zA=({className:e})=>(0,q.jsx)(`svg`,{viewBox:`54.8 -720 3743.8 925`,className:U(`h-3.5 w-auto`,e),role:`img`,"aria-label":`Protobase`,children:(0,q.jsx)(`path`,{className:NA,d:RA})}),BA=({compact:e,workspace:t,appName:n,appIcon:r})=>(0,q.jsxs)(`div`,{className:`flex items-center gap-2.5 overflow-hidden`,children:[(0,q.jsx)(LA,{appName:n,appIcon:r}),!e&&(0,q.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-0.5 leading-tight`,children:[r||n&&n!==`Protobase`?(0,q.jsx)(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:n??`Protobase`}):(0,q.jsx)(zA,{className:`self-start`}),t&&(0,q.jsx)(`div`,{className:`truncate text-[0.6875rem] text-muted-foreground`,children:t})]})]}),VA=`protobase:logo-tap`,HA=(e=window)=>{let t=!e.dispatchEvent(new Event(VA,{cancelable:!0}));return e.parent&&e.parent!==e&&e.parent.postMessage({type:VA},`*`),t},UA=({label:e,current:t,others:n,rowClassName:r,onSwitch:i})=>(0,q.jsxs)(`div`,{className:`border-b py-1`,role:`group`,"aria-label":e,children:[t&&(0,q.jsxs)(`div`,{className:U(r,`text-foreground hover:bg-transparent`),"aria-current":`true`,children:[(0,q.jsx)(xi,{className:`size-4`}),(0,q.jsx)(`span`,{className:`truncate`,children:t.label})]}),n.map(e=>(0,q.jsxs)(`button`,{type:`button`,role:`menuitem`,onClick:()=>i(e.id),className:r,children:[(0,q.jsx)(`span`,{className:`size-4`}),(0,q.jsx)(`span`,{className:`truncate`,children:e.label})]},e.id))]}),WA=()=>[{value:`light`,label:Wr(`light`),icon:Md},{value:`dark`,label:Wr(`dark`),icon:Su},{value:`system`,label:Wr(`system`),icon:bu}],GA=({theme:e,className:t})=>(0,q.jsxs)(`div`,{className:t,children:[(0,q.jsx)(Ad,{className:`size-4`}),(0,q.jsx)(`span`,{className:`flex-1`,children:Wr(`theme`)}),(0,q.jsx)(Av,{label:Wr(`theme`),iconOnly:!0,value:e.preference,options:WA(),onChange:e.onChange})]}),KA=`flex min-h-11 w-full items-center gap-2.5 px-3 py-1.5 text-left text-muted-foreground hover:bg-muted md:min-h-0`,qA=({user:e,compact:t,open:n,items:r=[],account:i,onNavigate:a,onSignOut:o,organizations:s,roles:c,theme:l,status:u})=>{let d=c?.roles.find(e=>e.name===c.active),[f,p]=(0,W.useState)(!1),m=n??f,h=(0,W.useRef)(null),[g,_]=(0,W.useState)();(0,W.useEffect)(()=>{if(!m||n!==void 0)return;let e=e=>{(e instanceof KeyboardEvent?e.key===`Escape`:!h.current?.contains(e.target))&&p(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,e),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,e)}},[m,n]);let v=r.filter(e=>e.length>0),y=(e,t,n)=>{p(!1),!n&&a&&(e.preventDefault(),a(t))};return(0,q.jsxs)(`div`,{ref:h,className:`relative`,children:[(0,q.jsxs)(`button`,{type:`button`,className:`flex min-h-11 w-full items-center gap-2.5 rounded-md p-1 text-left hover:bg-muted md:min-h-0`,"aria-label":Wr(`profileMenu`),"aria-haspopup":`menu`,"aria-expanded":m,onClick:()=>{let e=h.current?.getBoundingClientRect();e&&_({left:e.left,bottom:window.innerHeight-e.top+8}),p(!f)},children:[(0,q.jsx)(v_,{initials:e.initials,hue:e.hue,size:`md`,className:`ring-0`}),!t&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`span`,{className:`min-w-0 flex-1 leading-tight`,children:[u?.mark?(0,q.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1`,children:[(0,q.jsx)(`span`,{className:`truncate font-medium`,children:e.name}),u.mark]}):(0,q.jsx)(`span`,{className:`block truncate font-medium`,children:e.name}),(0,q.jsx)(Ni,{tone:e.roleTone,dot:!1,className:`mt-0.5 h-4 px-1.5 text-[0.625rem]`,children:e.role})]}),(0,q.jsx)(Ec,{className:`size-3.5 shrink-0 text-faint-foreground`})]})]}),m&&(0,q.jsxs)(`div`,{role:`menu`,className:n===void 0?`fixed z-[60] w-56 overflow-hidden rounded-lg border bg-background py-1 shadow-pop`:`absolute bottom-full left-0 z-50 mb-2 w-56 overflow-hidden rounded-lg border bg-background py-1 shadow-pop`,style:n===void 0&&g?{left:g.left,bottom:g.bottom}:void 0,children:[i?(0,q.jsxs)(`a`,{role:`menuitem`,href:i,onClick:e=>y(e,i),className:`block border-b px-3 pb-2 pt-1.5 hover:bg-muted`,children:[(0,q.jsx)(`div`,{className:`font-medium`,children:e.name}),(0,q.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,children:e.email})]}):(0,q.jsxs)(`div`,{className:`border-b px-3 pb-2 pt-1.5`,children:[(0,q.jsx)(`div`,{className:`font-medium`,children:e.name}),(0,q.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,children:e.email})]}),u&&(0,q.jsx)(`div`,{className:`border-b py-1`,children:(0,q.jsxs)(`button`,{type:`button`,role:`menuitem`,className:KA,onClick:()=>{p(!1),u.onOpen()},children:[(0,q.jsx)(fl,{className:`size-4 shrink-0`}),(0,q.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:u.label})]})}),s&&(s.current||s.others.length>0)&&(0,q.jsx)(UA,{label:Wr(`organizations`),...s.current&&{current:{id:s.current.id,label:s.current.name}},others:s.others.map(({id:e,name:t})=>({id:e,label:t})),rowClassName:KA,onSwitch:e=>{p(!1),s.onSwitch(e)}}),c&&c.roles.length>1&&(0,q.jsx)(UA,{label:Wr(`roles`),...d&&{current:{id:d.name,label:d.label}},others:c.roles.filter(e=>e!==d).map(({name:e,label:t})=>({id:e,label:t})),rowClassName:KA,onSwitch:e=>{p(!1),c.onSwitch(e)}}),v.map((e,t)=>(0,q.jsx)(`div`,{role:`group`,className:U(`py-1`,(t<v.length-1||l||o)&&`border-b`),children:e.map(e=>{let t=e.icon;return(0,q.jsxs)(`a`,{role:`menuitem`,href:e.href,"aria-current":e.active?`page`:void 0,...e.external?{target:`_blank`,rel:`noreferrer`}:{},onClick:t=>y(t,e.href,e.external),className:U(KA,e.active&&`bg-muted text-foreground`),children:[(0,q.jsx)(t,{className:`size-4`}),e.label]},e.id)})},e[0]?.id)),l&&(0,q.jsx)(`div`,{className:U(o&&`border-b`),children:(0,q.jsx)(GA,{theme:l,className:U(KA,`hover:bg-transparent`)})}),o&&(0,q.jsxs)(`button`,{type:`button`,role:`menuitem`,onClick:o,className:KA,children:[(0,q.jsx)(nu,{className:`size-4`}),Wr(`signOut`)]})]})]})},JA={"text-large":`h-8 gap-2.5 px-2.5`,"text-small":`h-7 gap-2 px-2 text-body`},YA={"text-large":`ml-[20px]`,"text-small":`ml-[17px]`},XA=({create:e,mode:t,onNavigate:n})=>(0,q.jsx)(`div`,{className:U(`border-l border-transparent pl-1.5`,YA[t]),children:(0,q.jsxs)(`a`,{href:e.href,onClick:n&&(t=>{t.preventDefault(),n(e.href)}),className:U(`flex items-center rounded-md text-faint-foreground transition-colors hover:bg-muted hover:text-foreground`,JA[t]),children:[(0,q.jsx)(Hu,{"aria-hidden":!0,className:`size-3.5 shrink-0`}),(0,q.jsx)(`span`,{className:`truncate`,children:e.label})]})}),ZA=`protobase:nav-open:`,QA=e=>`${ZA}${e}`,$A=(e,t)=>i(()=>e.getItem(t)!==`false`,!0),ej=(e,t,n)=>i(()=>n?e.removeItem(t):e.setItem(t,`false`),void 0),tj=({label:e,side:t=`right`,visible:n,children:r})=>(0,q.jsxs)(`span`,{className:`group/tooltip relative inline-flex`,children:[r,(0,q.jsx)(`span`,{role:`tooltip`,className:U(`pointer-events-none absolute z-50 whitespace-nowrap rounded-md bg-foreground px-2 py-1 text-xs font-medium text-background opacity-0 shadow-md transition-opacity group-hover/tooltip:opacity-100`,n&&`opacity-100`,t===`right`&&`left-full top-1/2 ml-2 -translate-y-1/2`,t===`top`&&`bottom-full left-1/2 mb-2 -translate-x-1/2`,t===`bottom`&&`left-1/2 top-full mt-2 -translate-x-1/2`),children:e})]}),nj=e=>e===`text-large`||e===`text-small`||e===`icon-expand`,rj=e=>e===`text-large`||e===`text-small`,ij={"text-large":`w-60 max-w-[33vw]`,"text-small":`w-52 max-w-[33vw]`,icon:`w-14`,"icon-label":`w-[76px]`,"icon-tooltip":`w-14`,"icon-expand":`w-14`},aj={"text-large":`h-9 gap-3 px-3 text-sm`,"text-small":`h-7 gap-2.5 px-2.5 text-body`,icon:`size-9 justify-center`,"icon-label":`w-full flex-col gap-0.5 py-1.5 text-[0.625rem]`,"icon-tooltip":`size-9 justify-center`,"icon-expand":`h-8 gap-3 px-3`},oj=({item:e,mode:t,active:n,onNavigate:r,className:i})=>{let a=e.icon,o=(0,q.jsxs)(`a`,{onClick:r&&(t=>{t.preventDefault(),r(e.href??`#${e.id}`)}),href:e.href??`#${e.id}`,"aria-label":e.problem?`${e.label}: ${e.problem}`:e.label,"aria-current":n?`page`:void 0,title:e.problem,className:U(`flex shrink-0 items-center rounded-md font-medium transition-colors`,aj[t],n?`bg-primary-soft text-primary-text`:`text-muted-foreground hover:bg-muted hover:text-foreground`,i),children:[(0,q.jsx)(a,{className:U(`shrink-0`,t===`text-small`?`size-4`:`size-[18px]`),strokeWidth:n?2.2:1.9}),(nj(t)||t===`icon-label`)&&(0,q.jsx)(`span`,{className:`whitespace-nowrap`,children:e.label}),rj(t)&&e.count&&(0,q.jsx)(`span`,{className:`ml-auto rounded bg-muted px-1.5 text-[0.6875rem] tabular-nums text-muted-foreground`,children:e.count}),rj(t)&&e.problem&&(0,q.jsx)(Mi,{"aria-hidden":!0,className:`ml-auto size-3.5 shrink-0 text-warning-text`})]});return t===`icon-tooltip`?(0,q.jsx)(tj,{label:e.label,children:o}):o},sj=99,cj=e=>e===void 0||e<=0?void 0:e>sj?`${sj}+`:String(e),lj=({count:e,className:t})=>{let n=cj(e);return n?(0,q.jsx)(Ni,{tone:`red`,dot:!1,className:U(`h-4 min-w-4 justify-center px-1 text-[0.625rem] font-semibold`,t),children:n}):null},uj=B(`status`),dj=({presence:e})=>{let t=uj(e);return(0,q.jsx)(`span`,{role:`img`,"aria-label":t,title:t,className:`flex shrink-0`,children:(0,q.jsx)(zx,{tone:e===`online`?`success`:`neutral`})})},fj=e=>uj(e===`busy`?`busy`:e===`do_not_disturb`?`doNotDisturb`:`automatic`),pj=({availability:e,title:t})=>{if(e===`automatic`)return null;let n=fj(e);return(0,q.jsx)(e===`busy`?Bc:Pc,{role:`img`,"aria-label":n,className:U(`size-3.5 shrink-0`,e===`busy`?`text-warning`:`text-danger`),children:(0,q.jsx)(`title`,{children:t??n})})},mj=({status:e,presence:t,textShown:n=`full`,className:r})=>{let i=xn(e);if(!i&&!t)return null;let a=i?.text??void 0;return(0,q.jsxs)(`span`,{className:U(`inline-flex min-w-0 items-center gap-1 text-muted-foreground`,r),title:a,children:[t&&(0,q.jsx)(dj,{presence:t}),i&&(0,q.jsx)(pj,{availability:i.availability,...n===`hover`&&a&&{title:a}}),i&&n===`hover`&&i.availability===`automatic`&&a&&(0,q.jsx)(`span`,{role:`img`,"aria-label":a,className:`size-1.5 shrink-0 rounded-full bg-faint-foreground`}),a&&n===`full`&&(0,q.jsx)(`span`,{className:`truncate text-xs`,children:a})]})},hj=(e,t)=>e.map(e=>{let n=t&&Object.hasOwn(t,e.id)?t[e.id]:void 0;return n?{...e,mark:n}:e}),gj=e=>{if(!e)return[];let t=xn(e.status);return[e.presence&&uj(e.presence),t&&t.availability!==`automatic`?fj(t.availability):void 0,t?.text??void 0]},_j=e=>{let t=[e.status?.label,...gj(e.mark?.person),e.mark?.label].filter(e=>e!==void 0&&e!==``);return{ariaLabel:[e.label,...t].join(`, `),title:t.length===0?e.label:`${e.label} (${t.join(`, `)})`}},vj=({records:e,mode:t,onNavigate:n})=>e.map(e=>{let{ariaLabel:r,title:i}=_j(e),a=n&&(t=>{t.preventDefault(),n(e.href)}),o=e.mark?.strong===!0;return(0,q.jsx)(`li`,{children:(0,q.jsxs)(`a`,{href:e.href,onClick:a,"aria-label":r,title:i,"aria-current":e.active?`page`:void 0,className:U(`flex min-w-0 items-center rounded-md transition-colors`,JA[t],o?`font-bold`:`font-medium`,e.active||o?`text-foreground`:`text-muted-foreground`,e.active?`bg-muted`:`hover:bg-muted hover:text-foreground`),children:[e.status&&(0,q.jsx)(zx,{tone:e.status.tone,pulse:e.status.pulse}),(0,q.jsx)(`span`,{className:`truncate`,children:e.label}),e.mark?.person&&(0,q.jsx)(mj,{...e.mark.person,textShown:`hover`,className:`ml-1.5 shrink-0`}),(0,q.jsx)(lj,{count:e.mark?.count,className:`ml-auto shrink-0`})]})},e.id)}),yj=({records:e,useMarks:t,...n})=>(0,q.jsx)(vj,{records:hj(e,t()),...n}),bj=({records:e,useMarks:t,mode:n,onNavigate:r})=>t?(0,q.jsx)(yj,{records:e,useMarks:t,mode:n,onNavigate:r}):(0,q.jsx)(vj,{records:e,mode:n,onNavigate:r}),xj=({item:e,recent:t,mode:n,active:r,onNavigate:i})=>{let a=QA(e.id),[o,s]=(0,W.useState)(()=>$A(localStorage,a)),c=(0,W.useId)(),l=e.href??`#${e.id}`;return(0,q.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,q.jsxs)(`div`,{className:`relative`,children:[(0,q.jsx)(oj,{item:e,mode:n,active:r,onNavigate:i,className:`pr-8`}),(0,q.jsx)(`button`,{type:`button`,"aria-expanded":o,"aria-controls":c,"aria-label":Wr(`recent`,{plural:e.label.toLowerCase()}),onClick:()=>{ej(localStorage,a,!o),s(!o)},className:`absolute right-1 top-1/2 inline-flex size-6 -translate-y-1/2 items-center justify-center rounded text-faint-foreground hover:bg-muted hover:text-foreground`,children:(0,q.jsx)(qn,{className:U(`size-3.5 transition-transform`,o&&`rotate-90`)})})]}),o&&(0,q.jsxs)(`ul`,{id:c,"aria-label":Wr(`recent`,{plural:e.label.toLowerCase()}),className:U(`flex flex-col gap-0.5 border-l pl-1.5`,YA[n]),children:[t.state===`loading`&&(0,q.jsx)(`li`,{role:`status`,"aria-label":Wr(`loading`),className:U(`flex items-center`,JA[n]),children:(0,q.jsx)(L,{className:`w-3/4`})}),t.state===`error`&&(0,q.jsx)(`li`,{className:U(`flex items-center text-faint-foreground`,JA[n]),children:Wr(`couldNotLoad`)}),t.state===`ready`&&(0,q.jsx)(bj,{records:t.records,useMarks:t.useMarks,mode:n,onNavigate:i}),(0,q.jsx)(`li`,{children:(0,q.jsx)(`a`,{...(e=>({href:e,onClick:i&&(t=>{t.preventDefault(),i(e)})}))(l),className:U(`flex items-center rounded-md text-faint-foreground transition-colors hover:bg-muted hover:text-foreground`,JA[n]),children:Wr(`viewAll`)})})]})]})},Sj=({mode:e,activeItem:t,user:n,workspace:r,appName:i,appIcon:a,forceExpanded:o,profileMenuOpen:s,groups:c=[],userMenu:l,account:u,onNavigate:d,onSignOut:f,signIn:p,organizations:m,roles:h,theme:g,status:_,sticky:v,logo:y=BA,notice:b,fill:x})=>{let S=e===`icon-expand`,C=S&&o,w=rj(e)||S;return(0,q.jsx)(`nav`,{"aria-label":Wr(`resources`),className:U(v?`sticky top-0 h-dvh self-start`:`relative`,`z-30 shrink-0`,x?`w-full`:ij[e]),children:(0,q.jsxs)(`div`,{className:U(`group/side absolute inset-y-0 left-0 flex flex-col overflow-hidden border-r bg-sidebar pb-[var(--pb-safe-bottom)] pt-[var(--pb-safe-top)]`,S?`w-14 transition-[width,box-shadow] duration-150 hover:w-60 hover:shadow-pop focus-within:w-60 focus-within:shadow-pop`:`w-full`,C&&`w-60 shadow-pop`),children:[(0,q.jsx)(`div`,{className:U(`flex h-12 shrink-0 items-center px-3.5`,e===`icon-label`&&`justify-center px-0`),onClick:()=>HA(),children:(0,q.jsx)(y,{compact:!w,workspace:r,appName:i,appIcon:a})}),(0,q.jsx)(`div`,{className:U(`flex-1 overflow-y-auto overflow-x-hidden pb-2`,`px-2`),children:c.map((n,r)=>(0,q.jsxs)(`div`,{className:U(`flex flex-col gap-0.5`,r>0&&`mt-3`),children:[w?n.label&&(0,q.jsx)(`h2`,{className:U(`px-3 pb-1 pt-1 text-xs font-medium uppercase tracking-wide text-faint-foreground`,S&&`h-4 whitespace-nowrap py-0 opacity-0 transition-opacity group-hover/side:opacity-100 group-focus-within/side:opacity-100`,C&&`opacity-100`),children:n.label}):(0,q.jsxs)(q.Fragment,{children:[n.label&&(0,q.jsx)(`h2`,{className:`sr-only`,children:n.label}),r>0&&(0,q.jsx)(`div`,{className:`mx-auto mb-1 h-px w-6 bg-border`})]}),n.items.map(n=>(0,q.jsxs)(W.Fragment,{children:[n.recent&&rj(e)?(0,q.jsx)(xj,{item:n,recent:n.recent,mode:e,active:n.id===t,onNavigate:d}):(0,q.jsx)(oj,{item:n,mode:e,active:n.id===t,onNavigate:d}),n.create&&rj(e)&&(0,q.jsx)(XA,{create:n.create,mode:e,onNavigate:d})]},n.id))]},n.label))}),b,(0,q.jsx)(`div`,{className:U(`shrink-0 border-t p-2`,e!==`text-large`&&e!==`text-small`&&!S&&`flex justify-center`),children:n?(0,q.jsx)(qA,{user:n,compact:!w,open:s,items:l,account:u,onNavigate:d,onSignOut:f,organizations:m,roles:h,theme:g,status:_}):(0,q.jsxs)(q.Fragment,{children:[g&&w&&(0,q.jsx)(GA,{theme:g,className:`flex min-h-11 w-full items-center gap-2.5 whitespace-nowrap p-1.5 text-muted-foreground md:min-h-0`}),p&&(0,q.jsxs)(Jn,{to:p,"aria-label":Wr(`signIn`),className:`flex min-h-11 w-full items-center gap-2.5 rounded-md p-1.5 text-left font-medium text-muted-foreground hover:bg-muted hover:text-foreground md:min-h-0`,children:[(0,q.jsx)(eu,{className:`size-4 shrink-0`}),w&&(0,q.jsx)(`span`,{className:`whitespace-nowrap`,children:Wr(`signIn`)})]})]})})]})})},Cj=e=>h()&&rj(e),wj=(0,W.createContext)(null),Tj=()=>(0,W.useContext)(wj),Ej=e=>{let t=e.at(-1),n=typeof t==`object`&&!!t.above,r=n?t:e.at(-2);if(typeof r==`object`&&r.href&&!r.loading)return{label:r.label,href:r.href,shown:n}},Dj=({children:e})=>(0,q.jsx)(`kbd`,{className:`inline-flex h-5 items-center rounded border border-border-strong bg-background px-1.5 font-sans text-[0.6875rem] font-medium text-muted-foreground`,children:e}),Oj=(e,t,n)=>t===0?-1:e<0?n===1?0:t-1:(e+n+t)%t,kj=e=>e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||e.button!==0,Aj=({search:e,className:t=`w-96`,fieldClassName:n,autoFocus:r,showShortcut:i=!0,ref:a})=>{let o=(0,W.useId)(),s=(0,W.useRef)(null),[c,l]=(0,W.useState)(!1),[u,d]=(0,W.useState)(-1),f=e.groups.flatMap(e=>e.hits),p=c&&(e.query!==``||e.loading),m=e=>`${o}-${e}`,h=(0,W.useRef)(null),g=(0,W.useRef)(null),_=Bv(p,h,g),v=Uv(p,h,g,`${_?.right} ${e.loading} ${f.length} ${e.groups.length}`),y=e=>{s.current=e,typeof a==`function`?a(e):a&&(a.current=e)},b=t=>{e.onSelect(t),d(-1),s.current?.blur()},x=()=>{e.onTextChange(``),d(-1),s.current?.focus()},S=t=>{if(t.key===`ArrowDown`||t.key===`ArrowUp`)t.preventDefault(),d(e=>Oj(e,f.length,t.key===`ArrowDown`?1:-1));else if(t.key===`Enter`){let e=f[u]??f[0];if(!e)return;t.preventDefault(),b(e.href)}else t.key===`Escape`&&(e.text?e.onTextChange(``):t.currentTarget.blur(),d(-1))},C=-1;return(0,q.jsxs)(`div`,{ref:h,className:U(`relative`,t),children:[(0,q.jsx)(bi,{ref:y,wrapperClassName:U(`w-full bg-surface shadow-none`,n),leading:e.loading?(0,q.jsx)(wn,{className:`size-4`}):(0,q.jsx)(id,{className:`size-4`}),trailing:e.text?(0,q.jsx)(`button`,{type:`button`,"aria-label":Wr(`clearSearch`),className:`-mr-1 inline-flex size-6 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-muted hover:text-foreground`,onMouseDown:e=>e.preventDefault(),onClick:x,children:(0,q.jsx)(Ci,{className:`size-3.5`})}):i?(0,q.jsx)(`span`,{className:`hidden md:inline-flex`,children:(0,q.jsx)(Dj,{children:`⌘K`})}):void 0,placeholder:e.placeholder,"aria-label":Wr(`globalSearch`),role:`combobox`,"aria-autocomplete":`list`,"aria-expanded":p,"aria-controls":o,"aria-activedescendant":p&&f[u]?m(u):void 0,autoFocus:r,value:e.text,onChange:t=>{e.onTextChange(t.target.value),d(-1)},onFocus:()=>l(!0),onBlur:()=>l(!1),onKeyDown:S}),p&&(0,q.jsxs)(`div`,{ref:g,id:o,role:`listbox`,"aria-label":Wr(`searchResults`),style:{..._,...v},className:`absolute right-0 top-full z-40 mt-1 max-h-96 w-full min-w-72 overflow-y-auto rounded-lg border bg-background py-1 shadow-pop`,children:[e.groups.length===0&&(0,q.jsx)(`p`,{className:`px-3 py-2 text-muted-foreground`,children:e.loading?Wr(`searching`):Wr(`noMatches`,{query:e.query})}),e.groups.map(e=>(0,q.jsxs)(`div`,{role:`group`,"aria-label":e.label,children:[(0,q.jsx)(`div`,{className:`px-3 pb-1 pt-2 text-[0.6875rem] font-medium uppercase tracking-wide text-faint-foreground`,children:e.label}),e.failed&&(0,q.jsx)(`p`,{className:`px-3 py-1.5 text-danger-text`,children:Wr(`couldNotSearch`,{label:e.label})}),e.hits.map(e=>{C+=1;let t=C;return(0,q.jsxs)(`a`,{id:m(t),href:e.href,tabIndex:-1,role:`option`,"aria-selected":t===u,className:U(`block px-3 py-1.5`,t===u?`bg-primary-soft text-primary-text`:`hover:bg-muted`),onMouseDown:e=>e.preventDefault(),onClick:t=>{kj(t)||(t.preventDefault(),b(e.href))},onMouseEnter:()=>d(t),children:[(0,q.jsx)(`span`,{className:`block truncate font-semibold`,children:e.title}),e.subtitle&&(0,q.jsx)(`span`,{className:U(`block truncate text-xs`,t===u?`text-primary-text/80`:`text-muted-foreground`),children:e.subtitle})]},e.id)})]},e.id))]})]})},jj=`inline-flex size-[min(2.75rem,max(44px,13vw))] shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-muted md:hidden [&_svg]:size-[min(1.25rem,max(20px,6vw))]`,Mj=`max-h-[max(40px,calc(13vw-4px),calc(1.25em+2px))] text-body [&>input]:leading-[1.25] [&>svg]:size-[min(1rem,max(16px,6vw))] [&>button]:size-[min(1.5rem,max(24px,9vw))] [&>button>svg]:size-[min(0.875rem,max(14px,5vw))]`,Nj=`inline-flex min-h-[min(2.75rem,max(44px,13vw))] min-w-0 items-center gap-[4px] rounded-md pr-[8px] pl-[12px] text-muted-foreground hover:bg-muted hover:text-foreground md:hidden [&_svg]:size-[min(1.25rem,max(20px,6vw))]`,Pj=({breadcrumb:e,titleStatus:t,onNavigate:n,onBack:r,actions:i,onMenu:a,menuOpen:o,menuControls:s,search:c,sticky:l,slotRef:u,ref:d})=>{let[f,p]=(0,W.useState)(!1),m=Ej(e),h=(0,W.useRef)(null);return(0,W.useLayoutEffect)(()=>{if(!c)return;let e=e=>{if(e.key.toLowerCase()!==`k`||!(e.metaKey||e.ctrlKey))return;e.preventDefault();let t=h.current;t&&t.offsetParent!==null?t.focus():p(!0)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[c]),(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`header`,{ref:d,className:U(l?`sticky top-0 z-30 max-md:fixed max-md:left-[var(--pb-safe-left)] max-md:right-[var(--pb-safe-right)]`:`relative`,`flex shrink-0 items-center gap-[4px] border-b bg-background pt-[calc(var(--pb-safe-top)+1.5px)] pr-[8px] pb-[1.5px] pl-[16px] md:h-[calc(3rem+var(--pb-safe-top))] md:gap-4 md:px-5 md:pt-[var(--pb-safe-top)] md:pb-0`),children:[a&&(0,q.jsx)(`button`,{type:`button`,"aria-label":Wr(`openNavigation`),"aria-expanded":!!o,"aria-controls":s,onClick:a,className:U(`inline-flex size-[min(2.75rem,max(44px,13vw))] shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-muted md:hidden [&_svg]:size-[min(1.25rem,max(20px,6vw))]`,`-ml-[12px]`),children:(0,q.jsx)(uu,{})}),m&&(0,q.jsxs)(`a`,{href:m.href,"aria-label":Wr(`backTo`,{label:m.label}),onClick:e=>{let t=r??n;t&&nr(e)&&(e.preventDefault(),t(m.href))},className:U(m.shown?Nj:`inline-flex size-[min(2.75rem,max(44px,13vw))] shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-muted md:hidden [&_svg]:size-[min(1.25rem,max(20px,6vw))]`,!a&&`-ml-[12px]`),children:[(0,q.jsx)(wc,{className:`shrink-0`,"aria-hidden":!0}),m.shown&&(0,q.jsx)(`span`,{className:`truncate`,children:m.label})]}),(0,q.jsx)(Xn,{parts:e,onNavigate:n}),t&&(0,q.jsx)(`span`,{className:`flex shrink-0 items-center`,children:t}),(0,q.jsxs)(`div`,{className:`ml-auto flex items-center gap-[4px] md:gap-3`,children:[c&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`div`,{className:`hidden md:block`,children:(0,q.jsx)(Aj,{ref:h,search:c})}),(0,q.jsx)(`button`,{type:`button`,"aria-label":Wr(`search`),"aria-expanded":f,onClick:()=>p(!0),className:`inline-flex size-[min(2.75rem,max(44px,13vw))] shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-muted md:hidden [&_svg]:size-[min(1.25rem,max(20px,6vw))]`,children:(0,q.jsx)(id,{})})]}),i,(0,q.jsx)(`div`,{ref:u,className:`contents md:hidden`})]}),c&&f&&(0,q.jsxs)(`div`,{className:`absolute inset-0 z-20 flex items-center gap-[4px] bg-background px-[12px] pt-[var(--pb-safe-top)] md:hidden`,children:[(0,q.jsx)(Aj,{className:`min-w-0 flex-1`,fieldClassName:Mj,autoFocus:!0,showShortcut:!1,search:{...c,onSelect:e=>{c.onSelect(e),p(!1)}}}),(0,q.jsx)(`button`,{type:`button`,"aria-label":Wr(`closeSearch`),onClick:()=>p(!1),className:`inline-flex size-[min(2.75rem,max(44px,13vw))] shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-muted md:hidden [&_svg]:size-[min(1.25rem,max(20px,6vw))]`,children:(0,q.jsx)(Ci,{})})]})]}),l&&(0,q.jsx)(`div`,{"aria-hidden":!0,className:`h-[var(--pb-sticky-top)] shrink-0 md:hidden`})]})},Fj=`app-drawer`,Ij={refreshing:`[animation:pb-stale_1.4s_ease-in-out_infinite] motion-reduce:[animation:none] motion-reduce:opacity-60`,failed:`opacity-60`},Lj=({sidebarMode:e,activeItem:t,breadcrumb:n,titleStatus:r,staleContent:i,user:a,workspace:o,appName:s,appIcon:c,logo:l,actions:u,rightPanel:d,sidebarNotice:f,banner:p,forceExpanded:m,profileMenuOpen:g,navGroups:_,userMenu:v,account:y,bottomBar:b,onNavigate:x,onBack:S,onSignOut:C,signIn:w,organizations:T,roles:E,theme:D,status:O,search:k,pageScroll:ee=!1,className:A,children:te})=>{let ne=h(),re=Cj(e),[j,ie]=(0,W.useState)(!1);(0,W.useEffect)(()=>{ne&&ie(!1)},[ne]);let M=!ne&&b&&b.length>0?b:void 0,[ae,oe]=(0,W.useState)(),se=ae??ee,ce=(0,W.useRef)(null),[le,ue]=(0,W.useState)(null),de=(0,W.useRef)(null);jA(se,ce,de,!!M),kA(se);let fe=e=>(0,q.jsx)(Sj,{...e,activeItem:t,user:a,workspace:o,appName:s,appIcon:c,forceExpanded:m,profileMenuOpen:g,groups:_,userMenu:v,account:y,onNavigate:x,onSignOut:C,signIn:w,organizations:T,roles:E,theme:D,status:O,logo:l});return(0,q.jsx)(DA.Provider,{value:oe,children:(0,q.jsxs)(`div`,{className:U(se?`flex min-h-full w-full overflow-x-clip bg-background`:`relative flex h-full min-h-0 w-full overflow-hidden bg-background`,A),children:[ne?fe({mode:e,sticky:se,notice:re&&f}):(0,q.jsx)(EA,{id:Fj,open:j,onClose:()=>ie(!1),children:fe({mode:`text-large`,fill:!0})}),(0,q.jsxs)(`div`,{className:U(`flex min-w-0 flex-1 flex-col`,!M&&`pb-[var(--pb-safe-bottom)]`),children:[(0,q.jsx)(Pj,{ref:ce,slotRef:ue,sticky:se,breadcrumb:n,titleStatus:r,onNavigate:x,onBack:S,actions:u,onMenu:ne||M?void 0:()=>ie(!0),menuOpen:j,menuControls:Fj,search:k}),p,(0,q.jsx)(`main`,{className:U(se?`flex flex-1 flex-col`:`flex min-h-0 flex-1 flex-col`,i&&Ij[i]),"aria-busy":i===`refreshing`||void 0,children:(0,q.jsx)(wj.Provider,{value:le,children:te})}),M&&(0,q.jsx)(TA,{ref:de,sticky:se,tabs:M,onNavigate:x,onMore:()=>ie(!0),moreOpen:j,moreControls:Fj})]}),d&&(0,q.jsx)(`div`,{className:se?`sticky top-0 flex h-dvh shrink-0 self-start pt-[var(--pb-safe-top)]`:`flex shrink-0`,children:d})]})})},Rj=({title:e,subtitle:t,actions:n,subtitleBelow:r})=>r?(0,q.jsx)(zj,{title:e,subtitle:t,actions:n}):(0,q.jsxs)(`div`,{className:`flex flex-col gap-x-4 gap-y-2 md:flex-row md:items-end md:justify-between`,children:[(0,q.jsxs)(`div`,{className:`min-w-0 break-words md:flex-1`,children:[(0,q.jsx)(`h1`,{className:`text-xl font-semibold tracking-tight`,children:e}),t&&(0,q.jsx)(`p`,{className:`text-muted-foreground`,children:t})]}),n&&(0,q.jsx)(`div`,{className:`flex flex-wrap items-center gap-2 md:justify-end`,children:n})]}),zj=({title:e,subtitle:t,actions:n})=>(0,q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-x-4 gap-y-2 md:flex-nowrap`,children:[(0,q.jsx)(`h1`,{className:`min-w-0 break-words text-xl font-semibold tracking-tight md:flex-1`,children:e}),n&&(0,q.jsx)(`div`,{className:`flex flex-wrap items-center gap-2 md:justify-end`,children:n})]}),t&&(0,q.jsx)(`p`,{className:`break-words text-muted-foreground`,children:t})]}),Bj=({node:e,children:t,slots:n,className:r})=>{let{title:i,description:a,width:o}=xT(e);return(0,q.jsx)(`div`,{className:U(`flex-1`,r),children:(0,q.jsxs)(`div`,{className:U(`flex flex-col gap-6 px-4 pb-16 pt-6 md:px-10 md:py-8`,o!==`full`&&`mx-auto max-w-[1200px]`),children:[(0,q.jsx)(Rj,{title:i,subtitle:a,actions:n.actions}),t]})})},Vj=(e,t)=>{let n=tT(),r=typeof e==`string`?oT(n,e):void 0,i=qT(r&&`frame`in r?r.frame:void 0,r&&`path`in r?r.path:``);return typeof e==`number`?e:e===void 0?t:r&&`item`in r?Number(r.item):i.state===`ready`?Number(i.value):i.state===`loading`?void 0:NaN},Hj=({node:e,className:t})=>{let{value:n,max:r,label:i}=xT(e),a=Vj(n,0),o=Vj(r,100);if(a===void 0||o===void 0)return(0,q.jsx)(L,{className:`h-6 w-full`});if(!Number.isFinite(a)||!Number.isFinite(o))return null;let s=o>0?Math.min(1,Math.max(0,a/o)):0;return(0,q.jsxs)(`div`,{className:U(`min-w-0`,t),children:[(0,q.jsxs)(`div`,{className:`flex items-baseline justify-between gap-2 text-body`,children:[(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:i}),(0,q.jsxs)(`span`,{className:`tabular-nums`,children:[a.toLocaleString(ci()),` / `,o.toLocaleString(ci())]})]}),(0,q.jsx)(`div`,{role:`progressbar`,"aria-label":i,"aria-valuenow":a,"aria-valuemin":0,"aria-valuemax":o,className:`mt-1.5 h-2 overflow-hidden rounded-full bg-muted`,children:(0,q.jsx)(`div`,{className:s>=.9?`h-full rounded-full bg-warning`:`h-full rounded-full bg-primary`,style:{width:`${s*100}%`}})})]})},Uj=({model:e,at:t,filter:n,sort:r,recordKey:i,title:a,description:o,empty:s,actions:c,children:l,className:u})=>{let d=mE(t),f=Zr(e,{filter:n,sort:r,key:i,enabled:!d}),p=d?$r(e,d):f,m=e=>p.data?(0,q.jsx)(Zw,{value:p.data,children:e}):void 0,h=p.isPending?(0,q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,q.jsx)(L,{className:`h-4 w-1/2`}),(0,q.jsx)(L,{className:`h-4 w-1/3`})]}):p.error?(0,q.jsx)(Oy,{title:z(`couldNotLoad`),error:p.error}):p.data?m((0,q.jsx)(`div`,{className:`flex flex-col gap-3`,children:l})):(0,q.jsx)(Uw,{children:s??z(`nothingYet`)});return(0,q.jsx)(Hw,{title:a,description:o,actions:c?m(c):void 0,className:U(`h-full`,u),children:h})},Wj=({node:e,at:t,children:n,slots:r,className:i})=>{let{resource:a,filter:o,sort:s,recordKey:l,title:u,description:d,empty:f}=xT(e),p=c().resources[a];return p?(0,q.jsx)(Uj,{model:p,...t!==void 0&&{at:t},filter:o,sort:s,recordKey:l,title:u,description:d,empty:f,actions:r.actions,className:i,children:n}):null},Gj=`0.75rem`,Kj=e=>{if(!(e>0&&e<=1))throw Error(`An item's share of a row is above 0 and at most 1, not ${e}`);return`calc((100% + ${Gj}) * ${e} - ${Gj})`},qj=e=>e===void 0?{width:`min(256px, 100%)`,minWidth:`0px`}:{width:Kj(e),minWidth:`min(100%, 12rem)`},Jj=`absolute top-1/2 z-10 hidden size-8 -translate-y-1/2 items-center justify-center rounded-full border border-border-strong bg-background shadow-pop hover:bg-muted sm:flex`,Yj=({scroll:e,label:t,share:n,children:r})=>{let i=qj(n);return(0,q.jsxs)(`div`,{className:`relative min-w-0`,children:[(0,q.jsx)(`ul`,{ref:e.ref,"aria-label":t,className:`relative flex snap-x snap-mandatory overflow-x-auto overflow-y-hidden overscroll-x-contain pb-1 *:w-(--snap-item-width) *:min-w-(--snap-item-min-width) *:shrink-0 *:snap-start`,style:{gap:Gj,scrollbarWidth:`thin`,"--snap-item-width":i.width,"--snap-item-min-width":i.minWidth},children:r}),e.back&&(0,q.jsx)(`button`,{type:`button`,"aria-label":yn(`previous`,{label:t.toLowerCase()}),onClick:()=>e.page(-1),className:`${Jj} -left-3`,children:(0,q.jsx)(wc,{className:`size-4`,"aria-hidden":!0})}),e.on&&(0,q.jsx)(`button`,{type:`button`,"aria-label":yn(`next`,{label:t.toLowerCase()}),onClick:()=>e.page(1),className:`${Jj} -right-3`,children:(0,q.jsx)(qn,{className:`size-4`,"aria-hidden":!0})})]})},Xj=(e,t)=>{let n={left:e.scrollLeft,width:e.clientWidth};return{...n,back:n.left>0,on:n.left+n.width<e.scrollWidth-1,watched:t(n)}},Zj=(e,t)=>e.width===t.width&&e.back===t.back&&e.on===t.on&&e.watched===t.watched,Qj=(e=()=>``)=>{let[t,n]=(0,W.useState)(null),[r,i]=(0,W.useState)({left:0,width:0,back:!1,on:!1,watched:``}),a=()=>{if(!t)return;let n=Xj(t,e);i(e=>Zj(e,n)?e:n)},o=(0,W.useRef)(a);return(0,W.useLayoutEffect)(()=>{o.current=a,a()}),(0,W.useLayoutEffect)(()=>{if(!t)return;let e=()=>o.current(),n=new ResizeObserver(e);return n.observe(t),t.addEventListener(`scroll`,e,{passive:!0}),()=>{n.disconnect(),t.removeEventListener(`scroll`,e)}},[t]),{ref:n,view:{left:r.left,width:r.width},back:r.back,on:r.on,page:e=>{if(!t)return;let n=parseFloat(getComputedStyle(t).columnGap)||0;t.scrollBy({left:e*Math.max(1,t.clientWidth-n),behavior:`smooth`})}}},$j=B(`app/embedded-list`),eM=(e,t,n)=>{if(!(e>=t))return $j(n?`firstOfAbout`:`firstOf`,{shown:e,total:t.toLocaleString(ci())})},tM=`protobase:embedded-display:`,nM=e=>`${tM}${e}`,rM=(e,t)=>i(()=>e.getItem(t)??void 0,void 0),iM=(e,t,n)=>i(()=>e.setItem(t,n),void 0),aM=(e,t,{picked:n,preferred:r})=>{let i=_e(e).map(e=>e.name);return n!==void 0&&i.includes(n)?n:me(e,t,r!==void 0&&i.includes(r)?r:void 0)},oM=(e,t,n,{resource:r=e.name,...i})=>ze({kind:`list`,resource:r},i,{...Ce(e,t,n),display:me(t,n)}),sM=e=>e.total??Number(e.rows[0]?.count??0),cM=e=>e==null||e===``,lM=e=>typeof e==`string`&&URL.canParse(e)&&new URL(e).protocol===`https:`?new URL(e).href:void 0,uM=e=>typeof e==`number`||typeof e==`boolean`||typeof e==`string`&&/^(-?\d+(\.\d+)?|true|false)$/.test(e),dM=(e,t)=>{if(e.kind!==`list`||e.filter===void 0)return!1;let n=Object.hasOwn(t,e.resource)?t[e.resource]:void 0;if(!n)return!1;let r=Te(e.filter);return!r.ok||!r.ast?!1:s(n,r.ast).ok},fM=(e,t,n,r,i)=>{let a=ve(e).find(e=>!he(e).some(e=>cM(r[e])));if(!a)return;let o=cr(a.label,e=>{let i=t.fields[e];return i?Lr(i,r[e],n?.fields[e]):String(r[e])}),s=je(a);if(`href`in s){let e=lM(r[Vn(s.href)??``]);return e===void 0?void 0:{label:o,href:e}}if(ur(s.to)!==void 0){let e=Mr(s.to,r);return dM(e,i)?{label:o,to:e}:void 0}if(Kn(s.to).every(e=>uM(r[e])))return{label:o,to:Mr(s.to,r)}},pM=({button:e,model:t,view:n,record:r,models:i})=>{let a=fM(e,t,n,r,i);if(!a)return null;let o=U(zn({variant:`secondary`,size:`sm`}),`min-w-0 max-w-full shrink`),s=(0,q.jsx)(`span`,{className:`truncate`,children:a.label});return`href`in a?(0,q.jsxs)(`a`,{href:a.href,target:`_blank`,rel:`noreferrer`,title:a.label,className:o,children:[s,(0,q.jsxs)(`span`,{className:`sr-only`,children:[` `,R(`opensNewTab`)]}),(0,q.jsx)(ol,{"aria-hidden":!0,className:`size-3.5 shrink-0`})]}):(0,q.jsx)(Ue,{to:a.to,title:a.label,className:o,children:s})},mM=B(`app/related-cards`),hM=({children:e})=>{let t=(0,W.useRef)(null),[n,r]=(0,W.useState)(!1),[i,a]=(0,W.useState)(!1);return(0,W.useLayoutEffect)(()=>{let e=t.current;if(!e)return;let n=()=>a(e.scrollHeight>e.parentElement.clientHeight+1);n();let r=new ResizeObserver(n);return r.observe(e),()=>r.disconnect()},[n]),(0,q.jsxs)(`div`,{className:`flex flex-col items-start gap-1`,children:[(0,q.jsx)(`div`,{className:U(`w-full min-w-0`,!n&&`max-h-40 overflow-hidden`),children:(0,q.jsx)(`div`,{ref:t,children:e})}),(i||n)&&(0,q.jsx)(P,{size:`sm`,variant:`ghost`,className:`-ml-2`,"aria-expanded":n,onClick:()=>r(!n),children:mM(n?`showLess`:`showMore`)})]})},gM=e=>e==null||e===``,_M=({scope:e,path:t,labelled:n=!0,clamped:r=!1})=>{let{views:i}=c(),a=qT(e,t);if(a.state===`missing`||a.state===`ready`&&gM(a.value))return null;let o=a.state===`loading`?(0,q.jsx)(L,{className:`h-4 w-24`}):(0,q.jsx)(vC,{model:a.model,field:a.field,value:a.value}),s=r?(0,q.jsx)(hM,{children:o}):o;if(!n)return(0,q.jsx)(`div`,{className:`min-w-0`,children:s});let l=Ek(t,a.state===`ready`?i[a.model.name]?.fields[a.field.name]?.label:void 0);return(0,q.jsxs)(`div`,{className:`min-w-0`,children:[(0,q.jsx)(`dt`,{className:`text-body text-muted-foreground`,children:l}),(0,q.jsx)(`dd`,{className:`mt-0.5`,children:s})]})},vM=(e,t)=>{let n=Jr(e,t);return n===void 0?{className:ji[ei(e,t)]}:{style:{backgroundColor:n}}},yM=({view:e,field:t,record:n})=>{let r=vM(e?.fields[t]?.valueColors,n[t]);return(0,q.jsx)(`span`,{"aria-hidden":!0,"data-tone-edge":!0,style:r.style,className:U(`absolute -inset-y-px -left-px w-1 rounded-l-lg`,r.className)})},bM=({scope:e,view:t,fields:n,time:r,tone:i,actions:a,button:o,onActed:s})=>{let l=Qy(),{resources:u}=c(),d=l(e.model,t,e.record,e.key),f=a.length>0||o!==void 0;return(0,q.jsxs)(`li`,{"data-card":e.key,className:U(`relative grid min-w-0 items-center gap-x-4 gap-y-1 rounded-lg border border-border bg-surface px-4 py-2.5`,f?`grid-cols-[minmax(0,1fr)_auto]`:`grid-cols-[minmax(0,1fr)]`),children:[i&&(0,q.jsx)(yM,{view:t,field:i,record:e.record}),(0,q.jsxs)(`div`,{className:U(`flex min-w-0 items-baseline gap-2`,f&&`col-span-2 sm:col-span-1`),children:[(0,q.jsx)(Ue,{to:{kind:`record`,resource:e.model.name,key:xr(e.model,e.record)},className:`line-clamp-2 min-w-0 font-medium [overflow-wrap:anywhere] text-primary-text hover:underline`,children:d}),r&&(0,q.jsx)(`div`,{className:`ml-auto shrink-0 text-body whitespace-nowrap text-muted-foreground empty:hidden`,children:(0,q.jsx)(_M,{scope:e,path:r,labelled:!1})})]}),n.length>0&&(0,q.jsx)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-y-0.5 text-body text-muted-foreground`,children:n.map(t=>(0,q.jsx)(`div`,{className:`flex max-w-full min-w-0 items-center whitespace-nowrap empty:hidden [&>div]:truncate [:not(:empty)~&]:before:mx-2 [:not(:empty)~&]:before:content-['·'_/_'']`,children:(0,q.jsx)(_M,{scope:e,path:t,labelled:!1})},t))}),f&&(0,q.jsx)(Zw,{value:e,children:(0,q.jsxs)(`div`,{className:`col-start-2 flex flex-wrap items-center justify-end gap-2 sm:row-span-2 sm:row-start-1`,children:[o&&(0,q.jsx)(pM,{button:o,model:e.model,view:t,record:e.record,models:u}),a.map(e=>(0,q.jsx)(wT,{name:e,about:d,onRun:e=>s?.(e,d)},e))]})})]})},xM=({scope:e,view:t,fields:n,tone:r,actions:i,button:a,onActed:o})=>{let s=Qy(),{resources:l}=c(),u=s(e.model,t,e.record,e.key);return(0,q.jsxs)(`li`,{"data-card":e.key,className:`relative flex min-w-0 flex-col gap-3 rounded-lg border border-border bg-surface p-4`,children:[r&&(0,q.jsx)(yM,{view:t,field:r,record:e.record}),(0,q.jsx)(Ue,{to:{kind:`record`,resource:e.model.name,key:xr(e.model,e.record)},className:`self-start font-medium text-primary-text hover:underline`,children:u}),n.length>0&&(0,q.jsx)(`dl`,{className:`flex flex-col gap-3`,children:n.map(t=>(0,q.jsx)(_M,{scope:e,path:t,clamped:!0},t))}),(i.length>0||a)&&(0,q.jsx)(Zw,{value:e,children:(0,q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[a&&(0,q.jsx)(pM,{button:a,model:e.model,view:t,record:e.record,models:l}),i.map(e=>(0,q.jsx)(wT,{name:e,about:u,onRun:e=>o?.(e,u)},e))]})})]})},SM=e=>!e.disabled&&e.getAttribute(`aria-disabled`)!==`true`,CM=e=>[...e.querySelectorAll(`button`)].find(SM)??e.querySelector(`a`),wM=(e,t,n)=>{let r=e.indexOf(n),i=e=>t.includes(e);return e.slice(r+1).find(i)??e.slice(0,Math.max(r,0)).findLast(i)},TM=e=>{let t=e.closest(`section`)?.querySelector(`h2`);return t&&!t.hasAttribute(`tabindex`)&&(t.tabIndex=-1),t},EM=e=>{let t=(0,W.useRef)(null),n=(0,W.useRef)({current:e,previous:e}),r=(0,W.useRef)(void 0),[i,a]=(0,W.useState)(``),o=(e,n,i)=>{if(r.current=void 0,i.includes(e.key)||!t.current||(a(mM(`left`,{action:e.action,title:e.title})),document.activeElement&&document.activeElement!==document.body))return;let o=wM(n,i,e.key),s=o===void 0?void 0:t.current.querySelector(`[data-card="${CSS.escape(o)}"]`);(s?CM(s):TM(t.current))?.focus()};return(0,W.useEffect)(()=>{let t=n.current.current;n.current={current:e,previous:t},r.current&&o(r.current,t,e)},[e]),{root:t,acted:(e,t,i)=>{let{current:a,previous:s}=n.current;if(a.includes(e)){r.current={key:e,action:t,title:i};return}o({key:e,action:t,title:i},s,a)},announcement:i}},DM=({compact:e,limit:t})=>(0,q.jsx)(`div`,{className:e?`flex flex-col gap-2`:`flex flex-col gap-3`,children:Array.from({length:e?Math.min(t,3):2},(t,n)=>(0,q.jsx)(L,{className:e?`h-17.5 w-full max-sm:h-24`:`h-24 w-full`},n))}),OM=({model:e,view:t,filter:n,sort:r,fields:i,actions:a,button:o,limit:s,display:c,empty:l,carousel:u,compact:d,tone:f,planned:p})=>{let m=v(),h=Qj(),g=t?.names?.plural??H(e.name),_=r||Pe(e,t),y=ii(e,{filter:n,sort:_,pageSize:s,enabled:!p}),b=Kr(e,n,!p),x=p?p.rows:{isPending:y.isPending,error:y.error},S=p?p.rows.rows:y.data?.items,C=p?{data:p.total&&!p.total.isPending&&!p.total.error?sM(p.total):void 0}:b,w=(0,W.useMemo)(()=>(S??[]).map(t=>ni(e,t)),[e,S]),T=EM((0,W.useMemo)(()=>w.map(e=>e.key),[w]));return(0,q.jsxs)(`div`,{ref:T.root,children:[(()=>{if(x.isPending)return(0,q.jsx)(DM,{compact:!!d,limit:s});if(x.error)return(0,q.jsx)(Oy,{title:mM(`couldNotLoad`),error:x.error});if(w.length===0)return(0,q.jsx)(`p`,{className:`text-muted-foreground`,children:l??mM(`nothingYet`)});let r=w.map(e=>{let n=(t,n)=>T.acted(e.key,t,n);return d?(0,q.jsx)(bM,{scope:e,view:t,fields:i,time:d.time,tone:f,actions:a,button:o,onActed:n},e.key):(0,q.jsx)(xM,{scope:e,view:t,fields:i,tone:f,actions:a,button:o,onActed:n},e.key)}),p=C.data===void 0?void 0:eM(w.length,C.data,!1);return(0,q.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[u===void 0?(0,q.jsx)(`ul`,{className:d?`flex flex-col gap-2`:`flex flex-col gap-3`,children:r}):(0,q.jsx)(Yj,{scroll:h,label:g,share:u,children:r}),(0,q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:p}),(0,q.jsxs)(Ue,{to:oM(e,t,m,{filter:n,orderBy:_,display:aM(t,m,{preferred:c})}),className:`flex items-center gap-1 font-medium text-primary-text hover:underline`,children:[$j(`viewAll`),` `,(0,q.jsx)(`span`,{className:`sr-only`,children:g.toLowerCase()}),(0,q.jsx)(Is,{className:`size-3.5`,"aria-hidden":!0})]})]})]})})(),(0,q.jsx)(`p`,{role:`status`,className:`sr-only`,children:T.announcement})]})},kM={"1/4":1/4,"1/3":1/3,"1/2":1/2,"2/3":2/3},AM=({node:e,at:t,slots:n,className:r})=>{let i=xT(e),{resource:a,filter:o=``,sort:s=``,fields:l,cardActions:u=[],limit:d=10,display:f,title:p,description:m,empty:h}=i,{layout:g,cardWidth:_}=Om(i),{resources:v,views:y}=c(),[b,x]=hE([t,t===void 0?void 0:`${t}#total`]),S=(0,W.useMemo)(()=>b&&{rows:b,total:x},[b,x]),C=v[a];if(!C)return null;let w=y[C.name];return(0,q.jsx)(`section`,{className:U(`min-w-0`,r),"aria-label":p,children:(0,q.jsx)(E_,{title:p,help:m,actions:n.actions,children:(0,q.jsx)(OM,{model:C,view:w,filter:o,sort:s,fields:l??He(C,w),actions:u,limit:d,display:f,empty:h,carousel:g===`carousel`?kM[_]:void 0,...S&&{planned:S}})})})},jM=fn({rowSortingFeature:bt,rowSelectionFeature:at}),MM=St(),NM=e=>MM.columns(e.map(e=>MM.accessor(t=>e.value?e.value(t):t[e.id],{id:e.id,header:e.header,enableSorting:e.sortable??!1,cell:t=>e.render?e.render(t.row.original):RT(e,t.getValue(),t.row.original)}))),PM=(e,t)=>e.flatMap(e=>{let n=e.available?t.filter(e.available):t;return n.length===0?[]:[{action:e,rows:n,skipped:t.length-n.length}]}),FM=async(e,t,n)=>{let r=await e.onRun(t,n);if(!r)return t;let i=new Set(r.map(e=>e.id));return t.filter(e=>!i.has(e.id))},IM=()=>{let e=!1;return async(t,n,r)=>{if(!e){e=!0;try{return await FM(t,n,r)}finally{e=!1}}}},LM=({total:e,selectedCount:t,bulkActions:n=[],className:r})=>(0,q.jsx)(`div`,{className:U(`flex h-9 shrink-0 items-center border-t bg-surface px-3 text-xs text-muted-foreground`,r),children:(0,q.jsxs)(`span`,{className:`flex items-center tabular-nums`,children:[M_(e),t>0&&(0,q.jsx)(`span`,{className:`ml-3 font-medium text-primary-text`,children:F_(`selected`,{count:k_(t)})}),t>0&&n.map(e=>(0,q.jsx)(`button`,{type:`button`,onClick:e.onRun,className:U(`ml-3 rounded border bg-background px-2 py-0.5 font-medium hover:bg-muted`,e.destructive?`border-danger/40 text-danger-text`:`text-foreground`),children:e.label},e.label))]})}),RM=(e,t)=>typeof e.label==`string`?e.label:e.label(t),zM=(e,t)=>e.filter(e=>e.available?.(t)??!0),BM=({row:e,actions:t})=>{let{open:n,setOpen:r,place:i,button:a,menu:o}=Gv();return(0,q.jsxs)(`div`,{className:`relative flex justify-center bg-inherit`,onClick:e=>e.stopPropagation(),children:[(0,q.jsx)(`button`,{ref:a,type:`button`,"aria-label":F_(`rowActions`),"aria-haspopup":`menu`,"aria-expanded":n,onClick:()=>r(!n),className:`inline-flex items-center justify-center rounded p-1 text-faint-foreground hover:bg-muted hover:text-foreground pointer-coarse:size-11`,children:(0,q.jsx)(il,{className:`size-4`})}),n&&(0,ls.createPortal)((0,q.jsx)(`ul`,{ref:o,role:`menu`,onClick:e=>e.stopPropagation(),style:i??{visibility:`hidden`},className:`fixed z-50 min-w-36 rounded-md border bg-background py-1 shadow-pop`,children:t.map((t,n)=>{let i=RM(t,e),a=t.blocked?.(e),o=U(`block w-full px-3 py-1.5 text-left hover:bg-muted disabled:cursor-default disabled:opacity-60 disabled:hover:bg-transparent`,t.destructive&&`text-danger-text`);return(0,q.jsx)(`li`,{role:`none`,children:t.link&&a===void 0?(0,q.jsx)(Jn,{role:`menuitem`,to:t.link(e),onClick:()=>r(!1),className:o,children:i}):(0,q.jsx)(`button`,{type:`button`,role:`menuitem`,disabled:a!==void 0,title:a,className:o,onClick:()=>{r(!1),t.onSelect?.(e)},children:i})},n)})}),document.body)]})},VM=e=>52+Math.ceil(String(e).length*1.33)*7,HM=.6,UM=(e,t)=>Math.max(e.minWidth??0,e.width*t),WM=(e,t)=>e.fixed?`${Math.max(e.minWidth??0,e.width)}px`:`minmax(${UM(e,t)}px, ${e.width}fr)`,GM=(e,t,n=0,r=HM)=>`${t}px ${e.map(e=>WM(e,r)).join(` `)}${n>0?` ${n}px`:``}`,KM=(e,t,n=0,r=HM)=>t+n+e.reduce((e,t)=>e+(t.fixed?Math.max(t.minWidth??0,t.width):UM(t,r)),0),qM=()=>{let e=(0,W.useRef)(null),t=(0,W.useRef)(null),[n,r]=(0,W.useState)({scrolled:!1,more:!1}),i=(0,W.useCallback)(()=>{let t=e.current;if(!t)return;let n={scrolled:t.scrollLeft>1,more:t.scrollLeft+t.clientWidth<t.scrollWidth-1};r(e=>e.scrolled===n.scrolled&&e.more===n.more?e:n)},[]);return{ref:e,attach:(0,W.useCallback)(n=>{if(t.current?.disconnect(),t.current=null,e.current=n,!n)return;let r=new ResizeObserver(i);r.observe(n);for(let e of Array.from(n.children))r.observe(e);t.current=r,i()},[i]),onScroll:i,...n}},JM=`protobase:pinned:`,YM=(e,t)=>`${JM}${e}:${t}`,XM=(e,t)=>i(()=>{let n=e.getItem(t);if(n===null)return;let r=JSON.parse(n);return Array.isArray(r)&&r.every(e=>typeof e==`string`)?r:void 0},void 0),ZM=(e,t,n)=>i(()=>e.setItem(t,JSON.stringify(n)),void 0),QM=(e,t=[])=>{let[n,r]=(0,W.useState)(()=>e?XM(localStorage,e):void 0),i=(0,W.useCallback)(t=>{r(t),e&&ZM(localStorage,e,t)},[e]);return[n??t,i]},$M=e=>{let t=e.findIndex(e=>e.title);return t<0||t>1?[]:e.slice(0,t+1).map(e=>e.id)},eN=e=>Object.fromEntries(e.map(({id:e,width:t,minWidth:n,fixed:r})=>[e,{width:t,minWidth:n,fixed:r}])),tN=e=>e.map(({id:e,minWidth:t,maxWidth:n})=>`${e}:${t??``}:${n??``}`).sort().join(` `),nN=(e,t)=>{let n=tN(e),[r,i]=(0,W.useState)(),a=r?.key===n?r:void 0;!a&&t.length>0&&i({key:n,sizes:eN(ev(e,t))});let o=a?.sizes;return(0,W.useMemo)(()=>o?e.map(e=>({...e,...o[e.id]})):e,[e,o])},rN=(e,t)=>Math.max(Math.min(64,e),Math.round(e+t)),iN=(e,t)=>e.map(e=>e.id in t?{...e,fixed:!0,width:t[e.id],minWidth:void 0}:e),aN=e=>Object.fromEntries([...e.querySelectorAll(`[data-col-id]`)].map(e=>[e.dataset.colId,e.offsetWidth])),oN=e=>{let[t,n]=(0,W.useState)({}),r=()=>({...e.current?aN(e.current):{},...t});return{widths:t,onPointerDown:(e,t)=>{if(t.button!==0)return;t.preventDefault();let i=r(),a=t.clientX,o=t=>n({...i,[e]:rN(i[e]??0,t.clientX-a)}),s=()=>{window.removeEventListener(`pointermove`,o),window.removeEventListener(`pointerup`,s),window.removeEventListener(`pointercancel`,s)};window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,s),window.addEventListener(`pointercancel`,s)},onKeyDown:(e,t)=>{let i=t.key===`ArrowRight`?16:t.key===`ArrowLeft`?-16:0;if(i===0)return;t.preventDefault();let a=r();n({...a,[e]:rN(a[e]??0,i)})}}},sN=()=>parseFloat(getComputedStyle(document.documentElement).fontSize),cN=()=>(0,W.useSyncExternalStore)(e=>(window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)),sN,()=>16),lN=2,uN=2.25,dN=1.75,fN=2,pN=2.25,mN=(e,{compact:t,withBelow:n})=>({header:lN*e,row:((t?dN:uN)+(n?fN:0))*e,footer:pN*e}),hN=e=>e===`money`||e===`number`||e===`signed`||e===`percent`,gN=()=>F_(`unsortable`),_N=({header:e,pinned:t,sortable:n,onTogglePin:r})=>{let{open:i,setOpen:a,place:o,button:s,menu:c}=Gv();return(0,q.jsxs)(`div`,{className:`relative ml-auto shrink-0`,children:[(0,q.jsx)(`button`,{ref:s,type:`button`,"aria-label":F_(`columnMenu`,{header:e}),"aria-haspopup":`menu`,"aria-expanded":i,onClick:()=>a(!i),className:`relative inline-flex size-5 items-center justify-center rounded text-faint-foreground hover:bg-muted hover:text-foreground focus-visible:opacity-100 after:absolute after:-inset-2 after:content-[''] md:opacity-0 md:group-hover/cell:opacity-100 aria-expanded:opacity-100`,children:(0,q.jsx)(il,{className:`size-3.5`})}),i&&(0,ls.createPortal)((0,q.jsxs)(`ul`,{ref:c,role:`menu`,style:o??{visibility:`hidden`},className:`fixed z-50 min-w-32 rounded-md border bg-background py-1 text-body font-normal text-foreground shadow-pop`,children:[!n&&(0,q.jsx)(`li`,{role:`none`,children:(0,q.jsx)(`span`,{role:`menuitem`,"aria-disabled":`true`,className:`block min-h-9 whitespace-nowrap px-3 py-1.5 text-muted-foreground`,children:gN()})}),(0,q.jsx)(`li`,{role:`none`,children:(0,q.jsx)(`button`,{type:`button`,role:`menuitem`,className:`block min-h-9 w-full whitespace-nowrap px-3 py-1.5 text-left hover:bg-muted`,onClick:()=>{a(!1),r()},children:F_(t?`unpin`:`pinToLeft`)})})]}),document.body)]})},vN=({id:e,header:t,width:n,resize:r})=>(0,q.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":F_(`resizeColumn`,{header:t}),"aria-valuemin":64,"aria-valuenow":n,tabIndex:0,onPointerDown:t=>r.onPointerDown(e,t),onKeyDown:t=>r.onKeyDown(e,t),className:`group/resize absolute inset-y-0 right-0 z-10 flex w-2 cursor-col-resize touch-none justify-end outline-none`,children:(0,q.jsx)(`div`,{className:`h-full w-0.5 bg-transparent group-hover/resize:bg-primary group-focus-visible/resize:bg-primary group-active/resize:bg-primary`})}),yN=({sorted:e})=>e===`asc`?(0,q.jsx)(Hs,{className:`size-3 text-foreground`}):e===`desc`?(0,q.jsx)(As,{className:`size-3 text-foreground`}):(0,q.jsx)(Ec,{className:`size-3 opacity-0 group-hover/head:opacity-100`}),bN=({spec:e})=>(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`span`,{className:`truncate`,children:e.header}),e.highlight&&(0,q.jsx)(`span`,{className:`rounded bg-primary px-1 text-[0.625rem] font-semibold uppercase leading-4 text-primary-foreground`,children:F_(`new`)})]}),xN=({cells:e,specs:t,gutter:n,selectedCount:r,selectable:i,trailing:a,minScale:o,pins:s={},lastPinned:c,scrolled:l,onTogglePin:u,resize:d,widths:f={},onClearSelection:p})=>(0,q.jsxs)(`div`,{className:`grid h-8 shrink-0 items-center border-b bg-surface text-body font-medium text-muted-foreground`,style:{gridTemplateColumns:GM(t,n,a,o)},role:`row`,children:[(0,q.jsxs)(`div`,{className:U(`sticky left-0 z-10 flex h-full items-center gap-2 bg-inherit pl-3`,l&&!c&&`shadow-[1px_0_0_var(--border),4px_0_6px_-2px_rgb(0_0_0/0.12)]`),style:{width:n},children:[i&&(0,q.jsx)(Di,{checked:!1,indeterminate:r>0,label:F_(r>0?`clearSelection`:`noRowsSelected`),disabled:r===0,onChange:p,className:U(r===0&&`opacity-60`)}),n>40&&(0,q.jsx)(`span`,{className:`w-6 text-right text-faint-foreground`,children:`#`})]}),e.map(({spec:e,sorted:t,onSort:n})=>{let r=e.id in s;return(0,q.jsxs)(`div`,{"data-col-id":e.id,style:r?{left:s[e.id]}:void 0,className:U(`group/cell flex h-full min-w-0 items-center`,r?`sticky z-10 bg-inherit`:`relative`,r&&l&&e.id===c&&`shadow-[1px_0_0_var(--border),4px_0_6px_-2px_rgb(0_0_0/0.12)]`,e.highlight&&`bg-primary-soft text-primary-text`),children:[e.sortable?(0,q.jsxs)(`button`,{type:`button`,onClick:n,className:U(`group/head flex h-full min-w-0 flex-1 items-center gap-1 pl-3 pr-1 text-left`,hN(e.kind)&&`justify-end`,`hover:text-foreground`,t&&`text-foreground`),children:[(0,q.jsx)(bN,{spec:e}),(0,q.jsx)(yN,{sorted:t})]}):(0,q.jsx)(`div`,{title:gN(),className:U(`flex h-full min-w-0 flex-1 items-center gap-1 pl-3 pr-1 text-left`,hN(e.kind)&&`justify-end`),children:(0,q.jsx)(bN,{spec:e})}),(0,q.jsx)(`div`,{className:`pr-1.5`,children:(0,q.jsx)(_N,{header:e.header,pinned:r,sortable:!!e.sortable,onTogglePin:()=>u(e.id)})}),d&&(0,q.jsx)(vN,{id:e.id,header:e.header,width:f[e.id],resize:d})]},e.id)}),a?(0,q.jsx)(`div`,{className:`sticky right-0 z-10 h-full bg-inherit`}):null]}),SN=e=>({gridTemplateColumns:GM(e.specs,e.gutter,e.trailing,e.minScale),height:e.height,transform:`translateY(${e.offset}px)`}),CN=(e,t)=>U(`flex h-full min-w-0 items-center overflow-hidden whitespace-nowrap px-3`,hN(e.kind)&&`justify-end`,e.highlight&&`bg-primary-soft/60`,t.pins&&e.id in t.pins&&`sticky z-10 bg-inherit`,t.scrolled&&e.id===t.lastPinned&&`shadow-[1px_0_0_var(--border),4px_0_6px_-2px_rgb(0_0_0/0.12)]`),wN=(e,t)=>t&&e.id in t?{left:t[e.id]}:void 0,TN=({width:e,index:t,selectable:n,selected:r,onToggle:i,edge:a})=>(0,q.jsxs)(`div`,{onClick:n?e=>{e.stopPropagation(),i?.()}:void 0,className:U(`sticky left-0 z-10 flex h-full items-center gap-2 bg-inherit pl-3`,n&&`cursor-default`,a&&`shadow-[1px_0_0_var(--border),4px_0_6px_-2px_rgb(0_0_0/0.12)]`),style:{width:e},children:[n&&(0,q.jsx)(Di,{checked:!!r,label:F_(`selectRow`,{row:t+1})}),e>40&&(0,q.jsx)(`span`,{className:`min-w-6 text-right text-[0.6875rem] tabular-nums text-faint-foreground`,children:k_(t+1)})]}),EN=(e,t,n)=>({gridTemplateColumns:GM(e.specs,e.gutter,e.trailing,e.minScale),height:e.height,top:e.offset,transform:t===0?void 0:`translateY(${t}px)`,transition:n}),DN=e=>t=>{t.target.closest(`a`)||e()},ON=({cells:e,selected:t,current:n=!1,onToggle:r,onOpen:i,menu:a,handle:o,rowRef:s,dragY:c,transition:l,dragging:u,...d})=>(0,q.jsxs)(`div`,{ref:s,role:`row`,"aria-current":n||void 0,"data-pressable":i?``:void 0,onClick:i&&DN(i),className:U(`absolute inset-x-0 top-0 grid items-center border-b`,t||n?`bg-primary-soft`:`bg-background hover:bg-surface`,i&&`cursor-pointer`,u&&`z-30 bg-surface shadow-pop`),style:c===void 0?SN(d):EN(d,c,l),children:[o?(0,q.jsx)(`div`,{className:U(`sticky left-0 z-10 flex h-full items-center bg-inherit pl-1.5`,d.scrolled&&!d.lastPinned&&`shadow-[1px_0_0_var(--border),4px_0_6px_-2px_rgb(0_0_0/0.12)]`),style:{width:d.gutter},children:o}):(0,q.jsx)(TN,{width:d.gutter,index:d.index,selectable:d.selectable,selected:t,onToggle:r,edge:d.scrolled&&!d.lastPinned}),e.map(({spec:e,content:t,props:n,chosen:r,editing:i,editable:a})=>(0,q.jsx)(`div`,{role:n?`gridcell`:`cell`,...n,className:U(CN(e,d),n&&`scroll-mb-[calc(var(--pb-sticky-bottom,0px)+3rem)] scroll-mt-[calc(var(--pb-sticky-top,0px)+2rem)] outline-none`,a&&!i&&`cursor-default`,r&&`shadow-[inset_0_0_0_2px_var(--primary)]`,i&&`z-30 overflow-visible bg-background px-1`),style:wN(e,d.pins),children:t},e.id)),a&&(0,q.jsx)(`div`,{className:`sticky right-0 z-10 flex h-full items-center justify-center bg-inherit`,children:a})]}),kN=[`w-3/4`,`w-1/2`,`w-2/3`,`w-5/6`,`w-2/5`],AN=e=>(0,q.jsxs)(`div`,{role:`row`,"aria-busy":!0,className:`absolute inset-x-0 top-0 grid items-center border-b bg-background`,style:SN(e),children:[(0,q.jsx)(TN,{width:e.gutter,index:e.index,selectable:!1,edge:e.scrolled&&!e.lastPinned}),e.specs.map((t,n)=>(0,q.jsx)(`div`,{className:CN(t,e),style:wN(t,e.pins),children:(0,q.jsx)(L,{className:U(`h-2.5`,kN[(e.index+n)%kN.length],hN(t.kind)&&`ml-auto`)})},t.id))]}),jN=(e,t)=>{let n=new Map;return{get:t=>n.get(Math.floor(t/e))?.[t%e],hasPage:e=>n.has(e),setPage:(e,r)=>{if(n.delete(e),n.set(e,r),n.size<=t)return;let i=n.keys().next();i.done||n.delete(i.value)},keepOnly:e=>{for(let t of[...n.keys()])e.includes(t)||n.delete(t)},get size(){return n.size}}},MN=(e,t,n)=>{let r=Math.floor(e/n),i=Math.floor(t/n);return Array.from({length:i-r+1},(e,t)=>r+t)},NN=(e,t)=>Math.max(0,Math.min(40,e-t*40)),PN=({total:e,rowAt:t,loadRows:n,revision:r,latencyMs:i},a,o)=>{let s=(0,W.useMemo)(()=>jN(40,60),[t,n]),[c,l]=(0,W.useState)(0),u=Math.floor(a/40),d=Math.floor(o/40),f=!n&&i===0;(0,W.useEffect)(()=>{if(f)return;let r=MN(u*40,d*40,40).filter(e=>!s.hasPage(e)),a=t=>NN(e,t),o=(e,t)=>{s.setPage(e,t),l(e=>e+1)};if(n){let e=!1;for(let t of r)n(t*40,a(t)).then(n=>{e||o(t,n)});return()=>{e=!0}}let c=r.map(e=>setTimeout(()=>o(e,Array.from({length:a(e)},(n,r)=>t(e*40+r))),i));return()=>c.forEach(clearTimeout)},[s,u,d,i,e,t,n,f]);let p=(0,W.useRef)(r);return(0,W.useEffect)(()=>{if(!n||r===p.current)return;p.current=r;let t=MN(u*40,d*40,40);s.keepOnly(t);for(let r of t.filter(e=>s.hasPage(e)))n(r*40,NN(e,r)).then(e=>{s.setPage(r,e),l(e=>e+1)})},[s,r,n,u,d,e]),(0,W.useCallback)(e=>f?t(e):s.get(e),[s,f,t,c])},FN=1e7,IN=(e,t,n)=>{let r=e*t,i=Math.min(r,FN);return{rowHeight:t,trueHeight:r,contentHeight:i,scaled:r>i,maxTop:Math.max(0,r-n),maxScroll:Math.max(0,i-n)}},LN=(e,t)=>!e.scaled||t<=0?t:t>=e.maxScroll?e.maxTop+t-e.maxScroll:t/e.maxScroll*e.maxTop,RN=(e,t)=>!e.scaled||t<=0?t:t>=e.maxTop?e.maxScroll+t-e.maxTop:t/e.maxTop*e.maxScroll,zN=(e,t,n,r)=>{let i=t*e.rowHeight;return e.scaled?i-n+r:i},BN=(e,t,n,r,i)=>{let a=Math.min(e,Math.max(0,Math.floor(t/n)-i)),o=Math.min(e-1,Math.floor((t+r)/n)+i);return{first:a,last:Math.max(a-1,o)}},VN=e=>{let t=document.scrollingElement??document.documentElement;for(let n=e.parentElement;n&&n!==t&&n!==document.body;n=n.parentElement)if(/auto|scroll/.test(getComputedStyle(n).overflowY))return n;return t},HN=e=>e===(document.scrollingElement??document.documentElement),UN=e=>HN(e)?window:e,WN=e=>Number.parseFloat(e)||0,GN=e=>{let t=getComputedStyle(e),n=HN(e)?{top:0,height:e.clientHeight}:{top:e.getBoundingClientRect().top+e.clientTop,height:e.clientHeight},r=WN(t.scrollPaddingTop);return{top:n.top+r,height:Math.max(0,n.height-r-WN(t.scrollPaddingBottom))}},KN=6,qN=(e,t,n)=>{let r=IN(t,n,e.height),i=LN(r,e.position);return{geometry:r,top:i,topIndex:Math.floor(Math.max(0,i)/n),...BN(t,i,n,e.height,KN)}},JN=({total:e,rowHeight:t,initialIndex:n,inset:r=0,settle:i,ready:a=!0,onScroll:o})=>{let s=(0,W.useRef)(null),c=(0,W.useRef)(null),[l,u]=(0,W.useState)({position:0,height:0}),d=(0,W.useRef)({total:e,rowHeight:t,initialIndex:n,inset:r,ready:a,onScroll:o});d.current={total:e,rowHeight:t,initialIndex:n,inset:r,ready:a,onScroll:o};let f=(0,W.useCallback)(()=>{let e=s.current;if(!e||!c.current)return;let t=GN(c.current),n=d.current.inset;return{position:t.top+n-e.getBoundingClientRect().top,height:Math.max(0,t.height-n)}},[]),p=(0,W.useRef)({pending:!0,laidOut:!1}),m=(0,W.useRef)(l);m.current=l;let h=(0,W.useCallback)(()=>{let e=f();if(!e)return;let t=m.current,{total:n,rowHeight:r,onScroll:i}=d.current,a=qN(t,n,r),o=qN(e,n,r);p.current.pending||i?.(Math.max(0,o.top));let s=!o.geometry.scaled&&a.first===o.first&&a.last===o.last&&a.topIndex===o.topIndex;(t.height!==e.height||t.position!==e.position&&!s)&&(m.current=e,u(e))},[f]),g=(0,W.useCallback)(()=>{if(!p.current.pending||!p.current.laidOut||!d.current.ready)return;let e=f(),t=c.current;if(!e||!t)return;p.current.pending=!1;let{total:n,rowHeight:r,initialIndex:i}=d.current;i>0?t.scrollTop+=RN(IN(n,r,e.height),i*r)-e.position:e.position>0&&(t.scrollTop=0)},[f]);(0,W.useLayoutEffect)(()=>{let e=s.current;if(!e)return;let t=VN(e);c.current=t;let n=UN(t);n.addEventListener(`scroll`,h,{passive:!0}),window.addEventListener(`resize`,h,{passive:!0});let r=new ResizeObserver(()=>{p.current.laidOut=!0,g(),h()});return r.observe(t),r.observe(e),h(),()=>{n.removeEventListener(`scroll`,h),window.removeEventListener(`resize`,h),r.disconnect(),c.current=null}},[h,g]),(0,W.useLayoutEffect)(()=>{g(),h()});let _=(0,W.useCallback)(e=>{let t=f();if(!t||!c.current)return;let n=IN(d.current.total,d.current.rowHeight,t.height);c.current.scrollTop+=RN(n,e)-t.position,h()},[f,h]),v=(0,W.useCallback)(()=>!p.current.pending,[]),y=qN(l,e,t),b=i?i(y.top):y.top,{first:x,last:S}=i?BN(e,b,t,l.height,KN):y,C=Array.from({length:S-x+1},(e,t)=>({index:x+t,offset:zN(y.geometry,x+t,b,l.position)}));return{ref:s,height:l.height,top:b,geometry:y.geometry,rows:C,first:x,last:S,scrollTo:_,started:v}},YN=e=>e===`ArrowUp`||e===`ArrowDown`||e===`ArrowLeft`||e===`ArrowRight`,XN=(e,t,n,r)=>{let i=n.indexOf(e.column);if(t===`ArrowUp`)return e.index>0?{...e,index:e.index-1}:void 0;if(t===`ArrowDown`)return e.index<r-1?{...e,index:e.index+1}:void 0;let a=n[t===`ArrowLeft`?i-1:i+1];return i>=0&&a!==void 0?{...e,column:a}:void 0},ZN=(e,t,n,r)=>{let i=t.indexOf(e);return(r===1?t.slice(i+1):t.slice(0,Math.max(0,i)).reverse()).find(n)},QN=e=>`${e.index}:${e.column}`,$N=({editor:e,columns:t,total:n,rowAt:r,onOpenRow:i,container:a})=>{let[o,s]=(0,W.useState)(),[c,l]=(0,W.useState)(!1),u=(0,W.useRef)(!1),d=(0,W.useRef)(!1);if((0,W.useEffect)(()=>{if(!o||c||!u.current)return;u.current=!1;let e=a.current?.querySelector(`[data-cell="${QN(o)}"]`);e&&(e.focus({preventScroll:!0}),e.scrollIntoView({block:`nearest`,inline:`nearest`}))},[o,c,a]),!e)return;let f=t=>{let n=r(t.index);return n!==void 0&&e.editable(n,t.column)},p=(e,t=!1)=>{u.current=!0,s(e),l(t&&f(e))},m=n=>{if(!o)return;let i=r(o.index),s=n&&i?ZN(o.column,t,t=>e.editable(i,t),n):void 0,c=!!a.current?.contains(document.activeElement);p(s?{...o,column:s}:o,s!==void 0),u.current=c};return{cell:(n,r,i,a)=>{let l={index:n,column:i},u=o?.index===n&&o.column===i,f=e.editable(r,i),h=u||!o&&n===0&&i===t[0];return{content:u&&c?e.render(r,i,m):a,chosen:u,editing:u&&c,editable:f,props:{"data-cell":QN(l),tabIndex:h?0:-1,"aria-selected":u,onMouseDown:()=>{d.current=u},onFocus:e=>{e.target===e.currentTarget&&!u&&s(l)},onClick:e=>{f&&(e.stopPropagation(),d.current&&!c&&p(l,!0))},onDoubleClick:e=>{f&&(e.stopPropagation(),u&&c||p(l,!0))}}}},onKeyDown:e=>{if(c||!o||!(e.target instanceof HTMLElement)||e.target.dataset.cell!==QN(o))return;let a=e.key===`Tab`?e.shiftKey?`ArrowLeft`:`ArrowRight`:e.key;if(YN(a)){let i=XN(o,a,t,n);if(!i&&e.key===`Tab`)return;e.preventDefault(),i&&r(i.index)&&p(i);return}if(e.key===`Enter`||e.key===`F2`){e.preventDefault();let t=r(o.index);f(o)?p(o,!0):e.key===`Enter`&&t&&i?.(t);return}e.key===`Escape`&&s(void 0)}}},eP=({ids:e,rowAt:t,reorder:n,children:r})=>{let i=At(gn(It,{activationConstraint:{distance:4}}),gn($t,{activationConstraint:{delay:250,tolerance:5}}),gn(Pt,{coordinateGetter:Zt})),a=t=>e.indexOf(String(t)),o=e=>{let r=t(a(e));return r?n.label(r):F_(`row`)};return(0,q.jsx)(Kt,{sensors:i,collisionDetection:Jt,onDragEnd:({active:e,over:t})=>{t&&e.id!==t.id&&n.onMove(a(e.id),a(t.id))},accessibility:{announcements:{onDragStart:({active:t})=>F_(`pickedUp`,{name:o(t.id),row:a(t.id)+1,rows:e.length}),onDragOver:({active:t,over:n})=>n?F_(`isOver`,{name:o(t.id),row:a(n.id)+1,rows:e.length}):void 0,onDragEnd:({active:t,over:n})=>n?F_(`droppedAt`,{name:o(t.id),row:a(n.id)+1,rows:e.length}):F_(`putBack`,{name:o(t.id)}),onDragCancel:({active:e})=>F_(`cancelled`,{name:o(e.id),row:a(e.id)+1})},screenReaderInstructions:{draggable:F_(`reorderInstructions`)}},children:(0,q.jsx)(Vt,{items:e,strategy:Mt,children:r})})},tP=({row:e,label:t,...n})=>{let{attributes:r,listeners:i,setNodeRef:a,setActivatorNodeRef:o,transform:s,transition:c,isDragging:l}=rn({id:e.id}),u=(0,q.jsx)(`button`,{ref:o,type:`button`,"aria-label":F_(`move`,{label:t}),...r,...i,onClick:e=>e.stopPropagation(),style:{touchAction:`none`},className:`flex size-7 cursor-grab items-center justify-center rounded text-faint-foreground hover:bg-muted hover:text-foreground focus-visible:text-foreground active:cursor-grabbing pointer-coarse:size-9`,children:(0,q.jsx)(bl,{className:`size-4`})});return(0,q.jsx)(ON,{...n,rowRef:a,handle:u,dragY:s?.y??0,transition:c,dragging:l})},nP=({columns:e,source:t,naturalSort:n,initialScrollIndex:r=0,onScrollIndex:i,latencyMs:a=150,sort:o,onSortChange:s,onOpenRow:c,rowLink:l,chosenRow:u,rowActions:d,cellEditor:f,rowPatches:p,bulkActions:m,pinKey:g,defaultPinned:_,rowNumbers:v=!0,compact:y=!1,selectable:b=!0,reorder:x,fit:S=!1,scroll:C=`own`,className:w})=>{let T=b&&!x,{header:E,row:D,footer:O}=mN(cN(),{compact:y,withBelow:e.some(e=>e.below)}),k=!h(),ee=(_??(k?[]:$M(e))).join(` `),[A,te]=QM(g,(0,W.useMemo)(()=>ee?ee.split(` `):[],[ee])),ne=(0,W.useMemo)(()=>[...A.flatMap(t=>e.find(e=>e.id===t)??[]),...e.filter(e=>!A.includes(e.id))],[e,A]),re=ne.slice(0,ne.filter(e=>A.includes(e.id)).length).map(e=>e.id),{total:j}=t,[ie,M]=(0,W.useState)(n?[{id:n.columnId,desc:n.direction===`desc`}]:[]),ae=o?[{id:o.columnId,desc:o.direction===`desc`}]:ie,oe=e=>{let t=typeof e==`function`?e(ae):e,n=t[0];s&&n&&s({columnId:n.id,direction:n.desc?`desc`:`asc`}),o||M(t)},[se,ce]=(0,W.useState)({}),le=(0,W.useMemo)(()=>NM(ne),[ne]),ue=ae[0],de=!!(!o&&n&&ue&&ue.id===n.columnId&&(ue.desc?`desc`:`asc`)!==n.direction),fe=t.rowAt,pe=(0,W.useCallback)(e=>fe(de?j-1-e:e),[fe,de,j]),[me]=(0,W.useState)(r),{ref:he,geometry:ge,rows:_e,first:ve,last:ye}=JN({total:j,rowHeight:D,initialIndex:me,inset:E,onScroll:i&&(e=>i(e/D))}),be=k||!v?40:VM(j),xe=PN({total:j,rowAt:fe?pe:void 0,loadRows:t.loadRows,revision:t.revision,latencyMs:a},ve,ye),Se=(0,W.useCallback)(e=>{let t=xe(e),n=t&&p?.get(t.id);return n?{...t,...n}:t},[xe,p]),Ce=_e.map(({index:e,offset:t})=>({index:e,offset:t,row:Se(e)})),we=(0,W.useMemo)(()=>Ce.flatMap(({row:e})=>e?[e]:[]),[Se,ve,ye]),N=(0,W.useRef)(null),Te=oN(N),Ee=nN(ne,we),De=(0,W.useMemo)(()=>iN(Ee,Te.widths),[Ee,Te.widths]),Oe=mn({features:jM,columns:le,data:we,state:{sorting:ae,rowSelection:se},onSortingChange:oe,onRowSelectionChange:ce,manualSorting:!0,enableMultiSort:!1,enableSortingRemoval:!1,getRowId:e=>e.id}),ke=new Map(Oe.getRowModel().rows.map(e=>[e.id,e])),Ae=Object.keys(se).length,je=(0,W.useRef)(new Map),[Me]=(0,W.useState)(IM);for(let e of Oe.getRowModel().rows)e.getIsSelected()&&je.current.set(e.id,e.original);let Ne=d&&d.length>0?40:0,Pe=k?1:HM,Fe=qM(),Ie=()=>{Fe.onScroll(),N.current&&Fe.ref.current&&(N.current.scrollLeft=Fe.ref.current.scrollLeft)},[Le,Re]=(0,W.useState)({});(0,W.useLayoutEffect)(()=>{let e=N.current?.querySelector(`[role=row]`);if(!e)return;let t=be,n={};for(let r of re)n[r]=t,t+=e.querySelector(`[data-col-id="${r}"]`)?.offsetWidth??0;JSON.stringify(Le)!==JSON.stringify(n)&&Re(n)});let ze=re.at(-1),Be=e=>te(A.includes(e)?A.filter(t=>t!==e):[...A,e]),Ve=Oe.getHeaderGroups().flatMap(e=>e.headers.map(e=>({spec:ne.find(t=>t.id===e.column.id),sorted:e.column.getIsSorted(),onSort:t=>e.column.getToggleSortingHandler()?.(t)}))),He=(0,W.useRef)(null),Ue=$N({editor:f,columns:(0,W.useMemo)(()=>ne.map(e=>e.id),[ne]),total:j,rowAt:Se,onOpenRow:c,container:He}),We=(ne.find(e=>e.title)??ne[0])?.id,Ge=KM(De,be,Ne,Pe),Ke=C===`own`,qe=!S||T&&!!m?.length,Je=(0,q.jsx)(`div`,{ref:N,className:U(`sticky z-20 shrink-0 overflow-hidden`,Ke?`top-0`:`top-[var(--pb-sticky-top,0px)]`),children:(0,q.jsx)(`div`,{style:{minWidth:Ge},children:(0,q.jsx)(xN,{cells:Ve,specs:De,gutter:be,trailing:Ne,minScale:Pe,pins:Le,lastPinned:ze,scrolled:Fe.scrolled,onTogglePin:Be,resize:Te,widths:Te.widths,selectable:T,selectedCount:Ae,onClearSelection:()=>ce({})})})}),Ye=Ce.map(({index:e,offset:t,row:n})=>{let r={specs:De,gutter:be,index:e,offset:t,height:D,selectable:T,trailing:Ne,minScale:Pe,scrolled:Fe.scrolled,pins:Le,lastPinned:ze},i=n?ke.get(n.id):void 0;if(!i||!n)return(0,q.jsx)(AN,{...r},`skeleton-${e}`);let a=Ne?zM(d,n):[],o={...r,selected:i.getIsSelected(),current:n.id===u,onToggle:()=>i.toggleSelected(),onOpen:c?()=>c(n):void 0,menu:a.length>0?(0,q.jsx)(BM,{row:n,actions:a}):void 0,cells:i.getAllCells().map(t=>{let r=ne.find(e=>e.id===t.column.id),i=(0,q.jsx)(Oe.FlexRender,{cell:t}),a=!!f?.editable(n,t.column.id),o=l&&t.column.id===We&&!a?(0,q.jsx)(Jn,{to:l(n),className:`flex min-w-0 items-center hover:underline`,children:i}):i,s=r.below?(0,q.jsxs)(`div`,{className:`flex min-w-0 flex-col items-start gap-1`,children:[o,r.below(n)]}):o;return{spec:r,...Ue?Ue.cell(e,n,t.column.id,s):{content:s}}})};return x?(0,q.jsx)(tP,{...o,row:n,label:x.label(n)},n.id):(0,q.jsx)(ON,{...o},n.id)}),Xe=(0,q.jsx)(`div`,{ref:Fe.attach,onScroll:Ie,className:`overflow-x-auto overflow-y-hidden overscroll-x-contain [-webkit-overflow-scrolling:touch]`,children:(0,q.jsx)(`div`,{ref:he,className:`relative`,style:{minWidth:Ge,height:ge.contentHeight},children:x?(0,q.jsx)(eP,{ids:Array.from({length:j},(e,t)=>Se(t)?.id??`missing-${t}`),rowAt:Se,reorder:x,children:Ye}):Ye})});return(0,q.jsxs)(`div`,{ref:He,role:`grid`,"aria-rowcount":j,onKeyDown:Ue?.onKeyDown,className:U(`flex flex-col rounded-lg border bg-background`,Ke?`min-h-0 overflow-hidden`:`overflow-clip`,w),style:S&&Ke?{height:E+j*D+(qe?O:0)+2}:void 0,children:[(0,q.jsxs)(`div`,{className:U(`relative`,Ke&&`flex min-h-0 flex-1 flex-col`),children:[Ke?(0,q.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overflow-x-hidden`,children:[Je,Xe]}):(0,q.jsxs)(q.Fragment,{children:[Je,Xe]}),Fe.more&&(0,q.jsx)(`div`,{"aria-hidden":!0,className:`pointer-events-none absolute inset-y-0 right-0 z-20 w-8 bg-gradient-to-l from-backdrop/15 to-transparent`})]}),qe&&(0,q.jsx)(LM,{total:j,className:Ke?void 0:`sticky bottom-[var(--pb-sticky-bottom,0px)] z-20`,selectedCount:Ae,bulkActions:PM(m??[],Object.keys(se).flatMap(e=>je.current.get(e)??[])).map(({action:e,rows:t,skipped:n})=>({label:e.label(t.length),destructive:e.destructive,onRun:()=>void Me(e,t,n).then(e=>{if(!e)return;let t=new Set(e.map(e=>e.id));ce(e=>Object.fromEntries(Object.entries(e).filter(([e])=>!t.has(e))));for(let e of t)je.current.delete(e)})}))})]})},rP=500,iP=async(e,t,n)=>{let r=[],i={},a;do{let o=await e.search(t,{...n,pageSize:rP,...a&&{pageToken:a}});r.push(...o.items);for(let[e,t]of Object.entries(o.labels??{}))i[e]={...i[e],...t};a=o.nextPageToken||void 0}while(a);return{items:r,labels:i}},aP=m(),oP=(...e)=>{let t=e.filter(e=>!!e);return t.length===1?t[0]:t.map(e=>`(${e})`).join(` AND `)},sP=e=>e==null?void 0:String(e),cP=(e,t,n)=>{let r=new Map;for(let[t,n]of e)r.set(n,(r.get(n)??new Set).add(t));let i=new Map;for(let e of t){let t=e[n],a=sP(typeof t==`object`&&t&&`id`in t?t.id:t);for(let t of a===void 0?[]:r.get(a)??[])i.set(t,[...i.get(t)??[],e])}return i},lP=async(e,t,n,r)=>{let i=n.through;if(!i)return r.map(e=>[e,e]);let a=t[i.resource],o=i.key??a?.primaryKey[0];if(!a||o===void 0)throw Error(`The related column ${n.name} names a join resource the app does not have: ${i.resource}`);return(await iP(e,a.name,{filter:oP(vn(aP.in(i.field,r)),i.filter),fields:[i.field,o]})).items.flatMap(e=>{let t=sP(e[i.field]),n=sP(e[o]);return t===void 0||n===void 0?[]:[[t,n]]})},uP=async({client:e,resources:t,views:n,load:r,owners:i})=>{let{column:a,fields:o}=r,s=t[a.resource];if(!s)throw Error(`The related column ${a.name} shows a resource the app does not have: ${a.resource}`);if(i.length===0)return new Map;let c=await lP(e,t,a,i),l=[...new Set(c.map(([,e])=>e))];if(l.length===0)return new Map;let u=[...new Set([...s.primaryKey,a.field,a.status,...o])],d=ab(t,n,s,u),f=await iP(e,s.name,{filter:oP(vn(aP.in(a.field,l)),a.filter),...a.sort&&{orderBy:a.sort},fields:u,labels:d});return cP(c,ob(t,s,u,f.items,f.labels),a.field)},dP=5e3,fP=({queryClient:e,client:t,resources:n,views:r,model:i,columns:a,filter:o,orderBy:s,related:c=[]})=>{let l=c.map(e=>e.column.name).join(`,`),u=e=>c.length===0?I.page(i.name,o,s,40,e):[...I.page(i.name,o,s,40,e),l],d=ab(n,r,i,a),f=C(r[i.name]),p=async e=>e.nextPageToken===``?e.items.length:e.totalSizeEstimate>dP?e.totalSizeEstimate:(await t.list(i.name,{filter:o,orderBy:s,pageSize:1,count:`exact`})).totalSize??e.totalSizeEstimate,m=async t=>{if(t===0)return``;let n=u(t-1),r=e.getQueryData(n);if(r)return r.nextPageToken;if(e.getQueryState(n)?.fetchStatus===`fetching`)return(await g(t-1)).nextPageToken},h=async l=>{let u=await m(l);if(l>0&&u===``)return{rows:[],total:0,nextPageToken:``};let h={filter:o,orderBy:s,pageSize:40,labels:d,photos:f},g=u===void 0?await t.seek(i.name,{...h,position:l*40}):await t.list(i.name,{...h,pageToken:u});if(g.items.length===0&&l>0)return{rows:[],total:0,nextPageToken:``};let _=g.items.map(e=>Nr(i,e)),v=ob(n,i,a,E(i,g.items,g.photos),g.labels),[y]=await Promise.all([Promise.all(c.map(e=>uP({client:t,resources:n,views:r,load:e,owners:_}))),db(e,t,n,r,i,a,g.items)]);return{rows:v.map((e,t)=>({...e,...Object.fromEntries(c.map((e,n)=>[e.column.name,y[n].get(_[t])??[]])),id:_[t]})),total:l===0?await p(g):g.totalSizeEstimate,nextPageToken:g.nextPageToken}},g=t=>e.fetchQuery({queryKey:u(t),staleTime:6e4,queryFn:()=>h(t)});return{page:g,loadRows:async e=>(await g(Math.floor(e/40))).rows}},pP=e=>{let{queryClient:t,model:n,columns:r,filter:i,orderBy:a}=e;return{queryKey:[...I.first(n.name,i,a),r.join(`,`)],queryFn:async()=>(await t.invalidateQueries({queryKey:I.pages(n.name,i,a),refetchType:`none`}),fP(e).page(0))}},mP=({resources:e,views:t,model:n,columns:r,filter:i,orderBy:a,related:o})=>{let s=F(),c=nn(),l=r.join(`,`),u=JSON.stringify(o??[]),d=(0,W.useMemo)(()=>({queryClient:c,client:s,resources:e,views:t,model:n,columns:r,filter:i,orderBy:a,...o&&{related:o}}),[c,s,e,t,n,l,i,a,u]),f=(0,W.useMemo)(()=>fP(d),[d]),p=pP(d),m=Tt(p);return{source:(0,W.useMemo)(()=>m.data?{total:m.data.total,loadRows:f.loadRows,revision:m.dataUpdatedAt}:void 0,[m.data,m.dataUpdatedAt,f]),error:m.error,isLoading:m.isLoading,page:f.page,key:p.queryKey}},hP=B(`app/searches`),gP=`inline-flex h-6 items-center rounded-full border border-primary-border bg-primary-soft px-2.5 text-xs font-medium text-primary-text`,_P=({chips:e,className:t})=>(0,q.jsx)(`ul`,{className:U(`flex flex-wrap gap-1.5`,t),"aria-label":hP(`filters`),children:e.map(e=>(0,q.jsx)(`li`,{className:gP,children:e.label},e.key))}),vP=({chips:e})=>(0,q.jsx)(`span`,{className:`flex flex-wrap gap-1.5`,children:e.map((e,t)=>(0,q.jsxs)(`span`,{className:gP,children:[t>0&&(0,q.jsx)(`span`,{className:`sr-only`,children:`, `}),e.label]},e.key))}),yP=e=>e.map(e=>e.label).join(`, `),bP=B(`filter-panel`),xP=`inline-flex h-6 items-center gap-1 rounded-full border border-primary-border bg-primary-soft pl-2.5 pr-1.5 text-xs font-medium text-primary-text`,SP=({chips:e,lockedLabels:t=[],onRemove:n,onClear:r,scroll:i})=>e.length===0&&t.length===0?null:(0,q.jsxs)(`div`,{className:i?`flex flex-nowrap items-center gap-1.5 overflow-x-auto pb-1 [&>*]:shrink-0`:`flex flex-wrap items-center gap-1.5`,children:[t.map(e=>(0,q.jsxs)(`span`,{className:`inline-flex h-6 items-center gap-1.5 rounded-full border border-border-strong bg-muted px-2.5 text-xs font-medium text-foreground`,children:[(0,q.jsx)(Ql,{className:`size-3 text-muted-foreground`}),e]},e)),e.map(e=>(0,q.jsxs)(`span`,{className:xP,children:[e.label,(0,q.jsx)(`button`,{type:`button`,"aria-label":bP(`remove`,{label:e.label}),onClick:()=>n(e.key),className:`rounded-full p-0.5 hover:bg-primary-border/60`,children:(0,q.jsx)(Ci,{className:`size-3`})})]},e.key)),e.length>0&&(0,q.jsx)(`button`,{type:`button`,onClick:r,className:`ml-1 text-xs font-medium text-muted-foreground hover:text-foreground`,children:bP(`clearAll`)})]}),CP=[`today`,`7d`,`30d`,`year`],wP=new Set([`today`,`yesterday`,`24h`,`7d`,`30d`,`90d`,`month`,`quarter`,`year`]),TP=e=>wP.has(e)?bP(e):void 0,EP=({value:e,presets:t=CP,onChange:n})=>(0,q.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:t.map(t=>{let r=TP(t);return(0,q.jsx)(`button`,{type:`button`,disabled:!r,title:r?void 0:bP(`unknownPreset`,{id:t}),onClick:()=>n(e===t?void 0:t),className:U(`h-7 rounded-md border px-2.5 text-body font-medium transition-colors`,!r&&`border-dashed text-danger-text`,e===t?`border-primary-border bg-primary-soft text-primary-text`:`border-border-strong bg-background text-muted-foreground hover:bg-muted`),children:r??bP(`unsupported`,{id:t})},t)})}),DP={facets:{},toggles:[]},OP=(e,t,n)=>{let r=e.facets[t]??[],i=r.includes(n)?r.filter(e=>e!==n):[...r,n];return{...e,facets:{...e.facets,[t]:i}}},kP=(e,t)=>({...e,toggles:e.toggles.includes(t)?e.toggles.filter(e=>e!==t):[...e.toggles,t]}),AP=(e,t,n)=>{let{[t]:r,...i}=e.ranges??{};return{...e,ranges:n?{...i,[t]:n}:i}},jP=(e,t)=>e.options.find(e=>e.value===t)?.label??e.labels?.[t]??t,MP=(e,t)=>{let n=e.facets.flatMap(e=>(t.facets[e.id]??[]).map(t=>({key:`facet:${e.id}:${t}`,label:`${e.label}: ${jP(e,t)}`}))),r=(e.ranges??[]).flatMap(e=>{let n=t.ranges?.[e.id];return n?[{key:`range:${e.id}`,label:`${e.label}: ${e.format(n[0])} – ${e.format(n[1])}`}]:[]}),i=t.date?[{key:`date`,label:TP(t.date)??t.date}]:[],a=t.toggles.map(t=>({key:`toggle:${t}`,label:e.toggles?.find(e=>e.id===t)?.label??t}));return[...n,...r,...i,...a]},NP=(e,t)=>{if(t===`date`)return{...e,date:void 0};let[n,r,i]=t.split(`:`);if(n===`range`)return AP(e,r,void 0);if(n===`toggle`)return kP(e,r);if(n===`facet`)return OP(e,r,i);throw Error(`Unknown filter chip key: ${t}`)},PP=(e,t)=>e.toLowerCase().includes(t.trim().toLowerCase()),FP=(e,t)=>e.onSearch?e.options:e.options.filter(e=>PP(e.label,t)),IP=(e,t,n)=>t===0?-1:n===`ArrowDown`?e<0?0:(e+1)%t:e<0?t-1:(e-1+t)%t,LP=({config:e,selected:t,onToggle:n,inline:r=!1})=>{let i=(0,W.useId)(),a=(0,W.useRef)(null),[o,s]=(0,W.useState)(``),[c,l]=(0,W.useState)(!1),[u,d]=(0,W.useState)(-1),f=r||c,p=FP(e,o),m=(0,W.useRef)(e.onSearch);m.current=e.onSearch,(0,W.useEffect)(()=>()=>m.current?.(``),[]);let h=t=>{s(t),d(-1),e.onSearch?.(t)};return(0,q.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,q.jsxs)(`div`,{className:`flex min-h-8 cursor-text flex-wrap items-center gap-1 rounded-md border border-border-strong bg-background px-2 py-1 shadow-sm focus-within:border-primary focus-within:ring-2 focus-within:ring-primary/20`,onClick:()=>a.current?.focus(),children:[(0,q.jsx)(id,{className:`size-3.5 shrink-0 text-muted-foreground`}),t.map(t=>(0,q.jsx)(Kb,{label:jP(e,t),onRemove:()=>n(t)},t)),(0,q.jsx)(`input`,{ref:a,autoFocus:r,role:`combobox`,"aria-label":e.label,"aria-expanded":f,"aria-controls":`${i}-options`,"aria-autocomplete":`list`,"aria-activedescendant":p[u]?`${i}-${u}`:void 0,placeholder:t.length>0?``:bP(`searchIn`,{label:e.label}),className:`h-6 min-w-16 flex-1 bg-transparent text-foreground outline-none placeholder:text-faint-foreground`,value:o,onChange:e=>h(e.target.value),onKeyDown:e=>{if(e.key===`ArrowDown`||e.key===`ArrowUp`){e.preventDefault(),d(IP(u,p.length,e.key));return}if(e.key===`Enter`&&p[u]){e.preventDefault(),n(p[u].value);return}if(e.key===`Backspace`&&o===``&&t.length>0){n(t[t.length-1]);return}e.key===`Escape`&&o!==``&&(e.stopPropagation(),h(``))},onFocus:()=>l(!0),onBlur:()=>{l(!1),d(-1),!r&&o!==``&&h(``)}})]}),f&&(0,q.jsxs)(`ul`,{id:`${i}-options`,role:`listbox`,"aria-label":e.label,"aria-multiselectable":!0,className:U(`flex max-h-60 flex-col gap-px overflow-y-auto`,!r&&`rounded-md border bg-background p-1 shadow-sm`),children:[p.map((e,r)=>{let a=t.includes(e.value);return(0,q.jsxs)(`li`,{id:`${i}-${r}`,role:`option`,"aria-selected":a,tabIndex:-1,className:U(`flex cursor-pointer items-center gap-2 rounded px-1.5 py-1 hover:bg-muted`,r===u&&`bg-muted`),onMouseDown:e=>e.preventDefault(),onClick:()=>n(e.value),children:[(0,q.jsx)(`span`,{className:U(`inline-flex size-4 shrink-0 items-center justify-center rounded border`,a?`border-primary bg-primary text-primary-foreground`:`border-border-strong bg-background`),children:a&&(0,q.jsx)(xi,{className:`size-3`,strokeWidth:3})}),(0,q.jsx)(`span`,{className:`flex-1 truncate`,children:e.label}),e.count!==void 0&&(0,q.jsx)(`span`,{className:`text-xs tabular-nums text-faint-foreground`,children:k_(e.count)})]},e.value)}),p.length===0&&(0,q.jsx)(`li`,{className:`px-1.5 py-1 text-xs text-faint-foreground`,children:bP(`noMatches`)})]})]})},RP=({config:e,selected:t,onToggle:n})=>{let[r,i]=(0,W.useState)(``),a=e.options.filter(e=>PP(e.label,r));return(0,q.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[e.searchable&&(0,q.jsx)(bi,{wrapperClassName:`mb-1 h-7`,leading:(0,q.jsx)(id,{className:`size-3.5`}),placeholder:bP(`searchIn`,{label:e.label}),value:r,onChange:e=>i(e.target.value)}),a.map(e=>(0,q.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 rounded px-1 py-1 hover:bg-muted`,children:[(0,q.jsx)(Di,{checked:t.includes(e.value),onChange:()=>n(e.value),label:e.label}),(0,q.jsx)(`span`,{className:`flex-1 truncate`,children:e.label}),e.count!==void 0&&(0,q.jsx)(`span`,{className:`text-xs tabular-nums text-faint-foreground`,children:k_(e.count)})]},e.value)),a.length===0&&(0,q.jsx)(`span`,{className:`px-1 py-1 text-xs text-faint-foreground`,children:bP(`noMatches`)})]})},zP=({label:e,activeCount:t,width:n=240,defaultOpen:r=!1,children:i})=>{let[a,o]=(0,W.useState)(r),[s,c]=(0,W.useState)({width:n}),l=(0,W.useRef)(null),u=(0,W.useRef)(null);(0,W.useLayoutEffect)(()=>{if(!a||!l.current)return;let e=l.current.getBoundingClientRect(),t=document.documentElement.clientWidth,r=Math.min(n,zv(t));c({width:r,right:e.left+r>t?e.right-Rv(e.right,r,t):void 0})},[a,n]);let d=Uv(a,l,u,s);return(0,W.useEffect)(()=>{if(!a)return;let e=e=>{e.target instanceof Node&&!l.current?.contains(e.target)&&o(!1)};return document.addEventListener(`pointerdown`,e),()=>document.removeEventListener(`pointerdown`,e)},[a]),(0,q.jsxs)(`div`,{ref:l,className:`relative`,children:[(0,q.jsxs)(`button`,{type:`button`,"aria-expanded":a,onClick:()=>o(!a),className:U(`inline-flex h-8 items-center gap-1.5 rounded-md border bg-background px-2.5 font-medium shadow-sm transition-colors hover:bg-muted`,t>0?`border-primary-border text-primary-text`:`border-border-strong text-foreground`),children:[e,t>0&&(0,q.jsx)(`span`,{className:`rounded-full bg-primary px-1.5 text-[0.6875rem] leading-4 text-primary-foreground`,children:t}),(0,q.jsx)(Sc,{className:`size-3.5 text-muted-foreground`})]}),a&&(0,q.jsx)(`div`,{ref:u,className:U(`absolute top-full z-30 mt-1.5 rounded-lg border bg-background p-3 shadow-pop`,s.right===void 0&&`left-0`),style:{...s,...d},children:typeof i==`function`?i(()=>o(!1)):i})]})},BP=({title:e,children:t})=>(0,q.jsxs)(`section`,{className:`flex flex-col gap-2 border-b py-3 last:border-b-0`,children:[(0,q.jsx)(`h3`,{className:`text-xs font-semibold uppercase tracking-wide text-muted-foreground`,children:e}),t]}),VP=({items:e,onPick:t,close:n})=>{let r=(0,W.useRef)([]);return(0,W.useEffect)(()=>r.current[0]?.focus(),[]),(0,q.jsx)(`ul`,{role:`menu`,"aria-label":bP(`moreFilters`),onKeyDown:t=>{if(t.key===`Escape`)return n();let i=jO(t.key,r.current.indexOf(document.activeElement),e.length);i!==void 0&&(t.preventDefault(),r.current[i]?.focus())},className:`-mx-3 -my-3`,children:e.map((e,i)=>(0,q.jsx)(`li`,{role:`none`,children:(0,q.jsx)(`button`,{ref:e=>{r.current[i]=e},type:`button`,role:`menuitem`,className:Lv,onClick:()=>{n(),t(e.key)},children:e.label})},e.key))})},HP=({items:e,onPick:t})=>e.length===0?null:(0,q.jsx)(zP,{label:bP(`moreFilters`),activeCount:0,children:n=>(0,q.jsx)(VP,{items:e,onPick:t,close:n})}),UP=(e,t,n,r,i)=>{let a=n+(r-n)*e/t;return n+(r-n)*(e+1)/t>i[0]&&a<i[1]},WP=(e,t,n)=>n===t?0:(e-t)/(n-t),GP=(e,t,n)=>t===0?[Math.min(n,e[1]),e[1]]:[e[0],Math.max(n,e[0])],KP=1e3,qP=({config:e,value:t,onChange:n})=>{let{min:r,max:i,step:a,histogram:o,format:s}=e,[c,l]=(0,W.useState)(),u=c??t??[r,i],d=Math.max(...o),f=()=>{c&&(l(void 0),n(c[0]===r&&c[1]===i?void 0:c))},p=BO(c,KP);return(0,W.useEffect)(()=>{p&&f()},[p]),(0,q.jsxs)(`div`,{className:`w-full`,children:[(0,q.jsxs)(`div`,{className:`px-[7px]`,children:[o.length>0&&(0,q.jsx)(`div`,{className:`mb-1 flex h-12 items-end gap-0.5`,children:o.map((e,t)=>(0,q.jsx)(`span`,{className:U(`flex-1 rounded-t-sm`,UP(t,o.length,r,i,u)?`bg-primary/70`:`bg-border`),style:{height:`${Math.max(6,e/d*100)}%`}},t))}),(0,q.jsxs)(`div`,{className:`relative h-4`,children:[(0,q.jsx)(`span`,{className:`absolute inset-x-0 top-1/2 h-1 -translate-y-1/2 rounded-full bg-border`}),(0,q.jsx)(`span`,{className:`absolute top-1/2 h-1 -translate-y-1/2 rounded-full bg-primary`,style:{left:`${WP(u[0],r,i)*100}%`,right:`${100-WP(u[1],r,i)*100}%`}})]})]}),(0,q.jsx)(`div`,{className:`relative -mt-4 h-4`,children:[0,1].map(t=>(0,q.jsx)(`input`,{type:`range`,className:`pb-range`,"aria-label":bP(t===0?`minimum`:`maximum`,{label:e.label}),min:r,max:i,step:a,value:u[t],onChange:e=>l(GP(u,t,Number(e.target.value))),onPointerUp:f,onTouchEnd:f,onBlur:f},t))}),(0,q.jsxs)(`div`,{className:`mt-2 flex justify-between text-xs tabular-nums text-muted-foreground`,children:[(0,q.jsx)(`span`,{children:s(u[0])}),(0,q.jsx)(`span`,{children:s(u[1])})]})]})},JP=e=>[...new Set(e.map(e=>e.key.split(`:`).slice(0,2).join(`:`)))],YP=(e,t)=>{let n=t.filter(t=>!e.includes(t));return n.length===0?e:[...e,...n]},XP=(e,t)=>{let n=[...e.facets.map(e=>({key:`facet:${e.id}`,label:e.label,secondary:e.secondary})),...(e.ranges??[]).map(e=>({key:`range:${e.id}`,label:e.label,secondary:e.secondary})),...e.datePresets?[{key:`date`,label:bP(`date`),secondary:e.dateSecondary}]:[],...(e.toggles??[]).map(e=>({key:`toggle:${e.id}`,label:e.label,secondary:e.secondary}))],r=new Set,i=[];for(let e of n)!e.secondary||t.includes(e.key)?r.add(e.key):i.push({key:e.key,label:e.label});return{shown:r,more:i}},ZP=({label:e,checked:t,onChange:n})=>(0,q.jsxs)(`label`,{className:`flex cursor-pointer items-center justify-between gap-3 py-1`,children:[(0,q.jsx)(`span`,{children:e}),(0,q.jsx)(ky,{checked:t,onChange:n,label:e})]}),QP=(e,t)=>e.some(e=>e.length>0)||!!t,$P=({groups:e,trailing:t})=>{if(!QP(e,t))return null;let n=e.filter(e=>e.length>0);return(0,q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[n.map((e,t)=>(0,q.jsxs)(W.Fragment,{children:[t>0&&(0,q.jsx)(`span`,{className:`mx-1 h-5 w-px bg-border`}),e]},t)),t&&(0,q.jsx)(`div`,{className:`flex min-w-32 flex-1 justify-end`,children:t})]})},eF=(e,t,n)=>{let[r,i]=(0,W.useState)(t??DP);return[e??r,e=>{i(e),n?.(e)}]},tF=({config:e,layout:t,value:n,defaultValue:r,onChange:i,lockedLabels:a,defaultOpenMenu:o,fullWidth:s,leading:c,trailing:l})=>{let[u,d]=eF(n,r,i),f=MP(e,u),p=JP(f),[m,h]=(0,W.useState)(()=>p),[g,_]=(0,W.useState)();(0,W.useEffect)(()=>h(e=>YP(e,p)),[p.join(`,`)]);let v=(0,q.jsx)(SP,{chips:f,lockedLabels:a,onRemove:e=>d(NP(u,e)),onClear:()=>d(DP)}),y=(e,t=!1)=>{let n=u.facets[e.id]??[],r=t=>d(OP(u,e.id,t));return e.combobox?(0,q.jsx)(LP,{config:e,selected:n,onToggle:r,inline:t}):(0,q.jsx)(RP,{config:e,selected:n,onToggle:r})},b=e.ranges??[],x=e=>(0,q.jsx)(qP,{config:e,value:u.ranges?.[e.id],onChange:t=>d(AP(u,e.id,t))}),S=e.datePresets&&(0,q.jsx)(EP,{value:u.date,presets:Array.isArray(e.datePresets)?e.datePresets:void 0,onChange:e=>d({...u,date:e})}),C=(e.toggles??[]).map(e=>(0,q.jsx)(ZP,{label:e.label,checked:u.toggles.includes(e.id),onChange:()=>d(kP(u,e.id))},e.id));if(t===`panel`)return(0,q.jsxs)(`aside`,{className:s?`flex w-full flex-col gap-1`:`flex w-64 shrink-0 flex-col gap-1 overflow-y-auto rounded-lg border bg-background px-4 py-3`,children:[(0,q.jsx)(`div`,{className:`flex items-center justify-between pb-1`,children:(0,q.jsx)(`h2`,{className:`font-semibold`,children:bP(`filters`)})}),(f.length>0||(a?.length??0)>0)&&(0,q.jsx)(`div`,{className:`border-b pb-3`,children:v}),c,e.facets.map(e=>(0,q.jsx)(BP,{title:e.label,children:y(e)},e.id)),b.map(e=>(0,q.jsx)(BP,{title:e.label,children:x(e)},e.id)),S&&(0,q.jsx)(BP,{title:bP(`date`),children:S}),C.length>0&&(0,q.jsx)(BP,{title:bP(`showOnly`),children:C})]});let{shown:w,more:T}=XP(e,m),E=e=>{h(t=>YP(t,[e])),_(e)},D=[...e.facets.filter(e=>w.has(`facet:${e.id}`)).map(e=>(0,q.jsx)(zP,{label:e.label,activeCount:(u.facets[e.id]??[]).length,width:e.combobox?280:void 0,defaultOpen:o===e.id||g===`facet:${e.id}`,children:y(e,!0)},e.id)),...b.filter(e=>w.has(`range:${e.id}`)).map(e=>(0,q.jsx)(zP,{label:e.label,activeCount:+!!u.ranges?.[e.id],width:280,defaultOpen:o===e.id||g===`range:${e.id}`,children:x(e)},`range:${e.id}`)),...S&&w.has(`date`)?[(0,q.jsx)(W.Fragment,{children:S},`date`)]:[]],O=(e.toggles??[]).filter(e=>w.has(`toggle:${e.id}`)).map(e=>(0,q.jsx)(`div`,{className:`flex items-center gap-2 text-muted-foreground`,children:(0,q.jsx)(ZP,{label:e.label,checked:u.toggles.includes(e.id),onChange:()=>d(kP(u,e.id))})},e.id)),k=[c?[(0,q.jsx)(W.Fragment,{children:c},`leading`)]:[],D,O,T.length>0?[(0,q.jsx)(HP,{items:T,onPick:E},`more`)]:[]];return!QP(k,l)&&f.length===0&&!a?.length?null:(0,q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,q.jsx)($P,{groups:k,trailing:l}),v]})},nF=m(),rF={start:0,end:0},iF={"24h":{amount:24,unit:`h`},"7d":{amount:7,unit:`d`},"30d":{amount:30,unit:`d`},"90d":{amount:90,unit:`d`}},aF=e=>new Date(e).toISOString().replace(`.000Z`,`Z`),oF=(e,t,n)=>{let r=Wn(t.getTime(),n),[i,a]=[Number(r.slice(0,4)),Number(r.slice(5,7))-1],o=e=>new Date(e).toISOString().slice(0,10);return e===`year`?o(Date.UTC(i,0,1)):e===`quarter`?o(Date.UTC(i,Math.floor(a/3)*3,1)):e===`month`?o(Date.UTC(i,a,1)):e===`yesterday`?o(Date.parse(`${r}T00:00:00Z`)-864e5):r},sF=[`year`,`quarter`,`month`,`yesterday`,`today`],cF=(e,t,n)=>t===`date`?e:aF(wr(e,n)),lF=(e,t,n)=>t===`date`?{kind:`string`,value:cF(e,t,n),span:rF}:{kind:`timestamp`,value:cF(e,t,n),span:rF},uF=(e,t,n,r,i)=>{if(t in iF)return[nF.gte(e,nF.ago(t))];let a=nF.gte(e,lF(oF(t,n,i),r,i));return t===`yesterday`?[a,nF.lt(e,lF(oF(`today`,n,i),r,i))]:[a]},dF=(e,t,n=new Date,r=Hn())=>{let i=e.facets.flatMap(e=>{let n=t.facets[e.id]??[];if(n.length===0)return[];if(e.flags){let t=e.options.filter(e=>n.includes(e.value)).map(e=>nF.eq(e.value,!0));return t.length===0?[]:[t.length===1?t[0]:nF.or(...t)]}return[n.length===1?nF.eq(e.id,n[0]):nF.in(e.id,n)]}),a=(e.ranges??[]).flatMap(e=>{let n=t.ranges?.[e.id];return n?[nF.gte(e.id,n[0]),nF.lte(e.id,n[1])]:[]}),o=e.dateField&&t.date?uF(e.dateField,t.date,n,e.dateKind,r):[],s=(e.toggles??[]).filter(e=>t.toggles.includes(e.id)).map(e=>nF.eq(e.id,!0));return[...i,...a,...o,...s]},fF=e=>e.length===0?``:vn(nF.and(...e)),pF=(e,t,n=[],r=new Date,i=Hn())=>fF([...dF(e,t,r,i),...n]),mF=e=>e.kind===`and`?e.args.flatMap(mF):[e],hF=e=>e.field.path.join(`.`),gF=e=>e.kind===`compare`&&e.op===`=`&&e.value.kind===`boolean`&&e.value.value,_F=(e,t)=>{let n=e.kind===`or`?e.args:[e];if(!n.every(gF))return;let r=n.map(hF),i=t.get(r[0]);return i!==void 0&&r.every(e=>t.get(e)===i)?{group:i,fields:r}:void 0},vF=e=>e.kind===`number`?String(e.raw):e.kind===`string`?String(e.value):void 0,yF=(e,t,n)=>{let r=e.value;if(r.kind===`now`&&r.offset?.sign===`-`){let{amount:e,unit:t}=r.offset.duration;return Object.entries(iF).find(([,n])=>n.amount===e&&n.unit===t)?.[0]}if(r.kind===`timestamp`)return sF.find(e=>cF(oF(e,t,n),`timestamp`,n)===r.value);if(r.kind===`string`)return sF.find(e=>oF(e,t,n)===r.value)},bF=(e,t,n=new Date,r=Hn())=>{let i=Te(t);if(!i.ok)return{ok:!1,errors:i.errors};let a={facets:{},toggles:[]},o=[],s=new Set(e.facets.filter(e=>!e.flags).map(e=>e.id)),c=new Map(e.facets.filter(e=>e.flags).flatMap(e=>e.options.map(t=>[t.value,e.id]))),l=new Set((e.toggles??[]).map(e=>e.id)),u=new Set((e.ranges??[]).map(e=>e.id)),d=new Map,f,p;for(let t of i.ast?mF(i.ast):[]){let i=_F(t,c);if(i&&!a.facets[i.group])a.facets[i.group]=i.fields;else if(t.kind===`compare`&&s.has(hF(t))&&t.op===`=`&&vF(t.value)!==void 0)a.facets[hF(t)]=[...a.facets[hF(t)]??[],vF(t.value)];else if(t.kind===`in`&&s.has(hF(t))&&t.values.every(e=>vF(e)!==void 0))a.facets[hF(t)]=[...a.facets[hF(t)]??[],...t.values.map(e=>vF(e))];else if(t.kind===`compare`&&e.dateField===hF(t)&&t.op===`>=`&&yF(t,n,r)&&!a.date)a.date=yF(t,n,r),f=t;else if(t.kind===`compare`&&e.dateField===hF(t)&&t.op===`<`&&(t.value.kind===`timestamp`||t.value.kind===`string`)&&t.value.value===cF(oF(`today`,n,r),t.value.kind===`string`?`date`:`timestamp`,r))p=t;else if(t.kind===`compare`&&l.has(hF(t))&&t.op===`=`&&t.value.kind===`boolean`&&t.value.value)a.toggles.push(hF(t));else if(t.kind===`compare`&&u.has(hF(t))&&(t.op===`>=`||t.op===`<=`)&&t.value.kind===`number`){let e=d.get(hF(t))??{clauses:[]};t.op===`>=`?e.low=t.value.value:e.high=t.value.value,e.clauses.push(t),d.set(hF(t),e)}else o.push(t)}a.date===`yesterday`&&!p&&(o.push(f),a.date=void 0),p&&a.date!==`yesterday`&&o.push(p);for(let[e,t]of d)t.low!==void 0&&t.high!==void 0?a.ranges={...a.ranges,[e]:[t.low,t.high]}:o.push(...t.clauses);return{ok:!0,state:a,extras:o}},xF=[`integer`,`bigint`,`decimal`],SF=(e,t)=>{let n=e?.fields[t]?.type;return n!==void 0&&xF.includes(n)},CF=(e,t)=>e.kind===`range`||e.kind===`facets`&&SF(t,e.field),wF=e=>e.secondary?{secondary:!0}:{},TF=e=>({id:e.field,label:e.field,min:0,max:0,step:1,histogram:[],format:String,...wF(e)}),EF=(e,t)=>{let n=e?.filters??[],r=n.find(e=>e.kind===`dateRange`);return{facets:n.flatMap(e=>e.kind===`facets`&&!CF(e,t)?[{id:e.field,label:e.field,options:[],searchable:e.search,...t?.fields[e.field]?.type===`relation`&&{combobox:!0},...wF(e)}]:e.kind===`flags`?[{id:e.fields.join(`|`),label:e.label,options:e.fields.map(e=>({value:e,label:e,count:0})),flags:!0,...wF(e)}]:[]),ranges:n.flatMap(e=>e.kind!==`flags`&&CF(e,t)?[TF(e)]:[]),...r&&{dateField:r.field,...r.secondary&&{dateSecondary:!0},dateKind:t?.fields[r.field]?.type===`date`?`date`:`timestamp`,...r.presets.length>0&&{datePresets:r.presets}},toggles:n.flatMap(e=>e.kind===`toggle`?[{id:e.field,label:e.field,...wF(e)}]:[])}},DF=(e,t)=>(e?.filters??[]).some(e=>e.kind===`range`&&e.field===t&&e.histogram),OF=(e,t)=>{let n=e?.fields[t],r=n?.suffix??``,i=n?.currency;return i===void 0?e=>`${n?.prefix??``}${e}${r}`:e=>`${P_(e*100,i).replace(`.00`,``)}${r}`},kF=m(),AF={start:0,end:0},jF=(e,t,n)=>{let r=bF(EF(t,e),n);return r.ok?Object.fromEntries(Object.entries(r.state.facets).filter(([t,n])=>e.fields[t]?.type===`relation`&&n.length>0)):{}},MF=(e,t,n)=>{let r=e=>t?.fields[e]?.label??H(e),i=EF(t,e);return{...i,facets:i.facets.map(i=>{if(i.flags)return{...i,options:i.options.map(e=>({...e,label:r(e.value)}))};let a=e.fields[i.id]?.enumValues??[],o=e.fields[i.id]?.type===`enum`?Object.fromEntries(a.map(e=>[e,ar(e,t?.fields[i.id]?.valueLabels)])):n[i.id]??{};return{...i,label:r(i.id),labels:o}}),ranges:(i.ranges??[]).map(e=>({...e,label:r(e.id),format:OF(t,e.id)})),toggles:i.toggles?.map(e=>({...e,label:r(e.id)}))}},NF=(e,t,n,r={})=>{let i=MF(e,t,r),a=bF(i,n);if(!a.ok)return[{key:`unreadable`,label:hP(`unreadableFilter`)}];let o=a.extras.map((e,t)=>({key:`extra:${t}`,label:e.kind===`search`?`"${e.text}"`:vn(e)}));return[...MP(i,a.state),...o]},PF=e=>Object.fromEntries(e.facets.filter(e=>!e.flags).map(e=>[e.id,{...e.labels,...Object.fromEntries(e.options.map(e=>[e.value,e.label]))}])),FF=(e,t,n)=>{if(typeof n!=`string`||n===``)return e;let r=kF.gt(t,{kind:`timestamp`,value:new Date(n).toISOString(),span:AF}),i=Te(e);if(!i.ok)throw Error(`The saved filter cannot be read: ${i.errors.map(e=>e.message).join(`; `)}`);return vn(i.ast?kF.and(i.ast,r):r)},IF=(e,t)=>typeof t!=`string`||t===``?!0:typeof e!=`string`||e===``?!1:new Date(e).getTime()>new Date(t).getTime(),LF=(e,t)=>{let n=F(),r=nn(),{resources:i,views:a}=c(),o=a[e.name],s=Object.entries(jF(e,o,t)),l=wt({queries:s.map(([t,o])=>{let s=i[e.fields[t].relation.resource];return{queryKey:I.labels(`chips:${e.name}.${t}`,o.join(`,`)),enabled:s!==void 0,queryFn:async()=>Object.fromEntries(await rb(r,n,s,o,a[s.name]))}})});return NF(e,o,t,Object.fromEntries(s.flatMap(([e],t)=>l[t]?.data?[[e,l[t].data]]:[])))},RF=(e,t)=>({record:Object.fromEntries(Object.entries(t).filter(([t])=>Object.hasOwn(e.fields,t))),etag:typeof t.etag==`string`?t.etag:``,...typeof t.permissions==`object`&&t.permissions!==null&&{permissions:t.permissions}}),zF=e=>{let t=nn();return(0,W.useCallback)(n=>t.setQueryData(I.recordPreview(e.name,Nn(xr(e,n))),RF(e,n)),[t,e])},BF={wallet:lf,"file-text":vl,send:cd,ruler:nd,bed:Xs,bath:Js,house:El,"door-open":Xc,"land-plot":Il,leaf:Hl,tag:Rd,key:Ml,calendar:gc,heart:wl,history:Qu,bell:nc,bookmark:uc,"external-link":ol,ban:Ks,play:Iu,stop:Od,power:Wu,restart:ed,terminal:Hd,camera:vc,"hard-drive":Sl,server:ud,network:wu,archive:Os,copy:Wc,"arrow-right-left":Ps,download:Qc,upload:Jd,cpu:Kc,memory:cu,plug:Bu,wrench:hf,plus:Hu,table:Pd},VF=e=>e!==void 0&&Object.hasOwn(BF,e)?BF[e]:void 0,HF=({target:e,id:t})=>(0,q.jsx)(q.Fragment,{children:mb(e,t)??t}),UF=()=>{let{path:e,params:t,basePath:n,navigate:r}=le(),i=(0,W.useMemo)(()=>Of(e,t),[e,t]),a=Cg(new URL(t.size>0?`${e}?${t}`:e,`http://local`).href),o=i?i.next:a,s=(0,W.useCallback)((e=`sign-in`,t)=>r(Df({step:e,next:o}),t),[r,o]);return{address:i,next:o,open:s,link:(0,W.useCallback)((e=`sign-in`,t)=>({href:`${n}${Df({step:e,next:o})}`,onFollow:()=>s(e,t)}),[n,o,s]),leave:(0,W.useCallback)(()=>r(o??`/`,{replace:!0}),[r,o])}},WF=({benefits:e})=>e&&e.length>0?(0,q.jsx)(`ul`,{className:`flex flex-col gap-2 text-left`,children:e.map(e=>(0,q.jsxs)(`li`,{className:`flex items-start gap-2`,children:[(0,q.jsx)(xi,{className:`mt-0.5 size-4 shrink-0 text-primary`,"aria-hidden":!0}),e]},e))}):null,GF=({prompt:e})=>{let{canSignUp:t}=Y(),{link:n}=UF(),r=zn({variant:`primary`}),i=e.signUp?(0,q.jsx)(`a`,{href:e.signUp.href,target:`_blank`,rel:`noreferrer`,className:r,children:e.signUp.label}):t&&(0,q.jsx)(Jn,{to:n(`sign-up`),className:r,children:J(`createAnAccount`)});return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(Jn,{to:n(),className:i?zn():r,children:J(`signIn`)}),i]})},KF=e=>{let{prompt:t}=e,n=(0,W.useId)();if(e.as===`dialog`)return(0,q.jsx)(g_,{title:t.title,description:t.description,open:e.open,onClose:e.onClose,actions:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(P,{onClick:e.onClose,children:J(`notNow`)}),(0,q.jsx)(GF,{prompt:t})]}),children:(0,q.jsx)(WF,{benefits:t.benefits})});let r=VF(t.icon)??eu;return(0,q.jsxs)(`section`,{"aria-labelledby":n,className:`mx-auto flex w-full max-w-md flex-col items-center gap-4 px-5 py-10 text-center sm:py-16`,children:[(0,q.jsx)(`span`,{className:`flex size-12 items-center justify-center rounded-full bg-primary/10 text-primary`,children:(0,q.jsx)(r,{className:`size-6`,"aria-hidden":!0})}),(0,q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,q.jsx)(`h1`,{id:n,className:`text-lg font-semibold`,children:t.title}),(0,q.jsx)(`p`,{className:`text-muted-foreground`,children:t.description})]}),(0,q.jsx)(WF,{benefits:t.benefits}),(0,q.jsx)(`div`,{className:`mt-2 flex w-full flex-col-reverse gap-2 sm:w-auto sm:flex-row sm:justify-center [&>*]:min-h-11 sm:[&>*]:min-h-0`,children:(0,q.jsx)(GF,{prompt:t})})]})},qF=m(),JF=e=>{if(typeof e==`string`||typeof e==`number`)return e;if(e&&typeof e==`object`&&`id`in e)return JF(e.id)},YF=(e,t,n)=>n.flatMap(n=>{let r=JF(n[t]);return r===void 0?[]:[{key:Nn(xr(e,n)),target:r}]}),XF=(e,t)=>e.find(e=>Nn(e.target)===t),ZF=(e,t)=>[...e,{key:``,target:t}],QF=(e,t)=>e.filter(e=>Nn(e.target)!==t),$F=(e,t)=>{let[n]=e.primaryKey;if(e.primaryKey.length!==1||n===void 0)throw Error(`${e.name} has a composite key, so its saved records cannot be listed`);let r=[...new Set(t.map(e=>e.target))];return r.length===0?void 0:qF.in(n,r)},eI=(e,t)=>I.list(e,``,``,500,`saved:${t}`),tI=(e,t,n)=>{let r=F(),i=c().resources[e];return Tt({queryKey:eI(e,t),enabled:n&&i!==void 0,queryFn:async()=>{let n=[],a;do{let o=await r.list(e,{pageSize:500,fields:[...i.primaryKey,t],...a&&{pageToken:a}});n.push(...o.items),a=o.nextPageToken||void 0}while(a);return YF(i,t,n)}})},nI=B(`app/saved`),rI=e=>e instanceof Error?e.message:nI(`somethingWrong`),iI=(e,t,n)=>{let r=c(),i=F(),a=nn(),o=nS(),s=qr(),{resource:l,field:u}=e,d=r.permissions[l],f=r.resources[l]!==void 0&&d!==void 0&&iS(d,`create`)&&iS(d,`delete`),p=r.signIn?.[l]?.signIn,m=tI(l,u,f),h=m.data&&XF(m.data,t),g=eI(l,u),_=en({mutationFn:async e=>{e?await i.remove(l,e.key):await i.create(l,{[u]:n})},onMutate:async e=>{await a.cancelQueries({queryKey:g,exact:!0});let r=a.getQueryData(g);return a.setQueryData(g,(r=[])=>e?QF(r,t):ZF(r,n)),{before:r}},onError:(e,t,n)=>{a.setQueryData(g,n?.before),o.show({state:`error`,title:nI(t?`couldNotTakeOff`:`couldNotSave`),description:rI(e)})},onSettled:()=>s(l)});return{mode:f?`save`:p?`sign-in`:void 0,prompt:p,saved:h!==void 0,ready:m.data!==void 0&&!_.isPending,toggle:()=>_.mutate(h)}},aI=({favorite:e,recordKey:t,target:n,className:r})=>{let i=iI(e,t,n),[a,o]=(0,W.useState)(!1);if(!i.mode)return null;let s=e.label??nI(`favorite`),c=U(`absolute right-2 top-2 flex size-8 items-center justify-center rounded-full bg-background/85 text-foreground shadow-sm transition-colors hover:bg-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/30`,r);return i.mode===`sign-in`?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`button`,{type:`button`,"aria-label":s,"aria-haspopup":`dialog`,className:c,onClick:()=>o(!0),children:(0,q.jsx)(wl,{className:`size-4`,"aria-hidden":!0})}),(0,q.jsx)(KF,{as:`dialog`,prompt:i.prompt,open:a,onClose:()=>o(!1)})]}):(0,q.jsx)(`button`,{type:`button`,"aria-label":s,"aria-pressed":i.saved,"aria-disabled":!i.ready,className:c,onClick:()=>i.ready&&i.toggle(),children:(0,q.jsx)(wl,{className:U(`size-4`,i.saved&&`fill-current text-danger`),"aria-hidden":!0})})},oI=6,sI=(e,t,n)=>{let r=e.bottom+oI;return{top:r+t.height>n.height-oI?Math.max(oI,e.top-oI-t.height):r,left:Math.max(oI,Math.min(e.left,n.width-oI-t.width))}},cI=(e,t)=>{let n=Ae(e).find(e=>e.kind===`cards`);if(!n)return{kind:`cards`,name:`dot`,badge:t};let{photos:r,favorite:i,dots:a,...o}=n;return o},lI=(e,t,n,r)=>(e?.list?.relatedColumns??[]).filter(e=>r.includes(e.name)).flatMap(e=>{let r=t[e.resource];return r?[{column:e,fields:l(r,n[r.name],cI(n[r.name],e.status))}]:[]}),uI=B(`app/related-dots`),dI=(e,{values:t,label:n,singular:r,plural:i})=>{if(e.length===0)return uI(`none`,{plural:i});let a=new Map;for(let t of e)t!=null&&a.set(String(t),(a.get(String(t))??0)+1);let o=[...t,...[...a.keys()].filter(e=>!t.includes(e))].filter(e=>a.has(e)).map(e=>`${a.get(e)} ${n(e)}`),s=`${e.length} ${e.length===1?r:i}`;return o.length===0?s:`${s}: ${o.join(`, `)}`},fI=`flex shrink-0 items-center justify-center rounded-full p-0.5 pointer-coarse:p-1.5`,pI=`size-2.5 rounded-full`,mI=`flex min-w-0 items-center gap-0.5`,hI=150,gI=288,_I=({shown:e,row:t,target:n,view:r,column:i,Card:a,onEnter:o,onLeave:s})=>{let c=(0,W.useRef)(null),[l,u]=(0,W.useState)();return(0,W.useLayoutEffect)(()=>{c.current&&u(sI(e.dot,{width:gI,height:c.current.offsetHeight},{width:window.innerWidth,height:window.innerHeight}))},[e]),(0,ls.createPortal)((0,q.jsx)(`div`,{ref:c,"data-dot-card":!0,onMouseEnter:o,onMouseLeave:s,style:{width:gI,...l??{visibility:`hidden`,top:0,left:0}},className:`fixed z-50 rounded-lg shadow-pop`,children:(0,q.jsx)(a,{model:n,view:r,display:cI(r,i.status),row:t})}),document.body)},vI=({column:e,records:t,target:n,view:r,wrap:i=!1,Card:a})=>{let o=(0,W.useMemo)(()=>t.map(e=>Ie(n,e)),[t,n]),[s,c]=(0,W.useState)(),l=(0,W.useRef)(void 0),u=(0,W.useRef)(`mouse`),d=(0,W.useRef)(null),f=n.fields[e.status],p=r?.fields[e.status],m=t=>f?Lr(f,t.record[e.status],p):``,h=Ke(n,r),g=e=>e.labels[h]??String(e.record[h]??e.key),_=(r?.names?.singular??H(n.name)).toLowerCase(),v=(r?.names?.plural??H(n.name)).toLowerCase(),y=dI(o.map(t=>t.record[e.status]),{values:f?.enumValues??[],label:e=>f?Lr(f,e,p):e,singular:_,plural:v}),b=()=>window.clearTimeout(l.current),x=()=>{b(),l.current=window.setTimeout(()=>c(void 0),hI)},S=(e,t)=>{b(),c({key:e,dot:t.getBoundingClientRect()})};(0,W.useEffect)(()=>b,[]),(0,W.useEffect)(()=>{if(!s)return;let e=()=>c(void 0),t=t=>t.key===`Escape`&&e(),n=t=>{let n=t.target;!d.current?.contains(n)&&!n?.closest?.(`[data-dot-card]`)&&e()};return document.addEventListener(`keydown`,t),document.addEventListener(`pointerdown`,n),document.addEventListener(`scroll`,e,!0),window.addEventListener(`resize`,e),()=>{document.removeEventListener(`keydown`,t),document.removeEventListener(`pointerdown`,n),document.removeEventListener(`scroll`,e,!0),window.removeEventListener(`resize`,e)}},[s]);let C=e=>t=>{u.current===`touch`&&s?.key!==e&&(t.preventDefault(),S(e,t.currentTarget))},w=e=>{e.relatedTarget?.closest?.(`[data-dot-card]`)||x()},T=s&&o.find(e=>e.key===s.key);return(0,q.jsxs)(`div`,{ref:d,className:U(mI,i&&`pointer-events-none flex-wrap`),onClick:e=>e.stopPropagation(),onPointerDown:e=>u.current=e.pointerType,children:[(0,q.jsx)(`span`,{className:`sr-only`,children:y}),o.map(t=>{let r=t.record[e.status],i=Jr(p?.valueColors,r);return(0,q.jsx)(Ue,{to:{kind:`record`,resource:n.name,key:t.key},"aria-label":`${g(t)}, ${m(t)}`,onPointerEnter:e=>e.pointerType!==`touch`&&S(t.key,e.currentTarget),onPointerLeave:e=>e.pointerType!==`touch`&&x(),onFocus:e=>e.currentTarget.matches(`:focus-visible`)&&S(t.key,e.currentTarget),onBlur:w,onClick:C(t.key),className:U(fI,`pointer-events-auto focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40`),children:(0,q.jsx)(`span`,{"aria-hidden":!0,style:i===void 0?void 0:{backgroundColor:i},className:U(pI,i===void 0&&ji[ei(p?.valueColors,r)],s?.key===t.key&&`ring-2 ring-foreground/30`)})},t.key)}),s&&T&&(0,q.jsx)(_I,{shown:s,row:T,target:n,view:r,column:e,Card:a,onEnter:b,onLeave:x})]})},yI=({count:e})=>(0,q.jsx)(`span`,{"aria-hidden":!0,className:U(mI,`invisible flex-wrap`),children:Array.from({length:e},(e,t)=>(0,q.jsx)(`span`,{className:fI,children:(0,q.jsx)(`span`,{className:pI})},t))}),bI=`flex flex-col gap-1.5`,xI=({dots:e})=>(0,q.jsx)(`span`,{className:bI,children:e.map(({column:e,records:t})=>(0,q.jsx)(yI,{count:t.length},e.name))}),SI=({dots:e,Card:t})=>{let{resources:n,views:r}=c();return(0,q.jsx)(`div`,{className:`pointer-events-none absolute inset-x-[calc(0.75rem+1px)] bottom-[calc(0.75rem+1px)] ${bI}`,children:e.map(({column:e,records:i})=>{let a=n[e.resource];return a&&(0,q.jsx)(vI,{column:e,records:i,target:a,view:r[a.name],Card:t,wrap:!0},e.name)})})},CI=(e,t,n)=>(t.dots??[]).flatMap(t=>{let r=e?.list?.relatedColumns?.find(e=>e.name===t),i=n.record[t];return r&&Array.isArray(i)&&i.length>0?[{column:r,records:i}]:[]}),wI=B(`carousel`),TI=`pointer-events-auto absolute top-1/2 flex size-7 -translate-y-1/2 items-center justify-center rounded-full bg-background/85 text-foreground shadow-sm opacity-0 transition-opacity group-hover/arrows:opacity-100 group-has-[:focus-visible]/arrows:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/30`,EI=`[@media(hover:none)]:opacity-100`,DI=({carousel:e,count:t,swipe:n,reveal:r,className:i})=>{if(t<2)return null;let{index:a,press:o}=e;return(0,q.jsxs)(`div`,{className:U(`group/arrows pointer-events-none absolute`,i),children:[(0,q.jsx)(`button`,{type:`button`,"aria-label":wI(`previousPhoto`),className:U(TI,r,!n&&EI,`left-2`),onClick:()=>o(-1),children:(0,q.jsx)(wc,{className:`size-4`,"aria-hidden":!0})}),(0,q.jsx)(`button`,{type:`button`,"aria-label":wI(`nextPhoto`),className:U(TI,r,!n&&EI,`right-2`),onClick:()=>o(1),children:(0,q.jsx)(qn,{className:`size-4`,"aria-hidden":!0})}),(0,q.jsxs)(`span`,{className:`absolute inset-x-0 bottom-2 flex justify-center`,"aria-live":`polite`,children:[(0,q.jsx)(`span`,{className:`sr-only`,children:wI(`photoOf`,{index:a+1,count:t})}),(0,q.jsx)(`span`,{className:`flex items-center gap-1 rounded-full bg-background/70 px-1.5 py-1 leading-none`,"aria-hidden":!0,children:Array.from({length:t},(e,t)=>(0,q.jsx)(`span`,{className:U(`size-1.5 rounded-full`,t===a?`bg-foreground`:`bg-foreground/35`)},t))})]})]})},OI=({carousel:e,swipe:t,slides:n,className:r,...i})=>(0,q.jsx)(`span`,{...i,ref:e.track,tabIndex:-1,onPointerDown:e.touch,onScroll:t=>e.scrolled(t.currentTarget),className:U(`flex size-full snap-x snap-mandatory outline-none [scrollbar-width:none] motion-safe:scroll-smooth [&::-webkit-scrollbar]:hidden`,t?`overflow-x-auto overscroll-x-contain`:`overflow-x-hidden`,r),children:n.map((e,t)=>(0,q.jsx)(`span`,{className:`block size-full shrink-0 snap-start snap-always`,children:e},t))}),kI=(e,t)=>t===0?0:(e%t+t)%t,AI=(e,t,n)=>t<=0||n===0?0:Math.min(n-1,Math.max(0,Math.round(e/t))),jI=e=>{let t=(0,W.useRef)(null),n=(0,W.useRef)(void 0),[r,i]=(0,W.useState)(0),a=e=>{let n=t.current;n&&n.scrollTo({left:e*n.clientWidth})};return{track:t,index:r,press:t=>{n.current=kI((n.current??r)+t,e),a(n.current)},touch:()=>{n.current=void 0},scrolled:t=>{i(AI(t.scrollLeft,t.clientWidth,e)),n.current!==void 0&&Math.abs(t.scrollLeft-n.current*t.clientWidth)<1&&(n.current=void 0)}}},MI=({value:e})=>{let t=jr(e,{width:320,height:240});return t?(0,q.jsx)(Iy,{image:t,loading:`lazy`,className:`size-full object-cover`}):null},NI=({children:e})=>(0,q.jsx)(`span`,{className:`-mx-3 -mt-3 mb-1.5 block aspect-[4/3] overflow-hidden rounded-t-lg border-b border-border bg-muted`,children:e}),PI=({value:e})=>(0,q.jsx)(NI,{children:(0,q.jsx)(MI,{value:e})}),FI=10,II=(e,t)=>{let n=vr(e)?e.uri:void 0,r=t.filter(e=>vr(e)&&e.uri!==n);return(n===void 0?r:[e,...r]).slice(0,FI)},LI=({photos:e,cover:t,swipe:n=!0,children:r})=>{let i=II(t,e),a=jI(i.length),o=(0,q.jsx)(NI,{children:(0,q.jsx)(OI,{"data-card-photos":!0,carousel:a,swipe:n,slides:i.map(e=>(0,q.jsx)(MI,{value:e}))})});return(0,q.jsxs)(q.Fragment,{children:[r(o),(0,q.jsx)(DI,{carousel:a,count:i.length,swipe:n,reveal:`group-has-[[data-card-photos]:hover]/card:opacity-100`,className:`inset-x-px top-px aspect-[4/3]`})]})},RI=({icon:e,children:t})=>{let n=VF(e);return(0,q.jsxs)(`dd`,{className:`flex items-center gap-1 tabular-nums`,children:[n&&(0,q.jsx)(n,{className:`size-3.5 shrink-0`,"aria-hidden":!0}),t]})},zI=({model:e,view:t,display:n,row:r,swipe:i=!0,mark:a})=>{let{image:o,title:s,subtitle:l,amount:u,badge:d,code:f,meta:p,footer:m,flags:h}=Ge(e,t,n),g=e=>t?.fields[e]?.label??H(e),{resources:_,views:v}=c(),y=n=>{let i=e.fields[n];if(!i)return``;let a=r.record[n],o=i.type===`relation`&&i.relation?_[i.relation.resource]:void 0;return o&&v[o.name]?.titleFrom&&a!=null?(0,q.jsx)(HF,{target:o,id:String(a)}):r.labels[n]===void 0&&ov(i,t?.fields[n])&&typeof a==`string`&&a!==``?av(a):i.type===`json`&&a!=null?_v(a):t?.fields[n]?.format===`url`&&typeof a==`string`&&a!==``?bv(e,t,n,r.record)??a:r.labels[n]??Lr(i,a,t?.fields[n])},{fields:b,components:x}=qy(),S=zF(e),C=n.card===void 0?void 0:x?.[n.card],w=n=>{let i=e.fields[n],a=i&&jS(b,i,t?.fields[n]);return a?(0,q.jsx)(RS,{shown:a,part:`display`,field:i,value:r.record[n],fallback:y(n)}):y(n)},T=n=>{let i=e.fields[n],a=r.record[n];return!i||!ov(i,t?.fields[n])||jS(b,i,t?.fields[n])||typeof a!=`string`||a===``?w(n):(0,q.jsx)(BS,{source:a,inLink:!0})},E=n=>{let i=e.fields[n],a=t?.fields[n],o=r.record[n];return!i||a?.format!==`badge`||jS(b,i,a)||o==null||o===``?w(n):(0,q.jsx)(ri,{value:o,hints:a,children:y(n)})},D=n=>{let i=e.fields[n];if(!i)return;if(r.labels[n]!==void 0||jS(b,i,t?.fields[n]))return(0,q.jsx)(`strong`,{className:`font-semibold text-foreground`,children:w(n)});let a=Oe(i,r.record[n],t?.fields[n]);return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`strong`,{className:`font-semibold text-foreground`,children:a.amount}),a.suffix]})},O=C?void 0:n.photos,k=d===void 0?void 0:r.record[d],ee=h.filter(e=>r.record[e]===!0),A=o===void 0?void 0:r.record[o],te=xe(r,u),ne=ye(r,f),re=oe(r,m),j=o!==void 0||O!==void 0,ie=n.favorite,M=C?[]:CI(t,n,r),ae=(t,n)=>(0,q.jsx)(Ue,{to:{kind:`record`,resource:e.name,key:r.key},onClick:()=>S(r.record),"data-card-link":!0,className:`${t} after:absolute after:inset-0 after:rounded-lg after:content-[''] focus-visible:outline-hidden`,children:n}),se=(n,i)=>(0,q.jsxs)(q.Fragment,{children:[j&&n,(0,q.jsxs)(`span`,{className:`flex items-start justify-between gap-2 ${ie&&!j?`pr-8`:``}`,children:[i?ae(`min-w-0 truncate font-medium`,w(s)):(0,q.jsx)(`span`,{className:`min-w-0 truncate font-medium`,children:w(s)}),d!==void 0&&k!=null&&(0,q.jsx)(ri,{value:k,hints:t?.fields[d],children:y(d)})]}),l!==void 0&&(0,q.jsx)(`span`,{className:t?.fields[l]?.markdown?`line-clamp-3 break-words text-muted-foreground`:t?.fields[l]?.multiline?`line-clamp-3 whitespace-pre-line break-words text-muted-foreground`:`truncate text-muted-foreground`,children:T(l)}),te!==void 0&&(0,q.jsx)(`span`,{className:`truncate tabular-nums text-muted-foreground`,children:D(te)}),ne!==void 0&&(0,q.jsx)(hb,{children:Ze(e.fields[ne],r.record[ne])??y(ne)}),p.length>0&&(0,q.jsx)(`dl`,{className:`mt-auto flex flex-wrap items-center gap-x-3 gap-y-0.5 pt-1 text-xs text-muted-foreground`,children:oe(r,p).map(e=>(0,q.jsxs)(`div`,{className:`flex gap-1`,children:[(0,q.jsx)(`dt`,{className:`sr-only`,children:g(e)}),(0,q.jsx)(RI,{icon:t?.fields[e]?.icon,children:E(e)})]},e))}),ee.length>0&&(0,q.jsx)(`ul`,{className:`flex flex-wrap gap-1`,"aria-label":N(`features`),children:ee.map(e=>(0,q.jsx)(`li`,{children:(0,q.jsx)(Ni,{dot:!1,children:g(e)})},e))}),re.length>0&&(0,q.jsx)(`span`,{className:`truncate text-xs text-muted-foreground ${p.length>0?``:`mt-auto`}`,children:re.map((e,t)=>(0,q.jsxs)(`span`,{children:[t>0&&(0,q.jsx)(`span`,{"aria-hidden":!0,children:` • `}),w(e)]},e))}),M.length>0&&(0,q.jsx)(xI,{dots:M})]}),ce=e=>(0,q.jsxs)(`div`,{className:`relative isolate flex h-full flex-col gap-1.5 rounded-lg border border-border bg-background p-3 hover:border-border-strong hover:bg-surface has-[[data-card-link]:focus-visible]:ring-2 has-[[data-card-link]:focus-visible]:ring-primary/30`,children:[a&&!j&&(0,q.jsx)(Ni,{tone:`blue`,className:`self-start`,children:a}),C?(0,q.jsxs)(q.Fragment,{children:[ae(`absolute inset-0`,(0,q.jsx)(`span`,{className:`sr-only`,children:w(s)})),(0,q.jsx)(FS,{name:n.card,fallback:se(e,!1),children:(0,q.jsx)(C,{row:r})})]}):se(e,!0)]});return(0,q.jsxs)(`div`,{className:O?`group/card relative h-full`:ie||a||M.length>0?`relative h-full`:`h-full`,children:[O?(0,q.jsx)(LI,{photos:r.photos??[],cover:A,swipe:i,children:t=>ce((0,q.jsx)(Ue,{to:{kind:`record`,resource:e.name,key:r.key},onClick:()=>S(r.record),tabIndex:-1,"aria-hidden":!0,className:`relative z-[1] block`,children:t}))},r.key):ce((0,q.jsx)(PI,{value:A})),a&&j&&(0,q.jsx)(Ni,{tone:`blue`,className:`pointer-events-none absolute top-2 left-2 shadow-sm`,children:a}),M.length>0&&(0,q.jsx)(SI,{dots:M,Card:zI}),ie&&(0,q.jsx)(aI,{favorite:ie,recordKey:r.key,target:xr(e,r.record),className:j?void 0:`right-1.5 top-1.5`})]})},BI=12,VI=3,HI=(e,t,n)=>{let r=Math.max(1,Math.min(256,t))+BI,i=Math.floor(Math.max(0,e)/r),a=Math.ceil((Math.max(0,e)+t)/r);return{start:Math.max(0,i-VI),end:Math.min(n,a+VI)}},UI=B(`app/record-row`),WI=({model:e,view:t,display:n,source:r,label:i,isNew:a})=>{let{total:o}=r,s=e=>HI(e.left,e.width,o),c=Qj(e=>{let{start:t,end:n}=s(e);return`${t}-${n}`}),{start:l,end:u}=s(c.view),d=PN({total:o,rowAt:r.rowAt,loadRows:r.loadRows,revision:r.revision,latencyMs:0},l,Math.max(l,u-1));return(0,q.jsx)(Yj,{scroll:c,label:i,children:Array.from({length:o},(r,i)=>{if(i<l||i>=u)return(0,q.jsx)(`li`,{"aria-hidden":!0},`place-${i}`);let s=d(i);if(!s)return(0,q.jsx)(`li`,{"aria-hidden":!0,children:(0,q.jsx)(L,{className:`h-full min-h-24 rounded-lg`})},`skeleton-${i}`);let c=Ie(e,s);return(0,q.jsx)(`li`,{"aria-posinset":i+1,"aria-setsize":o,className:`grid grid-cols-[minmax(0,1fr)]`,children:(0,q.jsx)(zI,{model:e,view:t,display:n,row:c,swipe:!1,mark:a?.(c)?UI(`new`):void 0})},c.key)})})},GI=m(),KI=(e,t)=>{if(!t)return e;let n=Te(e);if(!n.ok)throw Error(`The filter cannot be read: ${n.errors.map(e=>e.message).join(`; `)}`);return vn(n.ast?GI.and(n.ast,t):t)},qI=(e,t,{filter:n,sort:r,scope:i})=>({columns:$e(e,t,[]),filter:KI(n,i),orderBy:r||Pe(e,t)}),JI=(e,t)=>{let n=Ae(e).filter(e=>e.kind===`cards`);return n.find(e=>e.name===t)??n[0]??{kind:`cards`,name:`cards`}},YI=()=>(0,q.jsx)(`div`,{className:`flex gap-3 overflow-hidden`,children:Array.from({length:3},(e,t)=>(0,q.jsx)(L,{className:`h-24 w-64 shrink-0`},t))}),XI=({model:e,view:t,filter:n,sort:r=``,display:i,limit:a,chips:o=!0,empty:s,note:l,isNew:u,viewAll:d,scope:f,list:p})=>{let{resources:m,views:h}=c(),g=v(),_=JI(t,i),y=(0,W.useMemo)(()=>qI(e,t,{filter:n,sort:r,scope:f}),[e,t,n,r,f]),{orderBy:b}=y,x=mP({resources:m,views:h,model:e,...y}),S=LF(e,n),C=(t?.names?.singular??H(e.name)).toLowerCase(),w=t?.names?.plural??H(e.name),T=x.source?.total,E=(0,W.useMemo)(()=>x.source&&{...x.source,total:Math.min(x.source.total,a??1/0)},[x.source,a]);return(0,q.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3`,children:[o&&S.length>0||T!==void 0||l?(0,q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[o&&S.length>0?(0,q.jsx)(_P,{chips:S}):(0,q.jsx)(`span`,{}),(0,q.jsxs)(`p`,{className:`flex flex-wrap gap-x-3 text-muted-foreground`,children:[l&&(0,q.jsx)(`span`,{children:l}),T!==void 0&&(0,q.jsx)(`span`,{className:`tabular-nums`,children:`${T.toLocaleString(ci())} ${T===1?C:w.toLowerCase()}`})]})]}):null,x.isLoading?(0,q.jsx)(YI,{}):x.error?(0,q.jsx)(Oy,{title:UI(`couldNotLoad`),error:x.error}):!E||E.total===0?(0,q.jsx)(`p`,{className:`text-muted-foreground`,children:s??UI(`noneMatch`,{plural:w.toLowerCase()})}):(0,q.jsx)(WI,{model:e,view:t,display:_,source:E,label:w,isNew:u}),(0,q.jsxs)(Ue,{to:oM(e,t,g,{filter:n,orderBy:b,display:_.name,savedSearch:d?.savedSearch,resource:p}),onClick:d?.onOpen,className:`flex items-center gap-1 self-end font-medium text-primary-text hover:underline`,children:[d?.label??(0,q.jsxs)(q.Fragment,{children:[UI(`viewAll`),` `,(0,q.jsx)(`span`,{className:`sr-only`,children:w.toLowerCase()})]}),(0,q.jsx)(Is,{className:`size-3.5`,"aria-hidden":!0})]})]})},ZI=({model:e,view:t,empty:n,...r})=>{let{resources:i,views:a}=c(),o=ce(i,a,e.name),s=tI(e.name,t.listOf,!0),l=(t.names?.plural??H(e.name)).toLowerCase();if(!o.listOf)return null;if(s.error)return(0,q.jsx)(Oy,{title:UI(`couldNotLoadYour`,{plural:l}),error:s.error});if(!s.data)return(0,q.jsx)(L,{className:`h-24`});let u=$F(o.model,s.data);return u?(0,q.jsx)(XI,{...r,model:o.model,view:o.view,filter:``,scope:u,list:e.name,empty:n}):(0,q.jsx)(`p`,{className:`text-muted-foreground`,children:n??UI(`noneYet`,{plural:l})})},QI=e=>I.list(e,``,``,500,`saved-searches`),$I=(e,t)=>{let n=F(),{resources:r,views:i}=c(),a=r[e];return Tt({queryKey:QI(e),enabled:t&&a!==void 0,queryFn:async()=>{let t=[],r;do{let o=await n.list(e,{pageSize:500,orderBy:Pe(a,i[e]),...r&&{pageToken:r}});t.push(...o.items),r=o.nextPageToken||void 0}while(r);return t}})},eL=({model:e,of:t,target:n,targetView:r,row:i,recordKey:a})=>{let o=F(),s=qr(),c=String(i[t.filter]??``),l=LF(n,c),u=t.name===void 0?void 0:i[t.name],d=typeof u==`string`&&u!==``?u:void 0,f=t.unseen,p=en({mutationFn:t=>o.update(e.name,a,{[f.seenAt]:t},i.etag??`*`),onSettled:()=>s(e.name)}),m=Tt({...ti(o,n,f?FF(c,f.field,i[f.seenAt]):``),enabled:f!==void 0}),h=(r?.names?.plural??H(n.name)).toLowerCase(),g={model:n,view:r,filter:c,sort:f?`${f.field} desc`:void 0,limit:t.limit,chips:d!==void 0,empty:hP(`noneMatch`,{plural:h}),note:f&&m.data===0&&hP(`noNew`,{plural:h}),isNew:f&&(e=>IF(e.record[f.field],i[f.seenAt])),viewAll:{label:hP(`viewAll`),savedSearch:a,...f&&{onOpen:()=>p.mutate(new Date().toISOString())}}};return{name:d,chips:l,title:d??yP(l),body:g}},tL=({model:e,view:t,target:n,targetView:r,row:i})=>{let a=Nn(xr(e,i)),{name:o,chips:s,title:c,body:l}=eL({model:e,of:t.searchesOf,target:n,targetView:r,row:i,recordKey:a});return(0,q.jsxs)(`section`,{"aria-label":c,className:`flex flex-col gap-3 py-4 first:pt-0 last:pb-0`,children:[(0,q.jsx)(`h3`,{className:`text-[0.9375rem] font-semibold`,children:(0,q.jsx)(Ue,{to:{kind:`record`,resource:e.name,key:a},className:`hover:underline`,children:o??(0,q.jsx)(vP,{chips:s})})}),(0,q.jsx)(XI,{...l})]})},nL=({model:e,view:t,empty:n})=>{let{resources:r,views:i}=c(),a=t.searchesOf,o=r[a.resource],s=$I(e.name,!0),l=(t.names?.plural??H(e.name)).toLowerCase();return o?s.error?(0,q.jsx)(Oy,{title:hP(`couldNotLoadYour`,{plural:l}),error:s.error}):s.data?s.data.length===0?(0,q.jsx)(`p`,{className:`text-muted-foreground`,children:n??hP(`noneYet`,{plural:l})}):(0,q.jsx)(`div`,{className:`flex flex-col divide-y`,children:s.data.map(n=>(0,q.jsx)(tL,{model:e,view:t,target:o,targetView:i[a.resource],row:n},Nn(xr(e,n))))}):(0,q.jsx)(L,{className:`h-40`}):null},rL=({node:e,slots:t,className:n})=>{let{resource:r,filter:i=``,sort:a,limit:o,display:s,title:l,description:u,empty:d}=xT(e),{resources:f,views:p}=c(),m=f[r];if(!m)return null;let h=p[m.name];return(0,q.jsx)(Hw,{title:l,description:u,actions:t.actions,className:n,children:h?.searchesOf?(0,q.jsx)(nL,{model:m,view:h,empty:d}):h?.listOf===void 0?(0,q.jsx)(XI,{model:m,view:h,filter:i,sort:a,limit:o,display:s,empty:d}):(0,q.jsx)(ZI,{model:m,view:h,limit:o,display:s,empty:d})})},iL=e=>e.type===`boolean`||e.type===`enum`,aL=({model:e,fields:t,title:n,description:r,stored:i,className:a})=>{let{resources:o,views:s}=c(),l=re(e.name),u=F(),d=nS(),f=qr(),p=s[e.name],[m,h]=(0,W.useState)(i),[g,_]=(0,W.useState)(()=>vA(e,t,i?.record)),[v,y]=(0,W.useState)({}),[b,x]=(0,W.useState)(),[S,C]=(0,W.useState)(!1),w=(0,W.useRef)(Promise.resolve()),T=(0,W.useRef)(i),E=vA(e,t,void 0),D=m?iS(l,`update`)&&m.permissions?.update!==!1:iS(l,`create`),O=t.filter(t=>!iL(e.fields[t])),k=O.some(t=>m?uy(e.fields[t],g[t],m.record[t]):g[t]!==E[t]),ee=async t=>{let n=T.current;if(n){let r=await u.update(e.name,n.key,yA(e,t,n.record),n.etag??`*`);return{...ni(e,r.record),etag:r.etag,permissions:r.permissions??n.permissions}}let r=await u.create(e.name,by(e,o,{...E,...t}));return{...ni(e,r.record),etag:r.etag}},A=t=>{let r=w.current.then(async()=>{C(!0),x(void 0),await ee(t).then(async r=>{T.current=r,h(r),y(e=>Object.fromEntries(Object.entries(e).filter(([e])=>!Object.hasOwn(t,e)))),await f(e.name),d.show({state:`success`,title:z(`saved`,{label:n??z(`settings`)})})},e=>{y(t=>({...t,...hA(e)})),x(e)}),C(!1)});w.current=r},te=(t,n)=>{_(e=>({...e,[t]:n})),iL(e.fields[t])&&A({[t]:n})};return(0,q.jsx)(Hw,{title:n,description:r,className:U(`h-full`,a),children:(0,q.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),k&&A(Object.fromEntries(O.map(e=>[e,g[e]])))},children:[b!==void 0&&Object.keys(v).length===0&&(0,q.jsx)(Oy,{title:z(`notSaved`),error:b}),t.map(t=>{let n=e.fields[t],r=p?.fields[t]?.label??H(t),i=v[t];return(0,q.jsx)(Mv,{name:t,label:r,help:p?.fields[t]?.help,error:i&&mA(n,r,i),children:(0,q.jsx)(GC,{field:n,hints:p?.fields[t],value:g[t],stored:m?.record[t]??E[t],invalid:!!i,locked:!D||n.readOnly,resource:e.name,onChange:e=>te(t,e)})},t)}),D&&k&&(0,q.jsx)(`div`,{children:(0,q.jsx)(P,{type:`submit`,variant:`primary`,size:`sm`,loading:S,children:z(`save`)})})]})})},oL=e=>{let t=Zr(e.model,{});return t.isPending?(0,q.jsx)(Hw,{title:e.title,description:e.description,className:e.className,children:(0,q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,q.jsx)(L,{className:`h-4 w-1/2`}),(0,q.jsx)(L,{className:`h-4 w-1/3`})]})}):t.error?(0,q.jsx)(Hw,{title:e.title,description:e.description,className:e.className,children:(0,q.jsx)(Oy,{title:z(`couldNotLoad`),error:t.error})}):(0,q.jsx)(aL,{...e,stored:t.data??void 0})},sL=({node:e,className:t})=>{let{resource:n,fields:r=[],className:i,...a}=xT(e),o=c().resources[n];return o?(0,q.jsx)(oL,{...a,model:o,fields:r.filter(e=>Object.hasOwn(o.fields,e)),stored:void 0,className:t}):null},cL=(e,t)=>lL(e,t?[t]:[]),lL=(e,t)=>{let{resources:n}=c(),r=F(),i=JSON.stringify(e),a=(0,W.useMemo)(()=>JSON.parse(i).map(Zp),[i]),o=e=>t.some(t=>`item`in t?typeof t.item==`object`&&t.item!==null&&Object.hasOwn(t.item,e):Object.hasOwn(t.model.fields,e)),s=[...new Set(a.flatMap(e=>e.ok?e.paths:[]))],l=new Map(s.flatMap(e=>{let t=tm(e,o);return t===void 0?[]:[[e,t]]})),u=s.filter(e=>!l.has(e)),d=[...new Set(l.values())].flatMap(e=>n[e]?[n[e]]:[]),f=u.map(e=>oT(t,e)),p=YT(u.map((e,t)=>{let n=f[t];return n&&`frame`in n?{scope:n.frame,path:n.path}:{scope:void 0,path:e}})),m=wt({queries:d.map(e=>ti(r,e))});return a.map(e=>{if(!e.ok)return!1;let t={};for(let n of e.paths){let e=l.get(n);if(e===void 0){let e=u.indexOf(n),r=f[e];if(r&&`item`in r){t[n]=r.item;continue}let i=p[e];if(i.state===`loading`)return;i.state===`ready`&&(t[n]=i.value);continue}let r=d.findIndex(t=>t.name===e);if(r===-1)t[n]=0;else if(m[r].isPending)return;else t[n]=m[r].data??0}return em(e,t)})},uL=(e,t)=>typeof e.props.fallback==`string`?e.props.fallback:t.fallback,dL=({node:e,children:t,slots:n,className:r})=>{let{when:i}=xT(e),[a]=lL([i],tT());if(a===void 0)return null;let o=a?t:uL(e,n);return o==null?null:r===void 0?(0,q.jsx)(q.Fragment,{children:o}):(0,q.jsx)(`div`,{className:r,children:o})},fL=(e,t)=>e.flatMap(e=>typeof e==`string`?[]:[String(Um(e,rT(t)).props.when)]),pL=({node:e,children:t,slots:n,className:r})=>{let i=tT(),a=lL(fL(e.children,i),i),o=a.findIndex(e=>e!==!1);if(o!==-1&&a[o]===void 0)return null;let s=o===-1?uL(e,n):t[o];return s==null?null:r===void 0?(0,q.jsx)(q.Fragment,{children:s}):(0,q.jsx)(`div`,{className:r,children:s})},mL=({children:e})=>(0,q.jsx)(q.Fragment,{children:e}),hL=`text-2xl font-semibold tracking-tight tabular-nums`,gL=({model:e,at:t,filter:n})=>{let{views:r}=c(),i=mE(t),a=Kr(e,n,!i),o=i??a;if(o.isPending)return(0,q.jsx)(L,{className:`h-8 w-16`});if(o.error)return(0,q.jsx)(`span`,{className:`text-danger-text`,children:z(`couldNotCount`)});let s=i?sM(i):a.data;return(0,q.jsx)(Ue,{to:RE(r[e.name],e.name,n),className:`${hL} hover:text-primary-text after:absolute after:inset-0 after:content-['']`,children:s.toLocaleString(ci())})},_L=({field:e,format:t})=>{let n=JT(e);return n.state===`loading`?(0,q.jsx)(L,{className:`h-8 w-16`}):n.state===`missing`?null:n.state===`plain`?(0,q.jsx)(`span`,{className:hL,children:Tk(n.value)}):(0,q.jsx)(`span`,{className:hL,children:(0,q.jsx)(vC,{model:n.model,field:n.field,value:n.value,format:t})})},vL=({node:e,at:t,className:n})=>{let{label:r,value:i,resource:a,filter:o,field:s,format:l,description:u}=xT(e),{resources:d}=c(),f=a===void 0?void 0:d[a];return(0,q.jsxs)(Hw,{className:U(`relative h-full`,n),bodyClassName:`flex flex-col`,children:[(0,q.jsx)(`p`,{className:`text-muted-foreground break-words`,children:r}),(0,q.jsxs)(`div`,{className:`mt-auto pt-1`,children:[i!==void 0&&(0,q.jsx)(`span`,{className:hL,children:i}),f&&(0,q.jsx)(gL,{model:f,...t!==void 0&&{at:t},filter:o}),s!==void 0&&(0,q.jsx)(_L,{field:s,format:l})]}),u&&(0,q.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:u})]})},yL=(e,t)=>{let n=e.position;if(!n||!iS(t,`update`))return;let r=e.fields[n.field];return r&&!r.readOnly?n.field:void 0},bL=(e,t)=>e.position?.within===void 0?yL(e,t):void 0,xL=(e,t,n)=>t.position?.within!==void 0&&e.field===t.position.within&&!e.through&&!e.from&&!e.filter?yL(t,n):void 0,SL=(e,t,n,r)=>{if(t===void 0||e?.list?.drag?.rank!==!0||r!==``)return!1;let i=Ve(n);return i.columnId===t&&i.direction===`asc`},CL=e=>e===null?`none`:`value:${e}`,wL=e=>e.data.current?.sortable!==void 0,TL=e=>{let t=zt(e),n=t.find(e=>e.data?.droppableContainer&&wL(e.data.droppableContainer));return n?[n]:t.length>0?t:Lt(e)},EL=(e,{context:{collisionRect:t,droppableRects:n,droppableContainers:r,over:i}})=>{let a=e.code===`ArrowRight`?1:e.code===`ArrowLeft`?-1:0;if(a===0||!t)return;e.preventDefault();let o=r.getEnabled(),s=o.filter(e=>!wL(e)).flatMap(e=>{let t=n.get(e.id);return t?[{id:e.id,rect:t}]:[]}).sort((e,t)=>e.rect.left-t.rect.left),c=t.left+t.width/2,l=i?.data.current?.sortable?.containerId??i?.id,u=l===void 0?s.findIndex(e=>e.rect.left<=c&&c<=e.rect.right):s.findIndex(e=>e.id===l),d=s[u+a];if(u===-1||!d)return;let f=DL(o,n,d.id)[0];return{x:d.rect.left+(d.rect.width-t.width)/2,y:f?.rect.top??d.rect.top}},DL=(e,t,n)=>e.filter(e=>e.data.current?.sortable?.containerId===n).flatMap(e=>{let n=t.get(e.id);return n?[{id:e.id,rect:n}]:[]}).sort((e,t)=>e.rect.top-t.rect.top),OL=(e,t)=>{let n=e.code===`ArrowDown`?1:e.code===`ArrowUp`?-1:0;if(n===0)return EL(e,t);let{droppableRects:r,droppableContainers:i,over:a}=t.context,o=a?.data.current?.sortable?.containerId??a?.id;if(o===void 0)return;let s=DL(i.getEnabled(),r,o),c=s[(a?.id===o?s.length:s.findIndex(e=>e.id===a?.id))+n];if(c)return e.preventDefault(),{x:c.rect.left,y:c.rect.top}},kL=(e,t,n,r)=>{let i=mt({queryKey:[...n,`display`],enabled:r,initialPageParam:0,queryFn:({pageParam:e})=>t(e),getNextPageParam:(e,t)=>e.rows.length===40&&t.length*40<(t[0]?.total??0)?t.length:void 0}),a=i.data?.pages??[];return{resource:e.name,rows:a.flatMap(t=>t.rows.map(t=>Ie(e,t))),total:a[0]?.total??0,loading:i.isPending,error:i.error,more:i.hasNextPage,loadMore:()=>void i.fetchNextPage()}},AL=({model:e,by:t,value:n,fields:r,filter:i,orderBy:a})=>{let{resources:o,views:s}=c(),l=mP({resources:o,views:s,model:e,columns:r,filter:Ee(i,t,n),orderBy:a});return kL(e,l.page,l.key,!0)},jL=(e,t)=>{if(!t)return e;let n=new Map(e.map(e=>[e.key,e])),r=new Set(t);return[...t.flatMap(e=>n.get(e)??[]),...e.filter(e=>!r.has(e.key))]},ML=({model:e,view:t,display:n,column:r,fields:i,filter:a,orderBy:o,limit:s,moves:c,movable:l,placeable:u,dragged:d})=>{let f=AL({model:e,by:n.by,value:r.value,fields:i,filter:a,orderBy:o}),m=p(e,t,n),h=new Set(f.rows.map(e=>e.key)),g=new Map(c.map(e=>[e.row.key,e])),_=f.rows.filter(e=>g.has(e.key)&&g.get(e.key).to!==r.value),v=c.filter(e=>e.to===r.value&&!h.has(e.row.key)).map(e=>e.row),y=f.rows.filter(e=>!_.includes(e)).map(e=>g.has(e.key)?g.get(e.key).row:e),b=c.findLast(e=>e.to===r.value&&e.order),x=jL([...v,...y],b?.order),S=x.slice(0,s),C=f.more||x.length>S.length,{setNodeRef:w,isOver:T}=un({id:CL(r.value),data:{column:r,rows:S,more:C}}),E=f.total-_.length+v.length;if(r.value===null&&!f.loading&&E===0&&!T)return null;let D=(t?.names?.plural??H(e.name)).toLowerCase(),O=t?.fields[n.by];return(0,q.jsxs)(`section`,{ref:w,"aria-label":`${r.label}, ${E}`,className:U(`flex w-72 shrink-0 snap-start flex-col gap-2 rounded-lg bg-surface p-2`,T&&`ring-2 ring-primary/30`),children:[(0,q.jsxs)(`header`,{className:`flex items-center justify-between gap-2 px-1 pt-0.5`,children:[(0,q.jsx)(`h2`,{className:`min-w-0 truncate text-body font-medium`,children:r.value===null?(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:r.label}):(0,q.jsx)(ri,{value:r.value,hints:O,children:r.label})}),!f.loading&&(0,q.jsx)(`span`,{className:`text-xs tabular-nums text-muted-foreground`,children:E.toLocaleString(ci())})]}),f.loading?Array.from({length:3},(e,t)=>(0,q.jsx)(L,{className:`h-20`},t)):f.error?(0,q.jsx)(Oy,{title:N(`couldNotLoadRows`),error:f.error}):S.length===0?(0,q.jsx)(`p`,{className:`px-1 py-4 text-center text-xs text-muted-foreground`,children:N(`noPlural`,{plural:D})}):(0,q.jsx)(Vt,{id:CL(r.value),items:S.map(e=>e.key),strategy:Mt,children:(0,q.jsx)(`ul`,{className:`-mb-2 flex flex-col`,children:S.map(n=>(0,q.jsx)(NL,{model:e,view:t,card:m,row:n,column:r,rows:S,more:C,draggable:(l||u)&&aS(n.record,`update`),placeable:u,dragged:d},n.key))})}),s===void 0&&f.more&&(0,q.jsx)(P,{size:`sm`,variant:`ghost`,onClick:f.loadMore,children:N(`showMore`)})]})},NL=({model:e,view:t,card:n,row:r,column:i,rows:a,more:o,draggable:s,placeable:c,dragged:l})=>{let{setNodeRef:u,setActivatorNodeRef:d,listeners:f,isDragging:p,isOver:m,active:h,transform:g,transition:_}=rn({id:r.key,data:{row:r,column:i,rows:a,more:o},disabled:{draggable:!s,droppable:!c}}),v=m&&h?.data.current?.column?.value!==i.value;return(0,q.jsx)(`li`,{ref:e=>{u(e),d(e?.querySelector(`a[data-card-link]`)??e)},...f,onDragStart:e=>e.preventDefault(),onClickCapture:e=>{l()&&(e.preventDefault(),e.stopPropagation())},style:{transform:g?`translate3d(${g.x}px, ${g.y}px, 0)`:void 0,transition:_},className:U(`relative pb-2`,s&&`cursor-grab touch-manipulation`,p&&`opacity-40`,v&&`before:absolute before:inset-x-0 before:-top-1 before:h-0.5 before:rounded-full before:bg-primary`),children:(0,q.jsx)(zI,{model:e,view:t,display:n,row:r,swipe:!1})})},PL=e=>e.kind===`and`?e.args.flatMap(PL):[e],FL=e=>e.kind===`string`?String(e.value):void 0,IL=(e,t)=>{if(e.kind===`compare`&&e.op===`=`&&e.field.path.join(`.`)===t){let t=FL(e.value);return t===void 0?void 0:[t]}if(e.kind===`in`&&e.field.path.join(`.`)===t){let t=e.values.map(FL);return t.every(e=>e!==void 0)?t:void 0}},LL=(e,t,n)=>{let r=Te(e);if(!r.ok||!r.ast)return n;let i=PL(r.ast).map(e=>IL(e,t)).filter(e=>e!==void 0);return n.filter(e=>i.every(t=>e.value!==null&&t.includes(e.value)))},RL=(e,t)=>t!==null&&Object.hasOwn(e,t)?e[t]:void 0,zL=B(`app/hand-order`),BL=(e,t,{title:n,place:r})=>!Tn(e)||e.status!==412?{state:`error`,title:t,description:o(e)}:n===void 0?{state:`warning`,title:t,description:zL(`orderChangedSince`,{place:r})}:{state:`warning`,title:zL(`notSaved`,{title:n}),description:zL(`orderChangedThere`,{place:r})},VL=(e,t,n)=>t.flatMap(({before:t,record:r,etag:i})=>{let a=n.filter(e=>Object.hasOwn(t,e)&&t[e]!==r[e]);return a.length===0?[]:[{op:`update`,resource:e.name,key:xr(e,r),data:Object.fromEntries(a.map(e=>[e,t[e]])),etag:i}]}),HL=async(e,t,n)=>{let r=[],i=``;do{let a=await e.search(t,{filter:n,pageSize:100,...i&&{pageToken:i}});r.push(...a.items),i=a.nextPageToken}while(i);return r},UL=(e,t)=>t===void 0?e:`(${e}) AND (${t})`,WL=async(e,t,n,r)=>{let i=t.position?.after;if(!i)return{after:[],before:[]};let a=t.primaryKey[0],o=xr(t,r),s=e=>Nn([e]),c=await HL(e,i.resource,UL(vn(f.or(f.eq(i.field,o),f.eq(i.key,o))),i.filter)),l=(e,t)=>c.flatMap(n=>s(n[e])===s(o)&&s(n[t])!==s(o)?[n[t]]:[]),u=l(i.field,i.key),d=l(i.key,i.field),[p,m]=await Promise.all([HL(e,t.name,UL(vn(f.in(a,[o,...u])),i.while)),d.length===0?[]:HL(e,t.name,vn(f.in(a,d)))]),h=e=>{let r=Nn(xr(t,e));return{key:r,rank:e[t.position.field],title:ke(t,n,e,r)}},g=p.some(e=>s(e[a])===s(o));return{after:p.filter(e=>s(e[a])!==s(o)).map(h),before:g?m.map(h):[]}},GL=(e,t,n,r,i,a=!1)=>{let o=t=>r[t]?xr(e,r[t]):null,s=a&&i===r.length-1;return{op:`move`,resource:e.name,field:t,key:xr(e,r[i]),after:o(i-1),...!s&&{before:o(i+1)},...n&&{filter:n}}},KL=(e,t)=>{let n=new Map;for(let r of e)if(r.op===`reorder`||r.op===`move`)for(let e of r.records){let r=t(e.record);n.has(r)||n.set(r,e.previous)}return n},qL=(e,t,n)=>{let r=e.findIndex(e=>e.key===t.key);return r===-1?[...e.slice(0,n),t,...e.slice(n)]:Ot(e,r,n)},JL=(e,t,n)=>{let r=e.findIndex(e=>e.key===t.key);return{order:qL(e,t,n),first:r===-1?n:Math.min(r,n),last:r===-1?n:Math.max(r,n)}},YL=(e,t,n,r,i,a,o,s,c)=>{let l=xr(e,i.record),u=o.findIndex(e=>e.key===i.key),d=GL(e,n,Ee(r,t,a.value),o.map(e=>e.record),u,s),f=c===void 0?[]:[{op:`reorder`,resource:e.name,field:n,keys:[l],start:c,etags:{[Nn(l)]:`*`}}];return[...(i.record[t]??null)===a.value?[]:[{op:`update`,resource:e.name,key:l,data:{[t]:a.value},etag:`*`}],...f,d]},XL=(e,t,n,r)=>{let i=t=>Nn(xr(e,t)),a=KL(r.results,i),o=new Map(n.map(e=>{let n=i(e.record);return[n,a.has(n)?{...e.record,[t]:a.get(n)}:e.record]})),s=new Map;for(let e of r.results){let t=e.op===`reorder`||e.op===`move`?e.records:e.op===`update`?[e]:[];for(let{record:e,etag:n}of t)s.set(i(e),{record:e,etag:n})}return[...s].flatMap(([e,t])=>{let n=o.get(e);return n?[{before:n,...t}]:[]})},ZL=B(`app/rank-after`),QL=e=>e!=null&&e!==``,$L=({model:e,rank:t,rows:n,row:r,index:i,bounds:a,title:o})=>{let s=n.some(e=>e.key===r.key)?n.length-1:n.length,c;for(let l=i;l<=s;l++){let{order:i,first:u,last:d}=JL(n,r,l),f=i.map(e=>e.record[t]),p=cs(f,u,d),m=new Map(i.map((t,n)=>[Nn(xr(e,t.record)),n>=p.first&&n<=p.last?p.start+n-p.first:f[n]])),h=e=>m.has(e.key)?m.get(e.key):e.rank,g=Number(m.get(Nn(xr(e,r.record)))),_=a.after.filter(e=>QL(h(e))&&Number(h(e))>=g),v=a.before.find(e=>QL(h(e))&&Number(h(e))<=g),y=v?ZL(`dependsOn`,{record:v.title,other:o}):_[0]&&ZL(`dependsOn`,{record:o,other:_[0].title});if(!y)return{place:{index:l},...c!==void 0&&{reason:c}};if(c??=y,l!==s||v)continue;let b=Math.max(..._.map(e=>Number(h(e))))+1;if(a.before.every(e=>!QL(h(e))||Number(h(e))>b))return{place:{index:l,bump:b},reason:c}}return{reason:c}},eR=({model:e,view:t,by:n,rank:r,filter:i,drop:a,labelOf:o,titleOf:s})=>{let c=F(),l=nS(),u=qr(),[d,f]=(0,W.useState)([]),p=(0,W.useRef)(void 0),m=e=>f(t=>t.filter(t=>t.row.key!==e)),h=r?[n,r]:[n],g=en({mutationFn:e=>e(),onError:e=>l.show(BL(e,N(`couldNotUndo`),{place:`board`})),onSettled:()=>u(e.name)}),_=async(t,r)=>{let i=a&&RL(a,r.value);if(!i)throw Error(`The column ${r.label} takes no cards`);let o=xr(e,t.record),s=typeof t.record.etag==`string`?t.record.etag:`*`,l=await i({resource:e.name,record:t.record,recordKey:o,etag:s,to:r.value,client:c});return{landed:(await c.get(e.name,o)).record[n]??null,...l&&{undo:l}}},v=(t,n)=>({landed:n.value,undo:()=>c.batchWrite(VL(e,t,h))}),y=(e,t,r)=>{let i={...e,record:{...e.record,[n]:t.value}},a=r?.map(e=>e.key);f(n=>[...n.filter(t=>t.row.key!==e.key),{row:i,to:t.value,...a&&{order:a}}])},b=async(n,i,a)=>{if(!e.position?.after)return{index:a.index};let o=await WL(c,e,t,n.record),u=$L({model:e,rank:r,rows:a.rows,row:n,index:a.index,bounds:o,title:s(n)}),d=!u.place||u.place.bump===void 0&&u.place.index===a.rows.findIndex(e=>e.key===n.key);if(u.reason!==void 0&&l.show({state:`warning`,title:d?zL(`notMoved`):zL(`movedToPlace`,{place:u.place.index+1}),description:u.reason}),!d)return u.place.index!==a.index&&y(n,i,JL(a.rows,n,u.place.index).order),u.place},x=async(t,a,o)=>{let s=await b(t,a,o);if(!s)return;let{order:l}=JL(o.rows,t,s.index);return v(XL(e,r,l,await c.batchWrite(YL(e,n,r,i,t,a,l,o.more,s.bump))),a)},S=en({mutationFn:async({row:t,to:i,place:o})=>{if(o&&!r)throw Error(`A board places a card only by its rank`);let s=t.record[n]??null;if(a&&i.value!==s)return _(t,i);if(o)return x(t,i,o);let l=typeof t.record.etag==`string`?t.record.etag:`*`,u=await c.update(e.name,xr(e,t.record),{[n]:i.value},l);return v([{before:t.record,record:u.record,etag:u.etag}],i)},onMutate:({row:e,to:t,place:n})=>y(e,t,n&&JL(n.rows,e,n.index).order),onSuccess:(e,{row:t,to:r})=>{if(!e)return;let{landed:i,undo:a}=e;p.current!==void 0&&l.dismiss(p.current),p.current=void 0;let s=t.record[n]??null,c=i===s?s===r.value?N(`orderChanged`):N(`stayedIn`,{column:o(i)}):N(`movedTo`,{column:o(i)});if(!a){l.show({state:`success`,title:c});return}let u=l.show({state:`success`,title:c,action:{label:N(`undo`),onClick:()=>{l.dismiss(u),p.current=void 0,g.mutate(a)}}});p.current=u},onError:(e,{row:t,to:r})=>{m(t.key);let i=(t.record[n]??null)===r.value?N(`couldNotReorder`):N(`couldNotMoveTo`,{to:r.label});l.show(BL(e,i,{place:`board`,title:s(t)}))},onSettled:async(t,n,{row:r})=>{await u(e.name),m(r.key)}});return{moves:d,move:(e,t,n)=>S.mutate({row:e,to:t,...n&&{place:n}})}},tR=(e,t)=>{let n=e.data.current;if(!n?.column||!n.rows)return;let r=n.more===!0;if(n.sortable)return{column:n.column,rows:n.rows,more:r,index:n.sortable.index};let i=n.rows.some(e=>e.key===t.key);return{column:n.column,rows:n.rows,more:r,index:i?n.rows.length-1:n.rows.length}},nR=({model:e,view:t,display:n,fields:r,filter:i,orderBy:a,limit:o})=>{let s=d(e,t,n),c=LL(i,n.by,s),l=p(e,t,n),u=re(e.name),{boardDrops:f}=qy(),m=t?.list?.drag,h=typeof m?.board==`string`?m.board:void 0,g=h===void 0?void 0:f?.[h],_=t=>iS(u,`update`)&&(m?.board===!0?!e.fields[n.by]?.readOnly:g!==void 0&&RL(g,t)!==void 0),v=c.some(e=>_(e.value)),y=w(e),b=m?.rank===!0&&y!==void 0&&bL(e,u)!==void 0,x=y?`${y} asc`:a,S=e=>s.find(t=>t.value===e)?.label??String(e),C=e=>String(e.labels[l.title]??e.record[l.title]??e.key),{moves:T,move:E}=eR({model:e,view:t,by:n.by,rank:y,filter:i,drop:g,labelOf:S,titleOf:C}),[D,O]=(0,W.useState)(),k=(0,W.useRef)(!1),ee=At(gn(It,{activationConstraint:{distance:4}}),gn($t,{activationConstraint:{delay:250,tolerance:5}}),gn(Pt,{keyboardCodes:{start:[`Space`],cancel:[`Escape`],end:[`Space`,`Enter`]},coordinateGetter:OL}));if(h!==void 0&&!g)return(0,q.jsx)(PS,{children:N.rich(`noDrop`,{drop:h})});let A=e=>c.find(t=>CL(t.value)===e),te=e=>e.record[n.by]??null,ne=(e,t)=>_(te(e))&&_(t.value),j=(e,t)=>{if(!t)return{over:N(`noColumn`)};let n=b?tR(t,e):void 0;if(!n)return{over:A(t.id)?.label??N(`noColumn`)};let r=n.rows.some(t=>t.key===e.key)?n.rows.length:n.rows.length+1;return{over:N(`placeOf`,{column:n.column.label,place:n.index+1,count:r}),place:N(`place`,{column:n.column.label,place:n.index+1})}},ie=(e,t)=>{let n=(b?tR(t,e)?.column:void 0)??A(t.id);return n!==void 0&&n.value!==te(e)&&!ne(e,n)};return(0,q.jsxs)(Kt,{sensors:ee,collisionDetection:TL,onDragStart:({active:e})=>{k.current=!0,O(e.data.current.row)},onDragEnd:({active:e,over:t})=>{O(void 0),setTimeout(()=>k.current=!1);let n=e.data.current.row;if(!t)return;let r=b?tR(t,n):void 0;if(!r){let e=A(t.id);e&&e.value!==te(n)&&ne(n,e)&&E(n,e);return}let i=r.rows.findIndex(e=>e.key===n.key);if(i!==-1||ne(n,r.column)){if(i===-1&&g)return E(n,r.column);i!==r.index&&E(n,r.column,{rows:r.rows,more:r.more,index:r.index})}},onDragCancel:()=>{O(void 0),setTimeout(()=>k.current=!1)},accessibility:{announcements:{onDragStart:({active:e})=>N(`pickedUp`,{title:C(e.data.current.row)}),onDragOver:({active:e,over:t})=>N(`isOver`,{title:C(e.data.current.row),over:j(e.data.current.row,t).over}),onDragEnd:({active:e,over:t})=>{let n=e.data.current.row;if(!t||ie(n,t))return N(`putBack`,{title:C(n)});let r=j(n,t);return N(`wasMovedTo`,{title:C(n),to:r.place??r.over})},onDragCancel:({active:e})=>N(`cancelled`,{title:C(e.data.current.row)})},screenReaderInstructions:{draggable:N(b?v?`boardAnywhere`:`boardWithin`:`boardAcross`)}},children:[(0,q.jsx)(`div`,{className:`relative min-w-0 flex-1 overflow-x-auto`,children:(0,q.jsx)(`div`,{className:`flex snap-x items-start gap-3 pb-2`,children:c.map(a=>(0,q.jsx)(ML,{model:e,view:t,display:n,column:a,fields:r,filter:i,orderBy:x,limit:o,moves:T,movable:_(a.value),placeable:b,dragged:()=>k.current},CL(a.value)))})}),(0,q.jsx)(cn,{children:D&&(0,q.jsx)(zI,{model:e,view:t,display:l,row:D,swipe:!1})})]})},rR=864e5,iR=e=>new Date(e).toISOString().slice(0,10),aR=e=>Date.parse(`${e}T00:00:00Z`),oR=(e,t)=>iR(aR(e)+t*rR),sR=e=>oR(e,-((new Date(aR(e)).getUTCDay()+6)%7)),cR=(e,t=0)=>{let n=new Date(aR(e));return iR(Date.UTC(n.getUTCFullYear(),n.getUTCMonth()+t,1))},lR=({scale:e,day:t})=>({scale:e,day:e===`month`?cR(t):sR(t)}),uR=(e,t,n=Hn())=>lR(e??{scale:`month`,day:Wn(t,n)}),dR=(e,t,n=Hn())=>lR({scale:e,day:Wn(t,n)}),fR=(e,t)=>e.scale===`month`?{scale:`month`,day:cR(e.day,t)}:{scale:`week`,day:oR(sR(e.day),7*t)},pR=e=>{let t=sR(e.scale===`month`?cR(e.day):e.day),n=(aR(e.scale===`month`?oR(sR(oR(cR(e.day,1),-1)),6):oR(t,6))-aR(t))/rR+1;return Array.from({length:n},(e,n)=>oR(t,n))},mR=e=>{let t=pR(e);return{from:t[0],to:oR(t.at(-1),1)}},hR=(e,t)=>t.fields[e.start]?.type===`timestamp`,gR=(e,t,n,r=Hn())=>{let i=hR(e,t),a=e=>new Date(wr(e,r)).toISOString().replace(`.000Z`,`Z`),o=e=>i?{kind:`timestamp`,value:a(e),span:{start:0,end:0}}:{kind:`string`,value:e,span:{start:0,end:0}},s=f.and(f.gte(e.start,o(n.from)),f.lt(e.start,o(n.to)));if(e.end===void 0)return vn(s);let c=i?f.gt(e.end,o(n.from)):f.gte(e.end,o(n.from));return vn(f.or(s,f.and(f.lt(e.start,o(n.from)),c)))},_R=(e,t)=>e===``?t:`(${e}) AND (${t})`,vR=e=>{if(typeof e!=`string`)return;let t=Date.parse(/^\d{4}-\d{2}-\d{2}$/.test(e)?`${e}T00:00:00Z`:e);return Number.isNaN(t)?void 0:t},yR=(e,t,n,r=Hn())=>{let i=vR(e[t.start]);if(i===void 0)return;let a=hR(t,n),o=e=>a?Wn(e,r):iR(e),s=o(i),c=t.end===void 0?void 0:vR(e[t.end]),l=c===void 0?s:o(a?c-1:c);return{first:s,last:l<s?s:l}},bR=(e,t,n,r,i=Hn())=>{let a=yR(e,t,n,i);return a?r.filter(e=>e>=a.first&&e<=a.last):[]},xR=(e,t)=>e.toSorted((e,n)=>(vR(e.record[t.start])??0)-(vR(n.record[t.start])??0)),SR=(e,t,n,r,i=Hn())=>{let a=new Map(r.map(e=>[e,[]]));for(let o of xR(e,t))for(let e of bR(o.record,t,n,r,i))a.get(e).push(o);return a},CR=(e,t,n,r,i,a=Hn())=>{let o=(aR(i)-aR(r))/rR,s=hR(t,n),c=e=>{let t=vR(e);if(t!==void 0)return s?new Date($n(t+Zn(t,a)+o*rR,a)).toISOString():oR(iR(t),o)},l=c(e[t.start]),u=t.end===void 0?void 0:c(e[t.end]);return{...l!==void 0&&{[t.start]:l},...u!==void 0&&{[t.end]:u}}},wR=({heading:e,unit:t,previous:n,today:r,next:i,scales:a,scalesLabel:o,linkTo:s,onView:c})=>{let l=(e,t,n,r,i)=>s?(0,q.jsx)(Ue,{to:s(e),className:t,"aria-label":n,"aria-current":i?`page`:void 0,children:r}):(0,q.jsx)(`button`,{type:`button`,className:t,"aria-label":n,"aria-pressed":i,onClick:()=>c?.(e),children:r}),u=zn({variant:`secondary`,size:`sm`});return(0,q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,q.jsx)(`h2`,{className:`text-sm font-medium`,children:e}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[l(n,u,N(`previousPeriod`,{unit:t}),(0,q.jsx)(wc,{className:`size-3.5`})),l(r,u,N(`today`),N(`today`)),l(i,u,N(`nextPeriod`,{unit:t}),(0,q.jsx)(qn,{className:`size-3.5`}))]}),(0,q.jsx)(`span`,{role:`group`,"aria-label":o,className:kv.group(),children:a.map(e=>(0,q.jsx)(W.Fragment,{children:l(e.view,kv.option(e.current),e.label,e.label,e.current)},e.label))})]})]})},TR=e=>{let t=pR(e),n=e=>Date.parse(`${e}T00:00:00Z`);return e.scale===`month`?mr(n(e.day)):Br(n(t[0]),n(t.at(-1)))},ER=({view:e,now:t,linkTo:n,onView:r})=>{let i=e.scale===`month`&&Wn(t,Hn()).startsWith(e.day.slice(0,7)),a=n=>n===`week`&&i?dR(`week`,t):uR({scale:n,day:e.day},t),o=(t,n)=>({view:a(t),label:n,current:e.scale===t});return(0,q.jsx)(wR,{heading:TR(e),unit:e.scale===`month`?`month`:`week`,previous:fR(e,-1),today:dR(e.scale,t),next:fR(e,1),scales:[o(`month`,N(`month`)),o(`week`,N(`week`))],scalesLabel:N(`calendarScale`),linkTo:n,onView:r})},DR=`day:`,OR=e=>`${DR}${e}`,kR=(e,t)=>`${e}@${t}`,AR=(e,{context:{active:t,collisionRect:n,droppableRects:r,over:i}})=>{let a={ArrowLeft:-1,ArrowRight:1,ArrowUp:-7,ArrowDown:7}[e.code],o=i?String(i.id).slice(4):t?.data.current?.day;if(a===void 0||!n||o===void 0)return;e.preventDefault();let s=r.get(OR(oR(o,a)));if(s)return{x:s.left+(s.width-n.width)/2,y:s.top+4}},jR=({day:e,count:t,children:n,more:r,inMonth:i,today:a,week:o})=>{let{setNodeRef:s,isOver:c}=un({id:OR(e)}),l=Date.parse(`${e}T00:00:00Z`);return(0,q.jsxs)(`section`,{ref:s,"aria-label":`${Gn(l)}, ${t}`,className:U(`flex min-w-0 flex-col gap-1 bg-background p-1`,o?`min-h-28 sm:min-h-64`:`min-h-24`,!i&&`bg-surface`,c&&`ring-2 ring-inset ring-primary/30`),children:[(0,q.jsxs)(`header`,{className:U(`flex items-center gap-1 px-0.5 text-xs`,i?`text-foreground`:`text-muted-foreground`),children:[o&&(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:ir(l)}),(0,q.jsx)(`span`,{"aria-current":a?`date`:void 0,className:U(`inline-flex size-5 items-center justify-center rounded-full tabular-nums`,a&&`bg-primary font-medium text-primary-foreground`),children:Number(e.slice(8))})]}),n,r]})},MR=(e,t,n,r)=>{let i=n.title??Ke(e,t),a=e.fields[i],o=r.labels[i]??(a?Lr(a,r.record[i],t?.fields[i]):``);return o===``?r.key:o},NR=(e,t,n,r)=>{let i=n.record[t.start];if(e.fields[t.start]?.type!==`timestamp`||typeof i!=`string`)return;let a=Date.parse(i);return Wn(a,Hn())===r?Vr(a):void 0},PR=({model:e,view:t,display:n,row:r,day:i,className:a})=>{let o=zF(e),s=NR(e,n,r,i);return(0,q.jsxs)(Ue,{to:{kind:`record`,resource:e.name,key:r.key},onClick:()=>o(r.record),className:U(`flex min-w-0 items-baseline gap-1 rounded-md border border-border bg-background px-1.5 py-0.5 text-xs hover:border-border-strong hover:bg-surface focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/30`,a),children:[s&&(0,q.jsx)(`span`,{className:`shrink-0 tabular-nums text-muted-foreground`,children:s}),(0,q.jsx)(`span`,{className:`min-w-0 truncate`,children:MR(e,t,n,r)})]})},FR=({movable:e,dragged:t,...n})=>{let{setNodeRef:r,setActivatorNodeRef:i,listeners:a,isDragging:o}=Et({id:kR(n.row.key,n.day),data:{row:n.row,day:n.day},disabled:!e});return(0,q.jsx)(`div`,{ref:e=>{r(e),i(e?.querySelector(`a`)??e)},...a,onDragStart:e=>e.preventDefault(),onClickCapture:e=>{t()&&(e.preventDefault(),e.stopPropagation())},className:U(`min-w-0`,e&&`cursor-grab touch-manipulation`,o&&`opacity-40`),children:(0,q.jsx)(PR,{...n})})},IR=({model:e,display:t,range:n,fields:r,filter:i})=>{let{resources:a,views:o}=c(),s=mP({resources:a,views:o,model:e,columns:r,filter:_R(i,gR(t,e,n)),orderBy:`${t.start} asc`}),l=kL(e,s.page,s.key,!0),u=l.more&&!l.loading&&l.rows.length<500;(0,W.useEffect)(()=>{u&&l.loadMore()},[u,l.rows.length]);let d=l.rows.length>500||l.rows.length===500&&l.more;return{rows:l.rows.slice(0,500),capped:d,loading:l.loading,error:l.error}},LR=(e,t)=>{let n=new Map(t.map(e=>[e.key,e.patch]));return e.map(e=>n.has(e.key)?{...e,record:{...e.record,...n.get(e.key)}}:e)},RR=(e,t)=>{let n=F(),r=nS(),i=qr(),[a,s]=(0,W.useState)([]),c=e=>s(t=>t.filter(t=>t.key!==e)),l=en({mutationFn:({row:t,patch:r})=>{let i=typeof t.record.etag==`string`?t.record.etag:`*`;return n.update(e.name,xr(e,t.record),r,i)},onMutate:({row:e,patch:t})=>s(n=>[...n.filter(t=>t.key!==e.key),{key:e.key,patch:t}]),onError:(e,{row:t,to:n})=>{c(t.key),r.show({state:`error`,title:N(`couldNotMoveTo`,{to:yr(Date.parse(`${n}T00:00:00Z`))}),description:o(e)})},onSettled:async(t,n,{row:r})=>{await i(e.name),c(r.key)}});return{moves:a,move:(n,r,i)=>l.mutate({row:n,patch:CR(n.record,t,e,r,i),to:i})}},zR=3,BR=({model:e,view:t,display:n,fields:r,filter:i,at:a,linkTo:o,now:s=Date.now()})=>{let[c,l]=(0,W.useState)(),u=uR(o?a:c,s),d=pR(u),f=IR({model:e,display:n,range:mR(u),fields:r,filter:i}),{moves:p,move:m}=RR(e,n),h=SR(LR(f.rows,p),n,e,d),g=iS(re(e.name),`update`)&&[n.start,n.end].every(t=>t===void 0||!e.fields[t]?.readOnly),[_,v]=(0,W.useState)(),y=(0,W.useRef)(!1),b=At(gn(It,{activationConstraint:{distance:4}}),gn($t,{activationConstraint:{delay:250,tolerance:5}}),gn(Pt,{keyboardCodes:{start:[`Space`],cancel:[`Escape`],end:[`Space`,`Enter`]},coordinateGetter:AR})),x=Wn(s,Hn()),S=u.scale===`week`,C=e=>yr(Date.parse(`${String(e).slice(OR(``).length)}T00:00:00Z`)),w=r=>MR(e,t,n,r.row),T={onDragStart:({active:e})=>N(`pickedUp`,{title:w(e.data.current)}),onDragOver:({active:e,over:t})=>N(`isOver`,{title:w(e.data.current),over:t?C(t.id):N(`noDay`)}),onDragEnd:({active:e,over:t})=>t?N(`wasMovedTo`,{title:w(e.data.current),to:C(t.id)}):N(`putBack`,{title:w(e.data.current)}),onDragCancel:({active:e})=>N(`cancelled`,{title:w(e.data.current)})},E=()=>{v(void 0),setTimeout(()=>y.current=!1)},D=({active:e})=>{y.current=!0,v(e.data.current)},O=({active:e,over:t})=>{E();let{row:n,day:r}=e.data.current,i=t?String(t.id).slice(OR(``).length):void 0;i&&i!==r&&m(n,r,i)},k=(e,t)=>{let n=uR({scale:`week`,day:e},s),r=N(`moreHidden`,{count:t}),i=`self-start rounded px-1 text-xs text-muted-foreground hover:text-foreground focus-visible:outline-2 focus-visible:outline-primary`;return o?(0,q.jsx)(Ue,{to:o(n),className:i,children:r}):(0,q.jsx)(`button`,{type:`button`,className:i,onClick:()=>l(n),children:r})};return(0,q.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-3`,children:[(0,q.jsx)(ER,{view:u,now:s,linkTo:o,onView:l}),f.error&&(0,q.jsx)(Oy,{title:N(`couldNotLoadRows`),error:f.error}),f.capped&&(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:N(`capped`,{limit:500,unit:u.scale})}),(0,q.jsxs)(Kt,{sensors:b,collisionDetection:TL,onDragStart:D,onDragEnd:O,onDragCancel:E,accessibility:{announcements:T,screenReaderInstructions:{draggable:N(`calendarInstructions`)}},children:[(0,q.jsxs)(`div`,{className:`overflow-hidden rounded-lg border border-border`,children:[!S&&(0,q.jsx)(`div`,{"aria-hidden":!0,className:`grid grid-cols-7 gap-px border-b border-border bg-border`,children:d.slice(0,7).map(e=>(0,q.jsx)(`span`,{className:`bg-surface px-1.5 py-1 text-xs font-medium text-muted-foreground`,children:ir(Date.parse(`${e}T00:00:00Z`))},e))}),(0,q.jsx)(`div`,{className:U(`grid gap-px bg-border`,S?`grid-cols-1 sm:grid-cols-7`:`grid-cols-7`),children:d.map(r=>{let i=h.get(r),a=S?i:i.slice(0,zR);return(0,q.jsx)(jR,{day:r,count:i.length,inMonth:S||r.startsWith(u.day.slice(0,7)),today:r===x,week:S,more:a.length<i.length&&k(r,i.length-a.length),children:f.loading?(0,q.jsx)(L,{className:`h-4`}):a.map(i=>(0,q.jsx)(FR,{model:e,view:t,display:n,row:i,day:r,movable:g&&aS(i.record,`update`),dragged:()=>y.current},i.key))},r)})})]}),(0,q.jsx)(cn,{children:_&&(0,q.jsx)(PR,{model:e,view:t,display:n,row:_.row,day:_.day})})]})]})},VR=864e5,HR=e=>Date.parse(`${e}T00:00:00Z`),UR=(e,t=0)=>{let n=new Date(HR(e));return new Date(Date.UTC(n.getUTCFullYear(),Math.floor(n.getUTCMonth()/3)*3+3*t,1)).toISOString().slice(0,10)},WR=({scale:e,day:t})=>({scale:e,day:e===`week`?sR(t):e===`month`?cR(t):UR(t)}),GR=(e,t,n=Hn())=>WR(e??{scale:`month`,day:Wn(t,n)}),KR=(e,t)=>{let{scale:n,day:r}=WR(e);return{scale:n,day:n===`week`?oR(r,7*t):n===`month`?cR(r,t):UR(r,t)}},qR=e=>{let t=WR(e).day,n=(HR(KR(e,1).day)-HR(t))/VR;return Array.from({length:n},(e,n)=>oR(t,n))},JR=e=>({from:WR(e).day,to:KR(e,1).day}),YR=(e,t,n,r=Hn())=>{let i=Wn(n,r),a=qR(e);return WR({scale:t,day:i>=a[0]&&i<=a.at(-1)?i:a[0]})},XR=e=>{let t=qR(e);return e.scale===`week`?Br(HR(t[0]),HR(t.at(-1))):e.scale===`month`?mr(HR(t[0])):rr(HR(t[0]),HR(cR(t.at(-1))))},ZR=e=>{let t=qR(e);if(e.scale===`week`)return t.map((e,t)=>({index:t,span:1,label:`${ir(HR(e))} ${Number(e.slice(8))}`}));if(e.scale===`month`)return t.map((e,t)=>({index:t,span:1,label:String(Number(e.slice(8))),...t%7!=0&&{minor:!0}}));let n=t.flatMap((e,t)=>e.endsWith(`-01`)?[t]:[]);return n.map((e,r)=>({index:e,span:(n[r+1]??t.length)-e,label:Hr(HR(t[e]))}))},QR=(e,t,n,r,i=Hn())=>{let a=yR(e,t,n,i),o=r[0],s=r.at(-1);if(!(!a||o===void 0||s===void 0||a.last<o||a.first>s))return{first:a.first<o?0:r.indexOf(a.first),last:a.last>s?r.length-1:r.indexOf(a.last),before:a.first<o,after:a.last>s,start:a.first}},$R=`none`,ez=(e,t,n,r)=>{let i=r.group,a=i===void 0?void 0:t.fields[i];if(i===void 0||!a)return[{key:``,rows:e}];let o=n?.fields[i],s=new Map;for(let t of e){let e=t.record[i],n=e==null||e===``,r=n?$R:`value:${String(e)}`,c=n?N(`noValue`,{label:o?.label??H(i)}):t.labels[i]??Lr(a,e,o),l=s.get(r)??{value:n?void 0:e,lane:{key:r,label:c,rows:[]}};l.lane.rows.push(t),s.set(r,l)}let c=a.enumValues??[],l=(e,t)=>e.value===void 0||t.value===void 0?Number(e.value===void 0)-Number(t.value===void 0):a.type===`enum`?c.indexOf(String(e.value))-c.indexOf(String(t.value)):a.type===`relation`?e.lane.label.localeCompare(t.lane.label):typeof e.value==`number`&&typeof t.value==`number`?e.value-t.value:String(e.value).localeCompare(String(t.value),void 0,{numeric:!0});return[...s.values()].toSorted(l).map(({lane:e})=>e)},tz=`grid grid-cols-1 sm:grid-cols-[12rem_minmax(0,1fr)]`,nz=(e,t)=>`${e/t*100}%`,rz=({ticks:e,days:t,today:n,label:r,trackRef:i})=>(0,q.jsxs)(`div`,{className:U(tz,`border-b border-border bg-surface`),children:[(0,q.jsx)(`span`,{className:`hidden truncate px-2 py-1 text-xs font-medium text-muted-foreground sm:block`,children:r}),(0,q.jsx)(`div`,{ref:i,"aria-hidden":!0,className:`relative h-6`,children:e.map(e=>(0,q.jsx)(`span`,{className:U(`absolute inset-y-0 items-center truncate px-1 text-xs tabular-nums text-muted-foreground`,e.index>0?`border-l border-border`:`border-border sm:border-l`,e.minor?`hidden sm:flex`:`flex`,e.span===1&&t[e.index]===n&&`font-medium text-primary`),style:{left:nz(e.index,t.length),width:nz(e.span,t.length)},children:e.label},e.index))})]}),iz=({ticks:e,days:t,today:n})=>{let r=t.indexOf(n);return(0,q.jsxs)(`div`,{"aria-hidden":!0,className:U(tz,`pointer-events-none absolute inset-0`),children:[(0,q.jsx)(`span`,{className:`hidden sm:block`}),(0,q.jsxs)(`div`,{className:`relative`,children:[r>=0&&(0,q.jsx)(`span`,{className:`absolute inset-y-0 bg-primary/10`,style:{left:nz(r,t.length),width:nz(1,t.length)}}),e.map(e=>(0,q.jsx)(`span`,{className:U(`absolute inset-y-0 w-px bg-border`,(e.minor||e.index===0)&&`hidden sm:block`),style:{left:nz(e.index,t.length)}},e.index))]})]})},az=({model:e,view:t,display:n,row:r,days:i,movable:a,dragged:o})=>{let s=QR(r.record,n,e,i);return(0,q.jsxs)(`div`,{className:U(tz,`relative border-b border-border last:border-b-0`),children:[(0,q.jsx)(`span`,{"aria-hidden":!0,className:`truncate px-2 pt-1 text-body sm:py-1.5`,children:MR(e,t,n,r)}),(0,q.jsx)(`div`,{className:`relative h-7`,children:s&&(0,q.jsx)(`div`,{className:`absolute top-1/2 -translate-y-1/2`,style:{left:nz(s.first,i.length),width:nz(s.last-s.first+1,i.length)},children:(0,q.jsx)(FR,{model:e,view:t,display:n,row:r,day:s.start,movable:a,dragged:o,className:U(s.before&&`rounded-l-none border-l-0`,s.after&&`rounded-r-none border-r-0`)})})})]})},oz=()=>[{scale:`week`,label:N(`week`)},{scale:`month`,label:N(`month`)},{scale:`quarter`,label:N(`quarter`)}],sz=({model:e,view:t,display:n,fields:r,filter:i,at:a,linkTo:o,now:s=Date.now()})=>{let[c,l]=(0,W.useState)(),u=GR(o?a:c,s),d=qR(u),f=ZR(u),p=IR({model:e,display:n,range:JR(u),fields:r,filter:i}),{moves:m,move:h}=RR(e,n),g=ez(xR(LR(p.rows,m),n),e,t,n),_=iS(re(e.name),`update`)&&[n.start,n.end].every(t=>t===void 0||!e.fields[t]?.readOnly),[v,y]=(0,W.useState)(),b=(0,W.useRef)(!1),x=(0,W.useRef)(0),S=(0,W.useRef)(null),C=()=>(S.current?.getBoundingClientRect().width??0)/d.length,w=e=>{let t=C();return t>0?Math.round(e/t):0},T=({transform:e})=>({...e,x:w(e.x)*C(),y:0}),E=At(gn(It,{activationConstraint:{distance:4}}),gn($t,{activationConstraint:{delay:250,tolerance:5}}),gn(Pt,{keyboardCodes:{start:[`Space`],cancel:[`Escape`],end:[`Space`,`Enter`]},coordinateGetter:(e,{currentCoordinates:t})=>{let n=e.code===`ArrowLeft`?-1:+(e.code===`ArrowRight`);if(n!==0)return e.preventDefault(),{x:t.x+n*C(),y:t.y}}})),D=Wn(s,Hn()),O=r=>MR(e,t,n,r.row),k=e=>yr(Date.parse(`${oR(e.day,x.current)}T00:00:00Z`)),ee={onDragStart:({active:e})=>N(`pickedUp`,{title:O(e.data.current)}),onDragMove:({active:e})=>N(`startsOn`,{title:O(e.data.current),day:k(e.data.current)}),onDragOver:()=>void 0,onDragEnd:({active:e})=>x.current===0?N(`putBack`,{title:O(e.data.current)}):N(`wasMovedTo`,{title:O(e.data.current),to:k(e.data.current)}),onDragCancel:({active:e})=>N(`cancelled`,{title:O(e.data.current)})},A=()=>{y(void 0),setTimeout(()=>b.current=!1)},te=({active:e})=>{b.current=!0,x.current=0,y(e.data.current)},ne=({delta:e})=>x.current=w(e.x),j=({active:t,delta:r})=>{A(),x.current=w(r.x);let{row:i}=t.data.current,a=yR(i.record,n,e);a&&x.current!==0&&h(i,a.first,oR(a.first,x.current))},ie=n.group===void 0?t?.names?.plural??H(e.name):t?.fields[n.group]?.label??H(n.group),M=!p.loading&&!p.error&&p.rows.length===0;return(0,q.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-3`,children:[(0,q.jsx)(wR,{heading:XR(u),unit:u.scale,previous:KR(u,-1),today:GR({scale:u.scale,day:D},s),next:KR(u,1),scales:oz().map(({scale:e,label:t})=>({view:YR(u,e,s),label:t,current:u.scale===e})),scalesLabel:N(`timelineScale`),linkTo:o,onView:l}),p.error&&(0,q.jsx)(Oy,{title:N(`couldNotLoadRows`),error:p.error}),p.capped&&(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:N(`capped`,{limit:500,unit:u.scale})}),(0,q.jsxs)(Kt,{sensors:E,modifiers:[T],onDragStart:te,onDragMove:ne,onDragEnd:j,onDragCancel:A,accessibility:{announcements:ee,screenReaderInstructions:{draggable:N(`timelineInstructions`)}},children:[(0,q.jsxs)(`div`,{className:`overflow-hidden rounded-lg border border-border`,children:[(0,q.jsx)(rz,{ticks:f,days:d,today:D,label:ie,trackRef:S}),(0,q.jsxs)(`div`,{className:`relative`,children:[(0,q.jsx)(iz,{ticks:f,days:d,today:D}),p.loading&&(0,q.jsxs)(`div`,{className:`relative flex flex-col gap-2 p-2`,children:[(0,q.jsx)(L,{className:`h-4`}),(0,q.jsx)(L,{className:`h-4`})]}),M&&(0,q.jsx)(`p`,{className:`relative px-2 py-3 text-xs text-muted-foreground`,children:N(`nothingIn`,{unit:u.scale})}),!p.loading&&g.map(r=>(0,q.jsxs)(`section`,{"aria-label":r.label,className:`relative border-b border-border last:border-b-0`,children:[r.label!==void 0&&(0,q.jsxs)(`h3`,{className:`flex items-center gap-1.5 border-b border-border bg-surface px-2 py-1 text-xs font-medium`,children:[r.label,(0,q.jsx)(`span`,{className:`tabular-nums text-muted-foreground`,children:r.rows.length})]}),r.rows.map(r=>(0,q.jsx)(az,{model:e,view:t,display:n,row:r,days:d,movable:_&&aS(r.record,`update`),dragged:()=>b.current},r.key))]},r.key))]})]}),(0,q.jsx)(cn,{children:v&&(0,q.jsx)(PR,{model:e,view:t,display:n,row:v.row,day:v.day})})]})]})},cz=({list:e,empty:t,loading:n,children:r})=>(0,q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:e.loading?n:e.error?(0,q.jsx)(Oy,{title:N(`couldNotLoadRows`),error:e.error}):e.rows.length===0?(0,q.jsx)(`p`,{className:`py-8 text-center text-muted-foreground`,children:t}):r}),lz=({list:e})=>(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-3 py-3 text-xs text-muted-foreground`,children:[(0,q.jsxs)(`span`,{children:[e.rows.length.toLocaleString(ci()),` of `,e.total.toLocaleString(ci())]}),e.more&&(0,q.jsx)(P,{size:`sm`,onClick:e.loadMore,children:N(`showMore`)})]}),uz=`grid grid-cols-[repeat(auto-fill,minmax(15rem,1fr))] gap-3`,dz=`relative flex snap-x snap-mandatory gap-3 overflow-x-auto pb-1`,fz=({model:e,view:t,display:n,list:r,row:i=!1,footer:a=!0})=>{let o=(t?.names?.plural??H(e.name)).toLowerCase();return(0,q.jsxs)(cz,{list:r,empty:N(`noneMatch`,{plural:o}),loading:(0,q.jsx)(`div`,{className:uz,children:Array.from({length:6},(e,t)=>(0,q.jsx)(L,{className:`h-24`},t))}),children:[(0,q.jsx)(`ul`,{className:i?dz:uz,"aria-label":t?.names?.plural??H(e.name),children:r.rows.map(r=>(0,q.jsx)(`li`,{className:U(i&&`w-64 shrink-0 snap-start`),children:(0,q.jsx)(zI,{model:e,view:t,display:n,row:r,swipe:!i})},r.key))}),a&&(0,q.jsx)(lz,{list:r})]})},pz=(0,W.createContext)(void 0),mz=({value:e,children:t})=>(0,q.jsx)(pz.Provider,{value:e,children:t}),hz=()=>{let e=(0,W.useContext)(pz);if(!e)throw Error(`useListDisplay is used inside a list display, which the list page draws`);return e},gz=()=>(0,W.useContext)(pz),_z=({display:e,list:t})=>{let{components:n}=qy(),r=n?.[e.component];return r?(0,q.jsx)(mz,{value:t,children:(0,q.jsx)(`div`,{className:`relative min-w-0 flex-1 overflow-x-auto`,children:(0,q.jsx)(FS,{name:e.component,children:(0,q.jsx)(r,{...u(e.props??{})})})})}):(0,q.jsx)(PS,{children:N.rich(`noComponent`,{component:e.component})})},vz=m(),yz={bounds:{south:-90,west:-180,north:90,east:180},zoom:0},bz=22,xz=e=>Math.floor(e*1e6)/1e6,Sz=e=>Math.ceil(e*1e6)/1e6,Cz=e=>((e+180)%360+360)%360-180,wz=(e,t)=>{let n=[vz.gte(e.latitude,xz(Math.max(t.south,-90))),vz.lte(e.latitude,Sz(Math.min(t.north,90)))];if(t.east-t.west>=360)return vz.and(...n);let r=vz.gte(e.longitude,xz(Cz(t.west))),i=vz.lte(e.longitude,Sz(Cz(t.east)));return Cz(t.west)<=Cz(t.east)?vz.and(...n,r,i):vz.and(...n,vz.or(r,i))},Tz=(e,t,n)=>{let r=vn(wz(t,n));return e.trim()===``?r:`(${e}) AND ${r}`},Ez=e=>Math.min(Math.max(Math.floor(e),0),bz),Dz=(e,t)=>{let n=[...e.map(e=>({south:e.latitude,west:e.longitude,north:e.latitude,east:e.longitude})),...t.map(e=>e.bounds)];if(n.length!==0)return{south:Math.min(...n.map(e=>e.south)),west:Math.min(...n.map(e=>e.west)),north:Math.max(...n.map(e=>e.north)),east:Math.max(...n.map(e=>e.east))}},Oz=e=>{if(typeof e==`number`)return e;if(typeof e==`string`&&e.trim()!==``)return Number(e)},kz=(e,t)=>{let n=Oz(e[t.latitude]),r=Oz(e[t.longitude]);if(n!==void 0&&r!==void 0&&Math.abs(n)<=90&&Math.abs(r)<=180)return{latitude:n,longitude:r}},Az=6371008.8,jz=64,Mz=(e,t)=>t.approximate===void 0?t.exact!==void 0&&e[t.exact]===!1:e[t.approximate]===!0,Nz=(e,t)=>{let n=t/Az,r=e.latitude*Math.PI/180,i=e.longitude*Math.PI/180;return{type:`Polygon`,coordinates:[Array.from({length:65},(e,t)=>{let a=t%jz/jz*2*Math.PI,o=Math.asin(Math.sin(r)*Math.cos(n)+Math.cos(r)*Math.sin(n)*Math.cos(a));return[(i+Math.atan2(Math.sin(a)*Math.sin(n)*Math.cos(r),Math.cos(n)-Math.sin(r)*Math.sin(o)))*180/Math.PI,o*180/Math.PI]})]}},Pz=e=>Array.isArray(e)&&e.length>=2&&typeof e[0]==`number`&&typeof e[1]==`number`&&Math.abs(e[0])<=180&&Math.abs(e[1])<=90,Fz=(e,t)=>Array.isArray(e)&&e.length>=t&&e.every(Pz),Iz=e=>Array.isArray(e)&&e.length>0&&e.every(e=>Fz(e,4)),Lz=e=>Array.isArray(e)&&e.length>0&&e.every(e=>Fz(e,2)),Rz=e=>{if(typeof e!=`string`)return e;try{return JSON.parse(e)}catch(e){if(e instanceof SyntaxError)return;throw e}},zz=e=>{let t=Rz(e);if(typeof t!=`object`||!t)return;let n=t.type===`Feature`?t.geometry:t;if(typeof n!=`object`||!n)return;let{type:r,coordinates:i}=n;if(r===`Polygon`&&Iz(i)||r===`MultiPolygon`&&Array.isArray(i)&&i.length>0&&i.every(Iz)||r===`LineString`&&Fz(i,2)||r===`MultiLineString`&&Lz(i))return{type:r,coordinates:i}},Bz=(e,t,n)=>{if(!Mz(e,t))return;let r=t.area===void 0?void 0:zz(e[t.area]);if(r)return r;let i=t.radius===void 0?void 0:Oz(e[t.radius]);return i!==void 0&&Number.isFinite(i)&&i>0?Nz(n,i):t.defaultRadius===void 0?void 0:Nz(n,t.defaultRadius)},Vz=(e,t)=>e.flatMap(e=>{let n=kz(e.record,t);if(!n)return[];if(!Mz(e.record,t))return[{key:e.key,...n}];let r=Bz(e.record,t,n);return[{key:e.key,...n,approximate:!0,...r&&{area:r}}]}),Hz=(e,t)=>{let n=[];for(let r of e){let e=n.find(e=>Math.hypot(e.at.x-r.x,e.at.y-r.y)<=t);e?e.keys.push(r.key):n.push({at:r,keys:[r.key]})}return n.map(e=>({keys:e.keys,at:e.at.key}))},Uz=(e,t)=>{if(!e)return;let n=new Set(t.map(e=>e.key)),r=e.keys.filter(e=>n.has(e));if(r.length===0)return;let i=r.indexOf(e.keys[e.index]);return{keys:r,index:Math.max(i,0)}},Wz=(e,t)=>({keys:e.keys,index:((e.index+t)%e.keys.length+e.keys.length)%e.keys.length}),Gz=({model:e,view:t,display:n,fields:r,filter:i,orderBy:a,area:o})=>{let s=F(),{resources:l,views:u}=c(),d={latitude:n.latitude,longitude:n.longitude},f=o?Tz(i,d,o.bounds):``,p=o?Ez(o.zoom):0;return Tt({queryKey:I.map(e.name,`${d.latitude},${d.longitude}`,p,f,a),enabled:o!==void 0,placeholderData:sn,queryFn:async()=>{let n=await s.map(e.name,{...d,zoom:p,filter:f,orderBy:a,labels:ab(l,u,e,r),photos:C(t)});return{rows:ob(l,e,r,E(e,n.items,n.photos),n.labels).map(t=>Ie(e,t)),buckets:n.buckets,total:n.totalSize}}})},Kz=(0,W.lazy)(()=>Ht(()=>import(`./records-map-CCHa0cjg.js`).then(e=>({default:e.RecordsMap})),__vite__mapDeps([47,1,3,8,48,14,6,5,49,50,51,52,53,35]))),qz=250,Jz=`flex size-8 items-center justify-center rounded-full border border-border bg-background hover:bg-surface focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/30`,Yz=({model:e,view:t,display:n,filter:r,orderBy:i,fields:a,at:o,onMove:s,footer:l=!0,flush:u=!1})=>{let d=c().maps,f=d?.style,[p,m]=(0,W.useState)(),[h,g]=(0,W.useState)(),_=BO(h,qz),[v,y]=(0,W.useState)(o===void 0),b=Gz({model:e,view:t,display:n,fields:a,filter:r,orderBy:i,area:v?yz:_}),x=b.isPlaceholderData?void 0:b.data,S=b.data?.rows??[],C=b.data?.buckets??[],w=Vz(S,n),T=v&&x?Dz(Vz(x.rows,n),x.buckets):void 0,E=ue(t,n),D=(t?.names?.plural??H(e.name)).toLowerCase(),O=(t?.names?.singular??H(e.name)).toLowerCase(),k=Uz(p,S),ee=k&&S.find(e=>e.key===k.keys[k.index]),A=new Set(w.filter(e=>e.approximate).map(e=>e.key)),te=e=>{let t=e.filter(e=>A.has(e)).length;return e.length===1?N(t===1?`showOneApproximate`:`showOne`,{singular:O}):t===0?N(`showMany`,{count:e.length,plural:D}):t===e.length?N(`showManyApproximate`,{count:e.length,plural:D}):N(`showManySomeApproximate`,{count:e.length,plural:D,near:t})},ne=e=>N(`zoomIn`,{count:e.toLocaleString(ci()),noun:e===1?O:D}),re=(0,W.useRef)(null),[j,ie]=(0,W.useState)(0);if((0,W.useLayoutEffect)(()=>ie(re.current?.offsetHeight??0),[ee?.key]),!f)return(0,q.jsx)(PS,{children:N(`needsStyle`)});let M=x?.total===0;return(0,q.jsxs)(`div`,{className:U(`flex h-full min-h-[36rem] flex-1 flex-col sm:min-h-[28rem]`,u&&`max-md:-mx-5 max-md:-mb-4 max-md:min-h-0`),children:[(0,q.jsxs)(`div`,{className:U(`relative min-h-0 flex-1 overflow-hidden rounded-lg border border-border bg-muted`,u&&`max-md:rounded-none max-md:border-0`),children:[(0,q.jsx)(W.Suspense,{fallback:null,children:(0,q.jsx)(Kz,{style:f,layers:d?.layers,initial:o,points:w,buckets:C,fit:T,onFitted:()=>y(!1),onMove:(e,t)=>{g(e),s?.(t)},selected:k?.keys,covered:k?j:0,onSelect:e=>m({keys:e,index:0}),onClear:()=>m(void 0),markerLabel:te,bucketLabel:ne})}),b.error&&(0,q.jsx)(`div`,{className:`absolute inset-x-3 top-3 z-10`,children:(0,q.jsx)(Oy,{title:N(`couldNotLoadRows`),error:b.error})}),M&&(0,q.jsx)(`div`,{className:`pointer-events-none absolute inset-x-3 top-3 z-10 flex justify-center`,children:(0,q.jsxs)(`p`,{className:`pointer-events-auto flex items-center gap-3 rounded-full border border-border bg-background px-4 py-1.5 text-muted-foreground shadow`,role:`status`,children:[N(v?`noneMatch`:`noneHere`,{plural:D}),!v&&(0,q.jsx)(P,{size:`sm`,onClick:()=>y(!0),children:N(`showAll`)})]})}),k&&ee&&(0,q.jsx)(`div`,{ref:re,className:`pointer-events-none absolute inset-x-3 bottom-3 z-10 flex justify-center`,children:(0,q.jsxs)(`div`,{className:`pointer-events-auto flex w-full max-w-[16rem] flex-col gap-2 sm:max-w-xs`,role:`group`,"aria-label":N(`chosen`,{singular:O}),children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-end gap-1.5`,children:[A.has(ee.key)&&(0,q.jsxs)(`span`,{className:`mr-auto flex items-center gap-1 rounded-full border border-border bg-background px-2 py-1 text-xs`,children:[(0,q.jsx)(Mc,{className:`size-3.5`,"aria-hidden":!0}),N(`approximatePosition`)]}),k.keys.length>1&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`button`,{type:`button`,"aria-label":N(`previous`),className:Jz,onClick:()=>m(Wz(k,-1)),children:(0,q.jsx)(wc,{className:`size-4`,"aria-hidden":!0})}),(0,q.jsxs)(`span`,{className:`rounded-full border border-border bg-background px-2 py-1 text-xs tabular-nums`,"aria-live":`polite`,children:[k.index+1,` / `,k.keys.length]}),(0,q.jsx)(`button`,{type:`button`,"aria-label":N(`next`),className:Jz,onClick:()=>m(Wz(k,1)),children:(0,q.jsx)(qn,{className:`size-4`,"aria-hidden":!0})})]}),(0,q.jsx)(`button`,{type:`button`,"aria-label":N(`close`),className:Jz,onClick:()=>m(void 0),children:(0,q.jsx)(Ci,{className:`size-4`,"aria-hidden":!0})})]}),(0,q.jsx)(`div`,{className:`shadow-lg`,children:(0,q.jsx)(zI,{model:e,view:t,display:E,row:ee})})]})})]}),l&&(0,q.jsx)(`p`,{className:`hidden py-3 text-xs text-muted-foreground md:block`,children:Xz(b.data,D)})]})},Xz=(e,t)=>{if(!e)return`\xA0`;let n=e.total.toLocaleString(ci());return e.buckets.length===0&&e.rows.length<e.total?`${e.rows.length.toLocaleString(ci())} of ${n} ${t} in view`:`${n} ${t} in view`},Zz=({value:e,options:t,onChange:n,link:r,label:i})=>{let[a,o]=(0,W.useState)(!1),s=(0,W.useRef)(null),c=(0,W.useRef)(null),l=(0,W.useRef)([]),u=(0,W.useRef)(null),d=Bv(a,s,u),f=Uv(a,s,u,d?.right),p=t.findIndex(t=>t.value===e),m=t[p];(0,W.useEffect)(()=>{if(!a)return;l.current[Math.max(p,0)]?.focus();let e=e=>{e.target instanceof Node&&!s.current?.contains(e.target)&&o(!1)};return document.addEventListener(`pointerdown`,e),()=>document.removeEventListener(`pointerdown`,e)},[a]);let h=()=>{o(!1),c.current?.focus()};return(0,q.jsxs)(`div`,{ref:s,className:`relative shrink-0`,children:[(0,q.jsxs)(`button`,{ref:c,type:`button`,"aria-label":m?`${i}: ${m.label}`:i,"aria-haspopup":`menu`,"aria-expanded":a,onClick:()=>o(!a),className:`inline-flex h-8 items-center gap-1.5 rounded-md border border-border-strong bg-background px-2.5 text-body font-medium shadow-sm transition-colors hover:bg-muted pointer-coarse:h-11`,children:[m?.icon&&(0,q.jsx)(m.icon,{className:`size-3.5`}),m?.label??i,(0,q.jsx)(Sc,{className:`size-3.5 text-muted-foreground`})]}),a&&(0,q.jsx)(`ul`,{ref:u,role:`menu`,"aria-label":i,onKeyDown:e=>{if(e.key===`Escape`)return h();if(e.key===`Tab`)return o(!1);let n=jO(e.key,l.current.indexOf(document.activeElement),t.length);n!==void 0&&(e.preventDefault(),l.current[n]?.focus())},style:{...d,...f},className:`absolute right-0 top-full z-30 mt-1 w-max min-w-40 rounded-md border bg-background py-1 text-body shadow-pop`,children:t.map((t,i)=>{let a={ref:e=>{l.current[i]=e},role:`menuitemradio`,"aria-checked":t.value===e,className:U(`flex min-h-9 w-full items-center gap-2 px-3 py-1.5 text-left hover:bg-muted focus:bg-muted focus:outline-none pointer-coarse:min-h-11`,t.value===e&&`font-medium`)},o=(0,q.jsxs)(q.Fragment,{children:[t.icon?(0,q.jsx)(t.icon,{className:`size-3.5`}):(0,q.jsx)(`span`,{className:`size-3.5`}),(0,q.jsx)(`span`,{className:`flex-1`,children:t.label}),t.value===e&&(0,q.jsx)(xi,{className:`size-3.5 text-primary-text`})]});return(0,q.jsx)(`li`,{role:`none`,children:r?(0,q.jsx)(Jn,{...a,to:r(t.value),onClick:h,children:o}):(0,q.jsx)(`button`,{...a,type:`button`,onClick:()=>{h(),t.value!==e&&n(t.value)},children:o})},t.value)})})]})},Qz={table:Pd,cards:vi,kanban:Ed,board:Hc,list:Xl,calendar:gc,timeline:bc,map:ou},$z=({view:e,value:t,onChange:n,menu:r=!1,choices:i=_e(e)})=>{if(i.length<2)return null;let a=i.map(e=>({value:e.name,label:e.label,icon:e.icon===void 0?void 0:Qz[e.icon]}));return r?(0,q.jsx)(Zz,{label:N(`display`),value:t,onChange:n,options:a}):(0,q.jsx)(Av,{label:N(`display`),size:`md`,value:t,onChange:n,options:a})},eB=[[`asc`,`ascending`],[`desc`,`descending`]],tB=({model:e,view:t,display:n,orderBy:r,onChange:i,className:a})=>{let o=Ve(r),s=A(e,t,n),c=s.includes(o.columnId)?s:[o.columnId,...s],l=e=>t?.fields[e]?.label??H(e);return(0,q.jsx)(`select`,{"aria-label":N(`sort`),value:`${o.columnId} ${o.direction}`,onChange:e=>i(e.target.value),className:U(`h-8 rounded-md border border-border-strong bg-background px-2.5 shadow-sm focus:border-primary focus:outline-none focus:ring-2 focus:ring-primary/20`,a),children:c.flatMap(e=>eB.map(([t,n])=>(0,q.jsxs)(`option`,{value:`${e} ${t}`,children:[l(e),`, `,N(n)]},`${e} ${t}`)))})},nB=8,rB=22,iB=20,aB={wide:288,narrow:192},oB=(e,t)=>Ie(e,t).record,sB=(e,t,n,r)=>i=>(0,q.jsx)(pM,{button:n,model:e,view:t,record:oB(e,i),models:r}),cB=(e,t,n,r)=>i=>{let a=fM(n,e,t,oB(e,i),r);return a?Math.ceil(a.label.length*nB)+rB+(`href`in a?iB:0)+24:0},lB=(e,t,n,r,i)=>({id:`_row_button`,header:``,kind:`text`,width:152,minWidth:96,maxWidth:i,sortable:!1,render:sB(e,t,n,r),fit:cB(e,t,n,r)}),uB=(e,t,n,r,i,a)=>{if(!a)return[...e,lB(t,n,r,i,aB.wide)];let[o,...s]=e;return o?[{...o,below:sB(t,n,r,i)},...s]:[lB(t,n,r,i,aB.narrow)]},dB=(e,t,n)=>{let r=Object.hasOwn(e.fields,t)?e.fields[t]:void 0;return r?.type===`relation`&&r.relation!==void 0&&n[r.relation.resource]?.primaryKey.length===1},fB=(e,t,n)=>{if(e.open!==void 0)return e.open!==e.field&&dB(t,e.open,n)?e.open:void 0;let r=t.primaryKey.filter(r=>r!==e.field&&r!==t.tenant&&dB(t,r,n));return r.length===1?r[0]:void 0},pB=(e,t)=>{let n=e[t],r=typeof n==`object`&&n&&`id`in n?n.id:n;return typeof r==`string`||typeof r==`number`?r:void 0},mB=(e,t)=>(t?.names?.singular??H(e.name)).toLowerCase(),hB=({model:e,view:t,opens:n,resources:r,views:i,canUpdate:a})=>{let o=t=>({kind:`record`,resource:e.name,key:xr(e,t)}),s=n&&e.fields[n]?.relation?.resource,c=s?r[s]:void 0,l=e=>{let t=n&&c?pB(e,n):void 0;return c&&t!==void 0?{kind:`record`,resource:c.name,key:t}:void 0},u=e=>l(e)??o(e),d=mB(e,t);return{address:u,actions:t=>{let n={label:$j(`open`,{singular:d}),link:e=>t(o(e))};if(!c)return[n];let r=e=>a&&aS(e,`update`);return[{label:$j(`open`,{singular:mB(c,i[c.name])}),available:e=>l(e)!==void 0,link:e=>t(l(e))},{label:$j(`edit`,{singular:d}),available:r,link:n=>t({kind:`record`,resource:e.name,key:xr(e,n),edit:!0})},{...n,available:e=>!r(e)}]}}},gB=(e,t,{href:n,go:r})=>{if(`to`in e){let i=Mr(e.to,t);return{href:n(i),onFollow:()=>r(i)}}let i=dT(e.href,t);if(i===void 0)throw Error(`A link action without a target on the record is not shown`);return{href:i,newTab:/^https?:/i.test(i)}},_B=(e,t)=>({model:e,record:Object.fromEntries(Object.entries(Ie(e,t).record).filter(([t])=>Object.hasOwn(e.fields,t))),key:t.id,...typeof t.etag==`string`&&{etag:t.etag},...typeof t.permissions==`object`&&t.permissions!==null&&{permissions:t.permissions}}),vB=e=>{let{views:t,resources:n}=c(),r=yT(e.name,void 0),i=Me(),a=Qy(),[o,s]=(0,W.useState)(),l=t[e.name]?.actions??[],u=l.filter(e=>!e.inputs?.length),d=async(e,t)=>`row`in e?(await r.run(e.action,e.row),[]):(await r.runEach(e.action,e.selection,e.skipped,t)).refused,f=e=>new Promise(t=>{e.action.confirm||e.action.inputs?.length?s({...e,settle:t}):t(d(e))});return{rowActions:u.map(t=>{let a=r=>hT(t,_B(e,r).record,n),o={label:e=>a(e)?.label??t.label,destructive:zw(t)},s=t.run,c=n=>r.blockedOn(t,_B(e,n)),l=e=>a(e)!==void 0;return s?.kind===`link`?{...o,available:l,blocked:c,link:t=>gB(s,_B(e,t).record,i)}:{...o,available:l,blocked:c,onSelect:n=>void f({action:t,row:_B(e,n)})}}),bulkActions:l.filter(e=>e.bulk&&e.run?.kind!==`link`).map(t=>({label:e=>ST(`actionCount`,{label:t.label,count:e}),destructive:zw(t),available:n=>r.verdictOn(t,_B(e,n))!==`skip`,onRun:async(n,r)=>{let i=n.map(t=>_B(e,t)),a=await f({action:t,selection:i,skipped:r});return n.filter((e,t)=>a.includes(i[t]))}})),prompt:o&&(0,q.jsx)(Vw,{action:o.action,label:`row`in o?o.action.label:ST(`actionCount`,{label:o.action.label,count:o.selection.length}),danger:zw(o.action),records:`row`in o?[o.row.record]:o.selection.map(e=>e.record),names:`row`in o?[]:o.selection.map(n=>_T(a(e,t[e.name],n.record,n.key))),onCancel:()=>{s(void 0),o.settle(`row`in o?[o.row]:o.selection)},onConfirm:()=>{s(void 0),o.settle(d(o))},onSubmit:async e=>{s(void 0);let t=d(o,e);o.settle(t),await t}})}},yB=({client:e,queryClient:t,resources:n,views:r},{model:i,filter:a,orderBy:o,limit:s,fields:c,read:l})=>({queryKey:[...I.list(i.name,a,o,s,`embedded`),c.join(`,`),l?.join(`,`)??`*`],queryFn:async()=>{let u=ab(n,r,i,c),d=C(r[i.name]),f=await e.search(i.name,{filter:a||void 0,orderBy:o||void 0,pageSize:s,count:`exact`,labels:u,photos:d,fields:l});await db(t,e,n,r,i,c,f.items);let p=ob(n,i,c,E(i,f.items,f.photos),f.labels).map((e,t)=>({...e,id:Nr(i,f.items[t])}));return f.nextPageToken===``?{rows:p,total:p.length,estimated:!1}:{rows:p,total:f.totalSize??f.totalSizeEstimate,estimated:f.totalSize===void 0}}}),bB=(e,t=!0)=>{let{resources:n,views:r}=c();return Tt({...yB({client:F(),queryClient:nn(),resources:n,views:r},e),placeholderData:sn,enabled:t})},xB=(e,t,n,{rows:r,total:i})=>{let a=r.isPending||!!i?.isPending,o=r.error??i?.error??null;if(a||o)return{isPending:a,error:o,data:void 0};let s=ob(e,t,n,E(t,r.rows,r.photos),r.labels).map((e,n)=>({...e,id:Nr(t,r.rows[n])}));return{isPending:a,error:o,data:{rows:s,total:i?sM(i):s.length,estimated:!1}}},SB=({view:e,value:t,onChange:n})=>(0,q.jsx)($z,{view:e,value:t,onChange:n,menu:!h()}),CB=()=>(0,q.jsx)(`div`,{className:`flex flex-col gap-2`,children:Array.from({length:3},(e,t)=>(0,q.jsx)(L,{className:`h-4 w-full`},t))}),wB=({model:e,view:t,filter:n,sort:r,columns:i,limit:a,display:o,empty:s,row:l=!1,viewAll:u,link:d=!0,opens:f,button:p,bulk:m=!1,phoneColumns:g,rowTo:_,chosenKey:y,planned:b})=>{let{resources:x,views:S}=c(),C=iS(re(e.name),`update`),{fields:w}=qy(),{go:T,href:E}=Me(),D=v(),O=!h(),ee=r||Pe(e,t),[A,te]=(0,W.useState)(ee),{specs:ne,fields:j,read:ie}=(0,W.useMemo)(()=>tE({model:e,view:t,resources:x,views:S,fieldTypes:w,columns:i,button:p,opens:f,bulk:m,phoneColumns:g,xs:D}),[e,t,x,S,w,i?.join(`,`),p,f,m,g,D]),M=(0,W.useMemo)(()=>p?uB(ne,e,t,p,x,O):ne,[ne,e,t,p,x,O]),ae=b!==void 0&&A===ee,oe=bB({model:e,filter:n,orderBy:A,limit:a,fields:j,read:ie},!ae),se=(0,W.useMemo)(()=>b&&xB(x,e,j,b),[b,x,e,j]),ce=ae?se:oe,le=vB(e),ue=ce.data?.rows,de=(0,W.useMemo)(()=>ue&&{total:ue.length,rowAt:e=>ue[e]},[ue]),pe=k(t,o),me=t?.names?.plural??H(e.name),he=d&&(0,q.jsxs)(Ue,{to:oM(e,t,D,u?{filter:u.filter,orderBy:Pe(e,t),display:o,savedSearch:u.savedSearch}:{filter:n,orderBy:A,display:o}),onClick:u?.onOpen,className:`flex items-center gap-1 self-end font-medium text-primary-text hover:underline`,children:[u?u.label:(0,q.jsxs)(q.Fragment,{children:[$j(`viewAll`),` `,(0,q.jsx)(`span`,{className:`sr-only`,children:me.toLowerCase()})]}),(0,q.jsx)(Is,{className:`size-3.5`,"aria-hidden":!0})]}),ge=e=>(0,q.jsxs)(q.Fragment,{children:[e,le.prompt]});if(ce.isPending)return ge((0,q.jsx)(CB,{}));if(ce.error)return ge((0,q.jsx)(Oy,{title:$j(`couldNotLoad`),error:ce.error}));let _e=ce.data;if(!_e||!de||de.total===0){let e=(0,q.jsx)(`p`,{className:`text-muted-foreground`,children:s??$j(`nothingYet`)});return ge(u&&d?(0,q.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[e,he]}):e)}let ve={resource:e.name,rows:_e.rows.map(t=>Ie(e,t)),total:_e.total,loading:!1,error:null,more:!1,loadMore:()=>void 0},ye=hB({model:e,view:t,opens:f,resources:x,views:S,canUpdate:C}),be=e=>({href:E(e),onFollow:()=>T(e)}),xe=t=>Nn(xr(e,t)),Se=e=>_?_(xe(e)):be(ye.address(e)),Ce=y===void 0?void 0:_e.rows.find(e=>xe(e)===y)?.id,we=eM(de.total,_e.total,_e.estimated);return(0,q.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[pe?pe.kind===`cards`?(0,q.jsx)(fz,{model:e,view:t,display:pe,list:ve,row:l||D,footer:!1}):pe.kind===`map`?(0,q.jsx)(Yz,{model:e,view:t,display:pe,filter:n,orderBy:A,fields:j,footer:!1}):pe.kind===`board`?(0,q.jsx)(nR,{model:e,view:t,display:pe,fields:j,filter:n,orderBy:A,limit:a}):pe.kind===`calendar`?(0,q.jsx)(BR,{model:e,view:t,display:pe,fields:j,filter:n}):pe.kind===`timeline`?(0,q.jsx)(sz,{model:e,view:t,display:pe,fields:j,filter:n}):(0,q.jsx)(_z,{display:pe,list:ve}):(0,q.jsx)(nP,{fit:!0,columns:M,source:de,latencyMs:0,sort:Ve(A),onSortChange:e=>te(fe(e)),onOpenRow:e=>Se(e).onFollow?.(),rowLink:Se,chosenRow:Ce,rowActions:ye.actions(be),rowNumbers:!1,selectable:m,...m&&{bulkActions:le.bulkActions}}),le.prompt,we&&d?(0,q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:we}),he]}):he]})},TB=(e,t,n)=>{let r=v(),i=nM(t),[a,o]=(0,W.useState)(()=>rM(localStorage,i)),s=(0,W.useCallback)(e=>{o(e),iM(localStorage,i,e)},[i]);return[aM(e,r,{picked:a,preferred:n}),s]},EB=({model:e,items:t,columns:n,button:r,title:i,description:a,empty:o,actions:s,className:l})=>{let{resources:u,views:d}=c(),f=d[e.name],{fields:p}=qy(),m=iS(re(e.name),`update`),{go:g,href:_}=Me(),y=v(),b=!h(),x=(0,W.useMemo)(()=>n?.map(fm)??He(e,f),[n,e,f]),S=(0,W.useMemo)(()=>$T(e,f,x,{resources:u,views:d,fieldTypes:p}),[e,f,x,u,d,p]),C=(0,W.useMemo)(()=>y?nE(n)(S):S,[y,n,S]),w=(0,W.useMemo)(()=>r?uB(C,e,f,r,u,b):C,[C,e,f,r,u,b]),T=(0,W.useMemo)(()=>t.map(t=>({...t,id:Nr(e,t)})),[t,e]),E=(0,W.useMemo)(()=>({total:T.length,rowAt:e=>T[e]}),[T]),D=hB({model:e,view:f,opens:void 0,resources:u,views:d,canUpdate:m}),O=e=>({href:_(e),onFollow:()=>g(e)});return(0,q.jsx)(Hw,{title:i,description:a,actions:s,className:l,children:T.length===0?(0,q.jsx)(Uw,{children:o??z(`nothingYet`)}):(0,q.jsx)(nP,{fit:!0,columns:w,source:E,latencyMs:0,onOpenRow:e=>g(D.address(e)),rowLink:e=>O(D.address(e)),rowActions:D.actions(O),rowNumbers:!1,selectable:!1})})},DB=e=>{let t=Kw();return t?.model?(0,q.jsx)(EB,{...e,model:t.model,items:t.items}):null},OB=({model:e,view:t,filter:n=``,sort:r=``,columns:i,button:a,bulk:o,limit:s=10,display:c,title:l,description:u,empty:d,actions:f,className:p,chosen:m,planned:h})=>{let[g,_]=TB(t,`page:${e.name}:${l??``}:${n}`,c),v=m?ee:g,y=(0,W.useMemo)(()=>i?.map(fm),[i]),b=(0,W.useMemo)(()=>nE(i),[i]);return(0,q.jsxs)(Hw,{title:l,description:u,actions:(0,q.jsxs)(q.Fragment,{children:[!m&&(0,q.jsx)(SB,{view:t,value:v,onChange:_}),f]}),className:U(`h-full`,p),children:[(0,q.jsx)(wB,{model:e,view:t,filter:n,sort:r,columns:y,button:a,bulk:o,limit:s,display:v,empty:d,phoneColumns:b,...m&&{rowTo:m.rowTo,chosenKey:m.key},...h&&{planned:h}}),m?.details]})},kB=({node:e,at:t,slots:n,children:r,className:i})=>{let{className:a,resource:o,select:s,children:l,...u}=xT(e),{resources:d,views:f}=c(),[p,m]=hE([t,t===void 0?void 0:`${t}#total`]),h=(0,W.useMemo)(()=>p&&{rows:p,total:m},[p,m]);if(o===void 0)return(0,q.jsx)(DB,{...u,actions:n.actions,className:i});let g=d[o];return g?s===void 0?(0,q.jsx)(OB,{...u,model:g,view:f[g.name],actions:n.actions,className:i,...h&&{planned:h}}):(0,q.jsx)(AB,{...u,model:g,view:f[g.name],actions:n.actions,className:i,select:s,...h&&{planned:h},children:r}):null},AB=({select:e,children:t,...n})=>{let{given:r,linkTo:i}=NT(),a=t=>i({[e]:t}),o=r[e],s=o===void 0?null:(0,q.jsx)(Fe,{name:e,children:(0,q.jsx)(yD,{model:n.model,query:{key:o},children:t},o)});return(0,q.jsx)(OB,{...n,chosen:{rowTo:a,key:o,details:s}})},jB=({node:e,children:t,className:n})=>{let{tab:r,pathOf:i}=e_(),{navigate:a}=le(),o=t_(e),s=r_(o,r),c=e=>i(e===o[0]?.name?void 0:e);return(0,q.jsxs)(`div`,{className:U(`flex flex-col gap-6`,n),children:[(0,q.jsxs)(`select`,{"aria-label":z(`tabs`),value:s?.name??``,onChange:e=>a(c(e.target.value)),className:`h-9 rounded-md border border-border-strong bg-background px-2 font-medium md:hidden`,children:[!s&&(0,q.jsx)(`option`,{value:``,disabled:!0}),o.map(e=>(0,q.jsx)(`option`,{value:e.name,children:e.label},e.name))]}),(0,q.jsx)(`nav`,{"aria-label":z(`tabs`),className:`hidden border-b md:block`,children:(0,q.jsx)(`ul`,{className:`flex gap-1`,children:o.map(e=>(0,q.jsx)(`li`,{children:(0,q.jsx)(Ne,{to:c(e.name),"aria-current":e===s?`page`:void 0,className:U(`-mb-px inline-flex h-9 items-center whitespace-nowrap border-b-2 px-3 font-medium transition-colors`,e===s?`border-foreground text-foreground`:`border-transparent text-muted-foreground hover:text-foreground`),children:e.label})},e.name))})}),s?(0,q.jsx)(W.Fragment,{children:t[o.indexOf(s)]},s.name):(0,q.jsx)(PS,{children:z(`noTab`,{name:r??``})})]})},MB=({children:e})=>(0,q.jsx)(`div`,{className:`flex flex-col gap-6`,children:e}),NB=e=>e===void 0?1/0:Date.parse(e),PB=(e,t)=>{let n=e=>e.more&&e.items.length>0?NB(e.items.at(-1).time):-1/0,r=Math.max(n(e),n(t)),i=[],a=0,o=0;for(;a<e.items.length||o<t.items.length;){let n=o>=t.items.length||a<e.items.length&&NB(e.items[a].time)>=NB(t.items[o].time)?e.items[a++]:t.items[o++];if(NB(n.time)<r)break;i.push(n)}return i},FB=({value:e,hints:t,mark:n})=>{let r=ar(e,t?.valueLabels);return n===`done`?(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,q.jsx)(xi,{"aria-hidden":!0,className:`size-3.5 shrink-0 text-success-text`}),r]}):n===`running`?(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,q.jsx)(wn,{hidden:!0,className:`size-3.5 shrink-0`}),r]}):n!==`error`&&ei(t?.valueColors,e)!==`red`?r:(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-danger-text`,children:[(0,q.jsx)(yi,{"aria-hidden":!0,className:`size-3.5 shrink-0`}),r]})},IB=({value:e})=>{let t=typeof e==`string`?Sb(e):e;return t===xb?(0,q.jsx)(hb,{children:String(e)}):(0,q.jsx)(vb,{value:t})},LB=({label:e,children:t})=>(0,q.jsxs)(`div`,{className:`grid gap-1`,children:[(0,q.jsx)(`p`,{className:`text-xs font-medium text-muted-foreground`,children:e}),t]}),RB=({call:e,statusHints:t})=>{let[n,r]=(0,W.useState)(!1),i=(0,W.useId)(),a=e.status!==void 0&&(0,q.jsx)(FB,{value:e.status,hints:t,mark:e.state}),o=(0,q.jsx)(`span`,{className:`font-mono text-xs text-foreground`,children:e.name}),s=e.input!==void 0||e.result!==void 0||e.error!==void 0;return(0,q.jsxs)(`div`,{"data-tool-call":!0,className:`flex min-w-0 flex-col gap-1 pl-11 text-xs text-muted-foreground`,children:[s?(0,q.jsxs)(P,{size:`sm`,variant:`ghost`,className:`-ml-2.5 self-start`,"aria-expanded":n,"aria-controls":i,onClick:()=>r(!n),children:[(0,q.jsx)(qn,{"aria-hidden":!0,className:U(`size-3.5 transition-transform`,n&&`rotate-90`)}),o,a]}):(0,q.jsxs)(`p`,{className:`flex items-center gap-1.5`,children:[o,a]}),n&&(0,q.jsxs)(`div`,{id:i,className:`grid gap-2`,children:[e.input!==void 0&&(0,q.jsx)(LB,{label:XO(`callInput`),children:(0,q.jsx)(IB,{value:e.input})}),e.result!==void 0&&(0,q.jsx)(LB,{label:XO(`callResult`),children:(0,q.jsx)(IB,{value:e.result})}),e.error!==void 0&&(0,q.jsx)(LB,{label:XO(`callError`),children:(0,q.jsx)(hb,{children:e.error})})]})]})},zB=(e,t)=>e.map(e=>({kind:`message`,row:e,time:typeof e[t]==`string`?e[t]:void 0})),BB=e=>{if(typeof e==`object`&&e&&`id`in e){let{id:t,name:n}=e;return{id:String(t),...typeof n==`string`&&{name:n}}}return{id:String(e??``),...typeof e==`string`&&{name:e}}},VB=(e,{key:t,sender:n,text:r,status:i},a=Date.now())=>{let o=[],s;for(let c of[...e].reverse()){let e=c.time,l=s?.time!==void 0&&e!==void 0&&vO(s.time,e);if(e!==void 0&&!l&&o.push({kind:`day`,key:`day:${c.kind===`call`?c.key:t(c.row)}`,label:yO(e,a)}),c.kind===`call`){o.push(c),s={author:void 0,time:e};continue}let{row:u}=c,d=n===void 0?void 0:BB(u[n]),f=d?.id??``,p=i===void 0||u[i]==null||u[i]===``?void 0:String(u[i]);o.push({kind:`message`,key:t(u),...d&&{author:d},time:e,text:u[r]==null?``:String(u[r]),...p!==void 0&&{status:p},continued:l&&s?.author===f}),s={author:f,time:e}}return o},HB=e=>Lp.includes(e??``)?e:void 0,UB=e=>e==null||e===``?void 0:String(e),WB=e=>`call:${JSON.stringify(e)}`,GB=(e,t,n)=>{let r=UB(e[n.status]),i=HB(r),a=n.input===void 0?void 0:e[n.input],o=n.result===void 0?void 0:e[n.result],s=n.error===void 0?void 0:UB(e[n.error]);return{kind:`call`,key:t,name:String(e[n.name]??``),time:typeof e[n.time]==`string`?e[n.time]:void 0,...r!==void 0&&{status:r},...i!==void 0&&{state:i},...a!=null&&{input:a},...o!=null&&{result:o},...s!==void 0&&{error:s}}},KB=({planned:e,limit:t,expanded:n,expand:r,own:i})=>{if(!e)return i;let a=n&&!i.error&&i.pages<2&&(i.pages===0||i.hasNextPage),o={items:e.rows,labels:e.labels??{},hasNextPage:e.rows.length>=t,isFetchingNextPage:a,isFetchNextPageError:!1,isLoading:e.isPending};return n&&i.error&&i.pages===0?{...o,error:i.error,fetchNextPage:i.refetch,refetch:i.refetch}:n&&!a?i:{...o,error:e.error,fetchNextPage:r,refetch:r}},qB=(e,{pageSize:t=50,enabled:n=!0,...r},i)=>{let[a,o]=(0,W.useState)(!1),s=tx(e,{...r,pageSize:t,enabled:n&&(!i||a)}),c=s.data?.pages.length??0,{hasNextPage:l,isFetchingNextPage:u,fetchNextPage:d,error:f}=s;return(0,W.useEffect)(()=>{i&&a&&!f&&c===1&&l&&!u&&d()},[i,a,f,c,l,u,d]),KB({planned:i,limit:t,expanded:a,expand:()=>o(!0),own:{...s,pages:c}})},JB=(e,t,n)=>{let{views:r}=c(),i=e?.model.name??``,a=qB(i,{filter:e?.filter,orderBy:e&&Ip(e.fields.time),pageSize:t,enabled:e!==void 0},n);return e?{calls:a.items.map(t=>GB(t,WB(xr(e.model,t)),e.fields)),hasNextPage:a.hasNextPage,isFetchingNextPage:a.isFetchingNextPage,list:a,statusHints:r[i]?.fields[e.fields.status]}:{calls:[],hasNextPage:!1,isFetchingNextPage:!1,list:a,statusHints:void 0}},YB=e=>e.items.length>0?`messages`:e.error?`error`:e.isLoading?`loading`:`messages`,XB=(e,t)=>e.isLoading?t.loading:t.empty,ZB=e=>e.items.length>0&&!!e.error,QB=e=>e.isFetchNextPageError?()=>void e.fetchNextPage():()=>void e.refetch(),$B=e=>{for(let t of e)t.hasNextPage&&t.fetchNextPage()},eV=({model:e,filter:t,sender:n,time:r,text:i,status:a,limit:o=50,empty:s,working:l,calls:u,planned:d})=>{let{resources:f,views:p}=c(),m=Ig(),h=m?.state.kind===`signed-in`?m.state.user.id:void 0,g=n===void 0?[]:[n],_=ab(f,p,e,g),v=qB(e.name,{filter:t,orderBy:Ip(r),pageSize:o,labels:_},d?.messages),y=JB(u,o,d?.calls),b=YB(v);if(b===`error`)return(0,q.jsx)(Oy,{title:XO(`couldNotLoad`),error:v.error,onRetry:QB(v)});if(b===`loading`)return(0,q.jsx)(`div`,{className:`p-4`,children:(0,q.jsx)(Uw,{children:XO(`loadingMessages`)})});let x=ob(f,e,g,v.items,v.labels),S=PB({items:y.calls,more:y.hasNextPage},{items:zB(x,r),more:v.hasNextPage}),C=VB(S,{key:t=>String(xr(e,t)),sender:n,time:r,text:i,status:a}),w=a===void 0?void 0:p[e.name]?.fields[a],T=e.fields[i]!==void 0&&ov(e.fields[i],p[e.name]?.fields[i]),E=C.findLast(e=>e.kind===`message`&&e.author!==void 0&&e.author.id===h);return(0,q.jsxs)(q.Fragment,{children:[ZB(v)&&(0,q.jsx)(`div`,{className:`shrink-0 p-2`,children:(0,q.jsx)(Oy,{title:XO(`couldNotLoad`),error:v.error,onRetry:QB(v)})}),u&&y.list.error&&(0,q.jsx)(`div`,{className:`shrink-0 p-2`,children:(0,q.jsx)(Oy,{title:XO(`couldNotLoadCalls`),error:y.list.error,onRetry:QB(y.list)})}),(0,q.jsx)(AO,{length:S.length,followKey:E?.key,working:l,empty:XB(y.list,{loading:XO(`loadingMessages`),empty:s??XO(`noMessages`)}),onLoadEarlier:v.hasNextPage||y.hasNextPage?()=>$B([v,y.list]):void 0,loadingEarlier:v.isFetchingNextPage||y.isFetchingNextPage,children:C.map(e=>e.kind===`day`?(0,q.jsx)(bO,{label:e.label},e.key):e.kind===`call`?(0,q.jsx)(RB,{call:e,statusHints:y.statusHints},e.key):(0,q.jsx)(CO,{...e.author?{author:e.author}:{alone:!0},time:e.time,continued:e.continued,footer:e.status!==void 0&&(0,q.jsx)(FB,{value:e.status,hints:w}),children:T&&e.text!==``?(0,q.jsx)(BS,{source:e.text,className:`whitespace-normal`}):e.text},e.key))})]})},tV=({children:e})=>(0,q.jsx)(`div`,{className:`flex h-[min(36rem,65dvh)] flex-col rounded-lg border border-border bg-background`,children:e}),nV=({node:e,at:t,slots:n,className:r})=>{let{title:i,description:a,resource:o,filter:s,sender:l,time:u,text:d,status:f,working:p,calls:m,limit:h,empty:g}=xT(e),{resources:_}=c(),[v]=lL(p===void 0?[]:[p],tT()),[y,b]=hE([t,t===void 0?void 0:`${t}#calls`]),x=_[o];if(!x)return null;let S=m&&_[m.resource];return(0,q.jsx)(`section`,{className:U(`flex min-w-0 flex-col`,r),"aria-label":i,children:(0,q.jsx)(E_,{title:i,help:a,actions:n.actions,children:(0,q.jsx)(tV,{children:(0,q.jsx)(eV,{model:x,filter:s,sender:l,time:u,text:d,status:f,calls:m&&S&&{model:S,filter:m.filter,fields:m},limit:h,empty:g,working:p===void 0?void 0:v===!0,...(y||b)&&{planned:{messages:y,calls:b}}})})})})},rV=({children:e,className:t})=>(0,q.jsx)(`div`,{className:t,children:e}),iV=({children:e,className:t})=>(0,q.jsx)(`div`,{className:U(`flex`,t),children:e}),aV=({children:e,className:t})=>(0,q.jsx)(`div`,{className:U(`flex flex-col`,t),children:e}),oV=({node:e,children:t,className:n})=>{let{as:r=`p`}=xT(e);return(0,q.jsx)(r,{className:n,children:t})},sV=({node:e,children:t})=>{let{source:n}=xT(e),r=Im(rT(tT()),n),i=(0,W.useMemo)(()=>({items:Array.isArray(r)?r:[]}),[r]);return(0,q.jsx)(Gw,{value:i,children:t})},cV=({node:e,className:t})=>{let{source:n,choices:r,label:i=n,defaultValue:a}=xT(e),{values:o,linkTo:s}=NT(),c=o[n];return(0,q.jsxs)(`div`,{className:U(`flex flex-wrap items-center gap-2`,t),children:[(0,q.jsx)(`span`,{className:`font-medium text-muted-foreground`,children:i}),r?(0,q.jsx)(Zz,{label:i,value:c??``,options:r.map(e=>({value:String(e.id),label:e.name})),link:e=>s({[n]:a!==void 0&&e===String(a)?void 0:e})}):(0,q.jsx)(`span`,{children:c})]})},lV=({model:e,filter:t,perPage:n,more:r,planned:i,expanded:a,expand:o,own:s})=>{if(t===void 0)return{read:{isPending:!1,error:null},list:{model:e,items:[]}};if(i&&!a){let t=i.rows.slice(0,n),a=r&&t.length===n?o:void 0;return{read:i,list:{model:e,items:t,planned:!0,...a&&{loadMore:a}}}}if(i&&!s.error&&s.pages<2&&(s.pages===0||s.hasNextPage))return{read:i,list:{model:e,items:i.rows.slice(0,n),planned:!0,loadMore:()=>{},loadingMore:!0}};let c=r&&s.hasNextPage?()=>void s.fetchNextPage():void 0;return{read:{isPending:s.isPending,error:s.error},list:{model:e,items:s.items,...c&&{loadMore:c,loadingMore:s.isFetchingNextPage}}}},uV=({model:e,filter:t,sort:n,perPage:r,more:i,planned:a})=>{let[o,s]=(0,W.useState)(!1),c=tx(e.name,{filter:t,orderBy:n,pageSize:r,enabled:t!==void 0&&(!a||o)}),l=c.data?.pages.length??0,{hasNextPage:u,isFetchingNextPage:d,fetchNextPage:f,error:p}=c;return(0,W.useEffect)(()=>{a&&o&&!p&&l===1&&u&&!d&&f()},[a,o,p,l,u,d,f]),lV({model:e,filter:t,perPage:r,more:i,planned:a,expanded:o,expand:()=>s(!0),own:{pages:l,items:c.items,hasNextPage:u,isFetchingNextPage:d,isPending:c.isPending,error:p,fetchNextPage:f}})},dV=({node:e,at:t,children:n})=>{let r=xT(e),i=c().resources[r.reference],a=Lm(rT(tT())),o=mE(t);return i?(0,q.jsx)(fV,{model:i,...lm(r,i.primaryKey[0],a),more:r.pagination===`more`,empty:r.empty,...o&&{planned:o},children:n}):null},fV=({empty:e,children:t,...n})=>{let{read:r,list:i}=uV(n);return(0,q.jsx)(qw,{read:r,list:i,empty:e,children:t})},pV=({node:e,at:t,children:n})=>{let r=xT(e),i=c().resources[r.reference],a=Lm(rT(tT())),o=mE(t);return i?(0,q.jsx)(fV,{model:i,...um(r,i.primaryKey[0],a),more:!1,empty:r.empty,...o&&{planned:o},children:n}):null},mV=({model:e,at:t,recordKey:n,link:r=`edit`,children:i,className:a})=>{let{views:o}=c(),s=mE(t),l=Zr(e,{key:n,enabled:!s}),u=s?$r(e,s):l;if(u.isPending)return(0,q.jsx)(L,{className:`h-4 w-24`});if(u.error)return(0,q.jsx)(Oy,{title:z(`couldNotLoad`),error:u.error});if(!u.data)return null;let d=i.length>0?(0,q.jsx)(Zw,{value:u.data,children:i}):ke(e,o[e.name],u.data.record,n);return r===!1?(0,q.jsx)(`span`,{className:a,children:d}):(0,q.jsx)(Ue,{to:{kind:`record`,resource:e.name,key:n},className:a??`font-medium text-primary-text hover:underline`,children:d})},hV=({node:e,at:t,children:n,className:r})=>{let{reference:i,source:a,link:o,empty:s}=xT(e),l=c().resources[i],u=Im(rT(tT()),a);return l?u==null||u===``?s===void 0?null:(0,q.jsx)(`span`,{className:r,children:s}):(0,q.jsx)(mV,{model:l,...t!==void 0&&{at:t},recordKey:String(u),link:o,className:r,children:n}):null},gV=({title:e,status:t,description:n,children:r})=>(0,q.jsxs)(`section`,{"aria-label":e,className:`rounded-lg border bg-background p-4 sm:p-5`,children:[(0,q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,q.jsx)(`h2`,{className:`text-base font-semibold`,children:e}),t]}),(0,q.jsx)(`p`,{className:`mt-1 text-muted-foreground`,children:n}),r&&(0,q.jsx)(`div`,{className:`mt-4`,children:r})]}),_V=({message:e})=>e?(0,q.jsx)(`p`,{role:`alert`,className:`mb-3 text-body font-medium text-danger-text`,children:e}):null,vV=({message:e})=>e?(0,q.jsx)(`p`,{role:`status`,className:`mb-3 font-medium`,children:e}):null,yV=()=>{let[e,t]=(0,W.useState)(!1),[n,r]=(0,W.useState)();return{busy:e,error:n,run:async e=>{t(!0),r(void 0);try{await e()}catch(e){if(!(e instanceof Jm))throw e;r($C(e))}t(!1)},setError:r}},bV=B(`invitations`),xV=({link:e})=>e?(0,q.jsx)(`p`,{className:`mt-3 break-all rounded-md border bg-muted px-3 py-2 text-xs`,children:bV.rich(`passLinkOn`,{link:(0,q.jsx)(`span`,{className:`font-mono`,children:e})})}):null,SV=({title:e,description:t,onInvite:n,beside:r,children:i,incomplete:a=!1})=>{let[o,s]=(0,W.useState)(``),[c,l]=(0,W.useState)(),{busy:u,error:d,run:f}=yV(),p=()=>f(async()=>{l((await n(o.trim())).link),s(``)});return(0,q.jsxs)(gV,{title:e,description:t,children:[(0,q.jsx)(_V,{message:d}),(0,q.jsxs)(`form`,{className:`flex flex-col gap-3`,onSubmit:e=>{e.preventDefault(),p()},children:[(0,q.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,q.jsx)(bi,{"aria-label":bV(`email`),type:`email`,placeholder:`name@example.com`,value:o,onChange:e=>s(e.target.value),wrapperClassName:`flex-1`}),r,(0,q.jsx)(P,{type:`submit`,variant:`primary`,loading:u,disabled:!o.trim()||a,children:bV(`invite`)})]}),i]}),(0,q.jsx)(xV,{link:c})]})},CV=({email:e,gives:t,expiresAt:n,onResend:r,onRevoke:i})=>{let[a,o]=(0,W.useState)(),{busy:s,error:c,run:l}=yV(),u=new Date(n).getTime()<Date.now();return(0,q.jsxs)(`li`,{className:`px-3 py-2.5`,children:[(0,q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,q.jsx)(`span`,{className:`block truncate font-medium`,children:e}),(0,q.jsxs)(`span`,{className:`block text-xs text-muted-foreground`,children:[t,` · `,u?bV(`expired`):bV(`until`,{date:new Date(n).toLocaleDateString(ci())})]})]}),(0,q.jsx)(P,{size:`sm`,loading:s,onClick:()=>void l(async()=>o((await r()).link)),children:bV(`sendAgain`)}),(0,q.jsx)(P,{size:`sm`,variant:`danger`,loading:s,onClick:()=>void l(i),children:bV(`revoke`)})]}),(0,q.jsx)(_V,{message:c}),(0,q.jsx)(xV,{link:a})]})},Z=B(`organizations`),wV=({roles:e,selected:t,grantable:n,disabled:r,onChange:i})=>(0,q.jsx)(`div`,{className:`flex flex-wrap gap-x-4 gap-y-2`,children:e.map(e=>{let a=t.includes(e.name),o=r||!n.has(e.name);return(0,q.jsxs)(`label`,{title:o&&!r?Z(`cannotChangeRole`):void 0,className:U(`inline-flex items-center gap-1.5`,o&&`text-muted-foreground`),children:[(0,q.jsx)(Di,{checked:a,label:e.label,onChange:o?void 0:n=>i(n?[...t,e.name]:t.filter(t=>t!==e.name)),className:U(o&&`cursor-default opacity-60`)}),e.label]},e.name)})}),TV=`/-/organizations`,EV=`/-/organization`,DV=`/-/organization/members`,OV=`/-/organization/invitations`,kV={[TV]:`organizations`,[EV]:`organization`,[DV]:`members`,[OV]:`invitations`},AV=e=>{let t=kV[e];return t&&Z(t)},jV=e=>Z(e),MV=(e,t)=>e.find(e=>e.name===t)?.label??t,NV=e=>e?.role===`owner`||e?.role===`admin`,PV=(e,t,n)=>{let r=(n,r,i,a)=>({id:n,label:r,icon:i,href:`${e}${a}`,active:t===a});return[r(`organizations`,Z(`manageOrganizations`),wu,TV),...n?.organization?[r(`organization`,Z(`organization`),mc,EV)]:[],...NV(n)?[r(`members`,Z(`members`),nf,DV),r(`invitations`,Z(`invitations`),iu,OV)]:[]]},FV=(e,t)=>{let n=[...t?.globalRoles??[],...t?.appRoles??[]],r=e.filter(e=>e.membership).map(e=>e.name);if(n.includes(`admin`))return new Set(r);let i=n.flatMap(t=>e.find(e=>e.name===t)?.grants??[]);return new Set([...n,...i].filter(e=>r.includes(e)))},IV=(e,t)=>t.map(t=>MV(e,t)).join(`, `),LV=B(`users`),RV=({roles:e})=>{let{session:t}=Y(),[n,r]=(0,W.useState)([]),[i,a]=(0,W.useState)([]),o=(0,W.useCallback)(()=>void t.users.invitations().then(a,()=>a([])),[t]);return(0,W.useEffect)(o,[o]),(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(SV,{title:LV(`inviteSomeone`),description:LV(`inviteDescription`),onInvite:async e=>{let i=await t.users.invite({email:e,roles:n});return r([]),o(),i},incomplete:n.length===0,children:(0,q.jsx)(wV,{roles:e,selected:n,grantable:new Set(e.map(e=>e.name)),onChange:r})}),(0,q.jsx)(gV,{title:LV(`notAcceptedYet`),description:i.length>0?LV(`sendingAgain`):LV(`nobodyWaiting`),children:i.length>0&&(0,q.jsx)(`ul`,{className:`divide-y rounded-md border`,children:i.map(n=>(0,q.jsx)(CV,{email:n.email,gives:IV(e,n.roles),expiresAt:n.expiresAt,onResend:async()=>{let e=await t.users.invite({email:n.email,roles:n.roles});return o(),e},onRevoke:async()=>{await t.users.revoke(n.id),o()}},n.id))})})]})},zV=({address:e,page:t,accountPage:n,resourceLabel:r,singular:i,recordTitle:a,recordLoading:o})=>{if(t)return t.tab?[t.tab,t.title]:[t.title];if(n)return[n];if(!e||e.kind===`page`)return[];let s=r?[r]:[];if(e.kind===`list`)return s;if(e.kind===`create`)return[...i?[hy(`title`,{noun:i})]:[],...s];let c=a??(o?void 0:e.key);return[...c?[c]:[],...s]},BV=(e,t)=>[...e.filter(Boolean),t].join(` · `),VV=e=>{(0,W.useEffect)(()=>{if(e===void 0)return;let t=document.title;return document.title=e,()=>{document.title=t}},[e])},HV=({title:e,description:t,size:n=`sm`,appName:r,icon:i,footer:a,children:o})=>{let s=Ig()?.identity;return VV(s?.appName),(0,q.jsxs)(`div`,{className:`flex min-h-full w-full flex-col items-center bg-background px-4 pb-[calc(2.5rem+var(--pb-safe-bottom))] pt-[calc(2.5rem+var(--pb-safe-top))] short:pb-[calc(1rem+var(--pb-safe-bottom))] short:pt-[calc(1rem+var(--pb-safe-top))]`,children:[(0,q.jsx)(`div`,{className:`flex w-full flex-1 items-center justify-center`,children:(0,q.jsxs)(`div`,{className:U(`w-full`,n===`sm`?`max-w-sm`:`max-w-lg`),children:[(0,q.jsxs)(`div`,{className:`mb-6 flex flex-col items-center text-center short:mb-4`,children:[(0,q.jsx)(LA,{appName:r??s?.appName,appIcon:i??s?.appIcon,size:`lg`,className:`short:hidden`}),(0,q.jsx)(`h1`,{className:`mt-4 text-xl font-semibold tracking-tight short:mt-0`,children:e}),t&&(0,q.jsx)(`p`,{className:`mt-1 text-muted-foreground`,children:t})]}),(0,q.jsx)(`div`,{className:`rounded-lg border bg-background p-5 shadow-sm`,children:o})]})}),a]})},UV=({onSubmit:e,invalidLink:t,onRequestNewLink:n,onBack:r,busy:i,error:a})=>{let[o,s]=(0,W.useState)(``),[c,l]=(0,W.useState)(``),[u,d]=(0,W.useState)(!1);if(t)return(0,q.jsxs)(HV,{title:J(`linkExpiredTitle`),children:[(0,q.jsx)(`p`,{className:`text-muted-foreground`,children:J(`linkExpiredExplanation`)}),(0,q.jsxs)(`div`,{className:`mt-4 flex flex-col gap-2`,children:[n&&(0,q.jsx)(P,{variant:`primary`,className:`min-h-10`,onClick:n,children:J(`sendNewLink`)}),(0,q.jsx)(P,{variant:n?`ghost`:`primary`,className:`min-h-10`,onClick:r,children:J(`backToSignIn`)})]})]});let f=u?J(`passwordsDiffer`):a;return(0,q.jsx)(HV,{title:J(`choosePassword`),description:J(`atLeast`,{length:12}),children:(0,q.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:t=>{t.preventDefault(),d(o!==c),o===c&&e(o)},children:[(0,q.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[J(`newPassword`),(0,q.jsx)(bi,{type:`password`,name:`new-password`,autoComplete:`new-password`,required:!0,minLength:12,autoFocus:!0,value:o,invalid:!!f,onChange:e=>s(e.target.value),className:`min-h-6`})]}),(0,q.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[J(`repeatPassword`),(0,q.jsx)(bi,{type:`password`,name:`repeat-password`,autoComplete:`new-password`,required:!0,minLength:12,value:c,invalid:!!f,onChange:e=>l(e.target.value),className:`min-h-6`})]}),f&&(0,q.jsx)(`p`,{role:`alert`,className:`text-body font-medium text-danger-text`,children:f}),(0,q.jsx)(P,{variant:`primary`,type:`submit`,loading:i,className:`min-h-10`,children:J(`setPassword`)})]})})},WV=({roles:e,onCreated:t})=>{let{session:n}=Y(),[r,i]=(0,W.useState)(``),[a,o]=(0,W.useState)(``),[s,c]=(0,W.useState)(``),[l,u]=(0,W.useState)([]),{busy:d,error:f,run:p}=yV(),m=()=>p(async()=>{await n.users.create({email:r.trim(),name:a.trim(),roles:l,...s&&{password:s}}),i(``),o(``),c(``),u([]),t()}),h=!r.trim()||!a.trim()||l.length===0||s!==``&&s.length<12;return(0,q.jsxs)(gV,{title:LV(`addAnAccount`),description:LV(`addDescription`),children:[(0,q.jsx)(_V,{message:f}),(0,q.jsxs)(`form`,{className:`flex flex-col gap-3`,onSubmit:e=>{e.preventDefault(),m()},children:[(0,q.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,q.jsx)(bi,{"aria-label":LV(`email`),type:`email`,placeholder:`name@example.com`,value:r,onChange:e=>i(e.target.value),wrapperClassName:`flex-1`}),(0,q.jsx)(bi,{"aria-label":LV(`name`),placeholder:LV(`name`),autoComplete:`off`,value:a,onChange:e=>o(e.target.value),wrapperClassName:`flex-1`})]}),(0,q.jsx)(bi,{"aria-label":LV(`password`),type:`password`,autoComplete:`new-password`,placeholder:LV(`passwordOptional`,{length:12}),value:s,onChange:e=>c(e.target.value)}),(0,q.jsx)(wV,{roles:e,selected:l,grantable:new Set(e.map(e=>e.name)),onChange:u}),(0,q.jsx)(`div`,{children:(0,q.jsx)(P,{type:`submit`,variant:`primary`,loading:d,disabled:h,children:LV(`addAccount`)})})]})]})},GV=B(`lists`),KV=({title:e,description:t,searchLabel:n,placeholder:r,query:i,onQuery:a,list:o,error:s,renderRow:c})=>(0,q.jsxs)(gV,{title:e,description:t,children:[(0,q.jsx)(_V,{message:s}),(0,q.jsx)(bi,{"aria-label":n,placeholder:r,value:i,onChange:e=>a(e.target.value),leading:(0,q.jsx)(id,{className:`size-3.5`}),wrapperClassName:`mb-2`}),(0,q.jsxs)(`p`,{className:`mb-3 text-xs text-muted-foreground`,children:[o.found.length,` of `,o.total]}),o.found.length>0&&(0,q.jsx)(`ul`,{className:`divide-y rounded-md border`,children:o.found.map(c)}),o.found.length<o.total&&(0,q.jsx)(P,{className:`mt-3`,loading:o.loading,onClick:()=>void o.more(),children:GV(`showMore`)})]}),qV=(e,t)=>{let[n,r]=(0,W.useState)([]),[i,a]=(0,W.useState)(0),[o,s]=(0,W.useState)(!1),c=(0,W.useRef)(t);return c.current=t,(0,W.useEffect)(()=>{let n=setTimeout(()=>{s(!0),e(t,0).then(e=>{c.current===t&&(r(e.items),a(e.total),s(!1))},()=>{c.current===t&&(r([]),a(0),s(!1))})},200);return()=>clearTimeout(n)},[e,t]),{found:n,total:i,more:async()=>{let i=t;s(!0);let o=await e(i,n.length).catch(()=>void 0);c.current===i&&(o&&(r(e=>[...e,...o.items]),a(o.total)),s(!1))},loading:o}},JV=({name:e,email:t,self:n,actions:r,children:i,error:a,status:o})=>(0,q.jsxs)(`li`,{className:`flex flex-col gap-2 px-3 py-3`,children:[(0,q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[o?(0,q.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,q.jsxs)(`span`,{className:`truncate font-medium`,children:[e,n&&` (you)`]}),o]}):(0,q.jsxs)(`span`,{className:`block truncate font-medium`,children:[e,n&&` (you)`]}),(0,q.jsx)(`span`,{className:`block truncate text-xs text-muted-foreground`,children:t})]}),r]}),i,(0,q.jsx)(_V,{message:a})]}),YV=({user:e,roles:t,self:n})=>{let{session:r}=Y(),[i,a]=(0,W.useState)(e),{busy:o,error:s,run:c,setError:l}=yV(),u=e=>{if(e.length===0)return l(LV(`keepOneRole`));c(async()=>{await r.users.setRoles(i.id,e),a({...i,roles:e})})},d=e=>void c(async()=>{await(e?r.users.block(i.id):r.users.unblock(i.id)),a({...i,blocked:e})});return(0,q.jsx)(JV,{name:i.name,email:i.email,self:n,error:s,actions:(0,q.jsxs)(q.Fragment,{children:[i.blocked&&(0,q.jsx)(Ni,{tone:`red`,children:LV(`blocked`)}),!n&&(i.blocked?(0,q.jsx)(P,{size:`sm`,loading:o,onClick:()=>d(!1),children:LV(`unblock`)}):(0,q.jsx)(P,{size:`sm`,variant:`danger`,loading:o,onClick:()=>d(!0),children:LV(`block`)}))]}),children:(0,q.jsx)(wV,{roles:t,selected:i.roles,grantable:new Set(t.map(e=>e.name)),disabled:o,onChange:u})})},XV=({roles:e,version:t})=>{let{session:n,state:r}=Y(),[i,a]=(0,W.useState)(``),o=qV((0,W.useCallback)((e,t)=>n.users.search(e,t).then(e=>({items:e.users,total:e.total})),[n,t]),i),s=r.kind===`signed-in`?r.user.id:void 0;return(0,q.jsx)(KV,{title:LV(`people`),description:LV(`peopleDescription`),searchLabel:LV(`findSomeone`),placeholder:LV(`emailAddress`),query:i,onQuery:a,list:o,renderRow:n=>(0,q.jsx)(YV,{user:n,roles:e,self:n.id===s},`${t}/${n.id}`)})},ZV=()=>{let{session:e}=Y(),[t,n]=(0,W.useState)([]),[r,i]=(0,W.useState)();return(0,W.useEffect)(()=>{e.users.roles().then(n,e=>i(e instanceof Jm?$C(e):LV(`couldNotReadRoles`)))},[e]),{roles:t,error:r}},QV=()=>{let{roles:e,error:t}=ZV(),[n,r]=(0,W.useState)(0);return(0,q.jsxs)(`div`,{className:`flex max-w-3xl flex-col gap-4`,children:[(0,q.jsx)(_V,{message:t}),(0,q.jsx)(XV,{roles:e,version:n}),(0,q.jsx)(RV,{roles:e}),(0,q.jsx)(WV,{roles:e,onCreated:()=>r(e=>e+1)})]})},$V=({providers:e,linked:t,onConnect:n,error:r,reconnect:i=!1,notes:a={},title:o=X(`connectedAccounts`),description:s=X(`connectedAccountsDescription`),children:c})=>{let[l,u]=(0,W.useState)(),[d,f]=(0,W.useState)(r),p=async e=>{u(e),f(void 0);try{await n(e)}catch(e){if(!(e instanceof Jm))throw e;f($C(e)),u(void 0)}};return(0,q.jsxs)(gV,{title:o,description:s,children:[(0,q.jsx)(_V,{message:d}),(0,q.jsx)(`ul`,{className:`divide-y rounded-md border`,children:e.map(e=>(0,q.jsxs)(`li`,{className:`flex flex-wrap items-center gap-3 px-3 py-2.5`,children:[(0,q.jsx)(Kl,{className:`size-4 shrink-0 text-muted-foreground`}),(0,q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,q.jsx)(`span`,{className:`block truncate font-medium`,children:e.name}),a[e.id]&&(0,q.jsx)(`span`,{className:`block text-muted-foreground`,children:a[e.id]})]}),t.includes(e.id)&&(0,q.jsx)(Ni,{tone:`green`,children:X(`connected`)}),(!t.includes(e.id)||i)&&(0,q.jsx)(P,{size:`sm`,loading:l===e.id,disabled:l!==void 0,onClick:()=>void p(e.id),children:X(t.includes(e.id)?`connectAgain`:`connect`,{name:e.name})})]},e.id))}),c]})},eH=({error:e})=>e?(0,q.jsx)(`p`,{role:`alert`,className:`text-danger-text`,children:e}):(0,q.jsxs)(`div`,{className:`flex items-center gap-2 text-muted-foreground`,children:[(0,q.jsx)(wn,{}),` `,X(`loading`)]}),tH=(e,t)=>{let[n,r]=(0,W.useState)(),[i,a]=(0,W.useState)(),o=(0,W.useRef)(0),s=(0,W.useCallback)(()=>{let n=++o.current;return e().then(e=>{n===o.current&&(r({value:e}),a(void 0))},e=>{n===o.current&&a(e instanceof Jm?$C(e):t)})},[e,t]);return(0,W.useEffect)(()=>{s()},[s]),{data:n?.value,loaded:n!==void 0,error:i,reload:s}},nH=()=>{let e=bg(window.location.href);return e&&window.history.replaceState(window.history.state,``,Cg(window.location.href)),e},rH=({providers:e})=>{let{session:t,linkProvider:n}=Y(),{account:r}=t,[i]=(0,W.useState)(nH),{data:a,error:o}=tH((0,W.useCallback)(()=>r.linkedProviders(),[r]),X(`couldNotReadMethods`));return a?(0,q.jsx)($V,{providers:e,linked:a,onConnect:n,error:i&&iw(i,e.length===1?e[0].name:X(`theProvider`))}):(0,q.jsx)(eH,{error:o})},iH=({signInProviders:e,socialProviders:t,platformProviders:n})=>e.filter(e=>t.includes(e.id)&&!n.some(t=>t.provider===e.id&&t.hidden)),aH=()=>{let e=iH(Y());return e.length>0?(0,q.jsx)(rH,{providers:e}):null},oH=({sender:e,busy:t,error:n,onSave:r,onClose:i})=>{let[a,o]=(0,W.useState)(e?.address??``),[s,c]=(0,W.useState)(e?.name??``),[l,u]=(0,W.useState)(e?.signature??``),[d,f]=(0,W.useState)(e?.isDefault??!1);return(0,q.jsxs)(di,{title:e?e.address:X(`addFromAddress`),description:X(e?`changeFromAddressDescription`:`addFromAddressDescription`),onClose:i,actions:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(P,{onClick:i,children:X(`cancel`)}),(0,q.jsx)(P,{variant:`primary`,loading:t,disabled:!a.trim(),onClick:()=>r({address:a.trim(),name:s.trim(),signature:l,isDefault:d}),children:X(e?`save`:`addAddress`)})]}),children:[!e&&(0,q.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[X(`fromAddress`),(0,q.jsx)(bi,{autoFocus:!0,type:`email`,value:a,maxLength:254,placeholder:X(`fromAddressPlaceholder`),onChange:e=>o(e.target.value)})]}),(0,q.jsxs)(`label`,{className:`mt-3 flex flex-col gap-1.5 font-medium`,children:[X(`fromName`),(0,q.jsx)(bi,{value:s,maxLength:100,placeholder:X(`fromNamePlaceholder`),onChange:e=>c(e.target.value)})]}),(0,q.jsxs)(`label`,{className:`mt-3 flex cursor-pointer items-center justify-between gap-3`,children:[(0,q.jsx)(`span`,{children:X(`defaultFromAddress`)}),(0,q.jsx)(ky,{checked:d,onChange:f,label:X(`defaultFromAddress`)})]}),(0,q.jsxs)(`label`,{className:`mt-3 flex flex-col gap-1.5 font-medium`,children:[X(`signature`),(0,q.jsx)(jy,{value:l,maxLength:2e3,placeholder:X(`signaturePlaceholder`),onChange:e=>u(e.target.value)})]}),(0,q.jsx)(_V,{message:n})]})},sH=e=>e.signature?X(`ownSignature`):X(`genericSignature`),cH=({senders:{address:e,senders:t},onAdd:n,onUpdate:r,onRemove:i})=>{let[a,o]=(0,W.useState)(!1),[s,c]=(0,W.useState)(),[l,u]=(0,W.useState)(),d=(0,W.useRef)(!1),f=t.find(e=>e.isDefault),p=()=>{u(void 0),c(void 0)},m=async e=>{if(!d.current){d.current=!0,o(!0),c(void 0);try{await e(),u(void 0)}catch(e){if(e instanceof TypeError)return c(X(`noAnswerFromServer`));if(!(e instanceof Jm))throw e;c($C(e))}finally{d.current=!1,o(!1)}}},h=e=>m(async()=>{let t=e.name||null,i=e.signature.trim()?e.signature:null;if(l?.kind===`change`)return r(l.sender.id,{name:t,signature:i,isDefault:e.isDefault});let a=await n({address:e.address,...t&&{name:t},...i&&{signature:i}});e.isDefault&&await r(a.id,{isDefault:!0})});return(0,q.jsxs)(`div`,{className:`mt-5 border-t pt-4`,children:[(0,q.jsx)(`h3`,{className:`font-semibold`,children:X(`fromAddresses`)}),(0,q.jsx)(`p`,{className:`mt-1 mb-3 text-muted-foreground`,children:X(`fromAddressesDescription`)}),(0,q.jsx)(_V,{message:l?void 0:s}),(e||t.length>0)&&(0,q.jsxs)(`ul`,{className:`mb-3 divide-y rounded-md border`,children:[e&&(0,q.jsxs)(`li`,{className:`flex flex-wrap items-center gap-3 px-3 py-2.5`,children:[(0,q.jsx)(Ws,{className:`size-4 shrink-0 text-muted-foreground`}),(0,q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,q.jsx)(`bdi`,{className:`block truncate font-medium`,children:e}),(0,q.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:X(`mailboxOwnAddress`)})]}),f?(0,q.jsx)(P,{size:`sm`,variant:`ghost`,loading:a,onClick:()=>void m(()=>r(f.id,{isDefault:!1})),children:X(`makeDefault`)}):(0,q.jsx)(Ni,{tone:`blue`,children:X(`default`)})]}),t.map(e=>(0,q.jsxs)(`li`,{className:`flex flex-wrap items-center gap-3 px-3 py-2.5`,children:[(0,q.jsx)(Ws,{className:`size-4 shrink-0 text-muted-foreground`}),(0,q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,q.jsx)(`bdi`,{className:`block truncate font-medium`,children:e.address}),e.name&&(0,q.jsx)(`bdi`,{className:`block truncate`,children:e.name}),(0,q.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:sH(e)})]}),e.isDefault&&(0,q.jsx)(Ni,{tone:`blue`,children:X(`default`)}),(0,q.jsx)(P,{size:`sm`,variant:`ghost`,onClick:()=>u({kind:`change`,sender:e}),children:X(`edit`)}),(0,q.jsx)(P,{size:`sm`,variant:`ghost`,onClick:()=>u({kind:`remove`,sender:e}),children:X(`remove`)})]},e.id))]}),(0,q.jsxs)(P,{onClick:()=>u({kind:`add`}),children:[(0,q.jsx)(Hu,{className:`size-3.5`}),X(`addFromAddress`)]}),l?.kind===`add`&&(0,q.jsx)(oH,{busy:a,error:s,onSave:e=>void h(e),onClose:p}),l?.kind===`change`&&(0,q.jsx)(oH,{sender:l.sender,busy:a,error:s,onSave:e=>void h(e),onClose:p},l.sender.id),l?.kind===`remove`&&(0,q.jsx)(di,{title:X(`removeFromAddress`,{address:l.sender.address}),description:X(`removeFromAddressDescription`),onClose:p,actions:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(P,{onClick:p,children:X(`cancel`)}),(0,q.jsx)(P,{variant:`danger`,loading:a,onClick:()=>void m(()=>i(l.sender.id)),children:X(`remove`)})]}),children:(0,q.jsx)(_V,{message:s})})]})},lH=(e,t,n)=>Object.fromEntries(lw(e,t,{code:`not_linked`}).filter(e=>e.signInOnly).map(({link:e})=>[e.id,aw(`signInOnly`,{provider:n(e.provider),name:e.name})])),uH=({links:e})=>{let{session:t,linkPersonalMail:n,signInProviders:r}=Y(),{account:i}=t,[a]=(0,W.useState)(nH),{data:o,error:s,reload:c}=tH((0,W.useCallback)(async()=>{let[t,n,r]=await Promise.all([i.linkedPersonalMail(e),i.linkedProviders(),i.mailSenders()]);return{mail:t,providers:n,senders:r}},[i,e]),X(`couldNotReadMethods`));return o?(0,q.jsx)($V,{title:X(`mailbox`),description:X(`mailboxDescription`),providers:e.map(({id:e,name:t})=>({id:e,name:t})),linked:o.mail,notes:lH(e,o,e=>r.find(t=>t.id===e)?.name??Tg(e)),reconnect:!0,onConnect:t=>n(e.find(e=>e.id===t)),error:a&&iw(a,e.length===1?e[0].name:X(`theProvider`)),children:(0,q.jsx)(cH,{senders:o.senders,onAdd:async e=>{let t=await i.addMailSender(e);return await c(),t},onUpdate:async(e,t)=>{await i.updateMailSender(e,t),await c()},onRemove:async e=>{await i.removeMailSender(e),await c()}})}):(0,q.jsx)(eH,{error:s})},dH=()=>{let{personalMail:e}=Y();return e.length>0?(0,q.jsx)(uH,{links:e}):null},fH=/[\u0000-\u001f\u007f-\u009f\u00ad\u061c\u115f\u1160\u180e\u200b-\u200f\u2028-\u202e\u2060-\u206f\u3164\ufe00-\ufe0f\ufeff]/g,pH=e=>{let t=(e??``).replace(fH,` `).replace(/\s+/g,` `).trim();if(t)return t.length>60?`${t.slice(0,59)}…`:t},mH=e=>{if(!URL.canParse(e))return;let t=new URL(e);return t.protocol===`https:`?t.host:void 0},hH=e=>pH(e.name)??`An unnamed app`,gH=e=>e.access.map(({role:e,organization:t})=>`as ${e||`no role`}${t?` in ${t}`:``}`).join(`, `),_H=({apps:e,onDisconnect:t})=>{let[n,r]=(0,W.useState)(!1),[i,a]=(0,W.useState)(),[o,s]=(0,W.useState)(),c=async e=>{r(!0),a(void 0);try{await t(e.clientId),s(void 0)}catch(e){if(!(e instanceof Jm))throw e;a($C(e))}r(!1)};return(0,q.jsxs)(gV,{title:`Connected apps`,description:`AI assistants and other apps you allowed to act as you here. Disconnecting one stops it within 15 minutes; it has to ask you again to come back.`,children:[(0,q.jsx)(_V,{message:o?void 0:i}),e.length===0?(0,q.jsx)(`p`,{className:`text-muted-foreground`,children:`No apps are connected. Add this app's MCP address to an AI assistant to connect one.`}):(0,q.jsx)(`ul`,{className:`divide-y rounded-md border`,children:e.map(e=>{let t=mH(e.clientId);return(0,q.jsxs)(`li`,{className:`flex flex-wrap items-center gap-3 px-3 py-2.5`,children:[(0,q.jsx)(fc,{className:`size-4 shrink-0 text-muted-foreground`}),(0,q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,q.jsx)(`bdi`,{className:`block truncate font-medium`,children:hH(e)}),(0,q.jsxs)(`span`,{className:`block text-xs text-muted-foreground`,children:[t&&`Published by ${t} · `,`Allowed `,yr(Date.parse(e.allowedAt)),` · `,gH(e)]})]}),(0,q.jsx)(P,{size:`sm`,variant:`ghost`,onClick:()=>s(e),children:`Disconnect`})]},e.clientId)})}),o&&(0,q.jsx)(di,{title:`Disconnect ${hH(o)}?`,description:`It can no longer read or change anything as you. What it already started may keep working for up to 15 minutes.`,onClose:()=>s(void 0),actions:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(P,{onClick:()=>s(void 0),children:`Cancel`}),(0,q.jsx)(P,{variant:`danger`,loading:n,onClick:()=>void c(o),children:`Disconnect`})]}),children:i&&(0,q.jsx)(_V,{message:i})})]})},vH=(e,t)=>{let n=new URL(`https://claude.ai/customize/connectors`);return n.searchParams.set(`modal`,`add-custom-connector`),t&&n.searchParams.set(`connectorName`,t),n.searchParams.set(`connectorUrl`,e),n.href},yH=({url:e,appName:t})=>(0,q.jsx)(gV,{title:X(`mcpAddress`),description:X(`mcpAddressDescription`),children:(0,q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,q.jsx)(TS,{value:e,copyLabel:X(`copyMcpAddress`)}),(0,q.jsxs)(`a`,{href:vH(e,t),target:`_blank`,rel:`noreferrer`,className:zn(),children:[(0,q.jsx)(ol,{className:`size-3.5`}),X(`addToClaude`)]})]})}),bH=()=>{let{account:e}=Y().session,{data:t,error:n,reload:r}=tH((0,W.useCallback)(()=>e.connectedApps(),[e]),X(`couldNotReadMethods`));return t?(0,q.jsx)(_H,{apps:t,onDisconnect:t=>e.disconnectApp(t).then(r)}):(0,q.jsx)(eH,{error:n})},xH=({url:e})=>(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(yH,{url:e,appName:c().appName}),(0,q.jsx)(bH,{})]}),SH=()=>{let{mcp:e}=Y();return e?(0,q.jsx)(xH,{url:e.url}):null},CH={30:30,90:90,365:365,never:void 0},wH={30:`expiresIn30Days`,90:`expiresIn90Days`,365:`expiresInAYear`,never:`neverExpires`},TH=e=>yr(Date.parse(e)),EH=e=>e?X(Date.parse(e)<=Date.now()?`expiredOn`:`expiresOn`,{date:TH(e)}):X(`neverExpires`),DH=e=>[X(`createdOn`,{date:TH(e.createdAt)}),EH(e.expiresAt),e.lastUsedAt?X(`lastUsedOn`,{date:TH(e.lastUsedAt)}):X(`notUsedYet`),e.organization?X(`actsAsIn`,{role:e.role,organization:e.organization}):X(`actsAs`,{role:e.role})].join(` · `),OH=({tokens:e,onCreate:t,onRevoke:n})=>{let[r,i]=(0,W.useState)(!1),[a,o]=(0,W.useState)(),[s,c]=(0,W.useState)(),[l,u]=(0,W.useState)(``),[d,f]=(0,W.useState)(`90`),[p,m]=(0,W.useState)(),h=()=>{c(void 0),o(void 0),m(void 0)},g=(0,W.useRef)(!1),_=async e=>{if(!g.current){g.current=!0,i(!0),o(void 0);try{c(await e()),m(void 0)}catch(e){if(e instanceof TypeError)return o(X(`noAnswerFromServer`));if(!(e instanceof Jm))throw e;e.code===`STRONG_SIGN_IN_REQUIRED`?m(`asked`):o($C(e))}finally{g.current=!1,i(!1)}}},v=()=>_(async()=>{let e=CH[d];return{kind:`created`,created:await t({name:l.trim(),...e!==void 0&&{expiresInDays:e}})}});return(0,q.jsxs)(gV,{title:X(`accessTokens`),description:X(`accessTokensDescription`),children:[(0,q.jsx)(_V,{message:s?void 0:a}),e.length===0?(0,q.jsx)(`p`,{className:`mb-3 text-muted-foreground`,children:X(`noAccessTokens`)}):(0,q.jsx)(`ul`,{className:`mb-3 divide-y rounded-md border`,children:e.map(e=>(0,q.jsxs)(`li`,{className:`flex flex-wrap items-center gap-3 px-3 py-2.5`,children:[(0,q.jsx)(Pl,{className:`size-4 shrink-0 text-muted-foreground`}),(0,q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,q.jsx)(`bdi`,{className:`block truncate font-medium`,children:e.name}),(0,q.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:DH(e)})]}),(0,q.jsx)(P,{size:`sm`,variant:`ghost`,onClick:()=>c({kind:`revoke`,token:e}),children:X(`revoke`)})]},e.id))}),(0,q.jsxs)(P,{onClick:()=>{u(``),f(`90`),c({kind:`create`})},children:[(0,q.jsx)(Hu,{className:`size-3.5`}),X(`newAccessToken`)]}),s?.kind===`create`&&(0,q.jsxs)(di,{title:X(`newAccessToken`),description:X(`newAccessTokenDescription`),onClose:h,actions:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(P,{onClick:h,children:X(`cancel`)}),(0,q.jsx)(P,{variant:`primary`,loading:r,disabled:!l.trim(),onClick:()=>void v(),children:X(`createAccessToken`)})]}),children:[(0,q.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[X(`name`),(0,q.jsx)(bi,{autoFocus:!0,value:l,maxLength:100,placeholder:X(`accessTokenNamePlaceholder`),onChange:e=>u(e.target.value)})]}),(0,q.jsxs)(`label`,{className:`mt-3 flex flex-col gap-1.5 font-medium`,children:[X(`accessTokenExpiry`),(0,q.jsx)(gi,{value:d,onChange:e=>f(e.target.value),children:Object.keys(CH).map(e=>(0,q.jsx)(`option`,{value:e,children:X(wH[e])},e))})]}),p===`asked`&&(0,q.jsx)(TC,{purpose:`change`,minutes:15,onConfirmed:()=>m(`done`)}),p===`done`&&(0,q.jsx)(`p`,{className:`mt-2 text-muted-foreground`,children:X(`confirmedCreateAccessToken`)}),(0,q.jsx)(_V,{message:a})]}),s?.kind===`created`&&(0,q.jsx)(di,{title:X(`accessTokenCreated`,{name:s.created.personalAccessToken.name}),description:X(`accessTokenCreatedDescription`),onClose:h,actions:(0,q.jsx)(P,{variant:`primary`,onClick:h,children:X(`done`)}),children:(0,q.jsx)(TS,{value:s.created.token,copyLabel:X(`copyAccessToken`)})}),s?.kind===`revoke`&&(0,q.jsx)(di,{title:X(`revokeAccessToken`,{name:s.token.name}),description:X(`revokeAccessTokenDescription`),onClose:h,actions:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(P,{onClick:h,children:X(`cancel`)}),(0,q.jsx)(P,{variant:`danger`,loading:r,onClick:()=>void _(async()=>(await n(s.token.id),void 0)),children:X(`revoke`)})]}),children:(0,q.jsx)(_V,{message:a})})]})},kH=()=>{let{account:e}=Y().session,{data:t,error:n,reload:r}=tH((0,W.useCallback)(()=>e.personalAccessTokens(),[e]),X(`couldNotReadAccessTokens`));return t?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(_V,{message:n}),(0,q.jsx)(OH,{tokens:t,onCreate:t=>e.createPersonalAccessToken(t).then(e=>(r(),e),async e=>{throw await r(),e}),onRevoke:t=>e.revokePersonalAccessToken(t).finally(r)})]}):(0,q.jsx)(eH,{error:n})},AH=()=>Y().personalAccessTokens?(0,q.jsx)(kH,{}):null,jH=({row:e,resource:t,recordKey:n,...r})=>{let i=gz(),a=eT(),o=t??i?.resource??a?.model.name;if(o===void 0)throw Error(`RecordLink needs a resource outside a list display or a record`);return(0,q.jsx)(Ue,{to:{kind:`record`,resource:o,key:e?e.key:n},...r})},MH={revoked:`disconnectedRevoked`,queued:`disconnectedQueued`,not_revoked:`disconnectedNotRevoked`},NH=e=>e.provider===`google`,PH=({connections:e,onConnect:t,onDisconnect:n,error:r})=>{let[i,a]=(0,W.useState)(),[o,s]=(0,W.useState)(r),[c,l]=(0,W.useState)(),[u,d]=(0,W.useState)(),f=async(e,t)=>{a(e),s(void 0),d(void 0);try{await t(),l(void 0)}catch(e){if(!(e instanceof Jm))throw e;s($C(e))}finally{a(void 0)}};return(0,q.jsxs)(gV,{title:X(`connections`),description:X(`connectionsDescription`),children:[(0,q.jsx)(_V,{message:c?void 0:o}),(0,q.jsx)(vV,{message:u}),(0,q.jsx)(`ul`,{className:`divide-y rounded-md border`,children:e.map(e=>(0,q.jsxs)(`li`,{className:`flex flex-col gap-2 px-3 py-2.5`,children:[(0,q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,q.jsx)(Ru,{className:`size-4 shrink-0 text-muted-foreground`}),(0,q.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-medium`,children:e.label}),(0,q.jsx)(P,{size:`sm`,loading:i===e.key,disabled:i!==void 0,onClick:()=>void f(e.key,()=>t(e)),children:e.accounts.length>0?X(`connectAgain`,{name:e.label}):X(`connect`,{name:e.label})})]}),e.accounts.map(t=>(0,q.jsxs)(W.Fragment,{children:[(0,q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 pl-7 text-sm`,children:[(0,q.jsxs)(`span`,{className:`min-w-0 flex-1 text-muted-foreground`,children:[X(`connectedOn`,{date:yr(Date.parse(t.created_at))}),` · `,(0,q.jsx)(`code`,{className:`text-xs`,children:t.id})]}),t.needs_sign_in?(0,q.jsx)(Ni,{tone:`amber`,children:X(`connectionNeedsSignIn`)}):(0,q.jsx)(Ni,{tone:`green`,children:X(`connected`)}),(0,q.jsx)(P,{size:`sm`,variant:`ghost`,onClick:()=>l({connection:e,accountId:t.id}),children:X(`disconnect`)})]}),t.used_by.length>0&&(0,q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 pl-7 text-sm`,children:[(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:X(`connectionUsedBy`)}),t.used_by.map(e=>(0,q.jsx)(jH,{resource:`workflows`,recordKey:e.id,className:`font-medium text-primary-text hover:underline`,children:e.name},e.id))]})]},t.id))]},e.key))}),c&&(0,q.jsx)(di,{title:X(`disconnectTitle`,{name:c.connection.label}),description:NH(c.connection)?`${X(`disconnectDescription`)} ${X(`disconnectWholeGrant`)}`:X(`disconnectDescription`),onClose:()=>l(void 0),actions:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(P,{onClick:()=>l(void 0),children:X(`cancel`)}),(0,q.jsx)(P,{variant:`danger`,loading:i===c.accountId,onClick:()=>void f(c.accountId,async()=>d(X(MH[await n(c.accountId)]))),children:X(`disconnect`)})]}),children:o&&(0,q.jsx)(_V,{message:o})})]})},FH=()=>{let{session:e,connectAccount:t}=Y(),{account:n}=e,[r]=(0,W.useState)(nH),{data:i,error:a,reload:o}=tH((0,W.useCallback)(()=>n.workflowConnections(),[n]),X(`couldNotReadMethods`));return i?i.length===0?null:(0,q.jsx)(PH,{connections:i,onConnect:t,onDisconnect:e=>n.disconnectAccount(e).finally(o),error:r&&iw(r,X(`theProvider`))}):(0,q.jsx)(eH,{error:a})},IH=e=>e.code===`LAST_ADMIN`?X(`deleteAccountLastAdmin`):e.code===`ACCOUNT_LOCKED`?X(`deleteAccountLocked`):$C(e),LH=({hasPassword:e,onDelete:t,onClose:n})=>{let[r,i]=(0,W.useState)(``),[a,o]=(0,W.useState)(!1),[s,c]=(0,W.useState)(),[l,u]=(0,W.useState)(!1),d=(0,W.useId)(),f=async()=>{o(!0),c(void 0),u(!1);try{await t(e?r:void 0)}catch(e){if(!(e instanceof Jm))throw e;e.code===`STRONG_SIGN_IN_REQUIRED`?u(!0):c(IH(e)),o(!1)}};return(0,q.jsxs)(di,{title:X(`deleteAccountQuestion`),description:X(`deleteAccountWarning`),onClose:n,actions:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(P,{onClick:n,children:X(`cancel`)}),(0,q.jsx)(P,{variant:`danger`,type:`submit`,form:d,loading:a,disabled:e&&!r,children:X(`deleteAccountConfirm`)})]}),children:[(0,q.jsxs)(`form`,{id:d,className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),f()},children:[e&&(0,q.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[X(`deleteAccountPassword`),(0,q.jsx)(bi,{type:`password`,name:`current-password`,autoComplete:`current-password`,autoFocus:!0,value:r,invalid:!!s,onChange:e=>i(e.target.value)})]}),(0,q.jsx)(_V,{message:s})]}),l&&(0,q.jsx)(TC,{purpose:`change`,minutes:15,onConfirmed:()=>void f()})]})},RH=({hasPassword:e,staff:t,onDelete:n})=>{let[r,i]=(0,W.useState)(!1);return(0,q.jsxs)(gV,{title:X(`deleteAccount`),description:X(t?`deleteAccountStaff`:`deleteAccountDescription`),children:[!t&&(0,q.jsx)(P,{variant:`danger`,onClick:()=>i(!0),children:X(`deleteAccount`)}),r&&(0,q.jsx)(LH,{hasPassword:e,onDelete:n,onClose:()=>i(!1)})]})},zH=()=>{let{session:e,state:t,deleteAccount:n}=Y(),{account:r}=e,{data:i,error:a}=tH((0,W.useCallback)(()=>r.signInMethods(),[r]),X(`couldNotReadMethods`));return i?(0,q.jsx)(RH,{hasPassword:i.account.password,staff:t.kind===`signed-in`&&!!t.staff,onDelete:n}):(0,q.jsx)(eH,{error:a})},BH=[[/Edg(e|A|iOS)?\//,`Edge`],[/OPR\/|Opera/,`Opera`],[/SamsungBrowser\//,`Samsung Internet`],[/Firefox\/|FxiOS\//,`Firefox`],[/Chrome\/|CriOS\//,`Chrome`],[/Safari\//,`Safari`]],VH=[[/iPhone/,`iPhone`],[/iPad/,`iPad`],[/Android/,`Android`],[/CrOS/,`ChromeOS`],[/Windows/,`Windows`],[/Mac OS X|Macintosh/,`macOS`],[/Linux/,`Linux`]],HH=(e,t)=>e.find(([e])=>e.test(t))?.[1],UH=e=>e?{browser:HH(BH,e),system:HH(VH,e)}:{},WH=e=>e.device?X(`deviceThrough`,{device:e.device,provider:e.name}):e.name,GH=(e,t)=>{if(e.staff)return t?X(`staffOf`,{operator:t}):X(`staff`);let{browser:n,system:r}=UH(e.userAgent);return n&&r?X(`browserOn`,{browser:n,system:r}):r?X(`aBrowserOn`,{system:r}):n??X(`unknownDevice`)},KH=e=>{if(e.staff)return gd;let{system:t}=UH(e.userAgent);return t===`iPhone`||t===`Android`?Sd:t===`iPad`?Id:Rl},qH=e=>[...e].sort((e,t)=>Number(t.current)-Number(e.current)||t.createdAt.localeCompare(e.createdAt)),JH=(e,t)=>e.kind===`one`?X(`signOutDevice`,{name:GH(e.session,t)}):e.kind===`link`?X(`signOutDevice`,{name:WH(e.link)}):X(`signOutOthersTitle`),YH=e=>X(e.kind===`one`?`signOutDeviceDescription`:e.kind===`link`?`signOutLinkedDeviceDescription`:`signOutOthersDescription`),XH=({sessions:e,operator:t,links:n=[],onSignOut:r,onSignOutOthers:i,onSignOutLink:a})=>{let[o,s]=(0,W.useState)(!1),[c,l]=(0,W.useState)(),[u,d]=(0,W.useState)(),f=e.filter(e=>!n.some(t=>t.sessions.includes(e.token))),p=e.filter(e=>!e.current),m=e=>e.kind===`one`?r(e.session.token):e.kind===`link`?a(e.link.id):i(),h=async e=>{s(!0),l(void 0);try{await m(e),d(void 0)}catch(e){if(!(e instanceof Jm))throw e;l($C(e))}s(!1)},g=e=>{l(void 0),d(e)};return(0,q.jsxs)(gV,{title:X(`devices`),description:X(`devicesDescription`),children:[f.length===0&&n.length===0?(0,q.jsx)(`p`,{className:`text-muted-foreground`,children:X(`noDevices`)}):(0,q.jsxs)(`ul`,{className:`divide-y rounded-md border`,children:[qH(f).map(e=>{let n=KH(e);return(0,q.jsxs)(`li`,{className:`flex flex-wrap items-center gap-3 px-3 py-2.5`,children:[(0,q.jsx)(n,{className:`size-4 shrink-0 text-muted-foreground`}),(0,q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,q.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2`,children:[(0,q.jsx)(`bdi`,{className:`truncate font-medium`,children:GH(e,t)}),e.current&&(0,q.jsx)(Ni,{tone:`green`,children:X(`thisDevice`)})]}),(0,q.jsxs)(`span`,{className:`block text-xs text-muted-foreground`,children:[X(`signedInFromUntil`,{from:dr(Date.parse(e.createdAt)),until:dr(Date.parse(e.expiresAt))}),!e.staff&&e.ipAddress&&` · ${e.ipAddress}`]})]}),!e.current&&(0,q.jsx)(P,{size:`sm`,variant:`ghost`,onClick:()=>g({kind:`one`,session:e}),children:X(`signOut`)})]},e.token)}),n.map(t=>{let n=e.some(e=>e.current&&t.sessions.includes(e.token));return(0,q.jsxs)(`li`,{className:`flex flex-wrap items-center gap-3 px-3 py-2.5`,children:[(0,q.jsx)(Sd,{className:`size-4 shrink-0 text-muted-foreground`}),(0,q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,q.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2`,children:[(0,q.jsx)(`bdi`,{className:`truncate font-medium`,children:WH(t)}),n&&(0,q.jsx)(Ni,{tone:`green`,children:X(`thisDevice`)})]}),(0,q.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:X(`linkedOn`,{date:dr(Date.parse(t.linkedAt))})})]}),!n&&a&&(0,q.jsx)(P,{size:`sm`,variant:`ghost`,onClick:()=>g({kind:`link`,link:t}),children:X(`signOut`)})]},t.id)})]}),p.length>0&&(0,q.jsx)(P,{className:`mt-3`,onClick:()=>g({kind:`others`}),children:X(`signOutOthers`)}),u&&(0,q.jsx)(di,{title:JH(u,t),description:YH(u),onClose:()=>d(void 0),actions:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(P,{onClick:()=>d(void 0),children:X(`cancel`)}),(0,q.jsx)(P,{variant:`danger`,loading:o,onClick:()=>void h(u),children:X(`signOut`)})]}),children:(0,q.jsx)(_V,{message:c})})]})},ZH=()=>{let{session:e,staffSignIn:t,deviceLinks:n}=Y(),{account:r}=e,{data:i,error:a,reload:o}=tH((0,W.useCallback)(async()=>{let[e,t]=await Promise.all([r.sessions(),n?r.deviceLinks():[]]);return{sessions:e,links:t}},[r,n]),X(`couldNotReadDevices`));return i?(0,q.jsx)(XH,{sessions:i.sessions,links:i.links,operator:t,onSignOut:e=>r.revokeSession(e).then(o),onSignOutOthers:()=>r.revokeOtherSessions().then(o),onSignOutLink:e=>r.signOutDeviceLink(e).then(o)}):(0,q.jsx)(eH,{error:a})},QH={allowed:`passkeysAllowed`,required:`passkeysRequired`,forbidden:`passkeysForbidden`},$H=({rule:e,passkeys:t,onAdd:n,onRename:r,onRemove:i})=>{let[a,o]=(0,W.useState)(!1),[s,c]=(0,W.useState)(),[l,u]=(0,W.useState)(),[d,f]=(0,W.useState)(``),[p,m]=(0,W.useState)(),h=e===`required`&&t.length<=1,g=async e=>{o(!0),c(void 0),m(void 0);try{await e(),u(void 0)}catch(e){if(!(e instanceof Jm))throw e;e.code===`STRONG_SIGN_IN_REQUIRED`?m(`asked`):c($C(e))}o(!1)};return(0,q.jsxs)(gV,{title:X(`passkeys`),status:e===`required`&&(0,q.jsx)(Ni,{tone:`blue`,children:X(`required`)}),description:X(QH[e]),children:[(0,q.jsx)(_V,{message:l?void 0:s}),t.length>0&&(0,q.jsx)(`ul`,{className:`mb-3 divide-y rounded-md border`,children:t.map(e=>(0,q.jsxs)(`li`,{className:`flex flex-wrap items-center gap-3 px-3 py-2.5`,children:[(0,q.jsx)(Ml,{className:`size-4 shrink-0 text-muted-foreground`}),(0,q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,q.jsx)(`span`,{className:`block truncate font-medium`,children:e.name??X(`passkey`)}),(0,q.jsxs)(`span`,{className:`block text-xs text-muted-foreground`,children:[e.createdAt?X(`addedOn`,{date:yr(Date.parse(e.createdAt))}):X(`addedEarlier`),` · `,e.backedUp?X(`synced`):X(`oneDevice`)]})]}),(0,q.jsxs)(`span`,{className:`flex gap-1`,children:[(0,q.jsx)(P,{size:`sm`,variant:`ghost`,onClick:()=>{f(e.name??``),u({kind:`rename`,passkey:e})},children:X(`rename`)}),(0,q.jsx)(P,{size:`sm`,variant:`ghost`,disabled:h,title:h?X(`keepLastPasskey`):void 0,onClick:()=>u({kind:`remove`,passkey:e}),children:X(`remove`)})]})]},e.id))}),e!==`forbidden`&&(0,q.jsxs)(P,{loading:a&&!l,onClick:()=>void g(n),children:[(0,q.jsx)(Hu,{className:`size-3.5`}),X(`addPasskey`)]}),p===`asked`&&(0,q.jsx)(TC,{purpose:`change`,withPassword:!0,minutes:15,onConfirmed:()=>m(`done`)}),p===`done`&&(0,q.jsx)(`p`,{className:`mt-2 text-muted-foreground`,children:X(`confirmedAddPasskey`)}),l?.kind===`rename`&&(0,q.jsxs)(di,{title:X(`renamePasskey`),description:X(`renamePasskeyDescription`),onClose:()=>u(void 0),actions:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(P,{onClick:()=>u(void 0),children:X(`cancel`)}),(0,q.jsx)(P,{variant:`primary`,loading:a,disabled:!d.trim(),onClick:()=>void g(()=>r(l.passkey.id,d.trim())),children:X(`save`)})]}),children:[(0,q.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[X(`name`),(0,q.jsx)(bi,{autoFocus:!0,value:d,maxLength:60,onChange:e=>f(e.target.value)})]}),(0,q.jsx)(_V,{message:s})]}),l?.kind===`remove`&&(0,q.jsx)(di,{title:X(`removePasskey`),description:X(`removePasskeyDescription`,{name:l.passkey.name??X(`thisPasskey`)}),onClose:()=>u(void 0),actions:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(P,{onClick:()=>u(void 0),children:X(`cancel`)}),(0,q.jsx)(P,{variant:`danger`,loading:a,onClick:()=>void g(()=>i(l.passkey.id)),children:X(`remove`)})]}),children:s&&(0,q.jsx)(_V,{message:s})})]})},eU=()=>{let{account:e}=Y().session,{data:t,error:n,reload:r}=tH((0,W.useCallback)(()=>Promise.all([e.signInMethods(),e.passkeys()]),[e]),X(`couldNotReadMethods`));if(!t)return(0,q.jsx)(eH,{error:n});let[i,a]=t;return(0,q.jsx)($H,{rule:i.policy.passkey,passkeys:a,onAdd:()=>e.addPasskey().then(r),onRename:(t,n)=>e.renamePasskey(t,n).then(r),onRemove:t=>e.removePasskey(t).then(r)})},tU=e=>e.code===`PASSWORD_TOO_SHORT`?X(`useAtLeast`,{length:12}):e.code===`PASSWORD_TOO_LONG`?X(`passwordTooLong`):$C(e),nU=(e,t)=>{if(e.length<12)return X(`useAtLeast`,{length:12});if(e!==t)return X(`passwordsDiffer`)},rU=({hasPassword:e,onSave:t,onClose:n})=>{let[r,i]=(0,W.useState)(``),[a,o]=(0,W.useState)(``),[s,c]=(0,W.useState)(``),[l,u]=(0,W.useState)(!1),[d,f]=(0,W.useState)(),p=(0,W.useId)(),m=(!e||r)&&a&&s,h=async()=>{let e=nU(a,s);if(f(e),!e){u(!0);try{await t({current:r,next:a})}catch(e){if(!(e instanceof Jm))throw e;f(tU(e)),u(!1)}}};return(0,q.jsx)(di,{title:X(e?`changePassword`:`setPassword`),description:X(`atLeast`,{length:12}),onClose:n,actions:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(P,{onClick:n,children:X(`cancel`)}),(0,q.jsx)(P,{variant:`primary`,type:`submit`,form:p,loading:l,disabled:!m,children:X(`save`)})]}),children:(0,q.jsxs)(`form`,{id:p,className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),h()},children:[e&&(0,q.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[X(`currentPassword`),(0,q.jsx)(bi,{type:`password`,name:`current-password`,autoComplete:`current-password`,autoFocus:!0,value:r,onChange:e=>i(e.target.value)})]}),(0,q.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[X(`newPassword`),(0,q.jsx)(bi,{type:`password`,name:`new-password`,autoComplete:`new-password`,autoFocus:!e,value:a,invalid:!!d,onChange:e=>o(e.target.value)})]}),(0,q.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[X(`repeatPassword`),(0,q.jsx)(bi,{type:`password`,name:`repeat-password`,autoComplete:`new-password`,value:s,invalid:!!d,onChange:e=>c(e.target.value)})]}),e&&(0,q.jsx)(`p`,{className:`text-muted-foreground`,children:X(`changeSignsOutOthers`)}),(0,q.jsx)(_V,{message:d})]})})},iU=({rule:e,hasPassword:t,staff:n})=>X(n?`passwordStaff`:e===`forbidden`?`passwordForbidden`:t?`passwordIsSet`:`passwordNotSet`),aU=({rule:e,hasPassword:t,staff:n,onChange:r,onSet:i})=>{let[a,o]=(0,W.useState)(!1),[s,c]=(0,W.useState)(!1),l=!n&&e===`allowed`;return(0,q.jsxs)(gV,{title:X(`password`),description:iU({rule:e,hasPassword:t,staff:n}),children:[(0,q.jsx)(vV,{message:s?X(`passwordSaved`):void 0}),l&&(0,q.jsx)(P,{onClick:()=>{c(!1),o(!0)},children:X(t?`changePassword`:`setPassword`)}),a&&(0,q.jsx)(rU,{hasPassword:t,onClose:()=>o(!1),onSave:async({current:e,next:n})=>{await(t?r(e,n):i(n)),o(!1),c(!0)}})]})},oU=()=>{let{session:e,state:t}=Y(),{account:n}=e,{data:r,error:i,reload:a}=tH((0,W.useCallback)(()=>n.signInMethods(),[n]),X(`couldNotReadMethods`));return r?(0,q.jsx)(aU,{rule:r.policy.password,hasPassword:r.account.password,staff:t.kind===`signed-in`&&!!t.staff,onChange:(e,t)=>n.changePassword(e,t).then(a),onSet:e=>n.setPassword(e).then(a)}):(0,q.jsx)(eH,{error:i})},sU=({email:e,change:t,onDone:n,onClose:r})=>{let[i,a]=(0,W.useState)(``),[o,s]=(0,W.useState)(),[c,l]=(0,W.useState)(``),[u,d]=(0,W.useState)(!1),[f,p]=(0,W.useState)(),m=async e=>{d(!0),p(void 0);try{await e()}catch(e){if(!(e instanceof Jm))throw e;p($C(e))}d(!1)},h=i.trim(),g=()=>m(async()=>{await t.request(h),l(``),s(h)}),_=e=>m(async()=>{await t.confirm(o,e),n()});return o?(0,q.jsxs)(di,{title:X(`changeEmail`),description:X(`codeSentTo`,{email:o,minutes:10}),onClose:r,actions:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(P,{variant:`ghost`,onClick:()=>{s(void 0),p(void 0)},children:X(`otherAddress`)}),(0,q.jsx)(P,{variant:`primary`,loading:u,disabled:c.length<6,onClick:()=>void _(c),children:X(`changeEmail`)})]}),children:[(0,q.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[X(`code`),(0,q.jsx)(CC,{name:`code`,required:!0,autoFocus:!0,value:c,invalid:!!f,onChange:l,onComplete:e=>!u&&void _(e)})]}),(0,q.jsx)(_V,{message:f})]}):(0,q.jsxs)(di,{title:X(`changeEmail`),description:X(`changeEmailDescription`),onClose:r,actions:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(P,{onClick:r,children:X(`cancel`)}),(0,q.jsx)(P,{variant:`primary`,loading:u,disabled:!h||h.toLowerCase()===e.toLowerCase(),onClick:()=>void g(),children:X(`sendCode`)})]}),children:[(0,q.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[X(`newEmail`),(0,q.jsx)(bi,{type:`email`,autoComplete:`email`,autoFocus:!0,value:i,onChange:e=>a(e.target.value)})]}),(0,q.jsx)(_V,{message:f})]})},cU=({name:e,email:t,onRename:n,emailChange:r,onEmailChanged:i})=>{let[a,o]=(0,W.useState)(!1),[s,c]=(0,W.useState)(!1),[l,u]=(0,W.useState)(``),[d,f]=(0,W.useState)(!1),[p,m]=(0,W.useState)(),h=async()=>{f(!0),m(void 0);try{await n(l.trim()),o(!1)}catch(e){if(!(e instanceof Jm))throw e;m($C(e))}f(!1)};return(0,q.jsxs)(gV,{title:X(`profile`),description:X(`profileDescription`),children:[(0,q.jsxs)(`dl`,{className:`mb-3 grid grid-cols-[auto_1fr] gap-x-6 gap-y-1.5`,children:[(0,q.jsx)(`dt`,{className:`text-muted-foreground`,children:X(`name`)}),(0,q.jsx)(`dd`,{className:`min-w-0 truncate font-medium`,children:e}),(0,q.jsx)(`dt`,{className:`text-muted-foreground`,children:X(`email`)}),(0,q.jsx)(`dd`,{className:`min-w-0 truncate font-medium`,children:t})]}),(0,q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,q.jsx)(P,{onClick:()=>{u(e),m(void 0),o(!0)},children:X(`changeName`)}),r&&(0,q.jsx)(P,{onClick:()=>c(!0),children:X(`changeEmail`)})]}),a&&(0,q.jsxs)(di,{title:X(`changeName`),description:X(`changeNameDescription`),onClose:()=>o(!1),actions:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(P,{onClick:()=>o(!1),children:X(`cancel`)}),(0,q.jsx)(P,{variant:`primary`,loading:d,disabled:!l.trim()||l.trim()===e,onClick:()=>void h(),children:X(`save`)})]}),children:[(0,q.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[X(`name`),(0,q.jsx)(bi,{autoFocus:!0,value:l,maxLength:100,onChange:e=>u(e.target.value)})]}),(0,q.jsx)(_V,{message:p})]}),s&&r&&(0,q.jsx)(sU,{email:t,change:r,onClose:()=>c(!1),onDone:()=>{c(!1),i?.()}})]})},lU=()=>{let{session:e,changeEmail:t}=Y(),{data:n,loaded:r,error:i,reload:a}=tH((0,W.useCallback)(()=>e.session(),[e]),X(`couldNotReadProfile`));if(!r)return(0,q.jsx)(eH,{error:i});if(!n)return null;let o=t?{request:e.account.requestEmailChange,confirm:e.account.changeEmail}:void 0;return(0,q.jsx)(cU,{name:n.name,email:n.email,onRename:t=>e.account.updateName(t).then(a),emailChange:o,onEmailChanged:a})},uU=(e,t,n=`text/plain`)=>{let r=URL.createObjectURL(new Blob([e],{type:n}));Object.assign(document.createElement(`a`),{href:r,download:t}).click(),URL.revokeObjectURL(r)},dU=({codes:e})=>{let[t,n]=(0,W.useState)(!1),r=`${e.join(`
13
+ `)}\n`;return(0,q.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,q.jsx)(`ul`,{"aria-label":X(`backupCodes`),className:`grid grid-cols-2 gap-x-4 gap-y-1 rounded-md border bg-surface p-3 font-mono`,children:e.map(e=>(0,q.jsx)(`li`,{children:e},e))}),(0,q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,q.jsxs)(P,{size:`sm`,onClick:()=>{navigator.clipboard.writeText(r).then(()=>{n(!0),setTimeout(()=>n(!1),2e3)})},children:[t?(0,q.jsx)(xi,{className:`size-3.5 text-success`}):(0,q.jsx)(Wc,{className:`size-3.5`}),X(t?`copied`:`copy`)]}),(0,q.jsxs)(P,{size:`sm`,onClick:()=>uU(r,`backup-codes.txt`),children:[(0,q.jsx)(Qc,{className:`size-3.5`}),X(`download`)]})]})]})},fU=({title:e,description:t,confirmLabel:n,danger:r,needsPassword:i,onConfirm:a,onClose:o})=>{let[s,c]=(0,W.useState)(``),[l,u]=(0,W.useState)(!1),[d,f]=(0,W.useState)(),[p,m]=(0,W.useState)(!1),h=async()=>{u(!0),f(void 0),m(!1);try{await a(i?s:void 0)}catch(e){if(!(e instanceof Jm))throw e;e.code===`STRONG_SIGN_IN_REQUIRED`?m(!0):f($C(e)),u(!1)}};return(0,q.jsxs)(di,{title:e,description:t,onClose:o,actions:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(P,{onClick:o,children:X(`cancel`)}),(0,q.jsx)(P,{variant:r?`danger`:`primary`,loading:l,disabled:i&&!s,onClick:()=>void h(),children:n})]}),children:[i&&(0,q.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[X(`yourPassword`),(0,q.jsx)(bi,{type:`password`,autoComplete:`current-password`,autoFocus:!0,value:s,invalid:!!d,onChange:e=>c(e.target.value),onKeyDown:e=>e.key===`Enter`&&s&&void h()})]}),d&&(0,q.jsx)(`p`,{role:`alert`,className:`mt-2 text-body font-medium text-danger-text`,children:d}),p&&(0,q.jsx)(TC,{purpose:`change`,minutes:15,onConfirmed:()=>void h()})]})},pU=({uri:e,className:t})=>{let{size:n,path:r}=(0,W.useMemo)(()=>{let t=tn(e,{ecc:`M`,border:2}),n=t.data.flatMap((e,t)=>e.flatMap((e,n)=>e?[`M${n} ${t}h1v1h-1z`]:[]));return{size:t.size,path:n.join(``)}},[e]);return(0,q.jsxs)(`svg`,{viewBox:`0 0 ${n} ${n}`,role:`img`,"aria-label":X(`qrCode`),shapeRendering:`crispEdges`,className:t,children:[(0,q.jsx)(`rect`,{width:n,height:n,fill:`#fff`}),(0,q.jsx)(`path`,{d:r,fill:`#000`})]})},mU=e=>(new URL(e).searchParams.get(`secret`)??``).replace(/(.{4})(?=.)/g,`$1 `),hU=()=>[{value:`app`,label:X(`authenticatorApp`),description:X(`authenticatorAppDescription`)},{value:`email`,label:X(`emailedCode`),description:X(`emailedCodeDescription`)}],gU=({offerEmailedCodes:e,needsPassword:t,onStartApp:n,onConfirmApp:r,onEmailedCodes:i,onDone:a,onCancel:o})=>{let[s,c]=(0,W.useState)({kind:`choose`}),[l,u]=(0,W.useState)(`app`),[d,f]=(0,W.useState)(``),[p,m]=(0,W.useState)(``),[h,g]=(0,W.useState)(!1),[_,v]=(0,W.useState)(),[y,b]=(0,W.useState)(!1),x=e?hU():hU().filter(e=>e.value===`app`),S=async e=>{g(!0),v(void 0),b(!1);try{await e()}catch(e){if(!(e instanceof Jm))throw e;e.code===`STRONG_SIGN_IN_REQUIRED`?b(!0):v($C(e))}g(!1)},C=()=>S(async()=>{let e=t?d:void 0;if(l===`email`)return await i(e),a();c({kind:`scan`,setup:await n(e)})}),w=(e,t=p)=>S(async()=>{await r(t),c({kind:`backup-codes`,codes:e.backupCodes})}),T=_&&(0,q.jsx)(`p`,{role:`alert`,className:`text-body font-medium text-danger-text`,children:_});return s.kind===`backup-codes`?(0,q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,q.jsx)(`p`,{className:`text-muted-foreground`,children:X(`twoFactorIsOn`)}),(0,q.jsx)(dU,{codes:s.codes}),(0,q.jsx)(P,{variant:`primary`,onClick:a,className:`min-h-10`,children:X(`savedCodes`)})]}):s.kind===`scan`?(0,q.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),w(s.setup)},children:[(0,q.jsx)(`p`,{className:`text-muted-foreground`,children:X(`scanCode`)}),(0,q.jsxs)(`div`,{className:`flex flex-col items-center gap-2`,children:[(0,q.jsx)(pU,{uri:s.setup.totpURI,className:`size-44 rounded-md border`}),(0,q.jsxs)(`p`,{className:`text-center text-xs text-muted-foreground`,children:[X(`cannotScan`),(0,q.jsx)(`span`,{className:`mt-1 block break-all font-mono text-body text-foreground`,children:mU(s.setup.totpURI)})]})]}),(0,q.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[X(`codeFromApp`),(0,q.jsx)(CC,{name:`code`,required:!0,autoFocus:!0,value:p,invalid:!!_,onChange:m,onComplete:e=>!h&&void w(s.setup,e)})]}),T,(0,q.jsx)(P,{variant:`primary`,type:`submit`,loading:h,className:`min-h-10`,children:X(`turnOn`)}),o&&(0,q.jsx)(P,{variant:`ghost`,onClick:o,className:`min-h-10`,children:X(`cancel`)})]}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),C()},children:[(0,q.jsx)(`div`,{role:`radiogroup`,"aria-label":X(`secondStep`),className:`flex flex-col gap-2`,children:x.map(e=>(0,q.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":l===e.value,onClick:()=>u(e.value),className:U(`rounded-md border p-3 text-left transition-colors`,l===e.value?`border-primary bg-primary-soft`:`border-border-strong hover:bg-muted`),children:[(0,q.jsx)(`span`,{className:`block font-medium`,children:e.label}),(0,q.jsx)(`span`,{className:`mt-0.5 block text-xs text-muted-foreground`,children:e.description})]},e.value))}),t&&(0,q.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[X(`yourPassword`),(0,q.jsx)(bi,{type:`password`,name:`password`,autoComplete:`current-password`,required:!0,value:d,invalid:!!_,onChange:e=>f(e.target.value),className:`min-h-6`})]}),T,(0,q.jsx)(P,{variant:`primary`,type:`submit`,loading:h,className:`min-h-10`,children:X(`continue`)}),o&&(0,q.jsx)(P,{variant:`ghost`,onClick:o,className:`min-h-10`,children:X(`cancel`)})]}),y&&(0,q.jsx)(TC,{purpose:`change`,minutes:15,onConfirmed:()=>void C()})]})},_U={allowed:`twoFactorAllowed`,required:`twoFactorRequired`,forbidden:`twoFactorForbidden`},vU=e=>{let{rule:t,enabled:n,authenticatorApp:r,mail:i,needsPassword:a,onTurnOff:o,onNewBackupCodes:s,onChanged:c}=e,[l,u]=(0,W.useState)(),d=()=>u(void 0),f=n?(0,q.jsx)(Ni,{tone:`green`,children:X(`on`)}):t===`required`?(0,q.jsx)(Ni,{tone:`amber`,children:X(`required`)}):(0,q.jsx)(Ni,{children:X(`off`)}),p=X(n?r?i?`twoFactorOnWithAppOrMail`:`twoFactorOnWithApp`:`twoFactorOnWithMail`:_U[t]);return l?.kind===`setup`?(0,q.jsx)(gV,{title:X(`twoFactor`),status:f,description:p,children:(0,q.jsx)(`div`,{className:`max-w-sm`,children:(0,q.jsx)(gU,{offerEmailedCodes:i&&!l.appOnly,needsPassword:a,onStartApp:e.onStartApp,onConfirmApp:e.onConfirmApp,onEmailedCodes:e.onEmailedCodes,onCancel:d,onDone:()=>{d(),c()}})})}):(0,q.jsxs)(gV,{title:X(`twoFactor`),status:f,description:p,children:[(0,q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[!n&&t!==`forbidden`&&(0,q.jsx)(P,{variant:`primary`,onClick:()=>u({kind:`setup`,appOnly:!1}),children:X(`turnOn`)}),n&&!r&&t!==`forbidden`&&(0,q.jsx)(P,{onClick:()=>u({kind:`setup`,appOnly:!0}),children:X(`addAuthenticator`)}),n&&r&&(0,q.jsx)(P,{onClick:()=>u({kind:`new-codes`}),children:X(`newBackupCodes`)}),n&&(0,q.jsx)(P,{variant:`danger`,disabled:t===`required`,title:t===`required`?X(`twoFactorIsRequired`):void 0,onClick:()=>u({kind:`turn-off`}),children:X(`turnOff`)})]}),l?.kind===`turn-off`&&(0,q.jsx)(fU,{title:X(`turnOffTitle`),description:X(`turnOffDescription`),confirmLabel:X(`turnOff`),danger:!0,needsPassword:a,onClose:d,onConfirm:async e=>{await o(e),d(),c()}}),l?.kind===`new-codes`&&(0,q.jsx)(fU,{title:X(`newCodesTitle`),description:X(`newCodesDescription`),confirmLabel:X(`makeNewCodes`),needsPassword:a,onClose:d,onConfirm:async e=>u({kind:`codes`,codes:await s(e)})}),l?.kind===`codes`&&(0,q.jsx)(di,{title:X(`yourNewCodes`),description:X(`keepCodesSafe`),onClose:d,actions:(0,q.jsx)(P,{variant:`primary`,onClick:d,children:X(`savedCodes`)}),children:(0,q.jsx)(dU,{codes:l.codes})})]})},yU=()=>{let{account:e}=Y().session,{data:t,error:n,reload:r}=tH((0,W.useCallback)(()=>e.signInMethods(),[e]),X(`couldNotReadMethods`));return t?(0,q.jsx)(vU,{rule:t.policy.twoFactor,enabled:t.account.twoFactor,authenticatorApp:t.account.authenticatorApp,mail:t.mail,needsPassword:t.account.password,onStartApp:t=>e.startAuthenticatorApp(t),onConfirmApp:t=>e.confirmAuthenticatorApp(t),onEmailedCodes:t=>e.turnOnEmailedCodes(t),onTurnOff:t=>e.turnOffTwoFactor(t),onNewBackupCodes:t=>e.newBackupCodes(t),onChanged:r}):(0,q.jsx)(eH,{error:n})},bU=({problem:e,fallback:t})=>t===void 0?(0,q.jsx)(PS,{children:e}):(0,q.jsxs)(q.Fragment,{children:[!1,t]}),xU=({name:e,registered:t,fallback:n,children:r})=>t?(0,q.jsx)(FS,{name:e,fallback:n===void 0?void 0:(0,q.jsx)(bU,{problem:z.rich(`couldNotDraw`,{name:e}),fallback:n}),children:r}):(0,q.jsx)(bU,{problem:z.rich(`noComponent`,{component:e}),fallback:n}),SU={Page:Bj,Grid:Mk,Card:ET,Stat:vL,RecordCard:Wj,Field:Dk,Diff:wk,Table:kB,CardRow:yE,RecordRow:rL,RecordCards:AM,Chart:vD,Timeline:iO,Graph:hO,Progress:Hj,Image:Zk,ModalForm:SA,Thread:nV,Composer:QO,Action:TT,Show:dL,Switch:pL,Match:mL,Link:sA,Settings:sL,Tabs:jB,Tab:MB,Users:QV,Profile:lU,Password:oU,Passkeys:eU,TwoFactor:yU,ConnectedAccounts:aH,PersonalMail:dH,Connections:FH,Devices:ZH,ConnectedApps:SH,PersonalAccessTokens:AH,DeleteAccount:zH,Box:rV,Row:iV,Column:aV,Text:oV,ReferenceManyField:dV,ReferenceArrayField:pV,ArrayField:sV,RecordsIterator:_E,ReferenceField:hV,SelectInput:cV,Details:$O,Summary:ek,TextField:eA,NumberField:tA,DateField:nA,BooleanField:rA,UrlField:iA,ChipField:aA},CU=new Set(`Page.Grid.Card.Stat.RecordCard.Field.Diff.Table.CardRow.RecordRow.RecordCards.Chart.Timeline.Graph.Progress.Image.Thread.Link.Tabs.Settings.Show.Switch.Action.Box.Row.Column.Text.ReferenceField.SelectInput.Details.Summary.TextField.NumberField.DateField.BooleanField.UrlField.ChipField`.split(`.`)),wU=(e,t,...n)=>e.map((e,r)=>({child:e,...t!==void 0&&{at:Nm(t,...n,r)}})),TU=({text:e})=>{let t=tT(),n=jT(),r={...rT(t),params:n};return(0,q.jsx)(q.Fragment,{children:cr(e,e=>Sr(Im(r,e)))})},EU=(e,t)=>e.includes(`{{`)?(0,q.jsx)(TU,{text:e},t):(0,q.jsx)(W.Fragment,{children:e},t),DU=e=>e.map(({child:e,at:t},n)=>typeof e==`string`?EU(e,n):(0,q.jsx)(PU,{node:e,at:t},n)),OU=e=>{let t=[];for(let n of e){let e=t.at(-1);bm(n.child)&&e&&bm(e[0].child)?e.push(n):t.push([n])}return t.map((e,t)=>{let[n]=e;return bm(n.child)?(0,q.jsx)(`p`,{className:`leading-6`,children:DU(e)},t):(0,q.jsx)(PU,{node:n.child,at:n.at},t)})},kU=e=>er(e)||Array.isArray(e)&&e.length>0&&e.every(er),AU=(e,t)=>Object.fromEntries(Object.entries(e.props).flatMap(([e,n])=>kU(n)?[[e,(0,q.jsx)(q.Fragment,{children:OU(jU(n,t,e))})]]:[])),jU=(e,t,n)=>Array.isArray(e)?wU(e,t,`props`,n):[{child:e,...t!==void 0&&{at:Nm(t,`props`,n)}}],MU=e=>typeof e==`object`&&!!e&&!Array.isArray(e),NU=(e,t)=>{let n=MU(e.props.components)?e.props.components:{},r=Object.fromEntries(Object.entries(n).flatMap(([e,t])=>er(t)?[[e,e=>({...t,children:[...t.children,...e]})]]:[])),i=D(t,String(e.props.i18nKey),MU(e.props.values)?e.props.values:{},r);return Array.isArray(i)?i.map(e=>typeof e==`string`||er(e)?e:String(e)):[i]},PU=({node:e,at:t})=>{let{components:n}=qy(),r=tT(),i=jT(),a=Re(),o=(0,W.useMemo)(()=>y(Um(e,{...rT(r),params:i}),a),[e,r,i,a]);if(o.type===`Trans`&&!o.custom)return(0,q.jsx)(q.Fragment,{children:DU(NU(o,a).map(e=>({child:e})))});if(o.custom){let e=n?.[o.type],r=o.children.length>0?(0,q.jsx)(fO,{node:o,children:OU(wU(o.children,t,`children`))}):void 0;return(0,q.jsx)(xU,{name:o.type,registered:!!e,fallback:o.fallback&&(0,q.jsx)(q.Fragment,{children:OU(wU(o.fallback,t,`fallback`))}),children:e&&(0,q.jsx)(oO,{node:o,...t!==void 0&&{at:t},children:(0,q.jsx)(e,{...u(o.props),children:r})})})}let s=SU[o.type];if(!s)return(0,q.jsx)(PS,{children:z.rich(`unknownBlock`,{type:o.type})});let c=typeof o.props.className==`string`?o.props.className:void 0,l=wU(o.children,t,`children`),d=(0,q.jsx)(s,{node:o,at:t,slots:AU(o,t),className:c,children:o.type===`Text`||o.type===`Link`||o.type===`Summary`?DU(l):OU(o.type===`Switch`?l.filter(({child:e})=>typeof e!=`string`):l)}),f=c===void 0||CU.has(o.type)?d:(0,q.jsx)(`div`,{className:c,children:d});return o.fallback?(0,q.jsx)(FS,{name:o.type,resetKey:o,fallback:(0,q.jsx)(q.Fragment,{children:OU(wU(o.fallback,t,`fallback`))}),children:f}):f},FU=(e,t)=>{let n=fp(e,e=>e.custom?e:t.has(e.type)||(e.type===`Tab`||e.type===`Tabs`)&&e.children.length===0?null:e);if(!n)throw Error(`The account page keeps its Page, which no hidden block replaces`);return n},IU=()=>{let{account:e}=c(),t=Y(),{mcp:n,personalAccessTokens:r,accountDeletion:i}=t,a=iH(t).length>0,o=t.personalMail.length>0;return(0,W.useMemo)(()=>{if(!e)return;let t=new Set([...n?[]:[`ConnectedApps`],...r?[]:[`PersonalAccessTokens`],...a?[]:[`ConnectedAccounts`],...o?[]:[`PersonalMail`],...i?[]:[`DeleteAccount`]]);return{...e,tree:FU(e.tree,t)}},[e,n,r,a,o,i])},LU=({tab:e})=>{let t=IU();return t?(0,q.jsx)($g,{route:{...e&&{tab:e},pathOf:Xg},children:(0,q.jsx)(PU,{node:t.tree})}):(0,q.jsx)(tt,{title:X(`noAccount`),children:X(`noAccountDescription`)})},RU=500,zU=(e=window)=>e.top!==e.self,BU=(e,t,n)=>{let r=!1,i,a=e=>{r!==e&&(r=e,n(e))},o=()=>{clearTimeout(i),a(!1)},s=()=>{o(),e.defaultView&&e.visibilityState===`visible`&&e.hasFocus()&&(i=setTimeout(()=>a(!0),t))},c=()=>e.visibilityState===`visible`?s():o(),l=()=>{r||s()},u=e=>{`persisted`in e&&e.persisted&&s()};return e.defaultView?.addEventListener(`focus`,s),e.defaultView?.addEventListener(`blur`,o),e.defaultView?.addEventListener(`pagehide`,o),e.defaultView?.addEventListener(`pageshow`,u),e.addEventListener(`visibilitychange`,c),e.addEventListener(`pointerdown`,l,!0),e.addEventListener(`keydown`,l,!0),s(),()=>{clearTimeout(i),e.defaultView?.removeEventListener(`focus`,s),e.defaultView?.removeEventListener(`blur`,o),e.defaultView?.removeEventListener(`pagehide`,o),e.defaultView?.removeEventListener(`pageshow`,u),e.removeEventListener(`visibilitychange`,c),e.removeEventListener(`pointerdown`,l,!0),e.removeEventListener(`keydown`,l,!0)}},VU=()=>{let e=!1;return{down:(t,n=!1)=>{e=t&&!n},take:()=>{let t=e;return e=!1,t}}},HU=(e,t)=>n=>n?e(!0):t(()=>e(!1)),UU=e=>{let[t,n]=(0,W.useState)(!1);return(0,W.useEffect)(()=>BU(document,e,HU(n,ls.flushSync)),[e]),t},WU=(e,t)=>{let n=(0,W.useRef)(VU());return{onPointerDown:()=>n.current.down(e),onKeyDown:t=>n.current.down(e,t.repeat),onClick:()=>{n.current.take()&&t()}}},GU=[`localhost`,`127.0.0.1`,`[::1]`],KU=[`javascript:`,`data:`,`vbscript:`,`file:`,`blob:`,`about:`],qU=e=>{if(!URL.canParse(e))return;let t=new URL(e);if(t.protocol===`https:`)return{kind:`site`,host:t.host};if(t.protocol===`http:`)return GU.includes(t.hostname)?{kind:`this-computer`,port:t.port||`80`}:void 0;if(!KU.includes(t.protocol))return{kind:`device-app`,uri:e.split(`?`)[0].split(`#`)[0]}},JU=e=>!URL.canParse(e,`http://local`)||!KU.includes(new URL(e,`http://local`).protocol),YU=(e,t)=>{let n=new URL(e,t.origin);if(n.origin===t.origin&&n.pathname===t.pathname)return xf(n.search).oauthQuery},XU=()=>{let{params:e}=le();return(0,W.useMemo)(()=>xf(e.toString()),[e])},ZU={invalid_signature:`This request has expired: connect again from your app.`,STAFF_CANNOT_CONNECT:`Staff signed in as someone cannot allow apps to act for them.`,SIGN_IN_SETUP_REQUIRED:`Set up what this app requires for signing in first, then connect again from your app.`,ADDRESS_NOT_VERIFIED:`Confirm your address first: sign out, then sign in with a code emailed to you, and connect again from your app.`},QU=e=>{if(!(e instanceof Jm))throw e;return(e.code&&ZU[e.code])??$C(e)},$U=e=>t=>{if(!JU(t))throw new Jm(`The app asked to be sent somewhere this page will not go.`,400);e(t)},eW=({target:e})=>e.kind===`site`?(0,q.jsxs)(q.Fragment,{children:[`the website `,(0,q.jsx)(`strong`,{className:`font-medium text-foreground`,children:e.host})]}):e.kind===`this-computer`?(0,q.jsxs)(q.Fragment,{children:[`an app on this computer (port `,e.port,`)`]}):(0,q.jsxs)(q.Fragment,{children:[`an app on this device that opens `,(0,q.jsx)(`code`,{className:`break-all text-foreground`,children:e.uri})]}),tW=({title:e,icon:t,children:n})=>(0,q.jsx)(HV,{title:e,icon:t,children:(0,q.jsx)(`p`,{className:`text-muted-foreground`,children:n})}),nW=({asking:e,appName:t,appIcon:n,email:r,onAnswer:i,onSignOut:a})=>{let[o,s]=(0,W.useState)(!1),c=UU(500),l=e=>{s(!0),i(e).finally(()=>s(!1))},u=WU(c&&!o,()=>l(!0)),d=pH(e.client.client_name),f=mH(e.client.client_id),{target:p}=e;return(0,q.jsx)(HV,{title:`Allow an app to act as you in ${t}?`,icon:n,size:`md`,children:(0,q.jsxs)(`section`,{"aria-label":`Allow an app`,children:[(0,q.jsxs)(`p`,{children:[`An app that calls itself`,` `,(0,q.jsxs)(`bdi`,{className:`inline-block max-w-full truncate align-bottom font-medium`,title:d,children:[`“`,d??`no name`,`”`]}),` `,`asks to act as you here.`]}),f&&(0,q.jsxs)(`p`,{className:`mt-1 text-muted-foreground`,children:[`Published by `,f,`.`]}),p?(0,q.jsxs)(`p`,{className:`mt-3 text-muted-foreground`,children:[`Allowing sends you on to `,(0,q.jsx)(eW,{target:p}),`.`]}):(0,q.jsx)(`p`,{role:`alert`,className:`mt-3 text-danger-text`,children:`This app asked to be sent somewhere this page will not go, so it cannot be allowed.`}),(0,q.jsx)(`p`,{className:`mt-3 text-muted-foreground`,children:`It can then read and change what you can, with your current role and organization, until you disconnect it from your account page.`}),(0,q.jsxs)(`div`,{className:`mt-5 flex flex-col-reverse gap-2 sm:flex-row sm:justify-end`,children:[(0,q.jsx)(P,{disabled:o,onClick:()=>l(!1),children:`Deny`}),p&&(0,q.jsx)(P,{variant:`primary`,loading:o,disabled:!c||o,...u,children:`Allow`})]}),(0,q.jsxs)(`p`,{className:`mt-4 border-t pt-3 text-xs text-muted-foreground`,children:[`Signed in as `,r,`.`,` `,(0,q.jsx)(`button`,{type:`button`,className:`underline underline-offset-2 hover:text-foreground`,onClick:a,children:`Not you? Sign out`})]})]})})},rW=({oauthQuery:e,appName:t,appIcon:n,email:r,assign:i})=>{let{session:a,signOut:o}=Y(),{path:s,basePath:c}=le(),l=$U(i),u=e=>YU(e,{origin:window.location.origin,pathname:`${c}${s}`}),[d,f]=(0,W.useState)({kind:`loading`}),p=e=>f({kind:`failed`,message:QU(e)});(0,W.useEffect)(()=>{let t=!0;return(async()=>{let{url:n}=await a.connect.resume(e),r=u(n);if(r===void 0)return l(n);let i=new URLSearchParams(r),o=await a.connect.client(i.get(`client_id`)??``);t&&f({kind:`asking`,asking:{oauthQuery:r,client:o,target:qU(i.get(`redirect_uri`)??``)}})})().catch(e=>t&&p(e)),()=>{t=!1}},[a,e]);let m=async(e,t)=>{try{let{url:n}=await a.connect.answer(e,t.oauthQuery);u(n)!==void 0&&await o(),l(n)}catch(e){p(e)}};return d.kind===`failed`?(0,q.jsx)(tW,{title:`This app cannot be connected`,icon:n,children:d.message}):d.kind===`loading`?(0,q.jsxs)(`div`,{className:`flex min-h-full w-full items-center justify-center gap-2 bg-surface text-muted-foreground`,children:[(0,q.jsx)(wn,{}),` Loading`]}):(0,q.jsx)(nW,{asking:d.asking,appName:t,appIcon:n,email:r,onAnswer:e=>m(e,d.asking),onSignOut:()=>void o()})},iW=({email:e,appName:t,appIcon:n,isFramed:r=zU,assign:i=e=>window.location.assign(e)})=>{let[a]=(0,W.useState)(r),{oauthQuery:o}=XU();return a?(0,q.jsxs)(tW,{title:`This page cannot be used inside another site`,icon:n,children:[(0,q.jsx)(`a`,{href:window.location.href,target:`_blank`,rel:`noopener`,className:`underline underline-offset-2`,children:`Open it on its own`}),` `,`to go on.`]}):o?(0,q.jsx)(rW,{oauthQuery:o,appName:t,appIcon:n,email:e,assign:i},o):(0,q.jsx)(tW,{title:`Nothing to connect`,icon:n,children:`Connect again from your app.`})},aW={title:`Sign in to connect an app`,description:`An app asks to act as you here. Sign in, then choose whether to allow it.`},oW=()=>{let e=c(),{state:t}=Y();return VV(BV([`Connect an app`],e.appName)),t.kind===`signed-in`?(0,q.jsx)(iW,{email:t.user.email,appName:e.appName??`this app`,appIcon:e.appIcon}):(0,q.jsx)(HV,{title:aW.title,description:aW.description,icon:e.appIcon,children:(0,q.jsx)(`div`,{className:`flex flex-col gap-2 [&>*]:min-h-10 [&>*]:w-full`,children:(0,q.jsx)(GF,{prompt:aW})})})},sW=()=>[{value:`allowed`,label:X(`on`)},{value:`forbidden`,label:X(`off`)}],cW=()=>[{value:`allowed`,label:X(`optional`)},{value:`required`,label:X(`required`)},{value:`forbidden`,label:X(`off`)}],lW=()=>[{method:`password`,label:X(`password`),description:X(`passwordDescription`),rules:sW()},{method:`emailCode`,label:X(`emailedSignInCode`),description:X(`emailedSignInCodeDescription`),rules:sW()},{method:`passkey`,label:X(`passkeys`),description:X(`passkeysPolicyDescription`),rules:cW()},{method:`twoFactor`,label:X(`twoFactor`),description:X(`twoFactorPolicyDescription`),rules:cW()},{method:`staffAccess`,label:X(`staffAccess`),description:X(`staffAccessDescription`),rules:[{value:`allowed`,label:X(`on`)},{value:`notify`,label:X(`emailThePerson`)},{value:`forbidden`,label:X(`off`)}]},{method:`platformSignIn`,label:X(`platformSignIn`),description:X(`platformSignInDescription`),rules:sW()}],uW=(e,t)=>{let n=lW().find(t=>t.method===e)?.rules.find(e=>e.value===t)?.label;if(n===void 0)throw Error(`No label for the ${t} rule of ${e}`);return n},dW=({row:e,value:t,onChange:n})=>(0,q.jsx)(`span`,{role:`radiogroup`,"aria-label":e.label,className:`inline-flex h-8 shrink-0 rounded-md bg-muted p-0.5`,children:e.rules.map(e=>(0,q.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":e.value===t,onClick:()=>n(e.value),className:U(`rounded px-3 text-body font-medium transition-colors`,e.value===t?`bg-background text-foreground shadow-sm`:`text-muted-foreground hover:text-foreground`),children:e.label},e.value))}),fW=({method:e},t,{mail:n,effective:r,policy:i})=>{if(e===`emailCode`&&!n)return X(`codeNeedsMail`);if(e===`password`&&!n&&t.password===`forbidden`)return X(`passwordStaysOn`);if(e===`staffAccess`&&!n&&t.staffAccess===`notify`)return X(`staffNeedsMail`);if(e===`platformSignIn`&&t.platformSignIn===`allowed`&&t.passkey===`required`)return X(`platformOff`);if(t[e]===i[e]&&r[e]!==i[e])return X(`appliesAs`,{rule:uW(e,r[e])})},pW=({operator:e,platformProviders:t=[]})=>lW().flatMap(n=>n.method===`staffAccess`&&!e?[]:n.method===`platformSignIn`?t.length>0?[{...n,label:X(`platformSignInWith`,{provider:new Intl.ListFormat(ci(),{type:`conjunction`}).format(t)})}]:[]:[n]),mW=({state:e,onSave:t,busy:n,error:r,notice:i})=>{let[a,o]=(0,W.useState)(e.policy),s=pW(e),c=s.some(({method:t})=>a[t]!==e.policy[t]);return(0,q.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),t(a)},children:[(0,q.jsx)(`ul`,{className:`divide-y rounded-lg border bg-background`,children:s.map(t=>{let n=fW(t,a,e);return(0,q.jsxs)(`li`,{className:`flex flex-col gap-3 p-4 sm:flex-row sm:items-start sm:justify-between`,children:[(0,q.jsxs)(`div`,{className:`min-w-0`,children:[(0,q.jsx)(`h2`,{className:`font-semibold`,children:t.label}),(0,q.jsx)(`p`,{className:`mt-0.5 text-muted-foreground`,children:t.description}),n&&(0,q.jsx)(`p`,{className:`mt-1.5 text-xs font-medium text-warning-text`,children:n})]}),(0,q.jsx)(dW,{row:t,value:a[t.method],onChange:e=>o({...a,[t.method]:e})})]},t.method)})}),r&&(0,q.jsx)(`p`,{role:`alert`,className:`rounded-md bg-danger-soft px-3 py-2 text-body font-medium text-danger-text`,children:r}),i&&!c&&(0,q.jsx)(`p`,{role:`status`,className:`rounded-md bg-success-soft px-3 py-2 text-body font-medium text-success-text`,children:i}),(0,q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.savedAt?e.savedBy?X(`lastSavedBy`,{name:e.savedBy,time:dr(Date.parse(e.savedAt))}):X(`lastSaved`,{time:dr(Date.parse(e.savedAt))}):X(`neverChanged`)}),(0,q.jsxs)(`div`,{className:`flex gap-2`,children:[c&&(0,q.jsx)(P,{onClick:()=>o(e.policy),children:X(`reset`)}),(0,q.jsx)(P,{variant:`primary`,type:`submit`,loading:n,disabled:!c,children:X(`save`)})]})]})]})},hW=(e,t)=>e.endedAt?(0,q.jsx)(Ni,{tone:`neutral`,children:X(`stopped`,{time:dr(Date.parse(e.endedAt))})}):Date.parse(e.expiresAt)<=t?(0,q.jsx)(Ni,{tone:`neutral`,children:X(`ended`,{time:dr(Date.parse(e.expiresAt))})}):(0,q.jsx)(Ni,{tone:`amber`,children:X(`signedInUntil`,{time:dr(Date.parse(e.expiresAt))})}),gW=({signIns:e,operator:t,error:n,now:r=Date.now()})=>(0,q.jsxs)(gV,{title:X(`staffSignIns`),description:X(`staffSignInsDescription`,{operator:t}),children:[(0,q.jsx)(_V,{message:n}),e&&e.length===0&&(0,q.jsx)(`p`,{className:`text-muted-foreground`,children:X(`noStaffSignIns`)}),e&&e.length>0&&(0,q.jsx)(`ul`,{className:`divide-y rounded-md border`,children:e.map(e=>(0,q.jsxs)(`li`,{className:`flex flex-col gap-1.5 p-3`,children:[(0,q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1`,children:[(0,q.jsx)(`span`,{className:`font-medium break-all`,children:e.staffName?`${e.staffName} (${e.staff})`:e.staff}),(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:X(`as`)}),(0,q.jsx)(`span`,{className:`font-medium break-all`,children:e.user})]}),(0,q.jsx)(`p`,{className:`break-words`,children:e.reason}),(0,q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-xs text-muted-foreground`,children:[(0,q.jsx)(`span`,{children:dr(Date.parse(e.startedAt))}),hW(e,r)]})]},e.id))})]}),_W=({operator:e})=>{let{session:t}=Y(),[n,r]=(0,W.useState)(),[i,a]=(0,W.useState)();return(0,W.useEffect)(()=>{t.staff.log().then(r,e=>a(e instanceof Jm?$C(e):X(`couldNotReadStaffSignIns`)))},[t]),(0,q.jsx)(gW,{operator:e,signIns:n,error:i})},vW=()=>{let{session:e}=Y(),[t,n]=(0,W.useState)(),[r,i]=(0,W.useState)(!1),[a,o]=(0,W.useState)(),[s,c]=(0,W.useState)();(0,W.useEffect)(()=>{e.signInPolicy.read().then(n,e=>o(e instanceof Jm?$C(e):X(`couldNotReadPolicy`)))},[e]);let l=async t=>{i(!0),o(void 0),c(void 0);try{n(await e.signInPolicy.save(t)),c(X(`policySaved`))}catch(e){if(!(e instanceof Jm))throw e;o($C(e))}i(!1)};return(0,q.jsxs)(`div`,{className:`mx-auto flex w-full max-w-3xl flex-col gap-4 px-4 py-6 md:px-6`,children:[(0,q.jsx)(Rj,{title:X(`signInPolicy`),subtitle:X(`policySubtitle`)}),t?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(mW,{state:t,busy:r,error:a,notice:s,onSave:e=>void l(e)},t.savedAt??`default`),t.operator&&(0,q.jsx)(_W,{operator:t.operator})]}):a?(0,q.jsx)(`p`,{role:`alert`,className:`text-danger-text`,children:a}):(0,q.jsxs)(`div`,{className:`flex items-center gap-2 text-muted-foreground`,children:[(0,q.jsx)(wn,{}),` `,X(`loading`)]})]})},yW=4194304,bW=(e,t=yW)=>{let n=e.reduce((e,t)=>e+t.bytes,0),r=new Set(e.map(e=>e.hash)),i=e.filter(e=>!e.pinned).sort((e,t)=>e.lastUsed-t.lastUsed);for(let e of i){if(n<=t)break;r.delete(e.hash),n-=e.bytes}return r},xW=new TextEncoder,SW=e=>xW.encode(JSON.stringify(e)??``).length,CW=1e3,wW=JSON.stringify(I.meta),TW=e=>e.state.status===`success`&&e.state.fetchFailureCount===0&&!(e.queryHash===wW&&e.state.data?.versionChange),EW=(e,t,n,r,i,a=yW)=>{let o=yt(e,{shouldDehydrateQuery:TW}).queries,s=new Set(o.map(e=>e.queryHash)),c=[...o,...t.filter(e=>!s.has(e.queryHash))],l=e=>n[e.queryHash]??e.state.dataUpdatedAt,u=bW(c.map(e=>({hash:e.queryHash,bytes:e.queryHash.length+r(e.state.data),lastUsed:l(e),pinned:e.queryHash===wW||i.has(e.queryHash)})),a),d=c.filter(e=>u.has(e.queryHash));return{queries:d,used:Object.fromEntries(d.map(e=>[e.queryHash,l(e)]))}},DW=({cache:e,owner:t})=>{let n=e.queries(t),r={...n?.used},i=n?.state.queries??[],a=new WeakMap,o=e=>{if(typeof e!=`object`||!e)return SW(e);let t=a.get(e);if(t!==void 0)return t;let n=SW(e);return a.set(e,n),n};return{restore:e=>{n&&(nt(e,n.state),e.invalidateQueries({refetchType:`none`}))},subscribe:n=>{let a,s=()=>{a=void 0;let s=Date.now(),c=new Set(n.getQueryCache().findAll({type:`active`}).map(e=>e.queryHash));for(let e of c)r[e]=s;let l=EW(n,i,r,o,c);i=l.queries,r=l.used,e.saveQueries({owner:t,used:r,state:{mutations:[],queries:i}})},c=n.getQueryCache().subscribe(e=>{if(e.type===`observerAdded`)r[e.query.queryHash]=Date.now();else if(e.type!==`added`&&e.type!==`removed`&&e.type!==`updated`)return;a??=setTimeout(s,CW)});return()=>{c(),clearTimeout(a)}}}},OW=({onResend:e,cooldown:t=30,disabled:n})=>{let[r,i]=(0,W.useState)(()=>Date.now()+t*1e3),[a,o]=(0,W.useState)(()=>Date.now()),s=Math.max(0,Math.ceil((r-a)/1e3));return(0,W.useEffect)(()=>{if(s===0)return;let e=setInterval(()=>o(Date.now()),1e3);return()=>clearInterval(e)},[s]),(0,q.jsx)(P,{variant:`ghost`,disabled:n||s>0,onClick:()=>{let n=Date.now();i(n+t*1e3),o(n),e()},className:`min-h-10`,children:s>0?J(`sendNewCodeIn`,{seconds:s}):J(`sendNewCode`)})},kW=({title:e,description:t,explanation:n,submitLabel:r,onSubmit:i,onResend:a,onChangeAddress:o,changeAddressLabel:s,busy:c,error:l,notice:u,resendCooldown:d})=>{let[f,p]=(0,W.useState)(``),m=(0,W.useRef)(null);return(0,W.useEffect)(()=>{u&&(p(``),m.current?.focus())},[u]),(0,q.jsxs)(HV,{title:e,description:t,children:[(0,q.jsx)(`p`,{className:`mb-4 text-muted-foreground`,children:n}),u&&(0,q.jsx)(`p`,{role:`status`,className:`mb-4 rounded-md bg-success-soft px-3 py-2 text-body font-medium text-success-text`,children:u}),(0,q.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),i(f)},children:[(0,q.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[J(`code`),(0,q.jsx)(CC,{ref:m,name:`code`,required:!0,autoFocus:!0,value:f,invalid:!!l,onChange:p,onComplete:e=>!c&&i(e)})]}),l&&(0,q.jsx)(`p`,{role:`alert`,className:`text-body font-medium text-danger-text`,children:l}),(0,q.jsx)(P,{variant:`primary`,type:`submit`,loading:c,className:`min-h-10`,children:r}),(0,q.jsxs)(`div`,{className:`flex flex-wrap justify-center gap-x-2 sm:justify-between`,children:[(0,q.jsx)(P,{variant:`ghost`,onClick:o,className:`min-h-10`,children:s}),(0,q.jsx)(OW,{onResend:a,disabled:c,cooldown:d})]})]})]})},AW=({email:e,onBack:t,...n})=>(0,q.jsx)(kW,{title:J(`checkEmail`),description:J(`signInCodeDescription`),explanation:(0,q.jsx)(q.Fragment,{children:J.rich(`signInCodeSent`,{email:(0,q.jsx)(`span`,{className:`font-medium text-foreground`,children:e}),minutes:10})}),submitLabel:J(`signIn`),onChangeAddress:t,changeAddressLabel:J(`backToSignIn`),...n}),jW=({email:e,onBack:t})=>{let{signInWithCode:n,sendSignInCode:r}=Y(),[i,a]=(0,W.useState)(!1),[o,s]=(0,W.useState)(),[c,l]=(0,W.useState)(),u=async e=>{a(!0),s(void 0),l(void 0);try{await e()}catch(e){if(!(e instanceof Jm))throw e;s($C(e))}a(!1)};return(0,q.jsx)(AW,{email:e,busy:i,error:o,notice:c,onBack:t,onSubmit:t=>void u(()=>n(e,t)),onResend:()=>void u(async()=>{await r(e),l(J(`newCodeSent`))})})},MW=`protobase users create you@example.com`,NW=({command:e=MW,firstAdminUrl:t,onCheckAgain:n,busy:r})=>(0,q.jsxs)(HV,{title:J(`noAdminTitle`),description:J(`noAdminDescription`),children:[t?(0,q.jsx)(PW,{url:t}):(0,q.jsx)(FW,{command:e}),(0,q.jsx)(P,{variant:t?`secondary`:`primary`,className:`mt-4 min-h-10 w-full`,loading:r,onClick:n,children:J(`reload`)})]}),PW=({url:e})=>(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`p`,{className:`text-muted-foreground`,children:J(`firstAdminExplanation`)}),(0,q.jsxs)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,className:U(zn({variant:`primary`}),`mt-4 min-h-10 w-full`),children:[J(`firstAdminLink`),(0,q.jsx)(ol,{className:`size-4`})]})]}),FW=({command:e})=>{let[t,n]=(0,W.useState)(!1);return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`p`,{className:`text-muted-foreground`,children:J(`noAdminExplanation`)}),(0,q.jsxs)(`div`,{className:`mt-4 flex items-center gap-2 rounded-md border bg-surface py-1.5 pl-3 pr-1.5`,children:[(0,q.jsx)(`code`,{className:`min-w-0 flex-1 break-all font-mono text-xs`,children:e}),(0,q.jsx)(`button`,{type:`button`,"aria-label":J(`copyCommand`),onClick:()=>{navigator.clipboard.writeText(e).then(()=>{n(!0),setTimeout(()=>n(!1),2e3)})},className:`inline-flex size-8 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-muted pointer-coarse:size-11`,children:t?(0,q.jsx)(xi,{className:`size-4 text-success`}):(0,q.jsx)(Wc,{className:`size-4`})})]})]})},IW=({onSubmit:e,back:t,busy:n,error:r,sentTo:i})=>{let[a,o]=(0,W.useState)(``);return i?(0,q.jsxs)(HV,{title:J(`checkEmail`),children:[(0,q.jsx)(`p`,{className:`text-muted-foreground`,children:J.rich(`resetSent`,{email:(0,q.jsx)(`span`,{className:`font-medium text-foreground`,children:i})})}),(0,q.jsx)(Jn,{to:t,className:U(zn({variant:`primary`}),`mt-4 min-h-10 w-full`),children:J(`backToSignIn`)})]}):(0,q.jsx)(HV,{title:J(`resetTitle`),description:J(`resetDescription`),children:(0,q.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:t=>{t.preventDefault(),e(a.trim())},children:[(0,q.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[J(`email`),(0,q.jsx)(bi,{type:`email`,name:`email`,autoComplete:`username`,required:!0,autoFocus:!0,value:a,invalid:!!r,onChange:e=>o(e.target.value),className:`min-h-6`})]}),r&&(0,q.jsx)(`p`,{role:`alert`,className:`text-body font-medium text-danger-text`,children:r}),(0,q.jsx)(P,{variant:`primary`,type:`submit`,loading:n,className:`min-h-10`,children:J(`sendResetLink`)}),(0,q.jsx)(Jn,{to:t,className:U(zn({variant:`ghost`}),`min-h-10`),children:J(`backToSignIn`)})]})})},LW=`password-reset`,RW=e=>{let t=new URL(e);return`${t.origin}${t.pathname}?${LW}`},zW=e=>{let t=new URL(e).searchParams;if(t.has(`password-reset`))return{token:t.get(`token`)||void 0}},BW=e=>{let t=new URL(e);for(let e of[LW,`token`,`error`])t.searchParams.delete(e);return`${t.pathname}${t.search}${t.hash}`},VW=({back:e})=>{let{session:t}=Y(),[n,r]=(0,W.useState)(!1),[i,a]=(0,W.useState)(),[o,s]=(0,W.useState)(),c=async e=>{r(!0),a(void 0);try{await t.requestPasswordReset(e,RW(window.location.href)),s(e)}catch(e){if(!(e instanceof Jm))throw e;a(e.status===429?J(`tooManyRequests`):e.message)}r(!1)};return(0,q.jsx)(IW,{busy:n,error:i,sentTo:o,back:e,onSubmit:e=>void c(e)})},HW=({name:e,workspace:t})=>(0,q.jsx)(HV,{title:J(`signingInWith`,{name:e}),description:t,children:(0,q.jsxs)(`p`,{role:`status`,className:`flex items-center justify-center gap-2 text-muted-foreground`,children:[(0,q.jsx)(wn,{}),` `,J(`takingYouTo`,{name:e})]})}),UW=({provider:e,workspace:t,onFailed:n})=>{let{signInProviders:r,signInSocial:i}=Y(),a=r.find(t=>t.id===e),o=a?.name??Tg(e),s=(0,W.useRef)(!1);return(0,W.useEffect)(()=>{if(!s.current){if(s.current=!0,!a)return n(J(`providerNotOffered`,{name:o}));i(e).catch(e=>{if(!(e instanceof Jm))throw e;n(ew(e))})}},[a,o,e,i,n]),(0,q.jsx)(HW,{name:o,workspace:t})},WW=e=>e.status===429?J(`tooManyAttempts`):e.code===`PASSWORD_TOO_SHORT`?J(`useAtLeast`,{length:12}):e.code===`PASSWORD_TOO_LONG`?J(`passwordTooLong`):$C(e),GW=({token:e,onDone:t,onRequestNewLink:n,onBack:r})=>{let{session:i}=Y(),[a,o]=(0,W.useState)(!1),[s,c]=(0,W.useState)(),[l,u]=(0,W.useState)(!e),d=async n=>{o(!0),c(void 0);try{await i.resetPassword(e,n),t()}catch(e){if(!(e instanceof Jm))throw e;e.code===`INVALID_TOKEN`?u(!0):c(WW(e)),o(!1)}};return(0,q.jsx)(UV,{busy:a,error:s,invalidLink:l,onRequestNewLink:n,onBack:r,onSubmit:e=>void d(e)})},KW=e=>J(e===`twoFactor`?`turnOnTwoFactor`:`addPasskey`),qW=({step:e,twoFactor:t,onAddPasskey:n,busy:r,error:i,onSignOut:a})=>(0,q.jsxs)(HV,{title:KW(e),description:J(`requiredForEveryAccount`),children:[e===`twoFactor`?(0,q.jsx)(gU,{...t}):(0,q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,q.jsx)(`p`,{className:`text-muted-foreground`,children:J(`passkeyExplanation`)}),i&&(0,q.jsx)(`p`,{role:`alert`,className:`text-body font-medium text-danger-text`,children:i}),(0,q.jsxs)(P,{variant:`primary`,loading:r,onClick:n,className:`min-h-10`,children:[(0,q.jsx)(Ml,{className:`size-4`}),J(`addPasskey`)]})]}),(0,q.jsx)(`button`,{type:`button`,onClick:a,className:`mt-4 w-full text-center font-medium text-muted-foreground hover:underline`,children:J(`signOut`)})]}),JW=({missing:e})=>{let{session:t,recheck:n,signOut:r}=Y(),[i,a]=(0,W.useState)(),[o,s]=(0,W.useState)(!1),[c,l]=(0,W.useState)();(0,W.useEffect)(()=>{t.account.signInMethods().then(a,e=>l(e instanceof Jm?$C(e):J(`couldNotReadAccount`)))},[t]);let u=async()=>{s(!0),l(void 0);try{await t.account.addPasskey(),n()}catch(e){if(!(e instanceof Jm))throw e;l($C(e)),s(!1)}};return!i&&!c?(0,q.jsxs)(`div`,{className:`flex h-full min-h-48 items-center justify-center gap-2 text-muted-foreground`,children:[(0,q.jsx)(wn,{}),` `,J(`loading`)]}):(0,q.jsx)(qW,{step:e[0],busy:o,error:c,onAddPasskey:()=>void u(),onSignOut:()=>void r(),twoFactor:{offerEmailedCodes:i?.mail??!1,needsPassword:i?.account.password??!0,onStartApp:e=>t.account.startAuthenticatorApp(e),onConfirmApp:e=>t.account.confirmAuthenticatorApp(e),onEmailedCodes:e=>t.account.turnOnEmailedCodes(e),onDone:n}})},YW=({className:e})=>(0,q.jsx)(`svg`,{viewBox:`0 0 24 24`,fill:`currentColor`,className:U(`size-4 shrink-0`,e),"aria-hidden":!0,children:(0,q.jsx)(`path`,{d:`M10.226 17.284c-2.965-.36-5.054-2.493-5.054-5.256 0-1.123.404-2.336 1.078-3.144-.292-.741-.247-2.314.09-2.965.898-.112 2.111.36 2.83 1.01.853-.269 1.752-.404 2.853-.404 1.1 0 1.999.135 2.807.382.696-.629 1.932-1.1 2.83-.988.315.606.36 2.179.067 2.942.72.854 1.101 2 1.101 3.167 0 2.763-2.089 4.852-5.098 5.234.763.494 1.28 1.572 1.28 2.807v2.336c0 .674.561 1.056 1.235.786 4.066-1.55 7.255-5.615 7.255-10.646C23.5 6.188 18.334 1 11.978 1 5.62 1 .5 6.188.5 12.545c0 4.986 3.167 9.12 7.435 10.669.606.225 1.19-.18 1.19-.786V20.63a2.9 2.9 0 0 1-1.078.224c-1.483 0-2.359-.808-2.987-2.313-.247-.607-.517-.966-1.034-1.033-.27-.023-.359-.135-.359-.27 0-.27.45-.471.898-.471.652 0 1.213.404 1.797 1.235.45.651.921.943 1.483.943.561 0 .92-.202 1.437-.719.382-.381.674-.718.944-.943`})}),XW=({id:e,className:t})=>e===`github`?(0,q.jsx)(YW,{className:t}):null,ZW=`https://protobase.net/`,QW=()=>(0,q.jsx)(`footer`,{className:`mt-8 text-center`,children:(0,q.jsx)(`a`,{href:ZW,rel:`nofollow noreferrer`,className:`inline-block text-sm font-normal leading-6 text-muted-foreground no-underline hover:underline focus-visible:underline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary`,children:J(`runsOnProtobase`)})}),$W=()=>(0,q.jsxs)(`div`,{className:`my-4 flex items-center gap-3 text-xs text-muted-foreground`,children:[(0,q.jsx)(`span`,{className:`h-px flex-1 bg-border`}),J(`or`),(0,q.jsx)(`span`,{className:`h-px flex-1 bg-border`})]}),eG=({onSubmit:e,busy:t,error:n,workspace:r,notice:i,methods:a=[`password`],first:o=`password`,onSendCode:s,onPasskey:c,passkeyDomains:l=[],forgotPassword:u,providers:d=[],onContinueWith:f,signUp:p,onBrowse:m,appName:h,runsOnNote:g=!1})=>{let[_,v]=(0,W.useState)(``),[y,b]=(0,W.useState)(``),[x,S]=(0,W.useState)(!1),C=(0,W.useRef)(null),w=a.includes(`password`),T=a.includes(`emailCode`)&&s!==void 0,E=a.includes(`passkey`)&&c!==void 0,D=f?d:[],O=o===`emailCode`&&w&&T&&!x,k=w&&!O,ee=()=>{C.current?.reportValidity()&&s?.(_.trim())};return(0,q.jsxs)(HV,{title:J(`signInTitle`,{name:h??`Protobase`}),description:r,appName:h,footer:g&&(0,q.jsx)(QW,{}),children:[i&&(0,q.jsx)(`p`,{role:`status`,className:`mb-4 rounded-md bg-success-soft px-3 py-2 text-body font-medium text-success-text`,children:i}),(D.length>0||E)&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[D.map(e=>(0,q.jsxs)(P,{onClick:()=>f?.(e.id),disabled:t,className:`min-h-10 w-full`,children:[(0,q.jsx)(XW,{id:e.id}),J(`continueWith`,{name:e.name})]},e.id)),E&&(0,q.jsxs)(P,{onClick:()=>c?.(),disabled:t,className:`min-h-10 w-full`,children:[(0,q.jsx)(Ml,{className:`size-4`}),J(`signInWithPasskey`)]}),E&&l.slice(1).map(e=>(0,q.jsx)(P,{variant:`ghost`,size:`sm`,onClick:()=>c?.(e),disabled:t,className:`w-full`,children:J(`passkeyFor`,{domain:e})},e))]}),w||T?(0,q.jsx)($W,{}):n&&(0,q.jsx)(`p`,{role:`alert`,className:`mt-4 text-body font-medium text-danger-text`,children:n})]}),(w||T)&&(0,q.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:t=>{t.preventDefault(),k?e(_.trim(),y):ee()},children:[(0,q.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[J(`email`),(0,q.jsx)(bi,{ref:C,type:`email`,name:`email`,autoComplete:`username webauthn`,required:!0,autoFocus:!0,value:_,invalid:!!n,onChange:e=>v(e.target.value),className:`min-h-6`})]}),k&&(0,q.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[J(`password`),(0,q.jsx)(bi,{type:`password`,name:`password`,autoComplete:`current-password`,required:!0,value:y,invalid:!!n,onChange:e=>b(e.target.value),className:`min-h-6`})]}),n&&(0,q.jsx)(`p`,{role:`alert`,className:`text-body font-medium text-danger-text`,children:n}),k&&(0,q.jsx)(P,{variant:`primary`,type:`submit`,loading:t,className:`min-h-10`,children:J(`signIn`)}),T&&(0,q.jsxs)(P,{variant:k?`secondary`:`primary`,type:k?`button`:`submit`,onClick:k?ee:void 0,loading:t&&!k,disabled:t,className:`min-h-10`,children:[(0,q.jsx)(iu,{className:`size-4`}),J(`emailSignInCode`)]}),O&&(0,q.jsx)(P,{variant:`ghost`,onClick:()=>S(!0),disabled:t,className:`min-h-10`,children:J(`usePassword`)}),k&&u&&(0,q.jsx)(Jn,{to:u,className:`self-center font-medium text-primary-text hover:underline`,children:J(`forgotPassword`)})]}),p&&(0,q.jsxs)(`p`,{className:`mt-4 text-center text-muted-foreground`,children:[J(`newHere`),` `,(0,q.jsx)(Jn,{to:p,className:`font-medium text-primary-text hover:underline`,children:J(`createAnAccount`)})]}),m&&(0,q.jsx)(`button`,{type:`button`,onClick:m,className:`mt-4 w-full text-center font-medium text-muted-foreground hover:text-foreground hover:underline`,children:J(`browse`)})]})},tG=({workspace:e,notice:t,forgotPassword:n,signUp:r,onBrowse:i,onCodeSent:a,error:o})=>{let{identity:s,signIn:c,signInSocial:l,signInProviders:u,signInMethods:d,signInFirst:f,passkeyDomains:p,sendSignInCode:m,signInWithPasskey:h}=Y(),[g,_]=(0,W.useState)(!1),[v,y]=(0,W.useState)(o),b=async(e,t)=>{_(!0),y(void 0);try{await e()}catch(e){if(!(e instanceof Jm))throw e;y(t(e)),_(!1)}};return(0,q.jsx)(eG,{busy:g,error:v,workspace:e,notice:t,methods:d,first:f,forgotPassword:n,signUp:r,onBrowse:i,...s.appName&&{appName:s.appName},runsOnNote:s.runsOnNote,providers:Eg(u),onContinueWith:e=>void b(()=>l(e),ew),passkeyDomains:p,onPasskey:e=>void b(()=>h(e),$C),onSendCode:e=>void b(async()=>{await m(e),a(e)},$C),onSubmit:(e,t)=>void b(()=>c(e,t),ew)})},nG=({email:e,onBack:t,...n})=>(0,q.jsx)(kW,{title:J(`checkEmail`),description:J(`signUpCodeDescription`),explanation:(0,q.jsx)(q.Fragment,{children:J.rich(`signUpCodeSent`,{email:(0,q.jsx)(`span`,{className:`font-medium text-foreground`,children:e}),minutes:10})}),submitLabel:J(`continue`),onChangeAddress:t,changeAddressLabel:J(`useAnotherAddress`),...n}),rG=({email:e,onSubmit:t,onBack:n,methods:r,askName:i=!0,busy:a,error:o})=>{let[s,c]=(0,W.useState)(``),[l,u]=(0,W.useState)(``),d=(0,W.useId)(),f=r.includes(`password`),p=r.includes(`emailCode`);return(0,q.jsxs)(HV,{title:J(`detailsTitle`),description:J(`detailsDescription`),children:[(0,q.jsx)(`p`,{className:`mb-4 text-muted-foreground`,children:J.rich(`codeWasRight`,{email:(0,q.jsx)(`span`,{className:`font-medium text-foreground`,children:e})})}),(0,q.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),t({...i&&{name:s.trim()},...f&&l&&{password:l}})},children:[i&&(0,q.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[J(`yourName`),(0,q.jsx)(bi,{name:`name`,autoComplete:`name`,required:!0,autoFocus:!0,maxLength:200,value:s,onChange:e=>c(e.target.value),className:`min-h-6`})]}),f&&(0,q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,q.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[J(p?`passwordOptional`:`password`),(0,q.jsx)(bi,{type:`password`,name:`password`,autoComplete:`new-password`,"aria-describedby":d,required:!p,minLength:12,maxLength:128,value:l,onChange:e=>u(e.target.value),className:`min-h-6`})]}),(0,q.jsxs)(`p`,{id:d,className:`text-xs text-muted-foreground`,children:[J(`atLeast`,{length:12}),p&&J(`withoutPassword`)]})]}),o&&(0,q.jsx)(`p`,{role:`alert`,className:`text-body font-medium text-danger-text`,children:o}),(0,q.jsx)(P,{variant:`primary`,type:`submit`,loading:a,className:`min-h-10`,children:J(`createAccount`)}),(0,q.jsx)(P,{variant:`ghost`,onClick:n,className:`min-h-10`,children:J(`useAnotherAddress`)})]})]})},iG=({onSubmit:e,onSignIn:t,onBrowse:n,busy:r,error:i,workspace:a})=>{let[o,s]=(0,W.useState)(``);return(0,q.jsxs)(HV,{title:J(`createAnAccount`),description:a,children:[(0,q.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:t=>{t.preventDefault(),e(o.trim())},children:[(0,q.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[J(`email`),(0,q.jsx)(bi,{type:`email`,name:`email`,autoComplete:`email`,required:!0,autoFocus:!0,value:o,invalid:!!i,onChange:e=>s(e.target.value),className:`min-h-6`})]}),(0,q.jsx)(`p`,{className:`text-muted-foreground`,children:J(`codeToConfirm`)}),i&&(0,q.jsx)(`p`,{role:`alert`,className:`text-body font-medium text-danger-text`,children:i}),(0,q.jsxs)(P,{variant:`primary`,type:`submit`,loading:r,className:`min-h-10`,children:[(0,q.jsx)(iu,{className:`size-4`}),J(`emailCode`)]}),(0,q.jsxs)(`p`,{className:`text-center text-muted-foreground`,children:[J(`haveAccount`),` `,(0,q.jsx)(`button`,{type:`button`,onClick:t,className:`font-medium text-primary-text hover:underline`,children:J(`signIn`)})]})]}),n&&(0,q.jsx)(`button`,{type:`button`,onClick:n,className:`mt-4 w-full text-center font-medium text-muted-foreground hover:text-foreground hover:underline`,children:J(`browseWithoutAccount`)})]})},aG=({workspace:e,email:t,ticket:n,onCodeSent:r,onVerified:i,onBack:a,onSignIn:o,onBrowse:s})=>{let{signInMethods:c,sendSignUpCode:l,verifySignUpCode:u,signUp:d,signUpAsksName:f}=Y(),p=f||c.includes(`password`)&&!c.includes(`emailCode`),[m,h]=(0,W.useState)(!1),[g,_]=(0,W.useState)(),[v,y]=(0,W.useState)(),b=async e=>{h(!0),_(void 0),y(void 0);try{await e()}catch(e){if(!(e instanceof Jm))throw e;_($C(e))}h(!1)};return t===void 0?(0,q.jsx)(iG,{workspace:e,busy:m,error:g,onSignIn:o,onBrowse:s,onSubmit:e=>void b(async()=>{await l(e),r(e)})}):n===void 0?(0,q.jsx)(nG,{email:t,busy:m,error:g,notice:v,onBack:a,onSubmit:e=>void b(async()=>{let n=await u(t,e);p?i(n):await d({ticket:n})}),onResend:()=>void b(async()=>{await l(t),y(J(`newCodeSent`))})}):(0,q.jsx)(rG,{email:t,methods:c,askName:f,busy:m,error:g,onBack:a,onSubmit:e=>void b(()=>d({ticket:n,...e}))})},oG=`staff-sign-in`,sG=`staff-error`,cG=e=>{let t=new URL(e).searchParams,n=t.get(sG);if(!t.has(`staff-sign-in`)&&!n)return;let r=t.has(oG);return{email:r&&t.get(`email`)||``,reason:r&&t.get(`reason`)||``,...n&&{error:n}}},lG=e=>{let t=new URL(e);if(t.searchParams.has(`staff-sign-in`))for(let e of[oG,`email`,`reason`])t.searchParams.delete(e);return t.searchParams.delete(sG),`${t.pathname}${t.search}${t.hash}`},uG=10,dG=({operator:e,email:t=``,reason:n=``,onSubmit:r,onBack:i,busy:a,error:o})=>{let[s,c]=(0,W.useState)(t),[l,u]=(0,W.useState)(n);return e?(0,q.jsx)(HV,{title:J(`signInAsPerson`),description:J(`forStaffOf`,{operator:e}),children:(0,q.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),r(s.trim(),l.trim())},children:[(0,q.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[J(`theirEmail`),(0,q.jsx)(bi,{type:`email`,name:`email`,required:!0,autoFocus:!t,value:s,onChange:e=>c(e.target.value),className:`min-h-6`})]}),(0,q.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[J(`reason`),(0,q.jsx)(`textarea`,{name:`reason`,required:!0,minLength:uG,rows:3,value:l,placeholder:J(`reasonExample`),onChange:e=>u(e.target.value),className:U(`resize-y rounded-md border bg-background px-2.5 py-1.5 font-normal shadow-sm outline-none placeholder:text-faint-foreground focus:border-primary focus:ring-2 focus:ring-primary/20`,o?`border-danger`:`border-border-strong`)})]}),(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:J(`staffExplanation`,{operator:e})}),o&&(0,q.jsx)(`p`,{role:`alert`,className:`text-body font-medium text-danger-text`,children:o}),(0,q.jsx)(P,{variant:`primary`,type:`submit`,loading:a,className:`min-h-10`,children:J(`continueWith`,{name:e})}),(0,q.jsx)(P,{variant:`ghost`,onClick:i,className:`min-h-10`,children:J(`backToSignIn`)})]})}):(0,q.jsxs)(HV,{title:J(`staffTitle`),description:J(`staffUnavailable`),children:[o&&(0,q.jsx)(`p`,{role:`alert`,className:`mb-4 text-body font-medium text-danger-text`,children:o}),(0,q.jsx)(P,{variant:`primary`,className:`min-h-10 w-full`,onClick:i,children:J(`backToSignIn`)})]})},fG=({link:e,onBack:t})=>{let{session:n,staffSignIn:r}=Y(),[i,a]=(0,W.useState)(!1),[o,s]=(0,W.useState)(e.error&&nw(e.error)),c=async(e,t)=>{a(!0),s(void 0);try{let r=`${window.location.origin}${lG(window.location.href)}`;window.location.assign(await n.staff.start({email:e,reason:t,callbackURL:r}))}catch(e){if(!(e instanceof Jm))throw e;s(nw(e)),a(!1)}};return(0,q.jsx)(dG,{operator:r,email:e.email,reason:e.reason,busy:i,error:o,onBack:t,onSubmit:(e,t)=>void c(e,t)})},pG={totp:`totpInstruction`,otp:`otpInstruction`,backup:`backupInstruction`},mG=({methods:e,onVerify:t,onSendCode:n,onBack:r,busy:i,error:a,codeSent:o,initialStep:s})=>{let[c,l]=(0,W.useState)(s??(e.includes(`totp`)?`totp`:`otp`)),[u,d]=(0,W.useState)(``),[f,p]=(0,W.useState)(!1),m=c===`otp`&&!o,h=e=>{l(e),d(``),e===`otp`&&!o&&n()};return(0,q.jsxs)(HV,{title:J(`twoFactorTitle`),description:J(`twoFactorDescription`),children:[m?(0,q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,q.jsx)(`p`,{className:`text-muted-foreground`,children:J(`codeToFinish`)}),a&&(0,q.jsx)(`p`,{role:`alert`,className:`text-body font-medium text-danger-text`,children:a}),(0,q.jsx)(P,{variant:`primary`,loading:i,onClick:n,className:`min-h-10`,children:J(`emailCode`)})]}):(0,q.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),t({method:c,code:u.trim(),trustDevice:f})},children:[(0,q.jsx)(`p`,{className:`text-muted-foreground`,children:J(pG[c],{minutes:10})}),(0,q.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[J(c===`backup`?`backupCode`:`code`),c===`backup`?(0,q.jsx)(bi,{name:`code`,autoComplete:`off`,spellCheck:!1,required:!0,autoFocus:!0,value:u,invalid:!!a,onChange:e=>d(e.target.value),className:`min-h-6 font-mono`}):(0,q.jsx)(CC,{name:`code`,required:!0,autoFocus:!0,value:u,invalid:!!a,onChange:d})]}),(0,q.jsxs)(`label`,{className:`flex items-center gap-2 text-muted-foreground`,children:[(0,q.jsx)(Di,{checked:f,onChange:p,label:J(`trustBrowser`)}),J(`trustBrowserFor`)]}),a&&(0,q.jsx)(`p`,{role:`alert`,className:`text-body font-medium text-danger-text`,children:a}),(0,q.jsx)(P,{variant:`primary`,type:`submit`,loading:i,className:`min-h-10`,children:J(`verify`)})]}),(0,q.jsxs)(`div`,{className:`mt-4 flex flex-col items-center gap-2 border-t pt-4`,children:[c!==`totp`&&e.includes(`totp`)&&(0,q.jsx)(`button`,{type:`button`,onClick:()=>h(`totp`),className:`font-medium text-primary-text hover:underline`,children:J(`useAuthenticator`)}),c!==`otp`&&e.includes(`otp`)&&(0,q.jsx)(`button`,{type:`button`,onClick:()=>h(`otp`),className:`font-medium text-primary-text hover:underline`,children:J(`emailCodeInstead`)}),c!==`backup`&&e.includes(`totp`)&&(0,q.jsx)(`button`,{type:`button`,onClick:()=>h(`backup`),className:`font-medium text-primary-text hover:underline`,children:J(`useBackupCode`)}),(0,q.jsx)(`button`,{type:`button`,onClick:r,className:`font-medium text-muted-foreground hover:underline`,children:J(`backToSignIn`)})]})]})},hG=({methods:e,onBack:t})=>{let{verifyTwoFactor:n,session:r}=Y(),[i,a]=(0,W.useState)(!1),[o,s]=(0,W.useState)(),[c,l]=(0,W.useState)(!1),u=async e=>{a(!0),s(void 0);try{await e()}catch(e){if(!(e instanceof Jm))throw e;s($C(e))}a(!1)};return(0,q.jsx)(mG,{methods:e,busy:i,error:o,codeSent:c,onBack:t,onVerify:e=>void u(()=>n(e)),onSendCode:()=>void u(async()=>{await r.sendTwoFactorCode(),l(!0)})})},gG=e=>{let t=new URL(e),n=t.searchParams.get(`token`);return t.pathname.endsWith(`/-/invitation`)&&n?{token:n}:void 0},_G=e=>`${new URL(e).pathname.slice(0,-13)}/`,vG=({token:e,preview:t,joins:n,onDone:r})=>{let{session:i,signInMethods:a,recheck:o}=Y(),[s,c]=(0,W.useState)(``),[l,u]=(0,W.useState)(``),{busy:d,error:f,run:p}=yV(),m=a.includes(`password`),h=a.includes(`emailCode`),g=()=>p(async()=>{await i.organizations.signUpFromInvitation(e,{name:s.trim(),...m&&l&&{password:l}}),r(),o()});return(0,q.jsxs)(`form`,{className:`flex flex-col gap-3`,onSubmit:e=>{e.preventDefault(),g()},children:[(0,q.jsx)(`p`,{className:`text-muted-foreground`,children:Z(n?`makeAccountToJoin`:`makeAccount`,{email:t.email})}),f&&(0,q.jsx)(`p`,{role:`alert`,className:`text-body font-medium text-danger-text`,children:f}),(0,q.jsx)(bi,{"aria-label":Z(`yourName`),placeholder:Z(`yourName`),autoComplete:`name`,value:s,onChange:e=>c(e.target.value)}),m&&(0,q.jsx)(bi,{"aria-label":Z(`password`),type:`password`,autoComplete:`new-password`,placeholder:Z(h?`passwordOptional`:`passwordRequired`,{length:12}),value:l,onChange:e=>u(e.target.value)}),(0,q.jsx)(P,{type:`submit`,variant:`primary`,loading:d,disabled:!s.trim()||m&&!h&&l.length<12,children:Z(n?`createAndJoin`:`createYourAccount`)})]})},yG=({token:e,onDone:t,signIn:n})=>{let{session:r,state:i,signOut:a,organizations:o}=Y(),[s,c]=(0,W.useState)(),[l,u]=(0,W.useState)(),{busy:d,error:f,run:p}=yV();if((0,W.useEffect)(()=>{r.organizations.invitation(e).then(c,e=>u(e instanceof Jm?$C(e):Z(`invalidLink`)))},[r,e]),l)return(0,q.jsx)(HV,{title:Z(`invitation`),description:l,children:(0,q.jsx)(P,{className:`w-full`,onClick:t,children:Z(`goToApp`)})});if(!s)return(0,q.jsx)(HV,{title:Z(`invitation`),children:(0,q.jsxs)(`div`,{className:`flex items-center justify-center gap-2 text-muted-foreground`,children:[(0,q.jsx)(wn,{}),` `,Z(`loading`)]})});let m=i.kind===`signed-in`?i.user:void 0,h=m?.email.toLowerCase()===s.email.toLowerCase();if(!s.organization){let r=s.app?.name??``,i=Z(`invitesToApp`,{inviter:s.inviter.name,app:r});return(0,q.jsx)(HV,{title:Z(`join`,{name:r}),description:i,children:s.hasAccount?m&&h?(0,q.jsx)(P,{variant:`primary`,className:`w-full`,onClick:t,children:Z(`goToApp`)}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`p`,{className:`mb-3 text-muted-foreground`,children:Z(`hasAccount`,{email:s.email})}),m?(0,q.jsx)(P,{className:`w-full`,onClick:()=>void a(),children:Z(`signOut`)}):(0,q.jsx)(Jn,{to:n,className:U(zn({variant:`primary`}),`w-full`),children:Z(`signInAs`,{email:s.email})})]}):m?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`p`,{className:`mb-3 text-muted-foreground`,children:Z(`otherAddress`,{invited:s.email,signedIn:m.email})}),(0,q.jsx)(P,{className:`w-full`,onClick:()=>void a(),children:Z(`signOutToAccept`)})]}):(0,q.jsx)(vG,{token:e,preview:s,joins:!1,onDone:t})})}let g=s.organization,_=s.appRoles.map(e=>MV(o?.roles??[],e)),v=jV(s.role).toLowerCase(),y=_.length>0?Z(`invitesToWith`,{inviter:s.inviter.name,organization:g.name,role:v,roles:_.join(`, `)}):Z(`invitesTo`,{inviter:s.inviter.name,organization:g.name,role:v});return m&&!h?(0,q.jsxs)(HV,{title:Z(`join`,{name:g.name}),description:y,children:[(0,q.jsx)(`p`,{className:`mb-3 text-muted-foreground`,children:Z(`otherAddress`,{invited:s.email,signedIn:m.email})}),(0,q.jsx)(P,{className:`w-full`,onClick:()=>void a(),children:Z(`signOutToAccept`)})]}):(0,q.jsx)(HV,{title:Z(`join`,{name:g.name}),description:y,children:m?(0,q.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[f&&(0,q.jsx)(`p`,{role:`alert`,className:`text-body font-medium text-danger-text`,children:f}),(0,q.jsx)(P,{variant:`primary`,className:`w-full`,loading:d,onClick:()=>void p(async()=>{await r.organizations.accept(e),t()}),children:Z(`join`,{name:g.name})})]}):s.hasAccount?(0,q.jsx)(Jn,{to:n,className:U(zn({variant:`primary`}),`w-full`),children:Z(`signInAsToJoin`,{email:s.email})}):(0,q.jsx)(vG,{token:e,preview:s,joins:!0,onDone:t})})},bG=/^[A-Z][A-Za-z0-9]*$/,xG=e=>typeof e==`function`||typeof e==`object`&&!!e&&`$$typeof`in e,SG=e=>{let t=e.default??{},n=Object.entries(e).filter(e=>e[0]!=="default"&&bG.test(e[0])&&xG(e[1]));if(n.length===0)return t;for(let[e,r]of n)if(t.components&&Object.hasOwn(t.components,e)&&t.components[e]!==r)throw Error(`The component "${e}" is exported by name and given in components as another one; keep the export`);return{...t,components:{...t.components,...Object.fromEntries(n)}}},CG=class extends Error{name=`UiConflictError`},wG=e=>Object.keys(e).some(e=>e==="default"||/^[A-Z]/.test(e))?SG(e):e,TG=(e,t)=>[...(e.extends??[]).map(wG).flatMap((e,n)=>TG(e,e.name??`${t} extends[${n}]`)),{ui:e,label:t}],EG=(e,t,n)=>{let r={},i=new Map;for(let{ui:a,label:o}of t)for(let[t,s]of Object.entries(n(a)??{})){if(Object.hasOwn(r,t)&&r[t]!==s)throw new CG(`${e} "${t}" is defined twice, by ${i.get(t)} and by ${o}; rename one of them`);r[t]=s,i.set(t,i.get(t)??o)}return r},DG=e=>e.length<=1?e[0]:()=>e.map((e,t)=>(0,q.jsx)(e,{},t)),OG=e=>e.length<=1?e[0]:({children:t,...n})=>e.reduceRight((e,t)=>(0,q.jsx)(t,{...n,children:e}),t),kG=(...e)=>{let t=e.flatMap((e,t)=>TG(e,e.name??`UI config ${t+1}`)),n=EG(`The component`,t,e=>e.components),r=EG(`The action handler`,t,e=>e.actions),i=EG(`The field type`,t,e=>e.fields),a=EG(`The file viewer`,t,e=>e.fileViewers),o=EG(`The drop rule`,t,e=>e.dropRules),s=EG(`The board drop`,t,e=>e.boardDrops),c=EG(`The title rule`,t,e=>e.titles),l=EG(`The marks hook`,t,e=>e.marks),u=DG(t.flatMap(({ui:e})=>e.shell?.actions?[e.shell.actions]:[])),d=DG(t.flatMap(({ui:e})=>e.shell?.rightPanel?[e.shell.rightPanel]:[])),f=t.findLast(({ui:e})=>e.shell?.logo)?.ui.shell?.logo,p=t.findLast(({ui:e})=>e.shell?.bell)?.ui.shell?.bell,m=t.findLast(({ui:e})=>e.presence)?.ui.presence,h=OG(t.flatMap(({ui:e})=>e.beforeSignIn?[e.beforeSignIn]:[])),g=e.at(-1)?.name;return{...g&&{name:g},components:n,actions:r,...Object.keys(i).length>0&&{fields:i},...Object.keys(a).length>0&&{fileViewers:a},...Object.keys(o).length>0&&{dropRules:o},...Object.keys(s).length>0&&{boardDrops:s},...Object.keys(c).length>0&&{titles:c},...Object.keys(l).length>0&&{marks:l},...(u||d||f||p)&&{shell:{...u&&{actions:u},...d&&{rightPanel:d},...f&&{logo:f},...p&&{bell:p}}},...m&&{presence:m},...h&&{beforeSignIn:h}}},AG=(e,t)=>{let n=kG(e??{}),r=[],i=[];for(let e of t){if(e.kind===`off`){i.push(e);continue}try{kG(...r,e.ui,n),r.push(e.ui)}catch(t){if(!(t instanceof CG))throw t;i.push({kind:`off`,url:e.plugin.url,name:e.plugin.name,reason:t.message})}}return{ui:r.length===0?n:kG(...r,n),off:i}},jG=B(`plugins`),MG=e=>typeof e==`string`&&e.trim()!==``,NG=e=>{if(typeof e!=`object`||!e||Array.isArray(e))return{problem:jG(`notObject`)};let{name:t,version:n,api:r,protobase:i,entry:a,css:o}=e;return MG(t)?Number.isInteger(r)?MG(i)?MG(a)?o!==void 0&&!MG(o)?{problem:jG(`badStylesheet`)}:n!==void 0&&!MG(n)?{problem:jG(`badVersion`)}:{manifest:{name:t,api:r,protobase:i,entry:a,...n!==void 0&&{version:n},...o!==void 0&&{css:o}}}:{problem:jG(`noModule`)}:{problem:jG(`noVersions`)}:{problem:jG(`noApi`)}:{problem:jG(`noName`)}},PG=(0,W.createContext)(null),FG=PG.Provider,IG=()=>{let e=(0,W.useContext)(PG);if(!e)throw Error(`usePlugin is for the components of a plugin the app loaded`);return e},LG=(e,t,n)=>{let r=n=>(0,q.jsx)(FG,{value:e,children:(0,q.jsx)(t,{...n})});return r.displayName=`${e.name}:${n}`,r},RG=(e,t,n)=>({of:n.of,display:LG(e,n.display,`fields.${t}.display`),...n.editor&&{editor:LG(e,n.editor,`fields.${t}.editor`)},...n.cell&&{cell:LG(e,n.cell,`fields.${t}.cell`)}}),zG=(e,t)=>{let n=kG({...SG(t),name:e.name}),r=Object.fromEntries(Object.entries(n.components??{}).map(([t,n])=>[t,LG(e,n,t)])),i=n.fields&&Object.fromEntries(Object.entries(n.fields).map(([t,n])=>[t,RG(e,t,n)])),a=n.fileViewers&&Object.fromEntries(Object.entries(n.fileViewers).map(([t,n])=>[t,{component:LG(e,n.component,`fileViewers.${t}`)}])),o=n.shell&&{...n.shell.actions&&{actions:LG(e,n.shell.actions,`shell.actions`)},...n.shell.rightPanel&&{rightPanel:LG(e,n.shell.rightPanel,`shell.rightPanel`)},...n.shell.logo&&{logo:LG(e,n.shell.logo,`shell.logo`)},...n.shell.bell&&{bell:LG(e,n.shell.bell,`shell.bell`)}},s=n.beforeSignIn&&LG(e,n.beforeSignIn,`beforeSignIn`);return{name:e.name,components:r,...n.actions&&{actions:n.actions},...n.dropRules&&{dropRules:n.dropRules},...n.boardDrops&&{boardDrops:n.boardDrops},...n.titles&&{titles:n.titles},...n.marks&&{marks:n.marks},...i&&{fields:i},...a&&{fileViewers:a},...o&&{shell:o},...s&&{beforeSignIn:s}}},BG={readJson:async e=>{let t=await fetch(e,{cache:`no-cache`,credentials:`same-origin`});return t.ok?{json:await t.json()}:{status:t.status}},addStylesheet:e=>{if([...document.querySelectorAll(`link[rel="stylesheet"]`)].some(t=>t.href===e))return;let t=document.createElement(`link`);t.rel=`stylesheet`,t.href=e,document.head.append(t)},importModule:e=>Ht(()=>import(e),[])},VG={api:ds,version:fs},HG=e=>e instanceof Error?e.message:String(e),UG=async(e,t,n,r=VG)=>{let i=new URL(e.url,n).href,a=(e,t)=>({kind:`off`,url:i,...t&&{name:t},reason:e}),o;try{let n=await t.readJson(i);if(`status`in n)return a(jG(`answered`,{status:n.status}));let s=NG(n.json);if(`problem`in s)return a(s.problem);let{manifest:c}=s;o=c.name;let l=ko(c,r);if(l)return a(l,o);c.css&&t.addStylesheet(new URL(c.css,i).href);let u=await t.importModule(new URL(c.entry,i).href),d={name:o,...c.version&&{version:c.version},url:i,settings:e.settings??{}};return{kind:`loaded`,plugin:d,ui:zG(d,u)}}catch(e){return a(jG(`couldNotLoad`,{reason:HG(e)}),o)}},WG=e=>{let t=new Map;return{load:n=>{let r=JSON.stringify(n),i=t.get(r);if(i)return i;let a=UG(n,e,window.location.href);return t.set(r,a),a}}},GG=(0,W.createContext)(null),KG=({loader:e=BG,children:t})=>{let n=(0,W.useMemo)(()=>WG(e),[e]);return(0,q.jsx)(GG.Provider,{value:n,children:t})},qG=()=>{let e=(0,W.useContext)(GG);if(!e)throw Error(`usePluginSource must be used inside PluginSourceProvider`);return e},JG=1e4,YG=[],XG=(e,t)=>{let n=JSON.stringify(e),[r,i]=(0,W.useState)({key:`[]`,loads:YG,settled:!0});return(0,W.useEffect)(()=>{if(e.length===0)return;let r=!0,a=!1,o=e.map(()=>void 0),s=()=>{if(!r)return;let t=o.filter(e=>e!==void 0);i({key:n,loads:t,settled:a||t.length===e.length})},c=setTimeout(()=>{a=!0,s()},JG);return e.forEach((e,n)=>{t.load(e).then(e=>{o[n]=e,s()})}),()=>{r=!1,clearTimeout(c)}},[n,t]),e.length===0?{loads:YG,settled:!0}:r.key===n?r:{loads:YG,settled:!1}},ZG=({children:e})=>{let{state:t,beforeSignIn:n,adoptSession:r}=Y(),{path:i,params:a,navigate:o}=le(),{loads:s,settled:c}=XG(n,qG()),l=(0,W.useMemo)(()=>AG(void 0,s).ui.beforeSignIn,[s]),u=(0,W.useCallback)(e=>{let t=new URLSearchParams(a);for(let n of e)t.delete(n);o(t.size>0?`${i}?${t}`:i,{replace:!0})},[i,a,o]);return t.kind!==`signed-out`&&t.kind!==`visitor`?e:c?l?(0,q.jsx)(FS,{name:`beforeSignIn`,fallback:e,children:(0,q.jsx)(l,{signedIn:r,params:a,removeParams:u,children:e})}):e:(0,q.jsxs)(`div`,{className:`flex h-full min-h-48 items-center justify-center gap-2 text-muted-foreground`,children:[(0,q.jsx)(ne,{}),(0,q.jsx)(wn,{}),` `,jG(`loading`)]})},QG=()=>{let e=window.location.href,t=zW(e);if(t)return{kind:`reset-password`,token:t.token};let n=cG(e);if(n)return{kind:`staff-sign-in`,link:n};let r=gG(e);if(r)return{kind:`invitation`,token:r.token};let i=yg(e);if(i)return{kind:`provider-sign-in`,provider:i};let a=bg(e);return a?{kind:`sign-in`,providerError:a}:{kind:`sign-in`}},$G=({to:e})=>{let{navigate:t}=le();return(0,W.useEffect)(()=>t(e,{replace:!0}),[t,e]),null},eK=({workspace:e,children:t})=>{let n=tK(e,t);return(0,q.jsx)(ZG,{children:n})},tK=(e,t)=>{let{state:n,recheck:r,passwordReset:i,signOut:a,signInProviders:o,canSignUp:s,browse:c}=Y(),{path:l,params:u,basePath:d,navigate:f}=le(),{address:p,next:m,open:h,link:g,leave:_}=UF(),[v,y]=(0,W.useState)(QG),[b,x]=(0,W.useState)(),[S,C]=(0,W.useState)(),[w,T]=(0,W.useState)(),E=new URL(`${d}${l}${u.size>0?`?${u}`:``}`,window.location.origin).href,D=(0,W.useCallback)(e=>{let t=e(E).slice(d.length);f(t.startsWith(`/`)?t:`/${t}`,{replace:!0})},[E,d,f]),O=n.kind===`signed-in`||n.kind===`two-factor`||n.kind===`setup-required`,k=Sg(E)!==void 0;(0,W.useEffect)(()=>{O&&((v.kind===`provider-sign-in`||k)&&D(Cg),(v.kind===`provider-sign-in`||v.kind===`sign-in`&&(v.notice||v.error||v.providerError))&&y({kind:`sign-in`}),x(void 0),C(void 0),T(void 0))},[O,v,k,D]);let ee=p!==void 0&&bg(E)!==void 0;(0,W.useEffect)(()=>{!O&&v.kind===`sign-in`&&v.providerError&&ee&&D(Cg)},[O,v,ee,D]);let A=(0,W.useCallback)(e=>y({kind:`sign-in`,error:e}),[]),te=e=>{D(BW),y(e)},re=async()=>{n.kind===`signed-in`&&await a(),te({kind:`sign-in`,notice:J(`passwordChanged`)})},j=()=>{y({kind:`sign-in`}),a().then(()=>h(`sign-in`,{replace:!0}))};switch(n.kind){case`loading`:return(0,q.jsxs)(`div`,{className:U(`flex h-full min-h-48 items-center justify-center gap-2 text-muted-foreground`,or),children:[(0,q.jsx)(ne,{}),(0,q.jsx)(wn,{}),` `,J(`loading`)]});case`error`:return(0,q.jsxs)(`div`,{className:`flex h-full min-h-48 flex-col items-center justify-center gap-3 p-8 text-center`,children:[(0,q.jsx)(`p`,{className:`text-muted-foreground`,children:J(`cannotReach`,{message:n.message})}),(0,q.jsx)(P,{onClick:r,children:J(`tryAgain`)})]});case`needs-admin`:return(0,q.jsx)(NW,{firstAdminUrl:n.firstAdminUrl,onCheckAgain:r})}if(n.kind===`signed-in`&&p)return(0,q.jsx)($G,{to:m??`/`});if(v.kind===`reset-password`)return(0,q.jsx)(GW,{token:v.token,onDone:()=>void re(),onRequestNewLink:i?()=>{y({kind:`sign-in`}),f(Df({step:`forgot-password`}),{replace:!0})}:void 0,onBack:()=>te({kind:`sign-in`})});if(v.kind===`staff-sign-in`)return(0,q.jsx)(fG,{link:v.link,onBack:()=>{D(lG),y({kind:`sign-in`})}});let ie=n.kind===`signed-out`||n.kind===`visitor`;if(v.kind===`invitation`&&(n.kind===`signed-in`||ie&&!p))return(0,q.jsx)(yG,{token:v.token,onDone:()=>{D(_G),y({kind:`sign-in`})},signIn:g()});if(n.kind===`signed-in`)return t;if(n.kind===`two-factor`)return(0,q.jsx)(hG,{methods:n.methods,onBack:j});if(n.kind===`setup-required`)return(0,q.jsx)(JW,{missing:n.missing},n.missing.join());if(v.kind===`provider-sign-in`)return(0,q.jsx)(UW,{provider:v.provider,workspace:e,onFailed:A});let M=v.kind===`sign-in`?v:{kind:`sign-in`};if(!p){let e=M.notice||M.error||M.providerError;return n.kind===`visitor`&&!e?t:(0,q.jsx)($G,{to:Df({next:m})})}let ae={"sign-in":!0,"forgot-password":i,"email-code":b!==void 0,"sign-up":s,"sign-up-code":s&&S!==void 0,"sign-up-details":s&&w!==void 0}[p.step]?p.step:`sign-in`,oe=e=>()=>h(e,{replace:!0}),se=c&&(()=>{c(),_()});if(ae===`forgot-password`)return(0,q.jsx)(VW,{back:g(`sign-in`,{replace:!0})});if(ae===`email-code`)return(0,q.jsx)(jW,{email:b,onBack:oe(`sign-in`)});if(ae===`sign-up`||ae===`sign-up-code`||ae===`sign-up-details`)return(0,q.jsx)(aG,{workspace:e,email:ae===`sign-up`?void 0:S,ticket:ae===`sign-up-details`?w:void 0,onCodeSent:e=>{C(e),T(void 0),h(`sign-up-code`)},onVerified:e=>{T(e),h(`sign-up-details`,{replace:!0})},onBack:oe(`sign-up`),onSignIn:()=>h(`sign-in`),onBrowse:se},ae);let ce=M.providerError&&iw(M.providerError,o.length===1?o[0].name:`the provider`),ue=M.error??ce;return(0,q.jsx)(tG,{workspace:e,notice:M.notice,error:ue,forgotPassword:i?g(`forgot-password`):void 0,onCodeSent:e=>{x(e),h(`email-code`)},signUp:s?g(`sign-up`):void 0,onBrowse:se},ue)},nK=3e4,rK=(e,t=Date.now())=>Math.max(1e3,bh(e)-t-nK),iK=()=>{let{state:e,session:t}=Y(),n=e.kind===`signed-in`,[r,i]=(0,W.useState)();return(0,W.useEffect)(()=>{if(!n)return;let e=!0,r,a=async n=>{let o=await t.token(),s=o!==void 0&&o===n?await t.token({refresh:!0}):o;e&&(i(s),s&&(r=setTimeout(()=>void a(s),rK(s))))};return a(),()=>{e=!1,clearTimeout(r)}},[t,n]),n?r:void 0},aK=({children:e})=>(0,q.jsx)(M,{locale:Y().locale,children:e}),oK=e=>{if(e?.kind!==`signed-in`)return;let{id:t,name:n}=e.user;return{id:t,...n&&{name:n}}},sK=()=>{let e=Ig()?.state;return(0,W.useMemo)(()=>oK(e),[e])},cK=e=>{let t=oK(e);return t?`user:${t.id}`:`state:${e.kind}`},lK=e=>{let t=F(),n=nn(),r=(0,W.useContext)(On),i=(0,W.useMemo)(()=>Object.values(e.resources).filter(t=>t.live&&!ie(e,t.name)).map(e=>e.name).sort().join(`,`),[e]);(0,W.useEffect)(()=>{if(!i)return;let e=ix(n,()=>r?.paused()??!1),a=t.live({onChanges:t=>e.changed(t.map(e=>e.resource)),onResync:()=>e.changed(i.split(`,`))});return()=>{a(),e.stop()}},[t,n,r,i])},uK=B(`forms`),dK=async(e,t)=>{let n=await e.formChallenge(t),r=await Xt({challenge:n,deriveKey:on});if(!r)throw Error(uK(`checkTooLong`));return{challenge:n,solution:{counter:r.counter,derivedKey:r.derivedKey}}},fK=({name:e})=>{let t=F(),n=Tt({queryKey:I.publicForm(e),queryFn:()=>t.form(e)});return n.isPending?(0,q.jsxs)(`div`,{className:`flex h-full min-h-48 items-center justify-center gap-2 text-muted-foreground`,children:[(0,q.jsx)(wn,{}),` `,uK(`loading`)]}):n.error?Tn(n.error)&&n.error.status===404?(0,q.jsx)(tt,{title:uK(`notFound`),children:uK(`noForm`)}):(0,q.jsx)(tt,{title:_(`cannotReach`),children:Tn(n.error)?n.error.message:_(`noAnswer`)}):(0,q.jsx)(pK,{form:n.data})},pK=({form:e})=>{let t=F(),{resource:n,view:r}=e,i=e.title??r.names?.singular??H(r.resource);VV(i);let[a,o]=(0,W.useState)(()=>Ty(n,[{title:i,fields:e.fields}])),[s,c]=(0,W.useState)({}),[l,u]=(0,W.useState)(),[d,f]=(0,W.useState)(!1),[p,m]=(0,W.useState)(!1),[h,g]=(0,W.useState)(0),_=_A(h);if(p)return(0,q.jsx)(HV,{title:i,size:`md`,children:(0,q.jsx)(`p`,{role:`status`,className:`rounded-md bg-success-soft px-3 py-2 text-body font-medium text-success-text`,children:e.thanks})});let v=(e,t)=>{c(t=>Object.fromEntries(Object.entries(t).filter(([t])=>t!==e))),o(n=>({...n,[e]:t}))},y=async()=>{f(!0),u(void 0);try{await t.submitForm(e.name,by(n,{},a),await dK(t,e.name)),m(!0)}catch(e){let t=hA(e);c(t),Object.keys(t).length>0?g(e=>e+1):u(e)}finally{f(!1)}};return(0,q.jsx)(HV,{title:i,size:`md`,children:(0,q.jsxs)(`form`,{ref:_,className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),y()},children:[e.fields.map(e=>{let t=n.fields[e],i=r.fields[e],o=i?.label??H(e),c=s[e];return(0,q.jsx)(Mv,{name:e,label:o,help:i?.help,required:xy(t),error:c&&mA(t,o,c),children:(0,q.jsx)(GC,{field:t,hints:i,value:a[e]??(t.type!==`boolean`&&``),stored:void 0,placeholder:Ey(t)?uK(`setByDatabase`):wy(t),invalid:!!c,onChange:t=>v(e,t)})},e)}),l!==void 0&&(0,q.jsx)(Oy,{title:uK(`notSent`),error:l}),(0,q.jsx)(P,{variant:`primary`,type:`submit`,loading:d,className:`min-h-10`,children:uK(`send`)})]})})},mK=()=>{let{path:e}=le();return(0,W.useMemo)(()=>Ra(e),[e])},Q=B(`calls`),hK=(e,t)=>{e.srcObject=new MediaStream([t]);let n=()=>{t.readyState===`live`&&e.play().catch(e=>{if(!(e instanceof DOMException&&(e.name===`AbortError`||e.name===`NotAllowedError`)))throw e})};return e.addEventListener(`pause`,n),()=>e.removeEventListener(`pause`,n)},gK=({track:e,...t})=>{let n=(0,W.useCallback)(t=>t?hK(t,e):void 0,[e]);return(0,q.jsx)(`video`,{ref:n,autoPlay:!0,playsInline:!0,muted:!0,...t})},_K=({track:e})=>{let t=(0,W.useCallback)(t=>t?hK(t,e):void 0,[e]);return(0,q.jsx)(`audio`,{ref:t,autoPlay:!0})},vK=e=>U(`size-10 rounded-full`,!e&&`bg-danger-soft text-danger-text`),yK=({name:e,member:t,camera:n,microphoneOn:r,cameraOn:i,microphone:a,cameraAvailable:o,notices:s,onMicrophone:c,onCamera:l,onJoin:u,cancel:d,joinLabel:f=Q(`joinCall`)})=>(0,q.jsxs)(`section`,{"aria-label":Q(`preview`),className:`flex size-full min-h-0 flex-col items-center justify-center gap-3 bg-background p-4`,children:[(0,q.jsx)(`figure`,{className:`relative flex aspect-video w-full max-w-md items-center justify-center overflow-hidden rounded-lg bg-neutral-900`,children:n&&i?(0,q.jsx)(gK,{track:n,"aria-label":Q(`preview`),className:`size-full -scale-x-100 object-cover`}):(0,q.jsx)(v_,{initials:Ob(e),hue:Db(t),size:`md`,className:`size-16 text-xl ring-0`})}),s.length>0&&(0,q.jsx)(`div`,{role:`status`,className:`flex w-full max-w-md flex-col gap-1`,children:s.map(e=>(0,q.jsx)(`p`,{className:`rounded-md bg-warning-soft px-3 py-1.5 text-xs text-foreground`,children:e},e))}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(P,{size:`icon`,"aria-label":Q(`microphone`),"aria-pressed":r,disabled:!a,className:vK(r),onClick:c,children:r?(0,q.jsx)(mu,{className:`size-4`}):(0,q.jsx)(fu,{className:`size-4`})}),(0,q.jsx)(P,{size:`icon`,"aria-label":Q(`camera`),"aria-pressed":i,disabled:!o,className:vK(i),onClick:l,children:i?(0,q.jsx)(sf,{className:`size-4`}):(0,q.jsx)(af,{className:`size-4`})}),(0,q.jsx)(P,{variant:`primary`,className:`h-10 rounded-full px-5`,onClick:u,children:f}),(0,q.jsx)(Jn,{to:d,className:`px-2 text-sm text-muted-foreground hover:text-foreground`,children:Q(`leave`)})]})]}),bK=()=>{let[e,t]=(0,W.useState)(!1);return{run:(0,W.useCallback)(e=>{t(!1),(async()=>{let{GuestRefused:n}=await Ht(async()=>{let{GuestRefused:e}=await import(`./calls-BQqt6R-b.js`);return{GuestRefused:e}},__vite__mapDeps([54,7]));await e().catch(e=>{if(!(e instanceof n))throw e;t(!0)})})()},[]),refused:e}},xK={all:[`camera`,`microphone`,`screen`,`screen-audio`],camera:[`camera`,`microphone`],microphone:[`microphone`]},SK={call:void 0,hour:36e5},CK=({name:e,children:t})=>(0,q.jsxs)(`li`,{className:`flex items-center justify-between gap-2 py-1.5`,children:[(0,q.jsx)(`span`,{className:`min-w-0 truncate text-sm text-foreground`,children:e}),(0,q.jsx)(`span`,{className:`flex shrink-0 gap-1.5`,children:t})]}),wK=({lobby:e,inCall:t,guests:n,linkOf:r,open:i,onClose:a})=>{let[o,s]=(0,W.useState)(`camera`),[c,l]=(0,W.useState)(`call`),[u,d]=(0,W.useState)(),[f,p]=(0,W.useState)(!1),{run:m,refused:h}=bK(),g=()=>m(async()=>{let e=SK[c],{link:t,token:i}=await n.link({publish:xK[o],...e!==void 0&&{expiresAt:new Date(Date.now()+e)}});d({id:t.id,url:r(i)})}),_=e=>void navigator.clipboard.writeText(e).then(()=>{p(!0),setTimeout(()=>p(!1),2e3)});return(0,q.jsx)(g_,{title:Q(`guests`),description:Q(`addressesVisible`),open:i,onClose:a,actions:(0,q.jsx)(P,{onClick:a,children:Q(`close`)}),children:(0,q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[h&&(0,q.jsx)(`p`,{role:`alert`,className:`rounded-md bg-warning-soft px-3 py-1.5 text-xs text-foreground`,children:Q(`guestRefused`)}),e.guests.length>0&&(0,q.jsxs)(`section`,{"aria-label":Q(`inLobby`),children:[(0,q.jsx)(`h3`,{className:`text-xs font-medium text-muted-foreground`,children:Q(`inLobby`)}),(0,q.jsx)(`ul`,{children:e.guests.map(({guest:e,name:t})=>(0,q.jsxs)(CK,{name:t,children:[(0,q.jsx)(P,{size:`sm`,variant:`primary`,onClick:()=>m(()=>n.admit(e)),children:Q(`admit`)}),(0,q.jsx)(P,{size:`sm`,onClick:()=>m(()=>n.deny(e)),children:Q(`deny`)})]},e))})]}),t.length>0&&(0,q.jsxs)(`section`,{"aria-label":Q(`guestsInCall`),children:[(0,q.jsx)(`h3`,{className:`text-xs font-medium text-muted-foreground`,children:Q(`guestsInCall`)}),(0,q.jsx)(`ul`,{children:t.map(({guest:e,name:t})=>(0,q.jsx)(CK,{name:t,children:(0,q.jsx)(P,{size:`sm`,variant:`danger`,onClick:()=>m(()=>n.remove(e)),children:Q(`remove`)})},e))})]}),(0,q.jsxs)(`section`,{"aria-label":Q(`guestLinks`),className:`flex flex-col gap-2`,children:[(0,q.jsx)(`h3`,{className:`text-xs font-medium text-muted-foreground`,children:Q(`guestLinks`)}),e.links.length===0&&(0,q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:Q(`noLinks`)}),(0,q.jsx)(`ul`,{children:e.links.map(e=>(0,q.jsxs)(`li`,{className:`flex flex-col gap-1.5 py-1.5`,children:[u?.id===e.id&&(0,q.jsx)(bi,{readOnly:!0,value:u.url,"aria-label":Q(`copyLink`),onFocus:e=>e.currentTarget.select(),trailing:(0,q.jsx)(`button`,{type:`button`,"aria-label":Q(f?`copied`:`copyLink`),onClick:()=>_(u.url),className:`inline-flex size-8 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-muted pointer-coarse:size-11`,children:f?(0,q.jsx)(xi,{className:`size-4 text-success`}):(0,q.jsx)(Wc,{className:`size-4`})})}),(0,q.jsxs)(`span`,{className:`flex items-center justify-between gap-2 text-xs text-muted-foreground`,children:[e.expires_at?Q(`linkUntil`,{until:new Date(e.expires_at).toLocaleString()}):Q(`linkUntilEnd`),(0,q.jsx)(P,{size:`sm`,onClick:()=>m(()=>n.revoke(e.id)),children:Q(`revoke`)})]})]},e.id))}),(0,q.jsxs)(`div`,{className:`flex flex-col items-start gap-2`,children:[(0,q.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2 text-xs text-muted-foreground`,children:[Q(`guestsMaySend`),(0,q.jsx)(Av,{label:Q(`guestsMaySend`),value:o,onChange:s,options:[{value:`all`,label:Q(`sendAll`)},{value:`camera`,label:Q(`sendCamera`)},{value:`microphone`,label:Q(`sendMicrophone`)}]})]}),(0,q.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2 text-xs text-muted-foreground`,children:[Q(`linkLasts`),(0,q.jsx)(Av,{label:Q(`linkLasts`),value:c,onChange:l,options:[{value:`call`,label:Q(`linkUntilEnd`)},{value:`hour`,label:Q(`forAnHour`)}]})]}),(0,q.jsx)(P,{variant:`primary`,onClick:g,children:Q(`newLink`)})]})]})]})})},TK=({waiting:e,guests:t})=>{let{run:n,refused:r}=bK(),i=e[0];return i?(0,q.jsxs)(`div`,{role:`status`,className:`flex shrink-0 flex-wrap items-center gap-2 rounded-md bg-primary-soft px-3 py-1.5 text-xs text-foreground`,children:[(0,q.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:r?Q(`guestRefused`):Q(`waitingGuest`,{name:i.name})}),(0,q.jsx)(P,{size:`sm`,variant:`primary`,onClick:()=>n(()=>t.admit(i.guest)),children:Q(`admit`)}),(0,q.jsx)(P,{size:`sm`,onClick:()=>n(()=>t.deny(i.guest)),children:Q(`deny`)})]}):null},EK={ended:`ended`,removed:`removed`,full:`full`,refused:`refused`,unavailable:`unavailable`,denied:`denied`},DK=({reason:e,onJoinAgain:t})=>(0,q.jsxs)(`section`,{role:`status`,className:`flex size-full min-h-0 flex-col items-center justify-center gap-3 bg-background p-4 text-center`,children:[(0,q.jsx)(`p`,{className:`text-sm text-foreground`,children:Q(e===`rejoin`?`ended`:EK[e])}),t&&e!==`removed`&&e!==`refused`&&e!==`denied`&&(0,q.jsx)(P,{onClick:t,children:Q(`callAgain`)})]}),OK=(e,t)=>t<640?e<=2?1:2:Math.min(4,Math.ceil(Math.sqrt(e))),kK=({people:e,sharers:t,width:n})=>t[0]===void 0?e<=1?{kind:`alone`}:{kind:`grid`,columns:OK(e,n)}:{kind:`share`,sharer:t[0]},AK=({roundTripMs:e,lostRatio:t})=>(e??0)>400||(t??0)>.05?`poor`:`good`,jK=(e,t,n)=>e===`failed`||e!==`connected`&&n-t>=15e3,MK=(e,t=.05)=>{let n;for(let[r,i]of e)i>=t&&(!n||i>n[1])&&(n=[r,i]);return n?.[0]},NK=(e,t)=>e.find(e=>e.source===t&&e.track),PK=({members:e,self:t,tracks:n,own:r,nameOf:i,speaker:a,connections:o,seen:s,now:c})=>(e.some(e=>e.member===t)?e:[{member:t,joined_at:``},...e]).map(({member:e,name:l})=>{let u={member:e,name:e.startsWith(`guest:`)?Q(`guestName`,{name:l??``}):l??i(e),...a===e&&{speaking:!0}};if(e===t)return{...u,self:!0,...r.camera&&{camera:r.camera},...r.microphone&&{microphone:r.microphone},...r.screen&&{screen:r.screen},microphoneOff:!r.microphone||!r.microphoneOn,cameraOff:!r.camera||!r.cameraOn};let d=n.filter(t=>t.member===e),[f,p,m,h]=[`camera`,`microphone`,`screen`,`screen-audio`].map(e=>NK(d,e)),g=o.find(t=>t.member===e),_=jK(g?.state,s.get(e)??c,c)?`failed`:g?.state===`connected`?AK(g):void 0;return{...u,...f&&{camera:f.track},...p&&{microphone:p.track},...m&&{screen:m.track},...h&&{screenAudio:h.track},microphoneOff:!p||p.muted,cameraOff:!f||f.muted,..._&&{connection:_}}}),FK=e=>U(`size-10 rounded-full`,!e&&`bg-danger-soft text-danger-text`),IK=({microphoneOn:e,cameraOn:t,sharing:n,onMicrophone:r,onCamera:i,onShare:a,guests:o,leave:s})=>(0,q.jsxs)(`div`,{role:`toolbar`,"aria-label":Q(`joinCall`),className:`flex shrink-0 flex-wrap items-center justify-center gap-2 py-2`,children:[(0,q.jsx)(P,{size:`icon`,"aria-label":Q(`microphone`),"aria-pressed":e,title:Q(`microphone`),className:FK(e),onClick:r,children:e?(0,q.jsx)(mu,{className:`size-4`}):(0,q.jsx)(fu,{className:`size-4`})}),(0,q.jsx)(P,{size:`icon`,"aria-label":Q(`camera`),"aria-pressed":t,title:Q(`camera`),className:FK(t),onClick:i,children:t?(0,q.jsx)(sf,{className:`size-4`}):(0,q.jsx)(af,{className:`size-4`})}),a&&(0,q.jsx)(P,{size:`icon`,"aria-label":Q(n?`stopSharing`:`shareScreen`),"aria-pressed":!!n,title:Q(n?`stopSharing`:`shareScreen`),className:`size-10 rounded-full`,onClick:a,children:n?(0,q.jsx)(vu,{className:`size-4`}):(0,q.jsx)(gu,{className:`size-4`})}),o&&(0,q.jsxs)(P,{size:`icon`,"aria-label":Q(`guests`),title:Q(`guests`),className:`relative size-10 rounded-full`,onClick:o.onOpen,children:[(0,q.jsx)(Xd,{className:`size-4`}),(0,q.jsx)(lj,{count:o.waiting,className:`absolute -top-1 -right-1`})]}),(0,q.jsxs)(Jn,{to:s,className:U(zn({variant:`danger`}),`h-10 rounded-full px-4`),children:[(0,q.jsx)(Pu,{className:`size-4`}),Q(`leave`)]})]}),LK=({person:e,screen:t=!1,className:n})=>{let r=t?e.screen:e.cameraOff?void 0:e.camera,i=t?e.self?Q(`youAreSharing`):Q(`sharing`,{name:e.name}):e.self?`${e.name} (${Q(`you`)})`:e.name;return(0,q.jsxs)(`figure`,{"data-member":e.member,"data-speaking":e.speaking?`true`:void 0,"aria-label":i,className:U(`relative flex min-h-0 min-w-0 items-center justify-center overflow-hidden rounded-lg bg-neutral-900 ring-offset-2 ring-offset-background`,e.speaking&&!t&&`ring-2 ring-success`,n),children:[r?(0,q.jsx)(gK,{track:r,className:U(`size-full`,t?`object-contain`:`object-cover`,e.self&&!t&&`-scale-x-100`)}):(0,q.jsx)(v_,{initials:Ob(e.name),hue:Db(e.member),size:`md`,className:`size-16 text-xl ring-0`}),e.connection===`failed`&&!e.self&&(0,q.jsx)(`p`,{role:`status`,className:`absolute inset-x-1 top-1 truncate rounded bg-black/70 px-2 py-1 text-center text-xs text-white`,children:Q(`cannotConnect`,{name:e.name})}),(0,q.jsxs)(`figcaption`,{className:`absolute bottom-1.5 left-1.5 flex max-w-[calc(100%-0.75rem)] items-center gap-1 rounded bg-black/60 px-1.5 py-0.5 text-xs text-white`,children:[!t&&e.microphoneOff&&(0,q.jsx)(fu,{role:`img`,"aria-label":Q(`muted`),className:`size-3 shrink-0`}),!t&&e.connection===`poor`&&(0,q.jsx)(pf,{role:`img`,"aria-label":Q(`poorConnection`),className:`size-3 shrink-0 text-warning`}),(0,q.jsx)(`span`,{className:`truncate`,children:i})]})]})},RK=()=>{let[e,t]=(0,W.useState)(0);return{ref:(0,W.useCallback)(e=>{if(!e)return;t(e.clientWidth);let n=new ResizeObserver(([e])=>t(e.contentRect.width));return n.observe(e),()=>n.disconnect()},[]),width:e}},zK=4,BK=({people:e,columns:t})=>(0,q.jsx)(`div`,{className:`grid size-full min-h-0 gap-2`,style:{gridTemplateColumns:`repeat(${t}, minmax(0, 1fr))`,gridTemplateRows:`repeat(${Math.ceil(e.length/t)}, minmax(0, 1fr))`},children:e.map(e=>(0,q.jsx)(LK,{person:e},e.member))}),VK=({people:e,sharer:t,narrow:n})=>{let r=e.slice(0,zK),i=e.length-r.length;return(0,q.jsxs)(`div`,{className:U(`flex size-full min-h-0 gap-2`,n?`flex-col`:`flex-row`),children:[(0,q.jsx)(LK,{person:t,screen:!0,className:`min-h-0 flex-1`}),(0,q.jsxs)(`div`,{className:U(`flex shrink-0 gap-2`,n?`h-20 flex-row`:`w-40 flex-col`),children:[r.map(e=>(0,q.jsx)(LK,{person:e,className:n?`aspect-video h-full`:`aspect-video w-full`},e.member)),i>0&&(0,q.jsxs)(`p`,{className:`flex items-center justify-center rounded-lg bg-muted px-2 text-xs text-muted-foreground`,children:[`+`,i]})]})]})},HK=({layout:e,people:t,narrow:n})=>e.kind===`share`?(0,q.jsx)(VK,{people:t,sharer:t.find(t=>t.member===e.sharer),narrow:n}):e.kind===`grid`?(0,q.jsx)(BK,{people:t,columns:e.columns}):(0,q.jsxs)(`div`,{className:`relative size-full min-h-0`,children:[(0,q.jsx)(LK,{person:t[0],className:`size-full`}),(0,q.jsx)(`p`,{className:`absolute inset-x-0 top-3 text-center text-sm text-white drop-shadow`,children:Q(`alone`)})]}),UK=({people:e,state:t,notices:n=[],controls:r,aside:i,children:a,className:o})=>{let{ref:s,width:c}=RK(),l=c>0&&c<640,u=kK({people:e.length,sharers:e.filter(e=>e.screen).map(e=>e.member),width:c}),d=[...t===`resuming`?[Q(`reconnecting`)]:[],...n];return(0,q.jsxs)(`section`,{ref:s,"aria-label":Q(`joinCall`),"data-layout":u.kind,className:U(`flex size-full min-h-0 flex-col gap-2 bg-background p-2`,o),children:[d.length>0&&(0,q.jsx)(`div`,{role:`status`,className:`flex shrink-0 flex-col gap-1`,children:d.map(e=>(0,q.jsxs)(`p`,{className:`flex items-center gap-2 rounded-md bg-warning-soft px-3 py-1.5 text-xs text-foreground`,children:[e===Q(`reconnecting`)&&(0,q.jsx)(wn,{className:`size-3`}),e]},e))}),i,(0,q.jsx)(`div`,{className:`min-h-0 flex-1`,children:t===`joining`?(0,q.jsxs)(`p`,{role:`status`,className:`flex size-full items-center justify-center gap-2 text-muted-foreground`,children:[(0,q.jsx)(wn,{className:`size-4`}),Q(`connecting`)]}):(0,q.jsx)(HK,{layout:u,people:e,narrow:l})}),(0,q.jsx)(IK,{...r}),e.filter(e=>!e.self).flatMap(e=>[[`microphone`,e.microphone],[`screen-audio`,e.screenAudio]].map(([t,n])=>n&&{key:`${e.member} ${t}`,track:n})).filter(e=>e!==void 0).map(({key:e,track:t})=>(0,q.jsx)(_K,{track:t},e)),a]})},WK=({leave:e})=>(0,q.jsxs)(`section`,{role:`status`,className:`flex size-full min-h-0 flex-col items-center justify-center gap-3 bg-background p-4 text-center`,children:[(0,q.jsxs)(`p`,{className:`flex items-center gap-2 text-sm text-foreground`,children:[(0,q.jsx)(wn,{className:`size-4`}),Q(`waiting`)]}),(0,q.jsx)(Jn,{to:e,className:`px-2 text-sm text-muted-foreground hover:text-foreground`,children:Q(`leave`)})]}),GK=`/-/call-guest`,KK=(e,t)=>`${e}${GK}#${t}`,qK=(e,t)=>{let n=t.replace(/^#/,``);return e===`/-/call-guest`&&n?{token:n}:void 0},JK=()=>{let{path:e}=le();return(0,W.useMemo)(()=>qK(e,globalThis.location?.hash??``),[e])},YK=200,XK=1e3,ZK=(e,t)=>{e.getFloatTimeDomainData(t);let n=0;for(let e of t)n+=e*e;return Math.min(1,Math.sqrt(n/t.length)*4)},QK=e=>{let[t,n]=(0,W.useState)(),r=[...e].map(([e,t])=>`${e}:${t.id}`).join(`,`);return(0,W.useEffect)(()=>{if(e.size===0||typeof AudioContext>`u`)return;let t=new AudioContext,r=new Map([...e].map(([e,n])=>{let r=t.createAnalyser();return r.fftSize=512,t.createMediaStreamSource(new MediaStream([n])).connect(r),[e,r]})),i=new Float32Array(512),a,o=setInterval(()=>{let e=MK(new Map([...r].map(([e,t])=>[e,ZK(t,i)])));e&&(a={member:e,at:Date.now()}),n(a&&Date.now()-a.at<XK?a.member:void 0)},YK);return()=>{clearInterval(o),t.close()}},[r]),t},$K=new Set([`NotAllowedError`,`SecurityError`]),eq=new Set([`NotFoundError`,`NotReadableError`,`OverconstrainedError`]),tq=async(e,t)=>{try{return{track:(await e.getUserMedia({[t]:!0})).getTracks()[0],blocked:!1}}catch(e){if(!(e instanceof DOMException))throw e;if($K.has(e.name))return{blocked:!0};if(eq.has(e.name))return{blocked:!1};throw e}},nq=async(e=navigator.mediaDevices)=>{try{let t=await e.getUserMedia({audio:!0,video:!0});return{microphone:t.getAudioTracks()[0],camera:t.getVideoTracks()[0],blocked:{microphone:!1,camera:!1},none:!1}}catch(e){if(!(e instanceof DOMException)||!($K.has(e.name)||eq.has(e.name)))throw e}let[t,n]=[await tq(e,`audio`),await tq(e,`video`)];return{...t.track&&{microphone:t.track},...n.track&&{camera:n.track},blocked:{microphone:t.blocked,camera:n.blocked},none:!t.track&&!n.track&&!t.blocked&&!n.blocked}},rq=class extends Error{reason;constructor(e){super(`Not let into the call: ${e}`),this.reason=e,this.name=`NotLetIn`}},iq=1e3,aq=(e,t)=>new Promise(n=>{let r=setTimeout(n,e);t.addEventListener(`abort`,()=>(clearTimeout(r),n()),{once:!0})}),oq=async(e,t,n,r)=>{let{LobbyRefused:i}=await Ht(async()=>{let{LobbyRefused:e}=await import(`./calls-BQqt6R-b.js`);return{LobbyRefused:e}},__vite__mapDeps([54,7])),a=e=>e instanceof i?new rq(e.status===404?`refused`:e.status===429?`unavailable`:`ended`):e,{token:o}=await e.enter(t,n).catch(e=>Promise.reject(a(e)));for(;!r.aborted;){let t=await e.wait(o).catch(e=>Promise.reject(a(e)));if(t.state===`admitted`)return o;if(t.state===`denied`)throw new rq(`denied`);if(t.state===`ended`)throw new rq(`ended`);await aq(iq,r)}throw await e.leave(o),new rq(`ended`)},sq=2e3,cq=e=>{for(let t of e)t?.stop()},lq=(e,{admission:t}={})=>{let[n,r]=(0,W.useState)({kind:`check`}),[i,a]=(0,W.useState)(),o=(0,W.useRef)(new AbortController),[s,c]=(0,W.useState)(),[l,u]=(0,W.useState)(!0),[d,f]=(0,W.useState)(!0),[p,m]=(0,W.useState)([]),[h,g]=(0,W.useState)([]),[_,v]=(0,W.useState)([]),[y,b]=(0,W.useState)(),[x,S]=(0,W.useState)(!1),C=(0,W.useRef)(void 0),w=(0,W.useRef)(!1),T=(0,W.useRef)([]),E=(0,W.useRef)(new Map),D=(0,W.useRef)(Promise.resolve(void 0));(0,W.useEffect)(()=>{let e=!1;return w.current=!1,D.current=nq().then(t=>{if(e){cq([t.microphone,t.camera]);return}return T.current.push(t.microphone,t.camera),c(t),t}),()=>{e=!0,w.current=!0,o.current.abort(),C.current?.leave(),C.current=void 0,cq(T.current),T.current=[]}},[]),(0,W.useEffect)(()=>{for(let{member:e}of h)E.current.has(e)||E.current.set(e,Date.now())},[h]),(0,W.useEffect)(()=>{if(n.kind!==`in`)return;let e=setInterval(()=>void C.current?.connections().then(v),sq);return()=>clearInterval(e)},[n.kind]);let O=async()=>{if(!t)return{};r({kind:`waiting`}),o.current=new AbortController;let e=await t(o.current.signal).then(e=>e,e=>{if(!(e instanceof rq))throw e;r({kind:`left`,reason:e.reason})});return e===void 0?void 0:{guest:e}},k=(0,W.useCallback)(async()=>{let t=await O();if(!t||w.current)return;r({kind:`joining`});let{joinCall:n,PublishRefused:i}=await Ht(async()=>{let{joinCall:e,PublishRefused:t}=await import(`./calls-BQqt6R-b.js`);return{joinCall:e,PublishRefused:t}},__vite__mapDeps([54,7])),o=await n({url:e,...t,onLobby:a,onTracks:m,onMembers:g,onState:e=>{(e.state===`joined`||e.state===`resuming`)&&r({kind:`in`,resuming:e.state===`resuming`}),e.state===`left`&&r({kind:`left`,reason:e.reason})}}).then(e=>e,()=>void 0);if(!o)return;if(w.current)return o.leave();C.current=o;let s=await D.current,c={...s?.microphone&&{microphone:s.microphone},...s?.camera&&{camera:s.camera}};await o.publish(c).then(()=>{c.microphone&&o.mute(`microphone`,!l),c.camera&&o.mute(`camera`,!d)},e=>{if(!(e instanceof i))throw e;S(!0)})},[e,t,l,d]),ee=(0,W.useCallback)(()=>{let e=!l;u(e),s?.microphone&&(s.microphone.enabled=e),C.current?.mute(`microphone`,!e)},[l,s]),A=(0,W.useCallback)(()=>{let e=!d;f(e),s?.camera&&(s.camera.enabled=e),C.current?.mute(`camera`,!e)},[d,s]),te=(0,W.useCallback)(async e=>{b(void 0),cq([e.video,e.audio]),await C.current?.unpublish(`screen`),e.audio&&await C.current?.unpublish(`screen-audio`)},[]),ne=(0,W.useCallback)(async()=>{if(y)return te(y);let e;try{e=await navigator.mediaDevices.getDisplayMedia({video:!0,audio:!0})}catch(e){if(e instanceof DOMException&&e.name===`NotAllowedError`)return;throw e}let t={video:e.getVideoTracks()[0],...e.getAudioTracks()[0]&&{audio:e.getAudioTracks()[0]}};T.current.push(t.video,t.audio),t.video.addEventListener(`ended`,()=>void te(t)),await C.current?.publish({screen:t.video,...t.audio&&{"screen-audio":t.audio}}),b(t)},[y,te]),re=typeof navigator<`u`&&typeof navigator.mediaDevices?.getDisplayMedia==`function`;return{phase:n,devices:s,microphoneOn:l,cameraOn:d,tracks:p,members:h,connections:_,screen:y,refusedSending:x,seen:E.current,self:C.current?.participant,lobby:i,guests:C.current?.guests,join:k,toggleMicrophone:ee,toggleCamera:A,...re&&{toggleScreen:ne}}},uq=(e,t)=>[...e?.blocked.microphone?[Q(`noMicrophone`)]:[],...e?.blocked.camera?[Q(`noCamera`)]:[],...e?.none?[Q(`noDevices`)]:[],...t?[Q(`refused`)]:[]],dq=({url:e,leave:t,nameOf:n=e=>e,admission:r,name:i,className:a})=>{let o=lq(e,{...r&&{admission:r}}),[s,c]=(0,W.useState)(!1),{basePath:l}=le(),u=Ig(),d=u?.state.kind===`signed-in`?u.state.user:void 0,f=o.self??d?.id??``,[p]=(0,W.useState)(()=>Date.now()),{devices:m,phase:h}=o,g={...m?.microphone&&{microphone:m.microphone},...m?.camera&&{camera:m.camera},...o.screen&&{screen:o.screen.video},microphoneOn:o.microphoneOn,cameraOn:o.cameraOn},_=new Map([...m?.microphone&&o.microphoneOn?[[f,m.microphone]]:[],...o.tracks.filter(e=>e.source===`microphone`&&e.track&&!e.muted).map(e=>[e.member,e.track])]),v=QK(h.kind===`in`?_:new Map),y=uq(m,o.refusedSending);if(h.kind===`left`)return(0,q.jsx)(DK,{reason:h.reason,onJoinAgain:()=>void o.join()});if(h.kind===`waiting`)return(0,q.jsx)(WK,{leave:t});if(h.kind===`check`)return(0,q.jsx)(yK,{name:i??d?.name??Q(`you`),...r&&{joinLabel:Q(`askToJoin`)},member:f,...m?.camera&&{camera:m.camera},microphoneOn:o.microphoneOn,cameraOn:o.cameraOn,microphone:!!m?.microphone,cameraAvailable:!!m?.camera,notices:y,onMicrophone:o.toggleMicrophone,onCamera:o.toggleCamera,onJoin:()=>void o.join(),cancel:t});let{lobby:b,guests:x}=o,S=o.members.filter(e=>e.member.startsWith(`guest:`)).map(e=>({guest:e.member.slice(6),name:e.name??``})),C=PK({members:o.members,self:f,tracks:o.tracks,own:g,nameOf:n,...v&&{speaker:v},connections:o.connections,seen:o.seen,now:Math.max(p,Date.now())});return(0,q.jsx)(UK,{...a&&{className:a},people:C,state:h.kind===`joining`?`joining`:h.resuming?`resuming`:`joined`,notices:y,...b&&x&&{aside:(0,q.jsx)(TK,{waiting:b.guests,guests:x})},controls:{microphoneOn:o.microphoneOn&&!!m?.microphone,cameraOn:o.cameraOn&&!!m?.camera,sharing:!!o.screen,onMicrophone:o.toggleMicrophone,onCamera:o.toggleCamera,...o.toggleScreen&&{onShare:()=>void o.toggleScreen()},...b&&{guests:{waiting:b.guests.length,onOpen:()=>c(!0)}},leave:t},children:b&&x&&(0,q.jsx)(wK,{lobby:b,inCall:S,guests:x,linkOf:e=>KK(`${window.location.origin}${l}`,e),open:s,onClose:()=>c(!1)})})},fq=({link:e,systemPath:t,base:n})=>{let[r,i]=(0,W.useState)(``),[a,o]=(0,W.useState)(),[s,c]=(0,W.useState)(!1),l=(0,W.useCallback)(async n=>{let{guestLobby:r}=await Ht(async()=>{let{guestLobby:e}=await import(`./calls-BQqt6R-b.js`);return{guestLobby:e}},__vite__mapDeps([54,7]));return oq(r({systemPath:t}),e,a,n)},[t,e,a]),u=e=>{e.preventDefault(),r.trim()&&o(r.trim())},d=KK(n,e);return s?(0,q.jsx)(`p`,{role:`status`,className:`flex min-h-[100dvh] items-center justify-center bg-background p-4 text-sm text-foreground`,children:Q(`youLeft`)}):a===void 0?(0,q.jsx)(`main`,{className:`flex min-h-[100dvh] items-center justify-center bg-background p-4`,children:(0,q.jsxs)(`form`,{onSubmit:u,className:`flex w-full max-w-sm flex-col gap-3`,children:[(0,q.jsx)(`p`,{className:`text-sm text-foreground`,children:Q(`guestIntro`)}),(0,q.jsxs)(`label`,{className:`flex flex-col gap-1 text-sm text-foreground`,children:[Q(`yourName`),(0,q.jsx)(bi,{autoFocus:!0,autoComplete:`name`,maxLength:60,value:r,onChange:e=>i(e.target.value)})]}),(0,q.jsx)(P,{type:`submit`,variant:`primary`,disabled:!r.trim(),children:Q(`continue`)})]})}):(0,q.jsx)(`main`,{className:`h-[100dvh]`,children:(0,q.jsx)(dq,{url:pi(t,`socket`),admission:l,name:a,nameOf:()=>Q(`someone`),leave:{href:d,onFollow:()=>c(!0)}})})},pq=e=>{let[t,n]=(0,W.useState)();return(0,W.useEffect)(()=>{let t=window.visualViewport;if(!e||!t)return n(void 0);let r=()=>n({top:t.offsetTop,height:t.height});return r(),t.addEventListener(`resize`,r),t.addEventListener(`scroll`,r),()=>{t.removeEventListener(`resize`,r),t.removeEventListener(`scroll`,r)}},[e]),e?t:void 0},mq=B(`side-panel`),hq=({title:e,icon:t,status:n,onClose:r,footer:i,children:a})=>{let o=pq(!h());return(0,q.jsxs)(`aside`,{"aria-label":e,className:`flex h-full w-[380px] max-w-full shrink-0 flex-col border-l border-border bg-surface max-md:fixed max-md:inset-0 max-md:z-40 max-md:w-full max-md:border-l-0`,style:o&&{top:o.top,bottom:`auto`,height:o.height},children:[(0,q.jsxs)(`header`,{className:`flex h-12 shrink-0 items-center gap-2 border-b border-border bg-background px-4`,children:[t,(0,q.jsx)(`h2`,{className:`flex-1 font-semibold`,children:e}),n&&(0,q.jsx)(`span`,{className:`truncate text-xs font-medium text-muted-foreground`,children:n}),r&&(0,q.jsx)(P,{variant:`ghost`,size:`sm`,className:`w-7 px-0`,"aria-label":mq(`close`),onClick:r,children:(0,q.jsx)(Ci,{className:`size-4`})})]}),a,i&&(0,q.jsx)(`footer`,{className:`shrink-0 space-y-2 border-t border-border bg-background p-3`,children:i})]})},gq=({fields:e})=>(0,q.jsx)(`dl`,{className:`grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-1 text-body`,children:e.map((e,t)=>(0,q.jsxs)(`div`,{className:`contents`,children:[(0,q.jsx)(`dt`,{className:`text-muted-foreground`,children:e.label}),(0,q.jsx)(`dd`,{className:`min-w-0 break-words`,children:e.value})]},`${t}-${e.label}`))}),_q=e=>e==null?`null`:typeof e==`object`?JSON.stringify(e):String(e),vq=B(`compact-table`),yq=({columns:e,rows:t,caption:n,truncated:r,className:i})=>(0,q.jsxs)(`section`,{"aria-label":n??vq(`table`),className:U(`shrink-0 overflow-hidden rounded-lg border border-border-strong bg-background shadow-sm`,i),children:[n&&(0,q.jsx)(`code`,{className:`block whitespace-pre-wrap break-words bg-surface px-3 py-2 font-mono text-[0.6875rem] text-foreground`,children:n}),t.length===0?(0,q.jsx)(`p`,{className:`px-3 py-2 text-xs text-muted-foreground`,children:vq(`noRows`)}):(0,q.jsx)(`div`,{className:`max-h-64 overflow-auto`,children:(0,q.jsxs)(`table`,{className:`w-full border-collapse text-left text-[0.6875rem]`,children:[(0,q.jsx)(`thead`,{className:`sticky top-0 bg-background`,children:(0,q.jsx)(`tr`,{children:e.map(e=>(0,q.jsx)(`th`,{scope:`col`,className:`border-b border-border px-2 py-1 font-semibold whitespace-nowrap`,children:e},e))})}),(0,q.jsx)(`tbody`,{children:t.map((e,t)=>(0,q.jsx)(`tr`,{className:`border-b border-border last:border-b-0`,children:e.map((e,t)=>(0,q.jsx)(`td`,{className:U(`px-2 py-1 whitespace-nowrap`,e===null&&`text-faint-foreground`),children:_q(e)},t))},t))})]})}),(0,q.jsxs)(`footer`,{className:`border-t border-border px-3 py-1.5 text-[0.6875rem] text-muted-foreground`,children:[vq(`rows`,{count:t.length}),r&&vq(`cutOff`)]})]}),bq={pending:(0,q.jsx)(Rc,{className:`size-3 text-faint-foreground`}),running:(0,q.jsx)(wn,{className:`size-3.5 text-primary`}),done:(0,q.jsx)(xi,{className:`size-3.5 text-success`,strokeWidth:2.5}),failed:(0,q.jsx)(Ci,{className:`size-3.5 text-danger`,strokeWidth:2.5})},xq={pending:`text-muted-foreground`,running:`text-foreground`,done:`text-muted-foreground`,failed:`text-danger-text`},Sq=({steps:e,className:t})=>(0,q.jsx)(`ul`,{className:U(`shrink-0 space-y-2`,t),children:e.map((e,t)=>(0,q.jsxs)(`li`,{className:`flex items-start gap-2.5`,"data-state":e.state,children:[(0,q.jsx)(`span`,{className:`mt-0.5 flex size-4 shrink-0 items-center justify-center`,children:bq[e.state]}),(0,q.jsx)(`span`,{className:xq[e.state],children:e.label})]},`${t}-${e.label}`))}),Cq=B(`assistant-dock`),wq=({part:e,note:t})=>e.fallback?(0,q.jsx)(JC,{title:e.fallback.title,note:t,children:e.fallback.body&&(0,q.jsx)(`p`,{children:e.fallback.body})}):(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`${e.name}: ${t}`}),Tq=class extends W.Component{state={failed:!1};static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(e,t){Bh(e,t.componentStack)}render(){return this.state.failed?(0,q.jsx)(wq,{part:this.props.part,note:Cq(`couldNotDraw`)}):this.props.children}},Eq=({part:e})=>{let{components:t={}}=qy(),n=Object.hasOwn(t,e.name)?t[e.name]:void 0;return n?(0,q.jsx)(Tq,{part:e,children:(0,q.jsx)(n,{...e.props})}):(0,q.jsx)(wq,{part:e,note:Cq(`cannotShowLive`)})},Dq=({part:e,onAction:t})=>{switch(e.type){case`text`:return(0,q.jsx)(`p`,{children:e.text});case`table`:return(0,q.jsx)(yq,{columns:e.columns,rows:e.rows,caption:e.caption,truncated:e.truncated});case`card`:return(0,q.jsxs)(JC,{title:e.title,tone:e.tone,badge:e.badge,note:e.note,actions:e.actions,onAction:n=>t?.(e.id,n),children:[e.body&&(0,q.jsx)(`p`,{children:e.body}),e.code&&(0,q.jsx)(`pre`,{className:`overflow-x-auto rounded-md bg-surface px-2.5 py-2 font-mono text-[0.6875rem] whitespace-pre-wrap break-words`,children:e.code}),e.fields&&e.fields.length>0&&(0,q.jsx)(gq,{fields:e.fields}),e.steps&&e.steps.length>0&&(0,q.jsx)(Sq,{steps:e.steps}),e.diffs?.map((e,t)=>(0,q.jsx)(dk,{source:e.source,start:e.start,path:e.path,className:`rounded-md border border-border`},`${t}-${e.path}`))]});case`widget`:return(0,q.jsx)(Eq,{part:e})}},Oq=(0,W.createContext)(void 0),kq=e=>e instanceof Error?e:Error(Cq(`backendNoAnswer`)),Aq=(e,t)=>typeof e==`function`?e(t):e,jq=(e,{refreshMs:t=!1}={})=>{let n=(0,W.useContext)(Oq),[r,i]=(0,W.useState)({}),[a,o]=(0,W.useState)(0),s=(0,W.useRef)(t);s.current=t;let c=(0,W.useRef)(void 0);return(0,W.useEffect)(()=>{if(!n){i({error:Error(`useBackendData works only in a widget the assistant dock draws`)});return}let t=!0,r,a=async()=>{let o=await n.fetch(e).then(e=>e.json()).then(e=>({data:e}),e=>({data:c.current,error:kq(e)}));if(!t)return;c.current=o.data,i(o);let l=Aq(s.current,o.data);l!==!1&&(r=setTimeout(a,l))};return a(),()=>{t=!1,clearTimeout(r)}},[n,e,a]),{...r,reload:()=>o(e=>e+1),post:async(e,t)=>{if(!n)throw Error(`useBackendData works only in a widget the assistant dock draws`);let r={method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(t??{})},a=await n.fetch(e,r).then(e=>e.json()).then(e=>({data:e}),e=>({data:c.current,error:kq(e)}));c.current=a.data,i(a)}}},Mq=({state:e,offline:t,error:n,onSend:r,onAction:i,onClose:a,client:o})=>{let s=(0,W.useRef)(null);return(0,W.useEffect)(()=>{e.placeholder&&s.current?.focus()},[e.placeholder]),(0,q.jsx)(hq,{title:Cq(`assistant`),icon:(0,q.jsx)(wd,{className:`size-4 text-primary`}),status:t?Cq(`reconnecting`):e.status,onClose:a,footer:(0,q.jsxs)(q.Fragment,{children:[n&&(0,q.jsx)(`p`,{role:`alert`,className:`text-body text-danger-text`,children:n}),(0,q.jsx)(YO,{inputRef:s,onSend:r,busy:e.replying,placeholder:e.placeholder??Cq(`askQuestion`)})]}),children:(0,q.jsx)(Oq.Provider,{value:o,children:(0,q.jsx)(AO,{length:e.messages.reduce((e,t)=>e+t.parts.length,0),empty:Cq(`empty`),children:e.messages.map(e=>(0,q.jsx)(CO,{from:e.from,children:e.parts.map(e=>(0,q.jsx)(Dq,{part:e,onAction:i},e.id))},e.id))})})})},Nq=e=>e instanceof Error?e.message:Cq(`noAnswer`),Pq=e=>{let[t,n]=(0,W.useState)(Bo),[r,i]=(0,W.useState)(!1),[a,o]=(0,W.useState)();(0,W.useEffect)(()=>{if(e)return e.connect(e=>n(t=>Uo(t,e)),e=>i(e.state===`retrying`))},[e]);let s=e=>{o(void 0),e.catch(e=>o(Nq(e)))};return{state:t,offline:r,error:a,send:(t,n)=>e&&s(e.send(t,n)),act:(t,n)=>e&&s(e.act(t,n))}},Fq=e=>{let t=iK(),n=(0,W.useRef)(t);n.current=t;let r=t!==void 0;return(0,W.useMemo)(()=>r?Eh({url:e,token:()=>n.current}):void 0,[e,r])},Iq=({open:e,onToggle:t})=>(0,q.jsxs)(P,{size:`sm`,variant:e?`primary`:`secondary`,"aria-pressed":e,onClick:t,className:`max-md:size-9 max-md:p-0`,children:[(0,q.jsx)(wd,{className:`size-3.5`}),(0,q.jsx)(`span`,{className:`max-md:sr-only`,children:R(`assistant`)})]}),Lq=({client:e,page:t,onClose:n})=>{let{state:r,offline:i,error:a,send:o,act:s}=Pq(e);return(0,q.jsx)(Mq,{state:r,offline:i,error:a,onSend:e=>o(e,t),onAction:s,onClose:n,client:e})},Rq=({url:e,...t})=>(0,q.jsx)(Lq,{client:Fq(e),...t}),zq=({url:e,client:t,...n})=>t?(0,q.jsx)(Lq,{client:t,...n}):(0,q.jsx)(Rq,{url:e,...n}),Bq={bell:nc,"book-open":ic,bookmark:uc,building:mc,"credit-card":Jc,"external-link":ol,"file-text":vl,globe:el,heart:wl,key:Ml,"layout-dashboard":Bl,"life-buoy":Wl,mail:iu,package:Eu,receipt:Ju,settings:fd,shield:md,"shopping-cart":vd,tags:Bd,users:nf,warehouse:df};Object.keys(Bq);var Vq=(e,t)=>e?Bq[e]??t:t,Hq=(e,t)=>Vq(e.views[t]?.icon??e.signIn?.[t]?.icon,Pd),Uq=(e,t,n)=>(e.bottomBar?.items??[]).map((r,i)=>r.kind===`link`?{id:`link-${i}`,label:r.label,icon:Vq(r.icon,ol),href:r.href,external:!0}:r.kind===`page`?{id:r.page,label:r.label,icon:Vq(r.icon??e.pages[r.page]?.icon,Bl),href:We({kind:`page`,page:r.page},t),active:r.page===n}:{id:r.resource,label:r.label,icon:Vq(r.icon,Hq(e,r.resource)),href:We({kind:`list`,resource:r.resource},t),active:r.resource===n}),Wq=({basePath:e,address:t,group:n,page:r,resourceLabel:i,headingless:a,recordTitle:o,recordLoading:s})=>{let c=n&&n!==i?[n]:[];if(r)return[...c,{label:r.title,href:We({kind:`page`,page:r.name},e)}];if(!t||t.kind===`page`)return[R(`admin`)];let l=We({kind:`list`,resource:t.resource,...t.kind===`list`&&t.list&&{list:t.list}},e),u=t.kind===`record`&&!a,d=i?[{label:i,href:l,...u&&{above:!0}}]:[];if(t.kind===`list`||u)return[...c,...d];let f=We(t,e),p=t.kind===`create`?{label:R(`new`),href:f}:o===void 0&&s?{label:R(`loadingRecord`),href:f,loading:!0}:{label:o??t.key,href:f};return[...c,...d,p]},Gq=2e3,Kq={type:`active`,predicate:e=>e.state.data===void 0},qq=({children:e})=>{let t=nn(),n=pt(Kq),[r,i]=(0,W.useState)(!1);return(0,W.useEffect)(()=>{if(r)return;let e=setTimeout(()=>i(!0),Gq);return()=>clearTimeout(e)},[r]),(0,W.useEffect)(()=>{if(r||n>0)return;let e=setTimeout(()=>t.isFetching(Kq)===0&&i(!0),0);return()=>clearTimeout(e)},[r,n,t]),(0,q.jsxs)(`div`,{className:`relative flex min-h-0 flex-1 flex-col`,"aria-busy":!r||void 0,children:[(0,q.jsx)(`div`,{className:U(`flex min-h-0 flex-1 flex-col`,!r&&`invisible`),children:e}),!r&&(0,q.jsx)(Jq,{})]})},Jq=()=>(0,q.jsxs)(`div`,{role:`status`,"aria-label":R(`loading`),className:`absolute inset-x-0 top-0 flex flex-col gap-4 p-4 md:p-6`,children:[(0,q.jsx)(L,{className:`h-6 w-48`}),(0,q.jsx)(L,{className:`h-24`}),(0,q.jsx)(L,{className:`h-40`}),(0,q.jsx)(L,{className:`h-40`})]}),Yq=e=>({queryKey:e.queryKey,start:t=>t.prefetchQuery(e)}),Xq=e=>({queryKey:e.queryKey,start:t=>t.prefetchInfiniteQuery(e)}),Zq={Table:(e,t,n)=>{let{resource:r,filter:i=``,sort:a=``,columns:o,button:s,bulk:c=!1,limit:l=10,select:u}=xT(e),d=r===void 0?void 0:n.resources[r];if(!d)return[];if(t.part===`chosen`){let e=u===void 0?void 0:n.given[u];return e?[Yq(Xr(n.client,d,{key:e}))]:[]}let f=n.views[d.name],{fields:p,read:m}=tE({...n,model:d,view:f,columns:o?.map(fm),button:s,bulk:c,phoneColumns:nE(o)});return[Yq(yB(n,{model:d,filter:i,orderBy:a||Pe(d,f),limit:l,fields:p,read:m}))]},Chart:(e,t,{client:n,resources:r,views:i})=>{let{resource:a,groupBy:o,splitBy:s,sum:c,average:l,filter:u,granularity:d,range:f,limit:p}=xT(e),m=r[a],h=m&&LE({model:m,groupBy:o,splitBy:s,sum:c,average:l,filter:u,granularity:d,range:f,limit:p},r,i);return m&&h?[Yq(CE(n,m.name,h))]:[]},RecordCards:(e,t,{client:n,resources:r,views:i})=>{let{resource:a,filter:o=``,sort:s=``,limit:c=10}=xT(e),l=r[a];if(!l)return[];let u=s||Pe(l,i[l.name]);return[Yq(Gr(n,l,{filter:o,sort:u,pageSize:c})),Yq(ti(n,l,o))]},RecordRow:(e,t,{client:n,queryClient:r,resources:i,views:a})=>{let{resource:o,filter:s=``,sort:c=``}=xT(e),l=i[o];if(!l)return[];let u=a[l.name];return u?.searchesOf||u?.listOf!==void 0?[]:[Yq(pP({queryClient:r,client:n,resources:i,views:a,model:l,...qI(l,u,{filter:s,sort:c})}))]},Thread:(e,t,{client:n,resources:r,views:i})=>{let{resource:a,filter:o,sender:s,time:c,calls:l,limit:u=50}=xT(e);if(t.part===`calls`){let e=l&&r[l.resource];return e?[Xq(ex(n,e.name,{filter:l.filter,orderBy:Ip(l.time),pageSize:u}))]:[]}let d=r[a];if(!d)return[];let f=ab(r,i,d,s===void 0?[]:[s]);return[Xq(ex(n,d.name,{filter:o,orderBy:Ip(c),pageSize:u,labels:f}))]}},Qq=(e,t,{client:n,resources:r})=>{let i=r[t.resource];return i?[Yq(ti(n,i))]:[]},$q=(e,t,n)=>(n?.reads??[]).flatMap(n=>{let r=Mm(t,n.block);if(!r||r.custom)return[];if(n.part===`condition`)return Qq(r,n,e);if(n.split)return[];let i=Zq[r.type];return i?i(Um(r,{stack:[],params:e.params,...e.root&&{root:e.root}}),n,e):[]}),eJ=({tree:e,plan:t})=>{let n=F(),r=nn(),{resources:i,views:a}=c(),o=qy().fields,s=v(),l=jT(),u=MT(),d=nT(tT()),f=(0,W.useMemo)(()=>$q({client:n,queryClient:r,resources:i,views:a,fieldTypes:o,xs:s,params:l,given:u,...d&&{root:d}},e,t),[n,r,i,a,o,s,l,u,d,e,t]);return(0,W.useEffect)(()=>{for(let e of f)e.start(r)},[f,r]),null},tJ=({name:e,tab:t,params:n})=>{let r=c().pages[e];if(!r)return(0,q.jsx)(tt,{title:z(`notFound`),children:z.rich(`noPage`,{page:e})});let i=t=>We(kT({page:e,...t&&{tab:t},given:n??{}}));return(0,q.jsx)($g,{route:{...t&&{tab:t},pathOf:i},children:(0,q.jsx)(AT,{page:e,...t&&{tab:t},tree:r.tree,...n&&{given:n},children:(0,q.jsxs)(fE,{tree:r.tree,plan:r.reads,children:[(0,q.jsx)(eJ,{tree:r.tree,plan:r.reads}),(0,q.jsx)(qq,{children:(0,q.jsx)(PU,{node:r.tree,at:``})})]})})})},nJ=B(`app/record`),rJ=(e,t)=>{let n=Mr(e,t);return n.kind===`record`&&(Array.isArray(n.key)?n.key:[n.key]).some(e=>e===``)?void 0:n},iJ=({to:e})=>{let{go:t}=Me();return(0,W.useEffect)(()=>t(e,{replace:!0}),[e,t]),(0,q.jsx)(tt,{title:nJ(`loading`),children:nJ(`fetching`)})},aJ=({title:e,eyebrow:t,width:n,submit:r,saving:i,disabled:a,error:o,errorTitle:s=hy(`notSaved`),onSubmit:c,onCancel:l,children:u,ref:d})=>{let f=(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[l&&(0,q.jsx)(P,{className:`max-sm:min-h-11`,onClick:l,children:hy(`cancel`)}),(0,q.jsx)(P,{variant:`primary`,type:`submit`,className:`max-sm:min-h-11 max-sm:flex-1`,loading:i,disabled:a,children:r})]}),p=o!==void 0&&(0,q.jsx)(`div`,{className:`mt-4`,children:(0,q.jsx)(Oy,{title:s,error:o})}),m=(0,q.jsx)(`div`,{className:`divide-y divide-border`,children:u}),h=e=>{e.preventDefault(),c()};return e===void 0?(0,q.jsxs)(`form`,{ref:d,className:`max-w-[760px]`,onSubmit:h,children:[p,m,(0,q.jsx)(`footer`,{className:`border-t pt-6 sm:flex sm:justify-end`,children:f})]}):(0,q.jsx)(`form`,{ref:d,className:`flex-1`,onSubmit:h,children:(0,q.jsxs)(`div`,{className:U(n!==`full`&&`mx-auto max-w-[760px]`,`px-4 py-6 md:px-10 md:py-8`),children:[(0,q.jsxs)(`header`,{className:`flex flex-col gap-4 border-b pb-6 sm:flex-row sm:items-end sm:justify-between sm:gap-6`,children:[(0,q.jsxs)(`div`,{children:[t&&(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:t}),(0,q.jsx)(`h1`,{className:`mt-1 text-2xl font-semibold tracking-tight`,children:e})]}),f]}),p,m]})})},oJ=({noun:e,collection:t,sections:n,width:r,saving:i,message:a,onSubmit:o,onCancel:s,ref:c})=>(0,q.jsx)(aJ,{ref:c,title:hy(`title`,{noun:e}),eyebrow:t,width:r,submit:hy(`submit`,{noun:e}),saving:i,error:a?Error(a):void 0,errorTitle:hy(`notCreated`),onSubmit:o,onCancel:s,children:n.map(e=>(0,q.jsx)(D_,{title:e.title,help:e.help,children:(0,q.jsx)(`div`,{className:`grid grid-cols-1 gap-x-6 gap-y-5 sm:grid-cols-2`,children:e.fields.map(e=>(0,q.jsx)(Mv,{name:e.name,label:e.label,required:e.required,help:e.help,error:e.error,wide:e.wide,children:e.editor},e.name))})},e.title))}),sJ=2e3,cJ=Symbol(`nothing saved`),lJ=(e,t)=>{let n=nS(),[r,i]=(0,W.useState)(`idle`),[a,o]=(0,W.useState)(),s=(0,W.useRef)(void 0);return(0,W.useEffect)(()=>()=>clearTimeout(s.current),[]),{phase:r,message:a,run:async r=>{let a=e===`toast`?n.show({state:`loading`,title:nJ(`savingSubject`,{subject:t})}):void 0;o(void 0),e===`button`&&i(`saving`);try{return await r()===cJ?(a!==void 0&&n.dismiss(a),e===`button`&&i(`idle`),!0):(a!==void 0&&n.update(a,{state:`success`,title:nJ(`subjectSaved`,{subject:t})}),e===`button`&&(i(`saved`),s.current=setTimeout(()=>i(`idle`),sJ)),!0)}catch(t){if(!Tn(t))throw t;let r=t.status===412?nJ(`changedBySomeoneElse`):nJ(`couldNotSave`),s=gA(t);return a!==void 0&&n.update(a,{state:`error`,title:r,description:s}),e===`button`&&(i(`idle`),o(`${r}: ${s}`)),!1}}}},uJ=(e,t)=>Object.fromEntries(Object.entries(e).filter(([e])=>e!==t)),dJ=({resource:e,values:t,onCreated:n,feedback:r})=>{let i=c(),a=i.resources[e],o=i.views[e],s=F(),l=nn(),{fields:u}=qy(),d=o?.names?.singular??H(e),f=lJ(r??o?.saveFeedback??`toast`,hy(`subject`,{noun:d})),p=vy(a,o),[m,h]=(0,W.useState)(()=>Ty(a,p,t)),[g,_]=(0,W.useState)({}),[v,y]=(0,W.useState)(0),b=_A(v),[x,S]=(0,W.useState)(!1),C=(0,W.useRef)(!1),[w,T]=(0,W.useState)(!1);(0,W.useEffect)(()=>{for(let[e,n]of Object.entries(t??{})){let t=i.resources[a.fields[e]?.relation?.resource??``];t&&rb(l,s,t,[n],i.views[t.name]).then(t=>{let r=t.get(n);r&&h(t=>gy(t[e])&&t[e].key===n&&t[e].label!==r?{...t,[e]:{key:n,label:r}}:t)})}},[t,i,a,s,l]);let E=(e,t)=>{_(t=>uJ(t,e)),S(!0),h(n=>({...n,[e]:t}))},D=async(e={})=>{if(C.current)return!1;C.current=!0,T(!0);try{return await O(e)}finally{C.current=!1,T(!1)}},O=t=>f.run(async()=>{let r;try{r=await s.create(e,{...by(a,i.resources,m),...t})}catch(t){let r=Tn(t)?t.existing:void 0;if(r)return n(void 0,{kind:`record`,resource:e,key:r.key}),cJ;let i=hA(t);throw _(i),Object.keys(i).length>0&&y(e=>e+1),t}for(let t of[`page`,`list`,`first-page`,`map`,`facets`,`series`,`aggregate`,`count`])l.invalidateQueries({queryKey:[t,e]});n(r.record,{kind:`record`,resource:e,key:xr(a,r.record)})});return{ref:b,sections:p.map(e=>({title:e.title,help:e.help,fields:e.fields.map(e=>{let t=a.fields[e],n=m[e],r=t.relation?i.resources[t.relation.resource]:void 0,s=o?.fields[e]?.label??H(e),c=g[e];return{name:e,label:s,help:o?.fields[e]?.help,required:xy(t),error:c&&mA(t,s,c),wide:NS(u,t,o?.fields[e]),editor:(0,q.jsx)(GC,{field:t,hints:o?.fields[e],value:gy(n)?n.key:n??(t.type!==`boolean`&&``),stored:void 0,relationLabel:gy(n)?n.label:void 0,placeholder:Ey(t)?hy(`setByDatabase`):wy(t),relationPicker:r?{target:r,view:i.views[r.name]}:void 0,invalid:!!g[e],resource:a.name,onChange:t=>E(e,t)})}})})),set:E,submit:D,touched:x,saving:w,message:f.message}},fJ=({resource:e,values:t})=>{let n=c(),r=n.resources[e],i=re(e);return r?iS(i,`create`)?(0,q.jsx)(pJ,{resource:e,values:t}):(0,q.jsx)(tt,{title:hy(`notAllowed`),children:hy(`cannotCreate`,{plural:n.views[e]?.names?.plural.toLowerCase()??e})}):(0,q.jsx)(tt,{title:R(`notFound`),children:R(`noResource`,{name:e})})},pJ=({resource:e,values:t})=>{let n=c().views[e],{go:r}=Me(),[i,a]=(0,W.useState)(),o=dJ({resource:e,values:t,onCreated:(e,t)=>a(t)});we(!i&&(o.touched||o.saving),`input-lost`),(0,W.useEffect)(()=>{i&&r(i,{replace:!0})},[i,r]);let s=n?.names?.singular??H(e);return(0,q.jsx)(oJ,{ref:o.ref,noun:s,collection:n?.names?.plural??H(e),sections:o.sections,width:n?.recordWidth,saving:o.saving,message:o.message,onSubmit:()=>void o.submit(),onCancel:()=>r({kind:`list`,resource:e})})},mJ=({resource:e,values:t})=>{let n=c(),r=n.views[e];return r?.createOpens&&sr(r.createOpens).every(e=>t?.[e])?(0,q.jsx)(iJ,{to:Mr(r.createOpens,t)}):r?.create?n.pages[r.create.page]?(0,q.jsx)(tJ,{name:r.create.page}):(0,q.jsx)(tt,{title:hy(`notAllowed`),children:hy(`cannotCreate`,{plural:r.names?.plural.toLowerCase()??H(e)})}):(0,q.jsx)(fJ,{resource:e,values:t},new URLSearchParams(t).toString())},hJ=(e,t)=>{let n=new Map(t.map(e=>[e.value,e.count]));return e.map(([e,t])=>({value:e,label:t,...n.get(e)!==void 0&&{count:n.get(e)}}))},gJ=(e,t)=>[...new Set(t.filter(t=>!e.includes(t)))],_J=m(),vJ=(e,t,n)=>{let r=F(),[i,a]=(0,W.useState)({}),o=e=>!!e?.search?.length&&e.primaryKey.length===1,s=e=>{let n=t[e.name];return[e.primaryKey[0],...n?.titleFrom?n.titleFrom.fields:[pe(e,n)]]},c=(e,r)=>{let i=t[e.name],a=String(r[e.primaryKey[0]]);return[a,i?.titleFrom?n(e,i,r,a):String(r[pe(e,i)])]},l=wt({queries:e.map(({id:e,target:t})=>{let n=(i[e]??``).trim();return{queryKey:[`reference-search`,e,t?.name??``,n],enabled:o(t)&&n!==``,placeholderData:sn,queryFn:async()=>(await r.list(t.name,{filter:vn(_J.search(n)),fields:s(t),pageSize:20})).items}})});return e.map(({id:e,target:t},n)=>{if(!o(t))return{};let r=t=>a(n=>({...n,[e]:t}));return(i[e]??``).trim()===``?{onSearch:r}:{onSearch:r,matches:(l[n]?.data??[]).map(e=>c(t,e))}})},yJ=24,bJ=({model:e,resources:t,views:n,view:r,state:i,extras:a,titleOf:o})=>{let s=F(),c=nn(),l=EF(r,e),u=e=>r?.fields[e]?.label??H(e),d=n=>{let r=e.fields[n];return r?.type===`relation`&&r.relation?t[r.relation.resource]:void 0},f=e=>!!(e&&n[e.name]?.titleFrom),p=l.facets.flatMap(e=>(e.flags?e.options.map(e=>e.value):[e.id]).map(t=>({group:e.id,field:t}))),m=wt({queries:p.map(({group:t,field:r})=>{let o=pF(l,{...i,facets:{...i.facets,[t]:[]}},a),c=d(r),u=c?.primaryKey.length===1&&!f(c)?pe(c,n[c.name]):void 0;return{queryKey:I.facets(e.name,r,o),queryFn:()=>s.facets(e.name,r,{filter:o,limit:50,...u&&{label:u}})}})}),h=(e,t)=>m[p.findIndex(n=>n.group===e&&n.field===t)]?.data,g=e=>(h(e,e)??[]).flatMap(e=>e.value===null?[]:[String(e.value)]),_=wt({queries:l.facets.map(t=>{let r=d(t.id),a=gJ(g(t.id),i.facets[t.id]??[]);return{queryKey:I.labels(`facet:${e.name}.${t.id}`,a.join(`,`)),enabled:!!r&&!f(r)&&a.length>0,queryFn:async()=>[...await rb(c,s,r,a,n[r.name])]}})}),v=wt({queries:l.facets.map(t=>{let r=d(t.id),a=r&&f(r)?cb(r,n[r.name]):void 0,o=[...new Set([...g(t.id),...i.facets[t.id]??[]])];return{queryKey:I.labels(`facet-title:${e.name}.${t.id}`,o.join(`,`)),enabled:a!==void 0&&o.length>0,queryFn:async()=>[...await ub(s,r,a,o)]}})}),y=(e,t)=>{let r=d(e);return(v[t]?.data??[]).map(([e,t])=>[e,o(r,n[r.name],t,e)])},b=vJ(l.facets.map(e=>({id:e.id,target:e.combobox?d(e.id):void 0})),n,o),x=l.ranges??[],S=wt({queries:x.map(t=>{let n=pF(l,AP(i,t.id,void 0),a),o=DF(r,t.id)?yJ:1;return{queryKey:I.histogram(e.name,t.id,o,n),queryFn:()=>s.histogram(e.name,t.id,{filter:n,buckets:o})}})});return{facets:l.facets.map((t,n)=>{if(t.flags){let e=t.options.map(({value:e})=>({value:e,label:u(e),count:h(t.id,e)?.find(e=>String(e.value)===`true`)?.count??0}));return{...t,options:e}}let i=e.fields[t.id],a=(h(t.id,t.id)??[]).flatMap(e=>e.label===void 0?[]:[[String(e.value),e.label]]),o=i?.type===`enum`?(i.enumValues??[]).map(e=>[e,ar(e,r?.fields[t.id]?.valueLabels)]):[],s=new Map([...o,...a,..._[n]?.data??[],...y(t.id,n)]),c=(h(t.id,t.id)??[]).flatMap(e=>e.value===null?[]:[{value:String(e.value),label:s.get(String(e.value))??String(e.value),count:e.count}]),l=b[n];return{...t,label:u(t.id),options:l.matches?hJ(l.matches,c):c,...s.size>0&&{labels:Object.fromEntries(s)},...l.onSearch&&{onSearch:l.onSearch}}}),ranges:x.flatMap((e,t)=>{let n=S[t]?.data;return!n||n.min===null||n.max===null?[]:[{...e,label:u(e.id),min:Math.floor(n.min),max:Math.ceil(n.max),step:Math.max(1,Math.round((n.max-n.min)/100)),histogram:DF(r,e.id)?n.buckets.map(e=>e.count):[],format:OF(r,e.id)}]}),...l.dateField&&{datePresets:l.datePresets??!0,dateField:l.dateField,dateKind:l.dateKind,...l.dateSecondary&&{dateSecondary:!0}},toggles:l.toggles?.map(e=>({...e,label:u(e.id)}))}},xJ=B(`app/delete`),SJ=m(),CJ=({blockingPlural:e,noun:t})=>xJ(`stillPointAt`,{plural:e,noun:t}),wJ=({blockedBy:e,resources:t,views:n,noun:r,key:i})=>{let{resource:a,field:o}=e;if(!t[a])return;let s=n[a]?.names?.plural??H(a),c=CJ({blockingPlural:s,noun:r});if(!o||i===void 0)return{text:c};let l={kind:`list`,resource:a,filter:vn(SJ.eq(o,i))};return{text:c,link:{label:xJ(`show`,{plural:s}),to:l}}},TJ=({title:e,noun:t,busy:n,onConfirm:r,onCancel:i})=>(0,q.jsx)(di,{title:xJ(`confirmTitle`,{title:e}),description:xJ(`confirmDescription`,{noun:t,title:e}),onClose:i,actions:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(P,{onClick:i,children:xJ(`cancel`)}),(0,q.jsx)(P,{variant:`primary`,className:`bg-danger hover:bg-danger/90`,loading:n,onClick:r,children:xJ(`delete`)})]})}),EJ=({title:e,changes:t,busy:n,onReview:r,onDeleteAnyway:i,onCancel:a})=>(0,q.jsx)(di,{title:xJ(`changedTitle`,{title:e}),description:xJ(`changedDescription`),onClose:a,actions:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(P,{onClick:r,children:xJ(`reviewChanges`)}),(0,q.jsx)(P,{variant:`primary`,className:`bg-danger hover:bg-danger/90`,loading:n,onClick:i,children:xJ(`deleteAnyway`)})]}),children:t.length===0?(0,q.jsx)(`p`,{className:`text-muted-foreground`,children:xJ(`noVisibleChanges`)}):(0,q.jsx)(`ul`,{className:`divide-y rounded-md border`,children:t.map(e=>(0,q.jsxs)(`li`,{className:`grid grid-cols-[96px_1fr] gap-3 px-3 py-2`,children:[(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:e.label}),(0,q.jsxs)(`span`,{children:[(0,q.jsx)(`span`,{className:`text-muted-foreground line-through`,children:e.before}),` `,(0,q.jsx)(`span`,{className:`font-medium`,children:e.after})]})]},e.field))})}),DJ=e=>{if(e.stage===`confirm`)return(0,q.jsx)(di,{title:xJ(`bulkConfirmTitle`,{count:e.count,noun:e.noun,plural:e.plural}),description:xJ(`bulkConfirmDescription`),onClose:e.onCancel,actions:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(P,{onClick:e.onCancel,children:xJ(`cancel`)}),(0,q.jsx)(P,{variant:`primary`,className:`bg-danger hover:bg-danger/90`,onClick:e.onConfirm,children:xJ(`deleteCount`,{count:e.count})})]})});if(e.stage===`running`)return(0,q.jsx)(di,{title:xJ(`deleting`),description:xJ(`progress`,{done:e.done,total:e.total}),onClose:()=>void 0,actions:(0,q.jsx)(P,{loading:!0,disabled:!0,children:xJ(`working`)})});let t=e.total-e.failures.length;return(0,q.jsx)(di,{title:e.failures.length===0?xJ(`deleted`,{count:t}):xJ(`deletedOf`,{count:t,total:e.total}),description:e.failures.length===0?void 0:xJ(`kept`,{count:e.failures.length}),onClose:e.onClose,actions:(0,q.jsx)(P,{variant:`primary`,onClick:e.onClose,children:xJ(`done`)}),children:e.failures.length>0&&(0,q.jsx)(`ul`,{className:`max-h-48 divide-y overflow-y-auto rounded-md border`,children:e.failures.map(e=>(0,q.jsxs)(`li`,{className:`px-3 py-2`,children:[(0,q.jsx)(`span`,{className:`font-medium`,children:e.title}),(0,q.jsx)(`span`,{className:`block text-xs text-danger-text`,children:e.message})]},e.title))})})},OJ=new Set([`updated_at`,`updatedAt`]),kJ=(e,t,n,r)=>Object.values(e.fields).flatMap(e=>{if(OJ.has(e.name)||JSON.stringify(n[e.name]??null)===JSON.stringify(r[e.name]??null))return[];let i=t?.fields[e.name];return[{field:e.name,label:i?.label??H(e.name),before:Lr(e,n[e.name],i),after:Lr(e,r[e.name],i)}]}),AJ=4,jJ=({model:e,view:t,onDeleted:n,onReview:r,restore:i})=>{let a=F(),o=nn(),s=nS(),[l,u]=(0,W.useState)(),[d,f]=(0,W.useState)(!1),p=t?.names?.singular??H(e.name),m=t?.names?.plural??H(e.name),{resources:h,views:g}=c(),{href:_,open:v}=Me(),y=(t,n)=>t.blockedBy&&wJ({blockedBy:t.blockedBy,resources:h,views:g,noun:p,...e.primaryKey.length===1&&{key:n.key}}),b=()=>{for(let t of[`page`,`list`,`first-page`,`map`])o.invalidateQueries({queryKey:[t,e.name]});for(let t of[`facets`,`series`,`aggregate`,`histogram`,`count`])o.invalidateQueries({queryKey:[t,e.name]})},x=async(t,n)=>{let r=n??(await a.get(e.name,t.key)).etag;try{await a.remove(e.name,t.key,{etag:r})}catch(e){if(!(e instanceof kn))throw e;return e}},S=t=>{b(),u(void 0),n?.(t),s.show({state:`success`,title:xJ(`deletedToast`,{title:t.title}),...e.softDelete&&i&&{action:{label:xJ(`undo`),onClick:()=>{i(t).then(()=>{b(),s.show({state:`success`,title:xJ(`restored`,{title:t.title})})},e=>{if(!Tn(e))throw e;b(),s.show({state:e.status===409?`success`:`error`,title:e.status===409?xJ(`alreadyBack`,{title:t.title}):xJ(`couldNotRestore`,{title:t.title}),description:e.status===409?void 0:e.message})})}}}})},C=async(n,r)=>{f(!0);try{if(!await x(n,r))return S(n);let i=(await a.get(e.name,n.key)).record;u({kind:`conflict`,target:n,fresh:i,changes:kJ(e,t,n.snapshot,i)})}catch(e){if(!Tn(e))throw e;u(void 0);let t=y(e,n);s.show({state:`error`,title:xJ(`couldNotDelete`,{title:n.title}),description:t?.text??e.message,...t?.link&&{action:{label:t.link.label,href:_(t.link.to),onNavigate:v}}})}finally{f(!1)}},w=async e=>{try{return await x(e,e.etag)?{title:e.title,message:xJ(`changedSinceLoaded`)}:void 0}catch(t){if(!Tn(t))throw t;return{title:e.title,message:y(t,e)?.text??t.message}}},T=async e=>{let t=[],n=[],r=0;u({kind:`bulk-running`,done:r,total:e.length});let i=[...e];return await Promise.all(Array.from({length:Math.min(AJ,e.length)},async()=>{for(let a=i.shift();a;a=i.shift()){let i=await w(a);i&&(t.push(i),n.push(a)),r+=1,u({kind:`bulk-running`,done:r,total:e.length})}})),b(),u({kind:`bulk-done`,total:e.length,failures:t}),n},E=()=>u(void 0);return{dialogs:l&&(0,q.jsxs)(q.Fragment,{children:[l.kind===`confirm`&&(0,q.jsx)(TJ,{title:l.target.title,noun:p,busy:d,onCancel:E,onConfirm:()=>void C(l.target,l.target.etag)}),l.kind===`conflict`&&(0,q.jsx)(EJ,{title:l.target.title,changes:l.changes,busy:d,onCancel:E,onReview:()=>{E(),r?.(l.target,l.fresh)},onDeleteAnyway:()=>void C(l.target,`*`)}),l.kind===`bulk-confirm`&&(0,q.jsx)(DJ,{stage:`confirm`,count:l.targets.length,noun:p,plural:m,onCancel:()=>{E(),l.settle(l.targets)},onConfirm:()=>l.settle(T(l.targets))}),l.kind===`bulk-running`&&(0,q.jsx)(DJ,{stage:`running`,done:l.done,total:l.total}),l.kind===`bulk-done`&&(0,q.jsx)(DJ,{stage:`done`,total:l.total,failures:l.failures,onClose:E})]}),start:t=>e.softDelete?C(t,t.etag):u({kind:`confirm`,target:t}),startBulk:e=>new Promise(t=>u({kind:`bulk-confirm`,targets:e,settle:t}))}},MJ=e=>{let t=F();return e.softDelete?async n=>void await t.undelete(e.name,n.key):void 0},NJ=(e,t,n)=>e?.create?Object.hasOwn(t,e.create.page):iS(n,`create`),$=B(`app/import`),PJ=e=>typeof e==`object`&&!!e&&`date`in e,FJ=e=>typeof e==`object`&&!!e&&`json`in e,IJ=e=>e===null||typeof e==`string`&&e.trim()===``,LJ=e=>e===null?``:PJ(e)?e.date.replace(`T`,` `):FJ(e)?JSON.stringify(e.json):typeof e==`boolean`?e?`TRUE`:`FALSE`:String(e),RJ=e=>e<26?String.fromCharCode(65+e):RJ(Math.floor(e/26)-1)+RJ(e%26),zJ=(e,t)=>e[t]?.trim()?e[t]:$(`column`,{letters:RJ(t)}),BJ=e=>/[",\r\n]/.test(e)?`"${e.replace(/"/g,`""`)}"`:e,VJ=(e,t)=>{let n=[...t].sort((e,t)=>e.line-t.line).map(t=>[...e.map((e,n)=>LJ(t.cells[n]??null)),String(t.line),t.problems.join(`; `)]);return`${[[...e,$(`line`),$(`problems`)],...n].map(e=>e.map(BJ).join(`,`)).join(`\r
14
+ `)}\r\n`},HJ=({label:e,counts:t})=>(0,q.jsx)(`dl`,{"aria-label":e,className:`grid grid-cols-2 gap-3 sm:grid-cols-4`,children:t.map(([e,t])=>(0,q.jsxs)(`div`,{className:`rounded-lg border px-3 py-2`,children:[(0,q.jsx)(`dt`,{className:`text-xs text-muted-foreground`,children:e}),(0,q.jsx)(`dd`,{className:`text-lg font-semibold tabular-nums`,children:t.toLocaleString(ci())})]},e))}),UJ=(e,t)=>e?.fields[t]?.label??H(t),WJ=new Set([`text`,`integer`,`bigint`,`decimal`,`boolean`,`date`,`timestamp`,`uuid`,`enum`,`relation`,`currency`,`country`]),GJ=(e,t)=>{let n=e.relation?t[e.relation.resource]:void 0;return n?.primaryKey.length===1?n:void 0},KJ=(e,t,{json:n=!1}={})=>Object.values(e.fields).filter(r=>r.readOnly||r.name===e.tenant?!1:r.type===`json`?n:WJ.has(r.type)?r.type!==`relation`||GJ(r,t)!==void 0:!1),qJ=new Set([`text`,`integer`,`bigint`,`uuid`,`date`,`currency`,`country`,`enum`]),JJ=e=>{let t=e.primaryKey.length===1?[e.fields[e.primaryKey[0]]]:[],n=Object.values(e.fields).filter(t=>t.filterable&&!t.sensitive&&qJ.has(t.type)&&!e.primaryKey.includes(t.name));return[...t,...n]},YJ=(e,t)=>GJ(e,t),XJ=e=>!e.nullable&&!e.default,ZJ=e=>e.toLowerCase().replace(/[\s_-]+/g,``),QJ=(e,t,n)=>{let r=new Set;return e.flatMap((e,i)=>{let a=ZJ(e);if(a===``)return[];let o=t.find(e=>!r.has(e.name)&&(ZJ(UJ(n,e.name))===a||ZJ(e.name)===a));return o?(r.add(o.name),[{column:i,field:o.name}]):[]})},$J=(e,t,n)=>{if(e===`update`)return[];let r=new Set(n.map(e=>e.field));return t.filter(e=>XJ(e)&&!r.has(e.name))},eY=e=>({ok:!0,value:e}),tY=e=>({ok:!1,problem:e}),nY=e=>`“${LJ(e)}”`,rY=(e,t)=>{if(typeof e==`number`)return String(e);if(typeof e==`string`)return Qv(e,t.decimal)},iY=(e,t,n)=>{let r=rY(t,n);if(r===void 0)return tY($(`notNumber`,{cell:nY(t)}));let[i,a=``]=r.split(`.`);if(/[1-9]/.test(a)||/e/i.test(r))return tY($(`notWholeNumber`,{cell:nY(t)}));if(e.type===`bigint`)return eY(String(BigInt(i)));let o=Number(i);return Number.isSafeInteger(o)?eY(o):tY($(`tooLarge`,{cell:nY(t)}))},aY=(e,t)=>{let n=rY(e,t);return n===void 0?tY($(`notNumber`,{cell:nY(e)})):eY(n)},oY=new Set([`true`,`yes`,`1`]),sY=new Set([`false`,`no`,`0`]),cY=e=>{if(typeof e==`boolean`)return eY(e);let t=typeof e==`string`||typeof e==`number`?String(e).trim().toLowerCase():``;return oY.has(t)?eY(!0):sY.has(t)?eY(!1):tY($(`notBoolean`,{cell:nY(e)}))},lY=e=>String(e).padStart(2,`0`),uY=(e,t,n)=>{let r=new Date(Date.UTC(e,t-1,n));if(r.getUTCFullYear()===e&&r.getUTCMonth()===t-1&&r.getUTCDate()===n)return`${e}-${lY(t)}-${lY(n)}`},dY=`(\\d{1,2}):(\\d{2})(?::(\\d{2})(?:\\.\\d+)?)?`,fY=(e,t)=>{let n=RegExp(`^(\\d{4})[-/](\\d{1,2})[-/](\\d{1,2})(?:[T ]${dY}(Z|[+-]\\d{2}:?\\d{2})?)?$`).exec(e.trim()),r=RegExp(`^(\\d{1,2})[./-](\\d{1,2})[./-](\\d{4})(?: ${dY})?$`).exec(e.trim());if(!n&&!r)return;let[i,a,o]=n?[n[1],n[2],n[3]].map(Number):t===`dmy`?[r[3],r[2],r[1]].map(Number):[r[3],r[1],r[2]].map(Number),s=uY(i,a,o);if(!s)return;let[c,l,u=`0`]=n?n.slice(4,7):r.slice(4,7);if(c===void 0)return{date:s};if(!(Number(c)>23||Number(l)>59||Number(u)>59))return{date:s,time:`${lY(Number(c))}:${l}:${lY(Number(u))}`,zone:n?.[7]}},pY=(e,t)=>{if(PJ(e)){let[t,n]=e.date.split(`T`);return{date:t,time:n}}return typeof e==`string`?fY(e,t.dateOrder):void 0},mY=(e,t)=>tY($(`notDate`,{cell:nY(e),dayFirst:t.dateOrder===`dmy`})),hY=(e,t)=>{let n=pY(e,t);return n?n.time&&n.time!==`00:00:00`?tY($(`hasTime`,{cell:nY(e)})):eY(n.date):mY(e,t)},gY=(e,t)=>{let n=pY(e,t);if(!n)return mY(e,t);if(n.zone)return eY(new Date(`${n.date}T${n.time}${n.zone===`Z`?`Z`:n.zone.replace(/^([+-]\d{2})(\d{2})$/,`$1:$2`)}`).toISOString());let[r,i,a]=n.date.split(`-`).map(Number),[o,s,c]=(n.time??`00:00:00`).split(`:`).map(Number);return eY(new Date(r,i-1,a,o,s,c).toISOString())},_Y=e=>e.trim().toLowerCase().replace(/\s+/g,` `),vY=(e,t,n)=>{let r=e.enumValues??[],i=_Y(LJ(n)),a=r.filter(e=>_Y(e)===i||_Y(ar(e,t?.valueLabels))===i);return a.length===1?eY(a[0]):a.length>1?tY($(`severalValues`,{cell:nY(n),values:a.map(e=>ar(e,t?.valueLabels)).join(`, `)})):tY($(`notOneOf`,{cell:nY(n),values:r.map(e=>ar(e,t?.valueLabels)).join(`, `)}))},yY=(e,t)=>typeof e==`boolean`&&!t.booleanText?tY($(`notText`,{cell:nY(e)})):eY(LJ(e)),bY=e=>FJ(e)?eY(e.json):eY(e),xY=(e,t,n,r)=>{if(IJ(n))return e.nullable?eY(null):tY($(`emptyRequired`));if(e.type===`json`)return bY(n);if(FJ(n))return tY($(`nestedValue`,{cell:nY(n)}));switch(e.type){case`integer`:case`bigint`:return iY(e,n,r);case`decimal`:return aY(n,r);case`boolean`:return cY(n);case`date`:return hY(n,r);case`timestamp`:return gY(n,r);case`enum`:return vY(e,t,n);case`text`:case`uuid`:case`currency`:case`country`:return yY(n,r);default:throw Error(`Not implemented: importing ${e.type} fields, which importableFields leaves out`)}},SY=(e,t)=>e[t]?.names?.singular??H(t),CY=(e,t)=>e[t]?.names?.plural??H(t),wY=(e,t,n)=>{let{model:r,resources:i,views:a}=n,o=a[r.name],s={},c={},l=[],u=[];for(let{column:n,field:d,matchBy:f}of t.columns){let p=r.fields[d],m=e.cells[n]??null,h=UJ(o,d),g=YJ(p,i);if(g&&!IJ(m)){let e=f??g.primaryKey[0],n=xY(g.fields[e],a[g.name]?.fields[e],m,t.options);n.ok?u.push({field:d,finding:{model:g,field:e,value:n.value}}):l.push(`${h}: ${n.problem}`),s[d]=LJ(m);continue}let _=xY(p,o?.fields[d],m,t.options);_.ok?c[d]=s[d]=_.value:l.push(`${h}: ${_.problem}`)}let d;if(t.match&&t.mode!==`create`){let n=r.fields[t.match.field],i=xY({...n,nullable:!1},o?.fields[n.name],e.cells[t.match.column]??null,t.options);i.ok?d={model:r,field:n.name,value:i.value}:l.push(`${UJ(o,n.name)}: ${i.problem}`)}return{values:s,data:c,problems:l,relations:u,match:d}},TY=(e,t)=>{let n=e.lookups.keysOf(t.model.name,t.field,t.value),r=`${UJ(e.views[t.model.name],t.field).toLowerCase()} “${String(t.value)}”`;return n.length===1?{key:n[0]}:n.length===0?{none:$(`noneHas`,{singular:SY(e.views,t.model.name),named:r})}:{several:$(`severalHave`,{count:n.length,plural:CY(e.views,t.model.name),named:r})}},EY=e=>e.cells.every(IJ),DY=async(e,t,n)=>{let{model:r,views:i}=n,a=e.filter(e=>!EY(e)).map(e=>({row:e,...wY(e,t,n)})),o=new Map;for(let e of a.flatMap(e=>[...e.relations.map(e=>e.finding),...e.match?[e.match]:[]])){let t=`${e.model.name}.${e.field}`;o.has(t)||o.set(t,{model:e.model,field:e.field,values:[]}),o.get(t).values.push(e.value)}for(let{model:e,field:t,values:r}of o.values())await n.lookups.load(e,t,r);return a.map(({row:e,values:a,data:o,problems:s,relations:c,match:l})=>{let u={...o};for(let{field:e,finding:t}of c){let a=TY(n,t);`key`in a?u[e]=a.key:s.push(`${UJ(i[r.name],e)}: ${a.none??a.several}`)}let d=l&&TY(n,l);d?.several&&s.push($(`notOneRecord`,{found:d.several})),d?.none&&t.mode===`update`&&s.push($(`nothingToUpdate`,{found:d.none}));let f={line:e.line,cells:e.cells,values:a,problems:s};return s.length>0?f:d&&`key`in d?{...f,op:{op:`update`,resource:r.name,key:d.key,etag:`*`,data:u}}:{...f,op:{op:`create`,resource:r.name,data:u}}})},OY=5,kY=5,AY=async(e,t)=>{let n=e.rows(t),{value:r=[]}=await n.next();await n.return(void 0);let[i,...a]=r;return{headers:(i?.cells??[]).map(LJ),sample:a.slice(0,OY)}};async function*jY(e,t){let n=!0;for await(let r of e.rows(t))yield n?r.slice(1):r,n=!1}var MY=async(e,t,n,r,i,a)=>{let o={rows:0,creates:0,updates:0,problems:[],preview:[]};for await(let s of jY(e,t)){a?.throwIfAborted();for(let e of await DY(s,n,r))o.rows++,o.preview.length<kY&&o.preview.push(e),e.op?.op===`create`?o.creates++:e.op?.op===`update`?o.updates++:o.problems.push({line:e.line,cells:e.cells,problems:e.problems});i(o.rows)}return o},NY=(e,t)=>{if(!Tn(e))return[e.message];let n=e.errors.filter(e=>e.field);return n.length===0?[e.message]:n.map(e=>`${UJ(t.views[t.model.name],e.field)}: ${e.message}`)},PY=async(e,t,n,r,{client:i,onProgress:a,cancelled:o})=>{let s={created:0,updated:0,skipped:0,failed:0,notWritten:[]},c=async e=>{let t=[...e];for(;t.length>0;){let e=t.map(e=>e.op);try{let{results:t}=await i.batchWrite(e);for(let e of t)e.op===`create`?s.created++:e.op===`update`&&s.updated++;return}catch(e){let n=Tn(e)?e.operation:void 0;if(n===void 0||!t[n])throw e;let[i]=t.splice(n,1);s.failed++,s.notWritten.push({line:i.line,cells:i.cells,problems:NY(e,r)})}}},l=[],u=async e=>{for(;l.length>=100||e&&l.length>0;){if(o())return!1;await c(l.splice(0,100)),a({...s})}return!0};for await(let i of jY(e,t)){for(let e of await DY(i,n,r))e.op?l.push(e):(s.skipped++,s.notWritten.push({line:e.line,cells:e.cells,problems:e.problems}));if(!await u(!1))return{...s,cancelled:!0}}return await u(!0)?{...s,cancelled:!1}:{...s,cancelled:!0}},FY=50,IY=(e,t,n)=>uU(VJ(t,n),$(`notImportedFile`,{name:(e??`import`).replace(/\.[^.]+$/,``)}),`text/csv`),LY=({rows:e})=>(0,q.jsxs)(`ul`,{"aria-label":$(`rowsNotImported`),className:`flex flex-col gap-1 text-body`,children:[e.slice(0,FY).map(e=>(0,q.jsxs)(`li`,{children:[(0,q.jsx)(`span`,{className:`font-medium`,children:$(`rowProblems`,{line:e.line})}),` `,e.problems.join(`; `)]},e.line)),e.length>FY&&(0,q.jsx)(`li`,{className:`text-muted-foreground`,children:$(`andMore`,{count:(e.length-FY).toLocaleString(ci())})})]}),RY=({rows:e})=>(0,q.jsxs)(`p`,{className:`flex items-center gap-2 text-muted-foreground`,role:`status`,children:[(0,q.jsx)(wn,{className:`size-3.5`}),$(`checkingRows`,{count:e.toLocaleString(ci())})]}),zY=({check:e,model:t,resources:n,views:r,columns:i,headers:a,fileName:o})=>{let s=r[t.name],c=i.map(e=>t.fields[e.field]);return(0,q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,q.jsx)(HJ,{label:$(`check`),counts:[[$(`rows`),e.rows],[$(`toCreate`),e.creates],[$(`toUpdate`),e.updates],[$(`withProblems`),e.problems.length]]}),e.preview.length>0&&(0,q.jsx)(`div`,{className:`overflow-x-auto rounded-lg border`,children:(0,q.jsxs)(`table`,{"aria-label":$(`firstRows`),className:`w-full text-left text-body`,children:[(0,q.jsx)(`thead`,{className:`bg-muted text-muted-foreground`,children:(0,q.jsxs)(`tr`,{children:[(0,q.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:$(`row`)}),c.map(e=>(0,q.jsx)(`th`,{className:`whitespace-nowrap px-2 py-1.5 font-medium`,children:UJ(s,e.name)},e.name))]})}),(0,q.jsx)(`tbody`,{className:`divide-y`,children:e.preview.map(e=>(0,q.jsxs)(`tr`,{className:e.problems.length>0?`bg-danger-soft`:void 0,children:[(0,q.jsx)(`td`,{className:`px-2 py-1.5 tabular-nums text-muted-foreground`,children:e.line}),c.map(t=>(0,q.jsx)(`td`,{className:`max-w-48 truncate px-2 py-1.5`,children:YJ(t,n)?String(e.values[t.name]??`—`):t.name in e.values?Lr(t,e.values[t.name],s?.fields[t.name]):``},t.name))]},e.line))})]})}),e.problems.length>0&&(0,q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,q.jsx)(`h3`,{className:`font-medium`,children:$(`problemRows`)}),(0,q.jsxs)(P,{size:`sm`,onClick:()=>IY(o,a,e.problems),children:[(0,q.jsx)(Qc,{className:`size-3.5`}),$(`download`)]})]}),(0,q.jsx)(LY,{rows:e.problems})]}),(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:$(`batches`,{size:100})})]})},BY=[`.xlsx`,`.csv`,`.json`],VY=[`text/csv`,`application/json`,`application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`],HY=[`text/comma-separated-values`,`application/csv`,`text/x-csv`,`application/vnd.ms-excel`,`text/plain`,`application/octet-stream`],UY=e=>/\bAndroid\b/.test(e),WY=e=>[...BY,...VY,...UY(e)?HY:[]].join(`,`),GY=({label:e,name:t,value:n,options:r,onChange:i,help:a,className:o})=>{let s=(0,W.useId)();return(0,q.jsxs)(`div`,{className:U(`flex min-w-0 flex-col gap-1.5`,o),children:[(0,q.jsx)(`label`,{htmlFor:s,className:`font-medium`,children:e}),(0,q.jsx)(`select`,{id:s,"aria-label":t,value:n,onChange:e=>i(e.target.value),className:`h-8 w-full min-w-0 rounded-md border border-border-strong bg-background px-2 shadow-sm focus:border-primary focus:outline-none focus:ring-2 focus:ring-primary/20 max-sm:min-h-11`,children:r.map(e=>(0,q.jsx)(`option`,{value:e.value,children:e.label},e.value))}),a&&(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:a})]})},KY=({file:e,sheets:t,sheet:n,reading:r,onChoose:i,onSheet:a})=>{let o=(0,W.useId)();return(0,q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,q.jsx)(`label`,{htmlFor:o,className:`font-medium`,children:$(`file`)}),(0,q.jsx)(`input`,{id:o,type:`file`,accept:WY(globalThis.navigator?.userAgent??``),disabled:r,onChange:e=>{let t=e.target.files?.[0];t&&i(t)},className:`file:mr-3 file:h-8 file:rounded-md file:border file:border-border-strong file:bg-background file:px-3 file:font-medium file:text-foreground max-sm:file:min-h-11`}),(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:$(`fileHint`)})]}),r&&(0,q.jsxs)(`p`,{className:`flex items-center gap-2 text-muted-foreground`,role:`status`,children:[(0,q.jsx)(wn,{className:`size-3.5`}),$(`reading`,{name:e?.name??$(`theFile`)})]}),!r&&t.length>1&&(0,q.jsxs)(`div`,{className:`flex items-end gap-3`,children:[(0,q.jsx)(gl,{className:`mb-2 size-4 shrink-0 text-muted-foreground`}),(0,q.jsx)(GY,{className:`flex-1`,label:$(`sheet`),value:n??``,options:t.map(e=>({value:e,label:e})),onChange:a})]})]})},qY=()=>[{value:`create`,label:$(`create`)},{value:`update`,label:$(`update`)},{value:`upsert`,label:$(`upsert`)}],JY={create:`createHint`,update:`updateHint`,upsert:`upsertHint`},YY=``,XY=({flow:e,model:t,resources:n,views:r,canUpdate:i})=>{let a=r[t.name],o=e.head?.headers??[],s=e.head?.sample??[],c=$J(e.mode,e.fields,e.columns),l=[{value:YY,label:$(`doNotImport`)},...e.fields.map(e=>({value:e.name,label:`${UJ(a,e.name)}${XJ(e)?` *`:``}`}))],u=o.map((e,t)=>({value:String(t),label:zJ(o,t)})),d=JJ(t);return(0,q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[i&&(0,q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,q.jsx)(`span`,{className:`font-medium`,children:$(`rows`)}),(0,q.jsx)(`div`,{children:(0,q.jsx)(Av,{label:$(`whatEachRowDoes`),size:`md`,value:e.mode,options:qY(),onChange:e.setMode})}),(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:$(JY[e.mode])})]}),e.mode!==`create`&&(0,q.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2`,children:[(0,q.jsx)(GY,{label:$(`findBy`),value:e.match?.field??YY,options:[{value:YY,label:$(`chooseField`)},...d.map(e=>({value:e.name,label:UJ(a,e.name)}))],onChange:t=>e.setMatch(t?{field:t,column:e.match?.column??0}:void 0),help:$(`findByHint`)}),(0,q.jsx)(GY,{label:$(`foundInColumn`),value:e.match?String(e.match.column):YY,options:[{value:YY,label:$(`chooseColumn`)},...u],onChange:t=>e.setMatch(t&&e.match?{...e.match,column:Number(t)}:e.match)})]}),(0,q.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2`,children:[(0,q.jsx)(GY,{label:$(`numbers`),value:e.options.decimal,options:[{value:`.`,label:`1,234.56`},{value:`,`,label:`1.234,56`}],onChange:t=>e.setOptions({...e.options,decimal:t})}),(0,q.jsx)(GY,{label:$(`dates`),value:e.options.dateOrder,options:[{value:`dmy`,label:$(`dayFirst`)},{value:`mdy`,label:$(`monthFirst`)}],onChange:t=>e.setOptions({...e.options,dateOrder:t}),help:$(`datesHint`)})]}),e.mode!==`update`&&(0,q.jsx)(`p`,{className:`-mb-3 text-xs text-muted-foreground`,children:$(`requiredMarked`)}),(0,q.jsx)(`section`,{"aria-label":$(`columns`),className:`flex flex-col divide-y divide-border border-y`,children:o.map((i,c)=>{let u=e.columns.find(e=>e.column===c),d=u?t.fields[u.field]:void 0,f=d?YJ(d,n):void 0,p=s.map(e=>LJ(e.cells[c]??null)).filter(e=>e!==``).slice(0,3),m=zJ(o,c);return(0,q.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 py-3 sm:grid-cols-2 sm:gap-4`,children:[(0,q.jsxs)(`div`,{className:`min-w-0`,children:[(0,q.jsx)(`p`,{className:`truncate font-medium`,children:m}),(0,q.jsx)(`p`,{className:`truncate text-xs text-muted-foreground`,children:p.length>0?p.join(`, `):$(`emptyInFirstRows`)})]}),(0,q.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[(0,q.jsx)(GY,{label:$(`field`),name:$(`fieldFor`,{name:m}),value:u?.field??YY,options:l,onChange:t=>e.mapColumn(c,t||void 0)}),f&&(0,q.jsx)(GY,{label:$(`foundBy`),name:$(`pluralFoundBy`,{plural:r[f.name]?.names?.plural??UJ(a,d.name)}),value:u.matchBy??f.primaryKey[0],options:JJ(f).map(e=>({value:e.name,label:UJ(r[f.name],e.name)})),onChange:t=>e.matchColumnBy(c,t)})]})]},c)})}),c.length>0&&(0,q.jsxs)(`p`,{role:`alert`,className:`flex gap-2 rounded-lg border border-warning/30 bg-warning-soft px-3 py-2 text-warning-text`,children:[(0,q.jsx)(Mi,{className:`mt-0.5 size-4 shrink-0`}),(0,q.jsx)(`span`,{children:$(`noColumnFills`,{fields:c.map(e=>UJ(a,e.name)).join(`, `)})})]})]})},ZY=e=>e.toLocaleString(ci()),QY=({progress:e,total:t,cancelling:n})=>{let r=e.created+e.updated+e.failed;return(0,q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,q.jsxs)(`div`,{className:`flex items-baseline justify-between gap-2 text-xs`,children:[(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:$(n?`stopping`:`saving`)}),(0,q.jsxs)(`span`,{className:`tabular-nums`,children:[ZY(r),` / `,ZY(t)]})]}),(0,q.jsx)(`div`,{role:`progressbar`,"aria-label":$(`rowsSaved`),"aria-valuenow":r,"aria-valuemin":0,"aria-valuemax":t,className:`h-2 overflow-hidden rounded-full bg-muted`,children:(0,q.jsx)(`div`,{className:`h-full rounded-full bg-primary transition-[width]`,style:{width:`${t>0?Math.min(100,r/t*100):0}%`}})})]})},$Y=({result:e,stopped:t,headers:n,fileName:r})=>(0,q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[t!==void 0&&(0,q.jsx)(Oy,{title:$(`stopped`),error:t}),e.cancelled&&(0,q.jsx)(`p`,{role:`status`,children:$(`cancelled`)}),(0,q.jsx)(HJ,{label:$(`summary`),counts:[[$(`created`),e.created],[$(`updated`),e.updated],[$(`skipped`),e.skipped],[$(`failed`),e.failed]]}),e.notWritten.length>0&&(0,q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,q.jsx)(`h3`,{className:`font-medium`,children:$(`rowsNotImported`)}),(0,q.jsxs)(P,{size:`sm`,onClick:()=>IY(r,n,e.notWritten),children:[(0,q.jsx)(Qc,{className:`size-3.5`}),$(`download`)]})]}),(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:$(`notWrittenHint`)}),(0,q.jsx)(LY,{rows:[...e.notWritten].sort((e,t)=>e.line-t.line)})]})]}),eX=e=>{let t=Xv(e),n=new Intl.DateTimeFormat(e).formatToParts(new Date(2026,3,3)).map(e=>e.type);return{decimal:t,dateOrder:n.indexOf(`month`)<n.indexOf(`day`)?`mdy`:`dmy`}},tX=m(),nX=100,rX=e=>String(e),iX=e=>{let t=new Map,n=(e,n)=>{let r=`${e}.${n}`;return t.has(r)||t.set(r,new Map),t.get(r)};return{load:async(t,r,i)=>{let a=n(t.name,r),o=[...new Map(i.filter(e=>!a.has(rX(e))).map(e=>[rX(e),e])).values()],s=t.primaryKey[0];for(let n=0;n<o.length;n+=nX){let i=o.slice(n,n+nX);for(let e of i)a.set(rX(e),[]);let c=vn(tX.in(r,i)),l;do{let n=await e(t.name).list(t.name,{filter:c,fields:[...new Set([s,r])],pageSize:1e3,pageToken:l});for(let e of n.items)a.get(rX(e[r]))?.push(e[s]);l=n.nextPageToken||void 0}while(l)}},keysOf:(e,t,r)=>n(e,t).get(rX(r))??[]}},aX=e=>/\.json$/i.test(e.name)||e.type.split(`;`)[0].trim().toLowerCase()===`application/json`,oX=500,sX=()=>{let e=new Worker(new URL(`/assets/parse-worker-D7uEODYK.js`,``+import.meta.url),{type:`module`}),t=[],n;return e.onmessage=e=>{if(n){let t=n;n=void 0,t(e.data)}else t.push(e.data)},e.onerror=e=>{e.preventDefault();let r={type:`error`,message:$(`unreadable`)};n?n(r):t.push(r)},{send:t=>e.postMessage(t),receive:()=>t.length>0?Promise.resolve(t.shift()):new Promise(e=>n=e),stop:()=>e.terminate()}},cX=e=>({sheets:async()=>{let t=sX();try{t.send({type:`sheets`,file:e,locale:oi()});let n=await t.receive();if(n.type===`error`)throw Error(n.message);if(n.type!==`sheets`)throw Error(`The parse worker answered ${n.type} to a request for sheets`);return n.sheets}finally{t.stop()}},rows:async function*(t){let n=sX();try{for(n.send({type:`read`,file:e,sheet:t,chunk:oX,locale:oi()});;){let e=await n.receive();if(e.type===`error`)throw Error(e.message);if(e.type===`end`)return;if(e.type!==`rows`)throw Error(`The parse worker answered ${e.type} to a read`);yield e.rows,n.send({type:`next`})}}finally{n.stop()}}}),lX={created:0,updated:0,skipped:0,failed:0,notWritten:[]},uX=({model:e,resources:t,views:n,sourceFor:r=cX})=>{let i=En(),a=nn(),o=n[e.name],[s,c]=(0,W.useState)({kind:`file`,reading:!1}),[l,u]=(0,W.useState)(),[d,f]=(0,W.useState)(),p=d?aX(d.file):!1,m=(0,W.useMemo)(()=>KJ(e,t,{json:p}),[e,t,p]),[h,g]=(0,W.useState)(),[_,v]=(0,W.useState)(),[y,b]=(0,W.useState)(`create`),[x,S]=(0,W.useState)([]),[C,w]=(0,W.useState)(),[T,E]=(0,W.useState)(()=>eX()),D=(0,W.useRef)(!1),O=(0,W.useRef)(void 0),k=e=>t=>{u(t),c(e)},ee=n=>{u(void 0),c({kind:`file`,reading:!0});let i=r(n);i.sheets().then(r=>{if(f({file:n,source:i,sheets:r}),g(r[0]),r.length<=1)return A(i,r[0],KJ(e,t,{json:aX(n)}));c({kind:`file`,reading:!1})}).catch(k({kind:`file`,reading:!1}))},A=async(t,n,r)=>{c({kind:`file`,reading:!0});let i=await AY(t,n);v(i),S(QJ(i.headers,r,o));let a=JJ(e)[0],s=a?QJ(i.headers,[a],o)[0]:void 0;w(a&&s?{field:a.name,column:s.column}:void 0),c({kind:`map`})},te=()=>{d&&(u(void 0),A(d.source,h,m).catch(k({kind:`file`,reading:!1})))},ne=(e,t)=>S(n=>{let r=n.filter(n=>n.column!==e&&n.field!==t);return t?[...r,{column:e,field:t}].sort((e,t)=>e.column-t.column):r}),re=(e,t)=>S(n=>n.map(n=>n.column===e?{...n,matchBy:t}:n)),j=()=>({mode:y,columns:x,match:y===`create`?void 0:C,options:T}),ie=()=>({model:e,resources:t,views:n,lookups:iX(i)});return{step:s,error:l,file:d?.file,sheets:d?.sheets??[],sheet:h,setSheet:g,head:_,fields:m,mode:y,setMode:b,columns:x,mapColumn:ne,matchColumnBy:re,match:C,setMatch:w,options:T,setOptions:E,choose:ee,openSheet:te,check:()=>{if(!d)return;u(void 0);let e=new AbortController;O.current=e,c({kind:`checking`,rows:0}),MY(d.source,h,j(),ie(),e=>c({kind:`checking`,rows:e}),e.signal).then(t=>{e.signal.aborted||c({kind:`checked`,check:t})}).catch(t=>{e.signal.aborted||k({kind:`map`})(t)})},back:()=>{O.current?.abort(),u(void 0),c({kind:`map`})},start:t=>{if(!d)return;u(void 0),D.current=!1,c({kind:`importing`,progress:lX,total:t,cancelling:!1});let n=lX;PY(d.source,h,j(),ie(),{client:i(e.name),onProgress:e=>{n=e,c({kind:`importing`,progress:e,total:t,cancelling:D.current})},cancelled:()=>D.current}).then(e=>c({kind:`done`,result:e})).catch(e=>c({kind:`done`,result:{...n,cancelled:!1},stopped:e})).finally(()=>{for(let t of[`page`,`list`,`first-page`,`map`,`facets`,`series`,`aggregate`,`count`])a.invalidateQueries({queryKey:[t,e.name]})})},cancel:()=>{D.current=!0,c(e=>e.kind===`importing`?{...e,cancelling:!0}:e)},stop:()=>O.current?.abort()}},dX=e=>e.step.kind===`file`?$(`couldNotReadFile`):$(`couldNotCheck`),fX=e=>e.columns.length===0?!1:e.mode===`create`?$J(`create`,e.fields,e.columns).length===0:e.match!==void 0,pX=({model:e,resources:t,views:n,canUpdate:r,onClose:i,sourceFor:a})=>{let o=uX({model:e,resources:t,views:n,sourceFor:a}),s=n[e.name]?.names?.plural??H(e.name),{step:c}=o,l=o.head?.headers??[],u=()=>{c.kind!==`importing`&&(o.stop(),i())},d=(0,q.jsx)(P,{onClick:u,children:$(`cancel`)});return(0,q.jsx)(g_,{open:!0,wide:!0,title:$(`importPlural`,{plural:s}),description:o.file&&c.kind!==`file`?o.file.name:void 0,onClose:u,actions:(()=>{switch(c.kind){case`file`:return(0,q.jsxs)(q.Fragment,{children:[d,o.sheets.length>1&&(0,q.jsx)(P,{variant:`primary`,loading:c.reading,onClick:o.openSheet,children:$(`next`)})]});case`map`:return(0,q.jsxs)(q.Fragment,{children:[d,(0,q.jsx)(P,{variant:`primary`,disabled:!fX(o),onClick:o.check,children:$(`checkRows`)})]});case`checking`:return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(P,{onClick:o.back,children:$(`back`)}),(0,q.jsx)(P,{variant:`primary`,loading:!0,children:$(`checking`)})]});case`checked`:{let e=c.check.creates+c.check.updates;return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(P,{onClick:o.back,children:$(`back`)}),(0,q.jsx)(P,{variant:`primary`,disabled:e===0,onClick:()=>o.start(e),children:$(`importRows`,{count:e.toLocaleString(ci()),rows:e})})]})}case`importing`:return(0,q.jsx)(P,{variant:`danger`,disabled:c.cancelling,onClick:o.cancel,children:$(`cancelImport`)});case`done`:return(0,q.jsx)(P,{variant:`primary`,onClick:i,children:$(`done`)})}})(),children:(0,q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[o.error!==void 0&&(0,q.jsx)(Oy,{title:dX(o),error:o.error}),(()=>{switch(c.kind){case`file`:return(0,q.jsx)(KY,{file:o.file,sheets:o.sheets,sheet:o.sheet,reading:c.reading,onChoose:o.choose,onSheet:o.setSheet});case`map`:return(0,q.jsx)(XY,{flow:o,model:e,resources:t,views:n,canUpdate:r});case`checking`:return(0,q.jsx)(RY,{rows:c.rows});case`checked`:return(0,q.jsx)(zY,{check:c.check,model:e,resources:t,views:n,columns:o.columns,headers:l,fileName:o.file?.name});case`importing`:return(0,q.jsx)(QY,{progress:c.progress,total:c.total,cancelling:c.cancelling});case`done`:return(0,q.jsx)($Y,{result:c.result,stopped:c.stopped,headers:l,fileName:o.file?.name})}})()]})})},mX=(e,t,n,r)=>{let i=qf(t.headers),a=t.headers.map((e,n)=>({column:n,include:!0,name:i[n],label:zJ(t.headers,n).trim(),type:t.types[n].type,inferred:t.types[n],decimal:t.decimals[n]}));return{name:Jf(e,n,r)??``,pluralLabel:e.replace(/\.[^.]+$/,``).trim(),singularLabel:``,titleField:a.find(e=>e.type===`text`)?.name,fields:a}},hX=e=>e.fields.filter(e=>e.include),gX=(e,t,n)=>{let r=e.fields.find(e=>e.column===t),i=e.fields.map(e=>e.column===t?{...e,...n}:e),a=i.find(e=>e.column===t),o=r?.name===e.titleField,s=a.include&&a.type===`text`;return o?{...e,fields:i,titleField:s?a.name:void 0}:{...e,fields:i}},_X=`user_table_fields`,vX=`table`,yX=(e,t)=>{let n=hX(t).map((e,t)=>({op:`create`,resource:_X,data:{table_id:{$ref:vX},name:e.name,label:e.label.trim(),type:e.type,position:t+1,...e.type===`decimal`&&{precision:e.decimal.precision,scale:e.decimal.scale}}})),r=t.titleField?[{op:`update`,resource:e,key:{$ref:vX},etag:`*`,data:{title_field:t.titleField}}]:[];return[{op:`create`,resource:e,ref:vX,data:{name:t.name,singular_label:t.singularLabel.trim(),plural_label:t.pluralLabel.trim()}},...n,...r]},bX=(e,t)=>{let n=e[t],r=e[_X];return{table:e=>({label:UJ(n,e),help:n?.fields[e]?.help}),field:e=>({label:UJ(r,e),help:r?.fields[e]?.help}),type:e=>r?.fields.type?.valueLabels?.[e]??e}},xX=(e,t,n)=>e===`form`?$(`nameForm`,{max:n}):$(e===`reserved_word`?`nameReservedWord`:`nameReservedField`,{name:t}),SX=e=>{if(e.trim()===``)return $(`needed`);if(e.trim().length>200)return $(`labelTooLong`,{max:200})},CX=(e,t,n)=>{let r=os(e.name,`table`,n),i={name:r?xX(r,e.name,n):t.has(e.name)?$(`nameTaken`,{name:e.name}):void 0,pluralLabel:SX(e.pluralLabel),singularLabel:SX(e.singularLabel),fields:{}},a=hX(e);a.length===0&&(i.noFields=$(`noFields`));let o=new Set;for(let e of a){let t=os(e.name,`field`),n=t?xX(t,e.name,63):o.has(e.name)?$(`nameTwice`,{name:e.name}):void 0;o.add(e.name);let r=SX(e.label);(n||r)&&(i.fields[e.column]={...n&&{name:n},...r&&{label:r}})}return i},wX=e=>!!(e.name||e.pluralLabel||e.singularLabel||e.noFields||Object.keys(e.fields).length>0),TX=``,EX=({field:e,column:t,examples:n,problems:r,texts:i,onChange:a})=>{let o=i.field(`type`),s=i.field(`label`),c=i.field(`name`),l=Hf(e.inferred.type).map(e=>({value:e,label:i.type(e)})),u=e.include&&e.type===`decimal`;return(0,q.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 py-3 sm:grid-cols-2 sm:gap-4`,children:[(0,q.jsxs)(`div`,{className:`min-w-0`,children:[(0,q.jsx)(`p`,{className:`truncate font-medium`,children:t}),(0,q.jsx)(`p`,{className:`truncate text-xs text-muted-foreground`,children:n.length>0?n.join(`, `):$(`emptyInFirstRows`)})]}),(0,q.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[(0,q.jsx)(GY,{label:o.label,name:$(`typeFor`,{name:t}),value:e.include?e.type:TX,options:[...l,{value:TX,label:$(`doNotImport`)}],onChange:e=>a(e===TX?{include:!1}:{include:!0,type:e}),help:u?$(`decimalSize`,{precision:e.decimal.precision,scale:e.decimal.scale}):void 0}),e.include&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(Mv,{label:s.label,error:r?.label,required:!0,children:(0,q.jsx)(bi,{wrapperClassName:`max-sm:min-h-11`,"aria-label":$(`labelFor`,{name:t}),value:e.label,onChange:e=>a({label:e.target.value})})}),(0,q.jsx)(Mv,{label:c.label,error:r?.name,required:!0,children:(0,q.jsx)(bi,{wrapperClassName:`max-sm:min-h-11`,className:`font-mono`,"aria-label":$(`nameFor`,{name:t}),autoCapitalize:`none`,autoCorrect:`off`,spellCheck:!1,value:e.name,onChange:e=>a({name:e.target.value})})})]})]})]})},DX=``,OX=({proposal:e,problems:t,texts:n,onChange:r})=>{let i=hX(e).filter(e=>e.type===`text`),a=n.table(`plural_label`),o=n.table(`singular_label`),s=n.table(`name`),c=n.table(`title_field`);return(0,q.jsxs)(`section`,{"aria-label":$(`newTable`),className:`grid grid-cols-1 gap-3 sm:grid-cols-2`,children:[(0,q.jsx)(Mv,{label:a.label,help:a.help,error:t.pluralLabel,required:!0,children:(0,q.jsx)(bi,{wrapperClassName:`max-sm:min-h-11`,value:e.pluralLabel,onChange:e=>r({pluralLabel:e.target.value})})}),(0,q.jsx)(Mv,{label:o.label,help:o.help,error:t.singularLabel,required:!0,children:(0,q.jsx)(bi,{wrapperClassName:`max-sm:min-h-11`,value:e.singularLabel,onChange:e=>r({singularLabel:e.target.value})})}),(0,q.jsx)(Mv,{label:s.label,help:s.help,error:t.name,required:!0,children:(0,q.jsx)(bi,{wrapperClassName:`max-sm:min-h-11`,className:`font-mono`,autoCapitalize:`none`,autoCorrect:`off`,spellCheck:!1,value:e.name,onChange:e=>r({name:e.target.value})})}),(0,q.jsx)(GY,{label:c.label,value:e.titleField??DX,options:[{value:DX,label:$(`noTitle`)},...i.map(e=>({value:e.name,label:e.label||e.name}))],onChange:e=>r({titleField:e||void 0}),help:c.help})]})},kX=({flow:e,problems:t,texts:n})=>{let{proposal:r,read:i}=e;return!r||!i?null:(0,q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,q.jsx)(OX,{proposal:r,problems:t,texts:n,onChange:e.changeTable}),(0,q.jsx)(`p`,{className:`-mb-3 text-xs text-muted-foreground`,children:$(`typesFromCells`,{rows:i.rows})}),(0,q.jsx)(`section`,{"aria-label":$(`columns`),className:`flex flex-col divide-y divide-border border-y`,children:r.fields.map(r=>(0,q.jsx)(EX,{field:r,column:zJ(i.headers,r.column),examples:i.sample.map(e=>LJ(e.cells[r.column]??null)).filter(e=>e!==``).slice(0,3),problems:t.fields[r.column],texts:n,onChange:t=>e.change(r.column,t)},r.column))}),t.noFields&&(0,q.jsxs)(`p`,{role:`alert`,className:`flex gap-2 rounded-lg border border-warning/30 bg-warning-soft px-3 py-2 text-warning-text`,children:[(0,q.jsx)(Mi,{className:`mt-0.5 size-4 shrink-0`}),(0,q.jsx)(`span`,{children:t.noFields})]})]})},AX=5,jX=async(e,t,n,r)=>{let i,a=[],o=[],s=0;for await(let c of e.rows(t)){r?.throwIfAborted();for(let e of c){if(!i){i=e.cells.map(LJ),a=i.map(()=>Vf());continue}e.cells.every(IJ)||(s++,o.length<AX&&o.push(e),a.forEach((t,n)=>t.add(e.cells[n]??null)))}n(s)}return{headers:i??[],types:a.map(e=>e.type()),decimals:a.map(e=>e.decimal()),sample:o,rows:s}},MX={created:0,updated:0,skipped:0,failed:0,notWritten:[]},NX={decimal:`.`,dateOrder:`dmy`,booleanText:!0},PX=({tables:e,resources:t,sourceFor:n=cX})=>{let r=En(),i=nn(),{go:a}=Me(),o=e.tenant!==void 0,s=o?42:63,c=(0,W.useMemo)(()=>new Set(o?[]:Object.keys(t)),[o,t]),[l,u]=(0,W.useState)({kind:`file`,reading:!1}),[d,f]=(0,W.useState)(),[p,m]=(0,W.useState)(),[h,g]=(0,W.useState)(),[_,v]=(0,W.useState)(),[y,b]=(0,W.useState)(),[x,S]=(0,W.useState)(),C=(0,W.useRef)(!1),w=(0,W.useRef)(void 0),T=e=>t=>{f(t),u(e)},E=(e,t,n)=>{let r=new AbortController;w.current=r,u({kind:`reading`,rows:0}),jX(t,n,e=>u({kind:`reading`,rows:e}),r.signal).then(t=>{r.signal.aborted||(v(t),b(mX(e.name,t,c,s)),u({kind:`fields`}))}).catch(e=>{r.signal.aborted||T({kind:`file`,reading:!1})(e)})},D=e=>{f(void 0),u({kind:`file`,reading:!0});let t=n(e);t.sheets().then(n=>{if(m({file:e,source:t,sheets:n}),g(n[0]),n.length<=1)return E(e,t,n[0]);u({kind:`file`,reading:!1})}).catch(T({kind:`file`,reading:!1}))},O=()=>{p&&(f(void 0),E(p.file,p.source,h))},k=(e,t)=>b(n=>n&&gX(n,e,t)),ee=e=>b(t=>t&&{...t,...e}),A=async e=>{await i.refetchQueries({queryKey:I.meta});let t=i.getQueryData(I.meta),n=t?.resources[e];if(!t||!n)throw Error(`The server does not serve the new table ${e} yet`);return{model:n,resources:t.resources,views:t.views}},te=async(e,t)=>{if(!p||!_)return;let n={...await A(e),lookups:iX(r)},i={mode:`create`,columns:hX(t).map(e=>({column:e.column,field:e.name})),options:NX};C.current=!1;let o=MX;u({kind:`importing`,progress:MX,total:_.rows,cancelling:!1});let s=await PY(p.source,h,i,n,{client:r(e),onProgress:e=>{o=e,u({kind:`importing`,progress:e,total:_.rows,cancelling:C.current})},cancelled:()=>C.current}).catch(e=>({...o,cancelled:!1,stopped:e})),c=`stopped`in s?s.stopped:void 0;if(c===void 0&&!s.cancelled&&s.notWritten.length===0)return a({kind:`list`,resource:e});u({kind:`done`,result:s,stopped:c})};return{step:l,error:d,file:p?.file,sheets:p?.sheets??[],sheet:h,setSheet:g,read:_,proposal:y,table:x,taken:c,maxTableBytes:s,choose:D,openSheet:O,change:k,changeTable:ee,create:()=>{y&&(f(void 0),u({kind:`creating`}),r(e.name).batchWrite(yX(e.name,y)).then(({results:e})=>{let[t]=e,n=t?.op===`create`?String(t.record.table_name):y.name;return S(n),te(n,y).catch(e=>u({kind:`done`,result:{...MX,cancelled:!1},stopped:e}))},T({kind:`fields`})))},cancel:()=>{C.current=!0,u(e=>e.kind===`importing`?{...e,cancelling:!0}:e)},back:()=>{w.current?.abort(),f(void 0),u({kind:`file`,reading:!1})},stop:()=>w.current?.abort()}},FX=e=>e.step.kind===`fields`?$(`couldNotMakeTable`):$(`couldNotReadFile`),IX=({tables:e,resources:t,views:n,onClose:r,sourceFor:i})=>{let a=PX({tables:e,resources:t,sourceFor:i}),o=bX(n,e.name),{step:s,proposal:c}=a,l=c?CX(c,a.taken,a.maxTableBytes):void 0,u=a.read?.headers??[],d=s.kind===`creating`||s.kind===`importing`,f=()=>{d||(a.stop(),r())},p=(0,q.jsx)(P,{onClick:f,children:$(`cancel`)});return(0,q.jsx)(g_,{open:!0,wide:!0,title:$(`tableFromFile`),description:a.file&&s.kind!==`file`?a.file.name:void 0,onClose:f,actions:(()=>{switch(s.kind){case`file`:return(0,q.jsxs)(q.Fragment,{children:[p,a.sheets.length>1&&(0,q.jsx)(P,{variant:`primary`,loading:s.reading,onClick:a.openSheet,children:$(`next`)})]});case`reading`:return(0,q.jsx)(P,{onClick:a.back,children:$(`back`)});case`fields`:case`creating`:{let e=a.read?.rows??0;return(0,q.jsxs)(q.Fragment,{children:[p,(0,q.jsx)(P,{variant:`primary`,loading:s.kind===`creating`,disabled:!l||wX(l),onClick:a.create,children:$(`makeTable`,{rows:e})})]})}case`importing`:return(0,q.jsx)(P,{variant:`danger`,disabled:s.cancelling,onClick:a.cancel,children:$(`cancelImport`)});case`done`:return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(P,{onClick:r,children:$(`done`)}),a.table&&(0,q.jsx)(Ue,{to:{kind:`list`,resource:a.table},className:zn({variant:`primary`}),children:$(`openTable`)})]})}})(),children:(0,q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[a.error!==void 0&&(0,q.jsx)(Oy,{title:FX(a),error:a.error}),(()=>{switch(s.kind){case`file`:return(0,q.jsx)(KY,{file:a.file,sheets:a.sheets,sheet:a.sheet,reading:s.reading,onChoose:a.choose,onSheet:a.setSheet});case`reading`:return(0,q.jsx)(RY,{rows:s.rows});case`fields`:case`creating`:return l&&(0,q.jsx)(kX,{flow:a,problems:l,texts:o});case`importing`:return(0,q.jsx)(QY,{progress:s.progress,total:s.total,cancelling:s.cancelling});case`done`:return(0,q.jsx)($Y,{result:s.result,stopped:s.stopped,headers:u,fileName:a.file?.name})}})()]})})},LX=({model:e})=>{let{resources:t,views:n}=c(),r=re(e.name),i=re(_X),[a,o]=(0,W.useState)(!1),s=n[e.name]?.import;return s===!1||!iS(r,`create`)||s===`table`&&!iS(i,`create`)?null:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(P,{onClick:()=>o(!0),"aria-haspopup":`dialog`,children:[(0,q.jsx)(Jd,{className:`size-3.5`}),$(s===`table`?`fromFile`:`import`)]}),a&&s===`table`&&(0,q.jsx)(IX,{tables:e,resources:t,views:n,onClose:()=>o(!1)}),a&&s!==`table`&&(0,q.jsx)(pX,{model:e,resources:t,views:n,canUpdate:iS(r,`update`),onClose:()=>o(!1)})]})},RX=B(`app/export`),zX=()=>new DOMException(RX(`cancelled`),`AbortError`),BX=async({client:e,resource:t,filters:n,orderBy:r,plan:i,labels:a,limit:o,port:s,sink:c,signal:l,onProgress:u})=>{let d=i.columns.map(e=>e.name),f=0;try{await c.write(await s.send({kind:`start`,plan:i,locale:oi()}));for(let[i,p]of n.entries()){let m=``;do{let h=await e.search(t,{filter:p,orderBy:r,pageSize:500,pageToken:m,fields:d,labels:a});if(l.aborted)throw zX();let g=h.items.slice(0,o-f);if(await c.write(await s.send({kind:`page`,records:g,labels:h.labels??{}})),f+=g.length,u(f),m=h.nextPageToken,f>=o)return await VX(s,c),{rows:f,truncated:g.length<h.items.length||m!==``||i+1<n.length}}while(m!==``)}return await VX(s,c),{rows:f,truncated:!1}}catch(e){throw await c.abort(),e}finally{s.close()}},VX=async(e,t)=>{await t.write(await e.send({kind:`finish`})),await t.close()},HX=1048575,UX=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
15
+ `,WX=`http://schemas.openxmlformats.org/officeDocument/2006/relationships`,GX=`http://schemas.openxmlformats.org/package/2006/relationships`;`${UX}`,`${UX}${GX}${WX}`,`${UX}${GX}${WX}${WX}`,new TextEncoder;var KX=m(),qX=e=>e?.export!==!1,JX=e=>Object.values(e.fields).flatMap(e=>e.sensitive?[]:[e.name]),YX=(e,t)=>{let n=new Set(JX(e));return He(e,t).filter(e=>n.has(e))},XX=(e,t,n)=>Object.fromEntries(Tv(e,t,[],n).map(e=>[e.id,e.header])),ZX=(e,t,n)=>{let r=XX(e,t,n);return n.flatMap(n=>{let i=e.fields[n];return i?[{name:n,header:r[n],field:i,hints:t?.fields[n]??{}}]:[]})},QX=(e,t)=>{let n=e?.export?e.export.maxRows??1/0:1/0;return Math.min(n,t===`xlsx`?HX:1/0)},$X=e=>e.primaryKey.length===1,eZ=(e,t)=>{let[n]=e.primaryKey;if(!n||e.primaryKey.length!==1)throw Error(`Not implemented: selected rows are exported by a single-field key`);let r=[];for(let e=0;e<t.length;e+=500)r.push(vn(KX.in(n,t.slice(e,e+500))));return r},tZ=()=>{let e=new Worker(new URL(`/assets/export-worker-BGjZsI8V.js`,``+import.meta.url),{type:`module`,name:`protobase-export`}),t=[];return e.onmessage=e=>t.shift()?.resolve(e.data.bytes),e.onerror=e=>{e.preventDefault();let n=Error(RX(`couldNotBuild`,{message:e.message}));for(let e of t.splice(0))e.reject(n)},{send:n=>new Promise((r,i)=>{t.push({resolve:r,reject:i}),e.postMessage(n)}),close:()=>e.terminate()}},nZ=()=>[{value:`xlsx`,label:RX(`excel`)},{value:`csv`,label:RX(`csv`)}],rZ=()=>[{value:`shown`,label:RX(`asShown`)},{value:`raw`,label:RX(`rawValues`)}],iZ={shown:`shownHint`,raw:`rawHint`},aZ=e=>e.kind===`counting`?RX(`counting`):e.kind===`exact`||e.rows>1e4?M_(e.rows):RX(`moreThan`),oZ=e=>{if(e.kind!==`counting`)return e.kind===`exact`?e.rows:Math.max(e.rows,10001)},sZ=({label:e,help:t,children:n})=>(0,q.jsxs)(`div`,{className:`flex flex-col items-start gap-1.5`,children:[(0,q.jsx)(`span`,{className:`text-body font-medium`,children:e}),n,t&&(0,q.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:t})]}),cZ=(e,t,n)=>{let r=e.indexOf(t),i=[...e];return i.splice(r,1),i.splice(r+n,0,t),i},lZ=({fields:e,columns:t,onChange:n})=>{let r=Object.fromEntries(e.map(e=>[e.name,e.label])),i=[...t,...e.map(e=>e.name).filter(e=>!t.includes(e))];return(0,q.jsx)(`ul`,{className:`divide-y self-stretch rounded-md border`,"aria-label":RX(`columns`),children:i.map(e=>{let i=t.includes(e),a=t.indexOf(e);return(0,q.jsxs)(`li`,{className:`flex min-h-10 items-center gap-2 px-3 py-1`,children:[(0,q.jsxs)(`label`,{className:`flex min-w-0 flex-1 cursor-pointer items-center gap-2.5`,children:[(0,q.jsx)(Di,{checked:i,label:r[e],onChange:r=>n(r?[...t,e]:t.filter(t=>t!==e))}),(0,q.jsx)(`span`,{className:i?`truncate`:`truncate text-muted-foreground`,children:r[e]})]}),i&&(0,q.jsxs)(`span`,{className:`flex shrink-0 gap-1`,children:[(0,q.jsx)(P,{size:`sm`,variant:`ghost`,className:`min-h-8 px-2`,"aria-label":RX(`moveUp`,{label:r[e]}),disabled:a===0,onClick:()=>n(cZ(t,e,-1)),children:(0,q.jsx)(Hs,{className:`size-3.5`})}),(0,q.jsx)(P,{size:`sm`,variant:`ghost`,className:`min-h-8 px-2`,"aria-label":RX(`moveDown`,{label:r[e]}),disabled:a===t.length-1,onClick:()=>n(cZ(t,e,1)),children:(0,q.jsx)(As,{className:`size-3.5`})})]})]},e)})})},uZ=({plural:e,view:t,fields:n,initialColumns:r,count:i,selected:a,open:o,onExport:s,onClose:c})=>{let[l,u]=(0,W.useState)(`xlsx`),[d,f]=(0,W.useState)(a?`selected`:`list`),[p,m]=(0,W.useState)(r),[h,g]=(0,W.useState)(`shown`),_=QX(t,l),v=d===`selected`?RX(`selectedRows`,{count:k_(a??0),rows:a??0}):aZ(i),y=(d===`selected`?a??0:oZ(i)??0)>_,b=[{value:`list`,label:RX(`rowsInList`)},{value:`selected`,label:RX(`selected`,{count:k_(a??0)})}];return(0,q.jsx)(g_,{title:RX(`exportPlural`,{plural:e}),open:o,onClose:c,actions:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(P,{onClick:c,children:RX(`cancel`)}),(0,q.jsx)(P,{variant:`primary`,disabled:p.length===0,onClick:()=>s({format:l,scope:d,columns:p,mode:h}),children:RX(`export`)})]}),children:(0,q.jsxs)(`div`,{className:`flex flex-col gap-4 text-body`,children:[(0,q.jsx)(sZ,{label:RX(`format`),children:(0,q.jsx)(Av,{size:`md`,label:RX(`format`),value:l,options:nZ(),onChange:u})}),a!==void 0&&a>0&&(0,q.jsx)(sZ,{label:RX(`rows`),help:d===`list`?RX(`listHint`):void 0,children:(0,q.jsx)(Av,{size:`md`,label:RX(`rows`),value:d,options:b,onChange:f})}),(0,q.jsx)(sZ,{label:RX(`values`),help:RX(iZ[h]),children:(0,q.jsx)(Av,{size:`md`,label:RX(`values`),value:h,options:rZ(),onChange:g})}),(0,q.jsx)(sZ,{label:RX(`columns`),children:(0,q.jsx)(lZ,{fields:n,columns:p,onChange:m})}),(0,q.jsxs)(`p`,{role:`status`,className:`text-muted-foreground`,children:[RX(`exports`,{rows:v}),y&&RX(`overLimit`,{limit:k_(_)})]})]})})},dZ=({plural:e,done:t,total:n,onCancel:r})=>{let i=n?Math.min(1,t/n):void 0;return(0,q.jsx)(g_,{title:RX(`exporting`,{plural:e}),open:!0,onClose:r,actions:(0,q.jsx)(P,{onClick:r,children:RX(`cancel`)}),children:(0,q.jsxs)(`div`,{className:`flex flex-col gap-2 text-body`,children:[(0,q.jsx)(`div`,{role:`progressbar`,"aria-label":RX(`rowsExported`),"aria-valuemin":0,"aria-valuemax":n,"aria-valuenow":t,className:`h-1.5 overflow-hidden rounded-full bg-muted`,children:(0,q.jsx)(`div`,{className:`h-full rounded-full bg-primary transition-[width]`,style:{width:`${(i??0)*100}%`}})}),(0,q.jsx)(`p`,{className:`text-muted-foreground`,children:n?RX(`doneOf`,{done:k_(t),total:k_(n)}):RX(`done`,{done:k_(t)})})]})})},fZ={xlsx:{mime:`application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`,extension:`.xlsx`,description:`workbook`},csv:{mime:`text/csv`,extension:`.csv`,description:`csvFile`}},pZ=/[\\/:*?"<>|\u0000-\u001f]/g,mZ=(e,t,n=new Date)=>{let r=[n.getFullYear(),String(n.getMonth()+1).padStart(2,`0`),String(n.getDate()).padStart(2,`0`)].join(`-`);return`${e.replace(pZ,` `).trim()} ${r}${fZ[t].extension}`},hZ=8e6,gZ=(e,t)=>{let n=new Blob([],{type:fZ[t].mime}),r=[],i=0,a=()=>{n=new Blob([n,...r],{type:fZ[t].mime}),r=[],i=0};return{write:async e=>{e.length!==0&&(r.push(e),i+=e.length,i>=hZ&&a())},close:async()=>{a();let t=URL.createObjectURL(n),r=document.createElement(`a`);r.href=t,r.download=e,r.click(),setTimeout(()=>URL.revokeObjectURL(t),6e4)},abort:async()=>{r=[],n=new Blob([])}}},_Z=()=>globalThis.showSaveFilePicker,vZ=()=>typeof _Z()==`function`,yZ=async(e,t)=>{let n=_Z();if(!n)throw Error(`This browser cannot save a file as it is built`);let r=fZ[t],i;try{i=await n({suggestedName:e,types:[{description:RX(r.description),accept:{[r.mime]:[r.extension]}}]})}catch(e){if(e instanceof DOMException&&e.name===`AbortError`)return;throw e}let a=await i.createWritable();return{write:async e=>{e.length>0&&await a.write(e)},close:()=>a.close(),abort:()=>a.abort()}},bZ=(e,t)=>vZ()?yZ(e,t):Promise.resolve(gZ(e,t)),xZ=(e,t)=>{let n=t[e.primaryKey[0]];return typeof n==`object`&&n&&`id`in n?n.id:n},SZ=({model:e,view:t,resources:n,views:r,plural:i,filter:a,orderBy:o,createPort:s=tZ,createSink:c=bZ})=>{let l=F(),u=nS(),[d,f]=(0,W.useState)({kind:`closed`}),p=(0,W.useRef)(void 0),m=(0,W.useRef)(void 0),h=Tt({queryKey:I.exportCount(e.name,a),enabled:d.kind===`settings`,queryFn:async()=>{let t=await l.list(e.name,{filter:a||void 0,pageSize:1,count:`exact`,fields:e.primaryKey});return t.totalSize===void 0?{kind:`estimate`,rows:t.totalSizeEstimate}:{kind:`exact`,rows:t.totalSize}}}).data??{kind:`counting`},g=(e,t=m.current)=>{let n=m.current;n&&n===t&&(m.current=void 0,n.settle(e?[]:n.rows))},_=(t=[])=>(g(!1),f({kind:`settings`,selected:$X(e)?t.map(t=>xZ(e,t)):[]}),new Promise(e=>{m.current={rows:t,settle:e}})),v=()=>{f({kind:`closed`}),g(!1)},y=async(d,_)=>{let v=mZ(i,d.format),y=await c(v,d.format);if(!y)return;let b=m.current,x=QX(t,d.format),S=d.scope===`selected`?_.length:oZ(h),C=S===void 0?void 0:Math.min(S,x),w=new AbortController;p.current=w,f({kind:`running`,done:0,total:C});try{let c=await BX({client:l,resource:e.name,filters:d.scope===`selected`?eZ(e,_):[a],orderBy:o,plan:{format:d.format,mode:d.mode,name:i,columns:ZX(e,t,d.columns)},labels:d.mode===`shown`?ab(n,r,e,d.columns):{},limit:x,port:s(),sink:y,signal:w.signal,onProgress:e=>w.signal.aborted||f({kind:`running`,done:e,total:C})});u.show({state:`success`,title:RX(`exported`,{count:k_(c.rows),plural:i}),description:c.truncated?RX(`truncated`,{name:v,count:k_(c.rows)}):v}),g(!0,b)}catch(e){if(e instanceof DOMException&&e.name===`AbortError`)return;if(!Tn(e))throw e;u.show({state:`error`,title:RX(`couldNotExport`,{plural:i}),description:e.message})}finally{p.current=void 0,f(e=>e.kind===`running`?{kind:`closed`}:e),g(!1,b)}},b=()=>{p.current?.abort(),v()},x=JX(e),S=XX(e,t,x);return{open:_,dialogs:d.kind===`settings`?(0,q.jsx)(uZ,{plural:i,view:t,fields:x.map(e=>({name:e,label:S[e]})),initialColumns:YX(e,t),count:h,selected:d.selected.length>0?d.selected.length:void 0,open:!0,onExport:e=>void y(e,d.selected),onClose:v}):d.kind===`running`?(0,q.jsx)(dZ,{plural:i,done:d.done,total:d.total,onCancel:b}):null}},CZ=({state:e,onClearSearch:t,onClearFilters:n,create:r})=>(0,q.jsxs)(`div`,{className:`flex flex-col items-center gap-3 py-8 text-center text-muted-foreground`,children:[(0,q.jsx)(`p`,{children:e.message}),(e.clearSearch||e.clearFilters||e.create&&r)&&(0,q.jsxs)(`div`,{className:`flex flex-wrap justify-center gap-2`,children:[e.clearSearch&&(0,q.jsx)(P,{onClick:t,children:ST(`clearSearch`)}),e.clearFilters&&(0,q.jsx)(P,{onClick:n,children:ST(`clearFilters`)}),e.create&&r]})]}),wZ=({plural:e,search:t,filtered:n,scoped:r,canCreate:i})=>t?{message:ST(`noMatchSearch`,{plural:e,search:t}),clearSearch:!0,clearFilters:n,create:!1}:n?{message:ST(`noMatchFilters`,{plural:e}),clearSearch:!1,clearFilters:!0,create:!1}:r?{message:ST(`noMatch`,{plural:e}),clearSearch:!1,clearFilters:!1,create:!1}:{message:ST(`noneYet`,{plural:e}),clearSearch:!1,clearFilters:!1,create:i},TZ=(e,t)=>{},EZ=({windowMs:e=1e3,comebacks:t=2,onHold:n=TZ}={})=>{let r,i=[],a;return(o,s)=>{if(a?.among.has(o))return a.value;if(a&&(a=void 0,i=[]),o===r||(r=o,i=i.filter(t=>s-t.at<=e),i.push({value:o,at:s,comeback:i.some(e=>e.value===o)}),i.filter(e=>e.comeback).length<t))return o;let c=new Set(i.slice(-2*t).map(e=>e.value));return a={value:Math.min(...c),among:c},n(a.value,[...c]),a.value}},DZ=e=>Math.max(1,Math.floor((e+12)/252)),OZ=(e,t)=>Math.max(0,(e-(t-1)*12)/t),kZ=(e,t,n,r)=>({start:e*n,end:Math.max(0,Math.min(r,(t+1)*n)-1)}),AZ=(e,t,n)=>{let r=e/t.rowHeight;return t.columns===n.columns?r*n.rowHeight:Math.floor(Math.floor(r)*t.columns/n.columns)*n.rowHeight},jZ=(e,t)=>{let n=e/t.rowHeight;return Math.floor(n)*t.columns+n%1},MZ=(e,t)=>Math.floor(Math.floor(e)/t)+e%1,NZ=8,PZ=(e,t,n)=>{let r=e.get(t);if(r!==void 0&&r>=n)return e;let i=new Map(e);i.delete(t),i.set(t,n);for(let e of i.keys()){if(i.size<=NZ)break;i.delete(e)}return i},FZ=({source:e,label:t,initialIndex:n,onScrollIndex:r,minHeight:i,children:a})=>{let{total:o}=e,[s]=(0,W.useState)(n),[c,l]=(0,W.useState)(0),u=DZ(c),d=OZ(c,u),[f,p]=(0,W.useState)(()=>new Map),m=Math.ceil(Math.max(i(d),f.get(d)??0)),h=m+12,g={columns:u,rowHeight:h},_=(0,W.useRef)({layout:g,top:0}),v=_.current.top>0&&(_.current.layout.columns!==u||_.current.layout.rowHeight!==h),y=e=>v?AZ(_.current.top,_.current.layout,g):e,b=d>0&&f.has(d),x=JN({total:Math.ceil(o/u),rowHeight:h,initialIndex:MZ(s,u),settle:y,ready:b,onScroll:e=>r(jZ(e,g))});(0,W.useLayoutEffect)(()=>{v&&x.scrollTo(x.top),_.current={layout:g,top:x.started()?x.top:0}});let S=kZ(x.first,x.last,u,o),C=PN({total:o,rowAt:e.rowAt,loadRows:e.loadRows,revision:e.revision,latencyMs:0},S.start,S.end),[w]=(0,W.useState)(()=>EZ());(0,W.useLayoutEffect)(()=>{let e=x.ref.current;if(!e)return;let t=()=>l(w(e.clientWidth,performance.now())),n=new ResizeObserver(t);return n.observe(e),t(),()=>n.disconnect()},[w]);let T=(0,W.useRef)(d);T.current=d;let[E]=(0,W.useState)(()=>new ResizeObserver(e=>{let t=Math.max(...e.map(e=>e.borderBoxSize[0]?.blockSize??e.contentRect.height)),n=T.current;p(e=>PZ(e,n,t))}));(0,W.useLayoutEffect)(()=>()=>E.disconnect(),[E]),(0,W.useLayoutEffect)(()=>{let e=x.ref.current;if(b||d===0||!e)return;let t=[...e.querySelectorAll(`:scope > li[aria-posinset]`)];if(t.length===0)return;let n=Math.max(...t.map(e=>e.getBoundingClientRect().height));p(e=>PZ(e,d,n))});let D=(0,W.useCallback)(e=>{if(e)return E.observe(e),()=>E.unobserve(e)},[E]);return(0,q.jsx)(`ul`,{ref:x.ref,className:`relative min-w-0 flex-auto`,"aria-label":t,style:{height:x.geometry.contentHeight},children:x.rows.flatMap(({index:e,offset:t})=>Array.from({length:u},(n,r)=>{let i=e*u+r;if(i>=o)return[];let s=C(i),c={top:t,left:r*(d+12),width:d,minHeight:m};return s?(0,q.jsx)(`li`,{ref:D,"aria-posinset":i+1,"aria-setsize":o,className:`absolute grid grid-cols-[minmax(0,1fr)]`,style:c,children:a(s)},s.id):(0,q.jsx)(`li`,{"aria-hidden":!0,className:`absolute grid grid-cols-[minmax(0,1fr)]`,style:c,children:(0,q.jsx)(L,{className:`h-full rounded-lg`})},`skeleton-${i}`)}))})},IZ=`grid grid-cols-[repeat(auto-fill,minmax(15rem,1fr))] gap-3`,LZ=e=>e*.75,RZ=44,zZ=({model:e,view:t,display:n,list:r,empty:i})=>{let a=t?.names?.plural??H(e.name),o=n.card===void 0&&(n.image!==void 0||n.photos!==void 0);return r.isLoading?(0,q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-hidden ${IZ}`,children:Array.from({length:6},(e,t)=>(0,q.jsx)(L,{className:`h-24`},t))}):r.error?(0,q.jsx)(Oy,{title:N(`couldNotLoadRows`),error:r.error}):!r.source||r.source.total===0?i??(0,q.jsx)(`p`,{className:`py-8 text-center text-muted-foreground`,children:N(`noneMatch`,{plural:a.toLowerCase()})}):(0,q.jsx)(FZ,{source:r.source,label:a,initialIndex:r.initialIndex,onScrollIndex:r.onScrollIndex,minHeight:e=>(o?LZ(e):0)+RZ,children:r=>(0,q.jsx)(zI,{model:e,view:t,display:n,row:Ie(e,r)})})},BZ=`protobase:list-places`,VZ=50,HZ=(e,t)=>`${e} ${t}`,UZ=e=>{if(typeof e!=`object`||!e)return!1;let{entry:t,url:n,place:r}=e;return typeof t==`string`&&typeof n==`string`&&typeof r==`number`&&Number.isFinite(r)&&r>=0},WZ=e=>i(()=>{let t=e.getItem(BZ);if(t===null)return[];let n=JSON.parse(t);return Array.isArray(n)?n.filter(UZ):[]},[]),GZ=e=>{let t=new Map(WZ(e).map(e=>[HZ(e.entry,e.url),e]));return{placeOf:(e,n)=>{let r=t.get(HZ(e,n));return r?r.place:[...t.values()].findLast(e=>e.url===n)?.place??0},save:(e,n,r)=>{let i=HZ(e,n);t.delete(i),t.set(i,{entry:e,url:n,place:r});for(let e of[...t.keys()].slice(0,Math.max(0,t.size-VZ)))t.delete(e)},persist:()=>i(()=>e.setItem(BZ,JSON.stringify([...t.values()])),void 0)}},KZ={getItem:()=>null,setItem:()=>{}},qZ,JZ=()=>qZ??=GZ(i(()=>window.sessionStorage,void 0)??KZ),YZ=()=>{let{entry:e,path:t,params:n}=le(),r=`${t}?${n.toString()}`,i=JZ();(0,W.useEffect)(()=>{let e=()=>i.persist(),t=()=>document.visibilityState===`hidden`&&i.persist();return window.addEventListener(`pagehide`,e),document.addEventListener(`visibilitychange`,t),()=>{window.removeEventListener(`pagehide`,e),document.removeEventListener(`visibilitychange`,t),i.persist()}},[i]);let a=(0,W.useCallback)(t=>i.save(e,r,t),[i,e,r]);return{initialIndex:i.placeOf(e,r),remember:a}},XZ=e=>e.reduce((e,t)=>e+t.count,0),ZZ=e=>{let t=Math.floor(e.length/2),n=XZ(e.slice(0,t)),r=XZ(e.slice(e.length-t));return n===0?0:(r-n)/n*100},QZ=B(`activity-chart`),$Z=({title:e,defaultGranularity:t=`day`,data:n,granularity:r,onGranularityChange:i,periodLabel:a,className:o})=>{let[s,c]=(0,W.useState)(t),l=r??s,u=i??c,d=ZZ(n),f=n.map(({at:e,count:t})=>({at:e,value:t,count:t}));return(0,q.jsxs)(`section`,{className:U(`rounded-lg border bg-background px-4 pb-2 pt-3`,o),children:[(0,q.jsxs)(`header`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,q.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,q.jsx)(`h2`,{className:`font-semibold`,children:e}),(0,q.jsx)(`span`,{className:`font-semibold tabular-nums`,children:k_(XZ(n))}),(0,q.jsxs)(`span`,{className:U(`text-xs font-medium tabular-nums`,d>=0?`text-success-text`:`text-danger-text`),children:[d>=0?`+`:`−`,Math.abs(d).toFixed(1),`%`]}),(0,q.jsx)(`span`,{className:`hidden text-xs text-muted-foreground sm:inline`,children:a??`last ${l===`day`?`30 days`:`12 weeks`}`})]}),(0,q.jsx)(Av,{value:l,onChange:u,options:[{value:`day`,label:QZ(`day`)},{value:`week`,label:QZ(`week`)}]})]}),(0,q.jsx)(`div`,{className:`mt-2`,children:(0,q.jsx)(pD,{points:f,measure:{kind:`count`},bucket:l,type:`bar`,compact:!0})})]})},eQ={"7d":`last 7 days`,"30d":`last 30 days`,"90d":`last 90 days`,"1y":`last year`,all:`all time`},tQ=({resource:e,chart:t,title:n,filter:r})=>{let[i,a]=(0,W.useState)(t.granularity===`week`?`week`:`day`),o=i===`week`?`90d`:t.range,s=xE(e,{field:t.field,range:o,granularity:i,filter:r,timeZone:Hn()}).data?.points.map(e=>({at:Date.parse(`${e.bucket}Z`),count:e.count}))??[];return(0,q.jsx)($Z,{title:n,data:s,granularity:i,onGranularityChange:a,periodLabel:i===`week`?`last 12 weeks`:eQ[o]})},nQ=(e,t,n)=>{let r=e.sum??e.average;if(r===void 0)return n;let i=t?.fields[r]?.label??H(r);return e.sum===void 0?R(`average`,{label:i}):`${i}`},rQ=({model:e,view:t,chart:n,plural:r,filter:i})=>{let a=t?.fields[n.groupBy]?.label??H(n.groupBy);return(0,q.jsxs)(`section`,{className:`rounded-lg border bg-background px-4 pb-3 pt-3`,"aria-label":`${nQ(n,t,r)} by ${a.toLowerCase()}`,children:[(0,q.jsxs)(`h2`,{className:`mb-2 font-semibold`,children:[nQ(n,t,r),` by `,a.toLowerCase()]}),(0,q.jsx)(_D,{model:e,view:t,groupBy:n.groupBy,type:n.type,sum:n.sum,average:n.average,limit:n.limit,filter:i})]})},iQ=({value:e,onCommit:t,placeholder:n,className:r})=>{let[i,a]=(0,W.useState)(e);return(0,W.useEffect)(()=>a(e),[e]),(0,W.useEffect)(()=>{if(i===e)return;let n=setTimeout(()=>t(i),350);return()=>clearTimeout(n)},[i,e,t]),(0,q.jsx)(bi,{wrapperClassName:U(`min-w-0 flex-1 sm:w-72 sm:flex-initial`,r),leading:(0,q.jsx)(id,{className:`size-4`}),placeholder:n,"aria-label":ST(`search`),value:i,onChange:e=>a(e.target.value),onKeyDown:e=>e.key===`Enter`&&t(i)})},aQ=e=>new Set((e.userMenu?.items??[]).flatMap(e=>e.kind===`resource`?[e.resource]:e.kind===`page`?[e.page]:[])),oQ=(e,t,n)=>(e.userMenu?.items??[]).map((r,i)=>{if(r.kind===`link`)return{id:`link-${i}`,label:r.label,icon:Vq(r.icon,ol),href:r.href,external:!0};if(r.kind===`page`){let i=e.pages[r.page];return{id:r.page,label:r.label??i?.title??H(r.page),icon:Vq(r.icon??i?.icon,Bl),href:We({kind:`page`,page:r.page},t),active:r.page===n}}return{id:r.resource,label:r.label??e.views[r.resource]?.names?.plural??H(r.resource),icon:Vq(r.icon,Hq(e,r.resource)),href:We({kind:`list`,resource:r.resource},t),active:r.resource===n}}),sQ=(e,t)=>t===void 0?e:`${e}/${t}`,cQ={sales:`sales`,crm:`crm`,catalog:`catalog`,inventory:`inventory`,core:`admin`,hr:`hr`,table_definitions:`tables`,user_tables:`tables`},lQ=(e=`public`)=>e===`public`?``:cQ[e]?R(cQ[e]):H(e),uQ=(e,t,n,r,i)=>!n?.create||!NJ(t,e.pages,e.permissions[t.resource]??ae)?{}:{create:{label:n.create===!0?hy(`title`,{noun:r}):n.create.label,href:We({kind:`create`,resource:t.resource},i)}},dQ=(e,t=``,n={})=>{let r=new Map,i=new Map,a=aQ(e);for(let n of Object.values(e.pages)){if(n.nav?.hidden||a.has(n.name))continue;let e=n.nav?.group??R(`pages`),o=r.get(e)??{label:e,items:[]};o.items.push({id:n.name,label:n.title,icon:Vq(n.icon,Bl),href:We({kind:`page`,page:n.name},t)}),r.set(e,o),i.set(n.name,n.nav?.order??2**53-1)}for(let o of Object.values(e.resources)){let s=e.views[o.name];if(!s||a.has(o.name))continue;let c=s.nav?.group??lQ(o.table.schema),l=(e,t,n)=>{let a=r.get(e)??{label:e,items:[]};a.items.push(t),r.set(e,a),i.set(t.id,n??2**53-1)},u=!s.nav?.creatorsOnly||NJ(s,e.pages,e.permissions[s.resource]??ae);!s.nav?.hidden&&u&&l(c,{id:sQ(o.name),label:s.names?.plural??H(o.name),icon:Hq(e,o.name),href:We({kind:`list`,resource:o.name},t),...n[o.name]&&{recent:n[o.name]},...uQ(e,s,s.nav,s.names?.singular??H(o.name),t)},s.nav?.order);for(let n of s.lists??[])n.nav?.hidden||l(n.nav?.group??c,{id:sQ(o.name,n.name),label:n.names.plural,icon:Hq(e,o.name),href:We({kind:`list`,resource:o.name,list:n.name},t),...uQ(e,s,n.nav,n.names.singular,t)},n.nav?.order)}for(let n of Object.values(e.signIn??{})){if(n.nav?.hidden||a.has(n.resource))continue;let o=n.nav?.group??R(`account`),s=r.get(o)??{label:o,items:[]};s.items.push({id:n.resource,label:n.names?.plural??H(n.resource),icon:Hq(e,n.resource),href:We({kind:`list`,resource:n.resource},t)}),r.set(o,s),i.set(n.resource,n.nav?.order??2**53-1)}for(let n of e.sources??[]){if(n.state!==`error`)continue;let e=r.get(n.source.label)??{label:n.source.label,items:[]};for(let r of n.source.resources)e.items.push({id:r,label:H(r),icon:Pd,href:We({kind:`list`,resource:r},t),problem:R(`cannotReach`,{label:n.source.label})});r.set(n.source.label,e)}return[...r.values()].map(e=>({...e,items:[...e.items].sort((e,t)=>(i.get(e.id)??0)-(i.get(t.id)??0))}))},fQ=(e,t,n,r,i)=>{let a=n?.list?.relatedColumns??[];if(a.length===0)return e;let o=new Map(e.map(e=>[e.id,e]));return He(t,n).flatMap(e=>{let t=o.get(e);if(t)return[t];let n=a.find(t=>t.name===e),s=n&&r[n.resource];if(!n||!s)return[];let c=n.label??H(n.name);return[{id:n.name,header:c,kind:`text`,width:160,minWidth:R_(c,!1),sortable:!1,render:e=>(0,q.jsx)(vI,{column:n,records:e[n.name]??[],target:s,view:i[s.name],Card:zI})}]})},pQ=({model:e,view:t,target:n,children:r})=>{let i=tI(e.name,t.listOf,!0),a=t.names?.plural??H(e.name),o=e=>(0,q.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 px-5 py-4`,children:[(0,q.jsx)(Rj,{title:a,subtitle:t.help}),e]});if(i.error)return o((0,q.jsx)(Oy,{title:nI(`couldNotLoadYour`,{plural:a.toLowerCase()}),error:i.error}));if(!i.data)return o((0,q.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(15rem,1fr))] gap-3`,children:Array.from({length:3},(e,t)=>(0,q.jsx)(L,{className:`h-24`},t))}));let s=$F(n,i.data);return s?r(s):o((0,q.jsx)(`p`,{className:`py-8 text-center text-muted-foreground`,children:nI(`noneYet`,{plural:a.toLowerCase()})}))},mQ=({title:e,chips:t,label:n,required:r,initial:i=``,busy:a,onSave:o,onClose:s})=>{let c=(0,W.useId)(),[l,u]=(0,W.useState)(i),d=`${c}-form`;return(0,q.jsx)(g_,{open:!0,title:e,onClose:s,actions:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(P,{onClick:s,children:hP(`cancel`)}),(0,q.jsx)(P,{type:`submit`,form:d,variant:`primary`,loading:a,children:hP(`save`)})]}),children:(0,q.jsxs)(`form`,{id:d,className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),o(l.trim()===``?null:l.trim())},children:[t.length>0&&(0,q.jsx)(_P,{chips:t}),(0,q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,q.jsxs)(`div`,{className:`flex items-baseline justify-between gap-2`,children:[(0,q.jsx)(`label`,{htmlFor:c,className:`font-medium`,children:n}),!r&&(0,q.jsx)(`span`,{id:`${c}-hint`,className:`text-xs text-muted-foreground`,children:hP(`optional`)})]}),(0,q.jsx)(bi,{id:c,value:l,required:r,pattern:r?`.*\\S.*`:void 0,"aria-describedby":r?void 0:`${c}-hint`,autoFocus:!0,autoComplete:`off`,onChange:e=>u(e.target.value)})]})]})})},hQ=m(),gQ={start:0,end:0},_Q=(e,t)=>hQ.and(t,{kind:`present`,field:e.field,span:gQ}),vQ=e=>{switch(e.kind){case`and`:case`or`:return{...e,args:e.args.map(vQ)};case`not`:return yQ(e.arg);case`search`:case`present`:case`isNull`:case`related`:return e;default:return _Q(e,e)}},yQ=e=>{switch(e.kind){case`and`:return hQ.or(...e.args.map(yQ));case`or`:return hQ.and(...e.args.map(yQ));case`not`:return vQ(e.arg);case`search`:case`present`:case`isNull`:case`related`:return hQ.not(e);default:return _Q(e,hQ.not(e))}},bQ=e=>{let t=Te(e);if(!t.ok)throw Error(`The filter cannot be read: ${t.errors.map(e=>e.message).join(`; `)}`);return t.ast},xQ=e=>e.kind===`and`||e.kind===`or`?e.args.some(xQ):e.kind===`not`?xQ(e.arg):e.kind===`related`,SQ=(e,t)=>![bQ(e),bQ(t)].some(e=>e&&xQ(e)),CQ=(e,t)=>{let n=bQ(e);if(!n)return null;let r=bQ(t),i=hQ.not(vQ(n));return vn(r?hQ.and(r,i):i)},wQ=(e,t)=>CQ(t,e),TQ=e=>e.key.startsWith(`extra:`)?`extra:${e.label}`:e.key,EQ=(e,t)=>{let n=new Map(e.map(e=>[TQ(e),e])),r=new Map(t.map(e=>[TQ(e),e])),i=e.filter(e=>!r.has(TQ(e))).map(e=>({kind:`removed`,label:e.label})),a=t.flatMap(e=>{let t=n.get(TQ(e));return t&&t.label!==e.label?[{kind:`changed`,label:e.label,before:t.label}]:[]}),o=t.filter(e=>!n.has(TQ(e))).map(e=>({kind:`added`,label:e.label}));return[...i,...a,...o]},DQ=(e,t,n,r)=>{let i=e-t;if(i===0)return hP(`asMany`,{plural:r});let a=Math.abs(i)===1?n:r;return i>0?hP(`more`,{count:i,noun:a}):hP(`fewer`,{count:-i,noun:a})},OQ=12,kQ={added:{word:`added`,className:`text-success-text`},removed:{word:`removed`,className:`text-danger-text`},changed:{word:`changed`,className:`text-primary-text`}},AQ=({changes:e})=>(0,q.jsx)(`ul`,{"aria-label":hP(`filterChanges`),className:`divide-y rounded-md border`,children:e.map(e=>(0,q.jsxs)(`li`,{className:`grid grid-cols-[72px_1fr] gap-3 px-3 py-2`,children:[(0,q.jsx)(`span`,{className:`font-medium ${kQ[e.kind].className}`,children:hP(kQ[e.kind].word)}),e.kind===`changed`?(0,q.jsxs)(`span`,{children:[(0,q.jsx)(`span`,{className:`text-muted-foreground line-through`,children:e.before}),` `,(0,q.jsx)(`span`,{className:`font-medium`,children:e.label})]}):(0,q.jsx)(`span`,{className:e.kind===`removed`?`text-muted-foreground line-through`:`font-medium`,children:e.label})]},`${e.kind}:${e.label}`))}),jQ=(e,t)=>{let n=Tt({...ti(F(),e,t??``),enabled:t!==null});return t===null?0:n.data},MQ=(e,t,n)=>`${e} ${e===1?t:n}`,NQ=({model:e,view:t,title:n,filter:r,total:i,plural:a})=>{let o=t?.list?.displays?.find(e=>e.kind===`cards`);return(0,q.jsxs)(`section`,{"aria-label":n,className:`flex flex-col gap-2`,children:[(0,q.jsxs)(`h3`,{className:`font-semibold`,children:[n,` `,(0,q.jsxs)(`span`,{className:`font-normal text-muted-foreground`,children:[`(`,i??`…`,`)`]})]}),i!==void 0&&i>OQ&&(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:hP(`firstOf`,{limit:OQ,total:i})}),r===null||i===0?(0,q.jsx)(`p`,{className:`text-muted-foreground`,children:hP(`noPlural`,{plural:a})}):(0,q.jsx)(wB,{model:e,view:t,filter:r,sort:Pe(e,t),limit:OQ,display:o?.name??`table`,row:!0,link:!1,empty:`No ${a}.`})]})},PQ=({model:e,view:t,before:n,after:r})=>{let i=(0,W.useMemo)(()=>CQ(n,r),[n,r]),a=(0,W.useMemo)(()=>wQ(n,r),[n,r]),o=jQ(e,i),s=jQ(e,a),c=(t?.names?.singular??H(e.name)).toLowerCase(),l=(t?.names?.plural??H(e.name)).toLowerCase();return(0,q.jsxs)(q.Fragment,{children:[o!==void 0&&s!==void 0?(0,q.jsxs)(`p`,{children:[(0,q.jsx)(`span`,{className:`font-semibold`,children:DQ(o,s,c,l)}),(0,q.jsxs)(`span`,{className:`text-muted-foreground`,children:[`: `,hP(`addedRemoved`,{added:MQ(o,c,l),removed:s})]})]}):(0,q.jsx)(L,{className:`h-4 w-48`}),(0,q.jsx)(NQ,{model:e,view:t,title:hP(`added`),filter:i,total:o,plural:l}),(0,q.jsx)(NQ,{model:e,view:t,title:hP(`removed`),filter:a,total:s,plural:l})]})},FQ=({model:e,view:t,title:n,before:r,after:i,saveNewLabel:a,updating:o,creating:s,onUpdate:c,onSaveNew:l,onCancel:u})=>{let d=EQ(LF(e,r),LF(e,i));return(0,q.jsx)(g_,{open:!0,wide:!0,title:n,onClose:u,actions:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(P,{onClick:u,children:hP(`cancel`)}),(0,q.jsx)(P,{loading:s,disabled:o,onClick:l,children:a}),(0,q.jsx)(P,{variant:`primary`,loading:o,disabled:s,onClick:c,children:hP(`update`)})]}),children:(0,q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[d.length>0&&(0,q.jsx)(AQ,{changes:d}),SQ(r,i)?(0,q.jsx)(PQ,{model:e,view:t,before:r,after:i}):(0,q.jsx)(`p`,{className:`text-muted-foreground`,children:hP(`noRecordsDiff`)})]})})},IQ=()=>{let{address:e,set:t}=Me();return{key:e?.kind===`list`?e.savedSearch:void 0,open:e=>t({savedSearch:e})}},LQ=e=>e instanceof Error?e.message:hP(`somethingWrong`),RQ=(e,t)=>{let n=c(),r=F(),i=nS(),a=qr(),{href:o,open:s}=Me(),l=IQ(),{resource:u}=e,d=n.resources[u],f=n.views[u]?.searchesOf,p=n.permissions[u],m=d!==void 0&&f!==void 0&&p!==void 0&&iS(p,`create`)&&iS(p,`delete`),h=n.signIn?.[u]?.signIn,g=$I(u,m),_=e=>Nn(xr(d,e)),v=f&&g.data?.find(e=>e[f.filter]===t),y=v||l.key===void 0||!p||!iS(p,`update`)?void 0:g.data?.find(e=>_(e)===l.key),b=n.views[u]?.names,x=b?.plural??`saved searches`,S=f?.name===void 0?void 0:d?.fields[f.name],C=en({mutationFn:e=>r.create(u,{[f.filter]:t,...f.name&&{[f.name]:e}}),onSuccess:e=>{l.open(_(e.record)),i.show({state:`success`,title:hP(`searchSaved`),action:{label:hP(`openPlural`,{plural:x}),href:o({kind:`list`,resource:u}),onNavigate:s}})},onError:e=>i.show({state:`error`,title:hP(`couldNotSave`),description:LQ(e)}),onSettled:()=>a(u)}),w=en({mutationFn:e=>r.remove(u,_(e)),onError:e=>i.show({state:`error`,title:hP(`couldNotTakeOff`),description:LQ(e)}),onSettled:()=>a(u)}),T=en({mutationFn:e=>r.update(u,_(e),{[f.filter]:t},e.etag??`*`),onSuccess:()=>i.show({state:`success`,title:hP(`searchUpdated`)}),onError:e=>i.show({state:`error`,title:hP(`couldNotUpdate`),description:LQ(e)}),onSettled:()=>a(u)}),E=C.isPending||w.isPending||T.isPending;return{mode:m?`save`:h?`sign-in`:void 0,prompt:h,saved:v!==void 0,opened:y&&{filter:String(y[f.filter]??``),name:f.name&&typeof y[f.name]==`string`&&y[f.name]!==``?String(y[f.name]):void 0},noun:(b?.singular??H(u)).toLowerCase(),naming:S&&{label:n.views[u]?.fields[S.name]?.label??H(S.name),required:!S.nullable},ready:g.data!==void 0&&!E,updating:T.isPending,creating:C.isPending,remove:()=>v&&w.mutate(v),saveNew:(e,t)=>C.mutate(e,t),update:e=>y&&T.mutate(y,e)}},zQ=({model:e,view:t,search:n,filter:r,chips:i,className:a})=>{let o=RQ(n,r),[s,c]=(0,W.useState)(!1),[l,u]=(0,W.useState)(!1),[d,f]=(0,W.useState)();if(!o.mode)return null;let p=n.label??hP(`saveSearch`);if(o.mode===`sign-in`)return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(P,{className:a,"aria-haspopup":`dialog`,onClick:()=>c(!0),children:[(0,q.jsx)(uc,{className:`size-3.5`,"aria-hidden":!0}),p]}),(0,q.jsx)(KF,{as:`dialog`,prompt:o.prompt,open:s,onClose:()=>c(!1)})]});let m=e=>{u(!1),o.naming?f(e):o.saveNew(null)},h=d!==void 0&&o.naming&&(0,q.jsx)(mQ,{title:d,chips:i,label:o.naming.label,required:o.naming.required,busy:o.creating,onSave:e=>o.saveNew(e,{onSuccess:()=>f(void 0)}),onClose:()=>f(void 0)}),g=o.opened;if(g){let n=hP(`saveAsNew`,{noun:o.noun});return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(P,{className:a,"aria-haspopup":`dialog`,"aria-disabled":!o.ready,onClick:()=>o.ready&&u(!0),children:[(0,q.jsx)(Xu,{className:`size-3.5`,"aria-hidden":!0}),(0,q.jsx)(`span`,{className:`max-w-60 truncate`,children:hP(`updateName`,{name:g.name??o.noun})})]}),(0,q.jsxs)(P,{className:a,"aria-haspopup":o.naming?`dialog`:void 0,"aria-disabled":!o.ready,onClick:()=>o.ready&&m(n),children:[(0,q.jsx)(cc,{className:`size-3.5`,"aria-hidden":!0}),n]}),l&&(0,q.jsx)(FQ,{model:e,view:t,title:g.name?hP(`updateNameQuestion`,{name:g.name}):hP(`updateNounQuestion`,{noun:o.noun}),before:g.filter,after:r,saveNewLabel:n,updating:o.updating,creating:o.creating,onUpdate:()=>o.update({onSuccess:()=>u(!1)}),onSaveNew:()=>m(n),onCancel:()=>u(!1)}),h]})}let _=o.saved?oc:uc;return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(P,{className:a,"aria-pressed":o.saved,"aria-haspopup":!o.saved&&o.naming?`dialog`:void 0,"aria-disabled":!o.ready,onClick:()=>o.ready&&(o.saved?o.remove():m(p)),children:[(0,q.jsx)(_,{className:o.saved?`size-3.5 text-primary`:`size-3.5`,"aria-hidden":!0}),p]}),h]})},BQ=e=>e instanceof Error?e.message:hP(`somethingWrong`),VQ=({model:e,view:t,name:n,value:r,onChange:i})=>{let a=(0,W.useId)(),o=e.fields[n],s=t.fields[n],c=s?.label??H(n);if(o?.type===`boolean`)return(0,q.jsx)(ky,{checked:r===!0,onChange:i,label:c});if(o?.type!==`enum`)throw Error(`Not implemented: "${n}" is ${o?.type??`unknown`}, and a saved search's controls are enums or booleans`);return(0,q.jsxs)(`label`,{htmlFor:a,className:`flex items-center gap-2 text-muted-foreground`,children:[c,(0,q.jsx)(`select`,{id:a,value:String(r??``),onChange:e=>i(e.target.value),className:`h-8 rounded-md border border-border-strong bg-background px-2 text-foreground shadow-sm focus:border-primary focus:outline-none focus:ring-2 focus:ring-primary/20`,children:(o.enumValues??[]).map(e=>(0,q.jsx)(`option`,{value:e,children:ar(e,s?.valueLabels)},e))})]})},HQ=(e,t,n)=>Object.entries(n).map(([n,r])=>`${t.fields[n]?.label??H(n)}: ${e.fields[n]?.type===`boolean`?hP(r===!0?`on`:`off`):ar(String(r),t.fields[n]?.valueLabels)}`).join(`, `),UQ=({model:e,view:t,recordKey:n,title:r,row:i,fields:a})=>{let o=F(),s=nS(),c=qr(),l=en({mutationFn:t=>o.update(e.name,n,t,i.etag??`*`),onSuccess:(n,i)=>s.show({state:`success`,title:hP(`saved`,{title:r}),description:HQ(e,t,i)}),onError:e=>s.show({state:`error`,title:hP(`couldNotChange`),description:BQ(e)}),onSettled:()=>c(e.name)});return(0,q.jsx)(`div`,{className:`flex flex-wrap items-center gap-3`,children:a.map(n=>(0,q.jsx)(VQ,{model:e,view:t,name:n,value:l.isPending&&n in(l.variables??{})?l.variables[n]:i[n],onChange:e=>l.mutate({[n]:e})},n))})},WQ=e=>e instanceof Error?e.message:hP(`somethingWrong`),GQ=({model:e,view:t,of:n,target:r,targetView:i,row:a,recordKey:o,canRename:s,onDelete:c})=>{let l=F(),u=nS(),d=qr(),[f,p]=(0,W.useState)(!1),{name:m,chips:h,title:g,body:_}=eL({model:e,of:n,target:r,targetView:i,row:a,recordKey:o}),v=en({mutationFn:t=>l.update(e.name,o,{[n.name]:t},a.etag??`*`),onSuccess:()=>p(!1),onError:e=>u.show({state:`error`,title:hP(`couldNotRename`),description:WQ(e)}),onSettled:()=>d(e.name)}),y=n.name===void 0?void 0:e.fields[n.name];return(0,q.jsxs)(`section`,{"aria-label":g,className:`flex flex-col gap-3 rounded-lg border bg-surface p-4`,children:[(0,q.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,q.jsx)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:(0,q.jsx)(`h2`,{className:`text-base font-semibold`,children:(0,q.jsx)(Ue,{to:{kind:`record`,resource:e.name,key:o},className:`hover:underline`,children:m??(0,q.jsx)(vP,{chips:h})})})}),(0,q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[n.controls&&(0,q.jsx)(UQ,{model:e,view:t,recordKey:o,title:g,row:a,fields:n.controls}),s&&y&&(0,q.jsx)(P,{variant:`ghost`,"aria-label":hP(`renameTitle`,{title:g}),"aria-haspopup":`dialog`,onClick:()=>p(!0),children:(0,q.jsx)(Au,{className:`size-3.5`,"aria-hidden":!0})}),c&&(0,q.jsx)(P,{variant:`ghost`,"aria-label":hP(`deleteTitle`,{title:g}),onClick:()=>c(g),children:(0,q.jsx)(Wd,{className:`size-3.5`,"aria-hidden":!0})})]})]}),f&&y&&(0,q.jsx)(mQ,{title:hP(`renameTitle`,{title:g}),chips:h,label:t.fields[y.name]?.label??H(y.name),required:!y.nullable,initial:m,busy:v.isPending,onSave:e=>v.mutate(e),onClose:()=>p(!1)}),(0,q.jsx)(XI,{..._})]})},KQ=({model:e,view:t})=>{let{resources:n,views:r}=c(),i=t.searchesOf,a=n[i.resource],o=r[i.resource],s=$I(e.name,!0),l=re(e.name),u=jJ({model:e,view:t}),d=t.names?.plural??H(e.name),f=e=>(0,q.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 px-5 py-4`,children:[u.dialogs,(0,q.jsx)(Rj,{title:d,subtitle:t.help}),e]});if(!a)return f((0,q.jsx)(tt,{title:hP(`notFound`),children:hP.rich(`noResource`,{resource:i.resource})}));if(s.error)return f((0,q.jsx)(Oy,{title:hP(`couldNotLoadYour`,{plural:d.toLowerCase()}),error:s.error}));if(!s.data)return f((0,q.jsx)(`div`,{className:`flex flex-col gap-3`,children:Array.from({length:2},(e,t)=>(0,q.jsx)(L,{className:`h-56`},t))}));if(s.data.length===0){let e=(o?.names?.plural??H(a.name)).toLowerCase();return f((0,q.jsx)(`p`,{className:`py-8 text-center text-muted-foreground`,children:hP.rich(`noSavedYet`,{plural:d.toLowerCase(),list:(0,q.jsx)(Ue,{to:{kind:`list`,resource:a.name},className:`font-medium text-primary-text hover:underline`,children:e})})}))}return f((0,q.jsx)(`div`,{className:`flex flex-col gap-4`,children:s.data.map(n=>{let r=Nn(xr(e,n)),s=iS(l,`delete`)?e=>void u.start({key:r,title:e,etag:n.etag,snapshot:n}):void 0;return(0,q.jsx)(GQ,{model:e,view:t,of:i,target:a,targetView:o,row:n,recordKey:r,canRename:iS(l,`update`),onDelete:s},r)})}))},qQ=({field:e,hints:t,resource:n,stored:r,onSave:i,close:a})=>{let[o,s]=(0,W.useState)(()=>ly(e,r)),c=(0,W.useRef)(null),l=(0,W.useRef)(!1),u=!t?.widget&&(e.type===`boolean`||e.type===`enum`);(0,W.useEffect)(()=>{c.current?.querySelector(`input, select, textarea, button, [tabindex]`)?.focus()},[]);let d=(t,n,s=o)=>{l.current||(l.current=!0,t&&uy(e,s,r)&&i(sy(e,s)),a(n))};return(0,q.jsx)(`div`,{ref:c,className:`w-full min-w-0`,onKeyDown:e=>{BC(e.target)||(e.key===`Enter`?(e.preventDefault(),d(!0)):e.key===`Tab`?(e.preventDefault(),d(!0,e.shiftKey?-1:1)):e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),d(!1)))},onBlur:e=>{!c.current?.contains(e.relatedTarget)&&!BC(e.relatedTarget)&&d(!0)},children:(0,q.jsx)(GC,{field:e,hints:t,value:o,stored:r,resource:n,onChange:e=>{s(e),u&&d(!0,void 0,e)}})})},JQ=B(`app/list-edit`),YQ=e=>{let t=F(),n=nn(),r=nS(),[i,a]=(0,W.useState)(new Map),o=(0,W.useRef)(i),s=(0,W.useRef)(new Map),c=(e,t)=>{o.current=new Map(o.current).set(e,{...o.current.get(e),...t}),a(o.current)},l=async(i,a,s)=>{let l=xr(e,i),u=String(o.current.get(i.id)?.etag??i.etag);try{let r=await t.update(e.name,l,{[a]:s},u);c(i.id,{[a]:r.record[a],etag:r.etag}),n.setQueryData(I.record(e.name,Nn(l)),r),n.invalidateQueries({queryKey:[`page`,e.name]}),n.invalidateQueries({queryKey:[`list`,e.name]}),n.invalidateQueries({queryKey:[`map`,e.name]}),n.invalidateQueries({queryKey:[`count`,e.name]})}catch(n){if(!Tn(n))throw c(i.id,{[a]:i[a]}),n;let o=n.status===412,s=o?await t.get(e.name,l):void 0;c(i.id,s?{[a]:s.record[a],etag:s.etag}:{[a]:i[a]});let u=n.errors.find(e=>e.field===a)?.message??n.message;r.show({state:`error`,title:JQ(o?`changedBySomeoneElse`:`couldNotSave`),description:u})}};return{patches:i,save:(e,t,n)=>{c(e.id,{[t]:n});let r=(s.current.get(e.id)??Promise.resolve()).then(()=>l(e,t,n));return s.current.set(e.id,r.catch(()=>void 0)),r}}},XQ=(e,t,n)=>{let r=YQ(e),i=t?.list?.editable??[];return{editor:i.length>0&&iS(n,`update`)?{editable:(t,n)=>i.includes(n)&&e.fields[n]!==void 0&&ny(e.fields[n])&&aS(t,`update`),render:(n,i,a)=>(0,q.jsx)(qQ,{field:e.fields[i],hints:t?.fields[i],resource:e.name,stored:n[i],onSave:e=>void r.save(n,i,e),close:a})}:void 0,patches:r.patches}},ZQ=(e,t,n)=>({order:r,index:i})=>{let a=t=>r.findIndex(n=>Nn(xr(e,n))===t),o=t.after.find(e=>a(e.key)>i);if(o)return ZL(`dependsOn`,{record:n,other:o.title});let s=t.before.find(e=>a(e.key)!==-1&&a(e.key)<i);return s?ZL(`dependsOn`,{record:s.title,other:n}):void 0},QQ=(e,t,n,r)=>{let i=e[t],a;for(let o=n;o<e.length;o++){let n=r({record:i,order:Ot(e,t,o),index:o});if(n===void 0)return{to:o,...a!==void 0&&{reason:a}};a??=n}return{to:t,reason:a}},$Q=({model:e,view:t,field:n,filter:r,fields:i,rule:a})=>{let o=F(),s=nS(),l=qr(),{resources:u,views:d}=c(),f=`${n} asc`,p=Tt({queryKey:[...I.list(e.name,r,f,500,`hand-order`),i.join(`,`)],queryFn:async()=>{let t=ab(u,d,e,i),n=[],a=``;do{let s=await o.search(e.name,{filter:r||void 0,orderBy:f,pageSize:500,labels:t,...a&&{pageToken:a}});n.push(...ob(u,e,i,s.items,s.labels).map((t,n)=>({...t,id:Nr(e,s.items[n])}))),a=s.nextPageToken}while(a);return n}}),[m,h]=(0,W.useState)(),g=(0,W.useRef)(void 0),_=(0,W.useRef)([]),v=(0,W.useRef)(void 0),y=(0,W.useRef)(Promise.resolve()),b=(0,W.useRef)(0),x=(0,W.useRef)(void 0),S=async()=>{let t=g.current,r=_.current;if(_.current=[],!t||r.length===0)return;let i=await o.batchWrite(r),a=new Map(i.results.flatMap(e=>e.op===`move`?e.records:[]).map(t=>[Nr(e,t.record),t])),c=KL(i.results,t=>Nr(e,t)),l=VL(e,[...a].map(([e,t])=>({...t,before:{[n]:c.get(e)}})),[n]);x.current!==void 0&&s.dismiss(x.current),x.current=s.show({state:`success`,title:zL(`orderChanged`),action:{label:zL(`undo`),onClick:()=>O(l)}}),g.current&&=g.current.map(e=>{let t=a.get(e.id);return t?{...e,[n]:t.record[n],etag:t.etag}:e})},C=(e,t)=>n=>{g.current=void 0,_.current=[],h(void 0),s.show(BL(n,e,{place:`list`,title:t?v.current:void 0}))},w=async()=>{--b.current,!(b.current>0)&&(await l(e.name),!(b.current>0)&&(g.current=void 0,h(void 0)))},T=(n,r)=>{let i=g.current??p.data;if(!i||n===r)return;if(!e.position?.after)return E(i,n,r,a);let s=Ie(e,i[n]).record,c=i[n].id;WL(o,e,t,s).then(n=>{let i=g.current??p.data,o=ZQ(e,n,ke(e,t,s,c));E(i,i.findIndex(e=>e.id===c),r,e=>o(e)??a?.(e))},C(zL(`couldNotChange`),!1))},E=(i,a,o,s)=>{if(a===-1||a===o)return;let c=s?D(i,a,o,s):o;a!==c&&(g.current=Ot(i,a,c),_.current=[..._.current,GL(e,n,r,g.current,c)],h(g.current),b.current+=1,v.current=ke(e,t,Ie(e,i[a]).record,i[a].id),y.current=y.current.then(S).catch(C(zL(`couldNotChange`),!0)).then(w))},D=(t,n,r,i)=>{let a=QQ(t.map(t=>Ie(e,t).record),n,r,i);return a.reason!==void 0&&s.show({state:`warning`,title:a.to===n?zL(`notMoved`):zL(`movedToPlace`,{place:a.to+1}),description:a.reason}),a.to},O=e=>{x.current!==void 0&&s.dismiss(x.current),x.current=void 0,b.current+=1,y.current=y.current.then(async()=>{await o.batchWrite(e),g.current=void 0,_.current=[],h(void 0)}).catch(C(zL(`couldNotUndo`),!1)).then(w)};return{rows:m??p.data,loading:p.isPending,error:p.error,move:T}},e$=({model:e,view:t,field:n,filter:r,columns:i,sort:a})=>{let{resources:o,views:s}=c(),{fields:l,dropRules:u}=qy(),{go:d,href:f}=Me(),p=a!==void 0,m=(0,W.useMemo)(()=>$T(e,t,i,{resources:o,views:s,fieldTypes:l}).map(e=>p?e:{...e,sortable:!1}),[e,t,i.join(`,`),o,s,l,p]),h=(0,W.useMemo)(()=>$e(e,t,m.map(e=>e.id)),[e,t,m]),g=t?.list?.drag?.rule,_=g===void 0?void 0:u?.[g],v=$Q({model:e,view:t,field:n,filter:r,fields:h,..._&&{rule:_}}),y=v.rows,b=(0,W.useMemo)(()=>y&&{total:y.length,rowAt:e=>y[e]},[y]);if(g!==void 0&&!_)return(0,q.jsx)(PS,{children:zL.rich(`noRule`,{rule:g})});if(v.loading)return(0,q.jsx)(`div`,{className:`flex flex-col gap-2`,children:Array.from({length:3},(e,t)=>(0,q.jsx)(L,{className:`h-4 w-full`},t))});if(v.error)return(0,q.jsx)(Oy,{title:zL(`couldNotLoad`),error:v.error});if(!b||b.total===0)return(0,q.jsx)(`p`,{className:`text-muted-foreground`,children:zL(`nothingYet`)});let x=t=>d({kind:`record`,resource:e.name,key:xr(e,t)});return(0,q.jsx)(nP,{fit:!0,scroll:`parent`,columns:m,source:b,latencyMs:0,onOpenRow:x,rowLink:t=>({href:f({kind:`record`,resource:e.name,key:xr(e,t)}),onFollow:()=>x(t)}),...a&&{sort:a.value,onSortChange:a.onChange},rowNumbers:!1,reorder:{label:n=>ke(e,t,n,n.id),onMove:v.move}})},t$=({sorting:e,onChange:t,size:n,iconOnly:r=!1})=>{let i=zL(e?`done`:`reorder`);return(0,q.jsxs)(P,{size:n,variant:e?`primary`:`secondary`,onClick:()=>t(!e),...r&&{"aria-label":i,title:i},children:[e?(0,q.jsx)(xi,{className:`size-3.5`}):(0,q.jsx)(Rs,{className:`size-3.5`}),!r&&i]})},n$=m(),r$=e=>e.find(e=>e.kind===`search`),i$=({address:e})=>{let{resources:t,views:n,signIn:r}=c(),i=t[e.resource],a=r?.[e.resource];if(!i)return a?(0,q.jsx)(KF,{as:`page`,prompt:a.signIn}):(0,q.jsx)(tt,{title:R(`notFound`),children:R(`noResource`,{name:e.resource})});let o=Se(n[e.resource],e.list);if(e.list!==void 0&&!o)return(0,q.jsx)(tt,{title:R(`notFound`),children:ST(`noList`,{name:e.list})});if(o?.searchesOf)return(0,q.jsx)(KQ,{model:i,view:o});let s=ce(t,n,e.resource,e.list);if(o&&s.listOf){let t=s.model;return(0,q.jsx)(pQ,{model:i,view:o,target:t,children:n=>(0,q.jsx)(a$,{model:t,address:e,scope:n,heading:{title:o.names?.plural??H(i.name),subtitle:o.help}})})}return(0,q.jsx)(a$,{model:i,address:e})},a$=({model:e,address:t,scope:n,heading:r})=>{let i=c(),{set:a,listTo:o,go:s,href:l}=Me(),u=e.name,d=Se(i.views[u],t.list),f=(0,W.useMemo)(()=>EF(d,e),[d,e]),{fields:p}=qy(),m=(0,W.useMemo)(()=>fQ(UT(BT(Tv(e,d),e,d,p),e,i.resources,i.views),e,d,i.resources,i.views),[e,d,p,i.resources,i.views]),g=t.filter,_=(0,W.useMemo)(()=>bF(f,g),[f,g]),y=_.ok?_.state:DP,b=_.ok?_.extras:[],{orderBy:x,filterLayout:S}=t,C=h(),T=v(),[E,D]=(0,W.useState)(!1),O=n?[...b,n]:b,k=Qy(),ee=bJ({model:e,resources:i.resources,views:i.views,view:d,state:y,extras:O,titleOf:k}),A=n?pF(f,y,O):_.ok?g:``,te=(0,W.useMemo)(()=>$e(e,d,m.map(e=>e.id)),[e,d,m]),ne=(0,W.useMemo)(()=>lI(d,i.resources,i.views,te),[d,i.resources,i.views,te]),j=mP({resources:i.resources,views:i.views,model:e,columns:te,filter:A,orderBy:x,related:ne}),ie=Ye(e,d,t.display),M=re(u),ae=n?void 0:bL(e,M),[oe,se]=(0,W.useState)(!1),ce=oe&&ae!==void 0,le=!ie&&!ce&&SL(d,ae,x,A),ue=ce||ie?.kind!==`map`;OA(ue);let de=kL(e,j.page,j.key,ie?.kind===`custom`),pe=YZ(),me=Ke(e,d),he=e=>({key:e.id,title:String(typeof e[me]==`object`?e[me].name:e[me]??e.id),etag:typeof e.etag==`string`?e.etag:void 0,snapshot:e}),ge=d?.names?.singular??H(u),_e=XQ(e,d,M),{state:ve}=Y(),ye=jJ({model:e,view:d,restore:MJ(e),onReview:e=>s({kind:`record`,resource:u,key:e.key})}),be=vB(e),xe=d?.actions.some(e=>e.run?.kind===`delete`)??!1,Ce=(e,t=b)=>a({filter:pF(f,e,t)}),we=r$(b),N=e=>{let t=b.filter(e=>e.kind!==`search`);Ce(y,e?[...t,n$.search(e)]:t)},Te=d?.names?.plural??H(u),Ee=ie?.kind===`calendar`||ie?.kind===`timeline`||ie?.kind===`board`&&w(e)?void 0:ie,De=Ee&&(0,q.jsx)(tB,{model:e,view:d,display:Ee,orderBy:x,onChange:e=>a({orderBy:e})}),Oe=e.search?.length?(0,q.jsx)(iQ,{value:we?.kind===`search`?we.text:``,onCommit:N,placeholder:ST(`searchPlural`,{plural:Te}),className:C?void 0:`min-h-11`}):null,ke=(0,q.jsx)(tF,{layout:S,config:ee,value:y,onChange:Ce,leading:S===`bar`?De:void 0,trailing:Oe}),Ae=S===`bar`?ke:(0,q.jsx)($P,{groups:[De?[De]:[]],trailing:Oe}),je=MP(ee,y),Ne=(0,q.jsx)(SP,{scroll:!0,chips:je,onRemove:e=>Ce(NP(y,e)),onClear:()=>Ce(DP)}),Pe=Ee&&(0,q.jsx)(BP,{title:ST(`sort`),children:(0,q.jsx)(tB,{model:e,view:d,display:Ee,orderBy:x,onChange:e=>a({orderBy:e}),className:`min-h-11 w-full`})}),Fe=(0,q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsxs)(P,{className:`min-h-11`,onClick:()=>D(!0),"aria-haspopup":`dialog`,children:[(0,q.jsx)(bd,{className:`size-3.5`}),je.length>0?ST(`filtersCount`,{count:je.length}):ST(`filters`)]}),Oe??(0,q.jsx)(`div`,{className:`min-w-0 flex-1`,children:Ne})]}),Oe&&Ne,(0,q.jsx)(h_,{title:ST(`filters`),open:E,onClose:()=>D(!1),children:(0,q.jsx)(tF,{layout:`panel`,fullWidth:!0,config:ee,value:y,onChange:Ce,leading:Pe})})]}),Le=!n&&NJ(d,i.pages,M)&&(0,q.jsxs)(Ue,{to:{kind:`create`,resource:u},className:zn({variant:`primary`}),children:[(0,q.jsx)(Hu,{className:`size-3.5`}),ST(`newRecord`,{singular:ge})]}),Re=d?.saveSearch&&!n&&_.ok&&g&&(0,q.jsx)(zQ,{model:e,view:d,search:d.saveSearch,filter:g,chips:NF(e,d,g,PF(ee))}),ze=!n&&(0,q.jsx)(LX,{model:e}),Be=SZ({model:e,view:d,resources:i.resources,views:i.views,plural:Te,filter:A,orderBy:x}),We=qX(d)&&(0,q.jsxs)(P,{onClick:()=>Be.open(),...!C&&{"aria-label":ST(`export`),title:ST(`export`)},children:[(0,q.jsx)(Qc,{className:`size-3.5`}),C&&ST(`export`)]}),Ge=ae&&!le&&(0,q.jsx)(t$,{sorting:ce,onChange:se,iconOnly:!C}),Je=t=>!ce&&(0,q.jsx)($z,{view:d,choices:qe(e,d,T),value:ie?.name??`table`,onChange:e=>a({display:e}),menu:t}),Xe=zF(e),Ze=t=>{Xe(Ie(e,t).record),s({kind:`record`,resource:u,key:xr(e,t)})},Qe=async e=>{let t=e.map(he),n=await ye.startBulk(t);return e.filter((e,r)=>n.includes(t[r]))},et=j.source?(0,q.jsx)(nP,{columns:m,source:j.source,sort:Ve(x),onSortChange:e=>a({orderBy:fe(e)}),onOpenRow:Ze,rowLink:t=>({href:l({kind:`record`,resource:u,key:xr(e,t)}),onFollow:()=>Ze(t)}),cellEditor:_e.editor,rowPatches:_e.patches,initialScrollIndex:pe.initialIndex,onScrollIndex:pe.remember,rowActions:[{label:ST(`openRecord`,{singular:ge}),onSelect:Ze},...be.rowActions,...iS(M,`delete`)&&!xe?[{label:ST(`delete`),destructive:!0,available:e=>aS(e,`delete`),onSelect:e=>void ye.start(he(e))}]:[]],bulkActions:[...qX(d)&&$X(e)?[{label:e=>ST(`exportCount`,{count:e}),onRun:e=>Be.open(e)}]:[],...be.bulkActions,...iS(M,`delete`)?[{label:e=>ST(`deleteCount`,{count:e}),destructive:!0,onRun:e=>Qe(e)}]:[]],rowNumbers:!1,pinKey:ve.kind===`signed-in`?YM(ve.user.id,sQ(u,t.list)):void 0,scroll:`parent`,className:`flex-1`}):(0,q.jsx)(`div`,{className:`flex-1 rounded-lg border bg-surface`}),tt={...j,initialIndex:pe.initialIndex,onScrollIndex:pe.remember},nt=wZ({plural:Te,search:we?.kind===`search`?we.text:``,filtered:je.length>0,scoped:!!n||b.some(e=>e.kind!==`search`),canCreate:!!Le}),rt=(0,q.jsx)(CZ,{state:nt,onClearSearch:()=>N(``),onClearFilters:()=>Ce(DP),create:Le}),it=ce?(0,q.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,q.jsx)(`p`,{className:`text-muted-foreground`,children:ST(`dragToSort`)}),(0,q.jsx)(e$,{model:e,view:d,field:ae,filter:``,columns:He(e,d)})]}):le?(0,q.jsx)(e$,{model:e,view:d,field:ae,filter:``,columns:He(e,d),sort:{value:Ve(x),onChange:e=>a({orderBy:fe(e)})}}):ie?ie.kind===`cards`?(0,q.jsx)(zZ,{model:e,view:d,display:ie,list:tt,empty:rt},j.key.join(` `)):ie.kind===`map`?(0,q.jsx)(Yz,{model:e,view:d,display:ie,filter:A,orderBy:x,fields:te,at:t.map,onMove:e=>a({map:e}),flush:!0}):ie.kind===`board`?(0,q.jsx)(nR,{model:e,view:d,display:ie,fields:te,filter:A,orderBy:x}):ie.kind===`calendar`?(0,q.jsx)(BR,{model:e,view:d,display:ie,fields:te,filter:A,at:t.calendar,linkTo:e=>o({calendar:e})}):ie.kind===`timeline`?(0,q.jsx)(sz,{model:e,view:d,display:ie,fields:te,filter:A,at:t.timeline,linkTo:e=>o({timeline:e})}):(0,q.jsx)(_z,{display:ie,list:de}):j.source?.total===0&&!j.error?rt:et;return(0,q.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 px-5 py-4`,children:[ye.dialogs,Be.dialogs,be.prompt,(0,q.jsx)(Rj,{title:r?.title??Te,subtitle:r?r.subtitle:d?.help,subtitleBelow:!0,actions:(0,q.jsxs)(q.Fragment,{children:[Je(!C),Ge,Re,ze,We,Le]})}),!_.ok&&(0,q.jsx)(Oy,{title:ST(`unreadableFilter`),error:Error(_.errors.map(e=>e.message).join(`; `))}),j.error&&!ie&&!ce&&(0,q.jsx)(Oy,{title:ST(`couldNotLoadRows`),error:j.error}),d?.chart&&!ce&&(lo(d.chart)?(0,q.jsx)(rQ,{model:e,view:d,chart:d.chart,plural:Te,filter:A}):(0,q.jsx)(tQ,{resource:u,chart:d.chart,title:ST(`created`,{plural:Te}),filter:A})),!ce&&(C?Ae:Fe),C&&S===`panel`&&!ce?(0,q.jsxs)(`div`,{className:`flex min-h-0 flex-1 gap-4`,children:[(0,q.jsx)(`div`,{className:ue?`sticky top-[calc(var(--pb-sticky-top,0px)+1rem)] flex max-h-[calc(100dvh-var(--pb-sticky-top,0px)-var(--pb-sticky-bottom,0px)-2rem)] shrink-0 self-start`:`flex shrink-0`,children:ke}),it]}):it]})},o$=()=>{let e,t=new Set;return{get:()=>e,set:n=>{if(n!==e){e=n;for(let e of t)e()}},subscribe:e=>(t.add(e),()=>void t.delete(e))}},s$=(0,W.createContext)(void 0),c$=()=>()=>{},l$=()=>void 0,u$=()=>{let e=(0,W.useContext)(s$);return(0,W.useSyncExternalStore)(e?.subscribe??c$,e?.get??l$,e?.get??l$)},d$=(e,t)=>e&&Object.hasOwn(e,t)?e[t]:void 0,f$=e=>e?.role===`owner`?[`owner`,`admin`,`member`]:[`admin`,`member`],p$=({member:e,current:t,status:n,presence:r,onChanged:i})=>{let{session:a,organizations:o}=Y(),s=t.organization.id,{busy:c,error:l,run:u}=yV(),d=o?.roles??[],f=e.id===t.memberId,p=f$(t),m=e.role===`owner`&&t.role!==`owner`,h=d.filter(e=>e.membership);return(0,q.jsx)(JV,{name:e.name,email:e.email,self:f,error:l,...(n||r)&&{status:(0,q.jsx)(mj,{status:n,presence:r})},actions:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`select`,{"aria-label":Z(`roleOf`,{name:e.name}),value:e.role,disabled:c||m,onChange:t=>void u(async()=>{await a.organizations.setRole(s,e.id,t.target.value),i()}),className:`h-7 rounded-md border border-border-strong bg-background px-2 text-body`,children:(m?[e.role]:p).map(e=>(0,q.jsx)(`option`,{value:e,children:jV(e)},e))}),!f&&(0,q.jsx)(P,{size:`sm`,variant:`danger`,loading:c,disabled:m,onClick:()=>void u(async()=>{await a.organizations.removeMember(s,e.id),i()}),children:Z(`remove`)})]}),children:(0,q.jsx)(wV,{roles:h,selected:e.appRoles,grantable:FV(d,t),disabled:c,onChange:t=>void u(async()=>{await a.organizations.setAppRoles(e.id,t),i()})})})},m$=({current:e,statuses:t,presence:n})=>{let{session:r}=Y(),[i,a]=(0,W.useState)(),[o,s]=(0,W.useState)(),c=e?.organization?.id,l=(0,W.useCallback)(()=>{c&&r.organizations.members(c).then(a,e=>s(e instanceof Jm?$C(e):Z(`couldNotReadMembers`)))},[r,c]);return(0,W.useEffect)(l,[l]),e?.organization?(0,q.jsxs)(`div`,{className:`mx-auto flex w-full max-w-3xl flex-col gap-4 px-4 py-6 md:px-6`,children:[(0,q.jsx)(Rj,{title:Z(`members`),subtitle:Z(`whoWorks`,{organization:e.organization.name})}),(0,q.jsxs)(gV,{title:Z(`members`),description:Z(`membersDescription`),children:[(0,q.jsx)(_V,{message:o}),i?(0,q.jsx)(`ul`,{className:`divide-y rounded-md border`,children:i.map(r=>(0,q.jsx)(p$,{member:r,current:e,status:t?.find(e=>e.userId===r.userId),presence:d$(n,r.userId),onChanged:l},`${r.id}/${r.role}/${r.appRoles.join()}`))}):!o&&(0,q.jsxs)(`div`,{className:`flex items-center gap-2 text-muted-foreground`,children:[(0,q.jsx)(wn,{}),` `,Z(`loading`)]})]})]}):null},h$=({current:e,onSent:t})=>{let{session:n,organizations:r}=Y(),i=r?.roles??[],[a,o]=(0,W.useState)(`member`),[s,c]=(0,W.useState)([]);return(0,q.jsx)(SV,{title:Z(`inviteSomeone`),description:Z(`inviteDescription`),onInvite:async r=>{let i=await n.organizations.invite(e.organization.id,{email:r,role:a,appRoles:s});return c([]),t(),i},beside:(0,q.jsx)(`select`,{"aria-label":Z(`organizationRole`),value:a,onChange:e=>o(e.target.value),className:`h-8 rounded-md border border-border-strong bg-background px-2`,children:f$(e).map(e=>(0,q.jsx)(`option`,{value:e,children:jV(e)},e))}),children:(0,q.jsx)(wV,{roles:i.filter(e=>e.membership),selected:s,grantable:FV(i,e),onChange:c})})},g$=({invitation:e,organizationId:t,onChanged:n})=>{let{session:r,organizations:i}=Y(),a=e.appRoles.map(e=>MV(i?.roles??[],e));return(0,q.jsx)(CV,{email:e.email,gives:`${jV(e.role)}${a.length>0?` · ${a.join(`, `)}`:``}`,expiresAt:e.expiresAt,onResend:async()=>{let i=await r.organizations.resend(t,e);return n(),i},onRevoke:async()=>{await r.organizations.revoke(e.id),n()}})},_$=({current:e})=>{let{session:t}=Y(),[n,r]=(0,W.useState)([]),i=e?.organization?.id,a=(0,W.useCallback)(()=>{i&&t.organizations.invitations(i).then(e=>r(e.filter(e=>e.status===`pending`)),()=>r([]))},[t,i]);return(0,W.useEffect)(a,[a]),!e?.organization||!i?null:(0,q.jsxs)(`div`,{className:`mx-auto flex w-full max-w-3xl flex-col gap-4 px-4 py-6 md:px-6`,children:[(0,q.jsx)(Rj,{title:Z(`invitations`),subtitle:Z(`peopleInvited`,{organization:e.organization.name})}),(0,q.jsx)(h$,{current:e,onSent:a}),(0,q.jsx)(gV,{title:Z(`notAcceptedYet`),description:n.length>0?Z(`sendingAgain`):Z(`nobodyWaiting`),children:n.length>0&&(0,q.jsx)(`ul`,{className:`divide-y rounded-md border`,children:n.map(e=>(0,q.jsx)(g$,{invitation:e,organizationId:i,onChanged:a},e.id))})})]})},v$=({usePresence:e,store:t})=>{let n=e();return(0,W.useEffect)(()=>t.set(n),[t,n]),(0,W.useEffect)(()=>()=>t.set(void 0),[t]),null},y$=({children:e})=>{let{presence:t}=qy(),[n]=(0,W.useState)(o$),[r,i]=(0,W.useState)({hook:t,key:0});return r.hook!==t&&i({hook:t,key:r.key+1}),(0,q.jsxs)(s$.Provider,{value:n,children:[t&&(0,q.jsx)(v$,{usePresence:t,store:n},r.key),e]})},b$=e=>{let{session:t}=Y(),[n,r]=(0,W.useState)(),[i,a]=(0,W.useState)([]),[o,s]=(0,W.useState)(),[c,l]=(0,W.useState)(0),u=(0,W.useCallback)(()=>l(e=>e+1),[]);return(0,W.useEffect)(()=>{e&&Promise.all([t.organizations.current(),t.organizations.list()]).then(([e,t])=>{r(e),a(t)},e=>s(e instanceof Jm?$C(e):Z(`couldNotReadOrganizations`)))},[e,t,c]),{current:n,organizations:i,...o&&{error:o},reload:u}},x$=e=>window.location.assign(`${e}/`),S$=({organization:e,editable:t,onSaved:n})=>{let{session:r}=Y(),[i,a]=(0,W.useState)(e.name),[o,s]=(0,W.useState)(e.slug),{busy:c,error:l,run:u}=yV(),d=i.trim()!==e.name||o!==e.slug;return(0,q.jsxs)(gV,{title:Z(`details`),description:Z(t?`detailsEditable`:`detailsReadOnly`),children:[(0,q.jsx)(_V,{message:l}),(0,q.jsxs)(`form`,{className:`flex flex-col gap-2 sm:flex-row`,onSubmit:t=>{t.preventDefault(),u(async()=>{await r.organizations.rename(e.id,{name:i.trim(),slug:o}),n()})},children:[(0,q.jsx)(bi,{"aria-label":Z(`name`),value:i,disabled:!t,onChange:e=>a(e.target.value),wrapperClassName:`flex-1`}),(0,q.jsx)(bi,{"aria-label":Z(`slug`),value:o,disabled:!t,onChange:e=>s(e.target.value),wrapperClassName:`sm:w-48`}),t&&(0,q.jsx)(P,{type:`submit`,variant:`primary`,loading:c,disabled:!d||!i.trim(),children:Z(`save`)})]})]})},C$=({organization:e,memberId:t})=>{let{session:n}=Y(),[r,i]=(0,W.useState)([]),[a,o]=(0,W.useState)(``),{busy:s,error:c,run:l}=yV();return(0,W.useEffect)(()=>{n.organizations.members(e.id).then(e=>i(e.filter(e=>e.id!==t)),()=>i([]))},[n,e.id,t]),(0,q.jsxs)(gV,{title:Z(`handOver`),description:Z(`handOverDescription`),children:[(0,q.jsx)(_V,{message:c}),(0,q.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,q.jsxs)(`select`,{"aria-label":Z(`newOwner`),value:a,onChange:e=>o(e.target.value),className:`h-8 flex-1 rounded-md border border-border-strong bg-background px-2`,children:[(0,q.jsx)(`option`,{value:``,children:Z(`chooseMember`)}),r.map(e=>(0,q.jsxs)(`option`,{value:e.id,children:[e.name,` (`,e.email,`)`]},e.id))]}),(0,q.jsx)(P,{loading:s,disabled:!a,onClick:()=>void l(async()=>{await n.organizations.transferOwnership(a),window.location.reload()}),children:Z(`handOver`)})]})]})},w$=({organization:e,basePath:t})=>{let{session:n}=Y(),[r,i]=(0,W.useState)(!1),[a,o]=(0,W.useState)(``),{busy:s,error:c,run:l}=yV(),u=()=>l(async()=>{await n.organizations.remove(e.id),x$(t)});return(0,q.jsxs)(gV,{title:Z(`deleteOrganization`),description:Z(`deleteDescription`),children:[(0,q.jsx)(_V,{message:r?void 0:c}),(0,q.jsx)(P,{variant:`danger`,onClick:()=>i(!0),children:Z(`deleteOrganization`)}),r&&(0,q.jsxs)(di,{title:Z(`deleteTitle`,{name:e.name}),description:Z(`deleteConfirm`),onClose:()=>i(!1),actions:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(P,{onClick:()=>i(!1),children:Z(`cancel`)}),(0,q.jsx)(P,{variant:`danger`,loading:s,disabled:a!==e.name,onClick:()=>void u(),children:Z(`delete`)})]}),children:[(0,q.jsx)(_V,{message:c}),(0,q.jsx)(bi,{"aria-label":Z(`organizationName`),value:a,onChange:e=>o(e.target.value)})]})]})},T$=({editable:e})=>{let t=F(),[n,r]=(0,W.useState)(),{busy:i,error:a,run:o}=yV();return(0,W.useEffect)(()=>{t.callGuests.allowed().then(r)},[t]),n===void 0?null:(0,q.jsxs)(gV,{title:Z(`guestLinks`),description:Z(`guestLinksDescription`),children:[(0,q.jsx)(_V,{message:a}),(0,q.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-foreground`,children:[(0,q.jsx)(ky,{checked:n,label:Z(`guestLinksAllowed`),...e&&!i&&{onChange:e=>void o(async()=>{await t.callGuests.setAllowed(e),r(e)})}}),Z(`guestLinksAllowed`)]})]})},E$=({organization:e,basePath:t,owner:n})=>{let{session:r}=Y(),{busy:i,error:a,run:o}=yV();return(0,q.jsxs)(gV,{title:Z(`leave`),description:Z(n?`leaveOwner`:`leaveMember`),children:[(0,q.jsx)(_V,{message:a}),(0,q.jsx)(P,{loading:i,onClick:()=>void o(async()=>{await r.organizations.leave(e.id),x$(t)}),children:Z(`leaveName`,{name:e.name})})]})},D$=({current:e,basePath:t,onChanged:n})=>{let r=fi().data?.calls===!0,i=e?.organization;if(!i)return(0,q.jsx)(`div`,{className:`mx-auto w-full max-w-3xl px-4 py-6 md:px-6`,children:(0,q.jsx)(Rj,{title:Z(`organization`),subtitle:Z(`noOrganization`)})});let a=e.role===`owner`;return(0,q.jsxs)(`div`,{className:`mx-auto flex w-full max-w-3xl flex-col gap-4 px-4 py-6 md:px-6`,children:[(0,q.jsx)(Rj,{title:i.name,subtitle:e.role?Z(`youAre`,{role:jV(e.role).toLowerCase()}):Z(`throughGlobalRoles`)}),(0,q.jsx)(S$,{organization:i,editable:NV(e),onSaved:n},`${i.name}/${i.slug}`),r&&e.role&&(0,q.jsx)(T$,{editable:NV(e)}),a&&e.memberId&&(0,q.jsx)(C$,{organization:i,memberId:e.memberId}),e.role&&(0,q.jsx)(E$,{organization:i,basePath:t,owner:a}),a&&(0,q.jsx)(w$,{organization:i,basePath:t})]})},O$=({organization:e,current:t,busy:n,onOpen:r})=>(0,q.jsxs)(`li`,{className:`flex items-center gap-3 px-3 py-2.5`,children:[(0,q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,q.jsx)(`span`,{className:`block truncate font-medium`,children:e.name}),(0,q.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:e.slug})]}),t?(0,q.jsx)(Ni,{tone:`green`,children:Z(`current`)}):(0,q.jsx)(P,{size:`sm`,loading:n,onClick:r,children:Z(`open`)})]}),k$=({basePath:e,currentId:t})=>{let{session:n}=Y(),[r,i]=(0,W.useState)(``),a=qV((0,W.useCallback)((e,t)=>n.organizations.search(e,t).then(e=>({items:e.organizations,total:e.total})),[n]),r),{busy:o,error:s,run:c}=yV();return(0,q.jsx)(KV,{title:Z(`allOrganizations`),description:Z(`allOrganizationsDescription`),searchLabel:Z(`findOrganization`),placeholder:Z(`nameOrSlug`),query:r,onQuery:i,list:a,error:s,renderRow:r=>(0,q.jsx)(O$,{organization:r,current:r.id===t,busy:o,onOpen:()=>void c(async()=>{await n.organizations.switchTo(r.id),x$(e)})},r.id)})},A$=e=>e.normalize(`NFKD`).replace(/[̀-ͯ]/g,``).toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,63),j$=({basePath:e})=>{let{session:t}=Y(),[n,r]=(0,W.useState)(``),[i,a]=(0,W.useState)(),{busy:o,error:s,run:c}=yV(),l=()=>c(async()=>{await t.organizations.create({name:n.trim(),slug:i??A$(n)}),x$(e)});return(0,q.jsxs)(gV,{title:Z(`newOrganization`),description:Z(`newOrganizationDescription`),children:[(0,q.jsx)(_V,{message:s}),(0,q.jsxs)(`form`,{className:`flex flex-col gap-2 sm:flex-row`,onSubmit:e=>{e.preventDefault(),l()},children:[(0,q.jsx)(bi,{"aria-label":Z(`name`),placeholder:Z(`name`),value:n,onChange:e=>r(e.target.value),wrapperClassName:`flex-1`}),(0,q.jsx)(bi,{"aria-label":Z(`slug`),placeholder:`slug`,value:i??A$(n),onChange:e=>a(e.target.value),wrapperClassName:`sm:w-48`}),(0,q.jsx)(P,{type:`submit`,variant:`primary`,loading:o,disabled:!n.trim(),children:Z(`create`)})]})]})},M$=({basePath:e})=>{let{session:t,organizations:n}=Y(),[r,i]=(0,W.useState)([]),{busy:a,error:o,run:s}=yV();if((0,W.useEffect)(()=>{t.organizations.myInvitations().then(i,()=>i([]))},[t]),r.length===0)return null;let c=n?.roles??[],l=n=>s(async()=>{await t.organizations.acceptMine(n),x$(e)});return(0,q.jsxs)(gV,{title:Z(`invitationsForYou`),description:Z(`invitationsForYouDescription`),children:[(0,q.jsx)(_V,{message:o}),(0,q.jsx)(`ul`,{className:`divide-y rounded-md border`,children:r.map(e=>(0,q.jsxs)(`li`,{className:`flex items-center gap-3 px-3 py-2.5`,children:[(0,q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,q.jsx)(`span`,{className:`font-medium`,children:e.organizationName??Z(`anOrganization`)}),`: `,e.appRoles.map(e=>MV(c,e)).join(`, `)||Z(`noAppRoles`),(0,q.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:Z(`until`,{date:new Date(e.expiresAt).toLocaleDateString(ci())})})]}),(0,q.jsx)(P,{size:`sm`,variant:`primary`,loading:a,onClick:()=>void l(e.id),children:Z(`accept`)})]},e.id))})]})},N$=({state:e,basePath:t})=>{let{session:n,organizations:r,state:i}=Y(),{busy:a,error:o,run:s}=yV(),c=i.kind===`signed-in`?i.user:void 0,l=r?.create===`everyone`||c!==void 0&&Ab(c),u=e.current?.organization?.id;return(0,q.jsxs)(`div`,{className:`mx-auto flex w-full max-w-3xl flex-col gap-4 px-4 py-6 md:px-6`,children:[(0,q.jsx)(Rj,{title:Z(`organizations`),subtitle:Z(`organizationsSubtitle`)}),(0,q.jsxs)(gV,{title:Z(`yourOrganizations`),description:e.organizations.length>0?Z(`memberOf`):Z(`notMember`),children:[(0,q.jsx)(_V,{message:o??e.error}),e.organizations.length>0&&(0,q.jsx)(`ul`,{className:`divide-y rounded-md border`,children:e.organizations.map(e=>(0,q.jsx)(O$,{organization:e,current:e.id===u,busy:a,onOpen:()=>void s(async()=>{await n.organizations.switchTo(e.id),x$(t)})},e.id))})]}),(0,q.jsx)(M$,{basePath:t}),l&&(0,q.jsx)(j$,{basePath:t}),(e.current?.globalRoles.length??0)>0&&(0,q.jsx)(k$,{basePath:t,currentId:u})]})},P$=(e,t)=>t?.active?{...e,role:t.active}:e,F$=B(`roles`),I$=(e,t)=>e instanceof Jm?$C(e):t,L$=(e,t=!0)=>{let{session:n}=Y(),r=nS(),[i,a]=(0,W.useState)();(0,W.useEffect)(()=>{t&&n.roles.current().then(a,e=>r.show({state:`error`,title:I$(e,F$(`couldNotReadRoles`))}))},[n,r,t]);let o=(0,W.useCallback)(t=>void n.roles.switchTo(t).then(e,e=>r.show({state:`error`,title:I$(e,F$(`couldNotSwitch`))})),[n,r,e]);return{...i&&{current:i},switchTo:o}},R$=e=>{let t=dQ(e).flatMap(e=>e.items).find(e=>!e.problem);if(t&&e.pages[t.id])return{kind:`page`,page:t.id};if(t){let[e,n]=t.id.split(`/`);return{kind:`list`,resource:e,...n!==void 0&&{list:n}}}let n=Object.keys(e.pages)[0];if(n)return{kind:`page`,page:n};let r=Object.keys(e.resources)[0];return r?{kind:`list`,resource:r}:void 0},z$=e=>{let t=qy().shell?.logo;return t?(0,q.jsx)(FS,{name:`shell.logo`,fallback:(0,q.jsx)(BA,{...e}),children:(0,q.jsx)(t,{...e})}):(0,q.jsx)(BA,{...e})},B$=[440,480],V$=400,H$=3e3,U$=e=>{(0,W.useEffect)(()=>{if(!e||typeof AudioContext>`u`)return;let t=new AudioContext,n=()=>{let e=t.createGain();e.gain.value=.08,e.connect(t.destination);for(let[n,r]of[0,V$*1.5/1e3].entries())for(let i of B$){let a=t.createOscillator();a.frequency.value=i,a.connect(e),a.start(t.currentTime+r),a.stop(t.currentTime+r+V$/1e3/(n+1))}};n();let r=setInterval(n,H$);return()=>{clearInterval(r),t.close()}},[e])},W$=(e,t)=>e.map(e=>({...e,until:t+e.remaining_ms})),G$=(e,t)=>{let n=e.filter(e=>e.until>t);return{ringing:n,next:n.length===0?void 0:Math.min(...n.map(e=>e.until))}},K$=e=>{let t=F(),n=nn(),r=Tt({queryKey:I.rings,queryFn:async()=>W$(await t.rings.list(),Date.now()),enabled:e});(0,W.useEffect)(()=>{if(!e)return;let r=()=>void n.invalidateQueries({queryKey:I.rings});return t.live({onChanges:e=>e.some(e=>e.resource===`$rings`)&&r(),onResync:r})},[t,n,e]);let[i,a]=(0,W.useState)(()=>Date.now()),{ringing:o,next:s}=G$(r.data??[],Math.max(i,r.dataUpdatedAt));(0,W.useEffect)(()=>{if(s===void 0)return;let e=setTimeout(()=>a(Date.now()),Math.max(0,s-Date.now()));return()=>clearTimeout(e)},[s]);let c=(0,W.useCallback)(e=>n.setQueryData(I.rings,t=>t?.filter(t=>t.call!==e)),[n]);return{ringing:o,decline:en({mutationFn:e=>t.rings.decline(e),onMutate:c,onSettled:()=>n.invalidateQueries({queryKey:I.rings})}).mutate,hide:c}},q$=(e,t,n)=>({state:`call`,sticky:!0,title:e.title,...e.body!==null&&{description:e.body},actions:[{label:Q(`decline`),onClick:()=>n(e.call)},{label:Q(`accept`),...t}]}),J$=()=>{let{ringing:e,decline:t,hide:n}=K$(!0),r=nS(),{href:i,open:a}=Me(),o=(0,W.useRef)(new Map);return U$(e.length>0),(0,W.useEffect)(()=>{let s=new Set(e.map(e=>e.call));for(let[e,t]of o.current)s.has(e)||(r.dismiss(t),o.current.delete(e));for(let s of e){if(o.current.has(s.call))continue;let e={href:i({kind:`record`,resource:s.resource,key:s.key,call:`join`}),onNavigate:e=>{n(s.call),a(e)}};o.current.set(s.call,r.show({...q$(s,e,t),onClose:()=>t(s.call)}))}},[e,r,i,a,t,n]),(0,W.useEffect)(()=>{let e=o.current;return()=>{for(let t of e.values())r.dismiss(t);e.clear()}},[r]),null},Y$=(e,t)=>({turnOn:async()=>{t({failure:void 0,busy:!0});try{t({state:await e.turnOn()})}catch(e){console.error(`Notifications could not be turned on:`,e),t({failure:Gh(e)})}finally{t({busy:!1})}},turnOff:async()=>{t({failure:void 0,busy:!0});try{await e.turnOff({chosen:!0})}catch(e){console.error(`Notifications could not be turned off for good:`,e),t({failure:Gh(e)})}try{t({state:await e.state()})}catch(e){console.error(`Whether notifications are on could not be read:`,e)}finally{t({busy:!1})}}}),X$=(e,t=window)=>{let n,r=!1,i=()=>{t.document.visibilityState===`visible`&&e()};return t.addEventListener(`focus`,e),t.document.addEventListener(`visibilitychange`,i),`permissions`in t.navigator&&t.navigator.permissions.query({name:`notifications`}).then(t=>{r||(n=t,t.addEventListener(`change`,e))},e=>{if(!(e instanceof TypeError))throw e}),()=>{r=!0,t.removeEventListener(`focus`,e),t.document.removeEventListener(`visibilitychange`,i),n?.removeEventListener(`change`,e)}},Z$=()=>{let{push:e,state:t}=Y(),n=t.kind===`signed-in`?t.user.id:void 0,[r,i]=(0,W.useState)(`loading`),[a,o]=(0,W.useState)(),[s,c]=(0,W.useState)(!1),[l,u]=(0,W.useState)(0);(0,W.useEffect)(()=>{let t=!0,n=()=>void e.state().then(e=>t&&i(e));n();let r=typeof window>`u`?void 0:X$(n);return()=>{t=!1,r?.()}},[e,n,l]);let d=(0,W.useCallback)(()=>u(e=>e+1),[]),{turnOn:f,turnOff:p}=(0,W.useMemo)(()=>Y$(e,e=>{e.state&&i(e.state),`failure`in e&&o(e.failure),e.busy!==void 0&&c(e.busy)}),[e]);return{state:r,busy:s,failure:a,turnOn:f,turnOff:p,refresh:d}},Q$=B(`notifications/bell`),$$=`flex w-full gap-2.5 px-3 py-2.5 text-left`,e1=({item:e,target:t,onNavigate:n,onOpen:r,now:i})=>{let a=e.readAt===null,o=(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`span`,{className:U(`mt-1.5 size-2 shrink-0 rounded-full`,a?ji.blue:`bg-transparent`),children:a&&(0,q.jsx)(`span`,{className:`sr-only`,children:Q$(`unread`)})}),(0,q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,q.jsx)(`span`,{className:U(`block text-body text-foreground`,a&&`font-semibold`),children:e.title}),e.body&&(0,q.jsx)(`span`,{className:`mt-0.5 line-clamp-2 block text-xs text-muted-foreground`,children:e.body}),(0,q.jsx)(`time`,{dateTime:e.createdAt,className:`mt-0.5 block text-xs text-faint-foreground`,children:Un((i-Date.parse(e.createdAt))/1e3)})]})]}),s=()=>r(e),c=e=>{e.button===1&&s()};return t?t.kind===`app`?(0,q.jsx)(Jn,{to:{href:t.href,onFollow:()=>n(t.path)},onClick:s,onAuxClick:c,className:U($$,`hover:bg-muted`),children:o}):(0,q.jsx)(`a`,{href:t.href,onClick:s,onAuxClick:c,className:U($$,`hover:bg-muted`),children:o}):(0,q.jsx)(`div`,{className:$$,children:o})},t1=({items:e,loading:t,failed:n,onRetry:r,hasMore:i,loadingMore:a,onMore:o,onMarkAllRead:s,markingAll:c,targetOf:l,onNavigate:u,onOpen:d,footer:f,now:p})=>{let m=e[0],h=e.some(e=>e.readAt===null);return(0,q.jsxs)(`div`,{className:`flex max-h-[min(32rem,calc(100dvh-var(--pb-sticky-top,3rem)-1rem))] flex-col`,children:[(0,q.jsxs)(`div`,{className:`flex min-h-11 items-center gap-2 border-b px-3`,children:[(0,q.jsx)(`h2`,{className:`flex-1 text-body font-semibold`,children:Q$(`notifications`)}),m&&h&&(0,q.jsx)(P,{size:`sm`,variant:`ghost`,loading:c,onClick:()=>s(m),children:Q$(`markAllRead`)})]}),(0,q.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overscroll-contain`,children:[t?(0,q.jsx)(`div`,{className:`flex justify-center py-8`,children:(0,q.jsx)(wn,{className:`size-4`})}):n?(0,q.jsxs)(`div`,{className:`flex flex-col items-center gap-2 px-3 py-6 text-center text-body text-muted-foreground`,children:[(0,q.jsx)(`p`,{children:Q$(`loadFailed`)}),(0,q.jsx)(P,{size:`sm`,onClick:r,children:Q$(`tryAgain`)})]}):e.length===0?(0,q.jsx)(`p`,{className:`px-3 py-8 text-center text-body text-muted-foreground`,children:Q$(`empty`)}):(0,q.jsx)(`ul`,{className:`divide-y`,children:e.map(e=>(0,q.jsx)(`li`,{children:(0,q.jsx)(e1,{item:e,target:l(e),onNavigate:u,onOpen:d,now:p})},e.id))}),i&&!t&&!n&&(0,q.jsx)(`div`,{className:`flex justify-center border-t py-2`,children:(0,q.jsx)(P,{size:`sm`,variant:`ghost`,loading:a,onClick:o,children:Q$(`showMore`)})})]}),f]})},n1=(e,{origin:t,basePath:n})=>{if(e===null||!URL.canParse(e,t))return;let r=new URL(e,t);if(r.protocol!==`http:`&&r.protocol!==`https:`)return;if(r.origin!==t)return{kind:`page`,href:r.href};let i=`${r.pathname}${r.search}${r.hash}`;return n===``?{kind:`app`,href:i,path:i}:r.pathname===n||r.pathname.startsWith(`${n}/`)?{kind:`app`,href:i,path:i.slice(n.length)||`/`}:{kind:`page`,href:i}},r1=e=>e.kind===`registration`?Q$(`pushRegistrationFailed`,{reason:e.reason}):e.kind===`no-token`?Q$(e.service===`apns`?`pushNoTokenApns`:`pushNoTokenFcm`):e.kind===`off-not-stored`?Q$(`pushOffNotStored`):e.kind===`refused`?Q$(`pushRefused`,{reason:e.reason}):Q$(`pushFailed`,{reason:e.reason}),i1=({state:e,busy:t=!1,failure:n,onTurnOn:r,onTurnOff:i})=>{if(e===`loading`||e===`unsupported`)return null;if(e===`blocked`)return(0,q.jsxs)(`p`,{className:`flex gap-2 border-t px-3 py-2.5 text-xs text-muted-foreground`,children:[(0,q.jsx)(Qs,{className:`mt-0.5 size-3.5 shrink-0`,"aria-hidden":!0}),Q$(`pushBlocked`)]});let a=e===`on`,o=!a&&n;return(0,q.jsxs)(`div`,{className:`flex items-center gap-2 border-t px-3 py-2.5 text-xs text-muted-foreground`,children:[(0,q.jsx)(ec,{className:`size-3.5 shrink-0`,"aria-hidden":!0}),o?(0,q.jsx)(`span`,{role:`alert`,className:`min-w-0 flex-1 text-danger-text`,children:r1(o)}):(0,q.jsx)(`span`,{className:`min-w-0 flex-1`,children:Q$(a?`pushOn`:`pushOff`)}),(0,q.jsx)(P,{size:`sm`,variant:a?`secondary`:`primary`,loading:t,onClick:a?i:r,children:Q$(a?`turnOff`:o&&o.kind!==`off-not-stored`?`tryAgain`:`turnOn`)})]})},a1=3e4,o1=e=>Tn(e)&&e.status===403,s1=({enabled:e=!0}={})=>{let t=F();return Tt({queryKey:I.inboxUnread,queryFn:()=>t.notifications.unread(),refetchInterval:e=>!o1(e.state.error)&&a1,enabled:e})},c1=({enabled:e=!0}={})=>{let t=F(),n=mt({queryKey:I.inboxPages,queryFn:({pageParam:e})=>t.notifications.list(e===``?{}:{cursor:e}),initialPageParam:``,getNextPageParam:e=>e.next??void 0,enabled:e}),r=n.data?.pages.flatMap(e=>e.items)??[];return{...n,items:r}},l1=(e,t)=>{let n=new Date().toISOString(),r=0;e.setQueryData(I.inboxPages,e=>e&&{...e,pages:e.pages.map(e=>({...e,items:e.items.map(e=>e.readAt!==null||!t(e)?e:(r+=1,{...e,readAt:n}))}))}),e.setQueryData(I.inboxUnread,e=>e===void 0?e:Math.max(0,e-r))},u1=()=>{let e=F(),t=nn(),n=()=>t.invalidateQueries({queryKey:I.inbox}),r=en({mutationFn:t=>e.notifications.markRead(t.id),onMutate:e=>l1(t,t=>t.id===e.id),onSettled:n}),i=en({mutationFn:t=>e.notifications.markAllRead(t.createdAt),onMutate:e=>l1(t,t=>t.createdAt<=e.createdAt),onSettled:n}),a=r.mutate;return{markRead:(0,W.useCallback)(e=>{e.readAt===null&&a(e)},[a]),markAllRead:i.mutate,markingAll:i.isPending}},d1=99,f1=e=>e===void 0||e<=0?Q$(`notifications`):e>d1?Q$(`notificationsManyUnread`):Q$(`notificationsUnread`,{count:String(e)}),p1=()=>{let{open:e,setOpen:t,place:n,button:r,menu:i}=Gv(),a=s1(),o=c1({enabled:e}),{markRead:s,markAllRead:c,markingAll:l}=u1(),u=Z$(),{navigate:d,basePath:f}=le(),[p,m]=(0,W.useState)(Date.now),h=f1(a.data),g=window.location.origin;return o1(a.error)?null:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(P,{ref:r,size:`icon`,variant:`ghost`,"aria-label":h,title:h,"aria-haspopup":`dialog`,"aria-expanded":e,onClick:()=>{e||(m(Date.now()),a.refetch(),o.data&&o.refetch(),u.busy||u.refresh()),t(!e)},className:`relative max-md:size-9`,children:[(0,q.jsx)(nc,{className:`size-4 max-md:size-5`}),(0,q.jsx)(lj,{count:a.data,className:`pointer-events-none absolute -top-1 -right-1.5 max-md:top-0 max-md:right-0`})]}),e&&(0,ls.createPortal)((0,q.jsx)(`div`,{ref:i,role:`dialog`,"aria-label":f1(void 0),style:n??{visibility:`hidden`},className:`fixed z-50 w-[min(22rem,calc(100%-0.5rem))] rounded-md border bg-background shadow-pop`,children:(0,q.jsx)(t1,{items:o.items,loading:o.isPending,failed:o.isError,onRetry:()=>void o.refetch(),hasMore:o.hasNextPage,loadingMore:o.isFetchingNextPage,onMore:()=>void o.fetchNextPage(),onMarkAllRead:c,markingAll:l,targetOf:e=>n1(e.url,{origin:g,basePath:f}),onNavigate:e=>d(e),onOpen:e=>{s(e),t(!1)},footer:(0,q.jsx)(i1,{state:u.state,busy:u.busy,failure:u.failure,onTurnOn:()=>void u.turnOn(),onTurnOff:()=>void u.turnOff()}),now:p})}),document.body)]})},m1=({own:e})=>e?(0,q.jsx)(FS,{name:`shell.bell`,fallback:null,children:(0,q.jsx)(e,{})}):(0,q.jsx)(p1,{}),h1=(0,W.createContext)([]),g1=()=>(0,W.useContext)(h1),_1=({ui:e,children:t})=>{let{plugins:n=[]}=c(),{loads:r,settled:i}=XG(n,qG()),a=(0,W.useMemo)(()=>AG(e,r),[e,r]);return i?(0,q.jsx)(Ky.Provider,{value:a.ui,children:(0,q.jsx)(h1.Provider,{value:a.off,children:t})}):(0,q.jsxs)(`div`,{className:U(`flex h-full min-h-48 items-center justify-center gap-2 text-muted-foreground`,or),children:[(0,q.jsx)(ne,{}),(0,q.jsx)(wn,{}),` `,jG(`loading`)]})},v1=({off:e})=>{let[t,n]=(0,W.useState)(!1);return t||e.length===0?null:(0,q.jsxs)(`div`,{role:`region`,"aria-label":jG(`pluginsOff`),className:`flex items-start gap-3 border-b border-warning/40 bg-warning-soft px-4 py-2 text-warning-text`,children:[(0,q.jsx)(Ku,{"aria-hidden":!0,className:`mt-0.5 size-4 shrink-0`}),(0,q.jsx)(`ul`,{className:`min-w-0 flex-1 space-y-0.5 break-words`,children:e.map(e=>(0,q.jsx)(`li`,{children:jG.rich(`pluginOff`,{plugin:(0,q.jsx)(`span`,{className:`font-semibold`,children:e.name??e.url}),reason:e.reason})},e.url))}),(0,q.jsx)(`button`,{type:`button`,"aria-label":jG(`dismiss`),className:`rounded p-0.5 hover:bg-warning/10`,onClick:()=>n(!0),children:(0,q.jsx)(Ci,{"aria-hidden":!0,className:`size-4`})})]})},y1=(e,t)=>[`${t}_at`,`${t}At`].find(t=>e.fields[t]),b1=(e,t)=>e.sidebar?e.title?(0,q.jsx)(Jv,{title:e.title,children:t}):t:e.title?(0,q.jsx)(D_,{title:e.title,children:t}):(0,q.jsx)(`section`,{className:`py-8`,children:t}),x1=({item:e,scope:t,fallback:n})=>{let{components:r}=qy(),i=r?.[e.component],a=i&&(0,q.jsx)(Zw,{value:t,children:(0,q.jsx)(i,{...u(e.props??{})})});return n===void 0?b1(e,(0,q.jsx)(xU,{name:e.component,registered:!!i,fallback:void 0,children:a})):(0,q.jsx)(xU,{name:e.component,registered:!!i,fallback:n,children:b1(e,a)})},S1=({component:e,scope:t,standard:n})=>{let{components:r}=qy(),i=r?.[e];return i?(0,q.jsx)(FS,{name:e,fallback:n,children:(0,q.jsx)(C1,{children:(0,q.jsx)(Zw,{value:t,children:(0,q.jsx)(i,{})})})}):n},C1=({children:e})=>(OA(!1),(0,q.jsx)(`div`,{className:`grid min-h-0 flex-1 grid-cols-[minmax(0,1fr)] grid-rows-[minmax(0,1fr)]`,children:e})),w1=(0,W.createContext)(void 0),T1=()=>{let e=(0,W.useContext)(w1);if(!e)throw Error(`A focus part is used outside a FocusPage`);return e},E1=()=>{let e=(0,W.useContext)(w1);return e&&{size:e.size}},D1=B(`focus-page`),O1=2,k1=({action:e})=>{let t=e.icon,n=(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(t,{className:`size-3.5`,"aria-hidden":!0}),e.name]});return e.render&&!e.blocked?e.render({className:zn(),children:n}):(0,q.jsx)(P,{variant:e.tone===`danger`?`danger`:`secondary`,onClick:()=>!e.blocked&&e.onRun?.(),"aria-disabled":!!e.blocked,loading:e.running,title:e.blocked,children:n})},A1=(e,t)=>t===`wide`||t===`medium`?e.filter(e=>e.inBar).slice(0,O1):[],j1=()=>{let{store:e,size:t}=T1();return A1((0,W.useSyncExternalStore)(e.subscribe,e.actions),t).map(e=>(0,q.jsx)(k1,{action:e},e.name))},M1=()=>{let{store:e,size:t}=T1(),n=(0,W.useSyncExternalStore)(e.subscribe,e.actions),r=Tj(),i=h(),a=A1(n,t),o=n.filter(e=>!a.includes(e)),s=[...o.filter(e=>e.tone!==`danger`),...o.filter(e=>e.tone===`danger`)];return r&&!i?(0,ls.createPortal)((0,q.jsx)(Kv,{actions:s,label:D1(`more`),className:jj}),r):(0,q.jsx)(Kv,{actions:s,label:D1(`more`),className:zn({size:`icon`})})},N1=e=>e>=1100?`wide`:e>=950?`medium`:e>=720?`narrow`:`compact`,P1=(e,t=1)=>e>0&&t>0&&e-t*380<480,F1=[`refused`,`conflict`,`draft`,`info`],I1=e=>F1.indexOf(e),L1=()=>{let e=new Map,t=new Map,n=new Map,r=new Map,i=new Set,a=[],o,s=()=>{a=[...e.values()].flat(),o=[...t].sort(([,e],[,t])=>I1(e)-I1(t))[0]?.[0];for(let e of i)e()};return{subscribe:e=>(i.add(e),()=>{i.delete(e)}),actions:()=>a,notice:()=>o,filled:e=>(n.get(e)??0)>0,openPanels:()=>new Set(r.values()).size,openPanel:(e,t)=>(r.set(e,t),s(),()=>{r.delete(e),s()}),setActions:(t,n)=>{n?e.set(t,n):e.delete(t),s()},setNotice:(e,n)=>{n?t.set(e,n):t.delete(e),s()},fill:e=>(n.set(e,(n.get(e)??0)+1),s(),()=>{n.set(e,(n.get(e)??1)-1),s()})}},R1=e=>(0,W.useState)(()=>{let t=t=>n=>e(e=>e[t]===n?e:{...e,[t]:n});return{mode:t(`mode`),controls:t(`controls`),state:t(`state`),secondary:t(`secondary`),primary:t(`primary`),notice:t(`notice`),start:t(`start`),end:t(`end`)}})[0],z1=`flex min-w-0 shrink-0 items-center gap-2 empty:hidden`,B1=({label:e,children:t})=>{OA(!1);let[n]=(0,W.useState)(L1),[r,i]=(0,W.useState)({}),a=R1(i),[o,s]=Nk(),[c,l]=Nk(),u=N1(s),d=P1(l,(0,W.useSyncExternalStore)(n.subscribe,n.openPanels)),f=(0,W.useMemo)(()=>({store:n,hosts:r,size:u}),[n,r,u]);return(0,q.jsx)(w1.Provider,{value:f,children:(0,q.jsxs)(`section`,{"aria-label":e,className:`flex min-h-0 min-w-0 flex-1 flex-col`,children:[(0,q.jsx)(`h1`,{className:`sr-only`,children:e}),(0,q.jsxs)(`div`,{ref:o,role:`group`,"aria-label":D1(`tools`),className:`flex min-h-12 shrink-0 items-center gap-2 border-b bg-background px-3 max-md:min-h-14`,children:[(0,q.jsx)(`div`,{ref:a.mode,className:U(z1,`shrink`)}),(0,q.jsx)(`div`,{ref:a.controls,className:z1}),(0,q.jsx)(`div`,{className:`min-w-0 flex-1`}),(0,q.jsx)(`div`,{ref:a.state,className:U(z1,`shrink text-xs text-muted-foreground`)}),(0,q.jsx)(j1,{}),(0,q.jsx)(`div`,{ref:a.secondary,className:z1}),(0,q.jsx)(`div`,{ref:a.primary,className:z1}),(0,q.jsx)(M1,{})]}),(0,q.jsx)(`div`,{ref:a.notice,className:`shrink-0 empty:hidden`}),(0,q.jsxs)(`div`,{ref:c,className:`relative flex min-h-0 flex-1`,children:[(0,q.jsx)(`div`,{ref:a.start,className:U(`h-full shrink-0 empty:hidden`,d&&`absolute inset-y-0 left-0 z-10 shadow-pop`)}),(0,q.jsx)(`div`,{className:`relative isolate min-h-0 min-w-0 flex-1`,children:t}),(0,q.jsx)(`div`,{ref:a.end,className:U(`h-full shrink-0 empty:hidden`,d&&`absolute inset-y-0 right-0 z-10 shadow-pop`)})]})]})})},V1=({zone:e,fallback:t=!1,children:n})=>{let{store:r,hosts:i}=T1();(0,W.useLayoutEffect)(()=>t?void 0:r.fill(e),[r,e,t]);let a=H1(e),o=i[e];return o&&!(t&&a)?(0,ls.createPortal)(n,o):null},H1=e=>{let{store:t}=T1();return(0,W.useSyncExternalStore)(t.subscribe,()=>t.filled(e))},U1=({actions:e})=>{let{store:t}=T1(),n=(0,W.useId)();return(0,W.useLayoutEffect)(()=>t.setActions(n,e)),(0,W.useEffect)(()=>()=>t.setActions(n,void 0),[t,n]),null},W1={refused:`bg-danger-soft`,conflict:`bg-warning-soft`,draft:`bg-surface`,info:`bg-surface`},G1=({level:e,actions:t,children:n})=>{let{store:r,hosts:i}=T1(),a=(0,W.useId)();(0,W.useLayoutEffect)(()=>(r.setNotice(a,e),()=>r.setNotice(a,void 0)),[r,a,e]);let o=(0,W.useSyncExternalStore)(r.subscribe,r.notice)===a,s=i.notice;return!o||!s?null:(0,ls.createPortal)((0,q.jsxs)(`div`,{role:e===`refused`||e===`conflict`?`alert`:`status`,className:U(`flex flex-wrap items-center gap-x-3 gap-y-2 border-b px-3 py-2 text-body`,W1[e]),children:[(0,q.jsx)(`div`,{className:`min-w-0 flex-1 basis-48`,children:n}),t&&(0,q.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:t})]}),s)},K1=({side:e=`end`,title:t,icon:n,status:r,onClose:i,footer:a,takesFocus:o=!1,children:s})=>{let{hosts:c,store:l}=T1(),u=c[e],d=(0,W.useId)();(0,W.useLayoutEffect)(()=>l.openPanel(d,e),[l,d,e]);let f=(0,W.useRef)(null),[p]=(0,W.useState)(()=>document.activeElement),m=!!u;return(0,W.useEffect)(()=>{if(o&&m)return f.current?.contains(document.activeElement)||f.current?.focus(),()=>{p instanceof HTMLElement&&p.isConnected&&p.focus()}},[o,m,p]),u?(0,ls.createPortal)((0,q.jsx)(hq,{title:t,icon:n,status:r,onClose:i,footer:a,children:(0,q.jsx)(`div`,{ref:f,tabIndex:-1,className:`min-h-0 flex-1 overflow-y-auto p-4 outline-none`,onKeyDown:e=>{e.key===`Escape`&&(e.stopPropagation(),i())},children:s})}),u):null},q1=(e,t,n)=>`protobase:draft:${e}:${t}:${n}`,J1=(e,t,n)=>i(()=>{let r=e.getItem(t);if(r===null)return;let i=JSON.parse(r);if(i&&i.etag===n&&typeof i.fields==`object`&&i.fields!==null)return{etag:n,fields:i.fields,...Array.isArray(i.order)&&{order:i.order.map(String)}}},void 0),Y1=(e,t,n)=>i(()=>n?e.setItem(t,JSON.stringify(n)):e.removeItem(t),void 0),X1=e=>VF(e)??_f,Z1=({model:e,stored:t,recordKey:n,edit:r,onDelete:i})=>{let a=Me(),{go:o}=a,s={model:e,record:t.record,key:n,etag:t.etag,permissions:t.permissions},c=yT(e.name,s,t=>t.run?.kind===`delete`&&o({kind:`list`,resource:e.name},{replace:!0})),[l,u]=(0,W.useState)(),d=c.actions.map(e=>{let n=c.blocked(e),r=e.run?.kind===`link`&&!n?gB(e.run,t.record,a):void 0;return{name:e.label,icon:X1(e.icon),blocked:n,running:c.running===e.name,...zw(e)&&{tone:`danger`},onRun:()=>Bw(e)?u(e):void c.run(e),...r&&{render:({className:e,children:t,role:n})=>(0,q.jsx)(Jn,{to:r,role:n,className:e,children:t})}}}),f=c.actions.some(e=>e.run?.kind===`delete`);return{actions:[...r?[{name:nJ(`edit`),icon:Au,render:({className:e,children:t,role:n})=>(0,q.jsx)(Ue,{to:r,role:n,className:e,children:t})}]:[],...d,...i&&!f?[{name:nJ(`delete`),icon:Wd,tone:`danger`,onRun:i}]:[]],prompt:l&&(0,q.jsx)(Vw,{action:l,label:l.label,danger:zw(l),records:[t.record],onCancel:()=>u(void 0),onConfirm:()=>{u(void 0),c.run(l)},onSubmit:async e=>{await c.submit(l,e),u(void 0)}})}},Q1=e=>{let t=Tj(),{actions:n,prompt:r}=Z1(e);return n.length===0?null:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`div`,{className:t?`max-md:hidden`:void 0,children:(0,q.jsx)(Iv,{actions:n})}),t&&(0,ls.createPortal)((0,q.jsx)(Kv,{actions:n,label:nJ(`recordActions`),className:`inline-flex size-[min(2.75rem,max(44px,13vw))] shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-muted md:hidden [&_svg]:size-[min(1.25rem,max(20px,6vw))]`}),t),r]})},$1=(e,t)=>{let n=F(),r=nn(),i=Nn(t);return en({mutationFn:({patch:r,etag:i})=>n.update(e,t,r,i),onSuccess:t=>{r.setQueryData(I.record(e,i),t),r.invalidateQueries({queryKey:[`page`,e]}),r.invalidateQueries({queryKey:[`list`,e]}),r.invalidateQueries({queryKey:[`map`,e]}),r.invalidateQueries({queryKey:[`count`,e]}),r.invalidateQueries({queryKey:[`aggregate`,e]}),r.invalidateQueries({predicate:t=>t.queryKey[0]===`plan`&&Dn(t.queryKey,new Set([e]))})}})},e0=e=>e instanceof kn,t0=e=>{let t=typeof e.resource==`string`?e.resource:e.resource.toModel().name;return e.op===`reorder`?`reorder ${t} by ${e.field}`:`${e.op} ${t}`},n0=(e,t)=>{let n=e.operation,r=n===void 0?void 0:t[n];return r?R(`operationFailed`,{index:n+1,label:t0(r),message:e.message}):R(`nothingSaved`,{message:e.message})},r0=(e,t)=>new e.constructor({...e.problem,detail:n0(e,t)}),i0=(e,t)=>Object.fromEntries(Object.entries(e).filter(([e])=>e!==t)),a0=({model:e,stored:t,recordKey:n,mode:r,subject:i,draftKey:a,lines:o})=>{let s=F(),c=nn(),l=$1(e.name,n),u=lJ(r,i),[d]=(0,W.useState)(()=>a?J1(localStorage,a,t.etag):void 0),[f,p]=(0,W.useState)(d?.fields??{}),[m,h]=(0,W.useState)(!!d),[g,_]=(0,W.useState)(!1),[v,y]=(0,W.useState)({}),[b,x]=(0,W.useState)({}),[S,C]=(0,W.useState)(0),w=Object.entries(f).filter(([n,r])=>uy(e.fields[n],r,t.record[n])),T=w.length>0,E=T||!!o?.dirty;(0,W.useEffect)(()=>{d?.order&&o?.setOrder(d.order)},[]),(0,W.useEffect)(()=>{if(!a)return;let n=Object.fromEntries(Object.entries(f).filter(([t])=>!e.fields[t]?.sensitive)),r=Object.keys(n).length>0||!!o?.order;Y1(localStorage,a,r?{etag:t.etag,fields:n,...o?.order&&{order:o.order}}:void 0)},[a,e,f,o?.order,t.etag]);let D=n=>n in f?f[n]:[`boolean`,`file`].includes(e.fields[n].type)?t.record[n]:$v(t.record[n]),O=(n,r)=>{x(e=>i0(e,n));let i=typeof r==`string`?r!==$v(t.record[n]):uy(e.fields[n],r,t.record[n]);p(e=>i?{...e,[n]:r}:i0(e,n))},k=async()=>{let r=await s.get(e.name,n);c.setQueryData(I.record(e.name,n),r);let i={},a={};for(let[n,o]of Object.entries(f)){let s=e.fields[n];uy(s,o,r.record[n])&&(a[n]=o,$v(r.record[n])!==$v(t.record[n])&&(i[n]=s.type===`file`?Lr(s,r.record[n]):$v(r.record[n])))}p(a),y(i)},ee=()=>Object.fromEntries(w.map(([t,n])=>[t,sy(e.fields[t],n)])),A=e=>{let t=hA(e);x(t),Object.keys(t).length>0&&C(e=>e+1)},te=async()=>{try{await l.mutateAsync({patch:ee(),etag:t.etag})}catch(e){throw e0(e)?await k():Tn(e)&&A(e),e}},ne=async r=>{let i=T?[{op:`update`,resource:e.name,key:n,data:ee(),etag:t.etag}]:[],a=[...i,...r.ops];try{await s.batchWrite(a)}catch(e){if(e0(e))await k(),await c.invalidateQueries({queryKey:[`list`]}),_(!0);else if(Tn(e)){let t=e.operation===void 0?-1:e.operation-i.length,n=r.rows[t];t<0?A(e):n&&o?.reject(n,e)}throw Tn(e)?r0(e,a):e}await Promise.all([c.invalidateQueries({queryKey:I.record(e.name,n)}),c.invalidateQueries({queryKey:[`list`]}),c.invalidateQueries({queryKey:[`page`]}),c.invalidateQueries({queryKey:[`map`]}),c.invalidateQueries({queryKey:[`aggregate`]})]),o?.reset()};return{value:D,change:O,save:()=>u.run(async()=>{let e=o?.plan();e&&e.ops.length>0?await ne(e):await te(),p({}),y({}),x({}),_(!1),h(!1)}),dirty:E,discard:()=>{p({}),y({}),x({}),_(!1),h(!1),o?.reset()},restored:m&&E,dismissRestored:()=>h(!1),linesConflict:g,saving:u.phase===`saving`,phase:u.phase,message:u.message,conflicts:v,errors:b,rejections:S,keepMine:e=>y(t=>i0(t,e)),useTheirs:e=>{y(t=>i0(t,e)),p(t=>i0(t,e))}}},o0=B(`focus-record`),s0=({fields:e,onKeepMine:t,onUseTheirs:n})=>(0,q.jsx)(q.Fragment,{children:e.map(({name:e,label:r})=>[(0,q.jsx)(P,{size:`sm`,onClick:()=>t(e),children:o0(`keepMine`,{field:r})},`mine:${e}`),(0,q.jsx)(P,{size:`sm`,onClick:()=>n(e),children:o0(`useTheirs`,{field:r})},`theirs:${e}`)])}),c0=({record:e,label:t})=>{let{dirty:n,saving:r,save:i}=e,a=H1(`primary`),o=E1()?.size===`compact`,s=(0,q.jsx)(P,{variant:!a||n?`primary`:`secondary`,loading:r,"aria-disabled":!n,className:`max-md:min-h-11`,onClick:()=>void(n&&!r&&i()),children:t});return o&&!n?null:a?(0,q.jsx)(V1,{zone:`secondary`,children:s}):(0,q.jsx)(V1,{zone:`primary`,fallback:!0,children:s})},l0=({record:e,saved:t,readOnly:n})=>{let r=E1()?.size,i=n?o0(`readOnly`):e.saving?o0(`saving`):e.dirty?o0(r===`wide`?`unsaved`:`unsavedShort`):t?o0(`saved`):void 0;return i?(0,q.jsx)(V1,{zone:`state`,fallback:!0,children:(0,q.jsxs)(`span`,{role:`status`,title:n?o0(`readOnlyWhy`):void 0,className:`flex items-center gap-1 truncate`,children:[!n&&!e.dirty&&!e.saving&&(0,q.jsx)(xi,{className:`size-3.5 text-success-text`,"aria-hidden":!0}),i]})}):null},u0=({model:e,recordKey:t,stored:n,page:r})=>{let i=c().views[e.name],{address:a,go:o}=Me(),s=Qy()(e,i,n.record,t),{state:l}=Y(),u=a0({model:e,stored:n,recordKey:t,mode:`button`,subject:s,draftKey:l.kind===`signed-in`?`${q1(l.user.id,e.name,t)}:focus`:void 0});we(u.dirty||u.saving),In(u.dirty);let d=nn(),[f,p]=(0,W.useState)(!1),m=i?.names?.singular??H(e.name),h=re(e.name),g=MJ(e),_=a?.kind===`record`&&a.version!==void 0&&a.version!==Number(n.record.version),v=`surface`in r&&(oS(n.permissions,r.surface)===`read`||e.fields[r.surface]?.readOnly===!0),y=iS(h,`update`)&&n.permissions?.update!==!1&&!v,b=!y||_,x=iS(h,`delete`)&&n.permissions?.delete!==!1,S=jJ({model:e,view:i,restore:g,onDeleted:()=>o({kind:`list`,resource:e.name},{replace:!0}),onReview:()=>void d.invalidateQueries({queryKey:I.record(e.name,t)})}),{actions:C,prompt:w}=Z1({model:e,stored:n,recordKey:t,onDelete:x?()=>void S.start({key:t,title:s,etag:n.etag,snapshot:n.record}):void 0}),T=(0,W.useMemo)(()=>({kind:`record`,resource:e.name,key:t,standard:!0}),[e.name,t]),E=C.filter(e=>e.tone===`danger`),D=[...C.filter(e=>e.tone!==`danger`),...u.dirty?[{name:o0(`discardChanges`),icon:Kd,onRun:()=>p(!0)}]:[],{name:o0(`detailsOf`,{noun:m}),icon:Jl,render:({className:e,children:t,role:n})=>(0,q.jsx)(Ue,{to:T,role:n,className:e,children:t})},...E],O={model:e,record:n.record,key:t,...n.etag!==void 0&&{etag:n.etag},...n.permissions&&{permissions:n.permissions},readOnly:b,mayUpdate:y,value:u.value,change:(e,t)=>b?void 0:u.change(e,t),dirty:u.dirty,saving:u.saving,refused:u.message!==void 0,save:async()=>!b&&!!await u.save(),discard:u.discard,details:T},k=`surface`in r?r.surface:void 0,ee=f&&u.dirty&&(0,q.jsx)(G1,{level:`draft`,actions:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(P,{size:`sm`,variant:`danger`,onClick:()=>{u.discard(),p(!1)},children:o0(`discardChanges`)}),(0,q.jsx)(P,{size:`sm`,onClick:()=>p(!1),children:o0(`keep`)})]}),children:o0(`discardAsk`)}),A=Object.keys(u.conflicts).length>0,te=k?u.errors[k]:void 0,ne=te&&k?mA(e.fields[k],i?.fields[k]?.label??H(k),te):void 0;return(0,q.jsxs)(Qb.Provider,{value:O,children:[!b&&(0,q.jsx)(c0,{record:O,label:o0(`save`)}),(0,q.jsx)(l0,{record:O,saved:u.phase===`saved`,readOnly:b}),(0,q.jsx)(U1,{actions:D}),u.message&&!f&&(0,q.jsxs)(G1,{level:`refused`,actions:(0,q.jsx)(Ue,{to:T,className:`text-body font-medium text-primary-text hover:underline`,children:o0(`detailsOf`,{noun:m})}),children:[(0,q.jsx)(`strong`,{className:`font-medium`,children:o0(`notSaved`)}),` `,ne??u.message]}),A&&(0,q.jsx)(G1,{level:`conflict`,actions:(0,q.jsx)(s0,{fields:Object.keys(u.conflicts).map(e=>({name:e,label:i?.fields[e]?.label??H(e)})),onKeepMine:u.keepMine,onUseTheirs:u.useTheirs}),children:o0(`conflict`)}),ee,u.restored&&!f&&(0,q.jsx)(G1,{level:`draft`,actions:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(P,{size:`sm`,onClick:u.dismissRestored,children:o0(`keep`)}),(0,q.jsx)(P,{size:`sm`,onClick:u.discard,children:o0(`discard`)})]}),children:o0(`restored`)}),k?(0,q.jsx)(d0,{model:e,name:k,stored:n,editor:u,readOnly:b}):(0,q.jsx)(f0,{name:r.component,model:e,stored:n,recordKey:t}),S.dialogs,w]})},d0=({model:e,name:t,stored:n,editor:r,readOnly:i})=>{let a=c().views[e.name]?.fields[t];if(oS(n.permissions,t)===`hidden`)throw Error(`The surface's field ${t} is hidden from this reader`);return(0,q.jsx)(`div`,{className:`absolute inset-0`,children:(0,q.jsx)(GC,{field:e.fields[t],hints:a,value:r.value(t),stored:n.record[t],locked:i,invalid:!!r.errors[t],resource:e.name,onChange:e=>r.change(t,e)})})},f0=({name:e,model:t,stored:n,recordKey:r})=>{let i=qy().components?.[e];if(!i)throw Error(`No component is registered as ${e}`);return(0,q.jsx)(`div`,{className:`absolute inset-0`,children:(0,q.jsx)(Zw,{value:{model:t,record:n.record,key:r,etag:n.etag,permissions:n.permissions},children:(0,q.jsx)(i,{})})})},p0=({model:e,recordKey:t,stored:n,page:r,standard:i})=>{let a=Qy()(e,c().views[e.name],n.record,t);return(0,q.jsx)(FS,{name:`surface`in r?r.surface:r.component,fallback:i,resetKey:e,children:(0,q.jsx)(B1,{label:a,children:(0,q.jsx)(u0,{model:e,recordKey:t,stored:n,page:r})})})},m0=(0,W.lazy)(()=>Ht(()=>import(`./record-map-BSsmZmbf.js`).then(e=>({default:e.RecordMap})),__vite__mapDeps([55,1,3,48,14,6,5,49,50,51,52,53]))),h0=15,g0=({item:e,record:t})=>{let n=c().maps,r=n?.style,i=kz(t,e);if(!r||!i)return null;let a=(0,q.jsx)(`div`,{className:`overflow-hidden rounded-lg border border-border bg-muted ${e.sidebar?`h-48`:`h-64 md:h-80`}`,children:(0,q.jsx)(W.Suspense,{fallback:null,children:(0,q.jsx)(m0,{style:r,layers:n?.layers,position:i,zoom:e.zoom??h0},`${i.latitude},${i.longitude}`)})});return e.sidebar?(0,q.jsx)(Jv,{title:e.title,children:a}):(0,q.jsx)(D_,{title:e.title,children:a})},_0={"1h":`minute`,"24h":`5_minutes`,"7d":`hour`},v0=(e,t,n)=>{let r=new Map;e.forEach((e,i)=>{for(let a of e){let e=Date.parse(`${String(a.value)}Z`),o=r.get(e)??{at:e,value:null,count:0};o[t[i]]=a[n]??null,o.count=Math.max(o.count,a.count),r.set(e,o)}});let i=Object.fromEntries(t.map(e=>[e,null]));return[...r.values()].sort((e,t)=>e.at-t.at).map(e=>({...i,...e}))},y0=B(`app/record-chart`),b0=m(),x0=[`1h`,`24h`,`7d`],S0={"1h":`hour`,"24h":`day`,"7d":`week`},C0=({item:e,recordKey:t})=>{let{resources:n,views:r}=c(),[i,a]=(0,W.useState)(e.range??`1h`),[o,s]=(0,W.useState)(`average`),l=n[e.resource],u=r[e.resource],d=_0[i],f=vn(b0.eq(e.field,t)),p=e.series.map(t=>({groupBy:e.at,filter:f,...o===`average`?{average:t}:{maximum:t},range:i,granularity:d,timeZone:Hn()})),m=TE(e.resource,p,!!l);if(!l)return null;let h=e.series.map(e=>({kind:o,field:l.fields[e],...u?.fields[e]&&{hints:u.fields[e]}})),g=e.series.map((e,t)=>({key:`s${t}`,label:u?.fields[e]?.label??H(e),color:`var(--chart-${t+1})`,measure:h[t]})),_=m.every(e=>e.data)?v0(m.map(e=>e.data.groups),g.map(e=>e.key),o):[],v=(0,q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,q.jsx)(Av,{label:y0(`measure`),value:o,onChange:s,options:[{value:`average`,label:y0(`average`)},{value:`maximum`,label:y0(`maximum`)}]}),(0,q.jsx)(Av,{label:y0(`range`),value:i,onChange:a,options:x0.map(e=>({value:e,label:y0(S0[e])}))})]});return(0,q.jsx)(D_,{title:e.title,help:e.help,actions:v,children:m.some(e=>e.error)?(0,q.jsx)(`p`,{className:`text-danger-text`,children:y0(`couldNotLoad`)}):m.some(e=>e.isPending)?(0,q.jsx)(L,{className:`h-40 w-full`}):_.every(e=>e.count===0)?(0,q.jsx)(`p`,{className:`text-muted-foreground`,children:y0(`noSamples`)}):(0,q.jsx)(pD,{points:_,measure:h[0],bucket:d,type:`line`,series:g,...g.length>1&&{resource:e.resource,view:u}})})},w0=B(`app/record-trend`),T0=(e,t)=>w0(`total_${t}`,{count:e}),E0=m(),D0={kind:`count`},O0=({item:e,recordKey:t})=>{let n=vn(E0.eq(e.field,t)),r=wE(e.resource,{groupBy:e.at,filter:n,granularity:e.granularity,range:e.range,timeZone:Hn()});return(0,q.jsx)(D_,{title:e.title,help:e.help,children:(0,q.jsx)(`div`,{"aria-busy":r.isPending,children:(()=>{if(r.isPending)return(0,q.jsx)(L,{className:`h-[calc(10rem+2rem)] w-full`});if(r.error)return(0,q.jsx)(Oy,{title:w0(`couldNotLoad`),error:r.error,onRetry:()=>void r.refetch()});let t=r.data.groups.reduce((e,t)=>e+t.count,0);return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`p`,{className:`mb-3 leading-5 text-foreground`,children:T0(t,e.range)}),(0,q.jsx)(pD,{points:PE(r.data.groups,D0),measure:D0,bucket:e.granularity,type:`bar`})]})})()})})},k0=(e=[],t)=>e.includes(t)?e.filter(e=>e!==t):[...e,t],A0=(e,t=[],n)=>!e.collapsed||t.includes(e.title)||e.items.some(e=>e.kind===`section`&&e.fields.some(n)),j0=e=>{let t=e.findIndex(e=>e.kind===`tab`);if(t===-1)return{before:e,tabs:[],after:[]};let n=[];for(let r of e.slice(t)){if(r.kind!==`tab`)break;n.push(r)}return{before:e.slice(0,t),tabs:n,after:e.slice(t+n.length)}},M0=(e,t)=>e.find(e=>e.title===t)??e[0],N0=e=>za(e.items).flatMap(e=>e.kind===`section`?e.fields:[]),P0=(e,t,n)=>{if(t&&!N0(t).some(n))return e.find(e=>N0(e).some(n))},F0=e=>e.width??`minmax(8rem,1fr)`,I0=e=>({"--line-columns":e.map(F0).join(` `)}),L0=e=>`${e.reduce((e,t)=>e+(t.width?.endsWith(`px`)?parseInt(t.width)/16:8),6)}rem`,R0=`grid grid-cols-[28px_var(--line-columns)_32px] items-center gap-2 pointer-coarse:grid-cols-[44px_var(--line-columns)_44px]`,z0=({items:e,label:t})=>{let[n,r]=(0,W.useState)(!1),i=(0,W.useRef)(null),a=(0,W.useRef)(null),o=Bv(n,i,a),s=Uv(n,i,a,o?.right);return(0,W.useEffect)(()=>{if(!n)return;let e=e=>{(e instanceof KeyboardEvent?e.key===`Escape`:!i.current?.contains(e.target))&&r(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,e),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,e)}},[n]),(0,q.jsxs)(`div`,{ref:i,className:`relative flex justify-center`,children:[(0,q.jsx)(`button`,{type:`button`,"aria-label":t,"aria-haspopup":`menu`,"aria-expanded":n,onClick:()=>r(!n),className:`inline-flex size-7 items-center justify-center rounded text-faint-foreground hover:bg-muted hover:text-foreground pointer-coarse:size-11`,children:(0,q.jsx)(il,{className:`size-4`})}),n&&(0,q.jsx)(`ul`,{ref:a,role:`menu`,style:{...o,...s},className:`absolute right-0 top-full z-30 mt-1 w-max min-w-36 rounded-md border bg-background py-1 shadow-pop`,children:e.map(e=>(0,q.jsx)(`li`,{role:`none`,children:(0,q.jsx)(`button`,{type:`button`,role:`menuitem`,disabled:e.disabled,className:U(`block min-h-9 w-full px-3 py-1.5 text-left hover:bg-muted disabled:text-faint-foreground disabled:hover:bg-transparent`,e.destructive&&`text-danger-text`),onClick:()=>{r(!1),e.onSelect()},children:e.label})},e.label))})]})},B0=B(`inline-child-table`),V0=({line:e,name:t,columns:n,position:r,count:i,reorderable:a,onRemove:o,onMove:s,error:c})=>{let{attributes:l,listeners:u,setNodeRef:d,setActivatorNodeRef:f,transform:p,transition:m,isDragging:h}=rn({id:e.id,disabled:!a}),g=[...a?[{label:B0(`moveUp`),disabled:r===0,onSelect:()=>s(r-1)},{label:B0(`moveDown`),disabled:r===i-1,onSelect:()=>s(r+1)}]:[],...o?[{label:B0(`removeLine`),destructive:!0,onSelect:o}]:[]];return(0,q.jsxs)(`div`,{ref:d,"data-line-id":e.id,"aria-invalid":c?!0:void 0,style:{transform:p?`translate3d(0, ${p.y}px, 0)`:void 0,transition:m},className:U(`group relative border-b border-border bg-background px-2 py-1 last:border-b-0 hover:bg-surface`,R0,h&&`z-10 bg-surface opacity-80 shadow-pop`,c&&`bg-danger-soft`),children:[a?(0,q.jsx)(`button`,{ref:f,type:`button`,"aria-label":B0(`dragToReorder`,{name:t}),...l,...u,style:{touchAction:`none`},className:`flex size-7 cursor-grab items-center justify-center rounded text-faint-foreground opacity-60 hover:bg-muted hover:opacity-100 focus-visible:opacity-100 active:cursor-grabbing pointer-coarse:size-11`,children:(0,q.jsx)(bl,{className:`size-4`})}):(0,q.jsx)(`span`,{}),n.map(t=>(0,q.jsx)(`div`,{className:U(`min-w-0`,t.align===`right`&&`text-right`),children:t.cell(e)},t.key)),g.length>0?(0,q.jsx)(z0,{label:B0(`actionsFor`,{name:t}),items:g}):(0,q.jsx)(`span`,{}),c&&(0,q.jsx)(`p`,{role:`alert`,className:`col-span-full px-2 pb-1 text-xs text-danger-text`,children:c})]})},H0=(e,t,n)=>{if(t===n||t<0||t>=e.length)return[...e];let r=[...e],[i]=r.splice(t,1);return r.splice(Math.min(Math.max(n,0),r.length),0,i),r},U0=`px-2 text-[0.6875rem] font-medium uppercase tracking-wide text-muted-foreground`,W0=(e,t)=>{let n=n=>{let r=e.find(e=>e.id===n);return r?t(r):B0(`line`)},r=t=>e.findIndex(e=>e.id===t)+1;return{onDragStart:({active:t})=>B0(`pickedUp`,{name:n(t.id),place:r(t.id),count:e.length}),onDragOver:({active:t,over:i})=>i?B0(`over`,{name:n(t.id),place:r(i.id),count:e.length}):void 0,onDragEnd:({active:t,over:i})=>i?B0(`dropped`,{name:n(t.id),place:r(i.id),count:e.length}):B0(`droppedAtStart`,{name:n(t.id)}),onDragCancel:({active:e})=>B0(`cancelled`,{name:n(e.id),place:r(e.id)})}},G0=({lines:e,columns:t,lineName:n,onReorder:r,reorderable:i=!!r,onAdd:a,onRemove:o,removable:s=()=>!0,lineError:c,footer:l})=>{let u=At(gn(It,{activationConstraint:{distance:4}}),gn($t,{activationConstraint:{delay:250,tolerance:5}}),gn(Pt,{coordinateGetter:Zt})),d=(t,n)=>{let i=e[t];!i||!r||n<0||n>=e.length||t===n||r(H0(e,t,n),{id:i.id,from:t,to:n})};return(0,q.jsxs)(`div`,{children:[(0,q.jsxs)(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,style:I0(t),children:[(0,q.jsxs)(`div`,{className:`${R0} border-b border-border bg-surface px-2 py-2`,children:[(0,q.jsx)(`span`,{}),t.map(e=>(0,q.jsx)(`span`,{className:U(U0,e.align===`right`&&`text-right`),children:e.label},e.key)),(0,q.jsx)(`span`,{})]}),e.length===0&&(0,q.jsx)(`p`,{className:`px-4 py-3 text-muted-foreground`,children:B0(`noLines`)}),(0,q.jsx)(Kt,{sensors:u,collisionDetection:Jt,onDragEnd:({active:t,over:n})=>{n&&t.id!==n.id&&d(e.findIndex(e=>e.id===t.id),e.findIndex(e=>e.id===n.id))},accessibility:{announcements:W0(e,n),screenReaderInstructions:{draggable:B0(`instructions`)}},children:(0,q.jsx)(Vt,{items:e.map(e=>e.id),strategy:Mt,children:e.map((r,a)=>(0,q.jsx)(V0,{line:r,name:n(r),columns:t,position:a,count:e.length,reorderable:i,onRemove:o&&s(r)?()=>o(r):void 0,onMove:e=>d(a,e),error:c?.(r)},r.id))})}),a&&(0,q.jsx)(`div`,{className:`border-t border-border bg-surface px-2 py-1.5`,children:(0,q.jsxs)(P,{variant:`ghost`,size:`sm`,onClick:a,children:[(0,q.jsx)(Hu,{className:`size-3.5`}),B0(`addLine`)]})})]}),l]})},K0=({field:e,hints:t,label:n,lineNumber:r,resource:i,value:a,stored:o,relationLabel:s,relationTo:c,relationPicker:l,locked:u,problem:d,onChange:f})=>{let p=(0,W.useId)(),m=d&&mA(e,n,d);return(0,q.jsxs)(wi.Provider,{value:{id:p,invalid:!!d,required:!1,...m&&{describedBy:`${p}-error`}},children:[(0,q.jsx)(`label`,{htmlFor:p,className:`sr-only`,children:nJ(`lineField`,{label:n,place:r})}),(0,q.jsx)(GC,{field:e,hints:t,value:a,stored:o,relationLabel:s,relationTo:c,relationPicker:l,locked:u,invalid:!!d,resource:i,onChange:f}),m&&(0,q.jsx)(`p`,{id:`${p}-error`,className:`px-1 pt-0.5 text-xs text-danger-text`,children:m})]})},q0=(e,t,n,r,i)=>{let a=tx(e?.name??``,{enabled:!!(e&&t),filter:t?`${t.name} = "${r}"`:void 0,pageSize:500,labels:i,...n&&e?.fields[n]?.sortable&&{orderBy:`${n} asc`}}),o=(0,W.useMemo)(()=>n?[...a.items].sort((e,t)=>Number(e[n])-Number(t[n])):a.items,[a.data,n]),s=a.hasNextPage&&a.items.length<1e3;return(0,W.useEffect)(()=>{s&&!a.isFetchingNextPage&&a.fetchNextPage()},[s,a.isFetchingNextPage]),{items:o,labels:a.labels,loading:(a.isPending||s)&&!!e,complete:!a.hasNextPage}},J0=({lines:e,editable:t,saving:n})=>{let{resources:r,views:i}=c(),{item:a,model:o,columns:s,data:l,draft:u}=e,d=re(o.name),f=i[o.name],[p,m]=(0,W.useState)({}),h=t&&l.complete&&!l.loading&&!n,g=h&&iS(d,`update`),_=h&&iS(d,`create`),v=h&&iS(d,`delete`),y=e=>e.stored?g&&aS(e.stored,`update`):_,b=e=>u.shown.indexOf(e)+1,x=e=>u.rejection?.id===e.id?u.rejection:void 0,S=s.map(e=>{let t=o.fields[e],n=f?.fields[e],a=n?.label??H(e),s=t.relation?r[t.relation.resource]:void 0,c=s&&s.primaryKey.length===1?s:void 0;return{key:e,label:a,...[`integer`,`bigint`,`decimal`].includes(t.type)&&{align:`right`,width:`minmax(6rem,0.6fr)`},cell:r=>{let s=u.value(r.id,e),d=s==null||s===``?void 0:String(s);return(0,q.jsx)(K0,{field:t,hints:n,label:a,lineNumber:b(r),resource:o.name,value:s,stored:r.stored?.[e],relationLabel:d===void 0?void 0:p[`${r.id}/${e}`]??l.labels[e]?.[d],relationTo:c&&d!==void 0?{kind:`record`,resource:c.name,key:d}:void 0,relationPicker:c&&{target:c,view:i[c.name]},locked:!y(r),problem:x(r)?.fields[e],onChange:t=>{if(!c||!gy(t))return u.change(r.id,e,t);m(n=>({...n,[`${r.id}/${e}`]:t.label})),u.change(r.id,e,yy(c,t.key))}})}}});return(0,q.jsxs)(D_,{title:a.title,help:a.help,children:[!l.complete&&(0,q.jsx)(`p`,{className:`mb-2 text-muted-foreground`,children:nJ(`tooManyLines`,{limit:k_(1e3)})}),(0,q.jsx)(`div`,{className:`-mx-4 overflow-x-auto px-4 [-webkit-overflow-scrolling:touch] md:mx-0 md:px-0`,children:(0,q.jsx)(`div`,{style:{minWidth:L0(S)},children:(0,q.jsx)(G0,{lines:u.shown,columns:S,lineName:e=>ke(o,f,e.stored??{},``)||nJ(`lineNumber`,{place:b(e)}),onReorder:e=>u.setOrder(e.map(e=>e.id)),reorderable:g,onAdd:_?()=>void u.add():void 0,onRemove:_||v?e=>u.remove(e.id):void 0,removable:e=>e.stored?v&&aS(e.stored,`delete`):_,lineError:e=>{let t=x(e);if(t&&!s.some(e=>t.fields[e]))return t.message}})})})]})},Y0={added:[],edits:{},removed:[]},X0=(e,t)=>{let n=[...e.filter(e=>!t.removed.includes(e)),...t.added];return t.order?[...t.order.filter(e=>n.includes(e)),...n.filter(e=>!t.order.includes(e))]:n},Z0=(e,t,n)=>Object.fromEntries(Object.entries(t).flatMap(([t,r])=>{let i=e.fields[t];return i&&uy(i,r,n[t])?[[t,sy(i,r)]]:[]})),Q0=(e,t)=>Object.fromEntries(Object.entries(t).flatMap(([t,n])=>{let r=e.fields[t];return!r||r.type!==`boolean`&&String(n??``).trim()===``?[]:[[t,sy(r,n)]]})),$0=({model:e,position:t,link:n,stored:r,state:i})=>{let a={ops:[],rows:[]},o=(e,t)=>{a.ops.push(e),a.rows.push(t)},s=new Map(r.map(t=>[Nr(e,t),t])),c=[...s.keys()],l=X0(c,i),u=t=>xr(e,s.get(t)),d=e=>{let t=s.get(e).etag;return typeof t==`string`?t:void 0};for(let t of i.removed){if(!s.has(t))continue;let n=d(t);o({op:`delete`,resource:e.name,key:u(t),...n&&{etag:n}},t)}let f=new Set;for(let[t,n]of Object.entries(i.edits)){if(!s.has(t)||i.removed.includes(t))continue;let r=Z0(e,n,s.get(t));if(Object.keys(r).length===0)continue;let a=d(t);o({op:`update`,resource:e.name,key:u(t),data:r,...a&&{etag:a}},t),f.add(t)}let p=l.filter(e=>s.has(e)),m=l.filter(e=>!s.has(e)),h=(e,t)=>Object.fromEntries(e.flatMap(e=>{let n=t||f.has(e)?`*`:d(e);return n?[[Nn(u(e)),n]]:[]})),g=(n,r,i)=>({op:`reorder`,resource:e.name,field:t,keys:n,...r!==1&&{start:r},etags:i}),_=(r,a,o)=>({op:`create`,resource:e.name,data:{...Q0(e,i.edits[r]??{}),[n.field]:n.value,[t]:a},...o&&{ref:o}}),v=e=>Number(e[t])||0,y=p.some((e,t)=>e!==c.filter(e=>p.includes(e))[t]);if(m.every(e=>l.indexOf(e)>=p.length)){y&&o(g(p.map(u),1,h(p,!1)));let e=y?p.length:Math.max(0,...p.map(e=>v(s.get(e))));return m.forEach((t,n)=>o(_(t,e+1+n),t)),a}let b=Math.max(l.length,...r.map(v))+1;p.length>0&&o(g(p.map(u),b,h(p,!1)));let x=e=>`line${m.indexOf(e)+1}`;for(let e of m)o(_(e,l.indexOf(e)+1,x(e)),e);return o(g(l.map(e=>s.has(e)?u(e):{$ref:x(e)}),1,h(p,!0))),a},e2=(e,t)=>Object.fromEntries(Object.entries(e).filter(([e])=>e!==t)),t2=(e,t)=>{let[n,r]=(0,W.useState)(Y0),[i,a]=(0,W.useState)(),o=(0,W.useRef)(1),s=(0,W.useMemo)(()=>new Map(e?t.map(t=>[Nr(e.model,t),t]):[]),[e,t]),c=X0([...s.keys()],n).map(e=>({id:e,stored:s.get(e)})),l=()=>e?$0({...e,stored:t,state:n}):{ops:[],rows:[]},u=l().ops.length>0,d=(0,W.useMemo)(()=>{let e=X0([...s.keys()],n).filter(e=>s.has(e)),t=[...s.keys()].filter(t=>e.includes(t));return n.order!==void 0&&e.some((e,n)=>e!==t[n])?e:void 0},[s,n]),f=(t,r)=>{let i=n.edits[t];if(i&&r in i)return i[r];let a=e?.model.fields[r],o=s.get(t)?.[r];return a?[`boolean`,`file`].includes(a.type)?o:ly(a,o):o},p=e=>a(t=>t?.id===e?void 0:t);return{shown:c,dirty:u,order:d,value:f,change:(e,t,n)=>{p(e),r(r=>({...r,edits:{...r.edits,[e]:{...r.edits[e],[t]:n}}}))},add:()=>{let e=`new:${o.current++}`;return r(t=>({...t,added:[...t.added,e]})),e},remove:e=>{p(e),r(t=>t.added.includes(e)?{...t,added:t.added.filter(t=>t!==e),edits:e2(t.edits,e)}:{...t,removed:[...t.removed,e]})},setOrder:e=>r(t=>({...t,order:e})),reset:()=>{r(Y0),a(void 0)},reject:(e,t)=>a({id:e,fields:hA(t),message:t.message}),rejection:i,plan:l}},n2=(e,t)=>{let n=za(t?.layout??[]).find(e=>e.kind===`related`&&e.lines===!0);if(n?.kind!==`related`)return;let r=e[n.resource],i=r?.fields[n.field],a=r?.position?.field;if(r&&i&&a&&r.position?.within===n.field)return{item:n,model:r,link:i,position:a}},r2=(e,t,n,r)=>He(e,t).filter(t=>{let i=e.fields[t];return i&&!i.writeOnly&&t!==n&&t!==r&&t!==e.tenant&&!e.primaryKey.includes(t)}),i2=(e,t)=>{let{resources:n,views:r}=c(),i=(0,W.useMemo)(()=>n2(n,r[e.name]),[n,r,e]),a=i?.model,o=i?r2(i.model,r[i.model.name],i.link.name,i.position):[],s=q0(a,i?.link,i?.position,t,a?ab(n,r,a,o):void 0),l=t2((0,W.useMemo)(()=>i?{model:i.model,position:i.position,link:{field:i.link.name,value:yy(e,t)}}:void 0,[i,e,t]),s.items);return{item:i?.item,model:a,columns:o,data:s,draft:l}},a2=e=>{let t=e>=5?5:e===4?3:e;return{shown:t,more:e-t}},o2=(e,t)=>Math.abs(e)<40||Math.abs(e)<=Math.abs(t)?0:e<0?1:-1,s2=e=>e===`ArrowRight`?1:e===`ArrowLeft`?-1:0,c2=(e,t,n)=>Math.min(Math.max(e+t,0),Math.max(n-1,0)),l2=e=>e.key===`i`&&!e.ctrlKey&&!e.metaKey&&!e.altKey,u2=`protobase:lightbox-details`,d2=e=>i(()=>e.getItem(u2)===`true`,!1),f2=(e,t)=>i(()=>t?e.setItem(u2,`true`):e.removeItem(u2),void 0),p2=B(`app/gallery`),m2=`flex size-10 shrink-0 items-center justify-center rounded-full bg-background/85 text-foreground shadow-sm transition-colors hover:bg-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40`,h2=({title:e,photos:t,index:n,onIndex:r,onClose:i,details:a,detailsTitle:o=p2(`details`)})=>{let s=(0,W.useRef)(null),c=(0,W.useRef)(void 0),l=(0,W.useId)(),u=h(),[d,f]=(0,W.useState)(()=>d2(localStorage)),[p,m]=(0,W.useState)(!1);li(s,!0,i),(0,W.useEffect)(()=>m(!0),[]);let g=t.length,_=e=>{let t=c2(n,e,g);t!==n&&r(t)},v=jr(t[n],{width:1600,height:1200}),y=a?.(n),b=y!==void 0,x=e=>{f(e),f2(localStorage,e)};return(0,q.jsxs)(`div`,{ref:s,tabIndex:-1,role:`dialog`,"aria-modal":`true`,"aria-label":e,onKeyDown:e=>{if(b&&l2(e))return e.preventDefault(),x(!d);let t=s2(e.key);t!==0&&(e.preventDefault(),_(t))},className:`fixed inset-0 z-[90] flex flex-col overflow-y-auto overscroll-contain bg-backdrop pl-[var(--pb-safe-left)] pr-[var(--pb-safe-right)] outline-none md:flex-row`,children:[(0,q.jsxs)(`div`,{className:`flex h-dvh shrink-0 flex-col md:sticky md:top-0 md:min-w-0 md:flex-1`,children:[(0,q.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between gap-2 p-3 pt-[calc(0.75rem+var(--pb-safe-top))]`,children:[(0,q.jsx)(`span`,{className:`rounded-full bg-background/85 px-3 py-1 font-medium tabular-nums text-foreground`,"aria-live":`polite`,children:`${n+1} / ${g}`}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[b&&(0,q.jsx)(`button`,{type:`button`,className:U(m2,`aria-expanded:bg-foreground aria-expanded:text-background`),"aria-label":o,"aria-expanded":d,"aria-controls":u?l:void 0,"aria-keyshortcuts":`i`,onClick:()=>x(!d),children:(0,q.jsx)(Al,{className:`size-4`,"aria-hidden":!0})}),(0,q.jsx)(`button`,{type:`button`,className:m2,"aria-label":p2(`close`),onClick:i,children:(0,q.jsx)(Ci,{className:`size-4`,"aria-hidden":!0})})]})]}),(0,q.jsxs)(`div`,{className:`relative flex min-h-0 flex-1 touch-pan-y items-center justify-center px-3 pb-[calc(0.75rem+var(--pb-safe-bottom))] md:px-16`,onPointerDown:e=>{e.pointerType===`touch`&&(c.current={x:e.clientX,y:e.clientY})},onPointerUp:e=>{c.current&&=(_(o2(e.clientX-c.current.x,e.clientY-c.current.y)),void 0)},onPointerCancel:()=>c.current=void 0,children:[v&&(0,q.jsx)(Iy,{image:v,className:`max-h-full max-w-full select-none object-contain`},v.url),g>1&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`button`,{type:`button`,className:U(m2,`absolute left-3 top-1/2 -translate-y-1/2 aria-disabled:cursor-default aria-disabled:opacity-40`),"aria-label":p2(`previousPhoto`),"aria-disabled":n===0,onClick:()=>_(-1),children:(0,q.jsx)(wc,{className:`size-5`,"aria-hidden":!0})}),(0,q.jsx)(`button`,{type:`button`,className:U(m2,`absolute right-3 top-1/2 -translate-y-1/2 aria-disabled:cursor-default aria-disabled:opacity-40`),"aria-label":p2(`nextPhoto`),"aria-disabled":n===g-1,onClick:()=>_(1),children:(0,q.jsx)(qn,{className:`size-5`,"aria-hidden":!0})})]})]})]}),b&&d&&u&&(0,q.jsxs)(`aside`,{id:l,"aria-label":o,className:`min-h-dvh w-[360px] shrink-0 border-l border-border bg-background p-5 pt-[calc(1.25rem+var(--pb-safe-top))] text-foreground`,children:[(0,q.jsx)(`h2`,{className:`mb-3 text-base font-semibold`,children:o}),y]}),(0,q.jsx)(h_,{title:o,open:b&&d&&!u&&p,onClose:()=>x(!1),children:(0,q.jsx)(`div`,{className:`pt-3`,children:y})})]})},g2=(e,t,n)=>{let r=za(t?.layout??[]).flatMap(e=>e.kind===`section`&&my(e.when,!1)?e.fields:[]);return(r.length>0?[...new Set(r)]:Object.keys(e.fields).filter(t=>t!==e.tenant&&!e.primaryKey.includes(t))).filter(r=>e.fields[r]&&!e.fields[r].sensitive&&!n.includes(r)&&my(t?.fields[r]?.when,!1))},_2=({model:e,view:t,photoKey:n,fields:r})=>{let i=nx(e.name,n),a=(t?.names?.singular??H(e.name)).toLowerCase();if(i.isPending)return(0,q.jsx)(L,{className:`h-4 w-48`});if(i.error)return(0,q.jsx)(Oy,{title:p2(`couldNotLoadOne`,{singular:a}),error:i.error});let o=r.filter(e=>oS(i.data.permissions,e)!==`hidden`);return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(Nv,{rows:o.map(n=>({label:t?.fields[n]?.label??H(n),value:(0,q.jsx)(vC,{model:e,field:e.fields[n],value:i.data.record[n]})}))}),(0,q.jsx)(Ue,{to:{kind:`record`,resource:e.name,key:n},className:`mt-3 inline-block font-medium text-primary-text hover:underline`,children:p2(`open`,{singular:a})})]})},v2=e=>jr(e,{width:0,height:0})!==void 0,y2=(e,t)=>{let n=e.primaryKey.map(e=>t[e]);if(!n.some(e=>e==null))return Nn(n)},b2=(e,t,n,r)=>{let i=n===void 0?[]:t.flatMap(e=>{let t=e[n];if(!vr(t)||!v2(t))return[];let i=r&&y2(r,e);return[{file:t,...i!==void 0&&{key:i}}]});if(!vr(e)||!v2(e))return i;let a=t=>vr(t.file)&&t.file.uri===e.uri,o=i.find(a)?.key;return[{file:e,...o!==void 0&&{key:o}},...i.filter(e=>!a(e))]},x2=m(),S2=(e,t,n)=>{let r=F(),{resources:i}=c(),a=e.photos?i[e.photos.resource]:void 0,o=e.photos?vn(x2.eq(e.photos.field,n)):``,s=e.photos?.sort??``,l=Tt({queryKey:I.list(a?.name??``,o,s,500,`gallery`),enabled:a!==void 0,queryFn:async()=>(await r.list(a.name,{filter:o,...s&&{orderBy:s},pageSize:500})).items});return{holder:a,items:b2(e.image===void 0?void 0:t[e.image],l.data??[],e.photos?.image,a),isPending:a!==void 0&&l.isPending,error:l.error}},C2={1:[`md:col-span-4 md:row-span-2`],2:[`md:col-span-2 md:row-span-2`,`md:col-span-2 md:row-span-2`],3:[`md:col-span-2 md:row-span-2`,`md:col-span-2`,`md:col-span-2`],5:[`md:col-span-2 md:row-span-2`,``,``,``,``]},w2=({photo:e,large:t})=>{let n=jr(e,t?{width:960,height:720}:{width:480,height:360});return n?(0,q.jsx)(Iy,{image:n,loading:`lazy`,className:`size-full object-cover transition-transform duration-300 group-hover/tile:scale-[1.02]`}):null},T2=({item:e,record:t,recordKey:n})=>{let{views:r}=c(),i=S2(e,t,n),a=re(i.holder?.name??``),[o,s]=(0,W.useState)();if(i.isPending)return(0,q.jsx)(D_,{title:e.title,children:(0,q.jsx)(L,{className:`aspect-[4/3] w-full rounded-lg md:aspect-[2/1]`})});if(i.error)return(0,q.jsx)(D_,{title:e.title,children:(0,q.jsx)(Oy,{title:p2(`couldNotLoad`),error:i.error})});let l=i.items.length;if(l===0)return null;let{shown:u,more:d}=a2(l),f=i.holder,p=f&&r[f.name],m=f?g2(f,p,[e.photos?.image,e.photos?.field].filter(e=>e!==void 0)):[],h=f!==void 0&&a.read!==!1&&m.length>0;return(0,q.jsxs)(D_,{title:e.title,children:[(0,q.jsx)(`div`,{className:`grid aspect-[4/3] grid-cols-4 grid-rows-2 gap-1.5 overflow-hidden rounded-lg md:aspect-[2/1]`,children:i.items.slice(0,u).map((e,t)=>{let n=t===u-1&&d>0;return(0,q.jsxs)(`button`,{type:`button`,"aria-label":n?p2(`showAll`,{count:l}):p2(`showPhoto`,{index:t+1,count:l}),onClick:()=>s(t),className:U(`group/tile relative overflow-hidden bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary`,t===0?`col-span-4 row-span-2`:`max-md:hidden`,C2[u][t]),children:[(0,q.jsx)(w2,{photo:e.file,large:t===0}),n&&(0,q.jsx)(`span`,{className:`absolute inset-0 flex items-center justify-center bg-backdrop/55 text-lg font-semibold text-white`,"aria-hidden":!0,children:`+${d}`}),t===0&&l>1&&(0,q.jsxs)(`span`,{className:`absolute bottom-2 right-2 flex items-center gap-1.5 rounded-full bg-background/85 px-2.5 py-1 text-xs font-medium tabular-nums text-foreground md:hidden`,"aria-hidden":!0,children:[(0,q.jsx)(Ol,{className:`size-3.5`}),l]})]},t)})}),o!==void 0&&(0,q.jsx)(h2,{title:e.title,photos:i.items.map(e=>e.file),index:o,onIndex:s,onClose:()=>s(void 0),details:e=>{let t=i.items[e]?.key;return h&&t!==void 0?(0,q.jsx)(_2,{model:f,view:p,photoKey:t,fields:m},t):void 0},detailsTitle:f&&p2(`holderDetails`,{singular:p?.names?.singular??H(f.name)})})]})},E2=B(`app/history`),D2=e=>e.actor?e.actor.name??e.actor.id:e.databaseRole?E2(`databaseRole`,{role:e.databaseRole}):E2(`database`),O2=(e,t,n)=>{let r=(e.operation===`create`?[]:e.changed).flatMap(r=>{let i=t.fields[r];if(!i||r===t.softDelete)return[];let a=n?.fields[r],o=a?.label??H(r);return i.sensitive||!e.before||!e.after?[{name:r,label:o}]:[{name:r,label:o,before:Lr(i,e.before[r],a),after:Lr(i,e.after[r],a)}]}),i=e.operation===`update`&&r.length===0?E2(`changedThis`):E2(e.operation);return{who:D2(e),verb:i,fields:r}},k2=1500,A2=(e,t,n,r)=>{let i=F(),a=mt({queryKey:I.history(e,t,n),initialPageParam:``,queryFn:({pageParam:r})=>i.history(e,t,{pageSize:n,pageToken:r}),getNextPageParam:e=>e.nextPageToken||void 0}),{refetch:o}=a;return(0,W.useEffect)(()=>{let e=setTimeout(()=>void o(),k2);return()=>clearTimeout(e)},[r,o]),{...a,items:a.data?.pages.flatMap(e=>e.items)??[]}},j2=()=>(0,q.jsx)(`div`,{className:`flex flex-col gap-2`,children:Array.from({length:3},(e,t)=>(0,q.jsx)(L,{className:`h-4 w-full`},t))}),M2=({change:e,model:t,view:n})=>{let{who:r,verb:i,fields:a}=O2(e,t,n),o=Date.parse(e.at);return(0,q.jsxs)(`li`,{className:`flex flex-col gap-1.5 py-3 first:pt-0 last:pb-0`,children:[(0,q.jsxs)(`p`,{children:[(0,q.jsx)(`span`,{className:`font-medium text-foreground`,children:r}),` `,(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:i}),` `,(0,q.jsxs)(`time`,{dateTime:e.at,title:dr(o),className:`text-muted-foreground`,children:[`· `,Un(Math.max(0,Math.round((Date.now()-o)/1e3)))]})]}),a.length>0&&(0,q.jsx)(`dl`,{className:`grid grid-cols-[minmax(0,auto)_minmax(0,1fr)] gap-x-4 gap-y-1`,children:a.map(e=>(0,q.jsxs)(`div`,{className:`contents`,children:[(0,q.jsx)(`dt`,{className:`text-muted-foreground`,children:e.label}),(0,q.jsx)(`dd`,{className:`min-w-0 break-words`,children:e.before===void 0?(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:`changed`}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`del`,{className:`text-muted-foreground`,children:e.before}),` → `,(0,q.jsx)(`ins`,{className:`no-underline`,children:e.after})]})})]},e.name))})]})},N2=({item:e,model:t,view:n,recordKey:r,etag:i})=>{let a=A2(t.name,r,e.limit??10,i);return(0,q.jsx)(D_,{title:e.title,children:a.isPending?(0,q.jsx)(j2,{}):a.error?(0,q.jsx)(Oy,{title:`Could not load the history`,error:a.error}):a.items.length===0?(0,q.jsx)(`p`,{className:`text-muted-foreground`,children:`No changes kept yet.`}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`ol`,{className:`divide-y divide-border`,children:a.items.map(e=>(0,q.jsx)(M2,{change:e,model:t,view:n},e.id))}),a.hasNextPage&&(0,q.jsx)(P,{size:`sm`,className:`mt-4`,disabled:a.isFetchingNextPage,onClick:()=>void a.fetchNextPage(),children:`Show more`})]})})},P2=({comment:e})=>(0,q.jsx)(GO,{text:e.body,mentions:e.mentions}),F2=(e,t)=>{let n=F(),r=nn();return en({mutationFn:r=>n.comment(e,t,r),onSuccess:()=>r.invalidateQueries({queryKey:I.comments(e,t)})})},I2=B(`app/comments`),L2=({resource:e,recordKey:t})=>{let[n,r]=(0,W.useState)(HO),i=F(),a=nS(),s=F2(e,t),c=(0,W.useCallback)(n=>i.mentionable(e,t,n),[i,e,t]);we(n.text.trim()!==``||s.isPending,`input-lost`);let l=()=>{n.text.trim()===``||s.isPending||s.mutate({body:n.text,mentions:IO(n.text,n.picked)},{onSuccess:()=>r(HO),onError:e=>a.show({state:`error`,title:I2(`couldNotPost`),description:o(e)})})};return(0,q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,q.jsx)(WO,{"aria-label":I2(`comment`),placeholder:I2(`placeholder`),value:n,onChange:r,searchPeople:c,onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),l())}}),(0,q.jsx)(`div`,{children:(0,q.jsx)(P,{variant:`primary`,size:`sm`,disabled:n.text.trim()===``,loading:s.isPending,onClick:l,children:I2(`comment`)})})]})},R2=20,z2=(e,t)=>{let n=F(),r=mt({queryKey:I.comments(e,t),initialPageParam:``,queryFn:({pageParam:r})=>n.comments(e,t,{pageSize:R2,pageToken:r}),getNextPageParam:e=>e.nextPageToken||void 0});return{...r,items:r.data?.pages.flatMap(e=>e.items).reverse()??[]}},B2=()=>(0,q.jsx)(`div`,{className:`flex flex-col gap-2`,children:Array.from({length:3},(e,t)=>(0,q.jsx)(L,{className:`h-4 w-full`},t))}),V2=({comment:e})=>{let t=e.author.name??e.author.id,n=Date.parse(e.createdAt);return(0,q.jsxs)(`li`,{className:`flex gap-3 py-3 first:pt-0 last:pb-0`,children:[(0,q.jsx)(v_,{initials:Ob(t)||`?`,hue:Db(e.author.id),size:`md`,className:`ring-0`}),(0,q.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-0.5`,children:[(0,q.jsxs)(`p`,{children:[(0,q.jsx)(`span`,{className:`font-medium text-foreground`,children:t}),` `,(0,q.jsxs)(`time`,{dateTime:e.createdAt,title:dr(n),className:`text-muted-foreground`,children:[`· `,Un(Math.max(0,Math.round((Date.now()-n)/1e3)))]})]}),(0,q.jsx)(P2,{comment:e})]})]})},H2=({item:e,resource:t,recordKey:n,canWrite:r})=>{let i=z2(t,n);return(0,q.jsxs)(D_,{title:e.title,children:[i.isPending?(0,q.jsx)(B2,{}):i.error?(0,q.jsx)(Oy,{title:I2(`couldNotLoad`),error:i.error}):(0,q.jsxs)(q.Fragment,{children:[i.hasNextPage&&(0,q.jsx)(P,{size:`sm`,className:`mb-4`,disabled:i.isFetchingNextPage,onClick:()=>void i.fetchNextPage(),children:I2(`showEarlier`)}),i.items.length===0?(0,q.jsx)(`p`,{className:`text-muted-foreground`,children:I2(`noComments`)}):(0,q.jsx)(`ol`,{className:`divide-y divide-border`,children:i.items.map(e=>(0,q.jsx)(V2,{comment:e},e.id))})]}),r&&(0,q.jsx)(`div`,{className:`mt-4`,children:(0,q.jsx)(L2,{resource:t,recordKey:n})})]})},U2=e=>e.kind===`group`||e.kind===`tab`?e.items:e.kind===`custom`?e.fallback??[]:[],W2=e=>e.kind===`tab`?void 0:e.when,G2=e=>e.flatMap(e=>[e,...G2(U2(e))]).filter(e=>yf(W2(e))),K2=e=>(e.fallback??[]).map((t,n)=>[t,e.fallbackAt?.[n]??n]),q2=(e,t,n,r)=>{let i=0,a=e=>{let a=W2(e);return yf(a)?!r&&t[i++]===!0:my(a,n)},o=e=>e.flatMap(e=>{let t=a(e);if(e.kind===`custom`&&e.fallback){let n=e.fallback.map(e=>o([e])),r=n.flatMap((e,t)=>e.length>0?[t]:[]);return t?[{...e,fallback:n.flat(),fallbackAt:r}]:[]}if(e.kind!==`group`&&e.kind!==`tab`)return t?[e]:[];let n=o(e.items);return t&&n.length>0?[{...e,items:n}]:[]});return o(e)},J2=(e,t,n,r)=>q2(e,cL(r?[]:G2(e).map(e=>W2(e)),t),n,r),Y2=m(),X2=(e,t)=>{let[n,...r]=e.primaryKey;if(!(!e.tenantAcross||e.tenant===void 0||n===void 0||r.length>0||!e.fields[n]?.filterable))return{filter:vn(Y2.eq(n,t)),pageSize:1,fields:[n,e.tenant]}},Z2=(e,t,n)=>{let r=t?.[e.tenant];if(r!=null&&String(r)!==n)return String(r)},Q2=(e,t)=>{let n=F(),{session:r,organizations:i}=Y(),a=(0,W.useMemo)(()=>i?X2(e,t):void 0,[i,e,t]),[o,s]=(0,W.useState)(a?{state:`looking`}:{state:`missing`});return(0,W.useEffect)(()=>{a&&(async()=>{let[t,i]=await Promise.all([n.list(e.name,a),r.organizations.current()]),o=Z2(e,t.items[0],i.organization?.id);if(o===void 0)return s({state:`missing`});s({state:`switching`}),await r.organizations.switchTo(o),window.location.reload()})().catch(e=>s({state:`failed`,error:e}))},[n,r,e,a]),o},$2=(e,t,n,r)=>{let i=F(),a=nn(),o=Qy(),s=Object.values(e.fields).filter(n=>n.type===`relation`&&n.relation&&n.name!==e.tenant&&r[n.name]!=null&&t[n.relation.resource]?.primaryKey.length===1),c=wt({queries:s.map(e=>{let o=t[e.relation.resource];return fb(a,i,o,n[o.name],String(r[e.name]))})}),l=s.map(e=>({kind:`record`,resource:e.relation.resource,key:String(r[e.name])}));return{addresses:Object.fromEntries(s.map((e,t)=>[e.name,l[t]])),labels:Object.fromEntries(s.map((e,i)=>{let a=t[e.relation.resource];return[e.name,pb(c[i]?.data,o,a,n[a.name],String(r[e.name]))]}))}},e4=m(),t4=(e,t,n,r,i)=>{if(e.primaryKey.length!==1)return[];let a=new Set(n4(r,i).flatMap(e=>e.kind===`thread`?[`${e.resource}.${e.field}`,...e.calls?[`${e.calls.resource}.${e.calls.field}`]:[]]:e.kind===`related`&&!e.through&&!e.from?[`${e.resource}.${e.field}`]:[])),o=Object.values(t).flatMap(t=>Object.values(t.fields).filter(t=>t.type===`relation`&&t.relation?.resource===e.name&&t.relation.columns.length===1&&t.filterable).filter(e=>e.name!==t.tenant&&!a.has(`${t.name}.${e.name}`)).map(e=>({source:t,field:e.name})));return o.map(({source:e,field:t})=>{let r=n[e.name],i=r?.names?.plural??H(e.name),a=o.filter(t=>t.source.name===e.name).length>1;return{resource:e.name,field:t,label:a?`${i} (${r?.fields[t]?.label??H(t)})`:i}})},n4=(e,t)=>e.flatMap(e=>e.kind===`group`||e.kind===`tab`?n4(e.items,t):e.kind===`custom`&&!t(e.component)?[e,...n4(e.fallback??[],t)]:[e]),r4=(e,t)=>({kind:`list`,resource:e.resource,filter:vn(e4.eq(e.field,t))}),i4=m(),a4=(e,t,n)=>{let r=F(),i=wt({queries:e.map(e=>{let i=vn(i4.eq(e.field,n));return{queryKey:I.list(e.resource,i,``,1,`incoming`),queryFn:async()=>{let n=await r.list(e.resource,{filter:i,pageSize:1,count:`exact`,fields:t[e.resource].primaryKey});return{count:n.totalSize??n.totalSizeEstimate,exact:n.totalSize!==void 0}}}})});return e.flatMap((e,t)=>{let n=i[t];return n.error?[]:[{relation:e,count:n.data}]})},o4=({model:e,recordKey:t,layout:n})=>{let{resources:r,views:i}=c(),{components:a}=qy(),o=a4(t4(e,r,i,n,e=>!!a?.[e]),r,t);return o.length===0?null:(0,q.jsx)(Jv,{title:nJ(`relatedRecords`),children:(0,q.jsx)(`ul`,{className:`-mx-2`,children:o.map(({relation:e,count:n})=>(0,q.jsx)(`li`,{children:(0,q.jsxs)(Ue,{to:r4(e,t),className:`group flex items-center justify-between gap-3 rounded-md px-2 py-2 hover:bg-muted`,children:[(0,q.jsx)(`span`,{className:`min-w-0 truncate font-medium text-primary-text`,children:e.label}),(0,q.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1 tabular-nums text-muted-foreground`,children:[n===void 0?(0,q.jsx)(L,{className:`h-4 w-6`}):`${k_(n.count)}${n.exact?``:`+`}`,(0,q.jsx)(qn,{className:`size-4 text-faint-foreground group-hover:text-foreground`})]})]})},`${e.resource}.${e.field}`))})})},s4=({count:e,names:t})=>e===null?null:e===void 0?(0,q.jsx)(L,{className:`inline-block h-5 w-7 rounded-full`}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(Ni,{dot:!1,className:U(`tabular-nums`,e===0&&`bg-transparent ring-1 ring-border ring-inset`),children:(0,q.jsx)(`span`,{"aria-hidden":!0,children:e.toLocaleString(ci())})}),(0,q.jsx)(`span`,{className:`sr-only`,children:t?b_(`headingCount`,{count:e,...t}):b_(`headingCountRecords`,{count:e})})]}),c4=(e,t,n,r,i)=>{if(!(e.through||t===null)&&NJ(n,r,i))return{kind:`create`,resource:e.resource,values:{[e.field]:String(t)}}},l4=({empty:e})=>(0,q.jsx)(`p`,{className:`text-muted-foreground`,children:e??mM(`nothingYet`)}),u4=(e,t)=>(t?.names?.singular??H(e.name)).toLowerCase(),d4=({title:e,help:t,count:n,model:r,view:i,filter:a,sort:o,fields:s,button:l,empty:u,add:d})=>{let f=v(),{resources:p}=c(),m=o||Pe(r,i),h=ii(r,{filter:a,sort:m,pageSize:2});if(h.isPending)return(0,q.jsx)(D_,{title:e,help:t,count:n,children:(0,q.jsx)(L,{className:`h-24 w-full`})});if(h.error)return(0,q.jsx)(D_,{title:e,help:t,count:n,children:(0,q.jsx)(Oy,{title:mM(`couldNotLoad`),error:h.error})});let[g,_]=h.data.items;if(!g){let a=d&&(0,q.jsxs)(Ue,{to:d,className:zn({size:`sm`}),children:[(0,q.jsx)(Hu,{className:`size-3.5`}),mM(`add`,{singular:u4(r,i)})]});return(0,q.jsx)(D_,{title:e,help:t,count:n,actions:a,children:(0,q.jsx)(l4,{empty:u})})}let y=ni(r,g),b=u4(r,i),x=i?.names?.plural??H(r.name),S=s.length>1,C=s.map(e=>(0,q.jsx)(_M,{scope:y,path:e,labelled:S},e)),w=(0,q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[l&&(0,q.jsx)(pM,{button:l,model:r,view:i,record:g,models:p}),(0,q.jsx)(Ue,{to:{kind:`record`,resource:r.name,key:xr(r,g)},className:zn({size:`sm`}),children:mM(`open`,{singular:b})})]});return(0,q.jsx)(D_,{title:e,help:t,count:n,actions:w,children:(0,q.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4`,children:[S?(0,q.jsx)(`dl`,{className:`flex flex-col gap-4`,children:C}):C,_&&(0,q.jsxs)(Ue,{to:oM(r,i,f,{filter:a,orderBy:m,display:aM(i,f,{})}),className:`flex items-center gap-1 self-start font-medium text-primary-text hover:underline`,children:[$j(`viewAll`),` `,(0,q.jsx)(`span`,{className:`sr-only`,children:x.toLowerCase()}),(0,q.jsx)(Is,{className:`size-3.5`,"aria-hidden":!0})]})]})})},f4=m(),p4=(...e)=>{let t=e.filter(e=>!!e);return t.length===1?t[0]:t.map(e=>`(${e})`).join(` AND `)},m4=(e,t,n)=>{let{through:r}=e;if(t===null)return null;if(!r)return p4(vn(f4.eq(e.field,t)),e.filter);let i=r.key??n[r.resource]?.primaryKey[0],a=Te(p4(vn(f4.eq(r.field,t)),r.filter));return!a.ok||!i?null:p4(vn(f4.related(e.field,r.resource,i,a.ast)),e.filter)},h4=e=>{if(e.some(e=>e===null))return null;if(!e.some(e=>e===void 0))return e.reduce((e,t)=>e+t,0)},g4=(e,t=!0)=>{let n=F(),{resources:r}=c(),i=e.flatMap(({item:e,value:t})=>{let n=r[e.resource];return n?[{model:n,match:m4(e,t,r)}]:[]}),a=wt({queries:i.map(({model:e,match:r})=>({...ti(n,e,r??``),enabled:t&&r!==null}))});return h4(i.map(({match:e},t)=>{if(e===null)return 0;let n=a[t];return n.isError?null:n.isSuccess?n.data??null:void 0}))},_4=m(),v4=({empty:e})=>(0,q.jsx)(`p`,{className:`text-muted-foreground`,children:e??nJ(`nothingYet`)}),y4=({item:e,value:t,owner:n})=>{let{resources:r,views:i,pages:a}=c(),o=r[e.resource],s=o&&i[o.name],l=m4(e,t,r),[u,d]=TB(s,`related:${n}:${e.title}`,e.display),f=re(e.resource),[p,m]=(0,W.useState)(!1),h=g4([{item:e,value:t}],!!(e.hideEmpty||e.count));if(!o||e.hideEmpty&&(h===void 0||h===0))return null;let g={title:e.title,help:e.help,count:e.count?(0,q.jsx)(s4,{count:h,names:s?.names}):void 0},_=fB(e,o,r),v=e.columns??He(o,s).filter(t=>t!==e.field),y=t=>l===null?(0,q.jsx)(v4,{empty:e.empty}):t(l);if(e.presentation===`cards`||e.presentation===`compact`){let t=e.presentation===`compact`?{time:e.time}:void 0,n=t?v.filter(t=>t!==e.time):v,r=e.tone===void 0||n.includes(e.tone)?n:[e.tone,...n];return(0,q.jsx)(D_,{...g,children:y(n=>(0,q.jsx)(OM,{model:o,view:s,filter:n,sort:e.sort??``,fields:r,actions:e.actions??[],button:e.button,limit:e.limit??10,display:e.display,empty:e.empty,compact:t,tone:e.tone}))})}if(e.presentation===`record`)return l===null?(0,q.jsx)(D_,{...g,children:(0,q.jsx)(v4,{empty:e.empty})}):(0,q.jsx)(d4,{...g,model:o,view:s,filter:l,sort:e.sort??``,fields:v,button:e.button,empty:e.empty,add:c4(e,t,s,a,f)},l);let b=xL(e,o,f),x=(0,q.jsx)(SB,{view:s,value:u,onChange:d}),S=b?(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[!p&&x,(0,q.jsx)(t$,{size:`sm`,sorting:p,onChange:m})]}):x;return p&&b?(0,q.jsx)(D_,{...g,actions:S,children:(0,q.jsx)(e$,{model:o,view:s,field:b,filter:vn(_4.eq(e.field,t)),columns:v})}):(0,q.jsx)(D_,{...g,actions:S,children:y(t=>(0,q.jsx)(wB,{model:o,view:s,filter:t,sort:e.sort??``,columns:v,limit:e.limit??10,display:u,empty:e.empty,opens:_,button:e.button},t))})},b4=(e,t,n)=>{if(e.from===void 0)return n;let r=t[e.from];return typeof r==`boolean`?r:pB(t,e.from)??null},x4=({sections:e})=>{let t=g4(e),{views:n}=c(),r=new Set(e.map(({item:e})=>e.resource)),[i]=r,a=r.size===1?n[i]?.names:void 0;return(0,q.jsx)(s4,{count:t,names:a})},S4=(e,t,n,r,i)=>{let a=e.fields.status?.type===`enum`&&!r.includes(`status`)?`status`:void 0,o=t?.titleBadge??a;if(o===void 0||!e.fields[o]||!i(o))return;let s=n[o];if(s!=null&&s!==``)return o},C4=({item:e,owner:t,recordKey:n})=>(0,q.jsx)(`div`,{className:`pb-8`,children:(0,q.jsx)(ZO,{resource:e.resource,field:e.text,values:{[e.field]:yy(t,n)},placeholder:e.placeholder})}),w4=m(),T4=(e,t)=>vn(w4.eq(e,t)),E4=({item:e,scope:t})=>{let{resources:n}=c(),[r]=cL(e.working===void 0?[]:[e.working],t),i=n[e.resource];if(!i)return null;let a=e.calls&&n[e.calls.resource],o=e.calls&&a&&{model:a,filter:T4(e.calls.field,t.key),fields:e.calls};return(0,q.jsx)(D_,{title:e.title,help:e.help,children:(0,q.jsx)(tV,{children:(0,q.jsx)(eV,{model:i,filter:T4(e.field,t.key),sender:e.sender,time:e.time,text:e.text,status:e.status,calls:o,limit:e.limit,empty:e.empty,working:e.working===void 0?void 0:r===!0})})})},D4=({item:e,scope:t})=>{let n=e.tree,r=e.reads;return(0,q.jsx)(Qw,{value:t,children:(0,q.jsxs)(fE,{tree:n,plan:r,children:[(0,q.jsx)(eJ,{tree:n,plan:r}),(0,q.jsx)(PU,{node:n,at:``})]})})},O4=[32,24,40,28,20],k4=()=>(0,q.jsxs)(`div`,{role:`status`,"aria-label":R(`loading`),className:`mx-auto w-full max-w-[1100px] px-4 pb-8 pt-6 md:px-10 md:py-8`,children:[(0,q.jsx)(L,{className:`h-8 w-3/4 max-w-96`}),(0,q.jsxs)(`div`,{className:`mt-10 grid grid-cols-1 gap-8 md:grid-cols-[minmax(0,1fr)_300px] md:gap-12`,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(L,{className:`h-5 w-32`}),(0,q.jsx)(`div`,{className:`mt-5 divide-y divide-border border-t`,children:O4.map((e,t)=>(0,q.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,2fr)_minmax(0,3fr)] gap-x-4 py-3`,children:[(0,q.jsx)(L,{className:`h-4 w-24`}),(0,q.jsx)(L,{className:`h-4`,style:{width:`${e*2}%`}})]},t))})]}),(0,q.jsx)(L,{className:`h-40 rounded-lg max-md:hidden`})]})]}),A4=(e,t)=>t===e.tenant||e.primaryKey.includes(t),j4=(e,t,n)=>{if(t&&t.layout.length>0)return t.layout;let r=Object.values(e.fields).filter(t=>!A4(e,t.name)&&!t.writeOnly),i=r.filter(e=>!e.readOnly),a=(i.length>0&&!n?i:r).map(e=>e.name);return[{kind:`section`,title:nJ(`details`),fields:a},...e.history?[{kind:`history`,title:nJ(`history`)}]:[],...e.comments?[{kind:`comments`,title:nJ(`comments`)}]:[]]},M4=({resource:e,recordKey:t})=>{let{resources:n,views:r}=c(),{address:i}=Me(),a=qy(),o=n[e],s=rx(e,t);if(!o)return(0,q.jsx)(tt,{title:R(`notFound`),children:R(`noResource`,{name:e})});if(s.isPending)return(0,q.jsx)(k4,{});if(s.error)return(0,q.jsx)(`div`,{className:`p-8`,children:Tn(s.error)&&s.error.status===404?(0,q.jsx)(N4,{model:o,recordKey:t}):(0,q.jsx)(Oy,{title:nJ(`couldNotLoad`),error:s.error})});let l=(0,q.jsx)(P4,{model:o,recordKey:t,stored:s.data,preview:s.isPlaceholderData},s.isPlaceholderData?`preview`:`loaded`),u=i?.kind===`record`&&i.file!==void 0&&!s.isPlaceholderData?sC(a,o,s.data.record,i.file):void 0,d={kind:`record`,resource:e,key:t,...(r[e]?.recordOpens!==void 0||r[e]?.record!==void 0)&&{standard:!0}};if(u)return(0,q.jsx)(cC,{model:o,record:s.data.record,viewed:u,back:d},u.file.uri);let f=i?.kind===`record`&&i.standard===!0,p=r[e]?.recordOpens;if(p&&!f){if(s.isPlaceholderData)return(0,q.jsx)(k4,{});let e=rJ(p,s.data.record);if(e)return(0,q.jsx)(iJ,{to:e})}let m=r[e]?.record;if(!m||f)return l;if(s.isPlaceholderData)return(0,q.jsx)(k4,{});if(`surface`in m||m.focus)return(0,q.jsx)(p0,{model:o,recordKey:t,stored:s.data,page:m,standard:l});let{record:h,etag:g,permissions:_}=s.data;return(0,q.jsx)(S1,{component:m.component,scope:{model:o,record:h,key:t,etag:g,permissions:_},standard:l})},N4=({model:e,recordKey:t})=>{let n=Q2(e,t);return n.state===`looking`?(0,q.jsx)(k4,{}):n.state===`switching`?(0,q.jsx)(tt,{title:nJ(`loading`),children:nJ(`openingElsewhere`)}):n.state===`failed`?(0,q.jsx)(Oy,{title:nJ(`couldNotLoad`),error:n.error}):(0,q.jsx)(tt,{title:R(`notFound`),children:nJ(`noRecord`)})},P4=({model:e,recordKey:t,stored:n,preview:r})=>{let i=c(),{address:a,go:o}=Me(),s=i.views[e.name],l=Qy()(e,s,n.record,t),{state:u}=Y(),d=i2(e,t),f=a0({model:e,stored:n,recordKey:t,mode:s?.saveFeedback??`toast`,subject:l,draftKey:!r&&u.kind===`signed-in`?q1(u.user.id,e.name,t):void 0,lines:d.draft}),p=nn(),m=F(),h=_A(f.rejections),g=re(e.name),_=MJ(e),v=a?.kind===`record`&&a.version!==void 0,y=iS(g,`update`)&&n.permissions?.update!==!1&&!v,{shown:b,offersEdit:x,editing:C}=dy(s?.recordMode,y,a?.kind===`record`&&a.edit===!0);we(f.dirty&&b===`form`||f.saving),In(f.dirty);let w=a?.kind===`record`?a.open:void 0,T=a?.kind===`record`&&a.edit===!0,E=a?.kind===`record`?a.tab:void 0,D=a?.kind===`record`&&a.standard===!0,O=(n=[],r=!1,i)=>({kind:`record`,resource:e.name,key:t,...r&&{edit:r},...n.length>0&&{open:n},...i&&{tab:i},...D&&{standard:D}}),k=O(w,!1,E),ee=O(w,!0,E),A=b===`form`&&s?.recordMode!==void 0&&s.recordMode!==`edit`,te=iS(g,`delete`)&&n.permissions?.delete!==!1,ne=jJ({model:e,view:s,restore:_,onDeleted:()=>o({kind:`list`,resource:e.name},{replace:!0}),onReview:()=>void p.invalidateQueries({queryKey:I.record(e.name,t)})}),j=$2(e,i.resources,i.views,n.record),ie=t=>{let n=e.fields[t],r=n?.relation?i.resources[n.relation.resource]:void 0;if(r&&r.primaryKey.length===1&&t!==e.tenant&&!e.primaryKey.includes(t))return r},M=Object.values(e.fields).filter(e=>ie(e.name)),ae={...n.record,...Object.fromEntries(M.map(e=>[e.name,cy(e,f.value(e.name))]))},oe=$2(e,i.resources,i.views,ae),se=(e,t)=>{let n=ie(e);if(!n||!gy(t))return f.change(e,t);p.setQueryData(I.relatedLabel(n.name,t.key),{label:t.label}),f.change(e,yy(n,t.key))},{fields:ce}=qy(),le={model:e,record:n.record,key:t,etag:n.etag,permissions:n.permissions},ue=J2(j4(e,s,b===`read`),le,C,r),{before:de,tabs:fe,after:pe}=j0(ue),me=M0(fe,E),he=e=>C&&(f.errors[e]!==void 0||f.conflicts[e]!==void 0);(0,W.useEffect)(()=>{if(f.rejections===0)return;let e=P0(fe,me,he);e&&o(O(w,T,e===fe[0]?void 0:e.title),{replace:!0})},[f.rejections]);let ge=ue.flatMap(e=>e.kind===`sidebar`?e.fields:[]),_e=y1(e,`updated`),ve=e=>s?.fields[e],ye=t=>oS(n.permissions,t)!==`hidden`&&my(ve(t)?.when,C)&&(b===`form`||!e.fields[t]?.writeOnly),be=e=>!r||Object.hasOwn(n.record,e),xe=S4(e,s,n.record,ge,ye),Se=xe&&(0,q.jsxs)(ri,{value:n.record[xe],hints:ve(xe),children:[(0,q.jsxs)(`span`,{className:`sr-only`,children:[ve(xe)?.label??H(xe),`: `]}),Lr(e.fields[xe],n.record[xe],ve(xe))]}),Ce=r=>{let a=e.fields[r],o=oS(n.permissions,r);if(!a||o===`hidden`)return null;let c=f.conflicts[r],l=ie(r),u=ve(r)?.label??H(r),d=f.errors[r],p=b!==`form`||o===`read`;return(0,q.jsx)(Mv,{name:r,label:u,required:b===`form`&&o!==`read`&&ry(a),help:py(ve(r),s,C),error:d&&mA(a,u,d),wide:NS(ce,a,ve(r)),readOnly:UC(a,ve(r),p,!!l),conflict:c===void 0?void 0:{user:{name:nJ(`someoneElse`),initials:`?`,hue:40},ago:nJ(`justNow`),theirValue:c||`—`,onKeepMine:()=>f.keepMine(r),onUseTheirs:()=>f.useTheirs(r)},children:be(r)?(0,q.jsx)(GC,{field:a,hints:ve(r),value:f.value(r),stored:n.record[r],relationLabel:oe.labels[r],relationTo:oe.addresses[r],relationPicker:l&&{target:l,view:i.views[l.name]},locked:p,invalid:!!f.errors[r],reveal:a.sensitive&&!a.writeOnly?()=>m.reveal(e.name,t,r):void 0,resource:e.name,record:n.record,linkText:ve(r)?.format===`url`?bv(e,s,r,n.record,j.labels):void 0,onChange:e=>se(r,e)}):(0,q.jsx)(L,{className:`h-9`})},a.sensitive?`${r}:${n.etag}`:r)},N=r=>{let i=e.fields[r],a=be(r)?i.sensitive?(0,q.jsx)(GC,{field:i,hints:ve(r),value:``,stored:n.record[r],locked:!0,reveal:()=>m.reveal(e.name,t,r),resource:e.name,onChange:e=>f.change(r,e)}):(0,q.jsx)(vC,{model:e,field:i,value:n.record[r],relationLabel:j.labels[r],record:n.record,relationLabels:j.labels}):(0,q.jsx)(L,{className:`h-4 w-32`});return{label:ve(r)?.label??H(r),help:py(ve(r),s,C),wide:NS(ce,i,ve(r)),value:a}},Te=ue.findIndex(e=>e.kind===`sidebar`),Ee=(0,q.jsx)(Yv,{title:nJ(`summary`),rows:ge.flatMap(t=>{let r=e.fields[t];if(!r||!ye(t))return[];if(!be(t))return[{label:ve(t)?.label??H(t),value:(0,q.jsx)(L,{className:`h-4 w-24`})}];let i=n.record[t],a=ov(r,ve(t))&&typeof i==`string`&&i!==``,o=r.type===`json`&&i!=null,c=a?av(i):o?_v(i):Lr(r,i,ve(t)),l=r.type===`text`&&typeof i==`string`&&i!==``?cv(ve(t)):void 0,u=r.type===`enum`?(0,q.jsx)(ri,{value:i,hints:ve(t),children:c}):l?(0,q.jsx)(HS,{format:l,value:c,label:bv(e,s,t,n.record,j.labels)}):(0,q.jsx)(`span`,{title:Dr(r,i,void 0,ve(t)),children:c}),d=jS(ce,r,ve(t));return[{label:ve(t)?.label??H(t),title:c,value:d?(0,q.jsx)(RS,{shown:d,part:`display`,field:r,value:n.record[t],fallback:u}):u}]})}),De=async()=>{await f.save()&&A&&o(k,{replace:!0})},Oe=te?()=>void ne.start({key:t,title:l,etag:n.etag,snapshot:n.record}):void 0,ke=b===`form`&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(P,{variant:`primary`,className:`max-md:min-h-11 max-md:flex-1 md:w-full`,loading:f.saving,disabled:!f.dirty&&f.phase!==`saved`,onClick:()=>void De(),children:[f.phase===`saved`&&(0,q.jsx)(xi,{className:`size-4`}),f.phase===`saved`?nJ(`saved`):nJ(`save`)]}),A&&(0,q.jsx)(Ue,{to:k,className:U(zn(),`max-md:min-h-11 md:w-full`),onClick:e=>nr(e)&&f.discard(),children:nJ(`cancel`)}),f.dirty&&(0,q.jsx)(`span`,{className:`text-xs text-muted-foreground max-md:order-first`,children:nJ(`unsavedChanges`)})]}),Ae=(i,a)=>{if(i.kind===`group`){let e=i.items.flatMap(Ae);if(e.length===0)return[];let r=A0(i,w,he),a=i.collapsed?O(k0(w,i.title),T,E):void 0,o=i.items.flatMap(e=>e.kind===`related`&&(e.from===void 0||be(e.from))?[{item:e,value:b4(e,n.record,t)}]:[]),s=i.count?(0,q.jsx)(x4,{sections:o}):void 0;return[(0,q.jsx)(Dv,{title:i.title,help:i.help,count:s,open:r,toggle:a,children:e},`group:${i.title}`)]}if(i.kind===`related`&&i.lines)return!d.model||!d.item||r?[]:[(0,q.jsx)(J0,{lines:{...d,model:d.model,item:d.item},editable:b===`form`,saving:f.saving},`lines:${i.title}`)];if(i.kind===`related`)return i.from!==void 0&&!be(i.from)?[]:[(0,q.jsx)(y4,{item:i,value:b4(i,n.record,t),owner:e.name},`related:${i.title}`)];if(i.kind===`chart`)return[(0,q.jsx)(C0,{item:i,recordKey:t},`chart:${a}`)];if(i.kind===`trend`)return[(0,q.jsx)(O0,{item:i,recordKey:t},`trend:${a}`)];if(r&&(i.kind===`custom`||i.kind===`map`||i.kind===`gallery`||i.kind===`blocks`))return[];if(i.kind===`custom`)return i.sidebar?[]:[(0,q.jsx)(x1,{item:i,scope:le,fallback:i.fallback&&(0,q.jsx)(q.Fragment,{children:K2(i).flatMap(([e,t])=>Ae(e,t))})},`custom:${a}`)];if(i.kind===`map`)return i.sidebar?[]:[(0,q.jsx)(g0,{item:i,record:n.record},`map:${a}`)];if(i.kind===`gallery`)return[(0,q.jsx)(T2,{item:i,record:n.record,recordKey:t},`gallery:${a}`)];if(i.kind===`history`)return[(0,q.jsx)(N2,{item:i,model:e,view:s,recordKey:t,etag:n.etag},`history:${a}`)];if(i.kind===`thread`)return[(0,q.jsx)(E4,{item:i,scope:le},`thread:${a}`)];if(i.kind===`blocks`)return[(0,q.jsx)(D4,{item:i,scope:le},`blocks:${a}`)];if(i.kind===`composer`)return r?[]:[(0,q.jsx)(C4,{item:i,owner:e,recordKey:t},`composer:${a}`)];if(i.kind===`comments`)return[(0,q.jsx)(H2,{item:i,resource:e.name,recordKey:t,canWrite:u.kind!==`visitor`},`comments:${a}`)];if(i.kind!==`section`)return[];let o=i.fields.filter(t=>e.fields[t]&&ye(t)),c=b===`read`&&i.presentation===`facts`,l=c?S(n.record,o):o;return l.length===0?[]:[(0,q.jsx)(D_,{title:i.title,help:fy(i.helpWhen,s,C)?i.help:void 0,children:c?(0,q.jsx)(Pv,{facts:l.map(e=>({label:N(e).label,value:N(e).value,icon:VF(ve(e)?.icon)}))}):b===`read`?(0,q.jsx)(Nv,{rows:l.map(N)}):(0,q.jsx)(`div`,{className:`grid grid-cols-1 gap-x-6 gap-y-5 sm:grid-cols-2`,children:l.map(Ce)})},i.title)]},je=(e,t)=>e.kind===`map`?(0,q.jsx)(g0,{item:e,record:n.record},`map:${t}`):e.kind===`custom`?(0,q.jsx)(x1,{item:e,scope:le,fallback:e.fallback&&(0,q.jsx)(q.Fragment,{children:K2(e).map(([e,t])=>je(e,t))})},`custom:${t}`):null;return(0,q.jsxs)(`div`,{ref:h,className:`flex flex-1 flex-col`,inert:r,children:[ne.dialogs,(0,q.jsx)(`div`,{className:`flex-1`,children:(0,q.jsxs)(`div`,{className:U(s?.recordWidth!==`full`&&`mx-auto max-w-[1100px]`,`px-4 pb-8 pt-6 md:px-10 md:py-8`),children:[(0,q.jsx)(x_,{title:l,badge:Se}),f.message&&(0,q.jsx)(`div`,{className:`mt-4`,children:(0,q.jsx)(Oy,{title:nJ(`notSaved`),error:Error(f.message)})}),f.linesConflict&&(0,q.jsx)(`div`,{className:`mt-4`,children:(0,q.jsx)(Oy,{title:nJ(`linesChanged`),error:Error(nJ(`linesReloaded`))})}),b!==`form`&&x&&f.dirty&&(0,q.jsxs)(`div`,{className:`mt-4 flex items-center justify-between gap-3 rounded-lg border bg-surface px-3 py-2`,role:`status`,children:[(0,q.jsx)(`span`,{children:nJ(`unsavedKept`)}),(0,q.jsxs)(`span`,{className:`flex gap-2`,children:[(0,q.jsx)(Ue,{to:ee,className:zn({size:`sm`}),children:nJ(`continueEditing`)}),(0,q.jsx)(P,{size:`sm`,onClick:f.discard,children:nJ(`discard`)})]})]}),b===`form`&&f.restored&&(0,q.jsxs)(`div`,{className:`mt-4 flex items-center justify-between gap-3 rounded-lg border bg-surface px-3 py-2`,role:`status`,children:[(0,q.jsx)(`span`,{children:nJ(`unsavedRestored`)}),(0,q.jsxs)(`span`,{className:`flex gap-2`,children:[(0,q.jsx)(P,{size:`sm`,onClick:f.dismissRestored,children:nJ(`keep`)}),(0,q.jsx)(P,{size:`sm`,onClick:f.discard,children:nJ(`discard`)})]})]}),(0,q.jsxs)(`div`,{className:`grid grid-cols-1 gap-8 md:grid-cols-[minmax(0,1fr)_300px] md:gap-12`,children:[(0,q.jsxs)(`div`,{className:`divide-y divide-border`,children:[de.flatMap(Ae),me&&(0,q.jsx)(jv,{tabs:fe.map((e,t)=>({title:e.title,to:O(w,T,t===0?void 0:e.title),current:e===me}))}),me&&(0,q.jsx)(`div`,{className:`divide-y divide-border`,children:me.items.flatMap(Ae)},`tab:${me.title}`),pe.flatMap(Ae)]}),(0,q.jsxs)(`aside`,{className:`space-y-4 md:sticky md:top-[var(--pb-sticky-top,0px)] md:max-h-[calc(100dvh-var(--pb-sticky-top,0px)-var(--pb-sticky-bottom,0px))] md:self-start md:overflow-y-auto md:pb-4 md:pt-8`,children:[ke&&(0,q.jsx)(`div`,{className:`hidden flex-col items-center gap-2 md:flex`,children:ke}),!r&&(0,q.jsx)(Q1,{model:e,stored:n,recordKey:t,edit:x?ee:void 0,onDelete:Oe}),Te===-1&&Ee,ue.map((e,t)=>(e.kind===`custom`||e.kind===`map`)&&e.sidebar&&!r?je(e,t):t===Te?(0,q.jsx)(W.Fragment,{children:Ee},`summary`):null),(0,q.jsx)(Yv,{title:nJ(`details`),rows:[y1(e,`created`),_e].flatMap(t=>{let r=t?e.fields[t]:void 0;return!t||!r||!ye(t)||ge.includes(t)?[]:[{label:ve(t)?.label??H(t),value:be(t)?(0,q.jsx)(`span`,{title:Dr(r,n.record[t],void 0,ve(t)),children:Lr(r,n.record[t],ve(t))}):(0,q.jsx)(L,{className:`h-4 w-24`})}]})}),!r&&(0,q.jsx)(o4,{model:e,recordKey:t,layout:ue})]})]})]})}),ke&&(0,q.jsx)(`div`,{className:`sticky bottom-[var(--pb-sticky-bottom,0px)] z-20 flex shrink-0 items-center gap-2 border-t bg-background p-3 md:hidden`,children:ke})]})},F4=({failed:e})=>(0,q.jsxs)(`span`,{className:`inline-flex items-center text-muted-foreground`,children:[(0,q.jsx)(`span`,{role:`status`,className:`sr-only`,children:R(e?`refreshFailed`:`refreshing`)}),e?(0,q.jsx)(tj,{label:R(`refreshFailed`),side:`bottom`,children:(0,q.jsx)(Mi,{"aria-hidden":!0,className:`size-4 text-warning`})}):(0,q.jsx)(`span`,{className:or,children:(0,q.jsx)(wn,{hidden:!0})})]}),I4=e=>Tn(e)?e.status===401||e.status===403?R(`signInRefused`,{message:e.message}):e.message:R(`noAnswer`),L4=({status:e})=>{let t=nn();return e.state===`error`?(0,q.jsx)(`div`,{className:`flex h-full min-h-48 flex-1 items-center justify-center p-8`,children:(0,q.jsxs)(`div`,{className:`max-w-md text-center`,children:[(0,q.jsx)(`h1`,{className:`text-base font-semibold`,children:R(`cannotReach`,{label:e.source.label})}),(0,q.jsxs)(`p`,{className:`mt-1 text-muted-foreground`,children:[I4(e.error),` `,R(`restWorks`)]}),(0,q.jsx)(P,{className:`mt-3`,onClick:()=>void t.refetchQueries({queryKey:I.sourceMetas(e.source.url)}),children:R(`tryAgain`)})]})}):(0,q.jsxs)(`div`,{className:`flex h-full min-h-48 flex-1 items-center justify-center gap-2 text-muted-foreground`,children:[(0,q.jsx)(wn,{}),` `,R(`loadingFrom`,{label:e.source.label})]})},R4=B(`app/search`),z4=(e,t)=>e.toLowerCase().includes(t.trim().toLowerCase()),B4=(e,t,n=``)=>{let r=dQ(e,n).flatMap(e=>e.items.filter(e=>e.href!==void 0&&!e.problem)).filter(e=>z4(e.label,t)).slice(0,5),i=t.trim().replace(/^new\s+/i,``),a=Object.values(e.resources).flatMap(r=>{let a=e.views[r.name];if(!a||a.nav?.hidden||!NJ(a,e.pages,e.permissions[r.name]??ae))return[];let o=a.names?.singular??H(r.name),s=hy(`title`,{noun:o});return!z4(s,t)&&!z4(o,i)&&!z4(a.names?.plural??H(r.name),i)?[]:[{id:`new:${r.name}`,title:s,href:We({kind:`create`,resource:r.name},n)}]});return[...r.length>0?[{id:`go-to`,label:R4(`goTo`),hits:r.map(e=>({id:`go-to:${e.id}`,title:e.label,href:e.href}))}]:[],...a.length>0?[{id:`create`,label:R4(`create`),hits:a.slice(0,5)}]:[]]},V4=m(),H4=e=>Object.values(e.resources).flatMap(t=>{let n=e.views[t.name];return!t.search?.length||!n||n.nav?.hidden||e.permissions[t.name]?.read===!1?[]:[{model:t,view:n,label:n.names?.plural??H(t.name)}]}),U4=e=>{let t=e.map(e=>e.label.toLowerCase());return t.length===0?R4(`search`):t.length===1?R4(`searchOne`,{name:t[0]}):t.length===2?R4(`searchTwo`,{first:t[0],second:t[1]}):R4(`searchMore`,{first:t[0],second:t[1]})},W4=e=>vn(V4.search(e.trim())),G4=e=>!e.view?.searchResult?.title?.length&&e.view?.titleFrom!==void 0,K4=e=>{let t=e.view?.searchResult?.title;return t?.length?t:G4(e)?[]:[Ke(e.model,e.view)]},q4=e=>{let t=K4(e);return e.view?.searchResult?.subtitle??e.model.search?.find(e=>!t.includes(e))},J4=e=>{let t=q4(e),n=G4(e)?Jy(e.model,e.view):[],r=[...K4(e),...n,...t?[t]:[],...e.model.search??[]];return[...new Set([...e.model.primaryKey,...r.filter(t=>Object.hasOwn(e.model.fields,t))])]},Y4=(e,t,n)=>{let r=t[n];return r==null?``:e.model.fields[n]?.type===`enum`?ar(String(r),e.view?.fields[n]?.valueLabels):String(r)},X4=(e,t,n,r=``,i=Yy({},{user:void 0,member:()=>void 0}))=>{let a=Nn(xr(e.model,t)),o=K4(e),s=q4(e),c=Hi(e.model,t,n,[...o,...s?[s]:[]])??s,l=c?Y4(e,t,c):``;return{id:a,title:G4(e)?i(e.model,e.view,t,a):o.map(n=>Y4(e,t,n)).filter(Boolean).join(` `)||a,...l&&{subtitle:l},href:We({kind:`record`,resource:e.model.name,key:a},r)}},Z4=()=>{let e=c(),t=F(),{basePath:n}=le(),r=Qy(),i=(0,W.useMemo)(()=>H4(e),[e]),[a,o]=(0,W.useState)(``),s=a.trim(),l=BO(s,200),u=s.length>=2,d=u&&l.length>=2,f=wt({queries:i.map(e=>({queryKey:[`global-search`,e.model.name,l],enabled:d,staleTime:1/0,gcTime:0,queryFn:()=>t.list(e.model.name,{filter:W4(l),pageSize:5,fields:J4(e)})}))}),p=(0,W.useMemo)(()=>d?B4(e,l,n):[],[d,e,l,n]),m=i.flatMap((e,t)=>{let i=f[t];if(!d||!i)return[];if(i.error)return[{id:e.model.name,label:e.label,hits:[],failed:!0}];let a=(i.data?.items??[]).map(t=>X4(e,t,l,n,r));return a.length>0?[{id:e.model.name,label:e.label,hits:a}]:[]}),h=[...p,...m];return{available:Object.keys(e.pages).length>0||Object.keys(e.resources).length>0,placeholder:U4(i),text:a,setText:o,query:d?l:``,loading:u&&(s!==l||f.some(e=>e.isFetching)),groups:h}},Q4=(0,W.createContext)(void 0),$4=()=>(0,W.useContext)(Q4),e3=B(`app/new-version`),t3=()=>{let{versionChange:e,appName:t}=c(),{reload:n}=le(),r=$4();return!e||r?null:(0,q.jsxs)(`button`,{type:`button`,onClick:n,className:`flex w-full shrink-0 items-start gap-2 border-t border-warning/40 bg-warning-soft px-3.5 py-2 text-left text-warning-text transition-colors hover:bg-warning/15 focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-primary`,children:[(0,q.jsx)(ed,{"aria-hidden":!0,className:`mt-0.5 size-3.5 shrink-0`}),(0,q.jsxs)(`span`,{className:`flex min-w-0 flex-col gap-0.5`,children:[(0,q.jsx)(`span`,{className:`break-words font-semibold`,children:t?e3.rich(`bannerTitle`,{app:t}):e3(`title`)}),(0,q.jsx)(`span`,{className:`text-xs`,children:e3(`bannerLine`)})]})]})},n3=()=>{let e=!!c().versionChange,{reload:t}=le(),n=$4();return!e||n?null:(0,q.jsxs)(P,{size:`sm`,variant:`ghost`,"aria-label":e3(`reloadPageHint`),title:e3(`reloadPageHint`),onClick:t,className:`max-md:size-9 max-md:p-0`,children:[(0,q.jsx)(ed,{className:`size-3.5 text-primary`}),(0,q.jsx)(`span`,{className:`max-md:sr-only`,children:e3(`reloadPage`)})]})},r3=()=>document.querySelector(`[aria-modal="true"]`)!==null,i3=()=>{let[e,t]=(0,W.useState)(r3);return(0,W.useEffect)(()=>{let e=new MutationObserver(()=>t(r3()));return e.observe(document.body,{childList:!0,subtree:!0}),t(r3()),()=>e.disconnect()},[]),e},a3=()=>{let e=!!c().versionChange,t=i3(),[n,r]=(0,W.useState)(!1),i=nS(),{reload:a}=le(),o=$4(),s=e&&!n&&!t&&!o;return(0,W.useEffect)(()=>{if(!s)return;let e=i.show({state:`info`,sticky:!0,title:e3(`title`),description:e3(`description`),action:{label:e3(`reload`),onClick:a},onClose:()=>r(!0)});return()=>i.dismiss(e)},[s,i,a]),null},o3=B(`app/runtime`),s3=e=>!!(e?.updateAvailable&&e.indicator),c3=e=>e?5e3:18e5,l3=(e,t)=>{if(!e.updateStage)return o3(`updatingNow`);let n=o3(e.updateStage);if(!e.updateStartedAt)return n;let r=Math.max(0,Math.floor((t-Date.parse(e.updateStartedAt))/1e3));return o3(`started`,{stage:n,ago:br(r)})},u3=(e,t=Date.now(),n=Hn())=>e.updating?l3(e,t):e.nextUpdateAt?o3(`nextOn`,{policy:o3(e.policy),when:dr(Date.parse(e.nextUpdateAt),n)}):o3(e.policy),d3=(e,t=Hn())=>{let n=dr(Date.parse(e.finishedAt),t),r=o3(e.outcome,{version:e.toVersion,when:n});return e.message?`${r}: ${e.message}`:`${r}.`},f3=e=>Tn(e)&&e.status<500&&e.problem.detail?e.problem.detail:Tn(e)&&e.status===409?o3(`alreadyLatest`):Tn(e)&&e.status===403?o3(`onlyAdmin`):o3(`couldNotStart`),p3=({label:e,value:t})=>(0,q.jsxs)(`div`,{className:`flex justify-between gap-4 py-1`,children:[(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:e}),(0,q.jsx)(`span`,{className:`font-medium tabular-nums`,children:t})]}),m3=({status:e,requesting:t,error:n,checkError:r,onUpdate:i,onClose:a})=>{let o=e.updating?void 0:e.lastUpdate;return(0,q.jsxs)(di,{title:o3(`runtimeUpdate`),description:e.updating?(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,q.jsx)(wn,{className:`size-3.5`}),u3(e)]}):u3(e),onClose:a,actions:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(P,{onClick:a,children:o3(`close`)}),(0,q.jsx)(P,{variant:`primary`,loading:t,disabled:e.updating||!e.updateAvailable,onClick:i,children:e.updating?o3(`updating`):o3(`updateNow`)})]}),children:[(0,q.jsx)(p3,{label:o3(`currentVersion`),value:e.version}),(0,q.jsx)(p3,{label:o3(`latestVersion`),value:e.latest}),o&&(0,q.jsx)(`p`,{className:o.outcome===`failed`?`mt-3 text-danger-text`:`mt-3 text-muted-foreground`,children:d3(o)}),n!==void 0&&(0,q.jsx)(`p`,{role:`alert`,className:`mt-3 text-danger-text`,children:f3(n)}),r!==void 0&&(0,q.jsx)(`p`,{className:`mt-3 text-muted-foreground`,children:o3(`checkFailed`)})]})},h3=e=>{let t=iK(),n=(0,W.useRef)(t);n.current=t;let r=t!==void 0;return(0,W.useMemo)(()=>r?kh({url:e,token:()=>n.current}):void 0,[e,r])},g3=e=>{let[t,n]=(0,W.useState)(),[r,i]=(0,W.useState)(!1),[a,o]=(0,W.useState)(),[s,c]=(0,W.useState)(),l=t?.updating??!1;return(0,W.useEffect)(()=>{if(!e)return;let t=!0,r=()=>e.status().then(e=>{t&&(n(e),c(void 0))},e=>t&&c(e));r();let i=setInterval(()=>void r(),c3(l));return()=>{t=!1,clearInterval(i)}},[e,l]),{status:t,update:(0,W.useCallback)(async()=>{e&&(i(!0),o(void 0),await e.update().then(n,o),i(!1))},[e]),requesting:r,error:a,checkError:s}},_3=({client:e})=>{let{status:t,update:n,requesting:r,error:i,checkError:a}=g3(e),[o,s]=(0,W.useState)(!1);return!t||!o&&!s3(t)?null:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(P,{size:`sm`,variant:`ghost`,"aria-label":o3(`updateAvailable`),title:o3(`updateAvailable`),onClick:()=>s(!0),className:`max-md:size-9 max-md:p-0`,children:[(0,q.jsx)(Oc,{className:`size-3.5 text-primary`}),(0,q.jsx)(`span`,{className:`max-md:sr-only`,children:o3(`update`)})]}),o&&(0,q.jsx)(m3,{status:t,requesting:r,error:i,checkError:a,onUpdate:()=>void n(),onClose:()=>s(!1)})]})},v3=({url:e})=>(0,q.jsx)(_3,{client:h3(e)}),y3=({url:e,client:t})=>t?(0,q.jsx)(_3,{client:t}):(0,q.jsx)(v3,{url:e}),b3=({signIn:e,onStop:t})=>{let[n,r]=(0,W.useState)(!1),[i,a]=(0,W.useState)(),o=async()=>{r(!0),a(void 0);try{await t()}catch(e){if(!(e instanceof Jm))throw e;a($C(e)),r(!1)}};return(0,q.jsxs)(`div`,{role:`region`,"aria-label":R(`staffSession`),className:`flex flex-wrap items-center gap-x-3 gap-y-2 border-b border-warning/40 bg-warning-soft px-4 py-2 text-warning-text`,children:[(0,q.jsx)(Qd,{"aria-hidden":!0,className:`size-4 shrink-0`}),(0,q.jsx)(`p`,{className:`min-w-64 flex-1 break-words`,children:R.rich(`staffSignedIn`,{staff:(0,q.jsx)(`span`,{className:`font-semibold`,children:e.staffName??e.staff}),user:(0,q.jsx)(`span`,{className:`font-semibold`,children:e.user}),until:dr(Date.parse(e.expiresAt)),reason:e.reason})}),i&&(0,q.jsx)(`p`,{role:`alert`,className:`text-body font-medium text-danger-text`,children:i}),(0,q.jsx)(P,{size:`sm`,loading:n,onClick:()=>void o(),children:R(`stopStaffSession`)})]})},x3=(e,t,n)=>{if(!e)return;let r=new Map((n??[]).map(e=>[e.userId,e]));return Object.fromEntries(Object.entries(e).map(([e,{person:n,...i}])=>{if(n===void 0)return[e,i];let a=r.get(n),o=d$(t,n);return[e,{...i,person:{...a&&{status:a},...o&&{presence:o}}}]}))},S3=(e,t,n)=>({filter:n.filter??``,orderBy:n.orderBy??Pe(e,t),pageSize:n.limit??3,fields:[...new Set([...e.primaryKey,Ke(e,t),...Jy(e,t),...n.status===void 0?[]:[n.status]])]}),C3=(e,t,n,r)=>{if(n.status===void 0)return;let i=String(r[n.status]??``);return{label:e.fields[n.status]?.type===`enum`&&i?ar(i,t.fields[n.status]?.valueLabels):i,tone:n.tones?.[i]??`neutral`,pulse:n.pulse?.includes(i)??!1}},w3=(e,t,n,r,i,a,o)=>r.map(r=>{let s=Nn(xr(e,r)),c=C3(e,t,n,r);return{id:s,label:o(e,t,r,s),href:We({kind:`record`,resource:e.name,key:s},i),...c&&{status:c},active:s===a}}),T3=(e,t,n,r,i)=>{let a=n.find(t=>Nn(xr(e,t))===r);return a!==void 0&&t.some(e=>!Object.is(a[e],i[e]))},E3=(e,t,n)=>{if(t.marks===void 0||!n||!Object.hasOwn(n,t.marks))return;let r=n[t.marks];return()=>r(e)},D3=e=>e&&(()=>x3(e(),u$(),zy().data)),O3=({model:e,request:t})=>I.navRecent(e.name,t.filter,t.orderBy,t.pageSize),k3=e=>{let t=nn();(0,W.useEffect)(()=>t.getQueryCache().subscribe(n=>{if(n.type!==`updated`||n.action.type!==`success`)return;let[r,i,a]=n.query.queryKey,o=n.action.data?.record;if(r===`record`&&typeof a==`string`&&o)for(let n of e){if(n.model.name!==i)continue;let e=t.getQueryData(O3(n));e&&T3(n.model,n.request.fields,e.items,a,o)&&t.invalidateQueries({queryKey:O3(n),exact:!0})}}),[t,e])},A3=(e,t,n)=>{let r=F(),i=Qy(),{marks:a}=qy(),o=(0,W.useMemo)(()=>{let t=aQ(e);return Object.values(e.views).flatMap(n=>{let r=e.resources[n.resource],i=n.nav?.recent;return r&&i&&!n.nav?.hidden&&!t.has(r.name)?[{model:r,view:n,recent:i,request:S3(r,n,i),useMarks:D3(E3(r.name,i,a))}]:[]})},[e,a]);k3(o);let s=wt({queries:o.map(e=>({queryKey:O3(e),queryFn:()=>r.list(e.model.name,e.request)}))});return Object.fromEntries(o.map(({model:e,view:r,recent:a,useMarks:o},c)=>{let l=s[c];if(l.isPending)return[e.name,{state:`loading`}];if(l.isError)return[e.name,{state:`error`}];let u=n.resource===e.name?n.key:void 0;return[e.name,{state:`ready`,records:w3(e,r,a,l.data.items,t,u,i),...o&&{useMarks:o}}]}))},j3=`SplashScreen`,M3=e=>{if(e?.isPluginAvailable(j3))return{show:()=>e.nativePromise(j3,`show`,{autoHide:!1}),hide:()=>e.nativePromise(j3,`hide`,{})}},N3=({answer:e,current:t,next:n})=>!e?.bundleId||e.required||e.bundleId===t||e.bundleId===n?{kind:`none`}:{kind:`take`,bundleId:e.bundleId},P3=e=>{let t=typeof e==`object`&&e?e.bundleId:void 0;return typeof t==`string`?t:null},F3=({bridge:e,check:t,releasesUrl:n,splash:r})=>{let i=(t,n={})=>e.nativePromise(`LiveUpdate`,t,n),a=t=>t instanceof e.Exception,o=async(e,t)=>{try{return await e()}catch(e){if(!a(e))throw e;return t}},s=async e=>{await i(`downloadBundle`,{bundleId:e,url:`${n}/${e}`,artifactType:`manifest`}),await i(`setNextBundle`,{bundleId:e})},c=()=>o(async()=>{let[e,n,r]=await Promise.all([t(),i(`getCurrentBundle`),i(`getNextBundle`)]),a=N3({answer:e,current:P3(n),next:P3(r)});a.kind!==`none`&&await s(a.bundleId)},void 0),l=e=>o(async()=>{let[t,n]=await Promise.all([i(`getCurrentBundle`),i(`getNextBundle`)]),a=P3(n);if(a===null||a===P3(t))return!1;e();let o=!1;try{await r?.show(),await i(`reload`),o=!0}finally{o||await r?.hide()}return!0},!1),u;return{ready:()=>i(`ready`),applyNext:l,check:()=>(u??=c().finally(()=>{u=void 0}),u)}},I3=e=>/(?:^|\s)ProtobaseNative\/([0-9a-f]{16})(?:\s|$)/.exec(e)?.[1],L3=/^[A-Za-z0-9_-]{1,64}$/,R3=e=>typeof e==`object`&&!!e&&!Array.isArray(e),z3=e=>{if(!R3(e))return;let{bundleId:t,url:n,required:r}=e;if((t===null||typeof t==`string`&&L3.test(t))&&(n===null||typeof n==`string`)&&typeof r==`boolean`)return{bundleId:t,url:n,required:r}},B3=15e3,V3=e=>e instanceof TypeError||e instanceof DOMException&&e.name===`TimeoutError`,H3=async(e,{apiOrigin:t,fingerprint:n,shellVersion:r})=>{let i=`${t}${Go}?${qo({fingerprint:n,shellVersion:r})}`;try{let t=await e(i,{credentials:`omit`,cache:`no-store`,signal:AbortSignal.timeout(B3)});return t.status===200?z3(await t.json()):void 0}catch(e){if(V3(e)||e instanceof SyntaxError)return;throw e}},U3=({bridge:e,apiOrigin:t,userAgent:n,fetch:r})=>{if(!e?.Exception||!e.isPluginAvailable(`LiveUpdate`))return;let i=I3(n);return F3({bridge:{nativePromise:e.nativePromise.bind(e),Exception:e.Exception},check:async()=>i&&t?H3(r,{apiOrigin:t,fingerprint:i,shellVersion:fs}):void 0,releasesUrl:`${t}${Ko}`,splash:M3(e)})},W3=({updater:e,children:t})=>((0,W.useEffect)(()=>{e&&e.ready()},[e]),(0,q.jsx)(Q4.Provider,{value:e,children:t})),G3=async(e,t)=>{let n=!1,r=!1;try{r=await e.applyNext(()=>{t.keep(),n=!0})}finally{!r&&n&&t.forget()}return r},K3=2e4,q3=async(e,t)=>{let n,r=new Promise(e=>{n=setTimeout(()=>e(!1),K3)}),i=e.check();return await Promise.race([i.then(()=>!0),r]).finally(()=>clearTimeout(n))?t?G3(e,t):!1:(i.then(()=>void 0),!1)},J3=`pb-start`,Y3=e=>(e.getElementById(`pb-snapshot`)?.childNodes.length??0)>0,X3=`pb-start-hand-off`,Z3=e=>{let t=e.getElementById(J3);t&&(t.dispatchEvent(new Event(X3)),t.remove())},Q3=4e3,$3={type:`active`,predicate:e=>e.state.data===void 0},e6=()=>{let e=(0,W.useContext)(j),t=nn(),n=pt($3),[r]=(0,W.useState)(()=>typeof document<`u`&&Y3(document)),i=(0,W.useRef)(void 0);return(0,W.useEffect)(()=>{if(!e||!r)return;let t=e.hold();i.current=t;let n=setTimeout(t,Q3);return()=>{clearTimeout(n),t()}},[e,r]),(0,W.useEffect)(()=>{if(n>0)return;let e=setTimeout(()=>t.isFetching($3)===0&&i.current?.(),0);return()=>clearTimeout(e)},[n,t]),null},t6=9e5,n6=(e,t)=>{e();let n=setInterval(()=>{t()&&e()},t6);return()=>clearInterval(n)},r6=()=>{let e=$4(),t=Y().state.kind===`signed-in`,n=!!c().versionChange;return(0,W.useEffect)(()=>{if(e&&t)return n6(()=>void e.check(),()=>document.visibilityState===`visible`)},[e,t,n]),null},i6=(e=Date.now)=>{let t;return{leave:()=>{t=e()},back:()=>{let n=t===void 0?0:e()-t;return t=void 0,n}}},a6=({updater:e,holdsChanges:t,page:n,now:r})=>{let i=i6(r);return{leave:i.leave,back:async()=>{let r=i.back();n&&r>=3e5&&!t()&&await G3(e,n)||await e.check()}}},o6=()=>{let e=$4(),{holdsChanges:t}=le();return(0,W.useEffect)(()=>{if(!e)return;let n=a6({updater:e,holdsChanges:t,page:Es()}),r=()=>{if(document.visibilityState===`hidden`)return n.leave();n.back()};return document.addEventListener(`visibilitychange`,r),()=>document.removeEventListener(`visibilitychange`,r)},[e,t]),null},s6=[`never`,`thirty_minutes`,`one_hour`,`four_hours`,`today`,`this_week`,`custom`],c6={thirty_minutes:30,one_hour:60,four_hours:240},l6=(e,t)=>new Date(e.getFullYear(),e.getMonth(),e.getDate()+t),u6=(e,t,n=``)=>{if(e===`never`)return null;if(e===`today`)return l6(t,1).toISOString();if(e===`this_week`)return l6(t,(8-t.getDay())%7||7).toISOString();if(e===`custom`){let e=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2})?$/.test(n)?new Date(n):void 0;return e&&!Number.isNaN(e.getTime())?e.toISOString():void 0}return new Date(t.getTime()+c6[e]*6e4).toISOString()},d6=e=>String(e).padStart(2,`0`),f6=e=>{let t=new Date(e);return`${t.getFullYear()}-${d6(t.getMonth()+1)}-${d6(t.getDate())}T${d6(t.getHours())}:${d6(t.getMinutes())}`},p6=(e,t=Date.now())=>{let n=xn(e,t);return n?{availability:n.availability,text:n.text??``,clears:n.clearsAt===null?`never`:`custom`,custom:n.clearsAt===null?``:f6(n.clearsAt)}:{availability:`automatic`,text:``,clears:`never`,custom:``}},m6=(e,t)=>{let n=e.text.trim(),r=n===``?void 0:bn(n);if(r)return{problem:`text`,message:r};let i=u6(e.clears,t,e.custom);return i===void 0||i!==null&&Date.parse(i)<=t.getTime()?{problem:`time`}:{input:{availability:e.availability,text:n===``?null:n,clearsAt:i}}},h6={never:`never`,thirty_minutes:`thirtyMinutes`,one_hour:`oneHour`,four_hours:`fourHours`,today:`today`,this_week:`thisWeek`,custom:`custom`},g6=({current:e,onSave:t,onClear:n,onClose:r})=>{let[i,a]=(0,W.useState)(()=>p6(e)),[o,s]=(0,W.useState)(!1),[c,l]=(0,W.useState)(),[u,d]=(0,W.useState)(!1),f=(0,W.useId)(),p=(0,W.useId)(),m=(0,W.useId)(),h=e=>a({...i,...e}),g=m6(i,new Date),_=u&&`problem`in g?g:void 0,v=async e=>{s(!0),l(void 0);try{await e(),r()}catch(e){if(!(e instanceof An))throw e;l(e.status===400?e.message:uj(`couldNotSave`)),s(!1)}},y=()=>{d(!0),`input`in g&&v(()=>t(g.input))};return(0,q.jsx)(di,{title:uj(e?`editStatus`:`setStatus`),onClose:r,actions:(0,q.jsxs)(q.Fragment,{children:[e&&(0,q.jsx)(P,{variant:`ghost`,className:`sm:mr-auto`,disabled:o,onClick:()=>void v(n),children:uj(`clear`)}),(0,q.jsx)(P,{onClick:r,children:uj(`cancel`)}),(0,q.jsx)(P,{variant:`primary`,type:`submit`,form:f,loading:o,children:uj(`save`)})]}),children:(0,q.jsxs)(`form`,{id:f,className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),y()},children:[(0,q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,q.jsx)(`label`,{htmlFor:p,className:`font-medium`,children:uj(`statusText`)}),(0,q.jsx)(bi,{id:p,name:`status`,autoComplete:`off`,autoFocus:!0,placeholder:uj(`statusPlaceholder`),value:i.text,maxLength:200,invalid:_?.problem===`text`,..._?.problem===`text`&&{"aria-describedby":`${p}-problem`},onChange:e=>h({text:e.target.value})}),_?.problem===`text`&&(0,q.jsx)(`span`,{id:`${p}-problem`,className:`text-xs text-danger-text`,children:_.message})]}),(0,q.jsxs)(`div`,{className:`flex flex-col gap-1.5 font-medium`,children:[uj(`availability`),(0,q.jsx)(Av,{label:uj(`availability`),value:i.availability,onChange:e=>h({availability:e}),options:[{value:`automatic`,label:uj(`automatic`)},{value:`busy`,label:uj(`busy`)},{value:`do_not_disturb`,label:uj(`doNotDisturb`)}]}),i.availability===`do_not_disturb`&&(0,q.jsx)(`span`,{className:`text-xs font-normal text-muted-foreground`,children:uj(`doNotDisturbHint`)})]}),(0,q.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[uj(`clearsAfter`),(0,q.jsx)(`select`,{name:`clears`,value:i.clears,onChange:e=>h({clears:e.target.value}),className:`h-8 rounded-md border border-border-strong bg-background px-2 font-normal`,children:s6.map(e=>(0,q.jsx)(`option`,{value:e,children:uj(h6[e])},e))})]}),i.clears===`custom`&&(0,q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,q.jsx)(`label`,{htmlFor:m,className:`font-medium`,children:uj(`clearsAt`)}),(0,q.jsx)(bi,{id:m,type:`datetime-local`,name:`clears-at`,value:i.custom,invalid:_?.problem===`time`,..._?.problem===`time`&&{"aria-describedby":`${m}-problem`},onChange:e=>h({custom:e.target.value})}),_?.problem===`time`&&(0,q.jsx)(`span`,{id:`${m}-problem`,className:`text-xs text-danger-text`,children:uj(`pickTime`)})]}),c&&(0,q.jsx)(`p`,{role:`alert`,className:`text-danger-text`,children:c})]})})},_6=e=>{let t=F(),n=nn(),r=By(),[i,a]=(0,W.useState)(!1);if(!e||!r.isSuccess)return{};let o=xn(r.data),s=()=>n.invalidateQueries({queryKey:[`statuses`]});return{menu:{mark:o&&(0,q.jsx)(mj,{status:o,textShown:`hover`}),label:o?(0,q.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5 text-foreground`,children:[(0,q.jsx)(pj,{availability:o.availability}),(0,q.jsx)(`span`,{className:`truncate`,children:o.text??fj(o.availability)})]}):uj(`setStatus`),onOpen:()=>a(!0)},...i&&{dialog:(0,q.jsx)(g6,{current:o,onSave:async e=>{await t.status.set(e),await s()},onClear:async()=>{await t.status.clear(),await s()},onClose:()=>a(!1)})}}},v6=e=>e?.kind===`page`?e.page:e?.kind===`list`?sQ(e.resource,e.list):e?.resource,y6=e=>e?.kind===`record`?e:void 0,b6=({workspace:e,sidebarMode:t,assistant:n,runtime:r})=>{let i=c(),{state:a,session:o,signOut:s,stopStaffSession:l,organizations:u}=Y(),d=UF();if(a.kind!==`signed-in`&&a.kind!==`visitor`)throw Error(`The shell is only rendered for a signed-in user or a visitor`);let f=a.kind===`signed-in`?a.user:void 0,p=a.kind===`signed-in`?a.staff:void 0,{path:m,params:h,basePath:g,navigate:_}=le(),{address:v,go:y,open:b,back:x}=Me(),S=v6(v),C=y6(v),w=Z4(),T=Uk(),E=A3(i,g,{resource:C?.resource,key:C?.key}),D=Pn();lK(i);let O=dQ(i,g,E),k=(0,W.useMemo)(()=>R$(i),[i]),ee=v?.kind===`page`?i.pages[v.page]:void 0;(0,W.useEffect)(()=>{m===`/`&&(k?y(k,{replace:!0}):f&&_(qg,{replace:!0}))},[m,k,y,f,_]);let A=v?.kind===`page`?void 0:v?.resource,te=A?ie(i,A):void 0,ne=A?Se(i.views[A],v?.kind===`list`?v.list:void 0):void 0,re=O.find(e=>e.items.some(e=>e.id===S)),j=A?i.resources[A]:void 0,M=rx(C?.resource??``,C?.key??``,!!(j&&C)),ae=Qy(),oe=j&&C&&M.data?ae(j,ne,M.data.record,C.key):void 0,se=!!C&&(M.isLoading||te?.state===`loading`),{shell:ce}=qy(),ue=ce?.actions,de=ce?.rightPanel,fe=i.bell&&f&&!p&&(0,q.jsx)(m1,{own:ce?.bell}),pe=_6(!!(i.status&&f&&!p)),me=zy().data,he=u$(),[ge,_e]=(0,W.useState)(!1),ve=i.assistant?.url,ye=ve&&(0,q.jsx)(Iq,{open:ge,onToggle:()=>_e(!ge)}),be=ve&&ge&&(0,q.jsx)(zq,{url:ve,client:n,page:h.size>0?`${m}?${h}`:m,onClose:()=>_e(!1)}),xe=i.errorReporting;(0,W.useEffect)(()=>{xe&&zh(xe)},[xe]);let Ce=i.runtime?.url,we=Ce&&(0,q.jsx)(y3,{url:Ce,client:r}),N=Cj(t??`text-small`),Te=i.versionChange&&!N&&(0,q.jsx)(n3,{}),Ee=L$((0,W.useCallback)(()=>x$(g),[g]),!!f),De=f&&P$(f,Ee.current),Oe=De?Ab(De):!1,ke=g1(),Ae=b$(!!(u&&f)),je=Ae.current,Ne=!!u&&je!==void 0&&!je.organization,Pe=u&&f?AV(m):void 0,Fe=IU(),Ie=f?Yg(m):void 0,Le=Ie&&Fe?r_(n_(Fe.tree),Ie.tab):void 0,Re=f?Ie?Fe?.title??R(`account`):m===`/-/sign-in-policy`?R(`signInPolicy`):Pe:void 0,ze=ne?.names?.plural??(A&&H(A)),Be=v?.kind===`record`&&!v.standard&&!!i.views[v.resource]?.record,Ve=Re?[Re]:Wq({basePath:g,address:v,group:re?.label,page:ee,resourceLabel:ze,headingless:Be,recordTitle:oe,recordLoading:se}),He=ne?.names?.singular??(A&&H(A)),Ue=ee&&v?.kind===`page`?r_(n_(ee.tree),v.tab):void 0;VV(BV(zV({address:v,page:ee?{title:ee.title,...Ue&&{tab:Ue.label}}:Ie&&Fe&&{title:Fe.title,...Le&&{tab:Le.label}},accountPage:Re,resourceLabel:ze,singular:He,recordTitle:oe,recordLoading:se}),i.appName));let We=Ie?(0,q.jsx)(LU,{...Ie}):f&&m===`/-/sign-in-policy`?Oe?(0,q.jsx)(vW,{}):(0,q.jsx)(tt,{title:R(`adminsOnly`),children:R(`onlyAdminPolicy`)}):Pe&&m===`/-/organization`?(0,q.jsx)(D$,{current:je,basePath:g,onChanged:Ae.reload}):Pe&&(m===`/-/organization/members`||m===`/-/organization/invitations`)?NV(je)?m===`/-/organization/members`?(0,q.jsx)(m$,{current:je,statuses:me,presence:he}):(0,q.jsx)(_$,{current:je}):(0,q.jsx)(tt,{title:R(`ownersOnly`),children:R(`onlyOwners`)}):Pe&&m===`/-/organizations`||Ne?(0,q.jsx)(N$,{state:Ae,basePath:g}):v?v.kind===`page`?ee?(0,q.jsx)(tJ,{name:ee.name,...v.tab&&{tab:v.tab},...v.params&&{params:v.params}},ee.name):(0,q.jsx)(tt,{title:R(`notFound`),children:R.rich(`noPage`,{page:v.page})}):te&&te.state!==`ready`?(0,q.jsx)(L4,{status:te}):v.kind===`create`?(0,q.jsx)(mJ,{resource:v.resource,values:v.values},v.resource):v.kind===`record`?(0,q.jsx)(M4,{resource:v.resource,recordKey:v.key},`${v.resource}/${v.key}`):(0,q.jsx)(i$,{address:v},sQ(v.resource,v.list)):m===`/`?(0,q.jsx)(tt,{title:R(`chooseResource`),children:R(`pickFromSidebar`)}):(0,q.jsx)(tt,{title:R(`notFound`),children:R(`nothingHere`)}),Ge=Oe&&ke.length>0;return(0,q.jsxs)(Lj,{pageScroll:!0,sidebarMode:t??`text-small`,activeItem:S??``,breadcrumb:Ve,titleStatus:D!==`fresh`&&(0,q.jsx)(F4,{failed:D===`failed`}),staleContent:D===`fresh`?void 0:D===`failed`?`failed`:`refreshing`,user:De&&Mb(De),onSignOut:f&&(()=>void s()),signIn:f?void 0:d.link(),workspace:je?.organization?.name??e,appName:i.appName,appIcon:i.appIcon,logo:z$,navGroups:O,bottomBar:Uq(i,g,S),userMenu:[oQ(i,g,S),u&&f?PV(g,m,je):[],f?Zg(g,m,Oe):[]],account:f&&`${g}/-/account`,organizations:u&&{...je?.organization&&{current:{id:je.organization.id,name:je.organization.name}},others:Ae.organizations.filter(e=>e.id!==je?.organization?.id),onSwitch:e=>void o.organizations.switchTo(e).then(()=>x$(g))},theme:{preference:T.preference,onChange:T.choose},...pe.menu&&{status:pe.menu},roles:Ee.current?.active?{active:Ee.current.active,roles:Ee.current.roles,onSwitch:Ee.switchTo}:void 0,onNavigate:b,onBack:x,sidebarNotice:(0,q.jsx)(t3,{}),banner:(p||Ge)&&(0,q.jsxs)(q.Fragment,{children:[p&&(0,q.jsx)(b3,{signIn:p,onStop:l}),Ge&&(0,q.jsx)(v1,{off:ke})]}),search:w.available?{placeholder:w.placeholder,text:w.text,onTextChange:w.setText,query:w.query,loading:w.loading,groups:w.groups,onSelect:b}:void 0,actions:(ue||fe||Te||we||ye)&&(0,q.jsxs)(q.Fragment,{children:[ue&&(0,q.jsx)(FS,{name:`shell.actions`,fallback:null,children:(0,q.jsx)(ue,{})}),fe,Te,we,ye]}),rightPanel:(de||be)&&(0,q.jsxs)(q.Fragment,{children:[de&&(0,q.jsx)(FS,{name:`shell.rightPanel`,fallback:null,children:(0,q.jsx)(de,{})}),be]}),children:[We,pe.dialog,i.calls&&f&&!p&&(0,q.jsx)(J$,{})]})},x6=({baseUrl:e,client:t,sources:n,workspace:r,sidebarMode:i,ui:a,assistant:o,runtime:s})=>{let{state:c,session:l,markSignedOut:u}=Y(),d=Cj(i??`text-small`),{path:f}=le(),p=cK(c),m=Dg(c),h=ys(),g=(0,W.useMemo)(()=>h&&m?DW({cache:h,owner:p}):void 0,[h,m,p]);return(0,q.jsx)(Ln,{baseUrl:e,client:t,sources:n,token:c.kind===`visitor`?void 0:l.token,onUnauthenticated:u,persistence:g,children:(0,q.jsx)(O,{children:(0,q.jsxs)(rS,{children:[!d&&(0,q.jsx)(a3,{}),(0,q.jsx)(r6,{}),f===`/-/connect`?(0,q.jsx)(oW,{}):(0,q.jsxs)(_1,{ui:a,children:[(0,q.jsx)(e6,{}),(0,q.jsx)(y$,{children:(0,q.jsx)(tb,{children:(0,q.jsx)(b6,{workspace:r,sidebarMode:i,assistant:o,runtime:s})})})]})]})})},p)},S6=({baseUrl:e,client:t,ui:n,children:r})=>{let i=mK();return i?(0,q.jsx)(Ln,{baseUrl:e,client:t,children:(0,q.jsx)(Ky.Provider,{value:n??{},children:(0,q.jsx)(fK,{name:i.name},i.name)})}):r},C6=({baseUrl:e,children:t})=>{let n=JK(),{basePath:r}=le();if(!n)return t;let i=new URL(e??`/api/v1`,window.location.href),a=`${i.origin}${i.pathname.slice(0,i.pathname.lastIndexOf(`/`))}`;return(0,q.jsx)(fq,{link:n.token,systemPath:a,base:`${window.location.origin}${r}`})},w6=({auth:e,workspace:t,basePath:n,initialUrl:r,pluginLoader:i,locale:a,nativeBridge:o,startCache:s,...c})=>{ai(a??`en`);let l=c.baseUrl&&new URL(c.baseUrl,window.location.href).origin,u=(0,W.useMemo)(()=>U3({bridge:o,apiOrigin:l,userAgent:navigator.userAgent,fetch:window.fetch.bind(window)}),[o,l]),d=(0,W.useMemo)(()=>u&&(()=>q3(u,Es())),[u]),f=(0,W.useMemo)(()=>b(()=>{Z3(document),M3(o)?.hide()}),[o]);return(0,W.useEffect)(()=>f.start(),[f]),(0,q.jsx)(g,{value:f,children:(0,q.jsx)(vs,{value:s,children:(0,q.jsx)(Hk,{children:(0,q.jsx)(W3,{updater:u,children:(0,q.jsx)(Lg,{session:e,...l&&{origin:l},...o&&{nativeBridge:o},...d&&{afterSignIn:d},children:(0,q.jsxs)(Be,{basePath:n,initialUrl:r,children:[(0,q.jsx)(o6,{}),o&&l&&(0,q.jsx)(Kg,{nativeBridge:o,apiOrigin:l}),(0,q.jsx)(KG,{...i&&{loader:i},children:(0,q.jsx)(aK,{children:(0,q.jsx)(S6,{baseUrl:c.baseUrl,client:c.client,ui:c.ui,children:(0,q.jsx)(C6,{...c.baseUrl&&{baseUrl:c.baseUrl},children:(0,q.jsx)(eK,{workspace:t,children:(0,q.jsx)(x6,{workspace:t,...c})})})})})})]})})})})})})};export{LA as $,jy as $t,iK as A,ds as An,iS as At,jH as B,nx as Bt,Sq as C,vl as Cn,JC as Ct,dq as D,Ms as Dn,qS as Dt,hq as E,nc as En,oC as Et,OW as F,gx as Ft,jI as G,rb as Gt,Zz as H,$b as Ht,RU as I,hx as It,KF as J,Uy as Jt,OI as K,Gy as Kt,zU as L,mx as Lt,kG as M,xx as Mt,SG as N,vx as Nt,Q as O,Ts as On,GS as Ot,kW as P,_x as Pt,VA as Q,Iy as Qt,UU as R,px as Rt,Dq as S,iu as Sn,Pw as St,gq as T,Ac as Tn,yC as Tt,Hz as U,Kb as Ut,HV as V,tx as Vt,hz as W,vb as Wt,pj as X,By as Xt,yM as Y,Ly as Yt,mj as Z,zy as Zt,aJ as _,Ku as _n,bE as _t,G1 as a,Av as an,YO as at,Mq as b,Iu as bn,Zw as bt,H1 as c,g_ as cn,HO as ct,c1 as d,em as dn,CO as dt,ky as en,PA as et,u1 as f,Zp as fn,bO as ft,dJ as g,Qu as gn,dO as gt,u$ as h,id as hn,lO as ht,U1 as i,Mv as in,tk as it,IG as j,fs as jn,Sx as jt,sK as k,gs as kn,BS as kt,B1 as l,Ah as ln,IO as lt,Z$ as m,Wd as mn,vO as mt,e0 as n,hy as nn,dk as nt,K1 as o,D_ as on,GO as ot,s1 as p,Jd as pn,yO as pt,DI as q,Wy as qt,$1 as r,Yv as rn,nk as rt,V1 as s,C_ as sn,WO as st,w6 as t,Oy as tn,Ck as tt,E1 as u,Im as un,AO as ut,Fq as v,Wu as vn,SE as vt,yq as w,Ic as wn,CC as wt,jq as x,Eu as xn,eT as xt,Pq as y,Hu as yn,xE as yt,WU as z,cx as zt};
16
+ //# debugId=5b07bf6b-1a86-45a4-a107-406aeba2b651