@protobase/ui 0.54.5 → 0.55.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app/app.js +6 -5
- package/dist/app/create/create-values.js +5 -5
- package/dist/app/field-editor.js +1 -1
- package/dist/app/field-types/built-in-fields.js +6 -0
- package/dist/app/field-types/members/member-chip.js +20 -0
- package/dist/app/field-types/members/member-ids.js +13 -0
- package/dist/app/field-types/members/members-display.js +44 -0
- package/dist/app/field-types/members/members-editor.js +44 -0
- package/dist/app/field-types/members/members-field.js +16 -0
- package/dist/app/field-types/members/messages.js +18 -0
- package/dist/app/field-types/members/use-members-field.js +18 -0
- package/dist/app/field-types/shown-widget.js +11 -6
- package/dist/app/nav-recent.js +7 -5
- package/dist/app/pages/field-value.js +19 -11
- package/dist/app/pages/merge-ui.d.ts +1 -1
- package/dist/app/pages/merge-ui.js +3 -1
- package/dist/app/pages/project-ui.d.ts +4 -1
- package/dist/app/picker/picker-combobox.js +140 -0
- package/dist/app/record-page.js +3 -3
- package/dist/app/related-cards/related-card.js +32 -28
- package/dist/app/relation-picker.js +27 -124
- package/dist/app/search/search-model.js +15 -6
- package/dist/app/search/use-global-search.js +3 -1
- package/dist/app/titles/record-title-of.js +17 -0
- package/dist/app/titles/record-titles.js +63 -0
- package/dist/app/titles/relation-title.js +35 -0
- package/dist/app/titles/title-rule.d.ts +14 -0
- package/dist/app/use-nav-recent.js +3 -1
- package/dist/app/use-related-records.js +9 -9
- package/dist/data/query-keys.js +7 -0
- package/dist/filter-panel/facet-combobox.js +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/dist/live/field-values.js +22 -1
- package/dist/organizations/organizations-page.js +1 -1
- package/dist/package.js +1 -1
- package/dist/plugins/plugin-ui.js +1 -0
- package/dist/shell/assets/app-tBBnYXLP.js +9 -0
- package/dist/shell/assets/{index-DvC8OI3c.js → index-DvCa5s54.js} +2 -2
- package/dist/shell/assets/{records-map-C-UIoBtb.js → records-map-BWSeQRmm.js} +2 -2
- package/dist/shell/assets/shared-protobase-ui-Br4XDldp.js +2 -0
- package/dist/shell/index.html +3 -3
- package/dist/shell/protobase.shell.json +1 -1
- package/dist/shell/protobase.sw.js +2 -2
- package/dist/shell-source-maps/assets/app-tBBnYXLP.js.map +1 -0
- package/dist/shell-source-maps/assets/{index-DvC8OI3c.js.map → index-DvCa5s54.js.map} +1 -1
- package/dist/shell-source-maps/assets/{records-map-C-UIoBtb.js.map → records-map-BWSeQRmm.js.map} +1 -1
- package/dist/shell-source-maps/assets/shared-protobase-ui-Br4XDldp.js.map +1 -0
- package/package.json +4 -4
- package/dist/shell/assets/app-7LGt1Apg.js +0 -9
- package/dist/shell/assets/shared-protobase-ui-Cc69lTef.js +0 -2
- package/dist/shell-source-maps/assets/app-7LGt1Apg.js.map +0 -1
- package/dist/shell-source-maps/assets/shared-protobase-ui-Cc69lTef.js.map +0 -1
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/markdown-content-DOuciTNH.js","assets/rolldown-runtime-hePW80VL.js","assets/react-CR5VJ85Q.js","assets/cn-Bi0ZEjD9.js","assets/records-map-C-UIoBtb.js","assets/maplibre-CjNYwEqW.js","assets/preload-helper-SYSsmQ2O.js","assets/maplibre-DBE96hFo.css","assets/record-map-DjqQGqZ2.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,r as n,t as r}from"./react-CR5VJ85Q.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,d as ie,et as ae,f as oe,g as se,h as ce,i as le,it as ue,j as de,k as fe,l as pe,m as me,n as he,nt as ge,o as _e,ot as ve,p as ye,q as be,r as xe,rt as Se,s as Ce,st as we,t as Te,tt as Ee,u as De,v as Oe,w as ke,x as Ae,y as je,z as Me}from"./vendor-xNCj9Gc_.js";import{a as M,d as Ne,f as Pe,i as Fe,l as Ie,n as Le,o as N,r as Re,s as ze,t as Be,u as Ve}from"./preload-helper-SYSsmQ2O.js";import{t as P}from"./cn-Bi0ZEjD9.js";var He=(e,t,n,r)=>({code:e,message:t,hint:n,span:r}),Ue=(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]},We=(e,t)=>{let n=e.toLowerCase(),r=t.map(e=>({candidate:e,score:Ue(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},Ge={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`}},Ke={extensions:{arithmetic:`now-offset`,durationUnits:!0}},qe=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`}},Je=e=>({fields:Object.fromEntries(Object.values(e.fields).map(e=>[e.name,{type:qe(e),filterable:e.filterable,sortable:e.sortable,aliases:e.aliases,...e.enumValues&&{values:e.enumValues}}])),functions:Ge}),Ye=(e,t,n,r)=>{e.errors.push(He(`unsupported`,t,n,r))},Xe=(e,t)=>t.kind===`member`?{kind:`field`,path:t.path,span:t.span}:Ye(e,`Only fields can be compared`,`Put a field name on the left, for example total > 100`,t.span),Ze=(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}:Ye(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}:Ye(e,`Arithmetic is only supported as now() +/- duration`,`Write now() - 30d`,t.span)}default:return t}},Qe=(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}:Ye(e,`Expected a literal value`,`Use strings, numbers, true/false, durations or timestamps`,t.span)),$e=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``}},et=(e,t)=>{let[n,r,...i]=t.args,a=n?.kind===`member`?Xe(e,n):void 0,o=e=>e?.kind===`string`?e.value:void 0,s=n=>{e.errors.push(He(`invalid-arguments`,`Invalid arguments to ${t.name}()`,`Usage: ${n}`,t.span))};switch(t.name){case`in`:{let n=t.args.slice(1).map(t=>Qe(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(He(`unknown-function`,`Unknown function "${t.name}"`,`Available functions: ${Object.keys(Ge).join(`, `)}`,t.span));return}},tt=e=>e.every(e=>e)?e:void 0,nt=(e,t)=>{switch(t.kind){case`sequence`:case`and`:case`or`:{let n=tt(t.args.map(t=>nt(e,t)));return n&&{kind:t.kind===`or`?`or`:`and`,args:n,span:t.span}}case`not`:{let n=nt(e,t.arg);return n&&{kind:`not`,arg:n,span:t.span}}case`compare`:{let n=Xe(e,t.left),r=Ze(e,t.right);return n&&r&&{kind:`compare`,op:t.op,field:n,value:r,span:t.span}}case`has`:{let n=Xe(e,t.left),r=Qe(e,t.right);return n&&r&&{kind:`has`,field:n,value:r,span:t.span}}case`present`:{let n=Xe(e,t.left);return n&&{kind:`present`,field:n,span:t.span}}case`global`:return{kind:`search`,text:$e(t.value),span:t.span};case`call`:return et(e,t)}},rt=(e,t={})=>{let n=ve(e,{...Ke,...t}),r={errors:[]},i=n.ast&&nt(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}},it=(e,t)=>t===2?e%4==0&&(e%100!=0||e%400==0)?29:28:[4,6,9,11].includes(t)?30:31,at=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<=it(n,r)},ot=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 at(t[1])&&n<=23&&r<=59&&i<=59&&a<=23&&o<=59},st=(e,t)=>({message:e,hint:t}),ct=-(2n**63n),lt=2n**63n-1n,ut=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,dt=e=>e.kind===`number`?e.raw:e.kind===`string`?e.value:void 0,ft=(e,t=`Write ${e} values like the examples in the docs`)=>st(`Expected ${e}`,t),pt=e=>{let t=dt(e),n=t===void 0?NaN:Number(t);if(t===void 0||t.trim()===``||!Number.isSafeInteger(n))return ft(`a whole number`,`Use an integer such as 42, or a bigint field for larger values`)},mt=e=>{let t=dt(e);if(t===void 0||!/^-?\d+$/.test(t)||BigInt(t)<ct||BigInt(t)>lt)return ft(`a 64-bit integer`,`Use plain digits such as 9007199254740993 (no exponent or fraction)`)},ht=e=>{let t=dt(e);if(t===void 0||!/^-?\d+(\.\d+)?$/.test(t))return ft(`a decimal number`,`Use plain digits such as 100.50, or quote it: "100.50" (no exponent)`)},gt=(e,t)=>{if(t.kind===`now`)return e.type===`date`||e.type===`timestamp`?void 0:st(`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:ft(`a quoted string`,`Wrap the text in double quotes`);case`integer`:return pt(t);case`bigint`:return mt(t);case`decimal`:return ht(t);case`boolean`:return t.kind===`boolean`?void 0:ft(`true or false`);case`date`:return t.kind===`string`&&at(t.value)?void 0:ft(`a date`,`Quote a calendar date: "2012-04-21"`);case`timestamp`:return t.kind===`timestamp`||t.kind===`string`&&ot(t.value)?void 0:ft(`an RFC-3339 timestamp`,`Use 2012-04-21T11:30:00Z, or now() - 7d`);case`uuid`:return t.kind===`string`&&ut.test(t.value)?void 0:ft(`a uuid`,`Quote a uuid like "0b5a4f0e-6f2a-4a3c-9d4e-1f2a3b4c5d6e"`);case`enum`:return t.kind===`string`&&e.enumValues?.includes(t.value)?void 0:st(`Invalid enum value`,`Allowed values: ${(e.enumValues??[]).join(`, `)}`);case`currency`:return t.kind===`string`&&/^[A-Z]{3}$/.test(t.value)?void 0:ft(`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:ft(`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:ft(`a record key`,`Use the related record key: 42 or "abc"`);case`json`:case`file`:return st(`${e.type} fields cannot be compared`,`Use field:value on json fields, or isNull(field)`)}},_t=(e,t)=>Object.hasOwn(e.fields,t)?e.fields[t]:Object.values(e.fields).find(e=>e.aliases.includes(t)),vt=(e,t,n)=>{if(t.path.length>1){e.errors.push(He(`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=_t(e.model,r);if(!i){let i=Object.values(e.model.fields).filter(e=>e[n]).map(e=>e.name),a=We(r,i);e.errors.push(He(`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(He(n===`filterable`?`not-filterable`:`not-sortable`,`Field "${i.name}" is not ${r}`,`Mark it with .${r}() in data.ts`,t.span));return}return i},yt=[`=`,`!=`],bt=[`=`,`!=`,`<`,`<=`,`>`,`>=`],xt=e=>{switch(e){case`text`:case`integer`:case`bigint`:case`decimal`:case`date`:case`timestamp`:return bt;case`json`:case`file`:return[];default:return yt}},St=e=>e===`json`||e===`file`,Ct=(e,t,n)=>{let r=gt(t,n);return r&&e.errors.push(He(`invalid-value`,r.message,r.hint,n.span)),!r},wt=(e,t,n,r)=>{e.errors.push(He(`operator-not-allowed`,t,n,r))},Tt=(e,t)=>(e===`=`||e===`!=`)&&t.kind===`string`&&t.value.includes(`*`),Et=(e,t)=>{let n=vt(e,t.field,`filterable`);if(!n)return;let r=xt(n.type);if(!r.includes(t.op)){wt(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(Tt(t.op,t.value)&&n.type!==`text`){e.errors.push(He(`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(Tt(t.op,t.value)||Ct(e,n,t.value))return{...t,field:n}},Dt=(e,t)=>{let n=vt(e,t.field,`filterable`);if(n){if(n.type!==`json`){wt(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}}},Ot=(e,t)=>{let n=vt(e,t.field,`filterable`);if(n){if(St(n.type)){wt(e,`in() is not supported for ${n.type} fields`,`Use field:value on json fields`,t.span);return}return t.values.map(t=>Ct(e,n,t)).every(Boolean)?{...t,field:n}:void 0}},kt=(e,t,n)=>{let r=vt(e,n,`filterable`);if(r&&r.type!==`text`){wt(e,`${t}() only works on text fields, not ${r.type}`,`Field "${r.name}" is ${r.type}`,n.span);return}return r},At=(e,t)=>{switch(t.kind){case`and`:case`or`:{let n=t.args.map(t=>At(e,t));return n.every(e=>e)?{...t,args:n}:void 0}case`not`:{let n=At(e,t.arg);return n&&{...t,arg:n}}case`compare`:return Et(e,t);case`has`:return Dt(e,t);case`in`:return Ot(e,t);case`search`:if(e.model.search?.length)return t;e.errors.push(He(`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=vt(e,t.field,`filterable`);return n&&{...t,field:n}}case`similar`:case`regex`:{let n=kt(e,t.kind,t.field);return n&&{...t,field:n}}}},jt=(e,t)=>{let n={model:e,errors:[]},r=At(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}},Mt=(e,t)=>`path`in e?{kind:`member`,path:e.path,span:e.span}:{kind:`member`,path:[e.name],field:{name:e.name,spec:{type:qe(e)}},span:t},Nt=(e,t,n)=>({kind:`call`,name:e,args:t,span:n}),Pt=(e,t)=>({kind:`string`,value:e,span:t}),Ft=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},It=(e,t={})=>{let n=e=>It(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:Mt(e.field,e.span),right:Ft(e.value),span:e.span};case`has`:return{kind:`has`,left:Mt(e.field,e.span),right:e.value,span:e.span};case`present`:return{kind:`present`,left:Mt(e.field,e.span),span:e.span};case`in`:return t.expand?{kind:`or`,args:e.values.map(t=>({kind:`compare`,op:`=`,left:Mt(e.field,e.span),right:t,span:e.span})),span:e.span}:Nt(`in`,[Mt(e.field,e.span),...e.values],e.span);case`search`:return Nt(`search`,[Pt(e.text,e.span)],e.span);case`similar`:return Nt(`similar`,[Mt(e.field,e.span),Pt(e.text,e.span)],e.span);case`regex`:return Nt(`regex`,[Mt(e.field,e.span),Pt(e.pattern,e.span)],e.span);case`isNull`:return t.expand?{kind:`not`,arg:{kind:`present`,left:Mt(e.field,e.span),span:e.span},span:e.span}:Nt(`isNull`,[Mt(e.field,e.span)],e.span)}},Lt=(e,t)=>{let n=jt(e,t);if(!n.ok&&n.errors.some(e=>e.code===`unsupported-traversal`))return n;let r=ue(It(t),Je(e));return r.ok?jt(e,t):{ok:!1,errors:r.errors}},Rt=/^[\d\s+\-().\/]+$/,zt=e=>Rt.test(e)?e.replace(/\D/g,``):``,Bt=e=>{let t=e.split(/\s+/).filter(Boolean).map(e=>({text:e,digits:zt(e),whole:!1})),n=t.length>1?zt(e.trim()):``;return n?[{text:e.trim(),digits:n,whole:!0},...t]:t},Vt=(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()),Ht=(e,t,n)=>(e.search??[]).filter(r=>Vt(t[r],n,e.searchMatch?.[r])),Ut=(e,t,n)=>{let r=Bt(n),i=r.filter(e=>!e.whole),a=r.find(e=>e.whole);return a&&Ht(e,t,a).length>0?!0:i.length>0&&i.every(n=>Ht(e,t,n).length>0)},Wt=(e,t,n,r)=>{for(let i of Bt(n)){let n=Ht(e,t,i);if(n.length>0&&!n.some(e=>r.includes(e)))return n[0]}},Gt=e=>()=>{throw Error(`Not implemented: ${e}() needs the database (the resource's search fields, trigram matching), so it cannot be evaluated against a record`)},Kt=(e,t,n)=>({...Ge,search:{...Ge.search,evaluate:n?e=>Ut(n,t,e):Gt(`search`)},similar:{...Ge.similar,evaluate:Gt(`similar`)},regex:{...Ge.regex,evaluate:(e,t)=>e.some(e=>typeof e==`string`&&new RegExp(t).test(e))},now:{...Ge.now,evaluate:e}}),qt=(e,t,n={})=>te(It(e,{expand:!0}),t,{functions:Kt(n.now??(()=>new Date),t,n.search)}),Jt=e=>we(It(e)),Yt=e=>e.map(e=>({path:e.path.path,direction:e.direction,span:e.span})),Xt=e=>e.replace(/([^\s,])(\s+)(asc|desc)(?=\s|,|$)/gi,(e,t,n,r)=>`${t}${n}${r.toLowerCase()}`),Zt=e=>{let t=Se(Xt(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}},Qt=(e,t)=>{let n=t.filter(e=>e.path.path.length>1).map(e=>He(`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=ge(Yt(t),Je(e));return r.ok?{ok:!0,sort:r.items.map(e=>[e.path[0],e.direction])}:{ok:!1,errors:r.errors}},$t=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}}},en={start:0,end:0},tn=e=>({kind:`field`,path:e.split(`.`),span:en}),nn=e=>{if(typeof e==`string`)return{kind:`string`,value:e,span:en};if(typeof e==`boolean`)return{kind:`boolean`,value:e,span:en};if(!Number.isFinite(e))throw Error(`Filter numbers must be finite`);return{kind:`number`,value:e,raw:String(e),span:en}},rn=e=>typeof e==`object`?e:nn(e),an=(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:en}},on=()=>{let e=e=>(t,n)=>({kind:`compare`,op:e,field:tn(t),value:rn(n),span:en}),t=e=>t=>({kind:`now`,offset:{sign:e,duration:$t(t)},span:en});return{eq:e(`=`),ne:e(`!=`),lt:e(`<`),lte:e(`<=`),gt:e(`>`),gte:e(`>=`),between:(t,n,r)=>an(`and`,[e(`>=`)(t,n),e(`<=`)(t,r)]),has:(e,t)=>({kind:`has`,field:tn(e),value:nn(t),span:en}),present:e=>({kind:`present`,field:tn(e),span:en}),in:(e,t)=>({kind:`in`,field:tn(e),values:t.map(nn),span:en}),isNull:e=>({kind:`isNull`,field:tn(e),span:en}),search:e=>({kind:`search`,text:e,span:en}),similar:(e,t)=>({kind:`similar`,field:tn(e),text:t,span:en}),regex:(e,t)=>({kind:`regex`,field:tn(e),pattern:t,span:en}),and:(...e)=>an(`and`,e),or:(...e)=>an(`or`,e),not:e=>({kind:`not`,arg:e,span:en}),now:()=>({kind:`now`,span:en}),ago:t(`-`),fromNow:t(`+`)}},sn=on(),cn=/\{([A-Za-z_][A-Za-z0-9_]*)\}/g,ln=e=>[...e.matchAll(cn)].map(e=>e[1]),un=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??{}):[],dn=e=>[...new Set(un(e).flatMap(ln))],fn=(e,t)=>e.replace(cn,(e,n)=>t[n]===null||t[n]===void 0?``:String(t[n])),pn=(e,t={})=>{if(e.kind===`record`){let n=e=>typeof e==`string`?fn(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,fn(n,t)]))}:e:e.kind===`list`?{...e,...e.filter!==void 0&&{filter:fn(e.filter,t)},...e.orderBy!==void 0&&{orderBy:fn(e.orderBy,t)}}:e},mn=e=>/^\{([A-Za-z_][A-Za-z0-9_]*)\}$/.exec(e)?.[1],hn=e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&Object.keys(e).length===1&&typeof e.$field==`string`,gn=e=>typeof e==`object`&&!!e&&!Array.isArray(e),_n=e=>hn(e)?e.$field:Array.isArray(e)?e.map(_n):gn(e)?Object.fromEntries(Object.entries(e).map(([e,t])=>[e,_n(t)])):e,vn=`table`,yn=/^[a-z0-9][a-z0-9_-]*$/,bn=e=>{if(!e.startsWith(`/-/forms/`))return;let t=e.slice(9);return yn.test(t)?{name:t}:void 0},xn=e=>e.flatMap(e=>e.kind===`group`||e.kind===`tab`?xn(e.items):[e]),Sn=(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}},Cn={text:`text`,integer:`integer`,decimal:`decimal`,boolean:`boolean`,date:`date`,choice:`text`,custom:`json`},wn=e=>({name:e.name,column:e.name,type:e.options?`enum`:Cn[e.kind],nullable:!0,readOnly:!1,filterable:e.kind!==`custom`,sortable:!1,aliases:[],...e.options&&{enumValues:e.options.map(e=>e.value)}}),Tn=e=>({name:`inputs`,table:{name:`inputs`},fields:Object.fromEntries(e.map(e=>[e.name,wn(e)])),primaryKey:[]}),En=(e,t)=>{let n=e[t].when;if(n===void 0)return;let r=rt(n);if(!r.ok)return r.errors.map(e=>e.message).join(`; `);if(!r.ast)return`it is empty`;let i=Lt(Tn(e.slice(0,t)),r.ast);return i.ok?i.filter:i.errors.map(e=>e.message).join(`; `)},Dn=(e,t)=>{let n=new Set,r={};return e.forEach((i,a)=>{let o=En(e,a);if(typeof o==`string`)throw Error(`Input "${i.name}": ${o}`);let s=o===void 0||qt(o,r)===!0;s&&n.add(i.name),r[i.name]=s?t[i.name]??null:null}),n},On=(e,t)=>Object.fromEntries(Object.entries(e).flatMap(([e,n])=>{let r=typeof n==`string`?mn(n):void 0;return r===void 0?[[e,n]]:Object.hasOwn(t,r)?[[e,t[r]]]:[]})),kn=e=>`groupBy`in e,An=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(`,`)},jn=e(Ee(),1),Mn=e=>{try{return new jn.default.Comparator(e),!0}catch(e){if(e instanceof TypeError)return!1;throw e}},Nn=(e,t)=>{let n=t.trim().split(/\s+/);if(jn.default.valid(e)!==null&&t.trim()!==``&&n.every(Mn))return jn.default.satisfies(e,t)},Pn=(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=Nn(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}`},Fn=`[Filtered]`,In=/authorization|cookie|passw|secret|token|api[-_]?key|credential|session|csrf|signature|^sig$/i,Ln=new Set([`url`,`query_string`,`from`,`to`]),Rn=12,zn=e=>e.replace(/(^|&)([^=&]*)=([^&]*)/g,(e,t,n)=>In.test(n)?`${t}${n}=${Fn}`:e),Bn=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)}${zn(r)}${n===-1?``:e.slice(n)}`},Vn=(e,t,n)=>In.test(e)?Fn:typeof t==`string`&&Ln.has(e)?e===`query_string`?zn(t):Bn(t):Hn(t,n+1),Hn=(e,t)=>t>Rn||typeof e!=`object`||!e?e:Array.isArray(e)?e.map(e=>Array.isArray(e)&&e.length===2&&typeof e[0]==`string`?[e[0],Vn(e[0],e[1],t)]:Hn(e,t+1)):Object.fromEntries(Object.entries(e).map(([e,n])=>[e,Vn(e,n,t)])),Un=e=>Hn(e,0),Wn=[`unknown-field`,`not-filterable`,`not-sortable`,`unsupported-traversal`,`invalid-traversal`],Gn=e=>e.replace(/(["']?)\{[A-Za-z_][A-Za-z0-9_]*\}\1/g,(e,t)=>t?`${t}x${t}`:`0`),Kn=(e,t)=>{let n=rt(Gn(t));if(!n.ok)return n.errors.map(e=>`filter: ${e.message}`);if(!n.ast)return[];let r=Lt(e,n.ast);return r.ok?[]:r.errors.filter(e=>Wn.includes(e.code)).map(e=>`filter: ${e.message}`)},qn=(e,t)=>{if(dn({kind:`list`,resource:e.name,orderBy:t}).length>0)return[];let n=Zt(t);if(!n.ok)return n.errors.map(e=>`orderBy: ${e.message}`);let r=Qt(e,n.items);return r.ok?[]:r.errors.map(e=>`orderBy: ${e.message}`)},Jn=(e,{models:t,pages:n,source:r,createPages:i})=>{let a=dn(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?Kn(n,e.filter):[],...e.orderBy?qn(n,e.orderBy):[]]:a:[`unknown resource "${e.resource}"`]}default:return[`an address's kind is list, record, create or page, not "${String(e.kind)}"`]}},Yn={messages:[],replying:!1},Xn=(e,t)=>{let n=e.findIndex(e=>e.id===t.id);return n===-1?[...e,t]:e.map((e,r)=>r===n?t:e)},Zn=(e,t,n)=>{let r=e.find(e=>e.id===t);return Xn(e,r?{...r,parts:Xn(r.parts,n)}:{id:t,from:`assistant`,parts:[n]})},Qn=(e,t)=>{switch(t.type){case`state`:return t.state;case`message`:return{...e,messages:Xn(e.messages,t.message)};case`part`:return{...e,messages:Zn(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}}}}},$n=async(e,t,n)=>{let r=new TextDecoder,i=e.getReader();n?.addEventListener(`abort`,()=>void i.cancel(),{once:!0});let a=``,o=[],s=e=>{if(e===``){o.length>0&&t(o.join(`
|
|
3
|
-
`)),o=[];return}e.startsWith(`data:`)&&o.push(e.slice(e.startsWith(`data: `)?6:5))};for(;;){let{done:e,value:t}=await i.read();a+=e?r.decode():r.decode(t,{stream:!0});let n=a.split(/\r\n|\r|\n/);if(a=e?``:n.pop()??``,n.forEach(s),e)return s(``)}},er=e=>e.charAt(0).toUpperCase()+e.slice(1),F=e=>er(e.replace(/(Id|Code|_id|_code)$/,``).replace(/([a-z0-9])([A-Z])/g,`$1 $2`).replace(/_+/g,` `).trim().toLowerCase()||e),tr=(e,t)=>t?.[e]??e,nr=[`name`,`title`,`number`,`sku`,`email`,`code`,`description`],rr=e=>e?.type===`text`&&!e.sensitive,ir=(e,t)=>t?.title??nr.find(t=>rr(e.fields[t]))??Object.values(e.fields).find(rr)?.name??e.primaryKey[0],ar=(e,t)=>t?.title??t?.list?.columns.find(t=>e.fields[t]?.type===`text`)??ir(e),or=(e,t,n,r)=>{let i=ar(e,t),a=n[i];return a==null?r:e.fields[i]?.type===`enum`?tr(String(a),t?.fields[i]?.valueLabels):String(a)},sr=`/api/auth`,cr={ios:`capacitor://localhost`,android:`https://localhost`},lr={database:`protobase-push`,store:`registration`,key:`current`},ur=`protobase.sw.js`,dr=(e,t)=>`${e}/notifications/devices${t===void 0?``:`/${encodeURIComponent(t)}`}`,fr=/^[A-Za-z0-9_-]{1,64}$/,pr=(e,t)=>{let n=`${e}/notifications/history`;if(t===void 0)return n;if(typeof t==`string`)return`${n}/${t}`;if(!fr.test(t.read))throw Error(`A history entry id is letters, digits, "_" and "-" only`);return`${n}/${t.read}/read`},mr=(e,t)=>t?.list?.columns??Object.values(e.fields).filter(e=>!e.writeOnly).slice(0,6).map(e=>e.name),hr={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`}]]};hr.node;var gr=N(hr),_r={name:`arrow-down`,size:24,node:[[`path`,{d:`M12 5v14`,key:`s699le`}],[`path`,{d:`m19 12-7 7-7-7`,key:`1idqje`}]]};_r.node;var vr=N(_r),yr={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`}]]};yr.node;var br=N(yr),xr={name:`arrow-right`,size:24,node:[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`m12 5 7 7-7 7`,key:`xquz4c`}]]};xr.node;var Sr=N(xr),Cr={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`}]]};Cr.node;var wr=N(Cr),Tr={name:`arrow-up-right`,size:24,node:[[`path`,{d:`M7 7h10v10`,key:`1tivn9`}],[`path`,{d:`M7 17 17 7`,key:`1vkiza`}]]};Tr.node;var Er=N(Tr),Dr={name:`arrow-up`,size:24,node:[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]};Dr.node;var Or=N(Dr),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 Ar=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 Mr=N(jr),Nr={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`}]]};Nr.node;var Pr=N(Nr),Fr={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`}]]};Fr.node;var Ir=N(Fr),Lr={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`}]]};Lr.node;var Rr=N(Lr),zr={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`}]]};zr.node;var Br=N(zr),Vr={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`}]]};Vr.node;var Hr=N(Vr),Ur={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`}]]};Ur.node;var Wr=N(Ur),Gr={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`}]]};Gr.node;var Kr=N(Gr),qr={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`}]]};qr.node;var Jr=N(qr),Yr={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`}]]};Yr.node;var Xr=N(Yr),Zr={name:`boxes`,size:24,node:[[`path`,{d:`M2.97 12.92A2 2 0 0 0 2 14.63v3.24a2 2 0 0 0 .97 1.71l3 1.8a2 2 0 0 0 2.06 0L12 19v-5.5l-5-3-4.03 2.42Z`,key:`lc1i9w`}],[`path`,{d:`m7 16.5-4.74-2.85`,key:`1o9zyk`}],[`path`,{d:`m7 16.5 5-3`,key:`va8pkn`}],[`path`,{d:`M7 16.5v5.17`,key:`jnp8gn`}],[`path`,{d:`M12 13.5V19l3.97 2.38a2 2 0 0 0 2.06 0l3-1.8a2 2 0 0 0 .97-1.71v-3.24a2 2 0 0 0-.97-1.71L17 10.5l-5 3Z`,key:`8zsnat`}],[`path`,{d:`m17 16.5-5-3`,key:`8arw3v`}],[`path`,{d:`m17 16.5 4.74-2.85`,key:`8rfmw`}],[`path`,{d:`M17 16.5v5.17`,key:`k6z78m`}],[`path`,{d:`M7.97 4.42A2 2 0 0 0 7 6.13v4.37l5 3 5-3V6.13a2 2 0 0 0-.97-1.71l-3-1.8a2 2 0 0 0-2.06 0l-3 1.8Z`,key:`1xygjf`}],[`path`,{d:`M12 8 7.26 5.15`,key:`1vbdud`}],[`path`,{d:`m12 8 4.74-2.85`,key:`3rx089`}],[`path`,{d:`M12 13.5V8`,key:`1io7kd`}]]};Zr.node;var Qr=N(Zr),$r={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`]};$r.node;var ei=N($r),ti={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`}]]};ti.node;var ni=N(ti),ri={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`}]]};ri.node;var ii=N(ri),ai={name:`chart-column`,size:24,node:[[`path`,{d:`M3 3v16a2 2 0 0 0 2 2h16`,key:`c24i48`}],[`path`,{d:`M18 17V9`,key:`2bz60n`}],[`path`,{d:`M13 17V5`,key:`1frdt8`}],[`path`,{d:`M8 17v-3`,key:`17ska0`}]],aliases:[`bar-chart-3`]};ai.node;var oi=N(ai),si={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`}]]};si.node;var ci=N(si),li={name:`check`,size:24,node:[[`path`,{d:`M20 6 9 17l-5-5`,key:`1gmf2c`}]]};li.node;var ui=N(li),di={name:`chevron-down`,size:24,node:[[`path`,{d:`m6 9 6 6 6-6`,key:`qrunsl`}]]};di.node;var fi=N(di),pi={name:`chevron-left`,size:24,node:[[`path`,{d:`m15 18-6-6 6-6`,key:`1wnfg3`}]]};pi.node;var mi=N(pi),hi={name:`chevron-right`,size:24,node:[[`path`,{d:`m9 18 6-6-6-6`,key:`mthhwq`}]]};hi.node;var gi=N(hi),_i={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`}]]};_i.node;var vi=N(_i),yi={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`]};yi.node;var bi=N(yi),xi={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`]};xi.node;var Si=N(xi),Ci={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`}]]};Ci.node;var wi=N(Ci),Ti={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`]};Ti.node;var Ei=N(Ti),Di={name:`circle`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]};Di.node;var Oi=N(Di),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 Ai=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 Mi=N(ji),Ni={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`}]]};Ni.node;var Pi=N(Ni),Fi={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`}]]};Fi.node;var Ii=N(Fi),Li={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`}]]};Li.node;var Ri=N(Li),zi={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`}]]};zi.node;var Bi=N(zi),Vi={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`]};Vi.node;var Hi=N(Vi),Ui={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`]};Ui.node;var Wi=N(Ui),Gi={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`]};Gi.node;var Ki=N(Gi),qi={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`}]]};qi.node;var Ji=N(qi),Yi={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`}]]};Yi.node;var Xi=N(Yi),Zi={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`}]]};Zi.node;var Qi=N(Zi),$i={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`]};$i.node;var ea=N($i),ta={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`}]]};ta.node;var na=N(ta),ra={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`}]]};ra.node;var ia=N(ra),aa={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`}]]};aa.node;var oa=N(aa),sa={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`}]]};sa.node;var ca=N(sa),la={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`}]]};la.node;var ua=N(la),da={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`]};da.node;var fa=N(da),pa={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`}]]};pa.node;var ma=N(pa),ha={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`}]]};ha.node;var ga=N(ha),_a={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`}]]};_a.node;var va=N(_a),ya={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`}]]};ya.node;var ba=N(ya),xa={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`}]]};xa.node;var Sa=N(xa),Ca={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`}]]};Ca.node;var wa=N(Ca),Ta={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`}]]};Ta.node;var Ea=N(Ta),Da={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`}]]};Da.node;var Oa=N(Da),ka={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`}]]};ka.node;var Aa=N(ka),ja={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`}]]};ja.node;var Ma=N(ja),Na={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`}]]};Na.node;var Pa=N(Na),Fa={name:`loader-circle`,size:24,node:[[`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`,key:`13zald`}]],aliases:[`loader-2`]};Fa.node;var Ia=N(Fa),La={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`}]]};La.node;var Ra=N(La),za={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`}]]};za.node;var Ba=N(za),Va={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`}]]};Va.node;var Ha=N(Va),Ua={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`}]]};Ua.node;var Wa=N(Ua),Ga={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`}]]};Ga.node;var Ka=N(Ga),qa={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`}]]};qa.node;var Ja=N(qa),Ya={name:`menu`,size:24,node:[[`path`,{d:`M4 5h16`,key:`1tepv9`}],[`path`,{d:`M4 12h16`,key:`1lakjw`}],[`path`,{d:`M4 19h16`,key:`1djgab`}]]};Ya.node;var Xa=N(Ya),Za={name:`minus`,size:24,node:[[`path`,{d:`M5 12h14`,key:`1ays0h`}]]};Za.node;var Qa=N(Za),$a={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`}]]};$a.node;var eo=N($a),to={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`}]]};to.node;var no=N(to),ro={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`}]]};ro.node;var io=N(ro),ao={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`}]]};ao.node;var oo=N(ao),so={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`}]]};so.node;var co=N(so),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 uo=N(lo),fo={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`}]]};fo.node;var po=N(fo),mo={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`}]]};mo.node;var ho=N(mo),go={name:`plus`,size:24,node:[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`M12 5v14`,key:`s699le`}]]};go.node;var _o=N(go),vo={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`}]]};vo.node;var yo=N(vo),bo={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`}]]};bo.node;var xo=N(bo),So={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`}]]};So.node;var Co=N(So),wo={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`}]]};wo.node;var To=N(wo),Eo={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`}]]};Eo.node;var Do=N(Eo),Oo={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`}]]};Oo.node;var ko=N(Oo),Ao={name:`search`,size:24,node:[[`path`,{d:`m21 21-4.34-4.34`,key:`14j7rj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}]]};Ao.node;var jo=N(Ao),Mo={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`]};Mo.node;var No=N(Mo),Po={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`}]]};Po.node;var Fo=N(Po),Io={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`}]]};Io.node;var Lo=N(Io),Ro={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`}]]};Ro.node;var zo=N(Ro),Bo={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`}]]};Bo.node;var Vo=N(Bo),Ho={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`}]]};Ho.node;var Uo=N(Ho),Wo={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`}]]};Wo.node;var Go=N(Wo),Ko={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`}]]};Ko.node;var qo=N(Ko),Jo={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`}]]};Jo.node;var Yo=N(Jo),Xo={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`]};Xo.node;var Zo=N(Xo),Qo={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`]};Qo.node;var $o=N(Qo),es={name:`square`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]};es.node;var ts=N(es),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 rs=N(ns),is={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`}]]};is.node;var as=N(is),os={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`}]]};os.node;var ss=N(os),cs={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`}]]};cs.node;var ls=N(cs),us={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`}]]};us.node;var ds=N(us),fs={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`}]]};fs.node;var ps=N(fs),ms={name:`terminal`,size:24,node:[[`path`,{d:`M12 19h8`,key:`baeox8`}],[`path`,{d:`m4 17 6-6-6-6`,key:`1yngyt`}]]};ms.node;var hs=N(ms),gs={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`]};gs.node;var _s=N(gs),vs={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`]};vs.node;var ys=N(vs),bs={name:`truck`,size:24,node:[[`path`,{d:`M14 18V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v11a1 1 0 0 0 1 1h2`,key:`wrbu53`}],[`path`,{d:`M15 18H9`,key:`1lyqi6`}],[`path`,{d:`M19 18h2a1 1 0 0 0 1-1v-3.65a1 1 0 0 0-.22-.624l-3.48-4.35A1 1 0 0 0 17.52 8H14`,key:`lysw3i`}],[`circle`,{cx:`17`,cy:`18`,r:`2`,key:`332jqn`}],[`circle`,{cx:`7`,cy:`18`,r:`2`,key:`19iecd`}]]};bs.node;var xs=N(bs),Ss={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`}]]};Ss.node;var Cs=N(Ss),ws={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`]};ws.node;var Ts=N(ws),Es={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`]};Es.node;var Ds=N(Es),Os={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`}]]};Os.node;var ks=N(Os),As={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`}]]};As.node;var js=N(As),Ms={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`}]]};Ms.node;var Ns=N(Ms),Ps={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`}]]};Ps.node;var Fs=N(Ps),Is={name:`x`,size:24,node:[[`path`,{d:`M18 6 6 18`,key:`1bl5f8`}],[`path`,{d:`m6 6 12 12`,key:`d8bk6v`}]]};Is.node;var Ls=N(Is),Rs={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`}]]};Rs.node;var zs=N(Rs),I=e(t(),1),Bs=e(n(),1),L=M({en:{account:`Account`,noAccount:`No account page`,noAccountDescription:`This app has no account page for you.`,signInPolicy:`Sign-in policy`,couldNotReadMethods:`Could not read your sign-in methods`,couldNotReadProfile:`Could not read your profile`,profile:`Profile`,profileDescription:`Your name as others see it in this app, and the address you sign in with.`,email:`Email`,changeName:`Change name`,changeNameDescription:`The name others see on your comments, changes and invitations.`,changeEmail:`Change email`,changeEmailDescription:`We email a code to the new address. Once you enter it here, you sign in with that address.`,newEmail:`New email`,sendCode:`Send code`,codeSentTo:e=>`Enter the 6-digit code we emailed to ${e}. It works for 5 minutes. No code comes when another account has the address.`,code:`Code`,otherAddress:`Use another address`,theProvider:`the provider`,loading:`Loading`,backupCodes:`Backup codes`,copied:`Copied`,copy:`Copy`,download:`Download`,cancel:`Cancel`,save:`Save`,name:`Name`,yourPassword:`Your password`,passwordIsSet:`Sign in with your email address and this password. Changing it asks for the current one.`,passwordNotSet:`You sign in without a password now. Set one to sign in with your email address and a password too; you stay signed in everywhere.`,passwordForbidden:`Your admin turned passwords off for this app, so they cannot be used to sign in.`,passwordStaff:`Staff signed in as someone cannot change their password.`,passwordSaved:`Your password is saved.`,changePassword:`Change password`,setPassword:`Set a password`,currentPassword:`Current password`,newPassword:`New password`,repeatPassword:`Repeat new password`,atLeast:e=>`At least ${e} characters.`,useAtLeast:e=>`Use at least ${e} characters.`,passwordTooLong:`That password is too long.`,passwordsDiffer:`The passwords are not the same.`,continue:`Continue`,on:`On`,off:`Off`,optional:`Optional`,required:`Required`,passkeys:`Passkeys`,passkey:`Passkey`,passkeysAllowed:`Sign in with Face ID, Touch ID, Windows Hello, your phone or a security key instead of a password.`,passkeysRequired:`This app requires a passkey for every account. Sign in with Face ID, Touch ID, Windows Hello, your phone or a security key.`,passkeysForbidden:`Your admin turned passkeys off for this app, so they cannot be used to sign in.`,addedOn:e=>`Added ${e}`,addedEarlier:`Added earlier`,synced:`Synced across your devices`,oneDevice:`On one device`,rename:`Rename`,remove:`Remove`,keepLastPasskey:`Passkeys are required: add another one before removing this one.`,addPasskey:`Add a passkey`,renamePasskey:`Rename passkey`,renamePasskeyDescription:`A name that tells you where this passkey lives, such as the device or password manager.`,removePasskey:`Remove passkey?`,removePasskeyDescription:e=>`${e} will no longer sign you in here. It stays on the device until you delete it there.`,thisPasskey:`This passkey`,connectedAccounts:`Connected accounts`,connectedAccountsDescription:`Sign in with these instead of your password. Connecting one asks you to sign in there; its address may differ from yours here.`,connected:`Connected`,connect:e=>`Connect ${e}`,stopped:e=>`Stopped ${e}`,ended:e=>`Ended ${e}`,signedInUntil:e=>`Signed in until ${e}`,devices:`Devices`,devicesDescription:`The browsers and apps signed in to your account. To sign out this one, use Sign out in the menu.`,couldNotReadDevices:`Could not read your devices`,noDevices:`No device is signed in.`,thisDevice:`This device`,browserOn:(e,t)=>`${e} on ${t}`,aBrowserOn:e=>`A browser on ${e}`,unknownDevice:`Unknown device`,staffOf:e=>`${e} staff`,staff:`Staff`,signedInFromUntil:(e,t)=>`Signed in ${e}, until ${t}`,signOut:`Sign out`,signOutDevice:e=>`Sign out ${e}?`,signOutDeviceDescription:`It has to sign in again to use your account.`,signOutOthers:`Sign out of all other devices`,signOutOthersTitle:`Sign out of all other devices?`,signOutOthersDescription:`Every other browser and app signed in to your account has to sign in again. This device stays signed in.`,staffSignIns:`Staff sign-ins`,staffSignInsDescription:e=>`Each time staff of ${e} signed in as someone here, newest first.`,noStaffSignIns:`No staff has signed in as anyone yet.`,as:`as`,qrCode:`QR code for your authenticator app`,twoFactor:`Two-factor authentication`,twoFactorAllowed:`Ask for a second step after your password or an emailed sign-in code: a code from an authenticator app, or one emailed to you. A passkey needs no second step.`,twoFactorRequired:`This app requires two-factor authentication for every account. Turn it on to keep using the app.`,twoFactorForbidden:`Your admin turned two-factor authentication off for this app.`,twoFactorOnWithApp:`Signing in with a password or an emailed sign-in code also asks for a code from your authenticator app. Backup codes work when you do not have the app.`,twoFactorOnWithAppOrMail:`Signing in with a password or an emailed sign-in code also asks for a code from your authenticator app, or one emailed to you. Backup codes work when you do not have the app.`,twoFactorOnWithMail:`Signing in with a password or an emailed sign-in code also asks for a code emailed to you.`,turnOn:`Turn on`,turnOff:`Turn off`,addAuthenticator:`Add an authenticator app`,newBackupCodes:`New backup codes`,twoFactorIsRequired:`This app requires two-factor authentication.`,turnOffTitle:`Turn off two-factor authentication?`,turnOffDescription:`Signing in then needs only your password or an emailed code. Your backup codes stop working.`,newCodesTitle:`Make new backup codes?`,newCodesDescription:`Your current backup codes stop working, and you get ten new ones.`,makeNewCodes:`Make new codes`,yourNewCodes:`Your new backup codes`,keepCodesSafe:`Keep them somewhere safe: each one signs you in once if you lose your phone. They are not shown again.`,savedCodes:`I saved my backup codes`,authenticatorApp:`Authenticator app`,authenticatorAppDescription:`A code from an app such as Google Authenticator, Microsoft Authenticator or 1Password. Comes with backup codes.`,emailedCode:`Emailed code`,emailedCodeDescription:`A code mailed to your address each time you sign in with a password or an emailed sign-in code.`,twoFactorIsOn:`Two-factor authentication is on. Keep these backup codes somewhere safe: each one signs you in once if you lose your phone. They are not shown again.`,scanCode:`Scan this code with your authenticator app, then enter the 6-digit code it shows.`,cannotScan:`Can't scan it? Enter this key in the app:`,codeFromApp:`Code from the app`,secondStep:`Second step`,password:`Password`,passwordDescription:`Sign in with the email address and a password.`,emailedSignInCode:`Emailed sign-in code`,emailedSignInCodeDescription:`Sign in with a one-time code mailed to the account's address.`,passkeysPolicyDescription:`Sign in with Face ID, Touch ID, Windows Hello, a phone or a security key. Required: everyone adds one after signing in.`,twoFactorPolicyDescription:`A code from an authenticator app, or an emailed one, after a password or an emailed sign-in code. Required: everyone turns it on after signing in.`,staffAccess:`Staff sign-in as a person`,staffAccessDescription:`The team that runs this app signs in as someone to help them, with a reason, for a short session. Each time is in the log below; with "Email the person" they are told too.`,emailThePerson:`Email the person`,platformSignIn:`Sign-in through the platform`,platformSignInDescription:`The sign-in provider the platform that runs this app adds, for people who have an account here already. It never creates accounts.`,platformSignInWith:e=>`Sign in with ${e} through the platform`,codeNeedsMail:`Needs mail settings (PROTOBASE_SMTP_URL and PROTOBASE_MAIL_FROM): off until they are set.`,passwordStaysOn:`Without mail settings, password sign-in stays on so nobody is locked out.`,staffNeedsMail:`Needs mail settings (PROTOBASE_SMTP_URL and PROTOBASE_MAIL_FROM): staff cannot sign in until they are set.`,platformOff:`Off while passkeys or two-factor authentication are required: it skips the second step.`,appliesAs:e=>`Applies as ${e} for now.`,lastSaved:e=>`Last saved on ${e}.`,lastSavedBy:(e,t)=>`Last saved by ${e} on ${t}.`,neverChanged:`Never changed: this is the app's default.`,reset:`Reset`,couldNotReadStaffSignIns:`Could not read the staff sign-ins`,couldNotReadPolicy:`Could not read the sign-in policy`,policySaved:`Saved. It applies to every sign-in from now on.`,policySubtitle:`How people sign in to this app. Signed-in people keep their session, and are asked for what is newly required within 15 minutes.`,mcpAddress:`MCP address`,mcpAddressDescription:`Add this address to an AI assistant or code editor that speaks MCP, as a custom connector or remote MCP server. It opens this app in your browser, where you sign in and allow it; it then works with your access.`,copyMcpAddress:`Copy the MCP address`,addToClaude:`Add to Claude`,deleteAccount:`Delete account`,deleteAccountDescription:`Delete your account and sign out everywhere. You can no longer sign in with it, and this cannot be undone.`,deleteAccountStaff:`Staff signed in as someone cannot delete their account.`,deleteAccountQuestion:`Delete your account?`,deleteAccountWarning:`Your account, its sign-in methods and every device signed in to it are deleted. This cannot be undone.`,deleteAccountPassword:`Enter your password to confirm.`,deleteAccountConfirm:`Delete my account`,deleteAccountLastAdmin:`You are the last admin of this app. Make someone else an admin first.`,deleteAccountLocked:`This account is locked, so it cannot be deleted.`},nl:{account:`Account`,noAccount:`Geen accountpagina`,noAccountDescription:`Deze app heeft geen accountpagina voor je.`,signInPolicy:`Inlogbeleid`,couldNotReadMethods:`Kon je inlogmethoden niet lezen`,couldNotReadProfile:`Kon je profiel niet lezen`,profile:`Profiel`,profileDescription:`Je naam zoals anderen die in deze app zien, en het adres waarmee je inlogt.`,email:`E-mail`,changeName:`Naam wijzigen`,changeNameDescription:`De naam die anderen zien bij je opmerkingen, wijzigingen en uitnodigingen.`,changeEmail:`E-mailadres wijzigen`,changeEmailDescription:`We mailen een code naar het nieuwe adres. Zodra je die hier invult, log je in met dat adres.`,newEmail:`Nieuw e-mailadres`,sendCode:`Code versturen`,codeSentTo:e=>`Vul de code van 6 cijfers in die we naar ${e} mailden. Die werkt 5 minuten. Heeft een ander account het adres, dan komt er geen code.`,code:`Code`,otherAddress:`Ander adres gebruiken`,theProvider:`de provider`,loading:`Laden`,backupCodes:`Back-upcodes`,copied:`Gekopieerd`,copy:`Kopiëren`,download:`Downloaden`,cancel:`Annuleren`,save:`Bewaren`,name:`Naam`,yourPassword:`Je wachtwoord`,passwordIsSet:`Log in met je e-mailadres en dit wachtwoord. Wijzigen vraagt het huidige.`,passwordNotSet:`Je logt nu in zonder wachtwoord. Stel er een in om ook met je e-mailadres en een wachtwoord in te loggen; je blijft overal ingelogd.`,passwordForbidden:`Je beheerder heeft wachtwoorden uitgezet voor deze app, dus je kunt er niet mee inloggen.`,passwordStaff:`Een medewerker die als iemand anders is ingelogd, kan diens wachtwoord niet wijzigen.`,passwordSaved:`Je wachtwoord is bewaard.`,changePassword:`Wachtwoord wijzigen`,setPassword:`Wachtwoord instellen`,currentPassword:`Huidig wachtwoord`,newPassword:`Nieuw wachtwoord`,repeatPassword:`Nieuw wachtwoord herhalen`,atLeast:e=>`Minstens ${e} tekens.`,useAtLeast:e=>`Gebruik minstens ${e} tekens.`,passwordTooLong:`Dat wachtwoord is te lang.`,passwordsDiffer:`De wachtwoorden zijn niet hetzelfde.`,continue:`Doorgaan`,on:`Aan`,off:`Uit`,optional:`Optioneel`,required:`Verplicht`,passkeys:`Passkeys`,passkey:`Passkey`,passkeysAllowed:`Log in met Face ID, Touch ID, Windows Hello, je telefoon of een beveiligingssleutel in plaats van een wachtwoord.`,passkeysRequired:`Deze app vraagt een passkey voor elk account. Log in met Face ID, Touch ID, Windows Hello, je telefoon of een beveiligingssleutel.`,passkeysForbidden:`Je beheerder heeft passkeys uitgezet voor deze app, dus je kunt er niet mee inloggen.`,addedOn:e=>`Toegevoegd ${e}`,addedEarlier:`Eerder toegevoegd`,synced:`Gesynchroniseerd op je apparaten`,oneDevice:`Op één apparaat`,rename:`Naam wijzigen`,remove:`Verwijderen`,keepLastPasskey:`Passkeys zijn verplicht: voeg er nog een toe voordat je deze verwijdert.`,addPasskey:`Passkey toevoegen`,renamePasskey:`Naam van passkey wijzigen`,renamePasskeyDescription:`Een naam die zegt waar deze passkey staat, zoals het apparaat of de wachtwoordbeheerder.`,removePasskey:`Passkey verwijderen?`,removePasskeyDescription:e=>`Met ${e} log je hier niet meer in. Die blijft op het apparaat tot je die daar verwijdert.`,thisPasskey:`deze passkey`,connectedAccounts:`Gekoppelde accounts`,connectedAccountsDescription:`Log hiermee in in plaats van met je wachtwoord. Koppelen vraagt je daar in te loggen; het adres daar kan anders zijn dan hier.`,connected:`Gekoppeld`,connect:e=>`${e} koppelen`,stopped:e=>`Gestopt ${e}`,ended:e=>`Afgelopen ${e}`,signedInUntil:e=>`Ingelogd tot ${e}`,devices:`Apparaten`,devicesDescription:`De browsers en apps die op je account zijn ingelogd. Log hier uit met Uitloggen in het menu.`,couldNotReadDevices:`Kon je apparaten niet lezen`,noDevices:`Er is geen apparaat ingelogd.`,thisDevice:`Dit apparaat`,browserOn:(e,t)=>`${e} op ${t}`,aBrowserOn:e=>`Een browser op ${e}`,unknownDevice:`Onbekend apparaat`,staffOf:e=>`Medewerker van ${e}`,staff:`Medewerker`,signedInFromUntil:(e,t)=>`Ingelogd ${e}, tot ${t}`,signOut:`Uitloggen`,signOutDevice:e=>`${e} uitloggen?`,signOutDeviceDescription:`Dat moet opnieuw inloggen om je account te gebruiken.`,signOutOthers:`Uitloggen op alle andere apparaten`,signOutOthersTitle:`Uitloggen op alle andere apparaten?`,signOutOthersDescription:`Elke andere browser en app die op je account is ingelogd, moet opnieuw inloggen. Dit apparaat blijft ingelogd.`,staffSignIns:`Inlogs van medewerkers`,staffSignInsDescription:e=>`Elke keer dat een medewerker van ${e} hier als iemand anders inlogde, nieuwste eerst.`,noStaffSignIns:`Nog geen medewerker heeft als iemand anders ingelogd.`,as:`als`,qrCode:`QR-code voor je authenticator-app`,twoFactor:`Tweestapsverificatie`,twoFactorAllowed:`Vraag een tweede stap na je wachtwoord of een gemailde inlogcode: een code uit een authenticator-app, of een die je gemaild krijgt. Een passkey heeft geen tweede stap nodig.`,twoFactorRequired:`Deze app vraagt tweestapsverificatie voor elk account. Zet het aan om de app te blijven gebruiken.`,twoFactorForbidden:`Je beheerder heeft tweestapsverificatie uitgezet voor deze app.`,twoFactorOnWithApp:`Inloggen met een wachtwoord of een gemailde inlogcode vraagt ook een code uit je authenticator-app. Back-upcodes werken als je de app niet bij de hand hebt.`,twoFactorOnWithAppOrMail:`Inloggen met een wachtwoord of een gemailde inlogcode vraagt ook een code uit je authenticator-app, of een die je gemaild krijgt. Back-upcodes werken als je de app niet bij de hand hebt.`,twoFactorOnWithMail:`Inloggen met een wachtwoord of een gemailde inlogcode vraagt ook een code die je gemaild krijgt.`,turnOn:`Aanzetten`,turnOff:`Uitzetten`,addAuthenticator:`Authenticator-app toevoegen`,newBackupCodes:`Nieuwe back-upcodes`,twoFactorIsRequired:`Deze app vraagt tweestapsverificatie.`,turnOffTitle:`Tweestapsverificatie uitzetten?`,turnOffDescription:`Inloggen vraagt dan alleen je wachtwoord of een gemailde code. Je back-upcodes werken niet meer.`,newCodesTitle:`Nieuwe back-upcodes maken?`,newCodesDescription:`Je huidige back-upcodes werken niet meer, en je krijgt tien nieuwe.`,makeNewCodes:`Nieuwe codes maken`,yourNewCodes:`Je nieuwe back-upcodes`,keepCodesSafe:`Bewaar ze op een veilige plek: met elke code log je één keer in als je je telefoon kwijt bent. Ze worden niet opnieuw getoond.`,savedCodes:`Ik heb mijn back-upcodes bewaard`,authenticatorApp:`Authenticator-app`,authenticatorAppDescription:`Een code uit een app zoals Google Authenticator, Microsoft Authenticator of 1Password. Met back-upcodes.`,emailedCode:`Gemailde code`,emailedCodeDescription:`Een code naar je adres, elke keer dat je inlogt met een wachtwoord of een gemailde inlogcode.`,twoFactorIsOn:`Tweestapsverificatie staat aan. Bewaar deze back-upcodes op een veilige plek: met elke code log je één keer in als je je telefoon kwijt bent. Ze worden niet opnieuw getoond.`,scanCode:`Scan deze code met je authenticator-app en vul daarna de code van 6 cijfers in die de app toont.`,cannotScan:`Lukt scannen niet? Vul deze sleutel in de app in:`,codeFromApp:`Code uit de app`,secondStep:`Tweede stap`,password:`Wachtwoord`,passwordDescription:`Inloggen met het e-mailadres en een wachtwoord.`,emailedSignInCode:`Gemailde inlogcode`,emailedSignInCodeDescription:`Inloggen met een eenmalige code naar het adres van het account.`,passkeysPolicyDescription:`Inloggen met Face ID, Touch ID, Windows Hello, een telefoon of een beveiligingssleutel. Verplicht: iedereen voegt er een toe na het inloggen.`,twoFactorPolicyDescription:`Een code uit een authenticator-app, of een gemailde, na een wachtwoord of een gemailde inlogcode. Verplicht: iedereen zet het aan na het inloggen.`,staffAccess:`Medewerker logt in als iemand anders`,staffAccessDescription:`Het team dat deze app beheert, logt in als iemand om die te helpen, met een reden, voor een korte sessie. Elke keer staat in het logboek hieronder; met "De persoon mailen" krijgt die het ook te horen.`,emailThePerson:`De persoon mailen`,platformSignIn:`Inloggen via het platform`,platformSignInDescription:`De inlogprovider die het platform van deze app toevoegt, voor mensen die hier al een account hebben. Die maakt nooit accounts.`,platformSignInWith:e=>`Inloggen met ${e} via het platform`,codeNeedsMail:`Vraagt mailinstellingen (PROTOBASE_SMTP_URL en PROTOBASE_MAIL_FROM): uit tot die zijn ingesteld.`,passwordStaysOn:`Zonder mailinstellingen blijft inloggen met een wachtwoord aan, zodat niemand wordt buitengesloten.`,staffNeedsMail:`Vraagt mailinstellingen (PROTOBASE_SMTP_URL en PROTOBASE_MAIL_FROM): medewerkers kunnen niet inloggen tot die zijn ingesteld.`,platformOff:`Uit zolang passkeys of tweestapsverificatie verplicht zijn: het slaat de tweede stap over.`,appliesAs:e=>`Geldt voorlopig als ${e}.`,lastSaved:e=>`Laatst bewaard op ${e}.`,lastSavedBy:(e,t)=>`Laatst bewaard door ${e} op ${t}.`,neverChanged:`Nooit gewijzigd: dit is de standaard van de app.`,reset:`Terugzetten`,couldNotReadStaffSignIns:`Kon de inlogs van medewerkers niet lezen`,couldNotReadPolicy:`Kon het inlogbeleid niet lezen`,policySaved:`Bewaard. Het geldt vanaf nu voor elke inlog.`,policySubtitle:`Hoe mensen inloggen bij deze app. Wie is ingelogd, houdt de sessie en krijgt binnen 15 minuten de vraag naar wat nieuw verplicht is.`,mcpAddress:`MCP-adres`,mcpAddressDescription:`Voeg dit adres toe aan een AI-assistent of code-editor die MCP spreekt, als aangepaste connector of externe MCP-server. Die opent deze app in je browser, waar je inlogt en hem toestaat; daarna werkt hij met jouw toegang.`,copyMcpAddress:`Het MCP-adres kopiëren`,addToClaude:`Toevoegen aan Claude`,deleteAccount:`Account verwijderen`,deleteAccountDescription:`Verwijder je account en log overal uit. Je kunt er daarna niet meer mee inloggen, en dit kan niet ongedaan worden gemaakt.`,deleteAccountStaff:`Een medewerker die als iemand anders is ingelogd, kan diens account niet verwijderen.`,deleteAccountQuestion:`Je account verwijderen?`,deleteAccountWarning:`Je account, je inlogmethoden en elk apparaat dat ermee is ingelogd worden verwijderd. Dit kan niet ongedaan worden gemaakt.`,deleteAccountPassword:`Vul je wachtwoord in om te bevestigen.`,deleteAccountConfirm:`Mijn account verwijderen`,deleteAccountLastAdmin:`Je bent de laatste beheerder van deze app. Maak eerst iemand anders beheerder.`,deleteAccountLocked:`Dit account is vergrendeld en kan dus niet worden verwijderd.`}}),Vs=`/-/account`,Hs=`/-/sign-in-policy`,Us=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}},Ws=e=>e?`${Vs}/${encodeURIComponent(e)}`:Vs,Gs=(e,t,n)=>[{id:`account`,label:L(`account`),icon:Ds,href:`${e}${Vs}`,active:Us(t)!==void 0},...n?[{id:`sign-in-policy`,label:L(`signInPolicy`),icon:Vo,href:`${e}${Hs}`,active:t===Hs}]:[]],Ks=[`always`,`editing`,`reading`],qs=e=>e!==void 0&&!Ks.includes(e),Js={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`},Ys=[`list`,`display`,`filter`,`orderBy`,`filterLayout`,`savedSearch`],Xs=e=>`${e.latitude.toFixed(5)},${e.longitude.toFixed(5)},${e.zoom.toFixed(2)}`,Zs=(e,t,n=-t)=>Number.isFinite(e)&&e>=n&&e<=t,Qs=e=>{let t=e?.split(`,`);if(t?.length!==3||t.some(e=>e.trim()===``))return;let[n,r,i]=t.map(Number);return Zs(n,90)&&Zs(r,180)&&Zs(i,22,0)?{latitude:n,longitude:r,zoom:i}:void 0},$s=e=>`${e.scale},${e.day}`,ec=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},tc=(e,t)=>{let n=e?.split(`,`);if(n?.length!==2)return;let[r,i]=n;return t.includes(r)&&ec(i)?{scale:r,day:i}:void 0},nc=e=>{let t=new URLSearchParams;for(let n of Ys){let r=e[n];r===void 0||r===``&&n!==`filter`||t.set(Js[n],r)}e.map&&t.set(Js.map,Xs(e.map)),e.calendar&&t.set(Js.calendar,$s(e.calendar)),e.timeline&&t.set(Js.timeline,$s(e.timeline));let n=t.toString();return n?`?${n}`:``},rc=e=>{let t=new URLSearchParams;e.edit&&t.set(Js.edit,`true`);for(let n of e.open??[])t.append(Js.open,n);e.tab&&t.set(Js.tab,e.tab);let n=t.toString();return n?`?${n}`:``},ic=(e,t=``)=>{switch(e.kind){case`page`:return`${t}/${encodeURIComponent(e.page)}${e.tab?`/${encodeURIComponent(e.tab)}`:``}`;case`create`:return`${t}/${encodeURIComponent(e.resource)}/${Js.create}${oc(e.values)}`;case`record`:return`${t}/${encodeURIComponent(e.resource)}/${encodeURIComponent(An(e.key))}${rc(e)}`;case`list`:return`${t}/${encodeURIComponent(e.resource)}${nc(e)}`}},ac=e=>{try{return e.split(`/`).filter(Boolean).map(decodeURIComponent)}catch(e){if(e instanceof URIError)return;throw e}},oc=(e={})=>{let t=new URLSearchParams(Object.entries(e).filter(([,e])=>e!==``)).toString();return t?`?${t}`:``},sc=e=>e===`bar`||e===`panel`?e:void 0,cc=(e,t)=>{let n=new URL(e,`http://app`),r=ac(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===Js.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(Js.open).filter(e=>e!==``))],t=n.searchParams.get(Js.tab)||void 0;return{kind:`record`,resource:i,key:a,...n.searchParams.get(Js.edit)===`true`&&{edit:!0},...e.length>0&&{open:e},...t&&{tab:t}}}let o=n.searchParams,s=o.get(Js.list)||void 0,c=o.get(Js.display)||void 0,l=o.get(Js.filter)??void 0,u=o.get(Js.orderBy)||void 0,d=sc(o.get(Js.filterLayout)),f=Qs(o.get(Js.map)),p=tc(o.get(Js.calendar),[`month`,`week`]),m=tc(o.get(Js.timeline),[`week`,`month`,`quarter`]),h=o.get(Js.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}}},lc={signature:`sig`},uc=e=>{let t=e.startsWith(`?`)?e.slice(1):e;return new URLSearchParams(t).has(lc.signature)?{oauthQuery:t}:{}},dc=`/-/sign-in`,fc={step:`step`,next:`next`},pc=[`sign-in`,`forgot-password`,`email-code`,`sign-up`,`sign-up-code`,`sign-up-details`],mc=e=>pc.includes(e),hc=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}`},gc=({step:e=`sign-in`,next:t}={})=>{let n=new URLSearchParams;e!==`sign-in`&&n.set(fc.step,e);let r=hc(t);r&&r!==`/`&&n.set(fc.next,r);let i=n.toString();return i?`${dc}?${i}`:dc},_c=(e,t)=>{if(e!==`/-/sign-in`)return;let n=t.get(fc.step),r=hc(t.get(fc.next));return{step:mc(n)?n:`sign-in`,...r&&{next:r}}},vc=e=>typeof e==`string`?e:e&&Jt(e),yc=e=>{let t=Object.entries(e??{}).map(([e,t])=>`${e}.${t}`);return t.length>0?t:void 0},bc=e=>({photos:e&&`${e.resource}.${e.field}.${e.image}`,photos_order_by:e?.sort}),xc=(e={})=>({filter:vc(e.filter)||void 0,order_by:e.orderBy,page_size:e.pageSize,page_token:e.pageToken||void 0,fields:e.fields?.join(`,`),labels:yc(e.labels)?.join(`,`),...bc(e.photos),count:e.count}),Sc=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}`:``},Cc=e=>e.startsWith(`/`)&&!e.startsWith(`//`),wc=e=>{if(typeof e!=`object`||!e)return!1;let{uri:t,url:n}=e;return typeof t==`string`&&typeof n==`string`&&Cc(n)},Tc=e=>e!==void 0&&URL.canParse(e)?new URL(e).origin:void 0,Ec=(e,t)=>({...e,url:`${t}${e.url}`,...e.variants&&{variants:Object.fromEntries(Object.entries(e.variants).map(([e,n])=>[e,Cc(n.url)?{...n,url:`${t}${n.url}`}:n]))}}),Dc=(e,t)=>t===void 0||typeof e!=`object`||!e?e:Object.fromEntries(Object.entries(e).map(([e,n])=>[e,wc(n)?Ec(n,t):n])),Oc=(e,t)=>t===void 0?e:Object.fromEntries(Object.entries(e).map(([e,n])=>[e,n.map(e=>wc(e)?Ec(e,t):e)])),kc=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 errors(){return this.problem.errors??[]}get filterErrors(){return this.slug===`invalid-filter`?this.errors:[]}},Ac=class extends kc{constructor(e){super(e),this.name=`PreconditionFailedError`}},jc=e=>e instanceof kc,Mc=e=>typeof e==`object`&&!!e&&`type`in e&&`status`in e,Nc=async e=>{let t=e.headers.get(`content-type`)?.includes(`json`)??!1?await e.json():void 0,n=Mc(t)?t:{type:`urn:protobase:problem:unknown`,title:e.statusText||`Request failed`,status:e.status};return n.status===412?new Ac(n):new kc(n)},Pc=(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 Nc(h);return h}},Fc=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()]})),Ic=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:Fc(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)}),Lc=e=>Math.min(3e4,1e3*2**e),Rc=(e,t)=>new Promise(n=>{let r=setTimeout(n,e);t.addEventListener(`abort`,()=>{clearTimeout(r),n()},{once:!0})}),zc=(e,t,n=Lc)=>{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:Sc({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 $n(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 Rc(n(o++),i)}})(),()=>r.abort()},Bc=e=>({register:async t=>(await e({method:`POST`,path:dr(``),system:!0,body:t})).json(),remove:async t=>{await e({method:`DELETE`,path:dr(``,t),system:!0})}}),Vc=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:pr(``),query:i,system:!0})).json()},unread:async()=>(await(await e({method:`GET`,path:pr(``,`unread`),system:!0})).json()).count,markRead:async t=>{await e({method:`POST`,path:pr(``,{read:t}),body:{},system:!0})},markAllRead:async t=>{await e({method:`POST`,path:pr(``,`read`),body:{upTo:t},system:!0})}}),Hc=e=>typeof e==`string`?e:e.toModel().name,Uc=(e,t)=>`/${Hc(e)}/${An(t)}`,Wc=(e,t,n)=>({items:e.items.map(e=>Dc(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:Oc(e.photos,n)},...t.headers.get(`x-protobase-warning`)&&{warning:t.headers.get(`x-protobase-warning`)}}),Gc=({created_at:e,...t})=>({...t,createdAt:e}),Kc=e=>e.headers.get(`etag`)??``,qc=async(e,t)=>{let{permissions:n,...r}=await e.json();return{record:Dc(r,t),etag:Kc(e),...n&&{permissions:n}}},Jc=(e,t)=>({results:(e.results??[]).map(e=>e.op===`create`||e.op===`update`?{...e,record:Dc(e.record,t)}:e.op===`reorder`?{...e,records:e.records.map(e=>({...e,record:Dc(e.record,t)}))}:e)}),Yc=(e={})=>{let t=Pc(e),n=Tc(e.baseUrl),r=async(e,r)=>{let i=await t({method:`GET`,path:`/${Hc(e)}`,query:Sc(xc(r))});return Wc(await i.json(),i,n)},i=async(e,r)=>{let i=xc(r),a=await t({method:`POST`,path:`/${Hc(e)}:search`,body:{...i,fields:r?.fields,labels:yc(r?.labels)}});return Wc(await a.json(),a,n)},a=async(e,r)=>qc(await t({method:`GET`,path:Uc(e,r)}),n),o=async(e,r)=>{let i=await t({method:`POST`,path:`/${Hc(e)}`,body:r});return{record:Dc(await i.json(),n),etag:Kc(i),location:i.headers.get(`location`)??``}},s=async(e,r,i,a)=>qc(await t({method:`PATCH`,path:Uc(e,r),body:i,headers:{"if-match":a}}),n),c=async(e,n,{etag:r}={})=>{await t({method:`DELETE`,path:Uc(e,n),headers:r?{"if-match":r}:void 0})},l=async(e,r)=>{let i=await t({method:`POST`,path:`${Uc(e,r)}:undelete`});return{record:Dc(await i.json(),n),etag:Kc(i)}},u=async(e,n,r)=>(await(await t({method:`POST`,path:`${Uc(e,n)}:reveal`,body:{field:r}})).json()).value,d=async(e,r,i)=>qc(await t({method:`POST`,path:`${Uc(e,r)}:generate`,body:{action:i}}),n),f=async(e,n,{pageSize:r,pageToken:i}={})=>{let a=Sc({page_size:r,page_token:i||void 0}),o=await(await t({method:`GET`,path:`${Uc(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=Sc({page_size:r,page_token:i||void 0}),o=await(await t({method:`GET`,path:`${Uc(e,n)}:comments`,query:a})).json();return{items:o.items.map(Gc),nextPageToken:o.next_page_token}},m=async(e,n,{body:r,mentions:i=[]})=>Gc(await(await t({method:`POST`,path:`${Uc(e,n)}:comments`,body:{body:r,mentions:i}})).json()),h=async(e,n,r)=>(await(await t({method:`GET`,path:`${Uc(e,n)}:mentionable`,query:Sc({q:r})})).json()).items,g=async e=>{let r=e=>typeof e==`object`&&e&&`$ref`in e?e:An(e),i=e.map(e=>({...e,resource:Hc(e.resource),...`key`in e&&{key:r(e.key)},...e.op===`reorder`&&{keys:e.keys.map(r)}}));return Jc(await(await t({method:`POST`,path:`:batchWrite`,body:{ops:i}})).json(),n)},_=async(e,n,r={})=>(await(await t({method:`GET`,path:`/${Hc(e)}:facets`,query:Sc({field:n,filter:vc(r.filter)||void 0,limit:r.limit,label:r.label})})).json()).facets,v=async(e,n)=>{let r=await(await t({method:`GET`,path:`/${Hc(e)}:aggregate`,query:Sc({group_by:n.groupBy,filter:vc(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:`/${Hc(e)}:series`,query:Sc({field:n.field,range:n.range,from:n.from,to:n.to,granularity:n.granularity,time_zone:n.timeZone,filter:vc(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:`/${Hc(e)}:histogram`,query:Sc({field:n,buckets:r.buckets,filter:vc(r.filter)||void 0})})).json(),x=async(e,r)=>{let i=await(await t({method:`GET`,path:`/${Hc(e)}:map`,query:Sc({latitude:r.latitude,longitude:r.longitude,zoom:r.zoom,filter:vc(r.filter)||void 0,order_by:r.orderBy,fields:r.fields?.join(`,`),labels:yc(r.labels)?.join(`,`),...bc(r.photos)})})).json();return{items:i.items.map(e=>Dc(e,n)),buckets:i.buckets,totalSize:i.total_size,...i.labels!==void 0&&{labels:i.labels},...i.photos!==void 0&&{photos:Oc(i.photos,n)}}},S=async(e,r)=>{let i=await t({method:`GET`,path:`/${Hc(e)}:seek`,query:Sc({...xc(r),position:r.position})});return Wc(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:Kc(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 s.headers.get(`content-type`)?.includes(`json`)?s.json():s.text()},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`?Ic(i):void 0,c=await(await t({method:`POST`,path:`/${Hc(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)}`;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:async e=>(await t({method:`GET`,path:E(e),system:!0})).json(),formChallenge:async e=>(await t({method:`GET`,path:`${E(e)}:challenge`,system:!0})).json(),submitForm:async(e,n,r)=>{await t({method:`POST`,path:E(e),body:{values:n,proof:r},system:!0})},live:e=>zc(t,e),devices:Bc(t),notifications:Vc(t)}},Xc=e=>typeof e==`string`?e:e.toModel().name,Zc=(e,t)=>{let n=n=>t(Xc(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=>Xc(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),devices:e.devices,notifications:e.notifications}},Qc=e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&typeof e.type==`string`&&Array.isArray(e.children),$c={record:!1},el=e=>({resource:typeof e.props.resource==`string`?e.props.resource:void 0,record:!0}),tl=(e,t)=>!e.custom&&(e.type===`RecordCard`||e.type===`CardRow`)?el(e):t,nl=(e,t)=>!e.custom&&e.type===`RecordCard`?el(e):t,rl=e=>`<${e.type}${typeof e.props.resource==`string`?` resource="${e.props.resource}"`:``}${typeof e.props.name==`string`?` name="${e.props.name}"`:``}>`,il=e=>Qc(e)||Array.isArray(e)&&e.length>0&&e.every(Qc),al=(e,t,n={path:rl(e),scope:$c})=>{let r=tl(e,n.scope),i=nl(e,n.scope),a=e.children.flatMap(e=>{if(typeof e==`string`)return[e];let i=al(e,t,{path:`${n.path} › ${rl(e)}`,scope:r});return i?[i]:[]}),o=Object.fromEntries(Object.entries(e.props).flatMap(([e,r])=>{if(!il(r))return[[e,r]];let a=(Array.isArray(r)?r:[r]).flatMap(r=>al(r,t,{path:`${n.path} ${e}={${rl(r)}}`,scope:i})??[]);return a.length===0?[]:[[e,Array.isArray(r)?a:a[0]]]}));return t({...e,props:o,children:a},n)},ol=e=>typeof e==`object`&&!!e&&e.kind===`member`,sl=e=>ol(e)?[e.path.join(`.`)]:typeof e!=`object`||!e?[]:Object.values(e).flatMap(sl),cl=e=>ol(e)?{...e,path:[e.path.join(`.`)]}:Array.isArray(e)?e.map(cl):typeof e!=`object`||!e?e:Object.fromEntries(Object.entries(e).map(([e,t])=>[e,cl(t)])),ll=e=>{let t=ve(e);return t.ok?t.ast?{ok:!0,ast:t.ast,paths:[...new Set(sl(t.ast))]}:{ok:!1,message:`the condition is empty`}:{ok:!1,message:t.errors.map(e=>e.message).join(`; `)}},ul=(e,t)=>e.ast!==void 0&&te(cl(e.ast),t),dl=(e,t)=>{let[n,r,...i]=e.split(`.`);return n&&r===`count`&&i.length===0&&!t(n)?n:void 0},fl=({layout:e,cardWidth:t})=>({layout:e??`stack`,cardWidth:t??`2/3`}),pl=(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}},ml=(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]}))}),hl=(e,t)=>{if(e.kind===`group`){let n=e.items.flatMap(e=>hl(e,t));return n.length>0?[{...e,items:n}]:[]}if(e.kind===`tab`){let n=e.items.flatMap(e=>hl(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=>pl(t,e.resource,n).ok);return[i&&i.length>0?{...r,columns:i}:r]},gl=(e,t,n)=>e.run?.kind!==`link`||!(`to`in e.run)||Jn(e.run.to,{models:n,pages:new Set,source:t}).length===0,_l=(e,t)=>({...e,layout:e.layout.flatMap(e=>hl(e,t)),actions:e.actions.filter(n=>gl(n,t[e.resource],t))}),vl=(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=>ml(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=>_l(e,a)),permissions:Object.fromEntries(n.flatMap(t=>e.permissions?.[t.name]?[[t.name,e.permissions[t.name]]]:[]))}},yl=class extends Error{status;code;constructor(e,t,n){super(e),this.status=t,this.code=n,this.name=`AuthError`}},R=(e,t)=>new yl(e?.message||t,e?.status??500,e?.code),bl=e=>new Date(e).toISOString(),xl=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,r)=>{let{error:i}=await e.changePassword({currentPassword:t,newPassword:n,revokeOtherSessions:r});if(i)throw R(i,`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:bl(e.createdAt),updatedAt:bl(e.updatedAt),expiresAt:bl(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`)}}),Sl=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},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}}),Cl=(e,t)=>new yl(e?.message||e?.error_description||t,e?.status??500,e?.code??e?.error),wl=e=>({client:async t=>{let{data:n,error:r}=await e.$fetch(`/oauth2/public-client`,{query:{client_id:t}});if(r||!n)throw Cl(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 Cl(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 Cl(i,`Could not answer the request`);return{url:r.url}}}),Tl=(e,t,n)=>x({baseURL:e,basePath:t,plugins:[k(),O(),m(),A()],disableDefaultFetchPlugins:!0,fetchOptions:{customFetchImpl:n}}),El=e=>Array.isArray(e)?e.filter(e=>typeof e==`string`):typeof e==`string`?JSON.parse(e):[],Dl=e=>{let t=e.split(`,`);return t.includes(`owner`)?`owner`:t.includes(`admin`)?`admin`:`member`},Ol=e=>({id:e.id,userId:e.userId,name:e.user.name||e.user.email,email:e.user.email,role:Dl(e.role),appRoles:El(e.appRoles),createdAt:new Date(e.createdAt).toISOString()}),kl=e=>({id:e.id,email:e.email,role:Dl(e.role),appRoles:El(e.appRoles),status:e.status,expiresAt:new Date(e.expiresAt).toISOString(),...e.organizationName&&{organizationName:e.organizationName}}),Al=(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(Ol),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(kl),invite:async(e,t)=>{let r=await n(`/organization/invite-member`,`Could not send the invitation`,{body:{organizationId:e,...t}});return{invitation:kl(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:kl(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(kl),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}}))}},jl=(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()}}),Ml=20,Nl=e=>Array.isArray(e)?e:(e??``).split(`,`).map(e=>e.trim()).filter(Boolean),Pl=e=>({id:e.id,name:e.name||e.email,email:e.email,roles:Nl(e.role),blocked:!!e.banned,createdAt:new Date(e.createdAt).toISOString()}),Fl=e=>({id:e.id,email:e.email,roles:e.roles,expiresAt:new Date(e.expiresAt).toISOString()}),Il=e=>({invitation:Fl(e),...e.link&&{link:e.link}}),Ll=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(Ml),sortBy:`createdAt`,sortDirection:`asc`,...n>0&&{offset:String(n)},...e&&{searchValue:e,searchField:`email`}}});return{users:r.users.map(Pl),total:r.total}},create:async e=>Pl((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=>Il(await t(`/users/invite`,`Could not send the invitation`,{body:e})),invitations:async()=>(await t(`/users/invitations`,`Could not read the invitations`)).invitations.map(Fl),revoke:e=>t(`/users/invitations/cancel`,`Could not revoke the invitation`,{body:{id:e}}),roles:()=>t(`/users/roles`,`Could not read the roles`)}},Rl=(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 yl(`Auth cancelled`,400,e instanceof ae?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}}},zl=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}}),Bl=e=>new Date(e).toISOString(),Vl=({startedAt:e,expiresAt:t,endedAt:n,...r})=>({...r,startedAt:Bl(e),expiresAt:Bl(t),...n&&{endedAt:Bl(n)}}),Hl=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?Vl(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(Vl)}}),Ul=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},Wl=(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=Tl(t,n,i),o=Hl(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:Ul(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 yl(`This server has no sign-in. Is the API URL right?`,404);if(!e.ok)throw new yl(`Could not read the sign-in status`,e.status);let r=await e.json();return{needsAdmin:!!r.needsAdmin,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.plugins&&r.plugins.length>0&&{plugins:r.plugins},...Pe(r.locale)&&{locale:r.locale}}},session:async()=>{let{data:e}=await a.getSession();return e?.user},...Rl(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:{...Sl(a),...xl(a)},connect:wl(a),organizations:Al(a,()=>f({refresh:!0})),roles:jl(a,()=>f({refresh:!0})),signInPolicy:zl(a),users:Ll(a),staff:{...o,stop:async()=>{u(),await o.stop()}}}},Gl=e=>Math.min(3e4,1e3*2**e),Kl=(e,t)=>new Promise(n=>{let r=setTimeout(n,e);t.addEventListener(`abort`,()=>{clearTimeout(r),n()},{once:!0})}),ql=`http://same-origin.invalid`,Jl=(e,t)=>{let n=new URL(e,ql),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===ql?`${r.pathname}${r.search}`:r.href},Yl=e=>{let t=e.url.replace(/\/+$/,``),n=e.fetch??((e,t)=>fetch(e,t)),r=e.retryDelayMs??Gl,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 Nc(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 $n(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 Kl(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=Jl(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 Nc(c);return c}}},Xl=e=>typeof e==`object`&&!!e&&`error`in e&&typeof e.error==`object`&&e.error!==null&&`code`in e.error&&`message`in e.error,Zl=async e=>{let t=e.headers.get(`content-type`)?.includes(`json`)??!1?await e.clone().json():void 0;return Xl(t)?new kc({type:`urn:protobase:problem:${t.error.code}`,title:e.statusText||`Request failed`,status:e.status,detail:t.error.message}):Nc(e)},Ql=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 Zl(o);return await o.json()};return{status:()=>r(``,`GET`),update:()=>r(`/update`,`POST`)}},$l=e=>e.Capacitor?.isNativePlatform()?e.Capacitor:void 0,eu=[101,204,205,304],tu=/%2f|%5c/i,nu=e=>Object.hasOwn(cr,e),ru=(e,t)=>e.origin===t&&!e.username&&!e.password&&e.pathname.startsWith(`/api/auth/`)&&!tu.test(e.pathname),iu=(e,{url:t,method:n,headers:r,data:i})=>{let a=i===void 0?{}:{data:i};return e===`android`?[`ProtobaseAuth`,`request`,{url:t,method:n,headers:r,...a}]:[`CapacitorHttp`,`request`,{url:t,method:n,headers:{...r,origin:cr[e]},...a,responseType:`text`,disableRedirects:!0}]},au=({status:e,headers:t,data:n})=>eu.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),ou=(e,t)=>{let n=e.getPlatform();if(!nu(n))throw Error(`Signing in through native HTTP is for iOS and Android, not ${n}`);return async(r,i)=>{let a=new Request(r,i),o=new URL(a.url);if(!ru(o,t))throw Error(`Native sign-in requests go to ${t}${sr}/ only, not ${a.url}`);let s=a.method!==`GET`&&a.method!==`HEAD`,c=iu(n,{url:o.href,method:a.method,headers:Object.fromEntries(a.headers),...s&&{data:await a.text()}}),l=await e.nativePromise(...c),u=Object.entries(l.headers).filter(([e])=>e.toLowerCase()!==`set-cookie`);return new Response(au(l),{status:l.status,headers:u})}},su=(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(`/${ur}`),t.serviceWorker.ready),clearBadge:async()=>{`clearAppBadge`in t&&await t.clearAppBadge()},userAgent:t.userAgent.replace(/[\u0000-\u001f\u007f]/g,``).slice(0,512)}},cu=(e=indexedDB)=>{let t=(t,n)=>new Promise((r,i)=>{let a=e.open(lr.database,1);a.onupgradeneeded=()=>a.result.createObjectStore(lr.store),a.onerror=()=>i(a.error),a.onsuccess=()=>{let e=a.result,o=n(e.transaction(lr.store,t).objectStore(lr.store));o.onsuccess=()=>(e.close(),r(o.result)),o.onerror=()=>(e.close(),i(o.error))}});return{read:()=>t(`readonly`,e=>e.get(lr.key)),write:async e=>void await t(`readwrite`,t=>t.put(e,lr.key)),clear:async()=>void await t(`readwrite`,e=>e.delete(lr.key))}},lu=e=>Uint8Array.from(atob(e.replace(/-/g,`+`).replace(/_/g,`/`)),e=>e.charCodeAt(0)),uu=(e,t)=>Promise.race([t,new Promise(t=>setTimeout(t,e))]),du=class extends Error{},fu=(e,t)=>e instanceof kc&&e.status===409&&e.slug===t,pu=({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 du;let e=await c.pushManager.getSubscription()??await c.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:lu(a)}),i={userId:n.id,endpoint:e.endpoint,appName:r};if(await t.write(i),!o())throw new du;await d(e,i)};try{await h()}catch(e){if(fu(e,`device-held`))return await u(c),m(c,h);if(await u(c),e instanceof du||fu(e,`other-user`))return`off`;throw e}return`on`},m=async(e,t)=>{try{await t()}catch(t){if(await u(e),t instanceof du||fu(t,`device-held`)||fu(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 uu(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 uu(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(!fu(e,`device-held`)&&!fu(e,`other-user`))throw e;await u(r)}}}},mu={state:async()=>`unsupported`,turnOn:async()=>`unsupported`,turnOff:async()=>{},forget:async()=>{},adopt:async()=>{}},hu=({nativeBridge:e,...t})=>{if(e||typeof window>`u`)return mu;let n=su();return n.supported?pu({...t,browser:n,records:cu()}):mu},gu=`sign-in`,_u=`error`,vu=e=>{let t=new URL(e).searchParams;if(!t.has(_u))return t.get(`sign-in`)||void 0},yu=e=>new URL(e).searchParams.get(_u)||void 0,bu=e=>{let t=new URL(e);for(let e of[gu,_u])t.searchParams.delete(e);return`${t.pathname}${t.search}${t.hash}`},xu={github:`GitHub`,gitlab:`GitLab`,google:`Google`,microsoft:`Microsoft`,apple:`Apple`},Su=(e,t)=>t?.provider===e?t.name:xu[e]??e.charAt(0).toUpperCase()+e.slice(1),z=M({en:{loading:`Loading`,cannotReach:e=>`Cannot reach the server: ${e}`,tryAgain:`Try again`,passwordChanged:`Your password is changed. Sign in with the new one.`,noAnswer:`The server did not answer`,code:`Code`,backupCode:`Backup code`,email:`Email`,password:`Password`,passwordOptional:`Password (optional)`,signIn:`Sign in`,signOut:`Sign out`,continue:`Continue`,backToSignIn:`Back to sign in`,useAnotherAddress:`Use another address`,checkEmail:`Check your email`,newCodeSent:`A new code is on its way. Only the newest one works.`,sendNewCode:`Send a new code`,sendNewCodeIn:e=>`Send a new code in ${e}s`,signInCodeDescription:`Enter the code we sent to sign in.`,signInCodeSent:`If {} has an account, a 6-digit code is on its way. It works for 5 minutes, once.`,signUpCodeDescription:`Enter the code we sent to create your account.`,signUpCodeSent:`A 6-digit code is on its way to {}. It works for 5 minutes, once. If the address has an account already, the email says so instead.`,noAdminTitle:`No admin yet`,noAdminDescription:`This Protobase has no users to sign in with.`,noAdminExplanation:`Run this in the terminal where Protobase runs, then reload. The first admin is created on the server, not in the browser, so nobody else can claim a fresh URL.`,copyCommand:`Copy command`,reload:`Reload`,tooManyRequests:`Too many requests. Wait a minute and try again.`,tooManyAttempts:`Too many attempts. Wait a minute and try again.`,resetTitle:`Reset your password`,resetDescription:`We email you a link to choose a new one.`,sendResetLink:`Send reset link`,resetSent:`If {} has an account, an email with a link to choose a new password is on its way. The link works once, for a limited time.`,linkExpiredTitle:`This link no longer works`,linkExpiredExplanation:`A reset link works once, for a limited time. Ask for a new one to choose your password.`,sendNewLink:`Send a new link`,passwordsDiffer:`The passwords are not the same.`,choosePassword:`Choose a new password`,atLeast:e=>`At least ${e} characters.`,useAtLeast:e=>`Use at least ${e} characters.`,passwordTooLong:`That password is too long.`,newPassword:`New password`,repeatPassword:`Repeat new password`,setPassword:`Set new password`,signingInWith:e=>`Signing in with ${e}`,takingYouTo:e=>`Taking you to ${e}…`,providerNotOffered:e=>`Signing in with ${e} is not offered here. Sign in another way.`,turnOnTwoFactor:`Turn on two-factor authentication`,addPasskey:`Add a passkey`,requiredForEveryAccount:`This app requires it for every account.`,passkeyExplanation:`A passkey signs you in with Face ID, Touch ID, Windows Hello, your phone or a security key. Your browser asks which one to use.`,couldNotReadAccount:`Could not read your account`,signInTitle:`Sign in to Protobase`,continueWith:e=>`Continue with ${e}`,signInWithPasskey:`Sign in with a passkey`,passkeyFor:e=>`Use a passkey made for ${e}`,or:`or`,emailSignInCode:`Email me a sign-in code`,usePassword:`Use a password`,forgotPassword:`Forgot password?`,newHere:`New here?`,haveAccount:`Have an account?`,createAnAccount:`Create an account`,browse:`Continue without signing in`,notNow:`Not now`,detailsTitle:`Your details`,detailsDescription:`One last step to create your account.`,yourName:`Your name`,codeWasRight:`The code was right: the account is for {}.`,withoutPassword:` Without one, you sign in with a code we email you.`,createAccount:`Create account`,codeToConfirm:`We email you a code to make sure the address is yours.`,emailCode:`Email me a code`,browseWithoutAccount:`Continue without an account`,staffTitle:`Staff sign-in`,staffUnavailable:`Staff of the team that runs this app cannot sign in as people here.`,signInAsPerson:`Sign in as a person`,forStaffOf:e=>`For staff of ${e}, to help someone with this app.`,theirEmail:`Their email`,reason:`Reason`,reasonExample:`Ticket 4211: the invoice totals look wrong`,staffExplanation:e=>`You sign in at ${e} with a passkey or a second step. The session is short, shows a banner, and cannot change their sign-in. The app's admins see who signed in as whom, and why.`,totpInstruction:`Enter the 6-digit code from your authenticator app.`,otpInstruction:`Enter the 6-digit code we emailed you. It works for 5 minutes.`,backupInstruction:`Enter one of the backup codes you saved when you set up the authenticator app. Each works once.`,twoFactorTitle:`Two-factor authentication`,twoFactorDescription:`One more step to sign in.`,codeToFinish:`We email you a code to finish signing in.`,trustBrowser:`Trust this browser`,trustBrowserFor:`Don't ask again in this browser for 30 days`,verify:`Verify`,useAuthenticator:`Use the authenticator app`,emailCodeInstead:`Email me a code instead`,useBackupCode:`Use a backup code`,admin:`Admin`},nl:{loading:`Laden`,cannotReach:e=>`Kan de server niet bereiken: ${e}`,tryAgain:`Opnieuw proberen`,passwordChanged:`Je wachtwoord is gewijzigd. Log in met het nieuwe.`,noAnswer:`De server antwoordde niet`,code:`Code`,backupCode:`Back-upcode`,email:`E-mailadres`,password:`Wachtwoord`,passwordOptional:`Wachtwoord (optioneel)`,signIn:`Inloggen`,signOut:`Uitloggen`,continue:`Doorgaan`,backToSignIn:`Terug naar inloggen`,useAnotherAddress:`Een ander adres gebruiken`,checkEmail:`Kijk in je e-mail`,newCodeSent:`Er is een nieuwe code onderweg. Alleen de nieuwste werkt.`,sendNewCode:`Nieuwe code sturen`,sendNewCodeIn:e=>`Nieuwe code sturen over ${e}s`,signInCodeDescription:`Vul de code in die we stuurden om in te loggen.`,signInCodeSent:`Als {} een account heeft, is er een code van 6 cijfers onderweg. Die werkt 5 minuten, één keer.`,signUpCodeDescription:`Vul de code in die we stuurden om je account te maken.`,signUpCodeSent:`Er is een code van 6 cijfers onderweg naar {}. Die werkt 5 minuten, één keer. Heeft het adres al een account, dan staat dat in de e-mail.`,noAdminTitle:`Nog geen beheerder`,noAdminDescription:`Deze Protobase heeft geen gebruikers om mee in te loggen.`,noAdminExplanation:`Voer dit uit in de terminal waar Protobase draait en laad de pagina daarna opnieuw. De eerste beheerder wordt op de server gemaakt, niet in de browser, zodat niemand anders een nieuwe URL kan opeisen.`,copyCommand:`Opdracht kopiëren`,reload:`Opnieuw laden`,tooManyRequests:`Te veel verzoeken. Wacht een minuut en probeer het opnieuw.`,tooManyAttempts:`Te veel pogingen. Wacht een minuut en probeer het opnieuw.`,resetTitle:`Je wachtwoord herstellen`,resetDescription:`We mailen je een link om een nieuw te kiezen.`,sendResetLink:`Herstellink sturen`,resetSent:`Als {} een account heeft, is er een e-mail onderweg met een link om een nieuw wachtwoord te kiezen. De link werkt één keer, een beperkte tijd.`,linkExpiredTitle:`Deze link werkt niet meer`,linkExpiredExplanation:`Een herstellink werkt één keer, een beperkte tijd. Vraag een nieuwe aan om je wachtwoord te kiezen.`,sendNewLink:`Nieuwe link sturen`,passwordsDiffer:`De wachtwoorden zijn niet hetzelfde.`,choosePassword:`Kies een nieuw wachtwoord`,atLeast:e=>`Minstens ${e} tekens.`,useAtLeast:e=>`Gebruik minstens ${e} tekens.`,passwordTooLong:`Dat wachtwoord is te lang.`,newPassword:`Nieuw wachtwoord`,repeatPassword:`Nieuw wachtwoord herhalen`,setPassword:`Nieuw wachtwoord instellen`,signingInWith:e=>`Inloggen met ${e}`,takingYouTo:e=>`Je gaat naar ${e}…`,providerNotOffered:e=>`Inloggen met ${e} kan hier niet. Log op een andere manier in.`,turnOnTwoFactor:`Tweestapsverificatie aanzetten`,addPasskey:`Passkey toevoegen`,requiredForEveryAccount:`Deze app vraagt het voor elk account.`,passkeyExplanation:`Met een passkey log je in met Face ID, Touch ID, Windows Hello, je telefoon of een beveiligingssleutel. Je browser vraagt welke je gebruikt.`,couldNotReadAccount:`Kon je account niet lezen`,signInTitle:`Inloggen bij Protobase`,continueWith:e=>`Doorgaan met ${e}`,signInWithPasskey:`Inloggen met een passkey`,passkeyFor:e=>`Een passkey voor ${e} gebruiken`,or:`of`,emailSignInCode:`Mail me een inlogcode`,usePassword:`Een wachtwoord gebruiken`,forgotPassword:`Wachtwoord vergeten?`,newHere:`Nieuw hier?`,haveAccount:`Heb je een account?`,createAnAccount:`Account maken`,browse:`Doorgaan zonder in te loggen`,notNow:`Niet nu`,detailsTitle:`Je gegevens`,detailsDescription:`Nog één stap om je account te maken.`,yourName:`Je naam`,codeWasRight:`De code klopte: het account is voor {}.`,withoutPassword:` Zonder wachtwoord log je in met een code die we je mailen.`,createAccount:`Account maken`,codeToConfirm:`We mailen je een code om te controleren dat het adres van jou is.`,emailCode:`Mail me een code`,browseWithoutAccount:`Doorgaan zonder account`,staffTitle:`Inloggen als medewerker`,staffUnavailable:`Medewerkers van het team dat deze app beheert, kunnen hier niet als iemand anders inloggen.`,signInAsPerson:`Inloggen als iemand anders`,forStaffOf:e=>`Voor medewerkers van ${e}, om iemand met deze app te helpen.`,theirEmail:`Hun e-mailadres`,reason:`Reden`,reasonExample:`Ticket 4211: de factuurtotalen kloppen niet`,staffExplanation:e=>`Je logt in bij ${e} met een passkey of een tweede stap. De sessie is kort, toont een balk en kan hun inlog niet wijzigen. De beheerders van de app zien wie als wie inlogde, en waarom.`,totpInstruction:`Vul de code van 6 cijfers uit je authenticator-app in.`,otpInstruction:`Vul de code van 6 cijfers in die we je mailden. Die werkt 5 minuten.`,backupInstruction:`Vul een van de back-upcodes in die je bewaarde toen je de authenticator-app instelde. Elke code werkt één keer.`,twoFactorTitle:`Tweestapsverificatie`,twoFactorDescription:`Nog één stap om in te loggen.`,codeToFinish:`We mailen je een code om het inloggen af te ronden.`,trustBrowser:`Deze browser vertrouwen`,trustBrowserFor:`Niet meer vragen in deze browser, 30 dagen lang`,verify:`Controleren`,useAuthenticator:`De authenticator-app gebruiken`,emailCodeInstead:`Mail me liever een code`,useBackupCode:`Een back-upcode gebruiken`,admin:`Beheerder`}}),B=e(r(),1),Cu=(0,I.createContext)(null),V=()=>{let e=(0,I.useContext)(Cu);if(!e)throw Error(`useAuth must be used inside AuthProvider`);return e},wu=()=>(0,I.useContext)(Cu),Tu=({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)(!1),[ne,re]=(0,I.useState)([]),[ie,ae]=(0,I.useState)(),oe=(0,I.useCallback)(()=>ee?{kind:`visitor`}:{kind:`signed-out`},[ee]),se=(0,I.useRef)(async()=>{}),ce=(0,I.useCallback)(()=>{se.current(),a(e=>e.kind===`signed-in`?{kind:`signed-out`}:e)},[]),le=(0,I.useRef)(ce);le.current=ce;let ue=(0,I.useMemo)(()=>e??Wl({...t&&{origin:t},...n&&{fetch:ou(n,t??window.location.origin)},onSignedOut:()=>le.current()}),[e,t,n]),de=(0,I.useRef)(void 0);de.current=i.kind===`signed-in`?{id:i.user.id,own:!i.staff}:void 0;let fe=(0,I.useMemo)(()=>{let e=Yc({baseUrl:`${t??globalThis.location?.origin??``}/api/v1`,token:({refresh:e})=>ue.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 hu({...n&&{nativeBridge:n},devices:e.devices,meta:r,user:()=>de.current})},[ue,t,n]);se.current=fe.forget;let pe=(0,I.useCallback)(async e=>{let[{missing:t},n]=await Promise.all([ue.account.signInMethods(),ue.staff.current()]);a(t.length>0?{kind:`setup-required`,user:e,missing:t}:{kind:`signed-in`,user:e,...n&&{staff:n}}),t.length===0&&fe.adopt({id:e.id,own:!n})},[ue,fe]),me=(0,I.useCallback)(async e=>e.kind===`two-factor`?a({kind:`two-factor`,methods:e.methods}):pe(e.user),[pe]),he=(0,I.useCallback)(()=>{a({kind:`loading`}),ue.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.samlProviders),k(e.staffSignIn),j(e.organizations),te(!!e.anonymous),re(e.plugins??[]),ae(e.locale),e.needsAdmin)return a({kind:`needs-admin`});let t=await ue.session();return t?pe(t):a({kind:e.anonymous?`visitor`:`signed-out`})}).catch(e=>a({kind:`error`,message:e instanceof Error?e.message:z(`noAnswer`)}))},[ue,pe,n]);(0,I.useEffect)(he,[he]);let ge=(0,I.useMemo)(()=>({state:i,session:ue,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:Su(e,w)})),...E],staffSignIn:O,...A&&{organizations:A},markSignedOut:ce,recheck:he,beforeSignIn:ne,locale:ie,adoptSession:async()=>{let e=await ue.session();return e?(await pe(e),!0):!1},...ee&&{browse:()=>{a(e=>e.kind===`signed-out`?{kind:`visitor`}:e)}},signIn:async(e,t)=>me(await ue.signIn(e,t)),sendSignInCode:e=>ue.sendSignInCode(e),signInWithCode:async(e,t)=>me(await ue.signInWithCode(e,t)),sendSignUpCode:e=>ue.sendSignUpCode(e),verifySignUpCode:(e,t)=>ue.verifySignUpCode(e,t),signUp:async e=>pe(await ue.signUp(e)),signInWithPasskey:async e=>pe(await ue.signInWithPasskey(e)),verifyTwoFactor:async e=>pe(await ue.verifyTwoFactor(e)),signInSocial:async e=>{let t=new URL(bu(window.location.href),window.location.href).href,n=E.some(t=>t.id===e);window.location.assign(await(n?ue.signInSaml(e,t):ue.signInSocial(e,t)))},linkProvider:async e=>{window.location.assign(await ue.account.linkProvider(e,new URL(bu(window.location.href),window.location.href).href))},stopStaffSession:async()=>{await fe.forget(),await ue.staff.stop(),a(oe())},signOut:async()=>{await fe.turnOff(),await ue.signOut(),a(oe())},deleteAccount:async e=>{await ue.deleteAccount(e),await fe.forget(),a(oe())},push:fe}),[fe,i,ue,o,c,u,f,m,g,v,b,S,w,E,O,A,ee,ne,ie,oe,ce,he,me,pe]);return(0,B.jsx)(Cu.Provider,{value:ge,children:r})},Eu=()=>{let e=0;return{refetchOnWindowFocus:()=>e>0?!1:`always`,paused:()=>e>0,pause:()=>{e+=1;let t=!1;return()=>{t||(t=!0,--e)}}}},Du=(0,I.createContext)(null),Ou=e=>{let t=(0,I.useContext)(Du);(0,I.useEffect)(()=>e&&t?t.pause():void 0,[e,t])},ku=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],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],publicForm:e=>[`public-form`,e]},Au=(0,I.createContext)(null),ju=(0,I.createContext)(null),Mu=(0,I.createContext)(null),U=()=>{let e=(0,I.useContext)(Au);if(!e)throw Error(`useClient must be used inside ApiProvider`);return e},Nu=e=>{let t=U();return(0,I.useContext)(Mu)?.(e)??t},Pu=()=>{let e=U(),t=(0,I.useContext)(Mu);return(0,I.useCallback)(n=>t?.(n)??e,[e,t])},Fu=()=>{let e=(0,I.useContext)(ju);if(!e)throw Error(`useSourceClients must be used inside ApiProvider`);return e},Iu=({client:e,resourceClient:t,children:n})=>(0,B.jsx)(Au.Provider,{value:e,children:(0,B.jsx)(Mu.Provider,{value:t,children:n})}),Lu=({baseUrl:e,client:t,sources:n,fetch:r,queryClient:i,token:a,onUnauthenticated:o,children:s})=>{let[c]=(0,I.useState)(Eu),[l]=(0,I.useState)(()=>i??new T({defaultOptions:{queries:{staleTime:3e4,retry:!1,refetchOnWindowFocus:c.refetchOnWindowFocus}}}));(0,I.useEffect)(()=>D.setEventListener(ku),[]);let u=(0,I.useRef)(void 0),d=(0,I.useMemo)(()=>t??Yc({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=Yc({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)(Au.Provider,{value:d,children:(0,B.jsx)(ju.Provider,{value:f,children:(0,B.jsx)(Du.Provider,{value:c,children:s})})})})},Ru=(0,I.createContext)(null),zu={create:!0,update:!0,delete:!0,conditional:[]},Bu=(e,t)=>e?e.versionChange?e:t.protobaseVersion===e.protobaseVersion?t:{...e,versionChange:{...t.protobaseVersion&&{to:t.protobaseVersion}}}:t,Vu=()=>{let e=U(),t=be(),n=(0,I.useContext)(Ru),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 Bu(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.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])},Hu=1e4,Uu=e=>e.map(e=>({data:e.data?.meta,error:e.error})),Wu=(e,t)=>{let n=be(),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(Hu)});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:vl(a.meta,e)}}}}),combine:Uu});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])},Gu=(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}},Ku=(e,t)=>e.sources?.find(e=>e.source.resources.includes(t)),qu=({locale:e,children:t})=>{Ve(e);let n=ze();return(0,I.useEffect)(()=>{document.documentElement.lang=n},[n]),(0,B.jsx)(I.Fragment,{children:t},n)},Ju=M({en:{close:`Close`,loading:`Loading`,remove:e=>`Remove ${e}`},nl:{close:`Sluiten`,loading:`Laden`,remove:e=>`${e} verwijderen`}}),Yu=({className:e})=>(0,B.jsx)(Ia,{"aria-label":Ju(`loading`),className:P(`size-4 animate-spin`,e)}),Xu=M({en:{loading:`Loading`,cannotReach:`Cannot reach the API`,noAnswer:`The server did not answer. Is it running?`},nl:{loading:`Laden`,cannotReach:`De API is niet bereikbaar`,noAnswer:`De server gaf geen antwoord. Draait hij?`}}),W=()=>{let e=(0,I.useContext)(Ru);if(!e)throw Error(`useAdminMeta must be used inside MetaGate`);return e},Zu=({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})]})}),Qu=({meta:e,children:t})=>{let n=U(),r=Fu(),i=(0,I.useMemo)(()=>(e.sources??[]).map(e=>e.source),[e.sources]),a=Wu(i,r),o=(0,I.useMemo)(()=>Gu(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:Zc(n,t),resourceClient:t}},[i,n,r]);return(0,B.jsx)(Iu,{client:s.client,resourceClient:s.resourceClient,children:(0,B.jsx)(Ru.Provider,{value:o,children:(0,B.jsx)(qu,{locale:e.locale,children:t})})})},$u=({children:e})=>{let t=Vu();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)(Yu,{}),` `,Xu(`loading`)]}):t.error?(0,B.jsx)(Zu,{title:Xu(`cannotReach`),children:jc(t.error)?t.error.message:Xu(`noAnswer`)}):(0,B.jsx)(Qu,{meta:t.data,children:e})},ed=e=>W().permissions[e]??zu,td=(0,I.createContext)(null),nd=({route:e,children:t})=>(0,B.jsx)(td.Provider,{value:e,children:t}),rd=()=>{let e=(0,I.useContext)(td);if(!e)throw Error(`Tabs render inside a page that gives them their addresses: a composed page`);return e},id=e=>e.children.filter(e=>typeof e!=`string`).map(e=>({node:e,...e.props})),ad=e=>{let t=e.children.find(e=>typeof e!=`string`&&!e.custom&&e.type===`Tabs`);return t?id(t):[]},od=(e,t)=>t===void 0?e[0]:e.find(e=>e.name===t),sd={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`},cd={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`},ld=({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`,sd[e],cd[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(ld({variant:e,size:t}),r),...o,children:[n&&(0,B.jsx)(Yu,{className:`size-3.5`}),i]}),ud=e=>(0,I.useSyncExternalStore)(t=>{let n=window.matchMedia(e);return n.addEventListener(`change`,t),()=>n.removeEventListener(`change`,t)},()=>window.matchMedia(e).matches,()=>!1),dd=()=>ud(`(min-width: 768px)`),fd=()=>ud(`not all and (min-width: 640px)`),pd=`data-pb-scroll-locked`,md=()=>{let{body:e,documentElement:t}=document,n=e.style.overflow,r=t.hasAttribute(pd);return window.innerWidth>t.clientWidth&&t.setAttribute(pd,``),e.style.overflow=`hidden`,()=>{e.style.overflow=n,r||t.removeAttribute(pd)}},hd=`a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])`,gd=[],_d=(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=md(),o={};gd.push(o);let s=()=>[...n.querySelectorAll(hd)];(s()[0]??n).focus();let c=e=>{if(gd.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),gd.splice(gd.indexOf(o),1),a(),i?.focus()}},[t,e])},vd=({title:e,description:t,onClose:n,actions:r,children:i,wide:a=!1})=>{let o=(0,I.useRef)(null);return _d(o,!0,n),(0,B.jsx)(`div`,{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:o,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})]})})},yd=(e,t)=>t>=60&&t>Math.abs(e),bd=({title:e,open:t,onClose:n,children:r})=>{let i=(0,I.useRef)(null),a=(0,I.useRef)(void 0);return _d(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=yd(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":Ju(`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)(Ls,{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},xd=({title:e,description:t,open:n,onClose:r,actions:i,children:a,wide:o})=>{let s=dd();return n?s?(0,B.jsx)(vd,{title:e,description:t,onClose:r,actions:i,wide:o,children:a}):(0,B.jsx)(bd,{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},Sd=Date.UTC(2026,9,6,9,41),Cd=(e,t)=>{let n=(e^Math.imul(t+2654435769,2246822507))>>>0;return n=Math.imul(n^n>>>16,2246822507),n=Math.imul(n^n>>>13,3266489909),(n^n>>>16)>>>0},wd=(e,t)=>{let n=Cd(e,t);return()=>{n=n+1831565813>>>0;let e=n;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}},Td=[{id:`u1`,name:`Sanne M.`,initials:`SM`,hue:250,role:`Admin`},{id:`u2`,name:`Jonas K.`,initials:`JK`,hue:160,role:`Sales`},{id:`u3`,name:`Lieke D.`,initials:`LD`,hue:20,role:`Finance`},{id:`u4`,name:`Tobias R.`,initials:`TR`,hue:310,role:`Warehouse`},{id:`u5`,name:`Imke V.`,initials:`IV`,hue:200,role:`Sales`},{id:`u6`,name:`Marek W.`,initials:`MW`,hue:80,role:`Warehouse`},{id:`u7`,name:`Hanna B.`,initials:`HB`,hue:350,role:`Finance`},{id:`u8`,name:`Daan P.`,initials:`DP`,hue:120,role:`Sales`}],Ed=e=>Td.find(t=>t.id===e)??Td[0];Td.filter(e=>e.role===`Sales`);var Dd=[[`M8 hex bolt A2, 100 pcs`,`FST`,1890],[`M10 hex nut A2, 100 pcs`,`FST`,1240],[`Stainless washer 8 mm, 250 pcs`,`FST`,990],[`Cable tie 300 mm, 100 pcs`,`ELC`,650],[`Cable gland M20, 25 pcs`,`ELC`,2340],[`Junction box IP65`,`ELC`,1480],[`Hydraulic hose 1/2 in, 5 m`,`HYD`,8650],[`Hydraulic coupling 3/8 in`,`HYD`,1895],[`Pallet wrap 500 mm`,`PKG`,740],[`Corrugated box 400 x 300`,`PKG`,215],[`Bubble wrap roll 50 m`,`PKG`,1990],[`Safety gloves, size L`,`PPE`,395],[`Safety glasses, clear`,`PPE`,450],[`Ear defenders SNR 31`,`PPE`,1295],[`Ball bearing 6204-2RS`,`BRG`,685],[`Taper roller bearing 30205`,`BRG`,1420],[`Timing belt HTD 5M, 600 mm`,`BLT`,2780],[`V-belt SPA 1250`,`BLT`,1360],[`Grease cartridge, 400 g`,`LUB`,920],[`Machine oil ISO 68, 5 l`,`LUB`,3950],[`Angle grinder disc 125 mm, 10 pcs`,`ABR`,1880],[`Drill bit set HSS, 19 pcs`,`TLS`,3490],[`Torque wrench 20-100 Nm`,`TLS`,14900],[`Pneumatic cylinder 40 x 100`,`PNE`,6120],[`Air hose PU 8 mm, 20 m`,`PNE`,2475],[`LED panel 600 x 600, 40 W`,`LGT`,3290],[`Pallet label roll 100 x 150`,`LBL`,1175],[`Thermal printer ribbon`,`LBL`,890],[`Euro pallet EPAL, used`,`PLT`,1150],[`Roll container, galvanised`,`PLT`,9800]];Dd.length;var Od=e=>{let[t,n,r]=Dd[e%Dd.length],i=e%Dd.length;return{id:`P-${200+i}`,sku:`${n}-${String(1e3+i*7).padStart(4,`0`)}`,name:t,category:n,priceCents:r}},kd=e=>e.quantity*e.unitPriceCents,Ad=(e,t=.21)=>{let n=e.reduce((e,t)=>e+kd(t),0),r=Math.round(n*t);return{subtotalCents:n,vatCents:r,totalCents:n+r}},jd=864e5,Md=e=>Array.from({length:e},(t,n)=>{let r=Sd-(e-1-n)*jd,i=new Date(r).getUTCDay();return{at:r,count:Math.round((i===0||i===6?120:410)*(.8+wd(71,n)()*.45)*(1+n/e/3))}}),Nd=e=>{if(e===`day`)return Md(30);let t=Md(84);return Array.from({length:12},(e,n)=>{let r=t.slice(n*7,n*7+7);return{at:r[0].at,count:r.reduce((e,t)=>e+t.count,0)}})},Pd=`grid grid-cols-[28px_minmax(0,1fr)_88px_112px_112px_32px] items-center gap-2 pointer-coarse:grid-cols-[44px_minmax(0,1fr)_88px_112px_112px_44px]`,Fd=new Map,Id=(e,t)=>{let n=Ie(),r=`${n}|${e}`;return Fd.has(r)||Fd.set(r,t(n)),Fd.get(r)},Ld=(e,t)=>Id(`money:${e}:${t??``}`,n=>new Intl.NumberFormat(n,{style:`currency`,currency:e,...t!==void 0&&{minimumFractionDigits:t,maximumFractionDigits:t}})),Rd=(e,t=`EUR`,n)=>Ld(t,n).format(e/100),zd=M({en:{rows:(e,t)=>`${e} ${t?`row`:`rows`}`,aboutRows:e=>`about ${e} rows`,secondsAgo:e=>`${e} s ago`,minutesAgo:e=>`${e} min ago`,hoursAgo:e=>`${e} h ago`,daysAgo:e=>`${e} d ago`,justNow:`just now`},nl:{rows:(e,t)=>`${e} ${t?`rij`:`rijen`}`,aboutRows:e=>`ongeveer ${e} rijen`,secondsAgo:e=>`${e} s geleden`,minutesAgo:e=>`${e} min geleden`,hoursAgo:e=>`${e} u geleden`,daysAgo:e=>`${e} d geleden`,justNow:`zojuist`}}),Bd=()=>Id(`grouped`,e=>new Intl.NumberFormat(e)),Vd=e=>Bd().format(e),Hd=e=>e>0?`+${Bd().format(e)}`:Bd().format(e).replace(`-`,`−`),Ud=e=>`${e}%`,Wd=e=>{if(e<1e4)return zd(`rows`,Vd(e),e===1);let t=10**(Math.floor(Math.log10(e))-3);return zd(`aboutRows`,Vd(Math.round(e/t)*t))},Gd=()=>Intl.DateTimeFormat().resolvedOptions().timeZone,Kd=new Map,qd=e=>{let t=Kd.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 Kd.set(e,n),n},Jd=(e,t)=>{let n=Object.fromEntries(qd(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)}},Yd=(e,t)=>{let n=Jd(e,t);return Date.UTC(n.year,n.month-1,n.day,n.hour,n.minute,n.second)-Math.floor(e/1e3)*1e3},Xd=e=>String(e).padStart(2,`0`),Zd=(e,t)=>{let n=Jd(e,t);return`${n.year}-${Xd(n.month)}-${Xd(n.day)}`},Qd=(e,t)=>e-Yd(e-Yd(e,t),t),$d=(e,t)=>Qd(Date.parse(`${e}T00:00:00Z`),t),ef=(e,t)=>{let n=Id(`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})`},tf=(e,t)=>()=>Id(`date:${e}`,e=>new Intl.DateTimeFormat(e,{...t,timeZone:`UTC`})),nf=tf(`day`,{day:`numeric`,month:`short`,year:`numeric`}),rf=tf(`dayShort`,{day:`numeric`,month:`short`}),af=tf(`month`,{month:`long`,year:`numeric`}),of=tf(`monthName`,{month:`long`}),sf=tf(`weekday`,{weekday:`short`}),cf=tf(`weekdayDate`,{weekday:`long`,day:`numeric`,month:`short`,year:`numeric`}),lf=e=>nf().format(e),uf=e=>rf().format(e),df=e=>Id(`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})})),ff=(e,t=Gd())=>{let n=df(t);return`${n.day.format(e)}, ${n.time.format(e)}`},pf=e=>af().format(e),mf=e=>of().format(e),hf=(e,t)=>af().formatRange(e,t),gf=e=>sf().format(e),_f=e=>cf().format(e),vf=(e,t)=>nf().formatRange(e,t),yf=(e,t=Gd())=>df(t).time.format(e),bf=e=>e<60?zd(`secondsAgo`,e):e<3600?zd(`minutesAgo`,Math.floor(e/60)):e<86400?zd(`hoursAgo`,Math.floor(e/3600)):zd(`daysAgo`,Math.floor(e/86400)),xf=()=>Id(`relative`,e=>new Intl.RelativeTimeFormat(e,{numeric:`auto`})),Sf=[[`year`,31536e3],[`month`,2592e3],[`day`,86400],[`hour`,3600],[`minute`,60]],Cf=e=>{let t=Math.abs(e),[n,r]=Sf.find(([,e])=>t>=e)??[`second`,1];return n===`second`&&t<45?zd(`justNow`):xf().format(-Math.sign(e)*Math.floor(t/r),n)},wf=({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)(Ki,{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))})]})},Tf=({value:e,onCommit:t,format:n,parse:r,label:i,width:a=`w-full`})=>{let[o,s]=(0,I.useState)(null);return(0,B.jsx)(`input`,{"aria-label":i,inputMode:`decimal`,value:o??n(e),onFocus:e=>e.currentTarget.select(),onChange:e=>s(e.target.value),onBlur:()=>{if(o===null)return;let e=r(o);s(null),Number.isFinite(e)&&e>=0&&t(e)},onKeyDown:e=>e.key===`Enter`&&e.currentTarget.blur(),className:P(`h-7 rounded-md border border-transparent bg-transparent px-2 text-right tabular-nums text-foreground outline-none hover:border-border-strong focus:border-primary focus:bg-background focus:ring-2 focus:ring-primary/20`,a)})},Ef=M({en:{instructions:`To pick up a line, press space or enter on its drag handle. Use the up and down arrow keys to move it, space or enter to drop it, and escape to cancel. The row menu also has Move up and Move down.`,line:`line`,pickedUp:(e,t,n)=>`Picked up ${e}, line ${t} of ${n}.`,over:(e,t,n)=>`${e} is over line ${t} of ${n}.`,dropped:(e,t,n)=>`${e} was dropped at line ${t} of ${n}.`,droppedAtStart:e=>`${e} was dropped where it started.`,cancelled:(e,t)=>`Moving ${e} was cancelled. It is back at line ${t}.`,item:`Item`,qty:`Qty`,quantity:`Quantity`,unitPrice:`Unit price`,lineTotal:`Line total`,addLine:`Add line`,moveUp:`Move up`,moveDown:`Move down`,removeLine:`Remove line`,dragToReorder:e=>`Drag to reorder ${e}`,actionsFor:e=>`Actions for ${e}`,subtotal:`Subtotal`,vat:e=>`VAT ${e}%`,total:`Total`},nl:{instructions:`Druk op spatie of enter op de sleepgreep om een regel op te pakken. Verplaats hem met de pijltjestoetsen omhoog en omlaag, zet hem neer met spatie of enter, en annuleer met escape. Het regelmenu heeft ook Omhoog en Omlaag.`,line:`regel`,pickedUp:(e,t,n)=>`${e} opgepakt, regel ${t} van ${n}.`,over:(e,t,n)=>`${e} is boven regel ${t} van ${n}.`,dropped:(e,t,n)=>`${e} is neergezet op regel ${t} van ${n}.`,droppedAtStart:e=>`${e} is neergezet waar hij begon.`,cancelled:(e,t)=>`Verplaatsen van ${e} is geannuleerd. Hij staat weer op regel ${t}.`,item:`Artikel`,qty:`Aantal`,quantity:`Aantal`,unitPrice:`Stukprijs`,lineTotal:`Regeltotaal`,addLine:`Regel toevoegen`,moveUp:`Omhoog`,moveDown:`Omlaag`,removeLine:`Regel verwijderen`,dragToReorder:e=>`Sleep om ${e} te verplaatsen`,actionsFor:e=>`Acties voor ${e}`,subtotal:`Subtotaal`,vat:e=>`Btw ${e}%`,total:`Totaal`}}),Df=e=>Math.round(Number(e.replace(`,`,`.`).replace(/[^0-9.]/g,``))*100),Of=({line:e,position:t,count:n,reorderable:r,editable:i,onChange:a,onRemove:o,onMove:s})=>{let{attributes:c,listeners:l,setNodeRef:u,setActivatorNodeRef:d,transform:f,transition:p,isDragging:m}=w({id:e.id,disabled:!r}),h=[...r?[{label:Ef(`moveUp`),disabled:t===0,onSelect:()=>s(t-1)},{label:Ef(`moveDown`),disabled:t===n-1,onSelect:()=>s(t+1)}]:[],...i?[{label:Ef(`removeLine`),destructive:!0,onSelect:o}]:[]];return(0,B.jsxs)(`div`,{ref:u,"data-line-id":e.id,style:{transform:f?`translate3d(0, ${f.y}px, 0)`:void 0,transition:p},className:P(`group relative border-b border-border bg-background px-2 py-1 last:border-b-0 hover:bg-surface`,Pd,m&&`z-10 bg-surface opacity-80 shadow-pop`),children:[r?(0,B.jsx)(`button`,{ref:d,type:`button`,"aria-label":Ef(`dragToReorder`,e.description),...c,...l,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)(oa,{className:`size-4`})}):(0,B.jsx)(`span`,{}),(0,B.jsxs)(`div`,{className:`min-w-0`,children:[(0,B.jsx)(`p`,{className:`truncate text-foreground`,children:e.description}),(0,B.jsx)(`p`,{className:`font-mono text-[11px] text-faint-foreground`,children:e.productId})]}),i?(0,B.jsx)(Tf,{label:Ef(`quantity`),value:e.quantity,format:String,parse:e=>Math.round(Number(e)),onCommit:e=>a({quantity:e})}):(0,B.jsx)(`span`,{className:`px-2 text-right tabular-nums`,children:e.quantity}),i?(0,B.jsx)(Tf,{label:Ef(`unitPrice`),value:e.unitPriceCents,format:e=>(e/100).toFixed(2),parse:Df,onCommit:e=>a({unitPriceCents:e})}):(0,B.jsx)(`span`,{className:`px-2 text-right tabular-nums`,children:(e.unitPriceCents/100).toFixed(2)}),(0,B.jsx)(`span`,{className:`px-2 text-right font-medium tabular-nums text-foreground`,children:Rd(kd(e))}),h.length>0?(0,B.jsx)(wf,{label:Ef(`actionsFor`,e.description),items:h}):(0,B.jsx)(`span`,{})]})},kf=(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},Af=({lines:e,vatRate:t})=>{let n=Ad(e,t);return(0,B.jsxs)(`dl`,{className:`ml-auto grid w-64 grid-cols-[1fr_auto] gap-x-6 gap-y-1 px-2 pt-3 tabular-nums`,children:[(0,B.jsx)(`dt`,{className:`text-muted-foreground`,children:Ef(`subtotal`)}),(0,B.jsx)(`dd`,{className:`text-right text-foreground`,children:Rd(n.subtotalCents)}),(0,B.jsx)(`dt`,{className:`text-muted-foreground`,children:Ef(`vat`,Math.round(t*100))}),(0,B.jsx)(`dd`,{className:`text-right text-foreground`,children:Rd(n.vatCents)}),(0,B.jsx)(`dt`,{className:`mt-1 border-t border-border pt-2 font-semibold text-foreground`,children:Ef(`total`)}),(0,B.jsx)(`dd`,{className:`mt-1 border-t border-border pt-2 text-right text-[16px] font-semibold text-foreground`,children:Rd(n.totalCents)})]})},jf=`px-2 text-[11px] font-medium uppercase tracking-wide text-muted-foreground`,Mf=e=>{let t=t=>e.find(e=>e.id===t)?.description??Ef(`line`),n=t=>e.findIndex(e=>e.id===t)+1;return{onDragStart:({active:r})=>Ef(`pickedUp`,t(r.id),n(r.id),e.length),onDragOver:({active:r,over:i})=>i?Ef(`over`,t(r.id),n(i.id),e.length):void 0,onDragEnd:({active:r,over:i})=>i?Ef(`dropped`,t(r.id),n(i.id),e.length):Ef(`droppedAtStart`,t(r.id)),onDragCancel:({active:e})=>Ef(`cancelled`,t(e.id),n(e.id))}},Nf=({lines:e,onChange:t,onReorder:n,vatRate:r=.21,readOnly:i,reorderable:o=!i})=>{let s=S(g(a,{activationConstraint:{distance:4}}),g(de,{activationConstraint:{delay:250,tolerance:5}}),g(fe,{coordinateGetter:ke})),u=(r,i)=>{let a=e[r];!a||i<0||i>=e.length||r===i||(n??(e=>t(e)))(kf(e,r,i),{id:a.id,from:r,to:i})};return(0,B.jsxs)(`div`,{children:[(0,B.jsxs)(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:[(0,B.jsxs)(`div`,{className:`${Pd} border-b border-border bg-surface px-2 py-2`,children:[(0,B.jsx)(`span`,{}),(0,B.jsx)(`span`,{className:jf,children:Ef(`item`)}),(0,B.jsx)(`span`,{className:`${jf} text-right`,children:Ef(`qty`)}),(0,B.jsx)(`span`,{className:`${jf} text-right`,children:Ef(`unitPrice`)}),(0,B.jsx)(`span`,{className:`${jf} text-right`,children:Ef(`lineTotal`)}),(0,B.jsx)(`span`,{})]}),(0,B.jsx)(c,{sensors:s,collisionDetection:_,onDragEnd:({active:t,over:n})=>{n&&t.id!==n.id&&u(e.findIndex(e=>e.id===t.id),e.findIndex(e=>e.id===n.id))},accessibility:{announcements:Mf(e),screenReaderInstructions:{draggable:Ef(`instructions`)}},children:(0,B.jsx)(C,{items:e.map(e=>e.id),strategy:l,children:e.map((n,r)=>(0,B.jsx)(Of,{line:n,position:r,count:e.length,reorderable:o,editable:!i,onChange:r=>t(e.map(e=>e.id===n.id?{...e,...r}:e)),onRemove:()=>t(e.filter(e=>e.id!==n.id)),onMove:e=>u(r,e)},n.id))})}),!i&&(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:()=>{let n=Od(e.length*3+1);t([...e,{id:`new-${e.length}-${n.id}`,productId:n.id,description:n.name,quantity:1,unitPriceCents:n.priceCents}])},children:[(0,B.jsx)(_o,{className:`size-3.5`}),Ef(`addLine`)]})})]}),(0,B.jsx)(Af,{lines:e,vatRate:r})]})},K=({className:e})=>(0,B.jsx)(`span`,{className:P(`block h-3 rounded bg-muted [animation:pb-shimmer_1.4s_ease-in-out_infinite]`,e)}),Pf=M({en:{navigation:`Navigation`,resources:`Resources`,breadcrumb:`Breadcrumb`,tabs:`Tabs`,more:`More`,openNavigation:`Open navigation`,backTo:e=>`Back to ${e}`,search:`Search`,closeSearch:`Close search`,clearSearch:`Clear search`,globalSearch:`Global search`,searchResults:`Search results`,searching:`Searching`,noMatches:e=>`No matches for “${e}”`,profileMenu:`Profile menu`,organizations:`Organizations`,roles:`Roles`,signIn:`Sign in`,signOut:`Sign out`,theme:`Theme`,light:`Light`,dark:`Dark`,system:`System`,recent:e=>`Recent ${e}`,loading:`Loading...`,couldNotLoad:`Could not load`,viewAll:`View all`,couldNotSearch:e=>`Could not search ${e.toLowerCase()}`},nl:{navigation:`Navigatie`,resources:`Onderdelen`,breadcrumb:`Kruimelpad`,tabs:`Tabbladen`,more:`Meer`,openNavigation:`Navigatie openen`,backTo:e=>`Terug naar ${e}`,search:`Zoeken`,closeSearch:`Zoeken sluiten`,clearSearch:`Zoekopdracht wissen`,globalSearch:`Overal zoeken`,searchResults:`Zoekresultaten`,searching:`Zoeken`,noMatches:e=>`Niets gevonden voor “${e}”`,profileMenu:`Profielmenu`,organizations:`Organisaties`,roles:`Rollen`,signIn:`Inloggen`,signOut:`Uitloggen`,theme:`Thema`,light:`Licht`,dark:`Donker`,system:`Systeem`,recent:e=>`Recente ${e}`,loading:`Laden...`,couldNotLoad:`Kon niet laden`,viewAll:`Alles bekijken`,couldNotSearch:e=>`Kon niet zoeken in ${e.toLowerCase()}`}}),Ff=e=>e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey,If=({parts:e,onNavigate:t})=>(0,B.jsx)(`nav`,{"aria-label":Pf(`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)(K,{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)(gi,{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&&Ff(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}`)})}),Lf=M({en:{dismiss:`Dismiss`},nl:{dismiss:`Sluiten`}}),Rf=`-my-0.5 rounded px-1.5 py-0.5 font-medium text-primary-text hover:bg-primary-soft`,zf=({action:e})=>{if(`onClick`in e)return(0,B.jsx)(`button`,{type:`button`,onClick:e.onClick,className:Rf,children:e.label});let{href:t,onNavigate:n}=e;return(0,B.jsx)(`a`,{href:t,onClick:e=>{n&&Ff(e)&&(e.preventDefault(),n(t))},className:Rf,children:e.label})},Bf={loading:(0,B.jsx)(Yu,{className:`text-primary`}),success:(0,B.jsx)(Si,{className:`size-4 text-success`}),warning:(0,B.jsx)(ys,{className:`size-4 text-warning`}),error:(0,B.jsx)(Ei,{className:`size-4 text-danger`}),info:(0,B.jsx)(Do,{className:`size-4 text-primary`})},Vf=({state:e,title:t,description:n,action:r,onDismiss:i})=>(0,B.jsxs)(`div`,{role:e===`error`?`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:Bf[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)(zf,{action:r}),i&&(0,B.jsx)(`button`,{type:`button`,"aria-label":Lf(`dismiss`),onClick:i,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)(Ls,{className:`size-3.5`})})]}),Hf={loading:1/0,success:3500,warning:8e3,error:8e3,info:8e3},Uf=8e3,Wf=(0,I.createContext)(null),Gf=()=>{let e=(0,I.useContext)(Wf);if(!e)throw Error(`useToast must be used inside ToastProvider`);return e},Kf=({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?Uf:Hf[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)(Wf.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)(Vf,{state:e.state,title:e.title,description:e.description,action:e.action,onDismiss:()=>c(e)})},e.id))})]})},qf=M({en:{savedDifferent:e=>`${e} saved a different value`,example:`Example:`,savedThis:e=>`saved this ${e}:`,keepMine:`Keep mine`,useTheirs:`Use theirs`,actions:`Actions`,saving:`Saving...`,savedAgo:e=>`Saved ${e}`,notSavedRetrying:`Not saved, retrying`,lastEditedBy:`Last edited by`,lastUpdated:e=>`Last updated ${e}`,viewing:e=>`${e} viewing`,savingSubject:e=>`Saving ${e}...`,subjectSaved:e=>`${e} saved`,tabs:`Tabs`},nl:{savedDifferent:e=>`${e} bewaarde een andere waarde`,example:`Voorbeeld:`,savedThis:e=>`bewaarde dit ${e}:`,keepMine:`Mijn waarde houden`,useTheirs:`Hun waarde gebruiken`,actions:`Acties`,saving:`Bewaren...`,savedAgo:e=>`Bewaard ${e}`,notSavedRetrying:`Niet bewaard, opnieuw proberen`,lastEditedBy:`Laatst bewerkt door`,lastUpdated:e=>`Laatst bijgewerkt ${e}`,viewing:e=>`${e} kijken mee`,savingSubject:e=>`${e} bewaren...`,subjectSaved:e=>`${e} bewaard`,tabs:`Tabbladen`}}),Jf=(0,I.createContext)(void 0),Yf=()=>{let e=(0,I.useContext)(Jf);return e?{id:e.id,name:e.name,"aria-describedby":e.describedBy,"aria-invalid":e.invalid||void 0,"aria-required":e.required||void 0}:{}},Xf=({leading:e,trailing:t,invalid:n,className:r,wrapperClassName:i,...a})=>{let o=Yf();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]})},Zf={xs:`size-5 text-[9px]`,sm:`size-6 text-[10px]`,md:`size-8 text-xs`},Qf=({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`,Zf[n],r),style:{background:`oklch(0.58 0.13 ${t})`},children:e}),$f=({people:e,size:t=`sm`})=>(0,B.jsx)(`span`,{className:`inline-flex -space-x-1`,children:e.map(e=>(0,B.jsx)(Qf,{...e,size:t},e.initials))}),ep=({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:qf(`savedDifferent`,o.user.name),children:[(0,B.jsx)(ys,{className:`size-3.5`}),(0,B.jsx)(Qf,{initials:o.user.initials,hue:o.user.hue,size:`xs`})]})]}),(0,B.jsx)(Jf,{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:[qf(`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}),` `,qf(`savedThis`,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:qf(`keepMine`)}),(0,B.jsx)(G,{size:`sm`,onClick:o.onUseTheirs,children:qf(`useTheirs`)})]})]})]})},tp=({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]})},np=({title:e,help:t,actions:n,children:r})=>(0,B.jsx)(`section`,{className:`py-8 first:pt-8`,children:(0,B.jsx)(tp,{title:e,help:t,actions:n,children:r})}),rp=`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`,ip=({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:qf(`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:rp,children:c}):(0,B.jsx)(`button`,{type:`button`,onClick:r,disabled:!!i||a,title:i,className:rp,children:c})},e)})})]}),ap=({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))}),op=({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]}),sp=({title:e,rows:t})=>t.length===0?null:(0,B.jsx)(op,{title:e,children:(0,B.jsx)(ap,{rows:t})}),cp=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},lp=`#ffffff`,up=`#111827`,dp=e=>{let t=cp(e);return 1.05/(t+.05)>=(t+.05)/(cp(up)+.05)?lp:up},fp={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`},pp={neutral:`bg-faint-foreground`,blue:`bg-primary`,green:`bg-success`,amber:`bg-warning`,red:`bg-danger`,violet:`bg-violet`},mp=`polygon(0 0, calc(100% - 0.625rem) 0, 100% 50%, calc(100% - 0.625rem) 100%, 0 100%)`,hp=({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:dp(n)},...r===`arrow`&&{clipPath:mp}},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&&fp[e],a),children:[t&&n===void 0&&r===void 0&&(0,B.jsx)(`span`,{className:P(`size-1.5 rounded-full`,pp[e])}),i]}),gp=({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)(hp,{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:[qf(`lastEditedBy`),` `,(0,B.jsx)(`span`,{className:`font-medium text-foreground`,children:r.name}),` `,r.ago]}):(0,B.jsx)(B.Fragment,{children:qf(`lastUpdated`,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)($f,{people:i,size:`md`}),qf(`viewing`,i.length)]}),a]})]}),_p=M({en:{yes:`Yes`,no:`No`,shownIn:e=>`Shown in ${e}`,fileMissing:`File missing`},nl:{yes:`Ja`,no:`Nee`,shownIn:e=>`Getoond in ${e}`,fileMissing:`Bestand ontbreekt`}}),vp=e=>typeof e==`object`&&!!e&&typeof e.uri==`string`,yp=e=>typeof e==`object`&&!!e&&typeof e.uploaded?.value==`string`,bp=e=>{if(yp(e))return{...e.uploaded.file,...e.preview&&{url:e.preview},corrected:e.uploaded.corrected};if(vp(e))return`missing`in e?{name:_p(`fileMissing`),type:``,missing:!0}:e},xp=[`bytes`,`kB`,`MB`,`GB`],Sp=e=>{let t=e,n=0;for(;t>=1e3&&n<xp.length-1;)t/=1e3,n+=1;return n===0?`${e} ${e===1?`byte`:`bytes`}`:`${t<10?t.toFixed(1):Math.round(t)} ${xp[n]}`},Cp=e=>e.startsWith(`image/`)&&e!==`image/svg+xml`,wp=2,Tp=1e5,Ep=(e,t)=>(e.width!==void 0||e.height!==void 0)&&(e.width??Tp)>=t.width*wp&&(e.height??Tp)>=t.height*wp,Dp=e=>(e.width??Tp)*(e.height??Tp),Op=(e,t)=>{let n=bp(e);if(!(!n||`missing`in n||!n.url||!Cp(n.type)))return{url:(`variants`in n&&n.variants?Object.values(n.variants):[]).filter(e=>Ep(e,t)).sort((e,t)=>Dp(e)-Dp(t))[0]?.url??n.url,...`placeholder`in n&&n.placeholder!==void 0&&{placeholder:n.placeholder}}},kp=e=>{let t=e.file?.accept??[];return t.length===0||t.includes(`*/*`)?void 0:t.join(`,`)},Ap=e=>yp(e)?e.uploaded.value:vp(e)?e.uri:null,jp=(e,t)=>{if(yp(e))return!0;let n=e=>vp(e)?e.uri:null;return n(e)!==n(t)},Mp=M({en:{unsortable:`This column can't be sorted`,columnMenu:e=>`${e} column menu`,unpin:`Unpin`,pinToLeft:`Pin to left`,resizeColumn:e=>`Resize ${e} column`,selected:e=>`${e} selected`,no:`No`,shownIn:e=>`Shown in ${e}`,new:`New`,clearSelection:`Clear selection`,noRowsSelected:`No rows selected`,selectRow:e=>`Select row ${e}`,rowActions:`Row actions`,row:`row`,move:e=>`Move ${e}`,reorderInstructions:`To move a row, press Space on its handle, move it with the up and down arrow keys, and press Space again to drop it there. Escape puts it back.`,pickedUp:(e,t,n)=>`Picked up ${e}, row ${t} of ${n}.`,isOver:(e,t,n)=>`${e} is over row ${t} of ${n}.`,droppedAt:(e,t,n)=>`${e} was dropped at row ${t} of ${n}.`,putBack:e=>`${e} was put back.`,cancelled:(e,t)=>`Moving ${e} was cancelled. It is back at row ${t}.`},nl:{unsortable:`Op deze kolom kan niet worden gesorteerd`,columnMenu:e=>`Kolommenu ${e}`,unpin:`Losmaken`,pinToLeft:`Links vastzetten`,resizeColumn:e=>`Breedte kolom ${e}`,selected:e=>`${e} geselecteerd`,no:`Nee`,shownIn:e=>`Getoond in ${e}`,new:`Nieuw`,clearSelection:`Selectie wissen`,noRowsSelected:`Geen rijen geselecteerd`,selectRow:e=>`Rij ${e} selecteren`,rowActions:`Rijacties`,row:`rij`,move:e=>`${e} verplaatsen`,reorderInstructions:`Om een rij te verplaatsen, druk op Spatie op de greep, verplaats hem met de pijltjestoetsen omhoog en omlaag, en druk nogmaals op Spatie om hem daar neer te zetten. Escape zet hem terug.`,pickedUp:(e,t,n)=>`${e} opgepakt, rij ${t} van ${n}.`,isOver:(e,t,n)=>`${e} is boven rij ${t} van ${n}.`,droppedAt:(e,t,n)=>`${e} is neergezet op rij ${t} van ${n}.`,putBack:e=>`${e} is teruggezet.`,cancelled:(e,t)=>`Verplaatsen van ${e} is geannuleerd. Hij staat weer op rij ${t}.`}}),Np=e=>typeof e==`object`&&e&&`name`in e?String(e.name):String(e),Pp=(e,t)=>{if(t==null)return`—`;switch(e.kind){case`text`:case`id`:return String(t);case`money`:return`${Rd(Number(t),e.currency,e.decimals)}${e.suffix??``}`;case`date`:return lf(Number(t));case`datetime`:return e.relative?Cf(Math.round((Date.now()-Number(t))/1e3)):ff(Number(t));case`number`:return`${Vd(Number(t))}${e.suffix??``}`;case`signed`:return`${Hd(Number(t))}${e.suffix??``}`;case`percent`:return Number(t)===0?`—`:Ud(Number(t));case`status`:return tr(String(t),e.labels);case`relation`:return Np(t);case`boolean`:return t?void 0:Mp(`no`);case`file`:return bp(t)?.name??`—`;case`user`:return Ed(String(t)).name}},Fp=(e,t)=>Math.ceil(e.length*7.2)+24+(t?16:0)+28,Ip=e=>Math.ceil(Math.max(0,...e.map(e=>e.length))*7.2)+56,Lp={body:7.5,mono:7.2,numeric:8},Rp=24,zp=24,Bp=16,Vp=new Set([`status`,`money`,`number`,`signed`,`percent`,`date`,`datetime`,`boolean`]),Hp=new Set([`money`,`number`,`signed`,`percent`,`date`,`datetime`]),Up=80,Wp=400,Gp=240,Kp=e=>e===`id`?Lp.mono:Hp.has(e)?Lp.numeric:Lp.body,qp=(e,t)=>e.value?e.value(t):t[e.id],Jp=(e,t)=>{let n=t.map(t=>Pp(e,qp(e,t)));if(e.kind===`status`)return Ip(n.map(e=>e??``));let r=e.kind===`user`||e.kind===`file`?zp:0;return Math.max(0,...n.map(t=>t===void 0?Bp:Math.ceil(t.length*Kp(e.kind))))+r+Rp},Yp=(e,t,n)=>Math.min(n,Math.max(t,e)),Xp=(e,t)=>{if(Vp.has(e.kind)&&!e.title)return{...e,fixed:!0,width:Math.max(e.minWidth??0,t)};let n={...e,fixed:!1,width:Yp(t,Up,Wp)};return e.kind===`id`?{...n,minWidth:Math.max(Fp(e.header,e.sortable??!1),Math.min(t,Gp))}:n},Zp=(e,t)=>{if(t.length===0)return e;let n=e.map(e=>e.render?e:Xp(e,Jp(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)},Qp=e=>e.charAt(0).toUpperCase()+e.slice(1),$p=[[/^\s*(```|~~~).*$/,``],[/^\s*\[[^\]]+\]:\s+\S.*$/,``],[/^\s*([-*_]\s*){3,}$/,``],[/^\s*\|?(\s*:?-+:?\s*\|)+\s*:?-*:?\s*$/,``],[/^\s*#{1,6}\s+/,``],[/^\s*(>\s?)+/,``],[/^\s*([-*+]|\d+[.)])\s+(\[[ xX]\]\s+)?/,``]],em=[[/!\[([^\]]*)\]\([^)]*\)/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`]],tm=200,nm=e=>{let t=e.split(/\r?\n/).map(e=>$p.reduce((e,[t,n])=>e.replace(t,n),e)),n=em.reduce((e,[t,n])=>e.replace(t,n),t.join(`
|
|
4
|
-
`)).replace(/\s+/g,` `).trim();return n.length>tm?`${n.slice(0,199).trimEnd()}…`:n},rm=(e,t)=>e.type===`text`&&!!t?.markdown,im=(e,t,n)=>{let r=t[n];return e.fields[n]?.type===`relation`&&typeof r==`object`&&r&&`id`in r?r.id:r},am=(e,t)=>e.primaryKey.map(n=>String(im(e,t,n))).join(`,`),om=(e,t)=>{let n=e.primaryKey.map(n=>im(e,t,n));return n.length===1?n[0]:n},sm=new Set([`email`,`phone`,`url`]),cm=e=>e?.format!==void 0&&sm.has(e.format)?e.format:void 0,lm=(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},um=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`}:{},dm={draft:`neutral`,confirmed:`blue`,picking:`amber`,shipped:`violet`,delivered:`green`,cancelled:`red`,sent:`blue`,paid:`green`,overdue:`red`,lead:`blue`,active:`green`,dormant:`neutral`,receipt:`green`,issue:`blue`,transfer:`violet`,adjustment:`amber`},fm=e=>dm[e]??`neutral`,pm={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},mm=new Set([`datetime`,`date`,`boolean`,`percent`]),hm=/^(number|sku|reference|code)$/,gm=(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?.prefix===`€`?`money`:`number`;case`integer`:case`bigint`:return/quantity|delta/.test(e.name)?`signed`:`number`;default:return hm.test(e.name)||n===0&&e.name===`id`?`id`:`text`}},_m=e=>Math.round(Number.parseFloat(String(e))*100),vm=(e,t,n=[],r=mr(e,t))=>{let i=ar(e,t);return r.flatMap((r,a)=>{let o=e.fields[r];if(!o)return[];let s=t?.fields[r],c=gm(o,s,a),l=Object.fromEntries((o.enumValues??[]).map(e=>[e,tr(e,s?.valueLabels)])),u=s?.suffix?Math.ceil(s.suffix.length*7.2):0;return[{id:r,header:s?.label??F(r),kind:c,width:(r===`name`?260:pm[c])+u,sortable:o.sortable,minWidth:Math.max(c===`id`?150:0,Fp(s?.label??F(r),o.sortable),c===`status`?Ip(Object.values(l)):0,u>0?pm[c]+u:0),...mm.has(c)&&{fixed:!0},...r===i&&{title:!0},...c===`text`&&r!==i&&cm(s)&&{link:cm(s)},...n.includes(r)&&{highlight:!0},...o.type===`enum`&&{tones:Object.fromEntries((o.enumValues??[]).map(e=>[e,fm(e)])),labels:l},...o.type===`enum`&&s?.valueColors&&{colors:s.valueColors},...o.type===`enum`&&s?.badgeShape&&{shape:s.badgeShape},...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`&&{currency:`EUR`,value:e=>e[r]==null?null:_m(e[r])},...(c===`datetime`||c===`date`)&&{value:e=>e[r]==null?null:Date.parse(String(e[r]))},...rm(o,s)&&{value:e=>typeof e[r]==`string`?nm(e[r]):e[r]},...(c===`percent`||c===`number`&&o.type===`decimal`)&&{value:e=>e[r]==null?null:Number(e[r])}}]})},ym=(e,t)=>`${t.prefix??``}${e}${t.suffix??``}`,bm=(e,t,n={},r=Gd(),i=Date.now())=>{if(t==null||t===``)return`—`;switch(e.type){case`boolean`:return _p(t?`yes`:`no`);case`file`:return bp(t)?.name??`—`;case`enum`:return tr(String(t),n.valueLabels);case`timestamp`:{let e=Date.parse(String(t));return n.format===`relative`?Cf(Math.round((i-e)/1e3)):ff(e,r)}case`date`:return lf(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)}%`:ym(Number(e).toLocaleString(Ie(),{minimumFractionDigits:n.decimals??0,maximumFractionDigits:n.decimals??20}),n)}case`integer`:case`bigint`:return ym(String(t),n);default:return typeof t==`object`?JSON.stringify(t):String(t)}},xm=(e,t,n=Gd(),r={})=>{if(e.type!==`timestamp`||typeof t!=`string`)return;let i=Date.parse(t);if(!Number.isNaN(i))return r.format===`relative`?ff(i,n):_p(`shownIn`,ef(i,n))},Sm=`$photos`,Cm=e=>{for(let t of e?.list?.displays??[])if(t.kind===`cards`&&t.photos)return t.photos},wm=(e,t,n)=>{if(n===void 0||e.primaryKey.length!==1)return t;let r=e.primaryKey[0];return t.map(e=>({...e,[Sm]:n[String(e[r])]??[]}))},Tm=(e,t)=>t.filter(t=>e[t]!==null&&e[t]!==void 0&&e[t]!==``),q=M({en:{table:`Table`,display:`Display`,sort:`Sort`,ascending:`ascending`,descending:`descending`,movedTo:e=>`Moved to ${e}`,orderChanged:`Order changed`,stayedIn:e=>`Saved, still in ${e}`,undo:`Undo`,couldNotUndo:`Could not undo`,couldNotLoadRows:`Could not load rows`,noPlural:e=>`No ${e}`,noValue:e=>`No ${e.toLowerCase()}`,somethingWrong:`Something went wrong`,showMore:`Show more`,noDrop:`No board drop is registered as {}. Give it in boardDrops in protobase.ui.tsx, or load the plugin that provides it.`,noComponent:`No component is registered as {}. Export it from protobase.ui.tsx, or load the plugin that provides it.`,pickedUp:e=>`Picked up ${e}.`,isOver:(e,t)=>`${e} is over ${t}.`,putBack:e=>`${e} was put back.`,wasMovedTo:(e,t)=>`${e} was moved to ${t}.`,cancelled:e=>`Moving ${e} was cancelled.`,startsOn:(e,t)=>`${e} starts on ${t}.`,noColumn:`no column`,noDay:`no day`,placeOf:(e,t,n)=>`${e}, place ${t} of ${n}`,place:(e,t)=>`${e}, place ${t}`,boardAcross:`To move a card to another column, press Space, move it with the left and right arrow keys, and press Space again to drop it there. Escape puts it back.`,boardAnywhere:`To move a card, press Space, move it with the up and down arrow keys within its column and the left and right arrow keys to another column, and press Space again to drop it there. Escape puts it back.`,boardWithin:`To move a card, press Space, move it with the up and down arrow keys within its column, and press Space again to drop it there. Escape puts it back.`,calendarInstructions:`To move an event to another day, press Space, move it a day with the left and right arrow keys or a week with the up and down arrow keys, and press Space again to drop it there. Escape puts it back.`,timelineInstructions:`To move a bar to other days, press Space, move it a day with the left and right arrow keys, and press Space again to drop it there. Escape puts it back.`,week:`Week`,month:`Month`,quarter:`Quarter`,calendarScale:`Calendar scale`,timelineScale:`Timeline scale`,previousPeriod:e=>`Previous ${e}`,nextPeriod:e=>`Next ${e}`,today:`Today`,capped:(e,t)=>`Showing the first ${e} records of this ${t}. Narrow the filter to see the rest.`,nothingIn:e=>`Nothing in this ${e}.`,noneMatch:e=>`No ${e} match.`,list:`List`,showOneApproximate:e=>`Show the ${e}, at an approximate position`,showOne:e=>`Show the ${e}`,showMany:(e,t)=>`Show ${e} ${t}`,showManyApproximate:(e,t)=>`Show ${e} ${t}, at approximate positions`,showManySomeApproximate:(e,t,n)=>`Show ${e} ${t}, ${n} at approximate positions`,zoomIn:(e,t)=>`Zoom in on ${e} ${t}`,needsStyle:`The map display needs a map style: set PROTOBASE_MAP_STYLE_URL.`,noneHere:e=>`No ${e} in this part of the map.`,showAll:`Show all`,chosen:e=>`Chosen ${e}`,approximatePosition:`Approximate position`,previous:`Previous`,next:`Next`,close:`Close`,features:`Features`,couldNotReorder:`Could not change the order`,couldNotMoveTo:e=>`Could not move it to ${e}`,moreHidden:e=>`+${e} more`},nl:{table:`Tabel`,display:`Weergave`,sort:`Sorteren`,ascending:`oplopend`,descending:`aflopend`,movedTo:e=>`Verplaatst naar ${e}`,orderChanged:`Volgorde gewijzigd`,stayedIn:e=>`Opgeslagen, nog in ${e}`,undo:`Ongedaan maken`,couldNotUndo:`Kon niet ongedaan maken`,couldNotLoadRows:`Kon de rijen niet laden`,noPlural:e=>`Geen ${e}`,noValue:e=>`Geen ${e.toLowerCase()}`,somethingWrong:`Er ging iets mis`,showMore:`Meer tonen`,noDrop:`Er is geen bordactie geregistreerd als {}. Geef die in boardDrops in protobase.ui.tsx, of laad de plug-in die haar levert.`,noComponent:`Er is geen component geregistreerd als {}. Exporteer die uit protobase.ui.tsx, of laad de plug-in die haar levert.`,pickedUp:e=>`${e} opgepakt.`,isOver:(e,t)=>`${e} is boven ${t}.`,putBack:e=>`${e} is teruggezet.`,wasMovedTo:(e,t)=>`${e} is verplaatst naar ${t}.`,cancelled:e=>`Verplaatsen van ${e} is geannuleerd.`,startsOn:(e,t)=>`${e} begint op ${t}.`,noColumn:`geen kolom`,noDay:`geen dag`,placeOf:(e,t,n)=>`${e}, plaats ${t} van ${n}`,place:(e,t)=>`${e}, plaats ${t}`,boardAcross:`Druk op Spatie om een kaart naar een andere kolom te verplaatsen, verplaats haar met de pijltjestoetsen links en rechts, en druk nogmaals op Spatie om haar daar neer te zetten. Escape zet haar terug.`,boardAnywhere:`Druk op Spatie om een kaart te verplaatsen, verplaats haar met de pijltjestoetsen omhoog en omlaag binnen haar kolom en met links en rechts naar een andere kolom, en druk nogmaals op Spatie om haar daar neer te zetten. Escape zet haar terug.`,boardWithin:`Druk op Spatie om een kaart te verplaatsen, verplaats haar met de pijltjestoetsen omhoog en omlaag binnen haar kolom, en druk nogmaals op Spatie om haar daar neer te zetten. Escape zet haar terug.`,calendarInstructions:`Druk op Spatie om een gebeurtenis naar een andere dag te verplaatsen, verplaats haar een dag met de pijltjestoetsen links en rechts of een week met omhoog en omlaag, en druk nogmaals op Spatie om haar daar neer te zetten. Escape zet haar terug.`,timelineInstructions:`Druk op Spatie om een balk naar andere dagen te verplaatsen, verplaats hem een dag met de pijltjestoetsen links en rechts, en druk nogmaals op Spatie om hem daar neer te zetten. Escape zet hem terug.`,week:`Week`,month:`Maand`,quarter:`Kwartaal`,calendarScale:`Schaal van de kalender`,timelineScale:`Schaal van de tijdlijn`,previousPeriod:e=>({week:`Vorige week`,month:`Vorige maand`,quarter:`Vorig kwartaal`})[e],nextPeriod:e=>({week:`Volgende week`,month:`Volgende maand`,quarter:`Volgend kwartaal`})[e],today:`Vandaag`,capped:(e,t)=>`De eerste ${e} records van ${{week:`deze week`,month:`deze maand`,quarter:`dit kwartaal`}[t]} worden getoond. Verfijn het filter om de rest te zien.`,nothingIn:e=>`Niets in ${{week:`deze week`,month:`deze maand`,quarter:`dit kwartaal`}[e]}.`,noneMatch:e=>`Geen ${e} gevonden.`,list:`Lijst`,showOneApproximate:e=>`${e} tonen, op een geschatte plek`,showOne:e=>`${e} tonen`,showMany:(e,t)=>`${e} ${t} tonen`,showManyApproximate:(e,t)=>`${e} ${t} tonen, op geschatte plekken`,showManySomeApproximate:(e,t,n)=>`${e} ${t} tonen, ${n} op geschatte plekken`,zoomIn:(e,t)=>`Inzoomen op ${e} ${t}`,needsStyle:`De kaartweergave heeft een kaartstijl nodig: stel PROTOBASE_MAP_STYLE_URL in.`,noneHere:e=>`Geen ${e} in dit deel van de kaart.`,showAll:`Alles tonen`,chosen:e=>`Gekozen ${e}`,approximatePosition:`Geschatte plek`,previous:`Vorige`,next:`Volgende`,close:`Sluiten`,features:`Kenmerken`,couldNotReorder:`Kon de volgorde niet wijzigen`,couldNotMoveTo:e=>`Kon het niet naar ${e} verplaatsen`,moreHidden:e=>`+${e} meer`}}),Em=(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:tr(e,i?.valueLabels)}));return r.nullable?[...a,{value:null,label:q(`noValue`,i?.label??F(n.by))}]:a},Dm=e=>e.position&&e.position.within===void 0?e.position.field:void 0,Om=(e,t,n)=>{let r=Jt(n===null?sn.isNull(t):sn.eq(t,n));return e===``?r:`(${e}) AND ${r}`},km=(e,t,n)=>({kind:`cards`,name:n.name,title:n.title??ar(e,t),...n.subtitle!==void 0&&{subtitle:n.subtitle},...n.badge!==void 0&&{badge:n.badge},...n.meta&&{meta:n.meta}}),Am=e=>{if(!jc(e))return e instanceof Error?e.message:q(`somethingWrong`);let t=e.errors.map(e=>e.message);return t.length>0?t.join(`; `):e.message},jm=e=>e?.list?.displays??[],Mm=(e,t,n)=>{let r=n??e?.list?.default??`table`;if(!t)return r;let i=jm(e).filter(e=>e.kind===`cards`);return i.find(e=>e.name===r)?.name??i[0]?.name??r},Nm=`rows`,Pm=(e,t)=>{if(jm(t).some(e=>e.kind===`cards`||e.name===`rows`))return;let n=ar(e,t),r=mr(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:Nm,label:q(`list`),icon:`list`,title:n,...i!==void 0&&{badge:i},footer:a}},Fm=(e,t)=>t.name===`rows`&&!jm(e).some(e=>e.name===`rows`),Im=(e,t,n)=>{let r=Mm(t,n);return n&&r===`table`&&Pm(e,t)?Nm:r},Lm=(e,t,n)=>(n===`rows`?Pm(e,t):void 0)??Rm(t,n),Rm=(e,t)=>{if(t===`table`)return;let n=t=>jm(e).find(e=>e.name===t);return n(t)??n(e?.list?.default)},zm={cards:`cards`,map:`map`,board:`kanban`,calendar:`calendar`,timeline:`timeline`},Bm=e=>[{name:vn,label:q(`table`),icon:`table`},...jm(e).map(e=>({name:e.name,label:e.label??F(e.name),icon:e.icon??zm[e.kind]}))],Vm=(e,t,n)=>{let r=Bm(t);return n&&Pm(e,t)?[...r,{name:Nm,label:q(`list`),icon:`list`}]:r},Hm=(e,t,n)=>({image:n.image,title:n.title??ar(e,t),subtitle:n.subtitle,amount:n.amount??[],badge:n.badge,meta:n.meta??[],footer:n.footer??[],flags:n.flags??[]}),Um=(e,t)=>Tm(e.record,t),Wm=(e,t)=>Um(e,t)[0],Gm=(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:bm(e,t,n)}:{amount:bm(e,t,i),suffix:r}},Km=(e,t)=>{let n=jm(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}},qm=(e,t,n)=>{if(n.kind===`custom`)return n.fields;if(n.kind===`map`)return[n.latitude,n.longitude,...qm(e,t,Km(t,n))];if(n.kind===`board`){let r=km(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??ar(e,t)].filter(e=>e!==void 0);if(n.kind===`timeline`)return[n.start,n.end,n.group,n.title??ar(e,t)].filter(e=>e!==void 0);let{image:r,title:i,subtitle:a,amount:o,badge:s,meta:c,footer:l,flags:u}=Hm(e,t,n);return[r,i,a,...o,s,...c,...l,...u].filter(e=>e!==void 0)},Jm=(e,t,n)=>{let r=Pm(e,t),i=r?[...jm(t),r]:jm(t);return[...new Set([...n,...i.flatMap(n=>qm(e,t,n))])]},Ym=(e,t,n)=>{let r=Fm(t,n)?[ar(e,t),...mr(e,t)]:qm(e,t,n);return[...new Set(r)].filter(t=>e.fields[t]?.sortable)},Xm=e=>typeof e==`object`&&!!e&&`id`in e&&`name`in e,Zm=(e,t)=>{let n={},r={},i=Array.isArray(t.$photos)?t[Sm]:void 0;for(let[i,a]of Object.entries(t))(i!==`id`&&i!==`$photos`||Object.hasOwn(e.fields,i))&&(e.fields[i]?.type===`relation`&&Xm(a)?(n[i]=a.id,r[i]=a.name):n[i]=a);return{key:An(om(e,n)),record:n,labels:r,...i&&{photos:i}}},Qm=(e,t)=>{let n=t?.list?.sort?.[0];return n?`${n[0]} ${n[1]}`:`${e.primaryKey[0]} asc`},$m=e=>{let[t=``,n]=e.trim().split(/\s+/);return{columnId:t,direction:n===`desc`?`desc`:`asc`}},eh=e=>`${e.columnId} ${e.direction}`,th=(e,t,n,r)=>{let i=e[n],a=Sn(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}},nh=(e,t,n=!1)=>({display:e?Im(e,t,n):Mm(t,n),orderBy:e?Qm(e,t):``,filterLayout:`bar`,filter:t?.list?.filter??``}),rh=(e,t)=>e?.kind===`record`?{kind:`record`,resource:e.resource,key:An(e.key),...e.edit&&{edit:!0},...e.open&&{open:e.open},...e.tab&&{tab:e.tab}}:e?.kind===`list`?{...t(e.resource,e.list),...e}:e,ih=(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}}},ah=({to:e,onClick:t,...n})=>(0,B.jsx)(`a`,{href:e.href,onClick:n=>{t?.(n),!n.defaultPrevented&&Ff(n)&&(n.preventDefault(),e.onFollow())},...n}),J=M({en:{notFound:`Not found`,noResource:e=>`There is no resource called ${e}.`,somethingWentWrong:`Something went wrong`,signInPolicy:`Sign-in policy`,adminsOnly:`Admins only`,onlyAdminPolicy:`Only an admin can change how people sign in.`,ownersOnly:`Owners and admins only`,onlyOwners:`Only the organization's owners and admins manage its members.`,chooseResource:`Choose a resource`,pickFromSidebar:`Pick one from the sidebar.`,nothingHere:`There is nothing at this address.`,noPage:`There is no page called {}.`,assistant:`Assistant`,operationFailed:(e,t,n)=>`Operation ${e} (${t}) failed: ${n} Nothing was saved.`,nothingSaved:e=>`${e} Nothing was saved.`,admin:`Admin`,new:`New`,loadingRecord:`Loading record`,noComponent:`No component is registered as {}. Export it from protobase.ui.tsx, or load the plugin that provides it.`,choose:`Choose...`,fileMissing:`The file is missing from storage`,chooseFileFor:e=>`Choose a file for ${e}`,notUploaded:`Not uploaded`,uploadingLabel:e=>`Uploading ${e}`,uploading:e=>`Uploading… ${e}%`,replace:`Replace`,remove:`Remove`,dropFile:`Drop a file here or`,chooseFile:`Choose a file`,average:e=>`Average ${e.toLowerCase()}`,pages:`Pages`,account:`Account`,sales:`Sales`,crm:`CRM`,catalog:`Catalog`,inventory:`Inventory`,hr:`HR`,cannotReach:e=>`Cannot reach ${e}`,searchPlural:e=>`Search ${e}`,couldNotLoadOptions:`Could not load the options`,noMatches:`No matches`,loading:`Loading`,leaveTitle:`Leave without saving?`,leaveDescription:`You have unsaved changes on this page. They stay in this browser, and come back when you open the record again.`,leaveInputLost:`You have unsaved changes on this page. They are lost when you leave.`,stay:`Stay`,leave:`Leave`,reloadTitle:`Reload without saving?`,reloadDraftKept:`You have unsaved changes on this page. They stay in this browser, and come back after the page reloads.`,reloadInputLost:`You have unsaved changes on this page. They are lost when the page reloads.`,keepEditing:`Keep editing`,reload:`Reload`,show:e=>`Show ${e}`,hide:e=>`Hide ${e}`,couldNotShow:e=>`Could not show the ${e}`,setNewValue:`Set a new value`,noAnswer:`It did not answer.`,signInRefused:e=>`It did not accept your sign-in: ${e}`,loadingFrom:e=>`Loading from ${e}`,restWorks:`The rest of the app works as before.`,tryAgain:`Try again`,staffSession:`Staff session`,staffSignedIn:`{} is signed in as {} until {}. Reason: {}`,stopStaffSession:`Stop staff session`,open:`Open`,openLabel:e=>`Open ${e}`},nl:{notFound:`Niet gevonden`,noResource:e=>`Er is geen onderdeel met de naam ${e}.`,somethingWentWrong:`Er ging iets mis`,signInPolicy:`Inlogbeleid`,adminsOnly:`Alleen beheerders`,onlyAdminPolicy:`Alleen een beheerder kan wijzigen hoe mensen inloggen.`,ownersOnly:`Alleen eigenaren en beheerders`,onlyOwners:`Alleen de eigenaren en beheerders van de organisatie beheren de leden.`,chooseResource:`Kies een onderdeel`,pickFromSidebar:`Kies er een in de zijbalk.`,nothingHere:`Er is niets op dit adres.`,noPage:`Er is geen pagina met de naam {}.`,assistant:`Assistent`,operationFailed:(e,t,n)=>`Bewerking ${e} (${t}) mislukte: ${n} Er is niets bewaard.`,nothingSaved:e=>`${e} Er is niets bewaard.`,admin:`Beheer`,new:`Nieuw`,loadingRecord:`Record laden`,noComponent:`Er is geen component geregistreerd als {}. Exporteer die uit protobase.ui.tsx, of laad de plug-in die haar levert.`,choose:`Kiezen...`,fileMissing:`Het bestand ontbreekt in de opslag`,chooseFileFor:e=>`Kies een bestand voor ${e}`,notUploaded:`Niet geüpload`,uploadingLabel:e=>`${e} uploaden`,uploading:e=>`Uploaden… ${e}%`,replace:`Vervangen`,remove:`Verwijderen`,dropFile:`Zet hier een bestand neer of`,chooseFile:`Kies een bestand`,average:e=>`${e}, gemiddeld`,pages:`Pagina's`,account:`Account`,sales:`Verkoop`,crm:`CRM`,catalog:`Catalogus`,inventory:`Voorraad`,hr:`HR`,cannotReach:e=>`Kan ${e} niet bereiken`,searchPlural:e=>`${e} zoeken`,couldNotLoadOptions:`Kon de keuzes niet laden`,noMatches:`Niets gevonden`,loading:`Laden`,leaveTitle:`Weggaan zonder te bewaren?`,leaveDescription:`Je hebt niet-bewaarde wijzigingen op deze pagina. Ze blijven in deze browser, en komen terug als je het record weer opent.`,leaveInputLost:`Je hebt niet-bewaarde wijzigingen op deze pagina. Ze gaan verloren als je weggaat.`,stay:`Blijven`,leave:`Weggaan`,reloadTitle:`Opnieuw laden zonder op te slaan?`,reloadDraftKept:`Er zijn niet-opgeslagen wijzigingen op deze pagina. Ze blijven bewaard in deze browser en komen terug zodra de pagina opnieuw is geladen.`,reloadInputLost:`Er zijn niet-opgeslagen wijzigingen op deze pagina. Ze gaan verloren als de pagina opnieuw wordt geladen.`,keepEditing:`Verder bewerken`,reload:`Opnieuw laden`,show:e=>`${e} tonen`,hide:e=>`${e} verbergen`,couldNotShow:e=>`Kon ${e} niet tonen`,setNewValue:`Nieuwe waarde instellen`,noAnswer:`Het antwoordde niet.`,signInRefused:e=>`Het accepteerde je inlog niet: ${e}`,loadingFrom:e=>`Laden van ${e}`,restWorks:`De rest van de app werkt zoals eerst.`,tryAgain:`Opnieuw proberen`,staffSession:`Sessie van een medewerker`,staffSignedIn:`{} is ingelogd als {} tot {}. Reden: {}`,stopStaffSession:`Sessie van medewerker stoppen`,open:`Openen`,openLabel:e=>`${e} openen`}}),oh=`protobase:page-places`,sh=50,ch=e=>Array.isArray(e)&&e.length===2&&typeof e[0]==`string`&&typeof e[1]==`number`&&Number.isFinite(e[1])&&e[1]>=0,lh=e=>Fe(()=>{let t=e.getItem(oh);if(t===null)return[];let n=JSON.parse(t);return Array.isArray(n)?n.filter(ch):[]},[]),uh=e=>{let t=new Map(lh(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-sh)))t.delete(e)},persist:()=>Fe(()=>e.setItem(oh,JSON.stringify([...t])),void 0)}},dh=3e3,fh=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,dh);return r.observe(document.body),window.addEventListener(`scroll`,i,{passive:!0}),a},ph=(0,I.createContext)(null),mh=()=>{let e=(0,I.useContext)(ph);if(!e)throw Error(`useRouter must be used inside Router`);return e},hh=()=>`${window.location.pathname}${window.location.search}`,gh=e=>new URL(e,`http://local`).pathname,_h=()=>window.history.state??{},vh=()=>_h().protobaseIndex??0,yh=()=>Math.random().toString(36).slice(2),bh=()=>{let e=_h();if(e.protobaseEntry)return e.protobaseEntry;let t=yh();return window.history.replaceState({...e,protobaseEntry:t},``),t},xh={getItem:()=>null,setItem:()=>{}},Sh=({basePath:e=``,initialUrl:t,children:n})=>{let r=t!==void 0,[i,a]=(0,I.useState)(()=>({url:t??hh(),entry:r?yh():bh()})),[o]=(0,I.useState)(()=>uh(r?xh:Fe(()=>window.sessionStorage,void 0)??xh)),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:vh()),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)(()=>fh(o.placeOf(i.entry)),[o,i.entry]),(0,I.useEffect)(()=>{if(r)return;window.history.scrollRestoration=`manual`,window.history.replaceState({..._h(),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=vh();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=gh(hh())!==gh(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:hh(),entry:bh()})};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:yh();if(!r){u.current+=+!t;let r=t?_h().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(gh(r)!==gh(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:_h().protobasePrevious;if(n!==void 0&&gh(n)===gh(`${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)(ph.Provider,{value:T,children:[n,h?.kind===`reload`&&(0,B.jsx)(vd,{title:J(`reloadTitle`),description:J(h.inputLost?`reloadInputLost`:`reloadDraftKept`),onClose:()=>g(void 0),actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:()=>g(void 0),children:J(`keepEditing`)}),(0,B.jsx)(G,{variant:`primary`,onClick:w,children:J(`reload`)})]})}),h&&h.kind!==`reload`&&(0,B.jsx)(vd,{title:J(`leaveTitle`),description:J(h.inputLost?`leaveInputLost`:`leaveDescription`),onClose:()=>g(void 0),actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:()=>g(void 0),children:J(`stay`)}),(0,B.jsx)(G,{variant:`primary`,onClick:w,children:J(`leave`)})]})})]})},Ch=({to:e,replace:t,...n})=>{let{navigate:r,basePath:i}=mh();return(0,B.jsx)(ah,{to:{href:`${i}${e}`,onFollow:()=>r(e,{replace:t})},...n})},wh=(e,t=`draft-kept`)=>{let{registerGuard:n,reloadConfirmed:r}=mh();(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])},Th=()=>{let{path:e,params:t,basePath:n,navigate:r,back:i}=mh(),{pages:a,resources:o,views:s}=W(),c=fd(),l=(0,I.useMemo)(()=>new Set(Object.keys(a)),[a]),u=t.toString(),d=(0,I.useMemo)(()=>cc(u?`${e}?${u}`:e,l),[e,u,l]),f=(0,I.useCallback)((e,t)=>{let n=th(o,s,e,t);return nh(n.model,n.view,c)},[o,s,c]),p=(0,I.useMemo)(()=>rh(d,f),[d,f]),m=(0,I.useCallback)((e,t)=>r(ic(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 ih(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=>ic(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])}},Eh=({to:e,...t})=>(0,B.jsx)(Ch,{to:ic(e),...t}),Dh=`text-[16px] font-semibold text-foreground`,Oh=({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)(Eh,{to:n,replace:!0,"aria-expanded":t,"aria-controls":i,className:P(`inline-flex items-center gap-1.5`,Dh),children:[(0,B.jsx)(gi,{className:P(`size-4 transition-transform`,t&&`rotate-90`)}),e]}):(0,B.jsx)(`span`,{className:Dh,children:e})}),t&&(0,B.jsx)(`div`,{id:i,className:`divide-y divide-border`,children:r})]})},kh=({tabs:e})=>(0,B.jsx)(`nav`,{"aria-label":qf(`tabs`),className:`overflow-x-auto py-6`,children:(0,B.jsx)(`span`,{className:Re.group(`md`),children:e.map(e=>(0,B.jsx)(Eh,{to:e.to,replace:!0,"aria-current":e.current?`page`:void 0,className:P(Re.option(e.current,`md`),`whitespace-nowrap`),children:e.title},e.title))})}),Ah=({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))}),jh=({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))}),Mh=`flex w-full items-center gap-2 px-3 py-2.5 text-left hover:bg-muted disabled:cursor-default disabled:opacity-60`,Nh=4,Ph=(e,t,n)=>{let r=e.bottom+Nh;return{top:r+t.height>window.innerHeight-Nh?Math.max(Nh,e.top-Nh-t.height):r,right:Math.max(Nh,Math.min(n-e.right,n-Nh-t.width))}},Fh=()=>{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(Ph(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}},Ih=({actions:e,label:t=qf(`actions`),className:n})=>{let{open:r,setOpen:i,place:a,button:o,menu:s}=Fh();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)(Wi,{className:`size-5`})}),r&&(0,Bs.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)]})},Lh=(e=Ie())=>new Intl.NumberFormat(e).formatToParts(1.5).find(e=>e.type===`decimal`)?.value===`,`?`,`:`.`,Rh=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),zh=(e,t)=>{let n=`[${Rh(t===`.`?`,`:`.`)}\\s\\u00a0\\u202f']`,r=RegExp(`^([-+]?)(\\d{1,3}(?:${n}\\d{3})+|\\d+)(?:${Rh(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()))},Bh=e=>e==null?``:typeof e==`object`?JSON.stringify(e):String(e),Vh=new Set([`text`,`integer`,`bigint`,`decimal`,`date`,`currency`,`country`]),Hh=e=>!e.readOnly&&e.type!==`json`&&e.type!==`uuid`&&e.type!==`timestamp`&&e.type!==`relation`,Uh=e=>!e.readOnly&&!e.nullable&&e.type!==`boolean`,Wh=new Set([`integer`,`bigint`,`decimal`]),Gh=(e,t)=>zh(e,t)??e,Kh=(e,t,n=Lh())=>{if(e.type===`boolean`)return!!t;if(e.type===`file`)return Ap(t);let r=String(t).trim();if(r===``)return e.nullable?null:``;let i=Wh.has(e.type)?Gh(r,n):r;if(e.type===`integer`)return Number(i);if(e.type===`relation`)return typeof t==`number`?t:i;if(Vh.has(e.type)||e.type===`enum`)return i;throw Error(`Not implemented: editing ${e.type} fields`)},qh=(e,t,n=Lh())=>e.type===`boolean`?!!t:String(t??``).trim()===``?null:Kh(e,t,n),Jh=(e,t)=>e.type===`boolean`?!!t:Bh(t),Yh=(e,t,n,r=Lh())=>{if(e.type===`boolean`)return!!t!=!!n;if(e.type===`file`)return jp(t,n);let i=String(t??``).trim(),a=Bh(n);return e.type===`decimal`||e.type===`integer`?i===``||a===``?i!==a:Number(Gh(i,r))!==Number(a):i!==a},Xh=(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},Zh=(e,t,n)=>(e??t?.helpWhen??`always`)===`always`||n,Qh=(e,t,n)=>e?.help!==void 0&&Zh(e.helpWhen,t,n)?e.help:void 0,$h=(e,t)=>e===`editing`?t:e!==`reading`||!t,eg=M({en:{title:e=>`New ${e.toLowerCase()}`,subject:e=>`New ${e.toLowerCase()}`,submit:e=>`Create ${e.toLowerCase()}`,notCreated:`Not created`,notSaved:`Not saved`,cancel:`Cancel`,setByDatabase:`Set by the database`,details:`Details`,otherFields:`Other fields`,notAllowed:`Not allowed`,cannotCreate:e=>`You cannot create ${e}.`},nl:{title:e=>`${e} toevoegen`,subject:e=>e,submit:e=>`${e} aanmaken`,notCreated:`Niet aangemaakt`,notSaved:`Niet bewaard`,cancel:`Annuleren`,setByDatabase:`Ingevuld door de database`,details:`Details`,otherFields:`Overige velden`,notAllowed:`Niet toegestaan`,cannotCreate:e=>`Je mag geen ${e} aanmaken.`}}),tg=e=>typeof e==`object`&&!!e&&`key`in e,ng=(e,t)=>t.name!==e.tenant&&!t.readOnly&&(t.type===`relation`||Hh(t)),rg=(e,t)=>{let n=Object.values(e.fields).filter(t=>ng(e,t)).map(e=>e.name),r=new Set,i=xn(t?.layout??[]).flatMap(e=>{if(e.kind!==`section`||qs(e.when)||!$h(e.when,!0))return[];let i=e.fields.filter(e=>n.includes(e)&&!r.has(e)&&$h(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?eg(`details`):eg(`otherFields`),fields:a}]},ig=(e,t)=>(e?.primaryKey.length===1?e.fields[e.primaryKey[0]]?.type:void 0)===`integer`?Number(t):t,ag=(e,t,n)=>Object.fromEntries(Object.entries(n).flatMap(([n,r])=>{let i=e.fields[n];return i?tg(r)?[[n,ig(t[i.relation?.resource??``],r.key)]]:i.type===`boolean`?[[n,!!r]]:i.type===`file`?r?[[n,Kh(i,r)]]:[]:String(r).trim()===``?[]:[[n,Kh(i,r)]]:[]})),og=e=>!e.nullable&&!e.default&&e.type!==`boolean`,sg=(e,t)=>e.type===`relation`?{key:t,label:t}:e.type===`boolean`?t===`true`:t,cg=new Set([`integer`,`bigint`,`decimal`]),lg=e=>{if(!cg.has(e.type)||!e.default||!(`value`in e.default))return;let t=e.default.value;return t==null?void 0:String(t)},ug=(e,t,n={})=>Object.fromEntries(t.flatMap(t=>t.fields.flatMap(t=>{let r=e.fields[t];if(Object.hasOwn(n,t))return[[t,sg(r,n[t])]];let i=r.default;return lg(r)!==void 0||!i||!(`value`in i)||i.value===null||i.value===void 0?[]:[[t,typeof i.value==`boolean`?i.value:String(i.value)]]}))),dg=e=>!!(e.default&&`db`in e.default),fg=e=>{if(!jc(e))return[{message:e instanceof Error?e.message:J(`somethingWentWrong`)}];let t=e.errors.map(e=>({message:e.message,hint:e.hint}));return t.length>0?t:[{message:e.message}]},pg=({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)(ys,{className:`mt-0.5 size-4 shrink-0`}),(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`p`,{className:`font-medium`,children:t}),fg(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))]})]}),mg=({checked:e,onChange:t,label:n})=>{let r=Yf();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`)})})},hg=e=>{e.style.height=`auto`,e.style.height=`${e.scrollHeight+e.offsetHeight-e.clientHeight}px`},gg=({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=Yf();return(0,I.useLayoutEffect)(()=>{o.current&&hg(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,hg(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})},_g=(e,{filter:t,orderBy:n,pageSize:r=50,fields:i,startToken:a=``,enabled:o=!0,refetchInterval:s}={})=>{let c=U(),l=vc(t)??``,u=Me({queryKey:[...H.list(e,l,n??``,r,a),i?.join(`,`)??``],enabled:o,refetchInterval:s,initialPageParam:a,queryFn:({pageParam:t})=>c.list(e,{filter:l,orderBy:n,pageSize:r,fields:i,pageToken:t}),getNextPageParam:e=>e.nextPageToken||void 0}),d=u.data?.pages??[];return{...u,items:d.flatMap(e=>e.items),totalEstimate:d[0]?.totalSizeEstimate}},vg=on(),yg=e=>e.split(/\s+/).filter(Boolean),bg=(e,t,n,r=!1)=>{let i=yg(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:Jt(vg.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=>vg.eq(t,`*${e.replaceAll(`*`,``)}*`));return{filter:Jt(vg.and(...o)),local:!1}},xg=(e,t)=>{if(e==null)return!1;let n=String(e).toLowerCase();return yg(t).every(e=>n.includes(e.toLowerCase()))},Sg=(e,t,n,r)=>{(0,I.useEffect)(()=>{if(!e||!t)return;let n=new IntersectionObserver(e=>e.some(e=>e.isIntersecting)&&r(),{root:e});return n.observe(t),()=>n.disconnect()},[e,t,n,r])},Cg=({target:e,view:t,value:n,label:r,chosen:i=[n],several:a=!1,invalid:o,onChange:s})=>{let[c,l]=(0,I.useState)(``),[u,d]=(0,I.useState)(!1),[f,p]=(0,I.useState)(-1),[m,h]=(0,I.useState)(null),[g,_]=(0,I.useState)(null),v=(0,I.useId)(),y=e.primaryKey[0],b=ir(e,t),[x,S]=(0,I.useState)(!1),C=bg(e,b,c,x),w=_g(e.name,{filter:C.filter,fields:[y,b],enabled:u}),T=C.filter!==void 0&&w.error instanceof kc&&w.error.slug===`expensive-query`;(0,I.useEffect)(()=>{T&&S(!0)},[T]);let E=C.local?w.items.filter(e=>xg(e[b],c)):w.items,D=!!w.hasNextPage,O=w.isPending||w.isFetchingNextPage,{fetchNextPage:k}=w;Sg(m,g,w.items.length,(0,I.useCallback)(()=>k({cancelRefetch:!1}),[k]));let A=e=>`${v}-${e}`,j=(0,I.useRef)(null);(0,I.useEffect)(()=>{!u&&document.activeElement===j.current&&j.current?.select()},[u]),(0,I.useEffect)(()=>{u&&f>=0&&document.getElementById(A(f))?.scrollIntoView({block:`nearest`})});let ee=()=>{l(``),p(-1),d(!1)},te=e=>{if(s(String(e[y]),String(e[b])),!a)return ee();l(``),p(-1)};return(0,B.jsxs)(`div`,{className:`relative`,children:[(0,B.jsx)(Xf,{ref:j,role:`combobox`,"aria-autocomplete":`list`,"aria-expanded":u,"aria-controls":v,"aria-activedescendant":u&&E[f]?A(f):void 0,invalid:o,placeholder:J(`searchPlural`,(t?.names?.plural??F(e.name)).toLowerCase()),value:u?c:r??n,onFocus:()=>d(!0),onBlur:ee,onKeyDown:e=>{if(e.key===`ArrowDown`||e.key===`ArrowUp`){if(e.preventDefault(),!u)return d(!0);let t=e.key===`ArrowDown`?1:-1;p(e=>Math.min(Math.max(e+t,0),E.length-1));return}if(e.key===`Enter`&&u&&E[f]){e.preventDefault(),te(E[f]);return}e.key===`Escape`&&u&&(e.preventDefault(),e.stopPropagation(),ee())},onChange:e=>{l(e.target.value),p(e.target.value.trim()?0:-1),d(!0)}}),u&&(0,B.jsxs)(`ul`,{ref:h,id:v,role:`listbox`,"aria-multiselectable":a||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:[E.map((e,t)=>(0,B.jsx)(`li`,{id:A(t),role:`option`,"aria-selected":t===f,className:P(`cursor-pointer truncate px-3 py-1.5`,t===f&&`bg-muted`,i.includes(String(e[y]))&&`font-medium`),onMouseMove:()=>t!==f&&p(t),onClick:()=>te(e),children:String(e[b])},String(e[y]))),D&&(0,B.jsx)(`li`,{ref:_,"aria-hidden":!0,className:`h-px`}),w.error&&!T&&(0,B.jsx)(`li`,{className:`px-3 py-1.5 text-muted-foreground`,children:J(`couldNotLoadOptions`)}),!D&&!O&&!w.error&&E.length===0&&(0,B.jsx)(`li`,{className:`px-3 py-1.5 text-muted-foreground`,children:J(`noMatches`)}),O&&(0,B.jsx)(`li`,{className:`px-3 py-1.5 text-muted-foreground`,children:J(`loading`)})]})]})},wg=(e,t)=>e.replace(/\D/g,``).slice(0,t),Tg=(e,t,n)=>{let r=wg(t??``,n);return r.length===n?r:wg(e,n)},Eg=(e,t,n,r)=>{let i=t.replace(/\D/g,``);return i.length>=r?i.slice(0,r):wg(e.slice(0,n)+i+e.slice(n+i.length),r)},Dg=({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(Tg(e.target.value,t??n?.getData(`text/plain`),r))},onPaste:e=>{if(p?.(e),e.defaultPrevented)return;e.preventDefault();let t=e.currentTarget,n=Eg(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)}})]})},Og=M({en:{confirmTitle:`Confirm it's you`,confirmWhy:e=>`Showing this needs a passkey or your authenticator app in the last ${e} minutes.`,usePasskey:`Use a passkey`,authenticatorCode:`Code from your authenticator app`,confirm:`Confirm`,nothingToConfirmWith:`Add a passkey or an authenticator app on your account page first.`},nl:{confirmTitle:`Bevestig dat jij het bent`,confirmWhy:e=>`Dit tonen vraagt in de laatste ${e} minuten een passkey of je authenticator-app.`,usePasskey:`Passkey gebruiken`,authenticatorCode:`Code uit je authenticator-app`,confirm:`Bevestigen`,nothingToConfirmWith:`Voeg eerst een passkey of een authenticator-app toe op je accountpagina.`}}),kg=({minutes:e,onConfirmed:t})=>{let n=wu(),[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":Og(`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:Og(`confirmTitle`)}),(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:Og(`confirmWhy`,e)}),l&&l.passkeys>0&&(0,B.jsx)(G,{variant:`primary`,size:`sm`,className:`self-start`,loading:s.isPending,onClick:()=>s.mutate(),children:Og(`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:[Og(`authenticatorCode`),(0,B.jsx)(Dg,{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:Og(`confirm`)})]}),l&&l.passkeys===0&&!l.authenticatorApp&&(0,B.jsx)(`p`,{children:Og(`nothingToConfirmWith`)}),u&&(0,B.jsx)(`p`,{role:`alert`,className:`font-medium text-danger-text`,children:u.message})]})},Ag=`••••••••••`,jg=e=>jc(e)&&e.slug===`strong-sign-in-required`?e.problem.minutes??15:void 0,Mg=({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=Bh(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":J(l?`hide`:`show`,p),"aria-pressed":l,loading:d.isPending,onClick:()=>{l||f||!r||d.isSuccess?u(!l):d.mutate()},children:!d.isPending&&(l?(0,B.jsx)(Xi,{className:`size-3.5`}):(0,B.jsx)(Qi,{className:`size-3.5`}))}),h=jg(d.error),g=h===void 0?d.error&&(0,B.jsx)(`div`,{className:`mt-2`,children:(0,B.jsx)(pg,{title:J(`couldNotShow`,p),error:d.error})}):(0,B.jsx)(kg,{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?bm(e,d.data,t):Ag}),r&&m]}),g]});let _=f?Bh(n):l&&d.isSuccess?Bh(d.data):``;return(0,B.jsxs)(`div`,{children:[(0,B.jsx)(Xf,{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?J(`setNewValue`):void 0):Ag,value:_,trailing:m,onChange:e=>c(e.target.value)}),g]})},Ng=(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`},Pg=e=>URL.canParse(e)?[new URL(e).hostname]:[],Fg=()=>{let e=(0,I.useContext)(Ru);return(0,I.useMemo)(()=>[...e?.files?.trustedHosts??[],...(e?.sources??[]).flatMap(({source:e})=>Pg(e.url))],[e?.files,e?.sources])},Ig=e=>{let t;try{t=atob(e)}catch(e){if(e instanceof DOMException&&e.name===`InvalidCharacterError`)return;throw e}return Ae(Uint8Array.from(t,e=>e.charCodeAt(0)))},Lg=({image:e,alt:t=``,className:n,loading:r})=>{let[i,a]=(0,I.useState)(),o=Fg(),s=(0,I.useMemo)(()=>e.placeholder===void 0?void 0:Ig(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:Ng(e.url,window.location.href,o),onLoad:()=>a(e.url),className:n,style:c?{backgroundImage:`url("${s}")`,backgroundSize:`cover`,backgroundPosition:`center`}:void 0})},Rg=({value:e})=>{let t=Op(e,{width:40,height:40});return t?(0,B.jsx)(Lg,{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)(ia,{className:`size-4`})})},zg=({value:e})=>{let t=bp(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:J(`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)(Rg,{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&&` · ${Sp(t.size)}`,r&&` · sent as ${r.from}`]})]})]})},Bg=({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,...Cp(r.file.type)&&{preview:URL.createObjectURL(t)}}},onSuccess:e=>s(e),onSettled:()=>d(void 0)});if(i||e.readOnly)return(0,B.jsx)(zg,{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:kp(e),"aria-label":J(`chooseFileFor`,m),onChange:e=>g(e.target.files)}),y=h.error&&(0,B.jsx)(`div`,{className:`mt-2`,children:(0,B.jsx)(pg,{title:J(`notUploaded`),error:h.error})});return h.isPending?(0,B.jsxs)(`div`,{className:`py-1.5`,role:`status`,"aria-label":J(`uploadingLabel`,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:J(`uploading`,Math.round((u??0)*100))})]}):bp(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)(zg,{value:r})}),(0,B.jsx)(G,{size:`sm`,onClick:()=>l.current?.click(),children:J(`replace`)}),e.nullable&&(0,B.jsx)(G,{size:`sm`,variant:`ghost`,onClick:()=>s(null),children:J(`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)(Cs,{className:`size-4 shrink-0`}),(0,B.jsx)(`span`,{className:`flex-1`,children:J(`dropFile`)}),(0,B.jsxs)(G,{size:`sm`,onClick:()=>l.current?.click(),children:[(0,B.jsx)(co,{className:`size-3.5`}),J(`chooseFile`)]})]}),v,y]})},Vg=e=>e,Hg=e=>e,Ug=(0,I.createContext)({}),Wg=()=>(0,I.useContext)(Ug),Gg=(e,t,n)=>{let r=n?.widget;if(!r||t.sensitive||!e||!Object.hasOwn(e,r.name))return;let i=e[r.name];return i.of.includes(t.type)?{name:r.name,widget:i,props:r.props??{}}:void 0},Kg=(e,t)=>Gg(Wg().fields,e,t),qg,Jg,Yg=({dsn:e,environment:t})=>(qg??=Be(()=>import(`./prod-YZ9ZMG1O.js`).then(n=>{n.init({dsn:e,...t&&{environment:t},integrations:e=>e.filter(e=>e.name!==`BrowserSession`),beforeSend:e=>Un(e)}),Jg=(e,t)=>n.captureException(e,t?{contexts:{react:{componentStack:t}}}:void 0)}),[]),qg),Xg=(e,t)=>Jg?.(e,t??void 0),Zg=({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}),Qg=(e,...t)=>{let n=e.split(`{}`);if(n.length!==t.length+1)throw Error(`The text "${e}" has ${n.length-1} places for ${t.length} elements`);return(0,B.jsx)(B.Fragment,{children:n.map((e,n)=>(0,B.jsxs)(I.Fragment,{children:[e,n<t.length&&t[n]]},n))})},Y=M({en:{notFound:`Not found`,noPage:`There is no page called {}.`,tabs:`Tabs`,noTab:e=>`This page has no tab called ${e}.`,cancel:`Cancel`,couldNotDraw:`{} could not be drawn.`,noComponent:`No component is registered as {}. Export it from protobase.ui.tsx, or load the plugin that provides it.`,unknownBlock:`{} is not a block this version of the app knows.`,somethingWrong:`Something went wrong`,needsRecord:`Needs a record`,cannotChange:`You cannot change this record`,cannotDelete:`You cannot delete this record`,doesNotApply:`Does not apply to this record`,noHandler:e=>`The app has no handler for "${e}"`,noInputComponent:(e,t)=>`The app has no component "${e}" for input "${t}"`,done:e=>`${e}: done`,doneOn:(e,t,n,r)=>[`${e}: done on ${t}`,...n>0?[`skipped ${n} it does not apply to`]:[],...r>0?[`failed on ${r}`]:[]].join(`, `),failed:e=>`${e} failed`,noAction:e=>`No action "${e}"`,couldNotLoad:`Could not load`,nothingYet:`Nothing here yet.`,saved:e=>`${e}: saved`,create:`Create`,save:`Save`,notSaved:`Not saved`,settings:`Settings`,couldNotCount:`Could not count`,required:`Required`,wholeNumber:`A whole number`,number:`A number`,dateFormat:`A date as YYYY-MM-DD`,atMost:e=>`At most ${e} characters`},nl:{notFound:`Niet gevonden`,noPage:`Er is geen pagina met de naam {}.`,tabs:`Tabbladen`,noTab:e=>`Deze pagina heeft geen tabblad met de naam ${e}.`,cancel:`Annuleren`,couldNotDraw:`{} kon niet worden getekend.`,noComponent:`Er is geen component geregistreerd als {}. Exporteer die uit protobase.ui.tsx, of laad de plug-in die haar levert.`,unknownBlock:`{} is geen blok dat deze versie van de app kent.`,somethingWrong:`Er ging iets mis`,needsRecord:`Vraagt een record`,cannotChange:`Je kunt dit record niet wijzigen`,cannotDelete:`Je kunt dit record niet verwijderen`,doesNotApply:`Geldt niet voor dit record`,noHandler:e=>`De app heeft geen handler voor "${e}"`,noInputComponent:(e,t)=>`De app heeft geen component "${e}" voor invoer "${t}"`,done:e=>`${e}: klaar`,doneOn:(e,t,n,r)=>[`${e}: klaar voor ${t}`,...n>0?[`${n} overgeslagen waarvoor het niet geldt`]:[],...r>0?[`mislukt voor ${r}`]:[]].join(`, `),failed:e=>`${e} mislukt`,noAction:e=>`Geen actie "${e}"`,couldNotLoad:`Kon niet laden`,nothingYet:`Hier staat nog niets.`,saved:e=>`${e}: bewaard`,create:`Maken`,save:`Bewaren`,notSaved:`Niet bewaard`,settings:`Instellingen`,couldNotCount:`Kon niet tellen`,required:`Verplicht`,wholeNumber:`Een geheel getal`,number:`Een getal`,dateFormat:`Een datum als JJJJ-MM-DD`,atMost:e=>`Hoogstens ${e} tekens`}}),$g=class extends I.Component{state={failed:!1};static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(e,t){Xg(e,t.componentStack)}render(){return this.state.failed?this.props.fallback===void 0?(0,B.jsx)(Zg,{children:Qg(Y(`couldNotDraw`),this.props.name)}):this.props.fallback:this.props.children}},e_=M({en:{fieldType:e=>`The field type ${e}`},nl:{fieldType:e=>`Het veldtype ${e}`}}),t_=({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},n_=({fallback:e,...t})=>{let n=t_(t);return n?(0,B.jsx)($g,{name:e_(`fieldType`,t.shown.name),fallback:e,children:n}):e},r_=(0,I.lazy)(()=>Be(()=>import(`./markdown-content-DOuciTNH.js`).then(e=>({default:e.MarkdownContent})),__vite__mapDeps([0,1,2,3]))),i_=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)(r_,{...e})}),a_=M({en:{write:`Write`,preview:`Preview`,nothingToPreview:`Nothing to preview`},nl:{write:`Schrijven`,preview:`Voorbeeld`,nothingToPreview:`Niets om te tonen`}}),o_=()=>[{value:`write`,label:a_(`write`)},{value:`preview`,label:a_(`preview`)}],s_=({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)(Le,{value:a,options:o_(),onChange:o,label:n})}),a===`write`?(0,B.jsx)(gg,{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:a_(`nothingToPreview`)}):(0,B.jsx)(i_,{source:e})})]})},c_=new Set([`integer`,`bigint`,`decimal`]),l_=e=>e===`integer`||e===`bigint`?{inputMode:`numeric`,enterKeyHint:`done`}:e===`decimal`?{inputMode:`decimal`,enterKeyHint:`done`}:{},u_=e=>e.stopPropagation(),d_=({format:e,value:t,className:n})=>{let r=lm(e,t);return r?(0,B.jsx)(`a`,{href:r,...e===`url`?{target:`_blank`,rel:`noreferrer`}:{},onClick:u_,className:P(`font-medium text-primary-text hover:underline`,n),children:t}):(0,B.jsx)(`span`,{className:n,children:t})},f_=e=>typeof e==`object`&&e&&`key`in e?e.key:e,p_=(e,t,n,r,i)=>t?.confirm!==void 0&&!Yh(e,n,r)&&Yh(e,f_(i),r),m_=M({en:{title:e=>`Change ${e}?`,change:`Change`,cancel:`Cancel`},nl:{title:e=>`${e} wijzigen?`,change:`Wijzigen`,cancel:`Annuleren`}}),h_=e=>e instanceof Element&&e.closest(`[data-change-confirm]`)!==null,g_=({field:e,hints:t,value:n,stored:r,onChange:i})=>{let[a,o]=(0,I.useState)(),s=a=>{p_(e,t,n,r,a)?o({next:a}):i(a)},c=()=>o(void 0);return{onChange:s,dialog:a&&(0,Bs.createPortal)((0,B.jsx)(`div`,{"data-change-confirm":``,children:(0,B.jsx)(vd,{title:m_(`title`,t?.label??F(e.name)),description:t?.confirm,onClose:c,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:c,children:m_(`cancel`)}),(0,B.jsx)(G,{variant:`primary`,onClick:()=>{o(void 0),i(a.next)},children:m_(`change`)})]})})}),document.body)}},__=({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=Yf();if(e.type===`file`)return(0,B.jsx)(Bg,{field:e,hints:t,resource:d??``,value:n,locked:c||!d,invalid:s,onChange:f});if(e.sensitive)return(0,B.jsx)(Mg,{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)(Cg,{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)(Eh,{to:a,"aria-label":J(`openLabel`,i??String(n)),title:J(`open`),className:P(ld({variant:`ghost`}),`w-8 px-0`),children:(0,B.jsx)(Er,{className:`size-4`})})]}):e}if(e.type===`boolean`&&c)return(0,B.jsx)(`div`,{className:`py-1.5 text-muted-foreground`,children:bm(e,r,t)});if(e.type===`boolean`)return(0,B.jsx)(mg,{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)(Eh,{to:a,className:`font-medium text-primary-text hover:underline`,children:e}):e})}let m=!!t?.multiline&&e.type===`text`,h=rm(e,t);if((!Hh(e)||c)&&h&&typeof r==`string`&&r!==``)return(0,B.jsx)(i_,{source:r,className:`py-1.5`});let g=e.type===`text`?cm(t):void 0;return(!Hh(e)||c)&&g&&typeof r==`string`&&r!==``?(0,B.jsx)(`div`,{className:`min-w-0 break-words py-1.5`,children:(0,B.jsx)(d_,{format:g,value:r})}):!Hh(e)||c?(0,B.jsx)(`div`,{title:xm(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:bm(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:J(`choose`)}),(e.enumValues??[]).map(e=>(0,B.jsx)(`option`,{value:e,children:tr(e,t?.valueLabels)},e))]}):h?(0,B.jsx)(s_,{label:t?.label??F(e.name),invalid:s,placeholder:l,value:String(n),onChange:f}):m?(0,B.jsx)(gg,{invalid:s,placeholder:l,value:String(n),onChange:e=>f(e.target.value)}):(0,B.jsx)(Xf,{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(c_.has(e.type)&&`text-right tabular-nums`),...l_(e.type),...um(g),value:String(n),onChange:e=>f(e.target.value)})},v_=e=>{let{field:t,hints:n,value:r,stored:i,invalid:a,locked:o,onChange:s}=e,c=Kg(t,n),l=(0,B.jsx)(__,{...e});return c?o||!Hh(t)?(0,B.jsx)(n_,{shown:c,part:`display`,field:t,value:i,fallback:l}):t.type===`file`||t.type===`relation`?l:(0,B.jsx)(n_,{shown:c,part:`editor`,field:t,value:qh(t,r),invalid:!!a,onChange:e=>s(Jh(t,e)),fallback:l}):l},y_=e=>{let t=g_(e);return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(v_,{...e,onChange:t.onChange}),t.dialog]})},b_={text:`text`,integer:`integer`,decimal:`decimal`,boolean:`boolean`,date:`date`},x_=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:b_[e.kind]}},S_=e=>({label:e.label,...e.multiline&&{multiline:!0},...e.options&&{valueLabels:Object.fromEntries(e.options.map(e=>[e.value,e.label]))}}),C_=e=>Object.fromEntries(e.map(e=>e.kind===`custom`?[e.name,e.default??null]:e.kind===`boolean`?[e.name,!!e.default]:[e.name,Bh(e.default)])),w_=(e,t)=>e.kind===`custom`?t??null:tg(t)?t.key:e.resource===void 0?Kh(x_(e),t):String(t??``)===``?null:String(t),T_=(e,t)=>{let n=Object.fromEntries(e.map(e=>[e.name,w_(e,t[e.name])])),r=Dn(e,n);return{shown:r,values:Object.fromEntries(Object.entries(n).filter(([e])=>r.has(e)))}},E_=/^-?\d+(\.\d+)?$/,D_=/^\d{4}-\d{2}-\d{2}$/,O_=(e,t)=>{if(t===null||t===``)return e.required?Y(`required`):void 0;if(e.kind===`integer`&&!Number.isInteger(t))return Y(`wholeNumber`);if(e.kind===`decimal`&&!E_.test(String(t)))return Y(`number`);if(e.kind===`date`&&!D_.test(String(t)))return Y(`dateFormat`);if(e.max!==void 0&&String(t).length>e.max)return Y(`atMost`,e.max)},k_=(e,t)=>Object.fromEntries(e.flatMap(e=>{if(!Object.hasOwn(t,e.name))return[];let n=O_(e,t[e.name]);return n?[[e.name,n]]:[]})),A_=class extends Error{errors;constructor(e){super(Object.values(e).join(`; `)),this.errors=e,this.name=`ActionInputError`}},j_=(e,t)=>{let n=new Set(t.map(e=>e.name)),r=e instanceof A_?Object.entries(e.errors):jc(e)?e.errors.flatMap(e=>e.field?[[e.field,e.message]]:[]):[];return Object.fromEntries(r.filter(([e])=>n.has(e)))},M_=({input:e,held:t,invalid:n,onChange:r})=>{let{resources:i,views:a}=W(),{components:o}=Wg();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)(y_,{field:x_(e),hints:S_(e),value:tg(t)?t.key:t,stored:void 0,relationLabel:tg(t)?t.label:void 0,relationPicker:s?{target:s,view:a[s.name]}:void 0,invalid:n,onChange:r})},N_=({action:e,label:t,danger:n,onCancel:r,onSubmit:i})=>{let[a,o]=(0,I.useState)(()=>C_(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}=T_(e.inputs,a),g=async()=>{let t=k_(e.inputs,h);c(t),u(void 0),!(Object.keys(t).length>0)&&(f(!0),await i(h).catch(t=>{c(j_(t,e.inputs)),u(t)}),f(!1))},_=(e,t)=>{c(({[e]:t,...n})=>n),o(n=>({...n,[e]:t}))};return(0,B.jsx)(xd,{title:t,description:e.confirm,open:!0,onClose:r,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:r,children:Y(`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)(pg,{title:Y(`failed`,t),error:l}),e.inputs.filter(e=>m.has(e.name)).map(e=>(0,B.jsx)(ep,{label:e.label,required:e.required,help:e.help,error:s[e.name],children:(0,B.jsx)(M_,{input:e,held:a[e.name],invalid:!!s[e.name],onChange:t=>_(e.name,t)})},e.name))]})})},P_=({action:e,label:t,danger:n,onCancel:r,onConfirm:i})=>(0,B.jsx)(vd,{title:`${t}?`,description:e.confirm,onClose:r,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:r,children:Y(`cancel`)}),(0,B.jsx)(G,{variant:n?`danger`:`primary`,onClick:i,children:t})]})}),F_=e=>e.variant===`danger`||e.run?.kind===`delete`,I_=e=>!!(e.confirm||e.inputs?.length),L_=({action:e,label:t,danger:n,onCancel:r,onConfirm:i,onSubmit:a})=>{let{inputs:o}=e;return o?.length?(0,B.jsx)(N_,{action:{...e,inputs:o},label:t,danger:n,onCancel:r,onSubmit:a}):(0,B.jsx)(P_,{action:e,label:t,danger:n,onCancel:r,onConfirm:i})},R_=(0,I.createContext)(void 0),z_=({value:e,children:t})=>(0,B.jsx)(R_.Provider,{value:e,children:t}),B_=()=>(0,I.useContext)(R_),V_=(e,t)=>e[t]||e.conditional.includes(t),H_=(e,t)=>e.permissions?.[t]??!0,U_=(e,t)=>e?.fields?e.fields[t]??`hidden`:`edit`,W_=(e,t)=>{if(e.when===void 0)return!0;if(!t)return!1;let n=ll(e.when);return n.ok&&ul(n,t)},G_=(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]))),K_=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},q_=(e,t={})=>{let n=mn(e);return n===void 0?G_(e,t):K_(t[n])},J_=e=>{e!==void 0&&(/^https?:/i.test(e)?window.open(e,`_blank`,`noopener,noreferrer`):window.location.assign(e))},Y_=e=>URL.canParse(e)?new URL(e).hostname.replace(/^www\./,``):``,X_=(e,t)=>Object.entries(t).every(([t,n])=>Object.is(e[t],n)),Z_=(e,t)=>{if(!W_(e,t))return e.otherwise===`disable`?e:void 0;let n=e.run;if(n?.kind===`update`)return t&&!e.inputs?.length&&X_(t,n.values)?void 0:e;if(n?.kind!==`link`||!(`href`in n))return e;let r=q_(n.href,t);if(r!==void 0)return e.label.includes(`{host}`)?{...e,label:e.label.replaceAll(`{host}`,Y_(r))}:e},Q_=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},$_=(e,t)=>({model:e,record:t,key:An(om(e,t)),etag:typeof t.etag==`string`?t.etag:void 0,permissions:t.permissions}),ev=(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}}),tv=(e,t=``)=>E(ev(U(),e,t)),nv=(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{...$_(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]?$_(e,a.items[0]):null}})},rv=(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})})},iv=()=>{let e=be();return(0,I.useCallback)(t=>e.invalidateQueries({predicate:e=>e.queryKey[1]===t}),[e])},av=e=>e instanceof Error?e.message:Y(`somethingWrong`),ov=(e,t,n)=>{let{views:r}=W(),{actions:i,components:a}=Wg(),o=ed(e),s=U(),c=Nu(e),l=Gf(),u=iv(),{go:d}=Th(),[f,p]=(0,I.useState)(),m=(r[e]?.actions??[]).flatMap(e=>Z_(e,t?.record)??[]),h=(e,t)=>{let n=e.run?.kind;if((n===`update`||n===`delete`||n===`ai`)&&!t)return Y(`needsRecord`);if(!W_(e,t?.record))return e.reason??Y(`doesNotApply`);if((n===`update`||n===`ai`)&&(!V_(o,`update`)||t?.permissions?.update===!1)||e.run?.kind===`ai`&&t?.permissions?.fields?.[e.run.writes]===`read`)return Y(`cannotChange`);if(n===`delete`&&(!V_(o,`delete`)||t?.permissions?.delete===!1))return Y(`cannotDelete`);if(!e.run&&!i?.[e.name])return Y(`noHandler`,e.name);let r=e.inputs?.find(e=>e.kind===`custom`&&!a?.[e.component??``]);if(r)return Y(`noInputComponent`,String(r.component),r.name)},g=e=>h(e,t),_=async(t,n,r)=>{let{run:a}=t;if(a?.kind===`link`){`to`in a?d(pn(a.to,n?.record)):J_(q_(a.href,n?.record));return}a?.kind===`update`?await s.update(e,n.key,On(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:Y(`done`,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:Y(`failed`,e.label),description:av(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)=>Z_(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 Q_(r,e=>x(t,e),e=>_(t,e));p(void 0),await u(e);let o=Y(`doneOn`,t.label,a.done,a.skipped+i,a.failed);l.show(a.failed>0?{state:`error`,title:o,description:av(a.error)}:{state:`success`,title:o}),a.done>0&&n?.(t)}}},sv=(e,t,n)=>{let r=ov(e,n),i=r.actions.find(e=>e.name===t);return{action:i,blocked:i?r.blocked(i):Y(`noAction`,t),running:r.running===t,run:()=>i?r.run(i):Promise.resolve(),submit:e=>i?r.submit(i,e):Promise.resolve()}},cv=e=>e.props,lv=({name:e,resource:t,label:n,variant:r})=>{let i=B_(),a=sv(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:()=>I_(a.action)?s(!0):void a.run(),children:c}),o&&(0,B.jsx)(L_,{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)}})]})},uv=({node:e})=>(0,B.jsx)(lv,{...cv(e)}),dv=({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})]}),fv=({children:e})=>(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:e}),pv=({node:e,children:t,slots:n})=>{let{title:r,description:i}=cv(e);return(0,B.jsx)(dv,{title:r,description:i,actions:n.actions,className:`h-full`,children:(0,B.jsx)(`div`,{className:`flex flex-col gap-3`,children:t})})},mv=({model:e,filter:t,sort:n,limit:r=12,title:i,description:a,empty:o,actions:s,children:c})=>{let l=rv(e,{filter:t,sort:n,pageSize:r}),u=l.data?.items??[];return(0,B.jsx)(dv,{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)(K,{className:`h-24 w-56`},t))}):l.error?(0,B.jsx)(pg,{title:Y(`couldNotLoad`),error:l.error}):u.length===0?(0,B.jsx)(fv,{children:o??Y(`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=$_(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)(z_,{value:n,children:c})},n.key)})})})},hv=({node:e,children:t,slots:n})=>{let{resource:r,...i}=cv(e),a=W().resources[r];return a?(0,B.jsx)(mv,{...i,model:a,actions:n.actions,children:t}):null},gv=(e,t,n,r=!0)=>{let i=U(),a=vc(n)??``;return E({queryKey:H.facets(e,t,a),enabled:r,queryFn:()=>i.facets(e,t,{filter:a,limit:50})})},_v=(e,t,n=!0)=>{let r=U(),i=vc(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})})},vv=(e,t,n,r=20,i=!0)=>{let a=U(),o=vc(n)??``;return E({queryKey:H.histogram(e,t,r,o),enabled:i,queryFn:()=>a.histogram(e,t,{filter:o,buckets:r})})},yv=(e,t,n=!0)=>{let r=U(),i={...t,filter:vc(t.filter)??``};return E({queryKey:H.aggregate(e,JSON.stringify(i)),enabled:n,queryFn:()=>r.aggregate(e,i)})},bv=(e,t,n=!0)=>{let r=U();return f({queries:t.map(t=>{let i={...t,filter:vc(t.filter)??``};return{queryKey:H.aggregate(e,JSON.stringify(i)),enabled:n,queryFn:()=>r.aggregate(e,i)}})})},xv=M({en:{notSet:`Not set`,yes:`Yes`,no:`No`,nothingYet:`Nothing to chart yet.`,couldNotLoad:`Could not load the chart.`,weekOf:e=>`Week of ${e}`,other:`Other`,records:e=>`${e} records`},nl:{notSet:`Niet ingevuld`,yes:`Ja`,no:`Nee`,nothingYet:`Nog niets om in een grafiek te zetten.`,couldNotLoad:`Kon de grafiek niet laden.`,weekOf:e=>`Week van ${e}`,other:`Overig`,records:e=>`${e} records`}}),Sv=on(),Cv=e=>e>=0&&e<8?`var(--chart-${e+1})`:`var(--faint-foreground)`,wv=(e,t,n,r)=>{let i=String(n);return n===null?`var(--faint-foreground)`:t?.valueColors&&Object.hasOwn(t.valueColors,i)?t.valueColors[i]:e.type===`enum`?Cv(e.enumValues?.indexOf(i)??-1):e.type===`boolean`?Cv(+!n):Cv(r)},Tv=(e,t,n)=>n.value===null?xv(`notSet`):e.type===`enum`?tr(String(n.value),t?.valueLabels):e.type===`boolean`?n.value?xv(`yes`):xv(`no`):n.label??String(n.value),Ev=(e,t,n=``)=>{let r=Jt(t===null?Sv.isNull(e.name):Sv.eq(e.name,t));return n.trim()?`(${n}) AND ${r}`:r},Dv=(e,t)=>t.kind===`count`?e.count:e[t.kind]??null,Ov=(e,t,n,r,i=``)=>e.map((e,a)=>({key:String(e.value),label:Tv(t,n,e),value:Dv(e,r),count:e.count,color:wv(t,n,e.value,a),filter:Ev(t,e.value,i)})),kv=(e,t)=>e.map(e=>({at:Date.parse(`${String(e.value)}Z`),value:Dv(e,t),count:e.count})),Av=(e,t)=>{if(e===null)return`—`;if(t.kind===`count`)return e.toLocaleString(Ie());let n=t.hints?.decimals??(Number.isInteger(e)?0:2),r=e.toLocaleString(Ie(),{minimumFractionDigits:n,maximumFractionDigits:n});return`${t.hints?.prefix??``}${r}${t.hints?.suffix??``}`},jv=(e,t,n)=>n?{kind:`list`,resource:t,filter:n}:e?.list?.filter?{kind:`list`,resource:t,filter:``}:{kind:`list`,resource:t},Mv=({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)(Eh,{to:jv(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:xv(`records`,Av(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:Av(n.value,r)})]})},n.key)})})},Nv=`flex items-center gap-2 rounded-md px-1 py-0.5`,Pv=({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:Nv,children:o}):(0,B.jsx)(Eh,{to:jv(t,e,n),className:`group ${Nv} hover:bg-muted`,children:o})})},Fv=(e,t)=>t>0?`${Math.round(e/t*100)}%`:``,Iv=({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:Av(r.value,n)})]})},Lv=({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)(ne,{width:`100%`,height:`100%`,children:(0,B.jsxs)(pe,{children:[(0,B.jsx)(j,{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)(Oe,{fill:e.color},e.key))}),(0,B.jsx)(je,{content:(0,B.jsx)(Iv,{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)(Pv,{resource:e,view:t,filter:n.filter,color:n.color,label:n.label,children:[(0,B.jsx)(`span`,{className:`font-medium tabular-nums`,children:Av(n.value,r)}),(0,B.jsx)(`span`,{className:`w-9 text-right text-xs text-muted-foreground tabular-nums`,children:Fv(n.value??0,a)})]},n.key))})]})},Rv={hour:`2-digit`,minute:`2-digit`,hour12:!1},zv={day:`numeric`,month:`short`,...Rv},Bv={minute:Rv,"5_minutes":Rv,"15_minutes":Rv,hour:Rv,day:{day:`numeric`,month:`short`},week:{day:`numeric`,month:`short`},month:{month:`short`,year:`2-digit`},year:{year:`numeric`}},Vv={minute:zv,"5_minutes":zv,"15_minutes":zv,hour:zv,day:{day:`numeric`,month:`short`,year:`numeric`},week:{day:`numeric`,month:`short`,year:`numeric`},month:{month:`long`,year:`numeric`},year:{year:`numeric`}},Hv=e=>{let t=new Intl.DateTimeFormat(Ie(),{...e,timeZone:`UTC`});return e=>t.format(e)},Uv={fontSize:11,fill:`var(--muted-foreground)`},Wv=864e5,Gv=new Set([`minute`,`5_minutes`,`15_minutes`,`hour`]),Kv=(e,t)=>{let n=t.length>1?t.at(-1).at-t[0].at:0;return Gv.has(e)&&n>=Wv?zv:Bv[e]},qv=({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`?xv(`weekOf`,Hv(Vv[r])(a.at)):Hv(Vv[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:Av(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:Av(a.value,n)}),!i&&(0,B.jsx)(`div`,{className:`font-semibold tabular-nums`,children:Av(a.value,n)})]})},Jv=({points:e,measure:t,bucket:n,type:r,series:i,resource:a,view:o})=>{let s=ud(`(min-width: 640px)`),c=Hv(Kv(n,e)),l=(0,B.jsx)(se,{vertical:!1,stroke:`var(--border)`}),u=(0,B.jsx)(ye,{dataKey:`at`,tickFormatter:c,tick:Uv,axisLine:!1,tickLine:!1,minTickGap:s?24:40,height:18}),d=(0,B.jsx)(oe,{width:s?48:36,tick:Uv,axisLine:!1,tickLine:!1,tickCount:3,tickFormatter:e=>e.toLocaleString(Ie(),{notation:`compact`})}),f=(0,B.jsx)(je,{cursor:r===`bar`?{fill:`var(--muted)`}:{stroke:`var(--border-strong)`},content:(0,B.jsx)(qv,{measure:t,bucket:n,...i&&{series:i}}),isAnimationActive:!1}),p=i??[{key:`value`,label:``,color:`var(--chart-1)`}],m=(0,B.jsx)(`div`,{className:`h-40`,children:(0,B.jsx)(ne,{width:`100%`,height:`100%`,children:r===`line`?(0,B.jsxs)(ie,{data:e,margin:{top:6,right:6,bottom:0,left:0},children:[l,u,d,f,p.map(t=>(0,B.jsx)(ce,{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)(De,{data:e,margin:{top:6,right:0,bottom:0,left:0},barCategoryGap:`22%`,children:[l,u,d,f,p.map((e,t)=>(0,B.jsx)(me,{dataKey:e.key,fill:e.color,...i&&{stackId:`split`},radius:t===p.length-1?[4,4,0,0]:0,isAnimationActive:!1},e.key))]})})});return!i||a===void 0?m:(0,B.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[m,(0,B.jsx)(`ul`,{className:`flex flex-wrap gap-x-3 gap-y-0.5 text-sm`,children:i.map(e=>(0,B.jsx)(Pv,{resource:a,view:o,color:e.color,label:e.label,...e.filter!==void 0&&{filter:e.filter}},e.key))})]})},Yv=1e-6,Xv=(e,t,n,r,i,a=``)=>{let o=t.map((e,t)=>({key:`s${t}`,label:Tv(n,r,e),color:wv(n,r,e.value,t),filter:Ev(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=kv(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<Yv?0:l}});return i.kind!==`average`&&l.some(e=>(e.other??0)>0)?{series:[...o,{key:`other`,label:xv(`other`),color:`var(--border-strong)`}],points:l}:{series:o,points:l.map(({other:e,...t})=>t)}},Zv=(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]}},Qv=(e,t,n)=>{let r=e?.type===`relation`&&e.relation?t[e.relation.resource]:void 0;return r&&r.primaryKey.length===1?ir(r,n[r.name]):void 0},$v=({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=xv(`nothingYet`)})=>{let{resources:f,views:p}=W(),m=e.fields[n],h=m?.type===`date`||m?.type===`timestamp`,g=Qv(m,f,p),_=h&&r!==void 0?e.fields[r]:void 0,v=Qv(_,f,p),y=_?{splitBy:_.name,splitLimit:8,...v&&{splitLabel:v}}:{},b=h?{granularity:c,range:l,timeZone:Gd(),...y}:{limit:u,...g&&{label:g}},x=yv(e.name,{groupBy:n,filter:s,...a&&{sum:a},...o&&{average:o},...b},!!m),S=Zv(e,t,a,o);if(!m)return null;if(x.isPending)return(0,B.jsx)(K,{className:`h-36 w-full`});if(x.error)return(0,B.jsx)(`p`,{className:`text-danger-text`,children:xv(`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}=Xv(C,x.data.splits,_,t?.fields[_.name],S,s);return(0,B.jsx)(Jv,{points:r,measure:S,bucket:c,type:w,series:n,resource:e.name,view:t})}if(h)return(0,B.jsx)(Jv,{points:kv(C,S),measure:S,bucket:c,type:w});let T=Ov(C,m,t?.fields[n],S,s);return i===`donut`?(0,B.jsx)(Lv,{resource:e.name,view:t,slices:T,measure:S}):(0,B.jsx)(Mv,{resource:e.name,view:t,slices:T,measure:S})},ey=({node:e,slots:t})=>{let{resource:n,title:r,description:i,actions:a,span:o,...s}=cv(e),{resources:c,views:l}=W(),u=c[n];return u?(0,B.jsx)(dv,{title:r,description:i,actions:t.actions,className:`h-full`,children:(0,B.jsx)($v,{model:u,view:l[n],...s})}):null},ty=on(),ny=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=ir(n,i),c=await e.fetchQuery({queryKey:H.labels(n.name,o.join(`,`)),staleTime:3e5,queryFn:async()=>(await t.list(n.name,{filter:Jt(ty.in(a,o)),fields:[a,s],pageSize:o.length})).items.map(e=>[String(e[a]),String(e[s])])});return new Map(c)},ry=(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}]:[]}),iy=(e,t,n,r)=>Object.fromEntries(ry(e,n,r).filter(({target:e})=>e.primaryKey.length===1).map(({name:e,target:n})=>[e,ir(n,t[n.name])])),ay=(e,t,n,r,i={})=>{let a=ry(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})},oy=(e,t)=>{let n=String(t);return e&&Object.hasOwn(e,n)?e[n]:void 0},sy=({value:e,hints:t,children:n})=>(0,B.jsx)(hp,{tone:fm(String(e)),color:oy(t?.valueColors,e),shape:t?.badgeShape,children:n}),cy=({field:e,value:t,known:n})=>{let{resources:r,views:i}=W(),a=U(),o=be(),s=e.relation?r[e.relation.resource]:void 0,c=String(t),l=E({queryKey:H.relatedLabel(s?.name??``,c),enabled:!!s&&n===void 0,queryFn:async()=>(await ny(o,a,s,[c],i[s.name])).get(c)??c});return s?(0,B.jsx)(Eh,{to:{kind:`record`,resource:s.name,key:c},className:`font-medium text-primary-text hover:underline`,children:n??l.data??c}):(0,B.jsx)(`span`,{children:c})},ly=({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)(cy,{field:t,value:n,known:i});let s=t.type===`file`?bp(n):void 0;if(s&&`url`in s&&s.url){let e=Op(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)(Lg,{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(rm(t,o))return(0,B.jsx)(i_,{source:String(n)});let c=bm(t,n,o),l=t.type===`text`?cm(o):void 0;return l?(0,B.jsx)(d_,{format:l,value:c}):t.type===`enum`||o.format===`badge`?(0,B.jsx)(sy,{value:n,hints:o,children:c}):(0,B.jsx)(`span`,{title:xm(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})},uy=e=>{let{views:t}=W(),n=Kg(e.field,t[e.model.name]?.fields[e.field.name]),r=(0,B.jsx)(ly,{...e});return n?(0,B.jsx)(n_,{shown:n,part:`display`,field:e.field,value:e.value,fallback:r}):r},dy=(e,t,n)=>{if(!t)return[];let r=pl(e,t.model.name,n);return r.ok?r.steps:[]},fy=(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}}),py=(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}},my=(e,t)=>{let{resources:n}=W(),r=dy(n,e,t);return py(e,r,E(fy(U(),be(),e,t,r)))},hy=(e,t)=>{let{resources:n}=W(),r=U(),i=be(),a=t.map(t=>dy(n,e,t)),o=f({queries:t.map((t,n)=>fy(r,i,e,t,a[n]))});return t.map((t,n)=>py(e,a[n],o[n]))},gy=(e,t)=>{if(t)return t;let n=e.split(`.`).map(e=>F(e).toLowerCase()).join(` `);return n[0].toUpperCase()+n.slice(1)},_y=({node:e})=>{let{name:t,label:n,format:r}=cv(e),{views:i}=W(),a=my(B_(),t);if(a.state===`missing`)return null;let o=a.state===`loading`?(0,B.jsx)(K,{className:`h-4 w-24`}):(0,B.jsx)(uy,{model:a.model,field:a.field,value:a.value,format:r});if(n===!1)return(0,B.jsx)(`div`,{children:o});let s=n??gy(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})]})},vy={1:``,2:`md:grid-cols-2`,3:`md:grid-cols-2 xl:grid-cols-3`,4:`sm:grid-cols-2 xl:grid-cols-4`},yy={1:``,2:`grid-cols-2`,3:`grid-cols-2 xl:grid-cols-3`,4:`grid-cols-2 xl:grid-cols-4`},by={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`},xy=e=>typeof e==`object`&&!e.custom&&e.type===`Stat`,Sy=({node:e,children:t})=>{let{columns:n=2}=cv(e),r=e.children,i=r.length>0&&r.every(xy);return(0,B.jsx)(`div`,{className:P(`grid grid-cols-1 gap-4`,i?yy[n]:vy[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&&by[i]),children:e},t)})})},Cy=`font-medium text-primary-text hover:underline`,wy=({node:e})=>{let t=cv(e),n=B_()?.record,r=e.children.filter(e=>typeof e==`string`).join(``);if(t.to){let e=pn(t.to,n);return(0,B.jsx)(Eh,{to:e,className:Cy,children:r||ic(e)})}let i=t.href??``;return(0,B.jsx)(`a`,{href:i,className:Cy,...i.startsWith(`http`)&&{target:`_blank`,rel:`noreferrer`},children:r||i})},Ty=M({en:{atLeastCharacters:(e,t,n)=>`${e} needs at least ${t} character${n===1?``:`s`}`,atMostCharacters:(e,t,n)=>`${e} can have at most ${t} character${n===1?``:`s`}`,wholeNumberAtLeast:e=>`Enter a whole number of at least ${e}`,wholeNumberAtMost:e=>`Enter a whole number of at most ${e}`,wholeNumber:`Enter a whole number`,number:`Enter a number`,wholeNumberBelow:e=>`Enter a whole number below ${e}`,decimalsBelow:(e,t)=>`Enter a number with at most ${e} decimal${e===1?``:`s`}, below ${t}`,date:`Enter a date`,timestamp:`Enter a date and time`,country:`Enter a two-letter country code, such as NL`,currency:`Enter a three-letter currency code, such as EUR`,uuid:`Enter a valid ID`,enum:`Choose one of the options`,relation:`Choose a record`,json:`Enter valid JSON`,required:e=>`${e} is required`,checkField:`Check the marked field.`,checkFields:e=>`Check ${e} fields.`},nl:{atLeastCharacters:(e,t,n)=>`${e} moet minstens ${t} ${n===1?`teken`:`tekens`} hebben`,atMostCharacters:(e,t,n)=>`${e} mag hoogstens ${t} ${n===1?`teken`:`tekens`} hebben`,wholeNumberAtLeast:e=>`Vul een geheel getal in van minstens ${e}`,wholeNumberAtMost:e=>`Vul een geheel getal in van hoogstens ${e}`,wholeNumber:`Vul een geheel getal in`,number:`Vul een getal in`,wholeNumberBelow:e=>`Vul een geheel getal in onder ${e}`,decimalsBelow:(e,t)=>`Vul een getal in met hoogstens ${e} ${e===1?`decimaal`:`decimalen`}, onder ${t}`,date:`Vul een datum in`,timestamp:`Vul een datum en tijd in`,country:`Vul een landcode van twee letters in, zoals NL`,currency:`Vul een valutacode van drie letters in, zoals EUR`,uuid:`Vul een geldig ID in`,enum:`Kies een van de opties`,relation:`Kies een record`,json:`Vul geldige JSON in`,required:e=>`${e} is verplicht`,checkField:`Controleer het gemarkeerde veld.`,checkFields:e=>`Controleer ${e} velden.`}}),Ey=(e,t)=>typeof e?.[t]==`number`?e[t]:void 0,Dy=(e,t)=>{let n=Ey(t,`min`),r=Ey(t,`max`);if(n!==void 0)return Ty(`atLeastCharacters`,e,Vd(n),n);if(r!==void 0)return Ty(`atMostCharacters`,e,Vd(r),r)},Oy=e=>{let t=Ey(e,`min`),n=Ey(e,`max`);return t===void 0?n===void 0?Ty(`wholeNumber`):Ty(`wholeNumberAtMost`,Vd(n)):Ty(`wholeNumberAtLeast`,Vd(t))},ky=e=>{let t=Ey(e,`precision`),n=Ey(e,`scale`);if(t===void 0||n===void 0)return Ty(`number`);let r=Vd(10**(t-n));return n===0?Ty(`wholeNumberBelow`,r):Ty(`decimalsBelow`,n,r)},Ay={text:Dy,integer:(e,t)=>Oy(t),bigint:()=>Ty(`wholeNumber`),decimal:(e,t)=>ky(t),date:()=>Ty(`date`),timestamp:()=>Ty(`timestamp`),country:()=>Ty(`country`),currency:()=>Ty(`currency`),uuid:()=>Ty(`uuid`),enum:()=>Ty(`enum`),relation:()=>Ty(`relation`),json:()=>Ty(`json`)},jy=(e,t,n)=>n.code===`required`?Ty(`required`,t):n.code!==`invalid-value`||!e?n.message:Ay[e.type]?.(t,n.params)??n.message,My=e=>{if(!jc(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},Ny=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?Ty(`checkField`):Ty(`checkFields`,t.size)],...n].join(` `)},Py=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},Fy=(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]:Bh(n[t])];let i=r.default&&`value`in r.default?r.default.value:void 0;return[t,r.type===`boolean`?!!i:Bh(i)]})),Iy=(e,t,n)=>Object.fromEntries(Object.entries(t).flatMap(([t,r])=>{let i=e.fields[t];return tg(r)?r.key===Bh(n[t])?[]:[[t,i.type===`integer`?Number(r.key):r.key]]:Yh(i,r,n[t])?[[t,Kh(i,r)]]:[]})),Ly=({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=Gf(),f=iv(),p=l[e.name],[m,h]=(0,I.useState)(()=>Fy(e,a,t?.record)),[g,_]=(0,I.useState)({}),[v,y]=(0,I.useState)(0),b=Py(v),[x,S]=(0,I.useState)(),[C,w]=(0,I.useState)(!1),[T,E]=(0,I.useState)(!1);wh(T||C,`input-lost`);let D=async()=>{w(!0),S(void 0),await(n===`create`?u.create(e.name,{...ag(e,c,m),...o}):u.update(e.name,t.key,Iy(e,m,t.record),t.etag??`*`)).then(async()=>{await f(e.name),d.show({state:`success`,title:Y(`saved`,i??r)}),s()},e=>{let t=My(e);_(t),Object.keys(t).length>0&&y(e=>e+1),S(e)}),w(!1)};return(0,B.jsx)(vd,{title:i??r,onClose:s,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:s,children:Y(`cancel`)}),(0,B.jsx)(G,{variant:`primary`,loading:C,onClick:()=>void D(),children:Y(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)(pg,{title:Y(`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)(ep,{name:n,label:o,help:p?.fields[n]?.help,error:s&&jy(r,o,s),children:(0,B.jsx)(y_,{field:r,hints:p?.fields[n],value:tg(i)?i.key:i,stored:t?.record[n],relationLabel:tg(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)})]})})},Ry=({model:e,recordKey:t,children:n})=>{let r=nv(e,{key:t});return(0,B.jsx)(B.Fragment,{children:n(r.data??void 0)})},zy=({node:e})=>{let t=cv(e),n=B_(),{resources:r}=W(),i=r[t.resource??n?.model.name??``],a=ed(i?.name??``),[o,s]=(0,I.useState)(!1);if(!i||!(t.mode===`create`?V_(a,`create`):V_(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)(Ly,{...t,model:i,record:t.mode===`edit`?e:void 0,onClose:()=>s(!1)})]});return t.mode===`edit`&&t.recordKey!==void 0?(0,B.jsx)(Ry,{model:i,recordKey:t.recordKey,children:c}):c(t.mode===`edit`?n:void 0)},By=e=>e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey,Vy=`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`,Hy=({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":Pf(`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&&By(n)&&(n.preventDefault(),t(e.href))},className:P(Vy,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(Vy,s?`text-primary-text`:`text-muted-foreground`),children:[(0,B.jsx)(Ki,{className:`size-6`,strokeWidth:s?2.2:1.9,"aria-hidden":!0}),Pf(`more`)]})]})]})},Uy=({id:e,open:t,onClose:n,children:r})=>{let i=(0,I.useRef)(null);return _d(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":Pf(`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},Wy=(0,I.createContext)(()=>{}),Gy=e=>{let t=(0,I.useContext)(Wy);(0,I.useLayoutEffect)(()=>(t(e),()=>t(void 0)),[t,e])},Ky=e=>{(0,I.useLayoutEffect)(()=>{if(!e)return;let t=document.documentElement;return t.style.setProperty(`scrollbar-gutter`,`stable`),()=>{t.style.removeProperty(`scrollbar-gutter`)}},[e])},qy=[`--pb-sticky-top`,`--pb-sticky-bottom`,`scroll-padding-top`,`scroll-padding-bottom`],Jy=(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 qy)r.style.removeProperty(e)}},[e,t,n,r])},Yy=`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`,Xy=`fill-[#ff5a1f] dark:fill-[#ff6a33]`,Zy=`fill-[#14161a] dark:fill-[#f1f0ea]`,Qy=({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:Xy,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:Zy,d:`M17 0h10a5 5 0 0 1 5 5v22a5 5 0 0 1-5 5H5a5 5 0 0 1-5-5V17h17z`})]}),$y=({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:Zy,d:Yy})}),eb=`Protobase`,tb=({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)(Qy,{}),!e&&(0,B.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-0.5 leading-tight`,children:[r||n&&n!==eb?(0,B.jsx)(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:n??eb}):(0,B.jsx)($y,{className:`self-start`}),t&&(0,B.jsx)(`div`,{className:`truncate text-[11px] text-muted-foreground`,children:t})]})]}),nb=[{label:`Sales`,items:[{id:`orders`,label:`Orders`,icon:Go,count:12},{id:`customers`,label:`Customers`,icon:ei},{id:`invoices`,label:`Invoices`,icon:ia,count:3}]},{label:`Inventory`,items:[{id:`products`,label:`Products`,icon:oo},{id:`stock-moves`,label:`Stock moves`,icon:Qr},{id:`warehouses`,label:`Warehouses`,icon:Ns},{id:`shipments`,label:`Shipments`,icon:xs}]},{label:`Finance`,items:[{id:`payments`,label:`Payments`,icon:Ii},{id:`credit-notes`,label:`Credit notes`,icon:Co},{id:`reports`,label:`Reports`,icon:oi}]},{label:`Admin`,items:[{id:`users`,label:`Users`,icon:ks},{id:`settings`,label:`Settings`,icon:zo}]}],rb=({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)(ui,{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))]}),ib=()=>[{value:`light`,label:Pf(`light`),icon:as},{value:`dark`,label:Pf(`dark`),icon:no},{value:`system`,label:Pf(`system`),icon:eo}],ab=({theme:e,className:t})=>(0,B.jsxs)(`div`,{className:t,children:[(0,B.jsx)(rs,{className:`size-4`}),(0,B.jsx)(`span`,{className:`flex-1`,children:Pf(`theme`)}),(0,B.jsx)(Le,{label:Pf(`theme`),iconOnly:!0,value:e.preference,options:ib(),onChange:e.onChange})]}),ob=`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`,sb=({user:e,compact:t,open:n,items:r=[],account:i,onNavigate:a,onSignOut:o,organizations:s,roles:c,theme:l})=>{let u=c?.roles.find(e=>e.name===c.active),[d,f]=(0,I.useState)(!1),p=n??d,m=(0,I.useRef)(null),[h,g]=(0,I.useState)();(0,I.useEffect)(()=>{if(!p||n!==void 0)return;let e=e=>{(e instanceof KeyboardEvent?e.key===`Escape`:!m.current?.contains(e.target))&&f(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,e),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,e)}},[p,n]);let _=r.filter(e=>e.length>0),v=(e,t,n)=>{f(!1),!n&&a&&(e.preventDefault(),a(t))};return(0,B.jsxs)(`div`,{ref:m,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":Pf(`profileMenu`),"aria-haspopup":`menu`,"aria-expanded":p,onClick:()=>{let e=m.current?.getBoundingClientRect();e&&g({left:e.left,bottom:window.innerHeight-e.top+8}),f(!d)},children:[(0,B.jsx)(Qf,{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:[(0,B.jsx)(`span`,{className:`block truncate font-medium`,children:e.name}),(0,B.jsx)(hp,{tone:e.roleTone,dot:!1,className:`mt-0.5 h-4 px-1.5 text-[10px]`,children:e.role})]}),(0,B.jsx)(vi,{className:`size-3.5 shrink-0 text-faint-foreground`})]})]}),p&&(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&&h?{left:h.left,bottom:h.bottom}:void 0,children:[i?(0,B.jsxs)(`a`,{role:`menuitem`,href:i,onClick:e=>v(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})]}),s&&(s.current||s.others.length>0)&&(0,B.jsx)(rb,{label:Pf(`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:ob,onSwitch:e=>{f(!1),s.onSwitch(e)}}),c&&c.roles.length>1&&(0,B.jsx)(rb,{label:Pf(`roles`),...u&&{current:{id:u.name,label:u.label}},others:c.roles.filter(e=>e!==u).map(({name:e,label:t})=>({id:e,label:t})),rowClassName:ob,onSwitch:e=>{f(!1),c.onSwitch(e)}}),_.map((e,t)=>(0,B.jsx)(`div`,{role:`group`,className:P(`py-1`,(t<_.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=>v(t,e.href,e.external),className:P(ob,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)(ab,{theme:l,className:P(ob,`hover:bg-transparent`)})}),o&&(0,B.jsxs)(`button`,{type:`button`,role:`menuitem`,onClick:o,className:ob,children:[(0,B.jsx)(Ha,{className:`size-4`}),Pf(`signOut`)]})]})]})},cb=`protobase:nav-open:`,lb=e=>`${cb}${e}`,ub=(e,t)=>Fe(()=>e.getItem(t)!==`false`,!0),db=(e,t,n)=>Fe(()=>n?e.removeItem(t):e.setItem(t,`false`),void 0),fb=({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})]}),pb=e=>e===`text-large`||e===`text-small`||e===`icon-expand`,mb=e=>e===`text-large`||e===`text-small`,hb={"text-large":`w-60`,"text-small":`w-52`,icon:`w-14`,"icon-label":`w-[76px]`,"icon-tooltip":`w-14`,"icon-expand":`w-14`},gb={"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`},_b=({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`,gb[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}),(pb(t)||t===`icon-label`)&&(0,B.jsx)(`span`,{className:`whitespace-nowrap`,children:e.label}),mb(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}),mb(t)&&e.problem&&(0,B.jsx)(ys,{"aria-hidden":!0,className:`ml-auto size-3.5 shrink-0 text-warning-text`})]});return t===`icon-tooltip`?(0,B.jsx)(fb,{label:e.label,children:o}):o},vb={neutral:`bg-faint-foreground`,info:`bg-primary`,success:`bg-success`,warning:`bg-warning`,danger:`bg-danger`},yb=({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`,vb[e])}),(0,B.jsx)(`span`,{className:P(`relative size-2 rounded-full`,vb[e])})]}),bb={"text-large":`h-8 gap-2.5 px-2.5`,"text-small":`h-7 gap-2 px-2 text-body`},xb={"text-large":`ml-[20px]`,"text-small":`ml-[17px]`},Sb=({item:e,recent:t,mode:n,active:r,onNavigate:i})=>{let a=lb(e.id),[o,s]=(0,I.useState)(()=>ub(localStorage,a)),c=(0,I.useId)(),l=e.href??`#${e.id}`,u=()=>{db(localStorage,a,!o),s(!o)},d=e=>({href:e,onClick:i&&(t=>{t.preventDefault(),i(e)})});return(0,B.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,B.jsxs)(`div`,{className:`relative`,children:[(0,B.jsx)(_b,{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":Pf(`recent`,e.label.toLowerCase()),onClick:u,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)(gi,{className:P(`size-3.5 transition-transform`,o&&`rotate-90`)})})]}),o&&(0,B.jsxs)(`ul`,{id:c,"aria-label":Pf(`recent`,e.label.toLowerCase()),className:P(`flex flex-col gap-0.5 border-l pl-1.5`,xb[n]),children:[t.state===`loading`&&(0,B.jsx)(`li`,{className:P(`flex items-center text-faint-foreground`,bb[n]),children:Pf(`loading`)}),t.state===`error`&&(0,B.jsx)(`li`,{className:P(`flex items-center text-faint-foreground`,bb[n]),children:Pf(`couldNotLoad`)}),t.state===`ready`&&t.records.map(e=>(0,B.jsx)(`li`,{children:(0,B.jsxs)(`a`,{...d(e.href),"aria-label":e.status?`${e.label}, ${e.status.label}`:e.label,title:e.status?`${e.label} (${e.status.label})`:e.label,"aria-current":e.active?`page`:void 0,className:P(`flex min-w-0 items-center rounded-md font-medium transition-colors`,bb[n],e.active?`bg-muted text-foreground`:`text-muted-foreground hover:bg-muted hover:text-foreground`),children:[e.status&&(0,B.jsx)(yb,{tone:e.status.tone,pulse:e.status.pulse}),(0,B.jsx)(`span`,{className:`truncate`,children:e.label})]})},e.id)),(0,B.jsx)(`li`,{children:(0,B.jsx)(`a`,{...d(l),className:P(`flex items-center rounded-md text-faint-foreground transition-colors hover:bg-muted hover:text-foreground`,bb[n]),children:Pf(`viewAll`)})})]})]})},Cb=({mode:e,activeItem:t,user:n,workspace:r,appName:i,appIcon:a,forceExpanded:o,profileMenuOpen:s,groups:c=nb,userMenu:l,account:u,onNavigate:d,onSignOut:f,signIn:p,organizations:m,roles:h,theme:g,sticky:_,logo:v=tb,notice:y})=>{let b=e===`icon-expand`,x=b&&o,S=mb(e)||b;return(0,B.jsx)(`nav`,{"aria-label":Pf(`resources`),className:P(_?`sticky top-0 h-dvh self-start`:`relative`,`z-30 shrink-0`,hb[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)]`,b?`w-14 transition-[width,box-shadow] duration-150 hover:w-60 hover:shadow-pop focus-within:w-60 focus-within:shadow-pop`:`w-full`,x&&`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)(v,{compact:!S,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:[S?n.label&&(0,B.jsx)(`div`,{className:P(`px-3 pb-1 pt-1 text-xs font-medium uppercase tracking-wide text-faint-foreground`,b&&`h-4 whitespace-nowrap py-0 opacity-0 transition-opacity group-hover/side:opacity-100 group-focus-within/side:opacity-100`,x&&`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=>n.recent&&mb(e)?(0,B.jsx)(Sb,{item:n,recent:n.recent,mode:e,active:n.id===t,onNavigate:d},n.id):(0,B.jsx)(_b,{item:n,mode:e,active:n.id===t,onNavigate:d},n.id))]},n.label))}),y,(0,B.jsx)(`div`,{className:P(`shrink-0 border-t p-2`,e!==`text-large`&&e!==`text-small`&&!b&&`flex justify-center`),children:n?(0,B.jsx)(sb,{user:n,compact:!S,open:s,items:l,account:u,onNavigate:d,onSignOut:f,organizations:m,roles:h,theme:g}):(0,B.jsxs)(B.Fragment,{children:[g&&S&&(0,B.jsx)(ab,{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)(ah,{to:p,"aria-label":Pf(`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)(Ba,{className:`size-4 shrink-0`}),S&&(0,B.jsx)(`span`,{className:`whitespace-nowrap`,children:Pf(`signIn`)})]})]})})]})})},wb=e=>dd()&&mb(e),Tb=(0,I.createContext)(null),Eb=()=>(0,I.useContext)(Tb),Db=e=>{let t=e.at(-2);if(typeof t==`object`&&t.href&&!t.loading)return{label:t.label,href:t.href}},Ob=({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}),kb=(e,t,n)=>t===0?-1:e<0?n===1?0:t-1:(e+n+t)%t,Ab=e=>e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||e.button!==0,jb=({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=>kb(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)(Xf,{ref:m,wrapperClassName:`w-full bg-surface shadow-none`,leading:e.loading?(0,B.jsx)(Yu,{className:`size-4`}):(0,B.jsx)(jo,{className:`size-4`}),trailing:e.text?(0,B.jsx)(`button`,{type:`button`,"aria-label":Pf(`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)(Ls,{className:`size-3.5`})}):r?(0,B.jsx)(`span`,{className:`hidden md:inline-flex`,children:(0,B.jsx)(Ob,{children:`⌘K`})}):void 0,placeholder:e.placeholder,"aria-label":Pf(`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":Pf(`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?Pf(`searching`):Pf(`noMatches`,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:Pf(`couldNotSearch`,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=>{Ab(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))]})]})},Mb=({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=Db(e),m=(0,I.useRef)(null);return(0,I.useEffect)(()=>{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":Pf(`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)(Xa,{className:`size-5`})}),p&&(0,B.jsx)(`a`,{href:p.href,"aria-label":Pf(`backTo`,p.label),onClick:e=>{let r=n??t;r&&Ff(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)(mi,{className:`size-5`})}),(0,B.jsx)(If,{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)(jb,{ref:m,search:s})}),(0,B.jsx)(`button`,{type:`button`,"aria-label":Pf(`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)(jo,{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)(jb,{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":Pf(`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)(Ls,{className:`size-5`})})]})]}),c&&(0,B.jsx)(`div`,{"aria-hidden":!0,className:`h-[var(--pb-sticky-top)] shrink-0 md:hidden`})]})},Nb=`app-drawer`,Pb=({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,search:T,pageScroll:E=!1,className:D,children:O})=>{let k=dd(),A=wb(e),[j,ee]=(0,I.useState)(!1);(0,I.useEffect)(()=>{k&&ee(!1)},[k]);let te=!k&&_&&_.length>0?_:void 0,[ne,re]=(0,I.useState)(),ie=ne??E,ae=(0,I.useRef)(null),[oe,se]=(0,I.useState)(null),ce=(0,I.useRef)(null);Jy(ie,ae,ce,!!te),Ky(ie);let le=(e,n=!1,c)=>(0,B.jsx)(Cb,{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,logo:s});return(0,B.jsx)(Wy.Provider,{value:re,children:(0,B.jsxs)(`div`,{className:P(ie?`flex min-h-full w-full overflow-x-clip bg-background`:`relative flex h-full min-h-0 w-full overflow-hidden bg-background`,D),children:[k?le(e,ie,A&&u):(0,B.jsx)(Uy,{id:Nb,open:j,onClose:()=>ee(!1),children:le(`text-large`)}),(0,B.jsxs)(`div`,{className:P(`flex min-w-0 flex-1 flex-col`,!te&&`pb-[var(--pb-safe-bottom)]`),children:[(0,B.jsx)(Mb,{ref:ae,slotRef:se,sticky:ie,breadcrumb:n,onNavigate:v,onBack:y,actions:c,onMenu:k||te?void 0:()=>ee(!0),menuOpen:j,menuControls:Nb,search:T}),d,(0,B.jsx)(`main`,{className:ie?`flex flex-1 flex-col`:`flex min-h-0 flex-1 flex-col`,children:(0,B.jsx)(Tb.Provider,{value:oe,children:O})}),te&&(0,B.jsx)(Hy,{ref:ce,sticky:ie,tabs:te,onNavigate:v,onMore:()=>ee(!0),moreOpen:j,moreControls:Nb})]}),l&&(0,B.jsx)(`div`,{className:ie?`sticky top-0 flex h-dvh shrink-0 self-start pt-[var(--pb-safe-top)]`:`flex shrink-0`,children:l})]})})},Fb=({title:e,subtitle:t,actions:n,subtitleBelow:r})=>r?(0,B.jsx)(Ib,{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})]}),Ib=({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})]}),Lb=({node:e,children:t,slots:n})=>{let{title:r,description:i}=cv(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)(Fb,{title:r,subtitle:i,actions:n.actions}),t]})})},Rb=(e,t)=>{let n=B_(),r=my(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},zb=({node:e})=>{let{value:t,max:n,label:r}=cv(e),i=Rb(t,0),a=Rb(n,100);if(i===void 0||a===void 0)return(0,B.jsx)(K,{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(Ie()),` / `,a.toLocaleString(Ie())]})]}),(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}%`}})})]})},Bb=({model:e,filter:t,sort:n,recordKey:r,title:i,description:a,empty:o,actions:s,children:c})=>{let l=nv(e,{filter:t,sort:n,key:r}),u=e=>l.data?(0,B.jsx)(z_,{value:l.data,children:e}):void 0,d=l.isPending?(0,B.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,B.jsx)(K,{className:`h-4 w-1/2`}),(0,B.jsx)(K,{className:`h-4 w-1/3`})]}):l.error?(0,B.jsx)(pg,{title:Y(`couldNotLoad`),error:l.error}):l.data?u((0,B.jsx)(`div`,{className:`flex flex-col gap-3`,children:c})):(0,B.jsx)(fv,{children:o??Y(`nothingYet`)});return(0,B.jsx)(dv,{title:i,description:a,actions:s?u(s):void 0,className:`h-full`,children:d})},Vb=({node:e,children:t,slots:n})=>{let{resource:r,filter:i,sort:a,recordKey:o,title:s,description:c,empty:l}=cv(e),u=W().resources[r];return u?(0,B.jsx)(Bb,{model:u,filter:i,sort:a,recordKey:o,title:s,description:c,empty:l,actions:n.actions,children:t}):null},Hb=`0.75rem`,Ub=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% + ${Hb}) * ${e} - ${Hb})`},Wb=({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:Hb,scrollbarWidth:`thin`,"--snap-item-width":Ub(e)},children:n}),Gb=M({en:{firstOf:(e,t)=>`The first ${e} of ${t}.`,firstOfAbout:(e,t)=>`The first ${e} of about ${t}.`,open:e=>`Open ${e}`,edit:e=>`Edit ${e}`,viewAll:`View all`,couldNotLoad:`Could not load`,nothingYet:`Nothing here yet.`},nl:{firstOf:(e,t)=>`De eerste ${e} van ${t}.`,firstOfAbout:(e,t)=>`De eerste ${e} van ongeveer ${t}.`,open:e=>`${e} openen`,edit:e=>`${e} bewerken`,viewAll:`Alles bekijken`,couldNotLoad:`Kon niet laden`,nothingYet:`Hier staat nog niets.`}}),Kb=(e,t,n)=>{if(!(e>=t))return Gb(n?`firstOfAbout`:`firstOf`,e,t.toLocaleString(Ie()))},qb=`protobase:embedded-display:`,Jb=e=>`${qb}${e}`,Yb=(e,t)=>Fe(()=>e.getItem(t)??void 0,void 0),Xb=(e,t,n)=>Fe(()=>e.setItem(t,n),void 0),Zb=(e,t,{picked:n,preferred:r})=>{let i=Bm(e).map(e=>e.name);return n!==void 0&&i.includes(n)?n:Mm(e,t,r!==void 0&&i.includes(r)?r:void 0)},Qb=(e,t,n,{resource:r=e.name,...i})=>ih({kind:`list`,resource:r},i,{...nh(e,t,n),display:Mm(t,n)}),$b=M({en:{showMore:`Show more`,showLess:`Show less`,couldNotLoad:`Could not load`,nothingYet:`Nothing here yet.`},nl:{showMore:`Meer tonen`,showLess:`Minder tonen`,couldNotLoad:`Kon niet laden`,nothingYet:`Hier staat nog niets.`}}),ex=({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:$b(n?`showLess`:`showMore`)})]})},tx=e=>e==null||e===``,nx=({scope:e,path:t})=>{let{views:n}=W(),r=my(e,t);if(r.state===`missing`||r.state===`ready`&&tx(r.value))return null;let i=gy(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)(K,{className:`h-4 w-24`}):(0,B.jsx)(ex,{children:(0,B.jsx)(uy,{model:r.model,field:r.field,value:r.value})})})]})},rx=({scope:e,view:t,fields:n,actions:r})=>(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)(Eh,{to:{kind:`record`,resource:e.model.name,key:om(e.model,e.record)},className:`self-start font-medium text-primary-text hover:underline`,children:or(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)(nx,{scope:e,path:t},t))}),r.length>0&&(0,B.jsx)(z_,{value:e,children:(0,B.jsx)(`div`,{className:`flex flex-wrap items-center gap-2`,children:r.map(e=>(0,B.jsx)(lv,{name:e},e))})})]}),ix=({model:e,view:t,filter:n,sort:r,fields:i,actions:a,limit:o,display:s,empty:c,carousel:l})=>{let u=fd(),d=r||Qm(e,t),f=rv(e,{filter:n,sort:d,pageSize:o}),p=tv(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)(K,{className:`h-24 w-full`},t))});if(f.error)return(0,B.jsx)(pg,{title:$b(`couldNotLoad`),error:f.error});let m=f.data.items;if(m.length===0)return(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:c??$b(`nothingYet`)});let h=m.map(n=>{let r=$_(e,n);return(0,B.jsx)(rx,{scope:r,view:t,fields:i,actions:a},r.key)}),g=p.data===void 0?void 0:Kb(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)(Wb,{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)(Eh,{to:Qb(e,t,u,{filter:n,orderBy:d,display:Zb(t,u,{preferred:s})}),className:`flex items-center gap-1 font-medium text-primary-text hover:underline`,children:[Gb(`viewAll`),` `,(0,B.jsx)(`span`,{className:`sr-only`,children:(t?.names?.plural??F(e.name)).toLowerCase()}),(0,B.jsx)(Sr,{className:`size-3.5`,"aria-hidden":!0})]})]})]})},ax={"1/4":1/4,"1/3":1/3,"1/2":1/2,"2/3":2/3},ox=({node:e,slots:t})=>{let n=cv(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}=fl(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)(tp,{title:u,help:d,actions:t.actions,children:(0,B.jsx)(ix,{model:_,view:v,filter:i,sort:a,fields:o??mr(_,v),actions:s,limit:c,display:l,empty:f,carousel:p===`carousel`?ax[m]:void 0})})})},sx=e=>t=>{let n=t.currentTarget;n.scrollWidth>Math.ceil(n.getBoundingClientRect().width)?n.title=e:n.removeAttribute(`title`)},cx=({text:e,className:t})=>(0,B.jsx)(`span`,{className:P(`truncate`,t),onMouseEnter:sx(e),children:e}),lx=e=>(0,B.jsx)(`span`,{className:`text-faint-foreground`,children:e}),ux=(e,t)=>{if(t==null)return lx(`—`);let n=Pp(e,t)??``;switch(e.kind){case`text`:return e.link?(0,B.jsx)(d_,{format:e.link,value:n,className:`block min-w-0 truncate`}):(0,B.jsx)(cx,{text:n});case`id`:return(0,B.jsx)(cx,{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?ff(Number(t)):Mp(`shownIn`,ef(Number(t),Gd())),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?lx(`—`):(0,B.jsx)(`span`,{className:`tabular-nums`,children:n});case`status`:return(0,B.jsx)(hp,{tone:e.tones?.[String(t)]??`neutral`,color:oy(e.colors,t),shape:e.shape,children:n});case`relation`:return(0,B.jsx)(cx,{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)(ui,{className:`size-3`,strokeWidth:3})}):lx(Mp(`no`));case`file`:{let e=bp(t);if(!e)return lx(`—`);if(`missing`in e)return(0,B.jsx)(cx,{text:e.name,className:`text-danger-text`});let n=Op(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)(Lg,{image:n,className:`size-5 shrink-0 rounded-sm object-cover`}):(0,B.jsx)(co,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,B.jsx)(cx,{text:e.name})]})}case`user`:{let e=Ed(String(t));return(0,B.jsxs)(`span`,{className:`inline-flex items-center gap-2 truncate`,children:[(0,B.jsx)(Qf,{initials:e.initials,hue:e.hue,size:`xs`,className:`ring-0`}),(0,B.jsx)(cx,{text:e.name,className:`text-muted-foreground`})]})}}},dx=Ce({rowSortingFeature:ee,rowSelectionFeature:_e}),fx=re(),px=e=>fx.columns(e.map(e=>fx.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):ux(e,t.getValue())}))),mx=(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}]}),hx=({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:[Wd(e),t>0&&(0,B.jsx)(`span`,{className:`ml-3 font-medium text-primary-text`,children:Mp(`selected`,Vd(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))]})}),gx=(e,t)=>typeof e.label==`string`?e.label:e.label(t),_x=(e,t)=>e.filter(e=>e.available?.(t)??!0),vx=({row:e,actions:t})=>{let{open:n,setOpen:r,place:i,button:a,menu:o}=Fh();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":Mp(`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)(Ki,{className:`size-4`})}),n&&(0,Bs.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=gx(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?(0,B.jsx)(ah,{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)]})},yx=e=>52+Math.ceil(String(e).length*1.33)*7,bx=.6,xx=(e,t)=>Math.max(e.minWidth??0,e.width*t),Sx=(e,t)=>e.fixed?`${Math.max(e.minWidth??0,e.width)}px`:`minmax(${xx(e,t)}px, ${e.width}fr)`,Cx=(e,t,n=0,r=bx)=>`${t}px ${e.map(e=>Sx(e,r)).join(` `)}${n>0?` ${n}px`:``}`,wx=(e,t,n=0,r=bx)=>t+n+e.reduce((e,t)=>e+(t.fixed?Math.max(t.minWidth??0,t.width):xx(t,r)),0),Tx=()=>{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}},Ex=`protobase:pinned:`,Dx=(e,t)=>`${Ex}${e}:${t}`,Ox=(e,t)=>Fe(()=>{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),kx=(e,t,n)=>Fe(()=>e.setItem(t,JSON.stringify(n)),void 0),Ax=(e,t=[])=>{let[n,r]=(0,I.useState)(()=>e?Ox(localStorage,e):void 0),i=(0,I.useCallback)(t=>{r(t),e&&kx(localStorage,e,t)},[e]);return[n??t,i]},jx=e=>{let t=e.findIndex(e=>e.title);return t<0||t>1?[]:e.slice(0,t+1).map(e=>e.id)},Mx=e=>Object.fromEntries(e.map(({id:e,width:t,minWidth:n,fixed:r})=>[e,{width:t,minWidth:n,fixed:r}])),Nx=(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:Mx(Zp(e,t))});let o=a?.sizes;return(0,I.useMemo)(()=>o?e.map(e=>({...e,...o[e.id]})):e,[e,o])},Px=(e,t)=>Math.max(Math.min(64,e),Math.round(e+t)),Fx=(e,t)=>e.map(e=>e.id in t?{...e,fixed:!0,width:t[e.id],minWidth:void 0}:e),Ix=e=>Object.fromEntries([...e.querySelectorAll(`[data-col-id]`)].map(e=>[e.dataset.colId,e.offsetWidth])),Lx=e=>{let[t,n]=(0,I.useState)({}),r=()=>({...e.current?Ix(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]:Px(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]:Px(a[e]??0,i)})}}},Rx=({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)(Qa,{className:`size-3`,strokeWidth:3}):e&&(0,B.jsx)(ui,{className:`size-3`,strokeWidth:3})}),zx=e=>e===`money`||e===`number`||e===`signed`||e===`percent`,Bx=()=>Mp(`unsortable`),Vx=({header:e,pinned:t,sortable:n,onTogglePin:r})=>{let{open:i,setOpen:a,place:o,button:s,menu:c}=Fh();return(0,B.jsxs)(`div`,{className:`relative ml-auto shrink-0`,children:[(0,B.jsx)(`button`,{ref:s,type:`button`,"aria-label":Mp(`columnMenu`,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)(Ki,{className:`size-3.5`})}),i&&(0,Bs.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:Bx()})}),(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:Mp(t?`unpin`:`pinToLeft`)})})]}),document.body)]})},Hx=({id:e,header:t,width:n,resize:r})=>(0,B.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":Mp(`resizeColumn`,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`})}),Ux=({sorted:e})=>e===`asc`?(0,B.jsx)(Or,{className:`size-3 text-foreground`}):e===`desc`?(0,B.jsx)(vr,{className:`size-3 text-foreground`}):(0,B.jsx)(vi,{className:`size-3 opacity-0 group-hover/head:opacity-100`}),Wx=({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:Mp(`new`)})]}),Gx=({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:Cx(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)(Rx,{checked:!1,indeterminate:r>0,label:Mp(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`,zx(e.kind)&&`justify-end`,`hover:text-foreground`,t&&`text-foreground`),children:[(0,B.jsx)(Wx,{spec:e}),(0,B.jsx)(Ux,{sorted:t})]}):(0,B.jsx)(`div`,{title:Bx(),className:P(`flex h-full min-w-0 flex-1 items-center gap-1 pl-3 pr-1 text-left`,zx(e.kind)&&`justify-end`),children:(0,B.jsx)(Wx,{spec:e})}),(0,B.jsx)(`div`,{className:`pr-1.5`,children:(0,B.jsx)(Vx,{header:e.header,pinned:r,sortable:!!e.sortable,onTogglePin:()=>u(e.id)})}),d&&(0,B.jsx)(Hx,{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]}),Kx=e=>({gridTemplateColumns:Cx(e.specs,e.gutter,e.trailing,e.minScale),height:e.height,transform:`translateY(${e.offset}px)`}),qx=(e,t)=>P(`flex h-full min-w-0 items-center overflow-hidden whitespace-nowrap px-3`,zx(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)]`),Jx=(e,t)=>t&&e.id in t?{left:t[e.id]}:void 0,Yx=({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)(Rx,{checked:!!r,label:Mp(`selectRow`,t+1)}),e>40&&(0,B.jsx)(`span`,{className:`min-w-6 text-right text-[11px] tabular-nums text-faint-foreground`,children:Vd(t+1)})]}),Xx=(e,t,n)=>({gridTemplateColumns:Cx(e.specs,e.gutter,e.trailing,e.minScale),height:e.height,top:e.offset,transform:t===0?void 0:`translateY(${t}px)`,transition:n}),Zx=e=>t=>{t.target.closest(`a`)||e()},Qx=({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&&Zx(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?Kx(u):Xx(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)(Yx,{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(qx(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:Jx(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})]}),$x=[`w-3/4`,`w-1/2`,`w-2/3`,`w-5/6`,`w-2/5`],eS=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:Kx(e),children:[(0,B.jsx)(Yx,{width:e.gutter,index:e.index,selectable:!1,edge:e.scrolled&&!e.lastPinned}),e.specs.map((t,n)=>(0,B.jsx)(`div`,{className:qx(t,e),style:Jx(t,e.pins),children:(0,B.jsx)(K,{className:P(`h-2.5`,$x[(e.index+n)%$x.length],zx(t.kind)&&`ml-auto`)})},t.id))]}),tS=(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}}},nS=(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)},rS=(e,t)=>Math.max(0,Math.min(40,e-t*40)),iS=({total:e,rowAt:t,loadRows:n,revision:r,latencyMs:i},a,o)=>{let s=(0,I.useMemo)(()=>tS(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=nS(u*40,d*40,40).filter(e=>!s.hasPage(e)),a=t=>rS(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=nS(u*40,d*40,40);s.keepOnly(t);for(let r of t.filter(e=>s.hasPage(e)))n(r*40,rS(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])},aS=1e7,oS=(e,t,n)=>{let r=e*t,i=Math.min(r,aS);return{rowHeight:t,trueHeight:r,contentHeight:i,scaled:r>i,maxTop:Math.max(0,r-n),maxScroll:Math.max(0,i-n)}},sS=(e,t)=>!e.scaled||t<=0?t:t>=e.maxScroll?e.maxTop+t-e.maxScroll:t/e.maxScroll*e.maxTop,cS=(e,t)=>!e.scaled||t<=0?t:t>=e.maxTop?e.maxScroll+t-e.maxTop:t/e.maxTop*e.maxScroll,lS=(e,t,n,r)=>{let i=t*e.rowHeight;return e.scaled?i-n+r:i},uS=(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)}},dS=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},fS=e=>e===(document.scrollingElement??document.documentElement),pS=e=>fS(e)?window:e,mS=e=>Number.parseFloat(e)||0,hS=e=>{let t=getComputedStyle(e),n=fS(e)?{top:0,height:e.clientHeight}:{top:e.getBoundingClientRect().top+e.clientTop,height:e.clientHeight},r=mS(t.scrollPaddingTop);return{top:n.top+r,height:Math.max(0,n.height-r-mS(t.scrollPaddingBottom))}},gS=6,_S=(e,t,n)=>{let r=oS(t,n,e.height),i=sS(r,e.position);return{geometry:r,top:i,topIndex:Math.floor(Math.max(0,i)/n),...uS(t,i,n,e.height,gS)}},vS=({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=hS(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=_S(t,n,r),o=_S(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+=cS(oS(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=dS(e);c.current=t;let n=pS(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=oS(d.current.total,d.current.rowHeight,t.height);c.current.scrollTop+=cS(n,e)-t.position,h()},[f,h]),v=_S(l,e,t),y=i?i(v.top):v.top,{first:b,last:x}=i?uS(e,y,t,l.height,gS):v,S=Array.from({length:x-b+1},(e,t)=>({index:b+t,offset:lS(v.geometry,b+t,y,l.position)}));return{ref:s,height:l.height,top:y,geometry:v.geometry,rows:S,first:b,last:x,scrollTo:_}},yS=e=>e===`ArrowUp`||e===`ArrowDown`||e===`ArrowLeft`||e===`ArrowRight`,bS=(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},xS=(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)},SS=e=>`${e.index}:${e.column}`,CS=({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="${SS(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?xS(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":SS(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!==SS(o))return;let a=e.key===`Tab`?e.shiftKey?`ArrowLeft`:`ArrowRight`:e.key;if(yS(a)){let i=bS(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)}}},wS=({ids:e,rowAt:t,reorder:n,children:r})=>{let i=S(g(a,{activationConstraint:{distance:4}}),g(de,{activationConstraint:{delay:250,tolerance:5}}),g(fe,{coordinateGetter:ke})),o=t=>e.indexOf(String(t)),s=e=>{let r=t(o(e));return r?n.label(r):Mp(`row`)};return(0,B.jsx)(c,{sensors:i,collisionDetection:_,onDragEnd:({active:e,over:t})=>{t&&e.id!==t.id&&n.onMove(o(e.id),o(t.id))},accessibility:{announcements:{onDragStart:({active:t})=>Mp(`pickedUp`,s(t.id),o(t.id)+1,e.length),onDragOver:({active:t,over:n})=>n?Mp(`isOver`,s(t.id),o(n.id)+1,e.length):void 0,onDragEnd:({active:t,over:n})=>n?Mp(`droppedAt`,s(t.id),o(n.id)+1,e.length):Mp(`putBack`,s(t.id)),onDragCancel:({active:e})=>Mp(`cancelled`,s(e.id),o(e.id)+1)},screenReaderInstructions:{draggable:Mp(`reorderInstructions`)}},children:(0,B.jsx)(C,{items:e,strategy:l,children:r})})},TS=({row:e,label:t,...n})=>{let{attributes:r,listeners:i,setNodeRef:a,setActivatorNodeRef:o,transform:s,transition:c,isDragging:l}=w({id:e.id}),u=(0,B.jsx)(`button`,{ref:o,type:`button`,"aria-label":Mp(`move`,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)(oa,{className:`size-4`})});return(0,B.jsx)(Qx,{...n,rowRef:a,handle:u,dragY:s?.y??0,transition:c,dragging:l})},ES=32,DS=({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=!dd(),E=(h??(T?[]:jx(e))).join(` `),[D,O]=Ax(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)(()=>px(k),[k]),se=ne[0],ce=!!(!o&&n&&se&&se.id===n.columnId&&(se.desc?`desc`:`asc`)!==n.direction),ue=t.rowAt,de=(0,I.useCallback)(e=>ue(ce?j-1-e:e),[ue,ce,j]),[fe]=(0,I.useState)(r),{ref:pe,geometry:me,rows:he,first:ge,last:_e}=vS({total:j,rowHeight:w,initialIndex:fe,inset:ES,onScroll:i&&(e=>i(e/w))}),ve=T||!g?40:yx(j),ye=iS({total:j,rowAt:ue?de:void 0,loadRows:t.loadRows,revision:t.revision,latencyMs:a},ge,_e),be=(0,I.useCallback)(e=>{let t=ye(e),n=t&&f?.get(t.id);return n?{...t,...n}:t},[ye,f]),xe=he.map(({index:e,offset:t})=>({index:e,offset:t,row:be(e)})),Se=(0,I.useMemo)(()=>xe.flatMap(({row:e})=>e?[e]:[]),[be,ge,_e]),Ce=(0,I.useRef)(null),we=Lx(Ce),Te=Nx(k,Se),Ee=(0,I.useMemo)(()=>Fx(Te,we.widths),[Te,we.widths]),De=le({features:dx,columns:oe,data:Se,state:{sorting:ne,rowSelection:ie},onSortingChange:re,onRowSelectionChange:ae,manualSorting:!0,enableMultiSort:!1,enableSortingRemoval:!1,getRowId:e=>e.id}),Oe=new Map(De.getRowModel().rows.map(e=>[e.id,e])),ke=Object.keys(ie).length,Ae=(0,I.useRef)(new Map);for(let e of De.getRowModel().rows)e.getIsSelected()&&Ae.current.set(e.id,e.original);let je=u&&u.length>0?40:0,Me=T?1:bx,M=Tx(),Ne=()=>{M.onScroll(),Ce.current&&M.ref.current&&(Ce.current.scrollLeft=M.ref.current.scrollLeft)},[Pe,Fe]=(0,I.useState)({});(0,I.useLayoutEffect)(()=>{let e=Ce.current?.querySelector(`[role=row]`);if(!e)return;let t=ve,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]),N=De.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)}))),Re=(0,I.useRef)(null),ze=CS({editor:d,columns:(0,I.useMemo)(()=>k.map(e=>e.id),[k]),total:j,rowAt:be,onOpenRow:c,container:Re}),Be=(k.find(e=>e.title)??k[0])?.id,Ve=wx(Ee,ve,je,Me),He=x===`own`,Ue=(0,B.jsx)(`div`,{ref:Ce,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)(Gx,{cells:N,specs:Ee,gutter:ve,trailing:je,minScale:Me,pins:Pe,lastPinned:Ie,scrolled:M.scrolled,onTogglePin:Le,resize:we,widths:we.widths,selectable:C,selectedCount:ke,onClearSelection:()=>ae({})})})}),We=xe.map(({index:e,offset:t,row:n})=>{let r={specs:Ee,gutter:ve,index:e,offset:t,height:w,selectable:C,trailing:je,minScale:Me,scrolled:M.scrolled,pins:Pe,lastPinned:Ie},i=n?Oe.get(n.id):void 0;if(!i||!n)return(0,B.jsx)(eS,{...r},`skeleton-${e}`);let a=je?_x(u,n):[],o={...r,selected:i.getIsSelected(),onToggle:()=>i.toggleSelected(),onOpen:c?()=>c(n):void 0,menu:a.length>0?(0,B.jsx)(vx,{row:n,actions:a}):void 0,cells:i.getAllCells().map(t=>{let r=(0,B.jsx)(De.FlexRender,{cell:t}),i=!!d?.editable(n,t.column.id),a=l&&t.column.id===Be&&!i?(0,B.jsx)(ah,{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)(TS,{...o,row:n,label:y.label(n)},n.id):(0,B.jsx)(Qx,{...o},n.id)}),Ge=(0,B.jsx)(`div`,{ref:M.attach,onScroll:Ne,className:`overflow-x-auto overflow-y-hidden overscroll-x-contain [-webkit-overflow-scrolling:touch]`,children:(0,B.jsx)(`div`,{ref:pe,className:`relative`,style:{minWidth:Ve,height:me.contentHeight},children:y?(0,B.jsx)(wS,{ids:Array.from({length:j},(e,t)=>be(t)?.id??`missing-${t}`),rowAt:be,reorder:y,children:We}):We})});return(0,B.jsxs)(`div`,{ref:Re,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:ES+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]}),M.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)(hx,{total:j,className:He?void 0:`sticky bottom-[var(--pb-sticky-bottom,0px)] z-20`,selectedCount:ke,bulkActions:mx(p??[],Object.keys(ie).flatMap(e=>Ae.current.get(e)??[])).map(({action:e,rows:t,skipped:n})=>({label:e.label(t.length),destructive:e.destructive,onRun:()=>{e.onRun(t,n),ae({}),Ae.current.clear()}}))})]})},OS=500,kS=async(e,t,n)=>{let r=[],i={},a;do{let o=await e.search(t,{...n,pageSize:OS,...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}},AS=on(),jS=(...e)=>{let t=e.filter(e=>!!e);return t.length===1?t[0]:t.map(e=>`(${e})`).join(` AND `)},MS=e=>e==null?void 0:String(e),NS=(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=MS(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},PS=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 kS(e,a.name,{filter:jS(Jt(AS.in(i.field,r)),i.filter),fields:[i.field,o]})).items.flatMap(e=>{let t=MS(e[i.field]),n=MS(e[o]);return t===void 0||n===void 0?[]:[[t,n]]})},FS=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 PS(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=iy(t,n,s,u),f=await kS(e,s.name,{filter:jS(Jt(AS.in(a.field,l)),a.filter),...a.sort&&{orderBy:a.sort},fields:u,labels:d});return NS(c,ay(t,s,u,f.items,f.labels),a.field)},IS=5e3,LS=({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=iy(n,r,i,a),f=Cm(r[i.name]),p=async e=>e.nextPageToken===``?e.items.length:e.totalSizeEstimate>IS?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 e=>{let l=await m(e);if(e>0&&l===``)return{rows:[],total:0,nextPageToken:``};let u={filter:o,orderBy:s,pageSize:40,labels:d,photos:f},h=l===void 0?await t.seek(i.name,{...u,position:e*40}):await t.list(i.name,{...u,pageToken:l});if(h.items.length===0&&e>0)return{rows:[],total:0,nextPageToken:``};let g=h.items.map(e=>am(i,e)),_=ay(n,i,a,wm(i,h.items,h.photos),h.labels),v=await Promise.all(c.map(e=>FS({client:t,resources:n,views:r,load:e,owners:g})));return{rows:_.map((e,t)=>({...e,...Object.fromEntries(c.map((e,n)=>[e.column.name,v[n].get(g[t])??[]])),id:g[t]})),total:e===0?await p(h):h.totalSizeEstimate,nextPageToken:h.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}},RS=({resources:e,views:t,model:n,columns:r,filter:i,orderBy:a,related:o})=>{let s=U(),c=be(),l=r.join(`,`),u=JSON.stringify(o??[]),d=(0,I.useMemo)(()=>LS({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]}},X=M({en:{saveSearch:`Save search`,saveAsNew:e=>`Save as new ${e}`,updateName:e=>`Update ${e}`,updateNameQuestion:e=>`Update ${e}?`,updateNounQuestion:e=>`Update this ${e}?`,couldNotLoadYour:e=>`Could not load your ${e}`,noneYet:e=>`No ${e} yet.`,somethingWrong:`Something went wrong`,couldNotRename:`Could not rename the search`,renameTitle:e=>`Rename ${e}`,deleteTitle:e=>`Delete ${e}`,unreadableFilter:`A filter that cannot be read`,notFound:`Not found`,noResource:`There is no resource called {}.`,noSavedYet:e=>`No ${e} yet. Filter the {} and save the search.`,on:`On`,off:`Off`,saved:e=>`${e} saved`,couldNotChange:`Could not change the search`,asMany:e=>`As many ${e}`,more:(e,t)=>`${e} more ${t}`,fewer:(e,t)=>`${e} fewer ${t}`,cancel:`Cancel`,save:`Save`,optional:`Optional`,added:`Added`,removed:`Removed`,changed:`Changed`,filterChanges:`Filter changes`,firstOf:(e,t)=>`The first ${e} of ${t}.`,noPlural:e=>`No ${e}.`,update:`Update`,addedRemoved:(e,t)=>`${e} added, ${t} removed`,searchSaved:`Search saved`,openPlural:e=>`Open ${e.toLowerCase()}`,couldNotSave:`Could not save the search`,couldNotTakeOff:`Could not take the search off`,searchUpdated:`Search updated`,couldNotUpdate:`Could not update the search`,noneMatch:e=>`No ${e} match.`,noNew:e=>`No new ${e} since you last looked.`,viewAll:`View all results`,filters:`Filters`},nl:{saveSearch:`Zoekopdracht bewaren`,saveAsNew:e=>`Als extra ${e} bewaren`,updateName:e=>`${e} bijwerken`,updateNameQuestion:e=>`${e} bijwerken?`,updateNounQuestion:e=>`${e} bijwerken?`,couldNotLoadYour:e=>`Kon je ${e} niet laden`,noneYet:e=>`Nog geen ${e}.`,somethingWrong:`Er ging iets mis`,couldNotRename:`Kon de zoekopdracht niet hernoemen`,renameTitle:e=>`${e} hernoemen`,deleteTitle:e=>`${e} verwijderen`,unreadableFilter:`Een filter dat niet kan worden gelezen`,notFound:`Niet gevonden`,noResource:`Er is geen onderdeel met de naam {}.`,noSavedYet:e=>`Nog geen ${e}. Filter de {} en bewaar de zoekopdracht.`,on:`Aan`,off:`Uit`,saved:e=>`${e} bewaard`,couldNotChange:`Kon de zoekopdracht niet wijzigen`,asMany:e=>`Evenveel ${e}`,more:(e,t)=>`${e} ${t} meer`,fewer:(e,t)=>`${e} ${t} minder`,cancel:`Annuleren`,save:`Bewaren`,optional:`Optioneel`,added:`Erbij`,removed:`Eraf`,changed:`Gewijzigd`,filterChanges:`Wijzigingen in het filter`,firstOf:(e,t)=>`De eerste ${e} van ${t}.`,noPlural:e=>`Geen ${e}.`,update:`Bijwerken`,addedRemoved:(e,t)=>`${e} erbij, ${t} eraf`,searchSaved:`Zoekopdracht bewaard`,openPlural:e=>`${e} openen`,couldNotSave:`Kon de zoekopdracht niet bewaren`,couldNotTakeOff:`Kon de zoekopdracht niet weghalen`,searchUpdated:`Zoekopdracht bijgewerkt`,couldNotUpdate:`Kon de zoekopdracht niet bijwerken`,noneMatch:e=>`Geen ${e} gevonden.`,noNew:e=>`Geen nieuwe ${e} sinds je laatst keek.`,viewAll:`Alle resultaten bekijken`,filters:`Filters`}}),zS=`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`,BS=({chips:e,className:t})=>(0,B.jsx)(`ul`,{className:P(`flex flex-wrap gap-1.5`,t),"aria-label":X(`filters`),children:e.map(e=>(0,B.jsx)(`li`,{className:zS,children:e.label},e.key))}),VS=({chips:e})=>(0,B.jsx)(`span`,{className:`flex flex-wrap gap-1.5`,children:e.map((e,t)=>(0,B.jsxs)(`span`,{className:zS,children:[t>0&&(0,B.jsx)(`span`,{className:`sr-only`,children:`, `}),e.label]},e.key))}),HS=e=>e.map(e=>e.label).join(`, `),US=M({en:{today:`Today`,yesterday:`Yesterday`,"24h":`Last 24 hours`,"7d":`Last 7 days`,"30d":`Last 30 days`,"90d":`Last 90 days`,month:`This month`,quarter:`This quarter`,year:`This year`,unknownPreset:e=>`The server offers the preset "${e}", which this UI does not know`,unsupported:e=>`${e} (unsupported)`,remove:e=>`Remove ${e}`,clearAll:`Clear all`,searchIn:e=>`Search ${e.toLowerCase()}`,noMatches:`No matches`,moreFilters:`More filters`,filters:`Filters`,date:`Date`,showOnly:`Show only`,minimum:e=>`${e} minimum`,maximum:e=>`${e} maximum`},nl:{today:`Vandaag`,yesterday:`Gisteren`,"24h":`Afgelopen 24 uur`,"7d":`Afgelopen 7 dagen`,"30d":`Afgelopen 30 dagen`,"90d":`Afgelopen 90 dagen`,month:`Deze maand`,quarter:`Dit kwartaal`,year:`Dit jaar`,unknownPreset:e=>`De server biedt de periode "${e}", die deze UI niet kent`,unsupported:e=>`${e} (niet ondersteund)`,remove:e=>`${e} verwijderen`,clearAll:`Alles wissen`,searchIn:e=>`Zoeken in ${e.toLowerCase()}`,noMatches:`Niets gevonden`,moreFilters:`Meer filters`,filters:`Filters`,date:`Datum`,showOnly:`Alleen tonen`,minimum:e=>`${e} minimum`,maximum:e=>`${e} maximum`}}),WS=`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`,GS=({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)(Ra,{className:`size-3 text-muted-foreground`}),e]},e)),e.map(e=>(0,B.jsxs)(`span`,{className:WS,children:[e.label,(0,B.jsx)(`button`,{type:`button`,"aria-label":US(`remove`,e.label),onClick:()=>n(e.key),className:`rounded-full p-0.5 hover:bg-primary-border/60`,children:(0,B.jsx)(Ls,{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:US(`clearAll`)})]}),KS=[`today`,`7d`,`30d`,`year`],qS=new Set([`today`,`yesterday`,`24h`,`7d`,`30d`,`90d`,`month`,`quarter`,`year`]),JS=e=>qS.has(e)?US(e):void 0,YS=({value:e,presets:t=KS,onChange:n})=>(0,B.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:t.map(t=>{let r=JS(t);return(0,B.jsx)(`button`,{type:`button`,disabled:!r,title:r?void 0:US(`unknownPreset`,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??US(`unsupported`,t)},t)})}),XS=({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":Ju(`remove`,e),className:`rounded p-0.5 hover:bg-primary-border/60`,onMouseDown:e=>e.preventDefault(),onClick:t,children:(0,B.jsx)(Ls,{className:`size-3`})})]}),ZS={facets:{},toggles:[]},QS=(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}}},$S=(e,t)=>({...e,toggles:e.toggles.includes(t)?e.toggles.filter(e=>e!==t):[...e.toggles,t]}),eC=(e,t,n)=>{let{[t]:r,...i}=e.ranges??{};return{...e,ranges:n?{...i,[t]:n}:i}},tC=(e,t)=>e.options.find(e=>e.value===t)?.label??e.labels?.[t]??t,nC=(e,t)=>{let n=e.facets.flatMap(e=>(t.facets[e.id]??[]).map(t=>({key:`facet:${e.id}:${t}`,label:`${e.label}: ${tC(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:JS(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]},rC=(e,t)=>{if(t===`date`)return{...e,date:void 0};let[n,r,i]=t.split(`:`);if(n===`range`)return eC(e,r,void 0);if(n===`toggle`)return $S(e,r);if(n===`facet`)return QS(e,r,i);throw Error(`Unknown filter chip key: ${t}`)},iC=(e,t)=>e.toLowerCase().includes(t.trim().toLowerCase()),aC=(e,t)=>e.onSearch?e.options:e.options.filter(e=>iC(e.label,t)),oC=(e,t,n)=>t===0?-1:n===`ArrowDown`?e<0?0:(e+1)%t:e<0?t-1:(e-1+t)%t,sC=({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=aC(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)(jo,{className:`size-3.5 shrink-0 text-muted-foreground`}),t.map(t=>(0,B.jsx)(XS,{label:tC(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?``:US(`searchIn`,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(oC(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)(ui,{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:Vd(e.count)})]},e.value)}),p.length===0&&(0,B.jsx)(`li`,{className:`px-1.5 py-1 text-xs text-faint-foreground`,children:US(`noMatches`)})]})]})},cC=({config:e,selected:t,onToggle:n})=>{let[r,i]=(0,I.useState)(``),a=e.options.filter(e=>iC(e.label,r));return(0,B.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[e.searchable&&(0,B.jsx)(Xf,{wrapperClassName:`mb-1 h-7`,leading:(0,B.jsx)(jo,{className:`size-3.5`}),placeholder:US(`searchIn`,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)(Rx,{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:Vd(e.count)})]},e.value)),a.length===0&&(0,B.jsx)(`span`,{className:`px-1 py-1 text-xs text-faint-foreground`,children:US(`noMatches`)})]})},lC=({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)(fi,{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})]})},uC=({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]}),dC=(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}},fC=({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":US(`moreFilters`),onKeyDown:t=>{if(t.key===`Escape`)return n();let i=dC(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:Mh,onClick:()=>{n(),t(e.key)},children:e.label})},e.key))})},pC=({items:e,onPick:t})=>e.length===0?null:(0,B.jsx)(lC,{label:US(`moreFilters`),activeCount:0,children:n=>(0,B.jsx)(fC,{items:e,onPick:t,close:n})}),mC=(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},hC=(e,t,n,r,i)=>{let a=n+(r-n)*e/t;return n+(r-n)*(e+1)/t>i[0]&&a<i[1]},gC=(e,t,n)=>n===t?0:(e-t)/(n-t),_C=(e,t,n)=>t===0?[Math.min(n,e[1]),e[1]]:[e[0],Math.max(n,e[0])],vC=1e3,yC=({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=mC(c,vC);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`,hC(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:`${gC(u[0],r,i)*100}%`,right:`${100-gC(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":US(t===0?`minimum`:`maximum`,e.label),min:r,max:i,step:a,value:u[t],onChange:e=>l(_C(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])})]})]})},bC=e=>[...new Set(e.map(e=>e.key.split(`:`).slice(0,2).join(`:`)))],xC=(e,t)=>{let n=t.filter(t=>!e.includes(t));return n.length===0?e:[...e,...n]},SC=(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:US(`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}},CC=({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)(mg,{checked:t,onChange:n,label:e})]}),wC=(e,t)=>e.some(e=>e.length>0)||!!t,TC=({groups:e,trailing:t})=>{if(!wC(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})]})},EC=(e,t,n)=>{let[r,i]=(0,I.useState)(t??ZS);return[e??r,e=>{i(e),n?.(e)}]},DC=({config:e,layout:t,value:n,defaultValue:r,onChange:i,lockedLabels:a,defaultOpenMenu:o,fullWidth:s,leading:c,trailing:l})=>{let[u,d]=EC(n,r,i),f=nC(e,u),p=bC(f),[m,h]=(0,I.useState)(()=>p),[g,_]=(0,I.useState)();(0,I.useEffect)(()=>h(e=>xC(e,p)),[p.join(`,`)]);let v=(0,B.jsx)(GS,{chips:f,lockedLabels:a,onRemove:e=>d(rC(u,e)),onClear:()=>d(ZS)}),y=(e,t=!1)=>{let n=u.facets[e.id]??[],r=t=>d(QS(u,e.id,t));return e.combobox?(0,B.jsx)(sC,{config:e,selected:n,onToggle:r,inline:t}):(0,B.jsx)(cC,{config:e,selected:n,onToggle:r})},b=e.ranges??[],x=e=>(0,B.jsx)(yC,{config:e,value:u.ranges?.[e.id],onChange:t=>d(eC(u,e.id,t))}),S=e.datePresets&&(0,B.jsx)(YS,{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)(CC,{label:e.label,checked:u.toggles.includes(e.id),onChange:()=>d($S(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:US(`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)(uC,{title:e.label,children:y(e)},e.id)),b.map(e=>(0,B.jsx)(uC,{title:e.label,children:x(e)},e.id)),S&&(0,B.jsx)(uC,{title:US(`date`),children:S}),C.length>0&&(0,B.jsx)(uC,{title:US(`showOnly`),children:C})]});let{shown:w,more:T}=SC(e,m),E=e=>{h(t=>xC(t,[e])),_(e)},D=[...e.facets.filter(e=>w.has(`facet:${e.id}`)).map(e=>(0,B.jsx)(lC,{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)(lC,{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)(CC,{label:e.label,checked:u.toggles.includes(e.id),onChange:()=>d($S(u,e.id))})},e.id)),k=[c?[(0,B.jsx)(I.Fragment,{children:c},`leading`)]:[],D,O,T.length>0?[(0,B.jsx)(pC,{items:T,onPick:E},`more`)]:[]];return!wC(k,l)&&f.length===0&&!a?.length?null:(0,B.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,B.jsx)(TC,{groups:k,trailing:l}),v]})},OC=on(),kC={start:0,end:0},AC={"24h":{amount:24,unit:`h`},"7d":{amount:7,unit:`d`},"30d":{amount:30,unit:`d`},"90d":{amount:90,unit:`d`}},jC=e=>new Date(e).toISOString().replace(`.000Z`,`Z`),MC=(e,t,n)=>{let r=Zd(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},NC=[`year`,`quarter`,`month`,`yesterday`,`today`],PC=(e,t,n)=>t===`date`?e:jC($d(e,n)),FC=(e,t,n)=>t===`date`?{kind:`string`,value:PC(e,t,n),span:kC}:{kind:`timestamp`,value:PC(e,t,n),span:kC},IC=(e,t,n,r,i)=>{if(t in AC)return[OC.gte(e,OC.ago(t))];let a=OC.gte(e,FC(MC(t,n,i),r,i));return t===`yesterday`?[a,OC.lt(e,FC(MC(`today`,n,i),r,i))]:[a]},LC=(e,t,n=new Date,r=Gd())=>{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=>OC.eq(e.value,!0));return t.length===0?[]:[t.length===1?t[0]:OC.or(...t)]}return[n.length===1?OC.eq(e.id,n[0]):OC.in(e.id,n)]}),a=(e.ranges??[]).flatMap(e=>{let n=t.ranges?.[e.id];return n?[OC.gte(e.id,n[0]),OC.lte(e.id,n[1])]:[]}),o=e.dateField&&t.date?IC(e.dateField,t.date,n,e.dateKind,r):[],s=(e.toggles??[]).filter(e=>t.toggles.includes(e.id)).map(e=>OC.eq(e.id,!0));return[...i,...a,...o,...s]},RC=e=>e.length===0?``:Jt(OC.and(...e)),zC=(e,t,n=[],r=new Date,i=Gd())=>RC([...LC(e,t,r,i),...n]),BC=e=>e.kind===`and`?e.args.flatMap(BC):[e],VC=e=>e.field.path.join(`.`),HC=e=>e.kind===`compare`&&e.op===`=`&&e.value.kind===`boolean`&&e.value.value,UC=(e,t)=>{let n=e.kind===`or`?e.args:[e];if(!n.every(HC))return;let r=n.map(VC),i=t.get(r[0]);return i!==void 0&&r.every(e=>t.get(e)===i)?{group:i,fields:r}:void 0},WC=e=>e.kind===`number`?String(e.raw):e.kind===`string`?String(e.value):void 0,GC=(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(AC).find(([,n])=>n.amount===e&&n.unit===t)?.[0]}if(r.kind===`timestamp`)return NC.find(e=>PC(MC(e,t,n),`timestamp`,n)===r.value);if(r.kind===`string`)return NC.find(e=>MC(e,t,n)===r.value)},KC=(e,t,n=new Date,r=Gd())=>{let i=rt(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?BC(i.ast):[]){let i=UC(t,c);if(i&&!a.facets[i.group])a.facets[i.group]=i.fields;else if(t.kind===`compare`&&s.has(VC(t))&&t.op===`=`&&WC(t.value)!==void 0)a.facets[VC(t)]=[...a.facets[VC(t)]??[],WC(t.value)];else if(t.kind===`in`&&s.has(VC(t))&&t.values.every(e=>WC(e)!==void 0))a.facets[VC(t)]=[...a.facets[VC(t)]??[],...t.values.map(e=>WC(e))];else if(t.kind===`compare`&&e.dateField===VC(t)&&t.op===`>=`&&GC(t,n,r)&&!a.date)a.date=GC(t,n,r),f=t;else if(t.kind===`compare`&&e.dateField===VC(t)&&t.op===`<`&&(t.value.kind===`timestamp`||t.value.kind===`string`)&&t.value.value===PC(MC(`today`,n,r),t.value.kind===`string`?`date`:`timestamp`,r))p=t;else if(t.kind===`compare`&&l.has(VC(t))&&t.op===`=`&&t.value.kind===`boolean`&&t.value.value)a.toggles.push(VC(t));else if(t.kind===`compare`&&u.has(VC(t))&&(t.op===`>=`||t.op===`<=`)&&t.value.kind===`number`){let e=d.get(VC(t))??{clauses:[]};t.op===`>=`?e.low=t.value.value:e.high=t.value.value,e.clauses.push(t),d.set(VC(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}},qC=[`integer`,`bigint`,`decimal`],JC=(e,t)=>{let n=e?.fields[t]?.type;return n!==void 0&&qC.includes(n)},YC=(e,t)=>e.kind===`range`||e.kind===`facets`&&JC(t,e.field),XC=e=>e.secondary?{secondary:!0}:{},ZC=e=>({id:e.field,label:e.field,min:0,max:0,step:1,histogram:[],format:String,...XC(e)}),QC=(e,t)=>{let n=e?.filters??[],r=n.find(e=>e.kind===`dateRange`);return{facets:n.flatMap(e=>e.kind===`facets`&&!YC(e,t)?[{id:e.field,label:e.field,options:[],searchable:e.search,...t?.fields[e.field]?.type===`relation`&&{combobox:!0},...XC(e)}]:e.kind===`flags`?[{id:e.fields.join(`|`),label:e.label,options:e.fields.map(e=>({value:e,label:e,count:0})),flags:!0,...XC(e)}]:[]),ranges:n.flatMap(e=>e.kind!==`flags`&&YC(e,t)?[ZC(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,...XC(e)}]:[])}},$C=(e,t)=>(e?.filters??[]).some(e=>e.kind===`range`&&e.field===t&&e.histogram),ew=(e,t)=>{let n=e?.fields[t],r=n?.suffix??``;return e=>`${n?.prefix===`€`?Rd(e*100).replace(`.00`,``):String(e)}${r}`},tw=on(),nw={start:0,end:0},rw=(e,t,n)=>{let r=KC(QC(t,e),n);return r.ok?Object.fromEntries(Object.entries(r.state.facets).filter(([t,n])=>e.fields[t]?.type===`relation`&&n.length>0)):{}},iw=(e,t,n)=>{let r=e=>t?.fields[e]?.label??F(e),i=QC(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,tr(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:ew(t,e.id)})),toggles:i.toggles?.map(e=>({...e,label:r(e.id)}))}},aw=(e,t,n,r={})=>{let i=iw(e,t,r),a=KC(i,n);if(!a.ok)return[{key:`unreadable`,label:X(`unreadableFilter`)}];let o=a.extras.map((e,t)=>({key:`extra:${t}`,label:e.kind===`search`?`"${e.text}"`:Jt(e)}));return[...nC(i,a.state),...o]},ow=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]))}])),sw=(e,t,n)=>{if(typeof n!=`string`||n===``)return e;let r=tw.gt(t,{kind:`timestamp`,value:new Date(n).toISOString(),span:nw}),i=rt(e);if(!i.ok)throw Error(`The saved filter cannot be read: ${i.errors.map(e=>e.message).join(`; `)}`);return Jt(i.ast?tw.and(i.ast,r):r)},cw=(e,t)=>typeof t!=`string`||t===``?!0:typeof e!=`string`||e===``?!1:new Date(e).getTime()>new Date(t).getTime(),lw=(e,t)=>{let n=U(),r=be(),{resources:i,views:a}=W(),o=a[e.name],s=Object.entries(rw(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 ny(r,n,s,o,a[s.name]))}})});return aw(e,o,t,Object.fromEntries(s.flatMap(([e],t)=>c[t]?.data?[[e,c[t].data]]:[])))},uw=(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}}),dw=e=>{let t=be();return(0,I.useCallback)(n=>t.setQueryData(H.recordPreview(e.name,An(om(e,n))),uw(e,n)),[t,e])},fw={wallet:js,"file-text":ia,send:Fo,ruler:ko,bed:Pr,bath:Mr,house:fa,"door-open":Ri,"land-plot":ba,leaf:Oa,tag:ds,key:va,calendar:ni,heart:ua,bell:Br,bookmark:Jr,"external-link":Ji,ban:Ar,play:po,stop:ts,power:yo,restart:Do,terminal:hs,camera:ii,"hard-drive":ca,server:Lo,network:io,archive:gr,copy:Mi,"arrow-right-left":br,download:Bi,upload:Cs,cpu:Pi,memory:Ja,plug:ho,wrench:Fs},pw=e=>e!==void 0&&Object.hasOwn(fw,e)?fw[e]:void 0,mw=()=>{let{path:e,params:t,basePath:n,navigate:r}=mh(),i=(0,I.useMemo)(()=>_c(e,t),[e,t]),a=bu(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(gc({step:e,next:o}),t),[r,o]);return{address:i,next:o,open:s,link:(0,I.useCallback)((e=`sign-in`,t)=>({href:`${n}${gc({step:e,next:o})}`,onFollow:()=>s(e,t)}),[n,o,s]),leave:(0,I.useCallback)(()=>r(o??`/`,{replace:!0}),[r,o])}},hw=({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)(ui,{className:`mt-0.5 size-4 shrink-0 text-primary`,"aria-hidden":!0}),e]},e))}):null,gw=({prompt:e})=>{let{canSignUp:t}=V(),{link:n}=mw(),r=ld({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)(ah,{to:n(`sign-up`),className:r,children:z(`createAnAccount`)});return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(ah,{to:n(),className:i?ld():r,children:z(`signIn`)}),i]})},_w=e=>{let{prompt:t}=e,n=(0,I.useId)();if(e.as===`dialog`)return(0,B.jsx)(xd,{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)(gw,{prompt:t})]}),children:(0,B.jsx)(hw,{benefits:t.benefits})});let r=pw(t.icon)??Ba;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)(hw,{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)(gw,{prompt:t})})]})},vw=on(),yw=e=>{if(typeof e==`string`||typeof e==`number`)return e;if(e&&typeof e==`object`&&`id`in e)return yw(e.id)},bw=(e,t,n)=>n.flatMap(n=>{let r=yw(n[t]);return r===void 0?[]:[{key:An(om(e,n)),target:r}]}),xw=(e,t)=>e.find(e=>An(e.target)===t),Sw=(e,t)=>[...e,{key:``,target:t}],Cw=(e,t)=>e.filter(e=>An(e.target)!==t),ww=(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:vw.in(n,r)},Tw=(e,t)=>H.list(e,``,``,500,`saved:${t}`),Ew=(e,t,n)=>{let r=U(),i=W().resources[e];return E({queryKey:Tw(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 bw(i,t,n)}})},Dw=M({en:{favorite:`Favorite`,couldNotLoadYour:e=>`Could not load your ${e}`,noneYet:e=>`No ${e} yet.`,somethingWrong:`Something went wrong`,couldNotTakeOff:`Could not take it off`,couldNotSave:`Could not save it`},nl:{favorite:`Favoriet`,couldNotLoadYour:e=>`Kon je ${e} niet laden`,noneYet:e=>`Nog geen ${e}.`,somethingWrong:`Er ging iets mis`,couldNotTakeOff:`Kon het niet weghalen`,couldNotSave:`Kon het niet bewaren`}}),Ow=e=>e instanceof Error?e.message:Dw(`somethingWrong`),kw=(e,t,n)=>{let r=W(),i=U(),a=be(),s=Gf(),c=iv(),{resource:l,field:u}=e,d=r.permissions[l],f=r.resources[l]!==void 0&&d!==void 0&&V_(d,`create`)&&V_(d,`delete`),p=r.signIn?.[l]?.signIn,m=Ew(l,u,f),h=m.data&&xw(m.data,t),g=Tw(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?Cw(r,t):Sw(r,n)),{before:r}},onError:(e,t,n)=>{a.setQueryData(g,n?.before),s.show({state:`error`,title:Dw(t?`couldNotTakeOff`:`couldNotSave`),description:Ow(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)}},Aw=({favorite:e,recordKey:t,target:n,className:r})=>{let i=kw(e,t,n),[a,o]=(0,I.useState)(!1);if(!i.mode)return null;let s=e.label??Dw(`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)(ua,{className:`size-4`,"aria-hidden":!0})}),(0,B.jsx)(_w,{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)(ua,{className:P(`size-4`,i.saved&&`fill-current text-danger`),"aria-hidden":!0})})},jw=6,Mw=(e,t,n)=>{let r=e.bottom+jw;return{top:r+t.height>n.height-jw?Math.max(jw,e.top-jw-t.height):r,left:Math.max(jw,Math.min(e.left,n.width-jw-t.width))}},Nw=(e,t)=>{let n=jm(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},Pw=(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:qm(r,n[r.name],Nw(n[r.name],e.status))}]:[]}),Fw=M({en:{none:e=>`No ${e}`},nl:{none:e=>`Geen ${e}`}}),Iw=(e,{values:t,label:n,singular:r,plural:i})=>{if(e.length===0)return Fw(`none`,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(`, `)}`},Lw=`flex shrink-0 items-center justify-center rounded-full p-0.5 pointer-coarse:p-1.5`,Rw=`size-2.5 rounded-full`,zw=`flex min-w-0 items-center gap-0.5`,Bw=150,Vw=288,Hw=({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(Mw(e.dot,{width:Vw,height:c.current.offsetHeight},{width:window.innerWidth,height:window.innerHeight}))},[e]),(0,Bs.createPortal)((0,B.jsx)(`div`,{ref:c,"data-dot-card":!0,onMouseEnter:o,onMouseLeave:s,style:{width:Vw,...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:Nw(r,i.status),row:t})}),document.body)},Uw=({column:e,records:t,target:n,view:r,wrap:i=!1,Card:a})=>{let o=(0,I.useMemo)(()=>t.map(e=>Zm(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?bm(f,t.record[e.status],p):``,h=ar(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=Iw(o.map(t=>t.record[e.status]),{values:f?.enumValues??[],label:e=>f?bm(f,e,p):e,singular:_,plural:v}),b=()=>window.clearTimeout(l.current),x=()=>{b(),l.current=window.setTimeout(()=>c(void 0),Bw)},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(zw,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=oy(p?.valueColors,r);return(0,B.jsx)(Eh,{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(Lw,`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(Rw,i===void 0&&pp[fm(String(r))],s?.key===t.key&&`ring-2 ring-foreground/30`)})},t.key)}),s&&T&&(0,B.jsx)(Hw,{shown:s,row:T,target:n,view:r,column:e,Card:a,onEnter:b,onLeave:x})]})},Ww=({count:e})=>(0,B.jsx)(`span`,{"aria-hidden":!0,className:P(zw,`invisible flex-wrap`),children:Array.from({length:e},(e,t)=>(0,B.jsx)(`span`,{className:Lw,children:(0,B.jsx)(`span`,{className:Rw})},t))}),Gw=`flex flex-col gap-1.5`,Kw=({dots:e})=>(0,B.jsx)(`span`,{className:Gw,children:e.map(({column:e,records:t})=>(0,B.jsx)(Ww,{count:t.length},e.name))}),qw=({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)] ${Gw}`,children:e.map(({column:e,records:i})=>{let a=n[e.resource];return a&&(0,B.jsx)(Uw,{column:e,records:i,target:a,view:r[a.name],Card:t,wrap:!0},e.name)})})},Jw=(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}]:[]}),Yw=M({en:{photoOf:(e,t)=>`Photo ${e} of ${t}`,previousPhoto:`Previous photo`,nextPhoto:`Next photo`},nl:{photoOf:(e,t)=>`Foto ${e} van ${t}`,previousPhoto:`Vorige foto`,nextPhoto:`Volgende foto`}}),Xw=`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`,Zw=`[@media(hover:none)]:opacity-100`,Qw=({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":Yw(`previousPhoto`),className:P(Xw,r,!n&&Zw,`left-2`),onClick:()=>o(-1),children:(0,B.jsx)(mi,{className:`size-4`,"aria-hidden":!0})}),(0,B.jsx)(`button`,{type:`button`,"aria-label":Yw(`nextPhoto`),className:P(Xw,r,!n&&Zw,`right-2`),onClick:()=>o(1),children:(0,B.jsx)(gi,{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:Yw(`photoOf`,a+1,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))})]})]})},$w=({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))}),eT=(e,t)=>t===0?0:(e%t+t)%t,tT=(e,t,n)=>t<=0||n===0?0:Math.min(n-1,Math.max(0,Math.round(e/t))),nT=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=eT((n.current??r)+t,e),a(n.current)},touch:()=>{n.current=void 0},scrolled:t=>{i(tT(t.scrollLeft,t.clientWidth,e)),n.current!==void 0&&Math.abs(t.scrollLeft-n.current*t.clientWidth)<1&&(n.current=void 0)}}},rT=({value:e})=>{let t=Op(e,{width:320,height:240});return t?(0,B.jsx)(Lg,{image:t,loading:`lazy`,className:`size-full object-cover`}):null},iT=({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}),aT=({value:e})=>(0,B.jsx)(iT,{children:(0,B.jsx)(rT,{value:e})}),oT=10,sT=(e,t)=>{let n=vp(e)?e.uri:void 0,r=t.filter(e=>vp(e)&&e.uri!==n);return(n===void 0?r:[e,...r]).slice(0,oT)},cT=({photos:e,cover:t,swipe:n=!0,children:r})=>{let i=sT(t,e),a=nT(i.length),o=(0,B.jsx)(iT,{children:(0,B.jsx)($w,{"data-card-photos":!0,carousel:a,swipe:n,slides:i.map(e=>(0,B.jsx)(rT,{value:e}))})});return(0,B.jsxs)(B.Fragment,{children:[r(o),(0,B.jsx)(Qw,{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]`})]})},lT=({icon:e,children:t})=>{let n=pw(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]})},uT=({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}=Hm(e,t,n),m=e=>t?.fields[e]?.label??F(e),h=n=>{let i=e.fields[n];if(!i)return``;let a=r.record[n];return r.labels[n]===void 0&&rm(i,t?.fields[n])&&typeof a==`string`&&a!==``?nm(a):r.labels[n]??bm(i,a,t?.fields[n])},{fields:g,components:_}=Wg(),v=dw(e),y=n.card===void 0?void 0:_?.[n.card],b=n=>{let i=e.fields[n],a=i&&Gg(g,i,t?.fields[n]);return a?(0,B.jsx)(n_,{shown:a,part:`display`,field:i,value:r.record[n],fallback:h(n)}):h(n)},x=n=>{let i=e.fields[n],a=r.record[n];return!i||!rm(i,t?.fields[n])||Gg(g,i,t?.fields[n])||typeof a!=`string`||a===``?b(n):(0,B.jsx)(i_,{source:a,inLink:!0})},S=n=>{let i=e.fields[n],a=t?.fields[n],o=r.record[n];return!i||a?.format!==`badge`||Gg(g,i,a)||o==null||o===``?b(n):(0,B.jsx)(sy,{value:o,hints:a,children:h(n)})},C=n=>{let i=e.fields[n];if(!i)return;if(r.labels[n]!==void 0||Gg(g,i,t?.fields[n]))return(0,B.jsx)(`strong`,{className:`font-semibold text-foreground`,children:b(n)});let a=Gm(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]})},w=y?void 0:n.photos,T=u===void 0?void 0:r.record[u],E=p.filter(e=>r.record[e]===!0),D=o===void 0?void 0:r.record[o],O=Wm(r,l),k=Um(r,f),A=o!==void 0||w!==void 0,j=n.favorite,ee=y?[]:Jw(t,n,r),te=e=>(0,B.jsxs)(B.Fragment,{children:[A&&e,(0,B.jsxs)(`span`,{className:`flex items-start justify-between gap-2 ${j&&!A?`pr-8`:``}`,children:[(0,B.jsx)(`span`,{className:`min-w-0 truncate font-medium`,children:b(s)}),u!==void 0&&T!=null&&(0,B.jsx)(sy,{value:T,hints:t?.fields[u],children:h(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:x(c)}),O!==void 0&&(0,B.jsx)(`span`,{className:`truncate tabular-nums text-muted-foreground`,children:C(O)}),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:Um(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)(lT,{icon:t?.fields[e]?.icon,children:S(e)})]},e))}),E.length>0&&(0,B.jsx)(`ul`,{className:`flex flex-wrap gap-1`,"aria-label":q(`features`),children:E.map(e=>(0,B.jsx)(`li`,{children:(0,B.jsx)(hp,{dot:!1,children:m(e)})},e))}),k.length>0&&(0,B.jsx)(`span`,{className:`truncate text-xs text-muted-foreground ${d.length>0?``:`mt-auto`}`,children:k.map((e,t)=>(0,B.jsxs)(`span`,{children:[t>0&&(0,B.jsx)(`span`,{"aria-hidden":!0,children:` • `}),b(e)]},e))}),ee.length>0&&(0,B.jsx)(Kw,{dots:ee})]}),ne=t=>(0,B.jsxs)(Eh,{to:{kind:`record`,resource:e.name,key:r.key},onClick:()=>v(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&&!A&&(0,B.jsx)(hp,{tone:`blue`,className:`self-start`,children:a}),y?(0,B.jsx)($g,{name:n.card,fallback:te(t),children:(0,B.jsx)(y,{row:r})}):te(t)]});return(0,B.jsxs)(`div`,{className:w?`group/card relative h-full`:j||a||ee.length>0?`relative h-full`:`h-full`,children:[w?(0,B.jsx)(cT,{photos:r.photos??[],cover:D,swipe:i,children:ne},r.key):ne((0,B.jsx)(aT,{value:D})),a&&A&&(0,B.jsx)(hp,{tone:`blue`,className:`pointer-events-none absolute top-2 left-2 shadow-sm`,children:a}),ee.length>0&&(0,B.jsx)(qw,{dots:ee,Card:uT}),j&&(0,B.jsx)(Aw,{favorite:j,recordKey:r.key,target:om(e,r.record),className:A?void 0:`right-1.5 top-1.5`})]})},dT=268,fT=3,pT=(e,t,n)=>{let r=Math.floor(Math.max(0,e)/dT),i=Math.ceil((Math.max(0,e)+t)/dT);return{start:Math.max(0,r-fT),end:Math.min(n,i+fT)}},mT=e=>e*dT,hT=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]=[pT(t.left,t.width,e),pT(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,mT(e)-12),a=e=>t.current?.scrollBy({left:e*Math.max(mT(1),n.width-12),behavior:`smooth`});return{ref:t,...pT(n.left,n.width,e),back:n.left>0,on:n.left+n.width<i-1,page:a}},gT=M({en:{couldNotLoad:`Could not load`,noneMatch:e=>`No ${e} match.`,viewAll:`View all`,new:`New`,previous:e=>`Previous ${e}`,next:e=>`Next ${e}`,couldNotLoadYour:e=>`Could not load your ${e}`,noneYet:e=>`No ${e} yet.`},nl:{couldNotLoad:`Kon niet laden`,noneMatch:e=>`Geen ${e} gevonden.`,viewAll:`Alles bekijken`,new:`Nieuw`,previous:e=>`Terug in ${e}`,next:e=>`Verder in ${e}`,couldNotLoadYour:e=>`Kon je ${e} niet laden`,noneYet:e=>`Nog geen ${e}.`}}),_T=`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`,vT=({cards:e})=>e>0?(0,B.jsx)(`li`,{"aria-hidden":!0,className:`shrink-0`,style:{width:mT(e)-12}}):null,yT=({model:e,view:t,display:n,source:r,label:i,isNew:a})=>{let{total:o}=r,s=hT(o),c=iS({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)(vT,{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)(K,{className:`h-full min-h-24 rounded-lg`})},`skeleton-${r}`);let s=Zm(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)(uT,{model:e,view:t,display:n,row:s,swipe:!1,mark:a?.(s)?gT(`new`):void 0})},s.key)}),(0,B.jsx)(vT,{cards:o-s.end})]}),s.back&&(0,B.jsx)(`button`,{type:`button`,"aria-label":gT(`previous`,i.toLowerCase()),onClick:()=>s.page(-1),className:`${_T} -left-3`,children:(0,B.jsx)(mi,{className:`size-4`,"aria-hidden":!0})}),s.on&&(0,B.jsx)(`button`,{type:`button`,"aria-label":gT(`next`,i.toLowerCase()),onClick:()=>s.page(1),className:`${_T} -right-3`,children:(0,B.jsx)(gi,{className:`size-4`,"aria-hidden":!0})})]})},bT=on(),xT=(e,t)=>{if(!t)return e;let n=rt(e);if(!n.ok)throw Error(`The filter cannot be read: ${n.errors.map(e=>e.message).join(`; `)}`);return Jt(n.ast?bT.and(n.ast,t):t)},ST=(e,t)=>{let n=jm(e).filter(e=>e.kind===`cards`);return n.find(e=>e.name===t)??n[0]??{kind:`cards`,name:`cards`}},CT=()=>(0,B.jsx)(`div`,{className:`flex gap-3 overflow-hidden`,children:Array.from({length:3},(e,t)=>(0,B.jsx)(K,{className:`h-24 w-64 shrink-0`},t))}),wT=({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=fd(),g=ST(t,i),_=r||Qm(e,t),v=RS({resources:p,views:m,model:e,columns:(0,I.useMemo)(()=>Jm(e,t,[]),[e,t]),filter:(0,I.useMemo)(()=>xT(n,d),[n,d]),orderBy:_}),y=lw(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)(BS,{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(Ie())} ${S===1?b:x.toLowerCase()}`})]})]}):null,v.isLoading?(0,B.jsx)(CT,{}):v.error?(0,B.jsx)(pg,{title:gT(`couldNotLoad`),error:v.error}):!C||C.total===0?(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:s??gT(`noneMatch`,x.toLowerCase())}):(0,B.jsx)(yT,{model:e,view:t,display:g,source:C,label:x,isNew:l}),(0,B.jsxs)(Eh,{to:Qb(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:[gT(`viewAll`),` `,(0,B.jsx)(`span`,{className:`sr-only`,children:x.toLowerCase()})]}),(0,B.jsx)(Sr,{className:`size-3.5`,"aria-hidden":!0})]})]})},TT=({model:e,view:t,empty:n,...r})=>{let{resources:i,views:a}=W(),o=th(i,a,e.name),s=Ew(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)(pg,{title:gT(`couldNotLoadYour`,c),error:s.error});if(!s.data)return(0,B.jsx)(K,{className:`h-24`});let l=ww(o.model,s.data);return l?(0,B.jsx)(wT,{...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??gT(`noneYet`,c)})},ET=e=>H.list(e,``,``,500,`saved-searches`),DT=(e,t)=>{let n=U(),{resources:r,views:i}=W(),a=r[e];return E({queryKey:ET(e),enabled:t&&a!==void 0,queryFn:async()=>{let t=[],r;do{let o=await n.list(e,{pageSize:500,orderBy:Qm(a,i[e]),...r&&{pageToken:r}});t.push(...o.items),r=o.nextPageToken||void 0}while(r);return t}})},OT=({model:e,of:t,target:n,targetView:r,row:i,recordKey:a})=>{let s=U(),c=iv(),l=String(i[t.filter]??``),u=lw(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({...ev(s,n,p?sw(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:X(`noneMatch`,g),note:p&&h.data===0&&X(`noNew`,g),isNew:p&&(e=>cw(e.record[p.field],i[p.seenAt])),viewAll:{label:X(`viewAll`),savedSearch:a,...p&&{onOpen:()=>m.mutate(new Date().toISOString())}}};return{name:f,chips:u,title:f??HS(u),body:_}},kT=({model:e,view:t,target:n,targetView:r,row:i})=>{let a=An(om(e,i)),{name:o,chips:s,title:c,body:l}=OT({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)(Eh,{to:{kind:`record`,resource:e.name,key:a},className:`hover:underline`,children:o??(0,B.jsx)(VS,{chips:s})})}),(0,B.jsx)(wT,{...l})]})},AT=({model:e,view:t,empty:n})=>{let{resources:r,views:i}=W(),a=t.searchesOf,o=r[a.resource],s=DT(e.name,!0),c=(t.names?.plural??F(e.name)).toLowerCase();return o?s.error?(0,B.jsx)(pg,{title:X(`couldNotLoadYour`,c),error:s.error}):s.data?s.data.length===0?(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:n??X(`noneYet`,c)}):(0,B.jsx)(`div`,{className:`flex flex-col divide-y`,children:s.data.map(n=>(0,B.jsx)(kT,{model:e,view:t,target:o,targetView:i[a.resource],row:n},An(om(e,n))))}):(0,B.jsx)(K,{className:`h-40`}):null},jT=({node:e,slots:t})=>{let{resource:n,filter:r=``,sort:i,limit:a,display:o,title:s,description:c,empty:l}=cv(e),{resources:u,views:d}=W(),f=u[n];if(!f)return null;let p=d[f.name];return(0,B.jsx)(dv,{title:s,description:c,actions:t.actions,children:p?.searchesOf?(0,B.jsx)(AT,{model:f,view:p,empty:l}):p?.listOf===void 0?(0,B.jsx)(wT,{model:f,view:p,filter:r,sort:i,limit:a,display:o,empty:l}):(0,B.jsx)(TT,{model:f,view:p,limit:a,display:o,empty:l})})},MT=e=>e.type===`boolean`||e.type===`enum`,NT=({model:e,fields:t,title:n,description:r,stored:i})=>{let{resources:a,views:o}=W(),s=ed(e.name),c=U(),l=Gf(),u=iv(),d=o[e.name],[f,p]=(0,I.useState)(i),[m,h]=(0,I.useState)(()=>Fy(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=Fy(e,t,void 0),T=f?V_(s,`update`)&&f.permissions?.update!==!1:V_(s,`create`),E=t.filter(t=>!MT(e.fields[t])),D=E.some(t=>f?Yh(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,Iy(e,t,n.record),n.etag??`*`);return{...$_(e,r.record),etag:r.etag,permissions:r.permissions??n.permissions}}let r=await c.create(e.name,ag(e,a,{...w,...t}));return{...$_(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:Y(`saved`,n??Y(`settings`))})},e=>{_(t=>({...t,...My(e)})),y(e)}),x(!1)});S.current=r},A=(t,n)=>{h(e=>({...e,[t]:n})),MT(e.fields[t])&&k({[t]:n})};return(0,B.jsx)(dv,{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)(pg,{title:Y(`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)(ep,{name:t,label:r,help:d?.fields[t]?.help,error:i&&jy(n,r,i),children:(0,B.jsx)(y_,{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:Y(`save`)})})]})})},PT=e=>{let t=nv(e.model,{});return t.isPending?(0,B.jsx)(dv,{title:e.title,description:e.description,children:(0,B.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,B.jsx)(K,{className:`h-4 w-1/2`}),(0,B.jsx)(K,{className:`h-4 w-1/3`})]})}):t.error?(0,B.jsx)(dv,{title:e.title,description:e.description,children:(0,B.jsx)(pg,{title:Y(`couldNotLoad`),error:t.error})}):(0,B.jsx)(NT,{...e,stored:t.data??void 0})},FT=({node:e})=>{let{resource:t,fields:n=[],...r}=cv(e),i=W().resources[t];return i?(0,B.jsx)(PT,{...r,model:i,fields:n.filter(e=>Object.hasOwn(i.fields,e)),stored:void 0}):null},IT=(e,t)=>{let{resources:n}=W(),r=U(),i=JSON.stringify(e),a=(0,I.useMemo)(()=>JSON.parse(i).map(ll),[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=dl(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=hy(t,l),p=f({queries:u.map(e=>ev(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 ul(e,t)})},LT=({node:e,children:t})=>{let{when:n}=cv(e),[r]=IT([n],B_());return r?(0,B.jsx)(B.Fragment,{children:t}):null},RT=`text-2xl font-semibold tracking-tight tabular-nums`,zT=({model:e,filter:t})=>{let{views:n}=W(),r=tv(e,t);return r.isPending?(0,B.jsx)(K,{className:`h-8 w-16`}):r.error?(0,B.jsx)(`span`,{className:`text-danger-text`,children:Y(`couldNotCount`)}):(0,B.jsx)(Eh,{to:jv(n[e.name],e.name,t),className:`${RT} hover:text-primary-text after:absolute after:inset-0 after:content-['']`,children:r.data.toLocaleString(Ie())})},BT=({field:e,format:t})=>{let n=my(B_(),e);return n.state===`loading`?(0,B.jsx)(K,{className:`h-8 w-16`}):n.state===`missing`?null:(0,B.jsx)(`span`,{className:RT,children:(0,B.jsx)(uy,{model:n.model,field:n.field,value:n.value,format:t})})},VT=({node:e})=>{let{label:t,value:n,resource:r,filter:i,field:a,format:o,description:s}=cv(e),{resources:c}=W(),l=r===void 0?void 0:c[r];return(0,B.jsxs)(dv,{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:RT,children:n}),l&&(0,B.jsx)(zT,{model:l,filter:i}),a!==void 0&&(0,B.jsx)(BT,{field:a,format:o})]}),s&&(0,B.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:s})]})},HT=(e,t)=>{let n=e.position;if(!n||!V_(t,`update`))return;let r=e.fields[n.field];return r&&!r.readOnly?n.field:void 0},UT=(e,t)=>e.position?.within===void 0?HT(e,t):void 0,WT=(e,t,n)=>t.position?.within!==void 0&&e.field===t.position.within&&!e.through&&!e.from&&!e.filter?HT(t,n):void 0,GT=(e,t,n,r)=>{if(t===void 0||e?.list?.drag?.rank!==!0||r!==``)return!1;let i=$m(n);return i.columnId===t&&i.direction===`asc`},KT=e=>e===null?`none`:`value:${e}`,qT=e=>e.data.current?.sortable!==void 0,JT=e=>{let t=v(e),n=t.find(e=>e.data?.droppableContainer&&qT(e.data.droppableContainer));return n?[n]:t.length>0?t:b(e)},YT=(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=>!qT(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=XT(o,n,d.id)[0];return{x:d.rect.left+(d.rect.width-t.width)/2,y:f?.rect.top??d.rect.top}},XT=(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),ZT=(e,t)=>{let n=e.code===`ArrowDown`?1:e.code===`ArrowUp`?-1:0;if(n===0)return YT(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=XT(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}},QT=(e,t,n,r)=>{let i=Me({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=>Zm(e,t))),total:a[0]?.total??0,loading:i.isPending,error:i.error,more:i.hasNextPage,loadMore:()=>void i.fetchNextPage()}},$T=({model:e,by:t,value:n,fields:r,filter:i,orderBy:a})=>{let{resources:o,views:s}=W(),c=RS({resources:o,views:s,model:e,columns:r,filter:Om(i,t,n),orderBy:a});return QT(e,c.page,c.key,!0)},eE=(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))]},tE=({model:e,view:t,display:n,column:r,fields:i,filter:a,orderBy:o,limit:s,moves:c,movable:u,placeable:d,dragged:f})=>{let m=$T({model:e,by:n.by,value:r.value,fields:i,filter:a,orderBy:o}),h=km(e,t,n),g=new Set(m.rows.map(e=>e.key)),_=new Map(c.map(e=>[e.row.key,e])),v=m.rows.filter(e=>_.has(e.key)&&_.get(e.key).to!==r.value),y=c.filter(e=>e.to===r.value&&!g.has(e.row.key)).map(e=>e.row),b=m.rows.filter(e=>!v.includes(e)).map(e=>_.has(e.key)?_.get(e.key).row:e),x=c.findLast(e=>e.to===r.value&&e.order),S=eE([...y,...b],x?.order).slice(0,s),{setNodeRef:w,isOver:T}=p({id:KT(r.value),data:{column:r,rows:S}}),E=m.total-v.length+y.length;if(r.value===null&&!m.loading&&E===0&&!T)return null;let D=(t?.names?.plural??F(e.name)).toLowerCase(),O=t?.fields[n.by];return(0,B.jsxs)(`section`,{ref:w,"aria-label":`${r.label}, ${E}`,className:P(`flex w-72 shrink-0 snap-start flex-col gap-2 rounded-lg bg-surface p-2`,T&&`ring-2 ring-primary/30`),children:[(0,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)(sy,{value:r.value,hints:O,children:r.label})}),!m.loading&&(0,B.jsx)(`span`,{className:`text-xs tabular-nums text-muted-foreground`,children:E.toLocaleString(Ie())})]}),m.loading?Array.from({length:3},(e,t)=>(0,B.jsx)(K,{className:`h-20`},t)):m.error?(0,B.jsx)(pg,{title:q(`couldNotLoadRows`),error:m.error}):S.length===0?(0,B.jsx)(`p`,{className:`px-1 py-4 text-center text-xs text-muted-foreground`,children:q(`noPlural`,D)}):(0,B.jsx)(C,{id:KT(r.value),items:S.map(e=>e.key),strategy:l,children:(0,B.jsx)(`ul`,{className:`-mb-2 flex flex-col`,children:S.map(n=>(0,B.jsx)(nE,{model:e,view:t,card:h,row:n,column:r,rows:S,draggable:(u||d)&&H_(n.record,`update`),placeable:d,dragged:f},n.key))})}),s===void 0&&m.more&&(0,B.jsx)(G,{size:`sm`,variant:`ghost`,onClick:m.loadMore,children:q(`showMore`)})]})},nE=({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}=w({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)(uT,{model:e,view:t,display:n,row:r,swipe:!1})})},rE=e=>e.kind===`and`?e.args.flatMap(rE):[e],iE=e=>e.kind===`string`?String(e.value):void 0,aE=(e,t)=>{if(e.kind===`compare`&&e.op===`=`&&e.field.path.join(`.`)===t){let t=iE(e.value);return t===void 0?void 0:[t]}if(e.kind===`in`&&e.field.path.join(`.`)===t){let t=e.values.map(iE);return t.every(e=>e!==void 0)?t:void 0}},oE=(e,t,n)=>{let r=rt(e);if(!r.ok||!r.ast)return n;let i=rE(r.ast).map(e=>aE(e,t)).filter(e=>e!==void 0);return n.filter(e=>i.every(t=>e.value!==null&&t.includes(e.value)))},sE=(e,t)=>t!==null&&Object.hasOwn(e,t)?e[t]:void 0,cE=M({en:{done:`Done`,reorder:`Reorder`,couldNotLoad:`Could not load`,nothingYet:`Nothing here yet.`,couldNotChange:`Could not change the order`,orderChanged:`Order changed`,undo:`Undo`,couldNotUndo:`Could not undo`,movedToPlace:e=>`Moved to place ${e}`,notMoved:`Left in its place`,noRule:`No drop rule is registered as {}. Give it in dropRules in protobase.ui.tsx, or load the plugin that provides it.`},nl:{done:`Klaar`,reorder:`Volgorde wijzigen`,couldNotLoad:`Kon niet laden`,nothingYet:`Hier staat nog niets.`,couldNotChange:`Kon de volgorde niet wijzigen`,orderChanged:`Volgorde gewijzigd`,undo:`Ongedaan maken`,couldNotUndo:`Kon niet ongedaan maken`,movedToPlace:e=>`Verplaatst naar plaats ${e}`,notMoved:`Op zijn plaats gelaten`,noRule:`Er is geen sleepregel geregistreerd als {}. Geef die in dropRules in protobase.ui.tsx, of laad de plug-in die haar levert.`}}),lE=(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:om(e,r),data:Object.fromEntries(a.map(e=>[e,t[e]])),etag:i}]}),uE=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},dE=(e,t)=>t===void 0?e:`(${e}) AND (${t})`,fE=async(e,t,n,r)=>{let i=t.position?.after;if(!i)return{after:[],before:[]};let a=t.primaryKey[0],o=om(t,r),s=e=>An([e]),c=await uE(e,i.resource,dE(Jt(sn.or(sn.eq(i.field,o),sn.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([uE(e,t.name,dE(Jt(sn.in(a,[o,...u])),i.while)),d.length===0?[]:uE(e,t.name,Jt(sn.in(a,d)))]),m=e=>{let r=An(om(t,e));return{key:r,rank:e[t.position.field],title:or(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):[]}},pE=e=>typeof e==`number`&&Number.isInteger(e),mE=(e,t,n)=>{let r=0;for(;r<t&&pE(e[r])&&(r===0||e[r]>e[r-1]);)r+=1;let i=e.length;for(;i-1>n&&pE(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}},hE=(e,t,n)=>{let r=e.findIndex(e=>e.key===t.key);return r===-1?[...e.slice(0,n),t,...e.slice(n)]:s(e,r,n)},gE=(e,t,n)=>{let r=e.findIndex(e=>e.key===t.key);return{order:hE(e,t,n),first:r===-1?n:Math.min(r,n),last:r===-1?n:Math.max(r,n)}},_E=e=>typeof e.record.etag==`string`?e.record.etag:`*`,vE=(e,t,n,r,i,a,o,s,c)=>{let l=(r.record[t]??null)!==i.value,u=mE(a.map(e=>e.record[n]),o,s),d=a.slice(u.first,u.last+1),f=e=>l&&e.key===r.key?`*`:_E(e),p=(t,r)=>({op:`reorder`,resource:e.name,field:n,keys:t.map(t=>om(e,t.record)),start:r,etags:Object.fromEntries(t.map(t=>[An(om(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:om(e,r.record),data:{[t]:i.value},etag:_E(r)},...h]:h},yE=(e,t,n)=>{let r=new Map(t.map(t=>[An(om(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(An(om(e,t)),{record:t,etag:r})}return[...i].flatMap(([e,t])=>{let n=r.get(e);return n?[{before:n,...t}]:[]})},bE=M({en:{dependsOn:(e,t)=>`${e} depends on ${t}.`},nl:{dependsOn:(e,t)=>`${e} hangt af van ${t}.`}}),xE=e=>e!=null&&e!==``,SE=({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}=gE(n,r,l),f=i.map(e=>e.record[t]),p=mE(f,u,d),m=new Map(i.map((t,n)=>[An(om(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(An(om(e,r.record)))),_=a.after.filter(e=>xE(h(e))&&Number(h(e))>=g),v=a.before.find(e=>xE(h(e))&&Number(h(e))<=g),y=v?bE(`dependsOn`,v.title,o):_[0]&&bE(`dependsOn`,o,_[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=>!xE(h(e))||Number(h(e))>b))return{place:{index:l,bump:b},reason:c}}return{reason:c}},CE=({model:e,view:t,by:n,rank:r,drop:i,labelOf:a,titleOf:s})=>{let c=U(),l=Gf(),u=iv(),[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:q(`couldNotUndo`),description:Am(e)}),onSettled:()=>u(e.name)}),_=async(t,r)=>{let a=i&&sE(i,r.value);if(!a)throw Error(`The column ${r.label} takes no cards`);let o=om(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(lE(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 fE(c,e,t,n.record),u=SE({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?cE(`notMoved`):cE(`movedToPlace`,u.place.index+1),description:u.reason}),!d)return u.place.index!==a.index&&y(n,i,gE(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}=gE(a.rows,t,o.index);return v(yE(e,s,await c.batchWrite(vE(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,om(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&&gE(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?q(`orderChanged`):q(`stayedIn`,a(i)):q(`movedTo`,a(i));if(!o){l.show({state:`success`,title:c});return}let u=l.show({state:`success`,title:c,action:{label:q(`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?q(`couldNotReorder`):q(`couldNotMoveTo`,r.label);l.show({state:`error`,title:i,description:Am(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}})}},wE=(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}},TE=({model:e,view:t,display:n,fields:r,filter:i,orderBy:o,limit:s})=>{let l=Em(e,t,n),u=oE(i,n.by,l),d=km(e,t,n),f=ed(e.name),{boardDrops:p}=Wg(),m=t?.list?.drag,h=typeof m?.board==`string`?m.board:void 0,_=h===void 0?void 0:p?.[h],v=t=>V_(f,`update`)&&(m?.board===!0?!e.fields[n.by]?.readOnly:_!==void 0&&sE(_,t)!==void 0),b=u.some(e=>v(e.value)),x=Dm(e),C=m?.rank===!0&&x!==void 0&&UT(e,f)!==void 0,w=x?`${x} asc`:o,T=e=>l.find(t=>t.value===e)?.label??String(e),E=e=>String(e.labels[d.title]??e.record[d.title]??e.key),{moves:D,move:O}=CE({model:e,view:t,by:n.by,rank:x,drop:_,labelOf:T,titleOf:E}),[k,A]=(0,I.useState)(),j=(0,I.useRef)(!1),ee=S(g(a,{activationConstraint:{distance:4}}),g(de,{activationConstraint:{delay:250,tolerance:5}}),g(fe,{keyboardCodes:{start:[`Space`],cancel:[`Escape`],end:[`Space`,`Enter`]},coordinateGetter:ZT}));if(h!==void 0&&!_)return(0,B.jsx)(Zg,{children:Qg(q(`noDrop`),h)});let te=e=>u.find(t=>KT(t.value)===e),ne=e=>e.record[n.by]??null,re=(e,t)=>v(ne(e))&&v(t.value),ie=(e,t)=>{if(!t)return{over:q(`noColumn`)};let n=C?wE(t,e):void 0;if(!n)return{over:te(t.id)?.label??q(`noColumn`)};let r=n.rows.some(t=>t.key===e.key)?n.rows.length:n.rows.length+1;return{over:q(`placeOf`,n.column.label,n.index+1,r),place:q(`place`,n.column.label,n.index+1)}},ae=(e,t)=>{let n=(C?wE(t,e)?.column:void 0)??te(t.id);return n!==void 0&&n.value!==ne(e)&&!re(e,n)};return(0,B.jsxs)(c,{sensors:ee,collisionDetection:JT,onDragStart:({active:e})=>{j.current=!0,A(e.data.current.row)},onDragEnd:({active:e,over:t})=>{A(void 0),setTimeout(()=>j.current=!1);let n=e.data.current.row;if(!t)return;let r=C?wE(t,n):void 0;if(!r){let e=te(t.id);e&&e.value!==ne(n)&&re(n,e)&&O(n,e);return}let i=r.rows.findIndex(e=>e.key===n.key);if(i!==-1||re(n,r.column)){if(i===-1&&_)return O(n,r.column);i!==r.index&&O(n,r.column,{rows:r.rows,index:r.index})}},onDragCancel:()=>{A(void 0),setTimeout(()=>j.current=!1)},accessibility:{announcements:{onDragStart:({active:e})=>q(`pickedUp`,E(e.data.current.row)),onDragOver:({active:e,over:t})=>q(`isOver`,E(e.data.current.row),ie(e.data.current.row,t).over),onDragEnd:({active:e,over:t})=>{let n=e.data.current.row;if(!t||ae(n,t))return q(`putBack`,E(n));let r=ie(n,t);return q(`wasMovedTo`,E(n),r.place??r.over)},onDragCancel:({active:e})=>q(`cancelled`,E(e.data.current.row))},screenReaderInstructions:{draggable:q(C?b?`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:u.map(a=>(0,B.jsx)(tE,{model:e,view:t,display:n,column:a,fields:r,filter:i,orderBy:w,limit:s,moves:D,movable:v(a.value),placeable:C,dragged:()=>j.current},KT(a.value)))})}),(0,B.jsx)(y,{children:k&&(0,B.jsx)(uT,{model:e,view:t,display:d,row:k,swipe:!1})})]})},EE=864e5,DE=e=>new Date(e).toISOString().slice(0,10),OE=e=>Date.parse(`${e}T00:00:00Z`),kE=(e,t)=>DE(OE(e)+t*EE),AE=e=>kE(e,-((new Date(OE(e)).getUTCDay()+6)%7)),jE=(e,t=0)=>{let n=new Date(OE(e));return DE(Date.UTC(n.getUTCFullYear(),n.getUTCMonth()+t,1))},ME=({scale:e,day:t})=>({scale:e,day:e===`month`?jE(t):AE(t)}),NE=(e,t,n=Gd())=>ME(e??{scale:`month`,day:Zd(t,n)}),PE=(e,t,n=Gd())=>ME({scale:e,day:Zd(t,n)}),FE=(e,t)=>e.scale===`month`?{scale:`month`,day:jE(e.day,t)}:{scale:`week`,day:kE(AE(e.day),7*t)},IE=e=>{let t=AE(e.scale===`month`?jE(e.day):e.day),n=(OE(e.scale===`month`?kE(AE(kE(jE(e.day,1),-1)),6):kE(t,6))-OE(t))/EE+1;return Array.from({length:n},(e,n)=>kE(t,n))},LE=e=>{let t=IE(e);return{from:t[0],to:kE(t.at(-1),1)}},RE=(e,t)=>t.fields[e.start]?.type===`timestamp`,zE=(e,t,n,r=Gd())=>{let i=RE(e,t),a=e=>new Date($d(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=sn.and(sn.gte(e.start,o(n.from)),sn.lt(e.start,o(n.to)));if(e.end===void 0)return Jt(s);let c=i?sn.gt(e.end,o(n.from)):sn.gte(e.end,o(n.from));return Jt(sn.or(s,sn.and(sn.lt(e.start,o(n.from)),c)))},BE=(e,t)=>e===``?t:`(${e}) AND (${t})`,VE=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},HE=(e,t,n,r=Gd())=>{let i=VE(e[t.start]);if(i===void 0)return;let a=RE(t,n),o=e=>a?Zd(e,r):DE(e),s=o(i),c=t.end===void 0?void 0:VE(e[t.end]),l=c===void 0?s:o(a?c-1:c);return{first:s,last:l<s?s:l}},UE=(e,t,n,r,i=Gd())=>{let a=HE(e,t,n,i);return a?r.filter(e=>e>=a.first&&e<=a.last):[]},WE=(e,t)=>e.toSorted((e,n)=>(VE(e.record[t.start])??0)-(VE(n.record[t.start])??0)),GE=(e,t,n,r,i=Gd())=>{let a=new Map(r.map(e=>[e,[]]));for(let o of WE(e,t))for(let e of UE(o.record,t,n,r,i))a.get(e).push(o);return a},KE=(e,t,n,r,i,a=Gd())=>{let o=(OE(i)-OE(r))/EE,s=RE(t,n),c=e=>{let t=VE(e);if(t!==void 0)return s?new Date(Qd(t+Yd(t,a)+o*EE,a)).toISOString():kE(DE(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}}},qE=({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)(Eh,{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=ld({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,q(`previousPeriod`,t),(0,B.jsx)(mi,{className:`size-3.5`})),l(r,u,q(`today`),q(`today`)),l(i,u,q(`nextPeriod`,t),(0,B.jsx)(gi,{className:`size-3.5`}))]}),(0,B.jsx)(`span`,{role:`group`,"aria-label":o,className:Re.group(),children:a.map(e=>(0,B.jsx)(I.Fragment,{children:l(e.view,Re.option(e.current),e.label,e.label,e.current)},e.label))})]})]})},JE=e=>{let t=IE(e),n=e=>Date.parse(`${e}T00:00:00Z`);return e.scale===`month`?pf(n(e.day)):vf(n(t[0]),n(t.at(-1)))},YE=({view:e,now:t,linkTo:n,onView:r})=>{let i=e.scale===`month`&&Zd(t,Gd()).startsWith(e.day.slice(0,7)),a=n=>n===`week`&&i?PE(`week`,t):NE({scale:n,day:e.day},t),o=(t,n)=>({view:a(t),label:n,current:e.scale===t});return(0,B.jsx)(qE,{heading:JE(e),unit:e.scale===`month`?`month`:`week`,previous:FE(e,-1),today:PE(e.scale,t),next:FE(e,1),scales:[o(`month`,q(`month`)),o(`week`,q(`week`))],scalesLabel:q(`calendarScale`),linkTo:n,onView:r})},XE=`day:`,ZE=e=>`${XE}${e}`,QE=(e,t)=>`${e}@${t}`,$E=(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(ZE(kE(o,a)));if(s)return{x:s.left+(s.width-n.width)/2,y:s.top+4}},eD=({day:e,count:t,children:n,more:r,inMonth:i,today:a,week:o})=>{let{setNodeRef:s,isOver:c}=p({id:ZE(e)}),l=Date.parse(`${e}T00:00:00Z`);return(0,B.jsxs)(`section`,{ref:s,"aria-label":`${_f(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:gf(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]})},tD=(e,t,n,r)=>{let i=n.title??ar(e,t),a=e.fields[i],o=r.labels[i]??(a?bm(a,r.record[i],t?.fields[i]):``);return o===``?r.key:o},nD=(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 Zd(a,Gd())===r?yf(a):void 0},rD=({model:e,view:t,display:n,row:r,day:i,className:a})=>{let o=dw(e),s=nD(e,n,r,i);return(0,B.jsxs)(Eh,{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:tD(e,t,n,r)})]})},iD=({movable:e,dragged:t,...n})=>{let{setNodeRef:r,setActivatorNodeRef:i,listeners:a,isDragging:o}=u({id:QE(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)(rD,{...n})})},aD=({model:e,display:t,range:n,fields:r,filter:i})=>{let{resources:a,views:o}=W(),s=RS({resources:a,views:o,model:e,columns:r,filter:BE(i,zE(t,e,n)),orderBy:`${t.start} asc`}),c=QT(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}},oD=(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)},sD=(e,t)=>{let n=U(),r=Gf(),i=iv(),[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,om(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:q(`couldNotMoveTo`,lf(Date.parse(`${n}T00:00:00Z`))),description:Am(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:KE(n.record,t,e,r,i),to:i})}},cD=3,lD=({model:e,view:t,display:n,fields:r,filter:i,at:o,linkTo:s,now:l=Date.now()})=>{let[u,d]=(0,I.useState)(),f=NE(s?o:u,l),p=IE(f),m=aD({model:e,display:n,range:LE(f),fields:r,filter:i}),{moves:h,move:_}=sD(e,n),v=GE(oD(m.rows,h),n,e,p),b=V_(ed(e.name),`update`)&&[n.start,n.end].every(t=>t===void 0||!e.fields[t]?.readOnly),[x,C]=(0,I.useState)(),w=(0,I.useRef)(!1),T=S(g(a,{activationConstraint:{distance:4}}),g(de,{activationConstraint:{delay:250,tolerance:5}}),g(fe,{keyboardCodes:{start:[`Space`],cancel:[`Escape`],end:[`Space`,`Enter`]},coordinateGetter:$E})),E=Zd(l,Gd()),D=f.scale===`week`,O=e=>lf(Date.parse(`${String(e).slice(ZE(``).length)}T00:00:00Z`)),k=r=>tD(e,t,n,r.row),A={onDragStart:({active:e})=>q(`pickedUp`,k(e.data.current)),onDragOver:({active:e,over:t})=>q(`isOver`,k(e.data.current),t?O(t.id):q(`noDay`)),onDragEnd:({active:e,over:t})=>t?q(`wasMovedTo`,k(e.data.current),O(t.id)):q(`putBack`,k(e.data.current)),onDragCancel:({active:e})=>q(`cancelled`,k(e.data.current))},j=()=>{C(void 0),setTimeout(()=>w.current=!1)},ee=({active:e})=>{w.current=!0,C(e.data.current)},te=({active:e,over:t})=>{j();let{row:n,day:r}=e.data.current,i=t?String(t.id).slice(ZE(``).length):void 0;i&&i!==r&&_(n,r,i)},ne=(e,t)=>{let n=NE({scale:`week`,day:e},l),r=q(`moreHidden`,t),i=`self-start rounded px-1 text-xs text-muted-foreground hover:text-foreground focus-visible:outline-2 focus-visible:outline-primary`;return s?(0,B.jsx)(Eh,{to:s(n),className:i,children:r}):(0,B.jsx)(`button`,{type:`button`,className:i,onClick:()=>d(n),children:r})};return(0,B.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-3`,children:[(0,B.jsx)(YE,{view:f,now:l,linkTo:s,onView:d}),m.error&&(0,B.jsx)(pg,{title:q(`couldNotLoadRows`),error:m.error}),m.capped&&(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:q(`capped`,500,f.scale)}),(0,B.jsxs)(c,{sensors:T,collisionDetection:JT,onDragStart:ee,onDragEnd:te,onDragCancel:j,accessibility:{announcements:A,screenReaderInstructions:{draggable:q(`calendarInstructions`)}},children:[(0,B.jsxs)(`div`,{className:`overflow-hidden rounded-lg border border-border`,children:[!D&&(0,B.jsx)(`div`,{"aria-hidden":!0,className:`grid grid-cols-7 gap-px border-b border-border bg-border`,children:p.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:gf(Date.parse(`${e}T00:00:00Z`))},e))}),(0,B.jsx)(`div`,{className:P(`grid gap-px bg-border`,D?`grid-cols-1 sm:grid-cols-7`:`grid-cols-7`),children:p.map(r=>{let i=v.get(r),a=D?i:i.slice(0,cD);return(0,B.jsx)(eD,{day:r,count:i.length,inMonth:D||r.startsWith(f.day.slice(0,7)),today:r===E,week:D,more:a.length<i.length&&ne(r,i.length-a.length),children:m.loading?(0,B.jsx)(K,{className:`h-4`}):a.map(i=>(0,B.jsx)(iD,{model:e,view:t,display:n,row:i,day:r,movable:b&&H_(i.record,`update`),dragged:()=>w.current},i.key))},r)})})]}),(0,B.jsx)(y,{children:x&&(0,B.jsx)(rD,{model:e,view:t,display:n,row:x.row,day:x.day})})]})]})},uD=864e5,dD=e=>Date.parse(`${e}T00:00:00Z`),fD=(e,t=0)=>{let n=new Date(dD(e));return new Date(Date.UTC(n.getUTCFullYear(),Math.floor(n.getUTCMonth()/3)*3+3*t,1)).toISOString().slice(0,10)},pD=({scale:e,day:t})=>({scale:e,day:e===`week`?AE(t):e===`month`?jE(t):fD(t)}),mD=(e,t,n=Gd())=>pD(e??{scale:`month`,day:Zd(t,n)}),hD=(e,t)=>{let{scale:n,day:r}=pD(e);return{scale:n,day:n===`week`?kE(r,7*t):n===`month`?jE(r,t):fD(r,t)}},gD=e=>{let t=pD(e).day,n=(dD(hD(e,1).day)-dD(t))/uD;return Array.from({length:n},(e,n)=>kE(t,n))},_D=e=>({from:pD(e).day,to:hD(e,1).day}),vD=(e,t,n,r=Gd())=>{let i=Zd(n,r),a=gD(e);return pD({scale:t,day:i>=a[0]&&i<=a.at(-1)?i:a[0]})},yD=e=>{let t=gD(e);return e.scale===`week`?vf(dD(t[0]),dD(t.at(-1))):e.scale===`month`?pf(dD(t[0])):hf(dD(t[0]),dD(jE(t.at(-1))))},bD=e=>{let t=gD(e);if(e.scale===`week`)return t.map((e,t)=>({index:t,span:1,label:`${gf(dD(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:mf(dD(t[e]))}))},xD=(e,t,n,r,i=Gd())=>{let a=HE(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}},SD=`none`,CD=(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?SD:`value:${String(e)}`,c=n?q(`noValue`,o?.label??F(i)):t.labels[i]??bm(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)},wD=`grid grid-cols-1 sm:grid-cols-[12rem_minmax(0,1fr)]`,TD=(e,t)=>`${e/t*100}%`,ED=({ticks:e,days:t,today:n,label:r,trackRef:i})=>(0,B.jsxs)(`div`,{className:P(wD,`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:TD(e.index,t.length),width:TD(e.span,t.length)},children:e.label},e.index))})]}),DD=({ticks:e,days:t,today:n})=>{let r=t.indexOf(n);return(0,B.jsxs)(`div`,{"aria-hidden":!0,className:P(wD,`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:TD(r,t.length),width:TD(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:TD(e.index,t.length)}},e.index))]})]})},OD=({model:e,view:t,display:n,row:r,days:i,movable:a,dragged:o})=>{let s=xD(r.record,n,e,i);return(0,B.jsxs)(`div`,{className:P(wD,`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:tD(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:TD(s.first,i.length),width:TD(s.last-s.first+1,i.length)},children:(0,B.jsx)(iD,{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`)})})})]})},kD=()=>[{scale:`week`,label:q(`week`)},{scale:`month`,label:q(`month`)},{scale:`quarter`,label:q(`quarter`)}],AD=({model:e,view:t,display:n,fields:r,filter:i,at:o,linkTo:s,now:l=Date.now()})=>{let[u,d]=(0,I.useState)(),f=mD(s?o:u,l),p=gD(f),m=bD(f),h=aD({model:e,display:n,range:_D(f),fields:r,filter:i}),{moves:_,move:v}=sD(e,n),b=CD(WE(oD(h.rows,_),n),e,t,n),x=V_(ed(e.name),`update`)&&[n.start,n.end].every(t=>t===void 0||!e.fields[t]?.readOnly),[C,w]=(0,I.useState)(),T=(0,I.useRef)(!1),E=(0,I.useRef)(0),D=(0,I.useRef)(null),O=()=>(D.current?.getBoundingClientRect().width??0)/p.length,k=e=>{let t=O();return t>0?Math.round(e/t):0},A=({transform:e})=>({...e,x:k(e.x)*O(),y:0}),j=S(g(a,{activationConstraint:{distance:4}}),g(de,{activationConstraint:{delay:250,tolerance:5}}),g(fe,{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*O(),y:t.y}}})),ee=Zd(l,Gd()),te=r=>tD(e,t,n,r.row),ne=e=>lf(Date.parse(`${kE(e.day,E.current)}T00:00:00Z`)),re={onDragStart:({active:e})=>q(`pickedUp`,te(e.data.current)),onDragMove:({active:e})=>q(`startsOn`,te(e.data.current),ne(e.data.current)),onDragOver:()=>void 0,onDragEnd:({active:e})=>E.current===0?q(`putBack`,te(e.data.current)):q(`wasMovedTo`,te(e.data.current),ne(e.data.current)),onDragCancel:({active:e})=>q(`cancelled`,te(e.data.current))},ie=()=>{w(void 0),setTimeout(()=>T.current=!1)},ae=({active:e})=>{T.current=!0,E.current=0,w(e.data.current)},oe=({delta:e})=>E.current=k(e.x),se=({active:t,delta:r})=>{ie(),E.current=k(r.x);let{row:i}=t.data.current,a=HE(i.record,n,e);a&&E.current!==0&&v(i,a.first,kE(a.first,E.current))},ce=n.group===void 0?t?.names?.plural??F(e.name):t?.fields[n.group]?.label??F(n.group),le=!h.loading&&!h.error&&h.rows.length===0;return(0,B.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-3`,children:[(0,B.jsx)(qE,{heading:yD(f),unit:f.scale,previous:hD(f,-1),today:mD({scale:f.scale,day:ee},l),next:hD(f,1),scales:kD().map(({scale:e,label:t})=>({view:vD(f,e,l),label:t,current:f.scale===e})),scalesLabel:q(`timelineScale`),linkTo:s,onView:d}),h.error&&(0,B.jsx)(pg,{title:q(`couldNotLoadRows`),error:h.error}),h.capped&&(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:q(`capped`,500,f.scale)}),(0,B.jsxs)(c,{sensors:j,modifiers:[A],onDragStart:ae,onDragMove:oe,onDragEnd:se,onDragCancel:ie,accessibility:{announcements:re,screenReaderInstructions:{draggable:q(`timelineInstructions`)}},children:[(0,B.jsxs)(`div`,{className:`overflow-hidden rounded-lg border border-border`,children:[(0,B.jsx)(ED,{ticks:m,days:p,today:ee,label:ce,trackRef:D}),(0,B.jsxs)(`div`,{className:`relative`,children:[(0,B.jsx)(DD,{ticks:m,days:p,today:ee}),h.loading&&(0,B.jsxs)(`div`,{className:`relative flex flex-col gap-2 p-2`,children:[(0,B.jsx)(K,{className:`h-4`}),(0,B.jsx)(K,{className:`h-4`})]}),le&&(0,B.jsx)(`p`,{className:`relative px-2 py-3 text-xs text-muted-foreground`,children:q(`nothingIn`,f.scale)}),!h.loading&&b.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)(OD,{model:e,view:t,display:n,row:r,days:p,movable:x&&H_(r.record,`update`),dragged:()=>T.current},r.key))]},r.key))]})]}),(0,B.jsx)(y,{children:C&&(0,B.jsx)(rD,{model:e,view:t,display:n,row:C.row,day:C.day})})]})]})},jD=({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)(pg,{title:q(`couldNotLoadRows`),error:e.error}):e.rows.length===0?(0,B.jsx)(`p`,{className:`py-8 text-center text-muted-foreground`,children:t}):r}),MD=({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(Ie()),` of `,e.total.toLocaleString(Ie())]}),e.more&&(0,B.jsx)(G,{size:`sm`,onClick:e.loadMore,children:q(`showMore`)})]}),ND=`grid grid-cols-[repeat(auto-fill,minmax(15rem,1fr))] gap-3`,PD=`relative flex snap-x snap-mandatory gap-3 overflow-x-auto pb-1`,FD=({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)(jD,{list:r,empty:q(`noneMatch`,o),loading:(0,B.jsx)(`div`,{className:ND,children:Array.from({length:6},(e,t)=>(0,B.jsx)(K,{className:`h-24`},t))}),children:[(0,B.jsx)(`ul`,{className:i?PD:ND,"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)(uT,{model:e,view:t,display:n,row:r,swipe:!i})},r.key))}),a&&(0,B.jsx)(MD,{list:r})]})},ID=(0,I.createContext)(void 0),LD=({value:e,children:t})=>(0,B.jsx)(ID.Provider,{value:e,children:t}),RD=()=>{let e=(0,I.useContext)(ID);if(!e)throw Error(`useListDisplay is used inside a list display, which the list page draws`);return e},zD=()=>(0,I.useContext)(ID),BD=({display:e,list:t})=>{let{components:n}=Wg(),r=n?.[e.component];return r?(0,B.jsx)(LD,{value:t,children:(0,B.jsx)(`div`,{className:`relative min-w-0 flex-1 overflow-x-auto`,children:(0,B.jsx)($g,{name:e.component,children:(0,B.jsx)(r,{..._n(e.props??{})})})})}):(0,B.jsx)(Zg,{children:Qg(q(`noComponent`),e.component)})},VD=on(),HD={bounds:{south:-90,west:-180,north:90,east:180},zoom:0},UD=22,WD=e=>Math.floor(e*1e6)/1e6,GD=e=>Math.ceil(e*1e6)/1e6,KD=e=>((e+180)%360+360)%360-180,qD=(e,t)=>{let n=[VD.gte(e.latitude,WD(Math.max(t.south,-90))),VD.lte(e.latitude,GD(Math.min(t.north,90)))];if(t.east-t.west>=360)return VD.and(...n);let r=VD.gte(e.longitude,WD(KD(t.west))),i=VD.lte(e.longitude,GD(KD(t.east)));return KD(t.west)<=KD(t.east)?VD.and(...n,r,i):VD.and(...n,VD.or(r,i))},JD=(e,t,n)=>{let r=Jt(qD(t,n));return e.trim()===``?r:`(${e}) AND ${r}`},YD=e=>Math.min(Math.max(Math.floor(e),0),UD),XD=(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))}},ZD=e=>{if(typeof e==`number`)return e;if(typeof e==`string`&&e.trim()!==``)return Number(e)},QD=(e,t)=>{let n=ZD(e[t.latitude]),r=ZD(e[t.longitude]);if(n!==void 0&&r!==void 0&&Math.abs(n)<=90&&Math.abs(r)<=180)return{latitude:n,longitude:r}},$D=6371008.8,eO=64,tO=(e,t)=>t.approximate===void 0?t.exact!==void 0&&e[t.exact]===!1:e[t.approximate]===!0,nO=(e,t)=>{let n=t/$D,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%eO/eO*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]})]}},rO=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,iO=(e,t)=>Array.isArray(e)&&e.length>=t&&e.every(rO),aO=e=>Array.isArray(e)&&e.length>0&&e.every(e=>iO(e,4)),oO=e=>Array.isArray(e)&&e.length>0&&e.every(e=>iO(e,2)),sO=e=>{if(typeof e!=`string`)return e;try{return JSON.parse(e)}catch(e){if(e instanceof SyntaxError)return;throw e}},cO=e=>{let t=sO(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`&&aO(i)||r===`MultiPolygon`&&Array.isArray(i)&&i.length>0&&i.every(aO)||r===`LineString`&&iO(i,2)||r===`MultiLineString`&&oO(i))return{type:r,coordinates:i}},lO=(e,t,n)=>{if(!tO(e,t))return;let r=t.area===void 0?void 0:cO(e[t.area]);if(r)return r;let i=t.radius===void 0?void 0:ZD(e[t.radius]);return i!==void 0&&Number.isFinite(i)&&i>0?nO(n,i):t.defaultRadius===void 0?void 0:nO(n,t.defaultRadius)},uO=(e,t)=>e.flatMap(e=>{let n=QD(e.record,t);if(!n)return[];if(!tO(e.record,t))return[{key:e.key,...n}];let r=lO(e.record,t,n);return[{key:e.key,...n,approximate:!0,...r&&{area:r}}]}),dO=(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}))},fO=(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)}},pO=(e,t)=>({keys:e.keys,index:((e.index+t)%e.keys.length+e.keys.length)%e.keys.length}),mO=({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?JD(i,u,o.bounds):``,p=o?YD(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:iy(c,l,e,r),photos:Cm(t)});return{rows:ay(c,e,r,wm(e,n.items,n.photos),n.labels).map(t=>Zm(e,t)),buckets:n.buckets,total:n.totalSize}}})},hO=(0,I.lazy)(()=>Be(()=>import(`./records-map-C-UIoBtb.js`).then(e=>({default:e.RecordsMap})),__vite__mapDeps([4,1,2,5,6,3,7]))),gO=250,_O=`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`,vO=({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=mC(m,gO),[_,v]=(0,I.useState)(o===void 0),y=mO({model:e,view:t,display:n,fields:a,filter:r,orderBy:i,area:_?HD:g}),b=y.isPlaceholderData?void 0:y.data,x=y.data?.rows??[],S=y.data?.buckets??[],C=uO(x,n),w=_&&b?XD(uO(b.rows,n),b.buckets):void 0,T=Km(t,n),E=(t?.names?.plural??F(e.name)).toLowerCase(),D=(t?.names?.singular??F(e.name)).toLowerCase(),O=fO(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?q(t===1?`showOneApproximate`:`showOne`,D):t===0?q(`showMany`,e.length,E):t===e.length?q(`showManyApproximate`,e.length,E):q(`showManySomeApproximate`,e.length,E,t)},ee=e=>q(`zoomIn`,e.toLocaleString(Ie()),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)(Zg,{children:q(`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)(hO,{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)(pg,{title:q(`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:[q(_?`noneMatch`:`noneHere`,E),!_&&(0,B.jsx)(G,{size:`sm`,onClick:()=>v(!0),children:q(`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":q(`chosen`,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)(wi,{className:`size-3.5`,"aria-hidden":!0}),q(`approximatePosition`)]}),O.keys.length>1&&(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`button`,{type:`button`,"aria-label":q(`previous`),className:_O,onClick:()=>p(pO(O,-1)),children:(0,B.jsx)(mi,{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":q(`next`),className:_O,onClick:()=>p(pO(O,1)),children:(0,B.jsx)(gi,{className:`size-4`,"aria-hidden":!0})})]}),(0,B.jsx)(`button`,{type:`button`,"aria-label":q(`close`),className:_O,onClick:()=>p(void 0),children:(0,B.jsx)(Ls,{className:`size-4`,"aria-hidden":!0})})]}),(0,B.jsx)(`div`,{className:`shadow-lg`,children:(0,B.jsx)(uT,{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:yO(y.data,E)})]})},yO=(e,t)=>{if(!e)return`\xA0`;let n=e.total.toLocaleString(Ie());return e.buckets.length===0&&e.rows.length<e.total?`${e.rows.length.toLocaleString(Ie())} of ${n} ${t} in view`:`${n} ${t} in view`},bO=({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)(fi,{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=dC(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)(ui,{className:`size-3.5 text-primary-text`})]})},t.value))})]})},xO={table:ss,cards:Ea,kanban:$o,board:Ai,list:Pa,calendar:ni,timeline:ci,map:Ka},SO=({view:e,value:t,onChange:n,menu:r=!1,choices:i=Bm(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:xO[e.icon]}));return r?(0,B.jsx)(bO,{label:q(`display`),value:t,onChange:n,options:a}):(0,B.jsx)(Le,{label:q(`display`),size:`md`,value:t,onChange:n,options:a})},CO=[[`asc`,`ascending`],[`desc`,`descending`]],wO=({model:e,view:t,display:n,orderBy:r,onChange:i,className:a})=>{let o=$m(r),s=Ym(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":q(`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=>CO.map(([t,n])=>(0,B.jsxs)(`option`,{value:`${e} ${t}`,children:[l(e),`, `,q(n)]},`${e} ${t}`)))})},TO=(e,t,n,r)=>e.map(e=>{let i=t.fields[e.id],a=i&&Gg(r,i,n?.fields[e.id]);return a?{...e,render:t=>(0,B.jsx)(n_,{shown:a,part:`cell`,field:i,value:t[e.id],fallback:ux(e,e.value?e.value(t):t[e.id])})}:e}),EO=e=>e.includes(`.`),DO=({model:e,row:t,column:n})=>{let r=my($_(e,Zm(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)(uy,{model:r.model,field:r.field,value:r.value})},OO=(e,t,{resources:n,views:r})=>{let i=pl(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)(DO,{model:e,row:n,column:t})}},kO=(e,t,n,r)=>{let i=new Map(TO(vm(e,t,[],n.filter(e=>!EO(e))),e,t,r.fieldTypes).map(e=>[e.id,e]));return n.flatMap(t=>EO(t)?[OO(e,t,r)]:i.get(t)??[])},AO=(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},jO=(e,t,n)=>{if(e.open!==void 0)return e.open!==e.field&&AO(t,e.open,n)?e.open:void 0;let r=t.primaryKey.filter(r=>r!==e.field&&r!==t.tenant&&AO(t,r,n));return r.length===1?r[0]:void 0},MO=(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},NO=(e,t)=>(t?.names?.singular??F(e.name)).toLowerCase(),PO=({model:e,view:t,opens:n,resources:r,views:i,canUpdate:a})=>{let o=t=>({kind:`record`,resource:e.name,key:om(e,t)}),s=n&&e.fields[n]?.relation?.resource,c=s?r[s]:void 0,l=e=>{let t=n&&c?MO(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=NO(e,t);return{address:u,actions:t=>{let n={label:Gb(`open`,d),link:e=>t(o(e))};if(!c)return[n];let r=e=>a&&H_(e,`update`);return[{label:Gb(`open`,NO(c,i[c.name])),available:e=>l(e)!==void 0,link:e=>t(l(e))},{label:Gb(`edit`,d),available:r,link:n=>t({kind:`record`,resource:e.name,key:om(e,n),edit:!0})},{...n,available:e=>!r(e)}]}}},FO=({model:e,filter:t,orderBy:n,limit:r,fields:i})=>{let a=U(),{resources:o,views:s}=W();return E({queryKey:[...H.list(e.name,t,n,r,`embedded`),i.join(`,`)],placeholderData:d,queryFn:async()=>{let c=iy(o,s,e,i),l=Cm(s[e.name]),u=await a.search(e.name,{filter:t||void 0,orderBy:n||void 0,pageSize:r,count:`exact`,labels:c,photos:l}),d=ay(o,e,i,wm(e,u.items,u.photos),u.labels).map((t,n)=>({...t,id:am(e,u.items[n])}));return u.nextPageToken===``?{rows:d,total:d.length,estimated:!1}:{rows:d,total:u.totalSize??u.totalSizeEstimate,estimated:u.totalSize===void 0}}})},IO=({view:e,value:t,onChange:n})=>(0,B.jsx)(SO,{view:e,value:t,onChange:n,menu:!dd()}),LO=()=>(0,B.jsx)(`div`,{className:`flex flex-col gap-2`,children:Array.from({length:3},(e,t)=>(0,B.jsx)(K,{className:`h-4 w-full`},t))}),RO=({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=V_(ed(e.name),`update`),{fields:h}=Wg(),{go:g,href:_}=Th(),v=fd(),[y,b]=(0,I.useState)(r||Qm(e,t)),x=i??mr(e,t),S=(0,I.useMemo)(()=>kO(e,t,x,{resources:f,views:p,fieldTypes:h}),[e,t,x.join(`,`),f,p,h]),C=(0,I.useMemo)(()=>Jm(e,t,S.map(e=>e.id)),[e,t,S]),w=FO({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=Rm(t,o),O=t?.names?.plural??F(e.name),k=u&&(0,B.jsxs)(Eh,{to:Qb(e,t,v,l?{filter:l.filter,orderBy:Qm(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:[Gb(`viewAll`),` `,(0,B.jsx)(`span`,{className:`sr-only`,children:O.toLowerCase()})]}),(0,B.jsx)(Sr,{className:`size-3.5`,"aria-hidden":!0})]});if(w.isPending)return(0,B.jsx)(LO,{});if(w.error)return(0,B.jsx)(pg,{title:Gb(`couldNotLoad`),error:w.error});if(!E||E.total===0){let e=(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:s??Gb(`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=>Zm(e,t)),total:w.data.total,loading:!1,error:null,more:!1,loadMore:()=>void 0},j=PO({model:e,view:t,opens:d,resources:f,views:p,canUpdate:m}),ee=e=>({href:_(e),onFollow:()=>g(e)}),te=Kb(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)(FD,{model:e,view:t,display:D,list:A,row:c||v,footer:!1}):D.kind===`map`?(0,B.jsx)(vO,{model:e,view:t,display:D,filter:n,orderBy:y,fields:C,footer:!1}):D.kind===`board`?(0,B.jsx)(TE,{model:e,view:t,display:D,fields:C,filter:n,orderBy:y,limit:a}):D.kind===`calendar`?(0,B.jsx)(lD,{model:e,view:t,display:D,fields:C,filter:n}):D.kind===`timeline`?(0,B.jsx)(AD,{model:e,view:t,display:D,fields:C,filter:n}):(0,B.jsx)(BD,{display:D,list:A}):(0,B.jsx)(DS,{fit:!0,columns:S,source:E,latencyMs:0,sort:$m(y),onSortChange:e=>b(eh(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]})},zO=(e,t,n)=>{let r=fd(),i=Jb(t),[a,o]=(0,I.useState)(()=>Yb(localStorage,i)),s=(0,I.useCallback)(e=>{o(e),Xb(localStorage,i,e)},[i]);return[Zb(e,r,{picked:a,preferred:n}),s]},BO=({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]=zO(t,`page:${e.name}:${s??``}:${n}`,o);return(0,B.jsx)(dv,{title:s,description:c,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(IO,{view:t,value:d,onChange:f}),u]}),className:`h-full`,children:(0,B.jsx)(RO,{model:e,view:t,filter:n,sort:r,columns:i,limit:a,display:d,empty:l})})},VO=({node:e,slots:t})=>{let n=cv(e),{resources:r,views:i}=W(),a=r[n.resource];return a?(0,B.jsx)(BO,{...n,model:a,view:i[a.name],actions:t.actions}):null},HO=({node:e,children:t})=>{let{tab:n,pathOf:r}=rd(),{navigate:i}=mh(),a=id(e),o=od(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":Y(`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":Y(`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)(Ch,{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)(Zg,{children:Y(`noTab`,n??``)})]})},UO=({children:e})=>(0,B.jsx)(`div`,{className:`flex flex-col gap-6`,children:e}),WO=({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})]}),GO=({message:e})=>e?(0,B.jsx)(`p`,{role:`alert`,className:`mb-3 text-body font-medium text-danger-text`,children:e}):null,KO=M({en:{tooManyRequests:`Too many attempts. Wait a minute and try again.`,passkeyClosed:`The passkey prompt closed before it finished. Try again.`,wrongEmailOrPassword:`The email or password is not right.`,wrongPassword:`The password is not right.`,wrongCode:`The code is not right.`,wrongOrExpiredCode:`The code is not right, or has expired. Ask for a new one.`,codeExpired:`The code has expired. Ask for a new one.`,tooManyCodes:`Too many wrong codes. Ask for a new one.`,wrongBackupCode:`The backup code is not right, or was used before.`,tooManyCodesSignIn:`Too many wrong codes. Sign in again.`,locked:`Too many wrong codes. Wait 15 minutes and try again.`,tooSlow:`This sign-in took too long. Sign in again.`,passkeyNotFound:`This passkey is not registered for an account here.`,passkeyFailed:`The passkey could not be checked. Try again.`,passkeyAdded:`This passkey is added already.`,notFresh:`For this change, sign out and sign in again first.`,staffPermissionMissing:`Your staff account has no permission to sign in as people here.`,staffNotStrong:`Sign in to your staff account with a passkey or a second step, then try again.`,staffStale:`Your staff sign-in is too old. Sign in to your staff account again.`,staffExpired:`This staff sign-in took too long or was used already. Start again.`,staffProviderFailed:`The staff sign-in did not go through at the provider. Try again.`,staffUserUnavailable:`There is no account with this address, or it is disabled.`,staffReasonRequired:`Say why you sign in as this person, in at least 10 characters.`,staffForbidden:`Staff sign-in is turned off for this app.`,untrustedCallback:`This page is not on an address the server trusts.`,staffFailed:`The staff sign-in did not go through. Try again.`,passwordLeaked:`This password appears in a known data breach. Choose a different one.`},nl:{tooManyRequests:`Te veel pogingen. Wacht een minuut en probeer het opnieuw.`,passkeyClosed:`De passkey-vraag sloot voordat die klaar was. Probeer het opnieuw.`,wrongEmailOrPassword:`Het e-mailadres of wachtwoord klopt niet.`,wrongPassword:`Het wachtwoord klopt niet.`,wrongCode:`De code klopt niet.`,wrongOrExpiredCode:`De code klopt niet, of is verlopen. Vraag een nieuwe aan.`,codeExpired:`De code is verlopen. Vraag een nieuwe aan.`,tooManyCodes:`Te veel verkeerde codes. Vraag een nieuwe aan.`,wrongBackupCode:`De back-upcode klopt niet, of is al eerder gebruikt.`,tooManyCodesSignIn:`Te veel verkeerde codes. Log opnieuw in.`,locked:`Te veel verkeerde codes. Wacht 15 minuten en probeer het opnieuw.`,tooSlow:`Deze inlogpoging duurde te lang. Log opnieuw in.`,passkeyNotFound:`Deze passkey hoort hier bij geen enkel account.`,passkeyFailed:`De passkey kon niet worden gecontroleerd. Probeer het opnieuw.`,passkeyAdded:`Deze passkey is al toegevoegd.`,notFresh:`Log voor deze wijziging eerst uit en opnieuw in.`,staffPermissionMissing:`Je medewerkersaccount mag hier niet als iemand anders inloggen.`,staffNotStrong:`Log in op je medewerkersaccount met een passkey of een tweede stap, en probeer het dan opnieuw.`,staffStale:`Je inlog als medewerker is te oud. Log opnieuw in op je medewerkersaccount.`,staffExpired:`Deze inlog als medewerker duurde te lang of is al gebruikt. Begin opnieuw.`,staffProviderFailed:`De inlog als medewerker lukte niet bij de provider. Probeer het opnieuw.`,staffUserUnavailable:`Er is geen account met dit adres, of het is uitgeschakeld.`,staffReasonRequired:`Zeg in minstens 10 tekens waarom je als deze persoon inlogt.`,staffForbidden:`Inloggen als medewerker staat uit voor deze app.`,untrustedCallback:`Deze pagina staat niet op een adres dat de server vertrouwt.`,staffFailed:`De inlog als medewerker lukte niet. Probeer het opnieuw.`,passwordLeaked:`Dit wachtwoord komt voor in een bekend datalek. Kies een ander wachtwoord.`}}),qO=M({en:{signupDisabled:e=>`No account here belongs to this ${e} account. Ask an admin to add you, or sign in another way.`,notLinked:e=>`Your ${e} account is not linked to your account here. Sign in another way, then connect ${e} on your account page.`,linkedToOther:e=>`This ${e} account is linked to someone else here already.`,couldNotLink:e=>`Your ${e} account could not be linked. Try again.`,accessDenied:e=>`${e} did not let you in, or you cancelled.`,domainNotAllowed:e=>`${e} signed you in with an address this app does not accept from it. Sign in another way.`,providerFailed:e=>`Signing in with ${e} did not go through. Try again.`},nl:{signupDisabled:e=>`Geen account hier hoort bij dit ${e}-account. Vraag een beheerder om je toe te voegen, of log op een andere manier in.`,notLinked:e=>`Je ${e}-account is niet gekoppeld aan je account hier. Log op een andere manier in en koppel ${e} dan op je accountpagina.`,linkedToOther:e=>`Dit ${e}-account is hier al aan iemand anders gekoppeld.`,couldNotLink:e=>`Je ${e}-account kon niet worden gekoppeld. Probeer het opnieuw.`,accessDenied:e=>`${e} liet je niet binnen, of je hebt geannuleerd.`,domainNotAllowed:e=>`${e} logde je in met een adres dat deze app daarvan niet accepteert. Log op een andere manier in.`,providerFailed:e=>`Inloggen met ${e} lukte niet. Probeer het opnieuw.`}}),JO={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`},YO=(e,t)=>{let n=t?e[t]:void 0;return n&&KO(n)},XO=e=>YO(JO,e.code),ZO=e=>XO(e)??(e.status===429?KO(`tooManyRequests`):e.message),QO=e=>XO(e)??(e.status===429?KO(`tooManyRequests`):e.status===401?KO(`wrongEmailOrPassword`):e.message),$O={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`},ek=e=>YO($O,typeof e==`string`?e:e.code)||(typeof e==`string`?KO(`staffFailed`):e.status===429?KO(`tooManyRequests`):e.message),tk={signup_disabled:e=>qO(`signupDisabled`,e),account_not_linked:e=>qO(`notLinked`,e),account_already_linked_to_different_user:e=>qO(`linkedToOther`,e),unable_to_link_account:e=>qO(`couldNotLink`,e),access_denied:e=>qO(`accessDenied`,e),EMAIL_DOMAIN_NOT_ALLOWED:e=>qO(`domainNotAllowed`,e)},nk=(e,t)=>tk[e]?.(t)??qO(`providerFailed`,t),rk=()=>{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 yl))throw e;r(ZO(e))}t(!1)},setError:r}},ik=M({en:{email:`Email`,invite:`Invite`,expired:`Expired`,until:e=>`Until ${e}`,sendAgain:`Send again`,revoke:`Revoke`,passLinkOn:`This app cannot send email, so pass this link on yourself. It works once, until the invitation expires: {}`},nl:{email:`E-mailadres`,invite:`Uitnodigen`,expired:`Verlopen`,until:e=>`Tot ${e}`,sendAgain:`Opnieuw sturen`,revoke:`Intrekken`,passLinkOn:`Deze app kan geen e-mail sturen, dus geef deze link zelf door. Die werkt één keer, tot de uitnodiging verloopt: {}`}}),ak=({link:e})=>e?(0,B.jsx)(`p`,{className:`mt-3 break-all rounded-md border bg-muted px-3 py-2 text-xs`,children:Qg(ik(`passLinkOn`),(0,B.jsx)(`span`,{className:`font-mono`,children:e}))}):null,ok=({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}=rk(),p=()=>f(async()=>{l((await n(o.trim())).link),s(``)});return(0,B.jsxs)(WO,{title:e,description:t,children:[(0,B.jsx)(GO,{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)(Xf,{"aria-label":ik(`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:ik(`invite`)})]}),i]}),(0,B.jsx)(ak,{link:c})]})},sk=({email:e,gives:t,expiresAt:n,onResend:r,onRevoke:i})=>{let[a,o]=(0,I.useState)(),{busy:s,error:c,run:l}=rk(),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?ik(`expired`):ik(`until`,new Date(n).toLocaleDateString(Ie()))]})]}),(0,B.jsx)(G,{size:`sm`,loading:s,onClick:()=>void l(async()=>o((await r()).link)),children:ik(`sendAgain`)}),(0,B.jsx)(G,{size:`sm`,variant:`danger`,loading:s,onClick:()=>void l(i),children:ik(`revoke`)})]}),(0,B.jsx)(GO,{message:c}),(0,B.jsx)(ak,{link:a})]})},Z=M({en:{organizations:`Organizations`,manageOrganizations:`Manage organizations`,organization:`Organization`,members:`Members`,invitations:`Invitations`,owner:`Owner`,admin:`Admin`,member:`Member`,loading:`Loading`,name:`Name`,slug:`Slug`,save:`Save`,cancel:`Cancel`,delete:`Delete`,remove:`Remove`,create:`Create`,current:`Current`,open:`Open`,allOrganizations:`All organizations`,allOrganizationsDescription:`Every organization in the app. Your global roles let you work in any of them, with what those roles allow there. Opening one you are not a member of is written to the audit log.`,findOrganization:`Find an organization`,nameOrSlug:`Name or slug`,cannotChangeRole:`You cannot give or take away this role`,makeAccountToJoin:e=>`Make your account for ${e} to join.`,makeAccount:e=>`Make your account for ${e}.`,yourName:`Your name`,password:`Password`,passwordOptional:e=>`Password (optional, ${e}+ characters)`,passwordRequired:e=>`Password (${e}+ characters)`,createAndJoin:`Create account and join`,createYourAccount:`Create your account`,invalidLink:`This invitation link is not valid`,invitation:`Invitation`,goToApp:`Go to the app`,invitesToApp:(e,t)=>`${e} invites you to join ${t}.`,invitesTo:(e,t,n)=>`${e} invites you to ${t} as ${n}.`,invitesToWith:(e,t,n,r)=>`${e} invites you to ${t} as ${n}, with ${r}.`,join:e=>`Join ${e}`,hasAccount:e=>`${e} has an account already: sign in with it.`,signOut:`Sign out`,signInAs:e=>`Sign in as ${e}`,signInAsToJoin:e=>`Sign in as ${e} to join`,otherAddress:(e,t)=>`This invitation is for ${e}, and you are signed in as ${t}.`,signOutToAccept:`Sign out to accept it`,inviteSomeone:`Invite someone`,inviteDescription:`They get an email with a link to join, or to make an account first. You can give the app roles you hold, and those your roles grant.`,organizationRole:`Organization role`,peopleInvited:e=>`People invited to ${e}.`,notAcceptedYet:`Not accepted yet`,sendingAgain:`Sending again gives a new link, which replaces the earlier one.`,nobodyWaiting:`Nobody is waiting.`,roleOf:e=>`Organization role of ${e}`,couldNotReadMembers:`Could not read the members`,whoWorks:e=>`Who works in ${e}, and with which roles.`,membersDescription:`Owners and admins manage the organization; app roles decide what each member sees and does in the app.`,details:`Details`,detailsEditable:`The name people see, and the slug that names it in links.`,detailsReadOnly:`Owners and admins can change these.`,handOver:`Hand over`,handOverDescription:`Make another member the owner. You stay as an admin.`,newOwner:`New owner`,chooseMember:`Choose a member`,deleteOrganization:`Delete organization`,deleteDescription:`Takes the organization and its members and invitations away. Its records must be deleted first.`,deleteTitle:e=>`Delete ${e}?`,deleteConfirm:`Type its name to confirm. This cannot be undone.`,organizationName:`Organization name`,leave:`Leave`,leaveOwner:`An organization keeps an owner: hand it over before you leave, unless it has another owner.`,leaveMember:`You stop being a member, and lose your roles here.`,leaveName:e=>`Leave ${e}`,noOrganization:`You do not work in an organization now. Choose one under Organizations.`,youAre:e=>`You are ${e} here.`,throughGlobalRoles:`You work here through your global roles, without being a member.`,newOrganization:`New organization`,newOrganizationDescription:`You become its owner, with every role, and work in it once it is made.`,invitationsForYou:`Invitations for you`,invitationsForYouDescription:`Accept one to become a member and work there.`,accept:`Accept`,anOrganization:`An organization`,noAppRoles:`no app roles`,until:e=>`Until ${e}`,organizationsSubtitle:`You work in one organization at a time; what you see follows from your roles there.`,yourOrganizations:`Your organizations`,memberOf:`The organizations you are a member of.`,notMember:`You are not a member of an organization yet.`,couldNotReadOrganizations:`Could not read your organizations`},nl:{organizations:`Organisaties`,manageOrganizations:`Organisaties beheren`,organization:`Organisatie`,members:`Leden`,invitations:`Uitnodigingen`,owner:`Eigenaar`,admin:`Beheerder`,member:`Lid`,loading:`Laden`,name:`Naam`,slug:`Slug`,save:`Bewaren`,cancel:`Annuleren`,delete:`Verwijderen`,remove:`Verwijderen`,create:`Maken`,current:`Huidige`,open:`Openen`,allOrganizations:`Alle organisaties`,allOrganizationsDescription:`Elke organisatie in de app. Met je globale rollen kun je in elk ervan werken, met wat die rollen daar toestaan. Wie er een opent waar die geen lid van is, komt in het auditlogboek.`,findOrganization:`Een organisatie zoeken`,nameOrSlug:`Naam of slug`,cannotChangeRole:`Je kunt deze rol niet geven of afnemen`,makeAccountToJoin:e=>`Maak je account voor ${e} om lid te worden.`,makeAccount:e=>`Maak je account voor ${e}.`,yourName:`Je naam`,password:`Wachtwoord`,passwordOptional:e=>`Wachtwoord (optioneel, ${e}+ tekens)`,passwordRequired:e=>`Wachtwoord (${e}+ tekens)`,createAndJoin:`Account maken en lid worden`,createYourAccount:`Je account maken`,invalidLink:`Deze uitnodigingslink is niet geldig`,invitation:`Uitnodiging`,goToApp:`Naar de app`,invitesToApp:(e,t)=>`${e} nodigt je uit voor ${t}.`,invitesTo:(e,t,n)=>`${e} nodigt je uit voor ${t} als ${n}.`,invitesToWith:(e,t,n,r)=>`${e} nodigt je uit voor ${t} als ${n}, met ${r}.`,join:e=>`Lid worden van ${e}`,hasAccount:e=>`${e} heeft al een account: log daarmee in.`,signOut:`Uitloggen`,signInAs:e=>`Inloggen als ${e}`,signInAsToJoin:e=>`Inloggen als ${e} om lid te worden`,otherAddress:(e,t)=>`Deze uitnodiging is voor ${e}, en je bent ingelogd als ${t}.`,signOutToAccept:`Uitloggen om die te accepteren`,inviteSomeone:`Iemand uitnodigen`,inviteDescription:`Die krijgt een e-mail met een link om lid te worden, of om eerst een account te maken. Je kunt de app-rollen geven die je zelf hebt, en die je rollen toekennen.`,organizationRole:`Rol in de organisatie`,peopleInvited:e=>`Mensen uitgenodigd voor ${e}.`,notAcceptedYet:`Nog niet geaccepteerd`,sendingAgain:`Opnieuw sturen geeft een nieuwe link, die de vorige vervangt.`,nobodyWaiting:`Er wacht niemand.`,roleOf:e=>`Rol in de organisatie van ${e}`,couldNotReadMembers:`Kon de leden niet lezen`,whoWorks:e=>`Wie in ${e} werkt, en met welke rollen.`,membersDescription:`Eigenaren en beheerders beheren de organisatie; app-rollen bepalen wat elk lid in de app ziet en doet.`,details:`Gegevens`,detailsEditable:`De naam die mensen zien, en de slug die haar in links noemt.`,detailsReadOnly:`Eigenaren en beheerders kunnen dit wijzigen.`,handOver:`Overdragen`,handOverDescription:`Maak een ander lid eigenaar. Jij blijft beheerder.`,newOwner:`Nieuwe eigenaar`,chooseMember:`Kies een lid`,deleteOrganization:`Organisatie verwijderen`,deleteDescription:`Verwijdert de organisatie met haar leden en uitnodigingen. Haar records moeten eerst worden verwijderd.`,deleteTitle:e=>`${e} verwijderen?`,deleteConfirm:`Typ de naam om te bevestigen. Dit kan niet ongedaan worden gemaakt.`,organizationName:`Naam van de organisatie`,leave:`Verlaten`,leaveOwner:`Een organisatie houdt een eigenaar: draag die rol over voordat je vertrekt, tenzij er nog een eigenaar is.`,leaveMember:`Je bent dan geen lid meer, en verliest je rollen hier.`,leaveName:e=>`${e} verlaten`,noOrganization:`Je werkt nu niet in een organisatie. Kies er een onder Organisaties.`,youAre:e=>`Je bent hier ${e}.`,throughGlobalRoles:`Je werkt hier via je globale rollen, zonder lid te zijn.`,newOrganization:`Nieuwe organisatie`,newOrganizationDescription:`Je wordt de eigenaar, met elke rol, en werkt erin zodra die is gemaakt.`,invitationsForYou:`Uitnodigingen voor jou`,invitationsForYouDescription:`Accepteer er een om lid te worden en daar te werken.`,accept:`Accepteren`,anOrganization:`Een organisatie`,noAppRoles:`geen app-rollen`,until:e=>`Tot ${e}`,organizationsSubtitle:`Je werkt in één organisatie tegelijk; wat je ziet volgt uit je rollen daar.`,yourOrganizations:`Je organisaties`,memberOf:`De organisaties waar je lid van bent.`,notMember:`Je bent nog geen lid van een organisatie.`,couldNotReadOrganizations:`Kon je organisaties niet lezen`}}),ck=({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?Z(`cannotChangeRole`):void 0,className:P(`inline-flex items-center gap-1.5`,o&&`text-muted-foreground`),children:[(0,B.jsx)(Rx,{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)})}),lk=`/-/organizations`,uk=`/-/organization`,dk=`/-/organization/members`,fk=`/-/organization/invitations`,pk={[lk]:`organizations`,[uk]:`organization`,[dk]:`members`,[fk]:`invitations`},mk=e=>{let t=pk[e];return t&&Z(t)},hk=e=>Z(e),gk=(e,t)=>e.find(e=>e.name===t)?.label??t,_k=e=>e?.role===`owner`||e?.role===`admin`,vk=(e,t,n)=>{let r=(n,r,i,a)=>({id:n,label:r,icon:i,href:`${e}${a}`,active:t===a});return[r(`organizations`,Z(`manageOrganizations`),io,lk),...n?.organization?[r(`organization`,Z(`organization`),ei,uk)]:[],..._k(n)?[r(`members`,Z(`members`),ks,dk),r(`invitations`,Z(`invitations`),Wa,fk)]:[]]},yk=(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)))},bk=(e,t)=>t.map(t=>gk(e,t)).join(`, `),xk=M({en:{inviteSomeone:`Invite someone`,inviteDescription:`They get an email with a link to make their account, with the roles you tick.`,notAcceptedYet:`Not accepted yet`,sendingAgain:`Sending again gives a new link, which replaces the earlier one.`,nobodyWaiting:`Nobody is waiting.`,addAnAccount:`Add an account`,addDescription:`Makes the account at once, with the address counted as verified. Without a password, the person signs in another way this app allows, such as an emailed code.`,email:`Email`,name:`Name`,password:`Password`,passwordOptional:e=>`Password (optional, ${e}+ characters)`,addAccount:`Add account`,couldNotReadRoles:`Could not read the roles`,people:`People`,peopleDescription:`Everyone with an account. Roles decide what each sees and does; someone blocked cannot sign in, and is signed out at once.`,findSomeone:`Find someone`,emailAddress:`Email address`,keepOneRole:`Keep at least one role.`,blocked:`Blocked`,unblock:`Unblock`,block:`Block`},nl:{inviteSomeone:`Iemand uitnodigen`,inviteDescription:`Die krijgt een e-mail met een link om een account te maken, met de rollen die je aanvinkt.`,notAcceptedYet:`Nog niet geaccepteerd`,sendingAgain:`Opnieuw sturen geeft een nieuwe link, die de vorige vervangt.`,nobodyWaiting:`Er wacht niemand.`,addAnAccount:`Een account toevoegen`,addDescription:`Maakt het account meteen, met het adres als gecontroleerd. Zonder wachtwoord logt de persoon in op een andere manier die deze app toestaat, zoals een gemailde code.`,email:`E-mailadres`,name:`Naam`,password:`Wachtwoord`,passwordOptional:e=>`Wachtwoord (optioneel, ${e}+ tekens)`,addAccount:`Account toevoegen`,couldNotReadRoles:`Kon de rollen niet lezen`,people:`Mensen`,peopleDescription:`Iedereen met een account. Rollen bepalen wat ieder ziet en doet; wie geblokkeerd is, kan niet inloggen en wordt meteen uitgelogd.`,findSomeone:`Iemand zoeken`,emailAddress:`E-mailadres`,keepOneRole:`Houd minstens één rol.`,blocked:`Geblokkeerd`,unblock:`Deblokkeren`,block:`Blokkeren`}}),Sk=({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)(ok,{title:xk(`inviteSomeone`),description:xk(`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)(ck,{roles:e,selected:n,grantable:new Set(e.map(e=>e.name)),onChange:r})}),(0,B.jsx)(WO,{title:xk(`notAcceptedYet`),description:i.length>0?xk(`sendingAgain`):xk(`nobodyWaiting`),children:i.length>0&&(0,B.jsx)(`ul`,{className:`divide-y rounded-md border`,children:i.map(n=>(0,B.jsx)(sk,{email:n.email,gives:bk(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))})})]})},Ck=({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)(Qy,{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})]})}),wk=({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)(Ck,{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)(Ck,{title:z(`choosePassword`),description:z(`atLeast`,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)(Xf,{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)(Xf,{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`)})]})})},Tk=({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}=rk(),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)(WO,{title:xk(`addAnAccount`),description:xk(`addDescription`),children:[(0,B.jsx)(GO,{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)(Xf,{"aria-label":xk(`email`),type:`email`,placeholder:`name@example.com`,value:r,onChange:e=>i(e.target.value),wrapperClassName:`flex-1`}),(0,B.jsx)(Xf,{"aria-label":xk(`name`),placeholder:xk(`name`),autoComplete:`off`,value:a,onChange:e=>o(e.target.value),wrapperClassName:`flex-1`})]}),(0,B.jsx)(Xf,{"aria-label":xk(`password`),type:`password`,autoComplete:`new-password`,placeholder:xk(`passwordOptional`,12),value:s,onChange:e=>c(e.target.value)}),(0,B.jsx)(ck,{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:xk(`addAccount`)})})]})]})},Ek=M({en:{showMore:`Show more`},nl:{showMore:`Meer tonen`}}),Dk=({title:e,description:t,searchLabel:n,placeholder:r,query:i,onQuery:a,list:o,error:s,renderRow:c})=>(0,B.jsxs)(WO,{title:e,description:t,children:[(0,B.jsx)(GO,{message:s}),(0,B.jsx)(Xf,{"aria-label":n,placeholder:r,value:i,onChange:e=>a(e.target.value),leading:(0,B.jsx)(jo,{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:Ek(`showMore`)})]}),Ok=(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}},kk=({name:e,email:t,self:n,actions:r,children:i,error:a})=>(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:[(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)(GO,{message:a})]}),Ak=({user:e,roles:t,self:n})=>{let{session:r}=V(),[i,a]=(0,I.useState)(e),{busy:o,error:s,run:c,setError:l}=rk(),u=e=>{if(e.length===0)return l(xk(`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)(kk,{name:i.name,email:i.email,self:n,error:s,actions:(0,B.jsxs)(B.Fragment,{children:[i.blocked&&(0,B.jsx)(hp,{tone:`red`,children:xk(`blocked`)}),!n&&(i.blocked?(0,B.jsx)(G,{size:`sm`,loading:o,onClick:()=>d(!1),children:xk(`unblock`)}):(0,B.jsx)(G,{size:`sm`,variant:`danger`,loading:o,onClick:()=>d(!0),children:xk(`block`)}))]}),children:(0,B.jsx)(ck,{roles:t,selected:i.roles,grantable:new Set(t.map(e=>e.name)),disabled:o,onChange:u})})},jk=({roles:e,version:t})=>{let{session:n,state:r}=V(),[i,a]=(0,I.useState)(``),o=Ok((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)(Dk,{title:xk(`people`),description:xk(`peopleDescription`),searchLabel:xk(`findSomeone`),placeholder:xk(`emailAddress`),query:i,onQuery:a,list:o,renderRow:n=>(0,B.jsx)(Ak,{user:n,roles:e,self:n.id===s},`${t}/${n.id}`)})},Mk=()=>{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 yl?ZO(e):xk(`couldNotReadRoles`)))},[e]),{roles:t,error:r}},Nk=()=>{let{roles:e,error:t}=Mk(),[n,r]=(0,I.useState)(0);return(0,B.jsxs)(`div`,{className:`flex max-w-3xl flex-col gap-4`,children:[(0,B.jsx)(GO,{message:t}),(0,B.jsx)(jk,{roles:e,version:n}),(0,B.jsx)(Sk,{roles:e}),(0,B.jsx)(Tk,{roles:e,onCreated:()=>r(e=>e+1)})]})},Pk=({providers:e,linked:t,onConnect:n,error:r})=>{let[i,a]=(0,I.useState)(),[o,s]=(0,I.useState)(r),c=async e=>{a(e),s(void 0);try{await n(e)}catch(e){if(!(e instanceof yl))throw e;s(ZO(e)),a(void 0)}};return(0,B.jsxs)(WO,{title:L(`connectedAccounts`),description:L(`connectedAccountsDescription`),children:[(0,B.jsx)(GO,{message:o}),(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)(Ma,{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)(hp,{tone:`green`,children:L(`connected`)}):(0,B.jsx)(G,{size:`sm`,loading:i===e.id,disabled:i!==void 0,onClick:()=>void c(e.id),children:L(`connect`,e.name)})]},e.id))})]})},Fk=({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)(Yu,{}),` `,L(`loading`)]}),Ik=(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 yl?ZO(e):t))},[e,t]);return(0,I.useEffect)(o,[o]),{data:n?.value,loaded:n!==void 0,error:i,reload:o}},Lk=()=>{let e=yu(window.location.href);return e&&window.history.replaceState(window.history.state,``,bu(window.location.href)),e},Rk=({providers:e})=>{let{session:t,linkProvider:n}=V(),{account:r}=t,[i]=(0,I.useState)(Lk),{data:a,error:o}=Ik((0,I.useCallback)(()=>r.linkedProviders(),[r]),L(`couldNotReadMethods`));return a?(0,B.jsx)(Pk,{providers:e,linked:a,onConnect:n,error:i&&nk(i,e.length===1?e[0].name:L(`theProvider`))}):(0,B.jsx)(Fk,{error:o})},zk=({signInProviders:e,socialProviders:t})=>e.filter(e=>t.includes(e.id)),Bk=()=>{let e=zk(V());return e.length>0?(0,B.jsx)(Rk,{providers:e}):null},Vk=/[\u0000-\u001f\u007f-\u009f\u00ad\u061c\u115f\u1160\u180e\u200b-\u200f\u2028-\u202e\u2060-\u206f\u3164\ufe00-\ufe0f\ufeff]/g,Hk=e=>{let t=(e??``).replace(Vk,` `).replace(/\s+/g,` `).trim();if(t)return t.length>60?`${t.slice(0,59)}…`:t},Uk=e=>{if(!URL.canParse(e))return;let t=new URL(e);return t.protocol===`https:`?t.host:void 0},Wk=e=>Hk(e.name)??`An unnamed app`,Gk=e=>e.access.map(({role:e,organization:t})=>`as ${e||`no role`}${t?` in ${t}`:``}`).join(`, `),Kk=({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 yl))throw e;a(ZO(e))}r(!1)};return(0,B.jsxs)(WO,{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)(GO,{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=Uk(e.clientId);return(0,B.jsxs)(`li`,{className:`flex flex-wrap items-center gap-3 px-3 py-2.5`,children:[(0,B.jsx)(Xr,{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:Wk(e)}),(0,B.jsxs)(`span`,{className:`block text-xs text-muted-foreground`,children:[t&&`Published by ${t} · `,`Allowed `,lf(Date.parse(e.allowedAt)),` · `,Gk(e)]})]}),(0,B.jsx)(G,{size:`sm`,variant:`ghost`,onClick:()=>s(e),children:`Disconnect`})]},e.clientId)})}),o&&(0,B.jsx)(vd,{title:`Disconnect ${Wk(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)(GO,{message:i})})]})},qk=(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},Jk=({url:e,appName:t})=>{let[n,r]=(0,I.useState)(!1);return(0,B.jsx)(WO,{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)(ui,{className:`size-4 text-success`}):(0,B.jsx)(Mi,{className:`size-4`})})]}),(0,B.jsxs)(`a`,{href:qk(e,t),target:`_blank`,rel:`noreferrer`,className:ld(),children:[(0,B.jsx)(Ji,{className:`size-3.5`}),L(`addToClaude`)]})]})})},Yk=()=>{let{account:e}=V().session,{data:t,error:n,reload:r}=Ik((0,I.useCallback)(()=>e.connectedApps(),[e]),L(`couldNotReadMethods`));return t?(0,B.jsx)(Kk,{apps:t,onDisconnect:t=>e.disconnectApp(t).then(r)}):(0,B.jsx)(Fk,{error:n})},Xk=({url:e})=>(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(Jk,{url:e,appName:W().appName}),(0,B.jsx)(Yk,{})]}),Zk=()=>{let{mcp:e}=V();return e?(0,B.jsx)(Xk,{url:e.url}):null},Qk=e=>e.code===`LAST_ADMIN`?L(`deleteAccountLastAdmin`):e.code===`ACCOUNT_LOCKED`?L(`deleteAccountLocked`):ZO(e),$k=({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 yl))throw e;c(Qk(e)),o(!1)}};return(0,B.jsx)(vd,{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)(Xf,{type:`password`,name:`current-password`,autoComplete:`current-password`,autoFocus:!0,value:r,invalid:!!s,onChange:e=>i(e.target.value)})]}),(0,B.jsx)(GO,{message:s})]})})},eA=({hasPassword:e,staff:t,onDelete:n})=>{let[r,i]=(0,I.useState)(!1);return(0,B.jsxs)(WO,{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)($k,{hasPassword:e,onDelete:n,onClose:()=>i(!1)})]})},tA=()=>{let{session:e,state:t,deleteAccount:n}=V(),{account:r}=e,{data:i,error:a}=Ik((0,I.useCallback)(()=>r.signInMethods(),[r]),L(`couldNotReadMethods`));return i?(0,B.jsx)(eA,{hasPassword:i.account.password,staff:t.kind===`signed-in`&&!!t.staff,onDelete:n}):(0,B.jsx)(Fk,{error:a})},nA=[[/Edg(e|A|iOS)?\//,`Edge`],[/OPR\/|Opera/,`Opera`],[/SamsungBrowser\//,`Samsung Internet`],[/Firefox\/|FxiOS\//,`Firefox`],[/Chrome\/|CriOS\//,`Chrome`],[/Safari\//,`Safari`]],rA=[[/iPhone/,`iPhone`],[/iPad/,`iPad`],[/Android/,`Android`],[/CrOS/,`ChromeOS`],[/Windows/,`Windows`],[/Mac OS X|Macintosh/,`macOS`],[/Linux/,`Linux`]],iA=(e,t)=>e.find(([e])=>e.test(t))?.[1],aA=e=>e?{browser:iA(nA,e),system:iA(rA,e)}:{},oA=(e,t)=>{if(e.staff)return t?L(`staffOf`,t):L(`staff`);let{browser:n,system:r}=aA(e.userAgent);return n&&r?L(`browserOn`,n,r):r?L(`aBrowserOn`,r):n??L(`unknownDevice`)},sA=e=>{if(e.staff)return Uo;let{system:t}=aA(e.userAgent);return t===`iPhone`||t===`Android`?Yo:t===`iPad`?ls:Sa},cA=e=>[...e].sort((e,t)=>Number(t.current)-Number(e.current)||t.createdAt.localeCompare(e.createdAt)),lA=({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 yl))throw e;s(ZO(e))}a(!1)},f=e=>{s(void 0),l(e)};return(0,B.jsxs)(WO,{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:cA(e).map(e=>{let n=sA(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:oA(e,t)}),e.current&&(0,B.jsx)(hp,{tone:`green`,children:L(`thisDevice`)})]}),(0,B.jsxs)(`span`,{className:`block text-xs text-muted-foreground`,children:[L(`signedInFromUntil`,ff(Date.parse(e.createdAt)),ff(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)(vd,{title:c.kind===`one`?L(`signOutDevice`,oA(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)(GO,{message:o})})]})},uA=()=>{let{session:e,staffSignIn:t}=V(),{account:n}=e,{data:r,error:i,reload:a}=Ik((0,I.useCallback)(()=>n.sessions(),[n]),L(`couldNotReadDevices`));return r?(0,B.jsx)(lA,{sessions:r,operator:t,onSignOut:e=>n.revokeSession(e).then(a),onSignOutOthers:()=>n.revokeOtherSessions().then(a)}):(0,B.jsx)(Fk,{error:i})},dA={allowed:`passkeysAllowed`,required:`passkeysRequired`,forbidden:`passkeysForbidden`},fA=({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 yl))throw e;c(ZO(e))}o(!1)};return(0,B.jsxs)(WO,{title:L(`passkeys`),status:e===`required`&&(0,B.jsx)(hp,{tone:`blue`,children:L(`required`)}),description:L(dA[e]),children:[(0,B.jsx)(GO,{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)(va,{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`,lf(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)(_o,{className:`size-3.5`}),L(`addPasskey`)]}),l?.kind===`rename`&&(0,B.jsxs)(vd,{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)(Xf,{autoFocus:!0,value:d,maxLength:60,onChange:e=>f(e.target.value)})]}),(0,B.jsx)(GO,{message:s})]}),l?.kind===`remove`&&(0,B.jsx)(vd,{title:L(`removePasskey`),description:L(`removePasskeyDescription`,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)(GO,{message:s})})]})},pA=()=>{let{account:e}=V().session,{data:t,error:n,reload:r}=Ik((0,I.useCallback)(()=>Promise.all([e.signInMethods(),e.passkeys()]),[e]),L(`couldNotReadMethods`));if(!t)return(0,B.jsx)(Fk,{error:n});let[i,a]=t;return(0,B.jsx)(fA,{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)})},mA=e=>e.code===`PASSWORD_TOO_SHORT`?L(`useAtLeast`,12):e.code===`PASSWORD_TOO_LONG`?L(`passwordTooLong`):ZO(e),hA=(e,t)=>{if(e.length<12)return L(`useAtLeast`,12);if(e!==t)return L(`passwordsDiffer`)},gA=({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)(!1),[p,m]=(0,I.useState)(),h=(0,I.useId)(),g=(!e||r)&&a&&s,_=async()=>{let e=hA(a,s);if(m(e),!e){f(!0);try{await t({current:r,next:a,signOutOthers:l})}catch(e){if(!(e instanceof yl))throw e;m(mA(e)),f(!1)}}};return(0,B.jsx)(vd,{title:L(e?`changePassword`:`setPassword`),description:L(`atLeast`,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:h,loading:d,disabled:!g,children:L(`save`)})]}),children:(0,B.jsxs)(`form`,{id:h,className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),_()},children:[e&&(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[L(`currentPassword`),(0,B.jsx)(Xf,{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)(Xf,{type:`password`,name:`new-password`,autoComplete:`new-password`,autoFocus:!e,value:a,invalid:!!p,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)(Xf,{type:`password`,name:`repeat-password`,autoComplete:`new-password`,value:s,invalid:!!p,onChange:e=>c(e.target.value)})]}),e&&(0,B.jsxs)(`label`,{className:`flex items-center gap-2 text-muted-foreground`,children:[(0,B.jsx)(Rx,{checked:l,onChange:u,label:L(`signOutOthers`)}),L(`signOutOthers`)]}),(0,B.jsx)(GO,{message:p})]})})},_A=({rule:e,hasPassword:t,staff:n})=>L(n?`passwordStaff`:e===`forbidden`?`passwordForbidden`:t?`passwordIsSet`:`passwordNotSet`),vA=({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)(WO,{title:L(`password`),description:_A({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)(gA,{hasPassword:t,onClose:()=>o(!1),onSave:async({current:e,next:n,signOutOthers:a})=>{await(t?r(e,n,a):i(n)),o(!1),c(!0)}})]})},yA=()=>{let{session:e,state:t}=V(),{account:n}=e,{data:r,error:i,reload:a}=Ik((0,I.useCallback)(()=>n.signInMethods(),[n]),L(`couldNotReadMethods`));return r?(0,B.jsx)(vA,{rule:r.policy.password,hasPassword:r.account.password,staff:t.kind===`signed-in`&&!!t.staff,onChange:(e,t,r)=>n.changePassword(e,t,r).then(a),onSet:e=>n.setPassword(e).then(a)}):(0,B.jsx)(Fk,{error:i})},bA=({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 yl))throw e;p(ZO(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)(vd,{title:L(`changeEmail`),description:L(`codeSentTo`,o),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)(Dg,{name:`code`,required:!0,autoFocus:!0,value:c,invalid:!!f,onChange:l,onComplete:e=>!u&&void _(e)})]}),(0,B.jsx)(GO,{message:f})]}):(0,B.jsxs)(vd,{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)(Xf,{type:`email`,autoComplete:`email`,autoFocus:!0,value:i,onChange:e=>a(e.target.value)})]}),(0,B.jsx)(GO,{message:f})]})},xA=({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 yl))throw e;m(ZO(e))}f(!1)};return(0,B.jsxs)(WO,{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)(vd,{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)(Xf,{autoFocus:!0,value:l,maxLength:100,onChange:e=>u(e.target.value)})]}),(0,B.jsx)(GO,{message:p})]}),s&&r&&(0,B.jsx)(bA,{email:t,change:r,onClose:()=>c(!1),onDone:()=>{c(!1),i?.()}})]})},SA=()=>{let{session:e,changeEmail:t}=V(),{data:n,loaded:r,error:i,reload:a}=Ik((0,I.useCallback)(()=>e.session(),[e]),L(`couldNotReadProfile`));if(!r)return(0,B.jsx)(Fk,{error:i});if(!n)return null;let o=t?{request:e.account.requestEmailChange,confirm:e.account.changeEmail}:void 0;return(0,B.jsx)(xA,{name:n.name,email:n.email,onRename:t=>e.account.updateName(t).then(a),emailChange:o,onEmailChanged:a})},CA=(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)},wA=({codes:e})=>{let[t,n]=(0,I.useState)(!1),r=`${e.join(`
|
|
5
|
-
`)}\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)(ui,{className:`size-3.5 text-success`}):(0,B.jsx)(Mi,{className:`size-3.5`}),L(t?`copied`:`copy`)]}),(0,B.jsxs)(G,{size:`sm`,onClick:()=>CA(r,`backup-codes.txt`),children:[(0,B.jsx)(Bi,{className:`size-3.5`}),L(`download`)]})]})]})},TA=({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 yl))throw e;f(ZO(e)),u(!1)}};return(0,B.jsxs)(vd,{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)(Xf,{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})]})},EA=({uri:e,className:t})=>{let{size:n,path:r}=(0,I.useMemo)(()=>{let t=xe(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`})]})},DA=e=>(new URL(e).searchParams.get(`secret`)??``).replace(/(.{4})(?=.)/g,`$1 `),OA=()=>[{value:`app`,label:L(`authenticatorApp`),description:L(`authenticatorAppDescription`)},{value:`email`,label:L(`emailedCode`),description:L(`emailedCodeDescription`)}],kA=({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?OA():OA().filter(e=>e.value===`app`),b=async e=>{g(!0),v(void 0);try{await e()}catch(e){if(!(e instanceof yl))throw e;v(ZO(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)(wA,{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)(EA,{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:DA(s.setup.totpURI)})]})]}),(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[L(`codeFromApp`),(0,B.jsx)(Dg,{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)(Xf,{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`)})]})},AA={allowed:`twoFactorAllowed`,required:`twoFactorRequired`,forbidden:`twoFactorForbidden`},jA=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)(hp,{tone:`green`,children:L(`on`)}):t===`required`?(0,B.jsx)(hp,{tone:`amber`,children:L(`required`)}):(0,B.jsx)(hp,{children:L(`off`)}),p=L(n?r?i?`twoFactorOnWithAppOrMail`:`twoFactorOnWithApp`:`twoFactorOnWithMail`:AA[t]);return l?.kind===`setup`?(0,B.jsx)(WO,{title:L(`twoFactor`),status:f,description:p,children:(0,B.jsx)(`div`,{className:`max-w-sm`,children:(0,B.jsx)(kA,{offerEmailedCodes:i&&!l.appOnly,needsPassword:a,onStartApp:e.onStartApp,onConfirmApp:e.onConfirmApp,onEmailedCodes:e.onEmailedCodes,onCancel:d,onDone:()=>{d(),c()}})})}):(0,B.jsxs)(WO,{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)(TA,{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)(TA,{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)(vd,{title:L(`yourNewCodes`),description:L(`keepCodesSafe`),onClose:d,actions:(0,B.jsx)(G,{variant:`primary`,onClick:d,children:L(`savedCodes`)}),children:(0,B.jsx)(wA,{codes:l.codes})})]})},MA={Page:Lb,Grid:Sy,Card:pv,Stat:VT,RecordCard:Vb,Field:_y,Table:VO,CardRow:hv,RecordRow:jT,RecordCards:ox,Chart:ey,Progress:zb,ModalForm:zy,Action:uv,Show:LT,Link:wy,Settings:FT,Tabs:HO,Tab:UO,Users:Nk,Profile:SA,Password:yA,Passkeys:pA,TwoFactor:()=>{let{account:e}=V().session,{data:t,error:n,reload:r}=Ik((0,I.useCallback)(()=>e.signInMethods(),[e]),L(`couldNotReadMethods`));return t?(0,B.jsx)(jA,{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)(Fk,{error:n})},ConnectedAccounts:Bk,Devices:uA,ConnectedApps:Zk,DeleteAccount:tA},NA=e=>typeof e==`string`||!e.custom&&e.type===`Link`,PA=e=>{let t=[];for(let n of e){let e=t.at(-1);NA(n)&&e&&NA(e[0])?e.push(n):t.push([n])}return t.map((e,t)=>{let[n]=e;return NA(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)(LA,{node:e},t))},t):(0,B.jsx)(LA,{node:n},t)})},FA=e=>Qc(e)||Array.isArray(e)&&e.length>0&&e.every(Qc),IA=e=>Object.fromEntries(Object.entries(e.props).flatMap(([e,t])=>FA(t)?[[e,(0,B.jsx)(B.Fragment,{children:PA(Array.isArray(t)?t:[t])})]]:[])),LA=({node:e})=>{let{components:t}=Wg();if(e.custom){let n=t?.[e.type];return n?(0,B.jsx)($g,{name:e.type,children:(0,B.jsx)(n,{..._n(e.props),children:e.children.length>0?PA(e.children):void 0})}):(0,B.jsx)(Zg,{children:Qg(Y(`noComponent`),e.type)})}let n=MA[e.type];return n?(0,B.jsx)(n,{node:e,slots:IA(e),children:PA(e.children)}):(0,B.jsx)(Zg,{children:Qg(Y(`unknownBlock`),e.type)})},RA=(e,t)=>{let n=al(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},zA=()=>{let{account:e}=W(),t=V(),{mcp:n,accountDeletion:r}=t,i=zk(t).length>0;return(0,I.useMemo)(()=>{if(!e)return;let t=new Set([...n?[]:[`ConnectedApps`],...i?[]:[`ConnectedAccounts`],...r?[]:[`DeleteAccount`]]);return{...e,tree:RA(e.tree,t)}},[e,n,i,r])},BA=({tab:e})=>{let t=zA();return t?(0,B.jsx)(nd,{route:{...e&&{tab:e},pathOf:Ws},children:(0,B.jsx)(LA,{node:t.tree})}):(0,B.jsx)(Zu,{title:L(`noAccount`),children:L(`noAccountDescription`)})},VA=({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?[eg(`title`,i)]:[],...s];let c=a??(o?void 0:e.key);return[...c?[c]:[],...s]},HA=(e,t)=>[...e.filter(Boolean),t].join(` · `),UA=e=>{(0,I.useEffect)(()=>{let t=document.title;return document.title=e,()=>{document.title=t}},[e])},WA=500,GA=(e=window)=>e.top!==e.self,KA=(e,t,n)=>{let r=!1,i,a=e=>{r!==e&&(r=e,n(e))},o=()=>{clearTimeout(i),a(!1)},s=()=>{o(),e.visibilityState===`visible`&&e.hasFocus()&&(i=setTimeout(()=>a(!0),t))},c=()=>e.visibilityState===`visible`?s():o();return e.defaultView?.addEventListener(`focus`,s),e.defaultView?.addEventListener(`blur`,o),e.addEventListener(`visibilitychange`,c),s(),()=>{clearTimeout(i),e.defaultView?.removeEventListener(`focus`,s),e.defaultView?.removeEventListener(`blur`,o),e.removeEventListener(`visibilitychange`,c)}},qA=()=>{let e=!1;return{down:(t,n=!1)=>{e=t&&!n},take:()=>{let t=e;return e=!1,t}}},JA=e=>{let[t,n]=(0,I.useState)(!1);return(0,I.useEffect)(()=>KA(document,e,n),[e]),t},YA=(e,t)=>{let n=(0,I.useRef)(qA());return{onPointerDown:()=>n.current.down(e),onKeyDown:t=>n.current.down(e,t.repeat),onClick:()=>{n.current.take()&&t()}}},XA=[`localhost`,`127.0.0.1`,`[::1]`],ZA=[`javascript:`,`data:`,`vbscript:`,`file:`,`blob:`,`about:`],QA=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 XA.includes(t.hostname)?{kind:`this-computer`,port:t.port||`80`}:void 0;if(!ZA.includes(t.protocol))return{kind:`device-app`,uri:e.split(`?`)[0].split(`#`)[0]}},$A=e=>!URL.canParse(e,`http://local`)||!ZA.includes(new URL(e,`http://local`).protocol),ej=(e,t)=>{let n=new URL(e,t.origin);if(n.origin===t.origin&&n.pathname===t.pathname)return uc(n.search).oauthQuery},tj=()=>{let{params:e}=mh();return(0,I.useMemo)(()=>uc(e.toString()),[e])},nj={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.`},rj=e=>{if(!(e instanceof yl))throw e;return(e.code&&nj[e.code])??ZO(e)},ij=e=>t=>{if(!$A(t))throw new yl(`The app asked to be sent somewhere this page will not go.`,400);e(t)},aj=({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})]}),oj=({title:e,icon:t,children:n})=>(0,B.jsx)(Ck,{title:e,icon:t,children:(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:n})}),sj=({asking:e,appName:t,appIcon:n,email:r,onAnswer:i,onSignOut:a})=>{let[o,s]=(0,I.useState)(!1),c=JA(500),l=e=>{s(!0),i(e).finally(()=>s(!1))},u=YA(c&&!o,()=>l(!0)),d=Hk(e.client.client_name),f=Uk(e.client.client_id),{target:p}=e;return(0,B.jsx)(Ck,{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)(aj,{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`})]})]})})},cj=({oauthQuery:e,appName:t,appIcon:n,email:r,assign:i})=>{let{session:a,signOut:o}=V(),{path:s,basePath:c}=mh(),l=ij(i),u=e=>ej(e,{origin:window.location.origin,pathname:`${c}${s}`}),[d,f]=(0,I.useState)({kind:`loading`}),p=e=>f({kind:`failed`,message:rj(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:QA(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)(oj,{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)(Yu,{}),` Loading`]}):(0,B.jsx)(sj,{asking:d.asking,appName:t,appIcon:n,email:r,onAnswer:e=>m(e,d.asking),onSignOut:()=>void o()})},lj=({email:e,appName:t,appIcon:n,isFramed:r=GA,assign:i=e=>window.location.assign(e)})=>{let[a]=(0,I.useState)(r),{oauthQuery:o}=tj();return a?(0,B.jsxs)(oj,{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)(cj,{oauthQuery:o,appName:t,appIcon:n,email:e,assign:i},o):(0,B.jsx)(oj,{title:`Nothing to connect`,icon:n,children:`Connect again from your app.`})},uj={title:`Sign in to connect an app`,description:`An app asks to act as you here. Sign in, then choose whether to allow it.`},dj=()=>{let e=W(),{state:t}=V();return UA(HA([`Connect an app`],e.appName)),t.kind===`signed-in`?(0,B.jsx)(lj,{email:t.user.email,appName:e.appName??`this app`,appIcon:e.appIcon}):(0,B.jsx)(Ck,{title:uj.title,description:uj.description,icon:e.appIcon,children:(0,B.jsx)(`div`,{className:`flex flex-col gap-2 [&>*]:min-h-10 [&>*]:w-full`,children:(0,B.jsx)(gw,{prompt:uj})})})},fj=()=>[{value:`allowed`,label:L(`on`)},{value:`forbidden`,label:L(`off`)}],pj=()=>[{value:`allowed`,label:L(`optional`)},{value:`required`,label:L(`required`)},{value:`forbidden`,label:L(`off`)}],mj=()=>[{method:`password`,label:L(`password`),description:L(`passwordDescription`),rules:fj()},{method:`emailCode`,label:L(`emailedSignInCode`),description:L(`emailedSignInCodeDescription`),rules:fj()},{method:`passkey`,label:L(`passkeys`),description:L(`passkeysPolicyDescription`),rules:pj()},{method:`twoFactor`,label:L(`twoFactor`),description:L(`twoFactorPolicyDescription`),rules:pj()},{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:fj()}],hj=(e,t)=>{let n=mj().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},gj=({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))}),_j=({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`,hj(e,r[e]))},vj=({operator:e,platformSignIn:t})=>mj().flatMap(n=>n.method===`staffAccess`&&!e?[]:n.method===`platformSignIn`?t?[{...n,label:L(`platformSignInWith`,t)}]:[]:[n]),yj=({state:e,onSave:t,busy:n,error:r,notice:i})=>{let[a,o]=(0,I.useState)(e.policy),s=vj(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=_j(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)(gj,{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`,e.savedBy,ff(Date.parse(e.savedAt))):L(`lastSaved`,ff(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`)})]})]})]})},bj=(e,t)=>e.endedAt?(0,B.jsx)(hp,{tone:`neutral`,children:L(`stopped`,ff(Date.parse(e.endedAt)))}):Date.parse(e.expiresAt)<=t?(0,B.jsx)(hp,{tone:`neutral`,children:L(`ended`,ff(Date.parse(e.expiresAt)))}):(0,B.jsx)(hp,{tone:`amber`,children:L(`signedInUntil`,ff(Date.parse(e.expiresAt)))}),xj=({signIns:e,operator:t,error:n,now:r=Date.now()})=>(0,B.jsxs)(WO,{title:L(`staffSignIns`),description:L(`staffSignInsDescription`,t),children:[(0,B.jsx)(GO,{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:ff(Date.parse(e.startedAt))}),bj(e,r)]})]},e.id))})]}),Sj=({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 yl?ZO(e):L(`couldNotReadStaffSignIns`)))},[t]),(0,B.jsx)(xj,{operator:e,signIns:n,error:i})},Cj=()=>{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 yl?ZO(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 yl))throw e;o(ZO(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)(Fb,{title:L(`signInPolicy`),subtitle:L(`policySubtitle`)}),t?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(yj,{state:t,busy:r,error:a,notice:s,onSave:e=>void l(e)},t.savedAt??`default`),t.operator&&(0,B.jsx)(Sj,{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)(Yu,{}),` `,L(`loading`)]})]})},wj=({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`,s):z(`sendNewCode`)})},Tj=({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)(Ck,{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)(Dg,{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)(wj,{onResend:a,disabled:c,cooldown:d})]})]})]})},Ej=({email:e,onBack:t,...n})=>(0,B.jsx)(Tj,{title:z(`checkEmail`),description:z(`signInCodeDescription`),explanation:(0,B.jsx)(B.Fragment,{children:Qg(z(`signInCodeSent`),(0,B.jsx)(`span`,{className:`font-medium text-foreground`,children:e}))}),submitLabel:z(`signIn`),onChangeAddress:t,changeAddressLabel:z(`backToSignIn`),...n}),Dj=({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 yl))throw e;s(ZO(e))}a(!1)};return(0,B.jsx)(Ej,{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`))})})},Oj=`protobase users create you@example.com`,kj=({command:e=Oj,onCheckAgain:t,busy:n})=>{let[r,i]=(0,I.useState)(!1);return(0,B.jsxs)(Ck,{title:z(`noAdminTitle`),description:z(`noAdminDescription`),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(()=>{i(!0),setTimeout(()=>i(!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:r?(0,B.jsx)(ui,{className:`size-4 text-success`}):(0,B.jsx)(Mi,{className:`size-4`})})]}),(0,B.jsx)(G,{variant:`primary`,className:`mt-4 min-h-10 w-full`,loading:n,onClick:t,children:z(`reload`)})]})},Aj=({onSubmit:e,back:t,busy:n,error:r,sentTo:i})=>{let[a,o]=(0,I.useState)(``);return i?(0,B.jsxs)(Ck,{title:z(`checkEmail`),children:[(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:Qg(z(`resetSent`),(0,B.jsx)(`span`,{className:`font-medium text-foreground`,children:i}))}),(0,B.jsx)(ah,{to:t,className:P(ld({variant:`primary`}),`mt-4 min-h-10 w-full`),children:z(`backToSignIn`)})]}):(0,B.jsx)(Ck,{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)(Xf,{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)(ah,{to:t,className:P(ld({variant:`ghost`}),`min-h-10`),children:z(`backToSignIn`)})]})})},jj=`password-reset`,Mj=e=>{let t=new URL(e);return`${t.origin}${t.pathname}?${jj}`},Nj=e=>{let t=new URL(e).searchParams;if(t.has(`password-reset`))return{token:t.get(`token`)||void 0}},Pj=e=>{let t=new URL(e);for(let e of[jj,`token`,`error`])t.searchParams.delete(e);return`${t.pathname}${t.search}${t.hash}`},Fj=({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,Mj(window.location.href)),s(e)}catch(e){if(!(e instanceof yl))throw e;a(e.status===429?z(`tooManyRequests`):e.message)}r(!1)};return(0,B.jsx)(Aj,{busy:n,error:i,sentTo:o,back:e,onSubmit:e=>void c(e)})},Ij=({name:e,workspace:t})=>(0,B.jsx)(Ck,{title:z(`signingInWith`,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)(Yu,{}),` `,z(`takingYouTo`,e)]})}),Lj=({provider:e,workspace:t,onFailed:n})=>{let{signInProviders:r,signInSocial:i}=V(),a=r.find(t=>t.id===e),o=a?.name??Su(e),s=(0,I.useRef)(!1);return(0,I.useEffect)(()=>{if(!s.current){if(s.current=!0,!a)return n(z(`providerNotOffered`,o));i(e).catch(e=>{if(!(e instanceof yl))throw e;n(QO(e))})}},[a,o,e,i,n]),(0,B.jsx)(Ij,{name:o,workspace:t})},Rj=e=>e.status===429?z(`tooManyAttempts`):e.code===`PASSWORD_TOO_SHORT`?z(`useAtLeast`,12):e.code===`PASSWORD_TOO_LONG`?z(`passwordTooLong`):ZO(e),zj=({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 yl))throw e;e.code===`INVALID_TOKEN`?u(!0):c(Rj(e)),o(!1)}};return(0,B.jsx)(wk,{busy:a,error:s,invalidLink:l,onRequestNewLink:n,onBack:r,onSubmit:e=>void d(e)})},Bj=e=>z(e===`twoFactor`?`turnOnTwoFactor`:`addPasskey`),Vj=({step:e,twoFactor:t,onAddPasskey:n,busy:r,error:i,onSignOut:a})=>(0,B.jsxs)(Ck,{title:Bj(e),description:z(`requiredForEveryAccount`),children:[e===`twoFactor`?(0,B.jsx)(kA,{...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)(va,{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`)})]}),Hj=({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 yl?ZO(e):z(`couldNotReadAccount`)))},[t]);let u=async()=>{s(!0),l(void 0);try{await t.account.addPasskey(),n()}catch(e){if(!(e instanceof yl))throw e;l(ZO(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)(Yu,{}),` `,z(`loading`)]}):(0,B.jsx)(Vj,{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}})},Uj=({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`})}),Wj=({id:e,className:t})=>e===`github`?(0,B.jsx)(Uj,{className:t}):null,Gj=()=>(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`})]}),Kj=({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)(Ck,{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)(Wj,{id:e.id}),z(`continueWith`,e.name)]},e.id)),w&&(0,B.jsxs)(G,{onClick:()=>c?.(),disabled:t,className:`min-h-10 w-full`,children:[(0,B.jsx)(va,{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`,e)},e))]}),S||C?(0,B.jsx)(Gj,{}):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)(Xf,{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)(Xf,{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)(Wa,{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)(ah,{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)(ah,{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`)})]})},qj=({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 yl))throw e;v(t(e)),g(!1)}};return(0,B.jsx)(Kj,{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),QO),passkeyDomains:f,onPasskey:e=>void y(()=>m(e),ZO),onSendCode:e=>void y(async()=>{await p(e),a(e)},ZO),onSubmit:(e,t)=>void y(()=>s(e,t),QO)})},Jj=({email:e,onBack:t,...n})=>(0,B.jsx)(Tj,{title:z(`checkEmail`),description:z(`signUpCodeDescription`),explanation:(0,B.jsx)(B.Fragment,{children:Qg(z(`signUpCodeSent`),(0,B.jsx)(`span`,{className:`font-medium text-foreground`,children:e}))}),submitLabel:z(`continue`),onChangeAddress:t,changeAddressLabel:z(`useAnotherAddress`),...n}),Yj=({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)(Ck,{title:z(`detailsTitle`),description:z(`detailsDescription`),children:[(0,B.jsx)(`p`,{className:`mb-4 text-muted-foreground`,children:Qg(z(`codeWasRight`),(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)(Xf,{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)(Xf,{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`,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`)})]})]})},Xj=({onSubmit:e,onSignIn:t,onBrowse:n,busy:r,error:i,workspace:a})=>{let[o,s]=(0,I.useState)(``);return(0,B.jsxs)(Ck,{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)(Xf,{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)(Wa,{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`)})]})},Zj=({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 yl))throw e;h(ZO(e))}p(!1)};return t===void 0?(0,B.jsx)(Xj,{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)(Jj,{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)(Yj,{email:t,methods:c,busy:f,error:m,onBack:a,onSubmit:e=>void v(()=>d({ticket:n,...e}))})},Qj=`staff-sign-in`,$j=`staff-error`,eM=e=>{let t=new URL(e).searchParams,n=t.get($j);if(!t.has(`staff-sign-in`)&&!n)return;let r=t.has(Qj);return{email:r&&t.get(`email`)||``,reason:r&&t.get(`reason`)||``,...n&&{error:n}}},tM=e=>{let t=new URL(e);if(t.searchParams.has(`staff-sign-in`))for(let e of[Qj,`email`,`reason`])t.searchParams.delete(e);return t.searchParams.delete($j),`${t.pathname}${t.search}${t.hash}`},nM=10,rM=({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)(Ck,{title:z(`signInAsPerson`),description:z(`forStaffOf`,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)(Xf,{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:nM,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`,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`,e)}),(0,B.jsx)(G,{variant:`ghost`,onClick:i,className:`min-h-10`,children:z(`backToSignIn`)})]})}):(0,B.jsxs)(Ck,{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`)})]})},iM=({link:e,onBack:t})=>{let{session:n,staffSignIn:r}=V(),[i,a]=(0,I.useState)(!1),[o,s]=(0,I.useState)(e.error&&ek(e.error)),c=async(e,t)=>{a(!0),s(void 0);try{let r=`${window.location.origin}${tM(window.location.href)}`;window.location.assign(await n.staff.start({email:e,reason:t,callbackURL:r}))}catch(e){if(!(e instanceof yl))throw e;s(ek(e)),a(!1)}};return(0,B.jsx)(rM,{operator:r,email:e.email,reason:e.reason,busy:i,error:o,onBack:t,onSubmit:(e,t)=>void c(e,t)})},aM={totp:`totpInstruction`,otp:`otpInstruction`,backup:`backupInstruction`},oM=({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)(Ck,{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(aM[c])}),(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[z(c===`backup`?`backupCode`:`code`),c===`backup`?(0,B.jsx)(Xf,{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)(Dg,{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)(Rx,{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`)})]})]})},sM=({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 yl))throw e;s(ZO(e))}a(!1)};return(0,B.jsx)(oM,{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)})})},cM=e=>{let t=new URL(e),n=t.searchParams.get(`token`);return t.pathname.endsWith(`/-/invitation`)&&n?{token:n}:void 0},lM=e=>`${new URL(e).pathname.slice(0,-13)}/`,uM=({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}=rk(),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:Z(n?`makeAccountToJoin`:`makeAccount`,t.email)}),f&&(0,B.jsx)(`p`,{role:`alert`,className:`text-body font-medium text-danger-text`,children:f}),(0,B.jsx)(Xf,{"aria-label":Z(`yourName`),placeholder:Z(`yourName`),autoComplete:`name`,value:s,onChange:e=>c(e.target.value)}),m&&(0,B.jsx)(Xf,{"aria-label":Z(`password`),type:`password`,autoComplete:`new-password`,placeholder:Z(h?`passwordOptional`:`passwordRequired`,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:Z(n?`createAndJoin`:`createYourAccount`)})]})},dM=({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}=rk();if((0,I.useEffect)(()=>{r.organizations.invitation(e).then(c,e=>u(e instanceof yl?ZO(e):Z(`invalidLink`)))},[r,e]),l)return(0,B.jsx)(Ck,{title:Z(`invitation`),description:l,children:(0,B.jsx)(G,{className:`w-full`,onClick:t,children:Z(`goToApp`)})});if(!s)return(0,B.jsx)(Ck,{title:Z(`invitation`),children:(0,B.jsxs)(`div`,{className:`flex items-center justify-center gap-2 text-muted-foreground`,children:[(0,B.jsx)(Yu,{}),` `,Z(`loading`)]})});let m=i.kind===`signed-in`?i.user:void 0,h=m?.email.toLowerCase()===s.email.toLowerCase();if(!s.organization){let r=s.app?.name??``,i=Z(`invitesToApp`,s.inviter.name,r);return(0,B.jsx)(Ck,{title:Z(`join`,r),description:i,children:s.hasAccount?m&&h?(0,B.jsx)(G,{variant:`primary`,className:`w-full`,onClick:t,children:Z(`goToApp`)}):(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`p`,{className:`mb-3 text-muted-foreground`,children:Z(`hasAccount`,s.email)}),m?(0,B.jsx)(G,{className:`w-full`,onClick:()=>void a(),children:Z(`signOut`)}):(0,B.jsx)(ah,{to:n,className:P(ld({variant:`primary`}),`w-full`),children:Z(`signInAs`,s.email)})]}):m?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`p`,{className:`mb-3 text-muted-foreground`,children:Z(`otherAddress`,s.email,m.email)}),(0,B.jsx)(G,{className:`w-full`,onClick:()=>void a(),children:Z(`signOutToAccept`)})]}):(0,B.jsx)(uM,{token:e,preview:s,joins:!1,onDone:t})})}let g=s.organization,_=s.appRoles.map(e=>gk(o?.roles??[],e)),v=hk(s.role).toLowerCase(),y=_.length>0?Z(`invitesToWith`,s.inviter.name,g.name,v,_.join(`, `)):Z(`invitesTo`,s.inviter.name,g.name,v);return m&&!h?(0,B.jsxs)(Ck,{title:Z(`join`,g.name),description:y,children:[(0,B.jsx)(`p`,{className:`mb-3 text-muted-foreground`,children:Z(`otherAddress`,s.email,m.email)}),(0,B.jsx)(G,{className:`w-full`,onClick:()=>void a(),children:Z(`signOutToAccept`)})]}):(0,B.jsx)(Ck,{title:Z(`join`,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:Z(`join`,g.name)})]}):s.hasAccount?(0,B.jsx)(ah,{to:n,className:P(ld({variant:`primary`}),`w-full`),children:Z(`signInAsToJoin`,s.email)}):(0,B.jsx)(uM,{token:e,preview:s,joins:!0,onDone:t})})},fM=/^[A-Z][A-Za-z0-9]*$/,pM=e=>typeof e==`function`||typeof e==`object`&&!!e&&`$$typeof`in e,mM=e=>{let t=e.default??{},n=Object.entries(e).filter(e=>e[0]!=="default"&&fM.test(e[0])&&pM(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)}}},hM=class extends Error{name=`UiConflictError`},gM=e=>Object.keys(e).some(e=>e==="default"||/^[A-Z]/.test(e))?mM(e):e,_M=(e,t)=>[...(e.extends??[]).map(gM).flatMap((e,n)=>_M(e,e.name??`${t} extends[${n}]`)),{ui:e,label:t}],vM=(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 hM(`${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},yM=e=>e.length<=1?e[0]:()=>e.map((e,t)=>(0,B.jsx)(e,{},t)),bM=e=>e.length<=1?e[0]:({children:t,...n})=>e.reduceRight((e,t)=>(0,B.jsx)(t,{...n,children:e}),t),xM=(...e)=>{let t=e.flatMap((e,t)=>_M(e,e.name??`UI config ${t+1}`)),n=vM(`The component`,t,e=>e.components),r=vM(`The action handler`,t,e=>e.actions),i=vM(`The field type`,t,e=>e.fields),a=vM(`The drop rule`,t,e=>e.dropRules),o=vM(`The board drop`,t,e=>e.boardDrops),s=yM(t.flatMap(({ui:e})=>e.shell?.actions?[e.shell.actions]:[])),c=yM(t.flatMap(({ui:e})=>e.shell?.rightPanel?[e.shell.rightPanel]:[])),l=t.findLast(({ui:e})=>e.shell?.logo)?.ui.shell?.logo,u=t.findLast(({ui:e})=>e.shell?.bell)?.ui.shell?.bell,d=bM(t.flatMap(({ui:e})=>e.beforeSignIn?[e.beforeSignIn]:[])),f=e.at(-1)?.name;return{...f&&{name:f},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},...(s||c||l||u)&&{shell:{...s&&{actions:s},...c&&{rightPanel:c},...l&&{logo:l},...u&&{bell:u}}},...d&&{beforeSignIn:d}}},SM=(e,t)=>{let n=xM(e??{}),r=[],i=[];for(let e of t){if(e.kind===`off`){i.push(e);continue}try{xM(...r,e.ui,n),r.push(e.ui)}catch(t){if(!(t instanceof hM))throw t;i.push({kind:`off`,url:e.plugin.url,name:e.plugin.name,reason:t.message})}}return{ui:r.length===0?n:xM(...r,n),off:i}},CM=M({en:{loading:`Loading`,pluginsOff:`Plugins off`,pluginOff:`The plugin {} is off: {}.`,dismiss:`Dismiss`,answered:e=>`its plugin.json answered ${e}`,couldNotLoad:e=>`it could not be loaded: ${e}`,notObject:`its plugin.json is not an object`,noName:`its plugin.json names no plugin`,noApi:`its plugin.json names no plugin API`,noVersions:`its plugin.json names no Protobase versions`,noModule:`its plugin.json names no module`,badStylesheet:`its plugin.json names a stylesheet that is no URL`,badVersion:`its plugin.json has a version that is no text`},nl:{loading:`Laden`,pluginsOff:`Plug-ins uit`,pluginOff:`De plug-in {} staat uit: {}.`,dismiss:`Sluiten`,answered:e=>`de plugin.json antwoordde ${e}`,couldNotLoad:e=>`hij kon niet worden geladen: ${e}`,notObject:`de plugin.json is geen object`,noName:`de plugin.json noemt geen plug-in`,noApi:`de plugin.json noemt geen plug-in-API`,noVersions:`de plugin.json noemt geen Protobase-versies`,noModule:`de plugin.json noemt geen module`,badStylesheet:`de plugin.json noemt een stylesheet die geen URL is`,badVersion:`de plugin.json heeft een versie die geen tekst is`}}),wM=e=>typeof e==`string`&&e.trim()!==``,TM=e=>{if(typeof e!=`object`||!e||Array.isArray(e))return{problem:CM(`notObject`)};let{name:t,version:n,api:r,protobase:i,entry:a,css:o}=e;return wM(t)?Number.isInteger(r)?wM(i)?wM(a)?o!==void 0&&!wM(o)?{problem:CM(`badStylesheet`)}:n!==void 0&&!wM(n)?{problem:CM(`badVersion`)}:{manifest:{name:t,api:r,protobase:i,entry:a,...n!==void 0&&{version:n},...o!==void 0&&{css:o}}}:{problem:CM(`noModule`)}:{problem:CM(`noVersions`)}:{problem:CM(`noApi`)}:{problem:CM(`noName`)}},EM=(0,I.createContext)(null),DM=EM.Provider,OM=()=>{let e=(0,I.useContext)(EM);if(!e)throw Error(`usePlugin is for the components of a plugin the app loaded`);return e},kM=(e,t,n)=>{let r=n=>(0,B.jsx)(DM,{value:e,children:(0,B.jsx)(t,{...n})});return r.displayName=`${e.name}:${n}`,r},AM=(e,t,n)=>({of:n.of,display:kM(e,n.display,`fields.${t}.display`),...n.editor&&{editor:kM(e,n.editor,`fields.${t}.editor`)},...n.cell&&{cell:kM(e,n.cell,`fields.${t}.cell`)}}),jM=(e,t)=>{let n=xM({...mM(t),name:e.name}),r=Object.fromEntries(Object.entries(n.components??{}).map(([t,n])=>[t,kM(e,n,t)])),i=n.fields&&Object.fromEntries(Object.entries(n.fields).map(([t,n])=>[t,AM(e,t,n)])),a=n.shell&&{...n.shell.actions&&{actions:kM(e,n.shell.actions,`shell.actions`)},...n.shell.rightPanel&&{rightPanel:kM(e,n.shell.rightPanel,`shell.rightPanel`)},...n.shell.logo&&{logo:kM(e,n.shell.logo,`shell.logo`)},...n.shell.bell&&{bell:kM(e,n.shell.bell,`shell.bell`)}},o=n.beforeSignIn&&kM(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},...i&&{fields:i},...a&&{shell:a},...o&&{beforeSignIn:o}}},MM={name:`@protobase/ui`,version:`0.54.5`,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`,"lucide-react":`^1.52.0`,"maplibre-gl":`^6.14.0`,marked:`^18.1.1`,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`}},NM=MM.protobase.pluginApi,PM=MM.version,FM={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=>Be(()=>import(e),[])},IM={api:NM,version:PM},LM=e=>e instanceof Error?e.message:String(e),RM=async(e,t,n,r=IM)=>{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(CM(`answered`,n.status));let s=TM(n.json);if(`problem`in s)return a(s.problem);let{manifest:c}=s;o=c.name;let l=Pn(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:jM(d,u)}}catch(e){return a(CM(`couldNotLoad`,LM(e)),o)}},zM=e=>{let t=new Map;return{load:n=>{let r=JSON.stringify(n),i=t.get(r);if(i)return i;let a=RM(n,e,window.location.href);return t.set(r,a),a}}},BM=(0,I.createContext)(null),VM=({loader:e=FM,children:t})=>{let n=(0,I.useMemo)(()=>zM(e),[e]);return(0,B.jsx)(BM.Provider,{value:n,children:t})},HM=()=>{let e=(0,I.useContext)(BM);if(!e)throw Error(`usePluginSource must be used inside PluginSourceProvider`);return e},UM=1e4,WM=[],GM=(e,t)=>{let n=JSON.stringify(e),[r,i]=(0,I.useState)({key:`[]`,loads:WM,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()},UM);return e.forEach((e,n)=>{t.load(e).then(e=>{o[n]=e,s()})}),()=>{r=!1,clearTimeout(c)}},[n,t]),e.length===0?{loads:WM,settled:!0}:r.key===n?r:{loads:WM,settled:!1}},KM=({children:e})=>{let{state:t,beforeSignIn:n,adoptSession:r}=V(),{path:i,params:a,navigate:o}=mh(),{loads:s,settled:c}=GM(n,HM()),l=(0,I.useMemo)(()=>SM(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)($g,{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)(Yu,{}),` `,CM(`loading`)]})},qM=()=>{let e=window.location.href,t=Nj(e);if(t)return{kind:`reset-password`,token:t.token};let n=eM(e);if(n)return{kind:`staff-sign-in`,link:n};let r=cM(e);if(r)return{kind:`invitation`,token:r.token};let i=vu(e);if(i)return{kind:`provider-sign-in`,provider:i};let a=yu(e);return a?{kind:`sign-in`,providerError:a}:{kind:`sign-in`}},JM=({to:e})=>{let{navigate:t}=mh();return(0,I.useEffect)(()=>t(e,{replace:!0}),[t,e]),null},YM=({workspace:e,children:t})=>{let n=XM(e,t);return(0,B.jsx)(KM,{children:n})},XM=(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}=mh(),{address:p,next:m,open:h,link:g,leave:_}=mw(),[v,y]=(0,I.useState)(qM),[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(bu),(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&&yu(E)!==void 0;(0,I.useEffect)(()=>{!O&&v.kind===`sign-in`&&v.providerError&&k&&D(bu)},[O,v,k,D]);let A=(0,I.useCallback)(e=>y({kind:`sign-in`,error:e}),[]),j=e=>{D(Pj),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)(Yu,{}),` `,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`,n.message)}),(0,B.jsx)(G,{onClick:r,children:z(`tryAgain`)})]});case`needs-admin`:return(0,B.jsx)(kj,{onCheckAgain:r})}if(n.kind===`signed-in`&&p)return(0,B.jsx)(JM,{to:m??`/`});if(v.kind===`reset-password`)return(0,B.jsx)(zj,{token:v.token,onDone:()=>void ee(),onRequestNewLink:i?()=>{y({kind:`sign-in`}),f(gc({step:`forgot-password`}),{replace:!0})}:void 0,onBack:()=>j({kind:`sign-in`})});if(v.kind===`staff-sign-in`)return(0,B.jsx)(iM,{link:v.link,onBack:()=>{D(tM),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)(dM,{token:v.token,onDone:()=>{D(lM),y({kind:`sign-in`})},signIn:g()});if(n.kind===`signed-in`)return t;if(n.kind===`two-factor`)return(0,B.jsx)(sM,{methods:n.methods,onBack:te});if(n.kind===`setup-required`)return(0,B.jsx)(Hj,{missing:n.missing},n.missing.join());if(v.kind===`provider-sign-in`)return(0,B.jsx)(Lj,{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)(JM,{to:gc({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)(Fj,{back:g(`sign-in`,{replace:!0})});if(ie===`email-code`)return(0,B.jsx)(Dj,{email:b,onBack:ae(`sign-in`)});if(ie===`sign-up`||ie===`sign-up-code`||ie===`sign-up-details`)return(0,B.jsx)(Zj,{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&&nk(re.providerError,o.length===1?o[0].name:`the provider`),ce=re.error??se;return(0,B.jsx)(qj,{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)},ZM=e=>[...e].reduce((e,t)=>(e*31+t.charCodeAt(0))%360,7),QM=e=>e.split(/[\s@.]+/).filter(Boolean).slice(0,2).map(e=>e[0].toUpperCase()).join(``),$M=e=>(e.role??`user`).split(`,`).map(e=>e.trim()),eN=e=>$M(e).includes(`admin`),tN=e=>Qp(e.replace(/[_-]+/g,` `).trim()),nN=e=>{let t=$M(e),n=t.includes(`admin`);return{name:e.name||e.email,email:e.email,initials:QM(e.name||e.email)||`?`,hue:ZM(e.id||e.email),role:n?z(`admin`):tN(t[0]??`user`),roleTone:n?`violet`:`blue`}},rN=3e4,iN=(e,t=Date.now())=>Math.max(1e3,Ul(e)-t-rN),aN=()=>{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),iN(s))))};return a(),()=>{e=!1,clearTimeout(r)}},[t,n]),n?r:void 0},oN=({children:e})=>(0,B.jsx)(qu,{locale:V().locale,children:e}),sN=(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)}},cN=e=>{let t=U(),n=be(),r=(0,I.useContext)(Du),i=(0,I.useMemo)(()=>Object.values(e.resources).filter(t=>t.live&&!Ku(e,t.name)).map(e=>e.name).sort().join(`,`),[e]);(0,I.useEffect)(()=>{if(!i)return;let e=sN(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])},lN=(e,t,n=!0)=>{let r=U(),i=An(t);return E({queryKey:H.record(e,i),enabled:n,queryFn:()=>r.get(e,t)})},uN=(e,t,n=!0)=>{let r=U(),i=be(),a=An(t);return E({queryKey:H.record(e,a),enabled:n,queryFn:()=>r.get(e,t),placeholderData:()=>i.getQueryData(H.recordPreview(e,a))})},dN=M({en:{loading:`Loading`,notFound:`Not found`,noForm:`There is no form at this address.`,setByDatabase:`Set by the database`,notSent:`Not sent`,send:`Send`,checkTooLong:`The check that you are not a bot took too long; send the form again`},nl:{loading:`Laden`,notFound:`Niet gevonden`,noForm:`Er is geen formulier op dit adres.`,setByDatabase:`Ingevuld door de database`,notSent:`Niet verzonden`,send:`Verzenden`,checkTooLong:`De controle of je geen bot bent duurde te lang; verzend het formulier opnieuw`}}),fN=async(e,t)=>{let n=await e.formChallenge(t),r=await he({challenge:n,deriveKey:Te});if(!r)throw Error(dN(`checkTooLong`));return{challenge:n,solution:{counter:r.counter,derivedKey:r.derivedKey}}},pN=({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)(Yu,{}),` `,dN(`loading`)]}):n.error?jc(n.error)&&n.error.status===404?(0,B.jsx)(Zu,{title:dN(`notFound`),children:dN(`noForm`)}):(0,B.jsx)(Zu,{title:Xu(`cannotReach`),children:jc(n.error)?n.error.message:Xu(`noAnswer`)}):(0,B.jsx)(mN,{form:n.data})},mN=({form:e})=>{let t=U(),{resource:n,view:r}=e,i=e.title??r.names?.singular??F(r.resource);UA(i);let[a,o]=(0,I.useState)(()=>ug(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),_=Py(h);if(p)return(0,B.jsx)(Ck,{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,ag(n,{},a),await fN(t,e.name)),m(!0)}catch(e){let t=My(e);c(t),Object.keys(t).length>0?g(e=>e+1):u(e)}finally{f(!1)}};return(0,B.jsx)(Ck,{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)(ep,{name:e,label:o,help:i?.help,required:og(t),error:c&&jy(t,o,c),children:(0,B.jsx)(y_,{field:t,hints:i,value:a[e]??(t.type!==`boolean`&&``),stored:void 0,placeholder:dg(t)?dN(`setByDatabase`):lg(t),invalid:!!c,onChange:t=>v(e,t)})},e)}),l!==void 0&&(0,B.jsx)(pg,{title:dN(`notSent`),error:l}),(0,B.jsx)(G,{variant:`primary`,type:`submit`,loading:d,className:`min-h-10`,children:dN(`send`)})]})})},hN=()=>{let{path:e}=mh();return(0,I.useMemo)(()=>bn(e),[e])},gN=[`light`,`dark`,`system`],_N=`protobase:theme`,vN=`(prefers-color-scheme: dark)`,yN=e=>gN.includes(e),bN=e=>Fe(()=>{let t=e.getItem(_N);return yN(t)?t:`system`},`system`),xN=(e,t)=>Fe(()=>t===`system`?e.removeItem(_N):e.setItem(_N,t),void 0),SN=(e,t)=>e===`system`?t?`dark`:`light`:e,CN=(0,I.createContext)(void 0),wN=({children:e})=>{let[t,n]=(0,I.useState)(()=>bN(localStorage)),r=SN(t,ud(vN));return(0,I.useEffect)(()=>{document.documentElement.dataset.theme=r},[r]),(0,I.useEffect)(()=>{let e=e=>{(e.key===`protobase:theme`||e.key===null)&&n(bN(localStorage))};return window.addEventListener(`storage`,e),()=>window.removeEventListener(`storage`,e)},[]),(0,B.jsx)(CN.Provider,{value:{preference:t,theme:r,choose:e=>{xN(localStorage,e),n(e)}},children:e})},TN=()=>{let e=(0,I.useContext)(CN);if(!e)throw Error(`useTheme needs a ThemeProvider above it`);return e},EN=M({en:{message:`Message`,send:`Send`,today:`Today`,yesterday:`Yesterday`,newMessages:`New messages`,loadEarlier:`Load earlier messages`},nl:{message:`Bericht`,send:`Versturen`,today:`Vandaag`,yesterday:`Gisteren`,newMessages:`Nieuwe berichten`,loadEarlier:`Eerdere berichten laden`}}),DN=({children:e,className:t})=>(0,B.jsx)(`p`,{className:P(`text-xs text-muted-foreground`,t),children:e}),ON=({time:e})=>{let t=Date.parse(e);return(0,B.jsx)(`time`,{dateTime:e,title:ff(t),className:`text-xs text-muted-foreground`,children:yf(t)})},kN=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)(Qf,{initials:QM(s)||`?`,hue:ZM(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)(ON,{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)(DN,{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)(DN,{className:e.from===`user`?`text-right`:void 0,children:n})]}):r},AN=e=>e.scrollHeight-e.scrollTop-e.clientHeight<=24,jN=(e,t)=>{if(t.followKey!==e.followKey)return t.scrollHeight;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},MN=(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:AN(e),first:t.firstElementChild??void 0,followKey:n,...a}},NN=({children:e,empty:t,length:n,onLoadEarlier:r,loadingEarlier:i,followKey:a})=>{let o=(0,I.useRef)(null),s=(0,I.useRef)(null),c=(0,I.useRef)({atEnd:!0,first:void 0,followKey:a}),l=()=>{o.current&&s.current&&(c.current=MN(o.current,s.current,a))};(0,I.useLayoutEffect)(()=>{let e=o.current;if(!e||!s.current)return;let t=c.current,n=t.anchor&&t.anchor.element.isConnected?t.anchor.element.getBoundingClientRect().top-e.getBoundingClientRect().top:void 0,r=jN(t,{first:s.current.firstElementChild??void 0,anchorTop:n,scrollTop:e.scrollTop,scrollHeight:e.scrollHeight,followKey:a});r!==void 0&&(e.scrollTop=r),l()},[n,a]),(0,I.useEffect)(()=>{let e=o.current;if(!e||!s.current)return;let t=new ResizeObserver(()=>{c.current.atEnd&&(e.scrollTop=e.scrollHeight)});return t.observe(e),t.observe(s.current),()=>t.disconnect()},[]);let u=n===0&&!!t;return(0,B.jsxs)(`div`,{ref:o,onScroll:l,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:EN(`loadEarlier`)}),u&&(0,B.jsx)(`div`,{className:`m-auto max-w-60 text-center text-muted-foreground`,children:t}),(0,B.jsx)(`div`,{ref:s,role:`log`,"aria-live":`polite`,className:P(`flex flex-col gap-4`,u&&`hidden`),children:e})]})},PN=(e,t)=>{let n=/(?:^|\s)@([^\s@]*)$/.exec(e.slice(0,t));return n?{start:t-n[1].length-1,query:n[1]}:void 0},FN=(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(` `)}},IN=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),LN=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(IN).join(`|`)})(?![\\p{L}\\p{N}_])`,`gu`)},RN=(e,t)=>{let n=LN(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))]},zN=(e,t)=>{let n=LN(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},BN=M({en:{peopleToMention:`People to mention`,noOneFound:`No one found`,couldNotSearch:`Could not search for people`},nl:{peopleToMention:`Mensen om te noemen`,noOneFound:`Niemand gevonden`,couldNotSearch:`Kon niet naar mensen zoeken`}}),VN=({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":BN(`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:BN(o?`couldNotSearch`:`noOneFound`)})]}),HN=(e,t)=>{let n=mC(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},UN={text:``,picked:[]},WN=8,GN=({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?PN(e.text,l):void 0,S=d&&x!==void 0&&x.start!==h,C=HN(n,S?x.query:void 0),w=S&&C&&`people`in C?C.people.slice(0,WN):[],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=FN(e.text,x,n.name);y.current=r.caret,t({text:r.text,picked:[...e.picked,n]})},k=e=>{if(S){let t=dC(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)(gg,{...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)(VN,{id:b,optionId:E,people:w,active:p,onActive:m,onPick:O,failed:`failed`in C,at:r})]})},KN=({text:e,mentions:t})=>(0,B.jsx)(`p`,{className:`whitespace-pre-wrap break-words`,children:zN(e,t).map((e,t)=>`mention`in e?(0,B.jsxs)(`span`,{className:`font-medium text-primary`,children:[`@`,e.mention]},t):e.text)}),qN=({onSend:e,busy:t,placeholder:n,inputRef:r,searchPeople:i})=>{let[a,o]=(0,I.useState)(UN),s=a.text.trim(),c=()=>{s&&!t&&(e?.(s,RN(s,a.picked)),o(UN))};return(0,B.jsxs)(`form`,{className:`flex items-end gap-2`,onSubmit:e=>{e.preventDefault(),c()},children:[(0,B.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,B.jsx)(GN,{ref:r,rows:1,"aria-label":EN(`message`),placeholder:n,value:a,onChange:o,searchPeople:i,listAt:`above`,onKeyDown:e=>{e.key!==`Enter`||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),c())}})}),(0,B.jsx)(G,{type:`submit`,variant:`primary`,className:`w-8 px-0`,"aria-label":EN(`send`),disabled:!s||t,children:(0,B.jsx)(No,{className:`size-4`})})]})},JN=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},YN=M({en:{close:`Close`},nl:{close:`Sluiten`}}),XN=({title:e,icon:t,status:n,onClose:r,footer:i,children:a})=>{let o=JN(!dd());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":YN(`close`),onClick:r,children:(0,B.jsx)(Ls,{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})]})},ZN=M({en:{cancel:`Cancel`},nl:{cancel:`Annuleren`}}),QN={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`}},$N=({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`,QN[t].border),children:[!s&&(0,B.jsxs)(`header`,{className:P(`flex items-center gap-2 px-3 py-2`,QN[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)(vd,{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:ZN(`cancel`)}),(0,B.jsx)(G,{variant:c.style===`danger`?`danger`:`primary`,onClick:()=>{l(void 0),a?.(c.id)},children:c.label})]})})]})},eP=({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}`))}),tP=e=>e==null?`null`:typeof e==`object`?JSON.stringify(e):String(e),nP=M({en:{table:`Table`,noRows:`No rows.`,rows:e=>`${e} ${e===1?`row`:`rows`}`,cutOff:`, cut off at the limit`},nl:{table:`Tabel`,noRows:`Geen rijen.`,rows:e=>`${e} ${e===1?`rij`:`rijen`}`,cutOff:`, afgekapt bij de limiet`}}),rP=({columns:e,rows:t,caption:n,truncated:r,className:i})=>(0,B.jsxs)(`section`,{"aria-label":n??nP(`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:nP(`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:tP(e)},t))},t))})]})}),(0,B.jsxs)(`footer`,{className:`border-t border-border px-3 py-1.5 text-[11px] text-muted-foreground`,children:[nP(`rows`,t.length),r&&nP(`cutOff`)]})]}),iP=(e,t=1)=>{let n=t,r=t;return e.split(`
|
|
6
|
-
`).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++})},aP=e=>({added:e.filter(e=>e.kind===`add`).length,removed:e.filter(e=>e.kind===`del`).length}),oP={add:`bg-success-soft text-success-text`,del:`bg-danger-soft text-danger-text`,ctx:`text-muted-foreground`},sP={add:`+`,del:`−`,ctx:``},cP=({source:e,start:t,path:n,className:r})=>{let i=iP(e,t),a=aP(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)(ea,{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`,oP[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:sP[e.kind]}),(0,B.jsx)(`span`,{className:`min-w-0 whitespace-pre-wrap break-words pr-3`,children:e.text})]},t))})]})},lP={pending:(0,B.jsx)(Oi,{className:`size-3 text-faint-foreground`}),running:(0,B.jsx)(Yu,{className:`size-3.5 text-primary`}),done:(0,B.jsx)(ui,{className:`size-3.5 text-success`,strokeWidth:2.5}),failed:(0,B.jsx)(Ls,{className:`size-3.5 text-danger`,strokeWidth:2.5})},uP={pending:`text-muted-foreground`,running:`text-foreground`,done:`text-muted-foreground`,failed:`text-danger-text`},dP=({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:lP[e.state]}),(0,B.jsx)(`span`,{className:uP[e.state],children:e.label})]},`${t}-${e.label}`))}),fP=M({en:{askQuestion:`Ask a question...`,assistant:`Assistant`,reconnecting:`Reconnecting...`,empty:`Ask a question about this app or its data.`,noAnswer:`The assistant did not answer`,backendNoAnswer:`The assistant backend did not answer`,couldNotDraw:`It could not be drawn.`,cannotShowLive:`This version of the app cannot show it live.`},nl:{askQuestion:`Stel een vraag...`,assistant:`Assistent`,reconnecting:`Opnieuw verbinden...`,empty:`Stel een vraag over deze app of de gegevens ervan.`,noAnswer:`De assistent antwoordde niet`,backendNoAnswer:`De backend van de assistent antwoordde niet`,couldNotDraw:`Dit kon niet worden getekend.`,cannotShowLive:`Deze versie van de app kan dit niet live tonen.`}}),pP=({part:e,note:t})=>e.fallback?(0,B.jsx)($N,{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}`}),mP=class extends I.Component{state={failed:!1};static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(e,t){Xg(e,t.componentStack)}render(){return this.state.failed?(0,B.jsx)(pP,{part:this.props.part,note:fP(`couldNotDraw`)}):this.props.children}},hP=({part:e})=>{let{components:t={}}=Wg(),n=Object.hasOwn(t,e.name)?t[e.name]:void 0;return n?(0,B.jsx)(mP,{part:e,children:(0,B.jsx)(n,{...e.props})}):(0,B.jsx)(pP,{part:e,note:fP(`cannotShowLive`)})},gP=({part:e,onAction:t})=>{switch(e.type){case`text`:return(0,B.jsx)(`p`,{children:e.text});case`table`:return(0,B.jsx)(rP,{columns:e.columns,rows:e.rows,caption:e.caption,truncated:e.truncated});case`card`:return(0,B.jsxs)($N,{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)(eP,{fields:e.fields}),e.steps&&e.steps.length>0&&(0,B.jsx)(dP,{steps:e.steps}),e.diffs?.map((e,t)=>(0,B.jsx)(cP,{source:e.source,start:e.start,path:e.path,className:`rounded-md border border-border`},`${t}-${e.path}`))]});case`widget`:return(0,B.jsx)(hP,{part:e})}},_P=(0,I.createContext)(void 0),vP=e=>e instanceof Error?e:Error(fP(`backendNoAnswer`)),yP=(e,t)=>typeof e==`function`?e(t):e,bP=(e,{refreshMs:t=!1}={})=>{let n=(0,I.useContext)(_P),[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:vP(e)}));if(!t)return;c.current=o.data,i(o);let l=yP(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:vP(e)}));c.current=a.data,i(a)}}},xP=({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)(XN,{title:fP(`assistant`),icon:(0,B.jsx)(Zo,{className:`size-4 text-primary`}),status:t?fP(`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)(qN,{inputRef:s,onSend:r,busy:e.replying,placeholder:e.placeholder??fP(`askQuestion`)})]}),children:(0,B.jsx)(_P.Provider,{value:o,children:(0,B.jsx)(NN,{length:e.messages.reduce((e,t)=>e+t.parts.length,0),empty:fP(`empty`),children:e.messages.map(e=>(0,B.jsx)(kN,{from:e.from,children:e.parts.map(e=>(0,B.jsx)(gP,{part:e,onAction:i},e.id))},e.id))})})})},SP=e=>e instanceof Error?e.message:fP(`noAnswer`),CP=e=>{let[t,n]=(0,I.useState)(Yn),[r,i]=(0,I.useState)(!1),[a,o]=(0,I.useState)();(0,I.useEffect)(()=>{if(e)return e.connect(e=>n(t=>Qn(t,e)),e=>i(e.state===`retrying`))},[e]);let s=e=>{o(void 0),e.catch(e=>o(SP(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))}},wP=e=>{let t=aN(),n=(0,I.useRef)(t);n.current=t;let r=t!==void 0;return(0,I.useMemo)(()=>r?Yl({url:e,token:()=>n.current}):void 0,[e,r])},TP=({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)(Zo,{className:`size-3.5`}),(0,B.jsx)(`span`,{className:`max-md:sr-only`,children:J(`assistant`)})]}),EP=({client:e,page:t,onClose:n})=>{let{state:r,offline:i,error:a,send:o,act:s}=CP(e);return(0,B.jsx)(xP,{state:r,offline:i,error:a,onSend:e=>o(e,t),onAction:s,onClose:n,client:e})},DP=({url:e,...t})=>(0,B.jsx)(EP,{client:wP(e),...t}),OP=({url:e,client:t,...n})=>t?(0,B.jsx)(EP,{client:t,...n}):(0,B.jsx)(DP,{url:e,...n}),kP={orders:Go,orderLines:Go,companies:ei,invoices:ia,invoiceLines:Co,products:oo,categories:ps,tags:ps,companyTags:ps,stockMoves:Qr,stockLevels:Qr,warehouses:Ns,locations:Ns,people:ks,users:ks,empMaster:ks,organizations:zo,countries:Hi,currencies:Ii,shipments:xs},AP=e=>kP[e]??ss,jP={bell:Br,"book-open":Hr,bookmark:Jr,building:ei,"credit-card":Ii,"external-link":Ji,"file-text":ia,heart:ua,key:va,"layout-dashboard":wa,"life-buoy":Aa,mail:Wa,receipt:Co,settings:zo,shield:Vo,users:ks};Object.keys(jP);var MP=(e,t)=>e?jP[e]??t:t,NP=(e,t,n)=>(e.bottomBar?.items??[]).map((r,i)=>r.kind===`link`?{id:`link-${i}`,label:r.label,icon:MP(r.icon,Ji),href:r.href,external:!0}:r.kind===`page`?{id:r.page,label:r.label,icon:MP(r.icon??e.pages[r.page]?.icon,wa),href:ic({kind:`page`,page:r.page},t),active:r.page===n}:{id:r.resource,label:r.label,icon:MP(r.icon,AP(r.resource)),href:ic({kind:`list`,resource:r.resource},t),active:r.resource===n}),PP=({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:ic({kind:`page`,page:r.name},e)}];if(!t||t.kind===`page`)return[J(`admin`)];let c=i?[{label:i,href:ic({kind:`list`,resource:t.resource,...t.kind===`list`&&t.list&&{list:t.list}},e)}]:[];if(t.kind===`list`)return[...s,...c];let l=ic(t,e),u=t.kind===`create`?{label:J(`new`),href:l}:a===void 0&&o?{label:J(`loadingRecord`),href:l,loading:!0}:{label:a??t.key,href:l};return[...s,...c,u]},FP=({name:e,tab:t})=>{let n=W().pages[e];if(!n)return(0,B.jsx)(Zu,{title:Y(`notFound`),children:Qg(Y(`noPage`),e)});let r=t=>ic({kind:`page`,page:e,...t&&{tab:t}});return(0,B.jsx)(nd,{route:{...t&&{tab:t},pathOf:r},children:(0,B.jsx)(LA,{node:n.tree})})},Q=M({en:{details:`Details`,history:`History`,comments:`Comments`,summary:`Summary`,loading:`Loading`,fetching:`Fetching the record.`,noRecord:`This record does not exist, or you cannot see it.`,openingElsewhere:`Opening the record in its organization.`,couldNotLoad:`Could not load the record`,someoneElse:`Someone else`,justNow:`just now`,saved:`Saved`,save:`Save`,cancel:`Cancel`,unsavedChanges:`Unsaved changes`,notSaved:`Not saved`,linesChanged:`The lines were changed by someone else`,linesReloaded:`The lines were reloaded. Your new order is kept: Save again to apply it.`,unsavedKept:`You have unsaved changes to this record.`,continueEditing:`Continue editing`,discard:`Discard`,unsavedRestored:`Your unsaved changes were restored.`,keep:`Keep`,savingSubject:e=>`Saving ${e}...`,subjectSaved:e=>`${e} saved`,changedBySomeoneElse:`Changed by someone else`,couldNotSave:`Could not save`,recordActions:`Record actions`,edit:`Edit`,delete:`Delete`,nothingYet:`Nothing here yet.`,couldNotLoadRelated:`Could not load`,relatedRecords:`Related records`,lines:`Lines`,linesHelp:`What the document bills for. Drag the handle, or use the menu, to change the order; Save applies it.`},nl:{details:`Details`,history:`Geschiedenis`,comments:`Opmerkingen`,summary:`Overzicht`,loading:`Laden`,fetching:`Het record wordt opgehaald.`,noRecord:`Dit record bestaat niet, of je mag het niet zien.`,openingElsewhere:`Het record wordt in zijn organisatie geopend.`,couldNotLoad:`Kon het record niet laden`,someoneElse:`Iemand anders`,justNow:`zojuist`,saved:`Bewaard`,save:`Bewaren`,cancel:`Annuleren`,unsavedChanges:`Niet bewaarde wijzigingen`,notSaved:`Niet bewaard`,linesChanged:`De regels zijn door iemand anders gewijzigd`,linesReloaded:`De regels zijn opnieuw geladen. Je nieuwe volgorde is behouden: bewaar opnieuw om hem toe te passen.`,unsavedKept:`Je hebt niet bewaarde wijzigingen in dit record.`,continueEditing:`Verder bewerken`,discard:`Weggooien`,unsavedRestored:`Je niet bewaarde wijzigingen zijn teruggezet.`,keep:`Houden`,savingSubject:e=>`${e} bewaren...`,subjectSaved:e=>`${e} bewaard`,changedBySomeoneElse:`Gewijzigd door iemand anders`,couldNotSave:`Kon niet bewaren`,recordActions:`Recordacties`,edit:`Bewerken`,delete:`Verwijderen`,nothingYet:`Hier staat nog niets.`,couldNotLoadRelated:`Kon niet laden`,relatedRecords:`Gerelateerde records`,lines:`Regels`,linesHelp:`Waar het document voor factureert. Sleep de greep, of gebruik het menu, om de volgorde te wijzigen; Bewaren past hem toe.`}}),IP=2e3,LP=(e,t)=>{let n=Gf(),[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`,t)}):void 0;o(void 0),e===`button`&&i(`saving`);try{return await r(),a!==void 0&&n.update(a,{state:`success`,title:Q(`subjectSaved`,t)}),e===`button`&&(i(`saved`),s.current=setTimeout(()=>i(`idle`),IP)),!0}catch(t){if(!jc(t))throw t;let r=t.status===412?Q(`changedBySomeoneElse`):Q(`couldNotSave`),s=Ny(t);return a!==void 0&&n.update(a,{state:`error`,title:r,description:s}),e===`button`&&(i(`idle`),o(`${r}: ${s}`)),!1}}}},RP=({title:e,eyebrow:t,submit:n,saving:r,disabled:i,error:a,errorTitle:o=eg(`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:eg(`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)(pg,{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]})})},zP=({noun:e,collection:t,sections:n,saving:r,message:i,onSubmit:a,onCancel:o,ref:s})=>(0,B.jsx)(RP,{ref:s,title:eg(`title`,e),eyebrow:t,submit:eg(`submit`,e),saving:r,error:i?Error(i):void 0,errorTitle:eg(`notCreated`),onSubmit:a,onCancel:o,children:n.map(e=>(0,B.jsx)(np,{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)(ep,{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))}),BP=(e,t)=>Object.fromEntries(Object.entries(e).filter(([e])=>e!==t)),VP=({resource:e,values:t})=>{let n=W(),r=n.resources[e],i=ed(e);return r?V_(i,`create`)?(0,B.jsx)(HP,{resource:e,values:t}):(0,B.jsx)(Zu,{title:eg(`notAllowed`),children:eg(`cannotCreate`,n.views[e]?.names?.plural.toLowerCase()??e)}):(0,B.jsx)(Zu,{title:J(`notFound`),children:J(`noResource`,e)})},HP=({resource:e,values:t})=>{let n=W(),r=n.resources[e],i=n.views[e],a=U(),o=be(),{go:s}=Th(),c=i?.names?.singular??F(e),l=LP(i?.saveFeedback??`toast`,eg(`subject`,c)),u=rg(r,i),[d,f]=(0,I.useState)(()=>ug(r,u,t)),[p,m]=(0,I.useState)({}),[h,g]=(0,I.useState)(0),_=Py(h),[v,y]=(0,I.useState)(),[b,x]=(0,I.useState)(!1);wh(!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&&ny(o,a,t,[i],n.views[t.name]).then(t=>{let n=t.get(i);n&&f(t=>tg(t[e])&&t[e].key===i?{...t,[e]:{key:i,label:n}}:t)})}},[t,n,r,a,o]);let S=(e,t)=>{m(t=>BP(t,e)),x(!0),f(n=>({...n,[e]:t}))},C=()=>l.run(async()=>{let t;try{t=await a.create(e,ag(r,n.resources,d))}catch(e){let t=My(e);throw m(t),Object.keys(t).length>0&&g(e=>e+1),e}for(let t of[`page`,`list`,`first-page`,`map`,`facets`,`series`])o.invalidateQueries({queryKey:[t,e]});y({kind:`record`,resource:e,key:om(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:og(t),error:c&&jy(t,s,c),wide:!!(i?.fields[e]?.multiline||i?.fields[e]?.markdown),editor:(0,B.jsx)(y_,{field:t,hints:i?.fields[e],value:tg(a)?a.key:a??(t.type!==`boolean`&&``),stored:void 0,relationLabel:tg(a)?a.label:void 0,placeholder:dg(t)?eg(`setByDatabase`):lg(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)(zP,{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})})},UP=({resource:e,values:t})=>{let n=W(),r=n.views[e];return r?.create?n.pages[r.create.page]?(0,B.jsx)(FP,{name:r.create.page}):(0,B.jsx)(Zu,{title:eg(`notAllowed`),children:eg(`cannotCreate`,r.names?.plural.toLowerCase()??F(e))}):(0,B.jsx)(VP,{resource:e,values:t},new URLSearchParams(t).toString())},WP=(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)}}))},GP=(e,t)=>[...new Set(t.filter(t=>!e.includes(t)))],KP=on(),qP=(e,t)=>{let n=U(),[r,i]=(0,I.useState)({}),a=e=>!!e?.search?.length&&e.primaryKey.length===1,o=f({queries:e.map(({id:e,target:i})=>{let o=(r[e]??``).trim();return{queryKey:[`reference-search`,e,i?.name??``,o],enabled:a(i)&&o!==``,placeholderData:d,queryFn:async()=>{let e=i.primaryKey[0],r=ir(i,t[i.name]);return(await n.list(i.name,{filter:Jt(KP.search(o)),fields:[e,r],pageSize:20})).items.map(t=>[String(t[e]),String(t[r])])}}})});return e.map(({id:e,target:t},n)=>{if(!a(t))return{};let s=t=>i(n=>({...n,[e]:t}));return(r[e]??``).trim()===``?{onSearch:s}:{onSearch:s,matches:o[n]?.data??[]}})},JP=24,YP=({model:e,resources:t,views:n,view:r,state:i,extras:a})=>{let o=U(),s=be(),c=QC(r,e),l=e=>r?.fields[e]?.label??F(e),u=n=>{let r=e.fields[n];return r?.type===`relation`&&r.relation?t[r.relation.resource]:void 0},d=c.facets.flatMap(e=>(e.flags?e.options.map(e=>e.value):[e.id]).map(t=>({group:e.id,field:t}))),p=f({queries:d.map(({group:t,field:r})=>{let s=zC(c,{...i,facets:{...i.facets,[t]:[]}},a),l=u(r),d=l?.primaryKey.length===1?ir(l,n[l.name]):void 0;return{queryKey:H.facets(e.name,r,s),queryFn:()=>o.facets(e.name,r,{filter:s,limit:50,...d&&{label:d}})}})}),m=(e,t)=>p[d.findIndex(n=>n.group===e&&n.field===t)]?.data,h=f({queries:c.facets.map(t=>{let r=u(t.id),a=GP((m(t.id,t.id)??[]).flatMap(e=>e.value===null?[]:[String(e.value)]),i.facets[t.id]??[]);return{queryKey:H.labels(`facet:${e.name}.${t.id}`,a.join(`,`)),enabled:!!r&&a.length>0,queryFn:async()=>[...await ny(s,o,r,a,n[r.name])]}})}),g=qP(c.facets.map(e=>({id:e.id,target:e.combobox?u(e.id):void 0})),n),_=c.ranges??[],v=f({queries:_.map(t=>{let n=zC(c,eC(i,t.id,void 0),a),s=$C(r,t.id)?JP:1;return{queryKey:H.histogram(e.name,t.id,s,n),queryFn:()=>o.histogram(e.name,t.id,{filter:n,buckets:s})}})});return{facets:c.facets.map((t,n)=>{if(t.flags){let e=t.options.map(({value:e})=>({value:e,label:l(e),count:m(t.id,e)?.find(e=>String(e.value)===`true`)?.count??0}));return{...t,options:e}}let i=e.fields[t.id],a=(m(t.id,t.id)??[]).flatMap(e=>e.label===void 0?[]:[[String(e.value),e.label]]),o=new Map([...a,...h[n]?.data??[]]),s=(m(t.id,t.id)??[]).flatMap(e=>e.value===null?[]:[{value:String(e.value),label:i?.type===`enum`?tr(String(e.value),r?.fields[t.id]?.valueLabels):o.get(String(e.value))??String(e.value),count:e.count}]),c=g[n];return{...t,label:l(t.id),options:c.matches?WP(c.matches,s):s,...o.size>0&&{labels:Object.fromEntries(o)},...c.onSearch&&{onSearch:c.onSearch}}}),ranges:_.flatMap((e,t)=>{let n=v[t]?.data;return!n||n.min===null||n.max===null?[]:[{...e,label:l(e.id),min:Math.floor(n.min),max:Math.ceil(n.max),step:Math.max(1,Math.round((n.max-n.min)/100)),histogram:$C(r,e.id)?n.buckets.map(e=>e.count):[],format:ew(r,e.id)}]}),...c.dateField&&{datePresets:c.datePresets??!0,dateField:c.dateField,dateKind:c.dateKind,...c.dateSecondary&&{dateSecondary:!0}},toggles:c.toggles?.map(e=>({...e,label:l(e.id)}))}},XP=M({en:{confirmTitle:e=>`Delete ${e}?`,confirmDescription:(e,t)=>`This ${e.toLowerCase()} will be removed. This cannot be undone.`,cancel:`Cancel`,delete:`Delete`,changedTitle:e=>`${e} was changed since you opened it`,changedDescription:`Someone saved this record in the meantime. Review what changed before you delete it.`,reviewChanges:`Review changes`,deleteAnyway:`Delete anyway`,noVisibleChanges:`No visible fields differ; the record was saved again with the same values.`,bulkConfirmTitle:(e,t)=>`Delete ${e} ${e===1?t.replace(/s$/,``):t.toLowerCase()}?`,bulkConfirmDescription:`This cannot be undone. Each record is deleted only if it has not changed since the list loaded; anything that changed is reported and kept.`,deleteCount:e=>`Delete ${e}`,deleting:`Deleting`,progress:(e,t)=>`${e} of ${t} done`,working:`Working`,deleted:e=>`Deleted ${e}`,deletedOf:(e,t)=>`Deleted ${e} of ${t}`,kept:e=>`${e} could not be deleted and were kept.`,done:`Done`,deletedToast:e=>`${e} deleted`,undo:`Undo`,restored:e=>`${e} restored`,alreadyBack:e=>`${e} is already back`,couldNotRestore:e=>`Could not restore ${e}`,couldNotDelete:e=>`Could not delete ${e}`,changedSinceLoaded:`Changed since the list loaded, so it was kept.`,stillPointAt:(e,t)=>`${e} still point at this ${t.toLowerCase()}.`,show:e=>`Show ${e.toLowerCase()}`},nl:{confirmTitle:e=>`${e} verwijderen?`,confirmDescription:(e,t)=>`${t} wordt verwijderd. Dit kan niet ongedaan worden gemaakt.`,cancel:`Annuleren`,delete:`Verwijderen`,changedTitle:e=>`${e} is gewijzigd sinds je het opende`,changedDescription:`Iemand heeft dit record intussen bewaard. Bekijk wat er veranderde voordat je het verwijdert.`,reviewChanges:`Wijzigingen bekijken`,deleteAnyway:`Toch verwijderen`,noVisibleChanges:`Geen zichtbaar veld verschilt; het record is opnieuw bewaard met dezelfde waarden.`,bulkConfirmTitle:(e,t)=>e===1?`Eén record verwijderen?`:`${e} ${t.toLowerCase()} verwijderen?`,bulkConfirmDescription:`Dit kan niet ongedaan worden gemaakt. Elk record wordt alleen verwijderd als het niet is gewijzigd sinds de lijst laadde; wat wel is gewijzigd, wordt gemeld en behouden.`,deleteCount:e=>`${e} verwijderen`,deleting:`Verwijderen`,progress:(e,t)=>`${e} van ${t} klaar`,working:`Bezig`,deleted:e=>`${e} verwijderd`,deletedOf:(e,t)=>`${e} van ${t} verwijderd`,kept:e=>`${e} kon${e===1?``:`den`} niet worden verwijderd en ${e===1?`is`:`zijn`} behouden.`,done:`Klaar`,deletedToast:e=>`${e} verwijderd`,undo:`Ongedaan maken`,restored:e=>`${e} teruggezet`,alreadyBack:e=>`${e} is al terug`,couldNotRestore:e=>`Kon ${e} niet terugzetten`,couldNotDelete:e=>`Kon ${e} niet verwijderen`,changedSinceLoaded:`Gewijzigd sinds de lijst laadde, dus behouden.`,stillPointAt:(e,t)=>`${e} verwijzen hier nog naar.`,show:e=>`${e} tonen`}}),ZP=on(),QP=({blockingPlural:e,noun:t})=>XP(`stillPointAt`,e,t),$P=({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=QP({blockingPlural:s,noun:r});if(!o||i===void 0)return{text:c};let l={kind:`list`,resource:a,filter:Jt(ZP.eq(o,i))};return{text:c,link:{label:XP(`show`,s),to:l}}},eF=({title:e,noun:t,busy:n,onConfirm:r,onCancel:i})=>(0,B.jsx)(vd,{title:XP(`confirmTitle`,e),description:XP(`confirmDescription`,t,e),onClose:i,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:i,children:XP(`cancel`)}),(0,B.jsx)(G,{variant:`primary`,className:`bg-danger hover:bg-danger/90`,loading:n,onClick:r,children:XP(`delete`)})]})}),tF=({title:e,changes:t,busy:n,onReview:r,onDeleteAnyway:i,onCancel:a})=>(0,B.jsx)(vd,{title:XP(`changedTitle`,e),description:XP(`changedDescription`),onClose:a,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:r,children:XP(`reviewChanges`)}),(0,B.jsx)(G,{variant:`primary`,className:`bg-danger hover:bg-danger/90`,loading:n,onClick:i,children:XP(`deleteAnyway`)})]}),children:t.length===0?(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:XP(`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))})}),nF=e=>{if(e.stage===`confirm`)return(0,B.jsx)(vd,{title:XP(`bulkConfirmTitle`,e.count,e.plural),description:XP(`bulkConfirmDescription`),onClose:e.onCancel,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:e.onCancel,children:XP(`cancel`)}),(0,B.jsx)(G,{variant:`primary`,className:`bg-danger hover:bg-danger/90`,onClick:e.onConfirm,children:XP(`deleteCount`,e.count)})]})});if(e.stage===`running`)return(0,B.jsx)(vd,{title:XP(`deleting`),description:XP(`progress`,e.done,e.total),onClose:()=>void 0,actions:(0,B.jsx)(G,{loading:!0,disabled:!0,children:XP(`working`)})});let t=e.total-e.failures.length;return(0,B.jsx)(vd,{title:e.failures.length===0?XP(`deleted`,t):XP(`deletedOf`,t,e.total),description:e.failures.length===0?void 0:XP(`kept`,e.failures.length),onClose:e.onClose,actions:(0,B.jsx)(G,{variant:`primary`,onClick:e.onClose,children:XP(`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))})})},rF=new Set([`updated_at`,`updatedAt`]),iF=(e,t,n,r)=>Object.values(e.fields).flatMap(e=>{if(rF.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:bm(e,n[e.name],i),after:bm(e,r[e.name],i)}]}),aF=4,oF=({model:e,view:t,onDeleted:n,onReview:r,restore:i})=>{let a=U(),o=be(),s=Gf(),[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:_}=Th(),v=(t,n)=>t.blockedBy&&$P({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 Ac))throw e;return e}},x=t=>{y(),l(void 0),n?.(t),s.show({state:`success`,title:XP(`deletedToast`,t.title),...e.softDelete&&i&&{action:{label:XP(`undo`),onClick:()=>{i(t).then(()=>{y(),s.show({state:`success`,title:XP(`restored`,t.title)})},e=>{if(!jc(e))throw e;y(),s.show({state:e.status===409?`success`:`error`,title:e.status===409?XP(`alreadyBack`,t.title):XP(`couldNotRestore`,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:iF(e,t,n.snapshot,i)})}catch(e){if(!jc(e))throw e;l(void 0);let t=v(e,n);s.show({state:`error`,title:XP(`couldNotDelete`,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:XP(`changedSinceLoaded`)}:void 0}catch(t){if(!jc(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(aF,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)(eF,{title:c.target.title,noun:f,busy:u,onCancel:T,onConfirm:()=>void S(c.target,c.target.etag)}),c.kind===`conflict`&&(0,B.jsx)(tF,{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)(nF,{stage:`confirm`,count:c.targets.length,plural:p,onCancel:T,onConfirm:()=>void w(c.targets)}),c.kind===`bulk-running`&&(0,B.jsx)(nF,{stage:`running`,done:c.done,total:c.total}),c.kind===`bulk-done`&&(0,B.jsx)(nF,{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})}},sF=e=>{let t=U();return e.softDelete?async n=>void await t.undelete(e.name,n.key):void 0},cF=(e,t,n)=>e?.create?Object.hasOwn(t,e.create.page):V_(n,`create`),$=M({en:{import:`Import`,importPlural:e=>`Import ${e.toLowerCase()}`,couldNotReadFile:`Could not read the file`,couldNotCheck:`Could not check the rows`,cancel:`Cancel`,next:`Next`,checkRows:`Check rows`,back:`Back`,checking:`Checking`,importRows:(e,t)=>`Import ${e} ${t===1?`row`:`rows`}`,cancelImport:`Cancel import`,done:`Done`,file:`File`,fileHint:`An Excel workbook (.xlsx) or a CSV file saved as UTF-8. Its first row names the columns.`,reading:e=>`Reading ${e}…`,theFile:`the file`,sheet:`Sheet`,create:`Create`,update:`Update`,upsert:`Create or update`,createHint:`Each row creates a record.`,updateHint:`Each row updates the record its value finds; a row that finds none is not imported.`,upsertHint:`Each row updates the record its value finds, or creates one when it finds none.`,doNotImport:`Do not import`,rows:`Rows`,whatEachRowDoes:`What each row does`,findBy:`Find records by`,chooseField:`Choose a field`,findByHint:`A field no two records share, such as the key or an email.`,foundInColumn:`Found in column`,chooseColumn:`Choose a column`,numbers:`Numbers`,dates:`Dates`,dayFirst:`Day first (31/12/2026)`,monthFirst:`Month first (12/31/2026)`,datesHint:`Dates written as 2026-12-31 read the same either way. Times without a zone are your own time.`,requiredMarked:`New records need the fields marked *.`,columns:`Columns`,emptyInFirstRows:`Empty in the first rows`,field:`Field`,fieldFor:e=>`Field for ${e}`,foundBy:`Found by`,pluralFoundBy:e=>`${e} found by`,noColumnFills:e=>`No column fills ${e}, which new records need.`,rowsNotImported:`Rows not imported`,rowProblems:e=>`Row ${e}:`,andMore:e=>`And ${e} more rows, all in the file.`,checkingRows:e=>`Checking rows… ${e} read`,check:`Check`,toCreate:`To create`,toUpdate:`To update`,withProblems:`With problems`,firstRows:`First rows`,row:`Row`,problemRows:`Rows with problems, which are skipped`,download:`Download`,batches:e=>`Rows are saved in batches of ${e}. Cancelling, or an error, keeps the batches already saved; a row the server refuses is listed and the others are saved.`,stopping:`Stopping after this batch…`,saving:`Saving rows…`,rowsSaved:`Rows saved`,stopped:`The import stopped. The rows counted below were saved.`,cancelled:`Cancelled. The rows counted below were saved.`,summary:`Import summary`,created:`Created`,updated:`Updated`,skipped:`Skipped`,failed:`Failed`,notWrittenHint:`Skipped rows had problems in the file; the server refused the failed ones. The file holds each with the reason, to fix and import again.`,notImportedFile:e=>`${e} - not imported.csv`,line:`Line`,problems:`Problems`,notNumber:e=>`${e} is not a number`,notWholeNumber:e=>`${e} is not a whole number`,tooLarge:e=>`${e} is too large`,notBoolean:e=>`${e} is not true or false (true, false, yes, no, 1 or 0)`,notDate:(e,t)=>`${e} is not a date (2026-04-03 or ${t?`day/month/year`:`month/day/year`})`,hasTime:e=>`${e} has a time of day; the field holds a date`,severalValues:(e,t)=>`${e} matches more than one value: ${t}`,notOneOf:(e,t)=>`${e} is not one of ${t}`,notText:e=>`${e} is true or false, not text`,emptyRequired:`is empty, and it is required`,noneHas:(e,t)=>`no ${e.toLowerCase()} has ${t}`,severalHave:(e,t,n)=>`${e} ${t.toLowerCase()} have ${n}`,notOneRecord:e=>`Not one record: ${e}`,nothingToUpdate:e=>`Nothing to update: ${e}`,fileNotUtf8:`The file is not UTF-8 text. Save it as "CSV UTF-8" and choose it again.`,noSheets:`The workbook has no sheets`,missingSheetPart:`The workbook names a sheet it does not hold`,notZip:`The file is not an Excel workbook (.xlsx): it is no ZIP archive`,zip64:`The workbook is too large to read: it is a ZIP64 archive`,compression:(e,t)=>`The workbook's part ${e} is compressed in a way that cannot be read (method ${t})`,notWorkbook:e=>`The file is not an Excel workbook (.xlsx): it has no ${e}`,noSheetCalled:e=>`The workbook has no sheet called ${e}`,unreadable:`The file could not be read`,column:e=>`Column ${e}`},nl:{import:`Importeren`,importPlural:e=>`${e} importeren`,couldNotReadFile:`Kon het bestand niet lezen`,couldNotCheck:`Kon de rijen niet controleren`,cancel:`Annuleren`,next:`Volgende`,checkRows:`Rijen controleren`,back:`Terug`,checking:`Controleren`,importRows:(e,t)=>`${e} ${t===1?`rij`:`rijen`} importeren`,cancelImport:`Import annuleren`,done:`Klaar`,file:`Bestand`,fileHint:`Een Excel-werkmap (.xlsx) of een CSV-bestand bewaard als UTF-8. De eerste rij noemt de kolommen.`,reading:e=>`${e} lezen…`,theFile:`het bestand`,sheet:`Werkblad`,create:`Maken`,update:`Bijwerken`,upsert:`Maken of bijwerken`,createHint:`Elke rij maakt een record.`,updateHint:`Elke rij werkt het record bij dat haar waarde vindt; een rij die er geen vindt, wordt niet geïmporteerd.`,upsertHint:`Elke rij werkt het record bij dat haar waarde vindt, of maakt er een als ze er geen vindt.`,doNotImport:`Niet importeren`,rows:`Rijen`,whatEachRowDoes:`Wat elke rij doet`,findBy:`Records vinden op`,chooseField:`Kies een veld`,findByHint:`Een veld dat geen twee records delen, zoals de sleutel of een e-mailadres.`,foundInColumn:`Gevonden in kolom`,chooseColumn:`Kies een kolom`,numbers:`Getallen`,dates:`Datums`,dayFirst:`Dag eerst (31/12/2026)`,monthFirst:`Maand eerst (12/31/2026)`,datesHint:`Datums geschreven als 2026-12-31 lezen hoe dan ook hetzelfde. Tijden zonder zone zijn in je eigen tijd.`,requiredMarked:`Nieuwe records hebben de velden met * nodig.`,columns:`Kolommen`,emptyInFirstRows:`Leeg in de eerste rijen`,field:`Veld`,fieldFor:e=>`Veld voor ${e}`,foundBy:`Gevonden op`,pluralFoundBy:e=>`${e} gevonden op`,noColumnFills:e=>`Geen kolom vult ${e}, wat nieuwe records nodig hebben.`,rowsNotImported:`Niet geïmporteerde rijen`,rowProblems:e=>`Rij ${e}:`,andMore:e=>`En nog ${e} rijen, allemaal in het bestand.`,checkingRows:e=>`Rijen controleren… ${e} gelezen`,check:`Controle`,toCreate:`Te maken`,toUpdate:`Bij te werken`,withProblems:`Met problemen`,firstRows:`Eerste rijen`,row:`Rij`,problemRows:`Rijen met problemen, die worden overgeslagen`,download:`Downloaden`,batches:e=>`Rijen worden bewaard in groepen van ${e}. Annuleren, of een fout, houdt de groepen die al bewaard zijn; een rij die de server weigert, wordt vermeld en de andere worden bewaard.`,stopping:`Stoppen na deze groep…`,saving:`Rijen bewaren…`,rowsSaved:`Bewaarde rijen`,stopped:`De import is gestopt. De rijen die hieronder zijn geteld, zijn bewaard.`,cancelled:`Geannuleerd. De rijen die hieronder zijn geteld, zijn bewaard.`,summary:`Samenvatting van de import`,created:`Gemaakt`,updated:`Bijgewerkt`,skipped:`Overgeslagen`,failed:`Mislukt`,notWrittenHint:`Overgeslagen rijen hadden problemen in het bestand; de mislukte weigerde de server. Het bestand bevat elke rij met de reden, om te verbeteren en opnieuw te importeren.`,notImportedFile:e=>`${e} - niet geïmporteerd.csv`,line:`Regel`,problems:`Problemen`,notNumber:e=>`${e} is geen getal`,notWholeNumber:e=>`${e} is geen geheel getal`,tooLarge:e=>`${e} is te groot`,notBoolean:e=>`${e} is niet waar of onwaar (true, false, yes, no, 1 of 0)`,notDate:(e,t)=>`${e} is geen datum (2026-04-03 of ${t?`dag/maand/jaar`:`maand/dag/jaar`})`,hasTime:e=>`${e} heeft een tijd van de dag; het veld bevat een datum`,severalValues:(e,t)=>`${e} past bij meer dan één waarde: ${t}`,notOneOf:(e,t)=>`${e} is niet een van ${t}`,notText:e=>`${e} is waar of onwaar, geen tekst`,emptyRequired:`is leeg, en is verplicht`,noneHas:(e,t)=>`geen ${e.toLowerCase()} heeft ${t}`,severalHave:(e,t,n)=>`${e} ${t.toLowerCase()} hebben ${n}`,notOneRecord:e=>`Niet één record: ${e}`,nothingToUpdate:e=>`Niets om bij te werken: ${e}`,fileNotUtf8:`Het bestand is geen UTF-8-tekst. Bewaar het als "CSV UTF-8" en kies het opnieuw.`,noSheets:`De werkmap heeft geen werkbladen`,missingSheetPart:`De werkmap noemt een werkblad dat er niet in zit`,notZip:`Het bestand is geen Excel-werkmap (.xlsx): het is geen ZIP-archief`,zip64:`De werkmap is te groot om te lezen: het is een ZIP64-archief`,compression:(e,t)=>`Het deel ${e} van de werkmap is gecomprimeerd op een manier die niet kan worden gelezen (methode ${t})`,notWorkbook:e=>`Het bestand is geen Excel-werkmap (.xlsx): het heeft geen ${e}`,noSheetCalled:e=>`De werkmap heeft geen werkblad met de naam ${e}`,unreadable:`Het bestand kon niet worden gelezen`,column:e=>`Kolom ${e}`}}),lF=e=>typeof e==`object`&&!!e,uF=e=>e===null||typeof e==`string`&&e.trim()===``,dF=e=>e===null?``:lF(e)?e.date.replace(`T`,` `):typeof e==`boolean`?e?`TRUE`:`FALSE`:String(e),fF=e=>e<26?String.fromCharCode(65+e):fF(Math.floor(e/26)-1)+fF(e%26),pF=(e,t)=>e[t]?.trim()?e[t]:$(`column`,fF(t)),mF=e=>/[",\r\n]/.test(e)?`"${e.replace(/"/g,`""`)}"`:e,hF=(e,t)=>{let n=[...t].sort((e,t)=>e.line-t.line).map(t=>[...e.map((e,n)=>dF(t.cells[n]??null)),String(t.line),t.problems.join(`; `)]);return`${[[...e,$(`line`),$(`problems`)],...n].map(e=>e.map(mF).join(`,`)).join(`\r
|
|
7
|
-
`)}\r\n`},gF=({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(Ie())})]},e))}),_F=(e,t)=>e?.fields[t]?.label??F(t),vF=new Set([`text`,`integer`,`bigint`,`decimal`,`boolean`,`date`,`timestamp`,`uuid`,`enum`,`relation`,`currency`,`country`]),yF=(e,t)=>{let n=e.relation?t[e.relation.resource]:void 0;return n?.primaryKey.length===1?n:void 0},bF=(e,t)=>Object.values(e.fields).filter(n=>n.readOnly||n.name===e.tenant||!vF.has(n.type)?!1:n.type!==`relation`||yF(n,t)!==void 0),xF=new Set([`text`,`integer`,`bigint`,`uuid`,`date`,`currency`,`country`,`enum`]),SF=e=>{let t=e.primaryKey.length===1?[e.fields[e.primaryKey[0]]]:[],n=Object.values(e.fields).filter(t=>t.filterable&&!t.sensitive&&xF.has(t.type)&&!e.primaryKey.includes(t.name));return[...t,...n]},CF=(e,t)=>yF(e,t),wF=e=>!e.nullable&&!e.default,TF=e=>e.toLowerCase().replace(/[\s_-]+/g,``),EF=(e,t,n)=>{let r=new Set;return e.flatMap((e,i)=>{let a=TF(e);if(a===``)return[];let o=t.find(e=>!r.has(e.name)&&(TF(_F(n,e.name))===a||TF(e.name)===a));return o?(r.add(o.name),[{column:i,field:o.name}]):[]})},DF=(e,t,n)=>{if(e===`update`)return[];let r=new Set(n.map(e=>e.field));return t.filter(e=>wF(e)&&!r.has(e.name))},OF=e=>({ok:!0,value:e}),kF=e=>({ok:!1,problem:e}),AF=e=>`“${dF(e)}”`,jF=(e,t)=>{if(typeof e==`number`)return String(e);if(typeof e==`string`)return zh(e,t.decimal)},MF=(e,t,n)=>{let r=jF(t,n);if(r===void 0)return kF($(`notNumber`,AF(t)));let[i,a=``]=r.split(`.`);if(/[1-9]/.test(a)||/e/i.test(r))return kF($(`notWholeNumber`,AF(t)));if(e.type===`bigint`)return OF(String(BigInt(i)));let o=Number(i);return Number.isSafeInteger(o)?OF(o):kF($(`tooLarge`,AF(t)))},NF=(e,t)=>{let n=jF(e,t);return n===void 0?kF($(`notNumber`,AF(e))):OF(n)},PF=new Set([`true`,`yes`,`1`]),FF=new Set([`false`,`no`,`0`]),IF=e=>{if(typeof e==`boolean`)return OF(e);let t=typeof e==`string`||typeof e==`number`?String(e).trim().toLowerCase():``;return PF.has(t)?OF(!0):FF.has(t)?OF(!1):kF($(`notBoolean`,AF(e)))},LF=e=>String(e).padStart(2,`0`),RF=(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}-${LF(t)}-${LF(n)}`},zF=`(\\d{1,2}):(\\d{2})(?::(\\d{2})(?:\\.\\d+)?)?`,BF=(e,t)=>{let n=RegExp(`^(\\d{4})[-/](\\d{1,2})[-/](\\d{1,2})(?:[T ]${zF}(Z|[+-]\\d{2}:?\\d{2})?)?$`).exec(e.trim()),r=RegExp(`^(\\d{1,2})[./-](\\d{1,2})[./-](\\d{4})(?: ${zF})?$`).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=RF(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:`${LF(Number(c))}:${l}:${LF(Number(u))}`,zone:n?.[7]}},VF=(e,t)=>{if(lF(e)){let[t,n]=e.date.split(`T`);return{date:t,time:n}}return typeof e==`string`?BF(e,t.dateOrder):void 0},HF=(e,t)=>kF($(`notDate`,AF(e),t.dateOrder===`dmy`)),UF=(e,t)=>{let n=VF(e,t);return n?n.time&&n.time!==`00:00:00`?kF($(`hasTime`,AF(e))):OF(n.date):HF(e,t)},WF=(e,t)=>{let n=VF(e,t);if(!n)return HF(e,t);if(n.zone)return OF(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 OF(new Date(r,i-1,a,o,s,c).toISOString())},GF=e=>e.trim().toLowerCase().replace(/\s+/g,` `),KF=(e,t,n)=>{let r=e.enumValues??[],i=GF(dF(n)),a=r.filter(e=>GF(e)===i||GF(tr(e,t?.valueLabels))===i);return a.length===1?OF(a[0]):a.length>1?kF($(`severalValues`,AF(n),a.map(e=>tr(e,t?.valueLabels)).join(`, `))):kF($(`notOneOf`,AF(n),r.map(e=>tr(e,t?.valueLabels)).join(`, `)))},qF=e=>typeof e==`boolean`?kF($(`notText`,AF(e))):OF(dF(e)),JF=(e,t,n,r)=>{if(uF(n))return e.nullable?OF(null):kF($(`emptyRequired`));switch(e.type){case`integer`:case`bigint`:return MF(e,n,r);case`decimal`:return NF(n,r);case`boolean`:return IF(n);case`date`:return UF(n,r);case`timestamp`:return WF(n,r);case`enum`:return KF(e,t,n);case`text`:case`uuid`:case`currency`:case`country`:return qF(n);default:throw Error(`Not implemented: importing ${e.type} fields, which importableFields leaves out`)}},YF=(e,t)=>e[t]?.names?.singular??F(t),XF=(e,t)=>e[t]?.names?.plural??F(t),ZF=(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=_F(o,d),g=CF(p,i);if(g&&!uF(m)){let e=f??g.primaryKey[0],n=JF(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]=dF(m);continue}let _=JF(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=JF({...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(`${_F(o,n.name)}: ${i.problem}`)}return{values:s,data:c,problems:l,relations:u,match:d}},QF=(e,t)=>{let n=e.lookups.keysOf(t.model.name,t.field,t.value),r=`${_F(e.views[t.model.name],t.field).toLowerCase()} “${String(t.value)}”`;return n.length===1?{key:n[0]}:n.length===0?{none:$(`noneHas`,YF(e.views,t.model.name),r)}:{several:$(`severalHave`,n.length,XF(e.views,t.model.name),r)}},$F=e=>e.cells.every(uF),eI=async(e,t,n)=>{let{model:r,views:i}=n,a=e.filter(e=>!$F(e)).map(e=>({row:e,...ZF(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=QF(n,t);`key`in a?u[e]=a.key:s.push(`${_F(i[r.name],e)}: ${a.none??a.several}`)}let d=l&&QF(n,l);d?.several&&s.push($(`notOneRecord`,d.several)),d?.none&&t.mode===`update`&&s.push($(`nothingToUpdate`,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}}})},tI=5,nI=5,rI=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(dF),sample:a.slice(0,tI)}};async function*iI(e,t){let n=!0;for await(let r of e.rows(t))yield n?r.slice(1):r,n=!1}var aI=async(e,t,n,r,i,a)=>{let o={rows:0,creates:0,updates:0,problems:[],preview:[]};for await(let s of iI(e,t)){a?.throwIfAborted();for(let e of await eI(s,n,r))o.rows++,o.preview.length<nI&&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},oI=(e,t)=>{if(!jc(e))return[e.message];let n=e.errors.filter(e=>e.field);return n.length===0?[e.message]:n.map(e=>`${_F(t.views[t.model.name],e.field)}: ${e.message}`)},sI=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=jc(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:oI(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 iI(e,t)){for(let e of await eI(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}},cI=50,lI=(e,t,n)=>CA(hF(t,n),$(`notImportedFile`,(e??`import`).replace(/\.[^.]+$/,``)),`text/csv`),uI=({rows:e})=>(0,B.jsxs)(`ul`,{"aria-label":$(`rowsNotImported`),className:`flex flex-col gap-1 text-body`,children:[e.slice(0,cI).map(e=>(0,B.jsxs)(`li`,{children:[(0,B.jsx)(`span`,{className:`font-medium`,children:$(`rowProblems`,e.line)}),` `,e.problems.join(`; `)]},e.line)),e.length>cI&&(0,B.jsx)(`li`,{className:`text-muted-foreground`,children:$(`andMore`,(e.length-cI).toLocaleString(Ie()))})]}),dI=({rows:e})=>(0,B.jsxs)(`p`,{className:`flex items-center gap-2 text-muted-foreground`,role:`status`,children:[(0,B.jsx)(Yu,{className:`size-3.5`}),$(`checkingRows`,e.toLocaleString(Ie()))]}),fI=({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)(gF,{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:_F(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:CF(t,n)?String(e.values[t.name]??`—`):t.name in e.values?bm(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:()=>lI(o,a,e.problems),children:[(0,B.jsx)(Bi,{className:`size-3.5`}),$(`download`)]})]}),(0,B.jsx)(uI,{rows:e.problems})]}),(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:$(`batches`,100)})]})},pI=({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})]})},mI=({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)(Yu,{className:`size-3.5`}),$(`reading`,e?.name??$(`theFile`))]}),!r&&t.length>1&&(0,B.jsxs)(`div`,{className:`flex items-end gap-3`,children:[(0,B.jsx)(na,{className:`mb-2 size-4 shrink-0 text-muted-foreground`}),(0,B.jsx)(pI,{className:`flex-1`,label:$(`sheet`),value:n??``,options:t.map(e=>({value:e,label:e})),onChange:a})]})]})},hI=()=>[{value:`create`,label:$(`create`)},{value:`update`,label:$(`update`)},{value:`upsert`,label:$(`upsert`)}],gI={create:`createHint`,update:`updateHint`,upsert:`upsertHint`},_I=``,vI=({flow:e,model:t,resources:n,views:r,canUpdate:i})=>{let a=r[t.name],o=e.head?.headers??[],s=e.head?.sample??[],c=DF(e.mode,e.fields,e.columns),l=[{value:_I,label:$(`doNotImport`)},...e.fields.map(e=>({value:e.name,label:`${_F(a,e.name)}${wF(e)?` *`:``}`}))],u=o.map((e,t)=>({value:String(t),label:pF(o,t)})),d=SF(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)(Le,{label:$(`whatEachRowDoes`),size:`md`,value:e.mode,options:hI(),onChange:e.setMode})}),(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:$(gI[e.mode])})]}),e.mode!==`create`&&(0,B.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2`,children:[(0,B.jsx)(pI,{label:$(`findBy`),value:e.match?.field??_I,options:[{value:_I,label:$(`chooseField`)},...d.map(e=>({value:e.name,label:_F(a,e.name)}))],onChange:t=>e.setMatch(t?{field:t,column:e.match?.column??0}:void 0),help:$(`findByHint`)}),(0,B.jsx)(pI,{label:$(`foundInColumn`),value:e.match?String(e.match.column):_I,options:[{value:_I,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)(pI,{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)(pI,{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?CF(d,n):void 0,p=s.map(e=>dF(e.cells[c]??null)).filter(e=>e!==``).slice(0,3),m=pF(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)(pI,{label:$(`field`),name:$(`fieldFor`,m),value:u?.field??_I,options:l,onChange:t=>e.mapColumn(c,t||void 0)}),f&&(0,B.jsx)(pI,{label:$(`foundBy`),name:$(`pluralFoundBy`,r[f.name]?.names?.plural??_F(a,d.name)),value:u.matchBy??f.primaryKey[0],options:SF(f).map(e=>({value:e.name,label:_F(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)(ys,{className:`mt-0.5 size-4 shrink-0`}),(0,B.jsx)(`span`,{children:$(`noColumnFills`,c.map(e=>_F(a,e.name)).join(`, `))})]})]})},yI=e=>e.toLocaleString(Ie()),bI=({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:[yI(r),` / `,yI(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}%`}})})]})},xI=({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)(pg,{title:$(`stopped`),error:t}),e.cancelled&&(0,B.jsx)(`p`,{role:`status`,children:$(`cancelled`)}),(0,B.jsx)(gF,{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:()=>lI(r,n,e.notWritten),children:[(0,B.jsx)(Bi,{className:`size-3.5`}),$(`download`)]})]}),(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:$(`notWrittenHint`)}),(0,B.jsx)(uI,{rows:[...e.notWritten].sort((e,t)=>e.line-t.line)})]})]}),SI=e=>{let t=Lh(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`}},CI=on(),wI=100,TI=e=>String(e),EI=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(TI(e))).map(e=>[TI(e),e])).values()],s=t.primaryKey[0];for(let n=0;n<o.length;n+=wI){let i=o.slice(n,n+wI);for(let e of i)a.set(TI(e),[]);let c=Jt(CI.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(TI(e[r]))?.push(e[s]);l=n.nextPageToken||void 0}while(l)}},keysOf:(e,t,r)=>n(e,t).get(TI(r))??[]}},DI=500,OI=()=>{let e=new Worker(new URL(`/assets/parse-worker-UhbwEjS0.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()}},kI=e=>({sheets:async()=>{let t=OI();try{t.send({type:`sheets`,file:e,locale:ze()});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=OI();try{for(n.send({type:`read`,file:e,sheet:t,chunk:DI,locale:ze()});;){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()}}}),AI={created:0,updated:0,skipped:0,failed:0,notWritten:[]},jI=({model:e,resources:t,views:n,sourceFor:r=kI})=>{let i=Pu(),a=be(),o=n[e.name],s=(0,I.useMemo)(()=>bF(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)(()=>SI()),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 rI(t,n);_(r),x(EF(r.headers,s,o));let i=SF(e)[0],a=i?EF(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:EI(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}),aI(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:AI,total:t,cancelling:!1});let n=AI;sI(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()}},MI=e=>e.step.kind===`file`?$(`couldNotReadFile`):$(`couldNotCheck`),NI=e=>e.columns.length===0?!1:e.mode===`create`?DF(`create`,e.fields,e.columns).length===0:e.match!==void 0,PI=({model:e,resources:t,views:n,canUpdate:r,onClose:i,sourceFor:a})=>{let o=jI({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)(xd,{open:!0,wide:!0,title:$(`importPlural`,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:!NI(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`,e.toLocaleString(Ie()),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)(pg,{title:MI(o),error:o.error}),(()=>{switch(c.kind){case`file`:return(0,B.jsx)(mI,{file:o.file,sheets:o.sheets,sheet:o.sheet,reading:c.reading,onChoose:o.choose,onSheet:o.setSheet});case`map`:return(0,B.jsx)(vI,{flow:o,model:e,resources:t,views:n,canUpdate:r});case`checking`:return(0,B.jsx)(dI,{rows:c.rows});case`checked`:return(0,B.jsx)(fI,{check:c.check,model:e,resources:t,views:n,columns:o.columns,headers:l,fileName:o.file?.name});case`importing`:return(0,B.jsx)(bI,{progress:c.progress,total:c.total,cancelling:c.cancelling});case`done`:return(0,B.jsx)(xI,{result:c.result,stopped:c.stopped,headers:l,fileName:o.file?.name})}})()]})})},FI=({model:e})=>{let{resources:t,views:n}=W(),r=ed(e.name),[i,a]=(0,I.useState)(!1);return n[e.name]?.import===!1||!V_(r,`create`)?null:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(G,{onClick:()=>a(!0),"aria-haspopup":`dialog`,children:[(0,B.jsx)(Cs,{className:`size-3.5`}),$(`import`)]}),i&&(0,B.jsx)(PI,{model:e,resources:t,views:n,canUpdate:V_(r,`update`),onClose:()=>a(!1)})]})},II=M({en:{excel:`Excel (.xlsx)`,csv:`CSV`,asShown:`As shown`,rawValues:`Raw values`,shownHint:`Labels, dates and numbers as the list shows them.`,rawHint:`Values as they are stored, such as keys and codes.`,counting:`Counting rows…`,moreThan:`more than 10,000 rows`,columns:`Columns`,moveUp:e=>`Move ${e} up`,moveDown:e=>`Move ${e} down`,selectedRows:(e,t)=>`${e} selected ${t===1?`row`:`rows`}`,rowsInList:`Rows in the list`,selected:e=>`Selected (${e})`,exportPlural:e=>`Export ${e.toLowerCase()}`,cancel:`Cancel`,export:`Export`,format:`Format`,rows:`Rows`,listHint:`With the list’s filters, search and sort.`,values:`Values`,exports:e=>`Exports ${e}.`,overLimit:e=>` A file holds at most ${e} rows; the rest are left out.`,exporting:e=>`Exporting ${e.toLowerCase()}`,rowsExported:`Rows exported`,doneOf:(e,t)=>`${e} of ${t} rows`,done:e=>`${e} rows`,exported:(e,t)=>`Exported ${e} ${t.toLowerCase()}`,truncated:(e,t)=>`${e}: the first ${t} rows, as many as a file holds.`,couldNotExport:e=>`Could not export ${e.toLowerCase()}`,cancelled:`The export was cancelled`,couldNotBuild:e=>`The export could not be built: ${e}`,workbook:`Excel workbook`,csvFile:`CSV file`},nl:{excel:`Excel (.xlsx)`,csv:`CSV`,asShown:`Zoals getoond`,rawValues:`Ruwe waarden`,shownHint:`Labels, datums en getallen zoals de lijst ze toont.`,rawHint:`Waarden zoals ze zijn opgeslagen, zoals sleutels en codes.`,counting:`Rijen tellen…`,moreThan:`meer dan 10.000 rijen`,columns:`Kolommen`,moveUp:e=>`${e} omhoog`,moveDown:e=>`${e} omlaag`,selectedRows:(e,t)=>`${e} geselecteerde ${t===1?`rij`:`rijen`}`,rowsInList:`Rijen in de lijst`,selected:e=>`Geselecteerd (${e})`,exportPlural:e=>`${e} exporteren`,cancel:`Annuleren`,export:`Exporteren`,format:`Formaat`,rows:`Rijen`,listHint:`Met de filters, zoekopdracht en sortering van de lijst.`,values:`Waarden`,exports:e=>`Exporteert ${e}.`,overLimit:e=>` Een bestand bevat hoogstens ${e} rijen; de rest blijft weg.`,exporting:e=>`${e} exporteren`,rowsExported:`Geëxporteerde rijen`,doneOf:(e,t)=>`${e} van ${t} rijen`,done:e=>`${e} rijen`,exported:(e,t)=>`${e} ${t.toLowerCase()} geëxporteerd`,truncated:(e,t)=>`${e}: de eerste ${t} rijen, zoveel als een bestand bevat.`,couldNotExport:e=>`Kon ${e.toLowerCase()} niet exporteren`,cancelled:`De export is geannuleerd`,couldNotBuild:e=>`De export kon niet worden gemaakt: ${e}`,workbook:`Excel-werkmap`,csvFile:`CSV-bestand`}}),LI=()=>new DOMException(II(`cancelled`),`AbortError`),RI=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:ze()}));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 LI();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 zI(s,c),{rows:f,truncated:g.length<h.items.length||m!==``||i+1<n.length}}while(m!==``)}return await zI(s,c),{rows:f,truncated:!1}}catch(e){throw await c.abort(),e}finally{s.close()}},zI=async(e,t)=>{await t.write(await e.send({kind:`finish`})),await t.close()},BI=1048575,VI=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
8
|
-
`,HI=`http://schemas.openxmlformats.org/officeDocument/2006/relationships`,UI=`http://schemas.openxmlformats.org/package/2006/relationships`;`${VI}`,`${VI}${UI}${HI}`,`${VI}${UI}${HI}${HI}`,new TextEncoder;var WI=on(),GI=e=>e?.export!==!1,KI=e=>Object.values(e.fields).flatMap(e=>e.sensitive?[]:[e.name]),qI=(e,t)=>{let n=new Set(KI(e));return mr(e,t).filter(e=>n.has(e))},JI=(e,t,n)=>Object.fromEntries(vm(e,t,[],n).map(e=>[e.id,e.header])),YI=(e,t,n)=>{let r=JI(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]??{}}]:[]})},XI=(e,t)=>{let n=e?.export?e.export.maxRows??1/0:1/0;return Math.min(n,t===`xlsx`?BI:1/0)},ZI=e=>e.primaryKey.length===1,QI=(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(Jt(WI.in(n,t.slice(e,e+500))));return r},$I=()=>{let e=new Worker(new URL(`/assets/export-worker-3e4Zsv0a.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(II(`couldNotBuild`,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()}},eL=()=>[{value:`xlsx`,label:II(`excel`)},{value:`csv`,label:II(`csv`)}],tL=()=>[{value:`shown`,label:II(`asShown`)},{value:`raw`,label:II(`rawValues`)}],nL={shown:`shownHint`,raw:`rawHint`},rL=e=>e.kind===`counting`?II(`counting`):e.kind===`exact`||e.rows>1e4?Wd(e.rows):II(`moreThan`),iL=e=>{if(e.kind!==`counting`)return e.kind===`exact`?e.rows:Math.max(e.rows,10001)},aL=({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})]}),oL=(e,t,n)=>{let r=e.indexOf(t),i=[...e];return i.splice(r,1),i.splice(r+n,0,t),i},sL=({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":II(`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)(Rx,{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":II(`moveUp`,r[e]),disabled:a===0,onClick:()=>n(oL(t,e,-1)),children:(0,B.jsx)(Or,{className:`size-3.5`})}),(0,B.jsx)(G,{size:`sm`,variant:`ghost`,className:`min-h-8 px-2`,"aria-label":II(`moveDown`,r[e]),disabled:a===t.length-1,onClick:()=>n(oL(t,e,1)),children:(0,B.jsx)(vr,{className:`size-3.5`})})]})]},e)})})},cL=({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`),_=XI(t,l),v=d===`selected`?II(`selectedRows`,Vd(a??0),a??0):rL(i),y=(d===`selected`?a??0:iL(i)??0)>_,b=[{value:`list`,label:II(`rowsInList`)},{value:`selected`,label:II(`selected`,Vd(a??0))}];return(0,B.jsx)(xd,{title:II(`exportPlural`,e),open:o,onClose:c,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:c,children:II(`cancel`)}),(0,B.jsx)(G,{variant:`primary`,disabled:p.length===0,onClick:()=>s({format:l,scope:d,columns:p,mode:h}),children:II(`export`)})]}),children:(0,B.jsxs)(`div`,{className:`flex flex-col gap-4 text-body`,children:[(0,B.jsx)(aL,{label:II(`format`),children:(0,B.jsx)(Le,{size:`md`,label:II(`format`),value:l,options:eL(),onChange:u})}),a!==void 0&&a>0&&(0,B.jsx)(aL,{label:II(`rows`),help:d===`list`?II(`listHint`):void 0,children:(0,B.jsx)(Le,{size:`md`,label:II(`rows`),value:d,options:b,onChange:f})}),(0,B.jsx)(aL,{label:II(`values`),help:II(nL[h]),children:(0,B.jsx)(Le,{size:`md`,label:II(`values`),value:h,options:tL(),onChange:g})}),(0,B.jsx)(aL,{label:II(`columns`),children:(0,B.jsx)(sL,{fields:n,columns:p,onChange:m})}),(0,B.jsxs)(`p`,{role:`status`,className:`text-muted-foreground`,children:[II(`exports`,v),y&&II(`overLimit`,Vd(_))]})]})})},lL=({plural:e,done:t,total:n,onCancel:r})=>{let i=n?Math.min(1,t/n):void 0;return(0,B.jsx)(xd,{title:II(`exporting`,e),open:!0,onClose:r,actions:(0,B.jsx)(G,{onClick:r,children:II(`cancel`)}),children:(0,B.jsxs)(`div`,{className:`flex flex-col gap-2 text-body`,children:[(0,B.jsx)(`div`,{role:`progressbar`,"aria-label":II(`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?II(`doneOf`,Vd(t),Vd(n)):II(`done`,Vd(t))})]})})},uL={xlsx:{mime:`application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`,extension:`.xlsx`,description:`workbook`},csv:{mime:`text/csv`,extension:`.csv`,description:`csvFile`}},dL=/[\\/:*?"<>|\u0000-\u001f]/g,fL=(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(dL,` `).trim()} ${r}${uL[t].extension}`},pL=8e6,mL=(e,t)=>{let n=new Blob([],{type:uL[t].mime}),r=[],i=0,a=()=>{n=new Blob([n,...r],{type:uL[t].mime}),r=[],i=0};return{write:async e=>{e.length!==0&&(r.push(e),i+=e.length,i>=pL&&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([])}}},hL=()=>globalThis.showSaveFilePicker,gL=()=>typeof hL()==`function`,_L=async(e,t)=>{let n=hL();if(!n)throw Error(`This browser cannot save a file as it is built`);let r=uL[t],i;try{i=await n({suggestedName:e,types:[{description:II(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()}},vL=(e,t)=>gL()?_L(e,t):Promise.resolve(mL(e,t)),yL=(e,t)=>{let n=t[e.primaryKey[0]];return typeof n==`object`&&n&&`id`in n?n.id:n},bL=({model:e,view:t,resources:n,views:r,plural:i,filter:a,orderBy:o,createPort:s=$I,createSink:c=vL})=>{let l=U(),u=Gf(),[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:ZI(e)?t.map(t=>yL(e,t)):[]}),g=async(d,h)=>{let g=fL(i,d.format),_=await c(g,d.format);if(!_)return;let v=XI(t,d.format),y=d.scope===`selected`?h.length:iL(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 RI({client:l,resource:e.name,filters:d.scope===`selected`?QI(e,h):[a],orderBy:o,plan:{format:d.format,mode:d.mode,name:i,columns:YI(e,t,d.columns)},labels:d.mode===`shown`?iy(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:II(`exported`,Vd(c.rows),i),description:c.truncated?II(`truncated`,g,Vd(c.rows)):g})}catch(e){if(e instanceof DOMException&&e.name===`AbortError`)return;if(!jc(e))throw e;u.show({state:`error`,title:II(`couldNotExport`,i),description:e.message})}finally{p.current=void 0,f(e=>e.kind===`running`?{kind:`closed`}:e)}},_=()=>{p.current?.abort(),f({kind:`closed`})},v=KI(e),y=JI(e,t,v);return{open:h,dialogs:d.kind===`settings`?(0,B.jsx)(cL,{plural:i,view:t,fields:v.map(e=>({name:e,label:y[e]})),initialColumns:qI(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)(lL,{plural:i,done:d.done,total:d.total,onCancel:_}):null}},xL=M({en:{noList:e=>`There is no list called ${e}.`,searchPlural:e=>`Search ${e.toLowerCase()}`,search:`Search`,sort:`Sort`,filters:`Filters`,filtersCount:e=>`Filters (${e})`,newRecord:e=>`New ${e.toLowerCase()}`,export:`Export`,openRecord:e=>`Open ${e.toLowerCase()}`,delete:`Delete`,exportCount:e=>`Export ${e}`,deleteCount:e=>`Delete ${e}`,actionCount:(e,t)=>`${e} (${t})`,dragToSort:`Drag a row by its handle to move it. Every move is saved as you drop it.`,unreadableFilter:`The filter in the address could not be read`,couldNotLoadRows:`Could not load rows`,created:e=>`${e} created`,noMatchSearch:(e,t)=>`No ${e.toLowerCase()} match “${t}”.`,noMatchFilters:e=>`No ${e.toLowerCase()} match these filters.`,noMatch:e=>`No ${e.toLowerCase()} match.`,noneYet:e=>`No ${e.toLowerCase()} yet.`,clearSearch:`Clear search`,clearFilters:`Clear filters`},nl:{noList:e=>`Er is geen lijst met de naam ${e}.`,searchPlural:e=>`Zoeken in ${e.toLowerCase()}`,search:`Zoeken`,sort:`Sorteren`,filters:`Filters`,filtersCount:e=>`Filters (${e})`,newRecord:e=>`${e} toevoegen`,export:`Exporteren`,openRecord:e=>`${e} openen`,delete:`Verwijderen`,exportCount:e=>`${e} exporteren`,deleteCount:e=>`${e} verwijderen`,actionCount:(e,t)=>`${e} (${t})`,dragToSort:`Sleep een rij aan de greep om hem te verplaatsen. Elke verplaatsing wordt bewaard zodra je loslaat.`,unreadableFilter:`Het filter in het adres kon niet worden gelezen`,couldNotLoadRows:`Kon de rijen niet laden`,created:e=>`${e} aangemaakt`,noMatchSearch:(e,t)=>`Geen ${e.toLowerCase()} gevonden voor “${t}”.`,noMatchFilters:e=>`Geen ${e.toLowerCase()} gevonden met deze filters.`,noMatch:e=>`Geen ${e.toLowerCase()} gevonden.`,noneYet:e=>`Nog geen ${e.toLowerCase()}.`,clearSearch:`Zoekopdracht wissen`,clearFilters:`Filters wissen`}}),SL=({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:xL(`clearSearch`)}),e.clearFilters&&(0,B.jsx)(G,{onClick:n,children:xL(`clearFilters`)}),e.create&&r]})]}),CL=({plural:e,search:t,filtered:n,scoped:r,canCreate:i})=>t?{message:xL(`noMatchSearch`,e,t),clearSearch:!0,clearFilters:n,create:!1}:n?{message:xL(`noMatchFilters`,e),clearSearch:!1,clearFilters:!0,create:!1}:r?{message:xL(`noMatch`,e),clearSearch:!1,clearFilters:!1,create:!1}:{message:xL(`noneYet`,e),clearSearch:!1,clearFilters:!1,create:i},wL=(e,t)=>{},TL=({windowMs:e=1e3,comebacks:t=2,onHold:n=wL}={})=>{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}},EL=e=>Math.max(1,Math.floor((e+12)/252)),DL=(e,t)=>Math.max(0,(e-(t-1)*12)/t),OL=(e,t,n,r)=>({start:e*n,end:Math.max(0,Math.min(r,(t+1)*n)-1)}),kL=(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},AL=(e,t)=>{let n=e/t.rowHeight;return Math.floor(n)*t.columns+n%1},jL=(e,t)=>Math.floor(Math.floor(e)/t)+e%1,ML=8,NL=(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<=ML)break;i.delete(e)}return i},PL=({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=EL(c),d=DL(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?kL(_.current.top,_.current.layout,g):e,b=d>0&&f.has(d),x=vS({total:Math.ceil(o/u),rowHeight:h,initialIndex:jL(s,u),settle:y,ready:b,onScroll:e=>r(AL(e,g))});(0,I.useLayoutEffect)(()=>{v&&x.scrollTo(x.top),_.current={layout:g,top:x.top}});let S=OL(x.first,x.last,u,o),C=iS({total:o,rowAt:e.rowAt,loadRows:e.loadRows,revision:e.revision,latencyMs:0},S.start,S.end),[w]=(0,I.useState)(()=>TL());(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=>NL(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)(K,{className:`h-full rounded-lg`})},`skeleton-${i}`)}))})},FL=`grid grid-cols-[repeat(auto-fill,minmax(15rem,1fr))] gap-3`,IL=e=>e*.75,LL=44,RL=({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 ${FL}`,children:Array.from({length:6},(e,t)=>(0,B.jsx)(K,{className:`h-24`},t))}):r.error?(0,B.jsx)(pg,{title:q(`couldNotLoadRows`),error:r.error}):!r.source||r.source.total===0?i??(0,B.jsx)(`p`,{className:`py-8 text-center text-muted-foreground`,children:q(`noneMatch`,a.toLowerCase())}):(0,B.jsx)(PL,{source:r.source,label:a,initialIndex:r.initialIndex,onScrollIndex:r.onScrollIndex,minHeight:e=>(o?IL(e):0)+LL,children:r=>(0,B.jsx)(uT,{model:e,view:t,display:n,row:Zm(e,r)})})},zL=`protobase:list-places`,BL=50,VL=(e,t)=>`${e} ${t}`,HL=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},UL=e=>Fe(()=>{let t=e.getItem(zL);if(t===null)return[];let n=JSON.parse(t);return Array.isArray(n)?n.filter(HL):[]},[]),WL=e=>{let t=new Map(UL(e).map(e=>[VL(e.entry,e.url),e]));return{placeOf:(e,n)=>{let r=t.get(VL(e,n));return r?r.place:[...t.values()].findLast(e=>e.url===n)?.place??0},save:(e,n,r)=>{let i=VL(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-BL)))t.delete(e)},persist:()=>Fe(()=>e.setItem(zL,JSON.stringify([...t.values()])),void 0)}},GL={getItem:()=>null,setItem:()=>{}},KL,qL=()=>KL??=WL(Fe(()=>window.sessionStorage,void 0)??GL),JL=()=>{let{entry:e,path:t,params:n}=mh(),r=`${t}?${n.toString()}`,i=qL();(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}},YL=e=>e.reduce((e,t)=>e+t.count,0),XL=e=>{let t=Math.floor(e.length/2),n=YL(e.slice(0,t)),r=YL(e.slice(e.length-t));return n===0?0:(r-n)/n*100},ZL=({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:lf(r.at)}),(0,B.jsxs)(`div`,{className:`font-semibold tabular-nums`,children:[Vd(r.count),` `,n]})]})},QL=M({en:{day:`Day`,week:`Week`},nl:{day:`Dag`,week:`Week`}}),$L={fontSize:11,fill:`var(--muted-foreground)`},eR=({title:e=`Orders created`,noun:t=`orders`,defaultGranularity:n=`day`,data:r,granularity:i,onGranularityChange:a,periodLabel:o,className:s})=>{let[c,l]=(0,I.useState)(n),u=i??c,d=a??l,f=r??Nd(u),p=ud(`(min-width: 640px)`),m=XL(f);return(0,B.jsxs)(`section`,{className:P(`rounded-lg border bg-background px-4 pb-2 pt-3`,s),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:Vd(YL(f))}),(0,B.jsxs)(`span`,{className:P(`text-xs font-medium tabular-nums`,m>=0?`text-success-text`:`text-danger-text`),children:[m>=0?`+`:`−`,Math.abs(m).toFixed(1),`%`]}),(0,B.jsx)(`span`,{className:`hidden text-xs text-muted-foreground sm:inline`,children:o??`last ${u===`day`?`30 days`:`12 weeks`}`})]}),(0,B.jsx)(Le,{value:u,onChange:d,options:[{value:`day`,label:QL(`day`)},{value:`week`,label:QL(`week`)}]})]}),(0,B.jsx)(`div`,{className:`mt-2 h-24`,children:(0,B.jsx)(ne,{width:`100%`,height:`100%`,children:(0,B.jsxs)(De,{data:f,margin:{top:4,right:0,bottom:0,left:0},barCategoryGap:u===`day`?`22%`:`30%`,children:[(0,B.jsx)(se,{vertical:!1,stroke:`var(--border)`}),(0,B.jsx)(ye,{dataKey:`at`,padding:{left:4,right:p?4:18},tickFormatter:uf,tick:$L,axisLine:!1,tickLine:!1,interval:u===`day`?p?4:9:p?1:3,height:18}),(0,B.jsx)(oe,{width:p?36:28,tick:$L,axisLine:!1,tickLine:!1,tickCount:3}),(0,B.jsx)(je,{cursor:{fill:`var(--muted)`},content:(0,B.jsx)(ZL,{noun:t}),isAnimationActive:!1}),(0,B.jsx)(me,{dataKey:`count`,fill:`var(--primary)`,radius:[2,2,0,0],isAnimationActive:!1})]})})})]})},tR={"7d":`last 7 days`,"30d":`last 30 days`,"90d":`last 90 days`,"1y":`last year`,all:`all time`},nR=({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=_v(e,{field:t.field,range:s,granularity:a,filter:i,timeZone:Gd()}).data?.points.map(e=>({at:Date.parse(`${e.bucket}Z`),count:e.count}))??[];return(0,B.jsx)(eR,{title:n,noun:r,data:c,granularity:a,onGranularityChange:o,periodLabel:a===`week`?`last 12 weeks`:tR[s]})},rR=(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?J(`average`,i):`${i}`},iR=({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":`${rR(n,t,r)} by ${a.toLowerCase()}`,children:[(0,B.jsxs)(`h2`,{className:`mb-2 font-semibold`,children:[rR(n,t,r),` by `,a.toLowerCase()]}),(0,B.jsx)($v,{model:e,view:t,groupBy:n.groupBy,type:n.type,sum:n.sum,average:n.average,limit:n.limit,filter:i})]})},aR=({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)(Xf,{wrapperClassName:P(`min-w-0 flex-1 sm:w-72 sm:flex-initial`,r),leading:(0,B.jsx)(jo,{className:`size-4`}),placeholder:n,"aria-label":xL(`search`),value:i,onChange:e=>a(e.target.value),onKeyDown:e=>e.key===`Enter`&&t(i)})},oR=e=>new Set((e.userMenu?.items??[]).flatMap(e=>e.kind===`resource`?[e.resource]:e.kind===`page`?[e.page]:[])),sR=(e,t,n)=>(e.userMenu?.items??[]).map((r,i)=>{if(r.kind===`link`)return{id:`link-${i}`,label:r.label,icon:MP(r.icon,Ji),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:MP(r.icon??i?.icon,wa),href:ic({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:MP(r.icon,AP(r.resource)),href:ic({kind:`list`,resource:r.resource},t),active:r.resource===n}}),cR=(e,t)=>t===void 0?e:`${e}/${t}`,lR={sales:`sales`,crm:`crm`,catalog:`catalog`,inventory:`inventory`,core:`admin`,hr:`hr`},uR=(e=`public`)=>e===`public`?``:lR[e]?J(lR[e]):F(e),dR=(e,t=``,n={})=>{let r=new Map,i=new Map,a=oR(e);for(let n of Object.values(e.pages)){if(n.nav?.hidden||a.has(n.name))continue;let e=n.nav?.group??J(`pages`),o=r.get(e)??{label:e,items:[]};o.items.push({id:n.name,label:n.title,icon:MP(n.icon,wa),href:ic({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??uR(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:cR(o.name),label:s.names?.plural??F(o.name),icon:AP(o.name),href:ic({kind:`list`,resource:o.name},t),...n[o.name]&&{recent:n[o.name]}},s.nav?.order);for(let e of s.lists??[])e.nav?.hidden||l(e.nav?.group??c,{id:cR(o.name,e.name),label:e.names.plural,icon:AP(o.name),href:ic({kind:`list`,resource:o.name,list:e.name},t)},e.nav?.order)}for(let n of Object.values(e.signIn??{})){if(n.nav?.hidden||a.has(n.resource))continue;let e=n.nav?.group??J(`account`),o=r.get(e)??{label:e,items:[]};o.items.push({id:n.resource,label:n.names?.plural??F(n.resource),icon:AP(n.resource),href:ic({kind:`list`,resource:n.resource},t)}),r.set(e,o),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:AP(r),href:ic({kind:`list`,resource:r},t),problem:J(`cannotReach`,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))}))},fR=(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 mr(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:Fp(c,!1),sortable:!1,render:e=>(0,B.jsx)(Uw,{column:n,records:e[n.name]??[],target:s,view:i[s.name],Card:uT})}]})},pR=({model:e,view:t,target:n,children:r})=>{let i=Ew(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)(Fb,{title:a,subtitle:t.help}),e]});if(i.error)return o((0,B.jsx)(pg,{title:Dw(`couldNotLoadYour`,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)(K,{className:`h-24`},t))}));let s=ww(n,i.data);return s?r(s):o((0,B.jsx)(`p`,{className:`py-8 text-center text-muted-foreground`,children:Dw(`noneYet`,a.toLowerCase())}))},mR=({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)(xd,{open:!0,title:e,onClose:s,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:s,children:X(`cancel`)}),(0,B.jsx)(G,{type:`submit`,form:d,variant:`primary`,loading:a,children:X(`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)(BS,{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:X(`optional`)})]}),(0,B.jsx)(Xf,{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)})]})]})})},hR=on(),gR={start:0,end:0},_R=(e,t)=>hR.and(t,{kind:`present`,field:e.field,span:gR}),vR=e=>{switch(e.kind){case`and`:case`or`:return{...e,args:e.args.map(vR)};case`not`:return yR(e.arg);case`search`:case`present`:case`isNull`:return e;default:return _R(e,e)}},yR=e=>{switch(e.kind){case`and`:return hR.or(...e.args.map(yR));case`or`:return hR.and(...e.args.map(yR));case`not`:return vR(e.arg);case`search`:case`present`:case`isNull`:return hR.not(e);default:return _R(e,hR.not(e))}},bR=e=>{let t=rt(e);if(!t.ok)throw Error(`The filter cannot be read: ${t.errors.map(e=>e.message).join(`; `)}`);return t.ast},xR=(e,t)=>{let n=bR(e);if(!n)return null;let r=bR(t),i=hR.not(vR(n));return Jt(r?hR.and(r,i):i)},SR=(e,t)=>xR(t,e),CR=e=>e.key.startsWith(`extra:`)?`extra:${e.label}`:e.key,wR=(e,t)=>{let n=new Map(e.map(e=>[CR(e),e])),r=new Map(t.map(e=>[CR(e),e])),i=e.filter(e=>!r.has(CR(e))).map(e=>({kind:`removed`,label:e.label})),a=t.flatMap(e=>{let t=n.get(CR(e));return t&&t.label!==e.label?[{kind:`changed`,label:e.label,before:t.label}]:[]}),o=t.filter(e=>!n.has(CR(e))).map(e=>({kind:`added`,label:e.label}));return[...i,...a,...o]},TR=(e,t,n,r)=>{let i=e-t;if(i===0)return X(`asMany`,r);let a=Math.abs(i)===1?n:r;return i>0?X(`more`,i,a):X(`fewer`,-i,a)},ER=12,DR={added:{word:`added`,className:`text-success-text`},removed:{word:`removed`,className:`text-danger-text`},changed:{word:`changed`,className:`text-primary-text`}},OR=({changes:e})=>(0,B.jsx)(`ul`,{"aria-label":X(`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 ${DR[e.kind].className}`,children:X(DR[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}`))}),kR=(e,t)=>{let n=E({...ev(U(),e,t??``),enabled:t!==null});return t===null?0:n.data},AR=(e,t,n)=>`${e} ${e===1?t:n}`,jR=({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>ER&&(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:X(`firstOf`,ER,i)}),r===null||i===0?(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:X(`noPlural`,a)}):(0,B.jsx)(RO,{model:e,view:t,filter:r,sort:Qm(e,t),limit:ER,display:o?.name??`table`,row:!0,link:!1,empty:`No ${a}.`})]})},MR=({model:e,view:t,title:n,before:r,after:i,saveNewLabel:a,updating:o,creating:s,onUpdate:c,onSaveNew:l,onCancel:u})=>{let d=wR(lw(e,r),lw(e,i)),f=(0,I.useMemo)(()=>xR(r,i),[r,i]),p=(0,I.useMemo)(()=>SR(r,i),[r,i]),m=kR(e,f),h=kR(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)(xd,{open:!0,wide:!0,title:n,onClose:u,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:u,children:X(`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:X(`update`)})]}),children:(0,B.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[d.length>0&&(0,B.jsx)(OR,{changes:d}),v?(0,B.jsxs)(`p`,{children:[(0,B.jsx)(`span`,{className:`font-semibold`,children:TR(m,h,g,_)}),(0,B.jsxs)(`span`,{className:`text-muted-foreground`,children:[`: `,X(`addedRemoved`,AR(m,g,_),h)]})]}):(0,B.jsx)(K,{className:`h-4 w-48`}),(0,B.jsx)(jR,{model:e,view:t,title:X(`added`),filter:f,total:m,plural:_}),(0,B.jsx)(jR,{model:e,view:t,title:X(`removed`),filter:p,total:h,plural:_})]})})},NR=()=>{let{address:e,set:t}=Th();return{key:e?.kind===`list`?e.savedSearch:void 0,open:e=>t({savedSearch:e})}},PR=e=>e instanceof Error?e.message:X(`somethingWrong`),FR=(e,t)=>{let n=W(),r=U(),i=Gf(),a=iv(),{href:s,open:c}=Th(),l=NR(),{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&&V_(p,`create`)&&V_(p,`delete`),h=n.signIn?.[u]?.signIn,g=DT(u,m),_=e=>An(om(d,e)),v=f&&g.data?.find(e=>e[f.filter]===t),y=v||l.key===void 0||!p||!V_(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:X(`searchSaved`),action:{label:X(`openPlural`,x),href:s({kind:`list`,resource:u}),onNavigate:c}})},onError:e=>i.show({state:`error`,title:X(`couldNotSave`),description:PR(e)}),onSettled:()=>a(u)}),w=o({mutationFn:e=>r.remove(u,_(e)),onError:e=>i.show({state:`error`,title:X(`couldNotTakeOff`),description:PR(e)}),onSettled:()=>a(u)}),T=o({mutationFn:e=>r.update(u,_(e),{[f.filter]:t},e.etag??`*`),onSuccess:()=>i.show({state:`success`,title:X(`searchUpdated`)}),onError:e=>i.show({state:`error`,title:X(`couldNotUpdate`),description:PR(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)}},IR=({model:e,view:t,search:n,filter:r,chips:i,className:a})=>{let o=FR(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??X(`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)(Jr,{className:`size-3.5`,"aria-hidden":!0}),p]}),(0,B.jsx)(_w,{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)(mR,{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=X(`saveAsNew`,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)(To,{className:`size-3.5`,"aria-hidden":!0}),(0,B.jsx)(`span`,{className:`max-w-60 truncate`,children:X(`updateName`,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)(Kr,{className:`size-3.5`,"aria-hidden":!0}),n]}),l&&(0,B.jsx)(MR,{model:e,view:t,title:g.name?X(`updateNameQuestion`,g.name):X(`updateNounQuestion`,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?Wr:Jr;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]})},LR=e=>e instanceof Error?e.message:X(`somethingWrong`),RR=({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)(mg,{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:tr(e,s?.valueLabels)},e))})]})},zR=(e,t,n)=>Object.entries(n).map(([n,r])=>`${t.fields[n]?.label??F(n)}: ${e.fields[n]?.type===`boolean`?X(r===!0?`on`:`off`):tr(String(r),t.fields[n]?.valueLabels)}`).join(`, `),BR=({model:e,view:t,recordKey:n,title:r,row:i,fields:a})=>{let s=U(),c=Gf(),l=iv(),u=o({mutationFn:t=>s.update(e.name,n,t,i.etag??`*`),onSuccess:(n,i)=>c.show({state:`success`,title:X(`saved`,r),description:zR(e,t,i)}),onError:e=>c.show({state:`error`,title:X(`couldNotChange`),description:LR(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)(RR,{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))})},VR=e=>e instanceof Error?e.message:X(`somethingWrong`),HR=({model:e,view:t,of:n,target:r,targetView:i,row:a,recordKey:s,canRename:c,onDelete:l})=>{let u=U(),d=Gf(),f=iv(),[p,m]=(0,I.useState)(!1),{name:h,chips:g,title:_,body:v}=OT({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:X(`couldNotRename`),description:VR(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)(Eh,{to:{kind:`record`,resource:e.name,key:s},className:`hover:underline`,children:h??(0,B.jsx)(VS,{chips:g})})})}),(0,B.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[n.controls&&(0,B.jsx)(BR,{model:e,view:t,recordKey:s,title:_,row:a,fields:n.controls}),c&&b&&(0,B.jsx)(G,{variant:`ghost`,"aria-label":X(`renameTitle`,_),"aria-haspopup":`dialog`,onClick:()=>m(!0),children:(0,B.jsx)(uo,{className:`size-3.5`,"aria-hidden":!0})}),l&&(0,B.jsx)(G,{variant:`ghost`,"aria-label":X(`deleteTitle`,_),onClick:()=>l(_),children:(0,B.jsx)(_s,{className:`size-3.5`,"aria-hidden":!0})})]})]}),p&&b&&(0,B.jsx)(mR,{title:X(`renameTitle`,_),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)(wT,{...v})]})},UR=({model:e,view:t})=>{let{resources:n,views:r}=W(),i=t.searchesOf,a=n[i.resource],o=r[i.resource],s=DT(e.name,!0),c=ed(e.name),l=oF({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)(Fb,{title:u,subtitle:t.help}),e]});if(!a)return d((0,B.jsx)(Zu,{title:X(`notFound`),children:Qg(X(`noResource`),i.resource)}));if(s.error)return d((0,B.jsx)(pg,{title:X(`couldNotLoadYour`,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)(K,{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:Qg(X(`noSavedYet`,u.toLowerCase()),(0,B.jsx)(Eh,{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=An(om(e,n)),s=V_(c,`delete`)?e=>void l.start({key:r,title:e,etag:n.etag,snapshot:n}):void 0;return(0,B.jsx)(HR,{model:e,view:t,of:i,target:a,targetView:o,row:n,recordKey:r,canRename:V_(c,`update`),onDelete:s},r)})}))},WR=({field:e,hints:t,resource:n,stored:r,onSave:i,close:a})=>{let[o,s]=(0,I.useState)(()=>Jh(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&&Yh(e,s,r)&&i(Kh(e,s)),a(n))};return(0,B.jsx)(`div`,{ref:c,className:`w-full min-w-0`,onKeyDown:e=>{h_(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)&&!h_(e.relatedTarget)&&d(!0)},children:(0,B.jsx)(y_,{field:e,hints:t,value:o,stored:r,resource:n,onChange:e=>{s(e),u&&d(!0,void 0,e)}})})},GR=M({en:{changedBySomeoneElse:`Changed by someone else`,couldNotSave:`Could not save`},nl:{changedBySomeoneElse:`Gewijzigd door iemand anders`,couldNotSave:`Kon niet bewaren`}}),KR=e=>{let t=U(),n=be(),r=Gf(),[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=om(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,An(l)),r),n.invalidateQueries({queryKey:[`page`,e.name]}),n.invalidateQueries({queryKey:[`list`,e.name]}),n.invalidateQueries({queryKey:[`map`,e.name]})}catch(n){if(!jc(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:GR(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}}},qR=(e,t,n)=>{let r=KR(e),i=t?.list?.editable??[];return{editor:i.length>0&&V_(n,`update`)?{editable:(t,n)=>i.includes(n)&&e.fields[n]!==void 0&&Hh(e.fields[n])&&H_(t,`update`),render:(n,i,a)=>(0,B.jsx)(WR,{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}},JR=(e,t)=>({model:e,record:Object.fromEntries(Object.entries(Zm(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}}),YR=e=>{let{views:t}=W(),n=ov(e.name,void 0),{go:r,href:i}=Th(),[a,o]=(0,I.useState)(),s=(t[e.name]?.actions??[]).filter(e=>!e.inputs?.length),c=e=>`row`in e?n.run(e.action,e.row):n.runEach(e.action,e.selection,e.skipped),l=e=>{e.action.confirm?o(e):c(e)};return{rowActions:s.map(t=>{let a=n=>Z_(t,JR(e,n).record),o={label:e=>a(e)?.label??t.label,destructive:F_(t)},s=t.run;if(s?.kind===`link`){let n=n=>a(n)!==void 0&&W_(t,JR(e,n).record);if(`to`in s){let t=t=>pn(s.to,JR(e,t).record);return{...o,available:n,link:e=>({href:i(t(e)),onFollow:()=>r(t(e))})}}let c=t=>q_(s.href,JR(e,t).record)??``;return{...o,available:n,link:e=>({href:c(e),onFollow:()=>J_(c(e))})}}return{...o,available:e=>a(e)!==void 0,blocked:r=>n.blockedOn(t,JR(e,r)),onSelect:n=>l({action:t,row:JR(e,n)})}}),bulkActions:s.filter(e=>e.bulk&&e.run?.kind!==`link`).map(t=>({label:e=>xL(`actionCount`,t.label,e),destructive:F_(t),available:r=>n.appliesOn(t,JR(e,r)),onRun:(n,r)=>l({action:t,selection:n.map(t=>JR(e,t)),skipped:r})})),prompt:a&&(0,B.jsx)(P_,{action:a.action,label:a.action.label,danger:F_(a.action),onCancel:()=>o(void 0),onConfirm:()=>{o(void 0),c(a)}})}},XR=(e,t,n)=>({order:r,index:i})=>{let a=t=>r.findIndex(n=>An(om(e,n))===t),o=t.after.find(e=>a(e.key)>i);if(o)return bE(`dependsOn`,n,o.title);let s=t.before.find(e=>a(e.key)!==-1&&a(e.key)<i);return s?bE(`dependsOn`,s.title,n):void 0},ZR=(e,t,n,r)=>{let i=e[t],a;for(let o=n;o<e.length;o++){let n=r({record:i,order:s(e,t,o),index:o});if(n===void 0)return{to:o,...a!==void 0&&{reason:a}};a??=n}return{to:t,reason:a}},QR=({model:e,view:t,field:n,filter:r,fields:i,rule:a})=>{let o=U(),c=Gf(),l=iv(),{resources:u,views:d}=W(),f=`${n} asc`,p=E({queryKey:[...H.list(e.name,r,f,500,`hand-order`),i.join(`,`)],queryFn:async()=>{let t=iy(u,d,e,i),n=[],a=``;do{let s=await o.search(e.name,{filter:r||void 0,orderBy:f,pageSize:500,labels:t,...a&&{pageToken:a}});n.push(...ay(u,e,i,s.items,s.labels).map((t,n)=>({...t,id:am(e,s.items[n])}))),a=s.nextPageToken}while(a);return n}}),[m,h]=(0,I.useState)(),g=(0,I.useRef)(void 0),_=(0,I.useRef)(void 0),v=(0,I.useRef)(Promise.resolve()),y=(0,I.useRef)(0),b=(0,I.useRef)(void 0),x=async()=>{let t=g.current,r=_.current;if(_.current=void 0,!t||!r)return;let i=mE(t.map(e=>e[n]),r.first,r.last),a=t.slice(i.first,i.last+1),s=Object.fromEntries(a.flatMap(t=>typeof t.etag==`string`?[[An(om(e,t)),t.etag]]:[])),l=(await o.batchWrite([{op:`reorder`,resource:e.name,field:n,keys:a.map(t=>om(e,t)),start:i.start,etags:s}])).results[0];if(l?.op!==`reorder`)return;let u=new Map(a.map(e=>[e.id,{[n]:e[n]}])),d=lE(e,l.records.map(t=>({...t,before:u.get(am(e,t.record))??{}})),[n]);if(b.current!==void 0&&c.dismiss(b.current),b.current=c.show({state:`success`,title:cE(`orderChanged`),action:{label:cE(`undo`),onClick:()=>O(d)}}),!g.current)return;let f=new Map(l.records.map(t=>[am(e,t.record),t]));g.current=g.current.map(e=>{let t=f.get(e.id);return t?{...e,[n]:t.record[n],etag:t.etag}:e})},S=e=>t=>{g.current=void 0,_.current=void 0,h(void 0),c.show({state:`error`,title:e,description:Am(t)})},C=async()=>{--y.current,!(y.current>0)&&(await l(e.name),!(y.current>0)&&(g.current=void 0,h(void 0)))},w=(n,r)=>{let i=g.current??p.data;if(!i||n===r)return;if(!e.position?.after)return T(i,n,r,a);let s=Zm(e,i[n]).record,c=i[n].id;fE(o,e,t,s).then(n=>{let i=g.current??p.data,o=XR(e,n,or(e,t,s,c));T(i,i.findIndex(e=>e.id===c),r,e=>o(e)??a?.(e))},S(cE(`couldNotChange`)))},T=(e,t,n,r)=>{if(t===-1||t===n)return;let i=r?D(e,t,n,r):n;if(t===i)return;g.current=s(e,t,i);let a=Math.min(t,i),o=Math.max(t,i);_.current=_.current?{first:Math.min(_.current.first,a),last:Math.max(_.current.last,o)}:{first:a,last:o},h(g.current),y.current+=1,v.current=v.current.then(x).catch(S(cE(`couldNotChange`))).then(C)},D=(t,n,r,i)=>{let a=ZR(t.map(t=>Zm(e,t).record),n,r,i);return a.reason!==void 0&&c.show({state:`warning`,title:a.to===n?cE(`notMoved`):cE(`movedToPlace`,a.to+1),description:a.reason}),a.to},O=e=>{b.current!==void 0&&c.dismiss(b.current),b.current=void 0,y.current+=1,v.current=v.current.then(async()=>{await o.batchWrite(e),g.current=void 0,_.current=void 0,h(void 0)}).catch(S(cE(`couldNotUndo`))).then(C)};return{rows:m??p.data,loading:p.isPending,error:p.error,move:w}},$R=({model:e,view:t,field:n,filter:r,columns:i,sort:a})=>{let{resources:o,views:s}=W(),{fields:c,dropRules:l}=Wg(),{go:u,href:d}=Th(),f=a!==void 0,p=(0,I.useMemo)(()=>kO(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)(()=>Jm(e,t,p.map(e=>e.id)),[e,t,p]),h=t?.list?.drag?.rule,g=h===void 0?void 0:l?.[h],_=QR({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)(Zg,{children:Qg(cE(`noRule`),h)});if(_.loading)return(0,B.jsx)(`div`,{className:`flex flex-col gap-2`,children:Array.from({length:3},(e,t)=>(0,B.jsx)(K,{className:`h-4 w-full`},t))});if(_.error)return(0,B.jsx)(pg,{title:cE(`couldNotLoad`),error:_.error});if(!y||y.total===0)return(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:cE(`nothingYet`)});let b=t=>u({kind:`record`,resource:e.name,key:om(e,t)});return(0,B.jsx)(DS,{fit:!0,scroll:`parent`,columns:p,source:y,latencyMs:0,onOpenRow:b,rowLink:t=>({href:d({kind:`record`,resource:e.name,key:om(e,t)}),onFollow:()=>b(t)}),...a&&{sort:a.value,onSortChange:a.onChange},rowNumbers:!1,reorder:{label:n=>or(e,t,n,n.id),onMove:_.move}})},ez=({sorting:e,onChange:t,size:n,iconOnly:r=!1})=>{let i=cE(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)(ui,{className:`size-3.5`}):(0,B.jsx)(wr,{className:`size-3.5`}),!r&&i]})},tz=on(),nz=e=>e.find(e=>e.kind===`search`),rz=({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)(_w,{as:`page`,prompt:a.signIn}):(0,B.jsx)(Zu,{title:J(`notFound`),children:J(`noResource`,e.resource)});let o=Sn(n[e.resource],e.list);if(e.list!==void 0&&!o)return(0,B.jsx)(Zu,{title:J(`notFound`),children:xL(`noList`,e.list)});if(o?.searchesOf)return(0,B.jsx)(UR,{model:i,view:o});let s=th(t,n,e.resource,e.list);if(o&&s.listOf){let t=s.model;return(0,B.jsx)(pR,{model:i,view:o,target:t,children:n=>(0,B.jsx)(iz,{model:t,address:e,scope:n,heading:{title:o.names?.plural??F(i.name),subtitle:o.help}})})}return(0,B.jsx)(iz,{model:i,address:e})},iz=({model:e,address:t,scope:n,heading:r})=>{let i=W(),{set:a,listTo:o,go:s,href:c}=Th(),l=e.name,u=Sn(i.views[l],t.list),d=(0,I.useMemo)(()=>QC(u,e),[u,e]),{fields:f}=Wg(),p=(0,I.useMemo)(()=>fR(TO(vm(e,u),e,u,f),e,u,i.resources,i.views),[e,u,f,i.resources,i.views]),m=t.filter,h=(0,I.useMemo)(()=>KC(d,m),[d,m]),g=h.ok?h.state:ZS,_=h.ok?h.extras:[],{orderBy:v,filterLayout:y}=t,b=dd(),x=fd(),[S,C]=(0,I.useState)(!1),w=n?[..._,n]:_,T=YP({model:e,resources:i.resources,views:i.views,view:u,state:g,extras:w}),E=n?zC(d,g,w):h.ok?m:``,D=(0,I.useMemo)(()=>Jm(e,u,p.map(e=>e.id)),[e,u,p]),O=(0,I.useMemo)(()=>Pw(u,i.resources,i.views,D),[u,i.resources,i.views,D]),k=RS({resources:i.resources,views:i.views,model:e,columns:D,filter:E,orderBy:v,related:O}),A=Lm(e,u,t.display),j=ed(l),ee=n?void 0:UT(e,j),[te,ne]=(0,I.useState)(!1),re=te&&ee!==void 0,ie=!A&&!re&>(u,ee,v,E),ae=re||A?.kind!==`map`;Gy(ae);let oe=QT(e,k.page,k.key,A?.kind===`custom`),se=JL(),ce=ar(e,u),le=e=>({key:e.id,title:String(typeof e[ce]==`object`?e[ce].name:e[ce]??e.id),etag:typeof e.etag==`string`?e.etag:void 0,snapshot:e}),ue=u?.names?.singular??F(l),de=qR(e,u,j),{state:fe}=V(),pe=oF({model:e,view:u,restore:sF(e),onReview:e=>s({kind:`record`,resource:l,key:e.key})}),me=YR(e),he=u?.actions.some(e=>e.run?.kind===`delete`)??!1,ge=(e,t=_)=>a({filter:zC(d,e,t)}),_e=nz(_),ve=e=>{let t=_.filter(e=>e.kind!==`search`);ge(g,e?[...t,tz.search(e)]:t)},ye=u?.names?.plural??F(l),be=A?.kind===`calendar`||A?.kind===`timeline`||A?.kind===`board`&&Dm(e)?void 0:A,xe=be&&(0,B.jsx)(wO,{model:e,view:u,display:be,orderBy:v,onChange:e=>a({orderBy:e})}),Se=e.search?.length?(0,B.jsx)(aR,{value:_e?.kind===`search`?_e.text:``,onCommit:ve,placeholder:xL(`searchPlural`,ye),className:b?void 0:`min-h-11`}):null,Ce=(0,B.jsx)(DC,{layout:y,config:T,value:g,onChange:ge,leading:y===`bar`?xe:void 0,trailing:Se}),we=y===`bar`?Ce:(0,B.jsx)(TC,{groups:[xe?[xe]:[]],trailing:Se}),Te=nC(T,g),Ee=(0,B.jsx)(GS,{scroll:!0,chips:Te,onRemove:e=>ge(rC(g,e)),onClear:()=>ge(ZS)}),De=be&&(0,B.jsx)(uC,{title:xL(`sort`),children:(0,B.jsx)(wO,{model:e,view:u,display:be,orderBy:v,onChange:e=>a({orderBy:e}),className:`min-h-11 w-full`})}),Oe=(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)(qo,{className:`size-3.5`}),Te.length>0?xL(`filtersCount`,Te.length):xL(`filters`)]}),Se??(0,B.jsx)(`div`,{className:`min-w-0 flex-1`,children:Ee})]}),Se&&Ee,(0,B.jsx)(bd,{title:xL(`filters`),open:S,onClose:()=>C(!1),children:(0,B.jsx)(DC,{layout:`panel`,fullWidth:!0,config:T,value:g,onChange:ge,leading:De})})]}),ke=!n&&cF(u,i.pages,j)&&(0,B.jsxs)(Eh,{to:{kind:`create`,resource:l},className:ld({variant:`primary`}),children:[(0,B.jsx)(_o,{className:`size-3.5`}),xL(`newRecord`,ue)]}),Ae=u?.saveSearch&&!n&&h.ok&&m&&(0,B.jsx)(IR,{model:e,view:u,search:u.saveSearch,filter:m,chips:aw(e,u,m,ow(T))}),je=!n&&(0,B.jsx)(FI,{model:e}),Me=bL({model:e,view:u,resources:i.resources,views:i.views,plural:ye,filter:E,orderBy:v}),M=GI(u)&&(0,B.jsxs)(G,{onClick:()=>Me.open(),...!b&&{"aria-label":xL(`export`),title:xL(`export`)},children:[(0,B.jsx)(Bi,{className:`size-3.5`}),b&&xL(`export`)]}),Ne=ee&&!ie&&(0,B.jsx)(ez,{sorting:re,onChange:ne,iconOnly:!b}),Pe=t=>!re&&(0,B.jsx)(SO,{view:u,choices:Vm(e,u,x),value:A?.name??`table`,onChange:e=>a({display:e}),menu:t}),Fe=dw(e),Ie=t=>{Fe(Zm(e,t).record),s({kind:`record`,resource:l,key:om(e,t)})},Le=k.source?(0,B.jsx)(DS,{columns:p,source:k.source,sort:$m(v),onSortChange:e=>a({orderBy:eh(e)}),onOpenRow:Ie,rowLink:t=>({href:c({kind:`record`,resource:l,key:om(e,t)}),onFollow:()=>Ie(t)}),cellEditor:de.editor,rowPatches:de.patches,initialScrollIndex:se.initialIndex,onScrollIndex:se.remember,rowActions:[{label:xL(`openRecord`,ue),onSelect:Ie},...me.rowActions,...V_(j,`delete`)&&!he?[{label:xL(`delete`),destructive:!0,available:e=>H_(e,`delete`),onSelect:e=>void pe.start(le(e))}]:[]],bulkActions:[...GI(u)&&ZI(e)?[{label:e=>xL(`exportCount`,e),onRun:e=>Me.open(e)}]:[],...me.bulkActions,...V_(j,`delete`)?[{label:e=>xL(`deleteCount`,e),destructive:!0,onRun:e=>pe.startBulk(e.map(le))}]:[]],rowNumbers:!1,pinKey:fe.kind===`signed-in`?Dx(fe.user.id,cR(l,t.list)):void 0,scroll:`parent`,className:`flex-1`}):(0,B.jsx)(`div`,{className:`flex-1 rounded-lg border bg-surface`}),N={...k,initialIndex:se.initialIndex,onScrollIndex:se.remember},Re=CL({plural:ye,search:_e?.kind===`search`?_e.text:``,filtered:Te.length>0,scoped:!!n||_.some(e=>e.kind!==`search`),canCreate:!!ke}),ze=(0,B.jsx)(SL,{state:Re,onClearSearch:()=>ve(``),onClearFilters:()=>ge(ZS),create:ke}),Be=re?(0,B.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:xL(`dragToSort`)}),(0,B.jsx)($R,{model:e,view:u,field:ee,filter:``,columns:mr(e,u)})]}):ie?(0,B.jsx)($R,{model:e,view:u,field:ee,filter:``,columns:mr(e,u),sort:{value:$m(v),onChange:e=>a({orderBy:eh(e)})}}):A?A.kind===`cards`?(0,B.jsx)(RL,{model:e,view:u,display:A,list:N,empty:ze},k.key.join(` `)):A.kind===`map`?(0,B.jsx)(vO,{model:e,view:u,display:A,filter:E,orderBy:v,fields:D,at:t.map,onMove:e=>a({map:e}),flush:!0}):A.kind===`board`?(0,B.jsx)(TE,{model:e,view:u,display:A,fields:D,filter:E,orderBy:v}):A.kind===`calendar`?(0,B.jsx)(lD,{model:e,view:u,display:A,fields:D,filter:E,at:t.calendar,linkTo:e=>o({calendar:e})}):A.kind===`timeline`?(0,B.jsx)(AD,{model:e,view:u,display:A,fields:D,filter:E,at:t.timeline,linkTo:e=>o({timeline:e})}):(0,B.jsx)(BD,{display:A,list:oe}):k.source?.total===0&&!k.error?ze:Le;return(0,B.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 px-5 py-4`,children:[pe.dialogs,Me.dialogs,me.prompt,(0,B.jsx)(Fb,{title:r?.title??ye,subtitle:r?r.subtitle:u?.help,subtitleBelow:!0,actions:(0,B.jsxs)(B.Fragment,{children:[Pe(!b),Ne,Ae,je,M,ke]})}),!h.ok&&(0,B.jsx)(pg,{title:xL(`unreadableFilter`),error:Error(h.errors.map(e=>e.message).join(`; `))}),k.error&&!A&&!re&&(0,B.jsx)(pg,{title:xL(`couldNotLoadRows`),error:k.error}),u?.chart&&!re&&(kn(u.chart)?(0,B.jsx)(iR,{model:e,view:u,chart:u.chart,plural:ye,filter:E}):(0,B.jsx)(nR,{resource:l,chart:u.chart,title:xL(`created`,ye),noun:ye.toLowerCase(),filter:E})),!re&&(b?we:Oe),b&&y===`panel`&&!re?(0,B.jsxs)(`div`,{className:`flex min-h-0 flex-1 gap-4`,children:[(0,B.jsx)(`div`,{className:ae?`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:Ce}),Be]}):Be]})},az=e=>e?.role===`owner`?[`owner`,`admin`,`member`]:[`admin`,`member`],oz=({member:e,current:t,onChanged:n})=>{let{session:r,organizations:i}=V(),a=t.organization.id,{busy:o,error:s,run:c}=rk(),l=i?.roles??[],u=e.id===t.memberId,d=az(t),f=e.role===`owner`&&t.role!==`owner`,p=l.filter(e=>e.membership);return(0,B.jsx)(kk,{name:e.name,email:e.email,self:u,error:s,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`select`,{"aria-label":Z(`roleOf`,e.name),value:e.role,disabled:o||f,onChange:t=>void c(async()=>{await r.organizations.setRole(a,e.id,t.target.value),n()}),className:`h-7 rounded-md border border-border-strong bg-background px-2 text-body`,children:(f?[e.role]:d).map(e=>(0,B.jsx)(`option`,{value:e,children:hk(e)},e))}),!u&&(0,B.jsx)(G,{size:`sm`,variant:`danger`,loading:o,disabled:f,onClick:()=>void c(async()=>{await r.organizations.removeMember(a,e.id),n()}),children:Z(`remove`)})]}),children:(0,B.jsx)(ck,{roles:p,selected:e.appRoles,grantable:yk(l,t),disabled:o,onChange:t=>void c(async()=>{await r.organizations.setAppRoles(e.id,t),n()})})})},sz=({current:e})=>{let{session:t}=V(),[n,r]=(0,I.useState)(),[i,a]=(0,I.useState)(),o=e?.organization?.id,s=(0,I.useCallback)(()=>{o&&t.organizations.members(o).then(r,e=>a(e instanceof yl?ZO(e):Z(`couldNotReadMembers`)))},[t,o]);return(0,I.useEffect)(s,[s]),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)(Fb,{title:Z(`members`),subtitle:Z(`whoWorks`,e.organization.name)}),(0,B.jsxs)(WO,{title:Z(`members`),description:Z(`membersDescription`),children:[(0,B.jsx)(GO,{message:i}),n?(0,B.jsx)(`ul`,{className:`divide-y rounded-md border`,children:n.map(t=>(0,B.jsx)(oz,{member:t,current:e,onChanged:s},`${t.id}/${t.role}/${t.appRoles.join()}`))}):!i&&(0,B.jsxs)(`div`,{className:`flex items-center gap-2 text-muted-foreground`,children:[(0,B.jsx)(Yu,{}),` `,Z(`loading`)]})]})]}):null},cz=({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)(ok,{title:Z(`inviteSomeone`),description:Z(`inviteDescription`),onInvite:async r=>{let i=await n.organizations.invite(e.organization.id,{email:r,role:a,appRoles:s});return c([]),t(),i},beside:(0,B.jsx)(`select`,{"aria-label":Z(`organizationRole`),value:a,onChange:e=>o(e.target.value),className:`h-8 rounded-md border border-border-strong bg-background px-2`,children:az(e).map(e=>(0,B.jsx)(`option`,{value:e,children:hk(e)},e))}),children:(0,B.jsx)(ck,{roles:i.filter(e=>e.membership),selected:s,grantable:yk(i,e),onChange:c})})},lz=({invitation:e,organizationId:t,onChanged:n})=>{let{session:r,organizations:i}=V(),a=e.appRoles.map(e=>gk(i?.roles??[],e));return(0,B.jsx)(sk,{email:e.email,gives:`${hk(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()}})},uz=({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)(Fb,{title:Z(`invitations`),subtitle:Z(`peopleInvited`,e.organization.name)}),(0,B.jsx)(cz,{current:e,onSent:a}),(0,B.jsx)(WO,{title:Z(`notAcceptedYet`),description:n.length>0?Z(`sendingAgain`):Z(`nobodyWaiting`),children:n.length>0&&(0,B.jsx)(`ul`,{className:`divide-y rounded-md border`,children:n.map(e=>(0,B.jsx)(lz,{invitation:e,organizationId:i,onChanged:a},e.id))})})]})},dz=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 yl?ZO(e):Z(`couldNotReadOrganizations`)))},[e,t,c]),{current:n,organizations:i,...o&&{error:o},reload:u}},fz=e=>window.location.assign(`${e}/`),pz=({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}=rk(),d=i.trim()!==e.name||o!==e.slug;return(0,B.jsxs)(WO,{title:Z(`details`),description:Z(t?`detailsEditable`:`detailsReadOnly`),children:[(0,B.jsx)(GO,{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)(Xf,{"aria-label":Z(`name`),value:i,disabled:!t,onChange:e=>a(e.target.value),wrapperClassName:`flex-1`}),(0,B.jsx)(Xf,{"aria-label":Z(`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:Z(`save`)})]})]})},mz=({organization:e,memberId:t})=>{let{session:n}=V(),[r,i]=(0,I.useState)([]),[a,o]=(0,I.useState)(``),{busy:s,error:c,run:l}=rk();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)(WO,{title:Z(`handOver`),description:Z(`handOverDescription`),children:[(0,B.jsx)(GO,{message:c}),(0,B.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,B.jsxs)(`select`,{"aria-label":Z(`newOwner`),value:a,onChange:e=>o(e.target.value),className:`h-8 flex-1 rounded-md border border-border-strong bg-background px-2`,children:[(0,B.jsx)(`option`,{value:``,children:Z(`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:Z(`handOver`)})]})]})},hz=({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}=rk(),u=()=>l(async()=>{await n.organizations.remove(e.id),fz(t)});return(0,B.jsxs)(WO,{title:Z(`deleteOrganization`),description:Z(`deleteDescription`),children:[(0,B.jsx)(GO,{message:r?void 0:c}),(0,B.jsx)(G,{variant:`danger`,onClick:()=>i(!0),children:Z(`deleteOrganization`)}),r&&(0,B.jsxs)(vd,{title:Z(`deleteTitle`,e.name),description:Z(`deleteConfirm`),onClose:()=>i(!1),actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:()=>i(!1),children:Z(`cancel`)}),(0,B.jsx)(G,{variant:`danger`,loading:s,disabled:a!==e.name,onClick:()=>void u(),children:Z(`delete`)})]}),children:[(0,B.jsx)(GO,{message:c}),(0,B.jsx)(Xf,{"aria-label":Z(`organizationName`),value:a,onChange:e=>o(e.target.value)})]})]})},gz=({organization:e,basePath:t,owner:n})=>{let{session:r}=V(),{busy:i,error:a,run:o}=rk();return(0,B.jsxs)(WO,{title:Z(`leave`),description:Z(n?`leaveOwner`:`leaveMember`),children:[(0,B.jsx)(GO,{message:a}),(0,B.jsx)(G,{loading:i,onClick:()=>void o(async()=>{await r.organizations.leave(e.id),fz(t)}),children:Z(`leaveName`,e.name)})]})},_z=({current:e,basePath:t,onChanged:n})=>{let r=e?.organization;if(!r)return(0,B.jsx)(`div`,{className:`mx-auto w-full max-w-3xl px-4 py-6 md:px-6`,children:(0,B.jsx)(Fb,{title:Z(`organization`),subtitle:Z(`noOrganization`)})});let i=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)(Fb,{title:r.name,subtitle:e.role?Z(`youAre`,hk(e.role).toLowerCase()):Z(`throughGlobalRoles`)}),(0,B.jsx)(pz,{organization:r,editable:_k(e),onSaved:n},`${r.name}/${r.slug}`),i&&e.memberId&&(0,B.jsx)(mz,{organization:r,memberId:e.memberId}),e.role&&(0,B.jsx)(gz,{organization:r,basePath:t,owner:i}),i&&(0,B.jsx)(hz,{organization:r,basePath:t})]})},vz=({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)(hp,{tone:`green`,children:Z(`current`)}):(0,B.jsx)(G,{size:`sm`,loading:n,onClick:r,children:Z(`open`)})]}),yz=({basePath:e,currentId:t})=>{let{session:n}=V(),[r,i]=(0,I.useState)(``),a=Ok((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}=rk();return(0,B.jsx)(Dk,{title:Z(`allOrganizations`),description:Z(`allOrganizationsDescription`),searchLabel:Z(`findOrganization`),placeholder:Z(`nameOrSlug`),query:r,onQuery:i,list:a,error:s,renderRow:r=>(0,B.jsx)(vz,{organization:r,current:r.id===t,busy:o,onOpen:()=>void c(async()=>{await n.organizations.switchTo(r.id),fz(e)})},r.id)})},bz=e=>e.normalize(`NFKD`).replace(/[̀-ͯ]/g,``).toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,63),xz=({basePath:e})=>{let{session:t}=V(),[n,r]=(0,I.useState)(``),[i,a]=(0,I.useState)(),{busy:o,error:s,run:c}=rk(),l=()=>c(async()=>{await t.organizations.create({name:n.trim(),slug:i??bz(n)}),fz(e)});return(0,B.jsxs)(WO,{title:Z(`newOrganization`),description:Z(`newOrganizationDescription`),children:[(0,B.jsx)(GO,{message:s}),(0,B.jsxs)(`form`,{className:`flex flex-col gap-2 sm:flex-row`,onSubmit:e=>{e.preventDefault(),l()},children:[(0,B.jsx)(Xf,{"aria-label":Z(`name`),placeholder:Z(`name`),value:n,onChange:e=>r(e.target.value),wrapperClassName:`flex-1`}),(0,B.jsx)(Xf,{"aria-label":Z(`slug`),placeholder:`slug`,value:i??bz(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:Z(`create`)})]})]})},Sz=({basePath:e})=>{let{session:t,organizations:n}=V(),[r,i]=(0,I.useState)([]),{busy:a,error:o,run:s}=rk();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),fz(e)});return(0,B.jsxs)(WO,{title:Z(`invitationsForYou`),description:Z(`invitationsForYouDescription`),children:[(0,B.jsx)(GO,{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??Z(`anOrganization`)}),`: `,e.appRoles.map(e=>gk(c,e)).join(`, `)||Z(`noAppRoles`),(0,B.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:Z(`until`,new Date(e.expiresAt).toLocaleDateString(Ie()))})]}),(0,B.jsx)(G,{size:`sm`,variant:`primary`,loading:a,onClick:()=>void l(e.id),children:Z(`accept`)})]},e.id))})]})},Cz=({state:e,basePath:t})=>{let{session:n,organizations:r,state:i}=V(),{busy:a,error:o,run:s}=rk(),c=i.kind===`signed-in`?i.user:void 0,l=r?.create===`everyone`||c!==void 0&&eN(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)(Fb,{title:Z(`organizations`),subtitle:Z(`organizationsSubtitle`)}),(0,B.jsxs)(WO,{title:Z(`yourOrganizations`),description:e.organizations.length>0?Z(`memberOf`):Z(`notMember`),children:[(0,B.jsx)(GO,{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)(vz,{organization:e,current:e.id===u,busy:a,onOpen:()=>void s(async()=>{await n.organizations.switchTo(e.id),fz(t)})},e.id))})]}),(0,B.jsx)(Sz,{basePath:t}),l&&(0,B.jsx)(xz,{basePath:t}),(e.current?.globalRoles.length??0)>0&&(0,B.jsx)(yz,{basePath:t,currentId:u})]})},wz=(e,t)=>t?.active?{...e,role:t.active}:e,Tz=M({en:{couldNotReadRoles:`Could not read your roles`,couldNotSwitch:`Could not switch the role`},nl:{couldNotReadRoles:`Kon je rollen niet lezen`,couldNotSwitch:`Kon niet van rol wisselen`}}),Ez=(e,t)=>e instanceof yl?ZO(e):t,Dz=(e,t=!0)=>{let{session:n}=V(),r=Gf(),[i,a]=(0,I.useState)();(0,I.useEffect)(()=>{t&&n.roles.current().then(a,e=>r.show({state:`error`,title:Ez(e,Tz(`couldNotReadRoles`))}))},[n,r,t]);let o=(0,I.useCallback)(t=>void n.roles.switchTo(t).then(e,e=>r.show({state:`error`,title:Ez(e,Tz(`couldNotSwitch`))})),[n,r,e]);return{...i&&{current:i},switchTo:o}},Oz=e=>{let t=dR(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},kz=e=>{let t=Wg().shell?.logo;return t?(0,B.jsx)($g,{name:`shell.logo`,fallback:(0,B.jsx)(tb,{...e}),children:(0,B.jsx)(t,{...e})}):(0,B.jsx)(tb,{...e})},Az=(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)}},jz=()=>{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:Az(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])}},Mz=M({en:{notifications:`Notifications`,notificationsUnread:e=>`Notifications, ${e} unread`,notificationsManyUnread:`Notifications, more than 99 unread`,markAllRead:`Mark all as read`,empty:`No notifications yet`,showMore:`Show more`,loadFailed:`Your notifications could not be loaded.`,tryAgain:`Try again`,unread:`Unread`,pushOff:`Get notifications on this device, even when the app is closed.`,turnOn:`Turn on`,pushOn:`Notifications are on for this device.`,turnOff:`Turn off`,pushBlocked:`Notifications are blocked on this device. To get them, allow notifications for this site in your browser or device settings.`},nl:{notifications:`Meldingen`,notificationsUnread:e=>`Meldingen, ${e} ongelezen`,notificationsManyUnread:`Meldingen, meer dan 99 ongelezen`,markAllRead:`Alles als gelezen markeren`,empty:`Nog geen meldingen`,showMore:`Meer tonen`,loadFailed:`Je meldingen konden niet worden geladen.`,tryAgain:`Opnieuw proberen`,unread:`Ongelezen`,pushOff:`Ontvang meldingen op dit apparaat, ook als de app gesloten is.`,turnOn:`Inschakelen`,pushOn:`Meldingen staan op dit apparaat aan.`,turnOff:`Uitschakelen`,pushBlocked:`Meldingen zijn op dit apparaat geblokkeerd. Je kunt ze voor deze site toestaan in de instellingen van je browser of apparaat.`}}),Nz=`flex w-full gap-2.5 px-3 py-2.5 text-left`,Pz=({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?pp.blue:`bg-transparent`),children:a&&(0,B.jsx)(`span`,{className:`sr-only`,children:Mz(`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:Cf((i-Date.parse(e.createdAt))/1e3)})]})]}),s=()=>r(e),c=e=>{e.button===1&&s()};return t?t.kind===`app`?(0,B.jsx)(ah,{to:{href:t.href,onFollow:()=>n(t.path)},onClick:s,onAuxClick:c,className:P(Nz,`hover:bg-muted`),children:o}):(0,B.jsx)(`a`,{href:t.href,onClick:s,onAuxClick:c,className:P(Nz,`hover:bg-muted`),children:o}):(0,B.jsx)(`div`,{className:Nz,children:o})},Fz=({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:Mz(`notifications`)}),m&&h&&(0,B.jsx)(G,{size:`sm`,variant:`ghost`,loading:c,onClick:()=>s(m),children:Mz(`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)(Yu,{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:Mz(`loadFailed`)}),(0,B.jsx)(G,{size:`sm`,onClick:r,children:Mz(`tryAgain`)})]}):e.length===0?(0,B.jsx)(`p`,{className:`px-3 py-8 text-center text-body text-muted-foreground`,children:Mz(`empty`)}):(0,B.jsx)(`ul`,{className:`divide-y`,children:e.map(e=>(0,B.jsx)(`li`,{children:(0,B.jsx)(Pz,{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:Mz(`showMore`)})})]}),f]})},Iz=(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}},Lz=({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)(Ir,{className:`mt-0.5 size-3.5 shrink-0`,"aria-hidden":!0}),Mz(`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)(Rr,{className:`size-3.5 shrink-0`,"aria-hidden":!0}),(0,B.jsx)(`span`,{className:`min-w-0 flex-1`,children:Mz(r?`pushOn`:`pushOff`)}),(0,B.jsx)(G,{size:`sm`,variant:r?`secondary`:`primary`,onClick:r?n:t,children:Mz(r?`turnOff`:`turnOn`)})]})},Rz=3e4,zz=e=>jc(e)&&e.status===403,Bz=({enabled:e=!0}={})=>{let t=U();return E({queryKey:H.inboxUnread,queryFn:()=>t.notifications.unread(),refetchInterval:e=>!zz(e.state.error)&&Rz,enabled:e})},Vz=({enabled:e=!0}={})=>{let t=U(),n=Me({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}},Hz=(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))},Uz=()=>{let e=U(),t=be(),n=()=>t.invalidateQueries({queryKey:H.inbox}),r=o({mutationFn:t=>e.notifications.markRead(t.id),onMutate:e=>Hz(t,t=>t.id===e.id),onSettled:n}),i=o({mutationFn:t=>e.notifications.markAllRead(t.createdAt),onMutate:e=>Hz(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}},Wz=99,Gz=e=>e===void 0||e<=0?void 0:e>Wz?`${Wz}+`:String(e),Kz=e=>e===void 0||e<=0?Mz(`notifications`):e>Wz?Mz(`notificationsManyUnread`):Mz(`notificationsUnread`,String(e)),qz=()=>{let{open:e,setOpen:t,place:n,button:r,menu:i}=Fh(),a=Bz(),o=Vz({enabled:e}),{markRead:s,markAllRead:c,markingAll:l}=Uz(),u=jz(),{navigate:d,basePath:f}=mh(),[p,m]=(0,I.useState)(Date.now),h=Gz(a.data),g=Kz(a.data),_=window.location.origin;return zz(a.error)?null:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(G,{ref:r,size:`icon`,variant:`ghost`,"aria-label":g,title:g,"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)(Br,{className:`size-4 max-md:size-5`}),h&&(0,B.jsx)(hp,{tone:`red`,dot:!1,className:`pointer-events-none absolute -top-1 -right-1.5 h-4 min-w-4 justify-center px-1 text-[10px] font-semibold max-md:top-0 max-md:right-0`,children:h})]}),e&&(0,Bs.createPortal)((0,B.jsx)(`div`,{ref:i,role:`dialog`,"aria-label":Kz(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)(Fz,{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=>Iz(e.url,{origin:_,basePath:f}),onNavigate:e=>d(e),onOpen:e=>{s(e),t(!1)},footer:(0,B.jsx)(Lz,{state:u.state,onTurnOn:()=>void u.turnOn(),onTurnOff:()=>void u.turnOff()}),now:p})}),document.body)]})},Jz=({own:e})=>e?(0,B.jsx)($g,{name:`shell.bell`,fallback:null,children:(0,B.jsx)(e,{})}):(0,B.jsx)(qz,{}),Yz=(0,I.createContext)([]),Xz=()=>(0,I.useContext)(Yz),Zz=({ui:e,children:t})=>{let{plugins:n=[]}=W(),{loads:r,settled:i}=GM(n,HM()),a=(0,I.useMemo)(()=>SM(e,r),[e,r]);return i?(0,B.jsx)(Ug.Provider,{value:a.ui,children:(0,B.jsx)(Yz.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)(Yu,{}),` `,CM(`loading`)]})},Qz=({off:e})=>{let[t,n]=(0,I.useState)(!1);return t||e.length===0?null:(0,B.jsxs)(`div`,{role:`region`,"aria-label":CM(`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)(xo,{"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:Qg(CM(`pluginOff`),(0,B.jsx)(`span`,{className:`font-semibold`,children:e.name??e.url}),e.reason)},e.url))}),(0,B.jsx)(`button`,{type:`button`,"aria-label":CM(`dismiss`),className:`rounded p-0.5 hover:bg-warning/10`,onClick:()=>n(!0),children:(0,B.jsx)(Ls,{"aria-hidden":!0,className:`size-4`})})]})},$z=(e,t)=>[`${t}_at`,`${t}At`].find(t=>e.fields[t]),eB=({item:e,scope:t})=>{let{components:n}=Wg(),r=n?.[e.component],i=r?(0,B.jsx)(z_,{value:t,children:(0,B.jsx)($g,{name:e.component,children:(0,B.jsx)(r,{..._n(e.props??{})})})}):(0,B.jsx)(Zg,{children:Qg(J(`noComponent`),e.component)});return e.sidebar?e.title?(0,B.jsx)(op,{title:e.title,children:i}):i:e.title?(0,B.jsx)(np,{title:e.title,children:i}):(0,B.jsx)(`section`,{className:`py-8`,children:i})},tB=(0,I.lazy)(()=>Be(()=>import(`./record-map-DjqQGqZ2.js`).then(e=>({default:e.RecordMap})),__vite__mapDeps([8,1,2,5,6,3,7]))),nB=15,rB=({item:e,record:t})=>{let n=W().maps,r=n?.style,i=QD(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)(tB,{style:r,layers:n?.layers,position:i,zoom:e.zoom??nB},`${i.latitude},${i.longitude}`)})});return e.sidebar?(0,B.jsx)(op,{title:e.title,children:a}):(0,B.jsx)(np,{title:e.title,children:a})},iB={"1h":`minute`,"24h":`5_minutes`,"7d":`hour`},aB=(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}))},oB=M({en:{range:`Range`,hour:`Hour`,day:`Day`,week:`Week`,measure:`Per bucket`,average:`Average`,maximum:`Maximum`,noSamples:`No samples in this range.`,couldNotLoad:`Could not load the chart.`},nl:{range:`Periode`,hour:`Uur`,day:`Dag`,week:`Week`,measure:`Per interval`,average:`Gemiddelde`,maximum:`Maximum`,noSamples:`Geen metingen in deze periode.`,couldNotLoad:`Kon de grafiek niet laden.`}}),sB=on(),cB=[`1h`,`24h`,`7d`],lB={"1h":`hour`,"24h":`day`,"7d":`week`},uB=({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=iB[i],d=Jt(sB.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:Gd()})),p=bv(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)?aB(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)(Le,{label:oB(`measure`),value:o,onChange:s,options:[{value:`average`,label:oB(`average`)},{value:`maximum`,label:oB(`maximum`)}]}),(0,B.jsx)(Le,{label:oB(`range`),value:i,onChange:a,options:cB.map(e=>({value:e,label:oB(lB[e])}))})]});return(0,B.jsx)(np,{title:e.title,help:e.help,actions:_,children:p.some(e=>e.error)?(0,B.jsx)(`p`,{className:`text-danger-text`,children:oB(`couldNotLoad`)}):p.some(e=>e.isPending)?(0,B.jsx)(K,{className:`h-40 w-full`}):g.every(e=>e.count===0)?(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:oB(`noSamples`)}):(0,B.jsx)(Jv,{points:g,measure:m[0],bucket:u,type:`line`,series:h,...h.length>1&&{resource:e.resource,view:l}})})},dB=e=>pw(e)??zs,fB=({model:e,stored:t,recordKey:n,edit:r,onDelete:i})=>{let{go:a}=Th(),o=Eb(),s={model:e,record:t.record,key:n,etag:t.etag,permissions:t.permissions},c=ov(e.name,s,t=>t.run?.kind===`delete`&&a({kind:`list`,resource:e.name},{replace:!0})),[l,u]=(0,I.useState)(),d=c.actions.map(e=>({name:e.label,icon:dB(e.icon),blocked:c.blocked(e),running:c.running===e.name,...F_(e)&&{tone:`danger`},onRun:()=>I_(e)?u(e):void c.run(e)})),f=c.actions.some(e=>e.run?.kind===`delete`),p=[...r?[{name:Q(`edit`),icon:uo,render:({className:e,children:t,role:n})=>(0,B.jsx)(Eh,{to:r,role:n,className:e,children:t})}]:[],...d,...i&&!f?[{name:Q(`delete`),icon:_s,tone:`danger`,onRun:i}]:[]];return p.length===0?null:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`div`,{className:o?`max-md:hidden`:void 0,children:(0,B.jsx)(ip,{actions:p})}),o&&(0,Bs.createPortal)((0,B.jsx)(Ih,{actions:p,label:Q(`recordActions`),className:`inline-flex size-11 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-muted md:hidden`}),o),l&&(0,B.jsx)(L_,{action:l,label:l.label,danger:F_(l),onCancel:()=>u(void 0),onConfirm:()=>{u(void 0),c.run(l)},onSubmit:async e=>{await c.submit(l,e),u(void 0)}})]})},pB=(e=[],t)=>e.includes(t)?e.filter(e=>e!==t):[...e,t],mB=(e,t=[],n)=>!e.collapsed||t.includes(e.title)||e.items.some(e=>e.kind===`section`&&e.fields.some(n)),hB=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)}},gB=(e,t)=>e.find(e=>e.title===t)??e[0],_B=e=>xn(e.items).flatMap(e=>e.kind===`section`?e.fields:[]),vB=(e,t,n)=>{if(t&&!_B(t).some(n))return e.find(e=>_B(e).some(n))},yB=(e,t)=>Object.values(e).find(e=>e.name!==t.name&&e.fields.position&&e.fields.quantity&&Object.values(e.fields).some(e=>e.type===`relation`&&e.relation?.resource===t.name)),bB=e=>({id:String(e.id),productId:String(e.productId??``),description:String(e.description??``),quantity:Number(e.quantity),unitPriceCents:Math.round(Number(e.unitPrice)*100)}),xB=({lines:e,draft:t,vatRate:n,saving:r,locked:i=!1})=>{let a=V_(ed(e.name),`update`);return(0,B.jsx)(np,{title:Q(`lines`),help:Q(`linesHelp`),children:(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`,{className:`min-w-[560px]`,children:(0,B.jsx)(Nf,{lines:t.shown.map(bB),onChange:()=>void 0,onReorder:e=>t.setOrder(e.map(e=>e.id)),vatRate:n,readOnly:!0,reorderable:a&&!r&&!i})})})})},SB=(e,t,n)=>`protobase:draft:${e}:${t}:${n}`,CB=(e,t,n)=>Fe(()=>{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),wB=(e,t,n)=>Fe(()=>n?e.setItem(t,JSON.stringify(n)):e.removeItem(t),void 0),TB=(e,t)=>Number(e.position)-Number(t.position),EB=(e,t,n)=>{let r=e&&Object.values(e.fields).find(e=>e.type===`relation`&&e.relation?.resource===t.name),i=_g(e?.name??``,{enabled:!!(e&&r),filter:r?`${r.name} = "${n}"`:void 0,pageSize:200,...e?.fields.position?.sortable&&{orderBy:`position asc`}});return{items:[...i.items].sort(TB),loading:i.isPending&&!!e}},DB=(e,t)=>{let[n,r]=(0,I.useState)(),i=t.map(e=>String(e.id)),a=(0,I.useMemo)(()=>{if(!n)return t;let e=n.flatMap(e=>t.filter(t=>String(t.id)===e)),r=t.filter(e=>!n.includes(String(e.id)));return[...e,...r]},[n,t]),o=a.map(e=>String(e.id)),s=n!==void 0&&o.some((e,t)=>e!==i[t]),c=(0,I.useCallback)(()=>!e||!s?[]:[{op:`reorder`,resource:e.name,field:`position`,keys:a.map(t=>om(e,t)),etags:Object.fromEntries(a.flatMap(t=>typeof t.etag==`string`?[[An(om(e,t)),t.etag]]:[]))}],[e,s,a]);return{shown:a,dirty:s,order:s?o:void 0,setOrder:e=>r(e),reset:()=>r(void 0),op:c}},OB=e=>{let t=e>=5?5:e===4?3:e;return{shown:t,more:e-t}},kB=(e,t)=>Math.abs(e)<40||Math.abs(e)<=Math.abs(t)?0:e<0?1:-1,AB=e=>e===`ArrowRight`?1:e===`ArrowLeft`?-1:0,jB=(e,t,n)=>Math.min(Math.max(e+t,0),Math.max(n-1,0)),MB=e=>e.key===`i`&&!e.ctrlKey&&!e.metaKey&&!e.altKey,NB=`protobase:lightbox-details`,PB=e=>Fe(()=>e.getItem(NB)===`true`,!1),FB=(e,t)=>Fe(()=>t?e.setItem(NB,`true`):e.removeItem(NB),void 0),IB=M({en:{couldNotLoad:`Could not load the photos`,showAll:e=>`Show all ${e} photos`,showPhoto:(e,t)=>`Show photo ${e} of ${t}`,details:`Details`,holderDetails:e=>`${e} details`,close:`Close`,previousPhoto:`Previous photo`,nextPhoto:`Next photo`,couldNotLoadOne:e=>`Could not load the ${e}`,open:e=>`Open ${e}`},nl:{couldNotLoad:`Kon de foto’s niet laden`,showAll:e=>`Alle ${e} foto’s tonen`,showPhoto:(e,t)=>`Foto ${e} van ${t} tonen`,details:`Gegevens`,holderDetails:e=>`Gegevens van ${e.toLowerCase()}`,close:`Sluiten`,previousPhoto:`Vorige foto`,nextPhoto:`Volgende foto`,couldNotLoadOne:e=>`Kon ${e} niet laden`,open:e=>`${e} openen`}}),LB=`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`,RB=({title:e,photos:t,index:n,onIndex:r,onClose:i,details:a,detailsTitle:o=IB(`details`)})=>{let s=(0,I.useRef)(null),c=(0,I.useRef)(void 0),l=(0,I.useId)(),u=dd(),[d,f]=(0,I.useState)(()=>PB(localStorage)),[p,m]=(0,I.useState)(!1);_d(s,!0,i),(0,I.useEffect)(()=>m(!0),[]);let h=t.length,g=e=>{let t=jB(n,e,h);t!==n&&r(t)},_=Op(t[n],{width:1600,height:1200}),v=a?.(n),y=v!==void 0,b=e=>{f(e),FB(localStorage,e)};return(0,B.jsxs)(`div`,{ref:s,tabIndex:-1,role:`dialog`,"aria-modal":`true`,"aria-label":e,onKeyDown:e=>{if(y&&MB(e))return e.preventDefault(),b(!d);let t=AB(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(LB,`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)(ga,{className:`size-4`,"aria-hidden":!0})}),(0,B.jsx)(`button`,{type:`button`,className:LB,"aria-label":IB(`close`),onClick:i,children:(0,B.jsx)(Ls,{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(kB(e.clientX-c.current.x,e.clientY-c.current.y)),void 0)},onPointerCancel:()=>c.current=void 0,children:[_&&(0,B.jsx)(Lg,{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(LB,`absolute left-3 top-1/2 -translate-y-1/2 aria-disabled:cursor-default aria-disabled:opacity-40`),"aria-label":IB(`previousPhoto`),"aria-disabled":n===0,onClick:()=>g(-1),children:(0,B.jsx)(mi,{className:`size-5`,"aria-hidden":!0})}),(0,B.jsx)(`button`,{type:`button`,className:P(LB,`absolute right-3 top-1/2 -translate-y-1/2 aria-disabled:cursor-default aria-disabled:opacity-40`),"aria-label":IB(`nextPhoto`),"aria-disabled":n===h-1,onClick:()=>g(1),children:(0,B.jsx)(gi,{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)(bd,{title:o,open:y&&d&&!u&&p,onClose:()=>b(!1),children:(0,B.jsx)(`div`,{className:`pt-3`,children:v})})]})},zB=(e,t,n)=>{let r=xn(t?.layout??[]).flatMap(e=>e.kind===`section`&&$h(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)&&$h(t?.fields[r]?.when,!1))},BB=({model:e,view:t,photoKey:n,fields:r})=>{let i=lN(e.name,n),a=(t?.names?.singular??F(e.name)).toLowerCase();if(i.isPending)return(0,B.jsx)(K,{className:`h-4 w-48`});if(i.error)return(0,B.jsx)(pg,{title:IB(`couldNotLoadOne`,a),error:i.error});let o=r.filter(e=>U_(i.data.permissions,e)!==`hidden`);return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(Ah,{rows:o.map(n=>({label:t?.fields[n]?.label??F(n),value:(0,B.jsx)(uy,{model:e,field:e.fields[n],value:i.data.record[n]})}))}),(0,B.jsx)(Eh,{to:{kind:`record`,resource:e.name,key:n},className:`mt-3 inline-block font-medium text-primary-text hover:underline`,children:IB(`open`,a)})]})},VB=e=>Op(e,{width:0,height:0})!==void 0,HB=(e,t)=>{let n=e.primaryKey.map(e=>t[e]);if(!n.some(e=>e==null))return An(n)},UB=(e,t,n,r)=>{let i=n===void 0?[]:t.flatMap(e=>{let t=e[n];if(!vp(t)||!VB(t))return[];let i=r&&HB(r,e);return[{file:t,...i!==void 0&&{key:i}}]});if(!vp(e)||!VB(e))return i;let a=t=>vp(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))]},WB=on(),GB=(e,t,n)=>{let r=U(),{resources:i}=W(),a=e.photos?i[e.photos.resource]:void 0,o=e.photos?Jt(WB.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:UB(e.image===void 0?void 0:t[e.image],c.data??[],e.photos?.image,a),isPending:a!==void 0&&c.isPending,error:c.error}},KB={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`,``,``,``,``]},qB=({photo:e,large:t})=>{let n=Op(e,t?{width:960,height:720}:{width:480,height:360});return n?(0,B.jsx)(Lg,{image:n,loading:`lazy`,className:`size-full object-cover transition-transform duration-300 group-hover/tile:scale-[1.02]`}):null},JB=({item:e,record:t,recordKey:n})=>{let{views:r}=W(),i=GB(e,t,n),a=ed(i.holder?.name??``),[o,s]=(0,I.useState)();if(i.isPending)return(0,B.jsx)(np,{title:e.title,children:(0,B.jsx)(K,{className:`aspect-[4/3] w-full rounded-lg md:aspect-[2/1]`})});if(i.error)return(0,B.jsx)(np,{title:e.title,children:(0,B.jsx)(pg,{title:IB(`couldNotLoad`),error:i.error})});let c=i.items.length;if(c===0)return null;let{shown:l,more:u}=OB(c),d=i.holder,f=d&&r[d.name],p=d?zB(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)(np,{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?IB(`showAll`,c):IB(`showPhoto`,t+1,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`,KB[l][t]),children:[(0,B.jsx)(qB,{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)(ma,{className:`size-3.5`}),c]})]},t)})}),o!==void 0&&(0,B.jsx)(RB,{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)(BB,{model:d,view:f,photoKey:t,fields:p},t):void 0},detailsTitle:d&&IB(`holderDetails`,f?.names?.singular??F(d.name))})]})},YB=M({en:{create:`created this`,update:`changed`,delete:`deleted this`,undelete:`restored this`,database:`Database`,databaseRole:e=>`Database (${e})`,changed:`changed`,changedThis:`changed this`,couldNotLoad:`Could not load the history`,noChanges:`No changes kept yet.`,showMore:`Show more`},nl:{create:`maakte dit`,update:`wijzigde`,delete:`verwijderde dit`,undelete:`zette dit terug`,database:`Database`,databaseRole:e=>`Database (${e})`,changed:`gewijzigd`,changedThis:`wijzigde dit`,couldNotLoad:`Kon de geschiedenis niet laden`,noChanges:`Nog geen wijzigingen bewaard.`,showMore:`Meer tonen`}}),XB=e=>e.actor?e.actor.name??e.actor.id:e.databaseRole?YB(`databaseRole`,e.databaseRole):YB(`database`),ZB=(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:bm(i,e.before[r],a),after:bm(i,e.after[r],a)}]}),i=e.operation===`update`&&r.length===0?YB(`changedThis`):YB(e.operation);return{who:XB(e),verb:i,fields:r}},QB=1500,$B=(e,t,n,r)=>{let i=U(),a=Me({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(),QB);return()=>clearTimeout(e)},[r,o]),{...a,items:a.data?.pages.flatMap(e=>e.items)??[]}},eV=()=>(0,B.jsx)(`div`,{className:`flex flex-col gap-2`,children:Array.from({length:3},(e,t)=>(0,B.jsx)(K,{className:`h-4 w-full`},t))}),tV=({change:e,model:t,view:n})=>{let{who:r,verb:i,fields:a}=ZB(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:ff(o),className:`text-muted-foreground`,children:[`· `,Cf(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))})]})},nV=({item:e,model:t,view:n,recordKey:r,etag:i})=>{let a=$B(t.name,r,e.limit??10,i);return(0,B.jsx)(np,{title:e.title,children:a.isPending?(0,B.jsx)(eV,{}):a.error?(0,B.jsx)(pg,{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)(tV,{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`})]})})},rV=({comment:e})=>(0,B.jsx)(KN,{text:e.body,mentions:e.mentions}),iV=(e,t)=>{let n=U(),r=be();return o({mutationFn:r=>n.comment(e,t,r),onSuccess:()=>r.invalidateQueries({queryKey:H.comments(e,t)})})},aV=M({en:{couldNotPost:`Could not post the comment`,comment:`Comment`,placeholder:`Write a comment, @ to mention someone`,couldNotLoad:`Could not load the comments`,showEarlier:`Show earlier comments`,noComments:`No comments yet.`},nl:{couldNotPost:`Kon de opmerking niet plaatsen`,comment:`Opmerking`,placeholder:`Schrijf een opmerking, @ om iemand te noemen`,couldNotLoad:`Kon de opmerkingen niet laden`,showEarlier:`Eerdere opmerkingen tonen`,noComments:`Nog geen opmerkingen.`}}),oV=({resource:e,recordKey:t})=>{let[n,r]=(0,I.useState)(UN),i=U(),a=Gf(),o=iV(e,t),s=(0,I.useCallback)(n=>i.mentionable(e,t,n),[i,e,t]);wh(n.text.trim()!==``||o.isPending,`input-lost`);let c=()=>{n.text.trim()===``||o.isPending||o.mutate({body:n.text,mentions:RN(n.text,n.picked)},{onSuccess:()=>r(UN),onError:e=>a.show({state:`error`,title:aV(`couldNotPost`),description:Am(e)})})};return(0,B.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,B.jsx)(GN,{"aria-label":aV(`comment`),placeholder:aV(`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:aV(`comment`)})})]})},sV=20,cV=(e,t)=>{let n=U(),r=Me({queryKey:H.comments(e,t),initialPageParam:``,queryFn:({pageParam:r})=>n.comments(e,t,{pageSize:sV,pageToken:r}),getNextPageParam:e=>e.nextPageToken||void 0});return{...r,items:r.data?.pages.flatMap(e=>e.items).reverse()??[]}},lV=()=>(0,B.jsx)(`div`,{className:`flex flex-col gap-2`,children:Array.from({length:3},(e,t)=>(0,B.jsx)(K,{className:`h-4 w-full`},t))}),uV=({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)(Qf,{initials:QM(t)||`?`,hue:ZM(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:ff(n),className:`text-muted-foreground`,children:[`· `,Cf(Math.max(0,Math.round((Date.now()-n)/1e3)))]})]}),(0,B.jsx)(rV,{comment:e})]})]})},dV=({item:e,resource:t,recordKey:n,canWrite:r})=>{let i=cV(t,n);return(0,B.jsxs)(np,{title:e.title,children:[i.isPending?(0,B.jsx)(lV,{}):i.error?(0,B.jsx)(pg,{title:aV(`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:aV(`showEarlier`)}),i.items.length===0?(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:aV(`noComments`)}):(0,B.jsx)(`ol`,{className:`divide-y divide-border`,children:i.items.map(e=>(0,B.jsx)(uV,{comment:e},e.id))})]}),r&&(0,B.jsx)(`div`,{className:`mt-4`,children:(0,B.jsx)(oV,{resource:t,recordKey:n})})]})},fV=e=>e.kind===`group`||e.kind===`tab`?e.items:[],pV=e=>e.kind===`tab`?void 0:e.when,mV=e=>e.flatMap(e=>[e,...mV(fV(e))]).filter(e=>qs(pV(e))),hV=(e,t,n,r)=>{let i=0,a=e=>{let a=pV(e);return qs(a)?!r&&t[i++]===!0:$h(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)},gV=(e,t,n,r)=>hV(e,IT(r?[]:mV(e).map(e=>pV(e)),t),n,r),_V=(e,t)=>{let n=U(),r=be(),i=An(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]})}})},vV=e=>e instanceof Ac,yV=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}`},bV=(e,t)=>{let n=e.operation,r=n===void 0?void 0:t[n];return r?J(`operationFailed`,n+1,yV(r),e.message):J(`nothingSaved`,e.message)},xV=(e,t)=>new e.constructor({...e.problem,detail:bV(e,t)}),SV=(e,t)=>Object.fromEntries(Object.entries(e).filter(([e])=>e!==t)),CV=({model:e,stored:t,recordKey:n,mode:r,subject:i,draftKey:a,lines:o})=>{let s=U(),c=be(),l=_V(e.name,n),u=LP(r,i),[d]=(0,I.useState)(()=>a?CB(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])=>Yh(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?.dirty;wB(localStorage,a,r?{etag:t.etag,fields:n,...o?.order&&{order:o.order}}:void 0)},[a,e,f,o?.dirty,o?.order,t.etag]);let D=n=>n in f?f[n]:[`boolean`,`file`].includes(e.fields[n].type)?t.record[n]:Bh(t.record[n]),O=(n,r)=>{x(e=>SV(e,n));let i=typeof r==`string`?r!==Bh(t.record[n]):Yh(e.fields[n],r,t.record[n]);p(e=>i?{...e,[n]:r}:SV(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];Yh(s,o,r.record[n])&&(a[n]=o,Bh(r.record[n])!==Bh(t.record[n])&&(i[n]=s.type===`file`?bm(s,r.record[n]):Bh(r.record[n])))}p(a),y(i)},A=()=>Object.fromEntries(w.map(([t,n])=>[t,Kh(e.fields[t],n)])),j=e=>{let t=My(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 vV(e)?await k():jc(e)&&j(e),e}},te=async r=>{let i=[...T?[{op:`update`,resource:e.name,key:n,data:A(),etag:t.etag}]:[],...r];try{await s.batchWrite(i)}catch(e){throw vV(e)?(await k(),await c.invalidateQueries({queryKey:[`list`]}),_(!0)):jc(e)&&j(e),jc(e)?xV(e,i):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?.op()??[];e.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=>SV(t,e)),useTheirs:e=>{y(t=>SV(t,e)),p(t=>SV(t,e))}}},wV=on(),TV=(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:Jt(wV.eq(n,t)),pageSize:1,fields:[n,e.tenant]}},EV=(e,t,n)=>{let r=t?.[e.tenant];if(r!=null&&String(r)!==n)return String(r)},DV=(e,t)=>{let n=U(),{session:r,organizations:i}=V(),a=(0,I.useMemo)(()=>i?TV(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=EV(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},OV=(e,t,n,r)=>{let i=U(),a=be(),o=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),s=f({queries:o.map(e=>{let o=t[e.relation.resource],s=String(r[e.name]);return{queryKey:H.relatedLabel(o.name,s),queryFn:async()=>(await ny(a,i,o,[s],n[o.name])).get(s)??s}})}),c=o.map(e=>({kind:`record`,resource:e.relation.resource,key:String(r[e.name])}));return{addresses:Object.fromEntries(o.map((e,t)=>[e.name,c[t]])),labels:Object.fromEntries(o.map((e,t)=>[e.name,s[t]?.data]))}},kV=on(),AV=(e,t,n,r,i)=>{if(e.primaryKey.length!==1)return[];let a=new Set(xn(r).flatMap(e=>e.kind===`related`&&!e.through&&!e.from?[`${e.resource}.${e.field}`]:[])),o=Object.values(t).flatMap(t=>Object.values(t.fields).filter(t=>t.type===`relation`&&t.relation?.resource===e.name&&t.relation.columns.length===1&&t.filterable).filter(e=>e.name!==t.tenant&&t.name!==i?.name&&!a.has(`${t.name}.${e.name}`)).map(e=>({source:t,field:e.name})));return o.map(({source:e,field:t})=>{let r=n[e.name],i=r?.names?.plural??F(e.name),a=o.filter(t=>t.source.name===e.name).length>1;return{resource:e.name,field:t,label:a?`${i} (${r?.fields[t]?.label??F(t)})`:i}})},jV=(e,t)=>({kind:`list`,resource:e.resource,filter:Jt(kV.eq(e.field,t))}),MV=on(),NV=(e,t,n)=>{let r=U(),i=f({queries:e.map(e=>{let i=Jt(MV.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}]})},PV=({model:e,recordKey:t,layout:n,lines:r})=>{let{resources:i,views:a}=W(),o=NV(AV(e,i,a,n,r),i,t);return o.length===0?null:(0,B.jsx)(op,{title:Q(`relatedRecords`),children:(0,B.jsx)(`ul`,{className:`-mx-2`,children:o.map(({relation:e,count:n})=>(0,B.jsx)(`li`,{children:(0,B.jsxs)(Eh,{to:jV(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)(K,{className:`h-4 w-6`}):`${Vd(n.count)}${n.exact?``:`+`}`,(0,B.jsx)(gi,{className:`size-4 text-faint-foreground group-hover:text-foreground`})]})]})},`${e.resource}.${e.field}`))})})},FV=on(),IV=(...e)=>{let t=e.filter(e=>!!e);return t.length===1?t[0]:t.map(e=>`(${e})`).join(` AND `)},LV=(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?IV(Jt(FV.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 kS(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:IV(Jt(FV.in(e.field,c.data)),e.filter),isPending:!1,error:null}:{filter:void 0,isPending:c.isPending,error:c.error}:{filter:IV(Jt(FV.eq(e.field,t)),e.filter),isPending:!1,error:null}},RV=()=>(0,B.jsx)(`div`,{className:`flex flex-col gap-2`,children:Array.from({length:3},(e,t)=>(0,B.jsx)(K,{className:`h-4 w-full`},t))}),zV=({empty:e})=>(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:e??Q(`nothingYet`)}),BV=({item:e,value:t,owner:n})=>{let{resources:r,views:i}=W(),a=r[e.resource],o=a&&i[a.name],s=LV(e,t),[c,l]=zO(o,`related:${n}:${e.title}`,e.display),u=ed(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:()=>ev(p,a,s.filter??``).queryFn()});if(!a||e.hideEmpty&&(s.isPending||s.filter===null||m&&(h.isPending||h.data===0)))return null;let g=jO(e,a,r),_=e.columns??mr(a,o).filter(t=>t!==e.field),v=t=>s.isPending?(0,B.jsx)(RV,{}):s.error?(0,B.jsx)(pg,{title:Q(`couldNotLoadRelated`),error:s.error}):s.filter===null||s.filter===void 0?(0,B.jsx)(zV,{empty:e.empty}):t(s.filter);if(e.presentation===`cards`)return(0,B.jsx)(np,{title:e.title,help:e.help,children:v(t=>(0,B.jsx)(ix,{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=WT(e,a,u),b=(0,B.jsx)(IO,{view:o,value:c,onChange:l}),x=y?(0,B.jsxs)(`div`,{className:`flex items-center gap-2`,children:[!d&&b,(0,B.jsx)(ez,{size:`sm`,sorting:d,onChange:f})]}):b;return d&&y?(0,B.jsx)(np,{title:e.title,help:e.help,actions:x,children:(0,B.jsx)($R,{model:a,view:o,field:y,filter:Jt(FV.eq(e.field,t)),columns:_})}):(0,B.jsx)(np,{title:e.title,help:e.help,actions:x,children:v(t=>(0,B.jsx)(RO,{model:a,view:o,filter:t,sort:e.sort??``,columns:_,limit:e.limit??10,display:c,empty:e.empty,opens:g},t))})},VV=(e,t,n)=>{if(e.from===void 0)return n;let r=t[e.from];return typeof r==`boolean`?r:MO(t,e.from)??null},HV=(e,t)=>t===e.tenant||e.primaryKey.includes(t),UV=(e,t,n)=>{if(t&&t.layout.length>0)return t.layout;let r=Object.values(e.fields).filter(t=>!HV(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`)}]:[]]},WV=({resource:e,recordKey:t})=>{let{resources:n}=W(),r=n[e],i=uN(e,t);return r?i.isPending?(0,B.jsx)(Zu,{title:Q(`loading`),children:Q(`fetching`)}):i.error?(0,B.jsx)(`div`,{className:`p-8`,children:jc(i.error)&&i.error.status===404?(0,B.jsx)(GV,{model:r,recordKey:t}):(0,B.jsx)(pg,{title:Q(`couldNotLoad`),error:i.error})}):(0,B.jsx)(KV,{model:r,recordKey:t,stored:i.data,preview:i.isPlaceholderData},i.isPlaceholderData?`preview`:`loaded`):(0,B.jsx)(Zu,{title:J(`notFound`),children:J(`noResource`,e)})},GV=({model:e,recordKey:t})=>{let n=DV(e,t);return n.state===`looking`?(0,B.jsx)(Zu,{title:Q(`loading`),children:Q(`fetching`)}):n.state===`switching`?(0,B.jsx)(Zu,{title:Q(`loading`),children:Q(`openingElsewhere`)}):n.state===`failed`?(0,B.jsx)(pg,{title:Q(`couldNotLoad`),error:n.error}):(0,B.jsx)(Zu,{title:J(`notFound`),children:Q(`noRecord`)})},KV=({model:e,recordKey:t,stored:n,preview:r})=>{let i=W(),{address:a,go:o}=Th(),s=i.views[e.name],c=or(e,s,n.record,t),{state:l}=V(),u=(0,I.useMemo)(()=>yB(i.resources,e),[i.resources,e]),d=DB(u,EB(u,e,t).items),f=CV({model:e,stored:n,recordKey:t,mode:s?.saveFeedback??`toast`,subject:c,draftKey:!r&&l.kind===`signed-in`?SB(l.user.id,e.name,t):void 0,lines:d}),p=be(),m=U(),h=Py(f.rejections),g=ed(e.name),_=sF(e),v=V_(g,`update`)&&n.permissions?.update!==!1,{shown:y,offersEdit:b,editing:x}=Xh(s?.recordMode,v,a?.kind===`record`&&a.edit===!0);wh(f.dirty&&y===`form`||f.saving),Ou(f.dirty);let S=a?.kind===`record`?a.open:void 0,C=a?.kind===`record`&&a.edit===!0,w=a?.kind===`record`?a.tab:void 0,T=(n=[],r=!1,i)=>({kind:`record`,resource:e.name,key:t,...r&&{edit:r},...n.length>0&&{open:n},...i&&{tab:i}}),E=T(S,!1,w),D=T(S,!0,w),O=y===`form`&&s?.recordMode!==void 0&&s.recordMode!==`edit`,k=V_(g,`delete`)&&n.permissions?.delete!==!1,A=oF({model:e,view:s,restore:_,onDeleted:()=>o({kind:`list`,resource:e.name},{replace:!0}),onReview:()=>void p.invalidateQueries({queryKey:H.record(e.name,t)})}),j=OV(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,qh(e,f.value(e.name))]))},re=OV(e,i.resources,i.views,ne),ie=(e,t)=>{let n=ee(e);if(!n||!tg(t))return f.change(e,t);p.setQueryData(H.relatedLabel(n.name,t.key),t.label),f.change(e,ig(n,t.key))},{fields:ae}=Wg(),oe={model:e,record:n.record,key:t,etag:n.etag,permissions:n.permissions},se=gV(UV(e,s,y===`read`),oe,x,r),{before:ce,tabs:le,after:ue}=hB(se),de=gB(le,w),fe=e=>x&&(f.errors[e]!==void 0||f.conflicts[e]!==void 0);(0,I.useEffect)(()=>{if(f.rejections===0)return;let e=vB(le,de,fe);e&&o(T(S,C,e===le[0]?void 0:e.title),{replace:!0})},[f.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=$z(e,`updated`),ve=e=>s?.fields[e],ye=t=>U_(n.permissions,t)!==`hidden`&&$h(ve(t)?.when,x)&&(y===`form`||!e.fields[t]?.writeOnly),xe=e=>!r||Object.hasOwn(n.record,e),Se=r=>{let a=e.fields[r],o=U_(n.permissions,r);if(!a||o===`hidden`)return null;let c=f.conflicts[r],l=ee(r),u=ve(r)?.label??F(r),d=f.errors[r];return(0,B.jsx)(ep,{name:r,label:u,required:y===`form`&&o!==`read`&&Uh(a),help:Qh(ve(r),s,x),error:d&&jy(a,u,d),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:()=>f.keepMine(r),onUseTheirs:()=>f.useTheirs(r)},children:xe(r)?(0,B.jsx)(y_,{field:a,hints:ve(r),value:f.value(r),stored:n.record[r],relationLabel:re.labels[r],relationTo:re.addresses[r],relationPicker:l&&{target:l,view:i.views[l.name]},locked:y!==`form`||o===`read`,invalid:!!f.errors[r],reveal:a.sensitive&&!a.writeOnly?()=>m.reveal(e.name,t,r):void 0,resource:e.name,onChange:e=>ie(r,e)}):(0,B.jsx)(K,{className:`h-9`})},a.sensitive?`${r}:${n.etag}`:r)},Ce=r=>{let i=e.fields[r],a=xe(r)?i.sensitive?(0,B.jsx)(y_,{field:i,hints:ve(r),value:``,stored:n.record[r],locked:!0,reveal:()=>m.reveal(e.name,t,r),resource:e.name,onChange:e=>f.change(r,e)}):(0,B.jsx)(uy,{model:e,field:i,value:n.record[r],relationLabel:j.labels[r]}):(0,B.jsx)(K,{className:`h-4 w-32`});return{label:ve(r)?.label??F(r),help:Qh(ve(r),s,x),wide:!!(ve(r)?.multiline||ve(r)?.markdown),value:a}},we=se.findIndex(e=>e.kind===`sidebar`),Te=(0,B.jsx)(sp,{title:Q(`summary`),rows:pe.flatMap(t=>{let r=e.fields[t];if(!r||!ye(t))return[];if(!xe(t))return[{label:ve(t)?.label??F(t),value:(0,B.jsx)(K,{className:`h-4 w-24`})}];let i=n.record[t],a=rm(r,ve(t))&&typeof i==`string`&&i!==``?nm(i):bm(r,i,ve(t)),o=r.type===`text`&&typeof i==`string`&&i!==``?cm(ve(t)):void 0,s=r.type===`enum`?(0,B.jsx)(sy,{value:i,hints:ve(t),children:a}):o?(0,B.jsx)(d_,{format:o,value:a}):(0,B.jsx)(`span`,{title:xm(r,i,void 0,ve(t)),children:a}),c=Gg(ae,r,ve(t));return[{label:ve(t)?.label??F(t),title:a,value:c?(0,B.jsx)(n_,{shown:c,part:`display`,field:r,value:n.record[t],fallback:s}):s}]})}),Ee=async()=>{await f.save()&&O&&o(E,{replace:!0})},De=k?()=>void A.start({key:t,title:c,etag:n.etag,snapshot:n.record}):void 0,Oe=y===`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:f.saving,disabled:!f.dirty&&f.phase!==`saved`,onClick:()=>void Ee(),children:[f.phase===`saved`&&(0,B.jsx)(ui,{className:`size-4`}),f.phase===`saved`?Q(`saved`):Q(`save`)]}),O&&(0,B.jsx)(Eh,{to:E,className:P(ld(),`max-md:min-h-11 md:w-full`),onClick:e=>Ff(e)&&f.discard(),children:Q(`cancel`)}),f.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=mB(i,S,fe),n=i.collapsed?T(pB(S,i.title),C,w):void 0;return[(0,B.jsx)(Oh,{title:i.title,open:t,toggle:n,children:e},`group:${i.title}`)]}if(i.kind===`related`)return i.from!==void 0&&!xe(i.from)?[]:[(0,B.jsx)(BV,{item:i,value:VV(i,n.record,t),owner:e.name},`related:${i.title}`)];if(i.kind===`chart`)return[(0,B.jsx)(uB,{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)(eB,{item:i,scope:oe},`custom:${a}`)];if(i.kind===`map`)return i.sidebar?[]:[(0,B.jsx)(rB,{item:i,record:n.record},`map:${a}`)];if(i.kind===`gallery`)return[(0,B.jsx)(JB,{item:i,record:n.record,recordKey:t},`gallery:${a}`)];if(i.kind===`history`)return[(0,B.jsx)(nV,{item:i,model:e,view:s,recordKey:t,etag:n.etag},`history:${a}`)];if(i.kind===`comments`)return[(0,B.jsx)(dV,{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=y===`read`&&i.presentation===`facts`,u=c?Tm(n.record,o):o;return u.length===0?[]:[(0,B.jsx)(np,{title:i.title,help:Zh(i.helpWhen,s,x)?i.help:void 0,children:c?(0,B.jsx)(jh,{facts:u.map(e=>({label:Ce(e).label,value:Ce(e).value,icon:pw(ve(e)?.icon)}))}):y===`read`?(0,B.jsx)(Ah,{rows:u.map(Ce)}):(0,B.jsx)(`div`,{className:`grid grid-cols-1 gap-x-6 gap-y-5 sm:grid-cols-2`,children:u.map(Se)})},i.title)]};return(0,B.jsxs)(`div`,{ref:h,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)(gp,{title:c,status:ge?{label:tr(ge,ve(`status`)?.valueLabels),tone:fm(ge)}:void 0}),f.message&&(0,B.jsx)(`div`,{className:`mt-4`,children:(0,B.jsx)(pg,{title:Q(`notSaved`),error:Error(f.message)})}),f.linesConflict&&(0,B.jsx)(`div`,{className:`mt-4`,children:(0,B.jsx)(pg,{title:Q(`linesChanged`),error:Error(Q(`linesReloaded`))})}),y!==`form`&&b&&f.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)(Eh,{to:D,className:ld({size:`sm`}),children:Q(`continueEditing`)}),(0,B.jsx)(G,{size:`sm`,onClick:f.discard,children:Q(`discard`)})]})]}),y===`form`&&f.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:f.dismissRestored,children:Q(`keep`)}),(0,B.jsx)(G,{size:`sm`,onClick:f.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)(kh,{tabs:le.map((e,t)=>({title:e.title,to:T(S,C,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),u&&!r&&(0,B.jsx)(xB,{lines:u,draft:d,vatRate:Number(n.record.vatRate??21)/100,saving:f.saving,locked:y!==`form`})]}),(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)(fB,{model:e,stored:n,recordKey:t,edit:b?D:void 0,onDelete:De}),we===-1&&Te,se.map((e,t)=>e.kind===`custom`&&e.sidebar&&!r?(0,B.jsx)(eB,{item:e,scope:oe},`custom:${t}`):e.kind===`map`&&e.sidebar&&!r?(0,B.jsx)(rB,{item:e,record:n.record},`map:${t}`):t===we?(0,B.jsx)(I.Fragment,{children:Te},`summary`):null),(0,B.jsx)(sp,{title:Q(`details`),rows:[$z(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:xe(t)?(0,B.jsx)(`span`,{title:xm(r,n.record[t],void 0,ve(t)),children:bm(r,n.record[t],ve(t))}):(0,B.jsx)(K,{className:`h-4 w-24`})}]})}),!r&&(0,B.jsx)(PV,{model:e,recordKey:t,layout:se,lines:u})]})]})]})}),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})]})},qV=e=>jc(e)?e.status===401||e.status===403?J(`signInRefused`,e.message):e.message:J(`noAnswer`),JV=({status:e})=>{let t=be();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:J(`cannotReach`,e.source.label)}),(0,B.jsxs)(`p`,{className:`mt-1 text-muted-foreground`,children:[qV(e.error),` `,J(`restWorks`)]}),(0,B.jsx)(G,{className:`mt-3`,onClick:()=>void t.refetchQueries({queryKey:H.sourceMetas(e.source.url)}),children:J(`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)(Yu,{}),` `,J(`loadingFrom`,e.source.label)]})},YV=M({en:{search:`Search`,searchOne:e=>`Search ${e}`,searchTwo:(e,t)=>`Search ${e} and ${t}`,searchMore:(e,t)=>`Search ${e}, ${t} and more`,goTo:`Go to`,create:`Create`},nl:{search:`Zoeken`,searchOne:e=>`Zoek in ${e}`,searchTwo:(e,t)=>`Zoek in ${e} en ${t}`,searchMore:(e,t)=>`Zoek in ${e}, ${t} en meer`,goTo:`Ga naar`,create:`Maken`}}),XV=(e,t)=>e.toLowerCase().includes(t.trim().toLowerCase()),ZV=(e,t,n=``)=>{let r=dR(e,n).flatMap(e=>e.items.filter(e=>e.href!==void 0&&!e.problem)).filter(e=>XV(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||!cF(a,e.pages,e.permissions[r.name]??zu))return[];let o=a.names?.singular??F(r.name),s=eg(`title`,o);return!XV(s,t)&&!XV(o,i)&&!XV(a.names?.plural??F(r.name),i)?[]:[{id:`new:${r.name}`,title:s,href:ic({kind:`create`,resource:r.name},n)}]});return[...r.length>0?[{id:`go-to`,label:YV(`goTo`),hits:r.map(e=>({id:`go-to:${e.id}`,title:e.label,href:e.href}))}]:[],...a.length>0?[{id:`create`,label:YV(`create`),hits:a.slice(0,5)}]:[]]},QV=on(),$V=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)}]}),eH=e=>{let t=e.map(e=>e.label.toLowerCase());return t.length===0?YV(`search`):t.length===1?YV(`searchOne`,t[0]):t.length===2?YV(`searchTwo`,t[0],t[1]):YV(`searchMore`,t[0],t[1])},tH=e=>Jt(QV.search(e.trim())),nH=e=>{let t=e.view?.searchResult?.title;return t?.length?t:[ar(e.model,e.view)]},rH=e=>{let t=nH(e);return e.view?.searchResult?.subtitle??e.model.search?.find(e=>!t.includes(e))},iH=e=>{let t=rH(e),n=[...nH(e),...t?[t]:[],...e.model.search??[]];return[...new Set([...e.model.primaryKey,...n.filter(t=>Object.hasOwn(e.model.fields,t))])]},aH=(e,t,n)=>{let r=t[n];return r==null?``:e.model.fields[n]?.type===`enum`?tr(String(r),e.view?.fields[n]?.valueLabels):String(r)},oH=(e,t,n,r=``)=>{let i=An(om(e.model,t)),a=nH(e),o=rH(e),s=Wt(e.model,t,n,[...a,...o?[o]:[]])??o,c=s?aH(e,t,s):``;return{id:i,title:a.map(n=>aH(e,t,n)).filter(Boolean).join(` `)||i,...c&&{subtitle:c},href:ic({kind:`record`,resource:e.model.name,key:i},r)}},sH=()=>{let e=W(),t=U(),{basePath:n}=mh(),r=(0,I.useMemo)(()=>$V(e),[e]),[i,a]=(0,I.useState)(``),o=i.trim(),s=mC(o,200),c=o.length>=2,l=c&&s.length>=2,u=f({queries:r.map(e=>({queryKey:[`global-search`,e.model.name,s],enabled:l,staleTime:1/0,gcTime:0,queryFn:()=>t.list(e.model.name,{filter:tH(s),pageSize:5,fields:iH(e)})}))}),d=(0,I.useMemo)(()=>l?ZV(e,s,n):[],[l,e,s,n]),p=r.flatMap((e,t)=>{let r=u[t];if(!l||!r)return[];if(r.error)return[{id:e.model.name,label:e.label,hits:[],failed:!0}];let i=(r.data?.items??[]).map(t=>oH(e,t,s,n));return i.length>0?[{id:e.model.name,label:e.label,hits:i}]:[]}),m=[...d,...p];return{available:Object.keys(e.pages).length>0||Object.keys(e.resources).length>0,placeholder:eH(r),text:i,setText:a,query:l?s:``,loading:c&&(o!==s||u.some(e=>e.isFetching)),groups:m}},cH=M({en:{title:`This app has been updated`,description:`Reload the page to use the new version, when it suits you.`,reload:`Reload`,reloadPage:`Reload page`,reloadPageHint:`Reload page to use the new version`,bannerTitle:`{} updated`,bannerLine:`Save your work, then click here to reload. You may see errors until you do.`},nl:{title:`Deze app is bijgewerkt`,description:`Laad de pagina opnieuw voor de nieuwe versie, wanneer het uitkomt.`,reload:`Opnieuw laden`,reloadPage:`Opnieuw laden`,reloadPageHint:`Opnieuw laden om de nieuwe versie te gebruiken`,bannerTitle:`{} bijgewerkt`,bannerLine:`Sla je werk op en klik hier om te herladen. Tot dan kunnen er fouten optreden.`}}),lH=()=>{let{versionChange:e,appName:t}=W(),{reload:n}=mh();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)(Do,{"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?Qg(cH(`bannerTitle`),t):cH(`title`)}),(0,B.jsx)(`span`,{className:`text-xs`,children:cH(`bannerLine`)})]})]}):null},uH=()=>{let e=!!W().versionChange,{reload:t}=mh();return e?(0,B.jsxs)(G,{size:`sm`,variant:`ghost`,"aria-label":cH(`reloadPageHint`),title:cH(`reloadPageHint`),onClick:t,className:`max-md:size-9 max-md:p-0`,children:[(0,B.jsx)(Do,{className:`size-3.5 text-primary`}),(0,B.jsx)(`span`,{className:`max-md:sr-only`,children:cH(`reloadPage`)})]}):null},dH=()=>document.querySelector(`[aria-modal="true"]`)!==null,fH=()=>{let[e,t]=(0,I.useState)(dH);return(0,I.useEffect)(()=>{let e=new MutationObserver(()=>t(dH()));return e.observe(document.body,{childList:!0,subtree:!0}),t(dH()),()=>e.disconnect()},[]),e},pH=()=>{let e=!!W().versionChange,t=fH(),[n,r]=(0,I.useState)(!1),i=Gf(),{reload:a}=mh(),o=e&&!n&&!t;return(0,I.useEffect)(()=>{if(!o)return;let e=i.show({state:`info`,sticky:!0,title:cH(`title`),description:cH(`description`),action:{label:cH(`reload`),onClick:a},onClose:()=>r(!0)});return()=>i.dismiss(e)},[o,i,a]),null},mH=M({en:{immediate:`Updates as soon as a release is out`,weekly:`Updates at a set time every week`,scheduled:`Updates at the time set for this release`,manual:`Updates only when asked to`,job:`Preparing the update`,build:`Building`,updatingNow:`Updating now`,started:(e,t)=>`${e}, started ${t}`,nextOn:(e,t)=>`${e}: next on ${t}`,succeeded:(e,t)=>`Updated to ${e} on ${t}`,unchanged:(e,t)=>`The update to ${e} on ${t} changed nothing`,failed:(e,t)=>`The update to ${e} failed on ${t}`,alreadyLatest:`Already on the latest version, or an update is running.`,onlyAdmin:`Only an admin can update the runtime.`,couldNotStart:`The update could not be started. Try again later.`,runtimeUpdate:`Runtime update`,close:`Close`,updating:`Updating…`,updateNow:`Update now`,currentVersion:`Current version`,latestVersion:`Latest version`,checkFailed:`The status could not be checked again; this is the last one read.`,updateAvailable:`Update available`,update:`Update`},nl:{immediate:`Werkt bij zodra er een release is`,weekly:`Werkt elke week op een vast moment bij`,scheduled:`Werkt bij op het moment dat voor deze release is ingesteld`,manual:`Werkt alleen bij als erom wordt gevraagd`,job:`De update voorbereiden`,build:`Bouwen`,updatingNow:`Nu aan het bijwerken`,started:(e,t)=>`${e}, begonnen ${t}`,nextOn:(e,t)=>`${e}: volgende op ${t}`,succeeded:(e,t)=>`Bijgewerkt naar ${e} op ${t}`,unchanged:(e,t)=>`De update naar ${e} op ${t} veranderde niets`,failed:(e,t)=>`De update naar ${e} mislukte op ${t}`,alreadyLatest:`Al op de nieuwste versie, of er loopt een update.`,onlyAdmin:`Alleen een beheerder kan de runtime bijwerken.`,couldNotStart:`De update kon niet worden gestart. Probeer het later opnieuw.`,runtimeUpdate:`Runtime-update`,close:`Sluiten`,updating:`Bijwerken…`,updateNow:`Nu bijwerken`,currentVersion:`Huidige versie`,latestVersion:`Nieuwste versie`,checkFailed:`De status kon niet opnieuw worden gecontroleerd; dit is de laatst gelezen.`,updateAvailable:`Update beschikbaar`,update:`Bijwerken`}}),hH=e=>!!(e?.updateAvailable&&e.indicator),gH=e=>e?5e3:18e5,_H=(e,t)=>{if(!e.updateStage)return mH(`updatingNow`);let n=mH(e.updateStage);return e.updateStartedAt?mH(`started`,n,bf(Math.max(0,Math.floor((t-Date.parse(e.updateStartedAt))/1e3)))):n},vH=(e,t=Date.now(),n=Gd())=>e.updating?_H(e,t):e.nextUpdateAt?mH(`nextOn`,mH(e.policy),ff(Date.parse(e.nextUpdateAt),n)):mH(e.policy),yH=(e,t=Gd())=>{let n=ff(Date.parse(e.finishedAt),t),r=mH(e.outcome,e.toVersion,n);return e.message?`${r}: ${e.message}`:`${r}.`},bH=e=>jc(e)&&e.status<500&&e.problem.detail?e.problem.detail:jc(e)&&e.status===409?mH(`alreadyLatest`):jc(e)&&e.status===403?mH(`onlyAdmin`):mH(`couldNotStart`),xH=({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})]}),SH=({status:e,requesting:t,error:n,checkError:r,onUpdate:i,onClose:a})=>{let o=e.updating?void 0:e.lastUpdate;return(0,B.jsxs)(vd,{title:mH(`runtimeUpdate`),description:e.updating?(0,B.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,B.jsx)(Yu,{className:`size-3.5`}),vH(e)]}):vH(e),onClose:a,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:a,children:mH(`close`)}),(0,B.jsx)(G,{variant:`primary`,loading:t,disabled:e.updating||!e.updateAvailable,onClick:i,children:e.updating?mH(`updating`):mH(`updateNow`)})]}),children:[(0,B.jsx)(xH,{label:mH(`currentVersion`),value:e.version}),(0,B.jsx)(xH,{label:mH(`latestVersion`),value:e.latest}),o&&(0,B.jsx)(`p`,{className:o.outcome===`failed`?`mt-3 text-danger-text`:`mt-3 text-muted-foreground`,children:yH(o)}),n!==void 0&&(0,B.jsx)(`p`,{role:`alert`,className:`mt-3 text-danger-text`,children:bH(n)}),r!==void 0&&(0,B.jsx)(`p`,{className:`mt-3 text-muted-foreground`,children:mH(`checkFailed`)})]})},CH=e=>{let t=aN(),n=(0,I.useRef)(t);n.current=t;let r=t!==void 0;return(0,I.useMemo)(()=>r?Ql({url:e,token:()=>n.current}):void 0,[e,r])},wH=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(),gH(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}},TH=({client:e})=>{let{status:t,update:n,requesting:r,error:i,checkError:a}=wH(e),[o,s]=(0,I.useState)(!1);return!t||!o&&!hH(t)?null:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(G,{size:`sm`,variant:`ghost`,"aria-label":mH(`updateAvailable`),title:mH(`updateAvailable`),onClick:()=>s(!0),className:`max-md:size-9 max-md:p-0`,children:[(0,B.jsx)(bi,{className:`size-3.5 text-primary`}),(0,B.jsx)(`span`,{className:`max-md:sr-only`,children:mH(`update`)})]}),o&&(0,B.jsx)(SH,{status:t,requesting:r,error:i,checkError:a,onUpdate:()=>void n(),onClose:()=>s(!1)})]})},EH=({url:e})=>(0,B.jsx)(TH,{client:CH(e)}),DH=({url:e,client:t})=>t?(0,B.jsx)(TH,{client:t}):(0,B.jsx)(EH,{url:e}),OH=({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 yl))throw e;a(ZO(e)),r(!1)}};return(0,B.jsxs)(`div`,{role:`region`,"aria-label":J(`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)(Ts,{"aria-hidden":!0,className:`size-4 shrink-0`}),(0,B.jsx)(`p`,{className:`min-w-64 flex-1 break-words`,children:Qg(J(`staffSignedIn`),(0,B.jsx)(`span`,{className:`font-semibold`,children:e.staffName??e.staff}),(0,B.jsx)(`span`,{className:`font-semibold`,children:e.user}),ff(Date.parse(e.expiresAt)),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:J(`stopStaffSession`)})]})},kH=(e,t,n)=>({filter:n.filter??``,orderBy:n.orderBy??Qm(e,t),pageSize:n.limit??3,fields:[...new Set([...e.primaryKey,ar(e,t),...n.status===void 0?[]:[n.status]])]}),AH=(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?tr(i,t.fields[n.status]?.valueLabels):i,tone:n.tones?.[i]??`neutral`,pulse:n.pulse?.includes(i)??!1}},jH=(e,t,n,r,i,a)=>r.map(r=>{let o=An(om(e,r)),s=AH(e,t,n,r);return{id:o,label:or(e,t,r,o),href:ic({kind:`record`,resource:e.name,key:o},i),...s&&{status:s},active:o===a}}),MH=(e,t,n,r,i)=>{let a=n.find(t=>An(om(e,t))===r);return a!==void 0&&t.some(e=>!Object.is(a[e],i[e]))},NH=({model:e,request:t})=>H.navRecent(e.name,t.filter,t.orderBy,t.pageSize),PH=e=>{let t=be();(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(NH(n));e&&MH(n.model,n.request.fields,e.items,a,o)&&t.invalidateQueries({queryKey:NH(n),exact:!0})}}),[t,e])},FH=(e,t,n)=>{let r=U(),i=(0,I.useMemo)(()=>{let t=oR(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:kH(r,n,i)}]:[]})},[e]);PH(i);let a=f({queries:i.map(e=>({queryKey:NH(e),queryFn:()=>r.list(e.model.name,e.request)}))});return Object.fromEntries(i.map(({model:e,view:r,recent:i},o)=>{let s=a[o];if(s.isPending)return[e.name,{state:`loading`}];if(s.isError)return[e.name,{state:`error`}];let c=n.resource===e.name?n.key:void 0;return[e.name,{state:`ready`,records:jH(e,r,i,s.data.items,t,c)}]}))},IH=e=>e?.kind===`page`?e.page:e?.kind===`list`?cR(e.resource,e.list):e?.resource,LH=e=>e?.kind===`record`?e:void 0,RH=({workspace:e,sidebarMode:t,assistant:n,runtime:r})=>{let i=W(),{state:a,session:o,signOut:s,stopStaffSession:c,organizations:l}=V(),u=mw();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}=mh(),{address:g,go:_,open:v,back:y}=Th(),b=IH(g),x=LH(g),S=sH(),C=TN(),w=FH(i,h,{resource:x?.resource,key:x?.key});cN(i);let T=dR(i,h,w),E=(0,I.useMemo)(()=>Oz(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?Ku(i,O):void 0,A=O?Sn(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=uN(x?.resource??``,x?.key??``,!!(ee&&x)),ne=ee&&x&&te.data?or(ee,A,te.data.record,x.key):void 0,re=!!x&&(te.isLoading||k?.state===`loading`),{shell:ie}=Wg(),ae=ie?.actions,oe=ie?.rightPanel,se=i.bell&&d&&!f&&(0,B.jsx)(Jz,{own:ie?.bell}),[ce,le]=(0,I.useState)(!1),ue=i.assistant?.url,de=ue&&(0,B.jsx)(TP,{open:ce,onToggle:()=>le(!ce)}),fe=ue&&ce&&(0,B.jsx)(OP,{url:ue,client:n,page:m.size>0?`${p}?${m}`:p,onClose:()=>le(!1)}),pe=i.errorReporting;(0,I.useEffect)(()=>{pe&&Yg(pe)},[pe]);let me=i.runtime?.url,he=me&&(0,B.jsx)(DH,{url:me,client:r}),ge=wb(t??`text-small`),_e=i.versionChange&&!ge&&(0,B.jsx)(uH,{}),ve=Dz((0,I.useCallback)(()=>fz(h),[h]),!!d),ye=d&&wz(d,ve.current),be=ye?eN(ye):!1,xe=Xz(),Se=dz(!!(l&&d)),Ce=Se.current,we=!!l&&Ce!==void 0&&!Ce.organization,Te=l&&d?mk(p):void 0,Ee=zA(),De=d?Us(p):void 0,Oe=De&&Ee?od(ad(Ee.tree),De.tab):void 0,ke=d?De?Ee?.title??J(`account`):p===`/-/sign-in-policy`?J(`signInPolicy`):Te:void 0,Ae=A?.names?.plural??(O&&F(O)),je=ke?[ke]:PP({basePath:h,address:g,group:j?.label,page:D,resourceLabel:Ae,recordTitle:ne,recordLoading:re}),Me=A?.names?.singular??(O&&F(O)),M=D&&g?.kind===`page`?od(ad(D.tree),g.tab):void 0;UA(HA(VA({address:g,page:D?{title:D.title,...M&&{tab:M.label}}:De&&Ee&&{title:Ee.title,...Oe&&{tab:Oe.label}},accountPage:ke,resourceLabel:Ae,singular:Me,recordTitle:ne,recordLoading:re}),i.appName));let Ne=De?(0,B.jsx)(BA,{...De}):d&&p===`/-/sign-in-policy`?be?(0,B.jsx)(Cj,{}):(0,B.jsx)(Zu,{title:J(`adminsOnly`),children:J(`onlyAdminPolicy`)}):Te&&p===`/-/organization`?(0,B.jsx)(_z,{current:Ce,basePath:h,onChanged:Se.reload}):Te&&(p===`/-/organization/members`||p===`/-/organization/invitations`)?_k(Ce)?p===`/-/organization/members`?(0,B.jsx)(sz,{current:Ce}):(0,B.jsx)(uz,{current:Ce}):(0,B.jsx)(Zu,{title:J(`ownersOnly`),children:J(`onlyOwners`)}):Te&&p===`/-/organizations`||we?(0,B.jsx)(Cz,{state:Se,basePath:h}):g?g.kind===`page`?D?(0,B.jsx)(FP,{name:D.name,...g.tab&&{tab:g.tab}},D.name):(0,B.jsx)(Zu,{title:J(`notFound`),children:Qg(J(`noPage`),g.page)}):k&&k.state!==`ready`?(0,B.jsx)(JV,{status:k}):g.kind===`create`?(0,B.jsx)(UP,{resource:g.resource,values:g.values},g.resource):g.kind===`record`?(0,B.jsx)(WV,{resource:g.resource,recordKey:g.key},`${g.resource}/${g.key}`):(0,B.jsx)(rz,{address:g},cR(g.resource,g.list)):p===`/`?(0,B.jsx)(Zu,{title:J(`chooseResource`),children:J(`pickFromSidebar`)}):(0,B.jsx)(Zu,{title:J(`notFound`),children:J(`nothingHere`)}),Pe=be&&xe.length>0;return(0,B.jsx)(Pb,{pageScroll:!0,sidebarMode:t??`text-small`,activeItem:b??``,breadcrumb:je,user:ye&&nN(ye),onSignOut:d&&(()=>void s()),signIn:d?void 0:u.link(),workspace:Ce?.organization?.name??e,appName:i.appName,appIcon:i.appIcon,logo:kz,navGroups:T,bottomBar:NP(i,h,b),userMenu:[sR(i,h,b),l&&d?vk(h,p,Ce):[],d?Gs(h,p,be):[]],account:d&&`${h}/-/account`,organizations:l&&{...Ce?.organization&&{current:{id:Ce.organization.id,name:Ce.organization.name}},others:Se.organizations.filter(e=>e.id!==Ce?.organization?.id),onSwitch:e=>void o.organizations.switchTo(e).then(()=>fz(h))},theme:{preference:C.preference,onChange:C.choose},roles:ve.current?.active?{active:ve.current.active,roles:ve.current.roles,onSwitch:ve.switchTo}:void 0,onNavigate:v,onBack:y,sidebarNotice:(0,B.jsx)(lH,{}),banner:(f||Pe)&&(0,B.jsxs)(B.Fragment,{children:[f&&(0,B.jsx)(OH,{signIn:f,onStop:c}),Pe&&(0,B.jsx)(Qz,{off:xe})]}),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:(ae||se||_e||he||de)&&(0,B.jsxs)(B.Fragment,{children:[ae&&(0,B.jsx)($g,{name:`shell.actions`,fallback:null,children:(0,B.jsx)(ae,{})}),se,_e,he,de]}),rightPanel:(oe||fe)&&(0,B.jsxs)(B.Fragment,{children:[oe&&(0,B.jsx)($g,{name:`shell.rightPanel`,fallback:null,children:(0,B.jsx)(oe,{})}),fe]}),children:Ne})},zH=({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=wb(i??`text-small`),{path:f}=mh();return(0,B.jsx)(Lu,{baseUrl:e,client:t,sources:n,token:c.kind===`visitor`?void 0:l.token,onUnauthenticated:u,children:(0,B.jsx)($u,{children:(0,B.jsxs)(Kf,{children:[!d&&(0,B.jsx)(pH,{}),f===`/-/connect`?(0,B.jsx)(dj,{}):(0,B.jsx)(Zz,{ui:a,children:(0,B.jsx)(RH,{workspace:r,sidebarMode:i,assistant:o,runtime:s})})]})})})},BH=({baseUrl:e,client:t,ui:n,children:r})=>{let i=hN();return i?(0,B.jsx)(Lu,{baseUrl:e,client:t,children:(0,B.jsx)(Ug.Provider,{value:n??{},children:(0,B.jsx)(pN,{name:i.name},i.name)})}):r},VH=({auth:e,workspace:t,basePath:n,initialUrl:r,pluginLoader:i,locale:a,nativeBridge:o,...s})=>(Ne(a??`en`),(0,B.jsx)(wN,{children:(0,B.jsx)(Tu,{session:e,...s.baseUrl&&{origin:new URL(s.baseUrl,window.location.href).origin},...o&&{nativeBridge:o},children:(0,B.jsx)(Sh,{basePath:n,initialUrl:r,children:(0,B.jsx)(VM,{...i&&{loader:i},children:(0,B.jsx)(oN,{children:(0,B.jsx)(BH,{baseUrl:s.baseUrl,client:s.client,ui:s.ui,children:(0,B.jsx)(YM,{workspace:t,children:(0,B.jsx)(zH,{workspace:t,...s})})})})})})})}));export{Qy as $,lN as A,Yu as At,GA as B,KN as C,Gd as Ct,NN as D,G as Dt,RN as E,vd as Et,xM as F,H as Ft,dO as G,YA as H,mM as I,wu as It,nT as J,RD as K,Tj as L,$l as Lt,NM as M,Lu as Mt,PM as N,U as Nt,kN as O,ld as Ot,OM as P,Nu as Pt,XS as Q,wj as R,qN as S,Zd as St,UN as T,xd as Tt,Ck as U,JA as V,bO as W,Qw as X,$w as Y,_w as Z,iP as _,np as _t,Uz as a,A_ as at,$N as b,Yf as bt,RP as c,Vg as ct,xP as d,Cg as dt,ny as et,bP as f,_g as ft,aP as g,Op as gt,cP as h,Th as ht,Vz as i,B_ as it,aN as j,Vu as jt,EN as k,W as kt,wP as l,Lg as lt,dP as m,Eh as mt,vV as n,vv as nt,Bz as o,i_ as ot,gP as p,gg as pt,zD as q,_V as r,_v as rt,jz as s,Hg as st,VH as t,gv as tt,CP as u,Dg as ut,rP as v,ep as vt,GN as w,Id as wt,XN as x,_f as xt,eP as y,Xf as yt,WA as z};
|
|
9
|
-
//# debugId=3b2c6b75-0298-401b-9dd9-e65aa4be43fc
|