@protobase/ui 0.66.1 → 0.66.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/account/blocks/personal-mail-block.js +1 -0
- package/dist/account/sign-in-providers-section.js +5 -4
- package/dist/locale/en.js +1 -0
- package/dist/locale/nl.js +1 -0
- package/dist/package.js +1 -1
- package/dist/shell/assets/{app-D-elg6qm.js → app-wLUA_tPR.js} +7 -7
- package/dist/shell/assets/{calls-DHvl29Pd.js → calls-Dr-DRqHd.js} +2 -2
- package/dist/shell/assets/export-worker-BKuC4P2E.js +15 -0
- package/dist/shell/assets/{index-D8SK4U2s.js → index-DRGgkOjf.js} +2 -2
- package/dist/shell/assets/{maplibre-sUHB6Qig.js → maplibre-lc2A-_P4.js} +2 -2
- package/dist/shell/assets/parse-worker-BzLD2jKf.js +35 -0
- package/dist/shell/assets/preload-helper-DedkISGJ.js +2 -0
- package/dist/shell/assets/{record-map-CZ__Yamf.js → record-map-CupIwJyD.js} +2 -2
- package/dist/shell/assets/{records-map-hxWNR_fi.js → records-map-DAJkSlba.js} +2 -2
- package/dist/shell/assets/{shared-protobase-ui-7FTH3m59.js → shared-protobase-ui-DIN4Js5c.js} +2 -2
- package/dist/shell/index.html +4 -4
- package/dist/shell/protobase.shell.json +2 -2
- package/dist/shell/protobase.sw.js +2 -2
- package/dist/shell-source-maps/assets/app-wLUA_tPR.js.map +1 -0
- package/dist/shell-source-maps/assets/{calls-DHvl29Pd.js.map → calls-Dr-DRqHd.js.map} +1 -1
- package/dist/shell-source-maps/assets/export-worker-BKuC4P2E.js.map +1 -0
- package/dist/shell-source-maps/assets/{index-D8SK4U2s.js.map → index-DRGgkOjf.js.map} +1 -1
- package/dist/shell-source-maps/assets/{maplibre-sUHB6Qig.js.map → maplibre-lc2A-_P4.js.map} +1 -1
- package/dist/shell-source-maps/assets/parse-worker-BzLD2jKf.js.map +1 -0
- package/dist/shell-source-maps/assets/preload-helper-DedkISGJ.js.map +1 -0
- package/dist/shell-source-maps/assets/{record-map-CZ__Yamf.js.map → record-map-CupIwJyD.js.map} +1 -1
- package/dist/shell-source-maps/assets/{records-map-hxWNR_fi.js.map → records-map-DAJkSlba.js.map} +1 -1
- package/dist/shell-source-maps/assets/{shared-protobase-ui-7FTH3m59.js.map → shared-protobase-ui-DIN4Js5c.js.map} +1 -1
- package/package.json +4 -4
- package/dist/shell/assets/export-worker-Bux-6dp9.js +0 -15
- package/dist/shell/assets/parse-worker-CbZA-uNr.js +0 -35
- package/dist/shell/assets/preload-helper-BRlYOzPJ.js +0 -2
- package/dist/shell-source-maps/assets/app-D-elg6qm.js.map +0 -1
- package/dist/shell-source-maps/assets/export-worker-Bux-6dp9.js.map +0 -1
- package/dist/shell-source-maps/assets/parse-worker-CbZA-uNr.js.map +0 -1
- package/dist/shell-source-maps/assets/preload-helper-BRlYOzPJ.js.map +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
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-
|
|
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,ct as ie,d as ae,et as oe,f as se,g as ce,h as le,i as ue,it as de,j as fe,k as pe,l as me,lt as he,m as ge,n as _e,nt as ve,o as ye,ot as be,p as xe,q as Se,r as Ce,rt as we,s as Te,st as Ee,t as De,u as Oe,v as ke,w as Ae,x as je,y as Me,z as Ne}from"./vendor-Kvdo8Jrw.js";import{a as M,d as Pe,f as Fe,i as Ie,l as Le,n as Re,o as N,r as ze,s as Be,t as Ve,u as He}from"./preload-helper-BRlYOzPJ.js";import{t as P}from"./cn-Bi0ZEjD9.js";var Ue=(e,t,n,r)=>({code:e,message:t,hint:n,span:r}),We=(e,t)=>{let n=Array.from({length:t.length+1},(e,t)=>t);for(let r=1;r<=e.length;r++){let i=[r];for(let a=1;a<=t.length;a++){let o=e[r-1]===t[a-1]?0:1;i[a]=Math.min(n[a]+1,i[a-1]+1,n[a-1]+o)}n=i}return n[t.length]},Ge=(e,t)=>{let n=e.toLowerCase(),r=t.map(e=>({candidate:e,score:We(n,e.toLowerCase())})).sort((e,t)=>e.score-t.score)[0];return r&&r.score<=Math.max(2,Math.floor(e.length/3))?r.candidate:void 0},Ke={in:{params:[{name:`field`,type:`field`}],rest:{name:`value`,type:`any`}},search:{params:[{name:`text`,type:`string`}]},similar:{params:[{name:`field`,type:`field`,of:[`string`]},{name:`text`,type:`string`}]},regex:{params:[{name:`field`,type:`field`,of:[`string`]},{name:`pattern`,type:`string`}]},isNull:{params:[{name:`field`,type:`field`}]},now:{params:[],returns:`timestamp`}},qe={extensions:{arithmetic:`now-offset`,durationUnits:!0}},Je=e=>{switch(e.type){case`text`:return`string`;case`integer`:case`bigint`:return`integer`;case`boolean`:case`timestamp`:case`enum`:return e.type;default:return`any`}},Ye=e=>({fields:Object.fromEntries(Object.values(e.fields).map(e=>[e.name,{type:Je(e),filterable:e.filterable,sortable:e.sortable,aliases:e.aliases,...e.enumValues&&{values:e.enumValues}}])),functions:Ke}),Xe=(e,t,n,r)=>{e.errors.push(Ue(`unsupported`,t,n,r))},Ze=(e,t)=>t.kind===`member`?{kind:`field`,path:t.path,span:t.span}:Xe(e,`Only fields can be compared`,`Put a field name on the left, for example total > 100`,t.span),Qe=(e,t)=>{switch(t.kind){case`member`:return{kind:`string`,value:t.path.join(`.`),span:t.span};case`call`:return t.name===`now`&&t.args.length===0?{kind:`now`,span:t.span}:Xe(e,`${t.name}() cannot be used as a value`,`Only now() is a value function`,t.span);case`binary`:{let n=t.left;return n.kind===`call`&&n.name===`now`&&n.args.length===0&&t.right.kind===`duration`?{kind:`now`,offset:{sign:t.op,duration:t.right},span:t.span}:Xe(e,`Arithmetic is only supported as now() +/- duration`,`Write now() - 30d`,t.span)}default:return t}},$e=(e,t)=>(`kind`in t&&[`member`,`call`,`binary`].includes(t.kind)?void 0:t)||(t.kind===`member`?{kind:`string`,value:t.path.join(`.`),span:t.span}:Xe(e,`Expected a literal value`,`Use strings, numbers, true/false, durations or timestamps`,t.span)),et=e=>{switch(e.kind){case`member`:return e.path.join(`.`);case`string`:case`timestamp`:return e.kind,e.value;case`number`:return e.raw;case`boolean`:return String(e.value);case`duration`:return`${e.amount}${e.unit}`;default:return``}},tt=(e,t)=>{let[n,r,...i]=t.args,a=n?.kind===`member`?Ze(e,n):void 0,o=e=>e?.kind===`string`?e.value:void 0,s=n=>{e.errors.push(Ue(`invalid-arguments`,`Invalid arguments to ${t.name}()`,`Usage: ${n}`,t.span))};switch(t.name){case`in`:{let n=t.args.slice(1).map(t=>$e(e,t));return!a||n.length===0?s(`in(field, value1, value2, ...)`):n.every(e=>e)?{kind:`in`,field:a,values:n,span:t.span}:void 0}case`search`:return o(n)!==void 0&&!r?{kind:`search`,text:o(n),span:t.span}:s(`search("text")`);case`similar`:return a&&o(r)!==void 0&&i.length===0?{kind:`similar`,field:a,text:o(r),span:t.span}:s(`similar(field, "text")`);case`regex`:return a&&o(r)!==void 0&&i.length===0?{kind:`regex`,field:a,pattern:o(r),span:t.span}:s(`regex(field, "pattern")`);case`isNull`:return a&&!r?{kind:`isNull`,field:a,span:t.span}:s(`isNull(field)`);default:e.errors.push(Ue(`unknown-function`,`Unknown function "${t.name}"`,`Available functions: ${Object.keys(Ke).join(`, `)}`,t.span));return}},nt=e=>e.every(e=>e)?e:void 0,rt=(e,t)=>{switch(t.kind){case`sequence`:case`and`:case`or`:{let n=nt(t.args.map(t=>rt(e,t)));return n&&{kind:t.kind===`or`?`or`:`and`,args:n,span:t.span}}case`not`:{let n=rt(e,t.arg);return n&&{kind:`not`,arg:n,span:t.span}}case`compare`:{let n=Ze(e,t.left),r=Qe(e,t.right);return n&&r&&{kind:`compare`,op:t.op,field:n,value:r,span:t.span}}case`has`:{let n=Ze(e,t.left),r=$e(e,t.right);return n&&r&&{kind:`has`,field:n,value:r,span:t.span}}case`present`:{let n=Ze(e,t.left);return n&&{kind:`present`,field:n,span:t.span}}case`global`:return{kind:`search`,text:et(t.value),span:t.span};case`call`:return tt(e,t)}},it=(e,t={})=>{let n=ie(e,{...qe,...t}),r={errors:[]},i=n.ast&&rt(r,n.ast),a=[...n.errors,...r.errors].sort((e,t)=>e.span.start-t.span.start);return a.length===0?{ok:!0,ast:i,errors:[]}:{ok:!1,ast:i,errors:a}},at=(e,t)=>t===2?e%4==0&&(e%100!=0||e%400==0)?29:28:[4,6,9,11].includes(t)?30:31,ot=e=>{let t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e);if(!t)return!1;let[n,r,i]=[Number(t[1]),Number(t[2]),Number(t[3])];return r>=1&&r<=12&&i>=1&&i<=at(n,r)},st=e=>{let t=/^(\d{4}-\d{2}-\d{2})[Tt](\d{2}):(\d{2}):(\d{2})(?:\.\d+)?(?:[Zz]|[+-](\d{2}):(\d{2}))$/.exec(e);if(!t)return!1;let[n,r,i]=[Number(t[2]),Number(t[3]),Number(t[4])],[a,o]=[Number(t[5]??0),Number(t[6]??0)];return ot(t[1])&&n<=23&&r<=59&&i<=59&&a<=23&&o<=59},ct=(e,t)=>({message:e,hint:t}),lt=-(2n**63n),ut=2n**63n-1n,dt=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,ft=e=>e.kind===`number`?e.raw:e.kind===`string`?e.value:void 0,pt=(e,t=`Write ${e} values like the examples in the docs`)=>ct(`Expected ${e}`,t),mt=e=>{let t=ft(e),n=t===void 0?NaN:Number(t);if(t===void 0||t.trim()===``||!Number.isSafeInteger(n))return pt(`a whole number`,`Use an integer such as 42, or a bigint field for larger values`)},ht=e=>{let t=ft(e);if(t===void 0||!/^-?\d+$/.test(t)||BigInt(t)<lt||BigInt(t)>ut)return pt(`a 64-bit integer`,`Use plain digits such as 9007199254740993 (no exponent or fraction)`)},gt=e=>{let t=ft(e);if(t===void 0||!/^-?\d+(\.\d+)?$/.test(t))return pt(`a decimal number`,`Use plain digits such as 100.50, or quote it: "100.50" (no exponent)`)},_t=(e,t)=>{if(t.kind===`now`)return e.type===`date`||e.type===`timestamp`?void 0:ct(`now() only works with date and timestamp fields`,`Field "${e.name}" is ${e.type}`);switch(e.type){case`text`:return t.kind===`string`?void 0:pt(`a quoted string`,`Wrap the text in double quotes`);case`integer`:return mt(t);case`bigint`:return ht(t);case`decimal`:return gt(t);case`boolean`:return t.kind===`boolean`?void 0:pt(`true or false`);case`date`:return t.kind===`string`&&ot(t.value)?void 0:pt(`a date`,`Quote a calendar date: "2012-04-21"`);case`timestamp`:return t.kind===`timestamp`||t.kind===`string`&&st(t.value)?void 0:pt(`an RFC-3339 timestamp`,`Use 2012-04-21T11:30:00Z, or now() - 7d`);case`uuid`:return t.kind===`string`&&dt.test(t.value)?void 0:pt(`a uuid`,`Quote a uuid like "0b5a4f0e-6f2a-4a3c-9d4e-1f2a3b4c5d6e"`);case`enum`:return t.kind===`string`&&e.enumValues?.includes(t.value)?void 0:ct(`Invalid enum value`,`Allowed values: ${(e.enumValues??[]).join(`, `)}`);case`currency`:return t.kind===`string`&&/^[A-Z]{3}$/.test(t.value)?void 0:pt(`an ISO 4217 currency code`,`Use three capital letters, for example "EUR"`);case`country`:return t.kind===`string`&&/^[A-Z]{2}$/.test(t.value)?void 0:pt(`an ISO 3166-1 country code`,`Use two capital letters, for example "NL"`);case`relation`:return t.kind===`string`||t.kind===`number`&&Number.isSafeInteger(t.value)?void 0:pt(`a record key`,`Use the related record key: 42 or "abc"`);case`json`:case`file`:return ct(`${e.type} fields cannot be compared`,`Use field:value on json fields, or isNull(field)`)}},vt=(e,t)=>Object.hasOwn(e.fields,t)?e.fields[t]:Object.values(e.fields).find(e=>e.aliases.includes(t)),yt=(e,t,n)=>{if(t.path.length>1){e.errors.push(Ue(`unsupported-traversal`,`Traversal into "${t.path.join(`.`)}" is not supported yet`,`Filter on fields of this resource only`,t.span));return}let r=t.path[0],i=vt(e.model,r);if(!i){let i=Object.values(e.model.fields).filter(e=>e[n]).map(e=>e.name),a=Ge(r,i);e.errors.push(Ue(`unknown-field`,`Unknown field "${r}"`,a?`Did you mean "${a}"?`:`Available fields: ${i.join(`, `)}`,t.span));return}if(!i[n]){let r=n===`filterable`?`filterable`:`sortable`;e.errors.push(Ue(n===`filterable`?`not-filterable`:`not-sortable`,`Field "${i.name}" is not ${r}`,`Mark it with .${r}() in data.ts`,t.span));return}return i},bt=[`=`,`!=`],xt=[`=`,`!=`,`<`,`<=`,`>`,`>=`],St=e=>{switch(e){case`text`:case`integer`:case`bigint`:case`decimal`:case`date`:case`timestamp`:return xt;case`json`:case`file`:return[];default:return bt}},Ct=e=>e===`json`||e===`file`,wt=(e,t,n)=>{let r=_t(t,n);return r&&e.errors.push(Ue(`invalid-value`,r.message,r.hint,n.span)),!r},Tt=(e,t,n,r)=>{e.errors.push(Ue(`operator-not-allowed`,t,n,r))},Et=(e,t)=>(e===`=`||e===`!=`)&&t.kind===`string`&&t.value.includes(`*`),Dt=(e,t)=>{let n=yt(e,t.field,`filterable`);if(!n)return;let r=St(n.type);if(!r.includes(t.op)){Tt(e,`Operator "${t.op}" is not supported for ${n.type} fields`,r.length?`Supported: ${r.join(` `)}`:`Use field:value on json fields, or isNull(field)`,t.span);return}if(Et(t.op,t.value)&&n.type!==`text`){e.errors.push(Ue(`wildcard-not-allowed`,`Wildcards are only supported on text fields, not ${n.type}`,`Remove the "*" or filter a text field`,t.value.span));return}if(Et(t.op,t.value)||wt(e,n,t.value))return{...t,field:n}},Ot=(e,t)=>{let n=yt(e,t.field,`filterable`);if(n){if(n.type!==`json`){Tt(e,`":" is only supported on json fields, not ${n.type}`,`Use = on ${n.type} fields, or field:* to test for a value`,t.span);return}return{...t,field:n}}},kt=(e,t)=>{let n=yt(e,t.field,`filterable`);if(n){if(Ct(n.type)){Tt(e,`in() is not supported for ${n.type} fields`,`Use field:value on json fields`,t.span);return}return t.values.map(t=>wt(e,n,t)).every(Boolean)?{...t,field:n}:void 0}},At=(e,t,n)=>{let r=yt(e,n,`filterable`);if(r&&r.type!==`text`){Tt(e,`${t}() only works on text fields, not ${r.type}`,`Field "${r.name}" is ${r.type}`,n.span);return}return r},jt=(e,t)=>{switch(t.kind){case`and`:case`or`:{let n=t.args.map(t=>jt(e,t));return n.every(e=>e)?{...t,args:n}:void 0}case`not`:{let n=jt(e,t.arg);return n&&{...t,arg:n}}case`compare`:return Dt(e,t);case`has`:return Ot(e,t);case`in`:return kt(e,t);case`search`:if(e.model.search?.length)return t;e.errors.push(Ue(`no-search-fields`,`This resource has no search fields`,`Declare them with .search((r) => [r.title]) in data.ts`,t.span));return;case`present`:case`isNull`:{let n=yt(e,t.field,`filterable`);return n&&{...t,field:n}}case`similar`:case`regex`:{let n=At(e,t.kind,t.field);return n&&{...t,field:n}}}},Mt=(e,t)=>{let n={model:e,errors:[]},r=jt(n,t);return!r||n.errors.length>0?{ok:!1,errors:[...n.errors].sort((e,t)=>e.span.start-t.span.start)}:{ok:!0,filter:r}},Nt=(e,t)=>`path`in e?{kind:`member`,path:e.path,span:e.span}:{kind:`member`,path:[e.name],field:{name:e.name,spec:{type:Je(e)}},span:t},Pt=(e,t,n)=>({kind:`call`,name:e,args:t,span:n}),Ft=(e,t)=>({kind:`string`,value:e,span:t}),It=e=>{if(e.kind!==`now`)return e;let t={kind:`call`,name:`now`,args:[],span:e.span};return e.offset?{kind:`binary`,op:e.offset.sign,left:t,right:e.offset.duration,span:e.span}:t},Lt=(e,t={})=>{let n=e=>Lt(e,t);switch(e.kind){case`and`:case`or`:return{kind:e.kind,args:e.args.map(n),span:e.span};case`not`:return{kind:`not`,arg:n(e.arg),span:e.span};case`compare`:return{kind:`compare`,op:e.op,left:Nt(e.field,e.span),right:It(e.value),span:e.span};case`has`:return{kind:`has`,left:Nt(e.field,e.span),right:e.value,span:e.span};case`present`:return{kind:`present`,left:Nt(e.field,e.span),span:e.span};case`in`:return t.expand?{kind:`or`,args:e.values.map(t=>({kind:`compare`,op:`=`,left:Nt(e.field,e.span),right:t,span:e.span})),span:e.span}:Pt(`in`,[Nt(e.field,e.span),...e.values],e.span);case`search`:return Pt(`search`,[Ft(e.text,e.span)],e.span);case`similar`:return Pt(`similar`,[Nt(e.field,e.span),Ft(e.text,e.span)],e.span);case`regex`:return Pt(`regex`,[Nt(e.field,e.span),Ft(e.pattern,e.span)],e.span);case`isNull`:return t.expand?{kind:`not`,arg:{kind:`present`,left:Nt(e.field,e.span),span:e.span},span:e.span}:Pt(`isNull`,[Nt(e.field,e.span)],e.span)}},Rt=(e,t)=>{let n=Mt(e,t);if(!n.ok&&n.errors.some(e=>e.code===`unsupported-traversal`))return n;let r=be(Lt(t),Ye(e));return r.ok?Mt(e,t):{ok:!1,errors:r.errors}},zt=/^[\d\s+\-().\/]+$/,Bt=e=>zt.test(e)?e.replace(/\D/g,``):``,Vt=e=>{let t=e.split(/\s+/).filter(Boolean).map(e=>({text:e,digits:Bt(e),whole:!1})),n=t.length>1?Bt(e.trim()):``;return n?[{text:e.trim(),digits:n,whole:!0},...t]:t},Ht=(e,t,n)=>e==null?!1:n===`digitsEnd`?t.digits!==``&&String(e).replace(/\D/g,``).endsWith(t.digits):!t.whole&&String(e).toLowerCase().includes(t.text.toLowerCase()),Ut=(e,t,n)=>(e.search??[]).filter(r=>Ht(t[r],n,e.searchMatch?.[r])),Wt=(e,t,n)=>{let r=Vt(n),i=r.filter(e=>!e.whole),a=r.find(e=>e.whole);return a&&Ut(e,t,a).length>0?!0:i.length>0&&i.every(n=>Ut(e,t,n).length>0)},Gt=(e,t,n,r)=>{for(let i of Vt(n)){let n=Ut(e,t,i);if(n.length>0&&!n.some(e=>r.includes(e)))return n[0]}},Kt=e=>()=>{throw Error(`Not implemented: ${e}() needs the database (the resource's search fields, trigram matching), so it cannot be evaluated against a record`)},qt=(e,t,n)=>({...Ke,search:{...Ke.search,evaluate:n?e=>Wt(n,t,e):Kt(`search`)},similar:{...Ke.similar,evaluate:Kt(`similar`)},regex:{...Ke.regex,evaluate:(e,t)=>e.some(e=>typeof e==`string`&&new RegExp(t).test(e))},now:{...Ke.now,evaluate:e}}),Jt=(e,t,n={})=>Ee(Lt(e,{expand:!0}),t,{functions:qt(n.now??(()=>new Date),t,n.search)}),Yt=e=>he(Lt(e)),Xt=e=>e.map(e=>({path:e.path.path,direction:e.direction,span:e.span})),Zt=e=>e.replace(/([^\s,])(\s+)(asc|desc)(?=\s|,|$)/gi,(e,t,n,r)=>`${t}${n}${r.toLowerCase()}`),Qt=e=>{let t=te(Zt(e)),n=t.items.map(e=>({path:{kind:`field`,path:e.path,span:e.span},direction:e.direction,span:e.span}));return t.ok?{ok:!0,items:n,errors:[]}:{ok:!1,items:n,errors:t.errors}},$t=(e,t)=>{let n=t.filter(e=>e.path.path.length>1).map(e=>Ue(`unsupported-traversal`,`Traversal into "${e.path.path.join(`.`)}" is not supported yet`,`Sort on fields of this resource only`,e.path.span));if(n.length>0)return{ok:!1,errors:n};let r=de(Xt(t),Ye(e));return r.ok?{ok:!0,sort:r.items.map(e=>[e.path[0],e.direction])}:{ok:!1,errors:r.errors}},en=e=>{let t=/^(\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)([smhdw])$/.exec(e);if(!t)throw Error(`Invalid duration "${e}", expected for example 30d or 1.5h`);return{kind:`duration`,amount:Number(t[1]),unit:t[2],span:{start:0,end:0}}},tn={start:0,end:0},nn=e=>({kind:`field`,path:e.split(`.`),span:tn}),rn=e=>{if(typeof e==`string`)return{kind:`string`,value:e,span:tn};if(typeof e==`boolean`)return{kind:`boolean`,value:e,span:tn};if(!Number.isFinite(e))throw Error(`Filter numbers must be finite`);return{kind:`number`,value:e,raw:String(e),span:tn}},an=e=>typeof e==`object`?e:rn(e),on=(e,t)=>{if(t.length===0)throw Error(`where.${e} needs at least one filter`);return t.length===1?t[0]:{kind:e,args:t,span:tn}},sn=()=>{let e=e=>(t,n)=>({kind:`compare`,op:e,field:nn(t),value:an(n),span:tn}),t=e=>t=>({kind:`now`,offset:{sign:e,duration:en(t)},span:tn});return{eq:e(`=`),ne:e(`!=`),lt:e(`<`),lte:e(`<=`),gt:e(`>`),gte:e(`>=`),between:(t,n,r)=>on(`and`,[e(`>=`)(t,n),e(`<=`)(t,r)]),has:(e,t)=>({kind:`has`,field:nn(e),value:rn(t),span:tn}),present:e=>({kind:`present`,field:nn(e),span:tn}),in:(e,t)=>({kind:`in`,field:nn(e),values:t.map(rn),span:tn}),isNull:e=>({kind:`isNull`,field:nn(e),span:tn}),search:e=>({kind:`search`,text:e,span:tn}),similar:(e,t)=>({kind:`similar`,field:nn(e),text:t,span:tn}),regex:(e,t)=>({kind:`regex`,field:nn(e),pattern:t,span:tn}),and:(...e)=>on(`and`,e),or:(...e)=>on(`or`,e),not:e=>({kind:`not`,arg:e,span:tn}),now:()=>({kind:`now`,span:tn}),ago:t(`-`),fromNow:t(`+`)}},cn=sn(),ln=/\{([A-Za-z_][A-Za-z0-9_]*)\}/g,un=e=>[...e.matchAll(ln)].map(e=>e[1]),dn=e=>e.kind===`record`?(Array.isArray(e.key)?e.key:[e.key]).filter(e=>typeof e==`string`):e.kind===`list`?[e.filter,e.orderBy].filter(e=>e!==void 0):e.kind===`create`?Object.values(e.values??{}):[],fn=e=>[...new Set(dn(e).flatMap(un))],pn=(e,t)=>e.replace(ln,(e,n)=>t[n]===null||t[n]===void 0?``:String(t[n])),mn=(e,t={})=>{if(e.kind===`record`){let n=e=>typeof e==`string`?pn(e,t):e;return{...e,key:Array.isArray(e.key)?e.key.map(n):n(e.key)}}return e.kind===`create`?e.values?{...e,values:Object.fromEntries(Object.entries(e.values).map(([e,n])=>[e,pn(n,t)]))}:e:e.kind===`list`?{...e,...e.filter!==void 0&&{filter:pn(e.filter,t)},...e.orderBy!==void 0&&{orderBy:pn(e.orderBy,t)}}:e},hn=e=>/^\{([A-Za-z_][A-Za-z0-9_]*)\}$/.exec(e)?.[1],gn=e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&Object.keys(e).length===1&&typeof e.$field==`string`,_n=e=>typeof e==`object`&&!!e&&!Array.isArray(e),vn=e=>gn(e)?e.$field:Array.isArray(e)?e.map(vn):_n(e)?Object.fromEntries(Object.entries(e).map(([e,t])=>[e,vn(t)])):e,yn=`table`,bn=/^[a-z0-9][a-z0-9_-]*$/,xn=e=>{if(!e.startsWith(`/-/forms/`))return;let t=e.slice(9);return bn.test(t)?{name:t}:void 0},Sn=e=>e.flatMap(e=>e.kind===`group`||e.kind===`tab`?Sn(e.items):[e]),Cn=(e,t)=>{if(t===void 0)return e;let n=e?.lists?.find(e=>e.name===t);if(!e||!n)return;let{list:r,chart:i,help:a,nav:o,lists:s,names:c,...l}=e,{name:u,...d}=n;return{...l,...d}},wn={text:`text`,integer:`integer`,decimal:`decimal`,boolean:`boolean`,date:`date`,choice:`text`,custom:`json`},Tn=e=>({name:e.name,column:e.name,type:e.options?`enum`:wn[e.kind],nullable:!0,readOnly:!1,filterable:e.kind!==`custom`,sortable:!1,aliases:[],...e.options&&{enumValues:e.options.map(e=>e.value)}}),En=e=>({name:`inputs`,table:{name:`inputs`},fields:Object.fromEntries(e.map(e=>[e.name,Tn(e)])),primaryKey:[]}),Dn=(e,t)=>{let n=e[t].when;if(n===void 0)return;let r=it(n);if(!r.ok)return r.errors.map(e=>e.message).join(`; `);if(!r.ast)return`it is empty`;let i=Rt(En(e.slice(0,t)),r.ast);return i.ok?i.filter:i.errors.map(e=>e.message).join(`; `)},On=(e,t)=>{let n=new Set,r={};return e.forEach((i,a)=>{let o=Dn(e,a);if(typeof o==`string`)throw Error(`Input "${i.name}": ${o}`);let s=o===void 0||Jt(o,r)===!0;s&&n.add(i.name),r[i.name]=s?t[i.name]??null:null}),n},kn=(e,t)=>Object.fromEntries(Object.entries(e).flatMap(([e,n])=>{let r=typeof n==`string`?hn(n):void 0;return r===void 0?[[e,n]]:Object.hasOwn(t,r)?[[e,t[r]]]:[]})),An=e=>`groupBy`in e,jn=[`neutral`,`blue`,`green`,`amber`,`red`,`violet`],Mn=e=>jn.includes(e),Nn=e=>{if(!Array.isArray(e))return String(e);let t=e;return t.length===1?String(t[0]):t.map(e=>encodeURIComponent(String(e))).join(`,`)},Pn=e(we(),1),Fn=e=>{try{return new Pn.default.Comparator(e),!0}catch(e){if(e instanceof TypeError)return!1;throw e}},In=(e,t)=>{let n=t.trim().split(/\s+/);if(Pn.default.valid(e)!==null&&t.trim()!==``&&n.every(Fn))return Pn.default.satisfies(e,t)},Ln=(e,t)=>{if(e.api!==t.api)return`it is built for plugin API ${e.api}, and this app has plugin API ${t.api}`;let n=In(t.version,e.protobase);if(n===void 0)return`its Protobase range "${e.protobase}" is not one this app reads, such as >=0.12.0`;if(!n)return`it needs Protobase ${e.protobase}, and this app runs ${t.version}`},Rn=`[Filtered]`,zn=/authorization|cookie|passw|secret|token|api[-_]?key|credential|session|csrf|signature|^sig$/i,Bn=new Set([`url`,`query_string`,`from`,`to`]),Vn=12,Hn=e=>e.replace(/(^|&)([^=&]*)=([^&]*)/g,(e,t,n)=>zn.test(n)?`${t}${n}=${Rn}`:e),Un=e=>{let t=e.indexOf(`?`);if(t===-1)return e;let n=e.indexOf(`#`,t),r=n===-1?e.slice(t+1):e.slice(t+1,n);return`${e.slice(0,t+1)}${Hn(r)}${n===-1?``:e.slice(n)}`},Wn=(e,t,n)=>zn.test(e)?Rn:typeof t==`string`&&Bn.has(e)?e===`query_string`?Hn(t):Un(t):Gn(t,n+1),Gn=(e,t)=>t>Vn||typeof e!=`object`||!e?e:Array.isArray(e)?e.map(e=>Array.isArray(e)&&e.length===2&&typeof e[0]==`string`?[e[0],Wn(e[0],e[1],t)]:Gn(e,t+1)):Object.fromEntries(Object.entries(e).map(([e,n])=>[e,Wn(e,n,t)])),Kn=e=>Gn(e,0),qn=[`unknown-field`,`not-filterable`,`not-sortable`,`unsupported-traversal`,`invalid-traversal`],Jn=e=>e.replace(/(["']?)\{[A-Za-z_][A-Za-z0-9_]*\}\1/g,(e,t)=>t?`${t}x${t}`:`0`),Yn=(e,t)=>{let n=it(Jn(t));if(!n.ok)return n.errors.map(e=>`filter: ${e.message}`);if(!n.ast)return[];let r=Rt(e,n.ast);return r.ok?[]:r.errors.filter(e=>qn.includes(e.code)).map(e=>`filter: ${e.message}`)},Xn=(e,t)=>{if(fn({kind:`list`,resource:e.name,orderBy:t}).length>0)return[];let n=Qt(t);if(!n.ok)return n.errors.map(e=>`orderBy: ${e.message}`);let r=$t(e,n.items);return r.ok?[]:r.errors.map(e=>`orderBy: ${e.message}`)},Zn=(e,{models:t,pages:n,source:r,createPages:i})=>{let a=fn(e).flatMap(e=>r?Object.hasOwn(r.fields,e)?[]:[`"{${e}}" is not a field of ${r.name}`]:[`"{${e}}" takes a value from the record, but the link sits on none`]);switch(e.kind){case`page`:return n&&!n.has(e.page)?[`unknown page "${e.page}"`]:[];case`list`:case`record`:case`create`:{let n=Object.hasOwn(t,e.resource)?t[e.resource]:void 0;return n?e.kind===`create`&&i?.has(e.resource)?a:e.kind===`create`?[...a,...Object.keys(e.values??{}).filter(e=>!Object.hasOwn(n.fields,e)).map(t=>`values: unknown field "${t}" on ${e.resource}`)]:e.kind===`list`?[...a,...e.filter?Yn(n,e.filter):[],...e.orderBy?Xn(n,e.orderBy):[]]:a:[`unknown resource "${e.resource}"`]}default:return[`an address's kind is list, record, create or page, not "${String(e.kind)}"`]}},Qn={messages:[],replying:!1},$n=(e,t)=>{let n=e.findIndex(e=>e.id===t.id);return n===-1?[...e,t]:e.map((e,r)=>r===n?t:e)},er=(e,t,n)=>{let r=e.find(e=>e.id===t);return $n(e,r?{...r,parts:$n(r.parts,n)}:{id:t,from:`assistant`,parts:[n]})},tr=(e,t)=>{switch(t.type){case`state`:return t.state;case`message`:return{...e,messages:$n(e.messages,t.message)};case`part`:return{...e,messages:er(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}}}}},nr=async(e,t,n)=>{let r=ve({onEvent:e=>t(e.data)}),i=new TextDecoder,a=e.getReader();for(n?.addEventListener(`abort`,()=>void a.cancel(),{once:!0});;){let{done:e,value:t}=await a.read();if(e)break;r.feed(i.decode(t,{stream:!0}))}r.feed(`${i.decode()}\n\n`)},rr=e=>e.charAt(0).toUpperCase()+e.slice(1),F=e=>rr(e.replace(/(Id|Code|_id|_code)$/,``).replace(/([a-z0-9])([A-Z])/g,`$1 $2`).replace(/_+/g,` `).trim().toLowerCase()||e),ir=(e,t)=>t?.[e]??e,ar=[`name`,`title`,`number`,`sku`,`email`,`code`,`description`],or=e=>e?.type===`text`&&!e.sensitive,sr=(e,t)=>t?.title??ar.find(t=>or(e.fields[t]))??Object.values(e.fields).find(or)?.name??e.primaryKey[0],cr=(e,t)=>t?.title??t?.list?.columns.find(t=>e.fields[t]?.type===`text`)??sr(e),lr=(e,t,n,r)=>{let i=cr(e,t),a=n[i];return a==null?r:e.fields[i]?.type===`enum`?ir(String(a),t?.fields[i]?.valueLabels):String(a)},ur={fingerprint:`fingerprint`,shellVersion:`shell_version`},dr=`/api/mobile/release`,fr=`/api/mobile/releases`,pr=({fingerprint:e,shellVersion:t})=>new URLSearchParams({[ur.fingerprint]:e,[ur.shellVersion]:t}).toString(),mr=`/api/auth`,hr={ios:`capacitor://localhost`,android:`https://localhost`},gr={database:`protobase-push`,store:`registration`,key:`current`},_r=`protobase.sw.js`,vr=(e,t)=>`${e}/notifications/devices${t===void 0?``:`/${encodeURIComponent(t)}`}`,yr=/^[A-Za-z0-9_-]{1,64}$/,br=(e,t)=>{let n=`${e}/notifications/history`;if(t===void 0)return n;if(typeof t==`string`)return`${n}/${t}`;if(!yr.test(t.read))throw Error(`A history entry id is letters, digits, "_" and "-" only`);return`${n}/${t.read}/read`},xr=(e,t)=>`${e}/status${t===void 0?``:`/${t}`}`,Sr=/\p{Cc}/u,Cr=e=>{if(Sr.test(e))return`A status is one line of text, without control characters`;if([...e].length>100)return`A status is at most 100 characters`},wr=(e,t=Date.now())=>{if(e&&!(e.clearsAt!==null&&Date.parse(e.clearsAt)<=t)&&(e.availability!==`automatic`||e.text!==null))return e},Tr=(e,t)=>t?.list?.columns??Object.values(e.fields).filter(e=>!e.writeOnly).slice(0,6).map(e=>e.name),Er={members:[`json`]},Dr=(e,t)=>`${e}/calls/guests${t?`/${t}`:``}`,Or=`decline`,kr=(e,t)=>{let n=`${e}/calls/rings`;return t===void 0?n:`${n}/${encodeURIComponent(t.decline)}/${Or}`},Ar=`calls`,jr={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`}]]};jr.node;var Mr=N(jr),Nr={name:`arrow-down`,size:24,node:[[`path`,{d:`M12 5v14`,key:`s699le`}],[`path`,{d:`m19 12-7 7-7-7`,key:`1idqje`}]]};Nr.node;var Pr=N(Nr),Fr={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`}]]};Fr.node;var Ir=N(Fr),Lr={name:`arrow-right`,size:24,node:[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`m12 5 7 7-7 7`,key:`xquz4c`}]]};Lr.node;var Rr=N(Lr),zr={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`}]]};zr.node;var Br=N(zr),Vr={name:`arrow-up-right`,size:24,node:[[`path`,{d:`M7 7h10v10`,key:`1tivn9`}],[`path`,{d:`M7 17 17 7`,key:`1vkiza`}]]};Vr.node;var Hr=N(Vr),Ur={name:`arrow-up`,size:24,node:[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]};Ur.node;var Wr=N(Ur),Gr={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`}]]};Gr.node;var Kr=N(Gr),qr={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`}]]};qr.node;var Jr=N(qr),Yr={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`}]]};Yr.node;var Xr=N(Yr),Zr={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`}]]};Zr.node;var Qr=N(Zr),$r={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`}]]};$r.node;var ei=N($r),ti={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`}]]};ti.node;var ni=N(ti),ri={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`}]]};ri.node;var ii=N(ri),ai={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`}]]};ai.node;var oi=N(ai),si={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`}]]};si.node;var ci=N(si),li={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`}]]};li.node;var ui=N(li),di={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`}]]};di.node;var fi=N(di),pi={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`]};pi.node;var mi=N(pi),hi={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`}]]};hi.node;var gi=N(hi),_i={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`}]]};_i.node;var vi=N(_i),yi={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`}]]};yi.node;var bi=N(yi),xi={name:`check`,size:24,node:[[`path`,{d:`M20 6 9 17l-5-5`,key:`1gmf2c`}]]};xi.node;var Si=N(xi),Ci={name:`chevron-down`,size:24,node:[[`path`,{d:`m6 9 6 6 6-6`,key:`qrunsl`}]]};Ci.node;var wi=N(Ci),Ti={name:`chevron-left`,size:24,node:[[`path`,{d:`m15 18-6-6 6-6`,key:`1wnfg3`}]]};Ti.node;var Ei=N(Ti),Di={name:`chevron-right`,size:24,node:[[`path`,{d:`m9 18 6-6-6-6`,key:`mthhwq`}]]};Di.node;var Oi=N(Di),ki={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`}]]};ki.node;var Ai=N(ki),ji={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`]};ji.node;var Mi=N(ji),Ni={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`]};Ni.node;var Pi=N(Ni),Fi={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`}]]};Fi.node;var Ii=N(Fi),Li={name:`circle-minus`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M8 12h8`,key:`1wcyev`}]],aliases:[`minus-circle`]};Li.node;var Ri=N(Li),zi={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`]};zi.node;var Bi=N(zi),Vi={name:`circle`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]};Vi.node;var Hi=N(Vi),Ui={name:`clock`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 6v6l4 2`,key:`mmk7yg`}]]};Ui.node;var Wi=N(Ui),Gi={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`]};Gi.node;var Ki=N(Gi),qi={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`}]]};qi.node;var Ji=N(qi),Yi={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`}]]};Yi.node;var Xi=N(Yi),Zi={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`}]]};Zi.node;var Qi=N(Zi),$i={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`}]]};$i.node;var ea=N($i),ta={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`}]]};ta.node;var na=N(ta),ra={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`]};ra.node;var ia=N(ra),aa={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`]};aa.node;var oa=N(aa),sa={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`]};sa.node;var ca=N(sa),la={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`}]]};la.node;var ua=N(la),da={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`}]]};da.node;var fa=N(da),pa={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`}]]};pa.node;var ma=N(pa),ha={name:`face-slightly-smiling-plus`,size:24,node:[[`path`,{d:`M13.267 2.08a10 10 0 108.653 8.653`,key:`1wbpyh`}],[`path`,{d:`M15 10V9`,key:`4dkmfx`}],[`path`,{d:`M16 5h6`,key:`1vod17`}],[`path`,{d:`M16.472 15a6 6 0 01-8.943 0`,key:`7qomzy`}],[`path`,{d:`M19 2v6`,key:`4bpg5p`}],[`path`,{d:`M9 10V9`,key:`1lazqi`}]],aliases:[`smile-plus`]};ha.node;var ga=N(ha),_a={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`]};_a.node;var va=N(_a),ya={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`}]]};ya.node;var ba=N(ya),xa={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`}]]};xa.node;var Sa=N(xa),Ca={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`}]]};Ca.node;var wa=N(Ca),Ta={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`}]]};Ta.node;var Ea=N(Ta),Da={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`}]]};Da.node;var Oa=N(Da),ka={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`]};ka.node;var Aa=N(ka),ja={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`}]]};ja.node;var Ma=N(ja),Na={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`}]]};Na.node;var Pa=N(Na),Fa={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`}]]};Fa.node;var Ia=N(Fa),La={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`}]]};La.node;var Ra=N(La),za={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`}]]};za.node;var Ba=N(za),Va={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`}]]};Va.node;var Ha=N(Va),Ua={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`}]]};Ua.node;var Wa=N(Ua),Ga={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`}]]};Ga.node;var Ka=N(Ga),qa={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`}]]};qa.node;var Ja=N(qa),Ya={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`}]]};Ya.node;var Xa=N(Ya),Za={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`}]]};Za.node;var Qa=N(Za),$a={name:`loader-circle`,size:24,node:[[`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`,key:`13zald`}]],aliases:[`loader-2`]};$a.node;var eo=N($a),to={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`}]]};to.node;var no=N(to),ro={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`}]]};ro.node;var io=N(ro),ao={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`}]]};ao.node;var oo=N(ao),so={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`}]]};so.node;var co=N(so),lo={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`}]]};lo.node;var uo=N(lo),fo={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`}]]};fo.node;var po=N(fo),mo={name:`menu`,size:24,node:[[`path`,{d:`M4 5h16`,key:`1tepv9`}],[`path`,{d:`M4 12h16`,key:`1lakjw`}],[`path`,{d:`M4 19h16`,key:`1djgab`}]]};mo.node;var ho=N(mo),go={name:`mic-off`,size:24,node:[[`path`,{d:`M12 19v3`,key:`npa21l`}],[`path`,{d:`M15 9.34V5a3 3 0 0 0-5.68-1.33`,key:`1gzdoj`}],[`path`,{d:`M16.95 16.95A7 7 0 0 1 5 12v-2`,key:`cqa7eg`}],[`path`,{d:`M18.89 13.23A7 7 0 0 0 19 12v-2`,key:`16hl24`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M9 9v3a3 3 0 0 0 5.12 2.12`,key:`r2i35w`}]]};go.node;var _o=N(go),vo={name:`mic`,size:24,node:[[`path`,{d:`M12 19v3`,key:`npa21l`}],[`path`,{d:`M19 10v2a7 7 0 0 1-14 0v-2`,key:`1vc78b`}],[`rect`,{x:`9`,y:`2`,width:`6`,height:`13`,rx:`3`,key:`s6n7sd`}]]};vo.node;var yo=N(vo),bo={name:`minus`,size:24,node:[[`path`,{d:`M5 12h14`,key:`1ays0h`}]]};bo.node;var xo=N(bo),So={name:`monitor-up`,size:24,node:[[`path`,{d:`m9 10 3-3 3 3`,key:`11gsxs`}],[`path`,{d:`M12 13V7`,key:`h0r20n`}],[`rect`,{width:`20`,height:`14`,x:`2`,y:`3`,rx:`2`,key:`48i651`}],[`path`,{d:`M12 17v4`,key:`1riwvh`}],[`path`,{d:`M8 21h8`,key:`1ev6f3`}]]};So.node;var Co=N(So),wo={name:`monitor-x`,size:24,node:[[`path`,{d:`m14.5 12.5-5-5`,key:`1jahn5`}],[`path`,{d:`m9.5 12.5 5-5`,key:`1k2t7b`}],[`rect`,{width:`20`,height:`14`,x:`2`,y:`3`,rx:`2`,key:`48i651`}],[`path`,{d:`M12 17v4`,key:`1riwvh`}],[`path`,{d:`M8 21h8`,key:`1ev6f3`}]]};wo.node;var To=N(wo),Eo={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`}]]};Eo.node;var Do=N(Eo),Oo={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`}]]};Oo.node;var ko=N(Oo),Ao={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`}]]};Ao.node;var jo=N(Ao),Mo={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`}]]};Mo.node;var No=N(Mo),Po={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`}]]};Po.node;var Fo=N(Po),Io={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`}]]};Io.node;var Lo=N(Io),Ro={name:`phone-incoming`,size:24,node:[[`path`,{d:`M16 2v6h6`,key:`1mfrl5`}],[`path`,{d:`m22 2-6 6`,key:`6f0sa0`}],[`path`,{d:`M13.832 16.568a1 1 0 0 0 1.213-.303l.355-.465A2 2 0 0 1 17 15h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2A18 18 0 0 1 2 4a2 2 0 0 1 2-2h3a2 2 0 0 1 2 2v3a2 2 0 0 1-.8 1.6l-.468.351a1 1 0 0 0-.292 1.233 14 14 0 0 0 6.392 6.384`,key:`9njp5v`}]]};Ro.node;var zo=N(Ro),Bo={name:`phone-off`,size:24,node:[[`path`,{d:`M10.1 13.9a14 14 0 0 0 3.732 2.668 1 1 0 0 0 1.213-.303l.355-.465A2 2 0 0 1 17 15h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2 18 18 0 0 1-12.728-5.272`,key:`1wngk7`}],[`path`,{d:`M22 2 2 22`,key:`y4kqgn`}],[`path`,{d:`M4.76 13.582A18 18 0 0 1 2 4a2 2 0 0 1 2-2h3a2 2 0 0 1 2 2v3a2 2 0 0 1-.8 1.6l-.468.351a1 1 0 0 0-.292 1.233 14 14 0 0 0 .244.473`,key:`10hv5p`}]]};Bo.node;var Vo=N(Bo),Ho={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`}]]};Ho.node;var Uo=N(Ho),Wo={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`}]]};Wo.node;var Go=N(Wo),Ko={name:`plus`,size:24,node:[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`M12 5v14`,key:`s699le`}]]};Ko.node;var qo=N(Ko),Jo={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`}]]};Jo.node;var Yo=N(Jo),Xo={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`}]]};Xo.node;var Zo=N(Xo),Qo={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`}]]};Qo.node;var $o=N(Qo),es={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`}]]};es.node;var ts=N(es),ns={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`}]]};ns.node;var rs=N(ns),is={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`}]]};is.node;var as=N(is),os={name:`search`,size:24,node:[[`path`,{d:`m21 21-4.34-4.34`,key:`14j7rj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}]]};os.node;var ss=N(os),cs={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`]};cs.node;var ls=N(cs),us={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`}]]};us.node;var ds=N(us),fs={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`}]]};fs.node;var ps=N(fs),ms={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`}]]};ms.node;var hs=N(ms),gs={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`}]]};gs.node;var _s=N(gs),vs={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`}]]};vs.node;var ys=N(vs),bs={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`}]]};bs.node;var xs=N(bs),Ss={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`}]]};Ss.node;var Cs=N(Ss),ws={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`}]]};ws.node;var Ts=N(ws),Es={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`]};Es.node;var Ds=N(Es),Os={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`]};Os.node;var ks=N(Os),As={name:`square`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]};As.node;var js=N(As),Ms={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`}]]};Ms.node;var Ns=N(Ms),Ps={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`}]]};Ps.node;var Fs=N(Ps),Is={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`}]]};Is.node;var Ls=N(Is),Rs={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`}]]};Rs.node;var zs=N(Rs),Bs={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`}]]};Bs.node;var Vs=N(Bs),Hs={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`}]]};Hs.node;var Us=N(Hs),Ws={name:`terminal`,size:24,node:[[`path`,{d:`M12 19h8`,key:`baeox8`}],[`path`,{d:`m4 17 6-6-6-6`,key:`1yngyt`}]]};Ws.node;var Gs=N(Ws),Ks={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`]};Ks.node;var qs=N(Ks),Js={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`]};Js.node;var Ys=N(Js),Xs={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`}]]};Xs.node;var Zs=N(Xs),Qs={name:`user-plus`,size:24,node:[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}],[`line`,{x1:`19`,x2:`19`,y1:`8`,y2:`14`,key:`1bvyxn`}],[`line`,{x1:`22`,x2:`16`,y1:`11`,y2:`11`,key:`1shjgl`}]]};Qs.node;var $s=N(Qs),ec={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`]};ec.node;var tc=N(ec),nc={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`]};nc.node;var rc=N(nc),ic={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`}]]};ic.node;var ac=N(ic),oc={name:`video-off`,size:24,node:[[`path`,{d:`M10.66 6H14a2 2 0 0 1 2 2v2.5l5.248-3.062A.5.5 0 0 1 22 7.87v8.196`,key:`w8jjjt`}],[`path`,{d:`M16 16a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h2`,key:`1xawa7`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]};oc.node;var sc=N(oc),cc={name:`video`,size:24,node:[[`path`,{d:`m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5`,key:`ftymec`}],[`rect`,{x:`2`,y:`6`,width:`14`,height:`12`,rx:`2`,key:`158x01`}]]};cc.node;var lc=N(cc),uc={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`}]]};uc.node;var dc=N(uc),fc={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`}]]};fc.node;var pc=N(fc),mc={name:`wifi-off`,size:24,node:[[`path`,{d:`M12 20h.01`,key:`zekei9`}],[`path`,{d:`M8.5 16.429a5 5 0 0 1 7 0`,key:`1bycff`}],[`path`,{d:`M5 12.859a10 10 0 0 1 5.17-2.69`,key:`1dl1wf`}],[`path`,{d:`M19 12.859a10 10 0 0 0-2.007-1.523`,key:`4k23kn`}],[`path`,{d:`M2 8.82a15 15 0 0 1 4.177-2.643`,key:`1grhjp`}],[`path`,{d:`M22 8.82a15 15 0 0 0-11.288-3.764`,key:`z3jwby`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]};mc.node;var hc=N(mc),gc={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`}]]};gc.node;var _c=N(gc),vc={name:`x`,size:24,node:[[`path`,{d:`M18 6 6 18`,key:`1bl5f8`}],[`path`,{d:`m6 6 12 12`,key:`d8bk6v`}]]};vc.node;var yc=N(vc),bc={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`}]]};bc.node;var xc=N(bc),I=e(t(),1),Sc=e(n(),1),L=M(`account`),Cc=`/-/account`,wc=`/-/sign-in-policy`,Tc=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}},Ec=e=>e?`${Cc}/${encodeURIComponent(e)}`:Cc,Dc=(e,t,n)=>[{id:`account`,label:L(`account`),icon:rc,href:`${e}${Cc}`,active:Tc(t)!==void 0},...n?[{id:`sign-in-policy`,label:L(`signInPolicy`),icon:_s,href:`${e}${wc}`,active:t===wc}]:[]],Oc=[`always`,`editing`,`reading`],kc=e=>e!==void 0&&!Oc.includes(e),Ac={list:`list`,filter:`filter`,orderBy:`order_by`,display:`display`,filterLayout:`layout`,map:`map`,calendar:`calendar`,timeline:`timeline`,savedSearch:`saved_search`,create:`new`,edit:`edit`,open:`open`,tab:`tab`,standard:`standard`,call:`call`},jc=[`list`,`display`,`filter`,`orderBy`,`filterLayout`,`savedSearch`],Mc=e=>`${e.latitude.toFixed(5)},${e.longitude.toFixed(5)},${e.zoom.toFixed(2)}`,Nc=(e,t,n=-t)=>Number.isFinite(e)&&e>=n&&e<=t,Pc=e=>{let t=e?.split(`,`);if(t?.length!==3||t.some(e=>e.trim()===``))return;let[n,r,i]=t.map(Number);return Nc(n,90)&&Nc(r,180)&&Nc(i,22,0)?{latitude:n,longitude:r,zoom:i}:void 0},Fc=e=>`${e.scale},${e.day}`,Ic=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},Lc=(e,t)=>{let n=e?.split(`,`);if(n?.length!==2)return;let[r,i]=n;return t.includes(r)&&Ic(i)?{scale:r,day:i}:void 0},Rc=e=>{let t=new URLSearchParams;for(let n of jc){let r=e[n];r===void 0||r===``&&n!==`filter`||t.set(Ac[n],r)}e.map&&t.set(Ac.map,Mc(e.map)),e.calendar&&t.set(Ac.calendar,Fc(e.calendar)),e.timeline&&t.set(Ac.timeline,Fc(e.timeline));let n=t.toString();return n?`?${n}`:``},zc=e=>{let t=new URLSearchParams;e.edit&&t.set(Ac.edit,`true`);for(let n of e.open??[])t.append(Ac.open,n);e.tab&&t.set(Ac.tab,e.tab),e.standard&&t.set(Ac.standard,`true`),e.call&&t.set(Ac.call,e.call);let n=t.toString();return n?`?${n}`:``},Bc=(e,t=``)=>{switch(e.kind){case`page`:return`${t}/${encodeURIComponent(e.page)}${e.tab?`/${encodeURIComponent(e.tab)}`:``}`;case`create`:return`${t}/${encodeURIComponent(e.resource)}/${Ac.create}${Hc(e.values)}`;case`record`:return`${t}/${encodeURIComponent(e.resource)}/${encodeURIComponent(Nn(e.key))}${zc(e)}`;case`list`:return`${t}/${encodeURIComponent(e.resource)}${Rc(e)}`}},Vc=e=>{try{return e.split(`/`).filter(Boolean).map(decodeURIComponent)}catch(e){if(e instanceof URIError)return;throw e}},Hc=(e={})=>{let t=new URLSearchParams(Object.entries(e).filter(([,e])=>e!==``)).toString();return t?`?${t}`:``},Uc=e=>e===`bar`||e===`panel`?e:void 0,Wc=(e,t)=>{let n=new URL(e,`http://app`),r=Vc(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===Ac.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(Ac.open).filter(e=>e!==``))],t=n.searchParams.get(Ac.tab)||void 0,r=n.searchParams.get(Ac.standard)===`true`,o=n.searchParams.get(Ac.call)===`join`;return{kind:`record`,resource:i,key:a,...n.searchParams.get(Ac.edit)===`true`&&{edit:!0},...e.length>0&&{open:e},...t&&{tab:t},...r&&{standard:r},...o&&{call:`join`}}}let o=n.searchParams,s=o.get(Ac.list)||void 0,c=o.get(Ac.display)||void 0,l=o.get(Ac.filter)??void 0,u=o.get(Ac.orderBy)||void 0,d=Uc(o.get(Ac.filterLayout)),f=Pc(o.get(Ac.map)),p=Lc(o.get(Ac.calendar),[`month`,`week`]),m=Lc(o.get(Ac.timeline),[`week`,`month`,`quarter`]),h=o.get(Ac.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}}},Gc={signature:`sig`},Kc=e=>{let t=e.startsWith(`?`)?e.slice(1):e;return new URLSearchParams(t).has(Gc.signature)?{oauthQuery:t}:{}},qc=`/-/sign-in`,Jc={step:`step`,next:`next`},Yc=[`sign-in`,`forgot-password`,`email-code`,`sign-up`,`sign-up-code`,`sign-up-details`],Xc=e=>Yc.includes(e),Zc=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}`},Qc=({step:e=`sign-in`,next:t}={})=>{let n=new URLSearchParams;e!==`sign-in`&&n.set(Jc.step,e);let r=Zc(t);r&&r!==`/`&&n.set(Jc.next,r);let i=n.toString();return i?`${qc}?${i}`:qc},$c=(e,t)=>{if(e!==`/-/sign-in`)return;let n=t.get(Jc.step),r=Zc(t.get(Jc.next));return{step:Xc(n)?n:`sign-in`,...r&&{next:r}}},el=e=>typeof e==`string`?e:e&&Yt(e),tl=e=>{let t=Object.entries(e??{}).map(([e,t])=>`${e}.${t}`);return t.length>0?t:void 0},nl=e=>({photos:e&&`${e.resource}.${e.field}.${e.image}`,photos_order_by:e?.sort}),rl=(e={})=>({filter:el(e.filter)||void 0,order_by:e.orderBy,page_size:e.pageSize,page_token:e.pageToken||void 0,fields:e.fields?.join(`,`),labels:tl(e.labels)?.join(`,`),...nl(e.photos),count:e.count}),il=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}`:``},al=e=>e.startsWith(`/`)&&!e.startsWith(`//`),ol=e=>{if(typeof e!=`object`||!e)return!1;let{uri:t,url:n}=e;return typeof t==`string`&&typeof n==`string`&&al(n)},sl=e=>e!==void 0&&URL.canParse(e)?new URL(e).origin:void 0,cl=(e,t)=>({...e,url:`${t}${e.url}`,...e.variants&&{variants:Object.fromEntries(Object.entries(e.variants).map(([e,n])=>[e,al(n.url)?{...n,url:`${t}${n.url}`}:n]))}}),ll=(e,t)=>t===void 0||typeof e!=`object`||!e?e:Object.fromEntries(Object.entries(e).map(([e,n])=>[e,ol(n)?cl(n,t):n])),ul=(e,t)=>t===void 0?e:Object.fromEntries(Object.entries(e).map(([e,n])=>[e,n.map(e=>ol(e)?cl(e,t):e)])),dl=class extends Error{problem;constructor(e){super(e.detail??e.title),this.problem=e,this.name=`ApiError`}get status(){return this.problem.status}get slug(){return this.problem.type.split(`:`).at(-1)??``}get operation(){return this.problem.operation??this.errors.find(e=>e.operation!==void 0)?.operation}get blockedBy(){return this.problem.blockedBy}get existing(){return this.problem.existing}get errors(){return this.problem.errors??[]}get filterErrors(){return this.slug===`invalid-filter`?this.errors:[]}},fl=class extends dl{constructor(e){super(e),this.name=`PreconditionFailedError`}},pl=e=>e instanceof dl,ml=e=>typeof e==`object`&&!!e&&`type`in e&&`status`in e,hl=async e=>{let t=e.headers.get(`content-type`)?.includes(`json`)??!1?await e.json():void 0,n=ml(t)?t:{type:`urn:protobase:problem:unknown`,title:e.statusText||`Request failed`,status:e.status};return n.status===412?new fl(n):new dl(n)},gl=(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 hl(h);return h}},_l=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()]})),vl=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:_l(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)}),yl=e=>Math.min(3e4,1e3*2**e),bl=(e,t)=>new Promise(n=>{let r=setTimeout(n,e);t.addEventListener(`abort`,()=>{clearTimeout(r),n()},{once:!0})}),xl=(e,t,n=yl)=>{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:il({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 nr(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 bl(n(o++),i)}})(),()=>r.abort()},Sl=e=>{let t=new Set,n,r=e=>{for(let n of[...t])e(n)};return i=>{let a={...i};return t.add(a),n??=e({onChanges:e=>r(t=>t.onChanges(e)),onResync:()=>r(e=>e.onResync()),onRetry:e=>r(t=>t.onRetry?.(e))}),()=>{!t.delete(a)||t.size>0||(n?.(),n=void 0)}}},Cl=new TextEncoder,wl=new TextDecoder,Tl=4,El=(e,t)=>{let n=Cl.encode(JSON.stringify(e)),r=t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength),i=new Uint8Array(Tl+n.length+r.length);return new DataView(i.buffer).setUint32(0,n.length),i.set(n,Tl),i.set(r,Tl+n.length),i.buffer},Dl=e=>{let t=Tl+new DataView(e).getUint32(0);return{...JSON.parse(wl.decode(new Uint8Array(e,Tl,t-Tl))),payload:e.slice(t)}},Ol=e=>e instanceof ArrayBuffer||ArrayBuffer.isView(e),kl=class extends Error{code;constructor(e,t){super(t),this.code=e,this.name=`ChannelRefusal`}},Al=5e3,jl=1,Ml=`protobase.channels`,Nl=({url:e,token:t,socket:n,retryDelay:r,onOpen:i,onDown:a,onMessage:o})=>{let s,c=!1,l=0,u=0,d,f=0,p,m,h=new Map,g=()=>{for(let{reject:e}of h.values())e(new kl(`disconnected`,`The connection dropped before the server answered`));h.clear()},_=async e=>{let n=await t?.();s===e&&e.readyState===jl&&n!==void 0&&n!==d&&(d=n,e.send(JSON.stringify({type:`token`,token:n})))},v=async()=>{let u=await t?.();if(!c||s)return;d=u;let y=n(e(),u===void 0?[Ml]:[Ml,`bearer.${u}`]);s=y,y.binaryType=`arraybuffer`,y.onopen=()=>{l=0,f=Date.now(),p=setInterval(()=>{if(Date.now()-f>1e4)return y.close();y.send(JSON.stringify({type:`ping`})),_(y)},Al),i()},y.onmessage=({data:e})=>{if(f=Date.now(),typeof e!=`string`&&!(e instanceof ArrayBuffer))return;let t=typeof e==`string`?JSON.parse(e):Dl(e);if(t.type!==`reply`)return o(t);let n=h.get(t.ref);h.delete(t.ref),t.ok?n?.resolve(t):n?.reject(new kl(t.error.code,t.error.message))},y.onclose=()=>{s===y&&(clearInterval(p),s=void 0,g(),c&&(a(),m=setTimeout(()=>{m=void 0,v()},r(l++))))}},y=(e,t)=>s?.readyState===jl&&(s.send(t===void 0?JSON.stringify(e):El(e,t)),!0);return{start:()=>{c=!0,!s&&m===void 0&&v()},stop:()=>{c=!1,clearTimeout(m),m=void 0,clearInterval(p);let e=s;s=void 0,g(),e?.close(1e3)},request:(e,t)=>new Promise((n,r)=>{let i=String(++u);if(!y({...e,ref:i},t))return r(new kl(`disconnected`,`The connection is down`));h.set(i,{resolve:n,reject:r})}),post:y}},Pl=e=>{if(!(e instanceof kl&&e.code===`disconnected`))throw e},Fl=()=>new kl(`not-joined`,`The channel is not joined yet`),Il=e=>{let t=new Map,n=new Map,r=(e,t)=>{e.status=t;for(let n of e.statusListeners)n(t)},i=(e,t)=>{let n=[...e.presence.values()];for(let r of e.presenceListeners)r(n,t)},a=e=>{t.delete(e),t.size===0&&c.stop()},o=e=>{let i=`${e.resource}/${e.key}`;c.request({type:`join`,resource:e.resource,key:e.key}).then(o=>{if(t.get(i)===e){if(e.holders===0)return c.post({type:`leave`,channel:o.channel}),a(i);e.name=o.channel,n.set(e.name,e),r(e,{state:`joined`}),e.tracked&&c.request({type:`track`,channel:e.name,state:e.tracked.state}).catch(Pl)}}).catch(n=>{if(t.get(i)===e&&e.holders===0&&n instanceof kl)return a(i);if(!(n instanceof kl)||n.code===`disconnected`)return Pl(n);r(e,{state:`refused`,error:{code:n.code,message:n.message}})})},s=e=>{if(e.type===`pong`||e.type===`reply`||e.type===`error`)return;let t=n.get(e.channel);if(t){if(e.type===`presence`)return t.presence=new Map(e.entries.map(e=>[e.id,e])),i(t);if(e.type===`presence_diff`){for(let n of e.leaves)t.presence.delete(n.id);for(let n of[...e.joins,...e.updates])t.presence.set(n.id,n);return i(t,{joins:e.joins,updates:e.updates,leaves:e.leaves})}if(e.type===`broadcast`){let{event:n,payload:r,user:i,server:a}=e;for(let e of t.eventListeners.get(n)??[])e({event:n,payload:r,user:i,...a&&{server:a}});return}n.delete(e.channel),t.presence.clear(),i(t),r(t,{state:`closed`,error:e.error})}},c=Nl({...e,onOpen:()=>{for(let[e,n]of t)n.status.state===`joining`&&(n.holders===0?a(e):o(n))},onDown:()=>{n.clear();for(let e of t.values())e.status.state===`joined`&&r(e,{state:`joining`})},onMessage:s}),l=(e,t)=>{--t.holders,!(t.holders>0)&&(t.tracked=void 0,t.status.state!==`joining`&&(t.name!==void 0&&(n.delete(t.name),c.post({type:`leave`,channel:t.name})),a(e)))},u=(e,t)=>{let n=!1,r=new Set,i=(e,t)=>{e.add(t);let n=()=>{e.delete(t),r.delete(n)};return r.add(n),n},a=()=>t.status.state===`joined`?t.name:void 0;return{status:()=>t.status,onStatus:e=>i(t.statusListeners,e),presence:()=>[...t.presence.values()],onPresence:e=>i(t.presenceListeners,e),track:async e=>{t.tracked={state:e};let n=a();n!==void 0&&await c.request({type:`track`,channel:n,state:e})},untrack:async()=>{t.tracked=void 0;let e=a();e!==void 0&&await c.request({type:`untrack`,channel:e})},send:async(e,t,{self:n,ack:r}={})=>{let i=a();if(i===void 0)throw Fl();let o=Ol(t)?t:void 0,s={type:`send`,channel:i,event:e,...o===void 0&&{payload:t},...n&&{self:n}};if(r){await c.request({...s,ack:r},o);return}if(!c.post(s,o))throw new kl(`disconnected`,`The connection is down`)},on:(e,n)=>{let r=t.eventListeners.get(e)??new Set;return t.eventListeners.set(e,r),i(r,n)},leave:()=>{if(!n){n=!0;for(let e of[...r])e();l(e,t)}}}};return{channel:(e,n)=>{let r=Nn(n),i=`${e}/${r}`,a=t.get(i);if(a)return a.holders+=1,u(i,a);let s={resource:e,key:r,status:{state:`joining`},presence:new Map,holders:1,statusListeners:new Set,presenceListeners:new Set,eventListeners:new Map};return t.set(i,s),c.start(),o(s),u(i,s)}}},Ll=e=>({register:async t=>(await e({method:`POST`,path:vr(``),system:!0,body:t})).json(),remove:async t=>{await e({method:`DELETE`,path:vr(``,t),system:!0})}}),Rl=e=>({own:async()=>(await(await e({method:`GET`,path:xr(``),system:!0})).json()).status,set:async t=>(await(await e({method:`PUT`,path:xr(``),system:!0,body:t})).json()).status,clear:async()=>{await e({method:`DELETE`,path:xr(``),system:!0})},people:async()=>(await(await e({method:`GET`,path:xr(``,`people`),system:!0})).json()).statuses}),zl=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:br(``),query:i,system:!0})).json()},unread:async()=>(await(await e({method:`GET`,path:br(``,`unread`),system:!0})).json()).count,markRead:async t=>{await e({method:`POST`,path:br(``,{read:t}),body:{},system:!0})},markAllRead:async t=>{await e({method:`POST`,path:br(``,`read`),body:{upTo:t},system:!0})}}),Bl=e=>Math.min(3e4,1e3*2**e),Vl=(e,t)=>new Promise(n=>{let r=setTimeout(n,e);t.addEventListener(`abort`,()=>{clearTimeout(r),n()},{once:!0})}),Hl=(e,t,n=Bl)=>({calls:async(n,r)=>(await(await e({method:`GET`,path:t(n,r)})).json()).items,watchCalls:(r,i,a)=>{let o=new AbortController,{signal:s}=o,c=0,l=async()=>{let n=await e({method:`GET`,path:t(r,i),query:`?watch=true`,headers:{accept:`text/event-stream`},signal:s});if(!n.body)throw Error(`The server answered the calls stream without a body`);await nr(n.body,e=>{c=0,a.onCalls(JSON.parse(e).items)},s)};return(async()=>{for(;!s.aborted;){let e=await l().then(()=>void 0,e=>e);if(s.aborted)return;a.onRetry?.(e),await Vl(n(c++),s)}})(),()=>o.abort()}}),Ul=e=>({list:async()=>(await(await e({method:`GET`,path:kr(``),system:!0})).json()).items,decline:async t=>{await e({method:`POST`,path:kr(``,{decline:t}),system:!0,body:{}})}}),Wl=e=>({allowed:async()=>(await(await e({method:`GET`,path:Dr(``,`organization`),system:!0})).json()).allowed,setAllowed:async t=>{await e({method:`PUT`,path:Dr(``,`organization`),system:!0,body:{allowed:t}})}}),Gl=e=>typeof e==`string`?e:e.toModel().name,Kl=(e=`/api/v1`)=>{let t=new URL(`${e.replace(/\/[^/]*$/,``)}/channels`,globalThis.location?.href);return t.protocol=t.protocol===`https:`?`wss:`:`ws:`,t.toString()},ql=(e,t)=>`/${Gl(e)}/${Nn(t)}`,Jl=(e,t)=>`${ql(e,t)}:calls`,Yl=(e,t,n)=>({items:e.items.map(e=>ll(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:ul(e.photos,n)},...t.headers.get(`x-protobase-warning`)&&{warning:t.headers.get(`x-protobase-warning`)}}),Xl=({created_at:e,...t})=>({...t,createdAt:e}),Zl=e=>e.headers.get(`etag`)??``,Ql=async(e,t)=>{let{permissions:n,...r}=await e.json();return{record:ll(r,t),etag:Zl(e),...n&&{permissions:n}}},$l=(e,t)=>({results:(e.results??[]).map(e=>e.op===`create`||e.op===`update`?{...e,record:ll(e.record,t)}:e.op===`reorder`?{...e,records:e.records.map(e=>({...e,record:ll(e.record,t)}))}:e)}),eu=(e={})=>{let t=gl(e),n=sl(e.baseUrl),r=async(e,r)=>{let i=await t({method:`GET`,path:`/${Gl(e)}`,query:il(rl(r))});return Yl(await i.json(),i,n)},i=async(e,r)=>{let i=rl(r),a=await t({method:`POST`,path:`/${Gl(e)}:search`,body:{...i,fields:r?.fields,labels:tl(r?.labels)}});return Yl(await a.json(),a,n)},a=async(e,r)=>Ql(await t({method:`GET`,path:ql(e,r)}),n),o=async(e,r)=>{let i=await t({method:`POST`,path:`/${Gl(e)}`,body:r});return{record:ll(await i.json(),n),etag:Zl(i),location:i.headers.get(`location`)??``}},s=async(e,r,i,a)=>Ql(await t({method:`PATCH`,path:ql(e,r),body:i,headers:{"if-match":a}}),n),c=async(e,n,{etag:r}={})=>{await t({method:`DELETE`,path:ql(e,n),headers:r?{"if-match":r}:void 0})},l=async(e,r)=>{let i=await t({method:`POST`,path:`${ql(e,r)}:undelete`});return{record:ll(await i.json(),n),etag:Zl(i)}},u=async(e,n,r)=>(await(await t({method:`POST`,path:`${ql(e,n)}:reveal`,body:{field:r}})).json()).value,d=async(e,r,i)=>Ql(await t({method:`POST`,path:`${ql(e,r)}:generate`,body:{action:i}}),n),f=async(e,n,{pageSize:r,pageToken:i}={})=>{let a=il({page_size:r,page_token:i||void 0}),o=await(await t({method:`GET`,path:`${ql(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=il({page_size:r,page_token:i||void 0}),o=await(await t({method:`GET`,path:`${ql(e,n)}:comments`,query:a})).json();return{items:o.items.map(Xl),nextPageToken:o.next_page_token}},m=async(e,n,{body:r,mentions:i=[]})=>Xl(await(await t({method:`POST`,path:`${ql(e,n)}:comments`,body:{body:r,mentions:i}})).json()),h=async(e,n,r)=>(await(await t({method:`GET`,path:`${ql(e,n)}:mentionable`,query:il({q:r})})).json()).items,g=async e=>{let r=e=>typeof e==`object`&&e&&`$ref`in e?e:Nn(e),i=e.map(e=>({...e,resource:Gl(e.resource),...`key`in e&&{key:r(e.key)},...e.op===`reorder`&&{keys:e.keys.map(r)}}));return $l(await(await t({method:`POST`,path:`:batchWrite`,body:{ops:i}})).json(),n)},_=async(e,n,r={})=>(await(await t({method:`GET`,path:`/${Gl(e)}:facets`,query:il({field:n,filter:el(r.filter)||void 0,limit:r.limit,label:r.label})})).json()).facets,v=async(e,n)=>{let r=await(await t({method:`GET`,path:`/${Gl(e)}:aggregate`,query:il({group_by:n.groupBy,filter:el(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:`/${Gl(e)}:series`,query:il({field:n.field,range:n.range,from:n.from,to:n.to,granularity:n.granularity,time_zone:n.timeZone,filter:el(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:`/${Gl(e)}:histogram`,query:il({field:n,buckets:r.buckets,filter:el(r.filter)||void 0})})).json(),x=async(e,r)=>{let i=await(await t({method:`GET`,path:`/${Gl(e)}:map`,query:il({latitude:r.latitude,longitude:r.longitude,zoom:r.zoom,filter:el(r.filter)||void 0,order_by:r.orderBy,fields:r.fields?.join(`,`),labels:tl(r.labels)?.join(`,`),...nl(r.photos)})})).json();return{items:i.items.map(e=>ll(e,n)),buckets:i.buckets,totalSize:i.total_size,...i.labels!==void 0&&{labels:i.labels},...i.photos!==void 0&&{photos:ul(i.photos,n)}}},S=async(e,r)=>{let i=await t({method:`GET`,path:`/${Gl(e)}:seek`,query:il({...rl(r),position:r.position})});return Yl(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:Zl(r)}},w=async(e,{method:n,body:r,path:i=``,query:a,headers:o}={})=>{let s=await t({method:n??(r===void 0?`GET`:`POST`),path:`/functions/${encodeURIComponent(e)}${i}`,query:a?`?${new URLSearchParams(a)}`:``,body:r,headers:o,system:!0});if(s.status===204)return;let c=s.headers.get(`content-type`);return c?.includes(`json`)?s.json():!c||c.startsWith(`text/`)?s.text():s.blob()},T=async(e,n,r,{onProgress:i,signal:a}={})=>{let o=`name`in r&&typeof r.name==`string`?r.name:void 0,s=i&&typeof XMLHttpRequest<`u`?vl(i):void 0,c=await(await t({method:`POST`,path:`/${Gl(e)}:upload`,query:`?${new URLSearchParams({field:n,...o!==void 0&&{name:o}})}`,raw:r,headers:{"content-type":r.type||`application/octet-stream`},...s&&{via:s},...a&&{signal:a}})).json();return i?.(r.size,r.size),c},E=e=>`/forms/${encodeURIComponent(e)}`,D=async e=>(await t({method:`GET`,path:E(e),system:!0})).json(),O=async e=>(await t({method:`GET`,path:`${E(e)}:challenge`,system:!0})).json(),k=async(e,n,r)=>{await t({method:`POST`,path:E(e),body:{values:n,proof:r},system:!0})},A=Sl(e=>xl(t,e)),{channel:j}=Il({url:()=>Kl(e.baseUrl),...e.token&&{token:()=>e.token({refresh:!1})},socket:e.webSocket??((e,t)=>new WebSocket(e,t)),retryDelay:e=>Math.min(3e4,1e3*2**e)}),ee=Ll(t),te=zl(t),{calls:ne,watchCalls:re}=Hl(t,Jl);return{list:r,search:i,get:a,create:o,update:s,remove:c,undelete:l,generate:d,reveal:u,history:f,comments:p,comment:m,mentionable:h,batchWrite:g,facets:_,aggregate:v,series:y,histogram:b,map:x,seek:S,meta:C,invoke:w,upload:T,form:D,formChallenge:O,submitForm:k,live:A,channel:j,devices:ee,notifications:te,status:Rl(t),calls:ne,watchCalls:re,rings:Ul(t),callGuests:Wl(t)}},tu=e=>typeof e==`string`?e:e.toModel().name,nu=(e,t)=>{let n=n=>t(tu(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=>tu(e.resource)))].join(`, `)}, which different APIs serve`)):(r[0]??e).batchWrite(t)},facets:(e,t,r)=>n(e).facets(e,t,r),aggregate:(e,t)=>n(e).aggregate(e,t),series:(e,t)=>n(e).series(e,t),histogram:(e,t,r)=>n(e).histogram(e,t,r),map:(e,t)=>n(e).map(e,t),seek:(e,t)=>n(e).seek(e,t),meta:(t,n)=>e.meta(t,n),invoke:(t,n)=>e.invoke(t,n),upload:(e,t,r,i)=>n(e).upload(e,t,r,i),form:t=>e.form(t),formChallenge:t=>e.formChallenge(t),submitForm:(t,n,r)=>e.submitForm(t,n,r),live:t=>e.live(t),channel:(t,n)=>e.channel(t,n),devices:e.devices,notifications:e.notifications,status:e.status,rings:e.rings,callGuests:e.callGuests,calls:(e,t)=>n(e).calls(e,t),watchCalls:(e,t,r)=>n(e).watchCalls(e,t,r)}},ru=e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&typeof e.type==`string`&&Array.isArray(e.children),iu={record:!1},au=e=>({resource:typeof e.props.resource==`string`?e.props.resource:void 0,record:!0}),ou=(e,t)=>!e.custom&&(e.type===`RecordCard`||e.type===`CardRow`)?au(e):t,su=(e,t)=>!e.custom&&e.type===`RecordCard`?au(e):t,cu=e=>`<${e.type}${typeof e.props.resource==`string`?` resource="${e.props.resource}"`:``}${typeof e.props.name==`string`?` name="${e.props.name}"`:``}>`,lu=e=>ru(e)||Array.isArray(e)&&e.length>0&&e.every(ru),uu=(e,t,n={path:cu(e),scope:iu})=>{let r=ou(e,n.scope),i=su(e,n.scope),a=e.children.flatMap(e=>{if(typeof e==`string`)return[e];let i=uu(e,t,{path:`${n.path} › ${cu(e)}`,scope:r});return i?[i]:[]}),o=Object.fromEntries(Object.entries(e.props).flatMap(([e,r])=>{if(!lu(r))return[[e,r]];let a=(Array.isArray(r)?r:[r]).flatMap(r=>uu(r,t,{path:`${n.path} ${e}={${cu(r)}}`,scope:i})??[]);return a.length===0?[]:[[e,Array.isArray(r)?a:a[0]]]}));return t({...e,props:o,children:a},n)},du=e=>typeof e==`object`&&!!e&&e.kind===`member`,fu=e=>du(e)?[e.path.join(`.`)]:typeof e!=`object`||!e?[]:Object.values(e).flatMap(fu),pu=e=>du(e)?{...e,path:[e.path.join(`.`)]}:Array.isArray(e)?e.map(pu):typeof e!=`object`||!e?e:Object.fromEntries(Object.entries(e).map(([e,t])=>[e,pu(t)])),mu=e=>{let t=ie(e);return t.ok?t.ast?{ok:!0,ast:t.ast,paths:[...new Set(fu(t.ast))]}:{ok:!1,message:`the condition is empty`}:{ok:!1,message:t.errors.map(e=>e.message).join(`; `)}},hu=(e,t)=>e.ast!==void 0&&Ee(pu(e.ast),t),gu=(e,t)=>{let[n,r,...i]=e.split(`.`);return n&&r===`count`&&i.length===0&&!t(n)?n:void 0},_u=({layout:e,cardWidth:t})=>({layout:e??`stack`,cardWidth:t??`2/3`}),vu=(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}},yu=(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]}))}),bu=(e,t)=>{if(e.kind===`group`){let n=e.items.flatMap(e=>bu(e,t));return n.length>0?[{...e,items:n}]:[]}if(e.kind===`tab`){let n=e.items.flatMap(e=>bu(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=>vu(t,e.resource,n).ok);return[i&&i.length>0?{...r,columns:i}:r]},xu=(e,t,n)=>e.run?.kind!==`link`||!(`to`in e.run)||Zn(e.run.to,{models:n,pages:new Set,source:t}).length===0,Su=(e,t)=>({...e,layout:e.layout.flatMap(e=>bu(e,t)),actions:e.actions.filter(n=>xu(n,t[e.resource],t))}),Cu=(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=>yu(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=>Su(e,a)),permissions:Object.fromEntries(n.flatMap(t=>e.permissions?.[t.name]?[[t.name,e.permissions[t.name]]]:[]))}},wu=class extends Error{status;code;constructor(e,t,n){super(e),this.status=t,this.code=n,this.name=`AuthError`}},R=(e,t)=>new wu(e?.message||t,e?.status??500,e?.code),Tu=e=>new Date(e).toISOString(),Eu=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:Tu(e.createdAt),updatedAt:Tu(e.updatedAt),expiresAt:Tu(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`)}}),Du=e=>({signInMethods:async()=>{let{data:t,error:n}=await e.$fetch(`/account/sign-in-methods`);if(n||!t)throw R(n,`Could not read your sign-in methods`);return t},passkeys:async()=>{let{data:t,error:n}=await e.passkey.listUserPasskeys();if(n||!t)throw R(n,`Could not read your passkeys`);return t.map(e=>({id:e.id,backedUp:e.backedUp,...e.name&&{name:e.name},...e.createdAt&&{createdAt:new Date(e.createdAt).toISOString()}}))},addPasskey:async t=>{let{error:n}=await e.passkey.addPasskey(t?{name:t}:{});if(n)throw R(n,`Could not add the passkey`)},renamePasskey:async(t,n)=>{let{error:r}=await e.passkey.updatePasskey({id:t,name:n});if(r)throw R(r,`Could not rename the passkey`)},removePasskey:async t=>{let{error:n}=await e.passkey.deletePasskey({id:t});if(n)throw R(n,`Could not remove the passkey`)},startAuthenticatorApp:async t=>{let{data:n,error:r}=await e.twoFactor.enable({method:`totp`,...t&&{password:t}});if(r||n?.method!==`totp`)throw R(r,`Could not start two-factor authentication`);return{totpURI:n.totpURI,backupCodes:n.backupCodes}},confirmAuthenticatorApp:async t=>{let{error:n}=await e.twoFactor.verifyTotp({code:t});if(n)throw R(n,`The code did not work`)},turnOnEmailedCodes:async t=>{let{error:n}=await e.twoFactor.enable({method:`otp`,...t&&{password:t}});if(n)throw R(n,`Could not turn on two-factor authentication`)},turnOffTwoFactor:async t=>{let{error:n}=await e.twoFactor.disable(t?{password:t}:{});if(n)throw R(n,`Could not turn off two-factor authentication`)},linkedProviders:async()=>{let{data:t,error:n}=await e.listAccounts();if(n||!t)throw R(n,`Could not read your linked accounts`);return[...new Set(t.map(e=>e.providerId).filter(e=>e!==`credential`))]},linkProvider:async(t,n)=>{let{data:r,error:i}=await e.linkSocial({provider:t,callbackURL:n,errorCallbackURL:n,disableRedirect:!0});if(i||!r?.url)throw R(i,`Could not start linking the account`);return r.url},linkedPersonalMail:async t=>{let{data:n,error:r}=await e.listAccounts();if(r||!n)throw R(r,`Could not read your linked accounts`);return t.filter(e=>n.some(t=>t.providerId===e.provider&&e.scopes.every(e=>t.scopes.includes(e)))).map(e=>e.id)},linkPersonalMail:async(t,n)=>{let{data:r,error:i}=await e.linkSocial({provider:t.provider,scopes:t.scopes,additionalParams:t.params,callbackURL:n,errorCallbackURL:n,disableRedirect:!0});if(i||!r?.url)throw R(i,`Could not start linking the mailbox`);return r.url},connectedApps:async()=>{let{data:t,error:n}=await e.$fetch(`/account/connected-apps`);if(n||!t)throw R(n,`Could not read your connected apps`);return t.apps},disconnectApp:async t=>{let{error:n}=await e.$fetch(`/account/connected-apps/disconnect`,{method:`POST`,body:{clientId:t}});if(n)throw R(n,`Could not disconnect the app`)},newBackupCodes:async t=>{let{data:n,error:r}=await e.twoFactor.generateBackupCodes(t?{password:t}:{});if(r||!n)throw R(r,`Could not make new backup codes`);return n.backupCodes}}),Ou=(e,t)=>new wu(e?.message||e?.error_description||t,e?.status??500,e?.code??e?.error),ku=e=>({client:async t=>{let{data:n,error:r}=await e.$fetch(`/oauth2/public-client`,{query:{client_id:t}});if(r||!n)throw Ou(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 Ou(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 Ou(i,`Could not answer the request`);return{url:r.url}}}),Au=(e,t,n)=>x({baseURL:e,basePath:t,plugins:[k(),O(),m(),A()],disableDefaultFetchPlugins:!0,fetchOptions:{customFetchImpl:n}}),ju=e=>Array.isArray(e)?e.filter(e=>typeof e==`string`):typeof e==`string`?JSON.parse(e):[],Mu=e=>{let t=e.split(`,`);return t.includes(`owner`)?`owner`:t.includes(`admin`)?`admin`:`member`},Nu=e=>({id:e.id,userId:e.userId,name:e.user.name||e.user.email,email:e.user.email,role:Mu(e.role),appRoles:ju(e.appRoles),createdAt:new Date(e.createdAt).toISOString()}),Pu=e=>({id:e.id,email:e.email,role:Mu(e.role),appRoles:ju(e.appRoles),status:e.status,expiresAt:new Date(e.expiresAt).toISOString(),...e.organizationName&&{organizationName:e.organizationName}}),Fu=(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(Nu),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(Pu),invite:async(e,t)=>{let r=await n(`/organization/invite-member`,`Could not send the invitation`,{body:{organizationId:e,...t}});return{invitation:Pu(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:Pu(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(Pu),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}}))}},Iu=(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()}}),Lu=20,Ru=e=>Array.isArray(e)?e:(e??``).split(`,`).map(e=>e.trim()).filter(Boolean),zu=e=>({id:e.id,name:e.name||e.email,email:e.email,roles:Ru(e.role),blocked:!!e.banned,createdAt:new Date(e.createdAt).toISOString()}),Bu=e=>({id:e.id,email:e.email,roles:e.roles,expiresAt:new Date(e.expiresAt).toISOString()}),Vu=e=>({invitation:Bu(e),...e.link&&{link:e.link}}),Hu=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(Lu),sortBy:`createdAt`,sortDirection:`asc`,...n>0&&{offset:String(n)},...e&&{searchValue:e,searchField:`email`}}});return{users:r.users.map(zu),total:r.total}},create:async e=>zu((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=>Vu(await t(`/users/invite`,`Could not send the invitation`,{body:e})),invitations:async()=>(await t(`/users/invitations`,`Could not read the invitations`)).invitations.map(Bu),revoke:e=>t(`/users/invitations/cancel`,`Could not revoke the invitation`,{body:{id:e}}),roles:()=>t(`/users/roles`,`Could not read the roles`)}},Uu=(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 wu(`Auth cancelled`,400,e instanceof oe?e.code:`AUTH_CANCELLED`)}),s=await e.$fetch(`/passkey/verify-authentication`,{method:`POST`,body:{response:o}});if(s.error||!s.data)throw R(s.error,`Sign-in failed`);return await t(),s.data.user},sendTwoFactorCode:async()=>{let{error:t}=await e.twoFactor.sendOtp();if(t)throw R(t,`Could not send the code`)},verifyTwoFactor:async({method:n,code:r,trustDevice:i=!1})=>{let{data:a,error:o}=await(n===`totp`?e.twoFactor.verifyTotp:n===`otp`?e.twoFactor.verifyOtp:e.twoFactor.verifyBackupCode)({code:r,trustDevice:i});if(o||!a)throw R(o,`The code did not work`);return await t(),a.user}}},Wu=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}}),Gu=e=>new Date(e).toISOString(),Ku=({startedAt:e,expiresAt:t,endedAt:n,...r})=>({...r,startedAt:Gu(e),expiresAt:Gu(t),...n&&{endedAt:Gu(n)}}),qu=e=>({start:async t=>{let{data:n,error:r}=await e.$fetch(`/staff/sign-in`,{method:`POST`,body:t});if(r||!n?.url)throw R(r,`Could not start the staff sign-in`);return n.url},current:async()=>{let{data:t,error:n}=await e.$fetch(`/staff/session`);if(n||!t)throw R(n,`Could not read the session`);return t.staff?Ku(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(Ku)}}),Ju=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},Yu=(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=Au(t,n,i),o=qu(a),s,c,l,u=()=>{s=void 0,clearTimeout(l)},d=async()=>{let{data:t}=await a.$fetch(`/token`);if(!t?.token){u();return}return s={token:t.token,expiresAt:Ju(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 wu(`This server has no sign-in. Is the API URL right?`,404);if(!e.ok)throw new wu(`Could not read the sign-in status`,e.status);let r=await e.json();return{needsAdmin:!!r.needsAdmin,...r.needsAdmin&&r.firstAdminUrl&&{firstAdminUrl:r.firstAdminUrl},signInMethods:r.signInMethods??[`password`],...r.signInFirst===`emailCode`&&{signInFirst:`emailCode`},passwordReset:!!r.passwordReset,...r.changeEmail&&{changeEmail:!0},...r.accountDeletion&&{accountDeletion:!0},...r.signUp&&{signUp:!0},socialProviders:r.socialProviders??[],...r.platformSignIn&&{platformSignIn:r.platformSignIn},samlProviders:r.samlProviders??[],...r.staffSignIn&&{staffSignIn:r.staffSignIn},...r.passkeyDomains&&{passkeyDomains:r.passkeyDomains},...r.organizations&&{organizations:r.organizations},...r.anonymous&&{anonymous:!0},...r.mcp&&{mcp:{url:r.mcp.url}},...r.personalMail&&r.personalMail.length>0&&{personalMail:r.personalMail},...r.plugins&&r.plugins.length>0&&{plugins:r.plugins},...Fe(r.locale)&&{locale:r.locale}}},session:async()=>{let{data:e}=await a.getSession();return e?.user},...Uu(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:{...Du(a),...Eu(a)},connect:ku(a),organizations:Fu(a,()=>f({refresh:!0})),roles:Iu(a,()=>f({refresh:!0})),signInPolicy:Wu(a),users:Hu(a),staff:{...o,stop:async()=>{u(),await o.stop()}}}},Xu=e=>Math.min(3e4,1e3*2**e),Zu=(e,t)=>new Promise(n=>{let r=setTimeout(n,e);t.addEventListener(`abort`,()=>{clearTimeout(r),n()},{once:!0})}),Qu=`http://same-origin.invalid`,$u=(e,t)=>{let n=new URL(e,Qu),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===Qu?`${r.pathname}${r.search}`:r.href},ed=e=>{let t=e.url.replace(/\/+$/,``),n=e.fetch??((e,t)=>fetch(e,t)),r=e.retryDelayMs??Xu,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 hl(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 nr(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 Zu(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=$u(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 hl(c);return c}}},td=e=>typeof e==`object`&&!!e&&`error`in e&&typeof e.error==`object`&&e.error!==null&&`code`in e.error&&`message`in e.error,nd=async e=>{let t=e.headers.get(`content-type`)?.includes(`json`)??!1?await e.clone().json():void 0;return td(t)?new dl({type:`urn:protobase:problem:${t.error.code}`,title:e.statusText||`Request failed`,status:e.status,detail:t.error.message}):hl(e)},rd=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 nd(o);return await o.json()};return{status:()=>r(``,`GET`),update:()=>r(`/update`,`POST`)}},id=e=>e.Capacitor?.isNativePlatform()?e.Capacitor:void 0,ad=[101,204,205,304],od=/%2f|%5c/i,sd=e=>Object.hasOwn(hr,e),cd=(e,t)=>e.origin===t&&!e.username&&!e.password&&e.pathname.startsWith(`/api/auth/`)&&!od.test(e.pathname),ld=({status:e,headers:t,data:n})=>ad.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),ud=(e,t)=>{let n=e.getPlatform();if(!sd(n))throw Error(`Signing in through native HTTP is for iOS and Android, not ${n}`);return async(n,r)=>{let i=new Request(n,r),a=new URL(i.url);if(!cd(a,t))throw Error(`Native sign-in requests go to ${t}${mr}/ only, not ${i.url}`);let o=i.method!==`GET`&&i.method!==`HEAD`,s=await e.nativePromise(`ProtobaseAuth`,`request`,{url:a.href,method:i.method,headers:Object.fromEntries(i.headers),...o&&{data:await i.text()}}),c=Object.entries(s.headers).filter(([e])=>e.toLowerCase()!==`set-cookie`);return new Response(ld(s),{status:s.status,headers:c})}},dd=(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(`/${_r}`),t.serviceWorker.ready),clearBadge:async()=>{`clearAppBadge`in t&&await t.clearAppBadge()},userAgent:t.userAgent.replace(/[\u0000-\u001f\u007f]/g,``).slice(0,512)}},fd=(e=indexedDB)=>{let t=(t,n)=>new Promise((r,i)=>{let a=e.open(gr.database,1);a.onupgradeneeded=()=>a.result.createObjectStore(gr.store),a.onerror=()=>i(a.error),a.onsuccess=()=>{let e=a.result,o=n(e.transaction(gr.store,t).objectStore(gr.store));o.onsuccess=()=>(e.close(),r(o.result)),o.onerror=()=>(e.close(),i(o.error))}});return{read:()=>t(`readonly`,e=>e.get(gr.key)),write:async e=>void await t(`readwrite`,t=>t.put(e,gr.key)),clear:async()=>void await t(`readwrite`,e=>e.delete(gr.key))}},pd=e=>Uint8Array.from(atob(e.replace(/-/g,`+`).replace(/_/g,`/`)),e=>e.charCodeAt(0)),md=(e,t)=>Promise.race([t,new Promise(t=>setTimeout(t,e))]),hd=class extends Error{},gd=(e,t)=>e instanceof dl&&e.status===409&&e.slug===t,_d=({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 hd;let e=await c.pushManager.getSubscription()??await c.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:pd(a)}),i={userId:n.id,endpoint:e.endpoint,appName:r};if(await t.write(i),!o())throw new hd;await d(e,i)};try{await h()}catch(e){if(gd(e,`device-held`))return await u(c),m(c,h);if(await u(c),e instanceof hd||gd(e,`other-user`))return`off`;throw e}return`on`},m=async(e,t)=>{try{await t()}catch(t){if(await u(e),t instanceof hd||gd(t,`device-held`)||gd(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 md(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 md(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(!gd(e,`device-held`)&&!gd(e,`other-user`))throw e;await u(r)}}}},vd={state:async()=>`unsupported`,turnOn:async()=>`unsupported`,turnOff:async()=>{},forget:async()=>{},adopt:async()=>{}},yd=({nativeBridge:e,...t})=>{if(e||typeof window>`u`)return vd;let n=dd();return n.supported?_d({...t,browser:n,records:fd()}):vd},bd=`sign-in`,xd=`error`,Sd=e=>{let t=new URL(e).searchParams;if(!t.has(xd))return t.get(`sign-in`)||void 0},Cd=e=>new URL(e).searchParams.get(xd)||void 0,wd=e=>{let t=new URL(e);for(let e of[bd,xd])t.searchParams.delete(e);return`${t.pathname}${t.search}${t.hash}`},Td={github:`GitHub`,gitlab:`GitLab`,google:`Google`,microsoft:`Microsoft`,apple:`Apple`},Ed=(e,t)=>t?.provider===e?t.name:Td[e]??e.charAt(0).toUpperCase()+e.slice(1),z=M(`auth`),B=e(r(),1),Dd=(0,I.createContext)(null),V=()=>{let e=(0,I.useContext)(Dd);if(!e)throw Error(`useAuth must be used inside AuthProvider`);return e},Od=()=>(0,I.useContext)(Dd),kd=({session:e,origin:t,nativeBridge:n,children:r})=>{let[i,a]=(0,I.useState)({kind:`loading`}),[o,s]=(0,I.useState)([`password`]),[c,l]=(0,I.useState)(`password`),[u,d]=(0,I.useState)(!1),[f,p]=(0,I.useState)(!1),[m,h]=(0,I.useState)(!1),[g,_]=(0,I.useState)(),[v,y]=(0,I.useState)(!1),[b,x]=(0,I.useState)([]),[S,C]=(0,I.useState)([]),[w,T]=(0,I.useState)(),[E,D]=(0,I.useState)([]),[O,k]=(0,I.useState)([]),[A,j]=(0,I.useState)(),[ee,te]=(0,I.useState)(),[ne,re]=(0,I.useState)(!1),[ie,ae]=(0,I.useState)([]),[oe,se]=(0,I.useState)(),ce=(0,I.useCallback)(()=>ne?{kind:`visitor`}:{kind:`signed-out`},[ne]),le=(0,I.useRef)(async()=>{}),ue=(0,I.useCallback)(()=>{le.current(),a(e=>e.kind===`signed-in`?{kind:`signed-out`}:e)},[]),de=(0,I.useRef)(ue);de.current=ue;let fe=(0,I.useMemo)(()=>e??Yu({...t&&{origin:t},...n&&{fetch:ud(n,t??window.location.origin)},onSignedOut:()=>de.current()}),[e,t,n]),pe=(0,I.useRef)(void 0);pe.current=i.kind===`signed-in`?{id:i.user.id,own:!i.staff}:void 0;let me=(0,I.useMemo)(()=>{let e=eu({baseUrl:`${t??globalThis.location?.origin??``}/api/v1`,token:({refresh:e})=>fe.token({refresh:e})}),r=async()=>{let t=await e.meta();if(t.status!==`modified`)throw Error(`The app answered /meta without its content`);return{appName:t.meta.appName,...t.meta.notifications?.webPushKey&&{webPushKey:t.meta.notifications.webPushKey}}};return yd({...n&&{nativeBridge:n},devices:e.devices,meta:r,user:()=>pe.current})},[fe,t,n]);le.current=me.forget;let he=(0,I.useCallback)(async e=>{let[{missing:t},n]=await Promise.all([fe.account.signInMethods(),fe.staff.current()]);a(t.length>0?{kind:`setup-required`,user:e,missing:t}:{kind:`signed-in`,user:e,...n&&{staff:n}}),t.length===0&&me.adopt({id:e.id,own:!n})},[fe,me]),ge=(0,I.useCallback)(async e=>e.kind===`two-factor`?a({kind:`two-factor`,methods:e.methods}):he(e.user),[he]),_e=(0,I.useCallback)(()=>{a({kind:`loading`}),fe.status().then(async e=>{if(s(e.signInMethods),l(e.signInFirst??`password`),d(e.passwordReset&&!n),p(!!e.changeEmail),h(!!e.accountDeletion),_(e.mcp),y(!!e.signUp),x(e.passkeyDomains??[]),C(e.socialProviders),T(e.platformSignIn),D(e.personalMail??[]),k(e.samlProviders),j(e.staffSignIn),te(e.organizations),re(!!e.anonymous),ae(e.plugins??[]),se(e.locale),e.needsAdmin)return a({kind:`needs-admin`,...e.firstAdminUrl&&{firstAdminUrl:e.firstAdminUrl}});let t=await fe.session();return t?he(t):a({kind:e.anonymous?`visitor`:`signed-out`})}).catch(e=>a({kind:`error`,message:e instanceof Error?e.message:z(`noAnswer`)}))},[fe,he,n]);(0,I.useEffect)(_e,[_e]);let ve=(0,I.useMemo)(()=>({state:i,session:fe,signInMethods:o,signInFirst:c,passwordReset:u,changeEmail:f,accountDeletion:m,mcp:g,canSignUp:v,passkeyDomains:b,socialProviders:S,signInProviders:[...S.map(e=>({id:e,name:Ed(e,w)})),...O],staffSignIn:A,...ee&&{organizations:ee},markSignedOut:ue,recheck:_e,beforeSignIn:ie,locale:oe,adoptSession:async()=>{let e=await fe.session();return e?(await he(e),!0):!1},...ne&&{browse:()=>{a(e=>e.kind===`signed-out`?{kind:`visitor`}:e)}},signIn:async(e,t)=>ge(await fe.signIn(e,t)),sendSignInCode:e=>fe.sendSignInCode(e),signInWithCode:async(e,t)=>ge(await fe.signInWithCode(e,t)),sendSignUpCode:e=>fe.sendSignUpCode(e),verifySignUpCode:(e,t)=>fe.verifySignUpCode(e,t),signUp:async e=>he(await fe.signUp(e)),signInWithPasskey:async e=>he(await fe.signInWithPasskey(e)),verifyTwoFactor:async e=>he(await fe.verifyTwoFactor(e)),signInSocial:async e=>{let t=new URL(wd(window.location.href),window.location.href).href,n=O.some(t=>t.id===e);window.location.assign(await(n?fe.signInSaml(e,t):fe.signInSocial(e,t)))},linkProvider:async e=>{window.location.assign(await fe.account.linkProvider(e,new URL(wd(window.location.href),window.location.href).href))},personalMail:E,linkPersonalMail:async e=>{window.location.assign(await fe.account.linkPersonalMail(e,new URL(wd(window.location.href),window.location.href).href))},stopStaffSession:async()=>{await me.forget(),await fe.staff.stop(),a(ce())},signOut:async()=>{await me.turnOff(),await fe.signOut(),a(ce())},deleteAccount:async e=>{await fe.deleteAccount(e),await me.forget(),a(ce())},push:me}),[me,i,fe,o,c,u,f,m,g,v,b,S,w,E,O,A,ee,ne,ie,oe,ce,ue,_e,ge,he]);return(0,B.jsx)(Dd.Provider,{value:ve,children:r})},Ad=()=>{let e=0;return{refetchOnWindowFocus:()=>e>0?!1:`always`,paused:()=>e>0,pause:()=>{e+=1;let t=!1;return()=>{t||(t=!0,--e)}}}},jd=(0,I.createContext)(null),Md=e=>{let t=(0,I.useContext)(jd);(0,I.useEffect)(()=>e&&t?t.pause():void 0,[e,t])},Nd=e=>{let t=()=>e();return window.addEventListener(`visibilitychange`,t,!1),window.addEventListener(`focus`,t,!1),()=>{window.removeEventListener(`visibilitychange`,t),window.removeEventListener(`focus`,t)}},H={meta:[`meta`],sourceMeta:(e,t)=>[`source-meta`,e,t.join(`,`)],sourceMetas:e=>[`source-meta`,e],list:(e,t,n,r,i)=>[`list`,e,t,n,r,i],page:(e,t,n,r,i)=>[`page`,e,t,n,r,i],pages:(e,t,n)=>[`page`,e,t,n],navRecent:(e,t,n,r)=>[`list`,e,t,n,r,`nav-recent`],first:(e,t,n)=>[`first-page`,e,t,n],record:(e,t)=>[`record`,e,t],recordPreview:(e,t)=>[`record-preview`,e,t],history:(e,t,n)=>[`record`,e,t,`history`,n],comments:(e,t)=>[`record`,e,t,`comments`],facets:(e,t,n)=>[`facets`,e,t,n],series:(e,t,n,r,i)=>[`series`,e,t,n,r,i],aggregate:(e,t)=>[`aggregate`,e,t],histogram:(e,t,n,r)=>[`histogram`,e,t,n,r],map:(e,t,n,r,i)=>[`map`,e,t,n,r,i],relatedLabel:(e,t)=>[`related-label`,e,t],titleRow:(e,t,n)=>[`title-row`,e,t,n],labels:(e,t)=>[`labels`,e,t],pickedLabels:(e,t)=>[`picked-labels`,e,t],count:(e,t)=>[`count`,e,t],exportCount:(e,t)=>[`list`,e,t,`export-count`],firstRecord:(e,t,n)=>[`first-record`,e,t,n],pathValue:(e,t,n)=>[`path-value`,e,t,n],inbox:[`inbox`],inboxUnread:[`inbox`,`unread`],inboxPages:[`inbox`,`pages`],members:e=>[`members`,e],statuses:e=>[`statuses`,e],ownStatus:e=>[`statuses`,e,`own`],rings:[`call-rings`],recordCalls:(e,t)=>[`record-calls`,e,t],publicForm:e=>[`public-form`,e]},Pd=(0,I.createContext)(null),Fd=(0,I.createContext)(null),Id=(0,I.createContext)(null),U=()=>{let e=(0,I.useContext)(Pd);if(!e)throw Error(`useClient must be used inside ApiProvider`);return e},Ld=e=>{let t=U();return(0,I.useContext)(Id)?.(e)??t},Rd=()=>{let e=U(),t=(0,I.useContext)(Id);return(0,I.useCallback)(n=>t?.(n)??e,[e,t])},zd=()=>{let e=(0,I.useContext)(Fd);if(!e)throw Error(`useSourceClients must be used inside ApiProvider`);return e},Bd=({client:e,resourceClient:t,children:n})=>(0,B.jsx)(Pd.Provider,{value:e,children:(0,B.jsx)(Id.Provider,{value:t,children:n})}),Vd=({baseUrl:e,client:t,sources:n,fetch:r,queryClient:i,token:a,onUnauthenticated:o,children:s})=>{let[c]=(0,I.useState)(Ad),[l]=(0,I.useState)(()=>i??new T({defaultOptions:{queries:{staleTime:3e4,retry:!1,refetchOnWindowFocus:c.refetchOnWindowFocus}}}));(0,I.useEffect)(()=>D.setEventListener(Nd),[]);let u=(0,I.useRef)(void 0),d=(0,I.useMemo)(()=>t??eu({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=eu({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)(Pd.Provider,{value:d,children:(0,B.jsx)(Fd.Provider,{value:f,children:(0,B.jsx)(jd.Provider,{value:c,children:s})})})})},Hd=(0,I.createContext)(null),Ud={create:!0,update:!0,delete:!0,conditional:[]},Wd=(e,t)=>e?e.versionChange?e:t.protobaseVersion===e.protobaseVersion?t:{...e,versionChange:{...t.protobaseVersion&&{to:t.protobaseVersion}}}:t,Gd=()=>{let e=U(),t=Se(),n=(0,I.useContext)(Hd),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 Wd(n,{etag:r.etag,appName:r.meta.appName,...r.meta.protobaseVersion&&{protobaseVersion:r.meta.protobaseVersion},...r.meta.appIcon&&{appIcon:r.meta.appIcon},resources:Object.fromEntries(r.meta.resources.map(e=>[e.name,e])),views:Object.fromEntries(r.meta.views.map(e=>[e.resource,e])),pages:Object.fromEntries((r.meta.pages??[]).map(e=>[e.name,e])),...r.meta.account&&{account:r.meta.account},permissions:r.meta.permissions??{},...r.meta.userMenu&&{userMenu:r.meta.userMenu},...r.meta.signIn&&{signIn:Object.fromEntries(r.meta.signIn.map(e=>[e.resource,e]))},...r.meta.bottomBar&&{bottomBar:r.meta.bottomBar},...r.meta.assistant&&{assistant:r.meta.assistant},...r.meta.runtime&&{runtime:r.meta.runtime},...r.meta.errorReporting&&{errorReporting:r.meta.errorReporting},...r.meta.maps&&{maps:r.meta.maps},...r.meta.notifications?.bell&&{bell:!0},...r.meta.status&&{status:!0},...r.meta.calls&&{calls:!0},...r.meta.locale&&{locale:r.meta.locale},...r.meta.files&&{files:r.meta.files},...r.meta.plugins&&{plugins:r.meta.plugins},...r.meta.sources&&{sources:r.meta.sources.map(e=>({source:e,state:`loading`}))}})}});return(0,I.useMemo)(()=>n&&r.data?{...r,data:n}:r,[n,r])},Kd=1e4,qd=e=>e.map(e=>({data:e.data?.meta,error:e.error})),Jd=(e,t)=>{let n=Se(),r=f({queries:e.map(e=>{let r=H.sourceMeta(e.url,e.resources);return{queryKey:r,staleTime:0,refetchOnWindowFocus:`always`,queryFn:async()=>{let i=n.getQueryData(r),a=await t(e).meta(i?.etag,{signal:AbortSignal.timeout(Kd)});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:Cu(a.meta,e)}}}}),combine:qd});return(0,I.useMemo)(()=>e.map((e,t)=>{let{data:n,error:i}=r[t];return n?{source:e,state:`ready`,meta:n}:i?{source:e,state:`error`,error:i}:{source:e,state:`loading`}}),[e,r])},Yd=(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}},Xd=(e,t)=>e.sources?.find(e=>e.source.resources.includes(t)),Zd=({locale:e,children:t})=>{He(e);let n=Be();return(0,I.useEffect)(()=>{document.documentElement.lang=n},[n]),(0,B.jsx)(I.Fragment,{children:t},n)},Qd=M(`primitives`),$d=({className:e})=>(0,B.jsx)(eo,{"aria-label":Qd(`loading`),className:P(`size-4 animate-spin`,e)}),ef=M(`app/meta-gate`),W=()=>{let e=(0,I.useContext)(Hd);if(!e)throw Error(`useAdminMeta must be used inside MetaGate`);return e},tf=({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})]})}),nf=({meta:e,children:t})=>{let n=U(),r=zd(),i=(0,I.useMemo)(()=>(e.sources??[]).map(e=>e.source),[e.sources]),a=Jd(i,r),o=(0,I.useMemo)(()=>Yd(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:nu(n,t),resourceClient:t}},[i,n,r]);return(0,B.jsx)(Bd,{client:s.client,resourceClient:s.resourceClient,children:(0,B.jsx)(Hd.Provider,{value:o,children:(0,B.jsx)(Zd,{locale:e.locale,children:t})})})},rf=({children:e})=>{let t=Gd();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)($d,{}),` `,ef(`loading`)]}):t.error?(0,B.jsx)(tf,{title:ef(`cannotReach`),children:pl(t.error)?t.error.message:ef(`noAnswer`)}):(0,B.jsx)(nf,{meta:t.data,children:e})},af=e=>W().permissions[e]??Ud,of=(0,I.createContext)(null),sf=({route:e,children:t})=>(0,B.jsx)(of.Provider,{value:e,children:t}),cf=()=>{let e=(0,I.useContext)(of);if(!e)throw Error(`Tabs render inside a page that gives them their addresses: a composed page`);return e},lf=e=>e.children.filter(e=>typeof e!=`string`).map(e=>({node:e,...e.props})),uf=e=>{let t=e.children.find(e=>typeof e!=`string`&&!e.custom&&e.type===`Tabs`);return t?lf(t):[]},df=(e,t)=>t===void 0?e[0]:e.find(e=>e.name===t),ff={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`},pf={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`},mf=({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`,ff[e],pf[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(mf({variant:e,size:t}),r),...o,children:[n&&(0,B.jsx)($d,{className:`size-3.5`}),i]}),hf=e=>(0,I.useSyncExternalStore)(t=>{let n=window.matchMedia(e);return n.addEventListener(`change`,t),()=>n.removeEventListener(`change`,t)},()=>window.matchMedia(e).matches,()=>!1),gf=()=>hf(`(min-width: 768px)`),_f=()=>hf(`not all and (min-width: 640px)`),vf=`data-pb-scroll-locked`,yf=()=>{let{body:e,documentElement:t}=document,n=e.style.overflow,r=t.hasAttribute(vf);return window.innerWidth>t.clientWidth&&t.setAttribute(vf,``),e.style.overflow=`hidden`,()=>{e.style.overflow=n,r||t.removeAttribute(vf)}},bf=`a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])`,xf=[],Sf=(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=yf(),o={};xf.push(o);let s=()=>[...n.querySelectorAll(bf)];(s()[0]??n).focus();let c=e=>{if(xf.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),xf.splice(xf.indexOf(o),1),a(),i?.focus()}},[t,e])},Cf=({title:e,description:t,onClose:n,actions:r,children:i,wide:a=!1,name:o})=>{let s=(0,I.useRef)(null);return Sf(s,!0,n),(0,Sc.createPortal)((0,B.jsx)(`div`,{"data-dialog":o??``,className:`fixed inset-0 z-[90] flex items-center justify-center bg-backdrop/30 p-4 pb-[calc(1rem+var(--pb-safe-bottom))] pl-[calc(1rem+var(--pb-safe-left))] pr-[calc(1rem+var(--pb-safe-right))] pt-[calc(1rem+var(--pb-safe-top))]`,onMouseDown:e=>e.target===e.currentTarget&&n(),children:(0,B.jsxs)(`div`,{ref:s,tabIndex:-1,role:`dialog`,"aria-modal":`true`,"aria-label":e,className:P(`outline-none max-h-[min(90vh,100%)] w-full overflow-y-auto rounded-lg border bg-background p-4 shadow-pop sm:p-5`,a?`max-w-3xl`:`max-w-md`),children:[(0,B.jsx)(`h2`,{className:`text-[16px] font-semibold`,children:e}),t&&(0,B.jsx)(`p`,{className:`mt-1.5 text-muted-foreground`,children:t}),i&&(0,B.jsx)(`div`,{className:`mt-4`,children:i}),(0,B.jsx)(`div`,{className:`mt-5 flex flex-col-reverse gap-2 sm:flex-row sm:justify-end [&>*]:min-h-11 sm:[&>*]:min-h-0`,children:r})]})}),document.body)},wf=(e,t)=>t>=60&&t>Math.abs(e),Tf=({title:e,open:t,onClose:n,children:r})=>{let i=(0,I.useRef)(null),a=(0,I.useRef)(void 0);return Sf(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=wf(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":Qd(`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)(yc,{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},Ef=({title:e,description:t,open:n,onClose:r,actions:i,children:a,wide:o})=>{let s=gf();return n?s?(0,B.jsx)(Cf,{title:e,description:t,onClose:r,actions:i,wide:o,children:a}):(0,B.jsx)(Tf,{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},Df=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},Of=`#ffffff`,kf=`#111827`,Af=e=>{let t=Df(e);return 1.05/(t+.05)>=(t+.05)/(Df(kf)+.05)?Of:kf},jf={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`},Mf={neutral:`bg-faint-foreground`,blue:`bg-primary`,green:`bg-success`,amber:`bg-warning`,red:`bg-danger`,violet:`bg-violet`},Nf=`polygon(0 0, calc(100% - 0.625rem) 0, 100% 50%, calc(100% - 0.625rem) 100%, 0 100%)`,Pf=({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:Af(n)},...r===`arrow`&&{clipPath:Nf}},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&&jf[e],a),children:[t&&n===void 0&&r===void 0&&(0,B.jsx)(`span`,{className:P(`size-1.5 rounded-full`,Mf[e])}),i]}),Ff={xs:`size-5 text-[9px]`,sm:`size-6 text-[10px]`,md:`size-8 text-xs`},If=({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`,Ff[n],r),style:{background:`oklch(0.58 0.13 ${t})`},children:e}),Lf=({people:e,size:t=`sm`})=>(0,B.jsx)(`span`,{className:`inline-flex -space-x-1`,children:e.map(e=>(0,B.jsx)(If,{...e,size:t},e.initials))}),Rf=M(`record-view`),zf=({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)(Pf,{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:[Rf(`lastEditedBy`),` `,(0,B.jsx)(`span`,{className:`font-medium text-foreground`,children:r.name}),` `,r.ago]}):(0,B.jsx)(B.Fragment,{children:Rf(`lastUpdated`,{ago:r.ago})})})]}),(0,B.jsxs)(`div`,{className:`flex items-center gap-4`,children:[i.length>0&&(0,B.jsxs)(`span`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,B.jsx)(Lf,{people:i,size:`md`}),Rf(`viewing`,{count:i.length})]}),a]})]}),Bf=({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]})},Vf=({title:e,help:t,actions:n,children:r})=>(0,B.jsx)(`section`,{className:`py-8 first:pt-8`,children:(0,B.jsx)(Bf,{title:e,help:t,actions:n,children:r})}),Hf=new Map,Uf=(e,t)=>{let n=Le(),r=`${n}|${e}`;return Hf.has(r)||Hf.set(r,t(n)),Hf.get(r)},Wf=M(`format`),Gf=()=>Intl.DateTimeFormat().resolvedOptions().timeZone,Kf=new Map,qf=e=>{let t=Kf.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 Kf.set(e,n),n},Jf=(e,t)=>{let n=Object.fromEntries(qf(t).formatToParts(e).map(e=>[e.type,e.value]));return{year:Number(n.year),month:Number(n.month),day:Number(n.day),hour:Number(n.hour),minute:Number(n.minute),second:Number(n.second)}},Yf=(e,t)=>{let n=Jf(e,t);return Date.UTC(n.year,n.month-1,n.day,n.hour,n.minute,n.second)-Math.floor(e/1e3)*1e3},Xf=e=>String(e).padStart(2,`0`),Zf=(e,t)=>{let n=Jf(e,t);return`${n.year}-${Xf(n.month)}-${Xf(n.day)}`},Qf=(e,t)=>e-Yf(e-Yf(e,t),t),$f=(e,t)=>Qf(Date.parse(`${e}T00:00:00Z`),t),ep=(e,t)=>{let n=Uf(`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})`},tp=(e,t)=>()=>Uf(`date:${e}`,e=>new Intl.DateTimeFormat(e,{...t,timeZone:`UTC`})),np=tp(`day`,{day:`numeric`,month:`short`,year:`numeric`}),rp=tp(`dayShort`,{day:`numeric`,month:`short`}),ip=tp(`month`,{month:`long`,year:`numeric`}),ap=tp(`monthName`,{month:`long`}),op=tp(`weekday`,{weekday:`short`}),sp=tp(`weekdayDate`,{weekday:`long`,day:`numeric`,month:`short`,year:`numeric`}),cp=e=>np().format(e),lp=e=>rp().format(e),up=e=>Uf(`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})})),dp=(e,t=Gf())=>{let n=up(t);return`${n.day.format(e)}, ${n.time.format(e)}`},fp=e=>ip().format(e),pp=e=>ap().format(e),mp=(e,t)=>ip().formatRange(e,t),hp=e=>op().format(e),gp=e=>sp().format(e),_p=(e,t)=>np().formatRange(e,t),vp=(e,t=Gf())=>up(t).time.format(e),yp=e=>e<60?Wf(`secondsAgo`,{count:e}):e<3600?Wf(`minutesAgo`,{count:Math.floor(e/60)}):e<86400?Wf(`hoursAgo`,{count:Math.floor(e/3600)}):Wf(`daysAgo`,{count:Math.floor(e/86400)}),bp=()=>Uf(`relative`,e=>new Intl.RelativeTimeFormat(e,{numeric:`auto`})),xp=[[`year`,31536e3],[`month`,2592e3],[`day`,86400],[`hour`,3600],[`minute`,60]],Sp=e=>{let t=Math.abs(e),[n,r]=xp.find(([,e])=>t>=e)??[`second`,1];return n===`second`&&t<45?Wf(`justNow`):bp().format(-Math.sign(e)*Math.floor(t/r),n)},Cp=()=>Uf(`grouped`,e=>new Intl.NumberFormat(e)),wp=e=>Cp().format(e),Tp=e=>e>0?`+${Cp().format(e)}`:Cp().format(e).replace(`-`,`−`),Ep=e=>`${e}%`,Dp=e=>{if(e<1e4)return Wf(`rows`,{count:wp(e),n:e});let t=10**(Math.floor(Math.log10(e))-3);return Wf(`aboutRows`,{count:wp(Math.round(e/t)*t)})},Op=(e,t)=>Uf(`money:${e}:${t??``}`,n=>new Intl.NumberFormat(n,{style:`currency`,currency:e,...t!==void 0&&{minimumFractionDigits:t,maximumFractionDigits:t}})),kp=(e,t,n)=>Op(t,n).format(e/100),Ap=M(`live`),jp=e=>typeof e==`object`&&!!e&&typeof e.uri==`string`,Mp=e=>typeof e==`object`&&!!e&&typeof e.uploaded?.value==`string`,Np=e=>{if(Mp(e))return{...e.uploaded.file,...e.preview&&{url:e.preview},corrected:e.uploaded.corrected};if(jp(e))return`missing`in e?{name:Ap(`fileMissing`),type:``,missing:!0}:e},Pp=[`bytes`,`kB`,`MB`,`GB`],Fp=e=>{let t=e,n=0;for(;t>=1e3&&n<Pp.length-1;)t/=1e3,n+=1;return n===0?`${e} ${e===1?`byte`:`bytes`}`:`${t<10?t.toFixed(1):Math.round(t)} ${Pp[n]}`},Ip=e=>e.startsWith(`image/`)&&e!==`image/svg+xml`,Lp=2,Rp=1e5,zp=(e,t)=>(e.width!==void 0||e.height!==void 0)&&(e.width??Rp)>=t.width*Lp&&(e.height??Rp)>=t.height*Lp,Bp=e=>(e.width??Rp)*(e.height??Rp),Vp=(e,t)=>{let n=Np(e);if(!(!n||`missing`in n||!n.url||!Ip(n.type)))return{url:(`variants`in n&&n.variants?Object.values(n.variants):[]).filter(e=>zp(e,t)).sort((e,t)=>Bp(e)-Bp(t))[0]?.url??n.url,...`placeholder`in n&&n.placeholder!==void 0&&{placeholder:n.placeholder}}},Hp=e=>{let t=e.file?.accept??[];return t.length===0||t.includes(`*/*`)?void 0:t.join(`,`)},Up=e=>Mp(e)?e.uploaded.value:jp(e)?e.uri:null,Wp=(e,t)=>{if(Mp(e))return!0;let n=e=>jp(e)?e.uri:null;return n(e)!==n(t)},Gp=M(`data-grid`),Kp=e=>typeof e==`object`&&e&&`name`in e?String(e.name):String(e),qp=(e,t)=>{if(t==null)return`—`;switch(e.kind){case`text`:case`id`:return String(t);case`money`:if(e.currency===void 0)throw Error(`Money column "${e.id}" has no currency`);return`${kp(Number(t),e.currency,e.decimals)}${e.suffix??``}`;case`date`:return cp(Number(t));case`datetime`:return e.relative?Sp(Math.round((Date.now()-Number(t))/1e3)):dp(Number(t));case`number`:return`${e.prefix??``}${wp(Number(t))}${e.suffix??``}`;case`signed`:return`${e.prefix??``}${Tp(Number(t))}${e.suffix??``}`;case`percent`:return Number(t)===0?`—`:Ep(Number(t));case`status`:return ir(String(t),e.labels);case`relation`:return Kp(t);case`boolean`:return t?void 0:Gp(`no`);case`file`:return Np(t)?.name??`—`;case`user`:return e.users?.(String(t))?.name??String(t)}},Jp=(e,t)=>Math.ceil(e.length*7.2)+24+(t?16:0)+28,Yp=e=>Math.ceil(Math.max(0,...e.map(e=>e.length))*7.2)+56,Xp={body:7.5,mono:7.2,numeric:8},Zp=24,Qp=24,$p=16,em=new Set([`status`,`money`,`number`,`signed`,`percent`,`date`,`datetime`,`boolean`]),tm=new Set([`money`,`number`,`signed`,`percent`,`date`,`datetime`]),nm=80,rm=400,im=240,am=e=>e===`id`?Xp.mono:tm.has(e)?Xp.numeric:Xp.body,om=(e,t)=>e.value?e.value(t):t[e.id],sm=(e,t)=>{let n=t.map(t=>qp(e,om(e,t)));if(e.kind===`status`)return Yp(n.map(e=>e??``));let r=e.kind===`user`||e.kind===`file`?Qp:0;return Math.max(0,...n.map(t=>t===void 0?$p:Math.ceil(t.length*am(e.kind))))+r+Zp},cm=(e,t,n)=>Math.min(n,Math.max(t,e)),lm=(e,t)=>{if(em.has(e.kind)&&!e.title)return{...e,fixed:!0,width:Math.max(e.minWidth??0,t)};let n={...e,fixed:!1,width:cm(t,nm,rm)};return e.kind===`id`?{...n,minWidth:Math.max(Jp(e.header,e.sortable??!1),Math.min(t,im))}:n},um=(e,t)=>{if(t.length===0)return e;let n=e.map(e=>e.render?e:lm(e,sm(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)},dm=e=>e.charAt(0).toUpperCase()+e.slice(1),fm=[[/^\s*(```|~~~).*$/,``],[/^\s*\[[^\]]+\]:\s+\S.*$/,``],[/^\s*([-*_]\s*){3,}$/,``],[/^\s*\|?(\s*:?-+:?\s*\|)+\s*:?-*:?\s*$/,``],[/^\s*#{1,6}\s+/,``],[/^\s*(>\s?)+/,``],[/^\s*([-*+]|\d+[.)])\s+(\[[ xX]\]\s+)?/,``]],pm=[[/!\[([^\]]*)\]\([^)]*\)/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`]],mm=200,hm=e=>{let t=e.split(/\r?\n/).map(e=>fm.reduce((e,[t,n])=>e.replace(t,n),e)),n=pm.reduce((e,[t,n])=>e.replace(t,n),t.join(`
|
|
3
|
-
`)).replace(/\s+/g,` `).trim();return n.length>mm?`${n.slice(0,199).trimEnd()}…`:n},gm=(e,t)=>e.type===`text`&&!!t?.markdown,_m=(e,t,n)=>{let r=t[n];return e.fields[n]?.type===`relation`&&typeof r==`object`&&r&&`id`in r?r.id:r},vm=(e,t)=>e.primaryKey.map(n=>String(_m(e,t,n))).join(`,`),ym=(e,t)=>{let n=e.primaryKey.map(n=>_m(e,t,n));return n.length===1?n[0]:n},bm=new Set([`email`,`phone`,`url`]),xm=e=>e?.format!==void 0&&bm.has(e.format)?e.format:void 0,Sm=(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},Cm=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`}:{},wm=(e,t)=>{let n=String(t);return e&&Object.hasOwn(e,n)?e[n]:void 0},Tm=(e,t)=>{let n=wm(e,t);return n===void 0||Mn(n)?void 0:n},Em=(e,t)=>{let n=wm(e,t);return n!==void 0&&Mn(n)?n:`neutral`},Dm={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},Om=new Set([`datetime`,`date`,`boolean`,`percent`]),km=(e,t,n)=>{switch(e.type){case`relation`:return`relation`;case`file`:return`file`;case`enum`:return`status`;case`boolean`:return`boolean`;case`timestamp`:return`datetime`;case`date`:return`date`;case`decimal`:return t?.format===`percent`?`percent`:t?.currency===void 0?`number`:`money`;case`integer`:case`bigint`:return t?.format===`signed`?`signed`:`number`;default:return t?.format===`code`||n===0&&e.name===`id`?`id`:`text`}},Am=e=>Math.round(Number.parseFloat(String(e))*100),jm=(e,t,n=[],r=Tr(e,t))=>{let i=cr(e,t);return r.flatMap((r,a)=>{let o=e.fields[r];if(!o)return[];let s=t?.fields[r],c=km(o,s,a),l=Object.fromEntries((o.enumValues??[]).map(e=>[e,ir(e,s?.valueLabels)])),u=(c===`number`||c===`signed`)&&s?.prefix?s.prefix:void 0,d=Math.ceil(((u?.length??0)+(s?.suffix?.length??0))*7.2);return[{id:r,header:s?.label??F(r),kind:c,width:(r===`name`?260:Dm[c])+d,sortable:o.sortable,minWidth:Math.max(c===`id`?150:0,Jp(s?.label??F(r),o.sortable),c===`status`?Yp(Object.values(l)):0,d>0?Dm[c]+d:0),...Om.has(c)&&{fixed:!0},...r===i&&{title:!0},...c===`text`&&r!==i&&xm(s)&&{link:xm(s)},...n.includes(r)&&{highlight:!0},...o.type===`enum`&&{tones:Object.fromEntries((o.enumValues??[]).map(e=>[e,Em(s?.valueColors,e)])),labels:l},...o.type===`enum`&&s?.valueColors&&{colors:s.valueColors},...o.type===`enum`&&s?.badgeShape&&{shape:s.badgeShape},...u!==void 0&&{prefix:u},...s?.suffix!==void 0&&{suffix:s.suffix},...c===`datetime`&&s?.format===`relative`&&{relative:!0},...c===`money`&&s?.decimals!==void 0&&{decimals:s.decimals},...c===`money`&&s?.currency!==void 0&&{currency:s.currency,value:e=>e[r]==null?null:Am(e[r])},...(c===`datetime`||c===`date`)&&{value:e=>e[r]==null?null:Date.parse(String(e[r]))},...gm(o,s)&&{value:e=>typeof e[r]==`string`?hm(e[r]):e[r]},...(c===`percent`||c===`number`&&o.type===`decimal`)&&{value:e=>e[r]==null?null:Number(e[r])}}]})},Mm=(e,t)=>`${t.prefix??``}${e}${t.suffix??``}`,Nm=(e,t,n={},r=Gf(),i=Date.now())=>{if(t==null||t===``)return`—`;switch(e.type){case`boolean`:return Ap(t?`yes`:`no`);case`file`:return Np(t)?.name??`—`;case`enum`:return ir(String(t),n.valueLabels);case`timestamp`:{let e=Date.parse(String(t));return n.format===`relative`?Sp(Math.round((i-e)/1e3)):dp(e,r)}case`date`:return cp(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)}%`:Mm(Number(e).toLocaleString(Le(),{minimumFractionDigits:n.decimals??0,maximumFractionDigits:n.decimals??20}),n)}case`integer`:case`bigint`:return Mm(String(t),n);default:return typeof t==`object`?JSON.stringify(t):String(t)}},Pm=(e,t,n=Gf(),r={})=>{if(e.type!==`timestamp`||typeof t!=`string`)return;let i=Date.parse(t);if(!Number.isNaN(i))return r.format===`relative`?dp(i,n):Ap(`shownIn`,{zone:ep(i,n)})},Fm=`$photos`,Im=e=>{for(let t of e?.list?.displays??[])if(t.kind===`cards`&&t.photos)return t.photos},Lm=(e,t,n)=>{if(n===void 0||e.primaryKey.length!==1)return t;let r=e.primaryKey[0];return t.map(e=>({...e,[Fm]:n[String(e[r])]??[]}))},Rm=(e,t)=>t.filter(t=>e[t]!==null&&e[t]!==void 0&&e[t]!==``),K=M(`app/displays`),zm=(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:ir(e,i?.valueLabels)}));return r.nullable?[...a,{value:null,label:K(`noValue`,{label:i?.label??F(n.by)})}]:a},Bm=e=>e.position&&e.position.within===void 0?e.position.field:void 0,Vm=(e,t,n)=>{let r=Yt(n===null?cn.isNull(t):cn.eq(t,n));return e===``?r:`(${e}) AND ${r}`},Hm=(e,t,n)=>({kind:`cards`,name:n.name,title:n.title??cr(e,t),...n.subtitle!==void 0&&{subtitle:n.subtitle},...n.badge!==void 0&&{badge:n.badge},...n.meta&&{meta:n.meta}}),Um=e=>{if(!pl(e))return e instanceof Error?e.message:K(`somethingWrong`);let t=e.errors.map(e=>e.message);return t.length>0?t.join(`; `):e.message},Wm=e=>e?.list?.displays??[],Gm=(e,t,n)=>{let r=n??e?.list?.default??`table`;if(!t)return r;let i=Wm(e).filter(e=>e.kind===`cards`);return i.find(e=>e.name===r)?.name??i[0]?.name??r},Km=`rows`,qm=(e,t)=>{if(Wm(t).some(e=>e.kind===`cards`||e.name===`rows`))return;let n=cr(e,t),r=Tr(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:Km,label:K(`list`),icon:`list`,title:n,...i!==void 0&&{badge:i},footer:a}},Jm=(e,t)=>t.name===`rows`&&!Wm(e).some(e=>e.name===`rows`),Ym=(e,t,n)=>{let r=Gm(t,n);return n&&r===`table`&&qm(e,t)?Km:r},Xm=(e,t,n)=>(n===`rows`?qm(e,t):void 0)??Zm(t,n),Zm=(e,t)=>{if(t===`table`)return;let n=t=>Wm(e).find(e=>e.name===t);return n(t)??n(e?.list?.default)},Qm={cards:`cards`,map:`map`,board:`kanban`,calendar:`calendar`,timeline:`timeline`},$m=e=>[{name:yn,label:K(`table`),icon:`table`},...Wm(e).map(e=>({name:e.name,label:e.label??F(e.name),icon:e.icon??Qm[e.kind]}))],eh=(e,t,n)=>{let r=$m(t);return n&&qm(e,t)?[...r,{name:Km,label:K(`list`),icon:`list`}]:r},th=(e,t,n)=>({image:n.image,title:n.title??cr(e,t),subtitle:n.subtitle,amount:n.amount??[],badge:n.badge,meta:n.meta??[],footer:n.footer??[],flags:n.flags??[]}),nh=(e,t)=>Rm(e.record,t),rh=(e,t)=>nh(e,t)[0],ih=(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:Nm(e,t,n)}:{amount:Nm(e,t,i),suffix:r}},ah=(e,t)=>{let n=Wm(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}},oh=(e,t,n)=>{if(n.kind===`custom`)return n.fields;if(n.kind===`map`)return[n.latitude,n.longitude,...oh(e,t,ah(t,n))];if(n.kind===`board`){let r=Hm(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??cr(e,t)].filter(e=>e!==void 0);if(n.kind===`timeline`)return[n.start,n.end,n.group,n.title??cr(e,t)].filter(e=>e!==void 0);let{image:r,title:i,subtitle:a,amount:o,badge:s,meta:c,footer:l,flags:u}=th(e,t,n);return[r,i,a,...o,s,...c,...l,...u].filter(e=>e!==void 0)},sh=(e,t,n)=>{let r=qm(e,t),i=r?[...Wm(t),r]:Wm(t);return[...new Set([...n,...i.flatMap(n=>oh(e,t,n))])]},ch=(e,t,n)=>{let r=Jm(t,n)?[cr(e,t),...Tr(e,t)]:oh(e,t,n);return[...new Set(r)].filter(t=>e.fields[t]?.sortable)},lh=e=>typeof e==`object`&&!!e&&`id`in e&&`name`in e,uh=(e,t)=>{let n={},r={},i=Array.isArray(t.$photos)?t[Fm]:void 0;for(let[i,a]of Object.entries(t))(i!==`id`&&i!==`$photos`||Object.hasOwn(e.fields,i))&&(e.fields[i]?.type===`relation`&&lh(a)?(n[i]=a.id,r[i]=a.name):n[i]=a);return{key:Nn(ym(e,n)),record:n,labels:r,...i&&{photos:i}}},dh=(e,t)=>{let n=t?.list?.sort?.[0];if(n)return`${n[0]} ${n[1]}`;let r=e.primaryKey[0];return e.fields[r]?.sortable?`${r} asc`:``},fh=e=>{let[t=``,n]=e.trim().split(/\s+/);return{columnId:t,direction:n===`desc`?`desc`:`asc`}},ph=e=>`${e.columnId} ${e.direction}`,mh=(e,t,n,r)=>{let i=e[n],a=Cn(t[n],r),o=a?.listOf,s=o===void 0?void 0:i?.fields[o]?.relation?.resource;return s!==void 0&&e[s]?{model:e[s],view:t[s],listOf:!0}:{model:i,view:a,listOf:!1}},hh=(e,t,n=!1)=>({display:e?Ym(e,t,n):Gm(t,n),orderBy:e?dh(e,t):``,filterLayout:`bar`,filter:t?.list?.filter??``}),gh=(e,t)=>e?.kind===`record`?{kind:`record`,resource:e.resource,key:Nn(e.key),...e.edit&&{edit:!0},...e.open&&{open:e.open},...e.tab&&{tab:e.tab},...e.standard&&{standard:!0},...e.call&&{call:e.call}}:e?.kind===`list`?{...t(e.resource,e.list),...e}:e,_h=(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}}},vh=({className:e})=>(0,B.jsx)(`span`,{className:P(`block h-3 rounded bg-muted [animation:pb-shimmer_1.4s_ease-in-out_infinite]`,e)}),yh=M(`app-shell`),bh=e=>e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey,xh=({parts:e,onNavigate:t})=>(0,B.jsx)(`nav`,{"aria-label":yh(`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)(vh,{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)(Oi,{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&&bh(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}`)})}),Sh=({to:e,onClick:t,...n})=>{let{href:r,onFollow:i,newTab:a}=e;return(0,B.jsx)(`a`,{href:r,...a&&{target:`_blank`,rel:`noreferrer`},onClick:e=>{t?.(e),i&&!e.defaultPrevented&&bh(e)&&(e.preventDefault(),i())},...n})},q=M(`app`),Ch=`protobase:page-places`,wh=50,Th=e=>Array.isArray(e)&&e.length===2&&typeof e[0]==`string`&&typeof e[1]==`number`&&Number.isFinite(e[1])&&e[1]>=0,Eh=e=>Ie(()=>{let t=e.getItem(Ch);if(t===null)return[];let n=JSON.parse(t);return Array.isArray(n)?n.filter(Th):[]},[]),Dh=e=>{let t=new Map(Eh(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-wh)))t.delete(e)},persist:()=>Ie(()=>e.setItem(Ch,JSON.stringify([...t])),void 0)}},Oh=3e3,kh=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,Oh);return r.observe(document.body),window.addEventListener(`scroll`,i,{passive:!0}),a},Ah=(0,I.createContext)(null),jh=()=>{let e=(0,I.useContext)(Ah);if(!e)throw Error(`useRouter must be used inside Router`);return e},Mh=()=>`${window.location.pathname}${window.location.search}`,Nh=e=>new URL(e,`http://local`).pathname,Ph=()=>window.history.state??{},Fh=()=>Ph().protobaseIndex??0,Ih=()=>Math.random().toString(36).slice(2),Lh=()=>{let e=Ph();if(e.protobaseEntry)return e.protobaseEntry;let t=Ih();return window.history.replaceState({...e,protobaseEntry:t},``),t},Rh={getItem:()=>null,setItem:()=>{}},zh=({basePath:e=``,initialUrl:t,children:n})=>{let r=t!==void 0,[i,a]=(0,I.useState)(()=>({url:t??Mh(),entry:r?Ih():Lh()})),[o]=(0,I.useState)(()=>Dh(r?Rh:Ie(()=>window.sessionStorage,void 0)??Rh)),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:Fh()),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)(()=>kh(o.placeOf(i.entry)),[o,i.entry]),(0,I.useEffect)(()=>{if(r)return;window.history.scrollRestoration=`manual`,window.history.replaceState({...Ph(),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=Fh();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=Nh(Mh())!==Nh(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:Mh(),entry:Lh()})};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:Ih();if(!r){u.current+=+!t;let r=t?Ph().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(Nh(r)!==Nh(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:Ph().protobasePrevious;if(n!==void 0&&Nh(n)===Nh(`${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)(Ah.Provider,{value:T,children:[n,h?.kind===`reload`&&(0,B.jsx)(Cf,{title:q(`reloadTitle`),description:q(h.inputLost?`reloadInputLost`:`reloadDraftKept`),onClose:()=>g(void 0),actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:()=>g(void 0),children:q(`keepEditing`)}),(0,B.jsx)(G,{variant:`primary`,onClick:w,children:q(`reload`)})]})}),h&&h.kind!==`reload`&&(0,B.jsx)(Cf,{title:q(`leaveTitle`),description:q(h.inputLost?`leaveInputLost`:`leaveDescription`),onClose:()=>g(void 0),actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:()=>g(void 0),children:q(`stay`)}),(0,B.jsx)(G,{variant:`primary`,onClick:w,children:q(`leave`)})]})})]})},Bh=({to:e,replace:t,...n})=>{let{navigate:r,basePath:i}=jh();return(0,B.jsx)(Sh,{to:{href:`${i}${e}`,onFollow:()=>r(e,{replace:t})},...n})},Vh=(e,t=`draft-kept`)=>{let{registerGuard:n,reloadConfirmed:r}=jh();(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])},Hh=()=>{let{path:e,params:t,basePath:n,navigate:r,back:i}=jh(),{pages:a,resources:o,views:s}=W(),c=_f(),l=(0,I.useMemo)(()=>new Set(Object.keys(a)),[a]),u=t.toString(),d=(0,I.useMemo)(()=>Wc(u?`${e}?${u}`:e,l),[e,u,l]),f=(0,I.useCallback)((e,t)=>{let n=mh(o,s,e,t);return hh(n.model,n.view,c)},[o,s,c]),p=(0,I.useMemo)(()=>gh(d,f),[d,f]),m=(0,I.useCallback)((e,t)=>r(Bc(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 _h(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=>Bc(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])}},Uh=({to:e,...t})=>(0,B.jsx)(Bh,{to:Bc(e),...t}),Wh=`text-[16px] font-semibold text-foreground`,Gh=({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)(Uh,{to:n,replace:!0,"aria-expanded":t,"aria-controls":i,className:P(`inline-flex items-center gap-1.5`,Wh),children:[(0,B.jsx)(Oi,{className:P(`size-4 transition-transform`,t&&`rotate-90`)}),e]}):(0,B.jsx)(`span`,{className:Wh,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":Rf(`tabs`),className:`overflow-x-auto py-6`,children:(0,B.jsx)(`span`,{className:ze.group(`md`),children:e.map(e=>(0,B.jsx)(Uh,{to:e.to,replace:!0,"aria-current":e.current?`page`:void 0,className:P(ze.option(e.current,`md`),`whitespace-nowrap`),children:e.title},e.title))})}),qh=(0,I.createContext)(void 0),Jh=()=>{let e=(0,I.useContext)(qh);return e?{id:e.id,name:e.name,"aria-describedby":e.describedBy,"aria-invalid":e.invalid||void 0,"aria-required":e.required||void 0}:{}},Yh=({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:Rf(`savedDifferent`,{name:o.user.name}),children:[(0,B.jsx)(Ys,{className:`size-3.5`}),(0,B.jsx)(If,{initials:o.user.initials,hue:o.user.hue,size:`xs`})]})]}),(0,B.jsx)(qh,{value:{id:l,name:e,describedBy:u,invalid:!!a,required:!!n},children:c}),r&&(0,B.jsx)(`p`,{id:`${l}-help`,className:`mt-1.5 text-xs text-muted-foreground`,children:r}),i&&(0,B.jsxs)(`p`,{id:`${l}-example`,className:`mt-0.5 text-xs text-faint-foreground`,children:[Rf(`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}),` `,Rf(`savedThis`,{ago:o.ago}),` `,(0,B.jsx)(`strong`,{children:o.theirValue})]}),(0,B.jsxs)(`span`,{className:`flex gap-1.5`,children:[(0,B.jsx)(G,{size:`sm`,onClick:o.onKeepMine,children:Rf(`keepMine`)}),(0,B.jsx)(G,{size:`sm`,onClick:o.onUseTheirs,children:Rf(`useTheirs`)})]})]})]})},Xh=({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))}),Zh=({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))}),Qh=`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`,$h=({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:Rf(`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:Qh,children:c}):(0,B.jsx)(`button`,{type:`button`,onClick:r,disabled:!!i||a,title:i,className:Qh,children:c})},e)})})]}),eg=`flex w-full items-center gap-2 px-3 py-2.5 text-left hover:bg-muted disabled:cursor-default disabled:opacity-60`,tg=4,ng=(e,t,n)=>{let r=e.bottom+tg;return{top:r+t.height>window.innerHeight-tg?Math.max(tg,e.top-tg-t.height):r,right:Math.max(tg,Math.min(n-e.right,n-tg-t.width))}},rg=()=>{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(ng(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}},ig=({actions:e,label:t=Rf(`actions`),className:n})=>{let{open:r,setOpen:i,place:a,button:o,menu:s}=rg();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)(oa,{className:`size-5`})}),r&&(0,Sc.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)]})},ag=({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))}),og=({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]}),sg=({title:e,rows:t})=>t.length===0?null:(0,B.jsx)(og,{title:e,children:(0,B.jsx)(ag,{rows:t})}),cg=(e=Le())=>new Intl.NumberFormat(e).formatToParts(1.5).find(e=>e.type===`decimal`)?.value===`,`?`,`:`.`,lg=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),ug=(e,t)=>{let n=`[${lg(t===`.`?`,`:`.`)}\\s\\u00a0\\u202f']`,r=RegExp(`^([-+]?)(\\d{1,3}(?:${n}\\d{3})+|\\d+)(?:${lg(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()))},dg=e=>e==null?``:typeof e==`object`?JSON.stringify(e):String(e),fg=new Set([`text`,`integer`,`bigint`,`decimal`,`date`,`currency`,`country`]),pg=new Set([`uuid`,`timestamp`,`relation`]),mg=(e,t)=>e.readOnly||pg.has(e.type)?!1:e.type!==`json`||t?.widget!==void 0,hg=e=>!e.readOnly&&!e.nullable&&e.type!==`boolean`,gg=new Set([`integer`,`bigint`,`decimal`]),_g=e=>{try{return JSON.parse(e)}catch(t){if(t instanceof SyntaxError)return e;throw t}},vg=(e,t)=>ug(e,t)??e,yg=(e,t,n=cg())=>{if(e.type===`boolean`)return!!t;if(e.type===`file`)return Up(t);let r=String(t).trim();if(r===``)return e.nullable?null:``;let i=gg.has(e.type)?vg(r,n):r;if(e.type===`integer`)return Number(i);if(e.type===`relation`)return typeof t==`number`?t:i;if(fg.has(e.type)||e.type===`enum`)return i;if(e.type===`json`)return _g(i);throw Error(`Not implemented: editing ${e.type} fields`)},bg=(e,t,n=cg())=>e.type===`boolean`?!!t:String(t??``).trim()===``?null:yg(e,t,n),xg=(e,t)=>e.type===`boolean`?!!t:dg(t),Sg=(e,t,n,r=cg())=>{if(e.type===`boolean`)return!!t!=!!n;if(e.type===`file`)return Wp(t,n);let i=String(t??``).trim(),a=dg(n);return e.type===`decimal`||e.type===`integer`?i===``||a===``?i!==a:Number(vg(i,r))!==Number(a):i!==a},Cg=(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},wg=(e,t,n)=>(e??t?.helpWhen??`always`)===`always`||n,Tg=(e,t,n)=>e?.help!==void 0&&wg(e.helpWhen,t,n)?e.help:void 0,Eg=(e,t)=>e===`editing`?t:e!==`reading`||!t,Dg=M(`app/create`),Og=e=>typeof e==`object`&&!!e&&`key`in e,kg=(e,t,n)=>t.name!==e.tenant&&!t.readOnly&&(t.type===`relation`||mg(t,n)),Ag=(e,t)=>{let n=Object.values(e.fields).filter(n=>kg(e,n,t?.fields[n.name])).map(e=>e.name),r=new Set,i=Sn(t?.layout??[]).flatMap(e=>{if(e.kind!==`section`||kc(e.when)||!Eg(e.when,!0))return[];let i=e.fields.filter(e=>n.includes(e)&&!r.has(e)&&Eg(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?Dg(`details`):Dg(`otherFields`),fields:a}]},jg=(e,t)=>(e?.primaryKey.length===1?e.fields[e.primaryKey[0]]?.type:void 0)===`integer`?Number(t):t,Mg=(e,t,n)=>Object.fromEntries(Object.entries(n).flatMap(([n,r])=>{let i=e.fields[n];return i?Og(r)?[[n,jg(t[i.relation?.resource??``],r.key)]]:i.type===`boolean`?[[n,!!r]]:i.type===`file`?r?[[n,yg(i,r)]]:[]:String(r).trim()===``?[]:[[n,yg(i,r)]]:[]})),Ng=e=>!e.nullable&&!e.default&&e.type!==`boolean`,Pg=(e,t)=>e.type===`relation`?{key:t,label:t}:e.type===`boolean`?t===`true`:t,Fg=new Set([`integer`,`bigint`,`decimal`]),Ig=e=>{if(!Fg.has(e.type)||!e.default||!(`value`in e.default))return;let t=e.default.value;return t==null?void 0:String(t)},Lg=(e,t,n={})=>Object.fromEntries(t.flatMap(t=>t.fields.flatMap(t=>{let r=e.fields[t];if(Object.hasOwn(n,t))return[[t,Pg(r,n[t])]];let i=r.default;return Ig(r)!==void 0||!i||!(`value`in i)||i.value===null||i.value===void 0?[]:[[t,typeof i.value==`boolean`?i.value:dg(i.value)]]}))),Rg=e=>!!(e.default&&`db`in e.default),zg=e=>{if(!pl(e))return[{message:e instanceof Error?e.message:q(`somethingWentWrong`)}];let t=e.errors.map(e=>({message:e.message,hint:e.hint}));return t.length>0?t:[{message:e.message}]},Bg=({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}),zg(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))]})]}),Vg=({checked:e,onChange:t,label:n})=>{let r=Jh();return(0,B.jsx)(`button`,{type:`button`,role:`switch`,id:r.id,"aria-describedby":r[`aria-describedby`],"aria-checked":e,"aria-label":n,onClick:()=>t?.(!e),className:P(`relative inline-flex h-5 w-9 shrink-0 items-center rounded-full transition-colors`,e?`bg-primary`:`bg-border-strong`),children:(0,B.jsx)(`span`,{className:P(`size-4 rounded-full bg-white shadow transition-transform`,e?`translate-x-[18px]`:`translate-x-0.5`)})})},J=({leading:e,trailing:t,invalid:n,className:r,wrapperClassName:i,...a})=>{let o=Jh();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]})},Hg=e=>{e.style.height=`auto`,e.style.height=`${e.scrollHeight+e.offsetHeight-e.clientHeight}px`},Ug=({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=Jh();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})},Wg=(e,{filter:t,orderBy:n,pageSize:r=50,fields:i,labels:a,startToken:o=``,enabled:s=!0,refetchInterval:c}={})=>{let l=U(),u=el(t)??``,d=Ne({queryKey:[...H.list(e,u,n??``,r,o),i?.join(`,`)??``,...a?[a]:[]],enabled:s,refetchInterval:c,initialPageParam:o,queryFn:({pageParam:t})=>l.list(e,{filter:u,orderBy:n,pageSize:r,fields:i,labels:a,pageToken:t}),getNextPageParam:e=>e.nextPageToken||void 0}),f=d.data?.pages??[];return{...d,items:f.flatMap(e=>e.items),totalEstimate:f[0]?.totalSizeEstimate,labels:Object.fromEntries(Object.keys(a??{}).map(e=>[e,Object.assign({},...f.map(t=>t.labels?.[e]??{}))]))}},Gg=()=>{let[e,t]=(0,I.useState)(``),[n,r]=(0,I.useState)(!1);return{text:e,setText:t,open:n,setOpen:r}},Kg=(e,t,n,r)=>{(0,I.useEffect)(()=>{if(!e||!t||!r)return;let n=new IntersectionObserver(e=>e.some(e=>e.isIntersecting)&&r(),{root:e});return n.observe(t),()=>n.disconnect()},[e,t,n,r])},qg=({search:e,options:t,chosen:n,several:r,closedText:i,placeholder:a,invalid:o,paging:s,loading:c,failed:l,onChoose:u})=>{let{text:d,setText:f,open:p,setOpen:m}=e,[h,g]=(0,I.useState)(-1),[_,v]=(0,I.useState)(null),[y,b]=(0,I.useState)(null),x=(0,I.useId)(),S=s?.more??!1;Kg(_,y,s?.loaded??0,s?.loadMore);let C=e=>`${x}-${e}`,w=(0,I.useRef)(null);(0,I.useEffect)(()=>{!p&&document.activeElement===w.current&&w.current?.select()},[p]),(0,I.useEffect)(()=>{p&&h>=0&&document.getElementById(C(h))?.scrollIntoView({block:`nearest`})});let T=()=>{f(``),g(-1),m(!1)},E=e=>{if(u(e),!r)return T();f(``),g(-1)};return(0,B.jsxs)(`div`,{className:`relative`,children:[(0,B.jsx)(J,{ref:w,role:`combobox`,"aria-autocomplete":`list`,"aria-expanded":p,"aria-controls":x,"aria-activedescendant":p&&t[h]?C(h):void 0,invalid:o,placeholder:a,value:p?d:i,onFocus:()=>m(!0),onBlur:T,onKeyDown:e=>{if(e.key===`ArrowDown`||e.key===`ArrowUp`){if(e.preventDefault(),!p)return m(!0);let n=e.key===`ArrowDown`?1:-1;g(e=>Math.min(Math.max(e+n,0),t.length-1));return}if(e.key===`Enter`&&p&&t[h]){e.preventDefault(),E(t[h]);return}e.key===`Escape`&&p&&(e.preventDefault(),e.stopPropagation(),T())},onChange:e=>{f(e.target.value),g(e.target.value.trim()?0:-1),m(!0)}}),p&&(0,B.jsxs)(`ul`,{ref:v,id:x,role:`listbox`,"aria-multiselectable":r||void 0,className:`absolute z-30 mt-1 max-h-60 w-full overflow-y-auto rounded-md border bg-background py-1 shadow-pop`,onMouseDown:e=>e.preventDefault(),children:[t.map((e,t)=>(0,B.jsx)(`li`,{id:C(t),role:`option`,"aria-selected":t===h,className:P(`cursor-pointer truncate px-3 py-1.5`,t===h&&`bg-muted`,n.includes(e.key)&&`font-medium`),onMouseMove:()=>t!==h&&g(t),onClick:()=>E(e),children:e.label},e.key)),S&&(0,B.jsx)(`li`,{ref:b,"aria-hidden":!0,className:`h-px`}),l&&(0,B.jsx)(`li`,{className:`px-3 py-1.5 text-muted-foreground`,children:q(`couldNotLoadOptions`)}),!S&&!c&&!l&&t.length===0&&(0,B.jsx)(`li`,{className:`px-3 py-1.5 text-muted-foreground`,children:q(`noMatches`)}),c&&(0,B.jsx)(`li`,{className:`px-3 py-1.5 text-muted-foreground`,children:q(`loading`)})]})]})},Jg=sn(),Yg=e=>e.split(/\s+/).filter(Boolean),Xg=(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:Yt(Jg.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=>Jg.eq(t,`*${e.replaceAll(`*`,``)}*`));return{filter:Yt(Jg.and(...o)),local:!1}},Zg=(e,t)=>{if(e==null)return!1;let n=String(e).toLowerCase();return Yg(t).every(e=>n.includes(e.toLowerCase()))},Qg=15e3,$g=()=>{let e=Od();return Gd().data?.status&&e?.state.kind===`signed-in`?String(e.state.user.id):void 0},e_=()=>{let e=U(),t=$g();return E({queryKey:H.statuses(t??``),enabled:t!==void 0,refetchInterval:Qg,queryFn:()=>e.status.people()})},t_=()=>{let e=U(),t=$g();return E({queryKey:H.ownStatus(t??``),enabled:t!==void 0,refetchInterval:Qg,queryFn:()=>e.status.own()})},n_=(e,t=Date.now())=>e.isSuccess&&!e.isFetching&&t-e.dataUpdatedAt>=1e4,r_=(e,t)=>{let n=new Map(t.map(e=>[e.userId,e]));return e.map(e=>{let t=n.get(e.id);return t?{...e,status:t}:e})},i_=()=>{let e=Od(),t=e?.state.kind===`signed-in`?e.state.user:void 0,n=E({queryKey:H.members(t?.id??``),enabled:t!==void 0,queryFn:()=>{if(!e?.organizations)throw Error(`useMembers() needs organizations: turn them on in the auth config.`);return e.session.organizations.people()}}),r=e_().data,i=(0,I.useMemo)(()=>n.data&&(r?r_(n.data,r):n.data),[n.data,r]),a=(0,I.useMemo)(()=>new Map((i??[]).map(e=>[e.id,e])),[i]),{refetch:o}=n,s=(0,I.useCallback)(e=>{let t=a.get(e);return!t&&n_(n)&&setTimeout(()=>void o(),0),t},[a,n,o]);return{...n,data:i,member:s}},a_=e=>e,o_=e=>e,s_=(0,I.createContext)({}),c_=()=>(0,I.useContext)(s_),l_=(e,t)=>t?.titleFrom?.fields??[],u_=(e,t)=>(n,r,i,a)=>{let o=r?.titleFrom;if(!o)return lr(n,r,i,a);let s=e[o.rule];return!s||o.unreadable||o.fields.some(e=>i[e]===void 0)?a:s(i,t)||a},d_=()=>void 0,f_=(0,I.createContext)(u_({},{user:void 0,member:d_})),p_=()=>(0,I.useContext)(f_),m_=({rules:e,user:t,children:n})=>{let r=(0,I.useMemo)(()=>u_(e,{user:t,member:d_}),[e,t]);return(0,B.jsx)(f_.Provider,{value:r,children:n})},h_=({rules:e,user:t,children:n})=>{let{member:r}=i_(),i=(0,I.useMemo)(()=>u_(e,{user:t,member:r}),[e,t,r]);return(0,B.jsx)(f_.Provider,{value:i,children:n})},g_=({children:e})=>{let{views:t}=W(),{titles:n}=c_(),r=Od(),i=r?.state.kind===`signed-in`?r.state.user:void 0,a=n??{};return Object.values(t).some(e=>e.titleFrom!==void 0)&&i&&r?.organizations?(0,B.jsx)(h_,{rules:a,user:i,children:e}):(0,B.jsx)(m_,{rules:a,user:i,children:e})},__=({target:e,view:t,value:n,label:r,chosen:i=[n],several:a=!1,invalid:o,onChange:s})=>{let c=Gg(),l=e.primaryKey[0],u=sr(e,t),[d,f]=(0,I.useState)(!1),p=p_(),m=Xg(e,u,c.text,d||t?.titleFrom!==void 0&&!e.search?.length),h=[...new Set([l,u,...t?.titleFrom?.fields??[]])],g=n=>t?.titleFrom?p(e,t,n,String(n[l])):String(n[u]),_=Wg(e.name,{filter:m.filter,fields:h,enabled:c.open}),v=m.filter!==void 0&&_.error instanceof dl&&_.error.slug===`expensive-query`;(0,I.useEffect)(()=>{v&&f(!0)},[v]);let y=m.local?_.items.filter(e=>Zg(g(e),c.text)):_.items,{fetchNextPage:b}=_,x=(0,I.useCallback)(()=>b({cancelRefetch:!1}),[b]);return(0,B.jsx)(qg,{search:c,options:y.map(e=>({key:String(e[l]),label:g(e)})),chosen:i,several:a,closedText:r??n,placeholder:q(`searchPlural`,{plural:(t?.names?.plural??F(e.name)).toLowerCase()}),invalid:o,paging:{more:!!_.hasNextPage,loaded:_.items.length,loadMore:x},loading:_.isPending||_.isFetchingNextPage,failed:!!_.error&&!v,onChoose:e=>s(e.key,e.label)})},v_=(e,t)=>e.replace(/\D/g,``).slice(0,t),y_=(e,t,n)=>{let r=v_(t??``,n);return r.length===n?r:v_(e,n)},b_=(e,t,n,r)=>{let i=t.replace(/\D/g,``);return i.length>=r?i.slice(0,r):v_(e.slice(0,n)+i+e.slice(n+i.length),r)},x_=({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(y_(e.target.value,t??n?.getData(`text/plain`),r))},onPaste:e=>{if(p?.(e),e.defaultPrevented)return;e.preventDefault();let t=e.currentTarget,n=b_(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)}})]})},S_=M(`app/confirm-sign-in`),C_=({minutes:e,onConfirmed:t})=>{let n=Od(),[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":S_(`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:S_(`confirmTitle`)}),(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:S_(`confirmWhy`,{minutes:e})}),l&&l.passkeys>0&&(0,B.jsx)(G,{variant:`primary`,size:`sm`,className:`self-start`,loading:s.isPending,onClick:()=>s.mutate(),children:S_(`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:[S_(`authenticatorCode`),(0,B.jsx)(x_,{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:S_(`confirm`)})]}),l&&l.passkeys===0&&!l.authenticatorApp&&(0,B.jsx)(`p`,{children:S_(`nothingToConfirmWith`)}),u&&(0,B.jsx)(`p`,{role:`alert`,className:`font-medium text-danger-text`,children:u.message})]})},w_=`••••••••••`,T_=e=>pl(e)&&e.slug===`strong-sign-in-required`?e.problem.minutes??15:void 0,E_=({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=dg(n)!==``,p=t?.label??F(e.name),m=(0,B.jsx)(G,{variant:`ghost`,size:`sm`,className:`-mr-1.5 px-1.5`,"aria-label":q(l?`hide`:`show`,{label:p}),"aria-pressed":l,loading:d.isPending,onClick:()=>{l||f||!r||d.isSuccess?u(!l):d.mutate()},children:!d.isPending&&(l?(0,B.jsx)(fa,{className:`size-3.5`}):(0,B.jsx)(ma,{className:`size-3.5`}))}),h=T_(d.error),g=h===void 0?d.error&&(0,B.jsx)(`div`,{className:`mt-2`,children:(0,B.jsx)(Bg,{title:q(`couldNotShow`,{label:p}),error:d.error})}):(0,B.jsx)(C_,{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?Nm(e,d.data,t):w_}),r&&m]}),g]});let _=f?dg(n):l&&d.isSuccess?dg(d.data):``;return(0,B.jsxs)(`div`,{children:[(0,B.jsx)(J,{type:l?`text`:`password`,autoComplete:`off`,invalid:a,"aria-label":p,className:P(t?.format===`code`&&`font-mono text-xs`),placeholder:f||!r?s??(e.writeOnly?q(`setNewValue`):void 0):w_,value:_,trailing:m,onChange:e=>c(e.target.value)}),g]})},D_=(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`},O_=e=>URL.canParse(e)?[new URL(e).hostname]:[],k_=()=>{let e=(0,I.useContext)(Hd);return(0,I.useMemo)(()=>[...e?.files?.trustedHosts??[],...(e?.sources??[]).flatMap(({source:e})=>O_(e.url))],[e?.files,e?.sources])},A_=e=>{let t;try{t=atob(e)}catch(e){if(e instanceof DOMException&&e.name===`InvalidCharacterError`)return;throw e}return S(Uint8Array.from(t,e=>e.charCodeAt(0)))},j_=({image:e,alt:t=``,className:n,loading:r})=>{let[i,a]=(0,I.useState)(),o=k_(),s=(0,I.useMemo)(()=>e.placeholder===void 0?void 0:A_(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:D_(e.url,window.location.href,o),onLoad:()=>a(e.url),className:n,style:c?{backgroundImage:`url("${s}")`,backgroundSize:`cover`,backgroundPosition:`center`}:void 0})},M_=({value:e})=>{let t=Vp(e,{width:40,height:40});return t?(0,B.jsx)(j_,{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)(Sa,{className:`size-4`})})},N_=({value:e})=>{let t=Np(e);if(!t)return(0,B.jsx)(`div`,{className:`py-1.5 text-muted-foreground`,children:`—`});if(`missing`in t)return(0,B.jsx)(`div`,{className:`py-1.5 text-danger-text`,children:q(`fileMissing`)});let n=`url`in t?t.url:void 0,r=`corrected`in t?t.corrected:void 0;return(0,B.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3 py-1`,children:[(0,B.jsx)(M_,{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&&` · ${Fp(t.size)}`,r&&` · sent as ${r.from}`]})]})]})},P_=({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,...Ip(r.file.type)&&{preview:URL.createObjectURL(t)}}},onSuccess:e=>s(e),onSettled:()=>d(void 0)});if(i||e.readOnly)return(0,B.jsx)(N_,{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:Hp(e),"aria-label":q(`chooseFileFor`,{label:m}),onChange:e=>g(e.target.files)}),y=h.error&&(0,B.jsx)(`div`,{className:`mt-2`,children:(0,B.jsx)(Bg,{title:q(`notUploaded`),error:h.error})});return h.isPending?(0,B.jsxs)(`div`,{className:`py-1.5`,role:`status`,"aria-label":q(`uploadingLabel`,{label:m}),children:[(0,B.jsx)(`div`,{className:`h-1.5 overflow-hidden rounded-full bg-muted`,children:(0,B.jsx)(`div`,{className:`h-full rounded-full bg-primary transition-[width]`,style:{width:`${Math.round((u??0)*100)}%`}})}),(0,B.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:q(`uploading`,{percent:Math.round((u??0)*100)})})]}):Np(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)(N_,{value:r})}),(0,B.jsx)(G,{size:`sm`,onClick:()=>l.current?.click(),children:q(`replace`)}),e.nullable&&(0,B.jsx)(G,{size:`sm`,variant:`ghost`,onClick:()=>s(null),children:q(`remove`)})]}),v,y]}):(0,B.jsxs)(`div`,{children:[(0,B.jsxs)(`div`,{onDragOver:e=>{e.preventDefault(),p(!0)},onDragLeave:()=>p(!1),onDrop:_,className:P(`flex items-center gap-3 rounded-md border border-dashed px-3 py-2.5 text-muted-foreground`,f?`border-primary bg-primary/5`:a?`border-danger`:`border-border-strong`),children:[(0,B.jsx)(Zs,{className:`size-4 shrink-0`}),(0,B.jsx)(`span`,{className:`flex-1`,children:q(`dropFile`)}),(0,B.jsxs)(G,{size:`sm`,onClick:()=>l.current?.click(),children:[(0,B.jsx)(Fo,{className:`size-3.5`}),q(`chooseFile`)]})]}),v,y]})},F_=e=>[...e].reduce((e,t)=>(e*31+t.charCodeAt(0))%360,7),I_=e=>e.split(/[\s@.]+/).filter(Boolean).slice(0,2).map(e=>e[0].toUpperCase()).join(``),L_=e=>(e.role??`user`).split(`,`).map(e=>e.trim()),R_=e=>L_(e).includes(`admin`),z_=e=>dm(e.replace(/[_-]+/g,` `).trim()),B_=e=>{let t=L_(e),n=t.includes(`admin`);return{name:e.name||e.email,email:e.email,initials:I_(e.name||e.email)||`?`,hue:F_(e.id||e.email),role:n?z(`admin`):z_(t[0]??`user`),roleTone:n?`violet`:`blue`}},V_=M(`app/field-types/members`),H_=({id:e,name:t})=>(0,B.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-1.5`,children:[(0,B.jsx)(If,{initials:t&&I_(t)||`?`,hue:F_(e),size:`xs`,className:`ring-0`}),(0,B.jsx)(`span`,{className:t===void 0?`truncate text-muted-foreground`:`truncate`,children:t??V_(`unknownMember`)})]}),U_=e=>Array.isArray(e)?e.filter(e=>typeof e==`string`):[],W_=(e,t)=>e.includes(t)?e.filter(e=>e!==t):[...e,t],G_=(e,t)=>e.filter(e=>Zg(e.name,t)).map(e=>({key:e.id,label:e.name})),K_=()=>{let e=Od(),t=i_();return{...t,needsOrganizations:!e?.organizations,failed:t.isError}},q_=({value:e,line:t})=>{let n=K_(),r=U_(e);return r.length===0?(0,B.jsx)(`span`,{className:`text-muted-foreground`,children:`—`}):n.needsOrganizations?(0,B.jsx)(`span`,{className:`text-muted-foreground`,children:V_(`needsOrganizations`)}):n.failed?(0,B.jsx)(`span`,{className:`text-muted-foreground`,children:V_(`couldNotLoadMembers`)}):n.isLoading?(0,B.jsx)(vh,{className:`h-4 w-24`}):(0,B.jsx)(`span`,{className:P(`flex min-w-0 items-center gap-x-3 gap-y-1`,t?`overflow-hidden`:`flex-wrap`),children:r.map(e=>(0,B.jsx)(H_,{id:e,name:n.member(e)?.name},e))})},J_=e=>(0,B.jsx)(q_,{...e,line:!1}),Y_=e=>(0,B.jsx)(q_,{...e,line:!0}),X_=({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":Qd(`remove`,{label:e}),className:`rounded p-0.5 hover:bg-primary-border/60`,onMouseDown:e=>e.preventDefault(),onClick:t,children:(0,B.jsx)(yc,{className:`size-3`})})]}),Z_=({value:e,invalid:t,onChange:n})=>{let r=Gg(),i=K_(),a=U_(e);if(i.needsOrganizations)return(0,B.jsx)(`p`,{className:`py-1.5 text-muted-foreground`,children:V_(`needsOrganizations`)});let o=e=>i.member(e)?.name??V_(`unknownMember`);return(0,B.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,B.jsx)(qg,{search:r,options:G_(i.data??[],r.text),chosen:a,several:!0,closedText:``,placeholder:V_(`searchMembers`),invalid:t,loading:i.isLoading,failed:i.failed,onChoose:e=>n(W_(a,e.key))}),a.length>0&&(0,B.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:a.map(e=>(0,B.jsx)(X_,{label:o(e),onRemove:()=>n(a.filter(t=>t!==e))},e))})]})},Q_={members:{of:[...Er.members],display:J_,editor:Z_,cell:Y_}},$_=(e,t)=>{if(e&&Object.hasOwn(e,t))return e[t];if(Object.hasOwn(Q_,t))return Q_[t]},ev=(e,t,n)=>{let r=n?.widget;if(!r||t.sensitive)return;let i=$_(e,r.name);return i?.of.includes(t.type)?{name:r.name,widget:i,props:r.props??{}}:void 0},tv=(e,t)=>ev(c_().fields,e,t),nv,rv,iv=({dsn:e,environment:t})=>(nv??=Ve(()=>import(`./prod-YZ9ZMG1O.js`).then(n=>{n.init({dsn:e,...t&&{environment:t},integrations:e=>e.filter(e=>e.name!==`BrowserSession`),beforeSend:e=>Kn(e)}),rv=(e,t)=>n.captureException(e,t?{contexts:{react:{componentStack:t}}}:void 0)}),[]),nv),av=(e,t)=>rv?.(e,t??void 0),ov=({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}),sv=M(`app/pages`),cv=class extends I.Component{state={failed:!1};static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(e,t){av(e,t.componentStack)}render(){return this.state.failed?this.props.fallback===void 0?(0,B.jsx)(ov,{children:sv.rich(`couldNotDraw`,{name:this.props.name})}):this.props.fallback:this.props.children}},lv=M(`app/field-types`),uv=({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},dv=({fallback:e,...t})=>{let n=uv(t);return n?(0,B.jsx)(cv,{name:lv(`fieldType`,{name:t.shown.name}),fallback:e,children:n}):e},fv=(0,I.lazy)(()=>Ve(()=>import(`./markdown-content-DOuciTNH.js`).then(e=>({default:e.MarkdownContent})),__vite__mapDeps([0,1,2,3]))),pv=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)(fv,{...e})}),mv=M(`markdown`),hv=()=>[{value:`write`,label:mv(`write`)},{value:`preview`,label:mv(`preview`)}],gv=({value:e,onChange:t,label:n,invalid:r,placeholder:i})=>{let[a,o]=(0,I.useState)(`write`);return(0,B.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,B.jsx)(`span`,{className:`self-start`,children:(0,B.jsx)(Re,{value:a,options:hv(),onChange:o,label:n})}),a===`write`?(0,B.jsx)(Ug,{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:mv(`nothingToPreview`)}):(0,B.jsx)(pv,{source:e})})]})},_v=new Set([`integer`,`bigint`,`decimal`]),vv=e=>e===`integer`||e===`bigint`?{inputMode:`numeric`,enterKeyHint:`done`}:e===`decimal`?{inputMode:`decimal`,enterKeyHint:`done`}:{},yv=e=>e.stopPropagation(),bv=({format:e,value:t,className:n})=>{let r=Sm(e,t);return r?(0,B.jsx)(`a`,{href:r,...e===`url`?{target:`_blank`,rel:`noreferrer`}:{},onClick:yv,className:P(`font-medium text-primary-text hover:underline`,n),children:t}):(0,B.jsx)(`span`,{className:n,children:t})},xv=e=>typeof e==`object`&&e&&`key`in e?e.key:e,Sv=(e,t,n,r,i)=>t?.confirm!==void 0&&!Sg(e,n,r)&&Sg(e,xv(i),r),Cv=M(`app/change-confirm`),wv=e=>e instanceof Element&&e.closest(`[data-dialog="change-confirm"]`)!==null,Tv=({field:e,hints:t,value:n,stored:r,onChange:i})=>{let[a,o]=(0,I.useState)(),s=a=>{Sv(e,t,n,r,a)?o({next:a}):i(a)},c=()=>o(void 0);return{onChange:s,dialog:a&&(0,B.jsx)(Cf,{name:`change-confirm`,title:Cv(`title`,{label:t?.label??F(e.name)}),description:t?.confirm,onClose:c,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:c,children:Cv(`cancel`)}),(0,B.jsx)(G,{variant:`primary`,onClick:()=>{o(void 0),i(a.next)},children:Cv(`change`)})]})})}},Ev=({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=Jh();if(e.type===`file`)return(0,B.jsx)(P_,{field:e,hints:t,resource:d??``,value:n,locked:c||!d,invalid:s,onChange:f});if(e.sensitive)return(0,B.jsx)(E_,{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)(__,{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)(Uh,{to:a,"aria-label":q(`openLabel`,{label:i??String(n)}),title:q(`open`),className:P(mf({variant:`ghost`}),`w-8 px-0`),children:(0,B.jsx)(Hr,{className:`size-4`})})]}):e}if(e.type===`boolean`&&c)return(0,B.jsx)(`div`,{className:`py-1.5 text-muted-foreground`,children:Nm(e,r,t)});if(e.type===`boolean`)return(0,B.jsx)(Vg,{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)(Uh,{to:a,className:`font-medium text-primary-text hover:underline`,children:e}):e})}let m=!!t?.multiline&&e.type===`text`,h=gm(e,t);if((!mg(e)||c)&&h&&typeof r==`string`&&r!==``)return(0,B.jsx)(pv,{source:r,className:`py-1.5`});let g=e.type===`text`?xm(t):void 0;return(!mg(e)||c)&&g&&typeof r==`string`&&r!==``?(0,B.jsx)(`div`,{className:`min-w-0 break-words py-1.5`,children:(0,B.jsx)(bv,{format:g,value:r})}):!mg(e)||c?(0,B.jsx)(`div`,{title:Pm(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:Nm(e,r,t)}):e.type===`enum`?(0,B.jsxs)(`select`,{...p,...s&&{"aria-invalid":!0},value:String(n),onChange:e=>f(e.target.value),className:`h-8 w-full rounded-md border border-border-strong bg-background px-2 shadow-sm focus:border-primary focus:outline-none focus:ring-2 focus:ring-primary/20`,children:[n===``&&(0,B.jsx)(`option`,{value:``,children:q(`choose`)}),(e.enumValues??[]).map(e=>(0,B.jsx)(`option`,{value:e,children:ir(e,t?.valueLabels)},e))]}):h?(0,B.jsx)(gv,{label:t?.label??F(e.name),invalid:s,placeholder:l,value:String(n),onChange:f}):m?(0,B.jsx)(Ug,{invalid:s,placeholder:l,value:String(n),onChange:e=>f(e.target.value)}):(0,B.jsx)(J,{invalid:s,leading:t?.prefix?(0,B.jsx)(`span`,{children:t.prefix}):void 0,trailing:t?.suffix?(0,B.jsx)(`span`,{children:t.suffix.trim()}):void 0,placeholder:l,className:P(_v.has(e.type)&&`text-right tabular-nums`),...vv(e.type),...Cm(g),value:String(n),onChange:e=>f(e.target.value)})},Dv=e=>{let{field:t,hints:n,value:r,stored:i,invalid:a,locked:o,onChange:s}=e,c=tv(t,n),l=(0,B.jsx)(Ev,{...e});return c?o||!mg(t,n)?(0,B.jsx)(dv,{shown:c,part:`display`,field:t,value:i,fallback:l}):t.type===`file`||t.type===`relation`?l:(0,B.jsx)(dv,{shown:c,part:`editor`,field:t,value:bg(t,r),invalid:!!a,onChange:e=>s(xg(t,e)),fallback:l}):l},Ov=e=>{let t=Tv(e);return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(Dv,{...e,onChange:t.onChange}),t.dialog]})},kv={text:`text`,integer:`integer`,decimal:`decimal`,boolean:`boolean`,date:`date`},Av=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:kv[e.kind]}},jv=e=>({label:e.label,...e.multiline&&{multiline:!0},...e.options&&{valueLabels:Object.fromEntries(e.options.map(e=>[e.value,e.label]))}}),Mv=e=>Object.fromEntries(e.map(e=>e.kind===`custom`?[e.name,e.default??null]:e.kind===`boolean`?[e.name,!!e.default]:[e.name,dg(e.default)])),Nv=(e,t)=>e.kind===`custom`?t??null:Og(t)?t.key:e.resource===void 0?yg(Av(e),t):String(t??``)===``?null:String(t),Pv=(e,t)=>{let n=Object.fromEntries(e.map(e=>[e.name,Nv(e,t[e.name])])),r=On(e,n);return{shown:r,values:Object.fromEntries(Object.entries(n).filter(([e])=>r.has(e)))}},Fv=/^-?\d+(\.\d+)?$/,Iv=/^\d{4}-\d{2}-\d{2}$/,Lv=(e,t)=>{if(t===null||t===``)return e.required?sv(`required`):void 0;if(e.kind===`integer`&&!Number.isInteger(t))return sv(`wholeNumber`);if(e.kind===`decimal`&&!Fv.test(String(t)))return sv(`number`);if(e.kind===`date`&&!Iv.test(String(t)))return sv(`dateFormat`);if(e.max!==void 0&&String(t).length>e.max)return sv(`atMost`,{max:e.max})},Rv=(e,t)=>Object.fromEntries(e.flatMap(e=>{if(!Object.hasOwn(t,e.name))return[];let n=Lv(e,t[e.name]);return n?[[e.name,n]]:[]})),zv=class extends Error{errors;constructor(e){super(Object.values(e).join(`; `)),this.errors=e,this.name=`ActionInputError`}},Bv=(e,t)=>{let n=new Set(t.map(e=>e.name)),r=e instanceof zv?Object.entries(e.errors):pl(e)?e.errors.flatMap(e=>e.field?[[e.field,e.message]]:[]):[];return Object.fromEntries(r.filter(([e])=>n.has(e)))},Vv=({input:e,held:t,invalid:n,onChange:r})=>{let{resources:i,views:a}=W(),{components:o}=c_();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)(Ov,{field:Av(e),hints:jv(e),value:Og(t)?t.key:t,stored:void 0,relationLabel:Og(t)?t.label:void 0,relationPicker:s?{target:s,view:a[s.name]}:void 0,invalid:n,onChange:r})},Hv=({action:e,label:t,danger:n,onCancel:r,onSubmit:i})=>{let[a,o]=(0,I.useState)(()=>Mv(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}=Pv(e.inputs,a),g=async()=>{let t=Rv(e.inputs,h);c(t),u(void 0),!(Object.keys(t).length>0)&&(f(!0),await i(h).catch(t=>{c(Bv(t,e.inputs)),u(t)}),f(!1))},_=(e,t)=>{c(({[e]:t,...n})=>n),o(n=>({...n,[e]:t}))};return(0,B.jsx)(Ef,{title:t,description:e.confirm,open:!0,onClose:r,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:r,children:sv(`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)(Bg,{title:sv(`failed`,{label:t}),error:l}),e.inputs.filter(e=>m.has(e.name)).map(e=>(0,B.jsx)(Yh,{label:e.label,required:e.required,help:e.help,error:s[e.name],children:(0,B.jsx)(Vv,{input:e,held:a[e.name],invalid:!!s[e.name],onChange:t=>_(e.name,t)})},e.name))]})})},Uv=({action:e,label:t,danger:n,onCancel:r,onConfirm:i})=>(0,B.jsx)(Cf,{title:`${t}?`,description:e.confirm,onClose:r,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:r,children:sv(`cancel`)}),(0,B.jsx)(G,{variant:n?`danger`:`primary`,onClick:i,children:t})]})}),Wv=e=>e.variant===`danger`||e.run?.kind===`delete`,Gv=e=>!!(e.confirm||e.inputs?.length),Kv=({action:e,label:t,danger:n,onCancel:r,onConfirm:i,onSubmit:a})=>{let{inputs:o}=e;return o?.length?(0,B.jsx)(Hv,{action:{...e,inputs:o},label:t,danger:n,onCancel:r,onSubmit:a}):(0,B.jsx)(Uv,{action:e,label:t,danger:n,onCancel:r,onConfirm:i})},qv=(0,I.createContext)(void 0),Jv=({value:e,children:t})=>(0,B.jsx)(qv.Provider,{value:e,children:t}),Yv=()=>(0,I.useContext)(qv),Xv=M(`toasts`),Zv=`-my-0.5 rounded px-1.5 py-0.5 font-medium text-primary-text hover:bg-primary-soft`,Qv=({action:e})=>{if(`onClick`in e)return(0,B.jsx)(`button`,{type:`button`,onClick:e.onClick,className:Zv,children:e.label});let{href:t,onNavigate:n}=e;return(0,B.jsx)(`a`,{href:t,onClick:e=>{n&&bh(e)&&(e.preventDefault(),n(t))},className:Zv,children:e.label})},$v={loading:(0,B.jsx)($d,{className:`text-primary`}),success:(0,B.jsx)(Pi,{className:`size-4 text-success`}),warning:(0,B.jsx)(Ys,{className:`size-4 text-warning`}),error:(0,B.jsx)(Bi,{className:`size-4 text-danger`}),info:(0,B.jsx)(rs,{className:`size-4 text-primary`}),call:(0,B.jsx)(zo,{className:`size-4 animate-pulse text-success`})},ey=({state:e,title:t,description:n,action:r,actions:i=[],onDismiss:a})=>(0,B.jsxs)(`div`,{role:e===`error`||e===`call`?`alert`:`status`,className:P(`flex w-full max-w-80 items-start gap-3 rounded-lg border bg-background p-3 shadow-pop [animation:pb-slide-in_160ms_ease-out]`,e===`warning`&&`border-warning/40`,e===`error`&&`border-danger/40`),children:[(0,B.jsx)(`span`,{className:`mt-0.5`,children:$v[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)(Qv,{action:r}),i.map(e=>(0,B.jsx)(Qv,{action:e},e.label)),a&&(0,B.jsx)(`button`,{type:`button`,"aria-label":Xv(`dismiss`),onClick:a,className:`inline-flex items-center justify-center rounded p-0.5 text-faint-foreground hover:bg-muted hover:text-foreground pointer-coarse:size-9`,children:(0,B.jsx)(yc,{className:`size-3.5`})})]}),ty={loading:1/0,success:3500,warning:8e3,error:8e3,info:8e3,call:1/0},ny=8e3,ry=(0,I.createContext)(null),iy=()=>{let e=(0,I.useContext)(ry);if(!e)throw Error(`useToast must be used inside ToastProvider`);return e},ay=({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?ny:ty[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)(ry.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)(ey,{state:e.state,title:e.title,description:e.description,action:e.action,...e.actions&&{actions:e.actions},onDismiss:()=>c(e)})},e.id))})]})},oy=(e,t)=>e[t]||e.conditional.includes(t),sy=(e,t)=>e.permissions?.[t]??!0,cy=(e,t)=>e?.fields?e.fields[t]??`hidden`:`edit`,ly=(e,t)=>{if(e.when===void 0)return!0;if(!t)return!1;let n=mu(e.when);return n.ok&&hu(n,t)},uy=(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]))),dy=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},fy=(e,t={})=>{let n=hn(e);return n===void 0?uy(e,t):dy(t[n])},py=e=>{e!==void 0&&(/^https?:/i.test(e)?window.open(e,`_blank`,`noopener,noreferrer`):window.location.assign(e))},my=e=>URL.canParse(e)?new URL(e).hostname.replace(/^www\./,``):``,hy=(e,t)=>Object.entries(t).every(([t,n])=>Object.is(e[t],n)),gy=(e,t)=>{if(!ly(e,t))return e.otherwise===`disable`?e:void 0;let n=e.run;if(n?.kind===`update`)return t&&!e.inputs?.length&&hy(t,n.values)?void 0:e;if(n?.kind!==`link`||!(`href`in n))return e;let r=fy(n.href,t);if(r!==void 0)return e.label.includes(`{host}`)?{...e,label:e.label.replaceAll(`{host}`,my(r))}:e},_y=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},vy=(e,t)=>({model:e,record:t,key:Nn(ym(e,t)),etag:typeof t.etag==`string`?t.etag:void 0,permissions:t.permissions}),yy=(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}}),by=(e,t=``)=>E(yy(U(),e,t)),xy=(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{...vy(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]?vy(e,a.items[0]):null}})},Sy=(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})})},Cy=()=>{let e=Se();return(0,I.useCallback)(t=>e.invalidateQueries({predicate:e=>e.queryKey[1]===t}),[e])},wy=e=>e instanceof Error?e.message:sv(`somethingWrong`),Ty=(e,t,n)=>{let{views:r}=W(),{actions:i,components:a}=c_(),o=af(e),s=U(),c=Ld(e),l=iy(),u=Cy(),{go:d}=Hh(),[f,p]=(0,I.useState)(),m=(r[e]?.actions??[]).flatMap(e=>gy(e,t?.record)??[]),h=(e,t)=>{let n=e.run?.kind;if((n===`update`||n===`delete`||n===`ai`)&&!t)return sv(`needsRecord`);if(!ly(e,t?.record))return e.reason??sv(`doesNotApply`);if((n===`update`||n===`ai`)&&(!oy(o,`update`)||t?.permissions?.update===!1)||e.run?.kind===`ai`&&t?.permissions?.fields?.[e.run.writes]===`read`)return sv(`cannotChange`);if(n===`delete`&&(!oy(o,`delete`)||t?.permissions?.delete===!1))return sv(`cannotDelete`);if(!e.run&&!i?.[e.name])return sv(`noHandler`,{name:e.name});let r=e.inputs?.find(e=>e.kind===`custom`&&!a?.[e.component??``]);if(r)return sv(`noInputComponent`,{component:String(r.component),input:r.name})},g=e=>h(e,t),_=async(t,n,r)=>{let{run:a}=t;if(a?.kind===`link`){`to`in a?d(mn(a.to,n?.record)):py(fy(a.href,n?.record));return}a?.kind===`update`?await s.update(e,n.key,kn(a.values,r??{}),n.etag??`*`):a?.kind===`delete`?await s.remove(e,n.key,{etag:n.etag}):a?.kind===`ai`?await s.generate(e,n.key,t.name):await i[t.name]({resource:e,record:n?.record,recordKey:n?.key,etag:n?.etag,client:c,navigate:d,...r&&{values:r}})},v=async(t,r,i)=>{await _(t,r,i),t.run?.kind!==`link`&&(await u(e),l.show({state:`success`,title:sv(`done`,{label:t.label})}),n?.(t))},y=async(e,n=t)=>{h(e,n)||(p(e.name),await v(e,n).catch(t=>l.show({state:`error`,title:sv(`failed`,{label:e.label}),description:wy(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)=>gy(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 _y(r,e=>x(t,e),e=>_(t,e));p(void 0),await u(e);let o=sv(`doneOn`,{label:t.label,done:a.done,skipped:a.skipped+i,failed:a.failed});l.show(a.failed>0?{state:`error`,title:o,description:wy(a.error)}:{state:`success`,title:o}),a.done>0&&n?.(t)}}},Ey=(e,t,n)=>{let r=Ty(e,n),i=r.actions.find(e=>e.name===t);return{action:i,blocked:i?r.blocked(i):sv(`noAction`,{name:t}),running:r.running===t,run:()=>i?r.run(i):Promise.resolve(),submit:e=>i?r.submit(i,e):Promise.resolve()}},Dy=e=>e.props,Oy=({name:e,resource:t,label:n,variant:r})=>{let i=Yv(),a=Ey(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:()=>Gv(a.action)?s(!0):void a.run(),children:c}),o&&(0,B.jsx)(Kv,{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)}})]})},ky=({node:e})=>(0,B.jsx)(Oy,{...Dy(e)}),Ay=({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})]}),jy=({children:e})=>(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:e}),My=({node:e,children:t,slots:n})=>{let{title:r,description:i}=Dy(e);return(0,B.jsx)(Ay,{title:r,description:i,actions:n.actions,className:`h-full`,children:(0,B.jsx)(`div`,{className:`flex flex-col gap-3`,children:t})})},Ny=({model:e,filter:t,sort:n,limit:r=12,title:i,description:a,empty:o,actions:s,children:c})=>{let l=Sy(e,{filter:t,sort:n,pageSize:r}),u=l.data?.items??[];return(0,B.jsx)(Ay,{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)(vh,{className:`h-24 w-56`},t))}):l.error?(0,B.jsx)(Bg,{title:sv(`couldNotLoad`),error:l.error}):u.length===0?(0,B.jsx)(jy,{children:o??sv(`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=vy(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)(Jv,{value:n,children:c})},n.key)})})})},Py=({node:e,children:t,slots:n})=>{let{resource:r,...i}=Dy(e),a=W().resources[r];return a?(0,B.jsx)(Ny,{...i,model:a,actions:n.actions,children:t}):null},Fy=(e,t,n,r=!0)=>{let i=U(),a=el(n)??``;return E({queryKey:H.facets(e,t,a),enabled:r,queryFn:()=>i.facets(e,t,{filter:a,limit:50})})},Iy=(e,t,n=!0)=>{let r=U(),i=el(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})})},Ly=(e,t,n,r=20,i=!0)=>{let a=U(),o=el(n)??``;return E({queryKey:H.histogram(e,t,r,o),enabled:i,queryFn:()=>a.histogram(e,t,{filter:o,buckets:r})})},Ry=(e,t,n=!0)=>{let r=U(),i={...t,filter:el(t.filter)??``};return E({queryKey:H.aggregate(e,JSON.stringify(i)),enabled:n,queryFn:()=>r.aggregate(e,i)})},zy=(e,t,n=!0)=>{let r=U();return f({queries:t.map(t=>{let i={...t,filter:el(t.filter)??``};return{queryKey:H.aggregate(e,JSON.stringify(i)),enabled:n,queryFn:()=>r.aggregate(e,i)}})})},By=M(`app/charts`),Vy=sn(),Hy=e=>e>=0&&e<8?`var(--chart-${e+1})`:`var(--faint-foreground)`,Uy=(e,t,n,r)=>{let i=String(n);if(n===null)return`var(--faint-foreground)`;let a=Tm(t?.valueColors,n);return a===void 0?e.type===`enum`?Hy(e.enumValues?.indexOf(i)??-1):e.type===`boolean`?Hy(+!n):Hy(r):a},Wy=(e,t,n)=>n.value===null?By(`notSet`):e.type===`enum`?ir(String(n.value),t?.valueLabels):e.type===`boolean`?n.value?By(`yes`):By(`no`):n.label??String(n.value),Gy=(e,t,n=``)=>{let r=Yt(t===null?Vy.isNull(e.name):Vy.eq(e.name,t));return n.trim()?`(${n}) AND ${r}`:r},Ky=(e,t)=>t.kind===`count`?e.count:e[t.kind]??null,qy=(e,t,n,r,i=``)=>e.map((e,a)=>({key:String(e.value),label:Wy(t,n,e),value:Ky(e,r),count:e.count,color:Uy(t,n,e.value,a),filter:Gy(t,e.value,i)})),Jy=(e,t)=>e.map(e=>({at:Date.parse(`${String(e.value)}Z`),value:Ky(e,t),count:e.count})),Yy=(e,t)=>{if(e===null)return`—`;if(t.kind===`count`)return e.toLocaleString(Le());let n=t.hints?.decimals??(Number.isInteger(e)?0:2),r=e.toLocaleString(Le(),{minimumFractionDigits:n,maximumFractionDigits:n});return`${t.hints?.prefix??``}${r}${t.hints?.suffix??``}`},Xy=(e,t,n)=>n?{kind:`list`,resource:t,filter:n}:e?.list?.filter?{kind:`list`,resource:t,filter:``}:{kind:`list`,resource:t},Zy=({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)(Uh,{to:Xy(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:By(`records`,{count:Yy(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:Yy(n.value,r)})]})},n.key)})})},Qy=`flex items-center gap-2 rounded-md px-1 py-0.5`,$y=({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:Qy,children:o}):(0,B.jsx)(Uh,{to:Xy(t,e,n),className:`group ${Qy} hover:bg-muted`,children:o})})},eb=(e,t)=>t>0?`${Math.round(e/t*100)}%`:``,tb=({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:Yy(r.value,n)})]})},nb=({resource:e,view:t,slices:n,measure:r})=>{let i=n.filter(e=>e.value!==null&&e.value>0),a=i.reduce((e,t)=>e+t.value,0);return(0,B.jsxs)(`div`,{className:`flex flex-col items-center gap-4 sm:flex-row sm:items-center`,children:[(0,B.jsx)(`div`,{className:`size-36 shrink-0`,children:(0,B.jsx)(g,{width:`100%`,height:`100%`,children:(0,B.jsxs)(l,{children:[(0,B.jsx)(b,{data:i,dataKey:`value`,nameKey:`label`,innerRadius:`62%`,outerRadius:`100%`,paddingAngle:+(i.length>1),stroke:`var(--background)`,strokeWidth:2,isAnimationActive:!1,children:i.map(e=>(0,B.jsx)(u,{fill:e.color},e.key))}),(0,B.jsx)(p,{content:(0,B.jsx)(tb,{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)($y,{resource:e,view:t,filter:n.filter,color:n.color,label:n.label,children:[(0,B.jsx)(`span`,{className:`font-medium tabular-nums`,children:Yy(n.value,r)}),(0,B.jsx)(`span`,{className:`w-9 text-right text-xs text-muted-foreground tabular-nums`,children:eb(n.value??0,a)})]},n.key))})]})},rb={hour:`2-digit`,minute:`2-digit`,hour12:!1},ib={day:`numeric`,month:`short`,...rb},ab={minute:rb,"5_minutes":rb,"15_minutes":rb,hour:rb,day:{day:`numeric`,month:`short`},week:{day:`numeric`,month:`short`},month:{month:`short`,year:`2-digit`},year:{year:`numeric`}},ob={minute:ib,"5_minutes":ib,"15_minutes":ib,hour:ib,day:{day:`numeric`,month:`short`,year:`numeric`},week:{day:`numeric`,month:`short`,year:`numeric`},month:{month:`long`,year:`numeric`},year:{year:`numeric`}},sb=e=>{let t=new Intl.DateTimeFormat(Le(),{...e,timeZone:`UTC`});return e=>t.format(e)},cb={fontSize:11,fill:`var(--muted-foreground)`},lb=864e5,ub=new Set([`minute`,`5_minutes`,`15_minutes`,`hour`]),db=(e,t)=>{let n=t.length>1?t.at(-1).at-t[0].at:0;return ub.has(e)&&n>=lb?ib:ab[e]},fb=({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`?By(`weekOf`,{day:sb(ob[r])(a.at)}):sb(ob[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:Yy(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:Yy(a.value,n)}),!i&&(0,B.jsx)(`div`,{className:`font-semibold tabular-nums`,children:Yy(a.value,n)})]})},pb=({points:e,measure:t,bucket:n,type:r,series:i,resource:o,view:s})=>{let l=hf(`(min-width: 640px)`),u=sb(db(n,e)),d=(0,B.jsx)(v,{vertical:!1,stroke:`var(--border)`}),f=(0,B.jsx)(a,{dataKey:`at`,tickFormatter:u,tick:cb,axisLine:!1,tickLine:!1,minTickGap:l?24:40,height:18}),m=(0,B.jsx)(pe,{width:l?48:36,tick:cb,axisLine:!1,tickLine:!1,tickCount:3,tickFormatter:e=>e.toLocaleString(Le(),{notation:`compact`})}),h=(0,B.jsx)(p,{cursor:r===`bar`?{fill:`var(--muted)`}:{stroke:`var(--border-strong)`},content:(0,B.jsx)(fb,{measure:t,bucket:n,...i&&{series:i}}),isAnimationActive:!1}),b=i??[{key:`value`,label:``,color:`var(--chart-1)`}],x=(0,B.jsx)(`div`,{className:`h-40`,children:(0,B.jsx)(g,{width:`100%`,height:`100%`,children:r===`line`?(0,B.jsxs)(y,{data:e,margin:{top:6,right:6,bottom:0,left:0},children:[d,f,m,h,b.map(t=>(0,B.jsx)(_,{dataKey:t.key,stroke:t.color,strokeWidth:2,dot:e.length<=31&&{r:3,fill:t.color,strokeWidth:0},activeDot:{r:4,stroke:`var(--background)`,strokeWidth:2},isAnimationActive:!1},t.key))]}):(0,B.jsxs)(c,{data:e,margin:{top:6,right:0,bottom:0,left:0},barCategoryGap:`22%`,children:[d,f,m,h,b.map((e,t)=>(0,B.jsx)(fe,{dataKey:e.key,fill:e.color,...i&&{stackId:`split`},radius:t===b.length-1?[4,4,0,0]:0,isAnimationActive:!1},e.key))]})})});return!i||o===void 0?x:(0,B.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[x,(0,B.jsx)(`ul`,{className:`flex flex-wrap gap-x-3 gap-y-0.5 text-sm`,children:i.map(e=>(0,B.jsx)($y,{resource:o,view:s,color:e.color,label:e.label,...e.filter!==void 0&&{filter:e.filter}},e.key))})]})},mb=1e-6,hb=(e,t,n,r,i,a=``)=>{let o=t.map((e,t)=>({key:`s${t}`,label:Wy(n,r,e),color:Uy(n,r,e.value,t),filter:Gy(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=Jy(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<mb?0:l}});return i.kind!==`average`&&l.some(e=>(e.other??0)>0)?{series:[...o,{key:`other`,label:By(`other`),color:`var(--border-strong)`}],points:l}:{series:o,points:l.map(({other:e,...t})=>t)}},gb=(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]}},_b=(e,t,n)=>{let r=e?.type===`relation`&&e.relation?t[e.relation.resource]:void 0;return r&&r.primaryKey.length===1?sr(r,n[r.name]):void 0},vb=({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=By(`nothingYet`)})=>{let{resources:f,views:p}=W(),m=e.fields[n],h=m?.type===`date`||m?.type===`timestamp`,g=_b(m,f,p),_=h&&r!==void 0?e.fields[r]:void 0,v=_b(_,f,p),y=_?{splitBy:_.name,splitLimit:8,...v&&{splitLabel:v}}:{},b=h?{granularity:c,range:l,timeZone:Gf(),...y}:{limit:u,...g&&{label:g}},x=Ry(e.name,{groupBy:n,filter:s,...a&&{sum:a},...o&&{average:o},...b},!!m),S=gb(e,t,a,o);if(!m)return null;if(x.isPending)return(0,B.jsx)(vh,{className:`h-36 w-full`});if(x.error)return(0,B.jsx)(`p`,{className:`text-danger-text`,children:By(`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}=hb(C,x.data.splits,_,t?.fields[_.name],S,s);return(0,B.jsx)(pb,{points:r,measure:S,bucket:c,type:w,series:n,resource:e.name,view:t})}if(h)return(0,B.jsx)(pb,{points:Jy(C,S),measure:S,bucket:c,type:w});let T=qy(C,m,t?.fields[n],S,s);return i===`donut`?(0,B.jsx)(nb,{resource:e.name,view:t,slices:T,measure:S}):(0,B.jsx)(Zy,{resource:e.name,view:t,slices:T,measure:S})},yb=({node:e,slots:t})=>{let{resource:n,title:r,description:i,actions:a,span:o,...s}=Dy(e),{resources:c,views:l}=W(),u=c[n];return u?(0,B.jsx)(Ay,{title:r,description:i,actions:t.actions,className:`h-full`,children:(0,B.jsx)(vb,{model:u,view:l[n],...s})}):null},bb=sn(),xb=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=sr(n,i),c=await e.fetchQuery({queryKey:H.labels(n.name,o.join(`,`)),staleTime:3e5,queryFn:async()=>(await t.list(n.name,{filter:Yt(bb.in(a,o)),fields:[a,s],pageSize:o.length})).items.map(e=>[String(e[a]),String(e[s])])});return new Map(c)},Sb=(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}]:[]}),Cb=(e,t,n,r)=>Object.fromEntries(Sb(e,n,r).filter(({target:e})=>e.primaryKey.length===1&&!t[e.name]?.titleFrom).map(({name:e,target:n})=>[e,sr(n,t[n.name])])),wb=(e,t,n,r,i={})=>{let a=Sb(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})},Tb=sn(),Eb=(e,t)=>{let n=t?.titleFrom;if(n&&!n.unreadable&&e.primaryKey.length===1)return n.fields},Db=(e,t,n)=>H.titleRow(e.name,t,n.join(`,`)),Ob=async(e,t,n,r)=>{let i=t.primaryKey[0],a=[...new Set(r)];if(a.length===0)return new Map;let o=await e.list(t.name,{filter:Yt(Tb.in(i,a)),fields:[i,...n],pageSize:a.length});return new Map(o.items.map(e=>[String(e[i]),e]))},kb=async(e,t,n,r,i,a,o)=>{let s=new Map;for(let e of a){let t=i.fields[e],a=t?.type===`relation`&&t.relation?n[t.relation.resource]:void 0;if(!a||!Eb(a,r[a.name]))continue;let c=o.flatMap(t=>t[e]==null?[]:[String(t[e])]);s.set(a.name,[...s.get(a.name)??[],...c])}await Promise.all([...s].map(async([i,a])=>{let o=n[i],s=Eb(o,r[i]),c=await Ob(t,o,s,a);for(let t of new Set(a))e.setQueryData(Db(o,t,s),{row:c.get(t)??null})}))},Ab=(e,t,n,r,i)=>{let a=r?.titleFrom;return a?{queryKey:Db(n,i,a.fields),queryFn:async()=>({row:(await Ob(t,n,a.fields,[i])).get(i)??null})}:{queryKey:H.relatedLabel(n.name,i),queryFn:async()=>({label:(await xb(e,t,n,[i],r)).get(i)??i})}},jb=(e,t,n,r,i)=>{if(e)return`label`in e?e.label:e.row?t(n,r,e.row,i):i},Mb=(e,t,n=!0)=>{let{views:r}=W(),i=U(),a=Se(),o=p_(),s=r[e.name];return jb(E({...Ab(a,i,e,s,t),staleTime:3e5,enabled:n}).data,o,e,s,t)},Nb=({value:e,hints:t,children:n})=>(0,B.jsx)(Pf,{tone:Em(t?.valueColors,e),color:Tm(t?.valueColors,e),shape:t?.badgeShape,children:n}),Pb=({target:e,id:t,known:n})=>{let r=Mb(e,t,n===void 0);return(0,B.jsx)(Uh,{to:{kind:`record`,resource:e.name,key:t},className:`font-medium text-primary-text hover:underline`,children:n??r??t})},Fb=({field:e,value:t,known:n})=>{let{resources:r}=W(),i=e.relation?r[e.relation.resource]:void 0;return i?(0,B.jsx)(Pb,{target:i,id:String(t),known:n}):(0,B.jsx)(`span`,{children:String(t)})},Ib=({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)(Fb,{field:t,value:n,known:i});let s=t.type===`file`?Np(n):void 0;if(s&&`url`in s&&s.url){let e=Vp(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)(j_,{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(gm(t,o))return(0,B.jsx)(pv,{source:String(n)});let c=Nm(t,n,o),l=t.type===`text`?xm(o):void 0;return l?(0,B.jsx)(bv,{format:l,value:c}):t.type===`enum`||o.format===`badge`?(0,B.jsx)(Nb,{value:n,hints:o,children:c}):(0,B.jsx)(`span`,{title:Pm(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})},Lb=e=>{let{views:t}=W(),n=tv(e.field,t[e.model.name]?.fields[e.field.name]),r=(0,B.jsx)(Ib,{...e});return n?(0,B.jsx)(dv,{shown:n,part:`display`,field:e.field,value:e.value,fallback:r}):r},Rb=(e,t,n)=>{if(!t)return[];let r=vu(e,t.model.name,n);return r.ok?r.steps:[]},zb=(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}}),Bb=(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}},Vb=(e,t)=>{let{resources:n}=W(),r=Rb(n,e,t);return Bb(e,r,E(zb(U(),Se(),e,t,r)))},Hb=(e,t)=>{let{resources:n}=W(),r=U(),i=Se(),a=t.map(t=>Rb(n,e,t)),o=f({queries:t.map((t,n)=>zb(r,i,e,t,a[n]))});return t.map((t,n)=>Bb(e,a[n],o[n]))},Ub=(e,t)=>{if(t)return t;let n=e.split(`.`).map(e=>F(e).toLowerCase()).join(` `);return n[0].toUpperCase()+n.slice(1)},Wb=({node:e})=>{let{name:t,label:n,format:r}=Dy(e),{views:i}=W(),a=Vb(Yv(),t);if(a.state===`missing`)return null;let o=a.state===`loading`?(0,B.jsx)(vh,{className:`h-4 w-24`}):(0,B.jsx)(Lb,{model:a.model,field:a.field,value:a.value,format:r});if(n===!1)return(0,B.jsx)(`div`,{children:o});let s=n??Ub(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})]})},Gb={1:``,2:`md:grid-cols-2`,3:`md:grid-cols-2 xl:grid-cols-3`,4:`sm:grid-cols-2 xl:grid-cols-4`},Kb={1:``,2:`grid-cols-2`,3:`grid-cols-2 xl:grid-cols-3`,4:`grid-cols-2 xl:grid-cols-4`},qb={1:``,2:`md:col-span-2`,3:`md:col-span-2 xl:col-span-3`,4:`sm:col-span-2 md:col-span-2 xl:col-span-4`},Jb=e=>typeof e==`object`&&!e.custom&&e.type===`Stat`,Yb=({node:e,children:t})=>{let{columns:n=2}=Dy(e),r=e.children,i=r.length>0&&r.every(Jb);return(0,B.jsx)(`div`,{className:P(`grid grid-cols-1 gap-4`,i?Kb[n]:Gb[n]),children:t.map((e,t)=>{let n=r[t],i=typeof n==`object`?n.props.span:void 0;return(0,B.jsx)(`div`,{className:P(`min-w-0`,i&&qb[i]),children:e},t)})})},Xb=`font-medium text-primary-text hover:underline`,Zb=({node:e})=>{let t=Dy(e),n=Yv()?.record,r=e.children.filter(e=>typeof e==`string`).join(``);if(t.to){let e=mn(t.to,n);return(0,B.jsx)(Uh,{to:e,className:Xb,children:r||Bc(e)})}let i=t.href??``;return(0,B.jsx)(`a`,{href:i,className:Xb,...i.startsWith(`http`)&&{target:`_blank`,rel:`noreferrer`},children:r||i})},Qb=M(`app/field`),$b=(e,t)=>typeof e?.[t]==`number`?e[t]:void 0,ex=(e,t)=>{let n=$b(t,`min`),r=$b(t,`max`);if(n!==void 0)return Qb(`atLeastCharacters`,{label:e,count:wp(n),n});if(r!==void 0)return Qb(`atMostCharacters`,{label:e,count:wp(r),n:r})},tx=e=>{let t=$b(e,`min`),n=$b(e,`max`);return t===void 0?n===void 0?Qb(`wholeNumber`):Qb(`wholeNumberAtMost`,{max:wp(n)}):Qb(`wholeNumberAtLeast`,{min:wp(t)})},nx=e=>{let t=$b(e,`precision`),n=$b(e,`scale`);if(t===void 0||n===void 0)return Qb(`number`);let r=wp(10**(t-n));return n===0?Qb(`wholeNumberBelow`,{below:r}):Qb(`decimalsBelow`,{scale:n,below:r})},rx={text:ex,integer:(e,t)=>tx(t),bigint:()=>Qb(`wholeNumber`),decimal:(e,t)=>nx(t),date:()=>Qb(`date`),timestamp:()=>Qb(`timestamp`),country:()=>Qb(`country`),currency:()=>Qb(`currency`),uuid:()=>Qb(`uuid`),enum:()=>Qb(`enum`),relation:()=>Qb(`relation`),json:()=>Qb(`json`)},ix=(e,t,n)=>n.code===`required`?Qb(`required`,{label:t}):n.code!==`invalid-value`||!e?n.message:rx[e.type]?.(t,n.params)??n.message,ax=e=>{if(!pl(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},ox=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?Qb(`checkField`):Qb(`checkFields`,{count:t.size})],...n].join(` `)},sx=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},cx=(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]:dg(n[t])];let i=r.default&&`value`in r.default?r.default.value:void 0;return[t,r.type===`boolean`?!!i:dg(i)]})),lx=(e,t,n)=>Object.fromEntries(Object.entries(t).flatMap(([t,r])=>{let i=e.fields[t];return Og(r)?r.key===dg(n[t])?[]:[[t,i.type===`integer`?Number(r.key):r.key]]:Sg(i,r,n[t])?[[t,yg(i,r)]]:[]})),ux=({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=iy(),f=Cy(),p=l[e.name],[m,h]=(0,I.useState)(()=>cx(e,a,t?.record)),[g,_]=(0,I.useState)({}),[v,y]=(0,I.useState)(0),b=sx(v),[x,S]=(0,I.useState)(),[C,w]=(0,I.useState)(!1),[T,E]=(0,I.useState)(!1);Vh(T||C,`input-lost`);let D=async()=>{w(!0),S(void 0),await(n===`create`?u.create(e.name,{...Mg(e,c,m),...o}):u.update(e.name,t.key,lx(e,m,t.record),t.etag??`*`)).then(async()=>{await f(e.name),d.show({state:`success`,title:sv(`saved`,{label:i??r})}),s()},e=>{let t=ax(e);_(t),Object.keys(t).length>0&&y(e=>e+1),S(e)}),w(!1)};return(0,B.jsx)(Cf,{title:i??r,onClose:s,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:s,children:sv(`cancel`)}),(0,B.jsx)(G,{variant:`primary`,loading:C,onClick:()=>void D(),children:sv(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)(Bg,{title:sv(`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)(Yh,{name:n,label:o,help:p?.fields[n]?.help,error:s&&ix(r,o,s),children:(0,B.jsx)(Ov,{field:r,hints:p?.fields[n],value:Og(i)?i.key:i,stored:t?.record[n],relationLabel:Og(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)})]})})},dx=({model:e,recordKey:t,children:n})=>{let r=xy(e,{key:t});return(0,B.jsx)(B.Fragment,{children:n(r.data??void 0)})},fx=({node:e})=>{let t=Dy(e),n=Yv(),{resources:r}=W(),i=r[t.resource??n?.model.name??``],a=af(i?.name??``),[o,s]=(0,I.useState)(!1);if(!i||!(t.mode===`create`?oy(a,`create`):oy(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)(ux,{...t,model:i,record:t.mode===`edit`?e:void 0,onClose:()=>s(!1)})]});return t.mode===`edit`&&t.recordKey!==void 0?(0,B.jsx)(dx,{model:i,recordKey:t.recordKey,children:c}):c(t.mode===`edit`?n:void 0)},px=e=>e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey,mx=`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`,hx=({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":yh(`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&&px(n)&&(n.preventDefault(),t(e.href))},className:P(mx,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(mx,s?`text-primary-text`:`text-muted-foreground`),children:[(0,B.jsx)(ca,{className:`size-6`,strokeWidth:s?2.2:1.9,"aria-hidden":!0}),yh(`more`)]})]})]})},gx=({id:e,open:t,onClose:n,children:r})=>{let i=(0,I.useRef)(null);return Sf(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":yh(`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},_x=(0,I.createContext)(()=>{}),vx=e=>{let t=(0,I.useContext)(_x);(0,I.useLayoutEffect)(()=>(t(e),()=>t(void 0)),[t,e])},yx=e=>{(0,I.useLayoutEffect)(()=>{if(!e)return;let t=document.documentElement;return t.style.setProperty(`scrollbar-gutter`,`stable`),()=>{t.style.removeProperty(`scrollbar-gutter`)}},[e])},bx=[`--pb-sticky-top`,`--pb-sticky-bottom`,`scroll-padding-top`,`scroll-padding-bottom`],xx=(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 bx)r.style.removeProperty(e)}},[e,t,n,r])},Sx=`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`,Cx=`fill-[#ff5a1f] dark:fill-[#ff6a33]`,wx=`fill-[#14161a] dark:fill-[#f1f0ea]`,Tx=({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:Cx,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:wx,d:`M17 0h10a5 5 0 0 1 5 5v22a5 5 0 0 1-5 5H5a5 5 0 0 1-5-5V17h17z`})]}),Ex=({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:wx,d:Sx})}),Dx=`Protobase`,Ox=({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)(Tx,{}),!e&&(0,B.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-0.5 leading-tight`,children:[r||n&&n!==Dx?(0,B.jsx)(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:n??Dx}):(0,B.jsx)(Ex,{className:`self-start`}),t&&(0,B.jsx)(`div`,{className:`truncate text-[11px] text-muted-foreground`,children:t})]})]}),kx=({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)(Si,{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))]}),Ax=()=>[{value:`light`,label:yh(`light`),icon:Fs},{value:`dark`,label:yh(`dark`),icon:ko},{value:`system`,label:yh(`system`),icon:Do}],jx=({theme:e,className:t})=>(0,B.jsxs)(`div`,{className:t,children:[(0,B.jsx)(Ns,{className:`size-4`}),(0,B.jsx)(`span`,{className:`flex-1`,children:yh(`theme`)}),(0,B.jsx)(Re,{label:yh(`theme`),iconOnly:!0,value:e.preference,options:Ax(),onChange:e.onChange})]}),Mx=`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`,Nx=({user:e,compact:t,open:n,items:r=[],account:i,onNavigate:a,onSignOut:o,organizations:s,roles:c,theme:l,status:u})=>{let d=c?.roles.find(e=>e.name===c.active),[f,p]=(0,I.useState)(!1),m=n??f,h=(0,I.useRef)(null),[g,_]=(0,I.useState)();(0,I.useEffect)(()=>{if(!m||n!==void 0)return;let e=e=>{(e instanceof KeyboardEvent?e.key===`Escape`:!h.current?.contains(e.target))&&p(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,e),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,e)}},[m,n]);let v=r.filter(e=>e.length>0),y=(e,t,n)=>{p(!1),!n&&a&&(e.preventDefault(),a(t))};return(0,B.jsxs)(`div`,{ref:h,className:`relative`,children:[(0,B.jsxs)(`button`,{type:`button`,className:`flex min-h-11 w-full items-center gap-2.5 rounded-md p-1 text-left hover:bg-muted md:min-h-0`,"aria-label":yh(`profileMenu`),"aria-haspopup":`menu`,"aria-expanded":m,onClick:()=>{let e=h.current?.getBoundingClientRect();e&&_({left:e.left,bottom:window.innerHeight-e.top+8}),p(!f)},children:[(0,B.jsx)(If,{initials:e.initials,hue:e.hue,size:`md`,className:`ring-0`}),!t&&(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(`span`,{className:`min-w-0 flex-1 leading-tight`,children:[u?.mark?(0,B.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1`,children:[(0,B.jsx)(`span`,{className:`truncate font-medium`,children:e.name}),u.mark]}):(0,B.jsx)(`span`,{className:`block truncate font-medium`,children:e.name}),(0,B.jsx)(Pf,{tone:e.roleTone,dot:!1,className:`mt-0.5 h-4 px-1.5 text-[10px]`,children:e.role})]}),(0,B.jsx)(Ai,{className:`size-3.5 shrink-0 text-faint-foreground`})]})]}),m&&(0,B.jsxs)(`div`,{role:`menu`,className:n===void 0?`fixed z-[60] w-56 overflow-hidden rounded-lg border bg-background py-1 shadow-pop`:`absolute bottom-full left-0 z-50 mb-2 w-56 overflow-hidden rounded-lg border bg-background py-1 shadow-pop`,style:n===void 0&&g?{left:g.left,bottom:g.bottom}:void 0,children:[i?(0,B.jsxs)(`a`,{role:`menuitem`,href:i,onClick:e=>y(e,i),className:`block border-b px-3 pb-2 pt-1.5 hover:bg-muted`,children:[(0,B.jsx)(`div`,{className:`font-medium`,children:e.name}),(0,B.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,children:e.email})]}):(0,B.jsxs)(`div`,{className:`border-b px-3 pb-2 pt-1.5`,children:[(0,B.jsx)(`div`,{className:`font-medium`,children:e.name}),(0,B.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,children:e.email})]}),u&&(0,B.jsx)(`div`,{className:`border-b py-1`,children:(0,B.jsxs)(`button`,{type:`button`,role:`menuitem`,className:Mx,onClick:()=>{p(!1),u.onOpen()},children:[(0,B.jsx)(ga,{className:`size-4 shrink-0`}),(0,B.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:u.label})]})}),s&&(s.current||s.others.length>0)&&(0,B.jsx)(kx,{label:yh(`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:Mx,onSwitch:e=>{p(!1),s.onSwitch(e)}}),c&&c.roles.length>1&&(0,B.jsx)(kx,{label:yh(`roles`),...d&&{current:{id:d.name,label:d.label}},others:c.roles.filter(e=>e!==d).map(({name:e,label:t})=>({id:e,label:t})),rowClassName:Mx,onSwitch:e=>{p(!1),c.onSwitch(e)}}),v.map((e,t)=>(0,B.jsx)(`div`,{role:`group`,className:P(`py-1`,(t<v.length-1||l||o)&&`border-b`),children:e.map(e=>{let t=e.icon;return(0,B.jsxs)(`a`,{role:`menuitem`,href:e.href,"aria-current":e.active?`page`:void 0,...e.external?{target:`_blank`,rel:`noreferrer`}:{},onClick:t=>y(t,e.href,e.external),className:P(Mx,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)(jx,{theme:l,className:P(Mx,`hover:bg-transparent`)})}),o&&(0,B.jsxs)(`button`,{type:`button`,role:`menuitem`,onClick:o,className:Mx,children:[(0,B.jsx)(oo,{className:`size-4`}),yh(`signOut`)]})]})]})},Px={"text-large":`h-8 gap-2.5 px-2.5`,"text-small":`h-7 gap-2 px-2 text-body`},Fx={"text-large":`ml-[20px]`,"text-small":`ml-[17px]`},Ix=({create:e,mode:t,onNavigate:n})=>(0,B.jsx)(`div`,{className:P(`border-l border-transparent pl-1.5`,Fx[t]),children:(0,B.jsxs)(`a`,{href:e.href,onClick:n&&(t=>{t.preventDefault(),n(e.href)}),className:P(`flex items-center rounded-md text-faint-foreground transition-colors hover:bg-muted hover:text-foreground`,Px[t]),children:[(0,B.jsx)(qo,{"aria-hidden":!0,className:`size-3.5 shrink-0`}),(0,B.jsx)(`span`,{className:`truncate`,children:e.label})]})}),Lx=`protobase:nav-open:`,Rx=e=>`${Lx}${e}`,zx=(e,t)=>Ie(()=>e.getItem(t)!==`false`,!0),Bx=(e,t,n)=>Ie(()=>n?e.removeItem(t):e.setItem(t,`false`),void 0),Vx=({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})]}),Hx=e=>e===`text-large`||e===`text-small`||e===`icon-expand`,Ux=e=>e===`text-large`||e===`text-small`,Wx={"text-large":`w-60`,"text-small":`w-52`,icon:`w-14`,"icon-label":`w-[76px]`,"icon-tooltip":`w-14`,"icon-expand":`w-14`},Gx={"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`},Kx=({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`,Gx[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}),(Hx(t)||t===`icon-label`)&&(0,B.jsx)(`span`,{className:`whitespace-nowrap`,children:e.label}),Ux(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}),Ux(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)(Vx,{label:e.label,children:o}):o},qx=99,Jx=e=>e===void 0||e<=0?void 0:e>qx?`${qx}+`:String(e),Yx=({count:e,className:t})=>{let n=Jx(e);return n?(0,B.jsx)(Pf,{tone:`red`,dot:!1,className:P(`h-4 min-w-4 justify-center px-1 text-[10px] font-semibold`,t),children:n}):null},Xx={neutral:`bg-faint-foreground`,info:`bg-primary`,success:`bg-success`,warning:`bg-warning`,danger:`bg-danger`},Zx=({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`,Xx[e])}),(0,B.jsx)(`span`,{className:P(`relative size-2 rounded-full`,Xx[e])})]}),Qx=M(`status`),$x=({presence:e})=>{let t=Qx(e);return(0,B.jsx)(`span`,{role:`img`,"aria-label":t,title:t,className:`flex shrink-0`,children:(0,B.jsx)(Zx,{tone:e===`online`?`success`:`neutral`})})},eS=e=>Qx(e===`busy`?`busy`:e===`do_not_disturb`?`doNotDisturb`:`automatic`),tS=({availability:e,title:t})=>{if(e===`automatic`)return null;let n=eS(e);return(0,B.jsx)(e===`busy`?Wi:Ri,{role:`img`,"aria-label":n,className:P(`size-3.5 shrink-0`,e===`busy`?`text-warning`:`text-danger`),children:(0,B.jsx)(`title`,{children:t??n})})},nS=({status:e,presence:t,textShown:n=`full`,className:r})=>{let i=wr(e);if(!i&&!t)return null;let a=i?.text??void 0;return(0,B.jsxs)(`span`,{className:P(`inline-flex min-w-0 items-center gap-1 text-muted-foreground`,r),title:a,children:[t&&(0,B.jsx)($x,{presence:t}),i&&(0,B.jsx)(tS,{availability:i.availability,...n===`hover`&&a&&{title:a}}),i&&n===`hover`&&i.availability===`automatic`&&a&&(0,B.jsx)(`span`,{role:`img`,"aria-label":a,className:`size-1.5 shrink-0 rounded-full bg-faint-foreground`}),a&&n===`full`&&(0,B.jsx)(`span`,{className:`truncate text-xs`,children:a})]})},rS=(e,t)=>e.map(e=>{let n=t&&Object.hasOwn(t,e.id)?t[e.id]:void 0;return n?{...e,mark:n}:e}),iS=e=>{if(!e)return[];let t=wr(e.status);return[e.presence&&Qx(e.presence),t&&t.availability!==`automatic`?eS(t.availability):void 0,t?.text??void 0]},aS=e=>{let t=[e.status?.label,...iS(e.mark?.person),e.mark?.label].filter(e=>e!==void 0&&e!==``);return{ariaLabel:[e.label,...t].join(`, `),title:t.length===0?e.label:`${e.label} (${t.join(`, `)})`}},oS=({records:e,mode:t,onNavigate:n})=>e.map(e=>{let{ariaLabel:r,title:i}=aS(e),a=n&&(t=>{t.preventDefault(),n(e.href)}),o=e.mark?.strong===!0;return(0,B.jsx)(`li`,{children:(0,B.jsxs)(`a`,{href:e.href,onClick:a,"aria-label":r,title:i,"aria-current":e.active?`page`:void 0,className:P(`flex min-w-0 items-center rounded-md transition-colors`,Px[t],o?`font-bold`:`font-medium`,e.active||o?`text-foreground`:`text-muted-foreground`,e.active?`bg-muted`:`hover:bg-muted hover:text-foreground`),children:[e.status&&(0,B.jsx)(Zx,{tone:e.status.tone,pulse:e.status.pulse}),(0,B.jsx)(`span`,{className:`truncate`,children:e.label}),e.mark?.person&&(0,B.jsx)(nS,{...e.mark.person,textShown:`hover`,className:`ml-1.5 shrink-0`}),(0,B.jsx)(Yx,{count:e.mark?.count,className:`ml-auto shrink-0`})]})},e.id)}),sS=({records:e,useMarks:t,...n})=>(0,B.jsx)(oS,{records:rS(e,t()),...n}),cS=({records:e,useMarks:t,mode:n,onNavigate:r})=>t?(0,B.jsx)(sS,{records:e,useMarks:t,mode:n,onNavigate:r}):(0,B.jsx)(oS,{records:e,mode:n,onNavigate:r}),lS=({item:e,recent:t,mode:n,active:r,onNavigate:i})=>{let a=Rx(e.id),[o,s]=(0,I.useState)(()=>zx(localStorage,a)),c=(0,I.useId)(),l=e.href??`#${e.id}`;return(0,B.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,B.jsxs)(`div`,{className:`relative`,children:[(0,B.jsx)(Kx,{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":yh(`recent`,{plural:e.label.toLowerCase()}),onClick:()=>{Bx(localStorage,a,!o),s(!o)},className:`absolute right-1 top-1/2 inline-flex size-6 -translate-y-1/2 items-center justify-center rounded text-faint-foreground hover:bg-muted hover:text-foreground`,children:(0,B.jsx)(Oi,{className:P(`size-3.5 transition-transform`,o&&`rotate-90`)})})]}),o&&(0,B.jsxs)(`ul`,{id:c,"aria-label":yh(`recent`,{plural:e.label.toLowerCase()}),className:P(`flex flex-col gap-0.5 border-l pl-1.5`,Fx[n]),children:[t.state===`loading`&&(0,B.jsx)(`li`,{className:P(`flex items-center text-faint-foreground`,Px[n]),children:yh(`loading`)}),t.state===`error`&&(0,B.jsx)(`li`,{className:P(`flex items-center text-faint-foreground`,Px[n]),children:yh(`couldNotLoad`)}),t.state===`ready`&&(0,B.jsx)(cS,{records:t.records,useMarks:t.useMarks,mode:n,onNavigate:i}),(0,B.jsx)(`li`,{children:(0,B.jsx)(`a`,{...(e=>({href:e,onClick:i&&(t=>{t.preventDefault(),i(e)})}))(l),className:P(`flex items-center rounded-md text-faint-foreground transition-colors hover:bg-muted hover:text-foreground`,Px[n]),children:yh(`viewAll`)})})]})]})},uS=({mode:e,activeItem:t,user:n,workspace:r,appName:i,appIcon:a,forceExpanded:o,profileMenuOpen:s,groups:c=[],userMenu:l,account:u,onNavigate:d,onSignOut:f,signIn:p,organizations:m,roles:h,theme:g,status:_,sticky:v,logo:y=Ox,notice:b})=>{let x=e===`icon-expand`,S=x&&o,C=Ux(e)||x;return(0,B.jsx)(`nav`,{"aria-label":yh(`resources`),className:P(v?`sticky top-0 h-dvh self-start`:`relative`,`z-30 shrink-0`,Wx[e]),children:(0,B.jsxs)(`div`,{className:P(`group/side absolute inset-y-0 left-0 flex flex-col overflow-hidden border-r bg-sidebar pb-[var(--pb-safe-bottom)] pt-[var(--pb-safe-top)]`,x?`w-14 transition-[width,box-shadow] duration-150 hover:w-60 hover:shadow-pop focus-within:w-60 focus-within:shadow-pop`:`w-full`,S&&`w-60 shadow-pop`),children:[(0,B.jsx)(`div`,{className:P(`flex h-12 shrink-0 items-center px-3.5`,e===`icon-label`&&`justify-center px-0`),children:(0,B.jsx)(y,{compact:!C,workspace:r,appName:i,appIcon:a})}),(0,B.jsx)(`div`,{className:P(`flex-1 overflow-y-auto overflow-x-hidden pb-2`,`px-2`),children:c.map((n,r)=>(0,B.jsxs)(`div`,{className:P(`flex flex-col gap-0.5`,r>0&&`mt-3`),children:[C?n.label&&(0,B.jsx)(`div`,{className:P(`px-3 pb-1 pt-1 text-xs font-medium uppercase tracking-wide text-faint-foreground`,x&&`h-4 whitespace-nowrap py-0 opacity-0 transition-opacity group-hover/side:opacity-100 group-focus-within/side:opacity-100`,S&&`opacity-100`),children:n.label}):r>0&&(0,B.jsx)(`div`,{className:`mx-auto mb-1 h-px w-6 bg-border`}),n.items.map(n=>(0,B.jsxs)(I.Fragment,{children:[n.recent&&Ux(e)?(0,B.jsx)(lS,{item:n,recent:n.recent,mode:e,active:n.id===t,onNavigate:d}):(0,B.jsx)(Kx,{item:n,mode:e,active:n.id===t,onNavigate:d}),n.create&&Ux(e)&&(0,B.jsx)(Ix,{create:n.create,mode:e,onNavigate:d})]},n.id))]},n.label))}),b,(0,B.jsx)(`div`,{className:P(`shrink-0 border-t p-2`,e!==`text-large`&&e!==`text-small`&&!x&&`flex justify-center`),children:n?(0,B.jsx)(Nx,{user:n,compact:!C,open:s,items:l,account:u,onNavigate:d,onSignOut:f,organizations:m,roles:h,theme:g,status:_}):(0,B.jsxs)(B.Fragment,{children:[g&&C&&(0,B.jsx)(jx,{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)(Sh,{to:p,"aria-label":yh(`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)(io,{className:`size-4 shrink-0`}),C&&(0,B.jsx)(`span`,{className:`whitespace-nowrap`,children:yh(`signIn`)})]})]})})]})})},dS=e=>gf()&&Ux(e),fS=(0,I.createContext)(null),pS=()=>(0,I.useContext)(fS),mS=e=>{let t=e.at(-2);if(typeof t==`object`&&t.href&&!t.loading)return{label:t.label,href:t.href}},hS=({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}),gS=(e,t,n)=>t===0?-1:e<0?n===1?0:t-1:(e+n+t)%t,_S=e=>e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||e.button!==0,vS=({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=>gS(e,d.length,t.key===`ArrowDown`?1:-1));else if(t.key===`Enter`){let e=d[l]??d[0];if(!e)return;t.preventDefault(),h(e.href)}else t.key===`Escape`&&(e.text?e.onTextChange(``):t.currentTarget.blur(),u(-1))},v=-1;return(0,B.jsxs)(`div`,{className:P(`relative`,t),children:[(0,B.jsx)(J,{ref:m,wrapperClassName:`w-full bg-surface shadow-none`,leading:e.loading?(0,B.jsx)($d,{className:`size-4`}):(0,B.jsx)(ss,{className:`size-4`}),trailing:e.text?(0,B.jsx)(`button`,{type:`button`,"aria-label":yh(`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)(yc,{className:`size-3.5`})}):r?(0,B.jsx)(`span`,{className:`hidden md:inline-flex`,children:(0,B.jsx)(hS,{children:`⌘K`})}):void 0,placeholder:e.placeholder,"aria-label":yh(`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":yh(`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?yh(`searching`):yh(`noMatches`,{query:e.query})}),e.groups.map(e=>(0,B.jsxs)(`div`,{role:`group`,"aria-label":e.label,children:[(0,B.jsx)(`div`,{className:`px-3 pb-1 pt-2 text-[11px] font-medium uppercase tracking-wide text-faint-foreground`,children:e.label}),e.failed&&(0,B.jsx)(`p`,{className:`px-3 py-1.5 text-danger-text`,children:yh(`couldNotSearch`,{label:e.label})}),e.hits.map(e=>{v+=1;let t=v;return(0,B.jsxs)(`a`,{id:p(t),href:e.href,tabIndex:-1,role:`option`,"aria-selected":t===l,className:P(`block px-3 py-1.5`,t===l?`bg-primary-soft text-primary-text`:`hover:bg-muted`),onMouseDown:e=>e.preventDefault(),onClick:t=>{_S(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))]})]})},yS=({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=mS(e),m=(0,I.useRef)(null);return(0,I.useLayoutEffect)(()=>{if(!s)return;let e=e=>{if(e.key.toLowerCase()!==`k`||!(e.metaKey||e.ctrlKey))return;e.preventDefault();let t=m.current;t&&t.offsetParent!==null?t.focus():f(!0)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[s]),(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(`header`,{ref:u,className:P(c?`sticky top-0 z-30 max-md:fixed max-md:left-[var(--pb-safe-left)] max-md:right-[var(--pb-safe-right)]`:`relative`,`flex h-[calc(3rem+var(--pb-safe-top))] shrink-0 items-center gap-1 border-b bg-background pl-4 pr-2 pt-[var(--pb-safe-top)] md:gap-4 md:px-5`),children:[i&&(0,B.jsx)(`button`,{type:`button`,"aria-label":yh(`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)(ho,{className:`size-5`})}),p&&(0,B.jsx)(`a`,{href:p.href,"aria-label":yh(`backTo`,{label:p.label}),onClick:e=>{let r=n??t;r&&bh(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)(Ei,{className:`size-5`})}),(0,B.jsx)(xh,{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)(vS,{ref:m,search:s})}),(0,B.jsx)(`button`,{type:`button`,"aria-label":yh(`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)(ss,{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)(vS,{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":yh(`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)(yc,{className:`size-5`})})]})]}),c&&(0,B.jsx)(`div`,{"aria-hidden":!0,className:`h-[var(--pb-sticky-top)] shrink-0 md:hidden`})]})},bS=`app-drawer`,xS=({sidebarMode:e,activeItem:t,breadcrumb:n,user:r,workspace:i,appName:a,appIcon:o,logo:s,actions:c,rightPanel:l,sidebarNotice:u,banner:d,forceExpanded:f,profileMenuOpen:p,navGroups:m,userMenu:h,account:g,bottomBar:_,onNavigate:v,onBack:y,onSignOut:b,signIn:x,organizations:S,roles:C,theme:w,status:T,search:E,pageScroll:D=!1,className:O,children:k})=>{let A=gf(),j=dS(e),[ee,te]=(0,I.useState)(!1);(0,I.useEffect)(()=>{A&&te(!1)},[A]);let ne=!A&&_&&_.length>0?_:void 0,[re,ie]=(0,I.useState)(),ae=re??D,oe=(0,I.useRef)(null),[se,ce]=(0,I.useState)(null),le=(0,I.useRef)(null);xx(ae,oe,le,!!ne),yx(ae);let ue=(e,n=!1,c)=>(0,B.jsx)(uS,{mode:e,sticky:n,notice:c,activeItem:t,user:r,workspace:i,appName:a,appIcon:o,forceExpanded:f,profileMenuOpen:p,groups:m,userMenu:h,account:g,onNavigate:v,onSignOut:b,signIn:x,organizations:S,roles:C,theme:w,status:T,logo:s});return(0,B.jsx)(_x.Provider,{value:ie,children:(0,B.jsxs)(`div`,{className:P(ae?`flex min-h-full w-full overflow-x-clip bg-background`:`relative flex h-full min-h-0 w-full overflow-hidden bg-background`,O),children:[A?ue(e,ae,j&&u):(0,B.jsx)(gx,{id:bS,open:ee,onClose:()=>te(!1),children:ue(`text-large`)}),(0,B.jsxs)(`div`,{className:P(`flex min-w-0 flex-1 flex-col`,!ne&&`pb-[var(--pb-safe-bottom)]`),children:[(0,B.jsx)(yS,{ref:oe,slotRef:ce,sticky:ae,breadcrumb:n,onNavigate:v,onBack:y,actions:c,onMenu:A||ne?void 0:()=>te(!0),menuOpen:ee,menuControls:bS,search:E}),d,(0,B.jsx)(`main`,{className:ae?`flex flex-1 flex-col`:`flex min-h-0 flex-1 flex-col`,children:(0,B.jsx)(fS.Provider,{value:se,children:k})}),ne&&(0,B.jsx)(hx,{ref:le,sticky:ae,tabs:ne,onNavigate:v,onMore:()=>te(!0),moreOpen:ee,moreControls:bS})]}),l&&(0,B.jsx)(`div`,{className:ae?`sticky top-0 flex h-dvh shrink-0 self-start pt-[var(--pb-safe-top)]`:`flex shrink-0`,children:l})]})})},SS=({title:e,subtitle:t,actions:n,subtitleBelow:r})=>r?(0,B.jsx)(CS,{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})]}),CS=({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})]}),wS=({node:e,children:t,slots:n})=>{let{title:r,description:i}=Dy(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)(SS,{title:r,subtitle:i,actions:n.actions}),t]})})},TS=(e,t)=>{let n=Yv(),r=Vb(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},ES=({node:e})=>{let{value:t,max:n,label:r}=Dy(e),i=TS(t,0),a=TS(n,100);if(i===void 0||a===void 0)return(0,B.jsx)(vh,{className:`h-6 w-full`});if(!Number.isFinite(i)||!Number.isFinite(a))return null;let o=a>0?Math.min(1,Math.max(0,i/a)):0;return(0,B.jsxs)(`div`,{className:`min-w-0`,children:[(0,B.jsxs)(`div`,{className:`flex items-baseline justify-between gap-2 text-body`,children:[(0,B.jsx)(`span`,{className:`text-muted-foreground`,children:r}),(0,B.jsxs)(`span`,{className:`tabular-nums`,children:[i.toLocaleString(Le()),` / `,a.toLocaleString(Le())]})]}),(0,B.jsx)(`div`,{role:`progressbar`,"aria-label":r,"aria-valuenow":i,"aria-valuemin":0,"aria-valuemax":a,className:`mt-1.5 h-2 overflow-hidden rounded-full bg-muted`,children:(0,B.jsx)(`div`,{className:o>=.9?`h-full rounded-full bg-warning`:`h-full rounded-full bg-primary`,style:{width:`${o*100}%`}})})]})},DS=({model:e,filter:t,sort:n,recordKey:r,title:i,description:a,empty:o,actions:s,children:c})=>{let l=xy(e,{filter:t,sort:n,key:r}),u=e=>l.data?(0,B.jsx)(Jv,{value:l.data,children:e}):void 0,d=l.isPending?(0,B.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,B.jsx)(vh,{className:`h-4 w-1/2`}),(0,B.jsx)(vh,{className:`h-4 w-1/3`})]}):l.error?(0,B.jsx)(Bg,{title:sv(`couldNotLoad`),error:l.error}):l.data?u((0,B.jsx)(`div`,{className:`flex flex-col gap-3`,children:c})):(0,B.jsx)(jy,{children:o??sv(`nothingYet`)});return(0,B.jsx)(Ay,{title:i,description:a,actions:s?u(s):void 0,className:`h-full`,children:d})},OS=({node:e,children:t,slots:n})=>{let{resource:r,filter:i,sort:a,recordKey:o,title:s,description:c,empty:l}=Dy(e),u=W().resources[r];return u?(0,B.jsx)(DS,{model:u,filter:i,sort:a,recordKey:o,title:s,description:c,empty:l,actions:n.actions,children:t}):null},kS=`0.75rem`,AS=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% + ${kS}) * ${e} - ${kS})`},jS=({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:kS,scrollbarWidth:`thin`,"--snap-item-width":AS(e)},children:n}),MS=M(`app/embedded-list`),NS=(e,t,n)=>{if(!(e>=t))return MS(n?`firstOfAbout`:`firstOf`,{shown:e,total:t.toLocaleString(Le())})},PS=`protobase:embedded-display:`,FS=e=>`${PS}${e}`,IS=(e,t)=>Ie(()=>e.getItem(t)??void 0,void 0),LS=(e,t,n)=>Ie(()=>e.setItem(t,n),void 0),RS=(e,t,{picked:n,preferred:r})=>{let i=$m(e).map(e=>e.name);return n!==void 0&&i.includes(n)?n:Gm(e,t,r!==void 0&&i.includes(r)?r:void 0)},zS=(e,t,n,{resource:r=e.name,...i})=>_h({kind:`list`,resource:r},i,{...hh(e,t,n),display:Gm(t,n)}),BS=M(`app/related-cards`),VS=({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:BS(n?`showLess`:`showMore`)})]})},HS=e=>e==null||e===``,US=({scope:e,path:t})=>{let{views:n}=W(),r=Vb(e,t);if(r.state===`missing`||r.state===`ready`&&HS(r.value))return null;let i=Ub(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)(vh,{className:`h-4 w-24`}):(0,B.jsx)(VS,{children:(0,B.jsx)(Lb,{model:r.model,field:r.field,value:r.value})})})]})},WS=({scope:e,view:t,fields:n,actions:r})=>{let i=p_();return(0,B.jsxs)(`li`,{className:`flex min-w-0 flex-col gap-3 rounded-lg border border-border bg-surface p-4`,children:[(0,B.jsx)(Uh,{to:{kind:`record`,resource:e.model.name,key:ym(e.model,e.record)},className:`self-start font-medium text-primary-text hover:underline`,children:i(e.model,t,e.record,e.key)}),n.length>0&&(0,B.jsx)(`dl`,{className:`flex flex-col gap-3`,children:n.map(t=>(0,B.jsx)(US,{scope:e,path:t},t))}),r.length>0&&(0,B.jsx)(Jv,{value:e,children:(0,B.jsx)(`div`,{className:`flex flex-wrap items-center gap-2`,children:r.map(e=>(0,B.jsx)(Oy,{name:e},e))})})]})},GS=({model:e,view:t,filter:n,sort:r,fields:i,actions:a,limit:o,display:s,empty:c,carousel:l})=>{let u=_f(),d=r||dh(e,t),f=Sy(e,{filter:n,sort:d,pageSize:o}),p=by(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)(vh,{className:`h-24 w-full`},t))});if(f.error)return(0,B.jsx)(Bg,{title:BS(`couldNotLoad`),error:f.error});let m=f.data.items;if(m.length===0)return(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:c??BS(`nothingYet`)});let h=m.map(n=>{let r=vy(e,n);return(0,B.jsx)(WS,{scope:r,view:t,fields:i,actions:a},r.key)}),g=p.data===void 0?void 0:NS(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)(jS,{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)(Uh,{to:zS(e,t,u,{filter:n,orderBy:d,display:RS(t,u,{preferred:s})}),className:`flex items-center gap-1 font-medium text-primary-text hover:underline`,children:[MS(`viewAll`),` `,(0,B.jsx)(`span`,{className:`sr-only`,children:(t?.names?.plural??F(e.name)).toLowerCase()}),(0,B.jsx)(Rr,{className:`size-3.5`,"aria-hidden":!0})]})]})]})},KS={"1/4":1/4,"1/3":1/3,"1/2":1/2,"2/3":2/3},qS=({node:e,slots:t})=>{let n=Dy(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}=_u(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)(Bf,{title:u,help:d,actions:t.actions,children:(0,B.jsx)(GS,{model:_,view:v,filter:i,sort:a,fields:o??Tr(_,v),actions:s,limit:c,display:l,empty:f,carousel:p===`carousel`?KS[m]:void 0})})})},JS=e=>t=>{let n=t.currentTarget;n.scrollWidth>Math.ceil(n.getBoundingClientRect().width)?n.title=e:n.removeAttribute(`title`)},YS=({text:e,className:t})=>(0,B.jsx)(`span`,{className:P(`truncate`,t),onMouseEnter:JS(e),children:e}),XS=e=>(0,B.jsx)(`span`,{className:`text-faint-foreground`,children:e}),ZS=(e,t)=>{if(t==null)return XS(`—`);let n=qp(e,t)??``;switch(e.kind){case`text`:return e.link?(0,B.jsx)(bv,{format:e.link,value:n,className:`block min-w-0 truncate`}):(0,B.jsx)(YS,{text:n});case`id`:return(0,B.jsx)(YS,{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?dp(Number(t)):Gp(`shownIn`,{zone:ep(Number(t),Gf())}),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?XS(`—`):(0,B.jsx)(`span`,{className:`tabular-nums`,children:n});case`status`:return(0,B.jsx)(Pf,{tone:e.tones?.[String(t)]??`neutral`,color:Tm(e.colors,t),shape:e.shape,children:n});case`relation`:return(0,B.jsx)(YS,{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)(Si,{className:`size-3`,strokeWidth:3})}):XS(Gp(`no`));case`file`:{let e=Np(t);if(!e)return XS(`—`);if(`missing`in e)return(0,B.jsx)(YS,{text:e.name,className:`text-danger-text`});let n=Vp(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)(j_,{image:n,className:`size-5 shrink-0 rounded-sm object-cover`}):(0,B.jsx)(Fo,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,B.jsx)(YS,{text:e.name})]})}case`user`:{let r=e.users?.(String(t));return r?(0,B.jsxs)(`span`,{className:`inline-flex items-center gap-2 truncate`,children:[(0,B.jsx)(If,{initials:r.initials,hue:r.hue,size:`xs`,className:`ring-0`}),(0,B.jsx)(YS,{text:r.name,className:`text-muted-foreground`})]}):(0,B.jsx)(YS,{text:n,className:`text-muted-foreground`})}}},QS=Ae({rowSortingFeature:C,rowSelectionFeature:s}),$S=w(),eC=e=>$S.columns(e.map(e=>$S.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):ZS(e,t.getValue())}))),tC=(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}]}),nC=({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:[Dp(e),t>0&&(0,B.jsx)(`span`,{className:`ml-3 font-medium text-primary-text`,children:Gp(`selected`,{count:wp(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))]})}),rC=(e,t)=>typeof e.label==`string`?e.label:e.label(t),iC=(e,t)=>e.filter(e=>e.available?.(t)??!0),aC=({row:e,actions:t})=>{let{open:n,setOpen:r,place:i,button:a,menu:o}=rg();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":Gp(`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)(ca,{className:`size-4`})}),n&&(0,Sc.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=rC(t,e),a=t.blocked?.(e),o=P(`block w-full px-3 py-1.5 text-left hover:bg-muted disabled:cursor-default disabled:opacity-60 disabled:hover:bg-transparent`,t.destructive&&`text-danger-text`);return(0,B.jsx)(`li`,{role:`none`,children:t.link&&a===void 0?(0,B.jsx)(Sh,{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)]})},oC=e=>52+Math.ceil(String(e).length*1.33)*7,sC=.6,cC=(e,t)=>Math.max(e.minWidth??0,e.width*t),lC=(e,t)=>e.fixed?`${Math.max(e.minWidth??0,e.width)}px`:`minmax(${cC(e,t)}px, ${e.width}fr)`,uC=(e,t,n=0,r=sC)=>`${t}px ${e.map(e=>lC(e,r)).join(` `)}${n>0?` ${n}px`:``}`,dC=(e,t,n=0,r=sC)=>t+n+e.reduce((e,t)=>e+(t.fixed?Math.max(t.minWidth??0,t.width):cC(t,r)),0),fC=()=>{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}},pC=`protobase:pinned:`,mC=(e,t)=>`${pC}${e}:${t}`,hC=(e,t)=>Ie(()=>{let n=e.getItem(t);if(n===null)return;let r=JSON.parse(n);return Array.isArray(r)&&r.every(e=>typeof e==`string`)?r:void 0},void 0),gC=(e,t,n)=>Ie(()=>e.setItem(t,JSON.stringify(n)),void 0),_C=(e,t=[])=>{let[n,r]=(0,I.useState)(()=>e?hC(localStorage,e):void 0),i=(0,I.useCallback)(t=>{r(t),e&&gC(localStorage,e,t)},[e]);return[n??t,i]},vC=e=>{let t=e.findIndex(e=>e.title);return t<0||t>1?[]:e.slice(0,t+1).map(e=>e.id)},yC=e=>Object.fromEntries(e.map(({id:e,width:t,minWidth:n,fixed:r})=>[e,{width:t,minWidth:n,fixed:r}])),bC=(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:yC(um(e,t))});let o=a?.sizes;return(0,I.useMemo)(()=>o?e.map(e=>({...e,...o[e.id]})):e,[e,o])},xC=(e,t)=>Math.max(Math.min(64,e),Math.round(e+t)),SC=(e,t)=>e.map(e=>e.id in t?{...e,fixed:!0,width:t[e.id],minWidth:void 0}:e),CC=e=>Object.fromEntries([...e.querySelectorAll(`[data-col-id]`)].map(e=>[e.dataset.colId,e.offsetWidth])),wC=e=>{let[t,n]=(0,I.useState)({}),r=()=>({...e.current?CC(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]:xC(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]:xC(a[e]??0,i)})}}},TC=({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)(xo,{className:`size-3`,strokeWidth:3}):e&&(0,B.jsx)(Si,{className:`size-3`,strokeWidth:3})}),EC=e=>e===`money`||e===`number`||e===`signed`||e===`percent`,DC=()=>Gp(`unsortable`),OC=({header:e,pinned:t,sortable:n,onTogglePin:r})=>{let{open:i,setOpen:a,place:o,button:s,menu:c}=rg();return(0,B.jsxs)(`div`,{className:`relative ml-auto shrink-0`,children:[(0,B.jsx)(`button`,{ref:s,type:`button`,"aria-label":Gp(`columnMenu`,{header:e}),"aria-haspopup":`menu`,"aria-expanded":i,onClick:()=>a(!i),className:`relative inline-flex size-5 items-center justify-center rounded text-faint-foreground hover:bg-muted hover:text-foreground focus-visible:opacity-100 after:absolute after:-inset-2 after:content-[''] md:opacity-0 md:group-hover/cell:opacity-100 aria-expanded:opacity-100`,children:(0,B.jsx)(ca,{className:`size-3.5`})}),i&&(0,Sc.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:DC()})}),(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:Gp(t?`unpin`:`pinToLeft`)})})]}),document.body)]})},kC=({id:e,header:t,width:n,resize:r})=>(0,B.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":Gp(`resizeColumn`,{header:t}),"aria-valuemin":64,"aria-valuenow":n,tabIndex:0,onPointerDown:t=>r.onPointerDown(e,t),onKeyDown:t=>r.onKeyDown(e,t),className:`group/resize absolute inset-y-0 right-0 z-10 flex w-2 cursor-col-resize touch-none justify-end outline-none`,children:(0,B.jsx)(`div`,{className:`h-full w-0.5 bg-transparent group-hover/resize:bg-primary group-focus-visible/resize:bg-primary group-active/resize:bg-primary`})}),AC=({sorted:e})=>e===`asc`?(0,B.jsx)(Wr,{className:`size-3 text-foreground`}):e===`desc`?(0,B.jsx)(Pr,{className:`size-3 text-foreground`}):(0,B.jsx)(Ai,{className:`size-3 opacity-0 group-hover/head:opacity-100`}),jC=({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:Gp(`new`)})]}),MC=({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:uC(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)(TC,{checked:!1,indeterminate:r>0,label:Gp(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`,EC(e.kind)&&`justify-end`,`hover:text-foreground`,t&&`text-foreground`),children:[(0,B.jsx)(jC,{spec:e}),(0,B.jsx)(AC,{sorted:t})]}):(0,B.jsx)(`div`,{title:DC(),className:P(`flex h-full min-w-0 flex-1 items-center gap-1 pl-3 pr-1 text-left`,EC(e.kind)&&`justify-end`),children:(0,B.jsx)(jC,{spec:e})}),(0,B.jsx)(`div`,{className:`pr-1.5`,children:(0,B.jsx)(OC,{header:e.header,pinned:r,sortable:!!e.sortable,onTogglePin:()=>u(e.id)})}),d&&(0,B.jsx)(kC,{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]}),NC=e=>({gridTemplateColumns:uC(e.specs,e.gutter,e.trailing,e.minScale),height:e.height,transform:`translateY(${e.offset}px)`}),PC=(e,t)=>P(`flex h-full min-w-0 items-center overflow-hidden whitespace-nowrap px-3`,EC(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)]`),FC=(e,t)=>t&&e.id in t?{left:t[e.id]}:void 0,IC=({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)(TC,{checked:!!r,label:Gp(`selectRow`,{row:t+1})}),e>40&&(0,B.jsx)(`span`,{className:`min-w-6 text-right text-[11px] tabular-nums text-faint-foreground`,children:wp(t+1)})]}),LC=(e,t,n)=>({gridTemplateColumns:uC(e.specs,e.gutter,e.trailing,e.minScale),height:e.height,top:e.offset,transform:t===0?void 0:`translateY(${t}px)`,transition:n}),RC=e=>t=>{t.target.closest(`a`)||e()},zC=({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&&RC(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?NC(u):LC(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)(IC,{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(PC(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:FC(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})]}),BC=[`w-3/4`,`w-1/2`,`w-2/3`,`w-5/6`,`w-2/5`],VC=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:NC(e),children:[(0,B.jsx)(IC,{width:e.gutter,index:e.index,selectable:!1,edge:e.scrolled&&!e.lastPinned}),e.specs.map((t,n)=>(0,B.jsx)(`div`,{className:PC(t,e),style:FC(t,e.pins),children:(0,B.jsx)(vh,{className:P(`h-2.5`,BC[(e.index+n)%BC.length],EC(t.kind)&&`ml-auto`)})},t.id))]}),HC=(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}}},UC=(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)},WC=(e,t)=>Math.max(0,Math.min(40,e-t*40)),GC=({total:e,rowAt:t,loadRows:n,revision:r,latencyMs:i},a,o)=>{let s=(0,I.useMemo)(()=>HC(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=UC(u*40,d*40,40).filter(e=>!s.hasPage(e)),a=t=>WC(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=UC(u*40,d*40,40);s.keepOnly(t);for(let r of t.filter(e=>s.hasPage(e)))n(r*40,WC(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])},KC=1e7,qC=(e,t,n)=>{let r=e*t,i=Math.min(r,KC);return{rowHeight:t,trueHeight:r,contentHeight:i,scaled:r>i,maxTop:Math.max(0,r-n),maxScroll:Math.max(0,i-n)}},JC=(e,t)=>!e.scaled||t<=0?t:t>=e.maxScroll?e.maxTop+t-e.maxScroll:t/e.maxScroll*e.maxTop,YC=(e,t)=>!e.scaled||t<=0?t:t>=e.maxTop?e.maxScroll+t-e.maxTop:t/e.maxTop*e.maxScroll,XC=(e,t,n,r)=>{let i=t*e.rowHeight;return e.scaled?i-n+r:i},ZC=(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)}},QC=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},$C=e=>e===(document.scrollingElement??document.documentElement),ew=e=>$C(e)?window:e,tw=e=>Number.parseFloat(e)||0,nw=e=>{let t=getComputedStyle(e),n=$C(e)?{top:0,height:e.clientHeight}:{top:e.getBoundingClientRect().top+e.clientTop,height:e.clientHeight},r=tw(t.scrollPaddingTop);return{top:n.top+r,height:Math.max(0,n.height-r-tw(t.scrollPaddingBottom))}},rw=6,iw=(e,t,n)=>{let r=qC(t,n,e.height),i=JC(r,e.position);return{geometry:r,top:i,topIndex:Math.floor(Math.max(0,i)/n),...ZC(t,i,n,e.height,rw)}},aw=({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=nw(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=iw(t,n,r),o=iw(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+=YC(qC(n,r,e.height),i*r)-e.position:e.position>0&&(t.scrollTop=0)},[f]);(0,I.useLayoutEffect)(()=>{let e=s.current;if(!e)return;let t=QC(e);c.current=t;let n=ew(t);n.addEventListener(`scroll`,h,{passive:!0}),window.addEventListener(`resize`,h,{passive:!0});let r=new ResizeObserver(()=>{p.current.laidOut=!0,g(),h()});return r.observe(t),r.observe(e),h(),()=>{n.removeEventListener(`scroll`,h),window.removeEventListener(`resize`,h),r.disconnect(),c.current=null}},[h,g]),(0,I.useLayoutEffect)(()=>{g(),h()});let _=(0,I.useCallback)(e=>{let t=f();if(!t||!c.current)return;let n=qC(d.current.total,d.current.rowHeight,t.height);c.current.scrollTop+=YC(n,e)-t.position,h()},[f,h]),v=(0,I.useCallback)(()=>!p.current.pending,[]),y=iw(l,e,t),b=i?i(y.top):y.top,{first:x,last:S}=i?ZC(e,b,t,l.height,rw):y,C=Array.from({length:S-x+1},(e,t)=>({index:x+t,offset:XC(y.geometry,x+t,b,l.position)}));return{ref:s,height:l.height,top:b,geometry:y.geometry,rows:C,first:x,last:S,scrollTo:_,started:v}},ow=e=>e===`ArrowUp`||e===`ArrowDown`||e===`ArrowLeft`||e===`ArrowRight`,sw=(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},cw=(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)},lw=e=>`${e.index}:${e.column}`,uw=({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="${lw(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?cw(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":lw(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!==lw(o))return;let a=e.key===`Tab`?e.shiftKey?`ArrowLeft`:`ArrowRight`:e.key;if(ow(a)){let i=sw(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)}}},dw=({ids:e,rowAt:t,reorder:n,children:r})=>{let i=ne(Me(se,{activationConstraint:{distance:4}}),Me(xe,{activationConstraint:{delay:250,tolerance:5}}),Me(ae,{coordinateGetter:ye})),a=t=>e.indexOf(String(t)),o=e=>{let r=t(a(e));return r?n.label(r):Gp(`row`)};return(0,B.jsx)(me,{sensors:i,collisionDetection:ge,onDragEnd:({active:e,over:t})=>{t&&e.id!==t.id&&n.onMove(a(e.id),a(t.id))},accessibility:{announcements:{onDragStart:({active:t})=>Gp(`pickedUp`,{name:o(t.id),row:a(t.id)+1,rows:e.length}),onDragOver:({active:t,over:n})=>n?Gp(`isOver`,{name:o(t.id),row:a(n.id)+1,rows:e.length}):void 0,onDragEnd:({active:t,over:n})=>n?Gp(`droppedAt`,{name:o(t.id),row:a(n.id)+1,rows:e.length}):Gp(`putBack`,{name:o(t.id)}),onDragCancel:({active:e})=>Gp(`cancelled`,{name:o(e.id),row:a(e.id)+1})},screenReaderInstructions:{draggable:Gp(`reorderInstructions`)}},children:(0,B.jsx)(ue,{items:e,strategy:re,children:r})})},fw=({row:e,label:t,...n})=>{let{attributes:r,listeners:i,setNodeRef:a,setActivatorNodeRef:o,transform:s,transition:c,isDragging:l}=Te({id:e.id}),u=(0,B.jsx)(`button`,{ref:o,type:`button`,"aria-label":Gp(`move`,{label:t}),...r,...i,onClick:e=>e.stopPropagation(),style:{touchAction:`none`},className:`flex size-7 cursor-grab items-center justify-center rounded text-faint-foreground hover:bg-muted hover:text-foreground focus-visible:text-foreground active:cursor-grabbing pointer-coarse:size-9`,children:(0,B.jsx)(wa,{className:`size-4`})});return(0,B.jsx)(zC,{...n,rowRef:a,handle:u,dragY:s?.y??0,transition:c,dragging:l})},pw=32,mw=({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=!gf(),E=(h??(T?[]:vC(e))).join(` `),[D,O]=_C(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)(()=>eC(k),[k]),se=ne[0],ce=!!(!o&&n&&se&&se.id===n.columnId&&(se.desc?`desc`:`asc`)!==n.direction),le=t.rowAt,ue=(0,I.useCallback)(e=>le(ce?j-1-e:e),[le,ce,j]),[de]=(0,I.useState)(r),{ref:fe,geometry:pe,rows:me,first:he,last:ge}=aw({total:j,rowHeight:w,initialIndex:de,inset:pw,onScroll:i&&(e=>i(e/w))}),_e=T||!g?40:oC(j),ve=GC({total:j,rowAt:le?ue:void 0,loadRows:t.loadRows,revision:t.revision,latencyMs:a},he,ge),ye=(0,I.useCallback)(e=>{let t=ve(e),n=t&&f?.get(t.id);return n?{...t,...n}:t},[ve,f]),be=me.map(({index:e,offset:t})=>({index:e,offset:t,row:ye(e)})),xe=(0,I.useMemo)(()=>be.flatMap(({row:e})=>e?[e]:[]),[ye,he,ge]),Se=(0,I.useRef)(null),Ce=wC(Se),we=bC(k,xe),Te=(0,I.useMemo)(()=>SC(we,Ce.widths),[we,Ce.widths]),Ee=je({features:QS,columns:oe,data:xe,state:{sorting:ne,rowSelection:ie},onSortingChange:re,onRowSelectionChange:ae,manualSorting:!0,enableMultiSort:!1,enableSortingRemoval:!1,getRowId:e=>e.id}),De=new Map(Ee.getRowModel().rows.map(e=>[e.id,e])),Oe=Object.keys(ie).length,ke=(0,I.useRef)(new Map);for(let e of Ee.getRowModel().rows)e.getIsSelected()&&ke.current.set(e.id,e.original);let Ae=u&&u.length>0?40:0,Me=T?1:sC,Ne=fC(),M=()=>{Ne.onScroll(),Se.current&&Ne.ref.current&&(Se.current.scrollLeft=Ne.ref.current.scrollLeft)},[Pe,Fe]=(0,I.useState)({});(0,I.useLayoutEffect)(()=>{let e=Se.current?.querySelector(`[role=row]`);if(!e)return;let t=_e,n={};for(let r of A)n[r]=t,t+=e.querySelector(`[data-col-id="${r}"]`)?.offsetWidth??0;JSON.stringify(Pe)!==JSON.stringify(n)&&Fe(n)});let Ie=A.at(-1),Le=e=>O(D.includes(e)?D.filter(t=>t!==e):[...D,e]),Re=Ee.getHeaderGroups().flatMap(e=>e.headers.map(e=>({spec:k.find(t=>t.id===e.column.id),sorted:e.column.getIsSorted(),onSort:t=>e.column.getToggleSortingHandler()?.(t)}))),N=(0,I.useRef)(null),ze=uw({editor:d,columns:(0,I.useMemo)(()=>k.map(e=>e.id),[k]),total:j,rowAt:ye,onOpenRow:c,container:N}),Be=(k.find(e=>e.title)??k[0])?.id,Ve=dC(Te,_e,Ae,Me),He=x===`own`,Ue=(0,B.jsx)(`div`,{ref:Se,className:P(`sticky z-20 shrink-0 overflow-hidden`,He?`top-0`:`top-[var(--pb-sticky-top,0px)]`),children:(0,B.jsx)(`div`,{style:{minWidth:Ve},children:(0,B.jsx)(MC,{cells:Re,specs:Te,gutter:_e,trailing:Ae,minScale:Me,pins:Pe,lastPinned:Ie,scrolled:Ne.scrolled,onTogglePin:Le,resize:Ce,widths:Ce.widths,selectable:C,selectedCount:Oe,onClearSelection:()=>ae({})})})}),We=be.map(({index:e,offset:t,row:n})=>{let r={specs:Te,gutter:_e,index:e,offset:t,height:w,selectable:C,trailing:Ae,minScale:Me,scrolled:Ne.scrolled,pins:Pe,lastPinned:Ie},i=n?De.get(n.id):void 0;if(!i||!n)return(0,B.jsx)(VC,{...r},`skeleton-${e}`);let a=Ae?iC(u,n):[],o={...r,selected:i.getIsSelected(),onToggle:()=>i.toggleSelected(),onOpen:c?()=>c(n):void 0,menu:a.length>0?(0,B.jsx)(aC,{row:n,actions:a}):void 0,cells:i.getAllCells().map(t=>{let r=(0,B.jsx)(Ee.FlexRender,{cell:t}),i=!!d?.editable(n,t.column.id),a=l&&t.column.id===Be&&!i?(0,B.jsx)(Sh,{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)(fw,{...o,row:n,label:y.label(n)},n.id):(0,B.jsx)(zC,{...o},n.id)}),Ge=(0,B.jsx)(`div`,{ref:Ne.attach,onScroll:M,className:`overflow-x-auto overflow-y-hidden overscroll-x-contain [-webkit-overflow-scrolling:touch]`,children:(0,B.jsx)(`div`,{ref:fe,className:`relative`,style:{minWidth:Ve,height:pe.contentHeight},children:y?(0,B.jsx)(dw,{ids:Array.from({length:j},(e,t)=>ye(t)?.id??`missing-${t}`),rowAt:ye,reorder:y,children:We}):We})});return(0,B.jsxs)(`div`,{ref:N,role:`grid`,"aria-rowcount":j,onKeyDown:ze?.onKeyDown,className:P(`flex flex-col rounded-lg border bg-background`,He?`min-h-0 overflow-hidden`:`overflow-clip`,S),style:b&&He?{height:pw+j*w+2}:void 0,children:[(0,B.jsxs)(`div`,{className:P(`relative`,He&&`flex min-h-0 flex-1 flex-col`),children:[He?(0,B.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overflow-x-hidden`,children:[Ue,Ge]}):(0,B.jsxs)(B.Fragment,{children:[Ue,Ge]}),Ne.more&&(0,B.jsx)(`div`,{"aria-hidden":!0,className:`pointer-events-none absolute inset-y-0 right-0 z-20 w-8 bg-gradient-to-l from-backdrop/15 to-transparent`})]}),!b&&(0,B.jsx)(nC,{total:j,className:He?void 0:`sticky bottom-[var(--pb-sticky-bottom,0px)] z-20`,selectedCount:Oe,bulkActions:tC(p??[],Object.keys(ie).flatMap(e=>ke.current.get(e)??[])).map(({action:e,rows:t,skipped:n})=>({label:e.label(t.length),destructive:e.destructive,onRun:()=>{e.onRun(t,n),ae({}),ke.current.clear()}}))})]})},hw=500,gw=async(e,t,n)=>{let r=[],i={},a;do{let o=await e.search(t,{...n,pageSize:hw,...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}},_w=sn(),vw=(...e)=>{let t=e.filter(e=>!!e);return t.length===1?t[0]:t.map(e=>`(${e})`).join(` AND `)},yw=e=>e==null?void 0:String(e),bw=(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=yw(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},xw=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 gw(e,a.name,{filter:vw(Yt(_w.in(i.field,r)),i.filter),fields:[i.field,o]})).items.flatMap(e=>{let t=yw(e[i.field]),n=yw(e[o]);return t===void 0||n===void 0?[]:[[t,n]]})},Sw=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 xw(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=Cb(t,n,s,u),f=await gw(e,s.name,{filter:vw(Yt(_w.in(a.field,l)),a.filter),...a.sort&&{orderBy:a.sort},fields:u,labels:d});return bw(c,wb(t,s,u,f.items,f.labels),a.field)},Cw=5e3,ww=({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=Cb(n,r,i,a),f=Im(r[i.name]),p=async e=>e.nextPageToken===``?e.items.length:e.totalSizeEstimate>Cw?e.totalSizeEstimate:(await t.list(i.name,{filter:o,orderBy:s,pageSize:1,count:`exact`})).totalSize??e.totalSizeEstimate,m=async t=>{if(t===0)return``;let n=u(t-1),r=e.getQueryData(n);if(r)return r.nextPageToken;if(e.getQueryState(n)?.fetchStatus===`fetching`)return(await g(t-1)).nextPageToken},h=async l=>{let u=await m(l);if(l>0&&u===``)return{rows:[],total:0,nextPageToken:``};let h={filter:o,orderBy:s,pageSize:40,labels:d,photos:f},g=u===void 0?await t.seek(i.name,{...h,position:l*40}):await t.list(i.name,{...h,pageToken:u});if(g.items.length===0&&l>0)return{rows:[],total:0,nextPageToken:``};let _=g.items.map(e=>vm(i,e)),v=wb(n,i,a,Lm(i,g.items,g.photos),g.labels),[y]=await Promise.all([Promise.all(c.map(e=>Sw({client:t,resources:n,views:r,load:e,owners:_}))),kb(e,t,n,r,i,a,g.items)]);return{rows:v.map((e,t)=>({...e,...Object.fromEntries(c.map((e,n)=>[e.column.name,y[n].get(_[t])??[]])),id:_[t]})),total:l===0?await p(g):g.totalSizeEstimate,nextPageToken:g.nextPageToken}},g=t=>e.fetchQuery({queryKey:u(t),staleTime:6e4,queryFn:()=>h(t)});return{page:g,loadRows:async e=>(await g(Math.floor(e/40))).rows}},Tw=({resources:e,views:t,model:n,columns:r,filter:i,orderBy:a,related:o})=>{let s=U(),c=Se(),l=r.join(`,`),u=JSON.stringify(o??[]),d=(0,I.useMemo)(()=>ww({queryClient:c,client:s,resources:e,views:t,model:n,columns:r,filter:i,orderBy:a,...o&&{related:o}}),[c,s,e,t,n,l,i,a,u]),f=E({queryKey:[...H.first(n.name,i,a),l],queryFn:async()=>(await c.invalidateQueries({queryKey:H.pages(n.name,i,a),refetchType:`none`}),d.page(0))});return{source:(0,I.useMemo)(()=>f.data?{total:f.data.total,loadRows:d.loadRows,revision:f.dataUpdatedAt}:void 0,[f.data,f.dataUpdatedAt,d]),error:f.error,isLoading:f.isLoading,page:d.page,key:[...H.first(n.name,i,a),l]}},Y=M(`app/searches`),Ew=`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`,Dw=({chips:e,className:t})=>(0,B.jsx)(`ul`,{className:P(`flex flex-wrap gap-1.5`,t),"aria-label":Y(`filters`),children:e.map(e=>(0,B.jsx)(`li`,{className:Ew,children:e.label},e.key))}),Ow=({chips:e})=>(0,B.jsx)(`span`,{className:`flex flex-wrap gap-1.5`,children:e.map((e,t)=>(0,B.jsxs)(`span`,{className:Ew,children:[t>0&&(0,B.jsx)(`span`,{className:`sr-only`,children:`, `}),e.label]},e.key))}),kw=e=>e.map(e=>e.label).join(`, `),Aw=M(`filter-panel`),jw=`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`,Mw=({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)(no,{className:`size-3 text-muted-foreground`}),e]},e)),e.map(e=>(0,B.jsxs)(`span`,{className:jw,children:[e.label,(0,B.jsx)(`button`,{type:`button`,"aria-label":Aw(`remove`,{label:e.label}),onClick:()=>n(e.key),className:`rounded-full p-0.5 hover:bg-primary-border/60`,children:(0,B.jsx)(yc,{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:Aw(`clearAll`)})]}),Nw=[`today`,`7d`,`30d`,`year`],Pw=new Set([`today`,`yesterday`,`24h`,`7d`,`30d`,`90d`,`month`,`quarter`,`year`]),Fw=e=>Pw.has(e)?Aw(e):void 0,Iw=({value:e,presets:t=Nw,onChange:n})=>(0,B.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:t.map(t=>{let r=Fw(t);return(0,B.jsx)(`button`,{type:`button`,disabled:!r,title:r?void 0:Aw(`unknownPreset`,{id:t}),onClick:()=>n(e===t?void 0:t),className:P(`h-7 rounded-md border px-2.5 text-body font-medium transition-colors`,!r&&`border-dashed text-danger-text`,e===t?`border-primary-border bg-primary-soft text-primary-text`:`border-border-strong bg-background text-muted-foreground hover:bg-muted`),children:r??Aw(`unsupported`,{id:t})},t)})}),Lw={facets:{},toggles:[]},Rw=(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}}},zw=(e,t)=>({...e,toggles:e.toggles.includes(t)?e.toggles.filter(e=>e!==t):[...e.toggles,t]}),Bw=(e,t,n)=>{let{[t]:r,...i}=e.ranges??{};return{...e,ranges:n?{...i,[t]:n}:i}},Vw=(e,t)=>e.options.find(e=>e.value===t)?.label??e.labels?.[t]??t,Hw=(e,t)=>{let n=e.facets.flatMap(e=>(t.facets[e.id]??[]).map(t=>({key:`facet:${e.id}:${t}`,label:`${e.label}: ${Vw(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:Fw(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]},Uw=(e,t)=>{if(t===`date`)return{...e,date:void 0};let[n,r,i]=t.split(`:`);if(n===`range`)return Bw(e,r,void 0);if(n===`toggle`)return zw(e,r);if(n===`facet`)return Rw(e,r,i);throw Error(`Unknown filter chip key: ${t}`)},Ww=(e,t)=>e.toLowerCase().includes(t.trim().toLowerCase()),Gw=(e,t)=>e.onSearch?e.options:e.options.filter(e=>Ww(e.label,t)),Kw=(e,t,n)=>t===0?-1:n===`ArrowDown`?e<0?0:(e+1)%t:e<0?t-1:(e-1+t)%t,qw=({config:e,selected:t,onToggle:n,inline:r=!1})=>{let i=(0,I.useId)(),a=(0,I.useRef)(null),[o,s]=(0,I.useState)(``),[c,l]=(0,I.useState)(!1),[u,d]=(0,I.useState)(-1),f=r||c,p=Gw(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)(ss,{className:`size-3.5 shrink-0 text-muted-foreground`}),t.map(t=>(0,B.jsx)(X_,{label:Vw(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?``:Aw(`searchIn`,{label:e.label}),className:`h-6 min-w-16 flex-1 bg-transparent text-foreground outline-none placeholder:text-faint-foreground`,value:o,onChange:e=>h(e.target.value),onKeyDown:e=>{if(e.key===`ArrowDown`||e.key===`ArrowUp`){e.preventDefault(),d(Kw(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)(Si,{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:wp(e.count)})]},e.value)}),p.length===0&&(0,B.jsx)(`li`,{className:`px-1.5 py-1 text-xs text-faint-foreground`,children:Aw(`noMatches`)})]})]})},Jw=({config:e,selected:t,onToggle:n})=>{let[r,i]=(0,I.useState)(``),a=e.options.filter(e=>Ww(e.label,r));return(0,B.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[e.searchable&&(0,B.jsx)(J,{wrapperClassName:`mb-1 h-7`,leading:(0,B.jsx)(ss,{className:`size-3.5`}),placeholder:Aw(`searchIn`,{label:e.label}),value:r,onChange:e=>i(e.target.value)}),a.map(e=>(0,B.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 rounded px-1 py-1 hover:bg-muted`,children:[(0,B.jsx)(TC,{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:wp(e.count)})]},e.value)),a.length===0&&(0,B.jsx)(`span`,{className:`px-1 py-1 text-xs text-faint-foreground`,children:Aw(`noMatches`)})]})},Yw=({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)(wi,{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})]})},Xw=({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]}),Zw=(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}},Qw=({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":Aw(`moreFilters`),onKeyDown:t=>{if(t.key===`Escape`)return n();let i=Zw(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:eg,onClick:()=>{n(),t(e.key)},children:e.label})},e.key))})},$w=({items:e,onPick:t})=>e.length===0?null:(0,B.jsx)(Yw,{label:Aw(`moreFilters`),activeCount:0,children:n=>(0,B.jsx)(Qw,{items:e,onPick:t,close:n})}),eT=(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},tT=(e,t,n,r,i)=>{let a=n+(r-n)*e/t;return n+(r-n)*(e+1)/t>i[0]&&a<i[1]},nT=(e,t,n)=>n===t?0:(e-t)/(n-t),rT=(e,t,n)=>t===0?[Math.min(n,e[1]),e[1]]:[e[0],Math.max(n,e[0])],iT=1e3,aT=({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=eT(c,iT);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`,tT(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:`${nT(u[0],r,i)*100}%`,right:`${100-nT(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":Aw(t===0?`minimum`:`maximum`,{label:e.label}),min:r,max:i,step:a,value:u[t],onChange:e=>l(rT(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])})]})]})},oT=e=>[...new Set(e.map(e=>e.key.split(`:`).slice(0,2).join(`:`)))],sT=(e,t)=>{let n=t.filter(t=>!e.includes(t));return n.length===0?e:[...e,...n]},cT=(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:Aw(`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}},lT=({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)(Vg,{checked:t,onChange:n,label:e})]}),uT=(e,t)=>e.some(e=>e.length>0)||!!t,dT=({groups:e,trailing:t})=>{if(!uT(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})]})},fT=(e,t,n)=>{let[r,i]=(0,I.useState)(t??Lw);return[e??r,e=>{i(e),n?.(e)}]},pT=({config:e,layout:t,value:n,defaultValue:r,onChange:i,lockedLabels:a,defaultOpenMenu:o,fullWidth:s,leading:c,trailing:l})=>{let[u,d]=fT(n,r,i),f=Hw(e,u),p=oT(f),[m,h]=(0,I.useState)(()=>p),[g,_]=(0,I.useState)();(0,I.useEffect)(()=>h(e=>sT(e,p)),[p.join(`,`)]);let v=(0,B.jsx)(Mw,{chips:f,lockedLabels:a,onRemove:e=>d(Uw(u,e)),onClear:()=>d(Lw)}),y=(e,t=!1)=>{let n=u.facets[e.id]??[],r=t=>d(Rw(u,e.id,t));return e.combobox?(0,B.jsx)(qw,{config:e,selected:n,onToggle:r,inline:t}):(0,B.jsx)(Jw,{config:e,selected:n,onToggle:r})},b=e.ranges??[],x=e=>(0,B.jsx)(aT,{config:e,value:u.ranges?.[e.id],onChange:t=>d(Bw(u,e.id,t))}),S=e.datePresets&&(0,B.jsx)(Iw,{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)(lT,{label:e.label,checked:u.toggles.includes(e.id),onChange:()=>d(zw(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:Aw(`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)(Xw,{title:e.label,children:y(e)},e.id)),b.map(e=>(0,B.jsx)(Xw,{title:e.label,children:x(e)},e.id)),S&&(0,B.jsx)(Xw,{title:Aw(`date`),children:S}),C.length>0&&(0,B.jsx)(Xw,{title:Aw(`showOnly`),children:C})]});let{shown:w,more:T}=cT(e,m),E=e=>{h(t=>sT(t,[e])),_(e)},D=[...e.facets.filter(e=>w.has(`facet:${e.id}`)).map(e=>(0,B.jsx)(Yw,{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)(Yw,{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)(lT,{label:e.label,checked:u.toggles.includes(e.id),onChange:()=>d(zw(u,e.id))})},e.id)),k=[c?[(0,B.jsx)(I.Fragment,{children:c},`leading`)]:[],D,O,T.length>0?[(0,B.jsx)($w,{items:T,onPick:E},`more`)]:[]];return!uT(k,l)&&f.length===0&&!a?.length?null:(0,B.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,B.jsx)(dT,{groups:k,trailing:l}),v]})},mT=sn(),hT={start:0,end:0},gT={"24h":{amount:24,unit:`h`},"7d":{amount:7,unit:`d`},"30d":{amount:30,unit:`d`},"90d":{amount:90,unit:`d`}},_T=e=>new Date(e).toISOString().replace(`.000Z`,`Z`),vT=(e,t,n)=>{let r=Zf(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},yT=[`year`,`quarter`,`month`,`yesterday`,`today`],bT=(e,t,n)=>t===`date`?e:_T($f(e,n)),xT=(e,t,n)=>t===`date`?{kind:`string`,value:bT(e,t,n),span:hT}:{kind:`timestamp`,value:bT(e,t,n),span:hT},ST=(e,t,n,r,i)=>{if(t in gT)return[mT.gte(e,mT.ago(t))];let a=mT.gte(e,xT(vT(t,n,i),r,i));return t===`yesterday`?[a,mT.lt(e,xT(vT(`today`,n,i),r,i))]:[a]},CT=(e,t,n=new Date,r=Gf())=>{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=>mT.eq(e.value,!0));return t.length===0?[]:[t.length===1?t[0]:mT.or(...t)]}return[n.length===1?mT.eq(e.id,n[0]):mT.in(e.id,n)]}),a=(e.ranges??[]).flatMap(e=>{let n=t.ranges?.[e.id];return n?[mT.gte(e.id,n[0]),mT.lte(e.id,n[1])]:[]}),o=e.dateField&&t.date?ST(e.dateField,t.date,n,e.dateKind,r):[],s=(e.toggles??[]).filter(e=>t.toggles.includes(e.id)).map(e=>mT.eq(e.id,!0));return[...i,...a,...o,...s]},wT=e=>e.length===0?``:Yt(mT.and(...e)),TT=(e,t,n=[],r=new Date,i=Gf())=>wT([...CT(e,t,r,i),...n]),ET=e=>e.kind===`and`?e.args.flatMap(ET):[e],DT=e=>e.field.path.join(`.`),OT=e=>e.kind===`compare`&&e.op===`=`&&e.value.kind===`boolean`&&e.value.value,kT=(e,t)=>{let n=e.kind===`or`?e.args:[e];if(!n.every(OT))return;let r=n.map(DT),i=t.get(r[0]);return i!==void 0&&r.every(e=>t.get(e)===i)?{group:i,fields:r}:void 0},AT=e=>e.kind===`number`?String(e.raw):e.kind===`string`?String(e.value):void 0,jT=(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(gT).find(([,n])=>n.amount===e&&n.unit===t)?.[0]}if(r.kind===`timestamp`)return yT.find(e=>bT(vT(e,t,n),`timestamp`,n)===r.value);if(r.kind===`string`)return yT.find(e=>vT(e,t,n)===r.value)},MT=(e,t,n=new Date,r=Gf())=>{let i=it(t);if(!i.ok)return{ok:!1,errors:i.errors};let a={facets:{},toggles:[]},o=[],s=new Set(e.facets.filter(e=>!e.flags).map(e=>e.id)),c=new Map(e.facets.filter(e=>e.flags).flatMap(e=>e.options.map(t=>[t.value,e.id]))),l=new Set((e.toggles??[]).map(e=>e.id)),u=new Set((e.ranges??[]).map(e=>e.id)),d=new Map,f,p;for(let t of i.ast?ET(i.ast):[]){let i=kT(t,c);if(i&&!a.facets[i.group])a.facets[i.group]=i.fields;else if(t.kind===`compare`&&s.has(DT(t))&&t.op===`=`&&AT(t.value)!==void 0)a.facets[DT(t)]=[...a.facets[DT(t)]??[],AT(t.value)];else if(t.kind===`in`&&s.has(DT(t))&&t.values.every(e=>AT(e)!==void 0))a.facets[DT(t)]=[...a.facets[DT(t)]??[],...t.values.map(e=>AT(e))];else if(t.kind===`compare`&&e.dateField===DT(t)&&t.op===`>=`&&jT(t,n,r)&&!a.date)a.date=jT(t,n,r),f=t;else if(t.kind===`compare`&&e.dateField===DT(t)&&t.op===`<`&&(t.value.kind===`timestamp`||t.value.kind===`string`)&&t.value.value===bT(vT(`today`,n,r),t.value.kind===`string`?`date`:`timestamp`,r))p=t;else if(t.kind===`compare`&&l.has(DT(t))&&t.op===`=`&&t.value.kind===`boolean`&&t.value.value)a.toggles.push(DT(t));else if(t.kind===`compare`&&u.has(DT(t))&&(t.op===`>=`||t.op===`<=`)&&t.value.kind===`number`){let e=d.get(DT(t))??{clauses:[]};t.op===`>=`?e.low=t.value.value:e.high=t.value.value,e.clauses.push(t),d.set(DT(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}},NT=[`integer`,`bigint`,`decimal`],PT=(e,t)=>{let n=e?.fields[t]?.type;return n!==void 0&&NT.includes(n)},FT=(e,t)=>e.kind===`range`||e.kind===`facets`&&PT(t,e.field),IT=e=>e.secondary?{secondary:!0}:{},LT=e=>({id:e.field,label:e.field,min:0,max:0,step:1,histogram:[],format:String,...IT(e)}),RT=(e,t)=>{let n=e?.filters??[],r=n.find(e=>e.kind===`dateRange`);return{facets:n.flatMap(e=>e.kind===`facets`&&!FT(e,t)?[{id:e.field,label:e.field,options:[],searchable:e.search,...t?.fields[e.field]?.type===`relation`&&{combobox:!0},...IT(e)}]:e.kind===`flags`?[{id:e.fields.join(`|`),label:e.label,options:e.fields.map(e=>({value:e,label:e,count:0})),flags:!0,...IT(e)}]:[]),ranges:n.flatMap(e=>e.kind!==`flags`&&FT(e,t)?[LT(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,...IT(e)}]:[])}},zT=(e,t)=>(e?.filters??[]).some(e=>e.kind===`range`&&e.field===t&&e.histogram),BT=(e,t)=>{let n=e?.fields[t],r=n?.suffix??``,i=n?.currency;return i===void 0?e=>`${n?.prefix??``}${e}${r}`:e=>`${kp(e*100,i).replace(`.00`,``)}${r}`},VT=sn(),HT={start:0,end:0},UT=(e,t,n)=>{let r=MT(RT(t,e),n);return r.ok?Object.fromEntries(Object.entries(r.state.facets).filter(([t,n])=>e.fields[t]?.type===`relation`&&n.length>0)):{}},WT=(e,t,n)=>{let r=e=>t?.fields[e]?.label??F(e),i=RT(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,ir(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:BT(t,e.id)})),toggles:i.toggles?.map(e=>({...e,label:r(e.id)}))}},GT=(e,t,n,r={})=>{let i=WT(e,t,r),a=MT(i,n);if(!a.ok)return[{key:`unreadable`,label:Y(`unreadableFilter`)}];let o=a.extras.map((e,t)=>({key:`extra:${t}`,label:e.kind===`search`?`"${e.text}"`:Yt(e)}));return[...Hw(i,a.state),...o]},KT=e=>Object.fromEntries(e.facets.filter(e=>!e.flags).map(e=>[e.id,{...e.labels,...Object.fromEntries(e.options.map(e=>[e.value,e.label]))}])),qT=(e,t,n)=>{if(typeof n!=`string`||n===``)return e;let r=VT.gt(t,{kind:`timestamp`,value:new Date(n).toISOString(),span:HT}),i=it(e);if(!i.ok)throw Error(`The saved filter cannot be read: ${i.errors.map(e=>e.message).join(`; `)}`);return Yt(i.ast?VT.and(i.ast,r):r)},JT=(e,t)=>typeof t!=`string`||t===``?!0:typeof e!=`string`||e===``?!1:new Date(e).getTime()>new Date(t).getTime(),YT=(e,t)=>{let n=U(),r=Se(),{resources:i,views:a}=W(),o=a[e.name],s=Object.entries(UT(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 xb(r,n,s,o,a[s.name]))}})});return GT(e,o,t,Object.fromEntries(s.flatMap(([e],t)=>c[t]?.data?[[e,c[t].data]]:[])))},XT=(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}}),ZT=e=>{let t=Se();return(0,I.useCallback)(n=>t.setQueryData(H.recordPreview(e.name,Nn(ym(e,n))),XT(e,n)),[t,e])},QT={wallet:dc,"file-text":Sa,send:ds,ruler:as,bed:Xr,bath:Jr,house:Aa,"door-open":ea,"land-plot":Ra,leaf:Ka,tag:Vs,key:Ia,calendar:gi,heart:Oa,bell:ni,bookmark:ui,"external-link":ua,ban:Kr,play:Uo,stop:js,power:Yo,restart:rs,terminal:Gs,camera:vi,"hard-drive":Ea,server:ps,network:jo,archive:Mr,copy:Ji,"arrow-right-left":Ir,download:na,upload:Zs,cpu:Xi,memory:po,plug:Go,wrench:_c},$T=e=>e!==void 0&&Object.hasOwn(QT,e)?QT[e]:void 0,eE=({target:e,id:t})=>(0,B.jsx)(B.Fragment,{children:Mb(e,t)??t}),tE=()=>{let{path:e,params:t,basePath:n,navigate:r}=jh(),i=(0,I.useMemo)(()=>$c(e,t),[e,t]),a=wd(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(Qc({step:e,next:o}),t),[r,o]);return{address:i,next:o,open:s,link:(0,I.useCallback)((e=`sign-in`,t)=>({href:`${n}${Qc({step:e,next:o})}`,onFollow:()=>s(e,t)}),[n,o,s]),leave:(0,I.useCallback)(()=>r(o??`/`,{replace:!0}),[r,o])}},nE=({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)(Si,{className:`mt-0.5 size-4 shrink-0 text-primary`,"aria-hidden":!0}),e]},e))}):null,rE=({prompt:e})=>{let{canSignUp:t}=V(),{link:n}=tE(),r=mf({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)(Sh,{to:n(`sign-up`),className:r,children:z(`createAnAccount`)});return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(Sh,{to:n(),className:i?mf():r,children:z(`signIn`)}),i]})},iE=e=>{let{prompt:t}=e,n=(0,I.useId)();if(e.as===`dialog`)return(0,B.jsx)(Ef,{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)(rE,{prompt:t})]}),children:(0,B.jsx)(nE,{benefits:t.benefits})});let r=$T(t.icon)??io;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)(nE,{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)(rE,{prompt:t})})]})},aE=sn(),oE=e=>{if(typeof e==`string`||typeof e==`number`)return e;if(e&&typeof e==`object`&&`id`in e)return oE(e.id)},sE=(e,t,n)=>n.flatMap(n=>{let r=oE(n[t]);return r===void 0?[]:[{key:Nn(ym(e,n)),target:r}]}),cE=(e,t)=>e.find(e=>Nn(e.target)===t),lE=(e,t)=>[...e,{key:``,target:t}],uE=(e,t)=>e.filter(e=>Nn(e.target)!==t),dE=(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:aE.in(n,r)},fE=(e,t)=>H.list(e,``,``,500,`saved:${t}`),pE=(e,t,n)=>{let r=U(),i=W().resources[e];return E({queryKey:fE(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 sE(i,t,n)}})},mE=M(`app/saved`),hE=e=>e instanceof Error?e.message:mE(`somethingWrong`),gE=(e,t,n)=>{let r=W(),i=U(),a=Se(),s=iy(),c=Cy(),{resource:l,field:u}=e,d=r.permissions[l],f=r.resources[l]!==void 0&&d!==void 0&&oy(d,`create`)&&oy(d,`delete`),p=r.signIn?.[l]?.signIn,m=pE(l,u,f),h=m.data&&cE(m.data,t),g=fE(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?uE(r,t):lE(r,n)),{before:r}},onError:(e,t,n)=>{a.setQueryData(g,n?.before),s.show({state:`error`,title:mE(t?`couldNotTakeOff`:`couldNotSave`),description:hE(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)}},_E=({favorite:e,recordKey:t,target:n,className:r})=>{let i=gE(e,t,n),[a,o]=(0,I.useState)(!1);if(!i.mode)return null;let s=e.label??mE(`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)(Oa,{className:`size-4`,"aria-hidden":!0})}),(0,B.jsx)(iE,{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)(Oa,{className:P(`size-4`,i.saved&&`fill-current text-danger`),"aria-hidden":!0})})},vE=6,yE=(e,t,n)=>{let r=e.bottom+vE;return{top:r+t.height>n.height-vE?Math.max(vE,e.top-vE-t.height):r,left:Math.max(vE,Math.min(e.left,n.width-vE-t.width))}},bE=(e,t)=>{let n=Wm(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},xE=(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:oh(r,n[r.name],bE(n[r.name],e.status))}]:[]}),SE=M(`app/related-dots`),CE=(e,{values:t,label:n,singular:r,plural:i})=>{if(e.length===0)return SE(`none`,{plural:i});let a=new Map;for(let t of e)t!=null&&a.set(String(t),(a.get(String(t))??0)+1);let o=[...t,...[...a.keys()].filter(e=>!t.includes(e))].filter(e=>a.has(e)).map(e=>`${a.get(e)} ${n(e)}`),s=`${e.length} ${e.length===1?r:i}`;return o.length===0?s:`${s}: ${o.join(`, `)}`},wE=`flex shrink-0 items-center justify-center rounded-full p-0.5 pointer-coarse:p-1.5`,TE=`size-2.5 rounded-full`,EE=`flex min-w-0 items-center gap-0.5`,DE=150,OE=288,kE=({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(yE(e.dot,{width:OE,height:c.current.offsetHeight},{width:window.innerWidth,height:window.innerHeight}))},[e]),(0,Sc.createPortal)((0,B.jsx)(`div`,{ref:c,"data-dot-card":!0,onMouseEnter:o,onMouseLeave:s,style:{width:OE,...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:bE(r,i.status),row:t})}),document.body)},AE=({column:e,records:t,target:n,view:r,wrap:i=!1,Card:a})=>{let o=(0,I.useMemo)(()=>t.map(e=>uh(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?Nm(f,t.record[e.status],p):``,h=cr(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=CE(o.map(t=>t.record[e.status]),{values:f?.enumValues??[],label:e=>f?Nm(f,e,p):e,singular:_,plural:v}),b=()=>window.clearTimeout(l.current),x=()=>{b(),l.current=window.setTimeout(()=>c(void 0),DE)},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(EE,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=Tm(p?.valueColors,r);return(0,B.jsx)(Uh,{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(wE,`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(TE,i===void 0&&Mf[Em(p?.valueColors,r)],s?.key===t.key&&`ring-2 ring-foreground/30`)})},t.key)}),s&&T&&(0,B.jsx)(kE,{shown:s,row:T,target:n,view:r,column:e,Card:a,onEnter:b,onLeave:x})]})},jE=({count:e})=>(0,B.jsx)(`span`,{"aria-hidden":!0,className:P(EE,`invisible flex-wrap`),children:Array.from({length:e},(e,t)=>(0,B.jsx)(`span`,{className:wE,children:(0,B.jsx)(`span`,{className:TE})},t))}),ME=`flex flex-col gap-1.5`,NE=({dots:e})=>(0,B.jsx)(`span`,{className:ME,children:e.map(({column:e,records:t})=>(0,B.jsx)(jE,{count:t.length},e.name))}),PE=({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)] ${ME}`,children:e.map(({column:e,records:i})=>{let a=n[e.resource];return a&&(0,B.jsx)(AE,{column:e,records:i,target:a,view:r[a.name],Card:t,wrap:!0},e.name)})})},FE=(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}]:[]}),IE=M(`carousel`),LE=`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`,RE=`[@media(hover:none)]:opacity-100`,zE=({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":IE(`previousPhoto`),className:P(LE,r,!n&&RE,`left-2`),onClick:()=>o(-1),children:(0,B.jsx)(Ei,{className:`size-4`,"aria-hidden":!0})}),(0,B.jsx)(`button`,{type:`button`,"aria-label":IE(`nextPhoto`),className:P(LE,r,!n&&RE,`right-2`),onClick:()=>o(1),children:(0,B.jsx)(Oi,{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:IE(`photoOf`,{index:a+1,count:t})}),(0,B.jsx)(`span`,{className:`flex items-center gap-1 rounded-full bg-background/70 px-1.5 py-1 leading-none`,"aria-hidden":!0,children:Array.from({length:t},(e,t)=>(0,B.jsx)(`span`,{className:P(`size-1.5 rounded-full`,t===a?`bg-foreground`:`bg-foreground/35`)},t))})]})]})},BE=({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))}),VE=(e,t)=>t===0?0:(e%t+t)%t,HE=(e,t,n)=>t<=0||n===0?0:Math.min(n-1,Math.max(0,Math.round(e/t))),UE=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=VE((n.current??r)+t,e),a(n.current)},touch:()=>{n.current=void 0},scrolled:t=>{i(HE(t.scrollLeft,t.clientWidth,e)),n.current!==void 0&&Math.abs(t.scrollLeft-n.current*t.clientWidth)<1&&(n.current=void 0)}}},WE=({value:e})=>{let t=Vp(e,{width:320,height:240});return t?(0,B.jsx)(j_,{image:t,loading:`lazy`,className:`size-full object-cover`}):null},GE=({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}),KE=({value:e})=>(0,B.jsx)(GE,{children:(0,B.jsx)(WE,{value:e})}),qE=10,JE=(e,t)=>{let n=jp(e)?e.uri:void 0,r=t.filter(e=>jp(e)&&e.uri!==n);return(n===void 0?r:[e,...r]).slice(0,qE)},YE=({photos:e,cover:t,swipe:n=!0,children:r})=>{let i=JE(t,e),a=UE(i.length),o=(0,B.jsx)(GE,{children:(0,B.jsx)(BE,{"data-card-photos":!0,carousel:a,swipe:n,slides:i.map(e=>(0,B.jsx)(WE,{value:e}))})});return(0,B.jsxs)(B.Fragment,{children:[r(o),(0,B.jsx)(zE,{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]`})]})},XE=({icon:e,children:t})=>{let n=$T(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]})},ZE=({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}=th(e,t,n),m=e=>t?.fields[e]?.label??F(e),{resources:h,views:g}=W(),_=n=>{let i=e.fields[n];if(!i)return``;let a=r.record[n],o=i.type===`relation`&&i.relation?h[i.relation.resource]:void 0;return o&&g[o.name]?.titleFrom&&a!=null?(0,B.jsx)(eE,{target:o,id:String(a)}):r.labels[n]===void 0&&gm(i,t?.fields[n])&&typeof a==`string`&&a!==``?hm(a):r.labels[n]??Nm(i,a,t?.fields[n])},{fields:v,components:y}=c_(),b=ZT(e),x=n.card===void 0?void 0:y?.[n.card],S=n=>{let i=e.fields[n],a=i&&ev(v,i,t?.fields[n]);return a?(0,B.jsx)(dv,{shown:a,part:`display`,field:i,value:r.record[n],fallback:_(n)}):_(n)},C=n=>{let i=e.fields[n],a=r.record[n];return!i||!gm(i,t?.fields[n])||ev(v,i,t?.fields[n])||typeof a!=`string`||a===``?S(n):(0,B.jsx)(pv,{source:a,inLink:!0})},w=n=>{let i=e.fields[n],a=t?.fields[n],o=r.record[n];return!i||a?.format!==`badge`||ev(v,i,a)||o==null||o===``?S(n):(0,B.jsx)(Nb,{value:o,hints:a,children:_(n)})},T=n=>{let i=e.fields[n];if(!i)return;if(r.labels[n]!==void 0||ev(v,i,t?.fields[n]))return(0,B.jsx)(`strong`,{className:`font-semibold text-foreground`,children:S(n)});let a=ih(i,r.record[n],t?.fields[n]);return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`strong`,{className:`font-semibold text-foreground`,children:a.amount}),a.suffix]})},E=x?void 0:n.photos,D=u===void 0?void 0:r.record[u],O=p.filter(e=>r.record[e]===!0),k=o===void 0?void 0:r.record[o],A=rh(r,l),j=nh(r,f),ee=o!==void 0||E!==void 0,te=n.favorite,ne=x?[]:FE(t,n,r),re=e=>(0,B.jsxs)(B.Fragment,{children:[ee&&e,(0,B.jsxs)(`span`,{className:`flex items-start justify-between gap-2 ${te&&!ee?`pr-8`:``}`,children:[(0,B.jsx)(`span`,{className:`min-w-0 truncate font-medium`,children:S(s)}),u!==void 0&&D!=null&&(0,B.jsx)(Nb,{value:D,hints:t?.fields[u],children:_(u)})]}),c!==void 0&&(0,B.jsx)(`span`,{className:t?.fields[c]?.markdown?`line-clamp-3 break-words text-muted-foreground`:t?.fields[c]?.multiline?`line-clamp-3 whitespace-pre-line break-words text-muted-foreground`:`truncate text-muted-foreground`,children:C(c)}),A!==void 0&&(0,B.jsx)(`span`,{className:`truncate tabular-nums text-muted-foreground`,children:T(A)}),d.length>0&&(0,B.jsx)(`dl`,{className:`mt-auto flex flex-wrap items-center gap-x-3 gap-y-0.5 pt-1 text-xs text-muted-foreground`,children:nh(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)(XE,{icon:t?.fields[e]?.icon,children:w(e)})]},e))}),O.length>0&&(0,B.jsx)(`ul`,{className:`flex flex-wrap gap-1`,"aria-label":K(`features`),children:O.map(e=>(0,B.jsx)(`li`,{children:(0,B.jsx)(Pf,{dot:!1,children:m(e)})},e))}),j.length>0&&(0,B.jsx)(`span`,{className:`truncate text-xs text-muted-foreground ${d.length>0?``:`mt-auto`}`,children:j.map((e,t)=>(0,B.jsxs)(`span`,{children:[t>0&&(0,B.jsx)(`span`,{"aria-hidden":!0,children:` • `}),S(e)]},e))}),ne.length>0&&(0,B.jsx)(NE,{dots:ne})]}),ie=t=>(0,B.jsxs)(Uh,{to:{kind:`record`,resource:e.name,key:r.key},onClick:()=>b(r.record),className:`flex h-full flex-col gap-1.5 rounded-lg border border-border bg-background p-3 hover:border-border-strong hover:bg-surface focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/30`,children:[a&&!ee&&(0,B.jsx)(Pf,{tone:`blue`,className:`self-start`,children:a}),x?(0,B.jsx)(cv,{name:n.card,fallback:re(t),children:(0,B.jsx)(x,{row:r})}):re(t)]});return(0,B.jsxs)(`div`,{className:E?`group/card relative h-full`:te||a||ne.length>0?`relative h-full`:`h-full`,children:[E?(0,B.jsx)(YE,{photos:r.photos??[],cover:k,swipe:i,children:ie},r.key):ie((0,B.jsx)(KE,{value:k})),a&&ee&&(0,B.jsx)(Pf,{tone:`blue`,className:`pointer-events-none absolute top-2 left-2 shadow-sm`,children:a}),ne.length>0&&(0,B.jsx)(PE,{dots:ne,Card:ZE}),te&&(0,B.jsx)(_E,{favorite:te,recordKey:r.key,target:ym(e,r.record),className:ee?void 0:`right-1.5 top-1.5`})]})},QE=268,$E=3,eD=(e,t,n)=>{let r=Math.floor(Math.max(0,e)/QE),i=Math.ceil((Math.max(0,e)+t)/QE);return{start:Math.max(0,r-$E),end:Math.min(n,i+$E)}},tD=e=>e*QE,nD=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]=[eD(t.left,t.width,e),eD(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,tD(e)-12),a=e=>t.current?.scrollBy({left:e*Math.max(tD(1),n.width-12),behavior:`smooth`});return{ref:t,...eD(n.left,n.width,e),back:n.left>0,on:n.left+n.width<i-1,page:a}},rD=M(`app/record-row`),iD=`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`,aD=({cards:e})=>e>0?(0,B.jsx)(`li`,{"aria-hidden":!0,className:`shrink-0`,style:{width:tD(e)-12}}):null,oD=({model:e,view:t,display:n,source:r,label:i,isNew:a})=>{let{total:o}=r,s=nD(o),c=GC({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)(aD,{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)(vh,{className:`h-full min-h-24 rounded-lg`})},`skeleton-${r}`);let s=uh(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)(ZE,{model:e,view:t,display:n,row:s,swipe:!1,mark:a?.(s)?rD(`new`):void 0})},s.key)}),(0,B.jsx)(aD,{cards:o-s.end})]}),s.back&&(0,B.jsx)(`button`,{type:`button`,"aria-label":rD(`previous`,{label:i.toLowerCase()}),onClick:()=>s.page(-1),className:`${iD} -left-3`,children:(0,B.jsx)(Ei,{className:`size-4`,"aria-hidden":!0})}),s.on&&(0,B.jsx)(`button`,{type:`button`,"aria-label":rD(`next`,{label:i.toLowerCase()}),onClick:()=>s.page(1),className:`${iD} -right-3`,children:(0,B.jsx)(Oi,{className:`size-4`,"aria-hidden":!0})})]})},sD=sn(),cD=(e,t)=>{if(!t)return e;let n=it(e);if(!n.ok)throw Error(`The filter cannot be read: ${n.errors.map(e=>e.message).join(`; `)}`);return Yt(n.ast?sD.and(n.ast,t):t)},lD=(e,t)=>{let n=Wm(e).filter(e=>e.kind===`cards`);return n.find(e=>e.name===t)??n[0]??{kind:`cards`,name:`cards`}},uD=()=>(0,B.jsx)(`div`,{className:`flex gap-3 overflow-hidden`,children:Array.from({length:3},(e,t)=>(0,B.jsx)(vh,{className:`h-24 w-64 shrink-0`},t))}),dD=({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=_f(),g=lD(t,i),_=r||dh(e,t),v=Tw({resources:p,views:m,model:e,columns:(0,I.useMemo)(()=>sh(e,t,[]),[e,t]),filter:(0,I.useMemo)(()=>cD(n,d),[n,d]),orderBy:_}),y=YT(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)(Dw,{chips:y}):(0,B.jsx)(`span`,{}),(0,B.jsxs)(`p`,{className:`flex flex-wrap gap-x-3 text-muted-foreground`,children:[c&&(0,B.jsx)(`span`,{children:c}),S!==void 0&&(0,B.jsx)(`span`,{className:`tabular-nums`,children:`${S.toLocaleString(Le())} ${S===1?b:x.toLowerCase()}`})]})]}):null,v.isLoading?(0,B.jsx)(uD,{}):v.error?(0,B.jsx)(Bg,{title:rD(`couldNotLoad`),error:v.error}):!C||C.total===0?(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:s??rD(`noneMatch`,{plural:x.toLowerCase()})}):(0,B.jsx)(oD,{model:e,view:t,display:g,source:C,label:x,isNew:l}),(0,B.jsxs)(Uh,{to:zS(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:[rD(`viewAll`),` `,(0,B.jsx)(`span`,{className:`sr-only`,children:x.toLowerCase()})]}),(0,B.jsx)(Rr,{className:`size-3.5`,"aria-hidden":!0})]})]})},fD=({model:e,view:t,empty:n,...r})=>{let{resources:i,views:a}=W(),o=mh(i,a,e.name),s=pE(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)(Bg,{title:rD(`couldNotLoadYour`,{plural:c}),error:s.error});if(!s.data)return(0,B.jsx)(vh,{className:`h-24`});let l=dE(o.model,s.data);return l?(0,B.jsx)(dD,{...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??rD(`noneYet`,{plural:c})})},pD=e=>H.list(e,``,``,500,`saved-searches`),mD=(e,t)=>{let n=U(),{resources:r,views:i}=W(),a=r[e];return E({queryKey:pD(e),enabled:t&&a!==void 0,queryFn:async()=>{let t=[],r;do{let o=await n.list(e,{pageSize:500,orderBy:dh(a,i[e]),...r&&{pageToken:r}});t.push(...o.items),r=o.nextPageToken||void 0}while(r);return t}})},hD=({model:e,of:t,target:n,targetView:r,row:i,recordKey:a})=>{let s=U(),c=Cy(),l=String(i[t.filter]??``),u=YT(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({...yy(s,n,p?qT(l,p.field,i[p.seenAt]):``),enabled:p!==void 0}),g=(r?.names?.plural??F(n.name)).toLowerCase(),_={model:n,view:r,filter:l,sort:p?`${p.field} desc`:void 0,limit:t.limit,chips:f!==void 0,empty:Y(`noneMatch`,{plural:g}),note:p&&h.data===0&&Y(`noNew`,{plural:g}),isNew:p&&(e=>JT(e.record[p.field],i[p.seenAt])),viewAll:{label:Y(`viewAll`),savedSearch:a,...p&&{onOpen:()=>m.mutate(new Date().toISOString())}}};return{name:f,chips:u,title:f??kw(u),body:_}},gD=({model:e,view:t,target:n,targetView:r,row:i})=>{let a=Nn(ym(e,i)),{name:o,chips:s,title:c,body:l}=hD({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)(Uh,{to:{kind:`record`,resource:e.name,key:a},className:`hover:underline`,children:o??(0,B.jsx)(Ow,{chips:s})})}),(0,B.jsx)(dD,{...l})]})},_D=({model:e,view:t,empty:n})=>{let{resources:r,views:i}=W(),a=t.searchesOf,o=r[a.resource],s=mD(e.name,!0),c=(t.names?.plural??F(e.name)).toLowerCase();return o?s.error?(0,B.jsx)(Bg,{title:Y(`couldNotLoadYour`,{plural:c}),error:s.error}):s.data?s.data.length===0?(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:n??Y(`noneYet`,{plural:c})}):(0,B.jsx)(`div`,{className:`flex flex-col divide-y`,children:s.data.map(n=>(0,B.jsx)(gD,{model:e,view:t,target:o,targetView:i[a.resource],row:n},Nn(ym(e,n))))}):(0,B.jsx)(vh,{className:`h-40`}):null},vD=({node:e,slots:t})=>{let{resource:n,filter:r=``,sort:i,limit:a,display:o,title:s,description:c,empty:l}=Dy(e),{resources:u,views:d}=W(),f=u[n];if(!f)return null;let p=d[f.name];return(0,B.jsx)(Ay,{title:s,description:c,actions:t.actions,children:p?.searchesOf?(0,B.jsx)(_D,{model:f,view:p,empty:l}):p?.listOf===void 0?(0,B.jsx)(dD,{model:f,view:p,filter:r,sort:i,limit:a,display:o,empty:l}):(0,B.jsx)(fD,{model:f,view:p,limit:a,display:o,empty:l})})},yD=e=>e.type===`boolean`||e.type===`enum`,bD=({model:e,fields:t,title:n,description:r,stored:i})=>{let{resources:a,views:o}=W(),s=af(e.name),c=U(),l=iy(),u=Cy(),d=o[e.name],[f,p]=(0,I.useState)(i),[m,h]=(0,I.useState)(()=>cx(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=cx(e,t,void 0),T=f?oy(s,`update`)&&f.permissions?.update!==!1:oy(s,`create`),E=t.filter(t=>!yD(e.fields[t])),D=E.some(t=>f?Sg(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,lx(e,t,n.record),n.etag??`*`);return{...vy(e,r.record),etag:r.etag,permissions:r.permissions??n.permissions}}let r=await c.create(e.name,Mg(e,a,{...w,...t}));return{...vy(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:sv(`saved`,{label:n??sv(`settings`)})})},e=>{_(t=>({...t,...ax(e)})),y(e)}),x(!1)});S.current=r},A=(t,n)=>{h(e=>({...e,[t]:n})),yD(e.fields[t])&&k({[t]:n})};return(0,B.jsx)(Ay,{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)(Bg,{title:sv(`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)(Yh,{name:t,label:r,help:d?.fields[t]?.help,error:i&&ix(n,r,i),children:(0,B.jsx)(Ov,{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:sv(`save`)})})]})})},xD=e=>{let t=xy(e.model,{});return t.isPending?(0,B.jsx)(Ay,{title:e.title,description:e.description,children:(0,B.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,B.jsx)(vh,{className:`h-4 w-1/2`}),(0,B.jsx)(vh,{className:`h-4 w-1/3`})]})}):t.error?(0,B.jsx)(Ay,{title:e.title,description:e.description,children:(0,B.jsx)(Bg,{title:sv(`couldNotLoad`),error:t.error})}):(0,B.jsx)(bD,{...e,stored:t.data??void 0})},SD=({node:e})=>{let{resource:t,fields:n=[],...r}=Dy(e),i=W().resources[t];return i?(0,B.jsx)(xD,{...r,model:i,fields:n.filter(e=>Object.hasOwn(i.fields,e)),stored:void 0}):null},CD=(e,t)=>{let{resources:n}=W(),r=U(),i=JSON.stringify(e),a=(0,I.useMemo)(()=>JSON.parse(i).map(mu),[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=gu(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=Hb(t,l),p=f({queries:u.map(e=>yy(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 hu(e,t)})},wD=({node:e,children:t})=>{let{when:n}=Dy(e),[r]=CD([n],Yv());return r?(0,B.jsx)(B.Fragment,{children:t}):null},TD=`text-2xl font-semibold tracking-tight tabular-nums`,ED=({model:e,filter:t})=>{let{views:n}=W(),r=by(e,t);return r.isPending?(0,B.jsx)(vh,{className:`h-8 w-16`}):r.error?(0,B.jsx)(`span`,{className:`text-danger-text`,children:sv(`couldNotCount`)}):(0,B.jsx)(Uh,{to:Xy(n[e.name],e.name,t),className:`${TD} hover:text-primary-text after:absolute after:inset-0 after:content-['']`,children:r.data.toLocaleString(Le())})},DD=({field:e,format:t})=>{let n=Vb(Yv(),e);return n.state===`loading`?(0,B.jsx)(vh,{className:`h-8 w-16`}):n.state===`missing`?null:(0,B.jsx)(`span`,{className:TD,children:(0,B.jsx)(Lb,{model:n.model,field:n.field,value:n.value,format:t})})},OD=({node:e})=>{let{label:t,value:n,resource:r,filter:i,field:a,format:o,description:s}=Dy(e),{resources:c}=W(),l=r===void 0?void 0:c[r];return(0,B.jsxs)(Ay,{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:TD,children:n}),l&&(0,B.jsx)(ED,{model:l,filter:i}),a!==void 0&&(0,B.jsx)(DD,{field:a,format:o})]}),s&&(0,B.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:s})]})},kD=(e,t)=>{let n=e.position;if(!n||!oy(t,`update`))return;let r=e.fields[n.field];return r&&!r.readOnly?n.field:void 0},AD=(e,t)=>e.position?.within===void 0?kD(e,t):void 0,jD=(e,t,n)=>t.position?.within!==void 0&&e.field===t.position.within&&!e.through&&!e.from&&!e.filter?kD(t,n):void 0,MD=(e,t,n,r)=>{if(t===void 0||e?.list?.drag?.rank!==!0||r!==``)return!1;let i=fh(n);return i.columnId===t&&i.direction===`asc`},ND=e=>e===null?`none`:`value:${e}`,PD=e=>e.data.current?.sortable!==void 0,FD=e=>{let t=le(e),n=t.find(e=>e.data?.droppableContainer&&PD(e.data.droppableContainer));return n?[n]:t.length>0?t:ce(e)},ID=(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=>!PD(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=LD(o,n,d.id)[0];return{x:d.rect.left+(d.rect.width-t.width)/2,y:f?.rect.top??d.rect.top}},LD=(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),RD=(e,t)=>{let n=e.code===`ArrowDown`?1:e.code===`ArrowUp`?-1:0;if(n===0)return ID(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=LD(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}},zD=(e,t,n,r)=>{let i=Ne({queryKey:[...n,`display`],enabled:r,initialPageParam:0,queryFn:({pageParam:e})=>t(e),getNextPageParam:(e,t)=>e.rows.length===40&&t.length*40<(t[0]?.total??0)?t.length:void 0}),a=i.data?.pages??[];return{resource:e.name,rows:a.flatMap(t=>t.rows.map(t=>uh(e,t))),total:a[0]?.total??0,loading:i.isPending,error:i.error,more:i.hasNextPage,loadMore:()=>void i.fetchNextPage()}},BD=({model:e,by:t,value:n,fields:r,filter:i,orderBy:a})=>{let{resources:o,views:s}=W(),c=Tw({resources:o,views:s,model:e,columns:r,filter:Vm(i,t,n),orderBy:a});return zD(e,c.page,c.key,!0)},VD=(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))]},HD=({model:e,view:t,display:n,column:r,fields:i,filter:a,orderBy:o,limit:s,moves:c,movable:l,placeable:u,dragged:d})=>{let f=BD({model:e,by:n.by,value:r.value,fields:i,filter:a,orderBy:o}),p=Hm(e,t,n),m=new Set(f.rows.map(e=>e.key)),h=new Map(c.map(e=>[e.row.key,e])),g=f.rows.filter(e=>h.has(e.key)&&h.get(e.key).to!==r.value),_=c.filter(e=>e.to===r.value&&!m.has(e.row.key)).map(e=>e.row),v=f.rows.filter(e=>!g.includes(e)).map(e=>h.has(e.key)?h.get(e.key).row:e),y=c.findLast(e=>e.to===r.value&&e.order),b=VD([..._,...v],y?.order).slice(0,s),{setNodeRef:x,isOver:S}=ke({id:ND(r.value),data:{column:r,rows:b}}),C=f.total-g.length+_.length;if(r.value===null&&!f.loading&&C===0&&!S)return null;let w=(t?.names?.plural??F(e.name)).toLowerCase(),T=t?.fields[n.by];return(0,B.jsxs)(`section`,{ref:x,"aria-label":`${r.label}, ${C}`,className:P(`flex w-72 shrink-0 snap-start flex-col gap-2 rounded-lg bg-surface p-2`,S&&`ring-2 ring-primary/30`),children:[(0,B.jsxs)(`header`,{className:`flex items-center justify-between gap-2 px-1 pt-0.5`,children:[(0,B.jsx)(`h2`,{className:`min-w-0 truncate text-body font-medium`,children:r.value===null?(0,B.jsx)(`span`,{className:`text-muted-foreground`,children:r.label}):(0,B.jsx)(Nb,{value:r.value,hints:T,children:r.label})}),!f.loading&&(0,B.jsx)(`span`,{className:`text-xs tabular-nums text-muted-foreground`,children:C.toLocaleString(Le())})]}),f.loading?Array.from({length:3},(e,t)=>(0,B.jsx)(vh,{className:`h-20`},t)):f.error?(0,B.jsx)(Bg,{title:K(`couldNotLoadRows`),error:f.error}):b.length===0?(0,B.jsx)(`p`,{className:`px-1 py-4 text-center text-xs text-muted-foreground`,children:K(`noPlural`,{plural:w})}):(0,B.jsx)(ue,{id:ND(r.value),items:b.map(e=>e.key),strategy:re,children:(0,B.jsx)(`ul`,{className:`-mb-2 flex flex-col`,children:b.map(n=>(0,B.jsx)(UD,{model:e,view:t,card:p,row:n,column:r,rows:b,draggable:(l||u)&&sy(n.record,`update`),placeable:u,dragged:d},n.key))})}),s===void 0&&f.more&&(0,B.jsx)(G,{size:`sm`,variant:`ghost`,onClick:f.loadMore,children:K(`showMore`)})]})},UD=({model:e,view:t,card:n,row:r,column:i,rows:a,draggable:o,placeable:s,dragged:c})=>{let{setNodeRef:l,setActivatorNodeRef:u,listeners:d,isDragging:f,isOver:p,active:m,transform:h,transition:g}=Te({id:r.key,data:{row:r,column:i,rows:a},disabled:{draggable:!o,droppable:!s}}),_=p&&m?.data.current?.column?.value!==i.value;return(0,B.jsx)(`li`,{ref:e=>{l(e),u(e?.querySelector(`a`)??e)},...d,onDragStart:e=>e.preventDefault(),onClickCapture:e=>{c()&&(e.preventDefault(),e.stopPropagation())},style:{transform:h?`translate3d(${h.x}px, ${h.y}px, 0)`:void 0,transition:g},className:P(`relative pb-2`,o&&`cursor-grab touch-manipulation`,f&&`opacity-40`,_&&`before:absolute before:inset-x-0 before:-top-1 before:h-0.5 before:rounded-full before:bg-primary`),children:(0,B.jsx)(ZE,{model:e,view:t,display:n,row:r,swipe:!1})})},WD=e=>e.kind===`and`?e.args.flatMap(WD):[e],GD=e=>e.kind===`string`?String(e.value):void 0,KD=(e,t)=>{if(e.kind===`compare`&&e.op===`=`&&e.field.path.join(`.`)===t){let t=GD(e.value);return t===void 0?void 0:[t]}if(e.kind===`in`&&e.field.path.join(`.`)===t){let t=e.values.map(GD);return t.every(e=>e!==void 0)?t:void 0}},qD=(e,t,n)=>{let r=it(e);if(!r.ok||!r.ast)return n;let i=WD(r.ast).map(e=>KD(e,t)).filter(e=>e!==void 0);return n.filter(e=>i.every(t=>e.value!==null&&t.includes(e.value)))},JD=(e,t)=>t!==null&&Object.hasOwn(e,t)?e[t]:void 0,YD=M(`app/hand-order`),XD=(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:ym(e,r),data:Object.fromEntries(a.map(e=>[e,t[e]])),etag:i}]}),ZD=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},QD=(e,t)=>t===void 0?e:`(${e}) AND (${t})`,$D=async(e,t,n,r)=>{let i=t.position?.after;if(!i)return{after:[],before:[]};let a=t.primaryKey[0],o=ym(t,r),s=e=>Nn([e]),c=await ZD(e,i.resource,QD(Yt(cn.or(cn.eq(i.field,o),cn.eq(i.key,o))),i.filter)),l=(e,t)=>c.flatMap(n=>s(n[e])===s(o)&&s(n[t])!==s(o)?[n[t]]:[]),u=l(i.field,i.key),d=l(i.key,i.field),[f,p]=await Promise.all([ZD(e,t.name,QD(Yt(cn.in(a,[o,...u])),i.while)),d.length===0?[]:ZD(e,t.name,Yt(cn.in(a,d)))]),m=e=>{let r=Nn(ym(t,e));return{key:r,rank:e[t.position.field],title:lr(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):[]}},eO=e=>typeof e==`number`&&Number.isInteger(e),tO=(e,t,n)=>{let r=0;for(;r<t&&eO(e[r])&&(r===0||e[r]>e[r-1]);)r+=1;let i=e.length;for(;i-1>n&&eO(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}},nO=(e,t,n)=>{let r=e.findIndex(e=>e.key===t.key);return r===-1?[...e.slice(0,n),t,...e.slice(n)]:ee(e,r,n)},rO=(e,t,n)=>{let r=e.findIndex(e=>e.key===t.key);return{order:nO(e,t,n),first:r===-1?n:Math.min(r,n),last:r===-1?n:Math.max(r,n)}},iO=e=>typeof e.record.etag==`string`?e.record.etag:`*`,aO=(e,t,n,r,i,a,o,s,c)=>{let l=(r.record[t]??null)!==i.value,u=tO(a.map(e=>e.record[n]),o,s),d=a.slice(u.first,u.last+1),f=e=>l&&e.key===r.key?`*`:iO(e),p=(t,r)=>({op:`reorder`,resource:e.name,field:n,keys:t.map(t=>ym(e,t.record)),start:r,etags:Object.fromEntries(t.map(t=>[Nn(ym(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:ym(e,r.record),data:{[t]:i.value},etag:iO(r)},...h]:h},oO=(e,t,n)=>{let r=new Map(t.map(t=>[Nn(ym(e,t.record)),t.record])),i=new Map;for(let t of n.results){let n=t.op===`reorder`?t.records:t.op===`update`?[t]:[];for(let{record:t,etag:r}of n)i.set(Nn(ym(e,t)),{record:t,etag:r})}return[...i].flatMap(([e,t])=>{let n=r.get(e);return n?[{before:n,...t}]:[]})},sO=M(`app/rank-after`),cO=e=>e!=null&&e!==``,lO=({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}=rO(n,r,l),f=i.map(e=>e.record[t]),p=tO(f,u,d),m=new Map(i.map((t,n)=>[Nn(ym(e,t.record)),n>=p.first&&n<=p.last?p.start+n-p.first:f[n]])),h=e=>m.has(e.key)?m.get(e.key):e.rank,g=Number(m.get(Nn(ym(e,r.record)))),_=a.after.filter(e=>cO(h(e))&&Number(h(e))>=g),v=a.before.find(e=>cO(h(e))&&Number(h(e))<=g),y=v?sO(`dependsOn`,{record:v.title,other:o}):_[0]&&sO(`dependsOn`,{record:o,other:_[0].title});if(!y)return{place:{index:l},...c!==void 0&&{reason:c}};if(c??=y,l!==s||v)continue;let b=Math.max(..._.map(e=>Number(h(e))))+1;if(a.before.every(e=>!cO(h(e))||Number(h(e))>b))return{place:{index:l,bump:b},reason:c}}return{reason:c}},uO=({model:e,view:t,by:n,rank:r,drop:i,labelOf:a,titleOf:s})=>{let c=U(),l=iy(),u=Cy(),[d,f]=(0,I.useState)([]),p=(0,I.useRef)(void 0),m=e=>f(t=>t.filter(t=>t.row.key!==e)),h=r?[n,r]:[n],g=o({mutationFn:e=>e(),onError:e=>l.show({state:`error`,title:K(`couldNotUndo`),description:Um(e)}),onSettled:()=>u(e.name)}),_=async(t,r)=>{let a=i&&JD(i,r.value);if(!a)throw Error(`The column ${r.label} takes no cards`);let o=ym(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(XD(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 $D(c,e,t,n.record),u=lO({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?YD(`notMoved`):YD(`movedToPlace`,{place:u.place.index+1}),description:u.reason}),!d)return u.place.index!==a.index&&y(n,i,rO(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}=rO(a.rows,t,o.index);return v(oO(e,s,await c.batchWrite(aO(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,ym(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&&rO(n.rows,e,n.index).order),onSuccess:(e,{row:t,to:r})=>{if(!e)return;let{landed:i,undo:o}=e;p.current!==void 0&&l.dismiss(p.current),p.current=void 0;let s=t.record[n]??null,c=i===s?s===r.value?K(`orderChanged`):K(`stayedIn`,{column:a(i)}):K(`movedTo`,{column:a(i)});if(!o){l.show({state:`success`,title:c});return}let u=l.show({state:`success`,title:c,action:{label:K(`undo`),onClick:()=>{l.dismiss(u),p.current=void 0,g.mutate(o)}}});p.current=u},onError:(e,{row:t,to:r})=>{m(t.key);let i=(t.record[n]??null)===r.value?K(`couldNotReorder`):K(`couldNotMoveTo`,{to:r.label});l.show({state:`error`,title:i,description:Um(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}})}},dO=(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}},fO=({model:e,view:t,display:n,fields:r,filter:i,orderBy:a,limit:o})=>{let s=zm(e,t,n),c=qD(i,n.by,s),l=Hm(e,t,n),u=af(e.name),{boardDrops:d}=c_(),f=t?.list?.drag,p=typeof f?.board==`string`?f.board:void 0,m=p===void 0?void 0:d?.[p],h=t=>oy(u,`update`)&&(f?.board===!0?!e.fields[n.by]?.readOnly:m!==void 0&&JD(m,t)!==void 0),g=c.some(e=>h(e.value)),_=Bm(e),v=f?.rank===!0&&_!==void 0&&AD(e,u)!==void 0,y=_?`${_} asc`:a,b=e=>s.find(t=>t.value===e)?.label??String(e),x=e=>String(e.labels[l.title]??e.record[l.title]??e.key),{moves:S,move:C}=uO({model:e,view:t,by:n.by,rank:_,drop:m,labelOf:b,titleOf:x}),[w,T]=(0,I.useState)(),E=(0,I.useRef)(!1),D=ne(Me(se,{activationConstraint:{distance:4}}),Me(xe,{activationConstraint:{delay:250,tolerance:5}}),Me(ae,{keyboardCodes:{start:[`Space`],cancel:[`Escape`],end:[`Space`,`Enter`]},coordinateGetter:RD}));if(p!==void 0&&!m)return(0,B.jsx)(ov,{children:K.rich(`noDrop`,{drop:p})});let O=e=>c.find(t=>ND(t.value)===e),k=e=>e.record[n.by]??null,A=(e,t)=>h(k(e))&&h(t.value),j=(e,t)=>{if(!t)return{over:K(`noColumn`)};let n=v?dO(t,e):void 0;if(!n)return{over:O(t.id)?.label??K(`noColumn`)};let r=n.rows.some(t=>t.key===e.key)?n.rows.length:n.rows.length+1;return{over:K(`placeOf`,{column:n.column.label,place:n.index+1,count:r}),place:K(`place`,{column:n.column.label,place:n.index+1})}},ee=(e,t)=>{let n=(v?dO(t,e)?.column:void 0)??O(t.id);return n!==void 0&&n.value!==k(e)&&!A(e,n)};return(0,B.jsxs)(me,{sensors:D,collisionDetection:FD,onDragStart:({active:e})=>{E.current=!0,T(e.data.current.row)},onDragEnd:({active:e,over:t})=>{T(void 0),setTimeout(()=>E.current=!1);let n=e.data.current.row;if(!t)return;let r=v?dO(t,n):void 0;if(!r){let e=O(t.id);e&&e.value!==k(n)&&A(n,e)&&C(n,e);return}let i=r.rows.findIndex(e=>e.key===n.key);if(i!==-1||A(n,r.column)){if(i===-1&&m)return C(n,r.column);i!==r.index&&C(n,r.column,{rows:r.rows,index:r.index})}},onDragCancel:()=>{T(void 0),setTimeout(()=>E.current=!1)},accessibility:{announcements:{onDragStart:({active:e})=>K(`pickedUp`,{title:x(e.data.current.row)}),onDragOver:({active:e,over:t})=>K(`isOver`,{title:x(e.data.current.row),over:j(e.data.current.row,t).over}),onDragEnd:({active:e,over:t})=>{let n=e.data.current.row;if(!t||ee(n,t))return K(`putBack`,{title:x(n)});let r=j(n,t);return K(`wasMovedTo`,{title:x(n),to:r.place??r.over})},onDragCancel:({active:e})=>K(`cancelled`,{title:x(e.data.current.row)})},screenReaderInstructions:{draggable:K(v?g?`boardAnywhere`:`boardWithin`:`boardAcross`)}},children:[(0,B.jsx)(`div`,{className:`relative min-w-0 flex-1 overflow-x-auto`,children:(0,B.jsx)(`div`,{className:`flex snap-x items-start gap-3 pb-2`,children:c.map(a=>(0,B.jsx)(HD,{model:e,view:t,display:n,column:a,fields:r,filter:i,orderBy:y,limit:o,moves:S,movable:h(a.value),placeable:v,dragged:()=>E.current},ND(a.value)))})}),(0,B.jsx)(Oe,{children:w&&(0,B.jsx)(ZE,{model:e,view:t,display:l,row:w,swipe:!1})})]})},pO=864e5,mO=e=>new Date(e).toISOString().slice(0,10),hO=e=>Date.parse(`${e}T00:00:00Z`),gO=(e,t)=>mO(hO(e)+t*pO),_O=e=>gO(e,-((new Date(hO(e)).getUTCDay()+6)%7)),vO=(e,t=0)=>{let n=new Date(hO(e));return mO(Date.UTC(n.getUTCFullYear(),n.getUTCMonth()+t,1))},yO=({scale:e,day:t})=>({scale:e,day:e===`month`?vO(t):_O(t)}),bO=(e,t,n=Gf())=>yO(e??{scale:`month`,day:Zf(t,n)}),xO=(e,t,n=Gf())=>yO({scale:e,day:Zf(t,n)}),SO=(e,t)=>e.scale===`month`?{scale:`month`,day:vO(e.day,t)}:{scale:`week`,day:gO(_O(e.day),7*t)},CO=e=>{let t=_O(e.scale===`month`?vO(e.day):e.day),n=(hO(e.scale===`month`?gO(_O(gO(vO(e.day,1),-1)),6):gO(t,6))-hO(t))/pO+1;return Array.from({length:n},(e,n)=>gO(t,n))},wO=e=>{let t=CO(e);return{from:t[0],to:gO(t.at(-1),1)}},TO=(e,t)=>t.fields[e.start]?.type===`timestamp`,EO=(e,t,n,r=Gf())=>{let i=TO(e,t),a=e=>new Date($f(e,r)).toISOString().replace(`.000Z`,`Z`),o=e=>i?{kind:`timestamp`,value:a(e),span:{start:0,end:0}}:{kind:`string`,value:e,span:{start:0,end:0}},s=cn.and(cn.gte(e.start,o(n.from)),cn.lt(e.start,o(n.to)));if(e.end===void 0)return Yt(s);let c=i?cn.gt(e.end,o(n.from)):cn.gte(e.end,o(n.from));return Yt(cn.or(s,cn.and(cn.lt(e.start,o(n.from)),c)))},DO=(e,t)=>e===``?t:`(${e}) AND (${t})`,OO=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},kO=(e,t,n,r=Gf())=>{let i=OO(e[t.start]);if(i===void 0)return;let a=TO(t,n),o=e=>a?Zf(e,r):mO(e),s=o(i),c=t.end===void 0?void 0:OO(e[t.end]),l=c===void 0?s:o(a?c-1:c);return{first:s,last:l<s?s:l}},AO=(e,t,n,r,i=Gf())=>{let a=kO(e,t,n,i);return a?r.filter(e=>e>=a.first&&e<=a.last):[]},jO=(e,t)=>e.toSorted((e,n)=>(OO(e.record[t.start])??0)-(OO(n.record[t.start])??0)),MO=(e,t,n,r,i=Gf())=>{let a=new Map(r.map(e=>[e,[]]));for(let o of jO(e,t))for(let e of AO(o.record,t,n,r,i))a.get(e).push(o);return a},NO=(e,t,n,r,i,a=Gf())=>{let o=(hO(i)-hO(r))/pO,s=TO(t,n),c=e=>{let t=OO(e);if(t!==void 0)return s?new Date(Qf(t+Yf(t,a)+o*pO,a)).toISOString():gO(mO(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}}},PO=({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)(Uh,{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=mf({variant:`secondary`,size:`sm`});return(0,B.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,B.jsx)(`h2`,{className:`text-sm font-medium`,children:e}),(0,B.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,B.jsxs)(`div`,{className:`flex items-center gap-1`,children:[l(n,u,K(`previousPeriod`,{unit:t}),(0,B.jsx)(Ei,{className:`size-3.5`})),l(r,u,K(`today`),K(`today`)),l(i,u,K(`nextPeriod`,{unit:t}),(0,B.jsx)(Oi,{className:`size-3.5`}))]}),(0,B.jsx)(`span`,{role:`group`,"aria-label":o,className:ze.group(),children:a.map(e=>(0,B.jsx)(I.Fragment,{children:l(e.view,ze.option(e.current),e.label,e.label,e.current)},e.label))})]})]})},FO=e=>{let t=CO(e),n=e=>Date.parse(`${e}T00:00:00Z`);return e.scale===`month`?fp(n(e.day)):_p(n(t[0]),n(t.at(-1)))},IO=({view:e,now:t,linkTo:n,onView:r})=>{let i=e.scale===`month`&&Zf(t,Gf()).startsWith(e.day.slice(0,7)),a=n=>n===`week`&&i?xO(`week`,t):bO({scale:n,day:e.day},t),o=(t,n)=>({view:a(t),label:n,current:e.scale===t});return(0,B.jsx)(PO,{heading:FO(e),unit:e.scale===`month`?`month`:`week`,previous:SO(e,-1),today:xO(e.scale,t),next:SO(e,1),scales:[o(`month`,K(`month`)),o(`week`,K(`week`))],scalesLabel:K(`calendarScale`),linkTo:n,onView:r})},LO=`day:`,RO=e=>`${LO}${e}`,zO=(e,t)=>`${e}@${t}`,BO=(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(RO(gO(o,a)));if(s)return{x:s.left+(s.width-n.width)/2,y:s.top+4}},VO=({day:e,count:t,children:n,more:r,inMonth:i,today:a,week:o})=>{let{setNodeRef:s,isOver:c}=ke({id:RO(e)}),l=Date.parse(`${e}T00:00:00Z`);return(0,B.jsxs)(`section`,{ref:s,"aria-label":`${gp(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:hp(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]})},HO=(e,t,n,r)=>{let i=n.title??cr(e,t),a=e.fields[i],o=r.labels[i]??(a?Nm(a,r.record[i],t?.fields[i]):``);return o===``?r.key:o},UO=(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 Zf(a,Gf())===r?vp(a):void 0},WO=({model:e,view:t,display:n,row:r,day:i,className:a})=>{let o=ZT(e),s=UO(e,n,r,i);return(0,B.jsxs)(Uh,{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:HO(e,t,n,r)})]})},GO=({movable:e,dragged:t,...n})=>{let{setNodeRef:r,setActivatorNodeRef:i,listeners:a,isDragging:o}=j({id:zO(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)(WO,{...n})})},KO=({model:e,display:t,range:n,fields:r,filter:i})=>{let{resources:a,views:o}=W(),s=Tw({resources:a,views:o,model:e,columns:r,filter:DO(i,EO(t,e,n)),orderBy:`${t.start} asc`}),c=zD(e,s.page,s.key,!0),l=c.more&&!c.loading&&c.rows.length<500;(0,I.useEffect)(()=>{l&&c.loadMore()},[l,c.rows.length]);let u=c.rows.length>500||c.rows.length===500&&c.more;return{rows:c.rows.slice(0,500),capped:u,loading:c.loading,error:c.error}},qO=(e,t)=>{let n=new Map(t.map(e=>[e.key,e.patch]));return e.map(e=>n.has(e.key)?{...e,record:{...e.record,...n.get(e.key)}}:e)},JO=(e,t)=>{let n=U(),r=iy(),i=Cy(),[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,ym(e,t.record),r,i)},onMutate:({row:e,patch:t})=>s(n=>[...n.filter(t=>t.key!==e.key),{key:e.key,patch:t}]),onError:(e,{row:t,to:n})=>{c(t.key),r.show({state:`error`,title:K(`couldNotMoveTo`,{to:cp(Date.parse(`${n}T00:00:00Z`))}),description:Um(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:NO(n.record,t,e,r,i),to:i})}},YO=3,XO=({model:e,view:t,display:n,fields:r,filter:i,at:a,linkTo:o,now:s=Date.now()})=>{let[c,l]=(0,I.useState)(),u=bO(o?a:c,s),d=CO(u),f=KO({model:e,display:n,range:wO(u),fields:r,filter:i}),{moves:p,move:m}=JO(e,n),h=MO(qO(f.rows,p),n,e,d),g=oy(af(e.name),`update`)&&[n.start,n.end].every(t=>t===void 0||!e.fields[t]?.readOnly),[_,v]=(0,I.useState)(),y=(0,I.useRef)(!1),b=ne(Me(se,{activationConstraint:{distance:4}}),Me(xe,{activationConstraint:{delay:250,tolerance:5}}),Me(ae,{keyboardCodes:{start:[`Space`],cancel:[`Escape`],end:[`Space`,`Enter`]},coordinateGetter:BO})),x=Zf(s,Gf()),S=u.scale===`week`,C=e=>cp(Date.parse(`${String(e).slice(RO(``).length)}T00:00:00Z`)),w=r=>HO(e,t,n,r.row),T={onDragStart:({active:e})=>K(`pickedUp`,{title:w(e.data.current)}),onDragOver:({active:e,over:t})=>K(`isOver`,{title:w(e.data.current),over:t?C(t.id):K(`noDay`)}),onDragEnd:({active:e,over:t})=>t?K(`wasMovedTo`,{title:w(e.data.current),to:C(t.id)}):K(`putBack`,{title:w(e.data.current)}),onDragCancel:({active:e})=>K(`cancelled`,{title:w(e.data.current)})},E=()=>{v(void 0),setTimeout(()=>y.current=!1)},D=({active:e})=>{y.current=!0,v(e.data.current)},O=({active:e,over:t})=>{E();let{row:n,day:r}=e.data.current,i=t?String(t.id).slice(RO(``).length):void 0;i&&i!==r&&m(n,r,i)},k=(e,t)=>{let n=bO({scale:`week`,day:e},s),r=K(`moreHidden`,{count:t}),i=`self-start rounded px-1 text-xs text-muted-foreground hover:text-foreground focus-visible:outline-2 focus-visible:outline-primary`;return o?(0,B.jsx)(Uh,{to:o(n),className:i,children:r}):(0,B.jsx)(`button`,{type:`button`,className:i,onClick:()=>l(n),children:r})};return(0,B.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-3`,children:[(0,B.jsx)(IO,{view:u,now:s,linkTo:o,onView:l}),f.error&&(0,B.jsx)(Bg,{title:K(`couldNotLoadRows`),error:f.error}),f.capped&&(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:K(`capped`,{limit:500,unit:u.scale})}),(0,B.jsxs)(me,{sensors:b,collisionDetection:FD,onDragStart:D,onDragEnd:O,onDragCancel:E,accessibility:{announcements:T,screenReaderInstructions:{draggable:K(`calendarInstructions`)}},children:[(0,B.jsxs)(`div`,{className:`overflow-hidden rounded-lg border border-border`,children:[!S&&(0,B.jsx)(`div`,{"aria-hidden":!0,className:`grid grid-cols-7 gap-px border-b border-border bg-border`,children:d.slice(0,7).map(e=>(0,B.jsx)(`span`,{className:`bg-surface px-1.5 py-1 text-xs font-medium text-muted-foreground`,children:hp(Date.parse(`${e}T00:00:00Z`))},e))}),(0,B.jsx)(`div`,{className:P(`grid gap-px bg-border`,S?`grid-cols-1 sm:grid-cols-7`:`grid-cols-7`),children:d.map(r=>{let i=h.get(r),a=S?i:i.slice(0,YO);return(0,B.jsx)(VO,{day:r,count:i.length,inMonth:S||r.startsWith(u.day.slice(0,7)),today:r===x,week:S,more:a.length<i.length&&k(r,i.length-a.length),children:f.loading?(0,B.jsx)(vh,{className:`h-4`}):a.map(i=>(0,B.jsx)(GO,{model:e,view:t,display:n,row:i,day:r,movable:g&&sy(i.record,`update`),dragged:()=>y.current},i.key))},r)})})]}),(0,B.jsx)(Oe,{children:_&&(0,B.jsx)(WO,{model:e,view:t,display:n,row:_.row,day:_.day})})]})]})},ZO=864e5,QO=e=>Date.parse(`${e}T00:00:00Z`),$O=(e,t=0)=>{let n=new Date(QO(e));return new Date(Date.UTC(n.getUTCFullYear(),Math.floor(n.getUTCMonth()/3)*3+3*t,1)).toISOString().slice(0,10)},ek=({scale:e,day:t})=>({scale:e,day:e===`week`?_O(t):e===`month`?vO(t):$O(t)}),tk=(e,t,n=Gf())=>ek(e??{scale:`month`,day:Zf(t,n)}),nk=(e,t)=>{let{scale:n,day:r}=ek(e);return{scale:n,day:n===`week`?gO(r,7*t):n===`month`?vO(r,t):$O(r,t)}},rk=e=>{let t=ek(e).day,n=(QO(nk(e,1).day)-QO(t))/ZO;return Array.from({length:n},(e,n)=>gO(t,n))},ik=e=>({from:ek(e).day,to:nk(e,1).day}),ak=(e,t,n,r=Gf())=>{let i=Zf(n,r),a=rk(e);return ek({scale:t,day:i>=a[0]&&i<=a.at(-1)?i:a[0]})},ok=e=>{let t=rk(e);return e.scale===`week`?_p(QO(t[0]),QO(t.at(-1))):e.scale===`month`?fp(QO(t[0])):mp(QO(t[0]),QO(vO(t.at(-1))))},sk=e=>{let t=rk(e);if(e.scale===`week`)return t.map((e,t)=>({index:t,span:1,label:`${hp(QO(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:pp(QO(t[e]))}))},ck=(e,t,n,r,i=Gf())=>{let a=kO(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}},lk=`none`,uk=(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?lk:`value:${String(e)}`,c=n?K(`noValue`,{label:o?.label??F(i)}):t.labels[i]??Nm(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)},dk=`grid grid-cols-1 sm:grid-cols-[12rem_minmax(0,1fr)]`,fk=(e,t)=>`${e/t*100}%`,pk=({ticks:e,days:t,today:n,label:r,trackRef:i})=>(0,B.jsxs)(`div`,{className:P(dk,`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:fk(e.index,t.length),width:fk(e.span,t.length)},children:e.label},e.index))})]}),mk=({ticks:e,days:t,today:n})=>{let r=t.indexOf(n);return(0,B.jsxs)(`div`,{"aria-hidden":!0,className:P(dk,`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:fk(r,t.length),width:fk(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:fk(e.index,t.length)}},e.index))]})]})},hk=({model:e,view:t,display:n,row:r,days:i,movable:a,dragged:o})=>{let s=ck(r.record,n,e,i);return(0,B.jsxs)(`div`,{className:P(dk,`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:HO(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:fk(s.first,i.length),width:fk(s.last-s.first+1,i.length)},children:(0,B.jsx)(GO,{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`)})})})]})},gk=()=>[{scale:`week`,label:K(`week`)},{scale:`month`,label:K(`month`)},{scale:`quarter`,label:K(`quarter`)}],_k=({model:e,view:t,display:n,fields:r,filter:i,at:a,linkTo:o,now:s=Date.now()})=>{let[c,l]=(0,I.useState)(),u=tk(o?a:c,s),d=rk(u),f=sk(u),p=KO({model:e,display:n,range:ik(u),fields:r,filter:i}),{moves:m,move:h}=JO(e,n),g=uk(jO(qO(p.rows,m),n),e,t,n),_=oy(af(e.name),`update`)&&[n.start,n.end].every(t=>t===void 0||!e.fields[t]?.readOnly),[v,y]=(0,I.useState)(),b=(0,I.useRef)(!1),x=(0,I.useRef)(0),S=(0,I.useRef)(null),C=()=>(S.current?.getBoundingClientRect().width??0)/d.length,w=e=>{let t=C();return t>0?Math.round(e/t):0},T=({transform:e})=>({...e,x:w(e.x)*C(),y:0}),E=ne(Me(se,{activationConstraint:{distance:4}}),Me(xe,{activationConstraint:{delay:250,tolerance:5}}),Me(ae,{keyboardCodes:{start:[`Space`],cancel:[`Escape`],end:[`Space`,`Enter`]},coordinateGetter:(e,{currentCoordinates:t})=>{let n=e.code===`ArrowLeft`?-1:+(e.code===`ArrowRight`);if(n!==0)return e.preventDefault(),{x:t.x+n*C(),y:t.y}}})),D=Zf(s,Gf()),O=r=>HO(e,t,n,r.row),k=e=>cp(Date.parse(`${gO(e.day,x.current)}T00:00:00Z`)),A={onDragStart:({active:e})=>K(`pickedUp`,{title:O(e.data.current)}),onDragMove:({active:e})=>K(`startsOn`,{title:O(e.data.current),day:k(e.data.current)}),onDragOver:()=>void 0,onDragEnd:({active:e})=>x.current===0?K(`putBack`,{title:O(e.data.current)}):K(`wasMovedTo`,{title:O(e.data.current),to:k(e.data.current)}),onDragCancel:({active:e})=>K(`cancelled`,{title:O(e.data.current)})},j=()=>{y(void 0),setTimeout(()=>b.current=!1)},ee=({active:e})=>{b.current=!0,x.current=0,y(e.data.current)},te=({delta:e})=>x.current=w(e.x),re=({active:t,delta:r})=>{j(),x.current=w(r.x);let{row:i}=t.data.current,a=kO(i.record,n,e);a&&x.current!==0&&h(i,a.first,gO(a.first,x.current))},ie=n.group===void 0?t?.names?.plural??F(e.name):t?.fields[n.group]?.label??F(n.group),oe=!p.loading&&!p.error&&p.rows.length===0;return(0,B.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-3`,children:[(0,B.jsx)(PO,{heading:ok(u),unit:u.scale,previous:nk(u,-1),today:tk({scale:u.scale,day:D},s),next:nk(u,1),scales:gk().map(({scale:e,label:t})=>({view:ak(u,e,s),label:t,current:u.scale===e})),scalesLabel:K(`timelineScale`),linkTo:o,onView:l}),p.error&&(0,B.jsx)(Bg,{title:K(`couldNotLoadRows`),error:p.error}),p.capped&&(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:K(`capped`,{limit:500,unit:u.scale})}),(0,B.jsxs)(me,{sensors:E,modifiers:[T],onDragStart:ee,onDragMove:te,onDragEnd:re,onDragCancel:j,accessibility:{announcements:A,screenReaderInstructions:{draggable:K(`timelineInstructions`)}},children:[(0,B.jsxs)(`div`,{className:`overflow-hidden rounded-lg border border-border`,children:[(0,B.jsx)(pk,{ticks:f,days:d,today:D,label:ie,trackRef:S}),(0,B.jsxs)(`div`,{className:`relative`,children:[(0,B.jsx)(mk,{ticks:f,days:d,today:D}),p.loading&&(0,B.jsxs)(`div`,{className:`relative flex flex-col gap-2 p-2`,children:[(0,B.jsx)(vh,{className:`h-4`}),(0,B.jsx)(vh,{className:`h-4`})]}),oe&&(0,B.jsx)(`p`,{className:`relative px-2 py-3 text-xs text-muted-foreground`,children:K(`nothingIn`,{unit:u.scale})}),!p.loading&&g.map(r=>(0,B.jsxs)(`section`,{"aria-label":r.label,className:`relative border-b border-border last:border-b-0`,children:[r.label!==void 0&&(0,B.jsxs)(`h3`,{className:`flex items-center gap-1.5 border-b border-border bg-surface px-2 py-1 text-xs font-medium`,children:[r.label,(0,B.jsx)(`span`,{className:`tabular-nums text-muted-foreground`,children:r.rows.length})]}),r.rows.map(r=>(0,B.jsx)(hk,{model:e,view:t,display:n,row:r,days:d,movable:_&&sy(r.record,`update`),dragged:()=>b.current},r.key))]},r.key))]})]}),(0,B.jsx)(Oe,{children:v&&(0,B.jsx)(WO,{model:e,view:t,display:n,row:v.row,day:v.day})})]})]})},vk=({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)(Bg,{title:K(`couldNotLoadRows`),error:e.error}):e.rows.length===0?(0,B.jsx)(`p`,{className:`py-8 text-center text-muted-foreground`,children:t}):r}),yk=({list:e})=>(0,B.jsxs)(`div`,{className:`flex items-center justify-between gap-3 py-3 text-xs text-muted-foreground`,children:[(0,B.jsxs)(`span`,{children:[e.rows.length.toLocaleString(Le()),` of `,e.total.toLocaleString(Le())]}),e.more&&(0,B.jsx)(G,{size:`sm`,onClick:e.loadMore,children:K(`showMore`)})]}),bk=`grid grid-cols-[repeat(auto-fill,minmax(15rem,1fr))] gap-3`,xk=`relative flex snap-x snap-mandatory gap-3 overflow-x-auto pb-1`,Sk=({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)(vk,{list:r,empty:K(`noneMatch`,{plural:o}),loading:(0,B.jsx)(`div`,{className:bk,children:Array.from({length:6},(e,t)=>(0,B.jsx)(vh,{className:`h-24`},t))}),children:[(0,B.jsx)(`ul`,{className:i?xk:bk,"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)(ZE,{model:e,view:t,display:n,row:r,swipe:!i})},r.key))}),a&&(0,B.jsx)(yk,{list:r})]})},Ck=(0,I.createContext)(void 0),wk=({value:e,children:t})=>(0,B.jsx)(Ck.Provider,{value:e,children:t}),Tk=()=>{let e=(0,I.useContext)(Ck);if(!e)throw Error(`useListDisplay is used inside a list display, which the list page draws`);return e},Ek=()=>(0,I.useContext)(Ck),Dk=({display:e,list:t})=>{let{components:n}=c_(),r=n?.[e.component];return r?(0,B.jsx)(wk,{value:t,children:(0,B.jsx)(`div`,{className:`relative min-w-0 flex-1 overflow-x-auto`,children:(0,B.jsx)(cv,{name:e.component,children:(0,B.jsx)(r,{...vn(e.props??{})})})})}):(0,B.jsx)(ov,{children:K.rich(`noComponent`,{component:e.component})})},Ok=sn(),kk={bounds:{south:-90,west:-180,north:90,east:180},zoom:0},Ak=22,jk=e=>Math.floor(e*1e6)/1e6,Mk=e=>Math.ceil(e*1e6)/1e6,Nk=e=>((e+180)%360+360)%360-180,Pk=(e,t)=>{let n=[Ok.gte(e.latitude,jk(Math.max(t.south,-90))),Ok.lte(e.latitude,Mk(Math.min(t.north,90)))];if(t.east-t.west>=360)return Ok.and(...n);let r=Ok.gte(e.longitude,jk(Nk(t.west))),i=Ok.lte(e.longitude,Mk(Nk(t.east)));return Nk(t.west)<=Nk(t.east)?Ok.and(...n,r,i):Ok.and(...n,Ok.or(r,i))},Fk=(e,t,n)=>{let r=Yt(Pk(t,n));return e.trim()===``?r:`(${e}) AND ${r}`},Ik=e=>Math.min(Math.max(Math.floor(e),0),Ak),Lk=(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))}},Rk=e=>{if(typeof e==`number`)return e;if(typeof e==`string`&&e.trim()!==``)return Number(e)},zk=(e,t)=>{let n=Rk(e[t.latitude]),r=Rk(e[t.longitude]);if(n!==void 0&&r!==void 0&&Math.abs(n)<=90&&Math.abs(r)<=180)return{latitude:n,longitude:r}},Bk=6371008.8,Vk=64,Hk=(e,t)=>t.approximate===void 0?t.exact!==void 0&&e[t.exact]===!1:e[t.approximate]===!0,Uk=(e,t)=>{let n=t/Bk,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%Vk/Vk*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]})]}},Wk=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,Gk=(e,t)=>Array.isArray(e)&&e.length>=t&&e.every(Wk),Kk=e=>Array.isArray(e)&&e.length>0&&e.every(e=>Gk(e,4)),qk=e=>Array.isArray(e)&&e.length>0&&e.every(e=>Gk(e,2)),Jk=e=>{if(typeof e!=`string`)return e;try{return JSON.parse(e)}catch(e){if(e instanceof SyntaxError)return;throw e}},Yk=e=>{let t=Jk(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`&&Kk(i)||r===`MultiPolygon`&&Array.isArray(i)&&i.length>0&&i.every(Kk)||r===`LineString`&&Gk(i,2)||r===`MultiLineString`&&qk(i))return{type:r,coordinates:i}},Xk=(e,t,n)=>{if(!Hk(e,t))return;let r=t.area===void 0?void 0:Yk(e[t.area]);if(r)return r;let i=t.radius===void 0?void 0:Rk(e[t.radius]);return i!==void 0&&Number.isFinite(i)&&i>0?Uk(n,i):t.defaultRadius===void 0?void 0:Uk(n,t.defaultRadius)},Zk=(e,t)=>e.flatMap(e=>{let n=zk(e.record,t);if(!n)return[];if(!Hk(e.record,t))return[{key:e.key,...n}];let r=Xk(e.record,t,n);return[{key:e.key,...n,approximate:!0,...r&&{area:r}}]}),Qk=(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}))},$k=(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)}},eA=(e,t)=>({keys:e.keys,index:((e.index+t)%e.keys.length+e.keys.length)%e.keys.length}),tA=({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?Fk(i,u,o.bounds):``,p=o?Ik(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:Cb(c,l,e,r),photos:Im(t)});return{rows:wb(c,e,r,Lm(e,n.items,n.photos),n.labels).map(t=>uh(e,t)),buckets:n.buckets,total:n.totalSize}}})},nA=(0,I.lazy)(()=>Ve(()=>import(`./records-map-hxWNR_fi.js`).then(e=>({default:e.RecordsMap})),__vite__mapDeps([4,1,2,5,6,7,3,8]))),rA=250,iA=`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`,aA=({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=eT(m,rA),[_,v]=(0,I.useState)(o===void 0),y=tA({model:e,view:t,display:n,fields:a,filter:r,orderBy:i,area:_?kk:g}),b=y.isPlaceholderData?void 0:y.data,x=y.data?.rows??[],S=y.data?.buckets??[],C=Zk(x,n),w=_&&b?Lk(Zk(b.rows,n),b.buckets):void 0,T=ah(t,n),E=(t?.names?.plural??F(e.name)).toLowerCase(),D=(t?.names?.singular??F(e.name)).toLowerCase(),O=$k(f,x),k=O&&x.find(e=>e.key===O.keys[O.index]),A=new Set(C.filter(e=>e.approximate).map(e=>e.key)),j=e=>{let t=e.filter(e=>A.has(e)).length;return e.length===1?K(t===1?`showOneApproximate`:`showOne`,{singular:D}):t===0?K(`showMany`,{count:e.length,plural:E}):t===e.length?K(`showManyApproximate`,{count:e.length,plural:E}):K(`showManySomeApproximate`,{count:e.length,plural:E,near:t})},ee=e=>K(`zoomIn`,{count:e.toLocaleString(Le()),noun:e===1?D:E}),te=(0,I.useRef)(null),[ne,re]=(0,I.useState)(0);if((0,I.useLayoutEffect)(()=>re(te.current?.offsetHeight??0),[k?.key]),!d)return(0,B.jsx)(ov,{children:K(`needsStyle`)});let ie=b?.total===0;return(0,B.jsxs)(`div`,{className:P(`flex h-full min-h-[36rem] flex-1 flex-col sm:min-h-[28rem]`,l&&`max-md:-mx-5 max-md:-mb-4 max-md:min-h-0`),children:[(0,B.jsxs)(`div`,{className:P(`relative min-h-0 flex-1 overflow-hidden rounded-lg border border-border bg-muted`,l&&`max-md:rounded-none max-md:border-0`),children:[(0,B.jsx)(I.Suspense,{fallback:null,children:(0,B.jsx)(nA,{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)(Bg,{title:K(`couldNotLoadRows`),error:y.error})}),ie&&(0,B.jsx)(`div`,{className:`pointer-events-none absolute inset-x-3 top-3 z-10 flex justify-center`,children:(0,B.jsxs)(`p`,{className:`pointer-events-auto flex items-center gap-3 rounded-full border border-border bg-background px-4 py-1.5 text-muted-foreground shadow`,role:`status`,children:[K(_?`noneMatch`:`noneHere`,{plural:E}),!_&&(0,B.jsx)(G,{size:`sm`,onClick:()=>v(!0),children:K(`showAll`)})]})}),O&&k&&(0,B.jsx)(`div`,{ref:te,className:`pointer-events-none absolute inset-x-3 bottom-3 z-10 flex justify-center`,children:(0,B.jsxs)(`div`,{className:`pointer-events-auto flex w-full max-w-[16rem] flex-col gap-2 sm:max-w-xs`,role:`group`,"aria-label":K(`chosen`,{singular:D}),children:[(0,B.jsxs)(`div`,{className:`flex items-center justify-end gap-1.5`,children:[A.has(k.key)&&(0,B.jsxs)(`span`,{className:`mr-auto flex items-center gap-1 rounded-full border border-border bg-background px-2 py-1 text-xs`,children:[(0,B.jsx)(Ii,{className:`size-3.5`,"aria-hidden":!0}),K(`approximatePosition`)]}),O.keys.length>1&&(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`button`,{type:`button`,"aria-label":K(`previous`),className:iA,onClick:()=>p(eA(O,-1)),children:(0,B.jsx)(Ei,{className:`size-4`,"aria-hidden":!0})}),(0,B.jsxs)(`span`,{className:`rounded-full border border-border bg-background px-2 py-1 text-xs tabular-nums`,"aria-live":`polite`,children:[O.index+1,` / `,O.keys.length]}),(0,B.jsx)(`button`,{type:`button`,"aria-label":K(`next`),className:iA,onClick:()=>p(eA(O,1)),children:(0,B.jsx)(Oi,{className:`size-4`,"aria-hidden":!0})})]}),(0,B.jsx)(`button`,{type:`button`,"aria-label":K(`close`),className:iA,onClick:()=>p(void 0),children:(0,B.jsx)(yc,{className:`size-4`,"aria-hidden":!0})})]}),(0,B.jsx)(`div`,{className:`shadow-lg`,children:(0,B.jsx)(ZE,{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:oA(y.data,E)})]})},oA=(e,t)=>{if(!e)return`\xA0`;let n=e.total.toLocaleString(Le());return e.buckets.length===0&&e.rows.length<e.total?`${e.rows.length.toLocaleString(Le())} of ${n} ${t} in view`:`${n} ${t} in view`},sA=({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)(wi,{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=Zw(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)(Si,{className:`size-3.5 text-primary-text`})]})},t.value))})]})},cA={table:Ls,cards:Wa,kanban:ks,board:Ki,list:Qa,calendar:gi,timeline:bi,map:uo},lA=({view:e,value:t,onChange:n,menu:r=!1,choices:i=$m(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:cA[e.icon]}));return r?(0,B.jsx)(sA,{label:K(`display`),value:t,onChange:n,options:a}):(0,B.jsx)(Re,{label:K(`display`),size:`md`,value:t,onChange:n,options:a})},uA=[[`asc`,`ascending`],[`desc`,`descending`]],dA=({model:e,view:t,display:n,orderBy:r,onChange:i,className:a})=>{let o=fh(r),s=ch(e,t,n),c=s.includes(o.columnId)?s:[o.columnId,...s],l=e=>t?.fields[e]?.label??F(e);return(0,B.jsx)(`select`,{"aria-label":K(`sort`),value:`${o.columnId} ${o.direction}`,onChange:e=>i(e.target.value),className:P(`h-8 rounded-md border border-border-strong bg-background px-2.5 shadow-sm focus:border-primary focus:outline-none focus:ring-2 focus:ring-primary/20`,a),children:c.flatMap(e=>uA.map(([t,n])=>(0,B.jsxs)(`option`,{value:`${e} ${t}`,children:[l(e),`, `,K(n)]},`${e} ${t}`)))})},fA=(e,t,n,r)=>e.map(e=>{let i=t.fields[e.id],a=i&&ev(r,i,n?.fields[e.id]);return a?{...e,render:t=>(0,B.jsx)(dv,{shown:a,part:`cell`,field:i,value:t[e.id],fallback:ZS(e,e.value?e.value(t):t[e.id])})}:e}),pA=e=>String(typeof e==`object`&&e&&`id`in e?e.id:e),mA=({target:e,id:t})=>(0,B.jsx)(YS,{text:Mb(e,t)??t,className:`font-medium text-primary-text hover:underline`}),hA=(e,t,n,r)=>e.map(e=>{let i=t.fields[e.id],a=i?.type===`relation`&&i.relation?n[i.relation.resource]:void 0;return e.render||!a||!r[a.name]?.titleFrom?e:{...e,render:t=>t[e.id]==null?ZS(e,null):(0,B.jsx)(mA,{target:a,id:pA(t[e.id])})}}),gA=e=>e.includes(`.`),_A=({model:e,row:t,column:n})=>{let r=Vb(vy(e,uh(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)(Lb,{model:r.model,field:r.field,value:r.value})},vA=(e,t,{resources:n,views:r})=>{let i=vu(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)(_A,{model:e,row:n,column:t})}},yA=(e,t,n,r)=>{let i=new Map(hA(fA(jm(e,t,[],n.filter(e=>!gA(e))),e,t,r.fieldTypes),e,r.resources,r.views).map(e=>[e.id,e]));return n.flatMap(t=>gA(t)?[vA(e,t,r)]:i.get(t)??[])},bA=(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},xA=(e,t,n)=>{if(e.open!==void 0)return e.open!==e.field&&bA(t,e.open,n)?e.open:void 0;let r=t.primaryKey.filter(r=>r!==e.field&&r!==t.tenant&&bA(t,r,n));return r.length===1?r[0]:void 0},SA=(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},CA=(e,t)=>(t?.names?.singular??F(e.name)).toLowerCase(),wA=({model:e,view:t,opens:n,resources:r,views:i,canUpdate:a})=>{let o=t=>({kind:`record`,resource:e.name,key:ym(e,t)}),s=n&&e.fields[n]?.relation?.resource,c=s?r[s]:void 0,l=e=>{let t=n&&c?SA(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=CA(e,t);return{address:u,actions:t=>{let n={label:MS(`open`,{singular:d}),link:e=>t(o(e))};if(!c)return[n];let r=e=>a&&sy(e,`update`);return[{label:MS(`open`,{singular:CA(c,i[c.name])}),available:e=>l(e)!==void 0,link:e=>t(l(e))},{label:MS(`edit`,{singular:d}),available:r,link:n=>t({kind:`record`,resource:e.name,key:ym(e,n),edit:!0})},{...n,available:e=>!r(e)}]}}},TA=({model:e,filter:t,orderBy:n,limit:r,fields:i})=>{let a=U(),o=Se(),{resources:s,views:c}=W();return E({queryKey:[...H.list(e.name,t,n,r,`embedded`),i.join(`,`)],placeholderData:d,queryFn:async()=>{let l=Cb(s,c,e,i),u=Im(c[e.name]),d=await a.search(e.name,{filter:t||void 0,orderBy:n||void 0,pageSize:r,count:`exact`,labels:l,photos:u});await kb(o,a,s,c,e,i,d.items);let f=wb(s,e,i,Lm(e,d.items,d.photos),d.labels).map((t,n)=>({...t,id:vm(e,d.items[n])}));return d.nextPageToken===``?{rows:f,total:f.length,estimated:!1}:{rows:f,total:d.totalSize??d.totalSizeEstimate,estimated:d.totalSize===void 0}}})},EA=({view:e,value:t,onChange:n})=>(0,B.jsx)(lA,{view:e,value:t,onChange:n,menu:!gf()}),DA=()=>(0,B.jsx)(`div`,{className:`flex flex-col gap-2`,children:Array.from({length:3},(e,t)=>(0,B.jsx)(vh,{className:`h-4 w-full`},t))}),OA=({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=oy(af(e.name),`update`),{fields:h}=c_(),{go:g,href:_}=Hh(),v=_f(),[y,b]=(0,I.useState)(r||dh(e,t)),x=i??Tr(e,t),S=(0,I.useMemo)(()=>yA(e,t,x,{resources:f,views:p,fieldTypes:h}),[e,t,x.join(`,`),f,p,h]),C=(0,I.useMemo)(()=>sh(e,t,S.map(e=>e.id)),[e,t,S]),w=TA({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=Zm(t,o),O=t?.names?.plural??F(e.name),k=u&&(0,B.jsxs)(Uh,{to:zS(e,t,v,l?{filter:l.filter,orderBy:dh(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:[MS(`viewAll`),` `,(0,B.jsx)(`span`,{className:`sr-only`,children:O.toLowerCase()})]}),(0,B.jsx)(Rr,{className:`size-3.5`,"aria-hidden":!0})]});if(w.isPending)return(0,B.jsx)(DA,{});if(w.error)return(0,B.jsx)(Bg,{title:MS(`couldNotLoad`),error:w.error});if(!E||E.total===0){let e=(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:s??MS(`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=>uh(e,t)),total:w.data.total,loading:!1,error:null,more:!1,loadMore:()=>void 0},j=wA({model:e,view:t,opens:d,resources:f,views:p,canUpdate:m}),ee=e=>({href:_(e),onFollow:()=>g(e)}),te=NS(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)(Sk,{model:e,view:t,display:D,list:A,row:c||v,footer:!1}):D.kind===`map`?(0,B.jsx)(aA,{model:e,view:t,display:D,filter:n,orderBy:y,fields:C,footer:!1}):D.kind===`board`?(0,B.jsx)(fO,{model:e,view:t,display:D,fields:C,filter:n,orderBy:y,limit:a}):D.kind===`calendar`?(0,B.jsx)(XO,{model:e,view:t,display:D,fields:C,filter:n}):D.kind===`timeline`?(0,B.jsx)(_k,{model:e,view:t,display:D,fields:C,filter:n}):(0,B.jsx)(Dk,{display:D,list:A}):(0,B.jsx)(mw,{fit:!0,columns:S,source:E,latencyMs:0,sort:fh(y),onSortChange:e=>b(ph(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]})},kA=(e,t,n)=>{let r=_f(),i=FS(t),[a,o]=(0,I.useState)(()=>IS(localStorage,i)),s=(0,I.useCallback)(e=>{o(e),LS(localStorage,i,e)},[i]);return[RS(e,r,{picked:a,preferred:n}),s]},AA=({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]=kA(t,`page:${e.name}:${s??``}:${n}`,o);return(0,B.jsx)(Ay,{title:s,description:c,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(EA,{view:t,value:d,onChange:f}),u]}),className:`h-full`,children:(0,B.jsx)(OA,{model:e,view:t,filter:n,sort:r,columns:i,limit:a,display:d,empty:l})})},jA=({node:e,slots:t})=>{let n=Dy(e),{resources:r,views:i}=W(),a=r[n.resource];return a?(0,B.jsx)(AA,{...n,model:a,view:i[a.name],actions:t.actions}):null},MA=({node:e,children:t})=>{let{tab:n,pathOf:r}=cf(),{navigate:i}=jh(),a=lf(e),o=df(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":sv(`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":sv(`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)(Bh,{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)(ov,{children:sv(`noTab`,{name:n??``})})]})},NA=({children:e})=>(0,B.jsx)(`div`,{className:`flex flex-col gap-6`,children:e}),PA=({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})]}),FA=({message:e})=>e?(0,B.jsx)(`p`,{role:`alert`,className:`mb-3 text-body font-medium text-danger-text`,children:e}):null,IA=M(`auth/errors`),LA={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`},RA=(e,t)=>{let n=t?e[t]:void 0;return n&&IA(n)},zA=e=>RA(LA,e.code),BA=e=>zA(e)??(e.status===429?IA(`tooManyRequests`):e.message),VA=e=>zA(e)??(e.status===429?IA(`tooManyRequests`):e.status===401?IA(`wrongEmailOrPassword`):e.message),HA={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`},UA=e=>RA(HA,typeof e==`string`?e:e.code)||(typeof e==`string`?IA(`staffFailed`):e.status===429?IA(`tooManyRequests`):e.message),WA={signup_disabled:e=>IA(`signupDisabled`,{name:e}),account_not_linked:e=>IA(`notLinked`,{name:e}),account_already_linked_to_different_user:e=>IA(`linkedToOther`,{name:e}),unable_to_link_account:e=>IA(`couldNotLink`,{name:e}),access_denied:e=>IA(`accessDenied`,{name:e}),EMAIL_DOMAIN_NOT_ALLOWED:e=>IA(`domainNotAllowed`,{name:e})},GA=(e,t)=>WA[e]?.(t)??IA(`providerFailed`,{name:t}),KA=()=>{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 wu))throw e;r(BA(e))}t(!1)},setError:r}},qA=M(`invitations`),JA=({link:e})=>e?(0,B.jsx)(`p`,{className:`mt-3 break-all rounded-md border bg-muted px-3 py-2 text-xs`,children:qA.rich(`passLinkOn`,{link:(0,B.jsx)(`span`,{className:`font-mono`,children:e})})}):null,YA=({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}=KA(),p=()=>f(async()=>{l((await n(o.trim())).link),s(``)});return(0,B.jsxs)(PA,{title:e,description:t,children:[(0,B.jsx)(FA,{message:d}),(0,B.jsxs)(`form`,{className:`flex flex-col gap-3`,onSubmit:e=>{e.preventDefault(),p()},children:[(0,B.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,B.jsx)(J,{"aria-label":qA(`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:qA(`invite`)})]}),i]}),(0,B.jsx)(JA,{link:c})]})},XA=({email:e,gives:t,expiresAt:n,onResend:r,onRevoke:i})=>{let[a,o]=(0,I.useState)(),{busy:s,error:c,run:l}=KA(),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?qA(`expired`):qA(`until`,{date:new Date(n).toLocaleDateString(Le())})]})]}),(0,B.jsx)(G,{size:`sm`,loading:s,onClick:()=>void l(async()=>o((await r()).link)),children:qA(`sendAgain`)}),(0,B.jsx)(G,{size:`sm`,variant:`danger`,loading:s,onClick:()=>void l(i),children:qA(`revoke`)})]}),(0,B.jsx)(FA,{message:c}),(0,B.jsx)(JA,{link:a})]})},X=M(`organizations`),ZA=({roles:e,selected:t,grantable:n,disabled:r,onChange:i})=>(0,B.jsx)(`div`,{className:`flex flex-wrap gap-x-4 gap-y-2`,children:e.map(e=>{let a=t.includes(e.name),o=r||!n.has(e.name);return(0,B.jsxs)(`label`,{title:o&&!r?X(`cannotChangeRole`):void 0,className:P(`inline-flex items-center gap-1.5`,o&&`text-muted-foreground`),children:[(0,B.jsx)(TC,{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)})}),QA=`/-/organizations`,$A=`/-/organization`,ej=`/-/organization/members`,tj=`/-/organization/invitations`,nj={[QA]:`organizations`,[$A]:`organization`,[ej]:`members`,[tj]:`invitations`},rj=e=>{let t=nj[e];return t&&X(t)},ij=e=>X(e),aj=(e,t)=>e.find(e=>e.name===t)?.label??t,oj=e=>e?.role===`owner`||e?.role===`admin`,sj=(e,t,n)=>{let r=(n,r,i,a)=>({id:n,label:r,icon:i,href:`${e}${a}`,active:t===a});return[r(`organizations`,X(`manageOrganizations`),jo,QA),...n?.organization?[r(`organization`,X(`organization`),mi,$A)]:[],...oj(n)?[r(`members`,X(`members`),ac,ej),r(`invitations`,X(`invitations`),co,tj)]:[]]},cj=(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)))},lj=(e,t)=>t.map(t=>aj(e,t)).join(`, `),uj=M(`users`),dj=({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)(YA,{title:uj(`inviteSomeone`),description:uj(`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)(ZA,{roles:e,selected:n,grantable:new Set(e.map(e=>e.name)),onChange:r})}),(0,B.jsx)(PA,{title:uj(`notAcceptedYet`),description:i.length>0?uj(`sendingAgain`):uj(`nobodyWaiting`),children:i.length>0&&(0,B.jsx)(`ul`,{className:`divide-y rounded-md border`,children:i.map(n=>(0,B.jsx)(XA,{email:n.email,gives:lj(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))})})]})},fj=({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)(Tx,{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})]})}),pj=({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)(fj,{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)(fj,{title:z(`choosePassword`),description:z(`atLeast`,{length:12}),children:(0,B.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:t=>{t.preventDefault(),d(o!==c),o===c&&e(o)},children:[(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[z(`newPassword`),(0,B.jsx)(J,{type:`password`,name:`new-password`,autoComplete:`new-password`,required:!0,minLength:12,autoFocus:!0,value:o,invalid:!!f,onChange:e=>s(e.target.value),className:`min-h-6`})]}),(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[z(`repeatPassword`),(0,B.jsx)(J,{type:`password`,name:`repeat-password`,autoComplete:`new-password`,required:!0,minLength:12,value:c,invalid:!!f,onChange:e=>l(e.target.value),className:`min-h-6`})]}),f&&(0,B.jsx)(`p`,{role:`alert`,className:`text-body font-medium text-danger-text`,children:f}),(0,B.jsx)(G,{variant:`primary`,type:`submit`,loading:i,className:`min-h-10`,children:z(`setPassword`)})]})})},mj=({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}=KA(),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)(PA,{title:uj(`addAnAccount`),description:uj(`addDescription`),children:[(0,B.jsx)(FA,{message:f}),(0,B.jsxs)(`form`,{className:`flex flex-col gap-3`,onSubmit:e=>{e.preventDefault(),m()},children:[(0,B.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,B.jsx)(J,{"aria-label":uj(`email`),type:`email`,placeholder:`name@example.com`,value:r,onChange:e=>i(e.target.value),wrapperClassName:`flex-1`}),(0,B.jsx)(J,{"aria-label":uj(`name`),placeholder:uj(`name`),autoComplete:`off`,value:a,onChange:e=>o(e.target.value),wrapperClassName:`flex-1`})]}),(0,B.jsx)(J,{"aria-label":uj(`password`),type:`password`,autoComplete:`new-password`,placeholder:uj(`passwordOptional`,{length:12}),value:s,onChange:e=>c(e.target.value)}),(0,B.jsx)(ZA,{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:uj(`addAccount`)})})]})]})},hj=M(`lists`),gj=({title:e,description:t,searchLabel:n,placeholder:r,query:i,onQuery:a,list:o,error:s,renderRow:c})=>(0,B.jsxs)(PA,{title:e,description:t,children:[(0,B.jsx)(FA,{message:s}),(0,B.jsx)(J,{"aria-label":n,placeholder:r,value:i,onChange:e=>a(e.target.value),leading:(0,B.jsx)(ss,{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:hj(`showMore`)})]}),_j=(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}},vj=({name:e,email:t,self:n,actions:r,children:i,error:a,status:o})=>(0,B.jsxs)(`li`,{className:`flex flex-col gap-2 px-3 py-3`,children:[(0,B.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,B.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[o?(0,B.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,B.jsxs)(`span`,{className:`truncate font-medium`,children:[e,n&&` (you)`]}),o]}):(0,B.jsxs)(`span`,{className:`block truncate font-medium`,children:[e,n&&` (you)`]}),(0,B.jsx)(`span`,{className:`block truncate text-xs text-muted-foreground`,children:t})]}),r]}),i,(0,B.jsx)(FA,{message:a})]}),yj=({user:e,roles:t,self:n})=>{let{session:r}=V(),[i,a]=(0,I.useState)(e),{busy:o,error:s,run:c,setError:l}=KA(),u=e=>{if(e.length===0)return l(uj(`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)(vj,{name:i.name,email:i.email,self:n,error:s,actions:(0,B.jsxs)(B.Fragment,{children:[i.blocked&&(0,B.jsx)(Pf,{tone:`red`,children:uj(`blocked`)}),!n&&(i.blocked?(0,B.jsx)(G,{size:`sm`,loading:o,onClick:()=>d(!1),children:uj(`unblock`)}):(0,B.jsx)(G,{size:`sm`,variant:`danger`,loading:o,onClick:()=>d(!0),children:uj(`block`)}))]}),children:(0,B.jsx)(ZA,{roles:t,selected:i.roles,grantable:new Set(t.map(e=>e.name)),disabled:o,onChange:u})})},bj=({roles:e,version:t})=>{let{session:n,state:r}=V(),[i,a]=(0,I.useState)(``),o=_j((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)(gj,{title:uj(`people`),description:uj(`peopleDescription`),searchLabel:uj(`findSomeone`),placeholder:uj(`emailAddress`),query:i,onQuery:a,list:o,renderRow:n=>(0,B.jsx)(yj,{user:n,roles:e,self:n.id===s},`${t}/${n.id}`)})},xj=()=>{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 wu?BA(e):uj(`couldNotReadRoles`)))},[e]),{roles:t,error:r}},Sj=()=>{let{roles:e,error:t}=xj(),[n,r]=(0,I.useState)(0);return(0,B.jsxs)(`div`,{className:`flex max-w-3xl flex-col gap-4`,children:[(0,B.jsx)(FA,{message:t}),(0,B.jsx)(bj,{roles:e,version:n}),(0,B.jsx)(dj,{roles:e}),(0,B.jsx)(mj,{roles:e,onCreated:()=>r(e=>e+1)})]})},Cj=({providers:e,linked:t,onConnect:n,error:r,title:i=L(`connectedAccounts`),description:a=L(`connectedAccountsDescription`)})=>{let[o,s]=(0,I.useState)(),[c,l]=(0,I.useState)(r),u=async e=>{s(e),l(void 0);try{await n(e)}catch(e){if(!(e instanceof wu))throw e;l(BA(e)),s(void 0)}};return(0,B.jsxs)(PA,{title:i,description:a,children:[(0,B.jsx)(FA,{message:c}),(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)(Xa,{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)(Pf,{tone:`green`,children:L(`connected`)}):(0,B.jsx)(G,{size:`sm`,loading:o===e.id,disabled:o!==void 0,onClick:()=>void u(e.id),children:L(`connect`,{name:e.name})})]},e.id))})]})},wj=({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)($d,{}),` `,L(`loading`)]}),Tj=(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 wu?BA(e):t))},[e,t]);return(0,I.useEffect)(o,[o]),{data:n?.value,loaded:n!==void 0,error:i,reload:o}},Ej=()=>{let e=Cd(window.location.href);return e&&window.history.replaceState(window.history.state,``,wd(window.location.href)),e},Dj=({providers:e})=>{let{session:t,linkProvider:n}=V(),{account:r}=t,[i]=(0,I.useState)(Ej),{data:a,error:o}=Tj((0,I.useCallback)(()=>r.linkedProviders(),[r]),L(`couldNotReadMethods`));return a?(0,B.jsx)(Cj,{providers:e,linked:a,onConnect:n,error:i&&GA(i,e.length===1?e[0].name:L(`theProvider`))}):(0,B.jsx)(wj,{error:o})},Oj=({signInProviders:e,socialProviders:t})=>e.filter(e=>t.includes(e.id)),kj=()=>{let e=Oj(V());return e.length>0?(0,B.jsx)(Dj,{providers:e}):null},Aj=({links:e})=>{let{session:t,linkPersonalMail:n}=V(),{account:r}=t,[i]=(0,I.useState)(Ej),{data:a,error:o}=Tj((0,I.useCallback)(()=>r.linkedPersonalMail(e),[r,e]),L(`couldNotReadMethods`));return a?(0,B.jsx)(Cj,{title:L(`mailbox`),description:L(`mailboxDescription`),providers:e.map(({id:e,name:t})=>({id:e,name:t})),linked:a,onConnect:t=>n(e.find(e=>e.id===t)),error:i&&GA(i,e.length===1?e[0].name:L(`theProvider`))}):(0,B.jsx)(wj,{error:o})},jj=()=>{let{personalMail:e}=V();return e.length>0?(0,B.jsx)(Aj,{links:e}):null},Mj=/[\u0000-\u001f\u007f-\u009f\u00ad\u061c\u115f\u1160\u180e\u200b-\u200f\u2028-\u202e\u2060-\u206f\u3164\ufe00-\ufe0f\ufeff]/g,Nj=e=>{let t=(e??``).replace(Mj,` `).replace(/\s+/g,` `).trim();if(t)return t.length>60?`${t.slice(0,59)}…`:t},Pj=e=>{if(!URL.canParse(e))return;let t=new URL(e);return t.protocol===`https:`?t.host:void 0},Fj=e=>Nj(e.name)??`An unnamed app`,Ij=e=>e.access.map(({role:e,organization:t})=>`as ${e||`no role`}${t?` in ${t}`:``}`).join(`, `),Lj=({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 wu))throw e;a(BA(e))}r(!1)};return(0,B.jsxs)(PA,{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)(FA,{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=Pj(e.clientId);return(0,B.jsxs)(`li`,{className:`flex flex-wrap items-center gap-3 px-3 py-2.5`,children:[(0,B.jsx)(fi,{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:Fj(e)}),(0,B.jsxs)(`span`,{className:`block text-xs text-muted-foreground`,children:[t&&`Published by ${t} · `,`Allowed `,cp(Date.parse(e.allowedAt)),` · `,Ij(e)]})]}),(0,B.jsx)(G,{size:`sm`,variant:`ghost`,onClick:()=>s(e),children:`Disconnect`})]},e.clientId)})}),o&&(0,B.jsx)(Cf,{title:`Disconnect ${Fj(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)(FA,{message:i})})]})},Rj=(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},zj=({url:e,appName:t})=>{let[n,r]=(0,I.useState)(!1);return(0,B.jsx)(PA,{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)(Si,{className:`size-4 text-success`}):(0,B.jsx)(Ji,{className:`size-4`})})]}),(0,B.jsxs)(`a`,{href:Rj(e,t),target:`_blank`,rel:`noreferrer`,className:mf(),children:[(0,B.jsx)(ua,{className:`size-3.5`}),L(`addToClaude`)]})]})})},Bj=()=>{let{account:e}=V().session,{data:t,error:n,reload:r}=Tj((0,I.useCallback)(()=>e.connectedApps(),[e]),L(`couldNotReadMethods`));return t?(0,B.jsx)(Lj,{apps:t,onDisconnect:t=>e.disconnectApp(t).then(r)}):(0,B.jsx)(wj,{error:n})},Vj=({url:e})=>(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(zj,{url:e,appName:W().appName}),(0,B.jsx)(Bj,{})]}),Hj=()=>{let{mcp:e}=V();return e?(0,B.jsx)(Vj,{url:e.url}):null},Uj=e=>e.code===`LAST_ADMIN`?L(`deleteAccountLastAdmin`):e.code===`ACCOUNT_LOCKED`?L(`deleteAccountLocked`):BA(e),Wj=({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 wu))throw e;c(Uj(e)),o(!1)}};return(0,B.jsx)(Cf,{title:L(`deleteAccountQuestion`),description:L(`deleteAccountWarning`),onClose:n,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:n,children:L(`cancel`)}),(0,B.jsx)(G,{variant:`danger`,type:`submit`,form:l,loading:a,disabled:e&&!r,children:L(`deleteAccountConfirm`)})]}),children:(0,B.jsxs)(`form`,{id:l,className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),u()},children:[e&&(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[L(`deleteAccountPassword`),(0,B.jsx)(J,{type:`password`,name:`current-password`,autoComplete:`current-password`,autoFocus:!0,value:r,invalid:!!s,onChange:e=>i(e.target.value)})]}),(0,B.jsx)(FA,{message:s})]})})},Gj=({hasPassword:e,staff:t,onDelete:n})=>{let[r,i]=(0,I.useState)(!1);return(0,B.jsxs)(PA,{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)(Wj,{hasPassword:e,onDelete:n,onClose:()=>i(!1)})]})},Kj=()=>{let{session:e,state:t,deleteAccount:n}=V(),{account:r}=e,{data:i,error:a}=Tj((0,I.useCallback)(()=>r.signInMethods(),[r]),L(`couldNotReadMethods`));return i?(0,B.jsx)(Gj,{hasPassword:i.account.password,staff:t.kind===`signed-in`&&!!t.staff,onDelete:n}):(0,B.jsx)(wj,{error:a})},qj=[[/Edg(e|A|iOS)?\//,`Edge`],[/OPR\/|Opera/,`Opera`],[/SamsungBrowser\//,`Samsung Internet`],[/Firefox\/|FxiOS\//,`Firefox`],[/Chrome\/|CriOS\//,`Chrome`],[/Safari\//,`Safari`]],Jj=[[/iPhone/,`iPhone`],[/iPad/,`iPad`],[/Android/,`Android`],[/CrOS/,`ChromeOS`],[/Windows/,`Windows`],[/Mac OS X|Macintosh/,`macOS`],[/Linux/,`Linux`]],Yj=(e,t)=>e.find(([e])=>e.test(t))?.[1],Xj=e=>e?{browser:Yj(qj,e),system:Yj(Jj,e)}:{},Zj=(e,t)=>{if(e.staff)return t?L(`staffOf`,{operator:t}):L(`staff`);let{browser:n,system:r}=Xj(e.userAgent);return n&&r?L(`browserOn`,{browser:n,system:r}):r?L(`aBrowserOn`,{system:r}):n??L(`unknownDevice`)},Qj=e=>{if(e.staff)return ys;let{system:t}=Xj(e.userAgent);return t===`iPhone`||t===`Android`?Ts:t===`iPad`?zs:Ba},$j=e=>[...e].sort((e,t)=>Number(t.current)-Number(e.current)||t.createdAt.localeCompare(e.createdAt)),eM=({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 wu))throw e;s(BA(e))}a(!1)},f=e=>{s(void 0),l(e)};return(0,B.jsxs)(PA,{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:$j(e).map(e=>{let n=Qj(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:Zj(e,t)}),e.current&&(0,B.jsx)(Pf,{tone:`green`,children:L(`thisDevice`)})]}),(0,B.jsxs)(`span`,{className:`block text-xs text-muted-foreground`,children:[L(`signedInFromUntil`,{from:dp(Date.parse(e.createdAt)),until:dp(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)(Cf,{title:c.kind===`one`?L(`signOutDevice`,{name:Zj(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)(FA,{message:o})})]})},tM=()=>{let{session:e,staffSignIn:t}=V(),{account:n}=e,{data:r,error:i,reload:a}=Tj((0,I.useCallback)(()=>n.sessions(),[n]),L(`couldNotReadDevices`));return r?(0,B.jsx)(eM,{sessions:r,operator:t,onSignOut:e=>n.revokeSession(e).then(a),onSignOutOthers:()=>n.revokeOtherSessions().then(a)}):(0,B.jsx)(wj,{error:i})},nM={allowed:`passkeysAllowed`,required:`passkeysRequired`,forbidden:`passkeysForbidden`},rM=({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 wu))throw e;c(BA(e))}o(!1)};return(0,B.jsxs)(PA,{title:L(`passkeys`),status:e===`required`&&(0,B.jsx)(Pf,{tone:`blue`,children:L(`required`)}),description:L(nM[e]),children:[(0,B.jsx)(FA,{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)(Ia,{className:`size-4 shrink-0 text-muted-foreground`}),(0,B.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,B.jsx)(`span`,{className:`block truncate font-medium`,children:e.name??L(`passkey`)}),(0,B.jsxs)(`span`,{className:`block text-xs text-muted-foreground`,children:[e.createdAt?L(`addedOn`,{date:cp(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)(qo,{className:`size-3.5`}),L(`addPasskey`)]}),l?.kind===`rename`&&(0,B.jsxs)(Cf,{title:L(`renamePasskey`),description:L(`renamePasskeyDescription`),onClose:()=>u(void 0),actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:()=>u(void 0),children:L(`cancel`)}),(0,B.jsx)(G,{variant:`primary`,loading:a,disabled:!d.trim(),onClick:()=>void m(()=>r(l.passkey.id,d.trim())),children:L(`save`)})]}),children:[(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[L(`name`),(0,B.jsx)(J,{autoFocus:!0,value:d,maxLength:60,onChange:e=>f(e.target.value)})]}),(0,B.jsx)(FA,{message:s})]}),l?.kind===`remove`&&(0,B.jsx)(Cf,{title:L(`removePasskey`),description:L(`removePasskeyDescription`,{name:l.passkey.name??L(`thisPasskey`)}),onClose:()=>u(void 0),actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:()=>u(void 0),children:L(`cancel`)}),(0,B.jsx)(G,{variant:`danger`,loading:a,onClick:()=>void m(()=>i(l.passkey.id)),children:L(`remove`)})]}),children:s&&(0,B.jsx)(FA,{message:s})})]})},iM=()=>{let{account:e}=V().session,{data:t,error:n,reload:r}=Tj((0,I.useCallback)(()=>Promise.all([e.signInMethods(),e.passkeys()]),[e]),L(`couldNotReadMethods`));if(!t)return(0,B.jsx)(wj,{error:n});let[i,a]=t;return(0,B.jsx)(rM,{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)})},aM=e=>e.code===`PASSWORD_TOO_SHORT`?L(`useAtLeast`,{length:12}):e.code===`PASSWORD_TOO_LONG`?L(`passwordTooLong`):BA(e),oM=(e,t)=>{if(e.length<12)return L(`useAtLeast`,{length:12});if(e!==t)return L(`passwordsDiffer`)},sM=({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=oM(a,s);if(m(e),!e){f(!0);try{await t({current:r,next:a,signOutOthers:l})}catch(e){if(!(e instanceof wu))throw e;m(aM(e)),f(!1)}}};return(0,B.jsx)(Cf,{title:L(e?`changePassword`:`setPassword`),description:L(`atLeast`,{length:12}),onClose:n,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:n,children:L(`cancel`)}),(0,B.jsx)(G,{variant:`primary`,type:`submit`,form: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)(J,{type:`password`,name:`current-password`,autoComplete:`current-password`,autoFocus:!0,value:r,onChange:e=>i(e.target.value)})]}),(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[L(`newPassword`),(0,B.jsx)(J,{type:`password`,name:`new-password`,autoComplete:`new-password`,autoFocus:!e,value:a,invalid:!!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)(J,{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)(TC,{checked:l,onChange:u,label:L(`signOutOthers`)}),L(`signOutOthers`)]}),(0,B.jsx)(FA,{message:p})]})})},cM=({rule:e,hasPassword:t,staff:n})=>L(n?`passwordStaff`:e===`forbidden`?`passwordForbidden`:t?`passwordIsSet`:`passwordNotSet`),lM=({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)(PA,{title:L(`password`),description:cM({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)(sM,{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)}})]})},uM=()=>{let{session:e,state:t}=V(),{account:n}=e,{data:r,error:i,reload:a}=Tj((0,I.useCallback)(()=>n.signInMethods(),[n]),L(`couldNotReadMethods`));return r?(0,B.jsx)(lM,{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)(wj,{error:i})},dM=({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 wu))throw e;p(BA(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)(Cf,{title:L(`changeEmail`),description:L(`codeSentTo`,{email: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)(x_,{name:`code`,required:!0,autoFocus:!0,value:c,invalid:!!f,onChange:l,onComplete:e=>!u&&void _(e)})]}),(0,B.jsx)(FA,{message:f})]}):(0,B.jsxs)(Cf,{title:L(`changeEmail`),description:L(`changeEmailDescription`),onClose:r,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:r,children:L(`cancel`)}),(0,B.jsx)(G,{variant:`primary`,loading:u,disabled:!h||h.toLowerCase()===e.toLowerCase(),onClick:()=>void g(),children:L(`sendCode`)})]}),children:[(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[L(`newEmail`),(0,B.jsx)(J,{type:`email`,autoComplete:`email`,autoFocus:!0,value:i,onChange:e=>a(e.target.value)})]}),(0,B.jsx)(FA,{message:f})]})},fM=({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 wu))throw e;m(BA(e))}f(!1)};return(0,B.jsxs)(PA,{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)(Cf,{title:L(`changeName`),description:L(`changeNameDescription`),onClose:()=>o(!1),actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:()=>o(!1),children:L(`cancel`)}),(0,B.jsx)(G,{variant:`primary`,loading:d,disabled:!l.trim()||l.trim()===e,onClick:()=>void h(),children:L(`save`)})]}),children:[(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[L(`name`),(0,B.jsx)(J,{autoFocus:!0,value:l,maxLength:100,onChange:e=>u(e.target.value)})]}),(0,B.jsx)(FA,{message:p})]}),s&&r&&(0,B.jsx)(dM,{email:t,change:r,onClose:()=>c(!1),onDone:()=>{c(!1),i?.()}})]})},pM=()=>{let{session:e,changeEmail:t}=V(),{data:n,loaded:r,error:i,reload:a}=Tj((0,I.useCallback)(()=>e.session(),[e]),L(`couldNotReadProfile`));if(!r)return(0,B.jsx)(wj,{error:i});if(!n)return null;let o=t?{request:e.account.requestEmailChange,confirm:e.account.changeEmail}:void 0;return(0,B.jsx)(fM,{name:n.name,email:n.email,onRename:t=>e.account.updateName(t).then(a),emailChange:o,onEmailChanged:a})},mM=(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)},hM=({codes:e})=>{let[t,n]=(0,I.useState)(!1),r=`${e.join(`
|
|
4
|
-
`)}\n`;return(0,B.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,B.jsx)(`ul`,{"aria-label":L(`backupCodes`),className:`grid grid-cols-2 gap-x-4 gap-y-1 rounded-md border bg-surface p-3 font-mono`,children:e.map(e=>(0,B.jsx)(`li`,{children:e},e))}),(0,B.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,B.jsxs)(G,{size:`sm`,onClick:()=>{navigator.clipboard.writeText(r).then(()=>{n(!0),setTimeout(()=>n(!1),2e3)})},children:[t?(0,B.jsx)(Si,{className:`size-3.5 text-success`}):(0,B.jsx)(Ji,{className:`size-3.5`}),L(t?`copied`:`copy`)]}),(0,B.jsxs)(G,{size:`sm`,onClick:()=>mM(r,`backup-codes.txt`),children:[(0,B.jsx)(na,{className:`size-3.5`}),L(`download`)]})]})]})},gM=({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 wu))throw e;f(BA(e)),u(!1)}};return(0,B.jsxs)(Cf,{title:e,description:t,onClose:o,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:o,children:L(`cancel`)}),(0,B.jsx)(G,{variant:r?`danger`:`primary`,loading:l,disabled:i&&!s,onClick:()=>void p(),children:n})]}),children:[i&&(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[L(`yourPassword`),(0,B.jsx)(J,{type:`password`,autoComplete:`current-password`,autoFocus:!0,value:s,invalid:!!d,onChange:e=>c(e.target.value),onKeyDown:e=>e.key===`Enter`&&s&&void p()})]}),d&&(0,B.jsx)(`p`,{role:`alert`,className:`mt-2 text-body font-medium text-danger-text`,children:d})]})},_M=({uri:e,className:t})=>{let{size:n,path:r}=(0,I.useMemo)(()=>{let t=Ce(e,{ecc:`M`,border:2}),n=t.data.flatMap((e,t)=>e.flatMap((e,n)=>e?[`M${n} ${t}h1v1h-1z`]:[]));return{size:t.size,path:n.join(``)}},[e]);return(0,B.jsxs)(`svg`,{viewBox:`0 0 ${n} ${n}`,role:`img`,"aria-label":L(`qrCode`),shapeRendering:`crispEdges`,className:t,children:[(0,B.jsx)(`rect`,{width:n,height:n,fill:`#fff`}),(0,B.jsx)(`path`,{d:r,fill:`#000`})]})},vM=e=>(new URL(e).searchParams.get(`secret`)??``).replace(/(.{4})(?=.)/g,`$1 `),yM=()=>[{value:`app`,label:L(`authenticatorApp`),description:L(`authenticatorAppDescription`)},{value:`email`,label:L(`emailedCode`),description:L(`emailedCodeDescription`)}],bM=({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?yM():yM().filter(e=>e.value===`app`),b=async e=>{g(!0),v(void 0);try{await e()}catch(e){if(!(e instanceof wu))throw e;v(BA(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)(hM,{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)(_M,{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:vM(s.setup.totpURI)})]})]}),(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[L(`codeFromApp`),(0,B.jsx)(x_,{name:`code`,required:!0,autoFocus:!0,value:p,invalid:!!_,onChange:m,onComplete:e=>!h&&void S(s.setup,e)})]}),C,(0,B.jsx)(G,{variant:`primary`,type:`submit`,loading:h,className:`min-h-10`,children:L(`turnOn`)}),o&&(0,B.jsx)(G,{variant:`ghost`,onClick:o,className:`min-h-10`,children:L(`cancel`)})]}):(0,B.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),x()},children:[(0,B.jsx)(`div`,{role:`radiogroup`,"aria-label":L(`secondStep`),className:`flex flex-col gap-2`,children:y.map(e=>(0,B.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":l===e.value,onClick:()=>u(e.value),className:P(`rounded-md border p-3 text-left transition-colors`,l===e.value?`border-primary bg-primary-soft`:`border-border-strong hover:bg-muted`),children:[(0,B.jsx)(`span`,{className:`block font-medium`,children:e.label}),(0,B.jsx)(`span`,{className:`mt-0.5 block text-xs text-muted-foreground`,children:e.description})]},e.value))}),t&&(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[L(`yourPassword`),(0,B.jsx)(J,{type:`password`,name:`password`,autoComplete:`current-password`,required:!0,value:d,invalid:!!_,onChange:e=>f(e.target.value),className:`min-h-6`})]}),C,(0,B.jsx)(G,{variant:`primary`,type:`submit`,loading:h,className:`min-h-10`,children:L(`continue`)}),o&&(0,B.jsx)(G,{variant:`ghost`,onClick:o,className:`min-h-10`,children:L(`cancel`)})]})},xM={allowed:`twoFactorAllowed`,required:`twoFactorRequired`,forbidden:`twoFactorForbidden`},SM=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)(Pf,{tone:`green`,children:L(`on`)}):t===`required`?(0,B.jsx)(Pf,{tone:`amber`,children:L(`required`)}):(0,B.jsx)(Pf,{children:L(`off`)}),p=L(n?r?i?`twoFactorOnWithAppOrMail`:`twoFactorOnWithApp`:`twoFactorOnWithMail`:xM[t]);return l?.kind===`setup`?(0,B.jsx)(PA,{title:L(`twoFactor`),status:f,description:p,children:(0,B.jsx)(`div`,{className:`max-w-sm`,children:(0,B.jsx)(bM,{offerEmailedCodes:i&&!l.appOnly,needsPassword:a,onStartApp:e.onStartApp,onConfirmApp:e.onConfirmApp,onEmailedCodes:e.onEmailedCodes,onCancel:d,onDone:()=>{d(),c()}})})}):(0,B.jsxs)(PA,{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)(gM,{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)(gM,{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)(Cf,{title:L(`yourNewCodes`),description:L(`keepCodesSafe`),onClose:d,actions:(0,B.jsx)(G,{variant:`primary`,onClick:d,children:L(`savedCodes`)}),children:(0,B.jsx)(hM,{codes:l.codes})})]})},CM={Page:wS,Grid:Yb,Card:My,Stat:OD,RecordCard:OS,Field:Wb,Table:jA,CardRow:Py,RecordRow:vD,RecordCards:qS,Chart:yb,Progress:ES,ModalForm:fx,Action:ky,Show:wD,Link:Zb,Settings:SD,Tabs:MA,Tab:NA,Users:Sj,Profile:pM,Password:uM,Passkeys:iM,TwoFactor:()=>{let{account:e}=V().session,{data:t,error:n,reload:r}=Tj((0,I.useCallback)(()=>e.signInMethods(),[e]),L(`couldNotReadMethods`));return t?(0,B.jsx)(SM,{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)(wj,{error:n})},ConnectedAccounts:kj,PersonalMail:jj,Devices:tM,ConnectedApps:Hj,DeleteAccount:Kj},wM=e=>typeof e==`string`||!e.custom&&e.type===`Link`,TM=e=>{let t=[];for(let n of e){let e=t.at(-1);wM(n)&&e&&wM(e[0])?e.push(n):t.push([n])}return t.map((e,t)=>{let[n]=e;return wM(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)(OM,{node:e},t))},t):(0,B.jsx)(OM,{node:n},t)})},EM=e=>ru(e)||Array.isArray(e)&&e.length>0&&e.every(ru),DM=e=>Object.fromEntries(Object.entries(e.props).flatMap(([e,t])=>EM(t)?[[e,(0,B.jsx)(B.Fragment,{children:TM(Array.isArray(t)?t:[t])})]]:[])),OM=({node:e})=>{let{components:t}=c_();if(e.custom){let n=t?.[e.type];return n?(0,B.jsx)(cv,{name:e.type,children:(0,B.jsx)(n,{...vn(e.props),children:e.children.length>0?TM(e.children):void 0})}):(0,B.jsx)(ov,{children:sv.rich(`noComponent`,{component:e.type})})}let n=CM[e.type];return n?(0,B.jsx)(n,{node:e,slots:DM(e),children:TM(e.children)}):(0,B.jsx)(ov,{children:sv.rich(`unknownBlock`,{type:e.type})})},kM=(e,t)=>{let n=uu(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},AM=()=>{let{account:e}=W(),t=V(),{mcp:n,accountDeletion:r}=t,i=Oj(t).length>0,a=t.personalMail.length>0;return(0,I.useMemo)(()=>{if(!e)return;let t=new Set([...n?[]:[`ConnectedApps`],...i?[]:[`ConnectedAccounts`],...a?[]:[`PersonalMail`],...r?[]:[`DeleteAccount`]]);return{...e,tree:kM(e.tree,t)}},[e,n,i,a,r])},jM=({tab:e})=>{let t=AM();return t?(0,B.jsx)(sf,{route:{...e&&{tab:e},pathOf:Ec},children:(0,B.jsx)(OM,{node:t.tree})}):(0,B.jsx)(tf,{title:L(`noAccount`),children:L(`noAccountDescription`)})},MM=({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?[Dg(`title`,{noun:i})]:[],...s];let c=a??(o?void 0:e.key);return[...c?[c]:[],...s]},NM=(e,t)=>[...e.filter(Boolean),t].join(` · `),PM=e=>{(0,I.useEffect)(()=>{let t=document.title;return document.title=e,()=>{document.title=t}},[e])},FM=500,IM=(e=window)=>e.top!==e.self,LM=(e,t,n)=>{let r=!1,i,a=e=>{r!==e&&(r=e,n(e))},o=()=>{clearTimeout(i),a(!1)},s=()=>{o(),e.defaultView&&e.visibilityState===`visible`&&e.hasFocus()&&(i=setTimeout(()=>a(!0),t))},c=()=>e.visibilityState===`visible`?s():o(),l=()=>{r||s()},u=e=>{`persisted`in e&&e.persisted&&s()};return e.defaultView?.addEventListener(`focus`,s),e.defaultView?.addEventListener(`blur`,o),e.defaultView?.addEventListener(`pagehide`,o),e.defaultView?.addEventListener(`pageshow`,u),e.addEventListener(`visibilitychange`,c),e.addEventListener(`pointerdown`,l,!0),e.addEventListener(`keydown`,l,!0),s(),()=>{clearTimeout(i),e.defaultView?.removeEventListener(`focus`,s),e.defaultView?.removeEventListener(`blur`,o),e.defaultView?.removeEventListener(`pagehide`,o),e.defaultView?.removeEventListener(`pageshow`,u),e.removeEventListener(`visibilitychange`,c),e.removeEventListener(`pointerdown`,l,!0),e.removeEventListener(`keydown`,l,!0)}},RM=()=>{let e=!1;return{down:(t,n=!1)=>{e=t&&!n},take:()=>{let t=e;return e=!1,t}}},zM=(e,t)=>n=>n?e(!0):t(()=>e(!1)),BM=e=>{let[t,n]=(0,I.useState)(!1);return(0,I.useEffect)(()=>LM(document,e,zM(n,Sc.flushSync)),[e]),t},VM=(e,t)=>{let n=(0,I.useRef)(RM());return{onPointerDown:()=>n.current.down(e),onKeyDown:t=>n.current.down(e,t.repeat),onClick:()=>{n.current.take()&&t()}}},HM=[`localhost`,`127.0.0.1`,`[::1]`],UM=[`javascript:`,`data:`,`vbscript:`,`file:`,`blob:`,`about:`],WM=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 HM.includes(t.hostname)?{kind:`this-computer`,port:t.port||`80`}:void 0;if(!UM.includes(t.protocol))return{kind:`device-app`,uri:e.split(`?`)[0].split(`#`)[0]}},GM=e=>!URL.canParse(e,`http://local`)||!UM.includes(new URL(e,`http://local`).protocol),KM=(e,t)=>{let n=new URL(e,t.origin);if(n.origin===t.origin&&n.pathname===t.pathname)return Kc(n.search).oauthQuery},qM=()=>{let{params:e}=jh();return(0,I.useMemo)(()=>Kc(e.toString()),[e])},JM={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.`},YM=e=>{if(!(e instanceof wu))throw e;return(e.code&&JM[e.code])??BA(e)},XM=e=>t=>{if(!GM(t))throw new wu(`The app asked to be sent somewhere this page will not go.`,400);e(t)},ZM=({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})]}),QM=({title:e,icon:t,children:n})=>(0,B.jsx)(fj,{title:e,icon:t,children:(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:n})}),$M=({asking:e,appName:t,appIcon:n,email:r,onAnswer:i,onSignOut:a})=>{let[o,s]=(0,I.useState)(!1),c=BM(500),l=e=>{s(!0),i(e).finally(()=>s(!1))},u=VM(c&&!o,()=>l(!0)),d=Nj(e.client.client_name),f=Pj(e.client.client_id),{target:p}=e;return(0,B.jsx)(fj,{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)(ZM,{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`})]})]})})},eN=({oauthQuery:e,appName:t,appIcon:n,email:r,assign:i})=>{let{session:a,signOut:o}=V(),{path:s,basePath:c}=jh(),l=XM(i),u=e=>KM(e,{origin:window.location.origin,pathname:`${c}${s}`}),[d,f]=(0,I.useState)({kind:`loading`}),p=e=>f({kind:`failed`,message:YM(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:WM(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)(QM,{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)($d,{}),` Loading`]}):(0,B.jsx)($M,{asking:d.asking,appName:t,appIcon:n,email:r,onAnswer:e=>m(e,d.asking),onSignOut:()=>void o()})},tN=({email:e,appName:t,appIcon:n,isFramed:r=IM,assign:i=e=>window.location.assign(e)})=>{let[a]=(0,I.useState)(r),{oauthQuery:o}=qM();return a?(0,B.jsxs)(QM,{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)(eN,{oauthQuery:o,appName:t,appIcon:n,email:e,assign:i},o):(0,B.jsx)(QM,{title:`Nothing to connect`,icon:n,children:`Connect again from your app.`})},nN={title:`Sign in to connect an app`,description:`An app asks to act as you here. Sign in, then choose whether to allow it.`},rN=()=>{let e=W(),{state:t}=V();return PM(NM([`Connect an app`],e.appName)),t.kind===`signed-in`?(0,B.jsx)(tN,{email:t.user.email,appName:e.appName??`this app`,appIcon:e.appIcon}):(0,B.jsx)(fj,{title:nN.title,description:nN.description,icon:e.appIcon,children:(0,B.jsx)(`div`,{className:`flex flex-col gap-2 [&>*]:min-h-10 [&>*]:w-full`,children:(0,B.jsx)(rE,{prompt:nN})})})},iN=()=>[{value:`allowed`,label:L(`on`)},{value:`forbidden`,label:L(`off`)}],aN=()=>[{value:`allowed`,label:L(`optional`)},{value:`required`,label:L(`required`)},{value:`forbidden`,label:L(`off`)}],oN=()=>[{method:`password`,label:L(`password`),description:L(`passwordDescription`),rules:iN()},{method:`emailCode`,label:L(`emailedSignInCode`),description:L(`emailedSignInCodeDescription`),rules:iN()},{method:`passkey`,label:L(`passkeys`),description:L(`passkeysPolicyDescription`),rules:aN()},{method:`twoFactor`,label:L(`twoFactor`),description:L(`twoFactorPolicyDescription`),rules:aN()},{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:iN()}],sN=(e,t)=>{let n=oN().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},cN=({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))}),lN=({method:e},t,{mail:n,effective:r,policy:i})=>{if(e===`emailCode`&&!n)return L(`codeNeedsMail`);if(e===`password`&&!n&&t.password===`forbidden`)return L(`passwordStaysOn`);if(e===`staffAccess`&&!n&&t.staffAccess===`notify`)return L(`staffNeedsMail`);if(e===`platformSignIn`&&t.platformSignIn===`allowed`&&(t.passkey===`required`||t.twoFactor===`required`))return L(`platformOff`);if(t[e]===i[e]&&r[e]!==i[e])return L(`appliesAs`,{rule:sN(e,r[e])})},uN=({operator:e,platformSignIn:t})=>oN().flatMap(n=>n.method===`staffAccess`&&!e?[]:n.method===`platformSignIn`?t?[{...n,label:L(`platformSignInWith`,{provider:t})}]:[]:[n]),dN=({state:e,onSave:t,busy:n,error:r,notice:i})=>{let[a,o]=(0,I.useState)(e.policy),s=uN(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=lN(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)(cN,{row:t,value:a[t.method],onChange:e=>o({...a,[t.method]:e})})]},t.method)})}),r&&(0,B.jsx)(`p`,{role:`alert`,className:`rounded-md bg-danger-soft px-3 py-2 text-body font-medium text-danger-text`,children:r}),i&&!c&&(0,B.jsx)(`p`,{role:`status`,className:`rounded-md bg-success-soft px-3 py-2 text-body font-medium text-success-text`,children:i}),(0,B.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.savedAt?e.savedBy?L(`lastSavedBy`,{name:e.savedBy,time:dp(Date.parse(e.savedAt))}):L(`lastSaved`,{time:dp(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`)})]})]})]})},fN=(e,t)=>e.endedAt?(0,B.jsx)(Pf,{tone:`neutral`,children:L(`stopped`,{time:dp(Date.parse(e.endedAt))})}):Date.parse(e.expiresAt)<=t?(0,B.jsx)(Pf,{tone:`neutral`,children:L(`ended`,{time:dp(Date.parse(e.expiresAt))})}):(0,B.jsx)(Pf,{tone:`amber`,children:L(`signedInUntil`,{time:dp(Date.parse(e.expiresAt))})}),pN=({signIns:e,operator:t,error:n,now:r=Date.now()})=>(0,B.jsxs)(PA,{title:L(`staffSignIns`),description:L(`staffSignInsDescription`,{operator:t}),children:[(0,B.jsx)(FA,{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:dp(Date.parse(e.startedAt))}),fN(e,r)]})]},e.id))})]}),mN=({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 wu?BA(e):L(`couldNotReadStaffSignIns`)))},[t]),(0,B.jsx)(pN,{operator:e,signIns:n,error:i})},hN=()=>{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 wu?BA(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 wu))throw e;o(BA(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)(SS,{title:L(`signInPolicy`),subtitle:L(`policySubtitle`)}),t?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(dN,{state:t,busy:r,error:a,notice:s,onSave:e=>void l(e)},t.savedAt??`default`),t.operator&&(0,B.jsx)(mN,{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)($d,{}),` `,L(`loading`)]})]})},gN=({onResend:e,cooldown:t=30,disabled:n})=>{let[r,i]=(0,I.useState)(()=>Date.now()+t*1e3),[a,o]=(0,I.useState)(()=>Date.now()),s=Math.max(0,Math.ceil((r-a)/1e3));return(0,I.useEffect)(()=>{if(s===0)return;let e=setInterval(()=>o(Date.now()),1e3);return()=>clearInterval(e)},[s]),(0,B.jsx)(G,{variant:`ghost`,disabled:n||s>0,onClick:()=>{let n=Date.now();i(n+t*1e3),o(n),e()},className:`min-h-10`,children:s>0?z(`sendNewCodeIn`,{seconds:s}):z(`sendNewCode`)})},_N=({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)(fj,{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)(x_,{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)(gN,{onResend:a,disabled:c,cooldown:d})]})]})]})},vN=({email:e,onBack:t,...n})=>(0,B.jsx)(_N,{title:z(`checkEmail`),description:z(`signInCodeDescription`),explanation:(0,B.jsx)(B.Fragment,{children:z.rich(`signInCodeSent`,{email:(0,B.jsx)(`span`,{className:`font-medium text-foreground`,children:e})})}),submitLabel:z(`signIn`),onChangeAddress:t,changeAddressLabel:z(`backToSignIn`),...n}),yN=({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 wu))throw e;s(BA(e))}a(!1)};return(0,B.jsx)(vN,{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`))})})},bN=`protobase users create you@example.com`,xN=({command:e=bN,firstAdminUrl:t,onCheckAgain:n,busy:r})=>(0,B.jsxs)(fj,{title:z(`noAdminTitle`),description:z(`noAdminDescription`),children:[t?(0,B.jsx)(SN,{url:t}):(0,B.jsx)(CN,{command:e}),(0,B.jsx)(G,{variant:t?`secondary`:`primary`,className:`mt-4 min-h-10 w-full`,loading:r,onClick:n,children:z(`reload`)})]}),SN=({url:e})=>(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:z(`firstAdminExplanation`)}),(0,B.jsxs)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,className:P(mf({variant:`primary`}),`mt-4 min-h-10 w-full`),children:[z(`firstAdminLink`),(0,B.jsx)(ua,{className:`size-4`})]})]}),CN=({command:e})=>{let[t,n]=(0,I.useState)(!1);return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:z(`noAdminExplanation`)}),(0,B.jsxs)(`div`,{className:`mt-4 flex items-center gap-2 rounded-md border bg-surface py-1.5 pl-3 pr-1.5`,children:[(0,B.jsx)(`code`,{className:`min-w-0 flex-1 break-all font-mono text-xs`,children:e}),(0,B.jsx)(`button`,{type:`button`,"aria-label":z(`copyCommand`),onClick:()=>{navigator.clipboard.writeText(e).then(()=>{n(!0),setTimeout(()=>n(!1),2e3)})},className:`inline-flex size-8 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-muted pointer-coarse:size-11`,children:t?(0,B.jsx)(Si,{className:`size-4 text-success`}):(0,B.jsx)(Ji,{className:`size-4`})})]})]})},wN=({onSubmit:e,back:t,busy:n,error:r,sentTo:i})=>{let[a,o]=(0,I.useState)(``);return i?(0,B.jsxs)(fj,{title:z(`checkEmail`),children:[(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:z.rich(`resetSent`,{email:(0,B.jsx)(`span`,{className:`font-medium text-foreground`,children:i})})}),(0,B.jsx)(Sh,{to:t,className:P(mf({variant:`primary`}),`mt-4 min-h-10 w-full`),children:z(`backToSignIn`)})]}):(0,B.jsx)(fj,{title:z(`resetTitle`),description:z(`resetDescription`),children:(0,B.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:t=>{t.preventDefault(),e(a.trim())},children:[(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[z(`email`),(0,B.jsx)(J,{type:`email`,name:`email`,autoComplete:`username`,required:!0,autoFocus:!0,value:a,invalid:!!r,onChange:e=>o(e.target.value),className:`min-h-6`})]}),r&&(0,B.jsx)(`p`,{role:`alert`,className:`text-body font-medium text-danger-text`,children:r}),(0,B.jsx)(G,{variant:`primary`,type:`submit`,loading:n,className:`min-h-10`,children:z(`sendResetLink`)}),(0,B.jsx)(Sh,{to:t,className:P(mf({variant:`ghost`}),`min-h-10`),children:z(`backToSignIn`)})]})})},TN=`password-reset`,EN=e=>{let t=new URL(e);return`${t.origin}${t.pathname}?${TN}`},DN=e=>{let t=new URL(e).searchParams;if(t.has(`password-reset`))return{token:t.get(`token`)||void 0}},ON=e=>{let t=new URL(e);for(let e of[TN,`token`,`error`])t.searchParams.delete(e);return`${t.pathname}${t.search}${t.hash}`},kN=({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,EN(window.location.href)),s(e)}catch(e){if(!(e instanceof wu))throw e;a(e.status===429?z(`tooManyRequests`):e.message)}r(!1)};return(0,B.jsx)(wN,{busy:n,error:i,sentTo:o,back:e,onSubmit:e=>void c(e)})},AN=({name:e,workspace:t})=>(0,B.jsx)(fj,{title:z(`signingInWith`,{name:e}),description:t,children:(0,B.jsxs)(`p`,{role:`status`,className:`flex items-center justify-center gap-2 text-muted-foreground`,children:[(0,B.jsx)($d,{}),` `,z(`takingYouTo`,{name:e})]})}),jN=({provider:e,workspace:t,onFailed:n})=>{let{signInProviders:r,signInSocial:i}=V(),a=r.find(t=>t.id===e),o=a?.name??Ed(e),s=(0,I.useRef)(!1);return(0,I.useEffect)(()=>{if(!s.current){if(s.current=!0,!a)return n(z(`providerNotOffered`,{name:o}));i(e).catch(e=>{if(!(e instanceof wu))throw e;n(VA(e))})}},[a,o,e,i,n]),(0,B.jsx)(AN,{name:o,workspace:t})},MN=e=>e.status===429?z(`tooManyAttempts`):e.code===`PASSWORD_TOO_SHORT`?z(`useAtLeast`,{length:12}):e.code===`PASSWORD_TOO_LONG`?z(`passwordTooLong`):BA(e),NN=({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 wu))throw e;e.code===`INVALID_TOKEN`?u(!0):c(MN(e)),o(!1)}};return(0,B.jsx)(pj,{busy:a,error:s,invalidLink:l,onRequestNewLink:n,onBack:r,onSubmit:e=>void d(e)})},PN=e=>z(e===`twoFactor`?`turnOnTwoFactor`:`addPasskey`),FN=({step:e,twoFactor:t,onAddPasskey:n,busy:r,error:i,onSignOut:a})=>(0,B.jsxs)(fj,{title:PN(e),description:z(`requiredForEveryAccount`),children:[e===`twoFactor`?(0,B.jsx)(bM,{...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)(Ia,{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`)})]}),IN=({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 wu?BA(e):z(`couldNotReadAccount`)))},[t]);let u=async()=>{s(!0),l(void 0);try{await t.account.addPasskey(),n()}catch(e){if(!(e instanceof wu))throw e;l(BA(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)($d,{}),` `,z(`loading`)]}):(0,B.jsx)(FN,{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}})},LN=({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`})}),RN=({id:e,className:t})=>e===`github`?(0,B.jsx)(LN,{className:t}):null,zN=()=>(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`})]}),BN=({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)(fj,{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)(RN,{id:e.id}),z(`continueWith`,{name:e.name})]},e.id)),w&&(0,B.jsxs)(G,{onClick:()=>c?.(),disabled:t,className:`min-h-10 w-full`,children:[(0,B.jsx)(Ia,{className:`size-4`}),z(`signInWithPasskey`)]}),w&&l.slice(1).map(e=>(0,B.jsx)(G,{variant:`ghost`,size:`sm`,onClick:()=>c?.(e),disabled:t,className:`w-full`,children:z(`passkeyFor`,{domain:e})},e))]}),S||C?(0,B.jsx)(zN,{}):n&&(0,B.jsx)(`p`,{role:`alert`,className:`mt-4 text-body font-medium text-danger-text`,children:n})]}),(S||C)&&(0,B.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:t=>{t.preventDefault(),D?e(h.trim(),_):O()},children:[(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[z(`email`),(0,B.jsx)(J,{ref:x,type:`email`,name:`email`,autoComplete:`username webauthn`,required:!0,autoFocus:!0,value:h,invalid:!!n,onChange:e=>g(e.target.value),className:`min-h-6`})]}),D&&(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[z(`password`),(0,B.jsx)(J,{type:`password`,name:`password`,autoComplete:`current-password`,required:!0,value:_,invalid:!!n,onChange:e=>v(e.target.value),className:`min-h-6`})]}),n&&(0,B.jsx)(`p`,{role:`alert`,className:`text-body font-medium text-danger-text`,children:n}),D&&(0,B.jsx)(G,{variant:`primary`,type:`submit`,loading:t,className:`min-h-10`,children:z(`signIn`)}),C&&(0,B.jsxs)(G,{variant:D?`secondary`:`primary`,type:D?`button`:`submit`,onClick:D?O:void 0,loading:t&&!D,disabled:t,className:`min-h-10`,children:[(0,B.jsx)(co,{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)(Sh,{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)(Sh,{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`)})]})},VN=({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 wu))throw e;v(t(e)),g(!1)}};return(0,B.jsx)(BN,{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),VA),passkeyDomains:f,onPasskey:e=>void y(()=>m(e),BA),onSendCode:e=>void y(async()=>{await p(e),a(e)},BA),onSubmit:(e,t)=>void y(()=>s(e,t),VA)})},HN=({email:e,onBack:t,...n})=>(0,B.jsx)(_N,{title:z(`checkEmail`),description:z(`signUpCodeDescription`),explanation:(0,B.jsx)(B.Fragment,{children:z.rich(`signUpCodeSent`,{email:(0,B.jsx)(`span`,{className:`font-medium text-foreground`,children:e})})}),submitLabel:z(`continue`),onChangeAddress:t,changeAddressLabel:z(`useAnotherAddress`),...n}),UN=({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)(fj,{title:z(`detailsTitle`),description:z(`detailsDescription`),children:[(0,B.jsx)(`p`,{className:`mb-4 text-muted-foreground`,children:z.rich(`codeWasRight`,{email:(0,B.jsx)(`span`,{className:`font-medium text-foreground`,children:e})})}),(0,B.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),t({name:o.trim(),...d&&c&&{password:c}})},children:[(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[z(`yourName`),(0,B.jsx)(J,{name:`name`,autoComplete:`name`,required:!0,autoFocus:!0,maxLength:200,value:o,onChange:e=>s(e.target.value),className:`min-h-6`})]}),d&&(0,B.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[z(f?`passwordOptional`:`password`),(0,B.jsx)(J,{type:`password`,name:`password`,autoComplete:`new-password`,"aria-describedby":u,required:!f,minLength:12,maxLength:128,value:c,onChange:e=>l(e.target.value),className:`min-h-6`})]}),(0,B.jsxs)(`p`,{id:u,className:`text-xs text-muted-foreground`,children:[z(`atLeast`,{length:12}),f&&z(`withoutPassword`)]})]}),a&&(0,B.jsx)(`p`,{role:`alert`,className:`text-body font-medium text-danger-text`,children:a}),(0,B.jsx)(G,{variant:`primary`,type:`submit`,loading:i,className:`min-h-10`,children:z(`createAccount`)}),(0,B.jsx)(G,{variant:`ghost`,onClick:n,className:`min-h-10`,children:z(`useAnotherAddress`)})]})]})},WN=({onSubmit:e,onSignIn:t,onBrowse:n,busy:r,error:i,workspace:a})=>{let[o,s]=(0,I.useState)(``);return(0,B.jsxs)(fj,{title:z(`createAnAccount`),description:a,children:[(0,B.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:t=>{t.preventDefault(),e(o.trim())},children:[(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[z(`email`),(0,B.jsx)(J,{type:`email`,name:`email`,autoComplete:`email`,required:!0,autoFocus:!0,value:o,invalid:!!i,onChange:e=>s(e.target.value),className:`min-h-6`})]}),(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:z(`codeToConfirm`)}),i&&(0,B.jsx)(`p`,{role:`alert`,className:`text-body font-medium text-danger-text`,children:i}),(0,B.jsxs)(G,{variant:`primary`,type:`submit`,loading:r,className:`min-h-10`,children:[(0,B.jsx)(co,{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`)})]})},GN=({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 wu))throw e;h(BA(e))}p(!1)};return t===void 0?(0,B.jsx)(WN,{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)(HN,{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)(UN,{email:t,methods:c,busy:f,error:m,onBack:a,onSubmit:e=>void v(()=>d({ticket:n,...e}))})},KN=`staff-sign-in`,qN=`staff-error`,JN=e=>{let t=new URL(e).searchParams,n=t.get(qN);if(!t.has(`staff-sign-in`)&&!n)return;let r=t.has(KN);return{email:r&&t.get(`email`)||``,reason:r&&t.get(`reason`)||``,...n&&{error:n}}},YN=e=>{let t=new URL(e);if(t.searchParams.has(`staff-sign-in`))for(let e of[KN,`email`,`reason`])t.searchParams.delete(e);return t.searchParams.delete(qN),`${t.pathname}${t.search}${t.hash}`},XN=10,ZN=({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)(fj,{title:z(`signInAsPerson`),description:z(`forStaffOf`,{operator:e}),children:(0,B.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),r(s.trim(),l.trim())},children:[(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[z(`theirEmail`),(0,B.jsx)(J,{type:`email`,name:`email`,required:!0,autoFocus:!t,value:s,onChange:e=>c(e.target.value),className:`min-h-6`})]}),(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[z(`reason`),(0,B.jsx)(`textarea`,{name:`reason`,required:!0,minLength:XN,rows:3,value:l,placeholder:z(`reasonExample`),onChange:e=>u(e.target.value),className:P(`resize-y rounded-md border bg-background px-2.5 py-1.5 font-normal shadow-sm outline-none placeholder:text-faint-foreground focus:border-primary focus:ring-2 focus:ring-primary/20`,o?`border-danger`:`border-border-strong`)})]}),(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:z(`staffExplanation`,{operator:e})}),o&&(0,B.jsx)(`p`,{role:`alert`,className:`text-body font-medium text-danger-text`,children:o}),(0,B.jsx)(G,{variant:`primary`,type:`submit`,loading:a,className:`min-h-10`,children:z(`continueWith`,{name:e})}),(0,B.jsx)(G,{variant:`ghost`,onClick:i,className:`min-h-10`,children:z(`backToSignIn`)})]})}):(0,B.jsxs)(fj,{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`)})]})},QN=({link:e,onBack:t})=>{let{session:n,staffSignIn:r}=V(),[i,a]=(0,I.useState)(!1),[o,s]=(0,I.useState)(e.error&&UA(e.error)),c=async(e,t)=>{a(!0),s(void 0);try{let r=`${window.location.origin}${YN(window.location.href)}`;window.location.assign(await n.staff.start({email:e,reason:t,callbackURL:r}))}catch(e){if(!(e instanceof wu))throw e;s(UA(e)),a(!1)}};return(0,B.jsx)(ZN,{operator:r,email:e.email,reason:e.reason,busy:i,error:o,onBack:t,onSubmit:(e,t)=>void c(e,t)})},$N={totp:`totpInstruction`,otp:`otpInstruction`,backup:`backupInstruction`},eP=({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)(fj,{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($N[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)(J,{name:`code`,autoComplete:`off`,spellCheck:!1,required:!0,autoFocus:!0,value:u,invalid:!!a,onChange:e=>d(e.target.value),className:`min-h-6 font-mono`}):(0,B.jsx)(x_,{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)(TC,{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`)})]})]})},tP=({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 wu))throw e;s(BA(e))}a(!1)};return(0,B.jsx)(eP,{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)})})},nP=e=>{let t=new URL(e),n=t.searchParams.get(`token`);return t.pathname.endsWith(`/-/invitation`)&&n?{token:n}:void 0},rP=e=>`${new URL(e).pathname.slice(0,-13)}/`,iP=({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}=KA(),m=a.includes(`password`),h=a.includes(`emailCode`),g=()=>p(async()=>{await i.organizations.signUpFromInvitation(e,{name:s.trim(),...m&&l&&{password:l}}),r(),o()});return(0,B.jsxs)(`form`,{className:`flex flex-col gap-3`,onSubmit:e=>{e.preventDefault(),g()},children:[(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:X(n?`makeAccountToJoin`:`makeAccount`,{email:t.email})}),f&&(0,B.jsx)(`p`,{role:`alert`,className:`text-body font-medium text-danger-text`,children:f}),(0,B.jsx)(J,{"aria-label":X(`yourName`),placeholder:X(`yourName`),autoComplete:`name`,value:s,onChange:e=>c(e.target.value)}),m&&(0,B.jsx)(J,{"aria-label":X(`password`),type:`password`,autoComplete:`new-password`,placeholder:X(h?`passwordOptional`:`passwordRequired`,{length:12}),value:l,onChange:e=>u(e.target.value)}),(0,B.jsx)(G,{type:`submit`,variant:`primary`,loading:d,disabled:!s.trim()||m&&!h&&l.length<12,children:X(n?`createAndJoin`:`createYourAccount`)})]})},aP=({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}=KA();if((0,I.useEffect)(()=>{r.organizations.invitation(e).then(c,e=>u(e instanceof wu?BA(e):X(`invalidLink`)))},[r,e]),l)return(0,B.jsx)(fj,{title:X(`invitation`),description:l,children:(0,B.jsx)(G,{className:`w-full`,onClick:t,children:X(`goToApp`)})});if(!s)return(0,B.jsx)(fj,{title:X(`invitation`),children:(0,B.jsxs)(`div`,{className:`flex items-center justify-center gap-2 text-muted-foreground`,children:[(0,B.jsx)($d,{}),` `,X(`loading`)]})});let m=i.kind===`signed-in`?i.user:void 0,h=m?.email.toLowerCase()===s.email.toLowerCase();if(!s.organization){let r=s.app?.name??``,i=X(`invitesToApp`,{inviter:s.inviter.name,app:r});return(0,B.jsx)(fj,{title:X(`join`,{name:r}),description:i,children:s.hasAccount?m&&h?(0,B.jsx)(G,{variant:`primary`,className:`w-full`,onClick:t,children:X(`goToApp`)}):(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`p`,{className:`mb-3 text-muted-foreground`,children:X(`hasAccount`,{email:s.email})}),m?(0,B.jsx)(G,{className:`w-full`,onClick:()=>void a(),children:X(`signOut`)}):(0,B.jsx)(Sh,{to:n,className:P(mf({variant:`primary`}),`w-full`),children:X(`signInAs`,{email:s.email})})]}):m?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`p`,{className:`mb-3 text-muted-foreground`,children:X(`otherAddress`,{invited:s.email,signedIn:m.email})}),(0,B.jsx)(G,{className:`w-full`,onClick:()=>void a(),children:X(`signOutToAccept`)})]}):(0,B.jsx)(iP,{token:e,preview:s,joins:!1,onDone:t})})}let g=s.organization,_=s.appRoles.map(e=>aj(o?.roles??[],e)),v=ij(s.role).toLowerCase(),y=_.length>0?X(`invitesToWith`,{inviter:s.inviter.name,organization:g.name,role:v,roles:_.join(`, `)}):X(`invitesTo`,{inviter:s.inviter.name,organization:g.name,role:v});return m&&!h?(0,B.jsxs)(fj,{title:X(`join`,{name:g.name}),description:y,children:[(0,B.jsx)(`p`,{className:`mb-3 text-muted-foreground`,children:X(`otherAddress`,{invited:s.email,signedIn:m.email})}),(0,B.jsx)(G,{className:`w-full`,onClick:()=>void a(),children:X(`signOutToAccept`)})]}):(0,B.jsx)(fj,{title:X(`join`,{name:g.name}),description:y,children:m?(0,B.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[f&&(0,B.jsx)(`p`,{role:`alert`,className:`text-body font-medium text-danger-text`,children:f}),(0,B.jsx)(G,{variant:`primary`,className:`w-full`,loading:d,onClick:()=>void p(async()=>{await r.organizations.accept(e),t()}),children:X(`join`,{name:g.name})})]}):s.hasAccount?(0,B.jsx)(Sh,{to:n,className:P(mf({variant:`primary`}),`w-full`),children:X(`signInAsToJoin`,{email:s.email})}):(0,B.jsx)(iP,{token:e,preview:s,joins:!0,onDone:t})})},oP=/^[A-Z][A-Za-z0-9]*$/,sP=e=>typeof e==`function`||typeof e==`object`&&!!e&&`$$typeof`in e,cP=e=>{let t=e.default??{},n=Object.entries(e).filter(e=>e[0]!=="default"&&oP.test(e[0])&&sP(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)}}},lP=class extends Error{name=`UiConflictError`},uP=e=>Object.keys(e).some(e=>e==="default"||/^[A-Z]/.test(e))?cP(e):e,dP=(e,t)=>[...(e.extends??[]).map(uP).flatMap((e,n)=>dP(e,e.name??`${t} extends[${n}]`)),{ui:e,label:t}],fP=(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 lP(`${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},pP=e=>e.length<=1?e[0]:()=>e.map((e,t)=>(0,B.jsx)(e,{},t)),mP=e=>e.length<=1?e[0]:({children:t,...n})=>e.reduceRight((e,t)=>(0,B.jsx)(t,{...n,children:e}),t),hP=(...e)=>{let t=e.flatMap((e,t)=>dP(e,e.name??`UI config ${t+1}`)),n=fP(`The component`,t,e=>e.components),r=fP(`The action handler`,t,e=>e.actions),i=fP(`The field type`,t,e=>e.fields),a=fP(`The drop rule`,t,e=>e.dropRules),o=fP(`The board drop`,t,e=>e.boardDrops),s=fP(`The title rule`,t,e=>e.titles),c=fP(`The marks hook`,t,e=>e.marks),l=pP(t.flatMap(({ui:e})=>e.shell?.actions?[e.shell.actions]:[])),u=pP(t.flatMap(({ui:e})=>e.shell?.rightPanel?[e.shell.rightPanel]:[])),d=t.findLast(({ui:e})=>e.shell?.logo)?.ui.shell?.logo,f=t.findLast(({ui:e})=>e.shell?.bell)?.ui.shell?.bell,p=t.findLast(({ui:e})=>e.presence)?.ui.presence,m=mP(t.flatMap(({ui:e})=>e.beforeSignIn?[e.beforeSignIn]:[])),h=e.at(-1)?.name;return{...h&&{name:h},components:n,actions:r,...Object.keys(i).length>0&&{fields:i},...Object.keys(a).length>0&&{dropRules:a},...Object.keys(o).length>0&&{boardDrops:o},...Object.keys(s).length>0&&{titles:s},...Object.keys(c).length>0&&{marks:c},...(l||u||d||f)&&{shell:{...l&&{actions:l},...u&&{rightPanel:u},...d&&{logo:d},...f&&{bell:f}}},...p&&{presence:p},...m&&{beforeSignIn:m}}},gP=(e,t)=>{let n=hP(e??{}),r=[],i=[];for(let e of t){if(e.kind===`off`){i.push(e);continue}try{hP(...r,e.ui,n),r.push(e.ui)}catch(t){if(!(t instanceof lP))throw t;i.push({kind:`off`,url:e.plugin.url,name:e.plugin.name,reason:t.message})}}return{ui:r.length===0?n:hP(...r,n),off:i}},_P=M(`plugins`),vP=e=>typeof e==`string`&&e.trim()!==``,yP=e=>{if(typeof e!=`object`||!e||Array.isArray(e))return{problem:_P(`notObject`)};let{name:t,version:n,api:r,protobase:i,entry:a,css:o}=e;return vP(t)?Number.isInteger(r)?vP(i)?vP(a)?o!==void 0&&!vP(o)?{problem:_P(`badStylesheet`)}:n!==void 0&&!vP(n)?{problem:_P(`badVersion`)}:{manifest:{name:t,api:r,protobase:i,entry:a,...n!==void 0&&{version:n},...o!==void 0&&{css:o}}}:{problem:_P(`noModule`)}:{problem:_P(`noVersions`)}:{problem:_P(`noApi`)}:{problem:_P(`noName`)}},bP=(0,I.createContext)(null),xP=bP.Provider,SP=()=>{let e=(0,I.useContext)(bP);if(!e)throw Error(`usePlugin is for the components of a plugin the app loaded`);return e},CP=(e,t,n)=>{let r=n=>(0,B.jsx)(xP,{value:e,children:(0,B.jsx)(t,{...n})});return r.displayName=`${e.name}:${n}`,r},wP=(e,t,n)=>({of:n.of,display:CP(e,n.display,`fields.${t}.display`),...n.editor&&{editor:CP(e,n.editor,`fields.${t}.editor`)},...n.cell&&{cell:CP(e,n.cell,`fields.${t}.cell`)}}),TP=(e,t)=>{let n=hP({...cP(t),name:e.name}),r=Object.fromEntries(Object.entries(n.components??{}).map(([t,n])=>[t,CP(e,n,t)])),i=n.fields&&Object.fromEntries(Object.entries(n.fields).map(([t,n])=>[t,wP(e,t,n)])),a=n.shell&&{...n.shell.actions&&{actions:CP(e,n.shell.actions,`shell.actions`)},...n.shell.rightPanel&&{rightPanel:CP(e,n.shell.rightPanel,`shell.rightPanel`)},...n.shell.logo&&{logo:CP(e,n.shell.logo,`shell.logo`)},...n.shell.bell&&{bell:CP(e,n.shell.bell,`shell.bell`)}},o=n.beforeSignIn&&CP(e,n.beforeSignIn,`beforeSignIn`);return{name:e.name,components:r,...n.actions&&{actions:n.actions},...n.dropRules&&{dropRules:n.dropRules},...n.boardDrops&&{boardDrops:n.boardDrops},...n.titles&&{titles:n.titles},...n.marks&&{marks:n.marks},...i&&{fields:i},...a&&{shell:a},...o&&{beforeSignIn:o}}},EP={name:`@protobase/ui`,version:`0.66.1`,description:`The Protobase admin app and the React hooks and components for custom UI.`,license:`Apache-2.0`,repository:{type:`git`,url:`git+https://github.com/PrototeamHQ/protobase.git`,directory:`packages/ui`},homepage:`https://docs.protobase.net`,type:`module`,protobase:{pluginApi:1},sideEffects:[`*.css`,`./dist/app/main.js`],engines:{node:`>=22.12.0`},exports:{".":`./src/index.ts`,"./theme.css":`./src/theme.css`,"./styles.css":`./src/styles.css`},types:`./src/index.ts`,files:[`dist`],scripts:{build:`tsdown && protobase build-shell dist/shell --source-maps dist/shell-source-maps`,prepack:`tsdown && protobase build-shell dist/shell --source-maps dist/shell-source-maps`},publishConfig:{access:`public`,exports:{".":`./dist/index.js`,"./theme.css":`./dist/theme.css`,"./styles.css":`./dist/styles.css`},types:`./dist/index.d.ts`},dependencies:{"@dnd-kit/core":`^6.3.1`,"@dnd-kit/sortable":`^10.0.0`,"@protobase/client":`workspace:*`,"@protobase/layout":`workspace:*`,"@protobase/schema":`workspace:*`,"@sentry/browser":`^11.7.0`,"@tanstack/react-query":`^5.104.1`,"@tanstack/react-table":`^9.2.6`,"altcha-lib":`^2.6.0`,dompurify:`^3.4.17`,fflate:`^0.8.3`,"intl-messageformat":`^12.1.4`,"lucide-react":`^1.52.0`,"maplibre-gl":`^6.14.0`,marked:`^18.1.1`,papaparse:`^5.7.0`,pmtiles:`^4.5.0`,react:`^19.3.0`,"react-dom":`^19.3.0`,"react-map-gl":`^8.1.3`,recharts:`^3.10.1`,tailwindcss:`^4.3.3`,thumbhash:`^0.1.1`,uqr:`^0.1.3`},devDependencies:{"@types/papaparse":`^5.5.2`}},DP=EP.protobase.pluginApi,OP=EP.version,kP={readJson:async e=>{let t=await fetch(e,{cache:`no-cache`,credentials:`same-origin`});return t.ok?{json:await t.json()}:{status:t.status}},addStylesheet:e=>{if([...document.querySelectorAll(`link[rel="stylesheet"]`)].some(t=>t.href===e))return;let t=document.createElement(`link`);t.rel=`stylesheet`,t.href=e,document.head.append(t)},importModule:e=>Ve(()=>import(e),[])},AP={api:DP,version:OP},jP=e=>e instanceof Error?e.message:String(e),MP=async(e,t,n,r=AP)=>{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(_P(`answered`,{status:n.status}));let s=yP(n.json);if(`problem`in s)return a(s.problem);let{manifest:c}=s;o=c.name;let l=Ln(c,r);if(l)return a(l,o);c.css&&t.addStylesheet(new URL(c.css,i).href);let u=await t.importModule(new URL(c.entry,i).href),d={name:o,...c.version&&{version:c.version},url:i,settings:e.settings??{}};return{kind:`loaded`,plugin:d,ui:TP(d,u)}}catch(e){return a(_P(`couldNotLoad`,{reason:jP(e)}),o)}},NP=e=>{let t=new Map;return{load:n=>{let r=JSON.stringify(n),i=t.get(r);if(i)return i;let a=MP(n,e,window.location.href);return t.set(r,a),a}}},PP=(0,I.createContext)(null),FP=({loader:e=kP,children:t})=>{let n=(0,I.useMemo)(()=>NP(e),[e]);return(0,B.jsx)(PP.Provider,{value:n,children:t})},IP=()=>{let e=(0,I.useContext)(PP);if(!e)throw Error(`usePluginSource must be used inside PluginSourceProvider`);return e},LP=1e4,RP=[],zP=(e,t)=>{let n=JSON.stringify(e),[r,i]=(0,I.useState)({key:`[]`,loads:RP,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()},LP);return e.forEach((e,n)=>{t.load(e).then(e=>{o[n]=e,s()})}),()=>{r=!1,clearTimeout(c)}},[n,t]),e.length===0?{loads:RP,settled:!0}:r.key===n?r:{loads:RP,settled:!1}},BP=({children:e})=>{let{state:t,beforeSignIn:n,adoptSession:r}=V(),{path:i,params:a,navigate:o}=jh(),{loads:s,settled:c}=zP(n,IP()),l=(0,I.useMemo)(()=>gP(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)(cv,{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)($d,{}),` `,_P(`loading`)]})},VP=()=>{let e=window.location.href,t=DN(e);if(t)return{kind:`reset-password`,token:t.token};let n=JN(e);if(n)return{kind:`staff-sign-in`,link:n};let r=nP(e);if(r)return{kind:`invitation`,token:r.token};let i=Sd(e);if(i)return{kind:`provider-sign-in`,provider:i};let a=Cd(e);return a?{kind:`sign-in`,providerError:a}:{kind:`sign-in`}},HP=({to:e})=>{let{navigate:t}=jh();return(0,I.useEffect)(()=>t(e,{replace:!0}),[t,e]),null},UP=({workspace:e,children:t})=>{let n=WP(e,t);return(0,B.jsx)(BP,{children:n})},WP=(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}=jh(),{address:p,next:m,open:h,link:g,leave:_}=tE(),[v,y]=(0,I.useState)(VP),[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(wd),(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&&Cd(E)!==void 0;(0,I.useEffect)(()=>{!O&&v.kind===`sign-in`&&v.providerError&&k&&D(wd)},[O,v,k,D]);let A=(0,I.useCallback)(e=>y({kind:`sign-in`,error:e}),[]),j=e=>{D(ON),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)($d,{}),` `,z(`loading`)]});case`error`:return(0,B.jsxs)(`div`,{className:`flex h-full min-h-48 flex-col items-center justify-center gap-3 p-8 text-center`,children:[(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:z(`cannotReach`,{message:n.message})}),(0,B.jsx)(G,{onClick:r,children:z(`tryAgain`)})]});case`needs-admin`:return(0,B.jsx)(xN,{firstAdminUrl:n.firstAdminUrl,onCheckAgain:r})}if(n.kind===`signed-in`&&p)return(0,B.jsx)(HP,{to:m??`/`});if(v.kind===`reset-password`)return(0,B.jsx)(NN,{token:v.token,onDone:()=>void ee(),onRequestNewLink:i?()=>{y({kind:`sign-in`}),f(Qc({step:`forgot-password`}),{replace:!0})}:void 0,onBack:()=>j({kind:`sign-in`})});if(v.kind===`staff-sign-in`)return(0,B.jsx)(QN,{link:v.link,onBack:()=>{D(YN),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)(aP,{token:v.token,onDone:()=>{D(rP),y({kind:`sign-in`})},signIn:g()});if(n.kind===`signed-in`)return t;if(n.kind===`two-factor`)return(0,B.jsx)(tP,{methods:n.methods,onBack:te});if(n.kind===`setup-required`)return(0,B.jsx)(IN,{missing:n.missing},n.missing.join());if(v.kind===`provider-sign-in`)return(0,B.jsx)(jN,{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)(HP,{to:Qc({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)(kN,{back:g(`sign-in`,{replace:!0})});if(ie===`email-code`)return(0,B.jsx)(yN,{email:b,onBack:ae(`sign-in`)});if(ie===`sign-up`||ie===`sign-up-code`||ie===`sign-up-details`)return(0,B.jsx)(GN,{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&&GA(re.providerError,o.length===1?o[0].name:`the provider`),ce=re.error??se;return(0,B.jsx)(VN,{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)},GP=3e4,KP=(e,t=Date.now())=>Math.max(1e3,Ju(e)-t-GP),qP=()=>{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),KP(s))))};return a(),()=>{e=!1,clearTimeout(r)}},[t,n]),n?r:void 0},JP=({children:e})=>(0,B.jsx)(Zd,{locale:V().locale,children:e}),YP=(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)}},XP=e=>{let t=U(),n=Se(),r=(0,I.useContext)(jd),i=(0,I.useMemo)(()=>Object.values(e.resources).filter(t=>t.live&&!Xd(e,t.name)).map(e=>e.name).sort().join(`,`),[e]);(0,I.useEffect)(()=>{if(!i)return;let e=YP(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])},ZP=(e,t,n=!0)=>{let r=U(),i=Nn(t);return E({queryKey:H.record(e,i),enabled:n,queryFn:()=>r.get(e,t)})},QP=(e,t,n=!0)=>{let r=U(),i=Se(),a=Nn(t);return E({queryKey:H.record(e,a),enabled:n,queryFn:()=>r.get(e,t),placeholderData:()=>i.getQueryData(H.recordPreview(e,a))})},$P=M(`forms`),eF=async(e,t)=>{let n=await e.formChallenge(t),r=await _e({challenge:n,deriveKey:De});if(!r)throw Error($P(`checkTooLong`));return{challenge:n,solution:{counter:r.counter,derivedKey:r.derivedKey}}},tF=({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)($d,{}),` `,$P(`loading`)]}):n.error?pl(n.error)&&n.error.status===404?(0,B.jsx)(tf,{title:$P(`notFound`),children:$P(`noForm`)}):(0,B.jsx)(tf,{title:ef(`cannotReach`),children:pl(n.error)?n.error.message:ef(`noAnswer`)}):(0,B.jsx)(nF,{form:n.data})},nF=({form:e})=>{let t=U(),{resource:n,view:r}=e,i=e.title??r.names?.singular??F(r.resource);PM(i);let[a,o]=(0,I.useState)(()=>Lg(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),_=sx(h);if(p)return(0,B.jsx)(fj,{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,Mg(n,{},a),await eF(t,e.name)),m(!0)}catch(e){let t=ax(e);c(t),Object.keys(t).length>0?g(e=>e+1):u(e)}finally{f(!1)}};return(0,B.jsx)(fj,{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)(Yh,{name:e,label:o,help:i?.help,required:Ng(t),error:c&&ix(t,o,c),children:(0,B.jsx)(Ov,{field:t,hints:i,value:a[e]??(t.type!==`boolean`&&``),stored:void 0,placeholder:Rg(t)?$P(`setByDatabase`):Ig(t),invalid:!!c,onChange:t=>v(e,t)})},e)}),l!==void 0&&(0,B.jsx)(Bg,{title:$P(`notSent`),error:l}),(0,B.jsx)(G,{variant:`primary`,type:`submit`,loading:d,className:`min-h-10`,children:$P(`send`)})]})})},rF=()=>{let{path:e}=jh();return(0,I.useMemo)(()=>xn(e),[e])},Z=M(`calls`),iF=(e,t)=>{e.srcObject=new MediaStream([t]);let n=()=>{t.readyState===`live`&&e.play().catch(e=>{if(!(e instanceof DOMException&&(e.name===`AbortError`||e.name===`NotAllowedError`)))throw e})};return e.addEventListener(`pause`,n),()=>e.removeEventListener(`pause`,n)},aF=({track:e,...t})=>{let n=(0,I.useCallback)(t=>t?iF(t,e):void 0,[e]);return(0,B.jsx)(`video`,{ref:n,autoPlay:!0,playsInline:!0,muted:!0,...t})},oF=({track:e})=>{let t=(0,I.useCallback)(t=>t?iF(t,e):void 0,[e]);return(0,B.jsx)(`audio`,{ref:t,autoPlay:!0})},sF=e=>P(`size-10 rounded-full`,!e&&`bg-danger-soft text-danger-text`),cF=({name:e,member:t,camera:n,microphoneOn:r,cameraOn:i,microphone:a,cameraAvailable:o,notices:s,onMicrophone:c,onCamera:l,onJoin:u,cancel:d,joinLabel:f=Z(`joinCall`)})=>(0,B.jsxs)(`section`,{"aria-label":Z(`preview`),className:`flex size-full min-h-0 flex-col items-center justify-center gap-3 bg-background p-4`,children:[(0,B.jsx)(`figure`,{className:`relative flex aspect-video w-full max-w-md items-center justify-center overflow-hidden rounded-lg bg-neutral-900`,children:n&&i?(0,B.jsx)(aF,{track:n,"aria-label":Z(`preview`),className:`size-full -scale-x-100 object-cover`}):(0,B.jsx)(If,{initials:I_(e),hue:F_(t),size:`md`,className:`size-16 text-xl ring-0`})}),s.length>0&&(0,B.jsx)(`div`,{role:`status`,className:`flex w-full max-w-md flex-col gap-1`,children:s.map(e=>(0,B.jsx)(`p`,{className:`rounded-md bg-warning-soft px-3 py-1.5 text-xs text-foreground`,children:e},e))}),(0,B.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,B.jsx)(G,{size:`icon`,"aria-label":Z(`microphone`),"aria-pressed":r,disabled:!a,className:sF(r),onClick:c,children:r?(0,B.jsx)(yo,{className:`size-4`}):(0,B.jsx)(_o,{className:`size-4`})}),(0,B.jsx)(G,{size:`icon`,"aria-label":Z(`camera`),"aria-pressed":i,disabled:!o,className:sF(i),onClick:l,children:i?(0,B.jsx)(lc,{className:`size-4`}):(0,B.jsx)(sc,{className:`size-4`})}),(0,B.jsx)(G,{variant:`primary`,className:`h-10 rounded-full px-5`,onClick:u,children:f}),(0,B.jsx)(Sh,{to:d,className:`px-2 text-sm text-muted-foreground hover:text-foreground`,children:Z(`leave`)})]})]}),lF=()=>{let[e,t]=(0,I.useState)(!1);return{run:(0,I.useCallback)(e=>{t(!1),(async()=>{let{GuestRefused:n}=await Ve(async()=>{let{GuestRefused:e}=await import(`./calls-DHvl29Pd.js`);return{GuestRefused:e}},[]);await e().catch(e=>{if(!(e instanceof n))throw e;t(!0)})})()},[]),refused:e}},uF={all:[`camera`,`microphone`,`screen`,`screen-audio`],camera:[`camera`,`microphone`],microphone:[`microphone`]},dF={call:void 0,hour:36e5},fF=({name:e,children:t})=>(0,B.jsxs)(`li`,{className:`flex items-center justify-between gap-2 py-1.5`,children:[(0,B.jsx)(`span`,{className:`min-w-0 truncate text-sm text-foreground`,children:e}),(0,B.jsx)(`span`,{className:`flex shrink-0 gap-1.5`,children:t})]}),pF=({lobby:e,inCall:t,guests:n,linkOf:r,open:i,onClose:a})=>{let[o,s]=(0,I.useState)(`camera`),[c,l]=(0,I.useState)(`call`),[u,d]=(0,I.useState)(),[f,p]=(0,I.useState)(!1),{run:m,refused:h}=lF(),g=()=>m(async()=>{let e=dF[c],{link:t,token:i}=await n.link({publish:uF[o],...e!==void 0&&{expiresAt:new Date(Date.now()+e)}});d({id:t.id,url:r(i)})}),_=e=>void navigator.clipboard.writeText(e).then(()=>{p(!0),setTimeout(()=>p(!1),2e3)});return(0,B.jsx)(Ef,{title:Z(`guests`),description:Z(`addressesVisible`),open:i,onClose:a,actions:(0,B.jsx)(G,{onClick:a,children:Z(`close`)}),children:(0,B.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[h&&(0,B.jsx)(`p`,{role:`alert`,className:`rounded-md bg-warning-soft px-3 py-1.5 text-xs text-foreground`,children:Z(`guestRefused`)}),e.guests.length>0&&(0,B.jsxs)(`section`,{"aria-label":Z(`inLobby`),children:[(0,B.jsx)(`h3`,{className:`text-xs font-medium text-muted-foreground`,children:Z(`inLobby`)}),(0,B.jsx)(`ul`,{children:e.guests.map(({guest:e,name:t})=>(0,B.jsxs)(fF,{name:t,children:[(0,B.jsx)(G,{size:`sm`,variant:`primary`,onClick:()=>m(()=>n.admit(e)),children:Z(`admit`)}),(0,B.jsx)(G,{size:`sm`,onClick:()=>m(()=>n.deny(e)),children:Z(`deny`)})]},e))})]}),t.length>0&&(0,B.jsxs)(`section`,{"aria-label":Z(`guestsInCall`),children:[(0,B.jsx)(`h3`,{className:`text-xs font-medium text-muted-foreground`,children:Z(`guestsInCall`)}),(0,B.jsx)(`ul`,{children:t.map(({guest:e,name:t})=>(0,B.jsx)(fF,{name:t,children:(0,B.jsx)(G,{size:`sm`,variant:`danger`,onClick:()=>m(()=>n.remove(e)),children:Z(`remove`)})},e))})]}),(0,B.jsxs)(`section`,{"aria-label":Z(`guestLinks`),className:`flex flex-col gap-2`,children:[(0,B.jsx)(`h3`,{className:`text-xs font-medium text-muted-foreground`,children:Z(`guestLinks`)}),e.links.length===0&&(0,B.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:Z(`noLinks`)}),(0,B.jsx)(`ul`,{children:e.links.map(e=>(0,B.jsxs)(`li`,{className:`flex flex-col gap-1.5 py-1.5`,children:[u?.id===e.id&&(0,B.jsx)(J,{readOnly:!0,value:u.url,"aria-label":Z(`copyLink`),onFocus:e=>e.currentTarget.select(),trailing:(0,B.jsx)(`button`,{type:`button`,"aria-label":Z(f?`copied`:`copyLink`),onClick:()=>_(u.url),className:`inline-flex size-8 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-muted pointer-coarse:size-11`,children:f?(0,B.jsx)(Si,{className:`size-4 text-success`}):(0,B.jsx)(Ji,{className:`size-4`})})}),(0,B.jsxs)(`span`,{className:`flex items-center justify-between gap-2 text-xs text-muted-foreground`,children:[e.expires_at?Z(`linkUntil`,{until:new Date(e.expires_at).toLocaleString()}):Z(`linkUntilEnd`),(0,B.jsx)(G,{size:`sm`,onClick:()=>m(()=>n.revoke(e.id)),children:Z(`revoke`)})]})]},e.id))}),(0,B.jsxs)(`div`,{className:`flex flex-col items-start gap-2`,children:[(0,B.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2 text-xs text-muted-foreground`,children:[Z(`guestsMaySend`),(0,B.jsx)(Re,{label:Z(`guestsMaySend`),value:o,onChange:s,options:[{value:`all`,label:Z(`sendAll`)},{value:`camera`,label:Z(`sendCamera`)},{value:`microphone`,label:Z(`sendMicrophone`)}]})]}),(0,B.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2 text-xs text-muted-foreground`,children:[Z(`linkLasts`),(0,B.jsx)(Re,{label:Z(`linkLasts`),value:c,onChange:l,options:[{value:`call`,label:Z(`linkUntilEnd`)},{value:`hour`,label:Z(`forAnHour`)}]})]}),(0,B.jsx)(G,{variant:`primary`,onClick:g,children:Z(`newLink`)})]})]})]})})},mF=({waiting:e,guests:t})=>{let{run:n,refused:r}=lF(),i=e[0];return i?(0,B.jsxs)(`div`,{role:`status`,className:`flex shrink-0 flex-wrap items-center gap-2 rounded-md bg-primary-soft px-3 py-1.5 text-xs text-foreground`,children:[(0,B.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:r?Z(`guestRefused`):Z(`waitingGuest`,{name:i.name})}),(0,B.jsx)(G,{size:`sm`,variant:`primary`,onClick:()=>n(()=>t.admit(i.guest)),children:Z(`admit`)}),(0,B.jsx)(G,{size:`sm`,onClick:()=>n(()=>t.deny(i.guest)),children:Z(`deny`)})]}):null},hF={ended:`ended`,removed:`removed`,full:`full`,refused:`refused`,unavailable:`unavailable`,denied:`denied`},gF=({reason:e,onJoinAgain:t})=>(0,B.jsxs)(`section`,{role:`status`,className:`flex size-full min-h-0 flex-col items-center justify-center gap-3 bg-background p-4 text-center`,children:[(0,B.jsx)(`p`,{className:`text-sm text-foreground`,children:Z(e===`rejoin`?`ended`:hF[e])}),t&&e!==`removed`&&e!==`refused`&&e!==`denied`&&(0,B.jsx)(G,{onClick:t,children:Z(`callAgain`)})]}),_F=(e,t)=>t<640?e<=2?1:2:Math.min(4,Math.ceil(Math.sqrt(e))),vF=({people:e,sharers:t,width:n})=>t[0]===void 0?e<=1?{kind:`alone`}:{kind:`grid`,columns:_F(e,n)}:{kind:`share`,sharer:t[0]},yF=({roundTripMs:e,lostRatio:t})=>(e??0)>400||(t??0)>.05?`poor`:`good`,bF=(e,t,n)=>e===`failed`||e!==`connected`&&n-t>=15e3,xF=(e,t=.05)=>{let n;for(let[r,i]of e)i>=t&&(!n||i>n[1])&&(n=[r,i]);return n?.[0]},SF=(e,t)=>e.find(e=>e.source===t&&e.track),CF=({members:e,self:t,tracks:n,own:r,nameOf:i,speaker:a,connections:o,seen:s,now:c})=>(e.some(e=>e.member===t)?e:[{member:t,joined_at:``},...e]).map(({member:e,name:l})=>{let u={member:e,name:e.startsWith(`guest:`)?Z(`guestName`,{name:l??``}):l??i(e),...a===e&&{speaking:!0}};if(e===t)return{...u,self:!0,...r.camera&&{camera:r.camera},...r.microphone&&{microphone:r.microphone},...r.screen&&{screen:r.screen},microphoneOff:!r.microphone||!r.microphoneOn,cameraOff:!r.camera||!r.cameraOn};let d=n.filter(t=>t.member===e),[f,p,m,h]=[`camera`,`microphone`,`screen`,`screen-audio`].map(e=>SF(d,e)),g=o.find(t=>t.member===e),_=bF(g?.state,s.get(e)??c,c)?`failed`:g?.state===`connected`?yF(g):void 0;return{...u,...f&&{camera:f.track},...p&&{microphone:p.track},...m&&{screen:m.track},...h&&{screenAudio:h.track},microphoneOff:!p||p.muted,cameraOff:!f||f.muted,..._&&{connection:_}}}),wF=e=>P(`size-10 rounded-full`,!e&&`bg-danger-soft text-danger-text`),TF=({microphoneOn:e,cameraOn:t,sharing:n,onMicrophone:r,onCamera:i,onShare:a,guests:o,leave:s})=>(0,B.jsxs)(`div`,{role:`toolbar`,"aria-label":Z(`joinCall`),className:`flex shrink-0 flex-wrap items-center justify-center gap-2 py-2`,children:[(0,B.jsx)(G,{size:`icon`,"aria-label":Z(`microphone`),"aria-pressed":e,title:Z(`microphone`),className:wF(e),onClick:r,children:e?(0,B.jsx)(yo,{className:`size-4`}):(0,B.jsx)(_o,{className:`size-4`})}),(0,B.jsx)(G,{size:`icon`,"aria-label":Z(`camera`),"aria-pressed":t,title:Z(`camera`),className:wF(t),onClick:i,children:t?(0,B.jsx)(lc,{className:`size-4`}):(0,B.jsx)(sc,{className:`size-4`})}),a&&(0,B.jsx)(G,{size:`icon`,"aria-label":Z(n?`stopSharing`:`shareScreen`),"aria-pressed":!!n,title:Z(n?`stopSharing`:`shareScreen`),className:`size-10 rounded-full`,onClick:a,children:n?(0,B.jsx)(To,{className:`size-4`}):(0,B.jsx)(Co,{className:`size-4`})}),o&&(0,B.jsxs)(G,{size:`icon`,"aria-label":Z(`guests`),title:Z(`guests`),className:`relative size-10 rounded-full`,onClick:o.onOpen,children:[(0,B.jsx)($s,{className:`size-4`}),(0,B.jsx)(Yx,{count:o.waiting,className:`absolute -top-1 -right-1`})]}),(0,B.jsxs)(Sh,{to:s,className:P(mf({variant:`danger`}),`h-10 rounded-full px-4`),children:[(0,B.jsx)(Vo,{className:`size-4`}),Z(`leave`)]})]}),EF=({person:e,screen:t=!1,className:n})=>{let r=t?e.screen:e.cameraOff?void 0:e.camera,i=t?e.self?Z(`youAreSharing`):Z(`sharing`,{name:e.name}):e.self?`${e.name} (${Z(`you`)})`:e.name;return(0,B.jsxs)(`figure`,{"data-member":e.member,"data-speaking":e.speaking?`true`:void 0,"aria-label":i,className:P(`relative flex min-h-0 min-w-0 items-center justify-center overflow-hidden rounded-lg bg-neutral-900 ring-offset-2 ring-offset-background`,e.speaking&&!t&&`ring-2 ring-success`,n),children:[r?(0,B.jsx)(aF,{track:r,className:P(`size-full`,t?`object-contain`:`object-cover`,e.self&&!t&&`-scale-x-100`)}):(0,B.jsx)(If,{initials:I_(e.name),hue:F_(e.member),size:`md`,className:`size-16 text-xl ring-0`}),e.connection===`failed`&&!e.self&&(0,B.jsx)(`p`,{role:`status`,className:`absolute inset-x-1 top-1 truncate rounded bg-black/70 px-2 py-1 text-center text-xs text-white`,children:Z(`cannotConnect`,{name:e.name})}),(0,B.jsxs)(`figcaption`,{className:`absolute bottom-1.5 left-1.5 flex max-w-[calc(100%-0.75rem)] items-center gap-1 rounded bg-black/60 px-1.5 py-0.5 text-xs text-white`,children:[!t&&e.microphoneOff&&(0,B.jsx)(_o,{role:`img`,"aria-label":Z(`muted`),className:`size-3 shrink-0`}),!t&&e.connection===`poor`&&(0,B.jsx)(hc,{role:`img`,"aria-label":Z(`poorConnection`),className:`size-3 shrink-0 text-warning`}),(0,B.jsx)(`span`,{className:`truncate`,children:i})]})]})},DF=()=>{let[e,t]=(0,I.useState)(0);return{ref:(0,I.useCallback)(e=>{if(!e)return;t(e.clientWidth);let n=new ResizeObserver(([e])=>t(e.contentRect.width));return n.observe(e),()=>n.disconnect()},[]),width:e}},OF=4,kF=({people:e,columns:t})=>(0,B.jsx)(`div`,{className:`grid size-full min-h-0 gap-2`,style:{gridTemplateColumns:`repeat(${t}, minmax(0, 1fr))`,gridTemplateRows:`repeat(${Math.ceil(e.length/t)}, minmax(0, 1fr))`},children:e.map(e=>(0,B.jsx)(EF,{person:e},e.member))}),AF=({people:e,sharer:t,narrow:n})=>{let r=e.slice(0,OF),i=e.length-r.length;return(0,B.jsxs)(`div`,{className:P(`flex size-full min-h-0 gap-2`,n?`flex-col`:`flex-row`),children:[(0,B.jsx)(EF,{person:t,screen:!0,className:`min-h-0 flex-1`}),(0,B.jsxs)(`div`,{className:P(`flex shrink-0 gap-2`,n?`h-20 flex-row`:`w-40 flex-col`),children:[r.map(e=>(0,B.jsx)(EF,{person:e,className:n?`aspect-video h-full`:`aspect-video w-full`},e.member)),i>0&&(0,B.jsxs)(`p`,{className:`flex items-center justify-center rounded-lg bg-muted px-2 text-xs text-muted-foreground`,children:[`+`,i]})]})]})},jF=({layout:e,people:t,narrow:n})=>e.kind===`share`?(0,B.jsx)(AF,{people:t,sharer:t.find(t=>t.member===e.sharer),narrow:n}):e.kind===`grid`?(0,B.jsx)(kF,{people:t,columns:e.columns}):(0,B.jsxs)(`div`,{className:`relative size-full min-h-0`,children:[(0,B.jsx)(EF,{person:t[0],className:`size-full`}),(0,B.jsx)(`p`,{className:`absolute inset-x-0 top-3 text-center text-sm text-white drop-shadow`,children:Z(`alone`)})]}),MF=({people:e,state:t,notices:n=[],controls:r,aside:i,children:a,className:o})=>{let{ref:s,width:c}=DF(),l=c>0&&c<640,u=vF({people:e.length,sharers:e.filter(e=>e.screen).map(e=>e.member),width:c}),d=[...t===`resuming`?[Z(`reconnecting`)]:[],...n];return(0,B.jsxs)(`section`,{ref:s,"aria-label":Z(`joinCall`),"data-layout":u.kind,className:P(`flex size-full min-h-0 flex-col gap-2 bg-background p-2`,o),children:[d.length>0&&(0,B.jsx)(`div`,{role:`status`,className:`flex shrink-0 flex-col gap-1`,children:d.map(e=>(0,B.jsxs)(`p`,{className:`flex items-center gap-2 rounded-md bg-warning-soft px-3 py-1.5 text-xs text-foreground`,children:[e===Z(`reconnecting`)&&(0,B.jsx)($d,{className:`size-3`}),e]},e))}),i,(0,B.jsx)(`div`,{className:`min-h-0 flex-1`,children:t===`joining`?(0,B.jsxs)(`p`,{role:`status`,className:`flex size-full items-center justify-center gap-2 text-muted-foreground`,children:[(0,B.jsx)($d,{className:`size-4`}),Z(`connecting`)]}):(0,B.jsx)(jF,{layout:u,people:e,narrow:l})}),(0,B.jsx)(TF,{...r}),e.filter(e=>!e.self).flatMap(e=>[[`microphone`,e.microphone],[`screen-audio`,e.screenAudio]].map(([t,n])=>n&&{key:`${e.member} ${t}`,track:n})).filter(e=>e!==void 0).map(({key:e,track:t})=>(0,B.jsx)(oF,{track:t},e)),a]})},NF=({leave:e})=>(0,B.jsxs)(`section`,{role:`status`,className:`flex size-full min-h-0 flex-col items-center justify-center gap-3 bg-background p-4 text-center`,children:[(0,B.jsxs)(`p`,{className:`flex items-center gap-2 text-sm text-foreground`,children:[(0,B.jsx)($d,{className:`size-4`}),Z(`waiting`)]}),(0,B.jsx)(Sh,{to:e,className:`px-2 text-sm text-muted-foreground hover:text-foreground`,children:Z(`leave`)})]}),PF=`/-/call-guest`,FF=(e,t)=>`${e}${PF}#${t}`,IF=(e,t)=>{let n=t.replace(/^#/,``);return e===`/-/call-guest`&&n?{token:n}:void 0},LF=()=>{let{path:e}=jh();return(0,I.useMemo)(()=>IF(e,globalThis.location?.hash??``),[e])},RF=200,zF=1e3,BF=(e,t)=>{e.getFloatTimeDomainData(t);let n=0;for(let e of t)n+=e*e;return Math.min(1,Math.sqrt(n/t.length)*4)},VF=e=>{let[t,n]=(0,I.useState)(),r=[...e].map(([e,t])=>`${e}:${t.id}`).join(`,`);return(0,I.useEffect)(()=>{if(e.size===0||typeof AudioContext>`u`)return;let t=new AudioContext,r=new Map([...e].map(([e,n])=>{let r=t.createAnalyser();return r.fftSize=512,t.createMediaStreamSource(new MediaStream([n])).connect(r),[e,r]})),i=new Float32Array(512),a,o=setInterval(()=>{let e=xF(new Map([...r].map(([e,t])=>[e,BF(t,i)])));e&&(a={member:e,at:Date.now()}),n(a&&Date.now()-a.at<zF?a.member:void 0)},RF);return()=>{clearInterval(o),t.close()}},[r]),t},HF=new Set([`NotAllowedError`,`SecurityError`]),UF=new Set([`NotFoundError`,`NotReadableError`,`OverconstrainedError`]),WF=async(e,t)=>{try{return{track:(await e.getUserMedia({[t]:!0})).getTracks()[0],blocked:!1}}catch(e){if(!(e instanceof DOMException))throw e;if(HF.has(e.name))return{blocked:!0};if(UF.has(e.name))return{blocked:!1};throw e}},GF=async(e=navigator.mediaDevices)=>{try{let t=await e.getUserMedia({audio:!0,video:!0});return{microphone:t.getAudioTracks()[0],camera:t.getVideoTracks()[0],blocked:{microphone:!1,camera:!1},none:!1}}catch(e){if(!(e instanceof DOMException)||!(HF.has(e.name)||UF.has(e.name)))throw e}let[t,n]=[await WF(e,`audio`),await WF(e,`video`)];return{...t.track&&{microphone:t.track},...n.track&&{camera:n.track},blocked:{microphone:t.blocked,camera:n.blocked},none:!t.track&&!n.track&&!t.blocked&&!n.blocked}},KF=class extends Error{reason;constructor(e){super(`Not let into the call: ${e}`),this.reason=e,this.name=`NotLetIn`}},qF=1e3,JF=(e,t)=>new Promise(n=>{let r=setTimeout(n,e);t.addEventListener(`abort`,()=>(clearTimeout(r),n()),{once:!0})}),YF=async(e,t,n,r)=>{let{LobbyRefused:i}=await Ve(async()=>{let{LobbyRefused:e}=await import(`./calls-DHvl29Pd.js`);return{LobbyRefused:e}},[]),a=e=>e instanceof i?new KF(e.status===404?`refused`:e.status===429?`unavailable`:`ended`):e,{token:o}=await e.enter(t,n).catch(e=>Promise.reject(a(e)));for(;!r.aborted;){let t=await e.wait(o).catch(e=>Promise.reject(a(e)));if(t.state===`admitted`)return o;if(t.state===`denied`)throw new KF(`denied`);if(t.state===`ended`)throw new KF(`ended`);await JF(qF,r)}throw await e.leave(o),new KF(`ended`)},XF=2e3,ZF=e=>{for(let t of e)t?.stop()},QF=(e,{admission:t}={})=>{let[n,r]=(0,I.useState)({kind:`check`}),[i,a]=(0,I.useState)(),o=(0,I.useRef)(new AbortController),[s,c]=(0,I.useState)(),[l,u]=(0,I.useState)(!0),[d,f]=(0,I.useState)(!0),[p,m]=(0,I.useState)([]),[h,g]=(0,I.useState)([]),[_,v]=(0,I.useState)([]),[y,b]=(0,I.useState)(),[x,S]=(0,I.useState)(!1),C=(0,I.useRef)(void 0),w=(0,I.useRef)(!1),T=(0,I.useRef)([]),E=(0,I.useRef)(new Map),D=(0,I.useRef)(Promise.resolve(void 0));(0,I.useEffect)(()=>{let e=!1;return w.current=!1,D.current=GF().then(t=>{if(e){ZF([t.microphone,t.camera]);return}return T.current.push(t.microphone,t.camera),c(t),t}),()=>{e=!0,w.current=!0,o.current.abort(),C.current?.leave(),C.current=void 0,ZF(T.current),T.current=[]}},[]),(0,I.useEffect)(()=>{for(let{member:e}of h)E.current.has(e)||E.current.set(e,Date.now())},[h]),(0,I.useEffect)(()=>{if(n.kind!==`in`)return;let e=setInterval(()=>void C.current?.connections().then(v),XF);return()=>clearInterval(e)},[n.kind]);let O=async()=>{if(!t)return{};r({kind:`waiting`}),o.current=new AbortController;let e=await t(o.current.signal).then(e=>e,e=>{if(!(e instanceof KF))throw e;r({kind:`left`,reason:e.reason})});return e===void 0?void 0:{guest:e}},k=(0,I.useCallback)(async()=>{let t=await O();if(!t||w.current)return;r({kind:`joining`});let{joinCall:n,PublishRefused:i}=await Ve(async()=>{let{joinCall:e,PublishRefused:t}=await import(`./calls-DHvl29Pd.js`);return{joinCall:e,PublishRefused:t}},[]),o=await n({url:e,...t,onLobby:a,onTracks:m,onMembers:g,onState:e=>{(e.state===`joined`||e.state===`resuming`)&&r({kind:`in`,resuming:e.state===`resuming`}),e.state===`left`&&r({kind:`left`,reason:e.reason})}}).then(e=>e,()=>void 0);if(!o)return;if(w.current)return o.leave();C.current=o;let s=await D.current,c={...s?.microphone&&{microphone:s.microphone},...s?.camera&&{camera:s.camera}};await o.publish(c).then(()=>{c.microphone&&o.mute(`microphone`,!l),c.camera&&o.mute(`camera`,!d)},e=>{if(!(e instanceof i))throw e;S(!0)})},[e,t,l,d]),A=(0,I.useCallback)(()=>{let e=!l;u(e),s?.microphone&&(s.microphone.enabled=e),C.current?.mute(`microphone`,!e)},[l,s]),j=(0,I.useCallback)(()=>{let e=!d;f(e),s?.camera&&(s.camera.enabled=e),C.current?.mute(`camera`,!e)},[d,s]),ee=(0,I.useCallback)(async e=>{b(void 0),ZF([e.video,e.audio]),await C.current?.unpublish(`screen`),e.audio&&await C.current?.unpublish(`screen-audio`)},[]),te=(0,I.useCallback)(async()=>{if(y)return ee(y);let e;try{e=await navigator.mediaDevices.getDisplayMedia({video:!0,audio:!0})}catch(e){if(e instanceof DOMException&&e.name===`NotAllowedError`)return;throw e}let t={video:e.getVideoTracks()[0],...e.getAudioTracks()[0]&&{audio:e.getAudioTracks()[0]}};T.current.push(t.video,t.audio),t.video.addEventListener(`ended`,()=>void ee(t)),await C.current?.publish({screen:t.video,...t.audio&&{"screen-audio":t.audio}}),b(t)},[y,ee]),ne=typeof navigator<`u`&&typeof navigator.mediaDevices?.getDisplayMedia==`function`;return{phase:n,devices:s,microphoneOn:l,cameraOn:d,tracks:p,members:h,connections:_,screen:y,refusedSending:x,seen:E.current,self:C.current?.participant,lobby:i,guests:C.current?.guests,join:k,toggleMicrophone:A,toggleCamera:j,...ne&&{toggleScreen:te}}},$F=(e,t)=>[...e?.blocked.microphone?[Z(`noMicrophone`)]:[],...e?.blocked.camera?[Z(`noCamera`)]:[],...e?.none?[Z(`noDevices`)]:[],...t?[Z(`refused`)]:[]],eI=({url:e,leave:t,nameOf:n=e=>e,admission:r,name:i,className:a})=>{let o=QF(e,{...r&&{admission:r}}),[s,c]=(0,I.useState)(!1),{basePath:l}=jh(),u=Od(),d=u?.state.kind===`signed-in`?u.state.user:void 0,f=o.self??d?.id??``,[p]=(0,I.useState)(()=>Date.now()),{devices:m,phase:h}=o,g={...m?.microphone&&{microphone:m.microphone},...m?.camera&&{camera:m.camera},...o.screen&&{screen:o.screen.video},microphoneOn:o.microphoneOn,cameraOn:o.cameraOn},_=new Map([...m?.microphone&&o.microphoneOn?[[f,m.microphone]]:[],...o.tracks.filter(e=>e.source===`microphone`&&e.track&&!e.muted).map(e=>[e.member,e.track])]),v=VF(h.kind===`in`?_:new Map),y=$F(m,o.refusedSending);if(h.kind===`left`)return(0,B.jsx)(gF,{reason:h.reason,onJoinAgain:()=>void o.join()});if(h.kind===`waiting`)return(0,B.jsx)(NF,{leave:t});if(h.kind===`check`)return(0,B.jsx)(cF,{name:i??d?.name??Z(`you`),...r&&{joinLabel:Z(`askToJoin`)},member:f,...m?.camera&&{camera:m.camera},microphoneOn:o.microphoneOn,cameraOn:o.cameraOn,microphone:!!m?.microphone,cameraAvailable:!!m?.camera,notices:y,onMicrophone:o.toggleMicrophone,onCamera:o.toggleCamera,onJoin:()=>void o.join(),cancel:t});let{lobby:b,guests:x}=o,S=o.members.filter(e=>e.member.startsWith(`guest:`)).map(e=>({guest:e.member.slice(6),name:e.name??``})),C=CF({members:o.members,self:f,tracks:o.tracks,own:g,nameOf:n,...v&&{speaker:v},connections:o.connections,seen:o.seen,now:Math.max(p,Date.now())});return(0,B.jsx)(MF,{...a&&{className:a},people:C,state:h.kind===`joining`?`joining`:h.resuming?`resuming`:`joined`,notices:y,...b&&x&&{aside:(0,B.jsx)(mF,{waiting:b.guests,guests:x})},controls:{microphoneOn:o.microphoneOn&&!!m?.microphone,cameraOn:o.cameraOn&&!!m?.camera,sharing:!!o.screen,onMicrophone:o.toggleMicrophone,onCamera:o.toggleCamera,...o.toggleScreen&&{onShare:()=>void o.toggleScreen()},...b&&{guests:{waiting:b.guests.length,onOpen:()=>c(!0)}},leave:t},children:b&&x&&(0,B.jsx)(pF,{lobby:b,inCall:S,guests:x,linkOf:e=>FF(`${window.location.origin}${l}`,e),open:s,onClose:()=>c(!1)})})},tI=({link:e,systemPath:t,base:n})=>{let[r,i]=(0,I.useState)(``),[a,o]=(0,I.useState)(),[s,c]=(0,I.useState)(!1),l=(0,I.useCallback)(async n=>{let{guestLobby:r}=await Ve(async()=>{let{guestLobby:e}=await import(`./calls-DHvl29Pd.js`);return{guestLobby:e}},[]);return YF(r({systemPath:t}),e,a,n)},[t,e,a]),u=e=>{e.preventDefault(),r.trim()&&o(r.trim())},d=FF(n,e);return s?(0,B.jsx)(`p`,{role:`status`,className:`flex min-h-[100dvh] items-center justify-center bg-background p-4 text-sm text-foreground`,children:Z(`youLeft`)}):a===void 0?(0,B.jsx)(`main`,{className:`flex min-h-[100dvh] items-center justify-center bg-background p-4`,children:(0,B.jsxs)(`form`,{onSubmit:u,className:`flex w-full max-w-sm flex-col gap-3`,children:[(0,B.jsx)(`p`,{className:`text-sm text-foreground`,children:Z(`guestIntro`)}),(0,B.jsxs)(`label`,{className:`flex flex-col gap-1 text-sm text-foreground`,children:[Z(`yourName`),(0,B.jsx)(J,{autoFocus:!0,autoComplete:`name`,maxLength:60,value:r,onChange:e=>i(e.target.value)})]}),(0,B.jsx)(G,{type:`submit`,variant:`primary`,disabled:!r.trim(),children:Z(`continue`)})]})}):(0,B.jsx)(`main`,{className:`h-[100dvh]`,children:(0,B.jsx)(eI,{url:Dr(t,`socket`),admission:l,name:a,nameOf:()=>Z(`someone`),leave:{href:d,onFollow:()=>c(!0)}})})},nI=[`light`,`dark`,`system`],rI=`protobase:theme`,iI=`(prefers-color-scheme: dark)`,aI=e=>nI.includes(e),oI=e=>Ie(()=>{let t=e.getItem(rI);return aI(t)?t:`system`},`system`),sI=(e,t)=>Ie(()=>t===`system`?e.removeItem(rI):e.setItem(rI,t),void 0),cI=(e,t)=>e===`system`?t?`dark`:`light`:e,lI=(0,I.createContext)(void 0),uI=({children:e})=>{let[t,n]=(0,I.useState)(()=>oI(localStorage)),r=cI(t,hf(iI));return(0,I.useEffect)(()=>{document.documentElement.dataset.theme=r},[r]),(0,I.useEffect)(()=>{let e=e=>{(e.key===`protobase:theme`||e.key===null)&&n(oI(localStorage))};return window.addEventListener(`storage`,e),()=>window.removeEventListener(`storage`,e)},[]),(0,B.jsx)(lI.Provider,{value:{preference:t,theme:r,choose:e=>{sI(localStorage,e),n(e)}},children:e})},dI=()=>{let e=(0,I.useContext)(lI);if(!e)throw Error(`useTheme needs a ThemeProvider above it`);return e},fI=M(`chat`),pI=({children:e,className:t})=>(0,B.jsx)(`p`,{className:P(`text-xs text-muted-foreground`,t),children:e}),mI=({time:e})=>{let t=Date.parse(e);return(0,B.jsx)(`time`,{dateTime:e,title:dp(t),className:`text-xs text-muted-foreground`,children:vp(t)})},hI=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)(If,{initials:I_(s)||`?`,hue:F_(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)(mI,{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)(pI,{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)(pI,{className:e.from===`user`?`text-right`:void 0,children:n})]}):r},gI=e=>e.scrollHeight-e.scrollTop-e.clientHeight<=24,_I=(e,t)=>{if(t.followKey!==e.followKey)return t.scrollHeight;if(e.first===void 0&&t.first!==void 0&&t.newLineTop!==void 0)return Math.max(0,t.scrollTop+t.newLineTop-16);if(e.first!==void 0&&t.first!==e.first&&e.anchor&&t.anchorTop!==void 0)return t.scrollTop+t.anchorTop-e.anchor.top;if(e.atEnd)return t.scrollHeight},vI=(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:gI(e),first:t.firstElementChild??void 0,followKey:n,...a}},yI=(e,t)=>{let n=(0,I.useRef)({onReadToEnd:e,atEnd:t});(0,I.useLayoutEffect)(()=>{n.current={onReadToEnd:e,atEnd:t}});let r=(0,I.useCallback)(()=>{document.visibilityState===`visible`&&n.current.onReadToEnd?.()},[]);return(0,I.useEffect)(()=>{let e=()=>{n.current.atEnd()&&r()};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[r]),r},bI=e=>e.querySelector(`[data-chat-divider][data-tone="new"]`),xI=({children:e,empty:t,length:n,onLoadEarlier:r,loadingEarlier:i,followKey:a,onReadToEnd:o})=>{let s=(0,I.useRef)(null),c=(0,I.useRef)(null),l=(0,I.useRef)({atEnd:!0,first:void 0,followKey:a}),u=()=>{s.current&&c.current&&(l.current=vI(s.current,c.current,a))},d=()=>l.current.atEnd&&l.current.first!==void 0,f=yI(o,d),p=()=>{let e=l.current.atEnd;u(),!e&&d()&&f()};(0,I.useLayoutEffect)(()=>{let e=s.current;if(!e||!c.current)return;let t=l.current,n=t.anchor&&t.anchor.element.isConnected?t.anchor.element.getBoundingClientRect().top-e.getBoundingClientRect().top:void 0,r=bI(c.current),i=r?r.getBoundingClientRect().top-e.getBoundingClientRect().top:void 0,o=_I(t,{first:c.current.firstElementChild??void 0,anchorTop:n,scrollTop:e.scrollTop,scrollHeight:e.scrollHeight,followKey:a,newLineTop:i});o!==void 0&&(e.scrollTop=o),u(),d()&&f()},[n,a]),(0,I.useEffect)(()=>{let e=s.current;if(!e||!c.current)return;let t=new ResizeObserver(()=>{l.current.atEnd&&(e.scrollTop=e.scrollHeight)});return t.observe(e),t.observe(c.current),()=>t.disconnect()},[]);let m=n===0&&!!t;return(0,B.jsxs)(`div`,{ref:s,onScroll:p,className:`flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto p-4 [overflow-anchor:none]`,children:[r&&(0,B.jsx)(G,{size:`sm`,className:`self-center`,loading:i,onClick:r,children:fI(`loadEarlier`)}),m&&(0,B.jsx)(`div`,{className:`m-auto max-w-60 text-center text-muted-foreground`,children:t}),(0,B.jsx)(`div`,{ref:c,role:`log`,"aria-live":`polite`,className:P(`flex flex-col gap-4`,m&&`hidden`),children:e})]})},SI=(e,t)=>{let n=/(?:^|\s)@([^\s@]*)$/.exec(e.slice(0,t));return n?{start:t-n[1].length-1,query:n[1]}:void 0},CI=(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(` `)}},wI=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),TI=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(wI).join(`|`)})(?![\\p{L}\\p{N}_])`,`gu`)},EI=(e,t)=>{let n=TI(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))]},DI=(e,t)=>{let n=TI(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},OI=M(`mentions`),kI=({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":OI(`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:OI(o?`couldNotSearch`:`noOneFound`)})]}),AI=(e,t)=>{let n=eT(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},jI={text:``,picked:[]},MI=8,NI=({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?SI(e.text,l):void 0,S=d&&x!==void 0&&x.start!==h,C=AI(n,S?x.query:void 0),w=S&&C&&`people`in C?C.people.slice(0,MI):[],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=CI(e.text,x,n.name);y.current=r.caret,t({text:r.text,picked:[...e.picked,n]})},k=e=>{if(S){let t=Zw(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)(Ug,{...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)(kI,{id:b,optionId:E,people:w,active:p,onActive:m,onPick:O,failed:`failed`in C,at:r})]})},PI=({text:e,mentions:t})=>(0,B.jsx)(`p`,{className:`whitespace-pre-wrap break-words`,children:DI(e,t).map((e,t)=>`mention`in e?(0,B.jsxs)(`span`,{className:`font-medium text-primary`,children:[`@`,e.mention]},t):e.text)}),FI=e=>e.types.includes(`Files`),II=e=>e.types.includes(`text/plain`)?[]:[...e.files],LI=(e,{busy:t,canSendEmpty:n})=>t?!1:e!==``||n===!0,RI=({onSend:e,busy:t,placeholder:n,inputRef:r,searchPeople:i,attachments:a,actions:o,canSendEmpty:s,onFiles:c})=>{let[l,u]=(0,I.useState)(jI),d=l.text.trim(),f=LI(d,{busy:t,canSendEmpty:s}),p=()=>{f&&(e?.(d,EI(d,l.picked)),u(jI))};return(0,B.jsxs)(`form`,{className:`flex flex-wrap items-end gap-2`,onSubmit:e=>{e.preventDefault(),p()},onDragOver:e=>{c&&FI(e.dataTransfer)&&e.preventDefault()},onDrop:e=>{c&&FI(e.dataTransfer)&&(e.preventDefault(),c([...e.dataTransfer.files]))},children:[a&&(0,B.jsx)(`div`,{className:`basis-full`,children:a}),o,(0,B.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,B.jsx)(NI,{ref:r,rows:1,"aria-label":fI(`message`),placeholder:n,value:l,onChange:u,searchPeople:i,listAt:`above`,onKeyDown:e=>{e.key!==`Enter`||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),p())},onPaste:e=>{if(!c)return;let t=II(e.clipboardData);t.length!==0&&(e.preventDefault(),c(t))}})}),(0,B.jsx)(G,{type:`submit`,variant:`primary`,className:`w-8 px-0`,"aria-label":fI(`send`),disabled:!f,children:(0,B.jsx)(ls,{className:`size-4`})})]})},zI=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},BI=M(`side-panel`),VI=({title:e,icon:t,status:n,onClose:r,footer:i,children:a})=>{let o=zI(!gf());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":BI(`close`),onClick:r,children:(0,B.jsx)(yc,{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})]})},HI=M(`action-card`),UI={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`}},WI=({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`,UI[t].border),children:[!s&&(0,B.jsxs)(`header`,{className:P(`flex items-center gap-2 px-3 py-2`,UI[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)(Cf,{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:HI(`cancel`)}),(0,B.jsx)(G,{variant:c.style===`danger`?`danger`:`primary`,onClick:()=>{l(void 0),a?.(c.id)},children:c.label})]})})]})},GI=({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}`))}),KI=e=>e==null?`null`:typeof e==`object`?JSON.stringify(e):String(e),qI=M(`compact-table`),JI=({columns:e,rows:t,caption:n,truncated:r,className:i})=>(0,B.jsxs)(`section`,{"aria-label":n??qI(`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:qI(`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:KI(e)},t))},t))})]})}),(0,B.jsxs)(`footer`,{className:`border-t border-border px-3 py-1.5 text-[11px] text-muted-foreground`,children:[qI(`rows`,{count:t.length}),r&&qI(`cutOff`)]})]}),YI=(e,t=1)=>{let n=t,r=t;return e.split(`
|
|
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-DAJkSlba.js","assets/maplibre-lc2A-_P4.js","assets/preload-helper-DedkISGJ.js","assets/vendor-Kvdo8Jrw.js","assets/maplibre-DBE96hFo.css","assets/record-map-CupIwJyD.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,ct as ie,d as ae,et as oe,f as se,g as ce,h as le,i as ue,it as de,j as fe,k as pe,l as me,lt as he,m as ge,n as _e,nt as ve,o as ye,ot as be,p as xe,q as Se,r as Ce,rt as we,s as Te,st as Ee,t as De,u as Oe,v as ke,w as Ae,x as je,y as Me,z as Ne}from"./vendor-Kvdo8Jrw.js";import{a as M,d as Pe,f as Fe,i as Ie,l as Le,n as Re,o as N,r as ze,s as Be,t as Ve,u as He}from"./preload-helper-DedkISGJ.js";import{t as P}from"./cn-Bi0ZEjD9.js";var Ue=(e,t,n,r)=>({code:e,message:t,hint:n,span:r}),We=(e,t)=>{let n=Array.from({length:t.length+1},(e,t)=>t);for(let r=1;r<=e.length;r++){let i=[r];for(let a=1;a<=t.length;a++){let o=e[r-1]===t[a-1]?0:1;i[a]=Math.min(n[a]+1,i[a-1]+1,n[a-1]+o)}n=i}return n[t.length]},Ge=(e,t)=>{let n=e.toLowerCase(),r=t.map(e=>({candidate:e,score:We(n,e.toLowerCase())})).sort((e,t)=>e.score-t.score)[0];return r&&r.score<=Math.max(2,Math.floor(e.length/3))?r.candidate:void 0},Ke={in:{params:[{name:`field`,type:`field`}],rest:{name:`value`,type:`any`}},search:{params:[{name:`text`,type:`string`}]},similar:{params:[{name:`field`,type:`field`,of:[`string`]},{name:`text`,type:`string`}]},regex:{params:[{name:`field`,type:`field`,of:[`string`]},{name:`pattern`,type:`string`}]},isNull:{params:[{name:`field`,type:`field`}]},now:{params:[],returns:`timestamp`}},qe={extensions:{arithmetic:`now-offset`,durationUnits:!0}},Je=e=>{switch(e.type){case`text`:return`string`;case`integer`:case`bigint`:return`integer`;case`boolean`:case`timestamp`:case`enum`:return e.type;default:return`any`}},Ye=e=>({fields:Object.fromEntries(Object.values(e.fields).map(e=>[e.name,{type:Je(e),filterable:e.filterable,sortable:e.sortable,aliases:e.aliases,...e.enumValues&&{values:e.enumValues}}])),functions:Ke}),Xe=(e,t,n,r)=>{e.errors.push(Ue(`unsupported`,t,n,r))},Ze=(e,t)=>t.kind===`member`?{kind:`field`,path:t.path,span:t.span}:Xe(e,`Only fields can be compared`,`Put a field name on the left, for example total > 100`,t.span),Qe=(e,t)=>{switch(t.kind){case`member`:return{kind:`string`,value:t.path.join(`.`),span:t.span};case`call`:return t.name===`now`&&t.args.length===0?{kind:`now`,span:t.span}:Xe(e,`${t.name}() cannot be used as a value`,`Only now() is a value function`,t.span);case`binary`:{let n=t.left;return n.kind===`call`&&n.name===`now`&&n.args.length===0&&t.right.kind===`duration`?{kind:`now`,offset:{sign:t.op,duration:t.right},span:t.span}:Xe(e,`Arithmetic is only supported as now() +/- duration`,`Write now() - 30d`,t.span)}default:return t}},$e=(e,t)=>(`kind`in t&&[`member`,`call`,`binary`].includes(t.kind)?void 0:t)||(t.kind===`member`?{kind:`string`,value:t.path.join(`.`),span:t.span}:Xe(e,`Expected a literal value`,`Use strings, numbers, true/false, durations or timestamps`,t.span)),et=e=>{switch(e.kind){case`member`:return e.path.join(`.`);case`string`:case`timestamp`:return e.kind,e.value;case`number`:return e.raw;case`boolean`:return String(e.value);case`duration`:return`${e.amount}${e.unit}`;default:return``}},tt=(e,t)=>{let[n,r,...i]=t.args,a=n?.kind===`member`?Ze(e,n):void 0,o=e=>e?.kind===`string`?e.value:void 0,s=n=>{e.errors.push(Ue(`invalid-arguments`,`Invalid arguments to ${t.name}()`,`Usage: ${n}`,t.span))};switch(t.name){case`in`:{let n=t.args.slice(1).map(t=>$e(e,t));return!a||n.length===0?s(`in(field, value1, value2, ...)`):n.every(e=>e)?{kind:`in`,field:a,values:n,span:t.span}:void 0}case`search`:return o(n)!==void 0&&!r?{kind:`search`,text:o(n),span:t.span}:s(`search("text")`);case`similar`:return a&&o(r)!==void 0&&i.length===0?{kind:`similar`,field:a,text:o(r),span:t.span}:s(`similar(field, "text")`);case`regex`:return a&&o(r)!==void 0&&i.length===0?{kind:`regex`,field:a,pattern:o(r),span:t.span}:s(`regex(field, "pattern")`);case`isNull`:return a&&!r?{kind:`isNull`,field:a,span:t.span}:s(`isNull(field)`);default:e.errors.push(Ue(`unknown-function`,`Unknown function "${t.name}"`,`Available functions: ${Object.keys(Ke).join(`, `)}`,t.span));return}},nt=e=>e.every(e=>e)?e:void 0,rt=(e,t)=>{switch(t.kind){case`sequence`:case`and`:case`or`:{let n=nt(t.args.map(t=>rt(e,t)));return n&&{kind:t.kind===`or`?`or`:`and`,args:n,span:t.span}}case`not`:{let n=rt(e,t.arg);return n&&{kind:`not`,arg:n,span:t.span}}case`compare`:{let n=Ze(e,t.left),r=Qe(e,t.right);return n&&r&&{kind:`compare`,op:t.op,field:n,value:r,span:t.span}}case`has`:{let n=Ze(e,t.left),r=$e(e,t.right);return n&&r&&{kind:`has`,field:n,value:r,span:t.span}}case`present`:{let n=Ze(e,t.left);return n&&{kind:`present`,field:n,span:t.span}}case`global`:return{kind:`search`,text:et(t.value),span:t.span};case`call`:return tt(e,t)}},it=(e,t={})=>{let n=ie(e,{...qe,...t}),r={errors:[]},i=n.ast&&rt(r,n.ast),a=[...n.errors,...r.errors].sort((e,t)=>e.span.start-t.span.start);return a.length===0?{ok:!0,ast:i,errors:[]}:{ok:!1,ast:i,errors:a}},at=(e,t)=>t===2?e%4==0&&(e%100!=0||e%400==0)?29:28:[4,6,9,11].includes(t)?30:31,ot=e=>{let t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e);if(!t)return!1;let[n,r,i]=[Number(t[1]),Number(t[2]),Number(t[3])];return r>=1&&r<=12&&i>=1&&i<=at(n,r)},st=e=>{let t=/^(\d{4}-\d{2}-\d{2})[Tt](\d{2}):(\d{2}):(\d{2})(?:\.\d+)?(?:[Zz]|[+-](\d{2}):(\d{2}))$/.exec(e);if(!t)return!1;let[n,r,i]=[Number(t[2]),Number(t[3]),Number(t[4])],[a,o]=[Number(t[5]??0),Number(t[6]??0)];return ot(t[1])&&n<=23&&r<=59&&i<=59&&a<=23&&o<=59},ct=(e,t)=>({message:e,hint:t}),lt=-(2n**63n),ut=2n**63n-1n,dt=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,ft=e=>e.kind===`number`?e.raw:e.kind===`string`?e.value:void 0,pt=(e,t=`Write ${e} values like the examples in the docs`)=>ct(`Expected ${e}`,t),mt=e=>{let t=ft(e),n=t===void 0?NaN:Number(t);if(t===void 0||t.trim()===``||!Number.isSafeInteger(n))return pt(`a whole number`,`Use an integer such as 42, or a bigint field for larger values`)},ht=e=>{let t=ft(e);if(t===void 0||!/^-?\d+$/.test(t)||BigInt(t)<lt||BigInt(t)>ut)return pt(`a 64-bit integer`,`Use plain digits such as 9007199254740993 (no exponent or fraction)`)},gt=e=>{let t=ft(e);if(t===void 0||!/^-?\d+(\.\d+)?$/.test(t))return pt(`a decimal number`,`Use plain digits such as 100.50, or quote it: "100.50" (no exponent)`)},_t=(e,t)=>{if(t.kind===`now`)return e.type===`date`||e.type===`timestamp`?void 0:ct(`now() only works with date and timestamp fields`,`Field "${e.name}" is ${e.type}`);switch(e.type){case`text`:return t.kind===`string`?void 0:pt(`a quoted string`,`Wrap the text in double quotes`);case`integer`:return mt(t);case`bigint`:return ht(t);case`decimal`:return gt(t);case`boolean`:return t.kind===`boolean`?void 0:pt(`true or false`);case`date`:return t.kind===`string`&&ot(t.value)?void 0:pt(`a date`,`Quote a calendar date: "2012-04-21"`);case`timestamp`:return t.kind===`timestamp`||t.kind===`string`&&st(t.value)?void 0:pt(`an RFC-3339 timestamp`,`Use 2012-04-21T11:30:00Z, or now() - 7d`);case`uuid`:return t.kind===`string`&&dt.test(t.value)?void 0:pt(`a uuid`,`Quote a uuid like "0b5a4f0e-6f2a-4a3c-9d4e-1f2a3b4c5d6e"`);case`enum`:return t.kind===`string`&&e.enumValues?.includes(t.value)?void 0:ct(`Invalid enum value`,`Allowed values: ${(e.enumValues??[]).join(`, `)}`);case`currency`:return t.kind===`string`&&/^[A-Z]{3}$/.test(t.value)?void 0:pt(`an ISO 4217 currency code`,`Use three capital letters, for example "EUR"`);case`country`:return t.kind===`string`&&/^[A-Z]{2}$/.test(t.value)?void 0:pt(`an ISO 3166-1 country code`,`Use two capital letters, for example "NL"`);case`relation`:return t.kind===`string`||t.kind===`number`&&Number.isSafeInteger(t.value)?void 0:pt(`a record key`,`Use the related record key: 42 or "abc"`);case`json`:case`file`:return ct(`${e.type} fields cannot be compared`,`Use field:value on json fields, or isNull(field)`)}},vt=(e,t)=>Object.hasOwn(e.fields,t)?e.fields[t]:Object.values(e.fields).find(e=>e.aliases.includes(t)),yt=(e,t,n)=>{if(t.path.length>1){e.errors.push(Ue(`unsupported-traversal`,`Traversal into "${t.path.join(`.`)}" is not supported yet`,`Filter on fields of this resource only`,t.span));return}let r=t.path[0],i=vt(e.model,r);if(!i){let i=Object.values(e.model.fields).filter(e=>e[n]).map(e=>e.name),a=Ge(r,i);e.errors.push(Ue(`unknown-field`,`Unknown field "${r}"`,a?`Did you mean "${a}"?`:`Available fields: ${i.join(`, `)}`,t.span));return}if(!i[n]){let r=n===`filterable`?`filterable`:`sortable`;e.errors.push(Ue(n===`filterable`?`not-filterable`:`not-sortable`,`Field "${i.name}" is not ${r}`,`Mark it with .${r}() in data.ts`,t.span));return}return i},bt=[`=`,`!=`],xt=[`=`,`!=`,`<`,`<=`,`>`,`>=`],St=e=>{switch(e){case`text`:case`integer`:case`bigint`:case`decimal`:case`date`:case`timestamp`:return xt;case`json`:case`file`:return[];default:return bt}},Ct=e=>e===`json`||e===`file`,wt=(e,t,n)=>{let r=_t(t,n);return r&&e.errors.push(Ue(`invalid-value`,r.message,r.hint,n.span)),!r},Tt=(e,t,n,r)=>{e.errors.push(Ue(`operator-not-allowed`,t,n,r))},Et=(e,t)=>(e===`=`||e===`!=`)&&t.kind===`string`&&t.value.includes(`*`),Dt=(e,t)=>{let n=yt(e,t.field,`filterable`);if(!n)return;let r=St(n.type);if(!r.includes(t.op)){Tt(e,`Operator "${t.op}" is not supported for ${n.type} fields`,r.length?`Supported: ${r.join(` `)}`:`Use field:value on json fields, or isNull(field)`,t.span);return}if(Et(t.op,t.value)&&n.type!==`text`){e.errors.push(Ue(`wildcard-not-allowed`,`Wildcards are only supported on text fields, not ${n.type}`,`Remove the "*" or filter a text field`,t.value.span));return}if(Et(t.op,t.value)||wt(e,n,t.value))return{...t,field:n}},Ot=(e,t)=>{let n=yt(e,t.field,`filterable`);if(n){if(n.type!==`json`){Tt(e,`":" is only supported on json fields, not ${n.type}`,`Use = on ${n.type} fields, or field:* to test for a value`,t.span);return}return{...t,field:n}}},kt=(e,t)=>{let n=yt(e,t.field,`filterable`);if(n){if(Ct(n.type)){Tt(e,`in() is not supported for ${n.type} fields`,`Use field:value on json fields`,t.span);return}return t.values.map(t=>wt(e,n,t)).every(Boolean)?{...t,field:n}:void 0}},At=(e,t,n)=>{let r=yt(e,n,`filterable`);if(r&&r.type!==`text`){Tt(e,`${t}() only works on text fields, not ${r.type}`,`Field "${r.name}" is ${r.type}`,n.span);return}return r},jt=(e,t)=>{switch(t.kind){case`and`:case`or`:{let n=t.args.map(t=>jt(e,t));return n.every(e=>e)?{...t,args:n}:void 0}case`not`:{let n=jt(e,t.arg);return n&&{...t,arg:n}}case`compare`:return Dt(e,t);case`has`:return Ot(e,t);case`in`:return kt(e,t);case`search`:if(e.model.search?.length)return t;e.errors.push(Ue(`no-search-fields`,`This resource has no search fields`,`Declare them with .search((r) => [r.title]) in data.ts`,t.span));return;case`present`:case`isNull`:{let n=yt(e,t.field,`filterable`);return n&&{...t,field:n}}case`similar`:case`regex`:{let n=At(e,t.kind,t.field);return n&&{...t,field:n}}}},Mt=(e,t)=>{let n={model:e,errors:[]},r=jt(n,t);return!r||n.errors.length>0?{ok:!1,errors:[...n.errors].sort((e,t)=>e.span.start-t.span.start)}:{ok:!0,filter:r}},Nt=(e,t)=>`path`in e?{kind:`member`,path:e.path,span:e.span}:{kind:`member`,path:[e.name],field:{name:e.name,spec:{type:Je(e)}},span:t},Pt=(e,t,n)=>({kind:`call`,name:e,args:t,span:n}),Ft=(e,t)=>({kind:`string`,value:e,span:t}),It=e=>{if(e.kind!==`now`)return e;let t={kind:`call`,name:`now`,args:[],span:e.span};return e.offset?{kind:`binary`,op:e.offset.sign,left:t,right:e.offset.duration,span:e.span}:t},Lt=(e,t={})=>{let n=e=>Lt(e,t);switch(e.kind){case`and`:case`or`:return{kind:e.kind,args:e.args.map(n),span:e.span};case`not`:return{kind:`not`,arg:n(e.arg),span:e.span};case`compare`:return{kind:`compare`,op:e.op,left:Nt(e.field,e.span),right:It(e.value),span:e.span};case`has`:return{kind:`has`,left:Nt(e.field,e.span),right:e.value,span:e.span};case`present`:return{kind:`present`,left:Nt(e.field,e.span),span:e.span};case`in`:return t.expand?{kind:`or`,args:e.values.map(t=>({kind:`compare`,op:`=`,left:Nt(e.field,e.span),right:t,span:e.span})),span:e.span}:Pt(`in`,[Nt(e.field,e.span),...e.values],e.span);case`search`:return Pt(`search`,[Ft(e.text,e.span)],e.span);case`similar`:return Pt(`similar`,[Nt(e.field,e.span),Ft(e.text,e.span)],e.span);case`regex`:return Pt(`regex`,[Nt(e.field,e.span),Ft(e.pattern,e.span)],e.span);case`isNull`:return t.expand?{kind:`not`,arg:{kind:`present`,left:Nt(e.field,e.span),span:e.span},span:e.span}:Pt(`isNull`,[Nt(e.field,e.span)],e.span)}},Rt=(e,t)=>{let n=Mt(e,t);if(!n.ok&&n.errors.some(e=>e.code===`unsupported-traversal`))return n;let r=be(Lt(t),Ye(e));return r.ok?Mt(e,t):{ok:!1,errors:r.errors}},zt=/^[\d\s+\-().\/]+$/,Bt=e=>zt.test(e)?e.replace(/\D/g,``):``,Vt=e=>{let t=e.split(/\s+/).filter(Boolean).map(e=>({text:e,digits:Bt(e),whole:!1})),n=t.length>1?Bt(e.trim()):``;return n?[{text:e.trim(),digits:n,whole:!0},...t]:t},Ht=(e,t,n)=>e==null?!1:n===`digitsEnd`?t.digits!==``&&String(e).replace(/\D/g,``).endsWith(t.digits):!t.whole&&String(e).toLowerCase().includes(t.text.toLowerCase()),Ut=(e,t,n)=>(e.search??[]).filter(r=>Ht(t[r],n,e.searchMatch?.[r])),Wt=(e,t,n)=>{let r=Vt(n),i=r.filter(e=>!e.whole),a=r.find(e=>e.whole);return a&&Ut(e,t,a).length>0?!0:i.length>0&&i.every(n=>Ut(e,t,n).length>0)},Gt=(e,t,n,r)=>{for(let i of Vt(n)){let n=Ut(e,t,i);if(n.length>0&&!n.some(e=>r.includes(e)))return n[0]}},Kt=e=>()=>{throw Error(`Not implemented: ${e}() needs the database (the resource's search fields, trigram matching), so it cannot be evaluated against a record`)},qt=(e,t,n)=>({...Ke,search:{...Ke.search,evaluate:n?e=>Wt(n,t,e):Kt(`search`)},similar:{...Ke.similar,evaluate:Kt(`similar`)},regex:{...Ke.regex,evaluate:(e,t)=>e.some(e=>typeof e==`string`&&new RegExp(t).test(e))},now:{...Ke.now,evaluate:e}}),Jt=(e,t,n={})=>Ee(Lt(e,{expand:!0}),t,{functions:qt(n.now??(()=>new Date),t,n.search)}),Yt=e=>he(Lt(e)),Xt=e=>e.map(e=>({path:e.path.path,direction:e.direction,span:e.span})),Zt=e=>e.replace(/([^\s,])(\s+)(asc|desc)(?=\s|,|$)/gi,(e,t,n,r)=>`${t}${n}${r.toLowerCase()}`),Qt=e=>{let t=te(Zt(e)),n=t.items.map(e=>({path:{kind:`field`,path:e.path,span:e.span},direction:e.direction,span:e.span}));return t.ok?{ok:!0,items:n,errors:[]}:{ok:!1,items:n,errors:t.errors}},$t=(e,t)=>{let n=t.filter(e=>e.path.path.length>1).map(e=>Ue(`unsupported-traversal`,`Traversal into "${e.path.path.join(`.`)}" is not supported yet`,`Sort on fields of this resource only`,e.path.span));if(n.length>0)return{ok:!1,errors:n};let r=de(Xt(t),Ye(e));return r.ok?{ok:!0,sort:r.items.map(e=>[e.path[0],e.direction])}:{ok:!1,errors:r.errors}},en=e=>{let t=/^(\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)([smhdw])$/.exec(e);if(!t)throw Error(`Invalid duration "${e}", expected for example 30d or 1.5h`);return{kind:`duration`,amount:Number(t[1]),unit:t[2],span:{start:0,end:0}}},tn={start:0,end:0},nn=e=>({kind:`field`,path:e.split(`.`),span:tn}),rn=e=>{if(typeof e==`string`)return{kind:`string`,value:e,span:tn};if(typeof e==`boolean`)return{kind:`boolean`,value:e,span:tn};if(!Number.isFinite(e))throw Error(`Filter numbers must be finite`);return{kind:`number`,value:e,raw:String(e),span:tn}},an=e=>typeof e==`object`?e:rn(e),on=(e,t)=>{if(t.length===0)throw Error(`where.${e} needs at least one filter`);return t.length===1?t[0]:{kind:e,args:t,span:tn}},sn=()=>{let e=e=>(t,n)=>({kind:`compare`,op:e,field:nn(t),value:an(n),span:tn}),t=e=>t=>({kind:`now`,offset:{sign:e,duration:en(t)},span:tn});return{eq:e(`=`),ne:e(`!=`),lt:e(`<`),lte:e(`<=`),gt:e(`>`),gte:e(`>=`),between:(t,n,r)=>on(`and`,[e(`>=`)(t,n),e(`<=`)(t,r)]),has:(e,t)=>({kind:`has`,field:nn(e),value:rn(t),span:tn}),present:e=>({kind:`present`,field:nn(e),span:tn}),in:(e,t)=>({kind:`in`,field:nn(e),values:t.map(rn),span:tn}),isNull:e=>({kind:`isNull`,field:nn(e),span:tn}),search:e=>({kind:`search`,text:e,span:tn}),similar:(e,t)=>({kind:`similar`,field:nn(e),text:t,span:tn}),regex:(e,t)=>({kind:`regex`,field:nn(e),pattern:t,span:tn}),and:(...e)=>on(`and`,e),or:(...e)=>on(`or`,e),not:e=>({kind:`not`,arg:e,span:tn}),now:()=>({kind:`now`,span:tn}),ago:t(`-`),fromNow:t(`+`)}},cn=sn(),ln=/\{([A-Za-z_][A-Za-z0-9_]*)\}/g,un=e=>[...e.matchAll(ln)].map(e=>e[1]),dn=e=>e.kind===`record`?(Array.isArray(e.key)?e.key:[e.key]).filter(e=>typeof e==`string`):e.kind===`list`?[e.filter,e.orderBy].filter(e=>e!==void 0):e.kind===`create`?Object.values(e.values??{}):[],fn=e=>[...new Set(dn(e).flatMap(un))],pn=(e,t)=>e.replace(ln,(e,n)=>t[n]===null||t[n]===void 0?``:String(t[n])),mn=(e,t={})=>{if(e.kind===`record`){let n=e=>typeof e==`string`?pn(e,t):e;return{...e,key:Array.isArray(e.key)?e.key.map(n):n(e.key)}}return e.kind===`create`?e.values?{...e,values:Object.fromEntries(Object.entries(e.values).map(([e,n])=>[e,pn(n,t)]))}:e:e.kind===`list`?{...e,...e.filter!==void 0&&{filter:pn(e.filter,t)},...e.orderBy!==void 0&&{orderBy:pn(e.orderBy,t)}}:e},hn=e=>/^\{([A-Za-z_][A-Za-z0-9_]*)\}$/.exec(e)?.[1],gn=e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&Object.keys(e).length===1&&typeof e.$field==`string`,_n=e=>typeof e==`object`&&!!e&&!Array.isArray(e),vn=e=>gn(e)?e.$field:Array.isArray(e)?e.map(vn):_n(e)?Object.fromEntries(Object.entries(e).map(([e,t])=>[e,vn(t)])):e,yn=`table`,bn=/^[a-z0-9][a-z0-9_-]*$/,xn=e=>{if(!e.startsWith(`/-/forms/`))return;let t=e.slice(9);return bn.test(t)?{name:t}:void 0},Sn=e=>e.flatMap(e=>e.kind===`group`||e.kind===`tab`?Sn(e.items):[e]),Cn=(e,t)=>{if(t===void 0)return e;let n=e?.lists?.find(e=>e.name===t);if(!e||!n)return;let{list:r,chart:i,help:a,nav:o,lists:s,names:c,...l}=e,{name:u,...d}=n;return{...l,...d}},wn={text:`text`,integer:`integer`,decimal:`decimal`,boolean:`boolean`,date:`date`,choice:`text`,custom:`json`},Tn=e=>({name:e.name,column:e.name,type:e.options?`enum`:wn[e.kind],nullable:!0,readOnly:!1,filterable:e.kind!==`custom`,sortable:!1,aliases:[],...e.options&&{enumValues:e.options.map(e=>e.value)}}),En=e=>({name:`inputs`,table:{name:`inputs`},fields:Object.fromEntries(e.map(e=>[e.name,Tn(e)])),primaryKey:[]}),Dn=(e,t)=>{let n=e[t].when;if(n===void 0)return;let r=it(n);if(!r.ok)return r.errors.map(e=>e.message).join(`; `);if(!r.ast)return`it is empty`;let i=Rt(En(e.slice(0,t)),r.ast);return i.ok?i.filter:i.errors.map(e=>e.message).join(`; `)},On=(e,t)=>{let n=new Set,r={};return e.forEach((i,a)=>{let o=Dn(e,a);if(typeof o==`string`)throw Error(`Input "${i.name}": ${o}`);let s=o===void 0||Jt(o,r)===!0;s&&n.add(i.name),r[i.name]=s?t[i.name]??null:null}),n},kn=(e,t)=>Object.fromEntries(Object.entries(e).flatMap(([e,n])=>{let r=typeof n==`string`?hn(n):void 0;return r===void 0?[[e,n]]:Object.hasOwn(t,r)?[[e,t[r]]]:[]})),An=e=>`groupBy`in e,jn=[`neutral`,`blue`,`green`,`amber`,`red`,`violet`],Mn=e=>jn.includes(e),Nn=e=>{if(!Array.isArray(e))return String(e);let t=e;return t.length===1?String(t[0]):t.map(e=>encodeURIComponent(String(e))).join(`,`)},Pn=e(we(),1),Fn=e=>{try{return new Pn.default.Comparator(e),!0}catch(e){if(e instanceof TypeError)return!1;throw e}},In=(e,t)=>{let n=t.trim().split(/\s+/);if(Pn.default.valid(e)!==null&&t.trim()!==``&&n.every(Fn))return Pn.default.satisfies(e,t)},Ln=(e,t)=>{if(e.api!==t.api)return`it is built for plugin API ${e.api}, and this app has plugin API ${t.api}`;let n=In(t.version,e.protobase);if(n===void 0)return`its Protobase range "${e.protobase}" is not one this app reads, such as >=0.12.0`;if(!n)return`it needs Protobase ${e.protobase}, and this app runs ${t.version}`},Rn=`[Filtered]`,zn=/authorization|cookie|passw|secret|token|api[-_]?key|credential|session|csrf|signature|^sig$/i,Bn=new Set([`url`,`query_string`,`from`,`to`]),Vn=12,Hn=e=>e.replace(/(^|&)([^=&]*)=([^&]*)/g,(e,t,n)=>zn.test(n)?`${t}${n}=${Rn}`:e),Un=e=>{let t=e.indexOf(`?`);if(t===-1)return e;let n=e.indexOf(`#`,t),r=n===-1?e.slice(t+1):e.slice(t+1,n);return`${e.slice(0,t+1)}${Hn(r)}${n===-1?``:e.slice(n)}`},Wn=(e,t,n)=>zn.test(e)?Rn:typeof t==`string`&&Bn.has(e)?e===`query_string`?Hn(t):Un(t):Gn(t,n+1),Gn=(e,t)=>t>Vn||typeof e!=`object`||!e?e:Array.isArray(e)?e.map(e=>Array.isArray(e)&&e.length===2&&typeof e[0]==`string`?[e[0],Wn(e[0],e[1],t)]:Gn(e,t+1)):Object.fromEntries(Object.entries(e).map(([e,n])=>[e,Wn(e,n,t)])),Kn=e=>Gn(e,0),qn=[`unknown-field`,`not-filterable`,`not-sortable`,`unsupported-traversal`,`invalid-traversal`],Jn=e=>e.replace(/(["']?)\{[A-Za-z_][A-Za-z0-9_]*\}\1/g,(e,t)=>t?`${t}x${t}`:`0`),Yn=(e,t)=>{let n=it(Jn(t));if(!n.ok)return n.errors.map(e=>`filter: ${e.message}`);if(!n.ast)return[];let r=Rt(e,n.ast);return r.ok?[]:r.errors.filter(e=>qn.includes(e.code)).map(e=>`filter: ${e.message}`)},Xn=(e,t)=>{if(fn({kind:`list`,resource:e.name,orderBy:t}).length>0)return[];let n=Qt(t);if(!n.ok)return n.errors.map(e=>`orderBy: ${e.message}`);let r=$t(e,n.items);return r.ok?[]:r.errors.map(e=>`orderBy: ${e.message}`)},Zn=(e,{models:t,pages:n,source:r,createPages:i})=>{let a=fn(e).flatMap(e=>r?Object.hasOwn(r.fields,e)?[]:[`"{${e}}" is not a field of ${r.name}`]:[`"{${e}}" takes a value from the record, but the link sits on none`]);switch(e.kind){case`page`:return n&&!n.has(e.page)?[`unknown page "${e.page}"`]:[];case`list`:case`record`:case`create`:{let n=Object.hasOwn(t,e.resource)?t[e.resource]:void 0;return n?e.kind===`create`&&i?.has(e.resource)?a:e.kind===`create`?[...a,...Object.keys(e.values??{}).filter(e=>!Object.hasOwn(n.fields,e)).map(t=>`values: unknown field "${t}" on ${e.resource}`)]:e.kind===`list`?[...a,...e.filter?Yn(n,e.filter):[],...e.orderBy?Xn(n,e.orderBy):[]]:a:[`unknown resource "${e.resource}"`]}default:return[`an address's kind is list, record, create or page, not "${String(e.kind)}"`]}},Qn={messages:[],replying:!1},$n=(e,t)=>{let n=e.findIndex(e=>e.id===t.id);return n===-1?[...e,t]:e.map((e,r)=>r===n?t:e)},er=(e,t,n)=>{let r=e.find(e=>e.id===t);return $n(e,r?{...r,parts:$n(r.parts,n)}:{id:t,from:`assistant`,parts:[n]})},tr=(e,t)=>{switch(t.type){case`state`:return t.state;case`message`:return{...e,messages:$n(e.messages,t.message)};case`part`:return{...e,messages:er(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}}}}},nr=async(e,t,n)=>{let r=ve({onEvent:e=>t(e.data)}),i=new TextDecoder,a=e.getReader();for(n?.addEventListener(`abort`,()=>void a.cancel(),{once:!0});;){let{done:e,value:t}=await a.read();if(e)break;r.feed(i.decode(t,{stream:!0}))}r.feed(`${i.decode()}\n\n`)},rr=e=>e.charAt(0).toUpperCase()+e.slice(1),F=e=>rr(e.replace(/(Id|Code|_id|_code)$/,``).replace(/([a-z0-9])([A-Z])/g,`$1 $2`).replace(/_+/g,` `).trim().toLowerCase()||e),ir=(e,t)=>t?.[e]??e,ar=[`name`,`title`,`number`,`sku`,`email`,`code`,`description`],or=e=>e?.type===`text`&&!e.sensitive,sr=(e,t)=>t?.title??ar.find(t=>or(e.fields[t]))??Object.values(e.fields).find(or)?.name??e.primaryKey[0],cr=(e,t)=>t?.title??t?.list?.columns.find(t=>e.fields[t]?.type===`text`)??sr(e),lr=(e,t,n,r)=>{let i=cr(e,t),a=n[i];return a==null?r:e.fields[i]?.type===`enum`?ir(String(a),t?.fields[i]?.valueLabels):String(a)},ur={fingerprint:`fingerprint`,shellVersion:`shell_version`},dr=`/api/mobile/release`,fr=`/api/mobile/releases`,pr=({fingerprint:e,shellVersion:t})=>new URLSearchParams({[ur.fingerprint]:e,[ur.shellVersion]:t}).toString(),mr=`/api/auth`,hr={ios:`capacitor://localhost`,android:`https://localhost`},gr={database:`protobase-push`,store:`registration`,key:`current`},_r=`protobase.sw.js`,vr=(e,t)=>`${e}/notifications/devices${t===void 0?``:`/${encodeURIComponent(t)}`}`,yr=/^[A-Za-z0-9_-]{1,64}$/,br=(e,t)=>{let n=`${e}/notifications/history`;if(t===void 0)return n;if(typeof t==`string`)return`${n}/${t}`;if(!yr.test(t.read))throw Error(`A history entry id is letters, digits, "_" and "-" only`);return`${n}/${t.read}/read`},xr=(e,t)=>`${e}/status${t===void 0?``:`/${t}`}`,Sr=/\p{Cc}/u,Cr=e=>{if(Sr.test(e))return`A status is one line of text, without control characters`;if([...e].length>100)return`A status is at most 100 characters`},wr=(e,t=Date.now())=>{if(e&&!(e.clearsAt!==null&&Date.parse(e.clearsAt)<=t)&&(e.availability!==`automatic`||e.text!==null))return e},Tr=(e,t)=>t?.list?.columns??Object.values(e.fields).filter(e=>!e.writeOnly).slice(0,6).map(e=>e.name),Er={members:[`json`]},Dr=(e,t)=>`${e}/calls/guests${t?`/${t}`:``}`,Or=`decline`,kr=(e,t)=>{let n=`${e}/calls/rings`;return t===void 0?n:`${n}/${encodeURIComponent(t.decline)}/${Or}`},Ar=`calls`,jr={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`}]]};jr.node;var Mr=N(jr),Nr={name:`arrow-down`,size:24,node:[[`path`,{d:`M12 5v14`,key:`s699le`}],[`path`,{d:`m19 12-7 7-7-7`,key:`1idqje`}]]};Nr.node;var Pr=N(Nr),Fr={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`}]]};Fr.node;var Ir=N(Fr),Lr={name:`arrow-right`,size:24,node:[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`m12 5 7 7-7 7`,key:`xquz4c`}]]};Lr.node;var Rr=N(Lr),zr={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`}]]};zr.node;var Br=N(zr),Vr={name:`arrow-up-right`,size:24,node:[[`path`,{d:`M7 7h10v10`,key:`1tivn9`}],[`path`,{d:`M7 17 17 7`,key:`1vkiza`}]]};Vr.node;var Hr=N(Vr),Ur={name:`arrow-up`,size:24,node:[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]};Ur.node;var Wr=N(Ur),Gr={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`}]]};Gr.node;var Kr=N(Gr),qr={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`}]]};qr.node;var Jr=N(qr),Yr={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`}]]};Yr.node;var Xr=N(Yr),Zr={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`}]]};Zr.node;var Qr=N(Zr),$r={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`}]]};$r.node;var ei=N($r),ti={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`}]]};ti.node;var ni=N(ti),ri={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`}]]};ri.node;var ii=N(ri),ai={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`}]]};ai.node;var oi=N(ai),si={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`}]]};si.node;var ci=N(si),li={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`}]]};li.node;var ui=N(li),di={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`}]]};di.node;var fi=N(di),pi={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`]};pi.node;var mi=N(pi),hi={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`}]]};hi.node;var gi=N(hi),_i={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`}]]};_i.node;var vi=N(_i),yi={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`}]]};yi.node;var bi=N(yi),xi={name:`check`,size:24,node:[[`path`,{d:`M20 6 9 17l-5-5`,key:`1gmf2c`}]]};xi.node;var Si=N(xi),Ci={name:`chevron-down`,size:24,node:[[`path`,{d:`m6 9 6 6 6-6`,key:`qrunsl`}]]};Ci.node;var wi=N(Ci),Ti={name:`chevron-left`,size:24,node:[[`path`,{d:`m15 18-6-6 6-6`,key:`1wnfg3`}]]};Ti.node;var Ei=N(Ti),Di={name:`chevron-right`,size:24,node:[[`path`,{d:`m9 18 6-6-6-6`,key:`mthhwq`}]]};Di.node;var Oi=N(Di),ki={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`}]]};ki.node;var Ai=N(ki),ji={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`]};ji.node;var Mi=N(ji),Ni={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`]};Ni.node;var Pi=N(Ni),Fi={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`}]]};Fi.node;var Ii=N(Fi),Li={name:`circle-minus`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M8 12h8`,key:`1wcyev`}]],aliases:[`minus-circle`]};Li.node;var Ri=N(Li),zi={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`]};zi.node;var Bi=N(zi),Vi={name:`circle`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]};Vi.node;var Hi=N(Vi),Ui={name:`clock`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 6v6l4 2`,key:`mmk7yg`}]]};Ui.node;var Wi=N(Ui),Gi={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`]};Gi.node;var Ki=N(Gi),qi={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`}]]};qi.node;var Ji=N(qi),Yi={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`}]]};Yi.node;var Xi=N(Yi),Zi={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`}]]};Zi.node;var Qi=N(Zi),$i={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`}]]};$i.node;var ea=N($i),ta={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`}]]};ta.node;var na=N(ta),ra={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`]};ra.node;var ia=N(ra),aa={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`]};aa.node;var oa=N(aa),sa={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`]};sa.node;var ca=N(sa),la={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`}]]};la.node;var ua=N(la),da={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`}]]};da.node;var fa=N(da),pa={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`}]]};pa.node;var ma=N(pa),ha={name:`face-slightly-smiling-plus`,size:24,node:[[`path`,{d:`M13.267 2.08a10 10 0 108.653 8.653`,key:`1wbpyh`}],[`path`,{d:`M15 10V9`,key:`4dkmfx`}],[`path`,{d:`M16 5h6`,key:`1vod17`}],[`path`,{d:`M16.472 15a6 6 0 01-8.943 0`,key:`7qomzy`}],[`path`,{d:`M19 2v6`,key:`4bpg5p`}],[`path`,{d:`M9 10V9`,key:`1lazqi`}]],aliases:[`smile-plus`]};ha.node;var ga=N(ha),_a={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`]};_a.node;var va=N(_a),ya={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`}]]};ya.node;var ba=N(ya),xa={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`}]]};xa.node;var Sa=N(xa),Ca={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`}]]};Ca.node;var wa=N(Ca),Ta={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`}]]};Ta.node;var Ea=N(Ta),Da={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`}]]};Da.node;var Oa=N(Da),ka={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`]};ka.node;var Aa=N(ka),ja={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`}]]};ja.node;var Ma=N(ja),Na={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`}]]};Na.node;var Pa=N(Na),Fa={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`}]]};Fa.node;var Ia=N(Fa),La={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`}]]};La.node;var Ra=N(La),za={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`}]]};za.node;var Ba=N(za),Va={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`}]]};Va.node;var Ha=N(Va),Ua={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`}]]};Ua.node;var Wa=N(Ua),Ga={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`}]]};Ga.node;var Ka=N(Ga),qa={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`}]]};qa.node;var Ja=N(qa),Ya={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`}]]};Ya.node;var Xa=N(Ya),Za={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`}]]};Za.node;var Qa=N(Za),$a={name:`loader-circle`,size:24,node:[[`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`,key:`13zald`}]],aliases:[`loader-2`]};$a.node;var eo=N($a),to={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`}]]};to.node;var no=N(to),ro={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`}]]};ro.node;var io=N(ro),ao={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`}]]};ao.node;var oo=N(ao),so={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`}]]};so.node;var co=N(so),lo={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`}]]};lo.node;var uo=N(lo),fo={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`}]]};fo.node;var po=N(fo),mo={name:`menu`,size:24,node:[[`path`,{d:`M4 5h16`,key:`1tepv9`}],[`path`,{d:`M4 12h16`,key:`1lakjw`}],[`path`,{d:`M4 19h16`,key:`1djgab`}]]};mo.node;var ho=N(mo),go={name:`mic-off`,size:24,node:[[`path`,{d:`M12 19v3`,key:`npa21l`}],[`path`,{d:`M15 9.34V5a3 3 0 0 0-5.68-1.33`,key:`1gzdoj`}],[`path`,{d:`M16.95 16.95A7 7 0 0 1 5 12v-2`,key:`cqa7eg`}],[`path`,{d:`M18.89 13.23A7 7 0 0 0 19 12v-2`,key:`16hl24`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M9 9v3a3 3 0 0 0 5.12 2.12`,key:`r2i35w`}]]};go.node;var _o=N(go),vo={name:`mic`,size:24,node:[[`path`,{d:`M12 19v3`,key:`npa21l`}],[`path`,{d:`M19 10v2a7 7 0 0 1-14 0v-2`,key:`1vc78b`}],[`rect`,{x:`9`,y:`2`,width:`6`,height:`13`,rx:`3`,key:`s6n7sd`}]]};vo.node;var yo=N(vo),bo={name:`minus`,size:24,node:[[`path`,{d:`M5 12h14`,key:`1ays0h`}]]};bo.node;var xo=N(bo),So={name:`monitor-up`,size:24,node:[[`path`,{d:`m9 10 3-3 3 3`,key:`11gsxs`}],[`path`,{d:`M12 13V7`,key:`h0r20n`}],[`rect`,{width:`20`,height:`14`,x:`2`,y:`3`,rx:`2`,key:`48i651`}],[`path`,{d:`M12 17v4`,key:`1riwvh`}],[`path`,{d:`M8 21h8`,key:`1ev6f3`}]]};So.node;var Co=N(So),wo={name:`monitor-x`,size:24,node:[[`path`,{d:`m14.5 12.5-5-5`,key:`1jahn5`}],[`path`,{d:`m9.5 12.5 5-5`,key:`1k2t7b`}],[`rect`,{width:`20`,height:`14`,x:`2`,y:`3`,rx:`2`,key:`48i651`}],[`path`,{d:`M12 17v4`,key:`1riwvh`}],[`path`,{d:`M8 21h8`,key:`1ev6f3`}]]};wo.node;var To=N(wo),Eo={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`}]]};Eo.node;var Do=N(Eo),Oo={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`}]]};Oo.node;var ko=N(Oo),Ao={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`}]]};Ao.node;var jo=N(Ao),Mo={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`}]]};Mo.node;var No=N(Mo),Po={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`}]]};Po.node;var Fo=N(Po),Io={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`}]]};Io.node;var Lo=N(Io),Ro={name:`phone-incoming`,size:24,node:[[`path`,{d:`M16 2v6h6`,key:`1mfrl5`}],[`path`,{d:`m22 2-6 6`,key:`6f0sa0`}],[`path`,{d:`M13.832 16.568a1 1 0 0 0 1.213-.303l.355-.465A2 2 0 0 1 17 15h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2A18 18 0 0 1 2 4a2 2 0 0 1 2-2h3a2 2 0 0 1 2 2v3a2 2 0 0 1-.8 1.6l-.468.351a1 1 0 0 0-.292 1.233 14 14 0 0 0 6.392 6.384`,key:`9njp5v`}]]};Ro.node;var zo=N(Ro),Bo={name:`phone-off`,size:24,node:[[`path`,{d:`M10.1 13.9a14 14 0 0 0 3.732 2.668 1 1 0 0 0 1.213-.303l.355-.465A2 2 0 0 1 17 15h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2 18 18 0 0 1-12.728-5.272`,key:`1wngk7`}],[`path`,{d:`M22 2 2 22`,key:`y4kqgn`}],[`path`,{d:`M4.76 13.582A18 18 0 0 1 2 4a2 2 0 0 1 2-2h3a2 2 0 0 1 2 2v3a2 2 0 0 1-.8 1.6l-.468.351a1 1 0 0 0-.292 1.233 14 14 0 0 0 .244.473`,key:`10hv5p`}]]};Bo.node;var Vo=N(Bo),Ho={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`}]]};Ho.node;var Uo=N(Ho),Wo={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`}]]};Wo.node;var Go=N(Wo),Ko={name:`plus`,size:24,node:[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`M12 5v14`,key:`s699le`}]]};Ko.node;var qo=N(Ko),Jo={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`}]]};Jo.node;var Yo=N(Jo),Xo={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`}]]};Xo.node;var Zo=N(Xo),Qo={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`}]]};Qo.node;var $o=N(Qo),es={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`}]]};es.node;var ts=N(es),ns={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`}]]};ns.node;var rs=N(ns),is={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`}]]};is.node;var as=N(is),os={name:`search`,size:24,node:[[`path`,{d:`m21 21-4.34-4.34`,key:`14j7rj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}]]};os.node;var ss=N(os),cs={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`]};cs.node;var ls=N(cs),us={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`}]]};us.node;var ds=N(us),fs={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`}]]};fs.node;var ps=N(fs),ms={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`}]]};ms.node;var hs=N(ms),gs={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`}]]};gs.node;var _s=N(gs),vs={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`}]]};vs.node;var ys=N(vs),bs={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`}]]};bs.node;var xs=N(bs),Ss={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`}]]};Ss.node;var Cs=N(Ss),ws={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`}]]};ws.node;var Ts=N(ws),Es={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`]};Es.node;var Ds=N(Es),Os={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`]};Os.node;var ks=N(Os),As={name:`square`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]};As.node;var js=N(As),Ms={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`}]]};Ms.node;var Ns=N(Ms),Ps={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`}]]};Ps.node;var Fs=N(Ps),Is={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`}]]};Is.node;var Ls=N(Is),Rs={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`}]]};Rs.node;var zs=N(Rs),Bs={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`}]]};Bs.node;var Vs=N(Bs),Hs={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`}]]};Hs.node;var Us=N(Hs),Ws={name:`terminal`,size:24,node:[[`path`,{d:`M12 19h8`,key:`baeox8`}],[`path`,{d:`m4 17 6-6-6-6`,key:`1yngyt`}]]};Ws.node;var Gs=N(Ws),Ks={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`]};Ks.node;var qs=N(Ks),Js={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`]};Js.node;var Ys=N(Js),Xs={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`}]]};Xs.node;var Zs=N(Xs),Qs={name:`user-plus`,size:24,node:[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}],[`line`,{x1:`19`,x2:`19`,y1:`8`,y2:`14`,key:`1bvyxn`}],[`line`,{x1:`22`,x2:`16`,y1:`11`,y2:`11`,key:`1shjgl`}]]};Qs.node;var $s=N(Qs),ec={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`]};ec.node;var tc=N(ec),nc={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`]};nc.node;var rc=N(nc),ic={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`}]]};ic.node;var ac=N(ic),oc={name:`video-off`,size:24,node:[[`path`,{d:`M10.66 6H14a2 2 0 0 1 2 2v2.5l5.248-3.062A.5.5 0 0 1 22 7.87v8.196`,key:`w8jjjt`}],[`path`,{d:`M16 16a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h2`,key:`1xawa7`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]};oc.node;var sc=N(oc),cc={name:`video`,size:24,node:[[`path`,{d:`m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5`,key:`ftymec`}],[`rect`,{x:`2`,y:`6`,width:`14`,height:`12`,rx:`2`,key:`158x01`}]]};cc.node;var lc=N(cc),uc={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`}]]};uc.node;var dc=N(uc),fc={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`}]]};fc.node;var pc=N(fc),mc={name:`wifi-off`,size:24,node:[[`path`,{d:`M12 20h.01`,key:`zekei9`}],[`path`,{d:`M8.5 16.429a5 5 0 0 1 7 0`,key:`1bycff`}],[`path`,{d:`M5 12.859a10 10 0 0 1 5.17-2.69`,key:`1dl1wf`}],[`path`,{d:`M19 12.859a10 10 0 0 0-2.007-1.523`,key:`4k23kn`}],[`path`,{d:`M2 8.82a15 15 0 0 1 4.177-2.643`,key:`1grhjp`}],[`path`,{d:`M22 8.82a15 15 0 0 0-11.288-3.764`,key:`z3jwby`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]};mc.node;var hc=N(mc),gc={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`}]]};gc.node;var _c=N(gc),vc={name:`x`,size:24,node:[[`path`,{d:`M18 6 6 18`,key:`1bl5f8`}],[`path`,{d:`m6 6 12 12`,key:`d8bk6v`}]]};vc.node;var yc=N(vc),bc={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`}]]};bc.node;var xc=N(bc),I=e(t(),1),Sc=e(n(),1),L=M(`account`),Cc=`/-/account`,wc=`/-/sign-in-policy`,Tc=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}},Ec=e=>e?`${Cc}/${encodeURIComponent(e)}`:Cc,Dc=(e,t,n)=>[{id:`account`,label:L(`account`),icon:rc,href:`${e}${Cc}`,active:Tc(t)!==void 0},...n?[{id:`sign-in-policy`,label:L(`signInPolicy`),icon:_s,href:`${e}${wc}`,active:t===wc}]:[]],Oc=[`always`,`editing`,`reading`],kc=e=>e!==void 0&&!Oc.includes(e),Ac={list:`list`,filter:`filter`,orderBy:`order_by`,display:`display`,filterLayout:`layout`,map:`map`,calendar:`calendar`,timeline:`timeline`,savedSearch:`saved_search`,create:`new`,edit:`edit`,open:`open`,tab:`tab`,standard:`standard`,call:`call`},jc=[`list`,`display`,`filter`,`orderBy`,`filterLayout`,`savedSearch`],Mc=e=>`${e.latitude.toFixed(5)},${e.longitude.toFixed(5)},${e.zoom.toFixed(2)}`,Nc=(e,t,n=-t)=>Number.isFinite(e)&&e>=n&&e<=t,Pc=e=>{let t=e?.split(`,`);if(t?.length!==3||t.some(e=>e.trim()===``))return;let[n,r,i]=t.map(Number);return Nc(n,90)&&Nc(r,180)&&Nc(i,22,0)?{latitude:n,longitude:r,zoom:i}:void 0},Fc=e=>`${e.scale},${e.day}`,Ic=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},Lc=(e,t)=>{let n=e?.split(`,`);if(n?.length!==2)return;let[r,i]=n;return t.includes(r)&&Ic(i)?{scale:r,day:i}:void 0},Rc=e=>{let t=new URLSearchParams;for(let n of jc){let r=e[n];r===void 0||r===``&&n!==`filter`||t.set(Ac[n],r)}e.map&&t.set(Ac.map,Mc(e.map)),e.calendar&&t.set(Ac.calendar,Fc(e.calendar)),e.timeline&&t.set(Ac.timeline,Fc(e.timeline));let n=t.toString();return n?`?${n}`:``},zc=e=>{let t=new URLSearchParams;e.edit&&t.set(Ac.edit,`true`);for(let n of e.open??[])t.append(Ac.open,n);e.tab&&t.set(Ac.tab,e.tab),e.standard&&t.set(Ac.standard,`true`),e.call&&t.set(Ac.call,e.call);let n=t.toString();return n?`?${n}`:``},Bc=(e,t=``)=>{switch(e.kind){case`page`:return`${t}/${encodeURIComponent(e.page)}${e.tab?`/${encodeURIComponent(e.tab)}`:``}`;case`create`:return`${t}/${encodeURIComponent(e.resource)}/${Ac.create}${Hc(e.values)}`;case`record`:return`${t}/${encodeURIComponent(e.resource)}/${encodeURIComponent(Nn(e.key))}${zc(e)}`;case`list`:return`${t}/${encodeURIComponent(e.resource)}${Rc(e)}`}},Vc=e=>{try{return e.split(`/`).filter(Boolean).map(decodeURIComponent)}catch(e){if(e instanceof URIError)return;throw e}},Hc=(e={})=>{let t=new URLSearchParams(Object.entries(e).filter(([,e])=>e!==``)).toString();return t?`?${t}`:``},Uc=e=>e===`bar`||e===`panel`?e:void 0,Wc=(e,t)=>{let n=new URL(e,`http://app`),r=Vc(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===Ac.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(Ac.open).filter(e=>e!==``))],t=n.searchParams.get(Ac.tab)||void 0,r=n.searchParams.get(Ac.standard)===`true`,o=n.searchParams.get(Ac.call)===`join`;return{kind:`record`,resource:i,key:a,...n.searchParams.get(Ac.edit)===`true`&&{edit:!0},...e.length>0&&{open:e},...t&&{tab:t},...r&&{standard:r},...o&&{call:`join`}}}let o=n.searchParams,s=o.get(Ac.list)||void 0,c=o.get(Ac.display)||void 0,l=o.get(Ac.filter)??void 0,u=o.get(Ac.orderBy)||void 0,d=Uc(o.get(Ac.filterLayout)),f=Pc(o.get(Ac.map)),p=Lc(o.get(Ac.calendar),[`month`,`week`]),m=Lc(o.get(Ac.timeline),[`week`,`month`,`quarter`]),h=o.get(Ac.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}}},Gc={signature:`sig`},Kc=e=>{let t=e.startsWith(`?`)?e.slice(1):e;return new URLSearchParams(t).has(Gc.signature)?{oauthQuery:t}:{}},qc=`/-/sign-in`,Jc={step:`step`,next:`next`},Yc=[`sign-in`,`forgot-password`,`email-code`,`sign-up`,`sign-up-code`,`sign-up-details`],Xc=e=>Yc.includes(e),Zc=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}`},Qc=({step:e=`sign-in`,next:t}={})=>{let n=new URLSearchParams;e!==`sign-in`&&n.set(Jc.step,e);let r=Zc(t);r&&r!==`/`&&n.set(Jc.next,r);let i=n.toString();return i?`${qc}?${i}`:qc},$c=(e,t)=>{if(e!==`/-/sign-in`)return;let n=t.get(Jc.step),r=Zc(t.get(Jc.next));return{step:Xc(n)?n:`sign-in`,...r&&{next:r}}},el=e=>typeof e==`string`?e:e&&Yt(e),tl=e=>{let t=Object.entries(e??{}).map(([e,t])=>`${e}.${t}`);return t.length>0?t:void 0},nl=e=>({photos:e&&`${e.resource}.${e.field}.${e.image}`,photos_order_by:e?.sort}),rl=(e={})=>({filter:el(e.filter)||void 0,order_by:e.orderBy,page_size:e.pageSize,page_token:e.pageToken||void 0,fields:e.fields?.join(`,`),labels:tl(e.labels)?.join(`,`),...nl(e.photos),count:e.count}),il=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}`:``},al=e=>e.startsWith(`/`)&&!e.startsWith(`//`),ol=e=>{if(typeof e!=`object`||!e)return!1;let{uri:t,url:n}=e;return typeof t==`string`&&typeof n==`string`&&al(n)},sl=e=>e!==void 0&&URL.canParse(e)?new URL(e).origin:void 0,cl=(e,t)=>({...e,url:`${t}${e.url}`,...e.variants&&{variants:Object.fromEntries(Object.entries(e.variants).map(([e,n])=>[e,al(n.url)?{...n,url:`${t}${n.url}`}:n]))}}),ll=(e,t)=>t===void 0||typeof e!=`object`||!e?e:Object.fromEntries(Object.entries(e).map(([e,n])=>[e,ol(n)?cl(n,t):n])),ul=(e,t)=>t===void 0?e:Object.fromEntries(Object.entries(e).map(([e,n])=>[e,n.map(e=>ol(e)?cl(e,t):e)])),dl=class extends Error{problem;constructor(e){super(e.detail??e.title),this.problem=e,this.name=`ApiError`}get status(){return this.problem.status}get slug(){return this.problem.type.split(`:`).at(-1)??``}get operation(){return this.problem.operation??this.errors.find(e=>e.operation!==void 0)?.operation}get blockedBy(){return this.problem.blockedBy}get existing(){return this.problem.existing}get errors(){return this.problem.errors??[]}get filterErrors(){return this.slug===`invalid-filter`?this.errors:[]}},fl=class extends dl{constructor(e){super(e),this.name=`PreconditionFailedError`}},pl=e=>e instanceof dl,ml=e=>typeof e==`object`&&!!e&&`type`in e&&`status`in e,hl=async e=>{let t=e.headers.get(`content-type`)?.includes(`json`)??!1?await e.json():void 0,n=ml(t)?t:{type:`urn:protobase:problem:unknown`,title:e.statusText||`Request failed`,status:e.status};return n.status===412?new fl(n):new dl(n)},gl=(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 hl(h);return h}},_l=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()]})),vl=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:_l(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)}),yl=e=>Math.min(3e4,1e3*2**e),bl=(e,t)=>new Promise(n=>{let r=setTimeout(n,e);t.addEventListener(`abort`,()=>{clearTimeout(r),n()},{once:!0})}),xl=(e,t,n=yl)=>{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:il({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 nr(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 bl(n(o++),i)}})(),()=>r.abort()},Sl=e=>{let t=new Set,n,r=e=>{for(let n of[...t])e(n)};return i=>{let a={...i};return t.add(a),n??=e({onChanges:e=>r(t=>t.onChanges(e)),onResync:()=>r(e=>e.onResync()),onRetry:e=>r(t=>t.onRetry?.(e))}),()=>{!t.delete(a)||t.size>0||(n?.(),n=void 0)}}},Cl=new TextEncoder,wl=new TextDecoder,Tl=4,El=(e,t)=>{let n=Cl.encode(JSON.stringify(e)),r=t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength),i=new Uint8Array(Tl+n.length+r.length);return new DataView(i.buffer).setUint32(0,n.length),i.set(n,Tl),i.set(r,Tl+n.length),i.buffer},Dl=e=>{let t=Tl+new DataView(e).getUint32(0);return{...JSON.parse(wl.decode(new Uint8Array(e,Tl,t-Tl))),payload:e.slice(t)}},Ol=e=>e instanceof ArrayBuffer||ArrayBuffer.isView(e),kl=class extends Error{code;constructor(e,t){super(t),this.code=e,this.name=`ChannelRefusal`}},Al=5e3,jl=1,Ml=`protobase.channels`,Nl=({url:e,token:t,socket:n,retryDelay:r,onOpen:i,onDown:a,onMessage:o})=>{let s,c=!1,l=0,u=0,d,f=0,p,m,h=new Map,g=()=>{for(let{reject:e}of h.values())e(new kl(`disconnected`,`The connection dropped before the server answered`));h.clear()},_=async e=>{let n=await t?.();s===e&&e.readyState===jl&&n!==void 0&&n!==d&&(d=n,e.send(JSON.stringify({type:`token`,token:n})))},v=async()=>{let u=await t?.();if(!c||s)return;d=u;let y=n(e(),u===void 0?[Ml]:[Ml,`bearer.${u}`]);s=y,y.binaryType=`arraybuffer`,y.onopen=()=>{l=0,f=Date.now(),p=setInterval(()=>{if(Date.now()-f>1e4)return y.close();y.send(JSON.stringify({type:`ping`})),_(y)},Al),i()},y.onmessage=({data:e})=>{if(f=Date.now(),typeof e!=`string`&&!(e instanceof ArrayBuffer))return;let t=typeof e==`string`?JSON.parse(e):Dl(e);if(t.type!==`reply`)return o(t);let n=h.get(t.ref);h.delete(t.ref),t.ok?n?.resolve(t):n?.reject(new kl(t.error.code,t.error.message))},y.onclose=()=>{s===y&&(clearInterval(p),s=void 0,g(),c&&(a(),m=setTimeout(()=>{m=void 0,v()},r(l++))))}},y=(e,t)=>s?.readyState===jl&&(s.send(t===void 0?JSON.stringify(e):El(e,t)),!0);return{start:()=>{c=!0,!s&&m===void 0&&v()},stop:()=>{c=!1,clearTimeout(m),m=void 0,clearInterval(p);let e=s;s=void 0,g(),e?.close(1e3)},request:(e,t)=>new Promise((n,r)=>{let i=String(++u);if(!y({...e,ref:i},t))return r(new kl(`disconnected`,`The connection is down`));h.set(i,{resolve:n,reject:r})}),post:y}},Pl=e=>{if(!(e instanceof kl&&e.code===`disconnected`))throw e},Fl=()=>new kl(`not-joined`,`The channel is not joined yet`),Il=e=>{let t=new Map,n=new Map,r=(e,t)=>{e.status=t;for(let n of e.statusListeners)n(t)},i=(e,t)=>{let n=[...e.presence.values()];for(let r of e.presenceListeners)r(n,t)},a=e=>{t.delete(e),t.size===0&&c.stop()},o=e=>{let i=`${e.resource}/${e.key}`;c.request({type:`join`,resource:e.resource,key:e.key}).then(o=>{if(t.get(i)===e){if(e.holders===0)return c.post({type:`leave`,channel:o.channel}),a(i);e.name=o.channel,n.set(e.name,e),r(e,{state:`joined`}),e.tracked&&c.request({type:`track`,channel:e.name,state:e.tracked.state}).catch(Pl)}}).catch(n=>{if(t.get(i)===e&&e.holders===0&&n instanceof kl)return a(i);if(!(n instanceof kl)||n.code===`disconnected`)return Pl(n);r(e,{state:`refused`,error:{code:n.code,message:n.message}})})},s=e=>{if(e.type===`pong`||e.type===`reply`||e.type===`error`)return;let t=n.get(e.channel);if(t){if(e.type===`presence`)return t.presence=new Map(e.entries.map(e=>[e.id,e])),i(t);if(e.type===`presence_diff`){for(let n of e.leaves)t.presence.delete(n.id);for(let n of[...e.joins,...e.updates])t.presence.set(n.id,n);return i(t,{joins:e.joins,updates:e.updates,leaves:e.leaves})}if(e.type===`broadcast`){let{event:n,payload:r,user:i,server:a}=e;for(let e of t.eventListeners.get(n)??[])e({event:n,payload:r,user:i,...a&&{server:a}});return}n.delete(e.channel),t.presence.clear(),i(t),r(t,{state:`closed`,error:e.error})}},c=Nl({...e,onOpen:()=>{for(let[e,n]of t)n.status.state===`joining`&&(n.holders===0?a(e):o(n))},onDown:()=>{n.clear();for(let e of t.values())e.status.state===`joined`&&r(e,{state:`joining`})},onMessage:s}),l=(e,t)=>{--t.holders,!(t.holders>0)&&(t.tracked=void 0,t.status.state!==`joining`&&(t.name!==void 0&&(n.delete(t.name),c.post({type:`leave`,channel:t.name})),a(e)))},u=(e,t)=>{let n=!1,r=new Set,i=(e,t)=>{e.add(t);let n=()=>{e.delete(t),r.delete(n)};return r.add(n),n},a=()=>t.status.state===`joined`?t.name:void 0;return{status:()=>t.status,onStatus:e=>i(t.statusListeners,e),presence:()=>[...t.presence.values()],onPresence:e=>i(t.presenceListeners,e),track:async e=>{t.tracked={state:e};let n=a();n!==void 0&&await c.request({type:`track`,channel:n,state:e})},untrack:async()=>{t.tracked=void 0;let e=a();e!==void 0&&await c.request({type:`untrack`,channel:e})},send:async(e,t,{self:n,ack:r}={})=>{let i=a();if(i===void 0)throw Fl();let o=Ol(t)?t:void 0,s={type:`send`,channel:i,event:e,...o===void 0&&{payload:t},...n&&{self:n}};if(r){await c.request({...s,ack:r},o);return}if(!c.post(s,o))throw new kl(`disconnected`,`The connection is down`)},on:(e,n)=>{let r=t.eventListeners.get(e)??new Set;return t.eventListeners.set(e,r),i(r,n)},leave:()=>{if(!n){n=!0;for(let e of[...r])e();l(e,t)}}}};return{channel:(e,n)=>{let r=Nn(n),i=`${e}/${r}`,a=t.get(i);if(a)return a.holders+=1,u(i,a);let s={resource:e,key:r,status:{state:`joining`},presence:new Map,holders:1,statusListeners:new Set,presenceListeners:new Set,eventListeners:new Map};return t.set(i,s),c.start(),o(s),u(i,s)}}},Ll=e=>({register:async t=>(await e({method:`POST`,path:vr(``),system:!0,body:t})).json(),remove:async t=>{await e({method:`DELETE`,path:vr(``,t),system:!0})}}),Rl=e=>({own:async()=>(await(await e({method:`GET`,path:xr(``),system:!0})).json()).status,set:async t=>(await(await e({method:`PUT`,path:xr(``),system:!0,body:t})).json()).status,clear:async()=>{await e({method:`DELETE`,path:xr(``),system:!0})},people:async()=>(await(await e({method:`GET`,path:xr(``,`people`),system:!0})).json()).statuses}),zl=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:br(``),query:i,system:!0})).json()},unread:async()=>(await(await e({method:`GET`,path:br(``,`unread`),system:!0})).json()).count,markRead:async t=>{await e({method:`POST`,path:br(``,{read:t}),body:{},system:!0})},markAllRead:async t=>{await e({method:`POST`,path:br(``,`read`),body:{upTo:t},system:!0})}}),Bl=e=>Math.min(3e4,1e3*2**e),Vl=(e,t)=>new Promise(n=>{let r=setTimeout(n,e);t.addEventListener(`abort`,()=>{clearTimeout(r),n()},{once:!0})}),Hl=(e,t,n=Bl)=>({calls:async(n,r)=>(await(await e({method:`GET`,path:t(n,r)})).json()).items,watchCalls:(r,i,a)=>{let o=new AbortController,{signal:s}=o,c=0,l=async()=>{let n=await e({method:`GET`,path:t(r,i),query:`?watch=true`,headers:{accept:`text/event-stream`},signal:s});if(!n.body)throw Error(`The server answered the calls stream without a body`);await nr(n.body,e=>{c=0,a.onCalls(JSON.parse(e).items)},s)};return(async()=>{for(;!s.aborted;){let e=await l().then(()=>void 0,e=>e);if(s.aborted)return;a.onRetry?.(e),await Vl(n(c++),s)}})(),()=>o.abort()}}),Ul=e=>({list:async()=>(await(await e({method:`GET`,path:kr(``),system:!0})).json()).items,decline:async t=>{await e({method:`POST`,path:kr(``,{decline:t}),system:!0,body:{}})}}),Wl=e=>({allowed:async()=>(await(await e({method:`GET`,path:Dr(``,`organization`),system:!0})).json()).allowed,setAllowed:async t=>{await e({method:`PUT`,path:Dr(``,`organization`),system:!0,body:{allowed:t}})}}),Gl=e=>typeof e==`string`?e:e.toModel().name,Kl=(e=`/api/v1`)=>{let t=new URL(`${e.replace(/\/[^/]*$/,``)}/channels`,globalThis.location?.href);return t.protocol=t.protocol===`https:`?`wss:`:`ws:`,t.toString()},ql=(e,t)=>`/${Gl(e)}/${Nn(t)}`,Jl=(e,t)=>`${ql(e,t)}:calls`,Yl=(e,t,n)=>({items:e.items.map(e=>ll(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:ul(e.photos,n)},...t.headers.get(`x-protobase-warning`)&&{warning:t.headers.get(`x-protobase-warning`)}}),Xl=({created_at:e,...t})=>({...t,createdAt:e}),Zl=e=>e.headers.get(`etag`)??``,Ql=async(e,t)=>{let{permissions:n,...r}=await e.json();return{record:ll(r,t),etag:Zl(e),...n&&{permissions:n}}},$l=(e,t)=>({results:(e.results??[]).map(e=>e.op===`create`||e.op===`update`?{...e,record:ll(e.record,t)}:e.op===`reorder`?{...e,records:e.records.map(e=>({...e,record:ll(e.record,t)}))}:e)}),eu=(e={})=>{let t=gl(e),n=sl(e.baseUrl),r=async(e,r)=>{let i=await t({method:`GET`,path:`/${Gl(e)}`,query:il(rl(r))});return Yl(await i.json(),i,n)},i=async(e,r)=>{let i=rl(r),a=await t({method:`POST`,path:`/${Gl(e)}:search`,body:{...i,fields:r?.fields,labels:tl(r?.labels)}});return Yl(await a.json(),a,n)},a=async(e,r)=>Ql(await t({method:`GET`,path:ql(e,r)}),n),o=async(e,r)=>{let i=await t({method:`POST`,path:`/${Gl(e)}`,body:r});return{record:ll(await i.json(),n),etag:Zl(i),location:i.headers.get(`location`)??``}},s=async(e,r,i,a)=>Ql(await t({method:`PATCH`,path:ql(e,r),body:i,headers:{"if-match":a}}),n),c=async(e,n,{etag:r}={})=>{await t({method:`DELETE`,path:ql(e,n),headers:r?{"if-match":r}:void 0})},l=async(e,r)=>{let i=await t({method:`POST`,path:`${ql(e,r)}:undelete`});return{record:ll(await i.json(),n),etag:Zl(i)}},u=async(e,n,r)=>(await(await t({method:`POST`,path:`${ql(e,n)}:reveal`,body:{field:r}})).json()).value,d=async(e,r,i)=>Ql(await t({method:`POST`,path:`${ql(e,r)}:generate`,body:{action:i}}),n),f=async(e,n,{pageSize:r,pageToken:i}={})=>{let a=il({page_size:r,page_token:i||void 0}),o=await(await t({method:`GET`,path:`${ql(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=il({page_size:r,page_token:i||void 0}),o=await(await t({method:`GET`,path:`${ql(e,n)}:comments`,query:a})).json();return{items:o.items.map(Xl),nextPageToken:o.next_page_token}},m=async(e,n,{body:r,mentions:i=[]})=>Xl(await(await t({method:`POST`,path:`${ql(e,n)}:comments`,body:{body:r,mentions:i}})).json()),h=async(e,n,r)=>(await(await t({method:`GET`,path:`${ql(e,n)}:mentionable`,query:il({q:r})})).json()).items,g=async e=>{let r=e=>typeof e==`object`&&e&&`$ref`in e?e:Nn(e),i=e.map(e=>({...e,resource:Gl(e.resource),...`key`in e&&{key:r(e.key)},...e.op===`reorder`&&{keys:e.keys.map(r)}}));return $l(await(await t({method:`POST`,path:`:batchWrite`,body:{ops:i}})).json(),n)},_=async(e,n,r={})=>(await(await t({method:`GET`,path:`/${Gl(e)}:facets`,query:il({field:n,filter:el(r.filter)||void 0,limit:r.limit,label:r.label})})).json()).facets,v=async(e,n)=>{let r=await(await t({method:`GET`,path:`/${Gl(e)}:aggregate`,query:il({group_by:n.groupBy,filter:el(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:`/${Gl(e)}:series`,query:il({field:n.field,range:n.range,from:n.from,to:n.to,granularity:n.granularity,time_zone:n.timeZone,filter:el(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:`/${Gl(e)}:histogram`,query:il({field:n,buckets:r.buckets,filter:el(r.filter)||void 0})})).json(),x=async(e,r)=>{let i=await(await t({method:`GET`,path:`/${Gl(e)}:map`,query:il({latitude:r.latitude,longitude:r.longitude,zoom:r.zoom,filter:el(r.filter)||void 0,order_by:r.orderBy,fields:r.fields?.join(`,`),labels:tl(r.labels)?.join(`,`),...nl(r.photos)})})).json();return{items:i.items.map(e=>ll(e,n)),buckets:i.buckets,totalSize:i.total_size,...i.labels!==void 0&&{labels:i.labels},...i.photos!==void 0&&{photos:ul(i.photos,n)}}},S=async(e,r)=>{let i=await t({method:`GET`,path:`/${Gl(e)}:seek`,query:il({...rl(r),position:r.position})});return Yl(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:Zl(r)}},w=async(e,{method:n,body:r,path:i=``,query:a,headers:o}={})=>{let s=await t({method:n??(r===void 0?`GET`:`POST`),path:`/functions/${encodeURIComponent(e)}${i}`,query:a?`?${new URLSearchParams(a)}`:``,body:r,headers:o,system:!0});if(s.status===204)return;let c=s.headers.get(`content-type`);return c?.includes(`json`)?s.json():!c||c.startsWith(`text/`)?s.text():s.blob()},T=async(e,n,r,{onProgress:i,signal:a}={})=>{let o=`name`in r&&typeof r.name==`string`?r.name:void 0,s=i&&typeof XMLHttpRequest<`u`?vl(i):void 0,c=await(await t({method:`POST`,path:`/${Gl(e)}:upload`,query:`?${new URLSearchParams({field:n,...o!==void 0&&{name:o}})}`,raw:r,headers:{"content-type":r.type||`application/octet-stream`},...s&&{via:s},...a&&{signal:a}})).json();return i?.(r.size,r.size),c},E=e=>`/forms/${encodeURIComponent(e)}`,D=async e=>(await t({method:`GET`,path:E(e),system:!0})).json(),O=async e=>(await t({method:`GET`,path:`${E(e)}:challenge`,system:!0})).json(),k=async(e,n,r)=>{await t({method:`POST`,path:E(e),body:{values:n,proof:r},system:!0})},A=Sl(e=>xl(t,e)),{channel:j}=Il({url:()=>Kl(e.baseUrl),...e.token&&{token:()=>e.token({refresh:!1})},socket:e.webSocket??((e,t)=>new WebSocket(e,t)),retryDelay:e=>Math.min(3e4,1e3*2**e)}),ee=Ll(t),te=zl(t),{calls:ne,watchCalls:re}=Hl(t,Jl);return{list:r,search:i,get:a,create:o,update:s,remove:c,undelete:l,generate:d,reveal:u,history:f,comments:p,comment:m,mentionable:h,batchWrite:g,facets:_,aggregate:v,series:y,histogram:b,map:x,seek:S,meta:C,invoke:w,upload:T,form:D,formChallenge:O,submitForm:k,live:A,channel:j,devices:ee,notifications:te,status:Rl(t),calls:ne,watchCalls:re,rings:Ul(t),callGuests:Wl(t)}},tu=e=>typeof e==`string`?e:e.toModel().name,nu=(e,t)=>{let n=n=>t(tu(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=>tu(e.resource)))].join(`, `)}, which different APIs serve`)):(r[0]??e).batchWrite(t)},facets:(e,t,r)=>n(e).facets(e,t,r),aggregate:(e,t)=>n(e).aggregate(e,t),series:(e,t)=>n(e).series(e,t),histogram:(e,t,r)=>n(e).histogram(e,t,r),map:(e,t)=>n(e).map(e,t),seek:(e,t)=>n(e).seek(e,t),meta:(t,n)=>e.meta(t,n),invoke:(t,n)=>e.invoke(t,n),upload:(e,t,r,i)=>n(e).upload(e,t,r,i),form:t=>e.form(t),formChallenge:t=>e.formChallenge(t),submitForm:(t,n,r)=>e.submitForm(t,n,r),live:t=>e.live(t),channel:(t,n)=>e.channel(t,n),devices:e.devices,notifications:e.notifications,status:e.status,rings:e.rings,callGuests:e.callGuests,calls:(e,t)=>n(e).calls(e,t),watchCalls:(e,t,r)=>n(e).watchCalls(e,t,r)}},ru=e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&typeof e.type==`string`&&Array.isArray(e.children),iu={record:!1},au=e=>({resource:typeof e.props.resource==`string`?e.props.resource:void 0,record:!0}),ou=(e,t)=>!e.custom&&(e.type===`RecordCard`||e.type===`CardRow`)?au(e):t,su=(e,t)=>!e.custom&&e.type===`RecordCard`?au(e):t,cu=e=>`<${e.type}${typeof e.props.resource==`string`?` resource="${e.props.resource}"`:``}${typeof e.props.name==`string`?` name="${e.props.name}"`:``}>`,lu=e=>ru(e)||Array.isArray(e)&&e.length>0&&e.every(ru),uu=(e,t,n={path:cu(e),scope:iu})=>{let r=ou(e,n.scope),i=su(e,n.scope),a=e.children.flatMap(e=>{if(typeof e==`string`)return[e];let i=uu(e,t,{path:`${n.path} › ${cu(e)}`,scope:r});return i?[i]:[]}),o=Object.fromEntries(Object.entries(e.props).flatMap(([e,r])=>{if(!lu(r))return[[e,r]];let a=(Array.isArray(r)?r:[r]).flatMap(r=>uu(r,t,{path:`${n.path} ${e}={${cu(r)}}`,scope:i})??[]);return a.length===0?[]:[[e,Array.isArray(r)?a:a[0]]]}));return t({...e,props:o,children:a},n)},du=e=>typeof e==`object`&&!!e&&e.kind===`member`,fu=e=>du(e)?[e.path.join(`.`)]:typeof e!=`object`||!e?[]:Object.values(e).flatMap(fu),pu=e=>du(e)?{...e,path:[e.path.join(`.`)]}:Array.isArray(e)?e.map(pu):typeof e!=`object`||!e?e:Object.fromEntries(Object.entries(e).map(([e,t])=>[e,pu(t)])),mu=e=>{let t=ie(e);return t.ok?t.ast?{ok:!0,ast:t.ast,paths:[...new Set(fu(t.ast))]}:{ok:!1,message:`the condition is empty`}:{ok:!1,message:t.errors.map(e=>e.message).join(`; `)}},hu=(e,t)=>e.ast!==void 0&&Ee(pu(e.ast),t),gu=(e,t)=>{let[n,r,...i]=e.split(`.`);return n&&r===`count`&&i.length===0&&!t(n)?n:void 0},_u=({layout:e,cardWidth:t})=>({layout:e??`stack`,cardWidth:t??`2/3`}),vu=(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}},yu=(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]}))}),bu=(e,t)=>{if(e.kind===`group`){let n=e.items.flatMap(e=>bu(e,t));return n.length>0?[{...e,items:n}]:[]}if(e.kind===`tab`){let n=e.items.flatMap(e=>bu(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=>vu(t,e.resource,n).ok);return[i&&i.length>0?{...r,columns:i}:r]},xu=(e,t,n)=>e.run?.kind!==`link`||!(`to`in e.run)||Zn(e.run.to,{models:n,pages:new Set,source:t}).length===0,Su=(e,t)=>({...e,layout:e.layout.flatMap(e=>bu(e,t)),actions:e.actions.filter(n=>xu(n,t[e.resource],t))}),Cu=(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=>yu(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=>Su(e,a)),permissions:Object.fromEntries(n.flatMap(t=>e.permissions?.[t.name]?[[t.name,e.permissions[t.name]]]:[]))}},wu=class extends Error{status;code;constructor(e,t,n){super(e),this.status=t,this.code=n,this.name=`AuthError`}},R=(e,t)=>new wu(e?.message||t,e?.status??500,e?.code),Tu=e=>new Date(e).toISOString(),Eu=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:Tu(e.createdAt),updatedAt:Tu(e.updatedAt),expiresAt:Tu(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`)}}),Du=e=>({signInMethods:async()=>{let{data:t,error:n}=await e.$fetch(`/account/sign-in-methods`);if(n||!t)throw R(n,`Could not read your sign-in methods`);return t},passkeys:async()=>{let{data:t,error:n}=await e.passkey.listUserPasskeys();if(n||!t)throw R(n,`Could not read your passkeys`);return t.map(e=>({id:e.id,backedUp:e.backedUp,...e.name&&{name:e.name},...e.createdAt&&{createdAt:new Date(e.createdAt).toISOString()}}))},addPasskey:async t=>{let{error:n}=await e.passkey.addPasskey(t?{name:t}:{});if(n)throw R(n,`Could not add the passkey`)},renamePasskey:async(t,n)=>{let{error:r}=await e.passkey.updatePasskey({id:t,name:n});if(r)throw R(r,`Could not rename the passkey`)},removePasskey:async t=>{let{error:n}=await e.passkey.deletePasskey({id:t});if(n)throw R(n,`Could not remove the passkey`)},startAuthenticatorApp:async t=>{let{data:n,error:r}=await e.twoFactor.enable({method:`totp`,...t&&{password:t}});if(r||n?.method!==`totp`)throw R(r,`Could not start two-factor authentication`);return{totpURI:n.totpURI,backupCodes:n.backupCodes}},confirmAuthenticatorApp:async t=>{let{error:n}=await e.twoFactor.verifyTotp({code:t});if(n)throw R(n,`The code did not work`)},turnOnEmailedCodes:async t=>{let{error:n}=await e.twoFactor.enable({method:`otp`,...t&&{password:t}});if(n)throw R(n,`Could not turn on two-factor authentication`)},turnOffTwoFactor:async t=>{let{error:n}=await e.twoFactor.disable(t?{password:t}:{});if(n)throw R(n,`Could not turn off two-factor authentication`)},linkedProviders:async()=>{let{data:t,error:n}=await e.listAccounts();if(n||!t)throw R(n,`Could not read your linked accounts`);return[...new Set(t.map(e=>e.providerId).filter(e=>e!==`credential`))]},linkProvider:async(t,n)=>{let{data:r,error:i}=await e.linkSocial({provider:t,callbackURL:n,errorCallbackURL:n,disableRedirect:!0});if(i||!r?.url)throw R(i,`Could not start linking the account`);return r.url},linkedPersonalMail:async t=>{let{data:n,error:r}=await e.listAccounts();if(r||!n)throw R(r,`Could not read your linked accounts`);return t.filter(e=>n.some(t=>t.providerId===e.provider&&e.scopes.every(e=>t.scopes.includes(e)))).map(e=>e.id)},linkPersonalMail:async(t,n)=>{let{data:r,error:i}=await e.linkSocial({provider:t.provider,scopes:t.scopes,additionalParams:t.params,callbackURL:n,errorCallbackURL:n,disableRedirect:!0});if(i||!r?.url)throw R(i,`Could not start linking the mailbox`);return r.url},connectedApps:async()=>{let{data:t,error:n}=await e.$fetch(`/account/connected-apps`);if(n||!t)throw R(n,`Could not read your connected apps`);return t.apps},disconnectApp:async t=>{let{error:n}=await e.$fetch(`/account/connected-apps/disconnect`,{method:`POST`,body:{clientId:t}});if(n)throw R(n,`Could not disconnect the app`)},newBackupCodes:async t=>{let{data:n,error:r}=await e.twoFactor.generateBackupCodes(t?{password:t}:{});if(r||!n)throw R(r,`Could not make new backup codes`);return n.backupCodes}}),Ou=(e,t)=>new wu(e?.message||e?.error_description||t,e?.status??500,e?.code??e?.error),ku=e=>({client:async t=>{let{data:n,error:r}=await e.$fetch(`/oauth2/public-client`,{query:{client_id:t}});if(r||!n)throw Ou(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 Ou(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 Ou(i,`Could not answer the request`);return{url:r.url}}}),Au=(e,t,n)=>x({baseURL:e,basePath:t,plugins:[k(),O(),m(),A()],disableDefaultFetchPlugins:!0,fetchOptions:{customFetchImpl:n}}),ju=e=>Array.isArray(e)?e.filter(e=>typeof e==`string`):typeof e==`string`?JSON.parse(e):[],Mu=e=>{let t=e.split(`,`);return t.includes(`owner`)?`owner`:t.includes(`admin`)?`admin`:`member`},Nu=e=>({id:e.id,userId:e.userId,name:e.user.name||e.user.email,email:e.user.email,role:Mu(e.role),appRoles:ju(e.appRoles),createdAt:new Date(e.createdAt).toISOString()}),Pu=e=>({id:e.id,email:e.email,role:Mu(e.role),appRoles:ju(e.appRoles),status:e.status,expiresAt:new Date(e.expiresAt).toISOString(),...e.organizationName&&{organizationName:e.organizationName}}),Fu=(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(Nu),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(Pu),invite:async(e,t)=>{let r=await n(`/organization/invite-member`,`Could not send the invitation`,{body:{organizationId:e,...t}});return{invitation:Pu(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:Pu(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(Pu),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}}))}},Iu=(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()}}),Lu=20,Ru=e=>Array.isArray(e)?e:(e??``).split(`,`).map(e=>e.trim()).filter(Boolean),zu=e=>({id:e.id,name:e.name||e.email,email:e.email,roles:Ru(e.role),blocked:!!e.banned,createdAt:new Date(e.createdAt).toISOString()}),Bu=e=>({id:e.id,email:e.email,roles:e.roles,expiresAt:new Date(e.expiresAt).toISOString()}),Vu=e=>({invitation:Bu(e),...e.link&&{link:e.link}}),Hu=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(Lu),sortBy:`createdAt`,sortDirection:`asc`,...n>0&&{offset:String(n)},...e&&{searchValue:e,searchField:`email`}}});return{users:r.users.map(zu),total:r.total}},create:async e=>zu((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=>Vu(await t(`/users/invite`,`Could not send the invitation`,{body:e})),invitations:async()=>(await t(`/users/invitations`,`Could not read the invitations`)).invitations.map(Bu),revoke:e=>t(`/users/invitations/cancel`,`Could not revoke the invitation`,{body:{id:e}}),roles:()=>t(`/users/roles`,`Could not read the roles`)}},Uu=(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 wu(`Auth cancelled`,400,e instanceof oe?e.code:`AUTH_CANCELLED`)}),s=await e.$fetch(`/passkey/verify-authentication`,{method:`POST`,body:{response:o}});if(s.error||!s.data)throw R(s.error,`Sign-in failed`);return await t(),s.data.user},sendTwoFactorCode:async()=>{let{error:t}=await e.twoFactor.sendOtp();if(t)throw R(t,`Could not send the code`)},verifyTwoFactor:async({method:n,code:r,trustDevice:i=!1})=>{let{data:a,error:o}=await(n===`totp`?e.twoFactor.verifyTotp:n===`otp`?e.twoFactor.verifyOtp:e.twoFactor.verifyBackupCode)({code:r,trustDevice:i});if(o||!a)throw R(o,`The code did not work`);return await t(),a.user}}},Wu=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}}),Gu=e=>new Date(e).toISOString(),Ku=({startedAt:e,expiresAt:t,endedAt:n,...r})=>({...r,startedAt:Gu(e),expiresAt:Gu(t),...n&&{endedAt:Gu(n)}}),qu=e=>({start:async t=>{let{data:n,error:r}=await e.$fetch(`/staff/sign-in`,{method:`POST`,body:t});if(r||!n?.url)throw R(r,`Could not start the staff sign-in`);return n.url},current:async()=>{let{data:t,error:n}=await e.$fetch(`/staff/session`);if(n||!t)throw R(n,`Could not read the session`);return t.staff?Ku(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(Ku)}}),Ju=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},Yu=(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=Au(t,n,i),o=qu(a),s,c,l,u=()=>{s=void 0,clearTimeout(l)},d=async()=>{let{data:t}=await a.$fetch(`/token`);if(!t?.token){u();return}return s={token:t.token,expiresAt:Ju(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 wu(`This server has no sign-in. Is the API URL right?`,404);if(!e.ok)throw new wu(`Could not read the sign-in status`,e.status);let r=await e.json();return{needsAdmin:!!r.needsAdmin,...r.needsAdmin&&r.firstAdminUrl&&{firstAdminUrl:r.firstAdminUrl},signInMethods:r.signInMethods??[`password`],...r.signInFirst===`emailCode`&&{signInFirst:`emailCode`},passwordReset:!!r.passwordReset,...r.changeEmail&&{changeEmail:!0},...r.accountDeletion&&{accountDeletion:!0},...r.signUp&&{signUp:!0},socialProviders:r.socialProviders??[],...r.platformSignIn&&{platformSignIn:r.platformSignIn},samlProviders:r.samlProviders??[],...r.staffSignIn&&{staffSignIn:r.staffSignIn},...r.passkeyDomains&&{passkeyDomains:r.passkeyDomains},...r.organizations&&{organizations:r.organizations},...r.anonymous&&{anonymous:!0},...r.mcp&&{mcp:{url:r.mcp.url}},...r.personalMail&&r.personalMail.length>0&&{personalMail:r.personalMail},...r.plugins&&r.plugins.length>0&&{plugins:r.plugins},...Fe(r.locale)&&{locale:r.locale}}},session:async()=>{let{data:e}=await a.getSession();return e?.user},...Uu(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:{...Du(a),...Eu(a)},connect:ku(a),organizations:Fu(a,()=>f({refresh:!0})),roles:Iu(a,()=>f({refresh:!0})),signInPolicy:Wu(a),users:Hu(a),staff:{...o,stop:async()=>{u(),await o.stop()}}}},Xu=e=>Math.min(3e4,1e3*2**e),Zu=(e,t)=>new Promise(n=>{let r=setTimeout(n,e);t.addEventListener(`abort`,()=>{clearTimeout(r),n()},{once:!0})}),Qu=`http://same-origin.invalid`,$u=(e,t)=>{let n=new URL(e,Qu),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===Qu?`${r.pathname}${r.search}`:r.href},ed=e=>{let t=e.url.replace(/\/+$/,``),n=e.fetch??((e,t)=>fetch(e,t)),r=e.retryDelayMs??Xu,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 hl(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 nr(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 Zu(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=$u(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 hl(c);return c}}},td=e=>typeof e==`object`&&!!e&&`error`in e&&typeof e.error==`object`&&e.error!==null&&`code`in e.error&&`message`in e.error,nd=async e=>{let t=e.headers.get(`content-type`)?.includes(`json`)??!1?await e.clone().json():void 0;return td(t)?new dl({type:`urn:protobase:problem:${t.error.code}`,title:e.statusText||`Request failed`,status:e.status,detail:t.error.message}):hl(e)},rd=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 nd(o);return await o.json()};return{status:()=>r(``,`GET`),update:()=>r(`/update`,`POST`)}},id=e=>e.Capacitor?.isNativePlatform()?e.Capacitor:void 0,ad=[101,204,205,304],od=/%2f|%5c/i,sd=e=>Object.hasOwn(hr,e),cd=(e,t)=>e.origin===t&&!e.username&&!e.password&&e.pathname.startsWith(`/api/auth/`)&&!od.test(e.pathname),ld=({status:e,headers:t,data:n})=>ad.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),ud=(e,t)=>{let n=e.getPlatform();if(!sd(n))throw Error(`Signing in through native HTTP is for iOS and Android, not ${n}`);return async(n,r)=>{let i=new Request(n,r),a=new URL(i.url);if(!cd(a,t))throw Error(`Native sign-in requests go to ${t}${mr}/ only, not ${i.url}`);let o=i.method!==`GET`&&i.method!==`HEAD`,s=await e.nativePromise(`ProtobaseAuth`,`request`,{url:a.href,method:i.method,headers:Object.fromEntries(i.headers),...o&&{data:await i.text()}}),c=Object.entries(s.headers).filter(([e])=>e.toLowerCase()!==`set-cookie`);return new Response(ld(s),{status:s.status,headers:c})}},dd=(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(`/${_r}`),t.serviceWorker.ready),clearBadge:async()=>{`clearAppBadge`in t&&await t.clearAppBadge()},userAgent:t.userAgent.replace(/[\u0000-\u001f\u007f]/g,``).slice(0,512)}},fd=(e=indexedDB)=>{let t=(t,n)=>new Promise((r,i)=>{let a=e.open(gr.database,1);a.onupgradeneeded=()=>a.result.createObjectStore(gr.store),a.onerror=()=>i(a.error),a.onsuccess=()=>{let e=a.result,o=n(e.transaction(gr.store,t).objectStore(gr.store));o.onsuccess=()=>(e.close(),r(o.result)),o.onerror=()=>(e.close(),i(o.error))}});return{read:()=>t(`readonly`,e=>e.get(gr.key)),write:async e=>void await t(`readwrite`,t=>t.put(e,gr.key)),clear:async()=>void await t(`readwrite`,e=>e.delete(gr.key))}},pd=e=>Uint8Array.from(atob(e.replace(/-/g,`+`).replace(/_/g,`/`)),e=>e.charCodeAt(0)),md=(e,t)=>Promise.race([t,new Promise(t=>setTimeout(t,e))]),hd=class extends Error{},gd=(e,t)=>e instanceof dl&&e.status===409&&e.slug===t,_d=({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 hd;let e=await c.pushManager.getSubscription()??await c.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:pd(a)}),i={userId:n.id,endpoint:e.endpoint,appName:r};if(await t.write(i),!o())throw new hd;await d(e,i)};try{await h()}catch(e){if(gd(e,`device-held`))return await u(c),m(c,h);if(await u(c),e instanceof hd||gd(e,`other-user`))return`off`;throw e}return`on`},m=async(e,t)=>{try{await t()}catch(t){if(await u(e),t instanceof hd||gd(t,`device-held`)||gd(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 md(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 md(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(!gd(e,`device-held`)&&!gd(e,`other-user`))throw e;await u(r)}}}},vd={state:async()=>`unsupported`,turnOn:async()=>`unsupported`,turnOff:async()=>{},forget:async()=>{},adopt:async()=>{}},yd=({nativeBridge:e,...t})=>{if(e||typeof window>`u`)return vd;let n=dd();return n.supported?_d({...t,browser:n,records:fd()}):vd},bd=`sign-in`,xd=`error`,Sd=e=>{let t=new URL(e).searchParams;if(!t.has(xd))return t.get(`sign-in`)||void 0},Cd=e=>new URL(e).searchParams.get(xd)||void 0,wd=e=>{let t=new URL(e);for(let e of[bd,xd])t.searchParams.delete(e);return`${t.pathname}${t.search}${t.hash}`},Td={github:`GitHub`,gitlab:`GitLab`,google:`Google`,microsoft:`Microsoft`,apple:`Apple`},Ed=(e,t)=>t?.provider===e?t.name:Td[e]??e.charAt(0).toUpperCase()+e.slice(1),z=M(`auth`),B=e(r(),1),Dd=(0,I.createContext)(null),V=()=>{let e=(0,I.useContext)(Dd);if(!e)throw Error(`useAuth must be used inside AuthProvider`);return e},Od=()=>(0,I.useContext)(Dd),kd=({session:e,origin:t,nativeBridge:n,children:r})=>{let[i,a]=(0,I.useState)({kind:`loading`}),[o,s]=(0,I.useState)([`password`]),[c,l]=(0,I.useState)(`password`),[u,d]=(0,I.useState)(!1),[f,p]=(0,I.useState)(!1),[m,h]=(0,I.useState)(!1),[g,_]=(0,I.useState)(),[v,y]=(0,I.useState)(!1),[b,x]=(0,I.useState)([]),[S,C]=(0,I.useState)([]),[w,T]=(0,I.useState)(),[E,D]=(0,I.useState)([]),[O,k]=(0,I.useState)([]),[A,j]=(0,I.useState)(),[ee,te]=(0,I.useState)(),[ne,re]=(0,I.useState)(!1),[ie,ae]=(0,I.useState)([]),[oe,se]=(0,I.useState)(),ce=(0,I.useCallback)(()=>ne?{kind:`visitor`}:{kind:`signed-out`},[ne]),le=(0,I.useRef)(async()=>{}),ue=(0,I.useCallback)(()=>{le.current(),a(e=>e.kind===`signed-in`?{kind:`signed-out`}:e)},[]),de=(0,I.useRef)(ue);de.current=ue;let fe=(0,I.useMemo)(()=>e??Yu({...t&&{origin:t},...n&&{fetch:ud(n,t??window.location.origin)},onSignedOut:()=>de.current()}),[e,t,n]),pe=(0,I.useRef)(void 0);pe.current=i.kind===`signed-in`?{id:i.user.id,own:!i.staff}:void 0;let me=(0,I.useMemo)(()=>{let e=eu({baseUrl:`${t??globalThis.location?.origin??``}/api/v1`,token:({refresh:e})=>fe.token({refresh:e})}),r=async()=>{let t=await e.meta();if(t.status!==`modified`)throw Error(`The app answered /meta without its content`);return{appName:t.meta.appName,...t.meta.notifications?.webPushKey&&{webPushKey:t.meta.notifications.webPushKey}}};return yd({...n&&{nativeBridge:n},devices:e.devices,meta:r,user:()=>pe.current})},[fe,t,n]);le.current=me.forget;let he=(0,I.useCallback)(async e=>{let[{missing:t},n]=await Promise.all([fe.account.signInMethods(),fe.staff.current()]);a(t.length>0?{kind:`setup-required`,user:e,missing:t}:{kind:`signed-in`,user:e,...n&&{staff:n}}),t.length===0&&me.adopt({id:e.id,own:!n})},[fe,me]),ge=(0,I.useCallback)(async e=>e.kind===`two-factor`?a({kind:`two-factor`,methods:e.methods}):he(e.user),[he]),_e=(0,I.useCallback)(()=>{a({kind:`loading`}),fe.status().then(async e=>{if(s(e.signInMethods),l(e.signInFirst??`password`),d(e.passwordReset&&!n),p(!!e.changeEmail),h(!!e.accountDeletion),_(e.mcp),y(!!e.signUp),x(e.passkeyDomains??[]),C(e.socialProviders),T(e.platformSignIn),D(e.personalMail??[]),k(e.samlProviders),j(e.staffSignIn),te(e.organizations),re(!!e.anonymous),ae(e.plugins??[]),se(e.locale),e.needsAdmin)return a({kind:`needs-admin`,...e.firstAdminUrl&&{firstAdminUrl:e.firstAdminUrl}});let t=await fe.session();return t?he(t):a({kind:e.anonymous?`visitor`:`signed-out`})}).catch(e=>a({kind:`error`,message:e instanceof Error?e.message:z(`noAnswer`)}))},[fe,he,n]);(0,I.useEffect)(_e,[_e]);let ve=(0,I.useMemo)(()=>({state:i,session:fe,signInMethods:o,signInFirst:c,passwordReset:u,changeEmail:f,accountDeletion:m,mcp:g,canSignUp:v,passkeyDomains:b,socialProviders:S,signInProviders:[...S.map(e=>({id:e,name:Ed(e,w)})),...O],staffSignIn:A,...ee&&{organizations:ee},markSignedOut:ue,recheck:_e,beforeSignIn:ie,locale:oe,adoptSession:async()=>{let e=await fe.session();return e?(await he(e),!0):!1},...ne&&{browse:()=>{a(e=>e.kind===`signed-out`?{kind:`visitor`}:e)}},signIn:async(e,t)=>ge(await fe.signIn(e,t)),sendSignInCode:e=>fe.sendSignInCode(e),signInWithCode:async(e,t)=>ge(await fe.signInWithCode(e,t)),sendSignUpCode:e=>fe.sendSignUpCode(e),verifySignUpCode:(e,t)=>fe.verifySignUpCode(e,t),signUp:async e=>he(await fe.signUp(e)),signInWithPasskey:async e=>he(await fe.signInWithPasskey(e)),verifyTwoFactor:async e=>he(await fe.verifyTwoFactor(e)),signInSocial:async e=>{let t=new URL(wd(window.location.href),window.location.href).href,n=O.some(t=>t.id===e);window.location.assign(await(n?fe.signInSaml(e,t):fe.signInSocial(e,t)))},linkProvider:async e=>{window.location.assign(await fe.account.linkProvider(e,new URL(wd(window.location.href),window.location.href).href))},personalMail:E,linkPersonalMail:async e=>{window.location.assign(await fe.account.linkPersonalMail(e,new URL(wd(window.location.href),window.location.href).href))},stopStaffSession:async()=>{await me.forget(),await fe.staff.stop(),a(ce())},signOut:async()=>{await me.turnOff(),await fe.signOut(),a(ce())},deleteAccount:async e=>{await fe.deleteAccount(e),await me.forget(),a(ce())},push:me}),[me,i,fe,o,c,u,f,m,g,v,b,S,w,E,O,A,ee,ne,ie,oe,ce,ue,_e,ge,he]);return(0,B.jsx)(Dd.Provider,{value:ve,children:r})},Ad=()=>{let e=0;return{refetchOnWindowFocus:()=>e>0?!1:`always`,paused:()=>e>0,pause:()=>{e+=1;let t=!1;return()=>{t||(t=!0,--e)}}}},jd=(0,I.createContext)(null),Md=e=>{let t=(0,I.useContext)(jd);(0,I.useEffect)(()=>e&&t?t.pause():void 0,[e,t])},Nd=e=>{let t=()=>e();return window.addEventListener(`visibilitychange`,t,!1),window.addEventListener(`focus`,t,!1),()=>{window.removeEventListener(`visibilitychange`,t),window.removeEventListener(`focus`,t)}},H={meta:[`meta`],sourceMeta:(e,t)=>[`source-meta`,e,t.join(`,`)],sourceMetas:e=>[`source-meta`,e],list:(e,t,n,r,i)=>[`list`,e,t,n,r,i],page:(e,t,n,r,i)=>[`page`,e,t,n,r,i],pages:(e,t,n)=>[`page`,e,t,n],navRecent:(e,t,n,r)=>[`list`,e,t,n,r,`nav-recent`],first:(e,t,n)=>[`first-page`,e,t,n],record:(e,t)=>[`record`,e,t],recordPreview:(e,t)=>[`record-preview`,e,t],history:(e,t,n)=>[`record`,e,t,`history`,n],comments:(e,t)=>[`record`,e,t,`comments`],facets:(e,t,n)=>[`facets`,e,t,n],series:(e,t,n,r,i)=>[`series`,e,t,n,r,i],aggregate:(e,t)=>[`aggregate`,e,t],histogram:(e,t,n,r)=>[`histogram`,e,t,n,r],map:(e,t,n,r,i)=>[`map`,e,t,n,r,i],relatedLabel:(e,t)=>[`related-label`,e,t],titleRow:(e,t,n)=>[`title-row`,e,t,n],labels:(e,t)=>[`labels`,e,t],pickedLabels:(e,t)=>[`picked-labels`,e,t],count:(e,t)=>[`count`,e,t],exportCount:(e,t)=>[`list`,e,t,`export-count`],firstRecord:(e,t,n)=>[`first-record`,e,t,n],pathValue:(e,t,n)=>[`path-value`,e,t,n],inbox:[`inbox`],inboxUnread:[`inbox`,`unread`],inboxPages:[`inbox`,`pages`],members:e=>[`members`,e],statuses:e=>[`statuses`,e],ownStatus:e=>[`statuses`,e,`own`],rings:[`call-rings`],recordCalls:(e,t)=>[`record-calls`,e,t],publicForm:e=>[`public-form`,e]},Pd=(0,I.createContext)(null),Fd=(0,I.createContext)(null),Id=(0,I.createContext)(null),U=()=>{let e=(0,I.useContext)(Pd);if(!e)throw Error(`useClient must be used inside ApiProvider`);return e},Ld=e=>{let t=U();return(0,I.useContext)(Id)?.(e)??t},Rd=()=>{let e=U(),t=(0,I.useContext)(Id);return(0,I.useCallback)(n=>t?.(n)??e,[e,t])},zd=()=>{let e=(0,I.useContext)(Fd);if(!e)throw Error(`useSourceClients must be used inside ApiProvider`);return e},Bd=({client:e,resourceClient:t,children:n})=>(0,B.jsx)(Pd.Provider,{value:e,children:(0,B.jsx)(Id.Provider,{value:t,children:n})}),Vd=({baseUrl:e,client:t,sources:n,fetch:r,queryClient:i,token:a,onUnauthenticated:o,children:s})=>{let[c]=(0,I.useState)(Ad),[l]=(0,I.useState)(()=>i??new T({defaultOptions:{queries:{staleTime:3e4,retry:!1,refetchOnWindowFocus:c.refetchOnWindowFocus}}}));(0,I.useEffect)(()=>D.setEventListener(Nd),[]);let u=(0,I.useRef)(void 0),d=(0,I.useMemo)(()=>t??eu({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=eu({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)(Pd.Provider,{value:d,children:(0,B.jsx)(Fd.Provider,{value:f,children:(0,B.jsx)(jd.Provider,{value:c,children:s})})})})},Hd=(0,I.createContext)(null),Ud={create:!0,update:!0,delete:!0,conditional:[]},Wd=(e,t)=>e?e.versionChange?e:t.protobaseVersion===e.protobaseVersion?t:{...e,versionChange:{...t.protobaseVersion&&{to:t.protobaseVersion}}}:t,Gd=()=>{let e=U(),t=Se(),n=(0,I.useContext)(Hd),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 Wd(n,{etag:r.etag,appName:r.meta.appName,...r.meta.protobaseVersion&&{protobaseVersion:r.meta.protobaseVersion},...r.meta.appIcon&&{appIcon:r.meta.appIcon},resources:Object.fromEntries(r.meta.resources.map(e=>[e.name,e])),views:Object.fromEntries(r.meta.views.map(e=>[e.resource,e])),pages:Object.fromEntries((r.meta.pages??[]).map(e=>[e.name,e])),...r.meta.account&&{account:r.meta.account},permissions:r.meta.permissions??{},...r.meta.userMenu&&{userMenu:r.meta.userMenu},...r.meta.signIn&&{signIn:Object.fromEntries(r.meta.signIn.map(e=>[e.resource,e]))},...r.meta.bottomBar&&{bottomBar:r.meta.bottomBar},...r.meta.assistant&&{assistant:r.meta.assistant},...r.meta.runtime&&{runtime:r.meta.runtime},...r.meta.errorReporting&&{errorReporting:r.meta.errorReporting},...r.meta.maps&&{maps:r.meta.maps},...r.meta.notifications?.bell&&{bell:!0},...r.meta.status&&{status:!0},...r.meta.calls&&{calls:!0},...r.meta.locale&&{locale:r.meta.locale},...r.meta.files&&{files:r.meta.files},...r.meta.plugins&&{plugins:r.meta.plugins},...r.meta.sources&&{sources:r.meta.sources.map(e=>({source:e,state:`loading`}))}})}});return(0,I.useMemo)(()=>n&&r.data?{...r,data:n}:r,[n,r])},Kd=1e4,qd=e=>e.map(e=>({data:e.data?.meta,error:e.error})),Jd=(e,t)=>{let n=Se(),r=f({queries:e.map(e=>{let r=H.sourceMeta(e.url,e.resources);return{queryKey:r,staleTime:0,refetchOnWindowFocus:`always`,queryFn:async()=>{let i=n.getQueryData(r),a=await t(e).meta(i?.etag,{signal:AbortSignal.timeout(Kd)});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:Cu(a.meta,e)}}}}),combine:qd});return(0,I.useMemo)(()=>e.map((e,t)=>{let{data:n,error:i}=r[t];return n?{source:e,state:`ready`,meta:n}:i?{source:e,state:`error`,error:i}:{source:e,state:`loading`}}),[e,r])},Yd=(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}},Xd=(e,t)=>e.sources?.find(e=>e.source.resources.includes(t)),Zd=({locale:e,children:t})=>{He(e);let n=Be();return(0,I.useEffect)(()=>{document.documentElement.lang=n},[n]),(0,B.jsx)(I.Fragment,{children:t},n)},Qd=M(`primitives`),$d=({className:e})=>(0,B.jsx)(eo,{"aria-label":Qd(`loading`),className:P(`size-4 animate-spin`,e)}),ef=M(`app/meta-gate`),W=()=>{let e=(0,I.useContext)(Hd);if(!e)throw Error(`useAdminMeta must be used inside MetaGate`);return e},tf=({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})]})}),nf=({meta:e,children:t})=>{let n=U(),r=zd(),i=(0,I.useMemo)(()=>(e.sources??[]).map(e=>e.source),[e.sources]),a=Jd(i,r),o=(0,I.useMemo)(()=>Yd(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:nu(n,t),resourceClient:t}},[i,n,r]);return(0,B.jsx)(Bd,{client:s.client,resourceClient:s.resourceClient,children:(0,B.jsx)(Hd.Provider,{value:o,children:(0,B.jsx)(Zd,{locale:e.locale,children:t})})})},rf=({children:e})=>{let t=Gd();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)($d,{}),` `,ef(`loading`)]}):t.error?(0,B.jsx)(tf,{title:ef(`cannotReach`),children:pl(t.error)?t.error.message:ef(`noAnswer`)}):(0,B.jsx)(nf,{meta:t.data,children:e})},af=e=>W().permissions[e]??Ud,of=(0,I.createContext)(null),sf=({route:e,children:t})=>(0,B.jsx)(of.Provider,{value:e,children:t}),cf=()=>{let e=(0,I.useContext)(of);if(!e)throw Error(`Tabs render inside a page that gives them their addresses: a composed page`);return e},lf=e=>e.children.filter(e=>typeof e!=`string`).map(e=>({node:e,...e.props})),uf=e=>{let t=e.children.find(e=>typeof e!=`string`&&!e.custom&&e.type===`Tabs`);return t?lf(t):[]},df=(e,t)=>t===void 0?e[0]:e.find(e=>e.name===t),ff={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`},pf={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`},mf=({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`,ff[e],pf[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(mf({variant:e,size:t}),r),...o,children:[n&&(0,B.jsx)($d,{className:`size-3.5`}),i]}),hf=e=>(0,I.useSyncExternalStore)(t=>{let n=window.matchMedia(e);return n.addEventListener(`change`,t),()=>n.removeEventListener(`change`,t)},()=>window.matchMedia(e).matches,()=>!1),gf=()=>hf(`(min-width: 768px)`),_f=()=>hf(`not all and (min-width: 640px)`),vf=`data-pb-scroll-locked`,yf=()=>{let{body:e,documentElement:t}=document,n=e.style.overflow,r=t.hasAttribute(vf);return window.innerWidth>t.clientWidth&&t.setAttribute(vf,``),e.style.overflow=`hidden`,()=>{e.style.overflow=n,r||t.removeAttribute(vf)}},bf=`a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])`,xf=[],Sf=(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=yf(),o={};xf.push(o);let s=()=>[...n.querySelectorAll(bf)];(s()[0]??n).focus();let c=e=>{if(xf.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),xf.splice(xf.indexOf(o),1),a(),i?.focus()}},[t,e])},Cf=({title:e,description:t,onClose:n,actions:r,children:i,wide:a=!1,name:o})=>{let s=(0,I.useRef)(null);return Sf(s,!0,n),(0,Sc.createPortal)((0,B.jsx)(`div`,{"data-dialog":o??``,className:`fixed inset-0 z-[90] flex items-center justify-center bg-backdrop/30 p-4 pb-[calc(1rem+var(--pb-safe-bottom))] pl-[calc(1rem+var(--pb-safe-left))] pr-[calc(1rem+var(--pb-safe-right))] pt-[calc(1rem+var(--pb-safe-top))]`,onMouseDown:e=>e.target===e.currentTarget&&n(),children:(0,B.jsxs)(`div`,{ref:s,tabIndex:-1,role:`dialog`,"aria-modal":`true`,"aria-label":e,className:P(`outline-none max-h-[min(90vh,100%)] w-full overflow-y-auto rounded-lg border bg-background p-4 shadow-pop sm:p-5`,a?`max-w-3xl`:`max-w-md`),children:[(0,B.jsx)(`h2`,{className:`text-[16px] font-semibold`,children:e}),t&&(0,B.jsx)(`p`,{className:`mt-1.5 text-muted-foreground`,children:t}),i&&(0,B.jsx)(`div`,{className:`mt-4`,children:i}),(0,B.jsx)(`div`,{className:`mt-5 flex flex-col-reverse gap-2 sm:flex-row sm:justify-end [&>*]:min-h-11 sm:[&>*]:min-h-0`,children:r})]})}),document.body)},wf=(e,t)=>t>=60&&t>Math.abs(e),Tf=({title:e,open:t,onClose:n,children:r})=>{let i=(0,I.useRef)(null),a=(0,I.useRef)(void 0);return Sf(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=wf(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":Qd(`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)(yc,{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},Ef=({title:e,description:t,open:n,onClose:r,actions:i,children:a,wide:o})=>{let s=gf();return n?s?(0,B.jsx)(Cf,{title:e,description:t,onClose:r,actions:i,wide:o,children:a}):(0,B.jsx)(Tf,{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},Df=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},Of=`#ffffff`,kf=`#111827`,Af=e=>{let t=Df(e);return 1.05/(t+.05)>=(t+.05)/(Df(kf)+.05)?Of:kf},jf={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`},Mf={neutral:`bg-faint-foreground`,blue:`bg-primary`,green:`bg-success`,amber:`bg-warning`,red:`bg-danger`,violet:`bg-violet`},Nf=`polygon(0 0, calc(100% - 0.625rem) 0, 100% 50%, calc(100% - 0.625rem) 100%, 0 100%)`,Pf=({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:Af(n)},...r===`arrow`&&{clipPath:Nf}},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&&jf[e],a),children:[t&&n===void 0&&r===void 0&&(0,B.jsx)(`span`,{className:P(`size-1.5 rounded-full`,Mf[e])}),i]}),Ff={xs:`size-5 text-[9px]`,sm:`size-6 text-[10px]`,md:`size-8 text-xs`},If=({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`,Ff[n],r),style:{background:`oklch(0.58 0.13 ${t})`},children:e}),Lf=({people:e,size:t=`sm`})=>(0,B.jsx)(`span`,{className:`inline-flex -space-x-1`,children:e.map(e=>(0,B.jsx)(If,{...e,size:t},e.initials))}),Rf=M(`record-view`),zf=({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)(Pf,{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:[Rf(`lastEditedBy`),` `,(0,B.jsx)(`span`,{className:`font-medium text-foreground`,children:r.name}),` `,r.ago]}):(0,B.jsx)(B.Fragment,{children:Rf(`lastUpdated`,{ago:r.ago})})})]}),(0,B.jsxs)(`div`,{className:`flex items-center gap-4`,children:[i.length>0&&(0,B.jsxs)(`span`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,B.jsx)(Lf,{people:i,size:`md`}),Rf(`viewing`,{count:i.length})]}),a]})]}),Bf=({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]})},Vf=({title:e,help:t,actions:n,children:r})=>(0,B.jsx)(`section`,{className:`py-8 first:pt-8`,children:(0,B.jsx)(Bf,{title:e,help:t,actions:n,children:r})}),Hf=new Map,Uf=(e,t)=>{let n=Le(),r=`${n}|${e}`;return Hf.has(r)||Hf.set(r,t(n)),Hf.get(r)},Wf=M(`format`),Gf=()=>Intl.DateTimeFormat().resolvedOptions().timeZone,Kf=new Map,qf=e=>{let t=Kf.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 Kf.set(e,n),n},Jf=(e,t)=>{let n=Object.fromEntries(qf(t).formatToParts(e).map(e=>[e.type,e.value]));return{year:Number(n.year),month:Number(n.month),day:Number(n.day),hour:Number(n.hour),minute:Number(n.minute),second:Number(n.second)}},Yf=(e,t)=>{let n=Jf(e,t);return Date.UTC(n.year,n.month-1,n.day,n.hour,n.minute,n.second)-Math.floor(e/1e3)*1e3},Xf=e=>String(e).padStart(2,`0`),Zf=(e,t)=>{let n=Jf(e,t);return`${n.year}-${Xf(n.month)}-${Xf(n.day)}`},Qf=(e,t)=>e-Yf(e-Yf(e,t),t),$f=(e,t)=>Qf(Date.parse(`${e}T00:00:00Z`),t),ep=(e,t)=>{let n=Uf(`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})`},tp=(e,t)=>()=>Uf(`date:${e}`,e=>new Intl.DateTimeFormat(e,{...t,timeZone:`UTC`})),np=tp(`day`,{day:`numeric`,month:`short`,year:`numeric`}),rp=tp(`dayShort`,{day:`numeric`,month:`short`}),ip=tp(`month`,{month:`long`,year:`numeric`}),ap=tp(`monthName`,{month:`long`}),op=tp(`weekday`,{weekday:`short`}),sp=tp(`weekdayDate`,{weekday:`long`,day:`numeric`,month:`short`,year:`numeric`}),cp=e=>np().format(e),lp=e=>rp().format(e),up=e=>Uf(`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})})),dp=(e,t=Gf())=>{let n=up(t);return`${n.day.format(e)}, ${n.time.format(e)}`},fp=e=>ip().format(e),pp=e=>ap().format(e),mp=(e,t)=>ip().formatRange(e,t),hp=e=>op().format(e),gp=e=>sp().format(e),_p=(e,t)=>np().formatRange(e,t),vp=(e,t=Gf())=>up(t).time.format(e),yp=e=>e<60?Wf(`secondsAgo`,{count:e}):e<3600?Wf(`minutesAgo`,{count:Math.floor(e/60)}):e<86400?Wf(`hoursAgo`,{count:Math.floor(e/3600)}):Wf(`daysAgo`,{count:Math.floor(e/86400)}),bp=()=>Uf(`relative`,e=>new Intl.RelativeTimeFormat(e,{numeric:`auto`})),xp=[[`year`,31536e3],[`month`,2592e3],[`day`,86400],[`hour`,3600],[`minute`,60]],Sp=e=>{let t=Math.abs(e),[n,r]=xp.find(([,e])=>t>=e)??[`second`,1];return n===`second`&&t<45?Wf(`justNow`):bp().format(-Math.sign(e)*Math.floor(t/r),n)},Cp=()=>Uf(`grouped`,e=>new Intl.NumberFormat(e)),wp=e=>Cp().format(e),Tp=e=>e>0?`+${Cp().format(e)}`:Cp().format(e).replace(`-`,`−`),Ep=e=>`${e}%`,Dp=e=>{if(e<1e4)return Wf(`rows`,{count:wp(e),n:e});let t=10**(Math.floor(Math.log10(e))-3);return Wf(`aboutRows`,{count:wp(Math.round(e/t)*t)})},Op=(e,t)=>Uf(`money:${e}:${t??``}`,n=>new Intl.NumberFormat(n,{style:`currency`,currency:e,...t!==void 0&&{minimumFractionDigits:t,maximumFractionDigits:t}})),kp=(e,t,n)=>Op(t,n).format(e/100),Ap=M(`live`),jp=e=>typeof e==`object`&&!!e&&typeof e.uri==`string`,Mp=e=>typeof e==`object`&&!!e&&typeof e.uploaded?.value==`string`,Np=e=>{if(Mp(e))return{...e.uploaded.file,...e.preview&&{url:e.preview},corrected:e.uploaded.corrected};if(jp(e))return`missing`in e?{name:Ap(`fileMissing`),type:``,missing:!0}:e},Pp=[`bytes`,`kB`,`MB`,`GB`],Fp=e=>{let t=e,n=0;for(;t>=1e3&&n<Pp.length-1;)t/=1e3,n+=1;return n===0?`${e} ${e===1?`byte`:`bytes`}`:`${t<10?t.toFixed(1):Math.round(t)} ${Pp[n]}`},Ip=e=>e.startsWith(`image/`)&&e!==`image/svg+xml`,Lp=2,Rp=1e5,zp=(e,t)=>(e.width!==void 0||e.height!==void 0)&&(e.width??Rp)>=t.width*Lp&&(e.height??Rp)>=t.height*Lp,Bp=e=>(e.width??Rp)*(e.height??Rp),Vp=(e,t)=>{let n=Np(e);if(!(!n||`missing`in n||!n.url||!Ip(n.type)))return{url:(`variants`in n&&n.variants?Object.values(n.variants):[]).filter(e=>zp(e,t)).sort((e,t)=>Bp(e)-Bp(t))[0]?.url??n.url,...`placeholder`in n&&n.placeholder!==void 0&&{placeholder:n.placeholder}}},Hp=e=>{let t=e.file?.accept??[];return t.length===0||t.includes(`*/*`)?void 0:t.join(`,`)},Up=e=>Mp(e)?e.uploaded.value:jp(e)?e.uri:null,Wp=(e,t)=>{if(Mp(e))return!0;let n=e=>jp(e)?e.uri:null;return n(e)!==n(t)},Gp=M(`data-grid`),Kp=e=>typeof e==`object`&&e&&`name`in e?String(e.name):String(e),qp=(e,t)=>{if(t==null)return`—`;switch(e.kind){case`text`:case`id`:return String(t);case`money`:if(e.currency===void 0)throw Error(`Money column "${e.id}" has no currency`);return`${kp(Number(t),e.currency,e.decimals)}${e.suffix??``}`;case`date`:return cp(Number(t));case`datetime`:return e.relative?Sp(Math.round((Date.now()-Number(t))/1e3)):dp(Number(t));case`number`:return`${e.prefix??``}${wp(Number(t))}${e.suffix??``}`;case`signed`:return`${e.prefix??``}${Tp(Number(t))}${e.suffix??``}`;case`percent`:return Number(t)===0?`—`:Ep(Number(t));case`status`:return ir(String(t),e.labels);case`relation`:return Kp(t);case`boolean`:return t?void 0:Gp(`no`);case`file`:return Np(t)?.name??`—`;case`user`:return e.users?.(String(t))?.name??String(t)}},Jp=(e,t)=>Math.ceil(e.length*7.2)+24+(t?16:0)+28,Yp=e=>Math.ceil(Math.max(0,...e.map(e=>e.length))*7.2)+56,Xp={body:7.5,mono:7.2,numeric:8},Zp=24,Qp=24,$p=16,em=new Set([`status`,`money`,`number`,`signed`,`percent`,`date`,`datetime`,`boolean`]),tm=new Set([`money`,`number`,`signed`,`percent`,`date`,`datetime`]),nm=80,rm=400,im=240,am=e=>e===`id`?Xp.mono:tm.has(e)?Xp.numeric:Xp.body,om=(e,t)=>e.value?e.value(t):t[e.id],sm=(e,t)=>{let n=t.map(t=>qp(e,om(e,t)));if(e.kind===`status`)return Yp(n.map(e=>e??``));let r=e.kind===`user`||e.kind===`file`?Qp:0;return Math.max(0,...n.map(t=>t===void 0?$p:Math.ceil(t.length*am(e.kind))))+r+Zp},cm=(e,t,n)=>Math.min(n,Math.max(t,e)),lm=(e,t)=>{if(em.has(e.kind)&&!e.title)return{...e,fixed:!0,width:Math.max(e.minWidth??0,t)};let n={...e,fixed:!1,width:cm(t,nm,rm)};return e.kind===`id`?{...n,minWidth:Math.max(Jp(e.header,e.sortable??!1),Math.min(t,im))}:n},um=(e,t)=>{if(t.length===0)return e;let n=e.map(e=>e.render?e:lm(e,sm(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)},dm=e=>e.charAt(0).toUpperCase()+e.slice(1),fm=[[/^\s*(```|~~~).*$/,``],[/^\s*\[[^\]]+\]:\s+\S.*$/,``],[/^\s*([-*_]\s*){3,}$/,``],[/^\s*\|?(\s*:?-+:?\s*\|)+\s*:?-*:?\s*$/,``],[/^\s*#{1,6}\s+/,``],[/^\s*(>\s?)+/,``],[/^\s*([-*+]|\d+[.)])\s+(\[[ xX]\]\s+)?/,``]],pm=[[/!\[([^\]]*)\]\([^)]*\)/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`]],mm=200,hm=e=>{let t=e.split(/\r?\n/).map(e=>fm.reduce((e,[t,n])=>e.replace(t,n),e)),n=pm.reduce((e,[t,n])=>e.replace(t,n),t.join(`
|
|
3
|
+
`)).replace(/\s+/g,` `).trim();return n.length>mm?`${n.slice(0,199).trimEnd()}…`:n},gm=(e,t)=>e.type===`text`&&!!t?.markdown,_m=(e,t,n)=>{let r=t[n];return e.fields[n]?.type===`relation`&&typeof r==`object`&&r&&`id`in r?r.id:r},vm=(e,t)=>e.primaryKey.map(n=>String(_m(e,t,n))).join(`,`),ym=(e,t)=>{let n=e.primaryKey.map(n=>_m(e,t,n));return n.length===1?n[0]:n},bm=new Set([`email`,`phone`,`url`]),xm=e=>e?.format!==void 0&&bm.has(e.format)?e.format:void 0,Sm=(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},Cm=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`}:{},wm=(e,t)=>{let n=String(t);return e&&Object.hasOwn(e,n)?e[n]:void 0},Tm=(e,t)=>{let n=wm(e,t);return n===void 0||Mn(n)?void 0:n},Em=(e,t)=>{let n=wm(e,t);return n!==void 0&&Mn(n)?n:`neutral`},Dm={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},Om=new Set([`datetime`,`date`,`boolean`,`percent`]),km=(e,t,n)=>{switch(e.type){case`relation`:return`relation`;case`file`:return`file`;case`enum`:return`status`;case`boolean`:return`boolean`;case`timestamp`:return`datetime`;case`date`:return`date`;case`decimal`:return t?.format===`percent`?`percent`:t?.currency===void 0?`number`:`money`;case`integer`:case`bigint`:return t?.format===`signed`?`signed`:`number`;default:return t?.format===`code`||n===0&&e.name===`id`?`id`:`text`}},Am=e=>Math.round(Number.parseFloat(String(e))*100),jm=(e,t,n=[],r=Tr(e,t))=>{let i=cr(e,t);return r.flatMap((r,a)=>{let o=e.fields[r];if(!o)return[];let s=t?.fields[r],c=km(o,s,a),l=Object.fromEntries((o.enumValues??[]).map(e=>[e,ir(e,s?.valueLabels)])),u=(c===`number`||c===`signed`)&&s?.prefix?s.prefix:void 0,d=Math.ceil(((u?.length??0)+(s?.suffix?.length??0))*7.2);return[{id:r,header:s?.label??F(r),kind:c,width:(r===`name`?260:Dm[c])+d,sortable:o.sortable,minWidth:Math.max(c===`id`?150:0,Jp(s?.label??F(r),o.sortable),c===`status`?Yp(Object.values(l)):0,d>0?Dm[c]+d:0),...Om.has(c)&&{fixed:!0},...r===i&&{title:!0},...c===`text`&&r!==i&&xm(s)&&{link:xm(s)},...n.includes(r)&&{highlight:!0},...o.type===`enum`&&{tones:Object.fromEntries((o.enumValues??[]).map(e=>[e,Em(s?.valueColors,e)])),labels:l},...o.type===`enum`&&s?.valueColors&&{colors:s.valueColors},...o.type===`enum`&&s?.badgeShape&&{shape:s.badgeShape},...u!==void 0&&{prefix:u},...s?.suffix!==void 0&&{suffix:s.suffix},...c===`datetime`&&s?.format===`relative`&&{relative:!0},...c===`money`&&s?.decimals!==void 0&&{decimals:s.decimals},...c===`money`&&s?.currency!==void 0&&{currency:s.currency,value:e=>e[r]==null?null:Am(e[r])},...(c===`datetime`||c===`date`)&&{value:e=>e[r]==null?null:Date.parse(String(e[r]))},...gm(o,s)&&{value:e=>typeof e[r]==`string`?hm(e[r]):e[r]},...(c===`percent`||c===`number`&&o.type===`decimal`)&&{value:e=>e[r]==null?null:Number(e[r])}}]})},Mm=(e,t)=>`${t.prefix??``}${e}${t.suffix??``}`,Nm=(e,t,n={},r=Gf(),i=Date.now())=>{if(t==null||t===``)return`—`;switch(e.type){case`boolean`:return Ap(t?`yes`:`no`);case`file`:return Np(t)?.name??`—`;case`enum`:return ir(String(t),n.valueLabels);case`timestamp`:{let e=Date.parse(String(t));return n.format===`relative`?Sp(Math.round((i-e)/1e3)):dp(e,r)}case`date`:return cp(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)}%`:Mm(Number(e).toLocaleString(Le(),{minimumFractionDigits:n.decimals??0,maximumFractionDigits:n.decimals??20}),n)}case`integer`:case`bigint`:return Mm(String(t),n);default:return typeof t==`object`?JSON.stringify(t):String(t)}},Pm=(e,t,n=Gf(),r={})=>{if(e.type!==`timestamp`||typeof t!=`string`)return;let i=Date.parse(t);if(!Number.isNaN(i))return r.format===`relative`?dp(i,n):Ap(`shownIn`,{zone:ep(i,n)})},Fm=`$photos`,Im=e=>{for(let t of e?.list?.displays??[])if(t.kind===`cards`&&t.photos)return t.photos},Lm=(e,t,n)=>{if(n===void 0||e.primaryKey.length!==1)return t;let r=e.primaryKey[0];return t.map(e=>({...e,[Fm]:n[String(e[r])]??[]}))},Rm=(e,t)=>t.filter(t=>e[t]!==null&&e[t]!==void 0&&e[t]!==``),K=M(`app/displays`),zm=(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:ir(e,i?.valueLabels)}));return r.nullable?[...a,{value:null,label:K(`noValue`,{label:i?.label??F(n.by)})}]:a},Bm=e=>e.position&&e.position.within===void 0?e.position.field:void 0,Vm=(e,t,n)=>{let r=Yt(n===null?cn.isNull(t):cn.eq(t,n));return e===``?r:`(${e}) AND ${r}`},Hm=(e,t,n)=>({kind:`cards`,name:n.name,title:n.title??cr(e,t),...n.subtitle!==void 0&&{subtitle:n.subtitle},...n.badge!==void 0&&{badge:n.badge},...n.meta&&{meta:n.meta}}),Um=e=>{if(!pl(e))return e instanceof Error?e.message:K(`somethingWrong`);let t=e.errors.map(e=>e.message);return t.length>0?t.join(`; `):e.message},Wm=e=>e?.list?.displays??[],Gm=(e,t,n)=>{let r=n??e?.list?.default??`table`;if(!t)return r;let i=Wm(e).filter(e=>e.kind===`cards`);return i.find(e=>e.name===r)?.name??i[0]?.name??r},Km=`rows`,qm=(e,t)=>{if(Wm(t).some(e=>e.kind===`cards`||e.name===`rows`))return;let n=cr(e,t),r=Tr(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:Km,label:K(`list`),icon:`list`,title:n,...i!==void 0&&{badge:i},footer:a}},Jm=(e,t)=>t.name===`rows`&&!Wm(e).some(e=>e.name===`rows`),Ym=(e,t,n)=>{let r=Gm(t,n);return n&&r===`table`&&qm(e,t)?Km:r},Xm=(e,t,n)=>(n===`rows`?qm(e,t):void 0)??Zm(t,n),Zm=(e,t)=>{if(t===`table`)return;let n=t=>Wm(e).find(e=>e.name===t);return n(t)??n(e?.list?.default)},Qm={cards:`cards`,map:`map`,board:`kanban`,calendar:`calendar`,timeline:`timeline`},$m=e=>[{name:yn,label:K(`table`),icon:`table`},...Wm(e).map(e=>({name:e.name,label:e.label??F(e.name),icon:e.icon??Qm[e.kind]}))],eh=(e,t,n)=>{let r=$m(t);return n&&qm(e,t)?[...r,{name:Km,label:K(`list`),icon:`list`}]:r},th=(e,t,n)=>({image:n.image,title:n.title??cr(e,t),subtitle:n.subtitle,amount:n.amount??[],badge:n.badge,meta:n.meta??[],footer:n.footer??[],flags:n.flags??[]}),nh=(e,t)=>Rm(e.record,t),rh=(e,t)=>nh(e,t)[0],ih=(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:Nm(e,t,n)}:{amount:Nm(e,t,i),suffix:r}},ah=(e,t)=>{let n=Wm(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}},oh=(e,t,n)=>{if(n.kind===`custom`)return n.fields;if(n.kind===`map`)return[n.latitude,n.longitude,...oh(e,t,ah(t,n))];if(n.kind===`board`){let r=Hm(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??cr(e,t)].filter(e=>e!==void 0);if(n.kind===`timeline`)return[n.start,n.end,n.group,n.title??cr(e,t)].filter(e=>e!==void 0);let{image:r,title:i,subtitle:a,amount:o,badge:s,meta:c,footer:l,flags:u}=th(e,t,n);return[r,i,a,...o,s,...c,...l,...u].filter(e=>e!==void 0)},sh=(e,t,n)=>{let r=qm(e,t),i=r?[...Wm(t),r]:Wm(t);return[...new Set([...n,...i.flatMap(n=>oh(e,t,n))])]},ch=(e,t,n)=>{let r=Jm(t,n)?[cr(e,t),...Tr(e,t)]:oh(e,t,n);return[...new Set(r)].filter(t=>e.fields[t]?.sortable)},lh=e=>typeof e==`object`&&!!e&&`id`in e&&`name`in e,uh=(e,t)=>{let n={},r={},i=Array.isArray(t.$photos)?t[Fm]:void 0;for(let[i,a]of Object.entries(t))(i!==`id`&&i!==`$photos`||Object.hasOwn(e.fields,i))&&(e.fields[i]?.type===`relation`&&lh(a)?(n[i]=a.id,r[i]=a.name):n[i]=a);return{key:Nn(ym(e,n)),record:n,labels:r,...i&&{photos:i}}},dh=(e,t)=>{let n=t?.list?.sort?.[0];if(n)return`${n[0]} ${n[1]}`;let r=e.primaryKey[0];return e.fields[r]?.sortable?`${r} asc`:``},fh=e=>{let[t=``,n]=e.trim().split(/\s+/);return{columnId:t,direction:n===`desc`?`desc`:`asc`}},ph=e=>`${e.columnId} ${e.direction}`,mh=(e,t,n,r)=>{let i=e[n],a=Cn(t[n],r),o=a?.listOf,s=o===void 0?void 0:i?.fields[o]?.relation?.resource;return s!==void 0&&e[s]?{model:e[s],view:t[s],listOf:!0}:{model:i,view:a,listOf:!1}},hh=(e,t,n=!1)=>({display:e?Ym(e,t,n):Gm(t,n),orderBy:e?dh(e,t):``,filterLayout:`bar`,filter:t?.list?.filter??``}),gh=(e,t)=>e?.kind===`record`?{kind:`record`,resource:e.resource,key:Nn(e.key),...e.edit&&{edit:!0},...e.open&&{open:e.open},...e.tab&&{tab:e.tab},...e.standard&&{standard:!0},...e.call&&{call:e.call}}:e?.kind===`list`?{...t(e.resource,e.list),...e}:e,_h=(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}}},vh=({className:e})=>(0,B.jsx)(`span`,{className:P(`block h-3 rounded bg-muted [animation:pb-shimmer_1.4s_ease-in-out_infinite]`,e)}),yh=M(`app-shell`),bh=e=>e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey,xh=({parts:e,onNavigate:t})=>(0,B.jsx)(`nav`,{"aria-label":yh(`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)(vh,{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)(Oi,{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&&bh(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}`)})}),Sh=({to:e,onClick:t,...n})=>{let{href:r,onFollow:i,newTab:a}=e;return(0,B.jsx)(`a`,{href:r,...a&&{target:`_blank`,rel:`noreferrer`},onClick:e=>{t?.(e),i&&!e.defaultPrevented&&bh(e)&&(e.preventDefault(),i())},...n})},q=M(`app`),Ch=`protobase:page-places`,wh=50,Th=e=>Array.isArray(e)&&e.length===2&&typeof e[0]==`string`&&typeof e[1]==`number`&&Number.isFinite(e[1])&&e[1]>=0,Eh=e=>Ie(()=>{let t=e.getItem(Ch);if(t===null)return[];let n=JSON.parse(t);return Array.isArray(n)?n.filter(Th):[]},[]),Dh=e=>{let t=new Map(Eh(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-wh)))t.delete(e)},persist:()=>Ie(()=>e.setItem(Ch,JSON.stringify([...t])),void 0)}},Oh=3e3,kh=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,Oh);return r.observe(document.body),window.addEventListener(`scroll`,i,{passive:!0}),a},Ah=(0,I.createContext)(null),jh=()=>{let e=(0,I.useContext)(Ah);if(!e)throw Error(`useRouter must be used inside Router`);return e},Mh=()=>`${window.location.pathname}${window.location.search}`,Nh=e=>new URL(e,`http://local`).pathname,Ph=()=>window.history.state??{},Fh=()=>Ph().protobaseIndex??0,Ih=()=>Math.random().toString(36).slice(2),Lh=()=>{let e=Ph();if(e.protobaseEntry)return e.protobaseEntry;let t=Ih();return window.history.replaceState({...e,protobaseEntry:t},``),t},Rh={getItem:()=>null,setItem:()=>{}},zh=({basePath:e=``,initialUrl:t,children:n})=>{let r=t!==void 0,[i,a]=(0,I.useState)(()=>({url:t??Mh(),entry:r?Ih():Lh()})),[o]=(0,I.useState)(()=>Dh(r?Rh:Ie(()=>window.sessionStorage,void 0)??Rh)),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:Fh()),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)(()=>kh(o.placeOf(i.entry)),[o,i.entry]),(0,I.useEffect)(()=>{if(r)return;window.history.scrollRestoration=`manual`,window.history.replaceState({...Ph(),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=Fh();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=Nh(Mh())!==Nh(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:Mh(),entry:Lh()})};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:Ih();if(!r){u.current+=+!t;let r=t?Ph().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(Nh(r)!==Nh(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:Ph().protobasePrevious;if(n!==void 0&&Nh(n)===Nh(`${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)(Ah.Provider,{value:T,children:[n,h?.kind===`reload`&&(0,B.jsx)(Cf,{title:q(`reloadTitle`),description:q(h.inputLost?`reloadInputLost`:`reloadDraftKept`),onClose:()=>g(void 0),actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:()=>g(void 0),children:q(`keepEditing`)}),(0,B.jsx)(G,{variant:`primary`,onClick:w,children:q(`reload`)})]})}),h&&h.kind!==`reload`&&(0,B.jsx)(Cf,{title:q(`leaveTitle`),description:q(h.inputLost?`leaveInputLost`:`leaveDescription`),onClose:()=>g(void 0),actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:()=>g(void 0),children:q(`stay`)}),(0,B.jsx)(G,{variant:`primary`,onClick:w,children:q(`leave`)})]})})]})},Bh=({to:e,replace:t,...n})=>{let{navigate:r,basePath:i}=jh();return(0,B.jsx)(Sh,{to:{href:`${i}${e}`,onFollow:()=>r(e,{replace:t})},...n})},Vh=(e,t=`draft-kept`)=>{let{registerGuard:n,reloadConfirmed:r}=jh();(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])},Hh=()=>{let{path:e,params:t,basePath:n,navigate:r,back:i}=jh(),{pages:a,resources:o,views:s}=W(),c=_f(),l=(0,I.useMemo)(()=>new Set(Object.keys(a)),[a]),u=t.toString(),d=(0,I.useMemo)(()=>Wc(u?`${e}?${u}`:e,l),[e,u,l]),f=(0,I.useCallback)((e,t)=>{let n=mh(o,s,e,t);return hh(n.model,n.view,c)},[o,s,c]),p=(0,I.useMemo)(()=>gh(d,f),[d,f]),m=(0,I.useCallback)((e,t)=>r(Bc(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 _h(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=>Bc(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])}},Uh=({to:e,...t})=>(0,B.jsx)(Bh,{to:Bc(e),...t}),Wh=`text-[16px] font-semibold text-foreground`,Gh=({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)(Uh,{to:n,replace:!0,"aria-expanded":t,"aria-controls":i,className:P(`inline-flex items-center gap-1.5`,Wh),children:[(0,B.jsx)(Oi,{className:P(`size-4 transition-transform`,t&&`rotate-90`)}),e]}):(0,B.jsx)(`span`,{className:Wh,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":Rf(`tabs`),className:`overflow-x-auto py-6`,children:(0,B.jsx)(`span`,{className:ze.group(`md`),children:e.map(e=>(0,B.jsx)(Uh,{to:e.to,replace:!0,"aria-current":e.current?`page`:void 0,className:P(ze.option(e.current,`md`),`whitespace-nowrap`),children:e.title},e.title))})}),qh=(0,I.createContext)(void 0),Jh=()=>{let e=(0,I.useContext)(qh);return e?{id:e.id,name:e.name,"aria-describedby":e.describedBy,"aria-invalid":e.invalid||void 0,"aria-required":e.required||void 0}:{}},Yh=({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:Rf(`savedDifferent`,{name:o.user.name}),children:[(0,B.jsx)(Ys,{className:`size-3.5`}),(0,B.jsx)(If,{initials:o.user.initials,hue:o.user.hue,size:`xs`})]})]}),(0,B.jsx)(qh,{value:{id:l,name:e,describedBy:u,invalid:!!a,required:!!n},children:c}),r&&(0,B.jsx)(`p`,{id:`${l}-help`,className:`mt-1.5 text-xs text-muted-foreground`,children:r}),i&&(0,B.jsxs)(`p`,{id:`${l}-example`,className:`mt-0.5 text-xs text-faint-foreground`,children:[Rf(`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}),` `,Rf(`savedThis`,{ago:o.ago}),` `,(0,B.jsx)(`strong`,{children:o.theirValue})]}),(0,B.jsxs)(`span`,{className:`flex gap-1.5`,children:[(0,B.jsx)(G,{size:`sm`,onClick:o.onKeepMine,children:Rf(`keepMine`)}),(0,B.jsx)(G,{size:`sm`,onClick:o.onUseTheirs,children:Rf(`useTheirs`)})]})]})]})},Xh=({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))}),Zh=({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))}),Qh=`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`,$h=({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:Rf(`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:Qh,children:c}):(0,B.jsx)(`button`,{type:`button`,onClick:r,disabled:!!i||a,title:i,className:Qh,children:c})},e)})})]}),eg=`flex w-full items-center gap-2 px-3 py-2.5 text-left hover:bg-muted disabled:cursor-default disabled:opacity-60`,tg=4,ng=(e,t,n)=>{let r=e.bottom+tg;return{top:r+t.height>window.innerHeight-tg?Math.max(tg,e.top-tg-t.height):r,right:Math.max(tg,Math.min(n-e.right,n-tg-t.width))}},rg=()=>{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(ng(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}},ig=({actions:e,label:t=Rf(`actions`),className:n})=>{let{open:r,setOpen:i,place:a,button:o,menu:s}=rg();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)(oa,{className:`size-5`})}),r&&(0,Sc.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)]})},ag=({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))}),og=({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]}),sg=({title:e,rows:t})=>t.length===0?null:(0,B.jsx)(og,{title:e,children:(0,B.jsx)(ag,{rows:t})}),cg=(e=Le())=>new Intl.NumberFormat(e).formatToParts(1.5).find(e=>e.type===`decimal`)?.value===`,`?`,`:`.`,lg=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),ug=(e,t)=>{let n=`[${lg(t===`.`?`,`:`.`)}\\s\\u00a0\\u202f']`,r=RegExp(`^([-+]?)(\\d{1,3}(?:${n}\\d{3})+|\\d+)(?:${lg(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()))},dg=e=>e==null?``:typeof e==`object`?JSON.stringify(e):String(e),fg=new Set([`text`,`integer`,`bigint`,`decimal`,`date`,`currency`,`country`]),pg=new Set([`uuid`,`timestamp`,`relation`]),mg=(e,t)=>e.readOnly||pg.has(e.type)?!1:e.type!==`json`||t?.widget!==void 0,hg=e=>!e.readOnly&&!e.nullable&&e.type!==`boolean`,gg=new Set([`integer`,`bigint`,`decimal`]),_g=e=>{try{return JSON.parse(e)}catch(t){if(t instanceof SyntaxError)return e;throw t}},vg=(e,t)=>ug(e,t)??e,yg=(e,t,n=cg())=>{if(e.type===`boolean`)return!!t;if(e.type===`file`)return Up(t);let r=String(t).trim();if(r===``)return e.nullable?null:``;let i=gg.has(e.type)?vg(r,n):r;if(e.type===`integer`)return Number(i);if(e.type===`relation`)return typeof t==`number`?t:i;if(fg.has(e.type)||e.type===`enum`)return i;if(e.type===`json`)return _g(i);throw Error(`Not implemented: editing ${e.type} fields`)},bg=(e,t,n=cg())=>e.type===`boolean`?!!t:String(t??``).trim()===``?null:yg(e,t,n),xg=(e,t)=>e.type===`boolean`?!!t:dg(t),Sg=(e,t,n,r=cg())=>{if(e.type===`boolean`)return!!t!=!!n;if(e.type===`file`)return Wp(t,n);let i=String(t??``).trim(),a=dg(n);return e.type===`decimal`||e.type===`integer`?i===``||a===``?i!==a:Number(vg(i,r))!==Number(a):i!==a},Cg=(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},wg=(e,t,n)=>(e??t?.helpWhen??`always`)===`always`||n,Tg=(e,t,n)=>e?.help!==void 0&&wg(e.helpWhen,t,n)?e.help:void 0,Eg=(e,t)=>e===`editing`?t:e!==`reading`||!t,Dg=M(`app/create`),Og=e=>typeof e==`object`&&!!e&&`key`in e,kg=(e,t,n)=>t.name!==e.tenant&&!t.readOnly&&(t.type===`relation`||mg(t,n)),Ag=(e,t)=>{let n=Object.values(e.fields).filter(n=>kg(e,n,t?.fields[n.name])).map(e=>e.name),r=new Set,i=Sn(t?.layout??[]).flatMap(e=>{if(e.kind!==`section`||kc(e.when)||!Eg(e.when,!0))return[];let i=e.fields.filter(e=>n.includes(e)&&!r.has(e)&&Eg(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?Dg(`details`):Dg(`otherFields`),fields:a}]},jg=(e,t)=>(e?.primaryKey.length===1?e.fields[e.primaryKey[0]]?.type:void 0)===`integer`?Number(t):t,Mg=(e,t,n)=>Object.fromEntries(Object.entries(n).flatMap(([n,r])=>{let i=e.fields[n];return i?Og(r)?[[n,jg(t[i.relation?.resource??``],r.key)]]:i.type===`boolean`?[[n,!!r]]:i.type===`file`?r?[[n,yg(i,r)]]:[]:String(r).trim()===``?[]:[[n,yg(i,r)]]:[]})),Ng=e=>!e.nullable&&!e.default&&e.type!==`boolean`,Pg=(e,t)=>e.type===`relation`?{key:t,label:t}:e.type===`boolean`?t===`true`:t,Fg=new Set([`integer`,`bigint`,`decimal`]),Ig=e=>{if(!Fg.has(e.type)||!e.default||!(`value`in e.default))return;let t=e.default.value;return t==null?void 0:String(t)},Lg=(e,t,n={})=>Object.fromEntries(t.flatMap(t=>t.fields.flatMap(t=>{let r=e.fields[t];if(Object.hasOwn(n,t))return[[t,Pg(r,n[t])]];let i=r.default;return Ig(r)!==void 0||!i||!(`value`in i)||i.value===null||i.value===void 0?[]:[[t,typeof i.value==`boolean`?i.value:dg(i.value)]]}))),Rg=e=>!!(e.default&&`db`in e.default),zg=e=>{if(!pl(e))return[{message:e instanceof Error?e.message:q(`somethingWentWrong`)}];let t=e.errors.map(e=>({message:e.message,hint:e.hint}));return t.length>0?t:[{message:e.message}]},Bg=({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}),zg(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))]})]}),Vg=({checked:e,onChange:t,label:n})=>{let r=Jh();return(0,B.jsx)(`button`,{type:`button`,role:`switch`,id:r.id,"aria-describedby":r[`aria-describedby`],"aria-checked":e,"aria-label":n,onClick:()=>t?.(!e),className:P(`relative inline-flex h-5 w-9 shrink-0 items-center rounded-full transition-colors`,e?`bg-primary`:`bg-border-strong`),children:(0,B.jsx)(`span`,{className:P(`size-4 rounded-full bg-white shadow transition-transform`,e?`translate-x-[18px]`:`translate-x-0.5`)})})},J=({leading:e,trailing:t,invalid:n,className:r,wrapperClassName:i,...a})=>{let o=Jh();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]})},Hg=e=>{e.style.height=`auto`,e.style.height=`${e.scrollHeight+e.offsetHeight-e.clientHeight}px`},Ug=({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=Jh();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})},Wg=(e,{filter:t,orderBy:n,pageSize:r=50,fields:i,labels:a,startToken:o=``,enabled:s=!0,refetchInterval:c}={})=>{let l=U(),u=el(t)??``,d=Ne({queryKey:[...H.list(e,u,n??``,r,o),i?.join(`,`)??``,...a?[a]:[]],enabled:s,refetchInterval:c,initialPageParam:o,queryFn:({pageParam:t})=>l.list(e,{filter:u,orderBy:n,pageSize:r,fields:i,labels:a,pageToken:t}),getNextPageParam:e=>e.nextPageToken||void 0}),f=d.data?.pages??[];return{...d,items:f.flatMap(e=>e.items),totalEstimate:f[0]?.totalSizeEstimate,labels:Object.fromEntries(Object.keys(a??{}).map(e=>[e,Object.assign({},...f.map(t=>t.labels?.[e]??{}))]))}},Gg=()=>{let[e,t]=(0,I.useState)(``),[n,r]=(0,I.useState)(!1);return{text:e,setText:t,open:n,setOpen:r}},Kg=(e,t,n,r)=>{(0,I.useEffect)(()=>{if(!e||!t||!r)return;let n=new IntersectionObserver(e=>e.some(e=>e.isIntersecting)&&r(),{root:e});return n.observe(t),()=>n.disconnect()},[e,t,n,r])},qg=({search:e,options:t,chosen:n,several:r,closedText:i,placeholder:a,invalid:o,paging:s,loading:c,failed:l,onChoose:u})=>{let{text:d,setText:f,open:p,setOpen:m}=e,[h,g]=(0,I.useState)(-1),[_,v]=(0,I.useState)(null),[y,b]=(0,I.useState)(null),x=(0,I.useId)(),S=s?.more??!1;Kg(_,y,s?.loaded??0,s?.loadMore);let C=e=>`${x}-${e}`,w=(0,I.useRef)(null);(0,I.useEffect)(()=>{!p&&document.activeElement===w.current&&w.current?.select()},[p]),(0,I.useEffect)(()=>{p&&h>=0&&document.getElementById(C(h))?.scrollIntoView({block:`nearest`})});let T=()=>{f(``),g(-1),m(!1)},E=e=>{if(u(e),!r)return T();f(``),g(-1)};return(0,B.jsxs)(`div`,{className:`relative`,children:[(0,B.jsx)(J,{ref:w,role:`combobox`,"aria-autocomplete":`list`,"aria-expanded":p,"aria-controls":x,"aria-activedescendant":p&&t[h]?C(h):void 0,invalid:o,placeholder:a,value:p?d:i,onFocus:()=>m(!0),onBlur:T,onKeyDown:e=>{if(e.key===`ArrowDown`||e.key===`ArrowUp`){if(e.preventDefault(),!p)return m(!0);let n=e.key===`ArrowDown`?1:-1;g(e=>Math.min(Math.max(e+n,0),t.length-1));return}if(e.key===`Enter`&&p&&t[h]){e.preventDefault(),E(t[h]);return}e.key===`Escape`&&p&&(e.preventDefault(),e.stopPropagation(),T())},onChange:e=>{f(e.target.value),g(e.target.value.trim()?0:-1),m(!0)}}),p&&(0,B.jsxs)(`ul`,{ref:v,id:x,role:`listbox`,"aria-multiselectable":r||void 0,className:`absolute z-30 mt-1 max-h-60 w-full overflow-y-auto rounded-md border bg-background py-1 shadow-pop`,onMouseDown:e=>e.preventDefault(),children:[t.map((e,t)=>(0,B.jsx)(`li`,{id:C(t),role:`option`,"aria-selected":t===h,className:P(`cursor-pointer truncate px-3 py-1.5`,t===h&&`bg-muted`,n.includes(e.key)&&`font-medium`),onMouseMove:()=>t!==h&&g(t),onClick:()=>E(e),children:e.label},e.key)),S&&(0,B.jsx)(`li`,{ref:b,"aria-hidden":!0,className:`h-px`}),l&&(0,B.jsx)(`li`,{className:`px-3 py-1.5 text-muted-foreground`,children:q(`couldNotLoadOptions`)}),!S&&!c&&!l&&t.length===0&&(0,B.jsx)(`li`,{className:`px-3 py-1.5 text-muted-foreground`,children:q(`noMatches`)}),c&&(0,B.jsx)(`li`,{className:`px-3 py-1.5 text-muted-foreground`,children:q(`loading`)})]})]})},Jg=sn(),Yg=e=>e.split(/\s+/).filter(Boolean),Xg=(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:Yt(Jg.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=>Jg.eq(t,`*${e.replaceAll(`*`,``)}*`));return{filter:Yt(Jg.and(...o)),local:!1}},Zg=(e,t)=>{if(e==null)return!1;let n=String(e).toLowerCase();return Yg(t).every(e=>n.includes(e.toLowerCase()))},Qg=15e3,$g=()=>{let e=Od();return Gd().data?.status&&e?.state.kind===`signed-in`?String(e.state.user.id):void 0},e_=()=>{let e=U(),t=$g();return E({queryKey:H.statuses(t??``),enabled:t!==void 0,refetchInterval:Qg,queryFn:()=>e.status.people()})},t_=()=>{let e=U(),t=$g();return E({queryKey:H.ownStatus(t??``),enabled:t!==void 0,refetchInterval:Qg,queryFn:()=>e.status.own()})},n_=(e,t=Date.now())=>e.isSuccess&&!e.isFetching&&t-e.dataUpdatedAt>=1e4,r_=(e,t)=>{let n=new Map(t.map(e=>[e.userId,e]));return e.map(e=>{let t=n.get(e.id);return t?{...e,status:t}:e})},i_=()=>{let e=Od(),t=e?.state.kind===`signed-in`?e.state.user:void 0,n=E({queryKey:H.members(t?.id??``),enabled:t!==void 0,queryFn:()=>{if(!e?.organizations)throw Error(`useMembers() needs organizations: turn them on in the auth config.`);return e.session.organizations.people()}}),r=e_().data,i=(0,I.useMemo)(()=>n.data&&(r?r_(n.data,r):n.data),[n.data,r]),a=(0,I.useMemo)(()=>new Map((i??[]).map(e=>[e.id,e])),[i]),{refetch:o}=n,s=(0,I.useCallback)(e=>{let t=a.get(e);return!t&&n_(n)&&setTimeout(()=>void o(),0),t},[a,n,o]);return{...n,data:i,member:s}},a_=e=>e,o_=e=>e,s_=(0,I.createContext)({}),c_=()=>(0,I.useContext)(s_),l_=(e,t)=>t?.titleFrom?.fields??[],u_=(e,t)=>(n,r,i,a)=>{let o=r?.titleFrom;if(!o)return lr(n,r,i,a);let s=e[o.rule];return!s||o.unreadable||o.fields.some(e=>i[e]===void 0)?a:s(i,t)||a},d_=()=>void 0,f_=(0,I.createContext)(u_({},{user:void 0,member:d_})),p_=()=>(0,I.useContext)(f_),m_=({rules:e,user:t,children:n})=>{let r=(0,I.useMemo)(()=>u_(e,{user:t,member:d_}),[e,t]);return(0,B.jsx)(f_.Provider,{value:r,children:n})},h_=({rules:e,user:t,children:n})=>{let{member:r}=i_(),i=(0,I.useMemo)(()=>u_(e,{user:t,member:r}),[e,t,r]);return(0,B.jsx)(f_.Provider,{value:i,children:n})},g_=({children:e})=>{let{views:t}=W(),{titles:n}=c_(),r=Od(),i=r?.state.kind===`signed-in`?r.state.user:void 0,a=n??{};return Object.values(t).some(e=>e.titleFrom!==void 0)&&i&&r?.organizations?(0,B.jsx)(h_,{rules:a,user:i,children:e}):(0,B.jsx)(m_,{rules:a,user:i,children:e})},__=({target:e,view:t,value:n,label:r,chosen:i=[n],several:a=!1,invalid:o,onChange:s})=>{let c=Gg(),l=e.primaryKey[0],u=sr(e,t),[d,f]=(0,I.useState)(!1),p=p_(),m=Xg(e,u,c.text,d||t?.titleFrom!==void 0&&!e.search?.length),h=[...new Set([l,u,...t?.titleFrom?.fields??[]])],g=n=>t?.titleFrom?p(e,t,n,String(n[l])):String(n[u]),_=Wg(e.name,{filter:m.filter,fields:h,enabled:c.open}),v=m.filter!==void 0&&_.error instanceof dl&&_.error.slug===`expensive-query`;(0,I.useEffect)(()=>{v&&f(!0)},[v]);let y=m.local?_.items.filter(e=>Zg(g(e),c.text)):_.items,{fetchNextPage:b}=_,x=(0,I.useCallback)(()=>b({cancelRefetch:!1}),[b]);return(0,B.jsx)(qg,{search:c,options:y.map(e=>({key:String(e[l]),label:g(e)})),chosen:i,several:a,closedText:r??n,placeholder:q(`searchPlural`,{plural:(t?.names?.plural??F(e.name)).toLowerCase()}),invalid:o,paging:{more:!!_.hasNextPage,loaded:_.items.length,loadMore:x},loading:_.isPending||_.isFetchingNextPage,failed:!!_.error&&!v,onChoose:e=>s(e.key,e.label)})},v_=(e,t)=>e.replace(/\D/g,``).slice(0,t),y_=(e,t,n)=>{let r=v_(t??``,n);return r.length===n?r:v_(e,n)},b_=(e,t,n,r)=>{let i=t.replace(/\D/g,``);return i.length>=r?i.slice(0,r):v_(e.slice(0,n)+i+e.slice(n+i.length),r)},x_=({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(y_(e.target.value,t??n?.getData(`text/plain`),r))},onPaste:e=>{if(p?.(e),e.defaultPrevented)return;e.preventDefault();let t=e.currentTarget,n=b_(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)}})]})},S_=M(`app/confirm-sign-in`),C_=({minutes:e,onConfirmed:t})=>{let n=Od(),[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":S_(`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:S_(`confirmTitle`)}),(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:S_(`confirmWhy`,{minutes:e})}),l&&l.passkeys>0&&(0,B.jsx)(G,{variant:`primary`,size:`sm`,className:`self-start`,loading:s.isPending,onClick:()=>s.mutate(),children:S_(`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:[S_(`authenticatorCode`),(0,B.jsx)(x_,{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:S_(`confirm`)})]}),l&&l.passkeys===0&&!l.authenticatorApp&&(0,B.jsx)(`p`,{children:S_(`nothingToConfirmWith`)}),u&&(0,B.jsx)(`p`,{role:`alert`,className:`font-medium text-danger-text`,children:u.message})]})},w_=`••••••••••`,T_=e=>pl(e)&&e.slug===`strong-sign-in-required`?e.problem.minutes??15:void 0,E_=({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=dg(n)!==``,p=t?.label??F(e.name),m=(0,B.jsx)(G,{variant:`ghost`,size:`sm`,className:`-mr-1.5 px-1.5`,"aria-label":q(l?`hide`:`show`,{label:p}),"aria-pressed":l,loading:d.isPending,onClick:()=>{l||f||!r||d.isSuccess?u(!l):d.mutate()},children:!d.isPending&&(l?(0,B.jsx)(fa,{className:`size-3.5`}):(0,B.jsx)(ma,{className:`size-3.5`}))}),h=T_(d.error),g=h===void 0?d.error&&(0,B.jsx)(`div`,{className:`mt-2`,children:(0,B.jsx)(Bg,{title:q(`couldNotShow`,{label:p}),error:d.error})}):(0,B.jsx)(C_,{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?Nm(e,d.data,t):w_}),r&&m]}),g]});let _=f?dg(n):l&&d.isSuccess?dg(d.data):``;return(0,B.jsxs)(`div`,{children:[(0,B.jsx)(J,{type:l?`text`:`password`,autoComplete:`off`,invalid:a,"aria-label":p,className:P(t?.format===`code`&&`font-mono text-xs`),placeholder:f||!r?s??(e.writeOnly?q(`setNewValue`):void 0):w_,value:_,trailing:m,onChange:e=>c(e.target.value)}),g]})},D_=(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`},O_=e=>URL.canParse(e)?[new URL(e).hostname]:[],k_=()=>{let e=(0,I.useContext)(Hd);return(0,I.useMemo)(()=>[...e?.files?.trustedHosts??[],...(e?.sources??[]).flatMap(({source:e})=>O_(e.url))],[e?.files,e?.sources])},A_=e=>{let t;try{t=atob(e)}catch(e){if(e instanceof DOMException&&e.name===`InvalidCharacterError`)return;throw e}return S(Uint8Array.from(t,e=>e.charCodeAt(0)))},j_=({image:e,alt:t=``,className:n,loading:r})=>{let[i,a]=(0,I.useState)(),o=k_(),s=(0,I.useMemo)(()=>e.placeholder===void 0?void 0:A_(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:D_(e.url,window.location.href,o),onLoad:()=>a(e.url),className:n,style:c?{backgroundImage:`url("${s}")`,backgroundSize:`cover`,backgroundPosition:`center`}:void 0})},M_=({value:e})=>{let t=Vp(e,{width:40,height:40});return t?(0,B.jsx)(j_,{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)(Sa,{className:`size-4`})})},N_=({value:e})=>{let t=Np(e);if(!t)return(0,B.jsx)(`div`,{className:`py-1.5 text-muted-foreground`,children:`—`});if(`missing`in t)return(0,B.jsx)(`div`,{className:`py-1.5 text-danger-text`,children:q(`fileMissing`)});let n=`url`in t?t.url:void 0,r=`corrected`in t?t.corrected:void 0;return(0,B.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3 py-1`,children:[(0,B.jsx)(M_,{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&&` · ${Fp(t.size)}`,r&&` · sent as ${r.from}`]})]})]})},P_=({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,...Ip(r.file.type)&&{preview:URL.createObjectURL(t)}}},onSuccess:e=>s(e),onSettled:()=>d(void 0)});if(i||e.readOnly)return(0,B.jsx)(N_,{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:Hp(e),"aria-label":q(`chooseFileFor`,{label:m}),onChange:e=>g(e.target.files)}),y=h.error&&(0,B.jsx)(`div`,{className:`mt-2`,children:(0,B.jsx)(Bg,{title:q(`notUploaded`),error:h.error})});return h.isPending?(0,B.jsxs)(`div`,{className:`py-1.5`,role:`status`,"aria-label":q(`uploadingLabel`,{label:m}),children:[(0,B.jsx)(`div`,{className:`h-1.5 overflow-hidden rounded-full bg-muted`,children:(0,B.jsx)(`div`,{className:`h-full rounded-full bg-primary transition-[width]`,style:{width:`${Math.round((u??0)*100)}%`}})}),(0,B.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:q(`uploading`,{percent:Math.round((u??0)*100)})})]}):Np(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)(N_,{value:r})}),(0,B.jsx)(G,{size:`sm`,onClick:()=>l.current?.click(),children:q(`replace`)}),e.nullable&&(0,B.jsx)(G,{size:`sm`,variant:`ghost`,onClick:()=>s(null),children:q(`remove`)})]}),v,y]}):(0,B.jsxs)(`div`,{children:[(0,B.jsxs)(`div`,{onDragOver:e=>{e.preventDefault(),p(!0)},onDragLeave:()=>p(!1),onDrop:_,className:P(`flex items-center gap-3 rounded-md border border-dashed px-3 py-2.5 text-muted-foreground`,f?`border-primary bg-primary/5`:a?`border-danger`:`border-border-strong`),children:[(0,B.jsx)(Zs,{className:`size-4 shrink-0`}),(0,B.jsx)(`span`,{className:`flex-1`,children:q(`dropFile`)}),(0,B.jsxs)(G,{size:`sm`,onClick:()=>l.current?.click(),children:[(0,B.jsx)(Fo,{className:`size-3.5`}),q(`chooseFile`)]})]}),v,y]})},F_=e=>[...e].reduce((e,t)=>(e*31+t.charCodeAt(0))%360,7),I_=e=>e.split(/[\s@.]+/).filter(Boolean).slice(0,2).map(e=>e[0].toUpperCase()).join(``),L_=e=>(e.role??`user`).split(`,`).map(e=>e.trim()),R_=e=>L_(e).includes(`admin`),z_=e=>dm(e.replace(/[_-]+/g,` `).trim()),B_=e=>{let t=L_(e),n=t.includes(`admin`);return{name:e.name||e.email,email:e.email,initials:I_(e.name||e.email)||`?`,hue:F_(e.id||e.email),role:n?z(`admin`):z_(t[0]??`user`),roleTone:n?`violet`:`blue`}},V_=M(`app/field-types/members`),H_=({id:e,name:t})=>(0,B.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-1.5`,children:[(0,B.jsx)(If,{initials:t&&I_(t)||`?`,hue:F_(e),size:`xs`,className:`ring-0`}),(0,B.jsx)(`span`,{className:t===void 0?`truncate text-muted-foreground`:`truncate`,children:t??V_(`unknownMember`)})]}),U_=e=>Array.isArray(e)?e.filter(e=>typeof e==`string`):[],W_=(e,t)=>e.includes(t)?e.filter(e=>e!==t):[...e,t],G_=(e,t)=>e.filter(e=>Zg(e.name,t)).map(e=>({key:e.id,label:e.name})),K_=()=>{let e=Od(),t=i_();return{...t,needsOrganizations:!e?.organizations,failed:t.isError}},q_=({value:e,line:t})=>{let n=K_(),r=U_(e);return r.length===0?(0,B.jsx)(`span`,{className:`text-muted-foreground`,children:`—`}):n.needsOrganizations?(0,B.jsx)(`span`,{className:`text-muted-foreground`,children:V_(`needsOrganizations`)}):n.failed?(0,B.jsx)(`span`,{className:`text-muted-foreground`,children:V_(`couldNotLoadMembers`)}):n.isLoading?(0,B.jsx)(vh,{className:`h-4 w-24`}):(0,B.jsx)(`span`,{className:P(`flex min-w-0 items-center gap-x-3 gap-y-1`,t?`overflow-hidden`:`flex-wrap`),children:r.map(e=>(0,B.jsx)(H_,{id:e,name:n.member(e)?.name},e))})},J_=e=>(0,B.jsx)(q_,{...e,line:!1}),Y_=e=>(0,B.jsx)(q_,{...e,line:!0}),X_=({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":Qd(`remove`,{label:e}),className:`rounded p-0.5 hover:bg-primary-border/60`,onMouseDown:e=>e.preventDefault(),onClick:t,children:(0,B.jsx)(yc,{className:`size-3`})})]}),Z_=({value:e,invalid:t,onChange:n})=>{let r=Gg(),i=K_(),a=U_(e);if(i.needsOrganizations)return(0,B.jsx)(`p`,{className:`py-1.5 text-muted-foreground`,children:V_(`needsOrganizations`)});let o=e=>i.member(e)?.name??V_(`unknownMember`);return(0,B.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,B.jsx)(qg,{search:r,options:G_(i.data??[],r.text),chosen:a,several:!0,closedText:``,placeholder:V_(`searchMembers`),invalid:t,loading:i.isLoading,failed:i.failed,onChoose:e=>n(W_(a,e.key))}),a.length>0&&(0,B.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:a.map(e=>(0,B.jsx)(X_,{label:o(e),onRemove:()=>n(a.filter(t=>t!==e))},e))})]})},Q_={members:{of:[...Er.members],display:J_,editor:Z_,cell:Y_}},$_=(e,t)=>{if(e&&Object.hasOwn(e,t))return e[t];if(Object.hasOwn(Q_,t))return Q_[t]},ev=(e,t,n)=>{let r=n?.widget;if(!r||t.sensitive)return;let i=$_(e,r.name);return i?.of.includes(t.type)?{name:r.name,widget:i,props:r.props??{}}:void 0},tv=(e,t)=>ev(c_().fields,e,t),nv,rv,iv=({dsn:e,environment:t})=>(nv??=Ve(()=>import(`./prod-YZ9ZMG1O.js`).then(n=>{n.init({dsn:e,...t&&{environment:t},integrations:e=>e.filter(e=>e.name!==`BrowserSession`),beforeSend:e=>Kn(e)}),rv=(e,t)=>n.captureException(e,t?{contexts:{react:{componentStack:t}}}:void 0)}),[]),nv),av=(e,t)=>rv?.(e,t??void 0),ov=({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}),sv=M(`app/pages`),cv=class extends I.Component{state={failed:!1};static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(e,t){av(e,t.componentStack)}render(){return this.state.failed?this.props.fallback===void 0?(0,B.jsx)(ov,{children:sv.rich(`couldNotDraw`,{name:this.props.name})}):this.props.fallback:this.props.children}},lv=M(`app/field-types`),uv=({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},dv=({fallback:e,...t})=>{let n=uv(t);return n?(0,B.jsx)(cv,{name:lv(`fieldType`,{name:t.shown.name}),fallback:e,children:n}):e},fv=(0,I.lazy)(()=>Ve(()=>import(`./markdown-content-DOuciTNH.js`).then(e=>({default:e.MarkdownContent})),__vite__mapDeps([0,1,2,3]))),pv=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)(fv,{...e})}),mv=M(`markdown`),hv=()=>[{value:`write`,label:mv(`write`)},{value:`preview`,label:mv(`preview`)}],gv=({value:e,onChange:t,label:n,invalid:r,placeholder:i})=>{let[a,o]=(0,I.useState)(`write`);return(0,B.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,B.jsx)(`span`,{className:`self-start`,children:(0,B.jsx)(Re,{value:a,options:hv(),onChange:o,label:n})}),a===`write`?(0,B.jsx)(Ug,{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:mv(`nothingToPreview`)}):(0,B.jsx)(pv,{source:e})})]})},_v=new Set([`integer`,`bigint`,`decimal`]),vv=e=>e===`integer`||e===`bigint`?{inputMode:`numeric`,enterKeyHint:`done`}:e===`decimal`?{inputMode:`decimal`,enterKeyHint:`done`}:{},yv=e=>e.stopPropagation(),bv=({format:e,value:t,className:n})=>{let r=Sm(e,t);return r?(0,B.jsx)(`a`,{href:r,...e===`url`?{target:`_blank`,rel:`noreferrer`}:{},onClick:yv,className:P(`font-medium text-primary-text hover:underline`,n),children:t}):(0,B.jsx)(`span`,{className:n,children:t})},xv=e=>typeof e==`object`&&e&&`key`in e?e.key:e,Sv=(e,t,n,r,i)=>t?.confirm!==void 0&&!Sg(e,n,r)&&Sg(e,xv(i),r),Cv=M(`app/change-confirm`),wv=e=>e instanceof Element&&e.closest(`[data-dialog="change-confirm"]`)!==null,Tv=({field:e,hints:t,value:n,stored:r,onChange:i})=>{let[a,o]=(0,I.useState)(),s=a=>{Sv(e,t,n,r,a)?o({next:a}):i(a)},c=()=>o(void 0);return{onChange:s,dialog:a&&(0,B.jsx)(Cf,{name:`change-confirm`,title:Cv(`title`,{label:t?.label??F(e.name)}),description:t?.confirm,onClose:c,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:c,children:Cv(`cancel`)}),(0,B.jsx)(G,{variant:`primary`,onClick:()=>{o(void 0),i(a.next)},children:Cv(`change`)})]})})}},Ev=({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=Jh();if(e.type===`file`)return(0,B.jsx)(P_,{field:e,hints:t,resource:d??``,value:n,locked:c||!d,invalid:s,onChange:f});if(e.sensitive)return(0,B.jsx)(E_,{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)(__,{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)(Uh,{to:a,"aria-label":q(`openLabel`,{label:i??String(n)}),title:q(`open`),className:P(mf({variant:`ghost`}),`w-8 px-0`),children:(0,B.jsx)(Hr,{className:`size-4`})})]}):e}if(e.type===`boolean`&&c)return(0,B.jsx)(`div`,{className:`py-1.5 text-muted-foreground`,children:Nm(e,r,t)});if(e.type===`boolean`)return(0,B.jsx)(Vg,{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)(Uh,{to:a,className:`font-medium text-primary-text hover:underline`,children:e}):e})}let m=!!t?.multiline&&e.type===`text`,h=gm(e,t);if((!mg(e)||c)&&h&&typeof r==`string`&&r!==``)return(0,B.jsx)(pv,{source:r,className:`py-1.5`});let g=e.type===`text`?xm(t):void 0;return(!mg(e)||c)&&g&&typeof r==`string`&&r!==``?(0,B.jsx)(`div`,{className:`min-w-0 break-words py-1.5`,children:(0,B.jsx)(bv,{format:g,value:r})}):!mg(e)||c?(0,B.jsx)(`div`,{title:Pm(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:Nm(e,r,t)}):e.type===`enum`?(0,B.jsxs)(`select`,{...p,...s&&{"aria-invalid":!0},value:String(n),onChange:e=>f(e.target.value),className:`h-8 w-full rounded-md border border-border-strong bg-background px-2 shadow-sm focus:border-primary focus:outline-none focus:ring-2 focus:ring-primary/20`,children:[n===``&&(0,B.jsx)(`option`,{value:``,children:q(`choose`)}),(e.enumValues??[]).map(e=>(0,B.jsx)(`option`,{value:e,children:ir(e,t?.valueLabels)},e))]}):h?(0,B.jsx)(gv,{label:t?.label??F(e.name),invalid:s,placeholder:l,value:String(n),onChange:f}):m?(0,B.jsx)(Ug,{invalid:s,placeholder:l,value:String(n),onChange:e=>f(e.target.value)}):(0,B.jsx)(J,{invalid:s,leading:t?.prefix?(0,B.jsx)(`span`,{children:t.prefix}):void 0,trailing:t?.suffix?(0,B.jsx)(`span`,{children:t.suffix.trim()}):void 0,placeholder:l,className:P(_v.has(e.type)&&`text-right tabular-nums`),...vv(e.type),...Cm(g),value:String(n),onChange:e=>f(e.target.value)})},Dv=e=>{let{field:t,hints:n,value:r,stored:i,invalid:a,locked:o,onChange:s}=e,c=tv(t,n),l=(0,B.jsx)(Ev,{...e});return c?o||!mg(t,n)?(0,B.jsx)(dv,{shown:c,part:`display`,field:t,value:i,fallback:l}):t.type===`file`||t.type===`relation`?l:(0,B.jsx)(dv,{shown:c,part:`editor`,field:t,value:bg(t,r),invalid:!!a,onChange:e=>s(xg(t,e)),fallback:l}):l},Ov=e=>{let t=Tv(e);return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(Dv,{...e,onChange:t.onChange}),t.dialog]})},kv={text:`text`,integer:`integer`,decimal:`decimal`,boolean:`boolean`,date:`date`},Av=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:kv[e.kind]}},jv=e=>({label:e.label,...e.multiline&&{multiline:!0},...e.options&&{valueLabels:Object.fromEntries(e.options.map(e=>[e.value,e.label]))}}),Mv=e=>Object.fromEntries(e.map(e=>e.kind===`custom`?[e.name,e.default??null]:e.kind===`boolean`?[e.name,!!e.default]:[e.name,dg(e.default)])),Nv=(e,t)=>e.kind===`custom`?t??null:Og(t)?t.key:e.resource===void 0?yg(Av(e),t):String(t??``)===``?null:String(t),Pv=(e,t)=>{let n=Object.fromEntries(e.map(e=>[e.name,Nv(e,t[e.name])])),r=On(e,n);return{shown:r,values:Object.fromEntries(Object.entries(n).filter(([e])=>r.has(e)))}},Fv=/^-?\d+(\.\d+)?$/,Iv=/^\d{4}-\d{2}-\d{2}$/,Lv=(e,t)=>{if(t===null||t===``)return e.required?sv(`required`):void 0;if(e.kind===`integer`&&!Number.isInteger(t))return sv(`wholeNumber`);if(e.kind===`decimal`&&!Fv.test(String(t)))return sv(`number`);if(e.kind===`date`&&!Iv.test(String(t)))return sv(`dateFormat`);if(e.max!==void 0&&String(t).length>e.max)return sv(`atMost`,{max:e.max})},Rv=(e,t)=>Object.fromEntries(e.flatMap(e=>{if(!Object.hasOwn(t,e.name))return[];let n=Lv(e,t[e.name]);return n?[[e.name,n]]:[]})),zv=class extends Error{errors;constructor(e){super(Object.values(e).join(`; `)),this.errors=e,this.name=`ActionInputError`}},Bv=(e,t)=>{let n=new Set(t.map(e=>e.name)),r=e instanceof zv?Object.entries(e.errors):pl(e)?e.errors.flatMap(e=>e.field?[[e.field,e.message]]:[]):[];return Object.fromEntries(r.filter(([e])=>n.has(e)))},Vv=({input:e,held:t,invalid:n,onChange:r})=>{let{resources:i,views:a}=W(),{components:o}=c_();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)(Ov,{field:Av(e),hints:jv(e),value:Og(t)?t.key:t,stored:void 0,relationLabel:Og(t)?t.label:void 0,relationPicker:s?{target:s,view:a[s.name]}:void 0,invalid:n,onChange:r})},Hv=({action:e,label:t,danger:n,onCancel:r,onSubmit:i})=>{let[a,o]=(0,I.useState)(()=>Mv(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}=Pv(e.inputs,a),g=async()=>{let t=Rv(e.inputs,h);c(t),u(void 0),!(Object.keys(t).length>0)&&(f(!0),await i(h).catch(t=>{c(Bv(t,e.inputs)),u(t)}),f(!1))},_=(e,t)=>{c(({[e]:t,...n})=>n),o(n=>({...n,[e]:t}))};return(0,B.jsx)(Ef,{title:t,description:e.confirm,open:!0,onClose:r,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:r,children:sv(`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)(Bg,{title:sv(`failed`,{label:t}),error:l}),e.inputs.filter(e=>m.has(e.name)).map(e=>(0,B.jsx)(Yh,{label:e.label,required:e.required,help:e.help,error:s[e.name],children:(0,B.jsx)(Vv,{input:e,held:a[e.name],invalid:!!s[e.name],onChange:t=>_(e.name,t)})},e.name))]})})},Uv=({action:e,label:t,danger:n,onCancel:r,onConfirm:i})=>(0,B.jsx)(Cf,{title:`${t}?`,description:e.confirm,onClose:r,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:r,children:sv(`cancel`)}),(0,B.jsx)(G,{variant:n?`danger`:`primary`,onClick:i,children:t})]})}),Wv=e=>e.variant===`danger`||e.run?.kind===`delete`,Gv=e=>!!(e.confirm||e.inputs?.length),Kv=({action:e,label:t,danger:n,onCancel:r,onConfirm:i,onSubmit:a})=>{let{inputs:o}=e;return o?.length?(0,B.jsx)(Hv,{action:{...e,inputs:o},label:t,danger:n,onCancel:r,onSubmit:a}):(0,B.jsx)(Uv,{action:e,label:t,danger:n,onCancel:r,onConfirm:i})},qv=(0,I.createContext)(void 0),Jv=({value:e,children:t})=>(0,B.jsx)(qv.Provider,{value:e,children:t}),Yv=()=>(0,I.useContext)(qv),Xv=M(`toasts`),Zv=`-my-0.5 rounded px-1.5 py-0.5 font-medium text-primary-text hover:bg-primary-soft`,Qv=({action:e})=>{if(`onClick`in e)return(0,B.jsx)(`button`,{type:`button`,onClick:e.onClick,className:Zv,children:e.label});let{href:t,onNavigate:n}=e;return(0,B.jsx)(`a`,{href:t,onClick:e=>{n&&bh(e)&&(e.preventDefault(),n(t))},className:Zv,children:e.label})},$v={loading:(0,B.jsx)($d,{className:`text-primary`}),success:(0,B.jsx)(Pi,{className:`size-4 text-success`}),warning:(0,B.jsx)(Ys,{className:`size-4 text-warning`}),error:(0,B.jsx)(Bi,{className:`size-4 text-danger`}),info:(0,B.jsx)(rs,{className:`size-4 text-primary`}),call:(0,B.jsx)(zo,{className:`size-4 animate-pulse text-success`})},ey=({state:e,title:t,description:n,action:r,actions:i=[],onDismiss:a})=>(0,B.jsxs)(`div`,{role:e===`error`||e===`call`?`alert`:`status`,className:P(`flex w-full max-w-80 items-start gap-3 rounded-lg border bg-background p-3 shadow-pop [animation:pb-slide-in_160ms_ease-out]`,e===`warning`&&`border-warning/40`,e===`error`&&`border-danger/40`),children:[(0,B.jsx)(`span`,{className:`mt-0.5`,children:$v[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)(Qv,{action:r}),i.map(e=>(0,B.jsx)(Qv,{action:e},e.label)),a&&(0,B.jsx)(`button`,{type:`button`,"aria-label":Xv(`dismiss`),onClick:a,className:`inline-flex items-center justify-center rounded p-0.5 text-faint-foreground hover:bg-muted hover:text-foreground pointer-coarse:size-9`,children:(0,B.jsx)(yc,{className:`size-3.5`})})]}),ty={loading:1/0,success:3500,warning:8e3,error:8e3,info:8e3,call:1/0},ny=8e3,ry=(0,I.createContext)(null),iy=()=>{let e=(0,I.useContext)(ry);if(!e)throw Error(`useToast must be used inside ToastProvider`);return e},ay=({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?ny:ty[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)(ry.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)(ey,{state:e.state,title:e.title,description:e.description,action:e.action,...e.actions&&{actions:e.actions},onDismiss:()=>c(e)})},e.id))})]})},oy=(e,t)=>e[t]||e.conditional.includes(t),sy=(e,t)=>e.permissions?.[t]??!0,cy=(e,t)=>e?.fields?e.fields[t]??`hidden`:`edit`,ly=(e,t)=>{if(e.when===void 0)return!0;if(!t)return!1;let n=mu(e.when);return n.ok&&hu(n,t)},uy=(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]))),dy=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},fy=(e,t={})=>{let n=hn(e);return n===void 0?uy(e,t):dy(t[n])},py=e=>{e!==void 0&&(/^https?:/i.test(e)?window.open(e,`_blank`,`noopener,noreferrer`):window.location.assign(e))},my=e=>URL.canParse(e)?new URL(e).hostname.replace(/^www\./,``):``,hy=(e,t)=>Object.entries(t).every(([t,n])=>Object.is(e[t],n)),gy=(e,t)=>{if(!ly(e,t))return e.otherwise===`disable`?e:void 0;let n=e.run;if(n?.kind===`update`)return t&&!e.inputs?.length&&hy(t,n.values)?void 0:e;if(n?.kind!==`link`||!(`href`in n))return e;let r=fy(n.href,t);if(r!==void 0)return e.label.includes(`{host}`)?{...e,label:e.label.replaceAll(`{host}`,my(r))}:e},_y=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},vy=(e,t)=>({model:e,record:t,key:Nn(ym(e,t)),etag:typeof t.etag==`string`?t.etag:void 0,permissions:t.permissions}),yy=(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}}),by=(e,t=``)=>E(yy(U(),e,t)),xy=(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{...vy(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]?vy(e,a.items[0]):null}})},Sy=(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})})},Cy=()=>{let e=Se();return(0,I.useCallback)(t=>e.invalidateQueries({predicate:e=>e.queryKey[1]===t}),[e])},wy=e=>e instanceof Error?e.message:sv(`somethingWrong`),Ty=(e,t,n)=>{let{views:r}=W(),{actions:i,components:a}=c_(),o=af(e),s=U(),c=Ld(e),l=iy(),u=Cy(),{go:d}=Hh(),[f,p]=(0,I.useState)(),m=(r[e]?.actions??[]).flatMap(e=>gy(e,t?.record)??[]),h=(e,t)=>{let n=e.run?.kind;if((n===`update`||n===`delete`||n===`ai`)&&!t)return sv(`needsRecord`);if(!ly(e,t?.record))return e.reason??sv(`doesNotApply`);if((n===`update`||n===`ai`)&&(!oy(o,`update`)||t?.permissions?.update===!1)||e.run?.kind===`ai`&&t?.permissions?.fields?.[e.run.writes]===`read`)return sv(`cannotChange`);if(n===`delete`&&(!oy(o,`delete`)||t?.permissions?.delete===!1))return sv(`cannotDelete`);if(!e.run&&!i?.[e.name])return sv(`noHandler`,{name:e.name});let r=e.inputs?.find(e=>e.kind===`custom`&&!a?.[e.component??``]);if(r)return sv(`noInputComponent`,{component:String(r.component),input:r.name})},g=e=>h(e,t),_=async(t,n,r)=>{let{run:a}=t;if(a?.kind===`link`){`to`in a?d(mn(a.to,n?.record)):py(fy(a.href,n?.record));return}a?.kind===`update`?await s.update(e,n.key,kn(a.values,r??{}),n.etag??`*`):a?.kind===`delete`?await s.remove(e,n.key,{etag:n.etag}):a?.kind===`ai`?await s.generate(e,n.key,t.name):await i[t.name]({resource:e,record:n?.record,recordKey:n?.key,etag:n?.etag,client:c,navigate:d,...r&&{values:r}})},v=async(t,r,i)=>{await _(t,r,i),t.run?.kind!==`link`&&(await u(e),l.show({state:`success`,title:sv(`done`,{label:t.label})}),n?.(t))},y=async(e,n=t)=>{h(e,n)||(p(e.name),await v(e,n).catch(t=>l.show({state:`error`,title:sv(`failed`,{label:e.label}),description:wy(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)=>gy(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 _y(r,e=>x(t,e),e=>_(t,e));p(void 0),await u(e);let o=sv(`doneOn`,{label:t.label,done:a.done,skipped:a.skipped+i,failed:a.failed});l.show(a.failed>0?{state:`error`,title:o,description:wy(a.error)}:{state:`success`,title:o}),a.done>0&&n?.(t)}}},Ey=(e,t,n)=>{let r=Ty(e,n),i=r.actions.find(e=>e.name===t);return{action:i,blocked:i?r.blocked(i):sv(`noAction`,{name:t}),running:r.running===t,run:()=>i?r.run(i):Promise.resolve(),submit:e=>i?r.submit(i,e):Promise.resolve()}},Dy=e=>e.props,Oy=({name:e,resource:t,label:n,variant:r})=>{let i=Yv(),a=Ey(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:()=>Gv(a.action)?s(!0):void a.run(),children:c}),o&&(0,B.jsx)(Kv,{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)}})]})},ky=({node:e})=>(0,B.jsx)(Oy,{...Dy(e)}),Ay=({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})]}),jy=({children:e})=>(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:e}),My=({node:e,children:t,slots:n})=>{let{title:r,description:i}=Dy(e);return(0,B.jsx)(Ay,{title:r,description:i,actions:n.actions,className:`h-full`,children:(0,B.jsx)(`div`,{className:`flex flex-col gap-3`,children:t})})},Ny=({model:e,filter:t,sort:n,limit:r=12,title:i,description:a,empty:o,actions:s,children:c})=>{let l=Sy(e,{filter:t,sort:n,pageSize:r}),u=l.data?.items??[];return(0,B.jsx)(Ay,{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)(vh,{className:`h-24 w-56`},t))}):l.error?(0,B.jsx)(Bg,{title:sv(`couldNotLoad`),error:l.error}):u.length===0?(0,B.jsx)(jy,{children:o??sv(`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=vy(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)(Jv,{value:n,children:c})},n.key)})})})},Py=({node:e,children:t,slots:n})=>{let{resource:r,...i}=Dy(e),a=W().resources[r];return a?(0,B.jsx)(Ny,{...i,model:a,actions:n.actions,children:t}):null},Fy=(e,t,n,r=!0)=>{let i=U(),a=el(n)??``;return E({queryKey:H.facets(e,t,a),enabled:r,queryFn:()=>i.facets(e,t,{filter:a,limit:50})})},Iy=(e,t,n=!0)=>{let r=U(),i=el(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})})},Ly=(e,t,n,r=20,i=!0)=>{let a=U(),o=el(n)??``;return E({queryKey:H.histogram(e,t,r,o),enabled:i,queryFn:()=>a.histogram(e,t,{filter:o,buckets:r})})},Ry=(e,t,n=!0)=>{let r=U(),i={...t,filter:el(t.filter)??``};return E({queryKey:H.aggregate(e,JSON.stringify(i)),enabled:n,queryFn:()=>r.aggregate(e,i)})},zy=(e,t,n=!0)=>{let r=U();return f({queries:t.map(t=>{let i={...t,filter:el(t.filter)??``};return{queryKey:H.aggregate(e,JSON.stringify(i)),enabled:n,queryFn:()=>r.aggregate(e,i)}})})},By=M(`app/charts`),Vy=sn(),Hy=e=>e>=0&&e<8?`var(--chart-${e+1})`:`var(--faint-foreground)`,Uy=(e,t,n,r)=>{let i=String(n);if(n===null)return`var(--faint-foreground)`;let a=Tm(t?.valueColors,n);return a===void 0?e.type===`enum`?Hy(e.enumValues?.indexOf(i)??-1):e.type===`boolean`?Hy(+!n):Hy(r):a},Wy=(e,t,n)=>n.value===null?By(`notSet`):e.type===`enum`?ir(String(n.value),t?.valueLabels):e.type===`boolean`?n.value?By(`yes`):By(`no`):n.label??String(n.value),Gy=(e,t,n=``)=>{let r=Yt(t===null?Vy.isNull(e.name):Vy.eq(e.name,t));return n.trim()?`(${n}) AND ${r}`:r},Ky=(e,t)=>t.kind===`count`?e.count:e[t.kind]??null,qy=(e,t,n,r,i=``)=>e.map((e,a)=>({key:String(e.value),label:Wy(t,n,e),value:Ky(e,r),count:e.count,color:Uy(t,n,e.value,a),filter:Gy(t,e.value,i)})),Jy=(e,t)=>e.map(e=>({at:Date.parse(`${String(e.value)}Z`),value:Ky(e,t),count:e.count})),Yy=(e,t)=>{if(e===null)return`—`;if(t.kind===`count`)return e.toLocaleString(Le());let n=t.hints?.decimals??(Number.isInteger(e)?0:2),r=e.toLocaleString(Le(),{minimumFractionDigits:n,maximumFractionDigits:n});return`${t.hints?.prefix??``}${r}${t.hints?.suffix??``}`},Xy=(e,t,n)=>n?{kind:`list`,resource:t,filter:n}:e?.list?.filter?{kind:`list`,resource:t,filter:``}:{kind:`list`,resource:t},Zy=({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)(Uh,{to:Xy(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:By(`records`,{count:Yy(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:Yy(n.value,r)})]})},n.key)})})},Qy=`flex items-center gap-2 rounded-md px-1 py-0.5`,$y=({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:Qy,children:o}):(0,B.jsx)(Uh,{to:Xy(t,e,n),className:`group ${Qy} hover:bg-muted`,children:o})})},eb=(e,t)=>t>0?`${Math.round(e/t*100)}%`:``,tb=({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:Yy(r.value,n)})]})},nb=({resource:e,view:t,slices:n,measure:r})=>{let i=n.filter(e=>e.value!==null&&e.value>0),a=i.reduce((e,t)=>e+t.value,0);return(0,B.jsxs)(`div`,{className:`flex flex-col items-center gap-4 sm:flex-row sm:items-center`,children:[(0,B.jsx)(`div`,{className:`size-36 shrink-0`,children:(0,B.jsx)(g,{width:`100%`,height:`100%`,children:(0,B.jsxs)(l,{children:[(0,B.jsx)(b,{data:i,dataKey:`value`,nameKey:`label`,innerRadius:`62%`,outerRadius:`100%`,paddingAngle:+(i.length>1),stroke:`var(--background)`,strokeWidth:2,isAnimationActive:!1,children:i.map(e=>(0,B.jsx)(u,{fill:e.color},e.key))}),(0,B.jsx)(p,{content:(0,B.jsx)(tb,{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)($y,{resource:e,view:t,filter:n.filter,color:n.color,label:n.label,children:[(0,B.jsx)(`span`,{className:`font-medium tabular-nums`,children:Yy(n.value,r)}),(0,B.jsx)(`span`,{className:`w-9 text-right text-xs text-muted-foreground tabular-nums`,children:eb(n.value??0,a)})]},n.key))})]})},rb={hour:`2-digit`,minute:`2-digit`,hour12:!1},ib={day:`numeric`,month:`short`,...rb},ab={minute:rb,"5_minutes":rb,"15_minutes":rb,hour:rb,day:{day:`numeric`,month:`short`},week:{day:`numeric`,month:`short`},month:{month:`short`,year:`2-digit`},year:{year:`numeric`}},ob={minute:ib,"5_minutes":ib,"15_minutes":ib,hour:ib,day:{day:`numeric`,month:`short`,year:`numeric`},week:{day:`numeric`,month:`short`,year:`numeric`},month:{month:`long`,year:`numeric`},year:{year:`numeric`}},sb=e=>{let t=new Intl.DateTimeFormat(Le(),{...e,timeZone:`UTC`});return e=>t.format(e)},cb={fontSize:11,fill:`var(--muted-foreground)`},lb=864e5,ub=new Set([`minute`,`5_minutes`,`15_minutes`,`hour`]),db=(e,t)=>{let n=t.length>1?t.at(-1).at-t[0].at:0;return ub.has(e)&&n>=lb?ib:ab[e]},fb=({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`?By(`weekOf`,{day:sb(ob[r])(a.at)}):sb(ob[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:Yy(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:Yy(a.value,n)}),!i&&(0,B.jsx)(`div`,{className:`font-semibold tabular-nums`,children:Yy(a.value,n)})]})},pb=({points:e,measure:t,bucket:n,type:r,series:i,resource:o,view:s})=>{let l=hf(`(min-width: 640px)`),u=sb(db(n,e)),d=(0,B.jsx)(v,{vertical:!1,stroke:`var(--border)`}),f=(0,B.jsx)(a,{dataKey:`at`,tickFormatter:u,tick:cb,axisLine:!1,tickLine:!1,minTickGap:l?24:40,height:18}),m=(0,B.jsx)(pe,{width:l?48:36,tick:cb,axisLine:!1,tickLine:!1,tickCount:3,tickFormatter:e=>e.toLocaleString(Le(),{notation:`compact`})}),h=(0,B.jsx)(p,{cursor:r===`bar`?{fill:`var(--muted)`}:{stroke:`var(--border-strong)`},content:(0,B.jsx)(fb,{measure:t,bucket:n,...i&&{series:i}}),isAnimationActive:!1}),b=i??[{key:`value`,label:``,color:`var(--chart-1)`}],x=(0,B.jsx)(`div`,{className:`h-40`,children:(0,B.jsx)(g,{width:`100%`,height:`100%`,children:r===`line`?(0,B.jsxs)(y,{data:e,margin:{top:6,right:6,bottom:0,left:0},children:[d,f,m,h,b.map(t=>(0,B.jsx)(_,{dataKey:t.key,stroke:t.color,strokeWidth:2,dot:e.length<=31&&{r:3,fill:t.color,strokeWidth:0},activeDot:{r:4,stroke:`var(--background)`,strokeWidth:2},isAnimationActive:!1},t.key))]}):(0,B.jsxs)(c,{data:e,margin:{top:6,right:0,bottom:0,left:0},barCategoryGap:`22%`,children:[d,f,m,h,b.map((e,t)=>(0,B.jsx)(fe,{dataKey:e.key,fill:e.color,...i&&{stackId:`split`},radius:t===b.length-1?[4,4,0,0]:0,isAnimationActive:!1},e.key))]})})});return!i||o===void 0?x:(0,B.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[x,(0,B.jsx)(`ul`,{className:`flex flex-wrap gap-x-3 gap-y-0.5 text-sm`,children:i.map(e=>(0,B.jsx)($y,{resource:o,view:s,color:e.color,label:e.label,...e.filter!==void 0&&{filter:e.filter}},e.key))})]})},mb=1e-6,hb=(e,t,n,r,i,a=``)=>{let o=t.map((e,t)=>({key:`s${t}`,label:Wy(n,r,e),color:Uy(n,r,e.value,t),filter:Gy(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=Jy(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<mb?0:l}});return i.kind!==`average`&&l.some(e=>(e.other??0)>0)?{series:[...o,{key:`other`,label:By(`other`),color:`var(--border-strong)`}],points:l}:{series:o,points:l.map(({other:e,...t})=>t)}},gb=(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]}},_b=(e,t,n)=>{let r=e?.type===`relation`&&e.relation?t[e.relation.resource]:void 0;return r&&r.primaryKey.length===1?sr(r,n[r.name]):void 0},vb=({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=By(`nothingYet`)})=>{let{resources:f,views:p}=W(),m=e.fields[n],h=m?.type===`date`||m?.type===`timestamp`,g=_b(m,f,p),_=h&&r!==void 0?e.fields[r]:void 0,v=_b(_,f,p),y=_?{splitBy:_.name,splitLimit:8,...v&&{splitLabel:v}}:{},b=h?{granularity:c,range:l,timeZone:Gf(),...y}:{limit:u,...g&&{label:g}},x=Ry(e.name,{groupBy:n,filter:s,...a&&{sum:a},...o&&{average:o},...b},!!m),S=gb(e,t,a,o);if(!m)return null;if(x.isPending)return(0,B.jsx)(vh,{className:`h-36 w-full`});if(x.error)return(0,B.jsx)(`p`,{className:`text-danger-text`,children:By(`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}=hb(C,x.data.splits,_,t?.fields[_.name],S,s);return(0,B.jsx)(pb,{points:r,measure:S,bucket:c,type:w,series:n,resource:e.name,view:t})}if(h)return(0,B.jsx)(pb,{points:Jy(C,S),measure:S,bucket:c,type:w});let T=qy(C,m,t?.fields[n],S,s);return i===`donut`?(0,B.jsx)(nb,{resource:e.name,view:t,slices:T,measure:S}):(0,B.jsx)(Zy,{resource:e.name,view:t,slices:T,measure:S})},yb=({node:e,slots:t})=>{let{resource:n,title:r,description:i,actions:a,span:o,...s}=Dy(e),{resources:c,views:l}=W(),u=c[n];return u?(0,B.jsx)(Ay,{title:r,description:i,actions:t.actions,className:`h-full`,children:(0,B.jsx)(vb,{model:u,view:l[n],...s})}):null},bb=sn(),xb=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=sr(n,i),c=await e.fetchQuery({queryKey:H.labels(n.name,o.join(`,`)),staleTime:3e5,queryFn:async()=>(await t.list(n.name,{filter:Yt(bb.in(a,o)),fields:[a,s],pageSize:o.length})).items.map(e=>[String(e[a]),String(e[s])])});return new Map(c)},Sb=(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}]:[]}),Cb=(e,t,n,r)=>Object.fromEntries(Sb(e,n,r).filter(({target:e})=>e.primaryKey.length===1&&!t[e.name]?.titleFrom).map(({name:e,target:n})=>[e,sr(n,t[n.name])])),wb=(e,t,n,r,i={})=>{let a=Sb(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})},Tb=sn(),Eb=(e,t)=>{let n=t?.titleFrom;if(n&&!n.unreadable&&e.primaryKey.length===1)return n.fields},Db=(e,t,n)=>H.titleRow(e.name,t,n.join(`,`)),Ob=async(e,t,n,r)=>{let i=t.primaryKey[0],a=[...new Set(r)];if(a.length===0)return new Map;let o=await e.list(t.name,{filter:Yt(Tb.in(i,a)),fields:[i,...n],pageSize:a.length});return new Map(o.items.map(e=>[String(e[i]),e]))},kb=async(e,t,n,r,i,a,o)=>{let s=new Map;for(let e of a){let t=i.fields[e],a=t?.type===`relation`&&t.relation?n[t.relation.resource]:void 0;if(!a||!Eb(a,r[a.name]))continue;let c=o.flatMap(t=>t[e]==null?[]:[String(t[e])]);s.set(a.name,[...s.get(a.name)??[],...c])}await Promise.all([...s].map(async([i,a])=>{let o=n[i],s=Eb(o,r[i]),c=await Ob(t,o,s,a);for(let t of new Set(a))e.setQueryData(Db(o,t,s),{row:c.get(t)??null})}))},Ab=(e,t,n,r,i)=>{let a=r?.titleFrom;return a?{queryKey:Db(n,i,a.fields),queryFn:async()=>({row:(await Ob(t,n,a.fields,[i])).get(i)??null})}:{queryKey:H.relatedLabel(n.name,i),queryFn:async()=>({label:(await xb(e,t,n,[i],r)).get(i)??i})}},jb=(e,t,n,r,i)=>{if(e)return`label`in e?e.label:e.row?t(n,r,e.row,i):i},Mb=(e,t,n=!0)=>{let{views:r}=W(),i=U(),a=Se(),o=p_(),s=r[e.name];return jb(E({...Ab(a,i,e,s,t),staleTime:3e5,enabled:n}).data,o,e,s,t)},Nb=({value:e,hints:t,children:n})=>(0,B.jsx)(Pf,{tone:Em(t?.valueColors,e),color:Tm(t?.valueColors,e),shape:t?.badgeShape,children:n}),Pb=({target:e,id:t,known:n})=>{let r=Mb(e,t,n===void 0);return(0,B.jsx)(Uh,{to:{kind:`record`,resource:e.name,key:t},className:`font-medium text-primary-text hover:underline`,children:n??r??t})},Fb=({field:e,value:t,known:n})=>{let{resources:r}=W(),i=e.relation?r[e.relation.resource]:void 0;return i?(0,B.jsx)(Pb,{target:i,id:String(t),known:n}):(0,B.jsx)(`span`,{children:String(t)})},Ib=({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)(Fb,{field:t,value:n,known:i});let s=t.type===`file`?Np(n):void 0;if(s&&`url`in s&&s.url){let e=Vp(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)(j_,{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(gm(t,o))return(0,B.jsx)(pv,{source:String(n)});let c=Nm(t,n,o),l=t.type===`text`?xm(o):void 0;return l?(0,B.jsx)(bv,{format:l,value:c}):t.type===`enum`||o.format===`badge`?(0,B.jsx)(Nb,{value:n,hints:o,children:c}):(0,B.jsx)(`span`,{title:Pm(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})},Lb=e=>{let{views:t}=W(),n=tv(e.field,t[e.model.name]?.fields[e.field.name]),r=(0,B.jsx)(Ib,{...e});return n?(0,B.jsx)(dv,{shown:n,part:`display`,field:e.field,value:e.value,fallback:r}):r},Rb=(e,t,n)=>{if(!t)return[];let r=vu(e,t.model.name,n);return r.ok?r.steps:[]},zb=(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}}),Bb=(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}},Vb=(e,t)=>{let{resources:n}=W(),r=Rb(n,e,t);return Bb(e,r,E(zb(U(),Se(),e,t,r)))},Hb=(e,t)=>{let{resources:n}=W(),r=U(),i=Se(),a=t.map(t=>Rb(n,e,t)),o=f({queries:t.map((t,n)=>zb(r,i,e,t,a[n]))});return t.map((t,n)=>Bb(e,a[n],o[n]))},Ub=(e,t)=>{if(t)return t;let n=e.split(`.`).map(e=>F(e).toLowerCase()).join(` `);return n[0].toUpperCase()+n.slice(1)},Wb=({node:e})=>{let{name:t,label:n,format:r}=Dy(e),{views:i}=W(),a=Vb(Yv(),t);if(a.state===`missing`)return null;let o=a.state===`loading`?(0,B.jsx)(vh,{className:`h-4 w-24`}):(0,B.jsx)(Lb,{model:a.model,field:a.field,value:a.value,format:r});if(n===!1)return(0,B.jsx)(`div`,{children:o});let s=n??Ub(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})]})},Gb={1:``,2:`md:grid-cols-2`,3:`md:grid-cols-2 xl:grid-cols-3`,4:`sm:grid-cols-2 xl:grid-cols-4`},Kb={1:``,2:`grid-cols-2`,3:`grid-cols-2 xl:grid-cols-3`,4:`grid-cols-2 xl:grid-cols-4`},qb={1:``,2:`md:col-span-2`,3:`md:col-span-2 xl:col-span-3`,4:`sm:col-span-2 md:col-span-2 xl:col-span-4`},Jb=e=>typeof e==`object`&&!e.custom&&e.type===`Stat`,Yb=({node:e,children:t})=>{let{columns:n=2}=Dy(e),r=e.children,i=r.length>0&&r.every(Jb);return(0,B.jsx)(`div`,{className:P(`grid grid-cols-1 gap-4`,i?Kb[n]:Gb[n]),children:t.map((e,t)=>{let n=r[t],i=typeof n==`object`?n.props.span:void 0;return(0,B.jsx)(`div`,{className:P(`min-w-0`,i&&qb[i]),children:e},t)})})},Xb=`font-medium text-primary-text hover:underline`,Zb=({node:e})=>{let t=Dy(e),n=Yv()?.record,r=e.children.filter(e=>typeof e==`string`).join(``);if(t.to){let e=mn(t.to,n);return(0,B.jsx)(Uh,{to:e,className:Xb,children:r||Bc(e)})}let i=t.href??``;return(0,B.jsx)(`a`,{href:i,className:Xb,...i.startsWith(`http`)&&{target:`_blank`,rel:`noreferrer`},children:r||i})},Qb=M(`app/field`),$b=(e,t)=>typeof e?.[t]==`number`?e[t]:void 0,ex=(e,t)=>{let n=$b(t,`min`),r=$b(t,`max`);if(n!==void 0)return Qb(`atLeastCharacters`,{label:e,count:wp(n),n});if(r!==void 0)return Qb(`atMostCharacters`,{label:e,count:wp(r),n:r})},tx=e=>{let t=$b(e,`min`),n=$b(e,`max`);return t===void 0?n===void 0?Qb(`wholeNumber`):Qb(`wholeNumberAtMost`,{max:wp(n)}):Qb(`wholeNumberAtLeast`,{min:wp(t)})},nx=e=>{let t=$b(e,`precision`),n=$b(e,`scale`);if(t===void 0||n===void 0)return Qb(`number`);let r=wp(10**(t-n));return n===0?Qb(`wholeNumberBelow`,{below:r}):Qb(`decimalsBelow`,{scale:n,below:r})},rx={text:ex,integer:(e,t)=>tx(t),bigint:()=>Qb(`wholeNumber`),decimal:(e,t)=>nx(t),date:()=>Qb(`date`),timestamp:()=>Qb(`timestamp`),country:()=>Qb(`country`),currency:()=>Qb(`currency`),uuid:()=>Qb(`uuid`),enum:()=>Qb(`enum`),relation:()=>Qb(`relation`),json:()=>Qb(`json`)},ix=(e,t,n)=>n.code===`required`?Qb(`required`,{label:t}):n.code!==`invalid-value`||!e?n.message:rx[e.type]?.(t,n.params)??n.message,ax=e=>{if(!pl(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},ox=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?Qb(`checkField`):Qb(`checkFields`,{count:t.size})],...n].join(` `)},sx=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},cx=(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]:dg(n[t])];let i=r.default&&`value`in r.default?r.default.value:void 0;return[t,r.type===`boolean`?!!i:dg(i)]})),lx=(e,t,n)=>Object.fromEntries(Object.entries(t).flatMap(([t,r])=>{let i=e.fields[t];return Og(r)?r.key===dg(n[t])?[]:[[t,i.type===`integer`?Number(r.key):r.key]]:Sg(i,r,n[t])?[[t,yg(i,r)]]:[]})),ux=({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=iy(),f=Cy(),p=l[e.name],[m,h]=(0,I.useState)(()=>cx(e,a,t?.record)),[g,_]=(0,I.useState)({}),[v,y]=(0,I.useState)(0),b=sx(v),[x,S]=(0,I.useState)(),[C,w]=(0,I.useState)(!1),[T,E]=(0,I.useState)(!1);Vh(T||C,`input-lost`);let D=async()=>{w(!0),S(void 0),await(n===`create`?u.create(e.name,{...Mg(e,c,m),...o}):u.update(e.name,t.key,lx(e,m,t.record),t.etag??`*`)).then(async()=>{await f(e.name),d.show({state:`success`,title:sv(`saved`,{label:i??r})}),s()},e=>{let t=ax(e);_(t),Object.keys(t).length>0&&y(e=>e+1),S(e)}),w(!1)};return(0,B.jsx)(Cf,{title:i??r,onClose:s,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:s,children:sv(`cancel`)}),(0,B.jsx)(G,{variant:`primary`,loading:C,onClick:()=>void D(),children:sv(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)(Bg,{title:sv(`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)(Yh,{name:n,label:o,help:p?.fields[n]?.help,error:s&&ix(r,o,s),children:(0,B.jsx)(Ov,{field:r,hints:p?.fields[n],value:Og(i)?i.key:i,stored:t?.record[n],relationLabel:Og(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)})]})})},dx=({model:e,recordKey:t,children:n})=>{let r=xy(e,{key:t});return(0,B.jsx)(B.Fragment,{children:n(r.data??void 0)})},fx=({node:e})=>{let t=Dy(e),n=Yv(),{resources:r}=W(),i=r[t.resource??n?.model.name??``],a=af(i?.name??``),[o,s]=(0,I.useState)(!1);if(!i||!(t.mode===`create`?oy(a,`create`):oy(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)(ux,{...t,model:i,record:t.mode===`edit`?e:void 0,onClose:()=>s(!1)})]});return t.mode===`edit`&&t.recordKey!==void 0?(0,B.jsx)(dx,{model:i,recordKey:t.recordKey,children:c}):c(t.mode===`edit`?n:void 0)},px=e=>e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey,mx=`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`,hx=({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":yh(`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&&px(n)&&(n.preventDefault(),t(e.href))},className:P(mx,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(mx,s?`text-primary-text`:`text-muted-foreground`),children:[(0,B.jsx)(ca,{className:`size-6`,strokeWidth:s?2.2:1.9,"aria-hidden":!0}),yh(`more`)]})]})]})},gx=({id:e,open:t,onClose:n,children:r})=>{let i=(0,I.useRef)(null);return Sf(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":yh(`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},_x=(0,I.createContext)(()=>{}),vx=e=>{let t=(0,I.useContext)(_x);(0,I.useLayoutEffect)(()=>(t(e),()=>t(void 0)),[t,e])},yx=e=>{(0,I.useLayoutEffect)(()=>{if(!e)return;let t=document.documentElement;return t.style.setProperty(`scrollbar-gutter`,`stable`),()=>{t.style.removeProperty(`scrollbar-gutter`)}},[e])},bx=[`--pb-sticky-top`,`--pb-sticky-bottom`,`scroll-padding-top`,`scroll-padding-bottom`],xx=(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 bx)r.style.removeProperty(e)}},[e,t,n,r])},Sx=`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`,Cx=`fill-[#ff5a1f] dark:fill-[#ff6a33]`,wx=`fill-[#14161a] dark:fill-[#f1f0ea]`,Tx=({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:Cx,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:wx,d:`M17 0h10a5 5 0 0 1 5 5v22a5 5 0 0 1-5 5H5a5 5 0 0 1-5-5V17h17z`})]}),Ex=({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:wx,d:Sx})}),Dx=`Protobase`,Ox=({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)(Tx,{}),!e&&(0,B.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-0.5 leading-tight`,children:[r||n&&n!==Dx?(0,B.jsx)(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:n??Dx}):(0,B.jsx)(Ex,{className:`self-start`}),t&&(0,B.jsx)(`div`,{className:`truncate text-[11px] text-muted-foreground`,children:t})]})]}),kx=({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)(Si,{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))]}),Ax=()=>[{value:`light`,label:yh(`light`),icon:Fs},{value:`dark`,label:yh(`dark`),icon:ko},{value:`system`,label:yh(`system`),icon:Do}],jx=({theme:e,className:t})=>(0,B.jsxs)(`div`,{className:t,children:[(0,B.jsx)(Ns,{className:`size-4`}),(0,B.jsx)(`span`,{className:`flex-1`,children:yh(`theme`)}),(0,B.jsx)(Re,{label:yh(`theme`),iconOnly:!0,value:e.preference,options:Ax(),onChange:e.onChange})]}),Mx=`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`,Nx=({user:e,compact:t,open:n,items:r=[],account:i,onNavigate:a,onSignOut:o,organizations:s,roles:c,theme:l,status:u})=>{let d=c?.roles.find(e=>e.name===c.active),[f,p]=(0,I.useState)(!1),m=n??f,h=(0,I.useRef)(null),[g,_]=(0,I.useState)();(0,I.useEffect)(()=>{if(!m||n!==void 0)return;let e=e=>{(e instanceof KeyboardEvent?e.key===`Escape`:!h.current?.contains(e.target))&&p(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,e),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,e)}},[m,n]);let v=r.filter(e=>e.length>0),y=(e,t,n)=>{p(!1),!n&&a&&(e.preventDefault(),a(t))};return(0,B.jsxs)(`div`,{ref:h,className:`relative`,children:[(0,B.jsxs)(`button`,{type:`button`,className:`flex min-h-11 w-full items-center gap-2.5 rounded-md p-1 text-left hover:bg-muted md:min-h-0`,"aria-label":yh(`profileMenu`),"aria-haspopup":`menu`,"aria-expanded":m,onClick:()=>{let e=h.current?.getBoundingClientRect();e&&_({left:e.left,bottom:window.innerHeight-e.top+8}),p(!f)},children:[(0,B.jsx)(If,{initials:e.initials,hue:e.hue,size:`md`,className:`ring-0`}),!t&&(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(`span`,{className:`min-w-0 flex-1 leading-tight`,children:[u?.mark?(0,B.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1`,children:[(0,B.jsx)(`span`,{className:`truncate font-medium`,children:e.name}),u.mark]}):(0,B.jsx)(`span`,{className:`block truncate font-medium`,children:e.name}),(0,B.jsx)(Pf,{tone:e.roleTone,dot:!1,className:`mt-0.5 h-4 px-1.5 text-[10px]`,children:e.role})]}),(0,B.jsx)(Ai,{className:`size-3.5 shrink-0 text-faint-foreground`})]})]}),m&&(0,B.jsxs)(`div`,{role:`menu`,className:n===void 0?`fixed z-[60] w-56 overflow-hidden rounded-lg border bg-background py-1 shadow-pop`:`absolute bottom-full left-0 z-50 mb-2 w-56 overflow-hidden rounded-lg border bg-background py-1 shadow-pop`,style:n===void 0&&g?{left:g.left,bottom:g.bottom}:void 0,children:[i?(0,B.jsxs)(`a`,{role:`menuitem`,href:i,onClick:e=>y(e,i),className:`block border-b px-3 pb-2 pt-1.5 hover:bg-muted`,children:[(0,B.jsx)(`div`,{className:`font-medium`,children:e.name}),(0,B.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,children:e.email})]}):(0,B.jsxs)(`div`,{className:`border-b px-3 pb-2 pt-1.5`,children:[(0,B.jsx)(`div`,{className:`font-medium`,children:e.name}),(0,B.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,children:e.email})]}),u&&(0,B.jsx)(`div`,{className:`border-b py-1`,children:(0,B.jsxs)(`button`,{type:`button`,role:`menuitem`,className:Mx,onClick:()=>{p(!1),u.onOpen()},children:[(0,B.jsx)(ga,{className:`size-4 shrink-0`}),(0,B.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:u.label})]})}),s&&(s.current||s.others.length>0)&&(0,B.jsx)(kx,{label:yh(`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:Mx,onSwitch:e=>{p(!1),s.onSwitch(e)}}),c&&c.roles.length>1&&(0,B.jsx)(kx,{label:yh(`roles`),...d&&{current:{id:d.name,label:d.label}},others:c.roles.filter(e=>e!==d).map(({name:e,label:t})=>({id:e,label:t})),rowClassName:Mx,onSwitch:e=>{p(!1),c.onSwitch(e)}}),v.map((e,t)=>(0,B.jsx)(`div`,{role:`group`,className:P(`py-1`,(t<v.length-1||l||o)&&`border-b`),children:e.map(e=>{let t=e.icon;return(0,B.jsxs)(`a`,{role:`menuitem`,href:e.href,"aria-current":e.active?`page`:void 0,...e.external?{target:`_blank`,rel:`noreferrer`}:{},onClick:t=>y(t,e.href,e.external),className:P(Mx,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)(jx,{theme:l,className:P(Mx,`hover:bg-transparent`)})}),o&&(0,B.jsxs)(`button`,{type:`button`,role:`menuitem`,onClick:o,className:Mx,children:[(0,B.jsx)(oo,{className:`size-4`}),yh(`signOut`)]})]})]})},Px={"text-large":`h-8 gap-2.5 px-2.5`,"text-small":`h-7 gap-2 px-2 text-body`},Fx={"text-large":`ml-[20px]`,"text-small":`ml-[17px]`},Ix=({create:e,mode:t,onNavigate:n})=>(0,B.jsx)(`div`,{className:P(`border-l border-transparent pl-1.5`,Fx[t]),children:(0,B.jsxs)(`a`,{href:e.href,onClick:n&&(t=>{t.preventDefault(),n(e.href)}),className:P(`flex items-center rounded-md text-faint-foreground transition-colors hover:bg-muted hover:text-foreground`,Px[t]),children:[(0,B.jsx)(qo,{"aria-hidden":!0,className:`size-3.5 shrink-0`}),(0,B.jsx)(`span`,{className:`truncate`,children:e.label})]})}),Lx=`protobase:nav-open:`,Rx=e=>`${Lx}${e}`,zx=(e,t)=>Ie(()=>e.getItem(t)!==`false`,!0),Bx=(e,t,n)=>Ie(()=>n?e.removeItem(t):e.setItem(t,`false`),void 0),Vx=({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})]}),Hx=e=>e===`text-large`||e===`text-small`||e===`icon-expand`,Ux=e=>e===`text-large`||e===`text-small`,Wx={"text-large":`w-60`,"text-small":`w-52`,icon:`w-14`,"icon-label":`w-[76px]`,"icon-tooltip":`w-14`,"icon-expand":`w-14`},Gx={"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`},Kx=({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`,Gx[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}),(Hx(t)||t===`icon-label`)&&(0,B.jsx)(`span`,{className:`whitespace-nowrap`,children:e.label}),Ux(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}),Ux(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)(Vx,{label:e.label,children:o}):o},qx=99,Jx=e=>e===void 0||e<=0?void 0:e>qx?`${qx}+`:String(e),Yx=({count:e,className:t})=>{let n=Jx(e);return n?(0,B.jsx)(Pf,{tone:`red`,dot:!1,className:P(`h-4 min-w-4 justify-center px-1 text-[10px] font-semibold`,t),children:n}):null},Xx={neutral:`bg-faint-foreground`,info:`bg-primary`,success:`bg-success`,warning:`bg-warning`,danger:`bg-danger`},Zx=({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`,Xx[e])}),(0,B.jsx)(`span`,{className:P(`relative size-2 rounded-full`,Xx[e])})]}),Qx=M(`status`),$x=({presence:e})=>{let t=Qx(e);return(0,B.jsx)(`span`,{role:`img`,"aria-label":t,title:t,className:`flex shrink-0`,children:(0,B.jsx)(Zx,{tone:e===`online`?`success`:`neutral`})})},eS=e=>Qx(e===`busy`?`busy`:e===`do_not_disturb`?`doNotDisturb`:`automatic`),tS=({availability:e,title:t})=>{if(e===`automatic`)return null;let n=eS(e);return(0,B.jsx)(e===`busy`?Wi:Ri,{role:`img`,"aria-label":n,className:P(`size-3.5 shrink-0`,e===`busy`?`text-warning`:`text-danger`),children:(0,B.jsx)(`title`,{children:t??n})})},nS=({status:e,presence:t,textShown:n=`full`,className:r})=>{let i=wr(e);if(!i&&!t)return null;let a=i?.text??void 0;return(0,B.jsxs)(`span`,{className:P(`inline-flex min-w-0 items-center gap-1 text-muted-foreground`,r),title:a,children:[t&&(0,B.jsx)($x,{presence:t}),i&&(0,B.jsx)(tS,{availability:i.availability,...n===`hover`&&a&&{title:a}}),i&&n===`hover`&&i.availability===`automatic`&&a&&(0,B.jsx)(`span`,{role:`img`,"aria-label":a,className:`size-1.5 shrink-0 rounded-full bg-faint-foreground`}),a&&n===`full`&&(0,B.jsx)(`span`,{className:`truncate text-xs`,children:a})]})},rS=(e,t)=>e.map(e=>{let n=t&&Object.hasOwn(t,e.id)?t[e.id]:void 0;return n?{...e,mark:n}:e}),iS=e=>{if(!e)return[];let t=wr(e.status);return[e.presence&&Qx(e.presence),t&&t.availability!==`automatic`?eS(t.availability):void 0,t?.text??void 0]},aS=e=>{let t=[e.status?.label,...iS(e.mark?.person),e.mark?.label].filter(e=>e!==void 0&&e!==``);return{ariaLabel:[e.label,...t].join(`, `),title:t.length===0?e.label:`${e.label} (${t.join(`, `)})`}},oS=({records:e,mode:t,onNavigate:n})=>e.map(e=>{let{ariaLabel:r,title:i}=aS(e),a=n&&(t=>{t.preventDefault(),n(e.href)}),o=e.mark?.strong===!0;return(0,B.jsx)(`li`,{children:(0,B.jsxs)(`a`,{href:e.href,onClick:a,"aria-label":r,title:i,"aria-current":e.active?`page`:void 0,className:P(`flex min-w-0 items-center rounded-md transition-colors`,Px[t],o?`font-bold`:`font-medium`,e.active||o?`text-foreground`:`text-muted-foreground`,e.active?`bg-muted`:`hover:bg-muted hover:text-foreground`),children:[e.status&&(0,B.jsx)(Zx,{tone:e.status.tone,pulse:e.status.pulse}),(0,B.jsx)(`span`,{className:`truncate`,children:e.label}),e.mark?.person&&(0,B.jsx)(nS,{...e.mark.person,textShown:`hover`,className:`ml-1.5 shrink-0`}),(0,B.jsx)(Yx,{count:e.mark?.count,className:`ml-auto shrink-0`})]})},e.id)}),sS=({records:e,useMarks:t,...n})=>(0,B.jsx)(oS,{records:rS(e,t()),...n}),cS=({records:e,useMarks:t,mode:n,onNavigate:r})=>t?(0,B.jsx)(sS,{records:e,useMarks:t,mode:n,onNavigate:r}):(0,B.jsx)(oS,{records:e,mode:n,onNavigate:r}),lS=({item:e,recent:t,mode:n,active:r,onNavigate:i})=>{let a=Rx(e.id),[o,s]=(0,I.useState)(()=>zx(localStorage,a)),c=(0,I.useId)(),l=e.href??`#${e.id}`;return(0,B.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,B.jsxs)(`div`,{className:`relative`,children:[(0,B.jsx)(Kx,{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":yh(`recent`,{plural:e.label.toLowerCase()}),onClick:()=>{Bx(localStorage,a,!o),s(!o)},className:`absolute right-1 top-1/2 inline-flex size-6 -translate-y-1/2 items-center justify-center rounded text-faint-foreground hover:bg-muted hover:text-foreground`,children:(0,B.jsx)(Oi,{className:P(`size-3.5 transition-transform`,o&&`rotate-90`)})})]}),o&&(0,B.jsxs)(`ul`,{id:c,"aria-label":yh(`recent`,{plural:e.label.toLowerCase()}),className:P(`flex flex-col gap-0.5 border-l pl-1.5`,Fx[n]),children:[t.state===`loading`&&(0,B.jsx)(`li`,{className:P(`flex items-center text-faint-foreground`,Px[n]),children:yh(`loading`)}),t.state===`error`&&(0,B.jsx)(`li`,{className:P(`flex items-center text-faint-foreground`,Px[n]),children:yh(`couldNotLoad`)}),t.state===`ready`&&(0,B.jsx)(cS,{records:t.records,useMarks:t.useMarks,mode:n,onNavigate:i}),(0,B.jsx)(`li`,{children:(0,B.jsx)(`a`,{...(e=>({href:e,onClick:i&&(t=>{t.preventDefault(),i(e)})}))(l),className:P(`flex items-center rounded-md text-faint-foreground transition-colors hover:bg-muted hover:text-foreground`,Px[n]),children:yh(`viewAll`)})})]})]})},uS=({mode:e,activeItem:t,user:n,workspace:r,appName:i,appIcon:a,forceExpanded:o,profileMenuOpen:s,groups:c=[],userMenu:l,account:u,onNavigate:d,onSignOut:f,signIn:p,organizations:m,roles:h,theme:g,status:_,sticky:v,logo:y=Ox,notice:b})=>{let x=e===`icon-expand`,S=x&&o,C=Ux(e)||x;return(0,B.jsx)(`nav`,{"aria-label":yh(`resources`),className:P(v?`sticky top-0 h-dvh self-start`:`relative`,`z-30 shrink-0`,Wx[e]),children:(0,B.jsxs)(`div`,{className:P(`group/side absolute inset-y-0 left-0 flex flex-col overflow-hidden border-r bg-sidebar pb-[var(--pb-safe-bottom)] pt-[var(--pb-safe-top)]`,x?`w-14 transition-[width,box-shadow] duration-150 hover:w-60 hover:shadow-pop focus-within:w-60 focus-within:shadow-pop`:`w-full`,S&&`w-60 shadow-pop`),children:[(0,B.jsx)(`div`,{className:P(`flex h-12 shrink-0 items-center px-3.5`,e===`icon-label`&&`justify-center px-0`),children:(0,B.jsx)(y,{compact:!C,workspace:r,appName:i,appIcon:a})}),(0,B.jsx)(`div`,{className:P(`flex-1 overflow-y-auto overflow-x-hidden pb-2`,`px-2`),children:c.map((n,r)=>(0,B.jsxs)(`div`,{className:P(`flex flex-col gap-0.5`,r>0&&`mt-3`),children:[C?n.label&&(0,B.jsx)(`div`,{className:P(`px-3 pb-1 pt-1 text-xs font-medium uppercase tracking-wide text-faint-foreground`,x&&`h-4 whitespace-nowrap py-0 opacity-0 transition-opacity group-hover/side:opacity-100 group-focus-within/side:opacity-100`,S&&`opacity-100`),children:n.label}):r>0&&(0,B.jsx)(`div`,{className:`mx-auto mb-1 h-px w-6 bg-border`}),n.items.map(n=>(0,B.jsxs)(I.Fragment,{children:[n.recent&&Ux(e)?(0,B.jsx)(lS,{item:n,recent:n.recent,mode:e,active:n.id===t,onNavigate:d}):(0,B.jsx)(Kx,{item:n,mode:e,active:n.id===t,onNavigate:d}),n.create&&Ux(e)&&(0,B.jsx)(Ix,{create:n.create,mode:e,onNavigate:d})]},n.id))]},n.label))}),b,(0,B.jsx)(`div`,{className:P(`shrink-0 border-t p-2`,e!==`text-large`&&e!==`text-small`&&!x&&`flex justify-center`),children:n?(0,B.jsx)(Nx,{user:n,compact:!C,open:s,items:l,account:u,onNavigate:d,onSignOut:f,organizations:m,roles:h,theme:g,status:_}):(0,B.jsxs)(B.Fragment,{children:[g&&C&&(0,B.jsx)(jx,{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)(Sh,{to:p,"aria-label":yh(`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)(io,{className:`size-4 shrink-0`}),C&&(0,B.jsx)(`span`,{className:`whitespace-nowrap`,children:yh(`signIn`)})]})]})})]})})},dS=e=>gf()&&Ux(e),fS=(0,I.createContext)(null),pS=()=>(0,I.useContext)(fS),mS=e=>{let t=e.at(-2);if(typeof t==`object`&&t.href&&!t.loading)return{label:t.label,href:t.href}},hS=({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}),gS=(e,t,n)=>t===0?-1:e<0?n===1?0:t-1:(e+n+t)%t,_S=e=>e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||e.button!==0,vS=({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=>gS(e,d.length,t.key===`ArrowDown`?1:-1));else if(t.key===`Enter`){let e=d[l]??d[0];if(!e)return;t.preventDefault(),h(e.href)}else t.key===`Escape`&&(e.text?e.onTextChange(``):t.currentTarget.blur(),u(-1))},v=-1;return(0,B.jsxs)(`div`,{className:P(`relative`,t),children:[(0,B.jsx)(J,{ref:m,wrapperClassName:`w-full bg-surface shadow-none`,leading:e.loading?(0,B.jsx)($d,{className:`size-4`}):(0,B.jsx)(ss,{className:`size-4`}),trailing:e.text?(0,B.jsx)(`button`,{type:`button`,"aria-label":yh(`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)(yc,{className:`size-3.5`})}):r?(0,B.jsx)(`span`,{className:`hidden md:inline-flex`,children:(0,B.jsx)(hS,{children:`⌘K`})}):void 0,placeholder:e.placeholder,"aria-label":yh(`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":yh(`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?yh(`searching`):yh(`noMatches`,{query:e.query})}),e.groups.map(e=>(0,B.jsxs)(`div`,{role:`group`,"aria-label":e.label,children:[(0,B.jsx)(`div`,{className:`px-3 pb-1 pt-2 text-[11px] font-medium uppercase tracking-wide text-faint-foreground`,children:e.label}),e.failed&&(0,B.jsx)(`p`,{className:`px-3 py-1.5 text-danger-text`,children:yh(`couldNotSearch`,{label:e.label})}),e.hits.map(e=>{v+=1;let t=v;return(0,B.jsxs)(`a`,{id:p(t),href:e.href,tabIndex:-1,role:`option`,"aria-selected":t===l,className:P(`block px-3 py-1.5`,t===l?`bg-primary-soft text-primary-text`:`hover:bg-muted`),onMouseDown:e=>e.preventDefault(),onClick:t=>{_S(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))]})]})},yS=({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=mS(e),m=(0,I.useRef)(null);return(0,I.useLayoutEffect)(()=>{if(!s)return;let e=e=>{if(e.key.toLowerCase()!==`k`||!(e.metaKey||e.ctrlKey))return;e.preventDefault();let t=m.current;t&&t.offsetParent!==null?t.focus():f(!0)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[s]),(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(`header`,{ref:u,className:P(c?`sticky top-0 z-30 max-md:fixed max-md:left-[var(--pb-safe-left)] max-md:right-[var(--pb-safe-right)]`:`relative`,`flex h-[calc(3rem+var(--pb-safe-top))] shrink-0 items-center gap-1 border-b bg-background pl-4 pr-2 pt-[var(--pb-safe-top)] md:gap-4 md:px-5`),children:[i&&(0,B.jsx)(`button`,{type:`button`,"aria-label":yh(`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)(ho,{className:`size-5`})}),p&&(0,B.jsx)(`a`,{href:p.href,"aria-label":yh(`backTo`,{label:p.label}),onClick:e=>{let r=n??t;r&&bh(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)(Ei,{className:`size-5`})}),(0,B.jsx)(xh,{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)(vS,{ref:m,search:s})}),(0,B.jsx)(`button`,{type:`button`,"aria-label":yh(`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)(ss,{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)(vS,{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":yh(`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)(yc,{className:`size-5`})})]})]}),c&&(0,B.jsx)(`div`,{"aria-hidden":!0,className:`h-[var(--pb-sticky-top)] shrink-0 md:hidden`})]})},bS=`app-drawer`,xS=({sidebarMode:e,activeItem:t,breadcrumb:n,user:r,workspace:i,appName:a,appIcon:o,logo:s,actions:c,rightPanel:l,sidebarNotice:u,banner:d,forceExpanded:f,profileMenuOpen:p,navGroups:m,userMenu:h,account:g,bottomBar:_,onNavigate:v,onBack:y,onSignOut:b,signIn:x,organizations:S,roles:C,theme:w,status:T,search:E,pageScroll:D=!1,className:O,children:k})=>{let A=gf(),j=dS(e),[ee,te]=(0,I.useState)(!1);(0,I.useEffect)(()=>{A&&te(!1)},[A]);let ne=!A&&_&&_.length>0?_:void 0,[re,ie]=(0,I.useState)(),ae=re??D,oe=(0,I.useRef)(null),[se,ce]=(0,I.useState)(null),le=(0,I.useRef)(null);xx(ae,oe,le,!!ne),yx(ae);let ue=(e,n=!1,c)=>(0,B.jsx)(uS,{mode:e,sticky:n,notice:c,activeItem:t,user:r,workspace:i,appName:a,appIcon:o,forceExpanded:f,profileMenuOpen:p,groups:m,userMenu:h,account:g,onNavigate:v,onSignOut:b,signIn:x,organizations:S,roles:C,theme:w,status:T,logo:s});return(0,B.jsx)(_x.Provider,{value:ie,children:(0,B.jsxs)(`div`,{className:P(ae?`flex min-h-full w-full overflow-x-clip bg-background`:`relative flex h-full min-h-0 w-full overflow-hidden bg-background`,O),children:[A?ue(e,ae,j&&u):(0,B.jsx)(gx,{id:bS,open:ee,onClose:()=>te(!1),children:ue(`text-large`)}),(0,B.jsxs)(`div`,{className:P(`flex min-w-0 flex-1 flex-col`,!ne&&`pb-[var(--pb-safe-bottom)]`),children:[(0,B.jsx)(yS,{ref:oe,slotRef:ce,sticky:ae,breadcrumb:n,onNavigate:v,onBack:y,actions:c,onMenu:A||ne?void 0:()=>te(!0),menuOpen:ee,menuControls:bS,search:E}),d,(0,B.jsx)(`main`,{className:ae?`flex flex-1 flex-col`:`flex min-h-0 flex-1 flex-col`,children:(0,B.jsx)(fS.Provider,{value:se,children:k})}),ne&&(0,B.jsx)(hx,{ref:le,sticky:ae,tabs:ne,onNavigate:v,onMore:()=>te(!0),moreOpen:ee,moreControls:bS})]}),l&&(0,B.jsx)(`div`,{className:ae?`sticky top-0 flex h-dvh shrink-0 self-start pt-[var(--pb-safe-top)]`:`flex shrink-0`,children:l})]})})},SS=({title:e,subtitle:t,actions:n,subtitleBelow:r})=>r?(0,B.jsx)(CS,{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})]}),CS=({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})]}),wS=({node:e,children:t,slots:n})=>{let{title:r,description:i}=Dy(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)(SS,{title:r,subtitle:i,actions:n.actions}),t]})})},TS=(e,t)=>{let n=Yv(),r=Vb(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},ES=({node:e})=>{let{value:t,max:n,label:r}=Dy(e),i=TS(t,0),a=TS(n,100);if(i===void 0||a===void 0)return(0,B.jsx)(vh,{className:`h-6 w-full`});if(!Number.isFinite(i)||!Number.isFinite(a))return null;let o=a>0?Math.min(1,Math.max(0,i/a)):0;return(0,B.jsxs)(`div`,{className:`min-w-0`,children:[(0,B.jsxs)(`div`,{className:`flex items-baseline justify-between gap-2 text-body`,children:[(0,B.jsx)(`span`,{className:`text-muted-foreground`,children:r}),(0,B.jsxs)(`span`,{className:`tabular-nums`,children:[i.toLocaleString(Le()),` / `,a.toLocaleString(Le())]})]}),(0,B.jsx)(`div`,{role:`progressbar`,"aria-label":r,"aria-valuenow":i,"aria-valuemin":0,"aria-valuemax":a,className:`mt-1.5 h-2 overflow-hidden rounded-full bg-muted`,children:(0,B.jsx)(`div`,{className:o>=.9?`h-full rounded-full bg-warning`:`h-full rounded-full bg-primary`,style:{width:`${o*100}%`}})})]})},DS=({model:e,filter:t,sort:n,recordKey:r,title:i,description:a,empty:o,actions:s,children:c})=>{let l=xy(e,{filter:t,sort:n,key:r}),u=e=>l.data?(0,B.jsx)(Jv,{value:l.data,children:e}):void 0,d=l.isPending?(0,B.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,B.jsx)(vh,{className:`h-4 w-1/2`}),(0,B.jsx)(vh,{className:`h-4 w-1/3`})]}):l.error?(0,B.jsx)(Bg,{title:sv(`couldNotLoad`),error:l.error}):l.data?u((0,B.jsx)(`div`,{className:`flex flex-col gap-3`,children:c})):(0,B.jsx)(jy,{children:o??sv(`nothingYet`)});return(0,B.jsx)(Ay,{title:i,description:a,actions:s?u(s):void 0,className:`h-full`,children:d})},OS=({node:e,children:t,slots:n})=>{let{resource:r,filter:i,sort:a,recordKey:o,title:s,description:c,empty:l}=Dy(e),u=W().resources[r];return u?(0,B.jsx)(DS,{model:u,filter:i,sort:a,recordKey:o,title:s,description:c,empty:l,actions:n.actions,children:t}):null},kS=`0.75rem`,AS=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% + ${kS}) * ${e} - ${kS})`},jS=({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:kS,scrollbarWidth:`thin`,"--snap-item-width":AS(e)},children:n}),MS=M(`app/embedded-list`),NS=(e,t,n)=>{if(!(e>=t))return MS(n?`firstOfAbout`:`firstOf`,{shown:e,total:t.toLocaleString(Le())})},PS=`protobase:embedded-display:`,FS=e=>`${PS}${e}`,IS=(e,t)=>Ie(()=>e.getItem(t)??void 0,void 0),LS=(e,t,n)=>Ie(()=>e.setItem(t,n),void 0),RS=(e,t,{picked:n,preferred:r})=>{let i=$m(e).map(e=>e.name);return n!==void 0&&i.includes(n)?n:Gm(e,t,r!==void 0&&i.includes(r)?r:void 0)},zS=(e,t,n,{resource:r=e.name,...i})=>_h({kind:`list`,resource:r},i,{...hh(e,t,n),display:Gm(t,n)}),BS=M(`app/related-cards`),VS=({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:BS(n?`showLess`:`showMore`)})]})},HS=e=>e==null||e===``,US=({scope:e,path:t})=>{let{views:n}=W(),r=Vb(e,t);if(r.state===`missing`||r.state===`ready`&&HS(r.value))return null;let i=Ub(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)(vh,{className:`h-4 w-24`}):(0,B.jsx)(VS,{children:(0,B.jsx)(Lb,{model:r.model,field:r.field,value:r.value})})})]})},WS=({scope:e,view:t,fields:n,actions:r})=>{let i=p_();return(0,B.jsxs)(`li`,{className:`flex min-w-0 flex-col gap-3 rounded-lg border border-border bg-surface p-4`,children:[(0,B.jsx)(Uh,{to:{kind:`record`,resource:e.model.name,key:ym(e.model,e.record)},className:`self-start font-medium text-primary-text hover:underline`,children:i(e.model,t,e.record,e.key)}),n.length>0&&(0,B.jsx)(`dl`,{className:`flex flex-col gap-3`,children:n.map(t=>(0,B.jsx)(US,{scope:e,path:t},t))}),r.length>0&&(0,B.jsx)(Jv,{value:e,children:(0,B.jsx)(`div`,{className:`flex flex-wrap items-center gap-2`,children:r.map(e=>(0,B.jsx)(Oy,{name:e},e))})})]})},GS=({model:e,view:t,filter:n,sort:r,fields:i,actions:a,limit:o,display:s,empty:c,carousel:l})=>{let u=_f(),d=r||dh(e,t),f=Sy(e,{filter:n,sort:d,pageSize:o}),p=by(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)(vh,{className:`h-24 w-full`},t))});if(f.error)return(0,B.jsx)(Bg,{title:BS(`couldNotLoad`),error:f.error});let m=f.data.items;if(m.length===0)return(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:c??BS(`nothingYet`)});let h=m.map(n=>{let r=vy(e,n);return(0,B.jsx)(WS,{scope:r,view:t,fields:i,actions:a},r.key)}),g=p.data===void 0?void 0:NS(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)(jS,{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)(Uh,{to:zS(e,t,u,{filter:n,orderBy:d,display:RS(t,u,{preferred:s})}),className:`flex items-center gap-1 font-medium text-primary-text hover:underline`,children:[MS(`viewAll`),` `,(0,B.jsx)(`span`,{className:`sr-only`,children:(t?.names?.plural??F(e.name)).toLowerCase()}),(0,B.jsx)(Rr,{className:`size-3.5`,"aria-hidden":!0})]})]})]})},KS={"1/4":1/4,"1/3":1/3,"1/2":1/2,"2/3":2/3},qS=({node:e,slots:t})=>{let n=Dy(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}=_u(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)(Bf,{title:u,help:d,actions:t.actions,children:(0,B.jsx)(GS,{model:_,view:v,filter:i,sort:a,fields:o??Tr(_,v),actions:s,limit:c,display:l,empty:f,carousel:p===`carousel`?KS[m]:void 0})})})},JS=e=>t=>{let n=t.currentTarget;n.scrollWidth>Math.ceil(n.getBoundingClientRect().width)?n.title=e:n.removeAttribute(`title`)},YS=({text:e,className:t})=>(0,B.jsx)(`span`,{className:P(`truncate`,t),onMouseEnter:JS(e),children:e}),XS=e=>(0,B.jsx)(`span`,{className:`text-faint-foreground`,children:e}),ZS=(e,t)=>{if(t==null)return XS(`—`);let n=qp(e,t)??``;switch(e.kind){case`text`:return e.link?(0,B.jsx)(bv,{format:e.link,value:n,className:`block min-w-0 truncate`}):(0,B.jsx)(YS,{text:n});case`id`:return(0,B.jsx)(YS,{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?dp(Number(t)):Gp(`shownIn`,{zone:ep(Number(t),Gf())}),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?XS(`—`):(0,B.jsx)(`span`,{className:`tabular-nums`,children:n});case`status`:return(0,B.jsx)(Pf,{tone:e.tones?.[String(t)]??`neutral`,color:Tm(e.colors,t),shape:e.shape,children:n});case`relation`:return(0,B.jsx)(YS,{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)(Si,{className:`size-3`,strokeWidth:3})}):XS(Gp(`no`));case`file`:{let e=Np(t);if(!e)return XS(`—`);if(`missing`in e)return(0,B.jsx)(YS,{text:e.name,className:`text-danger-text`});let n=Vp(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)(j_,{image:n,className:`size-5 shrink-0 rounded-sm object-cover`}):(0,B.jsx)(Fo,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,B.jsx)(YS,{text:e.name})]})}case`user`:{let r=e.users?.(String(t));return r?(0,B.jsxs)(`span`,{className:`inline-flex items-center gap-2 truncate`,children:[(0,B.jsx)(If,{initials:r.initials,hue:r.hue,size:`xs`,className:`ring-0`}),(0,B.jsx)(YS,{text:r.name,className:`text-muted-foreground`})]}):(0,B.jsx)(YS,{text:n,className:`text-muted-foreground`})}}},QS=Ae({rowSortingFeature:C,rowSelectionFeature:s}),$S=w(),eC=e=>$S.columns(e.map(e=>$S.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):ZS(e,t.getValue())}))),tC=(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}]}),nC=({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:[Dp(e),t>0&&(0,B.jsx)(`span`,{className:`ml-3 font-medium text-primary-text`,children:Gp(`selected`,{count:wp(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))]})}),rC=(e,t)=>typeof e.label==`string`?e.label:e.label(t),iC=(e,t)=>e.filter(e=>e.available?.(t)??!0),aC=({row:e,actions:t})=>{let{open:n,setOpen:r,place:i,button:a,menu:o}=rg();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":Gp(`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)(ca,{className:`size-4`})}),n&&(0,Sc.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=rC(t,e),a=t.blocked?.(e),o=P(`block w-full px-3 py-1.5 text-left hover:bg-muted disabled:cursor-default disabled:opacity-60 disabled:hover:bg-transparent`,t.destructive&&`text-danger-text`);return(0,B.jsx)(`li`,{role:`none`,children:t.link&&a===void 0?(0,B.jsx)(Sh,{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)]})},oC=e=>52+Math.ceil(String(e).length*1.33)*7,sC=.6,cC=(e,t)=>Math.max(e.minWidth??0,e.width*t),lC=(e,t)=>e.fixed?`${Math.max(e.minWidth??0,e.width)}px`:`minmax(${cC(e,t)}px, ${e.width}fr)`,uC=(e,t,n=0,r=sC)=>`${t}px ${e.map(e=>lC(e,r)).join(` `)}${n>0?` ${n}px`:``}`,dC=(e,t,n=0,r=sC)=>t+n+e.reduce((e,t)=>e+(t.fixed?Math.max(t.minWidth??0,t.width):cC(t,r)),0),fC=()=>{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}},pC=`protobase:pinned:`,mC=(e,t)=>`${pC}${e}:${t}`,hC=(e,t)=>Ie(()=>{let n=e.getItem(t);if(n===null)return;let r=JSON.parse(n);return Array.isArray(r)&&r.every(e=>typeof e==`string`)?r:void 0},void 0),gC=(e,t,n)=>Ie(()=>e.setItem(t,JSON.stringify(n)),void 0),_C=(e,t=[])=>{let[n,r]=(0,I.useState)(()=>e?hC(localStorage,e):void 0),i=(0,I.useCallback)(t=>{r(t),e&&gC(localStorage,e,t)},[e]);return[n??t,i]},vC=e=>{let t=e.findIndex(e=>e.title);return t<0||t>1?[]:e.slice(0,t+1).map(e=>e.id)},yC=e=>Object.fromEntries(e.map(({id:e,width:t,minWidth:n,fixed:r})=>[e,{width:t,minWidth:n,fixed:r}])),bC=(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:yC(um(e,t))});let o=a?.sizes;return(0,I.useMemo)(()=>o?e.map(e=>({...e,...o[e.id]})):e,[e,o])},xC=(e,t)=>Math.max(Math.min(64,e),Math.round(e+t)),SC=(e,t)=>e.map(e=>e.id in t?{...e,fixed:!0,width:t[e.id],minWidth:void 0}:e),CC=e=>Object.fromEntries([...e.querySelectorAll(`[data-col-id]`)].map(e=>[e.dataset.colId,e.offsetWidth])),wC=e=>{let[t,n]=(0,I.useState)({}),r=()=>({...e.current?CC(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]:xC(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]:xC(a[e]??0,i)})}}},TC=({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)(xo,{className:`size-3`,strokeWidth:3}):e&&(0,B.jsx)(Si,{className:`size-3`,strokeWidth:3})}),EC=e=>e===`money`||e===`number`||e===`signed`||e===`percent`,DC=()=>Gp(`unsortable`),OC=({header:e,pinned:t,sortable:n,onTogglePin:r})=>{let{open:i,setOpen:a,place:o,button:s,menu:c}=rg();return(0,B.jsxs)(`div`,{className:`relative ml-auto shrink-0`,children:[(0,B.jsx)(`button`,{ref:s,type:`button`,"aria-label":Gp(`columnMenu`,{header:e}),"aria-haspopup":`menu`,"aria-expanded":i,onClick:()=>a(!i),className:`relative inline-flex size-5 items-center justify-center rounded text-faint-foreground hover:bg-muted hover:text-foreground focus-visible:opacity-100 after:absolute after:-inset-2 after:content-[''] md:opacity-0 md:group-hover/cell:opacity-100 aria-expanded:opacity-100`,children:(0,B.jsx)(ca,{className:`size-3.5`})}),i&&(0,Sc.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:DC()})}),(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:Gp(t?`unpin`:`pinToLeft`)})})]}),document.body)]})},kC=({id:e,header:t,width:n,resize:r})=>(0,B.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":Gp(`resizeColumn`,{header:t}),"aria-valuemin":64,"aria-valuenow":n,tabIndex:0,onPointerDown:t=>r.onPointerDown(e,t),onKeyDown:t=>r.onKeyDown(e,t),className:`group/resize absolute inset-y-0 right-0 z-10 flex w-2 cursor-col-resize touch-none justify-end outline-none`,children:(0,B.jsx)(`div`,{className:`h-full w-0.5 bg-transparent group-hover/resize:bg-primary group-focus-visible/resize:bg-primary group-active/resize:bg-primary`})}),AC=({sorted:e})=>e===`asc`?(0,B.jsx)(Wr,{className:`size-3 text-foreground`}):e===`desc`?(0,B.jsx)(Pr,{className:`size-3 text-foreground`}):(0,B.jsx)(Ai,{className:`size-3 opacity-0 group-hover/head:opacity-100`}),jC=({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:Gp(`new`)})]}),MC=({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:uC(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)(TC,{checked:!1,indeterminate:r>0,label:Gp(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`,EC(e.kind)&&`justify-end`,`hover:text-foreground`,t&&`text-foreground`),children:[(0,B.jsx)(jC,{spec:e}),(0,B.jsx)(AC,{sorted:t})]}):(0,B.jsx)(`div`,{title:DC(),className:P(`flex h-full min-w-0 flex-1 items-center gap-1 pl-3 pr-1 text-left`,EC(e.kind)&&`justify-end`),children:(0,B.jsx)(jC,{spec:e})}),(0,B.jsx)(`div`,{className:`pr-1.5`,children:(0,B.jsx)(OC,{header:e.header,pinned:r,sortable:!!e.sortable,onTogglePin:()=>u(e.id)})}),d&&(0,B.jsx)(kC,{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]}),NC=e=>({gridTemplateColumns:uC(e.specs,e.gutter,e.trailing,e.minScale),height:e.height,transform:`translateY(${e.offset}px)`}),PC=(e,t)=>P(`flex h-full min-w-0 items-center overflow-hidden whitespace-nowrap px-3`,EC(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)]`),FC=(e,t)=>t&&e.id in t?{left:t[e.id]}:void 0,IC=({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)(TC,{checked:!!r,label:Gp(`selectRow`,{row:t+1})}),e>40&&(0,B.jsx)(`span`,{className:`min-w-6 text-right text-[11px] tabular-nums text-faint-foreground`,children:wp(t+1)})]}),LC=(e,t,n)=>({gridTemplateColumns:uC(e.specs,e.gutter,e.trailing,e.minScale),height:e.height,top:e.offset,transform:t===0?void 0:`translateY(${t}px)`,transition:n}),RC=e=>t=>{t.target.closest(`a`)||e()},zC=({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&&RC(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?NC(u):LC(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)(IC,{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(PC(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:FC(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})]}),BC=[`w-3/4`,`w-1/2`,`w-2/3`,`w-5/6`,`w-2/5`],VC=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:NC(e),children:[(0,B.jsx)(IC,{width:e.gutter,index:e.index,selectable:!1,edge:e.scrolled&&!e.lastPinned}),e.specs.map((t,n)=>(0,B.jsx)(`div`,{className:PC(t,e),style:FC(t,e.pins),children:(0,B.jsx)(vh,{className:P(`h-2.5`,BC[(e.index+n)%BC.length],EC(t.kind)&&`ml-auto`)})},t.id))]}),HC=(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}}},UC=(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)},WC=(e,t)=>Math.max(0,Math.min(40,e-t*40)),GC=({total:e,rowAt:t,loadRows:n,revision:r,latencyMs:i},a,o)=>{let s=(0,I.useMemo)(()=>HC(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=UC(u*40,d*40,40).filter(e=>!s.hasPage(e)),a=t=>WC(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=UC(u*40,d*40,40);s.keepOnly(t);for(let r of t.filter(e=>s.hasPage(e)))n(r*40,WC(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])},KC=1e7,qC=(e,t,n)=>{let r=e*t,i=Math.min(r,KC);return{rowHeight:t,trueHeight:r,contentHeight:i,scaled:r>i,maxTop:Math.max(0,r-n),maxScroll:Math.max(0,i-n)}},JC=(e,t)=>!e.scaled||t<=0?t:t>=e.maxScroll?e.maxTop+t-e.maxScroll:t/e.maxScroll*e.maxTop,YC=(e,t)=>!e.scaled||t<=0?t:t>=e.maxTop?e.maxScroll+t-e.maxTop:t/e.maxTop*e.maxScroll,XC=(e,t,n,r)=>{let i=t*e.rowHeight;return e.scaled?i-n+r:i},ZC=(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)}},QC=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},$C=e=>e===(document.scrollingElement??document.documentElement),ew=e=>$C(e)?window:e,tw=e=>Number.parseFloat(e)||0,nw=e=>{let t=getComputedStyle(e),n=$C(e)?{top:0,height:e.clientHeight}:{top:e.getBoundingClientRect().top+e.clientTop,height:e.clientHeight},r=tw(t.scrollPaddingTop);return{top:n.top+r,height:Math.max(0,n.height-r-tw(t.scrollPaddingBottom))}},rw=6,iw=(e,t,n)=>{let r=qC(t,n,e.height),i=JC(r,e.position);return{geometry:r,top:i,topIndex:Math.floor(Math.max(0,i)/n),...ZC(t,i,n,e.height,rw)}},aw=({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=nw(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=iw(t,n,r),o=iw(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+=YC(qC(n,r,e.height),i*r)-e.position:e.position>0&&(t.scrollTop=0)},[f]);(0,I.useLayoutEffect)(()=>{let e=s.current;if(!e)return;let t=QC(e);c.current=t;let n=ew(t);n.addEventListener(`scroll`,h,{passive:!0}),window.addEventListener(`resize`,h,{passive:!0});let r=new ResizeObserver(()=>{p.current.laidOut=!0,g(),h()});return r.observe(t),r.observe(e),h(),()=>{n.removeEventListener(`scroll`,h),window.removeEventListener(`resize`,h),r.disconnect(),c.current=null}},[h,g]),(0,I.useLayoutEffect)(()=>{g(),h()});let _=(0,I.useCallback)(e=>{let t=f();if(!t||!c.current)return;let n=qC(d.current.total,d.current.rowHeight,t.height);c.current.scrollTop+=YC(n,e)-t.position,h()},[f,h]),v=(0,I.useCallback)(()=>!p.current.pending,[]),y=iw(l,e,t),b=i?i(y.top):y.top,{first:x,last:S}=i?ZC(e,b,t,l.height,rw):y,C=Array.from({length:S-x+1},(e,t)=>({index:x+t,offset:XC(y.geometry,x+t,b,l.position)}));return{ref:s,height:l.height,top:b,geometry:y.geometry,rows:C,first:x,last:S,scrollTo:_,started:v}},ow=e=>e===`ArrowUp`||e===`ArrowDown`||e===`ArrowLeft`||e===`ArrowRight`,sw=(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},cw=(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)},lw=e=>`${e.index}:${e.column}`,uw=({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="${lw(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?cw(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":lw(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!==lw(o))return;let a=e.key===`Tab`?e.shiftKey?`ArrowLeft`:`ArrowRight`:e.key;if(ow(a)){let i=sw(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)}}},dw=({ids:e,rowAt:t,reorder:n,children:r})=>{let i=ne(Me(se,{activationConstraint:{distance:4}}),Me(xe,{activationConstraint:{delay:250,tolerance:5}}),Me(ae,{coordinateGetter:ye})),a=t=>e.indexOf(String(t)),o=e=>{let r=t(a(e));return r?n.label(r):Gp(`row`)};return(0,B.jsx)(me,{sensors:i,collisionDetection:ge,onDragEnd:({active:e,over:t})=>{t&&e.id!==t.id&&n.onMove(a(e.id),a(t.id))},accessibility:{announcements:{onDragStart:({active:t})=>Gp(`pickedUp`,{name:o(t.id),row:a(t.id)+1,rows:e.length}),onDragOver:({active:t,over:n})=>n?Gp(`isOver`,{name:o(t.id),row:a(n.id)+1,rows:e.length}):void 0,onDragEnd:({active:t,over:n})=>n?Gp(`droppedAt`,{name:o(t.id),row:a(n.id)+1,rows:e.length}):Gp(`putBack`,{name:o(t.id)}),onDragCancel:({active:e})=>Gp(`cancelled`,{name:o(e.id),row:a(e.id)+1})},screenReaderInstructions:{draggable:Gp(`reorderInstructions`)}},children:(0,B.jsx)(ue,{items:e,strategy:re,children:r})})},fw=({row:e,label:t,...n})=>{let{attributes:r,listeners:i,setNodeRef:a,setActivatorNodeRef:o,transform:s,transition:c,isDragging:l}=Te({id:e.id}),u=(0,B.jsx)(`button`,{ref:o,type:`button`,"aria-label":Gp(`move`,{label:t}),...r,...i,onClick:e=>e.stopPropagation(),style:{touchAction:`none`},className:`flex size-7 cursor-grab items-center justify-center rounded text-faint-foreground hover:bg-muted hover:text-foreground focus-visible:text-foreground active:cursor-grabbing pointer-coarse:size-9`,children:(0,B.jsx)(wa,{className:`size-4`})});return(0,B.jsx)(zC,{...n,rowRef:a,handle:u,dragY:s?.y??0,transition:c,dragging:l})},pw=32,mw=({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=!gf(),E=(h??(T?[]:vC(e))).join(` `),[D,O]=_C(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)(()=>eC(k),[k]),se=ne[0],ce=!!(!o&&n&&se&&se.id===n.columnId&&(se.desc?`desc`:`asc`)!==n.direction),le=t.rowAt,ue=(0,I.useCallback)(e=>le(ce?j-1-e:e),[le,ce,j]),[de]=(0,I.useState)(r),{ref:fe,geometry:pe,rows:me,first:he,last:ge}=aw({total:j,rowHeight:w,initialIndex:de,inset:pw,onScroll:i&&(e=>i(e/w))}),_e=T||!g?40:oC(j),ve=GC({total:j,rowAt:le?ue:void 0,loadRows:t.loadRows,revision:t.revision,latencyMs:a},he,ge),ye=(0,I.useCallback)(e=>{let t=ve(e),n=t&&f?.get(t.id);return n?{...t,...n}:t},[ve,f]),be=me.map(({index:e,offset:t})=>({index:e,offset:t,row:ye(e)})),xe=(0,I.useMemo)(()=>be.flatMap(({row:e})=>e?[e]:[]),[ye,he,ge]),Se=(0,I.useRef)(null),Ce=wC(Se),we=bC(k,xe),Te=(0,I.useMemo)(()=>SC(we,Ce.widths),[we,Ce.widths]),Ee=je({features:QS,columns:oe,data:xe,state:{sorting:ne,rowSelection:ie},onSortingChange:re,onRowSelectionChange:ae,manualSorting:!0,enableMultiSort:!1,enableSortingRemoval:!1,getRowId:e=>e.id}),De=new Map(Ee.getRowModel().rows.map(e=>[e.id,e])),Oe=Object.keys(ie).length,ke=(0,I.useRef)(new Map);for(let e of Ee.getRowModel().rows)e.getIsSelected()&&ke.current.set(e.id,e.original);let Ae=u&&u.length>0?40:0,Me=T?1:sC,Ne=fC(),M=()=>{Ne.onScroll(),Se.current&&Ne.ref.current&&(Se.current.scrollLeft=Ne.ref.current.scrollLeft)},[Pe,Fe]=(0,I.useState)({});(0,I.useLayoutEffect)(()=>{let e=Se.current?.querySelector(`[role=row]`);if(!e)return;let t=_e,n={};for(let r of A)n[r]=t,t+=e.querySelector(`[data-col-id="${r}"]`)?.offsetWidth??0;JSON.stringify(Pe)!==JSON.stringify(n)&&Fe(n)});let Ie=A.at(-1),Le=e=>O(D.includes(e)?D.filter(t=>t!==e):[...D,e]),Re=Ee.getHeaderGroups().flatMap(e=>e.headers.map(e=>({spec:k.find(t=>t.id===e.column.id),sorted:e.column.getIsSorted(),onSort:t=>e.column.getToggleSortingHandler()?.(t)}))),N=(0,I.useRef)(null),ze=uw({editor:d,columns:(0,I.useMemo)(()=>k.map(e=>e.id),[k]),total:j,rowAt:ye,onOpenRow:c,container:N}),Be=(k.find(e=>e.title)??k[0])?.id,Ve=dC(Te,_e,Ae,Me),He=x===`own`,Ue=(0,B.jsx)(`div`,{ref:Se,className:P(`sticky z-20 shrink-0 overflow-hidden`,He?`top-0`:`top-[var(--pb-sticky-top,0px)]`),children:(0,B.jsx)(`div`,{style:{minWidth:Ve},children:(0,B.jsx)(MC,{cells:Re,specs:Te,gutter:_e,trailing:Ae,minScale:Me,pins:Pe,lastPinned:Ie,scrolled:Ne.scrolled,onTogglePin:Le,resize:Ce,widths:Ce.widths,selectable:C,selectedCount:Oe,onClearSelection:()=>ae({})})})}),We=be.map(({index:e,offset:t,row:n})=>{let r={specs:Te,gutter:_e,index:e,offset:t,height:w,selectable:C,trailing:Ae,minScale:Me,scrolled:Ne.scrolled,pins:Pe,lastPinned:Ie},i=n?De.get(n.id):void 0;if(!i||!n)return(0,B.jsx)(VC,{...r},`skeleton-${e}`);let a=Ae?iC(u,n):[],o={...r,selected:i.getIsSelected(),onToggle:()=>i.toggleSelected(),onOpen:c?()=>c(n):void 0,menu:a.length>0?(0,B.jsx)(aC,{row:n,actions:a}):void 0,cells:i.getAllCells().map(t=>{let r=(0,B.jsx)(Ee.FlexRender,{cell:t}),i=!!d?.editable(n,t.column.id),a=l&&t.column.id===Be&&!i?(0,B.jsx)(Sh,{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)(fw,{...o,row:n,label:y.label(n)},n.id):(0,B.jsx)(zC,{...o},n.id)}),Ge=(0,B.jsx)(`div`,{ref:Ne.attach,onScroll:M,className:`overflow-x-auto overflow-y-hidden overscroll-x-contain [-webkit-overflow-scrolling:touch]`,children:(0,B.jsx)(`div`,{ref:fe,className:`relative`,style:{minWidth:Ve,height:pe.contentHeight},children:y?(0,B.jsx)(dw,{ids:Array.from({length:j},(e,t)=>ye(t)?.id??`missing-${t}`),rowAt:ye,reorder:y,children:We}):We})});return(0,B.jsxs)(`div`,{ref:N,role:`grid`,"aria-rowcount":j,onKeyDown:ze?.onKeyDown,className:P(`flex flex-col rounded-lg border bg-background`,He?`min-h-0 overflow-hidden`:`overflow-clip`,S),style:b&&He?{height:pw+j*w+2}:void 0,children:[(0,B.jsxs)(`div`,{className:P(`relative`,He&&`flex min-h-0 flex-1 flex-col`),children:[He?(0,B.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overflow-x-hidden`,children:[Ue,Ge]}):(0,B.jsxs)(B.Fragment,{children:[Ue,Ge]}),Ne.more&&(0,B.jsx)(`div`,{"aria-hidden":!0,className:`pointer-events-none absolute inset-y-0 right-0 z-20 w-8 bg-gradient-to-l from-backdrop/15 to-transparent`})]}),!b&&(0,B.jsx)(nC,{total:j,className:He?void 0:`sticky bottom-[var(--pb-sticky-bottom,0px)] z-20`,selectedCount:Oe,bulkActions:tC(p??[],Object.keys(ie).flatMap(e=>ke.current.get(e)??[])).map(({action:e,rows:t,skipped:n})=>({label:e.label(t.length),destructive:e.destructive,onRun:()=>{e.onRun(t,n),ae({}),ke.current.clear()}}))})]})},hw=500,gw=async(e,t,n)=>{let r=[],i={},a;do{let o=await e.search(t,{...n,pageSize:hw,...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}},_w=sn(),vw=(...e)=>{let t=e.filter(e=>!!e);return t.length===1?t[0]:t.map(e=>`(${e})`).join(` AND `)},yw=e=>e==null?void 0:String(e),bw=(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=yw(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},xw=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 gw(e,a.name,{filter:vw(Yt(_w.in(i.field,r)),i.filter),fields:[i.field,o]})).items.flatMap(e=>{let t=yw(e[i.field]),n=yw(e[o]);return t===void 0||n===void 0?[]:[[t,n]]})},Sw=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 xw(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=Cb(t,n,s,u),f=await gw(e,s.name,{filter:vw(Yt(_w.in(a.field,l)),a.filter),...a.sort&&{orderBy:a.sort},fields:u,labels:d});return bw(c,wb(t,s,u,f.items,f.labels),a.field)},Cw=5e3,ww=({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=Cb(n,r,i,a),f=Im(r[i.name]),p=async e=>e.nextPageToken===``?e.items.length:e.totalSizeEstimate>Cw?e.totalSizeEstimate:(await t.list(i.name,{filter:o,orderBy:s,pageSize:1,count:`exact`})).totalSize??e.totalSizeEstimate,m=async t=>{if(t===0)return``;let n=u(t-1),r=e.getQueryData(n);if(r)return r.nextPageToken;if(e.getQueryState(n)?.fetchStatus===`fetching`)return(await g(t-1)).nextPageToken},h=async l=>{let u=await m(l);if(l>0&&u===``)return{rows:[],total:0,nextPageToken:``};let h={filter:o,orderBy:s,pageSize:40,labels:d,photos:f},g=u===void 0?await t.seek(i.name,{...h,position:l*40}):await t.list(i.name,{...h,pageToken:u});if(g.items.length===0&&l>0)return{rows:[],total:0,nextPageToken:``};let _=g.items.map(e=>vm(i,e)),v=wb(n,i,a,Lm(i,g.items,g.photos),g.labels),[y]=await Promise.all([Promise.all(c.map(e=>Sw({client:t,resources:n,views:r,load:e,owners:_}))),kb(e,t,n,r,i,a,g.items)]);return{rows:v.map((e,t)=>({...e,...Object.fromEntries(c.map((e,n)=>[e.column.name,y[n].get(_[t])??[]])),id:_[t]})),total:l===0?await p(g):g.totalSizeEstimate,nextPageToken:g.nextPageToken}},g=t=>e.fetchQuery({queryKey:u(t),staleTime:6e4,queryFn:()=>h(t)});return{page:g,loadRows:async e=>(await g(Math.floor(e/40))).rows}},Tw=({resources:e,views:t,model:n,columns:r,filter:i,orderBy:a,related:o})=>{let s=U(),c=Se(),l=r.join(`,`),u=JSON.stringify(o??[]),d=(0,I.useMemo)(()=>ww({queryClient:c,client:s,resources:e,views:t,model:n,columns:r,filter:i,orderBy:a,...o&&{related:o}}),[c,s,e,t,n,l,i,a,u]),f=E({queryKey:[...H.first(n.name,i,a),l],queryFn:async()=>(await c.invalidateQueries({queryKey:H.pages(n.name,i,a),refetchType:`none`}),d.page(0))});return{source:(0,I.useMemo)(()=>f.data?{total:f.data.total,loadRows:d.loadRows,revision:f.dataUpdatedAt}:void 0,[f.data,f.dataUpdatedAt,d]),error:f.error,isLoading:f.isLoading,page:d.page,key:[...H.first(n.name,i,a),l]}},Y=M(`app/searches`),Ew=`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`,Dw=({chips:e,className:t})=>(0,B.jsx)(`ul`,{className:P(`flex flex-wrap gap-1.5`,t),"aria-label":Y(`filters`),children:e.map(e=>(0,B.jsx)(`li`,{className:Ew,children:e.label},e.key))}),Ow=({chips:e})=>(0,B.jsx)(`span`,{className:`flex flex-wrap gap-1.5`,children:e.map((e,t)=>(0,B.jsxs)(`span`,{className:Ew,children:[t>0&&(0,B.jsx)(`span`,{className:`sr-only`,children:`, `}),e.label]},e.key))}),kw=e=>e.map(e=>e.label).join(`, `),Aw=M(`filter-panel`),jw=`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`,Mw=({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)(no,{className:`size-3 text-muted-foreground`}),e]},e)),e.map(e=>(0,B.jsxs)(`span`,{className:jw,children:[e.label,(0,B.jsx)(`button`,{type:`button`,"aria-label":Aw(`remove`,{label:e.label}),onClick:()=>n(e.key),className:`rounded-full p-0.5 hover:bg-primary-border/60`,children:(0,B.jsx)(yc,{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:Aw(`clearAll`)})]}),Nw=[`today`,`7d`,`30d`,`year`],Pw=new Set([`today`,`yesterday`,`24h`,`7d`,`30d`,`90d`,`month`,`quarter`,`year`]),Fw=e=>Pw.has(e)?Aw(e):void 0,Iw=({value:e,presets:t=Nw,onChange:n})=>(0,B.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:t.map(t=>{let r=Fw(t);return(0,B.jsx)(`button`,{type:`button`,disabled:!r,title:r?void 0:Aw(`unknownPreset`,{id:t}),onClick:()=>n(e===t?void 0:t),className:P(`h-7 rounded-md border px-2.5 text-body font-medium transition-colors`,!r&&`border-dashed text-danger-text`,e===t?`border-primary-border bg-primary-soft text-primary-text`:`border-border-strong bg-background text-muted-foreground hover:bg-muted`),children:r??Aw(`unsupported`,{id:t})},t)})}),Lw={facets:{},toggles:[]},Rw=(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}}},zw=(e,t)=>({...e,toggles:e.toggles.includes(t)?e.toggles.filter(e=>e!==t):[...e.toggles,t]}),Bw=(e,t,n)=>{let{[t]:r,...i}=e.ranges??{};return{...e,ranges:n?{...i,[t]:n}:i}},Vw=(e,t)=>e.options.find(e=>e.value===t)?.label??e.labels?.[t]??t,Hw=(e,t)=>{let n=e.facets.flatMap(e=>(t.facets[e.id]??[]).map(t=>({key:`facet:${e.id}:${t}`,label:`${e.label}: ${Vw(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:Fw(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]},Uw=(e,t)=>{if(t===`date`)return{...e,date:void 0};let[n,r,i]=t.split(`:`);if(n===`range`)return Bw(e,r,void 0);if(n===`toggle`)return zw(e,r);if(n===`facet`)return Rw(e,r,i);throw Error(`Unknown filter chip key: ${t}`)},Ww=(e,t)=>e.toLowerCase().includes(t.trim().toLowerCase()),Gw=(e,t)=>e.onSearch?e.options:e.options.filter(e=>Ww(e.label,t)),Kw=(e,t,n)=>t===0?-1:n===`ArrowDown`?e<0?0:(e+1)%t:e<0?t-1:(e-1+t)%t,qw=({config:e,selected:t,onToggle:n,inline:r=!1})=>{let i=(0,I.useId)(),a=(0,I.useRef)(null),[o,s]=(0,I.useState)(``),[c,l]=(0,I.useState)(!1),[u,d]=(0,I.useState)(-1),f=r||c,p=Gw(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)(ss,{className:`size-3.5 shrink-0 text-muted-foreground`}),t.map(t=>(0,B.jsx)(X_,{label:Vw(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?``:Aw(`searchIn`,{label:e.label}),className:`h-6 min-w-16 flex-1 bg-transparent text-foreground outline-none placeholder:text-faint-foreground`,value:o,onChange:e=>h(e.target.value),onKeyDown:e=>{if(e.key===`ArrowDown`||e.key===`ArrowUp`){e.preventDefault(),d(Kw(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)(Si,{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:wp(e.count)})]},e.value)}),p.length===0&&(0,B.jsx)(`li`,{className:`px-1.5 py-1 text-xs text-faint-foreground`,children:Aw(`noMatches`)})]})]})},Jw=({config:e,selected:t,onToggle:n})=>{let[r,i]=(0,I.useState)(``),a=e.options.filter(e=>Ww(e.label,r));return(0,B.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[e.searchable&&(0,B.jsx)(J,{wrapperClassName:`mb-1 h-7`,leading:(0,B.jsx)(ss,{className:`size-3.5`}),placeholder:Aw(`searchIn`,{label:e.label}),value:r,onChange:e=>i(e.target.value)}),a.map(e=>(0,B.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 rounded px-1 py-1 hover:bg-muted`,children:[(0,B.jsx)(TC,{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:wp(e.count)})]},e.value)),a.length===0&&(0,B.jsx)(`span`,{className:`px-1 py-1 text-xs text-faint-foreground`,children:Aw(`noMatches`)})]})},Yw=({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)(wi,{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})]})},Xw=({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]}),Zw=(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}},Qw=({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":Aw(`moreFilters`),onKeyDown:t=>{if(t.key===`Escape`)return n();let i=Zw(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:eg,onClick:()=>{n(),t(e.key)},children:e.label})},e.key))})},$w=({items:e,onPick:t})=>e.length===0?null:(0,B.jsx)(Yw,{label:Aw(`moreFilters`),activeCount:0,children:n=>(0,B.jsx)(Qw,{items:e,onPick:t,close:n})}),eT=(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},tT=(e,t,n,r,i)=>{let a=n+(r-n)*e/t;return n+(r-n)*(e+1)/t>i[0]&&a<i[1]},nT=(e,t,n)=>n===t?0:(e-t)/(n-t),rT=(e,t,n)=>t===0?[Math.min(n,e[1]),e[1]]:[e[0],Math.max(n,e[0])],iT=1e3,aT=({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=eT(c,iT);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`,tT(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:`${nT(u[0],r,i)*100}%`,right:`${100-nT(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":Aw(t===0?`minimum`:`maximum`,{label:e.label}),min:r,max:i,step:a,value:u[t],onChange:e=>l(rT(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])})]})]})},oT=e=>[...new Set(e.map(e=>e.key.split(`:`).slice(0,2).join(`:`)))],sT=(e,t)=>{let n=t.filter(t=>!e.includes(t));return n.length===0?e:[...e,...n]},cT=(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:Aw(`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}},lT=({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)(Vg,{checked:t,onChange:n,label:e})]}),uT=(e,t)=>e.some(e=>e.length>0)||!!t,dT=({groups:e,trailing:t})=>{if(!uT(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})]})},fT=(e,t,n)=>{let[r,i]=(0,I.useState)(t??Lw);return[e??r,e=>{i(e),n?.(e)}]},pT=({config:e,layout:t,value:n,defaultValue:r,onChange:i,lockedLabels:a,defaultOpenMenu:o,fullWidth:s,leading:c,trailing:l})=>{let[u,d]=fT(n,r,i),f=Hw(e,u),p=oT(f),[m,h]=(0,I.useState)(()=>p),[g,_]=(0,I.useState)();(0,I.useEffect)(()=>h(e=>sT(e,p)),[p.join(`,`)]);let v=(0,B.jsx)(Mw,{chips:f,lockedLabels:a,onRemove:e=>d(Uw(u,e)),onClear:()=>d(Lw)}),y=(e,t=!1)=>{let n=u.facets[e.id]??[],r=t=>d(Rw(u,e.id,t));return e.combobox?(0,B.jsx)(qw,{config:e,selected:n,onToggle:r,inline:t}):(0,B.jsx)(Jw,{config:e,selected:n,onToggle:r})},b=e.ranges??[],x=e=>(0,B.jsx)(aT,{config:e,value:u.ranges?.[e.id],onChange:t=>d(Bw(u,e.id,t))}),S=e.datePresets&&(0,B.jsx)(Iw,{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)(lT,{label:e.label,checked:u.toggles.includes(e.id),onChange:()=>d(zw(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:Aw(`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)(Xw,{title:e.label,children:y(e)},e.id)),b.map(e=>(0,B.jsx)(Xw,{title:e.label,children:x(e)},e.id)),S&&(0,B.jsx)(Xw,{title:Aw(`date`),children:S}),C.length>0&&(0,B.jsx)(Xw,{title:Aw(`showOnly`),children:C})]});let{shown:w,more:T}=cT(e,m),E=e=>{h(t=>sT(t,[e])),_(e)},D=[...e.facets.filter(e=>w.has(`facet:${e.id}`)).map(e=>(0,B.jsx)(Yw,{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)(Yw,{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)(lT,{label:e.label,checked:u.toggles.includes(e.id),onChange:()=>d(zw(u,e.id))})},e.id)),k=[c?[(0,B.jsx)(I.Fragment,{children:c},`leading`)]:[],D,O,T.length>0?[(0,B.jsx)($w,{items:T,onPick:E},`more`)]:[]];return!uT(k,l)&&f.length===0&&!a?.length?null:(0,B.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,B.jsx)(dT,{groups:k,trailing:l}),v]})},mT=sn(),hT={start:0,end:0},gT={"24h":{amount:24,unit:`h`},"7d":{amount:7,unit:`d`},"30d":{amount:30,unit:`d`},"90d":{amount:90,unit:`d`}},_T=e=>new Date(e).toISOString().replace(`.000Z`,`Z`),vT=(e,t,n)=>{let r=Zf(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},yT=[`year`,`quarter`,`month`,`yesterday`,`today`],bT=(e,t,n)=>t===`date`?e:_T($f(e,n)),xT=(e,t,n)=>t===`date`?{kind:`string`,value:bT(e,t,n),span:hT}:{kind:`timestamp`,value:bT(e,t,n),span:hT},ST=(e,t,n,r,i)=>{if(t in gT)return[mT.gte(e,mT.ago(t))];let a=mT.gte(e,xT(vT(t,n,i),r,i));return t===`yesterday`?[a,mT.lt(e,xT(vT(`today`,n,i),r,i))]:[a]},CT=(e,t,n=new Date,r=Gf())=>{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=>mT.eq(e.value,!0));return t.length===0?[]:[t.length===1?t[0]:mT.or(...t)]}return[n.length===1?mT.eq(e.id,n[0]):mT.in(e.id,n)]}),a=(e.ranges??[]).flatMap(e=>{let n=t.ranges?.[e.id];return n?[mT.gte(e.id,n[0]),mT.lte(e.id,n[1])]:[]}),o=e.dateField&&t.date?ST(e.dateField,t.date,n,e.dateKind,r):[],s=(e.toggles??[]).filter(e=>t.toggles.includes(e.id)).map(e=>mT.eq(e.id,!0));return[...i,...a,...o,...s]},wT=e=>e.length===0?``:Yt(mT.and(...e)),TT=(e,t,n=[],r=new Date,i=Gf())=>wT([...CT(e,t,r,i),...n]),ET=e=>e.kind===`and`?e.args.flatMap(ET):[e],DT=e=>e.field.path.join(`.`),OT=e=>e.kind===`compare`&&e.op===`=`&&e.value.kind===`boolean`&&e.value.value,kT=(e,t)=>{let n=e.kind===`or`?e.args:[e];if(!n.every(OT))return;let r=n.map(DT),i=t.get(r[0]);return i!==void 0&&r.every(e=>t.get(e)===i)?{group:i,fields:r}:void 0},AT=e=>e.kind===`number`?String(e.raw):e.kind===`string`?String(e.value):void 0,jT=(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(gT).find(([,n])=>n.amount===e&&n.unit===t)?.[0]}if(r.kind===`timestamp`)return yT.find(e=>bT(vT(e,t,n),`timestamp`,n)===r.value);if(r.kind===`string`)return yT.find(e=>vT(e,t,n)===r.value)},MT=(e,t,n=new Date,r=Gf())=>{let i=it(t);if(!i.ok)return{ok:!1,errors:i.errors};let a={facets:{},toggles:[]},o=[],s=new Set(e.facets.filter(e=>!e.flags).map(e=>e.id)),c=new Map(e.facets.filter(e=>e.flags).flatMap(e=>e.options.map(t=>[t.value,e.id]))),l=new Set((e.toggles??[]).map(e=>e.id)),u=new Set((e.ranges??[]).map(e=>e.id)),d=new Map,f,p;for(let t of i.ast?ET(i.ast):[]){let i=kT(t,c);if(i&&!a.facets[i.group])a.facets[i.group]=i.fields;else if(t.kind===`compare`&&s.has(DT(t))&&t.op===`=`&&AT(t.value)!==void 0)a.facets[DT(t)]=[...a.facets[DT(t)]??[],AT(t.value)];else if(t.kind===`in`&&s.has(DT(t))&&t.values.every(e=>AT(e)!==void 0))a.facets[DT(t)]=[...a.facets[DT(t)]??[],...t.values.map(e=>AT(e))];else if(t.kind===`compare`&&e.dateField===DT(t)&&t.op===`>=`&&jT(t,n,r)&&!a.date)a.date=jT(t,n,r),f=t;else if(t.kind===`compare`&&e.dateField===DT(t)&&t.op===`<`&&(t.value.kind===`timestamp`||t.value.kind===`string`)&&t.value.value===bT(vT(`today`,n,r),t.value.kind===`string`?`date`:`timestamp`,r))p=t;else if(t.kind===`compare`&&l.has(DT(t))&&t.op===`=`&&t.value.kind===`boolean`&&t.value.value)a.toggles.push(DT(t));else if(t.kind===`compare`&&u.has(DT(t))&&(t.op===`>=`||t.op===`<=`)&&t.value.kind===`number`){let e=d.get(DT(t))??{clauses:[]};t.op===`>=`?e.low=t.value.value:e.high=t.value.value,e.clauses.push(t),d.set(DT(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}},NT=[`integer`,`bigint`,`decimal`],PT=(e,t)=>{let n=e?.fields[t]?.type;return n!==void 0&&NT.includes(n)},FT=(e,t)=>e.kind===`range`||e.kind===`facets`&&PT(t,e.field),IT=e=>e.secondary?{secondary:!0}:{},LT=e=>({id:e.field,label:e.field,min:0,max:0,step:1,histogram:[],format:String,...IT(e)}),RT=(e,t)=>{let n=e?.filters??[],r=n.find(e=>e.kind===`dateRange`);return{facets:n.flatMap(e=>e.kind===`facets`&&!FT(e,t)?[{id:e.field,label:e.field,options:[],searchable:e.search,...t?.fields[e.field]?.type===`relation`&&{combobox:!0},...IT(e)}]:e.kind===`flags`?[{id:e.fields.join(`|`),label:e.label,options:e.fields.map(e=>({value:e,label:e,count:0})),flags:!0,...IT(e)}]:[]),ranges:n.flatMap(e=>e.kind!==`flags`&&FT(e,t)?[LT(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,...IT(e)}]:[])}},zT=(e,t)=>(e?.filters??[]).some(e=>e.kind===`range`&&e.field===t&&e.histogram),BT=(e,t)=>{let n=e?.fields[t],r=n?.suffix??``,i=n?.currency;return i===void 0?e=>`${n?.prefix??``}${e}${r}`:e=>`${kp(e*100,i).replace(`.00`,``)}${r}`},VT=sn(),HT={start:0,end:0},UT=(e,t,n)=>{let r=MT(RT(t,e),n);return r.ok?Object.fromEntries(Object.entries(r.state.facets).filter(([t,n])=>e.fields[t]?.type===`relation`&&n.length>0)):{}},WT=(e,t,n)=>{let r=e=>t?.fields[e]?.label??F(e),i=RT(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,ir(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:BT(t,e.id)})),toggles:i.toggles?.map(e=>({...e,label:r(e.id)}))}},GT=(e,t,n,r={})=>{let i=WT(e,t,r),a=MT(i,n);if(!a.ok)return[{key:`unreadable`,label:Y(`unreadableFilter`)}];let o=a.extras.map((e,t)=>({key:`extra:${t}`,label:e.kind===`search`?`"${e.text}"`:Yt(e)}));return[...Hw(i,a.state),...o]},KT=e=>Object.fromEntries(e.facets.filter(e=>!e.flags).map(e=>[e.id,{...e.labels,...Object.fromEntries(e.options.map(e=>[e.value,e.label]))}])),qT=(e,t,n)=>{if(typeof n!=`string`||n===``)return e;let r=VT.gt(t,{kind:`timestamp`,value:new Date(n).toISOString(),span:HT}),i=it(e);if(!i.ok)throw Error(`The saved filter cannot be read: ${i.errors.map(e=>e.message).join(`; `)}`);return Yt(i.ast?VT.and(i.ast,r):r)},JT=(e,t)=>typeof t!=`string`||t===``?!0:typeof e!=`string`||e===``?!1:new Date(e).getTime()>new Date(t).getTime(),YT=(e,t)=>{let n=U(),r=Se(),{resources:i,views:a}=W(),o=a[e.name],s=Object.entries(UT(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 xb(r,n,s,o,a[s.name]))}})});return GT(e,o,t,Object.fromEntries(s.flatMap(([e],t)=>c[t]?.data?[[e,c[t].data]]:[])))},XT=(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}}),ZT=e=>{let t=Se();return(0,I.useCallback)(n=>t.setQueryData(H.recordPreview(e.name,Nn(ym(e,n))),XT(e,n)),[t,e])},QT={wallet:dc,"file-text":Sa,send:ds,ruler:as,bed:Xr,bath:Jr,house:Aa,"door-open":ea,"land-plot":Ra,leaf:Ka,tag:Vs,key:Ia,calendar:gi,heart:Oa,bell:ni,bookmark:ui,"external-link":ua,ban:Kr,play:Uo,stop:js,power:Yo,restart:rs,terminal:Gs,camera:vi,"hard-drive":Ea,server:ps,network:jo,archive:Mr,copy:Ji,"arrow-right-left":Ir,download:na,upload:Zs,cpu:Xi,memory:po,plug:Go,wrench:_c},$T=e=>e!==void 0&&Object.hasOwn(QT,e)?QT[e]:void 0,eE=({target:e,id:t})=>(0,B.jsx)(B.Fragment,{children:Mb(e,t)??t}),tE=()=>{let{path:e,params:t,basePath:n,navigate:r}=jh(),i=(0,I.useMemo)(()=>$c(e,t),[e,t]),a=wd(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(Qc({step:e,next:o}),t),[r,o]);return{address:i,next:o,open:s,link:(0,I.useCallback)((e=`sign-in`,t)=>({href:`${n}${Qc({step:e,next:o})}`,onFollow:()=>s(e,t)}),[n,o,s]),leave:(0,I.useCallback)(()=>r(o??`/`,{replace:!0}),[r,o])}},nE=({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)(Si,{className:`mt-0.5 size-4 shrink-0 text-primary`,"aria-hidden":!0}),e]},e))}):null,rE=({prompt:e})=>{let{canSignUp:t}=V(),{link:n}=tE(),r=mf({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)(Sh,{to:n(`sign-up`),className:r,children:z(`createAnAccount`)});return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(Sh,{to:n(),className:i?mf():r,children:z(`signIn`)}),i]})},iE=e=>{let{prompt:t}=e,n=(0,I.useId)();if(e.as===`dialog`)return(0,B.jsx)(Ef,{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)(rE,{prompt:t})]}),children:(0,B.jsx)(nE,{benefits:t.benefits})});let r=$T(t.icon)??io;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)(nE,{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)(rE,{prompt:t})})]})},aE=sn(),oE=e=>{if(typeof e==`string`||typeof e==`number`)return e;if(e&&typeof e==`object`&&`id`in e)return oE(e.id)},sE=(e,t,n)=>n.flatMap(n=>{let r=oE(n[t]);return r===void 0?[]:[{key:Nn(ym(e,n)),target:r}]}),cE=(e,t)=>e.find(e=>Nn(e.target)===t),lE=(e,t)=>[...e,{key:``,target:t}],uE=(e,t)=>e.filter(e=>Nn(e.target)!==t),dE=(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:aE.in(n,r)},fE=(e,t)=>H.list(e,``,``,500,`saved:${t}`),pE=(e,t,n)=>{let r=U(),i=W().resources[e];return E({queryKey:fE(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 sE(i,t,n)}})},mE=M(`app/saved`),hE=e=>e instanceof Error?e.message:mE(`somethingWrong`),gE=(e,t,n)=>{let r=W(),i=U(),a=Se(),s=iy(),c=Cy(),{resource:l,field:u}=e,d=r.permissions[l],f=r.resources[l]!==void 0&&d!==void 0&&oy(d,`create`)&&oy(d,`delete`),p=r.signIn?.[l]?.signIn,m=pE(l,u,f),h=m.data&&cE(m.data,t),g=fE(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?uE(r,t):lE(r,n)),{before:r}},onError:(e,t,n)=>{a.setQueryData(g,n?.before),s.show({state:`error`,title:mE(t?`couldNotTakeOff`:`couldNotSave`),description:hE(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)}},_E=({favorite:e,recordKey:t,target:n,className:r})=>{let i=gE(e,t,n),[a,o]=(0,I.useState)(!1);if(!i.mode)return null;let s=e.label??mE(`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)(Oa,{className:`size-4`,"aria-hidden":!0})}),(0,B.jsx)(iE,{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)(Oa,{className:P(`size-4`,i.saved&&`fill-current text-danger`),"aria-hidden":!0})})},vE=6,yE=(e,t,n)=>{let r=e.bottom+vE;return{top:r+t.height>n.height-vE?Math.max(vE,e.top-vE-t.height):r,left:Math.max(vE,Math.min(e.left,n.width-vE-t.width))}},bE=(e,t)=>{let n=Wm(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},xE=(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:oh(r,n[r.name],bE(n[r.name],e.status))}]:[]}),SE=M(`app/related-dots`),CE=(e,{values:t,label:n,singular:r,plural:i})=>{if(e.length===0)return SE(`none`,{plural:i});let a=new Map;for(let t of e)t!=null&&a.set(String(t),(a.get(String(t))??0)+1);let o=[...t,...[...a.keys()].filter(e=>!t.includes(e))].filter(e=>a.has(e)).map(e=>`${a.get(e)} ${n(e)}`),s=`${e.length} ${e.length===1?r:i}`;return o.length===0?s:`${s}: ${o.join(`, `)}`},wE=`flex shrink-0 items-center justify-center rounded-full p-0.5 pointer-coarse:p-1.5`,TE=`size-2.5 rounded-full`,EE=`flex min-w-0 items-center gap-0.5`,DE=150,OE=288,kE=({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(yE(e.dot,{width:OE,height:c.current.offsetHeight},{width:window.innerWidth,height:window.innerHeight}))},[e]),(0,Sc.createPortal)((0,B.jsx)(`div`,{ref:c,"data-dot-card":!0,onMouseEnter:o,onMouseLeave:s,style:{width:OE,...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:bE(r,i.status),row:t})}),document.body)},AE=({column:e,records:t,target:n,view:r,wrap:i=!1,Card:a})=>{let o=(0,I.useMemo)(()=>t.map(e=>uh(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?Nm(f,t.record[e.status],p):``,h=cr(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=CE(o.map(t=>t.record[e.status]),{values:f?.enumValues??[],label:e=>f?Nm(f,e,p):e,singular:_,plural:v}),b=()=>window.clearTimeout(l.current),x=()=>{b(),l.current=window.setTimeout(()=>c(void 0),DE)},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(EE,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=Tm(p?.valueColors,r);return(0,B.jsx)(Uh,{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(wE,`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(TE,i===void 0&&Mf[Em(p?.valueColors,r)],s?.key===t.key&&`ring-2 ring-foreground/30`)})},t.key)}),s&&T&&(0,B.jsx)(kE,{shown:s,row:T,target:n,view:r,column:e,Card:a,onEnter:b,onLeave:x})]})},jE=({count:e})=>(0,B.jsx)(`span`,{"aria-hidden":!0,className:P(EE,`invisible flex-wrap`),children:Array.from({length:e},(e,t)=>(0,B.jsx)(`span`,{className:wE,children:(0,B.jsx)(`span`,{className:TE})},t))}),ME=`flex flex-col gap-1.5`,NE=({dots:e})=>(0,B.jsx)(`span`,{className:ME,children:e.map(({column:e,records:t})=>(0,B.jsx)(jE,{count:t.length},e.name))}),PE=({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)] ${ME}`,children:e.map(({column:e,records:i})=>{let a=n[e.resource];return a&&(0,B.jsx)(AE,{column:e,records:i,target:a,view:r[a.name],Card:t,wrap:!0},e.name)})})},FE=(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}]:[]}),IE=M(`carousel`),LE=`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`,RE=`[@media(hover:none)]:opacity-100`,zE=({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":IE(`previousPhoto`),className:P(LE,r,!n&&RE,`left-2`),onClick:()=>o(-1),children:(0,B.jsx)(Ei,{className:`size-4`,"aria-hidden":!0})}),(0,B.jsx)(`button`,{type:`button`,"aria-label":IE(`nextPhoto`),className:P(LE,r,!n&&RE,`right-2`),onClick:()=>o(1),children:(0,B.jsx)(Oi,{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:IE(`photoOf`,{index:a+1,count:t})}),(0,B.jsx)(`span`,{className:`flex items-center gap-1 rounded-full bg-background/70 px-1.5 py-1 leading-none`,"aria-hidden":!0,children:Array.from({length:t},(e,t)=>(0,B.jsx)(`span`,{className:P(`size-1.5 rounded-full`,t===a?`bg-foreground`:`bg-foreground/35`)},t))})]})]})},BE=({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))}),VE=(e,t)=>t===0?0:(e%t+t)%t,HE=(e,t,n)=>t<=0||n===0?0:Math.min(n-1,Math.max(0,Math.round(e/t))),UE=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=VE((n.current??r)+t,e),a(n.current)},touch:()=>{n.current=void 0},scrolled:t=>{i(HE(t.scrollLeft,t.clientWidth,e)),n.current!==void 0&&Math.abs(t.scrollLeft-n.current*t.clientWidth)<1&&(n.current=void 0)}}},WE=({value:e})=>{let t=Vp(e,{width:320,height:240});return t?(0,B.jsx)(j_,{image:t,loading:`lazy`,className:`size-full object-cover`}):null},GE=({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}),KE=({value:e})=>(0,B.jsx)(GE,{children:(0,B.jsx)(WE,{value:e})}),qE=10,JE=(e,t)=>{let n=jp(e)?e.uri:void 0,r=t.filter(e=>jp(e)&&e.uri!==n);return(n===void 0?r:[e,...r]).slice(0,qE)},YE=({photos:e,cover:t,swipe:n=!0,children:r})=>{let i=JE(t,e),a=UE(i.length),o=(0,B.jsx)(GE,{children:(0,B.jsx)(BE,{"data-card-photos":!0,carousel:a,swipe:n,slides:i.map(e=>(0,B.jsx)(WE,{value:e}))})});return(0,B.jsxs)(B.Fragment,{children:[r(o),(0,B.jsx)(zE,{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]`})]})},XE=({icon:e,children:t})=>{let n=$T(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]})},ZE=({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}=th(e,t,n),m=e=>t?.fields[e]?.label??F(e),{resources:h,views:g}=W(),_=n=>{let i=e.fields[n];if(!i)return``;let a=r.record[n],o=i.type===`relation`&&i.relation?h[i.relation.resource]:void 0;return o&&g[o.name]?.titleFrom&&a!=null?(0,B.jsx)(eE,{target:o,id:String(a)}):r.labels[n]===void 0&&gm(i,t?.fields[n])&&typeof a==`string`&&a!==``?hm(a):r.labels[n]??Nm(i,a,t?.fields[n])},{fields:v,components:y}=c_(),b=ZT(e),x=n.card===void 0?void 0:y?.[n.card],S=n=>{let i=e.fields[n],a=i&&ev(v,i,t?.fields[n]);return a?(0,B.jsx)(dv,{shown:a,part:`display`,field:i,value:r.record[n],fallback:_(n)}):_(n)},C=n=>{let i=e.fields[n],a=r.record[n];return!i||!gm(i,t?.fields[n])||ev(v,i,t?.fields[n])||typeof a!=`string`||a===``?S(n):(0,B.jsx)(pv,{source:a,inLink:!0})},w=n=>{let i=e.fields[n],a=t?.fields[n],o=r.record[n];return!i||a?.format!==`badge`||ev(v,i,a)||o==null||o===``?S(n):(0,B.jsx)(Nb,{value:o,hints:a,children:_(n)})},T=n=>{let i=e.fields[n];if(!i)return;if(r.labels[n]!==void 0||ev(v,i,t?.fields[n]))return(0,B.jsx)(`strong`,{className:`font-semibold text-foreground`,children:S(n)});let a=ih(i,r.record[n],t?.fields[n]);return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`strong`,{className:`font-semibold text-foreground`,children:a.amount}),a.suffix]})},E=x?void 0:n.photos,D=u===void 0?void 0:r.record[u],O=p.filter(e=>r.record[e]===!0),k=o===void 0?void 0:r.record[o],A=rh(r,l),j=nh(r,f),ee=o!==void 0||E!==void 0,te=n.favorite,ne=x?[]:FE(t,n,r),re=e=>(0,B.jsxs)(B.Fragment,{children:[ee&&e,(0,B.jsxs)(`span`,{className:`flex items-start justify-between gap-2 ${te&&!ee?`pr-8`:``}`,children:[(0,B.jsx)(`span`,{className:`min-w-0 truncate font-medium`,children:S(s)}),u!==void 0&&D!=null&&(0,B.jsx)(Nb,{value:D,hints:t?.fields[u],children:_(u)})]}),c!==void 0&&(0,B.jsx)(`span`,{className:t?.fields[c]?.markdown?`line-clamp-3 break-words text-muted-foreground`:t?.fields[c]?.multiline?`line-clamp-3 whitespace-pre-line break-words text-muted-foreground`:`truncate text-muted-foreground`,children:C(c)}),A!==void 0&&(0,B.jsx)(`span`,{className:`truncate tabular-nums text-muted-foreground`,children:T(A)}),d.length>0&&(0,B.jsx)(`dl`,{className:`mt-auto flex flex-wrap items-center gap-x-3 gap-y-0.5 pt-1 text-xs text-muted-foreground`,children:nh(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)(XE,{icon:t?.fields[e]?.icon,children:w(e)})]},e))}),O.length>0&&(0,B.jsx)(`ul`,{className:`flex flex-wrap gap-1`,"aria-label":K(`features`),children:O.map(e=>(0,B.jsx)(`li`,{children:(0,B.jsx)(Pf,{dot:!1,children:m(e)})},e))}),j.length>0&&(0,B.jsx)(`span`,{className:`truncate text-xs text-muted-foreground ${d.length>0?``:`mt-auto`}`,children:j.map((e,t)=>(0,B.jsxs)(`span`,{children:[t>0&&(0,B.jsx)(`span`,{"aria-hidden":!0,children:` • `}),S(e)]},e))}),ne.length>0&&(0,B.jsx)(NE,{dots:ne})]}),ie=t=>(0,B.jsxs)(Uh,{to:{kind:`record`,resource:e.name,key:r.key},onClick:()=>b(r.record),className:`flex h-full flex-col gap-1.5 rounded-lg border border-border bg-background p-3 hover:border-border-strong hover:bg-surface focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/30`,children:[a&&!ee&&(0,B.jsx)(Pf,{tone:`blue`,className:`self-start`,children:a}),x?(0,B.jsx)(cv,{name:n.card,fallback:re(t),children:(0,B.jsx)(x,{row:r})}):re(t)]});return(0,B.jsxs)(`div`,{className:E?`group/card relative h-full`:te||a||ne.length>0?`relative h-full`:`h-full`,children:[E?(0,B.jsx)(YE,{photos:r.photos??[],cover:k,swipe:i,children:ie},r.key):ie((0,B.jsx)(KE,{value:k})),a&&ee&&(0,B.jsx)(Pf,{tone:`blue`,className:`pointer-events-none absolute top-2 left-2 shadow-sm`,children:a}),ne.length>0&&(0,B.jsx)(PE,{dots:ne,Card:ZE}),te&&(0,B.jsx)(_E,{favorite:te,recordKey:r.key,target:ym(e,r.record),className:ee?void 0:`right-1.5 top-1.5`})]})},QE=268,$E=3,eD=(e,t,n)=>{let r=Math.floor(Math.max(0,e)/QE),i=Math.ceil((Math.max(0,e)+t)/QE);return{start:Math.max(0,r-$E),end:Math.min(n,i+$E)}},tD=e=>e*QE,nD=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]=[eD(t.left,t.width,e),eD(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,tD(e)-12),a=e=>t.current?.scrollBy({left:e*Math.max(tD(1),n.width-12),behavior:`smooth`});return{ref:t,...eD(n.left,n.width,e),back:n.left>0,on:n.left+n.width<i-1,page:a}},rD=M(`app/record-row`),iD=`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`,aD=({cards:e})=>e>0?(0,B.jsx)(`li`,{"aria-hidden":!0,className:`shrink-0`,style:{width:tD(e)-12}}):null,oD=({model:e,view:t,display:n,source:r,label:i,isNew:a})=>{let{total:o}=r,s=nD(o),c=GC({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)(aD,{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)(vh,{className:`h-full min-h-24 rounded-lg`})},`skeleton-${r}`);let s=uh(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)(ZE,{model:e,view:t,display:n,row:s,swipe:!1,mark:a?.(s)?rD(`new`):void 0})},s.key)}),(0,B.jsx)(aD,{cards:o-s.end})]}),s.back&&(0,B.jsx)(`button`,{type:`button`,"aria-label":rD(`previous`,{label:i.toLowerCase()}),onClick:()=>s.page(-1),className:`${iD} -left-3`,children:(0,B.jsx)(Ei,{className:`size-4`,"aria-hidden":!0})}),s.on&&(0,B.jsx)(`button`,{type:`button`,"aria-label":rD(`next`,{label:i.toLowerCase()}),onClick:()=>s.page(1),className:`${iD} -right-3`,children:(0,B.jsx)(Oi,{className:`size-4`,"aria-hidden":!0})})]})},sD=sn(),cD=(e,t)=>{if(!t)return e;let n=it(e);if(!n.ok)throw Error(`The filter cannot be read: ${n.errors.map(e=>e.message).join(`; `)}`);return Yt(n.ast?sD.and(n.ast,t):t)},lD=(e,t)=>{let n=Wm(e).filter(e=>e.kind===`cards`);return n.find(e=>e.name===t)??n[0]??{kind:`cards`,name:`cards`}},uD=()=>(0,B.jsx)(`div`,{className:`flex gap-3 overflow-hidden`,children:Array.from({length:3},(e,t)=>(0,B.jsx)(vh,{className:`h-24 w-64 shrink-0`},t))}),dD=({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=_f(),g=lD(t,i),_=r||dh(e,t),v=Tw({resources:p,views:m,model:e,columns:(0,I.useMemo)(()=>sh(e,t,[]),[e,t]),filter:(0,I.useMemo)(()=>cD(n,d),[n,d]),orderBy:_}),y=YT(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)(Dw,{chips:y}):(0,B.jsx)(`span`,{}),(0,B.jsxs)(`p`,{className:`flex flex-wrap gap-x-3 text-muted-foreground`,children:[c&&(0,B.jsx)(`span`,{children:c}),S!==void 0&&(0,B.jsx)(`span`,{className:`tabular-nums`,children:`${S.toLocaleString(Le())} ${S===1?b:x.toLowerCase()}`})]})]}):null,v.isLoading?(0,B.jsx)(uD,{}):v.error?(0,B.jsx)(Bg,{title:rD(`couldNotLoad`),error:v.error}):!C||C.total===0?(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:s??rD(`noneMatch`,{plural:x.toLowerCase()})}):(0,B.jsx)(oD,{model:e,view:t,display:g,source:C,label:x,isNew:l}),(0,B.jsxs)(Uh,{to:zS(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:[rD(`viewAll`),` `,(0,B.jsx)(`span`,{className:`sr-only`,children:x.toLowerCase()})]}),(0,B.jsx)(Rr,{className:`size-3.5`,"aria-hidden":!0})]})]})},fD=({model:e,view:t,empty:n,...r})=>{let{resources:i,views:a}=W(),o=mh(i,a,e.name),s=pE(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)(Bg,{title:rD(`couldNotLoadYour`,{plural:c}),error:s.error});if(!s.data)return(0,B.jsx)(vh,{className:`h-24`});let l=dE(o.model,s.data);return l?(0,B.jsx)(dD,{...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??rD(`noneYet`,{plural:c})})},pD=e=>H.list(e,``,``,500,`saved-searches`),mD=(e,t)=>{let n=U(),{resources:r,views:i}=W(),a=r[e];return E({queryKey:pD(e),enabled:t&&a!==void 0,queryFn:async()=>{let t=[],r;do{let o=await n.list(e,{pageSize:500,orderBy:dh(a,i[e]),...r&&{pageToken:r}});t.push(...o.items),r=o.nextPageToken||void 0}while(r);return t}})},hD=({model:e,of:t,target:n,targetView:r,row:i,recordKey:a})=>{let s=U(),c=Cy(),l=String(i[t.filter]??``),u=YT(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({...yy(s,n,p?qT(l,p.field,i[p.seenAt]):``),enabled:p!==void 0}),g=(r?.names?.plural??F(n.name)).toLowerCase(),_={model:n,view:r,filter:l,sort:p?`${p.field} desc`:void 0,limit:t.limit,chips:f!==void 0,empty:Y(`noneMatch`,{plural:g}),note:p&&h.data===0&&Y(`noNew`,{plural:g}),isNew:p&&(e=>JT(e.record[p.field],i[p.seenAt])),viewAll:{label:Y(`viewAll`),savedSearch:a,...p&&{onOpen:()=>m.mutate(new Date().toISOString())}}};return{name:f,chips:u,title:f??kw(u),body:_}},gD=({model:e,view:t,target:n,targetView:r,row:i})=>{let a=Nn(ym(e,i)),{name:o,chips:s,title:c,body:l}=hD({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)(Uh,{to:{kind:`record`,resource:e.name,key:a},className:`hover:underline`,children:o??(0,B.jsx)(Ow,{chips:s})})}),(0,B.jsx)(dD,{...l})]})},_D=({model:e,view:t,empty:n})=>{let{resources:r,views:i}=W(),a=t.searchesOf,o=r[a.resource],s=mD(e.name,!0),c=(t.names?.plural??F(e.name)).toLowerCase();return o?s.error?(0,B.jsx)(Bg,{title:Y(`couldNotLoadYour`,{plural:c}),error:s.error}):s.data?s.data.length===0?(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:n??Y(`noneYet`,{plural:c})}):(0,B.jsx)(`div`,{className:`flex flex-col divide-y`,children:s.data.map(n=>(0,B.jsx)(gD,{model:e,view:t,target:o,targetView:i[a.resource],row:n},Nn(ym(e,n))))}):(0,B.jsx)(vh,{className:`h-40`}):null},vD=({node:e,slots:t})=>{let{resource:n,filter:r=``,sort:i,limit:a,display:o,title:s,description:c,empty:l}=Dy(e),{resources:u,views:d}=W(),f=u[n];if(!f)return null;let p=d[f.name];return(0,B.jsx)(Ay,{title:s,description:c,actions:t.actions,children:p?.searchesOf?(0,B.jsx)(_D,{model:f,view:p,empty:l}):p?.listOf===void 0?(0,B.jsx)(dD,{model:f,view:p,filter:r,sort:i,limit:a,display:o,empty:l}):(0,B.jsx)(fD,{model:f,view:p,limit:a,display:o,empty:l})})},yD=e=>e.type===`boolean`||e.type===`enum`,bD=({model:e,fields:t,title:n,description:r,stored:i})=>{let{resources:a,views:o}=W(),s=af(e.name),c=U(),l=iy(),u=Cy(),d=o[e.name],[f,p]=(0,I.useState)(i),[m,h]=(0,I.useState)(()=>cx(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=cx(e,t,void 0),T=f?oy(s,`update`)&&f.permissions?.update!==!1:oy(s,`create`),E=t.filter(t=>!yD(e.fields[t])),D=E.some(t=>f?Sg(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,lx(e,t,n.record),n.etag??`*`);return{...vy(e,r.record),etag:r.etag,permissions:r.permissions??n.permissions}}let r=await c.create(e.name,Mg(e,a,{...w,...t}));return{...vy(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:sv(`saved`,{label:n??sv(`settings`)})})},e=>{_(t=>({...t,...ax(e)})),y(e)}),x(!1)});S.current=r},A=(t,n)=>{h(e=>({...e,[t]:n})),yD(e.fields[t])&&k({[t]:n})};return(0,B.jsx)(Ay,{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)(Bg,{title:sv(`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)(Yh,{name:t,label:r,help:d?.fields[t]?.help,error:i&&ix(n,r,i),children:(0,B.jsx)(Ov,{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:sv(`save`)})})]})})},xD=e=>{let t=xy(e.model,{});return t.isPending?(0,B.jsx)(Ay,{title:e.title,description:e.description,children:(0,B.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,B.jsx)(vh,{className:`h-4 w-1/2`}),(0,B.jsx)(vh,{className:`h-4 w-1/3`})]})}):t.error?(0,B.jsx)(Ay,{title:e.title,description:e.description,children:(0,B.jsx)(Bg,{title:sv(`couldNotLoad`),error:t.error})}):(0,B.jsx)(bD,{...e,stored:t.data??void 0})},SD=({node:e})=>{let{resource:t,fields:n=[],...r}=Dy(e),i=W().resources[t];return i?(0,B.jsx)(xD,{...r,model:i,fields:n.filter(e=>Object.hasOwn(i.fields,e)),stored:void 0}):null},CD=(e,t)=>{let{resources:n}=W(),r=U(),i=JSON.stringify(e),a=(0,I.useMemo)(()=>JSON.parse(i).map(mu),[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=gu(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=Hb(t,l),p=f({queries:u.map(e=>yy(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 hu(e,t)})},wD=({node:e,children:t})=>{let{when:n}=Dy(e),[r]=CD([n],Yv());return r?(0,B.jsx)(B.Fragment,{children:t}):null},TD=`text-2xl font-semibold tracking-tight tabular-nums`,ED=({model:e,filter:t})=>{let{views:n}=W(),r=by(e,t);return r.isPending?(0,B.jsx)(vh,{className:`h-8 w-16`}):r.error?(0,B.jsx)(`span`,{className:`text-danger-text`,children:sv(`couldNotCount`)}):(0,B.jsx)(Uh,{to:Xy(n[e.name],e.name,t),className:`${TD} hover:text-primary-text after:absolute after:inset-0 after:content-['']`,children:r.data.toLocaleString(Le())})},DD=({field:e,format:t})=>{let n=Vb(Yv(),e);return n.state===`loading`?(0,B.jsx)(vh,{className:`h-8 w-16`}):n.state===`missing`?null:(0,B.jsx)(`span`,{className:TD,children:(0,B.jsx)(Lb,{model:n.model,field:n.field,value:n.value,format:t})})},OD=({node:e})=>{let{label:t,value:n,resource:r,filter:i,field:a,format:o,description:s}=Dy(e),{resources:c}=W(),l=r===void 0?void 0:c[r];return(0,B.jsxs)(Ay,{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:TD,children:n}),l&&(0,B.jsx)(ED,{model:l,filter:i}),a!==void 0&&(0,B.jsx)(DD,{field:a,format:o})]}),s&&(0,B.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:s})]})},kD=(e,t)=>{let n=e.position;if(!n||!oy(t,`update`))return;let r=e.fields[n.field];return r&&!r.readOnly?n.field:void 0},AD=(e,t)=>e.position?.within===void 0?kD(e,t):void 0,jD=(e,t,n)=>t.position?.within!==void 0&&e.field===t.position.within&&!e.through&&!e.from&&!e.filter?kD(t,n):void 0,MD=(e,t,n,r)=>{if(t===void 0||e?.list?.drag?.rank!==!0||r!==``)return!1;let i=fh(n);return i.columnId===t&&i.direction===`asc`},ND=e=>e===null?`none`:`value:${e}`,PD=e=>e.data.current?.sortable!==void 0,FD=e=>{let t=le(e),n=t.find(e=>e.data?.droppableContainer&&PD(e.data.droppableContainer));return n?[n]:t.length>0?t:ce(e)},ID=(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=>!PD(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=LD(o,n,d.id)[0];return{x:d.rect.left+(d.rect.width-t.width)/2,y:f?.rect.top??d.rect.top}},LD=(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),RD=(e,t)=>{let n=e.code===`ArrowDown`?1:e.code===`ArrowUp`?-1:0;if(n===0)return ID(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=LD(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}},zD=(e,t,n,r)=>{let i=Ne({queryKey:[...n,`display`],enabled:r,initialPageParam:0,queryFn:({pageParam:e})=>t(e),getNextPageParam:(e,t)=>e.rows.length===40&&t.length*40<(t[0]?.total??0)?t.length:void 0}),a=i.data?.pages??[];return{resource:e.name,rows:a.flatMap(t=>t.rows.map(t=>uh(e,t))),total:a[0]?.total??0,loading:i.isPending,error:i.error,more:i.hasNextPage,loadMore:()=>void i.fetchNextPage()}},BD=({model:e,by:t,value:n,fields:r,filter:i,orderBy:a})=>{let{resources:o,views:s}=W(),c=Tw({resources:o,views:s,model:e,columns:r,filter:Vm(i,t,n),orderBy:a});return zD(e,c.page,c.key,!0)},VD=(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))]},HD=({model:e,view:t,display:n,column:r,fields:i,filter:a,orderBy:o,limit:s,moves:c,movable:l,placeable:u,dragged:d})=>{let f=BD({model:e,by:n.by,value:r.value,fields:i,filter:a,orderBy:o}),p=Hm(e,t,n),m=new Set(f.rows.map(e=>e.key)),h=new Map(c.map(e=>[e.row.key,e])),g=f.rows.filter(e=>h.has(e.key)&&h.get(e.key).to!==r.value),_=c.filter(e=>e.to===r.value&&!m.has(e.row.key)).map(e=>e.row),v=f.rows.filter(e=>!g.includes(e)).map(e=>h.has(e.key)?h.get(e.key).row:e),y=c.findLast(e=>e.to===r.value&&e.order),b=VD([..._,...v],y?.order).slice(0,s),{setNodeRef:x,isOver:S}=ke({id:ND(r.value),data:{column:r,rows:b}}),C=f.total-g.length+_.length;if(r.value===null&&!f.loading&&C===0&&!S)return null;let w=(t?.names?.plural??F(e.name)).toLowerCase(),T=t?.fields[n.by];return(0,B.jsxs)(`section`,{ref:x,"aria-label":`${r.label}, ${C}`,className:P(`flex w-72 shrink-0 snap-start flex-col gap-2 rounded-lg bg-surface p-2`,S&&`ring-2 ring-primary/30`),children:[(0,B.jsxs)(`header`,{className:`flex items-center justify-between gap-2 px-1 pt-0.5`,children:[(0,B.jsx)(`h2`,{className:`min-w-0 truncate text-body font-medium`,children:r.value===null?(0,B.jsx)(`span`,{className:`text-muted-foreground`,children:r.label}):(0,B.jsx)(Nb,{value:r.value,hints:T,children:r.label})}),!f.loading&&(0,B.jsx)(`span`,{className:`text-xs tabular-nums text-muted-foreground`,children:C.toLocaleString(Le())})]}),f.loading?Array.from({length:3},(e,t)=>(0,B.jsx)(vh,{className:`h-20`},t)):f.error?(0,B.jsx)(Bg,{title:K(`couldNotLoadRows`),error:f.error}):b.length===0?(0,B.jsx)(`p`,{className:`px-1 py-4 text-center text-xs text-muted-foreground`,children:K(`noPlural`,{plural:w})}):(0,B.jsx)(ue,{id:ND(r.value),items:b.map(e=>e.key),strategy:re,children:(0,B.jsx)(`ul`,{className:`-mb-2 flex flex-col`,children:b.map(n=>(0,B.jsx)(UD,{model:e,view:t,card:p,row:n,column:r,rows:b,draggable:(l||u)&&sy(n.record,`update`),placeable:u,dragged:d},n.key))})}),s===void 0&&f.more&&(0,B.jsx)(G,{size:`sm`,variant:`ghost`,onClick:f.loadMore,children:K(`showMore`)})]})},UD=({model:e,view:t,card:n,row:r,column:i,rows:a,draggable:o,placeable:s,dragged:c})=>{let{setNodeRef:l,setActivatorNodeRef:u,listeners:d,isDragging:f,isOver:p,active:m,transform:h,transition:g}=Te({id:r.key,data:{row:r,column:i,rows:a},disabled:{draggable:!o,droppable:!s}}),_=p&&m?.data.current?.column?.value!==i.value;return(0,B.jsx)(`li`,{ref:e=>{l(e),u(e?.querySelector(`a`)??e)},...d,onDragStart:e=>e.preventDefault(),onClickCapture:e=>{c()&&(e.preventDefault(),e.stopPropagation())},style:{transform:h?`translate3d(${h.x}px, ${h.y}px, 0)`:void 0,transition:g},className:P(`relative pb-2`,o&&`cursor-grab touch-manipulation`,f&&`opacity-40`,_&&`before:absolute before:inset-x-0 before:-top-1 before:h-0.5 before:rounded-full before:bg-primary`),children:(0,B.jsx)(ZE,{model:e,view:t,display:n,row:r,swipe:!1})})},WD=e=>e.kind===`and`?e.args.flatMap(WD):[e],GD=e=>e.kind===`string`?String(e.value):void 0,KD=(e,t)=>{if(e.kind===`compare`&&e.op===`=`&&e.field.path.join(`.`)===t){let t=GD(e.value);return t===void 0?void 0:[t]}if(e.kind===`in`&&e.field.path.join(`.`)===t){let t=e.values.map(GD);return t.every(e=>e!==void 0)?t:void 0}},qD=(e,t,n)=>{let r=it(e);if(!r.ok||!r.ast)return n;let i=WD(r.ast).map(e=>KD(e,t)).filter(e=>e!==void 0);return n.filter(e=>i.every(t=>e.value!==null&&t.includes(e.value)))},JD=(e,t)=>t!==null&&Object.hasOwn(e,t)?e[t]:void 0,YD=M(`app/hand-order`),XD=(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:ym(e,r),data:Object.fromEntries(a.map(e=>[e,t[e]])),etag:i}]}),ZD=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},QD=(e,t)=>t===void 0?e:`(${e}) AND (${t})`,$D=async(e,t,n,r)=>{let i=t.position?.after;if(!i)return{after:[],before:[]};let a=t.primaryKey[0],o=ym(t,r),s=e=>Nn([e]),c=await ZD(e,i.resource,QD(Yt(cn.or(cn.eq(i.field,o),cn.eq(i.key,o))),i.filter)),l=(e,t)=>c.flatMap(n=>s(n[e])===s(o)&&s(n[t])!==s(o)?[n[t]]:[]),u=l(i.field,i.key),d=l(i.key,i.field),[f,p]=await Promise.all([ZD(e,t.name,QD(Yt(cn.in(a,[o,...u])),i.while)),d.length===0?[]:ZD(e,t.name,Yt(cn.in(a,d)))]),m=e=>{let r=Nn(ym(t,e));return{key:r,rank:e[t.position.field],title:lr(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):[]}},eO=e=>typeof e==`number`&&Number.isInteger(e),tO=(e,t,n)=>{let r=0;for(;r<t&&eO(e[r])&&(r===0||e[r]>e[r-1]);)r+=1;let i=e.length;for(;i-1>n&&eO(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}},nO=(e,t,n)=>{let r=e.findIndex(e=>e.key===t.key);return r===-1?[...e.slice(0,n),t,...e.slice(n)]:ee(e,r,n)},rO=(e,t,n)=>{let r=e.findIndex(e=>e.key===t.key);return{order:nO(e,t,n),first:r===-1?n:Math.min(r,n),last:r===-1?n:Math.max(r,n)}},iO=e=>typeof e.record.etag==`string`?e.record.etag:`*`,aO=(e,t,n,r,i,a,o,s,c)=>{let l=(r.record[t]??null)!==i.value,u=tO(a.map(e=>e.record[n]),o,s),d=a.slice(u.first,u.last+1),f=e=>l&&e.key===r.key?`*`:iO(e),p=(t,r)=>({op:`reorder`,resource:e.name,field:n,keys:t.map(t=>ym(e,t.record)),start:r,etags:Object.fromEntries(t.map(t=>[Nn(ym(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:ym(e,r.record),data:{[t]:i.value},etag:iO(r)},...h]:h},oO=(e,t,n)=>{let r=new Map(t.map(t=>[Nn(ym(e,t.record)),t.record])),i=new Map;for(let t of n.results){let n=t.op===`reorder`?t.records:t.op===`update`?[t]:[];for(let{record:t,etag:r}of n)i.set(Nn(ym(e,t)),{record:t,etag:r})}return[...i].flatMap(([e,t])=>{let n=r.get(e);return n?[{before:n,...t}]:[]})},sO=M(`app/rank-after`),cO=e=>e!=null&&e!==``,lO=({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}=rO(n,r,l),f=i.map(e=>e.record[t]),p=tO(f,u,d),m=new Map(i.map((t,n)=>[Nn(ym(e,t.record)),n>=p.first&&n<=p.last?p.start+n-p.first:f[n]])),h=e=>m.has(e.key)?m.get(e.key):e.rank,g=Number(m.get(Nn(ym(e,r.record)))),_=a.after.filter(e=>cO(h(e))&&Number(h(e))>=g),v=a.before.find(e=>cO(h(e))&&Number(h(e))<=g),y=v?sO(`dependsOn`,{record:v.title,other:o}):_[0]&&sO(`dependsOn`,{record:o,other:_[0].title});if(!y)return{place:{index:l},...c!==void 0&&{reason:c}};if(c??=y,l!==s||v)continue;let b=Math.max(..._.map(e=>Number(h(e))))+1;if(a.before.every(e=>!cO(h(e))||Number(h(e))>b))return{place:{index:l,bump:b},reason:c}}return{reason:c}},uO=({model:e,view:t,by:n,rank:r,drop:i,labelOf:a,titleOf:s})=>{let c=U(),l=iy(),u=Cy(),[d,f]=(0,I.useState)([]),p=(0,I.useRef)(void 0),m=e=>f(t=>t.filter(t=>t.row.key!==e)),h=r?[n,r]:[n],g=o({mutationFn:e=>e(),onError:e=>l.show({state:`error`,title:K(`couldNotUndo`),description:Um(e)}),onSettled:()=>u(e.name)}),_=async(t,r)=>{let a=i&&JD(i,r.value);if(!a)throw Error(`The column ${r.label} takes no cards`);let o=ym(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(XD(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 $D(c,e,t,n.record),u=lO({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?YD(`notMoved`):YD(`movedToPlace`,{place:u.place.index+1}),description:u.reason}),!d)return u.place.index!==a.index&&y(n,i,rO(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}=rO(a.rows,t,o.index);return v(oO(e,s,await c.batchWrite(aO(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,ym(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&&rO(n.rows,e,n.index).order),onSuccess:(e,{row:t,to:r})=>{if(!e)return;let{landed:i,undo:o}=e;p.current!==void 0&&l.dismiss(p.current),p.current=void 0;let s=t.record[n]??null,c=i===s?s===r.value?K(`orderChanged`):K(`stayedIn`,{column:a(i)}):K(`movedTo`,{column:a(i)});if(!o){l.show({state:`success`,title:c});return}let u=l.show({state:`success`,title:c,action:{label:K(`undo`),onClick:()=>{l.dismiss(u),p.current=void 0,g.mutate(o)}}});p.current=u},onError:(e,{row:t,to:r})=>{m(t.key);let i=(t.record[n]??null)===r.value?K(`couldNotReorder`):K(`couldNotMoveTo`,{to:r.label});l.show({state:`error`,title:i,description:Um(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}})}},dO=(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}},fO=({model:e,view:t,display:n,fields:r,filter:i,orderBy:a,limit:o})=>{let s=zm(e,t,n),c=qD(i,n.by,s),l=Hm(e,t,n),u=af(e.name),{boardDrops:d}=c_(),f=t?.list?.drag,p=typeof f?.board==`string`?f.board:void 0,m=p===void 0?void 0:d?.[p],h=t=>oy(u,`update`)&&(f?.board===!0?!e.fields[n.by]?.readOnly:m!==void 0&&JD(m,t)!==void 0),g=c.some(e=>h(e.value)),_=Bm(e),v=f?.rank===!0&&_!==void 0&&AD(e,u)!==void 0,y=_?`${_} asc`:a,b=e=>s.find(t=>t.value===e)?.label??String(e),x=e=>String(e.labels[l.title]??e.record[l.title]??e.key),{moves:S,move:C}=uO({model:e,view:t,by:n.by,rank:_,drop:m,labelOf:b,titleOf:x}),[w,T]=(0,I.useState)(),E=(0,I.useRef)(!1),D=ne(Me(se,{activationConstraint:{distance:4}}),Me(xe,{activationConstraint:{delay:250,tolerance:5}}),Me(ae,{keyboardCodes:{start:[`Space`],cancel:[`Escape`],end:[`Space`,`Enter`]},coordinateGetter:RD}));if(p!==void 0&&!m)return(0,B.jsx)(ov,{children:K.rich(`noDrop`,{drop:p})});let O=e=>c.find(t=>ND(t.value)===e),k=e=>e.record[n.by]??null,A=(e,t)=>h(k(e))&&h(t.value),j=(e,t)=>{if(!t)return{over:K(`noColumn`)};let n=v?dO(t,e):void 0;if(!n)return{over:O(t.id)?.label??K(`noColumn`)};let r=n.rows.some(t=>t.key===e.key)?n.rows.length:n.rows.length+1;return{over:K(`placeOf`,{column:n.column.label,place:n.index+1,count:r}),place:K(`place`,{column:n.column.label,place:n.index+1})}},ee=(e,t)=>{let n=(v?dO(t,e)?.column:void 0)??O(t.id);return n!==void 0&&n.value!==k(e)&&!A(e,n)};return(0,B.jsxs)(me,{sensors:D,collisionDetection:FD,onDragStart:({active:e})=>{E.current=!0,T(e.data.current.row)},onDragEnd:({active:e,over:t})=>{T(void 0),setTimeout(()=>E.current=!1);let n=e.data.current.row;if(!t)return;let r=v?dO(t,n):void 0;if(!r){let e=O(t.id);e&&e.value!==k(n)&&A(n,e)&&C(n,e);return}let i=r.rows.findIndex(e=>e.key===n.key);if(i!==-1||A(n,r.column)){if(i===-1&&m)return C(n,r.column);i!==r.index&&C(n,r.column,{rows:r.rows,index:r.index})}},onDragCancel:()=>{T(void 0),setTimeout(()=>E.current=!1)},accessibility:{announcements:{onDragStart:({active:e})=>K(`pickedUp`,{title:x(e.data.current.row)}),onDragOver:({active:e,over:t})=>K(`isOver`,{title:x(e.data.current.row),over:j(e.data.current.row,t).over}),onDragEnd:({active:e,over:t})=>{let n=e.data.current.row;if(!t||ee(n,t))return K(`putBack`,{title:x(n)});let r=j(n,t);return K(`wasMovedTo`,{title:x(n),to:r.place??r.over})},onDragCancel:({active:e})=>K(`cancelled`,{title:x(e.data.current.row)})},screenReaderInstructions:{draggable:K(v?g?`boardAnywhere`:`boardWithin`:`boardAcross`)}},children:[(0,B.jsx)(`div`,{className:`relative min-w-0 flex-1 overflow-x-auto`,children:(0,B.jsx)(`div`,{className:`flex snap-x items-start gap-3 pb-2`,children:c.map(a=>(0,B.jsx)(HD,{model:e,view:t,display:n,column:a,fields:r,filter:i,orderBy:y,limit:o,moves:S,movable:h(a.value),placeable:v,dragged:()=>E.current},ND(a.value)))})}),(0,B.jsx)(Oe,{children:w&&(0,B.jsx)(ZE,{model:e,view:t,display:l,row:w,swipe:!1})})]})},pO=864e5,mO=e=>new Date(e).toISOString().slice(0,10),hO=e=>Date.parse(`${e}T00:00:00Z`),gO=(e,t)=>mO(hO(e)+t*pO),_O=e=>gO(e,-((new Date(hO(e)).getUTCDay()+6)%7)),vO=(e,t=0)=>{let n=new Date(hO(e));return mO(Date.UTC(n.getUTCFullYear(),n.getUTCMonth()+t,1))},yO=({scale:e,day:t})=>({scale:e,day:e===`month`?vO(t):_O(t)}),bO=(e,t,n=Gf())=>yO(e??{scale:`month`,day:Zf(t,n)}),xO=(e,t,n=Gf())=>yO({scale:e,day:Zf(t,n)}),SO=(e,t)=>e.scale===`month`?{scale:`month`,day:vO(e.day,t)}:{scale:`week`,day:gO(_O(e.day),7*t)},CO=e=>{let t=_O(e.scale===`month`?vO(e.day):e.day),n=(hO(e.scale===`month`?gO(_O(gO(vO(e.day,1),-1)),6):gO(t,6))-hO(t))/pO+1;return Array.from({length:n},(e,n)=>gO(t,n))},wO=e=>{let t=CO(e);return{from:t[0],to:gO(t.at(-1),1)}},TO=(e,t)=>t.fields[e.start]?.type===`timestamp`,EO=(e,t,n,r=Gf())=>{let i=TO(e,t),a=e=>new Date($f(e,r)).toISOString().replace(`.000Z`,`Z`),o=e=>i?{kind:`timestamp`,value:a(e),span:{start:0,end:0}}:{kind:`string`,value:e,span:{start:0,end:0}},s=cn.and(cn.gte(e.start,o(n.from)),cn.lt(e.start,o(n.to)));if(e.end===void 0)return Yt(s);let c=i?cn.gt(e.end,o(n.from)):cn.gte(e.end,o(n.from));return Yt(cn.or(s,cn.and(cn.lt(e.start,o(n.from)),c)))},DO=(e,t)=>e===``?t:`(${e}) AND (${t})`,OO=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},kO=(e,t,n,r=Gf())=>{let i=OO(e[t.start]);if(i===void 0)return;let a=TO(t,n),o=e=>a?Zf(e,r):mO(e),s=o(i),c=t.end===void 0?void 0:OO(e[t.end]),l=c===void 0?s:o(a?c-1:c);return{first:s,last:l<s?s:l}},AO=(e,t,n,r,i=Gf())=>{let a=kO(e,t,n,i);return a?r.filter(e=>e>=a.first&&e<=a.last):[]},jO=(e,t)=>e.toSorted((e,n)=>(OO(e.record[t.start])??0)-(OO(n.record[t.start])??0)),MO=(e,t,n,r,i=Gf())=>{let a=new Map(r.map(e=>[e,[]]));for(let o of jO(e,t))for(let e of AO(o.record,t,n,r,i))a.get(e).push(o);return a},NO=(e,t,n,r,i,a=Gf())=>{let o=(hO(i)-hO(r))/pO,s=TO(t,n),c=e=>{let t=OO(e);if(t!==void 0)return s?new Date(Qf(t+Yf(t,a)+o*pO,a)).toISOString():gO(mO(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}}},PO=({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)(Uh,{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=mf({variant:`secondary`,size:`sm`});return(0,B.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,B.jsx)(`h2`,{className:`text-sm font-medium`,children:e}),(0,B.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,B.jsxs)(`div`,{className:`flex items-center gap-1`,children:[l(n,u,K(`previousPeriod`,{unit:t}),(0,B.jsx)(Ei,{className:`size-3.5`})),l(r,u,K(`today`),K(`today`)),l(i,u,K(`nextPeriod`,{unit:t}),(0,B.jsx)(Oi,{className:`size-3.5`}))]}),(0,B.jsx)(`span`,{role:`group`,"aria-label":o,className:ze.group(),children:a.map(e=>(0,B.jsx)(I.Fragment,{children:l(e.view,ze.option(e.current),e.label,e.label,e.current)},e.label))})]})]})},FO=e=>{let t=CO(e),n=e=>Date.parse(`${e}T00:00:00Z`);return e.scale===`month`?fp(n(e.day)):_p(n(t[0]),n(t.at(-1)))},IO=({view:e,now:t,linkTo:n,onView:r})=>{let i=e.scale===`month`&&Zf(t,Gf()).startsWith(e.day.slice(0,7)),a=n=>n===`week`&&i?xO(`week`,t):bO({scale:n,day:e.day},t),o=(t,n)=>({view:a(t),label:n,current:e.scale===t});return(0,B.jsx)(PO,{heading:FO(e),unit:e.scale===`month`?`month`:`week`,previous:SO(e,-1),today:xO(e.scale,t),next:SO(e,1),scales:[o(`month`,K(`month`)),o(`week`,K(`week`))],scalesLabel:K(`calendarScale`),linkTo:n,onView:r})},LO=`day:`,RO=e=>`${LO}${e}`,zO=(e,t)=>`${e}@${t}`,BO=(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(RO(gO(o,a)));if(s)return{x:s.left+(s.width-n.width)/2,y:s.top+4}},VO=({day:e,count:t,children:n,more:r,inMonth:i,today:a,week:o})=>{let{setNodeRef:s,isOver:c}=ke({id:RO(e)}),l=Date.parse(`${e}T00:00:00Z`);return(0,B.jsxs)(`section`,{ref:s,"aria-label":`${gp(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:hp(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]})},HO=(e,t,n,r)=>{let i=n.title??cr(e,t),a=e.fields[i],o=r.labels[i]??(a?Nm(a,r.record[i],t?.fields[i]):``);return o===``?r.key:o},UO=(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 Zf(a,Gf())===r?vp(a):void 0},WO=({model:e,view:t,display:n,row:r,day:i,className:a})=>{let o=ZT(e),s=UO(e,n,r,i);return(0,B.jsxs)(Uh,{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:HO(e,t,n,r)})]})},GO=({movable:e,dragged:t,...n})=>{let{setNodeRef:r,setActivatorNodeRef:i,listeners:a,isDragging:o}=j({id:zO(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)(WO,{...n})})},KO=({model:e,display:t,range:n,fields:r,filter:i})=>{let{resources:a,views:o}=W(),s=Tw({resources:a,views:o,model:e,columns:r,filter:DO(i,EO(t,e,n)),orderBy:`${t.start} asc`}),c=zD(e,s.page,s.key,!0),l=c.more&&!c.loading&&c.rows.length<500;(0,I.useEffect)(()=>{l&&c.loadMore()},[l,c.rows.length]);let u=c.rows.length>500||c.rows.length===500&&c.more;return{rows:c.rows.slice(0,500),capped:u,loading:c.loading,error:c.error}},qO=(e,t)=>{let n=new Map(t.map(e=>[e.key,e.patch]));return e.map(e=>n.has(e.key)?{...e,record:{...e.record,...n.get(e.key)}}:e)},JO=(e,t)=>{let n=U(),r=iy(),i=Cy(),[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,ym(e,t.record),r,i)},onMutate:({row:e,patch:t})=>s(n=>[...n.filter(t=>t.key!==e.key),{key:e.key,patch:t}]),onError:(e,{row:t,to:n})=>{c(t.key),r.show({state:`error`,title:K(`couldNotMoveTo`,{to:cp(Date.parse(`${n}T00:00:00Z`))}),description:Um(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:NO(n.record,t,e,r,i),to:i})}},YO=3,XO=({model:e,view:t,display:n,fields:r,filter:i,at:a,linkTo:o,now:s=Date.now()})=>{let[c,l]=(0,I.useState)(),u=bO(o?a:c,s),d=CO(u),f=KO({model:e,display:n,range:wO(u),fields:r,filter:i}),{moves:p,move:m}=JO(e,n),h=MO(qO(f.rows,p),n,e,d),g=oy(af(e.name),`update`)&&[n.start,n.end].every(t=>t===void 0||!e.fields[t]?.readOnly),[_,v]=(0,I.useState)(),y=(0,I.useRef)(!1),b=ne(Me(se,{activationConstraint:{distance:4}}),Me(xe,{activationConstraint:{delay:250,tolerance:5}}),Me(ae,{keyboardCodes:{start:[`Space`],cancel:[`Escape`],end:[`Space`,`Enter`]},coordinateGetter:BO})),x=Zf(s,Gf()),S=u.scale===`week`,C=e=>cp(Date.parse(`${String(e).slice(RO(``).length)}T00:00:00Z`)),w=r=>HO(e,t,n,r.row),T={onDragStart:({active:e})=>K(`pickedUp`,{title:w(e.data.current)}),onDragOver:({active:e,over:t})=>K(`isOver`,{title:w(e.data.current),over:t?C(t.id):K(`noDay`)}),onDragEnd:({active:e,over:t})=>t?K(`wasMovedTo`,{title:w(e.data.current),to:C(t.id)}):K(`putBack`,{title:w(e.data.current)}),onDragCancel:({active:e})=>K(`cancelled`,{title:w(e.data.current)})},E=()=>{v(void 0),setTimeout(()=>y.current=!1)},D=({active:e})=>{y.current=!0,v(e.data.current)},O=({active:e,over:t})=>{E();let{row:n,day:r}=e.data.current,i=t?String(t.id).slice(RO(``).length):void 0;i&&i!==r&&m(n,r,i)},k=(e,t)=>{let n=bO({scale:`week`,day:e},s),r=K(`moreHidden`,{count:t}),i=`self-start rounded px-1 text-xs text-muted-foreground hover:text-foreground focus-visible:outline-2 focus-visible:outline-primary`;return o?(0,B.jsx)(Uh,{to:o(n),className:i,children:r}):(0,B.jsx)(`button`,{type:`button`,className:i,onClick:()=>l(n),children:r})};return(0,B.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-3`,children:[(0,B.jsx)(IO,{view:u,now:s,linkTo:o,onView:l}),f.error&&(0,B.jsx)(Bg,{title:K(`couldNotLoadRows`),error:f.error}),f.capped&&(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:K(`capped`,{limit:500,unit:u.scale})}),(0,B.jsxs)(me,{sensors:b,collisionDetection:FD,onDragStart:D,onDragEnd:O,onDragCancel:E,accessibility:{announcements:T,screenReaderInstructions:{draggable:K(`calendarInstructions`)}},children:[(0,B.jsxs)(`div`,{className:`overflow-hidden rounded-lg border border-border`,children:[!S&&(0,B.jsx)(`div`,{"aria-hidden":!0,className:`grid grid-cols-7 gap-px border-b border-border bg-border`,children:d.slice(0,7).map(e=>(0,B.jsx)(`span`,{className:`bg-surface px-1.5 py-1 text-xs font-medium text-muted-foreground`,children:hp(Date.parse(`${e}T00:00:00Z`))},e))}),(0,B.jsx)(`div`,{className:P(`grid gap-px bg-border`,S?`grid-cols-1 sm:grid-cols-7`:`grid-cols-7`),children:d.map(r=>{let i=h.get(r),a=S?i:i.slice(0,YO);return(0,B.jsx)(VO,{day:r,count:i.length,inMonth:S||r.startsWith(u.day.slice(0,7)),today:r===x,week:S,more:a.length<i.length&&k(r,i.length-a.length),children:f.loading?(0,B.jsx)(vh,{className:`h-4`}):a.map(i=>(0,B.jsx)(GO,{model:e,view:t,display:n,row:i,day:r,movable:g&&sy(i.record,`update`),dragged:()=>y.current},i.key))},r)})})]}),(0,B.jsx)(Oe,{children:_&&(0,B.jsx)(WO,{model:e,view:t,display:n,row:_.row,day:_.day})})]})]})},ZO=864e5,QO=e=>Date.parse(`${e}T00:00:00Z`),$O=(e,t=0)=>{let n=new Date(QO(e));return new Date(Date.UTC(n.getUTCFullYear(),Math.floor(n.getUTCMonth()/3)*3+3*t,1)).toISOString().slice(0,10)},ek=({scale:e,day:t})=>({scale:e,day:e===`week`?_O(t):e===`month`?vO(t):$O(t)}),tk=(e,t,n=Gf())=>ek(e??{scale:`month`,day:Zf(t,n)}),nk=(e,t)=>{let{scale:n,day:r}=ek(e);return{scale:n,day:n===`week`?gO(r,7*t):n===`month`?vO(r,t):$O(r,t)}},rk=e=>{let t=ek(e).day,n=(QO(nk(e,1).day)-QO(t))/ZO;return Array.from({length:n},(e,n)=>gO(t,n))},ik=e=>({from:ek(e).day,to:nk(e,1).day}),ak=(e,t,n,r=Gf())=>{let i=Zf(n,r),a=rk(e);return ek({scale:t,day:i>=a[0]&&i<=a.at(-1)?i:a[0]})},ok=e=>{let t=rk(e);return e.scale===`week`?_p(QO(t[0]),QO(t.at(-1))):e.scale===`month`?fp(QO(t[0])):mp(QO(t[0]),QO(vO(t.at(-1))))},sk=e=>{let t=rk(e);if(e.scale===`week`)return t.map((e,t)=>({index:t,span:1,label:`${hp(QO(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:pp(QO(t[e]))}))},ck=(e,t,n,r,i=Gf())=>{let a=kO(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}},lk=`none`,uk=(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?lk:`value:${String(e)}`,c=n?K(`noValue`,{label:o?.label??F(i)}):t.labels[i]??Nm(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)},dk=`grid grid-cols-1 sm:grid-cols-[12rem_minmax(0,1fr)]`,fk=(e,t)=>`${e/t*100}%`,pk=({ticks:e,days:t,today:n,label:r,trackRef:i})=>(0,B.jsxs)(`div`,{className:P(dk,`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:fk(e.index,t.length),width:fk(e.span,t.length)},children:e.label},e.index))})]}),mk=({ticks:e,days:t,today:n})=>{let r=t.indexOf(n);return(0,B.jsxs)(`div`,{"aria-hidden":!0,className:P(dk,`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:fk(r,t.length),width:fk(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:fk(e.index,t.length)}},e.index))]})]})},hk=({model:e,view:t,display:n,row:r,days:i,movable:a,dragged:o})=>{let s=ck(r.record,n,e,i);return(0,B.jsxs)(`div`,{className:P(dk,`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:HO(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:fk(s.first,i.length),width:fk(s.last-s.first+1,i.length)},children:(0,B.jsx)(GO,{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`)})})})]})},gk=()=>[{scale:`week`,label:K(`week`)},{scale:`month`,label:K(`month`)},{scale:`quarter`,label:K(`quarter`)}],_k=({model:e,view:t,display:n,fields:r,filter:i,at:a,linkTo:o,now:s=Date.now()})=>{let[c,l]=(0,I.useState)(),u=tk(o?a:c,s),d=rk(u),f=sk(u),p=KO({model:e,display:n,range:ik(u),fields:r,filter:i}),{moves:m,move:h}=JO(e,n),g=uk(jO(qO(p.rows,m),n),e,t,n),_=oy(af(e.name),`update`)&&[n.start,n.end].every(t=>t===void 0||!e.fields[t]?.readOnly),[v,y]=(0,I.useState)(),b=(0,I.useRef)(!1),x=(0,I.useRef)(0),S=(0,I.useRef)(null),C=()=>(S.current?.getBoundingClientRect().width??0)/d.length,w=e=>{let t=C();return t>0?Math.round(e/t):0},T=({transform:e})=>({...e,x:w(e.x)*C(),y:0}),E=ne(Me(se,{activationConstraint:{distance:4}}),Me(xe,{activationConstraint:{delay:250,tolerance:5}}),Me(ae,{keyboardCodes:{start:[`Space`],cancel:[`Escape`],end:[`Space`,`Enter`]},coordinateGetter:(e,{currentCoordinates:t})=>{let n=e.code===`ArrowLeft`?-1:+(e.code===`ArrowRight`);if(n!==0)return e.preventDefault(),{x:t.x+n*C(),y:t.y}}})),D=Zf(s,Gf()),O=r=>HO(e,t,n,r.row),k=e=>cp(Date.parse(`${gO(e.day,x.current)}T00:00:00Z`)),A={onDragStart:({active:e})=>K(`pickedUp`,{title:O(e.data.current)}),onDragMove:({active:e})=>K(`startsOn`,{title:O(e.data.current),day:k(e.data.current)}),onDragOver:()=>void 0,onDragEnd:({active:e})=>x.current===0?K(`putBack`,{title:O(e.data.current)}):K(`wasMovedTo`,{title:O(e.data.current),to:k(e.data.current)}),onDragCancel:({active:e})=>K(`cancelled`,{title:O(e.data.current)})},j=()=>{y(void 0),setTimeout(()=>b.current=!1)},ee=({active:e})=>{b.current=!0,x.current=0,y(e.data.current)},te=({delta:e})=>x.current=w(e.x),re=({active:t,delta:r})=>{j(),x.current=w(r.x);let{row:i}=t.data.current,a=kO(i.record,n,e);a&&x.current!==0&&h(i,a.first,gO(a.first,x.current))},ie=n.group===void 0?t?.names?.plural??F(e.name):t?.fields[n.group]?.label??F(n.group),oe=!p.loading&&!p.error&&p.rows.length===0;return(0,B.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-3`,children:[(0,B.jsx)(PO,{heading:ok(u),unit:u.scale,previous:nk(u,-1),today:tk({scale:u.scale,day:D},s),next:nk(u,1),scales:gk().map(({scale:e,label:t})=>({view:ak(u,e,s),label:t,current:u.scale===e})),scalesLabel:K(`timelineScale`),linkTo:o,onView:l}),p.error&&(0,B.jsx)(Bg,{title:K(`couldNotLoadRows`),error:p.error}),p.capped&&(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:K(`capped`,{limit:500,unit:u.scale})}),(0,B.jsxs)(me,{sensors:E,modifiers:[T],onDragStart:ee,onDragMove:te,onDragEnd:re,onDragCancel:j,accessibility:{announcements:A,screenReaderInstructions:{draggable:K(`timelineInstructions`)}},children:[(0,B.jsxs)(`div`,{className:`overflow-hidden rounded-lg border border-border`,children:[(0,B.jsx)(pk,{ticks:f,days:d,today:D,label:ie,trackRef:S}),(0,B.jsxs)(`div`,{className:`relative`,children:[(0,B.jsx)(mk,{ticks:f,days:d,today:D}),p.loading&&(0,B.jsxs)(`div`,{className:`relative flex flex-col gap-2 p-2`,children:[(0,B.jsx)(vh,{className:`h-4`}),(0,B.jsx)(vh,{className:`h-4`})]}),oe&&(0,B.jsx)(`p`,{className:`relative px-2 py-3 text-xs text-muted-foreground`,children:K(`nothingIn`,{unit:u.scale})}),!p.loading&&g.map(r=>(0,B.jsxs)(`section`,{"aria-label":r.label,className:`relative border-b border-border last:border-b-0`,children:[r.label!==void 0&&(0,B.jsxs)(`h3`,{className:`flex items-center gap-1.5 border-b border-border bg-surface px-2 py-1 text-xs font-medium`,children:[r.label,(0,B.jsx)(`span`,{className:`tabular-nums text-muted-foreground`,children:r.rows.length})]}),r.rows.map(r=>(0,B.jsx)(hk,{model:e,view:t,display:n,row:r,days:d,movable:_&&sy(r.record,`update`),dragged:()=>b.current},r.key))]},r.key))]})]}),(0,B.jsx)(Oe,{children:v&&(0,B.jsx)(WO,{model:e,view:t,display:n,row:v.row,day:v.day})})]})]})},vk=({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)(Bg,{title:K(`couldNotLoadRows`),error:e.error}):e.rows.length===0?(0,B.jsx)(`p`,{className:`py-8 text-center text-muted-foreground`,children:t}):r}),yk=({list:e})=>(0,B.jsxs)(`div`,{className:`flex items-center justify-between gap-3 py-3 text-xs text-muted-foreground`,children:[(0,B.jsxs)(`span`,{children:[e.rows.length.toLocaleString(Le()),` of `,e.total.toLocaleString(Le())]}),e.more&&(0,B.jsx)(G,{size:`sm`,onClick:e.loadMore,children:K(`showMore`)})]}),bk=`grid grid-cols-[repeat(auto-fill,minmax(15rem,1fr))] gap-3`,xk=`relative flex snap-x snap-mandatory gap-3 overflow-x-auto pb-1`,Sk=({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)(vk,{list:r,empty:K(`noneMatch`,{plural:o}),loading:(0,B.jsx)(`div`,{className:bk,children:Array.from({length:6},(e,t)=>(0,B.jsx)(vh,{className:`h-24`},t))}),children:[(0,B.jsx)(`ul`,{className:i?xk:bk,"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)(ZE,{model:e,view:t,display:n,row:r,swipe:!i})},r.key))}),a&&(0,B.jsx)(yk,{list:r})]})},Ck=(0,I.createContext)(void 0),wk=({value:e,children:t})=>(0,B.jsx)(Ck.Provider,{value:e,children:t}),Tk=()=>{let e=(0,I.useContext)(Ck);if(!e)throw Error(`useListDisplay is used inside a list display, which the list page draws`);return e},Ek=()=>(0,I.useContext)(Ck),Dk=({display:e,list:t})=>{let{components:n}=c_(),r=n?.[e.component];return r?(0,B.jsx)(wk,{value:t,children:(0,B.jsx)(`div`,{className:`relative min-w-0 flex-1 overflow-x-auto`,children:(0,B.jsx)(cv,{name:e.component,children:(0,B.jsx)(r,{...vn(e.props??{})})})})}):(0,B.jsx)(ov,{children:K.rich(`noComponent`,{component:e.component})})},Ok=sn(),kk={bounds:{south:-90,west:-180,north:90,east:180},zoom:0},Ak=22,jk=e=>Math.floor(e*1e6)/1e6,Mk=e=>Math.ceil(e*1e6)/1e6,Nk=e=>((e+180)%360+360)%360-180,Pk=(e,t)=>{let n=[Ok.gte(e.latitude,jk(Math.max(t.south,-90))),Ok.lte(e.latitude,Mk(Math.min(t.north,90)))];if(t.east-t.west>=360)return Ok.and(...n);let r=Ok.gte(e.longitude,jk(Nk(t.west))),i=Ok.lte(e.longitude,Mk(Nk(t.east)));return Nk(t.west)<=Nk(t.east)?Ok.and(...n,r,i):Ok.and(...n,Ok.or(r,i))},Fk=(e,t,n)=>{let r=Yt(Pk(t,n));return e.trim()===``?r:`(${e}) AND ${r}`},Ik=e=>Math.min(Math.max(Math.floor(e),0),Ak),Lk=(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))}},Rk=e=>{if(typeof e==`number`)return e;if(typeof e==`string`&&e.trim()!==``)return Number(e)},zk=(e,t)=>{let n=Rk(e[t.latitude]),r=Rk(e[t.longitude]);if(n!==void 0&&r!==void 0&&Math.abs(n)<=90&&Math.abs(r)<=180)return{latitude:n,longitude:r}},Bk=6371008.8,Vk=64,Hk=(e,t)=>t.approximate===void 0?t.exact!==void 0&&e[t.exact]===!1:e[t.approximate]===!0,Uk=(e,t)=>{let n=t/Bk,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%Vk/Vk*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]})]}},Wk=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,Gk=(e,t)=>Array.isArray(e)&&e.length>=t&&e.every(Wk),Kk=e=>Array.isArray(e)&&e.length>0&&e.every(e=>Gk(e,4)),qk=e=>Array.isArray(e)&&e.length>0&&e.every(e=>Gk(e,2)),Jk=e=>{if(typeof e!=`string`)return e;try{return JSON.parse(e)}catch(e){if(e instanceof SyntaxError)return;throw e}},Yk=e=>{let t=Jk(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`&&Kk(i)||r===`MultiPolygon`&&Array.isArray(i)&&i.length>0&&i.every(Kk)||r===`LineString`&&Gk(i,2)||r===`MultiLineString`&&qk(i))return{type:r,coordinates:i}},Xk=(e,t,n)=>{if(!Hk(e,t))return;let r=t.area===void 0?void 0:Yk(e[t.area]);if(r)return r;let i=t.radius===void 0?void 0:Rk(e[t.radius]);return i!==void 0&&Number.isFinite(i)&&i>0?Uk(n,i):t.defaultRadius===void 0?void 0:Uk(n,t.defaultRadius)},Zk=(e,t)=>e.flatMap(e=>{let n=zk(e.record,t);if(!n)return[];if(!Hk(e.record,t))return[{key:e.key,...n}];let r=Xk(e.record,t,n);return[{key:e.key,...n,approximate:!0,...r&&{area:r}}]}),Qk=(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}))},$k=(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)}},eA=(e,t)=>({keys:e.keys,index:((e.index+t)%e.keys.length+e.keys.length)%e.keys.length}),tA=({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?Fk(i,u,o.bounds):``,p=o?Ik(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:Cb(c,l,e,r),photos:Im(t)});return{rows:wb(c,e,r,Lm(e,n.items,n.photos),n.labels).map(t=>uh(e,t)),buckets:n.buckets,total:n.totalSize}}})},nA=(0,I.lazy)(()=>Ve(()=>import(`./records-map-DAJkSlba.js`).then(e=>({default:e.RecordsMap})),__vite__mapDeps([4,1,2,5,6,7,3,8]))),rA=250,iA=`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`,aA=({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=eT(m,rA),[_,v]=(0,I.useState)(o===void 0),y=tA({model:e,view:t,display:n,fields:a,filter:r,orderBy:i,area:_?kk:g}),b=y.isPlaceholderData?void 0:y.data,x=y.data?.rows??[],S=y.data?.buckets??[],C=Zk(x,n),w=_&&b?Lk(Zk(b.rows,n),b.buckets):void 0,T=ah(t,n),E=(t?.names?.plural??F(e.name)).toLowerCase(),D=(t?.names?.singular??F(e.name)).toLowerCase(),O=$k(f,x),k=O&&x.find(e=>e.key===O.keys[O.index]),A=new Set(C.filter(e=>e.approximate).map(e=>e.key)),j=e=>{let t=e.filter(e=>A.has(e)).length;return e.length===1?K(t===1?`showOneApproximate`:`showOne`,{singular:D}):t===0?K(`showMany`,{count:e.length,plural:E}):t===e.length?K(`showManyApproximate`,{count:e.length,plural:E}):K(`showManySomeApproximate`,{count:e.length,plural:E,near:t})},ee=e=>K(`zoomIn`,{count:e.toLocaleString(Le()),noun:e===1?D:E}),te=(0,I.useRef)(null),[ne,re]=(0,I.useState)(0);if((0,I.useLayoutEffect)(()=>re(te.current?.offsetHeight??0),[k?.key]),!d)return(0,B.jsx)(ov,{children:K(`needsStyle`)});let ie=b?.total===0;return(0,B.jsxs)(`div`,{className:P(`flex h-full min-h-[36rem] flex-1 flex-col sm:min-h-[28rem]`,l&&`max-md:-mx-5 max-md:-mb-4 max-md:min-h-0`),children:[(0,B.jsxs)(`div`,{className:P(`relative min-h-0 flex-1 overflow-hidden rounded-lg border border-border bg-muted`,l&&`max-md:rounded-none max-md:border-0`),children:[(0,B.jsx)(I.Suspense,{fallback:null,children:(0,B.jsx)(nA,{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)(Bg,{title:K(`couldNotLoadRows`),error:y.error})}),ie&&(0,B.jsx)(`div`,{className:`pointer-events-none absolute inset-x-3 top-3 z-10 flex justify-center`,children:(0,B.jsxs)(`p`,{className:`pointer-events-auto flex items-center gap-3 rounded-full border border-border bg-background px-4 py-1.5 text-muted-foreground shadow`,role:`status`,children:[K(_?`noneMatch`:`noneHere`,{plural:E}),!_&&(0,B.jsx)(G,{size:`sm`,onClick:()=>v(!0),children:K(`showAll`)})]})}),O&&k&&(0,B.jsx)(`div`,{ref:te,className:`pointer-events-none absolute inset-x-3 bottom-3 z-10 flex justify-center`,children:(0,B.jsxs)(`div`,{className:`pointer-events-auto flex w-full max-w-[16rem] flex-col gap-2 sm:max-w-xs`,role:`group`,"aria-label":K(`chosen`,{singular:D}),children:[(0,B.jsxs)(`div`,{className:`flex items-center justify-end gap-1.5`,children:[A.has(k.key)&&(0,B.jsxs)(`span`,{className:`mr-auto flex items-center gap-1 rounded-full border border-border bg-background px-2 py-1 text-xs`,children:[(0,B.jsx)(Ii,{className:`size-3.5`,"aria-hidden":!0}),K(`approximatePosition`)]}),O.keys.length>1&&(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`button`,{type:`button`,"aria-label":K(`previous`),className:iA,onClick:()=>p(eA(O,-1)),children:(0,B.jsx)(Ei,{className:`size-4`,"aria-hidden":!0})}),(0,B.jsxs)(`span`,{className:`rounded-full border border-border bg-background px-2 py-1 text-xs tabular-nums`,"aria-live":`polite`,children:[O.index+1,` / `,O.keys.length]}),(0,B.jsx)(`button`,{type:`button`,"aria-label":K(`next`),className:iA,onClick:()=>p(eA(O,1)),children:(0,B.jsx)(Oi,{className:`size-4`,"aria-hidden":!0})})]}),(0,B.jsx)(`button`,{type:`button`,"aria-label":K(`close`),className:iA,onClick:()=>p(void 0),children:(0,B.jsx)(yc,{className:`size-4`,"aria-hidden":!0})})]}),(0,B.jsx)(`div`,{className:`shadow-lg`,children:(0,B.jsx)(ZE,{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:oA(y.data,E)})]})},oA=(e,t)=>{if(!e)return`\xA0`;let n=e.total.toLocaleString(Le());return e.buckets.length===0&&e.rows.length<e.total?`${e.rows.length.toLocaleString(Le())} of ${n} ${t} in view`:`${n} ${t} in view`},sA=({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)(wi,{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=Zw(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)(Si,{className:`size-3.5 text-primary-text`})]})},t.value))})]})},cA={table:Ls,cards:Wa,kanban:ks,board:Ki,list:Qa,calendar:gi,timeline:bi,map:uo},lA=({view:e,value:t,onChange:n,menu:r=!1,choices:i=$m(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:cA[e.icon]}));return r?(0,B.jsx)(sA,{label:K(`display`),value:t,onChange:n,options:a}):(0,B.jsx)(Re,{label:K(`display`),size:`md`,value:t,onChange:n,options:a})},uA=[[`asc`,`ascending`],[`desc`,`descending`]],dA=({model:e,view:t,display:n,orderBy:r,onChange:i,className:a})=>{let o=fh(r),s=ch(e,t,n),c=s.includes(o.columnId)?s:[o.columnId,...s],l=e=>t?.fields[e]?.label??F(e);return(0,B.jsx)(`select`,{"aria-label":K(`sort`),value:`${o.columnId} ${o.direction}`,onChange:e=>i(e.target.value),className:P(`h-8 rounded-md border border-border-strong bg-background px-2.5 shadow-sm focus:border-primary focus:outline-none focus:ring-2 focus:ring-primary/20`,a),children:c.flatMap(e=>uA.map(([t,n])=>(0,B.jsxs)(`option`,{value:`${e} ${t}`,children:[l(e),`, `,K(n)]},`${e} ${t}`)))})},fA=(e,t,n,r)=>e.map(e=>{let i=t.fields[e.id],a=i&&ev(r,i,n?.fields[e.id]);return a?{...e,render:t=>(0,B.jsx)(dv,{shown:a,part:`cell`,field:i,value:t[e.id],fallback:ZS(e,e.value?e.value(t):t[e.id])})}:e}),pA=e=>String(typeof e==`object`&&e&&`id`in e?e.id:e),mA=({target:e,id:t})=>(0,B.jsx)(YS,{text:Mb(e,t)??t,className:`font-medium text-primary-text hover:underline`}),hA=(e,t,n,r)=>e.map(e=>{let i=t.fields[e.id],a=i?.type===`relation`&&i.relation?n[i.relation.resource]:void 0;return e.render||!a||!r[a.name]?.titleFrom?e:{...e,render:t=>t[e.id]==null?ZS(e,null):(0,B.jsx)(mA,{target:a,id:pA(t[e.id])})}}),gA=e=>e.includes(`.`),_A=({model:e,row:t,column:n})=>{let r=Vb(vy(e,uh(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)(Lb,{model:r.model,field:r.field,value:r.value})},vA=(e,t,{resources:n,views:r})=>{let i=vu(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)(_A,{model:e,row:n,column:t})}},yA=(e,t,n,r)=>{let i=new Map(hA(fA(jm(e,t,[],n.filter(e=>!gA(e))),e,t,r.fieldTypes),e,r.resources,r.views).map(e=>[e.id,e]));return n.flatMap(t=>gA(t)?[vA(e,t,r)]:i.get(t)??[])},bA=(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},xA=(e,t,n)=>{if(e.open!==void 0)return e.open!==e.field&&bA(t,e.open,n)?e.open:void 0;let r=t.primaryKey.filter(r=>r!==e.field&&r!==t.tenant&&bA(t,r,n));return r.length===1?r[0]:void 0},SA=(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},CA=(e,t)=>(t?.names?.singular??F(e.name)).toLowerCase(),wA=({model:e,view:t,opens:n,resources:r,views:i,canUpdate:a})=>{let o=t=>({kind:`record`,resource:e.name,key:ym(e,t)}),s=n&&e.fields[n]?.relation?.resource,c=s?r[s]:void 0,l=e=>{let t=n&&c?SA(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=CA(e,t);return{address:u,actions:t=>{let n={label:MS(`open`,{singular:d}),link:e=>t(o(e))};if(!c)return[n];let r=e=>a&&sy(e,`update`);return[{label:MS(`open`,{singular:CA(c,i[c.name])}),available:e=>l(e)!==void 0,link:e=>t(l(e))},{label:MS(`edit`,{singular:d}),available:r,link:n=>t({kind:`record`,resource:e.name,key:ym(e,n),edit:!0})},{...n,available:e=>!r(e)}]}}},TA=({model:e,filter:t,orderBy:n,limit:r,fields:i})=>{let a=U(),o=Se(),{resources:s,views:c}=W();return E({queryKey:[...H.list(e.name,t,n,r,`embedded`),i.join(`,`)],placeholderData:d,queryFn:async()=>{let l=Cb(s,c,e,i),u=Im(c[e.name]),d=await a.search(e.name,{filter:t||void 0,orderBy:n||void 0,pageSize:r,count:`exact`,labels:l,photos:u});await kb(o,a,s,c,e,i,d.items);let f=wb(s,e,i,Lm(e,d.items,d.photos),d.labels).map((t,n)=>({...t,id:vm(e,d.items[n])}));return d.nextPageToken===``?{rows:f,total:f.length,estimated:!1}:{rows:f,total:d.totalSize??d.totalSizeEstimate,estimated:d.totalSize===void 0}}})},EA=({view:e,value:t,onChange:n})=>(0,B.jsx)(lA,{view:e,value:t,onChange:n,menu:!gf()}),DA=()=>(0,B.jsx)(`div`,{className:`flex flex-col gap-2`,children:Array.from({length:3},(e,t)=>(0,B.jsx)(vh,{className:`h-4 w-full`},t))}),OA=({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=oy(af(e.name),`update`),{fields:h}=c_(),{go:g,href:_}=Hh(),v=_f(),[y,b]=(0,I.useState)(r||dh(e,t)),x=i??Tr(e,t),S=(0,I.useMemo)(()=>yA(e,t,x,{resources:f,views:p,fieldTypes:h}),[e,t,x.join(`,`),f,p,h]),C=(0,I.useMemo)(()=>sh(e,t,S.map(e=>e.id)),[e,t,S]),w=TA({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=Zm(t,o),O=t?.names?.plural??F(e.name),k=u&&(0,B.jsxs)(Uh,{to:zS(e,t,v,l?{filter:l.filter,orderBy:dh(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:[MS(`viewAll`),` `,(0,B.jsx)(`span`,{className:`sr-only`,children:O.toLowerCase()})]}),(0,B.jsx)(Rr,{className:`size-3.5`,"aria-hidden":!0})]});if(w.isPending)return(0,B.jsx)(DA,{});if(w.error)return(0,B.jsx)(Bg,{title:MS(`couldNotLoad`),error:w.error});if(!E||E.total===0){let e=(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:s??MS(`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=>uh(e,t)),total:w.data.total,loading:!1,error:null,more:!1,loadMore:()=>void 0},j=wA({model:e,view:t,opens:d,resources:f,views:p,canUpdate:m}),ee=e=>({href:_(e),onFollow:()=>g(e)}),te=NS(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)(Sk,{model:e,view:t,display:D,list:A,row:c||v,footer:!1}):D.kind===`map`?(0,B.jsx)(aA,{model:e,view:t,display:D,filter:n,orderBy:y,fields:C,footer:!1}):D.kind===`board`?(0,B.jsx)(fO,{model:e,view:t,display:D,fields:C,filter:n,orderBy:y,limit:a}):D.kind===`calendar`?(0,B.jsx)(XO,{model:e,view:t,display:D,fields:C,filter:n}):D.kind===`timeline`?(0,B.jsx)(_k,{model:e,view:t,display:D,fields:C,filter:n}):(0,B.jsx)(Dk,{display:D,list:A}):(0,B.jsx)(mw,{fit:!0,columns:S,source:E,latencyMs:0,sort:fh(y),onSortChange:e=>b(ph(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]})},kA=(e,t,n)=>{let r=_f(),i=FS(t),[a,o]=(0,I.useState)(()=>IS(localStorage,i)),s=(0,I.useCallback)(e=>{o(e),LS(localStorage,i,e)},[i]);return[RS(e,r,{picked:a,preferred:n}),s]},AA=({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]=kA(t,`page:${e.name}:${s??``}:${n}`,o);return(0,B.jsx)(Ay,{title:s,description:c,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(EA,{view:t,value:d,onChange:f}),u]}),className:`h-full`,children:(0,B.jsx)(OA,{model:e,view:t,filter:n,sort:r,columns:i,limit:a,display:d,empty:l})})},jA=({node:e,slots:t})=>{let n=Dy(e),{resources:r,views:i}=W(),a=r[n.resource];return a?(0,B.jsx)(AA,{...n,model:a,view:i[a.name],actions:t.actions}):null},MA=({node:e,children:t})=>{let{tab:n,pathOf:r}=cf(),{navigate:i}=jh(),a=lf(e),o=df(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":sv(`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":sv(`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)(Bh,{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)(ov,{children:sv(`noTab`,{name:n??``})})]})},NA=({children:e})=>(0,B.jsx)(`div`,{className:`flex flex-col gap-6`,children:e}),PA=({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})]}),FA=({message:e})=>e?(0,B.jsx)(`p`,{role:`alert`,className:`mb-3 text-body font-medium text-danger-text`,children:e}):null,IA=M(`auth/errors`),LA={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`},RA=(e,t)=>{let n=t?e[t]:void 0;return n&&IA(n)},zA=e=>RA(LA,e.code),BA=e=>zA(e)??(e.status===429?IA(`tooManyRequests`):e.message),VA=e=>zA(e)??(e.status===429?IA(`tooManyRequests`):e.status===401?IA(`wrongEmailOrPassword`):e.message),HA={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`},UA=e=>RA(HA,typeof e==`string`?e:e.code)||(typeof e==`string`?IA(`staffFailed`):e.status===429?IA(`tooManyRequests`):e.message),WA={signup_disabled:e=>IA(`signupDisabled`,{name:e}),account_not_linked:e=>IA(`notLinked`,{name:e}),account_already_linked_to_different_user:e=>IA(`linkedToOther`,{name:e}),unable_to_link_account:e=>IA(`couldNotLink`,{name:e}),access_denied:e=>IA(`accessDenied`,{name:e}),EMAIL_DOMAIN_NOT_ALLOWED:e=>IA(`domainNotAllowed`,{name:e})},GA=(e,t)=>WA[e]?.(t)??IA(`providerFailed`,{name:t}),KA=()=>{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 wu))throw e;r(BA(e))}t(!1)},setError:r}},qA=M(`invitations`),JA=({link:e})=>e?(0,B.jsx)(`p`,{className:`mt-3 break-all rounded-md border bg-muted px-3 py-2 text-xs`,children:qA.rich(`passLinkOn`,{link:(0,B.jsx)(`span`,{className:`font-mono`,children:e})})}):null,YA=({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}=KA(),p=()=>f(async()=>{l((await n(o.trim())).link),s(``)});return(0,B.jsxs)(PA,{title:e,description:t,children:[(0,B.jsx)(FA,{message:d}),(0,B.jsxs)(`form`,{className:`flex flex-col gap-3`,onSubmit:e=>{e.preventDefault(),p()},children:[(0,B.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,B.jsx)(J,{"aria-label":qA(`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:qA(`invite`)})]}),i]}),(0,B.jsx)(JA,{link:c})]})},XA=({email:e,gives:t,expiresAt:n,onResend:r,onRevoke:i})=>{let[a,o]=(0,I.useState)(),{busy:s,error:c,run:l}=KA(),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?qA(`expired`):qA(`until`,{date:new Date(n).toLocaleDateString(Le())})]})]}),(0,B.jsx)(G,{size:`sm`,loading:s,onClick:()=>void l(async()=>o((await r()).link)),children:qA(`sendAgain`)}),(0,B.jsx)(G,{size:`sm`,variant:`danger`,loading:s,onClick:()=>void l(i),children:qA(`revoke`)})]}),(0,B.jsx)(FA,{message:c}),(0,B.jsx)(JA,{link:a})]})},X=M(`organizations`),ZA=({roles:e,selected:t,grantable:n,disabled:r,onChange:i})=>(0,B.jsx)(`div`,{className:`flex flex-wrap gap-x-4 gap-y-2`,children:e.map(e=>{let a=t.includes(e.name),o=r||!n.has(e.name);return(0,B.jsxs)(`label`,{title:o&&!r?X(`cannotChangeRole`):void 0,className:P(`inline-flex items-center gap-1.5`,o&&`text-muted-foreground`),children:[(0,B.jsx)(TC,{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)})}),QA=`/-/organizations`,$A=`/-/organization`,ej=`/-/organization/members`,tj=`/-/organization/invitations`,nj={[QA]:`organizations`,[$A]:`organization`,[ej]:`members`,[tj]:`invitations`},rj=e=>{let t=nj[e];return t&&X(t)},ij=e=>X(e),aj=(e,t)=>e.find(e=>e.name===t)?.label??t,oj=e=>e?.role===`owner`||e?.role===`admin`,sj=(e,t,n)=>{let r=(n,r,i,a)=>({id:n,label:r,icon:i,href:`${e}${a}`,active:t===a});return[r(`organizations`,X(`manageOrganizations`),jo,QA),...n?.organization?[r(`organization`,X(`organization`),mi,$A)]:[],...oj(n)?[r(`members`,X(`members`),ac,ej),r(`invitations`,X(`invitations`),co,tj)]:[]]},cj=(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)))},lj=(e,t)=>t.map(t=>aj(e,t)).join(`, `),uj=M(`users`),dj=({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)(YA,{title:uj(`inviteSomeone`),description:uj(`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)(ZA,{roles:e,selected:n,grantable:new Set(e.map(e=>e.name)),onChange:r})}),(0,B.jsx)(PA,{title:uj(`notAcceptedYet`),description:i.length>0?uj(`sendingAgain`):uj(`nobodyWaiting`),children:i.length>0&&(0,B.jsx)(`ul`,{className:`divide-y rounded-md border`,children:i.map(n=>(0,B.jsx)(XA,{email:n.email,gives:lj(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))})})]})},fj=({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)(Tx,{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})]})}),pj=({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)(fj,{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)(fj,{title:z(`choosePassword`),description:z(`atLeast`,{length:12}),children:(0,B.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:t=>{t.preventDefault(),d(o!==c),o===c&&e(o)},children:[(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[z(`newPassword`),(0,B.jsx)(J,{type:`password`,name:`new-password`,autoComplete:`new-password`,required:!0,minLength:12,autoFocus:!0,value:o,invalid:!!f,onChange:e=>s(e.target.value),className:`min-h-6`})]}),(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[z(`repeatPassword`),(0,B.jsx)(J,{type:`password`,name:`repeat-password`,autoComplete:`new-password`,required:!0,minLength:12,value:c,invalid:!!f,onChange:e=>l(e.target.value),className:`min-h-6`})]}),f&&(0,B.jsx)(`p`,{role:`alert`,className:`text-body font-medium text-danger-text`,children:f}),(0,B.jsx)(G,{variant:`primary`,type:`submit`,loading:i,className:`min-h-10`,children:z(`setPassword`)})]})})},mj=({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}=KA(),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)(PA,{title:uj(`addAnAccount`),description:uj(`addDescription`),children:[(0,B.jsx)(FA,{message:f}),(0,B.jsxs)(`form`,{className:`flex flex-col gap-3`,onSubmit:e=>{e.preventDefault(),m()},children:[(0,B.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,B.jsx)(J,{"aria-label":uj(`email`),type:`email`,placeholder:`name@example.com`,value:r,onChange:e=>i(e.target.value),wrapperClassName:`flex-1`}),(0,B.jsx)(J,{"aria-label":uj(`name`),placeholder:uj(`name`),autoComplete:`off`,value:a,onChange:e=>o(e.target.value),wrapperClassName:`flex-1`})]}),(0,B.jsx)(J,{"aria-label":uj(`password`),type:`password`,autoComplete:`new-password`,placeholder:uj(`passwordOptional`,{length:12}),value:s,onChange:e=>c(e.target.value)}),(0,B.jsx)(ZA,{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:uj(`addAccount`)})})]})]})},hj=M(`lists`),gj=({title:e,description:t,searchLabel:n,placeholder:r,query:i,onQuery:a,list:o,error:s,renderRow:c})=>(0,B.jsxs)(PA,{title:e,description:t,children:[(0,B.jsx)(FA,{message:s}),(0,B.jsx)(J,{"aria-label":n,placeholder:r,value:i,onChange:e=>a(e.target.value),leading:(0,B.jsx)(ss,{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:hj(`showMore`)})]}),_j=(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}},vj=({name:e,email:t,self:n,actions:r,children:i,error:a,status:o})=>(0,B.jsxs)(`li`,{className:`flex flex-col gap-2 px-3 py-3`,children:[(0,B.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,B.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[o?(0,B.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,B.jsxs)(`span`,{className:`truncate font-medium`,children:[e,n&&` (you)`]}),o]}):(0,B.jsxs)(`span`,{className:`block truncate font-medium`,children:[e,n&&` (you)`]}),(0,B.jsx)(`span`,{className:`block truncate text-xs text-muted-foreground`,children:t})]}),r]}),i,(0,B.jsx)(FA,{message:a})]}),yj=({user:e,roles:t,self:n})=>{let{session:r}=V(),[i,a]=(0,I.useState)(e),{busy:o,error:s,run:c,setError:l}=KA(),u=e=>{if(e.length===0)return l(uj(`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)(vj,{name:i.name,email:i.email,self:n,error:s,actions:(0,B.jsxs)(B.Fragment,{children:[i.blocked&&(0,B.jsx)(Pf,{tone:`red`,children:uj(`blocked`)}),!n&&(i.blocked?(0,B.jsx)(G,{size:`sm`,loading:o,onClick:()=>d(!1),children:uj(`unblock`)}):(0,B.jsx)(G,{size:`sm`,variant:`danger`,loading:o,onClick:()=>d(!0),children:uj(`block`)}))]}),children:(0,B.jsx)(ZA,{roles:t,selected:i.roles,grantable:new Set(t.map(e=>e.name)),disabled:o,onChange:u})})},bj=({roles:e,version:t})=>{let{session:n,state:r}=V(),[i,a]=(0,I.useState)(``),o=_j((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)(gj,{title:uj(`people`),description:uj(`peopleDescription`),searchLabel:uj(`findSomeone`),placeholder:uj(`emailAddress`),query:i,onQuery:a,list:o,renderRow:n=>(0,B.jsx)(yj,{user:n,roles:e,self:n.id===s},`${t}/${n.id}`)})},xj=()=>{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 wu?BA(e):uj(`couldNotReadRoles`)))},[e]),{roles:t,error:r}},Sj=()=>{let{roles:e,error:t}=xj(),[n,r]=(0,I.useState)(0);return(0,B.jsxs)(`div`,{className:`flex max-w-3xl flex-col gap-4`,children:[(0,B.jsx)(FA,{message:t}),(0,B.jsx)(bj,{roles:e,version:n}),(0,B.jsx)(dj,{roles:e}),(0,B.jsx)(mj,{roles:e,onCreated:()=>r(e=>e+1)})]})},Cj=({providers:e,linked:t,onConnect:n,error:r,reconnect:i=!1,title:a=L(`connectedAccounts`),description:o=L(`connectedAccountsDescription`)})=>{let[s,c]=(0,I.useState)(),[l,u]=(0,I.useState)(r),d=async e=>{c(e),u(void 0);try{await n(e)}catch(e){if(!(e instanceof wu))throw e;u(BA(e)),c(void 0)}};return(0,B.jsxs)(PA,{title:a,description:o,children:[(0,B.jsx)(FA,{message:l}),(0,B.jsx)(`ul`,{className:`divide-y rounded-md border`,children:e.map(e=>(0,B.jsxs)(`li`,{className:`flex flex-wrap items-center gap-3 px-3 py-2.5`,children:[(0,B.jsx)(Xa,{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)(Pf,{tone:`green`,children:L(`connected`)}),(!t.includes(e.id)||i)&&(0,B.jsx)(G,{size:`sm`,loading:s===e.id,disabled:s!==void 0,onClick:()=>void d(e.id),children:L(t.includes(e.id)?`connectAgain`:`connect`,{name:e.name})})]},e.id))})]})},wj=({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)($d,{}),` `,L(`loading`)]}),Tj=(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 wu?BA(e):t))},[e,t]);return(0,I.useEffect)(o,[o]),{data:n?.value,loaded:n!==void 0,error:i,reload:o}},Ej=()=>{let e=Cd(window.location.href);return e&&window.history.replaceState(window.history.state,``,wd(window.location.href)),e},Dj=({providers:e})=>{let{session:t,linkProvider:n}=V(),{account:r}=t,[i]=(0,I.useState)(Ej),{data:a,error:o}=Tj((0,I.useCallback)(()=>r.linkedProviders(),[r]),L(`couldNotReadMethods`));return a?(0,B.jsx)(Cj,{providers:e,linked:a,onConnect:n,error:i&&GA(i,e.length===1?e[0].name:L(`theProvider`))}):(0,B.jsx)(wj,{error:o})},Oj=({signInProviders:e,socialProviders:t})=>e.filter(e=>t.includes(e.id)),kj=()=>{let e=Oj(V());return e.length>0?(0,B.jsx)(Dj,{providers:e}):null},Aj=({links:e})=>{let{session:t,linkPersonalMail:n}=V(),{account:r}=t,[i]=(0,I.useState)(Ej),{data:a,error:o}=Tj((0,I.useCallback)(()=>r.linkedPersonalMail(e),[r,e]),L(`couldNotReadMethods`));return a?(0,B.jsx)(Cj,{title:L(`mailbox`),description:L(`mailboxDescription`),providers:e.map(({id:e,name:t})=>({id:e,name:t})),linked:a,reconnect:!0,onConnect:t=>n(e.find(e=>e.id===t)),error:i&&GA(i,e.length===1?e[0].name:L(`theProvider`))}):(0,B.jsx)(wj,{error:o})},jj=()=>{let{personalMail:e}=V();return e.length>0?(0,B.jsx)(Aj,{links:e}):null},Mj=/[\u0000-\u001f\u007f-\u009f\u00ad\u061c\u115f\u1160\u180e\u200b-\u200f\u2028-\u202e\u2060-\u206f\u3164\ufe00-\ufe0f\ufeff]/g,Nj=e=>{let t=(e??``).replace(Mj,` `).replace(/\s+/g,` `).trim();if(t)return t.length>60?`${t.slice(0,59)}…`:t},Pj=e=>{if(!URL.canParse(e))return;let t=new URL(e);return t.protocol===`https:`?t.host:void 0},Fj=e=>Nj(e.name)??`An unnamed app`,Ij=e=>e.access.map(({role:e,organization:t})=>`as ${e||`no role`}${t?` in ${t}`:``}`).join(`, `),Lj=({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 wu))throw e;a(BA(e))}r(!1)};return(0,B.jsxs)(PA,{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)(FA,{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=Pj(e.clientId);return(0,B.jsxs)(`li`,{className:`flex flex-wrap items-center gap-3 px-3 py-2.5`,children:[(0,B.jsx)(fi,{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:Fj(e)}),(0,B.jsxs)(`span`,{className:`block text-xs text-muted-foreground`,children:[t&&`Published by ${t} · `,`Allowed `,cp(Date.parse(e.allowedAt)),` · `,Ij(e)]})]}),(0,B.jsx)(G,{size:`sm`,variant:`ghost`,onClick:()=>s(e),children:`Disconnect`})]},e.clientId)})}),o&&(0,B.jsx)(Cf,{title:`Disconnect ${Fj(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)(FA,{message:i})})]})},Rj=(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},zj=({url:e,appName:t})=>{let[n,r]=(0,I.useState)(!1);return(0,B.jsx)(PA,{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)(Si,{className:`size-4 text-success`}):(0,B.jsx)(Ji,{className:`size-4`})})]}),(0,B.jsxs)(`a`,{href:Rj(e,t),target:`_blank`,rel:`noreferrer`,className:mf(),children:[(0,B.jsx)(ua,{className:`size-3.5`}),L(`addToClaude`)]})]})})},Bj=()=>{let{account:e}=V().session,{data:t,error:n,reload:r}=Tj((0,I.useCallback)(()=>e.connectedApps(),[e]),L(`couldNotReadMethods`));return t?(0,B.jsx)(Lj,{apps:t,onDisconnect:t=>e.disconnectApp(t).then(r)}):(0,B.jsx)(wj,{error:n})},Vj=({url:e})=>(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(zj,{url:e,appName:W().appName}),(0,B.jsx)(Bj,{})]}),Hj=()=>{let{mcp:e}=V();return e?(0,B.jsx)(Vj,{url:e.url}):null},Uj=e=>e.code===`LAST_ADMIN`?L(`deleteAccountLastAdmin`):e.code===`ACCOUNT_LOCKED`?L(`deleteAccountLocked`):BA(e),Wj=({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 wu))throw e;c(Uj(e)),o(!1)}};return(0,B.jsx)(Cf,{title:L(`deleteAccountQuestion`),description:L(`deleteAccountWarning`),onClose:n,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:n,children:L(`cancel`)}),(0,B.jsx)(G,{variant:`danger`,type:`submit`,form:l,loading:a,disabled:e&&!r,children:L(`deleteAccountConfirm`)})]}),children:(0,B.jsxs)(`form`,{id:l,className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),u()},children:[e&&(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[L(`deleteAccountPassword`),(0,B.jsx)(J,{type:`password`,name:`current-password`,autoComplete:`current-password`,autoFocus:!0,value:r,invalid:!!s,onChange:e=>i(e.target.value)})]}),(0,B.jsx)(FA,{message:s})]})})},Gj=({hasPassword:e,staff:t,onDelete:n})=>{let[r,i]=(0,I.useState)(!1);return(0,B.jsxs)(PA,{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)(Wj,{hasPassword:e,onDelete:n,onClose:()=>i(!1)})]})},Kj=()=>{let{session:e,state:t,deleteAccount:n}=V(),{account:r}=e,{data:i,error:a}=Tj((0,I.useCallback)(()=>r.signInMethods(),[r]),L(`couldNotReadMethods`));return i?(0,B.jsx)(Gj,{hasPassword:i.account.password,staff:t.kind===`signed-in`&&!!t.staff,onDelete:n}):(0,B.jsx)(wj,{error:a})},qj=[[/Edg(e|A|iOS)?\//,`Edge`],[/OPR\/|Opera/,`Opera`],[/SamsungBrowser\//,`Samsung Internet`],[/Firefox\/|FxiOS\//,`Firefox`],[/Chrome\/|CriOS\//,`Chrome`],[/Safari\//,`Safari`]],Jj=[[/iPhone/,`iPhone`],[/iPad/,`iPad`],[/Android/,`Android`],[/CrOS/,`ChromeOS`],[/Windows/,`Windows`],[/Mac OS X|Macintosh/,`macOS`],[/Linux/,`Linux`]],Yj=(e,t)=>e.find(([e])=>e.test(t))?.[1],Xj=e=>e?{browser:Yj(qj,e),system:Yj(Jj,e)}:{},Zj=(e,t)=>{if(e.staff)return t?L(`staffOf`,{operator:t}):L(`staff`);let{browser:n,system:r}=Xj(e.userAgent);return n&&r?L(`browserOn`,{browser:n,system:r}):r?L(`aBrowserOn`,{system:r}):n??L(`unknownDevice`)},Qj=e=>{if(e.staff)return ys;let{system:t}=Xj(e.userAgent);return t===`iPhone`||t===`Android`?Ts:t===`iPad`?zs:Ba},$j=e=>[...e].sort((e,t)=>Number(t.current)-Number(e.current)||t.createdAt.localeCompare(e.createdAt)),eM=({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 wu))throw e;s(BA(e))}a(!1)},f=e=>{s(void 0),l(e)};return(0,B.jsxs)(PA,{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:$j(e).map(e=>{let n=Qj(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:Zj(e,t)}),e.current&&(0,B.jsx)(Pf,{tone:`green`,children:L(`thisDevice`)})]}),(0,B.jsxs)(`span`,{className:`block text-xs text-muted-foreground`,children:[L(`signedInFromUntil`,{from:dp(Date.parse(e.createdAt)),until:dp(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)(Cf,{title:c.kind===`one`?L(`signOutDevice`,{name:Zj(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)(FA,{message:o})})]})},tM=()=>{let{session:e,staffSignIn:t}=V(),{account:n}=e,{data:r,error:i,reload:a}=Tj((0,I.useCallback)(()=>n.sessions(),[n]),L(`couldNotReadDevices`));return r?(0,B.jsx)(eM,{sessions:r,operator:t,onSignOut:e=>n.revokeSession(e).then(a),onSignOutOthers:()=>n.revokeOtherSessions().then(a)}):(0,B.jsx)(wj,{error:i})},nM={allowed:`passkeysAllowed`,required:`passkeysRequired`,forbidden:`passkeysForbidden`},rM=({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 wu))throw e;c(BA(e))}o(!1)};return(0,B.jsxs)(PA,{title:L(`passkeys`),status:e===`required`&&(0,B.jsx)(Pf,{tone:`blue`,children:L(`required`)}),description:L(nM[e]),children:[(0,B.jsx)(FA,{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)(Ia,{className:`size-4 shrink-0 text-muted-foreground`}),(0,B.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,B.jsx)(`span`,{className:`block truncate font-medium`,children:e.name??L(`passkey`)}),(0,B.jsxs)(`span`,{className:`block text-xs text-muted-foreground`,children:[e.createdAt?L(`addedOn`,{date:cp(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)(qo,{className:`size-3.5`}),L(`addPasskey`)]}),l?.kind===`rename`&&(0,B.jsxs)(Cf,{title:L(`renamePasskey`),description:L(`renamePasskeyDescription`),onClose:()=>u(void 0),actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:()=>u(void 0),children:L(`cancel`)}),(0,B.jsx)(G,{variant:`primary`,loading:a,disabled:!d.trim(),onClick:()=>void m(()=>r(l.passkey.id,d.trim())),children:L(`save`)})]}),children:[(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[L(`name`),(0,B.jsx)(J,{autoFocus:!0,value:d,maxLength:60,onChange:e=>f(e.target.value)})]}),(0,B.jsx)(FA,{message:s})]}),l?.kind===`remove`&&(0,B.jsx)(Cf,{title:L(`removePasskey`),description:L(`removePasskeyDescription`,{name:l.passkey.name??L(`thisPasskey`)}),onClose:()=>u(void 0),actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:()=>u(void 0),children:L(`cancel`)}),(0,B.jsx)(G,{variant:`danger`,loading:a,onClick:()=>void m(()=>i(l.passkey.id)),children:L(`remove`)})]}),children:s&&(0,B.jsx)(FA,{message:s})})]})},iM=()=>{let{account:e}=V().session,{data:t,error:n,reload:r}=Tj((0,I.useCallback)(()=>Promise.all([e.signInMethods(),e.passkeys()]),[e]),L(`couldNotReadMethods`));if(!t)return(0,B.jsx)(wj,{error:n});let[i,a]=t;return(0,B.jsx)(rM,{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)})},aM=e=>e.code===`PASSWORD_TOO_SHORT`?L(`useAtLeast`,{length:12}):e.code===`PASSWORD_TOO_LONG`?L(`passwordTooLong`):BA(e),oM=(e,t)=>{if(e.length<12)return L(`useAtLeast`,{length:12});if(e!==t)return L(`passwordsDiffer`)},sM=({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=oM(a,s);if(m(e),!e){f(!0);try{await t({current:r,next:a,signOutOthers:l})}catch(e){if(!(e instanceof wu))throw e;m(aM(e)),f(!1)}}};return(0,B.jsx)(Cf,{title:L(e?`changePassword`:`setPassword`),description:L(`atLeast`,{length:12}),onClose:n,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:n,children:L(`cancel`)}),(0,B.jsx)(G,{variant:`primary`,type:`submit`,form: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)(J,{type:`password`,name:`current-password`,autoComplete:`current-password`,autoFocus:!0,value:r,onChange:e=>i(e.target.value)})]}),(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[L(`newPassword`),(0,B.jsx)(J,{type:`password`,name:`new-password`,autoComplete:`new-password`,autoFocus:!e,value:a,invalid:!!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)(J,{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)(TC,{checked:l,onChange:u,label:L(`signOutOthers`)}),L(`signOutOthers`)]}),(0,B.jsx)(FA,{message:p})]})})},cM=({rule:e,hasPassword:t,staff:n})=>L(n?`passwordStaff`:e===`forbidden`?`passwordForbidden`:t?`passwordIsSet`:`passwordNotSet`),lM=({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)(PA,{title:L(`password`),description:cM({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)(sM,{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)}})]})},uM=()=>{let{session:e,state:t}=V(),{account:n}=e,{data:r,error:i,reload:a}=Tj((0,I.useCallback)(()=>n.signInMethods(),[n]),L(`couldNotReadMethods`));return r?(0,B.jsx)(lM,{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)(wj,{error:i})},dM=({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 wu))throw e;p(BA(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)(Cf,{title:L(`changeEmail`),description:L(`codeSentTo`,{email: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)(x_,{name:`code`,required:!0,autoFocus:!0,value:c,invalid:!!f,onChange:l,onComplete:e=>!u&&void _(e)})]}),(0,B.jsx)(FA,{message:f})]}):(0,B.jsxs)(Cf,{title:L(`changeEmail`),description:L(`changeEmailDescription`),onClose:r,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:r,children:L(`cancel`)}),(0,B.jsx)(G,{variant:`primary`,loading:u,disabled:!h||h.toLowerCase()===e.toLowerCase(),onClick:()=>void g(),children:L(`sendCode`)})]}),children:[(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[L(`newEmail`),(0,B.jsx)(J,{type:`email`,autoComplete:`email`,autoFocus:!0,value:i,onChange:e=>a(e.target.value)})]}),(0,B.jsx)(FA,{message:f})]})},fM=({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 wu))throw e;m(BA(e))}f(!1)};return(0,B.jsxs)(PA,{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)(Cf,{title:L(`changeName`),description:L(`changeNameDescription`),onClose:()=>o(!1),actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:()=>o(!1),children:L(`cancel`)}),(0,B.jsx)(G,{variant:`primary`,loading:d,disabled:!l.trim()||l.trim()===e,onClick:()=>void h(),children:L(`save`)})]}),children:[(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[L(`name`),(0,B.jsx)(J,{autoFocus:!0,value:l,maxLength:100,onChange:e=>u(e.target.value)})]}),(0,B.jsx)(FA,{message:p})]}),s&&r&&(0,B.jsx)(dM,{email:t,change:r,onClose:()=>c(!1),onDone:()=>{c(!1),i?.()}})]})},pM=()=>{let{session:e,changeEmail:t}=V(),{data:n,loaded:r,error:i,reload:a}=Tj((0,I.useCallback)(()=>e.session(),[e]),L(`couldNotReadProfile`));if(!r)return(0,B.jsx)(wj,{error:i});if(!n)return null;let o=t?{request:e.account.requestEmailChange,confirm:e.account.changeEmail}:void 0;return(0,B.jsx)(fM,{name:n.name,email:n.email,onRename:t=>e.account.updateName(t).then(a),emailChange:o,onEmailChanged:a})},mM=(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)},hM=({codes:e})=>{let[t,n]=(0,I.useState)(!1),r=`${e.join(`
|
|
4
|
+
`)}\n`;return(0,B.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,B.jsx)(`ul`,{"aria-label":L(`backupCodes`),className:`grid grid-cols-2 gap-x-4 gap-y-1 rounded-md border bg-surface p-3 font-mono`,children:e.map(e=>(0,B.jsx)(`li`,{children:e},e))}),(0,B.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,B.jsxs)(G,{size:`sm`,onClick:()=>{navigator.clipboard.writeText(r).then(()=>{n(!0),setTimeout(()=>n(!1),2e3)})},children:[t?(0,B.jsx)(Si,{className:`size-3.5 text-success`}):(0,B.jsx)(Ji,{className:`size-3.5`}),L(t?`copied`:`copy`)]}),(0,B.jsxs)(G,{size:`sm`,onClick:()=>mM(r,`backup-codes.txt`),children:[(0,B.jsx)(na,{className:`size-3.5`}),L(`download`)]})]})]})},gM=({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 wu))throw e;f(BA(e)),u(!1)}};return(0,B.jsxs)(Cf,{title:e,description:t,onClose:o,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:o,children:L(`cancel`)}),(0,B.jsx)(G,{variant:r?`danger`:`primary`,loading:l,disabled:i&&!s,onClick:()=>void p(),children:n})]}),children:[i&&(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[L(`yourPassword`),(0,B.jsx)(J,{type:`password`,autoComplete:`current-password`,autoFocus:!0,value:s,invalid:!!d,onChange:e=>c(e.target.value),onKeyDown:e=>e.key===`Enter`&&s&&void p()})]}),d&&(0,B.jsx)(`p`,{role:`alert`,className:`mt-2 text-body font-medium text-danger-text`,children:d})]})},_M=({uri:e,className:t})=>{let{size:n,path:r}=(0,I.useMemo)(()=>{let t=Ce(e,{ecc:`M`,border:2}),n=t.data.flatMap((e,t)=>e.flatMap((e,n)=>e?[`M${n} ${t}h1v1h-1z`]:[]));return{size:t.size,path:n.join(``)}},[e]);return(0,B.jsxs)(`svg`,{viewBox:`0 0 ${n} ${n}`,role:`img`,"aria-label":L(`qrCode`),shapeRendering:`crispEdges`,className:t,children:[(0,B.jsx)(`rect`,{width:n,height:n,fill:`#fff`}),(0,B.jsx)(`path`,{d:r,fill:`#000`})]})},vM=e=>(new URL(e).searchParams.get(`secret`)??``).replace(/(.{4})(?=.)/g,`$1 `),yM=()=>[{value:`app`,label:L(`authenticatorApp`),description:L(`authenticatorAppDescription`)},{value:`email`,label:L(`emailedCode`),description:L(`emailedCodeDescription`)}],bM=({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?yM():yM().filter(e=>e.value===`app`),b=async e=>{g(!0),v(void 0);try{await e()}catch(e){if(!(e instanceof wu))throw e;v(BA(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)(hM,{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)(_M,{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:vM(s.setup.totpURI)})]})]}),(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[L(`codeFromApp`),(0,B.jsx)(x_,{name:`code`,required:!0,autoFocus:!0,value:p,invalid:!!_,onChange:m,onComplete:e=>!h&&void S(s.setup,e)})]}),C,(0,B.jsx)(G,{variant:`primary`,type:`submit`,loading:h,className:`min-h-10`,children:L(`turnOn`)}),o&&(0,B.jsx)(G,{variant:`ghost`,onClick:o,className:`min-h-10`,children:L(`cancel`)})]}):(0,B.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),x()},children:[(0,B.jsx)(`div`,{role:`radiogroup`,"aria-label":L(`secondStep`),className:`flex flex-col gap-2`,children:y.map(e=>(0,B.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":l===e.value,onClick:()=>u(e.value),className:P(`rounded-md border p-3 text-left transition-colors`,l===e.value?`border-primary bg-primary-soft`:`border-border-strong hover:bg-muted`),children:[(0,B.jsx)(`span`,{className:`block font-medium`,children:e.label}),(0,B.jsx)(`span`,{className:`mt-0.5 block text-xs text-muted-foreground`,children:e.description})]},e.value))}),t&&(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[L(`yourPassword`),(0,B.jsx)(J,{type:`password`,name:`password`,autoComplete:`current-password`,required:!0,value:d,invalid:!!_,onChange:e=>f(e.target.value),className:`min-h-6`})]}),C,(0,B.jsx)(G,{variant:`primary`,type:`submit`,loading:h,className:`min-h-10`,children:L(`continue`)}),o&&(0,B.jsx)(G,{variant:`ghost`,onClick:o,className:`min-h-10`,children:L(`cancel`)})]})},xM={allowed:`twoFactorAllowed`,required:`twoFactorRequired`,forbidden:`twoFactorForbidden`},SM=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)(Pf,{tone:`green`,children:L(`on`)}):t===`required`?(0,B.jsx)(Pf,{tone:`amber`,children:L(`required`)}):(0,B.jsx)(Pf,{children:L(`off`)}),p=L(n?r?i?`twoFactorOnWithAppOrMail`:`twoFactorOnWithApp`:`twoFactorOnWithMail`:xM[t]);return l?.kind===`setup`?(0,B.jsx)(PA,{title:L(`twoFactor`),status:f,description:p,children:(0,B.jsx)(`div`,{className:`max-w-sm`,children:(0,B.jsx)(bM,{offerEmailedCodes:i&&!l.appOnly,needsPassword:a,onStartApp:e.onStartApp,onConfirmApp:e.onConfirmApp,onEmailedCodes:e.onEmailedCodes,onCancel:d,onDone:()=>{d(),c()}})})}):(0,B.jsxs)(PA,{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)(gM,{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)(gM,{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)(Cf,{title:L(`yourNewCodes`),description:L(`keepCodesSafe`),onClose:d,actions:(0,B.jsx)(G,{variant:`primary`,onClick:d,children:L(`savedCodes`)}),children:(0,B.jsx)(hM,{codes:l.codes})})]})},CM={Page:wS,Grid:Yb,Card:My,Stat:OD,RecordCard:OS,Field:Wb,Table:jA,CardRow:Py,RecordRow:vD,RecordCards:qS,Chart:yb,Progress:ES,ModalForm:fx,Action:ky,Show:wD,Link:Zb,Settings:SD,Tabs:MA,Tab:NA,Users:Sj,Profile:pM,Password:uM,Passkeys:iM,TwoFactor:()=>{let{account:e}=V().session,{data:t,error:n,reload:r}=Tj((0,I.useCallback)(()=>e.signInMethods(),[e]),L(`couldNotReadMethods`));return t?(0,B.jsx)(SM,{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)(wj,{error:n})},ConnectedAccounts:kj,PersonalMail:jj,Devices:tM,ConnectedApps:Hj,DeleteAccount:Kj},wM=e=>typeof e==`string`||!e.custom&&e.type===`Link`,TM=e=>{let t=[];for(let n of e){let e=t.at(-1);wM(n)&&e&&wM(e[0])?e.push(n):t.push([n])}return t.map((e,t)=>{let[n]=e;return wM(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)(OM,{node:e},t))},t):(0,B.jsx)(OM,{node:n},t)})},EM=e=>ru(e)||Array.isArray(e)&&e.length>0&&e.every(ru),DM=e=>Object.fromEntries(Object.entries(e.props).flatMap(([e,t])=>EM(t)?[[e,(0,B.jsx)(B.Fragment,{children:TM(Array.isArray(t)?t:[t])})]]:[])),OM=({node:e})=>{let{components:t}=c_();if(e.custom){let n=t?.[e.type];return n?(0,B.jsx)(cv,{name:e.type,children:(0,B.jsx)(n,{...vn(e.props),children:e.children.length>0?TM(e.children):void 0})}):(0,B.jsx)(ov,{children:sv.rich(`noComponent`,{component:e.type})})}let n=CM[e.type];return n?(0,B.jsx)(n,{node:e,slots:DM(e),children:TM(e.children)}):(0,B.jsx)(ov,{children:sv.rich(`unknownBlock`,{type:e.type})})},kM=(e,t)=>{let n=uu(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},AM=()=>{let{account:e}=W(),t=V(),{mcp:n,accountDeletion:r}=t,i=Oj(t).length>0,a=t.personalMail.length>0;return(0,I.useMemo)(()=>{if(!e)return;let t=new Set([...n?[]:[`ConnectedApps`],...i?[]:[`ConnectedAccounts`],...a?[]:[`PersonalMail`],...r?[]:[`DeleteAccount`]]);return{...e,tree:kM(e.tree,t)}},[e,n,i,a,r])},jM=({tab:e})=>{let t=AM();return t?(0,B.jsx)(sf,{route:{...e&&{tab:e},pathOf:Ec},children:(0,B.jsx)(OM,{node:t.tree})}):(0,B.jsx)(tf,{title:L(`noAccount`),children:L(`noAccountDescription`)})},MM=({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?[Dg(`title`,{noun:i})]:[],...s];let c=a??(o?void 0:e.key);return[...c?[c]:[],...s]},NM=(e,t)=>[...e.filter(Boolean),t].join(` · `),PM=e=>{(0,I.useEffect)(()=>{let t=document.title;return document.title=e,()=>{document.title=t}},[e])},FM=500,IM=(e=window)=>e.top!==e.self,LM=(e,t,n)=>{let r=!1,i,a=e=>{r!==e&&(r=e,n(e))},o=()=>{clearTimeout(i),a(!1)},s=()=>{o(),e.defaultView&&e.visibilityState===`visible`&&e.hasFocus()&&(i=setTimeout(()=>a(!0),t))},c=()=>e.visibilityState===`visible`?s():o(),l=()=>{r||s()},u=e=>{`persisted`in e&&e.persisted&&s()};return e.defaultView?.addEventListener(`focus`,s),e.defaultView?.addEventListener(`blur`,o),e.defaultView?.addEventListener(`pagehide`,o),e.defaultView?.addEventListener(`pageshow`,u),e.addEventListener(`visibilitychange`,c),e.addEventListener(`pointerdown`,l,!0),e.addEventListener(`keydown`,l,!0),s(),()=>{clearTimeout(i),e.defaultView?.removeEventListener(`focus`,s),e.defaultView?.removeEventListener(`blur`,o),e.defaultView?.removeEventListener(`pagehide`,o),e.defaultView?.removeEventListener(`pageshow`,u),e.removeEventListener(`visibilitychange`,c),e.removeEventListener(`pointerdown`,l,!0),e.removeEventListener(`keydown`,l,!0)}},RM=()=>{let e=!1;return{down:(t,n=!1)=>{e=t&&!n},take:()=>{let t=e;return e=!1,t}}},zM=(e,t)=>n=>n?e(!0):t(()=>e(!1)),BM=e=>{let[t,n]=(0,I.useState)(!1);return(0,I.useEffect)(()=>LM(document,e,zM(n,Sc.flushSync)),[e]),t},VM=(e,t)=>{let n=(0,I.useRef)(RM());return{onPointerDown:()=>n.current.down(e),onKeyDown:t=>n.current.down(e,t.repeat),onClick:()=>{n.current.take()&&t()}}},HM=[`localhost`,`127.0.0.1`,`[::1]`],UM=[`javascript:`,`data:`,`vbscript:`,`file:`,`blob:`,`about:`],WM=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 HM.includes(t.hostname)?{kind:`this-computer`,port:t.port||`80`}:void 0;if(!UM.includes(t.protocol))return{kind:`device-app`,uri:e.split(`?`)[0].split(`#`)[0]}},GM=e=>!URL.canParse(e,`http://local`)||!UM.includes(new URL(e,`http://local`).protocol),KM=(e,t)=>{let n=new URL(e,t.origin);if(n.origin===t.origin&&n.pathname===t.pathname)return Kc(n.search).oauthQuery},qM=()=>{let{params:e}=jh();return(0,I.useMemo)(()=>Kc(e.toString()),[e])},JM={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.`},YM=e=>{if(!(e instanceof wu))throw e;return(e.code&&JM[e.code])??BA(e)},XM=e=>t=>{if(!GM(t))throw new wu(`The app asked to be sent somewhere this page will not go.`,400);e(t)},ZM=({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})]}),QM=({title:e,icon:t,children:n})=>(0,B.jsx)(fj,{title:e,icon:t,children:(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:n})}),$M=({asking:e,appName:t,appIcon:n,email:r,onAnswer:i,onSignOut:a})=>{let[o,s]=(0,I.useState)(!1),c=BM(500),l=e=>{s(!0),i(e).finally(()=>s(!1))},u=VM(c&&!o,()=>l(!0)),d=Nj(e.client.client_name),f=Pj(e.client.client_id),{target:p}=e;return(0,B.jsx)(fj,{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)(ZM,{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`})]})]})})},eN=({oauthQuery:e,appName:t,appIcon:n,email:r,assign:i})=>{let{session:a,signOut:o}=V(),{path:s,basePath:c}=jh(),l=XM(i),u=e=>KM(e,{origin:window.location.origin,pathname:`${c}${s}`}),[d,f]=(0,I.useState)({kind:`loading`}),p=e=>f({kind:`failed`,message:YM(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:WM(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)(QM,{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)($d,{}),` Loading`]}):(0,B.jsx)($M,{asking:d.asking,appName:t,appIcon:n,email:r,onAnswer:e=>m(e,d.asking),onSignOut:()=>void o()})},tN=({email:e,appName:t,appIcon:n,isFramed:r=IM,assign:i=e=>window.location.assign(e)})=>{let[a]=(0,I.useState)(r),{oauthQuery:o}=qM();return a?(0,B.jsxs)(QM,{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)(eN,{oauthQuery:o,appName:t,appIcon:n,email:e,assign:i},o):(0,B.jsx)(QM,{title:`Nothing to connect`,icon:n,children:`Connect again from your app.`})},nN={title:`Sign in to connect an app`,description:`An app asks to act as you here. Sign in, then choose whether to allow it.`},rN=()=>{let e=W(),{state:t}=V();return PM(NM([`Connect an app`],e.appName)),t.kind===`signed-in`?(0,B.jsx)(tN,{email:t.user.email,appName:e.appName??`this app`,appIcon:e.appIcon}):(0,B.jsx)(fj,{title:nN.title,description:nN.description,icon:e.appIcon,children:(0,B.jsx)(`div`,{className:`flex flex-col gap-2 [&>*]:min-h-10 [&>*]:w-full`,children:(0,B.jsx)(rE,{prompt:nN})})})},iN=()=>[{value:`allowed`,label:L(`on`)},{value:`forbidden`,label:L(`off`)}],aN=()=>[{value:`allowed`,label:L(`optional`)},{value:`required`,label:L(`required`)},{value:`forbidden`,label:L(`off`)}],oN=()=>[{method:`password`,label:L(`password`),description:L(`passwordDescription`),rules:iN()},{method:`emailCode`,label:L(`emailedSignInCode`),description:L(`emailedSignInCodeDescription`),rules:iN()},{method:`passkey`,label:L(`passkeys`),description:L(`passkeysPolicyDescription`),rules:aN()},{method:`twoFactor`,label:L(`twoFactor`),description:L(`twoFactorPolicyDescription`),rules:aN()},{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:iN()}],sN=(e,t)=>{let n=oN().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},cN=({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))}),lN=({method:e},t,{mail:n,effective:r,policy:i})=>{if(e===`emailCode`&&!n)return L(`codeNeedsMail`);if(e===`password`&&!n&&t.password===`forbidden`)return L(`passwordStaysOn`);if(e===`staffAccess`&&!n&&t.staffAccess===`notify`)return L(`staffNeedsMail`);if(e===`platformSignIn`&&t.platformSignIn===`allowed`&&(t.passkey===`required`||t.twoFactor===`required`))return L(`platformOff`);if(t[e]===i[e]&&r[e]!==i[e])return L(`appliesAs`,{rule:sN(e,r[e])})},uN=({operator:e,platformSignIn:t})=>oN().flatMap(n=>n.method===`staffAccess`&&!e?[]:n.method===`platformSignIn`?t?[{...n,label:L(`platformSignInWith`,{provider:t})}]:[]:[n]),dN=({state:e,onSave:t,busy:n,error:r,notice:i})=>{let[a,o]=(0,I.useState)(e.policy),s=uN(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=lN(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)(cN,{row:t,value:a[t.method],onChange:e=>o({...a,[t.method]:e})})]},t.method)})}),r&&(0,B.jsx)(`p`,{role:`alert`,className:`rounded-md bg-danger-soft px-3 py-2 text-body font-medium text-danger-text`,children:r}),i&&!c&&(0,B.jsx)(`p`,{role:`status`,className:`rounded-md bg-success-soft px-3 py-2 text-body font-medium text-success-text`,children:i}),(0,B.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.savedAt?e.savedBy?L(`lastSavedBy`,{name:e.savedBy,time:dp(Date.parse(e.savedAt))}):L(`lastSaved`,{time:dp(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`)})]})]})]})},fN=(e,t)=>e.endedAt?(0,B.jsx)(Pf,{tone:`neutral`,children:L(`stopped`,{time:dp(Date.parse(e.endedAt))})}):Date.parse(e.expiresAt)<=t?(0,B.jsx)(Pf,{tone:`neutral`,children:L(`ended`,{time:dp(Date.parse(e.expiresAt))})}):(0,B.jsx)(Pf,{tone:`amber`,children:L(`signedInUntil`,{time:dp(Date.parse(e.expiresAt))})}),pN=({signIns:e,operator:t,error:n,now:r=Date.now()})=>(0,B.jsxs)(PA,{title:L(`staffSignIns`),description:L(`staffSignInsDescription`,{operator:t}),children:[(0,B.jsx)(FA,{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:dp(Date.parse(e.startedAt))}),fN(e,r)]})]},e.id))})]}),mN=({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 wu?BA(e):L(`couldNotReadStaffSignIns`)))},[t]),(0,B.jsx)(pN,{operator:e,signIns:n,error:i})},hN=()=>{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 wu?BA(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 wu))throw e;o(BA(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)(SS,{title:L(`signInPolicy`),subtitle:L(`policySubtitle`)}),t?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(dN,{state:t,busy:r,error:a,notice:s,onSave:e=>void l(e)},t.savedAt??`default`),t.operator&&(0,B.jsx)(mN,{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)($d,{}),` `,L(`loading`)]})]})},gN=({onResend:e,cooldown:t=30,disabled:n})=>{let[r,i]=(0,I.useState)(()=>Date.now()+t*1e3),[a,o]=(0,I.useState)(()=>Date.now()),s=Math.max(0,Math.ceil((r-a)/1e3));return(0,I.useEffect)(()=>{if(s===0)return;let e=setInterval(()=>o(Date.now()),1e3);return()=>clearInterval(e)},[s]),(0,B.jsx)(G,{variant:`ghost`,disabled:n||s>0,onClick:()=>{let n=Date.now();i(n+t*1e3),o(n),e()},className:`min-h-10`,children:s>0?z(`sendNewCodeIn`,{seconds:s}):z(`sendNewCode`)})},_N=({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)(fj,{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)(x_,{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)(gN,{onResend:a,disabled:c,cooldown:d})]})]})]})},vN=({email:e,onBack:t,...n})=>(0,B.jsx)(_N,{title:z(`checkEmail`),description:z(`signInCodeDescription`),explanation:(0,B.jsx)(B.Fragment,{children:z.rich(`signInCodeSent`,{email:(0,B.jsx)(`span`,{className:`font-medium text-foreground`,children:e})})}),submitLabel:z(`signIn`),onChangeAddress:t,changeAddressLabel:z(`backToSignIn`),...n}),yN=({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 wu))throw e;s(BA(e))}a(!1)};return(0,B.jsx)(vN,{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`))})})},bN=`protobase users create you@example.com`,xN=({command:e=bN,firstAdminUrl:t,onCheckAgain:n,busy:r})=>(0,B.jsxs)(fj,{title:z(`noAdminTitle`),description:z(`noAdminDescription`),children:[t?(0,B.jsx)(SN,{url:t}):(0,B.jsx)(CN,{command:e}),(0,B.jsx)(G,{variant:t?`secondary`:`primary`,className:`mt-4 min-h-10 w-full`,loading:r,onClick:n,children:z(`reload`)})]}),SN=({url:e})=>(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:z(`firstAdminExplanation`)}),(0,B.jsxs)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,className:P(mf({variant:`primary`}),`mt-4 min-h-10 w-full`),children:[z(`firstAdminLink`),(0,B.jsx)(ua,{className:`size-4`})]})]}),CN=({command:e})=>{let[t,n]=(0,I.useState)(!1);return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:z(`noAdminExplanation`)}),(0,B.jsxs)(`div`,{className:`mt-4 flex items-center gap-2 rounded-md border bg-surface py-1.5 pl-3 pr-1.5`,children:[(0,B.jsx)(`code`,{className:`min-w-0 flex-1 break-all font-mono text-xs`,children:e}),(0,B.jsx)(`button`,{type:`button`,"aria-label":z(`copyCommand`),onClick:()=>{navigator.clipboard.writeText(e).then(()=>{n(!0),setTimeout(()=>n(!1),2e3)})},className:`inline-flex size-8 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-muted pointer-coarse:size-11`,children:t?(0,B.jsx)(Si,{className:`size-4 text-success`}):(0,B.jsx)(Ji,{className:`size-4`})})]})]})},wN=({onSubmit:e,back:t,busy:n,error:r,sentTo:i})=>{let[a,o]=(0,I.useState)(``);return i?(0,B.jsxs)(fj,{title:z(`checkEmail`),children:[(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:z.rich(`resetSent`,{email:(0,B.jsx)(`span`,{className:`font-medium text-foreground`,children:i})})}),(0,B.jsx)(Sh,{to:t,className:P(mf({variant:`primary`}),`mt-4 min-h-10 w-full`),children:z(`backToSignIn`)})]}):(0,B.jsx)(fj,{title:z(`resetTitle`),description:z(`resetDescription`),children:(0,B.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:t=>{t.preventDefault(),e(a.trim())},children:[(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[z(`email`),(0,B.jsx)(J,{type:`email`,name:`email`,autoComplete:`username`,required:!0,autoFocus:!0,value:a,invalid:!!r,onChange:e=>o(e.target.value),className:`min-h-6`})]}),r&&(0,B.jsx)(`p`,{role:`alert`,className:`text-body font-medium text-danger-text`,children:r}),(0,B.jsx)(G,{variant:`primary`,type:`submit`,loading:n,className:`min-h-10`,children:z(`sendResetLink`)}),(0,B.jsx)(Sh,{to:t,className:P(mf({variant:`ghost`}),`min-h-10`),children:z(`backToSignIn`)})]})})},TN=`password-reset`,EN=e=>{let t=new URL(e);return`${t.origin}${t.pathname}?${TN}`},DN=e=>{let t=new URL(e).searchParams;if(t.has(`password-reset`))return{token:t.get(`token`)||void 0}},ON=e=>{let t=new URL(e);for(let e of[TN,`token`,`error`])t.searchParams.delete(e);return`${t.pathname}${t.search}${t.hash}`},kN=({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,EN(window.location.href)),s(e)}catch(e){if(!(e instanceof wu))throw e;a(e.status===429?z(`tooManyRequests`):e.message)}r(!1)};return(0,B.jsx)(wN,{busy:n,error:i,sentTo:o,back:e,onSubmit:e=>void c(e)})},AN=({name:e,workspace:t})=>(0,B.jsx)(fj,{title:z(`signingInWith`,{name:e}),description:t,children:(0,B.jsxs)(`p`,{role:`status`,className:`flex items-center justify-center gap-2 text-muted-foreground`,children:[(0,B.jsx)($d,{}),` `,z(`takingYouTo`,{name:e})]})}),jN=({provider:e,workspace:t,onFailed:n})=>{let{signInProviders:r,signInSocial:i}=V(),a=r.find(t=>t.id===e),o=a?.name??Ed(e),s=(0,I.useRef)(!1);return(0,I.useEffect)(()=>{if(!s.current){if(s.current=!0,!a)return n(z(`providerNotOffered`,{name:o}));i(e).catch(e=>{if(!(e instanceof wu))throw e;n(VA(e))})}},[a,o,e,i,n]),(0,B.jsx)(AN,{name:o,workspace:t})},MN=e=>e.status===429?z(`tooManyAttempts`):e.code===`PASSWORD_TOO_SHORT`?z(`useAtLeast`,{length:12}):e.code===`PASSWORD_TOO_LONG`?z(`passwordTooLong`):BA(e),NN=({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 wu))throw e;e.code===`INVALID_TOKEN`?u(!0):c(MN(e)),o(!1)}};return(0,B.jsx)(pj,{busy:a,error:s,invalidLink:l,onRequestNewLink:n,onBack:r,onSubmit:e=>void d(e)})},PN=e=>z(e===`twoFactor`?`turnOnTwoFactor`:`addPasskey`),FN=({step:e,twoFactor:t,onAddPasskey:n,busy:r,error:i,onSignOut:a})=>(0,B.jsxs)(fj,{title:PN(e),description:z(`requiredForEveryAccount`),children:[e===`twoFactor`?(0,B.jsx)(bM,{...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)(Ia,{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`)})]}),IN=({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 wu?BA(e):z(`couldNotReadAccount`)))},[t]);let u=async()=>{s(!0),l(void 0);try{await t.account.addPasskey(),n()}catch(e){if(!(e instanceof wu))throw e;l(BA(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)($d,{}),` `,z(`loading`)]}):(0,B.jsx)(FN,{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}})},LN=({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`})}),RN=({id:e,className:t})=>e===`github`?(0,B.jsx)(LN,{className:t}):null,zN=()=>(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`})]}),BN=({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)(fj,{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)(RN,{id:e.id}),z(`continueWith`,{name:e.name})]},e.id)),w&&(0,B.jsxs)(G,{onClick:()=>c?.(),disabled:t,className:`min-h-10 w-full`,children:[(0,B.jsx)(Ia,{className:`size-4`}),z(`signInWithPasskey`)]}),w&&l.slice(1).map(e=>(0,B.jsx)(G,{variant:`ghost`,size:`sm`,onClick:()=>c?.(e),disabled:t,className:`w-full`,children:z(`passkeyFor`,{domain:e})},e))]}),S||C?(0,B.jsx)(zN,{}):n&&(0,B.jsx)(`p`,{role:`alert`,className:`mt-4 text-body font-medium text-danger-text`,children:n})]}),(S||C)&&(0,B.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:t=>{t.preventDefault(),D?e(h.trim(),_):O()},children:[(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[z(`email`),(0,B.jsx)(J,{ref:x,type:`email`,name:`email`,autoComplete:`username webauthn`,required:!0,autoFocus:!0,value:h,invalid:!!n,onChange:e=>g(e.target.value),className:`min-h-6`})]}),D&&(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[z(`password`),(0,B.jsx)(J,{type:`password`,name:`password`,autoComplete:`current-password`,required:!0,value:_,invalid:!!n,onChange:e=>v(e.target.value),className:`min-h-6`})]}),n&&(0,B.jsx)(`p`,{role:`alert`,className:`text-body font-medium text-danger-text`,children:n}),D&&(0,B.jsx)(G,{variant:`primary`,type:`submit`,loading:t,className:`min-h-10`,children:z(`signIn`)}),C&&(0,B.jsxs)(G,{variant:D?`secondary`:`primary`,type:D?`button`:`submit`,onClick:D?O:void 0,loading:t&&!D,disabled:t,className:`min-h-10`,children:[(0,B.jsx)(co,{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)(Sh,{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)(Sh,{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`)})]})},VN=({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 wu))throw e;v(t(e)),g(!1)}};return(0,B.jsx)(BN,{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),VA),passkeyDomains:f,onPasskey:e=>void y(()=>m(e),BA),onSendCode:e=>void y(async()=>{await p(e),a(e)},BA),onSubmit:(e,t)=>void y(()=>s(e,t),VA)})},HN=({email:e,onBack:t,...n})=>(0,B.jsx)(_N,{title:z(`checkEmail`),description:z(`signUpCodeDescription`),explanation:(0,B.jsx)(B.Fragment,{children:z.rich(`signUpCodeSent`,{email:(0,B.jsx)(`span`,{className:`font-medium text-foreground`,children:e})})}),submitLabel:z(`continue`),onChangeAddress:t,changeAddressLabel:z(`useAnotherAddress`),...n}),UN=({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)(fj,{title:z(`detailsTitle`),description:z(`detailsDescription`),children:[(0,B.jsx)(`p`,{className:`mb-4 text-muted-foreground`,children:z.rich(`codeWasRight`,{email:(0,B.jsx)(`span`,{className:`font-medium text-foreground`,children:e})})}),(0,B.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),t({name:o.trim(),...d&&c&&{password:c}})},children:[(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[z(`yourName`),(0,B.jsx)(J,{name:`name`,autoComplete:`name`,required:!0,autoFocus:!0,maxLength:200,value:o,onChange:e=>s(e.target.value),className:`min-h-6`})]}),d&&(0,B.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[z(f?`passwordOptional`:`password`),(0,B.jsx)(J,{type:`password`,name:`password`,autoComplete:`new-password`,"aria-describedby":u,required:!f,minLength:12,maxLength:128,value:c,onChange:e=>l(e.target.value),className:`min-h-6`})]}),(0,B.jsxs)(`p`,{id:u,className:`text-xs text-muted-foreground`,children:[z(`atLeast`,{length:12}),f&&z(`withoutPassword`)]})]}),a&&(0,B.jsx)(`p`,{role:`alert`,className:`text-body font-medium text-danger-text`,children:a}),(0,B.jsx)(G,{variant:`primary`,type:`submit`,loading:i,className:`min-h-10`,children:z(`createAccount`)}),(0,B.jsx)(G,{variant:`ghost`,onClick:n,className:`min-h-10`,children:z(`useAnotherAddress`)})]})]})},WN=({onSubmit:e,onSignIn:t,onBrowse:n,busy:r,error:i,workspace:a})=>{let[o,s]=(0,I.useState)(``);return(0,B.jsxs)(fj,{title:z(`createAnAccount`),description:a,children:[(0,B.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:t=>{t.preventDefault(),e(o.trim())},children:[(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[z(`email`),(0,B.jsx)(J,{type:`email`,name:`email`,autoComplete:`email`,required:!0,autoFocus:!0,value:o,invalid:!!i,onChange:e=>s(e.target.value),className:`min-h-6`})]}),(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:z(`codeToConfirm`)}),i&&(0,B.jsx)(`p`,{role:`alert`,className:`text-body font-medium text-danger-text`,children:i}),(0,B.jsxs)(G,{variant:`primary`,type:`submit`,loading:r,className:`min-h-10`,children:[(0,B.jsx)(co,{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`)})]})},GN=({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 wu))throw e;h(BA(e))}p(!1)};return t===void 0?(0,B.jsx)(WN,{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)(HN,{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)(UN,{email:t,methods:c,busy:f,error:m,onBack:a,onSubmit:e=>void v(()=>d({ticket:n,...e}))})},KN=`staff-sign-in`,qN=`staff-error`,JN=e=>{let t=new URL(e).searchParams,n=t.get(qN);if(!t.has(`staff-sign-in`)&&!n)return;let r=t.has(KN);return{email:r&&t.get(`email`)||``,reason:r&&t.get(`reason`)||``,...n&&{error:n}}},YN=e=>{let t=new URL(e);if(t.searchParams.has(`staff-sign-in`))for(let e of[KN,`email`,`reason`])t.searchParams.delete(e);return t.searchParams.delete(qN),`${t.pathname}${t.search}${t.hash}`},XN=10,ZN=({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)(fj,{title:z(`signInAsPerson`),description:z(`forStaffOf`,{operator:e}),children:(0,B.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),r(s.trim(),l.trim())},children:[(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[z(`theirEmail`),(0,B.jsx)(J,{type:`email`,name:`email`,required:!0,autoFocus:!t,value:s,onChange:e=>c(e.target.value),className:`min-h-6`})]}),(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[z(`reason`),(0,B.jsx)(`textarea`,{name:`reason`,required:!0,minLength:XN,rows:3,value:l,placeholder:z(`reasonExample`),onChange:e=>u(e.target.value),className:P(`resize-y rounded-md border bg-background px-2.5 py-1.5 font-normal shadow-sm outline-none placeholder:text-faint-foreground focus:border-primary focus:ring-2 focus:ring-primary/20`,o?`border-danger`:`border-border-strong`)})]}),(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:z(`staffExplanation`,{operator:e})}),o&&(0,B.jsx)(`p`,{role:`alert`,className:`text-body font-medium text-danger-text`,children:o}),(0,B.jsx)(G,{variant:`primary`,type:`submit`,loading:a,className:`min-h-10`,children:z(`continueWith`,{name:e})}),(0,B.jsx)(G,{variant:`ghost`,onClick:i,className:`min-h-10`,children:z(`backToSignIn`)})]})}):(0,B.jsxs)(fj,{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`)})]})},QN=({link:e,onBack:t})=>{let{session:n,staffSignIn:r}=V(),[i,a]=(0,I.useState)(!1),[o,s]=(0,I.useState)(e.error&&UA(e.error)),c=async(e,t)=>{a(!0),s(void 0);try{let r=`${window.location.origin}${YN(window.location.href)}`;window.location.assign(await n.staff.start({email:e,reason:t,callbackURL:r}))}catch(e){if(!(e instanceof wu))throw e;s(UA(e)),a(!1)}};return(0,B.jsx)(ZN,{operator:r,email:e.email,reason:e.reason,busy:i,error:o,onBack:t,onSubmit:(e,t)=>void c(e,t)})},$N={totp:`totpInstruction`,otp:`otpInstruction`,backup:`backupInstruction`},eP=({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)(fj,{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($N[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)(J,{name:`code`,autoComplete:`off`,spellCheck:!1,required:!0,autoFocus:!0,value:u,invalid:!!a,onChange:e=>d(e.target.value),className:`min-h-6 font-mono`}):(0,B.jsx)(x_,{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)(TC,{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`)})]})]})},tP=({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 wu))throw e;s(BA(e))}a(!1)};return(0,B.jsx)(eP,{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)})})},nP=e=>{let t=new URL(e),n=t.searchParams.get(`token`);return t.pathname.endsWith(`/-/invitation`)&&n?{token:n}:void 0},rP=e=>`${new URL(e).pathname.slice(0,-13)}/`,iP=({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}=KA(),m=a.includes(`password`),h=a.includes(`emailCode`),g=()=>p(async()=>{await i.organizations.signUpFromInvitation(e,{name:s.trim(),...m&&l&&{password:l}}),r(),o()});return(0,B.jsxs)(`form`,{className:`flex flex-col gap-3`,onSubmit:e=>{e.preventDefault(),g()},children:[(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:X(n?`makeAccountToJoin`:`makeAccount`,{email:t.email})}),f&&(0,B.jsx)(`p`,{role:`alert`,className:`text-body font-medium text-danger-text`,children:f}),(0,B.jsx)(J,{"aria-label":X(`yourName`),placeholder:X(`yourName`),autoComplete:`name`,value:s,onChange:e=>c(e.target.value)}),m&&(0,B.jsx)(J,{"aria-label":X(`password`),type:`password`,autoComplete:`new-password`,placeholder:X(h?`passwordOptional`:`passwordRequired`,{length:12}),value:l,onChange:e=>u(e.target.value)}),(0,B.jsx)(G,{type:`submit`,variant:`primary`,loading:d,disabled:!s.trim()||m&&!h&&l.length<12,children:X(n?`createAndJoin`:`createYourAccount`)})]})},aP=({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}=KA();if((0,I.useEffect)(()=>{r.organizations.invitation(e).then(c,e=>u(e instanceof wu?BA(e):X(`invalidLink`)))},[r,e]),l)return(0,B.jsx)(fj,{title:X(`invitation`),description:l,children:(0,B.jsx)(G,{className:`w-full`,onClick:t,children:X(`goToApp`)})});if(!s)return(0,B.jsx)(fj,{title:X(`invitation`),children:(0,B.jsxs)(`div`,{className:`flex items-center justify-center gap-2 text-muted-foreground`,children:[(0,B.jsx)($d,{}),` `,X(`loading`)]})});let m=i.kind===`signed-in`?i.user:void 0,h=m?.email.toLowerCase()===s.email.toLowerCase();if(!s.organization){let r=s.app?.name??``,i=X(`invitesToApp`,{inviter:s.inviter.name,app:r});return(0,B.jsx)(fj,{title:X(`join`,{name:r}),description:i,children:s.hasAccount?m&&h?(0,B.jsx)(G,{variant:`primary`,className:`w-full`,onClick:t,children:X(`goToApp`)}):(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`p`,{className:`mb-3 text-muted-foreground`,children:X(`hasAccount`,{email:s.email})}),m?(0,B.jsx)(G,{className:`w-full`,onClick:()=>void a(),children:X(`signOut`)}):(0,B.jsx)(Sh,{to:n,className:P(mf({variant:`primary`}),`w-full`),children:X(`signInAs`,{email:s.email})})]}):m?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`p`,{className:`mb-3 text-muted-foreground`,children:X(`otherAddress`,{invited:s.email,signedIn:m.email})}),(0,B.jsx)(G,{className:`w-full`,onClick:()=>void a(),children:X(`signOutToAccept`)})]}):(0,B.jsx)(iP,{token:e,preview:s,joins:!1,onDone:t})})}let g=s.organization,_=s.appRoles.map(e=>aj(o?.roles??[],e)),v=ij(s.role).toLowerCase(),y=_.length>0?X(`invitesToWith`,{inviter:s.inviter.name,organization:g.name,role:v,roles:_.join(`, `)}):X(`invitesTo`,{inviter:s.inviter.name,organization:g.name,role:v});return m&&!h?(0,B.jsxs)(fj,{title:X(`join`,{name:g.name}),description:y,children:[(0,B.jsx)(`p`,{className:`mb-3 text-muted-foreground`,children:X(`otherAddress`,{invited:s.email,signedIn:m.email})}),(0,B.jsx)(G,{className:`w-full`,onClick:()=>void a(),children:X(`signOutToAccept`)})]}):(0,B.jsx)(fj,{title:X(`join`,{name:g.name}),description:y,children:m?(0,B.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[f&&(0,B.jsx)(`p`,{role:`alert`,className:`text-body font-medium text-danger-text`,children:f}),(0,B.jsx)(G,{variant:`primary`,className:`w-full`,loading:d,onClick:()=>void p(async()=>{await r.organizations.accept(e),t()}),children:X(`join`,{name:g.name})})]}):s.hasAccount?(0,B.jsx)(Sh,{to:n,className:P(mf({variant:`primary`}),`w-full`),children:X(`signInAsToJoin`,{email:s.email})}):(0,B.jsx)(iP,{token:e,preview:s,joins:!0,onDone:t})})},oP=/^[A-Z][A-Za-z0-9]*$/,sP=e=>typeof e==`function`||typeof e==`object`&&!!e&&`$$typeof`in e,cP=e=>{let t=e.default??{},n=Object.entries(e).filter(e=>e[0]!=="default"&&oP.test(e[0])&&sP(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)}}},lP=class extends Error{name=`UiConflictError`},uP=e=>Object.keys(e).some(e=>e==="default"||/^[A-Z]/.test(e))?cP(e):e,dP=(e,t)=>[...(e.extends??[]).map(uP).flatMap((e,n)=>dP(e,e.name??`${t} extends[${n}]`)),{ui:e,label:t}],fP=(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 lP(`${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},pP=e=>e.length<=1?e[0]:()=>e.map((e,t)=>(0,B.jsx)(e,{},t)),mP=e=>e.length<=1?e[0]:({children:t,...n})=>e.reduceRight((e,t)=>(0,B.jsx)(t,{...n,children:e}),t),hP=(...e)=>{let t=e.flatMap((e,t)=>dP(e,e.name??`UI config ${t+1}`)),n=fP(`The component`,t,e=>e.components),r=fP(`The action handler`,t,e=>e.actions),i=fP(`The field type`,t,e=>e.fields),a=fP(`The drop rule`,t,e=>e.dropRules),o=fP(`The board drop`,t,e=>e.boardDrops),s=fP(`The title rule`,t,e=>e.titles),c=fP(`The marks hook`,t,e=>e.marks),l=pP(t.flatMap(({ui:e})=>e.shell?.actions?[e.shell.actions]:[])),u=pP(t.flatMap(({ui:e})=>e.shell?.rightPanel?[e.shell.rightPanel]:[])),d=t.findLast(({ui:e})=>e.shell?.logo)?.ui.shell?.logo,f=t.findLast(({ui:e})=>e.shell?.bell)?.ui.shell?.bell,p=t.findLast(({ui:e})=>e.presence)?.ui.presence,m=mP(t.flatMap(({ui:e})=>e.beforeSignIn?[e.beforeSignIn]:[])),h=e.at(-1)?.name;return{...h&&{name:h},components:n,actions:r,...Object.keys(i).length>0&&{fields:i},...Object.keys(a).length>0&&{dropRules:a},...Object.keys(o).length>0&&{boardDrops:o},...Object.keys(s).length>0&&{titles:s},...Object.keys(c).length>0&&{marks:c},...(l||u||d||f)&&{shell:{...l&&{actions:l},...u&&{rightPanel:u},...d&&{logo:d},...f&&{bell:f}}},...p&&{presence:p},...m&&{beforeSignIn:m}}},gP=(e,t)=>{let n=hP(e??{}),r=[],i=[];for(let e of t){if(e.kind===`off`){i.push(e);continue}try{hP(...r,e.ui,n),r.push(e.ui)}catch(t){if(!(t instanceof lP))throw t;i.push({kind:`off`,url:e.plugin.url,name:e.plugin.name,reason:t.message})}}return{ui:r.length===0?n:hP(...r,n),off:i}},_P=M(`plugins`),vP=e=>typeof e==`string`&&e.trim()!==``,yP=e=>{if(typeof e!=`object`||!e||Array.isArray(e))return{problem:_P(`notObject`)};let{name:t,version:n,api:r,protobase:i,entry:a,css:o}=e;return vP(t)?Number.isInteger(r)?vP(i)?vP(a)?o!==void 0&&!vP(o)?{problem:_P(`badStylesheet`)}:n!==void 0&&!vP(n)?{problem:_P(`badVersion`)}:{manifest:{name:t,api:r,protobase:i,entry:a,...n!==void 0&&{version:n},...o!==void 0&&{css:o}}}:{problem:_P(`noModule`)}:{problem:_P(`noVersions`)}:{problem:_P(`noApi`)}:{problem:_P(`noName`)}},bP=(0,I.createContext)(null),xP=bP.Provider,SP=()=>{let e=(0,I.useContext)(bP);if(!e)throw Error(`usePlugin is for the components of a plugin the app loaded`);return e},CP=(e,t,n)=>{let r=n=>(0,B.jsx)(xP,{value:e,children:(0,B.jsx)(t,{...n})});return r.displayName=`${e.name}:${n}`,r},wP=(e,t,n)=>({of:n.of,display:CP(e,n.display,`fields.${t}.display`),...n.editor&&{editor:CP(e,n.editor,`fields.${t}.editor`)},...n.cell&&{cell:CP(e,n.cell,`fields.${t}.cell`)}}),TP=(e,t)=>{let n=hP({...cP(t),name:e.name}),r=Object.fromEntries(Object.entries(n.components??{}).map(([t,n])=>[t,CP(e,n,t)])),i=n.fields&&Object.fromEntries(Object.entries(n.fields).map(([t,n])=>[t,wP(e,t,n)])),a=n.shell&&{...n.shell.actions&&{actions:CP(e,n.shell.actions,`shell.actions`)},...n.shell.rightPanel&&{rightPanel:CP(e,n.shell.rightPanel,`shell.rightPanel`)},...n.shell.logo&&{logo:CP(e,n.shell.logo,`shell.logo`)},...n.shell.bell&&{bell:CP(e,n.shell.bell,`shell.bell`)}},o=n.beforeSignIn&&CP(e,n.beforeSignIn,`beforeSignIn`);return{name:e.name,components:r,...n.actions&&{actions:n.actions},...n.dropRules&&{dropRules:n.dropRules},...n.boardDrops&&{boardDrops:n.boardDrops},...n.titles&&{titles:n.titles},...n.marks&&{marks:n.marks},...i&&{fields:i},...a&&{shell:a},...o&&{beforeSignIn:o}}},EP={name:`@protobase/ui`,version:`0.66.3`,description:`The Protobase admin app and the React hooks and components for custom UI.`,license:`Apache-2.0`,repository:{type:`git`,url:`git+https://github.com/PrototeamHQ/protobase.git`,directory:`packages/ui`},homepage:`https://docs.protobase.net`,type:`module`,protobase:{pluginApi:1},sideEffects:[`*.css`,`./dist/app/main.js`],engines:{node:`>=22.12.0`},exports:{".":`./src/index.ts`,"./theme.css":`./src/theme.css`,"./styles.css":`./src/styles.css`},types:`./src/index.ts`,files:[`dist`],scripts:{build:`tsdown && protobase build-shell dist/shell --source-maps dist/shell-source-maps`,prepack:`tsdown && protobase build-shell dist/shell --source-maps dist/shell-source-maps`},publishConfig:{access:`public`,exports:{".":`./dist/index.js`,"./theme.css":`./dist/theme.css`,"./styles.css":`./dist/styles.css`},types:`./dist/index.d.ts`},dependencies:{"@dnd-kit/core":`^6.3.1`,"@dnd-kit/sortable":`^10.0.0`,"@protobase/client":`workspace:*`,"@protobase/layout":`workspace:*`,"@protobase/schema":`workspace:*`,"@sentry/browser":`^11.7.0`,"@tanstack/react-query":`^5.104.1`,"@tanstack/react-table":`^9.2.6`,"altcha-lib":`^2.6.0`,dompurify:`^3.4.17`,fflate:`^0.8.3`,"intl-messageformat":`^12.1.4`,"lucide-react":`^1.52.0`,"maplibre-gl":`^6.14.0`,marked:`^18.1.1`,papaparse:`^5.7.0`,pmtiles:`^4.5.0`,react:`^19.3.0`,"react-dom":`^19.3.0`,"react-map-gl":`^8.1.3`,recharts:`^3.10.1`,tailwindcss:`^4.3.3`,thumbhash:`^0.1.1`,uqr:`^0.1.3`},devDependencies:{"@types/papaparse":`^5.5.2`}},DP=EP.protobase.pluginApi,OP=EP.version,kP={readJson:async e=>{let t=await fetch(e,{cache:`no-cache`,credentials:`same-origin`});return t.ok?{json:await t.json()}:{status:t.status}},addStylesheet:e=>{if([...document.querySelectorAll(`link[rel="stylesheet"]`)].some(t=>t.href===e))return;let t=document.createElement(`link`);t.rel=`stylesheet`,t.href=e,document.head.append(t)},importModule:e=>Ve(()=>import(e),[])},AP={api:DP,version:OP},jP=e=>e instanceof Error?e.message:String(e),MP=async(e,t,n,r=AP)=>{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(_P(`answered`,{status:n.status}));let s=yP(n.json);if(`problem`in s)return a(s.problem);let{manifest:c}=s;o=c.name;let l=Ln(c,r);if(l)return a(l,o);c.css&&t.addStylesheet(new URL(c.css,i).href);let u=await t.importModule(new URL(c.entry,i).href),d={name:o,...c.version&&{version:c.version},url:i,settings:e.settings??{}};return{kind:`loaded`,plugin:d,ui:TP(d,u)}}catch(e){return a(_P(`couldNotLoad`,{reason:jP(e)}),o)}},NP=e=>{let t=new Map;return{load:n=>{let r=JSON.stringify(n),i=t.get(r);if(i)return i;let a=MP(n,e,window.location.href);return t.set(r,a),a}}},PP=(0,I.createContext)(null),FP=({loader:e=kP,children:t})=>{let n=(0,I.useMemo)(()=>NP(e),[e]);return(0,B.jsx)(PP.Provider,{value:n,children:t})},IP=()=>{let e=(0,I.useContext)(PP);if(!e)throw Error(`usePluginSource must be used inside PluginSourceProvider`);return e},LP=1e4,RP=[],zP=(e,t)=>{let n=JSON.stringify(e),[r,i]=(0,I.useState)({key:`[]`,loads:RP,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()},LP);return e.forEach((e,n)=>{t.load(e).then(e=>{o[n]=e,s()})}),()=>{r=!1,clearTimeout(c)}},[n,t]),e.length===0?{loads:RP,settled:!0}:r.key===n?r:{loads:RP,settled:!1}},BP=({children:e})=>{let{state:t,beforeSignIn:n,adoptSession:r}=V(),{path:i,params:a,navigate:o}=jh(),{loads:s,settled:c}=zP(n,IP()),l=(0,I.useMemo)(()=>gP(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)(cv,{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)($d,{}),` `,_P(`loading`)]})},VP=()=>{let e=window.location.href,t=DN(e);if(t)return{kind:`reset-password`,token:t.token};let n=JN(e);if(n)return{kind:`staff-sign-in`,link:n};let r=nP(e);if(r)return{kind:`invitation`,token:r.token};let i=Sd(e);if(i)return{kind:`provider-sign-in`,provider:i};let a=Cd(e);return a?{kind:`sign-in`,providerError:a}:{kind:`sign-in`}},HP=({to:e})=>{let{navigate:t}=jh();return(0,I.useEffect)(()=>t(e,{replace:!0}),[t,e]),null},UP=({workspace:e,children:t})=>{let n=WP(e,t);return(0,B.jsx)(BP,{children:n})},WP=(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}=jh(),{address:p,next:m,open:h,link:g,leave:_}=tE(),[v,y]=(0,I.useState)(VP),[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(wd),(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&&Cd(E)!==void 0;(0,I.useEffect)(()=>{!O&&v.kind===`sign-in`&&v.providerError&&k&&D(wd)},[O,v,k,D]);let A=(0,I.useCallback)(e=>y({kind:`sign-in`,error:e}),[]),j=e=>{D(ON),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)($d,{}),` `,z(`loading`)]});case`error`:return(0,B.jsxs)(`div`,{className:`flex h-full min-h-48 flex-col items-center justify-center gap-3 p-8 text-center`,children:[(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:z(`cannotReach`,{message:n.message})}),(0,B.jsx)(G,{onClick:r,children:z(`tryAgain`)})]});case`needs-admin`:return(0,B.jsx)(xN,{firstAdminUrl:n.firstAdminUrl,onCheckAgain:r})}if(n.kind===`signed-in`&&p)return(0,B.jsx)(HP,{to:m??`/`});if(v.kind===`reset-password`)return(0,B.jsx)(NN,{token:v.token,onDone:()=>void ee(),onRequestNewLink:i?()=>{y({kind:`sign-in`}),f(Qc({step:`forgot-password`}),{replace:!0})}:void 0,onBack:()=>j({kind:`sign-in`})});if(v.kind===`staff-sign-in`)return(0,B.jsx)(QN,{link:v.link,onBack:()=>{D(YN),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)(aP,{token:v.token,onDone:()=>{D(rP),y({kind:`sign-in`})},signIn:g()});if(n.kind===`signed-in`)return t;if(n.kind===`two-factor`)return(0,B.jsx)(tP,{methods:n.methods,onBack:te});if(n.kind===`setup-required`)return(0,B.jsx)(IN,{missing:n.missing},n.missing.join());if(v.kind===`provider-sign-in`)return(0,B.jsx)(jN,{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)(HP,{to:Qc({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)(kN,{back:g(`sign-in`,{replace:!0})});if(ie===`email-code`)return(0,B.jsx)(yN,{email:b,onBack:ae(`sign-in`)});if(ie===`sign-up`||ie===`sign-up-code`||ie===`sign-up-details`)return(0,B.jsx)(GN,{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&&GA(re.providerError,o.length===1?o[0].name:`the provider`),ce=re.error??se;return(0,B.jsx)(VN,{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)},GP=3e4,KP=(e,t=Date.now())=>Math.max(1e3,Ju(e)-t-GP),qP=()=>{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),KP(s))))};return a(),()=>{e=!1,clearTimeout(r)}},[t,n]),n?r:void 0},JP=({children:e})=>(0,B.jsx)(Zd,{locale:V().locale,children:e}),YP=(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)}},XP=e=>{let t=U(),n=Se(),r=(0,I.useContext)(jd),i=(0,I.useMemo)(()=>Object.values(e.resources).filter(t=>t.live&&!Xd(e,t.name)).map(e=>e.name).sort().join(`,`),[e]);(0,I.useEffect)(()=>{if(!i)return;let e=YP(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])},ZP=(e,t,n=!0)=>{let r=U(),i=Nn(t);return E({queryKey:H.record(e,i),enabled:n,queryFn:()=>r.get(e,t)})},QP=(e,t,n=!0)=>{let r=U(),i=Se(),a=Nn(t);return E({queryKey:H.record(e,a),enabled:n,queryFn:()=>r.get(e,t),placeholderData:()=>i.getQueryData(H.recordPreview(e,a))})},$P=M(`forms`),eF=async(e,t)=>{let n=await e.formChallenge(t),r=await _e({challenge:n,deriveKey:De});if(!r)throw Error($P(`checkTooLong`));return{challenge:n,solution:{counter:r.counter,derivedKey:r.derivedKey}}},tF=({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)($d,{}),` `,$P(`loading`)]}):n.error?pl(n.error)&&n.error.status===404?(0,B.jsx)(tf,{title:$P(`notFound`),children:$P(`noForm`)}):(0,B.jsx)(tf,{title:ef(`cannotReach`),children:pl(n.error)?n.error.message:ef(`noAnswer`)}):(0,B.jsx)(nF,{form:n.data})},nF=({form:e})=>{let t=U(),{resource:n,view:r}=e,i=e.title??r.names?.singular??F(r.resource);PM(i);let[a,o]=(0,I.useState)(()=>Lg(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),_=sx(h);if(p)return(0,B.jsx)(fj,{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,Mg(n,{},a),await eF(t,e.name)),m(!0)}catch(e){let t=ax(e);c(t),Object.keys(t).length>0?g(e=>e+1):u(e)}finally{f(!1)}};return(0,B.jsx)(fj,{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)(Yh,{name:e,label:o,help:i?.help,required:Ng(t),error:c&&ix(t,o,c),children:(0,B.jsx)(Ov,{field:t,hints:i,value:a[e]??(t.type!==`boolean`&&``),stored:void 0,placeholder:Rg(t)?$P(`setByDatabase`):Ig(t),invalid:!!c,onChange:t=>v(e,t)})},e)}),l!==void 0&&(0,B.jsx)(Bg,{title:$P(`notSent`),error:l}),(0,B.jsx)(G,{variant:`primary`,type:`submit`,loading:d,className:`min-h-10`,children:$P(`send`)})]})})},rF=()=>{let{path:e}=jh();return(0,I.useMemo)(()=>xn(e),[e])},Z=M(`calls`),iF=(e,t)=>{e.srcObject=new MediaStream([t]);let n=()=>{t.readyState===`live`&&e.play().catch(e=>{if(!(e instanceof DOMException&&(e.name===`AbortError`||e.name===`NotAllowedError`)))throw e})};return e.addEventListener(`pause`,n),()=>e.removeEventListener(`pause`,n)},aF=({track:e,...t})=>{let n=(0,I.useCallback)(t=>t?iF(t,e):void 0,[e]);return(0,B.jsx)(`video`,{ref:n,autoPlay:!0,playsInline:!0,muted:!0,...t})},oF=({track:e})=>{let t=(0,I.useCallback)(t=>t?iF(t,e):void 0,[e]);return(0,B.jsx)(`audio`,{ref:t,autoPlay:!0})},sF=e=>P(`size-10 rounded-full`,!e&&`bg-danger-soft text-danger-text`),cF=({name:e,member:t,camera:n,microphoneOn:r,cameraOn:i,microphone:a,cameraAvailable:o,notices:s,onMicrophone:c,onCamera:l,onJoin:u,cancel:d,joinLabel:f=Z(`joinCall`)})=>(0,B.jsxs)(`section`,{"aria-label":Z(`preview`),className:`flex size-full min-h-0 flex-col items-center justify-center gap-3 bg-background p-4`,children:[(0,B.jsx)(`figure`,{className:`relative flex aspect-video w-full max-w-md items-center justify-center overflow-hidden rounded-lg bg-neutral-900`,children:n&&i?(0,B.jsx)(aF,{track:n,"aria-label":Z(`preview`),className:`size-full -scale-x-100 object-cover`}):(0,B.jsx)(If,{initials:I_(e),hue:F_(t),size:`md`,className:`size-16 text-xl ring-0`})}),s.length>0&&(0,B.jsx)(`div`,{role:`status`,className:`flex w-full max-w-md flex-col gap-1`,children:s.map(e=>(0,B.jsx)(`p`,{className:`rounded-md bg-warning-soft px-3 py-1.5 text-xs text-foreground`,children:e},e))}),(0,B.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,B.jsx)(G,{size:`icon`,"aria-label":Z(`microphone`),"aria-pressed":r,disabled:!a,className:sF(r),onClick:c,children:r?(0,B.jsx)(yo,{className:`size-4`}):(0,B.jsx)(_o,{className:`size-4`})}),(0,B.jsx)(G,{size:`icon`,"aria-label":Z(`camera`),"aria-pressed":i,disabled:!o,className:sF(i),onClick:l,children:i?(0,B.jsx)(lc,{className:`size-4`}):(0,B.jsx)(sc,{className:`size-4`})}),(0,B.jsx)(G,{variant:`primary`,className:`h-10 rounded-full px-5`,onClick:u,children:f}),(0,B.jsx)(Sh,{to:d,className:`px-2 text-sm text-muted-foreground hover:text-foreground`,children:Z(`leave`)})]})]}),lF=()=>{let[e,t]=(0,I.useState)(!1);return{run:(0,I.useCallback)(e=>{t(!1),(async()=>{let{GuestRefused:n}=await Ve(async()=>{let{GuestRefused:e}=await import(`./calls-Dr-DRqHd.js`);return{GuestRefused:e}},[]);await e().catch(e=>{if(!(e instanceof n))throw e;t(!0)})})()},[]),refused:e}},uF={all:[`camera`,`microphone`,`screen`,`screen-audio`],camera:[`camera`,`microphone`],microphone:[`microphone`]},dF={call:void 0,hour:36e5},fF=({name:e,children:t})=>(0,B.jsxs)(`li`,{className:`flex items-center justify-between gap-2 py-1.5`,children:[(0,B.jsx)(`span`,{className:`min-w-0 truncate text-sm text-foreground`,children:e}),(0,B.jsx)(`span`,{className:`flex shrink-0 gap-1.5`,children:t})]}),pF=({lobby:e,inCall:t,guests:n,linkOf:r,open:i,onClose:a})=>{let[o,s]=(0,I.useState)(`camera`),[c,l]=(0,I.useState)(`call`),[u,d]=(0,I.useState)(),[f,p]=(0,I.useState)(!1),{run:m,refused:h}=lF(),g=()=>m(async()=>{let e=dF[c],{link:t,token:i}=await n.link({publish:uF[o],...e!==void 0&&{expiresAt:new Date(Date.now()+e)}});d({id:t.id,url:r(i)})}),_=e=>void navigator.clipboard.writeText(e).then(()=>{p(!0),setTimeout(()=>p(!1),2e3)});return(0,B.jsx)(Ef,{title:Z(`guests`),description:Z(`addressesVisible`),open:i,onClose:a,actions:(0,B.jsx)(G,{onClick:a,children:Z(`close`)}),children:(0,B.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[h&&(0,B.jsx)(`p`,{role:`alert`,className:`rounded-md bg-warning-soft px-3 py-1.5 text-xs text-foreground`,children:Z(`guestRefused`)}),e.guests.length>0&&(0,B.jsxs)(`section`,{"aria-label":Z(`inLobby`),children:[(0,B.jsx)(`h3`,{className:`text-xs font-medium text-muted-foreground`,children:Z(`inLobby`)}),(0,B.jsx)(`ul`,{children:e.guests.map(({guest:e,name:t})=>(0,B.jsxs)(fF,{name:t,children:[(0,B.jsx)(G,{size:`sm`,variant:`primary`,onClick:()=>m(()=>n.admit(e)),children:Z(`admit`)}),(0,B.jsx)(G,{size:`sm`,onClick:()=>m(()=>n.deny(e)),children:Z(`deny`)})]},e))})]}),t.length>0&&(0,B.jsxs)(`section`,{"aria-label":Z(`guestsInCall`),children:[(0,B.jsx)(`h3`,{className:`text-xs font-medium text-muted-foreground`,children:Z(`guestsInCall`)}),(0,B.jsx)(`ul`,{children:t.map(({guest:e,name:t})=>(0,B.jsx)(fF,{name:t,children:(0,B.jsx)(G,{size:`sm`,variant:`danger`,onClick:()=>m(()=>n.remove(e)),children:Z(`remove`)})},e))})]}),(0,B.jsxs)(`section`,{"aria-label":Z(`guestLinks`),className:`flex flex-col gap-2`,children:[(0,B.jsx)(`h3`,{className:`text-xs font-medium text-muted-foreground`,children:Z(`guestLinks`)}),e.links.length===0&&(0,B.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:Z(`noLinks`)}),(0,B.jsx)(`ul`,{children:e.links.map(e=>(0,B.jsxs)(`li`,{className:`flex flex-col gap-1.5 py-1.5`,children:[u?.id===e.id&&(0,B.jsx)(J,{readOnly:!0,value:u.url,"aria-label":Z(`copyLink`),onFocus:e=>e.currentTarget.select(),trailing:(0,B.jsx)(`button`,{type:`button`,"aria-label":Z(f?`copied`:`copyLink`),onClick:()=>_(u.url),className:`inline-flex size-8 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-muted pointer-coarse:size-11`,children:f?(0,B.jsx)(Si,{className:`size-4 text-success`}):(0,B.jsx)(Ji,{className:`size-4`})})}),(0,B.jsxs)(`span`,{className:`flex items-center justify-between gap-2 text-xs text-muted-foreground`,children:[e.expires_at?Z(`linkUntil`,{until:new Date(e.expires_at).toLocaleString()}):Z(`linkUntilEnd`),(0,B.jsx)(G,{size:`sm`,onClick:()=>m(()=>n.revoke(e.id)),children:Z(`revoke`)})]})]},e.id))}),(0,B.jsxs)(`div`,{className:`flex flex-col items-start gap-2`,children:[(0,B.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2 text-xs text-muted-foreground`,children:[Z(`guestsMaySend`),(0,B.jsx)(Re,{label:Z(`guestsMaySend`),value:o,onChange:s,options:[{value:`all`,label:Z(`sendAll`)},{value:`camera`,label:Z(`sendCamera`)},{value:`microphone`,label:Z(`sendMicrophone`)}]})]}),(0,B.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2 text-xs text-muted-foreground`,children:[Z(`linkLasts`),(0,B.jsx)(Re,{label:Z(`linkLasts`),value:c,onChange:l,options:[{value:`call`,label:Z(`linkUntilEnd`)},{value:`hour`,label:Z(`forAnHour`)}]})]}),(0,B.jsx)(G,{variant:`primary`,onClick:g,children:Z(`newLink`)})]})]})]})})},mF=({waiting:e,guests:t})=>{let{run:n,refused:r}=lF(),i=e[0];return i?(0,B.jsxs)(`div`,{role:`status`,className:`flex shrink-0 flex-wrap items-center gap-2 rounded-md bg-primary-soft px-3 py-1.5 text-xs text-foreground`,children:[(0,B.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:r?Z(`guestRefused`):Z(`waitingGuest`,{name:i.name})}),(0,B.jsx)(G,{size:`sm`,variant:`primary`,onClick:()=>n(()=>t.admit(i.guest)),children:Z(`admit`)}),(0,B.jsx)(G,{size:`sm`,onClick:()=>n(()=>t.deny(i.guest)),children:Z(`deny`)})]}):null},hF={ended:`ended`,removed:`removed`,full:`full`,refused:`refused`,unavailable:`unavailable`,denied:`denied`},gF=({reason:e,onJoinAgain:t})=>(0,B.jsxs)(`section`,{role:`status`,className:`flex size-full min-h-0 flex-col items-center justify-center gap-3 bg-background p-4 text-center`,children:[(0,B.jsx)(`p`,{className:`text-sm text-foreground`,children:Z(e===`rejoin`?`ended`:hF[e])}),t&&e!==`removed`&&e!==`refused`&&e!==`denied`&&(0,B.jsx)(G,{onClick:t,children:Z(`callAgain`)})]}),_F=(e,t)=>t<640?e<=2?1:2:Math.min(4,Math.ceil(Math.sqrt(e))),vF=({people:e,sharers:t,width:n})=>t[0]===void 0?e<=1?{kind:`alone`}:{kind:`grid`,columns:_F(e,n)}:{kind:`share`,sharer:t[0]},yF=({roundTripMs:e,lostRatio:t})=>(e??0)>400||(t??0)>.05?`poor`:`good`,bF=(e,t,n)=>e===`failed`||e!==`connected`&&n-t>=15e3,xF=(e,t=.05)=>{let n;for(let[r,i]of e)i>=t&&(!n||i>n[1])&&(n=[r,i]);return n?.[0]},SF=(e,t)=>e.find(e=>e.source===t&&e.track),CF=({members:e,self:t,tracks:n,own:r,nameOf:i,speaker:a,connections:o,seen:s,now:c})=>(e.some(e=>e.member===t)?e:[{member:t,joined_at:``},...e]).map(({member:e,name:l})=>{let u={member:e,name:e.startsWith(`guest:`)?Z(`guestName`,{name:l??``}):l??i(e),...a===e&&{speaking:!0}};if(e===t)return{...u,self:!0,...r.camera&&{camera:r.camera},...r.microphone&&{microphone:r.microphone},...r.screen&&{screen:r.screen},microphoneOff:!r.microphone||!r.microphoneOn,cameraOff:!r.camera||!r.cameraOn};let d=n.filter(t=>t.member===e),[f,p,m,h]=[`camera`,`microphone`,`screen`,`screen-audio`].map(e=>SF(d,e)),g=o.find(t=>t.member===e),_=bF(g?.state,s.get(e)??c,c)?`failed`:g?.state===`connected`?yF(g):void 0;return{...u,...f&&{camera:f.track},...p&&{microphone:p.track},...m&&{screen:m.track},...h&&{screenAudio:h.track},microphoneOff:!p||p.muted,cameraOff:!f||f.muted,..._&&{connection:_}}}),wF=e=>P(`size-10 rounded-full`,!e&&`bg-danger-soft text-danger-text`),TF=({microphoneOn:e,cameraOn:t,sharing:n,onMicrophone:r,onCamera:i,onShare:a,guests:o,leave:s})=>(0,B.jsxs)(`div`,{role:`toolbar`,"aria-label":Z(`joinCall`),className:`flex shrink-0 flex-wrap items-center justify-center gap-2 py-2`,children:[(0,B.jsx)(G,{size:`icon`,"aria-label":Z(`microphone`),"aria-pressed":e,title:Z(`microphone`),className:wF(e),onClick:r,children:e?(0,B.jsx)(yo,{className:`size-4`}):(0,B.jsx)(_o,{className:`size-4`})}),(0,B.jsx)(G,{size:`icon`,"aria-label":Z(`camera`),"aria-pressed":t,title:Z(`camera`),className:wF(t),onClick:i,children:t?(0,B.jsx)(lc,{className:`size-4`}):(0,B.jsx)(sc,{className:`size-4`})}),a&&(0,B.jsx)(G,{size:`icon`,"aria-label":Z(n?`stopSharing`:`shareScreen`),"aria-pressed":!!n,title:Z(n?`stopSharing`:`shareScreen`),className:`size-10 rounded-full`,onClick:a,children:n?(0,B.jsx)(To,{className:`size-4`}):(0,B.jsx)(Co,{className:`size-4`})}),o&&(0,B.jsxs)(G,{size:`icon`,"aria-label":Z(`guests`),title:Z(`guests`),className:`relative size-10 rounded-full`,onClick:o.onOpen,children:[(0,B.jsx)($s,{className:`size-4`}),(0,B.jsx)(Yx,{count:o.waiting,className:`absolute -top-1 -right-1`})]}),(0,B.jsxs)(Sh,{to:s,className:P(mf({variant:`danger`}),`h-10 rounded-full px-4`),children:[(0,B.jsx)(Vo,{className:`size-4`}),Z(`leave`)]})]}),EF=({person:e,screen:t=!1,className:n})=>{let r=t?e.screen:e.cameraOff?void 0:e.camera,i=t?e.self?Z(`youAreSharing`):Z(`sharing`,{name:e.name}):e.self?`${e.name} (${Z(`you`)})`:e.name;return(0,B.jsxs)(`figure`,{"data-member":e.member,"data-speaking":e.speaking?`true`:void 0,"aria-label":i,className:P(`relative flex min-h-0 min-w-0 items-center justify-center overflow-hidden rounded-lg bg-neutral-900 ring-offset-2 ring-offset-background`,e.speaking&&!t&&`ring-2 ring-success`,n),children:[r?(0,B.jsx)(aF,{track:r,className:P(`size-full`,t?`object-contain`:`object-cover`,e.self&&!t&&`-scale-x-100`)}):(0,B.jsx)(If,{initials:I_(e.name),hue:F_(e.member),size:`md`,className:`size-16 text-xl ring-0`}),e.connection===`failed`&&!e.self&&(0,B.jsx)(`p`,{role:`status`,className:`absolute inset-x-1 top-1 truncate rounded bg-black/70 px-2 py-1 text-center text-xs text-white`,children:Z(`cannotConnect`,{name:e.name})}),(0,B.jsxs)(`figcaption`,{className:`absolute bottom-1.5 left-1.5 flex max-w-[calc(100%-0.75rem)] items-center gap-1 rounded bg-black/60 px-1.5 py-0.5 text-xs text-white`,children:[!t&&e.microphoneOff&&(0,B.jsx)(_o,{role:`img`,"aria-label":Z(`muted`),className:`size-3 shrink-0`}),!t&&e.connection===`poor`&&(0,B.jsx)(hc,{role:`img`,"aria-label":Z(`poorConnection`),className:`size-3 shrink-0 text-warning`}),(0,B.jsx)(`span`,{className:`truncate`,children:i})]})]})},DF=()=>{let[e,t]=(0,I.useState)(0);return{ref:(0,I.useCallback)(e=>{if(!e)return;t(e.clientWidth);let n=new ResizeObserver(([e])=>t(e.contentRect.width));return n.observe(e),()=>n.disconnect()},[]),width:e}},OF=4,kF=({people:e,columns:t})=>(0,B.jsx)(`div`,{className:`grid size-full min-h-0 gap-2`,style:{gridTemplateColumns:`repeat(${t}, minmax(0, 1fr))`,gridTemplateRows:`repeat(${Math.ceil(e.length/t)}, minmax(0, 1fr))`},children:e.map(e=>(0,B.jsx)(EF,{person:e},e.member))}),AF=({people:e,sharer:t,narrow:n})=>{let r=e.slice(0,OF),i=e.length-r.length;return(0,B.jsxs)(`div`,{className:P(`flex size-full min-h-0 gap-2`,n?`flex-col`:`flex-row`),children:[(0,B.jsx)(EF,{person:t,screen:!0,className:`min-h-0 flex-1`}),(0,B.jsxs)(`div`,{className:P(`flex shrink-0 gap-2`,n?`h-20 flex-row`:`w-40 flex-col`),children:[r.map(e=>(0,B.jsx)(EF,{person:e,className:n?`aspect-video h-full`:`aspect-video w-full`},e.member)),i>0&&(0,B.jsxs)(`p`,{className:`flex items-center justify-center rounded-lg bg-muted px-2 text-xs text-muted-foreground`,children:[`+`,i]})]})]})},jF=({layout:e,people:t,narrow:n})=>e.kind===`share`?(0,B.jsx)(AF,{people:t,sharer:t.find(t=>t.member===e.sharer),narrow:n}):e.kind===`grid`?(0,B.jsx)(kF,{people:t,columns:e.columns}):(0,B.jsxs)(`div`,{className:`relative size-full min-h-0`,children:[(0,B.jsx)(EF,{person:t[0],className:`size-full`}),(0,B.jsx)(`p`,{className:`absolute inset-x-0 top-3 text-center text-sm text-white drop-shadow`,children:Z(`alone`)})]}),MF=({people:e,state:t,notices:n=[],controls:r,aside:i,children:a,className:o})=>{let{ref:s,width:c}=DF(),l=c>0&&c<640,u=vF({people:e.length,sharers:e.filter(e=>e.screen).map(e=>e.member),width:c}),d=[...t===`resuming`?[Z(`reconnecting`)]:[],...n];return(0,B.jsxs)(`section`,{ref:s,"aria-label":Z(`joinCall`),"data-layout":u.kind,className:P(`flex size-full min-h-0 flex-col gap-2 bg-background p-2`,o),children:[d.length>0&&(0,B.jsx)(`div`,{role:`status`,className:`flex shrink-0 flex-col gap-1`,children:d.map(e=>(0,B.jsxs)(`p`,{className:`flex items-center gap-2 rounded-md bg-warning-soft px-3 py-1.5 text-xs text-foreground`,children:[e===Z(`reconnecting`)&&(0,B.jsx)($d,{className:`size-3`}),e]},e))}),i,(0,B.jsx)(`div`,{className:`min-h-0 flex-1`,children:t===`joining`?(0,B.jsxs)(`p`,{role:`status`,className:`flex size-full items-center justify-center gap-2 text-muted-foreground`,children:[(0,B.jsx)($d,{className:`size-4`}),Z(`connecting`)]}):(0,B.jsx)(jF,{layout:u,people:e,narrow:l})}),(0,B.jsx)(TF,{...r}),e.filter(e=>!e.self).flatMap(e=>[[`microphone`,e.microphone],[`screen-audio`,e.screenAudio]].map(([t,n])=>n&&{key:`${e.member} ${t}`,track:n})).filter(e=>e!==void 0).map(({key:e,track:t})=>(0,B.jsx)(oF,{track:t},e)),a]})},NF=({leave:e})=>(0,B.jsxs)(`section`,{role:`status`,className:`flex size-full min-h-0 flex-col items-center justify-center gap-3 bg-background p-4 text-center`,children:[(0,B.jsxs)(`p`,{className:`flex items-center gap-2 text-sm text-foreground`,children:[(0,B.jsx)($d,{className:`size-4`}),Z(`waiting`)]}),(0,B.jsx)(Sh,{to:e,className:`px-2 text-sm text-muted-foreground hover:text-foreground`,children:Z(`leave`)})]}),PF=`/-/call-guest`,FF=(e,t)=>`${e}${PF}#${t}`,IF=(e,t)=>{let n=t.replace(/^#/,``);return e===`/-/call-guest`&&n?{token:n}:void 0},LF=()=>{let{path:e}=jh();return(0,I.useMemo)(()=>IF(e,globalThis.location?.hash??``),[e])},RF=200,zF=1e3,BF=(e,t)=>{e.getFloatTimeDomainData(t);let n=0;for(let e of t)n+=e*e;return Math.min(1,Math.sqrt(n/t.length)*4)},VF=e=>{let[t,n]=(0,I.useState)(),r=[...e].map(([e,t])=>`${e}:${t.id}`).join(`,`);return(0,I.useEffect)(()=>{if(e.size===0||typeof AudioContext>`u`)return;let t=new AudioContext,r=new Map([...e].map(([e,n])=>{let r=t.createAnalyser();return r.fftSize=512,t.createMediaStreamSource(new MediaStream([n])).connect(r),[e,r]})),i=new Float32Array(512),a,o=setInterval(()=>{let e=xF(new Map([...r].map(([e,t])=>[e,BF(t,i)])));e&&(a={member:e,at:Date.now()}),n(a&&Date.now()-a.at<zF?a.member:void 0)},RF);return()=>{clearInterval(o),t.close()}},[r]),t},HF=new Set([`NotAllowedError`,`SecurityError`]),UF=new Set([`NotFoundError`,`NotReadableError`,`OverconstrainedError`]),WF=async(e,t)=>{try{return{track:(await e.getUserMedia({[t]:!0})).getTracks()[0],blocked:!1}}catch(e){if(!(e instanceof DOMException))throw e;if(HF.has(e.name))return{blocked:!0};if(UF.has(e.name))return{blocked:!1};throw e}},GF=async(e=navigator.mediaDevices)=>{try{let t=await e.getUserMedia({audio:!0,video:!0});return{microphone:t.getAudioTracks()[0],camera:t.getVideoTracks()[0],blocked:{microphone:!1,camera:!1},none:!1}}catch(e){if(!(e instanceof DOMException)||!(HF.has(e.name)||UF.has(e.name)))throw e}let[t,n]=[await WF(e,`audio`),await WF(e,`video`)];return{...t.track&&{microphone:t.track},...n.track&&{camera:n.track},blocked:{microphone:t.blocked,camera:n.blocked},none:!t.track&&!n.track&&!t.blocked&&!n.blocked}},KF=class extends Error{reason;constructor(e){super(`Not let into the call: ${e}`),this.reason=e,this.name=`NotLetIn`}},qF=1e3,JF=(e,t)=>new Promise(n=>{let r=setTimeout(n,e);t.addEventListener(`abort`,()=>(clearTimeout(r),n()),{once:!0})}),YF=async(e,t,n,r)=>{let{LobbyRefused:i}=await Ve(async()=>{let{LobbyRefused:e}=await import(`./calls-Dr-DRqHd.js`);return{LobbyRefused:e}},[]),a=e=>e instanceof i?new KF(e.status===404?`refused`:e.status===429?`unavailable`:`ended`):e,{token:o}=await e.enter(t,n).catch(e=>Promise.reject(a(e)));for(;!r.aborted;){let t=await e.wait(o).catch(e=>Promise.reject(a(e)));if(t.state===`admitted`)return o;if(t.state===`denied`)throw new KF(`denied`);if(t.state===`ended`)throw new KF(`ended`);await JF(qF,r)}throw await e.leave(o),new KF(`ended`)},XF=2e3,ZF=e=>{for(let t of e)t?.stop()},QF=(e,{admission:t}={})=>{let[n,r]=(0,I.useState)({kind:`check`}),[i,a]=(0,I.useState)(),o=(0,I.useRef)(new AbortController),[s,c]=(0,I.useState)(),[l,u]=(0,I.useState)(!0),[d,f]=(0,I.useState)(!0),[p,m]=(0,I.useState)([]),[h,g]=(0,I.useState)([]),[_,v]=(0,I.useState)([]),[y,b]=(0,I.useState)(),[x,S]=(0,I.useState)(!1),C=(0,I.useRef)(void 0),w=(0,I.useRef)(!1),T=(0,I.useRef)([]),E=(0,I.useRef)(new Map),D=(0,I.useRef)(Promise.resolve(void 0));(0,I.useEffect)(()=>{let e=!1;return w.current=!1,D.current=GF().then(t=>{if(e){ZF([t.microphone,t.camera]);return}return T.current.push(t.microphone,t.camera),c(t),t}),()=>{e=!0,w.current=!0,o.current.abort(),C.current?.leave(),C.current=void 0,ZF(T.current),T.current=[]}},[]),(0,I.useEffect)(()=>{for(let{member:e}of h)E.current.has(e)||E.current.set(e,Date.now())},[h]),(0,I.useEffect)(()=>{if(n.kind!==`in`)return;let e=setInterval(()=>void C.current?.connections().then(v),XF);return()=>clearInterval(e)},[n.kind]);let O=async()=>{if(!t)return{};r({kind:`waiting`}),o.current=new AbortController;let e=await t(o.current.signal).then(e=>e,e=>{if(!(e instanceof KF))throw e;r({kind:`left`,reason:e.reason})});return e===void 0?void 0:{guest:e}},k=(0,I.useCallback)(async()=>{let t=await O();if(!t||w.current)return;r({kind:`joining`});let{joinCall:n,PublishRefused:i}=await Ve(async()=>{let{joinCall:e,PublishRefused:t}=await import(`./calls-Dr-DRqHd.js`);return{joinCall:e,PublishRefused:t}},[]),o=await n({url:e,...t,onLobby:a,onTracks:m,onMembers:g,onState:e=>{(e.state===`joined`||e.state===`resuming`)&&r({kind:`in`,resuming:e.state===`resuming`}),e.state===`left`&&r({kind:`left`,reason:e.reason})}}).then(e=>e,()=>void 0);if(!o)return;if(w.current)return o.leave();C.current=o;let s=await D.current,c={...s?.microphone&&{microphone:s.microphone},...s?.camera&&{camera:s.camera}};await o.publish(c).then(()=>{c.microphone&&o.mute(`microphone`,!l),c.camera&&o.mute(`camera`,!d)},e=>{if(!(e instanceof i))throw e;S(!0)})},[e,t,l,d]),A=(0,I.useCallback)(()=>{let e=!l;u(e),s?.microphone&&(s.microphone.enabled=e),C.current?.mute(`microphone`,!e)},[l,s]),j=(0,I.useCallback)(()=>{let e=!d;f(e),s?.camera&&(s.camera.enabled=e),C.current?.mute(`camera`,!e)},[d,s]),ee=(0,I.useCallback)(async e=>{b(void 0),ZF([e.video,e.audio]),await C.current?.unpublish(`screen`),e.audio&&await C.current?.unpublish(`screen-audio`)},[]),te=(0,I.useCallback)(async()=>{if(y)return ee(y);let e;try{e=await navigator.mediaDevices.getDisplayMedia({video:!0,audio:!0})}catch(e){if(e instanceof DOMException&&e.name===`NotAllowedError`)return;throw e}let t={video:e.getVideoTracks()[0],...e.getAudioTracks()[0]&&{audio:e.getAudioTracks()[0]}};T.current.push(t.video,t.audio),t.video.addEventListener(`ended`,()=>void ee(t)),await C.current?.publish({screen:t.video,...t.audio&&{"screen-audio":t.audio}}),b(t)},[y,ee]),ne=typeof navigator<`u`&&typeof navigator.mediaDevices?.getDisplayMedia==`function`;return{phase:n,devices:s,microphoneOn:l,cameraOn:d,tracks:p,members:h,connections:_,screen:y,refusedSending:x,seen:E.current,self:C.current?.participant,lobby:i,guests:C.current?.guests,join:k,toggleMicrophone:A,toggleCamera:j,...ne&&{toggleScreen:te}}},$F=(e,t)=>[...e?.blocked.microphone?[Z(`noMicrophone`)]:[],...e?.blocked.camera?[Z(`noCamera`)]:[],...e?.none?[Z(`noDevices`)]:[],...t?[Z(`refused`)]:[]],eI=({url:e,leave:t,nameOf:n=e=>e,admission:r,name:i,className:a})=>{let o=QF(e,{...r&&{admission:r}}),[s,c]=(0,I.useState)(!1),{basePath:l}=jh(),u=Od(),d=u?.state.kind===`signed-in`?u.state.user:void 0,f=o.self??d?.id??``,[p]=(0,I.useState)(()=>Date.now()),{devices:m,phase:h}=o,g={...m?.microphone&&{microphone:m.microphone},...m?.camera&&{camera:m.camera},...o.screen&&{screen:o.screen.video},microphoneOn:o.microphoneOn,cameraOn:o.cameraOn},_=new Map([...m?.microphone&&o.microphoneOn?[[f,m.microphone]]:[],...o.tracks.filter(e=>e.source===`microphone`&&e.track&&!e.muted).map(e=>[e.member,e.track])]),v=VF(h.kind===`in`?_:new Map),y=$F(m,o.refusedSending);if(h.kind===`left`)return(0,B.jsx)(gF,{reason:h.reason,onJoinAgain:()=>void o.join()});if(h.kind===`waiting`)return(0,B.jsx)(NF,{leave:t});if(h.kind===`check`)return(0,B.jsx)(cF,{name:i??d?.name??Z(`you`),...r&&{joinLabel:Z(`askToJoin`)},member:f,...m?.camera&&{camera:m.camera},microphoneOn:o.microphoneOn,cameraOn:o.cameraOn,microphone:!!m?.microphone,cameraAvailable:!!m?.camera,notices:y,onMicrophone:o.toggleMicrophone,onCamera:o.toggleCamera,onJoin:()=>void o.join(),cancel:t});let{lobby:b,guests:x}=o,S=o.members.filter(e=>e.member.startsWith(`guest:`)).map(e=>({guest:e.member.slice(6),name:e.name??``})),C=CF({members:o.members,self:f,tracks:o.tracks,own:g,nameOf:n,...v&&{speaker:v},connections:o.connections,seen:o.seen,now:Math.max(p,Date.now())});return(0,B.jsx)(MF,{...a&&{className:a},people:C,state:h.kind===`joining`?`joining`:h.resuming?`resuming`:`joined`,notices:y,...b&&x&&{aside:(0,B.jsx)(mF,{waiting:b.guests,guests:x})},controls:{microphoneOn:o.microphoneOn&&!!m?.microphone,cameraOn:o.cameraOn&&!!m?.camera,sharing:!!o.screen,onMicrophone:o.toggleMicrophone,onCamera:o.toggleCamera,...o.toggleScreen&&{onShare:()=>void o.toggleScreen()},...b&&{guests:{waiting:b.guests.length,onOpen:()=>c(!0)}},leave:t},children:b&&x&&(0,B.jsx)(pF,{lobby:b,inCall:S,guests:x,linkOf:e=>FF(`${window.location.origin}${l}`,e),open:s,onClose:()=>c(!1)})})},tI=({link:e,systemPath:t,base:n})=>{let[r,i]=(0,I.useState)(``),[a,o]=(0,I.useState)(),[s,c]=(0,I.useState)(!1),l=(0,I.useCallback)(async n=>{let{guestLobby:r}=await Ve(async()=>{let{guestLobby:e}=await import(`./calls-Dr-DRqHd.js`);return{guestLobby:e}},[]);return YF(r({systemPath:t}),e,a,n)},[t,e,a]),u=e=>{e.preventDefault(),r.trim()&&o(r.trim())},d=FF(n,e);return s?(0,B.jsx)(`p`,{role:`status`,className:`flex min-h-[100dvh] items-center justify-center bg-background p-4 text-sm text-foreground`,children:Z(`youLeft`)}):a===void 0?(0,B.jsx)(`main`,{className:`flex min-h-[100dvh] items-center justify-center bg-background p-4`,children:(0,B.jsxs)(`form`,{onSubmit:u,className:`flex w-full max-w-sm flex-col gap-3`,children:[(0,B.jsx)(`p`,{className:`text-sm text-foreground`,children:Z(`guestIntro`)}),(0,B.jsxs)(`label`,{className:`flex flex-col gap-1 text-sm text-foreground`,children:[Z(`yourName`),(0,B.jsx)(J,{autoFocus:!0,autoComplete:`name`,maxLength:60,value:r,onChange:e=>i(e.target.value)})]}),(0,B.jsx)(G,{type:`submit`,variant:`primary`,disabled:!r.trim(),children:Z(`continue`)})]})}):(0,B.jsx)(`main`,{className:`h-[100dvh]`,children:(0,B.jsx)(eI,{url:Dr(t,`socket`),admission:l,name:a,nameOf:()=>Z(`someone`),leave:{href:d,onFollow:()=>c(!0)}})})},nI=[`light`,`dark`,`system`],rI=`protobase:theme`,iI=`(prefers-color-scheme: dark)`,aI=e=>nI.includes(e),oI=e=>Ie(()=>{let t=e.getItem(rI);return aI(t)?t:`system`},`system`),sI=(e,t)=>Ie(()=>t===`system`?e.removeItem(rI):e.setItem(rI,t),void 0),cI=(e,t)=>e===`system`?t?`dark`:`light`:e,lI=(0,I.createContext)(void 0),uI=({children:e})=>{let[t,n]=(0,I.useState)(()=>oI(localStorage)),r=cI(t,hf(iI));return(0,I.useEffect)(()=>{document.documentElement.dataset.theme=r},[r]),(0,I.useEffect)(()=>{let e=e=>{(e.key===`protobase:theme`||e.key===null)&&n(oI(localStorage))};return window.addEventListener(`storage`,e),()=>window.removeEventListener(`storage`,e)},[]),(0,B.jsx)(lI.Provider,{value:{preference:t,theme:r,choose:e=>{sI(localStorage,e),n(e)}},children:e})},dI=()=>{let e=(0,I.useContext)(lI);if(!e)throw Error(`useTheme needs a ThemeProvider above it`);return e},fI=M(`chat`),pI=({children:e,className:t})=>(0,B.jsx)(`p`,{className:P(`text-xs text-muted-foreground`,t),children:e}),mI=({time:e})=>{let t=Date.parse(e);return(0,B.jsx)(`time`,{dateTime:e,title:dp(t),className:`text-xs text-muted-foreground`,children:vp(t)})},hI=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)(If,{initials:I_(s)||`?`,hue:F_(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)(mI,{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)(pI,{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)(pI,{className:e.from===`user`?`text-right`:void 0,children:n})]}):r},gI=e=>e.scrollHeight-e.scrollTop-e.clientHeight<=24,_I=(e,t)=>{if(t.followKey!==e.followKey)return t.scrollHeight;if(e.first===void 0&&t.first!==void 0&&t.newLineTop!==void 0)return Math.max(0,t.scrollTop+t.newLineTop-16);if(e.first!==void 0&&t.first!==e.first&&e.anchor&&t.anchorTop!==void 0)return t.scrollTop+t.anchorTop-e.anchor.top;if(e.atEnd)return t.scrollHeight},vI=(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:gI(e),first:t.firstElementChild??void 0,followKey:n,...a}},yI=(e,t)=>{let n=(0,I.useRef)({onReadToEnd:e,atEnd:t});(0,I.useLayoutEffect)(()=>{n.current={onReadToEnd:e,atEnd:t}});let r=(0,I.useCallback)(()=>{document.visibilityState===`visible`&&n.current.onReadToEnd?.()},[]);return(0,I.useEffect)(()=>{let e=()=>{n.current.atEnd()&&r()};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[r]),r},bI=e=>e.querySelector(`[data-chat-divider][data-tone="new"]`),xI=({children:e,empty:t,length:n,onLoadEarlier:r,loadingEarlier:i,followKey:a,onReadToEnd:o})=>{let s=(0,I.useRef)(null),c=(0,I.useRef)(null),l=(0,I.useRef)({atEnd:!0,first:void 0,followKey:a}),u=()=>{s.current&&c.current&&(l.current=vI(s.current,c.current,a))},d=()=>l.current.atEnd&&l.current.first!==void 0,f=yI(o,d),p=()=>{let e=l.current.atEnd;u(),!e&&d()&&f()};(0,I.useLayoutEffect)(()=>{let e=s.current;if(!e||!c.current)return;let t=l.current,n=t.anchor&&t.anchor.element.isConnected?t.anchor.element.getBoundingClientRect().top-e.getBoundingClientRect().top:void 0,r=bI(c.current),i=r?r.getBoundingClientRect().top-e.getBoundingClientRect().top:void 0,o=_I(t,{first:c.current.firstElementChild??void 0,anchorTop:n,scrollTop:e.scrollTop,scrollHeight:e.scrollHeight,followKey:a,newLineTop:i});o!==void 0&&(e.scrollTop=o),u(),d()&&f()},[n,a]),(0,I.useEffect)(()=>{let e=s.current;if(!e||!c.current)return;let t=new ResizeObserver(()=>{l.current.atEnd&&(e.scrollTop=e.scrollHeight)});return t.observe(e),t.observe(c.current),()=>t.disconnect()},[]);let m=n===0&&!!t;return(0,B.jsxs)(`div`,{ref:s,onScroll:p,className:`flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto p-4 [overflow-anchor:none]`,children:[r&&(0,B.jsx)(G,{size:`sm`,className:`self-center`,loading:i,onClick:r,children:fI(`loadEarlier`)}),m&&(0,B.jsx)(`div`,{className:`m-auto max-w-60 text-center text-muted-foreground`,children:t}),(0,B.jsx)(`div`,{ref:c,role:`log`,"aria-live":`polite`,className:P(`flex flex-col gap-4`,m&&`hidden`),children:e})]})},SI=(e,t)=>{let n=/(?:^|\s)@([^\s@]*)$/.exec(e.slice(0,t));return n?{start:t-n[1].length-1,query:n[1]}:void 0},CI=(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(` `)}},wI=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),TI=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(wI).join(`|`)})(?![\\p{L}\\p{N}_])`,`gu`)},EI=(e,t)=>{let n=TI(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))]},DI=(e,t)=>{let n=TI(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},OI=M(`mentions`),kI=({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":OI(`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:OI(o?`couldNotSearch`:`noOneFound`)})]}),AI=(e,t)=>{let n=eT(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},jI={text:``,picked:[]},MI=8,NI=({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?SI(e.text,l):void 0,S=d&&x!==void 0&&x.start!==h,C=AI(n,S?x.query:void 0),w=S&&C&&`people`in C?C.people.slice(0,MI):[],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=CI(e.text,x,n.name);y.current=r.caret,t({text:r.text,picked:[...e.picked,n]})},k=e=>{if(S){let t=Zw(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)(Ug,{...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)(kI,{id:b,optionId:E,people:w,active:p,onActive:m,onPick:O,failed:`failed`in C,at:r})]})},PI=({text:e,mentions:t})=>(0,B.jsx)(`p`,{className:`whitespace-pre-wrap break-words`,children:DI(e,t).map((e,t)=>`mention`in e?(0,B.jsxs)(`span`,{className:`font-medium text-primary`,children:[`@`,e.mention]},t):e.text)}),FI=e=>e.types.includes(`Files`),II=e=>e.types.includes(`text/plain`)?[]:[...e.files],LI=(e,{busy:t,canSendEmpty:n})=>t?!1:e!==``||n===!0,RI=({onSend:e,busy:t,placeholder:n,inputRef:r,searchPeople:i,attachments:a,actions:o,canSendEmpty:s,onFiles:c})=>{let[l,u]=(0,I.useState)(jI),d=l.text.trim(),f=LI(d,{busy:t,canSendEmpty:s}),p=()=>{f&&(e?.(d,EI(d,l.picked)),u(jI))};return(0,B.jsxs)(`form`,{className:`flex flex-wrap items-end gap-2`,onSubmit:e=>{e.preventDefault(),p()},onDragOver:e=>{c&&FI(e.dataTransfer)&&e.preventDefault()},onDrop:e=>{c&&FI(e.dataTransfer)&&(e.preventDefault(),c([...e.dataTransfer.files]))},children:[a&&(0,B.jsx)(`div`,{className:`basis-full`,children:a}),o,(0,B.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,B.jsx)(NI,{ref:r,rows:1,"aria-label":fI(`message`),placeholder:n,value:l,onChange:u,searchPeople:i,listAt:`above`,onKeyDown:e=>{e.key!==`Enter`||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),p())},onPaste:e=>{if(!c)return;let t=II(e.clipboardData);t.length!==0&&(e.preventDefault(),c(t))}})}),(0,B.jsx)(G,{type:`submit`,variant:`primary`,className:`w-8 px-0`,"aria-label":fI(`send`),disabled:!f,children:(0,B.jsx)(ls,{className:`size-4`})})]})},zI=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},BI=M(`side-panel`),VI=({title:e,icon:t,status:n,onClose:r,footer:i,children:a})=>{let o=zI(!gf());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":BI(`close`),onClick:r,children:(0,B.jsx)(yc,{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})]})},HI=M(`action-card`),UI={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`}},WI=({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`,UI[t].border),children:[!s&&(0,B.jsxs)(`header`,{className:P(`flex items-center gap-2 px-3 py-2`,UI[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)(Cf,{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:HI(`cancel`)}),(0,B.jsx)(G,{variant:c.style===`danger`?`danger`:`primary`,onClick:()=>{l(void 0),a?.(c.id)},children:c.label})]})})]})},GI=({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}`))}),KI=e=>e==null?`null`:typeof e==`object`?JSON.stringify(e):String(e),qI=M(`compact-table`),JI=({columns:e,rows:t,caption:n,truncated:r,className:i})=>(0,B.jsxs)(`section`,{"aria-label":n??qI(`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:qI(`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:KI(e)},t))},t))})]})}),(0,B.jsxs)(`footer`,{className:`border-t border-border px-3 py-1.5 text-[11px] text-muted-foreground`,children:[qI(`rows`,{count:t.length}),r&&qI(`cutOff`)]})]}),YI=(e,t=1)=>{let n=t,r=t;return e.split(`
|
|
5
5
|
`).map(e=>e.startsWith(`+`)?{kind:`add`,text:e.slice(1),newNo:r++}:e.startsWith(`-`)?{kind:`del`,text:e.slice(1),oldNo:n++}:{kind:`ctx`,text:e.startsWith(` `)?e.slice(1):e,oldNo:n++,newNo:r++})},XI=e=>({added:e.filter(e=>e.kind===`add`).length,removed:e.filter(e=>e.kind===`del`).length}),ZI={add:`bg-success-soft text-success-text`,del:`bg-danger-soft text-danger-text`,ctx:`text-muted-foreground`},QI={add:`+`,del:`−`,ctx:``},$I=({source:e,start:t,path:n,className:r})=>{let i=YI(e,t),a=XI(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)(va,{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`,ZI[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:QI[e.kind]}),(0,B.jsx)(`span`,{className:`min-w-0 whitespace-pre-wrap break-words pr-3`,children:e.text})]},t))})]})},eL={pending:(0,B.jsx)(Hi,{className:`size-3 text-faint-foreground`}),running:(0,B.jsx)($d,{className:`size-3.5 text-primary`}),done:(0,B.jsx)(Si,{className:`size-3.5 text-success`,strokeWidth:2.5}),failed:(0,B.jsx)(yc,{className:`size-3.5 text-danger`,strokeWidth:2.5})},tL={pending:`text-muted-foreground`,running:`text-foreground`,done:`text-muted-foreground`,failed:`text-danger-text`},nL=({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:eL[e.state]}),(0,B.jsx)(`span`,{className:tL[e.state],children:e.label})]},`${t}-${e.label}`))}),rL=M(`assistant-dock`),iL=({part:e,note:t})=>e.fallback?(0,B.jsx)(WI,{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}`}),aL=class extends I.Component{state={failed:!1};static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(e,t){av(e,t.componentStack)}render(){return this.state.failed?(0,B.jsx)(iL,{part:this.props.part,note:rL(`couldNotDraw`)}):this.props.children}},oL=({part:e})=>{let{components:t={}}=c_(),n=Object.hasOwn(t,e.name)?t[e.name]:void 0;return n?(0,B.jsx)(aL,{part:e,children:(0,B.jsx)(n,{...e.props})}):(0,B.jsx)(iL,{part:e,note:rL(`cannotShowLive`)})},sL=({part:e,onAction:t})=>{switch(e.type){case`text`:return(0,B.jsx)(`p`,{children:e.text});case`table`:return(0,B.jsx)(JI,{columns:e.columns,rows:e.rows,caption:e.caption,truncated:e.truncated});case`card`:return(0,B.jsxs)(WI,{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)(GI,{fields:e.fields}),e.steps&&e.steps.length>0&&(0,B.jsx)(nL,{steps:e.steps}),e.diffs?.map((e,t)=>(0,B.jsx)($I,{source:e.source,start:e.start,path:e.path,className:`rounded-md border border-border`},`${t}-${e.path}`))]});case`widget`:return(0,B.jsx)(oL,{part:e})}},cL=(0,I.createContext)(void 0),lL=e=>e instanceof Error?e:Error(rL(`backendNoAnswer`)),uL=(e,t)=>typeof e==`function`?e(t):e,dL=(e,{refreshMs:t=!1}={})=>{let n=(0,I.useContext)(cL),[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:lL(e)}));if(!t)return;c.current=o.data,i(o);let l=uL(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:lL(e)}));c.current=a.data,i(a)}}},fL=({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)(VI,{title:rL(`assistant`),icon:(0,B.jsx)(Ds,{className:`size-4 text-primary`}),status:t?rL(`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)(RI,{inputRef:s,onSend:r,busy:e.replying,placeholder:e.placeholder??rL(`askQuestion`)})]}),children:(0,B.jsx)(cL.Provider,{value:o,children:(0,B.jsx)(xI,{length:e.messages.reduce((e,t)=>e+t.parts.length,0),empty:rL(`empty`),children:e.messages.map(e=>(0,B.jsx)(hI,{from:e.from,children:e.parts.map(e=>(0,B.jsx)(sL,{part:e,onAction:i},e.id))},e.id))})})})},pL=e=>e instanceof Error?e.message:rL(`noAnswer`),mL=e=>{let[t,n]=(0,I.useState)(Qn),[r,i]=(0,I.useState)(!1),[a,o]=(0,I.useState)();(0,I.useEffect)(()=>{if(e)return e.connect(e=>n(t=>tr(t,e)),e=>i(e.state===`retrying`))},[e]);let s=e=>{o(void 0),e.catch(e=>o(pL(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))}},hL=e=>{let t=qP(),n=(0,I.useRef)(t);n.current=t;let r=t!==void 0;return(0,I.useMemo)(()=>r?ed({url:e,token:()=>n.current}):void 0,[e,r])},gL=({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)(Ds,{className:`size-3.5`}),(0,B.jsx)(`span`,{className:`max-md:sr-only`,children:q(`assistant`)})]}),_L=({client:e,page:t,onClose:n})=>{let{state:r,offline:i,error:a,send:o,act:s}=mL(e);return(0,B.jsx)(fL,{state:r,offline:i,error:a,onSend:e=>o(e,t),onAction:s,onClose:n,client:e})},vL=({url:e,...t})=>(0,B.jsx)(_L,{client:hL(e),...t}),yL=({url:e,client:t,...n})=>t?(0,B.jsx)(_L,{client:t,...n}):(0,B.jsx)(vL,{url:e,...n}),bL={bell:ni,"book-open":ii,bookmark:ui,building:mi,"credit-card":Qi,"external-link":ua,"file-text":Sa,globe:ia,heart:Oa,key:Ia,"layout-dashboard":Ha,"life-buoy":Ja,mail:co,package:No,receipt:$o,settings:hs,shield:_s,"shopping-cart":xs,tags:Us,users:ac,warehouse:pc};Object.keys(bL);var xL=(e,t)=>e?bL[e]??t:t,SL=(e,t)=>xL(e.views[t]?.icon??e.signIn?.[t]?.icon,Ls),CL=(e,t,n)=>(e.bottomBar?.items??[]).map((r,i)=>r.kind===`link`?{id:`link-${i}`,label:r.label,icon:xL(r.icon,ua),href:r.href,external:!0}:r.kind===`page`?{id:r.page,label:r.label,icon:xL(r.icon??e.pages[r.page]?.icon,Ha),href:Bc({kind:`page`,page:r.page},t),active:r.page===n}:{id:r.resource,label:r.label,icon:xL(r.icon,SL(e,r.resource)),href:Bc({kind:`list`,resource:r.resource},t),active:r.resource===n}),wL=({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:Bc({kind:`page`,page:r.name},e)}];if(!t||t.kind===`page`)return[q(`admin`)];let c=i?[{label:i,href:Bc({kind:`list`,resource:t.resource,...t.kind===`list`&&t.list&&{list:t.list}},e)}]:[];if(t.kind===`list`)return[...s,...c];let l=Bc(t,e),u=t.kind===`create`?{label:q(`new`),href:l}:a===void 0&&o?{label:q(`loadingRecord`),href:l,loading:!0}:{label:a??t.key,href:l};return[...s,...c,u]},TL=({name:e,tab:t})=>{let n=W().pages[e];if(!n)return(0,B.jsx)(tf,{title:sv(`notFound`),children:sv.rich(`noPage`,{page:e})});let r=t=>Bc({kind:`page`,page:e,...t&&{tab:t}});return(0,B.jsx)(sf,{route:{...t&&{tab:t},pathOf:r},children:(0,B.jsx)(OM,{node:n.tree})})},Q=M(`app/record`),EL=2e3,DL=Symbol(`nothing saved`),OL=(e,t)=>{let n=iy(),[r,i]=(0,I.useState)(`idle`),[a,o]=(0,I.useState)(),s=(0,I.useRef)(void 0);return(0,I.useEffect)(()=>()=>clearTimeout(s.current),[]),{phase:r,message:a,run:async r=>{let a=e===`toast`?n.show({state:`loading`,title:Q(`savingSubject`,{subject:t})}):void 0;o(void 0),e===`button`&&i(`saving`);try{return await r()===DL?(a!==void 0&&n.dismiss(a),e===`button`&&i(`idle`),!0):(a!==void 0&&n.update(a,{state:`success`,title:Q(`subjectSaved`,{subject:t})}),e===`button`&&(i(`saved`),s.current=setTimeout(()=>i(`idle`),EL)),!0)}catch(t){if(!pl(t))throw t;let r=t.status===412?Q(`changedBySomeoneElse`):Q(`couldNotSave`),s=ox(t);return a!==void 0&&n.update(a,{state:`error`,title:r,description:s}),e===`button`&&(i(`idle`),o(`${r}: ${s}`)),!1}}}},kL=({title:e,eyebrow:t,submit:n,saving:r,disabled:i,error:a,errorTitle:o=Dg(`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:Dg(`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)(Bg,{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]})})},AL=({noun:e,collection:t,sections:n,saving:r,message:i,onSubmit:a,onCancel:o,ref:s})=>(0,B.jsx)(kL,{ref:s,title:Dg(`title`,{noun:e}),eyebrow:t,submit:Dg(`submit`,{noun:e}),saving:r,error:i?Error(i):void 0,errorTitle:Dg(`notCreated`),onSubmit:a,onCancel:o,children:n.map(e=>(0,B.jsx)(Vf,{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)(Yh,{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))}),jL=(e,t)=>Object.fromEntries(Object.entries(e).filter(([e])=>e!==t)),ML=({resource:e,values:t})=>{let n=W(),r=n.resources[e],i=af(e);return r?oy(i,`create`)?(0,B.jsx)(NL,{resource:e,values:t}):(0,B.jsx)(tf,{title:Dg(`notAllowed`),children:Dg(`cannotCreate`,{plural:n.views[e]?.names?.plural.toLowerCase()??e})}):(0,B.jsx)(tf,{title:q(`notFound`),children:q(`noResource`,{name:e})})},NL=({resource:e,values:t})=>{let n=W(),r=n.resources[e],i=n.views[e],a=U(),o=Se(),{go:s}=Hh(),c=i?.names?.singular??F(e),l=OL(i?.saveFeedback??`toast`,Dg(`subject`,{noun:c})),u=Ag(r,i),[d,f]=(0,I.useState)(()=>Lg(r,u,t)),[p,m]=(0,I.useState)({}),[h,g]=(0,I.useState)(0),_=sx(h),[v,y]=(0,I.useState)(),[b,x]=(0,I.useState)(!1);Vh(!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&&xb(o,a,t,[i],n.views[t.name]).then(t=>{let n=t.get(i);n&&f(t=>Og(t[e])&&t[e].key===i?{...t,[e]:{key:i,label:n}}:t)})}},[t,n,r,a,o]);let S=(e,t)=>{m(t=>jL(t,e)),x(!0),f(n=>({...n,[e]:t}))},C=()=>l.run(async()=>{let t;try{t=await a.create(e,Mg(r,n.resources,d))}catch(t){let n=pl(t)?t.existing:void 0;if(n)return y({kind:`record`,resource:e,key:n.key}),DL;let r=ax(t);throw m(r),Object.keys(r).length>0&&g(e=>e+1),t}for(let t of[`page`,`list`,`first-page`,`map`,`facets`,`series`])o.invalidateQueries({queryKey:[t,e]});y({kind:`record`,resource:e,key:ym(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:Ng(t),error:c&&ix(t,s,c),wide:!!(i?.fields[e]?.multiline||i?.fields[e]?.markdown),editor:(0,B.jsx)(Ov,{field:t,hints:i?.fields[e],value:Og(a)?a.key:a??(t.type!==`boolean`&&``),stored:void 0,relationLabel:Og(a)?a.label:void 0,placeholder:Rg(t)?Dg(`setByDatabase`):Ig(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)(AL,{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})})},PL=({resource:e,values:t})=>{let n=W(),r=n.views[e];return r?.create?n.pages[r.create.page]?(0,B.jsx)(TL,{name:r.create.page}):(0,B.jsx)(tf,{title:Dg(`notAllowed`),children:Dg(`cannotCreate`,{plural:r.names?.plural.toLowerCase()??F(e)})}):(0,B.jsx)(ML,{resource:e,values:t},new URLSearchParams(t).toString())},FL=(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)}}))},IL=(e,t)=>[...new Set(t.filter(t=>!e.includes(t)))],LL=sn(),RL=(e,t,n)=>{let r=U(),[i,a]=(0,I.useState)({}),o=e=>!!e?.search?.length&&e.primaryKey.length===1,s=e=>{let n=t[e.name];return[e.primaryKey[0],...n?.titleFrom?n.titleFrom.fields:[sr(e,n)]]},c=(e,r)=>{let i=t[e.name],a=String(r[e.primaryKey[0]]);return[a,i?.titleFrom?n(e,i,r,a):String(r[sr(e,i)])]},l=f({queries:e.map(({id:e,target:t})=>{let n=(i[e]??``).trim();return{queryKey:[`reference-search`,e,t?.name??``,n],enabled:o(t)&&n!==``,placeholderData:d,queryFn:async()=>(await r.list(t.name,{filter:Yt(LL.search(n)),fields:s(t),pageSize:20})).items}})});return e.map(({id:e,target:t},n)=>{if(!o(t))return{};let r=t=>a(n=>({...n,[e]:t}));return(i[e]??``).trim()===``?{onSearch:r}:{onSearch:r,matches:(l[n]?.data??[]).map(e=>c(t,e))}})},zL=24,BL=({model:e,resources:t,views:n,view:r,state:i,extras:a,titleOf:o})=>{let s=U(),c=Se(),l=RT(r,e),u=e=>r?.fields[e]?.label??F(e),d=n=>{let r=e.fields[n];return r?.type===`relation`&&r.relation?t[r.relation.resource]:void 0},p=e=>!!(e&&n[e.name]?.titleFrom),m=l.facets.flatMap(e=>(e.flags?e.options.map(e=>e.value):[e.id]).map(t=>({group:e.id,field:t}))),h=f({queries:m.map(({group:t,field:r})=>{let o=TT(l,{...i,facets:{...i.facets,[t]:[]}},a),c=d(r),u=c?.primaryKey.length===1&&!p(c)?sr(c,n[c.name]):void 0;return{queryKey:H.facets(e.name,r,o),queryFn:()=>s.facets(e.name,r,{filter:o,limit:50,...u&&{label:u}})}})}),g=(e,t)=>h[m.findIndex(n=>n.group===e&&n.field===t)]?.data,_=e=>(g(e,e)??[]).flatMap(e=>e.value===null?[]:[String(e.value)]),v=f({queries:l.facets.map(t=>{let r=d(t.id),a=IL(_(t.id),i.facets[t.id]??[]);return{queryKey:H.labels(`facet:${e.name}.${t.id}`,a.join(`,`)),enabled:!!r&&!p(r)&&a.length>0,queryFn:async()=>[...await xb(c,s,r,a,n[r.name])]}})}),y=f({queries:l.facets.map(t=>{let r=d(t.id),a=r&&p(r)?Eb(r,n[r.name]):void 0,o=[...new Set([..._(t.id),...i.facets[t.id]??[]])];return{queryKey:H.labels(`facet-title:${e.name}.${t.id}`,o.join(`,`)),enabled:a!==void 0&&o.length>0,queryFn:async()=>[...await Ob(s,r,a,o)]}})}),b=(e,t)=>{let r=d(e);return(y[t]?.data??[]).map(([e,t])=>[e,o(r,n[r.name],t,e)])},x=RL(l.facets.map(e=>({id:e.id,target:e.combobox?d(e.id):void 0})),n,o),S=l.ranges??[],C=f({queries:S.map(t=>{let n=TT(l,Bw(i,t.id,void 0),a),o=zT(r,t.id)?zL:1;return{queryKey:H.histogram(e.name,t.id,o,n),queryFn:()=>s.histogram(e.name,t.id,{filter:n,buckets:o})}})});return{facets:l.facets.map((t,n)=>{if(t.flags){let e=t.options.map(({value:e})=>({value:e,label:u(e),count:g(t.id,e)?.find(e=>String(e.value)===`true`)?.count??0}));return{...t,options:e}}let i=e.fields[t.id],a=(g(t.id,t.id)??[]).flatMap(e=>e.label===void 0?[]:[[String(e.value),e.label]]),o=new Map([...a,...v[n]?.data??[],...b(t.id,n)]),s=(g(t.id,t.id)??[]).flatMap(e=>e.value===null?[]:[{value:String(e.value),label:i?.type===`enum`?ir(String(e.value),r?.fields[t.id]?.valueLabels):o.get(String(e.value))??String(e.value),count:e.count}]),c=x[n];return{...t,label:u(t.id),options:c.matches?FL(c.matches,s):s,...o.size>0&&{labels:Object.fromEntries(o)},...c.onSearch&&{onSearch:c.onSearch}}}),ranges:S.flatMap((e,t)=>{let n=C[t]?.data;return!n||n.min===null||n.max===null?[]:[{...e,label:u(e.id),min:Math.floor(n.min),max:Math.ceil(n.max),step:Math.max(1,Math.round((n.max-n.min)/100)),histogram:zT(r,e.id)?n.buckets.map(e=>e.count):[],format:BT(r,e.id)}]}),...l.dateField&&{datePresets:l.datePresets??!0,dateField:l.dateField,dateKind:l.dateKind,...l.dateSecondary&&{dateSecondary:!0}},toggles:l.toggles?.map(e=>({...e,label:u(e.id)}))}},VL=M(`app/delete`),HL=sn(),UL=({blockingPlural:e,noun:t})=>VL(`stillPointAt`,{plural:e,noun:t}),WL=({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=UL({blockingPlural:s,noun:r});if(!o||i===void 0)return{text:c};let l={kind:`list`,resource:a,filter:Yt(HL.eq(o,i))};return{text:c,link:{label:VL(`show`,{plural:s}),to:l}}},GL=({title:e,noun:t,busy:n,onConfirm:r,onCancel:i})=>(0,B.jsx)(Cf,{title:VL(`confirmTitle`,{title:e}),description:VL(`confirmDescription`,{noun:t,title:e}),onClose:i,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:i,children:VL(`cancel`)}),(0,B.jsx)(G,{variant:`primary`,className:`bg-danger hover:bg-danger/90`,loading:n,onClick:r,children:VL(`delete`)})]})}),KL=({title:e,changes:t,busy:n,onReview:r,onDeleteAnyway:i,onCancel:a})=>(0,B.jsx)(Cf,{title:VL(`changedTitle`,{title:e}),description:VL(`changedDescription`),onClose:a,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:r,children:VL(`reviewChanges`)}),(0,B.jsx)(G,{variant:`primary`,className:`bg-danger hover:bg-danger/90`,loading:n,onClick:i,children:VL(`deleteAnyway`)})]}),children:t.length===0?(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:VL(`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))})}),qL=e=>{if(e.stage===`confirm`)return(0,B.jsx)(Cf,{title:VL(`bulkConfirmTitle`,{count:e.count,noun:e.noun,plural:e.plural}),description:VL(`bulkConfirmDescription`),onClose:e.onCancel,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:e.onCancel,children:VL(`cancel`)}),(0,B.jsx)(G,{variant:`primary`,className:`bg-danger hover:bg-danger/90`,onClick:e.onConfirm,children:VL(`deleteCount`,{count:e.count})})]})});if(e.stage===`running`)return(0,B.jsx)(Cf,{title:VL(`deleting`),description:VL(`progress`,{done:e.done,total:e.total}),onClose:()=>void 0,actions:(0,B.jsx)(G,{loading:!0,disabled:!0,children:VL(`working`)})});let t=e.total-e.failures.length;return(0,B.jsx)(Cf,{title:e.failures.length===0?VL(`deleted`,{count:t}):VL(`deletedOf`,{count:t,total:e.total}),description:e.failures.length===0?void 0:VL(`kept`,{count:e.failures.length}),onClose:e.onClose,actions:(0,B.jsx)(G,{variant:`primary`,onClick:e.onClose,children:VL(`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))})})},JL=new Set([`updated_at`,`updatedAt`]),YL=(e,t,n,r)=>Object.values(e.fields).flatMap(e=>{if(JL.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:Nm(e,n[e.name],i),after:Nm(e,r[e.name],i)}]}),XL=4,ZL=({model:e,view:t,onDeleted:n,onReview:r,restore:i})=>{let a=U(),o=Se(),s=iy(),[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:_}=Hh(),v=(t,n)=>t.blockedBy&&WL({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 fl))throw e;return e}},x=t=>{y(),l(void 0),n?.(t),s.show({state:`success`,title:VL(`deletedToast`,{title:t.title}),...e.softDelete&&i&&{action:{label:VL(`undo`),onClick:()=>{i(t).then(()=>{y(),s.show({state:`success`,title:VL(`restored`,{title:t.title})})},e=>{if(!pl(e))throw e;y(),s.show({state:e.status===409?`success`:`error`,title:e.status===409?VL(`alreadyBack`,{title:t.title}):VL(`couldNotRestore`,{title:t.title}),description:e.status===409?void 0:e.message})})}}}})},S=async(n,r)=>{d(!0);try{if(!await b(n,r))return x(n);let i=(await a.get(e.name,n.key)).record;l({kind:`conflict`,target:n,fresh:i,changes:YL(e,t,n.snapshot,i)})}catch(e){if(!pl(e))throw e;l(void 0);let t=v(e,n);s.show({state:`error`,title:VL(`couldNotDelete`,{title:n.title}),description:t?.text??e.message,...t?.link&&{action:{label:t.link.label,href:g(t.link.to),onNavigate:_}}})}finally{d(!1)}},C=async e=>{try{return await b(e,e.etag)?{title:e.title,message:VL(`changedSinceLoaded`)}:void 0}catch(t){if(!pl(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(XL,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)(GL,{title:c.target.title,noun:f,busy:u,onCancel:T,onConfirm:()=>void S(c.target,c.target.etag)}),c.kind===`conflict`&&(0,B.jsx)(KL,{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)(qL,{stage:`confirm`,count:c.targets.length,noun:f,plural:p,onCancel:T,onConfirm:()=>void w(c.targets)}),c.kind===`bulk-running`&&(0,B.jsx)(qL,{stage:`running`,done:c.done,total:c.total}),c.kind===`bulk-done`&&(0,B.jsx)(qL,{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})}},QL=e=>{let t=U();return e.softDelete?async n=>void await t.undelete(e.name,n.key):void 0},$L=(e,t,n)=>e?.create?Object.hasOwn(t,e.create.page):oy(n,`create`),$=M(`app/import`),eR=e=>typeof e==`object`&&!!e,tR=e=>e===null||typeof e==`string`&&e.trim()===``,nR=e=>e===null?``:eR(e)?e.date.replace(`T`,` `):typeof e==`boolean`?e?`TRUE`:`FALSE`:String(e),rR=e=>e<26?String.fromCharCode(65+e):rR(Math.floor(e/26)-1)+rR(e%26),iR=(e,t)=>e[t]?.trim()?e[t]:$(`column`,{letters:rR(t)}),aR=e=>/[",\r\n]/.test(e)?`"${e.replace(/"/g,`""`)}"`:e,oR=(e,t)=>{let n=[...t].sort((e,t)=>e.line-t.line).map(t=>[...e.map((e,n)=>nR(t.cells[n]??null)),String(t.line),t.problems.join(`; `)]);return`${[[...e,$(`line`),$(`problems`)],...n].map(e=>e.map(aR).join(`,`)).join(`\r
|
|
6
|
-
`)}\r\n`},sR=({label:e,counts:t})=>(0,B.jsx)(`dl`,{"aria-label":e,className:`grid grid-cols-2 gap-3 sm:grid-cols-4`,children:t.map(([e,t])=>(0,B.jsxs)(`div`,{className:`rounded-lg border px-3 py-2`,children:[(0,B.jsx)(`dt`,{className:`text-xs text-muted-foreground`,children:e}),(0,B.jsx)(`dd`,{className:`text-lg font-semibold tabular-nums`,children:t.toLocaleString(Le())})]},e))}),cR=(e,t)=>e?.fields[t]?.label??F(t),lR=new Set([`text`,`integer`,`bigint`,`decimal`,`boolean`,`date`,`timestamp`,`uuid`,`enum`,`relation`,`currency`,`country`]),uR=(e,t)=>{let n=e.relation?t[e.relation.resource]:void 0;return n?.primaryKey.length===1?n:void 0},dR=(e,t)=>Object.values(e.fields).filter(n=>n.readOnly||n.name===e.tenant||!lR.has(n.type)?!1:n.type!==`relation`||uR(n,t)!==void 0),fR=new Set([`text`,`integer`,`bigint`,`uuid`,`date`,`currency`,`country`,`enum`]),pR=e=>{let t=e.primaryKey.length===1?[e.fields[e.primaryKey[0]]]:[],n=Object.values(e.fields).filter(t=>t.filterable&&!t.sensitive&&fR.has(t.type)&&!e.primaryKey.includes(t.name));return[...t,...n]},mR=(e,t)=>uR(e,t),hR=e=>!e.nullable&&!e.default,gR=e=>e.toLowerCase().replace(/[\s_-]+/g,``),_R=(e,t,n)=>{let r=new Set;return e.flatMap((e,i)=>{let a=gR(e);if(a===``)return[];let o=t.find(e=>!r.has(e.name)&&(gR(cR(n,e.name))===a||gR(e.name)===a));return o?(r.add(o.name),[{column:i,field:o.name}]):[]})},vR=(e,t,n)=>{if(e===`update`)return[];let r=new Set(n.map(e=>e.field));return t.filter(e=>hR(e)&&!r.has(e.name))},yR=e=>({ok:!0,value:e}),bR=e=>({ok:!1,problem:e}),xR=e=>`“${nR(e)}”`,SR=(e,t)=>{if(typeof e==`number`)return String(e);if(typeof e==`string`)return ug(e,t.decimal)},CR=(e,t,n)=>{let r=SR(t,n);if(r===void 0)return bR($(`notNumber`,{cell:xR(t)}));let[i,a=``]=r.split(`.`);if(/[1-9]/.test(a)||/e/i.test(r))return bR($(`notWholeNumber`,{cell:xR(t)}));if(e.type===`bigint`)return yR(String(BigInt(i)));let o=Number(i);return Number.isSafeInteger(o)?yR(o):bR($(`tooLarge`,{cell:xR(t)}))},wR=(e,t)=>{let n=SR(e,t);return n===void 0?bR($(`notNumber`,{cell:xR(e)})):yR(n)},TR=new Set([`true`,`yes`,`1`]),ER=new Set([`false`,`no`,`0`]),DR=e=>{if(typeof e==`boolean`)return yR(e);let t=typeof e==`string`||typeof e==`number`?String(e).trim().toLowerCase():``;return TR.has(t)?yR(!0):ER.has(t)?yR(!1):bR($(`notBoolean`,{cell:xR(e)}))},OR=e=>String(e).padStart(2,`0`),kR=(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}-${OR(t)}-${OR(n)}`},AR=`(\\d{1,2}):(\\d{2})(?::(\\d{2})(?:\\.\\d+)?)?`,jR=(e,t)=>{let n=RegExp(`^(\\d{4})[-/](\\d{1,2})[-/](\\d{1,2})(?:[T ]${AR}(Z|[+-]\\d{2}:?\\d{2})?)?$`).exec(e.trim()),r=RegExp(`^(\\d{1,2})[./-](\\d{1,2})[./-](\\d{4})(?: ${AR})?$`).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=kR(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:`${OR(Number(c))}:${l}:${OR(Number(u))}`,zone:n?.[7]}},MR=(e,t)=>{if(eR(e)){let[t,n]=e.date.split(`T`);return{date:t,time:n}}return typeof e==`string`?jR(e,t.dateOrder):void 0},NR=(e,t)=>bR($(`notDate`,{cell:xR(e),dayFirst:t.dateOrder===`dmy`})),PR=(e,t)=>{let n=MR(e,t);return n?n.time&&n.time!==`00:00:00`?bR($(`hasTime`,{cell:xR(e)})):yR(n.date):NR(e,t)},FR=(e,t)=>{let n=MR(e,t);if(!n)return NR(e,t);if(n.zone)return yR(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 yR(new Date(r,i-1,a,o,s,c).toISOString())},IR=e=>e.trim().toLowerCase().replace(/\s+/g,` `),LR=(e,t,n)=>{let r=e.enumValues??[],i=IR(nR(n)),a=r.filter(e=>IR(e)===i||IR(ir(e,t?.valueLabels))===i);return a.length===1?yR(a[0]):a.length>1?bR($(`severalValues`,{cell:xR(n),values:a.map(e=>ir(e,t?.valueLabels)).join(`, `)})):bR($(`notOneOf`,{cell:xR(n),values:r.map(e=>ir(e,t?.valueLabels)).join(`, `)}))},RR=e=>typeof e==`boolean`?bR($(`notText`,{cell:xR(e)})):yR(nR(e)),zR=(e,t,n,r)=>{if(tR(n))return e.nullable?yR(null):bR($(`emptyRequired`));switch(e.type){case`integer`:case`bigint`:return CR(e,n,r);case`decimal`:return wR(n,r);case`boolean`:return DR(n);case`date`:return PR(n,r);case`timestamp`:return FR(n,r);case`enum`:return LR(e,t,n);case`text`:case`uuid`:case`currency`:case`country`:return RR(n);default:throw Error(`Not implemented: importing ${e.type} fields, which importableFields leaves out`)}},BR=(e,t)=>e[t]?.names?.singular??F(t),VR=(e,t)=>e[t]?.names?.plural??F(t),HR=(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=cR(o,d),g=mR(p,i);if(g&&!tR(m)){let e=f??g.primaryKey[0],n=zR(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]=nR(m);continue}let _=zR(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=zR({...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(`${cR(o,n.name)}: ${i.problem}`)}return{values:s,data:c,problems:l,relations:u,match:d}},UR=(e,t)=>{let n=e.lookups.keysOf(t.model.name,t.field,t.value),r=`${cR(e.views[t.model.name],t.field).toLowerCase()} “${String(t.value)}”`;return n.length===1?{key:n[0]}:n.length===0?{none:$(`noneHas`,{singular:BR(e.views,t.model.name),named:r})}:{several:$(`severalHave`,{count:n.length,plural:VR(e.views,t.model.name),named:r})}},WR=e=>e.cells.every(tR),GR=async(e,t,n)=>{let{model:r,views:i}=n,a=e.filter(e=>!WR(e)).map(e=>({row:e,...HR(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=UR(n,t);`key`in a?u[e]=a.key:s.push(`${cR(i[r.name],e)}: ${a.none??a.several}`)}let d=l&&UR(n,l);d?.several&&s.push($(`notOneRecord`,{found:d.several})),d?.none&&t.mode===`update`&&s.push($(`nothingToUpdate`,{found:d.none}));let f={line:e.line,cells:e.cells,values:a,problems:s};return s.length>0?f:d&&`key`in d?{...f,op:{op:`update`,resource:r.name,key:d.key,etag:`*`,data:u}}:{...f,op:{op:`create`,resource:r.name,data:u}}})},KR=5,qR=5,JR=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(nR),sample:a.slice(0,KR)}};async function*YR(e,t){let n=!0;for await(let r of e.rows(t))yield n?r.slice(1):r,n=!1}var XR=async(e,t,n,r,i,a)=>{let o={rows:0,creates:0,updates:0,problems:[],preview:[]};for await(let s of YR(e,t)){a?.throwIfAborted();for(let e of await GR(s,n,r))o.rows++,o.preview.length<qR&&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},ZR=(e,t)=>{if(!pl(e))return[e.message];let n=e.errors.filter(e=>e.field);return n.length===0?[e.message]:n.map(e=>`${cR(t.views[t.model.name],e.field)}: ${e.message}`)},QR=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=pl(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:ZR(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 YR(e,t)){for(let e of await GR(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}},$R=50,ez=(e,t,n)=>mM(oR(t,n),$(`notImportedFile`,{name:(e??`import`).replace(/\.[^.]+$/,``)}),`text/csv`),tz=({rows:e})=>(0,B.jsxs)(`ul`,{"aria-label":$(`rowsNotImported`),className:`flex flex-col gap-1 text-body`,children:[e.slice(0,$R).map(e=>(0,B.jsxs)(`li`,{children:[(0,B.jsx)(`span`,{className:`font-medium`,children:$(`rowProblems`,{line:e.line})}),` `,e.problems.join(`; `)]},e.line)),e.length>$R&&(0,B.jsx)(`li`,{className:`text-muted-foreground`,children:$(`andMore`,{count:(e.length-$R).toLocaleString(Le())})})]}),nz=({rows:e})=>(0,B.jsxs)(`p`,{className:`flex items-center gap-2 text-muted-foreground`,role:`status`,children:[(0,B.jsx)($d,{className:`size-3.5`}),$(`checkingRows`,{count:e.toLocaleString(Le())})]}),rz=({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)(sR,{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:cR(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:mR(t,n)?String(e.values[t.name]??`—`):t.name in e.values?Nm(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:()=>ez(o,a,e.problems),children:[(0,B.jsx)(na,{className:`size-3.5`}),$(`download`)]})]}),(0,B.jsx)(tz,{rows:e.problems})]}),(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:$(`batches`,{size:100})})]})},iz=({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})]})},az=({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)($d,{className:`size-3.5`}),$(`reading`,{name:e?.name??$(`theFile`)})]}),!r&&t.length>1&&(0,B.jsxs)(`div`,{className:`flex items-end gap-3`,children:[(0,B.jsx)(ba,{className:`mb-2 size-4 shrink-0 text-muted-foreground`}),(0,B.jsx)(iz,{className:`flex-1`,label:$(`sheet`),value:n??``,options:t.map(e=>({value:e,label:e})),onChange:a})]})]})},oz=()=>[{value:`create`,label:$(`create`)},{value:`update`,label:$(`update`)},{value:`upsert`,label:$(`upsert`)}],sz={create:`createHint`,update:`updateHint`,upsert:`upsertHint`},cz=``,lz=({flow:e,model:t,resources:n,views:r,canUpdate:i})=>{let a=r[t.name],o=e.head?.headers??[],s=e.head?.sample??[],c=vR(e.mode,e.fields,e.columns),l=[{value:cz,label:$(`doNotImport`)},...e.fields.map(e=>({value:e.name,label:`${cR(a,e.name)}${hR(e)?` *`:``}`}))],u=o.map((e,t)=>({value:String(t),label:iR(o,t)})),d=pR(t);return(0,B.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[i&&(0,B.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,B.jsx)(`span`,{className:`font-medium`,children:$(`rows`)}),(0,B.jsx)(`div`,{children:(0,B.jsx)(Re,{label:$(`whatEachRowDoes`),size:`md`,value:e.mode,options:oz(),onChange:e.setMode})}),(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:$(sz[e.mode])})]}),e.mode!==`create`&&(0,B.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2`,children:[(0,B.jsx)(iz,{label:$(`findBy`),value:e.match?.field??cz,options:[{value:cz,label:$(`chooseField`)},...d.map(e=>({value:e.name,label:cR(a,e.name)}))],onChange:t=>e.setMatch(t?{field:t,column:e.match?.column??0}:void 0),help:$(`findByHint`)}),(0,B.jsx)(iz,{label:$(`foundInColumn`),value:e.match?String(e.match.column):cz,options:[{value:cz,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)(iz,{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)(iz,{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?mR(d,n):void 0,p=s.map(e=>nR(e.cells[c]??null)).filter(e=>e!==``).slice(0,3),m=iR(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)(iz,{label:$(`field`),name:$(`fieldFor`,{name:m}),value:u?.field??cz,options:l,onChange:t=>e.mapColumn(c,t||void 0)}),f&&(0,B.jsx)(iz,{label:$(`foundBy`),name:$(`pluralFoundBy`,{plural:r[f.name]?.names?.plural??cR(a,d.name)}),value:u.matchBy??f.primaryKey[0],options:pR(f).map(e=>({value:e.name,label:cR(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`,{fields:c.map(e=>cR(a,e.name)).join(`, `)})})]})]})},uz=e=>e.toLocaleString(Le()),dz=({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:[uz(r),` / `,uz(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}%`}})})]})},fz=({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)(Bg,{title:$(`stopped`),error:t}),e.cancelled&&(0,B.jsx)(`p`,{role:`status`,children:$(`cancelled`)}),(0,B.jsx)(sR,{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:()=>ez(r,n,e.notWritten),children:[(0,B.jsx)(na,{className:`size-3.5`}),$(`download`)]})]}),(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:$(`notWrittenHint`)}),(0,B.jsx)(tz,{rows:[...e.notWritten].sort((e,t)=>e.line-t.line)})]})]}),pz=e=>{let t=cg(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`}},mz=sn(),hz=100,gz=e=>String(e),_z=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(gz(e))).map(e=>[gz(e),e])).values()],s=t.primaryKey[0];for(let n=0;n<o.length;n+=hz){let i=o.slice(n,n+hz);for(let e of i)a.set(gz(e),[]);let c=Yt(mz.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(gz(e[r]))?.push(e[s]);l=n.nextPageToken||void 0}while(l)}},keysOf:(e,t,r)=>n(e,t).get(gz(r))??[]}},vz=500,yz=()=>{let e=new Worker(new URL(`/assets/parse-worker-CbZA-uNr.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()}},bz=e=>({sheets:async()=>{let t=yz();try{t.send({type:`sheets`,file:e,locale:Be()});let n=await t.receive();if(n.type===`error`)throw Error(n.message);if(n.type!==`sheets`)throw Error(`The parse worker answered ${n.type} to a request for sheets`);return n.sheets}finally{t.stop()}},rows:async function*(t){let n=yz();try{for(n.send({type:`read`,file:e,sheet:t,chunk:vz,locale:Be()});;){let e=await n.receive();if(e.type===`error`)throw Error(e.message);if(e.type===`end`)return;if(e.type!==`rows`)throw Error(`The parse worker answered ${e.type} to a read`);yield e.rows,n.send({type:`next`})}}finally{n.stop()}}}),xz={created:0,updated:0,skipped:0,failed:0,notWritten:[]},Sz=({model:e,resources:t,views:n,sourceFor:r=bz})=>{let i=Rd(),a=Se(),o=n[e.name],s=(0,I.useMemo)(()=>dR(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)(()=>pz()),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 JR(t,n);_(r),x(_R(r.headers,s,o));let i=pR(e)[0],a=i?_R(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:_z(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}),XR(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:xz,total:t,cancelling:!1});let n=xz;QR(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()}},Cz=e=>e.step.kind===`file`?$(`couldNotReadFile`):$(`couldNotCheck`),wz=e=>e.columns.length===0?!1:e.mode===`create`?vR(`create`,e.fields,e.columns).length===0:e.match!==void 0,Tz=({model:e,resources:t,views:n,canUpdate:r,onClose:i,sourceFor:a})=>{let o=Sz({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)(Ef,{open:!0,wide:!0,title:$(`importPlural`,{plural:s}),description:o.file&&c.kind!==`file`?o.file.name:void 0,onClose:u,actions:(()=>{switch(c.kind){case`file`:return(0,B.jsxs)(B.Fragment,{children:[d,o.sheets.length>1&&(0,B.jsx)(G,{variant:`primary`,loading:c.reading,onClick:o.openSheet,children:$(`next`)})]});case`map`:return(0,B.jsxs)(B.Fragment,{children:[d,(0,B.jsx)(G,{variant:`primary`,disabled:!wz(o),onClick:o.check,children:$(`checkRows`)})]});case`checking`:return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:o.back,children:$(`back`)}),(0,B.jsx)(G,{variant:`primary`,loading:!0,children:$(`checking`)})]});case`checked`:{let e=c.check.creates+c.check.updates;return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:o.back,children:$(`back`)}),(0,B.jsx)(G,{variant:`primary`,disabled:e===0,onClick:()=>o.start(e),children:$(`importRows`,{count:e.toLocaleString(Le()),rows:e})})]})}case`importing`:return(0,B.jsx)(G,{variant:`danger`,disabled:c.cancelling,onClick:o.cancel,children:$(`cancelImport`)});case`done`:return(0,B.jsx)(G,{variant:`primary`,onClick:i,children:$(`done`)})}})(),children:(0,B.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[o.error!==void 0&&(0,B.jsx)(Bg,{title:Cz(o),error:o.error}),(()=>{switch(c.kind){case`file`:return(0,B.jsx)(az,{file:o.file,sheets:o.sheets,sheet:o.sheet,reading:c.reading,onChoose:o.choose,onSheet:o.setSheet});case`map`:return(0,B.jsx)(lz,{flow:o,model:e,resources:t,views:n,canUpdate:r});case`checking`:return(0,B.jsx)(nz,{rows:c.rows});case`checked`:return(0,B.jsx)(rz,{check:c.check,model:e,resources:t,views:n,columns:o.columns,headers:l,fileName:o.file?.name});case`importing`:return(0,B.jsx)(dz,{progress:c.progress,total:c.total,cancelling:c.cancelling});case`done`:return(0,B.jsx)(fz,{result:c.result,stopped:c.stopped,headers:l,fileName:o.file?.name})}})()]})})},Ez=({model:e})=>{let{resources:t,views:n}=W(),r=af(e.name),[i,a]=(0,I.useState)(!1);return n[e.name]?.import===!1||!oy(r,`create`)?null:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(G,{onClick:()=>a(!0),"aria-haspopup":`dialog`,children:[(0,B.jsx)(Zs,{className:`size-3.5`}),$(`import`)]}),i&&(0,B.jsx)(Tz,{model:e,resources:t,views:n,canUpdate:oy(r,`update`),onClose:()=>a(!1)})]})},Dz=M(`app/export`),Oz=()=>new DOMException(Dz(`cancelled`),`AbortError`),kz=async({client:e,resource:t,filters:n,orderBy:r,plan:i,labels:a,limit:o,port:s,sink:c,signal:l,onProgress:u})=>{let d=i.columns.map(e=>e.name),f=0;try{await c.write(await s.send({kind:`start`,plan:i,locale:Be()}));for(let[i,p]of n.entries()){let m=``;do{let h=await e.search(t,{filter:p,orderBy:r,pageSize:500,pageToken:m,fields:d,labels:a});if(l.aborted)throw Oz();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 Az(s,c),{rows:f,truncated:g.length<h.items.length||m!==``||i+1<n.length}}while(m!==``)}return await Az(s,c),{rows:f,truncated:!1}}catch(e){throw await c.abort(),e}finally{s.close()}},Az=async(e,t)=>{await t.write(await e.send({kind:`finish`})),await t.close()},jz=1048575,Mz=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
7
|
-
`,Nz=`http://schemas.openxmlformats.org/officeDocument/2006/relationships`,Pz=`http://schemas.openxmlformats.org/package/2006/relationships`;`${Mz}`,`${Mz}${Pz}${Nz}`,`${Mz}${Pz}${Nz}${Nz}`,new TextEncoder;var Fz=sn(),Iz=e=>e?.export!==!1,Lz=e=>Object.values(e.fields).flatMap(e=>e.sensitive?[]:[e.name]),Rz=(e,t)=>{let n=new Set(Lz(e));return Tr(e,t).filter(e=>n.has(e))},zz=(e,t,n)=>Object.fromEntries(jm(e,t,[],n).map(e=>[e.id,e.header])),Bz=(e,t,n)=>{let r=zz(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]??{}}]:[]})},Vz=(e,t)=>{let n=e?.export?e.export.maxRows??1/0:1/0;return Math.min(n,t===`xlsx`?jz:1/0)},Hz=e=>e.primaryKey.length===1,Uz=(e,t)=>{let[n]=e.primaryKey;if(!n||e.primaryKey.length!==1)throw Error(`Not implemented: selected rows are exported by a single-field key`);let r=[];for(let e=0;e<t.length;e+=500)r.push(Yt(Fz.in(n,t.slice(e,e+500))));return r},Wz=()=>{let e=new Worker(new URL(`/assets/export-worker-Bux-6dp9.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(Dz(`couldNotBuild`,{message:e.message}));for(let e of t.splice(0))e.reject(n)},{send:n=>new Promise((r,i)=>{t.push({resolve:r,reject:i}),e.postMessage(n)}),close:()=>e.terminate()}},Gz=()=>[{value:`xlsx`,label:Dz(`excel`)},{value:`csv`,label:Dz(`csv`)}],Kz=()=>[{value:`shown`,label:Dz(`asShown`)},{value:`raw`,label:Dz(`rawValues`)}],qz={shown:`shownHint`,raw:`rawHint`},Jz=e=>e.kind===`counting`?Dz(`counting`):e.kind===`exact`||e.rows>1e4?Dp(e.rows):Dz(`moreThan`),Yz=e=>{if(e.kind!==`counting`)return e.kind===`exact`?e.rows:Math.max(e.rows,10001)},Xz=({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})]}),Zz=(e,t,n)=>{let r=e.indexOf(t),i=[...e];return i.splice(r,1),i.splice(r+n,0,t),i},Qz=({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":Dz(`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)(TC,{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":Dz(`moveUp`,{label:r[e]}),disabled:a===0,onClick:()=>n(Zz(t,e,-1)),children:(0,B.jsx)(Wr,{className:`size-3.5`})}),(0,B.jsx)(G,{size:`sm`,variant:`ghost`,className:`min-h-8 px-2`,"aria-label":Dz(`moveDown`,{label:r[e]}),disabled:a===t.length-1,onClick:()=>n(Zz(t,e,1)),children:(0,B.jsx)(Pr,{className:`size-3.5`})})]})]},e)})})},$z=({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`),_=Vz(t,l),v=d===`selected`?Dz(`selectedRows`,{count:wp(a??0),rows:a??0}):Jz(i),y=(d===`selected`?a??0:Yz(i)??0)>_,b=[{value:`list`,label:Dz(`rowsInList`)},{value:`selected`,label:Dz(`selected`,{count:wp(a??0)})}];return(0,B.jsx)(Ef,{title:Dz(`exportPlural`,{plural:e}),open:o,onClose:c,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:c,children:Dz(`cancel`)}),(0,B.jsx)(G,{variant:`primary`,disabled:p.length===0,onClick:()=>s({format:l,scope:d,columns:p,mode:h}),children:Dz(`export`)})]}),children:(0,B.jsxs)(`div`,{className:`flex flex-col gap-4 text-body`,children:[(0,B.jsx)(Xz,{label:Dz(`format`),children:(0,B.jsx)(Re,{size:`md`,label:Dz(`format`),value:l,options:Gz(),onChange:u})}),a!==void 0&&a>0&&(0,B.jsx)(Xz,{label:Dz(`rows`),help:d===`list`?Dz(`listHint`):void 0,children:(0,B.jsx)(Re,{size:`md`,label:Dz(`rows`),value:d,options:b,onChange:f})}),(0,B.jsx)(Xz,{label:Dz(`values`),help:Dz(qz[h]),children:(0,B.jsx)(Re,{size:`md`,label:Dz(`values`),value:h,options:Kz(),onChange:g})}),(0,B.jsx)(Xz,{label:Dz(`columns`),children:(0,B.jsx)(Qz,{fields:n,columns:p,onChange:m})}),(0,B.jsxs)(`p`,{role:`status`,className:`text-muted-foreground`,children:[Dz(`exports`,{rows:v}),y&&Dz(`overLimit`,{limit:wp(_)})]})]})})},eB=({plural:e,done:t,total:n,onCancel:r})=>{let i=n?Math.min(1,t/n):void 0;return(0,B.jsx)(Ef,{title:Dz(`exporting`,{plural:e}),open:!0,onClose:r,actions:(0,B.jsx)(G,{onClick:r,children:Dz(`cancel`)}),children:(0,B.jsxs)(`div`,{className:`flex flex-col gap-2 text-body`,children:[(0,B.jsx)(`div`,{role:`progressbar`,"aria-label":Dz(`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?Dz(`doneOf`,{done:wp(t),total:wp(n)}):Dz(`done`,{done:wp(t)})})]})})},tB={xlsx:{mime:`application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`,extension:`.xlsx`,description:`workbook`},csv:{mime:`text/csv`,extension:`.csv`,description:`csvFile`}},nB=/[\\/:*?"<>|\u0000-\u001f]/g,rB=(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(nB,` `).trim()} ${r}${tB[t].extension}`},iB=8e6,aB=(e,t)=>{let n=new Blob([],{type:tB[t].mime}),r=[],i=0,a=()=>{n=new Blob([n,...r],{type:tB[t].mime}),r=[],i=0};return{write:async e=>{e.length!==0&&(r.push(e),i+=e.length,i>=iB&&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([])}}},oB=()=>globalThis.showSaveFilePicker,sB=()=>typeof oB()==`function`,cB=async(e,t)=>{let n=oB();if(!n)throw Error(`This browser cannot save a file as it is built`);let r=tB[t],i;try{i=await n({suggestedName:e,types:[{description:Dz(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()}},lB=(e,t)=>sB()?cB(e,t):Promise.resolve(aB(e,t)),uB=(e,t)=>{let n=t[e.primaryKey[0]];return typeof n==`object`&&n&&`id`in n?n.id:n},dB=({model:e,view:t,resources:n,views:r,plural:i,filter:a,orderBy:o,createPort:s=Wz,createSink:c=lB})=>{let l=U(),u=iy(),[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:Hz(e)?t.map(t=>uB(e,t)):[]}),g=async(d,h)=>{let g=rB(i,d.format),_=await c(g,d.format);if(!_)return;let v=Vz(t,d.format),y=d.scope===`selected`?h.length:Yz(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 kz({client:l,resource:e.name,filters:d.scope===`selected`?Uz(e,h):[a],orderBy:o,plan:{format:d.format,mode:d.mode,name:i,columns:Bz(e,t,d.columns)},labels:d.mode===`shown`?Cb(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:Dz(`exported`,{count:wp(c.rows),plural:i}),description:c.truncated?Dz(`truncated`,{name:g,count:wp(c.rows)}):g})}catch(e){if(e instanceof DOMException&&e.name===`AbortError`)return;if(!pl(e))throw e;u.show({state:`error`,title:Dz(`couldNotExport`,{plural:i}),description:e.message})}finally{p.current=void 0,f(e=>e.kind===`running`?{kind:`closed`}:e)}},_=()=>{p.current?.abort(),f({kind:`closed`})},v=Lz(e),y=zz(e,t,v);return{open:h,dialogs:d.kind===`settings`?(0,B.jsx)($z,{plural:i,view:t,fields:v.map(e=>({name:e,label:y[e]})),initialColumns:Rz(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)(eB,{plural:i,done:d.done,total:d.total,onCancel:_}):null}},fB=M(`app/list`),pB=({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:fB(`clearSearch`)}),e.clearFilters&&(0,B.jsx)(G,{onClick:n,children:fB(`clearFilters`)}),e.create&&r]})]}),mB=({plural:e,search:t,filtered:n,scoped:r,canCreate:i})=>t?{message:fB(`noMatchSearch`,{plural:e,search:t}),clearSearch:!0,clearFilters:n,create:!1}:n?{message:fB(`noMatchFilters`,{plural:e}),clearSearch:!1,clearFilters:!0,create:!1}:r?{message:fB(`noMatch`,{plural:e}),clearSearch:!1,clearFilters:!1,create:!1}:{message:fB(`noneYet`,{plural:e}),clearSearch:!1,clearFilters:!1,create:i},hB=(e,t)=>{},gB=({windowMs:e=1e3,comebacks:t=2,onHold:n=hB}={})=>{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}},_B=e=>Math.max(1,Math.floor((e+12)/252)),vB=(e,t)=>Math.max(0,(e-(t-1)*12)/t),yB=(e,t,n,r)=>({start:e*n,end:Math.max(0,Math.min(r,(t+1)*n)-1)}),bB=(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},xB=(e,t)=>{let n=e/t.rowHeight;return Math.floor(n)*t.columns+n%1},SB=(e,t)=>Math.floor(Math.floor(e)/t)+e%1,CB=8,wB=(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<=CB)break;i.delete(e)}return i},TB=({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=_B(c),d=vB(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?bB(_.current.top,_.current.layout,g):e,b=d>0&&f.has(d),x=aw({total:Math.ceil(o/u),rowHeight:h,initialIndex:SB(s,u),settle:y,ready:b,onScroll:e=>r(xB(e,g))});(0,I.useLayoutEffect)(()=>{v&&x.scrollTo(x.top),_.current={layout:g,top:x.started()?x.top:0}});let S=yB(x.first,x.last,u,o),C=GC({total:o,rowAt:e.rowAt,loadRows:e.loadRows,revision:e.revision,latencyMs:0},S.start,S.end),[w]=(0,I.useState)(()=>gB());(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=>wB(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)(vh,{className:`h-full rounded-lg`})},`skeleton-${i}`)}))})},EB=`grid grid-cols-[repeat(auto-fill,minmax(15rem,1fr))] gap-3`,DB=e=>e*.75,OB=44,kB=({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 ${EB}`,children:Array.from({length:6},(e,t)=>(0,B.jsx)(vh,{className:`h-24`},t))}):r.error?(0,B.jsx)(Bg,{title:K(`couldNotLoadRows`),error:r.error}):!r.source||r.source.total===0?i??(0,B.jsx)(`p`,{className:`py-8 text-center text-muted-foreground`,children:K(`noneMatch`,{plural:a.toLowerCase()})}):(0,B.jsx)(TB,{source:r.source,label:a,initialIndex:r.initialIndex,onScrollIndex:r.onScrollIndex,minHeight:e=>(o?DB(e):0)+OB,children:r=>(0,B.jsx)(ZE,{model:e,view:t,display:n,row:uh(e,r)})})},AB=`protobase:list-places`,jB=50,MB=(e,t)=>`${e} ${t}`,NB=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},PB=e=>Ie(()=>{let t=e.getItem(AB);if(t===null)return[];let n=JSON.parse(t);return Array.isArray(n)?n.filter(NB):[]},[]),FB=e=>{let t=new Map(PB(e).map(e=>[MB(e.entry,e.url),e]));return{placeOf:(e,n)=>{let r=t.get(MB(e,n));return r?r.place:[...t.values()].findLast(e=>e.url===n)?.place??0},save:(e,n,r)=>{let i=MB(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-jB)))t.delete(e)},persist:()=>Ie(()=>e.setItem(AB,JSON.stringify([...t.values()])),void 0)}},IB={getItem:()=>null,setItem:()=>{}},LB,RB=()=>LB??=FB(Ie(()=>window.sessionStorage,void 0)??IB),zB=()=>{let{entry:e,path:t,params:n}=jh(),r=`${t}?${n.toString()}`,i=RB();(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}},BB=e=>e.reduce((e,t)=>e+t.count,0),VB=e=>{let t=Math.floor(e.length/2),n=BB(e.slice(0,t)),r=BB(e.slice(e.length-t));return n===0?0:(r-n)/n*100},HB=({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:cp(r.at)}),(0,B.jsxs)(`div`,{className:`font-semibold tabular-nums`,children:[wp(r.count),` `,n]})]})},UB=M(`activity-chart`),WB={fontSize:11,fill:`var(--muted-foreground)`},GB=({title:e,noun:t,defaultGranularity:n=`day`,data:r,granularity:i,onGranularityChange:o,periodLabel:s,className:l})=>{let[u,d]=(0,I.useState)(n),f=i??u,m=o??d,h=hf(`(min-width: 640px)`),_=VB(r);return(0,B.jsxs)(`section`,{className:P(`rounded-lg border bg-background px-4 pb-2 pt-3`,l),children:[(0,B.jsxs)(`header`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,B.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,B.jsx)(`h2`,{className:`font-semibold`,children:e}),(0,B.jsx)(`span`,{className:`font-semibold tabular-nums`,children:wp(BB(r))}),(0,B.jsxs)(`span`,{className:P(`text-xs font-medium tabular-nums`,_>=0?`text-success-text`:`text-danger-text`),children:[_>=0?`+`:`−`,Math.abs(_).toFixed(1),`%`]}),(0,B.jsx)(`span`,{className:`hidden text-xs text-muted-foreground sm:inline`,children:s??`last ${f===`day`?`30 days`:`12 weeks`}`})]}),(0,B.jsx)(Re,{value:f,onChange:m,options:[{value:`day`,label:UB(`day`)},{value:`week`,label:UB(`week`)}]})]}),(0,B.jsx)(`div`,{className:`mt-2 h-24`,children:(0,B.jsx)(g,{width:`100%`,height:`100%`,children:(0,B.jsxs)(c,{data:r,margin:{top:4,right:0,bottom:0,left:0},barCategoryGap:f===`day`?`22%`:`30%`,children:[(0,B.jsx)(v,{vertical:!1,stroke:`var(--border)`}),(0,B.jsx)(a,{dataKey:`at`,padding:{left:4,right:h?4:18},tickFormatter:lp,tick:WB,axisLine:!1,tickLine:!1,interval:f===`day`?h?4:9:h?1:3,height:18}),(0,B.jsx)(pe,{width:h?36:28,tick:WB,axisLine:!1,tickLine:!1,tickCount:3}),(0,B.jsx)(p,{cursor:{fill:`var(--muted)`},content:(0,B.jsx)(HB,{noun:t}),isAnimationActive:!1}),(0,B.jsx)(fe,{dataKey:`count`,fill:`var(--primary)`,radius:[2,2,0,0],isAnimationActive:!1})]})})})]})},KB={"7d":`last 7 days`,"30d":`last 30 days`,"90d":`last 90 days`,"1y":`last year`,all:`all time`},qB=({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=Iy(e,{field:t.field,range:s,granularity:a,filter:i,timeZone:Gf()}).data?.points.map(e=>({at:Date.parse(`${e.bucket}Z`),count:e.count}))??[];return(0,B.jsx)(GB,{title:n,noun:r,data:c,granularity:a,onGranularityChange:o,periodLabel:a===`week`?`last 12 weeks`:KB[s]})},JB=(e,t,n)=>{let r=e.sum??e.average;if(r===void 0)return n;let i=t?.fields[r]?.label??F(r);return e.sum===void 0?q(`average`,{label:i}):`${i}`},YB=({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":`${JB(n,t,r)} by ${a.toLowerCase()}`,children:[(0,B.jsxs)(`h2`,{className:`mb-2 font-semibold`,children:[JB(n,t,r),` by `,a.toLowerCase()]}),(0,B.jsx)(vb,{model:e,view:t,groupBy:n.groupBy,type:n.type,sum:n.sum,average:n.average,limit:n.limit,filter:i})]})},XB=({value:e,onCommit:t,placeholder:n,className:r})=>{let[i,a]=(0,I.useState)(e);return(0,I.useEffect)(()=>a(e),[e]),(0,I.useEffect)(()=>{if(i===e)return;let n=setTimeout(()=>t(i),350);return()=>clearTimeout(n)},[i,e,t]),(0,B.jsx)(J,{wrapperClassName:P(`min-w-0 flex-1 sm:w-72 sm:flex-initial`,r),leading:(0,B.jsx)(ss,{className:`size-4`}),placeholder:n,"aria-label":fB(`search`),value:i,onChange:e=>a(e.target.value),onKeyDown:e=>e.key===`Enter`&&t(i)})},ZB=e=>new Set((e.userMenu?.items??[]).flatMap(e=>e.kind===`resource`?[e.resource]:e.kind===`page`?[e.page]:[])),QB=(e,t,n)=>(e.userMenu?.items??[]).map((r,i)=>{if(r.kind===`link`)return{id:`link-${i}`,label:r.label,icon:xL(r.icon,ua),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:xL(r.icon??i?.icon,Ha),href:Bc({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:xL(r.icon,SL(e,r.resource)),href:Bc({kind:`list`,resource:r.resource},t),active:r.resource===n}}),$B=(e,t)=>t===void 0?e:`${e}/${t}`,eV={sales:`sales`,crm:`crm`,catalog:`catalog`,inventory:`inventory`,core:`admin`,hr:`hr`},tV=(e=`public`)=>e===`public`?``:eV[e]?q(eV[e]):F(e),nV=(e,t,n,r,i)=>!n?.create||!$L(t,e.pages,e.permissions[t.resource]??Ud)?{}:{create:{label:n.create===!0?Dg(`title`,{noun:r}):n.create.label,href:Bc({kind:`create`,resource:t.resource},i)}},rV=(e,t=``,n={})=>{let r=new Map,i=new Map,a=ZB(e);for(let n of Object.values(e.pages)){if(n.nav?.hidden||a.has(n.name))continue;let e=n.nav?.group??q(`pages`),o=r.get(e)??{label:e,items:[]};o.items.push({id:n.name,label:n.title,icon:xL(n.icon,Ha),href:Bc({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??tV(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:$B(o.name),label:s.names?.plural??F(o.name),icon:SL(e,o.name),href:Bc({kind:`list`,resource:o.name},t),...n[o.name]&&{recent:n[o.name]},...nV(e,s,s.nav,s.names?.singular??F(o.name),t)},s.nav?.order);for(let n of s.lists??[])n.nav?.hidden||l(n.nav?.group??c,{id:$B(o.name,n.name),label:n.names.plural,icon:SL(e,o.name),href:Bc({kind:`list`,resource:o.name,list:n.name},t),...nV(e,s,n.nav,n.names.singular,t)},n.nav?.order)}for(let n of Object.values(e.signIn??{})){if(n.nav?.hidden||a.has(n.resource))continue;let o=n.nav?.group??q(`account`),s=r.get(o)??{label:o,items:[]};s.items.push({id:n.resource,label:n.names?.plural??F(n.resource),icon:SL(e,n.resource),href:Bc({kind:`list`,resource:n.resource},t)}),r.set(o,s),i.set(n.resource,n.nav?.order??2**53-1)}for(let n of e.sources??[]){if(n.state!==`error`)continue;let e=r.get(n.source.label)??{label:n.source.label,items:[]};for(let r of n.source.resources)e.items.push({id:r,label:F(r),icon:Ls,href:Bc({kind:`list`,resource:r},t),problem:q(`cannotReach`,{label:n.source.label})});r.set(n.source.label,e)}return[...r.values()].map(e=>({...e,items:[...e.items].sort((e,t)=>(i.get(e.id)??0)-(i.get(t.id)??0))}))},iV=(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 Tr(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:Jp(c,!1),sortable:!1,render:e=>(0,B.jsx)(AE,{column:n,records:e[n.name]??[],target:s,view:i[s.name],Card:ZE})}]})},aV=({model:e,view:t,target:n,children:r})=>{let i=pE(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)(SS,{title:a,subtitle:t.help}),e]});if(i.error)return o((0,B.jsx)(Bg,{title:mE(`couldNotLoadYour`,{plural:a.toLowerCase()}),error:i.error}));if(!i.data)return o((0,B.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(15rem,1fr))] gap-3`,children:Array.from({length:3},(e,t)=>(0,B.jsx)(vh,{className:`h-24`},t))}));let s=dE(n,i.data);return s?r(s):o((0,B.jsx)(`p`,{className:`py-8 text-center text-muted-foreground`,children:mE(`noneYet`,{plural:a.toLowerCase()})}))},oV=({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)(Ef,{open:!0,title:e,onClose:s,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:s,children:Y(`cancel`)}),(0,B.jsx)(G,{type:`submit`,form:d,variant:`primary`,loading:a,children:Y(`save`)})]}),children:(0,B.jsxs)(`form`,{id:d,className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),o(l.trim()===``?null:l.trim())},children:[t.length>0&&(0,B.jsx)(Dw,{chips:t}),(0,B.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,B.jsxs)(`div`,{className:`flex items-baseline justify-between gap-2`,children:[(0,B.jsx)(`label`,{htmlFor:c,className:`font-medium`,children:n}),!r&&(0,B.jsx)(`span`,{id:`${c}-hint`,className:`text-xs text-muted-foreground`,children:Y(`optional`)})]}),(0,B.jsx)(J,{id:c,value:l,required:r,pattern:r?`.*\\S.*`:void 0,"aria-describedby":r?void 0:`${c}-hint`,autoFocus:!0,autoComplete:`off`,onChange:e=>u(e.target.value)})]})]})})},sV=sn(),cV={start:0,end:0},lV=(e,t)=>sV.and(t,{kind:`present`,field:e.field,span:cV}),uV=e=>{switch(e.kind){case`and`:case`or`:return{...e,args:e.args.map(uV)};case`not`:return dV(e.arg);case`search`:case`present`:case`isNull`:return e;default:return lV(e,e)}},dV=e=>{switch(e.kind){case`and`:return sV.or(...e.args.map(dV));case`or`:return sV.and(...e.args.map(dV));case`not`:return uV(e.arg);case`search`:case`present`:case`isNull`:return sV.not(e);default:return lV(e,sV.not(e))}},fV=e=>{let t=it(e);if(!t.ok)throw Error(`The filter cannot be read: ${t.errors.map(e=>e.message).join(`; `)}`);return t.ast},pV=(e,t)=>{let n=fV(e);if(!n)return null;let r=fV(t),i=sV.not(uV(n));return Yt(r?sV.and(r,i):i)},mV=(e,t)=>pV(t,e),hV=e=>e.key.startsWith(`extra:`)?`extra:${e.label}`:e.key,gV=(e,t)=>{let n=new Map(e.map(e=>[hV(e),e])),r=new Map(t.map(e=>[hV(e),e])),i=e.filter(e=>!r.has(hV(e))).map(e=>({kind:`removed`,label:e.label})),a=t.flatMap(e=>{let t=n.get(hV(e));return t&&t.label!==e.label?[{kind:`changed`,label:e.label,before:t.label}]:[]}),o=t.filter(e=>!n.has(hV(e))).map(e=>({kind:`added`,label:e.label}));return[...i,...a,...o]},_V=(e,t,n,r)=>{let i=e-t;if(i===0)return Y(`asMany`,{plural:r});let a=Math.abs(i)===1?n:r;return i>0?Y(`more`,{count:i,noun:a}):Y(`fewer`,{count:-i,noun:a})},vV=12,yV={added:{word:`added`,className:`text-success-text`},removed:{word:`removed`,className:`text-danger-text`},changed:{word:`changed`,className:`text-primary-text`}},bV=({changes:e})=>(0,B.jsx)(`ul`,{"aria-label":Y(`filterChanges`),className:`divide-y rounded-md border`,children:e.map(e=>(0,B.jsxs)(`li`,{className:`grid grid-cols-[72px_1fr] gap-3 px-3 py-2`,children:[(0,B.jsx)(`span`,{className:`font-medium ${yV[e.kind].className}`,children:Y(yV[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}`))}),xV=(e,t)=>{let n=E({...yy(U(),e,t??``),enabled:t!==null});return t===null?0:n.data},SV=(e,t,n)=>`${e} ${e===1?t:n}`,CV=({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>vV&&(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:Y(`firstOf`,{limit:vV,total:i})}),r===null||i===0?(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:Y(`noPlural`,{plural:a})}):(0,B.jsx)(OA,{model:e,view:t,filter:r,sort:dh(e,t),limit:vV,display:o?.name??`table`,row:!0,link:!1,empty:`No ${a}.`})]})},wV=({model:e,view:t,title:n,before:r,after:i,saveNewLabel:a,updating:o,creating:s,onUpdate:c,onSaveNew:l,onCancel:u})=>{let d=gV(YT(e,r),YT(e,i)),f=(0,I.useMemo)(()=>pV(r,i),[r,i]),p=(0,I.useMemo)(()=>mV(r,i),[r,i]),m=xV(e,f),h=xV(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)(Ef,{open:!0,wide:!0,title:n,onClose:u,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:u,children:Y(`cancel`)}),(0,B.jsx)(G,{loading:s,disabled:o,onClick:l,children:a}),(0,B.jsx)(G,{variant:`primary`,loading:o,disabled:s,onClick:c,children:Y(`update`)})]}),children:(0,B.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[d.length>0&&(0,B.jsx)(bV,{changes:d}),v?(0,B.jsxs)(`p`,{children:[(0,B.jsx)(`span`,{className:`font-semibold`,children:_V(m,h,g,_)}),(0,B.jsxs)(`span`,{className:`text-muted-foreground`,children:[`: `,Y(`addedRemoved`,{added:SV(m,g,_),removed:h})]})]}):(0,B.jsx)(vh,{className:`h-4 w-48`}),(0,B.jsx)(CV,{model:e,view:t,title:Y(`added`),filter:f,total:m,plural:_}),(0,B.jsx)(CV,{model:e,view:t,title:Y(`removed`),filter:p,total:h,plural:_})]})})},TV=()=>{let{address:e,set:t}=Hh();return{key:e?.kind===`list`?e.savedSearch:void 0,open:e=>t({savedSearch:e})}},EV=e=>e instanceof Error?e.message:Y(`somethingWrong`),DV=(e,t)=>{let n=W(),r=U(),i=iy(),a=Cy(),{href:s,open:c}=Hh(),l=TV(),{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&&oy(p,`create`)&&oy(p,`delete`),h=n.signIn?.[u]?.signIn,g=mD(u,m),_=e=>Nn(ym(d,e)),v=f&&g.data?.find(e=>e[f.filter]===t),y=v||l.key===void 0||!p||!oy(p,`update`)?void 0:g.data?.find(e=>_(e)===l.key),b=n.views[u]?.names,x=b?.plural??`saved searches`,S=f?.name===void 0?void 0:d?.fields[f.name],C=o({mutationFn:e=>r.create(u,{[f.filter]:t,...f.name&&{[f.name]:e}}),onSuccess:e=>{l.open(_(e.record)),i.show({state:`success`,title:Y(`searchSaved`),action:{label:Y(`openPlural`,{plural:x}),href:s({kind:`list`,resource:u}),onNavigate:c}})},onError:e=>i.show({state:`error`,title:Y(`couldNotSave`),description:EV(e)}),onSettled:()=>a(u)}),w=o({mutationFn:e=>r.remove(u,_(e)),onError:e=>i.show({state:`error`,title:Y(`couldNotTakeOff`),description:EV(e)}),onSettled:()=>a(u)}),T=o({mutationFn:e=>r.update(u,_(e),{[f.filter]:t},e.etag??`*`),onSuccess:()=>i.show({state:`success`,title:Y(`searchUpdated`)}),onError:e=>i.show({state:`error`,title:Y(`couldNotUpdate`),description:EV(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)}},OV=({model:e,view:t,search:n,filter:r,chips:i,className:a})=>{let o=DV(n,r),[s,c]=(0,I.useState)(!1),[l,u]=(0,I.useState)(!1),[d,f]=(0,I.useState)();if(!o.mode)return null;let p=n.label??Y(`saveSearch`);if(o.mode===`sign-in`)return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(G,{className:a,"aria-haspopup":`dialog`,onClick:()=>c(!0),children:[(0,B.jsx)(ui,{className:`size-3.5`,"aria-hidden":!0}),p]}),(0,B.jsx)(iE,{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)(oV,{title:d,chips:i,label:o.naming.label,required:o.naming.required,busy:o.creating,onSave:e=>o.saveNew(e,{onSuccess:()=>f(void 0)}),onClose:()=>f(void 0)}),g=o.opened;if(g){let n=Y(`saveAsNew`,{noun:o.noun});return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(G,{className:a,"aria-haspopup":`dialog`,"aria-disabled":!o.ready,onClick:()=>o.ready&&u(!0),children:[(0,B.jsx)(ts,{className:`size-3.5`,"aria-hidden":!0}),(0,B.jsx)(`span`,{className:`max-w-60 truncate`,children:Y(`updateName`,{name:g.name??o.noun})})]}),(0,B.jsxs)(G,{className:a,"aria-haspopup":o.naming?`dialog`:void 0,"aria-disabled":!o.ready,onClick:()=>o.ready&&m(n),children:[(0,B.jsx)(ci,{className:`size-3.5`,"aria-hidden":!0}),n]}),l&&(0,B.jsx)(wV,{model:e,view:t,title:g.name?Y(`updateNameQuestion`,{name:g.name}):Y(`updateNounQuestion`,{noun:o.noun}),before:g.filter,after:r,saveNewLabel:n,updating:o.updating,creating:o.creating,onUpdate:()=>o.update({onSuccess:()=>u(!1)}),onSaveNew:()=>m(n),onCancel:()=>u(!1)}),h]})}let _=o.saved?oi:ui;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]})},kV=e=>e instanceof Error?e.message:Y(`somethingWrong`),AV=({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)(Vg,{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:ir(e,s?.valueLabels)},e))})]})},jV=(e,t,n)=>Object.entries(n).map(([n,r])=>`${t.fields[n]?.label??F(n)}: ${e.fields[n]?.type===`boolean`?Y(r===!0?`on`:`off`):ir(String(r),t.fields[n]?.valueLabels)}`).join(`, `),MV=({model:e,view:t,recordKey:n,title:r,row:i,fields:a})=>{let s=U(),c=iy(),l=Cy(),u=o({mutationFn:t=>s.update(e.name,n,t,i.etag??`*`),onSuccess:(n,i)=>c.show({state:`success`,title:Y(`saved`,{title:r}),description:jV(e,t,i)}),onError:e=>c.show({state:`error`,title:Y(`couldNotChange`),description:kV(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)(AV,{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))})},NV=e=>e instanceof Error?e.message:Y(`somethingWrong`),PV=({model:e,view:t,of:n,target:r,targetView:i,row:a,recordKey:s,canRename:c,onDelete:l})=>{let u=U(),d=iy(),f=Cy(),[p,m]=(0,I.useState)(!1),{name:h,chips:g,title:_,body:v}=hD({model:e,of:n,target:r,targetView:i,row:a,recordKey:s}),y=o({mutationFn:t=>u.update(e.name,s,{[n.name]:t},a.etag??`*`),onSuccess:()=>m(!1),onError:e=>d.show({state:`error`,title:Y(`couldNotRename`),description:NV(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)(Uh,{to:{kind:`record`,resource:e.name,key:s},className:`hover:underline`,children:h??(0,B.jsx)(Ow,{chips:g})})})}),(0,B.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[n.controls&&(0,B.jsx)(MV,{model:e,view:t,recordKey:s,title:_,row:a,fields:n.controls}),c&&b&&(0,B.jsx)(G,{variant:`ghost`,"aria-label":Y(`renameTitle`,{title:_}),"aria-haspopup":`dialog`,onClick:()=>m(!0),children:(0,B.jsx)(Lo,{className:`size-3.5`,"aria-hidden":!0})}),l&&(0,B.jsx)(G,{variant:`ghost`,"aria-label":Y(`deleteTitle`,{title:_}),onClick:()=>l(_),children:(0,B.jsx)(qs,{className:`size-3.5`,"aria-hidden":!0})})]})]}),p&&b&&(0,B.jsx)(oV,{title:Y(`renameTitle`,{title:_}),chips:g,label:t.fields[b.name]?.label??F(b.name),required:!b.nullable,initial:h,busy:y.isPending,onSave:e=>y.mutate(e),onClose:()=>m(!1)}),(0,B.jsx)(dD,{...v})]})},FV=({model:e,view:t})=>{let{resources:n,views:r}=W(),i=t.searchesOf,a=n[i.resource],o=r[i.resource],s=mD(e.name,!0),c=af(e.name),l=ZL({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)(SS,{title:u,subtitle:t.help}),e]});if(!a)return d((0,B.jsx)(tf,{title:Y(`notFound`),children:Y.rich(`noResource`,{resource:i.resource})}));if(s.error)return d((0,B.jsx)(Bg,{title:Y(`couldNotLoadYour`,{plural:u.toLowerCase()}),error:s.error}));if(!s.data)return d((0,B.jsx)(`div`,{className:`flex flex-col gap-3`,children:Array.from({length:2},(e,t)=>(0,B.jsx)(vh,{className:`h-56`},t))}));if(s.data.length===0){let e=(o?.names?.plural??F(a.name)).toLowerCase();return d((0,B.jsx)(`p`,{className:`py-8 text-center text-muted-foreground`,children:Y.rich(`noSavedYet`,{plural:u.toLowerCase(),list:(0,B.jsx)(Uh,{to:{kind:`list`,resource:a.name},className:`font-medium text-primary-text hover:underline`,children:e})})}))}return d((0,B.jsx)(`div`,{className:`flex flex-col gap-4`,children:s.data.map(n=>{let r=Nn(ym(e,n)),s=oy(c,`delete`)?e=>void l.start({key:r,title:e,etag:n.etag,snapshot:n}):void 0;return(0,B.jsx)(PV,{model:e,view:t,of:i,target:a,targetView:o,row:n,recordKey:r,canRename:oy(c,`update`),onDelete:s},r)})}))},IV=({field:e,hints:t,resource:n,stored:r,onSave:i,close:a})=>{let[o,s]=(0,I.useState)(()=>xg(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&&Sg(e,s,r)&&i(yg(e,s)),a(n))};return(0,B.jsx)(`div`,{ref:c,className:`w-full min-w-0`,onKeyDown:e=>{wv(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)&&!wv(e.relatedTarget)&&d(!0)},children:(0,B.jsx)(Ov,{field:e,hints:t,value:o,stored:r,resource:n,onChange:e=>{s(e),u&&d(!0,void 0,e)}})})},LV=M(`app/list-edit`),RV=e=>{let t=U(),n=Se(),r=iy(),[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=ym(e,i),u=String(o.current.get(i.id)?.etag??i.etag);try{let r=await t.update(e.name,l,{[a]:s},u);c(i.id,{[a]:r.record[a],etag:r.etag}),n.setQueryData(H.record(e.name,Nn(l)),r),n.invalidateQueries({queryKey:[`page`,e.name]}),n.invalidateQueries({queryKey:[`list`,e.name]}),n.invalidateQueries({queryKey:[`map`,e.name]})}catch(n){if(!pl(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:LV(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}}},zV=(e,t,n)=>{let r=RV(e),i=t?.list?.editable??[];return{editor:i.length>0&&oy(n,`update`)?{editable:(t,n)=>i.includes(n)&&e.fields[n]!==void 0&&mg(e.fields[n])&&sy(t,`update`),render:(n,i,a)=>(0,B.jsx)(IV,{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}},BV=(e,t,{href:n,go:r})=>{if(`to`in e){let i=mn(e.to,t);return{href:n(i),onFollow:()=>r(i)}}let i=fy(e.href,t);if(i===void 0)throw Error(`A link action without a target on the record is not shown`);return{href:i,newTab:/^https?:/i.test(i)}},VV=(e,t)=>({model:e,record:Object.fromEntries(Object.entries(uh(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}}),HV=e=>{let{views:t}=W(),n=Ty(e.name,void 0),r=Hh(),[i,a]=(0,I.useState)(),o=(t[e.name]?.actions??[]).filter(e=>!e.inputs?.length),s=e=>`row`in e?n.run(e.action,e.row):n.runEach(e.action,e.selection,e.skipped),c=e=>{e.action.confirm?a(e):s(e)};return{rowActions:o.map(t=>{let i=n=>gy(t,VV(e,n).record),a={label:e=>i(e)?.label??t.label,destructive:Wv(t)},o=t.run,s=r=>n.blockedOn(t,VV(e,r)),l=e=>i(e)!==void 0;return o?.kind===`link`?{...a,available:l,blocked:s,link:t=>BV(o,VV(e,t).record,r)}:{...a,available:l,blocked:s,onSelect:n=>c({action:t,row:VV(e,n)})}}),bulkActions:o.filter(e=>e.bulk&&e.run?.kind!==`link`).map(t=>({label:e=>fB(`actionCount`,{label:t.label,count:e}),destructive:Wv(t),available:r=>n.appliesOn(t,VV(e,r)),onRun:(n,r)=>c({action:t,selection:n.map(t=>VV(e,t)),skipped:r})})),prompt:i&&(0,B.jsx)(Uv,{action:i.action,label:i.action.label,danger:Wv(i.action),onCancel:()=>a(void 0),onConfirm:()=>{a(void 0),s(i)}})}},UV=(e,t,n)=>({order:r,index:i})=>{let a=t=>r.findIndex(n=>Nn(ym(e,n))===t),o=t.after.find(e=>a(e.key)>i);if(o)return sO(`dependsOn`,{record:n,other:o.title});let s=t.before.find(e=>a(e.key)!==-1&&a(e.key)<i);return s?sO(`dependsOn`,{record:s.title,other:n}):void 0},WV=(e,t,n,r)=>{let i=e[t],a;for(let o=n;o<e.length;o++){let n=r({record:i,order:ee(e,t,o),index:o});if(n===void 0)return{to:o,...a!==void 0&&{reason:a}};a??=n}return{to:t,reason:a}},GV=({model:e,view:t,field:n,filter:r,fields:i,rule:a})=>{let o=U(),s=iy(),c=Cy(),{resources:l,views:u}=W(),d=`${n} asc`,f=E({queryKey:[...H.list(e.name,r,d,500,`hand-order`),i.join(`,`)],queryFn:async()=>{let t=Cb(l,u,e,i),n=[],a=``;do{let s=await o.search(e.name,{filter:r||void 0,orderBy:d,pageSize:500,labels:t,...a&&{pageToken:a}});n.push(...wb(l,e,i,s.items,s.labels).map((t,n)=>({...t,id:vm(e,s.items[n])}))),a=s.nextPageToken}while(a);return n}}),[p,m]=(0,I.useState)(),h=(0,I.useRef)(void 0),g=(0,I.useRef)(void 0),_=(0,I.useRef)(Promise.resolve()),v=(0,I.useRef)(0),y=(0,I.useRef)(void 0),b=async()=>{let t=h.current,r=g.current;if(g.current=void 0,!t||!r)return;let i=tO(t.map(e=>e[n]),r.first,r.last),a=t.slice(i.first,i.last+1),c=Object.fromEntries(a.flatMap(t=>typeof t.etag==`string`?[[Nn(ym(e,t)),t.etag]]:[])),l=(await o.batchWrite([{op:`reorder`,resource:e.name,field:n,keys:a.map(t=>ym(e,t)),start:i.start,etags:c}])).results[0];if(l?.op!==`reorder`)return;let u=new Map(a.map(e=>[e.id,{[n]:e[n]}])),d=XD(e,l.records.map(t=>({...t,before:u.get(vm(e,t.record))??{}})),[n]);if(y.current!==void 0&&s.dismiss(y.current),y.current=s.show({state:`success`,title:YD(`orderChanged`),action:{label:YD(`undo`),onClick:()=>D(d)}}),!h.current)return;let f=new Map(l.records.map(t=>[vm(e,t.record),t]));h.current=h.current.map(e=>{let t=f.get(e.id);return t?{...e,[n]:t.record[n],etag:t.etag}:e})},x=e=>t=>{h.current=void 0,g.current=void 0,m(void 0),s.show({state:`error`,title:e,description:Um(t)})},S=async()=>{--v.current,!(v.current>0)&&(await c(e.name),!(v.current>0)&&(h.current=void 0,m(void 0)))},C=(n,r)=>{let i=h.current??f.data;if(!i||n===r)return;if(!e.position?.after)return w(i,n,r,a);let s=uh(e,i[n]).record,c=i[n].id;$D(o,e,t,s).then(n=>{let i=h.current??f.data,o=UV(e,n,lr(e,t,s,c));w(i,i.findIndex(e=>e.id===c),r,e=>o(e)??a?.(e))},x(YD(`couldNotChange`)))},w=(e,t,n,r)=>{if(t===-1||t===n)return;let i=r?T(e,t,n,r):n;if(t===i)return;h.current=ee(e,t,i);let a=Math.min(t,i),o=Math.max(t,i);g.current=g.current?{first:Math.min(g.current.first,a),last:Math.max(g.current.last,o)}:{first:a,last:o},m(h.current),v.current+=1,_.current=_.current.then(b).catch(x(YD(`couldNotChange`))).then(S)},T=(t,n,r,i)=>{let a=WV(t.map(t=>uh(e,t).record),n,r,i);return a.reason!==void 0&&s.show({state:`warning`,title:a.to===n?YD(`notMoved`):YD(`movedToPlace`,{place:a.to+1}),description:a.reason}),a.to},D=e=>{y.current!==void 0&&s.dismiss(y.current),y.current=void 0,v.current+=1,_.current=_.current.then(async()=>{await o.batchWrite(e),h.current=void 0,g.current=void 0,m(void 0)}).catch(x(YD(`couldNotUndo`))).then(S)};return{rows:p??f.data,loading:f.isPending,error:f.error,move:C}},KV=({model:e,view:t,field:n,filter:r,columns:i,sort:a})=>{let{resources:o,views:s}=W(),{fields:c,dropRules:l}=c_(),{go:u,href:d}=Hh(),f=a!==void 0,p=(0,I.useMemo)(()=>yA(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)(()=>sh(e,t,p.map(e=>e.id)),[e,t,p]),h=t?.list?.drag?.rule,g=h===void 0?void 0:l?.[h],_=GV({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)(ov,{children:YD.rich(`noRule`,{rule:h})});if(_.loading)return(0,B.jsx)(`div`,{className:`flex flex-col gap-2`,children:Array.from({length:3},(e,t)=>(0,B.jsx)(vh,{className:`h-4 w-full`},t))});if(_.error)return(0,B.jsx)(Bg,{title:YD(`couldNotLoad`),error:_.error});if(!y||y.total===0)return(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:YD(`nothingYet`)});let b=t=>u({kind:`record`,resource:e.name,key:ym(e,t)});return(0,B.jsx)(mw,{fit:!0,scroll:`parent`,columns:p,source:y,latencyMs:0,onOpenRow:b,rowLink:t=>({href:d({kind:`record`,resource:e.name,key:ym(e,t)}),onFollow:()=>b(t)}),...a&&{sort:a.value,onSortChange:a.onChange},rowNumbers:!1,reorder:{label:n=>lr(e,t,n,n.id),onMove:_.move}})},qV=({sorting:e,onChange:t,size:n,iconOnly:r=!1})=>{let i=YD(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)(Si,{className:`size-3.5`}):(0,B.jsx)(Br,{className:`size-3.5`}),!r&&i]})},JV=sn(),YV=e=>e.find(e=>e.kind===`search`),XV=({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)(iE,{as:`page`,prompt:a.signIn}):(0,B.jsx)(tf,{title:q(`notFound`),children:q(`noResource`,{name:e.resource})});let o=Cn(n[e.resource],e.list);if(e.list!==void 0&&!o)return(0,B.jsx)(tf,{title:q(`notFound`),children:fB(`noList`,{name:e.list})});if(o?.searchesOf)return(0,B.jsx)(FV,{model:i,view:o});let s=mh(t,n,e.resource,e.list);if(o&&s.listOf){let t=s.model;return(0,B.jsx)(aV,{model:i,view:o,target:t,children:n=>(0,B.jsx)(ZV,{model:t,address:e,scope:n,heading:{title:o.names?.plural??F(i.name),subtitle:o.help}})})}return(0,B.jsx)(ZV,{model:i,address:e})},ZV=({model:e,address:t,scope:n,heading:r})=>{let i=W(),{set:a,listTo:o,go:s,href:c}=Hh(),l=e.name,u=Cn(i.views[l],t.list),d=(0,I.useMemo)(()=>RT(u,e),[u,e]),{fields:f}=c_(),p=(0,I.useMemo)(()=>iV(hA(fA(jm(e,u),e,u,f),e,i.resources,i.views),e,u,i.resources,i.views),[e,u,f,i.resources,i.views]),m=t.filter,h=(0,I.useMemo)(()=>MT(d,m),[d,m]),g=h.ok?h.state:Lw,_=h.ok?h.extras:[],{orderBy:v,filterLayout:y}=t,b=gf(),x=_f(),[S,C]=(0,I.useState)(!1),w=n?[..._,n]:_,T=p_(),E=BL({model:e,resources:i.resources,views:i.views,view:u,state:g,extras:w,titleOf:T}),D=n?TT(d,g,w):h.ok?m:``,O=(0,I.useMemo)(()=>sh(e,u,p.map(e=>e.id)),[e,u,p]),k=(0,I.useMemo)(()=>xE(u,i.resources,i.views,O),[u,i.resources,i.views,O]),A=Tw({resources:i.resources,views:i.views,model:e,columns:O,filter:D,orderBy:v,related:k}),j=Xm(e,u,t.display),ee=af(l),te=n?void 0:AD(e,ee),[ne,re]=(0,I.useState)(!1),ie=ne&&te!==void 0,ae=!j&&!ie&&MD(u,te,v,D),oe=ie||j?.kind!==`map`;vx(oe);let se=zD(e,A.page,A.key,j?.kind===`custom`),ce=zB(),le=cr(e,u),ue=e=>({key:e.id,title:String(typeof e[le]==`object`?e[le].name:e[le]??e.id),etag:typeof e.etag==`string`?e.etag:void 0,snapshot:e}),de=u?.names?.singular??F(l),fe=zV(e,u,ee),{state:pe}=V(),me=ZL({model:e,view:u,restore:QL(e),onReview:e=>s({kind:`record`,resource:l,key:e.key})}),he=HV(e),ge=u?.actions.some(e=>e.run?.kind===`delete`)??!1,_e=(e,t=_)=>a({filter:TT(d,e,t)}),ve=YV(_),ye=e=>{let t=_.filter(e=>e.kind!==`search`);_e(g,e?[...t,JV.search(e)]:t)},be=u?.names?.plural??F(l),xe=j?.kind===`calendar`||j?.kind===`timeline`||j?.kind===`board`&&Bm(e)?void 0:j,Se=xe&&(0,B.jsx)(dA,{model:e,view:u,display:xe,orderBy:v,onChange:e=>a({orderBy:e})}),Ce=e.search?.length?(0,B.jsx)(XB,{value:ve?.kind===`search`?ve.text:``,onCommit:ye,placeholder:fB(`searchPlural`,{plural:be}),className:b?void 0:`min-h-11`}):null,we=(0,B.jsx)(pT,{layout:y,config:E,value:g,onChange:_e,leading:y===`bar`?Se:void 0,trailing:Ce}),Te=y===`bar`?we:(0,B.jsx)(dT,{groups:[Se?[Se]:[]],trailing:Ce}),Ee=Hw(E,g),De=(0,B.jsx)(Mw,{scroll:!0,chips:Ee,onRemove:e=>_e(Uw(g,e)),onClear:()=>_e(Lw)}),Oe=xe&&(0,B.jsx)(Xw,{title:fB(`sort`),children:(0,B.jsx)(dA,{model:e,view:u,display:xe,orderBy:v,onChange:e=>a({orderBy:e}),className:`min-h-11 w-full`})}),ke=(0,B.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,B.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,B.jsxs)(G,{className:`min-h-11`,onClick:()=>C(!0),"aria-haspopup":`dialog`,children:[(0,B.jsx)(Cs,{className:`size-3.5`}),Ee.length>0?fB(`filtersCount`,{count:Ee.length}):fB(`filters`)]}),Ce??(0,B.jsx)(`div`,{className:`min-w-0 flex-1`,children:De})]}),Ce&&De,(0,B.jsx)(Tf,{title:fB(`filters`),open:S,onClose:()=>C(!1),children:(0,B.jsx)(pT,{layout:`panel`,fullWidth:!0,config:E,value:g,onChange:_e,leading:Oe})})]}),Ae=!n&&$L(u,i.pages,ee)&&(0,B.jsxs)(Uh,{to:{kind:`create`,resource:l},className:mf({variant:`primary`}),children:[(0,B.jsx)(qo,{className:`size-3.5`}),fB(`newRecord`,{singular:de})]}),je=u?.saveSearch&&!n&&h.ok&&m&&(0,B.jsx)(OV,{model:e,view:u,search:u.saveSearch,filter:m,chips:GT(e,u,m,KT(E))}),Me=!n&&(0,B.jsx)(Ez,{model:e}),Ne=dB({model:e,view:u,resources:i.resources,views:i.views,plural:be,filter:D,orderBy:v}),M=Iz(u)&&(0,B.jsxs)(G,{onClick:()=>Ne.open(),...!b&&{"aria-label":fB(`export`),title:fB(`export`)},children:[(0,B.jsx)(na,{className:`size-3.5`}),b&&fB(`export`)]}),Pe=te&&!ae&&(0,B.jsx)(qV,{sorting:ie,onChange:re,iconOnly:!b}),Fe=t=>!ie&&(0,B.jsx)(lA,{view:u,choices:eh(e,u,x),value:j?.name??`table`,onChange:e=>a({display:e}),menu:t}),Ie=ZT(e),Le=t=>{Ie(uh(e,t).record),s({kind:`record`,resource:l,key:ym(e,t)})},Re=A.source?(0,B.jsx)(mw,{columns:p,source:A.source,sort:fh(v),onSortChange:e=>a({orderBy:ph(e)}),onOpenRow:Le,rowLink:t=>({href:c({kind:`record`,resource:l,key:ym(e,t)}),onFollow:()=>Le(t)}),cellEditor:fe.editor,rowPatches:fe.patches,initialScrollIndex:ce.initialIndex,onScrollIndex:ce.remember,rowActions:[{label:fB(`openRecord`,{singular:de}),onSelect:Le},...he.rowActions,...oy(ee,`delete`)&&!ge?[{label:fB(`delete`),destructive:!0,available:e=>sy(e,`delete`),onSelect:e=>void me.start(ue(e))}]:[]],bulkActions:[...Iz(u)&&Hz(e)?[{label:e=>fB(`exportCount`,{count:e}),onRun:e=>Ne.open(e)}]:[],...he.bulkActions,...oy(ee,`delete`)?[{label:e=>fB(`deleteCount`,{count:e}),destructive:!0,onRun:e=>me.startBulk(e.map(ue))}]:[]],rowNumbers:!1,pinKey:pe.kind===`signed-in`?mC(pe.user.id,$B(l,t.list)):void 0,scroll:`parent`,className:`flex-1`}):(0,B.jsx)(`div`,{className:`flex-1 rounded-lg border bg-surface`}),N={...A,initialIndex:ce.initialIndex,onScrollIndex:ce.remember},ze=mB({plural:be,search:ve?.kind===`search`?ve.text:``,filtered:Ee.length>0,scoped:!!n||_.some(e=>e.kind!==`search`),canCreate:!!Ae}),Be=(0,B.jsx)(pB,{state:ze,onClearSearch:()=>ye(``),onClearFilters:()=>_e(Lw),create:Ae}),Ve=ie?(0,B.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:fB(`dragToSort`)}),(0,B.jsx)(KV,{model:e,view:u,field:te,filter:``,columns:Tr(e,u)})]}):ae?(0,B.jsx)(KV,{model:e,view:u,field:te,filter:``,columns:Tr(e,u),sort:{value:fh(v),onChange:e=>a({orderBy:ph(e)})}}):j?j.kind===`cards`?(0,B.jsx)(kB,{model:e,view:u,display:j,list:N,empty:Be},A.key.join(` `)):j.kind===`map`?(0,B.jsx)(aA,{model:e,view:u,display:j,filter:D,orderBy:v,fields:O,at:t.map,onMove:e=>a({map:e}),flush:!0}):j.kind===`board`?(0,B.jsx)(fO,{model:e,view:u,display:j,fields:O,filter:D,orderBy:v}):j.kind===`calendar`?(0,B.jsx)(XO,{model:e,view:u,display:j,fields:O,filter:D,at:t.calendar,linkTo:e=>o({calendar:e})}):j.kind===`timeline`?(0,B.jsx)(_k,{model:e,view:u,display:j,fields:O,filter:D,at:t.timeline,linkTo:e=>o({timeline:e})}):(0,B.jsx)(Dk,{display:j,list:se}):A.source?.total===0&&!A.error?Be:Re;return(0,B.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 px-5 py-4`,children:[me.dialogs,Ne.dialogs,he.prompt,(0,B.jsx)(SS,{title:r?.title??be,subtitle:r?r.subtitle:u?.help,subtitleBelow:!0,actions:(0,B.jsxs)(B.Fragment,{children:[Fe(!b),Pe,je,Me,M,Ae]})}),!h.ok&&(0,B.jsx)(Bg,{title:fB(`unreadableFilter`),error:Error(h.errors.map(e=>e.message).join(`; `))}),A.error&&!j&&!ie&&(0,B.jsx)(Bg,{title:fB(`couldNotLoadRows`),error:A.error}),u?.chart&&!ie&&(An(u.chart)?(0,B.jsx)(YB,{model:e,view:u,chart:u.chart,plural:be,filter:D}):(0,B.jsx)(qB,{resource:l,chart:u.chart,title:fB(`created`,{plural:be}),noun:be.toLowerCase(),filter:D})),!ie&&(b?Te:ke),b&&y===`panel`&&!ie?(0,B.jsxs)(`div`,{className:`flex min-h-0 flex-1 gap-4`,children:[(0,B.jsx)(`div`,{className:oe?`sticky top-[calc(var(--pb-sticky-top,0px)+1rem)] flex max-h-[calc(100dvh-var(--pb-sticky-top,0px)-var(--pb-sticky-bottom,0px)-2rem)] shrink-0 self-start`:`flex shrink-0`,children:we}),Ve]}):Ve]})},QV=()=>{let e,t=new Set;return{get:()=>e,set:n=>{if(n!==e){e=n;for(let e of t)e()}},subscribe:e=>(t.add(e),()=>void t.delete(e))}},$V=(0,I.createContext)(void 0),eH=()=>()=>{},tH=()=>void 0,nH=()=>{let e=(0,I.useContext)($V);return(0,I.useSyncExternalStore)(e?.subscribe??eH,e?.get??tH,e?.get??tH)},rH=(e,t)=>e&&Object.hasOwn(e,t)?e[t]:void 0,iH=e=>e?.role===`owner`?[`owner`,`admin`,`member`]:[`admin`,`member`],aH=({member:e,current:t,status:n,presence:r,onChanged:i})=>{let{session:a,organizations:o}=V(),s=t.organization.id,{busy:c,error:l,run:u}=KA(),d=o?.roles??[],f=e.id===t.memberId,p=iH(t),m=e.role===`owner`&&t.role!==`owner`,h=d.filter(e=>e.membership);return(0,B.jsx)(vj,{name:e.name,email:e.email,self:f,error:l,...(n||r)&&{status:(0,B.jsx)(nS,{status:n,presence:r})},actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`select`,{"aria-label":X(`roleOf`,{name:e.name}),value:e.role,disabled:c||m,onChange:t=>void u(async()=>{await a.organizations.setRole(s,e.id,t.target.value),i()}),className:`h-7 rounded-md border border-border-strong bg-background px-2 text-body`,children:(m?[e.role]:p).map(e=>(0,B.jsx)(`option`,{value:e,children:ij(e)},e))}),!f&&(0,B.jsx)(G,{size:`sm`,variant:`danger`,loading:c,disabled:m,onClick:()=>void u(async()=>{await a.organizations.removeMember(s,e.id),i()}),children:X(`remove`)})]}),children:(0,B.jsx)(ZA,{roles:h,selected:e.appRoles,grantable:cj(d,t),disabled:c,onChange:t=>void u(async()=>{await a.organizations.setAppRoles(e.id,t),i()})})})},oH=({current:e,statuses:t,presence:n})=>{let{session:r}=V(),[i,a]=(0,I.useState)(),[o,s]=(0,I.useState)(),c=e?.organization?.id,l=(0,I.useCallback)(()=>{c&&r.organizations.members(c).then(a,e=>s(e instanceof wu?BA(e):X(`couldNotReadMembers`)))},[r,c]);return(0,I.useEffect)(l,[l]),e?.organization?(0,B.jsxs)(`div`,{className:`mx-auto flex w-full max-w-3xl flex-col gap-4 px-4 py-6 md:px-6`,children:[(0,B.jsx)(SS,{title:X(`members`),subtitle:X(`whoWorks`,{organization:e.organization.name})}),(0,B.jsxs)(PA,{title:X(`members`),description:X(`membersDescription`),children:[(0,B.jsx)(FA,{message:o}),i?(0,B.jsx)(`ul`,{className:`divide-y rounded-md border`,children:i.map(r=>(0,B.jsx)(aH,{member:r,current:e,status:t?.find(e=>e.userId===r.userId),presence:rH(n,r.userId),onChanged:l},`${r.id}/${r.role}/${r.appRoles.join()}`))}):!o&&(0,B.jsxs)(`div`,{className:`flex items-center gap-2 text-muted-foreground`,children:[(0,B.jsx)($d,{}),` `,X(`loading`)]})]})]}):null},sH=({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)(YA,{title:X(`inviteSomeone`),description:X(`inviteDescription`),onInvite:async r=>{let i=await n.organizations.invite(e.organization.id,{email:r,role:a,appRoles:s});return c([]),t(),i},beside:(0,B.jsx)(`select`,{"aria-label":X(`organizationRole`),value:a,onChange:e=>o(e.target.value),className:`h-8 rounded-md border border-border-strong bg-background px-2`,children:iH(e).map(e=>(0,B.jsx)(`option`,{value:e,children:ij(e)},e))}),children:(0,B.jsx)(ZA,{roles:i.filter(e=>e.membership),selected:s,grantable:cj(i,e),onChange:c})})},cH=({invitation:e,organizationId:t,onChanged:n})=>{let{session:r,organizations:i}=V(),a=e.appRoles.map(e=>aj(i?.roles??[],e));return(0,B.jsx)(XA,{email:e.email,gives:`${ij(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()}})},lH=({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)(SS,{title:X(`invitations`),subtitle:X(`peopleInvited`,{organization:e.organization.name})}),(0,B.jsx)(sH,{current:e,onSent:a}),(0,B.jsx)(PA,{title:X(`notAcceptedYet`),description:n.length>0?X(`sendingAgain`):X(`nobodyWaiting`),children:n.length>0&&(0,B.jsx)(`ul`,{className:`divide-y rounded-md border`,children:n.map(e=>(0,B.jsx)(cH,{invitation:e,organizationId:i,onChanged:a},e.id))})})]})},uH=({usePresence:e,store:t})=>{let n=e();return(0,I.useEffect)(()=>t.set(n),[t,n]),(0,I.useEffect)(()=>()=>t.set(void 0),[t]),null},dH=({children:e})=>{let{presence:t}=c_(),[n]=(0,I.useState)(QV),[r,i]=(0,I.useState)({hook:t,key:0});return r.hook!==t&&i({hook:t,key:r.key+1}),(0,B.jsxs)($V.Provider,{value:n,children:[t&&(0,B.jsx)(uH,{usePresence:t,store:n},r.key),e]})},fH=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 wu?BA(e):X(`couldNotReadOrganizations`)))},[e,t,c]),{current:n,organizations:i,...o&&{error:o},reload:u}},pH=e=>window.location.assign(`${e}/`),mH=({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}=KA(),d=i.trim()!==e.name||o!==e.slug;return(0,B.jsxs)(PA,{title:X(`details`),description:X(t?`detailsEditable`:`detailsReadOnly`),children:[(0,B.jsx)(FA,{message:l}),(0,B.jsxs)(`form`,{className:`flex flex-col gap-2 sm:flex-row`,onSubmit:t=>{t.preventDefault(),u(async()=>{await r.organizations.rename(e.id,{name:i.trim(),slug:o}),n()})},children:[(0,B.jsx)(J,{"aria-label":X(`name`),value:i,disabled:!t,onChange:e=>a(e.target.value),wrapperClassName:`flex-1`}),(0,B.jsx)(J,{"aria-label":X(`slug`),value:o,disabled:!t,onChange:e=>s(e.target.value),wrapperClassName:`sm:w-48`}),t&&(0,B.jsx)(G,{type:`submit`,variant:`primary`,loading:c,disabled:!d||!i.trim(),children:X(`save`)})]})]})},hH=({organization:e,memberId:t})=>{let{session:n}=V(),[r,i]=(0,I.useState)([]),[a,o]=(0,I.useState)(``),{busy:s,error:c,run:l}=KA();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)(PA,{title:X(`handOver`),description:X(`handOverDescription`),children:[(0,B.jsx)(FA,{message:c}),(0,B.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,B.jsxs)(`select`,{"aria-label":X(`newOwner`),value:a,onChange:e=>o(e.target.value),className:`h-8 flex-1 rounded-md border border-border-strong bg-background px-2`,children:[(0,B.jsx)(`option`,{value:``,children:X(`chooseMember`)}),r.map(e=>(0,B.jsxs)(`option`,{value:e.id,children:[e.name,` (`,e.email,`)`]},e.id))]}),(0,B.jsx)(G,{loading:s,disabled:!a,onClick:()=>void l(async()=>{await n.organizations.transferOwnership(a),window.location.reload()}),children:X(`handOver`)})]})]})},gH=({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}=KA(),u=()=>l(async()=>{await n.organizations.remove(e.id),pH(t)});return(0,B.jsxs)(PA,{title:X(`deleteOrganization`),description:X(`deleteDescription`),children:[(0,B.jsx)(FA,{message:r?void 0:c}),(0,B.jsx)(G,{variant:`danger`,onClick:()=>i(!0),children:X(`deleteOrganization`)}),r&&(0,B.jsxs)(Cf,{title:X(`deleteTitle`,{name:e.name}),description:X(`deleteConfirm`),onClose:()=>i(!1),actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:()=>i(!1),children:X(`cancel`)}),(0,B.jsx)(G,{variant:`danger`,loading:s,disabled:a!==e.name,onClick:()=>void u(),children:X(`delete`)})]}),children:[(0,B.jsx)(FA,{message:c}),(0,B.jsx)(J,{"aria-label":X(`organizationName`),value:a,onChange:e=>o(e.target.value)})]})]})},_H=({editable:e})=>{let t=U(),[n,r]=(0,I.useState)(),{busy:i,error:a,run:o}=KA();return(0,I.useEffect)(()=>{t.callGuests.allowed().then(r)},[t]),n===void 0?null:(0,B.jsxs)(PA,{title:X(`guestLinks`),description:X(`guestLinksDescription`),children:[(0,B.jsx)(FA,{message:a}),(0,B.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-foreground`,children:[(0,B.jsx)(Vg,{checked:n,label:X(`guestLinksAllowed`),...e&&!i&&{onChange:e=>void o(async()=>{await t.callGuests.setAllowed(e),r(e)})}}),X(`guestLinksAllowed`)]})]})},vH=({organization:e,basePath:t,owner:n})=>{let{session:r}=V(),{busy:i,error:a,run:o}=KA();return(0,B.jsxs)(PA,{title:X(`leave`),description:X(n?`leaveOwner`:`leaveMember`),children:[(0,B.jsx)(FA,{message:a}),(0,B.jsx)(G,{loading:i,onClick:()=>void o(async()=>{await r.organizations.leave(e.id),pH(t)}),children:X(`leaveName`,{name:e.name})})]})},yH=({current:e,basePath:t,onChanged:n})=>{let r=Gd().data?.calls===!0,i=e?.organization;if(!i)return(0,B.jsx)(`div`,{className:`mx-auto w-full max-w-3xl px-4 py-6 md:px-6`,children:(0,B.jsx)(SS,{title:X(`organization`),subtitle:X(`noOrganization`)})});let a=e.role===`owner`;return(0,B.jsxs)(`div`,{className:`mx-auto flex w-full max-w-3xl flex-col gap-4 px-4 py-6 md:px-6`,children:[(0,B.jsx)(SS,{title:i.name,subtitle:e.role?X(`youAre`,{role:ij(e.role).toLowerCase()}):X(`throughGlobalRoles`)}),(0,B.jsx)(mH,{organization:i,editable:oj(e),onSaved:n},`${i.name}/${i.slug}`),r&&e.role&&(0,B.jsx)(_H,{editable:oj(e)}),a&&e.memberId&&(0,B.jsx)(hH,{organization:i,memberId:e.memberId}),e.role&&(0,B.jsx)(vH,{organization:i,basePath:t,owner:a}),a&&(0,B.jsx)(gH,{organization:i,basePath:t})]})},bH=({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)(Pf,{tone:`green`,children:X(`current`)}):(0,B.jsx)(G,{size:`sm`,loading:n,onClick:r,children:X(`open`)})]}),xH=({basePath:e,currentId:t})=>{let{session:n}=V(),[r,i]=(0,I.useState)(``),a=_j((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}=KA();return(0,B.jsx)(gj,{title:X(`allOrganizations`),description:X(`allOrganizationsDescription`),searchLabel:X(`findOrganization`),placeholder:X(`nameOrSlug`),query:r,onQuery:i,list:a,error:s,renderRow:r=>(0,B.jsx)(bH,{organization:r,current:r.id===t,busy:o,onOpen:()=>void c(async()=>{await n.organizations.switchTo(r.id),pH(e)})},r.id)})},SH=e=>e.normalize(`NFKD`).replace(/[̀-ͯ]/g,``).toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,63),CH=({basePath:e})=>{let{session:t}=V(),[n,r]=(0,I.useState)(``),[i,a]=(0,I.useState)(),{busy:o,error:s,run:c}=KA(),l=()=>c(async()=>{await t.organizations.create({name:n.trim(),slug:i??SH(n)}),pH(e)});return(0,B.jsxs)(PA,{title:X(`newOrganization`),description:X(`newOrganizationDescription`),children:[(0,B.jsx)(FA,{message:s}),(0,B.jsxs)(`form`,{className:`flex flex-col gap-2 sm:flex-row`,onSubmit:e=>{e.preventDefault(),l()},children:[(0,B.jsx)(J,{"aria-label":X(`name`),placeholder:X(`name`),value:n,onChange:e=>r(e.target.value),wrapperClassName:`flex-1`}),(0,B.jsx)(J,{"aria-label":X(`slug`),placeholder:`slug`,value:i??SH(n),onChange:e=>a(e.target.value),wrapperClassName:`sm:w-48`}),(0,B.jsx)(G,{type:`submit`,variant:`primary`,loading:o,disabled:!n.trim(),children:X(`create`)})]})]})},wH=({basePath:e})=>{let{session:t,organizations:n}=V(),[r,i]=(0,I.useState)([]),{busy:a,error:o,run:s}=KA();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),pH(e)});return(0,B.jsxs)(PA,{title:X(`invitationsForYou`),description:X(`invitationsForYouDescription`),children:[(0,B.jsx)(FA,{message:o}),(0,B.jsx)(`ul`,{className:`divide-y rounded-md border`,children:r.map(e=>(0,B.jsxs)(`li`,{className:`flex items-center gap-3 px-3 py-2.5`,children:[(0,B.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,B.jsx)(`span`,{className:`font-medium`,children:e.organizationName??X(`anOrganization`)}),`: `,e.appRoles.map(e=>aj(c,e)).join(`, `)||X(`noAppRoles`),(0,B.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:X(`until`,{date:new Date(e.expiresAt).toLocaleDateString(Le())})})]}),(0,B.jsx)(G,{size:`sm`,variant:`primary`,loading:a,onClick:()=>void l(e.id),children:X(`accept`)})]},e.id))})]})},TH=({state:e,basePath:t})=>{let{session:n,organizations:r,state:i}=V(),{busy:a,error:o,run:s}=KA(),c=i.kind===`signed-in`?i.user:void 0,l=r?.create===`everyone`||c!==void 0&&R_(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)(SS,{title:X(`organizations`),subtitle:X(`organizationsSubtitle`)}),(0,B.jsxs)(PA,{title:X(`yourOrganizations`),description:e.organizations.length>0?X(`memberOf`):X(`notMember`),children:[(0,B.jsx)(FA,{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)(bH,{organization:e,current:e.id===u,busy:a,onOpen:()=>void s(async()=>{await n.organizations.switchTo(e.id),pH(t)})},e.id))})]}),(0,B.jsx)(wH,{basePath:t}),l&&(0,B.jsx)(CH,{basePath:t}),(e.current?.globalRoles.length??0)>0&&(0,B.jsx)(xH,{basePath:t,currentId:u})]})},EH=(e,t)=>t?.active?{...e,role:t.active}:e,DH=M(`roles`),OH=(e,t)=>e instanceof wu?BA(e):t,kH=(e,t=!0)=>{let{session:n}=V(),r=iy(),[i,a]=(0,I.useState)();(0,I.useEffect)(()=>{t&&n.roles.current().then(a,e=>r.show({state:`error`,title:OH(e,DH(`couldNotReadRoles`))}))},[n,r,t]);let o=(0,I.useCallback)(t=>void n.roles.switchTo(t).then(e,e=>r.show({state:`error`,title:OH(e,DH(`couldNotSwitch`))})),[n,r,e]);return{...i&&{current:i},switchTo:o}},AH=e=>{let t=rV(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},jH=e=>{let t=c_().shell?.logo;return t?(0,B.jsx)(cv,{name:`shell.logo`,fallback:(0,B.jsx)(Ox,{...e}),children:(0,B.jsx)(t,{...e})}):(0,B.jsx)(Ox,{...e})},MH=[440,480],NH=400,PH=3e3,FH=e=>{(0,I.useEffect)(()=>{if(!e||typeof AudioContext>`u`)return;let t=new AudioContext,n=()=>{let e=t.createGain();e.gain.value=.08,e.connect(t.destination);for(let[n,r]of[0,NH*1.5/1e3].entries())for(let i of MH){let a=t.createOscillator();a.frequency.value=i,a.connect(e),a.start(t.currentTime+r),a.stop(t.currentTime+r+NH/1e3/(n+1))}};n();let r=setInterval(n,PH);return()=>{clearInterval(r),t.close()}},[e])},IH=(e,t)=>e.map(e=>({...e,until:t+e.remaining_ms})),LH=(e,t)=>{let n=e.filter(e=>e.until>t);return{ringing:n,next:n.length===0?void 0:Math.min(...n.map(e=>e.until))}},RH=e=>{let t=U(),n=Se(),r=E({queryKey:H.rings,queryFn:async()=>IH(await t.rings.list(),Date.now()),enabled:e});(0,I.useEffect)(()=>{if(!e)return;let r=()=>void n.invalidateQueries({queryKey:H.rings});return t.live({onChanges:e=>e.some(e=>e.resource===`$rings`)&&r(),onResync:r})},[t,n,e]);let[i,a]=(0,I.useState)(()=>Date.now()),{ringing:s,next:c}=LH(r.data??[],Math.max(i,r.dataUpdatedAt));(0,I.useEffect)(()=>{if(c===void 0)return;let e=setTimeout(()=>a(Date.now()),Math.max(0,c-Date.now()));return()=>clearTimeout(e)},[c]);let l=(0,I.useCallback)(e=>n.setQueryData(H.rings,t=>t?.filter(t=>t.call!==e)),[n]);return{ringing:s,decline:o({mutationFn:e=>t.rings.decline(e),onMutate:l,onSettled:()=>n.invalidateQueries({queryKey:H.rings})}).mutate,hide:l}},zH=(e,t,n)=>({state:`call`,sticky:!0,title:e.title,...e.body!==null&&{description:e.body},actions:[{label:Z(`decline`),onClick:()=>n(e.call)},{label:Z(`accept`),...t}]}),BH=()=>{let{ringing:e,decline:t,hide:n}=RH(!0),r=iy(),{href:i,open:a}=Hh(),o=(0,I.useRef)(new Map);return FH(e.length>0),(0,I.useEffect)(()=>{let s=new Set(e.map(e=>e.call));for(let[e,t]of o.current)s.has(e)||(r.dismiss(t),o.current.delete(e));for(let s of e){if(o.current.has(s.call))continue;let e={href:i({kind:`record`,resource:s.resource,key:s.key,call:`join`}),onNavigate:e=>{n(s.call),a(e)}};o.current.set(s.call,r.show({...zH(s,e,t),onClose:()=>t(s.call)}))}},[e,r,i,a,t,n]),(0,I.useEffect)(()=>{let e=o.current;return()=>{for(let t of e.values())r.dismiss(t);e.clear()}},[r]),null},VH=(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)}},HH=()=>{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:VH(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])}},UH=M(`notifications/bell`),WH=`flex w-full gap-2.5 px-3 py-2.5 text-left`,GH=({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?Mf.blue:`bg-transparent`),children:a&&(0,B.jsx)(`span`,{className:`sr-only`,children:UH(`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:Sp((i-Date.parse(e.createdAt))/1e3)})]})]}),s=()=>r(e),c=e=>{e.button===1&&s()};return t?t.kind===`app`?(0,B.jsx)(Sh,{to:{href:t.href,onFollow:()=>n(t.path)},onClick:s,onAuxClick:c,className:P(WH,`hover:bg-muted`),children:o}):(0,B.jsx)(`a`,{href:t.href,onClick:s,onAuxClick:c,className:P(WH,`hover:bg-muted`),children:o}):(0,B.jsx)(`div`,{className:WH,children:o})},KH=({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:UH(`notifications`)}),m&&h&&(0,B.jsx)(G,{size:`sm`,variant:`ghost`,loading:c,onClick:()=>s(m),children:UH(`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)($d,{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:UH(`loadFailed`)}),(0,B.jsx)(G,{size:`sm`,onClick:r,children:UH(`tryAgain`)})]}):e.length===0?(0,B.jsx)(`p`,{className:`px-3 py-8 text-center text-body text-muted-foreground`,children:UH(`empty`)}):(0,B.jsx)(`ul`,{className:`divide-y`,children:e.map(e=>(0,B.jsx)(`li`,{children:(0,B.jsx)(GH,{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:UH(`showMore`)})})]}),f]})},qH=(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}},JH=({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)(Qr,{className:`mt-0.5 size-3.5 shrink-0`,"aria-hidden":!0}),UH(`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)(ei,{className:`size-3.5 shrink-0`,"aria-hidden":!0}),(0,B.jsx)(`span`,{className:`min-w-0 flex-1`,children:UH(r?`pushOn`:`pushOff`)}),(0,B.jsx)(G,{size:`sm`,variant:r?`secondary`:`primary`,onClick:r?n:t,children:UH(r?`turnOff`:`turnOn`)})]})},YH=3e4,XH=e=>pl(e)&&e.status===403,ZH=({enabled:e=!0}={})=>{let t=U();return E({queryKey:H.inboxUnread,queryFn:()=>t.notifications.unread(),refetchInterval:e=>!XH(e.state.error)&&YH,enabled:e})},QH=({enabled:e=!0}={})=>{let t=U(),n=Ne({queryKey:H.inboxPages,queryFn:({pageParam:e})=>t.notifications.list(e===``?{}:{cursor:e}),initialPageParam:``,getNextPageParam:e=>e.next??void 0,enabled:e}),r=n.data?.pages.flatMap(e=>e.items)??[];return{...n,items:r}},$H=(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))},eU=()=>{let e=U(),t=Se(),n=()=>t.invalidateQueries({queryKey:H.inbox}),r=o({mutationFn:t=>e.notifications.markRead(t.id),onMutate:e=>$H(t,t=>t.id===e.id),onSettled:n}),i=o({mutationFn:t=>e.notifications.markAllRead(t.createdAt),onMutate:e=>$H(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}},tU=99,nU=e=>e===void 0||e<=0?UH(`notifications`):e>tU?UH(`notificationsManyUnread`):UH(`notificationsUnread`,{count:String(e)}),rU=()=>{let{open:e,setOpen:t,place:n,button:r,menu:i}=rg(),a=ZH(),o=QH({enabled:e}),{markRead:s,markAllRead:c,markingAll:l}=eU(),u=HH(),{navigate:d,basePath:f}=jh(),[p,m]=(0,I.useState)(Date.now),h=nU(a.data),g=window.location.origin;return XH(a.error)?null:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(G,{ref:r,size:`icon`,variant:`ghost`,"aria-label":h,title:h,"aria-haspopup":`dialog`,"aria-expanded":e,onClick:()=>{e||(m(Date.now()),a.refetch(),o.data&&o.refetch()),t(!e)},className:`relative max-md:size-9`,children:[(0,B.jsx)(ni,{className:`size-4 max-md:size-5`}),(0,B.jsx)(Yx,{count:a.data,className:`pointer-events-none absolute -top-1 -right-1.5 max-md:top-0 max-md:right-0`})]}),e&&(0,Sc.createPortal)((0,B.jsx)(`div`,{ref:i,role:`dialog`,"aria-label":nU(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)(KH,{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=>qH(e.url,{origin:g,basePath:f}),onNavigate:e=>d(e),onOpen:e=>{s(e),t(!1)},footer:(0,B.jsx)(JH,{state:u.state,onTurnOn:()=>void u.turnOn(),onTurnOff:()=>void u.turnOff()}),now:p})}),document.body)]})},iU=({own:e})=>e?(0,B.jsx)(cv,{name:`shell.bell`,fallback:null,children:(0,B.jsx)(e,{})}):(0,B.jsx)(rU,{}),aU=(0,I.createContext)([]),oU=()=>(0,I.useContext)(aU),sU=({ui:e,children:t})=>{let{plugins:n=[]}=W(),{loads:r,settled:i}=zP(n,IP()),a=(0,I.useMemo)(()=>gP(e,r),[e,r]);return i?(0,B.jsx)(s_.Provider,{value:a.ui,children:(0,B.jsx)(aU.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)($d,{}),` `,_P(`loading`)]})},cU=({off:e})=>{let[t,n]=(0,I.useState)(!1);return t||e.length===0?null:(0,B.jsxs)(`div`,{role:`region`,"aria-label":_P(`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)(Zo,{"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:_P.rich(`pluginOff`,{plugin:(0,B.jsx)(`span`,{className:`font-semibold`,children:e.name??e.url}),reason:e.reason})},e.url))}),(0,B.jsx)(`button`,{type:`button`,"aria-label":_P(`dismiss`),className:`rounded p-0.5 hover:bg-warning/10`,onClick:()=>n(!0),children:(0,B.jsx)(yc,{"aria-hidden":!0,className:`size-4`})})]})},lU=(e,t)=>[`${t}_at`,`${t}At`].find(t=>e.fields[t]),uU=({item:e,scope:t})=>{let{components:n}=c_(),r=n?.[e.component],i=r?(0,B.jsx)(Jv,{value:t,children:(0,B.jsx)(cv,{name:e.component,children:(0,B.jsx)(r,{...vn(e.props??{})})})}):(0,B.jsx)(ov,{children:q.rich(`noComponent`,{component:e.component})});return e.sidebar?e.title?(0,B.jsx)(og,{title:e.title,children:i}):i:e.title?(0,B.jsx)(Vf,{title:e.title,children:i}):(0,B.jsx)(`section`,{className:`py-8`,children:i})},dU=({component:e,scope:t,standard:n})=>{let{components:r}=c_(),i=r?.[e];return i?(0,B.jsx)(cv,{name:e,fallback:n,children:(0,B.jsx)(fU,{children:(0,B.jsx)(Jv,{value:t,children:(0,B.jsx)(i,{})})})}):n},fU=({children:e})=>(vx(!1),(0,B.jsx)(`div`,{className:`grid min-h-0 flex-1 grid-cols-[minmax(0,1fr)] grid-rows-[minmax(0,1fr)]`,children:e})),pU=(0,I.lazy)(()=>Ve(()=>import(`./record-map-CZ__Yamf.js`).then(e=>({default:e.RecordMap})),__vite__mapDeps([9,1,2,5,6,7,3,8]))),mU=15,hU=({item:e,record:t})=>{let n=W().maps,r=n?.style,i=zk(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)(pU,{style:r,layers:n?.layers,position:i,zoom:e.zoom??mU},`${i.latitude},${i.longitude}`)})});return e.sidebar?(0,B.jsx)(og,{title:e.title,children:a}):(0,B.jsx)(Vf,{title:e.title,children:a})},gU={"1h":`minute`,"24h":`5_minutes`,"7d":`hour`},_U=(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}))},vU=M(`app/record-chart`),yU=sn(),bU=[`1h`,`24h`,`7d`],xU={"1h":`hour`,"24h":`day`,"7d":`week`},SU=({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=gU[i],d=Yt(yU.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:Gf()})),p=zy(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)?_U(p.map(e=>e.data.groups),h.map(e=>e.key),o):[],_=(0,B.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,B.jsx)(Re,{label:vU(`measure`),value:o,onChange:s,options:[{value:`average`,label:vU(`average`)},{value:`maximum`,label:vU(`maximum`)}]}),(0,B.jsx)(Re,{label:vU(`range`),value:i,onChange:a,options:bU.map(e=>({value:e,label:vU(xU[e])}))})]});return(0,B.jsx)(Vf,{title:e.title,help:e.help,actions:_,children:p.some(e=>e.error)?(0,B.jsx)(`p`,{className:`text-danger-text`,children:vU(`couldNotLoad`)}):p.some(e=>e.isPending)?(0,B.jsx)(vh,{className:`h-40 w-full`}):g.every(e=>e.count===0)?(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:vU(`noSamples`)}):(0,B.jsx)(pb,{points:g,measure:m[0],bucket:u,type:`line`,series:h,...h.length>1&&{resource:e.resource,view:l}})})},CU=e=>$T(e)??xc,wU=({model:e,stored:t,recordKey:n,edit:r,onDelete:i})=>{let a=Hh(),{go:o}=a,s=pS(),c={model:e,record:t.record,key:n,etag:t.etag,permissions:t.permissions},l=Ty(e.name,c,t=>t.run?.kind===`delete`&&o({kind:`list`,resource:e.name},{replace:!0})),[u,d]=(0,I.useState)(),f=l.actions.map(e=>{let n=l.blocked(e),r=e.run?.kind===`link`&&!n?BV(e.run,t.record,a):void 0;return{name:e.label,icon:CU(e.icon),blocked:n,running:l.running===e.name,...Wv(e)&&{tone:`danger`},onRun:()=>Gv(e)?d(e):void l.run(e),...r&&{render:({className:e,children:t,role:n})=>(0,B.jsx)(Sh,{to:r,role:n,className:e,children:t})}}}),p=l.actions.some(e=>e.run?.kind===`delete`),m=[...r?[{name:Q(`edit`),icon:Lo,render:({className:e,children:t,role:n})=>(0,B.jsx)(Uh,{to:r,role:n,className:e,children:t})}]:[],...f,...i&&!p?[{name:Q(`delete`),icon:qs,tone:`danger`,onRun:i}]:[]];return m.length===0?null:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`div`,{className:s?`max-md:hidden`:void 0,children:(0,B.jsx)($h,{actions:m})}),s&&(0,Sc.createPortal)((0,B.jsx)(ig,{actions:m,label:Q(`recordActions`),className:`inline-flex size-11 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-muted md:hidden`}),s),u&&(0,B.jsx)(Kv,{action:u,label:u.label,danger:Wv(u),onCancel:()=>d(void 0),onConfirm:()=>{d(void 0),l.run(u)},onSubmit:async e=>{await l.submit(u,e),d(void 0)}})]})},TU=(e=[],t)=>e.includes(t)?e.filter(e=>e!==t):[...e,t],EU=(e,t=[],n)=>!e.collapsed||t.includes(e.title)||e.items.some(e=>e.kind===`section`&&e.fields.some(n)),DU=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)}},OU=(e,t)=>e.find(e=>e.title===t)??e[0],kU=e=>Sn(e.items).flatMap(e=>e.kind===`section`?e.fields:[]),AU=(e,t,n)=>{if(t&&!kU(t).some(n))return e.find(e=>kU(e).some(n))},jU=e=>e.width??`minmax(8rem,1fr)`,MU=e=>({"--line-columns":e.map(jU).join(` `)}),NU=e=>`${e.reduce((e,t)=>e+(t.width?.endsWith(`px`)?parseInt(t.width)/16:8),6)}rem`,PU=`grid grid-cols-[28px_var(--line-columns)_32px] items-center gap-2 pointer-coarse:grid-cols-[44px_var(--line-columns)_44px]`,FU=({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)(ca,{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))})]})},IU=M(`inline-child-table`),LU=({line:e,name:t,columns:n,position:r,count:i,reorderable:a,onRemove:o,onMove:s,error:c})=>{let{attributes:l,listeners:u,setNodeRef:d,setActivatorNodeRef:f,transform:p,transition:m,isDragging:h}=Te({id:e.id,disabled:!a}),g=[...a?[{label:IU(`moveUp`),disabled:r===0,onSelect:()=>s(r-1)},{label:IU(`moveDown`),disabled:r===i-1,onSelect:()=>s(r+1)}]:[],...o?[{label:IU(`removeLine`),destructive:!0,onSelect:o}]:[]];return(0,B.jsxs)(`div`,{ref:d,"data-line-id":e.id,"aria-invalid":c?!0:void 0,style:{transform:p?`translate3d(0, ${p.y}px, 0)`:void 0,transition:m},className:P(`group relative border-b border-border bg-background px-2 py-1 last:border-b-0 hover:bg-surface`,PU,h&&`z-10 bg-surface opacity-80 shadow-pop`,c&&`bg-danger-soft`),children:[a?(0,B.jsx)(`button`,{ref:f,type:`button`,"aria-label":IU(`dragToReorder`,{name:t}),...l,...u,style:{touchAction:`none`},className:`flex size-7 cursor-grab items-center justify-center rounded text-faint-foreground opacity-60 hover:bg-muted hover:opacity-100 focus-visible:opacity-100 active:cursor-grabbing pointer-coarse:size-11`,children:(0,B.jsx)(wa,{className:`size-4`})}):(0,B.jsx)(`span`,{}),n.map(t=>(0,B.jsx)(`div`,{className:P(`min-w-0`,t.align===`right`&&`text-right`),children:t.cell(e)},t.key)),g.length>0?(0,B.jsx)(FU,{label:IU(`actionsFor`,{name:t}),items:g}):(0,B.jsx)(`span`,{}),c&&(0,B.jsx)(`p`,{role:`alert`,className:`col-span-full px-2 pb-1 text-xs text-danger-text`,children:c})]})},RU=(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},zU=`px-2 text-[11px] font-medium uppercase tracking-wide text-muted-foreground`,BU=(e,t)=>{let n=n=>{let r=e.find(e=>e.id===n);return r?t(r):IU(`line`)},r=t=>e.findIndex(e=>e.id===t)+1;return{onDragStart:({active:t})=>IU(`pickedUp`,{name:n(t.id),place:r(t.id),count:e.length}),onDragOver:({active:t,over:i})=>i?IU(`over`,{name:n(t.id),place:r(i.id),count:e.length}):void 0,onDragEnd:({active:t,over:i})=>i?IU(`dropped`,{name:n(t.id),place:r(i.id),count:e.length}):IU(`droppedAtStart`,{name:n(t.id)}),onDragCancel:({active:e})=>IU(`cancelled`,{name:n(e.id),place:r(e.id)})}},VU=({lines:e,columns:t,lineName:n,onReorder:r,reorderable:i=!!r,onAdd:a,onRemove:o,removable:s=()=>!0,lineError:c,footer:l})=>{let u=ne(Me(se,{activationConstraint:{distance:4}}),Me(xe,{activationConstraint:{delay:250,tolerance:5}}),Me(ae,{coordinateGetter:ye})),d=(t,n)=>{let i=e[t];!i||!r||n<0||n>=e.length||t===n||r(RU(e,t,n),{id:i.id,from:t,to:n})};return(0,B.jsxs)(`div`,{children:[(0,B.jsxs)(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,style:MU(t),children:[(0,B.jsxs)(`div`,{className:`${PU} border-b border-border bg-surface px-2 py-2`,children:[(0,B.jsx)(`span`,{}),t.map(e=>(0,B.jsx)(`span`,{className:P(zU,e.align===`right`&&`text-right`),children:e.label},e.key)),(0,B.jsx)(`span`,{})]}),e.length===0&&(0,B.jsx)(`p`,{className:`px-4 py-3 text-muted-foreground`,children:IU(`noLines`)}),(0,B.jsx)(me,{sensors:u,collisionDetection:ge,onDragEnd:({active:t,over:n})=>{n&&t.id!==n.id&&d(e.findIndex(e=>e.id===t.id),e.findIndex(e=>e.id===n.id))},accessibility:{announcements:BU(e,n),screenReaderInstructions:{draggable:IU(`instructions`)}},children:(0,B.jsx)(ue,{items:e.map(e=>e.id),strategy:re,children:e.map((r,a)=>(0,B.jsx)(LU,{line:r,name:n(r),columns:t,position:a,count:e.length,reorderable:i,onRemove:o&&s(r)?()=>o(r):void 0,onMove:e=>d(a,e),error:c?.(r)},r.id))})}),a&&(0,B.jsx)(`div`,{className:`border-t border-border bg-surface px-2 py-1.5`,children:(0,B.jsxs)(G,{variant:`ghost`,size:`sm`,onClick:a,children:[(0,B.jsx)(qo,{className:`size-3.5`}),IU(`addLine`)]})})]}),l]})},HU=({field:e,hints:t,label:n,lineNumber:r,resource:i,value:a,stored:o,relationLabel:s,relationTo:c,relationPicker:l,locked:u,problem:d,onChange:f})=>{let p=(0,I.useId)(),m=d&&ix(e,n,d);return(0,B.jsxs)(qh.Provider,{value:{id:p,invalid:!!d,required:!1,...m&&{describedBy:`${p}-error`}},children:[(0,B.jsx)(`label`,{htmlFor:p,className:`sr-only`,children:Q(`lineField`,{label:n,place:r})}),(0,B.jsx)(Ov,{field:e,hints:t,value:a,stored:o,relationLabel:s,relationTo:c,relationPicker:l,locked:u,invalid:!!d,resource:i,onChange:f}),m&&(0,B.jsx)(`p`,{id:`${p}-error`,className:`px-1 pt-0.5 text-xs text-danger-text`,children:m})]})},UU=(e,t,n,r,i)=>{let a=Wg(e?.name??``,{enabled:!!(e&&t),filter:t?`${t.name} = "${r}"`:void 0,pageSize:500,labels:i,...n&&e?.fields[n]?.sortable&&{orderBy:`${n} asc`}}),o=(0,I.useMemo)(()=>n?[...a.items].sort((e,t)=>Number(e[n])-Number(t[n])):a.items,[a.data,n]),s=a.hasNextPage&&a.items.length<1e3;return(0,I.useEffect)(()=>{s&&!a.isFetchingNextPage&&a.fetchNextPage()},[s,a.isFetchingNextPage]),{items:o,labels:a.labels,loading:(a.isPending||s)&&!!e,complete:!a.hasNextPage}},WU=({lines:e,editable:t,saving:n})=>{let{resources:r,views:i}=W(),{item:a,model:o,columns:s,data:c,draft:l}=e,u=af(o.name),d=i[o.name],[f,p]=(0,I.useState)({}),m=t&&c.complete&&!c.loading&&!n,h=m&&oy(u,`update`),g=m&&oy(u,`create`),_=m&&oy(u,`delete`),v=e=>e.stored?h&&sy(e.stored,`update`):g,y=e=>l.shown.indexOf(e)+1,b=e=>l.rejection?.id===e.id?l.rejection:void 0,x=s.map(e=>{let t=o.fields[e],n=d?.fields[e],a=n?.label??F(e),s=t.relation?r[t.relation.resource]:void 0,u=s&&s.primaryKey.length===1?s:void 0;return{key:e,label:a,...[`integer`,`bigint`,`decimal`].includes(t.type)&&{align:`right`,width:`minmax(6rem,0.6fr)`},cell:r=>{let s=l.value(r.id,e),d=s==null||s===``?void 0:String(s);return(0,B.jsx)(HU,{field:t,hints:n,label:a,lineNumber:y(r),resource:o.name,value:s,stored:r.stored?.[e],relationLabel:d===void 0?void 0:f[`${r.id}/${e}`]??c.labels[e]?.[d],relationTo:u&&d!==void 0?{kind:`record`,resource:u.name,key:d}:void 0,relationPicker:u&&{target:u,view:i[u.name]},locked:!v(r),problem:b(r)?.fields[e],onChange:t=>{if(!u||!Og(t))return l.change(r.id,e,t);p(n=>({...n,[`${r.id}/${e}`]:t.label})),l.change(r.id,e,jg(u,t.key))}})}}});return(0,B.jsxs)(Vf,{title:a.title,help:a.help,children:[!c.complete&&(0,B.jsx)(`p`,{className:`mb-2 text-muted-foreground`,children:Q(`tooManyLines`,{limit:wp(1e3)})}),(0,B.jsx)(`div`,{className:`-mx-4 overflow-x-auto px-4 [-webkit-overflow-scrolling:touch] md:mx-0 md:px-0`,children:(0,B.jsx)(`div`,{style:{minWidth:NU(x)},children:(0,B.jsx)(VU,{lines:l.shown,columns:x,lineName:e=>lr(o,d,e.stored??{},``)||Q(`lineNumber`,{place:y(e)}),onReorder:e=>l.setOrder(e.map(e=>e.id)),reorderable:h,onAdd:g?()=>void l.add():void 0,onRemove:g||_?e=>l.remove(e.id):void 0,removable:e=>e.stored?_&&sy(e.stored,`delete`):g,lineError:e=>{let t=b(e);if(t&&!s.some(e=>t.fields[e]))return t.message}})})})]})},GU=(e,t,n)=>`protobase:draft:${e}:${t}:${n}`,KU=(e,t,n)=>Ie(()=>{let r=e.getItem(t);if(r===null)return;let i=JSON.parse(r);if(i&&i.etag===n&&typeof i.fields==`object`&&i.fields!==null)return{etag:n,fields:i.fields,...Array.isArray(i.order)&&{order:i.order.map(String)}}},void 0),qU=(e,t,n)=>Ie(()=>n?e.setItem(t,JSON.stringify(n)):e.removeItem(t),void 0),JU={added:[],edits:{},removed:[]},YU=(e,t)=>{let n=[...e.filter(e=>!t.removed.includes(e)),...t.added];return t.order?[...t.order.filter(e=>n.includes(e)),...n.filter(e=>!t.order.includes(e))]:n},XU=(e,t,n)=>Object.fromEntries(Object.entries(t).flatMap(([t,r])=>{let i=e.fields[t];return i&&Sg(i,r,n[t])?[[t,yg(i,r)]]:[]})),ZU=(e,t)=>Object.fromEntries(Object.entries(t).flatMap(([t,n])=>{let r=e.fields[t];return!r||r.type!==`boolean`&&String(n??``).trim()===``?[]:[[t,yg(r,n)]]})),QU=({model:e,position:t,link:n,stored:r,state:i})=>{let a={ops:[],rows:[]},o=(e,t)=>{a.ops.push(e),a.rows.push(t)},s=new Map(r.map(t=>[vm(e,t),t])),c=[...s.keys()],l=YU(c,i),u=t=>ym(e,s.get(t)),d=e=>{let t=s.get(e).etag;return typeof t==`string`?t:void 0};for(let t of i.removed){if(!s.has(t))continue;let n=d(t);o({op:`delete`,resource:e.name,key:u(t),...n&&{etag:n}},t)}let f=new Set;for(let[t,n]of Object.entries(i.edits)){if(!s.has(t)||i.removed.includes(t))continue;let r=XU(e,n,s.get(t));if(Object.keys(r).length===0)continue;let a=d(t);o({op:`update`,resource:e.name,key:u(t),data:r,...a&&{etag:a}},t),f.add(t)}let p=l.filter(e=>s.has(e)),m=l.filter(e=>!s.has(e)),h=(e,t)=>Object.fromEntries(e.flatMap(e=>{let n=t||f.has(e)?`*`:d(e);return n?[[Nn(u(e)),n]]:[]})),g=(n,r,i)=>({op:`reorder`,resource:e.name,field:t,keys:n,...r!==1&&{start:r},etags:i}),_=(r,a,o)=>({op:`create`,resource:e.name,data:{...ZU(e,i.edits[r]??{}),[n.field]:n.value,[t]:a},...o&&{ref:o}}),v=e=>Number(e[t])||0,y=p.some((e,t)=>e!==c.filter(e=>p.includes(e))[t]);if(m.every(e=>l.indexOf(e)>=p.length)){y&&o(g(p.map(u),1,h(p,!1)));let e=y?p.length:Math.max(0,...p.map(e=>v(s.get(e))));return m.forEach((t,n)=>o(_(t,e+1+n),t)),a}let b=Math.max(l.length,...r.map(v))+1;p.length>0&&o(g(p.map(u),b,h(p,!1)));let x=e=>`line${m.indexOf(e)+1}`;for(let e of m)o(_(e,l.indexOf(e)+1,x(e)),e);return o(g(l.map(e=>s.has(e)?u(e):{$ref:x(e)}),1,h(p,!0))),a},$U=(e,t)=>Object.fromEntries(Object.entries(e).filter(([e])=>e!==t)),eW=(e,t)=>{let[n,r]=(0,I.useState)(JU),[i,a]=(0,I.useState)(),o=(0,I.useRef)(1),s=(0,I.useMemo)(()=>new Map(e?t.map(t=>[vm(e.model,t),t]):[]),[e,t]),c=YU([...s.keys()],n).map(e=>({id:e,stored:s.get(e)})),l=()=>e?QU({...e,stored:t,state:n}):{ops:[],rows:[]},u=l().ops.length>0,d=(0,I.useMemo)(()=>{let e=YU([...s.keys()],n).filter(e=>s.has(e)),t=[...s.keys()].filter(t=>e.includes(t));return n.order!==void 0&&e.some((e,n)=>e!==t[n])?e:void 0},[s,n]),f=(t,r)=>{let i=n.edits[t];if(i&&r in i)return i[r];let a=e?.model.fields[r],o=s.get(t)?.[r];return a?[`boolean`,`file`].includes(a.type)?o:xg(a,o):o},p=e=>a(t=>t?.id===e?void 0:t);return{shown:c,dirty:u,order:d,value:f,change:(e,t,n)=>{p(e),r(r=>({...r,edits:{...r.edits,[e]:{...r.edits[e],[t]:n}}}))},add:()=>{let e=`new:${o.current++}`;return r(t=>({...t,added:[...t.added,e]})),e},remove:e=>{p(e),r(t=>t.added.includes(e)?{...t,added:t.added.filter(t=>t!==e),edits:$U(t.edits,e)}:{...t,removed:[...t.removed,e]})},setOrder:e=>r(t=>({...t,order:e})),reset:()=>{r(JU),a(void 0)},reject:(e,t)=>a({id:e,fields:ax(t),message:t.message}),rejection:i,plan:l}},tW=(e,t)=>{let n=Sn(t?.layout??[]).find(e=>e.kind===`related`&&e.lines===!0);if(n?.kind!==`related`)return;let r=e[n.resource],i=r?.fields[n.field],a=r?.position?.field;if(r&&i&&a&&r.position?.within===n.field)return{item:n,model:r,link:i,position:a}},nW=(e,t,n,r)=>Tr(e,t).filter(t=>{let i=e.fields[t];return i&&!i.writeOnly&&t!==n&&t!==r&&t!==e.tenant&&!e.primaryKey.includes(t)}),rW=(e,t)=>{let{resources:n,views:r}=W(),i=(0,I.useMemo)(()=>tW(n,r[e.name]),[n,r,e]),a=i?.model,o=i?nW(i.model,r[i.model.name],i.link.name,i.position):[],s=UU(a,i?.link,i?.position,t,a?Cb(n,r,a,o):void 0),c=eW((0,I.useMemo)(()=>i?{model:i.model,position:i.position,link:{field:i.link.name,value:jg(e,t)}}:void 0,[i,e,t]),s.items);return{item:i?.item,model:a,columns:o,data:s,draft:c}},iW=e=>{let t=e>=5?5:e===4?3:e;return{shown:t,more:e-t}},aW=(e,t)=>Math.abs(e)<40||Math.abs(e)<=Math.abs(t)?0:e<0?1:-1,oW=e=>e===`ArrowRight`?1:e===`ArrowLeft`?-1:0,sW=(e,t,n)=>Math.min(Math.max(e+t,0),Math.max(n-1,0)),cW=e=>e.key===`i`&&!e.ctrlKey&&!e.metaKey&&!e.altKey,lW=`protobase:lightbox-details`,uW=e=>Ie(()=>e.getItem(lW)===`true`,!1),dW=(e,t)=>Ie(()=>t?e.setItem(lW,`true`):e.removeItem(lW),void 0),fW=M(`app/gallery`),pW=`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`,mW=({title:e,photos:t,index:n,onIndex:r,onClose:i,details:a,detailsTitle:o=fW(`details`)})=>{let s=(0,I.useRef)(null),c=(0,I.useRef)(void 0),l=(0,I.useId)(),u=gf(),[d,f]=(0,I.useState)(()=>uW(localStorage)),[p,m]=(0,I.useState)(!1);Sf(s,!0,i),(0,I.useEffect)(()=>m(!0),[]);let h=t.length,g=e=>{let t=sW(n,e,h);t!==n&&r(t)},_=Vp(t[n],{width:1600,height:1200}),v=a?.(n),y=v!==void 0,b=e=>{f(e),dW(localStorage,e)};return(0,B.jsxs)(`div`,{ref:s,tabIndex:-1,role:`dialog`,"aria-modal":`true`,"aria-label":e,onKeyDown:e=>{if(y&&cW(e))return e.preventDefault(),b(!d);let t=oW(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(pW,`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)(Pa,{className:`size-4`,"aria-hidden":!0})}),(0,B.jsx)(`button`,{type:`button`,className:pW,"aria-label":fW(`close`),onClick:i,children:(0,B.jsx)(yc,{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(aW(e.clientX-c.current.x,e.clientY-c.current.y)),void 0)},onPointerCancel:()=>c.current=void 0,children:[_&&(0,B.jsx)(j_,{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(pW,`absolute left-3 top-1/2 -translate-y-1/2 aria-disabled:cursor-default aria-disabled:opacity-40`),"aria-label":fW(`previousPhoto`),"aria-disabled":n===0,onClick:()=>g(-1),children:(0,B.jsx)(Ei,{className:`size-5`,"aria-hidden":!0})}),(0,B.jsx)(`button`,{type:`button`,className:P(pW,`absolute right-3 top-1/2 -translate-y-1/2 aria-disabled:cursor-default aria-disabled:opacity-40`),"aria-label":fW(`nextPhoto`),"aria-disabled":n===h-1,onClick:()=>g(1),children:(0,B.jsx)(Oi,{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)(Tf,{title:o,open:y&&d&&!u&&p,onClose:()=>b(!1),children:(0,B.jsx)(`div`,{className:`pt-3`,children:v})})]})},hW=(e,t,n)=>{let r=Sn(t?.layout??[]).flatMap(e=>e.kind===`section`&&Eg(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)&&Eg(t?.fields[r]?.when,!1))},gW=({model:e,view:t,photoKey:n,fields:r})=>{let i=ZP(e.name,n),a=(t?.names?.singular??F(e.name)).toLowerCase();if(i.isPending)return(0,B.jsx)(vh,{className:`h-4 w-48`});if(i.error)return(0,B.jsx)(Bg,{title:fW(`couldNotLoadOne`,{singular:a}),error:i.error});let o=r.filter(e=>cy(i.data.permissions,e)!==`hidden`);return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(Xh,{rows:o.map(n=>({label:t?.fields[n]?.label??F(n),value:(0,B.jsx)(Lb,{model:e,field:e.fields[n],value:i.data.record[n]})}))}),(0,B.jsx)(Uh,{to:{kind:`record`,resource:e.name,key:n},className:`mt-3 inline-block font-medium text-primary-text hover:underline`,children:fW(`open`,{singular:a})})]})},_W=e=>Vp(e,{width:0,height:0})!==void 0,vW=(e,t)=>{let n=e.primaryKey.map(e=>t[e]);if(!n.some(e=>e==null))return Nn(n)},yW=(e,t,n,r)=>{let i=n===void 0?[]:t.flatMap(e=>{let t=e[n];if(!jp(t)||!_W(t))return[];let i=r&&vW(r,e);return[{file:t,...i!==void 0&&{key:i}}]});if(!jp(e)||!_W(e))return i;let a=t=>jp(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))]},bW=sn(),xW=(e,t,n)=>{let r=U(),{resources:i}=W(),a=e.photos?i[e.photos.resource]:void 0,o=e.photos?Yt(bW.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:yW(e.image===void 0?void 0:t[e.image],c.data??[],e.photos?.image,a),isPending:a!==void 0&&c.isPending,error:c.error}},SW={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`,``,``,``,``]},CW=({photo:e,large:t})=>{let n=Vp(e,t?{width:960,height:720}:{width:480,height:360});return n?(0,B.jsx)(j_,{image:n,loading:`lazy`,className:`size-full object-cover transition-transform duration-300 group-hover/tile:scale-[1.02]`}):null},wW=({item:e,record:t,recordKey:n})=>{let{views:r}=W(),i=xW(e,t,n),a=af(i.holder?.name??``),[o,s]=(0,I.useState)();if(i.isPending)return(0,B.jsx)(Vf,{title:e.title,children:(0,B.jsx)(vh,{className:`aspect-[4/3] w-full rounded-lg md:aspect-[2/1]`})});if(i.error)return(0,B.jsx)(Vf,{title:e.title,children:(0,B.jsx)(Bg,{title:fW(`couldNotLoad`),error:i.error})});let c=i.items.length;if(c===0)return null;let{shown:l,more:u}=iW(c),d=i.holder,f=d&&r[d.name],p=d?hW(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)(Vf,{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?fW(`showAll`,{count:c}):fW(`showPhoto`,{index:t+1,count:c}),onClick:()=>s(t),className:P(`group/tile relative overflow-hidden bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary`,t===0?`col-span-4 row-span-2`:`max-md:hidden`,SW[l][t]),children:[(0,B.jsx)(CW,{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)(mW,{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)(gW,{model:d,view:f,photoKey:t,fields:p},t):void 0},detailsTitle:d&&fW(`holderDetails`,{singular:f?.names?.singular??F(d.name)})})]})},TW=M(`app/history`),EW=e=>e.actor?e.actor.name??e.actor.id:e.databaseRole?TW(`databaseRole`,{role:e.databaseRole}):TW(`database`),DW=(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:Nm(i,e.before[r],a),after:Nm(i,e.after[r],a)}]}),i=e.operation===`update`&&r.length===0?TW(`changedThis`):TW(e.operation);return{who:EW(e),verb:i,fields:r}},OW=1500,kW=(e,t,n,r)=>{let i=U(),a=Ne({queryKey:H.history(e,t,n),initialPageParam:``,queryFn:({pageParam:r})=>i.history(e,t,{pageSize:n,pageToken:r}),getNextPageParam:e=>e.nextPageToken||void 0}),{refetch:o}=a;return(0,I.useEffect)(()=>{let e=setTimeout(()=>void o(),OW);return()=>clearTimeout(e)},[r,o]),{...a,items:a.data?.pages.flatMap(e=>e.items)??[]}},AW=()=>(0,B.jsx)(`div`,{className:`flex flex-col gap-2`,children:Array.from({length:3},(e,t)=>(0,B.jsx)(vh,{className:`h-4 w-full`},t))}),jW=({change:e,model:t,view:n})=>{let{who:r,verb:i,fields:a}=DW(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:dp(o),className:`text-muted-foreground`,children:[`· `,Sp(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))})]})},MW=({item:e,model:t,view:n,recordKey:r,etag:i})=>{let a=kW(t.name,r,e.limit??10,i);return(0,B.jsx)(Vf,{title:e.title,children:a.isPending?(0,B.jsx)(AW,{}):a.error?(0,B.jsx)(Bg,{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)(jW,{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`})]})})},NW=({comment:e})=>(0,B.jsx)(PI,{text:e.body,mentions:e.mentions}),PW=(e,t)=>{let n=U(),r=Se();return o({mutationFn:r=>n.comment(e,t,r),onSuccess:()=>r.invalidateQueries({queryKey:H.comments(e,t)})})},FW=M(`app/comments`),IW=({resource:e,recordKey:t})=>{let[n,r]=(0,I.useState)(jI),i=U(),a=iy(),o=PW(e,t),s=(0,I.useCallback)(n=>i.mentionable(e,t,n),[i,e,t]);Vh(n.text.trim()!==``||o.isPending,`input-lost`);let c=()=>{n.text.trim()===``||o.isPending||o.mutate({body:n.text,mentions:EI(n.text,n.picked)},{onSuccess:()=>r(jI),onError:e=>a.show({state:`error`,title:FW(`couldNotPost`),description:Um(e)})})};return(0,B.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,B.jsx)(NI,{"aria-label":FW(`comment`),placeholder:FW(`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:FW(`comment`)})})]})},LW=20,RW=(e,t)=>{let n=U(),r=Ne({queryKey:H.comments(e,t),initialPageParam:``,queryFn:({pageParam:r})=>n.comments(e,t,{pageSize:LW,pageToken:r}),getNextPageParam:e=>e.nextPageToken||void 0});return{...r,items:r.data?.pages.flatMap(e=>e.items).reverse()??[]}},zW=()=>(0,B.jsx)(`div`,{className:`flex flex-col gap-2`,children:Array.from({length:3},(e,t)=>(0,B.jsx)(vh,{className:`h-4 w-full`},t))}),BW=({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)(If,{initials:I_(t)||`?`,hue:F_(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:dp(n),className:`text-muted-foreground`,children:[`· `,Sp(Math.max(0,Math.round((Date.now()-n)/1e3)))]})]}),(0,B.jsx)(NW,{comment:e})]})]})},VW=({item:e,resource:t,recordKey:n,canWrite:r})=>{let i=RW(t,n);return(0,B.jsxs)(Vf,{title:e.title,children:[i.isPending?(0,B.jsx)(zW,{}):i.error?(0,B.jsx)(Bg,{title:FW(`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:FW(`showEarlier`)}),i.items.length===0?(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:FW(`noComments`)}):(0,B.jsx)(`ol`,{className:`divide-y divide-border`,children:i.items.map(e=>(0,B.jsx)(BW,{comment:e},e.id))})]}),r&&(0,B.jsx)(`div`,{className:`mt-4`,children:(0,B.jsx)(IW,{resource:t,recordKey:n})})]})},HW=e=>e.kind===`group`||e.kind===`tab`?e.items:[],UW=e=>e.kind===`tab`?void 0:e.when,WW=e=>e.flatMap(e=>[e,...WW(HW(e))]).filter(e=>kc(UW(e))),GW=(e,t,n,r)=>{let i=0,a=e=>{let a=UW(e);return kc(a)?!r&&t[i++]===!0:Eg(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)},KW=(e,t,n,r)=>GW(e,CD(r?[]:WW(e).map(e=>UW(e)),t),n,r),qW=(e,t)=>{let n=U(),r=Se(),i=Nn(t);return o({mutationFn:({patch:r,etag:i})=>n.update(e,t,r,i),onSuccess:t=>{r.setQueryData(H.record(e,i),t),r.invalidateQueries({queryKey:[`page`,e]}),r.invalidateQueries({queryKey:[`list`,e]}),r.invalidateQueries({queryKey:[`map`,e]})}})},JW=e=>e instanceof fl,YW=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}`},XW=(e,t)=>{let n=e.operation,r=n===void 0?void 0:t[n];return r?q(`operationFailed`,{index:n+1,label:YW(r),message:e.message}):q(`nothingSaved`,{message:e.message})},ZW=(e,t)=>new e.constructor({...e.problem,detail:XW(e,t)}),QW=(e,t)=>Object.fromEntries(Object.entries(e).filter(([e])=>e!==t)),$W=({model:e,stored:t,recordKey:n,mode:r,subject:i,draftKey:a,lines:o})=>{let s=U(),c=Se(),l=qW(e.name,n),u=OL(r,i),[d]=(0,I.useState)(()=>a?KU(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])=>Sg(e.fields[n],r,t.record[n])),T=w.length>0,E=T||!!o?.dirty;(0,I.useEffect)(()=>{d?.order&&o?.setOrder(d.order)},[]),(0,I.useEffect)(()=>{if(!a)return;let n=Object.fromEntries(Object.entries(f).filter(([t])=>!e.fields[t]?.sensitive)),r=Object.keys(n).length>0||!!o?.order;qU(localStorage,a,r?{etag:t.etag,fields:n,...o?.order&&{order:o.order}}:void 0)},[a,e,f,o?.order,t.etag]);let D=n=>n in f?f[n]:[`boolean`,`file`].includes(e.fields[n].type)?t.record[n]:dg(t.record[n]),O=(n,r)=>{x(e=>QW(e,n));let i=typeof r==`string`?r!==dg(t.record[n]):Sg(e.fields[n],r,t.record[n]);p(e=>i?{...e,[n]:r}:QW(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];Sg(s,o,r.record[n])&&(a[n]=o,dg(r.record[n])!==dg(t.record[n])&&(i[n]=s.type===`file`?Nm(s,r.record[n]):dg(r.record[n])))}p(a),y(i)},A=()=>Object.fromEntries(w.map(([t,n])=>[t,yg(e.fields[t],n)])),j=e=>{let t=ax(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 JW(e)?await k():pl(e)&&j(e),e}},te=async r=>{let i=T?[{op:`update`,resource:e.name,key:n,data:A(),etag:t.etag}]:[],a=[...i,...r.ops];try{await s.batchWrite(a)}catch(e){if(JW(e))await k(),await c.invalidateQueries({queryKey:[`list`]}),_(!0);else if(pl(e)){let t=e.operation===void 0?-1:e.operation-i.length,n=r.rows[t];t<0?j(e):n&&o?.reject(n,e)}throw pl(e)?ZW(e,a):e}await Promise.all([c.invalidateQueries({queryKey:H.record(e.name,n)}),c.invalidateQueries({queryKey:[`list`]}),c.invalidateQueries({queryKey:[`page`]}),c.invalidateQueries({queryKey:[`map`]})]),o?.reset()};return{value:D,change:O,save:()=>u.run(async()=>{let e=o?.plan();e&&e.ops.length>0?await te(e):await ee(),p({}),y({}),x({}),_(!1),h(!1)}),dirty:E,discard:()=>{p({}),y({}),x({}),_(!1),h(!1),o?.reset()},restored:m&&E,dismissRestored:()=>h(!1),linesConflict:g,saving:u.phase===`saving`,phase:u.phase,message:u.message,conflicts:v,errors:b,rejections:S,keepMine:e=>y(t=>QW(t,e)),useTheirs:e=>{y(t=>QW(t,e)),p(t=>QW(t,e))}}},eG=sn(),tG=(e,t)=>{let[n,...r]=e.primaryKey;if(!(!e.tenantAcross||e.tenant===void 0||n===void 0||r.length>0||!e.fields[n]?.filterable))return{filter:Yt(eG.eq(n,t)),pageSize:1,fields:[n,e.tenant]}},nG=(e,t,n)=>{let r=t?.[e.tenant];if(r!=null&&String(r)!==n)return String(r)},rG=(e,t)=>{let n=U(),{session:r,organizations:i}=V(),a=(0,I.useMemo)(()=>i?tG(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=nG(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},iG=(e,t,n,r)=>{let i=U(),a=Se(),o=p_(),s=Object.values(e.fields).filter(n=>n.type===`relation`&&n.relation&&n.name!==e.tenant&&r[n.name]!=null&&t[n.relation.resource]?.primaryKey.length===1),c=f({queries:s.map(e=>{let o=t[e.relation.resource];return Ab(a,i,o,n[o.name],String(r[e.name]))})}),l=s.map(e=>({kind:`record`,resource:e.relation.resource,key:String(r[e.name])}));return{addresses:Object.fromEntries(s.map((e,t)=>[e.name,l[t]])),labels:Object.fromEntries(s.map((e,i)=>{let a=t[e.relation.resource];return[e.name,jb(c[i]?.data,o,a,n[a.name],String(r[e.name]))]}))}},aG=sn(),oG=(e,t,n,r)=>{if(e.primaryKey.length!==1)return[];let i=new Set(Sn(r).flatMap(e=>e.kind===`related`&&!e.through&&!e.from?[`${e.resource}.${e.field}`]:[])),a=Object.values(t).flatMap(t=>Object.values(t.fields).filter(t=>t.type===`relation`&&t.relation?.resource===e.name&&t.relation.columns.length===1&&t.filterable).filter(e=>e.name!==t.tenant&&!i.has(`${t.name}.${e.name}`)).map(e=>({source:t,field:e.name})));return a.map(({source:e,field:t})=>{let r=n[e.name],i=r?.names?.plural??F(e.name),o=a.filter(t=>t.source.name===e.name).length>1;return{resource:e.name,field:t,label:o?`${i} (${r?.fields[t]?.label??F(t)})`:i}})},sG=(e,t)=>({kind:`list`,resource:e.resource,filter:Yt(aG.eq(e.field,t))}),cG=sn(),lG=(e,t,n)=>{let r=U(),i=f({queries:e.map(e=>{let i=Yt(cG.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}]})},uG=({model:e,recordKey:t,layout:n})=>{let{resources:r,views:i}=W(),a=lG(oG(e,r,i,n),r,t);return a.length===0?null:(0,B.jsx)(og,{title:Q(`relatedRecords`),children:(0,B.jsx)(`ul`,{className:`-mx-2`,children:a.map(({relation:e,count:n})=>(0,B.jsx)(`li`,{children:(0,B.jsxs)(Uh,{to:sG(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)(vh,{className:`h-4 w-6`}):`${wp(n.count)}${n.exact?``:`+`}`,(0,B.jsx)(Oi,{className:`size-4 text-faint-foreground group-hover:text-foreground`})]})]})},`${e.resource}.${e.field}`))})})},dG=sn(),fG=(...e)=>{let t=e.filter(e=>!!e);return t.length===1?t[0]:t.map(e=>`(${e})`).join(` AND `)},pG=(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?fG(Yt(dG.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 gw(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:fG(Yt(dG.in(e.field,c.data)),e.filter),isPending:!1,error:null}:{filter:void 0,isPending:c.isPending,error:c.error}:{filter:fG(Yt(dG.eq(e.field,t)),e.filter),isPending:!1,error:null}},mG=()=>(0,B.jsx)(`div`,{className:`flex flex-col gap-2`,children:Array.from({length:3},(e,t)=>(0,B.jsx)(vh,{className:`h-4 w-full`},t))}),hG=({empty:e})=>(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:e??Q(`nothingYet`)}),gG=({item:e,value:t,owner:n})=>{let{resources:r,views:i}=W(),a=r[e.resource],o=a&&i[a.name],s=pG(e,t),[c,l]=kA(o,`related:${n}:${e.title}`,e.display),u=af(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:()=>yy(p,a,s.filter??``).queryFn()});if(!a||e.hideEmpty&&(s.isPending||s.filter===null||m&&(h.isPending||h.data===0)))return null;let g=xA(e,a,r),_=e.columns??Tr(a,o).filter(t=>t!==e.field),v=t=>s.isPending?(0,B.jsx)(mG,{}):s.error?(0,B.jsx)(Bg,{title:Q(`couldNotLoadRelated`),error:s.error}):s.filter===null||s.filter===void 0?(0,B.jsx)(hG,{empty:e.empty}):t(s.filter);if(e.presentation===`cards`)return(0,B.jsx)(Vf,{title:e.title,help:e.help,children:v(t=>(0,B.jsx)(GS,{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=jD(e,a,u),b=(0,B.jsx)(EA,{view:o,value:c,onChange:l}),x=y?(0,B.jsxs)(`div`,{className:`flex items-center gap-2`,children:[!d&&b,(0,B.jsx)(qV,{size:`sm`,sorting:d,onChange:f})]}):b;return d&&y?(0,B.jsx)(Vf,{title:e.title,help:e.help,actions:x,children:(0,B.jsx)(KV,{model:a,view:o,field:y,filter:Yt(dG.eq(e.field,t)),columns:_})}):(0,B.jsx)(Vf,{title:e.title,help:e.help,actions:x,children:v(t=>(0,B.jsx)(OA,{model:a,view:o,filter:t,sort:e.sort??``,columns:_,limit:e.limit??10,display:c,empty:e.empty,opens:g},t))})},_G=(e,t,n)=>{if(e.from===void 0)return n;let r=t[e.from];return typeof r==`boolean`?r:SA(t,e.from)??null},vG=(e,t)=>t===e.tenant||e.primaryKey.includes(t),yG=(e,t,n)=>{if(t&&t.layout.length>0)return t.layout;let r=Object.values(e.fields).filter(t=>!vG(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`)}]:[]]},bG=({resource:e,recordKey:t})=>{let{resources:n,views:r}=W(),{address:i}=Hh(),a=n[e],o=QP(e,t);if(!a)return(0,B.jsx)(tf,{title:q(`notFound`),children:q(`noResource`,{name:e})});if(o.isPending)return(0,B.jsx)(tf,{title:Q(`loading`),children:Q(`fetching`)});if(o.error)return(0,B.jsx)(`div`,{className:`p-8`,children:pl(o.error)&&o.error.status===404?(0,B.jsx)(xG,{model:a,recordKey:t}):(0,B.jsx)(Bg,{title:Q(`couldNotLoad`),error:o.error})});let s=(0,B.jsx)(SG,{model:a,recordKey:t,stored:o.data,preview:o.isPlaceholderData},o.isPlaceholderData?`preview`:`loaded`),c=r[e]?.record;if(!c||i?.kind===`record`&&i.standard)return s;if(o.isPlaceholderData)return(0,B.jsx)(tf,{title:Q(`loading`),children:Q(`fetching`)});let{record:l,etag:u,permissions:d}=o.data;return(0,B.jsx)(dU,{component:c.component,scope:{model:a,record:l,key:t,etag:u,permissions:d},standard:s})},xG=({model:e,recordKey:t})=>{let n=rG(e,t);return n.state===`looking`?(0,B.jsx)(tf,{title:Q(`loading`),children:Q(`fetching`)}):n.state===`switching`?(0,B.jsx)(tf,{title:Q(`loading`),children:Q(`openingElsewhere`)}):n.state===`failed`?(0,B.jsx)(Bg,{title:Q(`couldNotLoad`),error:n.error}):(0,B.jsx)(tf,{title:q(`notFound`),children:Q(`noRecord`)})},SG=({model:e,recordKey:t,stored:n,preview:r})=>{let i=W(),{address:a,go:o}=Hh(),s=i.views[e.name],c=p_()(e,s,n.record,t),{state:l}=V(),u=rW(e,t),d=$W({model:e,stored:n,recordKey:t,mode:s?.saveFeedback??`toast`,subject:c,draftKey:!r&&l.kind===`signed-in`?GU(l.user.id,e.name,t):void 0,lines:u.draft}),f=Se(),p=U(),m=sx(d.rejections),h=af(e.name),g=QL(e),_=oy(h,`update`)&&n.permissions?.update!==!1,{shown:v,offersEdit:y,editing:b}=Cg(s?.recordMode,_,a?.kind===`record`&&a.edit===!0);Vh(d.dirty&&v===`form`||d.saving),Md(d.dirty);let x=a?.kind===`record`?a.open:void 0,S=a?.kind===`record`&&a.edit===!0,C=a?.kind===`record`?a.tab:void 0,w=a?.kind===`record`&&a.standard===!0,T=(n=[],r=!1,i)=>({kind:`record`,resource:e.name,key:t,...r&&{edit:r},...n.length>0&&{open:n},...i&&{tab:i},...w&&{standard:w}}),E=T(x,!1,C),D=T(x,!0,C),O=v===`form`&&s?.recordMode!==void 0&&s.recordMode!==`edit`,k=oy(h,`delete`)&&n.permissions?.delete!==!1,A=ZL({model:e,view:s,restore:g,onDeleted:()=>o({kind:`list`,resource:e.name},{replace:!0}),onReview:()=>void f.invalidateQueries({queryKey:H.record(e.name,t)})}),j=iG(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,bg(e,d.value(e.name))]))},re=iG(e,i.resources,i.views,ne),ie=(e,t)=>{let n=ee(e);if(!n||!Og(t))return d.change(e,t);f.setQueryData(H.relatedLabel(n.name,t.key),{label:t.label}),d.change(e,jg(n,t.key))},{fields:ae}=c_(),oe={model:e,record:n.record,key:t,etag:n.etag,permissions:n.permissions},se=KW(yG(e,s,v===`read`),oe,b,r),{before:ce,tabs:le,after:ue}=DU(se),de=OU(le,C),fe=e=>b&&(d.errors[e]!==void 0||d.conflicts[e]!==void 0);(0,I.useEffect)(()=>{if(d.rejections===0)return;let e=AU(le,de,fe);e&&o(T(x,S,e===le[0]?void 0:e.title),{replace:!0})},[d.rejections]);let pe=se.flatMap(e=>e.kind===`sidebar`?e.fields:[]),me=e.fields.status?.type===`enum`,he=n.record.status,ge=me&&!pe.includes(`status`)&&he!=null&&he!==``?String(he):void 0,_e=lU(e,`updated`),ve=e=>s?.fields[e],ye=t=>cy(n.permissions,t)!==`hidden`&&Eg(ve(t)?.when,b)&&(v===`form`||!e.fields[t]?.writeOnly),be=e=>!r||Object.hasOwn(n.record,e),xe=r=>{let a=e.fields[r],o=cy(n.permissions,r);if(!a||o===`hidden`)return null;let c=d.conflicts[r],l=ee(r),u=ve(r)?.label??F(r),f=d.errors[r];return(0,B.jsx)(Yh,{name:r,label:u,required:v===`form`&&o!==`read`&&hg(a),help:Tg(ve(r),s,b),error:f&&ix(a,u,f),wide:!!(ve(r)?.multiline||ve(r)?.markdown),conflict:c===void 0?void 0:{user:{name:Q(`someoneElse`),initials:`?`,hue:40},ago:Q(`justNow`),theirValue:c||`—`,onKeepMine:()=>d.keepMine(r),onUseTheirs:()=>d.useTheirs(r)},children:be(r)?(0,B.jsx)(Ov,{field:a,hints:ve(r),value:d.value(r),stored:n.record[r],relationLabel:re.labels[r],relationTo:re.addresses[r],relationPicker:l&&{target:l,view:i.views[l.name]},locked:v!==`form`||o===`read`,invalid:!!d.errors[r],reveal:a.sensitive&&!a.writeOnly?()=>p.reveal(e.name,t,r):void 0,resource:e.name,onChange:e=>ie(r,e)}):(0,B.jsx)(vh,{className:`h-9`})},a.sensitive?`${r}:${n.etag}`:r)},Ce=r=>{let i=e.fields[r],a=be(r)?i.sensitive?(0,B.jsx)(Ov,{field:i,hints:ve(r),value:``,stored:n.record[r],locked:!0,reveal:()=>p.reveal(e.name,t,r),resource:e.name,onChange:e=>d.change(r,e)}):(0,B.jsx)(Lb,{model:e,field:i,value:n.record[r],relationLabel:j.labels[r]}):(0,B.jsx)(vh,{className:`h-4 w-32`});return{label:ve(r)?.label??F(r),help:Tg(ve(r),s,b),wide:!!(ve(r)?.multiline||ve(r)?.markdown),value:a}},we=se.findIndex(e=>e.kind===`sidebar`),Te=(0,B.jsx)(sg,{title:Q(`summary`),rows:pe.flatMap(t=>{let r=e.fields[t];if(!r||!ye(t))return[];if(!be(t))return[{label:ve(t)?.label??F(t),value:(0,B.jsx)(vh,{className:`h-4 w-24`})}];let i=n.record[t],a=gm(r,ve(t))&&typeof i==`string`&&i!==``?hm(i):Nm(r,i,ve(t)),o=r.type===`text`&&typeof i==`string`&&i!==``?xm(ve(t)):void 0,s=r.type===`enum`?(0,B.jsx)(Nb,{value:i,hints:ve(t),children:a}):o?(0,B.jsx)(bv,{format:o,value:a}):(0,B.jsx)(`span`,{title:Pm(r,i,void 0,ve(t)),children:a}),c=ev(ae,r,ve(t));return[{label:ve(t)?.label??F(t),title:a,value:c?(0,B.jsx)(dv,{shown:c,part:`display`,field:r,value:n.record[t],fallback:s}):s}]})}),Ee=async()=>{await d.save()&&O&&o(E,{replace:!0})},De=k?()=>void A.start({key:t,title:c,etag:n.etag,snapshot:n.record}):void 0,Oe=v===`form`&&(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(G,{variant:`primary`,className:`max-md:min-h-11 max-md:flex-1 md:w-full`,loading:d.saving,disabled:!d.dirty&&d.phase!==`saved`,onClick:()=>void Ee(),children:[d.phase===`saved`&&(0,B.jsx)(Si,{className:`size-4`}),d.phase===`saved`?Q(`saved`):Q(`save`)]}),O&&(0,B.jsx)(Uh,{to:E,className:P(mf(),`max-md:min-h-11 md:w-full`),onClick:e=>bh(e)&&d.discard(),children:Q(`cancel`)}),d.dirty&&(0,B.jsx)(`span`,{className:`text-xs text-muted-foreground max-md:order-first`,children:Q(`unsavedChanges`)})]}),ke=(i,a)=>{if(i.kind===`group`){let e=i.items.flatMap(ke);if(e.length===0)return[];let t=EU(i,x,fe),n=i.collapsed?T(TU(x,i.title),S,C):void 0;return[(0,B.jsx)(Gh,{title:i.title,open:t,toggle:n,children:e},`group:${i.title}`)]}if(i.kind===`related`&&i.lines)return!u.model||!u.item||r?[]:[(0,B.jsx)(WU,{lines:{...u,model:u.model,item:u.item},editable:v===`form`,saving:d.saving},`lines:${i.title}`)];if(i.kind===`related`)return i.from!==void 0&&!be(i.from)?[]:[(0,B.jsx)(gG,{item:i,value:_G(i,n.record,t),owner:e.name},`related:${i.title}`)];if(i.kind===`chart`)return[(0,B.jsx)(SU,{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)(uU,{item:i,scope:oe},`custom:${a}`)];if(i.kind===`map`)return i.sidebar?[]:[(0,B.jsx)(hU,{item:i,record:n.record},`map:${a}`)];if(i.kind===`gallery`)return[(0,B.jsx)(wW,{item:i,record:n.record,recordKey:t},`gallery:${a}`)];if(i.kind===`history`)return[(0,B.jsx)(MW,{item:i,model:e,view:s,recordKey:t,etag:n.etag},`history:${a}`)];if(i.kind===`comments`)return[(0,B.jsx)(VW,{item:i,resource:e.name,recordKey:t,canWrite:l.kind!==`visitor`},`comments:${a}`)];if(i.kind!==`section`)return[];let o=i.fields.filter(t=>e.fields[t]&&ye(t)),c=v===`read`&&i.presentation===`facts`,f=c?Rm(n.record,o):o;return f.length===0?[]:[(0,B.jsx)(Vf,{title:i.title,help:wg(i.helpWhen,s,b)?i.help:void 0,children:c?(0,B.jsx)(Zh,{facts:f.map(e=>({label:Ce(e).label,value:Ce(e).value,icon:$T(ve(e)?.icon)}))}):v===`read`?(0,B.jsx)(Xh,{rows:f.map(Ce)}):(0,B.jsx)(`div`,{className:`grid grid-cols-1 gap-x-6 gap-y-5 sm:grid-cols-2`,children:f.map(xe)})},i.title)]};return(0,B.jsxs)(`div`,{ref:m,className:`flex flex-1 flex-col`,inert:r,children:[A.dialogs,(0,B.jsx)(`div`,{className:`flex-1`,children:(0,B.jsxs)(`div`,{className:`mx-auto max-w-[1100px] px-4 pb-8 pt-6 md:px-10 md:py-8`,children:[(0,B.jsx)(zf,{title:c,status:ge?{label:ir(ge,ve(`status`)?.valueLabels),tone:Em(ve(`status`)?.valueColors,ge)}:void 0}),d.message&&(0,B.jsx)(`div`,{className:`mt-4`,children:(0,B.jsx)(Bg,{title:Q(`notSaved`),error:Error(d.message)})}),d.linesConflict&&(0,B.jsx)(`div`,{className:`mt-4`,children:(0,B.jsx)(Bg,{title:Q(`linesChanged`),error:Error(Q(`linesReloaded`))})}),v!==`form`&&y&&d.dirty&&(0,B.jsxs)(`div`,{className:`mt-4 flex items-center justify-between gap-3 rounded-lg border bg-surface px-3 py-2`,role:`status`,children:[(0,B.jsx)(`span`,{children:Q(`unsavedKept`)}),(0,B.jsxs)(`span`,{className:`flex gap-2`,children:[(0,B.jsx)(Uh,{to:D,className:mf({size:`sm`}),children:Q(`continueEditing`)}),(0,B.jsx)(G,{size:`sm`,onClick:d.discard,children:Q(`discard`)})]})]}),v===`form`&&d.restored&&(0,B.jsxs)(`div`,{className:`mt-4 flex items-center justify-between gap-3 rounded-lg border bg-surface px-3 py-2`,role:`status`,children:[(0,B.jsx)(`span`,{children:Q(`unsavedRestored`)}),(0,B.jsxs)(`span`,{className:`flex gap-2`,children:[(0,B.jsx)(G,{size:`sm`,onClick:d.dismissRestored,children:Q(`keep`)}),(0,B.jsx)(G,{size:`sm`,onClick:d.discard,children:Q(`discard`)})]})]}),(0,B.jsxs)(`div`,{className:`grid grid-cols-1 gap-8 md:grid-cols-[minmax(0,1fr)_300px] md:gap-12`,children:[(0,B.jsxs)(`main`,{className:`divide-y divide-border`,children:[ce.flatMap(ke),de&&(0,B.jsx)(Kh,{tabs:le.map((e,t)=>({title:e.title,to:T(x,S,t===0?void 0:e.title),current:e===de}))}),de&&(0,B.jsx)(`div`,{className:`divide-y divide-border`,children:de.items.flatMap(ke)},`tab:${de.title}`),ue.flatMap(ke)]}),(0,B.jsxs)(`aside`,{className:`space-y-4 md:sticky md:top-[var(--pb-sticky-top,0px)] md:max-h-[calc(100dvh-var(--pb-sticky-top,0px)-var(--pb-sticky-bottom,0px))] md:self-start md:overflow-y-auto md:pb-4 md:pt-8`,children:[Oe&&(0,B.jsx)(`div`,{className:`hidden flex-col items-center gap-2 md:flex`,children:Oe}),!r&&(0,B.jsx)(wU,{model:e,stored:n,recordKey:t,edit:y?D:void 0,onDelete:De}),we===-1&&Te,se.map((e,t)=>e.kind===`custom`&&e.sidebar&&!r?(0,B.jsx)(uU,{item:e,scope:oe},`custom:${t}`):e.kind===`map`&&e.sidebar&&!r?(0,B.jsx)(hU,{item:e,record:n.record},`map:${t}`):t===we?(0,B.jsx)(I.Fragment,{children:Te},`summary`):null),(0,B.jsx)(sg,{title:Q(`details`),rows:[lU(e,`created`),_e].flatMap(t=>{let r=t?e.fields[t]:void 0;return!t||!r||!ye(t)||pe.includes(t)?[]:[{label:ve(t)?.label??F(t),value:be(t)?(0,B.jsx)(`span`,{title:Pm(r,n.record[t],void 0,ve(t)),children:Nm(r,n.record[t],ve(t))}):(0,B.jsx)(vh,{className:`h-4 w-24`})}]})}),!r&&(0,B.jsx)(uG,{model:e,recordKey:t,layout:se})]})]})]})}),Oe&&(0,B.jsx)(`div`,{className:`sticky bottom-[var(--pb-sticky-bottom,0px)] z-20 flex shrink-0 items-center gap-2 border-t bg-background p-3 md:hidden`,children:Oe})]})},CG=e=>pl(e)?e.status===401||e.status===403?q(`signInRefused`,{message:e.message}):e.message:q(`noAnswer`),wG=({status:e})=>{let t=Se();return e.state===`error`?(0,B.jsx)(`div`,{className:`flex h-full min-h-48 flex-1 items-center justify-center p-8`,children:(0,B.jsxs)(`div`,{className:`max-w-md text-center`,children:[(0,B.jsx)(`h1`,{className:`text-[16px] font-semibold`,children:q(`cannotReach`,{label:e.source.label})}),(0,B.jsxs)(`p`,{className:`mt-1 text-muted-foreground`,children:[CG(e.error),` `,q(`restWorks`)]}),(0,B.jsx)(G,{className:`mt-3`,onClick:()=>void t.refetchQueries({queryKey:H.sourceMetas(e.source.url)}),children:q(`tryAgain`)})]})}):(0,B.jsxs)(`div`,{className:`flex h-full min-h-48 flex-1 items-center justify-center gap-2 text-muted-foreground`,children:[(0,B.jsx)($d,{}),` `,q(`loadingFrom`,{label:e.source.label})]})},TG=M(`app/search`),EG=(e,t)=>e.toLowerCase().includes(t.trim().toLowerCase()),DG=(e,t,n=``)=>{let r=rV(e,n).flatMap(e=>e.items.filter(e=>e.href!==void 0&&!e.problem)).filter(e=>EG(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||!$L(a,e.pages,e.permissions[r.name]??Ud))return[];let o=a.names?.singular??F(r.name),s=Dg(`title`,{noun:o});return!EG(s,t)&&!EG(o,i)&&!EG(a.names?.plural??F(r.name),i)?[]:[{id:`new:${r.name}`,title:s,href:Bc({kind:`create`,resource:r.name},n)}]});return[...r.length>0?[{id:`go-to`,label:TG(`goTo`),hits:r.map(e=>({id:`go-to:${e.id}`,title:e.label,href:e.href}))}]:[],...a.length>0?[{id:`create`,label:TG(`create`),hits:a.slice(0,5)}]:[]]},OG=sn(),kG=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)}]}),AG=e=>{let t=e.map(e=>e.label.toLowerCase());return t.length===0?TG(`search`):t.length===1?TG(`searchOne`,{name:t[0]}):t.length===2?TG(`searchTwo`,{first:t[0],second:t[1]}):TG(`searchMore`,{first:t[0],second:t[1]})},jG=e=>Yt(OG.search(e.trim())),MG=e=>!e.view?.searchResult?.title?.length&&e.view?.titleFrom!==void 0,NG=e=>{let t=e.view?.searchResult?.title;return t?.length?t:MG(e)?[]:[cr(e.model,e.view)]},PG=e=>{let t=NG(e);return e.view?.searchResult?.subtitle??e.model.search?.find(e=>!t.includes(e))},FG=e=>{let t=PG(e),n=MG(e)?l_(e.model,e.view):[],r=[...NG(e),...n,...t?[t]:[],...e.model.search??[]];return[...new Set([...e.model.primaryKey,...r.filter(t=>Object.hasOwn(e.model.fields,t))])]},IG=(e,t,n)=>{let r=t[n];return r==null?``:e.model.fields[n]?.type===`enum`?ir(String(r),e.view?.fields[n]?.valueLabels):String(r)},LG=(e,t,n,r=``,i=u_({},{user:void 0,member:()=>void 0}))=>{let a=Nn(ym(e.model,t)),o=NG(e),s=PG(e),c=Gt(e.model,t,n,[...o,...s?[s]:[]])??s,l=c?IG(e,t,c):``;return{id:a,title:MG(e)?i(e.model,e.view,t,a):o.map(n=>IG(e,t,n)).filter(Boolean).join(` `)||a,...l&&{subtitle:l},href:Bc({kind:`record`,resource:e.model.name,key:a},r)}},RG=()=>{let e=W(),t=U(),{basePath:n}=jh(),r=p_(),i=(0,I.useMemo)(()=>kG(e),[e]),[a,o]=(0,I.useState)(``),s=a.trim(),c=eT(s,200),l=s.length>=2,u=l&&c.length>=2,d=f({queries:i.map(e=>({queryKey:[`global-search`,e.model.name,c],enabled:u,staleTime:1/0,gcTime:0,queryFn:()=>t.list(e.model.name,{filter:jG(c),pageSize:5,fields:FG(e)})}))}),p=(0,I.useMemo)(()=>u?DG(e,c,n):[],[u,e,c,n]),m=i.flatMap((e,t)=>{let i=d[t];if(!u||!i)return[];if(i.error)return[{id:e.model.name,label:e.label,hits:[],failed:!0}];let a=(i.data?.items??[]).map(t=>LG(e,t,c,n,r));return a.length>0?[{id:e.model.name,label:e.label,hits:a}]:[]}),h=[...p,...m];return{available:Object.keys(e.pages).length>0||Object.keys(e.resources).length>0,placeholder:AG(i),text:a,setText:o,query:u?c:``,loading:l&&(s!==c||d.some(e=>e.isFetching)),groups:h}},zG=M(`app/new-version`),BG=()=>{let{versionChange:e,appName:t}=W(),{reload:n}=jh();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)(rs,{"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?zG.rich(`bannerTitle`,{app:t}):zG(`title`)}),(0,B.jsx)(`span`,{className:`text-xs`,children:zG(`bannerLine`)})]})]}):null},VG=()=>{let e=!!W().versionChange,{reload:t}=jh();return e?(0,B.jsxs)(G,{size:`sm`,variant:`ghost`,"aria-label":zG(`reloadPageHint`),title:zG(`reloadPageHint`),onClick:t,className:`max-md:size-9 max-md:p-0`,children:[(0,B.jsx)(rs,{className:`size-3.5 text-primary`}),(0,B.jsx)(`span`,{className:`max-md:sr-only`,children:zG(`reloadPage`)})]}):null},HG=()=>document.querySelector(`[aria-modal="true"]`)!==null,UG=()=>{let[e,t]=(0,I.useState)(HG);return(0,I.useEffect)(()=>{let e=new MutationObserver(()=>t(HG()));return e.observe(document.body,{childList:!0,subtree:!0}),t(HG()),()=>e.disconnect()},[]),e},WG=()=>{let e=!!W().versionChange,t=UG(),[n,r]=(0,I.useState)(!1),i=iy(),{reload:a}=jh(),o=e&&!n&&!t;return(0,I.useEffect)(()=>{if(!o)return;let e=i.show({state:`info`,sticky:!0,title:zG(`title`),description:zG(`description`),action:{label:zG(`reload`),onClick:a},onClose:()=>r(!0)});return()=>i.dismiss(e)},[o,i,a]),null},GG=M(`app/runtime`),KG=e=>!!(e?.updateAvailable&&e.indicator),qG=e=>e?5e3:18e5,JG=(e,t)=>{if(!e.updateStage)return GG(`updatingNow`);let n=GG(e.updateStage);return e.updateStartedAt?GG(`started`,{stage:n,ago:yp(Math.max(0,Math.floor((t-Date.parse(e.updateStartedAt))/1e3)))}):n},YG=(e,t=Date.now(),n=Gf())=>e.updating?JG(e,t):e.nextUpdateAt?GG(`nextOn`,{policy:GG(e.policy),when:dp(Date.parse(e.nextUpdateAt),n)}):GG(e.policy),XG=(e,t=Gf())=>{let n=dp(Date.parse(e.finishedAt),t),r=GG(e.outcome,{version:e.toVersion,when:n});return e.message?`${r}: ${e.message}`:`${r}.`},ZG=e=>pl(e)&&e.status<500&&e.problem.detail?e.problem.detail:pl(e)&&e.status===409?GG(`alreadyLatest`):pl(e)&&e.status===403?GG(`onlyAdmin`):GG(`couldNotStart`),QG=({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})]}),$G=({status:e,requesting:t,error:n,checkError:r,onUpdate:i,onClose:a})=>{let o=e.updating?void 0:e.lastUpdate;return(0,B.jsxs)(Cf,{title:GG(`runtimeUpdate`),description:e.updating?(0,B.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,B.jsx)($d,{className:`size-3.5`}),YG(e)]}):YG(e),onClose:a,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:a,children:GG(`close`)}),(0,B.jsx)(G,{variant:`primary`,loading:t,disabled:e.updating||!e.updateAvailable,onClick:i,children:e.updating?GG(`updating`):GG(`updateNow`)})]}),children:[(0,B.jsx)(QG,{label:GG(`currentVersion`),value:e.version}),(0,B.jsx)(QG,{label:GG(`latestVersion`),value:e.latest}),o&&(0,B.jsx)(`p`,{className:o.outcome===`failed`?`mt-3 text-danger-text`:`mt-3 text-muted-foreground`,children:XG(o)}),n!==void 0&&(0,B.jsx)(`p`,{role:`alert`,className:`mt-3 text-danger-text`,children:ZG(n)}),r!==void 0&&(0,B.jsx)(`p`,{className:`mt-3 text-muted-foreground`,children:GG(`checkFailed`)})]})},eK=e=>{let t=qP(),n=(0,I.useRef)(t);n.current=t;let r=t!==void 0;return(0,I.useMemo)(()=>r?rd({url:e,token:()=>n.current}):void 0,[e,r])},tK=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(),qG(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}},nK=({client:e})=>{let{status:t,update:n,requesting:r,error:i,checkError:a}=tK(e),[o,s]=(0,I.useState)(!1);return!t||!o&&!KG(t)?null:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(G,{size:`sm`,variant:`ghost`,"aria-label":GG(`updateAvailable`),title:GG(`updateAvailable`),onClick:()=>s(!0),className:`max-md:size-9 max-md:p-0`,children:[(0,B.jsx)(Mi,{className:`size-3.5 text-primary`}),(0,B.jsx)(`span`,{className:`max-md:sr-only`,children:GG(`update`)})]}),o&&(0,B.jsx)($G,{status:t,requesting:r,error:i,checkError:a,onUpdate:()=>void n(),onClose:()=>s(!1)})]})},rK=({url:e})=>(0,B.jsx)(nK,{client:eK(e)}),iK=({url:e,client:t})=>t?(0,B.jsx)(nK,{client:t}):(0,B.jsx)(rK,{url:e}),aK=({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 wu))throw e;a(BA(e)),r(!1)}};return(0,B.jsxs)(`div`,{role:`region`,"aria-label":q(`staffSession`),className:`flex flex-wrap items-center gap-x-3 gap-y-2 border-b border-warning/40 bg-warning-soft px-4 py-2 text-warning-text`,children:[(0,B.jsx)(tc,{"aria-hidden":!0,className:`size-4 shrink-0`}),(0,B.jsx)(`p`,{className:`min-w-64 flex-1 break-words`,children:q.rich(`staffSignedIn`,{staff:(0,B.jsx)(`span`,{className:`font-semibold`,children:e.staffName??e.staff}),user:(0,B.jsx)(`span`,{className:`font-semibold`,children:e.user}),until:dp(Date.parse(e.expiresAt)),reason:e.reason})}),i&&(0,B.jsx)(`p`,{role:`alert`,className:`text-body font-medium text-danger-text`,children:i}),(0,B.jsx)(G,{size:`sm`,loading:n,onClick:()=>void o(),children:q(`stopStaffSession`)})]})},oK=(e,t,n)=>{if(!e)return;let r=new Map((n??[]).map(e=>[e.userId,e]));return Object.fromEntries(Object.entries(e).map(([e,{person:n,...i}])=>{if(n===void 0)return[e,i];let a=r.get(n),o=rH(t,n);return[e,{...i,person:{...a&&{status:a},...o&&{presence:o}}}]}))},sK=(e,t,n)=>({filter:n.filter??``,orderBy:n.orderBy??dh(e,t),pageSize:n.limit??3,fields:[...new Set([...e.primaryKey,cr(e,t),...l_(e,t),...n.status===void 0?[]:[n.status]])]}),cK=(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?ir(i,t.fields[n.status]?.valueLabels):i,tone:n.tones?.[i]??`neutral`,pulse:n.pulse?.includes(i)??!1}},lK=(e,t,n,r,i,a,o)=>r.map(r=>{let s=Nn(ym(e,r)),c=cK(e,t,n,r);return{id:s,label:o(e,t,r,s),href:Bc({kind:`record`,resource:e.name,key:s},i),...c&&{status:c},active:s===a}}),uK=(e,t,n,r,i)=>{let a=n.find(t=>Nn(ym(e,t))===r);return a!==void 0&&t.some(e=>!Object.is(a[e],i[e]))},dK=(e,t,n)=>{if(t.marks===void 0||!n||!Object.hasOwn(n,t.marks))return;let r=n[t.marks];return()=>r(e)},fK=e=>e&&(()=>oK(e(),nH(),e_().data)),pK=({model:e,request:t})=>H.navRecent(e.name,t.filter,t.orderBy,t.pageSize),mK=e=>{let t=Se();(0,I.useEffect)(()=>t.getQueryCache().subscribe(n=>{if(n.type!==`updated`||n.action.type!==`success`)return;let[r,i,a]=n.query.queryKey,o=n.action.data?.record;if(r===`record`&&typeof a==`string`&&o)for(let n of e){if(n.model.name!==i)continue;let e=t.getQueryData(pK(n));e&&uK(n.model,n.request.fields,e.items,a,o)&&t.invalidateQueries({queryKey:pK(n),exact:!0})}}),[t,e])},hK=(e,t,n)=>{let r=U(),i=p_(),{marks:a}=c_(),o=(0,I.useMemo)(()=>{let t=ZB(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:sK(r,n,i),useMarks:fK(dK(r.name,i,a))}]:[]})},[e,a]);mK(o);let s=f({queries:o.map(e=>({queryKey:pK(e),queryFn:()=>r.list(e.model.name,e.request)}))});return Object.fromEntries(o.map(({model:e,view:r,recent:a,useMarks:o},c)=>{let l=s[c];if(l.isPending)return[e.name,{state:`loading`}];if(l.isError)return[e.name,{state:`error`}];let u=n.resource===e.name?n.key:void 0;return[e.name,{state:`ready`,records:lK(e,r,a,l.data.items,t,u,i),...o&&{useMarks:o}}]}))},gK=({answer:e,current:t,next:n,launch:r})=>{if(!e?.bundleId||e.bundleId===t)return{kind:`none`};let i=r&&e.required;return e.bundleId===n&&!i?{kind:`none`}:{kind:`take`,bundleId:e.bundleId,download:e.bundleId!==n,reload:i}},_K=6e4,vK=e=>{let t=typeof e==`object`&&e?e.bundleId:void 0;return typeof t==`string`?t:null},yK=({bridge:e,check:t,releasesUrl:n,onHold:r})=>{let i=(t,n={})=>e.nativePromise(`LiveUpdate`,t,n),a=t=>t instanceof e.Exception,o=async(e,t)=>{t&&await i(`downloadBundle`,{bundleId:e,url:`${n}/${e}`,artifactType:`manifest`}),await i(`setNextBundle`,{bundleId:e})},s=async(e,t)=>{let n=!0,a=()=>{n&&(n=!1,r(!1))};r(!0);let s=setTimeout(a,_K);try{await o(e,t),n&&await i(`reload`)}finally{clearTimeout(s),a()}},c=async e=>{let[n,r,c]=await Promise.all([t(),i(`getCurrentBundle`),i(`getNextBundle`)]),l=gK({answer:n,current:vK(r),next:vK(c),launch:e});if(l.kind!==`none`)try{await(l.reload?s(l.bundleId,l.download):o(l.bundleId,l.download))}catch(e){if(!a(e))throw e}},l;return{ready:()=>i(`ready`),check:e=>(l??=c(e).finally(()=>{l=void 0}),l)}},bK=e=>/(?:^|\s)ProtobaseNative\/([0-9a-f]{16})(?:\s|$)/.exec(e)?.[1],xK=/^[A-Za-z0-9_-]{1,64}$/,SK=e=>typeof e==`object`&&!!e&&!Array.isArray(e),CK=e=>{if(!SK(e))return;let{bundleId:t,url:n,required:r}=e;if((t===null||typeof t==`string`&&xK.test(t))&&(n===null||typeof n==`string`)&&typeof r==`boolean`)return{bundleId:t,url:n,required:r}},wK=15e3,TK=e=>e instanceof TypeError||e instanceof DOMException&&e.name===`TimeoutError`,EK=async(e,{apiOrigin:t,fingerprint:n,shellVersion:r})=>{let i=`${t}${dr}?${pr({fingerprint:n,shellVersion:r})}`;try{let t=await e(i,{credentials:`omit`,cache:`no-store`,signal:AbortSignal.timeout(wK)});return t.status===200?CK(await t.json()):void 0}catch(e){if(TK(e)||e instanceof SyntaxError)return;throw e}},DK=({bridge:e,apiOrigin:t,userAgent:n,fetch:r,onHold:i})=>{if(!e?.Exception||!e.isPluginAvailable(`LiveUpdate`))return;let a=bK(n);return yK({bridge:{nativePromise:e.nativePromise.bind(e),Exception:e.Exception},check:async()=>a&&t?EK(r,{apiOrigin:t,fingerprint:a,shellVersion:OP}):void 0,releasesUrl:`${t}${fr}`,onHold:i})},OK=M(`app/live-update`),kK=({nativeBridge:e,apiOrigin:t,children:n})=>{let[r,i]=(0,I.useState)(!1),a=(0,I.useMemo)(()=>DK({bridge:e,apiOrigin:t,userAgent:navigator.userAgent,fetch:window.fetch.bind(window),onHold:i}),[e,t]);return(0,I.useEffect)(()=>{if(!a)return;a.ready(),a.check(!0);let e=()=>{document.visibilityState===`visible`&&a.check(!1)};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[a]),r?(0,B.jsx)(tf,{title:OK(`holdTitle`),children:OK(`holdLine`)}):n},AK=[`never`,`thirty_minutes`,`one_hour`,`four_hours`,`today`,`this_week`,`custom`],jK={thirty_minutes:30,one_hour:60,four_hours:240},MK=(e,t)=>new Date(e.getFullYear(),e.getMonth(),e.getDate()+t),NK=(e,t,n=``)=>{if(e===`never`)return null;if(e===`today`)return MK(t,1).toISOString();if(e===`this_week`)return MK(t,(8-t.getDay())%7||7).toISOString();if(e===`custom`){let e=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2})?$/.test(n)?new Date(n):void 0;return e&&!Number.isNaN(e.getTime())?e.toISOString():void 0}return new Date(t.getTime()+jK[e]*6e4).toISOString()},PK=e=>String(e).padStart(2,`0`),FK=e=>{let t=new Date(e);return`${t.getFullYear()}-${PK(t.getMonth()+1)}-${PK(t.getDate())}T${PK(t.getHours())}:${PK(t.getMinutes())}`},IK=(e,t=Date.now())=>{let n=wr(e,t);return n?{availability:n.availability,text:n.text??``,clears:n.clearsAt===null?`never`:`custom`,custom:n.clearsAt===null?``:FK(n.clearsAt)}:{availability:`automatic`,text:``,clears:`never`,custom:``}},LK=(e,t)=>{let n=e.text.trim(),r=n===``?void 0:Cr(n);if(r)return{problem:`text`,message:r};let i=NK(e.clears,t,e.custom);return i===void 0||i!==null&&Date.parse(i)<=t.getTime()?{problem:`time`}:{input:{availability:e.availability,text:n===``?null:n,clearsAt:i}}},RK={never:`never`,thirty_minutes:`thirtyMinutes`,one_hour:`oneHour`,four_hours:`fourHours`,today:`today`,this_week:`thisWeek`,custom:`custom`},zK=({current:e,onSave:t,onClear:n,onClose:r})=>{let[i,a]=(0,I.useState)(()=>IK(e)),[o,s]=(0,I.useState)(!1),[c,l]=(0,I.useState)(),[u,d]=(0,I.useState)(!1),f=(0,I.useId)(),p=(0,I.useId)(),m=(0,I.useId)(),h=e=>a({...i,...e}),g=LK(i,new Date),_=u&&`problem`in g?g:void 0,v=async e=>{s(!0),l(void 0);try{await e(),r()}catch(e){if(!(e instanceof dl))throw e;l(e.status===400?e.message:Qx(`couldNotSave`)),s(!1)}},y=()=>{d(!0),`input`in g&&v(()=>t(g.input))};return(0,B.jsx)(Cf,{title:Qx(e?`editStatus`:`setStatus`),onClose:r,actions:(0,B.jsxs)(B.Fragment,{children:[e&&(0,B.jsx)(G,{variant:`ghost`,className:`sm:mr-auto`,disabled:o,onClick:()=>void v(n),children:Qx(`clear`)}),(0,B.jsx)(G,{onClick:r,children:Qx(`cancel`)}),(0,B.jsx)(G,{variant:`primary`,type:`submit`,form:f,loading:o,children:Qx(`save`)})]}),children:(0,B.jsxs)(`form`,{id:f,className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),y()},children:[(0,B.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,B.jsx)(`label`,{htmlFor:p,className:`font-medium`,children:Qx(`statusText`)}),(0,B.jsx)(J,{id:p,name:`status`,autoComplete:`off`,autoFocus:!0,placeholder:Qx(`statusPlaceholder`),value:i.text,maxLength:200,invalid:_?.problem===`text`,..._?.problem===`text`&&{"aria-describedby":`${p}-problem`},onChange:e=>h({text:e.target.value})}),_?.problem===`text`&&(0,B.jsx)(`span`,{id:`${p}-problem`,className:`text-xs text-danger-text`,children:_.message})]}),(0,B.jsxs)(`div`,{className:`flex flex-col gap-1.5 font-medium`,children:[Qx(`availability`),(0,B.jsx)(Re,{label:Qx(`availability`),value:i.availability,onChange:e=>h({availability:e}),options:[{value:`automatic`,label:Qx(`automatic`)},{value:`busy`,label:Qx(`busy`)},{value:`do_not_disturb`,label:Qx(`doNotDisturb`)}]}),i.availability===`do_not_disturb`&&(0,B.jsx)(`span`,{className:`text-xs font-normal text-muted-foreground`,children:Qx(`doNotDisturbHint`)})]}),(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[Qx(`clearsAfter`),(0,B.jsx)(`select`,{name:`clears`,value:i.clears,onChange:e=>h({clears:e.target.value}),className:`h-8 rounded-md border border-border-strong bg-background px-2 font-normal`,children:AK.map(e=>(0,B.jsx)(`option`,{value:e,children:Qx(RK[e])},e))})]}),i.clears===`custom`&&(0,B.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,B.jsx)(`label`,{htmlFor:m,className:`font-medium`,children:Qx(`clearsAt`)}),(0,B.jsx)(J,{id:m,type:`datetime-local`,name:`clears-at`,value:i.custom,invalid:_?.problem===`time`,..._?.problem===`time`&&{"aria-describedby":`${m}-problem`},onChange:e=>h({custom:e.target.value})}),_?.problem===`time`&&(0,B.jsx)(`span`,{id:`${m}-problem`,className:`text-xs text-danger-text`,children:Qx(`pickTime`)})]}),c&&(0,B.jsx)(`p`,{role:`alert`,className:`text-danger-text`,children:c})]})})},BK=e=>{let t=U(),n=Se(),r=t_(),[i,a]=(0,I.useState)(!1);if(!e||!r.isSuccess)return{};let o=wr(r.data),s=()=>n.invalidateQueries({queryKey:[`statuses`]});return{menu:{mark:o&&(0,B.jsx)(nS,{status:o,textShown:`hover`}),label:o?(0,B.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5 text-foreground`,children:[(0,B.jsx)(tS,{availability:o.availability}),(0,B.jsx)(`span`,{className:`truncate`,children:o.text??eS(o.availability)})]}):Qx(`setStatus`),onOpen:()=>a(!0)},...i&&{dialog:(0,B.jsx)(zK,{current:o,onSave:async e=>{await t.status.set(e),await s()},onClear:async()=>{await t.status.clear(),await s()},onClose:()=>a(!1)})}}},VK=e=>e?.kind===`page`?e.page:e?.kind===`list`?$B(e.resource,e.list):e?.resource,HK=e=>e?.kind===`record`?e:void 0,UK=({workspace:e,sidebarMode:t,assistant:n,runtime:r})=>{let i=W(),{state:a,session:o,signOut:s,stopStaffSession:c,organizations:l}=V(),u=tE();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}=jh(),{address:g,go:_,open:v,back:y}=Hh(),b=VK(g),x=HK(g),S=RG(),C=dI(),w=hK(i,h,{resource:x?.resource,key:x?.key});XP(i);let T=rV(i,h,w),E=(0,I.useMemo)(()=>AH(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?Xd(i,O):void 0,A=O?Cn(i.views[O],g?.kind===`list`?g.list:void 0):void 0,j=T.find(e=>e.items.some(e=>e.id===b)),ee=O?i.resources[O]:void 0,te=QP(x?.resource??``,x?.key??``,!!(ee&&x)),ne=p_(),re=ee&&x&&te.data?ne(ee,A,te.data.record,x.key):void 0,ie=!!x&&(te.isLoading||k?.state===`loading`),{shell:ae}=c_(),oe=ae?.actions,se=ae?.rightPanel,ce=i.bell&&d&&!f&&(0,B.jsx)(iU,{own:ae?.bell}),le=BK(!!(i.status&&d&&!f)),ue=e_().data,de=nH(),[fe,pe]=(0,I.useState)(!1),me=i.assistant?.url,he=me&&(0,B.jsx)(gL,{open:fe,onToggle:()=>pe(!fe)}),ge=me&&fe&&(0,B.jsx)(yL,{url:me,client:n,page:m.size>0?`${p}?${m}`:p,onClose:()=>pe(!1)}),_e=i.errorReporting;(0,I.useEffect)(()=>{_e&&iv(_e)},[_e]);let ve=i.runtime?.url,ye=ve&&(0,B.jsx)(iK,{url:ve,client:r}),be=dS(t??`text-small`),xe=i.versionChange&&!be&&(0,B.jsx)(VG,{}),Se=kH((0,I.useCallback)(()=>pH(h),[h]),!!d),Ce=d&&EH(d,Se.current),we=Ce?R_(Ce):!1,Te=oU(),Ee=fH(!!(l&&d)),De=Ee.current,Oe=!!l&&De!==void 0&&!De.organization,ke=l&&d?rj(p):void 0,Ae=AM(),je=d?Tc(p):void 0,Me=je&&Ae?df(uf(Ae.tree),je.tab):void 0,Ne=d?je?Ae?.title??q(`account`):p===`/-/sign-in-policy`?q(`signInPolicy`):ke:void 0,M=A?.names?.plural??(O&&F(O)),Pe=Ne?[Ne]:wL({basePath:h,address:g,group:j?.label,page:D,resourceLabel:M,recordTitle:re,recordLoading:ie}),Fe=A?.names?.singular??(O&&F(O)),Ie=D&&g?.kind===`page`?df(uf(D.tree),g.tab):void 0;PM(NM(MM({address:g,page:D?{title:D.title,...Ie&&{tab:Ie.label}}:je&&Ae&&{title:Ae.title,...Me&&{tab:Me.label}},accountPage:Ne,resourceLabel:M,singular:Fe,recordTitle:re,recordLoading:ie}),i.appName));let Le=je?(0,B.jsx)(jM,{...je}):d&&p===`/-/sign-in-policy`?we?(0,B.jsx)(hN,{}):(0,B.jsx)(tf,{title:q(`adminsOnly`),children:q(`onlyAdminPolicy`)}):ke&&p===`/-/organization`?(0,B.jsx)(yH,{current:De,basePath:h,onChanged:Ee.reload}):ke&&(p===`/-/organization/members`||p===`/-/organization/invitations`)?oj(De)?p===`/-/organization/members`?(0,B.jsx)(oH,{current:De,statuses:ue,presence:de}):(0,B.jsx)(lH,{current:De}):(0,B.jsx)(tf,{title:q(`ownersOnly`),children:q(`onlyOwners`)}):ke&&p===`/-/organizations`||Oe?(0,B.jsx)(TH,{state:Ee,basePath:h}):g?g.kind===`page`?D?(0,B.jsx)(TL,{name:D.name,...g.tab&&{tab:g.tab}},D.name):(0,B.jsx)(tf,{title:q(`notFound`),children:q.rich(`noPage`,{page:g.page})}):k&&k.state!==`ready`?(0,B.jsx)(wG,{status:k}):g.kind===`create`?(0,B.jsx)(PL,{resource:g.resource,values:g.values},g.resource):g.kind===`record`?(0,B.jsx)(bG,{resource:g.resource,recordKey:g.key},`${g.resource}/${g.key}`):(0,B.jsx)(XV,{address:g},$B(g.resource,g.list)):p===`/`?(0,B.jsx)(tf,{title:q(`chooseResource`),children:q(`pickFromSidebar`)}):(0,B.jsx)(tf,{title:q(`notFound`),children:q(`nothingHere`)}),Re=we&&Te.length>0;return(0,B.jsxs)(xS,{pageScroll:!0,sidebarMode:t??`text-small`,activeItem:b??``,breadcrumb:Pe,user:Ce&&B_(Ce),onSignOut:d&&(()=>void s()),signIn:d?void 0:u.link(),workspace:De?.organization?.name??e,appName:i.appName,appIcon:i.appIcon,logo:jH,navGroups:T,bottomBar:CL(i,h,b),userMenu:[QB(i,h,b),l&&d?sj(h,p,De):[],d?Dc(h,p,we):[]],account:d&&`${h}/-/account`,organizations:l&&{...De?.organization&&{current:{id:De.organization.id,name:De.organization.name}},others:Ee.organizations.filter(e=>e.id!==De?.organization?.id),onSwitch:e=>void o.organizations.switchTo(e).then(()=>pH(h))},theme:{preference:C.preference,onChange:C.choose},...le.menu&&{status:le.menu},roles:Se.current?.active?{active:Se.current.active,roles:Se.current.roles,onSwitch:Se.switchTo}:void 0,onNavigate:v,onBack:y,sidebarNotice:(0,B.jsx)(BG,{}),banner:(f||Re)&&(0,B.jsxs)(B.Fragment,{children:[f&&(0,B.jsx)(aK,{signIn:f,onStop:c}),Re&&(0,B.jsx)(cU,{off:Te})]}),search:S.available?{placeholder:S.placeholder,text:S.text,onTextChange:S.setText,query:S.query,loading:S.loading,groups:S.groups,onSelect:v}:void 0,actions:(oe||ce||xe||ye||he)&&(0,B.jsxs)(B.Fragment,{children:[oe&&(0,B.jsx)(cv,{name:`shell.actions`,fallback:null,children:(0,B.jsx)(oe,{})}),ce,xe,ye,he]}),rightPanel:(se||ge)&&(0,B.jsxs)(B.Fragment,{children:[se&&(0,B.jsx)(cv,{name:`shell.rightPanel`,fallback:null,children:(0,B.jsx)(se,{})}),ge]}),children:[Le,le.dialog,i.calls&&d&&!f&&(0,B.jsx)(BH,{})]})},WK=({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=dS(i??`text-small`),{path:f}=jh();return(0,B.jsx)(Vd,{baseUrl:e,client:t,sources:n,token:c.kind===`visitor`?void 0:l.token,onUnauthenticated:u,children:(0,B.jsx)(rf,{children:(0,B.jsxs)(ay,{children:[!d&&(0,B.jsx)(WG,{}),f===`/-/connect`?(0,B.jsx)(rN,{}):(0,B.jsx)(sU,{ui:a,children:(0,B.jsx)(dH,{children:(0,B.jsx)(g_,{children:(0,B.jsx)(UK,{workspace:r,sidebarMode:i,assistant:o,runtime:s})})})})]})})})},GK=({baseUrl:e,client:t,ui:n,children:r})=>{let i=rF();return i?(0,B.jsx)(Vd,{baseUrl:e,client:t,children:(0,B.jsx)(s_.Provider,{value:n??{},children:(0,B.jsx)(tF,{name:i.name},i.name)})}):r},KK=({baseUrl:e,children:t})=>{let n=LF(),{basePath:r}=jh();if(!n)return t;let i=new URL(e??`/api/v1`,window.location.href),a=`${i.origin}${i.pathname.slice(0,i.pathname.lastIndexOf(`/`))}`;return(0,B.jsx)(tI,{link:n.token,systemPath:a,base:`${window.location.origin}${r}`})},qK=({auth:e,workspace:t,basePath:n,initialUrl:r,pluginLoader:i,locale:a,nativeBridge:o,...s})=>{Pe(a??`en`);let c=s.baseUrl&&new URL(s.baseUrl,window.location.href).origin;return(0,B.jsx)(uI,{children:(0,B.jsx)(kK,{nativeBridge:o,apiOrigin:c,children:(0,B.jsx)(kd,{session:e,...c&&{origin:c},...o&&{nativeBridge:o},children:(0,B.jsx)(zh,{basePath:n,initialUrl:r,children:(0,B.jsx)(FP,{...i&&{loader:i},children:(0,B.jsx)(JP,{children:(0,B.jsx)(GK,{baseUrl:s.baseUrl,client:s.client,ui:s.ui,children:(0,B.jsx)(KK,{...s.baseUrl&&{baseUrl:s.baseUrl},children:(0,B.jsx)(UP,{workspace:t,children:(0,B.jsx)(WK,{workspace:t,...s})})})})})})})})})})};export{zE as $,fI as A,gp as At,_N as B,$d as Bt,RI as C,J as Ct,EI as D,Hh as Dt,jI as E,Uh as Et,DP as F,Ef as Ft,VM as G,H as Gt,FM as H,Vd as Ht,OP as I,Cf as It,Qk as J,Ar as Jt,fj as K,Od as Kt,SP as L,G as Lt,Z as M,Gf as Mt,ZP as N,Uf as Nt,xI as O,Sh as Ot,qP as P,Vf as Pt,BE as Q,hP as R,mf as Rt,VI as S,Ug as St,NI as T,Jh as Tt,IM as U,U as Ut,gN as V,Gd as Vt,BM as W,Ld as Wt,Ek as X,Tk as Y,Dr as Yt,UE as Z,XI as _,i_ as _t,eU as a,Fy as at,GI as b,e_ as bt,nH as c,Yv as ct,mL as d,X_ as dt,iE as et,fL as f,j_ as ft,$I as g,a_ as gt,nL as h,o_ as ht,QH as i,xb as it,eI as j,Zf as jt,hI as k,Vp as kt,kL as l,zv as lt,sL as m,__ as mt,JW as n,nS as nt,ZH as o,Ly as ot,dL as p,x_ as pt,sA as q,id as qt,qW as r,Tx as rt,HH as s,Iy as st,qK as t,tS as tt,hL as u,pv as ut,YI as v,Qg as vt,PI as w,Yh as wt,WI as x,Wg as xt,JI as y,t_ as yt,cP as z,W as zt};
|
|
8
|
-
//# debugId=
|
|
6
|
+
`)}\r\n`},sR=({label:e,counts:t})=>(0,B.jsx)(`dl`,{"aria-label":e,className:`grid grid-cols-2 gap-3 sm:grid-cols-4`,children:t.map(([e,t])=>(0,B.jsxs)(`div`,{className:`rounded-lg border px-3 py-2`,children:[(0,B.jsx)(`dt`,{className:`text-xs text-muted-foreground`,children:e}),(0,B.jsx)(`dd`,{className:`text-lg font-semibold tabular-nums`,children:t.toLocaleString(Le())})]},e))}),cR=(e,t)=>e?.fields[t]?.label??F(t),lR=new Set([`text`,`integer`,`bigint`,`decimal`,`boolean`,`date`,`timestamp`,`uuid`,`enum`,`relation`,`currency`,`country`]),uR=(e,t)=>{let n=e.relation?t[e.relation.resource]:void 0;return n?.primaryKey.length===1?n:void 0},dR=(e,t)=>Object.values(e.fields).filter(n=>n.readOnly||n.name===e.tenant||!lR.has(n.type)?!1:n.type!==`relation`||uR(n,t)!==void 0),fR=new Set([`text`,`integer`,`bigint`,`uuid`,`date`,`currency`,`country`,`enum`]),pR=e=>{let t=e.primaryKey.length===1?[e.fields[e.primaryKey[0]]]:[],n=Object.values(e.fields).filter(t=>t.filterable&&!t.sensitive&&fR.has(t.type)&&!e.primaryKey.includes(t.name));return[...t,...n]},mR=(e,t)=>uR(e,t),hR=e=>!e.nullable&&!e.default,gR=e=>e.toLowerCase().replace(/[\s_-]+/g,``),_R=(e,t,n)=>{let r=new Set;return e.flatMap((e,i)=>{let a=gR(e);if(a===``)return[];let o=t.find(e=>!r.has(e.name)&&(gR(cR(n,e.name))===a||gR(e.name)===a));return o?(r.add(o.name),[{column:i,field:o.name}]):[]})},vR=(e,t,n)=>{if(e===`update`)return[];let r=new Set(n.map(e=>e.field));return t.filter(e=>hR(e)&&!r.has(e.name))},yR=e=>({ok:!0,value:e}),bR=e=>({ok:!1,problem:e}),xR=e=>`“${nR(e)}”`,SR=(e,t)=>{if(typeof e==`number`)return String(e);if(typeof e==`string`)return ug(e,t.decimal)},CR=(e,t,n)=>{let r=SR(t,n);if(r===void 0)return bR($(`notNumber`,{cell:xR(t)}));let[i,a=``]=r.split(`.`);if(/[1-9]/.test(a)||/e/i.test(r))return bR($(`notWholeNumber`,{cell:xR(t)}));if(e.type===`bigint`)return yR(String(BigInt(i)));let o=Number(i);return Number.isSafeInteger(o)?yR(o):bR($(`tooLarge`,{cell:xR(t)}))},wR=(e,t)=>{let n=SR(e,t);return n===void 0?bR($(`notNumber`,{cell:xR(e)})):yR(n)},TR=new Set([`true`,`yes`,`1`]),ER=new Set([`false`,`no`,`0`]),DR=e=>{if(typeof e==`boolean`)return yR(e);let t=typeof e==`string`||typeof e==`number`?String(e).trim().toLowerCase():``;return TR.has(t)?yR(!0):ER.has(t)?yR(!1):bR($(`notBoolean`,{cell:xR(e)}))},OR=e=>String(e).padStart(2,`0`),kR=(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}-${OR(t)}-${OR(n)}`},AR=`(\\d{1,2}):(\\d{2})(?::(\\d{2})(?:\\.\\d+)?)?`,jR=(e,t)=>{let n=RegExp(`^(\\d{4})[-/](\\d{1,2})[-/](\\d{1,2})(?:[T ]${AR}(Z|[+-]\\d{2}:?\\d{2})?)?$`).exec(e.trim()),r=RegExp(`^(\\d{1,2})[./-](\\d{1,2})[./-](\\d{4})(?: ${AR})?$`).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=kR(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:`${OR(Number(c))}:${l}:${OR(Number(u))}`,zone:n?.[7]}},MR=(e,t)=>{if(eR(e)){let[t,n]=e.date.split(`T`);return{date:t,time:n}}return typeof e==`string`?jR(e,t.dateOrder):void 0},NR=(e,t)=>bR($(`notDate`,{cell:xR(e),dayFirst:t.dateOrder===`dmy`})),PR=(e,t)=>{let n=MR(e,t);return n?n.time&&n.time!==`00:00:00`?bR($(`hasTime`,{cell:xR(e)})):yR(n.date):NR(e,t)},FR=(e,t)=>{let n=MR(e,t);if(!n)return NR(e,t);if(n.zone)return yR(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 yR(new Date(r,i-1,a,o,s,c).toISOString())},IR=e=>e.trim().toLowerCase().replace(/\s+/g,` `),LR=(e,t,n)=>{let r=e.enumValues??[],i=IR(nR(n)),a=r.filter(e=>IR(e)===i||IR(ir(e,t?.valueLabels))===i);return a.length===1?yR(a[0]):a.length>1?bR($(`severalValues`,{cell:xR(n),values:a.map(e=>ir(e,t?.valueLabels)).join(`, `)})):bR($(`notOneOf`,{cell:xR(n),values:r.map(e=>ir(e,t?.valueLabels)).join(`, `)}))},RR=e=>typeof e==`boolean`?bR($(`notText`,{cell:xR(e)})):yR(nR(e)),zR=(e,t,n,r)=>{if(tR(n))return e.nullable?yR(null):bR($(`emptyRequired`));switch(e.type){case`integer`:case`bigint`:return CR(e,n,r);case`decimal`:return wR(n,r);case`boolean`:return DR(n);case`date`:return PR(n,r);case`timestamp`:return FR(n,r);case`enum`:return LR(e,t,n);case`text`:case`uuid`:case`currency`:case`country`:return RR(n);default:throw Error(`Not implemented: importing ${e.type} fields, which importableFields leaves out`)}},BR=(e,t)=>e[t]?.names?.singular??F(t),VR=(e,t)=>e[t]?.names?.plural??F(t),HR=(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=cR(o,d),g=mR(p,i);if(g&&!tR(m)){let e=f??g.primaryKey[0],n=zR(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]=nR(m);continue}let _=zR(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=zR({...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(`${cR(o,n.name)}: ${i.problem}`)}return{values:s,data:c,problems:l,relations:u,match:d}},UR=(e,t)=>{let n=e.lookups.keysOf(t.model.name,t.field,t.value),r=`${cR(e.views[t.model.name],t.field).toLowerCase()} “${String(t.value)}”`;return n.length===1?{key:n[0]}:n.length===0?{none:$(`noneHas`,{singular:BR(e.views,t.model.name),named:r})}:{several:$(`severalHave`,{count:n.length,plural:VR(e.views,t.model.name),named:r})}},WR=e=>e.cells.every(tR),GR=async(e,t,n)=>{let{model:r,views:i}=n,a=e.filter(e=>!WR(e)).map(e=>({row:e,...HR(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=UR(n,t);`key`in a?u[e]=a.key:s.push(`${cR(i[r.name],e)}: ${a.none??a.several}`)}let d=l&&UR(n,l);d?.several&&s.push($(`notOneRecord`,{found:d.several})),d?.none&&t.mode===`update`&&s.push($(`nothingToUpdate`,{found:d.none}));let f={line:e.line,cells:e.cells,values:a,problems:s};return s.length>0?f:d&&`key`in d?{...f,op:{op:`update`,resource:r.name,key:d.key,etag:`*`,data:u}}:{...f,op:{op:`create`,resource:r.name,data:u}}})},KR=5,qR=5,JR=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(nR),sample:a.slice(0,KR)}};async function*YR(e,t){let n=!0;for await(let r of e.rows(t))yield n?r.slice(1):r,n=!1}var XR=async(e,t,n,r,i,a)=>{let o={rows:0,creates:0,updates:0,problems:[],preview:[]};for await(let s of YR(e,t)){a?.throwIfAborted();for(let e of await GR(s,n,r))o.rows++,o.preview.length<qR&&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},ZR=(e,t)=>{if(!pl(e))return[e.message];let n=e.errors.filter(e=>e.field);return n.length===0?[e.message]:n.map(e=>`${cR(t.views[t.model.name],e.field)}: ${e.message}`)},QR=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=pl(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:ZR(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 YR(e,t)){for(let e of await GR(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}},$R=50,ez=(e,t,n)=>mM(oR(t,n),$(`notImportedFile`,{name:(e??`import`).replace(/\.[^.]+$/,``)}),`text/csv`),tz=({rows:e})=>(0,B.jsxs)(`ul`,{"aria-label":$(`rowsNotImported`),className:`flex flex-col gap-1 text-body`,children:[e.slice(0,$R).map(e=>(0,B.jsxs)(`li`,{children:[(0,B.jsx)(`span`,{className:`font-medium`,children:$(`rowProblems`,{line:e.line})}),` `,e.problems.join(`; `)]},e.line)),e.length>$R&&(0,B.jsx)(`li`,{className:`text-muted-foreground`,children:$(`andMore`,{count:(e.length-$R).toLocaleString(Le())})})]}),nz=({rows:e})=>(0,B.jsxs)(`p`,{className:`flex items-center gap-2 text-muted-foreground`,role:`status`,children:[(0,B.jsx)($d,{className:`size-3.5`}),$(`checkingRows`,{count:e.toLocaleString(Le())})]}),rz=({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)(sR,{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:cR(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:mR(t,n)?String(e.values[t.name]??`—`):t.name in e.values?Nm(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:()=>ez(o,a,e.problems),children:[(0,B.jsx)(na,{className:`size-3.5`}),$(`download`)]})]}),(0,B.jsx)(tz,{rows:e.problems})]}),(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:$(`batches`,{size:100})})]})},iz=({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})]})},az=({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)($d,{className:`size-3.5`}),$(`reading`,{name:e?.name??$(`theFile`)})]}),!r&&t.length>1&&(0,B.jsxs)(`div`,{className:`flex items-end gap-3`,children:[(0,B.jsx)(ba,{className:`mb-2 size-4 shrink-0 text-muted-foreground`}),(0,B.jsx)(iz,{className:`flex-1`,label:$(`sheet`),value:n??``,options:t.map(e=>({value:e,label:e})),onChange:a})]})]})},oz=()=>[{value:`create`,label:$(`create`)},{value:`update`,label:$(`update`)},{value:`upsert`,label:$(`upsert`)}],sz={create:`createHint`,update:`updateHint`,upsert:`upsertHint`},cz=``,lz=({flow:e,model:t,resources:n,views:r,canUpdate:i})=>{let a=r[t.name],o=e.head?.headers??[],s=e.head?.sample??[],c=vR(e.mode,e.fields,e.columns),l=[{value:cz,label:$(`doNotImport`)},...e.fields.map(e=>({value:e.name,label:`${cR(a,e.name)}${hR(e)?` *`:``}`}))],u=o.map((e,t)=>({value:String(t),label:iR(o,t)})),d=pR(t);return(0,B.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[i&&(0,B.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,B.jsx)(`span`,{className:`font-medium`,children:$(`rows`)}),(0,B.jsx)(`div`,{children:(0,B.jsx)(Re,{label:$(`whatEachRowDoes`),size:`md`,value:e.mode,options:oz(),onChange:e.setMode})}),(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:$(sz[e.mode])})]}),e.mode!==`create`&&(0,B.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2`,children:[(0,B.jsx)(iz,{label:$(`findBy`),value:e.match?.field??cz,options:[{value:cz,label:$(`chooseField`)},...d.map(e=>({value:e.name,label:cR(a,e.name)}))],onChange:t=>e.setMatch(t?{field:t,column:e.match?.column??0}:void 0),help:$(`findByHint`)}),(0,B.jsx)(iz,{label:$(`foundInColumn`),value:e.match?String(e.match.column):cz,options:[{value:cz,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)(iz,{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)(iz,{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?mR(d,n):void 0,p=s.map(e=>nR(e.cells[c]??null)).filter(e=>e!==``).slice(0,3),m=iR(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)(iz,{label:$(`field`),name:$(`fieldFor`,{name:m}),value:u?.field??cz,options:l,onChange:t=>e.mapColumn(c,t||void 0)}),f&&(0,B.jsx)(iz,{label:$(`foundBy`),name:$(`pluralFoundBy`,{plural:r[f.name]?.names?.plural??cR(a,d.name)}),value:u.matchBy??f.primaryKey[0],options:pR(f).map(e=>({value:e.name,label:cR(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`,{fields:c.map(e=>cR(a,e.name)).join(`, `)})})]})]})},uz=e=>e.toLocaleString(Le()),dz=({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:[uz(r),` / `,uz(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}%`}})})]})},fz=({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)(Bg,{title:$(`stopped`),error:t}),e.cancelled&&(0,B.jsx)(`p`,{role:`status`,children:$(`cancelled`)}),(0,B.jsx)(sR,{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:()=>ez(r,n,e.notWritten),children:[(0,B.jsx)(na,{className:`size-3.5`}),$(`download`)]})]}),(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:$(`notWrittenHint`)}),(0,B.jsx)(tz,{rows:[...e.notWritten].sort((e,t)=>e.line-t.line)})]})]}),pz=e=>{let t=cg(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`}},mz=sn(),hz=100,gz=e=>String(e),_z=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(gz(e))).map(e=>[gz(e),e])).values()],s=t.primaryKey[0];for(let n=0;n<o.length;n+=hz){let i=o.slice(n,n+hz);for(let e of i)a.set(gz(e),[]);let c=Yt(mz.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(gz(e[r]))?.push(e[s]);l=n.nextPageToken||void 0}while(l)}},keysOf:(e,t,r)=>n(e,t).get(gz(r))??[]}},vz=500,yz=()=>{let e=new Worker(new URL(`/assets/parse-worker-BzLD2jKf.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()}},bz=e=>({sheets:async()=>{let t=yz();try{t.send({type:`sheets`,file:e,locale:Be()});let n=await t.receive();if(n.type===`error`)throw Error(n.message);if(n.type!==`sheets`)throw Error(`The parse worker answered ${n.type} to a request for sheets`);return n.sheets}finally{t.stop()}},rows:async function*(t){let n=yz();try{for(n.send({type:`read`,file:e,sheet:t,chunk:vz,locale:Be()});;){let e=await n.receive();if(e.type===`error`)throw Error(e.message);if(e.type===`end`)return;if(e.type!==`rows`)throw Error(`The parse worker answered ${e.type} to a read`);yield e.rows,n.send({type:`next`})}}finally{n.stop()}}}),xz={created:0,updated:0,skipped:0,failed:0,notWritten:[]},Sz=({model:e,resources:t,views:n,sourceFor:r=bz})=>{let i=Rd(),a=Se(),o=n[e.name],s=(0,I.useMemo)(()=>dR(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)(()=>pz()),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 JR(t,n);_(r),x(_R(r.headers,s,o));let i=pR(e)[0],a=i?_R(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:_z(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}),XR(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:xz,total:t,cancelling:!1});let n=xz;QR(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()}},Cz=e=>e.step.kind===`file`?$(`couldNotReadFile`):$(`couldNotCheck`),wz=e=>e.columns.length===0?!1:e.mode===`create`?vR(`create`,e.fields,e.columns).length===0:e.match!==void 0,Tz=({model:e,resources:t,views:n,canUpdate:r,onClose:i,sourceFor:a})=>{let o=Sz({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)(Ef,{open:!0,wide:!0,title:$(`importPlural`,{plural:s}),description:o.file&&c.kind!==`file`?o.file.name:void 0,onClose:u,actions:(()=>{switch(c.kind){case`file`:return(0,B.jsxs)(B.Fragment,{children:[d,o.sheets.length>1&&(0,B.jsx)(G,{variant:`primary`,loading:c.reading,onClick:o.openSheet,children:$(`next`)})]});case`map`:return(0,B.jsxs)(B.Fragment,{children:[d,(0,B.jsx)(G,{variant:`primary`,disabled:!wz(o),onClick:o.check,children:$(`checkRows`)})]});case`checking`:return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:o.back,children:$(`back`)}),(0,B.jsx)(G,{variant:`primary`,loading:!0,children:$(`checking`)})]});case`checked`:{let e=c.check.creates+c.check.updates;return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:o.back,children:$(`back`)}),(0,B.jsx)(G,{variant:`primary`,disabled:e===0,onClick:()=>o.start(e),children:$(`importRows`,{count:e.toLocaleString(Le()),rows:e})})]})}case`importing`:return(0,B.jsx)(G,{variant:`danger`,disabled:c.cancelling,onClick:o.cancel,children:$(`cancelImport`)});case`done`:return(0,B.jsx)(G,{variant:`primary`,onClick:i,children:$(`done`)})}})(),children:(0,B.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[o.error!==void 0&&(0,B.jsx)(Bg,{title:Cz(o),error:o.error}),(()=>{switch(c.kind){case`file`:return(0,B.jsx)(az,{file:o.file,sheets:o.sheets,sheet:o.sheet,reading:c.reading,onChoose:o.choose,onSheet:o.setSheet});case`map`:return(0,B.jsx)(lz,{flow:o,model:e,resources:t,views:n,canUpdate:r});case`checking`:return(0,B.jsx)(nz,{rows:c.rows});case`checked`:return(0,B.jsx)(rz,{check:c.check,model:e,resources:t,views:n,columns:o.columns,headers:l,fileName:o.file?.name});case`importing`:return(0,B.jsx)(dz,{progress:c.progress,total:c.total,cancelling:c.cancelling});case`done`:return(0,B.jsx)(fz,{result:c.result,stopped:c.stopped,headers:l,fileName:o.file?.name})}})()]})})},Ez=({model:e})=>{let{resources:t,views:n}=W(),r=af(e.name),[i,a]=(0,I.useState)(!1);return n[e.name]?.import===!1||!oy(r,`create`)?null:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(G,{onClick:()=>a(!0),"aria-haspopup":`dialog`,children:[(0,B.jsx)(Zs,{className:`size-3.5`}),$(`import`)]}),i&&(0,B.jsx)(Tz,{model:e,resources:t,views:n,canUpdate:oy(r,`update`),onClose:()=>a(!1)})]})},Dz=M(`app/export`),Oz=()=>new DOMException(Dz(`cancelled`),`AbortError`),kz=async({client:e,resource:t,filters:n,orderBy:r,plan:i,labels:a,limit:o,port:s,sink:c,signal:l,onProgress:u})=>{let d=i.columns.map(e=>e.name),f=0;try{await c.write(await s.send({kind:`start`,plan:i,locale:Be()}));for(let[i,p]of n.entries()){let m=``;do{let h=await e.search(t,{filter:p,orderBy:r,pageSize:500,pageToken:m,fields:d,labels:a});if(l.aborted)throw Oz();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 Az(s,c),{rows:f,truncated:g.length<h.items.length||m!==``||i+1<n.length}}while(m!==``)}return await Az(s,c),{rows:f,truncated:!1}}catch(e){throw await c.abort(),e}finally{s.close()}},Az=async(e,t)=>{await t.write(await e.send({kind:`finish`})),await t.close()},jz=1048575,Mz=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
7
|
+
`,Nz=`http://schemas.openxmlformats.org/officeDocument/2006/relationships`,Pz=`http://schemas.openxmlformats.org/package/2006/relationships`;`${Mz}`,`${Mz}${Pz}${Nz}`,`${Mz}${Pz}${Nz}${Nz}`,new TextEncoder;var Fz=sn(),Iz=e=>e?.export!==!1,Lz=e=>Object.values(e.fields).flatMap(e=>e.sensitive?[]:[e.name]),Rz=(e,t)=>{let n=new Set(Lz(e));return Tr(e,t).filter(e=>n.has(e))},zz=(e,t,n)=>Object.fromEntries(jm(e,t,[],n).map(e=>[e.id,e.header])),Bz=(e,t,n)=>{let r=zz(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]??{}}]:[]})},Vz=(e,t)=>{let n=e?.export?e.export.maxRows??1/0:1/0;return Math.min(n,t===`xlsx`?jz:1/0)},Hz=e=>e.primaryKey.length===1,Uz=(e,t)=>{let[n]=e.primaryKey;if(!n||e.primaryKey.length!==1)throw Error(`Not implemented: selected rows are exported by a single-field key`);let r=[];for(let e=0;e<t.length;e+=500)r.push(Yt(Fz.in(n,t.slice(e,e+500))));return r},Wz=()=>{let e=new Worker(new URL(`/assets/export-worker-BKuC4P2E.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(Dz(`couldNotBuild`,{message:e.message}));for(let e of t.splice(0))e.reject(n)},{send:n=>new Promise((r,i)=>{t.push({resolve:r,reject:i}),e.postMessage(n)}),close:()=>e.terminate()}},Gz=()=>[{value:`xlsx`,label:Dz(`excel`)},{value:`csv`,label:Dz(`csv`)}],Kz=()=>[{value:`shown`,label:Dz(`asShown`)},{value:`raw`,label:Dz(`rawValues`)}],qz={shown:`shownHint`,raw:`rawHint`},Jz=e=>e.kind===`counting`?Dz(`counting`):e.kind===`exact`||e.rows>1e4?Dp(e.rows):Dz(`moreThan`),Yz=e=>{if(e.kind!==`counting`)return e.kind===`exact`?e.rows:Math.max(e.rows,10001)},Xz=({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})]}),Zz=(e,t,n)=>{let r=e.indexOf(t),i=[...e];return i.splice(r,1),i.splice(r+n,0,t),i},Qz=({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":Dz(`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)(TC,{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":Dz(`moveUp`,{label:r[e]}),disabled:a===0,onClick:()=>n(Zz(t,e,-1)),children:(0,B.jsx)(Wr,{className:`size-3.5`})}),(0,B.jsx)(G,{size:`sm`,variant:`ghost`,className:`min-h-8 px-2`,"aria-label":Dz(`moveDown`,{label:r[e]}),disabled:a===t.length-1,onClick:()=>n(Zz(t,e,1)),children:(0,B.jsx)(Pr,{className:`size-3.5`})})]})]},e)})})},$z=({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`),_=Vz(t,l),v=d===`selected`?Dz(`selectedRows`,{count:wp(a??0),rows:a??0}):Jz(i),y=(d===`selected`?a??0:Yz(i)??0)>_,b=[{value:`list`,label:Dz(`rowsInList`)},{value:`selected`,label:Dz(`selected`,{count:wp(a??0)})}];return(0,B.jsx)(Ef,{title:Dz(`exportPlural`,{plural:e}),open:o,onClose:c,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:c,children:Dz(`cancel`)}),(0,B.jsx)(G,{variant:`primary`,disabled:p.length===0,onClick:()=>s({format:l,scope:d,columns:p,mode:h}),children:Dz(`export`)})]}),children:(0,B.jsxs)(`div`,{className:`flex flex-col gap-4 text-body`,children:[(0,B.jsx)(Xz,{label:Dz(`format`),children:(0,B.jsx)(Re,{size:`md`,label:Dz(`format`),value:l,options:Gz(),onChange:u})}),a!==void 0&&a>0&&(0,B.jsx)(Xz,{label:Dz(`rows`),help:d===`list`?Dz(`listHint`):void 0,children:(0,B.jsx)(Re,{size:`md`,label:Dz(`rows`),value:d,options:b,onChange:f})}),(0,B.jsx)(Xz,{label:Dz(`values`),help:Dz(qz[h]),children:(0,B.jsx)(Re,{size:`md`,label:Dz(`values`),value:h,options:Kz(),onChange:g})}),(0,B.jsx)(Xz,{label:Dz(`columns`),children:(0,B.jsx)(Qz,{fields:n,columns:p,onChange:m})}),(0,B.jsxs)(`p`,{role:`status`,className:`text-muted-foreground`,children:[Dz(`exports`,{rows:v}),y&&Dz(`overLimit`,{limit:wp(_)})]})]})})},eB=({plural:e,done:t,total:n,onCancel:r})=>{let i=n?Math.min(1,t/n):void 0;return(0,B.jsx)(Ef,{title:Dz(`exporting`,{plural:e}),open:!0,onClose:r,actions:(0,B.jsx)(G,{onClick:r,children:Dz(`cancel`)}),children:(0,B.jsxs)(`div`,{className:`flex flex-col gap-2 text-body`,children:[(0,B.jsx)(`div`,{role:`progressbar`,"aria-label":Dz(`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?Dz(`doneOf`,{done:wp(t),total:wp(n)}):Dz(`done`,{done:wp(t)})})]})})},tB={xlsx:{mime:`application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`,extension:`.xlsx`,description:`workbook`},csv:{mime:`text/csv`,extension:`.csv`,description:`csvFile`}},nB=/[\\/:*?"<>|\u0000-\u001f]/g,rB=(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(nB,` `).trim()} ${r}${tB[t].extension}`},iB=8e6,aB=(e,t)=>{let n=new Blob([],{type:tB[t].mime}),r=[],i=0,a=()=>{n=new Blob([n,...r],{type:tB[t].mime}),r=[],i=0};return{write:async e=>{e.length!==0&&(r.push(e),i+=e.length,i>=iB&&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([])}}},oB=()=>globalThis.showSaveFilePicker,sB=()=>typeof oB()==`function`,cB=async(e,t)=>{let n=oB();if(!n)throw Error(`This browser cannot save a file as it is built`);let r=tB[t],i;try{i=await n({suggestedName:e,types:[{description:Dz(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()}},lB=(e,t)=>sB()?cB(e,t):Promise.resolve(aB(e,t)),uB=(e,t)=>{let n=t[e.primaryKey[0]];return typeof n==`object`&&n&&`id`in n?n.id:n},dB=({model:e,view:t,resources:n,views:r,plural:i,filter:a,orderBy:o,createPort:s=Wz,createSink:c=lB})=>{let l=U(),u=iy(),[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:Hz(e)?t.map(t=>uB(e,t)):[]}),g=async(d,h)=>{let g=rB(i,d.format),_=await c(g,d.format);if(!_)return;let v=Vz(t,d.format),y=d.scope===`selected`?h.length:Yz(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 kz({client:l,resource:e.name,filters:d.scope===`selected`?Uz(e,h):[a],orderBy:o,plan:{format:d.format,mode:d.mode,name:i,columns:Bz(e,t,d.columns)},labels:d.mode===`shown`?Cb(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:Dz(`exported`,{count:wp(c.rows),plural:i}),description:c.truncated?Dz(`truncated`,{name:g,count:wp(c.rows)}):g})}catch(e){if(e instanceof DOMException&&e.name===`AbortError`)return;if(!pl(e))throw e;u.show({state:`error`,title:Dz(`couldNotExport`,{plural:i}),description:e.message})}finally{p.current=void 0,f(e=>e.kind===`running`?{kind:`closed`}:e)}},_=()=>{p.current?.abort(),f({kind:`closed`})},v=Lz(e),y=zz(e,t,v);return{open:h,dialogs:d.kind===`settings`?(0,B.jsx)($z,{plural:i,view:t,fields:v.map(e=>({name:e,label:y[e]})),initialColumns:Rz(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)(eB,{plural:i,done:d.done,total:d.total,onCancel:_}):null}},fB=M(`app/list`),pB=({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:fB(`clearSearch`)}),e.clearFilters&&(0,B.jsx)(G,{onClick:n,children:fB(`clearFilters`)}),e.create&&r]})]}),mB=({plural:e,search:t,filtered:n,scoped:r,canCreate:i})=>t?{message:fB(`noMatchSearch`,{plural:e,search:t}),clearSearch:!0,clearFilters:n,create:!1}:n?{message:fB(`noMatchFilters`,{plural:e}),clearSearch:!1,clearFilters:!0,create:!1}:r?{message:fB(`noMatch`,{plural:e}),clearSearch:!1,clearFilters:!1,create:!1}:{message:fB(`noneYet`,{plural:e}),clearSearch:!1,clearFilters:!1,create:i},hB=(e,t)=>{},gB=({windowMs:e=1e3,comebacks:t=2,onHold:n=hB}={})=>{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}},_B=e=>Math.max(1,Math.floor((e+12)/252)),vB=(e,t)=>Math.max(0,(e-(t-1)*12)/t),yB=(e,t,n,r)=>({start:e*n,end:Math.max(0,Math.min(r,(t+1)*n)-1)}),bB=(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},xB=(e,t)=>{let n=e/t.rowHeight;return Math.floor(n)*t.columns+n%1},SB=(e,t)=>Math.floor(Math.floor(e)/t)+e%1,CB=8,wB=(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<=CB)break;i.delete(e)}return i},TB=({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=_B(c),d=vB(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?bB(_.current.top,_.current.layout,g):e,b=d>0&&f.has(d),x=aw({total:Math.ceil(o/u),rowHeight:h,initialIndex:SB(s,u),settle:y,ready:b,onScroll:e=>r(xB(e,g))});(0,I.useLayoutEffect)(()=>{v&&x.scrollTo(x.top),_.current={layout:g,top:x.started()?x.top:0}});let S=yB(x.first,x.last,u,o),C=GC({total:o,rowAt:e.rowAt,loadRows:e.loadRows,revision:e.revision,latencyMs:0},S.start,S.end),[w]=(0,I.useState)(()=>gB());(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=>wB(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)(vh,{className:`h-full rounded-lg`})},`skeleton-${i}`)}))})},EB=`grid grid-cols-[repeat(auto-fill,minmax(15rem,1fr))] gap-3`,DB=e=>e*.75,OB=44,kB=({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 ${EB}`,children:Array.from({length:6},(e,t)=>(0,B.jsx)(vh,{className:`h-24`},t))}):r.error?(0,B.jsx)(Bg,{title:K(`couldNotLoadRows`),error:r.error}):!r.source||r.source.total===0?i??(0,B.jsx)(`p`,{className:`py-8 text-center text-muted-foreground`,children:K(`noneMatch`,{plural:a.toLowerCase()})}):(0,B.jsx)(TB,{source:r.source,label:a,initialIndex:r.initialIndex,onScrollIndex:r.onScrollIndex,minHeight:e=>(o?DB(e):0)+OB,children:r=>(0,B.jsx)(ZE,{model:e,view:t,display:n,row:uh(e,r)})})},AB=`protobase:list-places`,jB=50,MB=(e,t)=>`${e} ${t}`,NB=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},PB=e=>Ie(()=>{let t=e.getItem(AB);if(t===null)return[];let n=JSON.parse(t);return Array.isArray(n)?n.filter(NB):[]},[]),FB=e=>{let t=new Map(PB(e).map(e=>[MB(e.entry,e.url),e]));return{placeOf:(e,n)=>{let r=t.get(MB(e,n));return r?r.place:[...t.values()].findLast(e=>e.url===n)?.place??0},save:(e,n,r)=>{let i=MB(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-jB)))t.delete(e)},persist:()=>Ie(()=>e.setItem(AB,JSON.stringify([...t.values()])),void 0)}},IB={getItem:()=>null,setItem:()=>{}},LB,RB=()=>LB??=FB(Ie(()=>window.sessionStorage,void 0)??IB),zB=()=>{let{entry:e,path:t,params:n}=jh(),r=`${t}?${n.toString()}`,i=RB();(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}},BB=e=>e.reduce((e,t)=>e+t.count,0),VB=e=>{let t=Math.floor(e.length/2),n=BB(e.slice(0,t)),r=BB(e.slice(e.length-t));return n===0?0:(r-n)/n*100},HB=({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:cp(r.at)}),(0,B.jsxs)(`div`,{className:`font-semibold tabular-nums`,children:[wp(r.count),` `,n]})]})},UB=M(`activity-chart`),WB={fontSize:11,fill:`var(--muted-foreground)`},GB=({title:e,noun:t,defaultGranularity:n=`day`,data:r,granularity:i,onGranularityChange:o,periodLabel:s,className:l})=>{let[u,d]=(0,I.useState)(n),f=i??u,m=o??d,h=hf(`(min-width: 640px)`),_=VB(r);return(0,B.jsxs)(`section`,{className:P(`rounded-lg border bg-background px-4 pb-2 pt-3`,l),children:[(0,B.jsxs)(`header`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,B.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,B.jsx)(`h2`,{className:`font-semibold`,children:e}),(0,B.jsx)(`span`,{className:`font-semibold tabular-nums`,children:wp(BB(r))}),(0,B.jsxs)(`span`,{className:P(`text-xs font-medium tabular-nums`,_>=0?`text-success-text`:`text-danger-text`),children:[_>=0?`+`:`−`,Math.abs(_).toFixed(1),`%`]}),(0,B.jsx)(`span`,{className:`hidden text-xs text-muted-foreground sm:inline`,children:s??`last ${f===`day`?`30 days`:`12 weeks`}`})]}),(0,B.jsx)(Re,{value:f,onChange:m,options:[{value:`day`,label:UB(`day`)},{value:`week`,label:UB(`week`)}]})]}),(0,B.jsx)(`div`,{className:`mt-2 h-24`,children:(0,B.jsx)(g,{width:`100%`,height:`100%`,children:(0,B.jsxs)(c,{data:r,margin:{top:4,right:0,bottom:0,left:0},barCategoryGap:f===`day`?`22%`:`30%`,children:[(0,B.jsx)(v,{vertical:!1,stroke:`var(--border)`}),(0,B.jsx)(a,{dataKey:`at`,padding:{left:4,right:h?4:18},tickFormatter:lp,tick:WB,axisLine:!1,tickLine:!1,interval:f===`day`?h?4:9:h?1:3,height:18}),(0,B.jsx)(pe,{width:h?36:28,tick:WB,axisLine:!1,tickLine:!1,tickCount:3}),(0,B.jsx)(p,{cursor:{fill:`var(--muted)`},content:(0,B.jsx)(HB,{noun:t}),isAnimationActive:!1}),(0,B.jsx)(fe,{dataKey:`count`,fill:`var(--primary)`,radius:[2,2,0,0],isAnimationActive:!1})]})})})]})},KB={"7d":`last 7 days`,"30d":`last 30 days`,"90d":`last 90 days`,"1y":`last year`,all:`all time`},qB=({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=Iy(e,{field:t.field,range:s,granularity:a,filter:i,timeZone:Gf()}).data?.points.map(e=>({at:Date.parse(`${e.bucket}Z`),count:e.count}))??[];return(0,B.jsx)(GB,{title:n,noun:r,data:c,granularity:a,onGranularityChange:o,periodLabel:a===`week`?`last 12 weeks`:KB[s]})},JB=(e,t,n)=>{let r=e.sum??e.average;if(r===void 0)return n;let i=t?.fields[r]?.label??F(r);return e.sum===void 0?q(`average`,{label:i}):`${i}`},YB=({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":`${JB(n,t,r)} by ${a.toLowerCase()}`,children:[(0,B.jsxs)(`h2`,{className:`mb-2 font-semibold`,children:[JB(n,t,r),` by `,a.toLowerCase()]}),(0,B.jsx)(vb,{model:e,view:t,groupBy:n.groupBy,type:n.type,sum:n.sum,average:n.average,limit:n.limit,filter:i})]})},XB=({value:e,onCommit:t,placeholder:n,className:r})=>{let[i,a]=(0,I.useState)(e);return(0,I.useEffect)(()=>a(e),[e]),(0,I.useEffect)(()=>{if(i===e)return;let n=setTimeout(()=>t(i),350);return()=>clearTimeout(n)},[i,e,t]),(0,B.jsx)(J,{wrapperClassName:P(`min-w-0 flex-1 sm:w-72 sm:flex-initial`,r),leading:(0,B.jsx)(ss,{className:`size-4`}),placeholder:n,"aria-label":fB(`search`),value:i,onChange:e=>a(e.target.value),onKeyDown:e=>e.key===`Enter`&&t(i)})},ZB=e=>new Set((e.userMenu?.items??[]).flatMap(e=>e.kind===`resource`?[e.resource]:e.kind===`page`?[e.page]:[])),QB=(e,t,n)=>(e.userMenu?.items??[]).map((r,i)=>{if(r.kind===`link`)return{id:`link-${i}`,label:r.label,icon:xL(r.icon,ua),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:xL(r.icon??i?.icon,Ha),href:Bc({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:xL(r.icon,SL(e,r.resource)),href:Bc({kind:`list`,resource:r.resource},t),active:r.resource===n}}),$B=(e,t)=>t===void 0?e:`${e}/${t}`,eV={sales:`sales`,crm:`crm`,catalog:`catalog`,inventory:`inventory`,core:`admin`,hr:`hr`},tV=(e=`public`)=>e===`public`?``:eV[e]?q(eV[e]):F(e),nV=(e,t,n,r,i)=>!n?.create||!$L(t,e.pages,e.permissions[t.resource]??Ud)?{}:{create:{label:n.create===!0?Dg(`title`,{noun:r}):n.create.label,href:Bc({kind:`create`,resource:t.resource},i)}},rV=(e,t=``,n={})=>{let r=new Map,i=new Map,a=ZB(e);for(let n of Object.values(e.pages)){if(n.nav?.hidden||a.has(n.name))continue;let e=n.nav?.group??q(`pages`),o=r.get(e)??{label:e,items:[]};o.items.push({id:n.name,label:n.title,icon:xL(n.icon,Ha),href:Bc({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??tV(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:$B(o.name),label:s.names?.plural??F(o.name),icon:SL(e,o.name),href:Bc({kind:`list`,resource:o.name},t),...n[o.name]&&{recent:n[o.name]},...nV(e,s,s.nav,s.names?.singular??F(o.name),t)},s.nav?.order);for(let n of s.lists??[])n.nav?.hidden||l(n.nav?.group??c,{id:$B(o.name,n.name),label:n.names.plural,icon:SL(e,o.name),href:Bc({kind:`list`,resource:o.name,list:n.name},t),...nV(e,s,n.nav,n.names.singular,t)},n.nav?.order)}for(let n of Object.values(e.signIn??{})){if(n.nav?.hidden||a.has(n.resource))continue;let o=n.nav?.group??q(`account`),s=r.get(o)??{label:o,items:[]};s.items.push({id:n.resource,label:n.names?.plural??F(n.resource),icon:SL(e,n.resource),href:Bc({kind:`list`,resource:n.resource},t)}),r.set(o,s),i.set(n.resource,n.nav?.order??2**53-1)}for(let n of e.sources??[]){if(n.state!==`error`)continue;let e=r.get(n.source.label)??{label:n.source.label,items:[]};for(let r of n.source.resources)e.items.push({id:r,label:F(r),icon:Ls,href:Bc({kind:`list`,resource:r},t),problem:q(`cannotReach`,{label:n.source.label})});r.set(n.source.label,e)}return[...r.values()].map(e=>({...e,items:[...e.items].sort((e,t)=>(i.get(e.id)??0)-(i.get(t.id)??0))}))},iV=(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 Tr(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:Jp(c,!1),sortable:!1,render:e=>(0,B.jsx)(AE,{column:n,records:e[n.name]??[],target:s,view:i[s.name],Card:ZE})}]})},aV=({model:e,view:t,target:n,children:r})=>{let i=pE(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)(SS,{title:a,subtitle:t.help}),e]});if(i.error)return o((0,B.jsx)(Bg,{title:mE(`couldNotLoadYour`,{plural:a.toLowerCase()}),error:i.error}));if(!i.data)return o((0,B.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(15rem,1fr))] gap-3`,children:Array.from({length:3},(e,t)=>(0,B.jsx)(vh,{className:`h-24`},t))}));let s=dE(n,i.data);return s?r(s):o((0,B.jsx)(`p`,{className:`py-8 text-center text-muted-foreground`,children:mE(`noneYet`,{plural:a.toLowerCase()})}))},oV=({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)(Ef,{open:!0,title:e,onClose:s,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:s,children:Y(`cancel`)}),(0,B.jsx)(G,{type:`submit`,form:d,variant:`primary`,loading:a,children:Y(`save`)})]}),children:(0,B.jsxs)(`form`,{id:d,className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),o(l.trim()===``?null:l.trim())},children:[t.length>0&&(0,B.jsx)(Dw,{chips:t}),(0,B.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,B.jsxs)(`div`,{className:`flex items-baseline justify-between gap-2`,children:[(0,B.jsx)(`label`,{htmlFor:c,className:`font-medium`,children:n}),!r&&(0,B.jsx)(`span`,{id:`${c}-hint`,className:`text-xs text-muted-foreground`,children:Y(`optional`)})]}),(0,B.jsx)(J,{id:c,value:l,required:r,pattern:r?`.*\\S.*`:void 0,"aria-describedby":r?void 0:`${c}-hint`,autoFocus:!0,autoComplete:`off`,onChange:e=>u(e.target.value)})]})]})})},sV=sn(),cV={start:0,end:0},lV=(e,t)=>sV.and(t,{kind:`present`,field:e.field,span:cV}),uV=e=>{switch(e.kind){case`and`:case`or`:return{...e,args:e.args.map(uV)};case`not`:return dV(e.arg);case`search`:case`present`:case`isNull`:return e;default:return lV(e,e)}},dV=e=>{switch(e.kind){case`and`:return sV.or(...e.args.map(dV));case`or`:return sV.and(...e.args.map(dV));case`not`:return uV(e.arg);case`search`:case`present`:case`isNull`:return sV.not(e);default:return lV(e,sV.not(e))}},fV=e=>{let t=it(e);if(!t.ok)throw Error(`The filter cannot be read: ${t.errors.map(e=>e.message).join(`; `)}`);return t.ast},pV=(e,t)=>{let n=fV(e);if(!n)return null;let r=fV(t),i=sV.not(uV(n));return Yt(r?sV.and(r,i):i)},mV=(e,t)=>pV(t,e),hV=e=>e.key.startsWith(`extra:`)?`extra:${e.label}`:e.key,gV=(e,t)=>{let n=new Map(e.map(e=>[hV(e),e])),r=new Map(t.map(e=>[hV(e),e])),i=e.filter(e=>!r.has(hV(e))).map(e=>({kind:`removed`,label:e.label})),a=t.flatMap(e=>{let t=n.get(hV(e));return t&&t.label!==e.label?[{kind:`changed`,label:e.label,before:t.label}]:[]}),o=t.filter(e=>!n.has(hV(e))).map(e=>({kind:`added`,label:e.label}));return[...i,...a,...o]},_V=(e,t,n,r)=>{let i=e-t;if(i===0)return Y(`asMany`,{plural:r});let a=Math.abs(i)===1?n:r;return i>0?Y(`more`,{count:i,noun:a}):Y(`fewer`,{count:-i,noun:a})},vV=12,yV={added:{word:`added`,className:`text-success-text`},removed:{word:`removed`,className:`text-danger-text`},changed:{word:`changed`,className:`text-primary-text`}},bV=({changes:e})=>(0,B.jsx)(`ul`,{"aria-label":Y(`filterChanges`),className:`divide-y rounded-md border`,children:e.map(e=>(0,B.jsxs)(`li`,{className:`grid grid-cols-[72px_1fr] gap-3 px-3 py-2`,children:[(0,B.jsx)(`span`,{className:`font-medium ${yV[e.kind].className}`,children:Y(yV[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}`))}),xV=(e,t)=>{let n=E({...yy(U(),e,t??``),enabled:t!==null});return t===null?0:n.data},SV=(e,t,n)=>`${e} ${e===1?t:n}`,CV=({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>vV&&(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:Y(`firstOf`,{limit:vV,total:i})}),r===null||i===0?(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:Y(`noPlural`,{plural:a})}):(0,B.jsx)(OA,{model:e,view:t,filter:r,sort:dh(e,t),limit:vV,display:o?.name??`table`,row:!0,link:!1,empty:`No ${a}.`})]})},wV=({model:e,view:t,title:n,before:r,after:i,saveNewLabel:a,updating:o,creating:s,onUpdate:c,onSaveNew:l,onCancel:u})=>{let d=gV(YT(e,r),YT(e,i)),f=(0,I.useMemo)(()=>pV(r,i),[r,i]),p=(0,I.useMemo)(()=>mV(r,i),[r,i]),m=xV(e,f),h=xV(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)(Ef,{open:!0,wide:!0,title:n,onClose:u,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:u,children:Y(`cancel`)}),(0,B.jsx)(G,{loading:s,disabled:o,onClick:l,children:a}),(0,B.jsx)(G,{variant:`primary`,loading:o,disabled:s,onClick:c,children:Y(`update`)})]}),children:(0,B.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[d.length>0&&(0,B.jsx)(bV,{changes:d}),v?(0,B.jsxs)(`p`,{children:[(0,B.jsx)(`span`,{className:`font-semibold`,children:_V(m,h,g,_)}),(0,B.jsxs)(`span`,{className:`text-muted-foreground`,children:[`: `,Y(`addedRemoved`,{added:SV(m,g,_),removed:h})]})]}):(0,B.jsx)(vh,{className:`h-4 w-48`}),(0,B.jsx)(CV,{model:e,view:t,title:Y(`added`),filter:f,total:m,plural:_}),(0,B.jsx)(CV,{model:e,view:t,title:Y(`removed`),filter:p,total:h,plural:_})]})})},TV=()=>{let{address:e,set:t}=Hh();return{key:e?.kind===`list`?e.savedSearch:void 0,open:e=>t({savedSearch:e})}},EV=e=>e instanceof Error?e.message:Y(`somethingWrong`),DV=(e,t)=>{let n=W(),r=U(),i=iy(),a=Cy(),{href:s,open:c}=Hh(),l=TV(),{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&&oy(p,`create`)&&oy(p,`delete`),h=n.signIn?.[u]?.signIn,g=mD(u,m),_=e=>Nn(ym(d,e)),v=f&&g.data?.find(e=>e[f.filter]===t),y=v||l.key===void 0||!p||!oy(p,`update`)?void 0:g.data?.find(e=>_(e)===l.key),b=n.views[u]?.names,x=b?.plural??`saved searches`,S=f?.name===void 0?void 0:d?.fields[f.name],C=o({mutationFn:e=>r.create(u,{[f.filter]:t,...f.name&&{[f.name]:e}}),onSuccess:e=>{l.open(_(e.record)),i.show({state:`success`,title:Y(`searchSaved`),action:{label:Y(`openPlural`,{plural:x}),href:s({kind:`list`,resource:u}),onNavigate:c}})},onError:e=>i.show({state:`error`,title:Y(`couldNotSave`),description:EV(e)}),onSettled:()=>a(u)}),w=o({mutationFn:e=>r.remove(u,_(e)),onError:e=>i.show({state:`error`,title:Y(`couldNotTakeOff`),description:EV(e)}),onSettled:()=>a(u)}),T=o({mutationFn:e=>r.update(u,_(e),{[f.filter]:t},e.etag??`*`),onSuccess:()=>i.show({state:`success`,title:Y(`searchUpdated`)}),onError:e=>i.show({state:`error`,title:Y(`couldNotUpdate`),description:EV(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)}},OV=({model:e,view:t,search:n,filter:r,chips:i,className:a})=>{let o=DV(n,r),[s,c]=(0,I.useState)(!1),[l,u]=(0,I.useState)(!1),[d,f]=(0,I.useState)();if(!o.mode)return null;let p=n.label??Y(`saveSearch`);if(o.mode===`sign-in`)return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(G,{className:a,"aria-haspopup":`dialog`,onClick:()=>c(!0),children:[(0,B.jsx)(ui,{className:`size-3.5`,"aria-hidden":!0}),p]}),(0,B.jsx)(iE,{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)(oV,{title:d,chips:i,label:o.naming.label,required:o.naming.required,busy:o.creating,onSave:e=>o.saveNew(e,{onSuccess:()=>f(void 0)}),onClose:()=>f(void 0)}),g=o.opened;if(g){let n=Y(`saveAsNew`,{noun:o.noun});return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(G,{className:a,"aria-haspopup":`dialog`,"aria-disabled":!o.ready,onClick:()=>o.ready&&u(!0),children:[(0,B.jsx)(ts,{className:`size-3.5`,"aria-hidden":!0}),(0,B.jsx)(`span`,{className:`max-w-60 truncate`,children:Y(`updateName`,{name:g.name??o.noun})})]}),(0,B.jsxs)(G,{className:a,"aria-haspopup":o.naming?`dialog`:void 0,"aria-disabled":!o.ready,onClick:()=>o.ready&&m(n),children:[(0,B.jsx)(ci,{className:`size-3.5`,"aria-hidden":!0}),n]}),l&&(0,B.jsx)(wV,{model:e,view:t,title:g.name?Y(`updateNameQuestion`,{name:g.name}):Y(`updateNounQuestion`,{noun:o.noun}),before:g.filter,after:r,saveNewLabel:n,updating:o.updating,creating:o.creating,onUpdate:()=>o.update({onSuccess:()=>u(!1)}),onSaveNew:()=>m(n),onCancel:()=>u(!1)}),h]})}let _=o.saved?oi:ui;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]})},kV=e=>e instanceof Error?e.message:Y(`somethingWrong`),AV=({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)(Vg,{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:ir(e,s?.valueLabels)},e))})]})},jV=(e,t,n)=>Object.entries(n).map(([n,r])=>`${t.fields[n]?.label??F(n)}: ${e.fields[n]?.type===`boolean`?Y(r===!0?`on`:`off`):ir(String(r),t.fields[n]?.valueLabels)}`).join(`, `),MV=({model:e,view:t,recordKey:n,title:r,row:i,fields:a})=>{let s=U(),c=iy(),l=Cy(),u=o({mutationFn:t=>s.update(e.name,n,t,i.etag??`*`),onSuccess:(n,i)=>c.show({state:`success`,title:Y(`saved`,{title:r}),description:jV(e,t,i)}),onError:e=>c.show({state:`error`,title:Y(`couldNotChange`),description:kV(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)(AV,{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))})},NV=e=>e instanceof Error?e.message:Y(`somethingWrong`),PV=({model:e,view:t,of:n,target:r,targetView:i,row:a,recordKey:s,canRename:c,onDelete:l})=>{let u=U(),d=iy(),f=Cy(),[p,m]=(0,I.useState)(!1),{name:h,chips:g,title:_,body:v}=hD({model:e,of:n,target:r,targetView:i,row:a,recordKey:s}),y=o({mutationFn:t=>u.update(e.name,s,{[n.name]:t},a.etag??`*`),onSuccess:()=>m(!1),onError:e=>d.show({state:`error`,title:Y(`couldNotRename`),description:NV(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)(Uh,{to:{kind:`record`,resource:e.name,key:s},className:`hover:underline`,children:h??(0,B.jsx)(Ow,{chips:g})})})}),(0,B.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[n.controls&&(0,B.jsx)(MV,{model:e,view:t,recordKey:s,title:_,row:a,fields:n.controls}),c&&b&&(0,B.jsx)(G,{variant:`ghost`,"aria-label":Y(`renameTitle`,{title:_}),"aria-haspopup":`dialog`,onClick:()=>m(!0),children:(0,B.jsx)(Lo,{className:`size-3.5`,"aria-hidden":!0})}),l&&(0,B.jsx)(G,{variant:`ghost`,"aria-label":Y(`deleteTitle`,{title:_}),onClick:()=>l(_),children:(0,B.jsx)(qs,{className:`size-3.5`,"aria-hidden":!0})})]})]}),p&&b&&(0,B.jsx)(oV,{title:Y(`renameTitle`,{title:_}),chips:g,label:t.fields[b.name]?.label??F(b.name),required:!b.nullable,initial:h,busy:y.isPending,onSave:e=>y.mutate(e),onClose:()=>m(!1)}),(0,B.jsx)(dD,{...v})]})},FV=({model:e,view:t})=>{let{resources:n,views:r}=W(),i=t.searchesOf,a=n[i.resource],o=r[i.resource],s=mD(e.name,!0),c=af(e.name),l=ZL({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)(SS,{title:u,subtitle:t.help}),e]});if(!a)return d((0,B.jsx)(tf,{title:Y(`notFound`),children:Y.rich(`noResource`,{resource:i.resource})}));if(s.error)return d((0,B.jsx)(Bg,{title:Y(`couldNotLoadYour`,{plural:u.toLowerCase()}),error:s.error}));if(!s.data)return d((0,B.jsx)(`div`,{className:`flex flex-col gap-3`,children:Array.from({length:2},(e,t)=>(0,B.jsx)(vh,{className:`h-56`},t))}));if(s.data.length===0){let e=(o?.names?.plural??F(a.name)).toLowerCase();return d((0,B.jsx)(`p`,{className:`py-8 text-center text-muted-foreground`,children:Y.rich(`noSavedYet`,{plural:u.toLowerCase(),list:(0,B.jsx)(Uh,{to:{kind:`list`,resource:a.name},className:`font-medium text-primary-text hover:underline`,children:e})})}))}return d((0,B.jsx)(`div`,{className:`flex flex-col gap-4`,children:s.data.map(n=>{let r=Nn(ym(e,n)),s=oy(c,`delete`)?e=>void l.start({key:r,title:e,etag:n.etag,snapshot:n}):void 0;return(0,B.jsx)(PV,{model:e,view:t,of:i,target:a,targetView:o,row:n,recordKey:r,canRename:oy(c,`update`),onDelete:s},r)})}))},IV=({field:e,hints:t,resource:n,stored:r,onSave:i,close:a})=>{let[o,s]=(0,I.useState)(()=>xg(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&&Sg(e,s,r)&&i(yg(e,s)),a(n))};return(0,B.jsx)(`div`,{ref:c,className:`w-full min-w-0`,onKeyDown:e=>{wv(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)&&!wv(e.relatedTarget)&&d(!0)},children:(0,B.jsx)(Ov,{field:e,hints:t,value:o,stored:r,resource:n,onChange:e=>{s(e),u&&d(!0,void 0,e)}})})},LV=M(`app/list-edit`),RV=e=>{let t=U(),n=Se(),r=iy(),[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=ym(e,i),u=String(o.current.get(i.id)?.etag??i.etag);try{let r=await t.update(e.name,l,{[a]:s},u);c(i.id,{[a]:r.record[a],etag:r.etag}),n.setQueryData(H.record(e.name,Nn(l)),r),n.invalidateQueries({queryKey:[`page`,e.name]}),n.invalidateQueries({queryKey:[`list`,e.name]}),n.invalidateQueries({queryKey:[`map`,e.name]})}catch(n){if(!pl(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:LV(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}}},zV=(e,t,n)=>{let r=RV(e),i=t?.list?.editable??[];return{editor:i.length>0&&oy(n,`update`)?{editable:(t,n)=>i.includes(n)&&e.fields[n]!==void 0&&mg(e.fields[n])&&sy(t,`update`),render:(n,i,a)=>(0,B.jsx)(IV,{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}},BV=(e,t,{href:n,go:r})=>{if(`to`in e){let i=mn(e.to,t);return{href:n(i),onFollow:()=>r(i)}}let i=fy(e.href,t);if(i===void 0)throw Error(`A link action without a target on the record is not shown`);return{href:i,newTab:/^https?:/i.test(i)}},VV=(e,t)=>({model:e,record:Object.fromEntries(Object.entries(uh(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}}),HV=e=>{let{views:t}=W(),n=Ty(e.name,void 0),r=Hh(),[i,a]=(0,I.useState)(),o=(t[e.name]?.actions??[]).filter(e=>!e.inputs?.length),s=e=>`row`in e?n.run(e.action,e.row):n.runEach(e.action,e.selection,e.skipped),c=e=>{e.action.confirm?a(e):s(e)};return{rowActions:o.map(t=>{let i=n=>gy(t,VV(e,n).record),a={label:e=>i(e)?.label??t.label,destructive:Wv(t)},o=t.run,s=r=>n.blockedOn(t,VV(e,r)),l=e=>i(e)!==void 0;return o?.kind===`link`?{...a,available:l,blocked:s,link:t=>BV(o,VV(e,t).record,r)}:{...a,available:l,blocked:s,onSelect:n=>c({action:t,row:VV(e,n)})}}),bulkActions:o.filter(e=>e.bulk&&e.run?.kind!==`link`).map(t=>({label:e=>fB(`actionCount`,{label:t.label,count:e}),destructive:Wv(t),available:r=>n.appliesOn(t,VV(e,r)),onRun:(n,r)=>c({action:t,selection:n.map(t=>VV(e,t)),skipped:r})})),prompt:i&&(0,B.jsx)(Uv,{action:i.action,label:i.action.label,danger:Wv(i.action),onCancel:()=>a(void 0),onConfirm:()=>{a(void 0),s(i)}})}},UV=(e,t,n)=>({order:r,index:i})=>{let a=t=>r.findIndex(n=>Nn(ym(e,n))===t),o=t.after.find(e=>a(e.key)>i);if(o)return sO(`dependsOn`,{record:n,other:o.title});let s=t.before.find(e=>a(e.key)!==-1&&a(e.key)<i);return s?sO(`dependsOn`,{record:s.title,other:n}):void 0},WV=(e,t,n,r)=>{let i=e[t],a;for(let o=n;o<e.length;o++){let n=r({record:i,order:ee(e,t,o),index:o});if(n===void 0)return{to:o,...a!==void 0&&{reason:a}};a??=n}return{to:t,reason:a}},GV=({model:e,view:t,field:n,filter:r,fields:i,rule:a})=>{let o=U(),s=iy(),c=Cy(),{resources:l,views:u}=W(),d=`${n} asc`,f=E({queryKey:[...H.list(e.name,r,d,500,`hand-order`),i.join(`,`)],queryFn:async()=>{let t=Cb(l,u,e,i),n=[],a=``;do{let s=await o.search(e.name,{filter:r||void 0,orderBy:d,pageSize:500,labels:t,...a&&{pageToken:a}});n.push(...wb(l,e,i,s.items,s.labels).map((t,n)=>({...t,id:vm(e,s.items[n])}))),a=s.nextPageToken}while(a);return n}}),[p,m]=(0,I.useState)(),h=(0,I.useRef)(void 0),g=(0,I.useRef)(void 0),_=(0,I.useRef)(Promise.resolve()),v=(0,I.useRef)(0),y=(0,I.useRef)(void 0),b=async()=>{let t=h.current,r=g.current;if(g.current=void 0,!t||!r)return;let i=tO(t.map(e=>e[n]),r.first,r.last),a=t.slice(i.first,i.last+1),c=Object.fromEntries(a.flatMap(t=>typeof t.etag==`string`?[[Nn(ym(e,t)),t.etag]]:[])),l=(await o.batchWrite([{op:`reorder`,resource:e.name,field:n,keys:a.map(t=>ym(e,t)),start:i.start,etags:c}])).results[0];if(l?.op!==`reorder`)return;let u=new Map(a.map(e=>[e.id,{[n]:e[n]}])),d=XD(e,l.records.map(t=>({...t,before:u.get(vm(e,t.record))??{}})),[n]);if(y.current!==void 0&&s.dismiss(y.current),y.current=s.show({state:`success`,title:YD(`orderChanged`),action:{label:YD(`undo`),onClick:()=>D(d)}}),!h.current)return;let f=new Map(l.records.map(t=>[vm(e,t.record),t]));h.current=h.current.map(e=>{let t=f.get(e.id);return t?{...e,[n]:t.record[n],etag:t.etag}:e})},x=e=>t=>{h.current=void 0,g.current=void 0,m(void 0),s.show({state:`error`,title:e,description:Um(t)})},S=async()=>{--v.current,!(v.current>0)&&(await c(e.name),!(v.current>0)&&(h.current=void 0,m(void 0)))},C=(n,r)=>{let i=h.current??f.data;if(!i||n===r)return;if(!e.position?.after)return w(i,n,r,a);let s=uh(e,i[n]).record,c=i[n].id;$D(o,e,t,s).then(n=>{let i=h.current??f.data,o=UV(e,n,lr(e,t,s,c));w(i,i.findIndex(e=>e.id===c),r,e=>o(e)??a?.(e))},x(YD(`couldNotChange`)))},w=(e,t,n,r)=>{if(t===-1||t===n)return;let i=r?T(e,t,n,r):n;if(t===i)return;h.current=ee(e,t,i);let a=Math.min(t,i),o=Math.max(t,i);g.current=g.current?{first:Math.min(g.current.first,a),last:Math.max(g.current.last,o)}:{first:a,last:o},m(h.current),v.current+=1,_.current=_.current.then(b).catch(x(YD(`couldNotChange`))).then(S)},T=(t,n,r,i)=>{let a=WV(t.map(t=>uh(e,t).record),n,r,i);return a.reason!==void 0&&s.show({state:`warning`,title:a.to===n?YD(`notMoved`):YD(`movedToPlace`,{place:a.to+1}),description:a.reason}),a.to},D=e=>{y.current!==void 0&&s.dismiss(y.current),y.current=void 0,v.current+=1,_.current=_.current.then(async()=>{await o.batchWrite(e),h.current=void 0,g.current=void 0,m(void 0)}).catch(x(YD(`couldNotUndo`))).then(S)};return{rows:p??f.data,loading:f.isPending,error:f.error,move:C}},KV=({model:e,view:t,field:n,filter:r,columns:i,sort:a})=>{let{resources:o,views:s}=W(),{fields:c,dropRules:l}=c_(),{go:u,href:d}=Hh(),f=a!==void 0,p=(0,I.useMemo)(()=>yA(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)(()=>sh(e,t,p.map(e=>e.id)),[e,t,p]),h=t?.list?.drag?.rule,g=h===void 0?void 0:l?.[h],_=GV({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)(ov,{children:YD.rich(`noRule`,{rule:h})});if(_.loading)return(0,B.jsx)(`div`,{className:`flex flex-col gap-2`,children:Array.from({length:3},(e,t)=>(0,B.jsx)(vh,{className:`h-4 w-full`},t))});if(_.error)return(0,B.jsx)(Bg,{title:YD(`couldNotLoad`),error:_.error});if(!y||y.total===0)return(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:YD(`nothingYet`)});let b=t=>u({kind:`record`,resource:e.name,key:ym(e,t)});return(0,B.jsx)(mw,{fit:!0,scroll:`parent`,columns:p,source:y,latencyMs:0,onOpenRow:b,rowLink:t=>({href:d({kind:`record`,resource:e.name,key:ym(e,t)}),onFollow:()=>b(t)}),...a&&{sort:a.value,onSortChange:a.onChange},rowNumbers:!1,reorder:{label:n=>lr(e,t,n,n.id),onMove:_.move}})},qV=({sorting:e,onChange:t,size:n,iconOnly:r=!1})=>{let i=YD(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)(Si,{className:`size-3.5`}):(0,B.jsx)(Br,{className:`size-3.5`}),!r&&i]})},JV=sn(),YV=e=>e.find(e=>e.kind===`search`),XV=({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)(iE,{as:`page`,prompt:a.signIn}):(0,B.jsx)(tf,{title:q(`notFound`),children:q(`noResource`,{name:e.resource})});let o=Cn(n[e.resource],e.list);if(e.list!==void 0&&!o)return(0,B.jsx)(tf,{title:q(`notFound`),children:fB(`noList`,{name:e.list})});if(o?.searchesOf)return(0,B.jsx)(FV,{model:i,view:o});let s=mh(t,n,e.resource,e.list);if(o&&s.listOf){let t=s.model;return(0,B.jsx)(aV,{model:i,view:o,target:t,children:n=>(0,B.jsx)(ZV,{model:t,address:e,scope:n,heading:{title:o.names?.plural??F(i.name),subtitle:o.help}})})}return(0,B.jsx)(ZV,{model:i,address:e})},ZV=({model:e,address:t,scope:n,heading:r})=>{let i=W(),{set:a,listTo:o,go:s,href:c}=Hh(),l=e.name,u=Cn(i.views[l],t.list),d=(0,I.useMemo)(()=>RT(u,e),[u,e]),{fields:f}=c_(),p=(0,I.useMemo)(()=>iV(hA(fA(jm(e,u),e,u,f),e,i.resources,i.views),e,u,i.resources,i.views),[e,u,f,i.resources,i.views]),m=t.filter,h=(0,I.useMemo)(()=>MT(d,m),[d,m]),g=h.ok?h.state:Lw,_=h.ok?h.extras:[],{orderBy:v,filterLayout:y}=t,b=gf(),x=_f(),[S,C]=(0,I.useState)(!1),w=n?[..._,n]:_,T=p_(),E=BL({model:e,resources:i.resources,views:i.views,view:u,state:g,extras:w,titleOf:T}),D=n?TT(d,g,w):h.ok?m:``,O=(0,I.useMemo)(()=>sh(e,u,p.map(e=>e.id)),[e,u,p]),k=(0,I.useMemo)(()=>xE(u,i.resources,i.views,O),[u,i.resources,i.views,O]),A=Tw({resources:i.resources,views:i.views,model:e,columns:O,filter:D,orderBy:v,related:k}),j=Xm(e,u,t.display),ee=af(l),te=n?void 0:AD(e,ee),[ne,re]=(0,I.useState)(!1),ie=ne&&te!==void 0,ae=!j&&!ie&&MD(u,te,v,D),oe=ie||j?.kind!==`map`;vx(oe);let se=zD(e,A.page,A.key,j?.kind===`custom`),ce=zB(),le=cr(e,u),ue=e=>({key:e.id,title:String(typeof e[le]==`object`?e[le].name:e[le]??e.id),etag:typeof e.etag==`string`?e.etag:void 0,snapshot:e}),de=u?.names?.singular??F(l),fe=zV(e,u,ee),{state:pe}=V(),me=ZL({model:e,view:u,restore:QL(e),onReview:e=>s({kind:`record`,resource:l,key:e.key})}),he=HV(e),ge=u?.actions.some(e=>e.run?.kind===`delete`)??!1,_e=(e,t=_)=>a({filter:TT(d,e,t)}),ve=YV(_),ye=e=>{let t=_.filter(e=>e.kind!==`search`);_e(g,e?[...t,JV.search(e)]:t)},be=u?.names?.plural??F(l),xe=j?.kind===`calendar`||j?.kind===`timeline`||j?.kind===`board`&&Bm(e)?void 0:j,Se=xe&&(0,B.jsx)(dA,{model:e,view:u,display:xe,orderBy:v,onChange:e=>a({orderBy:e})}),Ce=e.search?.length?(0,B.jsx)(XB,{value:ve?.kind===`search`?ve.text:``,onCommit:ye,placeholder:fB(`searchPlural`,{plural:be}),className:b?void 0:`min-h-11`}):null,we=(0,B.jsx)(pT,{layout:y,config:E,value:g,onChange:_e,leading:y===`bar`?Se:void 0,trailing:Ce}),Te=y===`bar`?we:(0,B.jsx)(dT,{groups:[Se?[Se]:[]],trailing:Ce}),Ee=Hw(E,g),De=(0,B.jsx)(Mw,{scroll:!0,chips:Ee,onRemove:e=>_e(Uw(g,e)),onClear:()=>_e(Lw)}),Oe=xe&&(0,B.jsx)(Xw,{title:fB(`sort`),children:(0,B.jsx)(dA,{model:e,view:u,display:xe,orderBy:v,onChange:e=>a({orderBy:e}),className:`min-h-11 w-full`})}),ke=(0,B.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,B.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,B.jsxs)(G,{className:`min-h-11`,onClick:()=>C(!0),"aria-haspopup":`dialog`,children:[(0,B.jsx)(Cs,{className:`size-3.5`}),Ee.length>0?fB(`filtersCount`,{count:Ee.length}):fB(`filters`)]}),Ce??(0,B.jsx)(`div`,{className:`min-w-0 flex-1`,children:De})]}),Ce&&De,(0,B.jsx)(Tf,{title:fB(`filters`),open:S,onClose:()=>C(!1),children:(0,B.jsx)(pT,{layout:`panel`,fullWidth:!0,config:E,value:g,onChange:_e,leading:Oe})})]}),Ae=!n&&$L(u,i.pages,ee)&&(0,B.jsxs)(Uh,{to:{kind:`create`,resource:l},className:mf({variant:`primary`}),children:[(0,B.jsx)(qo,{className:`size-3.5`}),fB(`newRecord`,{singular:de})]}),je=u?.saveSearch&&!n&&h.ok&&m&&(0,B.jsx)(OV,{model:e,view:u,search:u.saveSearch,filter:m,chips:GT(e,u,m,KT(E))}),Me=!n&&(0,B.jsx)(Ez,{model:e}),Ne=dB({model:e,view:u,resources:i.resources,views:i.views,plural:be,filter:D,orderBy:v}),M=Iz(u)&&(0,B.jsxs)(G,{onClick:()=>Ne.open(),...!b&&{"aria-label":fB(`export`),title:fB(`export`)},children:[(0,B.jsx)(na,{className:`size-3.5`}),b&&fB(`export`)]}),Pe=te&&!ae&&(0,B.jsx)(qV,{sorting:ie,onChange:re,iconOnly:!b}),Fe=t=>!ie&&(0,B.jsx)(lA,{view:u,choices:eh(e,u,x),value:j?.name??`table`,onChange:e=>a({display:e}),menu:t}),Ie=ZT(e),Le=t=>{Ie(uh(e,t).record),s({kind:`record`,resource:l,key:ym(e,t)})},Re=A.source?(0,B.jsx)(mw,{columns:p,source:A.source,sort:fh(v),onSortChange:e=>a({orderBy:ph(e)}),onOpenRow:Le,rowLink:t=>({href:c({kind:`record`,resource:l,key:ym(e,t)}),onFollow:()=>Le(t)}),cellEditor:fe.editor,rowPatches:fe.patches,initialScrollIndex:ce.initialIndex,onScrollIndex:ce.remember,rowActions:[{label:fB(`openRecord`,{singular:de}),onSelect:Le},...he.rowActions,...oy(ee,`delete`)&&!ge?[{label:fB(`delete`),destructive:!0,available:e=>sy(e,`delete`),onSelect:e=>void me.start(ue(e))}]:[]],bulkActions:[...Iz(u)&&Hz(e)?[{label:e=>fB(`exportCount`,{count:e}),onRun:e=>Ne.open(e)}]:[],...he.bulkActions,...oy(ee,`delete`)?[{label:e=>fB(`deleteCount`,{count:e}),destructive:!0,onRun:e=>me.startBulk(e.map(ue))}]:[]],rowNumbers:!1,pinKey:pe.kind===`signed-in`?mC(pe.user.id,$B(l,t.list)):void 0,scroll:`parent`,className:`flex-1`}):(0,B.jsx)(`div`,{className:`flex-1 rounded-lg border bg-surface`}),N={...A,initialIndex:ce.initialIndex,onScrollIndex:ce.remember},ze=mB({plural:be,search:ve?.kind===`search`?ve.text:``,filtered:Ee.length>0,scoped:!!n||_.some(e=>e.kind!==`search`),canCreate:!!Ae}),Be=(0,B.jsx)(pB,{state:ze,onClearSearch:()=>ye(``),onClearFilters:()=>_e(Lw),create:Ae}),Ve=ie?(0,B.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:fB(`dragToSort`)}),(0,B.jsx)(KV,{model:e,view:u,field:te,filter:``,columns:Tr(e,u)})]}):ae?(0,B.jsx)(KV,{model:e,view:u,field:te,filter:``,columns:Tr(e,u),sort:{value:fh(v),onChange:e=>a({orderBy:ph(e)})}}):j?j.kind===`cards`?(0,B.jsx)(kB,{model:e,view:u,display:j,list:N,empty:Be},A.key.join(` `)):j.kind===`map`?(0,B.jsx)(aA,{model:e,view:u,display:j,filter:D,orderBy:v,fields:O,at:t.map,onMove:e=>a({map:e}),flush:!0}):j.kind===`board`?(0,B.jsx)(fO,{model:e,view:u,display:j,fields:O,filter:D,orderBy:v}):j.kind===`calendar`?(0,B.jsx)(XO,{model:e,view:u,display:j,fields:O,filter:D,at:t.calendar,linkTo:e=>o({calendar:e})}):j.kind===`timeline`?(0,B.jsx)(_k,{model:e,view:u,display:j,fields:O,filter:D,at:t.timeline,linkTo:e=>o({timeline:e})}):(0,B.jsx)(Dk,{display:j,list:se}):A.source?.total===0&&!A.error?Be:Re;return(0,B.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 px-5 py-4`,children:[me.dialogs,Ne.dialogs,he.prompt,(0,B.jsx)(SS,{title:r?.title??be,subtitle:r?r.subtitle:u?.help,subtitleBelow:!0,actions:(0,B.jsxs)(B.Fragment,{children:[Fe(!b),Pe,je,Me,M,Ae]})}),!h.ok&&(0,B.jsx)(Bg,{title:fB(`unreadableFilter`),error:Error(h.errors.map(e=>e.message).join(`; `))}),A.error&&!j&&!ie&&(0,B.jsx)(Bg,{title:fB(`couldNotLoadRows`),error:A.error}),u?.chart&&!ie&&(An(u.chart)?(0,B.jsx)(YB,{model:e,view:u,chart:u.chart,plural:be,filter:D}):(0,B.jsx)(qB,{resource:l,chart:u.chart,title:fB(`created`,{plural:be}),noun:be.toLowerCase(),filter:D})),!ie&&(b?Te:ke),b&&y===`panel`&&!ie?(0,B.jsxs)(`div`,{className:`flex min-h-0 flex-1 gap-4`,children:[(0,B.jsx)(`div`,{className:oe?`sticky top-[calc(var(--pb-sticky-top,0px)+1rem)] flex max-h-[calc(100dvh-var(--pb-sticky-top,0px)-var(--pb-sticky-bottom,0px)-2rem)] shrink-0 self-start`:`flex shrink-0`,children:we}),Ve]}):Ve]})},QV=()=>{let e,t=new Set;return{get:()=>e,set:n=>{if(n!==e){e=n;for(let e of t)e()}},subscribe:e=>(t.add(e),()=>void t.delete(e))}},$V=(0,I.createContext)(void 0),eH=()=>()=>{},tH=()=>void 0,nH=()=>{let e=(0,I.useContext)($V);return(0,I.useSyncExternalStore)(e?.subscribe??eH,e?.get??tH,e?.get??tH)},rH=(e,t)=>e&&Object.hasOwn(e,t)?e[t]:void 0,iH=e=>e?.role===`owner`?[`owner`,`admin`,`member`]:[`admin`,`member`],aH=({member:e,current:t,status:n,presence:r,onChanged:i})=>{let{session:a,organizations:o}=V(),s=t.organization.id,{busy:c,error:l,run:u}=KA(),d=o?.roles??[],f=e.id===t.memberId,p=iH(t),m=e.role===`owner`&&t.role!==`owner`,h=d.filter(e=>e.membership);return(0,B.jsx)(vj,{name:e.name,email:e.email,self:f,error:l,...(n||r)&&{status:(0,B.jsx)(nS,{status:n,presence:r})},actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`select`,{"aria-label":X(`roleOf`,{name:e.name}),value:e.role,disabled:c||m,onChange:t=>void u(async()=>{await a.organizations.setRole(s,e.id,t.target.value),i()}),className:`h-7 rounded-md border border-border-strong bg-background px-2 text-body`,children:(m?[e.role]:p).map(e=>(0,B.jsx)(`option`,{value:e,children:ij(e)},e))}),!f&&(0,B.jsx)(G,{size:`sm`,variant:`danger`,loading:c,disabled:m,onClick:()=>void u(async()=>{await a.organizations.removeMember(s,e.id),i()}),children:X(`remove`)})]}),children:(0,B.jsx)(ZA,{roles:h,selected:e.appRoles,grantable:cj(d,t),disabled:c,onChange:t=>void u(async()=>{await a.organizations.setAppRoles(e.id,t),i()})})})},oH=({current:e,statuses:t,presence:n})=>{let{session:r}=V(),[i,a]=(0,I.useState)(),[o,s]=(0,I.useState)(),c=e?.organization?.id,l=(0,I.useCallback)(()=>{c&&r.organizations.members(c).then(a,e=>s(e instanceof wu?BA(e):X(`couldNotReadMembers`)))},[r,c]);return(0,I.useEffect)(l,[l]),e?.organization?(0,B.jsxs)(`div`,{className:`mx-auto flex w-full max-w-3xl flex-col gap-4 px-4 py-6 md:px-6`,children:[(0,B.jsx)(SS,{title:X(`members`),subtitle:X(`whoWorks`,{organization:e.organization.name})}),(0,B.jsxs)(PA,{title:X(`members`),description:X(`membersDescription`),children:[(0,B.jsx)(FA,{message:o}),i?(0,B.jsx)(`ul`,{className:`divide-y rounded-md border`,children:i.map(r=>(0,B.jsx)(aH,{member:r,current:e,status:t?.find(e=>e.userId===r.userId),presence:rH(n,r.userId),onChanged:l},`${r.id}/${r.role}/${r.appRoles.join()}`))}):!o&&(0,B.jsxs)(`div`,{className:`flex items-center gap-2 text-muted-foreground`,children:[(0,B.jsx)($d,{}),` `,X(`loading`)]})]})]}):null},sH=({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)(YA,{title:X(`inviteSomeone`),description:X(`inviteDescription`),onInvite:async r=>{let i=await n.organizations.invite(e.organization.id,{email:r,role:a,appRoles:s});return c([]),t(),i},beside:(0,B.jsx)(`select`,{"aria-label":X(`organizationRole`),value:a,onChange:e=>o(e.target.value),className:`h-8 rounded-md border border-border-strong bg-background px-2`,children:iH(e).map(e=>(0,B.jsx)(`option`,{value:e,children:ij(e)},e))}),children:(0,B.jsx)(ZA,{roles:i.filter(e=>e.membership),selected:s,grantable:cj(i,e),onChange:c})})},cH=({invitation:e,organizationId:t,onChanged:n})=>{let{session:r,organizations:i}=V(),a=e.appRoles.map(e=>aj(i?.roles??[],e));return(0,B.jsx)(XA,{email:e.email,gives:`${ij(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()}})},lH=({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)(SS,{title:X(`invitations`),subtitle:X(`peopleInvited`,{organization:e.organization.name})}),(0,B.jsx)(sH,{current:e,onSent:a}),(0,B.jsx)(PA,{title:X(`notAcceptedYet`),description:n.length>0?X(`sendingAgain`):X(`nobodyWaiting`),children:n.length>0&&(0,B.jsx)(`ul`,{className:`divide-y rounded-md border`,children:n.map(e=>(0,B.jsx)(cH,{invitation:e,organizationId:i,onChanged:a},e.id))})})]})},uH=({usePresence:e,store:t})=>{let n=e();return(0,I.useEffect)(()=>t.set(n),[t,n]),(0,I.useEffect)(()=>()=>t.set(void 0),[t]),null},dH=({children:e})=>{let{presence:t}=c_(),[n]=(0,I.useState)(QV),[r,i]=(0,I.useState)({hook:t,key:0});return r.hook!==t&&i({hook:t,key:r.key+1}),(0,B.jsxs)($V.Provider,{value:n,children:[t&&(0,B.jsx)(uH,{usePresence:t,store:n},r.key),e]})},fH=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 wu?BA(e):X(`couldNotReadOrganizations`)))},[e,t,c]),{current:n,organizations:i,...o&&{error:o},reload:u}},pH=e=>window.location.assign(`${e}/`),mH=({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}=KA(),d=i.trim()!==e.name||o!==e.slug;return(0,B.jsxs)(PA,{title:X(`details`),description:X(t?`detailsEditable`:`detailsReadOnly`),children:[(0,B.jsx)(FA,{message:l}),(0,B.jsxs)(`form`,{className:`flex flex-col gap-2 sm:flex-row`,onSubmit:t=>{t.preventDefault(),u(async()=>{await r.organizations.rename(e.id,{name:i.trim(),slug:o}),n()})},children:[(0,B.jsx)(J,{"aria-label":X(`name`),value:i,disabled:!t,onChange:e=>a(e.target.value),wrapperClassName:`flex-1`}),(0,B.jsx)(J,{"aria-label":X(`slug`),value:o,disabled:!t,onChange:e=>s(e.target.value),wrapperClassName:`sm:w-48`}),t&&(0,B.jsx)(G,{type:`submit`,variant:`primary`,loading:c,disabled:!d||!i.trim(),children:X(`save`)})]})]})},hH=({organization:e,memberId:t})=>{let{session:n}=V(),[r,i]=(0,I.useState)([]),[a,o]=(0,I.useState)(``),{busy:s,error:c,run:l}=KA();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)(PA,{title:X(`handOver`),description:X(`handOverDescription`),children:[(0,B.jsx)(FA,{message:c}),(0,B.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,B.jsxs)(`select`,{"aria-label":X(`newOwner`),value:a,onChange:e=>o(e.target.value),className:`h-8 flex-1 rounded-md border border-border-strong bg-background px-2`,children:[(0,B.jsx)(`option`,{value:``,children:X(`chooseMember`)}),r.map(e=>(0,B.jsxs)(`option`,{value:e.id,children:[e.name,` (`,e.email,`)`]},e.id))]}),(0,B.jsx)(G,{loading:s,disabled:!a,onClick:()=>void l(async()=>{await n.organizations.transferOwnership(a),window.location.reload()}),children:X(`handOver`)})]})]})},gH=({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}=KA(),u=()=>l(async()=>{await n.organizations.remove(e.id),pH(t)});return(0,B.jsxs)(PA,{title:X(`deleteOrganization`),description:X(`deleteDescription`),children:[(0,B.jsx)(FA,{message:r?void 0:c}),(0,B.jsx)(G,{variant:`danger`,onClick:()=>i(!0),children:X(`deleteOrganization`)}),r&&(0,B.jsxs)(Cf,{title:X(`deleteTitle`,{name:e.name}),description:X(`deleteConfirm`),onClose:()=>i(!1),actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:()=>i(!1),children:X(`cancel`)}),(0,B.jsx)(G,{variant:`danger`,loading:s,disabled:a!==e.name,onClick:()=>void u(),children:X(`delete`)})]}),children:[(0,B.jsx)(FA,{message:c}),(0,B.jsx)(J,{"aria-label":X(`organizationName`),value:a,onChange:e=>o(e.target.value)})]})]})},_H=({editable:e})=>{let t=U(),[n,r]=(0,I.useState)(),{busy:i,error:a,run:o}=KA();return(0,I.useEffect)(()=>{t.callGuests.allowed().then(r)},[t]),n===void 0?null:(0,B.jsxs)(PA,{title:X(`guestLinks`),description:X(`guestLinksDescription`),children:[(0,B.jsx)(FA,{message:a}),(0,B.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-foreground`,children:[(0,B.jsx)(Vg,{checked:n,label:X(`guestLinksAllowed`),...e&&!i&&{onChange:e=>void o(async()=>{await t.callGuests.setAllowed(e),r(e)})}}),X(`guestLinksAllowed`)]})]})},vH=({organization:e,basePath:t,owner:n})=>{let{session:r}=V(),{busy:i,error:a,run:o}=KA();return(0,B.jsxs)(PA,{title:X(`leave`),description:X(n?`leaveOwner`:`leaveMember`),children:[(0,B.jsx)(FA,{message:a}),(0,B.jsx)(G,{loading:i,onClick:()=>void o(async()=>{await r.organizations.leave(e.id),pH(t)}),children:X(`leaveName`,{name:e.name})})]})},yH=({current:e,basePath:t,onChanged:n})=>{let r=Gd().data?.calls===!0,i=e?.organization;if(!i)return(0,B.jsx)(`div`,{className:`mx-auto w-full max-w-3xl px-4 py-6 md:px-6`,children:(0,B.jsx)(SS,{title:X(`organization`),subtitle:X(`noOrganization`)})});let a=e.role===`owner`;return(0,B.jsxs)(`div`,{className:`mx-auto flex w-full max-w-3xl flex-col gap-4 px-4 py-6 md:px-6`,children:[(0,B.jsx)(SS,{title:i.name,subtitle:e.role?X(`youAre`,{role:ij(e.role).toLowerCase()}):X(`throughGlobalRoles`)}),(0,B.jsx)(mH,{organization:i,editable:oj(e),onSaved:n},`${i.name}/${i.slug}`),r&&e.role&&(0,B.jsx)(_H,{editable:oj(e)}),a&&e.memberId&&(0,B.jsx)(hH,{organization:i,memberId:e.memberId}),e.role&&(0,B.jsx)(vH,{organization:i,basePath:t,owner:a}),a&&(0,B.jsx)(gH,{organization:i,basePath:t})]})},bH=({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)(Pf,{tone:`green`,children:X(`current`)}):(0,B.jsx)(G,{size:`sm`,loading:n,onClick:r,children:X(`open`)})]}),xH=({basePath:e,currentId:t})=>{let{session:n}=V(),[r,i]=(0,I.useState)(``),a=_j((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}=KA();return(0,B.jsx)(gj,{title:X(`allOrganizations`),description:X(`allOrganizationsDescription`),searchLabel:X(`findOrganization`),placeholder:X(`nameOrSlug`),query:r,onQuery:i,list:a,error:s,renderRow:r=>(0,B.jsx)(bH,{organization:r,current:r.id===t,busy:o,onOpen:()=>void c(async()=>{await n.organizations.switchTo(r.id),pH(e)})},r.id)})},SH=e=>e.normalize(`NFKD`).replace(/[̀-ͯ]/g,``).toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,63),CH=({basePath:e})=>{let{session:t}=V(),[n,r]=(0,I.useState)(``),[i,a]=(0,I.useState)(),{busy:o,error:s,run:c}=KA(),l=()=>c(async()=>{await t.organizations.create({name:n.trim(),slug:i??SH(n)}),pH(e)});return(0,B.jsxs)(PA,{title:X(`newOrganization`),description:X(`newOrganizationDescription`),children:[(0,B.jsx)(FA,{message:s}),(0,B.jsxs)(`form`,{className:`flex flex-col gap-2 sm:flex-row`,onSubmit:e=>{e.preventDefault(),l()},children:[(0,B.jsx)(J,{"aria-label":X(`name`),placeholder:X(`name`),value:n,onChange:e=>r(e.target.value),wrapperClassName:`flex-1`}),(0,B.jsx)(J,{"aria-label":X(`slug`),placeholder:`slug`,value:i??SH(n),onChange:e=>a(e.target.value),wrapperClassName:`sm:w-48`}),(0,B.jsx)(G,{type:`submit`,variant:`primary`,loading:o,disabled:!n.trim(),children:X(`create`)})]})]})},wH=({basePath:e})=>{let{session:t,organizations:n}=V(),[r,i]=(0,I.useState)([]),{busy:a,error:o,run:s}=KA();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),pH(e)});return(0,B.jsxs)(PA,{title:X(`invitationsForYou`),description:X(`invitationsForYouDescription`),children:[(0,B.jsx)(FA,{message:o}),(0,B.jsx)(`ul`,{className:`divide-y rounded-md border`,children:r.map(e=>(0,B.jsxs)(`li`,{className:`flex items-center gap-3 px-3 py-2.5`,children:[(0,B.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,B.jsx)(`span`,{className:`font-medium`,children:e.organizationName??X(`anOrganization`)}),`: `,e.appRoles.map(e=>aj(c,e)).join(`, `)||X(`noAppRoles`),(0,B.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:X(`until`,{date:new Date(e.expiresAt).toLocaleDateString(Le())})})]}),(0,B.jsx)(G,{size:`sm`,variant:`primary`,loading:a,onClick:()=>void l(e.id),children:X(`accept`)})]},e.id))})]})},TH=({state:e,basePath:t})=>{let{session:n,organizations:r,state:i}=V(),{busy:a,error:o,run:s}=KA(),c=i.kind===`signed-in`?i.user:void 0,l=r?.create===`everyone`||c!==void 0&&R_(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)(SS,{title:X(`organizations`),subtitle:X(`organizationsSubtitle`)}),(0,B.jsxs)(PA,{title:X(`yourOrganizations`),description:e.organizations.length>0?X(`memberOf`):X(`notMember`),children:[(0,B.jsx)(FA,{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)(bH,{organization:e,current:e.id===u,busy:a,onOpen:()=>void s(async()=>{await n.organizations.switchTo(e.id),pH(t)})},e.id))})]}),(0,B.jsx)(wH,{basePath:t}),l&&(0,B.jsx)(CH,{basePath:t}),(e.current?.globalRoles.length??0)>0&&(0,B.jsx)(xH,{basePath:t,currentId:u})]})},EH=(e,t)=>t?.active?{...e,role:t.active}:e,DH=M(`roles`),OH=(e,t)=>e instanceof wu?BA(e):t,kH=(e,t=!0)=>{let{session:n}=V(),r=iy(),[i,a]=(0,I.useState)();(0,I.useEffect)(()=>{t&&n.roles.current().then(a,e=>r.show({state:`error`,title:OH(e,DH(`couldNotReadRoles`))}))},[n,r,t]);let o=(0,I.useCallback)(t=>void n.roles.switchTo(t).then(e,e=>r.show({state:`error`,title:OH(e,DH(`couldNotSwitch`))})),[n,r,e]);return{...i&&{current:i},switchTo:o}},AH=e=>{let t=rV(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},jH=e=>{let t=c_().shell?.logo;return t?(0,B.jsx)(cv,{name:`shell.logo`,fallback:(0,B.jsx)(Ox,{...e}),children:(0,B.jsx)(t,{...e})}):(0,B.jsx)(Ox,{...e})},MH=[440,480],NH=400,PH=3e3,FH=e=>{(0,I.useEffect)(()=>{if(!e||typeof AudioContext>`u`)return;let t=new AudioContext,n=()=>{let e=t.createGain();e.gain.value=.08,e.connect(t.destination);for(let[n,r]of[0,NH*1.5/1e3].entries())for(let i of MH){let a=t.createOscillator();a.frequency.value=i,a.connect(e),a.start(t.currentTime+r),a.stop(t.currentTime+r+NH/1e3/(n+1))}};n();let r=setInterval(n,PH);return()=>{clearInterval(r),t.close()}},[e])},IH=(e,t)=>e.map(e=>({...e,until:t+e.remaining_ms})),LH=(e,t)=>{let n=e.filter(e=>e.until>t);return{ringing:n,next:n.length===0?void 0:Math.min(...n.map(e=>e.until))}},RH=e=>{let t=U(),n=Se(),r=E({queryKey:H.rings,queryFn:async()=>IH(await t.rings.list(),Date.now()),enabled:e});(0,I.useEffect)(()=>{if(!e)return;let r=()=>void n.invalidateQueries({queryKey:H.rings});return t.live({onChanges:e=>e.some(e=>e.resource===`$rings`)&&r(),onResync:r})},[t,n,e]);let[i,a]=(0,I.useState)(()=>Date.now()),{ringing:s,next:c}=LH(r.data??[],Math.max(i,r.dataUpdatedAt));(0,I.useEffect)(()=>{if(c===void 0)return;let e=setTimeout(()=>a(Date.now()),Math.max(0,c-Date.now()));return()=>clearTimeout(e)},[c]);let l=(0,I.useCallback)(e=>n.setQueryData(H.rings,t=>t?.filter(t=>t.call!==e)),[n]);return{ringing:s,decline:o({mutationFn:e=>t.rings.decline(e),onMutate:l,onSettled:()=>n.invalidateQueries({queryKey:H.rings})}).mutate,hide:l}},zH=(e,t,n)=>({state:`call`,sticky:!0,title:e.title,...e.body!==null&&{description:e.body},actions:[{label:Z(`decline`),onClick:()=>n(e.call)},{label:Z(`accept`),...t}]}),BH=()=>{let{ringing:e,decline:t,hide:n}=RH(!0),r=iy(),{href:i,open:a}=Hh(),o=(0,I.useRef)(new Map);return FH(e.length>0),(0,I.useEffect)(()=>{let s=new Set(e.map(e=>e.call));for(let[e,t]of o.current)s.has(e)||(r.dismiss(t),o.current.delete(e));for(let s of e){if(o.current.has(s.call))continue;let e={href:i({kind:`record`,resource:s.resource,key:s.key,call:`join`}),onNavigate:e=>{n(s.call),a(e)}};o.current.set(s.call,r.show({...zH(s,e,t),onClose:()=>t(s.call)}))}},[e,r,i,a,t,n]),(0,I.useEffect)(()=>{let e=o.current;return()=>{for(let t of e.values())r.dismiss(t);e.clear()}},[r]),null},VH=(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)}},HH=()=>{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:VH(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])}},UH=M(`notifications/bell`),WH=`flex w-full gap-2.5 px-3 py-2.5 text-left`,GH=({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?Mf.blue:`bg-transparent`),children:a&&(0,B.jsx)(`span`,{className:`sr-only`,children:UH(`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:Sp((i-Date.parse(e.createdAt))/1e3)})]})]}),s=()=>r(e),c=e=>{e.button===1&&s()};return t?t.kind===`app`?(0,B.jsx)(Sh,{to:{href:t.href,onFollow:()=>n(t.path)},onClick:s,onAuxClick:c,className:P(WH,`hover:bg-muted`),children:o}):(0,B.jsx)(`a`,{href:t.href,onClick:s,onAuxClick:c,className:P(WH,`hover:bg-muted`),children:o}):(0,B.jsx)(`div`,{className:WH,children:o})},KH=({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:UH(`notifications`)}),m&&h&&(0,B.jsx)(G,{size:`sm`,variant:`ghost`,loading:c,onClick:()=>s(m),children:UH(`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)($d,{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:UH(`loadFailed`)}),(0,B.jsx)(G,{size:`sm`,onClick:r,children:UH(`tryAgain`)})]}):e.length===0?(0,B.jsx)(`p`,{className:`px-3 py-8 text-center text-body text-muted-foreground`,children:UH(`empty`)}):(0,B.jsx)(`ul`,{className:`divide-y`,children:e.map(e=>(0,B.jsx)(`li`,{children:(0,B.jsx)(GH,{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:UH(`showMore`)})})]}),f]})},qH=(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}},JH=({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)(Qr,{className:`mt-0.5 size-3.5 shrink-0`,"aria-hidden":!0}),UH(`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)(ei,{className:`size-3.5 shrink-0`,"aria-hidden":!0}),(0,B.jsx)(`span`,{className:`min-w-0 flex-1`,children:UH(r?`pushOn`:`pushOff`)}),(0,B.jsx)(G,{size:`sm`,variant:r?`secondary`:`primary`,onClick:r?n:t,children:UH(r?`turnOff`:`turnOn`)})]})},YH=3e4,XH=e=>pl(e)&&e.status===403,ZH=({enabled:e=!0}={})=>{let t=U();return E({queryKey:H.inboxUnread,queryFn:()=>t.notifications.unread(),refetchInterval:e=>!XH(e.state.error)&&YH,enabled:e})},QH=({enabled:e=!0}={})=>{let t=U(),n=Ne({queryKey:H.inboxPages,queryFn:({pageParam:e})=>t.notifications.list(e===``?{}:{cursor:e}),initialPageParam:``,getNextPageParam:e=>e.next??void 0,enabled:e}),r=n.data?.pages.flatMap(e=>e.items)??[];return{...n,items:r}},$H=(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))},eU=()=>{let e=U(),t=Se(),n=()=>t.invalidateQueries({queryKey:H.inbox}),r=o({mutationFn:t=>e.notifications.markRead(t.id),onMutate:e=>$H(t,t=>t.id===e.id),onSettled:n}),i=o({mutationFn:t=>e.notifications.markAllRead(t.createdAt),onMutate:e=>$H(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}},tU=99,nU=e=>e===void 0||e<=0?UH(`notifications`):e>tU?UH(`notificationsManyUnread`):UH(`notificationsUnread`,{count:String(e)}),rU=()=>{let{open:e,setOpen:t,place:n,button:r,menu:i}=rg(),a=ZH(),o=QH({enabled:e}),{markRead:s,markAllRead:c,markingAll:l}=eU(),u=HH(),{navigate:d,basePath:f}=jh(),[p,m]=(0,I.useState)(Date.now),h=nU(a.data),g=window.location.origin;return XH(a.error)?null:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(G,{ref:r,size:`icon`,variant:`ghost`,"aria-label":h,title:h,"aria-haspopup":`dialog`,"aria-expanded":e,onClick:()=>{e||(m(Date.now()),a.refetch(),o.data&&o.refetch()),t(!e)},className:`relative max-md:size-9`,children:[(0,B.jsx)(ni,{className:`size-4 max-md:size-5`}),(0,B.jsx)(Yx,{count:a.data,className:`pointer-events-none absolute -top-1 -right-1.5 max-md:top-0 max-md:right-0`})]}),e&&(0,Sc.createPortal)((0,B.jsx)(`div`,{ref:i,role:`dialog`,"aria-label":nU(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)(KH,{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=>qH(e.url,{origin:g,basePath:f}),onNavigate:e=>d(e),onOpen:e=>{s(e),t(!1)},footer:(0,B.jsx)(JH,{state:u.state,onTurnOn:()=>void u.turnOn(),onTurnOff:()=>void u.turnOff()}),now:p})}),document.body)]})},iU=({own:e})=>e?(0,B.jsx)(cv,{name:`shell.bell`,fallback:null,children:(0,B.jsx)(e,{})}):(0,B.jsx)(rU,{}),aU=(0,I.createContext)([]),oU=()=>(0,I.useContext)(aU),sU=({ui:e,children:t})=>{let{plugins:n=[]}=W(),{loads:r,settled:i}=zP(n,IP()),a=(0,I.useMemo)(()=>gP(e,r),[e,r]);return i?(0,B.jsx)(s_.Provider,{value:a.ui,children:(0,B.jsx)(aU.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)($d,{}),` `,_P(`loading`)]})},cU=({off:e})=>{let[t,n]=(0,I.useState)(!1);return t||e.length===0?null:(0,B.jsxs)(`div`,{role:`region`,"aria-label":_P(`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)(Zo,{"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:_P.rich(`pluginOff`,{plugin:(0,B.jsx)(`span`,{className:`font-semibold`,children:e.name??e.url}),reason:e.reason})},e.url))}),(0,B.jsx)(`button`,{type:`button`,"aria-label":_P(`dismiss`),className:`rounded p-0.5 hover:bg-warning/10`,onClick:()=>n(!0),children:(0,B.jsx)(yc,{"aria-hidden":!0,className:`size-4`})})]})},lU=(e,t)=>[`${t}_at`,`${t}At`].find(t=>e.fields[t]),uU=({item:e,scope:t})=>{let{components:n}=c_(),r=n?.[e.component],i=r?(0,B.jsx)(Jv,{value:t,children:(0,B.jsx)(cv,{name:e.component,children:(0,B.jsx)(r,{...vn(e.props??{})})})}):(0,B.jsx)(ov,{children:q.rich(`noComponent`,{component:e.component})});return e.sidebar?e.title?(0,B.jsx)(og,{title:e.title,children:i}):i:e.title?(0,B.jsx)(Vf,{title:e.title,children:i}):(0,B.jsx)(`section`,{className:`py-8`,children:i})},dU=({component:e,scope:t,standard:n})=>{let{components:r}=c_(),i=r?.[e];return i?(0,B.jsx)(cv,{name:e,fallback:n,children:(0,B.jsx)(fU,{children:(0,B.jsx)(Jv,{value:t,children:(0,B.jsx)(i,{})})})}):n},fU=({children:e})=>(vx(!1),(0,B.jsx)(`div`,{className:`grid min-h-0 flex-1 grid-cols-[minmax(0,1fr)] grid-rows-[minmax(0,1fr)]`,children:e})),pU=(0,I.lazy)(()=>Ve(()=>import(`./record-map-CupIwJyD.js`).then(e=>({default:e.RecordMap})),__vite__mapDeps([9,1,2,5,6,7,3,8]))),mU=15,hU=({item:e,record:t})=>{let n=W().maps,r=n?.style,i=zk(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)(pU,{style:r,layers:n?.layers,position:i,zoom:e.zoom??mU},`${i.latitude},${i.longitude}`)})});return e.sidebar?(0,B.jsx)(og,{title:e.title,children:a}):(0,B.jsx)(Vf,{title:e.title,children:a})},gU={"1h":`minute`,"24h":`5_minutes`,"7d":`hour`},_U=(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}))},vU=M(`app/record-chart`),yU=sn(),bU=[`1h`,`24h`,`7d`],xU={"1h":`hour`,"24h":`day`,"7d":`week`},SU=({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=gU[i],d=Yt(yU.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:Gf()})),p=zy(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)?_U(p.map(e=>e.data.groups),h.map(e=>e.key),o):[],_=(0,B.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,B.jsx)(Re,{label:vU(`measure`),value:o,onChange:s,options:[{value:`average`,label:vU(`average`)},{value:`maximum`,label:vU(`maximum`)}]}),(0,B.jsx)(Re,{label:vU(`range`),value:i,onChange:a,options:bU.map(e=>({value:e,label:vU(xU[e])}))})]});return(0,B.jsx)(Vf,{title:e.title,help:e.help,actions:_,children:p.some(e=>e.error)?(0,B.jsx)(`p`,{className:`text-danger-text`,children:vU(`couldNotLoad`)}):p.some(e=>e.isPending)?(0,B.jsx)(vh,{className:`h-40 w-full`}):g.every(e=>e.count===0)?(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:vU(`noSamples`)}):(0,B.jsx)(pb,{points:g,measure:m[0],bucket:u,type:`line`,series:h,...h.length>1&&{resource:e.resource,view:l}})})},CU=e=>$T(e)??xc,wU=({model:e,stored:t,recordKey:n,edit:r,onDelete:i})=>{let a=Hh(),{go:o}=a,s=pS(),c={model:e,record:t.record,key:n,etag:t.etag,permissions:t.permissions},l=Ty(e.name,c,t=>t.run?.kind===`delete`&&o({kind:`list`,resource:e.name},{replace:!0})),[u,d]=(0,I.useState)(),f=l.actions.map(e=>{let n=l.blocked(e),r=e.run?.kind===`link`&&!n?BV(e.run,t.record,a):void 0;return{name:e.label,icon:CU(e.icon),blocked:n,running:l.running===e.name,...Wv(e)&&{tone:`danger`},onRun:()=>Gv(e)?d(e):void l.run(e),...r&&{render:({className:e,children:t,role:n})=>(0,B.jsx)(Sh,{to:r,role:n,className:e,children:t})}}}),p=l.actions.some(e=>e.run?.kind===`delete`),m=[...r?[{name:Q(`edit`),icon:Lo,render:({className:e,children:t,role:n})=>(0,B.jsx)(Uh,{to:r,role:n,className:e,children:t})}]:[],...f,...i&&!p?[{name:Q(`delete`),icon:qs,tone:`danger`,onRun:i}]:[]];return m.length===0?null:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`div`,{className:s?`max-md:hidden`:void 0,children:(0,B.jsx)($h,{actions:m})}),s&&(0,Sc.createPortal)((0,B.jsx)(ig,{actions:m,label:Q(`recordActions`),className:`inline-flex size-11 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-muted md:hidden`}),s),u&&(0,B.jsx)(Kv,{action:u,label:u.label,danger:Wv(u),onCancel:()=>d(void 0),onConfirm:()=>{d(void 0),l.run(u)},onSubmit:async e=>{await l.submit(u,e),d(void 0)}})]})},TU=(e=[],t)=>e.includes(t)?e.filter(e=>e!==t):[...e,t],EU=(e,t=[],n)=>!e.collapsed||t.includes(e.title)||e.items.some(e=>e.kind===`section`&&e.fields.some(n)),DU=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)}},OU=(e,t)=>e.find(e=>e.title===t)??e[0],kU=e=>Sn(e.items).flatMap(e=>e.kind===`section`?e.fields:[]),AU=(e,t,n)=>{if(t&&!kU(t).some(n))return e.find(e=>kU(e).some(n))},jU=e=>e.width??`minmax(8rem,1fr)`,MU=e=>({"--line-columns":e.map(jU).join(` `)}),NU=e=>`${e.reduce((e,t)=>e+(t.width?.endsWith(`px`)?parseInt(t.width)/16:8),6)}rem`,PU=`grid grid-cols-[28px_var(--line-columns)_32px] items-center gap-2 pointer-coarse:grid-cols-[44px_var(--line-columns)_44px]`,FU=({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)(ca,{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))})]})},IU=M(`inline-child-table`),LU=({line:e,name:t,columns:n,position:r,count:i,reorderable:a,onRemove:o,onMove:s,error:c})=>{let{attributes:l,listeners:u,setNodeRef:d,setActivatorNodeRef:f,transform:p,transition:m,isDragging:h}=Te({id:e.id,disabled:!a}),g=[...a?[{label:IU(`moveUp`),disabled:r===0,onSelect:()=>s(r-1)},{label:IU(`moveDown`),disabled:r===i-1,onSelect:()=>s(r+1)}]:[],...o?[{label:IU(`removeLine`),destructive:!0,onSelect:o}]:[]];return(0,B.jsxs)(`div`,{ref:d,"data-line-id":e.id,"aria-invalid":c?!0:void 0,style:{transform:p?`translate3d(0, ${p.y}px, 0)`:void 0,transition:m},className:P(`group relative border-b border-border bg-background px-2 py-1 last:border-b-0 hover:bg-surface`,PU,h&&`z-10 bg-surface opacity-80 shadow-pop`,c&&`bg-danger-soft`),children:[a?(0,B.jsx)(`button`,{ref:f,type:`button`,"aria-label":IU(`dragToReorder`,{name:t}),...l,...u,style:{touchAction:`none`},className:`flex size-7 cursor-grab items-center justify-center rounded text-faint-foreground opacity-60 hover:bg-muted hover:opacity-100 focus-visible:opacity-100 active:cursor-grabbing pointer-coarse:size-11`,children:(0,B.jsx)(wa,{className:`size-4`})}):(0,B.jsx)(`span`,{}),n.map(t=>(0,B.jsx)(`div`,{className:P(`min-w-0`,t.align===`right`&&`text-right`),children:t.cell(e)},t.key)),g.length>0?(0,B.jsx)(FU,{label:IU(`actionsFor`,{name:t}),items:g}):(0,B.jsx)(`span`,{}),c&&(0,B.jsx)(`p`,{role:`alert`,className:`col-span-full px-2 pb-1 text-xs text-danger-text`,children:c})]})},RU=(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},zU=`px-2 text-[11px] font-medium uppercase tracking-wide text-muted-foreground`,BU=(e,t)=>{let n=n=>{let r=e.find(e=>e.id===n);return r?t(r):IU(`line`)},r=t=>e.findIndex(e=>e.id===t)+1;return{onDragStart:({active:t})=>IU(`pickedUp`,{name:n(t.id),place:r(t.id),count:e.length}),onDragOver:({active:t,over:i})=>i?IU(`over`,{name:n(t.id),place:r(i.id),count:e.length}):void 0,onDragEnd:({active:t,over:i})=>i?IU(`dropped`,{name:n(t.id),place:r(i.id),count:e.length}):IU(`droppedAtStart`,{name:n(t.id)}),onDragCancel:({active:e})=>IU(`cancelled`,{name:n(e.id),place:r(e.id)})}},VU=({lines:e,columns:t,lineName:n,onReorder:r,reorderable:i=!!r,onAdd:a,onRemove:o,removable:s=()=>!0,lineError:c,footer:l})=>{let u=ne(Me(se,{activationConstraint:{distance:4}}),Me(xe,{activationConstraint:{delay:250,tolerance:5}}),Me(ae,{coordinateGetter:ye})),d=(t,n)=>{let i=e[t];!i||!r||n<0||n>=e.length||t===n||r(RU(e,t,n),{id:i.id,from:t,to:n})};return(0,B.jsxs)(`div`,{children:[(0,B.jsxs)(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,style:MU(t),children:[(0,B.jsxs)(`div`,{className:`${PU} border-b border-border bg-surface px-2 py-2`,children:[(0,B.jsx)(`span`,{}),t.map(e=>(0,B.jsx)(`span`,{className:P(zU,e.align===`right`&&`text-right`),children:e.label},e.key)),(0,B.jsx)(`span`,{})]}),e.length===0&&(0,B.jsx)(`p`,{className:`px-4 py-3 text-muted-foreground`,children:IU(`noLines`)}),(0,B.jsx)(me,{sensors:u,collisionDetection:ge,onDragEnd:({active:t,over:n})=>{n&&t.id!==n.id&&d(e.findIndex(e=>e.id===t.id),e.findIndex(e=>e.id===n.id))},accessibility:{announcements:BU(e,n),screenReaderInstructions:{draggable:IU(`instructions`)}},children:(0,B.jsx)(ue,{items:e.map(e=>e.id),strategy:re,children:e.map((r,a)=>(0,B.jsx)(LU,{line:r,name:n(r),columns:t,position:a,count:e.length,reorderable:i,onRemove:o&&s(r)?()=>o(r):void 0,onMove:e=>d(a,e),error:c?.(r)},r.id))})}),a&&(0,B.jsx)(`div`,{className:`border-t border-border bg-surface px-2 py-1.5`,children:(0,B.jsxs)(G,{variant:`ghost`,size:`sm`,onClick:a,children:[(0,B.jsx)(qo,{className:`size-3.5`}),IU(`addLine`)]})})]}),l]})},HU=({field:e,hints:t,label:n,lineNumber:r,resource:i,value:a,stored:o,relationLabel:s,relationTo:c,relationPicker:l,locked:u,problem:d,onChange:f})=>{let p=(0,I.useId)(),m=d&&ix(e,n,d);return(0,B.jsxs)(qh.Provider,{value:{id:p,invalid:!!d,required:!1,...m&&{describedBy:`${p}-error`}},children:[(0,B.jsx)(`label`,{htmlFor:p,className:`sr-only`,children:Q(`lineField`,{label:n,place:r})}),(0,B.jsx)(Ov,{field:e,hints:t,value:a,stored:o,relationLabel:s,relationTo:c,relationPicker:l,locked:u,invalid:!!d,resource:i,onChange:f}),m&&(0,B.jsx)(`p`,{id:`${p}-error`,className:`px-1 pt-0.5 text-xs text-danger-text`,children:m})]})},UU=(e,t,n,r,i)=>{let a=Wg(e?.name??``,{enabled:!!(e&&t),filter:t?`${t.name} = "${r}"`:void 0,pageSize:500,labels:i,...n&&e?.fields[n]?.sortable&&{orderBy:`${n} asc`}}),o=(0,I.useMemo)(()=>n?[...a.items].sort((e,t)=>Number(e[n])-Number(t[n])):a.items,[a.data,n]),s=a.hasNextPage&&a.items.length<1e3;return(0,I.useEffect)(()=>{s&&!a.isFetchingNextPage&&a.fetchNextPage()},[s,a.isFetchingNextPage]),{items:o,labels:a.labels,loading:(a.isPending||s)&&!!e,complete:!a.hasNextPage}},WU=({lines:e,editable:t,saving:n})=>{let{resources:r,views:i}=W(),{item:a,model:o,columns:s,data:c,draft:l}=e,u=af(o.name),d=i[o.name],[f,p]=(0,I.useState)({}),m=t&&c.complete&&!c.loading&&!n,h=m&&oy(u,`update`),g=m&&oy(u,`create`),_=m&&oy(u,`delete`),v=e=>e.stored?h&&sy(e.stored,`update`):g,y=e=>l.shown.indexOf(e)+1,b=e=>l.rejection?.id===e.id?l.rejection:void 0,x=s.map(e=>{let t=o.fields[e],n=d?.fields[e],a=n?.label??F(e),s=t.relation?r[t.relation.resource]:void 0,u=s&&s.primaryKey.length===1?s:void 0;return{key:e,label:a,...[`integer`,`bigint`,`decimal`].includes(t.type)&&{align:`right`,width:`minmax(6rem,0.6fr)`},cell:r=>{let s=l.value(r.id,e),d=s==null||s===``?void 0:String(s);return(0,B.jsx)(HU,{field:t,hints:n,label:a,lineNumber:y(r),resource:o.name,value:s,stored:r.stored?.[e],relationLabel:d===void 0?void 0:f[`${r.id}/${e}`]??c.labels[e]?.[d],relationTo:u&&d!==void 0?{kind:`record`,resource:u.name,key:d}:void 0,relationPicker:u&&{target:u,view:i[u.name]},locked:!v(r),problem:b(r)?.fields[e],onChange:t=>{if(!u||!Og(t))return l.change(r.id,e,t);p(n=>({...n,[`${r.id}/${e}`]:t.label})),l.change(r.id,e,jg(u,t.key))}})}}});return(0,B.jsxs)(Vf,{title:a.title,help:a.help,children:[!c.complete&&(0,B.jsx)(`p`,{className:`mb-2 text-muted-foreground`,children:Q(`tooManyLines`,{limit:wp(1e3)})}),(0,B.jsx)(`div`,{className:`-mx-4 overflow-x-auto px-4 [-webkit-overflow-scrolling:touch] md:mx-0 md:px-0`,children:(0,B.jsx)(`div`,{style:{minWidth:NU(x)},children:(0,B.jsx)(VU,{lines:l.shown,columns:x,lineName:e=>lr(o,d,e.stored??{},``)||Q(`lineNumber`,{place:y(e)}),onReorder:e=>l.setOrder(e.map(e=>e.id)),reorderable:h,onAdd:g?()=>void l.add():void 0,onRemove:g||_?e=>l.remove(e.id):void 0,removable:e=>e.stored?_&&sy(e.stored,`delete`):g,lineError:e=>{let t=b(e);if(t&&!s.some(e=>t.fields[e]))return t.message}})})})]})},GU=(e,t,n)=>`protobase:draft:${e}:${t}:${n}`,KU=(e,t,n)=>Ie(()=>{let r=e.getItem(t);if(r===null)return;let i=JSON.parse(r);if(i&&i.etag===n&&typeof i.fields==`object`&&i.fields!==null)return{etag:n,fields:i.fields,...Array.isArray(i.order)&&{order:i.order.map(String)}}},void 0),qU=(e,t,n)=>Ie(()=>n?e.setItem(t,JSON.stringify(n)):e.removeItem(t),void 0),JU={added:[],edits:{},removed:[]},YU=(e,t)=>{let n=[...e.filter(e=>!t.removed.includes(e)),...t.added];return t.order?[...t.order.filter(e=>n.includes(e)),...n.filter(e=>!t.order.includes(e))]:n},XU=(e,t,n)=>Object.fromEntries(Object.entries(t).flatMap(([t,r])=>{let i=e.fields[t];return i&&Sg(i,r,n[t])?[[t,yg(i,r)]]:[]})),ZU=(e,t)=>Object.fromEntries(Object.entries(t).flatMap(([t,n])=>{let r=e.fields[t];return!r||r.type!==`boolean`&&String(n??``).trim()===``?[]:[[t,yg(r,n)]]})),QU=({model:e,position:t,link:n,stored:r,state:i})=>{let a={ops:[],rows:[]},o=(e,t)=>{a.ops.push(e),a.rows.push(t)},s=new Map(r.map(t=>[vm(e,t),t])),c=[...s.keys()],l=YU(c,i),u=t=>ym(e,s.get(t)),d=e=>{let t=s.get(e).etag;return typeof t==`string`?t:void 0};for(let t of i.removed){if(!s.has(t))continue;let n=d(t);o({op:`delete`,resource:e.name,key:u(t),...n&&{etag:n}},t)}let f=new Set;for(let[t,n]of Object.entries(i.edits)){if(!s.has(t)||i.removed.includes(t))continue;let r=XU(e,n,s.get(t));if(Object.keys(r).length===0)continue;let a=d(t);o({op:`update`,resource:e.name,key:u(t),data:r,...a&&{etag:a}},t),f.add(t)}let p=l.filter(e=>s.has(e)),m=l.filter(e=>!s.has(e)),h=(e,t)=>Object.fromEntries(e.flatMap(e=>{let n=t||f.has(e)?`*`:d(e);return n?[[Nn(u(e)),n]]:[]})),g=(n,r,i)=>({op:`reorder`,resource:e.name,field:t,keys:n,...r!==1&&{start:r},etags:i}),_=(r,a,o)=>({op:`create`,resource:e.name,data:{...ZU(e,i.edits[r]??{}),[n.field]:n.value,[t]:a},...o&&{ref:o}}),v=e=>Number(e[t])||0,y=p.some((e,t)=>e!==c.filter(e=>p.includes(e))[t]);if(m.every(e=>l.indexOf(e)>=p.length)){y&&o(g(p.map(u),1,h(p,!1)));let e=y?p.length:Math.max(0,...p.map(e=>v(s.get(e))));return m.forEach((t,n)=>o(_(t,e+1+n),t)),a}let b=Math.max(l.length,...r.map(v))+1;p.length>0&&o(g(p.map(u),b,h(p,!1)));let x=e=>`line${m.indexOf(e)+1}`;for(let e of m)o(_(e,l.indexOf(e)+1,x(e)),e);return o(g(l.map(e=>s.has(e)?u(e):{$ref:x(e)}),1,h(p,!0))),a},$U=(e,t)=>Object.fromEntries(Object.entries(e).filter(([e])=>e!==t)),eW=(e,t)=>{let[n,r]=(0,I.useState)(JU),[i,a]=(0,I.useState)(),o=(0,I.useRef)(1),s=(0,I.useMemo)(()=>new Map(e?t.map(t=>[vm(e.model,t),t]):[]),[e,t]),c=YU([...s.keys()],n).map(e=>({id:e,stored:s.get(e)})),l=()=>e?QU({...e,stored:t,state:n}):{ops:[],rows:[]},u=l().ops.length>0,d=(0,I.useMemo)(()=>{let e=YU([...s.keys()],n).filter(e=>s.has(e)),t=[...s.keys()].filter(t=>e.includes(t));return n.order!==void 0&&e.some((e,n)=>e!==t[n])?e:void 0},[s,n]),f=(t,r)=>{let i=n.edits[t];if(i&&r in i)return i[r];let a=e?.model.fields[r],o=s.get(t)?.[r];return a?[`boolean`,`file`].includes(a.type)?o:xg(a,o):o},p=e=>a(t=>t?.id===e?void 0:t);return{shown:c,dirty:u,order:d,value:f,change:(e,t,n)=>{p(e),r(r=>({...r,edits:{...r.edits,[e]:{...r.edits[e],[t]:n}}}))},add:()=>{let e=`new:${o.current++}`;return r(t=>({...t,added:[...t.added,e]})),e},remove:e=>{p(e),r(t=>t.added.includes(e)?{...t,added:t.added.filter(t=>t!==e),edits:$U(t.edits,e)}:{...t,removed:[...t.removed,e]})},setOrder:e=>r(t=>({...t,order:e})),reset:()=>{r(JU),a(void 0)},reject:(e,t)=>a({id:e,fields:ax(t),message:t.message}),rejection:i,plan:l}},tW=(e,t)=>{let n=Sn(t?.layout??[]).find(e=>e.kind===`related`&&e.lines===!0);if(n?.kind!==`related`)return;let r=e[n.resource],i=r?.fields[n.field],a=r?.position?.field;if(r&&i&&a&&r.position?.within===n.field)return{item:n,model:r,link:i,position:a}},nW=(e,t,n,r)=>Tr(e,t).filter(t=>{let i=e.fields[t];return i&&!i.writeOnly&&t!==n&&t!==r&&t!==e.tenant&&!e.primaryKey.includes(t)}),rW=(e,t)=>{let{resources:n,views:r}=W(),i=(0,I.useMemo)(()=>tW(n,r[e.name]),[n,r,e]),a=i?.model,o=i?nW(i.model,r[i.model.name],i.link.name,i.position):[],s=UU(a,i?.link,i?.position,t,a?Cb(n,r,a,o):void 0),c=eW((0,I.useMemo)(()=>i?{model:i.model,position:i.position,link:{field:i.link.name,value:jg(e,t)}}:void 0,[i,e,t]),s.items);return{item:i?.item,model:a,columns:o,data:s,draft:c}},iW=e=>{let t=e>=5?5:e===4?3:e;return{shown:t,more:e-t}},aW=(e,t)=>Math.abs(e)<40||Math.abs(e)<=Math.abs(t)?0:e<0?1:-1,oW=e=>e===`ArrowRight`?1:e===`ArrowLeft`?-1:0,sW=(e,t,n)=>Math.min(Math.max(e+t,0),Math.max(n-1,0)),cW=e=>e.key===`i`&&!e.ctrlKey&&!e.metaKey&&!e.altKey,lW=`protobase:lightbox-details`,uW=e=>Ie(()=>e.getItem(lW)===`true`,!1),dW=(e,t)=>Ie(()=>t?e.setItem(lW,`true`):e.removeItem(lW),void 0),fW=M(`app/gallery`),pW=`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`,mW=({title:e,photos:t,index:n,onIndex:r,onClose:i,details:a,detailsTitle:o=fW(`details`)})=>{let s=(0,I.useRef)(null),c=(0,I.useRef)(void 0),l=(0,I.useId)(),u=gf(),[d,f]=(0,I.useState)(()=>uW(localStorage)),[p,m]=(0,I.useState)(!1);Sf(s,!0,i),(0,I.useEffect)(()=>m(!0),[]);let h=t.length,g=e=>{let t=sW(n,e,h);t!==n&&r(t)},_=Vp(t[n],{width:1600,height:1200}),v=a?.(n),y=v!==void 0,b=e=>{f(e),dW(localStorage,e)};return(0,B.jsxs)(`div`,{ref:s,tabIndex:-1,role:`dialog`,"aria-modal":`true`,"aria-label":e,onKeyDown:e=>{if(y&&cW(e))return e.preventDefault(),b(!d);let t=oW(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(pW,`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)(Pa,{className:`size-4`,"aria-hidden":!0})}),(0,B.jsx)(`button`,{type:`button`,className:pW,"aria-label":fW(`close`),onClick:i,children:(0,B.jsx)(yc,{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(aW(e.clientX-c.current.x,e.clientY-c.current.y)),void 0)},onPointerCancel:()=>c.current=void 0,children:[_&&(0,B.jsx)(j_,{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(pW,`absolute left-3 top-1/2 -translate-y-1/2 aria-disabled:cursor-default aria-disabled:opacity-40`),"aria-label":fW(`previousPhoto`),"aria-disabled":n===0,onClick:()=>g(-1),children:(0,B.jsx)(Ei,{className:`size-5`,"aria-hidden":!0})}),(0,B.jsx)(`button`,{type:`button`,className:P(pW,`absolute right-3 top-1/2 -translate-y-1/2 aria-disabled:cursor-default aria-disabled:opacity-40`),"aria-label":fW(`nextPhoto`),"aria-disabled":n===h-1,onClick:()=>g(1),children:(0,B.jsx)(Oi,{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)(Tf,{title:o,open:y&&d&&!u&&p,onClose:()=>b(!1),children:(0,B.jsx)(`div`,{className:`pt-3`,children:v})})]})},hW=(e,t,n)=>{let r=Sn(t?.layout??[]).flatMap(e=>e.kind===`section`&&Eg(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)&&Eg(t?.fields[r]?.when,!1))},gW=({model:e,view:t,photoKey:n,fields:r})=>{let i=ZP(e.name,n),a=(t?.names?.singular??F(e.name)).toLowerCase();if(i.isPending)return(0,B.jsx)(vh,{className:`h-4 w-48`});if(i.error)return(0,B.jsx)(Bg,{title:fW(`couldNotLoadOne`,{singular:a}),error:i.error});let o=r.filter(e=>cy(i.data.permissions,e)!==`hidden`);return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(Xh,{rows:o.map(n=>({label:t?.fields[n]?.label??F(n),value:(0,B.jsx)(Lb,{model:e,field:e.fields[n],value:i.data.record[n]})}))}),(0,B.jsx)(Uh,{to:{kind:`record`,resource:e.name,key:n},className:`mt-3 inline-block font-medium text-primary-text hover:underline`,children:fW(`open`,{singular:a})})]})},_W=e=>Vp(e,{width:0,height:0})!==void 0,vW=(e,t)=>{let n=e.primaryKey.map(e=>t[e]);if(!n.some(e=>e==null))return Nn(n)},yW=(e,t,n,r)=>{let i=n===void 0?[]:t.flatMap(e=>{let t=e[n];if(!jp(t)||!_W(t))return[];let i=r&&vW(r,e);return[{file:t,...i!==void 0&&{key:i}}]});if(!jp(e)||!_W(e))return i;let a=t=>jp(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))]},bW=sn(),xW=(e,t,n)=>{let r=U(),{resources:i}=W(),a=e.photos?i[e.photos.resource]:void 0,o=e.photos?Yt(bW.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:yW(e.image===void 0?void 0:t[e.image],c.data??[],e.photos?.image,a),isPending:a!==void 0&&c.isPending,error:c.error}},SW={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`,``,``,``,``]},CW=({photo:e,large:t})=>{let n=Vp(e,t?{width:960,height:720}:{width:480,height:360});return n?(0,B.jsx)(j_,{image:n,loading:`lazy`,className:`size-full object-cover transition-transform duration-300 group-hover/tile:scale-[1.02]`}):null},wW=({item:e,record:t,recordKey:n})=>{let{views:r}=W(),i=xW(e,t,n),a=af(i.holder?.name??``),[o,s]=(0,I.useState)();if(i.isPending)return(0,B.jsx)(Vf,{title:e.title,children:(0,B.jsx)(vh,{className:`aspect-[4/3] w-full rounded-lg md:aspect-[2/1]`})});if(i.error)return(0,B.jsx)(Vf,{title:e.title,children:(0,B.jsx)(Bg,{title:fW(`couldNotLoad`),error:i.error})});let c=i.items.length;if(c===0)return null;let{shown:l,more:u}=iW(c),d=i.holder,f=d&&r[d.name],p=d?hW(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)(Vf,{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?fW(`showAll`,{count:c}):fW(`showPhoto`,{index:t+1,count:c}),onClick:()=>s(t),className:P(`group/tile relative overflow-hidden bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary`,t===0?`col-span-4 row-span-2`:`max-md:hidden`,SW[l][t]),children:[(0,B.jsx)(CW,{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)(mW,{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)(gW,{model:d,view:f,photoKey:t,fields:p},t):void 0},detailsTitle:d&&fW(`holderDetails`,{singular:f?.names?.singular??F(d.name)})})]})},TW=M(`app/history`),EW=e=>e.actor?e.actor.name??e.actor.id:e.databaseRole?TW(`databaseRole`,{role:e.databaseRole}):TW(`database`),DW=(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:Nm(i,e.before[r],a),after:Nm(i,e.after[r],a)}]}),i=e.operation===`update`&&r.length===0?TW(`changedThis`):TW(e.operation);return{who:EW(e),verb:i,fields:r}},OW=1500,kW=(e,t,n,r)=>{let i=U(),a=Ne({queryKey:H.history(e,t,n),initialPageParam:``,queryFn:({pageParam:r})=>i.history(e,t,{pageSize:n,pageToken:r}),getNextPageParam:e=>e.nextPageToken||void 0}),{refetch:o}=a;return(0,I.useEffect)(()=>{let e=setTimeout(()=>void o(),OW);return()=>clearTimeout(e)},[r,o]),{...a,items:a.data?.pages.flatMap(e=>e.items)??[]}},AW=()=>(0,B.jsx)(`div`,{className:`flex flex-col gap-2`,children:Array.from({length:3},(e,t)=>(0,B.jsx)(vh,{className:`h-4 w-full`},t))}),jW=({change:e,model:t,view:n})=>{let{who:r,verb:i,fields:a}=DW(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:dp(o),className:`text-muted-foreground`,children:[`· `,Sp(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))})]})},MW=({item:e,model:t,view:n,recordKey:r,etag:i})=>{let a=kW(t.name,r,e.limit??10,i);return(0,B.jsx)(Vf,{title:e.title,children:a.isPending?(0,B.jsx)(AW,{}):a.error?(0,B.jsx)(Bg,{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)(jW,{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`})]})})},NW=({comment:e})=>(0,B.jsx)(PI,{text:e.body,mentions:e.mentions}),PW=(e,t)=>{let n=U(),r=Se();return o({mutationFn:r=>n.comment(e,t,r),onSuccess:()=>r.invalidateQueries({queryKey:H.comments(e,t)})})},FW=M(`app/comments`),IW=({resource:e,recordKey:t})=>{let[n,r]=(0,I.useState)(jI),i=U(),a=iy(),o=PW(e,t),s=(0,I.useCallback)(n=>i.mentionable(e,t,n),[i,e,t]);Vh(n.text.trim()!==``||o.isPending,`input-lost`);let c=()=>{n.text.trim()===``||o.isPending||o.mutate({body:n.text,mentions:EI(n.text,n.picked)},{onSuccess:()=>r(jI),onError:e=>a.show({state:`error`,title:FW(`couldNotPost`),description:Um(e)})})};return(0,B.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,B.jsx)(NI,{"aria-label":FW(`comment`),placeholder:FW(`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:FW(`comment`)})})]})},LW=20,RW=(e,t)=>{let n=U(),r=Ne({queryKey:H.comments(e,t),initialPageParam:``,queryFn:({pageParam:r})=>n.comments(e,t,{pageSize:LW,pageToken:r}),getNextPageParam:e=>e.nextPageToken||void 0});return{...r,items:r.data?.pages.flatMap(e=>e.items).reverse()??[]}},zW=()=>(0,B.jsx)(`div`,{className:`flex flex-col gap-2`,children:Array.from({length:3},(e,t)=>(0,B.jsx)(vh,{className:`h-4 w-full`},t))}),BW=({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)(If,{initials:I_(t)||`?`,hue:F_(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:dp(n),className:`text-muted-foreground`,children:[`· `,Sp(Math.max(0,Math.round((Date.now()-n)/1e3)))]})]}),(0,B.jsx)(NW,{comment:e})]})]})},VW=({item:e,resource:t,recordKey:n,canWrite:r})=>{let i=RW(t,n);return(0,B.jsxs)(Vf,{title:e.title,children:[i.isPending?(0,B.jsx)(zW,{}):i.error?(0,B.jsx)(Bg,{title:FW(`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:FW(`showEarlier`)}),i.items.length===0?(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:FW(`noComments`)}):(0,B.jsx)(`ol`,{className:`divide-y divide-border`,children:i.items.map(e=>(0,B.jsx)(BW,{comment:e},e.id))})]}),r&&(0,B.jsx)(`div`,{className:`mt-4`,children:(0,B.jsx)(IW,{resource:t,recordKey:n})})]})},HW=e=>e.kind===`group`||e.kind===`tab`?e.items:[],UW=e=>e.kind===`tab`?void 0:e.when,WW=e=>e.flatMap(e=>[e,...WW(HW(e))]).filter(e=>kc(UW(e))),GW=(e,t,n,r)=>{let i=0,a=e=>{let a=UW(e);return kc(a)?!r&&t[i++]===!0:Eg(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)},KW=(e,t,n,r)=>GW(e,CD(r?[]:WW(e).map(e=>UW(e)),t),n,r),qW=(e,t)=>{let n=U(),r=Se(),i=Nn(t);return o({mutationFn:({patch:r,etag:i})=>n.update(e,t,r,i),onSuccess:t=>{r.setQueryData(H.record(e,i),t),r.invalidateQueries({queryKey:[`page`,e]}),r.invalidateQueries({queryKey:[`list`,e]}),r.invalidateQueries({queryKey:[`map`,e]})}})},JW=e=>e instanceof fl,YW=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}`},XW=(e,t)=>{let n=e.operation,r=n===void 0?void 0:t[n];return r?q(`operationFailed`,{index:n+1,label:YW(r),message:e.message}):q(`nothingSaved`,{message:e.message})},ZW=(e,t)=>new e.constructor({...e.problem,detail:XW(e,t)}),QW=(e,t)=>Object.fromEntries(Object.entries(e).filter(([e])=>e!==t)),$W=({model:e,stored:t,recordKey:n,mode:r,subject:i,draftKey:a,lines:o})=>{let s=U(),c=Se(),l=qW(e.name,n),u=OL(r,i),[d]=(0,I.useState)(()=>a?KU(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])=>Sg(e.fields[n],r,t.record[n])),T=w.length>0,E=T||!!o?.dirty;(0,I.useEffect)(()=>{d?.order&&o?.setOrder(d.order)},[]),(0,I.useEffect)(()=>{if(!a)return;let n=Object.fromEntries(Object.entries(f).filter(([t])=>!e.fields[t]?.sensitive)),r=Object.keys(n).length>0||!!o?.order;qU(localStorage,a,r?{etag:t.etag,fields:n,...o?.order&&{order:o.order}}:void 0)},[a,e,f,o?.order,t.etag]);let D=n=>n in f?f[n]:[`boolean`,`file`].includes(e.fields[n].type)?t.record[n]:dg(t.record[n]),O=(n,r)=>{x(e=>QW(e,n));let i=typeof r==`string`?r!==dg(t.record[n]):Sg(e.fields[n],r,t.record[n]);p(e=>i?{...e,[n]:r}:QW(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];Sg(s,o,r.record[n])&&(a[n]=o,dg(r.record[n])!==dg(t.record[n])&&(i[n]=s.type===`file`?Nm(s,r.record[n]):dg(r.record[n])))}p(a),y(i)},A=()=>Object.fromEntries(w.map(([t,n])=>[t,yg(e.fields[t],n)])),j=e=>{let t=ax(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 JW(e)?await k():pl(e)&&j(e),e}},te=async r=>{let i=T?[{op:`update`,resource:e.name,key:n,data:A(),etag:t.etag}]:[],a=[...i,...r.ops];try{await s.batchWrite(a)}catch(e){if(JW(e))await k(),await c.invalidateQueries({queryKey:[`list`]}),_(!0);else if(pl(e)){let t=e.operation===void 0?-1:e.operation-i.length,n=r.rows[t];t<0?j(e):n&&o?.reject(n,e)}throw pl(e)?ZW(e,a):e}await Promise.all([c.invalidateQueries({queryKey:H.record(e.name,n)}),c.invalidateQueries({queryKey:[`list`]}),c.invalidateQueries({queryKey:[`page`]}),c.invalidateQueries({queryKey:[`map`]})]),o?.reset()};return{value:D,change:O,save:()=>u.run(async()=>{let e=o?.plan();e&&e.ops.length>0?await te(e):await ee(),p({}),y({}),x({}),_(!1),h(!1)}),dirty:E,discard:()=>{p({}),y({}),x({}),_(!1),h(!1),o?.reset()},restored:m&&E,dismissRestored:()=>h(!1),linesConflict:g,saving:u.phase===`saving`,phase:u.phase,message:u.message,conflicts:v,errors:b,rejections:S,keepMine:e=>y(t=>QW(t,e)),useTheirs:e=>{y(t=>QW(t,e)),p(t=>QW(t,e))}}},eG=sn(),tG=(e,t)=>{let[n,...r]=e.primaryKey;if(!(!e.tenantAcross||e.tenant===void 0||n===void 0||r.length>0||!e.fields[n]?.filterable))return{filter:Yt(eG.eq(n,t)),pageSize:1,fields:[n,e.tenant]}},nG=(e,t,n)=>{let r=t?.[e.tenant];if(r!=null&&String(r)!==n)return String(r)},rG=(e,t)=>{let n=U(),{session:r,organizations:i}=V(),a=(0,I.useMemo)(()=>i?tG(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=nG(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},iG=(e,t,n,r)=>{let i=U(),a=Se(),o=p_(),s=Object.values(e.fields).filter(n=>n.type===`relation`&&n.relation&&n.name!==e.tenant&&r[n.name]!=null&&t[n.relation.resource]?.primaryKey.length===1),c=f({queries:s.map(e=>{let o=t[e.relation.resource];return Ab(a,i,o,n[o.name],String(r[e.name]))})}),l=s.map(e=>({kind:`record`,resource:e.relation.resource,key:String(r[e.name])}));return{addresses:Object.fromEntries(s.map((e,t)=>[e.name,l[t]])),labels:Object.fromEntries(s.map((e,i)=>{let a=t[e.relation.resource];return[e.name,jb(c[i]?.data,o,a,n[a.name],String(r[e.name]))]}))}},aG=sn(),oG=(e,t,n,r)=>{if(e.primaryKey.length!==1)return[];let i=new Set(Sn(r).flatMap(e=>e.kind===`related`&&!e.through&&!e.from?[`${e.resource}.${e.field}`]:[])),a=Object.values(t).flatMap(t=>Object.values(t.fields).filter(t=>t.type===`relation`&&t.relation?.resource===e.name&&t.relation.columns.length===1&&t.filterable).filter(e=>e.name!==t.tenant&&!i.has(`${t.name}.${e.name}`)).map(e=>({source:t,field:e.name})));return a.map(({source:e,field:t})=>{let r=n[e.name],i=r?.names?.plural??F(e.name),o=a.filter(t=>t.source.name===e.name).length>1;return{resource:e.name,field:t,label:o?`${i} (${r?.fields[t]?.label??F(t)})`:i}})},sG=(e,t)=>({kind:`list`,resource:e.resource,filter:Yt(aG.eq(e.field,t))}),cG=sn(),lG=(e,t,n)=>{let r=U(),i=f({queries:e.map(e=>{let i=Yt(cG.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}]})},uG=({model:e,recordKey:t,layout:n})=>{let{resources:r,views:i}=W(),a=lG(oG(e,r,i,n),r,t);return a.length===0?null:(0,B.jsx)(og,{title:Q(`relatedRecords`),children:(0,B.jsx)(`ul`,{className:`-mx-2`,children:a.map(({relation:e,count:n})=>(0,B.jsx)(`li`,{children:(0,B.jsxs)(Uh,{to:sG(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)(vh,{className:`h-4 w-6`}):`${wp(n.count)}${n.exact?``:`+`}`,(0,B.jsx)(Oi,{className:`size-4 text-faint-foreground group-hover:text-foreground`})]})]})},`${e.resource}.${e.field}`))})})},dG=sn(),fG=(...e)=>{let t=e.filter(e=>!!e);return t.length===1?t[0]:t.map(e=>`(${e})`).join(` AND `)},pG=(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?fG(Yt(dG.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 gw(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:fG(Yt(dG.in(e.field,c.data)),e.filter),isPending:!1,error:null}:{filter:void 0,isPending:c.isPending,error:c.error}:{filter:fG(Yt(dG.eq(e.field,t)),e.filter),isPending:!1,error:null}},mG=()=>(0,B.jsx)(`div`,{className:`flex flex-col gap-2`,children:Array.from({length:3},(e,t)=>(0,B.jsx)(vh,{className:`h-4 w-full`},t))}),hG=({empty:e})=>(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:e??Q(`nothingYet`)}),gG=({item:e,value:t,owner:n})=>{let{resources:r,views:i}=W(),a=r[e.resource],o=a&&i[a.name],s=pG(e,t),[c,l]=kA(o,`related:${n}:${e.title}`,e.display),u=af(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:()=>yy(p,a,s.filter??``).queryFn()});if(!a||e.hideEmpty&&(s.isPending||s.filter===null||m&&(h.isPending||h.data===0)))return null;let g=xA(e,a,r),_=e.columns??Tr(a,o).filter(t=>t!==e.field),v=t=>s.isPending?(0,B.jsx)(mG,{}):s.error?(0,B.jsx)(Bg,{title:Q(`couldNotLoadRelated`),error:s.error}):s.filter===null||s.filter===void 0?(0,B.jsx)(hG,{empty:e.empty}):t(s.filter);if(e.presentation===`cards`)return(0,B.jsx)(Vf,{title:e.title,help:e.help,children:v(t=>(0,B.jsx)(GS,{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=jD(e,a,u),b=(0,B.jsx)(EA,{view:o,value:c,onChange:l}),x=y?(0,B.jsxs)(`div`,{className:`flex items-center gap-2`,children:[!d&&b,(0,B.jsx)(qV,{size:`sm`,sorting:d,onChange:f})]}):b;return d&&y?(0,B.jsx)(Vf,{title:e.title,help:e.help,actions:x,children:(0,B.jsx)(KV,{model:a,view:o,field:y,filter:Yt(dG.eq(e.field,t)),columns:_})}):(0,B.jsx)(Vf,{title:e.title,help:e.help,actions:x,children:v(t=>(0,B.jsx)(OA,{model:a,view:o,filter:t,sort:e.sort??``,columns:_,limit:e.limit??10,display:c,empty:e.empty,opens:g},t))})},_G=(e,t,n)=>{if(e.from===void 0)return n;let r=t[e.from];return typeof r==`boolean`?r:SA(t,e.from)??null},vG=(e,t)=>t===e.tenant||e.primaryKey.includes(t),yG=(e,t,n)=>{if(t&&t.layout.length>0)return t.layout;let r=Object.values(e.fields).filter(t=>!vG(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`)}]:[]]},bG=({resource:e,recordKey:t})=>{let{resources:n,views:r}=W(),{address:i}=Hh(),a=n[e],o=QP(e,t);if(!a)return(0,B.jsx)(tf,{title:q(`notFound`),children:q(`noResource`,{name:e})});if(o.isPending)return(0,B.jsx)(tf,{title:Q(`loading`),children:Q(`fetching`)});if(o.error)return(0,B.jsx)(`div`,{className:`p-8`,children:pl(o.error)&&o.error.status===404?(0,B.jsx)(xG,{model:a,recordKey:t}):(0,B.jsx)(Bg,{title:Q(`couldNotLoad`),error:o.error})});let s=(0,B.jsx)(SG,{model:a,recordKey:t,stored:o.data,preview:o.isPlaceholderData},o.isPlaceholderData?`preview`:`loaded`),c=r[e]?.record;if(!c||i?.kind===`record`&&i.standard)return s;if(o.isPlaceholderData)return(0,B.jsx)(tf,{title:Q(`loading`),children:Q(`fetching`)});let{record:l,etag:u,permissions:d}=o.data;return(0,B.jsx)(dU,{component:c.component,scope:{model:a,record:l,key:t,etag:u,permissions:d},standard:s})},xG=({model:e,recordKey:t})=>{let n=rG(e,t);return n.state===`looking`?(0,B.jsx)(tf,{title:Q(`loading`),children:Q(`fetching`)}):n.state===`switching`?(0,B.jsx)(tf,{title:Q(`loading`),children:Q(`openingElsewhere`)}):n.state===`failed`?(0,B.jsx)(Bg,{title:Q(`couldNotLoad`),error:n.error}):(0,B.jsx)(tf,{title:q(`notFound`),children:Q(`noRecord`)})},SG=({model:e,recordKey:t,stored:n,preview:r})=>{let i=W(),{address:a,go:o}=Hh(),s=i.views[e.name],c=p_()(e,s,n.record,t),{state:l}=V(),u=rW(e,t),d=$W({model:e,stored:n,recordKey:t,mode:s?.saveFeedback??`toast`,subject:c,draftKey:!r&&l.kind===`signed-in`?GU(l.user.id,e.name,t):void 0,lines:u.draft}),f=Se(),p=U(),m=sx(d.rejections),h=af(e.name),g=QL(e),_=oy(h,`update`)&&n.permissions?.update!==!1,{shown:v,offersEdit:y,editing:b}=Cg(s?.recordMode,_,a?.kind===`record`&&a.edit===!0);Vh(d.dirty&&v===`form`||d.saving),Md(d.dirty);let x=a?.kind===`record`?a.open:void 0,S=a?.kind===`record`&&a.edit===!0,C=a?.kind===`record`?a.tab:void 0,w=a?.kind===`record`&&a.standard===!0,T=(n=[],r=!1,i)=>({kind:`record`,resource:e.name,key:t,...r&&{edit:r},...n.length>0&&{open:n},...i&&{tab:i},...w&&{standard:w}}),E=T(x,!1,C),D=T(x,!0,C),O=v===`form`&&s?.recordMode!==void 0&&s.recordMode!==`edit`,k=oy(h,`delete`)&&n.permissions?.delete!==!1,A=ZL({model:e,view:s,restore:g,onDeleted:()=>o({kind:`list`,resource:e.name},{replace:!0}),onReview:()=>void f.invalidateQueries({queryKey:H.record(e.name,t)})}),j=iG(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,bg(e,d.value(e.name))]))},re=iG(e,i.resources,i.views,ne),ie=(e,t)=>{let n=ee(e);if(!n||!Og(t))return d.change(e,t);f.setQueryData(H.relatedLabel(n.name,t.key),{label:t.label}),d.change(e,jg(n,t.key))},{fields:ae}=c_(),oe={model:e,record:n.record,key:t,etag:n.etag,permissions:n.permissions},se=KW(yG(e,s,v===`read`),oe,b,r),{before:ce,tabs:le,after:ue}=DU(se),de=OU(le,C),fe=e=>b&&(d.errors[e]!==void 0||d.conflicts[e]!==void 0);(0,I.useEffect)(()=>{if(d.rejections===0)return;let e=AU(le,de,fe);e&&o(T(x,S,e===le[0]?void 0:e.title),{replace:!0})},[d.rejections]);let pe=se.flatMap(e=>e.kind===`sidebar`?e.fields:[]),me=e.fields.status?.type===`enum`,he=n.record.status,ge=me&&!pe.includes(`status`)&&he!=null&&he!==``?String(he):void 0,_e=lU(e,`updated`),ve=e=>s?.fields[e],ye=t=>cy(n.permissions,t)!==`hidden`&&Eg(ve(t)?.when,b)&&(v===`form`||!e.fields[t]?.writeOnly),be=e=>!r||Object.hasOwn(n.record,e),xe=r=>{let a=e.fields[r],o=cy(n.permissions,r);if(!a||o===`hidden`)return null;let c=d.conflicts[r],l=ee(r),u=ve(r)?.label??F(r),f=d.errors[r];return(0,B.jsx)(Yh,{name:r,label:u,required:v===`form`&&o!==`read`&&hg(a),help:Tg(ve(r),s,b),error:f&&ix(a,u,f),wide:!!(ve(r)?.multiline||ve(r)?.markdown),conflict:c===void 0?void 0:{user:{name:Q(`someoneElse`),initials:`?`,hue:40},ago:Q(`justNow`),theirValue:c||`—`,onKeepMine:()=>d.keepMine(r),onUseTheirs:()=>d.useTheirs(r)},children:be(r)?(0,B.jsx)(Ov,{field:a,hints:ve(r),value:d.value(r),stored:n.record[r],relationLabel:re.labels[r],relationTo:re.addresses[r],relationPicker:l&&{target:l,view:i.views[l.name]},locked:v!==`form`||o===`read`,invalid:!!d.errors[r],reveal:a.sensitive&&!a.writeOnly?()=>p.reveal(e.name,t,r):void 0,resource:e.name,onChange:e=>ie(r,e)}):(0,B.jsx)(vh,{className:`h-9`})},a.sensitive?`${r}:${n.etag}`:r)},Ce=r=>{let i=e.fields[r],a=be(r)?i.sensitive?(0,B.jsx)(Ov,{field:i,hints:ve(r),value:``,stored:n.record[r],locked:!0,reveal:()=>p.reveal(e.name,t,r),resource:e.name,onChange:e=>d.change(r,e)}):(0,B.jsx)(Lb,{model:e,field:i,value:n.record[r],relationLabel:j.labels[r]}):(0,B.jsx)(vh,{className:`h-4 w-32`});return{label:ve(r)?.label??F(r),help:Tg(ve(r),s,b),wide:!!(ve(r)?.multiline||ve(r)?.markdown),value:a}},we=se.findIndex(e=>e.kind===`sidebar`),Te=(0,B.jsx)(sg,{title:Q(`summary`),rows:pe.flatMap(t=>{let r=e.fields[t];if(!r||!ye(t))return[];if(!be(t))return[{label:ve(t)?.label??F(t),value:(0,B.jsx)(vh,{className:`h-4 w-24`})}];let i=n.record[t],a=gm(r,ve(t))&&typeof i==`string`&&i!==``?hm(i):Nm(r,i,ve(t)),o=r.type===`text`&&typeof i==`string`&&i!==``?xm(ve(t)):void 0,s=r.type===`enum`?(0,B.jsx)(Nb,{value:i,hints:ve(t),children:a}):o?(0,B.jsx)(bv,{format:o,value:a}):(0,B.jsx)(`span`,{title:Pm(r,i,void 0,ve(t)),children:a}),c=ev(ae,r,ve(t));return[{label:ve(t)?.label??F(t),title:a,value:c?(0,B.jsx)(dv,{shown:c,part:`display`,field:r,value:n.record[t],fallback:s}):s}]})}),Ee=async()=>{await d.save()&&O&&o(E,{replace:!0})},De=k?()=>void A.start({key:t,title:c,etag:n.etag,snapshot:n.record}):void 0,Oe=v===`form`&&(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(G,{variant:`primary`,className:`max-md:min-h-11 max-md:flex-1 md:w-full`,loading:d.saving,disabled:!d.dirty&&d.phase!==`saved`,onClick:()=>void Ee(),children:[d.phase===`saved`&&(0,B.jsx)(Si,{className:`size-4`}),d.phase===`saved`?Q(`saved`):Q(`save`)]}),O&&(0,B.jsx)(Uh,{to:E,className:P(mf(),`max-md:min-h-11 md:w-full`),onClick:e=>bh(e)&&d.discard(),children:Q(`cancel`)}),d.dirty&&(0,B.jsx)(`span`,{className:`text-xs text-muted-foreground max-md:order-first`,children:Q(`unsavedChanges`)})]}),ke=(i,a)=>{if(i.kind===`group`){let e=i.items.flatMap(ke);if(e.length===0)return[];let t=EU(i,x,fe),n=i.collapsed?T(TU(x,i.title),S,C):void 0;return[(0,B.jsx)(Gh,{title:i.title,open:t,toggle:n,children:e},`group:${i.title}`)]}if(i.kind===`related`&&i.lines)return!u.model||!u.item||r?[]:[(0,B.jsx)(WU,{lines:{...u,model:u.model,item:u.item},editable:v===`form`,saving:d.saving},`lines:${i.title}`)];if(i.kind===`related`)return i.from!==void 0&&!be(i.from)?[]:[(0,B.jsx)(gG,{item:i,value:_G(i,n.record,t),owner:e.name},`related:${i.title}`)];if(i.kind===`chart`)return[(0,B.jsx)(SU,{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)(uU,{item:i,scope:oe},`custom:${a}`)];if(i.kind===`map`)return i.sidebar?[]:[(0,B.jsx)(hU,{item:i,record:n.record},`map:${a}`)];if(i.kind===`gallery`)return[(0,B.jsx)(wW,{item:i,record:n.record,recordKey:t},`gallery:${a}`)];if(i.kind===`history`)return[(0,B.jsx)(MW,{item:i,model:e,view:s,recordKey:t,etag:n.etag},`history:${a}`)];if(i.kind===`comments`)return[(0,B.jsx)(VW,{item:i,resource:e.name,recordKey:t,canWrite:l.kind!==`visitor`},`comments:${a}`)];if(i.kind!==`section`)return[];let o=i.fields.filter(t=>e.fields[t]&&ye(t)),c=v===`read`&&i.presentation===`facts`,f=c?Rm(n.record,o):o;return f.length===0?[]:[(0,B.jsx)(Vf,{title:i.title,help:wg(i.helpWhen,s,b)?i.help:void 0,children:c?(0,B.jsx)(Zh,{facts:f.map(e=>({label:Ce(e).label,value:Ce(e).value,icon:$T(ve(e)?.icon)}))}):v===`read`?(0,B.jsx)(Xh,{rows:f.map(Ce)}):(0,B.jsx)(`div`,{className:`grid grid-cols-1 gap-x-6 gap-y-5 sm:grid-cols-2`,children:f.map(xe)})},i.title)]};return(0,B.jsxs)(`div`,{ref:m,className:`flex flex-1 flex-col`,inert:r,children:[A.dialogs,(0,B.jsx)(`div`,{className:`flex-1`,children:(0,B.jsxs)(`div`,{className:`mx-auto max-w-[1100px] px-4 pb-8 pt-6 md:px-10 md:py-8`,children:[(0,B.jsx)(zf,{title:c,status:ge?{label:ir(ge,ve(`status`)?.valueLabels),tone:Em(ve(`status`)?.valueColors,ge)}:void 0}),d.message&&(0,B.jsx)(`div`,{className:`mt-4`,children:(0,B.jsx)(Bg,{title:Q(`notSaved`),error:Error(d.message)})}),d.linesConflict&&(0,B.jsx)(`div`,{className:`mt-4`,children:(0,B.jsx)(Bg,{title:Q(`linesChanged`),error:Error(Q(`linesReloaded`))})}),v!==`form`&&y&&d.dirty&&(0,B.jsxs)(`div`,{className:`mt-4 flex items-center justify-between gap-3 rounded-lg border bg-surface px-3 py-2`,role:`status`,children:[(0,B.jsx)(`span`,{children:Q(`unsavedKept`)}),(0,B.jsxs)(`span`,{className:`flex gap-2`,children:[(0,B.jsx)(Uh,{to:D,className:mf({size:`sm`}),children:Q(`continueEditing`)}),(0,B.jsx)(G,{size:`sm`,onClick:d.discard,children:Q(`discard`)})]})]}),v===`form`&&d.restored&&(0,B.jsxs)(`div`,{className:`mt-4 flex items-center justify-between gap-3 rounded-lg border bg-surface px-3 py-2`,role:`status`,children:[(0,B.jsx)(`span`,{children:Q(`unsavedRestored`)}),(0,B.jsxs)(`span`,{className:`flex gap-2`,children:[(0,B.jsx)(G,{size:`sm`,onClick:d.dismissRestored,children:Q(`keep`)}),(0,B.jsx)(G,{size:`sm`,onClick:d.discard,children:Q(`discard`)})]})]}),(0,B.jsxs)(`div`,{className:`grid grid-cols-1 gap-8 md:grid-cols-[minmax(0,1fr)_300px] md:gap-12`,children:[(0,B.jsxs)(`main`,{className:`divide-y divide-border`,children:[ce.flatMap(ke),de&&(0,B.jsx)(Kh,{tabs:le.map((e,t)=>({title:e.title,to:T(x,S,t===0?void 0:e.title),current:e===de}))}),de&&(0,B.jsx)(`div`,{className:`divide-y divide-border`,children:de.items.flatMap(ke)},`tab:${de.title}`),ue.flatMap(ke)]}),(0,B.jsxs)(`aside`,{className:`space-y-4 md:sticky md:top-[var(--pb-sticky-top,0px)] md:max-h-[calc(100dvh-var(--pb-sticky-top,0px)-var(--pb-sticky-bottom,0px))] md:self-start md:overflow-y-auto md:pb-4 md:pt-8`,children:[Oe&&(0,B.jsx)(`div`,{className:`hidden flex-col items-center gap-2 md:flex`,children:Oe}),!r&&(0,B.jsx)(wU,{model:e,stored:n,recordKey:t,edit:y?D:void 0,onDelete:De}),we===-1&&Te,se.map((e,t)=>e.kind===`custom`&&e.sidebar&&!r?(0,B.jsx)(uU,{item:e,scope:oe},`custom:${t}`):e.kind===`map`&&e.sidebar&&!r?(0,B.jsx)(hU,{item:e,record:n.record},`map:${t}`):t===we?(0,B.jsx)(I.Fragment,{children:Te},`summary`):null),(0,B.jsx)(sg,{title:Q(`details`),rows:[lU(e,`created`),_e].flatMap(t=>{let r=t?e.fields[t]:void 0;return!t||!r||!ye(t)||pe.includes(t)?[]:[{label:ve(t)?.label??F(t),value:be(t)?(0,B.jsx)(`span`,{title:Pm(r,n.record[t],void 0,ve(t)),children:Nm(r,n.record[t],ve(t))}):(0,B.jsx)(vh,{className:`h-4 w-24`})}]})}),!r&&(0,B.jsx)(uG,{model:e,recordKey:t,layout:se})]})]})]})}),Oe&&(0,B.jsx)(`div`,{className:`sticky bottom-[var(--pb-sticky-bottom,0px)] z-20 flex shrink-0 items-center gap-2 border-t bg-background p-3 md:hidden`,children:Oe})]})},CG=e=>pl(e)?e.status===401||e.status===403?q(`signInRefused`,{message:e.message}):e.message:q(`noAnswer`),wG=({status:e})=>{let t=Se();return e.state===`error`?(0,B.jsx)(`div`,{className:`flex h-full min-h-48 flex-1 items-center justify-center p-8`,children:(0,B.jsxs)(`div`,{className:`max-w-md text-center`,children:[(0,B.jsx)(`h1`,{className:`text-[16px] font-semibold`,children:q(`cannotReach`,{label:e.source.label})}),(0,B.jsxs)(`p`,{className:`mt-1 text-muted-foreground`,children:[CG(e.error),` `,q(`restWorks`)]}),(0,B.jsx)(G,{className:`mt-3`,onClick:()=>void t.refetchQueries({queryKey:H.sourceMetas(e.source.url)}),children:q(`tryAgain`)})]})}):(0,B.jsxs)(`div`,{className:`flex h-full min-h-48 flex-1 items-center justify-center gap-2 text-muted-foreground`,children:[(0,B.jsx)($d,{}),` `,q(`loadingFrom`,{label:e.source.label})]})},TG=M(`app/search`),EG=(e,t)=>e.toLowerCase().includes(t.trim().toLowerCase()),DG=(e,t,n=``)=>{let r=rV(e,n).flatMap(e=>e.items.filter(e=>e.href!==void 0&&!e.problem)).filter(e=>EG(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||!$L(a,e.pages,e.permissions[r.name]??Ud))return[];let o=a.names?.singular??F(r.name),s=Dg(`title`,{noun:o});return!EG(s,t)&&!EG(o,i)&&!EG(a.names?.plural??F(r.name),i)?[]:[{id:`new:${r.name}`,title:s,href:Bc({kind:`create`,resource:r.name},n)}]});return[...r.length>0?[{id:`go-to`,label:TG(`goTo`),hits:r.map(e=>({id:`go-to:${e.id}`,title:e.label,href:e.href}))}]:[],...a.length>0?[{id:`create`,label:TG(`create`),hits:a.slice(0,5)}]:[]]},OG=sn(),kG=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)}]}),AG=e=>{let t=e.map(e=>e.label.toLowerCase());return t.length===0?TG(`search`):t.length===1?TG(`searchOne`,{name:t[0]}):t.length===2?TG(`searchTwo`,{first:t[0],second:t[1]}):TG(`searchMore`,{first:t[0],second:t[1]})},jG=e=>Yt(OG.search(e.trim())),MG=e=>!e.view?.searchResult?.title?.length&&e.view?.titleFrom!==void 0,NG=e=>{let t=e.view?.searchResult?.title;return t?.length?t:MG(e)?[]:[cr(e.model,e.view)]},PG=e=>{let t=NG(e);return e.view?.searchResult?.subtitle??e.model.search?.find(e=>!t.includes(e))},FG=e=>{let t=PG(e),n=MG(e)?l_(e.model,e.view):[],r=[...NG(e),...n,...t?[t]:[],...e.model.search??[]];return[...new Set([...e.model.primaryKey,...r.filter(t=>Object.hasOwn(e.model.fields,t))])]},IG=(e,t,n)=>{let r=t[n];return r==null?``:e.model.fields[n]?.type===`enum`?ir(String(r),e.view?.fields[n]?.valueLabels):String(r)},LG=(e,t,n,r=``,i=u_({},{user:void 0,member:()=>void 0}))=>{let a=Nn(ym(e.model,t)),o=NG(e),s=PG(e),c=Gt(e.model,t,n,[...o,...s?[s]:[]])??s,l=c?IG(e,t,c):``;return{id:a,title:MG(e)?i(e.model,e.view,t,a):o.map(n=>IG(e,t,n)).filter(Boolean).join(` `)||a,...l&&{subtitle:l},href:Bc({kind:`record`,resource:e.model.name,key:a},r)}},RG=()=>{let e=W(),t=U(),{basePath:n}=jh(),r=p_(),i=(0,I.useMemo)(()=>kG(e),[e]),[a,o]=(0,I.useState)(``),s=a.trim(),c=eT(s,200),l=s.length>=2,u=l&&c.length>=2,d=f({queries:i.map(e=>({queryKey:[`global-search`,e.model.name,c],enabled:u,staleTime:1/0,gcTime:0,queryFn:()=>t.list(e.model.name,{filter:jG(c),pageSize:5,fields:FG(e)})}))}),p=(0,I.useMemo)(()=>u?DG(e,c,n):[],[u,e,c,n]),m=i.flatMap((e,t)=>{let i=d[t];if(!u||!i)return[];if(i.error)return[{id:e.model.name,label:e.label,hits:[],failed:!0}];let a=(i.data?.items??[]).map(t=>LG(e,t,c,n,r));return a.length>0?[{id:e.model.name,label:e.label,hits:a}]:[]}),h=[...p,...m];return{available:Object.keys(e.pages).length>0||Object.keys(e.resources).length>0,placeholder:AG(i),text:a,setText:o,query:u?c:``,loading:l&&(s!==c||d.some(e=>e.isFetching)),groups:h}},zG=M(`app/new-version`),BG=()=>{let{versionChange:e,appName:t}=W(),{reload:n}=jh();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)(rs,{"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?zG.rich(`bannerTitle`,{app:t}):zG(`title`)}),(0,B.jsx)(`span`,{className:`text-xs`,children:zG(`bannerLine`)})]})]}):null},VG=()=>{let e=!!W().versionChange,{reload:t}=jh();return e?(0,B.jsxs)(G,{size:`sm`,variant:`ghost`,"aria-label":zG(`reloadPageHint`),title:zG(`reloadPageHint`),onClick:t,className:`max-md:size-9 max-md:p-0`,children:[(0,B.jsx)(rs,{className:`size-3.5 text-primary`}),(0,B.jsx)(`span`,{className:`max-md:sr-only`,children:zG(`reloadPage`)})]}):null},HG=()=>document.querySelector(`[aria-modal="true"]`)!==null,UG=()=>{let[e,t]=(0,I.useState)(HG);return(0,I.useEffect)(()=>{let e=new MutationObserver(()=>t(HG()));return e.observe(document.body,{childList:!0,subtree:!0}),t(HG()),()=>e.disconnect()},[]),e},WG=()=>{let e=!!W().versionChange,t=UG(),[n,r]=(0,I.useState)(!1),i=iy(),{reload:a}=jh(),o=e&&!n&&!t;return(0,I.useEffect)(()=>{if(!o)return;let e=i.show({state:`info`,sticky:!0,title:zG(`title`),description:zG(`description`),action:{label:zG(`reload`),onClick:a},onClose:()=>r(!0)});return()=>i.dismiss(e)},[o,i,a]),null},GG=M(`app/runtime`),KG=e=>!!(e?.updateAvailable&&e.indicator),qG=e=>e?5e3:18e5,JG=(e,t)=>{if(!e.updateStage)return GG(`updatingNow`);let n=GG(e.updateStage);return e.updateStartedAt?GG(`started`,{stage:n,ago:yp(Math.max(0,Math.floor((t-Date.parse(e.updateStartedAt))/1e3)))}):n},YG=(e,t=Date.now(),n=Gf())=>e.updating?JG(e,t):e.nextUpdateAt?GG(`nextOn`,{policy:GG(e.policy),when:dp(Date.parse(e.nextUpdateAt),n)}):GG(e.policy),XG=(e,t=Gf())=>{let n=dp(Date.parse(e.finishedAt),t),r=GG(e.outcome,{version:e.toVersion,when:n});return e.message?`${r}: ${e.message}`:`${r}.`},ZG=e=>pl(e)&&e.status<500&&e.problem.detail?e.problem.detail:pl(e)&&e.status===409?GG(`alreadyLatest`):pl(e)&&e.status===403?GG(`onlyAdmin`):GG(`couldNotStart`),QG=({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})]}),$G=({status:e,requesting:t,error:n,checkError:r,onUpdate:i,onClose:a})=>{let o=e.updating?void 0:e.lastUpdate;return(0,B.jsxs)(Cf,{title:GG(`runtimeUpdate`),description:e.updating?(0,B.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,B.jsx)($d,{className:`size-3.5`}),YG(e)]}):YG(e),onClose:a,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(G,{onClick:a,children:GG(`close`)}),(0,B.jsx)(G,{variant:`primary`,loading:t,disabled:e.updating||!e.updateAvailable,onClick:i,children:e.updating?GG(`updating`):GG(`updateNow`)})]}),children:[(0,B.jsx)(QG,{label:GG(`currentVersion`),value:e.version}),(0,B.jsx)(QG,{label:GG(`latestVersion`),value:e.latest}),o&&(0,B.jsx)(`p`,{className:o.outcome===`failed`?`mt-3 text-danger-text`:`mt-3 text-muted-foreground`,children:XG(o)}),n!==void 0&&(0,B.jsx)(`p`,{role:`alert`,className:`mt-3 text-danger-text`,children:ZG(n)}),r!==void 0&&(0,B.jsx)(`p`,{className:`mt-3 text-muted-foreground`,children:GG(`checkFailed`)})]})},eK=e=>{let t=qP(),n=(0,I.useRef)(t);n.current=t;let r=t!==void 0;return(0,I.useMemo)(()=>r?rd({url:e,token:()=>n.current}):void 0,[e,r])},tK=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(),qG(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}},nK=({client:e})=>{let{status:t,update:n,requesting:r,error:i,checkError:a}=tK(e),[o,s]=(0,I.useState)(!1);return!t||!o&&!KG(t)?null:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(G,{size:`sm`,variant:`ghost`,"aria-label":GG(`updateAvailable`),title:GG(`updateAvailable`),onClick:()=>s(!0),className:`max-md:size-9 max-md:p-0`,children:[(0,B.jsx)(Mi,{className:`size-3.5 text-primary`}),(0,B.jsx)(`span`,{className:`max-md:sr-only`,children:GG(`update`)})]}),o&&(0,B.jsx)($G,{status:t,requesting:r,error:i,checkError:a,onUpdate:()=>void n(),onClose:()=>s(!1)})]})},rK=({url:e})=>(0,B.jsx)(nK,{client:eK(e)}),iK=({url:e,client:t})=>t?(0,B.jsx)(nK,{client:t}):(0,B.jsx)(rK,{url:e}),aK=({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 wu))throw e;a(BA(e)),r(!1)}};return(0,B.jsxs)(`div`,{role:`region`,"aria-label":q(`staffSession`),className:`flex flex-wrap items-center gap-x-3 gap-y-2 border-b border-warning/40 bg-warning-soft px-4 py-2 text-warning-text`,children:[(0,B.jsx)(tc,{"aria-hidden":!0,className:`size-4 shrink-0`}),(0,B.jsx)(`p`,{className:`min-w-64 flex-1 break-words`,children:q.rich(`staffSignedIn`,{staff:(0,B.jsx)(`span`,{className:`font-semibold`,children:e.staffName??e.staff}),user:(0,B.jsx)(`span`,{className:`font-semibold`,children:e.user}),until:dp(Date.parse(e.expiresAt)),reason:e.reason})}),i&&(0,B.jsx)(`p`,{role:`alert`,className:`text-body font-medium text-danger-text`,children:i}),(0,B.jsx)(G,{size:`sm`,loading:n,onClick:()=>void o(),children:q(`stopStaffSession`)})]})},oK=(e,t,n)=>{if(!e)return;let r=new Map((n??[]).map(e=>[e.userId,e]));return Object.fromEntries(Object.entries(e).map(([e,{person:n,...i}])=>{if(n===void 0)return[e,i];let a=r.get(n),o=rH(t,n);return[e,{...i,person:{...a&&{status:a},...o&&{presence:o}}}]}))},sK=(e,t,n)=>({filter:n.filter??``,orderBy:n.orderBy??dh(e,t),pageSize:n.limit??3,fields:[...new Set([...e.primaryKey,cr(e,t),...l_(e,t),...n.status===void 0?[]:[n.status]])]}),cK=(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?ir(i,t.fields[n.status]?.valueLabels):i,tone:n.tones?.[i]??`neutral`,pulse:n.pulse?.includes(i)??!1}},lK=(e,t,n,r,i,a,o)=>r.map(r=>{let s=Nn(ym(e,r)),c=cK(e,t,n,r);return{id:s,label:o(e,t,r,s),href:Bc({kind:`record`,resource:e.name,key:s},i),...c&&{status:c},active:s===a}}),uK=(e,t,n,r,i)=>{let a=n.find(t=>Nn(ym(e,t))===r);return a!==void 0&&t.some(e=>!Object.is(a[e],i[e]))},dK=(e,t,n)=>{if(t.marks===void 0||!n||!Object.hasOwn(n,t.marks))return;let r=n[t.marks];return()=>r(e)},fK=e=>e&&(()=>oK(e(),nH(),e_().data)),pK=({model:e,request:t})=>H.navRecent(e.name,t.filter,t.orderBy,t.pageSize),mK=e=>{let t=Se();(0,I.useEffect)(()=>t.getQueryCache().subscribe(n=>{if(n.type!==`updated`||n.action.type!==`success`)return;let[r,i,a]=n.query.queryKey,o=n.action.data?.record;if(r===`record`&&typeof a==`string`&&o)for(let n of e){if(n.model.name!==i)continue;let e=t.getQueryData(pK(n));e&&uK(n.model,n.request.fields,e.items,a,o)&&t.invalidateQueries({queryKey:pK(n),exact:!0})}}),[t,e])},hK=(e,t,n)=>{let r=U(),i=p_(),{marks:a}=c_(),o=(0,I.useMemo)(()=>{let t=ZB(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:sK(r,n,i),useMarks:fK(dK(r.name,i,a))}]:[]})},[e,a]);mK(o);let s=f({queries:o.map(e=>({queryKey:pK(e),queryFn:()=>r.list(e.model.name,e.request)}))});return Object.fromEntries(o.map(({model:e,view:r,recent:a,useMarks:o},c)=>{let l=s[c];if(l.isPending)return[e.name,{state:`loading`}];if(l.isError)return[e.name,{state:`error`}];let u=n.resource===e.name?n.key:void 0;return[e.name,{state:`ready`,records:lK(e,r,a,l.data.items,t,u,i),...o&&{useMarks:o}}]}))},gK=({answer:e,current:t,next:n,launch:r})=>{if(!e?.bundleId||e.bundleId===t)return{kind:`none`};let i=r&&e.required;return e.bundleId===n&&!i?{kind:`none`}:{kind:`take`,bundleId:e.bundleId,download:e.bundleId!==n,reload:i}},_K=6e4,vK=e=>{let t=typeof e==`object`&&e?e.bundleId:void 0;return typeof t==`string`?t:null},yK=({bridge:e,check:t,releasesUrl:n,onHold:r})=>{let i=(t,n={})=>e.nativePromise(`LiveUpdate`,t,n),a=t=>t instanceof e.Exception,o=async(e,t)=>{t&&await i(`downloadBundle`,{bundleId:e,url:`${n}/${e}`,artifactType:`manifest`}),await i(`setNextBundle`,{bundleId:e})},s=async(e,t)=>{let n=!0,a=()=>{n&&(n=!1,r(!1))};r(!0);let s=setTimeout(a,_K);try{await o(e,t),n&&await i(`reload`)}finally{clearTimeout(s),a()}},c=async e=>{let[n,r,c]=await Promise.all([t(),i(`getCurrentBundle`),i(`getNextBundle`)]),l=gK({answer:n,current:vK(r),next:vK(c),launch:e});if(l.kind!==`none`)try{await(l.reload?s(l.bundleId,l.download):o(l.bundleId,l.download))}catch(e){if(!a(e))throw e}},l;return{ready:()=>i(`ready`),check:e=>(l??=c(e).finally(()=>{l=void 0}),l)}},bK=e=>/(?:^|\s)ProtobaseNative\/([0-9a-f]{16})(?:\s|$)/.exec(e)?.[1],xK=/^[A-Za-z0-9_-]{1,64}$/,SK=e=>typeof e==`object`&&!!e&&!Array.isArray(e),CK=e=>{if(!SK(e))return;let{bundleId:t,url:n,required:r}=e;if((t===null||typeof t==`string`&&xK.test(t))&&(n===null||typeof n==`string`)&&typeof r==`boolean`)return{bundleId:t,url:n,required:r}},wK=15e3,TK=e=>e instanceof TypeError||e instanceof DOMException&&e.name===`TimeoutError`,EK=async(e,{apiOrigin:t,fingerprint:n,shellVersion:r})=>{let i=`${t}${dr}?${pr({fingerprint:n,shellVersion:r})}`;try{let t=await e(i,{credentials:`omit`,cache:`no-store`,signal:AbortSignal.timeout(wK)});return t.status===200?CK(await t.json()):void 0}catch(e){if(TK(e)||e instanceof SyntaxError)return;throw e}},DK=({bridge:e,apiOrigin:t,userAgent:n,fetch:r,onHold:i})=>{if(!e?.Exception||!e.isPluginAvailable(`LiveUpdate`))return;let a=bK(n);return yK({bridge:{nativePromise:e.nativePromise.bind(e),Exception:e.Exception},check:async()=>a&&t?EK(r,{apiOrigin:t,fingerprint:a,shellVersion:OP}):void 0,releasesUrl:`${t}${fr}`,onHold:i})},OK=M(`app/live-update`),kK=({nativeBridge:e,apiOrigin:t,children:n})=>{let[r,i]=(0,I.useState)(!1),a=(0,I.useMemo)(()=>DK({bridge:e,apiOrigin:t,userAgent:navigator.userAgent,fetch:window.fetch.bind(window),onHold:i}),[e,t]);return(0,I.useEffect)(()=>{if(!a)return;a.ready(),a.check(!0);let e=()=>{document.visibilityState===`visible`&&a.check(!1)};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[a]),r?(0,B.jsx)(tf,{title:OK(`holdTitle`),children:OK(`holdLine`)}):n},AK=[`never`,`thirty_minutes`,`one_hour`,`four_hours`,`today`,`this_week`,`custom`],jK={thirty_minutes:30,one_hour:60,four_hours:240},MK=(e,t)=>new Date(e.getFullYear(),e.getMonth(),e.getDate()+t),NK=(e,t,n=``)=>{if(e===`never`)return null;if(e===`today`)return MK(t,1).toISOString();if(e===`this_week`)return MK(t,(8-t.getDay())%7||7).toISOString();if(e===`custom`){let e=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2})?$/.test(n)?new Date(n):void 0;return e&&!Number.isNaN(e.getTime())?e.toISOString():void 0}return new Date(t.getTime()+jK[e]*6e4).toISOString()},PK=e=>String(e).padStart(2,`0`),FK=e=>{let t=new Date(e);return`${t.getFullYear()}-${PK(t.getMonth()+1)}-${PK(t.getDate())}T${PK(t.getHours())}:${PK(t.getMinutes())}`},IK=(e,t=Date.now())=>{let n=wr(e,t);return n?{availability:n.availability,text:n.text??``,clears:n.clearsAt===null?`never`:`custom`,custom:n.clearsAt===null?``:FK(n.clearsAt)}:{availability:`automatic`,text:``,clears:`never`,custom:``}},LK=(e,t)=>{let n=e.text.trim(),r=n===``?void 0:Cr(n);if(r)return{problem:`text`,message:r};let i=NK(e.clears,t,e.custom);return i===void 0||i!==null&&Date.parse(i)<=t.getTime()?{problem:`time`}:{input:{availability:e.availability,text:n===``?null:n,clearsAt:i}}},RK={never:`never`,thirty_minutes:`thirtyMinutes`,one_hour:`oneHour`,four_hours:`fourHours`,today:`today`,this_week:`thisWeek`,custom:`custom`},zK=({current:e,onSave:t,onClear:n,onClose:r})=>{let[i,a]=(0,I.useState)(()=>IK(e)),[o,s]=(0,I.useState)(!1),[c,l]=(0,I.useState)(),[u,d]=(0,I.useState)(!1),f=(0,I.useId)(),p=(0,I.useId)(),m=(0,I.useId)(),h=e=>a({...i,...e}),g=LK(i,new Date),_=u&&`problem`in g?g:void 0,v=async e=>{s(!0),l(void 0);try{await e(),r()}catch(e){if(!(e instanceof dl))throw e;l(e.status===400?e.message:Qx(`couldNotSave`)),s(!1)}},y=()=>{d(!0),`input`in g&&v(()=>t(g.input))};return(0,B.jsx)(Cf,{title:Qx(e?`editStatus`:`setStatus`),onClose:r,actions:(0,B.jsxs)(B.Fragment,{children:[e&&(0,B.jsx)(G,{variant:`ghost`,className:`sm:mr-auto`,disabled:o,onClick:()=>void v(n),children:Qx(`clear`)}),(0,B.jsx)(G,{onClick:r,children:Qx(`cancel`)}),(0,B.jsx)(G,{variant:`primary`,type:`submit`,form:f,loading:o,children:Qx(`save`)})]}),children:(0,B.jsxs)(`form`,{id:f,className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),y()},children:[(0,B.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,B.jsx)(`label`,{htmlFor:p,className:`font-medium`,children:Qx(`statusText`)}),(0,B.jsx)(J,{id:p,name:`status`,autoComplete:`off`,autoFocus:!0,placeholder:Qx(`statusPlaceholder`),value:i.text,maxLength:200,invalid:_?.problem===`text`,..._?.problem===`text`&&{"aria-describedby":`${p}-problem`},onChange:e=>h({text:e.target.value})}),_?.problem===`text`&&(0,B.jsx)(`span`,{id:`${p}-problem`,className:`text-xs text-danger-text`,children:_.message})]}),(0,B.jsxs)(`div`,{className:`flex flex-col gap-1.5 font-medium`,children:[Qx(`availability`),(0,B.jsx)(Re,{label:Qx(`availability`),value:i.availability,onChange:e=>h({availability:e}),options:[{value:`automatic`,label:Qx(`automatic`)},{value:`busy`,label:Qx(`busy`)},{value:`do_not_disturb`,label:Qx(`doNotDisturb`)}]}),i.availability===`do_not_disturb`&&(0,B.jsx)(`span`,{className:`text-xs font-normal text-muted-foreground`,children:Qx(`doNotDisturbHint`)})]}),(0,B.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[Qx(`clearsAfter`),(0,B.jsx)(`select`,{name:`clears`,value:i.clears,onChange:e=>h({clears:e.target.value}),className:`h-8 rounded-md border border-border-strong bg-background px-2 font-normal`,children:AK.map(e=>(0,B.jsx)(`option`,{value:e,children:Qx(RK[e])},e))})]}),i.clears===`custom`&&(0,B.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,B.jsx)(`label`,{htmlFor:m,className:`font-medium`,children:Qx(`clearsAt`)}),(0,B.jsx)(J,{id:m,type:`datetime-local`,name:`clears-at`,value:i.custom,invalid:_?.problem===`time`,..._?.problem===`time`&&{"aria-describedby":`${m}-problem`},onChange:e=>h({custom:e.target.value})}),_?.problem===`time`&&(0,B.jsx)(`span`,{id:`${m}-problem`,className:`text-xs text-danger-text`,children:Qx(`pickTime`)})]}),c&&(0,B.jsx)(`p`,{role:`alert`,className:`text-danger-text`,children:c})]})})},BK=e=>{let t=U(),n=Se(),r=t_(),[i,a]=(0,I.useState)(!1);if(!e||!r.isSuccess)return{};let o=wr(r.data),s=()=>n.invalidateQueries({queryKey:[`statuses`]});return{menu:{mark:o&&(0,B.jsx)(nS,{status:o,textShown:`hover`}),label:o?(0,B.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5 text-foreground`,children:[(0,B.jsx)(tS,{availability:o.availability}),(0,B.jsx)(`span`,{className:`truncate`,children:o.text??eS(o.availability)})]}):Qx(`setStatus`),onOpen:()=>a(!0)},...i&&{dialog:(0,B.jsx)(zK,{current:o,onSave:async e=>{await t.status.set(e),await s()},onClear:async()=>{await t.status.clear(),await s()},onClose:()=>a(!1)})}}},VK=e=>e?.kind===`page`?e.page:e?.kind===`list`?$B(e.resource,e.list):e?.resource,HK=e=>e?.kind===`record`?e:void 0,UK=({workspace:e,sidebarMode:t,assistant:n,runtime:r})=>{let i=W(),{state:a,session:o,signOut:s,stopStaffSession:c,organizations:l}=V(),u=tE();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}=jh(),{address:g,go:_,open:v,back:y}=Hh(),b=VK(g),x=HK(g),S=RG(),C=dI(),w=hK(i,h,{resource:x?.resource,key:x?.key});XP(i);let T=rV(i,h,w),E=(0,I.useMemo)(()=>AH(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?Xd(i,O):void 0,A=O?Cn(i.views[O],g?.kind===`list`?g.list:void 0):void 0,j=T.find(e=>e.items.some(e=>e.id===b)),ee=O?i.resources[O]:void 0,te=QP(x?.resource??``,x?.key??``,!!(ee&&x)),ne=p_(),re=ee&&x&&te.data?ne(ee,A,te.data.record,x.key):void 0,ie=!!x&&(te.isLoading||k?.state===`loading`),{shell:ae}=c_(),oe=ae?.actions,se=ae?.rightPanel,ce=i.bell&&d&&!f&&(0,B.jsx)(iU,{own:ae?.bell}),le=BK(!!(i.status&&d&&!f)),ue=e_().data,de=nH(),[fe,pe]=(0,I.useState)(!1),me=i.assistant?.url,he=me&&(0,B.jsx)(gL,{open:fe,onToggle:()=>pe(!fe)}),ge=me&&fe&&(0,B.jsx)(yL,{url:me,client:n,page:m.size>0?`${p}?${m}`:p,onClose:()=>pe(!1)}),_e=i.errorReporting;(0,I.useEffect)(()=>{_e&&iv(_e)},[_e]);let ve=i.runtime?.url,ye=ve&&(0,B.jsx)(iK,{url:ve,client:r}),be=dS(t??`text-small`),xe=i.versionChange&&!be&&(0,B.jsx)(VG,{}),Se=kH((0,I.useCallback)(()=>pH(h),[h]),!!d),Ce=d&&EH(d,Se.current),we=Ce?R_(Ce):!1,Te=oU(),Ee=fH(!!(l&&d)),De=Ee.current,Oe=!!l&&De!==void 0&&!De.organization,ke=l&&d?rj(p):void 0,Ae=AM(),je=d?Tc(p):void 0,Me=je&&Ae?df(uf(Ae.tree),je.tab):void 0,Ne=d?je?Ae?.title??q(`account`):p===`/-/sign-in-policy`?q(`signInPolicy`):ke:void 0,M=A?.names?.plural??(O&&F(O)),Pe=Ne?[Ne]:wL({basePath:h,address:g,group:j?.label,page:D,resourceLabel:M,recordTitle:re,recordLoading:ie}),Fe=A?.names?.singular??(O&&F(O)),Ie=D&&g?.kind===`page`?df(uf(D.tree),g.tab):void 0;PM(NM(MM({address:g,page:D?{title:D.title,...Ie&&{tab:Ie.label}}:je&&Ae&&{title:Ae.title,...Me&&{tab:Me.label}},accountPage:Ne,resourceLabel:M,singular:Fe,recordTitle:re,recordLoading:ie}),i.appName));let Le=je?(0,B.jsx)(jM,{...je}):d&&p===`/-/sign-in-policy`?we?(0,B.jsx)(hN,{}):(0,B.jsx)(tf,{title:q(`adminsOnly`),children:q(`onlyAdminPolicy`)}):ke&&p===`/-/organization`?(0,B.jsx)(yH,{current:De,basePath:h,onChanged:Ee.reload}):ke&&(p===`/-/organization/members`||p===`/-/organization/invitations`)?oj(De)?p===`/-/organization/members`?(0,B.jsx)(oH,{current:De,statuses:ue,presence:de}):(0,B.jsx)(lH,{current:De}):(0,B.jsx)(tf,{title:q(`ownersOnly`),children:q(`onlyOwners`)}):ke&&p===`/-/organizations`||Oe?(0,B.jsx)(TH,{state:Ee,basePath:h}):g?g.kind===`page`?D?(0,B.jsx)(TL,{name:D.name,...g.tab&&{tab:g.tab}},D.name):(0,B.jsx)(tf,{title:q(`notFound`),children:q.rich(`noPage`,{page:g.page})}):k&&k.state!==`ready`?(0,B.jsx)(wG,{status:k}):g.kind===`create`?(0,B.jsx)(PL,{resource:g.resource,values:g.values},g.resource):g.kind===`record`?(0,B.jsx)(bG,{resource:g.resource,recordKey:g.key},`${g.resource}/${g.key}`):(0,B.jsx)(XV,{address:g},$B(g.resource,g.list)):p===`/`?(0,B.jsx)(tf,{title:q(`chooseResource`),children:q(`pickFromSidebar`)}):(0,B.jsx)(tf,{title:q(`notFound`),children:q(`nothingHere`)}),Re=we&&Te.length>0;return(0,B.jsxs)(xS,{pageScroll:!0,sidebarMode:t??`text-small`,activeItem:b??``,breadcrumb:Pe,user:Ce&&B_(Ce),onSignOut:d&&(()=>void s()),signIn:d?void 0:u.link(),workspace:De?.organization?.name??e,appName:i.appName,appIcon:i.appIcon,logo:jH,navGroups:T,bottomBar:CL(i,h,b),userMenu:[QB(i,h,b),l&&d?sj(h,p,De):[],d?Dc(h,p,we):[]],account:d&&`${h}/-/account`,organizations:l&&{...De?.organization&&{current:{id:De.organization.id,name:De.organization.name}},others:Ee.organizations.filter(e=>e.id!==De?.organization?.id),onSwitch:e=>void o.organizations.switchTo(e).then(()=>pH(h))},theme:{preference:C.preference,onChange:C.choose},...le.menu&&{status:le.menu},roles:Se.current?.active?{active:Se.current.active,roles:Se.current.roles,onSwitch:Se.switchTo}:void 0,onNavigate:v,onBack:y,sidebarNotice:(0,B.jsx)(BG,{}),banner:(f||Re)&&(0,B.jsxs)(B.Fragment,{children:[f&&(0,B.jsx)(aK,{signIn:f,onStop:c}),Re&&(0,B.jsx)(cU,{off:Te})]}),search:S.available?{placeholder:S.placeholder,text:S.text,onTextChange:S.setText,query:S.query,loading:S.loading,groups:S.groups,onSelect:v}:void 0,actions:(oe||ce||xe||ye||he)&&(0,B.jsxs)(B.Fragment,{children:[oe&&(0,B.jsx)(cv,{name:`shell.actions`,fallback:null,children:(0,B.jsx)(oe,{})}),ce,xe,ye,he]}),rightPanel:(se||ge)&&(0,B.jsxs)(B.Fragment,{children:[se&&(0,B.jsx)(cv,{name:`shell.rightPanel`,fallback:null,children:(0,B.jsx)(se,{})}),ge]}),children:[Le,le.dialog,i.calls&&d&&!f&&(0,B.jsx)(BH,{})]})},WK=({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=dS(i??`text-small`),{path:f}=jh();return(0,B.jsx)(Vd,{baseUrl:e,client:t,sources:n,token:c.kind===`visitor`?void 0:l.token,onUnauthenticated:u,children:(0,B.jsx)(rf,{children:(0,B.jsxs)(ay,{children:[!d&&(0,B.jsx)(WG,{}),f===`/-/connect`?(0,B.jsx)(rN,{}):(0,B.jsx)(sU,{ui:a,children:(0,B.jsx)(dH,{children:(0,B.jsx)(g_,{children:(0,B.jsx)(UK,{workspace:r,sidebarMode:i,assistant:o,runtime:s})})})})]})})})},GK=({baseUrl:e,client:t,ui:n,children:r})=>{let i=rF();return i?(0,B.jsx)(Vd,{baseUrl:e,client:t,children:(0,B.jsx)(s_.Provider,{value:n??{},children:(0,B.jsx)(tF,{name:i.name},i.name)})}):r},KK=({baseUrl:e,children:t})=>{let n=LF(),{basePath:r}=jh();if(!n)return t;let i=new URL(e??`/api/v1`,window.location.href),a=`${i.origin}${i.pathname.slice(0,i.pathname.lastIndexOf(`/`))}`;return(0,B.jsx)(tI,{link:n.token,systemPath:a,base:`${window.location.origin}${r}`})},qK=({auth:e,workspace:t,basePath:n,initialUrl:r,pluginLoader:i,locale:a,nativeBridge:o,...s})=>{Pe(a??`en`);let c=s.baseUrl&&new URL(s.baseUrl,window.location.href).origin;return(0,B.jsx)(uI,{children:(0,B.jsx)(kK,{nativeBridge:o,apiOrigin:c,children:(0,B.jsx)(kd,{session:e,...c&&{origin:c},...o&&{nativeBridge:o},children:(0,B.jsx)(zh,{basePath:n,initialUrl:r,children:(0,B.jsx)(FP,{...i&&{loader:i},children:(0,B.jsx)(JP,{children:(0,B.jsx)(GK,{baseUrl:s.baseUrl,client:s.client,ui:s.ui,children:(0,B.jsx)(KK,{...s.baseUrl&&{baseUrl:s.baseUrl},children:(0,B.jsx)(UP,{workspace:t,children:(0,B.jsx)(WK,{workspace:t,...s})})})})})})})})})})};export{zE as $,fI as A,gp as At,_N as B,$d as Bt,RI as C,J as Ct,EI as D,Hh as Dt,jI as E,Uh as Et,DP as F,Ef as Ft,VM as G,H as Gt,FM as H,Vd as Ht,OP as I,Cf as It,Qk as J,Ar as Jt,fj as K,Od as Kt,SP as L,G as Lt,Z as M,Gf as Mt,ZP as N,Uf as Nt,xI as O,Sh as Ot,qP as P,Vf as Pt,BE as Q,hP as R,mf as Rt,VI as S,Ug as St,NI as T,Jh as Tt,IM as U,U as Ut,gN as V,Gd as Vt,BM as W,Ld as Wt,Ek as X,Tk as Y,Dr as Yt,UE as Z,XI as _,i_ as _t,eU as a,Fy as at,GI as b,e_ as bt,nH as c,Yv as ct,mL as d,X_ as dt,iE as et,fL as f,j_ as ft,$I as g,a_ as gt,nL as h,o_ as ht,QH as i,xb as it,eI as j,Zf as jt,hI as k,Vp as kt,kL as l,zv as lt,sL as m,__ as mt,JW as n,nS as nt,ZH as o,Ly as ot,dL as p,x_ as pt,sA as q,id as qt,qW as r,Tx as rt,HH as s,Iy as st,qK as t,tS as tt,hL as u,pv as ut,YI as v,Qg as vt,PI as w,Yh as wt,WI as x,Wg as xt,JI as y,t_ as yt,cP as z,W as zt};
|
|
8
|
+
//# debugId=302d403f-b4f4-42e9-9129-d1a7c30b5404
|