@protobase/ui 0.66.6 → 0.66.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/account/blocks/password-block.js +1 -1
- package/dist/account/change-email-dialog.js +5 -1
- package/dist/account/password-change-dialog.js +4 -11
- package/dist/account/password-section.js +2 -2
- package/dist/app/error-reporting.js +8 -3
- package/dist/app/field-types/field-type-cells.js +2 -1
- package/dist/auth/email-code-form.js +8 -4
- package/dist/auth/sign-up-code-form.js +8 -4
- package/dist/auth/two-factor-form.js +2 -1
- package/dist/locale/en.js +5 -4
- package/dist/locale/nl.js +5 -4
- package/dist/package.js +1 -1
- package/dist/shell/assets/app-BZ_OcfpZ.js +8 -0
- package/dist/shell/assets/calls-uuSb7D6L.js +2 -0
- package/dist/shell/assets/cn-B1sdg8aY.js +2 -0
- package/dist/shell/assets/export-worker-CcXp0ZdG.js +15 -0
- package/dist/shell/assets/index-B2M0LDVQ.js +2 -0
- package/dist/shell/assets/maplibre-DfXLXH-O.js +815 -0
- package/dist/shell/assets/{markdown-content-DOuciTNH.js → markdown-content-L1MZShpP.js} +2 -2
- package/dist/shell/assets/parse-worker-CUJ2o-AL.js +35 -0
- package/dist/shell/assets/preload-helper-Ru-oozfe.js +2 -0
- package/dist/shell/assets/{prod-YZ9ZMG1O.js → prod-DSoLg5cQ.js} +3 -3
- package/dist/shell/assets/{react-CR5VJ85Q.js → react-CqoBMk9d.js} +2 -2
- package/dist/shell/assets/record-map-Cocva8wo.js +2 -0
- package/dist/shell/assets/records-map-B1PDo3PS.js +2 -0
- package/dist/shell/assets/rolldown-runtime-DXfiGoCU.js +1 -0
- package/dist/shell/assets/shared-protobase-ui-V8ARYzmY.js +2 -0
- package/dist/shell/assets/shared-react-CJlT6JLM.js +1 -0
- package/dist/shell/assets/shared-react-dom-untDBgp5.js +1 -0
- package/dist/shell/assets/shared-react-jsx-runtime-DGG2WguE.js +1 -0
- package/dist/shell/assets/{vendor-Kvdo8Jrw.js → vendor-qs9zUu9T.js} +2 -2
- package/dist/shell/index.html +8 -8
- package/dist/shell/protobase.shell.json +2 -2
- package/dist/shell/protobase.sw.js +2 -2
- package/dist/shell-source-maps/assets/app-BZ_OcfpZ.js.map +1 -0
- package/dist/shell-source-maps/assets/calls-uuSb7D6L.js.map +1 -0
- package/dist/shell-source-maps/assets/cn-B1sdg8aY.js.map +1 -0
- package/dist/shell-source-maps/assets/export-worker-CcXp0ZdG.js.map +1 -0
- package/dist/shell-source-maps/assets/index-B2M0LDVQ.js.map +1 -0
- package/dist/shell-source-maps/assets/maplibre-DfXLXH-O.js.map +1 -0
- package/dist/shell-source-maps/assets/{markdown-content-DOuciTNH.js.map → markdown-content-L1MZShpP.js.map} +1 -1
- package/dist/shell-source-maps/assets/parse-worker-CUJ2o-AL.js.map +1 -0
- package/dist/shell-source-maps/assets/preload-helper-Ru-oozfe.js.map +1 -0
- package/dist/shell-source-maps/assets/prod-DSoLg5cQ.js.map +1 -0
- package/dist/shell-source-maps/assets/react-CqoBMk9d.js.map +1 -0
- package/dist/shell-source-maps/assets/record-map-Cocva8wo.js.map +1 -0
- package/dist/shell-source-maps/assets/records-map-B1PDo3PS.js.map +1 -0
- package/dist/shell-source-maps/assets/shared-protobase-ui-V8ARYzmY.js.map +1 -0
- package/dist/shell-source-maps/assets/{vendor-Kvdo8Jrw.js.map → vendor-qs9zUu9T.js.map} +1 -1
- package/package.json +4 -4
- package/dist/shell/assets/app-D1iOLNRp.js +0 -8
- package/dist/shell/assets/calls-CMM47K7J.js +0 -2
- package/dist/shell/assets/cn-Bi0ZEjD9.js +0 -2
- package/dist/shell/assets/export-worker-BKuC4P2E.js +0 -15
- package/dist/shell/assets/index-DYuB1IqS.js +0 -2
- package/dist/shell/assets/maplibre-lc2A-_P4.js +0 -815
- package/dist/shell/assets/parse-worker-BzLD2jKf.js +0 -35
- package/dist/shell/assets/preload-helper-DedkISGJ.js +0 -2
- package/dist/shell/assets/record-map-CupIwJyD.js +0 -2
- package/dist/shell/assets/records-map-Cs38aEuP.js +0 -2
- package/dist/shell/assets/rolldown-runtime-hePW80VL.js +0 -1
- package/dist/shell/assets/shared-protobase-ui-CMNP9cBW.js +0 -2
- package/dist/shell/assets/shared-react-CuZpzdyh.js +0 -1
- package/dist/shell/assets/shared-react-dom-BNlY7-7i.js +0 -1
- package/dist/shell/assets/shared-react-jsx-runtime-Csr2Kx2w.js +0 -1
- package/dist/shell-source-maps/assets/app-D1iOLNRp.js.map +0 -1
- package/dist/shell-source-maps/assets/calls-CMM47K7J.js.map +0 -1
- package/dist/shell-source-maps/assets/cn-Bi0ZEjD9.js.map +0 -1
- package/dist/shell-source-maps/assets/export-worker-BKuC4P2E.js.map +0 -1
- package/dist/shell-source-maps/assets/index-DYuB1IqS.js.map +0 -1
- package/dist/shell-source-maps/assets/maplibre-lc2A-_P4.js.map +0 -1
- package/dist/shell-source-maps/assets/parse-worker-BzLD2jKf.js.map +0 -1
- package/dist/shell-source-maps/assets/preload-helper-DedkISGJ.js.map +0 -1
- package/dist/shell-source-maps/assets/prod-YZ9ZMG1O.js.map +0 -1
- package/dist/shell-source-maps/assets/react-CR5VJ85Q.js.map +0 -1
- package/dist/shell-source-maps/assets/record-map-CupIwJyD.js.map +0 -1
- package/dist/shell-source-maps/assets/records-map-Cs38aEuP.js.map +0 -1
- package/dist/shell-source-maps/assets/shared-protobase-ui-CMNP9cBW.js.map +0 -1
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/markdown-content-L1MZShpP.js","assets/rolldown-runtime-DXfiGoCU.js","assets/react-CqoBMk9d.js","assets/cn-B1sdg8aY.js","assets/records-map-B1PDo3PS.js","assets/maplibre-DfXLXH-O.js","assets/preload-helper-Ru-oozfe.js","assets/vendor-qs9zUu9T.js","assets/maplibre-DBE96hFo.css","assets/record-map-Cocva8wo.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{r as e}from"./rolldown-runtime-DXfiGoCU.js";import{i as t,r as n,t as r}from"./react-CqoBMk9d.js";import{$ as i,A as a,B as o,C as s,D as c,E as l,F as u,G as d,H as f,I as p,J as m,K as h,L as g,M as _,N as v,O as y,P as b,Q as x,R as S,S as C,T as w,U as T,V as E,W as D,X as O,Y as k,Z as A,_ as j,a as ee,at as te,b as ne,c as re,ct as ie,d as ae,et as oe,f as se,g as ce,h as le,i as ue,it as de,j as fe,k as pe,l as me,lt as he,m as ge,n as _e,nt as ve,o as ye,ot as be,p as xe,q as Se,r as Ce,rt as we,s as Te,st as Ee,t as De,u as Oe,v as ke,w as Ae,x as je,y as Me,z as Ne}from"./vendor-qs9zUu9T.js";import{a as M,d as Pe,f as Fe,i as Ie,l as Le,n as Re,o as N,r as ze,s as Be,t as Ve,u as He}from"./preload-helper-Ru-oozfe.js";import{t as P}from"./cn-B1sdg8aY.js";var Ue=(e,t,n,r)=>({code:e,message:t,hint:n,span:r}),We=(e,t)=>{let n=Array.from({length:t.length+1},(e,t)=>t);for(let r=1;r<=e.length;r++){let i=[r];for(let a=1;a<=t.length;a++){let o=e[r-1]===t[a-1]?0:1;i[a]=Math.min(n[a]+1,i[a-1]+1,n[a-1]+o)}n=i}return n[t.length]},Ge=(e,t)=>{let n=e.toLowerCase(),r=t.map(e=>({candidate:e,score:We(n,e.toLowerCase())})).sort((e,t)=>e.score-t.score)[0];return r&&r.score<=Math.max(2,Math.floor(e.length/3))?r.candidate:void 0},Ke={in:{params:[{name:`field`,type:`field`}],rest:{name:`value`,type:`any`}},search:{params:[{name:`text`,type:`string`}]},similar:{params:[{name:`field`,type:`field`,of:[`string`]},{name:`text`,type:`string`}]},regex:{params:[{name:`field`,type:`field`,of:[`string`]},{name:`pattern`,type:`string`}]},isNull:{params:[{name:`field`,type:`field`}]},now:{params:[],returns:`timestamp`}},qe={extensions:{arithmetic:`now-offset`,durationUnits:!0}},Je=e=>{switch(e.type){case`text`:return`string`;case`integer`:case`bigint`:return`integer`;case`boolean`:case`timestamp`:case`enum`:return e.type;default:return`any`}},Ye=e=>({fields:Object.fromEntries(Object.values(e.fields).map(e=>[e.name,{type:Je(e),filterable:e.filterable,sortable:e.sortable,aliases:e.aliases,...e.enumValues&&{values:e.enumValues}}])),functions:Ke}),Xe=(e,t,n,r)=>{e.errors.push(Ue(`unsupported`,t,n,r))},Ze=(e,t)=>t.kind===`member`?{kind:`field`,path:t.path,span:t.span}:Xe(e,`Only fields can be compared`,`Put a field name on the left, for example total > 100`,t.span),Qe=(e,t)=>{switch(t.kind){case`member`:return{kind:`string`,value:t.path.join(`.`),span:t.span};case`call`:return t.name===`now`&&t.args.length===0?{kind:`now`,span:t.span}:Xe(e,`${t.name}() cannot be used as a value`,`Only now() is a value function`,t.span);case`binary`:{let n=t.left;return n.kind===`call`&&n.name===`now`&&n.args.length===0&&t.right.kind===`duration`?{kind:`now`,offset:{sign:t.op,duration:t.right},span:t.span}:Xe(e,`Arithmetic is only supported as now() +/- duration`,`Write now() - 30d`,t.span)}default:return t}},$e=(e,t)=>(`kind`in t&&[`member`,`call`,`binary`].includes(t.kind)?void 0:t)||(t.kind===`member`?{kind:`string`,value:t.path.join(`.`),span:t.span}:Xe(e,`Expected a literal value`,`Use strings, numbers, true/false, durations or timestamps`,t.span)),et=e=>{switch(e.kind){case`member`:return e.path.join(`.`);case`string`:case`timestamp`:return e.kind,e.value;case`number`:return e.raw;case`boolean`:return String(e.value);case`duration`:return`${e.amount}${e.unit}`;default:return``}},tt=(e,t)=>{let[n,r,...i]=t.args,a=n?.kind===`member`?Ze(e,n):void 0,o=e=>e?.kind===`string`?e.value:void 0,s=n=>{e.errors.push(Ue(`invalid-arguments`,`Invalid arguments to ${t.name}()`,`Usage: ${n}`,t.span))};switch(t.name){case`in`:{let n=t.args.slice(1).map(t=>$e(e,t));return!a||n.length===0?s(`in(field, value1, value2, ...)`):n.every(e=>e)?{kind:`in`,field:a,values:n,span:t.span}:void 0}case`search`:return o(n)!==void 0&&!r?{kind:`search`,text:o(n),span:t.span}:s(`search("text")`);case`similar`:return a&&o(r)!==void 0&&i.length===0?{kind:`similar`,field:a,text:o(r),span:t.span}:s(`similar(field, "text")`);case`regex`:return a&&o(r)!==void 0&&i.length===0?{kind:`regex`,field:a,pattern:o(r),span:t.span}:s(`regex(field, "pattern")`);case`isNull`:return a&&!r?{kind:`isNull`,field:a,span:t.span}:s(`isNull(field)`);default:e.errors.push(Ue(`unknown-function`,`Unknown function "${t.name}"`,`Available functions: ${Object.keys(Ke).join(`, `)}`,t.span));return}},nt=e=>e.every(e=>e)?e:void 0,rt=(e,t)=>{switch(t.kind){case`sequence`:case`and`:case`or`:{let n=nt(t.args.map(t=>rt(e,t)));return n&&{kind:t.kind===`or`?`or`:`and`,args:n,span:t.span}}case`not`:{let n=rt(e,t.arg);return n&&{kind:`not`,arg:n,span:t.span}}case`compare`:{let n=Ze(e,t.left),r=Qe(e,t.right);return n&&r&&{kind:`compare`,op:t.op,field:n,value:r,span:t.span}}case`has`:{let n=Ze(e,t.left),r=$e(e,t.right);return n&&r&&{kind:`has`,field:n,value:r,span:t.span}}case`present`:{let n=Ze(e,t.left);return n&&{kind:`present`,field:n,span:t.span}}case`global`:return{kind:`search`,text:et(t.value),span:t.span};case`call`:return tt(e,t)}},it=(e,t={})=>{let n=ie(e,{...qe,...t}),r={errors:[]},i=n.ast&&rt(r,n.ast),a=[...n.errors,...r.errors].sort((e,t)=>e.span.start-t.span.start);return a.length===0?{ok:!0,ast:i,errors:[]}:{ok:!1,ast:i,errors:a}},at=(e,t)=>t===2?e%4==0&&(e%100!=0||e%400==0)?29:28:[4,6,9,11].includes(t)?30:31,ot=e=>{let t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e);if(!t)return!1;let[n,r,i]=[Number(t[1]),Number(t[2]),Number(t[3])];return r>=1&&r<=12&&i>=1&&i<=at(n,r)},st=e=>{let t=/^(\d{4}-\d{2}-\d{2})[Tt](\d{2}):(\d{2}):(\d{2})(?:\.\d+)?(?:[Zz]|[+-](\d{2}):(\d{2}))$/.exec(e);if(!t)return!1;let[n,r,i]=[Number(t[2]),Number(t[3]),Number(t[4])],[a,o]=[Number(t[5]??0),Number(t[6]??0)];return ot(t[1])&&n<=23&&r<=59&&i<=59&&a<=23&&o<=59},ct=(e,t)=>({message:e,hint:t}),lt=-(2n**63n),ut=2n**63n-1n,dt=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,ft=e=>e.kind===`number`?e.raw:e.kind===`string`?e.value:void 0,pt=(e,t=`Write ${e} values like the examples in the docs`)=>ct(`Expected ${e}`,t),mt=e=>{let t=ft(e),n=t===void 0?NaN:Number(t);if(t===void 0||t.trim()===``||!Number.isSafeInteger(n))return pt(`a whole number`,`Use an integer such as 42, or a bigint field for larger values`)},ht=e=>{let t=ft(e);if(t===void 0||!/^-?\d+$/.test(t)||BigInt(t)<lt||BigInt(t)>ut)return pt(`a 64-bit integer`,`Use plain digits such as 9007199254740993 (no exponent or fraction)`)},gt=e=>{let t=ft(e);if(t===void 0||!/^-?\d+(\.\d+)?$/.test(t))return pt(`a decimal number`,`Use plain digits such as 100.50, or quote it: "100.50" (no exponent)`)},_t=(e,t)=>{if(t.kind===`now`)return e.type===`date`||e.type===`timestamp`?void 0:ct(`now() only works with date and timestamp fields`,`Field "${e.name}" is ${e.type}`);switch(e.type){case`text`:return t.kind===`string`?void 0:pt(`a quoted string`,`Wrap the text in double quotes`);case`integer`:return mt(t);case`bigint`:return ht(t);case`decimal`:return gt(t);case`boolean`:return t.kind===`boolean`?void 0:pt(`true or false`);case`date`:return t.kind===`string`&&ot(t.value)?void 0:pt(`a date`,`Quote a calendar date: "2012-04-21"`);case`timestamp`:return t.kind===`timestamp`||t.kind===`string`&&st(t.value)?void 0:pt(`an RFC-3339 timestamp`,`Use 2012-04-21T11:30:00Z, or now() - 7d`);case`uuid`:return t.kind===`string`&&dt.test(t.value)?void 0:pt(`a uuid`,`Quote a uuid like "0b5a4f0e-6f2a-4a3c-9d4e-1f2a3b4c5d6e"`);case`enum`:return t.kind===`string`&&e.enumValues?.includes(t.value)?void 0:ct(`Invalid enum value`,`Allowed values: ${(e.enumValues??[]).join(`, `)}`);case`currency`:return t.kind===`string`&&/^[A-Z]{3}$/.test(t.value)?void 0:pt(`an ISO 4217 currency code`,`Use three capital letters, for example "EUR"`);case`country`:return t.kind===`string`&&/^[A-Z]{2}$/.test(t.value)?void 0:pt(`an ISO 3166-1 country code`,`Use two capital letters, for example "NL"`);case`relation`:return t.kind===`string`||t.kind===`number`&&Number.isSafeInteger(t.value)?void 0:pt(`a record key`,`Use the related record key: 42 or "abc"`);case`json`:case`file`:return ct(`${e.type} fields cannot be compared`,`Use field:value on json fields, or isNull(field)`)}},vt=(e,t)=>Object.hasOwn(e.fields,t)?e.fields[t]:Object.values(e.fields).find(e=>e.aliases.includes(t)),yt=(e,t,n)=>{if(t.path.length>1){e.errors.push(Ue(`unsupported-traversal`,`Traversal into "${t.path.join(`.`)}" is not supported yet`,`Filter on fields of this resource only`,t.span));return}let r=t.path[0],i=vt(e.model,r);if(!i){let i=Object.values(e.model.fields).filter(e=>e[n]).map(e=>e.name),a=Ge(r,i);e.errors.push(Ue(`unknown-field`,`Unknown field "${r}"`,a?`Did you mean "${a}"?`:`Available fields: ${i.join(`, `)}`,t.span));return}if(!i[n]){let r=n===`filterable`?`filterable`:`sortable`;e.errors.push(Ue(n===`filterable`?`not-filterable`:`not-sortable`,`Field "${i.name}" is not ${r}`,`Mark it with .${r}() in data.ts`,t.span));return}return i},bt=[`=`,`!=`],xt=[`=`,`!=`,`<`,`<=`,`>`,`>=`],St=e=>{switch(e){case`text`:case`integer`:case`bigint`:case`decimal`:case`date`:case`timestamp`:return xt;case`json`:case`file`:return[];default:return bt}},Ct=e=>e===`json`||e===`file`,wt=(e,t,n)=>{let r=_t(t,n);return r&&e.errors.push(Ue(`invalid-value`,r.message,r.hint,n.span)),!r},Tt=(e,t,n,r)=>{e.errors.push(Ue(`operator-not-allowed`,t,n,r))},Et=(e,t)=>(e===`=`||e===`!=`)&&t.kind===`string`&&t.value.includes(`*`),Dt=(e,t)=>{let n=yt(e,t.field,`filterable`);if(!n)return;let r=St(n.type);if(!r.includes(t.op)){Tt(e,`Operator "${t.op}" is not supported for ${n.type} fields`,r.length?`Supported: ${r.join(` `)}`:`Use field:value on json fields, or isNull(field)`,t.span);return}if(Et(t.op,t.value)&&n.type!==`text`){e.errors.push(Ue(`wildcard-not-allowed`,`Wildcards are only supported on text fields, not ${n.type}`,`Remove the "*" or filter a text field`,t.value.span));return}if(Et(t.op,t.value)||wt(e,n,t.value))return{...t,field:n}},Ot=(e,t)=>{let n=yt(e,t.field,`filterable`);if(n){if(n.type!==`json`){Tt(e,`":" is only supported on json fields, not ${n.type}`,`Use = on ${n.type} fields, or field:* to test for a value`,t.span);return}return{...t,field:n}}},kt=(e,t)=>{let n=yt(e,t.field,`filterable`);if(n){if(Ct(n.type)){Tt(e,`in() is not supported for ${n.type} fields`,`Use field:value on json fields`,t.span);return}return t.values.map(t=>wt(e,n,t)).every(Boolean)?{...t,field:n}:void 0}},At=(e,t,n)=>{let r=yt(e,n,`filterable`);if(r&&r.type!==`text`){Tt(e,`${t}() only works on text fields, not ${r.type}`,`Field "${r.name}" is ${r.type}`,n.span);return}return r},jt=(e,t)=>{switch(t.kind){case`and`:case`or`:{let n=t.args.map(t=>jt(e,t));return n.every(e=>e)?{...t,args:n}:void 0}case`not`:{let n=jt(e,t.arg);return n&&{...t,arg:n}}case`compare`:return Dt(e,t);case`has`:return Ot(e,t);case`in`:return kt(e,t);case`search`:if(e.model.search?.length)return t;e.errors.push(Ue(`no-search-fields`,`This resource has no search fields`,`Declare them with .search((r) => [r.title]) in data.ts`,t.span));return;case`present`:case`isNull`:{let n=yt(e,t.field,`filterable`);return n&&{...t,field:n}}case`similar`:case`regex`:{let n=At(e,t.kind,t.field);return n&&{...t,field:n}}}},Mt=(e,t)=>{let n={model:e,errors:[]},r=jt(n,t);return!r||n.errors.length>0?{ok:!1,errors:[...n.errors].sort((e,t)=>e.span.start-t.span.start)}:{ok:!0,filter:r}},Nt=(e,t)=>`path`in e?{kind:`member`,path:e.path,span:e.span}:{kind:`member`,path:[e.name],field:{name:e.name,spec:{type:Je(e)}},span:t},Pt=(e,t,n)=>({kind:`call`,name:e,args:t,span:n}),Ft=(e,t)=>({kind:`string`,value:e,span:t}),It=e=>{if(e.kind!==`now`)return e;let t={kind:`call`,name:`now`,args:[],span:e.span};return e.offset?{kind:`binary`,op:e.offset.sign,left:t,right:e.offset.duration,span:e.span}:t},Lt=(e,t={})=>{let n=e=>Lt(e,t);switch(e.kind){case`and`:case`or`:return{kind:e.kind,args:e.args.map(n),span:e.span};case`not`:return{kind:`not`,arg:n(e.arg),span:e.span};case`compare`:return{kind:`compare`,op:e.op,left:Nt(e.field,e.span),right:It(e.value),span:e.span};case`has`:return{kind:`has`,left:Nt(e.field,e.span),right:e.value,span:e.span};case`present`:return{kind:`present`,left:Nt(e.field,e.span),span:e.span};case`in`:return t.expand?{kind:`or`,args:e.values.map(t=>({kind:`compare`,op:`=`,left:Nt(e.field,e.span),right:t,span:e.span})),span:e.span}:Pt(`in`,[Nt(e.field,e.span),...e.values],e.span);case`search`:return Pt(`search`,[Ft(e.text,e.span)],e.span);case`similar`:return Pt(`similar`,[Nt(e.field,e.span),Ft(e.text,e.span)],e.span);case`regex`:return Pt(`regex`,[Nt(e.field,e.span),Ft(e.pattern,e.span)],e.span);case`isNull`:return t.expand?{kind:`not`,arg:{kind:`present`,left:Nt(e.field,e.span),span:e.span},span:e.span}:Pt(`isNull`,[Nt(e.field,e.span)],e.span)}},Rt=(e,t)=>{let n=Mt(e,t);if(!n.ok&&n.errors.some(e=>e.code===`unsupported-traversal`))return n;let r=be(Lt(t),Ye(e));return r.ok?Mt(e,t):{ok:!1,errors:r.errors}},zt=/^[\d\s+\-().\/]+$/,Bt=e=>zt.test(e)?e.replace(/\D/g,``):``,Vt=e=>{let t=e.split(/\s+/).filter(Boolean).map(e=>({text:e,digits:Bt(e),whole:!1})),n=t.length>1?Bt(e.trim()):``;return n?[{text:e.trim(),digits:n,whole:!0},...t]:t},Ht=(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()),Ut=(e,t,n)=>(e.search??[]).filter(r=>Ht(t[r],n,e.searchMatch?.[r])),Wt=(e,t,n)=>{let r=Vt(n),i=r.filter(e=>!e.whole),a=r.find(e=>e.whole);return a&&Ut(e,t,a).length>0?!0:i.length>0&&i.every(n=>Ut(e,t,n).length>0)},Gt=(e,t,n,r)=>{for(let i of Vt(n)){let n=Ut(e,t,i);if(n.length>0&&!n.some(e=>r.includes(e)))return n[0]}},Kt=e=>()=>{throw Error(`Not implemented: ${e}() needs the database (the resource's search fields, trigram matching), so it cannot be evaluated against a record`)},qt=(e,t,n)=>({...Ke,search:{...Ke.search,evaluate:n?e=>Wt(n,t,e):Kt(`search`)},similar:{...Ke.similar,evaluate:Kt(`similar`)},regex:{...Ke.regex,evaluate:(e,t)=>e.some(e=>typeof e==`string`&&new RegExp(t).test(e))},now:{...Ke.now,evaluate:e}}),Jt=(e,t,n={})=>Ee(Lt(e,{expand:!0}),t,{functions:qt(n.now??(()=>new Date),t,n.search)}),Yt=e=>he(Lt(e)),Xt=e=>e.map(e=>({path:e.path.path,direction:e.direction,span:e.span})),Zt=e=>e.replace(/([^\s,])(\s+)(asc|desc)(?=\s|,|$)/gi,(e,t,n,r)=>`${t}${n}${r.toLowerCase()}`),Qt=e=>{let t=te(Zt(e)),n=t.items.map(e=>({path:{kind:`field`,path:e.path,span:e.span},direction:e.direction,span:e.span}));return t.ok?{ok:!0,items:n,errors:[]}:{ok:!1,items:n,errors:t.errors}},$t=(e,t)=>{let n=t.filter(e=>e.path.path.length>1).map(e=>Ue(`unsupported-traversal`,`Traversal into "${e.path.path.join(`.`)}" is not supported yet`,`Sort on fields of this resource only`,e.path.span));if(n.length>0)return{ok:!1,errors:n};let r=de(Xt(t),Ye(e));return r.ok?{ok:!0,sort:r.items.map(e=>[e.path[0],e.direction])}:{ok:!1,errors:r.errors}},en=e=>{let t=/^(\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)([smhdw])$/.exec(e);if(!t)throw Error(`Invalid duration "${e}", expected for example 30d or 1.5h`);return{kind:`duration`,amount:Number(t[1]),unit:t[2],span:{start:0,end:0}}},tn={start:0,end:0},nn=e=>({kind:`field`,path:e.split(`.`),span:tn}),rn=e=>{if(typeof e==`string`)return{kind:`string`,value:e,span:tn};if(typeof e==`boolean`)return{kind:`boolean`,value:e,span:tn};if(!Number.isFinite(e))throw Error(`Filter numbers must be finite`);return{kind:`number`,value:e,raw:String(e),span:tn}},an=e=>typeof e==`object`?e:rn(e),on=(e,t)=>{if(t.length===0)throw Error(`where.${e} needs at least one filter`);return t.length===1?t[0]:{kind:e,args:t,span:tn}},sn=()=>{let e=e=>(t,n)=>({kind:`compare`,op:e,field:nn(t),value:an(n),span:tn}),t=e=>t=>({kind:`now`,offset:{sign:e,duration:en(t)},span:tn});return{eq:e(`=`),ne:e(`!=`),lt:e(`<`),lte:e(`<=`),gt:e(`>`),gte:e(`>=`),between:(t,n,r)=>on(`and`,[e(`>=`)(t,n),e(`<=`)(t,r)]),has:(e,t)=>({kind:`has`,field:nn(e),value:rn(t),span:tn}),present:e=>({kind:`present`,field:nn(e),span:tn}),in:(e,t)=>({kind:`in`,field:nn(e),values:t.map(rn),span:tn}),isNull:e=>({kind:`isNull`,field:nn(e),span:tn}),search:e=>({kind:`search`,text:e,span:tn}),similar:(e,t)=>({kind:`similar`,field:nn(e),text:t,span:tn}),regex:(e,t)=>({kind:`regex`,field:nn(e),pattern:t,span:tn}),and:(...e)=>on(`and`,e),or:(...e)=>on(`or`,e),not:e=>({kind:`not`,arg:e,span:tn}),now:()=>({kind:`now`,span:tn}),ago:t(`-`),fromNow:t(`+`)}},cn=sn(),ln=/\{([A-Za-z_][A-Za-z0-9_]*)\}/g,un=e=>[...e.matchAll(ln)].map(e=>e[1]),dn=e=>e.kind===`record`?(Array.isArray(e.key)?e.key:[e.key]).filter(e=>typeof e==`string`):e.kind===`list`?[e.filter,e.orderBy].filter(e=>e!==void 0):e.kind===`create`?Object.values(e.values??{}):[],fn=e=>[...new Set(dn(e).flatMap(un))],pn=(e,t)=>e.replace(ln,(e,n)=>t[n]===null||t[n]===void 0?``:String(t[n])),mn=(e,t={})=>{if(e.kind===`record`){let n=e=>typeof e==`string`?pn(e,t):e;return{...e,key:Array.isArray(e.key)?e.key.map(n):n(e.key)}}return e.kind===`create`?e.values?{...e,values:Object.fromEntries(Object.entries(e.values).map(([e,n])=>[e,pn(n,t)]))}:e:e.kind===`list`?{...e,...e.filter!==void 0&&{filter:pn(e.filter,t)},...e.orderBy!==void 0&&{orderBy:pn(e.orderBy,t)}}:e},hn=e=>/^\{([A-Za-z_][A-Za-z0-9_]*)\}$/.exec(e)?.[1],gn=e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&Object.keys(e).length===1&&typeof e.$field==`string`,_n=e=>typeof e==`object`&&!!e&&!Array.isArray(e),vn=e=>gn(e)?e.$field:Array.isArray(e)?e.map(vn):_n(e)?Object.fromEntries(Object.entries(e).map(([e,t])=>[e,vn(t)])):e,yn=`table`,bn=/^[a-z0-9][a-z0-9_-]*$/,xn=e=>{if(!e.startsWith(`/-/forms/`))return;let t=e.slice(9);return bn.test(t)?{name:t}:void 0},Sn=e=>e.flatMap(e=>e.kind===`group`||e.kind===`tab`?Sn(e.items):[e]),Cn=(e,t)=>{if(t===void 0)return e;let n=e?.lists?.find(e=>e.name===t);if(!e||!n)return;let{list:r,chart:i,help:a,nav:o,lists:s,names:c,...l}=e,{name:u,...d}=n;return{...l,...d}},wn={text:`text`,integer:`integer`,decimal:`decimal`,boolean:`boolean`,date:`date`,choice:`text`,custom:`json`},Tn=e=>({name:e.name,column:e.name,type:e.options?`enum`:wn[e.kind],nullable:!0,readOnly:!1,filterable:e.kind!==`custom`,sortable:!1,aliases:[],...e.options&&{enumValues:e.options.map(e=>e.value)}}),En=e=>({name:`inputs`,table:{name:`inputs`},fields:Object.fromEntries(e.map(e=>[e.name,Tn(e)])),primaryKey:[]}),Dn=(e,t)=>{let n=e[t].when;if(n===void 0)return;let r=it(n);if(!r.ok)return r.errors.map(e=>e.message).join(`; `);if(!r.ast)return`it is empty`;let i=Rt(En(e.slice(0,t)),r.ast);return i.ok?i.filter:i.errors.map(e=>e.message).join(`; `)},On=(e,t)=>{let n=new Set,r={};return e.forEach((i,a)=>{let o=Dn(e,a);if(typeof o==`string`)throw Error(`Input "${i.name}": ${o}`);let s=o===void 0||Jt(o,r)===!0;s&&n.add(i.name),r[i.name]=s?t[i.name]??null:null}),n},kn=(e,t)=>Object.fromEntries(Object.entries(e).flatMap(([e,n])=>{let r=typeof n==`string`?hn(n):void 0;return r===void 0?[[e,n]]:Object.hasOwn(t,r)?[[e,t[r]]]:[]})),An=e=>`groupBy`in e,jn=[`neutral`,`blue`,`green`,`amber`,`red`,`violet`],Mn=e=>jn.includes(e),Nn=e=>{if(!Array.isArray(e))return String(e);let t=e;return t.length===1?String(t[0]):t.map(e=>encodeURIComponent(String(e))).join(`,`)},Pn=e(we(),1),Fn=e=>{try{return new Pn.default.Comparator(e),!0}catch(e){if(e instanceof TypeError)return!1;throw e}},In=(e,t)=>{let n=t.trim().split(/\s+/);if(Pn.default.valid(e)!==null&&t.trim()!==``&&n.every(Fn))return Pn.default.satisfies(e,t)},Ln=(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=In(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}`},Rn=`[Filtered]`,zn=/authorization|cookie|passw|secret|token|api[-_]?key|credential|session|csrf|signature|^sig$/i,Bn=new Set([`url`,`query_string`,`from`,`to`]),Vn=12,Hn=e=>e.replace(/(^|&)([^=&]*)=([^&]*)/g,(e,t,n)=>zn.test(n)?`${t}${n}=${Rn}`:e),Un=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)}${Hn(r)}${n===-1?``:e.slice(n)}`},Wn=(e,t,n)=>zn.test(e)?Rn:typeof t==`string`&&Bn.has(e)?e===`query_string`?Hn(t):Un(t):Gn(t,n+1),Gn=(e,t)=>t>Vn||typeof e!=`object`||!e?e:Array.isArray(e)?e.map(e=>Array.isArray(e)&&e.length===2&&typeof e[0]==`string`?[e[0],Wn(e[0],e[1],t)]:Gn(e,t+1)):Object.fromEntries(Object.entries(e).map(([e,n])=>[e,Wn(e,n,t)])),Kn=e=>Gn(e,0),qn=`protobase-app`,Jn=[`unknown-field`,`not-filterable`,`not-sortable`,`unsupported-traversal`,`invalid-traversal`],Yn=e=>e.replace(/(["']?)\{[A-Za-z_][A-Za-z0-9_]*\}\1/g,(e,t)=>t?`${t}x${t}`:`0`),Xn=(e,t)=>{let n=it(Yn(t));if(!n.ok)return n.errors.map(e=>`filter: ${e.message}`);if(!n.ast)return[];let r=Rt(e,n.ast);return r.ok?[]:r.errors.filter(e=>Jn.includes(e.code)).map(e=>`filter: ${e.message}`)},Zn=(e,t)=>{if(fn({kind:`list`,resource:e.name,orderBy:t}).length>0)return[];let n=Qt(t);if(!n.ok)return n.errors.map(e=>`orderBy: ${e.message}`);let r=$t(e,n.items);return r.ok?[]:r.errors.map(e=>`orderBy: ${e.message}`)},Qn=(e,{models:t,pages:n,source:r,createPages:i})=>{let a=fn(e).flatMap(e=>r?Object.hasOwn(r.fields,e)?[]:[`"{${e}}" is not a field of ${r.name}`]:[`"{${e}}" takes a value from the record, but the link sits on none`]);switch(e.kind){case`page`:return n&&!n.has(e.page)?[`unknown page "${e.page}"`]:[];case`list`:case`record`:case`create`:{let n=Object.hasOwn(t,e.resource)?t[e.resource]:void 0;return n?e.kind===`create`&&i?.has(e.resource)?a:e.kind===`create`?[...a,...Object.keys(e.values??{}).filter(e=>!Object.hasOwn(n.fields,e)).map(t=>`values: unknown field "${t}" on ${e.resource}`)]:e.kind===`list`?[...a,...e.filter?Xn(n,e.filter):[],...e.orderBy?Zn(n,e.orderBy):[]]:a:[`unknown resource "${e.resource}"`]}default:return[`an address's kind is list, record, create or page, not "${String(e.kind)}"`]}},$n={messages:[],replying:!1},er=(e,t)=>{let n=e.findIndex(e=>e.id===t.id);return n===-1?[...e,t]:e.map((e,r)=>r===n?t:e)},tr=(e,t,n)=>{let r=e.find(e=>e.id===t);return er(e,r?{...r,parts:er(r.parts,n)}:{id:t,from:`assistant`,parts:[n]})},nr=(e,t)=>{switch(t.type){case`state`:return t.state;case`message`:return{...e,messages:er(e.messages,t.message)};case`part`:return{...e,messages:tr(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}}}}},rr=async(e,t,n)=>{let r=ve({onEvent:e=>t(e.data)}),i=new TextDecoder,a=e.getReader();for(n?.addEventListener(`abort`,()=>void a.cancel(),{once:!0});;){let{done:e,value:t}=await a.read();if(e)break;r.feed(i.decode(t,{stream:!0}))}r.feed(`${i.decode()}\n\n`)},ir=e=>e.charAt(0).toUpperCase()+e.slice(1),F=e=>ir(e.replace(/(Id|Code|_id|_code)$/,``).replace(/([a-z0-9])([A-Z])/g,`$1 $2`).replace(/_+/g,` `).trim().toLowerCase()||e),ar=(e,t)=>t?.[e]??e,or=[`name`,`title`,`number`,`sku`,`email`,`code`,`description`],sr=e=>e?.type===`text`&&!e.sensitive,cr=(e,t)=>t?.title??or.find(t=>sr(e.fields[t]))??Object.values(e.fields).find(sr)?.name??e.primaryKey[0],lr=(e,t)=>t?.title??t?.list?.columns.find(t=>e.fields[t]?.type===`text`)??cr(e),ur=(e,t,n,r)=>{let i=lr(e,t),a=n[i];return a==null?r:e.fields[i]?.type===`enum`?ar(String(a),t?.fields[i]?.valueLabels):String(a)},dr={fingerprint:`fingerprint`,shellVersion:`shell_version`},fr=`/api/mobile/release`,pr=`/api/mobile/releases`,mr=({fingerprint:e,shellVersion:t})=>new URLSearchParams({[dr.fingerprint]:e,[dr.shellVersion]:t}).toString(),hr=`/api/auth`,gr={ios:`capacitor://localhost`,android:`https://localhost`},_r={database:`protobase-push`,store:`registration`,key:`current`},vr=`protobase.sw.js`,yr=(e,t)=>`${e}/notifications/devices${t===void 0?``:`/${encodeURIComponent(t)}`}`,br=/^[A-Za-z0-9_-]{1,64}$/,xr=(e,t)=>{let n=`${e}/notifications/history`;if(t===void 0)return n;if(typeof t==`string`)return`${n}/${t}`;if(!br.test(t.read))throw Error(`A history entry id is letters, digits, "_" and "-" only`);return`${n}/${t.read}/read`},Sr=(e,t)=>`${e}/status${t===void 0?``:`/${t}`}`,Cr=/\p{Cc}/u,wr=e=>{if(Cr.test(e))return`A status is one line of text, without control characters`;if([...e].length>100)return`A status is at most 100 characters`},Tr=(e,t=Date.now())=>{if(e&&!(e.clearsAt!==null&&Date.parse(e.clearsAt)<=t)&&(e.availability!==`automatic`||e.text!==null))return e},Er=(e,t)=>t?.list?.columns??Object.values(e.fields).filter(e=>!e.writeOnly).slice(0,6).map(e=>e.name),Dr={members:[`json`]},Or=(e,t)=>`${e}/calls/guests${t?`/${t}`:``}`,kr=`decline`,Ar=(e,t)=>{let n=`${e}/calls/rings`;return t===void 0?n:`${n}/${encodeURIComponent(t.decline)}/${kr}`},jr=`calls`,Mr={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`}]]};Mr.node;var Nr=N(Mr),Pr={name:`arrow-down`,size:24,node:[[`path`,{d:`M12 5v14`,key:`s699le`}],[`path`,{d:`m19 12-7 7-7-7`,key:`1idqje`}]]};Pr.node;var Fr=N(Pr),Ir={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`}]]};Ir.node;var Lr=N(Ir),Rr={name:`arrow-right`,size:24,node:[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`m12 5 7 7-7 7`,key:`xquz4c`}]]};Rr.node;var zr=N(Rr),Br={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`}]]};Br.node;var Vr=N(Br),Hr={name:`arrow-up-right`,size:24,node:[[`path`,{d:`M7 7h10v10`,key:`1tivn9`}],[`path`,{d:`M7 17 17 7`,key:`1vkiza`}]]};Hr.node;var Ur=N(Hr),Wr={name:`arrow-up`,size:24,node:[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]};Wr.node;var Gr=N(Wr),Kr={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`}]]};Kr.node;var qr=N(Kr),Jr={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`}]]};Jr.node;var Yr=N(Jr),Xr={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`}]]};Xr.node;var Zr=N(Xr),Qr={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`}]]};Qr.node;var $r=N(Qr),ei={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`}]]};ei.node;var ti=N(ei),ni={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`}]]};ni.node;var ri=N(ni),ii={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`}]]};ii.node;var ai=N(ii),oi={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`}]]};oi.node;var si=N(oi),ci={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`}]]};ci.node;var li=N(ci),ui={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`}]]};ui.node;var di=N(ui),fi={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`}]]};fi.node;var pi=N(fi),mi={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`]};mi.node;var hi=N(mi),gi={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`}]]};gi.node;var _i=N(gi),vi={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`}]]};vi.node;var yi=N(vi),bi={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`}]]};bi.node;var xi=N(bi),Si={name:`check`,size:24,node:[[`path`,{d:`M20 6 9 17l-5-5`,key:`1gmf2c`}]]};Si.node;var Ci=N(Si),wi={name:`chevron-down`,size:24,node:[[`path`,{d:`m6 9 6 6 6-6`,key:`qrunsl`}]]};wi.node;var Ti=N(wi),Ei={name:`chevron-left`,size:24,node:[[`path`,{d:`m15 18-6-6 6-6`,key:`1wnfg3`}]]};Ei.node;var Di=N(Ei),Oi={name:`chevron-right`,size:24,node:[[`path`,{d:`m9 18 6-6-6-6`,key:`mthhwq`}]]};Oi.node;var ki=N(Oi),Ai={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`}]]};Ai.node;var ji=N(Ai),Mi={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`]};Mi.node;var Ni=N(Mi),Pi={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`]};Pi.node;var Fi=N(Pi),Ii={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`}]]};Ii.node;var Li=N(Ii),Ri={name:`circle-minus`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M8 12h8`,key:`1wcyev`}]],aliases:[`minus-circle`]};Ri.node;var zi=N(Ri),Bi={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`]};Bi.node;var Vi=N(Bi),Hi={name:`circle`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]};Hi.node;var Ui=N(Hi),Wi={name:`clock`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 6v6l4 2`,key:`mmk7yg`}]]};Wi.node;var Gi=N(Wi),Ki={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`]};Ki.node;var qi=N(Ki),Ji={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`}]]};Ji.node;var Yi=N(Ji),Xi={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`}]]};Xi.node;var Zi=N(Xi),Qi={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`}]]};Qi.node;var $i=N(Qi),ea={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`}]]};ea.node;var ta=N(ea),na={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`}]]};na.node;var ra=N(na),ia={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`]};ia.node;var aa=N(ia),oa={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`]};oa.node;var sa=N(oa),ca={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`]};ca.node;var la=N(ca),ua={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`}]]};ua.node;var da=N(ua),fa={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`}]]};fa.node;var pa=N(fa),ma={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`}]]};ma.node;var ha=N(ma),ga={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`]};ga.node;var _a=N(ga),va={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`]};va.node;var ya=N(va),ba={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`}]]};ba.node;var xa=N(ba),Sa={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`}]]};Sa.node;var Ca=N(Sa),wa={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`}]]};wa.node;var Ta=N(wa),Ea={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`}]]};Ea.node;var Da=N(Ea),Oa={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`}]]};Oa.node;var ka=N(Oa),Aa={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`]};Aa.node;var ja=N(Aa),Ma={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`}]]};Ma.node;var Na=N(Ma),Pa={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`}]]};Pa.node;var Fa=N(Pa),Ia={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`}]]};Ia.node;var La=N(Ia),Ra={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`}]]};Ra.node;var za=N(Ra),Ba={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`}]]};Ba.node;var Va=N(Ba),Ha={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`}]]};Ha.node;var Ua=N(Ha),Wa={name:`layout-grid`,size:24,node:[[`rect`,{width:`7`,height:`7`,x:`3`,y:`3`,rx:`1`,key:`1g98yp`}],[`rect`,{width:`7`,height:`7`,x:`14`,y:`3`,rx:`1`,key:`6d4xhi`}],[`rect`,{width:`7`,height:`7`,x:`14`,y:`14`,rx:`1`,key:`nxv5o0`}],[`rect`,{width:`7`,height:`7`,x:`3`,y:`14`,rx:`1`,key:`1bb6yr`}]]};Wa.node;var Ga=N(Wa),Ka={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`}]]};Ka.node;var qa=N(Ka),Ja={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`}]]};Ja.node;var Ya=N(Ja),Xa={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`}]]};Xa.node;var Za=N(Xa),Qa={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`}]]};Qa.node;var $a=N(Qa),eo={name:`loader-circle`,size:24,node:[[`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`,key:`13zald`}]],aliases:[`loader-2`]};eo.node;var to=N(eo),no={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`}]]};no.node;var ro=N(no),io={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`}]]};io.node;var ao=N(io),oo={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`}]]};oo.node;var so=N(oo),co={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`}]]};co.node;var lo=N(co),uo={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`}]]};uo.node;var fo=N(uo),po={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`}]]};po.node;var mo=N(po),ho={name:`menu`,size:24,node:[[`path`,{d:`M4 5h16`,key:`1tepv9`}],[`path`,{d:`M4 12h16`,key:`1lakjw`}],[`path`,{d:`M4 19h16`,key:`1djgab`}]]};ho.node;var go=N(ho),_o={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`}]]};_o.node;var vo=N(_o),yo={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`}]]};yo.node;var bo=N(yo),xo={name:`minus`,size:24,node:[[`path`,{d:`M5 12h14`,key:`1ays0h`}]]};xo.node;var So=N(xo),Co={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`}]]};Co.node;var wo=N(Co),To={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`}]]};To.node;var Eo=N(To),Do={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`}]]};Do.node;var Oo=N(Do),ko={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`}]]};ko.node;var Ao=N(ko),jo={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`}]]};jo.node;var Mo=N(jo),No={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`}]]};No.node;var Po=N(No),Fo={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`}]]};Fo.node;var Io=N(Fo),Lo={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`}]]};Lo.node;var Ro=N(Lo),zo={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`}]]};zo.node;var Bo=N(zo),Vo={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`}]]};Vo.node;var Ho=N(Vo),Uo={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`}]]};Uo.node;var Wo=N(Uo),Go={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`}]]};Go.node;var Ko=N(Go),qo={name:`plus`,size:24,node:[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`M12 5v14`,key:`s699le`}]]};qo.node;var Jo=N(qo),Yo={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`}]]};Yo.node;var Xo=N(Yo),Zo={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`}]]};Zo.node;var Qo=N(Zo),$o={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`}]]};$o.node;var es=N($o),ts={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`}]]};ts.node;var ns=N(ts),rs={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`}]]};rs.node;var is=N(rs),as={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`}]]};as.node;var os=N(as),ss={name:`search`,size:24,node:[[`path`,{d:`m21 21-4.34-4.34`,key:`14j7rj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}]]};ss.node;var cs=N(ss),ls={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`]};ls.node;var us=N(ls),ds={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`}]]};ds.node;var fs=N(ds),ps={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`}]]};ps.node;var ms=N(ps),hs={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`}]]};hs.node;var gs=N(hs),_s={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`}]]};_s.node;var vs=N(_s),ys={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`}]]};ys.node;var bs=N(ys),xs={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`}]]};xs.node;var Ss=N(xs),Cs={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`}]]};Cs.node;var ws=N(Cs),Ts={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`}]]};Ts.node;var Es=N(Ts),Ds={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`]};Ds.node;var Os=N(Ds),ks={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`]};ks.node;var As=N(ks),js={name:`square`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]};js.node;var Ms=N(js),Ns={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`}]]};Ns.node;var Ps=N(Ns),Fs={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`}]]};Fs.node;var Is=N(Fs),Ls={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`}]]};Ls.node;var Rs=N(Ls),zs={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`}]]};zs.node;var Bs=N(zs),Vs={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`}]]};Vs.node;var Hs=N(Vs),Us={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`}]]};Us.node;var Ws=N(Us),Gs={name:`terminal`,size:24,node:[[`path`,{d:`M12 19h8`,key:`baeox8`}],[`path`,{d:`m4 17 6-6-6-6`,key:`1yngyt`}]]};Gs.node;var Ks=N(Gs),qs={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`]};qs.node;var Js=N(qs),Ys={name:`triangle-alert`,size:24,node:[[`path`,{d:`m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3`,key:`wmoenq`}],[`path`,{d:`M12 9v4`,key:`juzpu7`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]],aliases:[`alert-triangle`]};Ys.node;var Xs=N(Ys),Zs={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`}]]};Zs.node;var Qs=N(Zs),$s={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`}]]};$s.node;var ec=N($s),tc={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`]};tc.node;var nc=N(tc),rc={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`]};rc.node;var ic=N(rc),ac={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`}]]};ac.node;var oc=N(ac),sc={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`}]]};sc.node;var cc=N(sc),lc={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`}]]};lc.node;var uc=N(lc),dc={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`}]]};dc.node;var fc=N(dc),pc={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`}]]};pc.node;var mc=N(pc),hc={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`}]]};hc.node;var gc=N(hc),_c={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`}]]};_c.node;var vc=N(_c),yc={name:`x`,size:24,node:[[`path`,{d:`M18 6 6 18`,key:`1bl5f8`}],[`path`,{d:`m6 6 12 12`,key:`d8bk6v`}]]};yc.node;var bc=N(yc),xc={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`}]]};xc.node;var Sc=N(xc),I=e(t(),1),Cc=e(n(),1),L=M(`account`),wc=`/-/account`,Tc=`/-/sign-in-policy`,Ec=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}},Dc=e=>e?`${wc}/${encodeURIComponent(e)}`:wc,Oc=(e,t,n)=>[{id:`account`,label:L(`account`),icon:ic,href:`${e}${wc}`,active:Ec(t)!==void 0},...n?[{id:`sign-in-policy`,label:L(`signInPolicy`),icon:vs,href:`${e}${Tc}`,active:t===Tc}]:[]],kc=[`always`,`editing`,`reading`],Ac=e=>e!==void 0&&!kc.includes(e),jc={list:`list`,filter:`filter`,orderBy:`order_by`,display:`display`,filterLayout:`layout`,map:`map`,calendar:`calendar`,timeline:`timeline`,savedSearch:`saved_search`,create:`new`,edit:`edit`,open:`open`,tab:`tab`,standard:`standard`,call:`call`},Mc=[`list`,`display`,`filter`,`orderBy`,`filterLayout`,`savedSearch`],Nc=e=>`${e.latitude.toFixed(5)},${e.longitude.toFixed(5)},${e.zoom.toFixed(2)}`,Pc=(e,t,n=-t)=>Number.isFinite(e)&&e>=n&&e<=t,Fc=e=>{let t=e?.split(`,`);if(t?.length!==3||t.some(e=>e.trim()===``))return;let[n,r,i]=t.map(Number);return Pc(n,90)&&Pc(r,180)&&Pc(i,22,0)?{latitude:n,longitude:r,zoom:i}:void 0},Ic=e=>`${e.scale},${e.day}`,Lc=e=>{let t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e);if(!t)return!1;let[n,r,i]=t.slice(1).map(Number),a=new Date(Date.UTC(n,r-1,i));return a.getUTCFullYear()===n&&a.getUTCMonth()===r-1&&a.getUTCDate()===i},Rc=(e,t)=>{let n=e?.split(`,`);if(n?.length!==2)return;let[r,i]=n;return t.includes(r)&&Lc(i)?{scale:r,day:i}:void 0},zc=e=>{let t=new URLSearchParams;for(let n of Mc){let r=e[n];r===void 0||r===``&&n!==`filter`||t.set(jc[n],r)}e.map&&t.set(jc.map,Nc(e.map)),e.calendar&&t.set(jc.calendar,Ic(e.calendar)),e.timeline&&t.set(jc.timeline,Ic(e.timeline));let n=t.toString();return n?`?${n}`:``},Bc=e=>{let t=new URLSearchParams;e.edit&&t.set(jc.edit,`true`);for(let n of e.open??[])t.append(jc.open,n);e.tab&&t.set(jc.tab,e.tab),e.standard&&t.set(jc.standard,`true`),e.call&&t.set(jc.call,e.call);let n=t.toString();return n?`?${n}`:``},Vc=(e,t=``)=>{switch(e.kind){case`page`:return`${t}/${encodeURIComponent(e.page)}${e.tab?`/${encodeURIComponent(e.tab)}`:``}`;case`create`:return`${t}/${encodeURIComponent(e.resource)}/${jc.create}${Uc(e.values)}`;case`record`:return`${t}/${encodeURIComponent(e.resource)}/${encodeURIComponent(Nn(e.key))}${Bc(e)}`;case`list`:return`${t}/${encodeURIComponent(e.resource)}${zc(e)}`}},Hc=e=>{try{return e.split(`/`).filter(Boolean).map(decodeURIComponent)}catch(e){if(e instanceof URIError)return;throw e}},Uc=(e={})=>{let t=new URLSearchParams(Object.entries(e).filter(([,e])=>e!==``)).toString();return t?`?${t}`:``},Wc=e=>e===`bar`||e===`panel`?e:void 0,Gc=(e,t)=>{let n=new URL(e,`http://app`),r=Hc(n.pathname);if(!r||r.length===0||r.length>2)return;let[i,a]=r;if(i===`-`)return;if(t.has(i))return{kind:`page`,page:i,...a!==void 0&&{tab:a}};if(a===jc.create){let e=Object.fromEntries([...n.searchParams].filter(([,e])=>e!==``));return{kind:`create`,resource:i,...Object.keys(e).length>0&&{values:e}}}if(a!==void 0){let e=[...new Set(n.searchParams.getAll(jc.open).filter(e=>e!==``))],t=n.searchParams.get(jc.tab)||void 0,r=n.searchParams.get(jc.standard)===`true`,o=n.searchParams.get(jc.call)===`join`;return{kind:`record`,resource:i,key:a,...n.searchParams.get(jc.edit)===`true`&&{edit:!0},...e.length>0&&{open:e},...t&&{tab:t},...r&&{standard:r},...o&&{call:`join`}}}let o=n.searchParams,s=o.get(jc.list)||void 0,c=o.get(jc.display)||void 0,l=o.get(jc.filter)??void 0,u=o.get(jc.orderBy)||void 0,d=Wc(o.get(jc.filterLayout)),f=Fc(o.get(jc.map)),p=Rc(o.get(jc.calendar),[`month`,`week`]),m=Rc(o.get(jc.timeline),[`week`,`month`,`quarter`]),h=o.get(jc.savedSearch)||void 0;return{kind:`list`,resource:i,...s&&{list:s},...c&&{display:c},...l!==void 0&&{filter:l},...u&&{orderBy:u},...d&&{filterLayout:d},...f&&{map:f},...p&&{calendar:p},...m&&{timeline:m},...h&&{savedSearch:h}}},Kc={signature:`sig`},qc=e=>{let t=e.startsWith(`?`)?e.slice(1):e;return new URLSearchParams(t).has(Kc.signature)?{oauthQuery:t}:{}},Jc=`/-/sign-in`,Yc={step:`step`,next:`next`},Xc=[`sign-in`,`forgot-password`,`email-code`,`sign-up`,`sign-up-code`,`sign-up-details`],Zc=e=>Xc.includes(e),Qc=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}`},$c=({step:e=`sign-in`,next:t}={})=>{let n=new URLSearchParams;e!==`sign-in`&&n.set(Yc.step,e);let r=Qc(t);r&&r!==`/`&&n.set(Yc.next,r);let i=n.toString();return i?`${Jc}?${i}`:Jc},el=(e,t)=>{if(e!==`/-/sign-in`)return;let n=t.get(Yc.step),r=Qc(t.get(Yc.next));return{step:Zc(n)?n:`sign-in`,...r&&{next:r}}},tl=e=>typeof e==`string`?e:e&&Yt(e),nl=e=>{let t=Object.entries(e??{}).map(([e,t])=>`${e}.${t}`);return t.length>0?t:void 0},rl=e=>({photos:e&&`${e.resource}.${e.field}.${e.image}`,photos_order_by:e?.sort}),il=(e={})=>({filter:tl(e.filter)||void 0,order_by:e.orderBy,page_size:e.pageSize,page_token:e.pageToken||void 0,fields:e.fields?.join(`,`),labels:nl(e.labels)?.join(`,`),...rl(e.photos),count:e.count}),al=e=>{let t=new URLSearchParams;for(let[n,r]of Object.entries(e))r!==void 0&&t.set(n,String(r));let n=t.toString();return n?`?${n}`:``},ol=e=>e.startsWith(`/`)&&!e.startsWith(`//`),sl=e=>{if(typeof e!=`object`||!e)return!1;let{uri:t,url:n}=e;return typeof t==`string`&&typeof n==`string`&&ol(n)},cl=e=>e!==void 0&&URL.canParse(e)?new URL(e).origin:void 0,ll=(e,t)=>({...e,url:`${t}${e.url}`,...e.variants&&{variants:Object.fromEntries(Object.entries(e.variants).map(([e,n])=>[e,ol(n.url)?{...n,url:`${t}${n.url}`}:n]))}}),ul=(e,t)=>t===void 0||typeof e!=`object`||!e?e:Object.fromEntries(Object.entries(e).map(([e,n])=>[e,sl(n)?ll(n,t):n])),dl=(e,t)=>t===void 0?e:Object.fromEntries(Object.entries(e).map(([e,n])=>[e,n.map(e=>sl(e)?ll(e,t):e)])),fl=class extends Error{problem;constructor(e){super(e.detail??e.title),this.problem=e,this.name=`ApiError`}get status(){return this.problem.status}get slug(){return this.problem.type.split(`:`).at(-1)??``}get operation(){return this.problem.operation??this.errors.find(e=>e.operation!==void 0)?.operation}get blockedBy(){return this.problem.blockedBy}get existing(){return this.problem.existing}get errors(){return this.problem.errors??[]}get filterErrors(){return this.slug===`invalid-filter`?this.errors:[]}},pl=class extends fl{constructor(e){super(e),this.name=`PreconditionFailedError`}},ml=e=>e instanceof fl,hl=e=>typeof e==`object`&&!!e&&`type`in e&&`status`in e,gl=async e=>{let t=e.headers.get(`content-type`)?.includes(`json`)??!1?await e.json():void 0,n=hl(t)?t:{type:`urn:protobase:problem:unknown`,title:e.statusText||`Request failed`,status:e.status};return n.status===412?new pl(n):new fl(n)},_l=(e={})=>{let t=e.baseUrl??`/api/v1`,n=t.replace(/\/[^/]*$/,``),r=e.fetch??((e,t)=>fetch(e,t));return async({method:i,path:a,query:o=``,body:s,headers:c,accept:l=[],system:u,raw:d,via:f,signal:p})=>{let m=async l=>{let m=await e.token?.({refresh:l});return(f??r)(`${u?n:t}${a}${o}`,{method:i,headers:{...s!==void 0&&{"content-type":`application/json`},...m&&{authorization:`Bearer ${m}`},...e.headers?.(),...c},body:d??(s===void 0?void 0:JSON.stringify(s)),...p&&{signal:p}})},h=await m(!1);h.status===401&&e.token&&(h=await m(!0),h.status===401&&e.onUnauthenticated?.());let g=h.headers.get(`x-meta-version`);if(g&&e.onMetaVersion?.(g),!h.ok&&!l.includes(h.status))throw await gl(h);return h}},vl=e=>new Headers(e.trim().split(/[\r\n]+/).filter(Boolean).map(e=>{let t=e.indexOf(`:`);return[e.slice(0,t).trim(),e.slice(t+1).trim()]})),yl=e=>(t,n={})=>new Promise((r,i)=>{let a=new XMLHttpRequest;a.open(n.method??`GET`,String(t)),new Headers(n.headers).forEach((e,t)=>a.setRequestHeader(t,e)),a.responseType=`blob`,a.upload.onprogress=t=>e(t.loaded,t.lengthComputable?t.total:t.loaded),a.onload=()=>{let e=a.status===204||a.status===304;r(new Response(e?null:a.response,{status:a.status,statusText:a.statusText,headers:vl(a.getAllResponseHeaders())}))},a.onerror=()=>i(TypeError(`Network request failed`)),a.onabort=()=>i(new DOMException(`The upload was aborted`,`AbortError`)),n.signal?.addEventListener(`abort`,()=>a.abort()),a.send(n.body)}),bl=e=>Math.min(3e4,1e3*2**e),xl=(e,t)=>new Promise(n=>{let r=setTimeout(n,e);t.addEventListener(`abort`,()=>{clearTimeout(r),n()},{once:!0})}),Sl=(e,t,n=bl)=>{let r=new AbortController,{signal:i}=r,a,o=0,s=e=>{o=0,a=e.cursor,e.type===`resync`&&t.onResync(),e.type===`changes`&&t.onChanges(e.changes)},c=async()=>{let t=await e({method:`GET`,path:`/live`,query:al({after:a}),headers:{accept:`text/event-stream`},system:!0,signal:i});if(!t.body)throw Error(`The server answered the live stream without a body`);await rr(t.body,e=>s(JSON.parse(e)),i)};return(async()=>{for(;!i.aborted;){let e=await c().then(()=>void 0,e=>e);if(i.aborted)return;t.onRetry?.(e),await xl(n(o++),i)}})(),()=>r.abort()},Cl=e=>{let t=new Set,n,r=e=>{for(let n of[...t])e(n)};return i=>{let a={...i};return t.add(a),n??=e({onChanges:e=>r(t=>t.onChanges(e)),onResync:()=>r(e=>e.onResync()),onRetry:e=>r(t=>t.onRetry?.(e))}),()=>{!t.delete(a)||t.size>0||(n?.(),n=void 0)}}},wl=new TextEncoder,Tl=new TextDecoder,El=4,Dl=(e,t)=>{let n=wl.encode(JSON.stringify(e)),r=t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength),i=new Uint8Array(El+n.length+r.length);return new DataView(i.buffer).setUint32(0,n.length),i.set(n,El),i.set(r,El+n.length),i.buffer},Ol=e=>{let t=El+new DataView(e).getUint32(0);return{...JSON.parse(Tl.decode(new Uint8Array(e,El,t-El))),payload:e.slice(t)}},kl=e=>e instanceof ArrayBuffer||ArrayBuffer.isView(e),Al=class extends Error{code;constructor(e,t){super(t),this.code=e,this.name=`ChannelRefusal`}},jl=5e3,Ml=1,Nl=`protobase.channels`,Pl=({url:e,token:t,socket:n,retryDelay:r,onOpen:i,onDown:a,onMessage:o})=>{let s,c=!1,l=0,u=0,d,f=0,p,m,h=new Map,g=()=>{for(let{reject:e}of h.values())e(new Al(`disconnected`,`The connection dropped before the server answered`));h.clear()},_=async e=>{let n=await t?.();s===e&&e.readyState===Ml&&n!==void 0&&n!==d&&(d=n,e.send(JSON.stringify({type:`token`,token:n})))},v=async()=>{let u=await t?.();if(!c||s)return;d=u;let y=n(e(),u===void 0?[Nl]:[Nl,`bearer.${u}`]);s=y,y.binaryType=`arraybuffer`,y.onopen=()=>{l=0,f=Date.now(),p=setInterval(()=>{if(Date.now()-f>1e4)return y.close();y.send(JSON.stringify({type:`ping`})),_(y)},jl),i()},y.onmessage=({data:e})=>{if(f=Date.now(),typeof e!=`string`&&!(e instanceof ArrayBuffer))return;let t=typeof e==`string`?JSON.parse(e):Ol(e);if(t.type!==`reply`)return o(t);let n=h.get(t.ref);h.delete(t.ref),t.ok?n?.resolve(t):n?.reject(new Al(t.error.code,t.error.message))},y.onclose=()=>{s===y&&(clearInterval(p),s=void 0,g(),c&&(a(),m=setTimeout(()=>{m=void 0,v()},r(l++))))}},y=(e,t)=>s?.readyState===Ml&&(s.send(t===void 0?JSON.stringify(e):Dl(e,t)),!0);return{start:()=>{c=!0,!s&&m===void 0&&v()},stop:()=>{c=!1,clearTimeout(m),m=void 0,clearInterval(p);let e=s;s=void 0,g(),e?.close(1e3)},request:(e,t)=>new Promise((n,r)=>{let i=String(++u);if(!y({...e,ref:i},t))return r(new Al(`disconnected`,`The connection is down`));h.set(i,{resolve:n,reject:r})}),post:y}},Fl=e=>{if(!(e instanceof Al&&e.code===`disconnected`))throw e},Il=()=>new Al(`not-joined`,`The channel is not joined yet`),Ll=e=>{let t=new Map,n=new Map,r=(e,t)=>{e.status=t;for(let n of e.statusListeners)n(t)},i=(e,t)=>{let n=[...e.presence.values()];for(let r of e.presenceListeners)r(n,t)},a=e=>{t.delete(e),t.size===0&&c.stop()},o=e=>{let i=`${e.resource}/${e.key}`;c.request({type:`join`,resource:e.resource,key:e.key}).then(o=>{if(t.get(i)===e){if(e.holders===0)return c.post({type:`leave`,channel:o.channel}),a(i);e.name=o.channel,n.set(e.name,e),r(e,{state:`joined`}),e.tracked&&c.request({type:`track`,channel:e.name,state:e.tracked.state}).catch(Fl)}}).catch(n=>{if(t.get(i)===e&&e.holders===0&&n instanceof Al)return a(i);if(!(n instanceof Al)||n.code===`disconnected`)return Fl(n);r(e,{state:`refused`,error:{code:n.code,message:n.message}})})},s=e=>{if(e.type===`pong`||e.type===`reply`||e.type===`error`)return;let t=n.get(e.channel);if(t){if(e.type===`presence`)return t.presence=new Map(e.entries.map(e=>[e.id,e])),i(t);if(e.type===`presence_diff`){for(let n of e.leaves)t.presence.delete(n.id);for(let n of[...e.joins,...e.updates])t.presence.set(n.id,n);return i(t,{joins:e.joins,updates:e.updates,leaves:e.leaves})}if(e.type===`broadcast`){let{event:n,payload:r,user:i,server:a}=e;for(let e of t.eventListeners.get(n)??[])e({event:n,payload:r,user:i,...a&&{server:a}});return}n.delete(e.channel),t.presence.clear(),i(t),r(t,{state:`closed`,error:e.error})}},c=Pl({...e,onOpen:()=>{for(let[e,n]of t)n.status.state===`joining`&&(n.holders===0?a(e):o(n))},onDown:()=>{n.clear();for(let e of t.values())e.status.state===`joined`&&r(e,{state:`joining`})},onMessage:s}),l=(e,t)=>{--t.holders,!(t.holders>0)&&(t.tracked=void 0,t.status.state!==`joining`&&(t.name!==void 0&&(n.delete(t.name),c.post({type:`leave`,channel:t.name})),a(e)))},u=(e,t)=>{let n=!1,r=new Set,i=(e,t)=>{e.add(t);let n=()=>{e.delete(t),r.delete(n)};return r.add(n),n},a=()=>t.status.state===`joined`?t.name:void 0;return{status:()=>t.status,onStatus:e=>i(t.statusListeners,e),presence:()=>[...t.presence.values()],onPresence:e=>i(t.presenceListeners,e),track:async e=>{t.tracked={state:e};let n=a();n!==void 0&&await c.request({type:`track`,channel:n,state:e})},untrack:async()=>{t.tracked=void 0;let e=a();e!==void 0&&await c.request({type:`untrack`,channel:e})},send:async(e,t,{self:n,ack:r}={})=>{let i=a();if(i===void 0)throw Il();let o=kl(t)?t:void 0,s={type:`send`,channel:i,event:e,...o===void 0&&{payload:t},...n&&{self:n}};if(r){await c.request({...s,ack:r},o);return}if(!c.post(s,o))throw new Al(`disconnected`,`The connection is down`)},on:(e,n)=>{let r=t.eventListeners.get(e)??new Set;return t.eventListeners.set(e,r),i(r,n)},leave:()=>{if(!n){n=!0;for(let e of[...r])e();l(e,t)}}}};return{channel:(e,n)=>{let r=Nn(n),i=`${e}/${r}`,a=t.get(i);if(a)return a.holders+=1,u(i,a);let s={resource:e,key:r,status:{state:`joining`},presence:new Map,holders:1,statusListeners:new Set,presenceListeners:new Set,eventListeners:new Map};return t.set(i,s),c.start(),o(s),u(i,s)}}},Rl=e=>({register:async t=>(await e({method:`POST`,path:yr(``),system:!0,body:t})).json(),remove:async t=>{await e({method:`DELETE`,path:yr(``,t),system:!0})}}),zl=e=>({own:async()=>(await(await e({method:`GET`,path:Sr(``),system:!0})).json()).status,set:async t=>(await(await e({method:`PUT`,path:Sr(``),system:!0,body:t})).json()).status,clear:async()=>{await e({method:`DELETE`,path:Sr(``),system:!0})},people:async()=>(await(await e({method:`GET`,path:Sr(``,`people`),system:!0})).json()).statuses}),Bl=e=>({list:async({cursor:t,limit:n}={})=>{let r=new URLSearchParams({...t!==void 0&&{cursor:t},...n!==void 0&&{limit:String(n)}}),i=r.size>0?`?${r}`:``;return(await e({method:`GET`,path:xr(``),query:i,system:!0})).json()},unread:async()=>(await(await e({method:`GET`,path:xr(``,`unread`),system:!0})).json()).count,markRead:async t=>{await e({method:`POST`,path:xr(``,{read:t}),body:{},system:!0})},markAllRead:async t=>{await e({method:`POST`,path:xr(``,`read`),body:{upTo:t},system:!0})}}),Vl=e=>Math.min(3e4,1e3*2**e),Hl=(e,t)=>new Promise(n=>{let r=setTimeout(n,e);t.addEventListener(`abort`,()=>{clearTimeout(r),n()},{once:!0})}),Ul=(e,t,n=Vl)=>({calls:async(n,r)=>(await(await e({method:`GET`,path:t(n,r)})).json()).items,watchCalls:(r,i,a)=>{let o=new AbortController,{signal:s}=o,c=0,l=async()=>{let n=await e({method:`GET`,path:t(r,i),query:`?watch=true`,headers:{accept:`text/event-stream`},signal:s});if(!n.body)throw Error(`The server answered the calls stream without a body`);await rr(n.body,e=>{c=0,a.onCalls(JSON.parse(e).items)},s)};return(async()=>{for(;!s.aborted;){let e=await l().then(()=>void 0,e=>e);if(s.aborted)return;a.onRetry?.(e),await Hl(n(c++),s)}})(),()=>o.abort()}}),Wl=e=>({list:async()=>(await(await e({method:`GET`,path:Ar(``),system:!0})).json()).items,decline:async t=>{await e({method:`POST`,path:Ar(``,{decline:t}),system:!0,body:{}})}}),Gl=e=>({allowed:async()=>(await(await e({method:`GET`,path:Or(``,`organization`),system:!0})).json()).allowed,setAllowed:async t=>{await e({method:`PUT`,path:Or(``,`organization`),system:!0,body:{allowed:t}})}}),Kl=e=>typeof e==`string`?e:e.toModel().name,ql=(e=`/api/v1`)=>{let t=new URL(`${e.replace(/\/[^/]*$/,``)}/channels`,globalThis.location?.href);return t.protocol=t.protocol===`https:`?`wss:`:`ws:`,t.toString()},Jl=(e,t)=>`/${Kl(e)}/${Nn(t)}`,Yl=(e,t)=>`${Jl(e,t)}:calls`,Xl=(e,t,n)=>({items:e.items.map(e=>ul(e,n)),nextPageToken:e.next_page_token,totalSizeEstimate:e.total_size_estimate,...e.prev_page_token!==void 0&&{prevPageToken:e.prev_page_token},...e.total_size!==void 0&&{totalSize:e.total_size},...e.labels!==void 0&&{labels:e.labels},...e.photos!==void 0&&{photos:dl(e.photos,n)},...t.headers.get(`x-protobase-warning`)&&{warning:t.headers.get(`x-protobase-warning`)}}),Zl=({created_at:e,...t})=>({...t,createdAt:e}),Ql=e=>e.headers.get(`etag`)??``,$l=async(e,t)=>{let{permissions:n,...r}=await e.json();return{record:ul(r,t),etag:Ql(e),...n&&{permissions:n}}},eu=(e,t)=>({results:(e.results??[]).map(e=>e.op===`create`||e.op===`update`?{...e,record:ul(e.record,t)}:e.op===`reorder`?{...e,records:e.records.map(e=>({...e,record:ul(e.record,t)}))}:e)}),tu=(e={})=>{let t=_l(e),n=cl(e.baseUrl),r=async(e,r)=>{let i=await t({method:`GET`,path:`/${Kl(e)}`,query:al(il(r))});return Xl(await i.json(),i,n)},i=async(e,r)=>{let i=il(r),a=await t({method:`POST`,path:`/${Kl(e)}:search`,body:{...i,fields:r?.fields,labels:nl(r?.labels)}});return Xl(await a.json(),a,n)},a=async(e,r)=>$l(await t({method:`GET`,path:Jl(e,r)}),n),o=async(e,r)=>{let i=await t({method:`POST`,path:`/${Kl(e)}`,body:r});return{record:ul(await i.json(),n),etag:Ql(i),location:i.headers.get(`location`)??``}},s=async(e,r,i,a)=>$l(await t({method:`PATCH`,path:Jl(e,r),body:i,headers:{"if-match":a}}),n),c=async(e,n,{etag:r}={})=>{await t({method:`DELETE`,path:Jl(e,n),headers:r?{"if-match":r}:void 0})},l=async(e,r)=>{let i=await t({method:`POST`,path:`${Jl(e,r)}:undelete`});return{record:ul(await i.json(),n),etag:Ql(i)}},u=async(e,n,r)=>(await(await t({method:`POST`,path:`${Jl(e,n)}:reveal`,body:{field:r}})).json()).value,d=async(e,r,i)=>$l(await t({method:`POST`,path:`${Jl(e,r)}:generate`,body:{action:i}}),n),f=async(e,n,{pageSize:r,pageToken:i}={})=>{let a=al({page_size:r,page_token:i||void 0}),o=await(await t({method:`GET`,path:`${Jl(e,n)}:history`,query:a})).json();return{items:o.items.map(({database_role:e,...t})=>({...t,databaseRole:e})),nextPageToken:o.next_page_token}},p=async(e,n,{pageSize:r,pageToken:i}={})=>{let a=al({page_size:r,page_token:i||void 0}),o=await(await t({method:`GET`,path:`${Jl(e,n)}:comments`,query:a})).json();return{items:o.items.map(Zl),nextPageToken:o.next_page_token}},m=async(e,n,{body:r,mentions:i=[]})=>Zl(await(await t({method:`POST`,path:`${Jl(e,n)}:comments`,body:{body:r,mentions:i}})).json()),h=async(e,n,r)=>(await(await t({method:`GET`,path:`${Jl(e,n)}:mentionable`,query:al({q:r})})).json()).items,g=async e=>{let r=e=>typeof e==`object`&&e&&`$ref`in e?e:Nn(e),i=e.map(e=>({...e,resource:Kl(e.resource),...`key`in e&&{key:r(e.key)},...e.op===`reorder`&&{keys:e.keys.map(r)}}));return eu(await(await t({method:`POST`,path:`:batchWrite`,body:{ops:i}})).json(),n)},_=async(e,n,r={})=>(await(await t({method:`GET`,path:`/${Kl(e)}:facets`,query:al({field:n,filter:tl(r.filter)||void 0,limit:r.limit,label:r.label})})).json()).facets,v=async(e,n)=>{let r=await(await t({method:`GET`,path:`/${Kl(e)}:aggregate`,query:al({group_by:n.groupBy,filter:tl(n.filter)||void 0,sum:n.sum,average:n.average,maximum:n.maximum,limit:n.limit,label:n.label,granularity:n.granularity,range:n.range,from:n.from,to:n.to,time_zone:n.timeZone,split_by:n.splitBy,split_limit:n.splitLimit,split_label:n.splitLabel})})).json();return{groupBy:r.group_by,granularity:r.granularity,timeZone:r.time_zone,groups:r.groups,...r.split_by!==void 0&&{splitBy:r.split_by,splits:r.splits}}},y=async(e,n)=>{let r=await(await t({method:`GET`,path:`/${Kl(e)}:series`,query:al({field:n.field,range:n.range,from:n.from,to:n.to,granularity:n.granularity,time_zone:n.timeZone,filter:tl(n.filter)||void 0})})).json();return{field:r.field,granularity:r.granularity,timeZone:r.time_zone,points:r.points}},b=async(e,n,r={})=>(await t({method:`GET`,path:`/${Kl(e)}:histogram`,query:al({field:n,buckets:r.buckets,filter:tl(r.filter)||void 0})})).json(),x=async(e,r)=>{let i=await(await t({method:`GET`,path:`/${Kl(e)}:map`,query:al({latitude:r.latitude,longitude:r.longitude,zoom:r.zoom,filter:tl(r.filter)||void 0,order_by:r.orderBy,fields:r.fields?.join(`,`),labels:nl(r.labels)?.join(`,`),...rl(r.photos)})})).json();return{items:i.items.map(e=>ul(e,n)),buckets:i.buckets,totalSize:i.total_size,...i.labels!==void 0&&{labels:i.labels},...i.photos!==void 0&&{photos:dl(i.photos,n)}}},S=async(e,r)=>{let i=await t({method:`GET`,path:`/${Kl(e)}:seek`,query:al({...il(r),position:r.position})});return Xl(await i.json(),i,n)},C=async(e,{signal:n}={})=>{let r=await t({method:`GET`,path:`/meta`,system:!0,headers:e?{"if-none-match":e}:void 0,accept:[304],...n&&{signal:n}});return r.status===304?{status:`unchanged`}:{status:`modified`,meta:await r.json(),etag:Ql(r)}},w=async(e,{method:n,body:r,path:i=``,query:a,headers:o}={})=>{let s=await t({method:n??(r===void 0?`GET`:`POST`),path:`/functions/${encodeURIComponent(e)}${i}`,query:a?`?${new URLSearchParams(a)}`:``,body:r,headers:o,system:!0});if(s.status===204)return;let c=s.headers.get(`content-type`);return c?.includes(`json`)?s.json():!c||c.startsWith(`text/`)?s.text():s.blob()},T=async(e,n,r,{onProgress:i,signal:a}={})=>{let o=`name`in r&&typeof r.name==`string`?r.name:void 0,s=i&&typeof XMLHttpRequest<`u`?yl(i):void 0,c=await(await t({method:`POST`,path:`/${Kl(e)}:upload`,query:`?${new URLSearchParams({field:n,...o!==void 0&&{name:o}})}`,raw:r,headers:{"content-type":r.type||`application/octet-stream`},...s&&{via:s},...a&&{signal:a}})).json();return i?.(r.size,r.size),c},E=e=>`/forms/${encodeURIComponent(e)}`,D=async e=>(await t({method:`GET`,path:E(e),system:!0})).json(),O=async e=>(await t({method:`GET`,path:`${E(e)}:challenge`,system:!0})).json(),k=async(e,n,r)=>{await t({method:`POST`,path:E(e),body:{values:n,proof:r},system:!0})},A=Cl(e=>Sl(t,e)),{channel:j}=Ll({url:()=>ql(e.baseUrl),...e.token&&{token:()=>e.token({refresh:!1})},socket:e.webSocket??((e,t)=>new WebSocket(e,t)),retryDelay:e=>Math.min(3e4,1e3*2**e)}),ee=Rl(t),te=Bl(t),{calls:ne,watchCalls:re}=Ul(t,Yl);return{list:r,search:i,get:a,create:o,update:s,remove:c,undelete:l,generate:d,reveal:u,history:f,comments:p,comment:m,mentionable:h,batchWrite:g,facets:_,aggregate:v,series:y,histogram:b,map:x,seek:S,meta:C,invoke:w,upload:T,form:D,formChallenge:O,submitForm:k,live:A,channel:j,devices:ee,notifications:te,status:zl(t),calls:ne,watchCalls:re,rings:Wl(t),callGuests:Gl(t)}},nu=e=>typeof e==`string`?e:e.toModel().name,ru=(e,t)=>{let n=n=>t(nu(n))??e;return{list:(e,t)=>n(e).list(e,t),search:(e,t)=>n(e).search(e,t),get:(e,t)=>n(e).get(e,t),create:(e,t)=>n(e).create(e,t),update:(e,t,r,i)=>n(e).update(e,t,r,i),remove:(e,t,r)=>n(e).remove(e,t,r),undelete:(e,t)=>n(e).undelete(e,t),generate:(e,t,r)=>n(e).generate(e,t,r),reveal:(e,t,r)=>n(e).reveal(e,t,r),history:(e,t,r)=>n(e).history(e,t,r),comments:(e,t,r)=>n(e).comments(e,t,r),comment:(e,t,r)=>n(e).comment(e,t,r),mentionable:(e,t,r)=>n(e).mentionable(e,t,r),batchWrite:t=>{let r=[...new Set(t.map(e=>n(e.resource)))];return r.length>1?Promise.reject(Error(`A batch writes to one API, but these writes are for ${[...new Set(t.map(e=>nu(e.resource)))].join(`, `)}, which different APIs serve`)):(r[0]??e).batchWrite(t)},facets:(e,t,r)=>n(e).facets(e,t,r),aggregate:(e,t)=>n(e).aggregate(e,t),series:(e,t)=>n(e).series(e,t),histogram:(e,t,r)=>n(e).histogram(e,t,r),map:(e,t)=>n(e).map(e,t),seek:(e,t)=>n(e).seek(e,t),meta:(t,n)=>e.meta(t,n),invoke:(t,n)=>e.invoke(t,n),upload:(e,t,r,i)=>n(e).upload(e,t,r,i),form:t=>e.form(t),formChallenge:t=>e.formChallenge(t),submitForm:(t,n,r)=>e.submitForm(t,n,r),live:t=>e.live(t),channel:(t,n)=>e.channel(t,n),devices:e.devices,notifications:e.notifications,status:e.status,rings:e.rings,callGuests:e.callGuests,calls:(e,t)=>n(e).calls(e,t),watchCalls:(e,t,r)=>n(e).watchCalls(e,t,r)}},iu=e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&typeof e.type==`string`&&Array.isArray(e.children),au={record:!1},ou=e=>({resource:typeof e.props.resource==`string`?e.props.resource:void 0,record:!0}),su=(e,t)=>!e.custom&&(e.type===`RecordCard`||e.type===`CardRow`)?ou(e):t,cu=(e,t)=>!e.custom&&e.type===`RecordCard`?ou(e):t,lu=e=>`<${e.type}${typeof e.props.resource==`string`?` resource="${e.props.resource}"`:``}${typeof e.props.name==`string`?` name="${e.props.name}"`:``}>`,uu=e=>iu(e)||Array.isArray(e)&&e.length>0&&e.every(iu),du=(e,t,n={path:lu(e),scope:au})=>{let r=su(e,n.scope),i=cu(e,n.scope),a=e.children.flatMap(e=>{if(typeof e==`string`)return[e];let i=du(e,t,{path:`${n.path} › ${lu(e)}`,scope:r});return i?[i]:[]}),o=Object.fromEntries(Object.entries(e.props).flatMap(([e,r])=>{if(!uu(r))return[[e,r]];let a=(Array.isArray(r)?r:[r]).flatMap(r=>du(r,t,{path:`${n.path} ${e}={${lu(r)}}`,scope:i})??[]);return a.length===0?[]:[[e,Array.isArray(r)?a:a[0]]]}));return t({...e,props:o,children:a},n)},fu=e=>typeof e==`object`&&!!e&&e.kind===`member`,pu=e=>fu(e)?[e.path.join(`.`)]:typeof e!=`object`||!e?[]:Object.values(e).flatMap(pu),mu=e=>fu(e)?{...e,path:[e.path.join(`.`)]}:Array.isArray(e)?e.map(mu):typeof e!=`object`||!e?e:Object.fromEntries(Object.entries(e).map(([e,t])=>[e,mu(t)])),hu=new Set([`string`,`number`,`boolean`,`duration`,`timestamp`]),gu=e=>hu.has(e.kind),_u=e=>{let[t,...n]=e.args;if(t&&fu(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(gu))return{kind:`or`,args:n.map(n=>({kind:`compare`,op:`=`,left:t,right:n,span:e.span})),span:e.span}}},vu=e=>Array.isArray(e)?e.map(vu):typeof e!=`object`||!e?e:(e.kind===`call`?_u(e):void 0)||Object.fromEntries(Object.entries(e).map(([e,t])=>[e,vu(t)])),yu=e=>{let t=ie(e);return t.ok?t.ast?{ok:!0,ast:t.ast,paths:[...new Set(pu(t.ast))]}:{ok:!1,message:`the condition is empty`}:{ok:!1,message:t.errors.map(e=>e.message).join(`; `)}},bu=(e,t)=>e.ast!==void 0&&Ee(mu(vu(e.ast)),t),xu=(e,t)=>{let[n,r,...i]=e.split(`.`);return n&&r===`count`&&i.length===0&&!t(n)?n:void 0},Su=({layout:e,cardWidth:t})=>({layout:e??`stack`,cardWidth:t??`2/3`}),Cu=(e,t,n)=>{let r=[],i=e[t],a=n.split(`.`);for(let[o,s]of a.entries()){if(!i)return{ok:!1,message:`unknown resource "${t}"`};let c=Object.hasOwn(i.fields,s)?i.fields[s]:void 0;if(!c)return{ok:!1,message:`unknown field "${a.slice(0,o+1).join(`.`)}" on ${i.name}`};if(r.push({model:i,field:c}),o===a.length-1)break;if(c.type!==`relation`||!c.relation)return{ok:!1,message:`"${a.slice(0,o+1).join(`.`)}" is not a relation, so "${n}" cannot go through it`};t=c.relation.resource,i=e[t]}return{ok:!0,steps:r}},wu=(e,t)=>({...e,fields:Object.fromEntries(Object.entries(e.fields).map(([e,n])=>{if(!n.relation||Object.hasOwn(t,n.relation.resource))return[e,n];let{relation:r,...i}=n;return[e,i]}))}),Tu=(e,t)=>{if(e.kind===`group`){let n=e.items.flatMap(e=>Tu(e,t));return n.length>0?[{...e,items:n}]:[]}if(e.kind===`tab`){let n=e.items.flatMap(e=>Tu(e,t));return n.length>0?[{...e,items:n}]:[]}if(e.kind!==`related`)return[e];if(!Object.hasOwn(t,e.resource)||e.through&&!Object.hasOwn(t,e.through.resource))return[];let{columns:n,...r}=e,i=n?.filter(n=>Cu(t,e.resource,n).ok);return[i&&i.length>0?{...r,columns:i}:r]},Eu=(e,t,n)=>e.run?.kind!==`link`||!(`to`in e.run)||Qn(e.run.to,{models:n,pages:new Set,source:t}).length===0,Du=(e,t)=>({...e,layout:e.layout.flatMap(e=>Tu(e,t)),actions:e.actions.filter(n=>Eu(n,t[e.resource],t))}),Ou=(e,t)=>{let n=e.resources.filter(e=>t.resources.includes(e.name)),r=Object.fromEntries(n.map(e=>[e.name,e])),i=n.map(e=>wu(e,r)),a=Object.fromEntries(i.map(e=>[e.name,e]));return{resources:i,views:e.views.filter(e=>Object.hasOwn(a,e.resource)).map(e=>Du(e,a)),permissions:Object.fromEntries(n.flatMap(t=>e.permissions?.[t.name]?[[t.name,e.permissions[t.name]]]:[]))}},ku=class extends Error{status;code;constructor(e,t,n){super(e),this.status=t,this.code=n,this.name=`AuthError`}},R=(e,t)=>new ku(e?.message||t,e?.status??500,e?.code),Au=e=>new Date(e).toISOString(),ju=e=>({updateName:async t=>{let{error:n}=await e.updateUser({name:t});if(n)throw R(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 R(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 R(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 R(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 R(r,`Could not change your address`)},sessions:async()=>{let[t,n]=await Promise.all([e.listSessions(),e.getSession()]);if(t.error||!t.data)throw R(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:Au(e.createdAt),updatedAt:Au(e.updatedAt),expiresAt:Au(e.expiresAt),...t&&{staff:t}}})},revokeSession:async t=>{let{error:n}=await e.revokeSession({token:t});if(n)throw R(n,`Could not sign out the device`)},revokeOtherSessions:async()=>{let{error:t}=await e.revokeOtherSessions();if(t)throw R(t,`Could not sign out your other devices`)}}),Mu=e=>({signInMethods:async()=>{let{data:t,error:n}=await e.$fetch(`/account/sign-in-methods`);if(n||!t)throw R(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 R(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 R(n,`Could not add the passkey`)},renamePasskey:async(t,n)=>{let{error:r}=await e.passkey.updatePasskey({id:t,name:n});if(r)throw R(r,`Could not rename the passkey`)},removePasskey:async t=>{let{error:n}=await e.passkey.deletePasskey({id:t});if(n)throw R(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 R(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 R(n,`The code did not work`)},turnOnEmailedCodes:async t=>{let{error:n}=await e.twoFactor.enable({method:`otp`,...t&&{password:t}});if(n)throw R(n,`Could not turn on two-factor authentication`)},turnOffTwoFactor:async t=>{let{error:n}=await e.twoFactor.disable(t?{password:t}:{});if(n)throw R(n,`Could not turn off two-factor authentication`)},linkedProviders:async()=>{let{data:t,error:n}=await e.listAccounts();if(n||!t)throw R(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 R(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 R(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 R(i,`Could not start linking the mailbox`);return r.url},connectedApps:async()=>{let{data:t,error:n}=await e.$fetch(`/account/connected-apps`);if(n||!t)throw R(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 R(n,`Could not disconnect the app`)},newBackupCodes:async t=>{let{data:n,error:r}=await e.twoFactor.generateBackupCodes(t?{password:t}:{});if(r||!n)throw R(r,`Could not make new backup codes`);return n.backupCodes}}),Nu=(e,t)=>new ku(e?.message||e?.error_description||t,e?.status??500,e?.code??e?.error),Pu=e=>({client:async t=>{let{data:n,error:r}=await e.$fetch(`/oauth2/public-client`,{query:{client_id:t}});if(r||!n)throw Nu(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 Nu(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 Nu(i,`Could not answer the request`);return{url:r.url}}}),Fu=(e,t,n)=>x({baseURL:e,basePath:t,plugins:[k(),O(),m(),A()],disableDefaultFetchPlugins:!0,fetchOptions:{customFetchImpl:n}}),Iu=e=>Array.isArray(e)?e.filter(e=>typeof e==`string`):typeof e==`string`?JSON.parse(e):[],Lu=e=>{let t=e.split(`,`);return t.includes(`owner`)?`owner`:t.includes(`admin`)?`admin`:`member`},Ru=e=>({id:e.id,userId:e.userId,name:e.user.name||e.user.email,email:e.user.email,role:Lu(e.role),appRoles:Iu(e.appRoles),createdAt:new Date(e.createdAt).toISOString()}),zu=e=>({id:e.id,email:e.email,role:Lu(e.role),appRoles:Iu(e.appRoles),status:e.status,expiresAt:new Date(e.expiresAt).toISOString(),...e.organizationName&&{organizationName:e.organizationName}}),Bu=(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 R(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(Ru),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(zu),invite:async(e,t)=>{let r=await n(`/organization/invite-member`,`Could not send the invitation`,{body:{organizationId:e,...t}});return{invitation:zu(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:zu(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(zu),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}}))}},Vu=(e,t)=>({current:async()=>{let{data:t,error:n}=await e.$fetch(`/role/current`,{method:`GET`});if(n)throw R(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 R(r,`Could not switch the role`);await t()}}),Hu=20,Uu=e=>Array.isArray(e)?e:(e??``).split(`,`).map(e=>e.trim()).filter(Boolean),Wu=e=>({id:e.id,name:e.name||e.email,email:e.email,roles:Uu(e.role),blocked:!!e.banned,createdAt:new Date(e.createdAt).toISOString()}),Gu=e=>({id:e.id,email:e.email,roles:e.roles,expiresAt:new Date(e.expiresAt).toISOString()}),Ku=e=>({invitation:Gu(e),...e.link&&{link:e.link}}),qu=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 R(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(Hu),sortBy:`createdAt`,sortDirection:`asc`,...n>0&&{offset:String(n)},...e&&{searchValue:e,searchField:`email`}}});return{users:r.users.map(Wu),total:r.total}},create:async e=>Wu((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=>Ku(await t(`/users/invite`,`Could not send the invitation`,{body:e})),invitations:async()=>(await t(`/users/invitations`,`Could not read the invitations`)).invitations.map(Gu),revoke:e=>t(`/users/invitations/cancel`,`Could not revoke the invitation`,{body:{id:e}}),roles:()=>t(`/users/roles`,`Could not read the roles`)}},Ju=(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 R(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 R(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 R(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 R(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 R(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 R(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 R(r.error,`Sign-in failed`);let{clientExtensionResults:a,...o}=await i({optionsJSON:r.data}).catch(e=>{throw new ku(`Auth cancelled`,400,e instanceof oe?e.code:`AUTH_CANCELLED`)}),s=await e.$fetch(`/passkey/verify-authentication`,{method:`POST`,body:{response:o}});if(s.error||!s.data)throw R(s.error,`Sign-in failed`);return await t(),s.data.user},sendTwoFactorCode:async()=>{let{error:t}=await e.twoFactor.sendOtp();if(t)throw R(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 R(o,`The code did not work`);return await t(),a.user}}},Yu=e=>({read:async()=>{let{data:t,error:n}=await e.$fetch(`/policy/sign-in`);if(n||!t)throw R(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 R(r,`Could not save the sign-in policy`);return n}}),Xu=e=>new Date(e).toISOString(),Zu=({startedAt:e,expiresAt:t,endedAt:n,...r})=>({...r,startedAt:Xu(e),expiresAt:Xu(t),...n&&{endedAt:Xu(n)}}),Qu=e=>({start:async t=>{let{data:n,error:r}=await e.$fetch(`/staff/sign-in`,{method:`POST`,body:t});if(r||!n?.url)throw R(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 R(n,`Could not read the session`);return t.staff?Zu(t.staff):void 0},stop:async()=>{let{error:t}=await e.$fetch(`/staff/stop`,{method:`POST`,body:{}});if(t)throw R(t,`Could not end the staff session`)},log:async()=>{let{data:t,error:n}=await e.$fetch(`/staff/sign-ins`);if(n||!t)throw R(n,`Could not read the staff sign-ins`);return t.signIns.map(Zu)}}),$u=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},ed=(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=Fu(t,n,i),o=Qu(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:$u(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 ku(`This server has no sign-in. Is the API URL right?`,404);if(!e.ok)throw new ku(`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},socialProviders:r.socialProviders??[],...r.platformSignIn&&{platformSignIn:r.platformSignIn},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.personalMail&&r.personalMail.length>0&&{personalMail:r.personalMail},...r.plugins&&r.plugins.length>0&&{plugins:r.plugins},...Fe(r.locale)&&{locale:r.locale}}},session:async()=>{let{data:e}=await a.getSession();return e?.user},...Ju(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 R(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 R(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 R(t,`Could not delete your account`);u()},requestPasswordReset:async(e,t)=>{let{error:n}=await a.requestPasswordReset({email:e,redirectTo:t});if(n)throw R(n,`Could not send the reset link`)},resetPassword:async(e,t)=>{let{error:n}=await a.resetPassword({token:e,newPassword:t});if(n)throw R(n,`Could not set the password`)},account:{...Mu(a),...ju(a)},connect:Pu(a),organizations:Bu(a,()=>f({refresh:!0})),roles:Vu(a,()=>f({refresh:!0})),signInPolicy:Yu(a),users:qu(a),staff:{...o,stop:async()=>{u(),await o.stop()}}}},td=e=>Math.min(3e4,1e3*2**e),nd=(e,t)=>new Promise(n=>{let r=setTimeout(n,e);t.addEventListener(`abort`,()=>{clearTimeout(r),n()},{once:!0})}),rd=`http://same-origin.invalid`,id=(e,t)=>{let n=new URL(e,rd),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===rd?`${r.pathname}${r.search}`:r.href},ad=e=>{let t=e.url.replace(/\/+$/,``),n=e.fetch??((e,t)=>fetch(e,t)),r=e.retryDelayMs??td,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 gl(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 rr(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 nd(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=id(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 gl(c);return c}}},od=e=>typeof e==`object`&&!!e&&`error`in e&&typeof e.error==`object`&&e.error!==null&&`code`in e.error&&`message`in e.error,sd=async e=>{let t=e.headers.get(`content-type`)?.includes(`json`)??!1?await e.clone().json():void 0;return od(t)?new fl({type:`urn:protobase:problem:${t.error.code}`,title:e.statusText||`Request failed`,status:e.status,detail:t.error.message}):gl(e)},cd=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 sd(o);return await o.json()};return{status:()=>r(``,`GET`),update:()=>r(`/update`,`POST`)}},ld=e=>e.Capacitor?.isNativePlatform()?e.Capacitor:void 0,ud=[101,204,205,304],dd=/%2f|%5c/i,fd=e=>Object.hasOwn(gr,e),pd=(e,t)=>e.origin===t&&!e.username&&!e.password&&e.pathname.startsWith(`/api/auth/`)&&!dd.test(e.pathname),md=({status:e,headers:t,data:n})=>ud.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),hd=(e,t)=>{let n=e.getPlatform();if(!fd(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(!pd(a,t))throw Error(`Native sign-in requests go to ${t}${hr}/ 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(md(s),{status:s.status,headers:c})}},gd=(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(`/${vr}`),t.serviceWorker.ready),clearBadge:async()=>{`clearAppBadge`in t&&await t.clearAppBadge()},userAgent:t.userAgent.replace(/[\u0000-\u001f\u007f]/g,``).slice(0,512)}},_d=(e=indexedDB)=>{let t=(t,n)=>new Promise((r,i)=>{let a=e.open(_r.database,1);a.onupgradeneeded=()=>a.result.createObjectStore(_r.store),a.onerror=()=>i(a.error),a.onsuccess=()=>{let e=a.result,o=n(e.transaction(_r.store,t).objectStore(_r.store));o.onsuccess=()=>(e.close(),r(o.result)),o.onerror=()=>(e.close(),i(o.error))}});return{read:()=>t(`readonly`,e=>e.get(_r.key)),write:async e=>void await t(`readwrite`,t=>t.put(e,_r.key)),clear:async()=>void await t(`readwrite`,e=>e.delete(_r.key))}},vd=e=>Uint8Array.from(atob(e.replace(/-/g,`+`).replace(/_/g,`/`)),e=>e.charCodeAt(0)),yd=(e,t)=>Promise.race([t,new Promise(t=>setTimeout(t,e))]),bd=class extends Error{},xd=(e,t)=>e instanceof fl&&e.status===409&&e.slug===t,Sd=({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 bd;let e=await c.pushManager.getSubscription()??await c.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:vd(a)}),i={userId:n.id,endpoint:e.endpoint,appName:r};if(await t.write(i),!o())throw new bd;await d(e,i)};try{await h()}catch(e){if(xd(e,`device-held`))return await u(c),m(c,h);if(await u(c),e instanceof bd||xd(e,`other-user`))return`off`;throw e}return`on`},m=async(e,t)=>{try{await t()}catch(t){if(await u(e),t instanceof bd||xd(t,`device-held`)||xd(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 yd(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 yd(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(!xd(e,`device-held`)&&!xd(e,`other-user`))throw e;await u(r)}}}},Cd={state:async()=>`unsupported`,turnOn:async()=>`unsupported`,turnOff:async()=>{},forget:async()=>{},adopt:async()=>{}},wd=({nativeBridge:e,...t})=>{if(e||typeof window>`u`)return Cd;let n=gd();return n.supported?Sd({...t,browser:n,records:_d()}):Cd},Td=`sign-in`,Ed=`error`,Dd=e=>{let t=new URL(e).searchParams;if(!t.has(Ed))return t.get(`sign-in`)||void 0},Od=e=>new URL(e).searchParams.get(Ed)||void 0,kd=e=>{let t=new URL(e);for(let e of[Td,Ed])t.searchParams.delete(e);return`${t.pathname}${t.search}${t.hash}`},Ad={github:`GitHub`,gitlab:`GitLab`,google:`Google`,microsoft:`Microsoft`,apple:`Apple`},jd=(e,t)=>t?.provider===e?t.name:Ad[e]??e.charAt(0).toUpperCase()+e.slice(1),z=M(`auth`),B=e(r(),1),Md=(0,I.createContext)(null),V=()=>{let e=(0,I.useContext)(Md);if(!e)throw Error(`useAuth must be used inside AuthProvider`);return e},Nd=()=>(0,I.useContext)(Md),Pd=({session:e,origin:t,nativeBridge:n,children:r})=>{let[i,a]=(0,I.useState)({kind:`loading`}),[o,s]=(0,I.useState)([`password`]),[c,l]=(0,I.useState)(`password`),[u,d]=(0,I.useState)(!1),[f,p]=(0,I.useState)(!1),[m,h]=(0,I.useState)(!1),[g,_]=(0,I.useState)(),[v,y]=(0,I.useState)(!1),[b,x]=(0,I.useState)([]),[S,C]=(0,I.useState)([]),[w,T]=(0,I.useState)(),[E,D]=(0,I.useState)([]),[O,k]=(0,I.useState)([]),[A,j]=(0,I.useState)(),[ee,te]=(0,I.useState)(),[ne,re]=(0,I.useState)(!1),[ie,ae]=(0,I.useState)([]),[oe,se]=(0,I.useState)(),ce=(0,I.useCallback)(()=>ne?{kind:`visitor`}:{kind:`signed-out`},[ne]),le=(0,I.useRef)(async()=>{}),ue=(0,I.useCallback)(()=>{le.current(),a(e=>e.kind===`signed-in`?{kind:`signed-out`}:e)},[]),de=(0,I.useRef)(ue);de.current=ue;let fe=(0,I.useMemo)(()=>e??ed({...t&&{origin:t},...n&&{fetch:hd(n,t??window.location.origin)},onSignedOut:()=>de.current()}),[e,t,n]),pe=(0,I.useRef)(void 0);pe.current=i.kind===`signed-in`?{id:i.user.id,own:!i.staff}:void 0;let me=(0,I.useMemo)(()=>{let e=tu({baseUrl:`${t??globalThis.location?.origin??``}/api/v1`,token:({refresh:e})=>fe.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 wd({...n&&{nativeBridge:n},devices:e.devices,meta:r,user:()=>pe.current})},[fe,t,n]);le.current=me.forget;let he=(0,I.useCallback)(async e=>{let[{missing:t},n]=await Promise.all([fe.account.signInMethods(),fe.staff.current()]);a(t.length>0?{kind:`setup-required`,user:e,missing:t}:{kind:`signed-in`,user:e,...n&&{staff:n}}),t.length===0&&me.adopt({id:e.id,own:!n})},[fe,me]),ge=(0,I.useCallback)(async e=>e.kind===`two-factor`?a({kind:`two-factor`,methods:e.methods}):he(e.user),[he]),_e=(0,I.useCallback)(()=>{a({kind:`loading`}),fe.status().then(async e=>{if(s(e.signInMethods),l(e.signInFirst??`password`),d(e.passwordReset&&!n),p(!!e.changeEmail),h(!!e.accountDeletion),_(e.mcp),y(!!e.signUp),x(e.passkeyDomains??[]),C(e.socialProviders),T(e.platformSignIn),D(e.personalMail??[]),k(e.samlProviders),j(e.staffSignIn),te(e.organizations),re(!!e.anonymous),ae(e.plugins??[]),se(e.locale),e.needsAdmin)return a({kind:`needs-admin`,...e.firstAdminUrl&&{firstAdminUrl:e.firstAdminUrl}});let t=await fe.session();return t?he(t):a({kind:e.anonymous?`visitor`:`signed-out`})}).catch(e=>a({kind:`error`,message:e instanceof Error?e.message:z(`noAnswer`)}))},[fe,he,n]);(0,I.useEffect)(_e,[_e]);let ve=(0,I.useMemo)(()=>({state:i,session:fe,signInMethods:o,signInFirst:c,passwordReset:u,changeEmail:f,accountDeletion:m,mcp:g,canSignUp:v,passkeyDomains:b,socialProviders:S,signInProviders:[...S.map(e=>({id:e,name:jd(e,w)})),...O],staffSignIn:A,...ee&&{organizations:ee},markSignedOut:ue,recheck:_e,beforeSignIn:ie,locale:oe,adoptSession:async()=>{let e=await fe.session();return e?(await he(e),!0):!1},...ne&&{browse:()=>{a(e=>e.kind===`signed-out`?{kind:`visitor`}:e)}},signIn:async(e,t)=>ge(await fe.signIn(e,t)),sendSignInCode:e=>fe.sendSignInCode(e),signInWithCode:async(e,t)=>ge(await fe.signInWithCode(e,t)),sendSignUpCode:e=>fe.sendSignUpCode(e),verifySignUpCode:(e,t)=>fe.verifySignUpCode(e,t),signUp:async e=>he(await fe.signUp(e)),signInWithPasskey:async e=>he(await fe.signInWithPasskey(e)),verifyTwoFactor:async e=>he(await fe.verifyTwoFactor(e)),signInSocial:async e=>{let t=new URL(kd(window.location.href),window.location.href).href,n=O.some(t=>t.id===e);window.location.assign(await(n?fe.signInSaml(e,t):fe.signInSocial(e,t)))},linkProvider:async e=>{window.location.assign(await fe.account.linkProvider(e,new URL(kd(window.location.href),window.location.href).href))},personalMail:E,linkPersonalMail:async e=>{window.location.assign(await fe.account.linkPersonalMail(e,new URL(kd(window.location.href),window.location.href).href))},stopStaffSession:async()=>{await me.forget(),await fe.staff.stop(),a(ce())},signOut:async()=>{await me.turnOff(),await fe.signOut(),a(ce())},deleteAccount:async e=>{await fe.deleteAccount(e),await me.forget(),a(ce())},push:me}),[me,i,fe,o,c,u,f,m,g,v,b,S,w,E,O,A,ee,ne,ie,oe,ce,ue,_e,ge,he]);return(0,B.jsx)(Md.Provider,{value:ve,children:r})},Fd=()=>{let e=0;return{refetchOnWindowFocus:()=>e>0?!1:`always`,paused:()=>e>0,pause:()=>{e+=1;let t=!1;return()=>{t||(t=!0,--e)}}}},Id=(0,I.createContext)(null),Ld=e=>{let t=(0,I.useContext)(Id);(0,I.useEffect)(()=>e&&t?t.pause():void 0,[e,t])},Rd=e=>{let t=()=>e();return window.addEventListener(`visibilitychange`,t,!1),window.addEventListener(`focus`,t,!1),()=>{window.removeEventListener(`visibilitychange`,t),window.removeEventListener(`focus`,t)}},H={meta:[`meta`],sourceMeta:(e,t)=>[`source-meta`,e,t.join(`,`)],sourceMetas:e=>[`source-meta`,e],list:(e,t,n,r,i)=>[`list`,e,t,n,r,i],page:(e,t,n,r,i)=>[`page`,e,t,n,r,i],pages:(e,t,n)=>[`page`,e,t,n],navRecent:(e,t,n,r)=>[`list`,e,t,n,r,`nav-recent`],first:(e,t,n)=>[`first-page`,e,t,n],record:(e,t)=>[`record`,e,t],recordPreview:(e,t)=>[`record-preview`,e,t],history:(e,t,n)=>[`record`,e,t,`history`,n],comments:(e,t)=>[`record`,e,t,`comments`],facets:(e,t,n)=>[`facets`,e,t,n],series:(e,t,n,r,i)=>[`series`,e,t,n,r,i],aggregate:(e,t)=>[`aggregate`,e,t],histogram:(e,t,n,r)=>[`histogram`,e,t,n,r],map:(e,t,n,r,i)=>[`map`,e,t,n,r,i],relatedLabel:(e,t)=>[`related-label`,e,t],titleRow:(e,t,n)=>[`title-row`,e,t,n],labels:(e,t)=>[`labels`,e,t],pickedLabels:(e,t)=>[`picked-labels`,e,t],count:(e,t)=>[`count`,e,t],exportCount:(e,t)=>[`list`,e,t,`export-count`],firstRecord:(e,t,n)=>[`first-record`,e,t,n],pathValue:(e,t,n)=>[`path-value`,e,t,n],inbox:[`inbox`],inboxUnread:[`inbox`,`unread`],inboxPages:[`inbox`,`pages`],members:e=>[`members`,e],statuses:e=>[`statuses`,e],ownStatus:e=>[`statuses`,e,`own`],rings:[`call-rings`],recordCalls:(e,t)=>[`record-calls`,e,t],publicForm:e=>[`public-form`,e]},zd=(0,I.createContext)(null),Bd=(0,I.createContext)(null),Vd=(0,I.createContext)(null),U=()=>{let e=(0,I.useContext)(zd);if(!e)throw Error(`useClient must be used inside ApiProvider`);return e},Hd=e=>{let t=U();return(0,I.useContext)(Vd)?.(e)??t},Ud=()=>{let e=U(),t=(0,I.useContext)(Vd);return(0,I.useCallback)(n=>t?.(n)??e,[e,t])},Wd=()=>{let e=(0,I.useContext)(Bd);if(!e)throw Error(`useSourceClients must be used inside ApiProvider`);return e},Gd=({client:e,resourceClient:t,children:n})=>(0,B.jsx)(zd.Provider,{value:e,children:(0,B.jsx)(Vd.Provider,{value:t,children:n})}),Kd=({baseUrl:e,client:t,sources:n,fetch:r,queryClient:i,token:a,onUnauthenticated:o,children:s})=>{let[c]=(0,I.useState)(Fd),[l]=(0,I.useState)(()=>i??new T({defaultOptions:{queries:{staleTime:3e4,retry:!1,refetchOnWindowFocus:c.refetchOnWindowFocus}}}));(0,I.useEffect)(()=>D.setEventListener(Rd),[]);let u=(0,I.useRef)(void 0),d=(0,I.useMemo)(()=>t??tu({baseUrl:e,fetch:r,token:a,onUnauthenticated:o,onMetaVersion:e=>{let t=u.current;u.current=e,t!==void 0&&t!==e&&(l.getQueryData(H.meta)?.versionChange||l.invalidateQueries({queryKey:H.meta},{cancelRefetch:!1}))}}),[t,e,r,l,a,o]),f=(0,I.useMemo)(()=>{let e=new Map;return t=>{let i=n?.[t.url]??e.get(t.url);if(i)return i;let o,s=tu({baseUrl:t.url,fetch:r,token:a,onMetaVersion:e=>{let n=o;o=e,n!==void 0&&n!==e&&l.invalidateQueries({queryKey:H.sourceMetas(t.url)},{cancelRefetch:!1})}});return e.set(t.url,s),s}},[n,r,a,l]);return(0,B.jsx)(h,{client:l,children:(0,B.jsx)(zd.Provider,{value:d,children:(0,B.jsx)(Bd.Provider,{value:f,children:(0,B.jsx)(Id.Provider,{value:c,children:s})})})})},qd=(0,I.createContext)(null),Jd={create:!0,update:!0,delete:!0,conditional:[]},Yd=(e,t)=>e?e.versionChange?e:t.protobaseVersion===e.protobaseVersion?t:{...e,versionChange:{...t.protobaseVersion&&{to:t.protobaseVersion}}}:t,Xd=()=>{let e=U(),t=Se(),n=(0,I.useContext)(qd),r=E({queryKey:H.meta,staleTime:0,refetchOnWindowFocus:`always`,enabled:e=>!e.state.data?.versionChange,queryFn:async()=>{let n=t.getQueryData(H.meta),r=await e.meta(n?.etag);if(r.status===`unchanged`){if(!n)throw Error(`The server answered 304 to a request without If-None-Match`);return n}return Yd(n,{etag:r.etag,appName:r.meta.appName,...r.meta.protobaseVersion&&{protobaseVersion:r.meta.protobaseVersion},...r.meta.appIcon&&{appIcon:r.meta.appIcon},resources:Object.fromEntries(r.meta.resources.map(e=>[e.name,e])),views:Object.fromEntries(r.meta.views.map(e=>[e.resource,e])),pages:Object.fromEntries((r.meta.pages??[]).map(e=>[e.name,e])),...r.meta.account&&{account:r.meta.account},permissions:r.meta.permissions??{},...r.meta.userMenu&&{userMenu:r.meta.userMenu},...r.meta.signIn&&{signIn:Object.fromEntries(r.meta.signIn.map(e=>[e.resource,e]))},...r.meta.bottomBar&&{bottomBar:r.meta.bottomBar},...r.meta.assistant&&{assistant:r.meta.assistant},...r.meta.runtime&&{runtime:r.meta.runtime},...r.meta.errorReporting&&{errorReporting:r.meta.errorReporting},...r.meta.maps&&{maps:r.meta.maps},...r.meta.notifications?.bell&&{bell:!0},...r.meta.status&&{status:!0},...r.meta.calls&&{calls:!0},...r.meta.locale&&{locale:r.meta.locale},...r.meta.files&&{files:r.meta.files},...r.meta.plugins&&{plugins:r.meta.plugins},...r.meta.sources&&{sources:r.meta.sources.map(e=>({source:e,state:`loading`}))}})}});return(0,I.useMemo)(()=>n&&r.data?{...r,data:n}:r,[n,r])},Zd=1e4,Qd=e=>e.map(e=>({data:e.data?.meta,error:e.error})),$d=(e,t)=>{let n=Se(),r=f({queries:e.map(e=>{let r=H.sourceMeta(e.url,e.resources);return{queryKey:r,staleTime:0,refetchOnWindowFocus:`always`,queryFn:async()=>{let i=n.getQueryData(r),a=await t(e).meta(i?.etag,{signal:AbortSignal.timeout(Zd)});if(a.status===`unchanged`){if(!i)throw Error(`${e.label} answered 304 to a request without If-None-Match`);return i}return{etag:a.etag,meta:Ou(a.meta,e)}}}}),combine:Qd});return(0,I.useMemo)(()=>e.map((e,t)=>{let{data:n,error:i}=r[t];return n?{source:e,state:`ready`,meta:n}:i?{source:e,state:`error`,error:i}:{source:e,state:`loading`}}),[e,r])},ef=(e,t)=>{if(t.length===0)return e;let n=t.flatMap(e=>e.state===`ready`?[e.meta]:[]),r=t.map(e=>e.state===`error`?{source:e.source,state:`error`,error:e.error}:{source:e.source,state:e.state});return{...e,resources:{...e.resources,...Object.fromEntries(n.flatMap(e=>e.resources.map(e=>[e.name,e])))},views:{...e.views,...Object.fromEntries(n.flatMap(e=>e.views.map(e=>[e.resource,e])))},permissions:{...e.permissions,...Object.assign({},...n.map(e=>e.permissions))},sources:r}},tf=(e,t)=>e.sources?.find(e=>e.source.resources.includes(t)),nf=({locale:e,children:t})=>{He(e);let n=Be();return(0,I.useEffect)(()=>{document.documentElement.lang=n},[n]),(0,B.jsx)(I.Fragment,{children:t},n)},rf=M(`primitives`),af=({className:e})=>(0,B.jsx)(to,{"aria-label":rf(`loading`),className:P(`size-4 animate-spin`,e)}),of=M(`app/meta-gate`),W=()=>{let e=(0,I.useContext)(qd);if(!e)throw Error(`useAdminMeta must be used inside MetaGate`);return e},sf=({title:e,children:t})=>(0,B.jsx)(`div`,{className:`flex h-full min-h-48 flex-1 items-center justify-center p-8`,children:(0,B.jsxs)(`div`,{className:`max-w-md text-center`,children:[(0,B.jsx)(`h1`,{className:`text-[16px] font-semibold`,children:e}),(0,B.jsx)(`p`,{className:`mt-1 text-muted-foreground`,children:t})]})}),cf=({meta:e,children:t})=>{let n=U(),r=Wd(),i=(0,I.useMemo)(()=>(e.sources??[]).map(e=>e.source),[e.sources]),a=$d(i,r),o=(0,I.useMemo)(()=>ef(e,a),[e,a]),s=(0,I.useMemo)(()=>{let e=new Map(i.flatMap(e=>e.resources.map(t=>[t,e]))),t=t=>{let n=e.get(t);return n&&r(n)};return{client:ru(n,t),resourceClient:t}},[i,n,r]);return(0,B.jsx)(Gd,{client:s.client,resourceClient:s.resourceClient,children:(0,B.jsx)(qd.Provider,{value:o,children:(0,B.jsx)(nf,{locale:e.locale,children:t})})})},lf=({children:e})=>{let t=Xd();return t.isPending?(0,B.jsxs)(`div`,{className:`flex h-full min-h-48 items-center justify-center gap-2 text-muted-foreground`,children:[(0,B.jsx)(af,{}),` `,of(`loading`)]}):t.error?(0,B.jsx)(sf,{title:of(`cannotReach`),children:ml(t.error)?t.error.message:of(`noAnswer`)}):(0,B.jsx)(cf,{meta:t.data,children:e})},uf=e=>W().permissions[e]??Jd,df=(0,I.createContext)(null),ff=({route:e,children:t})=>(0,B.jsx)(df.Provider,{value:e,children:t}),pf=()=>{let e=(0,I.useContext)(df);if(!e)throw Error(`Tabs render inside a page that gives them their addresses: a composed page`);return e},mf=e=>e.children.filter(e=>typeof e!=`string`).map(e=>({node:e,...e.props})),hf=e=>{let t=e.children.find(e=>typeof e!=`string`&&!e.custom&&e.type===`Tabs`);return t?mf(t):[]},gf=(e,t)=>t===void 0?e[0]:e.find(e=>e.name===t),_f={primary:`bg-primary text-primary-foreground hover:bg-primary-hover shadow-sm`,secondary:`bg-background text-foreground border border-border-strong hover:bg-muted shadow-sm`,ghost:`text-muted-foreground hover:bg-muted hover:text-foreground`,danger:`bg-background text-danger-text border border-border-strong hover:bg-danger-soft shadow-sm`},vf={sm:`h-7 px-2.5 text-body gap-1.5`,md:`h-8 px-3 text-body gap-2`,icon:`size-7 text-body`},yf=({variant:e=`secondary`,size:t=`md`}={})=>P(`inline-flex shrink-0 items-center justify-center rounded-md font-medium transition-colors focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary disabled:opacity-60 disabled:cursor-default`,_f[e],vf[t]),G=({variant:e=`secondary`,size:t=`md`,loading:n,className:r,children:i,disabled:a,...o})=>(0,B.jsxs)(`button`,{type:`button`,disabled:a||n,className:P(yf({variant:e,size:t}),r),...o,children:[n&&(0,B.jsx)(af,{className:`size-3.5`}),i]}),bf=e=>(0,I.useSyncExternalStore)(t=>{let n=window.matchMedia(e);return n.addEventListener(`change`,t),()=>n.removeEventListener(`change`,t)},()=>window.matchMedia(e).matches,()=>!1),xf=()=>bf(`(min-width: 768px)`),Sf=()=>bf(`not all and (min-width: 640px)`),Cf=`data-pb-scroll-locked`,wf=()=>{let{body:e,documentElement:t}=document,n=e.style.overflow,r=t.hasAttribute(Cf);return window.innerWidth>t.clientWidth&&t.setAttribute(Cf,``),e.style.overflow=`hidden`,()=>{e.style.overflow=n,r||t.removeAttribute(Cf)}},Tf=`a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])`,Ef=[],Df=(e,t,n)=>{let r=(0,I.useRef)(n);r.current=n,(0,I.useEffect)(()=>{if(!t||!e.current)return;let n=e.current,i=document.activeElement instanceof HTMLElement?document.activeElement:null,a=wf(),o={};Ef.push(o);let s=()=>[...n.querySelectorAll(Tf)];(s()[0]??n).focus();let c=e=>{if(Ef.at(-1)!==o)return;if(e.key===`Escape`)return r.current();if(e.key!==`Tab`)return;let t=s();if(t.length===0)return e.preventDefault();let i=t[0],a=t[t.length-1];e.shiftKey&&document.activeElement===i?(e.preventDefault(),a.focus()):!e.shiftKey&&document.activeElement===a?(e.preventDefault(),i.focus()):n.contains(document.activeElement)||(e.preventDefault(),i.focus())};return document.addEventListener(`keydown`,c),()=>{document.removeEventListener(`keydown`,c),Ef.splice(Ef.indexOf(o),1),a(),i?.focus()}},[t,e])},Of=({title:e,description:t,onClose:n,actions:r,children:i,wide:a=!1,name:o})=>{let s=(0,I.useRef)(null);return Df(s,!0,n),(0,Cc.createPortal)((0,B.jsx)(`div`,{"data-dialog":o??``,className:`fixed inset-0 z-[90] flex items-center justify-center bg-backdrop/30 p-4 pb-[calc(1rem+var(--pb-safe-bottom))] pl-[calc(1rem+var(--pb-safe-left))] pr-[calc(1rem+var(--pb-safe-right))] pt-[calc(1rem+var(--pb-safe-top))]`,onMouseDown:e=>e.target===e.currentTarget&&n(),children:(0,B.jsxs)(`div`,{ref:s,tabIndex:-1,role:`dialog`,"aria-modal":`true`,"aria-label":e,className:P(`outline-none max-h-[min(90vh,100%)] w-full overflow-y-auto rounded-lg border bg-background p-4 shadow-pop sm:p-5`,a?`max-w-3xl`:`max-w-md`),children:[(0,B.jsx)(`h2`,{className:`text-[16px] font-semibold`,children:e}),t&&(0,B.jsx)(`p`,{className:`mt-1.5 text-muted-foreground`,children:t}),i&&(0,B.jsx)(`div`,{className:`mt-4`,children:i}),(0,B.jsx)(`div`,{className:`mt-5 flex flex-col-reverse gap-2 sm:flex-row sm:justify-end [&>*]:min-h-11 sm:[&>*]:min-h-0`,children:r})]})}),document.body)},kf=(e,t)=>t>=60&&t>Math.abs(e),Af=({title:e,open:t,onClose:n,children:r})=>{let i=(0,I.useRef)(null),a=(0,I.useRef)(void 0);return Df(i,t,n),t?(0,B.jsxs)(`div`,{className:`fixed inset-0 z-[80]`,children:[(0,B.jsx)(`div`,{className:`absolute inset-0 bg-backdrop/40`,onClick:n,"aria-hidden":!0}),(0,B.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`,children:[(0,B.jsxs)(`header`,{className:`relative flex shrink-0 touch-none items-center justify-between border-b px-4`,onPointerDown:e=>{e.pointerType===`touch`&&(a.current={x:e.clientX,y:e.clientY})},onPointerUp:e=>{if(!a.current)return;let t=kf(e.clientX-a.current.x,e.clientY-a.current.y);a.current=void 0,t&&n()},onPointerCancel:()=>a.current=void 0,children:[(0,B.jsx)(`span`,{className:`absolute left-1/2 top-1.5 h-1 w-9 -translate-x-1/2 rounded-full bg-border-strong`,"aria-hidden":!0}),(0,B.jsx)(`h2`,{className:`text-[16px] font-semibold`,children:e}),(0,B.jsx)(`button`,{type:`button`,"aria-label":rf(`close`),onClick:n,className:`-mr-2 inline-flex size-11 items-center justify-center rounded-md text-muted-foreground hover:bg-muted`,children:(0,B.jsx)(bc,{className:`size-5`})})]}),(0,B.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overscroll-contain px-4 pb-[calc(1.5rem+var(--pb-safe-bottom))]`,children:r})]})]}):null},jf=({title:e,description:t,open:n,onClose:r,actions:i,children:a,wide:o})=>{let s=xf();return n?s?(0,B.jsx)(Of,{title:e,description:t,onClose:r,actions:i,wide:o,children:a}):(0,B.jsx)(Af,{title:e,open:!0,onClose:r,children:(0,B.jsxs)(`div`,{className:`pt-3`,children:[t&&(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:t}),a&&(0,B.jsx)(`div`,{className:`mt-4`,children:a}),(0,B.jsx)(`div`,{className:`mt-5 flex flex-col-reverse gap-2 [&>*]:min-h-11`,children:i})]})}):null},Mf=e=>{let t=e.slice(1),n=t.length===3?[...t].map(e=>e+e).join(``):t,[r,i,a]=[0,2,4].map(e=>{let t=Number.parseInt(n.slice(e,e+2),16)/255;return t<=.03928?t/12.92:((t+.055)/1.055)**2.4});return .2126*r+.7152*i+.0722*a},Nf=`#ffffff`,Pf=`#111827`,Ff=e=>{let t=Mf(e);return 1.05/(t+.05)>=(t+.05)/(Mf(Pf)+.05)?Nf:Pf},If={neutral:`bg-muted text-muted-foreground`,blue:`bg-primary-soft text-primary-text`,green:`bg-success-soft text-success-text`,amber:`bg-warning-soft text-warning-text`,red:`bg-danger-soft text-danger-text`,violet:`bg-violet-soft text-violet-text`},Lf={neutral:`bg-faint-foreground`,blue:`bg-primary`,green:`bg-success`,amber:`bg-warning`,red:`bg-danger`,violet:`bg-violet`},Rf=`polygon(0 0, calc(100% - 0.625rem) 0, 100% 50%, calc(100% - 0.625rem) 100%, 0 100%)`,zf=({tone:e=`neutral`,dot:t=!0,color:n,shape:r,children:i,className:a})=>(0,B.jsxs)(`span`,{style:{...n!==void 0&&{backgroundColor:n,color:Ff(n)},...r===`arrow`&&{clipPath:Rf}},className:P(r===`arrow`?`inline-flex h-5 items-center gap-1.5 rounded-l-sm pr-4 pl-2 text-xs font-semibold whitespace-nowrap`:`inline-flex h-5 items-center gap-1.5 rounded-full px-2 text-xs font-medium whitespace-nowrap`,n===void 0&&If[e],a),children:[t&&n===void 0&&r===void 0&&(0,B.jsx)(`span`,{className:P(`size-1.5 rounded-full`,Lf[e])}),i]}),Bf={xs:`size-5 text-[9px]`,sm:`size-6 text-[10px]`,md:`size-8 text-xs`},Vf=({initials:e,hue:t,size:n=`sm`,className:r})=>(0,B.jsx)(`span`,{className:P(`inline-flex shrink-0 select-none items-center justify-center rounded-full font-semibold text-white ring-2 ring-background`,Bf[n],r),style:{background:`oklch(0.58 0.13 ${t})`},children:e}),Hf=({people:e,size:t=`sm`})=>(0,B.jsx)(`span`,{className:`inline-flex -space-x-1`,children:e.map(e=>(0,B.jsx)(Vf,{...e,size:t},e.initials))}),Uf=M(`record-view`),Wf=({collection:e,title:t,status:n,lastEditedBy:r,presence:i=[],actions:a})=>(0,B.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,B.jsxs)(`div`,{children:[e&&(0,B.jsx)(`p`,{className:`mb-1 text-xs text-muted-foreground`,children:e}),(0,B.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1`,children:[(0,B.jsx)(`h1`,{className:`text-xl font-semibold tracking-tight text-foreground md:text-2xl`,children:t}),n&&(0,B.jsx)(zf,{tone:n.tone,children:n.label})]}),r&&(0,B.jsx)(`p`,{className:`mt-1.5 text-xs text-muted-foreground`,children:r.name?(0,B.jsxs)(B.Fragment,{children:[Uf(`lastEditedBy`),` `,(0,B.jsx)(`span`,{className:`font-medium text-foreground`,children:r.name}),` `,r.ago]}):(0,B.jsx)(B.Fragment,{children:Uf(`lastUpdated`,{ago:r.ago})})})]}),(0,B.jsxs)(`div`,{className:`flex items-center gap-4`,children:[i.length>0&&(0,B.jsxs)(`span`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,B.jsx)(Hf,{people:i,size:`md`}),Uf(`viewing`,{count:i.length})]}),a]})]}),Gf=({title:e,help:t,actions:n,children:r})=>{let i=e?(0,B.jsx)(`h2`,{className:`text-[16px] font-semibold text-foreground`,children:e}):null;return(0,B.jsxs)(B.Fragment,{children:[n?(0,B.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-x-4 gap-y-2`,children:[i??(0,B.jsx)(`span`,{}),n]}):i,t&&(0,B.jsx)(`p`,{className:`mt-1 max-w-xl leading-6 text-muted-foreground`,children:t}),i||n||t?(0,B.jsx)(`div`,{className:`mt-5`,children:r}):r]})},Kf=({title:e,help:t,actions:n,children:r})=>(0,B.jsx)(`section`,{className:`py-8 first:pt-8`,children:(0,B.jsx)(Gf,{title:e,help:t,actions:n,children:r})}),qf=new Map,Jf=(e,t)=>{let n=Le(),r=`${n}|${e}`;return qf.has(r)||qf.set(r,t(n)),qf.get(r)},Yf=M(`format`),Xf=()=>Intl.DateTimeFormat().resolvedOptions().timeZone,Zf=new Map,Qf=e=>{let t=Zf.get(e);if(t)return t;let n=new Intl.DateTimeFormat(`en-US`,{timeZone:e,hourCycle:`h23`,year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`});return Zf.set(e,n),n},$f=(e,t)=>{let n=Object.fromEntries(Qf(t).formatToParts(e).map(e=>[e.type,e.value]));return{year:Number(n.year),month:Number(n.month),day:Number(n.day),hour:Number(n.hour),minute:Number(n.minute),second:Number(n.second)}},ep=(e,t)=>{let n=$f(e,t);return Date.UTC(n.year,n.month-1,n.day,n.hour,n.minute,n.second)-Math.floor(e/1e3)*1e3},tp=e=>String(e).padStart(2,`0`),np=(e,t)=>{let n=$f(e,t);return`${n.year}-${tp(n.month)}-${tp(n.day)}`},rp=(e,t)=>e-ep(e-ep(e,t),t),ip=(e,t)=>rp(Date.parse(`${e}T00:00:00Z`),t),ap=(e,t)=>{let n=Jf(`zoneName:${t}`,e=>new Intl.DateTimeFormat(e,{timeZone:t,timeZoneName:`shortOffset`})).formatToParts(e).find(e=>e.type===`timeZoneName`)?.value??t;return t===`UTC`||t===`Etc/UTC`?`UTC`:`${t} (${n})`},op=(e,t)=>()=>Jf(`date:${e}`,e=>new Intl.DateTimeFormat(e,{...t,timeZone:`UTC`})),sp=op(`day`,{day:`numeric`,month:`short`,year:`numeric`}),cp=op(`dayShort`,{day:`numeric`,month:`short`}),lp=op(`month`,{month:`long`,year:`numeric`}),up=op(`monthName`,{month:`long`}),dp=op(`weekday`,{weekday:`short`}),fp=op(`weekdayDate`,{weekday:`long`,day:`numeric`,month:`short`,year:`numeric`}),pp=e=>sp().format(e),mp=e=>cp().format(e),hp=e=>Jf(`zoned:${e}`,t=>({day:new Intl.DateTimeFormat(t,{day:`numeric`,month:`short`,year:`numeric`,timeZone:e}),time:new Intl.DateTimeFormat(t,{hour:`2-digit`,minute:`2-digit`,hour12:!1,timeZone:e})})),gp=(e,t=Xf())=>{let n=hp(t);return`${n.day.format(e)}, ${n.time.format(e)}`},_p=e=>lp().format(e),vp=e=>up().format(e),yp=(e,t)=>lp().formatRange(e,t),bp=e=>dp().format(e),xp=e=>fp().format(e),Sp=(e,t)=>sp().formatRange(e,t),Cp=(e,t=Xf())=>hp(t).time.format(e),wp=e=>e<60?Yf(`secondsAgo`,{count:e}):e<3600?Yf(`minutesAgo`,{count:Math.floor(e/60)}):e<86400?Yf(`hoursAgo`,{count:Math.floor(e/3600)}):Yf(`daysAgo`,{count:Math.floor(e/86400)}),Tp=()=>Jf(`relative`,e=>new Intl.RelativeTimeFormat(e,{numeric:`auto`})),Ep=[[`year`,31536e3],[`month`,2592e3],[`day`,86400],[`hour`,3600],[`minute`,60]],Dp=e=>{let t=Math.abs(e),[n,r]=Ep.find(([,e])=>t>=e)??[`second`,1];return n===`second`&&t<45?Yf(`justNow`):Tp().format(-Math.sign(e)*Math.floor(t/r),n)},Op=()=>Jf(`grouped`,e=>new Intl.NumberFormat(e)),kp=e=>Op().format(e),Ap=e=>e>0?`+${Op().format(e)}`:Op().format(e).replace(`-`,`−`),jp=e=>`${e}%`,Mp=e=>{if(e<1e4)return Yf(`rows`,{count:kp(e),n:e});let t=10**(Math.floor(Math.log10(e))-3);return Yf(`aboutRows`,{count:kp(Math.round(e/t)*t)})},Np=(e,t)=>Jf(`money:${e}:${t??``}`,n=>new Intl.NumberFormat(n,{style:`currency`,currency:e,...t!==void 0&&{minimumFractionDigits:t,maximumFractionDigits:t}})),Pp=(e,t,n)=>Np(t,n).format(e/100),Fp=M(`live`),Ip=e=>typeof e==`object`&&!!e&&typeof e.uri==`string`,Lp=e=>typeof e==`object`&&!!e&&typeof e.uploaded?.value==`string`,Rp=e=>{if(Lp(e))return{...e.uploaded.file,...e.preview&&{url:e.preview},corrected:e.uploaded.corrected};if(Ip(e))return`missing`in e?{name:Fp(`fileMissing`),type:``,missing:!0}:e},zp=[`bytes`,`kB`,`MB`,`GB`],Bp=e=>{let t=e,n=0;for(;t>=1e3&&n<zp.length-1;)t/=1e3,n+=1;return n===0?`${e} ${e===1?`byte`:`bytes`}`:`${t<10?t.toFixed(1):Math.round(t)} ${zp[n]}`},Vp=e=>e.startsWith(`image/`)&&e!==`image/svg+xml`,Hp=2,Up=1e5,Wp=(e,t)=>(e.width!==void 0||e.height!==void 0)&&(e.width??Up)>=t.width*Hp&&(e.height??Up)>=t.height*Hp,Gp=e=>(e.width??Up)*(e.height??Up),Kp=(e,t)=>{let n=Rp(e);if(!(!n||`missing`in n||!n.url||!Vp(n.type)))return{url:(`variants`in n&&n.variants?Object.values(n.variants):[]).filter(e=>Wp(e,t)).sort((e,t)=>Gp(e)-Gp(t))[0]?.url??n.url,...`placeholder`in n&&n.placeholder!==void 0&&{placeholder:n.placeholder}}},qp=e=>{let t=e.file?.accept??[];return t.length===0||t.includes(`*/*`)?void 0:t.join(`,`)},Jp=e=>Lp(e)?e.uploaded.value:Ip(e)?e.uri:null,Yp=(e,t)=>{if(Lp(e))return!0;let n=e=>Ip(e)?e.uri:null;return n(e)!==n(t)},Xp=M(`data-grid`),Zp=e=>typeof e==`object`&&e&&`name`in e?String(e.name):String(e),Qp=(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`${Pp(Number(t),e.currency,e.decimals)}${e.suffix??``}`;case`date`:return pp(Number(t));case`datetime`:return e.relative?Dp(Math.round((Date.now()-Number(t))/1e3)):gp(Number(t));case`number`:return`${e.prefix??``}${kp(Number(t))}${e.suffix??``}`;case`signed`:return`${e.prefix??``}${Ap(Number(t))}${e.suffix??``}`;case`percent`:return Number(t)===0?`—`:jp(Number(t));case`status`:return ar(String(t),e.labels);case`relation`:return Zp(t);case`boolean`:return t?void 0:Xp(`no`);case`file`:return Rp(t)?.name??`—`;case`user`:return e.users?.(String(t))?.name??String(t)}},$p=(e,t)=>Math.ceil(e.length*7.2)+24+(t?16:0)+28,em=e=>Math.ceil(Math.max(0,...e.map(e=>e.length))*7.2)+56,tm={body:7.5,mono:7.2,numeric:8},nm=24,rm=24,im=16,am=new Set([`status`,`money`,`number`,`signed`,`percent`,`date`,`datetime`,`boolean`]),om=new Set([`money`,`number`,`signed`,`percent`,`date`,`datetime`]),sm=80,cm=400,lm=240,um=e=>e===`id`?tm.mono:om.has(e)?tm.numeric:tm.body,dm=(e,t)=>e.value?e.value(t):t[e.id],fm=(e,t)=>{let n=t.map(t=>Qp(e,dm(e,t)));if(e.kind===`status`)return em(n.map(e=>e??``));let r=e.kind===`user`||e.kind===`file`?rm:0;return Math.max(0,...n.map(t=>t===void 0?im:Math.ceil(t.length*um(e.kind))))+r+nm},pm=(e,t,n)=>Math.min(n,Math.max(t,e)),mm=(e,t)=>{if(am.has(e.kind)&&!e.title)return{...e,fixed:!0,width:Math.max(e.minWidth??0,t)};let n={...e,fixed:!1,width:pm(t,sm,cm)};return e.kind===`id`?{...n,minWidth:Math.max($p(e.header,e.sortable??!1),Math.min(t,lm))}:n},hm=(e,t)=>{if(t.length===0)return e;let n=e.map(e=>e.render?e:mm(e,fm(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)},gm=e=>e.charAt(0).toUpperCase()+e.slice(1),_m=[[/^\s*(```|~~~).*$/,``],[/^\s*\[[^\]]+\]:\s+\S.*$/,``],[/^\s*([-*_]\s*){3,}$/,``],[/^\s*\|?(\s*:?-+:?\s*\|)+\s*:?-*:?\s*$/,``],[/^\s*#{1,6}\s+/,``],[/^\s*(>\s?)+/,``],[/^\s*([-*+]|\d+[.)])\s+(\[[ xX]\]\s+)?/,``]],vm=[[/!\[([^\]]*)\]\([^)]*\)/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`]],ym=200,bm=e=>{let t=e.split(/\r?\n/).map(e=>_m.reduce((e,[t,n])=>e.replace(t,n),e)),n=vm.reduce((e,[t,n])=>e.replace(t,n),t.join(`
|
|
3
|
+
`)).replace(/\s+/g,` `).trim();return n.length>ym?`${n.slice(0,199).trimEnd()}…`:n},xm=(e,t)=>e.type===`text`&&!!t?.markdown,Sm=(e,t,n)=>{let r=t[n];return e.fields[n]?.type===`relation`&&typeof r==`object`&&r&&`id`in r?r.id:r},Cm=(e,t)=>e.primaryKey.map(n=>String(Sm(e,t,n))).join(`,`),wm=(e,t)=>{let n=e.primaryKey.map(n=>Sm(e,t,n));return n.length===1?n[0]:n},Tm=new Set([`email`,`phone`,`url`]),Em=e=>e?.format!==void 0&&Tm.has(e.format)?e.format:void 0,Dm=(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},Om=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`}:{},km=(e,t)=>{let n=String(t);return e&&Object.hasOwn(e,n)?e[n]:void 0},Am=(e,t)=>{let n=km(e,t);return n===void 0||Mn(n)?void 0:n},jm=(e,t)=>{let n=km(e,t);return n!==void 0&&Mn(n)?n:`neutral`},Mm={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},Nm=new Set([`datetime`,`date`,`boolean`,`percent`]),Pm=(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`}},Fm=e=>Math.round(Number.parseFloat(String(e))*100),Im=(e,t,n=[],r=Er(e,t))=>{let i=lr(e,t);return r.flatMap((r,a)=>{let o=e.fields[r];if(!o)return[];let s=t?.fields[r],c=Pm(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??F(r),kind:c,width:(r===`name`?260:Mm[c])+d,sortable:o.sortable,minWidth:Math.max(c===`id`?150:0,$p(s?.label??F(r),o.sortable),c===`status`?em(Object.values(l)):0,d>0?Mm[c]+d:0),...Nm.has(c)&&{fixed:!0},...r===i&&{title:!0},...c===`text`&&r!==i&&Em(s)&&{link:Em(s)},...n.includes(r)&&{highlight:!0},...o.type===`enum`&&{tones:Object.fromEntries((o.enumValues??[]).map(e=>[e,jm(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:Fm(e[r])},...(c===`datetime`||c===`date`)&&{value:e=>e[r]==null?null:Date.parse(String(e[r]))},...xm(o,s)&&{value:e=>typeof e[r]==`string`?bm(e[r]):e[r]},...(c===`percent`||c===`number`&&o.type===`decimal`)&&{value:e=>e[r]==null?null:Number(e[r])}}]})},Lm=(e,t)=>`${t.prefix??``}${e}${t.suffix??``}`,Rm=(e,t,n={},r=Xf(),i=Date.now())=>{if(t==null||t===``)return`—`;switch(e.type){case`boolean`:return Fp(t?`yes`:`no`);case`file`:return Rp(t)?.name??`—`;case`enum`:return ar(String(t),n.valueLabels);case`timestamp`:{let e=Date.parse(String(t));return n.format===`relative`?Dp(Math.round((i-e)/1e3)):gp(e,r)}case`date`:return pp(Date.parse(String(t)));case`decimal`:{let e=n.decimals===void 0?String(t):Number(t).toFixed(n.decimals);return n.format===`percent`?`${Number(t)}%`:Lm(Number(e).toLocaleString(Le(),{minimumFractionDigits:n.decimals??0,maximumFractionDigits:n.decimals??20}),n)}case`integer`:case`bigint`:return Lm(String(t),n);default:return typeof t==`object`?JSON.stringify(t):String(t)}},zm=(e,t,n=Xf(),r={})=>{if(e.type!==`timestamp`||typeof t!=`string`)return;let i=Date.parse(t);if(!Number.isNaN(i))return r.format===`relative`?gp(i,n):Fp(`shownIn`,{zone:ap(i,n)})},Bm=`$photos`,Vm=e=>{for(let t of e?.list?.displays??[])if(t.kind===`cards`&&t.photos)return t.photos},Hm=(e,t,n)=>{if(n===void 0||e.primaryKey.length!==1)return t;let r=e.primaryKey[0];return t.map(e=>({...e,[Bm]:n[String(e[r])]??[]}))},Um=(e,t)=>t.filter(t=>e[t]!==null&&e[t]!==void 0&&e[t]!==``),K=M(`app/displays`),Wm=(e,t,n)=>{let r=e.fields[n.by];if(!r)return[];let i=t?.fields[n.by],a=(r.enumValues??[]).map(e=>({value:e,label:ar(e,i?.valueLabels)}));return r.nullable?[...a,{value:null,label:K(`noValue`,{label:i?.label??F(n.by)})}]:a},Gm=e=>e.position&&e.position.within===void 0?e.position.field:void 0,Km=(e,t,n)=>{let r=Yt(n===null?cn.isNull(t):cn.eq(t,n));return e===``?r:`(${e}) AND ${r}`},qm=(e,t,n)=>({kind:`cards`,name:n.name,title:n.title??lr(e,t),...n.subtitle!==void 0&&{subtitle:n.subtitle},...n.badge!==void 0&&{badge:n.badge},...n.meta&&{meta:n.meta}}),Jm=e=>{if(!ml(e))return e instanceof Error?e.message:K(`somethingWrong`);let t=e.errors.map(e=>e.message);return t.length>0?t.join(`; `):e.message},Ym=e=>e?.list?.displays??[],Xm=(e,t,n)=>{let r=n??e?.list?.default??`table`;if(!t)return r;let i=Ym(e).filter(e=>e.kind===`cards`);return i.find(e=>e.name===r)?.name??i[0]?.name??r},Zm=`rows`,Qm=(e,t)=>{if(Ym(t).some(e=>e.kind===`cards`||e.name===`rows`))return;let n=lr(e,t),r=Er(e,t).filter(t=>t!==n&&e.fields[t]!==void 0),i=r.find(t=>e.fields[t].type===`enum`),a=r.filter(t=>t!==i&&e.fields[t].type!==`boolean`).slice(0,2);return{kind:`cards`,name:Zm,label:K(`list`),icon:`list`,title:n,...i!==void 0&&{badge:i},footer:a}},$m=(e,t)=>t.name===`rows`&&!Ym(e).some(e=>e.name===`rows`),eh=(e,t,n)=>{let r=Xm(t,n);return n&&r===`table`&&Qm(e,t)?Zm:r},th=(e,t,n)=>(n===`rows`?Qm(e,t):void 0)??nh(t,n),nh=(e,t)=>{if(t===`table`)return;let n=t=>Ym(e).find(e=>e.name===t);return n(t)??n(e?.list?.default)},rh={cards:`cards`,map:`map`,board:`kanban`,calendar:`calendar`,timeline:`timeline`},ih=e=>[{name:yn,label:K(`table`),icon:`table`},...Ym(e).map(e=>({name:e.name,label:e.label??F(e.name),icon:e.icon??rh[e.kind]}))],ah=(e,t,n)=>{let r=ih(t);return n&&Qm(e,t)?[...r,{name:Zm,label:K(`list`),icon:`list`}]:r},oh=(e,t,n)=>({image:n.image,title:n.title??lr(e,t),subtitle:n.subtitle,amount:n.amount??[],badge:n.badge,meta:n.meta??[],footer:n.footer??[],flags:n.flags??[]}),sh=(e,t)=>Um(e.record,t),ch=(e,t)=>sh(e,t)[0],lh=(e,t,n={})=>{let{suffix:r,...i}=n;return e.type!==`decimal`&&e.type!==`integer`&&e.type!==`bigint`||r===void 0||n.format===`percent`?{amount:Rm(e,t,n)}:{amount:Rm(e,t,i),suffix:r}},uh=(e,t)=>{let n=Ym(e).filter(e=>e.kind===`cards`);return(t.cards===void 0?n[0]:n.find(e=>e.name===t.cards))??{kind:`cards`,name:t.name}},dh=(e,t,n)=>{if(n.kind===`custom`)return n.fields;if(n.kind===`map`)return[n.latitude,n.longitude,...dh(e,t,uh(t,n))];if(n.kind===`board`){let r=qm(e,t,n);return[n.by,r.title,r.subtitle,r.badge,...r.meta??[]].filter(e=>e!==void 0)}if(n.kind===`calendar`)return[n.start,n.end,n.title??lr(e,t)].filter(e=>e!==void 0);if(n.kind===`timeline`)return[n.start,n.end,n.group,n.title??lr(e,t)].filter(e=>e!==void 0);let{image:r,title:i,subtitle:a,amount:o,badge:s,meta:c,footer:l,flags:u}=oh(e,t,n);return[r,i,a,...o,s,...c,...l,...u].filter(e=>e!==void 0)},fh=(e,t,n)=>{let r=Qm(e,t),i=r?[...Ym(t),r]:Ym(t);return[...new Set([...n,...i.flatMap(n=>dh(e,t,n))])]},ph=(e,t,n)=>{let r=$m(t,n)?[lr(e,t),...Er(e,t)]:dh(e,t,n);return[...new Set(r)].filter(t=>e.fields[t]?.sortable)},mh=e=>typeof e==`object`&&!!e&&`id`in e&&`name`in e,hh=(e,t)=>{let n={},r={},i=Array.isArray(t.$photos)?t[Bm]:void 0;for(let[i,a]of Object.entries(t))(i!==`id`&&i!==`$photos`||Object.hasOwn(e.fields,i))&&(e.fields[i]?.type===`relation`&&mh(a)?(n[i]=a.id,r[i]=a.name):n[i]=a);return{key:Nn(wm(e,n)),record:n,labels:r,...i&&{photos:i}}},gh=(e,t)=>{let n=t?.list?.sort?.[0];if(n)return`${n[0]} ${n[1]}`;let r=e.primaryKey[0];return e.fields[r]?.sortable?`${r} asc`:``},_h=e=>{let[t=``,n]=e.trim().split(/\s+/);return{columnId:t,direction:n===`desc`?`desc`:`asc`}},vh=e=>`${e.columnId} ${e.direction}`,yh=(e,t,n,r)=>{let i=e[n],a=Cn(t[n],r),o=a?.listOf,s=o===void 0?void 0:i?.fields[o]?.relation?.resource;return s!==void 0&&e[s]?{model:e[s],view:t[s],listOf:!0}:{model:i,view:a,listOf:!1}},bh=(e,t,n=!1)=>({display:e?eh(e,t,n):Xm(t,n),orderBy:e?gh(e,t):``,filterLayout:`bar`,filter:t?.list?.filter??``}),xh=(e,t)=>e?.kind===`record`?{kind:`record`,resource:e.resource,key:Nn(e.key),...e.edit&&{edit:!0},...e.open&&{open:e.open},...e.tab&&{tab:e.tab},...e.standard&&{standard:!0},...e.call&&{call:e.call}}:e?.kind===`list`?{...t(e.resource,e.list),...e}:e,Sh=(e,t,n)=>{let r={...e,...t},i=e=>r[e]!==void 0&&r[e]!==n[e];return{kind:`list`,resource:e.resource,...e.list&&{list:e.list},...i(`filter`)&&{filter:r.filter},...i(`display`)&&{display:r.display},...i(`orderBy`)&&{orderBy:r.orderBy},...i(`filterLayout`)&&{filterLayout:r.filterLayout},...r.map&&{map:r.map},...r.calendar&&{calendar:r.calendar},...r.timeline&&{timeline:r.timeline},...r.savedSearch&&{savedSearch:r.savedSearch}}},Ch=({className:e})=>(0,B.jsx)(`span`,{className:P(`block h-3 rounded bg-muted [animation:pb-shimmer_1.4s_ease-in-out_infinite]`,e)}),wh=M(`app-shell`),Th=e=>e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey,Eh=({parts:e,onNavigate:t})=>(0,B.jsx)(`nav`,{"aria-label":wh(`breadcrumb`),className:`flex min-w-0 items-center gap-1.5`,children:e.map((n,r)=>{let i=r===e.length-1,{label:a,href:o,loading:s}=typeof n==`string`?{label:n,href:void 0,loading:!1}:n,c=s?(0,B.jsx)(Ch,{className:`w-24`}):a,l=P(`truncate`,i?`font-semibold`:`text-muted-foreground`);return(0,B.jsxs)(`span`,{className:P(`min-w-0 items-center gap-1.5`,i?`flex`:`hidden md:flex`),children:[r>0&&(0,B.jsx)(ki,{className:`hidden size-3.5 shrink-0 text-faint-foreground md:block`}),o?(0,B.jsx)(`a`,{href:o,"aria-current":i?`page`:void 0,"aria-label":s?a:void 0,"aria-busy":s||void 0,onClick:e=>{t&&Th(e)&&(e.preventDefault(),t(o))},className:P(l,`rounded-sm hover:text-foreground hover:underline`),children:c}):(0,B.jsx)(`span`,{className:l,"aria-label":s?a:void 0,"aria-busy":s||void 0,children:c})]},`${r}-${a}`)})}),Dh=({to:e,onClick:t,...n})=>{let{href:r,onFollow:i,newTab:a}=e;return(0,B.jsx)(`a`,{href:r,...a&&{target:`_blank`,rel:`noreferrer`},onClick:e=>{t?.(e),i&&!e.defaultPrevented&&Th(e)&&(e.preventDefault(),i())},...n})},q=M(`app`),Oh=`protobase:page-places`,kh=50,Ah=e=>Array.isArray(e)&&e.length===2&&typeof e[0]==`string`&&typeof e[1]==`number`&&Number.isFinite(e[1])&&e[1]>=0,jh=e=>Ie(()=>{let t=e.getItem(Oh);if(t===null)return[];let n=JSON.parse(t);return Array.isArray(n)?n.filter(Ah):[]},[]),Mh=e=>{let t=new Map(jh(e));return{placeOf:e=>t.get(e)??0,save:(e,n)=>{t.delete(e),t.set(e,Math.max(0,Math.round(n)));for(let e of[...t.keys()].slice(0,Math.max(0,t.size-kh)))t.delete(e)},persist:()=>Ie(()=>e.setItem(Oh,JSON.stringify([...t])),void 0)}},Nh=3e3,Ph=e=>{let t=0,n=()=>(window.scrollTo({top:e,behavior:`instant`}),t=window.scrollY,t>=e-1);if(n())return()=>{};let r=new ResizeObserver(()=>n()&&a()),i=()=>Math.abs(window.scrollY-t)>1&&a(),a=()=>{r.disconnect(),clearTimeout(o),window.removeEventListener(`scroll`,i)},o=setTimeout(a,Nh);return r.observe(document.body),window.addEventListener(`scroll`,i,{passive:!0}),a},Fh=(0,I.createContext)(null),Ih=()=>{let e=(0,I.useContext)(Fh);if(!e)throw Error(`useRouter must be used inside Router`);return e},Lh=()=>`${window.location.pathname}${window.location.search}`,Rh=e=>new URL(e,`http://local`).pathname,zh=()=>window.history.state??{},Bh=()=>zh().protobaseIndex??0,Vh=()=>Math.random().toString(36).slice(2),Hh=()=>{let e=zh();if(e.protobaseEntry)return e.protobaseEntry;let t=Vh();return window.history.replaceState({...e,protobaseEntry:t},``),t},Uh={getItem:()=>null,setItem:()=>{}},Wh=({basePath:e=``,initialUrl:t,children:n})=>{let r=t!==void 0,[i,a]=(0,I.useState)(()=>({url:t??Lh(),entry:r?Vh():Hh()})),[o]=(0,I.useState)(()=>Mh(r?Uh:Ie(()=>window.sessionStorage,void 0)??Uh)),s=(0,I.useRef)(new Map),c=()=>[...s.current.values()].includes(`input-lost`),l=(0,I.useRef)(i);l.current=i;let u=(0,I.useRef)(r?0:Bh()),d=(0,I.useRef)(!1),f=(0,I.useRef)(!1),p=(0,I.useRef)(void 0),m=(0,I.useRef)(!1),[h,g]=(0,I.useState)(),_=(0,I.useCallback)(()=>o.save(l.current.entry,window.scrollY),[o]);(0,I.useLayoutEffect)(()=>Ph(o.placeOf(i.entry)),[o,i.entry]),(0,I.useEffect)(()=>{if(r)return;window.history.scrollRestoration=`manual`,window.history.replaceState({...zh(),protobaseIndex:u.current,protobaseEntry:l.current.entry},``);let e=()=>{_(),o.persist()},t=()=>document.visibilityState===`hidden`&&e();window.addEventListener(`pagehide`,e),document.addEventListener(`visibilitychange`,t);let n=()=>{let e=Bh();if(d.current){d.current=!1,u.current=e,p.current!==void 0&&window.history.go(p.current),p.current=void 0;return}let t=e-u.current,n=Rh(Lh())!==Rh(l.current.url);if(!f.current&&s.current.size>0&&n){d.current=!0,window.history.go(-t),g({kind:`history`,delta:t,inputLost:c()});return}f.current=!1,u.current=e,_(),a({url:Lh(),entry:Hh()})};return window.addEventListener(`popstate`,n),()=>{window.removeEventListener(`popstate`,n),window.removeEventListener(`pagehide`,e),document.removeEventListener(`visibilitychange`,t)}},[r,_,o]);let v=(0,I.useCallback)((e,t)=>{let n=t?l.current.entry:Vh();if(!r){u.current+=+!t;let r=t?zh().protobasePrevious:l.current.url;window.history[t?`replaceState`:`pushState`]({protobaseIndex:u.current,protobaseEntry:n,protobasePrevious:r},``,e)}_(),a({url:e,entry:n})},[r,_]),y=(0,I.useCallback)((t,{replace:n=!1}={})=>{let r=`${e}${t}`;if(Rh(r)!==Rh(l.current.url)&&s.current.size>0)return g({kind:`link`,full:r,replace:n,inputLost:c()});v(r,n)},[e,v]),b=(0,I.useCallback)(t=>{let n=r?void 0:zh().protobasePrevious;if(n!==void 0&&Rh(n)===Rh(`${e}${t}`))return window.history.back();y(t)},[r,e,y]),x=(0,I.useCallback)((e=`draft-kept`)=>{let t=Symbol(`guard`);return s.current.set(t,e),()=>void s.current.delete(t)},[]),S=(0,I.useCallback)(()=>{if(s.current.size>0)return g({kind:`reload`,inputLost:c()});window.location.reload()},[]),C=(0,I.useCallback)(()=>m.current,[]),w=()=>{if(h){if(g(void 0),h.kind===`link`)return v(h.full,h.replace);if(h.kind===`reload`)return m.current=!0,window.location.reload();f.current=!0,d.current?p.current=h.delta:window.history.go(h.delta)}},T=(0,I.useMemo)(()=>{let t=new URL(i.url,`http://local`);return{path:t.pathname.slice(e.length)||`/`,params:t.searchParams,basePath:e,entry:i.entry,navigate:y,back:b,registerGuard:x,reload:S,reloadConfirmed:C}},[i,e,y,b,x,S,C]);return(0,B.jsxs)(Fh.Provider,{value:T,children:[n,h?.kind===`reload`&&(0,B.jsx)(Of,{title:q(`reloadTitle`),description:q(h.inputLost?`reloadInputLost`:`reloadDraftKept`),onClose:()=>g(void 0),actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:()=>g(void 0),children:q(`keepEditing`)}),(0,B.jsx)(G,{variant:`primary`,onClick:w,children:q(`reload`)})]})}),h&&h.kind!==`reload`&&(0,B.jsx)(Of,{title:q(`leaveTitle`),description:q(h.inputLost?`leaveInputLost`:`leaveDescription`),onClose:()=>g(void 0),actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:()=>g(void 0),children:q(`stay`)}),(0,B.jsx)(G,{variant:`primary`,onClick:w,children:q(`leave`)})]})})]})},Gh=({to:e,replace:t,...n})=>{let{navigate:r,basePath:i}=Ih();return(0,B.jsx)(Dh,{to:{href:`${i}${e}`,onFollow:()=>r(e,{replace:t})},...n})},Kh=(e,t=`draft-kept`)=>{let{registerGuard:n,reloadConfirmed:r}=Ih();(0,I.useEffect)(()=>e?n(t):void 0,[e,t,n]),(0,I.useEffect)(()=>{if(!e)return;let t=e=>{r()||e.preventDefault()};return window.addEventListener(`beforeunload`,t),()=>window.removeEventListener(`beforeunload`,t)},[e,r])},qh=()=>{let{path:e,params:t,basePath:n,navigate:r,back:i}=Ih(),{pages:a,resources:o,views:s}=W(),c=Sf(),l=(0,I.useMemo)(()=>new Set(Object.keys(a)),[a]),u=t.toString(),d=(0,I.useMemo)(()=>Gc(u?`${e}?${u}`:e,l),[e,u,l]),f=(0,I.useCallback)((e,t)=>{let n=yh(o,s,e,t);return bh(n.model,n.view,c)},[o,s,c]),p=(0,I.useMemo)(()=>xh(d,f),[d,f]),m=(0,I.useCallback)((e,t)=>r(Vc(e),t),[r]),h=(0,I.useCallback)(e=>{if(d?.kind!==`list`)throw Error(`listTo and set change the list the app shows; use go to move to another address`);return Sh(d,e,f(d.resource,d.list))},[d,f]),g=(0,I.useCallback)(e=>m(h(e),{replace:!0}),[h,m]),_=(0,I.useCallback)(e=>Vc(e,n),[n]),v=(0,I.useCallback)(e=>e.startsWith(`${n}/`)?e.slice(n.length):e,[n]);return{address:p,set:g,listTo:h,go:m,href:_,open:(0,I.useCallback)(e=>r(v(e)),[v,r]),back:(0,I.useCallback)(e=>i(v(e)),[v,i])}},Jh=({to:e,...t})=>(0,B.jsx)(Gh,{to:Vc(e),...t}),Yh=`text-[16px] font-semibold text-foreground`,Xh=({title:e,open:t,toggle:n,children:r})=>{let i=(0,I.useId)();return(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`h2`,{className:P(`py-8`,t&&`pb-0`),children:n?(0,B.jsxs)(Jh,{to:n,replace:!0,"aria-expanded":t,"aria-controls":i,className:P(`inline-flex items-center gap-1.5`,Yh),children:[(0,B.jsx)(ki,{className:P(`size-4 transition-transform`,t&&`rotate-90`)}),e]}):(0,B.jsx)(`span`,{className:Yh,children:e})}),t&&(0,B.jsx)(`div`,{id:i,className:`divide-y divide-border`,children:r})]})},Zh=({tabs:e})=>(0,B.jsx)(`nav`,{"aria-label":Uf(`tabs`),className:`overflow-x-auto py-6`,children:(0,B.jsx)(`span`,{className:ze.group(`md`),children:e.map(e=>(0,B.jsx)(Jh,{to:e.to,replace:!0,"aria-current":e.current?`page`:void 0,className:P(ze.option(e.current,`md`),`whitespace-nowrap`),children:e.title},e.title))})}),Qh=(0,I.createContext)(void 0),$h=()=>{let e=(0,I.useContext)(Qh);return e?{id:e.id,name:e.name,"aria-describedby":e.describedBy,"aria-invalid":e.invalid||void 0,"aria-required":e.required||void 0}:{}},eg=({name:e,label:t,required:n,help:r,example:i,error:a,conflict:o,wide:s,children:c})=>{let l=(0,I.useId)(),u=[r&&`${l}-help`,i&&`${l}-example`,a&&`${l}-error`].filter(Boolean).join(` `)||void 0;return(0,B.jsxs)(`div`,{className:s?`sm:col-span-2`:void 0,children:[(0,B.jsxs)(`div`,{className:`mb-1.5 flex items-center gap-2`,children:[(0,B.jsxs)(`label`,{htmlFor:l,className:`font-medium text-foreground`,children:[t,n&&(0,B.jsx)(`span`,{className:`ml-0.5 text-danger-text`,"aria-hidden":`true`,children:`*`})]}),o&&(0,B.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-warning-text`,title:Uf(`savedDifferent`,{name:o.user.name}),children:[(0,B.jsx)(Xs,{className:`size-3.5`}),(0,B.jsx)(Vf,{initials:o.user.initials,hue:o.user.hue,size:`xs`})]})]}),(0,B.jsx)(Qh,{value:{id:l,name:e,describedBy:u,invalid:!!a,required:!!n},children:c}),r&&(0,B.jsx)(`p`,{id:`${l}-help`,className:`mt-1.5 text-xs text-muted-foreground`,children:r}),i&&(0,B.jsxs)(`p`,{id:`${l}-example`,className:`mt-0.5 text-xs text-faint-foreground`,children:[Uf(`example`),` `,i]}),a&&(0,B.jsx)(`p`,{id:`${l}-error`,className:`mt-1.5 text-body font-medium text-danger-text`,children:a}),o&&(0,B.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,B.jsxs)(`span`,{children:[(0,B.jsx)(`strong`,{children:o.user.name}),` `,Uf(`savedThis`,{ago:o.ago}),` `,(0,B.jsx)(`strong`,{children:o.theirValue})]}),(0,B.jsxs)(`span`,{className:`flex gap-1.5`,children:[(0,B.jsx)(G,{size:`sm`,onClick:o.onKeepMine,children:Uf(`keepMine`)}),(0,B.jsx)(G,{size:`sm`,onClick:o.onUseTheirs,children:Uf(`useTheirs`)})]})]})]})},tg=({rows:e})=>(0,B.jsx)(`dl`,{className:`border-t border-border`,children:e.map(e=>(0,B.jsxs)(`div`,{className:P(`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,B.jsxs)(`dt`,{className:`min-w-0 text-muted-foreground`,children:[e.label,e.help&&(0,B.jsx)(`span`,{className:`mt-0.5 block text-xs text-faint-foreground`,children:e.help})]}),(0,B.jsx)(`dd`,{className:`min-w-0 break-words text-foreground`,children:e.value})]},e.label))}),ng=({facts:e})=>(0,B.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,B.jsxs)(`div`,{title:e,className:`flex min-w-0 flex-col gap-1.5`,children:[(0,B.jsx)(`dt`,{className:`text-muted-foreground`,children:n?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(n,{className:`size-5`,"aria-hidden":!0}),(0,B.jsx)(`span`,{className:`sr-only`,children:e})]}):e}),(0,B.jsx)(`dd`,{className:`min-w-0 break-words text-[16px] font-semibold text-foreground`,children:t})]},e))}),rg=`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`,ig=({actions:e})=>(0,B.jsxs)(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:[(0,B.jsx)(`h3`,{className:`hidden border-b border-border px-4 py-2.5 text-xs font-semibold uppercase tracking-wide text-muted-foreground md:block`,children:Uf(`actions`)}),(0,B.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,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(n,{className:P(`size-4 shrink-0 md:mt-0.5`,o===`danger`?`text-danger-text`:`text-muted-foreground`),"aria-hidden":!0}),(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`span`,{className:P(`block font-medium`,o===`danger`?`text-danger-text`:`text-foreground`),children:e}),t&&(0,B.jsx)(`span`,{className:`mt-0.5 hidden text-xs leading-snug text-muted-foreground md:block`,children:t})]})]});return(0,B.jsx)(`li`,{children:s?s({className:rg,children:c}):(0,B.jsx)(`button`,{type:`button`,onClick:r,disabled:!!i||a,title:i,className:rg,children:c})},e)})})]}),ag=`flex w-full items-center gap-2 px-3 py-2.5 text-left hover:bg-muted disabled:cursor-default disabled:opacity-60`,og=4,sg=(e,t,n)=>{let r=e.bottom+og;return{top:r+t.height>window.innerHeight-og?Math.max(og,e.top-og-t.height):r,right:Math.max(og,Math.min(n-e.right,n-og-t.width))}},cg=()=>{let[e,t]=(0,I.useState)(!1),[n,r]=(0,I.useState)(),i=(0,I.useRef)(null),a=(0,I.useRef)(null);return(0,I.useLayoutEffect)(()=>{if(!e||!i.current||!a.current){r(void 0);return}a.current.style.right=`0px`;let t=a.current.getBoundingClientRect().right;r(sg(i.current.getBoundingClientRect(),{width:a.current.offsetWidth,height:a.current.offsetHeight},t))},[e]),(0,I.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}},lg=({actions:e,label:t=Uf(`actions`),className:n})=>{let{open:r,setOpen:i,place:a,button:o,menu:s}=cg();return e.length===0?null:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`button`,{ref:o,type:`button`,"aria-label":t,"aria-haspopup":`menu`,"aria-expanded":r,onClick:()=>i(!r),className:n,children:(0,B.jsx)(sa,{className:`size-5`})}),r&&(0,Cc.createPortal)((0,B.jsx)(`ul`,{ref:s,role:`menu`,"aria-label":t,style:a??{visibility:`hidden`},className:`fixed z-50 min-w-48 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,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(t,{className:P(`size-4 shrink-0`,o===`danger`?`text-danger-text`:`text-muted-foreground`),"aria-hidden":!0}),(0,B.jsx)(`span`,{className:P(`font-medium`,o===`danger`&&`text-danger-text`),children:e})]});return(0,B.jsx)(`li`,{role:`none`,onClick:()=>i(!1),children:s?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,B.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)]})},ug=({rows:e})=>(0,B.jsx)(`dl`,{className:`grid grid-cols-[auto_minmax(0,1fr)] gap-x-4 gap-y-2`,children:e.map(e=>(0,B.jsxs)(`div`,{className:`contents`,children:[(0,B.jsx)(`dt`,{className:`text-muted-foreground`,children:e.label}),(0,B.jsx)(`dd`,{title:e.title,className:`truncate text-right tabular-nums text-foreground`,children:e.value})]},e.label))}),dg=({title:e,children:t})=>(0,B.jsxs)(`div`,{className:`rounded-lg border border-border bg-background p-4`,children:[(0,B.jsx)(`h3`,{className:`mb-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground`,children:e}),t]}),fg=({title:e,rows:t})=>t.length===0?null:(0,B.jsx)(dg,{title:e,children:(0,B.jsx)(ug,{rows:t})}),pg=(e=Le())=>new Intl.NumberFormat(e).formatToParts(1.5).find(e=>e.type===`decimal`)?.value===`,`?`,`:`.`,mg=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),hg=(e,t)=>{let n=`[${mg(t===`.`?`,`:`.`)}\\s\\u00a0\\u202f']`,r=RegExp(`^([-+]?)(\\d{1,3}(?:${n}\\d{3})+|\\d+)(?:${mg(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()))},gg=e=>e==null?``:typeof e==`object`?JSON.stringify(e):String(e),_g=new Set([`text`,`integer`,`bigint`,`decimal`,`date`,`currency`,`country`]),vg=new Set([`uuid`,`timestamp`,`relation`]),yg=(e,t)=>e.readOnly||vg.has(e.type)?!1:e.type!==`json`||t?.widget!==void 0,bg=e=>!e.readOnly&&!e.nullable&&e.type!==`boolean`,xg=new Set([`integer`,`bigint`,`decimal`]),Sg=e=>{try{return JSON.parse(e)}catch(t){if(t instanceof SyntaxError)return e;throw t}},Cg=(e,t)=>hg(e,t)??e,wg=(e,t,n=pg())=>{if(e.type===`boolean`)return!!t;if(e.type===`file`)return Jp(t);let r=String(t).trim();if(r===``)return e.nullable?null:``;let i=xg.has(e.type)?Cg(r,n):r;if(e.type===`integer`)return Number(i);if(e.type===`relation`)return typeof t==`number`?t:i;if(_g.has(e.type)||e.type===`enum`)return i;if(e.type===`json`)return Sg(i);throw Error(`Not implemented: editing ${e.type} fields`)},Tg=(e,t,n=pg())=>e.type===`boolean`?!!t:String(t??``).trim()===``?null:wg(e,t,n),Eg=(e,t)=>e.type===`boolean`?!!t:gg(t),Dg=(e,t,n,r=pg())=>{if(e.type===`boolean`)return!!t!=!!n;if(e.type===`file`)return Yp(t,n);let i=String(t??``).trim(),a=gg(n);return e.type===`decimal`||e.type===`integer`?i===``||a===``?i!==a:Number(Cg(i,r))!==Number(a):i!==a},Og=(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},kg=(e,t,n)=>(e??t?.helpWhen??`always`)===`always`||n,Ag=(e,t,n)=>e?.help!==void 0&&kg(e.helpWhen,t,n)?e.help:void 0,jg=(e,t)=>e===`editing`?t:e!==`reading`||!t,Mg=M(`app/create`),Ng=e=>typeof e==`object`&&!!e&&`key`in e,Pg=(e,t,n)=>t.name!==e.tenant&&!t.readOnly&&(t.type===`relation`||yg(t,n)),Fg=(e,t)=>{let n=Object.values(e.fields).filter(n=>Pg(e,n,t?.fields[n.name])).map(e=>e.name),r=new Set,i=Sn(t?.layout??[]).flatMap(e=>{if(e.kind!==`section`||Ac(e.when)||!jg(e.when,!0))return[];let i=e.fields.filter(e=>n.includes(e)&&!r.has(e)&&jg(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?Mg(`details`):Mg(`otherFields`),fields:a}]},Ig=(e,t)=>(e?.primaryKey.length===1?e.fields[e.primaryKey[0]]?.type:void 0)===`integer`?Number(t):t,Lg=(e,t,n)=>Object.fromEntries(Object.entries(n).flatMap(([n,r])=>{let i=e.fields[n];return i?Ng(r)?[[n,Ig(t[i.relation?.resource??``],r.key)]]:i.type===`boolean`?[[n,!!r]]:i.type===`file`?r?[[n,wg(i,r)]]:[]:String(r).trim()===``?[]:[[n,wg(i,r)]]:[]})),Rg=e=>!e.nullable&&!e.default&&e.type!==`boolean`,zg=(e,t)=>e.type===`relation`?{key:t,label:t}:e.type===`boolean`?t===`true`:t,Bg=new Set([`integer`,`bigint`,`decimal`]),Vg=e=>{if(!Bg.has(e.type)||!e.default||!(`value`in e.default))return;let t=e.default.value;return t==null?void 0:String(t)},Hg=(e,t,n={})=>Object.fromEntries(t.flatMap(t=>t.fields.flatMap(t=>{let r=e.fields[t];if(Object.hasOwn(n,t))return[[t,zg(r,n[t])]];let i=r.default;return Vg(r)!==void 0||!i||!(`value`in i)||i.value===null||i.value===void 0?[]:[[t,typeof i.value==`boolean`?i.value:gg(i.value)]]}))),Ug=e=>!!(e.default&&`db`in e.default),Wg=e=>{if(!ml(e))return[{message:e instanceof Error?e.message:q(`somethingWentWrong`)}];let t=e.errors.map(e=>({message:e.message,hint:e.hint}));return t.length>0?t:[{message:e.message}]},Gg=({error:e,title:t})=>(0,B.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,B.jsx)(Xs,{className:`mt-0.5 size-4 shrink-0`}),(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`p`,{className:`font-medium`,children:t}),Wg(e).map(e=>(0,B.jsxs)(`p`,{className:`text-body`,children:[e.message,e.hint&&(0,B.jsxs)(`span`,{className:`text-muted-foreground`,children:[` `,e.hint]})]},e.message))]})]}),Kg=({checked:e,onChange:t,label:n})=>{let r=$h();return(0,B.jsx)(`button`,{type:`button`,role:`switch`,id:r.id,"aria-describedby":r[`aria-describedby`],"aria-checked":e,"aria-label":n,onClick:()=>t?.(!e),className:P(`relative inline-flex h-5 w-9 shrink-0 items-center rounded-full transition-colors`,e?`bg-primary`:`bg-border-strong`),children:(0,B.jsx)(`span`,{className:P(`size-4 rounded-full bg-white shadow transition-transform`,e?`translate-x-[18px]`:`translate-x-0.5`)})})},J=({leading:e,trailing:t,invalid:n,className:r,wrapperClassName:i,...a})=>{let o=$h();return(0,B.jsxs)(`span`,{className:P(`flex h-8 items-center gap-2 rounded-md border bg-background px-2.5 text-muted-foreground shadow-sm focus-within:border-primary focus-within:ring-2 focus-within:ring-primary/20`,n?`border-danger`:`border-border-strong`,i),children:[e,(0,B.jsx)(`input`,{className:P(`min-w-0 flex-1 bg-transparent text-body text-foreground outline-none placeholder:text-faint-foreground`,r),...o,...n&&{"aria-invalid":!0},...a}),t]})},qg=e=>{e.style.height=`auto`,e.style.height=`${e.scrollHeight+e.offsetHeight-e.clientHeight}px`},Jg=({invalid:e,className:t,rows:n=3,value:r,ref:i,...a})=>{let o=(0,I.useRef)(null),s=(0,I.useCallback)(e=>{o.current=e,typeof i==`function`?i(e):i&&(i.current=e)},[i]),c=$h();return(0,I.useLayoutEffect)(()=>{o.current&&qg(o.current)},[r]),(0,I.useEffect)(()=>{let e=o.current;if(!e)return;let t=e.clientWidth,n=new ResizeObserver(()=>{e.clientWidth!==t&&(t=e.clientWidth,qg(e))});return n.observe(e),()=>n.disconnect()},[]),(0,B.jsx)(`textarea`,{ref:s,rows:n,value:r,className:P(`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})},Yg=(e,{filter:t,orderBy:n,pageSize:r=50,fields:i,labels:a,startToken:o=``,enabled:s=!0,refetchInterval:c}={})=>{let l=U(),u=tl(t)??``,d=Ne({queryKey:[...H.list(e,u,n??``,r,o),i?.join(`,`)??``,...a?[a]:[]],enabled:s,refetchInterval:c,initialPageParam:o,queryFn:({pageParam:t})=>l.list(e,{filter:u,orderBy:n,pageSize:r,fields:i,labels:a,pageToken:t}),getNextPageParam:e=>e.nextPageToken||void 0}),f=d.data?.pages??[];return{...d,items:f.flatMap(e=>e.items),totalEstimate:f[0]?.totalSizeEstimate,labels:Object.fromEntries(Object.keys(a??{}).map(e=>[e,Object.assign({},...f.map(t=>t.labels?.[e]??{}))]))}},Xg=()=>{let[e,t]=(0,I.useState)(``),[n,r]=(0,I.useState)(!1);return{text:e,setText:t,open:n,setOpen:r}},Zg=(e,t,n,r)=>{(0,I.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])},Qg=({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,I.useState)(-1),[_,v]=(0,I.useState)(null),[y,b]=(0,I.useState)(null),x=(0,I.useId)(),S=s?.more??!1;Zg(_,y,s?.loaded??0,s?.loadMore);let C=e=>`${x}-${e}`,w=(0,I.useRef)(null);(0,I.useEffect)(()=>{!p&&document.activeElement===w.current&&w.current?.select()},[p]),(0,I.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,B.jsxs)(`div`,{className:`relative`,children:[(0,B.jsx)(J,{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,B.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,B.jsx)(`li`,{id:C(t),role:`option`,"aria-selected":t===h,className:P(`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,B.jsx)(`li`,{ref:b,"aria-hidden":!0,className:`h-px`}),l&&(0,B.jsx)(`li`,{className:`px-3 py-1.5 text-muted-foreground`,children:q(`couldNotLoadOptions`)}),!S&&!c&&!l&&t.length===0&&(0,B.jsx)(`li`,{className:`px-3 py-1.5 text-muted-foreground`,children:q(`noMatches`)}),c&&(0,B.jsx)(`li`,{className:`px-3 py-1.5 text-muted-foreground`,children:q(`loading`)})]})]})},$g=sn(),e_=e=>e.split(/\s+/).filter(Boolean),t_=(e,t,n,r=!1)=>{let i=e_(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:Yt($g.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=>$g.eq(t,`*${e.replaceAll(`*`,``)}*`));return{filter:Yt($g.and(...o)),local:!1}},n_=(e,t)=>{if(e==null)return!1;let n=String(e).toLowerCase();return e_(t).every(e=>n.includes(e.toLowerCase()))},r_=15e3,i_=()=>{let e=Nd();return Xd().data?.status&&e?.state.kind===`signed-in`?String(e.state.user.id):void 0},a_=()=>{let e=U(),t=i_();return E({queryKey:H.statuses(t??``),enabled:t!==void 0,refetchInterval:r_,queryFn:()=>e.status.people()})},o_=()=>{let e=U(),t=i_();return E({queryKey:H.ownStatus(t??``),enabled:t!==void 0,refetchInterval:r_,queryFn:()=>e.status.own()})},s_=(e,t=Date.now())=>e.isSuccess&&!e.isFetching&&t-e.dataUpdatedAt>=1e4,c_=(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})},l_=()=>{let e=Nd(),t=e?.state.kind===`signed-in`?e.state.user:void 0,n=E({queryKey:H.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=a_().data,i=(0,I.useMemo)(()=>n.data&&(r?c_(n.data,r):n.data),[n.data,r]),a=(0,I.useMemo)(()=>new Map((i??[]).map(e=>[e.id,e])),[i]),{refetch:o}=n,s=(0,I.useCallback)(e=>{let t=a.get(e);return!t&&s_(n)&&setTimeout(()=>void o(),0),t},[a,n,o]);return{...n,data:i,member:s}},u_=e=>e,d_=e=>e,f_=(0,I.createContext)({}),p_=()=>(0,I.useContext)(f_),m_=(e,t)=>t?.titleFrom?.fields??[],h_=(e,t)=>(n,r,i,a)=>{let o=r?.titleFrom;if(!o)return ur(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},g_=()=>void 0,__=(0,I.createContext)(h_({},{user:void 0,member:g_})),v_=()=>(0,I.useContext)(__),y_=({rules:e,user:t,children:n})=>{let r=(0,I.useMemo)(()=>h_(e,{user:t,member:g_}),[e,t]);return(0,B.jsx)(__.Provider,{value:r,children:n})},b_=({rules:e,user:t,children:n})=>{let{member:r}=l_(),i=(0,I.useMemo)(()=>h_(e,{user:t,member:r}),[e,t,r]);return(0,B.jsx)(__.Provider,{value:i,children:n})},x_=({children:e})=>{let{views:t}=W(),{titles:n}=p_(),r=Nd(),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,B.jsx)(b_,{rules:a,user:i,children:e}):(0,B.jsx)(y_,{rules:a,user:i,children:e})},S_=({target:e,view:t,value:n,label:r,chosen:i=[n],several:a=!1,invalid:o,onChange:s})=>{let c=Xg(),l=e.primaryKey[0],u=cr(e,t),[d,f]=(0,I.useState)(!1),p=v_(),m=t_(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]),_=Yg(e.name,{filter:m.filter,fields:h,enabled:c.open}),v=m.filter!==void 0&&_.error instanceof fl&&_.error.slug===`expensive-query`;(0,I.useEffect)(()=>{v&&f(!0)},[v]);let y=m.local?_.items.filter(e=>n_(g(e),c.text)):_.items,{fetchNextPage:b}=_,x=(0,I.useCallback)(()=>b({cancelRefetch:!1}),[b]);return(0,B.jsx)(Qg,{search:c,options:y.map(e=>({key:String(e[l]),label:g(e)})),chosen:i,several:a,closedText:r??n,placeholder:q(`searchPlural`,{plural:(t?.names?.plural??F(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)})},C_=(e,t)=>e.replace(/\D/g,``).slice(0,t),w_=(e,t,n)=>{let r=C_(t??``,n);return r.length===n?r:C_(e,n)},T_=(e,t,n,r)=>{let i=t.replace(/\D/g,``);return i.length>=r?i.slice(0,r):C_(e.slice(0,n)+i+e.slice(n+i.length),r)},E_=({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,I.useRef)(null),[g,_]=(0,I.useState)(!1),[v,y]=(0,I.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,B.jsxs)(`div`,{className:P(`relative`,a&&`opacity-50`,o),children:[(0,B.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,B.jsx)(`div`,{"data-slot":t,"data-digit":b[t],className:P(`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,B.jsx)(`span`,{className:`h-6 w-px animate-pulse bg-foreground`}):(0,B.jsx)(`span`,{className:`size-1.5 rounded-full bg-border-strong`}))},t)})}),(0,B.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(w_(e.target.value,t??n?.getData(`text/plain`),r))},onPaste:e=>{if(p?.(e),e.defaultPrevented)return;e.preventDefault();let t=e.currentTarget,n=T_(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)}})]})},D_=M(`app/confirm-sign-in`),O_=({minutes:e,onConfirmed:t})=>{let n=Nd(),[r,i]=(0,I.useState)(``),a=E({queryKey:[`account-sign-in-methods`],queryFn:()=>n.session.account.signInMethods(),enabled:!!n}),s=o({mutationFn:()=>n.signInWithPasskey(),onSuccess:t}),c=o({mutationFn:e=>n.verifyTwoFactor({method:`totp`,code:e}),onSuccess:t}),l=a.data?.account,u=s.error??c.error??a.error;return(0,B.jsxs)(`section`,{"aria-label":D_(`confirmTitle`),className:`mt-2 flex flex-col gap-2 rounded-md border border-border bg-surface p-3`,children:[(0,B.jsx)(`p`,{className:`font-medium`,children:D_(`confirmTitle`)}),(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:D_(`confirmWhy`,{minutes:e})}),l&&l.passkeys>0&&(0,B.jsx)(G,{variant:`primary`,size:`sm`,className:`self-start`,loading:s.isPending,onClick:()=>s.mutate(),children:D_(`usePasskey`)}),l?.authenticatorApp&&(0,B.jsxs)(`form`,{className:`flex flex-wrap items-end gap-2`,onSubmit:e=>{e.preventDefault(),c.mutate(r.trim())},children:[(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5`,children:[D_(`authenticatorCode`),(0,B.jsx)(E_,{name:`code`,required:!0,value:r,invalid:c.isError,onChange:i,onComplete:e=>c.mutate(e)})]}),(0,B.jsx)(G,{type:`submit`,size:`sm`,loading:c.isPending,children:D_(`confirm`)})]}),l&&l.passkeys===0&&!l.authenticatorApp&&(0,B.jsx)(`p`,{children:D_(`nothingToConfirmWith`)}),u&&(0,B.jsx)(`p`,{role:`alert`,className:`font-medium text-danger-text`,children:u.message})]})},k_=`••••••••••`,A_=e=>ml(e)&&e.slug===`strong-sign-in-required`?e.problem.minutes??15:void 0,j_=({field:e,hints:t,value:n,reveal:r,locked:i,invalid:a,placeholder:s,onChange:c})=>{let[l,u]=(0,I.useState)(!1),d=o({mutationFn:async()=>r(),onSuccess:()=>u(!0)}),f=gg(n)!==``,p=t?.label??F(e.name),m=(0,B.jsx)(G,{variant:`ghost`,size:`sm`,className:`-mr-1.5 px-1.5`,"aria-label":q(l?`hide`:`show`,{label:p}),"aria-pressed":l,loading:d.isPending,onClick:()=>{l||f||!r||d.isSuccess?u(!l):d.mutate()},children:!d.isPending&&(l?(0,B.jsx)(pa,{className:`size-3.5`}):(0,B.jsx)(ha,{className:`size-3.5`}))}),h=A_(d.error),g=h===void 0?d.error&&(0,B.jsx)(`div`,{className:`mt-2`,children:(0,B.jsx)(Gg,{title:q(`couldNotShow`,{label:p}),error:d.error})}):(0,B.jsx)(O_,{minutes:h,onConfirmed:()=>d.mutate()});if(i)return(0,B.jsxs)(`div`,{children:[(0,B.jsxs)(`div`,{className:`flex items-center gap-2 py-1`,children:[(0,B.jsx)(`span`,{className:P(l?t?.format===`code`?`font-mono text-xs`:``:`tracking-widest text-muted-foreground`),children:l?Rm(e,d.data,t):k_}),r&&m]}),g]});let _=f?gg(n):l&&d.isSuccess?gg(d.data):``;return(0,B.jsxs)(`div`,{children:[(0,B.jsx)(J,{type:l?`text`:`password`,autoComplete:`off`,invalid:a,"aria-label":p,className:P(t?.format===`code`&&`font-mono text-xs`),placeholder:f||!r?s??(e.writeOnly?q(`setNewValue`):void 0):k_,value:_,trailing:m,onChange:e=>c(e.target.value)}),g]})},M_=(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`},N_=e=>URL.canParse(e)?[new URL(e).hostname]:[],P_=()=>{let e=(0,I.useContext)(qd);return(0,I.useMemo)(()=>[...e?.files?.trustedHosts??[],...(e?.sources??[]).flatMap(({source:e})=>N_(e.url))],[e?.files,e?.sources])},F_=e=>{let t;try{t=atob(e)}catch(e){if(e instanceof DOMException&&e.name===`InvalidCharacterError`)return;throw e}return S(Uint8Array.from(t,e=>e.charCodeAt(0)))},I_=({image:e,alt:t=``,className:n,loading:r})=>{let[i,a]=(0,I.useState)(),o=P_(),s=(0,I.useMemo)(()=>e.placeholder===void 0?void 0:F_(e.placeholder),[e.placeholder]),c=s!==void 0&&i!==e.url;return(0,B.jsx)(`img`,{src:e.url,alt:t,loading:r,decoding:`async`,referrerPolicy:M_(e.url,window.location.href,o),onLoad:()=>a(e.url),className:n,style:c?{backgroundImage:`url("${s}")`,backgroundSize:`cover`,backgroundPosition:`center`}:void 0})},L_=({value:e})=>{let t=Kp(e,{width:40,height:40});return t?(0,B.jsx)(I_,{image:t,className:`size-10 shrink-0 rounded border border-border object-cover`}):(0,B.jsx)(`span`,{className:`flex size-10 shrink-0 items-center justify-center rounded border border-border bg-muted text-muted-foreground`,children:(0,B.jsx)(Ca,{className:`size-4`})})},R_=({value:e})=>{let t=Rp(e);if(!t)return(0,B.jsx)(`div`,{className:`py-1.5 text-muted-foreground`,children:`—`});if(`missing`in t)return(0,B.jsx)(`div`,{className:`py-1.5 text-danger-text`,children:q(`fileMissing`)});let n=`url`in t?t.url:void 0,r=`corrected`in t?t.corrected:void 0;return(0,B.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3 py-1`,children:[(0,B.jsx)(L_,{value:e}),(0,B.jsxs)(`div`,{className:`min-w-0`,children:[n&&!n.startsWith(`blob:`)?(0,B.jsx)(`a`,{href:n,target:`_blank`,rel:`noreferrer`,className:`block truncate font-medium text-primary-text hover:underline`,children:t.name}):(0,B.jsx)(`span`,{className:`block truncate font-medium`,children:t.name}),(0,B.jsxs)(`span`,{className:`block truncate text-xs text-muted-foreground`,children:[t.type,t.size!==void 0&&` · ${Bp(t.size)}`,r&&` · sent as ${r.from}`]})]})]})},z_=({field:e,hints:t,resource:n,value:r,locked:i,invalid:a,onChange:s})=>{let c=U(),l=(0,I.useRef)(null),[u,d]=(0,I.useState)(),[f,p]=(0,I.useState)(!1),m=t?.label??F(e.name),h=o({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,...Vp(r.file.type)&&{preview:URL.createObjectURL(t)}}},onSuccess:e=>s(e),onSettled:()=>d(void 0)});if(i||e.readOnly)return(0,B.jsx)(R_,{value:r});let g=e=>{let t=e?.[0];t&&h.mutate(t)},_=e=>{e.preventDefault(),p(!1),g(e.dataTransfer.files)},v=(0,B.jsx)(`input`,{ref:l,type:`file`,hidden:!0,accept:qp(e),"aria-label":q(`chooseFileFor`,{label:m}),onChange:e=>g(e.target.files)}),y=h.error&&(0,B.jsx)(`div`,{className:`mt-2`,children:(0,B.jsx)(Gg,{title:q(`notUploaded`),error:h.error})});return h.isPending?(0,B.jsxs)(`div`,{className:`py-1.5`,role:`status`,"aria-label":q(`uploadingLabel`,{label:m}),children:[(0,B.jsx)(`div`,{className:`h-1.5 overflow-hidden rounded-full bg-muted`,children:(0,B.jsx)(`div`,{className:`h-full rounded-full bg-primary transition-[width]`,style:{width:`${Math.round((u??0)*100)}%`}})}),(0,B.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:q(`uploading`,{percent:Math.round((u??0)*100)})})]}):Rp(r)?(0,B.jsxs)(`div`,{children:[(0,B.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,B.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,B.jsx)(R_,{value:r})}),(0,B.jsx)(G,{size:`sm`,onClick:()=>l.current?.click(),children:q(`replace`)}),e.nullable&&(0,B.jsx)(G,{size:`sm`,variant:`ghost`,onClick:()=>s(null),children:q(`remove`)})]}),v,y]}):(0,B.jsxs)(`div`,{children:[(0,B.jsxs)(`div`,{onDragOver:e=>{e.preventDefault(),p(!0)},onDragLeave:()=>p(!1),onDrop:_,className:P(`flex items-center gap-3 rounded-md border border-dashed px-3 py-2.5 text-muted-foreground`,f?`border-primary bg-primary/5`:a?`border-danger`:`border-border-strong`),children:[(0,B.jsx)(Qs,{className:`size-4 shrink-0`}),(0,B.jsx)(`span`,{className:`flex-1`,children:q(`dropFile`)}),(0,B.jsxs)(G,{size:`sm`,onClick:()=>l.current?.click(),children:[(0,B.jsx)(Io,{className:`size-3.5`}),q(`chooseFile`)]})]}),v,y]})},B_=e=>[...e].reduce((e,t)=>(e*31+t.charCodeAt(0))%360,7),V_=e=>e.split(/[\s@.]+/).filter(Boolean).slice(0,2).map(e=>e[0].toUpperCase()).join(``),H_=e=>(e.role??`user`).split(`,`).map(e=>e.trim()),U_=e=>H_(e).includes(`admin`),W_=e=>gm(e.replace(/[_-]+/g,` `).trim()),G_=e=>{let t=H_(e),n=t.includes(`admin`);return{name:e.name||e.email,email:e.email,initials:V_(e.name||e.email)||`?`,hue:B_(e.id||e.email),role:n?z(`admin`):W_(t[0]??`user`),roleTone:n?`violet`:`blue`}},K_=M(`app/field-types/members`),q_=({id:e,name:t})=>(0,B.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-1.5`,children:[(0,B.jsx)(Vf,{initials:t&&V_(t)||`?`,hue:B_(e),size:`xs`,className:`ring-0`}),(0,B.jsx)(`span`,{className:t===void 0?`truncate text-muted-foreground`:`truncate`,children:t??K_(`unknownMember`)})]}),J_=e=>Array.isArray(e)?e.filter(e=>typeof e==`string`):[],Y_=(e,t)=>e.includes(t)?e.filter(e=>e!==t):[...e,t],X_=(e,t)=>e.filter(e=>n_(e.name,t)).map(e=>({key:e.id,label:e.name})),Z_=()=>{let e=Nd(),t=l_();return{...t,needsOrganizations:!e?.organizations,failed:t.isError}},Q_=({value:e,line:t})=>{let n=Z_(),r=J_(e);return r.length===0?(0,B.jsx)(`span`,{className:`text-muted-foreground`,children:`—`}):n.needsOrganizations?(0,B.jsx)(`span`,{className:`text-muted-foreground`,children:K_(`needsOrganizations`)}):n.failed?(0,B.jsx)(`span`,{className:`text-muted-foreground`,children:K_(`couldNotLoadMembers`)}):n.isLoading?(0,B.jsx)(Ch,{className:`h-4 w-24`}):(0,B.jsx)(`span`,{className:P(`flex min-w-0 items-center gap-x-3 gap-y-1`,t?`overflow-hidden`:`flex-wrap`),children:r.map(e=>(0,B.jsx)(q_,{id:e,name:n.member(e)?.name},e))})},$_=e=>(0,B.jsx)(Q_,{...e,line:!1}),ev=e=>(0,B.jsx)(Q_,{...e,line:!0}),tv=({label:e,onRemove:t})=>(0,B.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,B.jsx)(`span`,{className:`truncate`,children:e}),(0,B.jsx)(`button`,{type:`button`,"aria-label":rf(`remove`,{label:e}),className:`rounded p-0.5 hover:bg-primary-border/60`,onMouseDown:e=>e.preventDefault(),onClick:t,children:(0,B.jsx)(bc,{className:`size-3`})})]}),nv=({value:e,invalid:t,onChange:n})=>{let r=Xg(),i=Z_(),a=J_(e);if(i.needsOrganizations)return(0,B.jsx)(`p`,{className:`py-1.5 text-muted-foreground`,children:K_(`needsOrganizations`)});let o=e=>i.member(e)?.name??K_(`unknownMember`);return(0,B.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,B.jsx)(Qg,{search:r,options:X_(i.data??[],r.text),chosen:a,several:!0,closedText:``,placeholder:K_(`searchMembers`),invalid:t,loading:i.isLoading,failed:i.failed,onChoose:e=>n(Y_(a,e.key))}),a.length>0&&(0,B.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:a.map(e=>(0,B.jsx)(tv,{label:o(e),onRemove:()=>n(a.filter(t=>t!==e))},e))})]})},rv={members:{of:[...Dr.members],display:$_,editor:nv,cell:ev}},iv=(e,t)=>{if(e&&Object.hasOwn(e,t))return e[t];if(Object.hasOwn(rv,t))return rv[t]},av=(e,t,n)=>{let r=n?.widget;if(!r||t.sensitive)return;let i=iv(e,r.name);return i?.of.includes(t.type)?{name:r.name,widget:i,props:r.props??{}}:void 0},ov=(e,t)=>av(p_().fields,e,t),sv,cv,lv=({dsn:e,environment:t})=>(sv??=Ve(()=>import(`./prod-DSoLg5cQ.js`).then(n=>{n.init({dsn:e,...t&&{environment:t},integrations:e=>[...e.filter(e=>e.name!==`BrowserSession`),n.thirdPartyErrorFilterIntegration({filterKeys:[qn],behaviour:`drop-error-if-exclusively-contains-third-party-frames`})],beforeSend:e=>Kn(e)}),cv=(e,t)=>n.captureException(e,t?{contexts:{react:{componentStack:t}}}:void 0)}),[]),sv),uv=(e,t)=>cv?.(e,t??void 0),dv=({children:e})=>(0,B.jsx)(`div`,{role:`alert`,className:`rounded-lg border border-dashed border-warning bg-warning-soft p-3 text-warning-text`,children:e}),fv=M(`app/pages`),pv=class extends I.Component{state={failed:!1};static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(e,t){uv(e,t.componentStack)}render(){return this.state.failed?this.props.fallback===void 0?(0,B.jsx)(dv,{children:fv.rich(`couldNotDraw`,{name:this.props.name})}):this.props.fallback:this.props.children}},mv=M(`app/field-types`),hv=({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,B.jsx)(e,{...c})}let l=o.editor;return l&&i?(0,B.jsx)(l,{...c,onChange:i,invalid:a}):void 0},gv=({fallback:e,...t})=>{let n=hv(t);return n?(0,B.jsx)(pv,{name:mv(`fieldType`,{name:t.shown.name}),fallback:e,children:n}):e},_v=(0,I.lazy)(()=>Ve(()=>import(`./markdown-content-L1MZShpP.js`).then(e=>({default:e.MarkdownContent})),__vite__mapDeps([0,1,2,3]))),vv=e=>(0,B.jsx)(I.Suspense,{fallback:(0,B.jsx)(`div`,{className:P(`whitespace-pre-line break-words`,e.className),children:e.source}),children:(0,B.jsx)(_v,{...e})}),yv=M(`markdown`),bv=()=>[{value:`write`,label:yv(`write`)},{value:`preview`,label:yv(`preview`)}],xv=({value:e,onChange:t,label:n,invalid:r,placeholder:i})=>{let[a,o]=(0,I.useState)(`write`);return(0,B.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,B.jsx)(`span`,{className:`self-start`,children:(0,B.jsx)(Re,{value:a,options:bv(),onChange:o,label:n})}),a===`write`?(0,B.jsx)(Jg,{rows:5,invalid:r,placeholder:i,value:e,onChange:e=>t(e.target.value)}):(0,B.jsx)(`div`,{className:`min-h-[7.5rem] rounded-md border border-border px-2.5 py-1.5`,children:e.trim()===``?(0,B.jsx)(`span`,{className:`text-faint-foreground`,children:yv(`nothingToPreview`)}):(0,B.jsx)(vv,{source:e})})]})},Sv=new Set([`integer`,`bigint`,`decimal`]),Cv=e=>e===`integer`||e===`bigint`?{inputMode:`numeric`,enterKeyHint:`done`}:e===`decimal`?{inputMode:`decimal`,enterKeyHint:`done`}:{},wv=e=>e.stopPropagation(),Tv=({format:e,value:t,className:n})=>{let r=Dm(e,t);return r?(0,B.jsx)(`a`,{href:r,...e===`url`?{target:`_blank`,rel:`noreferrer`}:{},onClick:wv,className:P(`font-medium text-primary-text hover:underline`,n),children:t}):(0,B.jsx)(`span`,{className:n,children:t})},Ev=e=>typeof e==`object`&&e&&`key`in e?e.key:e,Dv=(e,t,n,r,i)=>t?.confirm!==void 0&&!Dg(e,n,r)&&Dg(e,Ev(i),r),Ov=M(`app/change-confirm`),kv=e=>e instanceof Element&&e.closest(`[data-dialog="change-confirm"]`)!==null,Av=({field:e,hints:t,value:n,stored:r,onChange:i})=>{let[a,o]=(0,I.useState)(),s=a=>{Dv(e,t,n,r,a)?o({next:a}):i(a)},c=()=>o(void 0);return{onChange:s,dialog:a&&(0,B.jsx)(Of,{name:`change-confirm`,title:Ov(`title`,{label:t?.label??F(e.name)}),description:t?.confirm,onClose:c,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:c,children:Ov(`cancel`)}),(0,B.jsx)(G,{variant:`primary`,onClick:()=>{o(void 0),i(a.next)},children:Ov(`change`)})]})})}},jv=({field:e,hints:t,value:n,stored:r,relationLabel:i,relationTo:a,relationPicker:o,invalid:s,locked:c,placeholder:l,reveal:u,resource:d,onChange:f})=>{let p=$h();if(e.type===`file`)return(0,B.jsx)(z_,{field:e,hints:t,resource:d??``,value:n,locked:c||!d,invalid:s,onChange:f});if(e.sensitive)return(0,B.jsx)(j_,{field:e,hints:t,value:n,reveal:u,locked:c||e.readOnly,invalid:s,placeholder:l,onChange:f});if(e.type===`relation`&&o&&!e.readOnly&&!c){let e=(0,B.jsx)(S_,{target:o.target,view:o.view,value:String(n),label:i,invalid:s,onChange:(e,t)=>f({key:e,label:t})});return a?(0,B.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,B.jsx)(`div`,{className:`min-w-0 flex-1`,children:e}),(0,B.jsx)(Jh,{to:a,"aria-label":q(`openLabel`,{label:i??String(n)}),title:q(`open`),className:P(yf({variant:`ghost`}),`w-8 px-0`),children:(0,B.jsx)(Ur,{className:`size-4`})})]}):e}if(e.type===`boolean`&&c)return(0,B.jsx)(`div`,{className:`py-1.5 text-muted-foreground`,children:Rm(e,r,t)});if(e.type===`boolean`)return(0,B.jsx)(Kg,{checked:!!n,onChange:f,label:t?.label??F(e.name)});if(e.type===`relation`){let e=i??String(r??`—`);return(0,B.jsx)(`div`,{className:`py-1.5`,children:a?(0,B.jsx)(Jh,{to:a,className:`font-medium text-primary-text hover:underline`,children:e}):e})}let m=!!t?.multiline&&e.type===`text`,h=xm(e,t);if((!yg(e)||c)&&h&&typeof r==`string`&&r!==``)return(0,B.jsx)(vv,{source:r,className:`py-1.5`});let g=e.type===`text`?Em(t):void 0;return(!yg(e)||c)&&g&&typeof r==`string`&&r!==``?(0,B.jsx)(`div`,{className:`min-w-0 break-words py-1.5`,children:(0,B.jsx)(Tv,{format:g,value:r})}):!yg(e)||c?(0,B.jsx)(`div`,{title:zm(e,r,void 0,t),className:P(`py-1.5 tabular-nums`,e.type===`decimal`||e.type===`integer`?`font-medium`:`text-muted-foreground`,m&&`whitespace-pre-line break-words`),children:Rm(e,r,t)}):e.type===`enum`?(0,B.jsxs)(`select`,{...p,...s&&{"aria-invalid":!0},value:String(n),onChange:e=>f(e.target.value),className:`h-8 w-full 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`,children:[n===``&&(0,B.jsx)(`option`,{value:``,children:q(`choose`)}),(e.enumValues??[]).map(e=>(0,B.jsx)(`option`,{value:e,children:ar(e,t?.valueLabels)},e))]}):h?(0,B.jsx)(xv,{label:t?.label??F(e.name),invalid:s,placeholder:l,value:String(n),onChange:f}):m?(0,B.jsx)(Jg,{invalid:s,placeholder:l,value:String(n),onChange:e=>f(e.target.value)}):(0,B.jsx)(J,{invalid:s,leading:t?.prefix?(0,B.jsx)(`span`,{children:t.prefix}):void 0,trailing:t?.suffix?(0,B.jsx)(`span`,{children:t.suffix.trim()}):void 0,placeholder:l,className:P(Sv.has(e.type)&&`text-right tabular-nums`),...Cv(e.type),...Om(g),value:String(n),onChange:e=>f(e.target.value)})},Mv=e=>{let{field:t,hints:n,value:r,stored:i,invalid:a,locked:o,onChange:s}=e,c=ov(t,n),l=(0,B.jsx)(jv,{...e});return c?o||!yg(t,n)?(0,B.jsx)(gv,{shown:c,part:`display`,field:t,value:i,fallback:l}):t.type===`file`||t.type===`relation`?l:(0,B.jsx)(gv,{shown:c,part:`editor`,field:t,value:Tg(t,r),invalid:!!a,onChange:e=>s(Eg(t,e)),fallback:l}):l},Nv=e=>{let t=Av(e);return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(Mv,{...e,onChange:t.onChange}),t.dialog]})},Pv={text:`text`,integer:`integer`,decimal:`decimal`,boolean:`boolean`,date:`date`},Fv=e=>{let t={name:e.name,column:e.name,nullable:!0,readOnly:!1,filterable:!1,sortable:!1,aliases:[]};return e.kind===`custom`?{...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:Pv[e.kind]}},Iv=e=>({label:e.label,...e.multiline&&{multiline:!0},...e.options&&{valueLabels:Object.fromEntries(e.options.map(e=>[e.value,e.label]))}}),Lv=e=>Object.fromEntries(e.map(e=>e.kind===`custom`?[e.name,e.default??null]:e.kind===`boolean`?[e.name,!!e.default]:[e.name,gg(e.default)])),Rv=(e,t)=>e.kind===`custom`?t??null:Ng(t)?t.key:e.resource===void 0?wg(Fv(e),t):String(t??``)===``?null:String(t),zv=(e,t)=>{let n=Object.fromEntries(e.map(e=>[e.name,Rv(e,t[e.name])])),r=On(e,n);return{shown:r,values:Object.fromEntries(Object.entries(n).filter(([e])=>r.has(e)))}},Bv=/^-?\d+(\.\d+)?$/,Vv=/^\d{4}-\d{2}-\d{2}$/,Hv=(e,t)=>{if(t===null||t===``)return e.required?fv(`required`):void 0;if(e.kind===`integer`&&!Number.isInteger(t))return fv(`wholeNumber`);if(e.kind===`decimal`&&!Bv.test(String(t)))return fv(`number`);if(e.kind===`date`&&!Vv.test(String(t)))return fv(`dateFormat`);if(e.max!==void 0&&String(t).length>e.max)return fv(`atMost`,{max:e.max})},Uv=(e,t)=>Object.fromEntries(e.flatMap(e=>{if(!Object.hasOwn(t,e.name))return[];let n=Hv(e,t[e.name]);return n?[[e.name,n]]:[]})),Wv=class extends Error{errors;constructor(e){super(Object.values(e).join(`; `)),this.errors=e,this.name=`ActionInputError`}},Gv=(e,t)=>{let n=new Set(t.map(e=>e.name)),r=e instanceof Wv?Object.entries(e.errors):ml(e)?e.errors.flatMap(e=>e.field?[[e.field,e.message]]:[]):[];return Object.fromEntries(r.filter(([e])=>n.has(e)))},Kv=({input:e,held:t,invalid:n,onChange:r})=>{let{resources:i,views:a}=W(),{components:o}=p_();if(e.kind===`custom`){let i=o?.[e.component??``];if(!i)throw Error(`Input "${e.name}": the app has no component "${e.component}"`);return(0,B.jsx)(i,{input:e,value:t??null,onChange:r,invalid:n,props:e.props??{}})}let s=e.resource===void 0?void 0:i[e.resource];return(0,B.jsx)(Nv,{field:Fv(e),hints:Iv(e),value:Ng(t)?t.key:t,stored:void 0,relationLabel:Ng(t)?t.label:void 0,relationPicker:s?{target:s,view:a[s.name]}:void 0,invalid:n,onChange:r})},qv=({action:e,label:t,danger:n,onCancel:r,onSubmit:i})=>{let[a,o]=(0,I.useState)(()=>Lv(e.inputs)),[s,c]=(0,I.useState)({}),[l,u]=(0,I.useState)(),[d,f]=(0,I.useState)(!1),p=(0,I.useId)(),{shown:m,values:h}=zv(e.inputs,a),g=async()=>{let t=Uv(e.inputs,h);c(t),u(void 0),!(Object.keys(t).length>0)&&(f(!0),await i(h).catch(t=>{c(Gv(t,e.inputs)),u(t)}),f(!1))},_=(e,t)=>{c(({[e]:t,...n})=>n),o(n=>({...n,[e]:t}))};return(0,B.jsx)(jf,{title:t,description:e.confirm,open:!0,onClose:r,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:r,children:fv(`cancel`)}),(0,B.jsx)(G,{variant:n?`danger`:`primary`,type:`submit`,form:p,loading:d,children:t})]}),children:(0,B.jsxs)(`form`,{id:p,className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),g()},children:[l!==void 0&&Object.keys(s).length===0&&(0,B.jsx)(Gg,{title:fv(`failed`,{label:t}),error:l}),e.inputs.filter(e=>m.has(e.name)).map(e=>(0,B.jsx)(eg,{label:e.label,required:e.required,help:e.help,error:s[e.name],children:(0,B.jsx)(Kv,{input:e,held:a[e.name],invalid:!!s[e.name],onChange:t=>_(e.name,t)})},e.name))]})})},Jv=({action:e,label:t,danger:n,onCancel:r,onConfirm:i})=>(0,B.jsx)(Of,{title:`${t}?`,description:e.confirm,onClose:r,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:r,children:fv(`cancel`)}),(0,B.jsx)(G,{variant:n?`danger`:`primary`,onClick:i,children:t})]})}),Yv=e=>e.variant===`danger`||e.run?.kind===`delete`,Xv=e=>!!(e.confirm||e.inputs?.length),Zv=({action:e,label:t,danger:n,onCancel:r,onConfirm:i,onSubmit:a})=>{let{inputs:o}=e;return o?.length?(0,B.jsx)(qv,{action:{...e,inputs:o},label:t,danger:n,onCancel:r,onSubmit:a}):(0,B.jsx)(Jv,{action:e,label:t,danger:n,onCancel:r,onConfirm:i})},Qv=(0,I.createContext)(void 0),$v=({value:e,children:t})=>(0,B.jsx)(Qv.Provider,{value:e,children:t}),ey=()=>(0,I.useContext)(Qv),ty=M(`toasts`),ny=`-my-0.5 rounded px-1.5 py-0.5 font-medium text-primary-text hover:bg-primary-soft`,ry=({action:e})=>{if(`onClick`in e)return(0,B.jsx)(`button`,{type:`button`,onClick:e.onClick,className:ny,children:e.label});let{href:t,onNavigate:n}=e;return(0,B.jsx)(`a`,{href:t,onClick:e=>{n&&Th(e)&&(e.preventDefault(),n(t))},className:ny,children:e.label})},iy={loading:(0,B.jsx)(af,{className:`text-primary`}),success:(0,B.jsx)(Fi,{className:`size-4 text-success`}),warning:(0,B.jsx)(Xs,{className:`size-4 text-warning`}),error:(0,B.jsx)(Vi,{className:`size-4 text-danger`}),info:(0,B.jsx)(is,{className:`size-4 text-primary`}),call:(0,B.jsx)(Bo,{className:`size-4 animate-pulse text-success`})},ay=({state:e,title:t,description:n,action:r,actions:i=[],onDismiss:a})=>(0,B.jsxs)(`div`,{role:e===`error`||e===`call`?`alert`:`status`,className:P(`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,B.jsx)(`span`,{className:`mt-0.5`,children:iy[e]}),(0,B.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,B.jsx)(`p`,{className:`font-medium text-foreground`,children:t}),n&&(0,B.jsx)(`p`,{className:`mt-0.5 text-xs text-muted-foreground`,children:n})]}),r&&(0,B.jsx)(ry,{action:r}),i.map(e=>(0,B.jsx)(ry,{action:e},e.label)),a&&(0,B.jsx)(`button`,{type:`button`,"aria-label":ty(`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,B.jsx)(bc,{className:`size-3.5`})})]}),oy={loading:1/0,success:3500,warning:8e3,error:8e3,info:8e3,call:1/0},sy=8e3,cy=(0,I.createContext)(null),ly=()=>{let e=(0,I.useContext)(cy);if(!e)throw Error(`useToast must be used inside ToastProvider`);return e},uy=({children:e})=>{let[t,n]=(0,I.useState)([]),r=(0,I.useRef)(1),i=(0,I.useRef)(new Map),a=(0,I.useRef)(new Set),o=(0,I.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,I.useCallback)((e,t,n=!1)=>{if(clearTimeout(i.current.get(e)),a.current.has(e))return;let r=n?sy:oy[t];r!==1/0&&i.current.set(e,setTimeout(()=>o(e),r))},[o]),c=e=>{e.onClose?.(),o(e.id)},l=(0,I.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,B.jsxs)(cy.Provider,{value:l,children:[e,(0,B.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,B.jsx)(`div`,{className:`pointer-events-auto`,children:(0,B.jsx)(ay,{state:e.state,title:e.title,description:e.description,action:e.action,...e.actions&&{actions:e.actions},onDismiss:()=>c(e)})},e.id))})]})},dy=(e,t)=>e[t]||e.conditional.includes(t),fy=(e,t)=>e.permissions?.[t]??!0,py=(e,t)=>e?.fields?e.fields[t]??`hidden`:`edit`,my=(e,t)=>{if(e.when===void 0)return!0;if(!t)return!1;let n=yu(e.when);return n.ok&&bu(n,t)},hy=(e,t={})=>e.replace(/\{([A-Za-z_][A-Za-z0-9_]*)\}/g,(e,n)=>encodeURIComponent(t[n]===null||t[n]===void 0?``:String(t[n]))),gy=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},_y=(e,t={})=>{let n=hn(e);return n===void 0?hy(e,t):gy(t[n])},vy=e=>{e!==void 0&&(/^https?:/i.test(e)?window.open(e,`_blank`,`noopener,noreferrer`):window.location.assign(e))},yy=e=>URL.canParse(e)?new URL(e).hostname.replace(/^www\./,``):``,by=(e,t)=>Object.entries(t).every(([t,n])=>Object.is(e[t],n)),xy=(e,t)=>{if(!my(e,t))return e.otherwise===`disable`?e:void 0;let n=e.run;if(n?.kind===`update`)return t&&!e.inputs?.length&&by(t,n.values)?void 0:e;if(n?.kind!==`link`||!(`href`in n))return e;let r=_y(n.href,t);if(r!==void 0)return e.label.includes(`{host}`)?{...e,label:e.label.replaceAll(`{host}`,yy(r))}:e},Sy=async(e,t,n)=>{let r=e.filter(t),i={done:0,skipped:e.length-r.length,failed:0};for(let e of r){let t=await n(e).then(()=>void 0,e=>({error:e}));t?(i.failed+=1,i.failed===1&&(i.error=t.error)):i.done+=1}return i},Cy=(e,t)=>({model:e,record:t,key:Nn(wm(e,t)),etag:typeof t.etag==`string`?t.etag:void 0,permissions:t.permissions}),wy=(e,t,n=``)=>({queryKey:H.count(t.name,n),queryFn:async()=>{let r=await e.list(t.name,{filter:n||void 0,pageSize:1,count:`exact`,fields:t.primaryKey});return r.totalSize??r.totalSizeEstimate}}),Ty=(e,t=``)=>E(wy(U(),e,t)),Ey=(e,{filter:t=``,sort:n=``,key:r})=>{let i=U();return E({queryKey:r===void 0?H.firstRecord(e.name,t,n):H.record(e.name,r),queryFn:async()=>{if(r!==void 0){let t=await i.get(e.name,r);return{...Cy(e,t.record),etag:t.etag,permissions:t.permissions}}let a=await i.list(e.name,{filter:t||void 0,orderBy:n||void 0,pageSize:1});return a.items[0]?Cy(e,a.items[0]):null}})},Dy=(e,{filter:t=``,sort:n=``,pageSize:r,pageToken:i=``})=>{let a=U();return E({queryKey:H.list(e.name,t,n,r,i),placeholderData:d,queryFn:()=>a.list(e.name,{filter:t||void 0,orderBy:n||void 0,pageSize:r,pageToken:i||void 0})})},Oy=()=>{let e=Se();return(0,I.useCallback)(t=>e.invalidateQueries({predicate:e=>e.queryKey[1]===t}),[e])},ky=e=>e instanceof Error?e.message:fv(`somethingWrong`),Ay=(e,t,n)=>{let{views:r}=W(),{actions:i,components:a}=p_(),o=uf(e),s=U(),c=Hd(e),l=ly(),u=Oy(),{go:d}=qh(),[f,p]=(0,I.useState)(),m=(r[e]?.actions??[]).flatMap(e=>xy(e,t?.record)??[]),h=(e,t)=>{let n=e.run?.kind;if((n===`update`||n===`delete`||n===`ai`)&&!t)return fv(`needsRecord`);if(!my(e,t?.record))return e.reason??fv(`doesNotApply`);if((n===`update`||n===`ai`)&&(!dy(o,`update`)||t?.permissions?.update===!1)||e.run?.kind===`ai`&&t?.permissions?.fields?.[e.run.writes]===`read`)return fv(`cannotChange`);if(n===`delete`&&(!dy(o,`delete`)||t?.permissions?.delete===!1))return fv(`cannotDelete`);if(!e.run&&!i?.[e.name])return fv(`noHandler`,{name:e.name});let r=e.inputs?.find(e=>e.kind===`custom`&&!a?.[e.component??``]);if(r)return fv(`noInputComponent`,{component:String(r.component),input:r.name})},g=e=>h(e,t),_=async(t,n,r)=>{let{run:a}=t;if(a?.kind===`link`){`to`in a?d(mn(a.to,n?.record)):vy(_y(a.href,n?.record));return}a?.kind===`update`?await s.update(e,n.key,kn(a.values,r??{}),n.etag??`*`):a?.kind===`delete`?await s.remove(e,n.key,{etag:n.etag}):a?.kind===`ai`?await s.generate(e,n.key,t.name):await i[t.name]({resource:e,record:n?.record,recordKey:n?.key,etag:n?.etag,client:c,navigate:d,...r&&{values:r}})},v=async(t,r,i)=>{await _(t,r,i),t.run?.kind!==`link`&&(await u(e),l.show({state:`success`,title:fv(`done`,{label:t.label})}),n?.(t))},y=async(e,n=t)=>{h(e,n)||(p(e.name),await v(e,n).catch(t=>l.show({state:`error`,title:fv(`failed`,{label:e.label}),description:ky(t)})),p(void 0))},b=async(e,n)=>{g(e)||(p(e.name),await v(e,t,n).finally(()=>p(void 0)))},x=(e,t)=>xy(e,t.record)!==void 0&&!h(e,t);return{actions:m,blocked:g,blockedOn:h,appliesOn:x,running:f,run:y,submit:b,runEach:async(t,r,i=0)=>{p(t.name);let a=await Sy(r,e=>x(t,e),e=>_(t,e));p(void 0),await u(e);let o=fv(`doneOn`,{label:t.label,done:a.done,skipped:a.skipped+i,failed:a.failed});l.show(a.failed>0?{state:`error`,title:o,description:ky(a.error)}:{state:`success`,title:o}),a.done>0&&n?.(t)}}},jy=(e,t,n)=>{let r=Ay(e,n),i=r.actions.find(e=>e.name===t);return{action:i,blocked:i?r.blocked(i):fv(`noAction`,{name:t}),running:r.running===t,run:()=>i?r.run(i):Promise.resolve(),submit:e=>i?r.submit(i,e):Promise.resolve()}},My=e=>e.props,Ny=({name:e,resource:t,label:n,variant:r})=>{let i=ey(),a=jy(t??i?.model.name??``,e,t===void 0||t===i?.model.name?i:void 0),[o,s]=(0,I.useState)(!1);if(!a.action)return null;let c=n??a.action.label,l=r??a.action.variant??`secondary`;return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{size:`sm`,variant:l,loading:a.running,disabled:!!a.blocked,title:a.blocked,onClick:()=>Xv(a.action)?s(!0):void a.run(),children:c}),o&&(0,B.jsx)(Zv,{action:a.action,label:c,danger:l===`danger`,onCancel:()=>s(!1),onConfirm:()=>{s(!1),a.run()},onSubmit:async e=>{await a.submit(e),s(!1)}})]})},Py=({node:e})=>(0,B.jsx)(Ny,{...My(e)}),Fy=({title:e,description:t,actions:n,className:r,bodyClassName:i,children:a})=>(0,B.jsxs)(`section`,{className:P(`flex min-w-0 flex-col rounded-lg border border-border bg-background`,r),"aria-label":e,children:[(e||t||n)&&(0,B.jsxs)(`header`,{className:`flex flex-wrap items-start justify-between gap-x-4 gap-y-2 px-4 pt-4`,children:[(0,B.jsxs)(`div`,{className:`min-w-0`,children:[e&&(0,B.jsx)(`h2`,{className:`text-[16px] font-semibold tracking-tight`,children:e}),t&&(0,B.jsx)(`p`,{className:`mt-0.5 text-muted-foreground`,children:t})]}),n&&(0,B.jsx)(`div`,{className:`flex flex-wrap items-center gap-2`,children:n})]}),(0,B.jsx)(`div`,{className:P(`min-w-0 flex-1 p-4`,i),children:a})]}),Iy=({children:e})=>(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:e}),Ly=({node:e,children:t,slots:n})=>{let{title:r,description:i}=My(e);return(0,B.jsx)(Fy,{title:r,description:i,actions:n.actions,className:`h-full`,children:(0,B.jsx)(`div`,{className:`flex flex-col gap-3`,children:t})})},Ry=({model:e,filter:t,sort:n,limit:r=12,title:i,description:a,empty:o,actions:s,children:c})=>{let l=Dy(e,{filter:t,sort:n,pageSize:r}),u=l.data?.items??[];return(0,B.jsx)(Fy,{title:i,description:a,actions:s,children:l.isPending?(0,B.jsx)(`div`,{className:`flex gap-3`,children:Array.from({length:3},(e,t)=>(0,B.jsx)(Ch,{className:`h-24 w-56`},t))}):l.error?(0,B.jsx)(Gg,{title:fv(`couldNotLoad`),error:l.error}):u.length===0?(0,B.jsx)(Iy,{children:o??fv(`nothingYet`)}):(0,B.jsx)(`ul`,{className:`relative -mx-4 flex snap-x gap-3 overflow-x-auto px-4 pb-1`,children:u.map(t=>{let n=Cy(e,t);return(0,B.jsx)(`li`,{className:`flex w-60 shrink-0 snap-start flex-col gap-2 rounded-lg border border-border bg-surface p-3`,children:(0,B.jsx)($v,{value:n,children:c})},n.key)})})})},zy=({node:e,children:t,slots:n})=>{let{resource:r,...i}=My(e),a=W().resources[r];return a?(0,B.jsx)(Ry,{...i,model:a,actions:n.actions,children:t}):null},By=(e,t,n,r=!0)=>{let i=U(),a=tl(n)??``;return E({queryKey:H.facets(e,t,a),enabled:r,queryFn:()=>i.facets(e,t,{filter:a,limit:50})})},Vy=(e,t,n=!0)=>{let r=U(),i=tl(t.filter)??``;return E({queryKey:H.series(e,t.field,`${t.range??``}${t.from??``}${t.to??``}`,t.granularity??``,i),enabled:n,queryFn:()=>r.series(e,{...t,filter:i})})},Hy=(e,t,n,r=20,i=!0)=>{let a=U(),o=tl(n)??``;return E({queryKey:H.histogram(e,t,r,o),enabled:i,queryFn:()=>a.histogram(e,t,{filter:o,buckets:r})})},Uy=(e,t,n=!0)=>{let r=U(),i={...t,filter:tl(t.filter)??``};return E({queryKey:H.aggregate(e,JSON.stringify(i)),enabled:n,queryFn:()=>r.aggregate(e,i)})},Wy=(e,t,n=!0)=>{let r=U();return f({queries:t.map(t=>{let i={...t,filter:tl(t.filter)??``};return{queryKey:H.aggregate(e,JSON.stringify(i)),enabled:n,queryFn:()=>r.aggregate(e,i)}})})},Gy=M(`app/charts`),Ky=sn(),qy=e=>e>=0&&e<8?`var(--chart-${e+1})`:`var(--faint-foreground)`,Jy=(e,t,n,r)=>{let i=String(n);if(n===null)return`var(--faint-foreground)`;let a=Am(t?.valueColors,n);return a===void 0?e.type===`enum`?qy(e.enumValues?.indexOf(i)??-1):e.type===`boolean`?qy(+!n):qy(r):a},Yy=(e,t,n)=>n.value===null?Gy(`notSet`):e.type===`enum`?ar(String(n.value),t?.valueLabels):e.type===`boolean`?n.value?Gy(`yes`):Gy(`no`):n.label??String(n.value),Xy=(e,t,n=``)=>{let r=Yt(t===null?Ky.isNull(e.name):Ky.eq(e.name,t));return n.trim()?`(${n}) AND ${r}`:r},Zy=(e,t)=>t.kind===`count`?e.count:e[t.kind]??null,Qy=(e,t,n,r,i=``)=>e.map((e,a)=>({key:String(e.value),label:Yy(t,n,e),value:Zy(e,r),count:e.count,color:Jy(t,n,e.value,a),filter:Xy(t,e.value,i)})),$y=(e,t)=>e.map(e=>({at:Date.parse(`${String(e.value)}Z`),value:Zy(e,t),count:e.count})),eb=(e,t)=>{if(e===null)return`—`;if(t.kind===`count`)return e.toLocaleString(Le());let n=t.hints?.decimals??(Number.isInteger(e)?0:2),r=e.toLocaleString(Le(),{minimumFractionDigits:n,maximumFractionDigits:n});return`${t.hints?.prefix??``}${r}${t.hints?.suffix??``}`},tb=(e,t,n)=>n?{kind:`list`,resource:t,filter:n}:e?.list?.filter?{kind:`list`,resource:t,filter:``}:{kind:`list`,resource:t},nb=({resource:e,view:t,slices:n,measure:r})=>{let i=Math.max(0,...n.map(e=>e.value??0));return(0,B.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,B.jsx)(`li`,{children:(0,B.jsxs)(Jh,{to:tb(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:Gy(`records`,{count:eb(n.count,{kind:`count`})}),children:[(0,B.jsx)(`span`,{className:`truncate group-hover:text-primary-text`,children:n.label}),(0,B.jsx)(`span`,{className:`h-3 rounded-r bg-muted`,"aria-hidden":!0,children:(0,B.jsx)(`span`,{className:`block h-full rounded-r`,style:{width:`${a*100}%`,background:`var(--chart-1)`}})}),(0,B.jsx)(`span`,{className:`text-right font-medium tabular-nums`,children:eb(n.value,r)})]})},n.key)})})},rb=`flex items-center gap-2 rounded-md px-1 py-0.5`,ib=({resource:e,view:t,filter:n,color:r,label:i,children:a})=>{let o=(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`span`,{className:`size-2.5 shrink-0 rounded-full`,style:{background:r},"aria-hidden":!0}),(0,B.jsx)(`span`,{className:`min-w-0 flex-1 truncate group-hover:text-primary-text`,children:i}),a]});return(0,B.jsx)(`li`,{children:n===void 0?(0,B.jsx)(`div`,{className:rb,children:o}):(0,B.jsx)(Jh,{to:tb(t,e,n),className:`group ${rb} hover:bg-muted`,children:o})})},ab=(e,t)=>t>0?`${Math.round(e/t*100)}%`:``,ob=({active:e,payload:t,measure:n})=>{let r=t?.[0]?.payload;return!e||!r?null:(0,B.jsxs)(`div`,{className:`rounded-md border bg-background px-2.5 py-1.5 text-xs shadow-pop`,children:[(0,B.jsx)(`div`,{className:`text-muted-foreground`,children:r.label}),(0,B.jsx)(`div`,{className:`font-semibold tabular-nums`,children:eb(r.value,n)})]})},sb=({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,B.jsxs)(`div`,{className:`flex flex-col items-center gap-4 sm:flex-row sm:items-center`,children:[(0,B.jsx)(`div`,{className:`size-36 shrink-0`,children:(0,B.jsx)(g,{width:`100%`,height:`100%`,children:(0,B.jsxs)(l,{children:[(0,B.jsx)(b,{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,B.jsx)(u,{fill:e.color},e.key))}),(0,B.jsx)(p,{content:(0,B.jsx)(ob,{measure:r}),isAnimationActive:!1})]})})}),(0,B.jsx)(`ul`,{className:`flex w-full min-w-0 flex-col gap-0.5`,children:n.map(n=>(0,B.jsxs)(ib,{resource:e,view:t,filter:n.filter,color:n.color,label:n.label,children:[(0,B.jsx)(`span`,{className:`font-medium tabular-nums`,children:eb(n.value,r)}),(0,B.jsx)(`span`,{className:`w-9 text-right text-xs text-muted-foreground tabular-nums`,children:ab(n.value??0,a)})]},n.key))})]})},cb={hour:`2-digit`,minute:`2-digit`,hour12:!1},lb={day:`numeric`,month:`short`,...cb},ub={minute:cb,"5_minutes":cb,"15_minutes":cb,hour:cb,day:{day:`numeric`,month:`short`},week:{day:`numeric`,month:`short`},month:{month:`short`,year:`2-digit`},year:{year:`numeric`}},db={minute:lb,"5_minutes":lb,"15_minutes":lb,hour:lb,day:{day:`numeric`,month:`short`,year:`numeric`},week:{day:`numeric`,month:`short`,year:`numeric`},month:{month:`long`,year:`numeric`},year:{year:`numeric`}},fb=e=>{let t=new Intl.DateTimeFormat(Le(),{...e,timeZone:`UTC`});return e=>t.format(e)},pb={fontSize:11,fill:`var(--muted-foreground)`},mb=864e5,hb=new Set([`minute`,`5_minutes`,`15_minutes`,`hour`]),gb=(e,t)=>{let n=t.length>1?t.at(-1).at-t[0].at:0;return hb.has(e)&&n>=mb?lb:ub[e]},_b=({active:e,payload:t,measure:n,bucket:r,series:i})=>{let a=t?.[0]?.payload;return!e||!a?null:(0,B.jsxs)(`div`,{className:`rounded-md border bg-background px-2.5 py-1.5 text-xs shadow-pop`,children:[(0,B.jsx)(`div`,{className:`text-muted-foreground`,children:r===`week`?Gy(`weekOf`,{day:fb(db[r])(a.at)}):fb(db[r])(a.at)}),i?.map(e=>(0,B.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,B.jsx)(`span`,{className:`size-2 shrink-0 rounded-full`,style:{background:e.color},"aria-hidden":!0}),(0,B.jsx)(`span`,{className:`flex-1`,children:e.label}),(0,B.jsx)(`span`,{className:`font-semibold tabular-nums`,children:eb(a[e.key]??null,e.measure??n)})]},e.key)),i&&(n.kind===`count`||n.kind===`sum`)&&(0,B.jsx)(`div`,{className:`mt-0.5 border-t pt-0.5 font-semibold tabular-nums`,children:eb(a.value,n)}),!i&&(0,B.jsx)(`div`,{className:`font-semibold tabular-nums`,children:eb(a.value,n)})]})},vb=({points:e,measure:t,bucket:n,type:r,series:i,resource:o,view:s})=>{let l=bf(`(min-width: 640px)`),u=fb(gb(n,e)),d=(0,B.jsx)(v,{vertical:!1,stroke:`var(--border)`}),f=(0,B.jsx)(a,{dataKey:`at`,tickFormatter:u,tick:pb,axisLine:!1,tickLine:!1,minTickGap:l?24:40,height:18}),m=(0,B.jsx)(pe,{width:l?48:36,tick:pb,axisLine:!1,tickLine:!1,tickCount:3,tickFormatter:e=>e.toLocaleString(Le(),{notation:`compact`})}),h=(0,B.jsx)(p,{cursor:r===`bar`?{fill:`var(--muted)`}:{stroke:`var(--border-strong)`},content:(0,B.jsx)(_b,{measure:t,bucket:n,...i&&{series:i}}),isAnimationActive:!1}),b=i??[{key:`value`,label:``,color:`var(--chart-1)`}],x=(0,B.jsx)(`div`,{className:`h-40`,children:(0,B.jsx)(g,{width:`100%`,height:`100%`,children:r===`line`?(0,B.jsxs)(y,{data:e,margin:{top:6,right:6,bottom:0,left:0},children:[d,f,m,h,b.map(t=>(0,B.jsx)(_,{dataKey:t.key,stroke:t.color,strokeWidth:2,dot:e.length<=31&&{r:3,fill:t.color,strokeWidth:0},activeDot:{r:4,stroke:`var(--background)`,strokeWidth:2},isAnimationActive:!1},t.key))]}):(0,B.jsxs)(c,{data:e,margin:{top:6,right:0,bottom:0,left:0},barCategoryGap:`22%`,children:[d,f,m,h,b.map((e,t)=>(0,B.jsx)(fe,{dataKey:e.key,fill:e.color,...i&&{stackId:`split`},radius:t===b.length-1?[4,4,0,0]:0,isAnimationActive:!1},e.key))]})})});return!i||o===void 0?x:(0,B.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[x,(0,B.jsx)(`ul`,{className:`flex flex-wrap gap-x-3 gap-y-0.5 text-sm`,children:i.map(e=>(0,B.jsx)(ib,{resource:o,view:s,color:e.color,label:e.label,...e.filter!==void 0&&{filter:e.filter}},e.key))})]})},yb=1e-6,bb=(e,t,n,r,i,a=``)=>{let o=t.map((e,t)=>({key:`s${t}`,label:Yy(n,r,e),color:Jy(n,r,e.value,t),filter:Xy(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=$y(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<yb?0:l}});return i.kind!==`average`&&l.some(e=>(e.other??0)>0)?{series:[...o,{key:`other`,label:Gy(`other`),color:`var(--border-strong)`}],points:l}:{series:o,points:l.map(({other:e,...t})=>t)}},xb=(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]}},Sb=(e,t,n)=>{let r=e?.type===`relation`&&e.relation?t[e.relation.resource]:void 0;return r&&r.primaryKey.length===1?cr(r,n[r.name]):void 0},Cb=({model:e,view:t,groupBy:n,splitBy:r,type:i=`bar`,sum:a,average:o,filter:s=``,granularity:c=`day`,range:l=`30d`,limit:u=10,empty:d=Gy(`nothingYet`)})=>{let{resources:f,views:p}=W(),m=e.fields[n],h=m?.type===`date`||m?.type===`timestamp`,g=Sb(m,f,p),_=h&&r!==void 0?e.fields[r]:void 0,v=Sb(_,f,p),y=_?{splitBy:_.name,splitLimit:8,...v&&{splitLabel:v}}:{},b=h?{granularity:c,range:l,timeZone:Xf(),...y}:{limit:u,...g&&{label:g}},x=Uy(e.name,{groupBy:n,filter:s,...a&&{sum:a},...o&&{average:o},...b},!!m),S=xb(e,t,a,o);if(!m)return null;if(x.isPending)return(0,B.jsx)(Ch,{className:`h-36 w-full`});if(x.error)return(0,B.jsx)(`p`,{className:`text-danger-text`,children:Gy(`couldNotLoad`)});let{groups:C}=x.data;if(C.every(e=>e.count===0))return(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:d});let w=i===`line`?`line`:`bar`;if(h&&_&&x.data.splits){let{series:n,points:r}=bb(C,x.data.splits,_,t?.fields[_.name],S,s);return(0,B.jsx)(vb,{points:r,measure:S,bucket:c,type:w,series:n,resource:e.name,view:t})}if(h)return(0,B.jsx)(vb,{points:$y(C,S),measure:S,bucket:c,type:w});let T=Qy(C,m,t?.fields[n],S,s);return i===`donut`?(0,B.jsx)(sb,{resource:e.name,view:t,slices:T,measure:S}):(0,B.jsx)(nb,{resource:e.name,view:t,slices:T,measure:S})},wb=({node:e,slots:t})=>{let{resource:n,title:r,description:i,actions:a,span:o,...s}=My(e),{resources:c,views:l}=W(),u=c[n];return u?(0,B.jsx)(Fy,{title:r,description:i,actions:t.actions,className:`h-full`,children:(0,B.jsx)(Cb,{model:u,view:l[n],...s})}):null},Tb=sn(),Eb=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=cr(n,i),c=await e.fetchQuery({queryKey:H.labels(n.name,o.join(`,`)),staleTime:3e5,queryFn:async()=>(await t.list(n.name,{filter:Yt(Tb.in(a,o)),fields:[a,s],pageSize:o.length})).items.map(e=>[String(e[a]),String(e[s])])});return new Map(c)},Db=(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}]:[]}),Ob=(e,t,n,r)=>Object.fromEntries(Db(e,n,r).filter(({target:e})=>e.primaryKey.length===1&&!t[e.name]?.titleFrom).map(({name:e,target:n})=>[e,cr(n,t[n.name])])),kb=(e,t,n,r,i={})=>{let a=Db(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})},Ab=sn(),jb=(e,t)=>{let n=t?.titleFrom;if(n&&!n.unreadable&&e.primaryKey.length===1)return n.fields},Mb=(e,t,n)=>H.titleRow(e.name,t,n.join(`,`)),Nb=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:Yt(Ab.in(i,a)),fields:[i,...n],pageSize:a.length});return new Map(o.items.map(e=>[String(e[i]),e]))},Pb=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||!jb(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=jb(o,r[i]),c=await Nb(t,o,s,a);for(let t of new Set(a))e.setQueryData(Mb(o,t,s),{row:c.get(t)??null})}))},Fb=(e,t,n,r,i)=>{let a=r?.titleFrom;return a?{queryKey:Mb(n,i,a.fields),queryFn:async()=>({row:(await Nb(t,n,a.fields,[i])).get(i)??null})}:{queryKey:H.relatedLabel(n.name,i),queryFn:async()=>({label:(await Eb(e,t,n,[i],r)).get(i)??i})}},Ib=(e,t,n,r,i)=>{if(e)return`label`in e?e.label:e.row?t(n,r,e.row,i):i},Lb=(e,t,n=!0)=>{let{views:r}=W(),i=U(),a=Se(),o=v_(),s=r[e.name];return Ib(E({...Fb(a,i,e,s,t),staleTime:3e5,enabled:n}).data,o,e,s,t)},Rb=({value:e,hints:t,children:n})=>(0,B.jsx)(zf,{tone:jm(t?.valueColors,e),color:Am(t?.valueColors,e),shape:t?.badgeShape,children:n}),zb=({target:e,id:t,known:n})=>{let r=Lb(e,t,n===void 0);return(0,B.jsx)(Jh,{to:{kind:`record`,resource:e.name,key:t},className:`font-medium text-primary-text hover:underline`,children:n??r??t})},Bb=({field:e,value:t,known:n})=>{let{resources:r}=W(),i=e.relation?r[e.relation.resource]:void 0;return i?(0,B.jsx)(zb,{target:i,id:String(t),known:n}):(0,B.jsx)(`span`,{children:String(t)})},Vb=({model:e,field:t,value:n,format:r,relationLabel:i})=>{let{views:a}=W(),o={...a[e.name]?.fields[t.name],...r&&{format:r}};if(n==null||n===``)return(0,B.jsx)(`span`,{className:`text-muted-foreground`,children:`—`});if(t.type===`relation`)return(0,B.jsx)(Bb,{field:t,value:n,known:i});let s=t.type===`file`?Rp(n):void 0;if(s&&`url`in s&&s.url){let e=Kp(n,{width:40,height:40});return(0,B.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-2`,children:[e&&(0,B.jsx)(I_,{image:e,className:`size-10 shrink-0 rounded border border-border object-cover`}),(0,B.jsx)(`a`,{href:s.url,target:`_blank`,rel:`noreferrer`,className:`truncate font-medium text-primary-text hover:underline`,children:s.name})]})}if(xm(t,o))return(0,B.jsx)(vv,{source:String(n)});let c=Rm(t,n,o),l=t.type===`text`?Em(o):void 0;return l?(0,B.jsx)(Tv,{format:l,value:c}):t.type===`enum`||o.format===`badge`?(0,B.jsx)(Rb,{value:n,hints:o,children:c}):(0,B.jsx)(`span`,{title:zm(t,n,void 0,o),className:P(o.format===`code`&&`font-mono text-xs`,(t.type===`decimal`||t.type===`integer`)&&`tabular-nums`,o.multiline&&`whitespace-pre-line break-words`),children:c})},Hb=e=>{let{views:t}=W(),n=ov(e.field,t[e.model.name]?.fields[e.field.name]),r=(0,B.jsx)(Vb,{...e});return n?(0,B.jsx)(gv,{shown:n,part:`display`,field:e.field,value:e.value,fallback:r}):r},Ub=(e,t,n)=>{if(!t)return[];let r=Cu(e,t.model.name,n);return r.ok?r.steps:[]},Wb=(e,t,n,r,i)=>({queryKey:H.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:H.record(a,String(i)),queryFn:()=>e.get(a,String(i))})).record}return r[i.at(-1).field.name]??null}}),Gb=(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}},Kb=(e,t)=>{let{resources:n}=W(),r=Ub(n,e,t);return Gb(e,r,E(Wb(U(),Se(),e,t,r)))},qb=(e,t)=>{let{resources:n}=W(),r=U(),i=Se(),a=t.map(t=>Ub(n,e,t)),o=f({queries:t.map((t,n)=>Wb(r,i,e,t,a[n]))});return t.map((t,n)=>Gb(e,a[n],o[n]))},Jb=(e,t)=>{if(t)return t;let n=e.split(`.`).map(e=>F(e).toLowerCase()).join(` `);return n[0].toUpperCase()+n.slice(1)},Yb=({node:e})=>{let{name:t,label:n,format:r}=My(e),{views:i}=W(),a=Kb(ey(),t);if(a.state===`missing`)return null;let o=a.state===`loading`?(0,B.jsx)(Ch,{className:`h-4 w-24`}):(0,B.jsx)(Hb,{model:a.model,field:a.field,value:a.value,format:r});if(n===!1)return(0,B.jsx)(`div`,{children:o});let s=n??Jb(t,a.state===`ready`?i[a.model.name]?.fields[a.field.name]?.label:void 0);return(0,B.jsxs)(`div`,{className:`min-w-0`,children:[(0,B.jsx)(`div`,{className:`text-body text-muted-foreground`,children:s}),(0,B.jsx)(`div`,{className:`mt-0.5 truncate`,children:o})]})},Xb={1:``,2:`md:grid-cols-2`,3:`md:grid-cols-2 xl:grid-cols-3`,4:`sm:grid-cols-2 xl:grid-cols-4`},Zb={1:``,2:`grid-cols-2`,3:`grid-cols-2 xl:grid-cols-3`,4:`grid-cols-2 xl:grid-cols-4`},Qb={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`},$b=e=>typeof e==`object`&&!e.custom&&e.type===`Stat`,ex=({node:e,children:t})=>{let{columns:n=2}=My(e),r=e.children,i=r.length>0&&r.every($b);return(0,B.jsx)(`div`,{className:P(`grid grid-cols-1 gap-4`,i?Zb[n]:Xb[n]),children:t.map((e,t)=>{let n=r[t],i=typeof n==`object`?n.props.span:void 0;return(0,B.jsx)(`div`,{className:P(`min-w-0`,i&&Qb[i]),children:e},t)})})},tx=`font-medium text-primary-text hover:underline`,nx=({node:e})=>{let t=My(e),n=ey()?.record,r=e.children.filter(e=>typeof e==`string`).join(``);if(t.to){let e=mn(t.to,n);return(0,B.jsx)(Jh,{to:e,className:tx,children:r||Vc(e)})}let i=t.href??``;return(0,B.jsx)(`a`,{href:i,className:tx,...i.startsWith(`http`)&&{target:`_blank`,rel:`noreferrer`},children:r||i})},rx=M(`app/field`),ix=(e,t)=>typeof e?.[t]==`number`?e[t]:void 0,ax=(e,t)=>{let n=ix(t,`min`),r=ix(t,`max`);if(n!==void 0)return rx(`atLeastCharacters`,{label:e,count:kp(n),n});if(r!==void 0)return rx(`atMostCharacters`,{label:e,count:kp(r),n:r})},ox=e=>{let t=ix(e,`min`),n=ix(e,`max`);return t===void 0?n===void 0?rx(`wholeNumber`):rx(`wholeNumberAtMost`,{max:kp(n)}):rx(`wholeNumberAtLeast`,{min:kp(t)})},sx=e=>{let t=ix(e,`precision`),n=ix(e,`scale`);if(t===void 0||n===void 0)return rx(`number`);let r=kp(10**(t-n));return n===0?rx(`wholeNumberBelow`,{below:r}):rx(`decimalsBelow`,{scale:n,below:r})},cx={text:ax,integer:(e,t)=>ox(t),bigint:()=>rx(`wholeNumber`),decimal:(e,t)=>sx(t),date:()=>rx(`date`),timestamp:()=>rx(`timestamp`),country:()=>rx(`country`),currency:()=>rx(`currency`),uuid:()=>rx(`uuid`),enum:()=>rx(`enum`),relation:()=>rx(`relation`),json:()=>rx(`json`)},lx=(e,t,n)=>n.code===`required`?rx(`required`,{label:t}):n.code!==`invalid-value`||!e?n.message:cx[e.type]?.(t,n.params)??n.message,ux=e=>{if(!ml(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},dx=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?rx(`checkField`):rx(`checkFields`,{count:t.size})],...n].join(` `)},fx=e=>{let t=(0,I.useRef)(null),n=(0,I.useRef)(!1);return(0,I.useEffect)(()=>{e>0&&(n.current=!0)},[e]),(0,I.useEffect)(()=>{if(!n.current)return;let e=t.current?.querySelector(`[aria-invalid="true"]`);e&&(e.focus(),n.current=!1)}),t},px=(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]:gg(n[t])];let i=r.default&&`value`in r.default?r.default.value:void 0;return[t,r.type===`boolean`?!!i:gg(i)]})),mx=(e,t,n)=>Object.fromEntries(Object.entries(t).flatMap(([t,r])=>{let i=e.fields[t];return Ng(r)?r.key===gg(n[t])?[]:[[t,i.type===`integer`?Number(r.key):r.key]]:Dg(i,r,n[t])?[[t,wg(i,r)]]:[]})),hx=({model:e,record:t,mode:n,label:r,title:i,fields:a,values:o,onClose:s})=>{let{resources:c,views:l}=W(),u=U(),d=ly(),f=Oy(),p=l[e.name],[m,h]=(0,I.useState)(()=>px(e,a,t?.record)),[g,_]=(0,I.useState)({}),[v,y]=(0,I.useState)(0),b=fx(v),[x,S]=(0,I.useState)(),[C,w]=(0,I.useState)(!1),[T,E]=(0,I.useState)(!1);Kh(T||C,`input-lost`);let D=async()=>{w(!0),S(void 0),await(n===`create`?u.create(e.name,{...Lg(e,c,m),...o}):u.update(e.name,t.key,mx(e,m,t.record),t.etag??`*`)).then(async()=>{await f(e.name),d.show({state:`success`,title:fv(`saved`,{label:i??r})}),s()},e=>{let t=ux(e);_(t),Object.keys(t).length>0&&y(e=>e+1),S(e)}),w(!1)};return(0,B.jsx)(Of,{title:i??r,onClose:s,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:s,children:fv(`cancel`)}),(0,B.jsx)(G,{variant:`primary`,loading:C,onClick:()=>void D(),children:fv(n===`create`?`create`:`save`)})]}),children:(0,B.jsxs)(`form`,{ref:b,className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),D()},children:[x!==void 0&&Object.keys(g).length===0&&(0,B.jsx)(Gg,{title:fv(`notSaved`),error:x}),a.map(n=>{let r=e.fields[n],i=m[n],a=r.relation?c[r.relation.resource]:void 0,o=p?.fields[n]?.label??F(n),s=g[n];return(0,B.jsx)(eg,{name:n,label:o,help:p?.fields[n]?.help,error:s&&lx(r,o,s),children:(0,B.jsx)(Nv,{field:r,hints:p?.fields[n],value:Ng(i)?i.key:i,stored:t?.record[n],relationLabel:Ng(i)?i.label:void 0,relationPicker:a?{target:a,view:l[a.name]}:void 0,invalid:!!g[n],resource:e.name,onChange:e=>{_(({[n]:e,...t})=>t),E(!0),h(t=>({...t,[n]:e}))}})},n)})]})})},gx=({model:e,recordKey:t,children:n})=>{let r=Ey(e,{key:t});return(0,B.jsx)(B.Fragment,{children:n(r.data??void 0)})},_x=({node:e})=>{let t=My(e),n=ey(),{resources:r}=W(),i=r[t.resource??n?.model.name??``],a=uf(i?.name??``),[o,s]=(0,I.useState)(!1);if(!i||!(t.mode===`create`?dy(a,`create`):dy(a,`update`)&&n?.permissions?.update!==!1))return null;let c=e=>(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{size:`sm`,variant:t.variant??`secondary`,disabled:t.mode===`edit`&&!e,onClick:()=>s(!0),children:t.label}),o&&(0,B.jsx)(hx,{...t,model:i,record:t.mode===`edit`?e:void 0,onClose:()=>s(!1)})]});return t.mode===`edit`&&t.recordKey!==void 0?(0,B.jsx)(gx,{model:i,recordKey:t.recordKey,children:c}):c(t.mode===`edit`?n:void 0)},vx=e=>e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey,yx=`flex min-h-[49px] min-w-0 flex-1 flex-col items-center justify-center gap-1 pb-1 pt-1.5 text-[10px] font-medium leading-none`,bx=({tabs:e,onNavigate:t,onMore:n,moreOpen:r,moreControls:i,sticky:a,ref:o})=>{let s=!e.some(e=>e.active);return(0,B.jsxs)(B.Fragment,{children:[a&&(0,B.jsx)(`div`,{"aria-hidden":!0,className:`h-[var(--pb-sticky-bottom)] shrink-0 md:hidden`}),(0,B.jsxs)(`nav`,{ref:o,"aria-label":wh(`tabs`),className:P(`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,B.jsxs)(`a`,{href:e.href,"aria-current":e.active?`page`:void 0,...e.external?{target:`_blank`,rel:`noreferrer`}:{},onClick:n=>{!e.external&&t&&vx(n)&&(n.preventDefault(),t(e.href))},className:P(yx,e.active?`text-primary-text`:`text-muted-foreground`),children:[(0,B.jsx)(n,{className:`size-6`,strokeWidth:e.active?2.2:1.9,"aria-hidden":!0}),(0,B.jsx)(`span`,{className:`max-w-full truncate px-0.5`,children:e.label})]},e.id)}),(0,B.jsxs)(`button`,{type:`button`,"aria-expanded":r,"aria-controls":i,"data-current":s||void 0,onClick:n,className:P(yx,s?`text-primary-text`:`text-muted-foreground`),children:[(0,B.jsx)(la,{className:`size-6`,strokeWidth:s?2.2:1.9,"aria-hidden":!0}),wh(`more`)]})]})]})},xx=({id:e,open:t,onClose:n,children:r})=>{let i=(0,I.useRef)(null);return Df(i,t,n),t?(0,B.jsxs)(`div`,{className:`fixed inset-0 z-50 md:hidden`,children:[(0,B.jsx)(`div`,{className:`absolute inset-0 bg-backdrop/40`,onClick:n,"aria-hidden":!0}),(0,B.jsx)(`div`,{ref:i,id:e,role:`dialog`,"aria-modal":`true`,"aria-label":wh(`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},Sx=(0,I.createContext)(()=>{}),Cx=e=>{let t=(0,I.useContext)(Sx);(0,I.useLayoutEffect)(()=>(t(e),()=>t(void 0)),[t,e])},wx=e=>{(0,I.useLayoutEffect)(()=>{if(!e)return;let t=document.documentElement;return t.style.setProperty(`scrollbar-gutter`,`stable`),()=>{t.style.removeProperty(`scrollbar-gutter`)}},[e])},Tx=[`--pb-sticky-top`,`--pb-sticky-bottom`,`scroll-padding-top`,`scroll-padding-bottom`],Ex=(e,t,n,r)=>{(0,I.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 Tx)r.style.removeProperty(e)}},[e,t,n,r])},Dx=`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`,Ox=`fill-[#ff5a1f] dark:fill-[#ff6a33]`,kx=`fill-[#14161a] dark:fill-[#f1f0ea]`,Ax=({className:e})=>(0,B.jsxs)(`svg`,{viewBox:`0 0 32 32`,className:P(`size-7 shrink-0`,e),"aria-hidden":!0,children:[(0,B.jsx)(`path`,{className:Ox,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,B.jsx)(`path`,{className:kx,d:`M17 0h10a5 5 0 0 1 5 5v22a5 5 0 0 1-5 5H5a5 5 0 0 1-5-5V17h17z`})]}),jx=({className:e})=>(0,B.jsx)(`svg`,{viewBox:`54.8 -720 3743.8 925`,className:P(`h-3.5 w-auto`,e),role:`img`,"aria-label":`Protobase`,children:(0,B.jsx)(`path`,{className:kx,d:Dx})}),Mx=`Protobase`,Nx=({compact:e,workspace:t,appName:n,appIcon:r})=>(0,B.jsxs)(`div`,{className:`flex items-center gap-2.5 overflow-hidden`,children:[r?(0,B.jsx)(`img`,{src:r,alt:``,className:`size-7 shrink-0 object-contain`}):(0,B.jsx)(Ax,{}),!e&&(0,B.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-0.5 leading-tight`,children:[r||n&&n!==Mx?(0,B.jsx)(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:n??Mx}):(0,B.jsx)(jx,{className:`self-start`}),t&&(0,B.jsx)(`div`,{className:`truncate text-[11px] text-muted-foreground`,children:t})]})]}),Px=({label:e,current:t,others:n,rowClassName:r,onSwitch:i})=>(0,B.jsxs)(`div`,{className:`border-b py-1`,role:`group`,"aria-label":e,children:[t&&(0,B.jsxs)(`div`,{className:P(r,`text-foreground hover:bg-transparent`),"aria-current":`true`,children:[(0,B.jsx)(Ci,{className:`size-4`}),(0,B.jsx)(`span`,{className:`truncate`,children:t.label})]}),n.map(e=>(0,B.jsxs)(`button`,{type:`button`,role:`menuitem`,onClick:()=>i(e.id),className:r,children:[(0,B.jsx)(`span`,{className:`size-4`}),(0,B.jsx)(`span`,{className:`truncate`,children:e.label})]},e.id))]}),Fx=()=>[{value:`light`,label:wh(`light`),icon:Is},{value:`dark`,label:wh(`dark`),icon:Ao},{value:`system`,label:wh(`system`),icon:Oo}],Ix=({theme:e,className:t})=>(0,B.jsxs)(`div`,{className:t,children:[(0,B.jsx)(Ps,{className:`size-4`}),(0,B.jsx)(`span`,{className:`flex-1`,children:wh(`theme`)}),(0,B.jsx)(Re,{label:wh(`theme`),iconOnly:!0,value:e.preference,options:Fx(),onChange:e.onChange})]}),Lx=`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`,Rx=({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,I.useState)(!1),m=n??f,h=(0,I.useRef)(null),[g,_]=(0,I.useState)();(0,I.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,B.jsxs)(`div`,{ref:h,className:`relative`,children:[(0,B.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":wh(`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,B.jsx)(Vf,{initials:e.initials,hue:e.hue,size:`md`,className:`ring-0`}),!t&&(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(`span`,{className:`min-w-0 flex-1 leading-tight`,children:[u?.mark?(0,B.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1`,children:[(0,B.jsx)(`span`,{className:`truncate font-medium`,children:e.name}),u.mark]}):(0,B.jsx)(`span`,{className:`block truncate font-medium`,children:e.name}),(0,B.jsx)(zf,{tone:e.roleTone,dot:!1,className:`mt-0.5 h-4 px-1.5 text-[10px]`,children:e.role})]}),(0,B.jsx)(ji,{className:`size-3.5 shrink-0 text-faint-foreground`})]})]}),m&&(0,B.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,B.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,B.jsx)(`div`,{className:`font-medium`,children:e.name}),(0,B.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,children:e.email})]}):(0,B.jsxs)(`div`,{className:`border-b px-3 pb-2 pt-1.5`,children:[(0,B.jsx)(`div`,{className:`font-medium`,children:e.name}),(0,B.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,children:e.email})]}),u&&(0,B.jsx)(`div`,{className:`border-b py-1`,children:(0,B.jsxs)(`button`,{type:`button`,role:`menuitem`,className:Lx,onClick:()=>{p(!1),u.onOpen()},children:[(0,B.jsx)(_a,{className:`size-4 shrink-0`}),(0,B.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:u.label})]})}),s&&(s.current||s.others.length>0)&&(0,B.jsx)(Px,{label:wh(`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:Lx,onSwitch:e=>{p(!1),s.onSwitch(e)}}),c&&c.roles.length>1&&(0,B.jsx)(Px,{label:wh(`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:Lx,onSwitch:e=>{p(!1),c.onSwitch(e)}}),v.map((e,t)=>(0,B.jsx)(`div`,{role:`group`,className:P(`py-1`,(t<v.length-1||l||o)&&`border-b`),children:e.map(e=>{let t=e.icon;return(0,B.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:P(Lx,e.active&&`bg-muted text-foreground`),children:[(0,B.jsx)(t,{className:`size-4`}),e.label]},e.id)})},e[0]?.id)),l&&(0,B.jsx)(`div`,{className:P(o&&`border-b`),children:(0,B.jsx)(Ix,{theme:l,className:P(Lx,`hover:bg-transparent`)})}),o&&(0,B.jsxs)(`button`,{type:`button`,role:`menuitem`,onClick:o,className:Lx,children:[(0,B.jsx)(so,{className:`size-4`}),wh(`signOut`)]})]})]})},zx={"text-large":`h-8 gap-2.5 px-2.5`,"text-small":`h-7 gap-2 px-2 text-body`},Bx={"text-large":`ml-[20px]`,"text-small":`ml-[17px]`},Vx=({create:e,mode:t,onNavigate:n})=>(0,B.jsx)(`div`,{className:P(`border-l border-transparent pl-1.5`,Bx[t]),children:(0,B.jsxs)(`a`,{href:e.href,onClick:n&&(t=>{t.preventDefault(),n(e.href)}),className:P(`flex items-center rounded-md text-faint-foreground transition-colors hover:bg-muted hover:text-foreground`,zx[t]),children:[(0,B.jsx)(Jo,{"aria-hidden":!0,className:`size-3.5 shrink-0`}),(0,B.jsx)(`span`,{className:`truncate`,children:e.label})]})}),Hx=`protobase:nav-open:`,Ux=e=>`${Hx}${e}`,Wx=(e,t)=>Ie(()=>e.getItem(t)!==`false`,!0),Gx=(e,t,n)=>Ie(()=>n?e.removeItem(t):e.setItem(t,`false`),void 0),Kx=({label:e,side:t=`right`,visible:n,children:r})=>(0,B.jsxs)(`span`,{className:`group/tooltip relative inline-flex`,children:[r,(0,B.jsx)(`span`,{role:`tooltip`,className:P(`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})]}),qx=e=>e===`text-large`||e===`text-small`||e===`icon-expand`,Jx=e=>e===`text-large`||e===`text-small`,Yx={"text-large":`w-60`,"text-small":`w-52`,icon:`w-14`,"icon-label":`w-[76px]`,"icon-tooltip":`w-14`,"icon-expand":`w-14`},Xx={"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-[10px]`,"icon-tooltip":`size-9 justify-center`,"icon-expand":`h-8 gap-3 px-3`},Zx=({item:e,mode:t,active:n,onNavigate:r,className:i})=>{let a=e.icon,o=(0,B.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:P(`flex shrink-0 items-center rounded-md font-medium transition-colors`,Xx[t],n?`bg-primary-soft text-primary-text`:`text-muted-foreground hover:bg-muted hover:text-foreground`,i),children:[(0,B.jsx)(a,{className:P(`shrink-0`,t===`text-small`?`size-4`:`size-[18px]`),strokeWidth:n?2.2:1.9}),(qx(t)||t===`icon-label`)&&(0,B.jsx)(`span`,{className:`whitespace-nowrap`,children:e.label}),Jx(t)&&e.count&&(0,B.jsx)(`span`,{className:`ml-auto rounded bg-muted px-1.5 text-[11px] tabular-nums text-muted-foreground`,children:e.count}),Jx(t)&&e.problem&&(0,B.jsx)(Xs,{"aria-hidden":!0,className:`ml-auto size-3.5 shrink-0 text-warning-text`})]});return t===`icon-tooltip`?(0,B.jsx)(Kx,{label:e.label,children:o}):o},Qx=99,$x=e=>e===void 0||e<=0?void 0:e>Qx?`${Qx}+`:String(e),eS=({count:e,className:t})=>{let n=$x(e);return n?(0,B.jsx)(zf,{tone:`red`,dot:!1,className:P(`h-4 min-w-4 justify-center px-1 text-[10px] font-semibold`,t),children:n}):null},tS={neutral:`bg-faint-foreground`,info:`bg-primary`,success:`bg-success`,warning:`bg-warning`,danger:`bg-danger`},nS=({tone:e,pulse:t=!1,className:n})=>(0,B.jsxs)(`span`,{"aria-hidden":!0,className:P(`relative flex size-2 shrink-0`,n),"data-tone":e,"data-pulse":t||void 0,children:[t&&(0,B.jsx)(`span`,{className:P(`absolute inset-0 animate-ping rounded-full opacity-60 motion-reduce:animate-none`,tS[e])}),(0,B.jsx)(`span`,{className:P(`relative size-2 rounded-full`,tS[e])})]}),rS=M(`status`),iS=({presence:e})=>{let t=rS(e);return(0,B.jsx)(`span`,{role:`img`,"aria-label":t,title:t,className:`flex shrink-0`,children:(0,B.jsx)(nS,{tone:e===`online`?`success`:`neutral`})})},aS=e=>rS(e===`busy`?`busy`:e===`do_not_disturb`?`doNotDisturb`:`automatic`),oS=({availability:e,title:t})=>{if(e===`automatic`)return null;let n=aS(e);return(0,B.jsx)(e===`busy`?Gi:zi,{role:`img`,"aria-label":n,className:P(`size-3.5 shrink-0`,e===`busy`?`text-warning`:`text-danger`),children:(0,B.jsx)(`title`,{children:t??n})})},sS=({status:e,presence:t,textShown:n=`full`,className:r})=>{let i=Tr(e);if(!i&&!t)return null;let a=i?.text??void 0;return(0,B.jsxs)(`span`,{className:P(`inline-flex min-w-0 items-center gap-1 text-muted-foreground`,r),title:a,children:[t&&(0,B.jsx)(iS,{presence:t}),i&&(0,B.jsx)(oS,{availability:i.availability,...n===`hover`&&a&&{title:a}}),i&&n===`hover`&&i.availability===`automatic`&&a&&(0,B.jsx)(`span`,{role:`img`,"aria-label":a,className:`size-1.5 shrink-0 rounded-full bg-faint-foreground`}),a&&n===`full`&&(0,B.jsx)(`span`,{className:`truncate text-xs`,children:a})]})},cS=(e,t)=>e.map(e=>{let n=t&&Object.hasOwn(t,e.id)?t[e.id]:void 0;return n?{...e,mark:n}:e}),lS=e=>{if(!e)return[];let t=Tr(e.status);return[e.presence&&rS(e.presence),t&&t.availability!==`automatic`?aS(t.availability):void 0,t?.text??void 0]},uS=e=>{let t=[e.status?.label,...lS(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(`, `)})`}},dS=({records:e,mode:t,onNavigate:n})=>e.map(e=>{let{ariaLabel:r,title:i}=uS(e),a=n&&(t=>{t.preventDefault(),n(e.href)}),o=e.mark?.strong===!0;return(0,B.jsx)(`li`,{children:(0,B.jsxs)(`a`,{href:e.href,onClick:a,"aria-label":r,title:i,"aria-current":e.active?`page`:void 0,className:P(`flex min-w-0 items-center rounded-md transition-colors`,zx[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,B.jsx)(nS,{tone:e.status.tone,pulse:e.status.pulse}),(0,B.jsx)(`span`,{className:`truncate`,children:e.label}),e.mark?.person&&(0,B.jsx)(sS,{...e.mark.person,textShown:`hover`,className:`ml-1.5 shrink-0`}),(0,B.jsx)(eS,{count:e.mark?.count,className:`ml-auto shrink-0`})]})},e.id)}),fS=({records:e,useMarks:t,...n})=>(0,B.jsx)(dS,{records:cS(e,t()),...n}),pS=({records:e,useMarks:t,mode:n,onNavigate:r})=>t?(0,B.jsx)(fS,{records:e,useMarks:t,mode:n,onNavigate:r}):(0,B.jsx)(dS,{records:e,mode:n,onNavigate:r}),mS=({item:e,recent:t,mode:n,active:r,onNavigate:i})=>{let a=Ux(e.id),[o,s]=(0,I.useState)(()=>Wx(localStorage,a)),c=(0,I.useId)(),l=e.href??`#${e.id}`;return(0,B.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,B.jsxs)(`div`,{className:`relative`,children:[(0,B.jsx)(Zx,{item:e,mode:n,active:r,onNavigate:i,className:`pr-8`}),(0,B.jsx)(`button`,{type:`button`,"aria-expanded":o,"aria-controls":c,"aria-label":wh(`recent`,{plural:e.label.toLowerCase()}),onClick:()=>{Gx(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,B.jsx)(ki,{className:P(`size-3.5 transition-transform`,o&&`rotate-90`)})})]}),o&&(0,B.jsxs)(`ul`,{id:c,"aria-label":wh(`recent`,{plural:e.label.toLowerCase()}),className:P(`flex flex-col gap-0.5 border-l pl-1.5`,Bx[n]),children:[t.state===`loading`&&(0,B.jsx)(`li`,{className:P(`flex items-center text-faint-foreground`,zx[n]),children:wh(`loading`)}),t.state===`error`&&(0,B.jsx)(`li`,{className:P(`flex items-center text-faint-foreground`,zx[n]),children:wh(`couldNotLoad`)}),t.state===`ready`&&(0,B.jsx)(pS,{records:t.records,useMarks:t.useMarks,mode:n,onNavigate:i}),(0,B.jsx)(`li`,{children:(0,B.jsx)(`a`,{...(e=>({href:e,onClick:i&&(t=>{t.preventDefault(),i(e)})}))(l),className:P(`flex items-center rounded-md text-faint-foreground transition-colors hover:bg-muted hover:text-foreground`,zx[n]),children:wh(`viewAll`)})})]})]})},hS=({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=Nx,notice:b})=>{let x=e===`icon-expand`,S=x&&o,C=Jx(e)||x;return(0,B.jsx)(`nav`,{"aria-label":wh(`resources`),className:P(v?`sticky top-0 h-dvh self-start`:`relative`,`z-30 shrink-0`,Yx[e]),children:(0,B.jsxs)(`div`,{className:P(`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)]`,x?`w-14 transition-[width,box-shadow] duration-150 hover:w-60 hover:shadow-pop focus-within:w-60 focus-within:shadow-pop`:`w-full`,S&&`w-60 shadow-pop`),children:[(0,B.jsx)(`div`,{className:P(`flex h-12 shrink-0 items-center px-3.5`,e===`icon-label`&&`justify-center px-0`),children:(0,B.jsx)(y,{compact:!C,workspace:r,appName:i,appIcon:a})}),(0,B.jsx)(`div`,{className:P(`flex-1 overflow-y-auto overflow-x-hidden pb-2`,`px-2`),children:c.map((n,r)=>(0,B.jsxs)(`div`,{className:P(`flex flex-col gap-0.5`,r>0&&`mt-3`),children:[C?n.label&&(0,B.jsx)(`div`,{className:P(`px-3 pb-1 pt-1 text-xs font-medium uppercase tracking-wide text-faint-foreground`,x&&`h-4 whitespace-nowrap py-0 opacity-0 transition-opacity group-hover/side:opacity-100 group-focus-within/side:opacity-100`,S&&`opacity-100`),children:n.label}):r>0&&(0,B.jsx)(`div`,{className:`mx-auto mb-1 h-px w-6 bg-border`}),n.items.map(n=>(0,B.jsxs)(I.Fragment,{children:[n.recent&&Jx(e)?(0,B.jsx)(mS,{item:n,recent:n.recent,mode:e,active:n.id===t,onNavigate:d}):(0,B.jsx)(Zx,{item:n,mode:e,active:n.id===t,onNavigate:d}),n.create&&Jx(e)&&(0,B.jsx)(Vx,{create:n.create,mode:e,onNavigate:d})]},n.id))]},n.label))}),b,(0,B.jsx)(`div`,{className:P(`shrink-0 border-t p-2`,e!==`text-large`&&e!==`text-small`&&!x&&`flex justify-center`),children:n?(0,B.jsx)(Rx,{user:n,compact:!C,open:s,items:l,account:u,onNavigate:d,onSignOut:f,organizations:m,roles:h,theme:g,status:_}):(0,B.jsxs)(B.Fragment,{children:[g&&C&&(0,B.jsx)(Ix,{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,B.jsxs)(Dh,{to:p,"aria-label":wh(`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,B.jsx)(ao,{className:`size-4 shrink-0`}),C&&(0,B.jsx)(`span`,{className:`whitespace-nowrap`,children:wh(`signIn`)})]})]})})]})})},gS=e=>xf()&&Jx(e),_S=(0,I.createContext)(null),vS=()=>(0,I.useContext)(_S),yS=e=>{let t=e.at(-2);if(typeof t==`object`&&t.href&&!t.loading)return{label:t.label,href:t.href}},bS=({children:e})=>(0,B.jsx)(`kbd`,{className:`inline-flex h-5 items-center rounded border border-border-strong bg-background px-1.5 font-sans text-[11px] font-medium text-muted-foreground`,children:e}),xS=(e,t,n)=>t===0?-1:e<0?n===1?0:t-1:(e+n+t)%t,SS=e=>e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||e.button!==0,CS=({search:e,className:t=`w-96`,autoFocus:n,showShortcut:r=!0,ref:i})=>{let a=(0,I.useId)(),o=(0,I.useRef)(null),[s,c]=(0,I.useState)(!1),[l,u]=(0,I.useState)(-1),d=e.groups.flatMap(e=>e.hits),f=s&&(e.query!==``||e.loading),p=e=>`${a}-${e}`,m=e=>{o.current=e,typeof i==`function`?i(e):i&&(i.current=e)},h=t=>{e.onSelect(t),u(-1),o.current?.blur()},g=()=>{e.onTextChange(``),u(-1),o.current?.focus()},_=t=>{if(t.key===`ArrowDown`||t.key===`ArrowUp`)t.preventDefault(),u(e=>xS(e,d.length,t.key===`ArrowDown`?1:-1));else if(t.key===`Enter`){let e=d[l]??d[0];if(!e)return;t.preventDefault(),h(e.href)}else t.key===`Escape`&&(e.text?e.onTextChange(``):t.currentTarget.blur(),u(-1))},v=-1;return(0,B.jsxs)(`div`,{className:P(`relative`,t),children:[(0,B.jsx)(J,{ref:m,wrapperClassName:`w-full bg-surface shadow-none`,leading:e.loading?(0,B.jsx)(af,{className:`size-4`}):(0,B.jsx)(cs,{className:`size-4`}),trailing:e.text?(0,B.jsx)(`button`,{type:`button`,"aria-label":wh(`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:g,children:(0,B.jsx)(bc,{className:`size-3.5`})}):r?(0,B.jsx)(`span`,{className:`hidden md:inline-flex`,children:(0,B.jsx)(bS,{children:`⌘K`})}):void 0,placeholder:e.placeholder,"aria-label":wh(`globalSearch`),role:`combobox`,"aria-autocomplete":`list`,"aria-expanded":f,"aria-controls":a,"aria-activedescendant":f&&d[l]?p(l):void 0,autoFocus:n,value:e.text,onChange:t=>{e.onTextChange(t.target.value),u(-1)},onFocus:()=>c(!0),onBlur:()=>c(!1),onKeyDown:_}),f&&(0,B.jsxs)(`div`,{id:a,role:`listbox`,"aria-label":wh(`searchResults`),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,B.jsx)(`p`,{className:`px-3 py-2 text-muted-foreground`,children:e.loading?wh(`searching`):wh(`noMatches`,{query:e.query})}),e.groups.map(e=>(0,B.jsxs)(`div`,{role:`group`,"aria-label":e.label,children:[(0,B.jsx)(`div`,{className:`px-3 pb-1 pt-2 text-[11px] font-medium uppercase tracking-wide text-faint-foreground`,children:e.label}),e.failed&&(0,B.jsx)(`p`,{className:`px-3 py-1.5 text-danger-text`,children:wh(`couldNotSearch`,{label:e.label})}),e.hits.map(e=>{v+=1;let t=v;return(0,B.jsxs)(`a`,{id:p(t),href:e.href,tabIndex:-1,role:`option`,"aria-selected":t===l,className:P(`block px-3 py-1.5`,t===l?`bg-primary-soft text-primary-text`:`hover:bg-muted`),onMouseDown:e=>e.preventDefault(),onClick:t=>{SS(t)||(t.preventDefault(),h(e.href))},onMouseEnter:()=>u(t),children:[(0,B.jsx)(`span`,{className:`block truncate font-semibold`,children:e.title}),e.subtitle&&(0,B.jsx)(`span`,{className:P(`block truncate text-xs`,t===l?`text-primary-text/80`:`text-muted-foreground`),children:e.subtitle})]},e.id)})]},e.id))]})]})},wS=({breadcrumb:e,onNavigate:t,onBack:n,actions:r,onMenu:i,menuOpen:a,menuControls:o,search:s,sticky:c,slotRef:l,ref:u})=>{let[d,f]=(0,I.useState)(!1),p=yS(e),m=(0,I.useRef)(null);return(0,I.useLayoutEffect)(()=>{if(!s)return;let e=e=>{if(e.key.toLowerCase()!==`k`||!(e.metaKey||e.ctrlKey))return;e.preventDefault();let t=m.current;t&&t.offsetParent!==null?t.focus():f(!0)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[s]),(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(`header`,{ref:u,className:P(c?`sticky top-0 z-30 max-md:fixed max-md:left-[var(--pb-safe-left)] max-md:right-[var(--pb-safe-right)]`:`relative`,`flex h-[calc(3rem+var(--pb-safe-top))] shrink-0 items-center gap-1 border-b bg-background pl-4 pr-2 pt-[var(--pb-safe-top)] md:gap-4 md:px-5`),children:[i&&(0,B.jsx)(`button`,{type:`button`,"aria-label":wh(`openNavigation`),"aria-expanded":!!a,"aria-controls":o,onClick:i,className:P(`inline-flex size-11 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-muted md:hidden`,`-ml-3`),children:(0,B.jsx)(go,{className:`size-5`})}),p&&(0,B.jsx)(`a`,{href:p.href,"aria-label":wh(`backTo`,{label:p.label}),onClick:e=>{let r=n??t;r&&Th(e)&&(e.preventDefault(),r(p.href))},className:P(`inline-flex size-11 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-muted md:hidden`,!i&&`-ml-3`),children:(0,B.jsx)(Di,{className:`size-5`})}),(0,B.jsx)(Eh,{parts:e,onNavigate:t}),(0,B.jsxs)(`div`,{className:`ml-auto flex items-center gap-1 md:gap-3`,children:[s&&(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`div`,{className:`hidden md:block`,children:(0,B.jsx)(CS,{ref:m,search:s})}),(0,B.jsx)(`button`,{type:`button`,"aria-label":wh(`search`),"aria-expanded":d,onClick:()=>f(!0),className:`inline-flex size-11 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-muted md:hidden`,children:(0,B.jsx)(cs,{className:`size-5`})})]}),r,(0,B.jsx)(`div`,{ref:l,className:`contents md:hidden`})]}),s&&d&&(0,B.jsxs)(`div`,{className:`absolute inset-0 z-20 flex items-center gap-1 bg-background px-3 pt-[var(--pb-safe-top)] md:hidden`,children:[(0,B.jsx)(CS,{className:`min-w-0 flex-1`,autoFocus:!0,showShortcut:!1,search:{...s,onSelect:e=>{s.onSelect(e),f(!1)}}}),(0,B.jsx)(`button`,{type:`button`,"aria-label":wh(`closeSearch`),onClick:()=>f(!1),className:`inline-flex size-11 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-muted md:hidden`,children:(0,B.jsx)(bc,{className:`size-5`})})]})]}),c&&(0,B.jsx)(`div`,{"aria-hidden":!0,className:`h-[var(--pb-sticky-top)] shrink-0 md:hidden`})]})},TS=`app-drawer`,ES=({sidebarMode:e,activeItem:t,breadcrumb:n,user:r,workspace:i,appName:a,appIcon:o,logo:s,actions:c,rightPanel:l,sidebarNotice:u,banner:d,forceExpanded:f,profileMenuOpen:p,navGroups:m,userMenu:h,account:g,bottomBar:_,onNavigate:v,onBack:y,onSignOut:b,signIn:x,organizations:S,roles:C,theme:w,status:T,search:E,pageScroll:D=!1,className:O,children:k})=>{let A=xf(),j=gS(e),[ee,te]=(0,I.useState)(!1);(0,I.useEffect)(()=>{A&&te(!1)},[A]);let ne=!A&&_&&_.length>0?_:void 0,[re,ie]=(0,I.useState)(),ae=re??D,oe=(0,I.useRef)(null),[se,ce]=(0,I.useState)(null),le=(0,I.useRef)(null);Ex(ae,oe,le,!!ne),wx(ae);let ue=(e,n=!1,c)=>(0,B.jsx)(hS,{mode:e,sticky:n,notice:c,activeItem:t,user:r,workspace:i,appName:a,appIcon:o,forceExpanded:f,profileMenuOpen:p,groups:m,userMenu:h,account:g,onNavigate:v,onSignOut:b,signIn:x,organizations:S,roles:C,theme:w,status:T,logo:s});return(0,B.jsx)(Sx.Provider,{value:ie,children:(0,B.jsxs)(`div`,{className:P(ae?`flex min-h-full w-full overflow-x-clip bg-background`:`relative flex h-full min-h-0 w-full overflow-hidden bg-background`,O),children:[A?ue(e,ae,j&&u):(0,B.jsx)(xx,{id:TS,open:ee,onClose:()=>te(!1),children:ue(`text-large`)}),(0,B.jsxs)(`div`,{className:P(`flex min-w-0 flex-1 flex-col`,!ne&&`pb-[var(--pb-safe-bottom)]`),children:[(0,B.jsx)(wS,{ref:oe,slotRef:ce,sticky:ae,breadcrumb:n,onNavigate:v,onBack:y,actions:c,onMenu:A||ne?void 0:()=>te(!0),menuOpen:ee,menuControls:TS,search:E}),d,(0,B.jsx)(`main`,{className:ae?`flex flex-1 flex-col`:`flex min-h-0 flex-1 flex-col`,children:(0,B.jsx)(_S.Provider,{value:se,children:k})}),ne&&(0,B.jsx)(bx,{ref:le,sticky:ae,tabs:ne,onNavigate:v,onMore:()=>te(!0),moreOpen:ee,moreControls:TS})]}),l&&(0,B.jsx)(`div`,{className:ae?`sticky top-0 flex h-dvh shrink-0 self-start pt-[var(--pb-safe-top)]`:`flex shrink-0`,children:l})]})})},DS=({title:e,subtitle:t,actions:n,subtitleBelow:r})=>r?(0,B.jsx)(OS,{title:e,subtitle:t,actions:n}):(0,B.jsxs)(`div`,{className:`flex flex-col gap-x-4 gap-y-2 md:flex-row md:items-end md:justify-between`,children:[(0,B.jsxs)(`div`,{className:`min-w-0 break-words md:flex-1`,children:[(0,B.jsx)(`h1`,{className:`text-xl font-semibold tracking-tight`,children:e}),t&&(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:t})]}),n&&(0,B.jsx)(`div`,{className:`flex flex-wrap items-center gap-2 md:justify-end`,children:n})]}),OS=({title:e,subtitle:t,actions:n})=>(0,B.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,B.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-x-4 gap-y-2 md:flex-nowrap`,children:[(0,B.jsx)(`h1`,{className:`min-w-0 break-words text-xl font-semibold tracking-tight md:flex-1`,children:e}),n&&(0,B.jsx)(`div`,{className:`flex flex-wrap items-center gap-2 md:justify-end`,children:n})]}),t&&(0,B.jsx)(`p`,{className:`break-words text-muted-foreground`,children:t})]}),kS=({node:e,children:t,slots:n})=>{let{title:r,description:i}=My(e);return(0,B.jsx)(`div`,{className:`flex-1`,children:(0,B.jsxs)(`div`,{className:`mx-auto flex max-w-[1200px] flex-col gap-6 px-4 pb-16 pt-6 md:px-10 md:py-8`,children:[(0,B.jsx)(DS,{title:r,subtitle:i,actions:n.actions}),t]})})},AS=(e,t)=>{let n=ey(),r=Kb(typeof e==`string`?n:void 0,typeof e==`string`?e:``);return typeof e==`number`?e:e===void 0?t:r.state===`ready`?Number(r.value):r.state===`loading`?void 0:NaN},jS=({node:e})=>{let{value:t,max:n,label:r}=My(e),i=AS(t,0),a=AS(n,100);if(i===void 0||a===void 0)return(0,B.jsx)(Ch,{className:`h-6 w-full`});if(!Number.isFinite(i)||!Number.isFinite(a))return null;let o=a>0?Math.min(1,Math.max(0,i/a)):0;return(0,B.jsxs)(`div`,{className:`min-w-0`,children:[(0,B.jsxs)(`div`,{className:`flex items-baseline justify-between gap-2 text-body`,children:[(0,B.jsx)(`span`,{className:`text-muted-foreground`,children:r}),(0,B.jsxs)(`span`,{className:`tabular-nums`,children:[i.toLocaleString(Le()),` / `,a.toLocaleString(Le())]})]}),(0,B.jsx)(`div`,{role:`progressbar`,"aria-label":r,"aria-valuenow":i,"aria-valuemin":0,"aria-valuemax":a,className:`mt-1.5 h-2 overflow-hidden rounded-full bg-muted`,children:(0,B.jsx)(`div`,{className:o>=.9?`h-full rounded-full bg-warning`:`h-full rounded-full bg-primary`,style:{width:`${o*100}%`}})})]})},MS=({model:e,filter:t,sort:n,recordKey:r,title:i,description:a,empty:o,actions:s,children:c})=>{let l=Ey(e,{filter:t,sort:n,key:r}),u=e=>l.data?(0,B.jsx)($v,{value:l.data,children:e}):void 0,d=l.isPending?(0,B.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,B.jsx)(Ch,{className:`h-4 w-1/2`}),(0,B.jsx)(Ch,{className:`h-4 w-1/3`})]}):l.error?(0,B.jsx)(Gg,{title:fv(`couldNotLoad`),error:l.error}):l.data?u((0,B.jsx)(`div`,{className:`flex flex-col gap-3`,children:c})):(0,B.jsx)(Iy,{children:o??fv(`nothingYet`)});return(0,B.jsx)(Fy,{title:i,description:a,actions:s?u(s):void 0,className:`h-full`,children:d})},NS=({node:e,children:t,slots:n})=>{let{resource:r,filter:i,sort:a,recordKey:o,title:s,description:c,empty:l}=My(e),u=W().resources[r];return u?(0,B.jsx)(MS,{model:u,filter:i,sort:a,recordKey:o,title:s,description:c,empty:l,actions:n.actions,children:t}):null},PS=`0.75rem`,FS=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% + ${PS}) * ${e} - ${PS})`},IS=({share:e,label:t,children:n})=>(0,B.jsx)(`ul`,{"aria-label":t,className:`flex snap-x snap-mandatory items-start overflow-x-auto overflow-y-hidden overscroll-x-contain pb-1 *:w-(--snap-item-width) *:min-w-[min(100%,12rem)] *:shrink-0 *:snap-start`,style:{gap:PS,scrollbarWidth:`thin`,"--snap-item-width":FS(e)},children:n}),LS=M(`app/embedded-list`),RS=(e,t,n)=>{if(!(e>=t))return LS(n?`firstOfAbout`:`firstOf`,{shown:e,total:t.toLocaleString(Le())})},zS=`protobase:embedded-display:`,BS=e=>`${zS}${e}`,VS=(e,t)=>Ie(()=>e.getItem(t)??void 0,void 0),HS=(e,t,n)=>Ie(()=>e.setItem(t,n),void 0),US=(e,t,{picked:n,preferred:r})=>{let i=ih(e).map(e=>e.name);return n!==void 0&&i.includes(n)?n:Xm(e,t,r!==void 0&&i.includes(r)?r:void 0)},WS=(e,t,n,{resource:r=e.name,...i})=>Sh({kind:`list`,resource:r},i,{...bh(e,t,n),display:Xm(t,n)}),GS=M(`app/related-cards`),KS=({children:e})=>{let t=(0,I.useRef)(null),[n,r]=(0,I.useState)(!1),[i,a]=(0,I.useState)(!1);return(0,I.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,B.jsxs)(`div`,{className:`flex flex-col items-start gap-1`,children:[(0,B.jsx)(`div`,{className:P(`w-full min-w-0`,!n&&`max-h-40 overflow-hidden`),children:(0,B.jsx)(`div`,{ref:t,children:e})}),(i||n)&&(0,B.jsx)(G,{size:`sm`,variant:`ghost`,className:`-ml-2`,"aria-expanded":n,onClick:()=>r(!n),children:GS(n?`showLess`:`showMore`)})]})},qS=e=>e==null||e===``,JS=({scope:e,path:t})=>{let{views:n}=W(),r=Kb(e,t);if(r.state===`missing`||r.state===`ready`&&qS(r.value))return null;let i=Jb(t,r.state===`ready`?n[r.model.name]?.fields[r.field.name]?.label:void 0);return(0,B.jsxs)(`div`,{className:`min-w-0`,children:[(0,B.jsx)(`dt`,{className:`text-body text-muted-foreground`,children:i}),(0,B.jsx)(`dd`,{className:`mt-0.5`,children:r.state===`loading`?(0,B.jsx)(Ch,{className:`h-4 w-24`}):(0,B.jsx)(KS,{children:(0,B.jsx)(Hb,{model:r.model,field:r.field,value:r.value})})})]})},YS=({scope:e,view:t,fields:n,actions:r})=>{let i=v_();return(0,B.jsxs)(`li`,{className:`flex min-w-0 flex-col gap-3 rounded-lg border border-border bg-surface p-4`,children:[(0,B.jsx)(Jh,{to:{kind:`record`,resource:e.model.name,key:wm(e.model,e.record)},className:`self-start font-medium text-primary-text hover:underline`,children:i(e.model,t,e.record,e.key)}),n.length>0&&(0,B.jsx)(`dl`,{className:`flex flex-col gap-3`,children:n.map(t=>(0,B.jsx)(JS,{scope:e,path:t},t))}),r.length>0&&(0,B.jsx)($v,{value:e,children:(0,B.jsx)(`div`,{className:`flex flex-wrap items-center gap-2`,children:r.map(e=>(0,B.jsx)(Ny,{name:e},e))})})]})},XS=({model:e,view:t,filter:n,sort:r,fields:i,actions:a,limit:o,display:s,empty:c,carousel:l})=>{let u=Sf(),d=r||gh(e,t),f=Dy(e,{filter:n,sort:d,pageSize:o}),p=Ty(e,n);if(f.isPending)return(0,B.jsx)(`div`,{className:`flex flex-col gap-3`,children:Array.from({length:2},(e,t)=>(0,B.jsx)(Ch,{className:`h-24 w-full`},t))});if(f.error)return(0,B.jsx)(Gg,{title:GS(`couldNotLoad`),error:f.error});let m=f.data.items;if(m.length===0)return(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:c??GS(`nothingYet`)});let h=m.map(n=>{let r=Cy(e,n);return(0,B.jsx)(YS,{scope:r,view:t,fields:i,actions:a},r.key)}),g=p.data===void 0?void 0:RS(m.length,p.data,!1);return(0,B.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[l===void 0?(0,B.jsx)(`ul`,{className:`flex flex-col gap-3`,children:h}):(0,B.jsx)(IS,{share:l,children:h}),(0,B.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:g}),(0,B.jsxs)(Jh,{to:WS(e,t,u,{filter:n,orderBy:d,display:US(t,u,{preferred:s})}),className:`flex items-center gap-1 font-medium text-primary-text hover:underline`,children:[LS(`viewAll`),` `,(0,B.jsx)(`span`,{className:`sr-only`,children:(t?.names?.plural??F(e.name)).toLowerCase()}),(0,B.jsx)(zr,{className:`size-3.5`,"aria-hidden":!0})]})]})]})},ZS={"1/4":1/4,"1/3":1/3,"1/2":1/2,"2/3":2/3},QS=({node:e,slots:t})=>{let n=My(e),{resource:r,filter:i=``,sort:a=``,fields:o,cardActions:s=[],limit:c=10,display:l,title:u,description:d,empty:f}=n,{layout:p,cardWidth:m}=Su(n),{resources:h,views:g}=W(),_=h[r];if(!_)return null;let v=g[_.name];return(0,B.jsx)(`section`,{className:`min-w-0`,"aria-label":u,children:(0,B.jsx)(Gf,{title:u,help:d,actions:t.actions,children:(0,B.jsx)(XS,{model:_,view:v,filter:i,sort:a,fields:o??Er(_,v),actions:s,limit:c,display:l,empty:f,carousel:p===`carousel`?ZS[m]:void 0})})})},$S=e=>t=>{let n=t.currentTarget;n.scrollWidth>Math.ceil(n.getBoundingClientRect().width)?n.title=e:n.removeAttribute(`title`)},eC=({text:e,className:t})=>(0,B.jsx)(`span`,{className:P(`truncate`,t),onMouseEnter:$S(e),children:e}),tC=e=>(0,B.jsx)(`span`,{className:`text-faint-foreground`,children:e}),nC=(e,t)=>{if(t==null)return tC(`—`);let n=Qp(e,t)??``;switch(e.kind){case`text`:return e.link?(0,B.jsx)(Tv,{format:e.link,value:n,className:`block min-w-0 truncate`}):(0,B.jsx)(eC,{text:n});case`id`:return(0,B.jsx)(eC,{text:n,className:`font-mono text-xs text-muted-foreground`});case`money`:return(0,B.jsx)(`span`,{className:`tabular-nums`,children:n});case`date`:return(0,B.jsx)(`span`,{className:`tabular-nums text-muted-foreground`,children:n});case`datetime`:return(0,B.jsx)(`span`,{className:`tabular-nums text-muted-foreground`,title:e.relative?gp(Number(t)):Xp(`shownIn`,{zone:ap(Number(t),Xf())}),children:n});case`number`:return(0,B.jsx)(`span`,{className:`tabular-nums`,children:n});case`signed`:return(0,B.jsx)(`span`,{className:P(`tabular-nums`,Number(t)<0?`text-danger-text`:`text-success-text`),children:n});case`percent`:return Number(t)===0?tC(`—`):(0,B.jsx)(`span`,{className:`tabular-nums`,children:n});case`status`:return(0,B.jsx)(zf,{tone:e.tones?.[String(t)]??`neutral`,color:Am(e.colors,t),shape:e.shape,children:n});case`relation`:return(0,B.jsx)(eC,{text:n,className:`font-medium text-primary-text hover:underline`});case`boolean`:return t?(0,B.jsx)(`span`,{className:`inline-flex size-4 items-center justify-center rounded-full bg-success-soft text-success-text`,children:(0,B.jsx)(Ci,{className:`size-3`,strokeWidth:3})}):tC(Xp(`no`));case`file`:{let e=Rp(t);if(!e)return tC(`—`);if(`missing`in e)return(0,B.jsx)(eC,{text:e.name,className:`text-danger-text`});let n=Kp(t,{width:20,height:20});return(0,B.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-2`,children:[n?(0,B.jsx)(I_,{image:n,className:`size-5 shrink-0 rounded-sm object-cover`}):(0,B.jsx)(Io,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,B.jsx)(eC,{text:e.name})]})}case`user`:{let r=e.users?.(String(t));return r?(0,B.jsxs)(`span`,{className:`inline-flex items-center gap-2 truncate`,children:[(0,B.jsx)(Vf,{initials:r.initials,hue:r.hue,size:`xs`,className:`ring-0`}),(0,B.jsx)(eC,{text:r.name,className:`text-muted-foreground`})]}):(0,B.jsx)(eC,{text:n,className:`text-muted-foreground`})}}},rC=Ae({rowSortingFeature:C,rowSelectionFeature:s}),iC=w(),aC=e=>iC.columns(e.map(e=>iC.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):nC(e,t.getValue())}))),oC=(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}]}),sC=({total:e,selectedCount:t,bulkActions:n=[],className:r})=>(0,B.jsx)(`div`,{className:P(`flex h-9 shrink-0 items-center border-t bg-surface px-3 text-xs text-muted-foreground`,r),children:(0,B.jsxs)(`span`,{className:`flex items-center tabular-nums`,children:[Mp(e),t>0&&(0,B.jsx)(`span`,{className:`ml-3 font-medium text-primary-text`,children:Xp(`selected`,{count:kp(t)})}),t>0&&n.map(e=>(0,B.jsx)(`button`,{type:`button`,onClick:e.onRun,className:P(`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))]})}),cC=(e,t)=>typeof e.label==`string`?e.label:e.label(t),lC=(e,t)=>e.filter(e=>e.available?.(t)??!0),uC=({row:e,actions:t})=>{let{open:n,setOpen:r,place:i,button:a,menu:o}=cg();return(0,B.jsxs)(`div`,{className:`relative flex justify-center bg-inherit`,onClick:e=>e.stopPropagation(),children:[(0,B.jsx)(`button`,{ref:a,type:`button`,"aria-label":Xp(`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,B.jsx)(la,{className:`size-4`})}),n&&(0,Cc.createPortal)((0,B.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=cC(t,e),a=t.blocked?.(e),o=P(`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,B.jsx)(`li`,{role:`none`,children:t.link&&a===void 0?(0,B.jsx)(Dh,{role:`menuitem`,to:t.link(e),onClick:()=>r(!1),className:o,children:i}):(0,B.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)]})},dC=e=>52+Math.ceil(String(e).length*1.33)*7,fC=.6,pC=(e,t)=>Math.max(e.minWidth??0,e.width*t),mC=(e,t)=>e.fixed?`${Math.max(e.minWidth??0,e.width)}px`:`minmax(${pC(e,t)}px, ${e.width}fr)`,hC=(e,t,n=0,r=fC)=>`${t}px ${e.map(e=>mC(e,r)).join(` `)}${n>0?` ${n}px`:``}`,gC=(e,t,n=0,r=fC)=>t+n+e.reduce((e,t)=>e+(t.fixed?Math.max(t.minWidth??0,t.width):pC(t,r)),0),_C=()=>{let e=(0,I.useRef)(null),t=(0,I.useRef)(null),[n,r]=(0,I.useState)({scrolled:!1,more:!1}),i=(0,I.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,I.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}},vC=`protobase:pinned:`,yC=(e,t)=>`${vC}${e}:${t}`,bC=(e,t)=>Ie(()=>{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),xC=(e,t,n)=>Ie(()=>e.setItem(t,JSON.stringify(n)),void 0),SC=(e,t=[])=>{let[n,r]=(0,I.useState)(()=>e?bC(localStorage,e):void 0),i=(0,I.useCallback)(t=>{r(t),e&&xC(localStorage,e,t)},[e]);return[n??t,i]},CC=e=>{let t=e.findIndex(e=>e.title);return t<0||t>1?[]:e.slice(0,t+1).map(e=>e.id)},wC=e=>Object.fromEntries(e.map(({id:e,width:t,minWidth:n,fixed:r})=>[e,{width:t,minWidth:n,fixed:r}])),TC=(e,t)=>{let n=e.map(e=>e.id).sort().join(` `),[r,i]=(0,I.useState)(),a=r?.key===n?r:void 0;!a&&t.length>0&&i({key:n,sizes:wC(hm(e,t))});let o=a?.sizes;return(0,I.useMemo)(()=>o?e.map(e=>({...e,...o[e.id]})):e,[e,o])},EC=(e,t)=>Math.max(Math.min(64,e),Math.round(e+t)),DC=(e,t)=>e.map(e=>e.id in t?{...e,fixed:!0,width:t[e.id],minWidth:void 0}:e),OC=e=>Object.fromEntries([...e.querySelectorAll(`[data-col-id]`)].map(e=>[e.dataset.colId,e.offsetWidth])),kC=e=>{let[t,n]=(0,I.useState)({}),r=()=>({...e.current?OC(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]:EC(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]:EC(a[e]??0,i)})}}},AC=({checked:e,indeterminate:t,onChange:n,label:r,disabled:i,className:a})=>(0,B.jsx)(`button`,{type:`button`,role:`checkbox`,"aria-checked":t?`mixed`:e,"aria-label":r,disabled:i,onClick:()=>n?.(!e),className:P(`relative inline-flex size-4 shrink-0 items-center justify-center rounded border transition-colors after:absolute after:-inset-1 after:content-[""] pointer-coarse:after:-inset-3.5`,e||t?`border-primary bg-primary text-primary-foreground`:`border-border-strong bg-background hover:border-faint-foreground`,a),children:t?(0,B.jsx)(So,{className:`size-3`,strokeWidth:3}):e&&(0,B.jsx)(Ci,{className:`size-3`,strokeWidth:3})}),jC=e=>e===`money`||e===`number`||e===`signed`||e===`percent`,MC=()=>Xp(`unsortable`),NC=({header:e,pinned:t,sortable:n,onTogglePin:r})=>{let{open:i,setOpen:a,place:o,button:s,menu:c}=cg();return(0,B.jsxs)(`div`,{className:`relative ml-auto shrink-0`,children:[(0,B.jsx)(`button`,{ref:s,type:`button`,"aria-label":Xp(`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,B.jsx)(la,{className:`size-3.5`})}),i&&(0,Cc.createPortal)((0,B.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,B.jsx)(`li`,{role:`none`,children:(0,B.jsx)(`span`,{role:`menuitem`,"aria-disabled":`true`,className:`block min-h-9 whitespace-nowrap px-3 py-1.5 text-muted-foreground`,children:MC()})}),(0,B.jsx)(`li`,{role:`none`,children:(0,B.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:Xp(t?`unpin`:`pinToLeft`)})})]}),document.body)]})},PC=({id:e,header:t,width:n,resize:r})=>(0,B.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":Xp(`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,B.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`})}),FC=({sorted:e})=>e===`asc`?(0,B.jsx)(Gr,{className:`size-3 text-foreground`}):e===`desc`?(0,B.jsx)(Fr,{className:`size-3 text-foreground`}):(0,B.jsx)(ji,{className:`size-3 opacity-0 group-hover/head:opacity-100`}),IC=({spec:e})=>(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`span`,{className:`truncate`,children:e.header}),e.highlight&&(0,B.jsx)(`span`,{className:`rounded bg-primary px-1 text-[10px] font-semibold uppercase leading-4 text-primary-foreground`,children:Xp(`new`)})]}),LC=({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,B.jsxs)(`div`,{className:`grid h-8 shrink-0 items-center border-b bg-surface text-body font-medium text-muted-foreground`,style:{gridTemplateColumns:hC(t,n,a,o)},role:`row`,children:[(0,B.jsxs)(`div`,{className:P(`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,B.jsx)(AC,{checked:!1,indeterminate:r>0,label:Xp(r>0?`clearSelection`:`noRowsSelected`),disabled:r===0,onChange:p,className:P(r===0&&`opacity-60`)}),n>40&&(0,B.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,B.jsxs)(`div`,{"data-col-id":e.id,style:r?{left:s[e.id]}:void 0,className:P(`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,B.jsxs)(`button`,{type:`button`,onClick:n,className:P(`group/head flex h-full min-w-0 flex-1 items-center gap-1 pl-3 pr-1 text-left`,jC(e.kind)&&`justify-end`,`hover:text-foreground`,t&&`text-foreground`),children:[(0,B.jsx)(IC,{spec:e}),(0,B.jsx)(FC,{sorted:t})]}):(0,B.jsx)(`div`,{title:MC(),className:P(`flex h-full min-w-0 flex-1 items-center gap-1 pl-3 pr-1 text-left`,jC(e.kind)&&`justify-end`),children:(0,B.jsx)(IC,{spec:e})}),(0,B.jsx)(`div`,{className:`pr-1.5`,children:(0,B.jsx)(NC,{header:e.header,pinned:r,sortable:!!e.sortable,onTogglePin:()=>u(e.id)})}),d&&(0,B.jsx)(PC,{id:e.id,header:e.header,width:f[e.id],resize:d})]},e.id)}),a?(0,B.jsx)(`div`,{className:`sticky right-0 z-10 h-full bg-inherit`}):null]}),RC=e=>({gridTemplateColumns:hC(e.specs,e.gutter,e.trailing,e.minScale),height:e.height,transform:`translateY(${e.offset}px)`}),zC=(e,t)=>P(`flex h-full min-w-0 items-center overflow-hidden whitespace-nowrap px-3`,jC(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)]`),BC=(e,t)=>t&&e.id in t?{left:t[e.id]}:void 0,VC=({width:e,index:t,selectable:n,selected:r,onToggle:i,edge:a})=>(0,B.jsxs)(`div`,{onClick:n?e=>{e.stopPropagation(),i?.()}:void 0,className:P(`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,B.jsx)(AC,{checked:!!r,label:Xp(`selectRow`,{row:t+1})}),e>40&&(0,B.jsx)(`span`,{className:`min-w-6 text-right text-[11px] tabular-nums text-faint-foreground`,children:kp(t+1)})]}),HC=(e,t,n)=>({gridTemplateColumns:hC(e.specs,e.gutter,e.trailing,e.minScale),height:e.height,top:e.offset,transform:t===0?void 0:`translateY(${t}px)`,transition:n}),UC=e=>t=>{t.target.closest(`a`)||e()},WC=({cells:e,selected:t,onToggle:n,onOpen:r,menu:i,handle:a,rowRef:o,dragY:s,transition:c,dragging:l,...u})=>(0,B.jsxs)(`div`,{ref:o,role:`row`,onClick:r&&UC(r),className:P(`absolute inset-x-0 top-0 grid items-center border-b`,t?`bg-primary-soft`:`bg-background hover:bg-surface`,r&&`cursor-pointer`,l&&`z-30 bg-surface shadow-pop`),style:s===void 0?RC(u):HC(u,s,c),children:[a?(0,B.jsx)(`div`,{className:P(`sticky left-0 z-10 flex h-full items-center bg-inherit pl-1.5`,u.scrolled&&!u.lastPinned&&`shadow-[1px_0_0_var(--border),4px_0_6px_-2px_rgb(0_0_0/0.12)]`),style:{width:u.gutter},children:a}):(0,B.jsx)(VC,{width:u.gutter,index:u.index,selectable:u.selectable,selected:t,onToggle:n,edge:u.scrolled&&!u.lastPinned}),e.map(({spec:e,content:t,props:n,chosen:r,editing:i,editable:a})=>(0,B.jsx)(`div`,{role:n?`gridcell`:`cell`,...n,className:P(zC(e,u),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:BC(e,u.pins),children:t},e.id)),i&&(0,B.jsx)(`div`,{className:`sticky right-0 z-10 flex h-full items-center justify-center bg-inherit`,children:i})]}),GC=[`w-3/4`,`w-1/2`,`w-2/3`,`w-5/6`,`w-2/5`],KC=e=>(0,B.jsxs)(`div`,{role:`row`,"aria-busy":!0,className:`absolute inset-x-0 top-0 grid items-center border-b bg-background`,style:RC(e),children:[(0,B.jsx)(VC,{width:e.gutter,index:e.index,selectable:!1,edge:e.scrolled&&!e.lastPinned}),e.specs.map((t,n)=>(0,B.jsx)(`div`,{className:zC(t,e),style:BC(t,e.pins),children:(0,B.jsx)(Ch,{className:P(`h-2.5`,GC[(e.index+n)%GC.length],jC(t.kind)&&`ml-auto`)})},t.id))]}),qC=(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}}},JC=(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)},YC=(e,t)=>Math.max(0,Math.min(40,e-t*40)),XC=({total:e,rowAt:t,loadRows:n,revision:r,latencyMs:i},a,o)=>{let s=(0,I.useMemo)(()=>qC(40,60),[t,n]),[c,l]=(0,I.useState)(0),u=Math.floor(a/40),d=Math.floor(o/40),f=!n&&i===0;(0,I.useEffect)(()=>{if(f)return;let r=JC(u*40,d*40,40).filter(e=>!s.hasPage(e)),a=t=>YC(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,I.useRef)(r);return(0,I.useEffect)(()=>{if(!n||r===p.current)return;p.current=r;let t=JC(u*40,d*40,40);s.keepOnly(t);for(let r of t.filter(e=>s.hasPage(e)))n(r*40,YC(e,r)).then(e=>{s.setPage(r,e),l(e=>e+1)})},[s,r,n,u,d,e]),(0,I.useCallback)(e=>f?t(e):s.get(e),[s,f,t,c])},ZC=1e7,QC=(e,t,n)=>{let r=e*t,i=Math.min(r,ZC);return{rowHeight:t,trueHeight:r,contentHeight:i,scaled:r>i,maxTop:Math.max(0,r-n),maxScroll:Math.max(0,i-n)}},$C=(e,t)=>!e.scaled||t<=0?t:t>=e.maxScroll?e.maxTop+t-e.maxScroll:t/e.maxScroll*e.maxTop,ew=(e,t)=>!e.scaled||t<=0?t:t>=e.maxTop?e.maxScroll+t-e.maxTop:t/e.maxTop*e.maxScroll,tw=(e,t,n,r)=>{let i=t*e.rowHeight;return e.scaled?i-n+r:i},nw=(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)}},rw=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},iw=e=>e===(document.scrollingElement??document.documentElement),aw=e=>iw(e)?window:e,ow=e=>Number.parseFloat(e)||0,sw=e=>{let t=getComputedStyle(e),n=iw(e)?{top:0,height:e.clientHeight}:{top:e.getBoundingClientRect().top+e.clientTop,height:e.clientHeight},r=ow(t.scrollPaddingTop);return{top:n.top+r,height:Math.max(0,n.height-r-ow(t.scrollPaddingBottom))}},cw=6,lw=(e,t,n)=>{let r=QC(t,n,e.height),i=$C(r,e.position);return{geometry:r,top:i,topIndex:Math.floor(Math.max(0,i)/n),...nw(t,i,n,e.height,cw)}},uw=({total:e,rowHeight:t,initialIndex:n,inset:r=0,settle:i,ready:a=!0,onScroll:o})=>{let s=(0,I.useRef)(null),c=(0,I.useRef)(null),[l,u]=(0,I.useState)({position:0,height:0}),d=(0,I.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,I.useCallback)(()=>{let e=s.current;if(!e||!c.current)return;let t=sw(c.current),n=d.current.inset;return{position:t.top+n-e.getBoundingClientRect().top,height:Math.max(0,t.height-n)}},[]),p=(0,I.useRef)({pending:!0,laidOut:!1}),m=(0,I.useRef)(l);m.current=l;let h=(0,I.useCallback)(()=>{let e=f();if(!e)return;let t=m.current,{total:n,rowHeight:r,onScroll:i}=d.current,a=lw(t,n,r),o=lw(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,I.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+=ew(QC(n,r,e.height),i*r)-e.position:e.position>0&&(t.scrollTop=0)},[f]);(0,I.useLayoutEffect)(()=>{let e=s.current;if(!e)return;let t=rw(e);c.current=t;let n=aw(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,I.useLayoutEffect)(()=>{g(),h()});let _=(0,I.useCallback)(e=>{let t=f();if(!t||!c.current)return;let n=QC(d.current.total,d.current.rowHeight,t.height);c.current.scrollTop+=ew(n,e)-t.position,h()},[f,h]),v=(0,I.useCallback)(()=>!p.current.pending,[]),y=lw(l,e,t),b=i?i(y.top):y.top,{first:x,last:S}=i?nw(e,b,t,l.height,cw):y,C=Array.from({length:S-x+1},(e,t)=>({index:x+t,offset:tw(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}},dw=e=>e===`ArrowUp`||e===`ArrowDown`||e===`ArrowLeft`||e===`ArrowRight`,fw=(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},pw=(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)},mw=e=>`${e.index}:${e.column}`,hw=({editor:e,columns:t,total:n,rowAt:r,onOpenRow:i,container:a})=>{let[o,s]=(0,I.useState)(),[c,l]=(0,I.useState)(!1),u=(0,I.useRef)(!1),d=(0,I.useRef)(!1);if((0,I.useEffect)(()=>{if(!o||c||!u.current)return;u.current=!1;let e=a.current?.querySelector(`[data-cell="${mw(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?pw(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":mw(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!==mw(o))return;let a=e.key===`Tab`?e.shiftKey?`ArrowLeft`:`ArrowRight`:e.key;if(dw(a)){let i=fw(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)}}},gw=({ids:e,rowAt:t,reorder:n,children:r})=>{let i=ne(Me(se,{activationConstraint:{distance:4}}),Me(xe,{activationConstraint:{delay:250,tolerance:5}}),Me(ae,{coordinateGetter:ye})),a=t=>e.indexOf(String(t)),o=e=>{let r=t(a(e));return r?n.label(r):Xp(`row`)};return(0,B.jsx)(me,{sensors:i,collisionDetection:ge,onDragEnd:({active:e,over:t})=>{t&&e.id!==t.id&&n.onMove(a(e.id),a(t.id))},accessibility:{announcements:{onDragStart:({active:t})=>Xp(`pickedUp`,{name:o(t.id),row:a(t.id)+1,rows:e.length}),onDragOver:({active:t,over:n})=>n?Xp(`isOver`,{name:o(t.id),row:a(n.id)+1,rows:e.length}):void 0,onDragEnd:({active:t,over:n})=>n?Xp(`droppedAt`,{name:o(t.id),row:a(n.id)+1,rows:e.length}):Xp(`putBack`,{name:o(t.id)}),onDragCancel:({active:e})=>Xp(`cancelled`,{name:o(e.id),row:a(e.id)+1})},screenReaderInstructions:{draggable:Xp(`reorderInstructions`)}},children:(0,B.jsx)(ue,{items:e,strategy:re,children:r})})},_w=({row:e,label:t,...n})=>{let{attributes:r,listeners:i,setNodeRef:a,setActivatorNodeRef:o,transform:s,transition:c,isDragging:l}=Te({id:e.id}),u=(0,B.jsx)(`button`,{ref:o,type:`button`,"aria-label":Xp(`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,B.jsx)(Ta,{className:`size-4`})});return(0,B.jsx)(WC,{...n,rowRef:a,handle:u,dragY:s?.y??0,transition:c,dragging:l})},vw=32,yw=({columns:e,source:t,naturalSort:n,initialScrollIndex:r=0,onScrollIndex:i,latencyMs:a=150,sort:o,onSortChange:s,onOpenRow:c,rowLink:l,rowActions:u,cellEditor:d,rowPatches:f,bulkActions:p,pinKey:m,defaultPinned:h,rowNumbers:g=!0,compact:_=!1,selectable:v=!0,reorder:y,fit:b=!1,scroll:x=`own`,className:S})=>{let C=v&&!y,w=_?28:36,T=!xf(),E=(h??(T?[]:CC(e))).join(` `),[D,O]=SC(m,(0,I.useMemo)(()=>E?E.split(` `):[],[E])),k=(0,I.useMemo)(()=>[...D.flatMap(t=>e.find(e=>e.id===t)??[]),...e.filter(e=>!D.includes(e.id))],[e,D]),A=k.slice(0,k.filter(e=>D.includes(e.id)).length).map(e=>e.id),{total:j}=t,[ee,te]=(0,I.useState)(n?[{id:n.columnId,desc:n.direction===`desc`}]:[]),ne=o?[{id:o.columnId,desc:o.direction===`desc`}]:ee,re=e=>{let t=typeof e==`function`?e(ne):e,n=t[0];s&&n&&s({columnId:n.id,direction:n.desc?`desc`:`asc`}),o||te(t)},[ie,ae]=(0,I.useState)({}),oe=(0,I.useMemo)(()=>aC(k),[k]),se=ne[0],ce=!!(!o&&n&&se&&se.id===n.columnId&&(se.desc?`desc`:`asc`)!==n.direction),le=t.rowAt,ue=(0,I.useCallback)(e=>le(ce?j-1-e:e),[le,ce,j]),[de]=(0,I.useState)(r),{ref:fe,geometry:pe,rows:me,first:he,last:ge}=uw({total:j,rowHeight:w,initialIndex:de,inset:vw,onScroll:i&&(e=>i(e/w))}),_e=T||!g?40:dC(j),ve=XC({total:j,rowAt:le?ue:void 0,loadRows:t.loadRows,revision:t.revision,latencyMs:a},he,ge),ye=(0,I.useCallback)(e=>{let t=ve(e),n=t&&f?.get(t.id);return n?{...t,...n}:t},[ve,f]),be=me.map(({index:e,offset:t})=>({index:e,offset:t,row:ye(e)})),xe=(0,I.useMemo)(()=>be.flatMap(({row:e})=>e?[e]:[]),[ye,he,ge]),Se=(0,I.useRef)(null),Ce=kC(Se),we=TC(k,xe),Te=(0,I.useMemo)(()=>DC(we,Ce.widths),[we,Ce.widths]),Ee=je({features:rC,columns:oe,data:xe,state:{sorting:ne,rowSelection:ie},onSortingChange:re,onRowSelectionChange:ae,manualSorting:!0,enableMultiSort:!1,enableSortingRemoval:!1,getRowId:e=>e.id}),De=new Map(Ee.getRowModel().rows.map(e=>[e.id,e])),Oe=Object.keys(ie).length,ke=(0,I.useRef)(new Map);for(let e of Ee.getRowModel().rows)e.getIsSelected()&&ke.current.set(e.id,e.original);let Ae=u&&u.length>0?40:0,Me=T?1:fC,Ne=_C(),M=()=>{Ne.onScroll(),Se.current&&Ne.ref.current&&(Se.current.scrollLeft=Ne.ref.current.scrollLeft)},[Pe,Fe]=(0,I.useState)({});(0,I.useLayoutEffect)(()=>{let e=Se.current?.querySelector(`[role=row]`);if(!e)return;let t=_e,n={};for(let r of A)n[r]=t,t+=e.querySelector(`[data-col-id="${r}"]`)?.offsetWidth??0;JSON.stringify(Pe)!==JSON.stringify(n)&&Fe(n)});let Ie=A.at(-1),Le=e=>O(D.includes(e)?D.filter(t=>t!==e):[...D,e]),Re=Ee.getHeaderGroups().flatMap(e=>e.headers.map(e=>({spec:k.find(t=>t.id===e.column.id),sorted:e.column.getIsSorted(),onSort:t=>e.column.getToggleSortingHandler()?.(t)}))),N=(0,I.useRef)(null),ze=hw({editor:d,columns:(0,I.useMemo)(()=>k.map(e=>e.id),[k]),total:j,rowAt:ye,onOpenRow:c,container:N}),Be=(k.find(e=>e.title)??k[0])?.id,Ve=gC(Te,_e,Ae,Me),He=x===`own`,Ue=(0,B.jsx)(`div`,{ref:Se,className:P(`sticky z-20 shrink-0 overflow-hidden`,He?`top-0`:`top-[var(--pb-sticky-top,0px)]`),children:(0,B.jsx)(`div`,{style:{minWidth:Ve},children:(0,B.jsx)(LC,{cells:Re,specs:Te,gutter:_e,trailing:Ae,minScale:Me,pins:Pe,lastPinned:Ie,scrolled:Ne.scrolled,onTogglePin:Le,resize:Ce,widths:Ce.widths,selectable:C,selectedCount:Oe,onClearSelection:()=>ae({})})})}),We=be.map(({index:e,offset:t,row:n})=>{let r={specs:Te,gutter:_e,index:e,offset:t,height:w,selectable:C,trailing:Ae,minScale:Me,scrolled:Ne.scrolled,pins:Pe,lastPinned:Ie},i=n?De.get(n.id):void 0;if(!i||!n)return(0,B.jsx)(KC,{...r},`skeleton-${e}`);let a=Ae?lC(u,n):[],o={...r,selected:i.getIsSelected(),onToggle:()=>i.toggleSelected(),onOpen:c?()=>c(n):void 0,menu:a.length>0?(0,B.jsx)(uC,{row:n,actions:a}):void 0,cells:i.getAllCells().map(t=>{let r=(0,B.jsx)(Ee.FlexRender,{cell:t}),i=!!d?.editable(n,t.column.id),a=l&&t.column.id===Be&&!i?(0,B.jsx)(Dh,{to:l(n),className:`flex min-w-0 items-center hover:underline`,children:r}):r;return{spec:k.find(e=>e.id===t.column.id),...ze?ze.cell(e,n,t.column.id,a):{content:a}}})};return y?(0,B.jsx)(_w,{...o,row:n,label:y.label(n)},n.id):(0,B.jsx)(WC,{...o},n.id)}),Ge=(0,B.jsx)(`div`,{ref:Ne.attach,onScroll:M,className:`overflow-x-auto overflow-y-hidden overscroll-x-contain [-webkit-overflow-scrolling:touch]`,children:(0,B.jsx)(`div`,{ref:fe,className:`relative`,style:{minWidth:Ve,height:pe.contentHeight},children:y?(0,B.jsx)(gw,{ids:Array.from({length:j},(e,t)=>ye(t)?.id??`missing-${t}`),rowAt:ye,reorder:y,children:We}):We})});return(0,B.jsxs)(`div`,{ref:N,role:`grid`,"aria-rowcount":j,onKeyDown:ze?.onKeyDown,className:P(`flex flex-col rounded-lg border bg-background`,He?`min-h-0 overflow-hidden`:`overflow-clip`,S),style:b&&He?{height:vw+j*w+2}:void 0,children:[(0,B.jsxs)(`div`,{className:P(`relative`,He&&`flex min-h-0 flex-1 flex-col`),children:[He?(0,B.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overflow-x-hidden`,children:[Ue,Ge]}):(0,B.jsxs)(B.Fragment,{children:[Ue,Ge]}),Ne.more&&(0,B.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`})]}),!b&&(0,B.jsx)(sC,{total:j,className:He?void 0:`sticky bottom-[var(--pb-sticky-bottom,0px)] z-20`,selectedCount:Oe,bulkActions:oC(p??[],Object.keys(ie).flatMap(e=>ke.current.get(e)??[])).map(({action:e,rows:t,skipped:n})=>({label:e.label(t.length),destructive:e.destructive,onRun:()=>{e.onRun(t,n),ae({}),ke.current.clear()}}))})]})},bw=500,xw=async(e,t,n)=>{let r=[],i={},a;do{let o=await e.search(t,{...n,pageSize:bw,...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}},Sw=sn(),Cw=(...e)=>{let t=e.filter(e=>!!e);return t.length===1?t[0]:t.map(e=>`(${e})`).join(` AND `)},ww=e=>e==null?void 0:String(e),Tw=(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=ww(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},Ew=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 xw(e,a.name,{filter:Cw(Yt(Sw.in(i.field,r)),i.filter),fields:[i.field,o]})).items.flatMap(e=>{let t=ww(e[i.field]),n=ww(e[o]);return t===void 0||n===void 0?[]:[[t,n]]})},Dw=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 Ew(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=Ob(t,n,s,u),f=await xw(e,s.name,{filter:Cw(Yt(Sw.in(a.field,l)),a.filter),...a.sort&&{orderBy:a.sort},fields:u,labels:d});return Tw(c,kb(t,s,u,f.items,f.labels),a.field)},Ow=5e3,kw=({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?H.page(i.name,o,s,40,e):[...H.page(i.name,o,s,40,e),l],d=Ob(n,r,i,a),f=Vm(r[i.name]),p=async e=>e.nextPageToken===``?e.items.length:e.totalSizeEstimate>Ow?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=>Cm(i,e)),v=kb(n,i,a,Hm(i,g.items,g.photos),g.labels),[y]=await Promise.all([Promise.all(c.map(e=>Dw({client:t,resources:n,views:r,load:e,owners:_}))),Pb(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}},Aw=({resources:e,views:t,model:n,columns:r,filter:i,orderBy:a,related:o})=>{let s=U(),c=Se(),l=r.join(`,`),u=JSON.stringify(o??[]),d=(0,I.useMemo)(()=>kw({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=E({queryKey:[...H.first(n.name,i,a),l],queryFn:async()=>(await c.invalidateQueries({queryKey:H.pages(n.name,i,a),refetchType:`none`}),d.page(0))});return{source:(0,I.useMemo)(()=>f.data?{total:f.data.total,loadRows:d.loadRows,revision:f.dataUpdatedAt}:void 0,[f.data,f.dataUpdatedAt,d]),error:f.error,isLoading:f.isLoading,page:d.page,key:[...H.first(n.name,i,a),l]}},Y=M(`app/searches`),jw=`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`,Mw=({chips:e,className:t})=>(0,B.jsx)(`ul`,{className:P(`flex flex-wrap gap-1.5`,t),"aria-label":Y(`filters`),children:e.map(e=>(0,B.jsx)(`li`,{className:jw,children:e.label},e.key))}),Nw=({chips:e})=>(0,B.jsx)(`span`,{className:`flex flex-wrap gap-1.5`,children:e.map((e,t)=>(0,B.jsxs)(`span`,{className:jw,children:[t>0&&(0,B.jsx)(`span`,{className:`sr-only`,children:`, `}),e.label]},e.key))}),Pw=e=>e.map(e=>e.label).join(`, `),Fw=M(`filter-panel`),Iw=`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`,Lw=({chips:e,lockedLabels:t=[],onRemove:n,onClear:r,scroll:i})=>e.length===0&&t.length===0?null:(0,B.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,B.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,B.jsx)(ro,{className:`size-3 text-muted-foreground`}),e]},e)),e.map(e=>(0,B.jsxs)(`span`,{className:Iw,children:[e.label,(0,B.jsx)(`button`,{type:`button`,"aria-label":Fw(`remove`,{label:e.label}),onClick:()=>n(e.key),className:`rounded-full p-0.5 hover:bg-primary-border/60`,children:(0,B.jsx)(bc,{className:`size-3`})})]},e.key)),e.length>0&&(0,B.jsx)(`button`,{type:`button`,onClick:r,className:`ml-1 text-xs font-medium text-muted-foreground hover:text-foreground`,children:Fw(`clearAll`)})]}),Rw=[`today`,`7d`,`30d`,`year`],zw=new Set([`today`,`yesterday`,`24h`,`7d`,`30d`,`90d`,`month`,`quarter`,`year`]),Bw=e=>zw.has(e)?Fw(e):void 0,Vw=({value:e,presets:t=Rw,onChange:n})=>(0,B.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:t.map(t=>{let r=Bw(t);return(0,B.jsx)(`button`,{type:`button`,disabled:!r,title:r?void 0:Fw(`unknownPreset`,{id:t}),onClick:()=>n(e===t?void 0:t),className:P(`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??Fw(`unsupported`,{id:t})},t)})}),Hw={facets:{},toggles:[]},Uw=(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}}},Ww=(e,t)=>({...e,toggles:e.toggles.includes(t)?e.toggles.filter(e=>e!==t):[...e.toggles,t]}),Gw=(e,t,n)=>{let{[t]:r,...i}=e.ranges??{};return{...e,ranges:n?{...i,[t]:n}:i}},Kw=(e,t)=>e.options.find(e=>e.value===t)?.label??e.labels?.[t]??t,qw=(e,t)=>{let n=e.facets.flatMap(e=>(t.facets[e.id]??[]).map(t=>({key:`facet:${e.id}:${t}`,label:`${e.label}: ${Kw(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:Bw(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]},Jw=(e,t)=>{if(t===`date`)return{...e,date:void 0};let[n,r,i]=t.split(`:`);if(n===`range`)return Gw(e,r,void 0);if(n===`toggle`)return Ww(e,r);if(n===`facet`)return Uw(e,r,i);throw Error(`Unknown filter chip key: ${t}`)},Yw=(e,t)=>e.toLowerCase().includes(t.trim().toLowerCase()),Xw=(e,t)=>e.onSearch?e.options:e.options.filter(e=>Yw(e.label,t)),Zw=(e,t,n)=>t===0?-1:n===`ArrowDown`?e<0?0:(e+1)%t:e<0?t-1:(e-1+t)%t,Qw=({config:e,selected:t,onToggle:n,inline:r=!1})=>{let i=(0,I.useId)(),a=(0,I.useRef)(null),[o,s]=(0,I.useState)(``),[c,l]=(0,I.useState)(!1),[u,d]=(0,I.useState)(-1),f=r||c,p=Xw(e,o),m=(0,I.useRef)(e.onSearch);m.current=e.onSearch,(0,I.useEffect)(()=>()=>m.current?.(``),[]);let h=t=>{s(t),d(-1),e.onSearch?.(t)};return(0,B.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,B.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,B.jsx)(cs,{className:`size-3.5 shrink-0 text-muted-foreground`}),t.map(t=>(0,B.jsx)(tv,{label:Kw(e,t),onRemove:()=>n(t)},t)),(0,B.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?``:Fw(`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(Zw(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,B.jsxs)(`ul`,{id:`${i}-options`,role:`listbox`,"aria-label":e.label,"aria-multiselectable":!0,className:P(`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,B.jsxs)(`li`,{id:`${i}-${r}`,role:`option`,"aria-selected":a,tabIndex:-1,className:P(`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,B.jsx)(`span`,{className:P(`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,B.jsx)(Ci,{className:`size-3`,strokeWidth:3})}),(0,B.jsx)(`span`,{className:`flex-1 truncate`,children:e.label}),e.count!==void 0&&(0,B.jsx)(`span`,{className:`text-xs tabular-nums text-faint-foreground`,children:kp(e.count)})]},e.value)}),p.length===0&&(0,B.jsx)(`li`,{className:`px-1.5 py-1 text-xs text-faint-foreground`,children:Fw(`noMatches`)})]})]})},$w=({config:e,selected:t,onToggle:n})=>{let[r,i]=(0,I.useState)(``),a=e.options.filter(e=>Yw(e.label,r));return(0,B.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[e.searchable&&(0,B.jsx)(J,{wrapperClassName:`mb-1 h-7`,leading:(0,B.jsx)(cs,{className:`size-3.5`}),placeholder:Fw(`searchIn`,{label:e.label}),value:r,onChange:e=>i(e.target.value)}),a.map(e=>(0,B.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 rounded px-1 py-1 hover:bg-muted`,children:[(0,B.jsx)(AC,{checked:t.includes(e.value),onChange:()=>n(e.value),label:e.label}),(0,B.jsx)(`span`,{className:`flex-1 truncate`,children:e.label}),e.count!==void 0&&(0,B.jsx)(`span`,{className:`text-xs tabular-nums text-faint-foreground`,children:kp(e.count)})]},e.value)),a.length===0&&(0,B.jsx)(`span`,{className:`px-1 py-1 text-xs text-faint-foreground`,children:Fw(`noMatches`)})]})},eT=({label:e,activeCount:t,width:n=240,defaultOpen:r=!1,children:i})=>{let[a,o]=(0,I.useState)(r),[s,c]=(0,I.useState)(!1),l=(0,I.useRef)(null);return(0,I.useLayoutEffect)(()=>{a&&l.current&&c(l.current.getBoundingClientRect().left+n>document.documentElement.clientWidth)},[a,n]),(0,I.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,B.jsxs)(`div`,{ref:l,className:`relative`,children:[(0,B.jsxs)(`button`,{type:`button`,"aria-expanded":a,onClick:()=>o(!a),className:P(`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,B.jsx)(`span`,{className:`rounded-full bg-primary px-1.5 text-[11px] leading-4 text-primary-foreground`,children:t}),(0,B.jsx)(Ti,{className:`size-3.5 text-muted-foreground`})]}),a&&(0,B.jsx)(`div`,{className:P(`absolute top-full z-30 mt-1.5 rounded-lg border bg-background p-3 shadow-pop`,s?`right-0`:`left-0`),style:{width:n},children:typeof i==`function`?i(()=>o(!1)):i})]})},tT=({title:e,children:t})=>(0,B.jsxs)(`section`,{className:`flex flex-col gap-2 border-b py-3 last:border-b-0`,children:[(0,B.jsx)(`h3`,{className:`text-xs font-semibold uppercase tracking-wide text-muted-foreground`,children:e}),t]}),nT=(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}},rT=({items:e,onPick:t,close:n})=>{let r=(0,I.useRef)([]);return(0,I.useEffect)(()=>r.current[0]?.focus(),[]),(0,B.jsx)(`ul`,{role:`menu`,"aria-label":Fw(`moreFilters`),onKeyDown:t=>{if(t.key===`Escape`)return n();let i=nT(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,B.jsx)(`li`,{role:`none`,children:(0,B.jsx)(`button`,{ref:e=>{r.current[i]=e},type:`button`,role:`menuitem`,className:ag,onClick:()=>{n(),t(e.key)},children:e.label})},e.key))})},iT=({items:e,onPick:t})=>e.length===0?null:(0,B.jsx)(eT,{label:Fw(`moreFilters`),activeCount:0,children:n=>(0,B.jsx)(rT,{items:e,onPick:t,close:n})}),aT=(e,t)=>{let[n,r]=(0,I.useState)(e);return(0,I.useEffect)(()=>{let n=setTimeout(()=>r(e),t);return()=>clearTimeout(n)},[e,t]),n},oT=(e,t,n,r,i)=>{let a=n+(r-n)*e/t;return n+(r-n)*(e+1)/t>i[0]&&a<i[1]},sT=(e,t,n)=>n===t?0:(e-t)/(n-t),cT=(e,t,n)=>t===0?[Math.min(n,e[1]),e[1]]:[e[0],Math.max(n,e[0])],lT=1e3,uT=({config:e,value:t,onChange:n})=>{let{min:r,max:i,step:a,histogram:o,format:s}=e,[c,l]=(0,I.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=aT(c,lT);return(0,I.useEffect)(()=>{p&&f()},[p]),(0,B.jsxs)(`div`,{className:`w-full`,children:[(0,B.jsxs)(`div`,{className:`px-[7px]`,children:[o.length>0&&(0,B.jsx)(`div`,{className:`mb-1 flex h-12 items-end gap-0.5`,children:o.map((e,t)=>(0,B.jsx)(`span`,{className:P(`flex-1 rounded-t-sm`,oT(t,o.length,r,i,u)?`bg-primary/70`:`bg-border`),style:{height:`${Math.max(6,e/d*100)}%`}},t))}),(0,B.jsxs)(`div`,{className:`relative h-4`,children:[(0,B.jsx)(`span`,{className:`absolute inset-x-0 top-1/2 h-1 -translate-y-1/2 rounded-full bg-border`}),(0,B.jsx)(`span`,{className:`absolute top-1/2 h-1 -translate-y-1/2 rounded-full bg-primary`,style:{left:`${sT(u[0],r,i)*100}%`,right:`${100-sT(u[1],r,i)*100}%`}})]})]}),(0,B.jsx)(`div`,{className:`relative -mt-4 h-4`,children:[0,1].map(t=>(0,B.jsx)(`input`,{type:`range`,className:`pb-range`,"aria-label":Fw(t===0?`minimum`:`maximum`,{label:e.label}),min:r,max:i,step:a,value:u[t],onChange:e=>l(cT(u,t,Number(e.target.value))),onPointerUp:f,onTouchEnd:f,onBlur:f},t))}),(0,B.jsxs)(`div`,{className:`mt-2 flex justify-between text-xs tabular-nums text-muted-foreground`,children:[(0,B.jsx)(`span`,{children:s(u[0])}),(0,B.jsx)(`span`,{children:s(u[1])})]})]})},dT=e=>[...new Set(e.map(e=>e.key.split(`:`).slice(0,2).join(`:`)))],fT=(e,t)=>{let n=t.filter(t=>!e.includes(t));return n.length===0?e:[...e,...n]},pT=(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:Fw(`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}},mT=({label:e,checked:t,onChange:n})=>(0,B.jsxs)(`label`,{className:`flex cursor-pointer items-center justify-between gap-3 py-1`,children:[(0,B.jsx)(`span`,{children:e}),(0,B.jsx)(Kg,{checked:t,onChange:n,label:e})]}),hT=(e,t)=>e.some(e=>e.length>0)||!!t,gT=({groups:e,trailing:t})=>{if(!hT(e,t))return null;let n=e.filter(e=>e.length>0);return(0,B.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[n.map((e,t)=>(0,B.jsxs)(I.Fragment,{children:[t>0&&(0,B.jsx)(`span`,{className:`mx-1 h-5 w-px bg-border`}),e]},t)),t&&(0,B.jsx)(`div`,{className:`flex min-w-32 flex-1 justify-end`,children:t})]})},_T=(e,t,n)=>{let[r,i]=(0,I.useState)(t??Hw);return[e??r,e=>{i(e),n?.(e)}]},vT=({config:e,layout:t,value:n,defaultValue:r,onChange:i,lockedLabels:a,defaultOpenMenu:o,fullWidth:s,leading:c,trailing:l})=>{let[u,d]=_T(n,r,i),f=qw(e,u),p=dT(f),[m,h]=(0,I.useState)(()=>p),[g,_]=(0,I.useState)();(0,I.useEffect)(()=>h(e=>fT(e,p)),[p.join(`,`)]);let v=(0,B.jsx)(Lw,{chips:f,lockedLabels:a,onRemove:e=>d(Jw(u,e)),onClear:()=>d(Hw)}),y=(e,t=!1)=>{let n=u.facets[e.id]??[],r=t=>d(Uw(u,e.id,t));return e.combobox?(0,B.jsx)(Qw,{config:e,selected:n,onToggle:r,inline:t}):(0,B.jsx)($w,{config:e,selected:n,onToggle:r})},b=e.ranges??[],x=e=>(0,B.jsx)(uT,{config:e,value:u.ranges?.[e.id],onChange:t=>d(Gw(u,e.id,t))}),S=e.datePresets&&(0,B.jsx)(Vw,{value:u.date,presets:Array.isArray(e.datePresets)?e.datePresets:void 0,onChange:e=>d({...u,date:e})}),C=(e.toggles??[]).map(e=>(0,B.jsx)(mT,{label:e.label,checked:u.toggles.includes(e.id),onChange:()=>d(Ww(u,e.id))},e.id));if(t===`panel`)return(0,B.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,B.jsx)(`div`,{className:`flex items-center justify-between pb-1`,children:(0,B.jsx)(`h2`,{className:`font-semibold`,children:Fw(`filters`)})}),(f.length>0||(a?.length??0)>0)&&(0,B.jsx)(`div`,{className:`border-b pb-3`,children:v}),c,e.facets.map(e=>(0,B.jsx)(tT,{title:e.label,children:y(e)},e.id)),b.map(e=>(0,B.jsx)(tT,{title:e.label,children:x(e)},e.id)),S&&(0,B.jsx)(tT,{title:Fw(`date`),children:S}),C.length>0&&(0,B.jsx)(tT,{title:Fw(`showOnly`),children:C})]});let{shown:w,more:T}=pT(e,m),E=e=>{h(t=>fT(t,[e])),_(e)},D=[...e.facets.filter(e=>w.has(`facet:${e.id}`)).map(e=>(0,B.jsx)(eT,{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,B.jsx)(eT,{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,B.jsx)(I.Fragment,{children:S},`date`)]:[]],O=(e.toggles??[]).filter(e=>w.has(`toggle:${e.id}`)).map(e=>(0,B.jsx)(`div`,{className:`flex items-center gap-2 text-muted-foreground`,children:(0,B.jsx)(mT,{label:e.label,checked:u.toggles.includes(e.id),onChange:()=>d(Ww(u,e.id))})},e.id)),k=[c?[(0,B.jsx)(I.Fragment,{children:c},`leading`)]:[],D,O,T.length>0?[(0,B.jsx)(iT,{items:T,onPick:E},`more`)]:[]];return!hT(k,l)&&f.length===0&&!a?.length?null:(0,B.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,B.jsx)(gT,{groups:k,trailing:l}),v]})},yT=sn(),bT={start:0,end:0},xT={"24h":{amount:24,unit:`h`},"7d":{amount:7,unit:`d`},"30d":{amount:30,unit:`d`},"90d":{amount:90,unit:`d`}},ST=e=>new Date(e).toISOString().replace(`.000Z`,`Z`),CT=(e,t,n)=>{let r=np(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},wT=[`year`,`quarter`,`month`,`yesterday`,`today`],TT=(e,t,n)=>t===`date`?e:ST(ip(e,n)),ET=(e,t,n)=>t===`date`?{kind:`string`,value:TT(e,t,n),span:bT}:{kind:`timestamp`,value:TT(e,t,n),span:bT},DT=(e,t,n,r,i)=>{if(t in xT)return[yT.gte(e,yT.ago(t))];let a=yT.gte(e,ET(CT(t,n,i),r,i));return t===`yesterday`?[a,yT.lt(e,ET(CT(`today`,n,i),r,i))]:[a]},OT=(e,t,n=new Date,r=Xf())=>{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=>yT.eq(e.value,!0));return t.length===0?[]:[t.length===1?t[0]:yT.or(...t)]}return[n.length===1?yT.eq(e.id,n[0]):yT.in(e.id,n)]}),a=(e.ranges??[]).flatMap(e=>{let n=t.ranges?.[e.id];return n?[yT.gte(e.id,n[0]),yT.lte(e.id,n[1])]:[]}),o=e.dateField&&t.date?DT(e.dateField,t.date,n,e.dateKind,r):[],s=(e.toggles??[]).filter(e=>t.toggles.includes(e.id)).map(e=>yT.eq(e.id,!0));return[...i,...a,...o,...s]},kT=e=>e.length===0?``:Yt(yT.and(...e)),AT=(e,t,n=[],r=new Date,i=Xf())=>kT([...OT(e,t,r,i),...n]),jT=e=>e.kind===`and`?e.args.flatMap(jT):[e],MT=e=>e.field.path.join(`.`),NT=e=>e.kind===`compare`&&e.op===`=`&&e.value.kind===`boolean`&&e.value.value,PT=(e,t)=>{let n=e.kind===`or`?e.args:[e];if(!n.every(NT))return;let r=n.map(MT),i=t.get(r[0]);return i!==void 0&&r.every(e=>t.get(e)===i)?{group:i,fields:r}:void 0},FT=e=>e.kind===`number`?String(e.raw):e.kind===`string`?String(e.value):void 0,IT=(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(xT).find(([,n])=>n.amount===e&&n.unit===t)?.[0]}if(r.kind===`timestamp`)return wT.find(e=>TT(CT(e,t,n),`timestamp`,n)===r.value);if(r.kind===`string`)return wT.find(e=>CT(e,t,n)===r.value)},LT=(e,t,n=new Date,r=Xf())=>{let i=it(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?jT(i.ast):[]){let i=PT(t,c);if(i&&!a.facets[i.group])a.facets[i.group]=i.fields;else if(t.kind===`compare`&&s.has(MT(t))&&t.op===`=`&&FT(t.value)!==void 0)a.facets[MT(t)]=[...a.facets[MT(t)]??[],FT(t.value)];else if(t.kind===`in`&&s.has(MT(t))&&t.values.every(e=>FT(e)!==void 0))a.facets[MT(t)]=[...a.facets[MT(t)]??[],...t.values.map(e=>FT(e))];else if(t.kind===`compare`&&e.dateField===MT(t)&&t.op===`>=`&&IT(t,n,r)&&!a.date)a.date=IT(t,n,r),f=t;else if(t.kind===`compare`&&e.dateField===MT(t)&&t.op===`<`&&(t.value.kind===`timestamp`||t.value.kind===`string`)&&t.value.value===TT(CT(`today`,n,r),t.value.kind===`string`?`date`:`timestamp`,r))p=t;else if(t.kind===`compare`&&l.has(MT(t))&&t.op===`=`&&t.value.kind===`boolean`&&t.value.value)a.toggles.push(MT(t));else if(t.kind===`compare`&&u.has(MT(t))&&(t.op===`>=`||t.op===`<=`)&&t.value.kind===`number`){let e=d.get(MT(t))??{clauses:[]};t.op===`>=`?e.low=t.value.value:e.high=t.value.value,e.clauses.push(t),d.set(MT(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}},RT=[`integer`,`bigint`,`decimal`],zT=(e,t)=>{let n=e?.fields[t]?.type;return n!==void 0&&RT.includes(n)},BT=(e,t)=>e.kind===`range`||e.kind===`facets`&&zT(t,e.field),VT=e=>e.secondary?{secondary:!0}:{},HT=e=>({id:e.field,label:e.field,min:0,max:0,step:1,histogram:[],format:String,...VT(e)}),UT=(e,t)=>{let n=e?.filters??[],r=n.find(e=>e.kind===`dateRange`);return{facets:n.flatMap(e=>e.kind===`facets`&&!BT(e,t)?[{id:e.field,label:e.field,options:[],searchable:e.search,...t?.fields[e.field]?.type===`relation`&&{combobox:!0},...VT(e)}]:e.kind===`flags`?[{id:e.fields.join(`|`),label:e.label,options:e.fields.map(e=>({value:e,label:e,count:0})),flags:!0,...VT(e)}]:[]),ranges:n.flatMap(e=>e.kind!==`flags`&&BT(e,t)?[HT(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,...VT(e)}]:[])}},WT=(e,t)=>(e?.filters??[]).some(e=>e.kind===`range`&&e.field===t&&e.histogram),GT=(e,t)=>{let n=e?.fields[t],r=n?.suffix??``,i=n?.currency;return i===void 0?e=>`${n?.prefix??``}${e}${r}`:e=>`${Pp(e*100,i).replace(`.00`,``)}${r}`},KT=sn(),qT={start:0,end:0},JT=(e,t,n)=>{let r=LT(UT(t,e),n);return r.ok?Object.fromEntries(Object.entries(r.state.facets).filter(([t,n])=>e.fields[t]?.type===`relation`&&n.length>0)):{}},YT=(e,t,n)=>{let r=e=>t?.fields[e]?.label??F(e),i=UT(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:GT(t,e.id)})),toggles:i.toggles?.map(e=>({...e,label:r(e.id)}))}},XT=(e,t,n,r={})=>{let i=YT(e,t,r),a=LT(i,n);if(!a.ok)return[{key:`unreadable`,label:Y(`unreadableFilter`)}];let o=a.extras.map((e,t)=>({key:`extra:${t}`,label:e.kind===`search`?`"${e.text}"`:Yt(e)}));return[...qw(i,a.state),...o]},ZT=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]))}])),QT=(e,t,n)=>{if(typeof n!=`string`||n===``)return e;let r=KT.gt(t,{kind:`timestamp`,value:new Date(n).toISOString(),span:qT}),i=it(e);if(!i.ok)throw Error(`The saved filter cannot be read: ${i.errors.map(e=>e.message).join(`; `)}`);return Yt(i.ast?KT.and(i.ast,r):r)},$T=(e,t)=>typeof t!=`string`||t===``?!0:typeof e!=`string`||e===``?!1:new Date(e).getTime()>new Date(t).getTime(),eE=(e,t)=>{let n=U(),r=Se(),{resources:i,views:a}=W(),o=a[e.name],s=Object.entries(JT(e,o,t)),c=f({queries:s.map(([t,o])=>{let s=i[e.fields[t].relation.resource];return{queryKey:H.labels(`chips:${e.name}.${t}`,o.join(`,`)),enabled:s!==void 0,queryFn:async()=>Object.fromEntries(await Eb(r,n,s,o,a[s.name]))}})});return XT(e,o,t,Object.fromEntries(s.flatMap(([e],t)=>c[t]?.data?[[e,c[t].data]]:[])))},tE=(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}}),nE=e=>{let t=Se();return(0,I.useCallback)(n=>t.setQueryData(H.recordPreview(e.name,Nn(wm(e,n))),tE(e,n)),[t,e])},rE={wallet:fc,"file-text":Ca,send:fs,ruler:os,bed:Zr,bath:Yr,house:ja,"door-open":ta,"land-plot":za,leaf:qa,tag:Hs,key:La,calendar:_i,heart:ka,bell:ri,bookmark:di,"external-link":da,ban:qr,play:Wo,stop:Ms,power:Xo,restart:is,terminal:Ks,camera:yi,"hard-drive":Da,server:ms,network:Mo,archive:Nr,copy:Yi,"arrow-right-left":Lr,download:ra,upload:Qs,cpu:Zi,memory:mo,plug:Ko,wrench:vc},iE=e=>e!==void 0&&Object.hasOwn(rE,e)?rE[e]:void 0,aE=({target:e,id:t})=>(0,B.jsx)(B.Fragment,{children:Lb(e,t)??t}),oE=()=>{let{path:e,params:t,basePath:n,navigate:r}=Ih(),i=(0,I.useMemo)(()=>el(e,t),[e,t]),a=kd(new URL(t.size>0?`${e}?${t}`:e,`http://local`).href),o=i?i.next:a,s=(0,I.useCallback)((e=`sign-in`,t)=>r($c({step:e,next:o}),t),[r,o]);return{address:i,next:o,open:s,link:(0,I.useCallback)((e=`sign-in`,t)=>({href:`${n}${$c({step:e,next:o})}`,onFollow:()=>s(e,t)}),[n,o,s]),leave:(0,I.useCallback)(()=>r(o??`/`,{replace:!0}),[r,o])}},sE=({benefits:e})=>e&&e.length>0?(0,B.jsx)(`ul`,{className:`flex flex-col gap-2 text-left`,children:e.map(e=>(0,B.jsxs)(`li`,{className:`flex items-start gap-2`,children:[(0,B.jsx)(Ci,{className:`mt-0.5 size-4 shrink-0 text-primary`,"aria-hidden":!0}),e]},e))}):null,cE=({prompt:e})=>{let{canSignUp:t}=V(),{link:n}=oE(),r=yf({variant:`primary`}),i=e.signUp?(0,B.jsx)(`a`,{href:e.signUp.href,target:`_blank`,rel:`noreferrer`,className:r,children:e.signUp.label}):t&&(0,B.jsx)(Dh,{to:n(`sign-up`),className:r,children:z(`createAnAccount`)});return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(Dh,{to:n(),className:i?yf():r,children:z(`signIn`)}),i]})},lE=e=>{let{prompt:t}=e,n=(0,I.useId)();if(e.as===`dialog`)return(0,B.jsx)(jf,{title:t.title,description:t.description,open:e.open,onClose:e.onClose,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:e.onClose,children:z(`notNow`)}),(0,B.jsx)(cE,{prompt:t})]}),children:(0,B.jsx)(sE,{benefits:t.benefits})});let r=iE(t.icon)??ao;return(0,B.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,B.jsx)(`span`,{className:`flex size-12 items-center justify-center rounded-full bg-primary/10 text-primary`,children:(0,B.jsx)(r,{className:`size-6`,"aria-hidden":!0})}),(0,B.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,B.jsx)(`h1`,{id:n,className:`text-lg font-semibold`,children:t.title}),(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:t.description})]}),(0,B.jsx)(sE,{benefits:t.benefits}),(0,B.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,B.jsx)(cE,{prompt:t})})]})},uE=sn(),dE=e=>{if(typeof e==`string`||typeof e==`number`)return e;if(e&&typeof e==`object`&&`id`in e)return dE(e.id)},fE=(e,t,n)=>n.flatMap(n=>{let r=dE(n[t]);return r===void 0?[]:[{key:Nn(wm(e,n)),target:r}]}),pE=(e,t)=>e.find(e=>Nn(e.target)===t),mE=(e,t)=>[...e,{key:``,target:t}],hE=(e,t)=>e.filter(e=>Nn(e.target)!==t),gE=(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:uE.in(n,r)},_E=(e,t)=>H.list(e,``,``,500,`saved:${t}`),vE=(e,t,n)=>{let r=U(),i=W().resources[e];return E({queryKey:_E(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 fE(i,t,n)}})},yE=M(`app/saved`),bE=e=>e instanceof Error?e.message:yE(`somethingWrong`),xE=(e,t,n)=>{let r=W(),i=U(),a=Se(),s=ly(),c=Oy(),{resource:l,field:u}=e,d=r.permissions[l],f=r.resources[l]!==void 0&&d!==void 0&&dy(d,`create`)&&dy(d,`delete`),p=r.signIn?.[l]?.signIn,m=vE(l,u,f),h=m.data&&pE(m.data,t),g=_E(l,u),_=o({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?hE(r,t):mE(r,n)),{before:r}},onError:(e,t,n)=>{a.setQueryData(g,n?.before),s.show({state:`error`,title:yE(t?`couldNotTakeOff`:`couldNotSave`),description:bE(e)})},onSettled:()=>c(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)}},SE=({favorite:e,recordKey:t,target:n,className:r})=>{let i=xE(e,t,n),[a,o]=(0,I.useState)(!1);if(!i.mode)return null;let s=e.label??yE(`favorite`),c=P(`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,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`button`,{type:`button`,"aria-label":s,"aria-haspopup":`dialog`,className:c,onClick:()=>o(!0),children:(0,B.jsx)(ka,{className:`size-4`,"aria-hidden":!0})}),(0,B.jsx)(lE,{as:`dialog`,prompt:i.prompt,open:a,onClose:()=>o(!1)})]}):(0,B.jsx)(`button`,{type:`button`,"aria-label":s,"aria-pressed":i.saved,"aria-disabled":!i.ready,className:c,onClick:()=>i.ready&&i.toggle(),children:(0,B.jsx)(ka,{className:P(`size-4`,i.saved&&`fill-current text-danger`),"aria-hidden":!0})})},CE=6,wE=(e,t,n)=>{let r=e.bottom+CE;return{top:r+t.height>n.height-CE?Math.max(CE,e.top-CE-t.height):r,left:Math.max(CE,Math.min(e.left,n.width-CE-t.width))}},TE=(e,t)=>{let n=Ym(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},EE=(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:dh(r,n[r.name],TE(n[r.name],e.status))}]:[]}),DE=M(`app/related-dots`),OE=(e,{values:t,label:n,singular:r,plural:i})=>{if(e.length===0)return DE(`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(`, `)}`},kE=`flex shrink-0 items-center justify-center rounded-full p-0.5 pointer-coarse:p-1.5`,AE=`size-2.5 rounded-full`,jE=`flex min-w-0 items-center gap-0.5`,ME=150,NE=288,PE=({shown:e,row:t,target:n,view:r,column:i,Card:a,onEnter:o,onLeave:s})=>{let c=(0,I.useRef)(null),[l,u]=(0,I.useState)();return(0,I.useLayoutEffect)(()=>{c.current&&u(wE(e.dot,{width:NE,height:c.current.offsetHeight},{width:window.innerWidth,height:window.innerHeight}))},[e]),(0,Cc.createPortal)((0,B.jsx)(`div`,{ref:c,"data-dot-card":!0,onMouseEnter:o,onMouseLeave:s,style:{width:NE,...l??{visibility:`hidden`,top:0,left:0}},className:`fixed z-50 rounded-lg shadow-pop`,children:(0,B.jsx)(a,{model:n,view:r,display:TE(r,i.status),row:t})}),document.body)},FE=({column:e,records:t,target:n,view:r,wrap:i=!1,Card:a})=>{let o=(0,I.useMemo)(()=>t.map(e=>hh(n,e)),[t,n]),[s,c]=(0,I.useState)(),l=(0,I.useRef)(void 0),u=(0,I.useRef)(`mouse`),d=(0,I.useRef)(null),f=n.fields[e.status],p=r?.fields[e.status],m=t=>f?Rm(f,t.record[e.status],p):``,h=lr(n,r),g=e=>e.labels[h]??String(e.record[h]??e.key),_=(r?.names?.singular??F(n.name)).toLowerCase(),v=(r?.names?.plural??F(n.name)).toLowerCase(),y=OE(o.map(t=>t.record[e.status]),{values:f?.enumValues??[],label:e=>f?Rm(f,e,p):e,singular:_,plural:v}),b=()=>window.clearTimeout(l.current),x=()=>{b(),l.current=window.setTimeout(()=>c(void 0),ME)},S=(e,t)=>{b(),c({key:e,dot:t.getBoundingClientRect()})};(0,I.useEffect)(()=>b,[]),(0,I.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,B.jsxs)(`div`,{ref:d,className:P(jE,i&&`pointer-events-none flex-wrap`),onClick:e=>e.stopPropagation(),onPointerDown:e=>u.current=e.pointerType,children:[(0,B.jsx)(`span`,{className:`sr-only`,children:y}),o.map(t=>{let r=t.record[e.status],i=Am(p?.valueColors,r);return(0,B.jsx)(Jh,{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:P(kE,`pointer-events-auto focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40`),children:(0,B.jsx)(`span`,{"aria-hidden":!0,style:i===void 0?void 0:{backgroundColor:i},className:P(AE,i===void 0&&Lf[jm(p?.valueColors,r)],s?.key===t.key&&`ring-2 ring-foreground/30`)})},t.key)}),s&&T&&(0,B.jsx)(PE,{shown:s,row:T,target:n,view:r,column:e,Card:a,onEnter:b,onLeave:x})]})},IE=({count:e})=>(0,B.jsx)(`span`,{"aria-hidden":!0,className:P(jE,`invisible flex-wrap`),children:Array.from({length:e},(e,t)=>(0,B.jsx)(`span`,{className:kE,children:(0,B.jsx)(`span`,{className:AE})},t))}),LE=`flex flex-col gap-1.5`,RE=({dots:e})=>(0,B.jsx)(`span`,{className:LE,children:e.map(({column:e,records:t})=>(0,B.jsx)(IE,{count:t.length},e.name))}),zE=({dots:e,Card:t})=>{let{resources:n,views:r}=W();return(0,B.jsx)(`div`,{className:`pointer-events-none absolute inset-x-[calc(0.75rem+1px)] bottom-[calc(0.75rem+1px)] ${LE}`,children:e.map(({column:e,records:i})=>{let a=n[e.resource];return a&&(0,B.jsx)(FE,{column:e,records:i,target:a,view:r[a.name],Card:t,wrap:!0},e.name)})})},BE=(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}]:[]}),VE=M(`carousel`),HE=`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`,UE=`[@media(hover:none)]:opacity-100`,WE=({carousel:e,count:t,swipe:n,reveal:r,className:i})=>{if(t<2)return null;let{index:a,press:o}=e;return(0,B.jsxs)(`div`,{className:P(`group/arrows pointer-events-none absolute`,i),children:[(0,B.jsx)(`button`,{type:`button`,"aria-label":VE(`previousPhoto`),className:P(HE,r,!n&&UE,`left-2`),onClick:()=>o(-1),children:(0,B.jsx)(Di,{className:`size-4`,"aria-hidden":!0})}),(0,B.jsx)(`button`,{type:`button`,"aria-label":VE(`nextPhoto`),className:P(HE,r,!n&&UE,`right-2`),onClick:()=>o(1),children:(0,B.jsx)(ki,{className:`size-4`,"aria-hidden":!0})}),(0,B.jsxs)(`span`,{className:`absolute inset-x-0 bottom-2 flex justify-center`,"aria-live":`polite`,children:[(0,B.jsx)(`span`,{className:`sr-only`,children:VE(`photoOf`,{index:a+1,count:t})}),(0,B.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,B.jsx)(`span`,{className:P(`size-1.5 rounded-full`,t===a?`bg-foreground`:`bg-foreground/35`)},t))})]})]})},GE=({carousel:e,swipe:t,slides:n,className:r,...i})=>(0,B.jsx)(`span`,{...i,ref:e.track,tabIndex:-1,onPointerDown:e.touch,onScroll:t=>e.scrolled(t.currentTarget),className:P(`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,B.jsx)(`span`,{className:`block size-full shrink-0 snap-start snap-always`,children:e},t))}),KE=(e,t)=>t===0?0:(e%t+t)%t,qE=(e,t,n)=>t<=0||n===0?0:Math.min(n-1,Math.max(0,Math.round(e/t))),JE=e=>{let t=(0,I.useRef)(null),n=(0,I.useRef)(void 0),[r,i]=(0,I.useState)(0),a=e=>{let n=t.current;n&&n.scrollTo({left:e*n.clientWidth})};return{track:t,index:r,press:t=>{n.current=KE((n.current??r)+t,e),a(n.current)},touch:()=>{n.current=void 0},scrolled:t=>{i(qE(t.scrollLeft,t.clientWidth,e)),n.current!==void 0&&Math.abs(t.scrollLeft-n.current*t.clientWidth)<1&&(n.current=void 0)}}},YE=({value:e})=>{let t=Kp(e,{width:320,height:240});return t?(0,B.jsx)(I_,{image:t,loading:`lazy`,className:`size-full object-cover`}):null},XE=({children:e})=>(0,B.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}),ZE=({value:e})=>(0,B.jsx)(XE,{children:(0,B.jsx)(YE,{value:e})}),QE=10,$E=(e,t)=>{let n=Ip(e)?e.uri:void 0,r=t.filter(e=>Ip(e)&&e.uri!==n);return(n===void 0?r:[e,...r]).slice(0,QE)},eD=({photos:e,cover:t,swipe:n=!0,children:r})=>{let i=$E(t,e),a=JE(i.length),o=(0,B.jsx)(XE,{children:(0,B.jsx)(GE,{"data-card-photos":!0,carousel:a,swipe:n,slides:i.map(e=>(0,B.jsx)(YE,{value:e}))})});return(0,B.jsxs)(B.Fragment,{children:[r(o),(0,B.jsx)(WE,{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]`})]})},tD=({icon:e,children:t})=>{let n=iE(e);return(0,B.jsxs)(`dd`,{className:`flex items-center gap-1 tabular-nums`,children:[n&&(0,B.jsx)(n,{className:`size-3.5 shrink-0`,"aria-hidden":!0}),t]})},nD=({model:e,view:t,display:n,row:r,swipe:i=!0,mark:a})=>{let{image:o,title:s,subtitle:c,amount:l,badge:u,meta:d,footer:f,flags:p}=oh(e,t,n),m=e=>t?.fields[e]?.label??F(e),{resources:h,views:g}=W(),_=n=>{let i=e.fields[n];if(!i)return``;let a=r.record[n],o=i.type===`relation`&&i.relation?h[i.relation.resource]:void 0;return o&&g[o.name]?.titleFrom&&a!=null?(0,B.jsx)(aE,{target:o,id:String(a)}):r.labels[n]===void 0&&xm(i,t?.fields[n])&&typeof a==`string`&&a!==``?bm(a):r.labels[n]??Rm(i,a,t?.fields[n])},{fields:v,components:y}=p_(),b=nE(e),x=n.card===void 0?void 0:y?.[n.card],S=n=>{let i=e.fields[n],a=i&&av(v,i,t?.fields[n]);return a?(0,B.jsx)(gv,{shown:a,part:`display`,field:i,value:r.record[n],fallback:_(n)}):_(n)},C=n=>{let i=e.fields[n],a=r.record[n];return!i||!xm(i,t?.fields[n])||av(v,i,t?.fields[n])||typeof a!=`string`||a===``?S(n):(0,B.jsx)(vv,{source:a,inLink:!0})},w=n=>{let i=e.fields[n],a=t?.fields[n],o=r.record[n];return!i||a?.format!==`badge`||av(v,i,a)||o==null||o===``?S(n):(0,B.jsx)(Rb,{value:o,hints:a,children:_(n)})},T=n=>{let i=e.fields[n];if(!i)return;if(r.labels[n]!==void 0||av(v,i,t?.fields[n]))return(0,B.jsx)(`strong`,{className:`font-semibold text-foreground`,children:S(n)});let a=lh(i,r.record[n],t?.fields[n]);return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`strong`,{className:`font-semibold text-foreground`,children:a.amount}),a.suffix]})},E=x?void 0:n.photos,D=u===void 0?void 0:r.record[u],O=p.filter(e=>r.record[e]===!0),k=o===void 0?void 0:r.record[o],A=ch(r,l),j=sh(r,f),ee=o!==void 0||E!==void 0,te=n.favorite,ne=x?[]:BE(t,n,r),re=e=>(0,B.jsxs)(B.Fragment,{children:[ee&&e,(0,B.jsxs)(`span`,{className:`flex items-start justify-between gap-2 ${te&&!ee?`pr-8`:``}`,children:[(0,B.jsx)(`span`,{className:`min-w-0 truncate font-medium`,children:S(s)}),u!==void 0&&D!=null&&(0,B.jsx)(Rb,{value:D,hints:t?.fields[u],children:_(u)})]}),c!==void 0&&(0,B.jsx)(`span`,{className:t?.fields[c]?.markdown?`line-clamp-3 break-words text-muted-foreground`:t?.fields[c]?.multiline?`line-clamp-3 whitespace-pre-line break-words text-muted-foreground`:`truncate text-muted-foreground`,children:C(c)}),A!==void 0&&(0,B.jsx)(`span`,{className:`truncate tabular-nums text-muted-foreground`,children:T(A)}),d.length>0&&(0,B.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:sh(r,d).map(e=>(0,B.jsxs)(`div`,{className:`flex gap-1`,children:[(0,B.jsx)(`dt`,{className:`sr-only`,children:m(e)}),(0,B.jsx)(tD,{icon:t?.fields[e]?.icon,children:w(e)})]},e))}),O.length>0&&(0,B.jsx)(`ul`,{className:`flex flex-wrap gap-1`,"aria-label":K(`features`),children:O.map(e=>(0,B.jsx)(`li`,{children:(0,B.jsx)(zf,{dot:!1,children:m(e)})},e))}),j.length>0&&(0,B.jsx)(`span`,{className:`truncate text-xs text-muted-foreground ${d.length>0?``:`mt-auto`}`,children:j.map((e,t)=>(0,B.jsxs)(`span`,{children:[t>0&&(0,B.jsx)(`span`,{"aria-hidden":!0,children:` • `}),S(e)]},e))}),ne.length>0&&(0,B.jsx)(RE,{dots:ne})]}),ie=t=>(0,B.jsxs)(Jh,{to:{kind:`record`,resource:e.name,key:r.key},onClick:()=>b(r.record),className:`flex h-full flex-col gap-1.5 rounded-lg border border-border bg-background p-3 hover:border-border-strong hover:bg-surface focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/30`,children:[a&&!ee&&(0,B.jsx)(zf,{tone:`blue`,className:`self-start`,children:a}),x?(0,B.jsx)(pv,{name:n.card,fallback:re(t),children:(0,B.jsx)(x,{row:r})}):re(t)]});return(0,B.jsxs)(`div`,{className:E?`group/card relative h-full`:te||a||ne.length>0?`relative h-full`:`h-full`,children:[E?(0,B.jsx)(eD,{photos:r.photos??[],cover:k,swipe:i,children:ie},r.key):ie((0,B.jsx)(ZE,{value:k})),a&&ee&&(0,B.jsx)(zf,{tone:`blue`,className:`pointer-events-none absolute top-2 left-2 shadow-sm`,children:a}),ne.length>0&&(0,B.jsx)(zE,{dots:ne,Card:nD}),te&&(0,B.jsx)(SE,{favorite:te,recordKey:r.key,target:wm(e,r.record),className:ee?void 0:`right-1.5 top-1.5`})]})},rD=268,iD=3,aD=(e,t,n)=>{let r=Math.floor(Math.max(0,e)/rD),i=Math.ceil((Math.max(0,e)+t)/rD);return{start:Math.max(0,r-iD),end:Math.min(n,i+iD)}},oD=e=>e*rD,sD=e=>{let t=(0,I.useRef)(null),[n,r]=(0,I.useState)({left:0,width:0});(0,I.useLayoutEffect)(()=>{let n=t.current;if(!n)return;let i=()=>r(t=>{let r={left:n.scrollLeft,width:n.clientWidth};return((t,n)=>{let[r,i]=[aD(t.left,t.width,e),aD(n.left,n.width,e)];return r.start===i.start&&r.end===i.end&&t.width===n.width&&t.left>0==n.left>0&&Math.abs(t.left-n.left)<1})(t,r)?t:r});i();let a=new ResizeObserver(i);return a.observe(n),n.addEventListener(`scroll`,i,{passive:!0}),()=>{a.disconnect(),n.removeEventListener(`scroll`,i)}},[e]);let i=Math.max(0,oD(e)-12),a=e=>t.current?.scrollBy({left:e*Math.max(oD(1),n.width-12),behavior:`smooth`});return{ref:t,...aD(n.left,n.width,e),back:n.left>0,on:n.left+n.width<i-1,page:a}},cD=M(`app/record-row`),lD=`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`,uD=({cards:e})=>e>0?(0,B.jsx)(`li`,{"aria-hidden":!0,className:`shrink-0`,style:{width:oD(e)-12}}):null,dD=({model:e,view:t,display:n,source:r,label:i,isNew:a})=>{let{total:o}=r,s=sD(o),c=XC({total:o,rowAt:r.rowAt,loadRows:r.loadRows,revision:r.revision,latencyMs:0},s.start,Math.max(s.start,s.end-1)),l=Array.from({length:s.end-s.start},(e,t)=>s.start+t);return(0,B.jsxs)(`div`,{className:`relative min-w-0`,children:[(0,B.jsxs)(`ul`,{ref:s.ref,"aria-label":i,className:`relative flex snap-x gap-3 overflow-x-auto overflow-y-hidden pb-1`,style:{scrollbarWidth:`thin`},children:[(0,B.jsx)(uD,{cards:s.start}),l.map(r=>{let i=c(r);if(!i)return(0,B.jsx)(`li`,{"aria-hidden":!0,className:`shrink-0`,style:{width:256},children:(0,B.jsx)(Ch,{className:`h-full min-h-24 rounded-lg`})},`skeleton-${r}`);let s=hh(e,i);return(0,B.jsx)(`li`,{"aria-posinset":r+1,"aria-setsize":o,className:`grid shrink-0 snap-start grid-cols-[minmax(0,1fr)]`,style:{width:256},children:(0,B.jsx)(nD,{model:e,view:t,display:n,row:s,swipe:!1,mark:a?.(s)?cD(`new`):void 0})},s.key)}),(0,B.jsx)(uD,{cards:o-s.end})]}),s.back&&(0,B.jsx)(`button`,{type:`button`,"aria-label":cD(`previous`,{label:i.toLowerCase()}),onClick:()=>s.page(-1),className:`${lD} -left-3`,children:(0,B.jsx)(Di,{className:`size-4`,"aria-hidden":!0})}),s.on&&(0,B.jsx)(`button`,{type:`button`,"aria-label":cD(`next`,{label:i.toLowerCase()}),onClick:()=>s.page(1),className:`${lD} -right-3`,children:(0,B.jsx)(ki,{className:`size-4`,"aria-hidden":!0})})]})},fD=sn(),pD=(e,t)=>{if(!t)return e;let n=it(e);if(!n.ok)throw Error(`The filter cannot be read: ${n.errors.map(e=>e.message).join(`; `)}`);return Yt(n.ast?fD.and(n.ast,t):t)},mD=(e,t)=>{let n=Ym(e).filter(e=>e.kind===`cards`);return n.find(e=>e.name===t)??n[0]??{kind:`cards`,name:`cards`}},hD=()=>(0,B.jsx)(`div`,{className:`flex gap-3 overflow-hidden`,children:Array.from({length:3},(e,t)=>(0,B.jsx)(Ch,{className:`h-24 w-64 shrink-0`},t))}),gD=({model:e,view:t,filter:n,sort:r=``,display:i,limit:a,chips:o=!0,empty:s,note:c,isNew:l,viewAll:u,scope:d,list:f})=>{let{resources:p,views:m}=W(),h=Sf(),g=mD(t,i),_=r||gh(e,t),v=Aw({resources:p,views:m,model:e,columns:(0,I.useMemo)(()=>fh(e,t,[]),[e,t]),filter:(0,I.useMemo)(()=>pD(n,d),[n,d]),orderBy:_}),y=eE(e,n),b=(t?.names?.singular??F(e.name)).toLowerCase(),x=t?.names?.plural??F(e.name),S=v.source?.total,C=(0,I.useMemo)(()=>v.source&&{...v.source,total:Math.min(v.source.total,a??1/0)},[v.source,a]);return(0,B.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3`,children:[o&&y.length>0||S!==void 0||c?(0,B.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[o&&y.length>0?(0,B.jsx)(Mw,{chips:y}):(0,B.jsx)(`span`,{}),(0,B.jsxs)(`p`,{className:`flex flex-wrap gap-x-3 text-muted-foreground`,children:[c&&(0,B.jsx)(`span`,{children:c}),S!==void 0&&(0,B.jsx)(`span`,{className:`tabular-nums`,children:`${S.toLocaleString(Le())} ${S===1?b:x.toLowerCase()}`})]})]}):null,v.isLoading?(0,B.jsx)(hD,{}):v.error?(0,B.jsx)(Gg,{title:cD(`couldNotLoad`),error:v.error}):!C||C.total===0?(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:s??cD(`noneMatch`,{plural:x.toLowerCase()})}):(0,B.jsx)(dD,{model:e,view:t,display:g,source:C,label:x,isNew:l}),(0,B.jsxs)(Jh,{to:WS(e,t,h,{filter:n,orderBy:_,display:g.name,savedSearch:u?.savedSearch,resource:f}),onClick:u?.onOpen,className:`flex items-center gap-1 self-end font-medium text-primary-text hover:underline`,children:[u?.label??(0,B.jsxs)(B.Fragment,{children:[cD(`viewAll`),` `,(0,B.jsx)(`span`,{className:`sr-only`,children:x.toLowerCase()})]}),(0,B.jsx)(zr,{className:`size-3.5`,"aria-hidden":!0})]})]})},_D=({model:e,view:t,empty:n,...r})=>{let{resources:i,views:a}=W(),o=yh(i,a,e.name),s=vE(e.name,t.listOf,!0),c=(t.names?.plural??F(e.name)).toLowerCase();if(!o.listOf)return null;if(s.error)return(0,B.jsx)(Gg,{title:cD(`couldNotLoadYour`,{plural:c}),error:s.error});if(!s.data)return(0,B.jsx)(Ch,{className:`h-24`});let l=gE(o.model,s.data);return l?(0,B.jsx)(gD,{...r,model:o.model,view:o.view,filter:``,scope:l,list:e.name,empty:n}):(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:n??cD(`noneYet`,{plural:c})})},vD=e=>H.list(e,``,``,500,`saved-searches`),yD=(e,t)=>{let n=U(),{resources:r,views:i}=W(),a=r[e];return E({queryKey:vD(e),enabled:t&&a!==void 0,queryFn:async()=>{let t=[],r;do{let o=await n.list(e,{pageSize:500,orderBy:gh(a,i[e]),...r&&{pageToken:r}});t.push(...o.items),r=o.nextPageToken||void 0}while(r);return t}})},bD=({model:e,of:t,target:n,targetView:r,row:i,recordKey:a})=>{let s=U(),c=Oy(),l=String(i[t.filter]??``),u=eE(n,l),d=t.name===void 0?void 0:i[t.name],f=typeof d==`string`&&d!==``?d:void 0,p=t.unseen,m=o({mutationFn:t=>s.update(e.name,a,{[p.seenAt]:t},i.etag??`*`),onSettled:()=>c(e.name)}),h=E({...wy(s,n,p?QT(l,p.field,i[p.seenAt]):``),enabled:p!==void 0}),g=(r?.names?.plural??F(n.name)).toLowerCase(),_={model:n,view:r,filter:l,sort:p?`${p.field} desc`:void 0,limit:t.limit,chips:f!==void 0,empty:Y(`noneMatch`,{plural:g}),note:p&&h.data===0&&Y(`noNew`,{plural:g}),isNew:p&&(e=>$T(e.record[p.field],i[p.seenAt])),viewAll:{label:Y(`viewAll`),savedSearch:a,...p&&{onOpen:()=>m.mutate(new Date().toISOString())}}};return{name:f,chips:u,title:f??Pw(u),body:_}},xD=({model:e,view:t,target:n,targetView:r,row:i})=>{let a=Nn(wm(e,i)),{name:o,chips:s,title:c,body:l}=bD({model:e,of:t.searchesOf,target:n,targetView:r,row:i,recordKey:a});return(0,B.jsxs)(`section`,{"aria-label":c,className:`flex flex-col gap-3 py-4 first:pt-0 last:pb-0`,children:[(0,B.jsx)(`h3`,{className:`text-[15px] font-semibold`,children:(0,B.jsx)(Jh,{to:{kind:`record`,resource:e.name,key:a},className:`hover:underline`,children:o??(0,B.jsx)(Nw,{chips:s})})}),(0,B.jsx)(gD,{...l})]})},SD=({model:e,view:t,empty:n})=>{let{resources:r,views:i}=W(),a=t.searchesOf,o=r[a.resource],s=yD(e.name,!0),c=(t.names?.plural??F(e.name)).toLowerCase();return o?s.error?(0,B.jsx)(Gg,{title:Y(`couldNotLoadYour`,{plural:c}),error:s.error}):s.data?s.data.length===0?(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:n??Y(`noneYet`,{plural:c})}):(0,B.jsx)(`div`,{className:`flex flex-col divide-y`,children:s.data.map(n=>(0,B.jsx)(xD,{model:e,view:t,target:o,targetView:i[a.resource],row:n},Nn(wm(e,n))))}):(0,B.jsx)(Ch,{className:`h-40`}):null},CD=({node:e,slots:t})=>{let{resource:n,filter:r=``,sort:i,limit:a,display:o,title:s,description:c,empty:l}=My(e),{resources:u,views:d}=W(),f=u[n];if(!f)return null;let p=d[f.name];return(0,B.jsx)(Fy,{title:s,description:c,actions:t.actions,children:p?.searchesOf?(0,B.jsx)(SD,{model:f,view:p,empty:l}):p?.listOf===void 0?(0,B.jsx)(gD,{model:f,view:p,filter:r,sort:i,limit:a,display:o,empty:l}):(0,B.jsx)(_D,{model:f,view:p,limit:a,display:o,empty:l})})},wD=e=>e.type===`boolean`||e.type===`enum`,TD=({model:e,fields:t,title:n,description:r,stored:i})=>{let{resources:a,views:o}=W(),s=uf(e.name),c=U(),l=ly(),u=Oy(),d=o[e.name],[f,p]=(0,I.useState)(i),[m,h]=(0,I.useState)(()=>px(e,t,i?.record)),[g,_]=(0,I.useState)({}),[v,y]=(0,I.useState)(),[b,x]=(0,I.useState)(!1),S=(0,I.useRef)(Promise.resolve()),C=(0,I.useRef)(i),w=px(e,t,void 0),T=f?dy(s,`update`)&&f.permissions?.update!==!1:dy(s,`create`),E=t.filter(t=>!wD(e.fields[t])),D=E.some(t=>f?Dg(e.fields[t],m[t],f.record[t]):m[t]!==w[t]),O=async t=>{let n=C.current;if(n){let r=await c.update(e.name,n.key,mx(e,t,n.record),n.etag??`*`);return{...Cy(e,r.record),etag:r.etag,permissions:r.permissions??n.permissions}}let r=await c.create(e.name,Lg(e,a,{...w,...t}));return{...Cy(e,r.record),etag:r.etag}},k=t=>{let r=S.current.then(async()=>{x(!0),y(void 0),await O(t).then(async r=>{C.current=r,p(r),_(e=>Object.fromEntries(Object.entries(e).filter(([e])=>!Object.hasOwn(t,e)))),await u(e.name),l.show({state:`success`,title:fv(`saved`,{label:n??fv(`settings`)})})},e=>{_(t=>({...t,...ux(e)})),y(e)}),x(!1)});S.current=r},A=(t,n)=>{h(e=>({...e,[t]:n})),wD(e.fields[t])&&k({[t]:n})};return(0,B.jsx)(Fy,{title:n,description:r,className:`h-full`,children:(0,B.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),D&&k(Object.fromEntries(E.map(e=>[e,m[e]])))},children:[v!==void 0&&Object.keys(g).length===0&&(0,B.jsx)(Gg,{title:fv(`notSaved`),error:v}),t.map(t=>{let n=e.fields[t],r=d?.fields[t]?.label??F(t),i=g[t];return(0,B.jsx)(eg,{name:t,label:r,help:d?.fields[t]?.help,error:i&&lx(n,r,i),children:(0,B.jsx)(Nv,{field:n,hints:d?.fields[t],value:m[t],stored:f?.record[t]??w[t],invalid:!!i,locked:!T||n.readOnly,resource:e.name,onChange:e=>A(t,e)})},t)}),T&&D&&(0,B.jsx)(`div`,{children:(0,B.jsx)(G,{type:`submit`,variant:`primary`,size:`sm`,loading:b,children:fv(`save`)})})]})})},ED=e=>{let t=Ey(e.model,{});return t.isPending?(0,B.jsx)(Fy,{title:e.title,description:e.description,children:(0,B.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,B.jsx)(Ch,{className:`h-4 w-1/2`}),(0,B.jsx)(Ch,{className:`h-4 w-1/3`})]})}):t.error?(0,B.jsx)(Fy,{title:e.title,description:e.description,children:(0,B.jsx)(Gg,{title:fv(`couldNotLoad`),error:t.error})}):(0,B.jsx)(TD,{...e,stored:t.data??void 0})},DD=({node:e})=>{let{resource:t,fields:n=[],...r}=My(e),i=W().resources[t];return i?(0,B.jsx)(ED,{...r,model:i,fields:n.filter(e=>Object.hasOwn(i.fields,e)),stored:void 0}):null},OD=(e,t)=>{let{resources:n}=W(),r=U(),i=JSON.stringify(e),a=(0,I.useMemo)(()=>JSON.parse(i).map(yu),[i]),o=e=>!!(t&&Object.hasOwn(t.model.fields,e)),s=[...new Set(a.flatMap(e=>e.ok?e.paths:[]))],c=new Map(s.flatMap(e=>{let t=xu(e,o);return t===void 0?[]:[[e,t]]})),l=s.filter(e=>!c.has(e)),u=[...new Set(c.values())].flatMap(e=>n[e]?[n[e]]:[]),d=qb(t,l),p=f({queries:u.map(e=>wy(r,e))});return a.map(e=>{if(!e.ok)return!1;let t={};for(let n of e.paths){let e=c.get(n);if(e===void 0){let e=d[l.indexOf(n)];if(e.state===`loading`)return;e.state===`ready`&&(t[n]=e.value);continue}let r=u.findIndex(t=>t.name===e);if(r===-1)t[n]=0;else if(p[r].isPending)return;else t[n]=p[r].data??0}return bu(e,t)})},kD=({node:e,children:t})=>{let{when:n}=My(e),[r]=OD([n],ey());return r?(0,B.jsx)(B.Fragment,{children:t}):null},AD=`text-2xl font-semibold tracking-tight tabular-nums`,jD=({model:e,filter:t})=>{let{views:n}=W(),r=Ty(e,t);return r.isPending?(0,B.jsx)(Ch,{className:`h-8 w-16`}):r.error?(0,B.jsx)(`span`,{className:`text-danger-text`,children:fv(`couldNotCount`)}):(0,B.jsx)(Jh,{to:tb(n[e.name],e.name,t),className:`${AD} hover:text-primary-text after:absolute after:inset-0 after:content-['']`,children:r.data.toLocaleString(Le())})},MD=({field:e,format:t})=>{let n=Kb(ey(),e);return n.state===`loading`?(0,B.jsx)(Ch,{className:`h-8 w-16`}):n.state===`missing`?null:(0,B.jsx)(`span`,{className:AD,children:(0,B.jsx)(Hb,{model:n.model,field:n.field,value:n.value,format:t})})},ND=({node:e})=>{let{label:t,value:n,resource:r,filter:i,field:a,format:o,description:s}=My(e),{resources:c}=W(),l=r===void 0?void 0:c[r];return(0,B.jsxs)(Fy,{className:`relative h-full`,bodyClassName:`flex flex-col`,children:[(0,B.jsx)(`p`,{className:`text-muted-foreground break-words`,children:t}),(0,B.jsxs)(`div`,{className:`mt-auto pt-1`,children:[n!==void 0&&(0,B.jsx)(`span`,{className:AD,children:n}),l&&(0,B.jsx)(jD,{model:l,filter:i}),a!==void 0&&(0,B.jsx)(MD,{field:a,format:o})]}),s&&(0,B.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:s})]})},PD=(e,t)=>{let n=e.position;if(!n||!dy(t,`update`))return;let r=e.fields[n.field];return r&&!r.readOnly?n.field:void 0},FD=(e,t)=>e.position?.within===void 0?PD(e,t):void 0,ID=(e,t,n)=>t.position?.within!==void 0&&e.field===t.position.within&&!e.through&&!e.from&&!e.filter?PD(t,n):void 0,LD=(e,t,n,r)=>{if(t===void 0||e?.list?.drag?.rank!==!0||r!==``)return!1;let i=_h(n);return i.columnId===t&&i.direction===`asc`},RD=e=>e===null?`none`:`value:${e}`,zD=e=>e.data.current?.sortable!==void 0,BD=e=>{let t=le(e),n=t.find(e=>e.data?.droppableContainer&&zD(e.data.droppableContainer));return n?[n]:t.length>0?t:ce(e)},VD=(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=>!zD(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=HD(o,n,d.id)[0];return{x:d.rect.left+(d.rect.width-t.width)/2,y:f?.rect.top??d.rect.top}},HD=(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),UD=(e,t)=>{let n=e.code===`ArrowDown`?1:e.code===`ArrowUp`?-1:0;if(n===0)return VD(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=HD(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}},WD=(e,t,n,r)=>{let i=Ne({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=>hh(e,t))),total:a[0]?.total??0,loading:i.isPending,error:i.error,more:i.hasNextPage,loadMore:()=>void i.fetchNextPage()}},GD=({model:e,by:t,value:n,fields:r,filter:i,orderBy:a})=>{let{resources:o,views:s}=W(),c=Aw({resources:o,views:s,model:e,columns:r,filter:Km(i,t,n),orderBy:a});return WD(e,c.page,c.key,!0)},KD=(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))]},qD=({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=GD({model:e,by:n.by,value:r.value,fields:i,filter:a,orderBy:o}),p=qm(e,t,n),m=new Set(f.rows.map(e=>e.key)),h=new Map(c.map(e=>[e.row.key,e])),g=f.rows.filter(e=>h.has(e.key)&&h.get(e.key).to!==r.value),_=c.filter(e=>e.to===r.value&&!m.has(e.row.key)).map(e=>e.row),v=f.rows.filter(e=>!g.includes(e)).map(e=>h.has(e.key)?h.get(e.key).row:e),y=c.findLast(e=>e.to===r.value&&e.order),b=KD([..._,...v],y?.order).slice(0,s),{setNodeRef:x,isOver:S}=ke({id:RD(r.value),data:{column:r,rows:b}}),C=f.total-g.length+_.length;if(r.value===null&&!f.loading&&C===0&&!S)return null;let w=(t?.names?.plural??F(e.name)).toLowerCase(),T=t?.fields[n.by];return(0,B.jsxs)(`section`,{ref:x,"aria-label":`${r.label}, ${C}`,className:P(`flex w-72 shrink-0 snap-start flex-col gap-2 rounded-lg bg-surface p-2`,S&&`ring-2 ring-primary/30`),children:[(0,B.jsxs)(`header`,{className:`flex items-center justify-between gap-2 px-1 pt-0.5`,children:[(0,B.jsx)(`h2`,{className:`min-w-0 truncate text-body font-medium`,children:r.value===null?(0,B.jsx)(`span`,{className:`text-muted-foreground`,children:r.label}):(0,B.jsx)(Rb,{value:r.value,hints:T,children:r.label})}),!f.loading&&(0,B.jsx)(`span`,{className:`text-xs tabular-nums text-muted-foreground`,children:C.toLocaleString(Le())})]}),f.loading?Array.from({length:3},(e,t)=>(0,B.jsx)(Ch,{className:`h-20`},t)):f.error?(0,B.jsx)(Gg,{title:K(`couldNotLoadRows`),error:f.error}):b.length===0?(0,B.jsx)(`p`,{className:`px-1 py-4 text-center text-xs text-muted-foreground`,children:K(`noPlural`,{plural:w})}):(0,B.jsx)(ue,{id:RD(r.value),items:b.map(e=>e.key),strategy:re,children:(0,B.jsx)(`ul`,{className:`-mb-2 flex flex-col`,children:b.map(n=>(0,B.jsx)(JD,{model:e,view:t,card:p,row:n,column:r,rows:b,draggable:(l||u)&&fy(n.record,`update`),placeable:u,dragged:d},n.key))})}),s===void 0&&f.more&&(0,B.jsx)(G,{size:`sm`,variant:`ghost`,onClick:f.loadMore,children:K(`showMore`)})]})},JD=({model:e,view:t,card:n,row:r,column:i,rows:a,draggable:o,placeable:s,dragged:c})=>{let{setNodeRef:l,setActivatorNodeRef:u,listeners:d,isDragging:f,isOver:p,active:m,transform:h,transition:g}=Te({id:r.key,data:{row:r,column:i,rows:a},disabled:{draggable:!o,droppable:!s}}),_=p&&m?.data.current?.column?.value!==i.value;return(0,B.jsx)(`li`,{ref:e=>{l(e),u(e?.querySelector(`a`)??e)},...d,onDragStart:e=>e.preventDefault(),onClickCapture:e=>{c()&&(e.preventDefault(),e.stopPropagation())},style:{transform:h?`translate3d(${h.x}px, ${h.y}px, 0)`:void 0,transition:g},className:P(`relative pb-2`,o&&`cursor-grab touch-manipulation`,f&&`opacity-40`,_&&`before:absolute before:inset-x-0 before:-top-1 before:h-0.5 before:rounded-full before:bg-primary`),children:(0,B.jsx)(nD,{model:e,view:t,display:n,row:r,swipe:!1})})},YD=e=>e.kind===`and`?e.args.flatMap(YD):[e],XD=e=>e.kind===`string`?String(e.value):void 0,ZD=(e,t)=>{if(e.kind===`compare`&&e.op===`=`&&e.field.path.join(`.`)===t){let t=XD(e.value);return t===void 0?void 0:[t]}if(e.kind===`in`&&e.field.path.join(`.`)===t){let t=e.values.map(XD);return t.every(e=>e!==void 0)?t:void 0}},QD=(e,t,n)=>{let r=it(e);if(!r.ok||!r.ast)return n;let i=YD(r.ast).map(e=>ZD(e,t)).filter(e=>e!==void 0);return n.filter(e=>i.every(t=>e.value!==null&&t.includes(e.value)))},$D=(e,t)=>t!==null&&Object.hasOwn(e,t)?e[t]:void 0,eO=M(`app/hand-order`),tO=(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:wm(e,r),data:Object.fromEntries(a.map(e=>[e,t[e]])),etag:i}]}),nO=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},rO=(e,t)=>t===void 0?e:`(${e}) AND (${t})`,iO=async(e,t,n,r)=>{let i=t.position?.after;if(!i)return{after:[],before:[]};let a=t.primaryKey[0],o=wm(t,r),s=e=>Nn([e]),c=await nO(e,i.resource,rO(Yt(cn.or(cn.eq(i.field,o),cn.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),[f,p]=await Promise.all([nO(e,t.name,rO(Yt(cn.in(a,[o,...u])),i.while)),d.length===0?[]:nO(e,t.name,Yt(cn.in(a,d)))]),m=e=>{let r=Nn(wm(t,e));return{key:r,rank:e[t.position.field],title:ur(t,n,e,r)}},h=f.some(e=>s(e[a])===s(o));return{after:f.filter(e=>s(e[a])!==s(o)).map(m),before:h?p.map(m):[]}},aO=e=>typeof e==`number`&&Number.isInteger(e),oO=(e,t,n)=>{let r=0;for(;r<t&&aO(e[r])&&(r===0||e[r]>e[r-1]);)r+=1;let i=e.length;for(;i-1>n&&aO(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}},sO=(e,t,n)=>{let r=e.findIndex(e=>e.key===t.key);return r===-1?[...e.slice(0,n),t,...e.slice(n)]:ee(e,r,n)},cO=(e,t,n)=>{let r=e.findIndex(e=>e.key===t.key);return{order:sO(e,t,n),first:r===-1?n:Math.min(r,n),last:r===-1?n:Math.max(r,n)}},lO=e=>typeof e.record.etag==`string`?e.record.etag:`*`,uO=(e,t,n,r,i,a,o,s,c)=>{let l=(r.record[t]??null)!==i.value,u=oO(a.map(e=>e.record[n]),o,s),d=a.slice(u.first,u.last+1),f=e=>l&&e.key===r.key?`*`:lO(e),p=(t,r)=>({op:`reorder`,resource:e.name,field:n,keys:t.map(t=>wm(e,t.record)),start:r,etags:Object.fromEntries(t.map(t=>[Nn(wm(e,t.record)),f(t)]))}),m=d.filter(e=>e.key!==r.key),h=c===void 0?[p(d,u.start)]:[p([r],c),...m.length>0?[p(m,u.start)]:[]];return l?[{op:`update`,resource:e.name,key:wm(e,r.record),data:{[t]:i.value},etag:lO(r)},...h]:h},dO=(e,t,n)=>{let r=new Map(t.map(t=>[Nn(wm(e,t.record)),t.record])),i=new Map;for(let t of n.results){let n=t.op===`reorder`?t.records:t.op===`update`?[t]:[];for(let{record:t,etag:r}of n)i.set(Nn(wm(e,t)),{record:t,etag:r})}return[...i].flatMap(([e,t])=>{let n=r.get(e);return n?[{before:n,...t}]:[]})},fO=M(`app/rank-after`),pO=e=>e!=null&&e!==``,mO=({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}=cO(n,r,l),f=i.map(e=>e.record[t]),p=oO(f,u,d),m=new Map(i.map((t,n)=>[Nn(wm(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(wm(e,r.record)))),_=a.after.filter(e=>pO(h(e))&&Number(h(e))>=g),v=a.before.find(e=>pO(h(e))&&Number(h(e))<=g),y=v?fO(`dependsOn`,{record:v.title,other:o}):_[0]&&fO(`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=>!pO(h(e))||Number(h(e))>b))return{place:{index:l,bump:b},reason:c}}return{reason:c}},hO=({model:e,view:t,by:n,rank:r,drop:i,labelOf:a,titleOf:s})=>{let c=U(),l=ly(),u=Oy(),[d,f]=(0,I.useState)([]),p=(0,I.useRef)(void 0),m=e=>f(t=>t.filter(t=>t.row.key!==e)),h=r?[n,r]:[n],g=o({mutationFn:e=>e(),onError:e=>l.show({state:`error`,title:K(`couldNotUndo`),description:Jm(e)}),onSettled:()=>u(e.name)}),_=async(t,r)=>{let a=i&&$D(i,r.value);if(!a)throw Error(`The column ${r.label} takes no cards`);let o=wm(e,t.record),s=typeof t.record.etag==`string`?t.record.etag:`*`,l=await a({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(tO(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 iO(c,e,t,n.record),u=mO({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?eO(`notMoved`):eO(`movedToPlace`,{place:u.place.index+1}),description:u.reason}),!d)return u.place.index!==a.index&&y(n,i,cO(a.rows,n,u.place.index).order),u.place},x=async(t,i,a)=>{let o=await b(t,i,a);if(!o)return;let{order:s,first:l,last:u}=cO(a.rows,t,o.index);return v(dO(e,s,await c.batchWrite(uO(e,n,r,t,i,s,l,u,o.bump))),i)},S=o({mutationFn:async({row:t,to:a,place:o})=>{if(o&&!r)throw Error(`A board places a card only by its rank`);let s=t.record[n]??null;if(i&&a.value!==s)return _(t,a);if(o)return x(t,a,o);let l=typeof t.record.etag==`string`?t.record.etag:`*`,u=await c.update(e.name,wm(e,t.record),{[n]:a.value},l);return v([{before:t.record,record:u.record,etag:u.etag}],a)},onMutate:({row:e,to:t,place:n})=>y(e,t,n&&cO(n.rows,e,n.index).order),onSuccess:(e,{row:t,to:r})=>{if(!e)return;let{landed:i,undo:o}=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?K(`orderChanged`):K(`stayedIn`,{column:a(i)}):K(`movedTo`,{column:a(i)});if(!o){l.show({state:`success`,title:c});return}let u=l.show({state:`success`,title:c,action:{label:K(`undo`),onClick:()=>{l.dismiss(u),p.current=void 0,g.mutate(o)}}});p.current=u},onError:(e,{row:t,to:r})=>{m(t.key);let i=(t.record[n]??null)===r.value?K(`couldNotReorder`):K(`couldNotMoveTo`,{to:r.label});l.show({state:`error`,title:i,description:Jm(e)})},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}})}},gO=(e,t)=>{let n=e.data.current;if(!n?.column||!n.rows)return;if(n.sortable)return{column:n.column,rows:n.rows,index:n.sortable.index};let r=n.rows.some(e=>e.key===t.key);return{column:n.column,rows:n.rows,index:r?n.rows.length-1:n.rows.length}},_O=({model:e,view:t,display:n,fields:r,filter:i,orderBy:a,limit:o})=>{let s=Wm(e,t,n),c=QD(i,n.by,s),l=qm(e,t,n),u=uf(e.name),{boardDrops:d}=p_(),f=t?.list?.drag,p=typeof f?.board==`string`?f.board:void 0,m=p===void 0?void 0:d?.[p],h=t=>dy(u,`update`)&&(f?.board===!0?!e.fields[n.by]?.readOnly:m!==void 0&&$D(m,t)!==void 0),g=c.some(e=>h(e.value)),_=Gm(e),v=f?.rank===!0&&_!==void 0&&FD(e,u)!==void 0,y=_?`${_} asc`:a,b=e=>s.find(t=>t.value===e)?.label??String(e),x=e=>String(e.labels[l.title]??e.record[l.title]??e.key),{moves:S,move:C}=hO({model:e,view:t,by:n.by,rank:_,drop:m,labelOf:b,titleOf:x}),[w,T]=(0,I.useState)(),E=(0,I.useRef)(!1),D=ne(Me(se,{activationConstraint:{distance:4}}),Me(xe,{activationConstraint:{delay:250,tolerance:5}}),Me(ae,{keyboardCodes:{start:[`Space`],cancel:[`Escape`],end:[`Space`,`Enter`]},coordinateGetter:UD}));if(p!==void 0&&!m)return(0,B.jsx)(dv,{children:K.rich(`noDrop`,{drop:p})});let O=e=>c.find(t=>RD(t.value)===e),k=e=>e.record[n.by]??null,A=(e,t)=>h(k(e))&&h(t.value),j=(e,t)=>{if(!t)return{over:K(`noColumn`)};let n=v?gO(t,e):void 0;if(!n)return{over:O(t.id)?.label??K(`noColumn`)};let r=n.rows.some(t=>t.key===e.key)?n.rows.length:n.rows.length+1;return{over:K(`placeOf`,{column:n.column.label,place:n.index+1,count:r}),place:K(`place`,{column:n.column.label,place:n.index+1})}},ee=(e,t)=>{let n=(v?gO(t,e)?.column:void 0)??O(t.id);return n!==void 0&&n.value!==k(e)&&!A(e,n)};return(0,B.jsxs)(me,{sensors:D,collisionDetection:BD,onDragStart:({active:e})=>{E.current=!0,T(e.data.current.row)},onDragEnd:({active:e,over:t})=>{T(void 0),setTimeout(()=>E.current=!1);let n=e.data.current.row;if(!t)return;let r=v?gO(t,n):void 0;if(!r){let e=O(t.id);e&&e.value!==k(n)&&A(n,e)&&C(n,e);return}let i=r.rows.findIndex(e=>e.key===n.key);if(i!==-1||A(n,r.column)){if(i===-1&&m)return C(n,r.column);i!==r.index&&C(n,r.column,{rows:r.rows,index:r.index})}},onDragCancel:()=>{T(void 0),setTimeout(()=>E.current=!1)},accessibility:{announcements:{onDragStart:({active:e})=>K(`pickedUp`,{title:x(e.data.current.row)}),onDragOver:({active:e,over:t})=>K(`isOver`,{title:x(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||ee(n,t))return K(`putBack`,{title:x(n)});let r=j(n,t);return K(`wasMovedTo`,{title:x(n),to:r.place??r.over})},onDragCancel:({active:e})=>K(`cancelled`,{title:x(e.data.current.row)})},screenReaderInstructions:{draggable:K(v?g?`boardAnywhere`:`boardWithin`:`boardAcross`)}},children:[(0,B.jsx)(`div`,{className:`relative min-w-0 flex-1 overflow-x-auto`,children:(0,B.jsx)(`div`,{className:`flex snap-x items-start gap-3 pb-2`,children:c.map(a=>(0,B.jsx)(qD,{model:e,view:t,display:n,column:a,fields:r,filter:i,orderBy:y,limit:o,moves:S,movable:h(a.value),placeable:v,dragged:()=>E.current},RD(a.value)))})}),(0,B.jsx)(Oe,{children:w&&(0,B.jsx)(nD,{model:e,view:t,display:l,row:w,swipe:!1})})]})},vO=864e5,yO=e=>new Date(e).toISOString().slice(0,10),bO=e=>Date.parse(`${e}T00:00:00Z`),xO=(e,t)=>yO(bO(e)+t*vO),SO=e=>xO(e,-((new Date(bO(e)).getUTCDay()+6)%7)),CO=(e,t=0)=>{let n=new Date(bO(e));return yO(Date.UTC(n.getUTCFullYear(),n.getUTCMonth()+t,1))},wO=({scale:e,day:t})=>({scale:e,day:e===`month`?CO(t):SO(t)}),TO=(e,t,n=Xf())=>wO(e??{scale:`month`,day:np(t,n)}),EO=(e,t,n=Xf())=>wO({scale:e,day:np(t,n)}),DO=(e,t)=>e.scale===`month`?{scale:`month`,day:CO(e.day,t)}:{scale:`week`,day:xO(SO(e.day),7*t)},OO=e=>{let t=SO(e.scale===`month`?CO(e.day):e.day),n=(bO(e.scale===`month`?xO(SO(xO(CO(e.day,1),-1)),6):xO(t,6))-bO(t))/vO+1;return Array.from({length:n},(e,n)=>xO(t,n))},kO=e=>{let t=OO(e);return{from:t[0],to:xO(t.at(-1),1)}},AO=(e,t)=>t.fields[e.start]?.type===`timestamp`,jO=(e,t,n,r=Xf())=>{let i=AO(e,t),a=e=>new Date(ip(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=cn.and(cn.gte(e.start,o(n.from)),cn.lt(e.start,o(n.to)));if(e.end===void 0)return Yt(s);let c=i?cn.gt(e.end,o(n.from)):cn.gte(e.end,o(n.from));return Yt(cn.or(s,cn.and(cn.lt(e.start,o(n.from)),c)))},MO=(e,t)=>e===``?t:`(${e}) AND (${t})`,NO=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},PO=(e,t,n,r=Xf())=>{let i=NO(e[t.start]);if(i===void 0)return;let a=AO(t,n),o=e=>a?np(e,r):yO(e),s=o(i),c=t.end===void 0?void 0:NO(e[t.end]),l=c===void 0?s:o(a?c-1:c);return{first:s,last:l<s?s:l}},FO=(e,t,n,r,i=Xf())=>{let a=PO(e,t,n,i);return a?r.filter(e=>e>=a.first&&e<=a.last):[]},IO=(e,t)=>e.toSorted((e,n)=>(NO(e.record[t.start])??0)-(NO(n.record[t.start])??0)),LO=(e,t,n,r,i=Xf())=>{let a=new Map(r.map(e=>[e,[]]));for(let o of IO(e,t))for(let e of FO(o.record,t,n,r,i))a.get(e).push(o);return a},RO=(e,t,n,r,i,a=Xf())=>{let o=(bO(i)-bO(r))/vO,s=AO(t,n),c=e=>{let t=NO(e);if(t!==void 0)return s?new Date(rp(t+ep(t,a)+o*vO,a)).toISOString():xO(yO(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}}},zO=({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,B.jsx)(Jh,{to:s(e),className:t,"aria-label":n,"aria-current":i?`page`:void 0,children:r}):(0,B.jsx)(`button`,{type:`button`,className:t,"aria-label":n,"aria-pressed":i,onClick:()=>c?.(e),children:r}),u=yf({variant:`secondary`,size:`sm`});return(0,B.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,B.jsx)(`h2`,{className:`text-sm font-medium`,children:e}),(0,B.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,B.jsxs)(`div`,{className:`flex items-center gap-1`,children:[l(n,u,K(`previousPeriod`,{unit:t}),(0,B.jsx)(Di,{className:`size-3.5`})),l(r,u,K(`today`),K(`today`)),l(i,u,K(`nextPeriod`,{unit:t}),(0,B.jsx)(ki,{className:`size-3.5`}))]}),(0,B.jsx)(`span`,{role:`group`,"aria-label":o,className:ze.group(),children:a.map(e=>(0,B.jsx)(I.Fragment,{children:l(e.view,ze.option(e.current),e.label,e.label,e.current)},e.label))})]})]})},BO=e=>{let t=OO(e),n=e=>Date.parse(`${e}T00:00:00Z`);return e.scale===`month`?_p(n(e.day)):Sp(n(t[0]),n(t.at(-1)))},VO=({view:e,now:t,linkTo:n,onView:r})=>{let i=e.scale===`month`&&np(t,Xf()).startsWith(e.day.slice(0,7)),a=n=>n===`week`&&i?EO(`week`,t):TO({scale:n,day:e.day},t),o=(t,n)=>({view:a(t),label:n,current:e.scale===t});return(0,B.jsx)(zO,{heading:BO(e),unit:e.scale===`month`?`month`:`week`,previous:DO(e,-1),today:EO(e.scale,t),next:DO(e,1),scales:[o(`month`,K(`month`)),o(`week`,K(`week`))],scalesLabel:K(`calendarScale`),linkTo:n,onView:r})},HO=`day:`,UO=e=>`${HO}${e}`,WO=(e,t)=>`${e}@${t}`,GO=(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(UO(xO(o,a)));if(s)return{x:s.left+(s.width-n.width)/2,y:s.top+4}},KO=({day:e,count:t,children:n,more:r,inMonth:i,today:a,week:o})=>{let{setNodeRef:s,isOver:c}=ke({id:UO(e)}),l=Date.parse(`${e}T00:00:00Z`);return(0,B.jsxs)(`section`,{ref:s,"aria-label":`${xp(l)}, ${t}`,className:P(`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,B.jsxs)(`header`,{className:P(`flex items-center gap-1 px-0.5 text-xs`,i?`text-foreground`:`text-muted-foreground`),children:[o&&(0,B.jsx)(`span`,{className:`text-muted-foreground`,children:bp(l)}),(0,B.jsx)(`span`,{"aria-current":a?`date`:void 0,className:P(`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]})},qO=(e,t,n,r)=>{let i=n.title??lr(e,t),a=e.fields[i],o=r.labels[i]??(a?Rm(a,r.record[i],t?.fields[i]):``);return o===``?r.key:o},JO=(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 np(a,Xf())===r?Cp(a):void 0},YO=({model:e,view:t,display:n,row:r,day:i,className:a})=>{let o=nE(e),s=JO(e,n,r,i);return(0,B.jsxs)(Jh,{to:{kind:`record`,resource:e.name,key:r.key},onClick:()=>o(r.record),className:P(`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,B.jsx)(`span`,{className:`shrink-0 tabular-nums text-muted-foreground`,children:s}),(0,B.jsx)(`span`,{className:`min-w-0 truncate`,children:qO(e,t,n,r)})]})},XO=({movable:e,dragged:t,...n})=>{let{setNodeRef:r,setActivatorNodeRef:i,listeners:a,isDragging:o}=j({id:WO(n.row.key,n.day),data:{row:n.row,day:n.day},disabled:!e});return(0,B.jsx)(`div`,{ref:e=>{r(e),i(e?.querySelector(`a`)??e)},...a,onDragStart:e=>e.preventDefault(),onClickCapture:e=>{t()&&(e.preventDefault(),e.stopPropagation())},className:P(`min-w-0`,e&&`cursor-grab touch-manipulation`,o&&`opacity-40`),children:(0,B.jsx)(YO,{...n})})},ZO=({model:e,display:t,range:n,fields:r,filter:i})=>{let{resources:a,views:o}=W(),s=Aw({resources:a,views:o,model:e,columns:r,filter:MO(i,jO(t,e,n)),orderBy:`${t.start} asc`}),c=WD(e,s.page,s.key,!0),l=c.more&&!c.loading&&c.rows.length<500;(0,I.useEffect)(()=>{l&&c.loadMore()},[l,c.rows.length]);let u=c.rows.length>500||c.rows.length===500&&c.more;return{rows:c.rows.slice(0,500),capped:u,loading:c.loading,error:c.error}},QO=(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)},$O=(e,t)=>{let n=U(),r=ly(),i=Oy(),[a,s]=(0,I.useState)([]),c=e=>s(t=>t.filter(t=>t.key!==e)),l=o({mutationFn:({row:t,patch:r})=>{let i=typeof t.record.etag==`string`?t.record.etag:`*`;return n.update(e.name,wm(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:K(`couldNotMoveTo`,{to:pp(Date.parse(`${n}T00:00:00Z`))}),description:Jm(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:RO(n.record,t,e,r,i),to:i})}},ek=3,tk=({model:e,view:t,display:n,fields:r,filter:i,at:a,linkTo:o,now:s=Date.now()})=>{let[c,l]=(0,I.useState)(),u=TO(o?a:c,s),d=OO(u),f=ZO({model:e,display:n,range:kO(u),fields:r,filter:i}),{moves:p,move:m}=$O(e,n),h=LO(QO(f.rows,p),n,e,d),g=dy(uf(e.name),`update`)&&[n.start,n.end].every(t=>t===void 0||!e.fields[t]?.readOnly),[_,v]=(0,I.useState)(),y=(0,I.useRef)(!1),b=ne(Me(se,{activationConstraint:{distance:4}}),Me(xe,{activationConstraint:{delay:250,tolerance:5}}),Me(ae,{keyboardCodes:{start:[`Space`],cancel:[`Escape`],end:[`Space`,`Enter`]},coordinateGetter:GO})),x=np(s,Xf()),S=u.scale===`week`,C=e=>pp(Date.parse(`${String(e).slice(UO(``).length)}T00:00:00Z`)),w=r=>qO(e,t,n,r.row),T={onDragStart:({active:e})=>K(`pickedUp`,{title:w(e.data.current)}),onDragOver:({active:e,over:t})=>K(`isOver`,{title:w(e.data.current),over:t?C(t.id):K(`noDay`)}),onDragEnd:({active:e,over:t})=>t?K(`wasMovedTo`,{title:w(e.data.current),to:C(t.id)}):K(`putBack`,{title:w(e.data.current)}),onDragCancel:({active:e})=>K(`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(UO(``).length):void 0;i&&i!==r&&m(n,r,i)},k=(e,t)=>{let n=TO({scale:`week`,day:e},s),r=K(`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,B.jsx)(Jh,{to:o(n),className:i,children:r}):(0,B.jsx)(`button`,{type:`button`,className:i,onClick:()=>l(n),children:r})};return(0,B.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-3`,children:[(0,B.jsx)(VO,{view:u,now:s,linkTo:o,onView:l}),f.error&&(0,B.jsx)(Gg,{title:K(`couldNotLoadRows`),error:f.error}),f.capped&&(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:K(`capped`,{limit:500,unit:u.scale})}),(0,B.jsxs)(me,{sensors:b,collisionDetection:BD,onDragStart:D,onDragEnd:O,onDragCancel:E,accessibility:{announcements:T,screenReaderInstructions:{draggable:K(`calendarInstructions`)}},children:[(0,B.jsxs)(`div`,{className:`overflow-hidden rounded-lg border border-border`,children:[!S&&(0,B.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,B.jsx)(`span`,{className:`bg-surface px-1.5 py-1 text-xs font-medium text-muted-foreground`,children:bp(Date.parse(`${e}T00:00:00Z`))},e))}),(0,B.jsx)(`div`,{className:P(`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,ek);return(0,B.jsx)(KO,{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,B.jsx)(Ch,{className:`h-4`}):a.map(i=>(0,B.jsx)(XO,{model:e,view:t,display:n,row:i,day:r,movable:g&&fy(i.record,`update`),dragged:()=>y.current},i.key))},r)})})]}),(0,B.jsx)(Oe,{children:_&&(0,B.jsx)(YO,{model:e,view:t,display:n,row:_.row,day:_.day})})]})]})},nk=864e5,rk=e=>Date.parse(`${e}T00:00:00Z`),ik=(e,t=0)=>{let n=new Date(rk(e));return new Date(Date.UTC(n.getUTCFullYear(),Math.floor(n.getUTCMonth()/3)*3+3*t,1)).toISOString().slice(0,10)},ak=({scale:e,day:t})=>({scale:e,day:e===`week`?SO(t):e===`month`?CO(t):ik(t)}),ok=(e,t,n=Xf())=>ak(e??{scale:`month`,day:np(t,n)}),sk=(e,t)=>{let{scale:n,day:r}=ak(e);return{scale:n,day:n===`week`?xO(r,7*t):n===`month`?CO(r,t):ik(r,t)}},ck=e=>{let t=ak(e).day,n=(rk(sk(e,1).day)-rk(t))/nk;return Array.from({length:n},(e,n)=>xO(t,n))},lk=e=>({from:ak(e).day,to:sk(e,1).day}),uk=(e,t,n,r=Xf())=>{let i=np(n,r),a=ck(e);return ak({scale:t,day:i>=a[0]&&i<=a.at(-1)?i:a[0]})},dk=e=>{let t=ck(e);return e.scale===`week`?Sp(rk(t[0]),rk(t.at(-1))):e.scale===`month`?_p(rk(t[0])):yp(rk(t[0]),rk(CO(t.at(-1))))},fk=e=>{let t=ck(e);if(e.scale===`week`)return t.map((e,t)=>({index:t,span:1,label:`${bp(rk(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:vp(rk(t[e]))}))},pk=(e,t,n,r,i=Xf())=>{let a=PO(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}},mk=`none`,hk=(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?mk:`value:${String(e)}`,c=n?K(`noValue`,{label:o?.label??F(i)}):t.labels[i]??Rm(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)},gk=`grid grid-cols-1 sm:grid-cols-[12rem_minmax(0,1fr)]`,_k=(e,t)=>`${e/t*100}%`,vk=({ticks:e,days:t,today:n,label:r,trackRef:i})=>(0,B.jsxs)(`div`,{className:P(gk,`border-b border-border bg-surface`),children:[(0,B.jsx)(`span`,{className:`hidden truncate px-2 py-1 text-xs font-medium text-muted-foreground sm:block`,children:r}),(0,B.jsx)(`div`,{ref:i,"aria-hidden":!0,className:`relative h-6`,children:e.map(e=>(0,B.jsx)(`span`,{className:P(`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:_k(e.index,t.length),width:_k(e.span,t.length)},children:e.label},e.index))})]}),yk=({ticks:e,days:t,today:n})=>{let r=t.indexOf(n);return(0,B.jsxs)(`div`,{"aria-hidden":!0,className:P(gk,`pointer-events-none absolute inset-0`),children:[(0,B.jsx)(`span`,{className:`hidden sm:block`}),(0,B.jsxs)(`div`,{className:`relative`,children:[r>=0&&(0,B.jsx)(`span`,{className:`absolute inset-y-0 bg-primary/10`,style:{left:_k(r,t.length),width:_k(1,t.length)}}),e.map(e=>(0,B.jsx)(`span`,{className:P(`absolute inset-y-0 w-px bg-border`,(e.minor||e.index===0)&&`hidden sm:block`),style:{left:_k(e.index,t.length)}},e.index))]})]})},bk=({model:e,view:t,display:n,row:r,days:i,movable:a,dragged:o})=>{let s=pk(r.record,n,e,i);return(0,B.jsxs)(`div`,{className:P(gk,`relative border-b border-border last:border-b-0`),children:[(0,B.jsx)(`span`,{"aria-hidden":!0,className:`truncate px-2 pt-1 text-body sm:py-1.5`,children:qO(e,t,n,r)}),(0,B.jsx)(`div`,{className:`relative h-7`,children:s&&(0,B.jsx)(`div`,{className:`absolute top-1/2 -translate-y-1/2`,style:{left:_k(s.first,i.length),width:_k(s.last-s.first+1,i.length)},children:(0,B.jsx)(XO,{model:e,view:t,display:n,row:r,day:s.start,movable:a,dragged:o,className:P(s.before&&`rounded-l-none border-l-0`,s.after&&`rounded-r-none border-r-0`)})})})]})},xk=()=>[{scale:`week`,label:K(`week`)},{scale:`month`,label:K(`month`)},{scale:`quarter`,label:K(`quarter`)}],Sk=({model:e,view:t,display:n,fields:r,filter:i,at:a,linkTo:o,now:s=Date.now()})=>{let[c,l]=(0,I.useState)(),u=ok(o?a:c,s),d=ck(u),f=fk(u),p=ZO({model:e,display:n,range:lk(u),fields:r,filter:i}),{moves:m,move:h}=$O(e,n),g=hk(IO(QO(p.rows,m),n),e,t,n),_=dy(uf(e.name),`update`)&&[n.start,n.end].every(t=>t===void 0||!e.fields[t]?.readOnly),[v,y]=(0,I.useState)(),b=(0,I.useRef)(!1),x=(0,I.useRef)(0),S=(0,I.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=ne(Me(se,{activationConstraint:{distance:4}}),Me(xe,{activationConstraint:{delay:250,tolerance:5}}),Me(ae,{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=np(s,Xf()),O=r=>qO(e,t,n,r.row),k=e=>pp(Date.parse(`${xO(e.day,x.current)}T00:00:00Z`)),A={onDragStart:({active:e})=>K(`pickedUp`,{title:O(e.data.current)}),onDragMove:({active:e})=>K(`startsOn`,{title:O(e.data.current),day:k(e.data.current)}),onDragOver:()=>void 0,onDragEnd:({active:e})=>x.current===0?K(`putBack`,{title:O(e.data.current)}):K(`wasMovedTo`,{title:O(e.data.current),to:k(e.data.current)}),onDragCancel:({active:e})=>K(`cancelled`,{title:O(e.data.current)})},j=()=>{y(void 0),setTimeout(()=>b.current=!1)},ee=({active:e})=>{b.current=!0,x.current=0,y(e.data.current)},te=({delta:e})=>x.current=w(e.x),re=({active:t,delta:r})=>{j(),x.current=w(r.x);let{row:i}=t.data.current,a=PO(i.record,n,e);a&&x.current!==0&&h(i,a.first,xO(a.first,x.current))},ie=n.group===void 0?t?.names?.plural??F(e.name):t?.fields[n.group]?.label??F(n.group),oe=!p.loading&&!p.error&&p.rows.length===0;return(0,B.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-3`,children:[(0,B.jsx)(zO,{heading:dk(u),unit:u.scale,previous:sk(u,-1),today:ok({scale:u.scale,day:D},s),next:sk(u,1),scales:xk().map(({scale:e,label:t})=>({view:uk(u,e,s),label:t,current:u.scale===e})),scalesLabel:K(`timelineScale`),linkTo:o,onView:l}),p.error&&(0,B.jsx)(Gg,{title:K(`couldNotLoadRows`),error:p.error}),p.capped&&(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:K(`capped`,{limit:500,unit:u.scale})}),(0,B.jsxs)(me,{sensors:E,modifiers:[T],onDragStart:ee,onDragMove:te,onDragEnd:re,onDragCancel:j,accessibility:{announcements:A,screenReaderInstructions:{draggable:K(`timelineInstructions`)}},children:[(0,B.jsxs)(`div`,{className:`overflow-hidden rounded-lg border border-border`,children:[(0,B.jsx)(vk,{ticks:f,days:d,today:D,label:ie,trackRef:S}),(0,B.jsxs)(`div`,{className:`relative`,children:[(0,B.jsx)(yk,{ticks:f,days:d,today:D}),p.loading&&(0,B.jsxs)(`div`,{className:`relative flex flex-col gap-2 p-2`,children:[(0,B.jsx)(Ch,{className:`h-4`}),(0,B.jsx)(Ch,{className:`h-4`})]}),oe&&(0,B.jsx)(`p`,{className:`relative px-2 py-3 text-xs text-muted-foreground`,children:K(`nothingIn`,{unit:u.scale})}),!p.loading&&g.map(r=>(0,B.jsxs)(`section`,{"aria-label":r.label,className:`relative border-b border-border last:border-b-0`,children:[r.label!==void 0&&(0,B.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,B.jsx)(`span`,{className:`tabular-nums text-muted-foreground`,children:r.rows.length})]}),r.rows.map(r=>(0,B.jsx)(bk,{model:e,view:t,display:n,row:r,days:d,movable:_&&fy(r.record,`update`),dragged:()=>b.current},r.key))]},r.key))]})]}),(0,B.jsx)(Oe,{children:v&&(0,B.jsx)(YO,{model:e,view:t,display:n,row:v.row,day:v.day})})]})]})},Ck=({list:e,empty:t,loading:n,children:r})=>(0,B.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:e.loading?n:e.error?(0,B.jsx)(Gg,{title:K(`couldNotLoadRows`),error:e.error}):e.rows.length===0?(0,B.jsx)(`p`,{className:`py-8 text-center text-muted-foreground`,children:t}):r}),wk=({list:e})=>(0,B.jsxs)(`div`,{className:`flex items-center justify-between gap-3 py-3 text-xs text-muted-foreground`,children:[(0,B.jsxs)(`span`,{children:[e.rows.length.toLocaleString(Le()),` of `,e.total.toLocaleString(Le())]}),e.more&&(0,B.jsx)(G,{size:`sm`,onClick:e.loadMore,children:K(`showMore`)})]}),Tk=`grid grid-cols-[repeat(auto-fill,minmax(15rem,1fr))] gap-3`,Ek=`relative flex snap-x snap-mandatory gap-3 overflow-x-auto pb-1`,Dk=({model:e,view:t,display:n,list:r,row:i=!1,footer:a=!0})=>{let o=(t?.names?.plural??F(e.name)).toLowerCase();return(0,B.jsxs)(Ck,{list:r,empty:K(`noneMatch`,{plural:o}),loading:(0,B.jsx)(`div`,{className:Tk,children:Array.from({length:6},(e,t)=>(0,B.jsx)(Ch,{className:`h-24`},t))}),children:[(0,B.jsx)(`ul`,{className:i?Ek:Tk,"aria-label":t?.names?.plural??F(e.name),children:r.rows.map(r=>(0,B.jsx)(`li`,{className:P(i&&`w-64 shrink-0 snap-start`),children:(0,B.jsx)(nD,{model:e,view:t,display:n,row:r,swipe:!i})},r.key))}),a&&(0,B.jsx)(wk,{list:r})]})},Ok=(0,I.createContext)(void 0),kk=({value:e,children:t})=>(0,B.jsx)(Ok.Provider,{value:e,children:t}),Ak=()=>{let e=(0,I.useContext)(Ok);if(!e)throw Error(`useListDisplay is used inside a list display, which the list page draws`);return e},jk=()=>(0,I.useContext)(Ok),Mk=({display:e,list:t})=>{let{components:n}=p_(),r=n?.[e.component];return r?(0,B.jsx)(kk,{value:t,children:(0,B.jsx)(`div`,{className:`relative min-w-0 flex-1 overflow-x-auto`,children:(0,B.jsx)(pv,{name:e.component,children:(0,B.jsx)(r,{...vn(e.props??{})})})})}):(0,B.jsx)(dv,{children:K.rich(`noComponent`,{component:e.component})})},Nk=sn(),Pk={bounds:{south:-90,west:-180,north:90,east:180},zoom:0},Fk=22,Ik=e=>Math.floor(e*1e6)/1e6,Lk=e=>Math.ceil(e*1e6)/1e6,Rk=e=>((e+180)%360+360)%360-180,zk=(e,t)=>{let n=[Nk.gte(e.latitude,Ik(Math.max(t.south,-90))),Nk.lte(e.latitude,Lk(Math.min(t.north,90)))];if(t.east-t.west>=360)return Nk.and(...n);let r=Nk.gte(e.longitude,Ik(Rk(t.west))),i=Nk.lte(e.longitude,Lk(Rk(t.east)));return Rk(t.west)<=Rk(t.east)?Nk.and(...n,r,i):Nk.and(...n,Nk.or(r,i))},Bk=(e,t,n)=>{let r=Yt(zk(t,n));return e.trim()===``?r:`(${e}) AND ${r}`},Vk=e=>Math.min(Math.max(Math.floor(e),0),Fk),Hk=(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))}},Uk=e=>{if(typeof e==`number`)return e;if(typeof e==`string`&&e.trim()!==``)return Number(e)},Wk=(e,t)=>{let n=Uk(e[t.latitude]),r=Uk(e[t.longitude]);if(n!==void 0&&r!==void 0&&Math.abs(n)<=90&&Math.abs(r)<=180)return{latitude:n,longitude:r}},Gk=6371008.8,Kk=64,qk=(e,t)=>t.approximate===void 0?t.exact!==void 0&&e[t.exact]===!1:e[t.approximate]===!0,Jk=(e,t)=>{let n=t/Gk,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%Kk/Kk*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]})]}},Yk=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,Xk=(e,t)=>Array.isArray(e)&&e.length>=t&&e.every(Yk),Zk=e=>Array.isArray(e)&&e.length>0&&e.every(e=>Xk(e,4)),Qk=e=>Array.isArray(e)&&e.length>0&&e.every(e=>Xk(e,2)),$k=e=>{if(typeof e!=`string`)return e;try{return JSON.parse(e)}catch(e){if(e instanceof SyntaxError)return;throw e}},eA=e=>{let t=$k(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`&&Zk(i)||r===`MultiPolygon`&&Array.isArray(i)&&i.length>0&&i.every(Zk)||r===`LineString`&&Xk(i,2)||r===`MultiLineString`&&Qk(i))return{type:r,coordinates:i}},tA=(e,t,n)=>{if(!qk(e,t))return;let r=t.area===void 0?void 0:eA(e[t.area]);if(r)return r;let i=t.radius===void 0?void 0:Uk(e[t.radius]);return i!==void 0&&Number.isFinite(i)&&i>0?Jk(n,i):t.defaultRadius===void 0?void 0:Jk(n,t.defaultRadius)},nA=(e,t)=>e.flatMap(e=>{let n=Wk(e.record,t);if(!n)return[];if(!qk(e.record,t))return[{key:e.key,...n}];let r=tA(e.record,t,n);return[{key:e.key,...n,approximate:!0,...r&&{area:r}}]}),rA=(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}))},iA=(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)}},aA=(e,t)=>({keys:e.keys,index:((e.index+t)%e.keys.length+e.keys.length)%e.keys.length}),oA=({model:e,view:t,display:n,fields:r,filter:i,orderBy:a,area:o})=>{let s=U(),{resources:c,views:l}=W(),u={latitude:n.latitude,longitude:n.longitude},f=o?Bk(i,u,o.bounds):``,p=o?Vk(o.zoom):0;return E({queryKey:H.map(e.name,`${u.latitude},${u.longitude}`,p,f,a),enabled:o!==void 0,placeholderData:d,queryFn:async()=>{let n=await s.map(e.name,{...u,zoom:p,filter:f,orderBy:a,labels:Ob(c,l,e,r),photos:Vm(t)});return{rows:kb(c,e,r,Hm(e,n.items,n.photos),n.labels).map(t=>hh(e,t)),buckets:n.buckets,total:n.totalSize}}})},sA=(0,I.lazy)(()=>Ve(()=>import(`./records-map-B1PDo3PS.js`).then(e=>({default:e.RecordsMap})),__vite__mapDeps([4,1,2,5,6,7,3,8]))),cA=250,lA=`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`,uA=({model:e,view:t,display:n,filter:r,orderBy:i,fields:a,at:o,onMove:s,footer:c=!0,flush:l=!1})=>{let u=W().maps,d=u?.style,[f,p]=(0,I.useState)(),[m,h]=(0,I.useState)(),g=aT(m,cA),[_,v]=(0,I.useState)(o===void 0),y=oA({model:e,view:t,display:n,fields:a,filter:r,orderBy:i,area:_?Pk:g}),b=y.isPlaceholderData?void 0:y.data,x=y.data?.rows??[],S=y.data?.buckets??[],C=nA(x,n),w=_&&b?Hk(nA(b.rows,n),b.buckets):void 0,T=uh(t,n),E=(t?.names?.plural??F(e.name)).toLowerCase(),D=(t?.names?.singular??F(e.name)).toLowerCase(),O=iA(f,x),k=O&&x.find(e=>e.key===O.keys[O.index]),A=new Set(C.filter(e=>e.approximate).map(e=>e.key)),j=e=>{let t=e.filter(e=>A.has(e)).length;return e.length===1?K(t===1?`showOneApproximate`:`showOne`,{singular:D}):t===0?K(`showMany`,{count:e.length,plural:E}):t===e.length?K(`showManyApproximate`,{count:e.length,plural:E}):K(`showManySomeApproximate`,{count:e.length,plural:E,near:t})},ee=e=>K(`zoomIn`,{count:e.toLocaleString(Le()),noun:e===1?D:E}),te=(0,I.useRef)(null),[ne,re]=(0,I.useState)(0);if((0,I.useLayoutEffect)(()=>re(te.current?.offsetHeight??0),[k?.key]),!d)return(0,B.jsx)(dv,{children:K(`needsStyle`)});let ie=b?.total===0;return(0,B.jsxs)(`div`,{className:P(`flex h-full min-h-[36rem] flex-1 flex-col sm:min-h-[28rem]`,l&&`max-md:-mx-5 max-md:-mb-4 max-md:min-h-0`),children:[(0,B.jsxs)(`div`,{className:P(`relative min-h-0 flex-1 overflow-hidden rounded-lg border border-border bg-muted`,l&&`max-md:rounded-none max-md:border-0`),children:[(0,B.jsx)(I.Suspense,{fallback:null,children:(0,B.jsx)(sA,{style:d,layers:u?.layers,initial:o,points:C,buckets:S,fit:w,onFitted:()=>v(!1),onMove:(e,t)=>{h(e),s?.(t)},selected:O?.keys,covered:O?ne:0,onSelect:e=>p({keys:e,index:0}),onClear:()=>p(void 0),markerLabel:j,bucketLabel:ee})}),y.error&&(0,B.jsx)(`div`,{className:`absolute inset-x-3 top-3 z-10`,children:(0,B.jsx)(Gg,{title:K(`couldNotLoadRows`),error:y.error})}),ie&&(0,B.jsx)(`div`,{className:`pointer-events-none absolute inset-x-3 top-3 z-10 flex justify-center`,children:(0,B.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:[K(_?`noneMatch`:`noneHere`,{plural:E}),!_&&(0,B.jsx)(G,{size:`sm`,onClick:()=>v(!0),children:K(`showAll`)})]})}),O&&k&&(0,B.jsx)(`div`,{ref:te,className:`pointer-events-none absolute inset-x-3 bottom-3 z-10 flex justify-center`,children:(0,B.jsxs)(`div`,{className:`pointer-events-auto flex w-full max-w-[16rem] flex-col gap-2 sm:max-w-xs`,role:`group`,"aria-label":K(`chosen`,{singular:D}),children:[(0,B.jsxs)(`div`,{className:`flex items-center justify-end gap-1.5`,children:[A.has(k.key)&&(0,B.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,B.jsx)(Li,{className:`size-3.5`,"aria-hidden":!0}),K(`approximatePosition`)]}),O.keys.length>1&&(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`button`,{type:`button`,"aria-label":K(`previous`),className:lA,onClick:()=>p(aA(O,-1)),children:(0,B.jsx)(Di,{className:`size-4`,"aria-hidden":!0})}),(0,B.jsxs)(`span`,{className:`rounded-full border border-border bg-background px-2 py-1 text-xs tabular-nums`,"aria-live":`polite`,children:[O.index+1,` / `,O.keys.length]}),(0,B.jsx)(`button`,{type:`button`,"aria-label":K(`next`),className:lA,onClick:()=>p(aA(O,1)),children:(0,B.jsx)(ki,{className:`size-4`,"aria-hidden":!0})})]}),(0,B.jsx)(`button`,{type:`button`,"aria-label":K(`close`),className:lA,onClick:()=>p(void 0),children:(0,B.jsx)(bc,{className:`size-4`,"aria-hidden":!0})})]}),(0,B.jsx)(`div`,{className:`shadow-lg`,children:(0,B.jsx)(nD,{model:e,view:t,display:T,row:k})})]})})]}),c&&(0,B.jsx)(`p`,{className:`hidden py-3 text-xs text-muted-foreground md:block`,children:dA(y.data,E)})]})},dA=(e,t)=>{if(!e)return`\xA0`;let n=e.total.toLocaleString(Le());return e.buckets.length===0&&e.rows.length<e.total?`${e.rows.length.toLocaleString(Le())} of ${n} ${t} in view`:`${n} ${t} in view`},fA=({value:e,options:t,onChange:n,label:r})=>{let[i,a]=(0,I.useState)(!1),o=(0,I.useRef)(null),s=(0,I.useRef)(null),c=(0,I.useRef)([]),l=t.findIndex(t=>t.value===e),u=t[l];(0,I.useEffect)(()=>{if(!i)return;c.current[Math.max(l,0)]?.focus();let e=e=>{e.target instanceof Node&&!o.current?.contains(e.target)&&a(!1)};return document.addEventListener(`pointerdown`,e),()=>document.removeEventListener(`pointerdown`,e)},[i]);let d=()=>{a(!1),s.current?.focus()};return(0,B.jsxs)(`div`,{ref:o,className:`relative shrink-0`,children:[(0,B.jsxs)(`button`,{ref:s,type:`button`,"aria-label":u?`${r}: ${u.label}`:r,"aria-haspopup":`menu`,"aria-expanded":i,onClick:()=>a(!i),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:[u?.icon&&(0,B.jsx)(u.icon,{className:`size-3.5`}),u?.label??r,(0,B.jsx)(Ti,{className:`size-3.5 text-muted-foreground`})]}),i&&(0,B.jsx)(`ul`,{role:`menu`,"aria-label":r,onKeyDown:e=>{if(e.key===`Escape`)return d();if(e.key===`Tab`)return a(!1);let n=nT(e.key,c.current.indexOf(document.activeElement),t.length);n!==void 0&&(e.preventDefault(),c.current[n]?.focus())},className:`absolute right-0 top-full z-30 mt-1 min-w-40 rounded-md border bg-background py-1 text-body shadow-pop`,children:t.map((t,r)=>(0,B.jsx)(`li`,{role:`none`,children:(0,B.jsxs)(`button`,{ref:e=>{c.current[r]=e},type:`button`,role:`menuitemradio`,"aria-checked":t.value===e,onClick:()=>{d(),t.value!==e&&n(t.value)},className:P(`flex min-h-9 w-full items-center gap-2 whitespace-nowrap 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`),children:[t.icon?(0,B.jsx)(t.icon,{className:`size-3.5`}):(0,B.jsx)(`span`,{className:`size-3.5`}),(0,B.jsx)(`span`,{className:`flex-1`,children:t.label}),t.value===e&&(0,B.jsx)(Ci,{className:`size-3.5 text-primary-text`})]})},t.value))})]})},pA={table:Rs,cards:Ga,kanban:As,board:qi,list:$a,calendar:_i,timeline:xi,map:fo},mA=({view:e,value:t,onChange:n,menu:r=!1,choices:i=ih(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:pA[e.icon]}));return r?(0,B.jsx)(fA,{label:K(`display`),value:t,onChange:n,options:a}):(0,B.jsx)(Re,{label:K(`display`),size:`md`,value:t,onChange:n,options:a})},hA=[[`asc`,`ascending`],[`desc`,`descending`]],gA=({model:e,view:t,display:n,orderBy:r,onChange:i,className:a})=>{let o=_h(r),s=ph(e,t,n),c=s.includes(o.columnId)?s:[o.columnId,...s],l=e=>t?.fields[e]?.label??F(e);return(0,B.jsx)(`select`,{"aria-label":K(`sort`),value:`${o.columnId} ${o.direction}`,onChange:e=>i(e.target.value),className:P(`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=>hA.map(([t,n])=>(0,B.jsxs)(`option`,{value:`${e} ${t}`,children:[l(e),`, `,K(n)]},`${e} ${t}`)))})},_A=(e,t)=>e.type===`relation`&&typeof t==`object`&&t&&`id`in t?t.id:t,vA=(e,t,n,r)=>e.map(e=>{let i=t.fields[e.id],a=i&&av(r,i,n?.fields[e.id]);return a?{...e,render:t=>(0,B.jsx)(gv,{shown:a,part:`cell`,field:i,value:_A(i,t[e.id]),fallback:nC(e,e.value?e.value(t):t[e.id])})}:e}),yA=e=>String(typeof e==`object`&&e&&`id`in e?e.id:e),bA=({target:e,id:t})=>(0,B.jsx)(eC,{text:Lb(e,t)??t,className:`font-medium text-primary-text hover:underline`}),xA=(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?nC(e,null):(0,B.jsx)(bA,{target:a,id:yA(t[e.id])})}}),SA=e=>e.includes(`.`),CA=({model:e,row:t,column:n})=>{let r=Kb(Cy(e,hh(e,t).record),n);return r.state===`loading`?(0,B.jsx)(`span`,{className:`text-muted-foreground`,children:`…`}):r.state===`missing`?(0,B.jsx)(`span`,{className:`text-muted-foreground`,children:`—`}):(0,B.jsx)(Hb,{model:r.model,field:r.field,value:r.value})},wA=(e,t,{resources:n,views:r})=>{let i=Cu(n,e.name,t),a=i.ok?i.steps.at(-1):void 0,o=a?.field.name??t;return{id:t,header:r[a?.model.name??e.name]?.fields[o]?.label??F(o),kind:`text`,width:200,render:n=>(0,B.jsx)(CA,{model:e,row:n,column:t})}},TA=(e,t,n,r)=>{let i=new Map(xA(vA(Im(e,t,[],n.filter(e=>!SA(e))),e,t,r.fieldTypes),e,r.resources,r.views).map(e=>[e.id,e]));return n.flatMap(t=>SA(t)?[wA(e,t,r)]:i.get(t)??[])},EA=(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},DA=(e,t,n)=>{if(e.open!==void 0)return e.open!==e.field&&EA(t,e.open,n)?e.open:void 0;let r=t.primaryKey.filter(r=>r!==e.field&&r!==t.tenant&&EA(t,r,n));return r.length===1?r[0]:void 0},OA=(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},kA=(e,t)=>(t?.names?.singular??F(e.name)).toLowerCase(),AA=({model:e,view:t,opens:n,resources:r,views:i,canUpdate:a})=>{let o=t=>({kind:`record`,resource:e.name,key:wm(e,t)}),s=n&&e.fields[n]?.relation?.resource,c=s?r[s]:void 0,l=e=>{let t=n&&c?OA(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=kA(e,t);return{address:u,actions:t=>{let n={label:LS(`open`,{singular:d}),link:e=>t(o(e))};if(!c)return[n];let r=e=>a&&fy(e,`update`);return[{label:LS(`open`,{singular:kA(c,i[c.name])}),available:e=>l(e)!==void 0,link:e=>t(l(e))},{label:LS(`edit`,{singular:d}),available:r,link:n=>t({kind:`record`,resource:e.name,key:wm(e,n),edit:!0})},{...n,available:e=>!r(e)}]}}},jA=({model:e,filter:t,orderBy:n,limit:r,fields:i})=>{let a=U(),o=Se(),{resources:s,views:c}=W();return E({queryKey:[...H.list(e.name,t,n,r,`embedded`),i.join(`,`)],placeholderData:d,queryFn:async()=>{let l=Ob(s,c,e,i),u=Vm(c[e.name]),d=await a.search(e.name,{filter:t||void 0,orderBy:n||void 0,pageSize:r,count:`exact`,labels:l,photos:u});await Pb(o,a,s,c,e,i,d.items);let f=kb(s,e,i,Hm(e,d.items,d.photos),d.labels).map((t,n)=>({...t,id:Cm(e,d.items[n])}));return d.nextPageToken===``?{rows:f,total:f.length,estimated:!1}:{rows:f,total:d.totalSize??d.totalSizeEstimate,estimated:d.totalSize===void 0}}})},MA=({view:e,value:t,onChange:n})=>(0,B.jsx)(mA,{view:e,value:t,onChange:n,menu:!xf()}),NA=()=>(0,B.jsx)(`div`,{className:`flex flex-col gap-2`,children:Array.from({length:3},(e,t)=>(0,B.jsx)(Ch,{className:`h-4 w-full`},t))}),PA=({model:e,view:t,filter:n,sort:r,columns:i,limit:a,display:o,empty:s,row:c=!1,viewAll:l,link:u=!0,opens:d})=>{let{resources:f,views:p}=W(),m=dy(uf(e.name),`update`),{fields:h}=p_(),{go:g,href:_}=qh(),v=Sf(),[y,b]=(0,I.useState)(r||gh(e,t)),x=i??Er(e,t),S=(0,I.useMemo)(()=>TA(e,t,x,{resources:f,views:p,fieldTypes:h}),[e,t,x.join(`,`),f,p,h]),C=(0,I.useMemo)(()=>fh(e,t,S.map(e=>e.id)),[e,t,S]),w=jA({model:e,filter:n,orderBy:y,limit:a,fields:C}),T=w.data?.rows,E=(0,I.useMemo)(()=>T&&{total:T.length,rowAt:e=>T[e]},[T]),D=nh(t,o),O=t?.names?.plural??F(e.name),k=u&&(0,B.jsxs)(Jh,{to:WS(e,t,v,l?{filter:l.filter,orderBy:gh(e,t),display:o,savedSearch:l.savedSearch}:{filter:n,orderBy:y,display:o}),onClick:l?.onOpen,className:`flex items-center gap-1 self-end font-medium text-primary-text hover:underline`,children:[l?l.label:(0,B.jsxs)(B.Fragment,{children:[LS(`viewAll`),` `,(0,B.jsx)(`span`,{className:`sr-only`,children:O.toLowerCase()})]}),(0,B.jsx)(zr,{className:`size-3.5`,"aria-hidden":!0})]});if(w.isPending)return(0,B.jsx)(NA,{});if(w.error)return(0,B.jsx)(Gg,{title:LS(`couldNotLoad`),error:w.error});if(!E||E.total===0){let e=(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:s??LS(`nothingYet`)});return l&&u?(0,B.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[e,k]}):e}let A={resource:e.name,rows:w.data.rows.map(t=>hh(e,t)),total:w.data.total,loading:!1,error:null,more:!1,loadMore:()=>void 0},j=AA({model:e,view:t,opens:d,resources:f,views:p,canUpdate:m}),ee=e=>({href:_(e),onFollow:()=>g(e)}),te=RS(E.total,w.data.total,w.data.estimated);return(0,B.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[D?D.kind===`cards`?(0,B.jsx)(Dk,{model:e,view:t,display:D,list:A,row:c||v,footer:!1}):D.kind===`map`?(0,B.jsx)(uA,{model:e,view:t,display:D,filter:n,orderBy:y,fields:C,footer:!1}):D.kind===`board`?(0,B.jsx)(_O,{model:e,view:t,display:D,fields:C,filter:n,orderBy:y,limit:a}):D.kind===`calendar`?(0,B.jsx)(tk,{model:e,view:t,display:D,fields:C,filter:n}):D.kind===`timeline`?(0,B.jsx)(Sk,{model:e,view:t,display:D,fields:C,filter:n}):(0,B.jsx)(Mk,{display:D,list:A}):(0,B.jsx)(yw,{fit:!0,columns:S,source:E,latencyMs:0,sort:_h(y),onSortChange:e=>b(vh(e)),onOpenRow:e=>g(j.address(e)),rowLink:e=>ee(j.address(e)),rowActions:j.actions(ee),rowNumbers:!1,selectable:!1}),te&&u?(0,B.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:te}),k]}):k]})},FA=(e,t,n)=>{let r=Sf(),i=BS(t),[a,o]=(0,I.useState)(()=>VS(localStorage,i)),s=(0,I.useCallback)(e=>{o(e),HS(localStorage,i,e)},[i]);return[US(e,r,{picked:a,preferred:n}),s]},IA=({model:e,view:t,filter:n=``,sort:r=``,columns:i,limit:a=10,display:o,title:s,description:c,empty:l,actions:u})=>{let[d,f]=FA(t,`page:${e.name}:${s??``}:${n}`,o);return(0,B.jsx)(Fy,{title:s,description:c,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(MA,{view:t,value:d,onChange:f}),u]}),className:`h-full`,children:(0,B.jsx)(PA,{model:e,view:t,filter:n,sort:r,columns:i,limit:a,display:d,empty:l})})},LA=({node:e,slots:t})=>{let n=My(e),{resources:r,views:i}=W(),a=r[n.resource];return a?(0,B.jsx)(IA,{...n,model:a,view:i[a.name],actions:t.actions}):null},RA=({node:e,children:t})=>{let{tab:n,pathOf:r}=pf(),{navigate:i}=Ih(),a=mf(e),o=gf(a,n),s=e=>r(e===a[0]?.name?void 0:e);return(0,B.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,B.jsxs)(`select`,{"aria-label":fv(`tabs`),value:o?.name??``,onChange:e=>i(s(e.target.value)),className:`h-9 rounded-md border border-border-strong bg-background px-2 font-medium md:hidden`,children:[!o&&(0,B.jsx)(`option`,{value:``,disabled:!0}),a.map(e=>(0,B.jsx)(`option`,{value:e.name,children:e.label},e.name))]}),(0,B.jsx)(`nav`,{"aria-label":fv(`tabs`),className:`hidden border-b md:block`,children:(0,B.jsx)(`ul`,{className:`flex gap-1`,children:a.map(e=>(0,B.jsx)(`li`,{children:(0,B.jsx)(Gh,{to:s(e.name),"aria-current":e===o?`page`:void 0,className:P(`-mb-px inline-flex h-9 items-center whitespace-nowrap border-b-2 px-3 font-medium transition-colors`,e===o?`border-foreground text-foreground`:`border-transparent text-muted-foreground hover:text-foreground`),children:e.label})},e.name))})}),o?(0,B.jsx)(I.Fragment,{children:t[a.indexOf(o)]},o.name):(0,B.jsx)(dv,{children:fv(`noTab`,{name:n??``})})]})},zA=({children:e})=>(0,B.jsx)(`div`,{className:`flex flex-col gap-6`,children:e}),BA=({title:e,status:t,description:n,children:r})=>(0,B.jsxs)(`section`,{"aria-label":e,className:`rounded-lg border bg-background p-4 sm:p-5`,children:[(0,B.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,B.jsx)(`h2`,{className:`text-[16px] font-semibold`,children:e}),t]}),(0,B.jsx)(`p`,{className:`mt-1 text-muted-foreground`,children:n}),r&&(0,B.jsx)(`div`,{className:`mt-4`,children:r})]}),VA=({message:e})=>e?(0,B.jsx)(`p`,{role:`alert`,className:`mb-3 text-body font-medium text-danger-text`,children:e}):null,HA=M(`auth/errors`),UA={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`,SESSION_NOT_FRESH:`notFresh`,SESSION_EXPIRED:`notFresh`,PASSWORD_COMPROMISED:`passwordLeaked`},WA=(e,t)=>{let n=t?e[t]:void 0;return n&&HA(n)},GA=e=>WA(UA,e.code),KA=e=>GA(e)??(e.status===429?HA(`tooManyRequests`):e.message),qA=e=>GA(e)??(e.status===429?HA(`tooManyRequests`):e.status===401?HA(`wrongEmailOrPassword`):e.message),JA={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`},YA=e=>WA(JA,typeof e==`string`?e:e.code)||(typeof e==`string`?HA(`staffFailed`):e.status===429?HA(`tooManyRequests`):e.message),XA={signup_disabled:e=>HA(`signupDisabled`,{name:e}),account_not_linked:e=>HA(`notLinked`,{name:e}),account_already_linked_to_different_user:e=>HA(`linkedToOther`,{name:e}),unable_to_link_account:e=>HA(`couldNotLink`,{name:e}),access_denied:e=>HA(`accessDenied`,{name:e}),EMAIL_DOMAIN_NOT_ALLOWED:e=>HA(`domainNotAllowed`,{name:e})},ZA=(e,t)=>XA[e]?.(t)??HA(`providerFailed`,{name:t}),QA=()=>{let[e,t]=(0,I.useState)(!1),[n,r]=(0,I.useState)();return{busy:e,error:n,run:async e=>{t(!0),r(void 0);try{await e()}catch(e){if(!(e instanceof ku))throw e;r(KA(e))}t(!1)},setError:r}},$A=M(`invitations`),ej=({link:e})=>e?(0,B.jsx)(`p`,{className:`mt-3 break-all rounded-md border bg-muted px-3 py-2 text-xs`,children:$A.rich(`passLinkOn`,{link:(0,B.jsx)(`span`,{className:`font-mono`,children:e})})}):null,tj=({title:e,description:t,onInvite:n,beside:r,children:i,incomplete:a=!1})=>{let[o,s]=(0,I.useState)(``),[c,l]=(0,I.useState)(),{busy:u,error:d,run:f}=QA(),p=()=>f(async()=>{l((await n(o.trim())).link),s(``)});return(0,B.jsxs)(BA,{title:e,description:t,children:[(0,B.jsx)(VA,{message:d}),(0,B.jsxs)(`form`,{className:`flex flex-col gap-3`,onSubmit:e=>{e.preventDefault(),p()},children:[(0,B.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,B.jsx)(J,{"aria-label":$A(`email`),type:`email`,placeholder:`name@example.com`,value:o,onChange:e=>s(e.target.value),wrapperClassName:`flex-1`}),r,(0,B.jsx)(G,{type:`submit`,variant:`primary`,loading:u,disabled:!o.trim()||a,children:$A(`invite`)})]}),i]}),(0,B.jsx)(ej,{link:c})]})},nj=({email:e,gives:t,expiresAt:n,onResend:r,onRevoke:i})=>{let[a,o]=(0,I.useState)(),{busy:s,error:c,run:l}=QA(),u=new Date(n).getTime()<Date.now();return(0,B.jsxs)(`li`,{className:`px-3 py-2.5`,children:[(0,B.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,B.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,B.jsx)(`span`,{className:`block truncate font-medium`,children:e}),(0,B.jsxs)(`span`,{className:`block text-xs text-muted-foreground`,children:[t,` · `,u?$A(`expired`):$A(`until`,{date:new Date(n).toLocaleDateString(Le())})]})]}),(0,B.jsx)(G,{size:`sm`,loading:s,onClick:()=>void l(async()=>o((await r()).link)),children:$A(`sendAgain`)}),(0,B.jsx)(G,{size:`sm`,variant:`danger`,loading:s,onClick:()=>void l(i),children:$A(`revoke`)})]}),(0,B.jsx)(VA,{message:c}),(0,B.jsx)(ej,{link:a})]})},X=M(`organizations`),rj=({roles:e,selected:t,grantable:n,disabled:r,onChange:i})=>(0,B.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,B.jsxs)(`label`,{title:o&&!r?X(`cannotChangeRole`):void 0,className:P(`inline-flex items-center gap-1.5`,o&&`text-muted-foreground`),children:[(0,B.jsx)(AC,{checked:a,label:e.label,onChange:o?void 0:n=>i(n?[...t,e.name]:t.filter(t=>t!==e.name)),className:P(o&&`cursor-default opacity-60`)}),e.label]},e.name)})}),ij=`/-/organizations`,aj=`/-/organization`,oj=`/-/organization/members`,sj=`/-/organization/invitations`,cj={[ij]:`organizations`,[aj]:`organization`,[oj]:`members`,[sj]:`invitations`},lj=e=>{let t=cj[e];return t&&X(t)},uj=e=>X(e),dj=(e,t)=>e.find(e=>e.name===t)?.label??t,fj=e=>e?.role===`owner`||e?.role===`admin`,pj=(e,t,n)=>{let r=(n,r,i,a)=>({id:n,label:r,icon:i,href:`${e}${a}`,active:t===a});return[r(`organizations`,X(`manageOrganizations`),Mo,ij),...n?.organization?[r(`organization`,X(`organization`),hi,aj)]:[],...fj(n)?[r(`members`,X(`members`),oc,oj),r(`invitations`,X(`invitations`),lo,sj)]:[]]},mj=(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)))},hj=(e,t)=>t.map(t=>dj(e,t)).join(`, `),gj=M(`users`),_j=({roles:e})=>{let{session:t}=V(),[n,r]=(0,I.useState)([]),[i,a]=(0,I.useState)([]),o=(0,I.useCallback)(()=>void t.users.invitations().then(a,()=>a([])),[t]);return(0,I.useEffect)(o,[o]),(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(tj,{title:gj(`inviteSomeone`),description:gj(`inviteDescription`),onInvite:async e=>{let i=await t.users.invite({email:e,roles:n});return r([]),o(),i},incomplete:n.length===0,children:(0,B.jsx)(rj,{roles:e,selected:n,grantable:new Set(e.map(e=>e.name)),onChange:r})}),(0,B.jsx)(BA,{title:gj(`notAcceptedYet`),description:i.length>0?gj(`sendingAgain`):gj(`nobodyWaiting`),children:i.length>0&&(0,B.jsx)(`ul`,{className:`divide-y rounded-md border`,children:i.map(n=>(0,B.jsx)(nj,{email:n.email,gives:hj(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))})})]})},vj=({title:e,description:t,size:n=`sm`,icon:r,children:i})=>(0,B.jsx)(`div`,{className:`flex min-h-full w-full items-center justify-center bg-surface 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,B.jsxs)(`div`,{className:P(`w-full`,n===`sm`?`max-w-sm`:`max-w-lg`),children:[(0,B.jsxs)(`div`,{className:`mb-6 flex flex-col items-center text-center short:mb-4`,children:[r?(0,B.jsx)(`img`,{src:r,alt:``,className:`size-10 object-contain short:hidden`}):(0,B.jsx)(Ax,{className:`size-10 short:hidden`}),(0,B.jsx)(`h1`,{className:`mt-4 text-xl font-semibold tracking-tight short:mt-0`,children:e}),t&&(0,B.jsx)(`p`,{className:`mt-1 text-muted-foreground`,children:t})]}),(0,B.jsx)(`div`,{className:`rounded-lg border bg-background p-5 shadow-sm`,children:i})]})}),yj=({onSubmit:e,invalidLink:t,onRequestNewLink:n,onBack:r,busy:i,error:a})=>{let[o,s]=(0,I.useState)(``),[c,l]=(0,I.useState)(``),[u,d]=(0,I.useState)(!1);if(t)return(0,B.jsxs)(vj,{title:z(`linkExpiredTitle`),children:[(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:z(`linkExpiredExplanation`)}),(0,B.jsxs)(`div`,{className:`mt-4 flex flex-col gap-2`,children:[n&&(0,B.jsx)(G,{variant:`primary`,className:`min-h-10`,onClick:n,children:z(`sendNewLink`)}),(0,B.jsx)(G,{variant:n?`ghost`:`primary`,className:`min-h-10`,onClick:r,children:z(`backToSignIn`)})]})]});let f=u?z(`passwordsDiffer`):a;return(0,B.jsx)(vj,{title:z(`choosePassword`),description:z(`atLeast`,{length:12}),children:(0,B.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:t=>{t.preventDefault(),d(o!==c),o===c&&e(o)},children:[(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[z(`newPassword`),(0,B.jsx)(J,{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,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[z(`repeatPassword`),(0,B.jsx)(J,{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,B.jsx)(`p`,{role:`alert`,className:`text-body font-medium text-danger-text`,children:f}),(0,B.jsx)(G,{variant:`primary`,type:`submit`,loading:i,className:`min-h-10`,children:z(`setPassword`)})]})})},bj=({roles:e,onCreated:t})=>{let{session:n}=V(),[r,i]=(0,I.useState)(``),[a,o]=(0,I.useState)(``),[s,c]=(0,I.useState)(``),[l,u]=(0,I.useState)([]),{busy:d,error:f,run:p}=QA(),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,B.jsxs)(BA,{title:gj(`addAnAccount`),description:gj(`addDescription`),children:[(0,B.jsx)(VA,{message:f}),(0,B.jsxs)(`form`,{className:`flex flex-col gap-3`,onSubmit:e=>{e.preventDefault(),m()},children:[(0,B.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,B.jsx)(J,{"aria-label":gj(`email`),type:`email`,placeholder:`name@example.com`,value:r,onChange:e=>i(e.target.value),wrapperClassName:`flex-1`}),(0,B.jsx)(J,{"aria-label":gj(`name`),placeholder:gj(`name`),autoComplete:`off`,value:a,onChange:e=>o(e.target.value),wrapperClassName:`flex-1`})]}),(0,B.jsx)(J,{"aria-label":gj(`password`),type:`password`,autoComplete:`new-password`,placeholder:gj(`passwordOptional`,{length:12}),value:s,onChange:e=>c(e.target.value)}),(0,B.jsx)(rj,{roles:e,selected:l,grantable:new Set(e.map(e=>e.name)),onChange:u}),(0,B.jsx)(`div`,{children:(0,B.jsx)(G,{type:`submit`,variant:`primary`,loading:d,disabled:h,children:gj(`addAccount`)})})]})]})},xj=M(`lists`),Sj=({title:e,description:t,searchLabel:n,placeholder:r,query:i,onQuery:a,list:o,error:s,renderRow:c})=>(0,B.jsxs)(BA,{title:e,description:t,children:[(0,B.jsx)(VA,{message:s}),(0,B.jsx)(J,{"aria-label":n,placeholder:r,value:i,onChange:e=>a(e.target.value),leading:(0,B.jsx)(cs,{className:`size-3.5`}),wrapperClassName:`mb-2`}),(0,B.jsxs)(`p`,{className:`mb-3 text-xs text-muted-foreground`,children:[o.found.length,` of `,o.total]}),o.found.length>0&&(0,B.jsx)(`ul`,{className:`divide-y rounded-md border`,children:o.found.map(c)}),o.found.length<o.total&&(0,B.jsx)(G,{className:`mt-3`,loading:o.loading,onClick:()=>void o.more(),children:xj(`showMore`)})]}),Cj=(e,t)=>{let[n,r]=(0,I.useState)([]),[i,a]=(0,I.useState)(0),[o,s]=(0,I.useState)(!1),c=(0,I.useRef)(t);return c.current=t,(0,I.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}},wj=({name:e,email:t,self:n,actions:r,children:i,error:a,status:o})=>(0,B.jsxs)(`li`,{className:`flex flex-col gap-2 px-3 py-3`,children:[(0,B.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,B.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[o?(0,B.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,B.jsxs)(`span`,{className:`truncate font-medium`,children:[e,n&&` (you)`]}),o]}):(0,B.jsxs)(`span`,{className:`block truncate font-medium`,children:[e,n&&` (you)`]}),(0,B.jsx)(`span`,{className:`block truncate text-xs text-muted-foreground`,children:t})]}),r]}),i,(0,B.jsx)(VA,{message:a})]}),Tj=({user:e,roles:t,self:n})=>{let{session:r}=V(),[i,a]=(0,I.useState)(e),{busy:o,error:s,run:c,setError:l}=QA(),u=e=>{if(e.length===0)return l(gj(`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,B.jsx)(wj,{name:i.name,email:i.email,self:n,error:s,actions:(0,B.jsxs)(B.Fragment,{children:[i.blocked&&(0,B.jsx)(zf,{tone:`red`,children:gj(`blocked`)}),!n&&(i.blocked?(0,B.jsx)(G,{size:`sm`,loading:o,onClick:()=>d(!1),children:gj(`unblock`)}):(0,B.jsx)(G,{size:`sm`,variant:`danger`,loading:o,onClick:()=>d(!0),children:gj(`block`)}))]}),children:(0,B.jsx)(rj,{roles:t,selected:i.roles,grantable:new Set(t.map(e=>e.name)),disabled:o,onChange:u})})},Ej=({roles:e,version:t})=>{let{session:n,state:r}=V(),[i,a]=(0,I.useState)(``),o=Cj((0,I.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,B.jsx)(Sj,{title:gj(`people`),description:gj(`peopleDescription`),searchLabel:gj(`findSomeone`),placeholder:gj(`emailAddress`),query:i,onQuery:a,list:o,renderRow:n=>(0,B.jsx)(Tj,{user:n,roles:e,self:n.id===s},`${t}/${n.id}`)})},Dj=()=>{let{session:e}=V(),[t,n]=(0,I.useState)([]),[r,i]=(0,I.useState)();return(0,I.useEffect)(()=>{e.users.roles().then(n,e=>i(e instanceof ku?KA(e):gj(`couldNotReadRoles`)))},[e]),{roles:t,error:r}},Oj=()=>{let{roles:e,error:t}=Dj(),[n,r]=(0,I.useState)(0);return(0,B.jsxs)(`div`,{className:`flex max-w-3xl flex-col gap-4`,children:[(0,B.jsx)(VA,{message:t}),(0,B.jsx)(Ej,{roles:e,version:n}),(0,B.jsx)(_j,{roles:e}),(0,B.jsx)(bj,{roles:e,onCreated:()=>r(e=>e+1)})]})},kj=({providers:e,linked:t,onConnect:n,error:r,reconnect:i=!1,title:a=L(`connectedAccounts`),description:o=L(`connectedAccountsDescription`)})=>{let[s,c]=(0,I.useState)(),[l,u]=(0,I.useState)(r),d=async e=>{c(e),u(void 0);try{await n(e)}catch(e){if(!(e instanceof ku))throw e;u(KA(e)),c(void 0)}};return(0,B.jsxs)(BA,{title:a,description:o,children:[(0,B.jsx)(VA,{message:l}),(0,B.jsx)(`ul`,{className:`divide-y rounded-md border`,children:e.map(e=>(0,B.jsxs)(`li`,{className:`flex flex-wrap items-center gap-3 px-3 py-2.5`,children:[(0,B.jsx)(Za,{className:`size-4 shrink-0 text-muted-foreground`}),(0,B.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-medium`,children:e.name}),t.includes(e.id)&&(0,B.jsx)(zf,{tone:`green`,children:L(`connected`)}),(!t.includes(e.id)||i)&&(0,B.jsx)(G,{size:`sm`,loading:s===e.id,disabled:s!==void 0,onClick:()=>void d(e.id),children:L(t.includes(e.id)?`connectAgain`:`connect`,{name:e.name})})]},e.id))})]})},Aj=({error:e})=>e?(0,B.jsx)(`p`,{role:`alert`,className:`text-danger-text`,children:e}):(0,B.jsxs)(`div`,{className:`flex items-center gap-2 text-muted-foreground`,children:[(0,B.jsx)(af,{}),` `,L(`loading`)]}),jj=(e,t)=>{let[n,r]=(0,I.useState)(),[i,a]=(0,I.useState)(),o=(0,I.useCallback)(()=>{e().then(e=>r({value:e}),e=>a(e instanceof ku?KA(e):t))},[e,t]);return(0,I.useEffect)(o,[o]),{data:n?.value,loaded:n!==void 0,error:i,reload:o}},Mj=()=>{let e=Od(window.location.href);return e&&window.history.replaceState(window.history.state,``,kd(window.location.href)),e},Nj=({providers:e})=>{let{session:t,linkProvider:n}=V(),{account:r}=t,[i]=(0,I.useState)(Mj),{data:a,error:o}=jj((0,I.useCallback)(()=>r.linkedProviders(),[r]),L(`couldNotReadMethods`));return a?(0,B.jsx)(kj,{providers:e,linked:a,onConnect:n,error:i&&ZA(i,e.length===1?e[0].name:L(`theProvider`))}):(0,B.jsx)(Aj,{error:o})},Pj=({signInProviders:e,socialProviders:t})=>e.filter(e=>t.includes(e.id)),Fj=()=>{let e=Pj(V());return e.length>0?(0,B.jsx)(Nj,{providers:e}):null},Ij=({links:e})=>{let{session:t,linkPersonalMail:n}=V(),{account:r}=t,[i]=(0,I.useState)(Mj),{data:a,error:o}=jj((0,I.useCallback)(()=>r.linkedPersonalMail(e),[r,e]),L(`couldNotReadMethods`));return a?(0,B.jsx)(kj,{title:L(`mailbox`),description:L(`mailboxDescription`),providers:e.map(({id:e,name:t})=>({id:e,name:t})),linked:a,reconnect:!0,onConnect:t=>n(e.find(e=>e.id===t)),error:i&&ZA(i,e.length===1?e[0].name:L(`theProvider`))}):(0,B.jsx)(Aj,{error:o})},Lj=()=>{let{personalMail:e}=V();return e.length>0?(0,B.jsx)(Ij,{links:e}):null},Rj=/[\u0000-\u001f\u007f-\u009f\u00ad\u061c\u115f\u1160\u180e\u200b-\u200f\u2028-\u202e\u2060-\u206f\u3164\ufe00-\ufe0f\ufeff]/g,zj=e=>{let t=(e??``).replace(Rj,` `).replace(/\s+/g,` `).trim();if(t)return t.length>60?`${t.slice(0,59)}…`:t},Bj=e=>{if(!URL.canParse(e))return;let t=new URL(e);return t.protocol===`https:`?t.host:void 0},Vj=e=>zj(e.name)??`An unnamed app`,Hj=e=>e.access.map(({role:e,organization:t})=>`as ${e||`no role`}${t?` in ${t}`:``}`).join(`, `),Uj=({apps:e,onDisconnect:t})=>{let[n,r]=(0,I.useState)(!1),[i,a]=(0,I.useState)(),[o,s]=(0,I.useState)(),c=async e=>{r(!0),a(void 0);try{await t(e.clientId),s(void 0)}catch(e){if(!(e instanceof ku))throw e;a(KA(e))}r(!1)};return(0,B.jsxs)(BA,{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,B.jsx)(VA,{message:o?void 0:i}),e.length===0?(0,B.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,B.jsx)(`ul`,{className:`divide-y rounded-md border`,children:e.map(e=>{let t=Bj(e.clientId);return(0,B.jsxs)(`li`,{className:`flex flex-wrap items-center gap-3 px-3 py-2.5`,children:[(0,B.jsx)(pi,{className:`size-4 shrink-0 text-muted-foreground`}),(0,B.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,B.jsx)(`bdi`,{className:`block truncate font-medium`,children:Vj(e)}),(0,B.jsxs)(`span`,{className:`block text-xs text-muted-foreground`,children:[t&&`Published by ${t} · `,`Allowed `,pp(Date.parse(e.allowedAt)),` · `,Hj(e)]})]}),(0,B.jsx)(G,{size:`sm`,variant:`ghost`,onClick:()=>s(e),children:`Disconnect`})]},e.clientId)})}),o&&(0,B.jsx)(Of,{title:`Disconnect ${Vj(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,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:()=>s(void 0),children:`Cancel`}),(0,B.jsx)(G,{variant:`danger`,loading:n,onClick:()=>void c(o),children:`Disconnect`})]}),children:i&&(0,B.jsx)(VA,{message:i})})]})},Wj=(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},Gj=({url:e,appName:t})=>{let[n,r]=(0,I.useState)(!1);return(0,B.jsx)(BA,{title:L(`mcpAddress`),description:L(`mcpAddressDescription`),children:(0,B.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,B.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-2 rounded-md border bg-surface py-1.5 pl-3 pr-1.5`,children:[(0,B.jsx)(`code`,{className:`min-w-0 flex-1 break-all font-mono text-xs`,children:e}),(0,B.jsx)(`button`,{type:`button`,"aria-label":L(n?`copied`:`copyMcpAddress`),onClick:()=>{navigator.clipboard.writeText(e).then(()=>{r(!0),setTimeout(()=>r(!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:n?(0,B.jsx)(Ci,{className:`size-4 text-success`}):(0,B.jsx)(Yi,{className:`size-4`})})]}),(0,B.jsxs)(`a`,{href:Wj(e,t),target:`_blank`,rel:`noreferrer`,className:yf(),children:[(0,B.jsx)(da,{className:`size-3.5`}),L(`addToClaude`)]})]})})},Kj=()=>{let{account:e}=V().session,{data:t,error:n,reload:r}=jj((0,I.useCallback)(()=>e.connectedApps(),[e]),L(`couldNotReadMethods`));return t?(0,B.jsx)(Uj,{apps:t,onDisconnect:t=>e.disconnectApp(t).then(r)}):(0,B.jsx)(Aj,{error:n})},qj=({url:e})=>(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(Gj,{url:e,appName:W().appName}),(0,B.jsx)(Kj,{})]}),Jj=()=>{let{mcp:e}=V();return e?(0,B.jsx)(qj,{url:e.url}):null},Yj=e=>e.code===`LAST_ADMIN`?L(`deleteAccountLastAdmin`):e.code===`ACCOUNT_LOCKED`?L(`deleteAccountLocked`):KA(e),Xj=({hasPassword:e,onDelete:t,onClose:n})=>{let[r,i]=(0,I.useState)(``),[a,o]=(0,I.useState)(!1),[s,c]=(0,I.useState)(),l=(0,I.useId)(),u=async()=>{o(!0),c(void 0);try{await t(e?r:void 0)}catch(e){if(!(e instanceof ku))throw e;c(Yj(e)),o(!1)}};return(0,B.jsx)(Of,{title:L(`deleteAccountQuestion`),description:L(`deleteAccountWarning`),onClose:n,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:n,children:L(`cancel`)}),(0,B.jsx)(G,{variant:`danger`,type:`submit`,form:l,loading:a,disabled:e&&!r,children:L(`deleteAccountConfirm`)})]}),children:(0,B.jsxs)(`form`,{id:l,className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),u()},children:[e&&(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[L(`deleteAccountPassword`),(0,B.jsx)(J,{type:`password`,name:`current-password`,autoComplete:`current-password`,autoFocus:!0,value:r,invalid:!!s,onChange:e=>i(e.target.value)})]}),(0,B.jsx)(VA,{message:s})]})})},Zj=({hasPassword:e,staff:t,onDelete:n})=>{let[r,i]=(0,I.useState)(!1);return(0,B.jsxs)(BA,{title:L(`deleteAccount`),description:L(t?`deleteAccountStaff`:`deleteAccountDescription`),children:[!t&&(0,B.jsx)(G,{variant:`danger`,onClick:()=>i(!0),children:L(`deleteAccount`)}),r&&(0,B.jsx)(Xj,{hasPassword:e,onDelete:n,onClose:()=>i(!1)})]})},Qj=()=>{let{session:e,state:t,deleteAccount:n}=V(),{account:r}=e,{data:i,error:a}=jj((0,I.useCallback)(()=>r.signInMethods(),[r]),L(`couldNotReadMethods`));return i?(0,B.jsx)(Zj,{hasPassword:i.account.password,staff:t.kind===`signed-in`&&!!t.staff,onDelete:n}):(0,B.jsx)(Aj,{error:a})},$j=[[/Edg(e|A|iOS)?\//,`Edge`],[/OPR\/|Opera/,`Opera`],[/SamsungBrowser\//,`Samsung Internet`],[/Firefox\/|FxiOS\//,`Firefox`],[/Chrome\/|CriOS\//,`Chrome`],[/Safari\//,`Safari`]],eM=[[/iPhone/,`iPhone`],[/iPad/,`iPad`],[/Android/,`Android`],[/CrOS/,`ChromeOS`],[/Windows/,`Windows`],[/Mac OS X|Macintosh/,`macOS`],[/Linux/,`Linux`]],tM=(e,t)=>e.find(([e])=>e.test(t))?.[1],nM=e=>e?{browser:tM($j,e),system:tM(eM,e)}:{},rM=(e,t)=>{if(e.staff)return t?L(`staffOf`,{operator:t}):L(`staff`);let{browser:n,system:r}=nM(e.userAgent);return n&&r?L(`browserOn`,{browser:n,system:r}):r?L(`aBrowserOn`,{system:r}):n??L(`unknownDevice`)},iM=e=>{if(e.staff)return bs;let{system:t}=nM(e.userAgent);return t===`iPhone`||t===`Android`?Es:t===`iPad`?Bs:Va},aM=e=>[...e].sort((e,t)=>Number(t.current)-Number(e.current)||t.createdAt.localeCompare(e.createdAt)),oM=({sessions:e,operator:t,onSignOut:n,onSignOutOthers:r})=>{let[i,a]=(0,I.useState)(!1),[o,s]=(0,I.useState)(),[c,l]=(0,I.useState)(),u=e.filter(e=>!e.current),d=async e=>{a(!0),s(void 0);try{await(e.kind===`one`?n(e.session.token):r()),l(void 0)}catch(e){if(!(e instanceof ku))throw e;s(KA(e))}a(!1)},f=e=>{s(void 0),l(e)};return(0,B.jsxs)(BA,{title:L(`devices`),description:L(`devicesDescription`),children:[e.length===0?(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:L(`noDevices`)}):(0,B.jsx)(`ul`,{className:`divide-y rounded-md border`,children:aM(e).map(e=>{let n=iM(e);return(0,B.jsxs)(`li`,{className:`flex flex-wrap items-center gap-3 px-3 py-2.5`,children:[(0,B.jsx)(n,{className:`size-4 shrink-0 text-muted-foreground`}),(0,B.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,B.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2`,children:[(0,B.jsx)(`bdi`,{className:`truncate font-medium`,children:rM(e,t)}),e.current&&(0,B.jsx)(zf,{tone:`green`,children:L(`thisDevice`)})]}),(0,B.jsxs)(`span`,{className:`block text-xs text-muted-foreground`,children:[L(`signedInFromUntil`,{from:gp(Date.parse(e.createdAt)),until:gp(Date.parse(e.expiresAt))}),!e.staff&&e.ipAddress&&` · ${e.ipAddress}`]})]}),!e.current&&(0,B.jsx)(G,{size:`sm`,variant:`ghost`,onClick:()=>f({kind:`one`,session:e}),children:L(`signOut`)})]},e.token)})}),u.length>0&&(0,B.jsx)(G,{className:`mt-3`,onClick:()=>f({kind:`others`}),children:L(`signOutOthers`)}),c&&(0,B.jsx)(Of,{title:c.kind===`one`?L(`signOutDevice`,{name:rM(c.session,t)}):L(`signOutOthersTitle`),description:c.kind===`one`?L(`signOutDeviceDescription`):L(`signOutOthersDescription`),onClose:()=>l(void 0),actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:()=>l(void 0),children:L(`cancel`)}),(0,B.jsx)(G,{variant:`danger`,loading:i,onClick:()=>void d(c),children:L(`signOut`)})]}),children:(0,B.jsx)(VA,{message:o})})]})},sM=()=>{let{session:e,staffSignIn:t}=V(),{account:n}=e,{data:r,error:i,reload:a}=jj((0,I.useCallback)(()=>n.sessions(),[n]),L(`couldNotReadDevices`));return r?(0,B.jsx)(oM,{sessions:r,operator:t,onSignOut:e=>n.revokeSession(e).then(a),onSignOutOthers:()=>n.revokeOtherSessions().then(a)}):(0,B.jsx)(Aj,{error:i})},cM={allowed:`passkeysAllowed`,required:`passkeysRequired`,forbidden:`passkeysForbidden`},lM=({rule:e,passkeys:t,onAdd:n,onRename:r,onRemove:i})=>{let[a,o]=(0,I.useState)(!1),[s,c]=(0,I.useState)(),[l,u]=(0,I.useState)(),[d,f]=(0,I.useState)(``),p=e===`required`&&t.length<=1,m=async e=>{o(!0),c(void 0);try{await e(),u(void 0)}catch(e){if(!(e instanceof ku))throw e;c(KA(e))}o(!1)};return(0,B.jsxs)(BA,{title:L(`passkeys`),status:e===`required`&&(0,B.jsx)(zf,{tone:`blue`,children:L(`required`)}),description:L(cM[e]),children:[(0,B.jsx)(VA,{message:l?void 0:s}),t.length>0&&(0,B.jsx)(`ul`,{className:`mb-3 divide-y rounded-md border`,children:t.map(e=>(0,B.jsxs)(`li`,{className:`flex flex-wrap items-center gap-3 px-3 py-2.5`,children:[(0,B.jsx)(La,{className:`size-4 shrink-0 text-muted-foreground`}),(0,B.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,B.jsx)(`span`,{className:`block truncate font-medium`,children:e.name??L(`passkey`)}),(0,B.jsxs)(`span`,{className:`block text-xs text-muted-foreground`,children:[e.createdAt?L(`addedOn`,{date:pp(Date.parse(e.createdAt))}):L(`addedEarlier`),` · `,e.backedUp?L(`synced`):L(`oneDevice`)]})]}),(0,B.jsxs)(`span`,{className:`flex gap-1`,children:[(0,B.jsx)(G,{size:`sm`,variant:`ghost`,onClick:()=>{f(e.name??``),u({kind:`rename`,passkey:e})},children:L(`rename`)}),(0,B.jsx)(G,{size:`sm`,variant:`ghost`,disabled:p,title:p?L(`keepLastPasskey`):void 0,onClick:()=>u({kind:`remove`,passkey:e}),children:L(`remove`)})]})]},e.id))}),e!==`forbidden`&&(0,B.jsxs)(G,{loading:a&&!l,onClick:()=>void m(n),children:[(0,B.jsx)(Jo,{className:`size-3.5`}),L(`addPasskey`)]}),l?.kind===`rename`&&(0,B.jsxs)(Of,{title:L(`renamePasskey`),description:L(`renamePasskeyDescription`),onClose:()=>u(void 0),actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:()=>u(void 0),children:L(`cancel`)}),(0,B.jsx)(G,{variant:`primary`,loading:a,disabled:!d.trim(),onClick:()=>void m(()=>r(l.passkey.id,d.trim())),children:L(`save`)})]}),children:[(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[L(`name`),(0,B.jsx)(J,{autoFocus:!0,value:d,maxLength:60,onChange:e=>f(e.target.value)})]}),(0,B.jsx)(VA,{message:s})]}),l?.kind===`remove`&&(0,B.jsx)(Of,{title:L(`removePasskey`),description:L(`removePasskeyDescription`,{name:l.passkey.name??L(`thisPasskey`)}),onClose:()=>u(void 0),actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:()=>u(void 0),children:L(`cancel`)}),(0,B.jsx)(G,{variant:`danger`,loading:a,onClick:()=>void m(()=>i(l.passkey.id)),children:L(`remove`)})]}),children:s&&(0,B.jsx)(VA,{message:s})})]})},uM=()=>{let{account:e}=V().session,{data:t,error:n,reload:r}=jj((0,I.useCallback)(()=>Promise.all([e.signInMethods(),e.passkeys()]),[e]),L(`couldNotReadMethods`));if(!t)return(0,B.jsx)(Aj,{error:n});let[i,a]=t;return(0,B.jsx)(lM,{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)})},dM=e=>e.code===`PASSWORD_TOO_SHORT`?L(`useAtLeast`,{length:12}):e.code===`PASSWORD_TOO_LONG`?L(`passwordTooLong`):KA(e),fM=(e,t)=>{if(e.length<12)return L(`useAtLeast`,{length:12});if(e!==t)return L(`passwordsDiffer`)},pM=({hasPassword:e,onSave:t,onClose:n})=>{let[r,i]=(0,I.useState)(``),[a,o]=(0,I.useState)(``),[s,c]=(0,I.useState)(``),[l,u]=(0,I.useState)(!1),[d,f]=(0,I.useState)(),p=(0,I.useId)(),m=(!e||r)&&a&&s,h=async()=>{let e=fM(a,s);if(f(e),!e){u(!0);try{await t({current:r,next:a})}catch(e){if(!(e instanceof ku))throw e;f(dM(e)),u(!1)}}};return(0,B.jsx)(Of,{title:L(e?`changePassword`:`setPassword`),description:L(`atLeast`,{length:12}),onClose:n,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:n,children:L(`cancel`)}),(0,B.jsx)(G,{variant:`primary`,type:`submit`,form:p,loading:l,disabled:!m,children:L(`save`)})]}),children:(0,B.jsxs)(`form`,{id:p,className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),h()},children:[e&&(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[L(`currentPassword`),(0,B.jsx)(J,{type:`password`,name:`current-password`,autoComplete:`current-password`,autoFocus:!0,value:r,onChange:e=>i(e.target.value)})]}),(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[L(`newPassword`),(0,B.jsx)(J,{type:`password`,name:`new-password`,autoComplete:`new-password`,autoFocus:!e,value:a,invalid:!!d,onChange:e=>o(e.target.value)})]}),(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[L(`repeatPassword`),(0,B.jsx)(J,{type:`password`,name:`repeat-password`,autoComplete:`new-password`,value:s,invalid:!!d,onChange:e=>c(e.target.value)})]}),e&&(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:L(`changeSignsOutOthers`)}),(0,B.jsx)(VA,{message:d})]})})},mM=({rule:e,hasPassword:t,staff:n})=>L(n?`passwordStaff`:e===`forbidden`?`passwordForbidden`:t?`passwordIsSet`:`passwordNotSet`),hM=({rule:e,hasPassword:t,staff:n,onChange:r,onSet:i})=>{let[a,o]=(0,I.useState)(!1),[s,c]=(0,I.useState)(!1),l=!n&&e===`allowed`;return(0,B.jsxs)(BA,{title:L(`password`),description:mM({rule:e,hasPassword:t,staff:n}),children:[s&&(0,B.jsx)(`p`,{role:`status`,className:`mb-3 font-medium`,children:L(`passwordSaved`)}),l&&(0,B.jsx)(G,{onClick:()=>{c(!1),o(!0)},children:L(t?`changePassword`:`setPassword`)}),a&&(0,B.jsx)(pM,{hasPassword:t,onClose:()=>o(!1),onSave:async({current:e,next:n})=>{await(t?r(e,n):i(n)),o(!1),c(!0)}})]})},gM=()=>{let{session:e,state:t}=V(),{account:n}=e,{data:r,error:i,reload:a}=jj((0,I.useCallback)(()=>n.signInMethods(),[n]),L(`couldNotReadMethods`));return r?(0,B.jsx)(hM,{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,B.jsx)(Aj,{error:i})},_M=({email:e,change:t,onDone:n,onClose:r})=>{let[i,a]=(0,I.useState)(``),[o,s]=(0,I.useState)(),[c,l]=(0,I.useState)(``),[u,d]=(0,I.useState)(!1),[f,p]=(0,I.useState)(),m=async e=>{d(!0),p(void 0);try{await e()}catch(e){if(!(e instanceof ku))throw e;p(KA(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,B.jsxs)(Of,{title:L(`changeEmail`),description:L(`codeSentTo`,{email:o,minutes:10}),onClose:r,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{variant:`ghost`,onClick:()=>{s(void 0),p(void 0)},children:L(`otherAddress`)}),(0,B.jsx)(G,{variant:`primary`,loading:u,disabled:c.length<6,onClick:()=>void _(c),children:L(`changeEmail`)})]}),children:[(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[L(`code`),(0,B.jsx)(E_,{name:`code`,required:!0,autoFocus:!0,value:c,invalid:!!f,onChange:l,onComplete:e=>!u&&void _(e)})]}),(0,B.jsx)(VA,{message:f})]}):(0,B.jsxs)(Of,{title:L(`changeEmail`),description:L(`changeEmailDescription`),onClose:r,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:r,children:L(`cancel`)}),(0,B.jsx)(G,{variant:`primary`,loading:u,disabled:!h||h.toLowerCase()===e.toLowerCase(),onClick:()=>void g(),children:L(`sendCode`)})]}),children:[(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[L(`newEmail`),(0,B.jsx)(J,{type:`email`,autoComplete:`email`,autoFocus:!0,value:i,onChange:e=>a(e.target.value)})]}),(0,B.jsx)(VA,{message:f})]})},vM=({name:e,email:t,onRename:n,emailChange:r,onEmailChanged:i})=>{let[a,o]=(0,I.useState)(!1),[s,c]=(0,I.useState)(!1),[l,u]=(0,I.useState)(``),[d,f]=(0,I.useState)(!1),[p,m]=(0,I.useState)(),h=async()=>{f(!0),m(void 0);try{await n(l.trim()),o(!1)}catch(e){if(!(e instanceof ku))throw e;m(KA(e))}f(!1)};return(0,B.jsxs)(BA,{title:L(`profile`),description:L(`profileDescription`),children:[(0,B.jsxs)(`dl`,{className:`mb-3 grid grid-cols-[auto_1fr] gap-x-6 gap-y-1.5`,children:[(0,B.jsx)(`dt`,{className:`text-muted-foreground`,children:L(`name`)}),(0,B.jsx)(`dd`,{className:`min-w-0 truncate font-medium`,children:e}),(0,B.jsx)(`dt`,{className:`text-muted-foreground`,children:L(`email`)}),(0,B.jsx)(`dd`,{className:`min-w-0 truncate font-medium`,children:t})]}),(0,B.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,B.jsx)(G,{onClick:()=>{u(e),m(void 0),o(!0)},children:L(`changeName`)}),r&&(0,B.jsx)(G,{onClick:()=>c(!0),children:L(`changeEmail`)})]}),a&&(0,B.jsxs)(Of,{title:L(`changeName`),description:L(`changeNameDescription`),onClose:()=>o(!1),actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:()=>o(!1),children:L(`cancel`)}),(0,B.jsx)(G,{variant:`primary`,loading:d,disabled:!l.trim()||l.trim()===e,onClick:()=>void h(),children:L(`save`)})]}),children:[(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[L(`name`),(0,B.jsx)(J,{autoFocus:!0,value:l,maxLength:100,onChange:e=>u(e.target.value)})]}),(0,B.jsx)(VA,{message:p})]}),s&&r&&(0,B.jsx)(_M,{email:t,change:r,onClose:()=>c(!1),onDone:()=>{c(!1),i?.()}})]})},yM=()=>{let{session:e,changeEmail:t}=V(),{data:n,loaded:r,error:i,reload:a}=jj((0,I.useCallback)(()=>e.session(),[e]),L(`couldNotReadProfile`));if(!r)return(0,B.jsx)(Aj,{error:i});if(!n)return null;let o=t?{request:e.account.requestEmailChange,confirm:e.account.changeEmail}:void 0;return(0,B.jsx)(vM,{name:n.name,email:n.email,onRename:t=>e.account.updateName(t).then(a),emailChange:o,onEmailChanged:a})},bM=(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)},xM=({codes:e})=>{let[t,n]=(0,I.useState)(!1),r=`${e.join(`
|
|
4
|
+
`)}\n`;return(0,B.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,B.jsx)(`ul`,{"aria-label":L(`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,B.jsx)(`li`,{children:e},e))}),(0,B.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,B.jsxs)(G,{size:`sm`,onClick:()=>{navigator.clipboard.writeText(r).then(()=>{n(!0),setTimeout(()=>n(!1),2e3)})},children:[t?(0,B.jsx)(Ci,{className:`size-3.5 text-success`}):(0,B.jsx)(Yi,{className:`size-3.5`}),L(t?`copied`:`copy`)]}),(0,B.jsxs)(G,{size:`sm`,onClick:()=>bM(r,`backup-codes.txt`),children:[(0,B.jsx)(ra,{className:`size-3.5`}),L(`download`)]})]})]})},SM=({title:e,description:t,confirmLabel:n,danger:r,needsPassword:i,onConfirm:a,onClose:o})=>{let[s,c]=(0,I.useState)(``),[l,u]=(0,I.useState)(!1),[d,f]=(0,I.useState)(),p=async()=>{u(!0),f(void 0);try{await a(i?s:void 0)}catch(e){if(!(e instanceof ku))throw e;f(KA(e)),u(!1)}};return(0,B.jsxs)(Of,{title:e,description:t,onClose:o,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:o,children:L(`cancel`)}),(0,B.jsx)(G,{variant:r?`danger`:`primary`,loading:l,disabled:i&&!s,onClick:()=>void p(),children:n})]}),children:[i&&(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[L(`yourPassword`),(0,B.jsx)(J,{type:`password`,autoComplete:`current-password`,autoFocus:!0,value:s,invalid:!!d,onChange:e=>c(e.target.value),onKeyDown:e=>e.key===`Enter`&&s&&void p()})]}),d&&(0,B.jsx)(`p`,{role:`alert`,className:`mt-2 text-body font-medium text-danger-text`,children:d})]})},CM=({uri:e,className:t})=>{let{size:n,path:r}=(0,I.useMemo)(()=>{let t=Ce(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,B.jsxs)(`svg`,{viewBox:`0 0 ${n} ${n}`,role:`img`,"aria-label":L(`qrCode`),shapeRendering:`crispEdges`,className:t,children:[(0,B.jsx)(`rect`,{width:n,height:n,fill:`#fff`}),(0,B.jsx)(`path`,{d:r,fill:`#000`})]})},wM=e=>(new URL(e).searchParams.get(`secret`)??``).replace(/(.{4})(?=.)/g,`$1 `),TM=()=>[{value:`app`,label:L(`authenticatorApp`),description:L(`authenticatorAppDescription`)},{value:`email`,label:L(`emailedCode`),description:L(`emailedCodeDescription`)}],EM=({offerEmailedCodes:e,needsPassword:t,onStartApp:n,onConfirmApp:r,onEmailedCodes:i,onDone:a,onCancel:o})=>{let[s,c]=(0,I.useState)({kind:`choose`}),[l,u]=(0,I.useState)(`app`),[d,f]=(0,I.useState)(``),[p,m]=(0,I.useState)(``),[h,g]=(0,I.useState)(!1),[_,v]=(0,I.useState)(),y=e?TM():TM().filter(e=>e.value===`app`),b=async e=>{g(!0),v(void 0);try{await e()}catch(e){if(!(e instanceof ku))throw e;v(KA(e))}g(!1)},x=()=>b(async()=>{let e=t?d:void 0;if(l===`email`)return await i(e),a();c({kind:`scan`,setup:await n(e)})}),S=(e,t=p)=>b(async()=>{await r(t),c({kind:`backup-codes`,codes:e.backupCodes})}),C=_&&(0,B.jsx)(`p`,{role:`alert`,className:`text-body font-medium text-danger-text`,children:_});return s.kind===`backup-codes`?(0,B.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:L(`twoFactorIsOn`)}),(0,B.jsx)(xM,{codes:s.codes}),(0,B.jsx)(G,{variant:`primary`,onClick:a,className:`min-h-10`,children:L(`savedCodes`)})]}):s.kind===`scan`?(0,B.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),S(s.setup)},children:[(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:L(`scanCode`)}),(0,B.jsxs)(`div`,{className:`flex flex-col items-center gap-2`,children:[(0,B.jsx)(CM,{uri:s.setup.totpURI,className:`size-44 rounded-md border`}),(0,B.jsxs)(`p`,{className:`text-center text-xs text-muted-foreground`,children:[L(`cannotScan`),(0,B.jsx)(`span`,{className:`mt-1 block break-all font-mono text-body text-foreground`,children:wM(s.setup.totpURI)})]})]}),(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[L(`codeFromApp`),(0,B.jsx)(E_,{name:`code`,required:!0,autoFocus:!0,value:p,invalid:!!_,onChange:m,onComplete:e=>!h&&void S(s.setup,e)})]}),C,(0,B.jsx)(G,{variant:`primary`,type:`submit`,loading:h,className:`min-h-10`,children:L(`turnOn`)}),o&&(0,B.jsx)(G,{variant:`ghost`,onClick:o,className:`min-h-10`,children:L(`cancel`)})]}):(0,B.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),x()},children:[(0,B.jsx)(`div`,{role:`radiogroup`,"aria-label":L(`secondStep`),className:`flex flex-col gap-2`,children:y.map(e=>(0,B.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":l===e.value,onClick:()=>u(e.value),className:P(`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,B.jsx)(`span`,{className:`block font-medium`,children:e.label}),(0,B.jsx)(`span`,{className:`mt-0.5 block text-xs text-muted-foreground`,children:e.description})]},e.value))}),t&&(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[L(`yourPassword`),(0,B.jsx)(J,{type:`password`,name:`password`,autoComplete:`current-password`,required:!0,value:d,invalid:!!_,onChange:e=>f(e.target.value),className:`min-h-6`})]}),C,(0,B.jsx)(G,{variant:`primary`,type:`submit`,loading:h,className:`min-h-10`,children:L(`continue`)}),o&&(0,B.jsx)(G,{variant:`ghost`,onClick:o,className:`min-h-10`,children:L(`cancel`)})]})},DM={allowed:`twoFactorAllowed`,required:`twoFactorRequired`,forbidden:`twoFactorForbidden`},OM=e=>{let{rule:t,enabled:n,authenticatorApp:r,mail:i,needsPassword:a,onTurnOff:o,onNewBackupCodes:s,onChanged:c}=e,[l,u]=(0,I.useState)(),d=()=>u(void 0),f=n?(0,B.jsx)(zf,{tone:`green`,children:L(`on`)}):t===`required`?(0,B.jsx)(zf,{tone:`amber`,children:L(`required`)}):(0,B.jsx)(zf,{children:L(`off`)}),p=L(n?r?i?`twoFactorOnWithAppOrMail`:`twoFactorOnWithApp`:`twoFactorOnWithMail`:DM[t]);return l?.kind===`setup`?(0,B.jsx)(BA,{title:L(`twoFactor`),status:f,description:p,children:(0,B.jsx)(`div`,{className:`max-w-sm`,children:(0,B.jsx)(EM,{offerEmailedCodes:i&&!l.appOnly,needsPassword:a,onStartApp:e.onStartApp,onConfirmApp:e.onConfirmApp,onEmailedCodes:e.onEmailedCodes,onCancel:d,onDone:()=>{d(),c()}})})}):(0,B.jsxs)(BA,{title:L(`twoFactor`),status:f,description:p,children:[(0,B.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[!n&&t!==`forbidden`&&(0,B.jsx)(G,{variant:`primary`,onClick:()=>u({kind:`setup`,appOnly:!1}),children:L(`turnOn`)}),n&&!r&&t!==`forbidden`&&(0,B.jsx)(G,{onClick:()=>u({kind:`setup`,appOnly:!0}),children:L(`addAuthenticator`)}),n&&r&&(0,B.jsx)(G,{onClick:()=>u({kind:`new-codes`}),children:L(`newBackupCodes`)}),n&&(0,B.jsx)(G,{variant:`danger`,disabled:t===`required`,title:t===`required`?L(`twoFactorIsRequired`):void 0,onClick:()=>u({kind:`turn-off`}),children:L(`turnOff`)})]}),l?.kind===`turn-off`&&(0,B.jsx)(SM,{title:L(`turnOffTitle`),description:L(`turnOffDescription`),confirmLabel:L(`turnOff`),danger:!0,needsPassword:a,onClose:d,onConfirm:async e=>{await o(e),d(),c()}}),l?.kind===`new-codes`&&(0,B.jsx)(SM,{title:L(`newCodesTitle`),description:L(`newCodesDescription`),confirmLabel:L(`makeNewCodes`),needsPassword:a,onClose:d,onConfirm:async e=>u({kind:`codes`,codes:await s(e)})}),l?.kind===`codes`&&(0,B.jsx)(Of,{title:L(`yourNewCodes`),description:L(`keepCodesSafe`),onClose:d,actions:(0,B.jsx)(G,{variant:`primary`,onClick:d,children:L(`savedCodes`)}),children:(0,B.jsx)(xM,{codes:l.codes})})]})},kM={Page:kS,Grid:ex,Card:Ly,Stat:ND,RecordCard:NS,Field:Yb,Table:LA,CardRow:zy,RecordRow:CD,RecordCards:QS,Chart:wb,Progress:jS,ModalForm:_x,Action:Py,Show:kD,Link:nx,Settings:DD,Tabs:RA,Tab:zA,Users:Oj,Profile:yM,Password:gM,Passkeys:uM,TwoFactor:()=>{let{account:e}=V().session,{data:t,error:n,reload:r}=jj((0,I.useCallback)(()=>e.signInMethods(),[e]),L(`couldNotReadMethods`));return t?(0,B.jsx)(OM,{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,B.jsx)(Aj,{error:n})},ConnectedAccounts:Fj,PersonalMail:Lj,Devices:sM,ConnectedApps:Jj,DeleteAccount:Qj},AM=e=>typeof e==`string`||!e.custom&&e.type===`Link`,jM=e=>{let t=[];for(let n of e){let e=t.at(-1);AM(n)&&e&&AM(e[0])?e.push(n):t.push([n])}return t.map((e,t)=>{let[n]=e;return AM(n)?(0,B.jsx)(`p`,{className:`leading-6`,children:e.map((e,t)=>typeof e==`string`?(0,B.jsx)(I.Fragment,{children:e},t):(0,B.jsx)(PM,{node:e},t))},t):(0,B.jsx)(PM,{node:n},t)})},MM=e=>iu(e)||Array.isArray(e)&&e.length>0&&e.every(iu),NM=e=>Object.fromEntries(Object.entries(e.props).flatMap(([e,t])=>MM(t)?[[e,(0,B.jsx)(B.Fragment,{children:jM(Array.isArray(t)?t:[t])})]]:[])),PM=({node:e})=>{let{components:t}=p_();if(e.custom){let n=t?.[e.type];return n?(0,B.jsx)(pv,{name:e.type,children:(0,B.jsx)(n,{...vn(e.props),children:e.children.length>0?jM(e.children):void 0})}):(0,B.jsx)(dv,{children:fv.rich(`noComponent`,{component:e.type})})}let n=kM[e.type];return n?(0,B.jsx)(n,{node:e,slots:NM(e),children:jM(e.children)}):(0,B.jsx)(dv,{children:fv.rich(`unknownBlock`,{type:e.type})})},FM=(e,t)=>{let n=du(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},IM=()=>{let{account:e}=W(),t=V(),{mcp:n,accountDeletion:r}=t,i=Pj(t).length>0,a=t.personalMail.length>0;return(0,I.useMemo)(()=>{if(!e)return;let t=new Set([...n?[]:[`ConnectedApps`],...i?[]:[`ConnectedAccounts`],...a?[]:[`PersonalMail`],...r?[]:[`DeleteAccount`]]);return{...e,tree:FM(e.tree,t)}},[e,n,i,a,r])},LM=({tab:e})=>{let t=IM();return t?(0,B.jsx)(ff,{route:{...e&&{tab:e},pathOf:Dc},children:(0,B.jsx)(PM,{node:t.tree})}):(0,B.jsx)(sf,{title:L(`noAccount`),children:L(`noAccountDescription`)})},RM=({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?[Mg(`title`,{noun:i})]:[],...s];let c=a??(o?void 0:e.key);return[...c?[c]:[],...s]},zM=(e,t)=>[...e.filter(Boolean),t].join(` · `),BM=e=>{(0,I.useEffect)(()=>{let t=document.title;return document.title=e,()=>{document.title=t}},[e])},VM=500,HM=(e=window)=>e.top!==e.self,UM=(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)}},WM=()=>{let e=!1;return{down:(t,n=!1)=>{e=t&&!n},take:()=>{let t=e;return e=!1,t}}},GM=(e,t)=>n=>n?e(!0):t(()=>e(!1)),KM=e=>{let[t,n]=(0,I.useState)(!1);return(0,I.useEffect)(()=>UM(document,e,GM(n,Cc.flushSync)),[e]),t},qM=(e,t)=>{let n=(0,I.useRef)(WM());return{onPointerDown:()=>n.current.down(e),onKeyDown:t=>n.current.down(e,t.repeat),onClick:()=>{n.current.take()&&t()}}},JM=[`localhost`,`127.0.0.1`,`[::1]`],YM=[`javascript:`,`data:`,`vbscript:`,`file:`,`blob:`,`about:`],XM=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 JM.includes(t.hostname)?{kind:`this-computer`,port:t.port||`80`}:void 0;if(!YM.includes(t.protocol))return{kind:`device-app`,uri:e.split(`?`)[0].split(`#`)[0]}},ZM=e=>!URL.canParse(e,`http://local`)||!YM.includes(new URL(e,`http://local`).protocol),QM=(e,t)=>{let n=new URL(e,t.origin);if(n.origin===t.origin&&n.pathname===t.pathname)return qc(n.search).oauthQuery},$M=()=>{let{params:e}=Ih();return(0,I.useMemo)(()=>qc(e.toString()),[e])},eN={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.`},tN=e=>{if(!(e instanceof ku))throw e;return(e.code&&eN[e.code])??KA(e)},nN=e=>t=>{if(!ZM(t))throw new ku(`The app asked to be sent somewhere this page will not go.`,400);e(t)},rN=({target:e})=>e.kind===`site`?(0,B.jsxs)(B.Fragment,{children:[`the website `,(0,B.jsx)(`strong`,{className:`font-medium text-foreground`,children:e.host})]}):e.kind===`this-computer`?(0,B.jsxs)(B.Fragment,{children:[`an app on this computer (port `,e.port,`)`]}):(0,B.jsxs)(B.Fragment,{children:[`an app on this device that opens `,(0,B.jsx)(`code`,{className:`break-all text-foreground`,children:e.uri})]}),iN=({title:e,icon:t,children:n})=>(0,B.jsx)(vj,{title:e,icon:t,children:(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:n})}),aN=({asking:e,appName:t,appIcon:n,email:r,onAnswer:i,onSignOut:a})=>{let[o,s]=(0,I.useState)(!1),c=KM(500),l=e=>{s(!0),i(e).finally(()=>s(!1))},u=qM(c&&!o,()=>l(!0)),d=zj(e.client.client_name),f=Bj(e.client.client_id),{target:p}=e;return(0,B.jsx)(vj,{title:`Allow an app to act as you in ${t}?`,icon:n,size:`md`,children:(0,B.jsxs)(`section`,{"aria-label":`Allow an app`,children:[(0,B.jsxs)(`p`,{children:[`An app that calls itself`,` `,(0,B.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,B.jsxs)(`p`,{className:`mt-1 text-muted-foreground`,children:[`Published by `,f,`.`]}),p?(0,B.jsxs)(`p`,{className:`mt-3 text-muted-foreground`,children:[`Allowing sends you on to `,(0,B.jsx)(rN,{target:p}),`.`]}):(0,B.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,B.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,B.jsxs)(`div`,{className:`mt-5 flex flex-col-reverse gap-2 sm:flex-row sm:justify-end`,children:[(0,B.jsx)(G,{disabled:o,onClick:()=>l(!1),children:`Deny`}),p&&(0,B.jsx)(G,{variant:`primary`,loading:o,disabled:!c||o,...u,children:`Allow`})]}),(0,B.jsxs)(`p`,{className:`mt-4 border-t pt-3 text-xs text-muted-foreground`,children:[`Signed in as `,r,`.`,` `,(0,B.jsx)(`button`,{type:`button`,className:`underline underline-offset-2 hover:text-foreground`,onClick:a,children:`Not you? Sign out`})]})]})})},oN=({oauthQuery:e,appName:t,appIcon:n,email:r,assign:i})=>{let{session:a,signOut:o}=V(),{path:s,basePath:c}=Ih(),l=nN(i),u=e=>QM(e,{origin:window.location.origin,pathname:`${c}${s}`}),[d,f]=(0,I.useState)({kind:`loading`}),p=e=>f({kind:`failed`,message:tN(e)});(0,I.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:XM(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,B.jsx)(iN,{title:`This app cannot be connected`,icon:n,children:d.message}):d.kind===`loading`?(0,B.jsxs)(`div`,{className:`flex min-h-full w-full items-center justify-center gap-2 bg-surface text-muted-foreground`,children:[(0,B.jsx)(af,{}),` Loading`]}):(0,B.jsx)(aN,{asking:d.asking,appName:t,appIcon:n,email:r,onAnswer:e=>m(e,d.asking),onSignOut:()=>void o()})},sN=({email:e,appName:t,appIcon:n,isFramed:r=HM,assign:i=e=>window.location.assign(e)})=>{let[a]=(0,I.useState)(r),{oauthQuery:o}=$M();return a?(0,B.jsxs)(iN,{title:`This page cannot be used inside another site`,icon:n,children:[(0,B.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,B.jsx)(oN,{oauthQuery:o,appName:t,appIcon:n,email:e,assign:i},o):(0,B.jsx)(iN,{title:`Nothing to connect`,icon:n,children:`Connect again from your app.`})},cN={title:`Sign in to connect an app`,description:`An app asks to act as you here. Sign in, then choose whether to allow it.`},lN=()=>{let e=W(),{state:t}=V();return BM(zM([`Connect an app`],e.appName)),t.kind===`signed-in`?(0,B.jsx)(sN,{email:t.user.email,appName:e.appName??`this app`,appIcon:e.appIcon}):(0,B.jsx)(vj,{title:cN.title,description:cN.description,icon:e.appIcon,children:(0,B.jsx)(`div`,{className:`flex flex-col gap-2 [&>*]:min-h-10 [&>*]:w-full`,children:(0,B.jsx)(cE,{prompt:cN})})})},uN=()=>[{value:`allowed`,label:L(`on`)},{value:`forbidden`,label:L(`off`)}],dN=()=>[{value:`allowed`,label:L(`optional`)},{value:`required`,label:L(`required`)},{value:`forbidden`,label:L(`off`)}],fN=()=>[{method:`password`,label:L(`password`),description:L(`passwordDescription`),rules:uN()},{method:`emailCode`,label:L(`emailedSignInCode`),description:L(`emailedSignInCodeDescription`),rules:uN()},{method:`passkey`,label:L(`passkeys`),description:L(`passkeysPolicyDescription`),rules:dN()},{method:`twoFactor`,label:L(`twoFactor`),description:L(`twoFactorPolicyDescription`),rules:dN()},{method:`staffAccess`,label:L(`staffAccess`),description:L(`staffAccessDescription`),rules:[{value:`allowed`,label:L(`on`)},{value:`notify`,label:L(`emailThePerson`)},{value:`forbidden`,label:L(`off`)}]},{method:`platformSignIn`,label:L(`platformSignIn`),description:L(`platformSignInDescription`),rules:uN()}],pN=(e,t)=>{let n=fN().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},mN=({row:e,value:t,onChange:n})=>(0,B.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,B.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":e.value===t,onClick:()=>n(e.value),className:P(`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))}),hN=({method:e},t,{mail:n,effective:r,policy:i})=>{if(e===`emailCode`&&!n)return L(`codeNeedsMail`);if(e===`password`&&!n&&t.password===`forbidden`)return L(`passwordStaysOn`);if(e===`staffAccess`&&!n&&t.staffAccess===`notify`)return L(`staffNeedsMail`);if(e===`platformSignIn`&&t.platformSignIn===`allowed`&&(t.passkey===`required`||t.twoFactor===`required`))return L(`platformOff`);if(t[e]===i[e]&&r[e]!==i[e])return L(`appliesAs`,{rule:pN(e,r[e])})},gN=({operator:e,platformSignIn:t})=>fN().flatMap(n=>n.method===`staffAccess`&&!e?[]:n.method===`platformSignIn`?t?[{...n,label:L(`platformSignInWith`,{provider:t})}]:[]:[n]),_N=({state:e,onSave:t,busy:n,error:r,notice:i})=>{let[a,o]=(0,I.useState)(e.policy),s=gN(e),c=s.some(({method:t})=>a[t]!==e.policy[t]);return(0,B.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),t(a)},children:[(0,B.jsx)(`ul`,{className:`divide-y rounded-lg border bg-background`,children:s.map(t=>{let n=hN(t,a,e);return(0,B.jsxs)(`li`,{className:`flex flex-col gap-3 p-4 sm:flex-row sm:items-start sm:justify-between`,children:[(0,B.jsxs)(`div`,{className:`min-w-0`,children:[(0,B.jsx)(`h2`,{className:`font-semibold`,children:t.label}),(0,B.jsx)(`p`,{className:`mt-0.5 text-muted-foreground`,children:t.description}),n&&(0,B.jsx)(`p`,{className:`mt-1.5 text-xs font-medium text-warning-text`,children:n})]}),(0,B.jsx)(mN,{row:t,value:a[t.method],onChange:e=>o({...a,[t.method]:e})})]},t.method)})}),r&&(0,B.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,B.jsx)(`p`,{role:`status`,className:`rounded-md bg-success-soft px-3 py-2 text-body font-medium text-success-text`,children:i}),(0,B.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.savedAt?e.savedBy?L(`lastSavedBy`,{name:e.savedBy,time:gp(Date.parse(e.savedAt))}):L(`lastSaved`,{time:gp(Date.parse(e.savedAt))}):L(`neverChanged`)}),(0,B.jsxs)(`div`,{className:`flex gap-2`,children:[c&&(0,B.jsx)(G,{onClick:()=>o(e.policy),children:L(`reset`)}),(0,B.jsx)(G,{variant:`primary`,type:`submit`,loading:n,disabled:!c,children:L(`save`)})]})]})]})},vN=(e,t)=>e.endedAt?(0,B.jsx)(zf,{tone:`neutral`,children:L(`stopped`,{time:gp(Date.parse(e.endedAt))})}):Date.parse(e.expiresAt)<=t?(0,B.jsx)(zf,{tone:`neutral`,children:L(`ended`,{time:gp(Date.parse(e.expiresAt))})}):(0,B.jsx)(zf,{tone:`amber`,children:L(`signedInUntil`,{time:gp(Date.parse(e.expiresAt))})}),yN=({signIns:e,operator:t,error:n,now:r=Date.now()})=>(0,B.jsxs)(BA,{title:L(`staffSignIns`),description:L(`staffSignInsDescription`,{operator:t}),children:[(0,B.jsx)(VA,{message:n}),e&&e.length===0&&(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:L(`noStaffSignIns`)}),e&&e.length>0&&(0,B.jsx)(`ul`,{className:`divide-y rounded-md border`,children:e.map(e=>(0,B.jsxs)(`li`,{className:`flex flex-col gap-1.5 p-3`,children:[(0,B.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1`,children:[(0,B.jsx)(`span`,{className:`font-medium break-all`,children:e.staffName?`${e.staffName} (${e.staff})`:e.staff}),(0,B.jsx)(`span`,{className:`text-muted-foreground`,children:L(`as`)}),(0,B.jsx)(`span`,{className:`font-medium break-all`,children:e.user})]}),(0,B.jsx)(`p`,{className:`break-words`,children:e.reason}),(0,B.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-xs text-muted-foreground`,children:[(0,B.jsx)(`span`,{children:gp(Date.parse(e.startedAt))}),vN(e,r)]})]},e.id))})]}),bN=({operator:e})=>{let{session:t}=V(),[n,r]=(0,I.useState)(),[i,a]=(0,I.useState)();return(0,I.useEffect)(()=>{t.staff.log().then(r,e=>a(e instanceof ku?KA(e):L(`couldNotReadStaffSignIns`)))},[t]),(0,B.jsx)(yN,{operator:e,signIns:n,error:i})},xN=()=>{let{session:e}=V(),[t,n]=(0,I.useState)(),[r,i]=(0,I.useState)(!1),[a,o]=(0,I.useState)(),[s,c]=(0,I.useState)();(0,I.useEffect)(()=>{e.signInPolicy.read().then(n,e=>o(e instanceof ku?KA(e):L(`couldNotReadPolicy`)))},[e]);let l=async t=>{i(!0),o(void 0),c(void 0);try{n(await e.signInPolicy.save(t)),c(L(`policySaved`))}catch(e){if(!(e instanceof ku))throw e;o(KA(e))}i(!1)};return(0,B.jsxs)(`div`,{className:`mx-auto flex w-full max-w-3xl flex-col gap-4 px-4 py-6 md:px-6`,children:[(0,B.jsx)(DS,{title:L(`signInPolicy`),subtitle:L(`policySubtitle`)}),t?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(_N,{state:t,busy:r,error:a,notice:s,onSave:e=>void l(e)},t.savedAt??`default`),t.operator&&(0,B.jsx)(bN,{operator:t.operator})]}):a?(0,B.jsx)(`p`,{role:`alert`,className:`text-danger-text`,children:a}):(0,B.jsxs)(`div`,{className:`flex items-center gap-2 text-muted-foreground`,children:[(0,B.jsx)(af,{}),` `,L(`loading`)]})]})},SN=({onResend:e,cooldown:t=30,disabled:n})=>{let[r,i]=(0,I.useState)(()=>Date.now()+t*1e3),[a,o]=(0,I.useState)(()=>Date.now()),s=Math.max(0,Math.ceil((r-a)/1e3));return(0,I.useEffect)(()=>{if(s===0)return;let e=setInterval(()=>o(Date.now()),1e3);return()=>clearInterval(e)},[s]),(0,B.jsx)(G,{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?z(`sendNewCodeIn`,{seconds:s}):z(`sendNewCode`)})},CN=({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,I.useState)(``),m=(0,I.useRef)(null);return(0,I.useEffect)(()=>{u&&(p(``),m.current?.focus())},[u]),(0,B.jsxs)(vj,{title:e,description:t,children:[(0,B.jsx)(`p`,{className:`mb-4 text-muted-foreground`,children:n}),u&&(0,B.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,B.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),i(f)},children:[(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[z(`code`),(0,B.jsx)(E_,{ref:m,name:`code`,required:!0,autoFocus:!0,value:f,invalid:!!l,onChange:p,onComplete:e=>!c&&i(e)})]}),l&&(0,B.jsx)(`p`,{role:`alert`,className:`text-body font-medium text-danger-text`,children:l}),(0,B.jsx)(G,{variant:`primary`,type:`submit`,loading:c,className:`min-h-10`,children:r}),(0,B.jsxs)(`div`,{className:`flex flex-wrap justify-center gap-x-2 sm:justify-between`,children:[(0,B.jsx)(G,{variant:`ghost`,onClick:o,className:`min-h-10`,children:s}),(0,B.jsx)(SN,{onResend:a,disabled:c,cooldown:d})]})]})]})},wN=({email:e,onBack:t,...n})=>(0,B.jsx)(CN,{title:z(`checkEmail`),description:z(`signInCodeDescription`),explanation:(0,B.jsx)(B.Fragment,{children:z.rich(`signInCodeSent`,{email:(0,B.jsx)(`span`,{className:`font-medium text-foreground`,children:e}),minutes:10})}),submitLabel:z(`signIn`),onChangeAddress:t,changeAddressLabel:z(`backToSignIn`),...n}),TN=({email:e,onBack:t})=>{let{signInWithCode:n,sendSignInCode:r}=V(),[i,a]=(0,I.useState)(!1),[o,s]=(0,I.useState)(),[c,l]=(0,I.useState)(),u=async e=>{a(!0),s(void 0),l(void 0);try{await e()}catch(e){if(!(e instanceof ku))throw e;s(KA(e))}a(!1)};return(0,B.jsx)(wN,{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(z(`newCodeSent`))})})},EN=`protobase users create you@example.com`,DN=({command:e=EN,firstAdminUrl:t,onCheckAgain:n,busy:r})=>(0,B.jsxs)(vj,{title:z(`noAdminTitle`),description:z(`noAdminDescription`),children:[t?(0,B.jsx)(ON,{url:t}):(0,B.jsx)(kN,{command:e}),(0,B.jsx)(G,{variant:t?`secondary`:`primary`,className:`mt-4 min-h-10 w-full`,loading:r,onClick:n,children:z(`reload`)})]}),ON=({url:e})=>(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:z(`firstAdminExplanation`)}),(0,B.jsxs)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,className:P(yf({variant:`primary`}),`mt-4 min-h-10 w-full`),children:[z(`firstAdminLink`),(0,B.jsx)(da,{className:`size-4`})]})]}),kN=({command:e})=>{let[t,n]=(0,I.useState)(!1);return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:z(`noAdminExplanation`)}),(0,B.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,B.jsx)(`code`,{className:`min-w-0 flex-1 break-all font-mono text-xs`,children:e}),(0,B.jsx)(`button`,{type:`button`,"aria-label":z(`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,B.jsx)(Ci,{className:`size-4 text-success`}):(0,B.jsx)(Yi,{className:`size-4`})})]})]})},AN=({onSubmit:e,back:t,busy:n,error:r,sentTo:i})=>{let[a,o]=(0,I.useState)(``);return i?(0,B.jsxs)(vj,{title:z(`checkEmail`),children:[(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:z.rich(`resetSent`,{email:(0,B.jsx)(`span`,{className:`font-medium text-foreground`,children:i})})}),(0,B.jsx)(Dh,{to:t,className:P(yf({variant:`primary`}),`mt-4 min-h-10 w-full`),children:z(`backToSignIn`)})]}):(0,B.jsx)(vj,{title:z(`resetTitle`),description:z(`resetDescription`),children:(0,B.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:t=>{t.preventDefault(),e(a.trim())},children:[(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[z(`email`),(0,B.jsx)(J,{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,B.jsx)(`p`,{role:`alert`,className:`text-body font-medium text-danger-text`,children:r}),(0,B.jsx)(G,{variant:`primary`,type:`submit`,loading:n,className:`min-h-10`,children:z(`sendResetLink`)}),(0,B.jsx)(Dh,{to:t,className:P(yf({variant:`ghost`}),`min-h-10`),children:z(`backToSignIn`)})]})})},jN=`password-reset`,MN=e=>{let t=new URL(e);return`${t.origin}${t.pathname}?${jN}`},NN=e=>{let t=new URL(e).searchParams;if(t.has(`password-reset`))return{token:t.get(`token`)||void 0}},PN=e=>{let t=new URL(e);for(let e of[jN,`token`,`error`])t.searchParams.delete(e);return`${t.pathname}${t.search}${t.hash}`},FN=({back:e})=>{let{session:t}=V(),[n,r]=(0,I.useState)(!1),[i,a]=(0,I.useState)(),[o,s]=(0,I.useState)(),c=async e=>{r(!0),a(void 0);try{await t.requestPasswordReset(e,MN(window.location.href)),s(e)}catch(e){if(!(e instanceof ku))throw e;a(e.status===429?z(`tooManyRequests`):e.message)}r(!1)};return(0,B.jsx)(AN,{busy:n,error:i,sentTo:o,back:e,onSubmit:e=>void c(e)})},IN=({name:e,workspace:t})=>(0,B.jsx)(vj,{title:z(`signingInWith`,{name:e}),description:t,children:(0,B.jsxs)(`p`,{role:`status`,className:`flex items-center justify-center gap-2 text-muted-foreground`,children:[(0,B.jsx)(af,{}),` `,z(`takingYouTo`,{name:e})]})}),LN=({provider:e,workspace:t,onFailed:n})=>{let{signInProviders:r,signInSocial:i}=V(),a=r.find(t=>t.id===e),o=a?.name??jd(e),s=(0,I.useRef)(!1);return(0,I.useEffect)(()=>{if(!s.current){if(s.current=!0,!a)return n(z(`providerNotOffered`,{name:o}));i(e).catch(e=>{if(!(e instanceof ku))throw e;n(qA(e))})}},[a,o,e,i,n]),(0,B.jsx)(IN,{name:o,workspace:t})},RN=e=>e.status===429?z(`tooManyAttempts`):e.code===`PASSWORD_TOO_SHORT`?z(`useAtLeast`,{length:12}):e.code===`PASSWORD_TOO_LONG`?z(`passwordTooLong`):KA(e),zN=({token:e,onDone:t,onRequestNewLink:n,onBack:r})=>{let{session:i}=V(),[a,o]=(0,I.useState)(!1),[s,c]=(0,I.useState)(),[l,u]=(0,I.useState)(!e),d=async n=>{o(!0),c(void 0);try{await i.resetPassword(e,n),t()}catch(e){if(!(e instanceof ku))throw e;e.code===`INVALID_TOKEN`?u(!0):c(RN(e)),o(!1)}};return(0,B.jsx)(yj,{busy:a,error:s,invalidLink:l,onRequestNewLink:n,onBack:r,onSubmit:e=>void d(e)})},BN=e=>z(e===`twoFactor`?`turnOnTwoFactor`:`addPasskey`),VN=({step:e,twoFactor:t,onAddPasskey:n,busy:r,error:i,onSignOut:a})=>(0,B.jsxs)(vj,{title:BN(e),description:z(`requiredForEveryAccount`),children:[e===`twoFactor`?(0,B.jsx)(EM,{...t}):(0,B.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:z(`passkeyExplanation`)}),i&&(0,B.jsx)(`p`,{role:`alert`,className:`text-body font-medium text-danger-text`,children:i}),(0,B.jsxs)(G,{variant:`primary`,loading:r,onClick:n,className:`min-h-10`,children:[(0,B.jsx)(La,{className:`size-4`}),z(`addPasskey`)]})]}),(0,B.jsx)(`button`,{type:`button`,onClick:a,className:`mt-4 w-full text-center font-medium text-muted-foreground hover:underline`,children:z(`signOut`)})]}),HN=({missing:e})=>{let{session:t,recheck:n,signOut:r}=V(),[i,a]=(0,I.useState)(),[o,s]=(0,I.useState)(!1),[c,l]=(0,I.useState)();(0,I.useEffect)(()=>{t.account.signInMethods().then(a,e=>l(e instanceof ku?KA(e):z(`couldNotReadAccount`)))},[t]);let u=async()=>{s(!0),l(void 0);try{await t.account.addPasskey(),n()}catch(e){if(!(e instanceof ku))throw e;l(KA(e)),s(!1)}};return!i&&!c?(0,B.jsxs)(`div`,{className:`flex h-full min-h-48 items-center justify-center gap-2 text-muted-foreground`,children:[(0,B.jsx)(af,{}),` `,z(`loading`)]}):(0,B.jsx)(VN,{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}})},UN=({className:e})=>(0,B.jsx)(`svg`,{viewBox:`0 0 24 24`,fill:`currentColor`,className:P(`size-4 shrink-0`,e),"aria-hidden":!0,children:(0,B.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`})}),WN=({id:e,className:t})=>e===`github`?(0,B.jsx)(UN,{className:t}):null,GN=()=>(0,B.jsxs)(`div`,{className:`my-4 flex items-center gap-3 text-xs text-muted-foreground`,children:[(0,B.jsx)(`span`,{className:`h-px flex-1 bg-border`}),z(`or`),(0,B.jsx)(`span`,{className:`h-px flex-1 bg-border`})]}),KN=({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})=>{let[h,g]=(0,I.useState)(``),[_,v]=(0,I.useState)(``),[y,b]=(0,I.useState)(!1),x=(0,I.useRef)(null),S=a.includes(`password`),C=a.includes(`emailCode`)&&s!==void 0,w=a.includes(`passkey`)&&c!==void 0,T=f?d:[],E=o===`emailCode`&&S&&C&&!y,D=S&&!E,O=()=>{x.current?.reportValidity()&&s?.(h.trim())};return(0,B.jsxs)(vj,{title:z(`signInTitle`),description:r,children:[i&&(0,B.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}),(T.length>0||w)&&(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[T.map(e=>(0,B.jsxs)(G,{onClick:()=>f?.(e.id),disabled:t,className:`min-h-10 w-full`,children:[(0,B.jsx)(WN,{id:e.id}),z(`continueWith`,{name:e.name})]},e.id)),w&&(0,B.jsxs)(G,{onClick:()=>c?.(),disabled:t,className:`min-h-10 w-full`,children:[(0,B.jsx)(La,{className:`size-4`}),z(`signInWithPasskey`)]}),w&&l.slice(1).map(e=>(0,B.jsx)(G,{variant:`ghost`,size:`sm`,onClick:()=>c?.(e),disabled:t,className:`w-full`,children:z(`passkeyFor`,{domain:e})},e))]}),S||C?(0,B.jsx)(GN,{}):n&&(0,B.jsx)(`p`,{role:`alert`,className:`mt-4 text-body font-medium text-danger-text`,children:n})]}),(S||C)&&(0,B.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:t=>{t.preventDefault(),D?e(h.trim(),_):O()},children:[(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[z(`email`),(0,B.jsx)(J,{ref:x,type:`email`,name:`email`,autoComplete:`username webauthn`,required:!0,autoFocus:!0,value:h,invalid:!!n,onChange:e=>g(e.target.value),className:`min-h-6`})]}),D&&(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[z(`password`),(0,B.jsx)(J,{type:`password`,name:`password`,autoComplete:`current-password`,required:!0,value:_,invalid:!!n,onChange:e=>v(e.target.value),className:`min-h-6`})]}),n&&(0,B.jsx)(`p`,{role:`alert`,className:`text-body font-medium text-danger-text`,children:n}),D&&(0,B.jsx)(G,{variant:`primary`,type:`submit`,loading:t,className:`min-h-10`,children:z(`signIn`)}),C&&(0,B.jsxs)(G,{variant:D?`secondary`:`primary`,type:D?`button`:`submit`,onClick:D?O:void 0,loading:t&&!D,disabled:t,className:`min-h-10`,children:[(0,B.jsx)(lo,{className:`size-4`}),z(`emailSignInCode`)]}),E&&(0,B.jsx)(G,{variant:`ghost`,onClick:()=>b(!0),disabled:t,className:`min-h-10`,children:z(`usePassword`)}),D&&u&&(0,B.jsx)(Dh,{to:u,className:`self-center font-medium text-primary-text hover:underline`,children:z(`forgotPassword`)})]}),p&&(0,B.jsxs)(`p`,{className:`mt-4 text-center text-muted-foreground`,children:[z(`newHere`),` `,(0,B.jsx)(Dh,{to:p,className:`font-medium text-primary-text hover:underline`,children:z(`createAnAccount`)})]}),m&&(0,B.jsx)(`button`,{type:`button`,onClick:m,className:`mt-4 w-full text-center font-medium text-muted-foreground hover:text-foreground hover:underline`,children:z(`browse`)})]})},qN=({workspace:e,notice:t,forgotPassword:n,signUp:r,onBrowse:i,onCodeSent:a,error:o})=>{let{signIn:s,signInSocial:c,signInProviders:l,signInMethods:u,signInFirst:d,passkeyDomains:f,sendSignInCode:p,signInWithPasskey:m}=V(),[h,g]=(0,I.useState)(!1),[_,v]=(0,I.useState)(o),y=async(e,t)=>{g(!0),v(void 0);try{await e()}catch(e){if(!(e instanceof ku))throw e;v(t(e)),g(!1)}};return(0,B.jsx)(KN,{busy:h,error:_,workspace:e,notice:t,methods:u,first:d,forgotPassword:n,signUp:r,onBrowse:i,providers:l,onContinueWith:e=>void y(()=>c(e),qA),passkeyDomains:f,onPasskey:e=>void y(()=>m(e),KA),onSendCode:e=>void y(async()=>{await p(e),a(e)},KA),onSubmit:(e,t)=>void y(()=>s(e,t),qA)})},JN=({email:e,onBack:t,...n})=>(0,B.jsx)(CN,{title:z(`checkEmail`),description:z(`signUpCodeDescription`),explanation:(0,B.jsx)(B.Fragment,{children:z.rich(`signUpCodeSent`,{email:(0,B.jsx)(`span`,{className:`font-medium text-foreground`,children:e}),minutes:10})}),submitLabel:z(`continue`),onChangeAddress:t,changeAddressLabel:z(`useAnotherAddress`),...n}),YN=({email:e,onSubmit:t,onBack:n,methods:r,busy:i,error:a})=>{let[o,s]=(0,I.useState)(``),[c,l]=(0,I.useState)(``),u=(0,I.useId)(),d=r.includes(`password`),f=r.includes(`emailCode`);return(0,B.jsxs)(vj,{title:z(`detailsTitle`),description:z(`detailsDescription`),children:[(0,B.jsx)(`p`,{className:`mb-4 text-muted-foreground`,children:z.rich(`codeWasRight`,{email:(0,B.jsx)(`span`,{className:`font-medium text-foreground`,children:e})})}),(0,B.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),t({name:o.trim(),...d&&c&&{password:c}})},children:[(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[z(`yourName`),(0,B.jsx)(J,{name:`name`,autoComplete:`name`,required:!0,autoFocus:!0,maxLength:200,value:o,onChange:e=>s(e.target.value),className:`min-h-6`})]}),d&&(0,B.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[z(f?`passwordOptional`:`password`),(0,B.jsx)(J,{type:`password`,name:`password`,autoComplete:`new-password`,"aria-describedby":u,required:!f,minLength:12,maxLength:128,value:c,onChange:e=>l(e.target.value),className:`min-h-6`})]}),(0,B.jsxs)(`p`,{id:u,className:`text-xs text-muted-foreground`,children:[z(`atLeast`,{length:12}),f&&z(`withoutPassword`)]})]}),a&&(0,B.jsx)(`p`,{role:`alert`,className:`text-body font-medium text-danger-text`,children:a}),(0,B.jsx)(G,{variant:`primary`,type:`submit`,loading:i,className:`min-h-10`,children:z(`createAccount`)}),(0,B.jsx)(G,{variant:`ghost`,onClick:n,className:`min-h-10`,children:z(`useAnotherAddress`)})]})]})},XN=({onSubmit:e,onSignIn:t,onBrowse:n,busy:r,error:i,workspace:a})=>{let[o,s]=(0,I.useState)(``);return(0,B.jsxs)(vj,{title:z(`createAnAccount`),description:a,children:[(0,B.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:t=>{t.preventDefault(),e(o.trim())},children:[(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[z(`email`),(0,B.jsx)(J,{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,B.jsx)(`p`,{className:`text-muted-foreground`,children:z(`codeToConfirm`)}),i&&(0,B.jsx)(`p`,{role:`alert`,className:`text-body font-medium text-danger-text`,children:i}),(0,B.jsxs)(G,{variant:`primary`,type:`submit`,loading:r,className:`min-h-10`,children:[(0,B.jsx)(lo,{className:`size-4`}),z(`emailCode`)]}),(0,B.jsxs)(`p`,{className:`text-center text-muted-foreground`,children:[z(`haveAccount`),` `,(0,B.jsx)(`button`,{type:`button`,onClick:t,className:`font-medium text-primary-text hover:underline`,children:z(`signIn`)})]})]}),n&&(0,B.jsx)(`button`,{type:`button`,onClick:n,className:`mt-4 w-full text-center font-medium text-muted-foreground hover:text-foreground hover:underline`,children:z(`browseWithoutAccount`)})]})},ZN=({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}=V(),[f,p]=(0,I.useState)(!1),[m,h]=(0,I.useState)(),[g,_]=(0,I.useState)(),v=async e=>{p(!0),h(void 0),_(void 0);try{await e()}catch(e){if(!(e instanceof ku))throw e;h(KA(e))}p(!1)};return t===void 0?(0,B.jsx)(XN,{workspace:e,busy:f,error:m,onSignIn:o,onBrowse:s,onSubmit:e=>void v(async()=>{await l(e),r(e)})}):n===void 0?(0,B.jsx)(JN,{email:t,busy:f,error:m,notice:g,onBack:a,onSubmit:e=>void v(async()=>i(await u(t,e))),onResend:()=>void v(async()=>{await l(t),_(z(`newCodeSent`))})}):(0,B.jsx)(YN,{email:t,methods:c,busy:f,error:m,onBack:a,onSubmit:e=>void v(()=>d({ticket:n,...e}))})},QN=`staff-sign-in`,$N=`staff-error`,eP=e=>{let t=new URL(e).searchParams,n=t.get($N);if(!t.has(`staff-sign-in`)&&!n)return;let r=t.has(QN);return{email:r&&t.get(`email`)||``,reason:r&&t.get(`reason`)||``,...n&&{error:n}}},tP=e=>{let t=new URL(e);if(t.searchParams.has(`staff-sign-in`))for(let e of[QN,`email`,`reason`])t.searchParams.delete(e);return t.searchParams.delete($N),`${t.pathname}${t.search}${t.hash}`},nP=10,rP=({operator:e,email:t=``,reason:n=``,onSubmit:r,onBack:i,busy:a,error:o})=>{let[s,c]=(0,I.useState)(t),[l,u]=(0,I.useState)(n);return e?(0,B.jsx)(vj,{title:z(`signInAsPerson`),description:z(`forStaffOf`,{operator:e}),children:(0,B.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),r(s.trim(),l.trim())},children:[(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[z(`theirEmail`),(0,B.jsx)(J,{type:`email`,name:`email`,required:!0,autoFocus:!t,value:s,onChange:e=>c(e.target.value),className:`min-h-6`})]}),(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[z(`reason`),(0,B.jsx)(`textarea`,{name:`reason`,required:!0,minLength:nP,rows:3,value:l,placeholder:z(`reasonExample`),onChange:e=>u(e.target.value),className:P(`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,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:z(`staffExplanation`,{operator:e})}),o&&(0,B.jsx)(`p`,{role:`alert`,className:`text-body font-medium text-danger-text`,children:o}),(0,B.jsx)(G,{variant:`primary`,type:`submit`,loading:a,className:`min-h-10`,children:z(`continueWith`,{name:e})}),(0,B.jsx)(G,{variant:`ghost`,onClick:i,className:`min-h-10`,children:z(`backToSignIn`)})]})}):(0,B.jsxs)(vj,{title:z(`staffTitle`),description:z(`staffUnavailable`),children:[o&&(0,B.jsx)(`p`,{role:`alert`,className:`mb-4 text-body font-medium text-danger-text`,children:o}),(0,B.jsx)(G,{variant:`primary`,className:`min-h-10 w-full`,onClick:i,children:z(`backToSignIn`)})]})},iP=({link:e,onBack:t})=>{let{session:n,staffSignIn:r}=V(),[i,a]=(0,I.useState)(!1),[o,s]=(0,I.useState)(e.error&&YA(e.error)),c=async(e,t)=>{a(!0),s(void 0);try{let r=`${window.location.origin}${tP(window.location.href)}`;window.location.assign(await n.staff.start({email:e,reason:t,callbackURL:r}))}catch(e){if(!(e instanceof ku))throw e;s(YA(e)),a(!1)}};return(0,B.jsx)(rP,{operator:r,email:e.email,reason:e.reason,busy:i,error:o,onBack:t,onSubmit:(e,t)=>void c(e,t)})},aP={totp:`totpInstruction`,otp:`otpInstruction`,backup:`backupInstruction`},oP=({methods:e,onVerify:t,onSendCode:n,onBack:r,busy:i,error:a,codeSent:o,initialStep:s})=>{let[c,l]=(0,I.useState)(s??(e.includes(`totp`)?`totp`:`otp`)),[u,d]=(0,I.useState)(``),[f,p]=(0,I.useState)(!1),m=c===`otp`&&!o,h=e=>{l(e),d(``),e===`otp`&&!o&&n()};return(0,B.jsxs)(vj,{title:z(`twoFactorTitle`),description:z(`twoFactorDescription`),children:[m?(0,B.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:z(`codeToFinish`)}),a&&(0,B.jsx)(`p`,{role:`alert`,className:`text-body font-medium text-danger-text`,children:a}),(0,B.jsx)(G,{variant:`primary`,loading:i,onClick:n,className:`min-h-10`,children:z(`emailCode`)})]}):(0,B.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),t({method:c,code:u.trim(),trustDevice:f})},children:[(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:z(aP[c],{minutes:10})}),(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[z(c===`backup`?`backupCode`:`code`),c===`backup`?(0,B.jsx)(J,{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,B.jsx)(E_,{name:`code`,required:!0,autoFocus:!0,value:u,invalid:!!a,onChange:d})]}),(0,B.jsxs)(`label`,{className:`flex items-center gap-2 text-muted-foreground`,children:[(0,B.jsx)(AC,{checked:f,onChange:p,label:z(`trustBrowser`)}),z(`trustBrowserFor`)]}),a&&(0,B.jsx)(`p`,{role:`alert`,className:`text-body font-medium text-danger-text`,children:a}),(0,B.jsx)(G,{variant:`primary`,type:`submit`,loading:i,className:`min-h-10`,children:z(`verify`)})]}),(0,B.jsxs)(`div`,{className:`mt-4 flex flex-col items-center gap-2 border-t pt-4`,children:[c!==`totp`&&e.includes(`totp`)&&(0,B.jsx)(`button`,{type:`button`,onClick:()=>h(`totp`),className:`font-medium text-primary-text hover:underline`,children:z(`useAuthenticator`)}),c!==`otp`&&e.includes(`otp`)&&(0,B.jsx)(`button`,{type:`button`,onClick:()=>h(`otp`),className:`font-medium text-primary-text hover:underline`,children:z(`emailCodeInstead`)}),c!==`backup`&&e.includes(`totp`)&&(0,B.jsx)(`button`,{type:`button`,onClick:()=>h(`backup`),className:`font-medium text-primary-text hover:underline`,children:z(`useBackupCode`)}),(0,B.jsx)(`button`,{type:`button`,onClick:r,className:`font-medium text-muted-foreground hover:underline`,children:z(`backToSignIn`)})]})]})},sP=({methods:e,onBack:t})=>{let{verifyTwoFactor:n,session:r}=V(),[i,a]=(0,I.useState)(!1),[o,s]=(0,I.useState)(),[c,l]=(0,I.useState)(!1),u=async e=>{a(!0),s(void 0);try{await e()}catch(e){if(!(e instanceof ku))throw e;s(KA(e))}a(!1)};return(0,B.jsx)(oP,{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)})})},cP=e=>{let t=new URL(e),n=t.searchParams.get(`token`);return t.pathname.endsWith(`/-/invitation`)&&n?{token:n}:void 0},lP=e=>`${new URL(e).pathname.slice(0,-13)}/`,uP=({token:e,preview:t,joins:n,onDone:r})=>{let{session:i,signInMethods:a,recheck:o}=V(),[s,c]=(0,I.useState)(``),[l,u]=(0,I.useState)(``),{busy:d,error:f,run:p}=QA(),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,B.jsxs)(`form`,{className:`flex flex-col gap-3`,onSubmit:e=>{e.preventDefault(),g()},children:[(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:X(n?`makeAccountToJoin`:`makeAccount`,{email:t.email})}),f&&(0,B.jsx)(`p`,{role:`alert`,className:`text-body font-medium text-danger-text`,children:f}),(0,B.jsx)(J,{"aria-label":X(`yourName`),placeholder:X(`yourName`),autoComplete:`name`,value:s,onChange:e=>c(e.target.value)}),m&&(0,B.jsx)(J,{"aria-label":X(`password`),type:`password`,autoComplete:`new-password`,placeholder:X(h?`passwordOptional`:`passwordRequired`,{length:12}),value:l,onChange:e=>u(e.target.value)}),(0,B.jsx)(G,{type:`submit`,variant:`primary`,loading:d,disabled:!s.trim()||m&&!h&&l.length<12,children:X(n?`createAndJoin`:`createYourAccount`)})]})},dP=({token:e,onDone:t,signIn:n})=>{let{session:r,state:i,signOut:a,organizations:o}=V(),[s,c]=(0,I.useState)(),[l,u]=(0,I.useState)(),{busy:d,error:f,run:p}=QA();if((0,I.useEffect)(()=>{r.organizations.invitation(e).then(c,e=>u(e instanceof ku?KA(e):X(`invalidLink`)))},[r,e]),l)return(0,B.jsx)(vj,{title:X(`invitation`),description:l,children:(0,B.jsx)(G,{className:`w-full`,onClick:t,children:X(`goToApp`)})});if(!s)return(0,B.jsx)(vj,{title:X(`invitation`),children:(0,B.jsxs)(`div`,{className:`flex items-center justify-center gap-2 text-muted-foreground`,children:[(0,B.jsx)(af,{}),` `,X(`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=X(`invitesToApp`,{inviter:s.inviter.name,app:r});return(0,B.jsx)(vj,{title:X(`join`,{name:r}),description:i,children:s.hasAccount?m&&h?(0,B.jsx)(G,{variant:`primary`,className:`w-full`,onClick:t,children:X(`goToApp`)}):(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`p`,{className:`mb-3 text-muted-foreground`,children:X(`hasAccount`,{email:s.email})}),m?(0,B.jsx)(G,{className:`w-full`,onClick:()=>void a(),children:X(`signOut`)}):(0,B.jsx)(Dh,{to:n,className:P(yf({variant:`primary`}),`w-full`),children:X(`signInAs`,{email:s.email})})]}):m?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`p`,{className:`mb-3 text-muted-foreground`,children:X(`otherAddress`,{invited:s.email,signedIn:m.email})}),(0,B.jsx)(G,{className:`w-full`,onClick:()=>void a(),children:X(`signOutToAccept`)})]}):(0,B.jsx)(uP,{token:e,preview:s,joins:!1,onDone:t})})}let g=s.organization,_=s.appRoles.map(e=>dj(o?.roles??[],e)),v=uj(s.role).toLowerCase(),y=_.length>0?X(`invitesToWith`,{inviter:s.inviter.name,organization:g.name,role:v,roles:_.join(`, `)}):X(`invitesTo`,{inviter:s.inviter.name,organization:g.name,role:v});return m&&!h?(0,B.jsxs)(vj,{title:X(`join`,{name:g.name}),description:y,children:[(0,B.jsx)(`p`,{className:`mb-3 text-muted-foreground`,children:X(`otherAddress`,{invited:s.email,signedIn:m.email})}),(0,B.jsx)(G,{className:`w-full`,onClick:()=>void a(),children:X(`signOutToAccept`)})]}):(0,B.jsx)(vj,{title:X(`join`,{name:g.name}),description:y,children:m?(0,B.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[f&&(0,B.jsx)(`p`,{role:`alert`,className:`text-body font-medium text-danger-text`,children:f}),(0,B.jsx)(G,{variant:`primary`,className:`w-full`,loading:d,onClick:()=>void p(async()=>{await r.organizations.accept(e),t()}),children:X(`join`,{name:g.name})})]}):s.hasAccount?(0,B.jsx)(Dh,{to:n,className:P(yf({variant:`primary`}),`w-full`),children:X(`signInAsToJoin`,{email:s.email})}):(0,B.jsx)(uP,{token:e,preview:s,joins:!0,onDone:t})})},fP=/^[A-Z][A-Za-z0-9]*$/,pP=e=>typeof e==`function`||typeof e==`object`&&!!e&&`$$typeof`in e,mP=e=>{let t=e.default??{},n=Object.entries(e).filter(e=>e[0]!=="default"&&fP.test(e[0])&&pP(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)}}},hP=class extends Error{name=`UiConflictError`},gP=e=>Object.keys(e).some(e=>e==="default"||/^[A-Z]/.test(e))?mP(e):e,_P=(e,t)=>[...(e.extends??[]).map(gP).flatMap((e,n)=>_P(e,e.name??`${t} extends[${n}]`)),{ui:e,label:t}],vP=(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 hP(`${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},yP=e=>e.length<=1?e[0]:()=>e.map((e,t)=>(0,B.jsx)(e,{},t)),bP=e=>e.length<=1?e[0]:({children:t,...n})=>e.reduceRight((e,t)=>(0,B.jsx)(t,{...n,children:e}),t),xP=(...e)=>{let t=e.flatMap((e,t)=>_P(e,e.name??`UI config ${t+1}`)),n=vP(`The component`,t,e=>e.components),r=vP(`The action handler`,t,e=>e.actions),i=vP(`The field type`,t,e=>e.fields),a=vP(`The drop rule`,t,e=>e.dropRules),o=vP(`The board drop`,t,e=>e.boardDrops),s=vP(`The title rule`,t,e=>e.titles),c=vP(`The marks hook`,t,e=>e.marks),l=yP(t.flatMap(({ui:e})=>e.shell?.actions?[e.shell.actions]:[])),u=yP(t.flatMap(({ui:e})=>e.shell?.rightPanel?[e.shell.rightPanel]:[])),d=t.findLast(({ui:e})=>e.shell?.logo)?.ui.shell?.logo,f=t.findLast(({ui:e})=>e.shell?.bell)?.ui.shell?.bell,p=t.findLast(({ui:e})=>e.presence)?.ui.presence,m=bP(t.flatMap(({ui:e})=>e.beforeSignIn?[e.beforeSignIn]:[])),h=e.at(-1)?.name;return{...h&&{name:h},components:n,actions:r,...Object.keys(i).length>0&&{fields:i},...Object.keys(a).length>0&&{dropRules:a},...Object.keys(o).length>0&&{boardDrops:o},...Object.keys(s).length>0&&{titles:s},...Object.keys(c).length>0&&{marks:c},...(l||u||d||f)&&{shell:{...l&&{actions:l},...u&&{rightPanel:u},...d&&{logo:d},...f&&{bell:f}}},...p&&{presence:p},...m&&{beforeSignIn:m}}},SP=(e,t)=>{let n=xP(e??{}),r=[],i=[];for(let e of t){if(e.kind===`off`){i.push(e);continue}try{xP(...r,e.ui,n),r.push(e.ui)}catch(t){if(!(t instanceof hP))throw t;i.push({kind:`off`,url:e.plugin.url,name:e.plugin.name,reason:t.message})}}return{ui:r.length===0?n:xP(...r,n),off:i}},CP=M(`plugins`),wP=e=>typeof e==`string`&&e.trim()!==``,TP=e=>{if(typeof e!=`object`||!e||Array.isArray(e))return{problem:CP(`notObject`)};let{name:t,version:n,api:r,protobase:i,entry:a,css:o}=e;return wP(t)?Number.isInteger(r)?wP(i)?wP(a)?o!==void 0&&!wP(o)?{problem:CP(`badStylesheet`)}:n!==void 0&&!wP(n)?{problem:CP(`badVersion`)}:{manifest:{name:t,api:r,protobase:i,entry:a,...n!==void 0&&{version:n},...o!==void 0&&{css:o}}}:{problem:CP(`noModule`)}:{problem:CP(`noVersions`)}:{problem:CP(`noApi`)}:{problem:CP(`noName`)}},EP=(0,I.createContext)(null),DP=EP.Provider,OP=()=>{let e=(0,I.useContext)(EP);if(!e)throw Error(`usePlugin is for the components of a plugin the app loaded`);return e},kP=(e,t,n)=>{let r=n=>(0,B.jsx)(DP,{value:e,children:(0,B.jsx)(t,{...n})});return r.displayName=`${e.name}:${n}`,r},AP=(e,t,n)=>({of:n.of,display:kP(e,n.display,`fields.${t}.display`),...n.editor&&{editor:kP(e,n.editor,`fields.${t}.editor`)},...n.cell&&{cell:kP(e,n.cell,`fields.${t}.cell`)}}),jP=(e,t)=>{let n=xP({...mP(t),name:e.name}),r=Object.fromEntries(Object.entries(n.components??{}).map(([t,n])=>[t,kP(e,n,t)])),i=n.fields&&Object.fromEntries(Object.entries(n.fields).map(([t,n])=>[t,AP(e,t,n)])),a=n.shell&&{...n.shell.actions&&{actions:kP(e,n.shell.actions,`shell.actions`)},...n.shell.rightPanel&&{rightPanel:kP(e,n.shell.rightPanel,`shell.rightPanel`)},...n.shell.logo&&{logo:kP(e,n.shell.logo,`shell.logo`)},...n.shell.bell&&{bell:kP(e,n.shell.bell,`shell.bell`)}},o=n.beforeSignIn&&kP(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&&{shell:a},...o&&{beforeSignIn:o}}},MP={name:`@protobase/ui`,version:`0.66.7`,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`},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`},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:*`,"@sentry/browser":`^11.7.0`,"@tanstack/react-query":`^5.104.1`,"@tanstack/react-table":`^9.2.6`,"altcha-lib":`^2.6.0`,dompurify:`^3.4.17`,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`}},NP=MP.protobase.pluginApi,PP=MP.version,FP={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=>Ve(()=>import(e),[])},IP={api:NP,version:PP},LP=e=>e instanceof Error?e.message:String(e),RP=async(e,t,n,r=IP)=>{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(CP(`answered`,{status:n.status}));let s=TP(n.json);if(`problem`in s)return a(s.problem);let{manifest:c}=s;o=c.name;let l=Ln(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:jP(d,u)}}catch(e){return a(CP(`couldNotLoad`,{reason:LP(e)}),o)}},zP=e=>{let t=new Map;return{load:n=>{let r=JSON.stringify(n),i=t.get(r);if(i)return i;let a=RP(n,e,window.location.href);return t.set(r,a),a}}},BP=(0,I.createContext)(null),VP=({loader:e=FP,children:t})=>{let n=(0,I.useMemo)(()=>zP(e),[e]);return(0,B.jsx)(BP.Provider,{value:n,children:t})},HP=()=>{let e=(0,I.useContext)(BP);if(!e)throw Error(`usePluginSource must be used inside PluginSourceProvider`);return e},UP=1e4,WP=[],GP=(e,t)=>{let n=JSON.stringify(e),[r,i]=(0,I.useState)({key:`[]`,loads:WP,settled:!0});return(0,I.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()},UP);return e.forEach((e,n)=>{t.load(e).then(e=>{o[n]=e,s()})}),()=>{r=!1,clearTimeout(c)}},[n,t]),e.length===0?{loads:WP,settled:!0}:r.key===n?r:{loads:WP,settled:!1}},KP=({children:e})=>{let{state:t,beforeSignIn:n,adoptSession:r}=V(),{path:i,params:a,navigate:o}=Ih(),{loads:s,settled:c}=GP(n,HP()),l=(0,I.useMemo)(()=>SP(void 0,s).ui.beforeSignIn,[s]),u=(0,I.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,B.jsx)(pv,{name:`beforeSignIn`,fallback:e,children:(0,B.jsx)(l,{signedIn:r,params:a,removeParams:u,children:e})}):e:(0,B.jsxs)(`div`,{className:`flex h-full min-h-48 items-center justify-center gap-2 text-muted-foreground`,children:[(0,B.jsx)(af,{}),` `,CP(`loading`)]})},qP=()=>{let e=window.location.href,t=NN(e);if(t)return{kind:`reset-password`,token:t.token};let n=eP(e);if(n)return{kind:`staff-sign-in`,link:n};let r=cP(e);if(r)return{kind:`invitation`,token:r.token};let i=Dd(e);if(i)return{kind:`provider-sign-in`,provider:i};let a=Od(e);return a?{kind:`sign-in`,providerError:a}:{kind:`sign-in`}},JP=({to:e})=>{let{navigate:t}=Ih();return(0,I.useEffect)(()=>t(e,{replace:!0}),[t,e]),null},YP=({workspace:e,children:t})=>{let n=XP(e,t);return(0,B.jsx)(KP,{children:n})},XP=(e,t)=>{let{state:n,recheck:r,passwordReset:i,signOut:a,signInProviders:o,canSignUp:s,browse:c}=V(),{path:l,params:u,basePath:d,navigate:f}=Ih(),{address:p,next:m,open:h,link:g,leave:_}=oE(),[v,y]=(0,I.useState)(qP),[b,x]=(0,I.useState)(),[S,C]=(0,I.useState)(),[w,T]=(0,I.useState)(),E=new URL(`${d}${l}${u.size>0?`?${u}`:``}`,window.location.origin).href,D=(0,I.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`;(0,I.useEffect)(()=>{O&&(v.kind===`provider-sign-in`&&D(kd),(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,D]);let k=p!==void 0&&Od(E)!==void 0;(0,I.useEffect)(()=>{!O&&v.kind===`sign-in`&&v.providerError&&k&&D(kd)},[O,v,k,D]);let A=(0,I.useCallback)(e=>y({kind:`sign-in`,error:e}),[]),j=e=>{D(PN),y(e)},ee=async()=>{n.kind===`signed-in`&&await a(),j({kind:`sign-in`,notice:z(`passwordChanged`)})},te=()=>{y({kind:`sign-in`}),a().then(()=>h(`sign-in`,{replace:!0}))};switch(n.kind){case`loading`:return(0,B.jsxs)(`div`,{className:`flex h-full min-h-48 items-center justify-center gap-2 text-muted-foreground`,children:[(0,B.jsx)(af,{}),` `,z(`loading`)]});case`error`:return(0,B.jsxs)(`div`,{className:`flex h-full min-h-48 flex-col items-center justify-center gap-3 p-8 text-center`,children:[(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:z(`cannotReach`,{message:n.message})}),(0,B.jsx)(G,{onClick:r,children:z(`tryAgain`)})]});case`needs-admin`:return(0,B.jsx)(DN,{firstAdminUrl:n.firstAdminUrl,onCheckAgain:r})}if(n.kind===`signed-in`&&p)return(0,B.jsx)(JP,{to:m??`/`});if(v.kind===`reset-password`)return(0,B.jsx)(zN,{token:v.token,onDone:()=>void ee(),onRequestNewLink:i?()=>{y({kind:`sign-in`}),f($c({step:`forgot-password`}),{replace:!0})}:void 0,onBack:()=>j({kind:`sign-in`})});if(v.kind===`staff-sign-in`)return(0,B.jsx)(iP,{link:v.link,onBack:()=>{D(tP),y({kind:`sign-in`})}});let ne=n.kind===`signed-out`||n.kind===`visitor`;if(v.kind===`invitation`&&(n.kind===`signed-in`||ne&&!p))return(0,B.jsx)(dP,{token:v.token,onDone:()=>{D(lP),y({kind:`sign-in`})},signIn:g()});if(n.kind===`signed-in`)return t;if(n.kind===`two-factor`)return(0,B.jsx)(sP,{methods:n.methods,onBack:te});if(n.kind===`setup-required`)return(0,B.jsx)(HN,{missing:n.missing},n.missing.join());if(v.kind===`provider-sign-in`)return(0,B.jsx)(LN,{provider:v.provider,workspace:e,onFailed:A});let re=v.kind===`sign-in`?v:{kind:`sign-in`};if(!p){let e=re.notice||re.error||re.providerError;return n.kind===`visitor`&&!e?t:(0,B.jsx)(JP,{to:$c({next:m})})}let ie={"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`,ae=e=>()=>h(e,{replace:!0}),oe=c&&(()=>{c(),_()});if(ie===`forgot-password`)return(0,B.jsx)(FN,{back:g(`sign-in`,{replace:!0})});if(ie===`email-code`)return(0,B.jsx)(TN,{email:b,onBack:ae(`sign-in`)});if(ie===`sign-up`||ie===`sign-up-code`||ie===`sign-up-details`)return(0,B.jsx)(ZN,{workspace:e,email:ie===`sign-up`?void 0:S,ticket:ie===`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:ae(`sign-up`),onSignIn:()=>h(`sign-in`),onBrowse:oe},ie);let se=re.providerError&&ZA(re.providerError,o.length===1?o[0].name:`the provider`),ce=re.error??se;return(0,B.jsx)(qN,{workspace:e,notice:re.notice,error:ce,forgotPassword:i?g(`forgot-password`):void 0,onCodeSent:e=>{x(e),h(`email-code`)},signUp:s?g(`sign-up`):void 0,onBrowse:oe},ce)},ZP=3e4,QP=(e,t=Date.now())=>Math.max(1e3,$u(e)-t-ZP),$P=()=>{let{state:e,session:t}=V(),n=e.kind===`signed-in`,[r,i]=(0,I.useState)();return(0,I.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),QP(s))))};return a(),()=>{e=!1,clearTimeout(r)}},[t,n]),n?r:void 0},eF=({children:e})=>(0,B.jsx)(nf,{locale:V().locale,children:e}),tF=(e,t)=>{let n=new Set,r,i=()=>{r=void 0;let i=new Set(n);n.clear();let a=e=>i.has(e[1]);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)}},nF=e=>{let t=U(),n=Se(),r=(0,I.useContext)(Id),i=(0,I.useMemo)(()=>Object.values(e.resources).filter(t=>t.live&&!tf(e,t.name)).map(e=>e.name).sort().join(`,`),[e]);(0,I.useEffect)(()=>{if(!i)return;let e=tF(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])},rF=(e,t,n=!0)=>{let r=U(),i=Nn(t);return E({queryKey:H.record(e,i),enabled:n,queryFn:()=>r.get(e,t)})},iF=(e,t,n=!0)=>{let r=U(),i=Se(),a=Nn(t);return E({queryKey:H.record(e,a),enabled:n,queryFn:()=>r.get(e,t),placeholderData:()=>i.getQueryData(H.recordPreview(e,a))})},aF=M(`forms`),oF=async(e,t)=>{let n=await e.formChallenge(t),r=await _e({challenge:n,deriveKey:De});if(!r)throw Error(aF(`checkTooLong`));return{challenge:n,solution:{counter:r.counter,derivedKey:r.derivedKey}}},sF=({name:e})=>{let t=U(),n=E({queryKey:H.publicForm(e),queryFn:()=>t.form(e)});return n.isPending?(0,B.jsxs)(`div`,{className:`flex h-full min-h-48 items-center justify-center gap-2 text-muted-foreground`,children:[(0,B.jsx)(af,{}),` `,aF(`loading`)]}):n.error?ml(n.error)&&n.error.status===404?(0,B.jsx)(sf,{title:aF(`notFound`),children:aF(`noForm`)}):(0,B.jsx)(sf,{title:of(`cannotReach`),children:ml(n.error)?n.error.message:of(`noAnswer`)}):(0,B.jsx)(cF,{form:n.data})},cF=({form:e})=>{let t=U(),{resource:n,view:r}=e,i=e.title??r.names?.singular??F(r.resource);BM(i);let[a,o]=(0,I.useState)(()=>Hg(n,[{title:i,fields:e.fields}])),[s,c]=(0,I.useState)({}),[l,u]=(0,I.useState)(),[d,f]=(0,I.useState)(!1),[p,m]=(0,I.useState)(!1),[h,g]=(0,I.useState)(0),_=fx(h);if(p)return(0,B.jsx)(vj,{title:i,size:`md`,children:(0,B.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,Lg(n,{},a),await oF(t,e.name)),m(!0)}catch(e){let t=ux(e);c(t),Object.keys(t).length>0?g(e=>e+1):u(e)}finally{f(!1)}};return(0,B.jsx)(vj,{title:i,size:`md`,children:(0,B.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??F(e),c=s[e];return(0,B.jsx)(eg,{name:e,label:o,help:i?.help,required:Rg(t),error:c&&lx(t,o,c),children:(0,B.jsx)(Nv,{field:t,hints:i,value:a[e]??(t.type!==`boolean`&&``),stored:void 0,placeholder:Ug(t)?aF(`setByDatabase`):Vg(t),invalid:!!c,onChange:t=>v(e,t)})},e)}),l!==void 0&&(0,B.jsx)(Gg,{title:aF(`notSent`),error:l}),(0,B.jsx)(G,{variant:`primary`,type:`submit`,loading:d,className:`min-h-10`,children:aF(`send`)})]})})},lF=()=>{let{path:e}=Ih();return(0,I.useMemo)(()=>xn(e),[e])},Z=M(`calls`),uF=(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)},dF=({track:e,...t})=>{let n=(0,I.useCallback)(t=>t?uF(t,e):void 0,[e]);return(0,B.jsx)(`video`,{ref:n,autoPlay:!0,playsInline:!0,muted:!0,...t})},fF=({track:e})=>{let t=(0,I.useCallback)(t=>t?uF(t,e):void 0,[e]);return(0,B.jsx)(`audio`,{ref:t,autoPlay:!0})},pF=e=>P(`size-10 rounded-full`,!e&&`bg-danger-soft text-danger-text`),mF=({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=Z(`joinCall`)})=>(0,B.jsxs)(`section`,{"aria-label":Z(`preview`),className:`flex size-full min-h-0 flex-col items-center justify-center gap-3 bg-background p-4`,children:[(0,B.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,B.jsx)(dF,{track:n,"aria-label":Z(`preview`),className:`size-full -scale-x-100 object-cover`}):(0,B.jsx)(Vf,{initials:V_(e),hue:B_(t),size:`md`,className:`size-16 text-xl ring-0`})}),s.length>0&&(0,B.jsx)(`div`,{role:`status`,className:`flex w-full max-w-md flex-col gap-1`,children:s.map(e=>(0,B.jsx)(`p`,{className:`rounded-md bg-warning-soft px-3 py-1.5 text-xs text-foreground`,children:e},e))}),(0,B.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,B.jsx)(G,{size:`icon`,"aria-label":Z(`microphone`),"aria-pressed":r,disabled:!a,className:pF(r),onClick:c,children:r?(0,B.jsx)(bo,{className:`size-4`}):(0,B.jsx)(vo,{className:`size-4`})}),(0,B.jsx)(G,{size:`icon`,"aria-label":Z(`camera`),"aria-pressed":i,disabled:!o,className:pF(i),onClick:l,children:i?(0,B.jsx)(uc,{className:`size-4`}):(0,B.jsx)(cc,{className:`size-4`})}),(0,B.jsx)(G,{variant:`primary`,className:`h-10 rounded-full px-5`,onClick:u,children:f}),(0,B.jsx)(Dh,{to:d,className:`px-2 text-sm text-muted-foreground hover:text-foreground`,children:Z(`leave`)})]})]}),hF=()=>{let[e,t]=(0,I.useState)(!1);return{run:(0,I.useCallback)(e=>{t(!1),(async()=>{let{GuestRefused:n}=await Ve(async()=>{let{GuestRefused:e}=await import(`./calls-uuSb7D6L.js`);return{GuestRefused:e}},[]);await e().catch(e=>{if(!(e instanceof n))throw e;t(!0)})})()},[]),refused:e}},gF={all:[`camera`,`microphone`,`screen`,`screen-audio`],camera:[`camera`,`microphone`],microphone:[`microphone`]},_F={call:void 0,hour:36e5},vF=({name:e,children:t})=>(0,B.jsxs)(`li`,{className:`flex items-center justify-between gap-2 py-1.5`,children:[(0,B.jsx)(`span`,{className:`min-w-0 truncate text-sm text-foreground`,children:e}),(0,B.jsx)(`span`,{className:`flex shrink-0 gap-1.5`,children:t})]}),yF=({lobby:e,inCall:t,guests:n,linkOf:r,open:i,onClose:a})=>{let[o,s]=(0,I.useState)(`camera`),[c,l]=(0,I.useState)(`call`),[u,d]=(0,I.useState)(),[f,p]=(0,I.useState)(!1),{run:m,refused:h}=hF(),g=()=>m(async()=>{let e=_F[c],{link:t,token:i}=await n.link({publish:gF[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,B.jsx)(jf,{title:Z(`guests`),description:Z(`addressesVisible`),open:i,onClose:a,actions:(0,B.jsx)(G,{onClick:a,children:Z(`close`)}),children:(0,B.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[h&&(0,B.jsx)(`p`,{role:`alert`,className:`rounded-md bg-warning-soft px-3 py-1.5 text-xs text-foreground`,children:Z(`guestRefused`)}),e.guests.length>0&&(0,B.jsxs)(`section`,{"aria-label":Z(`inLobby`),children:[(0,B.jsx)(`h3`,{className:`text-xs font-medium text-muted-foreground`,children:Z(`inLobby`)}),(0,B.jsx)(`ul`,{children:e.guests.map(({guest:e,name:t})=>(0,B.jsxs)(vF,{name:t,children:[(0,B.jsx)(G,{size:`sm`,variant:`primary`,onClick:()=>m(()=>n.admit(e)),children:Z(`admit`)}),(0,B.jsx)(G,{size:`sm`,onClick:()=>m(()=>n.deny(e)),children:Z(`deny`)})]},e))})]}),t.length>0&&(0,B.jsxs)(`section`,{"aria-label":Z(`guestsInCall`),children:[(0,B.jsx)(`h3`,{className:`text-xs font-medium text-muted-foreground`,children:Z(`guestsInCall`)}),(0,B.jsx)(`ul`,{children:t.map(({guest:e,name:t})=>(0,B.jsx)(vF,{name:t,children:(0,B.jsx)(G,{size:`sm`,variant:`danger`,onClick:()=>m(()=>n.remove(e)),children:Z(`remove`)})},e))})]}),(0,B.jsxs)(`section`,{"aria-label":Z(`guestLinks`),className:`flex flex-col gap-2`,children:[(0,B.jsx)(`h3`,{className:`text-xs font-medium text-muted-foreground`,children:Z(`guestLinks`)}),e.links.length===0&&(0,B.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:Z(`noLinks`)}),(0,B.jsx)(`ul`,{children:e.links.map(e=>(0,B.jsxs)(`li`,{className:`flex flex-col gap-1.5 py-1.5`,children:[u?.id===e.id&&(0,B.jsx)(J,{readOnly:!0,value:u.url,"aria-label":Z(`copyLink`),onFocus:e=>e.currentTarget.select(),trailing:(0,B.jsx)(`button`,{type:`button`,"aria-label":Z(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,B.jsx)(Ci,{className:`size-4 text-success`}):(0,B.jsx)(Yi,{className:`size-4`})})}),(0,B.jsxs)(`span`,{className:`flex items-center justify-between gap-2 text-xs text-muted-foreground`,children:[e.expires_at?Z(`linkUntil`,{until:new Date(e.expires_at).toLocaleString()}):Z(`linkUntilEnd`),(0,B.jsx)(G,{size:`sm`,onClick:()=>m(()=>n.revoke(e.id)),children:Z(`revoke`)})]})]},e.id))}),(0,B.jsxs)(`div`,{className:`flex flex-col items-start gap-2`,children:[(0,B.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2 text-xs text-muted-foreground`,children:[Z(`guestsMaySend`),(0,B.jsx)(Re,{label:Z(`guestsMaySend`),value:o,onChange:s,options:[{value:`all`,label:Z(`sendAll`)},{value:`camera`,label:Z(`sendCamera`)},{value:`microphone`,label:Z(`sendMicrophone`)}]})]}),(0,B.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2 text-xs text-muted-foreground`,children:[Z(`linkLasts`),(0,B.jsx)(Re,{label:Z(`linkLasts`),value:c,onChange:l,options:[{value:`call`,label:Z(`linkUntilEnd`)},{value:`hour`,label:Z(`forAnHour`)}]})]}),(0,B.jsx)(G,{variant:`primary`,onClick:g,children:Z(`newLink`)})]})]})]})})},bF=({waiting:e,guests:t})=>{let{run:n,refused:r}=hF(),i=e[0];return i?(0,B.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,B.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:r?Z(`guestRefused`):Z(`waitingGuest`,{name:i.name})}),(0,B.jsx)(G,{size:`sm`,variant:`primary`,onClick:()=>n(()=>t.admit(i.guest)),children:Z(`admit`)}),(0,B.jsx)(G,{size:`sm`,onClick:()=>n(()=>t.deny(i.guest)),children:Z(`deny`)})]}):null},xF={ended:`ended`,removed:`removed`,full:`full`,refused:`refused`,unavailable:`unavailable`,denied:`denied`},SF=({reason:e,onJoinAgain:t})=>(0,B.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,B.jsx)(`p`,{className:`text-sm text-foreground`,children:Z(e===`rejoin`?`ended`:xF[e])}),t&&e!==`removed`&&e!==`refused`&&e!==`denied`&&(0,B.jsx)(G,{onClick:t,children:Z(`callAgain`)})]}),CF=(e,t)=>t<640?e<=2?1:2:Math.min(4,Math.ceil(Math.sqrt(e))),wF=({people:e,sharers:t,width:n})=>t[0]===void 0?e<=1?{kind:`alone`}:{kind:`grid`,columns:CF(e,n)}:{kind:`share`,sharer:t[0]},TF=({roundTripMs:e,lostRatio:t})=>(e??0)>400||(t??0)>.05?`poor`:`good`,EF=(e,t,n)=>e===`failed`||e!==`connected`&&n-t>=15e3,DF=(e,t=.05)=>{let n;for(let[r,i]of e)i>=t&&(!n||i>n[1])&&(n=[r,i]);return n?.[0]},OF=(e,t)=>e.find(e=>e.source===t&&e.track),kF=({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:`)?Z(`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=>OF(d,e)),g=o.find(t=>t.member===e),_=EF(g?.state,s.get(e)??c,c)?`failed`:g?.state===`connected`?TF(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:_}}}),AF=e=>P(`size-10 rounded-full`,!e&&`bg-danger-soft text-danger-text`),jF=({microphoneOn:e,cameraOn:t,sharing:n,onMicrophone:r,onCamera:i,onShare:a,guests:o,leave:s})=>(0,B.jsxs)(`div`,{role:`toolbar`,"aria-label":Z(`joinCall`),className:`flex shrink-0 flex-wrap items-center justify-center gap-2 py-2`,children:[(0,B.jsx)(G,{size:`icon`,"aria-label":Z(`microphone`),"aria-pressed":e,title:Z(`microphone`),className:AF(e),onClick:r,children:e?(0,B.jsx)(bo,{className:`size-4`}):(0,B.jsx)(vo,{className:`size-4`})}),(0,B.jsx)(G,{size:`icon`,"aria-label":Z(`camera`),"aria-pressed":t,title:Z(`camera`),className:AF(t),onClick:i,children:t?(0,B.jsx)(uc,{className:`size-4`}):(0,B.jsx)(cc,{className:`size-4`})}),a&&(0,B.jsx)(G,{size:`icon`,"aria-label":Z(n?`stopSharing`:`shareScreen`),"aria-pressed":!!n,title:Z(n?`stopSharing`:`shareScreen`),className:`size-10 rounded-full`,onClick:a,children:n?(0,B.jsx)(Eo,{className:`size-4`}):(0,B.jsx)(wo,{className:`size-4`})}),o&&(0,B.jsxs)(G,{size:`icon`,"aria-label":Z(`guests`),title:Z(`guests`),className:`relative size-10 rounded-full`,onClick:o.onOpen,children:[(0,B.jsx)(ec,{className:`size-4`}),(0,B.jsx)(eS,{count:o.waiting,className:`absolute -top-1 -right-1`})]}),(0,B.jsxs)(Dh,{to:s,className:P(yf({variant:`danger`}),`h-10 rounded-full px-4`),children:[(0,B.jsx)(Ho,{className:`size-4`}),Z(`leave`)]})]}),MF=({person:e,screen:t=!1,className:n})=>{let r=t?e.screen:e.cameraOff?void 0:e.camera,i=t?e.self?Z(`youAreSharing`):Z(`sharing`,{name:e.name}):e.self?`${e.name} (${Z(`you`)})`:e.name;return(0,B.jsxs)(`figure`,{"data-member":e.member,"data-speaking":e.speaking?`true`:void 0,"aria-label":i,className:P(`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,B.jsx)(dF,{track:r,className:P(`size-full`,t?`object-contain`:`object-cover`,e.self&&!t&&`-scale-x-100`)}):(0,B.jsx)(Vf,{initials:V_(e.name),hue:B_(e.member),size:`md`,className:`size-16 text-xl ring-0`}),e.connection===`failed`&&!e.self&&(0,B.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:Z(`cannotConnect`,{name:e.name})}),(0,B.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,B.jsx)(vo,{role:`img`,"aria-label":Z(`muted`),className:`size-3 shrink-0`}),!t&&e.connection===`poor`&&(0,B.jsx)(gc,{role:`img`,"aria-label":Z(`poorConnection`),className:`size-3 shrink-0 text-warning`}),(0,B.jsx)(`span`,{className:`truncate`,children:i})]})]})},NF=()=>{let[e,t]=(0,I.useState)(0);return{ref:(0,I.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}},PF=4,FF=({people:e,columns:t})=>(0,B.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,B.jsx)(MF,{person:e},e.member))}),IF=({people:e,sharer:t,narrow:n})=>{let r=e.slice(0,PF),i=e.length-r.length;return(0,B.jsxs)(`div`,{className:P(`flex size-full min-h-0 gap-2`,n?`flex-col`:`flex-row`),children:[(0,B.jsx)(MF,{person:t,screen:!0,className:`min-h-0 flex-1`}),(0,B.jsxs)(`div`,{className:P(`flex shrink-0 gap-2`,n?`h-20 flex-row`:`w-40 flex-col`),children:[r.map(e=>(0,B.jsx)(MF,{person:e,className:n?`aspect-video h-full`:`aspect-video w-full`},e.member)),i>0&&(0,B.jsxs)(`p`,{className:`flex items-center justify-center rounded-lg bg-muted px-2 text-xs text-muted-foreground`,children:[`+`,i]})]})]})},LF=({layout:e,people:t,narrow:n})=>e.kind===`share`?(0,B.jsx)(IF,{people:t,sharer:t.find(t=>t.member===e.sharer),narrow:n}):e.kind===`grid`?(0,B.jsx)(FF,{people:t,columns:e.columns}):(0,B.jsxs)(`div`,{className:`relative size-full min-h-0`,children:[(0,B.jsx)(MF,{person:t[0],className:`size-full`}),(0,B.jsx)(`p`,{className:`absolute inset-x-0 top-3 text-center text-sm text-white drop-shadow`,children:Z(`alone`)})]}),RF=({people:e,state:t,notices:n=[],controls:r,aside:i,children:a,className:o})=>{let{ref:s,width:c}=NF(),l=c>0&&c<640,u=wF({people:e.length,sharers:e.filter(e=>e.screen).map(e=>e.member),width:c}),d=[...t===`resuming`?[Z(`reconnecting`)]:[],...n];return(0,B.jsxs)(`section`,{ref:s,"aria-label":Z(`joinCall`),"data-layout":u.kind,className:P(`flex size-full min-h-0 flex-col gap-2 bg-background p-2`,o),children:[d.length>0&&(0,B.jsx)(`div`,{role:`status`,className:`flex shrink-0 flex-col gap-1`,children:d.map(e=>(0,B.jsxs)(`p`,{className:`flex items-center gap-2 rounded-md bg-warning-soft px-3 py-1.5 text-xs text-foreground`,children:[e===Z(`reconnecting`)&&(0,B.jsx)(af,{className:`size-3`}),e]},e))}),i,(0,B.jsx)(`div`,{className:`min-h-0 flex-1`,children:t===`joining`?(0,B.jsxs)(`p`,{role:`status`,className:`flex size-full items-center justify-center gap-2 text-muted-foreground`,children:[(0,B.jsx)(af,{className:`size-4`}),Z(`connecting`)]}):(0,B.jsx)(LF,{layout:u,people:e,narrow:l})}),(0,B.jsx)(jF,{...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,B.jsx)(fF,{track:t},e)),a]})},zF=({leave:e})=>(0,B.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,B.jsxs)(`p`,{className:`flex items-center gap-2 text-sm text-foreground`,children:[(0,B.jsx)(af,{className:`size-4`}),Z(`waiting`)]}),(0,B.jsx)(Dh,{to:e,className:`px-2 text-sm text-muted-foreground hover:text-foreground`,children:Z(`leave`)})]}),BF=`/-/call-guest`,VF=(e,t)=>`${e}${BF}#${t}`,HF=(e,t)=>{let n=t.replace(/^#/,``);return e===`/-/call-guest`&&n?{token:n}:void 0},UF=()=>{let{path:e}=Ih();return(0,I.useMemo)(()=>HF(e,globalThis.location?.hash??``),[e])},WF=200,GF=1e3,KF=(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)},qF=e=>{let[t,n]=(0,I.useState)(),r=[...e].map(([e,t])=>`${e}:${t.id}`).join(`,`);return(0,I.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=DF(new Map([...r].map(([e,t])=>[e,KF(t,i)])));e&&(a={member:e,at:Date.now()}),n(a&&Date.now()-a.at<GF?a.member:void 0)},WF);return()=>{clearInterval(o),t.close()}},[r]),t},JF=new Set([`NotAllowedError`,`SecurityError`]),YF=new Set([`NotFoundError`,`NotReadableError`,`OverconstrainedError`]),XF=async(e,t)=>{try{return{track:(await e.getUserMedia({[t]:!0})).getTracks()[0],blocked:!1}}catch(e){if(!(e instanceof DOMException))throw e;if(JF.has(e.name))return{blocked:!0};if(YF.has(e.name))return{blocked:!1};throw e}},ZF=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)||!(JF.has(e.name)||YF.has(e.name)))throw e}let[t,n]=[await XF(e,`audio`),await XF(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}},QF=class extends Error{reason;constructor(e){super(`Not let into the call: ${e}`),this.reason=e,this.name=`NotLetIn`}},$F=1e3,eI=(e,t)=>new Promise(n=>{let r=setTimeout(n,e);t.addEventListener(`abort`,()=>(clearTimeout(r),n()),{once:!0})}),tI=async(e,t,n,r)=>{let{LobbyRefused:i}=await Ve(async()=>{let{LobbyRefused:e}=await import(`./calls-uuSb7D6L.js`);return{LobbyRefused:e}},[]),a=e=>e instanceof i?new QF(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 QF(`denied`);if(t.state===`ended`)throw new QF(`ended`);await eI($F,r)}throw await e.leave(o),new QF(`ended`)},nI=2e3,rI=e=>{for(let t of e)t?.stop()},iI=(e,{admission:t}={})=>{let[n,r]=(0,I.useState)({kind:`check`}),[i,a]=(0,I.useState)(),o=(0,I.useRef)(new AbortController),[s,c]=(0,I.useState)(),[l,u]=(0,I.useState)(!0),[d,f]=(0,I.useState)(!0),[p,m]=(0,I.useState)([]),[h,g]=(0,I.useState)([]),[_,v]=(0,I.useState)([]),[y,b]=(0,I.useState)(),[x,S]=(0,I.useState)(!1),C=(0,I.useRef)(void 0),w=(0,I.useRef)(!1),T=(0,I.useRef)([]),E=(0,I.useRef)(new Map),D=(0,I.useRef)(Promise.resolve(void 0));(0,I.useEffect)(()=>{let e=!1;return w.current=!1,D.current=ZF().then(t=>{if(e){rI([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,rI(T.current),T.current=[]}},[]),(0,I.useEffect)(()=>{for(let{member:e}of h)E.current.has(e)||E.current.set(e,Date.now())},[h]),(0,I.useEffect)(()=>{if(n.kind!==`in`)return;let e=setInterval(()=>void C.current?.connections().then(v),nI);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 QF))throw e;r({kind:`left`,reason:e.reason})});return e===void 0?void 0:{guest:e}},k=(0,I.useCallback)(async()=>{let t=await O();if(!t||w.current)return;r({kind:`joining`});let{joinCall:n,PublishRefused:i}=await Ve(async()=>{let{joinCall:e,PublishRefused:t}=await import(`./calls-uuSb7D6L.js`);return{joinCall:e,PublishRefused:t}},[]),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]),A=(0,I.useCallback)(()=>{let e=!l;u(e),s?.microphone&&(s.microphone.enabled=e),C.current?.mute(`microphone`,!e)},[l,s]),j=(0,I.useCallback)(()=>{let e=!d;f(e),s?.camera&&(s.camera.enabled=e),C.current?.mute(`camera`,!e)},[d,s]),ee=(0,I.useCallback)(async e=>{b(void 0),rI([e.video,e.audio]),await C.current?.unpublish(`screen`),e.audio&&await C.current?.unpublish(`screen-audio`)},[]),te=(0,I.useCallback)(async()=>{if(y)return ee(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 ee(t)),await C.current?.publish({screen:t.video,...t.audio&&{"screen-audio":t.audio}}),b(t)},[y,ee]),ne=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:A,toggleCamera:j,...ne&&{toggleScreen:te}}},aI=(e,t)=>[...e?.blocked.microphone?[Z(`noMicrophone`)]:[],...e?.blocked.camera?[Z(`noCamera`)]:[],...e?.none?[Z(`noDevices`)]:[],...t?[Z(`refused`)]:[]],oI=({url:e,leave:t,nameOf:n=e=>e,admission:r,name:i,className:a})=>{let o=iI(e,{...r&&{admission:r}}),[s,c]=(0,I.useState)(!1),{basePath:l}=Ih(),u=Nd(),d=u?.state.kind===`signed-in`?u.state.user:void 0,f=o.self??d?.id??``,[p]=(0,I.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=qF(h.kind===`in`?_:new Map),y=aI(m,o.refusedSending);if(h.kind===`left`)return(0,B.jsx)(SF,{reason:h.reason,onJoinAgain:()=>void o.join()});if(h.kind===`waiting`)return(0,B.jsx)(zF,{leave:t});if(h.kind===`check`)return(0,B.jsx)(mF,{name:i??d?.name??Z(`you`),...r&&{joinLabel:Z(`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=kF({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,B.jsx)(RF,{...a&&{className:a},people:C,state:h.kind===`joining`?`joining`:h.resuming?`resuming`:`joined`,notices:y,...b&&x&&{aside:(0,B.jsx)(bF,{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,B.jsx)(yF,{lobby:b,inCall:S,guests:x,linkOf:e=>VF(`${window.location.origin}${l}`,e),open:s,onClose:()=>c(!1)})})},sI=({link:e,systemPath:t,base:n})=>{let[r,i]=(0,I.useState)(``),[a,o]=(0,I.useState)(),[s,c]=(0,I.useState)(!1),l=(0,I.useCallback)(async n=>{let{guestLobby:r}=await Ve(async()=>{let{guestLobby:e}=await import(`./calls-uuSb7D6L.js`);return{guestLobby:e}},[]);return tI(r({systemPath:t}),e,a,n)},[t,e,a]),u=e=>{e.preventDefault(),r.trim()&&o(r.trim())},d=VF(n,e);return s?(0,B.jsx)(`p`,{role:`status`,className:`flex min-h-[100dvh] items-center justify-center bg-background p-4 text-sm text-foreground`,children:Z(`youLeft`)}):a===void 0?(0,B.jsx)(`main`,{className:`flex min-h-[100dvh] items-center justify-center bg-background p-4`,children:(0,B.jsxs)(`form`,{onSubmit:u,className:`flex w-full max-w-sm flex-col gap-3`,children:[(0,B.jsx)(`p`,{className:`text-sm text-foreground`,children:Z(`guestIntro`)}),(0,B.jsxs)(`label`,{className:`flex flex-col gap-1 text-sm text-foreground`,children:[Z(`yourName`),(0,B.jsx)(J,{autoFocus:!0,autoComplete:`name`,maxLength:60,value:r,onChange:e=>i(e.target.value)})]}),(0,B.jsx)(G,{type:`submit`,variant:`primary`,disabled:!r.trim(),children:Z(`continue`)})]})}):(0,B.jsx)(`main`,{className:`h-[100dvh]`,children:(0,B.jsx)(oI,{url:Or(t,`socket`),admission:l,name:a,nameOf:()=>Z(`someone`),leave:{href:d,onFollow:()=>c(!0)}})})},cI=[`light`,`dark`,`system`],lI=`protobase:theme`,uI=`(prefers-color-scheme: dark)`,dI=e=>cI.includes(e),fI=e=>Ie(()=>{let t=e.getItem(lI);return dI(t)?t:`system`},`system`),pI=(e,t)=>Ie(()=>t===`system`?e.removeItem(lI):e.setItem(lI,t),void 0),mI=(e,t)=>e===`system`?t?`dark`:`light`:e,hI=(0,I.createContext)(void 0),gI=({children:e})=>{let[t,n]=(0,I.useState)(()=>fI(localStorage)),r=mI(t,bf(uI));return(0,I.useEffect)(()=>{document.documentElement.dataset.theme=r},[r]),(0,I.useEffect)(()=>{let e=e=>{(e.key===`protobase:theme`||e.key===null)&&n(fI(localStorage))};return window.addEventListener(`storage`,e),()=>window.removeEventListener(`storage`,e)},[]),(0,B.jsx)(hI.Provider,{value:{preference:t,theme:r,choose:e=>{pI(localStorage,e),n(e)}},children:e})},_I=()=>{let e=(0,I.useContext)(hI);if(!e)throw Error(`useTheme needs a ThemeProvider above it`);return e},vI=M(`chat`),yI=({children:e,className:t})=>(0,B.jsx)(`p`,{className:P(`text-xs text-muted-foreground`,t),children:e}),bI=({time:e})=>{let t=Date.parse(e);return(0,B.jsx)(`time`,{dateTime:e,title:gp(t),className:`text-xs text-muted-foreground`,children:Cp(t)})},xI=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,B.jsxs)(`div`,{"data-from":`person`,className:P(`flex min-w-0 gap-3`,o&&`-mt-3`),children:[(0,B.jsx)(`div`,{className:`w-8 shrink-0`,children:!o&&(a??(0,B.jsx)(Vf,{initials:V_(s)||`?`,hue:B_(r.id),size:`md`,className:`ring-0`}))}),(0,B.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-0.5`,children:[!o&&(0,B.jsxs)(`p`,{className:`flex items-baseline gap-2`,children:[(0,B.jsx)(`span`,{className:`font-medium text-foreground`,children:s}),i&&(0,B.jsx)(bI,{time:i})]}),(0,B.jsx)(`div`,{className:`flex min-w-0 flex-col gap-2 whitespace-pre-wrap break-words text-foreground`,children:t}),n&&(0,B.jsx)(yI,{children:n})]})]})}let r=(0,B.jsx)(`div`,{"data-from":e.from,className:P(`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,B.jsxs)(`div`,{className:P(`flex min-w-0 flex-col gap-1`,e.from===`user`&&`items-end`),children:[r,(0,B.jsx)(yI,{className:e.from===`user`?`text-right`:void 0,children:n})]}):r},SI=e=>e.scrollHeight-e.scrollTop-e.clientHeight<=24,CI=(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},wI=(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:SI(e),first:t.firstElementChild??void 0,followKey:n,...a}},TI=(e,t)=>{let n=(0,I.useRef)({onReadToEnd:e,atEnd:t});(0,I.useLayoutEffect)(()=>{n.current={onReadToEnd:e,atEnd:t}});let r=(0,I.useCallback)(()=>{document.visibilityState===`visible`&&n.current.onReadToEnd?.()},[]);return(0,I.useEffect)(()=>{let e=()=>{n.current.atEnd()&&r()};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[r]),r},EI=e=>e.querySelector(`[data-chat-divider][data-tone="new"]`),DI=({children:e,empty:t,length:n,onLoadEarlier:r,loadingEarlier:i,followKey:a,onReadToEnd:o})=>{let s=(0,I.useRef)(null),c=(0,I.useRef)(null),l=(0,I.useRef)({atEnd:!0,first:void 0,followKey:a}),u=()=>{s.current&&c.current&&(l.current=wI(s.current,c.current,a))},d=()=>l.current.atEnd&&l.current.first!==void 0,f=TI(o,d),p=()=>{let e=l.current.atEnd;u(),!e&&d()&&f()};(0,I.useLayoutEffect)(()=>{let e=s.current;if(!e||!c.current)return;let t=l.current,n=t.anchor&&t.anchor.element.isConnected?t.anchor.element.getBoundingClientRect().top-e.getBoundingClientRect().top:void 0,r=EI(c.current),i=r?r.getBoundingClientRect().top-e.getBoundingClientRect().top:void 0,o=CI(t,{first:c.current.firstElementChild??void 0,anchorTop:n,scrollTop:e.scrollTop,scrollHeight:e.scrollHeight,followKey:a,newLineTop:i});o!==void 0&&(e.scrollTop=o),u(),d()&&f()},[n,a]),(0,I.useEffect)(()=>{let e=s.current;if(!e||!c.current)return;let t=new ResizeObserver(()=>{l.current.atEnd&&(e.scrollTop=e.scrollHeight)});return t.observe(e),t.observe(c.current),()=>t.disconnect()},[]);let m=n===0&&!!t;return(0,B.jsxs)(`div`,{ref:s,onScroll:p,className:`flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto p-4 [overflow-anchor:none]`,children:[r&&(0,B.jsx)(G,{size:`sm`,className:`self-center`,loading:i,onClick:r,children:vI(`loadEarlier`)}),m&&(0,B.jsx)(`div`,{className:`m-auto max-w-60 text-center text-muted-foreground`,children:t}),(0,B.jsx)(`div`,{ref:c,role:`log`,"aria-live":`polite`,className:P(`flex flex-col gap-4`,m&&`hidden`),children:e})]})},OI=(e,t)=>{let n=/(?:^|\s)@([^\s@]*)$/.exec(e.slice(0,t));return n?{start:t-n[1].length-1,query:n[1]}:void 0},kI=(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(` `)}},AI=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),jI=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(AI).join(`|`)})(?![\\p{L}\\p{N}_])`,`gu`)},MI=(e,t)=>{let n=jI(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))]},NI=(e,t)=>{let n=jI(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},PI=M(`mentions`),FI=({id:e,optionId:t,people:n,active:r,onActive:i,onPick:a,failed:o,at:s})=>(0,B.jsxs)(`ul`,{id:e,role:`listbox`,"aria-label":PI(`peopleToMention`),className:P(`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,B.jsx)(`li`,{id:t(n),role:`option`,"aria-selected":n===r,className:P(`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,B.jsx)(`li`,{className:`px-3 py-1.5 text-muted-foreground`,children:PI(o?`couldNotSearch`:`noOneFound`)})]}),II=(e,t)=>{let n=aT(t,150),[r,i]=(0,I.useState)(),a=(0,I.useRef)(e);return a.current=e,(0,I.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},LI={text:``,picked:[]},RI=8,zI=({value:e,onChange:t,searchPeople:n,listAt:r=`below`,onKeyDown:i,onFocus:a,onBlur:o,ref:s,...c})=>{let[l,u]=(0,I.useState)(0),[d,f]=(0,I.useState)(!1),[p,m]=(0,I.useState)(0),[h,g]=(0,I.useState)(),_=(0,I.useRef)(null),v=(0,I.useCallback)(e=>{_.current=e,typeof s==`function`?s(e):s&&(s.current=e)},[s]),y=(0,I.useRef)(void 0),b=(0,I.useId)(),x=n?OI(e.text,l):void 0,S=d&&x!==void 0&&x.start!==h,C=II(n,S?x.query:void 0),w=S&&C&&`people`in C?C.people.slice(0,RI):[],T=S&&C!==void 0,E=e=>`${b}-${e}`;(0,I.useEffect)(()=>m(0),[x?.query]);let D=x?.start;(0,I.useEffect)(()=>{D===void 0&&g(void 0)},[D]),(0,I.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=kI(e.text,x,n.name);y.current=r.caret,t({text:r.text,picked:[...e.picked,n]})},k=e=>{if(S){let t=nT(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)},A=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,B.jsxs)(`div`,{className:`relative`,children:[(0,B.jsx)(Jg,{...c,...A,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,B.jsx)(FI,{id:b,optionId:E,people:w,active:p,onActive:m,onPick:O,failed:`failed`in C,at:r})]})},BI=({text:e,mentions:t})=>(0,B.jsx)(`p`,{className:`whitespace-pre-wrap break-words`,children:NI(e,t).map((e,t)=>`mention`in e?(0,B.jsxs)(`span`,{className:`font-medium text-primary`,children:[`@`,e.mention]},t):e.text)}),VI=e=>e.types.includes(`Files`),HI=e=>e.types.includes(`text/plain`)?[]:[...e.files],UI=(e,{busy:t,canSendEmpty:n})=>t?!1:e!==``||n===!0,WI=({onSend:e,busy:t,placeholder:n,inputRef:r,searchPeople:i,attachments:a,actions:o,canSendEmpty:s,onFiles:c})=>{let[l,u]=(0,I.useState)(LI),d=l.text.trim(),f=UI(d,{busy:t,canSendEmpty:s}),p=()=>{f&&(e?.(d,MI(d,l.picked)),u(LI))};return(0,B.jsxs)(`form`,{className:`flex flex-wrap items-end gap-2`,onSubmit:e=>{e.preventDefault(),p()},onDragOver:e=>{c&&VI(e.dataTransfer)&&e.preventDefault()},onDrop:e=>{c&&VI(e.dataTransfer)&&(e.preventDefault(),c([...e.dataTransfer.files]))},children:[a&&(0,B.jsx)(`div`,{className:`basis-full`,children:a}),o,(0,B.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,B.jsx)(zI,{ref:r,rows:1,"aria-label":vI(`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=HI(e.clipboardData);t.length!==0&&(e.preventDefault(),c(t))}})}),(0,B.jsx)(G,{type:`submit`,variant:`primary`,className:`w-8 px-0`,"aria-label":vI(`send`),disabled:!f,children:(0,B.jsx)(us,{className:`size-4`})})]})},GI=e=>{let[t,n]=(0,I.useState)();return(0,I.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},KI=M(`side-panel`),qI=({title:e,icon:t,status:n,onClose:r,footer:i,children:a})=>{let o=GI(!xf());return(0,B.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,B.jsxs)(`header`,{className:`flex h-12 shrink-0 items-center gap-2 border-b border-border bg-background px-4`,children:[t,(0,B.jsx)(`h2`,{className:`flex-1 font-semibold`,children:e}),n&&(0,B.jsx)(`span`,{className:`truncate text-xs font-medium text-muted-foreground`,children:n}),r&&(0,B.jsx)(G,{variant:`ghost`,size:`sm`,className:`w-7 px-0`,"aria-label":KI(`close`),onClick:r,children:(0,B.jsx)(bc,{className:`size-4`})})]}),a,i&&(0,B.jsx)(`footer`,{className:`shrink-0 space-y-2 border-t border-border bg-background p-3`,children:i})]})},JI=M(`action-card`),YI={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`}},XI=({title:e,tone:t=`neutral`,badge:n,note:r,actions:i=[],onAction:a,children:o,frameless:s=!1})=>{let[c,l]=(0,I.useState)(),u=i.flatMap(e=>e.hint?[e.hint]:[]),d=e=>e.confirm?l(e):a?.(e.id);return(0,B.jsxs)(`section`,{"aria-label":e,className:s?`whitespace-normal text-foreground`:P(`shrink-0 overflow-hidden rounded-lg border bg-background whitespace-normal text-foreground shadow-sm`,YI[t].border),children:[!s&&(0,B.jsxs)(`header`,{className:P(`flex items-center gap-2 px-3 py-2`,YI[t].header),children:[(0,B.jsx)(`h3`,{className:`min-w-0 flex-1 font-semibold`,children:e}),n&&(0,B.jsx)(`span`,{className:`shrink-0 text-xs font-medium`,children:n})]}),(o||r||i.length>0)&&(0,B.jsxs)(`div`,{className:P(`space-y-2.5`,!s&&`px-3 py-2.5`),children:[o,r&&(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r}),i.length>0&&(0,B.jsx)(`div`,{className:`flex flex-wrap gap-2 pt-0.5`,children:i.map(e=>(0,B.jsx)(G,{size:`sm`,variant:e.style??`secondary`,className:P(e.style===`primary`&&`flex-1`),disabled:e.disabled,onClick:()=>d(e),children:e.label},e.id))}),u.map(e=>(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e},e))]}),c&&(0,B.jsx)(Of,{title:`${c.label}?`,description:c.confirm,onClose:()=>l(void 0),actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:()=>l(void 0),children:JI(`cancel`)}),(0,B.jsx)(G,{variant:c.style===`danger`?`danger`:`primary`,onClick:()=>{l(void 0),a?.(c.id)},children:c.label})]})})]})},ZI=({fields:e})=>(0,B.jsx)(`dl`,{className:`grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-1 text-body`,children:e.map((e,t)=>(0,B.jsxs)(`div`,{className:`contents`,children:[(0,B.jsx)(`dt`,{className:`text-muted-foreground`,children:e.label}),(0,B.jsx)(`dd`,{className:`min-w-0 break-words`,children:e.value})]},`${t}-${e.label}`))}),QI=e=>e==null?`null`:typeof e==`object`?JSON.stringify(e):String(e),$I=M(`compact-table`),eL=({columns:e,rows:t,caption:n,truncated:r,className:i})=>(0,B.jsxs)(`section`,{"aria-label":n??$I(`table`),className:P(`shrink-0 overflow-hidden rounded-lg border border-border-strong bg-background shadow-sm`,i),children:[n&&(0,B.jsx)(`code`,{className:`block whitespace-pre-wrap break-words bg-surface px-3 py-2 font-mono text-[11px] text-foreground`,children:n}),t.length===0?(0,B.jsx)(`p`,{className:`px-3 py-2 text-xs text-muted-foreground`,children:$I(`noRows`)}):(0,B.jsx)(`div`,{className:`max-h-64 overflow-auto`,children:(0,B.jsxs)(`table`,{className:`w-full border-collapse text-left text-[11px]`,children:[(0,B.jsx)(`thead`,{className:`sticky top-0 bg-background`,children:(0,B.jsx)(`tr`,{children:e.map(e=>(0,B.jsx)(`th`,{scope:`col`,className:`border-b border-border px-2 py-1 font-semibold whitespace-nowrap`,children:e},e))})}),(0,B.jsx)(`tbody`,{children:t.map((e,t)=>(0,B.jsx)(`tr`,{className:`border-b border-border last:border-b-0`,children:e.map((e,t)=>(0,B.jsx)(`td`,{className:P(`px-2 py-1 whitespace-nowrap`,e===null&&`text-faint-foreground`),children:QI(e)},t))},t))})]})}),(0,B.jsxs)(`footer`,{className:`border-t border-border px-3 py-1.5 text-[11px] text-muted-foreground`,children:[$I(`rows`,{count:t.length}),r&&$I(`cutOff`)]})]}),tL=(e,t=1)=>{let n=t,r=t;return e.split(`
|
|
5
|
+
`).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++})},nL=e=>({added:e.filter(e=>e.kind===`add`).length,removed:e.filter(e=>e.kind===`del`).length}),rL={add:`bg-success-soft text-success-text`,del:`bg-danger-soft text-danger-text`,ctx:`text-muted-foreground`},iL={add:`+`,del:`−`,ctx:``},aL=({source:e,start:t,path:n,className:r})=>{let i=tL(e,t),a=nL(i);return(0,B.jsxs)(`div`,{className:P(`overflow-hidden`,r),children:[n&&(0,B.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-border bg-surface px-3 py-1.5`,children:[(0,B.jsx)(ya,{className:`size-3.5 text-muted-foreground`}),(0,B.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-[11px] text-foreground`,children:n}),(0,B.jsxs)(`span`,{className:`text-[11px] font-medium text-success-text`,children:[`+`,a.added]}),a.removed>0&&(0,B.jsxs)(`span`,{className:`text-[11px] font-medium text-danger-text`,children:[`−`,a.removed]})]}),(0,B.jsx)(`pre`,{className:`overflow-x-auto bg-background py-1 font-mono text-[11px] leading-[18px]`,children:i.map((e,t)=>(0,B.jsxs)(`div`,{className:P(`flex`,rL[e.kind]),children:[(0,B.jsx)(`span`,{className:`w-8 shrink-0 select-none pr-2 text-right opacity-60`,children:e.newNo??e.oldNo}),(0,B.jsx)(`span`,{className:`w-3 shrink-0 select-none`,children:iL[e.kind]}),(0,B.jsx)(`span`,{className:`min-w-0 whitespace-pre-wrap break-words pr-3`,children:e.text})]},t))})]})},oL={pending:(0,B.jsx)(Ui,{className:`size-3 text-faint-foreground`}),running:(0,B.jsx)(af,{className:`size-3.5 text-primary`}),done:(0,B.jsx)(Ci,{className:`size-3.5 text-success`,strokeWidth:2.5}),failed:(0,B.jsx)(bc,{className:`size-3.5 text-danger`,strokeWidth:2.5})},sL={pending:`text-muted-foreground`,running:`text-foreground`,done:`text-muted-foreground`,failed:`text-danger-text`},cL=({steps:e,className:t})=>(0,B.jsx)(`ul`,{className:P(`shrink-0 space-y-2`,t),children:e.map((e,t)=>(0,B.jsxs)(`li`,{className:`flex items-start gap-2.5`,"data-state":e.state,children:[(0,B.jsx)(`span`,{className:`mt-0.5 flex size-4 shrink-0 items-center justify-center`,children:oL[e.state]}),(0,B.jsx)(`span`,{className:sL[e.state],children:e.label})]},`${t}-${e.label}`))}),lL=M(`assistant-dock`),uL=({part:e,note:t})=>e.fallback?(0,B.jsx)(XI,{title:e.fallback.title,note:t,children:e.fallback.body&&(0,B.jsx)(`p`,{children:e.fallback.body})}):(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`${e.name}: ${t}`}),dL=class extends I.Component{state={failed:!1};static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(e,t){uv(e,t.componentStack)}render(){return this.state.failed?(0,B.jsx)(uL,{part:this.props.part,note:lL(`couldNotDraw`)}):this.props.children}},fL=({part:e})=>{let{components:t={}}=p_(),n=Object.hasOwn(t,e.name)?t[e.name]:void 0;return n?(0,B.jsx)(dL,{part:e,children:(0,B.jsx)(n,{...e.props})}):(0,B.jsx)(uL,{part:e,note:lL(`cannotShowLive`)})},pL=({part:e,onAction:t})=>{switch(e.type){case`text`:return(0,B.jsx)(`p`,{children:e.text});case`table`:return(0,B.jsx)(eL,{columns:e.columns,rows:e.rows,caption:e.caption,truncated:e.truncated});case`card`:return(0,B.jsxs)(XI,{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,B.jsx)(`p`,{children:e.body}),e.code&&(0,B.jsx)(`pre`,{className:`overflow-x-auto rounded-md bg-surface px-2.5 py-2 font-mono text-[11px] whitespace-pre-wrap break-words`,children:e.code}),e.fields&&e.fields.length>0&&(0,B.jsx)(ZI,{fields:e.fields}),e.steps&&e.steps.length>0&&(0,B.jsx)(cL,{steps:e.steps}),e.diffs?.map((e,t)=>(0,B.jsx)(aL,{source:e.source,start:e.start,path:e.path,className:`rounded-md border border-border`},`${t}-${e.path}`))]});case`widget`:return(0,B.jsx)(fL,{part:e})}},mL=(0,I.createContext)(void 0),hL=e=>e instanceof Error?e:Error(lL(`backendNoAnswer`)),gL=(e,t)=>typeof e==`function`?e(t):e,_L=(e,{refreshMs:t=!1}={})=>{let n=(0,I.useContext)(mL),[r,i]=(0,I.useState)({}),[a,o]=(0,I.useState)(0),s=(0,I.useRef)(t);s.current=t;let c=(0,I.useRef)(void 0);return(0,I.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:hL(e)}));if(!t)return;c.current=o.data,i(o);let l=gL(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:hL(e)}));c.current=a.data,i(a)}}},vL=({state:e,offline:t,error:n,onSend:r,onAction:i,onClose:a,client:o})=>{let s=(0,I.useRef)(null);return(0,I.useEffect)(()=>{e.placeholder&&s.current?.focus()},[e.placeholder]),(0,B.jsx)(qI,{title:lL(`assistant`),icon:(0,B.jsx)(Os,{className:`size-4 text-primary`}),status:t?lL(`reconnecting`):e.status,onClose:a,footer:(0,B.jsxs)(B.Fragment,{children:[n&&(0,B.jsx)(`p`,{role:`alert`,className:`text-body text-danger-text`,children:n}),(0,B.jsx)(WI,{inputRef:s,onSend:r,busy:e.replying,placeholder:e.placeholder??lL(`askQuestion`)})]}),children:(0,B.jsx)(mL.Provider,{value:o,children:(0,B.jsx)(DI,{length:e.messages.reduce((e,t)=>e+t.parts.length,0),empty:lL(`empty`),children:e.messages.map(e=>(0,B.jsx)(xI,{from:e.from,children:e.parts.map(e=>(0,B.jsx)(pL,{part:e,onAction:i},e.id))},e.id))})})})},yL=e=>e instanceof Error?e.message:lL(`noAnswer`),bL=e=>{let[t,n]=(0,I.useState)($n),[r,i]=(0,I.useState)(!1),[a,o]=(0,I.useState)();(0,I.useEffect)(()=>{if(e)return e.connect(e=>n(t=>nr(t,e)),e=>i(e.state===`retrying`))},[e]);let s=e=>{o(void 0),e.catch(e=>o(yL(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))}},xL=e=>{let t=$P(),n=(0,I.useRef)(t);n.current=t;let r=t!==void 0;return(0,I.useMemo)(()=>r?ad({url:e,token:()=>n.current}):void 0,[e,r])},SL=({open:e,onToggle:t})=>(0,B.jsxs)(G,{size:`sm`,variant:e?`primary`:`secondary`,"aria-pressed":e,onClick:t,className:`max-md:size-9 max-md:p-0`,children:[(0,B.jsx)(Os,{className:`size-3.5`}),(0,B.jsx)(`span`,{className:`max-md:sr-only`,children:q(`assistant`)})]}),CL=({client:e,page:t,onClose:n})=>{let{state:r,offline:i,error:a,send:o,act:s}=bL(e);return(0,B.jsx)(vL,{state:r,offline:i,error:a,onSend:e=>o(e,t),onAction:s,onClose:n,client:e})},wL=({url:e,...t})=>(0,B.jsx)(CL,{client:xL(e),...t}),TL=({url:e,client:t,...n})=>t?(0,B.jsx)(CL,{client:t,...n}):(0,B.jsx)(wL,{url:e,...n}),EL={bell:ri,"book-open":ai,bookmark:di,building:hi,"credit-card":$i,"external-link":da,"file-text":Ca,globe:aa,heart:ka,key:La,"layout-dashboard":Ua,"life-buoy":Ya,mail:lo,package:Po,receipt:es,settings:gs,shield:vs,"shopping-cart":Ss,tags:Ws,users:oc,warehouse:mc};Object.keys(EL);var DL=(e,t)=>e?EL[e]??t:t,OL=(e,t)=>DL(e.views[t]?.icon??e.signIn?.[t]?.icon,Rs),kL=(e,t,n)=>(e.bottomBar?.items??[]).map((r,i)=>r.kind===`link`?{id:`link-${i}`,label:r.label,icon:DL(r.icon,da),href:r.href,external:!0}:r.kind===`page`?{id:r.page,label:r.label,icon:DL(r.icon??e.pages[r.page]?.icon,Ua),href:Vc({kind:`page`,page:r.page},t),active:r.page===n}:{id:r.resource,label:r.label,icon:DL(r.icon,OL(e,r.resource)),href:Vc({kind:`list`,resource:r.resource},t),active:r.resource===n}),AL=({basePath:e,address:t,group:n,page:r,resourceLabel:i,recordTitle:a,recordLoading:o})=>{let s=n?[n]:[];if(r)return[...s,{label:r.title,href:Vc({kind:`page`,page:r.name},e)}];if(!t||t.kind===`page`)return[q(`admin`)];let c=i?[{label:i,href:Vc({kind:`list`,resource:t.resource,...t.kind===`list`&&t.list&&{list:t.list}},e)}]:[];if(t.kind===`list`)return[...s,...c];let l=Vc(t,e),u=t.kind===`create`?{label:q(`new`),href:l}:a===void 0&&o?{label:q(`loadingRecord`),href:l,loading:!0}:{label:a??t.key,href:l};return[...s,...c,u]},jL=({name:e,tab:t})=>{let n=W().pages[e];if(!n)return(0,B.jsx)(sf,{title:fv(`notFound`),children:fv.rich(`noPage`,{page:e})});let r=t=>Vc({kind:`page`,page:e,...t&&{tab:t}});return(0,B.jsx)(ff,{route:{...t&&{tab:t},pathOf:r},children:(0,B.jsx)(PM,{node:n.tree})})},Q=M(`app/record`),ML=2e3,NL=Symbol(`nothing saved`),PL=(e,t)=>{let n=ly(),[r,i]=(0,I.useState)(`idle`),[a,o]=(0,I.useState)(),s=(0,I.useRef)(void 0);return(0,I.useEffect)(()=>()=>clearTimeout(s.current),[]),{phase:r,message:a,run:async r=>{let a=e===`toast`?n.show({state:`loading`,title:Q(`savingSubject`,{subject:t})}):void 0;o(void 0),e===`button`&&i(`saving`);try{return await r()===NL?(a!==void 0&&n.dismiss(a),e===`button`&&i(`idle`),!0):(a!==void 0&&n.update(a,{state:`success`,title:Q(`subjectSaved`,{subject:t})}),e===`button`&&(i(`saved`),s.current=setTimeout(()=>i(`idle`),ML)),!0)}catch(t){if(!ml(t))throw t;let r=t.status===412?Q(`changedBySomeoneElse`):Q(`couldNotSave`),s=dx(t);return a!==void 0&&n.update(a,{state:`error`,title:r,description:s}),e===`button`&&(i(`idle`),o(`${r}: ${s}`)),!1}}}},FL=({title:e,eyebrow:t,submit:n,saving:r,disabled:i,error:a,errorTitle:o=Mg(`notSaved`),onSubmit:s,onCancel:c,children:l,ref:u})=>{let d=(0,B.jsxs)(`div`,{className:`flex items-center gap-2`,children:[c&&(0,B.jsx)(G,{className:`max-sm:min-h-11`,onClick:c,children:Mg(`cancel`)}),(0,B.jsx)(G,{variant:`primary`,type:`submit`,className:`max-sm:min-h-11 max-sm:flex-1`,loading:r,disabled:i,children:n})]}),f=a!==void 0&&(0,B.jsx)(`div`,{className:`mt-4`,children:(0,B.jsx)(Gg,{title:o,error:a})}),p=(0,B.jsx)(`div`,{className:`divide-y divide-border`,children:l}),m=e=>{e.preventDefault(),s()};return e===void 0?(0,B.jsxs)(`form`,{ref:u,className:`max-w-[760px]`,onSubmit:m,children:[f,p,(0,B.jsx)(`footer`,{className:`border-t pt-6 sm:flex sm:justify-end`,children:d})]}):(0,B.jsx)(`form`,{ref:u,className:`flex-1`,onSubmit:m,children:(0,B.jsxs)(`div`,{className:`mx-auto max-w-[760px] px-4 py-6 md:px-10 md:py-8`,children:[(0,B.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,B.jsxs)(`div`,{children:[t&&(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:t}),(0,B.jsx)(`h1`,{className:`mt-1 text-2xl font-semibold tracking-tight`,children:e})]}),d]}),f,p]})})},IL=({noun:e,collection:t,sections:n,saving:r,message:i,onSubmit:a,onCancel:o,ref:s})=>(0,B.jsx)(FL,{ref:s,title:Mg(`title`,{noun:e}),eyebrow:t,submit:Mg(`submit`,{noun:e}),saving:r,error:i?Error(i):void 0,errorTitle:Mg(`notCreated`),onSubmit:a,onCancel:o,children:n.map(e=>(0,B.jsx)(Kf,{title:e.title,help:e.help,children:(0,B.jsx)(`div`,{className:`grid grid-cols-1 gap-x-6 gap-y-5 sm:grid-cols-2`,children:e.fields.map(e=>(0,B.jsx)(eg,{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))}),LL=(e,t)=>Object.fromEntries(Object.entries(e).filter(([e])=>e!==t)),RL=({resource:e,values:t})=>{let n=W(),r=n.resources[e],i=uf(e);return r?dy(i,`create`)?(0,B.jsx)(zL,{resource:e,values:t}):(0,B.jsx)(sf,{title:Mg(`notAllowed`),children:Mg(`cannotCreate`,{plural:n.views[e]?.names?.plural.toLowerCase()??e})}):(0,B.jsx)(sf,{title:q(`notFound`),children:q(`noResource`,{name:e})})},zL=({resource:e,values:t})=>{let n=W(),r=n.resources[e],i=n.views[e],a=U(),o=Se(),{go:s}=qh(),c=i?.names?.singular??F(e),l=PL(i?.saveFeedback??`toast`,Mg(`subject`,{noun:c})),u=Fg(r,i),[d,f]=(0,I.useState)(()=>Hg(r,u,t)),[p,m]=(0,I.useState)({}),[h,g]=(0,I.useState)(0),_=fx(h),[v,y]=(0,I.useState)(),[b,x]=(0,I.useState)(!1);Kh(!v&&(b||l.phase===`saving`),`input-lost`),(0,I.useEffect)(()=>{v&&s(v,{replace:!0})},[v,s]),(0,I.useEffect)(()=>{for(let[e,i]of Object.entries(t??{})){let t=n.resources[r.fields[e]?.relation?.resource??``];t&&Eb(o,a,t,[i],n.views[t.name]).then(t=>{let n=t.get(i);n&&f(t=>Ng(t[e])&&t[e].key===i?{...t,[e]:{key:i,label:n}}:t)})}},[t,n,r,a,o]);let S=(e,t)=>{m(t=>LL(t,e)),x(!0),f(n=>({...n,[e]:t}))},C=()=>l.run(async()=>{let t;try{t=await a.create(e,Lg(r,n.resources,d))}catch(t){let n=ml(t)?t.existing:void 0;if(n)return y({kind:`record`,resource:e,key:n.key}),NL;let r=ux(t);throw m(r),Object.keys(r).length>0&&g(e=>e+1),t}for(let t of[`page`,`list`,`first-page`,`map`,`facets`,`series`])o.invalidateQueries({queryKey:[t,e]});y({kind:`record`,resource:e,key:wm(r,t.record)})}),w=u.map(e=>({title:e.title,help:e.help,fields:e.fields.map(e=>{let t=r.fields[e],a=d[e],o=t.relation?n.resources[t.relation.resource]:void 0,s=i?.fields[e]?.label??F(e),c=p[e];return{name:e,label:s,help:i?.fields[e]?.help,required:Rg(t),error:c&&lx(t,s,c),wide:!!(i?.fields[e]?.multiline||i?.fields[e]?.markdown),editor:(0,B.jsx)(Nv,{field:t,hints:i?.fields[e],value:Ng(a)?a.key:a??(t.type!==`boolean`&&``),stored:void 0,relationLabel:Ng(a)?a.label:void 0,placeholder:Ug(t)?Mg(`setByDatabase`):Vg(t),relationPicker:o?{target:o,view:n.views[o.name]}:void 0,invalid:!!p[e],resource:r.name,onChange:t=>S(e,t)})}})}));return(0,B.jsx)(IL,{ref:_,noun:c,collection:i?.names?.plural??F(e),sections:w,saving:l.phase===`saving`,message:l.message,onSubmit:()=>void C(),onCancel:()=>s({kind:`list`,resource:e})})},BL=({resource:e,values:t})=>{let n=W(),r=n.views[e];return r?.create?n.pages[r.create.page]?(0,B.jsx)(jL,{name:r.create.page}):(0,B.jsx)(sf,{title:Mg(`notAllowed`),children:Mg(`cannotCreate`,{plural:r.names?.plural.toLowerCase()??F(e)})}):(0,B.jsx)(RL,{resource:e,values:t},new URLSearchParams(t).toString())},VL=(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)}}))},HL=(e,t)=>[...new Set(t.filter(t=>!e.includes(t)))],UL=sn(),WL=(e,t,n)=>{let r=U(),[i,a]=(0,I.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:[cr(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[cr(e,i)])]},l=f({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:d,queryFn:async()=>(await r.list(t.name,{filter:Yt(UL.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))}})},GL=24,KL=({model:e,resources:t,views:n,view:r,state:i,extras:a,titleOf:o})=>{let s=U(),c=Se(),l=UT(r,e),u=e=>r?.fields[e]?.label??F(e),d=n=>{let r=e.fields[n];return r?.type===`relation`&&r.relation?t[r.relation.resource]:void 0},p=e=>!!(e&&n[e.name]?.titleFrom),m=l.facets.flatMap(e=>(e.flags?e.options.map(e=>e.value):[e.id]).map(t=>({group:e.id,field:t}))),h=f({queries:m.map(({group:t,field:r})=>{let o=AT(l,{...i,facets:{...i.facets,[t]:[]}},a),c=d(r),u=c?.primaryKey.length===1&&!p(c)?cr(c,n[c.name]):void 0;return{queryKey:H.facets(e.name,r,o),queryFn:()=>s.facets(e.name,r,{filter:o,limit:50,...u&&{label:u}})}})}),g=(e,t)=>h[m.findIndex(n=>n.group===e&&n.field===t)]?.data,_=e=>(g(e,e)??[]).flatMap(e=>e.value===null?[]:[String(e.value)]),v=f({queries:l.facets.map(t=>{let r=d(t.id),a=HL(_(t.id),i.facets[t.id]??[]);return{queryKey:H.labels(`facet:${e.name}.${t.id}`,a.join(`,`)),enabled:!!r&&!p(r)&&a.length>0,queryFn:async()=>[...await Eb(c,s,r,a,n[r.name])]}})}),y=f({queries:l.facets.map(t=>{let r=d(t.id),a=r&&p(r)?jb(r,n[r.name]):void 0,o=[...new Set([..._(t.id),...i.facets[t.id]??[]])];return{queryKey:H.labels(`facet-title:${e.name}.${t.id}`,o.join(`,`)),enabled:a!==void 0&&o.length>0,queryFn:async()=>[...await Nb(s,r,a,o)]}})}),b=(e,t)=>{let r=d(e);return(y[t]?.data??[]).map(([e,t])=>[e,o(r,n[r.name],t,e)])},x=WL(l.facets.map(e=>({id:e.id,target:e.combobox?d(e.id):void 0})),n,o),S=l.ranges??[],C=f({queries:S.map(t=>{let n=AT(l,Gw(i,t.id,void 0),a),o=WT(r,t.id)?GL:1;return{queryKey:H.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:g(t.id,e)?.find(e=>String(e.value)===`true`)?.count??0}));return{...t,options:e}}let i=e.fields[t.id],a=(g(t.id,t.id)??[]).flatMap(e=>e.label===void 0?[]:[[String(e.value),e.label]]),o=new Map([...a,...v[n]?.data??[],...b(t.id,n)]),s=(g(t.id,t.id)??[]).flatMap(e=>e.value===null?[]:[{value:String(e.value),label:i?.type===`enum`?ar(String(e.value),r?.fields[t.id]?.valueLabels):o.get(String(e.value))??String(e.value),count:e.count}]),c=x[n];return{...t,label:u(t.id),options:c.matches?VL(c.matches,s):s,...o.size>0&&{labels:Object.fromEntries(o)},...c.onSearch&&{onSearch:c.onSearch}}}),ranges:S.flatMap((e,t)=>{let n=C[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:WT(r,e.id)?n.buckets.map(e=>e.count):[],format:GT(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)}))}},qL=M(`app/delete`),JL=sn(),YL=({blockingPlural:e,noun:t})=>qL(`stillPointAt`,{plural:e,noun:t}),XL=({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??F(a),c=YL({blockingPlural:s,noun:r});if(!o||i===void 0)return{text:c};let l={kind:`list`,resource:a,filter:Yt(JL.eq(o,i))};return{text:c,link:{label:qL(`show`,{plural:s}),to:l}}},ZL=({title:e,noun:t,busy:n,onConfirm:r,onCancel:i})=>(0,B.jsx)(Of,{title:qL(`confirmTitle`,{title:e}),description:qL(`confirmDescription`,{noun:t,title:e}),onClose:i,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:i,children:qL(`cancel`)}),(0,B.jsx)(G,{variant:`primary`,className:`bg-danger hover:bg-danger/90`,loading:n,onClick:r,children:qL(`delete`)})]})}),QL=({title:e,changes:t,busy:n,onReview:r,onDeleteAnyway:i,onCancel:a})=>(0,B.jsx)(Of,{title:qL(`changedTitle`,{title:e}),description:qL(`changedDescription`),onClose:a,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:r,children:qL(`reviewChanges`)}),(0,B.jsx)(G,{variant:`primary`,className:`bg-danger hover:bg-danger/90`,loading:n,onClick:i,children:qL(`deleteAnyway`)})]}),children:t.length===0?(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:qL(`noVisibleChanges`)}):(0,B.jsx)(`ul`,{className:`divide-y rounded-md border`,children:t.map(e=>(0,B.jsxs)(`li`,{className:`grid grid-cols-[96px_1fr] gap-3 px-3 py-2`,children:[(0,B.jsx)(`span`,{className:`text-muted-foreground`,children:e.label}),(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`span`,{className:`text-muted-foreground line-through`,children:e.before}),` `,(0,B.jsx)(`span`,{className:`font-medium`,children:e.after})]})]},e.field))})}),$L=e=>{if(e.stage===`confirm`)return(0,B.jsx)(Of,{title:qL(`bulkConfirmTitle`,{count:e.count,noun:e.noun,plural:e.plural}),description:qL(`bulkConfirmDescription`),onClose:e.onCancel,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:e.onCancel,children:qL(`cancel`)}),(0,B.jsx)(G,{variant:`primary`,className:`bg-danger hover:bg-danger/90`,onClick:e.onConfirm,children:qL(`deleteCount`,{count:e.count})})]})});if(e.stage===`running`)return(0,B.jsx)(Of,{title:qL(`deleting`),description:qL(`progress`,{done:e.done,total:e.total}),onClose:()=>void 0,actions:(0,B.jsx)(G,{loading:!0,disabled:!0,children:qL(`working`)})});let t=e.total-e.failures.length;return(0,B.jsx)(Of,{title:e.failures.length===0?qL(`deleted`,{count:t}):qL(`deletedOf`,{count:t,total:e.total}),description:e.failures.length===0?void 0:qL(`kept`,{count:e.failures.length}),onClose:e.onClose,actions:(0,B.jsx)(G,{variant:`primary`,onClick:e.onClose,children:qL(`done`)}),children:e.failures.length>0&&(0,B.jsx)(`ul`,{className:`max-h-48 divide-y overflow-y-auto rounded-md border`,children:e.failures.map(e=>(0,B.jsxs)(`li`,{className:`px-3 py-2`,children:[(0,B.jsx)(`span`,{className:`font-medium`,children:e.title}),(0,B.jsx)(`span`,{className:`block text-xs text-danger-text`,children:e.message})]},e.title))})})},eR=new Set([`updated_at`,`updatedAt`]),tR=(e,t,n,r)=>Object.values(e.fields).flatMap(e=>{if(eR.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??F(e.name),before:Rm(e,n[e.name],i),after:Rm(e,r[e.name],i)}]}),nR=4,rR=({model:e,view:t,onDeleted:n,onReview:r,restore:i})=>{let a=U(),o=Se(),s=ly(),[c,l]=(0,I.useState)(),[u,d]=(0,I.useState)(!1),f=t?.names?.singular??F(e.name),p=t?.names?.plural??F(e.name),{resources:m,views:h}=W(),{href:g,open:_}=qh(),v=(t,n)=>t.blockedBy&&XL({blockedBy:t.blockedBy,resources:m,views:h,noun:f,...e.primaryKey.length===1&&{key:n.key}}),y=()=>{for(let t of[`page`,`list`,`first-page`,`map`])o.invalidateQueries({queryKey:[t,e.name]});for(let t of[`facets`,`series`,`histogram`])o.invalidateQueries({queryKey:[t,e.name]})},b=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 pl))throw e;return e}},x=t=>{y(),l(void 0),n?.(t),s.show({state:`success`,title:qL(`deletedToast`,{title:t.title}),...e.softDelete&&i&&{action:{label:qL(`undo`),onClick:()=>{i(t).then(()=>{y(),s.show({state:`success`,title:qL(`restored`,{title:t.title})})},e=>{if(!ml(e))throw e;y(),s.show({state:e.status===409?`success`:`error`,title:e.status===409?qL(`alreadyBack`,{title:t.title}):qL(`couldNotRestore`,{title:t.title}),description:e.status===409?void 0:e.message})})}}}})},S=async(n,r)=>{d(!0);try{if(!await b(n,r))return x(n);let i=(await a.get(e.name,n.key)).record;l({kind:`conflict`,target:n,fresh:i,changes:tR(e,t,n.snapshot,i)})}catch(e){if(!ml(e))throw e;l(void 0);let t=v(e,n);s.show({state:`error`,title:qL(`couldNotDelete`,{title:n.title}),description:t?.text??e.message,...t?.link&&{action:{label:t.link.label,href:g(t.link.to),onNavigate:_}}})}finally{d(!1)}},C=async e=>{try{return await b(e,e.etag)?{title:e.title,message:qL(`changedSinceLoaded`)}:void 0}catch(t){if(!ml(t))throw t;return{title:e.title,message:v(t,e)?.text??t.message}}},w=async e=>{let t=[],n=0;l({kind:`bulk-running`,done:n,total:e.length});let r=[...e];await Promise.all(Array.from({length:Math.min(nR,e.length)},async()=>{for(let i=r.shift();i;i=r.shift()){let r=await C(i);r&&t.push(r),n+=1,l({kind:`bulk-running`,done:n,total:e.length})}})),y(),l({kind:`bulk-done`,total:e.length,failures:t})},T=()=>l(void 0);return{dialogs:c&&(0,B.jsxs)(B.Fragment,{children:[c.kind===`confirm`&&(0,B.jsx)(ZL,{title:c.target.title,noun:f,busy:u,onCancel:T,onConfirm:()=>void S(c.target,c.target.etag)}),c.kind===`conflict`&&(0,B.jsx)(QL,{title:c.target.title,changes:c.changes,busy:u,onCancel:T,onReview:()=>{T(),r?.(c.target,c.fresh)},onDeleteAnyway:()=>void S(c.target,`*`)}),c.kind===`bulk-confirm`&&(0,B.jsx)($L,{stage:`confirm`,count:c.targets.length,noun:f,plural:p,onCancel:T,onConfirm:()=>void w(c.targets)}),c.kind===`bulk-running`&&(0,B.jsx)($L,{stage:`running`,done:c.done,total:c.total}),c.kind===`bulk-done`&&(0,B.jsx)($L,{stage:`done`,total:c.total,failures:c.failures,onClose:T})]}),start:t=>e.softDelete?S(t,t.etag):l({kind:`confirm`,target:t}),startBulk:e=>l({kind:`bulk-confirm`,targets:e})}},iR=e=>{let t=U();return e.softDelete?async n=>void await t.undelete(e.name,n.key):void 0},aR=(e,t,n)=>e?.create?Object.hasOwn(t,e.create.page):dy(n,`create`),$=M(`app/import`),oR=e=>typeof e==`object`&&!!e,sR=e=>e===null||typeof e==`string`&&e.trim()===``,cR=e=>e===null?``:oR(e)?e.date.replace(`T`,` `):typeof e==`boolean`?e?`TRUE`:`FALSE`:String(e),lR=e=>e<26?String.fromCharCode(65+e):lR(Math.floor(e/26)-1)+lR(e%26),uR=(e,t)=>e[t]?.trim()?e[t]:$(`column`,{letters:lR(t)}),dR=e=>/[",\r\n]/.test(e)?`"${e.replace(/"/g,`""`)}"`:e,fR=(e,t)=>{let n=[...t].sort((e,t)=>e.line-t.line).map(t=>[...e.map((e,n)=>cR(t.cells[n]??null)),String(t.line),t.problems.join(`; `)]);return`${[[...e,$(`line`),$(`problems`)],...n].map(e=>e.map(dR).join(`,`)).join(`\r
|
|
6
|
+
`)}\r\n`},pR=({label:e,counts:t})=>(0,B.jsx)(`dl`,{"aria-label":e,className:`grid grid-cols-2 gap-3 sm:grid-cols-4`,children:t.map(([e,t])=>(0,B.jsxs)(`div`,{className:`rounded-lg border px-3 py-2`,children:[(0,B.jsx)(`dt`,{className:`text-xs text-muted-foreground`,children:e}),(0,B.jsx)(`dd`,{className:`text-lg font-semibold tabular-nums`,children:t.toLocaleString(Le())})]},e))}),mR=(e,t)=>e?.fields[t]?.label??F(t),hR=new Set([`text`,`integer`,`bigint`,`decimal`,`boolean`,`date`,`timestamp`,`uuid`,`enum`,`relation`,`currency`,`country`]),gR=(e,t)=>{let n=e.relation?t[e.relation.resource]:void 0;return n?.primaryKey.length===1?n:void 0},_R=(e,t)=>Object.values(e.fields).filter(n=>n.readOnly||n.name===e.tenant||!hR.has(n.type)?!1:n.type!==`relation`||gR(n,t)!==void 0),vR=new Set([`text`,`integer`,`bigint`,`uuid`,`date`,`currency`,`country`,`enum`]),yR=e=>{let t=e.primaryKey.length===1?[e.fields[e.primaryKey[0]]]:[],n=Object.values(e.fields).filter(t=>t.filterable&&!t.sensitive&&vR.has(t.type)&&!e.primaryKey.includes(t.name));return[...t,...n]},bR=(e,t)=>gR(e,t),xR=e=>!e.nullable&&!e.default,SR=e=>e.toLowerCase().replace(/[\s_-]+/g,``),CR=(e,t,n)=>{let r=new Set;return e.flatMap((e,i)=>{let a=SR(e);if(a===``)return[];let o=t.find(e=>!r.has(e.name)&&(SR(mR(n,e.name))===a||SR(e.name)===a));return o?(r.add(o.name),[{column:i,field:o.name}]):[]})},wR=(e,t,n)=>{if(e===`update`)return[];let r=new Set(n.map(e=>e.field));return t.filter(e=>xR(e)&&!r.has(e.name))},TR=e=>({ok:!0,value:e}),ER=e=>({ok:!1,problem:e}),DR=e=>`“${cR(e)}”`,OR=(e,t)=>{if(typeof e==`number`)return String(e);if(typeof e==`string`)return hg(e,t.decimal)},kR=(e,t,n)=>{let r=OR(t,n);if(r===void 0)return ER($(`notNumber`,{cell:DR(t)}));let[i,a=``]=r.split(`.`);if(/[1-9]/.test(a)||/e/i.test(r))return ER($(`notWholeNumber`,{cell:DR(t)}));if(e.type===`bigint`)return TR(String(BigInt(i)));let o=Number(i);return Number.isSafeInteger(o)?TR(o):ER($(`tooLarge`,{cell:DR(t)}))},AR=(e,t)=>{let n=OR(e,t);return n===void 0?ER($(`notNumber`,{cell:DR(e)})):TR(n)},jR=new Set([`true`,`yes`,`1`]),MR=new Set([`false`,`no`,`0`]),NR=e=>{if(typeof e==`boolean`)return TR(e);let t=typeof e==`string`||typeof e==`number`?String(e).trim().toLowerCase():``;return jR.has(t)?TR(!0):MR.has(t)?TR(!1):ER($(`notBoolean`,{cell:DR(e)}))},PR=e=>String(e).padStart(2,`0`),FR=(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}-${PR(t)}-${PR(n)}`},IR=`(\\d{1,2}):(\\d{2})(?::(\\d{2})(?:\\.\\d+)?)?`,LR=(e,t)=>{let n=RegExp(`^(\\d{4})[-/](\\d{1,2})[-/](\\d{1,2})(?:[T ]${IR}(Z|[+-]\\d{2}:?\\d{2})?)?$`).exec(e.trim()),r=RegExp(`^(\\d{1,2})[./-](\\d{1,2})[./-](\\d{4})(?: ${IR})?$`).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=FR(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:`${PR(Number(c))}:${l}:${PR(Number(u))}`,zone:n?.[7]}},RR=(e,t)=>{if(oR(e)){let[t,n]=e.date.split(`T`);return{date:t,time:n}}return typeof e==`string`?LR(e,t.dateOrder):void 0},zR=(e,t)=>ER($(`notDate`,{cell:DR(e),dayFirst:t.dateOrder===`dmy`})),BR=(e,t)=>{let n=RR(e,t);return n?n.time&&n.time!==`00:00:00`?ER($(`hasTime`,{cell:DR(e)})):TR(n.date):zR(e,t)},VR=(e,t)=>{let n=RR(e,t);if(!n)return zR(e,t);if(n.zone)return TR(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 TR(new Date(r,i-1,a,o,s,c).toISOString())},HR=e=>e.trim().toLowerCase().replace(/\s+/g,` `),UR=(e,t,n)=>{let r=e.enumValues??[],i=HR(cR(n)),a=r.filter(e=>HR(e)===i||HR(ar(e,t?.valueLabels))===i);return a.length===1?TR(a[0]):a.length>1?ER($(`severalValues`,{cell:DR(n),values:a.map(e=>ar(e,t?.valueLabels)).join(`, `)})):ER($(`notOneOf`,{cell:DR(n),values:r.map(e=>ar(e,t?.valueLabels)).join(`, `)}))},WR=e=>typeof e==`boolean`?ER($(`notText`,{cell:DR(e)})):TR(cR(e)),GR=(e,t,n,r)=>{if(sR(n))return e.nullable?TR(null):ER($(`emptyRequired`));switch(e.type){case`integer`:case`bigint`:return kR(e,n,r);case`decimal`:return AR(n,r);case`boolean`:return NR(n);case`date`:return BR(n,r);case`timestamp`:return VR(n,r);case`enum`:return UR(e,t,n);case`text`:case`uuid`:case`currency`:case`country`:return WR(n);default:throw Error(`Not implemented: importing ${e.type} fields, which importableFields leaves out`)}},KR=(e,t)=>e[t]?.names?.singular??F(t),qR=(e,t)=>e[t]?.names?.plural??F(t),JR=(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=mR(o,d),g=bR(p,i);if(g&&!sR(m)){let e=f??g.primaryKey[0],n=GR(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]=cR(m);continue}let _=GR(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=GR({...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(`${mR(o,n.name)}: ${i.problem}`)}return{values:s,data:c,problems:l,relations:u,match:d}},YR=(e,t)=>{let n=e.lookups.keysOf(t.model.name,t.field,t.value),r=`${mR(e.views[t.model.name],t.field).toLowerCase()} “${String(t.value)}”`;return n.length===1?{key:n[0]}:n.length===0?{none:$(`noneHas`,{singular:KR(e.views,t.model.name),named:r})}:{several:$(`severalHave`,{count:n.length,plural:qR(e.views,t.model.name),named:r})}},XR=e=>e.cells.every(sR),ZR=async(e,t,n)=>{let{model:r,views:i}=n,a=e.filter(e=>!XR(e)).map(e=>({row:e,...JR(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=YR(n,t);`key`in a?u[e]=a.key:s.push(`${mR(i[r.name],e)}: ${a.none??a.several}`)}let d=l&&YR(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}}})},QR=5,$R=5,ez=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(cR),sample:a.slice(0,QR)}};async function*tz(e,t){let n=!0;for await(let r of e.rows(t))yield n?r.slice(1):r,n=!1}var nz=async(e,t,n,r,i,a)=>{let o={rows:0,creates:0,updates:0,problems:[],preview:[]};for await(let s of tz(e,t)){a?.throwIfAborted();for(let e of await ZR(s,n,r))o.rows++,o.preview.length<$R&&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},rz=(e,t)=>{if(!ml(e))return[e.message];let n=e.errors.filter(e=>e.field);return n.length===0?[e.message]:n.map(e=>`${mR(t.views[t.model.name],e.field)}: ${e.message}`)},iz=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=ml(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:rz(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 tz(e,t)){for(let e of await ZR(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}},az=50,oz=(e,t,n)=>bM(fR(t,n),$(`notImportedFile`,{name:(e??`import`).replace(/\.[^.]+$/,``)}),`text/csv`),sz=({rows:e})=>(0,B.jsxs)(`ul`,{"aria-label":$(`rowsNotImported`),className:`flex flex-col gap-1 text-body`,children:[e.slice(0,az).map(e=>(0,B.jsxs)(`li`,{children:[(0,B.jsx)(`span`,{className:`font-medium`,children:$(`rowProblems`,{line:e.line})}),` `,e.problems.join(`; `)]},e.line)),e.length>az&&(0,B.jsx)(`li`,{className:`text-muted-foreground`,children:$(`andMore`,{count:(e.length-az).toLocaleString(Le())})})]}),cz=({rows:e})=>(0,B.jsxs)(`p`,{className:`flex items-center gap-2 text-muted-foreground`,role:`status`,children:[(0,B.jsx)(af,{className:`size-3.5`}),$(`checkingRows`,{count:e.toLocaleString(Le())})]}),lz=({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,B.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,B.jsx)(pR,{label:$(`check`),counts:[[$(`rows`),e.rows],[$(`toCreate`),e.creates],[$(`toUpdate`),e.updates],[$(`withProblems`),e.problems.length]]}),e.preview.length>0&&(0,B.jsx)(`div`,{className:`overflow-x-auto rounded-lg border`,children:(0,B.jsxs)(`table`,{"aria-label":$(`firstRows`),className:`w-full text-left text-body`,children:[(0,B.jsx)(`thead`,{className:`bg-muted text-muted-foreground`,children:(0,B.jsxs)(`tr`,{children:[(0,B.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:$(`row`)}),c.map(e=>(0,B.jsx)(`th`,{className:`whitespace-nowrap px-2 py-1.5 font-medium`,children:mR(s,e.name)},e.name))]})}),(0,B.jsx)(`tbody`,{className:`divide-y`,children:e.preview.map(e=>(0,B.jsxs)(`tr`,{className:e.problems.length>0?`bg-danger-soft`:void 0,children:[(0,B.jsx)(`td`,{className:`px-2 py-1.5 tabular-nums text-muted-foreground`,children:e.line}),c.map(t=>(0,B.jsx)(`td`,{className:`max-w-48 truncate px-2 py-1.5`,children:bR(t,n)?String(e.values[t.name]??`—`):t.name in e.values?Rm(t,e.values[t.name],s?.fields[t.name]):``},t.name))]},e.line))})]})}),e.problems.length>0&&(0,B.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,B.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,B.jsx)(`h3`,{className:`font-medium`,children:$(`problemRows`)}),(0,B.jsxs)(G,{size:`sm`,onClick:()=>oz(o,a,e.problems),children:[(0,B.jsx)(ra,{className:`size-3.5`}),$(`download`)]})]}),(0,B.jsx)(sz,{rows:e.problems})]}),(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:$(`batches`,{size:100})})]})},uz=({label:e,name:t,value:n,options:r,onChange:i,help:a,className:o})=>{let s=(0,I.useId)();return(0,B.jsxs)(`div`,{className:P(`flex min-w-0 flex-col gap-1.5`,o),children:[(0,B.jsx)(`label`,{htmlFor:s,className:`font-medium`,children:e}),(0,B.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,B.jsx)(`option`,{value:e.value,children:e.label},e.value))}),a&&(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:a})]})},dz=({file:e,sheets:t,sheet:n,reading:r,onChoose:i,onSheet:a})=>{let o=(0,I.useId)();return(0,B.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,B.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,B.jsx)(`label`,{htmlFor:o,className:`font-medium`,children:$(`file`)}),(0,B.jsx)(`input`,{id:o,type:`file`,accept:`.xlsx,.csv,text/csv,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`,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,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:$(`fileHint`)})]}),r&&(0,B.jsxs)(`p`,{className:`flex items-center gap-2 text-muted-foreground`,role:`status`,children:[(0,B.jsx)(af,{className:`size-3.5`}),$(`reading`,{name:e?.name??$(`theFile`)})]}),!r&&t.length>1&&(0,B.jsxs)(`div`,{className:`flex items-end gap-3`,children:[(0,B.jsx)(xa,{className:`mb-2 size-4 shrink-0 text-muted-foreground`}),(0,B.jsx)(uz,{className:`flex-1`,label:$(`sheet`),value:n??``,options:t.map(e=>({value:e,label:e})),onChange:a})]})]})},fz=()=>[{value:`create`,label:$(`create`)},{value:`update`,label:$(`update`)},{value:`upsert`,label:$(`upsert`)}],pz={create:`createHint`,update:`updateHint`,upsert:`upsertHint`},mz=``,hz=({flow:e,model:t,resources:n,views:r,canUpdate:i})=>{let a=r[t.name],o=e.head?.headers??[],s=e.head?.sample??[],c=wR(e.mode,e.fields,e.columns),l=[{value:mz,label:$(`doNotImport`)},...e.fields.map(e=>({value:e.name,label:`${mR(a,e.name)}${xR(e)?` *`:``}`}))],u=o.map((e,t)=>({value:String(t),label:uR(o,t)})),d=yR(t);return(0,B.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[i&&(0,B.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,B.jsx)(`span`,{className:`font-medium`,children:$(`rows`)}),(0,B.jsx)(`div`,{children:(0,B.jsx)(Re,{label:$(`whatEachRowDoes`),size:`md`,value:e.mode,options:fz(),onChange:e.setMode})}),(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:$(pz[e.mode])})]}),e.mode!==`create`&&(0,B.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2`,children:[(0,B.jsx)(uz,{label:$(`findBy`),value:e.match?.field??mz,options:[{value:mz,label:$(`chooseField`)},...d.map(e=>({value:e.name,label:mR(a,e.name)}))],onChange:t=>e.setMatch(t?{field:t,column:e.match?.column??0}:void 0),help:$(`findByHint`)}),(0,B.jsx)(uz,{label:$(`foundInColumn`),value:e.match?String(e.match.column):mz,options:[{value:mz,label:$(`chooseColumn`)},...u],onChange:t=>e.setMatch(t&&e.match?{...e.match,column:Number(t)}:e.match)})]}),(0,B.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2`,children:[(0,B.jsx)(uz,{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,B.jsx)(uz,{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,B.jsx)(`p`,{className:`-mb-3 text-xs text-muted-foreground`,children:$(`requiredMarked`)}),(0,B.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?bR(d,n):void 0,p=s.map(e=>cR(e.cells[c]??null)).filter(e=>e!==``).slice(0,3),m=uR(o,c);return(0,B.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 py-3 sm:grid-cols-2 sm:gap-4`,children:[(0,B.jsxs)(`div`,{className:`min-w-0`,children:[(0,B.jsx)(`p`,{className:`truncate font-medium`,children:m}),(0,B.jsx)(`p`,{className:`truncate text-xs text-muted-foreground`,children:p.length>0?p.join(`, `):$(`emptyInFirstRows`)})]}),(0,B.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[(0,B.jsx)(uz,{label:$(`field`),name:$(`fieldFor`,{name:m}),value:u?.field??mz,options:l,onChange:t=>e.mapColumn(c,t||void 0)}),f&&(0,B.jsx)(uz,{label:$(`foundBy`),name:$(`pluralFoundBy`,{plural:r[f.name]?.names?.plural??mR(a,d.name)}),value:u.matchBy??f.primaryKey[0],options:yR(f).map(e=>({value:e.name,label:mR(r[f.name],e.name)})),onChange:t=>e.matchColumnBy(c,t)})]})]},c)})}),c.length>0&&(0,B.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,B.jsx)(Xs,{className:`mt-0.5 size-4 shrink-0`}),(0,B.jsx)(`span`,{children:$(`noColumnFills`,{fields:c.map(e=>mR(a,e.name)).join(`, `)})})]})]})},gz=e=>e.toLocaleString(Le()),_z=({progress:e,total:t,cancelling:n})=>{let r=e.created+e.updated+e.failed;return(0,B.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,B.jsxs)(`div`,{className:`flex items-baseline justify-between gap-2 text-xs`,children:[(0,B.jsx)(`span`,{className:`text-muted-foreground`,children:$(n?`stopping`:`saving`)}),(0,B.jsxs)(`span`,{className:`tabular-nums`,children:[gz(r),` / `,gz(t)]})]}),(0,B.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,B.jsx)(`div`,{className:`h-full rounded-full bg-primary transition-[width]`,style:{width:`${t>0?Math.min(100,r/t*100):0}%`}})})]})},vz=({result:e,stopped:t,headers:n,fileName:r})=>(0,B.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[t!==void 0&&(0,B.jsx)(Gg,{title:$(`stopped`),error:t}),e.cancelled&&(0,B.jsx)(`p`,{role:`status`,children:$(`cancelled`)}),(0,B.jsx)(pR,{label:$(`summary`),counts:[[$(`created`),e.created],[$(`updated`),e.updated],[$(`skipped`),e.skipped],[$(`failed`),e.failed]]}),e.notWritten.length>0&&(0,B.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,B.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,B.jsx)(`h3`,{className:`font-medium`,children:$(`rowsNotImported`)}),(0,B.jsxs)(G,{size:`sm`,onClick:()=>oz(r,n,e.notWritten),children:[(0,B.jsx)(ra,{className:`size-3.5`}),$(`download`)]})]}),(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:$(`notWrittenHint`)}),(0,B.jsx)(sz,{rows:[...e.notWritten].sort((e,t)=>e.line-t.line)})]})]}),yz=e=>{let t=pg(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`}},bz=sn(),xz=100,Sz=e=>String(e),Cz=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(Sz(e))).map(e=>[Sz(e),e])).values()],s=t.primaryKey[0];for(let n=0;n<o.length;n+=xz){let i=o.slice(n,n+xz);for(let e of i)a.set(Sz(e),[]);let c=Yt(bz.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(Sz(e[r]))?.push(e[s]);l=n.nextPageToken||void 0}while(l)}},keysOf:(e,t,r)=>n(e,t).get(Sz(r))??[]}},wz=500,Tz=()=>{let e=new Worker(new URL(`/assets/parse-worker-CUJ2o-AL.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()}},Ez=e=>({sheets:async()=>{let t=Tz();try{t.send({type:`sheets`,file:e,locale:Be()});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=Tz();try{for(n.send({type:`read`,file:e,sheet:t,chunk:wz,locale:Be()});;){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()}}}),Dz={created:0,updated:0,skipped:0,failed:0,notWritten:[]},Oz=({model:e,resources:t,views:n,sourceFor:r=Ez})=>{let i=Ud(),a=Se(),o=n[e.name],s=(0,I.useMemo)(()=>_R(e,t),[e,t]),[c,l]=(0,I.useState)({kind:`file`,reading:!1}),[u,d]=(0,I.useState)(),[f,p]=(0,I.useState)(),[m,h]=(0,I.useState)(),[g,_]=(0,I.useState)(),[v,y]=(0,I.useState)(`create`),[b,x]=(0,I.useState)([]),[S,C]=(0,I.useState)(),[w,T]=(0,I.useState)(()=>yz()),E=(0,I.useRef)(!1),D=(0,I.useRef)(void 0),O=e=>t=>{d(t),l(e)},k=e=>{d(void 0),l({kind:`file`,reading:!0});let t=r(e);t.sheets().then(n=>{if(p({file:e,source:t,sheets:n}),h(n[0]),n.length<=1)return A(t,n[0]);l({kind:`file`,reading:!1})}).catch(O({kind:`file`,reading:!1}))},A=async(t,n)=>{l({kind:`file`,reading:!0});let r=await ez(t,n);_(r),x(CR(r.headers,s,o));let i=yR(e)[0],a=i?CR(r.headers,[i],o)[0]:void 0;C(i&&a?{field:i.name,column:a.column}:void 0),l({kind:`map`})},j=()=>{f&&(d(void 0),A(f.source,m).catch(O({kind:`file`,reading:!1})))},ee=(e,t)=>x(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}),te=(e,t)=>x(n=>n.map(n=>n.column===e?{...n,matchBy:t}:n)),ne=()=>({mode:v,columns:b,match:v===`create`?void 0:S,options:w}),re=()=>({model:e,resources:t,views:n,lookups:Cz(i)});return{step:c,error:u,file:f?.file,sheets:f?.sheets??[],sheet:m,setSheet:h,head:g,fields:s,mode:v,setMode:y,columns:b,mapColumn:ee,matchColumnBy:te,match:S,setMatch:C,options:w,setOptions:T,choose:k,openSheet:j,check:()=>{if(!f)return;d(void 0);let e=new AbortController;D.current=e,l({kind:`checking`,rows:0}),nz(f.source,m,ne(),re(),e=>l({kind:`checking`,rows:e}),e.signal).then(t=>{e.signal.aborted||l({kind:`checked`,check:t})}).catch(t=>{e.signal.aborted||O({kind:`map`})(t)})},back:()=>{D.current?.abort(),d(void 0),l({kind:`map`})},start:t=>{if(!f)return;d(void 0),E.current=!1,l({kind:`importing`,progress:Dz,total:t,cancelling:!1});let n=Dz;iz(f.source,m,ne(),re(),{client:i(e.name),onProgress:e=>{n=e,l({kind:`importing`,progress:e,total:t,cancelling:E.current})},cancelled:()=>E.current}).then(e=>l({kind:`done`,result:e})).catch(e=>l({kind:`done`,result:{...n,cancelled:!1},stopped:e})).finally(()=>{for(let t of[`page`,`list`,`first-page`,`map`,`facets`,`series`])a.invalidateQueries({queryKey:[t,e.name]})})},cancel:()=>{E.current=!0,l(e=>e.kind===`importing`?{...e,cancelling:!0}:e)},stop:()=>D.current?.abort()}},kz=e=>e.step.kind===`file`?$(`couldNotReadFile`):$(`couldNotCheck`),Az=e=>e.columns.length===0?!1:e.mode===`create`?wR(`create`,e.fields,e.columns).length===0:e.match!==void 0,jz=({model:e,resources:t,views:n,canUpdate:r,onClose:i,sourceFor:a})=>{let o=Oz({model:e,resources:t,views:n,sourceFor:a}),s=n[e.name]?.names?.plural??F(e.name),{step:c}=o,l=o.head?.headers??[],u=()=>{c.kind!==`importing`&&(o.stop(),i())},d=(0,B.jsx)(G,{onClick:u,children:$(`cancel`)});return(0,B.jsx)(jf,{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,B.jsxs)(B.Fragment,{children:[d,o.sheets.length>1&&(0,B.jsx)(G,{variant:`primary`,loading:c.reading,onClick:o.openSheet,children:$(`next`)})]});case`map`:return(0,B.jsxs)(B.Fragment,{children:[d,(0,B.jsx)(G,{variant:`primary`,disabled:!Az(o),onClick:o.check,children:$(`checkRows`)})]});case`checking`:return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:o.back,children:$(`back`)}),(0,B.jsx)(G,{variant:`primary`,loading:!0,children:$(`checking`)})]});case`checked`:{let e=c.check.creates+c.check.updates;return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:o.back,children:$(`back`)}),(0,B.jsx)(G,{variant:`primary`,disabled:e===0,onClick:()=>o.start(e),children:$(`importRows`,{count:e.toLocaleString(Le()),rows:e})})]})}case`importing`:return(0,B.jsx)(G,{variant:`danger`,disabled:c.cancelling,onClick:o.cancel,children:$(`cancelImport`)});case`done`:return(0,B.jsx)(G,{variant:`primary`,onClick:i,children:$(`done`)})}})(),children:(0,B.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[o.error!==void 0&&(0,B.jsx)(Gg,{title:kz(o),error:o.error}),(()=>{switch(c.kind){case`file`:return(0,B.jsx)(dz,{file:o.file,sheets:o.sheets,sheet:o.sheet,reading:c.reading,onChoose:o.choose,onSheet:o.setSheet});case`map`:return(0,B.jsx)(hz,{flow:o,model:e,resources:t,views:n,canUpdate:r});case`checking`:return(0,B.jsx)(cz,{rows:c.rows});case`checked`:return(0,B.jsx)(lz,{check:c.check,model:e,resources:t,views:n,columns:o.columns,headers:l,fileName:o.file?.name});case`importing`:return(0,B.jsx)(_z,{progress:c.progress,total:c.total,cancelling:c.cancelling});case`done`:return(0,B.jsx)(vz,{result:c.result,stopped:c.stopped,headers:l,fileName:o.file?.name})}})()]})})},Mz=({model:e})=>{let{resources:t,views:n}=W(),r=uf(e.name),[i,a]=(0,I.useState)(!1);return n[e.name]?.import===!1||!dy(r,`create`)?null:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(G,{onClick:()=>a(!0),"aria-haspopup":`dialog`,children:[(0,B.jsx)(Qs,{className:`size-3.5`}),$(`import`)]}),i&&(0,B.jsx)(jz,{model:e,resources:t,views:n,canUpdate:dy(r,`update`),onClose:()=>a(!1)})]})},Nz=M(`app/export`),Pz=()=>new DOMException(Nz(`cancelled`),`AbortError`),Fz=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:Be()}));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 Pz();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 Iz(s,c),{rows:f,truncated:g.length<h.items.length||m!==``||i+1<n.length}}while(m!==``)}return await Iz(s,c),{rows:f,truncated:!1}}catch(e){throw await c.abort(),e}finally{s.close()}},Iz=async(e,t)=>{await t.write(await e.send({kind:`finish`})),await t.close()},Lz=1048575,Rz=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
7
|
+
`,zz=`http://schemas.openxmlformats.org/officeDocument/2006/relationships`,Bz=`http://schemas.openxmlformats.org/package/2006/relationships`;`${Rz}`,`${Rz}${Bz}${zz}`,`${Rz}${Bz}${zz}${zz}`,new TextEncoder;var Vz=sn(),Hz=e=>e?.export!==!1,Uz=e=>Object.values(e.fields).flatMap(e=>e.sensitive?[]:[e.name]),Wz=(e,t)=>{let n=new Set(Uz(e));return Er(e,t).filter(e=>n.has(e))},Gz=(e,t,n)=>Object.fromEntries(Im(e,t,[],n).map(e=>[e.id,e.header])),Kz=(e,t,n)=>{let r=Gz(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]??{}}]:[]})},qz=(e,t)=>{let n=e?.export?e.export.maxRows??1/0:1/0;return Math.min(n,t===`xlsx`?Lz:1/0)},Jz=e=>e.primaryKey.length===1,Yz=(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(Yt(Vz.in(n,t.slice(e,e+500))));return r},Xz=()=>{let e=new Worker(new URL(`/assets/export-worker-CcXp0ZdG.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(Nz(`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()}},Zz=()=>[{value:`xlsx`,label:Nz(`excel`)},{value:`csv`,label:Nz(`csv`)}],Qz=()=>[{value:`shown`,label:Nz(`asShown`)},{value:`raw`,label:Nz(`rawValues`)}],$z={shown:`shownHint`,raw:`rawHint`},eB=e=>e.kind===`counting`?Nz(`counting`):e.kind===`exact`||e.rows>1e4?Mp(e.rows):Nz(`moreThan`),tB=e=>{if(e.kind!==`counting`)return e.kind===`exact`?e.rows:Math.max(e.rows,10001)},nB=({label:e,help:t,children:n})=>(0,B.jsxs)(`div`,{className:`flex flex-col items-start gap-1.5`,children:[(0,B.jsx)(`span`,{className:`text-body font-medium`,children:e}),n,t&&(0,B.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:t})]}),rB=(e,t,n)=>{let r=e.indexOf(t),i=[...e];return i.splice(r,1),i.splice(r+n,0,t),i},iB=({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,B.jsx)(`ul`,{className:`divide-y self-stretch rounded-md border`,"aria-label":Nz(`columns`),children:i.map(e=>{let i=t.includes(e),a=t.indexOf(e);return(0,B.jsxs)(`li`,{className:`flex min-h-10 items-center gap-2 px-3 py-1`,children:[(0,B.jsxs)(`label`,{className:`flex min-w-0 flex-1 cursor-pointer items-center gap-2.5`,children:[(0,B.jsx)(AC,{checked:i,label:r[e],onChange:r=>n(r?[...t,e]:t.filter(t=>t!==e))}),(0,B.jsx)(`span`,{className:i?`truncate`:`truncate text-muted-foreground`,children:r[e]})]}),i&&(0,B.jsxs)(`span`,{className:`flex shrink-0 gap-1`,children:[(0,B.jsx)(G,{size:`sm`,variant:`ghost`,className:`min-h-8 px-2`,"aria-label":Nz(`moveUp`,{label:r[e]}),disabled:a===0,onClick:()=>n(rB(t,e,-1)),children:(0,B.jsx)(Gr,{className:`size-3.5`})}),(0,B.jsx)(G,{size:`sm`,variant:`ghost`,className:`min-h-8 px-2`,"aria-label":Nz(`moveDown`,{label:r[e]}),disabled:a===t.length-1,onClick:()=>n(rB(t,e,1)),children:(0,B.jsx)(Fr,{className:`size-3.5`})})]})]},e)})})},aB=({plural:e,view:t,fields:n,initialColumns:r,count:i,selected:a,open:o,onExport:s,onClose:c})=>{let[l,u]=(0,I.useState)(`xlsx`),[d,f]=(0,I.useState)(a?`selected`:`list`),[p,m]=(0,I.useState)(r),[h,g]=(0,I.useState)(`shown`),_=qz(t,l),v=d===`selected`?Nz(`selectedRows`,{count:kp(a??0),rows:a??0}):eB(i),y=(d===`selected`?a??0:tB(i)??0)>_,b=[{value:`list`,label:Nz(`rowsInList`)},{value:`selected`,label:Nz(`selected`,{count:kp(a??0)})}];return(0,B.jsx)(jf,{title:Nz(`exportPlural`,{plural:e}),open:o,onClose:c,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:c,children:Nz(`cancel`)}),(0,B.jsx)(G,{variant:`primary`,disabled:p.length===0,onClick:()=>s({format:l,scope:d,columns:p,mode:h}),children:Nz(`export`)})]}),children:(0,B.jsxs)(`div`,{className:`flex flex-col gap-4 text-body`,children:[(0,B.jsx)(nB,{label:Nz(`format`),children:(0,B.jsx)(Re,{size:`md`,label:Nz(`format`),value:l,options:Zz(),onChange:u})}),a!==void 0&&a>0&&(0,B.jsx)(nB,{label:Nz(`rows`),help:d===`list`?Nz(`listHint`):void 0,children:(0,B.jsx)(Re,{size:`md`,label:Nz(`rows`),value:d,options:b,onChange:f})}),(0,B.jsx)(nB,{label:Nz(`values`),help:Nz($z[h]),children:(0,B.jsx)(Re,{size:`md`,label:Nz(`values`),value:h,options:Qz(),onChange:g})}),(0,B.jsx)(nB,{label:Nz(`columns`),children:(0,B.jsx)(iB,{fields:n,columns:p,onChange:m})}),(0,B.jsxs)(`p`,{role:`status`,className:`text-muted-foreground`,children:[Nz(`exports`,{rows:v}),y&&Nz(`overLimit`,{limit:kp(_)})]})]})})},oB=({plural:e,done:t,total:n,onCancel:r})=>{let i=n?Math.min(1,t/n):void 0;return(0,B.jsx)(jf,{title:Nz(`exporting`,{plural:e}),open:!0,onClose:r,actions:(0,B.jsx)(G,{onClick:r,children:Nz(`cancel`)}),children:(0,B.jsxs)(`div`,{className:`flex flex-col gap-2 text-body`,children:[(0,B.jsx)(`div`,{role:`progressbar`,"aria-label":Nz(`rowsExported`),"aria-valuemin":0,"aria-valuemax":n,"aria-valuenow":t,className:`h-1.5 overflow-hidden rounded-full bg-muted`,children:(0,B.jsx)(`div`,{className:`h-full rounded-full bg-primary transition-[width]`,style:{width:`${(i??0)*100}%`}})}),(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:n?Nz(`doneOf`,{done:kp(t),total:kp(n)}):Nz(`done`,{done:kp(t)})})]})})},sB={xlsx:{mime:`application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`,extension:`.xlsx`,description:`workbook`},csv:{mime:`text/csv`,extension:`.csv`,description:`csvFile`}},cB=/[\\/:*?"<>|\u0000-\u001f]/g,lB=(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(cB,` `).trim()} ${r}${sB[t].extension}`},uB=8e6,dB=(e,t)=>{let n=new Blob([],{type:sB[t].mime}),r=[],i=0,a=()=>{n=new Blob([n,...r],{type:sB[t].mime}),r=[],i=0};return{write:async e=>{e.length!==0&&(r.push(e),i+=e.length,i>=uB&&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([])}}},fB=()=>globalThis.showSaveFilePicker,pB=()=>typeof fB()==`function`,mB=async(e,t)=>{let n=fB();if(!n)throw Error(`This browser cannot save a file as it is built`);let r=sB[t],i;try{i=await n({suggestedName:e,types:[{description:Nz(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()}},hB=(e,t)=>pB()?mB(e,t):Promise.resolve(dB(e,t)),gB=(e,t)=>{let n=t[e.primaryKey[0]];return typeof n==`object`&&n&&`id`in n?n.id:n},_B=({model:e,view:t,resources:n,views:r,plural:i,filter:a,orderBy:o,createPort:s=Xz,createSink:c=hB})=>{let l=U(),u=ly(),[d,f]=(0,I.useState)({kind:`closed`}),p=(0,I.useRef)(void 0),m=E({queryKey:H.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`},h=(t=[])=>f({kind:`settings`,selected:Jz(e)?t.map(t=>gB(e,t)):[]}),g=async(d,h)=>{let g=lB(i,d.format),_=await c(g,d.format);if(!_)return;let v=qz(t,d.format),y=d.scope===`selected`?h.length:tB(m),b=y===void 0?void 0:Math.min(y,v),x=new AbortController;p.current=x,f({kind:`running`,done:0,total:b});try{let c=await Fz({client:l,resource:e.name,filters:d.scope===`selected`?Yz(e,h):[a],orderBy:o,plan:{format:d.format,mode:d.mode,name:i,columns:Kz(e,t,d.columns)},labels:d.mode===`shown`?Ob(n,r,e,d.columns):{},limit:v,port:s(),sink:_,signal:x.signal,onProgress:e=>x.signal.aborted||f({kind:`running`,done:e,total:b})});u.show({state:`success`,title:Nz(`exported`,{count:kp(c.rows),plural:i}),description:c.truncated?Nz(`truncated`,{name:g,count:kp(c.rows)}):g})}catch(e){if(e instanceof DOMException&&e.name===`AbortError`)return;if(!ml(e))throw e;u.show({state:`error`,title:Nz(`couldNotExport`,{plural:i}),description:e.message})}finally{p.current=void 0,f(e=>e.kind===`running`?{kind:`closed`}:e)}},_=()=>{p.current?.abort(),f({kind:`closed`})},v=Uz(e),y=Gz(e,t,v);return{open:h,dialogs:d.kind===`settings`?(0,B.jsx)(aB,{plural:i,view:t,fields:v.map(e=>({name:e,label:y[e]})),initialColumns:Wz(e,t),count:m,selected:d.selected.length>0?d.selected.length:void 0,open:!0,onExport:e=>void g(e,d.selected),onClose:()=>f({kind:`closed`})}):d.kind===`running`?(0,B.jsx)(oB,{plural:i,done:d.done,total:d.total,onCancel:_}):null}},vB=M(`app/list`),yB=({state:e,onClearSearch:t,onClearFilters:n,create:r})=>(0,B.jsxs)(`div`,{className:`flex flex-col items-center gap-3 py-8 text-center text-muted-foreground`,children:[(0,B.jsx)(`p`,{children:e.message}),(e.clearSearch||e.clearFilters||e.create&&r)&&(0,B.jsxs)(`div`,{className:`flex flex-wrap justify-center gap-2`,children:[e.clearSearch&&(0,B.jsx)(G,{onClick:t,children:vB(`clearSearch`)}),e.clearFilters&&(0,B.jsx)(G,{onClick:n,children:vB(`clearFilters`)}),e.create&&r]})]}),bB=({plural:e,search:t,filtered:n,scoped:r,canCreate:i})=>t?{message:vB(`noMatchSearch`,{plural:e,search:t}),clearSearch:!0,clearFilters:n,create:!1}:n?{message:vB(`noMatchFilters`,{plural:e}),clearSearch:!1,clearFilters:!0,create:!1}:r?{message:vB(`noMatch`,{plural:e}),clearSearch:!1,clearFilters:!1,create:!1}:{message:vB(`noneYet`,{plural:e}),clearSearch:!1,clearFilters:!1,create:i},xB=(e,t)=>{},SB=({windowMs:e=1e3,comebacks:t=2,onHold:n=xB}={})=>{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}},CB=e=>Math.max(1,Math.floor((e+12)/252)),wB=(e,t)=>Math.max(0,(e-(t-1)*12)/t),TB=(e,t,n,r)=>({start:e*n,end:Math.max(0,Math.min(r,(t+1)*n)-1)}),EB=(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},DB=(e,t)=>{let n=e/t.rowHeight;return Math.floor(n)*t.columns+n%1},OB=(e,t)=>Math.floor(Math.floor(e)/t)+e%1,kB=8,AB=(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<=kB)break;i.delete(e)}return i},jB=({source:e,label:t,initialIndex:n,onScrollIndex:r,minHeight:i,children:a})=>{let{total:o}=e,[s]=(0,I.useState)(n),[c,l]=(0,I.useState)(0),u=CB(c),d=wB(c,u),[f,p]=(0,I.useState)(()=>new Map),m=Math.ceil(Math.max(i(d),f.get(d)??0)),h=m+12,g={columns:u,rowHeight:h},_=(0,I.useRef)({layout:g,top:0}),v=_.current.top>0&&(_.current.layout.columns!==u||_.current.layout.rowHeight!==h),y=e=>v?EB(_.current.top,_.current.layout,g):e,b=d>0&&f.has(d),x=uw({total:Math.ceil(o/u),rowHeight:h,initialIndex:OB(s,u),settle:y,ready:b,onScroll:e=>r(DB(e,g))});(0,I.useLayoutEffect)(()=>{v&&x.scrollTo(x.top),_.current={layout:g,top:x.started()?x.top:0}});let S=TB(x.first,x.last,u,o),C=XC({total:o,rowAt:e.rowAt,loadRows:e.loadRows,revision:e.revision,latencyMs:0},S.start,S.end),[w]=(0,I.useState)(()=>SB());(0,I.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,I.useRef)(d);T.current=d;let[E]=(0,I.useState)(()=>new ResizeObserver(e=>{let t=Math.max(...e.map(e=>e.borderBoxSize[0]?.blockSize??e.contentRect.height)),n=T.current;p(e=>AB(e,n,t))}));(0,I.useLayoutEffect)(()=>()=>E.disconnect(),[E]);let D=(0,I.useCallback)(e=>{if(e)return E.observe(e),()=>E.unobserve(e)},[E]);return(0,B.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,B.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,B.jsx)(`li`,{"aria-hidden":!0,className:`absolute grid grid-cols-[minmax(0,1fr)]`,style:c,children:(0,B.jsx)(Ch,{className:`h-full rounded-lg`})},`skeleton-${i}`)}))})},MB=`grid grid-cols-[repeat(auto-fill,minmax(15rem,1fr))] gap-3`,NB=e=>e*.75,PB=44,FB=({model:e,view:t,display:n,list:r,empty:i})=>{let a=t?.names?.plural??F(e.name),o=n.card===void 0&&(n.image!==void 0||n.photos!==void 0);return r.isLoading?(0,B.jsx)(`div`,{className:`min-h-0 flex-1 overflow-hidden ${MB}`,children:Array.from({length:6},(e,t)=>(0,B.jsx)(Ch,{className:`h-24`},t))}):r.error?(0,B.jsx)(Gg,{title:K(`couldNotLoadRows`),error:r.error}):!r.source||r.source.total===0?i??(0,B.jsx)(`p`,{className:`py-8 text-center text-muted-foreground`,children:K(`noneMatch`,{plural:a.toLowerCase()})}):(0,B.jsx)(jB,{source:r.source,label:a,initialIndex:r.initialIndex,onScrollIndex:r.onScrollIndex,minHeight:e=>(o?NB(e):0)+PB,children:r=>(0,B.jsx)(nD,{model:e,view:t,display:n,row:hh(e,r)})})},IB=`protobase:list-places`,LB=50,RB=(e,t)=>`${e} ${t}`,zB=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},BB=e=>Ie(()=>{let t=e.getItem(IB);if(t===null)return[];let n=JSON.parse(t);return Array.isArray(n)?n.filter(zB):[]},[]),VB=e=>{let t=new Map(BB(e).map(e=>[RB(e.entry,e.url),e]));return{placeOf:(e,n)=>{let r=t.get(RB(e,n));return r?r.place:[...t.values()].findLast(e=>e.url===n)?.place??0},save:(e,n,r)=>{let i=RB(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-LB)))t.delete(e)},persist:()=>Ie(()=>e.setItem(IB,JSON.stringify([...t.values()])),void 0)}},HB={getItem:()=>null,setItem:()=>{}},UB,WB=()=>UB??=VB(Ie(()=>window.sessionStorage,void 0)??HB),GB=()=>{let{entry:e,path:t,params:n}=Ih(),r=`${t}?${n.toString()}`,i=WB();(0,I.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,I.useCallback)(t=>i.save(e,r,t),[i,e,r]);return{initialIndex:i.placeOf(e,r),remember:a}},KB=e=>e.reduce((e,t)=>e+t.count,0),qB=e=>{let t=Math.floor(e.length/2),n=KB(e.slice(0,t)),r=KB(e.slice(e.length-t));return n===0?0:(r-n)/n*100},JB=({active:e,payload:t,noun:n})=>{let r=t?.[0]?.payload;return!e||!r?null:(0,B.jsxs)(`div`,{className:`rounded-md border bg-background px-2.5 py-1.5 text-xs shadow-pop`,children:[(0,B.jsx)(`div`,{className:`text-muted-foreground`,children:pp(r.at)}),(0,B.jsxs)(`div`,{className:`font-semibold tabular-nums`,children:[kp(r.count),` `,n]})]})},YB=M(`activity-chart`),XB={fontSize:11,fill:`var(--muted-foreground)`},ZB=({title:e,noun:t,defaultGranularity:n=`day`,data:r,granularity:i,onGranularityChange:o,periodLabel:s,className:l})=>{let[u,d]=(0,I.useState)(n),f=i??u,m=o??d,h=bf(`(min-width: 640px)`),_=qB(r);return(0,B.jsxs)(`section`,{className:P(`rounded-lg border bg-background px-4 pb-2 pt-3`,l),children:[(0,B.jsxs)(`header`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,B.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,B.jsx)(`h2`,{className:`font-semibold`,children:e}),(0,B.jsx)(`span`,{className:`font-semibold tabular-nums`,children:kp(KB(r))}),(0,B.jsxs)(`span`,{className:P(`text-xs font-medium tabular-nums`,_>=0?`text-success-text`:`text-danger-text`),children:[_>=0?`+`:`−`,Math.abs(_).toFixed(1),`%`]}),(0,B.jsx)(`span`,{className:`hidden text-xs text-muted-foreground sm:inline`,children:s??`last ${f===`day`?`30 days`:`12 weeks`}`})]}),(0,B.jsx)(Re,{value:f,onChange:m,options:[{value:`day`,label:YB(`day`)},{value:`week`,label:YB(`week`)}]})]}),(0,B.jsx)(`div`,{className:`mt-2 h-24`,children:(0,B.jsx)(g,{width:`100%`,height:`100%`,children:(0,B.jsxs)(c,{data:r,margin:{top:4,right:0,bottom:0,left:0},barCategoryGap:f===`day`?`22%`:`30%`,children:[(0,B.jsx)(v,{vertical:!1,stroke:`var(--border)`}),(0,B.jsx)(a,{dataKey:`at`,padding:{left:4,right:h?4:18},tickFormatter:mp,tick:XB,axisLine:!1,tickLine:!1,interval:f===`day`?h?4:9:h?1:3,height:18}),(0,B.jsx)(pe,{width:h?36:28,tick:XB,axisLine:!1,tickLine:!1,tickCount:3}),(0,B.jsx)(p,{cursor:{fill:`var(--muted)`},content:(0,B.jsx)(JB,{noun:t}),isAnimationActive:!1}),(0,B.jsx)(fe,{dataKey:`count`,fill:`var(--primary)`,radius:[2,2,0,0],isAnimationActive:!1})]})})})]})},QB={"7d":`last 7 days`,"30d":`last 30 days`,"90d":`last 90 days`,"1y":`last year`,all:`all time`},$B=({resource:e,chart:t,title:n,noun:r,filter:i})=>{let[a,o]=(0,I.useState)(t.granularity===`week`?`week`:`day`),s=a===`week`?`90d`:t.range,c=Vy(e,{field:t.field,range:s,granularity:a,filter:i,timeZone:Xf()}).data?.points.map(e=>({at:Date.parse(`${e.bucket}Z`),count:e.count}))??[];return(0,B.jsx)(ZB,{title:n,noun:r,data:c,granularity:a,onGranularityChange:o,periodLabel:a===`week`?`last 12 weeks`:QB[s]})},eV=(e,t,n)=>{let r=e.sum??e.average;if(r===void 0)return n;let i=t?.fields[r]?.label??F(r);return e.sum===void 0?q(`average`,{label:i}):`${i}`},tV=({model:e,view:t,chart:n,plural:r,filter:i})=>{let a=t?.fields[n.groupBy]?.label??F(n.groupBy);return(0,B.jsxs)(`section`,{className:`rounded-lg border bg-background px-4 pb-3 pt-3`,"aria-label":`${eV(n,t,r)} by ${a.toLowerCase()}`,children:[(0,B.jsxs)(`h2`,{className:`mb-2 font-semibold`,children:[eV(n,t,r),` by `,a.toLowerCase()]}),(0,B.jsx)(Cb,{model:e,view:t,groupBy:n.groupBy,type:n.type,sum:n.sum,average:n.average,limit:n.limit,filter:i})]})},nV=({value:e,onCommit:t,placeholder:n,className:r})=>{let[i,a]=(0,I.useState)(e);return(0,I.useEffect)(()=>a(e),[e]),(0,I.useEffect)(()=>{if(i===e)return;let n=setTimeout(()=>t(i),350);return()=>clearTimeout(n)},[i,e,t]),(0,B.jsx)(J,{wrapperClassName:P(`min-w-0 flex-1 sm:w-72 sm:flex-initial`,r),leading:(0,B.jsx)(cs,{className:`size-4`}),placeholder:n,"aria-label":vB(`search`),value:i,onChange:e=>a(e.target.value),onKeyDown:e=>e.key===`Enter`&&t(i)})},rV=e=>new Set((e.userMenu?.items??[]).flatMap(e=>e.kind===`resource`?[e.resource]:e.kind===`page`?[e.page]:[])),iV=(e,t,n)=>(e.userMenu?.items??[]).map((r,i)=>{if(r.kind===`link`)return{id:`link-${i}`,label:r.label,icon:DL(r.icon,da),href:r.href,external:!0};if(r.kind===`page`){let i=e.pages[r.page];return{id:r.page,label:r.label??i?.title??F(r.page),icon:DL(r.icon??i?.icon,Ua),href:Vc({kind:`page`,page:r.page},t),active:r.page===n}}return{id:r.resource,label:r.label??e.views[r.resource]?.names?.plural??F(r.resource),icon:DL(r.icon,OL(e,r.resource)),href:Vc({kind:`list`,resource:r.resource},t),active:r.resource===n}}),aV=(e,t)=>t===void 0?e:`${e}/${t}`,oV={sales:`sales`,crm:`crm`,catalog:`catalog`,inventory:`inventory`,core:`admin`,hr:`hr`},sV=(e=`public`)=>e===`public`?``:oV[e]?q(oV[e]):F(e),cV=(e,t,n,r,i)=>!n?.create||!aR(t,e.pages,e.permissions[t.resource]??Jd)?{}:{create:{label:n.create===!0?Mg(`title`,{noun:r}):n.create.label,href:Vc({kind:`create`,resource:t.resource},i)}},lV=(e,t=``,n={})=>{let r=new Map,i=new Map,a=rV(e);for(let n of Object.values(e.pages)){if(n.nav?.hidden||a.has(n.name))continue;let e=n.nav?.group??q(`pages`),o=r.get(e)??{label:e,items:[]};o.items.push({id:n.name,label:n.title,icon:DL(n.icon,Ua),href:Vc({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??sV(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)};s.nav?.hidden||l(c,{id:aV(o.name),label:s.names?.plural??F(o.name),icon:OL(e,o.name),href:Vc({kind:`list`,resource:o.name},t),...n[o.name]&&{recent:n[o.name]},...cV(e,s,s.nav,s.names?.singular??F(o.name),t)},s.nav?.order);for(let n of s.lists??[])n.nav?.hidden||l(n.nav?.group??c,{id:aV(o.name,n.name),label:n.names.plural,icon:OL(e,o.name),href:Vc({kind:`list`,resource:o.name,list:n.name},t),...cV(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??q(`account`),s=r.get(o)??{label:o,items:[]};s.items.push({id:n.resource,label:n.names?.plural??F(n.resource),icon:OL(e,n.resource),href:Vc({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:F(r),icon:Rs,href:Vc({kind:`list`,resource:r},t),problem:q(`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))}))},uV=(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 Er(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??F(n.name);return[{id:n.name,header:c,kind:`text`,width:160,minWidth:$p(c,!1),sortable:!1,render:e=>(0,B.jsx)(FE,{column:n,records:e[n.name]??[],target:s,view:i[s.name],Card:nD})}]})},dV=({model:e,view:t,target:n,children:r})=>{let i=vE(e.name,t.listOf,!0),a=t.names?.plural??F(e.name),o=e=>(0,B.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 px-5 py-4`,children:[(0,B.jsx)(DS,{title:a,subtitle:t.help}),e]});if(i.error)return o((0,B.jsx)(Gg,{title:yE(`couldNotLoadYour`,{plural:a.toLowerCase()}),error:i.error}));if(!i.data)return o((0,B.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(15rem,1fr))] gap-3`,children:Array.from({length:3},(e,t)=>(0,B.jsx)(Ch,{className:`h-24`},t))}));let s=gE(n,i.data);return s?r(s):o((0,B.jsx)(`p`,{className:`py-8 text-center text-muted-foreground`,children:yE(`noneYet`,{plural:a.toLowerCase()})}))},fV=({title:e,chips:t,label:n,required:r,initial:i=``,busy:a,onSave:o,onClose:s})=>{let c=(0,I.useId)(),[l,u]=(0,I.useState)(i),d=`${c}-form`;return(0,B.jsx)(jf,{open:!0,title:e,onClose:s,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:s,children:Y(`cancel`)}),(0,B.jsx)(G,{type:`submit`,form:d,variant:`primary`,loading:a,children:Y(`save`)})]}),children:(0,B.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,B.jsx)(Mw,{chips:t}),(0,B.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,B.jsxs)(`div`,{className:`flex items-baseline justify-between gap-2`,children:[(0,B.jsx)(`label`,{htmlFor:c,className:`font-medium`,children:n}),!r&&(0,B.jsx)(`span`,{id:`${c}-hint`,className:`text-xs text-muted-foreground`,children:Y(`optional`)})]}),(0,B.jsx)(J,{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)})]})]})})},pV=sn(),mV={start:0,end:0},hV=(e,t)=>pV.and(t,{kind:`present`,field:e.field,span:mV}),gV=e=>{switch(e.kind){case`and`:case`or`:return{...e,args:e.args.map(gV)};case`not`:return _V(e.arg);case`search`:case`present`:case`isNull`:return e;default:return hV(e,e)}},_V=e=>{switch(e.kind){case`and`:return pV.or(...e.args.map(_V));case`or`:return pV.and(...e.args.map(_V));case`not`:return gV(e.arg);case`search`:case`present`:case`isNull`:return pV.not(e);default:return hV(e,pV.not(e))}},vV=e=>{let t=it(e);if(!t.ok)throw Error(`The filter cannot be read: ${t.errors.map(e=>e.message).join(`; `)}`);return t.ast},yV=(e,t)=>{let n=vV(e);if(!n)return null;let r=vV(t),i=pV.not(gV(n));return Yt(r?pV.and(r,i):i)},bV=(e,t)=>yV(t,e),xV=e=>e.key.startsWith(`extra:`)?`extra:${e.label}`:e.key,SV=(e,t)=>{let n=new Map(e.map(e=>[xV(e),e])),r=new Map(t.map(e=>[xV(e),e])),i=e.filter(e=>!r.has(xV(e))).map(e=>({kind:`removed`,label:e.label})),a=t.flatMap(e=>{let t=n.get(xV(e));return t&&t.label!==e.label?[{kind:`changed`,label:e.label,before:t.label}]:[]}),o=t.filter(e=>!n.has(xV(e))).map(e=>({kind:`added`,label:e.label}));return[...i,...a,...o]},CV=(e,t,n,r)=>{let i=e-t;if(i===0)return Y(`asMany`,{plural:r});let a=Math.abs(i)===1?n:r;return i>0?Y(`more`,{count:i,noun:a}):Y(`fewer`,{count:-i,noun:a})},wV=12,TV={added:{word:`added`,className:`text-success-text`},removed:{word:`removed`,className:`text-danger-text`},changed:{word:`changed`,className:`text-primary-text`}},EV=({changes:e})=>(0,B.jsx)(`ul`,{"aria-label":Y(`filterChanges`),className:`divide-y rounded-md border`,children:e.map(e=>(0,B.jsxs)(`li`,{className:`grid grid-cols-[72px_1fr] gap-3 px-3 py-2`,children:[(0,B.jsx)(`span`,{className:`font-medium ${TV[e.kind].className}`,children:Y(TV[e.kind].word)}),e.kind===`changed`?(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`span`,{className:`text-muted-foreground line-through`,children:e.before}),` `,(0,B.jsx)(`span`,{className:`font-medium`,children:e.label})]}):(0,B.jsx)(`span`,{className:e.kind===`removed`?`text-muted-foreground line-through`:`font-medium`,children:e.label})]},`${e.kind}:${e.label}`))}),DV=(e,t)=>{let n=E({...wy(U(),e,t??``),enabled:t!==null});return t===null?0:n.data},OV=(e,t,n)=>`${e} ${e===1?t:n}`,kV=({model:e,view:t,title:n,filter:r,total:i,plural:a})=>{let o=t?.list?.displays?.find(e=>e.kind===`cards`);return(0,B.jsxs)(`section`,{"aria-label":n,className:`flex flex-col gap-2`,children:[(0,B.jsxs)(`h3`,{className:`font-semibold`,children:[n,` `,(0,B.jsxs)(`span`,{className:`font-normal text-muted-foreground`,children:[`(`,i??`…`,`)`]})]}),i!==void 0&&i>wV&&(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:Y(`firstOf`,{limit:wV,total:i})}),r===null||i===0?(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:Y(`noPlural`,{plural:a})}):(0,B.jsx)(PA,{model:e,view:t,filter:r,sort:gh(e,t),limit:wV,display:o?.name??`table`,row:!0,link:!1,empty:`No ${a}.`})]})},AV=({model:e,view:t,title:n,before:r,after:i,saveNewLabel:a,updating:o,creating:s,onUpdate:c,onSaveNew:l,onCancel:u})=>{let d=SV(eE(e,r),eE(e,i)),f=(0,I.useMemo)(()=>yV(r,i),[r,i]),p=(0,I.useMemo)(()=>bV(r,i),[r,i]),m=DV(e,f),h=DV(e,p),g=(t?.names?.singular??F(e.name)).toLowerCase(),_=(t?.names?.plural??F(e.name)).toLowerCase(),v=m!==void 0&&h!==void 0;return(0,B.jsx)(jf,{open:!0,wide:!0,title:n,onClose:u,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:u,children:Y(`cancel`)}),(0,B.jsx)(G,{loading:s,disabled:o,onClick:l,children:a}),(0,B.jsx)(G,{variant:`primary`,loading:o,disabled:s,onClick:c,children:Y(`update`)})]}),children:(0,B.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[d.length>0&&(0,B.jsx)(EV,{changes:d}),v?(0,B.jsxs)(`p`,{children:[(0,B.jsx)(`span`,{className:`font-semibold`,children:CV(m,h,g,_)}),(0,B.jsxs)(`span`,{className:`text-muted-foreground`,children:[`: `,Y(`addedRemoved`,{added:OV(m,g,_),removed:h})]})]}):(0,B.jsx)(Ch,{className:`h-4 w-48`}),(0,B.jsx)(kV,{model:e,view:t,title:Y(`added`),filter:f,total:m,plural:_}),(0,B.jsx)(kV,{model:e,view:t,title:Y(`removed`),filter:p,total:h,plural:_})]})})},jV=()=>{let{address:e,set:t}=qh();return{key:e?.kind===`list`?e.savedSearch:void 0,open:e=>t({savedSearch:e})}},MV=e=>e instanceof Error?e.message:Y(`somethingWrong`),NV=(e,t)=>{let n=W(),r=U(),i=ly(),a=Oy(),{href:s,open:c}=qh(),l=jV(),{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&&dy(p,`create`)&&dy(p,`delete`),h=n.signIn?.[u]?.signIn,g=yD(u,m),_=e=>Nn(wm(d,e)),v=f&&g.data?.find(e=>e[f.filter]===t),y=v||l.key===void 0||!p||!dy(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=o({mutationFn:e=>r.create(u,{[f.filter]:t,...f.name&&{[f.name]:e}}),onSuccess:e=>{l.open(_(e.record)),i.show({state:`success`,title:Y(`searchSaved`),action:{label:Y(`openPlural`,{plural:x}),href:s({kind:`list`,resource:u}),onNavigate:c}})},onError:e=>i.show({state:`error`,title:Y(`couldNotSave`),description:MV(e)}),onSettled:()=>a(u)}),w=o({mutationFn:e=>r.remove(u,_(e)),onError:e=>i.show({state:`error`,title:Y(`couldNotTakeOff`),description:MV(e)}),onSettled:()=>a(u)}),T=o({mutationFn:e=>r.update(u,_(e),{[f.filter]:t},e.etag??`*`),onSuccess:()=>i.show({state:`success`,title:Y(`searchUpdated`)}),onError:e=>i.show({state:`error`,title:Y(`couldNotUpdate`),description:MV(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??F(u)).toLowerCase(),naming:S&&{label:n.views[u]?.fields[S.name]?.label??F(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)}},PV=({model:e,view:t,search:n,filter:r,chips:i,className:a})=>{let o=NV(n,r),[s,c]=(0,I.useState)(!1),[l,u]=(0,I.useState)(!1),[d,f]=(0,I.useState)();if(!o.mode)return null;let p=n.label??Y(`saveSearch`);if(o.mode===`sign-in`)return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(G,{className:a,"aria-haspopup":`dialog`,onClick:()=>c(!0),children:[(0,B.jsx)(di,{className:`size-3.5`,"aria-hidden":!0}),p]}),(0,B.jsx)(lE,{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,B.jsx)(fV,{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=Y(`saveAsNew`,{noun:o.noun});return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(G,{className:a,"aria-haspopup":`dialog`,"aria-disabled":!o.ready,onClick:()=>o.ready&&u(!0),children:[(0,B.jsx)(ns,{className:`size-3.5`,"aria-hidden":!0}),(0,B.jsx)(`span`,{className:`max-w-60 truncate`,children:Y(`updateName`,{name:g.name??o.noun})})]}),(0,B.jsxs)(G,{className:a,"aria-haspopup":o.naming?`dialog`:void 0,"aria-disabled":!o.ready,onClick:()=>o.ready&&m(n),children:[(0,B.jsx)(li,{className:`size-3.5`,"aria-hidden":!0}),n]}),l&&(0,B.jsx)(AV,{model:e,view:t,title:g.name?Y(`updateNameQuestion`,{name:g.name}):Y(`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?si:di;return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(G,{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,B.jsx)(_,{className:o.saved?`size-3.5 text-primary`:`size-3.5`,"aria-hidden":!0}),p]}),h]})},FV=e=>e instanceof Error?e.message:Y(`somethingWrong`),IV=({model:e,view:t,name:n,value:r,onChange:i})=>{let a=(0,I.useId)(),o=e.fields[n],s=t.fields[n],c=s?.label??F(n);if(o?.type===`boolean`)return(0,B.jsx)(Kg,{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,B.jsxs)(`label`,{htmlFor:a,className:`flex items-center gap-2 text-muted-foreground`,children:[c,(0,B.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,B.jsx)(`option`,{value:e,children:ar(e,s?.valueLabels)},e))})]})},LV=(e,t,n)=>Object.entries(n).map(([n,r])=>`${t.fields[n]?.label??F(n)}: ${e.fields[n]?.type===`boolean`?Y(r===!0?`on`:`off`):ar(String(r),t.fields[n]?.valueLabels)}`).join(`, `),RV=({model:e,view:t,recordKey:n,title:r,row:i,fields:a})=>{let s=U(),c=ly(),l=Oy(),u=o({mutationFn:t=>s.update(e.name,n,t,i.etag??`*`),onSuccess:(n,i)=>c.show({state:`success`,title:Y(`saved`,{title:r}),description:LV(e,t,i)}),onError:e=>c.show({state:`error`,title:Y(`couldNotChange`),description:FV(e)}),onSettled:()=>l(e.name)});return(0,B.jsx)(`div`,{className:`flex flex-wrap items-center gap-3`,children:a.map(n=>(0,B.jsx)(IV,{model:e,view:t,name:n,value:u.isPending&&n in(u.variables??{})?u.variables[n]:i[n],onChange:e=>u.mutate({[n]:e})},n))})},zV=e=>e instanceof Error?e.message:Y(`somethingWrong`),BV=({model:e,view:t,of:n,target:r,targetView:i,row:a,recordKey:s,canRename:c,onDelete:l})=>{let u=U(),d=ly(),f=Oy(),[p,m]=(0,I.useState)(!1),{name:h,chips:g,title:_,body:v}=bD({model:e,of:n,target:r,targetView:i,row:a,recordKey:s}),y=o({mutationFn:t=>u.update(e.name,s,{[n.name]:t},a.etag??`*`),onSuccess:()=>m(!1),onError:e=>d.show({state:`error`,title:Y(`couldNotRename`),description:zV(e)}),onSettled:()=>f(e.name)}),b=n.name===void 0?void 0:e.fields[n.name];return(0,B.jsxs)(`section`,{"aria-label":_,className:`flex flex-col gap-3 rounded-lg border bg-surface p-4`,children:[(0,B.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,B.jsx)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:(0,B.jsx)(`h2`,{className:`text-[16px] font-semibold`,children:(0,B.jsx)(Jh,{to:{kind:`record`,resource:e.name,key:s},className:`hover:underline`,children:h??(0,B.jsx)(Nw,{chips:g})})})}),(0,B.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[n.controls&&(0,B.jsx)(RV,{model:e,view:t,recordKey:s,title:_,row:a,fields:n.controls}),c&&b&&(0,B.jsx)(G,{variant:`ghost`,"aria-label":Y(`renameTitle`,{title:_}),"aria-haspopup":`dialog`,onClick:()=>m(!0),children:(0,B.jsx)(Ro,{className:`size-3.5`,"aria-hidden":!0})}),l&&(0,B.jsx)(G,{variant:`ghost`,"aria-label":Y(`deleteTitle`,{title:_}),onClick:()=>l(_),children:(0,B.jsx)(Js,{className:`size-3.5`,"aria-hidden":!0})})]})]}),p&&b&&(0,B.jsx)(fV,{title:Y(`renameTitle`,{title:_}),chips:g,label:t.fields[b.name]?.label??F(b.name),required:!b.nullable,initial:h,busy:y.isPending,onSave:e=>y.mutate(e),onClose:()=>m(!1)}),(0,B.jsx)(gD,{...v})]})},VV=({model:e,view:t})=>{let{resources:n,views:r}=W(),i=t.searchesOf,a=n[i.resource],o=r[i.resource],s=yD(e.name,!0),c=uf(e.name),l=rR({model:e,view:t}),u=t.names?.plural??F(e.name),d=e=>(0,B.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 px-5 py-4`,children:[l.dialogs,(0,B.jsx)(DS,{title:u,subtitle:t.help}),e]});if(!a)return d((0,B.jsx)(sf,{title:Y(`notFound`),children:Y.rich(`noResource`,{resource:i.resource})}));if(s.error)return d((0,B.jsx)(Gg,{title:Y(`couldNotLoadYour`,{plural:u.toLowerCase()}),error:s.error}));if(!s.data)return d((0,B.jsx)(`div`,{className:`flex flex-col gap-3`,children:Array.from({length:2},(e,t)=>(0,B.jsx)(Ch,{className:`h-56`},t))}));if(s.data.length===0){let e=(o?.names?.plural??F(a.name)).toLowerCase();return d((0,B.jsx)(`p`,{className:`py-8 text-center text-muted-foreground`,children:Y.rich(`noSavedYet`,{plural:u.toLowerCase(),list:(0,B.jsx)(Jh,{to:{kind:`list`,resource:a.name},className:`font-medium text-primary-text hover:underline`,children:e})})}))}return d((0,B.jsx)(`div`,{className:`flex flex-col gap-4`,children:s.data.map(n=>{let r=Nn(wm(e,n)),s=dy(c,`delete`)?e=>void l.start({key:r,title:e,etag:n.etag,snapshot:n}):void 0;return(0,B.jsx)(BV,{model:e,view:t,of:i,target:a,targetView:o,row:n,recordKey:r,canRename:dy(c,`update`),onDelete:s},r)})}))},HV=({field:e,hints:t,resource:n,stored:r,onSave:i,close:a})=>{let[o,s]=(0,I.useState)(()=>Eg(e,r)),c=(0,I.useRef)(null),l=(0,I.useRef)(!1),u=!t?.widget&&(e.type===`boolean`||e.type===`enum`);(0,I.useEffect)(()=>{c.current?.querySelector(`input, select, textarea, button, [tabindex]`)?.focus()},[]);let d=(t,n,s=o)=>{l.current||(l.current=!0,t&&Dg(e,s,r)&&i(wg(e,s)),a(n))};return(0,B.jsx)(`div`,{ref:c,className:`w-full min-w-0`,onKeyDown:e=>{kv(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)&&!kv(e.relatedTarget)&&d(!0)},children:(0,B.jsx)(Nv,{field:e,hints:t,value:o,stored:r,resource:n,onChange:e=>{s(e),u&&d(!0,void 0,e)}})})},UV=M(`app/list-edit`),WV=e=>{let t=U(),n=Se(),r=ly(),[i,a]=(0,I.useState)(new Map),o=(0,I.useRef)(i),s=(0,I.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=wm(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(H.record(e.name,Nn(l)),r),n.invalidateQueries({queryKey:[`page`,e.name]}),n.invalidateQueries({queryKey:[`list`,e.name]}),n.invalidateQueries({queryKey:[`map`,e.name]})}catch(n){if(!ml(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:UV(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}}},GV=(e,t,n)=>{let r=WV(e),i=t?.list?.editable??[];return{editor:i.length>0&&dy(n,`update`)?{editable:(t,n)=>i.includes(n)&&e.fields[n]!==void 0&&yg(e.fields[n])&&fy(t,`update`),render:(n,i,a)=>(0,B.jsx)(HV,{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}},KV=(e,t,{href:n,go:r})=>{if(`to`in e){let i=mn(e.to,t);return{href:n(i),onFollow:()=>r(i)}}let i=_y(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)}},qV=(e,t)=>({model:e,record:Object.fromEntries(Object.entries(hh(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}}),JV=e=>{let{views:t}=W(),n=Ay(e.name,void 0),r=qh(),[i,a]=(0,I.useState)(),o=(t[e.name]?.actions??[]).filter(e=>!e.inputs?.length),s=e=>`row`in e?n.run(e.action,e.row):n.runEach(e.action,e.selection,e.skipped),c=e=>{e.action.confirm?a(e):s(e)};return{rowActions:o.map(t=>{let i=n=>xy(t,qV(e,n).record),a={label:e=>i(e)?.label??t.label,destructive:Yv(t)},o=t.run,s=r=>n.blockedOn(t,qV(e,r)),l=e=>i(e)!==void 0;return o?.kind===`link`?{...a,available:l,blocked:s,link:t=>KV(o,qV(e,t).record,r)}:{...a,available:l,blocked:s,onSelect:n=>c({action:t,row:qV(e,n)})}}),bulkActions:o.filter(e=>e.bulk&&e.run?.kind!==`link`).map(t=>({label:e=>vB(`actionCount`,{label:t.label,count:e}),destructive:Yv(t),available:r=>n.appliesOn(t,qV(e,r)),onRun:(n,r)=>c({action:t,selection:n.map(t=>qV(e,t)),skipped:r})})),prompt:i&&(0,B.jsx)(Jv,{action:i.action,label:i.action.label,danger:Yv(i.action),onCancel:()=>a(void 0),onConfirm:()=>{a(void 0),s(i)}})}},YV=(e,t,n)=>({order:r,index:i})=>{let a=t=>r.findIndex(n=>Nn(wm(e,n))===t),o=t.after.find(e=>a(e.key)>i);if(o)return fO(`dependsOn`,{record:n,other:o.title});let s=t.before.find(e=>a(e.key)!==-1&&a(e.key)<i);return s?fO(`dependsOn`,{record:s.title,other:n}):void 0},XV=(e,t,n,r)=>{let i=e[t],a;for(let o=n;o<e.length;o++){let n=r({record:i,order:ee(e,t,o),index:o});if(n===void 0)return{to:o,...a!==void 0&&{reason:a}};a??=n}return{to:t,reason:a}},ZV=({model:e,view:t,field:n,filter:r,fields:i,rule:a})=>{let o=U(),s=ly(),c=Oy(),{resources:l,views:u}=W(),d=`${n} asc`,f=E({queryKey:[...H.list(e.name,r,d,500,`hand-order`),i.join(`,`)],queryFn:async()=>{let t=Ob(l,u,e,i),n=[],a=``;do{let s=await o.search(e.name,{filter:r||void 0,orderBy:d,pageSize:500,labels:t,...a&&{pageToken:a}});n.push(...kb(l,e,i,s.items,s.labels).map((t,n)=>({...t,id:Cm(e,s.items[n])}))),a=s.nextPageToken}while(a);return n}}),[p,m]=(0,I.useState)(),h=(0,I.useRef)(void 0),g=(0,I.useRef)(void 0),_=(0,I.useRef)(Promise.resolve()),v=(0,I.useRef)(0),y=(0,I.useRef)(void 0),b=async()=>{let t=h.current,r=g.current;if(g.current=void 0,!t||!r)return;let i=oO(t.map(e=>e[n]),r.first,r.last),a=t.slice(i.first,i.last+1),c=Object.fromEntries(a.flatMap(t=>typeof t.etag==`string`?[[Nn(wm(e,t)),t.etag]]:[])),l=(await o.batchWrite([{op:`reorder`,resource:e.name,field:n,keys:a.map(t=>wm(e,t)),start:i.start,etags:c}])).results[0];if(l?.op!==`reorder`)return;let u=new Map(a.map(e=>[e.id,{[n]:e[n]}])),d=tO(e,l.records.map(t=>({...t,before:u.get(Cm(e,t.record))??{}})),[n]);if(y.current!==void 0&&s.dismiss(y.current),y.current=s.show({state:`success`,title:eO(`orderChanged`),action:{label:eO(`undo`),onClick:()=>D(d)}}),!h.current)return;let f=new Map(l.records.map(t=>[Cm(e,t.record),t]));h.current=h.current.map(e=>{let t=f.get(e.id);return t?{...e,[n]:t.record[n],etag:t.etag}:e})},x=e=>t=>{h.current=void 0,g.current=void 0,m(void 0),s.show({state:`error`,title:e,description:Jm(t)})},S=async()=>{--v.current,!(v.current>0)&&(await c(e.name),!(v.current>0)&&(h.current=void 0,m(void 0)))},C=(n,r)=>{let i=h.current??f.data;if(!i||n===r)return;if(!e.position?.after)return w(i,n,r,a);let s=hh(e,i[n]).record,c=i[n].id;iO(o,e,t,s).then(n=>{let i=h.current??f.data,o=YV(e,n,ur(e,t,s,c));w(i,i.findIndex(e=>e.id===c),r,e=>o(e)??a?.(e))},x(eO(`couldNotChange`)))},w=(e,t,n,r)=>{if(t===-1||t===n)return;let i=r?T(e,t,n,r):n;if(t===i)return;h.current=ee(e,t,i);let a=Math.min(t,i),o=Math.max(t,i);g.current=g.current?{first:Math.min(g.current.first,a),last:Math.max(g.current.last,o)}:{first:a,last:o},m(h.current),v.current+=1,_.current=_.current.then(b).catch(x(eO(`couldNotChange`))).then(S)},T=(t,n,r,i)=>{let a=XV(t.map(t=>hh(e,t).record),n,r,i);return a.reason!==void 0&&s.show({state:`warning`,title:a.to===n?eO(`notMoved`):eO(`movedToPlace`,{place:a.to+1}),description:a.reason}),a.to},D=e=>{y.current!==void 0&&s.dismiss(y.current),y.current=void 0,v.current+=1,_.current=_.current.then(async()=>{await o.batchWrite(e),h.current=void 0,g.current=void 0,m(void 0)}).catch(x(eO(`couldNotUndo`))).then(S)};return{rows:p??f.data,loading:f.isPending,error:f.error,move:C}},QV=({model:e,view:t,field:n,filter:r,columns:i,sort:a})=>{let{resources:o,views:s}=W(),{fields:c,dropRules:l}=p_(),{go:u,href:d}=qh(),f=a!==void 0,p=(0,I.useMemo)(()=>TA(e,t,i,{resources:o,views:s,fieldTypes:c}).map(e=>f?e:{...e,sortable:!1}),[e,t,i.join(`,`),o,s,c,f]),m=(0,I.useMemo)(()=>fh(e,t,p.map(e=>e.id)),[e,t,p]),h=t?.list?.drag?.rule,g=h===void 0?void 0:l?.[h],_=ZV({model:e,view:t,field:n,filter:r,fields:m,...g&&{rule:g}}),v=_.rows,y=(0,I.useMemo)(()=>v&&{total:v.length,rowAt:e=>v[e]},[v]);if(h!==void 0&&!g)return(0,B.jsx)(dv,{children:eO.rich(`noRule`,{rule:h})});if(_.loading)return(0,B.jsx)(`div`,{className:`flex flex-col gap-2`,children:Array.from({length:3},(e,t)=>(0,B.jsx)(Ch,{className:`h-4 w-full`},t))});if(_.error)return(0,B.jsx)(Gg,{title:eO(`couldNotLoad`),error:_.error});if(!y||y.total===0)return(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:eO(`nothingYet`)});let b=t=>u({kind:`record`,resource:e.name,key:wm(e,t)});return(0,B.jsx)(yw,{fit:!0,scroll:`parent`,columns:p,source:y,latencyMs:0,onOpenRow:b,rowLink:t=>({href:d({kind:`record`,resource:e.name,key:wm(e,t)}),onFollow:()=>b(t)}),...a&&{sort:a.value,onSortChange:a.onChange},rowNumbers:!1,reorder:{label:n=>ur(e,t,n,n.id),onMove:_.move}})},$V=({sorting:e,onChange:t,size:n,iconOnly:r=!1})=>{let i=eO(e?`done`:`reorder`);return(0,B.jsxs)(G,{size:n,variant:e?`primary`:`secondary`,onClick:()=>t(!e),...r&&{"aria-label":i,title:i},children:[e?(0,B.jsx)(Ci,{className:`size-3.5`}):(0,B.jsx)(Vr,{className:`size-3.5`}),!r&&i]})},eH=sn(),tH=e=>e.find(e=>e.kind===`search`),nH=({address:e})=>{let{resources:t,views:n,signIn:r}=W(),i=t[e.resource],a=r?.[e.resource];if(!i)return a?(0,B.jsx)(lE,{as:`page`,prompt:a.signIn}):(0,B.jsx)(sf,{title:q(`notFound`),children:q(`noResource`,{name:e.resource})});let o=Cn(n[e.resource],e.list);if(e.list!==void 0&&!o)return(0,B.jsx)(sf,{title:q(`notFound`),children:vB(`noList`,{name:e.list})});if(o?.searchesOf)return(0,B.jsx)(VV,{model:i,view:o});let s=yh(t,n,e.resource,e.list);if(o&&s.listOf){let t=s.model;return(0,B.jsx)(dV,{model:i,view:o,target:t,children:n=>(0,B.jsx)(rH,{model:t,address:e,scope:n,heading:{title:o.names?.plural??F(i.name),subtitle:o.help}})})}return(0,B.jsx)(rH,{model:i,address:e})},rH=({model:e,address:t,scope:n,heading:r})=>{let i=W(),{set:a,listTo:o,go:s,href:c}=qh(),l=e.name,u=Cn(i.views[l],t.list),d=(0,I.useMemo)(()=>UT(u,e),[u,e]),{fields:f}=p_(),p=(0,I.useMemo)(()=>uV(xA(vA(Im(e,u),e,u,f),e,i.resources,i.views),e,u,i.resources,i.views),[e,u,f,i.resources,i.views]),m=t.filter,h=(0,I.useMemo)(()=>LT(d,m),[d,m]),g=h.ok?h.state:Hw,_=h.ok?h.extras:[],{orderBy:v,filterLayout:y}=t,b=xf(),x=Sf(),[S,C]=(0,I.useState)(!1),w=n?[..._,n]:_,T=v_(),E=KL({model:e,resources:i.resources,views:i.views,view:u,state:g,extras:w,titleOf:T}),D=n?AT(d,g,w):h.ok?m:``,O=(0,I.useMemo)(()=>fh(e,u,p.map(e=>e.id)),[e,u,p]),k=(0,I.useMemo)(()=>EE(u,i.resources,i.views,O),[u,i.resources,i.views,O]),A=Aw({resources:i.resources,views:i.views,model:e,columns:O,filter:D,orderBy:v,related:k}),j=th(e,u,t.display),ee=uf(l),te=n?void 0:FD(e,ee),[ne,re]=(0,I.useState)(!1),ie=ne&&te!==void 0,ae=!j&&!ie&&LD(u,te,v,D),oe=ie||j?.kind!==`map`;Cx(oe);let se=WD(e,A.page,A.key,j?.kind===`custom`),ce=GB(),le=lr(e,u),ue=e=>({key:e.id,title:String(typeof e[le]==`object`?e[le].name:e[le]??e.id),etag:typeof e.etag==`string`?e.etag:void 0,snapshot:e}),de=u?.names?.singular??F(l),fe=GV(e,u,ee),{state:pe}=V(),me=rR({model:e,view:u,restore:iR(e),onReview:e=>s({kind:`record`,resource:l,key:e.key})}),he=JV(e),ge=u?.actions.some(e=>e.run?.kind===`delete`)??!1,_e=(e,t=_)=>a({filter:AT(d,e,t)}),ve=tH(_),ye=e=>{let t=_.filter(e=>e.kind!==`search`);_e(g,e?[...t,eH.search(e)]:t)},be=u?.names?.plural??F(l),xe=j?.kind===`calendar`||j?.kind===`timeline`||j?.kind===`board`&&Gm(e)?void 0:j,Se=xe&&(0,B.jsx)(gA,{model:e,view:u,display:xe,orderBy:v,onChange:e=>a({orderBy:e})}),Ce=e.search?.length?(0,B.jsx)(nV,{value:ve?.kind===`search`?ve.text:``,onCommit:ye,placeholder:vB(`searchPlural`,{plural:be}),className:b?void 0:`min-h-11`}):null,we=(0,B.jsx)(vT,{layout:y,config:E,value:g,onChange:_e,leading:y===`bar`?Se:void 0,trailing:Ce}),Te=y===`bar`?we:(0,B.jsx)(gT,{groups:[Se?[Se]:[]],trailing:Ce}),Ee=qw(E,g),De=(0,B.jsx)(Lw,{scroll:!0,chips:Ee,onRemove:e=>_e(Jw(g,e)),onClear:()=>_e(Hw)}),Oe=xe&&(0,B.jsx)(tT,{title:vB(`sort`),children:(0,B.jsx)(gA,{model:e,view:u,display:xe,orderBy:v,onChange:e=>a({orderBy:e}),className:`min-h-11 w-full`})}),ke=(0,B.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,B.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,B.jsxs)(G,{className:`min-h-11`,onClick:()=>C(!0),"aria-haspopup":`dialog`,children:[(0,B.jsx)(ws,{className:`size-3.5`}),Ee.length>0?vB(`filtersCount`,{count:Ee.length}):vB(`filters`)]}),Ce??(0,B.jsx)(`div`,{className:`min-w-0 flex-1`,children:De})]}),Ce&&De,(0,B.jsx)(Af,{title:vB(`filters`),open:S,onClose:()=>C(!1),children:(0,B.jsx)(vT,{layout:`panel`,fullWidth:!0,config:E,value:g,onChange:_e,leading:Oe})})]}),Ae=!n&&aR(u,i.pages,ee)&&(0,B.jsxs)(Jh,{to:{kind:`create`,resource:l},className:yf({variant:`primary`}),children:[(0,B.jsx)(Jo,{className:`size-3.5`}),vB(`newRecord`,{singular:de})]}),je=u?.saveSearch&&!n&&h.ok&&m&&(0,B.jsx)(PV,{model:e,view:u,search:u.saveSearch,filter:m,chips:XT(e,u,m,ZT(E))}),Me=!n&&(0,B.jsx)(Mz,{model:e}),Ne=_B({model:e,view:u,resources:i.resources,views:i.views,plural:be,filter:D,orderBy:v}),M=Hz(u)&&(0,B.jsxs)(G,{onClick:()=>Ne.open(),...!b&&{"aria-label":vB(`export`),title:vB(`export`)},children:[(0,B.jsx)(ra,{className:`size-3.5`}),b&&vB(`export`)]}),Pe=te&&!ae&&(0,B.jsx)($V,{sorting:ie,onChange:re,iconOnly:!b}),Fe=t=>!ie&&(0,B.jsx)(mA,{view:u,choices:ah(e,u,x),value:j?.name??`table`,onChange:e=>a({display:e}),menu:t}),Ie=nE(e),Le=t=>{Ie(hh(e,t).record),s({kind:`record`,resource:l,key:wm(e,t)})},Re=A.source?(0,B.jsx)(yw,{columns:p,source:A.source,sort:_h(v),onSortChange:e=>a({orderBy:vh(e)}),onOpenRow:Le,rowLink:t=>({href:c({kind:`record`,resource:l,key:wm(e,t)}),onFollow:()=>Le(t)}),cellEditor:fe.editor,rowPatches:fe.patches,initialScrollIndex:ce.initialIndex,onScrollIndex:ce.remember,rowActions:[{label:vB(`openRecord`,{singular:de}),onSelect:Le},...he.rowActions,...dy(ee,`delete`)&&!ge?[{label:vB(`delete`),destructive:!0,available:e=>fy(e,`delete`),onSelect:e=>void me.start(ue(e))}]:[]],bulkActions:[...Hz(u)&&Jz(e)?[{label:e=>vB(`exportCount`,{count:e}),onRun:e=>Ne.open(e)}]:[],...he.bulkActions,...dy(ee,`delete`)?[{label:e=>vB(`deleteCount`,{count:e}),destructive:!0,onRun:e=>me.startBulk(e.map(ue))}]:[]],rowNumbers:!1,pinKey:pe.kind===`signed-in`?yC(pe.user.id,aV(l,t.list)):void 0,scroll:`parent`,className:`flex-1`}):(0,B.jsx)(`div`,{className:`flex-1 rounded-lg border bg-surface`}),N={...A,initialIndex:ce.initialIndex,onScrollIndex:ce.remember},ze=bB({plural:be,search:ve?.kind===`search`?ve.text:``,filtered:Ee.length>0,scoped:!!n||_.some(e=>e.kind!==`search`),canCreate:!!Ae}),Be=(0,B.jsx)(yB,{state:ze,onClearSearch:()=>ye(``),onClearFilters:()=>_e(Hw),create:Ae}),Ve=ie?(0,B.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:vB(`dragToSort`)}),(0,B.jsx)(QV,{model:e,view:u,field:te,filter:``,columns:Er(e,u)})]}):ae?(0,B.jsx)(QV,{model:e,view:u,field:te,filter:``,columns:Er(e,u),sort:{value:_h(v),onChange:e=>a({orderBy:vh(e)})}}):j?j.kind===`cards`?(0,B.jsx)(FB,{model:e,view:u,display:j,list:N,empty:Be},A.key.join(` `)):j.kind===`map`?(0,B.jsx)(uA,{model:e,view:u,display:j,filter:D,orderBy:v,fields:O,at:t.map,onMove:e=>a({map:e}),flush:!0}):j.kind===`board`?(0,B.jsx)(_O,{model:e,view:u,display:j,fields:O,filter:D,orderBy:v}):j.kind===`calendar`?(0,B.jsx)(tk,{model:e,view:u,display:j,fields:O,filter:D,at:t.calendar,linkTo:e=>o({calendar:e})}):j.kind===`timeline`?(0,B.jsx)(Sk,{model:e,view:u,display:j,fields:O,filter:D,at:t.timeline,linkTo:e=>o({timeline:e})}):(0,B.jsx)(Mk,{display:j,list:se}):A.source?.total===0&&!A.error?Be:Re;return(0,B.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 px-5 py-4`,children:[me.dialogs,Ne.dialogs,he.prompt,(0,B.jsx)(DS,{title:r?.title??be,subtitle:r?r.subtitle:u?.help,subtitleBelow:!0,actions:(0,B.jsxs)(B.Fragment,{children:[Fe(!b),Pe,je,Me,M,Ae]})}),!h.ok&&(0,B.jsx)(Gg,{title:vB(`unreadableFilter`),error:Error(h.errors.map(e=>e.message).join(`; `))}),A.error&&!j&&!ie&&(0,B.jsx)(Gg,{title:vB(`couldNotLoadRows`),error:A.error}),u?.chart&&!ie&&(An(u.chart)?(0,B.jsx)(tV,{model:e,view:u,chart:u.chart,plural:be,filter:D}):(0,B.jsx)($B,{resource:l,chart:u.chart,title:vB(`created`,{plural:be}),noun:be.toLowerCase(),filter:D})),!ie&&(b?Te:ke),b&&y===`panel`&&!ie?(0,B.jsxs)(`div`,{className:`flex min-h-0 flex-1 gap-4`,children:[(0,B.jsx)(`div`,{className:oe?`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:we}),Ve]}):Ve]})},iH=()=>{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))}},aH=(0,I.createContext)(void 0),oH=()=>()=>{},sH=()=>void 0,cH=()=>{let e=(0,I.useContext)(aH);return(0,I.useSyncExternalStore)(e?.subscribe??oH,e?.get??sH,e?.get??sH)},lH=(e,t)=>e&&Object.hasOwn(e,t)?e[t]:void 0,uH=e=>e?.role===`owner`?[`owner`,`admin`,`member`]:[`admin`,`member`],dH=({member:e,current:t,status:n,presence:r,onChanged:i})=>{let{session:a,organizations:o}=V(),s=t.organization.id,{busy:c,error:l,run:u}=QA(),d=o?.roles??[],f=e.id===t.memberId,p=uH(t),m=e.role===`owner`&&t.role!==`owner`,h=d.filter(e=>e.membership);return(0,B.jsx)(wj,{name:e.name,email:e.email,self:f,error:l,...(n||r)&&{status:(0,B.jsx)(sS,{status:n,presence:r})},actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`select`,{"aria-label":X(`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,B.jsx)(`option`,{value:e,children:uj(e)},e))}),!f&&(0,B.jsx)(G,{size:`sm`,variant:`danger`,loading:c,disabled:m,onClick:()=>void u(async()=>{await a.organizations.removeMember(s,e.id),i()}),children:X(`remove`)})]}),children:(0,B.jsx)(rj,{roles:h,selected:e.appRoles,grantable:mj(d,t),disabled:c,onChange:t=>void u(async()=>{await a.organizations.setAppRoles(e.id,t),i()})})})},fH=({current:e,statuses:t,presence:n})=>{let{session:r}=V(),[i,a]=(0,I.useState)(),[o,s]=(0,I.useState)(),c=e?.organization?.id,l=(0,I.useCallback)(()=>{c&&r.organizations.members(c).then(a,e=>s(e instanceof ku?KA(e):X(`couldNotReadMembers`)))},[r,c]);return(0,I.useEffect)(l,[l]),e?.organization?(0,B.jsxs)(`div`,{className:`mx-auto flex w-full max-w-3xl flex-col gap-4 px-4 py-6 md:px-6`,children:[(0,B.jsx)(DS,{title:X(`members`),subtitle:X(`whoWorks`,{organization:e.organization.name})}),(0,B.jsxs)(BA,{title:X(`members`),description:X(`membersDescription`),children:[(0,B.jsx)(VA,{message:o}),i?(0,B.jsx)(`ul`,{className:`divide-y rounded-md border`,children:i.map(r=>(0,B.jsx)(dH,{member:r,current:e,status:t?.find(e=>e.userId===r.userId),presence:lH(n,r.userId),onChanged:l},`${r.id}/${r.role}/${r.appRoles.join()}`))}):!o&&(0,B.jsxs)(`div`,{className:`flex items-center gap-2 text-muted-foreground`,children:[(0,B.jsx)(af,{}),` `,X(`loading`)]})]})]}):null},pH=({current:e,onSent:t})=>{let{session:n,organizations:r}=V(),i=r?.roles??[],[a,o]=(0,I.useState)(`member`),[s,c]=(0,I.useState)([]);return(0,B.jsx)(tj,{title:X(`inviteSomeone`),description:X(`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,B.jsx)(`select`,{"aria-label":X(`organizationRole`),value:a,onChange:e=>o(e.target.value),className:`h-8 rounded-md border border-border-strong bg-background px-2`,children:uH(e).map(e=>(0,B.jsx)(`option`,{value:e,children:uj(e)},e))}),children:(0,B.jsx)(rj,{roles:i.filter(e=>e.membership),selected:s,grantable:mj(i,e),onChange:c})})},mH=({invitation:e,organizationId:t,onChanged:n})=>{let{session:r,organizations:i}=V(),a=e.appRoles.map(e=>dj(i?.roles??[],e));return(0,B.jsx)(nj,{email:e.email,gives:`${uj(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()}})},hH=({current:e})=>{let{session:t}=V(),[n,r]=(0,I.useState)([]),i=e?.organization?.id,a=(0,I.useCallback)(()=>{i&&t.organizations.invitations(i).then(e=>r(e.filter(e=>e.status===`pending`)),()=>r([]))},[t,i]);return(0,I.useEffect)(a,[a]),!e?.organization||!i?null:(0,B.jsxs)(`div`,{className:`mx-auto flex w-full max-w-3xl flex-col gap-4 px-4 py-6 md:px-6`,children:[(0,B.jsx)(DS,{title:X(`invitations`),subtitle:X(`peopleInvited`,{organization:e.organization.name})}),(0,B.jsx)(pH,{current:e,onSent:a}),(0,B.jsx)(BA,{title:X(`notAcceptedYet`),description:n.length>0?X(`sendingAgain`):X(`nobodyWaiting`),children:n.length>0&&(0,B.jsx)(`ul`,{className:`divide-y rounded-md border`,children:n.map(e=>(0,B.jsx)(mH,{invitation:e,organizationId:i,onChanged:a},e.id))})})]})},gH=({usePresence:e,store:t})=>{let n=e();return(0,I.useEffect)(()=>t.set(n),[t,n]),(0,I.useEffect)(()=>()=>t.set(void 0),[t]),null},_H=({children:e})=>{let{presence:t}=p_(),[n]=(0,I.useState)(iH),[r,i]=(0,I.useState)({hook:t,key:0});return r.hook!==t&&i({hook:t,key:r.key+1}),(0,B.jsxs)(aH.Provider,{value:n,children:[t&&(0,B.jsx)(gH,{usePresence:t,store:n},r.key),e]})},vH=e=>{let{session:t}=V(),[n,r]=(0,I.useState)(),[i,a]=(0,I.useState)([]),[o,s]=(0,I.useState)(),[c,l]=(0,I.useState)(0),u=(0,I.useCallback)(()=>l(e=>e+1),[]);return(0,I.useEffect)(()=>{e&&Promise.all([t.organizations.current(),t.organizations.list()]).then(([e,t])=>{r(e),a(t)},e=>s(e instanceof ku?KA(e):X(`couldNotReadOrganizations`)))},[e,t,c]),{current:n,organizations:i,...o&&{error:o},reload:u}},yH=e=>window.location.assign(`${e}/`),bH=({organization:e,editable:t,onSaved:n})=>{let{session:r}=V(),[i,a]=(0,I.useState)(e.name),[o,s]=(0,I.useState)(e.slug),{busy:c,error:l,run:u}=QA(),d=i.trim()!==e.name||o!==e.slug;return(0,B.jsxs)(BA,{title:X(`details`),description:X(t?`detailsEditable`:`detailsReadOnly`),children:[(0,B.jsx)(VA,{message:l}),(0,B.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,B.jsx)(J,{"aria-label":X(`name`),value:i,disabled:!t,onChange:e=>a(e.target.value),wrapperClassName:`flex-1`}),(0,B.jsx)(J,{"aria-label":X(`slug`),value:o,disabled:!t,onChange:e=>s(e.target.value),wrapperClassName:`sm:w-48`}),t&&(0,B.jsx)(G,{type:`submit`,variant:`primary`,loading:c,disabled:!d||!i.trim(),children:X(`save`)})]})]})},xH=({organization:e,memberId:t})=>{let{session:n}=V(),[r,i]=(0,I.useState)([]),[a,o]=(0,I.useState)(``),{busy:s,error:c,run:l}=QA();return(0,I.useEffect)(()=>{n.organizations.members(e.id).then(e=>i(e.filter(e=>e.id!==t)),()=>i([]))},[n,e.id,t]),(0,B.jsxs)(BA,{title:X(`handOver`),description:X(`handOverDescription`),children:[(0,B.jsx)(VA,{message:c}),(0,B.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,B.jsxs)(`select`,{"aria-label":X(`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,B.jsx)(`option`,{value:``,children:X(`chooseMember`)}),r.map(e=>(0,B.jsxs)(`option`,{value:e.id,children:[e.name,` (`,e.email,`)`]},e.id))]}),(0,B.jsx)(G,{loading:s,disabled:!a,onClick:()=>void l(async()=>{await n.organizations.transferOwnership(a),window.location.reload()}),children:X(`handOver`)})]})]})},SH=({organization:e,basePath:t})=>{let{session:n}=V(),[r,i]=(0,I.useState)(!1),[a,o]=(0,I.useState)(``),{busy:s,error:c,run:l}=QA(),u=()=>l(async()=>{await n.organizations.remove(e.id),yH(t)});return(0,B.jsxs)(BA,{title:X(`deleteOrganization`),description:X(`deleteDescription`),children:[(0,B.jsx)(VA,{message:r?void 0:c}),(0,B.jsx)(G,{variant:`danger`,onClick:()=>i(!0),children:X(`deleteOrganization`)}),r&&(0,B.jsxs)(Of,{title:X(`deleteTitle`,{name:e.name}),description:X(`deleteConfirm`),onClose:()=>i(!1),actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:()=>i(!1),children:X(`cancel`)}),(0,B.jsx)(G,{variant:`danger`,loading:s,disabled:a!==e.name,onClick:()=>void u(),children:X(`delete`)})]}),children:[(0,B.jsx)(VA,{message:c}),(0,B.jsx)(J,{"aria-label":X(`organizationName`),value:a,onChange:e=>o(e.target.value)})]})]})},CH=({editable:e})=>{let t=U(),[n,r]=(0,I.useState)(),{busy:i,error:a,run:o}=QA();return(0,I.useEffect)(()=>{t.callGuests.allowed().then(r)},[t]),n===void 0?null:(0,B.jsxs)(BA,{title:X(`guestLinks`),description:X(`guestLinksDescription`),children:[(0,B.jsx)(VA,{message:a}),(0,B.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-foreground`,children:[(0,B.jsx)(Kg,{checked:n,label:X(`guestLinksAllowed`),...e&&!i&&{onChange:e=>void o(async()=>{await t.callGuests.setAllowed(e),r(e)})}}),X(`guestLinksAllowed`)]})]})},wH=({organization:e,basePath:t,owner:n})=>{let{session:r}=V(),{busy:i,error:a,run:o}=QA();return(0,B.jsxs)(BA,{title:X(`leave`),description:X(n?`leaveOwner`:`leaveMember`),children:[(0,B.jsx)(VA,{message:a}),(0,B.jsx)(G,{loading:i,onClick:()=>void o(async()=>{await r.organizations.leave(e.id),yH(t)}),children:X(`leaveName`,{name:e.name})})]})},TH=({current:e,basePath:t,onChanged:n})=>{let r=Xd().data?.calls===!0,i=e?.organization;if(!i)return(0,B.jsx)(`div`,{className:`mx-auto w-full max-w-3xl px-4 py-6 md:px-6`,children:(0,B.jsx)(DS,{title:X(`organization`),subtitle:X(`noOrganization`)})});let a=e.role===`owner`;return(0,B.jsxs)(`div`,{className:`mx-auto flex w-full max-w-3xl flex-col gap-4 px-4 py-6 md:px-6`,children:[(0,B.jsx)(DS,{title:i.name,subtitle:e.role?X(`youAre`,{role:uj(e.role).toLowerCase()}):X(`throughGlobalRoles`)}),(0,B.jsx)(bH,{organization:i,editable:fj(e),onSaved:n},`${i.name}/${i.slug}`),r&&e.role&&(0,B.jsx)(CH,{editable:fj(e)}),a&&e.memberId&&(0,B.jsx)(xH,{organization:i,memberId:e.memberId}),e.role&&(0,B.jsx)(wH,{organization:i,basePath:t,owner:a}),a&&(0,B.jsx)(SH,{organization:i,basePath:t})]})},EH=({organization:e,current:t,busy:n,onOpen:r})=>(0,B.jsxs)(`li`,{className:`flex items-center gap-3 px-3 py-2.5`,children:[(0,B.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,B.jsx)(`span`,{className:`block truncate font-medium`,children:e.name}),(0,B.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:e.slug})]}),t?(0,B.jsx)(zf,{tone:`green`,children:X(`current`)}):(0,B.jsx)(G,{size:`sm`,loading:n,onClick:r,children:X(`open`)})]}),DH=({basePath:e,currentId:t})=>{let{session:n}=V(),[r,i]=(0,I.useState)(``),a=Cj((0,I.useCallback)((e,t)=>n.organizations.search(e,t).then(e=>({items:e.organizations,total:e.total})),[n]),r),{busy:o,error:s,run:c}=QA();return(0,B.jsx)(Sj,{title:X(`allOrganizations`),description:X(`allOrganizationsDescription`),searchLabel:X(`findOrganization`),placeholder:X(`nameOrSlug`),query:r,onQuery:i,list:a,error:s,renderRow:r=>(0,B.jsx)(EH,{organization:r,current:r.id===t,busy:o,onOpen:()=>void c(async()=>{await n.organizations.switchTo(r.id),yH(e)})},r.id)})},OH=e=>e.normalize(`NFKD`).replace(/[̀-ͯ]/g,``).toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,63),kH=({basePath:e})=>{let{session:t}=V(),[n,r]=(0,I.useState)(``),[i,a]=(0,I.useState)(),{busy:o,error:s,run:c}=QA(),l=()=>c(async()=>{await t.organizations.create({name:n.trim(),slug:i??OH(n)}),yH(e)});return(0,B.jsxs)(BA,{title:X(`newOrganization`),description:X(`newOrganizationDescription`),children:[(0,B.jsx)(VA,{message:s}),(0,B.jsxs)(`form`,{className:`flex flex-col gap-2 sm:flex-row`,onSubmit:e=>{e.preventDefault(),l()},children:[(0,B.jsx)(J,{"aria-label":X(`name`),placeholder:X(`name`),value:n,onChange:e=>r(e.target.value),wrapperClassName:`flex-1`}),(0,B.jsx)(J,{"aria-label":X(`slug`),placeholder:`slug`,value:i??OH(n),onChange:e=>a(e.target.value),wrapperClassName:`sm:w-48`}),(0,B.jsx)(G,{type:`submit`,variant:`primary`,loading:o,disabled:!n.trim(),children:X(`create`)})]})]})},AH=({basePath:e})=>{let{session:t,organizations:n}=V(),[r,i]=(0,I.useState)([]),{busy:a,error:o,run:s}=QA();if((0,I.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),yH(e)});return(0,B.jsxs)(BA,{title:X(`invitationsForYou`),description:X(`invitationsForYouDescription`),children:[(0,B.jsx)(VA,{message:o}),(0,B.jsx)(`ul`,{className:`divide-y rounded-md border`,children:r.map(e=>(0,B.jsxs)(`li`,{className:`flex items-center gap-3 px-3 py-2.5`,children:[(0,B.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,B.jsx)(`span`,{className:`font-medium`,children:e.organizationName??X(`anOrganization`)}),`: `,e.appRoles.map(e=>dj(c,e)).join(`, `)||X(`noAppRoles`),(0,B.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:X(`until`,{date:new Date(e.expiresAt).toLocaleDateString(Le())})})]}),(0,B.jsx)(G,{size:`sm`,variant:`primary`,loading:a,onClick:()=>void l(e.id),children:X(`accept`)})]},e.id))})]})},jH=({state:e,basePath:t})=>{let{session:n,organizations:r,state:i}=V(),{busy:a,error:o,run:s}=QA(),c=i.kind===`signed-in`?i.user:void 0,l=r?.create===`everyone`||c!==void 0&&U_(c),u=e.current?.organization?.id;return(0,B.jsxs)(`div`,{className:`mx-auto flex w-full max-w-3xl flex-col gap-4 px-4 py-6 md:px-6`,children:[(0,B.jsx)(DS,{title:X(`organizations`),subtitle:X(`organizationsSubtitle`)}),(0,B.jsxs)(BA,{title:X(`yourOrganizations`),description:e.organizations.length>0?X(`memberOf`):X(`notMember`),children:[(0,B.jsx)(VA,{message:o??e.error}),e.organizations.length>0&&(0,B.jsx)(`ul`,{className:`divide-y rounded-md border`,children:e.organizations.map(e=>(0,B.jsx)(EH,{organization:e,current:e.id===u,busy:a,onOpen:()=>void s(async()=>{await n.organizations.switchTo(e.id),yH(t)})},e.id))})]}),(0,B.jsx)(AH,{basePath:t}),l&&(0,B.jsx)(kH,{basePath:t}),(e.current?.globalRoles.length??0)>0&&(0,B.jsx)(DH,{basePath:t,currentId:u})]})},MH=(e,t)=>t?.active?{...e,role:t.active}:e,NH=M(`roles`),PH=(e,t)=>e instanceof ku?KA(e):t,FH=(e,t=!0)=>{let{session:n}=V(),r=ly(),[i,a]=(0,I.useState)();(0,I.useEffect)(()=>{t&&n.roles.current().then(a,e=>r.show({state:`error`,title:PH(e,NH(`couldNotReadRoles`))}))},[n,r,t]);let o=(0,I.useCallback)(t=>void n.roles.switchTo(t).then(e,e=>r.show({state:`error`,title:PH(e,NH(`couldNotSwitch`))})),[n,r,e]);return{...i&&{current:i},switchTo:o}},IH=e=>{let t=lV(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},LH=e=>{let t=p_().shell?.logo;return t?(0,B.jsx)(pv,{name:`shell.logo`,fallback:(0,B.jsx)(Nx,{...e}),children:(0,B.jsx)(t,{...e})}):(0,B.jsx)(Nx,{...e})},RH=[440,480],zH=400,BH=3e3,VH=e=>{(0,I.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,zH*1.5/1e3].entries())for(let i of RH){let a=t.createOscillator();a.frequency.value=i,a.connect(e),a.start(t.currentTime+r),a.stop(t.currentTime+r+zH/1e3/(n+1))}};n();let r=setInterval(n,BH);return()=>{clearInterval(r),t.close()}},[e])},HH=(e,t)=>e.map(e=>({...e,until:t+e.remaining_ms})),UH=(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))}},WH=e=>{let t=U(),n=Se(),r=E({queryKey:H.rings,queryFn:async()=>HH(await t.rings.list(),Date.now()),enabled:e});(0,I.useEffect)(()=>{if(!e)return;let r=()=>void n.invalidateQueries({queryKey:H.rings});return t.live({onChanges:e=>e.some(e=>e.resource===`$rings`)&&r(),onResync:r})},[t,n,e]);let[i,a]=(0,I.useState)(()=>Date.now()),{ringing:s,next:c}=UH(r.data??[],Math.max(i,r.dataUpdatedAt));(0,I.useEffect)(()=>{if(c===void 0)return;let e=setTimeout(()=>a(Date.now()),Math.max(0,c-Date.now()));return()=>clearTimeout(e)},[c]);let l=(0,I.useCallback)(e=>n.setQueryData(H.rings,t=>t?.filter(t=>t.call!==e)),[n]);return{ringing:s,decline:o({mutationFn:e=>t.rings.decline(e),onMutate:l,onSettled:()=>n.invalidateQueries({queryKey:H.rings})}).mutate,hide:l}},GH=(e,t,n)=>({state:`call`,sticky:!0,title:e.title,...e.body!==null&&{description:e.body},actions:[{label:Z(`decline`),onClick:()=>n(e.call)},{label:Z(`accept`),...t}]}),KH=()=>{let{ringing:e,decline:t,hide:n}=WH(!0),r=ly(),{href:i,open:a}=qh(),o=(0,I.useRef)(new Map);return VH(e.length>0),(0,I.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({...GH(s,e,t),onClose:()=>t(s.call)}))}},[e,r,i,a,t,n]),(0,I.useEffect)(()=>{let e=o.current;return()=>{for(let t of e.values())r.dismiss(t);e.clear()}},[r]),null},qH=(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)}},JH=()=>{let{push:e,state:t}=V(),n=t.kind===`signed-in`?t.user.id:void 0,[r,i]=(0,I.useState)(`loading`);return(0,I.useEffect)(()=>{let t=!0,n=()=>void e.state().then(e=>t&&i(e));n();let r=typeof window>`u`?void 0:qH(n);return()=>{t=!1,r?.()}},[e,n]),{state:r,turnOn:(0,I.useCallback)(async()=>i(await e.turnOn()),[e]),turnOff:(0,I.useCallback)(async()=>{await e.turnOff(),i(await e.state())},[e])}},YH=M(`notifications/bell`),XH=`flex w-full gap-2.5 px-3 py-2.5 text-left`,ZH=({item:e,target:t,onNavigate:n,onOpen:r,now:i})=>{let a=e.readAt===null,o=(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`span`,{className:P(`mt-1.5 size-2 shrink-0 rounded-full`,a?Lf.blue:`bg-transparent`),children:a&&(0,B.jsx)(`span`,{className:`sr-only`,children:YH(`unread`)})}),(0,B.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,B.jsx)(`span`,{className:P(`block text-body text-foreground`,a&&`font-semibold`),children:e.title}),e.body&&(0,B.jsx)(`span`,{className:`mt-0.5 line-clamp-2 block text-xs text-muted-foreground`,children:e.body}),(0,B.jsx)(`time`,{dateTime:e.createdAt,className:`mt-0.5 block text-xs text-faint-foreground`,children:Dp((i-Date.parse(e.createdAt))/1e3)})]})]}),s=()=>r(e),c=e=>{e.button===1&&s()};return t?t.kind===`app`?(0,B.jsx)(Dh,{to:{href:t.href,onFollow:()=>n(t.path)},onClick:s,onAuxClick:c,className:P(XH,`hover:bg-muted`),children:o}):(0,B.jsx)(`a`,{href:t.href,onClick:s,onAuxClick:c,className:P(XH,`hover:bg-muted`),children:o}):(0,B.jsx)(`div`,{className:XH,children:o})},QH=({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,B.jsxs)(`div`,{className:`flex max-h-[min(32rem,calc(100dvh-var(--pb-sticky-top,3rem)-1rem))] flex-col`,children:[(0,B.jsxs)(`div`,{className:`flex min-h-11 items-center gap-2 border-b px-3`,children:[(0,B.jsx)(`h2`,{className:`flex-1 text-body font-semibold`,children:YH(`notifications`)}),m&&h&&(0,B.jsx)(G,{size:`sm`,variant:`ghost`,loading:c,onClick:()=>s(m),children:YH(`markAllRead`)})]}),(0,B.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overscroll-contain`,children:[t?(0,B.jsx)(`div`,{className:`flex justify-center py-8`,children:(0,B.jsx)(af,{className:`size-4`})}):n?(0,B.jsxs)(`div`,{className:`flex flex-col items-center gap-2 px-3 py-6 text-center text-body text-muted-foreground`,children:[(0,B.jsx)(`p`,{children:YH(`loadFailed`)}),(0,B.jsx)(G,{size:`sm`,onClick:r,children:YH(`tryAgain`)})]}):e.length===0?(0,B.jsx)(`p`,{className:`px-3 py-8 text-center text-body text-muted-foreground`,children:YH(`empty`)}):(0,B.jsx)(`ul`,{className:`divide-y`,children:e.map(e=>(0,B.jsx)(`li`,{children:(0,B.jsx)(ZH,{item:e,target:l(e),onNavigate:u,onOpen:d,now:p})},e.id))}),i&&!t&&!n&&(0,B.jsx)(`div`,{className:`flex justify-center border-t py-2`,children:(0,B.jsx)(G,{size:`sm`,variant:`ghost`,loading:a,onClick:o,children:YH(`showMore`)})})]}),f]})},$H=(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}},eU=({state:e,onTurnOn:t,onTurnOff:n})=>{if(e===`loading`||e===`unsupported`)return null;if(e===`blocked`)return(0,B.jsxs)(`p`,{className:`flex gap-2 border-t px-3 py-2.5 text-xs text-muted-foreground`,children:[(0,B.jsx)($r,{className:`mt-0.5 size-3.5 shrink-0`,"aria-hidden":!0}),YH(`pushBlocked`)]});let r=e===`on`;return(0,B.jsxs)(`div`,{className:`flex items-center gap-2 border-t px-3 py-2.5 text-xs text-muted-foreground`,children:[(0,B.jsx)(ti,{className:`size-3.5 shrink-0`,"aria-hidden":!0}),(0,B.jsx)(`span`,{className:`min-w-0 flex-1`,children:YH(r?`pushOn`:`pushOff`)}),(0,B.jsx)(G,{size:`sm`,variant:r?`secondary`:`primary`,onClick:r?n:t,children:YH(r?`turnOff`:`turnOn`)})]})},tU=3e4,nU=e=>ml(e)&&e.status===403,rU=({enabled:e=!0}={})=>{let t=U();return E({queryKey:H.inboxUnread,queryFn:()=>t.notifications.unread(),refetchInterval:e=>!nU(e.state.error)&&tU,enabled:e})},iU=({enabled:e=!0}={})=>{let t=U(),n=Ne({queryKey:H.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}},aU=(e,t)=>{let n=new Date().toISOString(),r=0;e.setQueryData(H.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(H.inboxUnread,e=>e===void 0?e:Math.max(0,e-r))},oU=()=>{let e=U(),t=Se(),n=()=>t.invalidateQueries({queryKey:H.inbox}),r=o({mutationFn:t=>e.notifications.markRead(t.id),onMutate:e=>aU(t,t=>t.id===e.id),onSettled:n}),i=o({mutationFn:t=>e.notifications.markAllRead(t.createdAt),onMutate:e=>aU(t,t=>t.createdAt<=e.createdAt),onSettled:n}),a=r.mutate;return{markRead:(0,I.useCallback)(e=>{e.readAt===null&&a(e)},[a]),markAllRead:i.mutate,markingAll:i.isPending}},sU=99,cU=e=>e===void 0||e<=0?YH(`notifications`):e>sU?YH(`notificationsManyUnread`):YH(`notificationsUnread`,{count:String(e)}),lU=()=>{let{open:e,setOpen:t,place:n,button:r,menu:i}=cg(),a=rU(),o=iU({enabled:e}),{markRead:s,markAllRead:c,markingAll:l}=oU(),u=JH(),{navigate:d,basePath:f}=Ih(),[p,m]=(0,I.useState)(Date.now),h=cU(a.data),g=window.location.origin;return nU(a.error)?null:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(G,{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()),t(!e)},className:`relative max-md:size-9`,children:[(0,B.jsx)(ri,{className:`size-4 max-md:size-5`}),(0,B.jsx)(eS,{count:a.data,className:`pointer-events-none absolute -top-1 -right-1.5 max-md:top-0 max-md:right-0`})]}),e&&(0,Cc.createPortal)((0,B.jsx)(`div`,{ref:i,role:`dialog`,"aria-label":cU(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,B.jsx)(QH,{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=>$H(e.url,{origin:g,basePath:f}),onNavigate:e=>d(e),onOpen:e=>{s(e),t(!1)},footer:(0,B.jsx)(eU,{state:u.state,onTurnOn:()=>void u.turnOn(),onTurnOff:()=>void u.turnOff()}),now:p})}),document.body)]})},uU=({own:e})=>e?(0,B.jsx)(pv,{name:`shell.bell`,fallback:null,children:(0,B.jsx)(e,{})}):(0,B.jsx)(lU,{}),dU=(0,I.createContext)([]),fU=()=>(0,I.useContext)(dU),pU=({ui:e,children:t})=>{let{plugins:n=[]}=W(),{loads:r,settled:i}=GP(n,HP()),a=(0,I.useMemo)(()=>SP(e,r),[e,r]);return i?(0,B.jsx)(f_.Provider,{value:a.ui,children:(0,B.jsx)(dU.Provider,{value:a.off,children:t})}):(0,B.jsxs)(`div`,{className:`flex h-full min-h-48 items-center justify-center gap-2 text-muted-foreground`,children:[(0,B.jsx)(af,{}),` `,CP(`loading`)]})},mU=({off:e})=>{let[t,n]=(0,I.useState)(!1);return t||e.length===0?null:(0,B.jsxs)(`div`,{role:`region`,"aria-label":CP(`pluginsOff`),className:`flex items-start gap-3 border-b border-warning/40 bg-warning-soft px-4 py-2 text-warning-text`,children:[(0,B.jsx)(Qo,{"aria-hidden":!0,className:`mt-0.5 size-4 shrink-0`}),(0,B.jsx)(`ul`,{className:`min-w-0 flex-1 space-y-0.5 break-words`,children:e.map(e=>(0,B.jsx)(`li`,{children:CP.rich(`pluginOff`,{plugin:(0,B.jsx)(`span`,{className:`font-semibold`,children:e.name??e.url}),reason:e.reason})},e.url))}),(0,B.jsx)(`button`,{type:`button`,"aria-label":CP(`dismiss`),className:`rounded p-0.5 hover:bg-warning/10`,onClick:()=>n(!0),children:(0,B.jsx)(bc,{"aria-hidden":!0,className:`size-4`})})]})},hU=(e,t)=>[`${t}_at`,`${t}At`].find(t=>e.fields[t]),gU=({item:e,scope:t})=>{let{components:n}=p_(),r=n?.[e.component],i=r?(0,B.jsx)($v,{value:t,children:(0,B.jsx)(pv,{name:e.component,children:(0,B.jsx)(r,{...vn(e.props??{})})})}):(0,B.jsx)(dv,{children:q.rich(`noComponent`,{component:e.component})});return e.sidebar?e.title?(0,B.jsx)(dg,{title:e.title,children:i}):i:e.title?(0,B.jsx)(Kf,{title:e.title,children:i}):(0,B.jsx)(`section`,{className:`py-8`,children:i})},_U=({component:e,scope:t,standard:n})=>{let{components:r}=p_(),i=r?.[e];return i?(0,B.jsx)(pv,{name:e,fallback:n,children:(0,B.jsx)(vU,{children:(0,B.jsx)($v,{value:t,children:(0,B.jsx)(i,{})})})}):n},vU=({children:e})=>(Cx(!1),(0,B.jsx)(`div`,{className:`grid min-h-0 flex-1 grid-cols-[minmax(0,1fr)] grid-rows-[minmax(0,1fr)]`,children:e})),yU=(0,I.lazy)(()=>Ve(()=>import(`./record-map-Cocva8wo.js`).then(e=>({default:e.RecordMap})),__vite__mapDeps([9,1,2,5,6,7,3,8]))),bU=15,xU=({item:e,record:t})=>{let n=W().maps,r=n?.style,i=Wk(t,e);if(!r||!i)return null;let a=(0,B.jsx)(`div`,{className:`overflow-hidden rounded-lg border border-border bg-muted ${e.sidebar?`h-48`:`h-64 md:h-80`}`,children:(0,B.jsx)(I.Suspense,{fallback:null,children:(0,B.jsx)(yU,{style:r,layers:n?.layers,position:i,zoom:e.zoom??bU},`${i.latitude},${i.longitude}`)})});return e.sidebar?(0,B.jsx)(dg,{title:e.title,children:a}):(0,B.jsx)(Kf,{title:e.title,children:a})},SU={"1h":`minute`,"24h":`5_minutes`,"7d":`hour`},CU=(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}))},wU=M(`app/record-chart`),TU=sn(),EU=[`1h`,`24h`,`7d`],DU={"1h":`hour`,"24h":`day`,"7d":`week`},OU=({item:e,recordKey:t})=>{let{resources:n,views:r}=W(),[i,a]=(0,I.useState)(e.range??`1h`),[o,s]=(0,I.useState)(`average`),c=n[e.resource],l=r[e.resource],u=SU[i],d=Yt(TU.eq(e.field,t)),f=e.series.map(t=>({groupBy:e.at,filter:d,...o===`average`?{average:t}:{maximum:t},range:i,granularity:u,timeZone:Xf()})),p=Wy(e.resource,f,!!c);if(!c)return null;let m=e.series.map(e=>({kind:o,field:c.fields[e],...l?.fields[e]&&{hints:l.fields[e]}})),h=e.series.map((e,t)=>({key:`s${t}`,label:l?.fields[e]?.label??F(e),color:`var(--chart-${t+1})`,measure:m[t]})),g=p.every(e=>e.data)?CU(p.map(e=>e.data.groups),h.map(e=>e.key),o):[],_=(0,B.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,B.jsx)(Re,{label:wU(`measure`),value:o,onChange:s,options:[{value:`average`,label:wU(`average`)},{value:`maximum`,label:wU(`maximum`)}]}),(0,B.jsx)(Re,{label:wU(`range`),value:i,onChange:a,options:EU.map(e=>({value:e,label:wU(DU[e])}))})]});return(0,B.jsx)(Kf,{title:e.title,help:e.help,actions:_,children:p.some(e=>e.error)?(0,B.jsx)(`p`,{className:`text-danger-text`,children:wU(`couldNotLoad`)}):p.some(e=>e.isPending)?(0,B.jsx)(Ch,{className:`h-40 w-full`}):g.every(e=>e.count===0)?(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:wU(`noSamples`)}):(0,B.jsx)(vb,{points:g,measure:m[0],bucket:u,type:`line`,series:h,...h.length>1&&{resource:e.resource,view:l}})})},kU=e=>iE(e)??Sc,AU=({model:e,stored:t,recordKey:n,edit:r,onDelete:i})=>{let a=qh(),{go:o}=a,s=vS(),c={model:e,record:t.record,key:n,etag:t.etag,permissions:t.permissions},l=Ay(e.name,c,t=>t.run?.kind===`delete`&&o({kind:`list`,resource:e.name},{replace:!0})),[u,d]=(0,I.useState)(),f=l.actions.map(e=>{let n=l.blocked(e),r=e.run?.kind===`link`&&!n?KV(e.run,t.record,a):void 0;return{name:e.label,icon:kU(e.icon),blocked:n,running:l.running===e.name,...Yv(e)&&{tone:`danger`},onRun:()=>Xv(e)?d(e):void l.run(e),...r&&{render:({className:e,children:t,role:n})=>(0,B.jsx)(Dh,{to:r,role:n,className:e,children:t})}}}),p=l.actions.some(e=>e.run?.kind===`delete`),m=[...r?[{name:Q(`edit`),icon:Ro,render:({className:e,children:t,role:n})=>(0,B.jsx)(Jh,{to:r,role:n,className:e,children:t})}]:[],...f,...i&&!p?[{name:Q(`delete`),icon:Js,tone:`danger`,onRun:i}]:[]];return m.length===0?null:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`div`,{className:s?`max-md:hidden`:void 0,children:(0,B.jsx)(ig,{actions:m})}),s&&(0,Cc.createPortal)((0,B.jsx)(lg,{actions:m,label:Q(`recordActions`),className:`inline-flex size-11 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-muted md:hidden`}),s),u&&(0,B.jsx)(Zv,{action:u,label:u.label,danger:Yv(u),onCancel:()=>d(void 0),onConfirm:()=>{d(void 0),l.run(u)},onSubmit:async e=>{await l.submit(u,e),d(void 0)}})]})},jU=(e=[],t)=>e.includes(t)?e.filter(e=>e!==t):[...e,t],MU=(e,t=[],n)=>!e.collapsed||t.includes(e.title)||e.items.some(e=>e.kind===`section`&&e.fields.some(n)),NU=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)}},PU=(e,t)=>e.find(e=>e.title===t)??e[0],FU=e=>Sn(e.items).flatMap(e=>e.kind===`section`?e.fields:[]),IU=(e,t,n)=>{if(t&&!FU(t).some(n))return e.find(e=>FU(e).some(n))},LU=e=>e.width??`minmax(8rem,1fr)`,RU=e=>({"--line-columns":e.map(LU).join(` `)}),zU=e=>`${e.reduce((e,t)=>e+(t.width?.endsWith(`px`)?parseInt(t.width)/16:8),6)}rem`,BU=`grid grid-cols-[28px_var(--line-columns)_32px] items-center gap-2 pointer-coarse:grid-cols-[44px_var(--line-columns)_44px]`,VU=({items:e,label:t})=>{let[n,r]=(0,I.useState)(!1),i=(0,I.useRef)(null);return(0,I.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,B.jsxs)(`div`,{ref:i,className:`relative flex justify-center`,children:[(0,B.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,B.jsx)(la,{className:`size-4`})}),n&&(0,B.jsx)(`ul`,{role:`menu`,className:`absolute right-0 top-full z-30 mt-1 min-w-36 rounded-md border bg-background py-1 shadow-pop`,children:e.map(e=>(0,B.jsx)(`li`,{role:`none`,children:(0,B.jsx)(`button`,{type:`button`,role:`menuitem`,disabled:e.disabled,className:P(`block min-h-9 w-full whitespace-nowrap 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))})]})},HU=M(`inline-child-table`),UU=({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}=Te({id:e.id,disabled:!a}),g=[...a?[{label:HU(`moveUp`),disabled:r===0,onSelect:()=>s(r-1)},{label:HU(`moveDown`),disabled:r===i-1,onSelect:()=>s(r+1)}]:[],...o?[{label:HU(`removeLine`),destructive:!0,onSelect:o}]:[]];return(0,B.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:P(`group relative border-b border-border bg-background px-2 py-1 last:border-b-0 hover:bg-surface`,BU,h&&`z-10 bg-surface opacity-80 shadow-pop`,c&&`bg-danger-soft`),children:[a?(0,B.jsx)(`button`,{ref:f,type:`button`,"aria-label":HU(`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,B.jsx)(Ta,{className:`size-4`})}):(0,B.jsx)(`span`,{}),n.map(t=>(0,B.jsx)(`div`,{className:P(`min-w-0`,t.align===`right`&&`text-right`),children:t.cell(e)},t.key)),g.length>0?(0,B.jsx)(VU,{label:HU(`actionsFor`,{name:t}),items:g}):(0,B.jsx)(`span`,{}),c&&(0,B.jsx)(`p`,{role:`alert`,className:`col-span-full px-2 pb-1 text-xs text-danger-text`,children:c})]})},WU=(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},GU=`px-2 text-[11px] font-medium uppercase tracking-wide text-muted-foreground`,KU=(e,t)=>{let n=n=>{let r=e.find(e=>e.id===n);return r?t(r):HU(`line`)},r=t=>e.findIndex(e=>e.id===t)+1;return{onDragStart:({active:t})=>HU(`pickedUp`,{name:n(t.id),place:r(t.id),count:e.length}),onDragOver:({active:t,over:i})=>i?HU(`over`,{name:n(t.id),place:r(i.id),count:e.length}):void 0,onDragEnd:({active:t,over:i})=>i?HU(`dropped`,{name:n(t.id),place:r(i.id),count:e.length}):HU(`droppedAtStart`,{name:n(t.id)}),onDragCancel:({active:e})=>HU(`cancelled`,{name:n(e.id),place:r(e.id)})}},qU=({lines:e,columns:t,lineName:n,onReorder:r,reorderable:i=!!r,onAdd:a,onRemove:o,removable:s=()=>!0,lineError:c,footer:l})=>{let u=ne(Me(se,{activationConstraint:{distance:4}}),Me(xe,{activationConstraint:{delay:250,tolerance:5}}),Me(ae,{coordinateGetter:ye})),d=(t,n)=>{let i=e[t];!i||!r||n<0||n>=e.length||t===n||r(WU(e,t,n),{id:i.id,from:t,to:n})};return(0,B.jsxs)(`div`,{children:[(0,B.jsxs)(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,style:RU(t),children:[(0,B.jsxs)(`div`,{className:`${BU} border-b border-border bg-surface px-2 py-2`,children:[(0,B.jsx)(`span`,{}),t.map(e=>(0,B.jsx)(`span`,{className:P(GU,e.align===`right`&&`text-right`),children:e.label},e.key)),(0,B.jsx)(`span`,{})]}),e.length===0&&(0,B.jsx)(`p`,{className:`px-4 py-3 text-muted-foreground`,children:HU(`noLines`)}),(0,B.jsx)(me,{sensors:u,collisionDetection:ge,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:KU(e,n),screenReaderInstructions:{draggable:HU(`instructions`)}},children:(0,B.jsx)(ue,{items:e.map(e=>e.id),strategy:re,children:e.map((r,a)=>(0,B.jsx)(UU,{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,B.jsx)(`div`,{className:`border-t border-border bg-surface px-2 py-1.5`,children:(0,B.jsxs)(G,{variant:`ghost`,size:`sm`,onClick:a,children:[(0,B.jsx)(Jo,{className:`size-3.5`}),HU(`addLine`)]})})]}),l]})},JU=({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,I.useId)(),m=d&&lx(e,n,d);return(0,B.jsxs)(Qh.Provider,{value:{id:p,invalid:!!d,required:!1,...m&&{describedBy:`${p}-error`}},children:[(0,B.jsx)(`label`,{htmlFor:p,className:`sr-only`,children:Q(`lineField`,{label:n,place:r})}),(0,B.jsx)(Nv,{field:e,hints:t,value:a,stored:o,relationLabel:s,relationTo:c,relationPicker:l,locked:u,invalid:!!d,resource:i,onChange:f}),m&&(0,B.jsx)(`p`,{id:`${p}-error`,className:`px-1 pt-0.5 text-xs text-danger-text`,children:m})]})},YU=(e,t,n,r,i)=>{let a=Yg(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,I.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,I.useEffect)(()=>{s&&!a.isFetchingNextPage&&a.fetchNextPage()},[s,a.isFetchingNextPage]),{items:o,labels:a.labels,loading:(a.isPending||s)&&!!e,complete:!a.hasNextPage}},XU=({lines:e,editable:t,saving:n})=>{let{resources:r,views:i}=W(),{item:a,model:o,columns:s,data:c,draft:l}=e,u=uf(o.name),d=i[o.name],[f,p]=(0,I.useState)({}),m=t&&c.complete&&!c.loading&&!n,h=m&&dy(u,`update`),g=m&&dy(u,`create`),_=m&&dy(u,`delete`),v=e=>e.stored?h&&fy(e.stored,`update`):g,y=e=>l.shown.indexOf(e)+1,b=e=>l.rejection?.id===e.id?l.rejection:void 0,x=s.map(e=>{let t=o.fields[e],n=d?.fields[e],a=n?.label??F(e),s=t.relation?r[t.relation.resource]:void 0,u=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=l.value(r.id,e),d=s==null||s===``?void 0:String(s);return(0,B.jsx)(JU,{field:t,hints:n,label:a,lineNumber:y(r),resource:o.name,value:s,stored:r.stored?.[e],relationLabel:d===void 0?void 0:f[`${r.id}/${e}`]??c.labels[e]?.[d],relationTo:u&&d!==void 0?{kind:`record`,resource:u.name,key:d}:void 0,relationPicker:u&&{target:u,view:i[u.name]},locked:!v(r),problem:b(r)?.fields[e],onChange:t=>{if(!u||!Ng(t))return l.change(r.id,e,t);p(n=>({...n,[`${r.id}/${e}`]:t.label})),l.change(r.id,e,Ig(u,t.key))}})}}});return(0,B.jsxs)(Kf,{title:a.title,help:a.help,children:[!c.complete&&(0,B.jsx)(`p`,{className:`mb-2 text-muted-foreground`,children:Q(`tooManyLines`,{limit:kp(1e3)})}),(0,B.jsx)(`div`,{className:`-mx-4 overflow-x-auto px-4 [-webkit-overflow-scrolling:touch] md:mx-0 md:px-0`,children:(0,B.jsx)(`div`,{style:{minWidth:zU(x)},children:(0,B.jsx)(qU,{lines:l.shown,columns:x,lineName:e=>ur(o,d,e.stored??{},``)||Q(`lineNumber`,{place:y(e)}),onReorder:e=>l.setOrder(e.map(e=>e.id)),reorderable:h,onAdd:g?()=>void l.add():void 0,onRemove:g||_?e=>l.remove(e.id):void 0,removable:e=>e.stored?_&&fy(e.stored,`delete`):g,lineError:e=>{let t=b(e);if(t&&!s.some(e=>t.fields[e]))return t.message}})})})]})},ZU=(e,t,n)=>`protobase:draft:${e}:${t}:${n}`,QU=(e,t,n)=>Ie(()=>{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),$U=(e,t,n)=>Ie(()=>n?e.setItem(t,JSON.stringify(n)):e.removeItem(t),void 0),eW={added:[],edits:{},removed:[]},tW=(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},nW=(e,t,n)=>Object.fromEntries(Object.entries(t).flatMap(([t,r])=>{let i=e.fields[t];return i&&Dg(i,r,n[t])?[[t,wg(i,r)]]:[]})),rW=(e,t)=>Object.fromEntries(Object.entries(t).flatMap(([t,n])=>{let r=e.fields[t];return!r||r.type!==`boolean`&&String(n??``).trim()===``?[]:[[t,wg(r,n)]]})),iW=({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=>[Cm(e,t),t])),c=[...s.keys()],l=tW(c,i),u=t=>wm(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=nW(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:{...rW(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},aW=(e,t)=>Object.fromEntries(Object.entries(e).filter(([e])=>e!==t)),oW=(e,t)=>{let[n,r]=(0,I.useState)(eW),[i,a]=(0,I.useState)(),o=(0,I.useRef)(1),s=(0,I.useMemo)(()=>new Map(e?t.map(t=>[Cm(e.model,t),t]):[]),[e,t]),c=tW([...s.keys()],n).map(e=>({id:e,stored:s.get(e)})),l=()=>e?iW({...e,stored:t,state:n}):{ops:[],rows:[]},u=l().ops.length>0,d=(0,I.useMemo)(()=>{let e=tW([...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:Eg(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:aW(t.edits,e)}:{...t,removed:[...t.removed,e]})},setOrder:e=>r(t=>({...t,order:e})),reset:()=>{r(eW),a(void 0)},reject:(e,t)=>a({id:e,fields:ux(t),message:t.message}),rejection:i,plan:l}},sW=(e,t)=>{let n=Sn(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}},cW=(e,t,n,r)=>Er(e,t).filter(t=>{let i=e.fields[t];return i&&!i.writeOnly&&t!==n&&t!==r&&t!==e.tenant&&!e.primaryKey.includes(t)}),lW=(e,t)=>{let{resources:n,views:r}=W(),i=(0,I.useMemo)(()=>sW(n,r[e.name]),[n,r,e]),a=i?.model,o=i?cW(i.model,r[i.model.name],i.link.name,i.position):[],s=YU(a,i?.link,i?.position,t,a?Ob(n,r,a,o):void 0),c=oW((0,I.useMemo)(()=>i?{model:i.model,position:i.position,link:{field:i.link.name,value:Ig(e,t)}}:void 0,[i,e,t]),s.items);return{item:i?.item,model:a,columns:o,data:s,draft:c}},uW=e=>{let t=e>=5?5:e===4?3:e;return{shown:t,more:e-t}},dW=(e,t)=>Math.abs(e)<40||Math.abs(e)<=Math.abs(t)?0:e<0?1:-1,fW=e=>e===`ArrowRight`?1:e===`ArrowLeft`?-1:0,pW=(e,t,n)=>Math.min(Math.max(e+t,0),Math.max(n-1,0)),mW=e=>e.key===`i`&&!e.ctrlKey&&!e.metaKey&&!e.altKey,hW=`protobase:lightbox-details`,gW=e=>Ie(()=>e.getItem(hW)===`true`,!1),_W=(e,t)=>Ie(()=>t?e.setItem(hW,`true`):e.removeItem(hW),void 0),vW=M(`app/gallery`),yW=`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`,bW=({title:e,photos:t,index:n,onIndex:r,onClose:i,details:a,detailsTitle:o=vW(`details`)})=>{let s=(0,I.useRef)(null),c=(0,I.useRef)(void 0),l=(0,I.useId)(),u=xf(),[d,f]=(0,I.useState)(()=>gW(localStorage)),[p,m]=(0,I.useState)(!1);Df(s,!0,i),(0,I.useEffect)(()=>m(!0),[]);let h=t.length,g=e=>{let t=pW(n,e,h);t!==n&&r(t)},_=Kp(t[n],{width:1600,height:1200}),v=a?.(n),y=v!==void 0,b=e=>{f(e),_W(localStorage,e)};return(0,B.jsxs)(`div`,{ref:s,tabIndex:-1,role:`dialog`,"aria-modal":`true`,"aria-label":e,onKeyDown:e=>{if(y&&mW(e))return e.preventDefault(),b(!d);let t=fW(e.key);t!==0&&(e.preventDefault(),g(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,B.jsxs)(`div`,{className:`flex h-dvh shrink-0 flex-col md:sticky md:top-0 md:min-w-0 md:flex-1`,children:[(0,B.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between gap-2 p-3 pt-[calc(0.75rem+var(--pb-safe-top))]`,children:[(0,B.jsx)(`span`,{className:`rounded-full bg-background/85 px-3 py-1 font-medium tabular-nums text-foreground`,"aria-live":`polite`,children:`${n+1} / ${h}`}),(0,B.jsxs)(`div`,{className:`flex items-center gap-2`,children:[y&&(0,B.jsx)(`button`,{type:`button`,className:P(yW,`aria-expanded:bg-foreground aria-expanded:text-background`),"aria-label":o,"aria-expanded":d,"aria-controls":u?l:void 0,"aria-keyshortcuts":`i`,onClick:()=>b(!d),children:(0,B.jsx)(Fa,{className:`size-4`,"aria-hidden":!0})}),(0,B.jsx)(`button`,{type:`button`,className:yW,"aria-label":vW(`close`),onClick:i,children:(0,B.jsx)(bc,{className:`size-4`,"aria-hidden":!0})})]})]}),(0,B.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&&=(g(dW(e.clientX-c.current.x,e.clientY-c.current.y)),void 0)},onPointerCancel:()=>c.current=void 0,children:[_&&(0,B.jsx)(I_,{image:_,className:`max-h-full max-w-full select-none object-contain`},_.url),h>1&&(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`button`,{type:`button`,className:P(yW,`absolute left-3 top-1/2 -translate-y-1/2 aria-disabled:cursor-default aria-disabled:opacity-40`),"aria-label":vW(`previousPhoto`),"aria-disabled":n===0,onClick:()=>g(-1),children:(0,B.jsx)(Di,{className:`size-5`,"aria-hidden":!0})}),(0,B.jsx)(`button`,{type:`button`,className:P(yW,`absolute right-3 top-1/2 -translate-y-1/2 aria-disabled:cursor-default aria-disabled:opacity-40`),"aria-label":vW(`nextPhoto`),"aria-disabled":n===h-1,onClick:()=>g(1),children:(0,B.jsx)(ki,{className:`size-5`,"aria-hidden":!0})})]})]})]}),y&&d&&u&&(0,B.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,B.jsx)(`h2`,{className:`mb-3 text-[16px] font-semibold`,children:o}),v]}),(0,B.jsx)(Af,{title:o,open:y&&d&&!u&&p,onClose:()=>b(!1),children:(0,B.jsx)(`div`,{className:`pt-3`,children:v})})]})},xW=(e,t,n)=>{let r=Sn(t?.layout??[]).flatMap(e=>e.kind===`section`&&jg(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)&&jg(t?.fields[r]?.when,!1))},SW=({model:e,view:t,photoKey:n,fields:r})=>{let i=rF(e.name,n),a=(t?.names?.singular??F(e.name)).toLowerCase();if(i.isPending)return(0,B.jsx)(Ch,{className:`h-4 w-48`});if(i.error)return(0,B.jsx)(Gg,{title:vW(`couldNotLoadOne`,{singular:a}),error:i.error});let o=r.filter(e=>py(i.data.permissions,e)!==`hidden`);return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(tg,{rows:o.map(n=>({label:t?.fields[n]?.label??F(n),value:(0,B.jsx)(Hb,{model:e,field:e.fields[n],value:i.data.record[n]})}))}),(0,B.jsx)(Jh,{to:{kind:`record`,resource:e.name,key:n},className:`mt-3 inline-block font-medium text-primary-text hover:underline`,children:vW(`open`,{singular:a})})]})},CW=e=>Kp(e,{width:0,height:0})!==void 0,wW=(e,t)=>{let n=e.primaryKey.map(e=>t[e]);if(!n.some(e=>e==null))return Nn(n)},TW=(e,t,n,r)=>{let i=n===void 0?[]:t.flatMap(e=>{let t=e[n];if(!Ip(t)||!CW(t))return[];let i=r&&wW(r,e);return[{file:t,...i!==void 0&&{key:i}}]});if(!Ip(e)||!CW(e))return i;let a=t=>Ip(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))]},EW=sn(),DW=(e,t,n)=>{let r=U(),{resources:i}=W(),a=e.photos?i[e.photos.resource]:void 0,o=e.photos?Yt(EW.eq(e.photos.field,n)):``,s=e.photos?.sort??``,c=E({queryKey:H.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:TW(e.image===void 0?void 0:t[e.image],c.data??[],e.photos?.image,a),isPending:a!==void 0&&c.isPending,error:c.error}},OW={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`,``,``,``,``]},kW=({photo:e,large:t})=>{let n=Kp(e,t?{width:960,height:720}:{width:480,height:360});return n?(0,B.jsx)(I_,{image:n,loading:`lazy`,className:`size-full object-cover transition-transform duration-300 group-hover/tile:scale-[1.02]`}):null},AW=({item:e,record:t,recordKey:n})=>{let{views:r}=W(),i=DW(e,t,n),a=uf(i.holder?.name??``),[o,s]=(0,I.useState)();if(i.isPending)return(0,B.jsx)(Kf,{title:e.title,children:(0,B.jsx)(Ch,{className:`aspect-[4/3] w-full rounded-lg md:aspect-[2/1]`})});if(i.error)return(0,B.jsx)(Kf,{title:e.title,children:(0,B.jsx)(Gg,{title:vW(`couldNotLoad`),error:i.error})});let c=i.items.length;if(c===0)return null;let{shown:l,more:u}=uW(c),d=i.holder,f=d&&r[d.name],p=d?xW(d,f,[e.photos?.image,e.photos?.field].filter(e=>e!==void 0)):[],m=d!==void 0&&a.read!==!1&&p.length>0;return(0,B.jsxs)(Kf,{title:e.title,children:[(0,B.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,l).map((e,t)=>{let n=t===l-1&&u>0;return(0,B.jsxs)(`button`,{type:`button`,"aria-label":n?vW(`showAll`,{count:c}):vW(`showPhoto`,{index:t+1,count:c}),onClick:()=>s(t),className:P(`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`,OW[l][t]),children:[(0,B.jsx)(kW,{photo:e.file,large:t===0}),n&&(0,B.jsx)(`span`,{className:`absolute inset-0 flex items-center justify-center bg-backdrop/55 text-lg font-semibold text-white`,"aria-hidden":!0,children:`+${u}`}),t===0&&c>1&&(0,B.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,B.jsx)(Na,{className:`size-3.5`}),c]})]},t)})}),o!==void 0&&(0,B.jsx)(bW,{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 m&&t!==void 0?(0,B.jsx)(SW,{model:d,view:f,photoKey:t,fields:p},t):void 0},detailsTitle:d&&vW(`holderDetails`,{singular:f?.names?.singular??F(d.name)})})]})},jW=M(`app/history`),MW=e=>e.actor?e.actor.name??e.actor.id:e.databaseRole?jW(`databaseRole`,{role:e.databaseRole}):jW(`database`),NW=(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??F(r);return i.sensitive||!e.before||!e.after?[{name:r,label:o}]:[{name:r,label:o,before:Rm(i,e.before[r],a),after:Rm(i,e.after[r],a)}]}),i=e.operation===`update`&&r.length===0?jW(`changedThis`):jW(e.operation);return{who:MW(e),verb:i,fields:r}},PW=1500,FW=(e,t,n,r)=>{let i=U(),a=Ne({queryKey:H.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,I.useEffect)(()=>{let e=setTimeout(()=>void o(),PW);return()=>clearTimeout(e)},[r,o]),{...a,items:a.data?.pages.flatMap(e=>e.items)??[]}},IW=()=>(0,B.jsx)(`div`,{className:`flex flex-col gap-2`,children:Array.from({length:3},(e,t)=>(0,B.jsx)(Ch,{className:`h-4 w-full`},t))}),LW=({change:e,model:t,view:n})=>{let{who:r,verb:i,fields:a}=NW(e,t,n),o=Date.parse(e.at);return(0,B.jsxs)(`li`,{className:`flex flex-col gap-1.5 py-3 first:pt-0 last:pb-0`,children:[(0,B.jsxs)(`p`,{children:[(0,B.jsx)(`span`,{className:`font-medium text-foreground`,children:r}),` `,(0,B.jsx)(`span`,{className:`text-muted-foreground`,children:i}),` `,(0,B.jsxs)(`time`,{dateTime:e.at,title:gp(o),className:`text-muted-foreground`,children:[`· `,Dp(Math.max(0,Math.round((Date.now()-o)/1e3)))]})]}),a.length>0&&(0,B.jsx)(`dl`,{className:`grid grid-cols-[minmax(0,auto)_minmax(0,1fr)] gap-x-4 gap-y-1`,children:a.map(e=>(0,B.jsxs)(`div`,{className:`contents`,children:[(0,B.jsx)(`dt`,{className:`text-muted-foreground`,children:e.label}),(0,B.jsx)(`dd`,{className:`min-w-0 break-words`,children:e.before===void 0?(0,B.jsx)(`span`,{className:`text-muted-foreground`,children:`changed`}):(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`del`,{className:`text-muted-foreground`,children:e.before}),` → `,(0,B.jsx)(`ins`,{className:`no-underline`,children:e.after})]})})]},e.name))})]})},RW=({item:e,model:t,view:n,recordKey:r,etag:i})=>{let a=FW(t.name,r,e.limit??10,i);return(0,B.jsx)(Kf,{title:e.title,children:a.isPending?(0,B.jsx)(IW,{}):a.error?(0,B.jsx)(Gg,{title:`Could not load the history`,error:a.error}):a.items.length===0?(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:`No changes kept yet.`}):(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`ol`,{className:`divide-y divide-border`,children:a.items.map(e=>(0,B.jsx)(LW,{change:e,model:t,view:n},e.id))}),a.hasNextPage&&(0,B.jsx)(G,{size:`sm`,className:`mt-4`,disabled:a.isFetchingNextPage,onClick:()=>void a.fetchNextPage(),children:`Show more`})]})})},zW=({comment:e})=>(0,B.jsx)(BI,{text:e.body,mentions:e.mentions}),BW=(e,t)=>{let n=U(),r=Se();return o({mutationFn:r=>n.comment(e,t,r),onSuccess:()=>r.invalidateQueries({queryKey:H.comments(e,t)})})},VW=M(`app/comments`),HW=({resource:e,recordKey:t})=>{let[n,r]=(0,I.useState)(LI),i=U(),a=ly(),o=BW(e,t),s=(0,I.useCallback)(n=>i.mentionable(e,t,n),[i,e,t]);Kh(n.text.trim()!==``||o.isPending,`input-lost`);let c=()=>{n.text.trim()===``||o.isPending||o.mutate({body:n.text,mentions:MI(n.text,n.picked)},{onSuccess:()=>r(LI),onError:e=>a.show({state:`error`,title:VW(`couldNotPost`),description:Jm(e)})})};return(0,B.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,B.jsx)(zI,{"aria-label":VW(`comment`),placeholder:VW(`placeholder`),value:n,onChange:r,searchPeople:s,onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),c())}}),(0,B.jsx)(`div`,{children:(0,B.jsx)(G,{variant:`primary`,size:`sm`,disabled:n.text.trim()===``,loading:o.isPending,onClick:c,children:VW(`comment`)})})]})},UW=20,WW=(e,t)=>{let n=U(),r=Ne({queryKey:H.comments(e,t),initialPageParam:``,queryFn:({pageParam:r})=>n.comments(e,t,{pageSize:UW,pageToken:r}),getNextPageParam:e=>e.nextPageToken||void 0});return{...r,items:r.data?.pages.flatMap(e=>e.items).reverse()??[]}},GW=()=>(0,B.jsx)(`div`,{className:`flex flex-col gap-2`,children:Array.from({length:3},(e,t)=>(0,B.jsx)(Ch,{className:`h-4 w-full`},t))}),KW=({comment:e})=>{let t=e.author.name??e.author.id,n=Date.parse(e.createdAt);return(0,B.jsxs)(`li`,{className:`flex gap-3 py-3 first:pt-0 last:pb-0`,children:[(0,B.jsx)(Vf,{initials:V_(t)||`?`,hue:B_(e.author.id),size:`md`,className:`ring-0`}),(0,B.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-0.5`,children:[(0,B.jsxs)(`p`,{children:[(0,B.jsx)(`span`,{className:`font-medium text-foreground`,children:t}),` `,(0,B.jsxs)(`time`,{dateTime:e.createdAt,title:gp(n),className:`text-muted-foreground`,children:[`· `,Dp(Math.max(0,Math.round((Date.now()-n)/1e3)))]})]}),(0,B.jsx)(zW,{comment:e})]})]})},qW=({item:e,resource:t,recordKey:n,canWrite:r})=>{let i=WW(t,n);return(0,B.jsxs)(Kf,{title:e.title,children:[i.isPending?(0,B.jsx)(GW,{}):i.error?(0,B.jsx)(Gg,{title:VW(`couldNotLoad`),error:i.error}):(0,B.jsxs)(B.Fragment,{children:[i.hasNextPage&&(0,B.jsx)(G,{size:`sm`,className:`mb-4`,disabled:i.isFetchingNextPage,onClick:()=>void i.fetchNextPage(),children:VW(`showEarlier`)}),i.items.length===0?(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:VW(`noComments`)}):(0,B.jsx)(`ol`,{className:`divide-y divide-border`,children:i.items.map(e=>(0,B.jsx)(KW,{comment:e},e.id))})]}),r&&(0,B.jsx)(`div`,{className:`mt-4`,children:(0,B.jsx)(HW,{resource:t,recordKey:n})})]})},JW=e=>e.kind===`group`||e.kind===`tab`?e.items:[],YW=e=>e.kind===`tab`?void 0:e.when,XW=e=>e.flatMap(e=>[e,...XW(JW(e))]).filter(e=>Ac(YW(e))),ZW=(e,t,n,r)=>{let i=0,a=e=>{let a=YW(e);return Ac(a)?!r&&t[i++]===!0:jg(a,n)},o=e=>e.flatMap(e=>{let t=a(e);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)},QW=(e,t,n,r)=>ZW(e,OD(r?[]:XW(e).map(e=>YW(e)),t),n,r),$W=(e,t)=>{let n=U(),r=Se(),i=Nn(t);return o({mutationFn:({patch:r,etag:i})=>n.update(e,t,r,i),onSuccess:t=>{r.setQueryData(H.record(e,i),t),r.invalidateQueries({queryKey:[`page`,e]}),r.invalidateQueries({queryKey:[`list`,e]}),r.invalidateQueries({queryKey:[`map`,e]})}})},eG=e=>e instanceof pl,tG=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}`},nG=(e,t)=>{let n=e.operation,r=n===void 0?void 0:t[n];return r?q(`operationFailed`,{index:n+1,label:tG(r),message:e.message}):q(`nothingSaved`,{message:e.message})},rG=(e,t)=>new e.constructor({...e.problem,detail:nG(e,t)}),iG=(e,t)=>Object.fromEntries(Object.entries(e).filter(([e])=>e!==t)),aG=({model:e,stored:t,recordKey:n,mode:r,subject:i,draftKey:a,lines:o})=>{let s=U(),c=Se(),l=$W(e.name,n),u=PL(r,i),[d]=(0,I.useState)(()=>a?QU(localStorage,a,t.etag):void 0),[f,p]=(0,I.useState)(d?.fields??{}),[m,h]=(0,I.useState)(!!d),[g,_]=(0,I.useState)(!1),[v,y]=(0,I.useState)({}),[b,x]=(0,I.useState)({}),[S,C]=(0,I.useState)(0),w=Object.entries(f).filter(([n,r])=>Dg(e.fields[n],r,t.record[n])),T=w.length>0,E=T||!!o?.dirty;(0,I.useEffect)(()=>{d?.order&&o?.setOrder(d.order)},[]),(0,I.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;$U(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]:gg(t.record[n]),O=(n,r)=>{x(e=>iG(e,n));let i=typeof r==`string`?r!==gg(t.record[n]):Dg(e.fields[n],r,t.record[n]);p(e=>i?{...e,[n]:r}:iG(e,n))},k=async()=>{let r=await s.get(e.name,n);c.setQueryData(H.record(e.name,n),r);let i={},a={};for(let[n,o]of Object.entries(f)){let s=e.fields[n];Dg(s,o,r.record[n])&&(a[n]=o,gg(r.record[n])!==gg(t.record[n])&&(i[n]=s.type===`file`?Rm(s,r.record[n]):gg(r.record[n])))}p(a),y(i)},A=()=>Object.fromEntries(w.map(([t,n])=>[t,wg(e.fields[t],n)])),j=e=>{let t=ux(e);x(t),Object.keys(t).length>0&&C(e=>e+1)},ee=async()=>{try{await l.mutateAsync({patch:A(),etag:t.etag})}catch(e){throw eG(e)?await k():ml(e)&&j(e),e}},te=async r=>{let i=T?[{op:`update`,resource:e.name,key:n,data:A(),etag:t.etag}]:[],a=[...i,...r.ops];try{await s.batchWrite(a)}catch(e){if(eG(e))await k(),await c.invalidateQueries({queryKey:[`list`]}),_(!0);else if(ml(e)){let t=e.operation===void 0?-1:e.operation-i.length,n=r.rows[t];t<0?j(e):n&&o?.reject(n,e)}throw ml(e)?rG(e,a):e}await Promise.all([c.invalidateQueries({queryKey:H.record(e.name,n)}),c.invalidateQueries({queryKey:[`list`]}),c.invalidateQueries({queryKey:[`page`]}),c.invalidateQueries({queryKey:[`map`]})]),o?.reset()};return{value:D,change:O,save:()=>u.run(async()=>{let e=o?.plan();e&&e.ops.length>0?await te(e):await ee(),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=>iG(t,e)),useTheirs:e=>{y(t=>iG(t,e)),p(t=>iG(t,e))}}},oG=sn(),sG=(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:Yt(oG.eq(n,t)),pageSize:1,fields:[n,e.tenant]}},cG=(e,t,n)=>{let r=t?.[e.tenant];if(r!=null&&String(r)!==n)return String(r)},lG=(e,t)=>{let n=U(),{session:r,organizations:i}=V(),a=(0,I.useMemo)(()=>i?sG(e,t):void 0,[i,e,t]),[o,s]=(0,I.useState)(a?{state:`looking`}:{state:`missing`});return(0,I.useEffect)(()=>{a&&(async()=>{let[t,i]=await Promise.all([n.list(e.name,a),r.organizations.current()]),o=cG(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},uG=(e,t,n,r)=>{let i=U(),a=Se(),o=v_(),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=f({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,Ib(c[i]?.data,o,a,n[a.name],String(r[e.name]))]}))}},dG=sn(),fG=(e,t,n,r)=>{if(e.primaryKey.length!==1)return[];let i=new Set(Sn(r).flatMap(e=>e.kind===`related`&&!e.through&&!e.from?[`${e.resource}.${e.field}`]:[])),a=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&&!i.has(`${t.name}.${e.name}`)).map(e=>({source:t,field:e.name})));return a.map(({source:e,field:t})=>{let r=n[e.name],i=r?.names?.plural??F(e.name),o=a.filter(t=>t.source.name===e.name).length>1;return{resource:e.name,field:t,label:o?`${i} (${r?.fields[t]?.label??F(t)})`:i}})},pG=(e,t)=>({kind:`list`,resource:e.resource,filter:Yt(dG.eq(e.field,t))}),mG=sn(),hG=(e,t,n)=>{let r=U(),i=f({queries:e.map(e=>{let i=Yt(mG.eq(e.field,n));return{queryKey:H.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}]})},gG=({model:e,recordKey:t,layout:n})=>{let{resources:r,views:i}=W(),a=hG(fG(e,r,i,n),r,t);return a.length===0?null:(0,B.jsx)(dg,{title:Q(`relatedRecords`),children:(0,B.jsx)(`ul`,{className:`-mx-2`,children:a.map(({relation:e,count:n})=>(0,B.jsx)(`li`,{children:(0,B.jsxs)(Jh,{to:pG(e,t),className:`group flex items-center justify-between gap-3 rounded-md px-2 py-2 hover:bg-muted`,children:[(0,B.jsx)(`span`,{className:`min-w-0 truncate font-medium text-primary-text`,children:e.label}),(0,B.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1 tabular-nums text-muted-foreground`,children:[n===void 0?(0,B.jsx)(Ch,{className:`h-4 w-6`}):`${kp(n.count)}${n.exact?``:`+`}`,(0,B.jsx)(ki,{className:`size-4 text-faint-foreground group-hover:text-foreground`})]})]})},`${e.resource}.${e.field}`))})})},_G=sn(),vG=(...e)=>{let t=e.filter(e=>!!e);return t.length===1?t[0]:t.map(e=>`(${e})`).join(` AND `)},yG=(e,t)=>{let n=U(),{resources:r}=W(),i=e.through,a=i?r[i.resource]:void 0,o=i?.key??a?.primaryKey[0],s=i?vG(Yt(_G.eq(i.field,t)),i.filter):``,c=E({queryKey:H.list(a?.name??``,s,``,0,`related:${o}`),enabled:!!(a&&o),queryFn:async()=>{let e=await xw(n,a.name,{filter:s,fields:[o]});return[...new Set(e.items.flatMap(e=>e[o]===null||e[o]===void 0?[]:[String(e[o])]))]}});return t===null?{filter:null,isPending:!1,error:null}:i?c.data?{filter:c.data.length===0?null:vG(Yt(_G.in(e.field,c.data)),e.filter),isPending:!1,error:null}:{filter:void 0,isPending:c.isPending,error:c.error}:{filter:vG(Yt(_G.eq(e.field,t)),e.filter),isPending:!1,error:null}},bG=()=>(0,B.jsx)(`div`,{className:`flex flex-col gap-2`,children:Array.from({length:3},(e,t)=>(0,B.jsx)(Ch,{className:`h-4 w-full`},t))}),xG=({empty:e})=>(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:e??Q(`nothingYet`)}),SG=({item:e,value:t,owner:n})=>{let{resources:r,views:i}=W(),a=r[e.resource],o=a&&i[a.name],s=yG(e,t),[c,l]=FA(o,`related:${n}:${e.title}`,e.display),u=uf(e.resource),[d,f]=(0,I.useState)(!1),p=U(),m=!!(e.hideEmpty&&a&&s.filter),h=E({queryKey:H.count(e.resource,s.filter??``),enabled:m,queryFn:()=>wy(p,a,s.filter??``).queryFn()});if(!a||e.hideEmpty&&(s.isPending||s.filter===null||m&&(h.isPending||h.data===0)))return null;let g=DA(e,a,r),_=e.columns??Er(a,o).filter(t=>t!==e.field),v=t=>s.isPending?(0,B.jsx)(bG,{}):s.error?(0,B.jsx)(Gg,{title:Q(`couldNotLoadRelated`),error:s.error}):s.filter===null||s.filter===void 0?(0,B.jsx)(xG,{empty:e.empty}):t(s.filter);if(e.presentation===`cards`)return(0,B.jsx)(Kf,{title:e.title,help:e.help,children:v(t=>(0,B.jsx)(XS,{model:a,view:o,filter:t,sort:e.sort??``,fields:_,actions:e.actions??[],limit:e.limit??10,display:e.display,empty:e.empty}))});let y=ID(e,a,u),b=(0,B.jsx)(MA,{view:o,value:c,onChange:l}),x=y?(0,B.jsxs)(`div`,{className:`flex items-center gap-2`,children:[!d&&b,(0,B.jsx)($V,{size:`sm`,sorting:d,onChange:f})]}):b;return d&&y?(0,B.jsx)(Kf,{title:e.title,help:e.help,actions:x,children:(0,B.jsx)(QV,{model:a,view:o,field:y,filter:Yt(_G.eq(e.field,t)),columns:_})}):(0,B.jsx)(Kf,{title:e.title,help:e.help,actions:x,children:v(t=>(0,B.jsx)(PA,{model:a,view:o,filter:t,sort:e.sort??``,columns:_,limit:e.limit??10,display:c,empty:e.empty,opens:g},t))})},CG=(e,t,n)=>{if(e.from===void 0)return n;let r=t[e.from];return typeof r==`boolean`?r:OA(t,e.from)??null},wG=(e,t)=>t===e.tenant||e.primaryKey.includes(t),TG=(e,t,n)=>{if(t&&t.layout.length>0)return t.layout;let r=Object.values(e.fields).filter(t=>!wG(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:Q(`details`),fields:a},...e.history?[{kind:`history`,title:Q(`history`)}]:[],...e.comments?[{kind:`comments`,title:Q(`comments`)}]:[]]},EG=({resource:e,recordKey:t})=>{let{resources:n,views:r}=W(),{address:i}=qh(),a=n[e],o=iF(e,t);if(!a)return(0,B.jsx)(sf,{title:q(`notFound`),children:q(`noResource`,{name:e})});if(o.isPending)return(0,B.jsx)(sf,{title:Q(`loading`),children:Q(`fetching`)});if(o.error)return(0,B.jsx)(`div`,{className:`p-8`,children:ml(o.error)&&o.error.status===404?(0,B.jsx)(DG,{model:a,recordKey:t}):(0,B.jsx)(Gg,{title:Q(`couldNotLoad`),error:o.error})});let s=(0,B.jsx)(OG,{model:a,recordKey:t,stored:o.data,preview:o.isPlaceholderData},o.isPlaceholderData?`preview`:`loaded`),c=r[e]?.record;if(!c||i?.kind===`record`&&i.standard)return s;if(o.isPlaceholderData)return(0,B.jsx)(sf,{title:Q(`loading`),children:Q(`fetching`)});let{record:l,etag:u,permissions:d}=o.data;return(0,B.jsx)(_U,{component:c.component,scope:{model:a,record:l,key:t,etag:u,permissions:d},standard:s})},DG=({model:e,recordKey:t})=>{let n=lG(e,t);return n.state===`looking`?(0,B.jsx)(sf,{title:Q(`loading`),children:Q(`fetching`)}):n.state===`switching`?(0,B.jsx)(sf,{title:Q(`loading`),children:Q(`openingElsewhere`)}):n.state===`failed`?(0,B.jsx)(Gg,{title:Q(`couldNotLoad`),error:n.error}):(0,B.jsx)(sf,{title:q(`notFound`),children:Q(`noRecord`)})},OG=({model:e,recordKey:t,stored:n,preview:r})=>{let i=W(),{address:a,go:o}=qh(),s=i.views[e.name],c=v_()(e,s,n.record,t),{state:l}=V(),u=lW(e,t),d=aG({model:e,stored:n,recordKey:t,mode:s?.saveFeedback??`toast`,subject:c,draftKey:!r&&l.kind===`signed-in`?ZU(l.user.id,e.name,t):void 0,lines:u.draft}),f=Se(),p=U(),m=fx(d.rejections),h=uf(e.name),g=iR(e),_=dy(h,`update`)&&n.permissions?.update!==!1,{shown:v,offersEdit:y,editing:b}=Og(s?.recordMode,_,a?.kind===`record`&&a.edit===!0);Kh(d.dirty&&v===`form`||d.saving),Ld(d.dirty);let x=a?.kind===`record`?a.open:void 0,S=a?.kind===`record`&&a.edit===!0,C=a?.kind===`record`?a.tab:void 0,w=a?.kind===`record`&&a.standard===!0,T=(n=[],r=!1,i)=>({kind:`record`,resource:e.name,key:t,...r&&{edit:r},...n.length>0&&{open:n},...i&&{tab:i},...w&&{standard:w}}),E=T(x,!1,C),D=T(x,!0,C),O=v===`form`&&s?.recordMode!==void 0&&s.recordMode!==`edit`,k=dy(h,`delete`)&&n.permissions?.delete!==!1,A=rR({model:e,view:s,restore:g,onDeleted:()=>o({kind:`list`,resource:e.name},{replace:!0}),onReview:()=>void f.invalidateQueries({queryKey:H.record(e.name,t)})}),j=uG(e,i.resources,i.views,n.record),ee=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},te=Object.values(e.fields).filter(e=>ee(e.name)),ne={...n.record,...Object.fromEntries(te.map(e=>[e.name,Tg(e,d.value(e.name))]))},re=uG(e,i.resources,i.views,ne),ie=(e,t)=>{let n=ee(e);if(!n||!Ng(t))return d.change(e,t);f.setQueryData(H.relatedLabel(n.name,t.key),{label:t.label}),d.change(e,Ig(n,t.key))},{fields:ae}=p_(),oe={model:e,record:n.record,key:t,etag:n.etag,permissions:n.permissions},se=QW(TG(e,s,v===`read`),oe,b,r),{before:ce,tabs:le,after:ue}=NU(se),de=PU(le,C),fe=e=>b&&(d.errors[e]!==void 0||d.conflicts[e]!==void 0);(0,I.useEffect)(()=>{if(d.rejections===0)return;let e=IU(le,de,fe);e&&o(T(x,S,e===le[0]?void 0:e.title),{replace:!0})},[d.rejections]);let pe=se.flatMap(e=>e.kind===`sidebar`?e.fields:[]),me=e.fields.status?.type===`enum`,he=n.record.status,ge=me&&!pe.includes(`status`)&&he!=null&&he!==``?String(he):void 0,_e=hU(e,`updated`),ve=e=>s?.fields[e],ye=t=>py(n.permissions,t)!==`hidden`&&jg(ve(t)?.when,b)&&(v===`form`||!e.fields[t]?.writeOnly),be=e=>!r||Object.hasOwn(n.record,e),xe=r=>{let a=e.fields[r],o=py(n.permissions,r);if(!a||o===`hidden`)return null;let c=d.conflicts[r],l=ee(r),u=ve(r)?.label??F(r),f=d.errors[r];return(0,B.jsx)(eg,{name:r,label:u,required:v===`form`&&o!==`read`&&bg(a),help:Ag(ve(r),s,b),error:f&&lx(a,u,f),wide:!!(ve(r)?.multiline||ve(r)?.markdown),conflict:c===void 0?void 0:{user:{name:Q(`someoneElse`),initials:`?`,hue:40},ago:Q(`justNow`),theirValue:c||`—`,onKeepMine:()=>d.keepMine(r),onUseTheirs:()=>d.useTheirs(r)},children:be(r)?(0,B.jsx)(Nv,{field:a,hints:ve(r),value:d.value(r),stored:n.record[r],relationLabel:re.labels[r],relationTo:re.addresses[r],relationPicker:l&&{target:l,view:i.views[l.name]},locked:v!==`form`||o===`read`,invalid:!!d.errors[r],reveal:a.sensitive&&!a.writeOnly?()=>p.reveal(e.name,t,r):void 0,resource:e.name,onChange:e=>ie(r,e)}):(0,B.jsx)(Ch,{className:`h-9`})},a.sensitive?`${r}:${n.etag}`:r)},Ce=r=>{let i=e.fields[r],a=be(r)?i.sensitive?(0,B.jsx)(Nv,{field:i,hints:ve(r),value:``,stored:n.record[r],locked:!0,reveal:()=>p.reveal(e.name,t,r),resource:e.name,onChange:e=>d.change(r,e)}):(0,B.jsx)(Hb,{model:e,field:i,value:n.record[r],relationLabel:j.labels[r]}):(0,B.jsx)(Ch,{className:`h-4 w-32`});return{label:ve(r)?.label??F(r),help:Ag(ve(r),s,b),wide:!!(ve(r)?.multiline||ve(r)?.markdown),value:a}},we=se.findIndex(e=>e.kind===`sidebar`),Te=(0,B.jsx)(fg,{title:Q(`summary`),rows:pe.flatMap(t=>{let r=e.fields[t];if(!r||!ye(t))return[];if(!be(t))return[{label:ve(t)?.label??F(t),value:(0,B.jsx)(Ch,{className:`h-4 w-24`})}];let i=n.record[t],a=xm(r,ve(t))&&typeof i==`string`&&i!==``?bm(i):Rm(r,i,ve(t)),o=r.type===`text`&&typeof i==`string`&&i!==``?Em(ve(t)):void 0,s=r.type===`enum`?(0,B.jsx)(Rb,{value:i,hints:ve(t),children:a}):o?(0,B.jsx)(Tv,{format:o,value:a}):(0,B.jsx)(`span`,{title:zm(r,i,void 0,ve(t)),children:a}),c=av(ae,r,ve(t));return[{label:ve(t)?.label??F(t),title:a,value:c?(0,B.jsx)(gv,{shown:c,part:`display`,field:r,value:n.record[t],fallback:s}):s}]})}),Ee=async()=>{await d.save()&&O&&o(E,{replace:!0})},De=k?()=>void A.start({key:t,title:c,etag:n.etag,snapshot:n.record}):void 0,Oe=v===`form`&&(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(G,{variant:`primary`,className:`max-md:min-h-11 max-md:flex-1 md:w-full`,loading:d.saving,disabled:!d.dirty&&d.phase!==`saved`,onClick:()=>void Ee(),children:[d.phase===`saved`&&(0,B.jsx)(Ci,{className:`size-4`}),d.phase===`saved`?Q(`saved`):Q(`save`)]}),O&&(0,B.jsx)(Jh,{to:E,className:P(yf(),`max-md:min-h-11 md:w-full`),onClick:e=>Th(e)&&d.discard(),children:Q(`cancel`)}),d.dirty&&(0,B.jsx)(`span`,{className:`text-xs text-muted-foreground max-md:order-first`,children:Q(`unsavedChanges`)})]}),ke=(i,a)=>{if(i.kind===`group`){let e=i.items.flatMap(ke);if(e.length===0)return[];let t=MU(i,x,fe),n=i.collapsed?T(jU(x,i.title),S,C):void 0;return[(0,B.jsx)(Xh,{title:i.title,open:t,toggle:n,children:e},`group:${i.title}`)]}if(i.kind===`related`&&i.lines)return!u.model||!u.item||r?[]:[(0,B.jsx)(XU,{lines:{...u,model:u.model,item:u.item},editable:v===`form`,saving:d.saving},`lines:${i.title}`)];if(i.kind===`related`)return i.from!==void 0&&!be(i.from)?[]:[(0,B.jsx)(SG,{item:i,value:CG(i,n.record,t),owner:e.name},`related:${i.title}`)];if(i.kind===`chart`)return[(0,B.jsx)(OU,{item:i,recordKey:t},`chart:${a}`)];if(r&&(i.kind===`custom`||i.kind===`map`||i.kind===`gallery`))return[];if(i.kind===`custom`)return i.sidebar?[]:[(0,B.jsx)(gU,{item:i,scope:oe},`custom:${a}`)];if(i.kind===`map`)return i.sidebar?[]:[(0,B.jsx)(xU,{item:i,record:n.record},`map:${a}`)];if(i.kind===`gallery`)return[(0,B.jsx)(AW,{item:i,record:n.record,recordKey:t},`gallery:${a}`)];if(i.kind===`history`)return[(0,B.jsx)(RW,{item:i,model:e,view:s,recordKey:t,etag:n.etag},`history:${a}`)];if(i.kind===`comments`)return[(0,B.jsx)(qW,{item:i,resource:e.name,recordKey:t,canWrite:l.kind!==`visitor`},`comments:${a}`)];if(i.kind!==`section`)return[];let o=i.fields.filter(t=>e.fields[t]&&ye(t)),c=v===`read`&&i.presentation===`facts`,f=c?Um(n.record,o):o;return f.length===0?[]:[(0,B.jsx)(Kf,{title:i.title,help:kg(i.helpWhen,s,b)?i.help:void 0,children:c?(0,B.jsx)(ng,{facts:f.map(e=>({label:Ce(e).label,value:Ce(e).value,icon:iE(ve(e)?.icon)}))}):v===`read`?(0,B.jsx)(tg,{rows:f.map(Ce)}):(0,B.jsx)(`div`,{className:`grid grid-cols-1 gap-x-6 gap-y-5 sm:grid-cols-2`,children:f.map(xe)})},i.title)]};return(0,B.jsxs)(`div`,{ref:m,className:`flex flex-1 flex-col`,inert:r,children:[A.dialogs,(0,B.jsx)(`div`,{className:`flex-1`,children:(0,B.jsxs)(`div`,{className:`mx-auto max-w-[1100px] px-4 pb-8 pt-6 md:px-10 md:py-8`,children:[(0,B.jsx)(Wf,{title:c,status:ge?{label:ar(ge,ve(`status`)?.valueLabels),tone:jm(ve(`status`)?.valueColors,ge)}:void 0}),d.message&&(0,B.jsx)(`div`,{className:`mt-4`,children:(0,B.jsx)(Gg,{title:Q(`notSaved`),error:Error(d.message)})}),d.linesConflict&&(0,B.jsx)(`div`,{className:`mt-4`,children:(0,B.jsx)(Gg,{title:Q(`linesChanged`),error:Error(Q(`linesReloaded`))})}),v!==`form`&&y&&d.dirty&&(0,B.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,B.jsx)(`span`,{children:Q(`unsavedKept`)}),(0,B.jsxs)(`span`,{className:`flex gap-2`,children:[(0,B.jsx)(Jh,{to:D,className:yf({size:`sm`}),children:Q(`continueEditing`)}),(0,B.jsx)(G,{size:`sm`,onClick:d.discard,children:Q(`discard`)})]})]}),v===`form`&&d.restored&&(0,B.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,B.jsx)(`span`,{children:Q(`unsavedRestored`)}),(0,B.jsxs)(`span`,{className:`flex gap-2`,children:[(0,B.jsx)(G,{size:`sm`,onClick:d.dismissRestored,children:Q(`keep`)}),(0,B.jsx)(G,{size:`sm`,onClick:d.discard,children:Q(`discard`)})]})]}),(0,B.jsxs)(`div`,{className:`grid grid-cols-1 gap-8 md:grid-cols-[minmax(0,1fr)_300px] md:gap-12`,children:[(0,B.jsxs)(`main`,{className:`divide-y divide-border`,children:[ce.flatMap(ke),de&&(0,B.jsx)(Zh,{tabs:le.map((e,t)=>({title:e.title,to:T(x,S,t===0?void 0:e.title),current:e===de}))}),de&&(0,B.jsx)(`div`,{className:`divide-y divide-border`,children:de.items.flatMap(ke)},`tab:${de.title}`),ue.flatMap(ke)]}),(0,B.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:[Oe&&(0,B.jsx)(`div`,{className:`hidden flex-col items-center gap-2 md:flex`,children:Oe}),!r&&(0,B.jsx)(AU,{model:e,stored:n,recordKey:t,edit:y?D:void 0,onDelete:De}),we===-1&&Te,se.map((e,t)=>e.kind===`custom`&&e.sidebar&&!r?(0,B.jsx)(gU,{item:e,scope:oe},`custom:${t}`):e.kind===`map`&&e.sidebar&&!r?(0,B.jsx)(xU,{item:e,record:n.record},`map:${t}`):t===we?(0,B.jsx)(I.Fragment,{children:Te},`summary`):null),(0,B.jsx)(fg,{title:Q(`details`),rows:[hU(e,`created`),_e].flatMap(t=>{let r=t?e.fields[t]:void 0;return!t||!r||!ye(t)||pe.includes(t)?[]:[{label:ve(t)?.label??F(t),value:be(t)?(0,B.jsx)(`span`,{title:zm(r,n.record[t],void 0,ve(t)),children:Rm(r,n.record[t],ve(t))}):(0,B.jsx)(Ch,{className:`h-4 w-24`})}]})}),!r&&(0,B.jsx)(gG,{model:e,recordKey:t,layout:se})]})]})]})}),Oe&&(0,B.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:Oe})]})},kG=e=>ml(e)?e.status===401||e.status===403?q(`signInRefused`,{message:e.message}):e.message:q(`noAnswer`),AG=({status:e})=>{let t=Se();return e.state===`error`?(0,B.jsx)(`div`,{className:`flex h-full min-h-48 flex-1 items-center justify-center p-8`,children:(0,B.jsxs)(`div`,{className:`max-w-md text-center`,children:[(0,B.jsx)(`h1`,{className:`text-[16px] font-semibold`,children:q(`cannotReach`,{label:e.source.label})}),(0,B.jsxs)(`p`,{className:`mt-1 text-muted-foreground`,children:[kG(e.error),` `,q(`restWorks`)]}),(0,B.jsx)(G,{className:`mt-3`,onClick:()=>void t.refetchQueries({queryKey:H.sourceMetas(e.source.url)}),children:q(`tryAgain`)})]})}):(0,B.jsxs)(`div`,{className:`flex h-full min-h-48 flex-1 items-center justify-center gap-2 text-muted-foreground`,children:[(0,B.jsx)(af,{}),` `,q(`loadingFrom`,{label:e.source.label})]})},jG=M(`app/search`),MG=(e,t)=>e.toLowerCase().includes(t.trim().toLowerCase()),NG=(e,t,n=``)=>{let r=lV(e,n).flatMap(e=>e.items.filter(e=>e.href!==void 0&&!e.problem)).filter(e=>MG(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||!aR(a,e.pages,e.permissions[r.name]??Jd))return[];let o=a.names?.singular??F(r.name),s=Mg(`title`,{noun:o});return!MG(s,t)&&!MG(o,i)&&!MG(a.names?.plural??F(r.name),i)?[]:[{id:`new:${r.name}`,title:s,href:Vc({kind:`create`,resource:r.name},n)}]});return[...r.length>0?[{id:`go-to`,label:jG(`goTo`),hits:r.map(e=>({id:`go-to:${e.id}`,title:e.label,href:e.href}))}]:[],...a.length>0?[{id:`create`,label:jG(`create`),hits:a.slice(0,5)}]:[]]},PG=sn(),FG=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??F(t.name)}]}),IG=e=>{let t=e.map(e=>e.label.toLowerCase());return t.length===0?jG(`search`):t.length===1?jG(`searchOne`,{name:t[0]}):t.length===2?jG(`searchTwo`,{first:t[0],second:t[1]}):jG(`searchMore`,{first:t[0],second:t[1]})},LG=e=>Yt(PG.search(e.trim())),RG=e=>!e.view?.searchResult?.title?.length&&e.view?.titleFrom!==void 0,zG=e=>{let t=e.view?.searchResult?.title;return t?.length?t:RG(e)?[]:[lr(e.model,e.view)]},BG=e=>{let t=zG(e);return e.view?.searchResult?.subtitle??e.model.search?.find(e=>!t.includes(e))},VG=e=>{let t=BG(e),n=RG(e)?m_(e.model,e.view):[],r=[...zG(e),...n,...t?[t]:[],...e.model.search??[]];return[...new Set([...e.model.primaryKey,...r.filter(t=>Object.hasOwn(e.model.fields,t))])]},HG=(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)},UG=(e,t,n,r=``,i=h_({},{user:void 0,member:()=>void 0}))=>{let a=Nn(wm(e.model,t)),o=zG(e),s=BG(e),c=Gt(e.model,t,n,[...o,...s?[s]:[]])??s,l=c?HG(e,t,c):``;return{id:a,title:RG(e)?i(e.model,e.view,t,a):o.map(n=>HG(e,t,n)).filter(Boolean).join(` `)||a,...l&&{subtitle:l},href:Vc({kind:`record`,resource:e.model.name,key:a},r)}},WG=()=>{let e=W(),t=U(),{basePath:n}=Ih(),r=v_(),i=(0,I.useMemo)(()=>FG(e),[e]),[a,o]=(0,I.useState)(``),s=a.trim(),c=aT(s,200),l=s.length>=2,u=l&&c.length>=2,d=f({queries:i.map(e=>({queryKey:[`global-search`,e.model.name,c],enabled:u,staleTime:1/0,gcTime:0,queryFn:()=>t.list(e.model.name,{filter:LG(c),pageSize:5,fields:VG(e)})}))}),p=(0,I.useMemo)(()=>u?NG(e,c,n):[],[u,e,c,n]),m=i.flatMap((e,t)=>{let i=d[t];if(!u||!i)return[];if(i.error)return[{id:e.model.name,label:e.label,hits:[],failed:!0}];let a=(i.data?.items??[]).map(t=>UG(e,t,c,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:IG(i),text:a,setText:o,query:u?c:``,loading:l&&(s!==c||d.some(e=>e.isFetching)),groups:h}},GG=M(`app/new-version`),KG=()=>{let{versionChange:e,appName:t}=W(),{reload:n}=Ih();return e?(0,B.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,B.jsx)(is,{"aria-hidden":!0,className:`mt-0.5 size-3.5 shrink-0`}),(0,B.jsxs)(`span`,{className:`flex min-w-0 flex-col gap-0.5`,children:[(0,B.jsx)(`span`,{className:`break-words font-semibold`,children:t?GG.rich(`bannerTitle`,{app:t}):GG(`title`)}),(0,B.jsx)(`span`,{className:`text-xs`,children:GG(`bannerLine`)})]})]}):null},qG=()=>{let e=!!W().versionChange,{reload:t}=Ih();return e?(0,B.jsxs)(G,{size:`sm`,variant:`ghost`,"aria-label":GG(`reloadPageHint`),title:GG(`reloadPageHint`),onClick:t,className:`max-md:size-9 max-md:p-0`,children:[(0,B.jsx)(is,{className:`size-3.5 text-primary`}),(0,B.jsx)(`span`,{className:`max-md:sr-only`,children:GG(`reloadPage`)})]}):null},JG=()=>document.querySelector(`[aria-modal="true"]`)!==null,YG=()=>{let[e,t]=(0,I.useState)(JG);return(0,I.useEffect)(()=>{let e=new MutationObserver(()=>t(JG()));return e.observe(document.body,{childList:!0,subtree:!0}),t(JG()),()=>e.disconnect()},[]),e},XG=()=>{let e=!!W().versionChange,t=YG(),[n,r]=(0,I.useState)(!1),i=ly(),{reload:a}=Ih(),o=e&&!n&&!t;return(0,I.useEffect)(()=>{if(!o)return;let e=i.show({state:`info`,sticky:!0,title:GG(`title`),description:GG(`description`),action:{label:GG(`reload`),onClick:a},onClose:()=>r(!0)});return()=>i.dismiss(e)},[o,i,a]),null},ZG=M(`app/runtime`),QG=e=>!!(e?.updateAvailable&&e.indicator),$G=e=>e?5e3:18e5,eK=(e,t)=>{if(!e.updateStage)return ZG(`updatingNow`);let n=ZG(e.updateStage);return e.updateStartedAt?ZG(`started`,{stage:n,ago:wp(Math.max(0,Math.floor((t-Date.parse(e.updateStartedAt))/1e3)))}):n},tK=(e,t=Date.now(),n=Xf())=>e.updating?eK(e,t):e.nextUpdateAt?ZG(`nextOn`,{policy:ZG(e.policy),when:gp(Date.parse(e.nextUpdateAt),n)}):ZG(e.policy),nK=(e,t=Xf())=>{let n=gp(Date.parse(e.finishedAt),t),r=ZG(e.outcome,{version:e.toVersion,when:n});return e.message?`${r}: ${e.message}`:`${r}.`},rK=e=>ml(e)&&e.status<500&&e.problem.detail?e.problem.detail:ml(e)&&e.status===409?ZG(`alreadyLatest`):ml(e)&&e.status===403?ZG(`onlyAdmin`):ZG(`couldNotStart`),iK=({label:e,value:t})=>(0,B.jsxs)(`div`,{className:`flex justify-between gap-4 py-1`,children:[(0,B.jsx)(`span`,{className:`text-muted-foreground`,children:e}),(0,B.jsx)(`span`,{className:`font-medium tabular-nums`,children:t})]}),aK=({status:e,requesting:t,error:n,checkError:r,onUpdate:i,onClose:a})=>{let o=e.updating?void 0:e.lastUpdate;return(0,B.jsxs)(Of,{title:ZG(`runtimeUpdate`),description:e.updating?(0,B.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,B.jsx)(af,{className:`size-3.5`}),tK(e)]}):tK(e),onClose:a,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:a,children:ZG(`close`)}),(0,B.jsx)(G,{variant:`primary`,loading:t,disabled:e.updating||!e.updateAvailable,onClick:i,children:e.updating?ZG(`updating`):ZG(`updateNow`)})]}),children:[(0,B.jsx)(iK,{label:ZG(`currentVersion`),value:e.version}),(0,B.jsx)(iK,{label:ZG(`latestVersion`),value:e.latest}),o&&(0,B.jsx)(`p`,{className:o.outcome===`failed`?`mt-3 text-danger-text`:`mt-3 text-muted-foreground`,children:nK(o)}),n!==void 0&&(0,B.jsx)(`p`,{role:`alert`,className:`mt-3 text-danger-text`,children:rK(n)}),r!==void 0&&(0,B.jsx)(`p`,{className:`mt-3 text-muted-foreground`,children:ZG(`checkFailed`)})]})},oK=e=>{let t=$P(),n=(0,I.useRef)(t);n.current=t;let r=t!==void 0;return(0,I.useMemo)(()=>r?cd({url:e,token:()=>n.current}):void 0,[e,r])},sK=e=>{let[t,n]=(0,I.useState)(),[r,i]=(0,I.useState)(!1),[a,o]=(0,I.useState)(),[s,c]=(0,I.useState)(),l=t?.updating??!1;return(0,I.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(),$G(l));return()=>{t=!1,clearInterval(i)}},[e,l]),{status:t,update:(0,I.useCallback)(async()=>{e&&(i(!0),o(void 0),await e.update().then(n,o),i(!1))},[e]),requesting:r,error:a,checkError:s}},cK=({client:e})=>{let{status:t,update:n,requesting:r,error:i,checkError:a}=sK(e),[o,s]=(0,I.useState)(!1);return!t||!o&&!QG(t)?null:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(G,{size:`sm`,variant:`ghost`,"aria-label":ZG(`updateAvailable`),title:ZG(`updateAvailable`),onClick:()=>s(!0),className:`max-md:size-9 max-md:p-0`,children:[(0,B.jsx)(Ni,{className:`size-3.5 text-primary`}),(0,B.jsx)(`span`,{className:`max-md:sr-only`,children:ZG(`update`)})]}),o&&(0,B.jsx)(aK,{status:t,requesting:r,error:i,checkError:a,onUpdate:()=>void n(),onClose:()=>s(!1)})]})},lK=({url:e})=>(0,B.jsx)(cK,{client:oK(e)}),uK=({url:e,client:t})=>t?(0,B.jsx)(cK,{client:t}):(0,B.jsx)(lK,{url:e}),dK=({signIn:e,onStop:t})=>{let[n,r]=(0,I.useState)(!1),[i,a]=(0,I.useState)(),o=async()=>{r(!0),a(void 0);try{await t()}catch(e){if(!(e instanceof ku))throw e;a(KA(e)),r(!1)}};return(0,B.jsxs)(`div`,{role:`region`,"aria-label":q(`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,B.jsx)(nc,{"aria-hidden":!0,className:`size-4 shrink-0`}),(0,B.jsx)(`p`,{className:`min-w-64 flex-1 break-words`,children:q.rich(`staffSignedIn`,{staff:(0,B.jsx)(`span`,{className:`font-semibold`,children:e.staffName??e.staff}),user:(0,B.jsx)(`span`,{className:`font-semibold`,children:e.user}),until:gp(Date.parse(e.expiresAt)),reason:e.reason})}),i&&(0,B.jsx)(`p`,{role:`alert`,className:`text-body font-medium text-danger-text`,children:i}),(0,B.jsx)(G,{size:`sm`,loading:n,onClick:()=>void o(),children:q(`stopStaffSession`)})]})},fK=(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=lH(t,n);return[e,{...i,person:{...a&&{status:a},...o&&{presence:o}}}]}))},pK=(e,t,n)=>({filter:n.filter??``,orderBy:n.orderBy??gh(e,t),pageSize:n.limit??3,fields:[...new Set([...e.primaryKey,lr(e,t),...m_(e,t),...n.status===void 0?[]:[n.status]])]}),mK=(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}},hK=(e,t,n,r,i,a,o)=>r.map(r=>{let s=Nn(wm(e,r)),c=mK(e,t,n,r);return{id:s,label:o(e,t,r,s),href:Vc({kind:`record`,resource:e.name,key:s},i),...c&&{status:c},active:s===a}}),gK=(e,t,n,r,i)=>{let a=n.find(t=>Nn(wm(e,t))===r);return a!==void 0&&t.some(e=>!Object.is(a[e],i[e]))},_K=(e,t,n)=>{if(t.marks===void 0||!n||!Object.hasOwn(n,t.marks))return;let r=n[t.marks];return()=>r(e)},vK=e=>e&&(()=>fK(e(),cH(),a_().data)),yK=({model:e,request:t})=>H.navRecent(e.name,t.filter,t.orderBy,t.pageSize),bK=e=>{let t=Se();(0,I.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(yK(n));e&&gK(n.model,n.request.fields,e.items,a,o)&&t.invalidateQueries({queryKey:yK(n),exact:!0})}}),[t,e])},xK=(e,t,n)=>{let r=U(),i=v_(),{marks:a}=p_(),o=(0,I.useMemo)(()=>{let t=rV(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:pK(r,n,i),useMarks:vK(_K(r.name,i,a))}]:[]})},[e,a]);bK(o);let s=f({queries:o.map(e=>({queryKey:yK(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:hK(e,r,a,l.data.items,t,u,i),...o&&{useMarks:o}}]}))},SK=({answer:e,current:t,next:n,launch:r})=>{if(!e?.bundleId||e.bundleId===t)return{kind:`none`};let i=r&&e.required;return e.bundleId===n&&!i?{kind:`none`}:{kind:`take`,bundleId:e.bundleId,download:e.bundleId!==n,reload:i}},CK=6e4,wK=e=>{let t=typeof e==`object`&&e?e.bundleId:void 0;return typeof t==`string`?t:null},TK=({bridge:e,check:t,releasesUrl:n,onHold:r})=>{let i=(t,n={})=>e.nativePromise(`LiveUpdate`,t,n),a=t=>t instanceof e.Exception,o=async(e,t)=>{t&&await i(`downloadBundle`,{bundleId:e,url:`${n}/${e}`,artifactType:`manifest`}),await i(`setNextBundle`,{bundleId:e})},s=async(e,t)=>{let n=!0,a=()=>{n&&(n=!1,r(!1))};r(!0);let s=setTimeout(a,CK);try{await o(e,t),n&&await i(`reload`)}finally{clearTimeout(s),a()}},c=async e=>{let[n,r,c]=await Promise.all([t(),i(`getCurrentBundle`),i(`getNextBundle`)]),l=SK({answer:n,current:wK(r),next:wK(c),launch:e});if(l.kind!==`none`)try{await(l.reload?s(l.bundleId,l.download):o(l.bundleId,l.download))}catch(e){if(!a(e))throw e}},l;return{ready:()=>i(`ready`),check:e=>(l??=c(e).finally(()=>{l=void 0}),l)}},EK=e=>/(?:^|\s)ProtobaseNative\/([0-9a-f]{16})(?:\s|$)/.exec(e)?.[1],DK=/^[A-Za-z0-9_-]{1,64}$/,OK=e=>typeof e==`object`&&!!e&&!Array.isArray(e),kK=e=>{if(!OK(e))return;let{bundleId:t,url:n,required:r}=e;if((t===null||typeof t==`string`&&DK.test(t))&&(n===null||typeof n==`string`)&&typeof r==`boolean`)return{bundleId:t,url:n,required:r}},AK=15e3,jK=e=>e instanceof TypeError||e instanceof DOMException&&e.name===`TimeoutError`,MK=async(e,{apiOrigin:t,fingerprint:n,shellVersion:r})=>{let i=`${t}${fr}?${mr({fingerprint:n,shellVersion:r})}`;try{let t=await e(i,{credentials:`omit`,cache:`no-store`,signal:AbortSignal.timeout(AK)});return t.status===200?kK(await t.json()):void 0}catch(e){if(jK(e)||e instanceof SyntaxError)return;throw e}},NK=({bridge:e,apiOrigin:t,userAgent:n,fetch:r,onHold:i})=>{if(!e?.Exception||!e.isPluginAvailable(`LiveUpdate`))return;let a=EK(n);return TK({bridge:{nativePromise:e.nativePromise.bind(e),Exception:e.Exception},check:async()=>a&&t?MK(r,{apiOrigin:t,fingerprint:a,shellVersion:PP}):void 0,releasesUrl:`${t}${pr}`,onHold:i})},PK=M(`app/live-update`),FK=({nativeBridge:e,apiOrigin:t,children:n})=>{let[r,i]=(0,I.useState)(!1),a=(0,I.useMemo)(()=>NK({bridge:e,apiOrigin:t,userAgent:navigator.userAgent,fetch:window.fetch.bind(window),onHold:i}),[e,t]);return(0,I.useEffect)(()=>{if(!a)return;a.ready(),a.check(!0);let e=()=>{document.visibilityState===`visible`&&a.check(!1)};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[a]),r?(0,B.jsx)(sf,{title:PK(`holdTitle`),children:PK(`holdLine`)}):n},IK=[`never`,`thirty_minutes`,`one_hour`,`four_hours`,`today`,`this_week`,`custom`],LK={thirty_minutes:30,one_hour:60,four_hours:240},RK=(e,t)=>new Date(e.getFullYear(),e.getMonth(),e.getDate()+t),zK=(e,t,n=``)=>{if(e===`never`)return null;if(e===`today`)return RK(t,1).toISOString();if(e===`this_week`)return RK(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()+LK[e]*6e4).toISOString()},BK=e=>String(e).padStart(2,`0`),VK=e=>{let t=new Date(e);return`${t.getFullYear()}-${BK(t.getMonth()+1)}-${BK(t.getDate())}T${BK(t.getHours())}:${BK(t.getMinutes())}`},HK=(e,t=Date.now())=>{let n=Tr(e,t);return n?{availability:n.availability,text:n.text??``,clears:n.clearsAt===null?`never`:`custom`,custom:n.clearsAt===null?``:VK(n.clearsAt)}:{availability:`automatic`,text:``,clears:`never`,custom:``}},UK=(e,t)=>{let n=e.text.trim(),r=n===``?void 0:wr(n);if(r)return{problem:`text`,message:r};let i=zK(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}}},WK={never:`never`,thirty_minutes:`thirtyMinutes`,one_hour:`oneHour`,four_hours:`fourHours`,today:`today`,this_week:`thisWeek`,custom:`custom`},GK=({current:e,onSave:t,onClear:n,onClose:r})=>{let[i,a]=(0,I.useState)(()=>HK(e)),[o,s]=(0,I.useState)(!1),[c,l]=(0,I.useState)(),[u,d]=(0,I.useState)(!1),f=(0,I.useId)(),p=(0,I.useId)(),m=(0,I.useId)(),h=e=>a({...i,...e}),g=UK(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 fl))throw e;l(e.status===400?e.message:rS(`couldNotSave`)),s(!1)}},y=()=>{d(!0),`input`in g&&v(()=>t(g.input))};return(0,B.jsx)(Of,{title:rS(e?`editStatus`:`setStatus`),onClose:r,actions:(0,B.jsxs)(B.Fragment,{children:[e&&(0,B.jsx)(G,{variant:`ghost`,className:`sm:mr-auto`,disabled:o,onClick:()=>void v(n),children:rS(`clear`)}),(0,B.jsx)(G,{onClick:r,children:rS(`cancel`)}),(0,B.jsx)(G,{variant:`primary`,type:`submit`,form:f,loading:o,children:rS(`save`)})]}),children:(0,B.jsxs)(`form`,{id:f,className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),y()},children:[(0,B.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,B.jsx)(`label`,{htmlFor:p,className:`font-medium`,children:rS(`statusText`)}),(0,B.jsx)(J,{id:p,name:`status`,autoComplete:`off`,autoFocus:!0,placeholder:rS(`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,B.jsx)(`span`,{id:`${p}-problem`,className:`text-xs text-danger-text`,children:_.message})]}),(0,B.jsxs)(`div`,{className:`flex flex-col gap-1.5 font-medium`,children:[rS(`availability`),(0,B.jsx)(Re,{label:rS(`availability`),value:i.availability,onChange:e=>h({availability:e}),options:[{value:`automatic`,label:rS(`automatic`)},{value:`busy`,label:rS(`busy`)},{value:`do_not_disturb`,label:rS(`doNotDisturb`)}]}),i.availability===`do_not_disturb`&&(0,B.jsx)(`span`,{className:`text-xs font-normal text-muted-foreground`,children:rS(`doNotDisturbHint`)})]}),(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[rS(`clearsAfter`),(0,B.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:IK.map(e=>(0,B.jsx)(`option`,{value:e,children:rS(WK[e])},e))})]}),i.clears===`custom`&&(0,B.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,B.jsx)(`label`,{htmlFor:m,className:`font-medium`,children:rS(`clearsAt`)}),(0,B.jsx)(J,{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,B.jsx)(`span`,{id:`${m}-problem`,className:`text-xs text-danger-text`,children:rS(`pickTime`)})]}),c&&(0,B.jsx)(`p`,{role:`alert`,className:`text-danger-text`,children:c})]})})},KK=e=>{let t=U(),n=Se(),r=o_(),[i,a]=(0,I.useState)(!1);if(!e||!r.isSuccess)return{};let o=Tr(r.data),s=()=>n.invalidateQueries({queryKey:[`statuses`]});return{menu:{mark:o&&(0,B.jsx)(sS,{status:o,textShown:`hover`}),label:o?(0,B.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5 text-foreground`,children:[(0,B.jsx)(oS,{availability:o.availability}),(0,B.jsx)(`span`,{className:`truncate`,children:o.text??aS(o.availability)})]}):rS(`setStatus`),onOpen:()=>a(!0)},...i&&{dialog:(0,B.jsx)(GK,{current:o,onSave:async e=>{await t.status.set(e),await s()},onClear:async()=>{await t.status.clear(),await s()},onClose:()=>a(!1)})}}},qK=e=>e?.kind===`page`?e.page:e?.kind===`list`?aV(e.resource,e.list):e?.resource,JK=e=>e?.kind===`record`?e:void 0,YK=({workspace:e,sidebarMode:t,assistant:n,runtime:r})=>{let i=W(),{state:a,session:o,signOut:s,stopStaffSession:c,organizations:l}=V(),u=oE();if(a.kind!==`signed-in`&&a.kind!==`visitor`)throw Error(`The shell is only rendered for a signed-in user or a visitor`);let d=a.kind===`signed-in`?a.user:void 0,f=a.kind===`signed-in`?a.staff:void 0,{path:p,params:m,basePath:h}=Ih(),{address:g,go:_,open:v,back:y}=qh(),b=qK(g),x=JK(g),S=WG(),C=_I(),w=xK(i,h,{resource:x?.resource,key:x?.key});nF(i);let T=lV(i,h,w),E=(0,I.useMemo)(()=>IH(i),[i]),D=g?.kind===`page`?i.pages[g.page]:void 0;(0,I.useEffect)(()=>{p===`/`&&E&&_(E,{replace:!0})},[p,E,_]);let O=g?.kind===`page`?void 0:g?.resource,k=O?tf(i,O):void 0,A=O?Cn(i.views[O],g?.kind===`list`?g.list:void 0):void 0,j=T.find(e=>e.items.some(e=>e.id===b)),ee=O?i.resources[O]:void 0,te=iF(x?.resource??``,x?.key??``,!!(ee&&x)),ne=v_(),re=ee&&x&&te.data?ne(ee,A,te.data.record,x.key):void 0,ie=!!x&&(te.isLoading||k?.state===`loading`),{shell:ae}=p_(),oe=ae?.actions,se=ae?.rightPanel,ce=i.bell&&d&&!f&&(0,B.jsx)(uU,{own:ae?.bell}),le=KK(!!(i.status&&d&&!f)),ue=a_().data,de=cH(),[fe,pe]=(0,I.useState)(!1),me=i.assistant?.url,he=me&&(0,B.jsx)(SL,{open:fe,onToggle:()=>pe(!fe)}),ge=me&&fe&&(0,B.jsx)(TL,{url:me,client:n,page:m.size>0?`${p}?${m}`:p,onClose:()=>pe(!1)}),_e=i.errorReporting;(0,I.useEffect)(()=>{_e&&lv(_e)},[_e]);let ve=i.runtime?.url,ye=ve&&(0,B.jsx)(uK,{url:ve,client:r}),be=gS(t??`text-small`),xe=i.versionChange&&!be&&(0,B.jsx)(qG,{}),Se=FH((0,I.useCallback)(()=>yH(h),[h]),!!d),Ce=d&&MH(d,Se.current),we=Ce?U_(Ce):!1,Te=fU(),Ee=vH(!!(l&&d)),De=Ee.current,Oe=!!l&&De!==void 0&&!De.organization,ke=l&&d?lj(p):void 0,Ae=IM(),je=d?Ec(p):void 0,Me=je&&Ae?gf(hf(Ae.tree),je.tab):void 0,Ne=d?je?Ae?.title??q(`account`):p===`/-/sign-in-policy`?q(`signInPolicy`):ke:void 0,M=A?.names?.plural??(O&&F(O)),Pe=Ne?[Ne]:AL({basePath:h,address:g,group:j?.label,page:D,resourceLabel:M,recordTitle:re,recordLoading:ie}),Fe=A?.names?.singular??(O&&F(O)),Ie=D&&g?.kind===`page`?gf(hf(D.tree),g.tab):void 0;BM(zM(RM({address:g,page:D?{title:D.title,...Ie&&{tab:Ie.label}}:je&&Ae&&{title:Ae.title,...Me&&{tab:Me.label}},accountPage:Ne,resourceLabel:M,singular:Fe,recordTitle:re,recordLoading:ie}),i.appName));let Le=je?(0,B.jsx)(LM,{...je}):d&&p===`/-/sign-in-policy`?we?(0,B.jsx)(xN,{}):(0,B.jsx)(sf,{title:q(`adminsOnly`),children:q(`onlyAdminPolicy`)}):ke&&p===`/-/organization`?(0,B.jsx)(TH,{current:De,basePath:h,onChanged:Ee.reload}):ke&&(p===`/-/organization/members`||p===`/-/organization/invitations`)?fj(De)?p===`/-/organization/members`?(0,B.jsx)(fH,{current:De,statuses:ue,presence:de}):(0,B.jsx)(hH,{current:De}):(0,B.jsx)(sf,{title:q(`ownersOnly`),children:q(`onlyOwners`)}):ke&&p===`/-/organizations`||Oe?(0,B.jsx)(jH,{state:Ee,basePath:h}):g?g.kind===`page`?D?(0,B.jsx)(jL,{name:D.name,...g.tab&&{tab:g.tab}},D.name):(0,B.jsx)(sf,{title:q(`notFound`),children:q.rich(`noPage`,{page:g.page})}):k&&k.state!==`ready`?(0,B.jsx)(AG,{status:k}):g.kind===`create`?(0,B.jsx)(BL,{resource:g.resource,values:g.values},g.resource):g.kind===`record`?(0,B.jsx)(EG,{resource:g.resource,recordKey:g.key},`${g.resource}/${g.key}`):(0,B.jsx)(nH,{address:g},aV(g.resource,g.list)):p===`/`?(0,B.jsx)(sf,{title:q(`chooseResource`),children:q(`pickFromSidebar`)}):(0,B.jsx)(sf,{title:q(`notFound`),children:q(`nothingHere`)}),Re=we&&Te.length>0;return(0,B.jsxs)(ES,{pageScroll:!0,sidebarMode:t??`text-small`,activeItem:b??``,breadcrumb:Pe,user:Ce&&G_(Ce),onSignOut:d&&(()=>void s()),signIn:d?void 0:u.link(),workspace:De?.organization?.name??e,appName:i.appName,appIcon:i.appIcon,logo:LH,navGroups:T,bottomBar:kL(i,h,b),userMenu:[iV(i,h,b),l&&d?pj(h,p,De):[],d?Oc(h,p,we):[]],account:d&&`${h}/-/account`,organizations:l&&{...De?.organization&&{current:{id:De.organization.id,name:De.organization.name}},others:Ee.organizations.filter(e=>e.id!==De?.organization?.id),onSwitch:e=>void o.organizations.switchTo(e).then(()=>yH(h))},theme:{preference:C.preference,onChange:C.choose},...le.menu&&{status:le.menu},roles:Se.current?.active?{active:Se.current.active,roles:Se.current.roles,onSwitch:Se.switchTo}:void 0,onNavigate:v,onBack:y,sidebarNotice:(0,B.jsx)(KG,{}),banner:(f||Re)&&(0,B.jsxs)(B.Fragment,{children:[f&&(0,B.jsx)(dK,{signIn:f,onStop:c}),Re&&(0,B.jsx)(mU,{off:Te})]}),search:S.available?{placeholder:S.placeholder,text:S.text,onTextChange:S.setText,query:S.query,loading:S.loading,groups:S.groups,onSelect:v}:void 0,actions:(oe||ce||xe||ye||he)&&(0,B.jsxs)(B.Fragment,{children:[oe&&(0,B.jsx)(pv,{name:`shell.actions`,fallback:null,children:(0,B.jsx)(oe,{})}),ce,xe,ye,he]}),rightPanel:(se||ge)&&(0,B.jsxs)(B.Fragment,{children:[se&&(0,B.jsx)(pv,{name:`shell.rightPanel`,fallback:null,children:(0,B.jsx)(se,{})}),ge]}),children:[Le,le.dialog,i.calls&&d&&!f&&(0,B.jsx)(KH,{})]})},XK=({baseUrl:e,client:t,sources:n,workspace:r,sidebarMode:i,ui:a,assistant:o,runtime:s})=>{let{state:c,session:l,markSignedOut:u}=V(),d=gS(i??`text-small`),{path:f}=Ih();return(0,B.jsx)(Kd,{baseUrl:e,client:t,sources:n,token:c.kind===`visitor`?void 0:l.token,onUnauthenticated:u,children:(0,B.jsx)(lf,{children:(0,B.jsxs)(uy,{children:[!d&&(0,B.jsx)(XG,{}),f===`/-/connect`?(0,B.jsx)(lN,{}):(0,B.jsx)(pU,{ui:a,children:(0,B.jsx)(_H,{children:(0,B.jsx)(x_,{children:(0,B.jsx)(YK,{workspace:r,sidebarMode:i,assistant:o,runtime:s})})})})]})})})},ZK=({baseUrl:e,client:t,ui:n,children:r})=>{let i=lF();return i?(0,B.jsx)(Kd,{baseUrl:e,client:t,children:(0,B.jsx)(f_.Provider,{value:n??{},children:(0,B.jsx)(sF,{name:i.name},i.name)})}):r},QK=({baseUrl:e,children:t})=>{let n=UF(),{basePath:r}=Ih();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,B.jsx)(sI,{link:n.token,systemPath:a,base:`${window.location.origin}${r}`})},$K=({auth:e,workspace:t,basePath:n,initialUrl:r,pluginLoader:i,locale:a,nativeBridge:o,...s})=>{Pe(a??`en`);let c=s.baseUrl&&new URL(s.baseUrl,window.location.href).origin;return(0,B.jsx)(gI,{children:(0,B.jsx)(FK,{nativeBridge:o,apiOrigin:c,children:(0,B.jsx)(Pd,{session:e,...c&&{origin:c},...o&&{nativeBridge:o},children:(0,B.jsx)(Wh,{basePath:n,initialUrl:r,children:(0,B.jsx)(VP,{...i&&{loader:i},children:(0,B.jsx)(eF,{children:(0,B.jsx)(ZK,{baseUrl:s.baseUrl,client:s.client,ui:s.ui,children:(0,B.jsx)(QK,{...s.baseUrl&&{baseUrl:s.baseUrl},children:(0,B.jsx)(YP,{workspace:t,children:(0,B.jsx)(XK,{workspace:t,...s})})})})})})})})})})};export{WE as $,vI as A,xp as At,CN as B,af as Bt,WI as C,J as Ct,MI as D,qh as Dt,LI as E,Jh as Et,NP as F,jf as Ft,qM as G,H as Gt,VM as H,Kd as Ht,PP as I,Of as It,rA as J,jr as Jt,vj as K,Nd as Kt,OP as L,G as Lt,Z as M,Xf as Mt,rF as N,Jf as Nt,DI as O,Dh as Ot,$P as P,Kf as Pt,GE as Q,xP as R,yf as Rt,qI as S,Jg as St,zI as T,$h as Tt,HM as U,U as Ut,SN as V,Xd as Vt,KM as W,Hd as Wt,jk as X,Ak as Y,Or as Yt,JE as Z,nL as _,l_ as _t,oU as a,By as at,ZI as b,a_ as bt,cH as c,ey as ct,bL as d,tv as dt,lE as et,vL as f,I_ as ft,aL as g,u_ as gt,cL as h,d_ as ht,iU as i,Eb as it,oI as j,np as jt,xI as k,Kp as kt,FL as l,Wv as lt,pL as m,S_ as mt,eG as n,sS as nt,rU as o,Hy as ot,_L as p,E_ as pt,fA as q,ld as qt,$W as r,Ax as rt,JH as s,Vy as st,$K as t,oS as tt,xL as u,vv as ut,tL as v,r_ as vt,BI as w,eg as wt,XI as x,Yg as xt,eL as y,o_ as yt,mP as z,W as zt};
|
|
8
|
+
//# debugId=59fce71f-a59f-465b-a119-fa2e310bab2a
|