@protobase/ui 0.16.1 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/records-map-2U_CQ4RG.js","assets/rolldown-runtime-hePW80VL.js","assets/react-Cvdyeg_0.js","assets/maplibre-AOh9A0NP.js","assets/react-dom-B-VxWsjA.js","assets/maplibre-DBE96hFo.css","assets/jsx-runtime-NZYk81nU.js","assets/record-map-DbwHSPf3.js"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/records-map-BORhj6IH.js","assets/rolldown-runtime-hePW80VL.js","assets/react-Cvdyeg_0.js","assets/maplibre-1qVldvCU.js","assets/react-dom-B-VxWsjA.js","assets/maplibre-DBE96hFo.css","assets/jsx-runtime-NZYk81nU.js","assets/record-map-BPHuPMlK.js"])))=>i.map(i=>d[i]);
2
2
  import{n as e,r as t,t as n}from"./rolldown-runtime-hePW80VL.js";import{t as r}from"./react-Cvdyeg_0.js";import{t as i}from"./react-dom-B-VxWsjA.js";import{t as a}from"./jsx-runtime-NZYk81nU.js";var o=t(r(),1),s=e=>e?.replace(/([a-z0-9])([A-Z])/g,`$1-$2`).toLowerCase();function c(e,t,n=[]){if(t==null)throw Error(`[lucide]: iconNode is required when icon name is used`);return{name:s(e),size:24,node:t,...n.length>0?{aliases:n}:{}}}var l=e=>{let t=``,n=!1;for(let r of e){if(r===`-`||r===`_`||r<=` `){n=t.length>0;continue}t.length===0?t+=r.toLowerCase():t+=n?r.toUpperCase():r,n=!1}return t},u=e=>{let t=l(e);return t.charAt(0).toUpperCase()+t.slice(1)},d=(...e)=>e.filter((e,t,n)=>!!e&&e.trim()!==``&&n.indexOf(e)===t).join(` `).trim(),f={xmlns:`http://www.w3.org/2000/svg`,width:24,height:24,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":2,"stroke-linecap":`round`,"stroke-linejoin":`round`};function p(e){return e!=null}function m(e,t={}){let n=t.attributeNames??{},r=e=>n[e]??e,i=e.size??e.width??f.width,a=e.size??e.height??f.height,o=e.aliases?.filter(e=>typeof e==`string`&&e.trim()!==``).map(e=>`lucide-${e}`)??[],s=[...e.name?[`lucide-${e.name}`]:[],...o],c=t.className?.split(` `).filter(Boolean)??[],l=t.includeDefaultClasses===!1?d(...c):d(`lucide`,...s,...c),u=t.absoluteStrokeWidth?Number(t.strokeWidth??f[`stroke-width`])*Number(e.size??e.width??f.width)/Number(t.size??t.width??f.width):t.strokeWidth??f[`stroke-width`];return[`svg`,{...Object.entries(f).reduce((e,[t,n])=>(e[r(t)]=n,e),{}),...`color`in t&&t.color&&{[r(`stroke`)]:t.color},...`size`in t&&p(t.size)&&{[r(`width`)]:t.size,[r(`height`)]:t.size},...`width`in t&&p(t.width)&&{[r(`width`)]:t.width},...`height`in t&&p(t.height)&&{[r(`height`)]:t.height},[r(`stroke-width`)]:u,...l&&{[r(`class`)]:l},[r(`viewBox`)]:`0 0 ${i} ${a}`,...t.hasA11yProp===!1?{[r(`aria-hidden`)]:`true`}:{},...`attributes`in t&&t.attributes},e.node.map(e=>{let[n,i,a]=e,o=t.nonScalingStroke?{[r(`vector-effect`)]:`non-scaling-stroke`,...i}:i;return a?[n,o,a]:[n,o]})]}function h(e,t={}){return m(e,{...t,attributeNames:{...t.attributeNames,class:`className`,"stroke-width":`strokeWidth`,"stroke-linecap":`strokeLinecap`,"stroke-linejoin":`strokeLinejoin`,"vector-effect":`vectorEffect`}})}var g=e=>{for(let t in e)if(t.startsWith(`aria-`)||t===`role`||t===`title`)return!0;return!1},_=(0,o.createContext)({}),v=()=>(0,o.useContext)(_),y=(0,o.forwardRef)(({color:e,size:t,width:n,height:r,strokeWidth:i,absoluteStrokeWidth:a,nonScalingStroke:s,className:c=``,children:l,iconNode:u=[],icon:f={node:u,aliases:[],size:24},...p},m)=>{let{size:_=24,strokeWidth:y=2,absoluteStrokeWidth:b=!1,nonScalingStroke:x=!1,color:S=`currentColor`,className:C=``}=v()??{},w=!!l||g(p),[T,E,D=[]]=h(f,{color:e??S,width:n??t??_,height:r??t??_,strokeWidth:i??y,absoluteStrokeWidth:a??b,nonScalingStroke:s??x,className:d(C,c),hasA11yProp:w,attributes:p});return(0,o.createElement)(T,{ref:m,...E},[...D.map(([e,t])=>(0,o.createElement)(e,t)),...Array.isArray(l)?l:[l]])});function b(e,t=[],n=[]){let r=typeof e==`string`?c(e,t,n):e,i=(0,o.forwardRef)(({className:e,...t},n)=>(0,o.createElement)(y,{ref:n,icon:r,className:e,...t}));return r.name&&(i.displayName=u(r.name)),i}var x={name:`arrow-down`,size:24,node:[[`path`,{d:`M12 5v14`,key:`s699le`}],[`path`,{d:`m19 12-7 7-7-7`,key:`1idqje`}]]};x.node;var S=b(x),C={name:`arrow-right`,size:24,node:[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`m12 5 7 7-7 7`,key:`xquz4c`}]]};C.node;var w=b(C),T={name:`arrow-up`,size:24,node:[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]};T.node;var E=b(T),D={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`}]]};D.node;var O=b(D),k={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`}]]};k.node;var A=b(k),j={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`}]]};j.node;var M=b(j),N={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`}]]};N.node;var ee=b(N),te={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`}]]};te.node;var ne=b(te),P={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`}]]};P.node;var re=b(P),ie={name:`boxes`,size:24,node:[[`path`,{d:`M2.97 12.92A2 2 0 0 0 2 14.63v3.24a2 2 0 0 0 .97 1.71l3 1.8a2 2 0 0 0 2.06 0L12 19v-5.5l-5-3-4.03 2.42Z`,key:`lc1i9w`}],[`path`,{d:`m7 16.5-4.74-2.85`,key:`1o9zyk`}],[`path`,{d:`m7 16.5 5-3`,key:`va8pkn`}],[`path`,{d:`M7 16.5v5.17`,key:`jnp8gn`}],[`path`,{d:`M12 13.5V19l3.97 2.38a2 2 0 0 0 2.06 0l3-1.8a2 2 0 0 0 .97-1.71v-3.24a2 2 0 0 0-.97-1.71L17 10.5l-5 3Z`,key:`8zsnat`}],[`path`,{d:`m17 16.5-5-3`,key:`8arw3v`}],[`path`,{d:`m17 16.5 4.74-2.85`,key:`8rfmw`}],[`path`,{d:`M17 16.5v5.17`,key:`k6z78m`}],[`path`,{d:`M7.97 4.42A2 2 0 0 0 7 6.13v4.37l5 3 5-3V6.13a2 2 0 0 0-.97-1.71l-3-1.8a2 2 0 0 0-2.06 0l-3 1.8Z`,key:`1xygjf`}],[`path`,{d:`M12 8 7.26 5.15`,key:`1vbdud`}],[`path`,{d:`m12 8 4.74-2.85`,key:`3rx089`}],[`path`,{d:`M12 13.5V8`,key:`1io7kd`}]]};ie.node;var ae=b(ie),F={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`]};F.node;var oe=b(F),se={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`}]]};se.node;var ce=b(se),I={name:`chart-column`,size:24,node:[[`path`,{d:`M3 3v16a2 2 0 0 0 2 2h16`,key:`c24i48`}],[`path`,{d:`M18 17V9`,key:`2bz60n`}],[`path`,{d:`M13 17V5`,key:`1frdt8`}],[`path`,{d:`M8 17v-3`,key:`17ska0`}]],aliases:[`bar-chart-3`]};I.node;var le=b(I),ue={name:`check`,size:24,node:[[`path`,{d:`M20 6 9 17l-5-5`,key:`1gmf2c`}]]};ue.node;var de=b(ue),fe={name:`chevron-down`,size:24,node:[[`path`,{d:`m6 9 6 6 6-6`,key:`qrunsl`}]]};fe.node;var pe=b(fe),me={name:`chevron-left`,size:24,node:[[`path`,{d:`m15 18-6-6 6-6`,key:`1wnfg3`}]]};me.node;var he=b(me),ge={name:`chevron-right`,size:24,node:[[`path`,{d:`m9 18 6-6-6-6`,key:`mthhwq`}]]};ge.node;var _e=b(ge),ve={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`}]]};ve.node;var ye=b(ve),be={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`]};be.node;var xe=b(be),Se={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`]};Se.node;var Ce=b(Se),we={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`}]]};we.node;var Te=b(we),Ee={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`]};Ee.node;var De=b(Ee),Oe={name:`circle`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]};Oe.node;var ke=b(Oe),Ae={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`]};Ae.node;var je=b(Ae),Me={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`}]]};Me.node;var Ne=b(Me),Pe={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`}]]};Pe.node;var Fe=b(Pe),Ie={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`}]]};Ie.node;var Le=b(Ie),Re={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`]};Re.node;var ze=b(Re),Be={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`]};Be.node;var Ve=b(Be),He={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`}]]};He.node;var Ue=b(He),We={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`}]]};We.node;var Ge=b(We),Ke={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`}]]};Ke.node;var qe=b(Ke),Je={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`]};Je.node;var eee=b(Je),Ye={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`}]]};Ye.node;var Xe=b(Ye),Ze={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`}]]};Ze.node;var tee=b(Ze),Qe={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`}]]};Qe.node;var $e=b(Qe),et={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`}]]};et.node;var tt=b(et),nt={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`}]]};nt.node;var rt=b(nt),it={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`}]]};it.node;var at=b(it),ot={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`}]]};ot.node;var st=b(ot),ct={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`}]]};ct.node;var lt=b(ct),ut={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`}]]};ut.node;var dt=b(ut),ft={name:`loader-circle`,size:24,node:[[`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`,key:`13zald`}]],aliases:[`loader-2`]};ft.node;var pt=b(ft),mt={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`}]]};mt.node;var ht=b(mt),gt={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`}]]};gt.node;var _t=b(gt),vt={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`}]]};vt.node;var yt=b(vt),bt={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`}]]};bt.node;var xt=b(bt),St={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`}]]};St.node;var Ct=b(St),wt={name:`menu`,size:24,node:[[`path`,{d:`M4 5h16`,key:`1tepv9`}],[`path`,{d:`M4 12h16`,key:`1lakjw`}],[`path`,{d:`M4 19h16`,key:`1djgab`}]]};wt.node;var nee=b(wt),Tt={name:`minus`,size:24,node:[[`path`,{d:`M5 12h14`,key:`1ays0h`}]]};Tt.node;var ree=b(Tt),Et={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`}]]};Et.node;var iee=b(Et),Dt={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`}]]};Dt.node;var aee=b(Dt),Ot={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`}]]};Ot.node;var kt=b(Ot),At={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`}]]};At.node;var jt=b(At),Mt={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`}]]};Mt.node;var Nt=b(Mt),Pt={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`}]]};Pt.node;var Ft=b(Pt),It={name:`plus`,size:24,node:[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`M12 5v14`,key:`s699le`}]]};It.node;var Lt=b(It),Rt={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`}]]};Rt.node;var zt=b(Rt),Bt={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`}]]};Bt.node;var Vt=b(Bt),Ht={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`}]]};Ht.node;var Ut=b(Ht),Wt={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`}]]};Wt.node;var Gt=b(Wt),Kt={name:`search`,size:24,node:[[`path`,{d:`m21 21-4.34-4.34`,key:`14j7rj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}]]};Kt.node;var qt=b(Kt),Jt={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`]};Jt.node;var Yt=b(Jt),Xt={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`}]]};Xt.node;var oee=b(Xt),Zt={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`}]]};Zt.node;var Qt=b(Zt),$t={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`}]]};$t.node;var en=b($t),tn={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`}]]};tn.node;var nn=b(tn),rn={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`}]]};rn.node;var an=b(rn),on={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`]};on.node;var sn=b(on),cn={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`]};cn.node;var ln=b(cn),un={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`}]]};un.node;var dn=b(un),fn={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`}]]};fn.node;var pn=b(fn),mn={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`}]]};mn.node;var hn=b(mn),gn={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`}]]};gn.node;var _n=b(gn),vn={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`]};vn.node;var yn=b(vn),bn={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`]};bn.node;var xn=b(bn),Sn={name:`truck`,size:24,node:[[`path`,{d:`M14 18V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v11a1 1 0 0 0 1 1h2`,key:`wrbu53`}],[`path`,{d:`M15 18H9`,key:`1lyqi6`}],[`path`,{d:`M19 18h2a1 1 0 0 0 1-1v-3.65a1 1 0 0 0-.22-.624l-3.48-4.35A1 1 0 0 0 17.52 8H14`,key:`lysw3i`}],[`circle`,{cx:`17`,cy:`18`,r:`2`,key:`332jqn`}],[`circle`,{cx:`7`,cy:`18`,r:`2`,key:`19iecd`}]]};Sn.node;var Cn=b(Sn),wn={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`}]]};wn.node;var Tn=b(wn),En={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`]};En.node;var see=b(En),Dn={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`}]]};Dn.node;var On=b(Dn),kn={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`}]]};kn.node;var cee=b(kn),An={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`}]]};An.node;var jn=b(An),Mn={name:`x`,size:24,node:[[`path`,{d:`M18 6 6 18`,key:`1bl5f8`}],[`path`,{d:`m6 6 12 12`,key:`d8bk6v`}]]};Mn.node;var Nn=b(Mn),Pn={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`}]]};Pn.node;var lee=b(Pn),Fn=t(i()),In=`/-/account`,Ln=`/-/sign-in-policy`,uee=(e,t,n)=>[{id:`account-security`,label:`Sign-in & security`,icon:tt,href:`${e}${In}`,active:t===In},...n?[{id:`sign-in-policy`,label:`Sign-in policy`,icon:en,href:`${e}${Ln}`,active:t===Ln}]:[]],Rn=(e,t,n,r)=>({code:e,message:t,hint:n,span:r}),dee=(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]},zn=(e,t)=>{let n=e.toLowerCase(),r=t.map(e=>({candidate:e,score:dee(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},Bn=(e,t)=>({start:e.start,end:t.end}),fee=(e,t)=>t===2?e%4==0&&(e%100!=0||e%400==0)?29:28:[4,6,9,11].includes(t)?30:31,Vn=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<=fee(n,r)},Hn=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 Vn(t[1])&&n<=23&&r<=59&&i<=59&&a<=23&&o<=59},Un={s:1,m:60,h:3600,d:86400,w:604800},Wn=e=>Hn(e)?Date.parse(e.toUpperCase()):void 0,Gn=/^(\d+(?:\.\d+)?)(s|m|h|d|w)$/,Kn=e=>{let t=Gn.exec(e);return t?Number(t[1])*Un[t[2]]:void 0},qn=/\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:[Zz]|[+-]\d{2}:\d{2})/y,Jn=/\d{4}-\d{2}-\d{2}/y,Yn=/[TtZz0-9:.+-]*/y,Xn=/0[xX][0-9a-fA-F]+/y,Zn=/\d+(?:\.\d+)?(?:[eE][+-]?\d+)?/y,Qn=(e,t,n)=>(e.lastIndex=n,e.exec(t)?.[0]),$n=(e,t,n,r)=>{let i=Qn(qn,e,t);if(i&&Hn(i))return{kind:`timestamp`,end:t+i.length};if(i||Qn(Jn,e,t)){let n=t+(Qn(Yn,e,t)??``).length;return{kind:`error`,end:n,error:Rn(`invalid-timestamp`,`"${e.slice(t,n)}" is not a valid RFC-3339 timestamp`,`Use a full timestamp like 2012-04-21T11:30:00Z, or quote a plain date: "2012-04-21"`,{start:t,end:n})}}let a=Qn(Xn,e,t);if(a)return n(e[t+a.length])?{kind:`number`,end:t+a.length}:void 0;let o=t+Qn(Zn,e,t).length;return(r.durationUnits?`smhdw`:`s`).includes(e[o]??` `)&&n(e[o+1])?{kind:`duration`,end:o+1}:n(e[o])?{kind:`number`,end:o}:void 0},er={a:`\x07`,b:`\b`,f:`\f`,n:`
3
3
  `,r:`\r`,t:` `,v:`\v`,"'":`'`,'"':`"`,"\\":`\\`,"?":`?`,"`":"`"},tr=(e,t,n)=>{let r=e.slice(t,t+n);return r.length===n&&/^[0-9a-fA-F]+$/.test(r)?parseInt(r,16):void 0},nr=(e,t)=>{let n=e[t+1];if(n===void 0)return{error:`a backslash at the end`,end:t+1};if(Object.hasOwn(er,n))return{text:er[n],end:t+2};let r={x:2,u:4,U:8};if(Object.hasOwn(r,n)){let i=tr(e,t+2,r[n]),a=t+2+r[n];return i!==void 0&&i<=1114111&&!(i>=55296&&i<=57343)?{text:String.fromCodePoint(i),end:a}:{error:`\\${n} needs ${r[n]} hex digits naming a Unicode scalar value`,end:t+2}}let i=/^[0-3][0-7]{2}/.exec(e.slice(t+1,t+4));return i?{text:String.fromCharCode(parseInt(i[0],8)),end:t+4}:{error:`the escape "\\${n}"`,end:t+2}},rr=(e,t)=>{let n=e[t],r=[],i=``,a=t+1;for(;a<e.length;){let t=e[a];if(t===n)return{end:a+1,value:i,errors:r};if(t!==`\\`){i+=t,a++;continue}let o=nr(e,a);`text`in o?i+=o.text:r.push(Rn(`invalid-escape`,`Invalid escape: ${o.error}`,`Valid escapes: \\a \\b \\f \\n \\r \\t \\v \\' \\" \\\\ \\? \\\` \\xHH \\uXXXX \\UXXXXXXXX \\ooo`,{start:a,end:o.end})),a=o.end}return r.push(Rn(`unterminated-string`,`String is missing its closing quote`,`Add a closing ${n}`,{start:t,end:e.length})),{end:e.length,value:void 0,errors:r}},ir={"(":`lparen`,")":`rparen`,",":`comma`,".":`dot`,":":`has`,"=":`eq`,"<":`lt`,">":`gt`,"-":`minus`},ar={AND:`and`,OR:`or`,NOT:`not`},or=e=>{let[t,n,r]=[e.at(-1),e.at(-2),e.at(-3)];return t?.kind===`rparen`&&n?.kind===`lparen`&&r?.text===`now`},sr=(e,t={})=>{let n=[],r=[],i=e=>e!==void 0&&(e in ir||e===`!`||t.arithmetic===!0&&e===`+`),a=e=>e===void 0||/\s/.test(e)||i(e)||e===`"`||e===`'`,o=(t,r,i,a=e.slice(r,i))=>n.push({kind:t,text:e.slice(r,i),value:a,span:{start:r,end:i}}),s=e.isWellFormed()?-1:e.search(/[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]/);s>=0&&r.push(Rn(`invalid-unicode`,`The filter contains an unpaired surrogate`,`Use well-formed UTF-16 text`,{start:s,end:s+1}));let c=0;for(;c<e.length;){let i=e[c];if(/\s/.test(i)){c++;continue}if(i===`"`||i===`'`){let t=rr(e,c);r.push(...t.errors),t.value!==void 0&&o(`string`,c,t.end,t.value),c=t.end;continue}if(/[0-9]/.test(i)){let n=$n(e,c,a,t);if(n?.kind===`error`?r.push(n.error):n&&o(n.kind,c,n.end),n){c=n.end;continue}}if(i===`!`||i===`<`||i===`>`){let t=e[c+1]===`=`;if(i===`!`&&!t){r.push(Rn(`unexpected-character`,`Unexpected character "!"`,`Use != for "not equal" or NOT / - for negation`,{start:c,end:c+1})),c++;continue}o(i===`!`?`ne`:i===`<`?t?`le`:`lt`:t?`ge`:`gt`,c,c+(t?2:1)),c+=t?2:1;continue}if(Object.hasOwn(ir,i)){o(ir[i],c,c+1),c++;continue}let s=t.arithmetic===`now-offset`&&or(n);if(i===`+`&&(t.arithmetic===!0||s)){o(`plus`,c,c+1),c++;continue}let l=c+1;for(;!a(e[l]);)l++;let u=e.slice(c,l);o(Object.hasOwn(ar,u)?ar[u]:`text`,c,l),c=l}return o(`eof`,e.length,e.length),{tokens:n,errors:r}},cr=class extends Error{error;constructor(e){super(e.message),this.error=e}},lr=(e,t,n,r)=>{throw new cr(Rn(e,t,n,r))},L=(e,t=0)=>e.tokens[Math.min(e.pos+t,e.tokens.length-1)],ur=e=>{let t=L(e);return t.kind!==`eof`&&e.pos++,t},dr=(e,t)=>L(e).kind===t?ur(e):void 0,fr=e=>e.kind===`eof`?`end of input`:`"${e.text}"`,pr=(e,t,n,r)=>dr(e,t)??lr(`expected-token`,`Expected ${n} but found ${fr(L(e))}`,r,L(e).span),mr=(e,t,n)=>{e.depth>=e.maxDepth&&lr(`too-deep`,`The filter is nested too deeply`,`Nest at most ${e.maxDepth} levels`,t),e.depth++;try{return n()}finally{e.depth--}},hr=[`text`,`and`,`or`,`not`],gr=e=>{let t=pr(e,`text`,`a field name or value`,`Text may not contain spaces or the characters ( ) - . = : < > ! ,`),n=[t.text],r=t.span;for(;L(e).kind===`dot`;){let t=L(e,1),i=t.kind===`number`&&/^\d+(\.\d+)?$/.test(t.text);!hr.includes(t.kind)&&!i&&lr(`expected-token`,`Expected a field name after "." but found ${fr(t)}`,`Write traversals like customer.country`,t.span),ur(e),ur(e),n.push(...i?t.text.split(`.`):[t.text]),r=Bn(r,t.span)}return{kind:`member`,path:n,span:r}},_r=e=>({kind:`duration`,amount:Number(e.text.slice(0,-1)),unit:e.text.slice(-1),span:e.span}),vr=[`member`,`string`,`number`,`boolean`,`duration`,`timestamp`,`call`,`binary`],yr=e=>vr.includes(e.kind),br=(e,t,n)=>mr(e,n,()=>{ur(e);let r=[];if(L(e).kind!==`rparen`)do r.push(Tr(e));while(dr(e,`comma`));return{kind:`call`,name:t,args:r,span:Bn(n,pr(e,`rparen`,`")"`,`Close the call to ${t}() with ")"`).span)}}),xr=e=>{let t=L(e);switch(t.kind){case`string`:return ur(e),{kind:`string`,value:t.value,span:t.span};case`number`:return ur(e),{kind:`number`,value:Number(t.text),raw:t.text,span:t.span};case`duration`:return ur(e),_r(t);case`timestamp`:return ur(e),{kind:`timestamp`,value:t.text,span:t.span};case`minus`:{let n=L(e,1);(n.kind!==`number`||n.span.start!==t.span.end)&&lr(`unexpected-token`,`Expected a number after "-" but found ${fr(n)}`,`Write negative numbers as -5, without a space`,n.span),ur(e),ur(e);let r=`-${n.text}`;return{kind:`number`,value:-Number(n.text),raw:r,span:Bn(t.span,n.span)}}case`text`:{if((t.text===`true`||t.text===`false`)&&L(e,1).kind!==`dot`&&(L(e,1).kind!==`lparen`||L(e,1).span.start!==t.span.end))return ur(e),{kind:`boolean`,value:t.text===`true`,span:t.span};let n=gr(e);return L(e).kind===`lparen`&&L(e).span.start===n.span.end?br(e,n.path.join(`.`),n.span):n}default:return lr(`unexpected-token`,`Expected a value but found ${fr(t)}`,`Values are text, "strings", numbers, true/false, durations, timestamps or function calls`,t.span)}},Sr=e=>{let t=ur(e);return mr(e,t.span,()=>{let n=e.expression(e);return pr(e,`rparen`,`")"`,`Close the group opened here`),n?n.kind===`global`?n.value:n:lr(`unexpected-token`,`Empty group`,`Put an expression inside the parentheses`,t.span)})},Cr=e=>L(e).kind===`lparen`?Sr(e):xr(e),wr=e=>[`text`,`string`,`number`,`duration`,`timestamp`,`lparen`,`minus`].includes(L(e,1).kind),Tr=e=>{let t=Cr(e);if(!e.extensions.arithmetic||!yr(t))return t;let n=t,r=e.extensions.arithmetic===`now-offset`,i=()=>n.kind===`call`&&n.name===`now`&&n.args.length===0,a=()=>!r||i()&&L(e,1).kind===`duration`;if(r&&i()&&(L(e).kind===`plus`||L(e).kind===`minus`)&&L(e,1).kind!==`duration`)return lr(`expected-token`,`Expected a duration after "${L(e).text}" but found ${fr(L(e,1))}`,`Durations need a unit, for example now() - 30d`,L(e,1).span);for(;(L(e).kind===`plus`||L(e).kind===`minus`)&&wr(e)&&a();){let t=ur(e).kind===`plus`?`+`:`-`,r=Cr(e);if(!yr(r))return lr(`unexpected-token`,`Arithmetic needs values, not conditions`,`Use values on both sides of + and -`,r.span);n={kind:`binary`,op:t,left:n,right:r,span:Bn(n.span,r.span)}}return n},Er=e=>{let t=L(e),n=Tr(e);return yr(n)||lr(`unexpected-token`,`A comparison needs a value on the right`,`Write field = value`,t.span),n},Dr={eq:`=`,ne:`!=`,lt:`<`,le:`<=`,gt:`>`,ge:`>=`},Or=[`text`,`string`,`number`,`duration`,`timestamp`,`not`,`minus`,`lparen`],kr=(e,t)=>{let n=t.filter(e=>e!==void 0);return n.length<=1?n[0]:{kind:e,args:n,span:Bn(n[0].span,n[n.length-1].span)}},Ar=e=>{let t=0;for(;;){let{kind:n}=L(e);if(n===`eof`||t===0&&(n===`and`||n===`or`||n===`rparen`))return;n===`lparen`&&t++,n===`rparen`&&t--,ur(e)}},jr=e=>{let t=xr(e),n=L(e);if(n.kind===`has`){ur(e);let n=L(e);if(n.kind===`text`&&n.text===`*`)return ur(e),{kind:`present`,left:t,span:Bn(t.span,n.span)};let r=Er(e);return{kind:`has`,left:t,right:r,span:Bn(t.span,r.span)}}let r=Dr[n.kind];if(r){ur(e);let n=Er(e);return{kind:`compare`,op:r,left:t,right:n,span:Bn(t.span,n.span)}}return t.kind===`call`?t:{kind:`global`,value:t,span:t.span}},Mr=e=>{let t=L(e);return t.kind===`lparen`?(ur(e),mr(e,t.span,()=>{let n=Lr(e);return dr(e,`rparen`)||e.errors.push(Rn(`expected-token`,`Expected ")" but found ${fr(L(e))}`,`Close the group opened here`,t.span)),n})):jr(e)},Nr=e=>{let t=L(e);if(t.kind!==`not`&&t.kind!==`minus`)return Or.includes(t.kind)?mr(e,t.span,()=>Mr(e)):lr(`unexpected-token`,`Unexpected ${fr(t)}`,`Expected a field, a value or "("`,t.span);ur(e);let n=L(e),r=n.kind===`minus`&&L(e,1).kind===`number`&&L(e,1).span.start===n.span.end;(n.kind===`not`||n.kind===`minus`&&!r)&&lr(`unexpected-token`,`Negations cannot be stacked`,`Group the inner one: NOT (NOT a)`,n.span);let i=mr(e,t.span,()=>Mr(e));if(!i)return;let a=Bn(t.span,i.span);if(t.kind===`minus`&&i.kind===`global`&&i.value.kind===`number`&&!i.value.raw.startsWith(`-`)){let{raw:e,value:t}=i.value;return{kind:`global`,value:{kind:`number`,value:-t,raw:`-${e}`,span:a},span:a}}return{kind:`not`,arg:i,span:a}},Pr=e=>{try{return Nr(e)}catch(t){if(!(t instanceof cr))throw t;e.errors.push(t.error),Ar(e);return}},Fr=e=>{let t=[Pr(e)];for(;dr(e,`or`);)t.push(Pr(e));return kr(`or`,t)},Ir=e=>{let t=[Fr(e)];for(;Or.includes(L(e).kind);)t.push(Fr(e));return kr(`sequence`,t)},Lr=e=>{let t=[Ir(e)];for(;dr(e,`and`);)t.push(Ir(e));return kr(`and`,t)},Rr=(e,t={})=>{let n=t.maxLength??1e4;if(e.length>n)return{ok:!1,ast:void 0,errors:[Rn(`too-long`,`The filter is longer than ${n} characters`,`Shorten the filter`,{start:n,end:e.length})]};let r=t.extensions??{},i=sr(e,r),a={tokens:i.tokens,pos:0,errors:i.errors,depth:0,maxDepth:t.maxDepth??64,extensions:r,expression:Lr},o=[];for(;L(a).kind!==`eof`;){if(L(a).kind===`rparen`){let e=ur(a);a.errors.push(Rn(`unexpected-token`,`Unmatched ")"`,`Remove it or add a matching "("`,e.span));continue}o.push(Lr(a))}let s=o.filter(e=>e!==void 0),c=s.length<=1?s[0]:{kind:`and`,args:s,span:{start:s[0].span.start,end:s[s.length-1].span.end}},l=[...a.errors].sort((e,t)=>e.span.start-t.span.start);return l.length===0?{ok:!0,ast:c,errors:[]}:{ok:!1,ast:c,errors:l}},zr=(e,t)=>{if(Object.hasOwn(e,t))return{name:t,spec:e[t]};let n=Object.entries(e).find(([,e])=>e.aliases?.includes(t));return n&&{name:n[0],spec:n[1]}},Br=(e,t)=>{let n=t.path[0],r=zr(e.schema.fields,n);if(!r){let r=Object.entries(e.schema.fields).filter(([,e])=>e.filterable!==!1).map(([e])=>e),i=zn(n,r);e.errors.push(Rn(`unknown-field`,`Unknown field "${n}"`,i?`Did you mean "${i}"?`:`Available fields: ${r.join(`, `)}`,t.span));return}let i=[r.name],a=r.spec,o=a.filterable!==!1;for(let n of t.path.slice(1)){let r=a.type===`message`?a.fields?.[n]:a.type===`map`?a.value:a.type===`any`?a:void 0;if(!r||a.type===`message`&&!Object.hasOwn(a.fields??{},n)){e.errors.push(Rn(`invalid-traversal`,`Cannot traverse into "${n}" of "${i.join(`.`)}"`,a.type===`message`?`Available fields: ${Object.keys(a.fields??{}).join(`, `)}`:`Only message, map and any fields can be traversed`,t.span));return}i.push(n),a=r,o&&=a.filterable!==!1}if(!o){e.errors.push(Rn(`not-filterable`,`Field "${i.join(`.`)}" cannot be filtered on`,`Mark it filterable in the schema`,t.span));return}return{...t,path:i,field:{name:i.join(`.`),spec:a}}},Vr=(e,t)=>({message:e,hint:t}),Hr=(e,t)=>Vr(`Expected ${e}`,t),Ur=e=>e.kind===`string`?e.value:e.kind===`member`?e.path.join(`.`):void 0,Wr={integer:/^-?(\d+|0[xX][0-9a-fA-F]+)$/,number:/^-?\d+(\.\d+)?([eE][+-]?\d+)?$|^-?0[xX][0-9a-fA-F]+$/},Gr=(e,t)=>e===t||e===`any`||t===`any`||[`integer`,`number`].includes(e)&&[`integer`,`number`].includes(t),Kr=(e,t,n)=>{let r=Ur(n);switch(e){case`any`:return;case`string`:return r===void 0?Hr(`a string`,`Quote text values: "..."`):void 0;case`enum`:return r!==void 0&&t?.values?.includes(r)?void 0:Vr(`Invalid enum value`,`Allowed values: ${(t?.values??[]).join(`, `)}`);case`integer`:case`number`:{let t=n.kind===`number`?n.raw:r;return t!==void 0&&Wr[e].test(t)?void 0:Hr(e===`integer`?`an integer`:`a number`,`Write 42, -1.5 or 2.5e3, or quote a numeric string`)}case`boolean`:return n.kind===`boolean`||r===`true`||r===`false`?void 0:Hr(`true or false`,`Write true or false`);case`timestamp`:return n.kind===`timestamp`||r!==void 0&&Hn(r)?void 0:Hr(`an RFC-3339 timestamp`,`Use "2012-04-21T11:30:00Z"`);case`duration`:return n.kind===`duration`||r!==void 0&&Kn(r)!==void 0?void 0:Hr(`a duration`,`Use a number with a unit, for example 20s or 1.5s`);case`map`:case`message`:return Vr(`${e} fields cannot be compared`,`Compare a nested field, or use field:key`)}},qr=e=>[`member`,`string`,`number`,`boolean`,`duration`,`timestamp`,`call`,`binary`].includes(e.kind),Jr=(e,t,n,r)=>{if(!qr(n)){e.errors.push(Rn(`wrong-argument`,`Argument "${t.name}" must be a value`,`Pass a field, literal or function call`,n.span));return}if(t.type===`field`){if(n.kind!==`member`){e.errors.push(Rn(`wrong-argument`,`Argument "${t.name}" must be a field`,`Pass a field name without quotes`,n.span));return}let r=Br(e,n);if(r&&t.of&&!t.of.includes(r.field.spec.type)){e.errors.push(Rn(`wrong-argument`,`Argument "${t.name}" cannot be a ${r.field.spec.type} field`,`Accepted field types: ${t.of.join(`, `)}`,n.span));return}return r}let i=r(e,n);if(!i)return;if(t.type===`any`)return i.node;let a=i.type&&(n.kind===`call`||n.kind===`binary`)?Gr(t.type,i.type)?void 0:{message:`Expected ${t.type}`,hint:`Argument "${t.name}" is ${i.type}`}:Kr(t.type,void 0,i.node);return a&&e.errors.push(Rn(`wrong-argument`,a.message,a.hint,n.span)),a?void 0:i.node},Yr=(e,t,n)=>{let r=e.schema.functions??{};if(!Object.hasOwn(r,t.name)){let n=zn(t.name,Object.keys(r));e.errors.push(Rn(`unknown-function`,`Unknown function "${t.name}"`,n?`Did you mean "${n}"?`:`Available functions: ${Object.keys(r).join(`, `)||`none`}`,t.span));return}let i=r[t.name],a=i.params.length;if(t.args.length<a||!i.rest&&t.args.length>a){let n=i.rest?`at least ${a}`:String(a);e.errors.push(Rn(`wrong-arity`,`${t.name}() takes ${n} argument(s) but got ${t.args.length}`,`Usage: ${t.name}(${[...i.params,...i.rest?[i.rest]:[]].map(e=>e.name).join(`, `)})`,t.span));return}let o=t.args.map((t,r)=>Jr(e,i.params[r]??i.rest,t,n));if(!o.some(e=>e===void 0))return{call:{...t,args:o},returns:i.returns??`boolean`}},Xr=(e,t,n)=>{if(e===`timestamp`&&t===`duration`)return`timestamp`;if(e===`timestamp`&&t===`timestamp`&&n===`-`||e===`duration`&&t===`duration`)return`duration`;if((e===`integer`||e===`number`)&&(t===`integer`||t===`number`))return e===`integer`&&t===`integer`?`integer`:`number`},Zr={number:`number`,boolean:`boolean`,duration:`duration`,timestamp:`timestamp`},Qr=(e,t)=>{switch(t.kind){case`call`:{let n=Yr(e,t,Qr);return n&&{node:n.call,type:n.returns}}case`binary`:{let n=Qr(e,t.left),r=Qr(e,t.right);if(!n||!r)return;let i=n.type&&r.type?Xr(n.type,r.type,t.op):n.type??r.type??`number`;if(!i){e.errors.push(Rn(`invalid-value`,`Cannot apply "${t.op}" to ${n.type} and ${r.type}`,`Add a duration to a timestamp, or combine numbers`,t.span));return}return{node:{...t,left:n.node,right:r.node},type:i}}case`number`:case`boolean`:case`duration`:case`timestamp`:return{node:t,type:Zr[t.kind]};default:return{node:t,type:void 0}}},$r=[`string`,`integer`,`number`,`timestamp`,`duration`,`any`],ei=(e,t)=>{if(t.kind===`member`){let n=Br(e,t);return n&&{node:n,type:n.field.spec.type,spec:n.field.spec}}let n=Qr(e,t);return n&&{...n,spec:void 0}},ti=(e,t,n,r)=>{e.errors.push(Rn(`operator-not-allowed`,t,n,r.span))},ni=(e,t,n)=>{if(!t.type)return Qr(e,n)?.node;let r=Qr(e,n);if(!r)return;let i=r.type&&(n.kind===`call`||n.kind===`binary`)?Gr(t.type,r.type)?void 0:{message:`Expected ${t.type} but got ${r.type}`,hint:`Compare values of the same type`}:Kr(t.type,t.spec,r.node);return i&&e.errors.push(Rn(`invalid-value`,i.message,i.hint,n.span)),i?void 0:r.node},ri=(e,t)=>{let n=ei(e,t.left);if(!n)return;let r=n.type;if(n.spec?.repeated)return ti(e,`"${t.op}" is not supported on repeated fields`,`Use field:value to test membership`,t);if(r===`map`||r===`message`)return ti(e,`${r} fields cannot be compared`,`Use field:key, or compare a nested field`,t);if(r&&![`=`,`!=`].includes(t.op)&&!$r.includes(r))return ti(e,`"${t.op}" is not supported for ${r} fields`,`Supported: = !=`,t);let i=(t.op===`=`||t.op===`!=`)&&t.right.kind===`string`&&t.right.value.includes(`*`);if(i&&r&&r!==`string`&&r!==`any`){e.errors.push(Rn(`wildcard-not-allowed`,`Wildcards are only supported on string fields, not ${r}`,`Remove the "*"`,t.right.span));return}let a=i?t.right:ni(e,n,t.right);return a&&{...t,left:n.node,right:a}},ii=(e,t)=>{let n=ei(e,t.left);if(!n)return;let{type:r,spec:i}=n,a=ni(e,!i?.repeated&&(r===`map`||r===`message`)?{...n,type:`string`}:n,t.right);return a&&{...t,left:n.node,right:a}},ai=(e,t)=>{switch(t.kind){case`sequence`:case`and`:case`or`:{let n=t.args.map(t=>ai(e,t));return n.every(e=>e)?{...t,args:n}:void 0}case`not`:{let n=ai(e,t.arg);return n&&{...t,arg:n}}case`compare`:return ri(e,t);case`has`:return ii(e,t);case`present`:{let n=ei(e,t.left);return n&&{...t,left:n.node}}case`global`:return t;case`call`:{let n=Yr(e,t,Qr);if(n&&n.returns!==`boolean`){e.errors.push(Rn(`not-boolean`,`${t.name}() returns ${n.returns}, not a condition`,`Compare its result: f(x) > 1`,t.span));return}return n?.call}}},oi=(e,t)=>{let n={schema:t,errors:[]},r=ai(n,e);return!r||n.errors.length>0?{ok:!1,errors:[...n.errors].sort((e,t)=>e.span.start-t.span.start)}:{ok:!0,ast:r}},si={"\\":`\\\\`,'"':`\\"`,"\n":`\\n`,"\r":`\\r`," ":`\\t`,"\x07":`\\a`,"\b":`\\b`,"\f":`\\f`,"\v":`\\v`},ci=e=>{if(!e.isWellFormed())throw Error(`Strings with unpaired surrogates cannot be printed`);return`"${e.replace(/[\\"\u0000-\u001f\u007f-\u009f]/g,e=>si[e]??`\\u${e.charCodeAt(0).toString(16).padStart(4,`0`)}`)}"`},li=e=>{switch(e.kind){case`string`:return ci(e.value);case`number`:return e.raw;case`boolean`:return String(e.value);case`duration`:return`${e.amount}${e.unit}`;case`timestamp`:return e.value}},ui=e=>e.kind===`number`&&e.raw.startsWith(`-`),di=e=>{switch(e.kind){case`member`:return e.path.join(`.`);case`call`:return`${e.name}(${e.args.map(fi).join(`, `)})`;case`binary`:if(e.right.kind===`binary`)throw Error(`Arithmetic is left-associative; a binary on the right cannot be printed`);return`${di(e.left)} ${e.op} ${di(e.right)}`;default:return li(e)}},fi=e=>mi(e)?`(${_i(e)})`:di(e),pi=[`member`,`string`,`number`,`boolean`,`duration`,`timestamp`,`binary`],mi=e=>!pi.includes(e.kind)&&e.kind!==`call`,hi=e=>{if(ui(e))throw Error(`A negative number cannot start a comparison; "-5 = x" parses as a negation`);return di(e)},gi=(e,t)=>({and:[`and`,`or`],sequence:[`and`,`or`,`sequence`],or:[`and`,`or`,`sequence`],not:[`and`,`or`,`sequence`,`not`]})[e].includes(t.kind)?`(${_i(t)})`:_i(t),_i=e=>{switch(e.kind){case`and`:return e.args.map(e=>gi(`and`,e)).join(` AND `);case`or`:return e.args.map(e=>gi(`or`,e)).join(` OR `);case`sequence`:return e.args.map(e=>gi(`sequence`,e)).join(` `);case`not`:return`NOT ${gi(`not`,e.arg)}`;case`compare`:return`${hi(e.left)} ${e.op} ${di(e.right)}`;case`has`:return`${hi(e.left)}:${di(e.right)}`;case`present`:return`${hi(e.left)}:*`;case`global`:return di(e.value);case`call`:return di(e)}},vi=class{int;scale;constructor(e,t){this.int=e,this.scale=t}compare(e){let t=Math.max(this.scale,e.scale),n=this.int*10n**BigInt(t-this.scale),r=e.int*10n**BigInt(t-e.scale);return n<r?-1:+(n>r)}toNumber(){return Number(`${this.int}e-${this.scale}`)}},yi=/^(-?)(\d+)(?:\.(\d+))?$/,bi=e=>{let t=yi.exec(e);if(!t)return;let n=t[3]??``;return new vi(BigInt(`${t[1]}${t[2]}${n}`),n.length)},xi=/^-?(?:\d+(?:\.\d+)?(?:[eE][+-]?\d+)?|0[xX][0-9a-fA-F]+)$/,Si=e=>{if(typeof e==`number`)return e;if(typeof e==`bigint`)return Number(e);if(e instanceof vi)return e.toNumber();if(typeof e==`string`&&xi.test(e))return e.startsWith(`-`)?-Number(e.slice(1)):Number(e)},Ci=e=>typeof e==`bigint`?new vi(e,0):typeof e==`number`?Number.isFinite(e)?bi(String(e)):void 0:typeof e==`string`?bi(e):e instanceof vi?e:void 0,wi=(e,t)=>{let n=0,r=0,i=-1,a=0;for(;r<t.length;)if(n<e.length&&e[n]===`*`)i=n++,a=r;else if(n<e.length&&e[n]===t[r])n++,r++;else if(i>=0)n=i+1,r=++a;else return!1;for(;e[n]===`*`;)n++;return n===e.length},Ti=e=>typeof e==`object`&&!!e&&!(e instanceof Date)&&!(e instanceof vi)&&`seconds`in e&&typeof e.seconds==`number`,pee=e=>{switch(e.kind){case`string`:return e.value;case`number`:return bi(e.raw)??e.value;case`boolean`:return e.value;case`duration`:return{seconds:e.amount*Un[e.unit]};case`timestamp`:return new Date(Wn(e.value)??NaN)}},Ei=e=>Ti(e)?e.seconds:typeof e==`number`?e:typeof e==`string`?Kn(e):void 0,Di=e=>e instanceof Date?e.getTime():typeof e==`string`?Wn(e):void 0,Oi=e=>{switch(e.kind){case`string`:return e.value;case`member`:return e.path.join(`.`);case`number`:return e.raw;case`boolean`:return String(e.value);case`duration`:return`${e.amount}${e.unit}`;case`timestamp`:return e.value;default:return}},ki=(e,t)=>{switch(e){case`=`:return t===0;case`!=`:return t!==0;case`<`:return t<0;case`<=`:return t<=0;case`>`:return t>0;case`>=`:return t>=0}},Ai=(e,t)=>e<t?-1:+(e>t),ji=(e,t)=>{let n=Ci(e),r=Ci(t);if(n&&r)return n.compare(r);let i=Si(e),a=Si(t);return i===void 0||a===void 0||Number.isNaN(i)||Number.isNaN(a)?void 0:Ai(i,a)},mee=(e,t,n)=>{let r=(e===`=`||e===`!=`)&&n.includes(`*`);if(typeof t==`string`)return r?ki(e,+!wi(n,t)):ki(e,Ai(t,n));if(typeof t==`number`||typeof t==`bigint`){let r=ji(t,n);return r===void 0?void 0:ki(e,r)}if(t instanceof Date){let r=Di(n);return r===void 0?void 0:ki(e,Ai(t.getTime(),r))}if(typeof t==`boolean`)return n===`true`||n===`false`?ki(e,Ai(String(t),n)):void 0;if(Ti(t)){let r=Ei(n);return r===void 0?void 0:ki(e,Ai(t.seconds,r))}},Mi=(e,t,n)=>{if(t==null)return!1;if(typeof n==`string`)return mee(e,t,n)??!1;if(n instanceof vi||typeof n==`number`||typeof n==`bigint`){let r=ji(t,n);return r!==void 0&&ki(e,r)}if(typeof n==`boolean`){let r=typeof t==`string`?t===`true`||t!==`false`&&void 0:t;return typeof r==`boolean`&&ki(e,Ai(String(r),String(n)))}if(n instanceof Date){let r=Di(t);return r===void 0||Number.isNaN(n.getTime())?!1:ki(e,Ai(r,n.getTime()))}if(Ti(n)){let r=Ei(t);return r!==void 0&&ki(e,Ai(r,n.seconds))}return!1},Ni=(e,t)=>{let n=[e];for(let e of t)n=n.flatMap(t=>Array.isArray(t)?t.flatMap(t=>Pi(t,e)):Pi(t,e));return n.filter(e=>e!=null)},Pi=(e,t)=>typeof e!=`object`||!e?[]:e instanceof Map?e.has(t)?[e.get(t)]:[]:Object.hasOwn(e,t)?[e[t]]:[],Fi=e=>e.flatMap(e=>Array.isArray(e)?e:[e]),hee=32,Ii=(e,t)=>t>hee||e==null?[]:typeof e==`string`?[e]:typeof e==`number`||typeof e==`boolean`||typeof e==`bigint`?[String(e)]:e instanceof Date?[e.toISOString()]:Array.isArray(e)?e.flatMap(e=>Ii(e,t+1)):e instanceof Map?[...e.values()].flatMap(e=>Ii(e,t+1)):typeof e==`object`?Object.values(e).flatMap(e=>Ii(e,t+1)):[],Li=(e,t)=>{let n=e.toLowerCase();return Ii(t,0).some(e=>e.toLowerCase().includes(n))},Ri=e=>[`member`,`string`,`number`,`boolean`,`duration`,`timestamp`,`call`,`binary`].includes(e.kind),zi=(e,t,n)=>{let r=e===`+`?1:-1;if(t instanceof Date&&Ti(n))return new Date(t.getTime()+r*n.seconds*1e3);if(t instanceof Date&&n instanceof Date&&e===`-`)return{seconds:(t.getTime()-n.getTime())/1e3};if(Ti(t)&&Ti(n))return{seconds:t.seconds+r*n.seconds};let i=t instanceof vi?t.toNumber():t,a=n instanceof vi?n.toNumber():n;return typeof i==`number`&&typeof a==`number`?i+r*a:void 0},Bi=(e,t)=>{let n=t.options.functions?.[e.name];if(!n?.evaluate)throw Error(`Function "${e.name}" has no evaluate implementation`);let r=e.args.map((e,r)=>{let i=n.params[r]??n.rest;return e.kind===`member`&&i?.type===`field`?Fi(Ni(t.record,e.path)):Ri(e)?Vi(e,t):Ki(e,t)});return n.evaluate(...r)},Vi=(e,t)=>{switch(e.kind){case`member`:return e.path.join(`.`);case`call`:return Bi(e,t);case`binary`:return zi(e.op,Vi(e.left,t),Vi(e.right,t));default:return pee(e)}},Hi=(e,t)=>e.kind===`member`?Ni(t.record,e.path):[Vi(e,t)],Ui=(e,t,n)=>Fi(t).some(t=>Mi(e,t,n)),Wi=(e,t)=>{let n=e.kind===`member`?e.field?.spec.type:void 0;return typeof t!=`string`||!n?t:n===`timestamp`?Di(t)===void 0?t:new Date(Di(t)):n===`duration`?Ei(t)===void 0?t:{seconds:Ei(t)}:n===`integer`||n===`number`?Ci(t)??t:n===`boolean`?t===`true`||t!==`false`&&t:t},Gi=(e,t)=>{let n=Wi(e.left,Vi(e.right,t)),r=Hi(e.left,t);return e.op===`!=`?!Ui(`=`,r,n):Ui(e.op,r,n)},gee=(e,t)=>{let n=Vi(e.right,t),r=Oi(e.right);return Hi(e.left,t).some(e=>Array.isArray(e)?e.some(e=>Mi(`=`,e,n)):e instanceof Map?r!==void 0&&e.has(r):typeof e==`object`&&e&&!(e instanceof Date)&&!Ti(e)&&!(e instanceof vi)?r!==void 0&&Object.hasOwn(e,r):Mi(`=`,e,n))},Ki=(e,t)=>{switch(e.kind){case`sequence`:case`and`:return e.args.every(e=>Ki(e,t));case`or`:return e.args.some(e=>Ki(e,t));case`not`:return!Ki(e.arg,t);case`compare`:return Gi(e,t);case`has`:return gee(e,t);case`present`:return Hi(e.left,t).some(e=>e!=null);case`global`:return(t.options.search??Li)(Oi(e.value)??String(Vi(e.value,t)),t.record);case`call`:return Bi(e,t)===!0}},_ee=(e,t,n={})=>Ki(e,{record:t,options:n}),qi=(e,t,n,r)=>({code:e,message:t,hint:n,span:r}),vee=(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]},Ji=(e,t)=>{let n=e.toLowerCase(),r=t.map(e=>({candidate:e,score:vee(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},Yi={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`}},Xi={extensions:{arithmetic:`now-offset`,durationUnits:!0}},Zi=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`}},Qi=e=>({fields:Object.fromEntries(Object.values(e.fields).map(e=>[e.name,{type:Zi(e),filterable:e.filterable,sortable:e.sortable,aliases:e.aliases,...e.enumValues&&{values:e.enumValues}}])),functions:Yi}),$i=(e,t,n,r)=>{e.errors.push(qi(`unsupported`,t,n,r))},ea=(e,t)=>t.kind===`member`?{kind:`field`,path:t.path,span:t.span}:$i(e,`Only fields can be compared`,`Put a field name on the left, for example total > 100`,t.span),yee=(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}:$i(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}:$i(e,`Arithmetic is only supported as now() +/- duration`,`Write now() - 30d`,t.span)}default:return t}},ta=(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}:$i(e,`Expected a literal value`,`Use strings, numbers, true/false, durations or timestamps`,t.span)),na=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``}},ra=(e,t)=>{let[n,r,...i]=t.args,a=n?.kind===`member`?ea(e,n):void 0,o=e=>e?.kind===`string`?e.value:void 0,s=n=>{e.errors.push(qi(`invalid-arguments`,`Invalid arguments to ${t.name}()`,`Usage: ${n}`,t.span))};switch(t.name){case`in`:{let n=t.args.slice(1).map(t=>ta(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(qi(`unknown-function`,`Unknown function "${t.name}"`,`Available functions: ${Object.keys(Yi).join(`, `)}`,t.span));return}},ia=e=>e.every(e=>e)?e:void 0,aa=(e,t)=>{switch(t.kind){case`sequence`:case`and`:case`or`:{let n=ia(t.args.map(t=>aa(e,t)));return n&&{kind:t.kind===`or`?`or`:`and`,args:n,span:t.span}}case`not`:{let n=aa(e,t.arg);return n&&{kind:`not`,arg:n,span:t.span}}case`compare`:{let n=ea(e,t.left),r=yee(e,t.right);return n&&r&&{kind:`compare`,op:t.op,field:n,value:r,span:t.span}}case`has`:{let n=ea(e,t.left),r=ta(e,t.right);return n&&r&&{kind:`has`,field:n,value:r,span:t.span}}case`present`:{let n=ea(e,t.left);return n&&{kind:`present`,field:n,span:t.span}}case`global`:return{kind:`search`,text:na(t.value),span:t.span};case`call`:return ra(e,t)}},oa=(e,t={})=>{let n=Rr(e,{...Xi,...t}),r={errors:[]},i=n.ast&&aa(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}},sa=(e,t)=>t===2?e%4==0&&(e%100!=0||e%400==0)?29:28:[4,6,9,11].includes(t)?30:31,ca=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<=sa(n,r)},la=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 ca(t[1])&&n<=23&&r<=59&&i<=59&&a<=23&&o<=59},ua=(e,t)=>({message:e,hint:t}),da=-(2n**63n),fa=2n**63n-1n,pa=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,ma=e=>e.kind===`number`?e.raw:e.kind===`string`?e.value:void 0,ha=(e,t=`Write ${e} values like the examples in the docs`)=>ua(`Expected ${e}`,t),ga=e=>{let t=ma(e),n=t===void 0?NaN:Number(t);if(t===void 0||t.trim()===``||!Number.isSafeInteger(n))return ha(`a whole number`,`Use an integer such as 42, or a bigint field for larger values`)},_a=e=>{let t=ma(e);if(t===void 0||!/^-?\d+$/.test(t)||BigInt(t)<da||BigInt(t)>fa)return ha(`a 64-bit integer`,`Use plain digits such as 9007199254740993 (no exponent or fraction)`)},va=e=>{let t=ma(e);if(t===void 0||!/^-?\d+(\.\d+)?$/.test(t))return ha(`a decimal number`,`Use plain digits such as 100.50, or quote it: "100.50" (no exponent)`)},ya=(e,t)=>{if(t.kind===`now`)return e.type===`date`||e.type===`timestamp`?void 0:ua(`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:ha(`a quoted string`,`Wrap the text in double quotes`);case`integer`:return ga(t);case`bigint`:return _a(t);case`decimal`:return va(t);case`boolean`:return t.kind===`boolean`?void 0:ha(`true or false`);case`date`:return t.kind===`string`&&ca(t.value)?void 0:ha(`a date`,`Quote a calendar date: "2012-04-21"`);case`timestamp`:return t.kind===`timestamp`||t.kind===`string`&&la(t.value)?void 0:ha(`an RFC-3339 timestamp`,`Use 2012-04-21T11:30:00Z, or now() - 7d`);case`uuid`:return t.kind===`string`&&pa.test(t.value)?void 0:ha(`a uuid`,`Quote a uuid like "0b5a4f0e-6f2a-4a3c-9d4e-1f2a3b4c5d6e"`);case`enum`:return t.kind===`string`&&e.enumValues?.includes(t.value)?void 0:ua(`Invalid enum value`,`Allowed values: ${(e.enumValues??[]).join(`, `)}`);case`currency`:return t.kind===`string`&&/^[A-Z]{3}$/.test(t.value)?void 0:ha(`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:ha(`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:ha(`a record key`,`Use the related record key: 42 or "abc"`);case`json`:case`file`:return ua(`${e.type} fields cannot be compared`,`Use field:value on json fields, or isNull(field)`)}},ba=(e,t)=>Object.hasOwn(e.fields,t)?e.fields[t]:Object.values(e.fields).find(e=>e.aliases.includes(t)),xa=(e,t,n)=>{if(t.path.length>1){e.errors.push(qi(`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=ba(e.model,r);if(!i){let i=Object.values(e.model.fields).filter(e=>e[n]).map(e=>e.name),a=Ji(r,i);e.errors.push(qi(`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(qi(n===`filterable`?`not-filterable`:`not-sortable`,`Field "${i.name}" is not ${r}`,`Mark it with .${r}() in data.ts`,t.span));return}return i},Sa=[`=`,`!=`],Ca=[`=`,`!=`,`<`,`<=`,`>`,`>=`],wa=e=>{switch(e){case`text`:case`integer`:case`bigint`:case`decimal`:case`date`:case`timestamp`:return Ca;case`json`:case`file`:return[];default:return Sa}},Ta=e=>e===`json`||e===`file`,Ea=(e,t,n)=>{let r=ya(t,n);return r&&e.errors.push(qi(`invalid-value`,r.message,r.hint,n.span)),!r},Da=(e,t,n,r)=>{e.errors.push(qi(`operator-not-allowed`,t,n,r))},Oa=(e,t)=>(e===`=`||e===`!=`)&&t.kind===`string`&&t.value.includes(`*`),ka=(e,t)=>{let n=xa(e,t.field,`filterable`);if(!n)return;let r=wa(n.type);if(!r.includes(t.op)){Da(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(Oa(t.op,t.value)&&n.type!==`text`){e.errors.push(qi(`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(Oa(t.op,t.value)||Ea(e,n,t.value))return{...t,field:n}},Aa=(e,t)=>{let n=xa(e,t.field,`filterable`);if(n){if(n.type!==`json`){Da(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}}},ja=(e,t)=>{let n=xa(e,t.field,`filterable`);if(n){if(Ta(n.type)){Da(e,`in() is not supported for ${n.type} fields`,`Use field:value on json fields`,t.span);return}return t.values.map(t=>Ea(e,n,t)).every(Boolean)?{...t,field:n}:void 0}},Ma=(e,t,n)=>{let r=xa(e,n,`filterable`);if(r&&r.type!==`text`){Da(e,`${t}() only works on text fields, not ${r.type}`,`Field "${r.name}" is ${r.type}`,n.span);return}return r},Na=(e,t)=>{switch(t.kind){case`and`:case`or`:{let n=t.args.map(t=>Na(e,t));return n.every(e=>e)?{...t,args:n}:void 0}case`not`:{let n=Na(e,t.arg);return n&&{...t,arg:n}}case`compare`:return ka(e,t);case`has`:return Aa(e,t);case`in`:return ja(e,t);case`search`:if(e.model.search?.length)return t;e.errors.push(qi(`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=xa(e,t.field,`filterable`);return n&&{...t,field:n}}case`similar`:case`regex`:{let n=Ma(e,t.kind,t.field);return n&&{...t,field:n}}}},Pa=(e,t)=>{let n={model:e,errors:[]},r=Na(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}},Fa=(e,t)=>`path`in e?{kind:`member`,path:e.path,span:e.span}:{kind:`member`,path:[e.name],field:{name:e.name,spec:{type:Zi(e)}},span:t},Ia=(e,t,n)=>({kind:`call`,name:e,args:t,span:n}),La=(e,t)=>({kind:`string`,value:e,span:t}),Ra=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},za=(e,t={})=>{let n=e=>za(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:Fa(e.field,e.span),right:Ra(e.value),span:e.span};case`has`:return{kind:`has`,left:Fa(e.field,e.span),right:e.value,span:e.span};case`present`:return{kind:`present`,left:Fa(e.field,e.span),span:e.span};case`in`:return t.expand?{kind:`or`,args:e.values.map(t=>({kind:`compare`,op:`=`,left:Fa(e.field,e.span),right:t,span:e.span})),span:e.span}:Ia(`in`,[Fa(e.field,e.span),...e.values],e.span);case`search`:return Ia(`search`,[La(e.text,e.span)],e.span);case`similar`:return Ia(`similar`,[Fa(e.field,e.span),La(e.text,e.span)],e.span);case`regex`:return Ia(`regex`,[Fa(e.field,e.span),La(e.pattern,e.span)],e.span);case`isNull`:return t.expand?{kind:`not`,arg:{kind:`present`,left:Fa(e.field,e.span),span:e.span},span:e.span}:Ia(`isNull`,[Fa(e.field,e.span)],e.span)}},Ba=(e,t)=>{let n=Pa(e,t);if(!n.ok&&n.errors.some(e=>e.code===`unsupported-traversal`))return n;let r=oi(za(t),Qi(e));return r.ok?Pa(e,t):{ok:!1,errors:r.errors}},Va=/^[\d\s+\-().\/]+$/,Ha=e=>Va.test(e)?e.replace(/\D/g,``):``,Ua=e=>{let t=e.split(/\s+/).filter(Boolean).map(e=>({text:e,digits:Ha(e),whole:!1})),n=t.length>1?Ha(e.trim()):``;return n?[{text:e.trim(),digits:n,whole:!0},...t]:t},Wa=(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()),Ga=(e,t,n)=>(e.search??[]).filter(r=>Wa(t[r],n,e.searchMatch?.[r])),Ka=(e,t,n,r)=>{for(let i of Ua(n)){let n=Ga(e,t,i);if(n.length>0&&!n.some(e=>r.includes(e)))return n[0]}},qa=e=>_i(za(e)),Ja=e=>{let t=[];for(let n of e.matchAll(/,|\.|[^\s,.]+/g)){let e=n.index,r=n[0]===`,`?`comma`:n[0]===`.`?`dot`:`word`;t.push({kind:r,text:n[0],span:{start:e,end:e+n[0].length}})}return t},Ya=e=>{let t=Ja(e),n=[],r=[],i={start:e.length,end:e.length},a=0,o=(e,t,r,i)=>n.push(Rn(e,t,r,i)),s=()=>{for(;a<t.length&&t[a].kind!==`comma`;)a++;a++},c=()=>{let e=t[a];if(!e||e.kind!==`word`)return o(`expected-field`,`Expected a field name but found ${e?`"${e.text}"`:`end of input`}`,`Write order_by like: createdAt desc, total`,e?.span??i),!1;let n=[e.text],s=e;for(a++;t[a]?.kind===`dot`;){let e=t[a+1];if(e?.kind!==`word`)return o(`expected-field`,`Expected a field name after "."`,`Write subfields like address.street`,e?.span??i),!1;n.push(e.text),s=e,a+=2}let c=t[a],l=`asc`;if(c?.kind===`word`){if(c.text!==`asc`&&c.text!==`desc`)return o(`unexpected-token`,`Expected "desc" or "," but found "${c.text}"`,`Separate fields with commas; append " desc" for descending order`,c.span),!1;l=c.text,s=c,a++}let u=t[a];return u&&u.kind!==`comma`?(o(`unexpected-token`,`Expected "," but found "${u.text}"`,`Separate fields with commas`,u.span),!1):(r.push({path:n,direction:l,span:{start:e.span.start,end:s.span.end}}),!0)};for(;a<t.length;){if(!c()){s();continue}t[a]?.kind===`comma`&&(a++,a>=t.length&&o(`expected-field`,`Expected a field name after ","`,`Remove the trailing comma`,i))}return n.length===0?{ok:!0,items:r,errors:[]}:{ok:!1,items:r,errors:n}},Xa=(e,t)=>{if(Object.hasOwn(e,t))return{name:t,field:e[t]};let n=Object.entries(e).find(([,e])=>e.aliases?.includes(t));return n&&{name:n[0],field:n[1]}},Za=(e,t)=>{let n=[],r=[];for(let i of e){let e=Xa(t.fields,i.path[0]);if(!e){let e=Object.entries(t.fields).filter(([,e])=>e.sortable!==!1).map(([e])=>e),r=zn(i.path[0],e);n.push(Rn(`unknown-field`,`Unknown field "${i.path[0]}"`,r?`Did you mean "${r}"?`:`Available fields: ${e.join(`, `)}`,i.span));continue}let a=[e.name],o=e.field,s=o.sortable!==!1,c=!1;for(let e of i.path.slice(1)){let t=o.fields?Xa(o.fields,e)?.field:o.value;if(!t){n.push(Rn(`invalid-traversal`,`Cannot sort by "${e}" inside "${a.join(`.`)}"`,`Only nested message fields and map values can be traversed`,i.span)),c=!0;break}a.push(o.fields?Xa(o.fields,e).name:e),o=t,s&&=o.sortable!==!1}if(!c){if(!s){n.push(Rn(`not-sortable`,`Field "${a.join(`.`)}" cannot be sorted on`,`Mark it sortable in the schema`,i.span));continue}r.push({...i,path:a})}}return n.length===0?{ok:!0,items:r}:{ok:!1,errors:n}},Qa=e=>e.map(e=>({path:e.path.path,direction:e.direction,span:e.span})),$a=e=>e.replace(/([^\s,])(\s+)(asc|desc)(?=\s|,|$)/gi,(e,t,n,r)=>`${t}${n}${r.toLowerCase()}`),bee=e=>{let t=Ya($a(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}},eo=(e,t)=>{let n=t.filter(e=>e.path.path.length>1).map(e=>qi(`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=Za(Qa(t),Qi(e));return r.ok?{ok:!0,sort:r.items.map(e=>[e.path[0],e.direction])}:{ok:!1,errors:r.errors}},to=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}}},no={start:0,end:0},ro=e=>({kind:`field`,path:e.split(`.`),span:no}),io=e=>{if(typeof e==`string`)return{kind:`string`,value:e,span:no};if(typeof e==`boolean`)return{kind:`boolean`,value:e,span:no};if(!Number.isFinite(e))throw Error(`Filter numbers must be finite`);return{kind:`number`,value:e,raw:String(e),span:no}},ao=e=>typeof e==`object`?e:io(e),oo=(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:no}},so=()=>{let e=e=>(t,n)=>({kind:`compare`,op:e,field:ro(t),value:ao(n),span:no}),t=e=>t=>({kind:`now`,offset:{sign:e,duration:to(t)},span:no});return{eq:e(`=`),ne:e(`!=`),lt:e(`<`),lte:e(`<=`),gt:e(`>`),gte:e(`>=`),between:(t,n,r)=>oo(`and`,[e(`>=`)(t,n),e(`<=`)(t,r)]),has:(e,t)=>({kind:`has`,field:ro(e),value:io(t),span:no}),present:e=>({kind:`present`,field:ro(e),span:no}),in:(e,t)=>({kind:`in`,field:ro(e),values:t.map(io),span:no}),isNull:e=>({kind:`isNull`,field:ro(e),span:no}),search:e=>({kind:`search`,text:e,span:no}),similar:(e,t)=>({kind:`similar`,field:ro(e),text:t,span:no}),regex:(e,t)=>({kind:`regex`,field:ro(e),pattern:t,span:no}),and:(...e)=>oo(`and`,e),or:(...e)=>oo(`or`,e),not:e=>({kind:`not`,arg:e,span:no}),now:()=>({kind:`now`,span:no}),ago:t(`-`),fromNow:t(`+`)}};so();var xee=e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&Object.keys(e).length===1&&typeof e.$field==`string`,See=e=>typeof e==`object`&&!!e&&!Array.isArray(e),co=e=>xee(e)?e.$field:Array.isArray(e)?e.map(co):See(e)?Object.fromEntries(Object.entries(e).map(([e,t])=>[e,co(t)])):e,Cee=`table`,lo=/\{([A-Za-z_][A-Za-z0-9_]*)\}/g,wee=e=>[...e.matchAll(lo)].map(e=>e[1]),Tee=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??{}):[],uo=e=>[...new Set(Tee(e).flatMap(wee))],fo=(e,t)=>e.replace(lo,(e,n)=>t[n]===null||t[n]===void 0?``:String(t[n])),po=(e,t={})=>{if(e.kind===`record`){let n=e=>typeof e==`string`?fo(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,fo(n,t)]))}:e:e.kind===`list`?{...e,...e.filter!==void 0&&{filter:fo(e.filter,t)},...e.orderBy!==void 0&&{orderBy:fo(e.orderBy,t)}}:e},Eee=e=>/^\{([A-Za-z_][A-Za-z0-9_]*)\}$/.exec(e)?.[1],mo=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(`,`)},Dee=/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/,ho=e=>{let t=Dee.exec(e);return t?[Number(t[1]),Number(t[2]),Number(t[3])]:void 0},go=(e,t)=>e[0]-t[0]||e[1]-t[1]||e[2]-t[2],_o=/^(>=|<=|>|<|=)?(.+)$/,vo={">=":e=>e>=0,"<=":e=>e<=0,">":e=>e>0,"<":e=>e<0,"=":e=>e===0},yo=(e,t)=>{let n=ho(e),r=t.trim().split(/\s+/);if(!n||t.trim()===``)return;let i=!0;for(let e of r){let[,t=`=`,r=``]=_o.exec(e)??[],a=ho(r);if(!a)return;i&&=vo[t](go(n,a))}return i},bo=(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=yo(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}`},xo=`[Filtered]`,So=/authorization|cookie|passw|secret|token|api[-_]?key|credential|session|csrf|signature|^sig$/i,Co=new Set([`url`,`query_string`,`from`,`to`]),wo=12,To=e=>e.replace(/(^|&)([^=&]*)=([^&]*)/g,(e,t,n)=>So.test(n)?`${t}${n}=${xo}`:e),Eo=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)}${To(r)}${n===-1?``:e.slice(n)}`},Do=(e,t,n)=>So.test(e)?xo:typeof t==`string`&&Co.has(e)?e===`query_string`?To(t):Eo(t):Oo(t,n+1),Oo=(e,t)=>t>wo||typeof e!=`object`||!e?e:Array.isArray(e)?e.map(e=>Array.isArray(e)&&e.length===2&&typeof e[0]==`string`?[e[0],Do(e[0],e[1],t)]:Oo(e,t+1)):Object.fromEntries(Object.entries(e).map(([e,n])=>[e,Do(e,n,t)])),ko=e=>Oo(e,0),Ao=[`unknown-field`,`not-filterable`,`not-sortable`,`unsupported-traversal`,`invalid-traversal`],jo=e=>e.replace(/(["']?)\{[A-Za-z_][A-Za-z0-9_]*\}\1/g,(e,t)=>t?`${t}x${t}`:`0`),Mo=(e,t)=>{let n=oa(jo(t));if(!n.ok)return n.errors.map(e=>`filter: ${e.message}`);if(!n.ast)return[];let r=Ba(e,n.ast);return r.ok?[]:r.errors.filter(e=>Ao.includes(e.code)).map(e=>`filter: ${e.message}`)},No=(e,t)=>{if(uo({kind:`list`,resource:e.name,orderBy:t}).length>0)return[];let n=bee(t);if(!n.ok)return n.errors.map(e=>`orderBy: ${e.message}`);let r=eo(e,n.items);return r.ok?[]:r.errors.map(e=>`orderBy: ${e.message}`)},Po=(e,{models:t,pages:n,source:r})=>{let i=uo(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,...Object.keys(e.values??{}).filter(e=>!Object.hasOwn(n.fields,e)).map(t=>`values: unknown field "${t}" on ${e.resource}`)]:e.kind===`list`?[...i,...e.filter?Mo(n,e.filter):[],...e.orderBy?No(n,e.orderBy):[]]:i:[`unknown resource "${e.resource}"`]}default:return[`an address's kind is list, record, create or page, not "${String(e.kind)}"`]}},Fo={messages:[],replying:!1},Io=(e,t)=>{let n=e.findIndex(e=>e.id===t.id);return n===-1?[...e,t]:e.map((e,r)=>r===n?t:e)},Lo=(e,t,n)=>{let r=e.find(e=>e.id===t);return Io(e,r?{...r,parts:Io(r.parts,n)}:{id:t,from:`assistant`,parts:[n]})},Ro=(e,t)=>{switch(t.type){case`state`:return t.state;case`message`:return{...e,messages:Io(e.messages,t.message)};case`part`:return{...e,messages:Lo(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}}}}},zo=async(e,t,n)=>{let r=new TextDecoder,i=e.getReader();n?.addEventListener(`abort`,()=>void i.cancel(),{once:!0});let a=``,o=[],s=e=>{if(e===``){o.length>0&&t(o.join(`
4
4
  `)),o=[];return}e.startsWith(`data:`)&&o.push(e.slice(e.startsWith(`data: `)?6:5))};for(;;){let{done:e,value:t}=await i.read();a+=e?r.decode():r.decode(t,{stream:!0});let n=a.split(/\r\n|\r|\n/);if(a=e?``:n.pop()??``,n.forEach(s),e)return s(``)}},Bo=(e,t)=>t?.[e]??e,Vo={filter:`filter`,orderBy:`order_by`,display:`display`,filterLayout:`layout`,map:`map`,savedSearch:`saved_search`,create:`new`},Ho=[`display`,`filter`,`orderBy`,`filterLayout`,`savedSearch`],Uo=e=>`${e.latitude.toFixed(5)},${e.longitude.toFixed(5)},${e.zoom.toFixed(2)}`,Wo=(e,t,n=-t)=>Number.isFinite(e)&&e>=n&&e<=t,Go=e=>{let t=e?.split(`,`);if(t?.length!==3||t.some(e=>e.trim()===``))return;let[n,r,i]=t.map(Number);return Wo(n,90)&&Wo(r,180)&&Wo(i,22,0)?{latitude:n,longitude:r,zoom:i}:void 0},Ko=e=>{let t=new URLSearchParams;for(let n of Ho){let r=e[n];r!==void 0&&r!==``&&t.set(Vo[n],r)}e.map&&t.set(Vo.map,Uo(e.map));let n=t.toString();return n?`?${n}`:``},qo=(e,t=``)=>{switch(e.kind){case`page`:return`${t}/${encodeURIComponent(e.page)}`;case`create`:return`${t}/${encodeURIComponent(e.resource)}/${Vo.create}${Yo(e.values)}`;case`record`:return`${t}/${encodeURIComponent(e.resource)}/${encodeURIComponent(mo(e.key))}`;case`list`:return`${t}/${encodeURIComponent(e.resource)}${Ko(e)}`}},Jo=e=>{try{return e.split(`/`).filter(Boolean).map(decodeURIComponent)}catch(e){if(e instanceof URIError)return;throw e}},Yo=(e={})=>{let t=new URLSearchParams(Object.entries(e).filter(([,e])=>e!==``)).toString();return t?`?${t}`:``},Xo=e=>e===`bar`||e===`panel`?e:void 0,Zo=(e,t)=>{let n=new URL(e,`http://app`),r=Jo(n.pathname);if(!r||r.length===0||r.length>2)return;let[i,a]=r;if(i===`-`)return;if(t.has(i))return a===void 0?{kind:`page`,page:i}:void 0;if(a===Vo.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)return{kind:`record`,resource:i,key:a};let o=n.searchParams,s=o.get(Vo.display)||void 0,c=o.get(Vo.filter)||void 0,l=o.get(Vo.orderBy)||void 0,u=Xo(o.get(Vo.filterLayout)),d=Go(o.get(Vo.map)),f=o.get(Vo.savedSearch)||void 0;return{kind:`list`,resource:i,...s&&{display:s},...c&&{filter:c},...l&&{orderBy:l},...u&&{filterLayout:u},...d&&{map:d},...f&&{savedSearch:f}}},Qo=`/-/sign-in`,$o={step:`step`,next:`next`},es=[`sign-in`,`forgot-password`,`email-code`,`sign-up`,`sign-up-code`,`sign-up-details`],ts=e=>es.includes(e),ns=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}`},rs=({step:e=`sign-in`,next:t}={})=>{let n=new URLSearchParams;e!==`sign-in`&&n.set($o.step,e);let r=ns(t);r&&r!==`/`&&n.set($o.next,r);let i=n.toString();return i?`${Qo}?${i}`:Qo},is=(e,t)=>{if(e!==`/-/sign-in`)return;let n=t.get($o.step),r=ns(t.get($o.next));return{step:ts(n)?n:`sign-in`,...r&&{next:r}}},as=e=>typeof e==`string`?e:e&&qa(e),os=e=>{let t=Object.entries(e??{}).map(([e,t])=>`${e}.${t}`);return t.length>0?t:void 0},ss=e=>({photos:e&&`${e.resource}.${e.field}.${e.image}`,photos_order_by:e?.sort}),cs=(e={})=>({filter:as(e.filter)||void 0,order_by:e.orderBy,page_size:e.pageSize,page_token:e.pageToken||void 0,fields:e.fields?.join(`,`),labels:os(e.labels)?.join(`,`),...ss(e.photos),count:e.count}),ls=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}`:``},us=e=>e.startsWith(`/`)&&!e.startsWith(`//`),ds=e=>{if(typeof e!=`object`||!e)return!1;let{uri:t,url:n}=e;return typeof t==`string`&&typeof n==`string`&&us(n)},fs=e=>e!==void 0&&URL.canParse(e)?new URL(e).origin:void 0,ps=(e,t)=>({...e,url:`${t}${e.url}`,...e.variants&&{variants:Object.fromEntries(Object.entries(e.variants).map(([e,n])=>[e,us(n.url)?{...n,url:`${t}${n.url}`}:n]))}}),ms=(e,t)=>t===void 0||typeof e!=`object`||!e?e:Object.fromEntries(Object.entries(e).map(([e,n])=>[e,ds(n)?ps(n,t):n])),hs=(e,t)=>t===void 0?e:Object.fromEntries(Object.entries(e).map(([e,n])=>[e,n.map(e=>ds(e)?ps(e,t):e)])),gs=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 errors(){return this.problem.errors??[]}get filterErrors(){return this.slug===`invalid-filter`?this.errors:[]}},_s=class extends gs{constructor(e){super(e),this.name=`PreconditionFailedError`}},vs=e=>e instanceof gs,ys=e=>typeof e==`object`&&!!e&&`type`in e&&`status`in e,bs=async e=>{let t=e.headers.get(`content-type`)?.includes(`json`)??!1?await e.json():void 0,n=ys(t)?t:{type:`urn:protobase:problem:unknown`,title:e.statusText||`Request failed`,status:e.status};return n.status===412?new _s(n):new gs(n)},xs=(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 bs(h);return h}},Ss=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()]})),Cs=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:Ss(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)}),ws=e=>typeof e==`string`?e:e.toModel().name,Ts=(e,t)=>`/${ws(e)}/${mo(t)}`,Es=(e,t,n)=>({items:e.items.map(e=>ms(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:hs(e.photos,n)},...t.headers.get(`x-protobase-warning`)&&{warning:t.headers.get(`x-protobase-warning`)}}),Ds=e=>e.headers.get(`etag`)??``,Os=async(e,t)=>{let{permissions:n,...r}=await e.json();return{record:ms(r,t),etag:Ds(e),...n&&{permissions:n}}},ks=(e,t)=>({results:(e.results??[]).map(e=>e.op===`create`||e.op===`update`?{...e,record:ms(e.record,t)}:e.op===`reorder`?{...e,records:e.records.map(e=>({...e,record:ms(e.record,t)}))}:e)}),As=(e={})=>{let t=xs(e),n=fs(e.baseUrl);return{list:async(e,r)=>{let i=await t({method:`GET`,path:`/${ws(e)}`,query:ls(cs(r))});return Es(await i.json(),i,n)},search:async(e,r)=>{let i=cs(r),a=await t({method:`POST`,path:`/${ws(e)}:search`,body:{...i,fields:r?.fields,labels:os(r?.labels)}});return Es(await a.json(),a,n)},get:async(e,r)=>Os(await t({method:`GET`,path:Ts(e,r)}),n),create:async(e,r)=>{let i=await t({method:`POST`,path:`/${ws(e)}`,body:r});return{record:ms(await i.json(),n),etag:Ds(i),location:i.headers.get(`location`)??``}},update:async(e,r,i,a)=>Os(await t({method:`PATCH`,path:Ts(e,r),body:i,headers:{"if-match":a}}),n),remove:async(e,n,{etag:r}={})=>{await t({method:`DELETE`,path:Ts(e,n),headers:r?{"if-match":r}:void 0})},undelete:async(e,r)=>{let i=await t({method:`POST`,path:`${Ts(e,r)}:undelete`});return{record:ms(await i.json(),n),etag:Ds(i)}},reveal:async(e,n,r)=>(await(await t({method:`POST`,path:`${Ts(e,n)}:reveal`,body:{field:r}})).json()).value,batchWrite:async e=>{let r=e=>typeof e==`object`&&e&&`$ref`in e?e:mo(e),i=e.map(e=>({...e,resource:ws(e.resource),...`key`in e&&{key:r(e.key)},...e.op===`reorder`&&{keys:e.keys.map(r)}}));return ks(await(await t({method:`POST`,path:`:batchWrite`,body:{ops:i}})).json(),n)},facets:async(e,n,r={})=>(await(await t({method:`GET`,path:`/${ws(e)}:facets`,query:ls({field:n,filter:as(r.filter)||void 0,limit:r.limit,label:r.label})})).json()).facets,series:async(e,n)=>{let r=await(await t({method:`GET`,path:`/${ws(e)}:series`,query:ls({field:n.field,range:n.range,from:n.from,to:n.to,granularity:n.granularity,time_zone:n.timeZone,filter:as(n.filter)||void 0})})).json();return{field:r.field,granularity:r.granularity,timeZone:r.time_zone,points:r.points}},histogram:async(e,n,r={})=>(await t({method:`GET`,path:`/${ws(e)}:histogram`,query:ls({field:n,buckets:r.buckets,filter:as(r.filter)||void 0})})).json(),map:async(e,r)=>{let i=await(await t({method:`GET`,path:`/${ws(e)}:map`,query:ls({latitude:r.latitude,longitude:r.longitude,zoom:r.zoom,filter:as(r.filter)||void 0,order_by:r.orderBy,fields:r.fields?.join(`,`),labels:os(r.labels)?.join(`,`),...ss(r.photos)})})).json();return{items:i.items.map(e=>ms(e,n)),buckets:i.buckets,totalSize:i.total_size,...i.labels!==void 0&&{labels:i.labels},...i.photos!==void 0&&{photos:hs(i.photos,n)}}},seek:async(e,r)=>{let i=await t({method:`GET`,path:`/${ws(e)}:seek`,query:ls({...cs(r),position:r.position})});return Es(await i.json(),i,n)},meta: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:Ds(r)}},invoke:async(e,{method:n,body:r,path:i=``,query:a,headers:o}={})=>{let s=await t({method:n??(r===void 0?`GET`:`POST`),path:`/functions/${encodeURIComponent(e)}${i}`,query:a?`?${new URLSearchParams(a)}`:``,body:r,headers:o,system:!0});if(s.status!==204)return s.headers.get(`content-type`)?.includes(`json`)?s.json():s.text()},upload: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`?Cs(i):void 0,c=await(await t({method:`POST`,path:`/${ws(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}}},js=e=>typeof e==`string`?e:e.toModel().name,Ms=(e,t)=>{let n=n=>t(js(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),reveal:(e,t,r)=>n(e).reveal(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=>js(e.resource)))].join(`, `)}, which different APIs serve`)):(r[0]??e).batchWrite(t)},facets:(e,t,r)=>n(e).facets(e,t,r),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)}},Ns=e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&typeof e.type==`string`&&Array.isArray(e.children),Ps=e=>typeof e==`object`&&!!e&&e.kind===`member`,Fs=e=>Ps(e)?[e.path.join(`.`)]:typeof e!=`object`||!e?[]:Object.values(e).flatMap(Fs),Is=e=>Ps(e)?{...e,path:[e.path.join(`.`)]}:Array.isArray(e)?e.map(Is):typeof e!=`object`||!e?e:Object.fromEntries(Object.entries(e).map(([e,t])=>[e,Is(t)])),Ls=e=>{let t=Rr(e);return t.ok?t.ast?{ok:!0,ast:t.ast,paths:[...new Set(Fs(t.ast))]}:{ok:!1,message:`the condition is empty`}:{ok:!1,message:t.errors.map(e=>e.message).join(`; `)}},Rs=(e,t)=>e.ast!==void 0&&_ee(Is(e.ast),t),zs=(e,t)=>{let[n,r,...i]=e.split(`.`);return n&&r===`count`&&i.length===0&&!t(n)?n:void 0},Bs=(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}},Vs=(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]}))}),Hs=(e,t)=>{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=>Bs(t,e.resource,n).ok);return[i&&i.length>0?{...r,columns:i}:r]},Us=(e,t,n)=>e.run?.kind!==`link`||!(`to`in e.run)||Po(e.run.to,{models:n,pages:new Set,source:t}).length===0,Ws=(e,t)=>({...e,layout:e.layout.flatMap(e=>Hs(e,t)),actions:e.actions.filter(n=>Us(n,t[e.resource],t))}),Gs=(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=>Vs(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=>Ws(e,a)),permissions:Object.fromEntries(n.flatMap(t=>e.permissions?.[t.name]?[[t.name,e.permissions[t.name]]]:[]))}},Ks=class extends Error{status;code;constructor(e,t,n){super(e),this.status=t,this.code=n,this.name=`AuthError`}},R=(e,t)=>new Ks(e?.message||t,e?.status??500,e?.code),qs=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},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}});function Js(e){return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,{code:e,message:t,toString:()=>e}]))}var Ys=Js({CHALLENGE_NOT_FOUND:`Challenge not found`,YOU_ARE_NOT_ALLOWED_TO_REGISTER_THIS_PASSKEY:`You are not allowed to register this passkey`,FAILED_TO_VERIFY_REGISTRATION:`Failed to verify registration`,PASSKEY_NOT_FOUND:`Passkey not found`,AUTHENTICATION_FAILED:`Authentication failed`,UNABLE_TO_CREATE_SESSION:`Unable to create session`,USER_NOT_FOUND:`User not found`,FAILED_TO_UPDATE_PASSKEY:`Failed to update passkey`,PREVIOUSLY_REGISTERED:`Previously registered`,REGISTRATION_CANCELLED:`Registration cancelled`,AUTH_CANCELLED:`Auth cancelled`,UNKNOWN_ERROR:`Unknown error`,SESSION_REQUIRED:`Passkey registration requires an authenticated session`,RESOLVE_USER_REQUIRED:`Passkey registration requires either an authenticated session or a resolveUser callback when requireSession is false`,RESOLVED_USER_INVALID:`Resolved user is invalid`}),Oee=`1.7.7`;function Xs(e){let t=new Uint8Array(e),n=``;for(let e of t)n+=String.fromCharCode(e);return btoa(n).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=/g,``)}function Zs(e){let t=e.replace(/-/g,`+`).replace(/_/g,`/`),n=(4-t.length%4)%4,r=t.padEnd(t.length+n,`=`),i=atob(r),a=new ArrayBuffer(i.length),o=new Uint8Array(a);for(let e=0;e<i.length;e++)o[e]=i.charCodeAt(e);return a}function Qs(){return kee.stubThis(globalThis?.PublicKeyCredential!==void 0&&typeof globalThis.PublicKeyCredential==`function`)}var kee={stubThis:e=>e};function $s(e){let{id:t}=e;return{...e,id:Zs(t),transports:e.transports}}function ec(e){return e===`localhost`||/^((xn--[a-z0-9-]+|[a-z0-9]+(-[a-z0-9]+)*)\.)+([a-z]{2,}|xn--[a-z0-9-]+)$/i.test(e)}var tc=class extends Error{constructor({message:e,code:t,cause:n,name:r}){super(e,{cause:n}),Object.defineProperty(this,"code",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.name=r??n.name,this.code=t}};function Aee({error:e,options:t}){let{publicKey:n}=t;if(!n)throw Error(`options was missing required publicKey property`);if(e.name===`AbortError`){if(t.signal instanceof AbortSignal)return new tc({message:`Registration ceremony was sent an abort signal`,code:`ERROR_CEREMONY_ABORTED`,cause:e})}else if(e.name===`ConstraintError`){if(n.authenticatorSelection?.requireResidentKey===!0)return new tc({message:`Discoverable credentials were required but no available authenticator supported it`,code:`ERROR_AUTHENTICATOR_MISSING_DISCOVERABLE_CREDENTIAL_SUPPORT`,cause:e});if(t.mediation===`conditional`&&n.authenticatorSelection?.userVerification===`required`)return new tc({message:`User verification was required during automatic registration but it could not be performed`,code:`ERROR_AUTO_REGISTER_USER_VERIFICATION_FAILURE`,cause:e});if(n.authenticatorSelection?.userVerification===`required`)return new tc({message:`User verification was required but no available authenticator supported it`,code:`ERROR_AUTHENTICATOR_MISSING_USER_VERIFICATION_SUPPORT`,cause:e})}else if(e.name===`InvalidStateError`)return new tc({message:`The authenticator was previously registered`,code:`ERROR_AUTHENTICATOR_PREVIOUSLY_REGISTERED`,cause:e});else if(e.name===`NotAllowedError`)return new tc({message:e.message,code:`ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY`,cause:e});else if(e.name===`NotSupportedError`)return n.pubKeyCredParams.filter(e=>e.type===`public-key`).length===0?new tc({message:`No entry in pubKeyCredParams was of type "public-key"`,code:`ERROR_MALFORMED_PUBKEYCREDPARAMS`,cause:e}):new tc({message:`No available authenticator supported any of the specified pubKeyCredParams algorithms`,code:`ERROR_AUTHENTICATOR_NO_SUPPORTED_PUBKEYCREDPARAMS_ALG`,cause:e});else if(e.name===`SecurityError`){let t=globalThis.location.hostname;if(!ec(t))return new tc({message:`${globalThis.location.hostname} is an invalid domain`,code:`ERROR_INVALID_DOMAIN`,cause:e});if(n.rp.id!==t)return new tc({message:`The RP ID "${n.rp.id}" is invalid for this domain`,code:`ERROR_INVALID_RP_ID`,cause:e})}else if(e.name===`TypeError`){if(n.user.id.byteLength<1||n.user.id.byteLength>64)return new tc({message:`User ID was not between 1 and 64 characters`,code:`ERROR_INVALID_USER_ID_LENGTH`,cause:e})}else if(e.name===`UnknownError`)return new tc({message:`The authenticator was unable to process the specified options, or could not create a new credential`,code:`ERROR_AUTHENTICATOR_GENERAL_ERROR`,cause:e});return e}var nc=new class{constructor(){Object.defineProperty(this,"controller",{enumerable:!0,configurable:!0,writable:!0,value:void 0})}createNewAbortSignal(){if(this.controller){let e=Error(`Cancelling existing WebAuthn API call for new one`);e.name=`AbortError`,this.controller.abort(e)}let e=new AbortController;return this.controller=e,e.signal}cancelCeremony(){if(this.controller){let e=Error(`Manually cancelling existing WebAuthn API call`);e.name=`AbortError`,this.controller.abort(e),this.controller=void 0}}},jee=[`cross-platform`,`platform`];function rc(e){if(e&&!(jee.indexOf(e)<0))return e}async function Mee(e){!e.optionsJSON&&e.challenge&&(console.warn(`startRegistration() was not called correctly. It will try to continue with the provided options, but this call should be refactored to use the expected call structure instead. See https://simplewebauthn.dev/docs/packages/browser#typeerror-cannot-read-properties-of-undefined-reading-challenge for more information.`),e={optionsJSON:e});let{optionsJSON:t,useAutoRegister:n=!1}=e;if(!Qs())throw Error(`WebAuthn is not supported in this browser`);let r={...t,challenge:Zs(t.challenge),user:{...t.user,id:Zs(t.user.id)},excludeCredentials:t.excludeCredentials?.map($s)},i={};n&&(i.mediation=`conditional`),i.publicKey=r,i.signal=nc.createNewAbortSignal();let a;try{a=await navigator.credentials.create(i)}catch(e){throw Aee({error:e,options:i})}if(!a)throw Error(`Registration was not completed`);let{id:o,rawId:s,response:c,type:l}=a,u;typeof c.getTransports==`function`&&(u=c.getTransports());let d;if(typeof c.getPublicKeyAlgorithm==`function`)try{d=c.getPublicKeyAlgorithm()}catch(e){ic(`getPublicKeyAlgorithm()`,e)}let f;if(typeof c.getPublicKey==`function`)try{let e=c.getPublicKey();e!==null&&(f=Xs(e))}catch(e){ic(`getPublicKey()`,e)}let p;if(typeof c.getAuthenticatorData==`function`)try{p=Xs(c.getAuthenticatorData())}catch(e){ic(`getAuthenticatorData()`,e)}return{id:o,rawId:Xs(s),response:{attestationObject:Xs(c.attestationObject),clientDataJSON:Xs(c.clientDataJSON),transports:u,publicKeyAlgorithm:d,publicKey:f,authenticatorData:p},type:l,clientExtensionResults:a.getClientExtensionResults(),authenticatorAttachment:rc(a.authenticatorAttachment)}}function ic(e,t){console.warn(`The browser extension that intercepted this WebAuthn API call incorrectly implemented ${e}. You should report this error to them.\n`,t)}function Nee(){if(!Qs())return ac.stubThis(new Promise(e=>e(!1)));let e=globalThis.PublicKeyCredential;return e?.isConditionalMediationAvailable===void 0?ac.stubThis(new Promise(e=>e(!1))):ac.stubThis(e.isConditionalMediationAvailable())}var ac={stubThis:e=>e};function Pee({error:e,options:t}){let{publicKey:n}=t;if(!n)throw Error(`options was missing required publicKey property`);if(e.name===`AbortError`){if(t.signal instanceof AbortSignal)return new tc({message:`Authentication ceremony was sent an abort signal`,code:`ERROR_CEREMONY_ABORTED`,cause:e})}else if(e.name===`NotAllowedError`)return new tc({message:e.message,code:`ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY`,cause:e});else if(e.name===`SecurityError`){let t=globalThis.location.hostname;if(!ec(t))return new tc({message:`${globalThis.location.hostname} is an invalid domain`,code:`ERROR_INVALID_DOMAIN`,cause:e});if(n.rpId!==t)return new tc({message:`The RP ID "${n.rpId}" is invalid for this domain`,code:`ERROR_INVALID_RP_ID`,cause:e})}else if(e.name===`UnknownError`)return new tc({message:`The authenticator was unable to process the specified options, or could not create a new assertion signature`,code:`ERROR_AUTHENTICATOR_GENERAL_ERROR`,cause:e});return e}async function oc(e){!e.optionsJSON&&e.challenge&&(console.warn(`startAuthentication() was not called correctly. It will try to continue with the provided options, but this call should be refactored to use the expected call structure instead. See https://simplewebauthn.dev/docs/packages/browser#typeerror-cannot-read-properties-of-undefined-reading-challenge for more information.`),e={optionsJSON:e});let{optionsJSON:t,useBrowserAutofill:n=!1,verifyBrowserAutofillInput:r=!0}=e;if(!Qs())throw Error(`WebAuthn is not supported in this browser`);let i;t.allowCredentials?.length!==0&&(i=t.allowCredentials?.map($s));let a={...t,challenge:Zs(t.challenge),allowCredentials:i},o={};if(n){if(!await Nee())throw Error(`Browser does not support WebAuthn autofill`);if(document.querySelectorAll(`input[autocomplete$='webauthn']`).length<1&&r)throw Error('No <input> with "webauthn" as the only or last value in its `autocomplete` attribute was detected');o.mediation=`conditional`,a.allowCredentials=[]}o.publicKey=a,o.signal=nc.createNewAbortSignal();let s;try{s=await navigator.credentials.get(o)}catch(e){throw Pee({error:e,options:o})}if(!s)throw Error(`Authentication was not completed`);let{id:c,rawId:l,response:u,type:d}=s,f;return u.userHandle&&(f=Xs(u.userHandle)),{id:c,rawId:Xs(l),response:{authenticatorData:Xs(u.authenticatorData),clientDataJSON:Xs(u.clientDataJSON),signature:Xs(u.signature),userHandle:f},type:d,clientExtensionResults:s.getClientExtensionResults(),authenticatorAttachment:rc(s.authenticatorAttachment)}}var sc=`1.7.7`,cc=Symbol.for(`better-auth:broadcast-channel`),Fee=()=>Math.floor(Date.now()/1e3),Iee=class{listeners=new Set;name;constructor(e=`better-auth.message`){this.name=e}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}post(e){if(typeof window<`u`)try{localStorage.setItem(this.name,JSON.stringify({...e,timestamp:Fee()}))}catch{}}setup(){if(typeof window>`u`||window.addEventListener===void 0)return()=>{};let e=e=>{if(e.key!==this.name)return;let t=JSON.parse(e.newValue??`{}`);t?.event===`session`&&t?.data&&this.listeners.forEach(e=>e(t))};return window.addEventListener(`storage`,e),()=>{window.removeEventListener(`storage`,e)}}};function lc(e=`better-auth.message`){return globalThis[cc]||(globalThis[cc]=new Iee(e)),globalThis[cc]}var uc=[],dc=0,fc=null,pc=4,Lee=globalThis.nanostoresGlobal||={epoch:0},Ree=()=>{let e,t;for(;dc<uc.length;){t=dc,dc+=pc;let n=fc?.get(uc[t]);if(n){if(!n.has(uc[t+1]))continue;n.clear()}try{uc[t](uc[t+1].value,uc[t+2],uc[t+3])}catch(t){e=t}}if(uc.length=dc=0,e)throw e},mc=e=>{let t=[],n={eq:Object.is,get(){return n.lc||n.listen(()=>{})(),n.value},init:e,lc:0,listen(e){return n.lc=t.push(e),()=>{fc?.get(e)?.delete(n);for(let t=dc;t<uc.length;)uc[t]===e&&uc[t+1]===n?uc.splice(t,pc):t+=pc;let r=t.indexOf(e);~r&&(t.splice(r,1),--n.lc||n.off())}},notify(e,r){Lee.epoch++;let i=!uc.length&&!0;for(let i of t)uc.push(i,n,e,r);i&&Ree()},off(){},set(e){let t=n.value;n.eq(t,e)||(n.value=e,n.notify(t))},subscribe(e){let t=n.listen(e);return e(n.value),t},value:e};return n},zee=2,Bee=5,hc=6,gc=10,_c=(e,t,n,r)=>(e.events=e.events||{},e.events[n+gc]||(e.events[n+gc]=r(t=>{e.events[n].reduceRight((e,t)=>(t(e),e),{shared:{},...t})})),e.events[n]=e.events[n]||[],e.events[n].push(t),()=>{let r=e.events[n],i=r.indexOf(t);~i&&(r.splice(i,1),r.length||(e.events[n+gc](),delete e.events[n+gc]))}),Vee=(e,t)=>_c(e,t,zee,t=>{let n=e.set,r=e.setKey;return e.setKey&&=(n,i)=>{let a;if(t({abort:()=>{a=!0},changed:n,newValue:{...e.value,[n]:i}}),!a)return r(n,i)},e.set=e=>{let r;if(t({abort:()=>{r=!0},newValue:e}),!r)return n(e)},()=>{e.set=n,e.setKey=r}}),vc=1e3,yc=(e,t)=>_c(e,n=>{let r=t(n);r&&e.events[hc].push(r)},Bee,t=>{let n=e.listen;e.listen=(...r)=>(!e.lc&&!e.active&&(e.active=!0,t()),n(...r));let r=e.off;return e.events[hc]=[],e.off=()=>{r(),setTimeout(()=>{if(e.active&&!e.lc){e.active=!1;for(let t of e.events[hc])t();e.events[hc]=[]}},vc)},()=>{e.listen=n,e.off=r}});function bc(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function xc(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!xc(e[n],t[n]))return!1;return!0}if(bc(e)&&bc(t)){let n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(let r of n)if(!(r in t)||!xc(e[r],t[r]))return!1;return!0}return!1}function Sc(e,t){return Vee(e,({newValue:n,abort:r})=>{t(e.value,n)&&r()})}var Cc=Symbol.for(`better-auth:focus-manager`),wc=class{listeners=new Set;subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}setFocused(e){this.listeners.forEach(t=>t(e))}setup(){if(typeof window>`u`||typeof document>`u`||window.addEventListener===void 0)return()=>{};let e=()=>{document.visibilityState===`visible`&&this.setFocused(!0)};return document.addEventListener(`visibilitychange`,e,!1),()=>{document.removeEventListener(`visibilitychange`,e,!1)}}};function Tc(){return globalThis[Cc]||(globalThis[Cc]=new wc),globalThis[Cc]}var Ec=Symbol.for(`better-auth:online-manager`),Dc=class{listeners=new Set;isOnline=typeof navigator<`u`?navigator.onLine:!0;subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}setOnline(e){this.isOnline=e,this.listeners.forEach(t=>t(e))}setup(){if(typeof window>`u`||window.addEventListener===void 0)return()=>{};let e=()=>this.setOnline(!0),t=()=>this.setOnline(!1);return window.addEventListener(`online`,e,!1),window.addEventListener(`offline`,t,!1),()=>{window.removeEventListener(`online`,e,!1),window.removeEventListener(`offline`,t,!1)}}};function Oc(){return globalThis[Ec]||(globalThis[Ec]=new Dc),globalThis[Ec]}var kc={proto:/"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/,constructor:/"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/,protoShort:/"__proto__"\s*:/,constructorShort:/"constructor"\s*:/},Ac=/^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/,jc={true:!0,false:!1,null:null,undefined:void 0,nan:NaN,infinity:1/0,"-infinity":-1/0},Mc=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,7}))?(?:Z|([+-])(\d{2}):(\d{2}))$/;function Nc(e){return e instanceof Date&&!isNaN(e.getTime())}function Pc(e){let t=Mc.exec(e);if(!t)return null;let[,n,r,i,a,o,s,c,l,u,d]=t,f=new Date(Date.UTC(parseInt(n,10),parseInt(r,10)-1,parseInt(i,10),parseInt(a,10),parseInt(o,10),parseInt(s,10),c?parseInt(c.padEnd(3,`0`),10):0));if(l){let e=(parseInt(u,10)*60+parseInt(d,10))*(l===`+`?-1:1);f.setUTCMinutes(f.getUTCMinutes()+e)}return Nc(f)?f:null}function Fc(e,t={}){let{strict:n=!1,warnings:r=!1,reviver:i,parseDates:a=!0}=t;if(typeof e!=`string`)return e;let o=e.trim(),s=o.toLowerCase();if(s.length<=9&&s in jc)return jc[s];if(!Ac.test(o)){if(n)throw SyntaxError(`[better-json] Invalid JSON`);return e}if(Object.entries(kc).some(([e,t])=>{let n=t.test(o);return n&&r&&console.warn(`[better-json] Detected potential prototype pollution attempt using ${e} pattern`),n})&&n)throw Error(`[better-json] Potential prototype pollution attempt detected`);try{return JSON.parse(o,(e,t)=>{if(e===`__proto__`||e===`constructor`&&t&&typeof t==`object`&&`prototype`in t){r&&console.warn(`[better-json] Dropping "${e}" key to prevent prototype pollution`);return}if(a&&typeof t==`string`){let e=Pc(t);if(e)return e}return i?i(e,t):t})}catch(t){if(n)throw t;return e}}function Ic(e,t={strict:!0}){return Fc(e,t)}var Lc=Symbol.for(`better-auth:auth-query`);function Rc(e){let t=mc(e);return Object.defineProperty(t,Lc,{value:!0}),t}var zc=()=>typeof window>`u`;function Bc(e,t){return xc(e.data,t.data)&&e.error===t.error&&e.isPending===t.isPending&&e.isRefetching===t.isRefetching&&e.refetch===t.refetch}var Vc=(e,t,n,r)=>{let i=Rc({data:null,error:null,isPending:!0,isRefetching:!1,refetch:e=>o(e)});yc(i,()=>Sc(i,Bc));let a=0,o=async e=>{let o=++a;return new Promise(s=>{let c=typeof r==`function`?r({data:i.get().data,error:i.get().error,isPending:i.get().isPending}):r;n(t,{...c,query:{...c?.query,...e?.query},async onSuccess(e){if(o===a){let t=i.get(),n=t.data!=null&&e.data!=null&&xc(t.data,e.data)?t.data:e.data;i.set({data:n,error:null,isPending:!1,isRefetching:!1,refetch:i.value.refetch})}await c?.onSuccess?.(e)},async onError(e){let{request:t}=e,n=typeof t.retry==`number`?t.retry:t.retry?.attempts,r=t.retryAttempt||0;if(!(n&&r<n)){if(o===a){let t=e.error.status===401;i.set({error:e.error,data:t?null:i.get().data,isPending:!1,isRefetching:!1,refetch:i.value.refetch})}await c?.onError?.(e)}},async onRequest(e){if(o===a){let e=i.get();i.set({isPending:e.data===null,data:e.data,error:null,isRefetching:!0,refetch:i.value.refetch})}await c?.onRequest?.(e)}}).catch(e=>{o===a&&i.set({error:e,data:i.get().data,isPending:!1,isRefetching:!1,refetch:i.value.refetch})}).finally(()=>{s(void 0)})})};e=Array.isArray(e)?e:[e];let s=!1,c=!1,l=!1,u=()=>{if(s){l=!0;return}s=!0,o().finally(()=>{s=!1;let e=l&&c;l=!1,e&&u()})};return yc(i,()=>{if(zc())return;c=!0;let t=!1,n,r=e.map(e=>e.listen(()=>{t?o():(t=!0,clearTimeout(n),u())}));return n=setTimeout(()=>{t=!0,u()},0),()=>{c=!1;for(let e of r)e();clearTimeout(n)}}),i},Hc=()=>Math.floor(Date.now()/1e3),Uc=5;function Wc(e){let{fetchSession:t,shouldPollSession:n=()=>!0,sessionSignal:r,options:i={}}=e,a=i.sessionOptions?.refetchInterval??0,o=i.sessionOptions?.refetchOnWindowFocus??!0,s=i.sessionOptions?.refetchWhenOffline??!1,c={isInitialized:!1,lastSessionRequest:0},l=()=>s||Oc().isOnline,u=e=>{if(l()){if(e?.event===`storage`){t();return}if(e?.event===`poll`){c.lastSessionRequest=Hc(),t();return}if(e?.event===`visibilitychange`){if(Hc()-c.lastSessionRequest<Uc)return;c.lastSessionRequest=Hc(),t();return}t()}},d=e=>{lc().post({event:`session`,data:{trigger:e},clientId:Math.random().toString(36).substring(7)})},f=()=>{a&&a>0&&(c.pollInterval=setInterval(()=>{n()&&u({event:`poll`})},a*1e3))},p=()=>{c.unsubscribeBroadcast=lc().subscribe(()=>{u({event:`storage`})})},m=()=>{o&&(c.unsubscribeFocus=Tc().subscribe(()=>{u({event:`visibilitychange`})}))},h=()=>{c.unsubscribeOnline=Oc().subscribe(e=>{e&&u({event:`visibilitychange`})})},g=()=>{c.unsubscribeSignal=r.listen(()=>{t()})};return{init:()=>{c.isInitialized||(c.isInitialized=!0,f(),p(),m(),h(),g(),c.cleanupBroadcastSetup=lc().setup(),c.cleanupFocusSetup=Tc().setup(),c.cleanupOnlineSetup=Oc().setup())},cleanup:()=>{c.isInitialized&&(c.pollInterval&&=(clearInterval(c.pollInterval),void 0),c.unsubscribeBroadcast&&=(c.unsubscribeBroadcast(),void 0),c.unsubscribeFocus&&=(c.unsubscribeFocus(),void 0),c.unsubscribeOnline&&=(c.unsubscribeOnline(),void 0),c.unsubscribeSignal&&=(c.unsubscribeSignal(),void 0),c.cleanupBroadcastSetup&&=(c.cleanupBroadcastSetup(),void 0),c.cleanupFocusSetup&&=(c.cleanupFocusSetup(),void 0),c.cleanupOnlineSetup&&=(c.cleanupOnlineSetup(),void 0),c.isInitialized=!1,c.lastSessionRequest=0)},triggerRefetch:u,broadcastSessionUpdate:d}}var Gc=Object.create(null),Kc=e=>({}),qc=new Proxy(Gc,{get(e,t){return Kc()[t]??Gc[t]},has(e,t){return t in Kc()||t in Gc},set(e,t,n){let r=Kc(!0);return r[t]=n,!0},deleteProperty(e,t){if(!t)return!1;let n=Kc(!0);return delete n[t],!0},ownKeys(){let e=Kc(!0);return Object.keys(e)}});qc.NODE_ENV;function Jc(e,t){return typeof process<`u`?{}[e]??t:typeof Deno<`u`?Deno.env.get(e)??t:typeof Bun<`u`?Bun.env[e]??t:t}Object.freeze({get BETTER_AUTH_SECRET(){return Jc(`BETTER_AUTH_SECRET`)},get AUTH_SECRET(){return Jc(`AUTH_SECRET`)},get BETTER_AUTH_TELEMETRY(){return Jc(`BETTER_AUTH_TELEMETRY`)},get BETTER_AUTH_TELEMETRY_ID(){return Jc(`BETTER_AUTH_TELEMETRY_ID`)},get NODE_ENV(){return Jc(`NODE_ENV`,`development`)},get PACKAGE_VERSION(){return Jc(`PACKAGE_VERSION`,`0.0.0`)},get BETTER_AUTH_TELEMETRY_ENDPOINT(){return Jc(`BETTER_AUTH_TELEMETRY_ENDPOINT`,``)}});function Yc(){let e=Object.getOwnPropertyDescriptor(Error,`stackTraceLimit`);return e===void 0?Object.isExtensible(Error):Object.prototype.hasOwnProperty.call(e,`writable`)?e.writable:e.set!==void 0}function Xc(e){let t=e.split(`
@@ -9,7 +9,7 @@ import{n as e,r as t,t as n}from"./rolldown-runtime-hePW80VL.js";import{t as r}f
9
9
  To pick up a draggable item, press the space bar.
10
10
  While dragging, use the arrow keys to move the item.
11
11
  Press space again to drop the item in its new position, or press escape to cancel.
12
- `},pb={onDragStart(e){let{active:t}=e;return`Picked up draggable item `+t.id+`.`},onDragOver(e){let{active:t,over:n}=e;return n?`Draggable item `+t.id+` was moved over droppable area `+n.id+`.`:`Draggable item `+t.id+` is no longer over a droppable area.`},onDragEnd(e){let{active:t,over:n}=e;return n?`Draggable item `+t.id+` was dropped over droppable area `+n.id:`Draggable item `+t.id+` was dropped.`},onDragCancel(e){let{active:t}=e;return`Dragging was cancelled. Draggable item `+t.id+` was dropped.`}};function mb(e){let{announcements:t=pb,container:n,hiddenTextDescribedById:r,screenReaderInstructions:i=fb}=e,{announce:a,announcement:s}=cb(),c=Jy(`DndLiveRegion`),[l,u]=(0,o.useState)(!1);if((0,o.useEffect)(()=>{u(!0)},[]),ub((0,o.useMemo)(()=>({onDragStart(e){let{active:n}=e;a(t.onDragStart({active:n}))},onDragMove(e){let{active:n,over:r}=e;t.onDragMove&&a(t.onDragMove({active:n,over:r}))},onDragOver(e){let{active:n,over:r}=e;a(t.onDragOver({active:n,over:r}))},onDragEnd(e){let{active:n,over:r}=e;a(t.onDragEnd({active:n,over:r}))},onDragCancel(e){let{active:n,over:r}=e;a(t.onDragCancel({active:n,over:r}))}}),[a,t])),!l)return null;let d=o.createElement(o.Fragment,null,o.createElement(ob,{id:r,value:i.draggable}),o.createElement(sb,{id:c,announcement:s}));return n?(0,Fn.createPortal)(d,n):d}var hb;(function(e){e.DragStart=`dragStart`,e.DragMove=`dragMove`,e.DragEnd=`dragEnd`,e.DragCancel=`dragCancel`,e.DragOver=`dragOver`,e.RegisterDroppable=`registerDroppable`,e.SetDroppableDisabled=`setDroppableDisabled`,e.UnregisterDroppable=`unregisterDroppable`})(hb||={});function gb(){}function _b(e,t){return(0,o.useMemo)(()=>({sensor:e,options:t??{}}),[e,t])}function vb(){var e=[...arguments];return(0,o.useMemo)(()=>[...e].filter(e=>e!=null),[...e])}var yb=Object.freeze({x:0,y:0});function bb(e,t){return Math.sqrt((e.x-t.x)**2+(e.y-t.y)**2)}function xb(e,t){let{data:{value:n}}=e,{data:{value:r}}=t;return n-r}function Sb(e,t){let{data:{value:n}}=e,{data:{value:r}}=t;return r-n}function Cb(e){let{left:t,top:n,height:r,width:i}=e;return[{x:t,y:n},{x:t+i,y:n},{x:t,y:n+r},{x:t+i,y:n+r}]}function wb(e,t){if(!e||e.length===0)return null;let[n]=e;return t?n[t]:n}function Tb(e,t,n){return t===void 0&&(t=e.left),n===void 0&&(n=e.top),{x:t+e.width*.5,y:n+e.height*.5}}var Eb=e=>{let{collisionRect:t,droppableRects:n,droppableContainers:r}=e,i=Tb(t,t.left,t.top),a=[];for(let e of r){let{id:t}=e,r=n.get(t);if(r){let n=bb(Tb(r),i);a.push({id:t,data:{droppableContainer:e,value:n}})}}return a.sort(xb)},Db=e=>{let{collisionRect:t,droppableRects:n,droppableContainers:r}=e,i=Cb(t),a=[];for(let e of r){let{id:t}=e,r=n.get(t);if(r){let n=Cb(r),o=i.reduce((e,t,r)=>e+bb(n[r],t),0),s=Number((o/4).toFixed(4));a.push({id:t,data:{droppableContainer:e,value:s}})}}return a.sort(xb)};function Ob(e,t){let n=Math.max(t.top,e.top),r=Math.max(t.left,e.left),i=Math.min(t.left+t.width,e.left+e.width),a=Math.min(t.top+t.height,e.top+e.height),o=i-r,s=a-n;if(r<i&&n<a){let n=t.width*t.height,r=e.width*e.height,i=o*s,a=i/(n+r-i);return Number(a.toFixed(4))}return 0}var kb=e=>{let{collisionRect:t,droppableRects:n,droppableContainers:r}=e,i=[];for(let e of r){let{id:r}=e,a=n.get(r);if(a){let n=Ob(a,t);n>0&&i.push({id:r,data:{droppableContainer:e,value:n}})}}return i.sort(Sb)};function Ab(e,t,n){return{...e,scaleX:t&&n?t.width/n.width:1,scaleY:t&&n?t.height/n.height:1}}function jb(e,t){return e&&t?{x:e.left-t.left,y:e.top-t.top}:yb}function Mb(e){return function(t){return[...arguments].slice(1).reduce((t,n)=>({...t,top:t.top+e*n.y,bottom:t.bottom+e*n.y,left:t.left+e*n.x,right:t.right+e*n.x}),{...t})}}var Nb=Mb(1);function Pb(e){if(e.startsWith(`matrix3d(`)){let t=e.slice(9,-1).split(/, /);return{x:+t[12],y:+t[13],scaleX:+t[0],scaleY:+t[5]}}if(e.startsWith(`matrix(`)){let t=e.slice(7,-1).split(/, /);return{x:+t[4],y:+t[5],scaleX:+t[0],scaleY:+t[3]}}return null}function Zte(e,t,n){let r=Pb(t);if(!r)return e;let{scaleX:i,scaleY:a,x:o,y:s}=r,c=e.left-o-(1-i)*parseFloat(n),l=e.top-s-(1-a)*parseFloat(n.slice(n.indexOf(` `)+1)),u=i?e.width/i:e.width,d=a?e.height/a:e.height;return{width:u,height:d,top:l,right:c+u,bottom:l+d,left:c}}var Qte={ignoreTransform:!1};function Fb(e,t){t===void 0&&(t=Qte);let n=e.getBoundingClientRect();if(t.ignoreTransform){let{transform:t,transformOrigin:r}=Fy(e).getComputedStyle(e);t&&(n=Zte(n,t,r))}let{top:r,left:i,width:a,height:o,bottom:s,right:c}=n;return{top:r,left:i,width:a,height:o,bottom:s,right:c}}function Ib(e){return Fb(e,{ignoreTransform:!0})}function $te(e){let t=e.innerWidth,n=e.innerHeight;return{top:0,left:0,right:t,bottom:n,width:t,height:n}}function ene(e,t){return t===void 0&&(t=Fy(e).getComputedStyle(e)),t.position===`fixed`}function tne(e,t){t===void 0&&(t=Fy(e).getComputedStyle(e));let n=/(auto|scroll|overlay)/;return[`overflow`,`overflowX`,`overflowY`].some(e=>{let r=t[e];return typeof r==`string`&&n.test(r)})}function Lb(e,t){let n=[];function r(i){if(t!=null&&n.length>=t||!i)return n;if(Iy(i)&&i.scrollingElement!=null&&!n.includes(i.scrollingElement))return n.push(i.scrollingElement),n;if(!Ly(i)||Ry(i)||n.includes(i))return n;let a=Fy(e).getComputedStyle(i);return i!==e&&tne(i,a)&&n.push(i),ene(i,a)?n:r(i.parentNode)}return e?r(e):n}function Rb(e){let[t]=Lb(e,1);return t??null}function zb(e){return!My||!e?null:Ny(e)?e:Py(e)?Iy(e)||e===zy(e).scrollingElement?window:Ly(e)?e:null:null}function Bb(e){return Ny(e)?e.scrollX:e.scrollLeft}function Vb(e){return Ny(e)?e.scrollY:e.scrollTop}function Hb(e){return{x:Bb(e),y:Vb(e)}}var Ub;(function(e){e[e.Forward=1]=`Forward`,e[e.Backward=-1]=`Backward`})(Ub||={});function Wb(e){return!My||!e?!1:e===document.scrollingElement}function Gb(e){let t={x:0,y:0},n=Wb(e)?{height:window.innerHeight,width:window.innerWidth}:{height:e.clientHeight,width:e.clientWidth},r={x:e.scrollWidth-n.width,y:e.scrollHeight-n.height};return{isTop:e.scrollTop<=t.y,isLeft:e.scrollLeft<=t.x,isBottom:e.scrollTop>=r.y,isRight:e.scrollLeft>=r.x,maxScroll:r,minScroll:t}}var nne={x:.2,y:.2};function rne(e,t,n,r,i){let{top:a,left:o,right:s,bottom:c}=n;r===void 0&&(r=10),i===void 0&&(i=nne);let{isTop:l,isBottom:u,isLeft:d,isRight:f}=Gb(e),p={x:0,y:0},m={x:0,y:0},h={height:t.height*i.y,width:t.width*i.x};return!l&&a<=t.top+h.height?(p.y=Ub.Backward,m.y=r*Math.abs((t.top+h.height-a)/h.height)):!u&&c>=t.bottom-h.height&&(p.y=Ub.Forward,m.y=r*Math.abs((t.bottom-h.height-c)/h.height)),!f&&s>=t.right-h.width?(p.x=Ub.Forward,m.x=r*Math.abs((t.right-h.width-s)/h.width)):!d&&o<=t.left+h.width&&(p.x=Ub.Backward,m.x=r*Math.abs((t.left+h.width-o)/h.width)),{direction:p,speed:m}}function ine(e){if(e===document.scrollingElement){let{innerWidth:e,innerHeight:t}=window;return{top:0,left:0,right:e,bottom:t,width:e,height:t}}let{top:t,left:n,right:r,bottom:i}=e.getBoundingClientRect();return{top:t,left:n,right:r,bottom:i,width:e.clientWidth,height:e.clientHeight}}function Kb(e){return e.reduce((e,t)=>Xy(e,Hb(t)),yb)}function ane(e){return e.reduce((e,t)=>e+Bb(t),0)}function one(e){return e.reduce((e,t)=>e+Vb(t),0)}function sne(e,t){if(t===void 0&&(t=Fb),!e)return;let{top:n,left:r,bottom:i,right:a}=t(e);Rb(e)&&(i<=0||a<=0||n>=window.innerHeight||r>=window.innerWidth)&&e.scrollIntoView({block:`center`,inline:`center`})}var cne=[[`x`,[`left`,`right`],ane],[`y`,[`top`,`bottom`],one]],qb=class{constructor(e,t){this.rect=void 0,this.width=void 0,this.height=void 0,this.top=void 0,this.bottom=void 0,this.right=void 0,this.left=void 0;let n=Lb(t),r=Kb(n);this.rect={...e},this.width=e.width,this.height=e.height;for(let[e,t,i]of cne)for(let a of t)Object.defineProperty(this,a,{get:()=>{let t=i(n),o=r[e]-t;return this.rect[a]+o},enumerable:!0});Object.defineProperty(this,"rect",{enumerable:!1})}},Jb=class{constructor(e){this.target=void 0,this.listeners=[],this.removeAll=()=>{this.listeners.forEach(e=>this.target?.removeEventListener(...e))},this.target=e}add(e,t,n){var r;(r=this.target)==null||r.addEventListener(e,t,n),this.listeners.push([e,t,n])}};function lne(e){let{EventTarget:t}=Fy(e);return e instanceof t?e:zy(e)}function Yb(e,t){let n=Math.abs(e.x),r=Math.abs(e.y);return typeof t==`number`?Math.sqrt(n**2+r**2)>t:`x`in t&&`y`in t?n>t.x&&r>t.y:`x`in t?n>t.x:`y`in t&&r>t.y}var Xb;(function(e){e.Click=`click`,e.DragStart=`dragstart`,e.Keydown=`keydown`,e.ContextMenu=`contextmenu`,e.Resize=`resize`,e.SelectionChange=`selectionchange`,e.VisibilityChange=`visibilitychange`})(Xb||={});function Zb(e){e.preventDefault()}function une(e){e.stopPropagation()}var q;(function(e){e.Space=`Space`,e.Down=`ArrowDown`,e.Right=`ArrowRight`,e.Left=`ArrowLeft`,e.Up=`ArrowUp`,e.Esc=`Escape`,e.Enter=`Enter`,e.Tab=`Tab`})(q||={});var Qb={start:[q.Space,q.Enter],cancel:[q.Esc],end:[q.Space,q.Enter,q.Tab]},dne=(e,t)=>{let{currentCoordinates:n}=t;switch(e.code){case q.Right:return{...n,x:n.x+25};case q.Left:return{...n,x:n.x-25};case q.Down:return{...n,y:n.y+25};case q.Up:return{...n,y:n.y-25}}},$b=class{constructor(e){this.props=void 0,this.autoScrollEnabled=!1,this.referenceCoordinates=void 0,this.listeners=void 0,this.windowListeners=void 0,this.props=e;let{event:{target:t}}=e;this.props=e,this.listeners=new Jb(zy(t)),this.windowListeners=new Jb(Fy(t)),this.handleKeyDown=this.handleKeyDown.bind(this),this.handleCancel=this.handleCancel.bind(this),this.attach()}attach(){this.handleStart(),this.windowListeners.add(Xb.Resize,this.handleCancel),this.windowListeners.add(Xb.VisibilityChange,this.handleCancel),setTimeout(()=>this.listeners.add(Xb.Keydown,this.handleKeyDown))}handleStart(){let{activeNode:e,onStart:t}=this.props,n=e.node.current;n&&sne(n),t(yb)}handleKeyDown(e){if($y(e)){let{active:t,context:n,options:r}=this.props,{keyboardCodes:i=Qb,coordinateGetter:a=dne,scrollBehavior:o=`smooth`}=r,{code:s}=e;if(i.end.includes(s)){this.handleEnd(e);return}if(i.cancel.includes(s)){this.handleCancel(e);return}let{collisionRect:c}=n.current,l=c?{x:c.left,y:c.top}:yb;this.referenceCoordinates||=l;let u=a(e,{active:t,context:n.current,currentCoordinates:l});if(u){let t=Zy(u,l),r={x:0,y:0},{scrollableAncestors:i}=n.current;for(let n of i){let i=e.code,{isTop:a,isRight:s,isLeft:c,isBottom:l,maxScroll:d,minScroll:f}=Gb(n),p=ine(n),m={x:Math.min(i===q.Right?p.right-p.width/2:p.right,Math.max(i===q.Right?p.left:p.left+p.width/2,u.x)),y:Math.min(i===q.Down?p.bottom-p.height/2:p.bottom,Math.max(i===q.Down?p.top:p.top+p.height/2,u.y))},h=i===q.Right&&!s||i===q.Left&&!c,g=i===q.Down&&!l||i===q.Up&&!a;if(h&&m.x!==u.x){let e=n.scrollLeft+t.x,a=i===q.Right&&e<=d.x||i===q.Left&&e>=f.x;if(a&&!t.y){n.scrollTo({left:e,behavior:o});return}r.x=a?n.scrollLeft-e:i===q.Right?n.scrollLeft-d.x:n.scrollLeft-f.x,r.x&&n.scrollBy({left:-r.x,behavior:o});break}if(g&&m.y!==u.y){let e=n.scrollTop+t.y,a=i===q.Down&&e<=d.y||i===q.Up&&e>=f.y;if(a&&!t.x){n.scrollTo({top:e,behavior:o});return}r.y=a?n.scrollTop-e:i===q.Down?n.scrollTop-d.y:n.scrollTop-f.y,r.y&&n.scrollBy({top:-r.y,behavior:o});break}}this.handleMove(e,Xy(Zy(u,this.referenceCoordinates),r))}}}handleMove(e,t){let{onMove:n}=this.props;e.preventDefault(),n(t)}handleEnd(e){let{onEnd:t}=this.props;e.preventDefault(),this.detach(),t()}handleCancel(e){let{onCancel:t}=this.props;e.preventDefault(),this.detach(),t()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll()}};$b.activators=[{eventName:`onKeyDown`,handler:(e,t,n)=>{let{keyboardCodes:r=Qb,onActivation:i}=t,{active:a}=n,{code:o}=e.nativeEvent;if(r.start.includes(o)){let t=a.activatorNode.current;return t&&e.target!==t?!1:(e.preventDefault(),i?.({event:e.nativeEvent}),!0)}return!1}}];function ex(e){return!!(e&&`distance`in e)}function tx(e){return!!(e&&`delay`in e)}var nx=class{constructor(e,t,n){n===void 0&&(n=lne(e.event.target)),this.props=void 0,this.events=void 0,this.autoScrollEnabled=!0,this.document=void 0,this.activated=!1,this.initialCoordinates=void 0,this.timeoutId=null,this.listeners=void 0,this.documentListeners=void 0,this.windowListeners=void 0,this.props=e,this.events=t;let{event:r}=e,{target:i}=r;this.props=e,this.events=t,this.document=zy(i),this.documentListeners=new Jb(this.document),this.listeners=new Jb(n),this.windowListeners=new Jb(Fy(i)),this.initialCoordinates=tb(r)??yb,this.handleStart=this.handleStart.bind(this),this.handleMove=this.handleMove.bind(this),this.handleEnd=this.handleEnd.bind(this),this.handleCancel=this.handleCancel.bind(this),this.handleKeydown=this.handleKeydown.bind(this),this.removeTextSelection=this.removeTextSelection.bind(this),this.attach()}attach(){let{events:e,props:{options:{activationConstraint:t,bypassActivationConstraint:n}}}=this;if(this.listeners.add(e.move.name,this.handleMove,{passive:!1}),this.listeners.add(e.end.name,this.handleEnd),e.cancel&&this.listeners.add(e.cancel.name,this.handleCancel),this.windowListeners.add(Xb.Resize,this.handleCancel),this.windowListeners.add(Xb.DragStart,Zb),this.windowListeners.add(Xb.VisibilityChange,this.handleCancel),this.windowListeners.add(Xb.ContextMenu,Zb),this.documentListeners.add(Xb.Keydown,this.handleKeydown),t){if(n!=null&&n({event:this.props.event,activeNode:this.props.activeNode,options:this.props.options}))return this.handleStart();if(tx(t)){this.timeoutId=setTimeout(this.handleStart,t.delay),this.handlePending(t);return}if(ex(t)){this.handlePending(t);return}}this.handleStart()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll(),setTimeout(this.documentListeners.removeAll,50),this.timeoutId!==null&&(clearTimeout(this.timeoutId),this.timeoutId=null)}handlePending(e,t){let{active:n,onPending:r}=this.props;r(n,e,this.initialCoordinates,t)}handleStart(){let{initialCoordinates:e}=this,{onStart:t}=this.props;e&&(this.activated=!0,this.documentListeners.add(Xb.Click,une,{capture:!0}),this.removeTextSelection(),this.documentListeners.add(Xb.SelectionChange,this.removeTextSelection),t(e))}handleMove(e){let{activated:t,initialCoordinates:n,props:r}=this,{onMove:i,options:{activationConstraint:a}}=r;if(!n)return;let o=tb(e)??yb,s=Zy(n,o);if(!t&&a){if(ex(a)){if(a.tolerance!=null&&Yb(s,a.tolerance))return this.handleCancel();if(Yb(s,a.distance))return this.handleStart()}if(tx(a)&&Yb(s,a.tolerance))return this.handleCancel();this.handlePending(a,s);return}e.cancelable&&e.preventDefault(),i(o)}handleEnd(){let{onAbort:e,onEnd:t}=this.props;this.detach(),this.activated||e(this.props.active),t()}handleCancel(){let{onAbort:e,onCancel:t}=this.props;this.detach(),this.activated||e(this.props.active),t()}handleKeydown(e){e.code===q.Esc&&this.handleCancel()}removeTextSelection(){var e;(e=this.document.getSelection())==null||e.removeAllRanges()}},fne={cancel:{name:`pointercancel`},move:{name:`pointermove`},end:{name:`pointerup`}},rx=class extends nx{constructor(e){let{event:t}=e,n=zy(t.target);super(e,fne,n)}};rx.activators=[{eventName:`onPointerDown`,handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t;return!n.isPrimary||n.button!==0?!1:(r?.({event:n}),!0)}}];var pne={move:{name:`mousemove`},end:{name:`mouseup`}},ix;(function(e){e[e.RightClick=2]=`RightClick`})(ix||={});var ax=class extends nx{constructor(e){super(e,pne,zy(e.event.target))}};ax.activators=[{eventName:`onMouseDown`,handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t;return n.button!==ix.RightClick&&(r?.({event:n}),!0)}}];var ox={cancel:{name:`touchcancel`},move:{name:`touchmove`},end:{name:`touchend`}},sx=class extends nx{constructor(e){super(e,ox)}static setup(){return window.addEventListener(ox.move.name,e,{capture:!1,passive:!1}),function(){window.removeEventListener(ox.move.name,e)};function e(){}}};sx.activators=[{eventName:`onTouchStart`,handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t,{touches:i}=n;return i.length>1?!1:(r?.({event:n}),!0)}}];var cx;(function(e){e[e.Pointer=0]=`Pointer`,e[e.DraggableRect=1]=`DraggableRect`})(cx||={});var lx;(function(e){e[e.TreeOrder=0]=`TreeOrder`,e[e.ReversedTreeOrder=1]=`ReversedTreeOrder`})(lx||={});function mne(e){let{acceleration:t,activator:n=cx.Pointer,canScroll:r,draggingRect:i,enabled:a,interval:s=5,order:c=lx.TreeOrder,pointerCoordinates:l,scrollableAncestors:u,scrollableAncestorRects:d,delta:f,threshold:p}=e,m=gne({delta:f,disabled:!a}),[h,g]=Hy(),_=(0,o.useRef)({x:0,y:0}),v=(0,o.useRef)({x:0,y:0}),y=(0,o.useMemo)(()=>{switch(n){case cx.Pointer:return l?{top:l.y,bottom:l.y,left:l.x,right:l.x}:null;case cx.DraggableRect:return i}},[n,i,l]),b=(0,o.useRef)(null),x=(0,o.useCallback)(()=>{let e=b.current;if(!e)return;let t=_.current.x*v.current.x,n=_.current.y*v.current.y;e.scrollBy(t,n)},[]),S=(0,o.useMemo)(()=>c===lx.TreeOrder?[...u].reverse():u,[c,u]);(0,o.useEffect)(()=>{if(!a||!u.length||!y){g();return}for(let e of S){if(r?.(e)===!1)continue;let n=u.indexOf(e),i=d[n];if(!i)continue;let{direction:a,speed:o}=rne(e,i,y,t,p);for(let e of[`x`,`y`])m[e][a[e]]||(o[e]=0,a[e]=0);if(o.x>0||o.y>0){g(),b.current=e,h(x,s),_.current=o,v.current=a;return}}_.current={x:0,y:0},v.current={x:0,y:0},g()},[t,x,r,g,a,s,JSON.stringify(y),JSON.stringify(m),h,u,S,d,JSON.stringify(p)])}var hne={x:{[Ub.Backward]:!1,[Ub.Forward]:!1},y:{[Ub.Backward]:!1,[Ub.Forward]:!1}};function gne(e){let{delta:t,disabled:n}=e,r=Ky(t);return Wy(e=>{if(n||!r||!e)return hne;let i={x:Math.sign(t.x-r.x),y:Math.sign(t.y-r.y)};return{x:{[Ub.Backward]:e.x[Ub.Backward]||i.x===-1,[Ub.Forward]:e.x[Ub.Forward]||i.x===1},y:{[Ub.Backward]:e.y[Ub.Backward]||i.y===-1,[Ub.Forward]:e.y[Ub.Forward]||i.y===1}}},[n,t,r])}function _ne(e,t){let n=t==null?void 0:e.get(t),r=n?n.node.current:null;return Wy(e=>t==null?null:r??e??null,[r,t])}function vne(e,t){return(0,o.useMemo)(()=>e.reduce((e,n)=>{let{sensor:r}=n,i=r.activators.map(e=>({eventName:e.eventName,handler:t(e.handler,n)}));return[...e,...i]},[]),[e,t])}var ux;(function(e){e[e.Always=0]=`Always`,e[e.BeforeDragging=1]=`BeforeDragging`,e[e.WhileDragging=2]=`WhileDragging`})(ux||={});var dx;(function(e){e.Optimized=`optimized`})(dx||={});var fx=new Map;function px(e,t){let{dragging:n,dependencies:r,config:i}=t,[a,s]=(0,o.useState)(null),{frequency:c,measure:l,strategy:u}=i,d=(0,o.useRef)(e),f=_(),p=Uy(f),m=(0,o.useCallback)(function(e){e===void 0&&(e=[]),!p.current&&s(t=>t===null?e:t.concat(e.filter(e=>!t.includes(e))))},[p]),h=(0,o.useRef)(null),g=Wy(t=>{if(f&&!n)return fx;if(!t||t===fx||d.current!==e||a!=null){let t=new Map;for(let n of e){if(!n)continue;if(a&&a.length>0&&!a.includes(n.id)&&n.rect.current){t.set(n.id,n.rect.current);continue}let e=n.node.current,r=e?new qb(l(e),e):null;n.rect.current=r,r&&t.set(n.id,r)}return t}return t},[e,a,n,f,l]);return(0,o.useEffect)(()=>{d.current=e},[e]),(0,o.useEffect)(()=>{f||m()},[n,f]),(0,o.useEffect)(()=>{a&&a.length>0&&s(null)},[JSON.stringify(a)]),(0,o.useEffect)(()=>{f||typeof c!=`number`||h.current!==null||(h.current=setTimeout(()=>{m(),h.current=null},c))},[c,f,m,...r]),{droppableRects:g,measureDroppableContainers:m,measuringScheduled:a!=null};function _(){switch(u){case ux.Always:return!1;case ux.BeforeDragging:return n;default:return!n}}}function mx(e,t){return Wy(n=>e?n||(typeof t==`function`?t(e):e):null,[t,e])}function hx(e,t){return mx(e,t)}function gx(e){let{callback:t,disabled:n}=e,r=Vy(t),i=(0,o.useMemo)(()=>{if(n||typeof window>`u`||window.MutationObserver===void 0)return;let{MutationObserver:e}=window;return new e(r)},[r,n]);return(0,o.useEffect)(()=>()=>i?.disconnect(),[i]),i}function _x(e){let{callback:t,disabled:n}=e,r=Vy(t),i=(0,o.useMemo)(()=>{if(n||typeof window>`u`||window.ResizeObserver===void 0)return;let{ResizeObserver:e}=window;return new e(r)},[n]);return(0,o.useEffect)(()=>()=>i?.disconnect(),[i]),i}function vx(e){return new qb(Fb(e),e)}function yx(e,t,n){t===void 0&&(t=vx);let[r,i]=(0,o.useState)(null);function a(){i(r=>{if(!e)return null;if(e.isConnected===!1)return r??n??null;let i=t(e);return JSON.stringify(r)===JSON.stringify(i)?r:i})}let s=gx({callback(t){if(e)for(let n of t){let{type:t,target:r}=n;if(t===`childList`&&r instanceof HTMLElement&&r.contains(e)){a();break}}}}),c=_x({callback:a});return By(()=>{a(),e?(c?.observe(e),s?.observe(document.body,{childList:!0,subtree:!0})):(c?.disconnect(),s?.disconnect())},[e]),r}function bx(e){return jb(e,mx(e))}var xx=[];function Sx(e){let t=(0,o.useRef)(e),n=Wy(n=>e?n&&n!==xx&&e&&t.current&&e.parentNode===t.current.parentNode?n:Lb(e):xx,[e]);return(0,o.useEffect)(()=>{t.current=e},[e]),n}function Cx(e){let[t,n]=(0,o.useState)(null),r=(0,o.useRef)(e),i=(0,o.useCallback)(e=>{let t=zb(e.target);t&&n(e=>e?(e.set(t,Hb(t)),new Map(e)):null)},[]);return(0,o.useEffect)(()=>{let t=r.current;if(e!==t){a(t);let o=e.map(e=>{let t=zb(e);return t?(t.addEventListener(`scroll`,i,{passive:!0}),[t,Hb(t)]):null}).filter(e=>e!=null);n(o.length?new Map(o):null),r.current=e}return()=>{a(e),a(t)};function a(e){e.forEach(e=>{zb(e)?.removeEventListener(`scroll`,i)})}},[i,e]),(0,o.useMemo)(()=>e.length?t?Array.from(t.values()).reduce((e,t)=>Xy(e,t),yb):Kb(e):yb,[e,t])}function wx(e,t){t===void 0&&(t=[]);let n=(0,o.useRef)(null);return(0,o.useEffect)(()=>{n.current=null},t),(0,o.useEffect)(()=>{let t=e!==yb;t&&!n.current&&(n.current=e),!t&&n.current&&(n.current=null)},[e]),n.current?Zy(e,n.current):yb}function Tx(e){(0,o.useEffect)(()=>{if(!My)return;let t=e.map(e=>{let{sensor:t}=e;return t.setup==null?void 0:t.setup()});return()=>{for(let e of t)e?.()}},e.map(e=>{let{sensor:t}=e;return t}))}function Ex(e,t){return(0,o.useMemo)(()=>e.reduce((e,n)=>{let{eventName:r,handler:i}=n;return e[r]=e=>{i(e,t)},e},{}),[e,t])}function Dx(e){return(0,o.useMemo)(()=>e?$te(e):null,[e])}var Ox=[];function kx(e,t){t===void 0&&(t=Fb);let[n]=e,r=Dx(n?Fy(n):null),[i,a]=(0,o.useState)(Ox);function s(){a(()=>e.length?e.map(e=>Wb(e)?r:new qb(t(e),e)):Ox)}let c=_x({callback:s});return By(()=>{c?.disconnect(),s(),e.forEach(e=>c?.observe(e))},[e]),i}function Ax(e){if(!e)return null;if(e.children.length>1)return e;let t=e.children[0];return Ly(t)?t:e}function jx(e){let{measure:t}=e,[n,r]=(0,o.useState)(null),i=_x({callback:(0,o.useCallback)(e=>{for(let{target:n}of e)if(Ly(n)){r(e=>{let r=t(n);return e?{...e,width:r.width,height:r.height}:r});break}},[t])}),[a,s]=Gy((0,o.useCallback)(e=>{let n=Ax(e);i?.disconnect(),n&&i?.observe(n),r(n?t(n):null)},[t,i]));return(0,o.useMemo)(()=>({nodeRef:a,rect:n,setRef:s}),[n,a,s])}var Mx=[{sensor:rx,options:{}},{sensor:$b,options:{}}],Nx={current:{}},Px={draggable:{measure:Ib},droppable:{measure:Ib,strategy:ux.WhileDragging,frequency:dx.Optimized},dragOverlay:{measure:Fb}},Fx=class extends Map{get(e){return e==null?void 0:super.get(e)??void 0}toArray(){return Array.from(this.values())}getEnabled(){return this.toArray().filter(e=>{let{disabled:t}=e;return!t})}getNodeFor(e){return this.get(e)?.node.current??void 0}},Ix={activatorEvent:null,active:null,activeNode:null,activeNodeRect:null,collisions:null,containerNodeRect:null,draggableNodes:new Map,droppableRects:new Map,droppableContainers:new Fx,over:null,dragOverlay:{nodeRef:{current:null},rect:null,setRef:gb},scrollableAncestors:[],scrollableAncestorRects:[],measuringConfiguration:Px,measureDroppableContainers:gb,windowRect:null,measuringScheduled:!1},Lx={activatorEvent:null,activators:[],active:null,activeNodeRect:null,ariaDescribedById:{draggable:``},dispatch:gb,draggableNodes:new Map,over:null,measureDroppableContainers:gb},Rx=(0,o.createContext)(Lx),zx=(0,o.createContext)(Ix);function Bx(){return{draggable:{active:null,initialCoordinates:{x:0,y:0},nodes:new Map,translate:{x:0,y:0}},droppable:{containers:new Fx}}}function Vx(e,t){switch(t.type){case hb.DragStart:return{...e,draggable:{...e.draggable,initialCoordinates:t.initialCoordinates,active:t.active}};case hb.DragMove:return e.draggable.active==null?e:{...e,draggable:{...e.draggable,translate:{x:t.coordinates.x-e.draggable.initialCoordinates.x,y:t.coordinates.y-e.draggable.initialCoordinates.y}}};case hb.DragEnd:case hb.DragCancel:return{...e,draggable:{...e.draggable,active:null,initialCoordinates:{x:0,y:0},translate:{x:0,y:0}}};case hb.RegisterDroppable:{let{element:n}=t,{id:r}=n,i=new Fx(e.droppable.containers);return i.set(r,n),{...e,droppable:{...e.droppable,containers:i}}}case hb.SetDroppableDisabled:{let{id:n,key:r,disabled:i}=t,a=e.droppable.containers.get(n);if(!a||r!==a.key)return e;let o=new Fx(e.droppable.containers);return o.set(n,{...a,disabled:i}),{...e,droppable:{...e.droppable,containers:o}}}case hb.UnregisterDroppable:{let{id:n,key:r}=t,i=e.droppable.containers.get(n);if(!i||r!==i.key)return e;let a=new Fx(e.droppable.containers);return a.delete(n),{...e,droppable:{...e.droppable,containers:a}}}default:return e}}function Hx(e){let{disabled:t}=e,{active:n,activatorEvent:r,draggableNodes:i}=(0,o.useContext)(Rx),a=Ky(r),s=Ky(n?.id);return(0,o.useEffect)(()=>{if(!t&&!r&&a&&s!=null){if(!$y(a)||document.activeElement===a.target)return;let e=i.get(s);if(!e)return;let{activatorNode:t,node:n}=e;if(!t.current&&!n.current)return;requestAnimationFrame(()=>{for(let e of[t.current,n.current]){if(!e)continue;let t=ib(e);if(t){t.focus();break}}})}},[r,t,i,s,a]),null}function Ux(e,t){let{transform:n,...r}=t;return e!=null&&e.length?e.reduce((e,t)=>t({transform:e,...r}),n):n}function Wx(e){return(0,o.useMemo)(()=>({draggable:{...Px.draggable,...e?.draggable},droppable:{...Px.droppable,...e?.droppable},dragOverlay:{...Px.dragOverlay,...e?.dragOverlay}}),[e?.draggable,e?.droppable,e?.dragOverlay])}function Gx(e){let{activeNode:t,measure:n,initialRect:r,config:i=!0}=e,a=(0,o.useRef)(!1),{x:s,y:c}=typeof i==`boolean`?{x:i,y:i}:i;By(()=>{if(!s&&!c||!t){a.current=!1;return}if(a.current||!r)return;let e=t?.node.current;if(!e||e.isConnected===!1)return;let i=jb(n(e),r);if(s||(i.x=0),c||(i.y=0),a.current=!0,Math.abs(i.x)>0||Math.abs(i.y)>0){let t=Rb(e);t&&t.scrollBy({top:i.y,left:i.x})}},[t,s,c,r,n])}var Kx=(0,o.createContext)({...yb,scaleX:1,scaleY:1}),qx;(function(e){e[e.Uninitialized=0]=`Uninitialized`,e[e.Initializing=1]=`Initializing`,e[e.Initialized=2]=`Initialized`})(qx||={});var Jx=(0,o.memo)(function(e){let{id:t,accessibility:n,autoScroll:r=!0,children:i,sensors:a=Mx,collisionDetection:s=kb,measuring:c,modifiers:l,...u}=e,[d,f]=(0,o.useReducer)(Vx,void 0,Bx),[p,m]=db(),[h,g]=(0,o.useState)(qx.Uninitialized),_=h===qx.Initialized,{draggable:{active:v,nodes:y,translate:b},droppable:{containers:x}}=d,S=v==null?null:y.get(v),C=(0,o.useRef)({initial:null,translated:null}),w=(0,o.useMemo)(()=>v==null?null:{id:v,data:S?.data??Nx,rect:C},[v,S]),T=(0,o.useRef)(null),[E,D]=(0,o.useState)(null),[O,k]=(0,o.useState)(null),A=Uy(u,Object.values(u)),j=Jy(`DndDescribedBy`,t),M=(0,o.useMemo)(()=>x.getEnabled(),[x]),N=Wx(c),{droppableRects:ee,measureDroppableContainers:te,measuringScheduled:ne}=px(M,{dragging:_,dependencies:[b.x,b.y],config:N.droppable}),P=_ne(y,v),re=(0,o.useMemo)(()=>O?tb(O):null,[O]),ie=Ne(),ae=hx(P,N.draggable.measure);Gx({activeNode:v==null?null:y.get(v),config:ie.layoutShiftCompensation,initialRect:ae,measure:N.draggable.measure});let F=yx(P,N.draggable.measure,ae),oe=yx(P?P.parentElement:null),se=(0,o.useRef)({activatorEvent:null,active:null,activeNode:P,collisionRect:null,collisions:null,droppableRects:ee,draggableNodes:y,draggingNode:null,draggingNodeRect:null,droppableContainers:x,over:null,scrollableAncestors:[],scrollAdjustedTranslate:null}),ce=x.getNodeFor(se.current.over?.id),I=jx({measure:N.dragOverlay.measure}),le=I.nodeRef.current??P,ue=_?I.rect??F:null,de=!!(I.nodeRef.current&&I.rect),fe=bx(de?null:F),pe=Dx(le?Fy(le):null),me=Sx(_?ce??P:null),he=kx(me),ge=Ux(l,{transform:{x:b.x-fe.x,y:b.y-fe.y,scaleX:1,scaleY:1},activatorEvent:O,active:w,activeNodeRect:F,containerNodeRect:oe,draggingNodeRect:ue,over:se.current.over,overlayNodeRect:I.rect,scrollableAncestors:me,scrollableAncestorRects:he,windowRect:pe}),_e=re?Xy(re,b):null,ve=Cx(me),ye=wx(ve),be=wx(ve,[F]),xe=Xy(ge,ye),Se=ue?Nb(ue,ge):null,Ce=w&&Se?s({active:w,collisionRect:Se,droppableRects:ee,droppableContainers:M,pointerCoordinates:_e}):null,we=wb(Ce,`id`),[Te,Ee]=(0,o.useState)(null),De=Ab(de?ge:Xy(ge,be),Te?.rect??null,F),Oe=(0,o.useRef)(null),ke=(0,o.useCallback)((e,t)=>{let{sensor:n,options:r}=t;if(T.current==null)return;let i=y.get(T.current);if(!i)return;let a=e.nativeEvent,o=new n({active:T.current,activeNode:i,event:a,options:r,context:se,onAbort(e){if(!y.get(e))return;let{onDragAbort:t}=A.current,n={id:e};t?.(n),p({type:`onDragAbort`,event:n})},onPending(e,t,n,r){if(!y.get(e))return;let{onDragPending:i}=A.current,a={id:e,constraint:t,initialCoordinates:n,offset:r};i?.(a),p({type:`onDragPending`,event:a})},onStart(e){let t=T.current;if(t==null)return;let n=y.get(t);if(!n)return;let{onDragStart:r}=A.current,i={activatorEvent:a,active:{id:t,data:n.data,rect:C}};(0,Fn.unstable_batchedUpdates)(()=>{r?.(i),g(qx.Initializing),f({type:hb.DragStart,initialCoordinates:e,active:t}),p({type:`onDragStart`,event:i}),D(Oe.current),k(a)})},onMove(e){f({type:hb.DragMove,coordinates:e})},onEnd:s(hb.DragEnd),onCancel:s(hb.DragCancel)});Oe.current=o;function s(e){return async function(){let{active:t,collisions:n,over:r,scrollAdjustedTranslate:i}=se.current,o=null;if(t&&i){let{cancelDrop:s}=A.current;o={activatorEvent:a,active:t,collisions:n,delta:i,over:r},e===hb.DragEnd&&typeof s==`function`&&await Promise.resolve(s(o))&&(e=hb.DragCancel)}T.current=null,(0,Fn.unstable_batchedUpdates)(()=>{f({type:e}),g(qx.Uninitialized),Ee(null),D(null),k(null),Oe.current=null;let t=e===hb.DragEnd?`onDragEnd`:`onDragCancel`;if(o){let e=A.current[t];e?.(o),p({type:t,event:o})}})}}},[y]),Ae=vne(a,(0,o.useCallback)((e,t)=>(n,r)=>{let i=n.nativeEvent,a=y.get(r);if(T.current!==null||!a||i.dndKit||i.defaultPrevented)return;let o={active:a};e(n,t.options,o)===!0&&(i.dndKit={capturedBy:t.sensor},T.current=r,ke(n,t))},[y,ke]));Tx(a),By(()=>{F&&h===qx.Initializing&&g(qx.Initialized)},[F,h]),(0,o.useEffect)(()=>{let{onDragMove:e}=A.current,{active:t,activatorEvent:n,collisions:r,over:i}=se.current;if(!t||!n)return;let a={active:t,activatorEvent:n,collisions:r,delta:{x:xe.x,y:xe.y},over:i};(0,Fn.unstable_batchedUpdates)(()=>{e?.(a),p({type:`onDragMove`,event:a})})},[xe.x,xe.y]),(0,o.useEffect)(()=>{let{active:e,activatorEvent:t,collisions:n,droppableContainers:r,scrollAdjustedTranslate:i}=se.current;if(!e||T.current==null||!t||!i)return;let{onDragOver:a}=A.current,o=r.get(we),s=o&&o.rect.current?{id:o.id,rect:o.rect.current,data:o.data,disabled:o.disabled}:null,c={active:e,activatorEvent:t,collisions:n,delta:{x:i.x,y:i.y},over:s};(0,Fn.unstable_batchedUpdates)(()=>{Ee(s),a?.(c),p({type:`onDragOver`,event:c})})},[we]),By(()=>{se.current={activatorEvent:O,active:w,activeNode:P,collisionRect:Se,collisions:Ce,droppableRects:ee,draggableNodes:y,draggingNode:le,draggingNodeRect:ue,droppableContainers:x,over:Te,scrollableAncestors:me,scrollAdjustedTranslate:xe},C.current={initial:ue,translated:Se}},[w,P,Ce,Se,y,le,ue,ee,x,Te,me,xe]),mne({...ie,delta:b,draggingRect:Se,pointerCoordinates:_e,scrollableAncestors:me,scrollableAncestorRects:he});let je=(0,o.useMemo)(()=>({active:w,activeNode:P,activeNodeRect:F,activatorEvent:O,collisions:Ce,containerNodeRect:oe,dragOverlay:I,draggableNodes:y,droppableContainers:x,droppableRects:ee,over:Te,measureDroppableContainers:te,scrollableAncestors:me,scrollableAncestorRects:he,measuringConfiguration:N,measuringScheduled:ne,windowRect:pe}),[w,P,F,O,Ce,oe,I,y,x,ee,Te,te,me,he,N,ne,pe]),Me=(0,o.useMemo)(()=>({activatorEvent:O,activators:Ae,active:w,activeNodeRect:F,ariaDescribedById:{draggable:j},dispatch:f,draggableNodes:y,over:Te,measureDroppableContainers:te}),[O,Ae,w,F,f,j,y,Te,te]);return o.createElement(lb.Provider,{value:m},o.createElement(Rx.Provider,{value:Me},o.createElement(zx.Provider,{value:je},o.createElement(Kx.Provider,{value:De},i)),o.createElement(Hx,{disabled:n?.restoreFocus===!1})),o.createElement(mb,{...n,hiddenTextDescribedById:j}));function Ne(){let e=E?.autoScrollEnabled===!1,t=typeof r==`object`?r.enabled===!1:r===!1,n=_&&!e&&!t;return typeof r==`object`?{...r,enabled:n}:{enabled:n}}}),Yx=(0,o.createContext)(null),Xx=`button`,Zx=`Draggable`;function Qx(e){let{id:t,data:n,disabled:r=!1,attributes:i}=e,a=Jy(Zx),{activators:s,activatorEvent:c,active:l,activeNodeRect:u,ariaDescribedById:d,draggableNodes:f,over:p}=(0,o.useContext)(Rx),{role:m=Xx,roleDescription:h=`draggable`,tabIndex:g=0}=i??{},_=l?.id===t,v=(0,o.useContext)(_?Kx:Yx),[y,b]=Gy(),[x,S]=Gy(),C=Ex(s,t),w=Uy(n);return By(()=>(f.set(t,{id:t,key:a,node:y,activatorNode:x,data:w}),()=>{let e=f.get(t);e&&e.key===a&&f.delete(t)}),[f,t]),{active:l,activatorEvent:c,activeNodeRect:u,attributes:(0,o.useMemo)(()=>({role:m,tabIndex:g,"aria-disabled":r,"aria-pressed":_&&m===Xx?!0:void 0,"aria-roledescription":h,"aria-describedby":d.draggable}),[r,m,g,_,h,d.draggable]),isDragging:_,listeners:r?void 0:C,node:y,over:p,setNodeRef:b,setActivatorNodeRef:S,transform:v}}function $x(){return(0,o.useContext)(zx)}var eS=`Droppable`,tS={timeout:25};function nS(e){let{data:t,disabled:n=!1,id:r,resizeObserverConfig:i}=e,a=Jy(eS),{active:s,dispatch:c,over:l,measureDroppableContainers:u}=(0,o.useContext)(Rx),d=(0,o.useRef)({disabled:n}),f=(0,o.useRef)(!1),p=(0,o.useRef)(null),m=(0,o.useRef)(null),{disabled:h,updateMeasurementsFor:g,timeout:_}={...tS,...i},v=Uy(g??r),y=_x({callback:(0,o.useCallback)(()=>{if(!f.current){f.current=!0;return}m.current!=null&&clearTimeout(m.current),m.current=setTimeout(()=>{u(Array.isArray(v.current)?v.current:[v.current]),m.current=null},_)},[_]),disabled:h||!s}),[b,x]=Gy((0,o.useCallback)((e,t)=>{y&&(t&&(y.unobserve(t),f.current=!1),e&&y.observe(e))},[y])),S=Uy(t);return(0,o.useEffect)(()=>{y&&b.current&&(y.disconnect(),f.current=!1,y.observe(b.current))},[b,y]),(0,o.useEffect)(()=>(c({type:hb.RegisterDroppable,element:{id:r,key:a,disabled:n,node:b,rect:p,data:S}}),()=>c({type:hb.UnregisterDroppable,key:a,id:r})),[r]),(0,o.useEffect)(()=>{n!==d.current.disabled&&(c({type:hb.SetDroppableDisabled,id:r,key:a,disabled:n}),d.current.disabled=n)},[r,a,n,c]),{active:s,rect:p,isOver:l?.id===r,node:b,over:l,setNodeRef:x}}function rS(e,t,n){let r=e.slice();return r.splice(n<0?r.length+n:n,0,r.splice(t,1)[0]),r}function iS(e,t){return e.reduce((e,n,r)=>{let i=t.get(n);return i&&(e[r]=i),e},Array(e.length))}function aS(e){return e!==null&&e>=0}function oS(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function sS(e){return typeof e==`boolean`?{draggable:e,droppable:e}:e}var cS=e=>{let{rects:t,activeIndex:n,overIndex:r,index:i}=e,a=rS(t,r,n),o=t[i],s=a[i];return!s||!o?null:{x:s.left-o.left,y:s.top-o.top,scaleX:s.width/o.width,scaleY:s.height/o.height}},lS={scaleX:1,scaleY:1},uS=e=>{let{activeIndex:t,activeNodeRect:n,index:r,rects:i,overIndex:a}=e,o=i[t]??n;if(!o)return null;if(r===t){let e=i[a];return e?{x:0,y:t<a?e.top+e.height-(o.top+o.height):e.top-o.top,...lS}:null}let s=dS(i,r,t);return r>t&&r<=a?{x:0,y:-o.height-s,...lS}:r<t&&r>=a?{x:0,y:o.height+s,...lS}:{x:0,y:0,...lS}};function dS(e,t,n){let r=e[t],i=e[t-1],a=e[t+1];return r?n<t?i?r.top-(i.top+i.height):a?a.top-(r.top+r.height):0:a?a.top-(r.top+r.height):i?r.top-(i.top+i.height):0:0}var fS=`Sortable`,pS=o.createContext({activeIndex:-1,containerId:fS,disableTransforms:!1,items:[],overIndex:-1,useDragOverlay:!1,sortedRects:[],strategy:cS,disabled:{draggable:!1,droppable:!1}});function mS(e){let{children:t,id:n,items:r,strategy:i=cS,disabled:a=!1}=e,{active:s,dragOverlay:c,droppableRects:l,over:u,measureDroppableContainers:d}=$x(),f=Jy(fS,n),p=c.rect!==null,m=(0,o.useMemo)(()=>r.map(e=>typeof e==`object`&&`id`in e?e.id:e),[r]),h=s!=null,g=s?m.indexOf(s.id):-1,_=u?m.indexOf(u.id):-1,v=(0,o.useRef)(m),y=!oS(m,v.current),b=_!==-1&&g===-1||y,x=sS(a);By(()=>{y&&h&&d(m)},[y,m,h,d]),(0,o.useEffect)(()=>{v.current=m},[m]);let S=(0,o.useMemo)(()=>({activeIndex:g,containerId:f,disabled:x,disableTransforms:b,items:m,overIndex:_,useDragOverlay:p,sortedRects:iS(m,l),strategy:i}),[g,f,x.draggable,x.droppable,b,m,_,l,p,i]);return o.createElement(pS.Provider,{value:S},t)}var hS=e=>{let{id:t,items:n,activeIndex:r,overIndex:i}=e;return rS(n,r,i).indexOf(t)},gS=e=>{let{containerId:t,isSorting:n,wasDragging:r,index:i,items:a,newIndex:o,previousItems:s,previousContainerId:c,transition:l}=e;return!l||!r||s!==a&&i===o?!1:n?!0:o!==i&&t===c},_S={duration:200,easing:`ease`},vS=`transform`,yS=nb.Transition.toString({property:vS,duration:0,easing:`linear`}),bS={roleDescription:`sortable`};function xS(e){let{disabled:t,index:n,node:r,rect:i}=e,[a,s]=(0,o.useState)(null),c=(0,o.useRef)(n);return By(()=>{if(!t&&n!==c.current&&r.current){let e=i.current;if(e){let t=Fb(r.current,{ignoreTransform:!0}),n={x:e.left-t.left,y:e.top-t.top,scaleX:e.width/t.width,scaleY:e.height/t.height};(n.x||n.y)&&s(n)}}n!==c.current&&(c.current=n)},[t,n,r,i]),(0,o.useEffect)(()=>{a&&s(null)},[a]),a}function SS(e){let{animateLayoutChanges:t=gS,attributes:n,disabled:r,data:i,getNewIndex:a=hS,id:s,strategy:c,resizeObserverConfig:l,transition:u=_S}=e,{items:d,containerId:f,activeIndex:p,disabled:m,disableTransforms:h,sortedRects:g,overIndex:_,useDragOverlay:v,strategy:y}=(0,o.useContext)(pS),b=CS(r,m),x=d.indexOf(s),S=(0,o.useMemo)(()=>({sortable:{containerId:f,index:x,items:d},...i}),[f,i,x,d]),C=(0,o.useMemo)(()=>d.slice(d.indexOf(s)),[d,s]),{rect:w,node:T,isOver:E,setNodeRef:D}=nS({id:s,data:S,disabled:b.droppable,resizeObserverConfig:{updateMeasurementsFor:C,...l}}),{active:O,activatorEvent:k,activeNodeRect:A,attributes:j,setNodeRef:M,listeners:N,isDragging:ee,over:te,setActivatorNodeRef:ne,transform:P}=Qx({id:s,data:S,attributes:{...bS,...n},disabled:b.draggable}),re=jy(D,M),ie=!!O,ae=ie&&!h&&aS(p)&&aS(_),F=!v&&ee,oe=ae?(F&&ae?P:null)??(c??y)({rects:g,activeNodeRect:A,activeIndex:p,overIndex:_,index:x}):null,se=aS(p)&&aS(_)?a({id:s,items:d,activeIndex:p,overIndex:_}):x,ce=O?.id,I=(0,o.useRef)({activeId:ce,items:d,newIndex:se,containerId:f}),le=d!==I.current.items,ue=t({active:O,containerId:f,isDragging:ee,isSorting:ie,id:s,index:x,items:d,newIndex:I.current.newIndex,previousItems:I.current.items,previousContainerId:I.current.containerId,transition:u,wasDragging:I.current.activeId!=null}),de=xS({disabled:!ue,index:x,node:T,rect:w});return(0,o.useEffect)(()=>{ie&&I.current.newIndex!==se&&(I.current.newIndex=se),f!==I.current.containerId&&(I.current.containerId=f),d!==I.current.items&&(I.current.items=d)},[ie,se,f,d]),(0,o.useEffect)(()=>{if(ce===I.current.activeId)return;if(ce!=null&&I.current.activeId==null){I.current.activeId=ce;return}let e=setTimeout(()=>{I.current.activeId=ce},50);return()=>clearTimeout(e)},[ce]),{active:O,activeIndex:p,attributes:j,data:S,rect:w,index:x,newIndex:se,items:d,isOver:E,isSorting:ie,isDragging:ee,listeners:N,node:T,overIndex:_,over:te,setNodeRef:re,setActivatorNodeRef:ne,setDroppableNodeRef:D,setDraggableNodeRef:M,transform:de??oe,transition:fe()};function fe(){if(de||le&&I.current.newIndex===x)return yS;if(!(F&&!$y(k)||!u)&&(ie||ue))return nb.Transition.toString({...u,property:vS})}}function CS(e,t){return typeof e==`boolean`?{draggable:e,droppable:!1}:{draggable:e?.draggable??t.draggable,droppable:e?.droppable??t.droppable}}function wS(e){if(!e)return!1;let t=e.data.current;return!!(t&&`sortable`in t&&typeof t.sortable==`object`&&`containerId`in t.sortable&&`items`in t.sortable&&`index`in t.sortable)}var TS=[q.Down,q.Right,q.Up,q.Left],ES=(e,t)=>{let{context:{active:n,collisionRect:r,droppableRects:i,droppableContainers:a,over:o,scrollableAncestors:s}}=t;if(TS.includes(e.code)){if(e.preventDefault(),!n||!r)return;let t=[];a.getEnabled().forEach(n=>{if(!n||n!=null&&n.disabled)return;let a=i.get(n.id);if(a)switch(e.code){case q.Down:r.top<a.top&&t.push(n);break;case q.Up:r.top>a.top&&t.push(n);break;case q.Left:r.left>a.left&&t.push(n);break;case q.Right:r.left<a.left&&t.push(n)}});let c=Db({active:n,collisionRect:r,droppableRects:i,droppableContainers:t,pointerCoordinates:null}),l=wb(c,`id`);if(l===o?.id&&c.length>1&&(l=c[1].id),l!=null){let e=a.get(n.id),t=a.get(l),o=t?i.get(t.id):null,c=t?.node.current;if(c&&o&&e&&t){let n=Lb(c).some((e,t)=>s[t]!==e),i=DS(e,t),a=OS(e,t),l=n||!i?{x:0,y:0}:{x:a?r.width-o.width:0,y:a?r.height-o.height:0},u={x:o.left,y:o.top};return l.x&&l.y?u:Zy(u,l)}}}};function DS(e,t){return!wS(e)||!wS(t)?!1:e.data.current.sortable.containerId===t.data.current.sortable.containerId}function OS(e,t){return!wS(e)||!wS(t)||!DS(e,t)?!1:e.data.current.sortable.index<t.data.current.sortable.index}var kS=Date.UTC(2026,9,6,9,41),AS=(e,t)=>{let n=(e^Math.imul(t+2654435769,2246822507))>>>0;return n=Math.imul(n^n>>>16,2246822507),n=Math.imul(n^n>>>13,3266489909),(n^n>>>16)>>>0},jS=(e,t)=>{let n=AS(e,t);return()=>{n=n+1831565813>>>0;let e=n;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}},MS=[{id:`u1`,name:`Sanne M.`,initials:`SM`,hue:250,role:`Admin`},{id:`u2`,name:`Jonas K.`,initials:`JK`,hue:160,role:`Sales`},{id:`u3`,name:`Lieke D.`,initials:`LD`,hue:20,role:`Finance`},{id:`u4`,name:`Tobias R.`,initials:`TR`,hue:310,role:`Warehouse`},{id:`u5`,name:`Imke V.`,initials:`IV`,hue:200,role:`Sales`},{id:`u6`,name:`Marek W.`,initials:`MW`,hue:80,role:`Warehouse`},{id:`u7`,name:`Hanna B.`,initials:`HB`,hue:350,role:`Finance`},{id:`u8`,name:`Daan P.`,initials:`DP`,hue:120,role:`Sales`}],NS=e=>MS.find(t=>t.id===e)??MS[0];MS.filter(e=>e.role===`Sales`);var PS=[[`M8 hex bolt A2, 100 pcs`,`FST`,1890],[`M10 hex nut A2, 100 pcs`,`FST`,1240],[`Stainless washer 8 mm, 250 pcs`,`FST`,990],[`Cable tie 300 mm, 100 pcs`,`ELC`,650],[`Cable gland M20, 25 pcs`,`ELC`,2340],[`Junction box IP65`,`ELC`,1480],[`Hydraulic hose 1/2 in, 5 m`,`HYD`,8650],[`Hydraulic coupling 3/8 in`,`HYD`,1895],[`Pallet wrap 500 mm`,`PKG`,740],[`Corrugated box 400 x 300`,`PKG`,215],[`Bubble wrap roll 50 m`,`PKG`,1990],[`Safety gloves, size L`,`PPE`,395],[`Safety glasses, clear`,`PPE`,450],[`Ear defenders SNR 31`,`PPE`,1295],[`Ball bearing 6204-2RS`,`BRG`,685],[`Taper roller bearing 30205`,`BRG`,1420],[`Timing belt HTD 5M, 600 mm`,`BLT`,2780],[`V-belt SPA 1250`,`BLT`,1360],[`Grease cartridge, 400 g`,`LUB`,920],[`Machine oil ISO 68, 5 l`,`LUB`,3950],[`Angle grinder disc 125 mm, 10 pcs`,`ABR`,1880],[`Drill bit set HSS, 19 pcs`,`TLS`,3490],[`Torque wrench 20-100 Nm`,`TLS`,14900],[`Pneumatic cylinder 40 x 100`,`PNE`,6120],[`Air hose PU 8 mm, 20 m`,`PNE`,2475],[`LED panel 600 x 600, 40 W`,`LGT`,3290],[`Pallet label roll 100 x 150`,`LBL`,1175],[`Thermal printer ribbon`,`LBL`,890],[`Euro pallet EPAL, used`,`PLT`,1150],[`Roll container, galvanised`,`PLT`,9800]];PS.length;var FS=e=>{let[t,n,r]=PS[e%PS.length],i=e%PS.length;return{id:`P-${200+i}`,sku:`${n}-${String(1e3+i*7).padStart(4,`0`)}`,name:t,category:n,priceCents:r}},IS=e=>e.quantity*e.unitPriceCents,LS=(e,t=.21)=>{let n=e.reduce((e,t)=>e+IS(t),0),r=Math.round(n*t);return{subtotalCents:n,vatCents:r,totalCents:n+r}},RS=864e5,zS=e=>Array.from({length:e},(t,n)=>{let r=kS-(e-1-n)*RS,i=new Date(r).getUTCDay();return{at:r,count:Math.round((i===0||i===6?120:410)*(.8+jS(71,n)()*.45)*(1+n/e/3))}}),BS=e=>{if(e===`day`)return zS(30);let t=zS(84);return Array.from({length:12},(e,n)=>{let r=t.slice(n*7,n*7+7);return{at:r[0].at,count:r.reduce((e,t)=>e+t.count,0)}})},VS=`grid grid-cols-[28px_minmax(0,1fr)_88px_112px_112px_32px] items-center gap-2 pointer-coarse:grid-cols-[44px_minmax(0,1fr)_88px_112px_112px_44px]`,HS=({items:e,label:t})=>{let[n,r]=(0,o.useState)(!1),i=(0,o.useRef)(null);return(0,o.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)(Ve,{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 text-[13px] 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:z(`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))})]})},US=({value:e,onCommit:t,format:n,parse:r,label:i,width:a=`w-full`})=>{let[s,c]=(0,o.useState)(null);return(0,B.jsx)(`input`,{"aria-label":i,inputMode:`decimal`,value:s??n(e),onFocus:e=>e.currentTarget.select(),onChange:e=>c(e.target.value),onBlur:()=>{if(s===null)return;let e=r(s);c(null),Number.isFinite(e)&&e>=0&&t(e)},onKeyDown:e=>e.key===`Enter`&&e.currentTarget.blur(),className:z(`h-7 rounded-md border border-transparent bg-transparent px-2 text-right text-[13px] tabular-nums text-foreground outline-none hover:border-border-strong focus:border-primary focus:bg-background focus:ring-2 focus:ring-primary/20`,a)})},WS=e=>Math.round(Number(e.replace(`,`,`.`).replace(/[^0-9.]/g,``))*100),GS=({line:e,position:t,count:n,reorderable:r,editable:i,onChange:a,onRemove:o,onMove:s})=>{let{attributes:c,listeners:l,setNodeRef:u,setActivatorNodeRef:d,transform:f,transition:p,isDragging:m}=SS({id:e.id,disabled:!r}),h=[...r?[{label:`Move up`,disabled:t===0,onSelect:()=>s(t-1)},{label:`Move down`,disabled:t===n-1,onSelect:()=>s(t+1)}]:[],...i?[{label:`Remove line`,destructive:!0,onSelect:o}]:[]];return(0,B.jsxs)(`div`,{ref:u,"data-line-id":e.id,style:{transform:f?`translate3d(0, ${f.y}px, 0)`:void 0,transition:p},className:z(`group relative border-b border-border bg-background px-2 py-1 last:border-b-0 hover:bg-surface`,VS,m&&`z-10 bg-surface opacity-80 shadow-pop`),children:[r?(0,B.jsx)(`button`,{ref:d,type:`button`,"aria-label":`Drag to reorder ${e.description}`,...c,...l,style:{touchAction:`none`},className:`flex size-7 cursor-grab items-center justify-center rounded text-faint-foreground opacity-60 hover:bg-muted hover:opacity-100 focus-visible:opacity-100 active:cursor-grabbing pointer-coarse:size-11`,children:(0,B.jsx)(tee,{className:`size-4`})}):(0,B.jsx)(`span`,{}),(0,B.jsxs)(`div`,{className:`min-w-0`,children:[(0,B.jsx)(`p`,{className:`truncate text-[13px] text-foreground`,children:e.description}),(0,B.jsx)(`p`,{className:`font-mono text-[11px] text-faint-foreground`,children:e.productId})]}),i?(0,B.jsx)(US,{label:`Quantity`,value:e.quantity,format:String,parse:e=>Math.round(Number(e)),onCommit:e=>a({quantity:e})}):(0,B.jsx)(`span`,{className:`px-2 text-right text-[13px] tabular-nums`,children:e.quantity}),i?(0,B.jsx)(US,{label:`Unit price`,value:e.unitPriceCents,format:e=>(e/100).toFixed(2),parse:WS,onCommit:e=>a({unitPriceCents:e})}):(0,B.jsx)(`span`,{className:`px-2 text-right text-[13px] tabular-nums`,children:(e.unitPriceCents/100).toFixed(2)}),(0,B.jsx)(`span`,{className:`px-2 text-right text-[13px] font-medium tabular-nums text-foreground`,children:Of(IS(e))}),h.length>0?(0,B.jsx)(HS,{label:`Actions for ${e.description}`,items:h}):(0,B.jsx)(`span`,{})]})},KS=(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},qS=({lines:e,vatRate:t})=>{let n=LS(e,t);return(0,B.jsxs)(`dl`,{className:`ml-auto grid w-64 grid-cols-[1fr_auto] gap-x-6 gap-y-1 px-2 pt-3 text-[13px] tabular-nums`,children:[(0,B.jsx)(`dt`,{className:`text-muted-foreground`,children:`Subtotal`}),(0,B.jsx)(`dd`,{className:`text-right text-foreground`,children:Of(n.subtotalCents)}),(0,B.jsxs)(`dt`,{className:`text-muted-foreground`,children:[`VAT `,Math.round(t*100),`%`]}),(0,B.jsx)(`dd`,{className:`text-right text-foreground`,children:Of(n.vatCents)}),(0,B.jsx)(`dt`,{className:`mt-1 border-t border-border pt-2 font-semibold text-foreground`,children:`Total`}),(0,B.jsx)(`dd`,{className:`mt-1 border-t border-border pt-2 text-right text-[15px] font-semibold text-foreground`,children:Of(n.totalCents)})]})},JS=`px-2 text-[11px] font-medium uppercase tracking-wide text-muted-foreground`,YS=`To pick up a line, press space or enter on its drag handle. Use the up and down arrow keys to move it, space or enter to drop it, and escape to cancel. The row menu also has Move up and Move down.`,XS=e=>{let t=t=>e.find(e=>e.id===t)?.description??`line`,n=t=>e.findIndex(e=>e.id===t)+1;return{onDragStart:({active:r})=>`Picked up ${t(r.id)}, line ${n(r.id)} of ${e.length}.`,onDragOver:({active:r,over:i})=>i?`${t(r.id)} is over line ${n(i.id)} of ${e.length}.`:void 0,onDragEnd:({active:r,over:i})=>i?`${t(r.id)} was dropped at line ${n(i.id)} of ${e.length}.`:`${t(r.id)} was dropped where it started.`,onDragCancel:({active:e})=>`Moving ${t(e.id)} was cancelled. It is back at line ${n(e.id)}.`}},ZS=({lines:e,onChange:t,onReorder:n,vatRate:r=.21,readOnly:i,reorderable:a=!i})=>{let o=vb(_b(ax,{activationConstraint:{distance:4}}),_b(sx,{activationConstraint:{delay:250,tolerance:5}}),_b($b,{coordinateGetter:ES})),s=(r,i)=>{let a=e[r];!a||i<0||i>=e.length||r===i||(n??(e=>t(e)))(KS(e,r,i),{id:a.id,from:r,to:i})};return(0,B.jsxs)(`div`,{children:[(0,B.jsxs)(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:[(0,B.jsxs)(`div`,{className:`${VS} border-b border-border bg-surface px-2 py-2`,children:[(0,B.jsx)(`span`,{}),(0,B.jsx)(`span`,{className:JS,children:`Item`}),(0,B.jsx)(`span`,{className:`${JS} text-right`,children:`Qty`}),(0,B.jsx)(`span`,{className:`${JS} text-right`,children:`Unit price`}),(0,B.jsx)(`span`,{className:`${JS} text-right`,children:`Line total`}),(0,B.jsx)(`span`,{})]}),(0,B.jsx)(Jx,{sensors:o,collisionDetection:Eb,onDragEnd:({active:t,over:n})=>{n&&t.id!==n.id&&s(e.findIndex(e=>e.id===t.id),e.findIndex(e=>e.id===n.id))},accessibility:{announcements:XS(e),screenReaderInstructions:{draggable:YS}},children:(0,B.jsx)(mS,{items:e.map(e=>e.id),strategy:uS,children:e.map((n,r)=>(0,B.jsx)(GS,{line:n,position:r,count:e.length,reorderable:a,editable:!i,onChange:r=>t(e.map(e=>e.id===n.id?{...e,...r}:e)),onRemove:()=>t(e.filter(e=>e.id!==n.id)),onMove:e=>s(r,e)},n.id))})}),!i&&(0,B.jsx)(`div`,{className:`border-t border-border bg-surface px-2 py-1.5`,children:(0,B.jsxs)(H,{variant:`ghost`,size:`sm`,onClick:()=>{let n=FS(e.length*3+1);t([...e,{id:`new-${e.length}-${n.id}`,productId:n.id,description:n.name,quantity:1,unitPriceCents:n.priceCents}])},children:[(0,B.jsx)(Lt,{className:`size-3.5`}),`Add line`]})})]}),(0,B.jsx)(qS,{lines:e,vatRate:r})]})},QS=({label:e,required:t,help:n,example:r,error:i,conflict:a,wide:o,children:s})=>(0,B.jsxs)(`div`,{className:o?`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`,{className:`text-[13px] font-medium text-foreground`,children:[e,t&&(0,B.jsx)(`span`,{className:`ml-0.5 text-danger-text`,"aria-label":`required`,children:`*`})]}),a&&(0,B.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-warning-text`,title:`${a.user.name} saved a different value`,children:[(0,B.jsx)(xn,{className:`size-3.5`}),(0,B.jsx)(md,{initials:a.user.initials,hue:a.user.hue,size:`xs`})]})]}),s,n&&(0,B.jsx)(`p`,{className:`mt-1.5 text-xs text-muted-foreground`,children:n}),r&&(0,B.jsxs)(`p`,{className:`mt-0.5 text-xs text-faint-foreground`,children:[`Example: `,r]}),i&&(0,B.jsx)(`p`,{className:`mt-1.5 text-xs font-medium text-danger-text`,children:i}),a&&(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-xs text-warning-text`,children:[(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`strong`,{children:a.user.name}),` saved this `,a.ago,`: `,(0,B.jsx)(`strong`,{children:a.theirValue})]}),(0,B.jsxs)(`span`,{className:`flex gap-1.5`,children:[(0,B.jsx)(H,{size:`sm`,onClick:a.onKeepMine,children:`Keep mine`}),(0,B.jsx)(H,{size:`sm`,onClick:a.onUseTheirs,children:`Use theirs`})]})]})]}),$S=({title:e,help:t,actions:n,children:r})=>{let i=(0,B.jsx)(`h2`,{className:`text-[15px] font-semibold text-foreground`,children:e});return(0,B.jsxs)(`section`,{className:`py-8 first:pt-8`,children:[n?(0,B.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-x-4 gap-y-2`,children:[i,n]}):i,t&&(0,B.jsx)(`p`,{className:`mt-1 max-w-xl text-[13px] leading-relaxed text-muted-foreground`,children:t}),(0,B.jsx)(`div`,{className:`mt-5`,children:r})]})},eC=({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:`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})=>(0,B.jsx)(`li`,{children:(0,B.jsxs)(`button`,{type:`button`,onClick:r,disabled:!!i||a,title:i,className:`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`,children:[(0,B.jsx)(n,{className:`size-4 shrink-0 text-muted-foreground md:mt-0.5`}),(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`span`,{className:`block text-[13px] font-medium 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})]})]})},e))})]}),tC=({rows:e})=>(0,B.jsx)(`dl`,{className:`grid grid-cols-[auto_1fr] gap-x-4 gap-y-2 text-[13px]`,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`,{className:`text-right tabular-nums text-foreground`,children:e.value})]},e.label))}),nC=({records:e,onNavigate:t})=>(0,B.jsx)(`ul`,{className:`-mx-2`,children:e.map(e=>(0,B.jsx)(`li`,{children:(0,B.jsxs)(`a`,{href:e.href??`#`,onClick:n=>{n.preventDefault(),e.href&&t?.(e.href)},className:`group flex items-center justify-between gap-3 rounded-md px-2 py-2 hover:bg-muted`,children:[(0,B.jsxs)(`span`,{className:`min-w-0`,children:[(0,B.jsx)(`span`,{className:`block text-[11px] uppercase tracking-wide text-faint-foreground`,children:e.kind}),(0,B.jsx)(`span`,{className:`block truncate text-[13px] font-medium text-primary-text`,children:e.label}),e.meta&&(0,B.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:e.meta})]}),(0,B.jsx)(_e,{className:`size-4 shrink-0 text-faint-foreground group-hover:text-foreground`})]})},e.label))}),rC=({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]}),iC=({title:e,rows:t})=>t.length===0?null:(0,B.jsx)(rC,{title:e,children:(0,B.jsx)(tC,{rows:t})}),aC=({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:[(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e}),(0,B.jsxs)(`div`,{className:`mt-1 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}),(0,B.jsx)(Cd,{tone:n.tone,children:n.label})]}),(0,B.jsx)(`p`,{className:`mt-1.5 text-xs text-muted-foreground`,children:r.name?(0,B.jsxs)(B.Fragment,{children:[`Last edited by `,(0,B.jsx)(`span`,{className:`font-medium text-foreground`,children:r.name}),` `,r.ago]}):(0,B.jsxs)(B.Fragment,{children:[`Last updated `,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)(hd,{people:i,size:`md`}),i.length,` viewing`]}),a]})]}),oC=({noun:e,collection:t,sections:n,saving:r,message:i,onSubmit:a,onCancel:o})=>(0,B.jsx)(`form`,{className:`flex-1`,onSubmit:e=>{e.preventDefault(),a()},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:[(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:t}),(0,B.jsxs)(`h1`,{className:`mt-1 text-2xl font-semibold tracking-tight`,children:[`New `,e.toLowerCase()]})]}),(0,B.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,B.jsx)(H,{className:`max-sm:min-h-11`,onClick:o,children:`Cancel`}),(0,B.jsxs)(H,{variant:`primary`,type:`submit`,className:`max-sm:min-h-11 max-sm:flex-1`,loading:r,children:[`Create `,e.toLowerCase()]})]})]}),i&&(0,B.jsx)(`div`,{className:`mt-4`,children:(0,B.jsx)(ny,{title:`Not created`,error:Error(i)})}),(0,B.jsx)(`div`,{className:`divide-y divide-border`,children:n.map(e=>(0,B.jsx)($S,{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)(QS,{label:e.label,required:e.required,help:e.help,error:e.error,wide:e.wide,children:e.editor},e.name))})},e.title))})]})}),sC=e=>typeof e==`object`&&!!e&&`key`in e,cC=(e,t)=>t.name!==e.tenant&&!t.readOnly&&(t.type===`relation`||Xv(t)),lC=(e,t)=>{let n=Object.values(e.fields).filter(t=>cC(e,t)).map(e=>e.name),r=new Set,i=(t?.layout??[]).flatMap(e=>{if(e.kind!==`section`)return[];let t=e.fields.filter(e=>n.includes(e)&&!r.has(e));return t.forEach(e=>r.add(e)),t.length>0?[{title:e.title,help:e.help,fields:t}]:[]}),a=n.filter(e=>!r.has(e));return a.length===0?i:[...i,{title:i.length===0?`Details`:`Other fields`,fields:a}]},uC=(e,t)=>(e?.primaryKey.length===1?e.fields[e.primaryKey[0]]?.type:void 0)===`integer`?Number(t):t,dC=(e,t,n)=>Object.fromEntries(Object.entries(n).flatMap(([n,r])=>{let i=e.fields[n];return i?sC(r)?[[n,uC(t[i.relation?.resource??``],r.key)]]:i.type===`boolean`?[[n,!!r]]:i.type===`file`?r?[[n,Zv(i,r)]]:[]:String(r).trim()===``?[]:[[n,Zv(i,r)]]:[]})),fC=e=>!e.nullable&&!e.default&&e.type!==`boolean`,pC=(e,t)=>e.type===`relation`?{key:t,label:t}:e.type===`boolean`?t===`true`:t,mC=(e,t,n={})=>Object.fromEntries(t.flatMap(t=>t.fields.flatMap(t=>{let r=e.fields[t];if(Object.hasOwn(n,t))return[[t,pC(r,n[t])]];let i=r.default;return!i||!(`value`in i)||i.value===null||i.value===void 0?[]:[[t,typeof i.value==`boolean`?i.value:String(i.value)]]}))),hC=e=>!!(e.default&&`db`in e.default),gC=(e,t)=>Object.fromEntries(Object.entries(e).filter(([e])=>e!==t)),_C=({resource:e,values:t})=>{let n=K(),r=n.resources[e],i=Uv(e);return r?Ey(i,`create`)?(0,B.jsx)(vC,{resource:e,values:t}):(0,B.jsxs)(Bv,{title:`Not allowed`,children:[`You cannot create `,n.views[e]?.names?.plural.toLowerCase()??e,`.`]}):(0,B.jsxs)(Bv,{title:`Not found`,children:[`There is no resource called `,e,`.`]})},vC=({resource:e,values:t})=>{let n=K(),r=n.resources[e],i=n.views[e],a=W(),s=pm(),{go:c}=Wv(),l=i?.names?.singular??G(e),u=Ay(i?.saveFeedback??`toast`,`New ${l.toLowerCase()}`),d=lC(r,i),[f,p]=(0,o.useState)(()=>mC(r,d,t)),[m,h]=(0,o.useState)({});(0,o.useEffect)(()=>{for(let[e,i]of Object.entries(t??{})){let t=n.resources[r.fields[e]?.relation?.resource??``];t&&R_(s,a,t,[i],n.views[t.name]).then(t=>{let n=t.get(i);n&&p(t=>sC(t[e])&&t[e].key===i?{...t,[e]:{key:i,label:n}}:t)})}},[t,n,r,a,s]);let g=(e,t)=>{h(t=>gC(t,e)),p(n=>({...n,[e]:t}))},_=()=>u.run(async()=>{let t;try{t=await a.create(e,dC(r,n.resources,f))}catch(e){throw vs(e)&&h(Object.fromEntries(e.errors.flatMap(e=>e.field?[[e.field,e.message]]:[]))),e}for(let t of[`page`,`list`,`first-page`,`map`,`facets`,`series`])s.invalidateQueries({queryKey:[t,e]});c({kind:`record`,resource:e,key:Mg(r,t.record)},{replace:!0})}),v=d.map(e=>({title:e.title,help:e.help,fields:e.fields.map(e=>{let t=r.fields[e],a=f[e],o=t.relation?n.resources[t.relation.resource]:void 0;return{name:e,label:i?.fields[e]?.label??G(e),help:i?.fields[e]?.help,required:fC(t),error:m[e],wide:!!i?.fields[e]?.multiline,editor:(0,B.jsx)(Ty,{field:t,hints:i?.fields[e],value:sC(a)?a.key:a??(t.type!==`boolean`&&``),stored:void 0,relationLabel:sC(a)?a.label:void 0,placeholder:hC(t)?`Set by the database`:void 0,relationPicker:o?{target:o,view:n.views[o.name]}:void 0,invalid:!!m[e],resource:r.name,onChange:t=>g(e,t)})}})}));return(0,B.jsx)(oC,{noun:l,collection:i?.names?.plural??G(e),sections:v,saving:u.phase===`saving`,message:u.message,onSubmit:()=>void _(),onCancel:()=>c({kind:`list`,resource:e})})};function yC(e){return bC(e)||typeof e==`function`||xC(e)}function bC(e){return typeof e==`function`&&(()=>{let t=Object.getPrototypeOf(e);return t.prototype&&t.prototype.isReactComponent})()}function xC(e){return typeof e==`object`&&typeof e.$$typeof==`symbol`&&[`react.memo`,`react.forward_ref`].includes(e.$$typeof.description)}function SC(e,t){return e==null?null:yC(e)?o.createElement(e,t):e}function CC(e){if(`cell`in e&&e.cell){let t=e.cell,n=t.column.columnDef,r=t,i=n;return r.getIsAggregated?.()?SC(i.aggregatedCell??n.cell,t.getContext()):r.getIsPlaceholder?.()?null:SC(n.cell,t.getContext())}return`header`in e&&e.header?SC(e.header.column.columnDef.header,e.header.getContext()):`footer`in e&&e.footer?SC(e.footer.column.columnDef.footer,e.footer.getContext()):null}function wC({update:e,notify:t,unwatched:n}){return{link:r,unlink:i,propagate:a,checkDirty:o,shallowPropagate:s};function r(e,t,n){let r=t.depsTail;if(r!==void 0&&r.dep===e)return;let i=r===void 0?t.deps:r.nextDep;if(i!==void 0&&i.dep===e){i.version=n,t.depsTail=i;return}let a=e.subsTail;if(a!==void 0&&a.version===n&&a.sub===t)return;let o=t.depsTail=e.subsTail={version:n,dep:e,sub:t,prevDep:r,nextDep:i,prevSub:a,nextSub:void 0};i!==void 0&&(i.prevDep=o),r===void 0?t.deps=o:r.nextDep=o,a===void 0?e.subs=o:a.nextSub=o}function i(e,t=e.sub){let r=e.dep,i=e.prevDep,a=e.nextDep,o=e.nextSub,s=e.prevSub;return a===void 0?t.depsTail=i:a.prevDep=i,i===void 0?t.deps=a:i.nextDep=a,o===void 0?r.subsTail=s:o.prevSub=s,s===void 0?(r.subs=o)===void 0&&n(r):s.nextSub=o,a}function a(e){let n=e.nextSub,r;top:do{let i=e.sub,a=i.flags;if(a&60?a&12?a&4?!(a&48)&&c(e,i)?(i.flags=a|40,a&=1):a=0:i.flags=a&-9|32:a=0:i.flags=a|32,a&2&&t(i),a&1){let t=i.subs;if(t!==void 0){let i=(e=t).nextSub;i!==void 0&&(r={value:n,prev:r},n=i);continue}}if((e=n)!==void 0){n=e.nextSub;continue}for(;r!==void 0;)if(e=r.value,r=r.prev,e!==void 0){n=e.nextSub;continue top}break}while(1)}function o(t,n){let r,i=0,a=!1;top:do{let o=t.dep,c=o.flags;if(n.flags&16)a=!0;else if((c&17)==17){if(e(o)){let e=o.subs;e.nextSub!==void 0&&s(e),a=!0}}else if((c&33)==33){(t.nextSub!==void 0||t.prevSub!==void 0)&&(r={value:t,prev:r}),t=o.deps,n=o,++i;continue}if(!a){let e=t.nextDep;if(e!==void 0){t=e;continue}}for(;i--;){let i=n.subs,o=i.nextSub!==void 0;if(o?(t=r.value,r=r.prev):t=i,a){if(e(n)){o&&s(i),n=t.sub;continue}a=!1}else n.flags&=-33;n=t.sub;let c=t.nextDep;if(c!==void 0){t=c;continue top}}return a}while(1)}function s(e){do{let n=e.sub,r=n.flags;(r&48)==32&&(n.flags=r|16,(r&6)==2&&t(n))}while((e=e.nextSub)!==void 0)}function c(e,t){let n=t.depsTail;for(;n!==void 0;){if(n===e)return!0;n=n.prevDep}return!1}}function TC(e,t,n){let r=typeof e==`object`,i=r?e:void 0;return{next:(r?e.next:e)?.bind(i),error:(r?e.error:t)?.bind(i),complete:(r?e.complete:n)?.bind(i)}}var EC=[],DC=0,{link:OC,unlink:kC,propagate:AC,checkDirty:jC,shallowPropagate:MC}=wC({update(e){return e._update()},notify(e){EC[PC++]=e,e.flags&=-3},unwatched(e){e.depsTail!==void 0&&(e.depsTail=void 0,e.flags=17,RC(e))}}),NC=0,PC=0,FC,IC=0;function LC(e){try{++IC,e()}finally{--IC||zC()}}function RC(e){let t=e.depsTail,n=t===void 0?e.deps:t.nextDep;for(;n!==void 0;)n=kC(n,e)}function zC(){if(!(IC>0)){for(;NC<PC;){let e=EC[NC];EC[NC++]=void 0,e.notify()}NC=0,PC=0}}function BC(e,t){let n=typeof e==`function`,r=e,i={_snapshot:n?void 0:e,subs:void 0,subsTail:void 0,deps:void 0,depsTail:void 0,flags:+!n,get(){return FC!==void 0&&OC(i,FC,DC),i._snapshot},subscribe(e){let t=TC(e),n={current:!1},r=VC(()=>{i.get(),n.current?(FC=void 0,t.next?.(i._snapshot)):n.current=!0});return{unsubscribe:()=>{r.stop()}}},_update(e){let a=FC,o=t?.compare??Object.is;if(n)FC=i,++DC,i.depsTail=void 0;else if(e===void 0)return!1;n&&(i.flags=5);try{let t=i._snapshot,a=typeof e==`function`?e(t):e===void 0&&n?r(t):e;return t===void 0||!o(t,a)?(i._snapshot=a,!0):!1}finally{FC=a,n&&(i.flags&=-5),RC(i)}}};return n?(i.flags=17,i.get=function(){let e=i.flags;if(e&16||e&32&&jC(i.deps,i)){if(i._update()){let e=i.subs;e!==void 0&&MC(e)}}else e&32&&(i.flags=e&-33);return FC!==void 0&&OC(i,FC,DC),i._snapshot}):i.set=function(e){if(i._update(e)){let e=i.subs;e!==void 0&&(AC(e),MC(e),zC())}},i}function VC(e){let t=()=>{let t=FC;FC=n,++DC,n.depsTail=void 0,n.flags=6;try{return e()}finally{FC=t,n.flags&=-5,RC(n)}},n={deps:void 0,depsTail:void 0,subs:void 0,subsTail:void 0,flags:6,notify(){let e=this.flags;e&16||e&32&&jC(this.deps,this)?t():this.flags=2},stop(){this.flags=0,this.depsTail=void 0,RC(this)}};return t(),n}function HC(e,t){if(Object.is(e,t))return!0;if(typeof e!=`object`||!e||typeof t!=`object`||!t)return!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(let[n,r]of e)if(!t.has(n)||!Object.is(r,t.get(n)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}if(e instanceof Date&&t instanceof Date)return e.getTime()===t.getTime();let n=UC(e);if(n.length!==UC(t).length)return!1;for(let r=0;r<n.length;r++)if(!Object.prototype.hasOwnProperty.call(t,n[r])||!Object.is(e[n[r]],t[n[r]]))return!1;return!0}function UC(e){return Object.keys(e).concat(Object.getOwnPropertySymbols(e))}var WC=n((e=>{var t=r();function n(e,t){return e===t&&(e!==0||1/e==1/t)||e!==e&&t!==t}var i=typeof Object.is==`function`?Object.is:n,a=t.useState,o=t.useEffect,s=t.useLayoutEffect,c=t.useDebugValue;function l(e,t){var n=t(),r=a({inst:{value:n,getSnapshot:t}}),i=r[0].inst,l=r[1];return s(function(){i.value=n,i.getSnapshot=t,u(i)&&l({inst:i})},[e,n,t]),o(function(){return u(i)&&l({inst:i}),e(function(){u(i)&&l({inst:i})})},[e]),c(n),n}function u(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!i(e,n)}catch{return!0}}function d(e,t){return t()}var f=typeof window>`u`||window.document===void 0||window.document.createElement===void 0?d:l;e.useSyncExternalStore=t.useSyncExternalStore===void 0?f:t.useSyncExternalStore})),GC=n(((e,t)=>{t.exports=WC()})),KC=n((e=>{var t=r(),n=GC();function i(e,t){return e===t&&(e!==0||1/e==1/t)||e!==e&&t!==t}var a=typeof Object.is==`function`?Object.is:i,o=n.useSyncExternalStore,s=t.useRef,c=t.useEffect,l=t.useMemo,u=t.useDebugValue;e.useSyncExternalStoreWithSelector=function(e,t,n,r,i){var d=s(null);if(d.current===null){var f={hasValue:!1,value:null};d.current=f}else f=d.current;d=l(function(){function e(e){if(!o){if(o=!0,s=e,e=r(e),i!==void 0&&f.hasValue){var t=f.value;if(i(t,e))return c=t}return c=e}if(t=c,a(s,e))return t;var n=r(e);return i!==void 0&&i(t,n)?(s=e,t):(s=e,c=n)}var o=!1,s,c,l=n===void 0?null:n;return[function(){return e(t())},l===null?void 0:function(){return e(l())}]},[t,n,r,i]);var p=o(e,d[0],d[1]);return c(function(){f.hasValue=!0,f.value=p},[p]),u(p),p}})),qC=n(((e,t)=>{t.exports=KC()}))();function JC(e,t){return e===t}function YC(e,t=e=>e,n){let r=n?.compare??JC,i=(0,o.useCallback)(t=>{let{unsubscribe:n}=e.subscribe(t);return n},[e]),a=(0,o.useCallback)(()=>e.get(),[e]);return(0,qC.useSyncExternalStoreWithSelector)(i,a,a,t,r)}function XC(e){let t=YC(e.source,e.selector,{compare:HC});return typeof e.children==`function`?e.children(t):e.children}function ZC(e){let t=e;return Object.defineProperty(e,"state",{get(){return e.get()}}),`set`in e&&(t.setState=e.set.bind(e)),t}function QC(e){let{createAtom:t,batch:n}=e,r=t(0);return{createOptionsStore:!1,wrapExternalAtoms:!1,addSubscription:()=>{throw Error(`Feature not supported in current reactivity implementation`)},unmount:()=>{throw Error(`Feature not supported in current reactivity implementation`)},schedule:e.schedule??(e=>queueMicrotask(e)),batch:n,untrack:e=>e(),createReadonlyAtom:(e,n)=>{let i=n?.compare??Object.is,a=!1,o,s=()=>{let t=e();return(!a||!i(o,t))&&(o=t,a=!0),o},c=t(()=>(r.get(),s()),{compare:i});return{get:s,subscribe:c.subscribe.bind(c)}},createWritableAtom:(e,n)=>t(e,{compare:n?.compare}),commit:()=>{r.set(e=>e+1)}}}function $C(e,t=Object.is){let n=!1,r;return{get:e.get,markCommitted:e=>{r=e,n=!0},subscribe:i=>e.subscribe(e=>{(!n||!t(r,e))&&i(e)})}}function ew(){return QC({createAtom:BC,batch:LC})}function tw(e,t){return typeof e==`function`?e(t):e}function nw(e){if(Array.isArray(e))return e.map(nw);if(e&&typeof e==`object`){let t=Object.getPrototypeOf(e);if(t!==Object.prototype&&t!==null)return e;let n=t===null?iw():{},r=Object.keys(e);for(let t=0;t<r.length;t++){let i=r[t];Object.defineProperty(n,i,{configurable:!0,enumerable:!0,value:nw(e[i]),writable:!0})}return n}return e}function rw(e,t){let n=Object.keys(t),r=e;for(let e=0;e<n.length;e++){let i=n[e];!i.startsWith(`_memo_`)&&i!==`_cellsCache`&&(r[i]=t[i])}return e}function iw(){return Object.create(null)}function aw(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function ow(e,t){return n=>{(t.options.atoms?.[e]??t.baseAtoms[e]).set(e=>tw(n,e))}}function sw(e){if(typeof e!=`object`||!e)return!1;if(Array.isArray(e))return!0;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function cw(e){return Reflect.ownKeys(e).filter(t=>Object.prototype.propertyIsEnumerable.call(e,t))}var lw=3;function uw(e,t){return dw(e,t,lw)}function dw(e,t,n){if(Object.is(e,t))return!0;if(n<=0||!sw(e)||!sw(t)||(Array.isArray(e)||Array.isArray(t))&&(!Array.isArray(e)||!Array.isArray(t)||e.length!==t.length))return!1;let r=cw(e),i=cw(t);if(r.length!==i.length)return!1;let a=e,o=t;for(let e=0;e<r.length;e++){let i=r[e];if(!Object.prototype.propertyIsEnumerable.call(t,i)||!dw(a[i],o[i],n-1))return!1}return!0}function fw(e,t,n,r=uw){let i=`on${t.charAt(0).toUpperCase()}${t.slice(1)}Change`,a=e.options[i];a&&a(e=>{let t=tw(n,e);return r(e,t)?e:t})}function pw(e){return e instanceof Function}function mw(e,t){let n=[],r=e=>{e.forEach(e=>{n.push(e);let i=t(e);i.length&&r(i)})};return r(e),n}var hw=({fn:e,memoDeps:t,onAfterCompare:n,onAfterUpdate:r,onBeforeCompare:i,onBeforeUpdate:a})=>{let o=[],s;return c=>{i?.();let l=t?.(c),u=!l||l.length!==o?.length;if(!u&&l){for(let e=0;e<l.length;e++)if(l[e]!==o[e]){u=!0;break}}return n?.(u),u?(o=l,a?.(),s=e(...l??[]),r?.(s),s):s}};function gw(e){let t=!1;return()=>{if(!t){t=!0;return}e()}}function _w({feature:e,fnName:t,objectId:n,onAfterUpdate:r,table:i,...a}){let o=()=>{if(!r)return;let{schedule:e,untrack:t}=i._reactivity;e(()=>t(()=>r()))},s={onAfterUpdate:()=>{o()}};return hw({...a,...s})}function vw(e,t=`_`){let[n,r]=e.split(t);return{fnKey:r,fnName:`${n}.${r}`,parentName:n}}function yw(e,t,n){for(let[r,{fn:i,memoDeps:a}]of Object.entries(n)){let{fnKey:n,fnName:o}=vw(r);t[n]=a?_w({memoDeps:a,fn:i,fnName:o,table:t,feature:e}):i}}function bw(e,t,n,r){for(let[i,{fn:a,memoDeps:o}]of Object.entries(r)){let{fnKey:r,fnName:s}=vw(i);if(o){let i=`_memo_${r}`;t[r]=function(...t){if(!this[i]){let t=this;this[i]=_w({memoDeps:e=>o(t,e),fn:(...e)=>a(t,...e),fnName:s,objectId:t.id,table:n,feature:e})}return this[i](...t)}}else t[r]=function(...e){return a(this,...e)}}}function xw(e,t,n,...r){return e[t]?.(...r)??n(e,...r)}function Sw(e){return e.row.getValue(e.column.id)}function Cw(e){return e.getValue()??e.table.options.renderFallbackValue}function ww(e){return{table:e.table,column:e.column,row:e.row,cell:e,getValue:()=>e.getValue(),renderValue:()=>e.renderValue()}}var Tw={assignCellPrototype:(e,t)=>{bw(`coreCellsFeature`,e,t,{cell_getValue:{fn:e=>Sw(e)},cell_renderValue:{fn:e=>Cw(e)},cell_getContext:{fn:e=>ww(e),memoDeps:e=>[e]}})}};function Ew(e){if(!e._headerPrototype){e._headerPrototype={table:e};let t=Object.values(e._features);for(let n=0;n<t.length;n++)t[n].assignHeaderPrototype?.(e._headerPrototype,e)}return e._headerPrototype}function Dw(e,t,n){let r=Ew(e),i=Object.create(r);i.colSpan=0,i.column=t,i.depth=n.depth,i.headerGroup=null,i.id=n.id??t.id,i.index=n.index,i.isPlaceholder=!!n.isPlaceholder,i.placeholderId=n.placeholderId,i.rowSpan=0,i.subHeaders=[];let a=e._headerInstanceInitFns;for(let e=0;e<a.length;e++)a[e](i);return i}function Ow(){return{start:[],end:[]}}function kw(e){let t=e.table.atoms.columnVisibility?.get();if(!t)return!0;let n=e.columns;return n.length?n.some(e=>xw(e,`getIsVisible`,kw)):(aw(t,e.id)?t[e.id]:void 0)??!0}function Aw(e){return e.getAllLeafColumns().filter(e=>xw(e,`getIsVisible`,kw))}function jw(e,t=1){let n=t;for(let r=0;r<e.length;r++){let i=e[r];xw(i,`getIsVisible`,kw)&&i.columns.length&&(n=Math.max(n,jw(i.columns,t+1)))}return n}function Mw(e,t){return e?`${e}_${t}`:String(t)}function Nw(e,t,n,r){let i=e??``;return t&&(i=i?`${i}_${t}`:String(t)),n&&(i=i?`${i}_${n}`:n),r&&(i=i?`${i}_${r}`:r),i}function Pw(e,t){let n=0;for(let r=0;r<e.length;r++)e[r].column===t&&n++;return n}function Fw(e,t,n,r,i,a){let o={depth:t,id:Mw(r,t),headers:[]},s=[];for(let i=0;i<e.length;i++){if(!(i in e))continue;let a=e[i],c=s[s.length-1],l=a.column.depth===o.depth,u,d=!1;if(l&&a.column.parent?u=a.column.parent:(u=a.column,d=!0),c&&c.column===u)c.subHeaders.push(a);else{let e=Dw(n,u,{id:Nw(r,t,u.id,a.id),isPlaceholder:d,placeholderId:d?String(Pw(s,u)):void 0,depth:t,index:s.length});e.subHeaders.push(a),s.push(e)}o.headers.push(a),a.headerGroup=o}for(let e=0;e<a.length;e++)a[e](o);i.push(o),t>0&&Fw(s,t-1,n,r,i,a)}function Iw(e){for(let t=0;t<e.length;t++){let n=e[t];if(!xw(n.column,`getIsVisible`,kw))continue;let r=0;if(n.subHeaders.length){Iw(n.subHeaders);for(let e=0;e<n.subHeaders.length;e++){let t=n.subHeaders[e];xw(t.column,`getIsVisible`,kw)&&(r+=t.colSpan)}}else r=1;if(n.colSpan=r,n.isPlaceholder&&n.subHeaders.length===1&&n.subHeaders[0].column===n.column){let e=1,t=n.subHeaders[0];for(;t;)t.rowSpan=0,e++,t=t.subHeaders.length===1&&t.subHeaders[0].column===n.column?t.subHeaders[0]:void 0;n.rowSpan=e}else n.rowSpan=1}}function Lw(e,t,n,r){let i=jw(e),a=[],o=n._headerGroupInstanceInitFns,s=Array(t.length);for(let e=0;e<t.length;e++)e in t&&(s[e]=Dw(n,t[e],{depth:i,index:e}));return Fw(s,i-1,n,r,a,o),a.reverse(),Iw(a[0]?.headers??[]),a}function Rw(e){if(!e._columnPrototype){e._columnPrototype={table:e};let t=Object.values(e._features);for(let n=0;n<t.length;n++)t[n].assignColumnPrototype?.(e._columnPrototype,e)}return e._columnPrototype}function zw(e,t,n,r){let i={...e.getDefaultColumnDef(),...t},a=i.accessorKey,o=a===void 0?void 0:String(a),s=i.id??o?.replaceAll(`.`,`_`)??(typeof i.header==`string`?i.header:void 0),c;if(i.accessorFn)c=i.accessorFn;else if(a!==void 0){if(typeof a==`string`&&a.includes(`.`)){let e=a.split(`.`);c=t=>{let n=t;for(let t=0;t<e.length;t++){let r=e[t];n=n?.[r]}return n}}else c=e=>e[i.accessorKey]}if(!s)throw Error();let l=Rw(e),u=Object.create(l);u.accessorFn=c,u.columnDef=i,u.columns=[],u.depth=n,u.id=`${String(s)}`,u.parent=r;let d=e._columnInstanceInitFns;for(let e=0;e<d.length;e++)d[e](u);return u}function Bw(e){let t=e.atoms.columnOrder?.get();return n=>{let r=[];if(!t?.length)r=n;else{let e=new Map;for(let t=0;t<n.length;t++){let r=n[t];e.set(r.id,r)}for(let n=0;n<t.length;n++){let i=t[n],a=e.get(i);a&&(r.push(a),e.delete(i))}for(let t=0;t<n.length;t++){let i=n[t];e.has(i.id)&&r.push(i)}}return Vw(e,r)}}function Vw(e,t){let n=e.atoms.grouping?.get()??[],{groupedColumnMode:r}=e.options;if(!n.length||!r)return t;let i=t.filter(e=>!n.includes(e.id));if(r===`remove`)return i;let a=new Map;for(let e=0;e<t.length;e++){let n=t[e];a.set(n.id,n)}let o=[];for(let e=0;e<n.length;e++){let t=a.get(n[e]);t&&o.push(t)}return[...o,...i]}function Hw(e){return[e,...e.columns.flatMap(e=>e.getFlatColumns())]}function Uw(e){if(e.columns.length){let t=e.columns.flatMap(e=>e.getLeafColumns());return xw(e.table,`getOrderColumns`,Bw)(t)}return[e]}function Ww(e){return{header:e=>{let t=e.header.column.columnDef;return t.accessorKey?t.accessorKey:t.accessorFn?t.id:null},cell:e=>e.renderValue()?.toString?.()??null,...Object.values(e._features).reduce((e,t)=>Object.assign(e,t.getDefaultColumnDef?.()),{}),...e.options.defaultColumn}}function Gw(e,t,n,r=0){let i=Array(t.length);for(let a=0;a<t.length;a++){if(!(a in t))continue;let o=t[a],s=zw(e,o,r,n),c=o;s.columns=c.columns?Gw(e,c.columns,s,r+1):[],i[a]=s}return i}function Kw(e){return Gw(e,e.options.columns)}function qw(e){return e.getAllColumns().flatMap(e=>e.getFlatColumns())}function Jw(e){let t=iw(),n=e.getAllFlatColumns();for(let e=0;e<n.length;e++){let r=n[e];t[r.id]=r}return t}function Yw(e){let t=e.getAllColumns().flatMap(e=>e.getLeafColumns());return xw(e,`getOrderColumns`,Bw)(t)}function Xw(e){let t=iw(),n=e.getAllLeafColumns();for(let e=0;e<n.length;e++){let r=n[e];t[r.id]=r}return t}function Zw(e,t){return e.getAllFlatColumnsById()[t]}var Qw={assignColumnPrototype:(e,t)=>{bw(`coreColumnsFeature`,e,t,{column_getFlatColumns:{fn:e=>Hw(e),memoDeps:e=>[e.table.options.columns]},column_getLeafColumns:{fn:e=>Uw(e),memoDeps:e=>[e.table.atoms.columnOrder?.get(),e.table.atoms.grouping?.get(),e.table.options.columns,e.table.options.groupedColumnMode]}})},constructTableAPIs:e=>{yw(`coreColumnsFeature`,e,{table_getDefaultColumnDef:{fn:()=>Ww(e),memoDeps:()=>[e.options.defaultColumn]},table_getAllColumns:{fn:()=>Kw(e),memoDeps:()=>[e.options.columns]},table_getAllFlatColumns:{fn:()=>qw(e),memoDeps:()=>[e.options.columns]},table_getAllFlatColumnsById:{fn:()=>Jw(e),memoDeps:()=>[e.options.columns]},table_getAllLeafColumns:{fn:()=>Yw(e),memoDeps:()=>[e.atoms.columnOrder?.get(),e.atoms.grouping?.get(),e.options.columns,e.options.groupedColumnMode]},table_getAllLeafColumnsById:{fn:()=>Xw(e),memoDeps:()=>[e.getAllLeafColumns()]},table_getColumn:{fn:t=>Zw(e,t)}})}};function $w(e,t){for(let n=0;n<e.subHeaders.length;n++)$w(e.subHeaders[n],t);t.push(e)}function eT(e){let t=[];return $w(e,t),t}function tT(e){return{column:e.column,header:e,table:e.column.table}}function nT(e){let{start:t,end:n}=e.atoms.columnPinning?.get()??Ow(),r=e.getAllColumns(),i=xw(e,`getVisibleLeafColumns`,Aw);if(!t.length&&!n.length)return Lw(r,i,e);let a=e.getAllLeafColumnsById(),o=[];for(let e=0;e<t.length;e++){let n=a[t[e]];n&&xw(n,`getIsVisible`,kw)&&o.push(n)}let s=[];for(let e=0;e<n.length;e++){let t=a[n[e]];t&&xw(t,`getIsVisible`,kw)&&s.push(t)}let c=i.filter(e=>!t.includes(e.id)&&!n.includes(e.id));return Lw(r,[...o,...c,...s],e)}function rT(e){return[...e.getHeaderGroups()].reverse()}function iT(e){let t=e.getHeaderGroups(),n=[];for(let e=0;e<t.length;e++){let r=t[e].headers;for(let e=0;e<r.length;e++)n.push(r[e])}return n}function aT(e){let t=e.getHeaderGroups()[0]?.headers??[],n=[];for(let e=0;e<t.length;e++){let r=t[e].getLeafHeaders();for(let e=0;e<r.length;e++)n.push(r[e])}return n}var oT={assignHeaderPrototype:(e,t)=>{bw(`coreHeadersFeature`,e,t,{header_getLeafHeaders:{fn:e=>eT(e),memoDeps:e=>[e.column.table.options.columns]},header_getContext:{fn:e=>tT(e),memoDeps:e=>[e.column.table.options.columns]}})},constructTableAPIs:e=>{yw(`coreHeadersFeature`,e,{table_getHeaderGroups:{fn:()=>nT(e),memoDeps:()=>[e.options.columns,e.atoms.columnOrder?.get(),e.atoms.grouping?.get(),e.atoms.columnPinning?.get(),e.atoms.columnVisibility?.get(),e.options.groupedColumnMode]},table_getFooterGroups:{fn:()=>rT(e),memoDeps:()=>[e.getHeaderGroups()]},table_getFlatHeaders:{fn:()=>iT(e),memoDeps:()=>[e.getHeaderGroups()]},table_getLeafHeaders:{fn:()=>aT(e),memoDeps:()=>[e.getHeaderGroups()]}})}};function sT(e){if(!e._rowPrototype){e._rowPrototype={table:e};let t=Object.values(e._features);for(let n=0;n<t.length;n++)t[n].assignRowPrototype?.(e._rowPrototype,e)}return e._rowPrototype}var cT=(e,t,n,r,i,a,o)=>{let s=sT(e),c=Object.create(s);c._displayIndexCache=-1,c._uniqueValuesCache=iw(),c._valuesCache=iw(),c.depth=i,c.id=t,c.index=r,c.original=n,c.parentId=o,c.subRows=a??[];let l=e._rowInstanceInitFns;for(let e=0;e<l.length;e++)l[e](c);return c},lT=/([0-9]+)/gm;function uT(e){let t=Object.assign((e,n,r)=>{let i=e.getValue(r),a=n.getValue(r),o=t.resolveDataValue;return o&&(i=o(i),a=o(a)),t.sort(i,a,e,n,r)},e);return t}uT({resolveDataValue:e=>mT(e).toLowerCase(),sort:(e,t)=>hT(e,t)}),uT({resolveDataValue:e=>mT(e),sort:(e,t)=>hT(e,t)}),uT({resolveDataValue:e=>mT(e).toLowerCase(),sort:(e,t)=>fT(e,t)}),uT({resolveDataValue:e=>mT(e),sort:(e,t)=>fT(e,t)}),uT({resolveDataValue:e=>pT(e),sort:(e,t)=>e>t?1:e<t?-1:0});var dT=uT({sort:(e,t)=>fT(e,t)});function fT(e,t){return e===t?0:e>t?1:-1}function pT(e){return e instanceof Date?e.getTime():e}function mT(e){return typeof e==`number`?isNaN(e)||e===1/0||e===-1/0?``:String(e):typeof e==`string`?e:``}function hT(e,t){let n=0,r=0,i=e.length,a=t.length;for(;n<i&&r<a;){let i=gT(e.charCodeAt(n)),a=gT(t.charCodeAt(r)),o=_T(e,n,i),s=_T(t,r,a);if(!i&&!a){let i=vT(e,n,o,t,r,s);if(i)return i;n=o,r=s;continue}if(i!==a)return i?1:-1;let c=yT(e,n,o,t,r,s);if(c)return c;n=o,r=s}return xT(e,n)-xT(t,r)}function gT(e){return e>=48&&e<=57}function _T(e,t,n){let r=t+1;for(;r<e.length&&gT(e.charCodeAt(r))===n;)r++;return r}function vT(e,t,n,r,i,a){let o=n-t,s=a-i,c=o<s?o:s;for(let n=0;n<c;n++){let a=e.charCodeAt(t+n),o=r.charCodeAt(i+n);if(a>o)return 1;if(o>a)return-1}return o>s?1:s>o?-1:0}function yT(e,t,n,r,i,a){let o=t;for(;o<n&&e.charCodeAt(o)===48;)o++;let s=i;for(;s<a&&r.charCodeAt(s)===48;)s++;let c=n-o,l=a-s;if(c===0&&l===0)return 0;if(c<=15&&l<=15){let t=bT(e,o,n),i=bT(r,s,a);return t>i?1:i>t?-1:0}let u=parseInt(e.slice(t,n),10),d=parseInt(r.slice(i,a),10);return u>d?1:d>u?-1:0}function bT(e,t,n){let r=0;for(let i=t;i<n;i++)r=r*10+e.charCodeAt(i)-48;return r}function xT(e,t){let n=0,r=t;for(;r<e.length;)n++,r=_T(e,r,gT(e.charCodeAt(r)));return n}function ST(){return[]}function CT(e,t){fw(e,`cellSelection`,t?ST():nw(e.initialState.cellSelection)??ST())}function wT(e){e.atoms.cellSelection&&(e.options.autoResetAll??e.options.autoResetCellSelection??!0)&&e._reactivity.schedule(()=>CT(e))}function TT(e){e.atoms.expanded&&(e.options.autoResetAll??e.options.autoResetExpanded??!e.options.manualExpanding)&&e._reactivity.schedule(()=>ET(e))}function ET(e,t){let n=e.initialState.expanded;fw(e,`expanded`,t?iw():n===!0||Object.assign(iw(),nw(n??{})))}var DT=0;function OT(e){if(e.options.autoResetAll??e.options.autoResetPageIndex??!e.options.manualPagination){if((e.atoms.pagination?.get()?.pageIndex??DT)===DT)return;jT(e,!0)}}function kT(e,t){fw(e,`pagination`,t)}function AT(e,t){kT(e,n=>{let r=tw(t,n.pageIndex),i=e.options.pageCount===void 0||e.options.pageCount===-1?2**53-1:e.options.pageCount-1;return r=Math.max(0,Math.min(r,i)),{...n,pageIndex:r}})}function jT(e,t){AT(e,t?DT:e.initialState.pagination?.pageIndex??DT)}function MT(){return[]}function NT(e,t){fw(e,`sorting`,t)}function PT(e,t){NT(e,t?[]:nw(e.initialState.sorting??[]))}function FT(e){e.atoms.sorting&&(e.options.autoResetAll??e.options.autoResetSorting??!1)&&PT(e)}function IT(e){let t=e.table._rowModelFns.sortFns,n=e.table.getFilteredRowModel().flatRows.slice(0,10),r,i=!1;for(let t=0;t<n.length;t++){let a=n[t].getValue(e.id);if(Object.prototype.toString.call(a)===`[object Date]`){r=`datetime`;break}if(typeof a==`string`&&(i=!0,a.split(lT).length>1)){r=`alphanumeric`;break}}if(!r&&i&&(r=`text`),r){let e=t?.[r];if(e||r===`alphanumeric`&&(e=t?.text),e)return e}return dT}function LT(e){let t=e.table.getFilteredRowModel().flatRows.slice(0,10);for(let n=0;n<t.length;n++){let r=t[n].getValue(e.id);if(r!=null)return typeof r==`string`?`asc`:`desc`}return`desc`}function RT(e){let t=e.table._rowModelFns.sortFns;return pw(e.columnDef.sortFn)?e.columnDef.sortFn:e.columnDef.sortFn===`auto`?IT(e):t?.[e.columnDef.sortFn]??dT}function zT(e,t,n){let r=VT(e,n&&UT(e)),i=t!==void 0;NT(e.table,a=>{let o=a.findIndex(t=>t.id===e.id),s=o===-1?void 0:a[o],c=[],l,u=i?t:r===`desc`,d=!!(a.length&&UT(e)&&n);return l=d?s?`toggle`:`add`:s?`toggle`:`replace`,l===`toggle`&&(i||r||(l=`remove`)),l===`add`?(c=[...a,{id:e.id,desc:u}],c.splice(0,c.length-(e.table.options.maxMultiSortColCount??2**53-1))):c=l===`toggle`?d?a.map(t=>t.id===e.id?{...t,desc:u}:t):[{id:e.id,desc:u}]:l===`remove`?d?a.filter(t=>t.id!==e.id):[]:[{id:e.id,desc:u}],c})}function BT(e){return e.columnDef.sortDescFirst??e.table.options.sortDescFirst??LT(e)===`desc`?`desc`:`asc`}function VT(e,t){let n=BT(e),r=WT(e);return r?r!==n&&(e.table.options.enableSortingRemoval??!0)&&(!t||(e.table.options.enableMultiRemove??!0))?!1:r===`desc`?`asc`:`desc`:n}function HT(e){return(e.columnDef.enableSorting??!0)&&(e.table.options.enableSorting??!0)&&!!e.accessorFn}function UT(e){return e.columnDef.enableMultiSort??e.table.options.enableMultiSort??!!e.accessorFn}function WT(e){let t=e.table.atoms.sorting?.get()?.find(t=>t.id===e.id);return t?t.desc?`desc`:`asc`:!1}function GT(e){return e.table.atoms.sorting?.get()?.findIndex(t=>t.id===e.id)??-1}function KT(e){NT(e.table,t=>t.length?t.filter(t=>t.id!==e.id):[])}function qT(e){let t=HT(e);return n=>{t&&zT(e,void 0,UT(e)?e.table.options.isMultiSortEvent?.(n):!1)}}function JT(){return e=>_w({feature:`coreRowModelsFeature`,table:e,fnName:`table.getCoreRowModel`,memoDeps:()=>[e.options.data],fn:()=>XT(e,e.options.data),onAfterUpdate:gw(()=>{TT(e),OT(e),FT(e),wT(e)})})}function YT(e,t,n,r=0,i){let a=[];for(let o=0;o<n.length;o++){let s=n[o],c=cT(e,e.getRowId(s,o,i),s,o,r,void 0,i?.id);t.flatRows.push(c),t.rowsById[c.id]=c,a.push(c),e.options.getSubRows&&(c.originalSubRows=e.options.getSubRows(s,o),c.originalSubRows?.length&&(c.subRows=YT(e,t,c.originalSubRows,r+1,c)))}return a}function XT(e,t){let n={rows:[],flatRows:[],rowsById:iw()};return n.rows=YT(e,n,t),n}function ZT(e){return e._rowModels.coreRowModel||(e._rowModels.coreRowModel=e.options.features.coreRowModel?.(e)??JT()(e)),e._rowModels.coreRowModel()}function QT(e){return e.getCoreRowModel()}function $T(e){return e._rowModels.filteredRowModel||(e._rowModels.filteredRowModel=e.options.features.filteredRowModel?.(e)),e.options.manualFiltering||!e._rowModels.filteredRowModel?e.getPreFilteredRowModel():e._rowModels.filteredRowModel()}function eE(e){return e.getFilteredRowModel()}function tE(e){return e._rowModels.groupedRowModel||(e._rowModels.groupedRowModel=e.options.features.groupedRowModel?.(e)),e.options.manualGrouping||!e._rowModels.groupedRowModel?e.getPreGroupedRowModel():e._rowModels.groupedRowModel()}function nE(e){return e.getGroupedRowModel()}function rE(e){return e._rowModels.sortedRowModel||(e._rowModels.sortedRowModel=e.options.features.sortedRowModel?.(e)),e.options.manualSorting||!e._rowModels.sortedRowModel?e.getPreSortedRowModel():e._rowModels.sortedRowModel()}function iE(e){return e.getSortedRowModel()}function aE(e){return e._rowModels.expandedRowModel||(e._rowModels.expandedRowModel=e.options.features.expandedRowModel?.(e)),e.options.manualExpanding||!e._rowModels.expandedRowModel?e.getPreExpandedRowModel():e._rowModels.expandedRowModel()}function oE(e){return e.getExpandedRowModel()}function sE(e){return e._rowModels.paginatedRowModel||(e._rowModels.paginatedRowModel=e.options.features.paginatedRowModel?.(e)),e.options.manualPagination||!e._rowModels.paginatedRowModel?e.getPrePaginatedRowModel():e._rowModels.paginatedRowModel()}function cE(e){return e.getPaginatedRowModel()}var lE={constructTableAPIs:e=>{yw(`coreRowModelsFeature`,e,{table_getCoreRowModel:{fn:()=>ZT(e)},table_getPreFilteredRowModel:{fn:()=>QT(e)},table_getFilteredRowModel:{fn:()=>$T(e)},table_getPreGroupedRowModel:{fn:()=>eE(e)},table_getGroupedRowModel:{fn:()=>tE(e)},table_getPreSortedRowModel:{fn:()=>nE(e)},table_getSortedRowModel:{fn:()=>rE(e)},table_getPreExpandedRowModel:{fn:()=>iE(e)},table_getExpandedRowModel:{fn:()=>aE(e)},table_getPrePaginatedRowModel:{fn:()=>oE(e)},table_getPaginatedRowModel:{fn:()=>sE(e)},table_getRowModel:{fn:()=>cE(e)}})}};function uE(e){if(!e._cellPrototype){e._cellPrototype={table:e};let t=Object.values(e._features);for(let n=0;n<t.length;n++)t[n].assignCellPrototype?.(e._cellPrototype,e)}return e._cellPrototype}function dE(e,t,n){let r=uE(n),i=Object.create(r);i.column=e,i.id=`${t.id}_${e.id}`,i.row=t;let a=n._cellInstanceInitFns;for(let e=0;e<a.length;e++)a[e](i);return i}function fE(e){let t=e.table.getRowsInDisplayOrder(),n=e._displayIndexCache;return t[n]===e?n:-1}function pE(e){let t=e.getPrePaginatedRowModel().rows;if(e.options.paginateExpandedRows===!1){let e=[],n=t=>{t._displayIndexCache=e.length,e.push(t),t.subRows.length&&t.getIsExpanded?.()&&t.subRows.forEach(n)};return t.forEach(n),e}for(let e=0;e<t.length;e++)t[e]._displayIndexCache=e;return t}function mE(e,t){if(aw(e._valuesCache,t))return e._valuesCache[t];let n=e.table.getColumn(t);if(n?.accessorFn)return e._valuesCache[t]=n.accessorFn(e.original,e.index),e._valuesCache[t]}function hE(e,t){if(aw(e._uniqueValuesCache,t))return e._uniqueValuesCache[t];let n=e.table.getColumn(t);if(n?.accessorFn)return n.columnDef.getUniqueValues?(e._uniqueValuesCache[t]=n.columnDef.getUniqueValues(e.original,e.index),e._uniqueValuesCache[t]):(e._uniqueValuesCache[t]=[e.getValue(t)],e._uniqueValuesCache[t])}function gE(e,t){return e.getValue(t)??e.table.options.renderFallbackValue}function _E(e){return mw(e.subRows,e=>e.subRows)}function vE(e){let t=e.getCoreRowModel().flatRows,n=0;for(let e=0;e<t.length;e++)n=Math.max(n,t[e].depth);return n}function yE(e){if(e.parentId)return e.table.getCoreRowModel().rowsById[e.parentId]??e.table.getRow(e.parentId,!0)}function bE(e){let t=[],n=e;for(;;){let e=n.getParentRow();if(!e)break;t.push(e),n=e}return t.reverse()}function xE(e){let t=e.table.getAllLeafColumns(),n=e._cellsCache;n||=e._cellsCache=new WeakMap;let r=Array(t.length);for(let i=0;i<t.length;i++){let a=t[i],o=n.get(a);o||(o=dE(a,e,e.table),n.set(a,o)),r[i]=o}return r}function SE(e){let t=iw(),n=e.getAllCells();for(let e=0;e<n.length;e++){let r=n[e];t[r.column.id]=r}return t}function CE(e,t,n,r){return t.options.getRowId?.(e,n,r)??(r?`${r.id}.${n}`:String(n))}function wE(e,t,n){let r=(n?e.getPrePaginatedRowModel():e.getRowModel()).rowsById[t];if(!r&&(r=e.getCoreRowModel().rowsById[t],!r))throw Error();return r}var TE={assignRowPrototype:(e,t)=>{bw(`coreRowsFeature`,e,t,{row_getDisplayIndex:{fn:e=>fE(e)},row_getAllCellsByColumnId:{fn:e=>SE(e),memoDeps:e=>[e.getAllCells()]},row_getAllCells:{fn:e=>xE(e),memoDeps:e=>[e.table.getAllLeafColumns()]},row_getLeafRows:{fn:e=>_E(e),memoDeps:e=>[e.subRows]},row_getParentRow:{fn:e=>yE(e)},row_getParentRows:{fn:e=>bE(e)},row_getUniqueValues:{fn:(e,t)=>hE(e,t)},row_getValue:{fn:(e,t)=>mE(e,t)},row_renderValue:{fn:(e,t)=>gE(e,t)}})},constructTableAPIs:e=>{yw(`coreRowsFeature`,e,{table_getRowsInDisplayOrder:{fn:()=>pE(e),memoDeps:()=>[e.getPrePaginatedRowModel().rows,e.options.paginateExpandedRows,e.options.paginateExpandedRows===!1?e.atoms.expanded?.get():void 0]},table_getRowId:{fn:(t,n,r)=>CE(t,e,n,r)},table_getRow:{fn:(t,n)=>wE(e,t,n)},table_getMaxSubRowDepth:{fn:()=>vE(e),memoDeps:()=>[e.getCoreRowModel()]}})}};function EE(e,t,n=(e,t)=>e===t){let r=t===void 0?e.options.state:t;e._reactivity.batch(()=>{if(r)for(let t in r){let i=e.baseAtoms[t];if(!i)continue;let a=r[t],o=a===void 0?e.initialState[t]:a;n(e._reactivity.untrack(()=>i.get()),o)||i.set(()=>o)}})}function DE(e,t,n=(e,t)=>e===t){e._reactivity.batch(()=>{EE(e,t,n),e._reactivity.commit?.()})}function OE(e){let t=nw(e.initialState);e._reactivity.batch(()=>{let n=Object.keys(t);for(let r=0;r<n.length;r++){let i=n[r];e.baseAtoms[i].set(t[i])}});let n=Object.values(e._features);for(let t=0;t<n.length;t++)n[t].resetTableInstanceData?.(e)}function kE(e,t){let{features:n,atoms:r,initialState:i}=e.options;if(!e.options.mergeOptions)return{...e.options,...t,features:n,atoms:r,initialState:i};let a=e.options.mergeOptions(e.options,t),o={...Object.getOwnPropertyDescriptors(a)};return Object.defineProperties(Object.create(Object.getPrototypeOf(a)),{...o,features:{value:n,enumerable:!0,configurable:!0,writable:!0},atoms:{value:r,enumerable:!0,configurable:!0,writable:!0},initialState:{value:i,enumerable:!0,configurable:!0,writable:!0}})}function AE(e,t,n){let r=kE(e,tw(t,e.options));e.optionsStore?e.optionsStore.set(()=>r):e.options=r,n?.syncExternalState!==!1&&DE(e,r.state??null)}var jE={coreCellsFeature:Tw,coreColumnsFeature:Qw,coreHeadersFeature:oT,coreRowModelsFeature:lE,coreRowsFeature:TE,coreTablesFeature:{constructTableAPIs:e=>{yw(`coreTablesFeature`,e,{table_reset:{fn:()=>OE(e)},table_setOptions:{fn:t=>AE(e,t)}})}}};function ME(){return{accessor:(e,t)=>typeof e==`function`?{...t,accessorFn:e}:{...t,accessorKey:e},columns:e=>e,display:e=>e,group:e=>e}}function NE(e){return e}function PE(e,t={}){return Object.values(e).forEach(e=>{t=e.getInitialState?.(t)??t}),nw(t)}function FE(e){let t=e.features.coreReactivityFeature,{aggregationFns:n,columnMeta:r,coreRowModel:i,expandedRowModel:a,facetedMinMaxValues:o,facetedRowModel:s,facetedUniqueValues:c,filterFns:l,filterMeta:u,filteredRowModel:d,groupedRowModel:f,paginatedRowModel:p,sortFns:m,sortedRowModel:h,tableMeta:g,..._}=e.features,v={_cellInstanceInitFns:[],_columnInstanceInitFns:[],_features:{...jE,..._},_headerGroupInstanceInitFns:[],_headerInstanceInitFns:[],_reactivity:t,_rowInstanceInitFns:[],_rowModelFns:{aggregationFns:n,filterFns:l,sortFns:m},_rowModels:{},atoms:{},baseAtoms:{}},y=Object.values(v._features),b={...y.reduce((e,t)=>Object.assign(e,t.getDefaultTableOptions?.(v)),{}),...e};if(t.wrapExternalAtoms&&b.atoms)for(let[e,n]of Object.entries(b.atoms)){let r=n,i=t.createWritableAtom(r.get(),{debugName:`externalAtom/${e}`});b.atoms[e]=i;let a=!1,o=r.subscribe(e=>{a||i.set(e)}),s=i.subscribe(e=>{a=!0,r.set(e),a=!1});t.addSubscription(o),t.addSubscription(s)}t.createOptionsStore?(v.optionsStore=t.createWritableAtom(b,{debugName:`table/optionsStore`}),Object.defineProperty(v,"options",{configurable:!0,enumerable:!0,get(){return v.optionsStore.get()},set(e){v.optionsStore.set(()=>e)}})):v.options=b,v.initialState=PE(v._features,v.options.initialState);let x=Object.keys(v.initialState);for(let e=0;e<x.length;e++){let n=x[e];v.baseAtoms[n]=t.createWritableAtom(v.initialState[n],{debugName:`table/baseAtoms/${n}`}),v.atoms[n]=t.createReadonlyAtom(()=>{let e=v.options,t=e.atoms?.[n],r=t?t.get():v.baseAtoms[n].get();if(t)return r;let i=e.state;if(i&&aw(i,n)){let e=i[n];return e===void 0?v.initialState[n]:e}return r},{debugName:`table/atoms/${n}`})}EE(v),v.store=ZC(t.createReadonlyAtom(()=>{let e={};for(let t=0;t<x.length;t++){let n=x[t];e[n]=v.atoms[n].get()}return e},{compare:HC,debugName:`table/store`}));for(let e=0;e<y.length;e++){let t=y[e];t.initTableInstanceData?.(v),t.initCellInstanceData&&v._cellInstanceInitFns.push(t.initCellInstanceData.bind(t)),t.initColumnInstanceData&&v._columnInstanceInitFns.push(t.initColumnInstanceData.bind(t)),t.initHeaderGroupInstanceData&&v._headerGroupInstanceInitFns.push(t.initHeaderGroupInstanceData.bind(t)),t.initHeaderInstanceData&&v._headerInstanceInitFns.push(t.initHeaderInstanceData.bind(t)),t.initRowInstanceData&&v._rowInstanceInitFns.push(t.initRowInstanceData.bind(t)),t.constructTableAPIs?.(v)}return v}function IE(){return iw()}function LE(e,t){e.options.onRowSelectionChange?.(t)}function RE(e,t){e._lastSelectedRowId=null,LE(e,t?iw():Object.assign(iw(),nw(e.initialState.rowSelection??{})))}function zE(e,t,n){e._lastSelectedRowId=null,LE(e,r=>{if(t=t===void 0?!xw(e,`getIsAllRowsSelected`,KE):t,n?.deselectAll&&!t)return iw();let i=Object.assign(iw(),r),a=e.getPreGroupedRowModel().flatRows;if(t){let e=new Map;a.forEach(t=>{cD(t,e)&&(i[t.id]=!0)})}else a.forEach(e=>{nD(e)&&delete i[e.id]});return i})}function BE(e,t,n){e._lastSelectedRowId=null,LE(e,r=>{let i=t===void 0?!xw(e,`getIsAllPageRowsSelected`,qE):t;if(n?.deselectAll&&!i)return iw();let a=Object.assign(iw(),r);return e.getRowModel().rows.forEach(t=>{sD(a,t.id,i,!0,e,!0)}),a})}function VE(e){return e.getCoreRowModel()}function HE(e){let t=e.getCoreRowModel();return xw(e,`getIsSomeRowsSelected`,JE)?dD(t,e):{rows:[],flatRows:[],rowsById:iw()}}function UE(e){let t=e.getFilteredRowModel();return xw(e,`getIsSomeRowsSelected`,JE)?dD(t,e):{rows:[],flatRows:[],rowsById:iw()}}function WE(e){let t=e.getSortedRowModel();return xw(e,`getIsSomeRowsSelected`,JE)?dD(t,e):{rows:[],flatRows:[],rowsById:iw()}}function GE(e){return Object.keys(e.atoms.rowSelection?.get()??{})}function KE(e){let t=e.getFilteredRowModel().flatRows,n=e.atoms.rowSelection?.get()??{},r=!!(t.length&&Object.keys(n).length);if(r){let e=new Map;t.some(t=>!fD(t,n)&&cD(t,e))&&(r=!1)}return r}function qE(e){let t=e.getPaginatedRowModel().flatRows,n=e.atoms.rowSelection?.get()??{},r=new Map,i=!1;for(let e=0;e<t.length;e++){let a=t[e];if(fD(a,n))!i&&cD(a,r)&&(i=!0);else if(cD(a,r))return!1}return i}function JE(e){return xw(e,`getSelectedRowIds`,GE).length>0}function YE(e){return e.getPaginatedRowModel().flatRows.filter(e=>nD(e)).some(e=>$E(e)||xw(e,`getIsSomeSelected`,eD))}function XE(e){return t=>{zE(e,t.target.checked)}}function ZE(e){return t=>{BE(e,t.target.checked)}}function QE(e,t,n){let r=$E(e);LE(e.table,i=>{t=t===void 0?!r:t;let a=Object.assign(iw(),i);return sD(a,e.id,t,(n?.selectChildren??!0)&&iD(e),e.table),!t&&n?.deselectParents&&lD(a,e),a})}function $E(e){return fD(e,e.table.atoms.rowSelection?.get()??{})}function eD(e){return pD(e)===`some`}function tD(e){return pD(e)===`all`}function nD(e){let t=e.table.options;return typeof t.enableRowSelection==`function`?t.enableRowSelection(e):t.enableRowSelection??!0}function rD(e){let t=e.table.options;return typeof t.enableSubRowSelection==`function`?t.enableSubRowSelection(e):t.enableSubRowSelection??!0}function iD(e){let t=e.table.options;return typeof t.enableMultiRowSelection==`function`?t.enableMultiRowSelection(e):t.enableMultiRowSelection??!0}function aD(e,t){let n=nD(e);return r=>{if(!n)return;let i=r,a=e.table,o=i.target.checked,s=a._lastSelectedRowId;(!(a.options.enableRowRangeSelection!==!1&&s!==null&&iD(e)&&(a.options.isRowRangeSelectionEvent?.(r)??!1))||!oD(e,s,o,t))&&QE(e,o,t),a._lastSelectedRowId=e.id}}function oD(e,t,n,r){let i=r?.selectChildren??!0,a=e.table,o=a.getRowsInDisplayOrder(),s=a.getPrePaginatedRowModel().rowsById[t]??a.getCoreRowModel().rowsById[t];if(!s)return!1;let c=s.getDisplayIndex(),l=e.getDisplayIndex(),u=o[c],d=o[l];if(c<0||l<0||c>=o.length||l>=o.length||u?.id!==s.id||d?.id!==e.id||!iD(s)||!iD(e))return!1;let f=Math.min(c,l),p=Math.max(c,l);return LE(a,e=>{let t=Object.assign(iw(),e);for(let e=f;e<=p;e++){let s=o[e];nD(s)&&iD(s)&&(sD(t,s.id,n,i,a),!n&&r?.deselectParents&&lD(t,s))}return t}),!0}function sD(e,t,n,r,i,a){let o=i.getRow(t,!0);n?(iD(o)||Object.keys(e).forEach(t=>delete e[t]),nD(o)&&(e[t]=!0)):(!a||nD(o))&&delete e[t],r&&o.subRows.length&&rD(o)&&o.subRows.forEach(t=>sD(e,t.id,n,r,i,a))}function cD(e,t){if(!nD(e))return!1;let n=e.table;if(n.options.enableSubRowSelection===!0)return!0;let r=e.parentId;if(r===void 0)return!0;let i=t.get(r);if(i!==void 0)return i;let a=n.getCoreRowModel().rowsById,o=[],s=!0,c=r;for(;c!==void 0;){let e=t.get(c);if(e!==void 0){s=e;break}o.push(c);let r=a[c]??n.getRow(c,!0);if(!rD(r)){s=!1;break}c=r.parentId}return o.forEach(e=>t.set(e,s)),s}function lD(e,t){let n=t.table.getCoreRowModel().rowsById,r=t.parentId;for(;r!==void 0;)delete e[r],r=(n[r]??t.table.getRow(r,!0)).parentId}function uD(e,t,n,r){let i=[];for(let a=0;a<e.length;a++){let o=e[a],s=fD(o,t);if(s&&(n.push(o),r[o.id]=o),o.subRows.length){let e=uD(o.subRows,t,n,r);if(s){let t=Object.create(Object.getPrototypeOf(o));rw(t,o),t.subRows=e,i.push(t)}}else s&&i.push(o)}return i}function dD(e,t){let n=[],r=iw(),i=t.atoms.rowSelection?.get()??{};return{rows:uD(e.rows,i,n,r),flatRows:n,rowsById:r}}function fD(e,t){return!!(aw(t,e.id)&&t[e.id])}function pD(e){if(!e.subRows.length)return!1;let t=e.table.atoms.rowSelection?.get()??{},n=!1,r=!0,i=!1;for(let a=0;a<e.subRows.length;a++){let o=e.subRows[a];if(n&&!r)break;if(nD(o)&&(i=!0,fD(o,t)?n=!0:r=!1),o.subRows.length){let e=pD(o);e===`all`?(n=!0,i=!0):e===`some`?(n=!0,r=!1,i=!0):r=!1}}return i?r?`all`:n?`some`:!1:!1}var mD={initTableInstanceData:e=>{e._lastSelectedRowId=null},resetTableInstanceData:e=>{e._lastSelectedRowId=null},getInitialState:e=>({rowSelection:IE(),...e}),getDefaultTableOptions:e=>({onRowSelectionChange:ow(`rowSelection`,e),enableRowSelection:!0,enableMultiRowSelection:!0,enableRowRangeSelection:!0,enableSubRowSelection:!0,isRowRangeSelectionEvent:e=>{let t=e;return!!(t.shiftKey||t.nativeEvent?.shiftKey)}}),assignRowPrototype:(e,t)=>{bw(`rowSelectionFeature`,e,t,{row_toggleSelected:{fn:(e,t,n)=>QE(e,t,n)},row_getIsSelected:{fn:e=>$E(e)},row_getIsSomeSelected:{fn:e=>eD(e),memoDeps:e=>[e.subRows,e.table.atoms.rowSelection?.get(),e.table.options.enableRowSelection]},row_getIsAllSubRowsSelected:{fn:e=>tD(e),memoDeps:e=>[e.subRows,e.table.atoms.rowSelection?.get(),e.table.options.enableRowSelection]},row_getCanSelect:{fn:e=>nD(e)},row_getCanSelectSubRows:{fn:e=>rD(e)},row_getCanMultiSelect:{fn:e=>iD(e)},row_getToggleSelectedHandler:{fn:(e,t)=>aD(e,t)}})},constructTableAPIs:e=>{yw(`rowSelectionFeature`,e,{table_setRowSelection:{fn:t=>LE(e,t)},table_resetRowSelection:{fn:t=>RE(e,t)},table_toggleAllRowsSelected:{fn:(t,n)=>zE(e,t,n)},table_toggleAllPageRowsSelected:{fn:(t,n)=>BE(e,t,n)},table_getPreSelectedRowModel:{fn:()=>VE(e)},table_getSelectedRowModel:{fn:()=>HE(e),memoDeps:()=>[e.atoms.rowSelection?.get(),e.getCoreRowModel()]},table_getFilteredSelectedRowModel:{fn:()=>UE(e),memoDeps:()=>[e.atoms.rowSelection?.get(),e.getFilteredRowModel()]},table_getGroupedSelectedRowModel:{fn:()=>WE(e),memoDeps:()=>[e.atoms.rowSelection?.get(),e.getSortedRowModel()]},table_getSelectedRowIds:{fn:()=>GE(e),memoDeps:()=>[e.atoms.rowSelection?.get()]},table_getIsAllRowsSelected:{fn:()=>KE(e),memoDeps:()=>[e.atoms.rowSelection?.get(),e.getFilteredRowModel(),e.options.enableRowSelection,e.options.enableSubRowSelection]},table_getIsAllPageRowsSelected:{fn:()=>qE(e),memoDeps:()=>[e.atoms.rowSelection?.get(),e.getPaginatedRowModel(),e.options.enableRowSelection,e.options.enableSubRowSelection]},table_getIsSomeRowsSelected:{fn:()=>JE(e),memoDeps:()=>[e.atoms.rowSelection?.get()]},table_getIsSomePageRowsSelected:{fn:()=>YE(e),memoDeps:()=>[e.atoms.rowSelection?.get(),e.getPaginatedRowModel(),e.options.enableRowSelection]},table_getToggleAllRowsSelectedHandler:{fn:()=>XE(e)},table_getToggleAllPageRowsSelectedHandler:{fn:()=>ZE(e)}})}},hD={getInitialState(e){return{sorting:MT(),...e}},getDefaultColumnDef(){return{sortFn:`auto`,sortUndefined:1}},getDefaultTableOptions(e){return{autoResetSorting:!1,onSortingChange:ow(`sorting`,e),isMultiSortEvent:e=>e.shiftKey}},assignColumnPrototype(e,t){bw(`rowSortingFeature`,e,t,{column_getAutoSortFn:{fn:e=>IT(e)},column_getAutoSortDir:{fn:e=>LT(e)},column_getSortFn:{fn:e=>RT(e)},column_toggleSorting:{fn:(e,t,n)=>zT(e,t,n)},column_getFirstSortDir:{fn:e=>BT(e)},column_getNextSortingOrder:{fn:(e,t)=>VT(e,t)},column_getCanSort:{fn:e=>HT(e)},column_getCanMultiSort:{fn:e=>UT(e)},column_getIsSorted:{fn:e=>WT(e)},column_getSortIndex:{fn:e=>GT(e)},column_clearSorting:{fn:e=>KT(e)},column_getToggleSortingHandler:{fn:e=>qT(e)}})},constructTableAPIs(e){yw(`rowSortingFeature`,e,{table_setSorting:{fn:t=>NT(e,t)},table_resetSorting:{fn:t=>PT(e,t)}})}},gD=typeof window>`u`?o.useEffect:o.useLayoutEffect;function _D(e,t){let[{table:n,rootSource:r}]=(0,o.useState)(()=>{let t=FE({...e,features:{coreReactivityFeature:ew(),...e.features}});return t.Subscribe=(e=>XC({...e,source:e.source??t.store})),t.FlexRender=CC,{table:t,rootSource:$C(t.store,HC)}}),i=n;AE(i,t=>({...t,...e}),{syncExternalState:!1});let a=i.options.state,s=r.get(),c=YC(r,t,{compare:HC});return gD(()=>{r.markCommitted(s),DE(i,a??null,HC)}),(0,o.useMemo)(()=>({...n,options:e,state:c}),[n,e,c])}var vD=(e,t)=>{let n=String(t);return e&&Object.hasOwn(e,n)?e[n]:void 0},yD=e=>(0,B.jsx)(`span`,{className:`text-faint-foreground`,children:e}),bD=e=>typeof e==`object`&&e&&`name`in e?String(e.name):String(e),xD=(e,t)=>{if(t==null)return yD(`—`);switch(e.kind){case`text`:return(0,B.jsx)(`span`,{className:`truncate`,children:String(t)});case`id`:return(0,B.jsx)(`span`,{className:`truncate font-mono text-xs text-muted-foreground`,children:String(t)});case`money`:return(0,B.jsxs)(`span`,{className:`tabular-nums`,children:[Of(Number(t),e.currency,e.decimals),e.suffix]});case`date`:return(0,B.jsx)(`span`,{className:`tabular-nums text-muted-foreground`,children:Lf(Number(t))});case`datetime`:return(0,B.jsx)(`span`,{className:`tabular-nums text-muted-foreground`,children:zf(Number(t))});case`number`:return(0,B.jsxs)(`span`,{className:`tabular-nums`,children:[Af(Number(t)),e.suffix]});case`signed`:return(0,B.jsxs)(`span`,{className:z(`tabular-nums`,Number(t)<0?`text-danger-text`:`text-success-text`),children:[jf(Number(t)),e.suffix]});case`percent`:return Number(t)===0?yD(`—`):(0,B.jsx)(`span`,{className:`tabular-nums`,children:Mf(Number(t))});case`status`:return(0,B.jsx)(Cd,{tone:e.tones?.[String(t)]??`neutral`,color:vD(e.colors,t),shape:e.shape,children:Bo(String(t),e.labels)});case`relation`:return(0,B.jsx)(`span`,{className:`truncate font-medium text-primary-text hover:underline`,children:bD(t)});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)(de,{className:`size-3`,strokeWidth:3})}):yD(`No`);case`file`:{let e=q_(t);if(!e)return yD(`—`);if(`missing`in e)return(0,B.jsx)(`span`,{className:`truncate text-danger-text`,children:e.name});let n=tv(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)(py,{image:n,className:`size-5 shrink-0 rounded-sm object-cover`}):(0,B.jsx)(Nt,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,B.jsx)(`span`,{className:`truncate`,children:e.name})]})}case`user`:{let e=NS(String(t));return(0,B.jsxs)(`span`,{className:`inline-flex items-center gap-2 truncate`,children:[(0,B.jsx)(md,{initials:e.initials,hue:e.hue,size:`xs`,className:`ring-0`}),(0,B.jsx)(`span`,{className:`truncate text-muted-foreground`,children:e.name})]})}}},SD=NE({rowSortingFeature:hD,rowSelectionFeature:mD}),CD=ME(),wD=e=>CD.columns(e.map(e=>CD.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):xD(e,t.getValue())}))),TD=({total:e,selectedCount:t,bulkActions:n=[],className:r})=>(0,B.jsx)(`div`,{className:z(`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:[Nf(e),t>0&&(0,B.jsxs)(`span`,{className:`ml-3 font-medium text-primary-text`,children:[Af(t),` selected`]}),t>0&&n.map(e=>(0,B.jsx)(`button`,{type:`button`,onClick:e.onRun,className:z(`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))]})}),ED=(e,t)=>e.filter(e=>e.available?.(t)??!0),DD=4,OD=(e,t)=>{let n=e.bottom+DD;return{top:n+t>window.innerHeight-DD?Math.max(DD,e.top-DD-t):n,right:window.innerWidth-e.right}},kD=({row:e,actions:t})=>{let[n,r]=(0,o.useState)(!1),[i,a]=(0,o.useState)(),s=(0,o.useRef)(null),c=(0,o.useRef)(null);return(0,o.useLayoutEffect)(()=>{if(!n||!s.current||!c.current){a(void 0);return}a(OD(s.current.getBoundingClientRect(),c.current.offsetHeight))},[n]),(0,o.useEffect)(()=>{if(!n)return;let e=e=>s.current?.contains(e)||c.current?.contains(e),t=t=>{(t instanceof KeyboardEvent?t.key===`Escape`:!e(t.target))&&r(!1)},i=()=>r(!1);return document.addEventListener(`mousedown`,t),document.addEventListener(`keydown`,t),document.addEventListener(`scroll`,i,!0),window.addEventListener(`resize`,i),()=>{document.removeEventListener(`mousedown`,t),document.removeEventListener(`keydown`,t),document.removeEventListener(`scroll`,i,!0),window.removeEventListener(`resize`,i)}},[n]),(0,B.jsxs)(`div`,{className:`relative flex justify-center bg-inherit`,onClick:e=>e.stopPropagation(),children:[(0,B.jsx)(`button`,{ref:s,type:`button`,"aria-label":`Row actions`,"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)(Ve,{className:`size-4`})}),n&&(0,Fn.createPortal)((0,B.jsx)(`ul`,{ref:c,role:`menu`,onClick:e=>e.stopPropagation(),style:i??{visibility:`hidden`},className:`fixed z-50 min-w-36 rounded-md border bg-background py-1 text-[13px] shadow-pop`,children:t.map(t=>(0,B.jsx)(`li`,{role:`none`,children:(0,B.jsx)(`button`,{type:`button`,role:`menuitem`,className:z(`block w-full px-3 py-1.5 text-left hover:bg-muted`,t.destructive&&`text-danger-text`),onClick:()=>{r(!1),t.onSelect(e)},children:t.label})},t.label))}),document.body)]})},AD=e=>52+Math.ceil(String(e).length*1.33)*7,jD=.6,MD=(e,t)=>Math.max(e.minWidth??0,e.width*t),ND=(e,t)=>e.fixed?`${Math.max(e.minWidth??0,e.width)}px`:`minmax(${MD(e,t)}px, ${e.width}fr)`,PD=(e,t,n=0,r=jD)=>`${t}px ${e.map(e=>ND(e,r)).join(` `)}${n>0?` ${n}px`:``}`,FD=(e,t,n=0,r=jD)=>t+n+e.reduce((e,t)=>e+(t.fixed?Math.max(t.minWidth??0,t.width):MD(t,r)),0),ID=()=>{let e=(0,o.useRef)(null),t=(0,o.useRef)(null),[n,r]=(0,o.useState)({scrolled:!1,more:!1}),i=(0,o.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,o.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}},LD=`protobase:pinned:`,RD=(e,t)=>`${LD}${e}:${t}`,zD=(e,t)=>jd(()=>{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),BD=(e,t,n)=>jd(()=>n.length===0?e.removeItem(t):e.setItem(t,JSON.stringify(n)),void 0),VD=(e,t=[])=>{let[n,r]=(0,o.useState)(()=>(e?zD(localStorage,e):void 0)??t);return[n,(0,o.useCallback)(t=>{r(t),e&&BD(localStorage,e,t)},[e])]},HD=e=>e===`money`||e===`number`||e===`signed`||e===`percent`,UD=({header:e,pinned:t,onTogglePin:n})=>{let[r,i]=(0,o.useState)(!1),a=(0,o.useRef)(null);return(0,o.useEffect)(()=>{if(!r)return;let e=e=>{(e instanceof KeyboardEvent?e.key===`Escape`:!a.current?.contains(e.target))&&i(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,e),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,e)}},[r]),(0,B.jsxs)(`div`,{ref:a,className:`relative ml-auto shrink-0`,children:[(0,B.jsx)(`button`,{type:`button`,"aria-label":`${e} column menu`,"aria-haspopup":`menu`,"aria-expanded":r,onClick:()=>i(!r),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)(Ve,{className:`size-3.5`})}),r&&(0,B.jsx)(`ul`,{role:`menu`,className:`absolute right-0 top-full z-30 mt-1 min-w-32 rounded-md border bg-background py-1 text-[13px] font-normal text-foreground shadow-pop`,children:(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:()=>{i(!1),n()},children:t?`Unpin`:`Pin to left`})})})]})},WD=({sorted:e})=>e===`asc`?(0,B.jsx)(E,{className:`size-3 text-foreground`}):e===`desc`?(0,B.jsx)(S,{className:`size-3 text-foreground`}):(0,B.jsx)(ye,{className:`size-3 opacity-0 group-hover/head:opacity-100`}),GD=({cells:e,specs:t,gutter:n,selectedCount:r,selectable:i,trailing:a,minScale:o,pins:s={},lastPinned:c,scrolled:l,onTogglePin:u,onClearSelection:d})=>(0,B.jsxs)(`div`,{className:`grid h-8 shrink-0 items-center border-b bg-surface text-xs font-medium text-muted-foreground`,style:{gridTemplateColumns:PD(t,n,a,o)},role:`row`,children:[(0,B.jsxs)(`div`,{className:z(`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)(Yh,{checked:!1,indeterminate:r>0,label:`Clear selection`,onChange:d,className:z(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:z(`group/cell flex h-full min-w-0 items-center`,r&&`sticky z-10 bg-inherit`,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:[(0,B.jsxs)(`button`,{type:`button`,onClick:n,disabled:!e.sortable,className:z(`group/head flex h-full min-w-0 flex-1 items-center gap-1 pl-3 pr-1 text-left`,HD(e.kind)&&`justify-end`,e.sortable&&`hover:text-foreground`,t&&`text-foreground`),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:`New`}),e.sortable&&(0,B.jsx)(WD,{sorted:t})]}),(0,B.jsx)(`div`,{className:`pr-1.5`,children:(0,B.jsx)(UD,{header:e.header,pinned:r,onTogglePin:()=>u(e.id)})})]},e.id)}),a?(0,B.jsx)(`div`,{}):null]}),KD=e=>({gridTemplateColumns:PD(e.specs,e.gutter,e.trailing,e.minScale),height:e.height,transform:`translateY(${e.offset}px)`}),qD=(e,t)=>z(`flex h-full min-w-0 items-center overflow-hidden whitespace-nowrap px-3`,HD(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)]`),JD=(e,t)=>t&&e.id in t?{left:t[e.id]}:void 0,YD=({width:e,index:t,selectable:n,selected:r,onToggle:i,edge:a})=>(0,B.jsxs)(`div`,{className:z(`sticky left-0 z-10 flex h-full items-center gap-2 bg-inherit pl-3`,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)(`span`,{onClick:e=>e.stopPropagation(),children:(0,B.jsx)(Yh,{checked:!!r,onChange:i,label:`Select row ${t+1}`})}),e>40&&(0,B.jsx)(`span`,{className:`min-w-6 text-right text-[11px] tabular-nums text-faint-foreground`,children:Af(t+1)})]}),XD=({cells:e,selected:t,onToggle:n,onOpen:r,menu:i,...a})=>(0,B.jsxs)(`div`,{role:`row`,onClick:r,className:z(`absolute inset-x-0 top-0 grid items-center border-b text-[13px]`,t?`bg-primary-soft`:`bg-background hover:bg-surface`,r&&`cursor-pointer`),style:KD(a),children:[(0,B.jsx)(YD,{width:a.gutter,index:a.index,selectable:a.selectable,selected:t,onToggle:n,edge:a.scrolled&&!a.lastPinned}),e.map(({spec:e,content:t})=>(0,B.jsx)(`div`,{role:`cell`,className:qD(e,a),style:JD(e,a.pins),children:t},e.id)),i&&(0,B.jsx)(`div`,{className:`flex h-full items-center justify-center`,children:i})]}),ZD=[`w-3/4`,`w-1/2`,`w-2/3`,`w-5/6`,`w-2/5`],QD=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:KD(e),children:[(0,B.jsx)(YD,{width:e.gutter,index:e.index,selectable:!1,edge:e.scrolled&&!e.lastPinned}),e.specs.map((t,n)=>(0,B.jsx)(`div`,{className:qD(t,e),style:JD(t,e.pins),children:(0,B.jsx)(od,{className:z(`h-2.5`,ZD[(e.index+n)%ZD.length],HD(t.kind)&&`ml-auto`)})},t.id))]}),$D=(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)},get size(){return n.size}}},eO=(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)},tO=({total:e,rowAt:t,loadRows:n,latencyMs:r},i,a)=>{let s=(0,o.useMemo)(()=>$D(40,60),[t,n]),[c,l]=(0,o.useState)(0),u=Math.floor(i/40),d=Math.floor(a/40),f=!n&&r===0;return(0,o.useEffect)(()=>{if(f)return;let i=eO(u*40,d*40,40).filter(e=>!s.hasPage(e)),a=t=>Math.max(0,Math.min(40,e-t*40)),o=(e,t)=>{s.setPage(e,t),l(e=>e+1)};if(n){let e=!1;for(let t of i)n(t*40,a(t)).then(n=>{e||o(t,n)});return()=>{e=!0}}let c=i.map(e=>setTimeout(()=>o(e,Array.from({length:a(e)},(n,r)=>t(e*40+r))),r));return()=>c.forEach(clearTimeout)},[s,u,d,r,e,t,n,f]),(0,o.useCallback)(e=>f?t(e):s.get(e),[s,f,t,c])},nO=1e7,rO=(e,t,n)=>{let r=e*t,i=Math.min(r,nO);return{rowHeight:t,trueHeight:r,contentHeight:i,scaled:r>i,maxTop:Math.max(0,r-n),maxScroll:Math.max(0,i-n)}},iO=(e,t)=>!e.scaled||t<=0?t:t>=e.maxScroll?e.maxTop+t-e.maxScroll:t/e.maxScroll*e.maxTop,aO=(e,t)=>!e.scaled||t<=0?t:t>=e.maxTop?e.maxScroll+t-e.maxTop:t/e.maxTop*e.maxScroll,oO=(e,t,n,r)=>{let i=t*e.rowHeight;return e.scaled?i-n+r:i},sO=(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)}},cO=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},lO=e=>e===(document.scrollingElement??document.documentElement),uO=e=>lO(e)?window:e,dO=e=>Number.parseFloat(e)||0,fO=e=>{let t=getComputedStyle(e),n=lO(e)?{top:0,height:e.clientHeight}:{top:e.getBoundingClientRect().top+e.clientTop,height:e.clientHeight},r=dO(t.scrollPaddingTop);return{top:n.top+r,height:Math.max(0,n.height-r-dO(t.scrollPaddingBottom))}},pO=6,mO=(e,t,n)=>{let r=rO(t,n,e.height),i=iO(r,e.position);return{geometry:r,top:i,topIndex:Math.floor(Math.max(0,i)/n),...sO(t,i,n,e.height,pO)}},hO=({total:e,rowHeight:t,initialIndex:n,inset:r=0,settle:i,ready:a=!0})=>{let s=(0,o.useRef)(null),c=(0,o.useRef)(null),[l,u]=(0,o.useState)({position:0,height:0}),d=(0,o.useRef)({total:e,rowHeight:t,initialIndex:n,inset:r,ready:a});d.current={total:e,rowHeight:t,initialIndex:n,inset:r,ready:a};let f=(0,o.useCallback)(()=>{let e=s.current;if(!e||!c.current)return;let t=fO(c.current),n=d.current.inset;return{position:t.top+n-e.getBoundingClientRect().top,height:Math.max(0,t.height-n)}},[]),p=(0,o.useRef)(l);p.current=l;let m=(0,o.useCallback)(()=>{let e=f();if(!e)return;let t=p.current,{total:n,rowHeight:r}=d.current,i=mO(t,n,r),a=mO(e,n,r),o=!a.geometry.scaled&&i.first===a.first&&i.last===a.last&&i.topIndex===a.topIndex;(t.height!==e.height||t.position!==e.position&&!o)&&(p.current=e,u(e))},[f]),h=(0,o.useRef)({pending:!0,laidOut:!1}),g=(0,o.useCallback)(()=>{if(!h.current.pending||!h.current.laidOut||!d.current.ready)return;let e=f(),t=c.current;if(!e||!t)return;h.current.pending=!1;let{total:n,rowHeight:r,initialIndex:i}=d.current;i>0?t.scrollTop+=aO(rO(n,r,e.height),i*r)-e.position:e.position>0&&(t.scrollTop=0)},[f]);(0,o.useLayoutEffect)(()=>{let e=s.current;if(!e)return;let t=cO(e);c.current=t;let n=uO(t);n.addEventListener(`scroll`,m,{passive:!0}),window.addEventListener(`resize`,m,{passive:!0});let r=new ResizeObserver(()=>{h.current.laidOut=!0,g(),m()});return r.observe(t),r.observe(e),m(),()=>{n.removeEventListener(`scroll`,m),window.removeEventListener(`resize`,m),r.disconnect(),c.current=null}},[m,g]),(0,o.useLayoutEffect)(()=>{g(),m()});let _=(0,o.useCallback)(e=>{let t=f();if(!t||!c.current)return;let n=rO(d.current.total,d.current.rowHeight,t.height);c.current.scrollTop+=aO(n,e)-t.position,m()},[f,m]),v=mO(l,e,t),y=i?i(v.top):v.top,{first:b,last:x}=i?sO(e,y,t,l.height,pO):v,S=Array.from({length:x-b+1},(e,t)=>({index:b+t,offset:oO(v.geometry,b+t,y,l.position)}));return{ref:s,height:l.height,top:y,geometry:v.geometry,rows:S,first:b,last:x,scrollTo:_}},gO=32,_O=({columns:e,source:t,naturalSort:n,initialScrollIndex:r=0,onScrollIndex:i,latencyMs:a=150,sort:s,onSortChange:c,onOpenRow:l,rowActions:u,bulkActions:d,pinKey:f,defaultPinned:p,rowNumbers:m=!0,compact:h=!1,selectable:g=!0,fit:_=!1,scroll:v=`own`,className:y})=>{let b=h?28:36,[x,S]=VD(f,p),C=(0,o.useMemo)(()=>[...x.flatMap(t=>e.find(e=>e.id===t)??[]),...e.filter(e=>!x.includes(e.id))],[e,x]),w=C.slice(0,C.filter(e=>x.includes(e.id)).length).map(e=>e.id),{total:T}=t,[E,D]=(0,o.useState)(n?[{id:n.columnId,desc:n.direction===`desc`}]:[]),O=s?[{id:s.columnId,desc:s.direction===`desc`}]:E,k=e=>{let t=typeof e==`function`?e(O):e,n=t[0];c&&n&&c({columnId:n.id,direction:n.desc?`desc`:`asc`}),s||D(t)},[A,j]=(0,o.useState)({}),M=(0,o.useMemo)(()=>wD(C),[C]),N=O[0],ee=!!(!s&&n&&N&&N.id===n.columnId&&(N.desc?`desc`:`asc`)!==n.direction),te=t.rowAt,ne=(0,o.useCallback)(e=>te(ee?T-1-e:e),[te,ee,T]),[P]=(0,o.useState)(r),{ref:re,top:ie,geometry:ae,rows:F,first:oe,last:se}=hO({total:T,rowHeight:b,initialIndex:P,inset:gO}),ce=!Gu(),I=ce||!m?40:AD(T),le=Math.floor(Math.max(0,ie)/b);(0,o.useEffect)(()=>i?.(le),[le,i]);let ue=tO({total:T,rowAt:te?ne:void 0,loadRows:t.loadRows,latencyMs:a},oe,se),de=F.map(({index:e,offset:t})=>({index:e,offset:t,row:ue(e)})),fe=_D({features:SD,columns:M,data:(0,o.useMemo)(()=>de.flatMap(({row:e})=>e?[e]:[]),[ue,oe,se]),state:{sorting:O,rowSelection:A},onSortingChange:k,onRowSelectionChange:j,manualSorting:!0,enableMultiSort:!1,enableSortingRemoval:!1,getRowId:e=>e.id}),pe=new Map(fe.getRowModel().rows.map(e=>[e.id,e])),me=Object.keys(A).length,he=(0,o.useRef)(new Map);for(let e of fe.getRowModel().rows)e.getIsSelected()&&he.current.set(e.id,e.original);let ge=u&&u.length>0?40:0,_e=ce?1:jD,ve=ID(),ye=(0,o.useRef)(null),be=()=>{ve.onScroll(),ye.current&&ve.ref.current&&(ye.current.scrollLeft=ve.ref.current.scrollLeft)},[xe,Se]=(0,o.useState)({});(0,o.useLayoutEffect)(()=>{let e=ye.current?.querySelector(`[role=row]`);if(!e)return;let t=I,n={};for(let r of w)n[r]=t,t+=e.querySelector(`[data-col-id="${r}"]`)?.offsetWidth??0;JSON.stringify(xe)!==JSON.stringify(n)&&Se(n)});let Ce=w.at(-1),we=e=>S(x.includes(e)?x.filter(t=>t!==e):[...x,e]),Te=fe.getHeaderGroups().flatMap(e=>e.headers.map(e=>({spec:C.find(t=>t.id===e.column.id),sorted:e.column.getIsSorted(),onSort:t=>e.column.getToggleSortingHandler()?.(t)}))),Ee=FD(C,I,ge,_e),De=v===`own`,Oe=(0,B.jsx)(`div`,{ref:ye,className:z(`sticky z-20 shrink-0 overflow-hidden`,De?`top-0`:`top-[var(--pb-sticky-top,0px)]`),children:(0,B.jsx)(`div`,{style:{minWidth:Ee},children:(0,B.jsx)(GD,{cells:Te,specs:C,gutter:I,trailing:ge,minScale:_e,pins:xe,lastPinned:Ce,scrolled:ve.scrolled,onTogglePin:we,selectable:g,selectedCount:me,onClearSelection:()=>j({})})})}),ke=(0,B.jsx)(`div`,{ref:ve.attach,onScroll:be,className:`overflow-x-auto overflow-y-hidden overscroll-x-contain [-webkit-overflow-scrolling:touch]`,children:(0,B.jsx)(`div`,{ref:re,className:`relative`,style:{minWidth:Ee,height:ae.contentHeight},children:de.map(({index:e,offset:t,row:n})=>{let r={specs:C,gutter:I,index:e,offset:t,height:b,selectable:g,trailing:ge,minScale:_e,scrolled:ve.scrolled,pins:xe,lastPinned:Ce},i=n?pe.get(n.id):void 0;if(!i)return(0,B.jsx)(QD,{...r},`skeleton-${e}`);let a=ge&&n?ED(u,n):[];return(0,B.jsx)(XD,{...r,selected:i.getIsSelected(),onToggle:()=>i.toggleSelected(),onOpen:l&&n?()=>l(n):void 0,menu:n&&a.length>0?(0,B.jsx)(kD,{row:n,actions:a}):void 0,cells:i.getAllCells().map(e=>({spec:C.find(t=>t.id===e.column.id),content:(0,B.jsx)(fe.FlexRender,{cell:e})}))},n?.id)})})});return(0,B.jsxs)(`div`,{role:`grid`,"aria-rowcount":T,className:z(`flex flex-col rounded-lg border bg-background`,De?`min-h-0 overflow-hidden`:`overflow-clip`,y),style:_&&De?{height:gO+T*b+2}:void 0,children:[(0,B.jsxs)(`div`,{className:z(`relative`,De&&`flex min-h-0 flex-1 flex-col`),children:[De?(0,B.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overflow-x-hidden`,children:[Oe,ke]}):(0,B.jsxs)(B.Fragment,{children:[Oe,ke]}),ve.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`})]}),!_&&(0,B.jsx)(TD,{total:T,className:De?void 0:`sticky bottom-[var(--pb-sticky-bottom,0px)] z-20`,selectedCount:me,bulkActions:d?.map(e=>({label:e.label(me),destructive:e.destructive,onRun:()=>{e.onRun(Object.keys(A).flatMap(e=>he.current.get(e)??[])),j({}),he.current.clear()}}))})]})},vO=`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`,yO=({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)(ht,{className:`size-3 text-muted-foreground`}),e]},e)),e.map(e=>(0,B.jsxs)(`span`,{className:vO,children:[e.label,(0,B.jsx)(`button`,{type:`button`,"aria-label":`Remove ${e.label}`,onClick:()=>n(e.key),className:`rounded-full p-0.5 hover:bg-primary-border/60`,children:(0,B.jsx)(Nn,{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:`Clear all`})]}),bO=[`7d`,`30d`,`year`],xO={today:`Today`,yesterday:`Yesterday`,"7d":`Last 7 days`,"30d":`Last 30 days`,"90d":`Last 90 days`,month:`This month`,quarter:`This quarter`,year:`This year`},SO=({value:e,presets:t=bO,onChange:n})=>(0,B.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:t.map(t=>{let r=xO[t];return(0,B.jsx)(`button`,{type:`button`,disabled:!r,title:r?void 0:`The server offers the preset "${t}", which this UI does not know`,onClick:()=>n(e===t?void 0:t),className:z(`h-7 rounded-md border px-2.5 text-xs 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??`${t} (unsupported)`},t)})}),CO={facets:{},toggles:[]},wO=(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}}},TO=(e,t)=>({...e,toggles:e.toggles.includes(t)?e.toggles.filter(e=>e!==t):[...e.toggles,t]}),EO=(e,t,n)=>{let{[t]:r,...i}=e.ranges??{};return{...e,ranges:n?{...i,[t]:n}:i}},DO=(e,t)=>e.options.find(e=>e.value===t)?.label??e.labels?.[t]??t,OO=(e,t)=>{let n=e.facets.flatMap(e=>(t.facets[e.id]??[]).map(t=>({key:`facet:${e.id}:${t}`,label:`${e.label}: ${DO(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:xO[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]},kO=(e,t)=>{if(t===`date`)return{...e,date:void 0};let[n,r,i]=t.split(`:`);if(n===`range`)return EO(e,r,void 0);if(n===`toggle`)return TO(e,r);if(n===`facet`)return wO(e,r,i);throw Error(`Unknown filter chip key: ${t}`)},AO=(e,t)=>e.toLowerCase().includes(t.trim().toLowerCase()),jO=(e,t)=>e.onSearch?e.options:e.options.filter(e=>AO(e.label,t)),MO=(e,t,n)=>t===0?-1:n===`ArrowDown`?e<0?0:(e+1)%t:e<0?t-1:(e-1+t)%t,NO=({config:e,selected:t,onToggle:n,inline:r=!1})=>{let i=(0,o.useId)(),a=(0,o.useRef)(null),[s,c]=(0,o.useState)(``),[l,u]=(0,o.useState)(!1),[d,f]=(0,o.useState)(-1),p=r||l,m=jO(e,s),h=(0,o.useRef)(e.onSearch);h.current=e.onSearch,(0,o.useEffect)(()=>()=>h.current?.(``),[]);let g=t=>{c(t),f(-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)(qt,{className:`size-3.5 shrink-0 text-muted-foreground`}),t.map(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:DO(e,t)}),(0,B.jsx)(`button`,{type:`button`,"aria-label":`Remove ${DO(e,t)}`,className:`rounded p-0.5 hover:bg-primary-border/60`,onMouseDown:e=>e.preventDefault(),onClick:()=>n(t),children:(0,B.jsx)(Nn,{className:`size-3`})})]},t)),(0,B.jsx)(`input`,{ref:a,autoFocus:r,role:`combobox`,"aria-label":e.label,"aria-expanded":p,"aria-controls":`${i}-options`,"aria-autocomplete":`list`,"aria-activedescendant":m[d]?`${i}-${d}`:void 0,placeholder:t.length>0?``:`Search ${e.label.toLowerCase()}`,className:`h-6 min-w-16 flex-1 bg-transparent text-[13px] text-foreground outline-none placeholder:text-faint-foreground`,value:s,onChange:e=>g(e.target.value),onKeyDown:e=>{if(e.key===`ArrowDown`||e.key===`ArrowUp`){e.preventDefault(),f(MO(d,m.length,e.key));return}if(e.key===`Enter`&&m[d]){e.preventDefault(),n(m[d].value);return}if(e.key===`Backspace`&&s===``&&t.length>0){n(t[t.length-1]);return}e.key===`Escape`&&s!==``&&(e.stopPropagation(),g(``))},onFocus:()=>u(!0),onBlur:()=>{u(!1),f(-1),!r&&s!==``&&g(``)}})]}),p&&(0,B.jsxs)(`ul`,{id:`${i}-options`,role:`listbox`,"aria-label":e.label,"aria-multiselectable":!0,className:z(`flex max-h-60 flex-col gap-px overflow-y-auto`,!r&&`rounded-md border bg-background p-1 shadow-sm`),children:[m.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:z(`flex cursor-pointer items-center gap-2 rounded px-1.5 py-1 hover:bg-muted`,r===d&&`bg-muted`),onMouseDown:e=>e.preventDefault(),onClick:()=>n(e.value),children:[(0,B.jsx)(`span`,{className:z(`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)(de,{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:Af(e.count)})]},e.value)}),m.length===0&&(0,B.jsx)(`li`,{className:`px-1.5 py-1 text-xs text-faint-foreground`,children:`No matches`})]})]})},PO=({config:e,selected:t,onToggle:n})=>{let[r,i]=(0,o.useState)(``),a=e.options.filter(e=>AO(e.label,r));return(0,B.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[e.searchable&&(0,B.jsx)(Yd,{wrapperClassName:`mb-1 h-7`,leading:(0,B.jsx)(qt,{className:`size-3.5`}),placeholder:`Search ${e.label.toLowerCase()}`,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)(Yh,{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:Af(e.count)})]},e.value)),a.length===0&&(0,B.jsx)(`span`,{className:`px-1 py-1 text-xs text-faint-foreground`,children:`No matches`})]})},FO=({label:e,activeCount:t,width:n=240,defaultOpen:r=!1,children:i})=>{let[a,s]=(0,o.useState)(r),[c,l]=(0,o.useState)(!1),u=(0,o.useRef)(null);return(0,o.useLayoutEffect)(()=>{a&&u.current&&l(u.current.getBoundingClientRect().left+n>document.documentElement.clientWidth)},[a,n]),(0,o.useEffect)(()=>{if(!a)return;let e=e=>{e.target instanceof Node&&!u.current?.contains(e.target)&&s(!1)};return document.addEventListener(`pointerdown`,e),()=>document.removeEventListener(`pointerdown`,e)},[a]),(0,B.jsxs)(`div`,{ref:u,className:`relative`,children:[(0,B.jsxs)(`button`,{type:`button`,"aria-expanded":a,onClick:()=>s(!a),className:z(`inline-flex h-8 items-center gap-1.5 rounded-md border bg-background px-2.5 text-[13px] 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)(pe,{className:`size-3.5 text-muted-foreground`})]}),a&&(0,B.jsx)(`div`,{className:z(`absolute top-full z-30 mt-1.5 rounded-lg border bg-background p-3 shadow-pop`,c?`right-0`:`left-0`),style:{width:n},children:i})]})},IO=({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]}),LO=(e,t)=>{let[n,r]=(0,o.useState)(e);return(0,o.useEffect)(()=>{let n=setTimeout(()=>r(e),t);return()=>clearTimeout(n)},[e,t]),n},RO=(e,t,n,r,i)=>{let a=n+(r-n)*e/t;return n+(r-n)*(e+1)/t>i[0]&&a<i[1]},zO=(e,t,n)=>n===t?0:(e-t)/(n-t),BO=(e,t,n)=>t===0?[Math.min(n,e[1]),e[1]]:[e[0],Math.max(n,e[0])],VO=1e3,HO=({config:e,value:t,onChange:n})=>{let{min:r,max:i,step:a,histogram:s,format:c}=e,[l,u]=(0,o.useState)(),d=l??t??[r,i],f=Math.max(...s),p=()=>{l&&(u(void 0),n(l[0]===r&&l[1]===i?void 0:l))},m=LO(l,VO);return(0,o.useEffect)(()=>{m&&p()},[m]),(0,B.jsxs)(`div`,{className:`w-full`,children:[(0,B.jsxs)(`div`,{className:`px-[7px]`,children:[s.length>0&&(0,B.jsx)(`div`,{className:`mb-1 flex h-12 items-end gap-0.5`,children:s.map((e,t)=>(0,B.jsx)(`span`,{className:z(`flex-1 rounded-t-sm`,RO(t,s.length,r,i,d)?`bg-primary/70`:`bg-border`),style:{height:`${Math.max(6,e/f*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:`${zO(d[0],r,i)*100}%`,right:`${100-zO(d[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":`${e.label} ${t===0?`minimum`:`maximum`}`,min:r,max:i,step:a,value:d[t],onChange:e=>u(BO(d,t,Number(e.target.value))),onPointerUp:p,onTouchEnd:p,onBlur:p},t))}),(0,B.jsxs)(`div`,{className:`mt-2 flex justify-between text-xs tabular-nums text-muted-foreground`,children:[(0,B.jsx)(`span`,{children:c(d[0])}),(0,B.jsx)(`span`,{children:c(d[1])})]})]})},UO=({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)(H_,{checked:t,onChange:n,label:e})]}),WO=(e,t)=>e.some(e=>e.length>0)||!!t,GO=({groups:e,trailing:t})=>{if(!WO(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)(o.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})]})},KO=(e,t,n)=>{let[r,i]=(0,o.useState)(t??CO);return[e??r,e=>{i(e),n?.(e)}]},qO=({config:e,layout:t,value:n,defaultValue:r,onChange:i,lockedLabels:a,defaultOpenMenu:s,fullWidth:c,leading:l,trailing:u})=>{let[d,f]=KO(n,r,i),p=OO(e,d),m=(0,B.jsx)(yO,{chips:p,lockedLabels:a,onRemove:e=>f(kO(d,e)),onClear:()=>f(CO)}),h=(e,t=!1)=>{let n=d.facets[e.id]??[],r=t=>f(wO(d,e.id,t));return e.combobox?(0,B.jsx)(NO,{config:e,selected:n,onToggle:r,inline:t}):(0,B.jsx)(PO,{config:e,selected:n,onToggle:r})},g=e.ranges??[],_=e=>(0,B.jsx)(HO,{config:e,value:d.ranges?.[e.id],onChange:t=>f(EO(d,e.id,t))}),v=e.datePresets&&(0,B.jsx)(SO,{value:d.date,presets:Array.isArray(e.datePresets)?e.datePresets:void 0,onChange:e=>f({...d,date:e})}),y=(e.toggles??[]).map(e=>(0,B.jsx)(UO,{label:e.label,checked:d.toggles.includes(e.id),onChange:()=>f(TO(d,e.id))},e.id));if(t===`panel`)return(0,B.jsxs)(`aside`,{className:c?`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:`text-[13px] font-semibold`,children:`Filters`})}),(p.length>0||(a?.length??0)>0)&&(0,B.jsx)(`div`,{className:`border-b pb-3`,children:m}),l,e.facets.map(e=>(0,B.jsx)(IO,{title:e.label,children:h(e)},e.id)),g.map(e=>(0,B.jsx)(IO,{title:e.label,children:_(e)},e.id)),v&&(0,B.jsx)(IO,{title:`Date`,children:v}),y.length>0&&(0,B.jsx)(IO,{title:`Show only`,children:y})]});let b=[...e.facets.map(e=>(0,B.jsx)(FO,{label:e.label,activeCount:(d.facets[e.id]??[]).length,width:e.combobox?280:void 0,defaultOpen:s===e.id,children:h(e,!0)},e.id)),...g.map(e=>(0,B.jsx)(FO,{label:e.label,activeCount:+!!d.ranges?.[e.id],width:280,defaultOpen:s===e.id,children:_(e)},`range:${e.id}`)),...v?[(0,B.jsx)(o.Fragment,{children:v},`date`)]:[]],x=(e.toggles??[]).map(e=>(0,B.jsx)(`div`,{className:`flex items-center gap-2 text-[13px] text-muted-foreground`,children:(0,B.jsx)(UO,{label:e.label,checked:d.toggles.includes(e.id),onChange:()=>f(TO(d,e.id))})},e.id)),S=[l?[(0,B.jsx)(o.Fragment,{children:l},`leading`)]:[],b,x];return!WO(S,u)&&p.length===0&&!a?.length?null:(0,B.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,B.jsx)(GO,{groups:S,trailing:u}),m]})},JO={draft:`neutral`,confirmed:`blue`,picking:`amber`,shipped:`violet`,delivered:`green`,cancelled:`red`,sent:`blue`,paid:`green`,overdue:`red`,lead:`blue`,active:`green`,dormant:`neutral`,receipt:`green`,issue:`blue`,transfer:`violet`,adjustment:`amber`},YO=e=>JO[e]??`neutral`,XO={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},ZO=(e,t)=>Math.ceil(e.length*7.2)+24+(t?16:0)+28,QO=e=>Math.ceil(Math.max(0,...e.map(e=>e.length))*7.2)+56,$O=new Set([`datetime`,`date`,`boolean`,`percent`]),ek=/^(number|sku|reference|code)$/,tk=(e,t,n)=>{switch(e.type){case`relation`:return`relation`;case`file`:return`file`;case`enum`:return`status`;case`boolean`:return`boolean`;case`timestamp`:return`datetime`;case`date`:return`date`;case`decimal`:return t?.format===`percent`?`percent`:t?.prefix===`€`?`money`:`number`;case`integer`:case`bigint`:return/quantity|delta/.test(e.name)?`signed`:`number`;default:return ek.test(e.name)||n===0&&e.name===`id`?`id`:`text`}},nk=e=>Math.round(Number.parseFloat(String(e))*100),rk=(e,t)=>t?.list?.columns??Object.keys(e.fields).slice(0,6),ik=(e,t,n=[],r=rk(e,t))=>r.flatMap((r,i)=>{let a=e.fields[r];if(!a)return[];let o=t?.fields[r],s=tk(a,o,i),c=Object.fromEntries((a.enumValues??[]).map(e=>[e,Bo(e,o?.valueLabels)])),l=o?.suffix?Math.ceil(o.suffix.length*7.2):0;return[{id:r,header:o?.label??G(r),kind:s,width:(r===`name`?260:XO[s])+l,sortable:a.sortable,minWidth:Math.max(s===`id`?150:0,ZO(o?.label??G(r),a.sortable),s===`status`?QO(Object.values(c)):0,l>0?XO[s]+l:0),...$O.has(s)&&{fixed:!0},...n.includes(r)&&{highlight:!0},...a.type===`enum`&&{tones:Object.fromEntries((a.enumValues??[]).map(e=>[e,YO(e)])),labels:c},...a.type===`enum`&&o?.valueColors&&{colors:o.valueColors},...a.type===`enum`&&o?.badgeShape&&{shape:o.badgeShape},...o?.suffix!==void 0&&{suffix:o.suffix},...s===`money`&&o?.decimals!==void 0&&{decimals:o.decimals},...s===`money`&&{currency:`EUR`,value:e=>e[r]==null?null:nk(e[r])},...(s===`datetime`||s===`date`)&&{value:e=>e[r]==null?null:Date.parse(String(e[r]))},...(s===`percent`||s===`number`&&a.type===`decimal`)&&{value:e=>e[r]==null?null:Number(e[r])}}]}),ak=so(),ok={start:0,end:0},sk={"7d":{amount:7,unit:`d`},"30d":{amount:30,unit:`d`},"90d":{amount:90,unit:`d`}},ck=e=>new Date(e).toISOString().replace(`.000Z`,`Z`),lk=(e,t)=>{let[n,r,i]=[t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate()];return ck(e===`year`?Date.UTC(n,0,1):e===`quarter`?Date.UTC(n,Math.floor(r/3)*3,1):e===`month`?Date.UTC(n,r,1):e===`yesterday`?Date.UTC(n,r,i-1):Date.UTC(n,r,i))},uk=[`year`,`quarter`,`month`,`yesterday`,`today`],dk=(e,t)=>t===`date`?{kind:`string`,value:e.slice(0,10),span:ok}:{kind:`timestamp`,value:e,span:ok},fk=(e,t,n,r)=>{if(t in sk)return[ak.gte(e,ak.ago(t))];let i=ak.gte(e,dk(lk(t,n),r));return t===`yesterday`?[i,ak.lt(e,dk(lk(`today`,n),r))]:[i]},pk=(e,t,n=new Date)=>{let r=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=>ak.eq(e.value,!0));return t.length===0?[]:[t.length===1?t[0]:ak.or(...t)]}return[n.length===1?ak.eq(e.id,n[0]):ak.in(e.id,n)]}),i=(e.ranges??[]).flatMap(e=>{let n=t.ranges?.[e.id];return n?[ak.gte(e.id,n[0]),ak.lte(e.id,n[1])]:[]}),a=e.dateField&&t.date?fk(e.dateField,t.date,n,e.dateKind):[],o=(e.toggles??[]).filter(e=>t.toggles.includes(e.id)).map(e=>ak.eq(e.id,!0));return[...r,...i,...a,...o]},mk=e=>e.length===0?``:qa(ak.and(...e)),hk=(e,t,n=[],r=new Date)=>mk([...pk(e,t,r),...n]),gk=e=>e.kind===`and`?e.args.flatMap(gk):[e],_k=e=>e.field.path.join(`.`),vk=e=>e.kind===`compare`&&e.op===`=`&&e.value.kind===`boolean`&&e.value.value,yk=(e,t)=>{let n=e.kind===`or`?e.args:[e];if(!n.every(vk))return;let r=n.map(_k),i=t.get(r[0]);return i!==void 0&&r.every(e=>t.get(e)===i)?{group:i,fields:r}:void 0},bk=e=>e.kind===`number`?String(e.raw):e.kind===`string`?String(e.value):void 0,xk=(e,t)=>{let n=e.value;if(n.kind===`now`&&n.offset?.sign===`-`){let{amount:e,unit:t}=n.offset.duration;return Object.entries(sk).find(([,n])=>n.amount===e&&n.unit===t)?.[0]}if(n.kind===`timestamp`)return uk.find(e=>lk(e,t)===n.value);if(n.kind===`string`)return uk.find(e=>lk(e,t).slice(0,10)===n.value)},Sk=(e,t,n=new Date)=>{let r=oa(t);if(!r.ok)return{ok:!1,errors:r.errors};let i={facets:{},toggles:[]},a=[],o=new Set(e.facets.filter(e=>!e.flags).map(e=>e.id)),s=new Map(e.facets.filter(e=>e.flags).flatMap(e=>e.options.map(t=>[t.value,e.id]))),c=new Set((e.toggles??[]).map(e=>e.id)),l=new Set((e.ranges??[]).map(e=>e.id)),u=new Map,d,f;for(let t of r.ast?gk(r.ast):[]){let r=yk(t,s);if(r&&!i.facets[r.group])i.facets[r.group]=r.fields;else if(t.kind===`compare`&&o.has(_k(t))&&t.op===`=`&&bk(t.value)!==void 0)i.facets[_k(t)]=[...i.facets[_k(t)]??[],bk(t.value)];else if(t.kind===`in`&&o.has(_k(t))&&t.values.every(e=>bk(e)!==void 0))i.facets[_k(t)]=[...i.facets[_k(t)]??[],...t.values.map(e=>bk(e))];else if(t.kind===`compare`&&e.dateField===_k(t)&&t.op===`>=`&&xk(t,n)&&!i.date)i.date=xk(t,n),d=t;else if(t.kind===`compare`&&e.dateField===_k(t)&&t.op===`<`&&(t.value.kind===`timestamp`||t.value.kind===`string`)&&lk(`today`,n).startsWith(t.value.value.slice(0,10)))f=t;else if(t.kind===`compare`&&c.has(_k(t))&&t.op===`=`&&t.value.kind===`boolean`&&t.value.value)i.toggles.push(_k(t));else if(t.kind===`compare`&&l.has(_k(t))&&(t.op===`>=`||t.op===`<=`)&&t.value.kind===`number`){let e=u.get(_k(t))??{clauses:[]};t.op===`>=`?e.low=t.value.value:e.high=t.value.value,e.clauses.push(t),u.set(_k(t),e)}else a.push(t)}i.date===`yesterday`&&!f&&(a.push(d),i.date=void 0),f&&i.date!==`yesterday`&&a.push(f);for(let[e,t]of u)t.low!==void 0&&t.high!==void 0?i.ranges={...i.ranges,[e]:[t.low,t.high]}:a.push(...t.clauses);return{ok:!0,state:i,extras:a}},Ck=(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)}}))},wk=(e,t)=>[...new Set(t.filter(t=>!e.includes(t)))],Tk=so(),Ek=(e,t)=>{let n=W(),[r,i]=(0,o.useState)({}),a=e=>!!e?.search?.length&&e.primaryKey.length===1,s=Dh({queries:e.map(({id:e,target:i})=>{let o=(r[e]??``).trim();return{queryKey:[`reference-search`,e,i?.name??``,o],enabled:a(i)&&o!==``,placeholderData:Lm,queryFn:async()=>{let e=i.primaryKey[0],r=Og(i,t[i.name]);return(await n.list(i.name,{filter:qa(Tk.search(o)),fields:[e,r],pageSize:20})).items.map(t=>[String(t[e]),String(t[r])])}}})});return e.map(({id:e,target:t},n)=>{if(!a(t))return{};let o=t=>i(n=>({...n,[e]:t}));return(r[e]??``).trim()===``?{onSearch:o}:{onSearch:o,matches:s[n]?.data??[]}})},Dk=[`integer`,`bigint`,`decimal`],Ok=(e,t)=>{let n=e?.fields[t]?.type;return n!==void 0&&Dk.includes(n)},kk=(e,t)=>e.kind===`range`||e.kind===`facets`&&Ok(t,e.field),Ak=e=>({id:e,label:e,min:0,max:0,step:1,histogram:[],format:String}),jk=(e,t)=>{let n=e?.filters??[],r=n.find(e=>e.kind===`dateRange`);return{facets:n.flatMap(e=>e.kind===`facets`&&!kk(e,t)?[{id:e.field,label:e.field,options:[],searchable:e.search,...t?.fields[e.field]?.type===`relation`&&{combobox:!0}}]:e.kind===`flags`?[{id:e.fields.join(`|`),label:e.label,options:e.fields.map(e=>({value:e,label:e,count:0})),flags:!0}]:[]),ranges:n.flatMap(e=>e.kind!==`flags`&&kk(e,t)?[Ak(e.field)]:[]),...r&&{dateField:r.field,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}]:[])}},Mk=(e,t)=>(e?.filters??[]).some(e=>e.kind===`range`&&e.field===t&&e.histogram),Nk=(e,t)=>{let n=e?.fields[t],r=n?.suffix??``;return e=>`${n?.prefix===`€`?Of(e*100).replace(`.00`,``):String(e)}${r}`},Pk=24,Fk=({model:e,resources:t,views:n,view:r,state:i,extras:a})=>{let o=W(),s=pm(),c=jk(r,e),l=e=>r?.fields[e]?.label??G(e),u=n=>{let r=e.fields[n];return r?.type===`relation`&&r.relation?t[r.relation.resource]:void 0},d=c.facets.flatMap(e=>(e.flags?e.options.map(e=>e.value):[e.id]).map(t=>({group:e.id,field:t}))),f=Dh({queries:d.map(({group:t,field:r})=>{let s=hk(c,{...i,facets:{...i.facets,[t]:[]}},a),l=u(r),d=l?.primaryKey.length===1?Og(l,n[l.name]):void 0;return{queryKey:U.facets(e.name,r,s),queryFn:()=>o.facets(e.name,r,{filter:s,limit:50,...d&&{label:d}})}})}),p=(e,t)=>f[d.findIndex(n=>n.group===e&&n.field===t)]?.data,m=Dh({queries:c.facets.map(t=>{let r=u(t.id),a=wk((p(t.id,t.id)??[]).flatMap(e=>e.value===null?[]:[String(e.value)]),i.facets[t.id]??[]);return{queryKey:U.labels(`facet:${e.name}.${t.id}`,a.join(`,`)),enabled:!!r&&a.length>0,queryFn:async()=>[...await R_(s,o,r,a,n[r.name])]}})}),h=Ek(c.facets.map(e=>({id:e.id,target:e.combobox?u(e.id):void 0})),n),g=c.ranges??[],_=Dh({queries:g.map(t=>{let n=hk(c,EO(i,t.id,void 0),a),s=Mk(r,t.id)?Pk:1;return{queryKey:U.histogram(e.name,t.id,s,n),queryFn:()=>o.histogram(e.name,t.id,{filter:n,buckets:s})}})});return{facets:c.facets.map((t,n)=>{if(t.flags){let e=t.options.map(({value:e})=>({value:e,label:l(e),count:p(t.id,e)?.find(e=>String(e.value)===`true`)?.count??0}));return{...t,options:e}}let i=e.fields[t.id],a=(p(t.id,t.id)??[]).flatMap(e=>e.label===void 0?[]:[[String(e.value),e.label]]),o=new Map([...a,...m[n]?.data??[]]),s=(p(t.id,t.id)??[]).flatMap(e=>e.value===null?[]:[{value:String(e.value),label:i?.type===`enum`?Bo(String(e.value),r?.fields[t.id]?.valueLabels):o.get(String(e.value))??String(e.value),count:e.count}]),c=h[n];return{...t,label:l(t.id),options:c.matches?Ck(c.matches,s):s,...o.size>0&&{labels:Object.fromEntries(o)},...c.onSearch&&{onSearch:c.onSearch}}}),ranges:g.flatMap((e,t)=>{let n=_[t]?.data;return!n||n.min===null||n.max===null?[]:[{...e,label:l(e.id),min:Math.floor(n.min),max:Math.ceil(n.max),step:Math.max(1,Math.round((n.max-n.min)/100)),histogram:Mk(r,e.id)?n.buckets.map(e=>e.count):[],format:Nk(r,e.id)}]}),...c.dateField&&{datePresets:c.datePresets??!0,dateField:c.dateField,dateKind:c.dateKind},toggles:c.toggles?.map(e=>({...e,label:l(e.id)}))}},Ik=5e3,Lk=({queryClient:e,client:t,resources:n,views:r,model:i,columns:a,filter:o,orderBy:s})=>{let c=e=>U.page(i.name,o,s,40,e),l=B_(n,r,i,a),u=cv(r[i.name]),d=async e=>e.nextPageToken===``?e.items.length:e.totalSizeEstimate>Ik?e.totalSizeEstimate:(await t.list(i.name,{filter:o,orderBy:s,pageSize:1,count:`exact`})).totalSize??e.totalSizeEstimate,f=async t=>{if(t===0)return``;let n=c(t-1),r=e.getQueryData(n);if(r)return r.nextPageToken;if(e.getQueryState(n)?.fetchStatus===`fetching`)return(await m(t-1)).nextPageToken},p=async e=>{let r=await f(e);if(e>0&&r===``)return{rows:[],total:0,nextPageToken:``};let c={filter:o,orderBy:s,pageSize:40,labels:l,photos:u},p=r===void 0?await t.seek(i.name,{...c,position:e*40}):await t.list(i.name,{...c,pageToken:r});if(p.items.length===0&&e>0)return{rows:[],total:0,nextPageToken:``};let m=p.items.map(e=>jg(i,e));return{rows:V_(n,i,a,lv(i,p.items,p.photos),p.labels).map((e,t)=>({...e,id:m[t]})),total:e===0?await d(p):p.totalSizeEstimate,nextPageToken:p.nextPageToken}},m=t=>e.fetchQuery({queryKey:c(t),staleTime:6e4,queryFn:()=>p(t)});return{page:m,loadRows:async e=>(await m(Math.floor(e/40))).rows}},Rk=({resources:e,views:t,model:n,columns:r,filter:i,orderBy:a})=>{let s=W(),c=pm(),l=r.join(`,`),u=(0,o.useMemo)(()=>Lk({queryClient:c,client:s,resources:e,views:t,model:n,columns:r,filter:i,orderBy:a}),[c,s,e,t,n,l,i,a]),d=kh({queryKey:[...U.first(n.name,i,a),l],queryFn:()=>u.page(0)});return{source:(0,o.useMemo)(()=>d.data?{total:d.data.total,loadRows:u.loadRows}:void 0,[d.data,u]),error:d.error,isLoading:d.isLoading,page:u.page,key:[...U.first(n.name,i,a),l]}},zk=({title:e,open:t,onClose:n,children:r})=>{let i=(0,o.useRef)(null);return $u(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 shadow-pop outline-none`,children:[(0,B.jsxs)(`header`,{className:`flex shrink-0 items-center justify-between border-b px-4`,children:[(0,B.jsx)(`h2`,{className:`text-[15px] font-semibold`,children:e}),(0,B.jsx)(`button`,{type:`button`,"aria-label":`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)(Nn,{className:`size-5`})})]}),(0,B.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overscroll-contain px-4 pb-6`,children:r})]})]}):null},Bk=({title:e,noun:t,busy:n,onConfirm:r,onCancel:i})=>(0,B.jsx)(Kf,{title:`Delete ${e}?`,description:`This ${t.toLowerCase()} will be removed. This cannot be undone.`,onClose:i,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(H,{onClick:i,children:`Cancel`}),(0,B.jsx)(H,{variant:`primary`,className:`bg-danger hover:bg-danger/90`,loading:n,onClick:r,children:`Delete`})]})}),Vk=({title:e,changes:t,busy:n,onReview:r,onDeleteAnyway:i,onCancel:a})=>(0,B.jsx)(Kf,{title:`${e} was changed since you opened it`,description:`Someone saved this record in the meantime. Review what changed before you delete it.`,onClose:a,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(H,{onClick:r,children:`Review changes`}),(0,B.jsx)(H,{variant:`primary`,className:`bg-danger hover:bg-danger/90`,loading:n,onClick:i,children:`Delete anyway`})]}),children:t.length===0?(0,B.jsx)(`p`,{className:`text-[13px] text-muted-foreground`,children:`No visible fields differ; the record was saved again with the same values.`}):(0,B.jsx)(`ul`,{className:`divide-y rounded-md border text-[13px]`,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))})}),Hk=e=>{if(e.stage===`confirm`)return(0,B.jsx)(Kf,{title:`Delete ${e.count} ${e.count===1?e.plural.replace(/s$/,``):e.plural.toLowerCase()}?`,description:`This cannot be undone. Each record is deleted only if it has not changed since the list loaded; anything that changed is reported and kept.`,onClose:e.onCancel,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(H,{onClick:e.onCancel,children:`Cancel`}),(0,B.jsxs)(H,{variant:`primary`,className:`bg-danger hover:bg-danger/90`,onClick:e.onConfirm,children:[`Delete `,e.count]})]})});if(e.stage===`running`)return(0,B.jsx)(Kf,{title:`Deleting`,description:`${e.done} of ${e.total} done`,onClose:()=>void 0,actions:(0,B.jsx)(H,{loading:!0,disabled:!0,children:`Working`})});let t=e.total-e.failures.length;return(0,B.jsx)(Kf,{title:e.failures.length===0?`Deleted ${t}`:`Deleted ${t} of ${e.total}`,description:e.failures.length===0?void 0:`${e.failures.length} could not be deleted and were kept.`,onClose:e.onClose,actions:(0,B.jsx)(H,{variant:`primary`,onClick:e.onClose,children:`Done`}),children:e.failures.length>0&&(0,B.jsx)(`ul`,{className:`max-h-48 divide-y overflow-y-auto rounded-md border text-[13px]`,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))})})},Uk=new Set([`updated_at`,`updatedAt`]),Wk=(e,t,n,r)=>Object.values(e.fields).flatMap(e=>{if(Uk.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??G(e.name),before:ov(e,n[e.name],i),after:ov(e,r[e.name],i)}]}),Gk=4,Kk=({model:e,view:t,onDeleted:n,onReview:r,restore:i})=>{let a=W(),s=pm(),c=Kg(),[l,u]=(0,o.useState)(),[d,f]=(0,o.useState)(!1),p=t?.names?.singular??G(e.name),m=t?.names?.plural??G(e.name),h=()=>{for(let t of[`page`,`list`,`first-page`,`map`])s.invalidateQueries({queryKey:[t,e.name]});for(let t of[`facets`,`series`,`histogram`])s.invalidateQueries({queryKey:[t,e.name]})},g=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 _s))throw e;return e}},_=t=>{h(),u(void 0),n?.(t),c.show({state:`success`,title:`${t.title} deleted`,...e.softDelete&&i&&{action:{label:`Undo`,onClick:()=>{i(t).then(()=>{h(),c.show({state:`success`,title:`${t.title} restored`})},e=>{if(!vs(e))throw e;h(),c.show({state:e.status===409?`success`:`error`,title:e.status===409?`${t.title} is already back`:`Could not restore ${t.title}`,description:e.status===409?void 0:e.message})})}}}})},v=async(n,r)=>{f(!0);try{if(!await g(n,r))return _(n);let i=(await a.get(e.name,n.key)).record;u({kind:`conflict`,target:n,fresh:i,changes:Wk(e,t,n.snapshot,i)})}catch(e){if(!vs(e))throw e;u(void 0),c.show({state:`error`,title:`Could not delete ${n.title}`,description:e.message})}finally{f(!1)}},y=async e=>{try{return await g(e,e.etag)?{title:e.title,message:`Changed since the list loaded, so it was kept.`}:void 0}catch(t){if(!vs(t))throw t;return{title:e.title,message:t.message}}},b=async e=>{let t=[],n=0;u({kind:`bulk-running`,done:n,total:e.length});let r=[...e];await Promise.all(Array.from({length:Math.min(Gk,e.length)},async()=>{for(let i=r.shift();i;i=r.shift()){let r=await y(i);r&&t.push(r),n+=1,u({kind:`bulk-running`,done:n,total:e.length})}})),h(),u({kind:`bulk-done`,total:e.length,failures:t})},x=()=>u(void 0);return{dialogs:l&&(0,B.jsxs)(B.Fragment,{children:[l.kind===`confirm`&&(0,B.jsx)(Bk,{title:l.target.title,noun:p,busy:d,onCancel:x,onConfirm:()=>void v(l.target,l.target.etag)}),l.kind===`conflict`&&(0,B.jsx)(Vk,{title:l.target.title,changes:l.changes,busy:d,onCancel:x,onReview:()=>{x(),r?.(l.target,l.fresh)},onDeleteAnyway:()=>void v(l.target,`*`)}),l.kind===`bulk-confirm`&&(0,B.jsx)(Hk,{stage:`confirm`,count:l.targets.length,plural:m,onCancel:x,onConfirm:()=>void b(l.targets)}),l.kind===`bulk-running`&&(0,B.jsx)(Hk,{stage:`running`,done:l.done,total:l.total}),l.kind===`bulk-done`&&(0,B.jsx)(Hk,{stage:`done`,total:l.total,failures:l.failures,onClose:x})]}),start:t=>e.softDelete?v(t,t.etag):u({kind:`confirm`,target:t}),startBulk:e=>u({kind:`bulk-confirm`,targets:e})}},qk=e=>{let t=W();return e.softDelete?async n=>void await t.undelete(e.name,n.key):void 0},Jk={wallet:cee,"file-text":Xe,send:oee,ruler:Gt,bed:O,heart:$e,bell:A,bookmark:re,"external-link":Ue},Yk=e=>e!==void 0&&Object.hasOwn(Jk,e)?Jk[e]:void 0,Xk=({title:e,description:t,open:n,onClose:r,actions:i,children:a,wide:o})=>{let s=Gu();return n?s?(0,B.jsx)(Kf,{title:e,description:t,onClose:r,actions:i,wide:o,children:a}):(0,B.jsx)(zk,{title:e,open:!0,onClose:r,children:(0,B.jsxs)(`div`,{className:`pt-3 text-[13px]`,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},Zk=({benefits:e})=>e&&e.length>0?(0,B.jsx)(`ul`,{className:`flex flex-col gap-2 text-left text-[13px]`,children:e.map(e=>(0,B.jsxs)(`li`,{className:`flex items-start gap-2`,children:[(0,B.jsx)(de,{className:`mt-0.5 size-4 shrink-0 text-primary`,"aria-hidden":!0}),e]},e))}):null,Qk=({prompt:e})=>{let{canSignUp:t}=V(),{link:n}=$h(),r=Gf({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)(ld,{to:n(`sign-up`),className:r,children:`Create an account`});return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(ld,{to:n(),className:i?Gf():r,children:`Sign in`}),i]})},$k=e=>{let{prompt:t}=e,n=(0,o.useId)();if(e.as===`dialog`)return(0,B.jsx)(Xk,{title:t.title,description:t.description,open:e.open,onClose:e.onClose,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(H,{onClick:e.onClose,children:`Not now`}),(0,B.jsx)(Qk,{prompt:t})]}),children:(0,B.jsx)(Zk,{benefits:t.benefits})});let r=Yk(t.icon)??_t;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-[13px] text-muted-foreground`,children:t.description})]}),(0,B.jsx)(Zk,{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)(Qk,{prompt:t})})]})},eA=(e,t)=>({model:e,record:t,key:mo(Mg(e,t)),etag:typeof t.etag==`string`?t.etag:void 0,permissions:t.permissions}),tA=(e,t,n=``)=>({queryKey:U.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}}),nA=(e,t=``)=>kh(tA(W(),e,t)),rA=(e,{filter:t=``,sort:n=``,key:r})=>{let i=W();return kh({queryKey:r===void 0?U.firstRecord(e.name,t,n):U.record(e.name,r),queryFn:async()=>{if(r!==void 0){let t=await i.get(e.name,r);return{...eA(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]?eA(e,a.items[0]):null}})},iA=(e,{filter:t=``,sort:n=``,pageSize:r,pageToken:i=``})=>{let a=W();return kh({queryKey:U.list(e.name,t,n,r,i),placeholderData:Lm,queryFn:()=>a.list(e.name,{filter:t||void 0,orderBy:n||void 0,pageSize:r,pageToken:i||void 0})})},aA=()=>{let e=pm();return(0,o.useCallback)(t=>e.invalidateQueries({predicate:e=>e.queryKey[1]===t}),[e])},oA=so(),sA=e=>{if(typeof e==`string`||typeof e==`number`)return e;if(e&&typeof e==`object`&&`id`in e)return sA(e.id)},cA=(e,t,n)=>n.flatMap(n=>{let r=sA(n[t]);return r===void 0?[]:[{key:mo(Mg(e,n)),target:r}]}),lA=(e,t)=>e.find(e=>mo(e.target)===t),uA=(e,t)=>[...e,{key:``,target:t}],dA=(e,t)=>e.filter(e=>mo(e.target)!==t),fA=(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:oA.in(n,r)},pA=(e,t)=>U.list(e,``,``,500,`saved:${t}`),mA=(e,t,n)=>{let r=W(),i=K().resources[e];return kh({queryKey:pA(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 cA(i,t,n)}})},hA=e=>e instanceof Error?e.message:`Something went wrong`,gA=(e,t,n)=>{let r=K(),i=W(),a=pm(),o=Kg(),s=aA(),{resource:c,field:l}=e,u=r.permissions[c],d=r.resources[c]!==void 0&&u!==void 0&&Ey(u,`create`)&&Ey(u,`delete`),f=r.signIn?.[c]?.signIn,p=mA(c,l,d),m=p.data&&lA(p.data,t),h=pA(c,l),g=Ah({mutationFn:async e=>{e?await i.remove(c,e.key):await i.create(c,{[l]:n})},onMutate:async e=>{await a.cancelQueries({queryKey:h,exact:!0});let r=a.getQueryData(h);return a.setQueryData(h,(r=[])=>e?dA(r,t):uA(r,n)),{before:r}},onError:(e,t,n)=>{a.setQueryData(h,n?.before),o.show({state:`error`,title:t?`Could not take it off`:`Could not save it`,description:hA(e)})},onSettled:()=>s(c)});return{mode:d?`save`:f?`sign-in`:void 0,prompt:f,saved:m!==void 0,ready:p.data!==void 0&&!g.isPending,toggle:()=>g.mutate(m)}},_A=({favorite:e,recordKey:t,target:n,className:r})=>{let i=gA(e,t,n),[a,s]=(0,o.useState)(!1);if(!i.mode)return null;let c=e.label??`Favorite`,l=z(`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":c,"aria-haspopup":`dialog`,className:l,onClick:()=>s(!0),children:(0,B.jsx)($e,{className:`size-4`,"aria-hidden":!0})}),(0,B.jsx)($k,{as:`dialog`,prompt:i.prompt,open:a,onClose:()=>s(!1)})]}):(0,B.jsx)(`button`,{type:`button`,"aria-label":c,"aria-pressed":i.saved,"aria-disabled":!i.ready,className:l,onClick:()=>i.ready&&i.toggle(),children:(0,B.jsx)($e,{className:z(`size-4`,i.saved&&`fill-current text-danger`),"aria-hidden":!0})})},vA=({value:e,hints:t,children:n})=>(0,B.jsx)(Cd,{tone:YO(String(e)),color:vD(t?.valueColors,e),shape:t?.badgeShape,children:n}),yA=({value:e})=>{let t=tv(e,{width:320,height:240});return t?(0,B.jsx)(py,{image:t,loading:`lazy`,className:`size-full object-cover`}):null},bA=({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}),xA=({value:e})=>(0,B.jsx)(bA,{children:(0,B.jsx)(yA,{value:e})}),SA=10,CA=(e,t)=>{let n=G_(e)?e.uri:void 0,r=t.filter(e=>G_(e)&&e.uri!==n);return(n===void 0?r:[e,...r]).slice(0,SA)},wA=(e,t)=>t===0?0:(e%t+t)%t,TA=(e,t,n)=>t<=0||n===0?0:Math.min(n-1,Math.max(0,Math.round(e/t))),EA=`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-has-[[data-card-photos]:hover]/card:opacity-100 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`,DA=`[@media(hover:none)]:opacity-100`,OA=({photos:e,cover:t,swipe:n=!0,children:r})=>{let i=(0,o.useRef)(null),a=(0,o.useRef)(void 0),[s,c]=(0,o.useState)(0),l=CA(t,e),u=e=>{let t=i.current;t&&t.scrollTo({left:e*t.clientWidth})},d=e=>{a.current=wA((a.current??s)+e,l.length),u(a.current)},f=()=>{a.current=void 0},p=e=>{c(TA(e.scrollLeft,e.clientWidth,l.length)),a.current!==void 0&&Math.abs(e.scrollLeft-a.current*e.clientWidth)<1&&(a.current=void 0)},m=(0,B.jsx)(bA,{children:(0,B.jsx)(`span`,{ref:i,tabIndex:-1,"data-card-photos":!0,onPointerDown:f,onScroll:e=>p(e.currentTarget),className:z(`flex size-full snap-x snap-mandatory outline-none [scrollbar-width:none] motion-safe:scroll-smooth [&::-webkit-scrollbar]:hidden`,n?`overflow-x-auto overscroll-x-contain`:`overflow-x-hidden`),children:l.map((e,t)=>(0,B.jsx)(`span`,{className:`block size-full shrink-0 snap-start snap-always`,children:(0,B.jsx)(yA,{value:e})},t))})});return(0,B.jsxs)(B.Fragment,{children:[r(m),l.length>1&&(0,B.jsxs)(`div`,{className:`group/arrows pointer-events-none absolute inset-x-px top-px aspect-[4/3]`,children:[(0,B.jsx)(`button`,{type:`button`,"aria-label":`Previous photo`,className:z(EA,!n&&DA,`left-2`),onClick:()=>d(-1),children:(0,B.jsx)(he,{className:`size-4`,"aria-hidden":!0})}),(0,B.jsx)(`button`,{type:`button`,"aria-label":`Next photo`,className:z(EA,!n&&DA,`right-2`),onClick:()=>d(1),children:(0,B.jsx)(_e,{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:`Photo ${s+1} of ${l.length}`}),(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:l.map((e,t)=>(0,B.jsx)(`span`,{className:z(`size-1.5 rounded-full`,t===s?`bg-foreground`:`bg-foreground/35`)},t))})]})]})]})},kA=({icon:e,children:t})=>{let n=Yk(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]})},AA=({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}=hv(e,t,n),m=e=>t?.fields[e]?.label??G(e),h=n=>{let i=e.fields[n];return i?r.labels[n]??ov(i,r.record[n],t?.fields[n]):``},{fields:g,components:_}=w_(),v=n.card===void 0?void 0:_?.[n.card],y=n=>{let i=e.fields[n],a=i&&_y(g,i,t?.fields[n]);return a?(0,B.jsx)(Sy,{shown:a,part:`display`,field:i,value:r.record[n],fallback:h(n)}):h(n)},b=n=>{let i=e.fields[n],a=t?.fields[n],o=r.record[n];return!i||a?.format!==`badge`||_y(g,i,a)||o==null||o===``?y(n):(0,B.jsx)(vA,{value:o,hints:a,children:h(n)})},x=n=>{let i=e.fields[n];if(!i)return;if(r.labels[n]!==void 0||_y(g,i,t?.fields[n]))return(0,B.jsx)(`strong`,{className:`font-semibold text-foreground`,children:y(n)});let a=vv(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]})},S=v?void 0:n.photos,C=u===void 0?void 0:r.record[u],w=p.filter(e=>r.record[e]===!0),T=o===void 0?void 0:r.record[o],E=_v(r,l),D=gv(r,f),O=o!==void 0||S!==void 0,k=n.favorite,A=e=>(0,B.jsxs)(B.Fragment,{children:[O&&e,(0,B.jsxs)(`span`,{className:`flex items-start justify-between gap-2 ${k&&!O?`pr-8`:``}`,children:[(0,B.jsx)(`span`,{className:`min-w-0 truncate font-medium`,children:y(s)}),u!==void 0&&C!=null&&(0,B.jsx)(vA,{value:C,hints:t?.fields[u],children:h(u)})]}),c!==void 0&&(0,B.jsx)(`span`,{className:t?.fields[c]?.multiline?`line-clamp-3 whitespace-pre-line break-words text-muted-foreground`:`truncate text-muted-foreground`,children:y(c)}),E!==void 0&&(0,B.jsx)(`span`,{className:`truncate tabular-nums text-muted-foreground`,children:x(E)}),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:gv(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)(kA,{icon:t?.fields[e]?.icon,children:b(e)})]},e))}),w.length>0&&(0,B.jsx)(`ul`,{className:`flex flex-wrap gap-1`,"aria-label":`Features`,children:w.map(e=>(0,B.jsx)(`li`,{children:(0,B.jsx)(Cd,{dot:!1,children:m(e)})},e))}),D.length>0&&(0,B.jsx)(`span`,{className:`truncate text-xs text-muted-foreground ${d.length>0?``:`mt-auto`}`,children:D.map((e,t)=>(0,B.jsxs)(`span`,{children:[t>0&&(0,B.jsx)(`span`,{"aria-hidden":!0,children:` • `}),y(e)]},e))})]}),j=t=>(0,B.jsxs)(Gv,{to:{kind:`record`,resource:e.name,key:r.key},className:`flex h-full flex-col gap-1.5 rounded-lg border border-border bg-background p-3 text-[13px] hover:border-border-strong hover:bg-surface focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/30`,children:[a&&!O&&(0,B.jsx)(Cd,{tone:`blue`,className:`self-start`,children:a}),v?(0,B.jsx)(by,{name:n.card,fallback:A(t),children:(0,B.jsx)(v,{row:r})}):A(t)]});return(0,B.jsxs)(`div`,{className:S?`group/card relative h-full`:k||a?`relative h-full`:`h-full`,children:[S?(0,B.jsx)(OA,{photos:r.photos??[],cover:T,swipe:i,children:j},r.key):j((0,B.jsx)(xA,{value:T})),a&&O&&(0,B.jsx)(Cd,{tone:`blue`,className:`pointer-events-none absolute top-2 left-2 shadow-sm`,children:a}),k&&(0,B.jsx)(_A,{favorite:k,recordKey:r.key,target:Mg(e,r.record),className:O?void 0:`right-1.5 top-1.5`})]})},yne=(e,t)=>{},bne=({windowMs:e=1e3,comebacks:t=2,onHold:n=yne}={})=>{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}},xne=e=>Math.max(1,Math.floor((e+12)/252)),Sne=(e,t)=>Math.max(0,(e-(t-1)*12)/t),Cne=(e,t,n,r)=>({start:e*n,end:Math.max(0,Math.min(r,(t+1)*n)-1)}),wne=(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},Tne=8,Ene=(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<=Tne)break;i.delete(e)}return i},Dne=({source:e,label:t,initialIndex:n,onScrollIndex:r,minHeight:i,children:a})=>{let{total:s}=e,[c]=(0,o.useState)(n),[l,u]=(0,o.useState)(0),d=xne(l),f=Sne(l,d),[p,m]=(0,o.useState)(()=>new Map),h=Math.ceil(Math.max(i(f),p.get(f)??0)),g=h+12,_={columns:d,rowHeight:g},v=(0,o.useRef)({layout:_,top:0}),y=v.current.top>0&&(v.current.layout.columns!==d||v.current.layout.rowHeight!==g),b=e=>y?wne(v.current.top,v.current.layout,_):e,x=f>0&&p.has(f),S=hO({total:Math.ceil(s/d),rowHeight:g,initialIndex:Math.floor(c/d),settle:b,ready:x});(0,o.useLayoutEffect)(()=>{y&&S.scrollTo(S.top),v.current={layout:_,top:S.top},y||r(Math.floor(Math.max(0,S.top)/g)*d)});let C=Cne(S.first,S.last,d,s),w=tO({total:s,rowAt:e.rowAt,loadRows:e.loadRows,latencyMs:0},C.start,C.end),[T]=(0,o.useState)(()=>bne());(0,o.useLayoutEffect)(()=>{let e=S.ref.current;if(!e)return;let t=()=>u(T(e.clientWidth,performance.now())),n=new ResizeObserver(t);return n.observe(e),t(),()=>n.disconnect()},[T]);let E=(0,o.useRef)(f);E.current=f;let[D]=(0,o.useState)(()=>new ResizeObserver(e=>{let t=Math.max(...e.map(e=>e.borderBoxSize[0]?.blockSize??e.contentRect.height)),n=E.current;m(e=>Ene(e,n,t))}));(0,o.useLayoutEffect)(()=>()=>D.disconnect(),[D]);let O=(0,o.useCallback)(e=>{if(e)return D.observe(e),()=>D.unobserve(e)},[D]);return(0,B.jsx)(`ul`,{ref:S.ref,className:`relative min-w-0 flex-auto`,"aria-label":t,style:{height:S.geometry.contentHeight},children:S.rows.flatMap(({index:e,offset:t})=>Array.from({length:d},(n,r)=>{let i=e*d+r;if(i>=s)return[];let o=w(i),c={top:t,left:r*(f+12),width:f,minHeight:h};return o?(0,B.jsx)(`li`,{ref:O,"aria-posinset":i+1,"aria-setsize":s,className:`absolute grid grid-cols-[minmax(0,1fr)]`,style:c,children:a(o)},o.id):(0,B.jsx)(`li`,{"aria-hidden":!0,className:`absolute grid grid-cols-[minmax(0,1fr)]`,style:c,children:(0,B.jsx)(od,{className:`h-full rounded-lg`})},`skeleton-${i}`)}))})},One=`grid grid-cols-[repeat(auto-fill,minmax(15rem,1fr))] gap-3`,kne=e=>e*.75,Ane=44,jne=({model:e,view:t,display:n,list:r})=>{let i=t?.names?.plural??G(e.name),a=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 ${One}`,children:Array.from({length:6},(e,t)=>(0,B.jsx)(od,{className:`h-24`},t))}):r.error?(0,B.jsx)(ny,{title:`Could not load rows`,error:r.error}):!r.source||r.source.total===0?(0,B.jsxs)(`p`,{className:`py-8 text-center text-[13px] text-muted-foreground`,children:[`No `,i.toLowerCase(),` match.`]}):(0,B.jsx)(Dne,{source:r.source,label:i,initialIndex:r.initialIndex,onScrollIndex:r.onScrollIndex,minHeight:e=>(a?kne(e):0)+Ane,children:r=>(0,B.jsx)(AA,{model:e,view:t,display:n,row:wv(e,r)})})},jA=so(),Mne={bounds:{south:-90,west:-180,north:90,east:180},zoom:0},Nne=22,MA=e=>Math.floor(e*1e6)/1e6,NA=e=>Math.ceil(e*1e6)/1e6,PA=e=>((e+180)%360+360)%360-180,Pne=(e,t)=>{let n=[jA.gte(e.latitude,MA(Math.max(t.south,-90))),jA.lte(e.latitude,NA(Math.min(t.north,90)))];if(t.east-t.west>=360)return jA.and(...n);let r=jA.gte(e.longitude,MA(PA(t.west))),i=jA.lte(e.longitude,NA(PA(t.east)));return PA(t.west)<=PA(t.east)?jA.and(...n,r,i):jA.and(...n,jA.or(r,i))},Fne=(e,t,n)=>{let r=qa(Pne(t,n));return e.trim()===``?r:`(${e}) AND ${r}`},Ine=e=>Math.min(Math.max(Math.floor(e),0),Nne),Lne=(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))}},FA=e=>{if(typeof e==`number`)return e;if(typeof e==`string`&&e.trim()!==``)return Number(e)},IA=(e,t)=>{let n=FA(e[t.latitude]),r=FA(e[t.longitude]);if(n!==void 0&&r!==void 0&&Math.abs(n)<=90&&Math.abs(r)<=180)return{latitude:n,longitude:r}},Rne=6371008.8,LA=64,RA=(e,t)=>t.approximate===void 0?t.exact!==void 0&&e[t.exact]===!1:e[t.approximate]===!0,zA=(e,t)=>{let n=t/Rne,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%LA/LA*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]})]}},zne=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,BA=(e,t)=>Array.isArray(e)&&e.length>=t&&e.every(zne),VA=e=>Array.isArray(e)&&e.length>0&&e.every(e=>BA(e,4)),Bne=e=>Array.isArray(e)&&e.length>0&&e.every(e=>BA(e,2)),Vne=e=>{if(typeof e!=`string`)return e;try{return JSON.parse(e)}catch(e){if(e instanceof SyntaxError)return;throw e}},Hne=e=>{let t=Vne(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`&&VA(i)||r===`MultiPolygon`&&Array.isArray(i)&&i.length>0&&i.every(VA)||r===`LineString`&&BA(i,2)||r===`MultiLineString`&&Bne(i))return{type:r,coordinates:i}},Une=(e,t,n)=>{if(!RA(e,t))return;let r=t.area===void 0?void 0:Hne(e[t.area]);if(r)return r;let i=t.radius===void 0?void 0:FA(e[t.radius]);return i!==void 0&&Number.isFinite(i)&&i>0?zA(n,i):t.defaultRadius===void 0?void 0:zA(n,t.defaultRadius)},HA=(e,t)=>e.flatMap(e=>{let n=IA(e.record,t);if(!n)return[];if(!RA(e.record,t))return[{key:e.key,...n}];let r=Une(e.record,t,n);return[{key:e.key,...n,approximate:!0,...r&&{area:r}}]}),Wne=(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}))},Gne=(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)}},UA=(e,t)=>({keys:e.keys,index:((e.index+t)%e.keys.length+e.keys.length)%e.keys.length}),Kne=({model:e,display:t,fields:n,filter:r,orderBy:i,area:a})=>{let o=W(),{resources:s,views:c}=K(),l={latitude:t.latitude,longitude:t.longitude},u=a?Fne(r,l,a.bounds):``,d=a?Ine(a.zoom):0;return kh({queryKey:U.map(e.name,`${l.latitude},${l.longitude}`,d,u,i),enabled:a!==void 0,placeholderData:Lm,queryFn:async()=>{let t=await o.map(e.name,{...l,zoom:d,filter:u,orderBy:i,labels:B_(s,c,e,n),photos:cv(c[e.name])});return{rows:V_(s,e,n,lv(e,t.items,t.photos),t.labels).map(t=>wv(e,t)),buckets:t.buckets,total:t.totalSize}}})},qne=(0,o.lazy)(()=>g_(()=>import(`./records-map-2U_CQ4RG.js`).then(e=>({default:e.RecordsMap})),__vite__mapDeps([0,1,2,3,4,5,6]))),Jne=250,WA=`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`,GA=({model:e,view:t,display:n,filter:r,orderBy:i,fields:a,at:s,onMove:c,footer:l=!0,flush:u=!1})=>{let d=K().maps?.style,[f,p]=(0,o.useState)(),[m,h]=(0,o.useState)(),g=LO(m,Jne),[_,v]=(0,o.useState)(s===void 0),y=Kne({model:e,display:n,fields:a,filter:r,orderBy:i,area:_?Mne:g}),b=y.isPlaceholderData?void 0:y.data,x=y.data?.rows??[],S=y.data?.buckets??[],C=HA(x,n),w=_&&b?Lne(HA(b.rows,n),b.buckets):void 0,T=yv(t,n),E=(t?.names?.plural??G(e.name)).toLowerCase(),D=(t?.names?.singular??G(e.name)).toLowerCase(),O=Gne(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?t===1?`Show the ${D}, at an approximate position`:`Show the ${D}`:t===0?`Show ${e.length} ${E}`:t===e.length?`Show ${e.length} ${E}, at approximate positions`:`Show ${e.length} ${E}, ${t} at approximate positions`},M=e=>`Zoom in on ${e.toLocaleString(`en-IE`)} ${e===1?D:E}`,N=(0,o.useRef)(null),[ee,te]=(0,o.useState)(0);if((0,o.useLayoutEffect)(()=>te(N.current?.offsetHeight??0),[k?.key]),!d)return(0,B.jsx)(yy,{children:`The map display needs a map style: set PROTOBASE_MAP_STYLE_URL.`});let ne=b?.total===0;return(0,B.jsxs)(`div`,{className:z(`flex h-full min-h-[36rem] flex-1 flex-col sm:min-h-[28rem]`,u&&`max-md:-mx-5 max-md:-mb-4 max-md:min-h-0`),children:[(0,B.jsxs)(`div`,{className:z(`relative min-h-0 flex-1 overflow-hidden rounded-lg border border-border bg-muted`,u&&`max-md:rounded-none max-md:border-0`),children:[(0,B.jsx)(o.Suspense,{fallback:null,children:(0,B.jsx)(qne,{style:d,initial:s,points:C,buckets:S,fit:w,onFitted:()=>v(!1),onMove:(e,t)=>{h(e),c?.(t)},selected:O?.keys,covered:O?ee:0,onSelect:e=>p({keys:e,index:0}),onClear:()=>p(void 0),markerLabel:j,bucketLabel:M})}),y.error&&(0,B.jsx)(`div`,{className:`absolute inset-x-3 top-3 z-10`,children:(0,B.jsx)(ny,{title:`Could not load rows`,error:y.error})}),ne&&(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-[13px] text-muted-foreground shadow`,role:`status`,children:[_?`No ${E} match.`:`No ${E} in this part of the map.`,!_&&(0,B.jsx)(H,{size:`sm`,onClick:()=>v(!0),children:`Show all`})]})}),O&&k&&(0,B.jsx)(`div`,{ref:N,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":`Chosen ${D}`,children:[(0,B.jsxs)(`div`,{className:`flex items-center justify-end gap-1.5`,children:[A.has(k.key)&&(0,B.jsxs)(`span`,{className:`mr-auto flex items-center gap-1 rounded-full border border-border bg-background px-2 py-1 text-xs`,children:[(0,B.jsx)(Te,{className:`size-3.5`,"aria-hidden":!0}),`Approximate position`]}),O.keys.length>1&&(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`button`,{type:`button`,"aria-label":`Previous`,className:WA,onClick:()=>p(UA(O,-1)),children:(0,B.jsx)(he,{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":`Next`,className:WA,onClick:()=>p(UA(O,1)),children:(0,B.jsx)(_e,{className:`size-4`,"aria-hidden":!0})})]}),(0,B.jsx)(`button`,{type:`button`,"aria-label":`Close`,className:WA,onClick:()=>p(void 0),children:(0,B.jsx)(Nn,{className:`size-4`,"aria-hidden":!0})})]}),(0,B.jsx)(`div`,{className:`shadow-lg`,children:(0,B.jsx)(AA,{model:e,view:t,display:T,row:k})})]})})]}),l&&(0,B.jsx)(`p`,{className:`hidden py-3 text-xs text-muted-foreground md:block`,children:Yne(y.data,E)})]})},Yne=(e,t)=>{if(!e)return`\xA0`;let n=e.total.toLocaleString(`en-IE`);return e.buckets.length===0&&e.rows.length<e.total?`${e.rows.length.toLocaleString(`en-IE`)} of ${n} ${t} in view`:`${n} ${t} in view`},KA=(0,o.createContext)(void 0),Xne=({value:e,children:t})=>(0,B.jsx)(KA.Provider,{value:e,children:t}),Zne=()=>{let e=(0,o.useContext)(KA);if(!e)throw Error(`useListDisplay is used inside a list display, which the list page draws`);return e},Qne=()=>(0,o.useContext)(KA),qA=({display:e,list:t})=>{let{components:n}=w_(),r=n?.[e.component];return r?(0,B.jsx)(Xne,{value:t,children:(0,B.jsx)(`div`,{className:`min-w-0 flex-1 overflow-x-auto`,children:(0,B.jsx)(by,{name:e.component,children:(0,B.jsx)(r,{...co(e.props??{})})})})}):(0,B.jsxs)(yy,{children:[`No component is registered as `,e.component,`. Export it from protobase.ui.tsx, or load the plugin that provides it.`]})},$ne=(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}},ere=({value:e,options:t,onChange:n,label:r})=>{let[i,a]=(0,o.useState)(!1),s=(0,o.useRef)(null),c=(0,o.useRef)(null),l=(0,o.useRef)([]),u=t.findIndex(t=>t.value===e),d=t[u];(0,o.useEffect)(()=>{if(!i)return;l.current[Math.max(u,0)]?.focus();let e=e=>{e.target instanceof Node&&!s.current?.contains(e.target)&&a(!1)};return document.addEventListener(`pointerdown`,e),()=>document.removeEventListener(`pointerdown`,e)},[i]);let f=()=>{a(!1),c.current?.focus()};return(0,B.jsxs)(`div`,{ref:s,className:`relative shrink-0`,children:[(0,B.jsxs)(`button`,{ref:c,type:`button`,"aria-label":d?`${r}: ${d.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-[13px] font-medium shadow-sm transition-colors hover:bg-muted pointer-coarse:h-11`,children:[d?.icon&&(0,B.jsx)(d.icon,{className:`size-3.5`}),d?.label??r,(0,B.jsx)(pe,{className:`size-3.5 text-muted-foreground`})]}),i&&(0,B.jsx)(`ul`,{role:`menu`,"aria-label":r,onKeyDown:e=>{if(e.key===`Escape`)return f();if(e.key===`Tab`)return a(!1);let n=$ne(e.key,l.current.indexOf(document.activeElement),t.length);n!==void 0&&(e.preventDefault(),l.current[n]?.focus())},className:`absolute right-0 top-full z-30 mt-1 min-w-40 rounded-md border bg-background py-1 text-[13px] shadow-pop`,children:t.map((t,r)=>(0,B.jsx)(`li`,{role:`none`,children:(0,B.jsxs)(`button`,{ref:e=>{l.current[r]=e},type:`button`,role:`menuitemradio`,"aria-checked":t.value===e,onClick:()=>{f(),t.value!==e&&n(t.value)},className:z(`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)(de,{className:`size-3.5 text-primary-text`})]})},t.value))})]})},tre={table:hn,cards:at,kanban:ln,board:je,list:dt,calendar:ce,map:Ct},JA=({view:e,value:t,onChange:n,menu:r=!1})=>{let i=mv(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:tre[e.icon]}));return r?(0,B.jsx)(ere,{label:`Display`,value:t,onChange:n,options:a}):(0,B.jsx)(Ed,{label:`Display`,size:`md`,value:t,onChange:n,options:a})},nre=[[`asc`,`ascending`],[`desc`,`descending`]],YA=({model:e,view:t,display:n,orderBy:r,onChange:i,className:a})=>{let o=Ev(r),s=Sv(e,t,n),c=s.includes(o.columnId)?s:[o.columnId,...s],l=e=>t?.fields[e]?.label??G(e);return(0,B.jsx)(`select`,{"aria-label":`Sort`,value:`${o.columnId} ${o.direction}`,onChange:e=>i(e.target.value),className:z(`h-8 rounded-md border border-border-strong bg-background px-2.5 text-[13px] shadow-sm focus:border-primary focus:outline-none focus:ring-2 focus:ring-primary/20`,a),children:c.flatMap(e=>nre.map(([t,n])=>(0,B.jsxs)(`option`,{value:`${e} ${t}`,children:[l(e),`, `,n]},`${e} ${t}`)))})},rre=(e,t,n,r)=>{let i=jh({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=>wv(e,t))),total:a[0]?.total??0,loading:i.isPending,error:i.error,more:i.hasNextPage,loadMore:()=>void i.fetchNextPage()}},XA=new Map,ire=()=>{let{entry:e,path:t,params:n}=Rh(),r=`${t}?${n.toString()}`,i=XA.get(e),a=(0,o.useCallback)(t=>void XA.set(e,{url:r,index:t}),[e,r]);return{initialIndex:i?.url===r?i.index:0,remember:a}},are=(e,t,n,r=!0)=>{let i=W(),a=as(n)??``;return kh({queryKey:U.facets(e,t,a),enabled:r,queryFn:()=>i.facets(e,t,{filter:a,limit:50})})},ZA=(e,t,n=!0)=>{let r=W(),i=as(t.filter)??``;return kh({queryKey:U.series(e,t.field,`${t.range??``}${t.from??``}${t.to??``}`,t.granularity??``,i),enabled:n,queryFn:()=>r.series(e,{...t,filter:i})})},ore=(e,t,n,r=20,i=!0)=>{let a=W(),o=as(n)??``;return kh({queryKey:U.histogram(e,t,r,o),enabled:i,queryFn:()=>a.histogram(e,t,{filter:o,buckets:r})})};function QA(e){var t,n,r=``;if(typeof e==`string`||typeof e==`number`)r+=e;else if(typeof e==`object`){if(Array.isArray(e)){var i=e.length;for(t=0;t<i;t++)e[t]&&(n=QA(e[t]))&&(r&&(r+=` `),r+=n)}else for(n in e)e[n]&&(r&&(r+=` `),r+=n)}return r}function $A(){for(var e,t,n=0,r=``,i=arguments.length;n<i;n++)(e=arguments[n])&&(t=QA(e))&&(r&&(r+=` `),r+=t);return r}var sre=`dangerouslySetInnerHTML.onCopy.onCopyCapture.onCut.onCutCapture.onPaste.onPasteCapture.onCompositionEnd.onCompositionEndCapture.onCompositionStart.onCompositionStartCapture.onCompositionUpdate.onCompositionUpdateCapture.onFocus.onFocusCapture.onBlur.onBlurCapture.onChange.onChangeCapture.onBeforeInput.onBeforeInputCapture.onInput.onInputCapture.onReset.onResetCapture.onSubmit.onSubmitCapture.onInvalid.onInvalidCapture.onLoad.onLoadCapture.onError.onErrorCapture.onKeyDown.onKeyDownCapture.onKeyPress.onKeyPressCapture.onKeyUp.onKeyUpCapture.onAbort.onAbortCapture.onCanPlay.onCanPlayCapture.onCanPlayThrough.onCanPlayThroughCapture.onDurationChange.onDurationChangeCapture.onEmptied.onEmptiedCapture.onEncrypted.onEncryptedCapture.onEnded.onEndedCapture.onLoadedData.onLoadedDataCapture.onLoadedMetadata.onLoadedMetadataCapture.onLoadStart.onLoadStartCapture.onPause.onPauseCapture.onPlay.onPlayCapture.onPlaying.onPlayingCapture.onProgress.onProgressCapture.onRateChange.onRateChangeCapture.onSeeked.onSeekedCapture.onSeeking.onSeekingCapture.onStalled.onStalledCapture.onSuspend.onSuspendCapture.onTimeUpdate.onTimeUpdateCapture.onVolumeChange.onVolumeChangeCapture.onWaiting.onWaitingCapture.onAuxClick.onAuxClickCapture.onClick.onClickCapture.onContextMenu.onContextMenuCapture.onDoubleClick.onDoubleClickCapture.onDrag.onDragCapture.onDragEnd.onDragEndCapture.onDragEnter.onDragEnterCapture.onDragExit.onDragExitCapture.onDragLeave.onDragLeaveCapture.onDragOver.onDragOverCapture.onDragStart.onDragStartCapture.onDrop.onDropCapture.onMouseDown.onMouseDownCapture.onMouseEnter.onMouseLeave.onMouseMove.onMouseMoveCapture.onMouseOut.onMouseOutCapture.onMouseOver.onMouseOverCapture.onMouseUp.onMouseUpCapture.onSelect.onSelectCapture.onTouchCancel.onTouchCancelCapture.onTouchEnd.onTouchEndCapture.onTouchMove.onTouchMoveCapture.onTouchStart.onTouchStartCapture.onPointerDown.onPointerDownCapture.onPointerMove.onPointerMoveCapture.onPointerUp.onPointerUpCapture.onPointerCancel.onPointerCancelCapture.onPointerEnter.onPointerEnterCapture.onPointerLeave.onPointerLeaveCapture.onPointerOver.onPointerOverCapture.onPointerOut.onPointerOutCapture.onGotPointerCapture.onGotPointerCaptureCapture.onLostPointerCapture.onLostPointerCaptureCapture.onScroll.onScrollCapture.onWheel.onWheelCapture.onAnimationStart.onAnimationStartCapture.onAnimationEnd.onAnimationEndCapture.onAnimationIteration.onAnimationIterationCapture.onTransitionEnd.onTransitionEndCapture`.split(`.`);function ej(e){return typeof e==`string`&&sre.includes(e)}var cre=new Set(`aria-activedescendant.aria-atomic.aria-autocomplete.aria-busy.aria-checked.aria-colcount.aria-colindex.aria-colspan.aria-controls.aria-current.aria-describedby.aria-details.aria-disabled.aria-errormessage.aria-expanded.aria-flowto.aria-haspopup.aria-hidden.aria-invalid.aria-keyshortcuts.aria-label.aria-labelledby.aria-level.aria-live.aria-modal.aria-multiline.aria-multiselectable.aria-orientation.aria-owns.aria-placeholder.aria-posinset.aria-pressed.aria-readonly.aria-relevant.aria-required.aria-roledescription.aria-rowcount.aria-rowindex.aria-rowspan.aria-selected.aria-setsize.aria-sort.aria-valuemax.aria-valuemin.aria-valuenow.aria-valuetext.className.color.height.id.lang.max.media.method.min.name.style.target.width.role.tabIndex.accentHeight.accumulate.additive.alignmentBaseline.allowReorder.alphabetic.amplitude.arabicForm.ascent.attributeName.attributeType.autoReverse.azimuth.baseFrequency.baselineShift.baseProfile.bbox.begin.bias.by.calcMode.capHeight.clip.clipPath.clipPathUnits.clipRule.colorInterpolation.colorInterpolationFilters.colorProfile.colorRendering.contentScriptType.contentStyleType.cursor.cx.cy.d.decelerate.descent.diffuseConstant.direction.display.divisor.dominantBaseline.dur.dx.dy.edgeMode.elevation.enableBackground.end.exponent.externalResourcesRequired.fill.fillOpacity.fillRule.filter.filterRes.filterUnits.floodColor.floodOpacity.focusable.fontFamily.fontSize.fontSizeAdjust.fontStretch.fontStyle.fontVariant.fontWeight.format.from.fx.fy.g1.g2.glyphName.glyphOrientationHorizontal.glyphOrientationVertical.glyphRef.gradientTransform.gradientUnits.hanging.horizAdvX.horizOriginX.href.ideographic.imageRendering.in2.in.intercept.k1.k2.k3.k4.k.kernelMatrix.kernelUnitLength.kerning.keyPoints.keySplines.keyTimes.lengthAdjust.letterSpacing.lightingColor.limitingConeAngle.local.markerEnd.markerHeight.markerMid.markerStart.markerUnits.markerWidth.mask.maskContentUnits.maskUnits.mathematical.mode.numOctaves.offset.opacity.operator.order.orient.orientation.origin.overflow.overlinePosition.overlineThickness.paintOrder.panose1.pathLength.patternContentUnits.patternTransform.patternUnits.pointerEvents.pointsAtX.pointsAtY.pointsAtZ.preserveAlpha.preserveAspectRatio.primitiveUnits.r.radius.refX.refY.renderingIntent.repeatCount.repeatDur.requiredExtensions.requiredFeatures.restart.result.rotate.rx.ry.seed.shapeRendering.slope.spacing.specularConstant.specularExponent.speed.spreadMethod.startOffset.stdDeviation.stemh.stemv.stitchTiles.stopColor.stopOpacity.strikethroughPosition.strikethroughThickness.string.stroke.strokeDasharray.strokeDashoffset.strokeLinecap.strokeLinejoin.strokeMiterlimit.strokeOpacity.strokeWidth.surfaceScale.systemLanguage.tableValues.targetX.targetY.textAnchor.textDecoration.textLength.textRendering.to.transform.u1.u2.underlinePosition.underlineThickness.unicode.unicodeBidi.unicodeRange.unitsPerEm.vAlphabetic.values.vectorEffect.version.vertAdvY.vertOriginX.vertOriginY.vHanging.vIdeographic.viewTarget.visibility.vMathematical.widths.wordSpacing.writingMode.x1.x2.x.xChannelSelector.xHeight.xlinkActuate.xlinkArcrole.xlinkHref.xlinkRole.xlinkShow.xlinkTitle.xlinkType.xmlBase.xmlLang.xmlns.xmlnsXlink.xmlSpace.y1.y2.y.yChannelSelector.z.zoomAndPan.ref.key.angle`.split(`.`));function tj(e){return typeof e==`string`&&cre.has(e)}function nj(e){return typeof e==`string`&&e.startsWith(`data-`)}function rj(e){if(typeof e!=`object`||!e)return{};var t={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(tj(n)||nj(n))&&(t[n]=e[n]);return t}function ij(e){if(e==null)return null;if((0,o.isValidElement)(e)&&typeof e.props==`object`&&e.props!==null){var t=e.props;return rj(t)}return typeof e==`object`&&!Array.isArray(e)?rj(e):null}function aj(e){var t={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(tj(n)||nj(n)||ej(n))&&(t[n]=e[n]);return t}var lre=[`children`,`width`,`height`,`viewBox`,`className`,`style`,`title`,`desc`];function oj(){return oj=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},oj.apply(null,arguments)}function ure(e,t){if(e==null)return{};var n,r,i=dre(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function dre(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}var sj=(0,o.forwardRef)((e,t)=>{var n=e.children,r=e.width,i=e.height,a=e.viewBox,s=e.className,c=e.style,l=e.title,u=e.desc,d=ure(e,lre),f=a||{width:r,height:i,x:0,y:0},p=$A(`recharts-surface`,s);return o.createElement(`svg`,oj({},aj(d),{className:p,width:r,height:i,style:c,viewBox:`${f.x} ${f.y} ${f.width} ${f.height}`,ref:t}),o.createElement(`title`,null,l),o.createElement(`desc`,null,u),n)}),fre=[`children`,`className`];function cj(){return cj=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},cj.apply(null,arguments)}function pre(e,t){if(e==null)return{};var n,r,i=mre(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function mre(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}var lj=o.forwardRef((e,t)=>{var n=e.children,r=e.className,i=pre(e,fre),a=$A(`recharts-layer`,r);return o.createElement(`g`,cj({className:a},aj(i),{ref:t}),n)});function uj(e){return e===`__proto__`}var hre=/\.|(\[(?:[^[\]]*|(["'])(?:(?!\2)[^\\]|\\.)*?\2)\])/;function dj(e){switch(typeof e){case`number`:case`symbol`:return!1;case`string`:return e===``||e.startsWith(`.`)||e.endsWith(`.`)?!1:hre.test(e);default:return!1}}function fj(e){return typeof e==`string`||typeof e==`symbol`?e:Object.is(e?.valueOf?.(),-0)?`-0`:String(e)}function pj(e){return typeof e==`symbol`||e instanceof Symbol}function gre(e){return e==null?``:mj(e)}function mj(e){if(typeof e==`string`)return e;if(Array.isArray(e))return e.map(mj).join(`,`);if(pj(e))return e.toString();let t=e+``;return t===`0`&&Object.is(Number(e),-0)?`-0`:t}function hj(e){if(Array.isArray(e))return e.map(fj);if(typeof e==`symbol`)return[e];e=gre(e);let t=[],n=e.length;if(n===0)return t;let r=0,i=``,a=``,o=!1,s=!1,c=/^-?\d+(?:\.\d+)?$/;for(e.charCodeAt(0)===46&&t.push(``);r<n;){let l=e[r];if(a)l===`\\`&&r+1<n?(r++,i+=e[r]):l===a?a=``:i+=l;else if(o){if(l===`"`||l===`'`)a=l,s=!0;else if(l===`]`){if(o=!1,!s&&i.includes(`.`)&&!c.test(i)){let e=i.split(`.`);for(let n=0;n<e.length;n++)e[n]!==``&&t.push(e[n])}else t.push(i);i=``}else i+=l}else if(l===`[`)o=!0,s=!1,i&&=(t.push(i),``);else if(l===`.`){i&&=(t.push(i),``);let n=e[r+1];(n===void 0||n===`.`)&&t.push(``)}else i+=l;r++}return i&&t.push(i),t}function gj(e,t,n){if(e==null)return n;switch(typeof t){case`string`:{if(uj(t))return n;let r=e[t];return r===void 0?dj(t)&&!Object.hasOwn(e,t)?gj(e,hj(t),n):n:r}case`number`:case`symbol`:{typeof t==`number`&&(t=fj(t));let r=e[t];return r===void 0?n:r}default:{if(Array.isArray(t))return _re(e,t,n);if(t=Object.is(t?.valueOf(),-0)?`-0`:String(t),uj(t))return n;let r=e[t];return r===void 0?n:r}}}function _re(e,t,n){if(t.length===0)return n;let r=e;for(let e=0;e<t.length;e++){if(r==null||uj(t[e]))return n;r=r[t[e]]}return r===void 0?n:r}var vre=4;function _j(e){var t=10**(arguments.length>1&&arguments[1]!==void 0?arguments[1]:vre),n=Math.round(e*t)/t;return Object.is(n,-0)?0:n}function vj(e){var t=[...arguments].slice(1);return e.reduce((e,n,r)=>{var i=t[r-1];return typeof i==`string`?e+i+n:i===void 0?e+n:e+_j(i)+n},``)}var yj=e=>e===0?0:e>0?1:-1,bj=e=>typeof e==`number`&&e!=+e,xj=e=>typeof e==`string`&&e.length>1&&e.indexOf(`%`)===e.length-1,J=e=>(typeof e==`number`||e instanceof Number)&&!bj(e),Sj=e=>J(e)||typeof e==`string`,yre=0,Cj=e=>{var t=++yre;return`${e||``}${t}`},wj=function(e,t){var n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:0,r=arguments.length>3&&arguments[3]!==void 0&&arguments[3];if(!J(e)&&typeof e!=`string`)return n;var i;if(xj(e)){if(t==null)return n;var a=e.indexOf(`%`);i=t*parseFloat(e.slice(0,a))/100}else i=+e;return bj(i)&&(i=n),r&&t!=null&&i>t&&(i=t),i},Tj=e=>{if(!Array.isArray(e))return!1;for(var t=e.length,n={},r=0;r<t;r++)if(!n[String(e[r])])n[String(e[r])]=!0;else return!0;return!1};function Ej(e,t,n){return J(e)&&J(t)?_j(e+n*(t-e)):t}function bre(e,t,n){if(e&&e.length)return e.find(e=>e&&(typeof t==`function`?t(e):gj(e,t))===n)}var Dj=e=>e==null,Oj=e=>Dj(e)?e:`${e.charAt(0).toUpperCase()}${e.slice(1)}`;function kj(e){return e!=null}function Aj(){}function jj(e){if(e)return{x:e.x,y:e.y,upperWidth:`upperWidth`in e?e.upperWidth:e.width,lowerWidth:`lowerWidth`in e?e.lowerWidth:e.width,width:e.width,height:e.height}}function Mj(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function Nj(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?Mj(Object(n),!0).forEach(function(t){xre(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Mj(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function xre(e,t,n){return(t=Sre(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Sre(e){var t=Cre(e,`string`);return typeof t==`symbol`?t:t+``}function Cre(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}var wre=e=>{var t=e.viewBox,n=e.position,r=e.offset,i=r===void 0?0:r,a=e.parentViewBox,o=e.clamp,s=jj(t),c=s.x,l=s.y,u=s.height,d=s.upperWidth,f=s.lowerWidth,p=c,m=c+(d-f)/2,h=(p+m)/2,g=(d+f)/2,_=p+d/2,v=u>=0?1:-1,y=v*i,b=v>0?`end`:`start`,x=v>0?`start`:`end`,S=d>=0?1:-1,C=S*i,w=S>0?`end`:`start`,T=S>0?`start`:`end`,E=a;if(n===`top`){var D={x:p+d/2,y:l-y,horizontalAnchor:`middle`,verticalAnchor:b};return o&&E&&(D.height=Math.max(l-E.y,0),D.width=d),D}if(n===`bottom`){var O={x:m+f/2,y:l+u+y,horizontalAnchor:`middle`,verticalAnchor:x};return o&&E&&(O.height=Math.max(E.y+E.height-(l+u),0),O.width=f),O}if(n===`left`){var k={x:h-C,y:l+u/2,horizontalAnchor:w,verticalAnchor:`middle`};return o&&E&&(k.width=Math.max(k.x-E.x,0),k.height=u),k}if(n===`right`){var A={x:h+g+C,y:l+u/2,horizontalAnchor:T,verticalAnchor:`middle`};return o&&E&&(A.width=Math.max(E.x+E.width-A.x,0),A.height=u),A}var j=o&&E?{width:g,height:u}:{};return n===`insideLeft`?Nj({x:h+C,y:l+u/2,horizontalAnchor:T,verticalAnchor:`middle`},j):n===`insideRight`?Nj({x:h+g-C,y:l+u/2,horizontalAnchor:w,verticalAnchor:`middle`},j):n===`insideTop`?Nj({x:p+d/2,y:l+y,horizontalAnchor:`middle`,verticalAnchor:x},j):n===`insideBottom`?Nj({x:m+f/2,y:l+u-y,horizontalAnchor:`middle`,verticalAnchor:b},j):n===`insideTopLeft`?Nj({x:p+C,y:l+y,horizontalAnchor:T,verticalAnchor:x},j):n===`insideTopRight`?Nj({x:p+d-C,y:l+y,horizontalAnchor:w,verticalAnchor:x},j):n===`insideBottomLeft`?Nj({x:m+C,y:l+u-y,horizontalAnchor:T,verticalAnchor:b},j):n===`insideBottomRight`?Nj({x:m+f-C,y:l+u-y,horizontalAnchor:w,verticalAnchor:b},j):n&&typeof n==`object`&&(J(n.x)||xj(n.x))&&(J(n.y)||xj(n.y))?Nj({x:c+wj(n.x,g),y:l+wj(n.y,u),horizontalAnchor:`end`,verticalAnchor:`end`},j):Nj({x:_,y:l+u/2,horizontalAnchor:`middle`,verticalAnchor:`middle`},j)},Tre=[`top`,`left`,`right`,`bottom`];function Ere(e){return e==null?!1:typeof e==`object`||Tre.includes(e)}var Dre=(0,o.createContext)(null);function Pj(e){return function(){return e}}var Fj=Math.PI,Ij=2*Fj,Lj=1e-6,Ore=Ij-Lj;function Rj(e){this._+=e[0];for(let t=1,n=e.length;t<n;++t)this._+=arguments[t]+e[t]}function kre(e){let t=Math.floor(e);if(!(t>=0))throw Error(`invalid digits: ${e}`);if(t>15)return Rj;let n=10**t;return function(e){this._+=e[0];for(let t=1,r=e.length;t<r;++t)this._+=Math.round(arguments[t]*n)/n+e[t]}}var zj=class{constructor(e){this._x0=this._y0=this._x1=this._y1=null,this._=``,this._append=e==null?Rj:kre(e)}moveTo(e,t){this._append`M${this._x0=this._x1=+e},${this._y0=this._y1=+t}`}closePath(){this._x1!==null&&(this._x1=this._x0,this._y1=this._y0,this._append`Z`)}lineTo(e,t){this._append`L${this._x1=+e},${this._y1=+t}`}quadraticCurveTo(e,t,n,r){this._append`Q${+e},${+t},${this._x1=+n},${this._y1=+r}`}bezierCurveTo(e,t,n,r,i,a){this._append`C${+e},${+t},${+n},${+r},${this._x1=+i},${this._y1=+a}`}arcTo(e,t,n,r,i){if(e=+e,t=+t,n=+n,r=+r,i=+i,i<0)throw Error(`negative radius: ${i}`);let a=this._x1,o=this._y1,s=n-e,c=r-t,l=a-e,u=o-t,d=l*l+u*u;if(this._x1===null)this._append`M${this._x1=e},${this._y1=t}`;else if(d>Lj){if(!(Math.abs(u*s-c*l)>Lj)||!i)this._append`L${this._x1=e},${this._y1=t}`;else{let f=n-a,p=r-o,m=s*s+c*c,h=f*f+p*p,g=Math.sqrt(m),_=Math.sqrt(d),v=i*Math.tan((Fj-Math.acos((m+d-h)/(2*g*_)))/2),y=v/_,b=v/g;Math.abs(y-1)>Lj&&this._append`L${e+y*l},${t+y*u}`,this._append`A${i},${i},0,0,${+(u*f>l*p)},${this._x1=e+b*s},${this._y1=t+b*c}`}}}arc(e,t,n,r,i,a){if(e=+e,t=+t,n=+n,a=!!a,n<0)throw Error(`negative radius: ${n}`);let o=n*Math.cos(r),s=n*Math.sin(r),c=e+o,l=t+s,u=1^a,d=a?r-i:i-r;this._x1===null?this._append`M${c},${l}`:(Math.abs(this._x1-c)>Lj||Math.abs(this._y1-l)>Lj)&&this._append`L${c},${l}`,n&&(d<0&&(d=d%Ij+Ij),d>Ore?this._append`A${n},${n},0,1,${u},${e-o},${t-s}A${n},${n},0,1,${u},${this._x1=c},${this._y1=l}`:d>Lj&&this._append`A${n},${n},0,${+(d>=Fj)},${u},${this._x1=e+n*Math.cos(i)},${this._y1=t+n*Math.sin(i)}`)}rect(e,t,n,r){this._append`M${this._x0=this._x1=+e},${this._y0=this._y1=+t}h${n=+n}v${+r}h${-n}Z`}toString(){return this._}};zj.prototype;function Bj(e){let t=3;return e.digits=function(n){if(!arguments.length)return t;if(n==null)t=null;else{let e=Math.floor(n);if(!(e>=0))throw RangeError(`invalid digits: ${n}`);t=e}return e},()=>new zj(t)}Array.prototype.slice;function Vj(e){return typeof e==`object`&&`length`in e?e:Array.from(e)}function Hj(e){this._context=e}Hj.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;default:this._context.lineTo(e,t)}}};function Uj(e){return new Hj(e)}function Wj(e){return e[0]}function Gj(e){return e[1]}function Kj(e,t){var n=Pj(!0),r=null,i=Uj,a=null,o=Bj(s);e=typeof e==`function`?e:e===void 0?Wj:Pj(e),t=typeof t==`function`?t:t===void 0?Gj:Pj(t);function s(s){var c,l=(s=Vj(s)).length,u,d=!1,f;for(r??(a=i(f=o())),c=0;c<=l;++c)!(c<l&&n(u=s[c],c,s))===d&&((d=!d)?a.lineStart():a.lineEnd()),d&&a.point(+e(u,c,s),+t(u,c,s));if(f)return a=null,f+``||null}return s.x=function(t){return arguments.length?(e=typeof t==`function`?t:Pj(+t),s):e},s.y=function(e){return arguments.length?(t=typeof e==`function`?e:Pj(+e),s):t},s.defined=function(e){return arguments.length?(n=typeof e==`function`?e:Pj(!!e),s):n},s.curve=function(e){return arguments.length?(i=e,r!=null&&(a=i(r)),s):i},s.context=function(e){return arguments.length?(e==null?r=a=null:a=i(r=e),s):r},s}function qj(e,t,n){var r=null,i=Pj(!0),a=null,o=Uj,s=null,c=Bj(l);e=typeof e==`function`?e:e===void 0?Wj:Pj(+e),t=typeof t==`function`?t:Pj(t===void 0?0:+t),n=typeof n==`function`?n:n===void 0?Gj:Pj(+n);function l(l){var u,d,f,p=(l=Vj(l)).length,m,h=!1,g,_=Array(p),v=Array(p);for(a??(s=o(g=c())),u=0;u<=p;++u){if(!(u<p&&i(m=l[u],u,l))===h){if(h=!h)d=u,s.areaStart(),s.lineStart();else{for(s.lineEnd(),s.lineStart(),f=u-1;f>=d;--f)s.point(_[f],v[f]);s.lineEnd(),s.areaEnd()}}h&&(_[u]=+e(m,u,l),v[u]=+t(m,u,l),s.point(r?+r(m,u,l):_[u],n?+n(m,u,l):v[u]))}if(g)return s=null,g+``||null}function u(){return Kj().defined(i).curve(o).context(a)}return l.x=function(t){return arguments.length?(e=typeof t==`function`?t:Pj(+t),r=null,l):e},l.x0=function(t){return arguments.length?(e=typeof t==`function`?t:Pj(+t),l):e},l.x1=function(e){return arguments.length?(r=e==null?null:typeof e==`function`?e:Pj(+e),l):r},l.y=function(e){return arguments.length?(t=typeof e==`function`?e:Pj(+e),n=null,l):t},l.y0=function(e){return arguments.length?(t=typeof e==`function`?e:Pj(+e),l):t},l.y1=function(e){return arguments.length?(n=e==null?null:typeof e==`function`?e:Pj(+e),l):n},l.lineX0=l.lineY0=function(){return u().x(e).y(t)},l.lineY1=function(){return u().x(e).y(n)},l.lineX1=function(){return u().x(r).y(t)},l.defined=function(e){return arguments.length?(i=typeof e==`function`?e:Pj(!!e),l):i},l.curve=function(e){return arguments.length?(o=e,a!=null&&(s=o(a)),l):o},l.context=function(e){return arguments.length?(e==null?a=s=null:s=o(a=e),l):a},l}var Jj=class{constructor(e,t){this._context=e,this._x=t}areaStart(){this._line=0}areaEnd(){this._line=NaN}lineStart(){this._point=0}lineEnd(){(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line}point(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;default:this._x?this._context.bezierCurveTo(this._x0=(this._x0+e)/2,this._y0,this._x0,t,e,t):this._context.bezierCurveTo(this._x0,this._y0=(this._y0+t)/2,e,this._y0,e,t)}this._x0=e,this._y0=t}};function Are(e){return new Jj(e,!0)}function jre(e){return new Jj(e,!1)}function Yj(){}function Xj(e,t,n){e._context.bezierCurveTo((2*e._x0+e._x1)/3,(2*e._y0+e._y1)/3,(e._x0+2*e._x1)/3,(e._y0+2*e._y1)/3,(e._x0+4*e._x1+t)/6,(e._y0+4*e._y1+n)/6)}function Zj(e){this._context=e}Zj.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=NaN,this._point=0},lineEnd:function(){switch(this._point){case 3:Xj(this,this._x1,this._y1);case 2:this._context.lineTo(this._x1,this._y1)}(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;break;case 2:this._point=3,this._context.lineTo((5*this._x0+this._x1)/6,(5*this._y0+this._y1)/6);default:Xj(this,e,t)}this._x0=this._x1,this._x1=e,this._y0=this._y1,this._y1=t}};function Mre(e){return new Zj(e)}function Qj(e){this._context=e}Qj.prototype={areaStart:Yj,areaEnd:Yj,lineStart:function(){this._x0=this._x1=this._x2=this._x3=this._x4=this._y0=this._y1=this._y2=this._y3=this._y4=NaN,this._point=0},lineEnd:function(){switch(this._point){case 1:this._context.moveTo(this._x2,this._y2),this._context.closePath();break;case 2:this._context.moveTo((this._x2+2*this._x3)/3,(this._y2+2*this._y3)/3),this._context.lineTo((this._x3+2*this._x2)/3,(this._y3+2*this._y2)/3),this._context.closePath();break;case 3:this.point(this._x2,this._y2),this.point(this._x3,this._y3),this.point(this._x4,this._y4)}},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1,this._x2=e,this._y2=t;break;case 1:this._point=2,this._x3=e,this._y3=t;break;case 2:this._point=3,this._x4=e,this._y4=t,this._context.moveTo((this._x0+4*this._x1+e)/6,(this._y0+4*this._y1+t)/6);break;default:Xj(this,e,t)}this._x0=this._x1,this._x1=e,this._y0=this._y1,this._y1=t}};function $j(e){return new Qj(e)}function eM(e){this._context=e}eM.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=NaN,this._point=0},lineEnd:function(){(this._line||this._line!==0&&this._point===3)&&this._context.closePath(),this._line=1-this._line},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1;break;case 1:this._point=2;break;case 2:this._point=3;var n=(this._x0+4*this._x1+e)/6,r=(this._y0+4*this._y1+t)/6;this._line?this._context.lineTo(n,r):this._context.moveTo(n,r);break;case 3:this._point=4;default:Xj(this,e,t)}this._x0=this._x1,this._x1=e,this._y0=this._y1,this._y1=t}};function tM(e){return new eM(e)}function nM(e){this._context=e}nM.prototype={areaStart:Yj,areaEnd:Yj,lineStart:function(){this._point=0},lineEnd:function(){this._point&&this._context.closePath()},point:function(e,t){e=+e,t=+t,this._point?this._context.lineTo(e,t):(this._point=1,this._context.moveTo(e,t))}};function rM(e){return new nM(e)}function iM(e){return e<0?-1:1}function aM(e,t,n){var r=e._x1-e._x0,i=t-e._x1,a=(e._y1-e._y0)/(r||i<0&&-0),o=(n-e._y1)/(i||r<0&&-0),s=(a*i+o*r)/(r+i);return(iM(a)+iM(o))*Math.min(Math.abs(a),Math.abs(o),.5*Math.abs(s))||0}function oM(e,t){var n=e._x1-e._x0;return n?(3*(e._y1-e._y0)/n-t)/2:t}function sM(e,t,n){var r=e._x0,i=e._y0,a=e._x1,o=e._y1,s=(a-r)/3;e._context.bezierCurveTo(r+s,i+s*t,a-s,o-s*n,a,o)}function cM(e){this._context=e}cM.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=this._t0=NaN,this._point=0},lineEnd:function(){switch(this._point){case 2:this._context.lineTo(this._x1,this._y1);break;case 3:sM(this,this._t0,oM(this,this._t0))}(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(e,t){var n=NaN;if(e=+e,t=+t,e!==this._x1||t!==this._y1){switch(this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;break;case 2:this._point=3,sM(this,oM(this,n=aM(this,e,t)),n);break;default:sM(this,this._t0,n=aM(this,e,t))}this._x0=this._x1,this._x1=e,this._y0=this._y1,this._y1=t,this._t0=n}}};function lM(e){this._context=new uM(e)}(lM.prototype=Object.create(cM.prototype)).point=function(e,t){cM.prototype.point.call(this,t,e)};function uM(e){this._context=e}uM.prototype={moveTo:function(e,t){this._context.moveTo(t,e)},closePath:function(){this._context.closePath()},lineTo:function(e,t){this._context.lineTo(t,e)},bezierCurveTo:function(e,t,n,r,i,a){this._context.bezierCurveTo(t,e,r,n,a,i)}};function dM(e){return new cM(e)}function fM(e){return new lM(e)}function pM(e){this._context=e}pM.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x=[],this._y=[]},lineEnd:function(){var e=this._x,t=this._y,n=e.length;if(n){if(this._line?this._context.lineTo(e[0],t[0]):this._context.moveTo(e[0],t[0]),n===2)this._context.lineTo(e[1],t[1]);else for(var r=mM(e),i=mM(t),a=0,o=1;o<n;++a,++o)this._context.bezierCurveTo(r[0][a],i[0][a],r[1][a],i[1][a],e[o],t[o])}(this._line||this._line!==0&&n===1)&&this._context.closePath(),this._line=1-this._line,this._x=this._y=null},point:function(e,t){this._x.push(+e),this._y.push(+t)}};function mM(e){var t,n=e.length-1,r,i=Array(n),a=Array(n),o=Array(n);for(i[0]=0,a[0]=2,o[0]=e[0]+2*e[1],t=1;t<n-1;++t)i[t]=1,a[t]=4,o[t]=4*e[t]+2*e[t+1];for(i[n-1]=2,a[n-1]=7,o[n-1]=8*e[n-1]+e[n],t=1;t<n;++t)r=i[t]/a[t-1],a[t]-=r,o[t]-=r*o[t-1];for(i[n-1]=o[n-1]/a[n-1],t=n-2;t>=0;--t)i[t]=(o[t]-i[t+1])/a[t];for(a[n-1]=(e[n]+i[n-1])/2,t=0;t<n-1;++t)a[t]=2*e[t+1]-i[t+1];return[i,a]}function hM(e){return new pM(e)}function gM(e,t){this._context=e,this._t=t}gM.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x=this._y=NaN,this._point=0},lineEnd:function(){0<this._t&&this._t<1&&this._point===2&&this._context.lineTo(this._x,this._y),(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line>=0&&(this._t=1-this._t,this._line=1-this._line)},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;default:if(this._t<=0)this._context.lineTo(this._x,t),this._context.lineTo(e,t);else{var n=this._x*(1-this._t)+e*this._t;this._context.lineTo(n,this._y),this._context.lineTo(n,t)}}this._x=e,this._y=t}};function _M(e){return new gM(e,.5)}function vM(e){return new gM(e,0)}function yM(e){return new gM(e,1)}function bM(e,t){if((o=e.length)>1)for(var n=1,r,i,a=e[t[0]],o,s=a.length;n<o;++n)for(i=a,a=e[t[n]],r=0;r<s;++r)a[r][1]+=a[r][0]=isNaN(i[r][1])?i[r][0]:i[r][1]}function xM(e){for(var t=e.length,n=Array(t);--t>=0;)n[t]=t;return n}function SM(e,t){return e[t]}function CM(e){let t=[];return t.key=e,t}function wM(){var e=Pj([]),t=xM,n=bM,r=SM;function i(i){var a=Array.from(e.apply(this,arguments),CM),o,s=a.length,c=-1,l;for(let e of i)for(o=0,++c;o<s;++o)(a[o][c]=[0,+r(e,a[o].key,c,i)]).data=e;for(o=0,l=Vj(t(a));o<s;++o)a[l[o]].index=o;return n(a,l),a}return i.keys=function(t){return arguments.length?(e=typeof t==`function`?t:Pj(Array.from(t)),i):e},i.value=function(e){return arguments.length?(r=typeof e==`function`?e:Pj(+e),i):r},i.order=function(e){return arguments.length?(t=e==null?xM:typeof e==`function`?e:Pj(Array.from(e)),i):t},i.offset=function(e){return arguments.length?(n=e??bM,i):n},i}function TM(e,t){if((r=e.length)>0){for(var n,r,i=0,a=e[0].length,o;i<a;++i){for(o=n=0;n<r;++n)o+=e[n][i][1]||0;if(o)for(n=0;n<r;++n)e[n][i][1]/=o}bM(e,t)}}function EM(e,t){if((i=e.length)>0){for(var n=0,r=e[t[0]],i,a=r.length;n<a;++n){for(var o=0,s=0;o<i;++o)s+=e[o][n][1]||0;r[n][1]+=r[n][0]=-s/2}bM(e,t)}}function DM(e,t){if((o=e.length)>0&&(a=(i=e[t[0]]).length)>0){for(var n=0,r=1,i,a,o;r<a;++r){for(var s=0,c=0,l=0;s<o;++s){for(var u=e[t[s]],d=u[r][1]||0,f=(d-(u[r-1][1]||0))/2,p=0;p<s;++p){var m=e[t[p]],h=m[r][1]||0,g=m[r-1][1]||0;f+=h-g}c+=d,l+=f*d}i[r-1][1]+=i[r-1][0]=n,c&&(n-=l/c)}i[r-1][1]+=i[r-1][0]=n,bM(e,t)}}var OM=e=>`radius`in e&&`startAngle`in e&&`endAngle`in e,kM=(e,t)=>{if(!e||typeof e==`function`||typeof e==`boolean`)return null;var n=e;if((0,o.isValidElement)(e)&&(n=e.props),typeof n!=`object`&&typeof n!=`function`)return null;var r={};return Object.keys(n).forEach(e=>{ej(e)&&typeof n[e]==`function`&&(r[e]=t||(t=>n[e](n,t)))}),r},AM=(e,t,n)=>r=>(e(t,n,r),null),jM=(e,t,n)=>{if(e===null||typeof e!=`object`&&typeof e!=`function`)return null;var r=null;return Object.keys(e).forEach(i=>{var a=e[i];ej(i)&&typeof a==`function`&&(r||={},r[i]=AM(a,t,n))}),r};function MM(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function NM(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?MM(Object(n),!0).forEach(function(t){PM(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):MM(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function PM(e,t,n){return(t=FM(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function FM(e){var t=IM(e,`string`);return typeof t==`symbol`?t:t+``}function IM(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function LM(e,t){var n=NM({},e),r=t;return Object.keys(t).reduce((e,t)=>(e[t]===void 0&&r[t]!==void 0&&(e[t]=r[t]),e),n)}function RM(e,t){let n=new Map;for(let r=0;r<e.length;r++){let i=e[r],a=t(i,r,e);n.has(a)||n.set(a,i)}return Array.from(n.values())}function zM(e,t){return function(...n){return e.apply(this,n.slice(0,t))}}function BM(e){return e}function VM(e){return Number.isSafeInteger(e)&&e>=0}function HM(e){return e!=null&&typeof e!=`function`&&VM(e.length)}function UM(e){return function(t){return gj(t,e)}}function WM(e){return e==null||typeof e!=`object`&&typeof e!=`function`}function GM(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function KM(e){return Object.getOwnPropertySymbols(e).filter(t=>Object.prototype.propertyIsEnumerable.call(e,t))}function qM(e){return e==null?e===void 0?`[object Undefined]`:`[object Null]`:Object.prototype.toString.call(e)}var JM=`[object RegExp]`,YM=`[object String]`,XM=`[object Number]`,ZM=`[object Boolean]`,QM=`[object Arguments]`,$M=`[object Symbol]`,eN=`[object Date]`,tN=`[object Map]`,nN=`[object Set]`,rN=`[object Array]`,iN=`[object Function]`,aN=`[object ArrayBuffer]`,oN=`[object Object]`,sN=`[object Error]`,cN=`[object DataView]`,lN=`[object Uint8Array]`,uN=`[object Uint8ClampedArray]`,dN=`[object Uint16Array]`,fN=`[object Uint32Array]`,pN=`[object BigUint64Array]`,mN=`[object Int8Array]`,hN=`[object Int16Array]`,gN=`[object Int32Array]`,_N=`[object BigInt64Array]`,vN=`[object Float32Array]`,yN=`[object Float64Array]`,bN=typeof globalThis==`object`&&globalThis||typeof window==`object`&&window||typeof self==`object`&&self||typeof global==`object`&&global||(function(){return this})();function xN(e){return bN.Buffer!==void 0&&bN.Buffer.isBuffer(e)}function SN(e,t){return CN(e,void 0,e,new Map,t)}function CN(e,t,n,r=new Map,i=void 0){let a=i?.(e,t,n,r);if(a!==void 0)return a;if(WM(e))return e;if(r.has(e))return r.get(e);if(Array.isArray(e)){let t=Array(e.length);r.set(e,t);for(let a=0;a<e.length;a++)t[a]=CN(e[a],a,n,r,i);return Object.hasOwn(e,`index`)&&(t.index=e.index),Object.hasOwn(e,`input`)&&(t.input=e.input),t}if(e instanceof Date)return new Date(e.getTime());if(e instanceof RegExp){let t=new RegExp(e.source,e.flags);return t.lastIndex=e.lastIndex,t}if(e instanceof Map){let t=new Map;r.set(e,t);for(let[a,o]of e)t.set(a,CN(o,a,n,r,i));return t}if(e instanceof Set){let t=new Set;r.set(e,t);for(let a of e)t.add(CN(a,void 0,n,r,i));return t}if(xN(e))return e.subarray();if(GM(e)){let t=new(Object.getPrototypeOf(e)).constructor(e.length);r.set(e,t);for(let a=0;a<e.length;a++)t[a]=CN(e[a],a,n,r,i);return t}if(e instanceof ArrayBuffer||typeof SharedArrayBuffer<`u`&&e instanceof SharedArrayBuffer)return e.slice(0);if(e instanceof DataView){let t=new DataView(e.buffer.slice(0),e.byteOffset,e.byteLength);return r.set(e,t),wN(t,e,n,r,i),t}if(typeof File<`u`&&e instanceof File){let t=new File([e],e.name,{type:e.type});return r.set(e,t),wN(t,e,n,r,i),t}if(typeof Blob<`u`&&e instanceof Blob){let t=new Blob([e],{type:e.type});return r.set(e,t),wN(t,e,n,r,i),t}if(e instanceof Error){let t=structuredClone(e);return r.set(e,t),t.message=e.message,t.name=e.name,t.stack=e.stack,t.cause=e.cause,t.constructor=e.constructor,wN(t,e,n,r,i),t}if(e instanceof Boolean){let t=new Boolean(e.valueOf());return r.set(e,t),wN(t,e,n,r,i),t}if(e instanceof Number){let t=new Number(e.valueOf());return r.set(e,t),wN(t,e,n,r,i),t}if(e instanceof String){let t=new String(e.valueOf());return r.set(e,t),wN(t,e,n,r,i),t}if(typeof e==`object`&&TN(e)){let t=Object.create(Object.getPrototypeOf(e));return r.set(e,t),wN(t,e,n,r,i),t}return e}function wN(e,t,n=e,r,i){let a=[...Object.keys(t),...KM(t)];for(let o=0;o<a.length;o++){let s=a[o],c=Object.getOwnPropertyDescriptor(e,s);(c==null||c.writable)&&(e[s]=CN(t[s],s,n,r,i))}}function TN(e){switch(qM(e)){case QM:case rN:case aN:case cN:case ZM:case eN:case vN:case yN:case mN:case hN:case gN:case tN:case XM:case oN:case JM:case nN:case YM:case $M:case lN:case uN:case dN:case fN:return!0;default:return!1}}function EN(e){return CN(e,void 0,e,new Map,void 0)}function DN(e,t){return e===t||Number.isNaN(e)&&Number.isNaN(t)}function ON(e){return e!==null&&(typeof e==`object`||typeof e==`function`)}function kN(e,t,n){return typeof n==`function`?AN(e,t,function e(t,r,i,a,o,s){let c=n(t,r,i,a,o,s);return c===void 0?AN(t,r,e,s,!1):!!c},new Map,!0):kN(e,t,()=>void 0)}function AN(e,t,n,r,i=!1){if(t===e)return!0;switch(typeof t){case`object`:return jN(e,t,n,r,i);case`function`:return Object.keys(t).length>0?AN(e,{...t},n,r,i):DN(e,t);default:return ON(e)&&i?typeof t!=`string`||t===``:DN(e,t)}}function jN(e,t,n,r,i=!1){if(t==null)return!0;if(Array.isArray(t))return NN(e,t,n,r);if(t instanceof Map)return MN(e,t,n,r);if(t instanceof Set)return PN(e,t,n,r);let a=Object.keys(t);if(e==null)return i&&a.length===0;if(i)WM(e)&&(e=Object(e));else{let t=qM(e);if(t!==`[object Object]`&&t!==`[object Arguments]`)return!1}if(a.length===0)return!0;if(r?.has(t))return r.get(t)===e;r?.set(t,e);try{for(let i=0;i<a.length;i++){let o=a[i];if(!(o in e)||t[o]===void 0&&e[o]!==void 0||t[o]===null&&e[o]!==null||!n(e[o],t[o],o,e,t,r))return!1}return!0}finally{r?.delete(t)}}function MN(e,t,n,r){if(t.size===0)return!0;if(!(e instanceof Map))return!1;for(let[i,a]of t.entries())if(n(e.get(i),a,i,e,t,r)===!1)return!1;return!0}function NN(e,t,n,r){if(t.length===0)return!0;if(!Array.isArray(e))return!1;let i=new Set;for(let a=0;a<t.length;a++){let o=t[a],s=!1;for(let c=0;c<e.length;c++){if(i.has(c))continue;let l=e[c],u=!1;if(n(l,o,a,e,t,r)&&(u=!0),u){i.add(c),s=!0;break}}if(!s)return!1}return!0}function PN(e,t,n,r){return t.size===0||e instanceof Set&&NN([...e],[...t],n,r)}function FN(e,t){return kN(e,t,()=>void 0)}function IN(e){return e=EN(e),t=>FN(t,e)}function LN(e,t){return SN(e,(n,r,i,a)=>{let o=t?.(n,r,i,a);if(o!==void 0)return o;if(typeof e==`object`){if(qM(e)===`[object Object]`&&typeof e.constructor!=`function`){let t={};return a.set(e,t),wN(t,e,i,a),t}switch(Object.prototype.toString.call(e)){case XM:case YM:case ZM:{let t=new e.constructor(e?.valueOf());return wN(t,e),t}case QM:{let t={};return wN(t,e),t.length=e.length,t[Symbol.iterator]=e[Symbol.iterator],t}default:return}}})}function RN(e){return LN(e)}var zN=/^(?:0|[1-9]\d*)$/;function BN(e,t=2**53-1){switch(typeof e){case`number`:return Number.isInteger(e)&&e>=0&&e<t;case`symbol`:return!1;case`string`:return zN.test(e)}}function VN(e){return typeof e==`object`&&!!e&&qM(e)===`[object Arguments]`}function HN(e,t){let n;if(n=Array.isArray(t)?t:typeof t==`string`&&dj(t)&&!(t in Object(e))?hj(t):[t],n.length===0)return!1;let r=e;for(let e=0;e<n.length;e++){let t=fj(n[e]);if((r==null||!Object.hasOwn(r,t))&&!((Array.isArray(r)||VN(r))&&BN(t)&&Number(t)<r.length))return!1;r=r[t]}return!0}function UN(e,t){switch(typeof e){case`object`:Object.is(e?.valueOf(),-0)&&(e=`-0`);break;case`number`:e=fj(e)}return t=RN(t),function(n){let r=gj(n,e);return r===void 0?HN(n,e):t===void 0?r===void 0:FN(r,t)}}function WN(e){if(e==null)return BM;switch(typeof e){case`function`:return e;case`object`:return Array.isArray(e)&&e.length===2?UN(e[0],e[1]):IN(e);default:return UM(e)}}function GN(e){return e===0?0:e}function KN(e,t=BM){return HM(e)?RM(Array.from(e),zM(WN(t),1)).map(GN):[]}function qN(e,t,n){return t===!0?KN(e,n):typeof t==`function`?KN(e,t):e}var JN=(0,o.createContext)(null),YN=e=>e,XN=()=>{var e=(0,o.useContext)(JN);return e?e.store.dispatch:YN},ZN=()=>{},QN=()=>ZN,$N=(e,t)=>e===t;function Y(e){var t=(0,o.useContext)(JN),n=(0,o.useMemo)(()=>t?t=>{if(t!=null)return e(t)}:ZN,[t,e]);return(0,qC.useSyncExternalStoreWithSelector)(t?t.subscription.addNestedSub:QN,t?t.store.getState:ZN,t?t.store.getState:ZN,n,$N)}function eP(e,t=`expected a function, instead received ${typeof e}`){if(typeof e!=`function`)throw TypeError(t)}function tP(e,t=`expected all items to be functions, instead received the following types: `){if(!e.every(e=>typeof e==`function`)){let n=e.map(e=>typeof e==`function`?`function ${e.name||`unnamed`}()`:typeof e).join(`, `);throw TypeError(`${t}[${n}]`)}}var nP=e=>Array.isArray(e)?e:[e];function rP(e){let t=Array.isArray(e[0])?e[0]:e;return tP(t,`createSelector expects all input-selectors to be functions, but received the following types: `),t}function iP(e,t){let n=[],{length:r}=e;for(let i=0;i<r;i++)n.push(e[i].apply(null,t));return n}var aP=class{constructor(e){this.value=e}deref(){return this.value}},oP=typeof WeakRef>`u`?aP:WeakRef,sP=0,cP=1;function lP(){return{s:sP,v:void 0,o:null,p:null}}function uP(e){return e instanceof oP?e.deref():e}function dP(e,t={}){let n=lP(),{resultEqualityCheck:r}=t,i,a=0;function o(){let t=n,{length:o}=arguments;for(let e=0,n=o;e<n;e++){let n=arguments[e];if(typeof n==`function`||typeof n==`object`&&n){let e=t.o;e===null&&(t.o=e=new WeakMap);let r=e.get(n);r===void 0?(t=lP(),e.set(n,t)):t=r}else{let e=t.p;e===null&&(t.p=e=new Map);let r=e.get(n);r===void 0?(t=lP(),e.set(n,t)):t=r}}let s=t,c;if(t.s===cP)c=t.v;else if(c=e.apply(null,arguments),a++,r){let e=uP(i);e!=null&&r(e,c)&&(c=e,a!==0&&a--),i=typeof c==`object`&&c||typeof c==`function`?new oP(c):c}return s.s=cP,s.v=c,c}return o.clearCache=()=>{n=lP(),o.resetResultsCount()},o.resultsCount=()=>a,o.resetResultsCount=()=>{a=0},o}function fP(e,...t){let n=typeof e==`function`?{memoize:e,memoizeOptions:t}:e,r=(...e)=>{let t=0,r=0,i,a={},o=e.pop();typeof o==`object`&&(a=o,o=e.pop()),eP(o,`createSelector expects an output function after the inputs, but received: [${typeof o}]`);let{memoize:s,memoizeOptions:c=[],argsMemoize:l=dP,argsMemoizeOptions:u=[]}={...n,...a},d=nP(c),f=nP(u),p=rP(e),m=s(function(){return t++,o.apply(null,arguments)},...d),h=l(function(){r++;let e=iP(p,arguments);return i=m.apply(null,e),i},...f);return Object.assign(h,{resultFunc:o,memoizedResultFunc:m,dependencies:p,dependencyRecomputations:()=>r,resetDependencyRecomputations:()=>{r=0},lastResult:()=>i,recomputations:()=>t,resetRecomputations:()=>{t=0},memoize:s,argsMemoize:l})};return Object.assign(r,{withTypes:()=>r}),r}var X=fP(dP);function pP(e,t=1){let n=[],r=Math.floor(t),i=(e,t)=>{for(let a=0;a<e.length;a++){let o=e[a];Array.isArray(o)&&t<r?i(o,t+1):n.push(o)}};return i(e,0),n}function mP(e,t,n){return ON(n)&&(typeof t==`number`&&HM(n)&&BN(t)&&t<n.length||typeof t==`string`&&t in n)?DN(n[t],e):!1}function hP(e){return typeof e==`symbol`?1:e===null?2:e===void 0?3:e===e?0:4}var gP=(e,t,n)=>{if(e!==t){let r=hP(e),i=hP(t);if(r===i&&r===0){if(e<t)return n===`desc`?1:-1;if(e>t)return n===`desc`?-1:1}return n===`desc`?i-r:r-i}return 0},_P=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,vP=/^\w*$/;function yP(e,t){return Array.isArray(e)?!1:typeof e==`number`||typeof e==`boolean`||e==null||pj(e)?!0:typeof e==`string`&&(vP.test(e)||!_P.test(e))||t!=null&&Object.hasOwn(t,e)}function bP(e,t,n,r){if(e==null)return[];n=r?void 0:n,Array.isArray(e)||(e=HM(e)?Array.from(e):Object.values(e)),Array.isArray(t)||(t=t==null?[null]:[t]),t.length===0&&(t=[null]),Array.isArray(n)||(n=n==null?[]:[n]),n=n.map(e=>String(e));let i=(e,t)=>{let n=e,r=0;for(;r<t.length&&n!=null;++r)n=n[t[r]];return r>0&&r===t.length?n:void 0},a=(e,t)=>{if(e==null)return t;if(t!=null)return typeof e==`object`&&`key`in e?Object.hasOwn(t,e.key)?t[e.key]:i(t,e.path):typeof e==`function`?e(t):Array.isArray(e)?i(t,e):t[e]},o=t.map(e=>(Array.isArray(e)&&e.length===1&&(e=e[0]),e==null||typeof e==`function`||Array.isArray(e)||yP(e)?e:{key:e,path:hj(e)}));return e.map(e=>({original:e,criteria:o.map(t=>a(t,e))})).slice().sort((e,t)=>{for(let r=0;r<o.length;r++){let i=gP(e.criteria[r],t.criteria[r],n[r]);if(i!==0)return i}return 0}).map(e=>e.original)}function xP(e,...t){let n=t.length;return n>1&&mP(e,t[0],t[1])?t=[]:n>2&&mP(t[0],t[1],t[2])&&(t=[t[0]]),bP(e,pP(t),[`asc`])}var SP=e=>e.legend.settings,CP=e=>e.legend.size;X([e=>e.legend.payload,SP],(e,t)=>{var n=t.itemSorter,r=e.flat(1);return n?xP(r,n):r});function wP(e,t){return kP(e)||OP(e,t)||EP(e,t)||TP()}function TP(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
12
+ `},pb={onDragStart(e){let{active:t}=e;return`Picked up draggable item `+t.id+`.`},onDragOver(e){let{active:t,over:n}=e;return n?`Draggable item `+t.id+` was moved over droppable area `+n.id+`.`:`Draggable item `+t.id+` is no longer over a droppable area.`},onDragEnd(e){let{active:t,over:n}=e;return n?`Draggable item `+t.id+` was dropped over droppable area `+n.id:`Draggable item `+t.id+` was dropped.`},onDragCancel(e){let{active:t}=e;return`Dragging was cancelled. Draggable item `+t.id+` was dropped.`}};function mb(e){let{announcements:t=pb,container:n,hiddenTextDescribedById:r,screenReaderInstructions:i=fb}=e,{announce:a,announcement:s}=cb(),c=Jy(`DndLiveRegion`),[l,u]=(0,o.useState)(!1);if((0,o.useEffect)(()=>{u(!0)},[]),ub((0,o.useMemo)(()=>({onDragStart(e){let{active:n}=e;a(t.onDragStart({active:n}))},onDragMove(e){let{active:n,over:r}=e;t.onDragMove&&a(t.onDragMove({active:n,over:r}))},onDragOver(e){let{active:n,over:r}=e;a(t.onDragOver({active:n,over:r}))},onDragEnd(e){let{active:n,over:r}=e;a(t.onDragEnd({active:n,over:r}))},onDragCancel(e){let{active:n,over:r}=e;a(t.onDragCancel({active:n,over:r}))}}),[a,t])),!l)return null;let d=o.createElement(o.Fragment,null,o.createElement(ob,{id:r,value:i.draggable}),o.createElement(sb,{id:c,announcement:s}));return n?(0,Fn.createPortal)(d,n):d}var hb;(function(e){e.DragStart=`dragStart`,e.DragMove=`dragMove`,e.DragEnd=`dragEnd`,e.DragCancel=`dragCancel`,e.DragOver=`dragOver`,e.RegisterDroppable=`registerDroppable`,e.SetDroppableDisabled=`setDroppableDisabled`,e.UnregisterDroppable=`unregisterDroppable`})(hb||={});function gb(){}function _b(e,t){return(0,o.useMemo)(()=>({sensor:e,options:t??{}}),[e,t])}function vb(){var e=[...arguments];return(0,o.useMemo)(()=>[...e].filter(e=>e!=null),[...e])}var yb=Object.freeze({x:0,y:0});function bb(e,t){return Math.sqrt((e.x-t.x)**2+(e.y-t.y)**2)}function xb(e,t){let{data:{value:n}}=e,{data:{value:r}}=t;return n-r}function Sb(e,t){let{data:{value:n}}=e,{data:{value:r}}=t;return r-n}function Cb(e){let{left:t,top:n,height:r,width:i}=e;return[{x:t,y:n},{x:t+i,y:n},{x:t,y:n+r},{x:t+i,y:n+r}]}function wb(e,t){if(!e||e.length===0)return null;let[n]=e;return t?n[t]:n}function Tb(e,t,n){return t===void 0&&(t=e.left),n===void 0&&(n=e.top),{x:t+e.width*.5,y:n+e.height*.5}}var Eb=e=>{let{collisionRect:t,droppableRects:n,droppableContainers:r}=e,i=Tb(t,t.left,t.top),a=[];for(let e of r){let{id:t}=e,r=n.get(t);if(r){let n=bb(Tb(r),i);a.push({id:t,data:{droppableContainer:e,value:n}})}}return a.sort(xb)},Db=e=>{let{collisionRect:t,droppableRects:n,droppableContainers:r}=e,i=Cb(t),a=[];for(let e of r){let{id:t}=e,r=n.get(t);if(r){let n=Cb(r),o=i.reduce((e,t,r)=>e+bb(n[r],t),0),s=Number((o/4).toFixed(4));a.push({id:t,data:{droppableContainer:e,value:s}})}}return a.sort(xb)};function Ob(e,t){let n=Math.max(t.top,e.top),r=Math.max(t.left,e.left),i=Math.min(t.left+t.width,e.left+e.width),a=Math.min(t.top+t.height,e.top+e.height),o=i-r,s=a-n;if(r<i&&n<a){let n=t.width*t.height,r=e.width*e.height,i=o*s,a=i/(n+r-i);return Number(a.toFixed(4))}return 0}var kb=e=>{let{collisionRect:t,droppableRects:n,droppableContainers:r}=e,i=[];for(let e of r){let{id:r}=e,a=n.get(r);if(a){let n=Ob(a,t);n>0&&i.push({id:r,data:{droppableContainer:e,value:n}})}}return i.sort(Sb)};function Ab(e,t,n){return{...e,scaleX:t&&n?t.width/n.width:1,scaleY:t&&n?t.height/n.height:1}}function jb(e,t){return e&&t?{x:e.left-t.left,y:e.top-t.top}:yb}function Mb(e){return function(t){return[...arguments].slice(1).reduce((t,n)=>({...t,top:t.top+e*n.y,bottom:t.bottom+e*n.y,left:t.left+e*n.x,right:t.right+e*n.x}),{...t})}}var Nb=Mb(1);function Pb(e){if(e.startsWith(`matrix3d(`)){let t=e.slice(9,-1).split(/, /);return{x:+t[12],y:+t[13],scaleX:+t[0],scaleY:+t[5]}}if(e.startsWith(`matrix(`)){let t=e.slice(7,-1).split(/, /);return{x:+t[4],y:+t[5],scaleX:+t[0],scaleY:+t[3]}}return null}function Zte(e,t,n){let r=Pb(t);if(!r)return e;let{scaleX:i,scaleY:a,x:o,y:s}=r,c=e.left-o-(1-i)*parseFloat(n),l=e.top-s-(1-a)*parseFloat(n.slice(n.indexOf(` `)+1)),u=i?e.width/i:e.width,d=a?e.height/a:e.height;return{width:u,height:d,top:l,right:c+u,bottom:l+d,left:c}}var Qte={ignoreTransform:!1};function Fb(e,t){t===void 0&&(t=Qte);let n=e.getBoundingClientRect();if(t.ignoreTransform){let{transform:t,transformOrigin:r}=Fy(e).getComputedStyle(e);t&&(n=Zte(n,t,r))}let{top:r,left:i,width:a,height:o,bottom:s,right:c}=n;return{top:r,left:i,width:a,height:o,bottom:s,right:c}}function Ib(e){return Fb(e,{ignoreTransform:!0})}function $te(e){let t=e.innerWidth,n=e.innerHeight;return{top:0,left:0,right:t,bottom:n,width:t,height:n}}function ene(e,t){return t===void 0&&(t=Fy(e).getComputedStyle(e)),t.position===`fixed`}function tne(e,t){t===void 0&&(t=Fy(e).getComputedStyle(e));let n=/(auto|scroll|overlay)/;return[`overflow`,`overflowX`,`overflowY`].some(e=>{let r=t[e];return typeof r==`string`&&n.test(r)})}function Lb(e,t){let n=[];function r(i){if(t!=null&&n.length>=t||!i)return n;if(Iy(i)&&i.scrollingElement!=null&&!n.includes(i.scrollingElement))return n.push(i.scrollingElement),n;if(!Ly(i)||Ry(i)||n.includes(i))return n;let a=Fy(e).getComputedStyle(i);return i!==e&&tne(i,a)&&n.push(i),ene(i,a)?n:r(i.parentNode)}return e?r(e):n}function Rb(e){let[t]=Lb(e,1);return t??null}function zb(e){return!My||!e?null:Ny(e)?e:Py(e)?Iy(e)||e===zy(e).scrollingElement?window:Ly(e)?e:null:null}function Bb(e){return Ny(e)?e.scrollX:e.scrollLeft}function Vb(e){return Ny(e)?e.scrollY:e.scrollTop}function Hb(e){return{x:Bb(e),y:Vb(e)}}var Ub;(function(e){e[e.Forward=1]=`Forward`,e[e.Backward=-1]=`Backward`})(Ub||={});function Wb(e){return!My||!e?!1:e===document.scrollingElement}function Gb(e){let t={x:0,y:0},n=Wb(e)?{height:window.innerHeight,width:window.innerWidth}:{height:e.clientHeight,width:e.clientWidth},r={x:e.scrollWidth-n.width,y:e.scrollHeight-n.height};return{isTop:e.scrollTop<=t.y,isLeft:e.scrollLeft<=t.x,isBottom:e.scrollTop>=r.y,isRight:e.scrollLeft>=r.x,maxScroll:r,minScroll:t}}var nne={x:.2,y:.2};function rne(e,t,n,r,i){let{top:a,left:o,right:s,bottom:c}=n;r===void 0&&(r=10),i===void 0&&(i=nne);let{isTop:l,isBottom:u,isLeft:d,isRight:f}=Gb(e),p={x:0,y:0},m={x:0,y:0},h={height:t.height*i.y,width:t.width*i.x};return!l&&a<=t.top+h.height?(p.y=Ub.Backward,m.y=r*Math.abs((t.top+h.height-a)/h.height)):!u&&c>=t.bottom-h.height&&(p.y=Ub.Forward,m.y=r*Math.abs((t.bottom-h.height-c)/h.height)),!f&&s>=t.right-h.width?(p.x=Ub.Forward,m.x=r*Math.abs((t.right-h.width-s)/h.width)):!d&&o<=t.left+h.width&&(p.x=Ub.Backward,m.x=r*Math.abs((t.left+h.width-o)/h.width)),{direction:p,speed:m}}function ine(e){if(e===document.scrollingElement){let{innerWidth:e,innerHeight:t}=window;return{top:0,left:0,right:e,bottom:t,width:e,height:t}}let{top:t,left:n,right:r,bottom:i}=e.getBoundingClientRect();return{top:t,left:n,right:r,bottom:i,width:e.clientWidth,height:e.clientHeight}}function Kb(e){return e.reduce((e,t)=>Xy(e,Hb(t)),yb)}function ane(e){return e.reduce((e,t)=>e+Bb(t),0)}function one(e){return e.reduce((e,t)=>e+Vb(t),0)}function sne(e,t){if(t===void 0&&(t=Fb),!e)return;let{top:n,left:r,bottom:i,right:a}=t(e);Rb(e)&&(i<=0||a<=0||n>=window.innerHeight||r>=window.innerWidth)&&e.scrollIntoView({block:`center`,inline:`center`})}var cne=[[`x`,[`left`,`right`],ane],[`y`,[`top`,`bottom`],one]],qb=class{constructor(e,t){this.rect=void 0,this.width=void 0,this.height=void 0,this.top=void 0,this.bottom=void 0,this.right=void 0,this.left=void 0;let n=Lb(t),r=Kb(n);this.rect={...e},this.width=e.width,this.height=e.height;for(let[e,t,i]of cne)for(let a of t)Object.defineProperty(this,a,{get:()=>{let t=i(n),o=r[e]-t;return this.rect[a]+o},enumerable:!0});Object.defineProperty(this,"rect",{enumerable:!1})}},Jb=class{constructor(e){this.target=void 0,this.listeners=[],this.removeAll=()=>{this.listeners.forEach(e=>this.target?.removeEventListener(...e))},this.target=e}add(e,t,n){var r;(r=this.target)==null||r.addEventListener(e,t,n),this.listeners.push([e,t,n])}};function lne(e){let{EventTarget:t}=Fy(e);return e instanceof t?e:zy(e)}function Yb(e,t){let n=Math.abs(e.x),r=Math.abs(e.y);return typeof t==`number`?Math.sqrt(n**2+r**2)>t:`x`in t&&`y`in t?n>t.x&&r>t.y:`x`in t?n>t.x:`y`in t&&r>t.y}var Xb;(function(e){e.Click=`click`,e.DragStart=`dragstart`,e.Keydown=`keydown`,e.ContextMenu=`contextmenu`,e.Resize=`resize`,e.SelectionChange=`selectionchange`,e.VisibilityChange=`visibilitychange`})(Xb||={});function Zb(e){e.preventDefault()}function une(e){e.stopPropagation()}var q;(function(e){e.Space=`Space`,e.Down=`ArrowDown`,e.Right=`ArrowRight`,e.Left=`ArrowLeft`,e.Up=`ArrowUp`,e.Esc=`Escape`,e.Enter=`Enter`,e.Tab=`Tab`})(q||={});var Qb={start:[q.Space,q.Enter],cancel:[q.Esc],end:[q.Space,q.Enter,q.Tab]},dne=(e,t)=>{let{currentCoordinates:n}=t;switch(e.code){case q.Right:return{...n,x:n.x+25};case q.Left:return{...n,x:n.x-25};case q.Down:return{...n,y:n.y+25};case q.Up:return{...n,y:n.y-25}}},$b=class{constructor(e){this.props=void 0,this.autoScrollEnabled=!1,this.referenceCoordinates=void 0,this.listeners=void 0,this.windowListeners=void 0,this.props=e;let{event:{target:t}}=e;this.props=e,this.listeners=new Jb(zy(t)),this.windowListeners=new Jb(Fy(t)),this.handleKeyDown=this.handleKeyDown.bind(this),this.handleCancel=this.handleCancel.bind(this),this.attach()}attach(){this.handleStart(),this.windowListeners.add(Xb.Resize,this.handleCancel),this.windowListeners.add(Xb.VisibilityChange,this.handleCancel),setTimeout(()=>this.listeners.add(Xb.Keydown,this.handleKeyDown))}handleStart(){let{activeNode:e,onStart:t}=this.props,n=e.node.current;n&&sne(n),t(yb)}handleKeyDown(e){if($y(e)){let{active:t,context:n,options:r}=this.props,{keyboardCodes:i=Qb,coordinateGetter:a=dne,scrollBehavior:o=`smooth`}=r,{code:s}=e;if(i.end.includes(s)){this.handleEnd(e);return}if(i.cancel.includes(s)){this.handleCancel(e);return}let{collisionRect:c}=n.current,l=c?{x:c.left,y:c.top}:yb;this.referenceCoordinates||=l;let u=a(e,{active:t,context:n.current,currentCoordinates:l});if(u){let t=Zy(u,l),r={x:0,y:0},{scrollableAncestors:i}=n.current;for(let n of i){let i=e.code,{isTop:a,isRight:s,isLeft:c,isBottom:l,maxScroll:d,minScroll:f}=Gb(n),p=ine(n),m={x:Math.min(i===q.Right?p.right-p.width/2:p.right,Math.max(i===q.Right?p.left:p.left+p.width/2,u.x)),y:Math.min(i===q.Down?p.bottom-p.height/2:p.bottom,Math.max(i===q.Down?p.top:p.top+p.height/2,u.y))},h=i===q.Right&&!s||i===q.Left&&!c,g=i===q.Down&&!l||i===q.Up&&!a;if(h&&m.x!==u.x){let e=n.scrollLeft+t.x,a=i===q.Right&&e<=d.x||i===q.Left&&e>=f.x;if(a&&!t.y){n.scrollTo({left:e,behavior:o});return}r.x=a?n.scrollLeft-e:i===q.Right?n.scrollLeft-d.x:n.scrollLeft-f.x,r.x&&n.scrollBy({left:-r.x,behavior:o});break}if(g&&m.y!==u.y){let e=n.scrollTop+t.y,a=i===q.Down&&e<=d.y||i===q.Up&&e>=f.y;if(a&&!t.x){n.scrollTo({top:e,behavior:o});return}r.y=a?n.scrollTop-e:i===q.Down?n.scrollTop-d.y:n.scrollTop-f.y,r.y&&n.scrollBy({top:-r.y,behavior:o});break}}this.handleMove(e,Xy(Zy(u,this.referenceCoordinates),r))}}}handleMove(e,t){let{onMove:n}=this.props;e.preventDefault(),n(t)}handleEnd(e){let{onEnd:t}=this.props;e.preventDefault(),this.detach(),t()}handleCancel(e){let{onCancel:t}=this.props;e.preventDefault(),this.detach(),t()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll()}};$b.activators=[{eventName:`onKeyDown`,handler:(e,t,n)=>{let{keyboardCodes:r=Qb,onActivation:i}=t,{active:a}=n,{code:o}=e.nativeEvent;if(r.start.includes(o)){let t=a.activatorNode.current;return t&&e.target!==t?!1:(e.preventDefault(),i?.({event:e.nativeEvent}),!0)}return!1}}];function ex(e){return!!(e&&`distance`in e)}function tx(e){return!!(e&&`delay`in e)}var nx=class{constructor(e,t,n){n===void 0&&(n=lne(e.event.target)),this.props=void 0,this.events=void 0,this.autoScrollEnabled=!0,this.document=void 0,this.activated=!1,this.initialCoordinates=void 0,this.timeoutId=null,this.listeners=void 0,this.documentListeners=void 0,this.windowListeners=void 0,this.props=e,this.events=t;let{event:r}=e,{target:i}=r;this.props=e,this.events=t,this.document=zy(i),this.documentListeners=new Jb(this.document),this.listeners=new Jb(n),this.windowListeners=new Jb(Fy(i)),this.initialCoordinates=tb(r)??yb,this.handleStart=this.handleStart.bind(this),this.handleMove=this.handleMove.bind(this),this.handleEnd=this.handleEnd.bind(this),this.handleCancel=this.handleCancel.bind(this),this.handleKeydown=this.handleKeydown.bind(this),this.removeTextSelection=this.removeTextSelection.bind(this),this.attach()}attach(){let{events:e,props:{options:{activationConstraint:t,bypassActivationConstraint:n}}}=this;if(this.listeners.add(e.move.name,this.handleMove,{passive:!1}),this.listeners.add(e.end.name,this.handleEnd),e.cancel&&this.listeners.add(e.cancel.name,this.handleCancel),this.windowListeners.add(Xb.Resize,this.handleCancel),this.windowListeners.add(Xb.DragStart,Zb),this.windowListeners.add(Xb.VisibilityChange,this.handleCancel),this.windowListeners.add(Xb.ContextMenu,Zb),this.documentListeners.add(Xb.Keydown,this.handleKeydown),t){if(n!=null&&n({event:this.props.event,activeNode:this.props.activeNode,options:this.props.options}))return this.handleStart();if(tx(t)){this.timeoutId=setTimeout(this.handleStart,t.delay),this.handlePending(t);return}if(ex(t)){this.handlePending(t);return}}this.handleStart()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll(),setTimeout(this.documentListeners.removeAll,50),this.timeoutId!==null&&(clearTimeout(this.timeoutId),this.timeoutId=null)}handlePending(e,t){let{active:n,onPending:r}=this.props;r(n,e,this.initialCoordinates,t)}handleStart(){let{initialCoordinates:e}=this,{onStart:t}=this.props;e&&(this.activated=!0,this.documentListeners.add(Xb.Click,une,{capture:!0}),this.removeTextSelection(),this.documentListeners.add(Xb.SelectionChange,this.removeTextSelection),t(e))}handleMove(e){let{activated:t,initialCoordinates:n,props:r}=this,{onMove:i,options:{activationConstraint:a}}=r;if(!n)return;let o=tb(e)??yb,s=Zy(n,o);if(!t&&a){if(ex(a)){if(a.tolerance!=null&&Yb(s,a.tolerance))return this.handleCancel();if(Yb(s,a.distance))return this.handleStart()}if(tx(a)&&Yb(s,a.tolerance))return this.handleCancel();this.handlePending(a,s);return}e.cancelable&&e.preventDefault(),i(o)}handleEnd(){let{onAbort:e,onEnd:t}=this.props;this.detach(),this.activated||e(this.props.active),t()}handleCancel(){let{onAbort:e,onCancel:t}=this.props;this.detach(),this.activated||e(this.props.active),t()}handleKeydown(e){e.code===q.Esc&&this.handleCancel()}removeTextSelection(){var e;(e=this.document.getSelection())==null||e.removeAllRanges()}},fne={cancel:{name:`pointercancel`},move:{name:`pointermove`},end:{name:`pointerup`}},rx=class extends nx{constructor(e){let{event:t}=e,n=zy(t.target);super(e,fne,n)}};rx.activators=[{eventName:`onPointerDown`,handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t;return!n.isPrimary||n.button!==0?!1:(r?.({event:n}),!0)}}];var pne={move:{name:`mousemove`},end:{name:`mouseup`}},ix;(function(e){e[e.RightClick=2]=`RightClick`})(ix||={});var ax=class extends nx{constructor(e){super(e,pne,zy(e.event.target))}};ax.activators=[{eventName:`onMouseDown`,handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t;return n.button!==ix.RightClick&&(r?.({event:n}),!0)}}];var ox={cancel:{name:`touchcancel`},move:{name:`touchmove`},end:{name:`touchend`}},sx=class extends nx{constructor(e){super(e,ox)}static setup(){return window.addEventListener(ox.move.name,e,{capture:!1,passive:!1}),function(){window.removeEventListener(ox.move.name,e)};function e(){}}};sx.activators=[{eventName:`onTouchStart`,handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t,{touches:i}=n;return i.length>1?!1:(r?.({event:n}),!0)}}];var cx;(function(e){e[e.Pointer=0]=`Pointer`,e[e.DraggableRect=1]=`DraggableRect`})(cx||={});var lx;(function(e){e[e.TreeOrder=0]=`TreeOrder`,e[e.ReversedTreeOrder=1]=`ReversedTreeOrder`})(lx||={});function mne(e){let{acceleration:t,activator:n=cx.Pointer,canScroll:r,draggingRect:i,enabled:a,interval:s=5,order:c=lx.TreeOrder,pointerCoordinates:l,scrollableAncestors:u,scrollableAncestorRects:d,delta:f,threshold:p}=e,m=gne({delta:f,disabled:!a}),[h,g]=Hy(),_=(0,o.useRef)({x:0,y:0}),v=(0,o.useRef)({x:0,y:0}),y=(0,o.useMemo)(()=>{switch(n){case cx.Pointer:return l?{top:l.y,bottom:l.y,left:l.x,right:l.x}:null;case cx.DraggableRect:return i}},[n,i,l]),b=(0,o.useRef)(null),x=(0,o.useCallback)(()=>{let e=b.current;if(!e)return;let t=_.current.x*v.current.x,n=_.current.y*v.current.y;e.scrollBy(t,n)},[]),S=(0,o.useMemo)(()=>c===lx.TreeOrder?[...u].reverse():u,[c,u]);(0,o.useEffect)(()=>{if(!a||!u.length||!y){g();return}for(let e of S){if(r?.(e)===!1)continue;let n=u.indexOf(e),i=d[n];if(!i)continue;let{direction:a,speed:o}=rne(e,i,y,t,p);for(let e of[`x`,`y`])m[e][a[e]]||(o[e]=0,a[e]=0);if(o.x>0||o.y>0){g(),b.current=e,h(x,s),_.current=o,v.current=a;return}}_.current={x:0,y:0},v.current={x:0,y:0},g()},[t,x,r,g,a,s,JSON.stringify(y),JSON.stringify(m),h,u,S,d,JSON.stringify(p)])}var hne={x:{[Ub.Backward]:!1,[Ub.Forward]:!1},y:{[Ub.Backward]:!1,[Ub.Forward]:!1}};function gne(e){let{delta:t,disabled:n}=e,r=Ky(t);return Wy(e=>{if(n||!r||!e)return hne;let i={x:Math.sign(t.x-r.x),y:Math.sign(t.y-r.y)};return{x:{[Ub.Backward]:e.x[Ub.Backward]||i.x===-1,[Ub.Forward]:e.x[Ub.Forward]||i.x===1},y:{[Ub.Backward]:e.y[Ub.Backward]||i.y===-1,[Ub.Forward]:e.y[Ub.Forward]||i.y===1}}},[n,t,r])}function _ne(e,t){let n=t==null?void 0:e.get(t),r=n?n.node.current:null;return Wy(e=>t==null?null:r??e??null,[r,t])}function vne(e,t){return(0,o.useMemo)(()=>e.reduce((e,n)=>{let{sensor:r}=n,i=r.activators.map(e=>({eventName:e.eventName,handler:t(e.handler,n)}));return[...e,...i]},[]),[e,t])}var ux;(function(e){e[e.Always=0]=`Always`,e[e.BeforeDragging=1]=`BeforeDragging`,e[e.WhileDragging=2]=`WhileDragging`})(ux||={});var dx;(function(e){e.Optimized=`optimized`})(dx||={});var fx=new Map;function px(e,t){let{dragging:n,dependencies:r,config:i}=t,[a,s]=(0,o.useState)(null),{frequency:c,measure:l,strategy:u}=i,d=(0,o.useRef)(e),f=_(),p=Uy(f),m=(0,o.useCallback)(function(e){e===void 0&&(e=[]),!p.current&&s(t=>t===null?e:t.concat(e.filter(e=>!t.includes(e))))},[p]),h=(0,o.useRef)(null),g=Wy(t=>{if(f&&!n)return fx;if(!t||t===fx||d.current!==e||a!=null){let t=new Map;for(let n of e){if(!n)continue;if(a&&a.length>0&&!a.includes(n.id)&&n.rect.current){t.set(n.id,n.rect.current);continue}let e=n.node.current,r=e?new qb(l(e),e):null;n.rect.current=r,r&&t.set(n.id,r)}return t}return t},[e,a,n,f,l]);return(0,o.useEffect)(()=>{d.current=e},[e]),(0,o.useEffect)(()=>{f||m()},[n,f]),(0,o.useEffect)(()=>{a&&a.length>0&&s(null)},[JSON.stringify(a)]),(0,o.useEffect)(()=>{f||typeof c!=`number`||h.current!==null||(h.current=setTimeout(()=>{m(),h.current=null},c))},[c,f,m,...r]),{droppableRects:g,measureDroppableContainers:m,measuringScheduled:a!=null};function _(){switch(u){case ux.Always:return!1;case ux.BeforeDragging:return n;default:return!n}}}function mx(e,t){return Wy(n=>e?n||(typeof t==`function`?t(e):e):null,[t,e])}function hx(e,t){return mx(e,t)}function gx(e){let{callback:t,disabled:n}=e,r=Vy(t),i=(0,o.useMemo)(()=>{if(n||typeof window>`u`||window.MutationObserver===void 0)return;let{MutationObserver:e}=window;return new e(r)},[r,n]);return(0,o.useEffect)(()=>()=>i?.disconnect(),[i]),i}function _x(e){let{callback:t,disabled:n}=e,r=Vy(t),i=(0,o.useMemo)(()=>{if(n||typeof window>`u`||window.ResizeObserver===void 0)return;let{ResizeObserver:e}=window;return new e(r)},[n]);return(0,o.useEffect)(()=>()=>i?.disconnect(),[i]),i}function vx(e){return new qb(Fb(e),e)}function yx(e,t,n){t===void 0&&(t=vx);let[r,i]=(0,o.useState)(null);function a(){i(r=>{if(!e)return null;if(e.isConnected===!1)return r??n??null;let i=t(e);return JSON.stringify(r)===JSON.stringify(i)?r:i})}let s=gx({callback(t){if(e)for(let n of t){let{type:t,target:r}=n;if(t===`childList`&&r instanceof HTMLElement&&r.contains(e)){a();break}}}}),c=_x({callback:a});return By(()=>{a(),e?(c?.observe(e),s?.observe(document.body,{childList:!0,subtree:!0})):(c?.disconnect(),s?.disconnect())},[e]),r}function bx(e){return jb(e,mx(e))}var xx=[];function Sx(e){let t=(0,o.useRef)(e),n=Wy(n=>e?n&&n!==xx&&e&&t.current&&e.parentNode===t.current.parentNode?n:Lb(e):xx,[e]);return(0,o.useEffect)(()=>{t.current=e},[e]),n}function Cx(e){let[t,n]=(0,o.useState)(null),r=(0,o.useRef)(e),i=(0,o.useCallback)(e=>{let t=zb(e.target);t&&n(e=>e?(e.set(t,Hb(t)),new Map(e)):null)},[]);return(0,o.useEffect)(()=>{let t=r.current;if(e!==t){a(t);let o=e.map(e=>{let t=zb(e);return t?(t.addEventListener(`scroll`,i,{passive:!0}),[t,Hb(t)]):null}).filter(e=>e!=null);n(o.length?new Map(o):null),r.current=e}return()=>{a(e),a(t)};function a(e){e.forEach(e=>{zb(e)?.removeEventListener(`scroll`,i)})}},[i,e]),(0,o.useMemo)(()=>e.length?t?Array.from(t.values()).reduce((e,t)=>Xy(e,t),yb):Kb(e):yb,[e,t])}function wx(e,t){t===void 0&&(t=[]);let n=(0,o.useRef)(null);return(0,o.useEffect)(()=>{n.current=null},t),(0,o.useEffect)(()=>{let t=e!==yb;t&&!n.current&&(n.current=e),!t&&n.current&&(n.current=null)},[e]),n.current?Zy(e,n.current):yb}function Tx(e){(0,o.useEffect)(()=>{if(!My)return;let t=e.map(e=>{let{sensor:t}=e;return t.setup==null?void 0:t.setup()});return()=>{for(let e of t)e?.()}},e.map(e=>{let{sensor:t}=e;return t}))}function Ex(e,t){return(0,o.useMemo)(()=>e.reduce((e,n)=>{let{eventName:r,handler:i}=n;return e[r]=e=>{i(e,t)},e},{}),[e,t])}function Dx(e){return(0,o.useMemo)(()=>e?$te(e):null,[e])}var Ox=[];function kx(e,t){t===void 0&&(t=Fb);let[n]=e,r=Dx(n?Fy(n):null),[i,a]=(0,o.useState)(Ox);function s(){a(()=>e.length?e.map(e=>Wb(e)?r:new qb(t(e),e)):Ox)}let c=_x({callback:s});return By(()=>{c?.disconnect(),s(),e.forEach(e=>c?.observe(e))},[e]),i}function Ax(e){if(!e)return null;if(e.children.length>1)return e;let t=e.children[0];return Ly(t)?t:e}function jx(e){let{measure:t}=e,[n,r]=(0,o.useState)(null),i=_x({callback:(0,o.useCallback)(e=>{for(let{target:n}of e)if(Ly(n)){r(e=>{let r=t(n);return e?{...e,width:r.width,height:r.height}:r});break}},[t])}),[a,s]=Gy((0,o.useCallback)(e=>{let n=Ax(e);i?.disconnect(),n&&i?.observe(n),r(n?t(n):null)},[t,i]));return(0,o.useMemo)(()=>({nodeRef:a,rect:n,setRef:s}),[n,a,s])}var Mx=[{sensor:rx,options:{}},{sensor:$b,options:{}}],Nx={current:{}},Px={draggable:{measure:Ib},droppable:{measure:Ib,strategy:ux.WhileDragging,frequency:dx.Optimized},dragOverlay:{measure:Fb}},Fx=class extends Map{get(e){return e==null?void 0:super.get(e)??void 0}toArray(){return Array.from(this.values())}getEnabled(){return this.toArray().filter(e=>{let{disabled:t}=e;return!t})}getNodeFor(e){return this.get(e)?.node.current??void 0}},Ix={activatorEvent:null,active:null,activeNode:null,activeNodeRect:null,collisions:null,containerNodeRect:null,draggableNodes:new Map,droppableRects:new Map,droppableContainers:new Fx,over:null,dragOverlay:{nodeRef:{current:null},rect:null,setRef:gb},scrollableAncestors:[],scrollableAncestorRects:[],measuringConfiguration:Px,measureDroppableContainers:gb,windowRect:null,measuringScheduled:!1},Lx={activatorEvent:null,activators:[],active:null,activeNodeRect:null,ariaDescribedById:{draggable:``},dispatch:gb,draggableNodes:new Map,over:null,measureDroppableContainers:gb},Rx=(0,o.createContext)(Lx),zx=(0,o.createContext)(Ix);function Bx(){return{draggable:{active:null,initialCoordinates:{x:0,y:0},nodes:new Map,translate:{x:0,y:0}},droppable:{containers:new Fx}}}function Vx(e,t){switch(t.type){case hb.DragStart:return{...e,draggable:{...e.draggable,initialCoordinates:t.initialCoordinates,active:t.active}};case hb.DragMove:return e.draggable.active==null?e:{...e,draggable:{...e.draggable,translate:{x:t.coordinates.x-e.draggable.initialCoordinates.x,y:t.coordinates.y-e.draggable.initialCoordinates.y}}};case hb.DragEnd:case hb.DragCancel:return{...e,draggable:{...e.draggable,active:null,initialCoordinates:{x:0,y:0},translate:{x:0,y:0}}};case hb.RegisterDroppable:{let{element:n}=t,{id:r}=n,i=new Fx(e.droppable.containers);return i.set(r,n),{...e,droppable:{...e.droppable,containers:i}}}case hb.SetDroppableDisabled:{let{id:n,key:r,disabled:i}=t,a=e.droppable.containers.get(n);if(!a||r!==a.key)return e;let o=new Fx(e.droppable.containers);return o.set(n,{...a,disabled:i}),{...e,droppable:{...e.droppable,containers:o}}}case hb.UnregisterDroppable:{let{id:n,key:r}=t,i=e.droppable.containers.get(n);if(!i||r!==i.key)return e;let a=new Fx(e.droppable.containers);return a.delete(n),{...e,droppable:{...e.droppable,containers:a}}}default:return e}}function Hx(e){let{disabled:t}=e,{active:n,activatorEvent:r,draggableNodes:i}=(0,o.useContext)(Rx),a=Ky(r),s=Ky(n?.id);return(0,o.useEffect)(()=>{if(!t&&!r&&a&&s!=null){if(!$y(a)||document.activeElement===a.target)return;let e=i.get(s);if(!e)return;let{activatorNode:t,node:n}=e;if(!t.current&&!n.current)return;requestAnimationFrame(()=>{for(let e of[t.current,n.current]){if(!e)continue;let t=ib(e);if(t){t.focus();break}}})}},[r,t,i,s,a]),null}function Ux(e,t){let{transform:n,...r}=t;return e!=null&&e.length?e.reduce((e,t)=>t({transform:e,...r}),n):n}function Wx(e){return(0,o.useMemo)(()=>({draggable:{...Px.draggable,...e?.draggable},droppable:{...Px.droppable,...e?.droppable},dragOverlay:{...Px.dragOverlay,...e?.dragOverlay}}),[e?.draggable,e?.droppable,e?.dragOverlay])}function Gx(e){let{activeNode:t,measure:n,initialRect:r,config:i=!0}=e,a=(0,o.useRef)(!1),{x:s,y:c}=typeof i==`boolean`?{x:i,y:i}:i;By(()=>{if(!s&&!c||!t){a.current=!1;return}if(a.current||!r)return;let e=t?.node.current;if(!e||e.isConnected===!1)return;let i=jb(n(e),r);if(s||(i.x=0),c||(i.y=0),a.current=!0,Math.abs(i.x)>0||Math.abs(i.y)>0){let t=Rb(e);t&&t.scrollBy({top:i.y,left:i.x})}},[t,s,c,r,n])}var Kx=(0,o.createContext)({...yb,scaleX:1,scaleY:1}),qx;(function(e){e[e.Uninitialized=0]=`Uninitialized`,e[e.Initializing=1]=`Initializing`,e[e.Initialized=2]=`Initialized`})(qx||={});var Jx=(0,o.memo)(function(e){let{id:t,accessibility:n,autoScroll:r=!0,children:i,sensors:a=Mx,collisionDetection:s=kb,measuring:c,modifiers:l,...u}=e,[d,f]=(0,o.useReducer)(Vx,void 0,Bx),[p,m]=db(),[h,g]=(0,o.useState)(qx.Uninitialized),_=h===qx.Initialized,{draggable:{active:v,nodes:y,translate:b},droppable:{containers:x}}=d,S=v==null?null:y.get(v),C=(0,o.useRef)({initial:null,translated:null}),w=(0,o.useMemo)(()=>v==null?null:{id:v,data:S?.data??Nx,rect:C},[v,S]),T=(0,o.useRef)(null),[E,D]=(0,o.useState)(null),[O,k]=(0,o.useState)(null),A=Uy(u,Object.values(u)),j=Jy(`DndDescribedBy`,t),M=(0,o.useMemo)(()=>x.getEnabled(),[x]),N=Wx(c),{droppableRects:ee,measureDroppableContainers:te,measuringScheduled:ne}=px(M,{dragging:_,dependencies:[b.x,b.y],config:N.droppable}),P=_ne(y,v),re=(0,o.useMemo)(()=>O?tb(O):null,[O]),ie=Ne(),ae=hx(P,N.draggable.measure);Gx({activeNode:v==null?null:y.get(v),config:ie.layoutShiftCompensation,initialRect:ae,measure:N.draggable.measure});let F=yx(P,N.draggable.measure,ae),oe=yx(P?P.parentElement:null),se=(0,o.useRef)({activatorEvent:null,active:null,activeNode:P,collisionRect:null,collisions:null,droppableRects:ee,draggableNodes:y,draggingNode:null,draggingNodeRect:null,droppableContainers:x,over:null,scrollableAncestors:[],scrollAdjustedTranslate:null}),ce=x.getNodeFor(se.current.over?.id),I=jx({measure:N.dragOverlay.measure}),le=I.nodeRef.current??P,ue=_?I.rect??F:null,de=!!(I.nodeRef.current&&I.rect),fe=bx(de?null:F),pe=Dx(le?Fy(le):null),me=Sx(_?ce??P:null),he=kx(me),ge=Ux(l,{transform:{x:b.x-fe.x,y:b.y-fe.y,scaleX:1,scaleY:1},activatorEvent:O,active:w,activeNodeRect:F,containerNodeRect:oe,draggingNodeRect:ue,over:se.current.over,overlayNodeRect:I.rect,scrollableAncestors:me,scrollableAncestorRects:he,windowRect:pe}),_e=re?Xy(re,b):null,ve=Cx(me),ye=wx(ve),be=wx(ve,[F]),xe=Xy(ge,ye),Se=ue?Nb(ue,ge):null,Ce=w&&Se?s({active:w,collisionRect:Se,droppableRects:ee,droppableContainers:M,pointerCoordinates:_e}):null,we=wb(Ce,`id`),[Te,Ee]=(0,o.useState)(null),De=Ab(de?ge:Xy(ge,be),Te?.rect??null,F),Oe=(0,o.useRef)(null),ke=(0,o.useCallback)((e,t)=>{let{sensor:n,options:r}=t;if(T.current==null)return;let i=y.get(T.current);if(!i)return;let a=e.nativeEvent,o=new n({active:T.current,activeNode:i,event:a,options:r,context:se,onAbort(e){if(!y.get(e))return;let{onDragAbort:t}=A.current,n={id:e};t?.(n),p({type:`onDragAbort`,event:n})},onPending(e,t,n,r){if(!y.get(e))return;let{onDragPending:i}=A.current,a={id:e,constraint:t,initialCoordinates:n,offset:r};i?.(a),p({type:`onDragPending`,event:a})},onStart(e){let t=T.current;if(t==null)return;let n=y.get(t);if(!n)return;let{onDragStart:r}=A.current,i={activatorEvent:a,active:{id:t,data:n.data,rect:C}};(0,Fn.unstable_batchedUpdates)(()=>{r?.(i),g(qx.Initializing),f({type:hb.DragStart,initialCoordinates:e,active:t}),p({type:`onDragStart`,event:i}),D(Oe.current),k(a)})},onMove(e){f({type:hb.DragMove,coordinates:e})},onEnd:s(hb.DragEnd),onCancel:s(hb.DragCancel)});Oe.current=o;function s(e){return async function(){let{active:t,collisions:n,over:r,scrollAdjustedTranslate:i}=se.current,o=null;if(t&&i){let{cancelDrop:s}=A.current;o={activatorEvent:a,active:t,collisions:n,delta:i,over:r},e===hb.DragEnd&&typeof s==`function`&&await Promise.resolve(s(o))&&(e=hb.DragCancel)}T.current=null,(0,Fn.unstable_batchedUpdates)(()=>{f({type:e}),g(qx.Uninitialized),Ee(null),D(null),k(null),Oe.current=null;let t=e===hb.DragEnd?`onDragEnd`:`onDragCancel`;if(o){let e=A.current[t];e?.(o),p({type:t,event:o})}})}}},[y]),Ae=vne(a,(0,o.useCallback)((e,t)=>(n,r)=>{let i=n.nativeEvent,a=y.get(r);if(T.current!==null||!a||i.dndKit||i.defaultPrevented)return;let o={active:a};e(n,t.options,o)===!0&&(i.dndKit={capturedBy:t.sensor},T.current=r,ke(n,t))},[y,ke]));Tx(a),By(()=>{F&&h===qx.Initializing&&g(qx.Initialized)},[F,h]),(0,o.useEffect)(()=>{let{onDragMove:e}=A.current,{active:t,activatorEvent:n,collisions:r,over:i}=se.current;if(!t||!n)return;let a={active:t,activatorEvent:n,collisions:r,delta:{x:xe.x,y:xe.y},over:i};(0,Fn.unstable_batchedUpdates)(()=>{e?.(a),p({type:`onDragMove`,event:a})})},[xe.x,xe.y]),(0,o.useEffect)(()=>{let{active:e,activatorEvent:t,collisions:n,droppableContainers:r,scrollAdjustedTranslate:i}=se.current;if(!e||T.current==null||!t||!i)return;let{onDragOver:a}=A.current,o=r.get(we),s=o&&o.rect.current?{id:o.id,rect:o.rect.current,data:o.data,disabled:o.disabled}:null,c={active:e,activatorEvent:t,collisions:n,delta:{x:i.x,y:i.y},over:s};(0,Fn.unstable_batchedUpdates)(()=>{Ee(s),a?.(c),p({type:`onDragOver`,event:c})})},[we]),By(()=>{se.current={activatorEvent:O,active:w,activeNode:P,collisionRect:Se,collisions:Ce,droppableRects:ee,draggableNodes:y,draggingNode:le,draggingNodeRect:ue,droppableContainers:x,over:Te,scrollableAncestors:me,scrollAdjustedTranslate:xe},C.current={initial:ue,translated:Se}},[w,P,Ce,Se,y,le,ue,ee,x,Te,me,xe]),mne({...ie,delta:b,draggingRect:Se,pointerCoordinates:_e,scrollableAncestors:me,scrollableAncestorRects:he});let je=(0,o.useMemo)(()=>({active:w,activeNode:P,activeNodeRect:F,activatorEvent:O,collisions:Ce,containerNodeRect:oe,dragOverlay:I,draggableNodes:y,droppableContainers:x,droppableRects:ee,over:Te,measureDroppableContainers:te,scrollableAncestors:me,scrollableAncestorRects:he,measuringConfiguration:N,measuringScheduled:ne,windowRect:pe}),[w,P,F,O,Ce,oe,I,y,x,ee,Te,te,me,he,N,ne,pe]),Me=(0,o.useMemo)(()=>({activatorEvent:O,activators:Ae,active:w,activeNodeRect:F,ariaDescribedById:{draggable:j},dispatch:f,draggableNodes:y,over:Te,measureDroppableContainers:te}),[O,Ae,w,F,f,j,y,Te,te]);return o.createElement(lb.Provider,{value:m},o.createElement(Rx.Provider,{value:Me},o.createElement(zx.Provider,{value:je},o.createElement(Kx.Provider,{value:De},i)),o.createElement(Hx,{disabled:n?.restoreFocus===!1})),o.createElement(mb,{...n,hiddenTextDescribedById:j}));function Ne(){let e=E?.autoScrollEnabled===!1,t=typeof r==`object`?r.enabled===!1:r===!1,n=_&&!e&&!t;return typeof r==`object`?{...r,enabled:n}:{enabled:n}}}),Yx=(0,o.createContext)(null),Xx=`button`,Zx=`Draggable`;function Qx(e){let{id:t,data:n,disabled:r=!1,attributes:i}=e,a=Jy(Zx),{activators:s,activatorEvent:c,active:l,activeNodeRect:u,ariaDescribedById:d,draggableNodes:f,over:p}=(0,o.useContext)(Rx),{role:m=Xx,roleDescription:h=`draggable`,tabIndex:g=0}=i??{},_=l?.id===t,v=(0,o.useContext)(_?Kx:Yx),[y,b]=Gy(),[x,S]=Gy(),C=Ex(s,t),w=Uy(n);return By(()=>(f.set(t,{id:t,key:a,node:y,activatorNode:x,data:w}),()=>{let e=f.get(t);e&&e.key===a&&f.delete(t)}),[f,t]),{active:l,activatorEvent:c,activeNodeRect:u,attributes:(0,o.useMemo)(()=>({role:m,tabIndex:g,"aria-disabled":r,"aria-pressed":_&&m===Xx?!0:void 0,"aria-roledescription":h,"aria-describedby":d.draggable}),[r,m,g,_,h,d.draggable]),isDragging:_,listeners:r?void 0:C,node:y,over:p,setNodeRef:b,setActivatorNodeRef:S,transform:v}}function $x(){return(0,o.useContext)(zx)}var eS=`Droppable`,tS={timeout:25};function nS(e){let{data:t,disabled:n=!1,id:r,resizeObserverConfig:i}=e,a=Jy(eS),{active:s,dispatch:c,over:l,measureDroppableContainers:u}=(0,o.useContext)(Rx),d=(0,o.useRef)({disabled:n}),f=(0,o.useRef)(!1),p=(0,o.useRef)(null),m=(0,o.useRef)(null),{disabled:h,updateMeasurementsFor:g,timeout:_}={...tS,...i},v=Uy(g??r),y=_x({callback:(0,o.useCallback)(()=>{if(!f.current){f.current=!0;return}m.current!=null&&clearTimeout(m.current),m.current=setTimeout(()=>{u(Array.isArray(v.current)?v.current:[v.current]),m.current=null},_)},[_]),disabled:h||!s}),[b,x]=Gy((0,o.useCallback)((e,t)=>{y&&(t&&(y.unobserve(t),f.current=!1),e&&y.observe(e))},[y])),S=Uy(t);return(0,o.useEffect)(()=>{y&&b.current&&(y.disconnect(),f.current=!1,y.observe(b.current))},[b,y]),(0,o.useEffect)(()=>(c({type:hb.RegisterDroppable,element:{id:r,key:a,disabled:n,node:b,rect:p,data:S}}),()=>c({type:hb.UnregisterDroppable,key:a,id:r})),[r]),(0,o.useEffect)(()=>{n!==d.current.disabled&&(c({type:hb.SetDroppableDisabled,id:r,key:a,disabled:n}),d.current.disabled=n)},[r,a,n,c]),{active:s,rect:p,isOver:l?.id===r,node:b,over:l,setNodeRef:x}}function rS(e,t,n){let r=e.slice();return r.splice(n<0?r.length+n:n,0,r.splice(t,1)[0]),r}function iS(e,t){return e.reduce((e,n,r)=>{let i=t.get(n);return i&&(e[r]=i),e},Array(e.length))}function aS(e){return e!==null&&e>=0}function oS(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function sS(e){return typeof e==`boolean`?{draggable:e,droppable:e}:e}var cS=e=>{let{rects:t,activeIndex:n,overIndex:r,index:i}=e,a=rS(t,r,n),o=t[i],s=a[i];return!s||!o?null:{x:s.left-o.left,y:s.top-o.top,scaleX:s.width/o.width,scaleY:s.height/o.height}},lS={scaleX:1,scaleY:1},uS=e=>{let{activeIndex:t,activeNodeRect:n,index:r,rects:i,overIndex:a}=e,o=i[t]??n;if(!o)return null;if(r===t){let e=i[a];return e?{x:0,y:t<a?e.top+e.height-(o.top+o.height):e.top-o.top,...lS}:null}let s=dS(i,r,t);return r>t&&r<=a?{x:0,y:-o.height-s,...lS}:r<t&&r>=a?{x:0,y:o.height+s,...lS}:{x:0,y:0,...lS}};function dS(e,t,n){let r=e[t],i=e[t-1],a=e[t+1];return r?n<t?i?r.top-(i.top+i.height):a?a.top-(r.top+r.height):0:a?a.top-(r.top+r.height):i?r.top-(i.top+i.height):0:0}var fS=`Sortable`,pS=o.createContext({activeIndex:-1,containerId:fS,disableTransforms:!1,items:[],overIndex:-1,useDragOverlay:!1,sortedRects:[],strategy:cS,disabled:{draggable:!1,droppable:!1}});function mS(e){let{children:t,id:n,items:r,strategy:i=cS,disabled:a=!1}=e,{active:s,dragOverlay:c,droppableRects:l,over:u,measureDroppableContainers:d}=$x(),f=Jy(fS,n),p=c.rect!==null,m=(0,o.useMemo)(()=>r.map(e=>typeof e==`object`&&`id`in e?e.id:e),[r]),h=s!=null,g=s?m.indexOf(s.id):-1,_=u?m.indexOf(u.id):-1,v=(0,o.useRef)(m),y=!oS(m,v.current),b=_!==-1&&g===-1||y,x=sS(a);By(()=>{y&&h&&d(m)},[y,m,h,d]),(0,o.useEffect)(()=>{v.current=m},[m]);let S=(0,o.useMemo)(()=>({activeIndex:g,containerId:f,disabled:x,disableTransforms:b,items:m,overIndex:_,useDragOverlay:p,sortedRects:iS(m,l),strategy:i}),[g,f,x.draggable,x.droppable,b,m,_,l,p,i]);return o.createElement(pS.Provider,{value:S},t)}var hS=e=>{let{id:t,items:n,activeIndex:r,overIndex:i}=e;return rS(n,r,i).indexOf(t)},gS=e=>{let{containerId:t,isSorting:n,wasDragging:r,index:i,items:a,newIndex:o,previousItems:s,previousContainerId:c,transition:l}=e;return!l||!r||s!==a&&i===o?!1:n?!0:o!==i&&t===c},_S={duration:200,easing:`ease`},vS=`transform`,yS=nb.Transition.toString({property:vS,duration:0,easing:`linear`}),bS={roleDescription:`sortable`};function xS(e){let{disabled:t,index:n,node:r,rect:i}=e,[a,s]=(0,o.useState)(null),c=(0,o.useRef)(n);return By(()=>{if(!t&&n!==c.current&&r.current){let e=i.current;if(e){let t=Fb(r.current,{ignoreTransform:!0}),n={x:e.left-t.left,y:e.top-t.top,scaleX:e.width/t.width,scaleY:e.height/t.height};(n.x||n.y)&&s(n)}}n!==c.current&&(c.current=n)},[t,n,r,i]),(0,o.useEffect)(()=>{a&&s(null)},[a]),a}function SS(e){let{animateLayoutChanges:t=gS,attributes:n,disabled:r,data:i,getNewIndex:a=hS,id:s,strategy:c,resizeObserverConfig:l,transition:u=_S}=e,{items:d,containerId:f,activeIndex:p,disabled:m,disableTransforms:h,sortedRects:g,overIndex:_,useDragOverlay:v,strategy:y}=(0,o.useContext)(pS),b=CS(r,m),x=d.indexOf(s),S=(0,o.useMemo)(()=>({sortable:{containerId:f,index:x,items:d},...i}),[f,i,x,d]),C=(0,o.useMemo)(()=>d.slice(d.indexOf(s)),[d,s]),{rect:w,node:T,isOver:E,setNodeRef:D}=nS({id:s,data:S,disabled:b.droppable,resizeObserverConfig:{updateMeasurementsFor:C,...l}}),{active:O,activatorEvent:k,activeNodeRect:A,attributes:j,setNodeRef:M,listeners:N,isDragging:ee,over:te,setActivatorNodeRef:ne,transform:P}=Qx({id:s,data:S,attributes:{...bS,...n},disabled:b.draggable}),re=jy(D,M),ie=!!O,ae=ie&&!h&&aS(p)&&aS(_),F=!v&&ee,oe=ae?(F&&ae?P:null)??(c??y)({rects:g,activeNodeRect:A,activeIndex:p,overIndex:_,index:x}):null,se=aS(p)&&aS(_)?a({id:s,items:d,activeIndex:p,overIndex:_}):x,ce=O?.id,I=(0,o.useRef)({activeId:ce,items:d,newIndex:se,containerId:f}),le=d!==I.current.items,ue=t({active:O,containerId:f,isDragging:ee,isSorting:ie,id:s,index:x,items:d,newIndex:I.current.newIndex,previousItems:I.current.items,previousContainerId:I.current.containerId,transition:u,wasDragging:I.current.activeId!=null}),de=xS({disabled:!ue,index:x,node:T,rect:w});return(0,o.useEffect)(()=>{ie&&I.current.newIndex!==se&&(I.current.newIndex=se),f!==I.current.containerId&&(I.current.containerId=f),d!==I.current.items&&(I.current.items=d)},[ie,se,f,d]),(0,o.useEffect)(()=>{if(ce===I.current.activeId)return;if(ce!=null&&I.current.activeId==null){I.current.activeId=ce;return}let e=setTimeout(()=>{I.current.activeId=ce},50);return()=>clearTimeout(e)},[ce]),{active:O,activeIndex:p,attributes:j,data:S,rect:w,index:x,newIndex:se,items:d,isOver:E,isSorting:ie,isDragging:ee,listeners:N,node:T,overIndex:_,over:te,setNodeRef:re,setActivatorNodeRef:ne,setDroppableNodeRef:D,setDraggableNodeRef:M,transform:de??oe,transition:fe()};function fe(){if(de||le&&I.current.newIndex===x)return yS;if(!(F&&!$y(k)||!u)&&(ie||ue))return nb.Transition.toString({...u,property:vS})}}function CS(e,t){return typeof e==`boolean`?{draggable:e,droppable:!1}:{draggable:e?.draggable??t.draggable,droppable:e?.droppable??t.droppable}}function wS(e){if(!e)return!1;let t=e.data.current;return!!(t&&`sortable`in t&&typeof t.sortable==`object`&&`containerId`in t.sortable&&`items`in t.sortable&&`index`in t.sortable)}var TS=[q.Down,q.Right,q.Up,q.Left],ES=(e,t)=>{let{context:{active:n,collisionRect:r,droppableRects:i,droppableContainers:a,over:o,scrollableAncestors:s}}=t;if(TS.includes(e.code)){if(e.preventDefault(),!n||!r)return;let t=[];a.getEnabled().forEach(n=>{if(!n||n!=null&&n.disabled)return;let a=i.get(n.id);if(a)switch(e.code){case q.Down:r.top<a.top&&t.push(n);break;case q.Up:r.top>a.top&&t.push(n);break;case q.Left:r.left>a.left&&t.push(n);break;case q.Right:r.left<a.left&&t.push(n)}});let c=Db({active:n,collisionRect:r,droppableRects:i,droppableContainers:t,pointerCoordinates:null}),l=wb(c,`id`);if(l===o?.id&&c.length>1&&(l=c[1].id),l!=null){let e=a.get(n.id),t=a.get(l),o=t?i.get(t.id):null,c=t?.node.current;if(c&&o&&e&&t){let n=Lb(c).some((e,t)=>s[t]!==e),i=DS(e,t),a=OS(e,t),l=n||!i?{x:0,y:0}:{x:a?r.width-o.width:0,y:a?r.height-o.height:0},u={x:o.left,y:o.top};return l.x&&l.y?u:Zy(u,l)}}}};function DS(e,t){return!wS(e)||!wS(t)?!1:e.data.current.sortable.containerId===t.data.current.sortable.containerId}function OS(e,t){return!wS(e)||!wS(t)||!DS(e,t)?!1:e.data.current.sortable.index<t.data.current.sortable.index}var kS=Date.UTC(2026,9,6,9,41),AS=(e,t)=>{let n=(e^Math.imul(t+2654435769,2246822507))>>>0;return n=Math.imul(n^n>>>16,2246822507),n=Math.imul(n^n>>>13,3266489909),(n^n>>>16)>>>0},jS=(e,t)=>{let n=AS(e,t);return()=>{n=n+1831565813>>>0;let e=n;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}},MS=[{id:`u1`,name:`Sanne M.`,initials:`SM`,hue:250,role:`Admin`},{id:`u2`,name:`Jonas K.`,initials:`JK`,hue:160,role:`Sales`},{id:`u3`,name:`Lieke D.`,initials:`LD`,hue:20,role:`Finance`},{id:`u4`,name:`Tobias R.`,initials:`TR`,hue:310,role:`Warehouse`},{id:`u5`,name:`Imke V.`,initials:`IV`,hue:200,role:`Sales`},{id:`u6`,name:`Marek W.`,initials:`MW`,hue:80,role:`Warehouse`},{id:`u7`,name:`Hanna B.`,initials:`HB`,hue:350,role:`Finance`},{id:`u8`,name:`Daan P.`,initials:`DP`,hue:120,role:`Sales`}],NS=e=>MS.find(t=>t.id===e)??MS[0];MS.filter(e=>e.role===`Sales`);var PS=[[`M8 hex bolt A2, 100 pcs`,`FST`,1890],[`M10 hex nut A2, 100 pcs`,`FST`,1240],[`Stainless washer 8 mm, 250 pcs`,`FST`,990],[`Cable tie 300 mm, 100 pcs`,`ELC`,650],[`Cable gland M20, 25 pcs`,`ELC`,2340],[`Junction box IP65`,`ELC`,1480],[`Hydraulic hose 1/2 in, 5 m`,`HYD`,8650],[`Hydraulic coupling 3/8 in`,`HYD`,1895],[`Pallet wrap 500 mm`,`PKG`,740],[`Corrugated box 400 x 300`,`PKG`,215],[`Bubble wrap roll 50 m`,`PKG`,1990],[`Safety gloves, size L`,`PPE`,395],[`Safety glasses, clear`,`PPE`,450],[`Ear defenders SNR 31`,`PPE`,1295],[`Ball bearing 6204-2RS`,`BRG`,685],[`Taper roller bearing 30205`,`BRG`,1420],[`Timing belt HTD 5M, 600 mm`,`BLT`,2780],[`V-belt SPA 1250`,`BLT`,1360],[`Grease cartridge, 400 g`,`LUB`,920],[`Machine oil ISO 68, 5 l`,`LUB`,3950],[`Angle grinder disc 125 mm, 10 pcs`,`ABR`,1880],[`Drill bit set HSS, 19 pcs`,`TLS`,3490],[`Torque wrench 20-100 Nm`,`TLS`,14900],[`Pneumatic cylinder 40 x 100`,`PNE`,6120],[`Air hose PU 8 mm, 20 m`,`PNE`,2475],[`LED panel 600 x 600, 40 W`,`LGT`,3290],[`Pallet label roll 100 x 150`,`LBL`,1175],[`Thermal printer ribbon`,`LBL`,890],[`Euro pallet EPAL, used`,`PLT`,1150],[`Roll container, galvanised`,`PLT`,9800]];PS.length;var FS=e=>{let[t,n,r]=PS[e%PS.length],i=e%PS.length;return{id:`P-${200+i}`,sku:`${n}-${String(1e3+i*7).padStart(4,`0`)}`,name:t,category:n,priceCents:r}},IS=e=>e.quantity*e.unitPriceCents,LS=(e,t=.21)=>{let n=e.reduce((e,t)=>e+IS(t),0),r=Math.round(n*t);return{subtotalCents:n,vatCents:r,totalCents:n+r}},RS=864e5,zS=e=>Array.from({length:e},(t,n)=>{let r=kS-(e-1-n)*RS,i=new Date(r).getUTCDay();return{at:r,count:Math.round((i===0||i===6?120:410)*(.8+jS(71,n)()*.45)*(1+n/e/3))}}),BS=e=>{if(e===`day`)return zS(30);let t=zS(84);return Array.from({length:12},(e,n)=>{let r=t.slice(n*7,n*7+7);return{at:r[0].at,count:r.reduce((e,t)=>e+t.count,0)}})},VS=`grid grid-cols-[28px_minmax(0,1fr)_88px_112px_112px_32px] items-center gap-2 pointer-coarse:grid-cols-[44px_minmax(0,1fr)_88px_112px_112px_44px]`,HS=({items:e,label:t})=>{let[n,r]=(0,o.useState)(!1),i=(0,o.useRef)(null);return(0,o.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)(Ve,{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 text-[13px] 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:z(`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))})]})},US=({value:e,onCommit:t,format:n,parse:r,label:i,width:a=`w-full`})=>{let[s,c]=(0,o.useState)(null);return(0,B.jsx)(`input`,{"aria-label":i,inputMode:`decimal`,value:s??n(e),onFocus:e=>e.currentTarget.select(),onChange:e=>c(e.target.value),onBlur:()=>{if(s===null)return;let e=r(s);c(null),Number.isFinite(e)&&e>=0&&t(e)},onKeyDown:e=>e.key===`Enter`&&e.currentTarget.blur(),className:z(`h-7 rounded-md border border-transparent bg-transparent px-2 text-right text-[13px] tabular-nums text-foreground outline-none hover:border-border-strong focus:border-primary focus:bg-background focus:ring-2 focus:ring-primary/20`,a)})},WS=e=>Math.round(Number(e.replace(`,`,`.`).replace(/[^0-9.]/g,``))*100),GS=({line:e,position:t,count:n,reorderable:r,editable:i,onChange:a,onRemove:o,onMove:s})=>{let{attributes:c,listeners:l,setNodeRef:u,setActivatorNodeRef:d,transform:f,transition:p,isDragging:m}=SS({id:e.id,disabled:!r}),h=[...r?[{label:`Move up`,disabled:t===0,onSelect:()=>s(t-1)},{label:`Move down`,disabled:t===n-1,onSelect:()=>s(t+1)}]:[],...i?[{label:`Remove line`,destructive:!0,onSelect:o}]:[]];return(0,B.jsxs)(`div`,{ref:u,"data-line-id":e.id,style:{transform:f?`translate3d(0, ${f.y}px, 0)`:void 0,transition:p},className:z(`group relative border-b border-border bg-background px-2 py-1 last:border-b-0 hover:bg-surface`,VS,m&&`z-10 bg-surface opacity-80 shadow-pop`),children:[r?(0,B.jsx)(`button`,{ref:d,type:`button`,"aria-label":`Drag to reorder ${e.description}`,...c,...l,style:{touchAction:`none`},className:`flex size-7 cursor-grab items-center justify-center rounded text-faint-foreground opacity-60 hover:bg-muted hover:opacity-100 focus-visible:opacity-100 active:cursor-grabbing pointer-coarse:size-11`,children:(0,B.jsx)(tee,{className:`size-4`})}):(0,B.jsx)(`span`,{}),(0,B.jsxs)(`div`,{className:`min-w-0`,children:[(0,B.jsx)(`p`,{className:`truncate text-[13px] text-foreground`,children:e.description}),(0,B.jsx)(`p`,{className:`font-mono text-[11px] text-faint-foreground`,children:e.productId})]}),i?(0,B.jsx)(US,{label:`Quantity`,value:e.quantity,format:String,parse:e=>Math.round(Number(e)),onCommit:e=>a({quantity:e})}):(0,B.jsx)(`span`,{className:`px-2 text-right text-[13px] tabular-nums`,children:e.quantity}),i?(0,B.jsx)(US,{label:`Unit price`,value:e.unitPriceCents,format:e=>(e/100).toFixed(2),parse:WS,onCommit:e=>a({unitPriceCents:e})}):(0,B.jsx)(`span`,{className:`px-2 text-right text-[13px] tabular-nums`,children:(e.unitPriceCents/100).toFixed(2)}),(0,B.jsx)(`span`,{className:`px-2 text-right text-[13px] font-medium tabular-nums text-foreground`,children:Of(IS(e))}),h.length>0?(0,B.jsx)(HS,{label:`Actions for ${e.description}`,items:h}):(0,B.jsx)(`span`,{})]})},KS=(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},qS=({lines:e,vatRate:t})=>{let n=LS(e,t);return(0,B.jsxs)(`dl`,{className:`ml-auto grid w-64 grid-cols-[1fr_auto] gap-x-6 gap-y-1 px-2 pt-3 text-[13px] tabular-nums`,children:[(0,B.jsx)(`dt`,{className:`text-muted-foreground`,children:`Subtotal`}),(0,B.jsx)(`dd`,{className:`text-right text-foreground`,children:Of(n.subtotalCents)}),(0,B.jsxs)(`dt`,{className:`text-muted-foreground`,children:[`VAT `,Math.round(t*100),`%`]}),(0,B.jsx)(`dd`,{className:`text-right text-foreground`,children:Of(n.vatCents)}),(0,B.jsx)(`dt`,{className:`mt-1 border-t border-border pt-2 font-semibold text-foreground`,children:`Total`}),(0,B.jsx)(`dd`,{className:`mt-1 border-t border-border pt-2 text-right text-[15px] font-semibold text-foreground`,children:Of(n.totalCents)})]})},JS=`px-2 text-[11px] font-medium uppercase tracking-wide text-muted-foreground`,YS=`To pick up a line, press space or enter on its drag handle. Use the up and down arrow keys to move it, space or enter to drop it, and escape to cancel. The row menu also has Move up and Move down.`,XS=e=>{let t=t=>e.find(e=>e.id===t)?.description??`line`,n=t=>e.findIndex(e=>e.id===t)+1;return{onDragStart:({active:r})=>`Picked up ${t(r.id)}, line ${n(r.id)} of ${e.length}.`,onDragOver:({active:r,over:i})=>i?`${t(r.id)} is over line ${n(i.id)} of ${e.length}.`:void 0,onDragEnd:({active:r,over:i})=>i?`${t(r.id)} was dropped at line ${n(i.id)} of ${e.length}.`:`${t(r.id)} was dropped where it started.`,onDragCancel:({active:e})=>`Moving ${t(e.id)} was cancelled. It is back at line ${n(e.id)}.`}},ZS=({lines:e,onChange:t,onReorder:n,vatRate:r=.21,readOnly:i,reorderable:a=!i})=>{let o=vb(_b(ax,{activationConstraint:{distance:4}}),_b(sx,{activationConstraint:{delay:250,tolerance:5}}),_b($b,{coordinateGetter:ES})),s=(r,i)=>{let a=e[r];!a||i<0||i>=e.length||r===i||(n??(e=>t(e)))(KS(e,r,i),{id:a.id,from:r,to:i})};return(0,B.jsxs)(`div`,{children:[(0,B.jsxs)(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:[(0,B.jsxs)(`div`,{className:`${VS} border-b border-border bg-surface px-2 py-2`,children:[(0,B.jsx)(`span`,{}),(0,B.jsx)(`span`,{className:JS,children:`Item`}),(0,B.jsx)(`span`,{className:`${JS} text-right`,children:`Qty`}),(0,B.jsx)(`span`,{className:`${JS} text-right`,children:`Unit price`}),(0,B.jsx)(`span`,{className:`${JS} text-right`,children:`Line total`}),(0,B.jsx)(`span`,{})]}),(0,B.jsx)(Jx,{sensors:o,collisionDetection:Eb,onDragEnd:({active:t,over:n})=>{n&&t.id!==n.id&&s(e.findIndex(e=>e.id===t.id),e.findIndex(e=>e.id===n.id))},accessibility:{announcements:XS(e),screenReaderInstructions:{draggable:YS}},children:(0,B.jsx)(mS,{items:e.map(e=>e.id),strategy:uS,children:e.map((n,r)=>(0,B.jsx)(GS,{line:n,position:r,count:e.length,reorderable:a,editable:!i,onChange:r=>t(e.map(e=>e.id===n.id?{...e,...r}:e)),onRemove:()=>t(e.filter(e=>e.id!==n.id)),onMove:e=>s(r,e)},n.id))})}),!i&&(0,B.jsx)(`div`,{className:`border-t border-border bg-surface px-2 py-1.5`,children:(0,B.jsxs)(H,{variant:`ghost`,size:`sm`,onClick:()=>{let n=FS(e.length*3+1);t([...e,{id:`new-${e.length}-${n.id}`,productId:n.id,description:n.name,quantity:1,unitPriceCents:n.priceCents}])},children:[(0,B.jsx)(Lt,{className:`size-3.5`}),`Add line`]})})]}),(0,B.jsx)(qS,{lines:e,vatRate:r})]})},QS=({label:e,required:t,help:n,example:r,error:i,conflict:a,wide:o,children:s})=>(0,B.jsxs)(`div`,{className:o?`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`,{className:`text-[13px] font-medium text-foreground`,children:[e,t&&(0,B.jsx)(`span`,{className:`ml-0.5 text-danger-text`,"aria-label":`required`,children:`*`})]}),a&&(0,B.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-warning-text`,title:`${a.user.name} saved a different value`,children:[(0,B.jsx)(xn,{className:`size-3.5`}),(0,B.jsx)(md,{initials:a.user.initials,hue:a.user.hue,size:`xs`})]})]}),s,n&&(0,B.jsx)(`p`,{className:`mt-1.5 text-xs text-muted-foreground`,children:n}),r&&(0,B.jsxs)(`p`,{className:`mt-0.5 text-xs text-faint-foreground`,children:[`Example: `,r]}),i&&(0,B.jsx)(`p`,{className:`mt-1.5 text-xs font-medium text-danger-text`,children:i}),a&&(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-xs text-warning-text`,children:[(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`strong`,{children:a.user.name}),` saved this `,a.ago,`: `,(0,B.jsx)(`strong`,{children:a.theirValue})]}),(0,B.jsxs)(`span`,{className:`flex gap-1.5`,children:[(0,B.jsx)(H,{size:`sm`,onClick:a.onKeepMine,children:`Keep mine`}),(0,B.jsx)(H,{size:`sm`,onClick:a.onUseTheirs,children:`Use theirs`})]})]})]}),$S=({title:e,help:t,actions:n,children:r})=>{let i=(0,B.jsx)(`h2`,{className:`text-[15px] font-semibold text-foreground`,children:e});return(0,B.jsxs)(`section`,{className:`py-8 first:pt-8`,children:[n?(0,B.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-x-4 gap-y-2`,children:[i,n]}):i,t&&(0,B.jsx)(`p`,{className:`mt-1 max-w-xl text-[13px] leading-relaxed text-muted-foreground`,children:t}),(0,B.jsx)(`div`,{className:`mt-5`,children:r})]})},eC=({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:`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})=>(0,B.jsx)(`li`,{children:(0,B.jsxs)(`button`,{type:`button`,onClick:r,disabled:!!i||a,title:i,className:`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`,children:[(0,B.jsx)(n,{className:`size-4 shrink-0 text-muted-foreground md:mt-0.5`}),(0,B.jsxs)(`span`,{children:[(0,B.jsx)(`span`,{className:`block text-[13px] font-medium 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})]})]})},e))})]}),tC=({rows:e})=>(0,B.jsx)(`dl`,{className:`grid grid-cols-[auto_1fr] gap-x-4 gap-y-2 text-[13px]`,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`,{className:`text-right tabular-nums text-foreground`,children:e.value})]},e.label))}),nC=({records:e,onNavigate:t})=>(0,B.jsx)(`ul`,{className:`-mx-2`,children:e.map(e=>(0,B.jsx)(`li`,{children:(0,B.jsxs)(`a`,{href:e.href??`#`,onClick:n=>{n.preventDefault(),e.href&&t?.(e.href)},className:`group flex items-center justify-between gap-3 rounded-md px-2 py-2 hover:bg-muted`,children:[(0,B.jsxs)(`span`,{className:`min-w-0`,children:[(0,B.jsx)(`span`,{className:`block text-[11px] uppercase tracking-wide text-faint-foreground`,children:e.kind}),(0,B.jsx)(`span`,{className:`block truncate text-[13px] font-medium text-primary-text`,children:e.label}),e.meta&&(0,B.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:e.meta})]}),(0,B.jsx)(_e,{className:`size-4 shrink-0 text-faint-foreground group-hover:text-foreground`})]})},e.label))}),rC=({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]}),iC=({title:e,rows:t})=>t.length===0?null:(0,B.jsx)(rC,{title:e,children:(0,B.jsx)(tC,{rows:t})}),aC=({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:[(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e}),(0,B.jsxs)(`div`,{className:`mt-1 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}),(0,B.jsx)(Cd,{tone:n.tone,children:n.label})]}),(0,B.jsx)(`p`,{className:`mt-1.5 text-xs text-muted-foreground`,children:r.name?(0,B.jsxs)(B.Fragment,{children:[`Last edited by `,(0,B.jsx)(`span`,{className:`font-medium text-foreground`,children:r.name}),` `,r.ago]}):(0,B.jsxs)(B.Fragment,{children:[`Last updated `,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)(hd,{people:i,size:`md`}),i.length,` viewing`]}),a]})]}),oC=({noun:e,collection:t,sections:n,saving:r,message:i,onSubmit:a,onCancel:o})=>(0,B.jsx)(`form`,{className:`flex-1`,onSubmit:e=>{e.preventDefault(),a()},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:[(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:t}),(0,B.jsxs)(`h1`,{className:`mt-1 text-2xl font-semibold tracking-tight`,children:[`New `,e.toLowerCase()]})]}),(0,B.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,B.jsx)(H,{className:`max-sm:min-h-11`,onClick:o,children:`Cancel`}),(0,B.jsxs)(H,{variant:`primary`,type:`submit`,className:`max-sm:min-h-11 max-sm:flex-1`,loading:r,children:[`Create `,e.toLowerCase()]})]})]}),i&&(0,B.jsx)(`div`,{className:`mt-4`,children:(0,B.jsx)(ny,{title:`Not created`,error:Error(i)})}),(0,B.jsx)(`div`,{className:`divide-y divide-border`,children:n.map(e=>(0,B.jsx)($S,{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)(QS,{label:e.label,required:e.required,help:e.help,error:e.error,wide:e.wide,children:e.editor},e.name))})},e.title))})]})}),sC=e=>typeof e==`object`&&!!e&&`key`in e,cC=(e,t)=>t.name!==e.tenant&&!t.readOnly&&(t.type===`relation`||Xv(t)),lC=(e,t)=>{let n=Object.values(e.fields).filter(t=>cC(e,t)).map(e=>e.name),r=new Set,i=(t?.layout??[]).flatMap(e=>{if(e.kind!==`section`)return[];let t=e.fields.filter(e=>n.includes(e)&&!r.has(e));return t.forEach(e=>r.add(e)),t.length>0?[{title:e.title,help:e.help,fields:t}]:[]}),a=n.filter(e=>!r.has(e));return a.length===0?i:[...i,{title:i.length===0?`Details`:`Other fields`,fields:a}]},uC=(e,t)=>(e?.primaryKey.length===1?e.fields[e.primaryKey[0]]?.type:void 0)===`integer`?Number(t):t,dC=(e,t,n)=>Object.fromEntries(Object.entries(n).flatMap(([n,r])=>{let i=e.fields[n];return i?sC(r)?[[n,uC(t[i.relation?.resource??``],r.key)]]:i.type===`boolean`?[[n,!!r]]:i.type===`file`?r?[[n,Zv(i,r)]]:[]:String(r).trim()===``?[]:[[n,Zv(i,r)]]:[]})),fC=e=>!e.nullable&&!e.default&&e.type!==`boolean`,pC=(e,t)=>e.type===`relation`?{key:t,label:t}:e.type===`boolean`?t===`true`:t,mC=(e,t,n={})=>Object.fromEntries(t.flatMap(t=>t.fields.flatMap(t=>{let r=e.fields[t];if(Object.hasOwn(n,t))return[[t,pC(r,n[t])]];let i=r.default;return!i||!(`value`in i)||i.value===null||i.value===void 0?[]:[[t,typeof i.value==`boolean`?i.value:String(i.value)]]}))),hC=e=>!!(e.default&&`db`in e.default),gC=(e,t)=>Object.fromEntries(Object.entries(e).filter(([e])=>e!==t)),_C=({resource:e,values:t})=>{let n=K(),r=n.resources[e],i=Uv(e);return r?Ey(i,`create`)?(0,B.jsx)(vC,{resource:e,values:t}):(0,B.jsxs)(Bv,{title:`Not allowed`,children:[`You cannot create `,n.views[e]?.names?.plural.toLowerCase()??e,`.`]}):(0,B.jsxs)(Bv,{title:`Not found`,children:[`There is no resource called `,e,`.`]})},vC=({resource:e,values:t})=>{let n=K(),r=n.resources[e],i=n.views[e],a=W(),s=pm(),{go:c}=Wv(),l=i?.names?.singular??G(e),u=Ay(i?.saveFeedback??`toast`,`New ${l.toLowerCase()}`),d=lC(r,i),[f,p]=(0,o.useState)(()=>mC(r,d,t)),[m,h]=(0,o.useState)({});(0,o.useEffect)(()=>{for(let[e,i]of Object.entries(t??{})){let t=n.resources[r.fields[e]?.relation?.resource??``];t&&R_(s,a,t,[i],n.views[t.name]).then(t=>{let n=t.get(i);n&&p(t=>sC(t[e])&&t[e].key===i?{...t,[e]:{key:i,label:n}}:t)})}},[t,n,r,a,s]);let g=(e,t)=>{h(t=>gC(t,e)),p(n=>({...n,[e]:t}))},_=()=>u.run(async()=>{let t;try{t=await a.create(e,dC(r,n.resources,f))}catch(e){throw vs(e)&&h(Object.fromEntries(e.errors.flatMap(e=>e.field?[[e.field,e.message]]:[]))),e}for(let t of[`page`,`list`,`first-page`,`map`,`facets`,`series`])s.invalidateQueries({queryKey:[t,e]});c({kind:`record`,resource:e,key:Mg(r,t.record)},{replace:!0})}),v=d.map(e=>({title:e.title,help:e.help,fields:e.fields.map(e=>{let t=r.fields[e],a=f[e],o=t.relation?n.resources[t.relation.resource]:void 0;return{name:e,label:i?.fields[e]?.label??G(e),help:i?.fields[e]?.help,required:fC(t),error:m[e],wide:!!i?.fields[e]?.multiline,editor:(0,B.jsx)(Ty,{field:t,hints:i?.fields[e],value:sC(a)?a.key:a??(t.type!==`boolean`&&``),stored:void 0,relationLabel:sC(a)?a.label:void 0,placeholder:hC(t)?`Set by the database`:void 0,relationPicker:o?{target:o,view:n.views[o.name]}:void 0,invalid:!!m[e],resource:r.name,onChange:t=>g(e,t)})}})}));return(0,B.jsx)(oC,{noun:l,collection:i?.names?.plural??G(e),sections:v,saving:u.phase===`saving`,message:u.message,onSubmit:()=>void _(),onCancel:()=>c({kind:`list`,resource:e})})};function yC(e){return bC(e)||typeof e==`function`||xC(e)}function bC(e){return typeof e==`function`&&(()=>{let t=Object.getPrototypeOf(e);return t.prototype&&t.prototype.isReactComponent})()}function xC(e){return typeof e==`object`&&typeof e.$$typeof==`symbol`&&[`react.memo`,`react.forward_ref`].includes(e.$$typeof.description)}function SC(e,t){return e==null?null:yC(e)?o.createElement(e,t):e}function CC(e){if(`cell`in e&&e.cell){let t=e.cell,n=t.column.columnDef,r=t,i=n;return r.getIsAggregated?.()?SC(i.aggregatedCell??n.cell,t.getContext()):r.getIsPlaceholder?.()?null:SC(n.cell,t.getContext())}return`header`in e&&e.header?SC(e.header.column.columnDef.header,e.header.getContext()):`footer`in e&&e.footer?SC(e.footer.column.columnDef.footer,e.footer.getContext()):null}function wC({update:e,notify:t,unwatched:n}){return{link:r,unlink:i,propagate:a,checkDirty:o,shallowPropagate:s};function r(e,t,n){let r=t.depsTail;if(r!==void 0&&r.dep===e)return;let i=r===void 0?t.deps:r.nextDep;if(i!==void 0&&i.dep===e){i.version=n,t.depsTail=i;return}let a=e.subsTail;if(a!==void 0&&a.version===n&&a.sub===t)return;let o=t.depsTail=e.subsTail={version:n,dep:e,sub:t,prevDep:r,nextDep:i,prevSub:a,nextSub:void 0};i!==void 0&&(i.prevDep=o),r===void 0?t.deps=o:r.nextDep=o,a===void 0?e.subs=o:a.nextSub=o}function i(e,t=e.sub){let r=e.dep,i=e.prevDep,a=e.nextDep,o=e.nextSub,s=e.prevSub;return a===void 0?t.depsTail=i:a.prevDep=i,i===void 0?t.deps=a:i.nextDep=a,o===void 0?r.subsTail=s:o.prevSub=s,s===void 0?(r.subs=o)===void 0&&n(r):s.nextSub=o,a}function a(e){let n=e.nextSub,r;top:do{let i=e.sub,a=i.flags;if(a&60?a&12?a&4?!(a&48)&&c(e,i)?(i.flags=a|40,a&=1):a=0:i.flags=a&-9|32:a=0:i.flags=a|32,a&2&&t(i),a&1){let t=i.subs;if(t!==void 0){let i=(e=t).nextSub;i!==void 0&&(r={value:n,prev:r},n=i);continue}}if((e=n)!==void 0){n=e.nextSub;continue}for(;r!==void 0;)if(e=r.value,r=r.prev,e!==void 0){n=e.nextSub;continue top}break}while(1)}function o(t,n){let r,i=0,a=!1;top:do{let o=t.dep,c=o.flags;if(n.flags&16)a=!0;else if((c&17)==17){if(e(o)){let e=o.subs;e.nextSub!==void 0&&s(e),a=!0}}else if((c&33)==33){(t.nextSub!==void 0||t.prevSub!==void 0)&&(r={value:t,prev:r}),t=o.deps,n=o,++i;continue}if(!a){let e=t.nextDep;if(e!==void 0){t=e;continue}}for(;i--;){let i=n.subs,o=i.nextSub!==void 0;if(o?(t=r.value,r=r.prev):t=i,a){if(e(n)){o&&s(i),n=t.sub;continue}a=!1}else n.flags&=-33;n=t.sub;let c=t.nextDep;if(c!==void 0){t=c;continue top}}return a}while(1)}function s(e){do{let n=e.sub,r=n.flags;(r&48)==32&&(n.flags=r|16,(r&6)==2&&t(n))}while((e=e.nextSub)!==void 0)}function c(e,t){let n=t.depsTail;for(;n!==void 0;){if(n===e)return!0;n=n.prevDep}return!1}}function TC(e,t,n){let r=typeof e==`object`,i=r?e:void 0;return{next:(r?e.next:e)?.bind(i),error:(r?e.error:t)?.bind(i),complete:(r?e.complete:n)?.bind(i)}}var EC=[],DC=0,{link:OC,unlink:kC,propagate:AC,checkDirty:jC,shallowPropagate:MC}=wC({update(e){return e._update()},notify(e){EC[PC++]=e,e.flags&=-3},unwatched(e){e.depsTail!==void 0&&(e.depsTail=void 0,e.flags=17,RC(e))}}),NC=0,PC=0,FC,IC=0;function LC(e){try{++IC,e()}finally{--IC||zC()}}function RC(e){let t=e.depsTail,n=t===void 0?e.deps:t.nextDep;for(;n!==void 0;)n=kC(n,e)}function zC(){if(!(IC>0)){for(;NC<PC;){let e=EC[NC];EC[NC++]=void 0,e.notify()}NC=0,PC=0}}function BC(e,t){let n=typeof e==`function`,r=e,i={_snapshot:n?void 0:e,subs:void 0,subsTail:void 0,deps:void 0,depsTail:void 0,flags:+!n,get(){return FC!==void 0&&OC(i,FC,DC),i._snapshot},subscribe(e){let t=TC(e),n={current:!1},r=VC(()=>{i.get(),n.current?(FC=void 0,t.next?.(i._snapshot)):n.current=!0});return{unsubscribe:()=>{r.stop()}}},_update(e){let a=FC,o=t?.compare??Object.is;if(n)FC=i,++DC,i.depsTail=void 0;else if(e===void 0)return!1;n&&(i.flags=5);try{let t=i._snapshot,a=typeof e==`function`?e(t):e===void 0&&n?r(t):e;return t===void 0||!o(t,a)?(i._snapshot=a,!0):!1}finally{FC=a,n&&(i.flags&=-5),RC(i)}}};return n?(i.flags=17,i.get=function(){let e=i.flags;if(e&16||e&32&&jC(i.deps,i)){if(i._update()){let e=i.subs;e!==void 0&&MC(e)}}else e&32&&(i.flags=e&-33);return FC!==void 0&&OC(i,FC,DC),i._snapshot}):i.set=function(e){if(i._update(e)){let e=i.subs;e!==void 0&&(AC(e),MC(e),zC())}},i}function VC(e){let t=()=>{let t=FC;FC=n,++DC,n.depsTail=void 0,n.flags=6;try{return e()}finally{FC=t,n.flags&=-5,RC(n)}},n={deps:void 0,depsTail:void 0,subs:void 0,subsTail:void 0,flags:6,notify(){let e=this.flags;e&16||e&32&&jC(this.deps,this)?t():this.flags=2},stop(){this.flags=0,this.depsTail=void 0,RC(this)}};return t(),n}function HC(e,t){if(Object.is(e,t))return!0;if(typeof e!=`object`||!e||typeof t!=`object`||!t)return!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(let[n,r]of e)if(!t.has(n)||!Object.is(r,t.get(n)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}if(e instanceof Date&&t instanceof Date)return e.getTime()===t.getTime();let n=UC(e);if(n.length!==UC(t).length)return!1;for(let r=0;r<n.length;r++)if(!Object.prototype.hasOwnProperty.call(t,n[r])||!Object.is(e[n[r]],t[n[r]]))return!1;return!0}function UC(e){return Object.keys(e).concat(Object.getOwnPropertySymbols(e))}var WC=n((e=>{var t=r();function n(e,t){return e===t&&(e!==0||1/e==1/t)||e!==e&&t!==t}var i=typeof Object.is==`function`?Object.is:n,a=t.useState,o=t.useEffect,s=t.useLayoutEffect,c=t.useDebugValue;function l(e,t){var n=t(),r=a({inst:{value:n,getSnapshot:t}}),i=r[0].inst,l=r[1];return s(function(){i.value=n,i.getSnapshot=t,u(i)&&l({inst:i})},[e,n,t]),o(function(){return u(i)&&l({inst:i}),e(function(){u(i)&&l({inst:i})})},[e]),c(n),n}function u(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!i(e,n)}catch{return!0}}function d(e,t){return t()}var f=typeof window>`u`||window.document===void 0||window.document.createElement===void 0?d:l;e.useSyncExternalStore=t.useSyncExternalStore===void 0?f:t.useSyncExternalStore})),GC=n(((e,t)=>{t.exports=WC()})),KC=n((e=>{var t=r(),n=GC();function i(e,t){return e===t&&(e!==0||1/e==1/t)||e!==e&&t!==t}var a=typeof Object.is==`function`?Object.is:i,o=n.useSyncExternalStore,s=t.useRef,c=t.useEffect,l=t.useMemo,u=t.useDebugValue;e.useSyncExternalStoreWithSelector=function(e,t,n,r,i){var d=s(null);if(d.current===null){var f={hasValue:!1,value:null};d.current=f}else f=d.current;d=l(function(){function e(e){if(!o){if(o=!0,s=e,e=r(e),i!==void 0&&f.hasValue){var t=f.value;if(i(t,e))return c=t}return c=e}if(t=c,a(s,e))return t;var n=r(e);return i!==void 0&&i(t,n)?(s=e,t):(s=e,c=n)}var o=!1,s,c,l=n===void 0?null:n;return[function(){return e(t())},l===null?void 0:function(){return e(l())}]},[t,n,r,i]);var p=o(e,d[0],d[1]);return c(function(){f.hasValue=!0,f.value=p},[p]),u(p),p}})),qC=n(((e,t)=>{t.exports=KC()}))();function JC(e,t){return e===t}function YC(e,t=e=>e,n){let r=n?.compare??JC,i=(0,o.useCallback)(t=>{let{unsubscribe:n}=e.subscribe(t);return n},[e]),a=(0,o.useCallback)(()=>e.get(),[e]);return(0,qC.useSyncExternalStoreWithSelector)(i,a,a,t,r)}function XC(e){let t=YC(e.source,e.selector,{compare:HC});return typeof e.children==`function`?e.children(t):e.children}function ZC(e){let t=e;return Object.defineProperty(e,"state",{get(){return e.get()}}),`set`in e&&(t.setState=e.set.bind(e)),t}function QC(e){let{createAtom:t,batch:n}=e,r=t(0);return{createOptionsStore:!1,wrapExternalAtoms:!1,addSubscription:()=>{throw Error(`Feature not supported in current reactivity implementation`)},unmount:()=>{throw Error(`Feature not supported in current reactivity implementation`)},schedule:e.schedule??(e=>queueMicrotask(e)),batch:n,untrack:e=>e(),createReadonlyAtom:(e,n)=>{let i=n?.compare??Object.is,a=!1,o,s=()=>{let t=e();return(!a||!i(o,t))&&(o=t,a=!0),o},c=t(()=>(r.get(),s()),{compare:i});return{get:s,subscribe:c.subscribe.bind(c)}},createWritableAtom:(e,n)=>t(e,{compare:n?.compare}),commit:()=>{r.set(e=>e+1)}}}function $C(e,t=Object.is){let n=!1,r;return{get:e.get,markCommitted:e=>{r=e,n=!0},subscribe:i=>e.subscribe(e=>{(!n||!t(r,e))&&i(e)})}}function ew(){return QC({createAtom:BC,batch:LC})}function tw(e,t){return typeof e==`function`?e(t):e}function nw(e){if(Array.isArray(e))return e.map(nw);if(e&&typeof e==`object`){let t=Object.getPrototypeOf(e);if(t!==Object.prototype&&t!==null)return e;let n=t===null?iw():{},r=Object.keys(e);for(let t=0;t<r.length;t++){let i=r[t];Object.defineProperty(n,i,{configurable:!0,enumerable:!0,value:nw(e[i]),writable:!0})}return n}return e}function rw(e,t){let n=Object.keys(t),r=e;for(let e=0;e<n.length;e++){let i=n[e];!i.startsWith(`_memo_`)&&i!==`_cellsCache`&&(r[i]=t[i])}return e}function iw(){return Object.create(null)}function aw(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function ow(e,t){return n=>{(t.options.atoms?.[e]??t.baseAtoms[e]).set(e=>tw(n,e))}}function sw(e){if(typeof e!=`object`||!e)return!1;if(Array.isArray(e))return!0;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function cw(e){return Reflect.ownKeys(e).filter(t=>Object.prototype.propertyIsEnumerable.call(e,t))}var lw=3;function uw(e,t){return dw(e,t,lw)}function dw(e,t,n){if(Object.is(e,t))return!0;if(n<=0||!sw(e)||!sw(t)||(Array.isArray(e)||Array.isArray(t))&&(!Array.isArray(e)||!Array.isArray(t)||e.length!==t.length))return!1;let r=cw(e),i=cw(t);if(r.length!==i.length)return!1;let a=e,o=t;for(let e=0;e<r.length;e++){let i=r[e];if(!Object.prototype.propertyIsEnumerable.call(t,i)||!dw(a[i],o[i],n-1))return!1}return!0}function fw(e,t,n,r=uw){let i=`on${t.charAt(0).toUpperCase()}${t.slice(1)}Change`,a=e.options[i];a&&a(e=>{let t=tw(n,e);return r(e,t)?e:t})}function pw(e){return e instanceof Function}function mw(e,t){let n=[],r=e=>{e.forEach(e=>{n.push(e);let i=t(e);i.length&&r(i)})};return r(e),n}var hw=({fn:e,memoDeps:t,onAfterCompare:n,onAfterUpdate:r,onBeforeCompare:i,onBeforeUpdate:a})=>{let o=[],s;return c=>{i?.();let l=t?.(c),u=!l||l.length!==o?.length;if(!u&&l){for(let e=0;e<l.length;e++)if(l[e]!==o[e]){u=!0;break}}return n?.(u),u?(o=l,a?.(),s=e(...l??[]),r?.(s),s):s}};function gw(e){let t=!1;return()=>{if(!t){t=!0;return}e()}}function _w({feature:e,fnName:t,objectId:n,onAfterUpdate:r,table:i,...a}){let o=()=>{if(!r)return;let{schedule:e,untrack:t}=i._reactivity;e(()=>t(()=>r()))},s={onAfterUpdate:()=>{o()}};return hw({...a,...s})}function vw(e,t=`_`){let[n,r]=e.split(t);return{fnKey:r,fnName:`${n}.${r}`,parentName:n}}function yw(e,t,n){for(let[r,{fn:i,memoDeps:a}]of Object.entries(n)){let{fnKey:n,fnName:o}=vw(r);t[n]=a?_w({memoDeps:a,fn:i,fnName:o,table:t,feature:e}):i}}function bw(e,t,n,r){for(let[i,{fn:a,memoDeps:o}]of Object.entries(r)){let{fnKey:r,fnName:s}=vw(i);if(o){let i=`_memo_${r}`;t[r]=function(...t){if(!this[i]){let t=this;this[i]=_w({memoDeps:e=>o(t,e),fn:(...e)=>a(t,...e),fnName:s,objectId:t.id,table:n,feature:e})}return this[i](...t)}}else t[r]=function(...e){return a(this,...e)}}}function xw(e,t,n,...r){return e[t]?.(...r)??n(e,...r)}function Sw(e){return e.row.getValue(e.column.id)}function Cw(e){return e.getValue()??e.table.options.renderFallbackValue}function ww(e){return{table:e.table,column:e.column,row:e.row,cell:e,getValue:()=>e.getValue(),renderValue:()=>e.renderValue()}}var Tw={assignCellPrototype:(e,t)=>{bw(`coreCellsFeature`,e,t,{cell_getValue:{fn:e=>Sw(e)},cell_renderValue:{fn:e=>Cw(e)},cell_getContext:{fn:e=>ww(e),memoDeps:e=>[e]}})}};function Ew(e){if(!e._headerPrototype){e._headerPrototype={table:e};let t=Object.values(e._features);for(let n=0;n<t.length;n++)t[n].assignHeaderPrototype?.(e._headerPrototype,e)}return e._headerPrototype}function Dw(e,t,n){let r=Ew(e),i=Object.create(r);i.colSpan=0,i.column=t,i.depth=n.depth,i.headerGroup=null,i.id=n.id??t.id,i.index=n.index,i.isPlaceholder=!!n.isPlaceholder,i.placeholderId=n.placeholderId,i.rowSpan=0,i.subHeaders=[];let a=e._headerInstanceInitFns;for(let e=0;e<a.length;e++)a[e](i);return i}function Ow(){return{start:[],end:[]}}function kw(e){let t=e.table.atoms.columnVisibility?.get();if(!t)return!0;let n=e.columns;return n.length?n.some(e=>xw(e,`getIsVisible`,kw)):(aw(t,e.id)?t[e.id]:void 0)??!0}function Aw(e){return e.getAllLeafColumns().filter(e=>xw(e,`getIsVisible`,kw))}function jw(e,t=1){let n=t;for(let r=0;r<e.length;r++){let i=e[r];xw(i,`getIsVisible`,kw)&&i.columns.length&&(n=Math.max(n,jw(i.columns,t+1)))}return n}function Mw(e,t){return e?`${e}_${t}`:String(t)}function Nw(e,t,n,r){let i=e??``;return t&&(i=i?`${i}_${t}`:String(t)),n&&(i=i?`${i}_${n}`:n),r&&(i=i?`${i}_${r}`:r),i}function Pw(e,t){let n=0;for(let r=0;r<e.length;r++)e[r].column===t&&n++;return n}function Fw(e,t,n,r,i,a){let o={depth:t,id:Mw(r,t),headers:[]},s=[];for(let i=0;i<e.length;i++){if(!(i in e))continue;let a=e[i],c=s[s.length-1],l=a.column.depth===o.depth,u,d=!1;if(l&&a.column.parent?u=a.column.parent:(u=a.column,d=!0),c&&c.column===u)c.subHeaders.push(a);else{let e=Dw(n,u,{id:Nw(r,t,u.id,a.id),isPlaceholder:d,placeholderId:d?String(Pw(s,u)):void 0,depth:t,index:s.length});e.subHeaders.push(a),s.push(e)}o.headers.push(a),a.headerGroup=o}for(let e=0;e<a.length;e++)a[e](o);i.push(o),t>0&&Fw(s,t-1,n,r,i,a)}function Iw(e){for(let t=0;t<e.length;t++){let n=e[t];if(!xw(n.column,`getIsVisible`,kw))continue;let r=0;if(n.subHeaders.length){Iw(n.subHeaders);for(let e=0;e<n.subHeaders.length;e++){let t=n.subHeaders[e];xw(t.column,`getIsVisible`,kw)&&(r+=t.colSpan)}}else r=1;if(n.colSpan=r,n.isPlaceholder&&n.subHeaders.length===1&&n.subHeaders[0].column===n.column){let e=1,t=n.subHeaders[0];for(;t;)t.rowSpan=0,e++,t=t.subHeaders.length===1&&t.subHeaders[0].column===n.column?t.subHeaders[0]:void 0;n.rowSpan=e}else n.rowSpan=1}}function Lw(e,t,n,r){let i=jw(e),a=[],o=n._headerGroupInstanceInitFns,s=Array(t.length);for(let e=0;e<t.length;e++)e in t&&(s[e]=Dw(n,t[e],{depth:i,index:e}));return Fw(s,i-1,n,r,a,o),a.reverse(),Iw(a[0]?.headers??[]),a}function Rw(e){if(!e._columnPrototype){e._columnPrototype={table:e};let t=Object.values(e._features);for(let n=0;n<t.length;n++)t[n].assignColumnPrototype?.(e._columnPrototype,e)}return e._columnPrototype}function zw(e,t,n,r){let i={...e.getDefaultColumnDef(),...t},a=i.accessorKey,o=a===void 0?void 0:String(a),s=i.id??o?.replaceAll(`.`,`_`)??(typeof i.header==`string`?i.header:void 0),c;if(i.accessorFn)c=i.accessorFn;else if(a!==void 0){if(typeof a==`string`&&a.includes(`.`)){let e=a.split(`.`);c=t=>{let n=t;for(let t=0;t<e.length;t++){let r=e[t];n=n?.[r]}return n}}else c=e=>e[i.accessorKey]}if(!s)throw Error();let l=Rw(e),u=Object.create(l);u.accessorFn=c,u.columnDef=i,u.columns=[],u.depth=n,u.id=`${String(s)}`,u.parent=r;let d=e._columnInstanceInitFns;for(let e=0;e<d.length;e++)d[e](u);return u}function Bw(e){let t=e.atoms.columnOrder?.get();return n=>{let r=[];if(!t?.length)r=n;else{let e=new Map;for(let t=0;t<n.length;t++){let r=n[t];e.set(r.id,r)}for(let n=0;n<t.length;n++){let i=t[n],a=e.get(i);a&&(r.push(a),e.delete(i))}for(let t=0;t<n.length;t++){let i=n[t];e.has(i.id)&&r.push(i)}}return Vw(e,r)}}function Vw(e,t){let n=e.atoms.grouping?.get()??[],{groupedColumnMode:r}=e.options;if(!n.length||!r)return t;let i=t.filter(e=>!n.includes(e.id));if(r===`remove`)return i;let a=new Map;for(let e=0;e<t.length;e++){let n=t[e];a.set(n.id,n)}let o=[];for(let e=0;e<n.length;e++){let t=a.get(n[e]);t&&o.push(t)}return[...o,...i]}function Hw(e){return[e,...e.columns.flatMap(e=>e.getFlatColumns())]}function Uw(e){if(e.columns.length){let t=e.columns.flatMap(e=>e.getLeafColumns());return xw(e.table,`getOrderColumns`,Bw)(t)}return[e]}function Ww(e){return{header:e=>{let t=e.header.column.columnDef;return t.accessorKey?t.accessorKey:t.accessorFn?t.id:null},cell:e=>e.renderValue()?.toString?.()??null,...Object.values(e._features).reduce((e,t)=>Object.assign(e,t.getDefaultColumnDef?.()),{}),...e.options.defaultColumn}}function Gw(e,t,n,r=0){let i=Array(t.length);for(let a=0;a<t.length;a++){if(!(a in t))continue;let o=t[a],s=zw(e,o,r,n),c=o;s.columns=c.columns?Gw(e,c.columns,s,r+1):[],i[a]=s}return i}function Kw(e){return Gw(e,e.options.columns)}function qw(e){return e.getAllColumns().flatMap(e=>e.getFlatColumns())}function Jw(e){let t=iw(),n=e.getAllFlatColumns();for(let e=0;e<n.length;e++){let r=n[e];t[r.id]=r}return t}function Yw(e){let t=e.getAllColumns().flatMap(e=>e.getLeafColumns());return xw(e,`getOrderColumns`,Bw)(t)}function Xw(e){let t=iw(),n=e.getAllLeafColumns();for(let e=0;e<n.length;e++){let r=n[e];t[r.id]=r}return t}function Zw(e,t){return e.getAllFlatColumnsById()[t]}var Qw={assignColumnPrototype:(e,t)=>{bw(`coreColumnsFeature`,e,t,{column_getFlatColumns:{fn:e=>Hw(e),memoDeps:e=>[e.table.options.columns]},column_getLeafColumns:{fn:e=>Uw(e),memoDeps:e=>[e.table.atoms.columnOrder?.get(),e.table.atoms.grouping?.get(),e.table.options.columns,e.table.options.groupedColumnMode]}})},constructTableAPIs:e=>{yw(`coreColumnsFeature`,e,{table_getDefaultColumnDef:{fn:()=>Ww(e),memoDeps:()=>[e.options.defaultColumn]},table_getAllColumns:{fn:()=>Kw(e),memoDeps:()=>[e.options.columns]},table_getAllFlatColumns:{fn:()=>qw(e),memoDeps:()=>[e.options.columns]},table_getAllFlatColumnsById:{fn:()=>Jw(e),memoDeps:()=>[e.options.columns]},table_getAllLeafColumns:{fn:()=>Yw(e),memoDeps:()=>[e.atoms.columnOrder?.get(),e.atoms.grouping?.get(),e.options.columns,e.options.groupedColumnMode]},table_getAllLeafColumnsById:{fn:()=>Xw(e),memoDeps:()=>[e.getAllLeafColumns()]},table_getColumn:{fn:t=>Zw(e,t)}})}};function $w(e,t){for(let n=0;n<e.subHeaders.length;n++)$w(e.subHeaders[n],t);t.push(e)}function eT(e){let t=[];return $w(e,t),t}function tT(e){return{column:e.column,header:e,table:e.column.table}}function nT(e){let{start:t,end:n}=e.atoms.columnPinning?.get()??Ow(),r=e.getAllColumns(),i=xw(e,`getVisibleLeafColumns`,Aw);if(!t.length&&!n.length)return Lw(r,i,e);let a=e.getAllLeafColumnsById(),o=[];for(let e=0;e<t.length;e++){let n=a[t[e]];n&&xw(n,`getIsVisible`,kw)&&o.push(n)}let s=[];for(let e=0;e<n.length;e++){let t=a[n[e]];t&&xw(t,`getIsVisible`,kw)&&s.push(t)}let c=i.filter(e=>!t.includes(e.id)&&!n.includes(e.id));return Lw(r,[...o,...c,...s],e)}function rT(e){return[...e.getHeaderGroups()].reverse()}function iT(e){let t=e.getHeaderGroups(),n=[];for(let e=0;e<t.length;e++){let r=t[e].headers;for(let e=0;e<r.length;e++)n.push(r[e])}return n}function aT(e){let t=e.getHeaderGroups()[0]?.headers??[],n=[];for(let e=0;e<t.length;e++){let r=t[e].getLeafHeaders();for(let e=0;e<r.length;e++)n.push(r[e])}return n}var oT={assignHeaderPrototype:(e,t)=>{bw(`coreHeadersFeature`,e,t,{header_getLeafHeaders:{fn:e=>eT(e),memoDeps:e=>[e.column.table.options.columns]},header_getContext:{fn:e=>tT(e),memoDeps:e=>[e.column.table.options.columns]}})},constructTableAPIs:e=>{yw(`coreHeadersFeature`,e,{table_getHeaderGroups:{fn:()=>nT(e),memoDeps:()=>[e.options.columns,e.atoms.columnOrder?.get(),e.atoms.grouping?.get(),e.atoms.columnPinning?.get(),e.atoms.columnVisibility?.get(),e.options.groupedColumnMode]},table_getFooterGroups:{fn:()=>rT(e),memoDeps:()=>[e.getHeaderGroups()]},table_getFlatHeaders:{fn:()=>iT(e),memoDeps:()=>[e.getHeaderGroups()]},table_getLeafHeaders:{fn:()=>aT(e),memoDeps:()=>[e.getHeaderGroups()]}})}};function sT(e){if(!e._rowPrototype){e._rowPrototype={table:e};let t=Object.values(e._features);for(let n=0;n<t.length;n++)t[n].assignRowPrototype?.(e._rowPrototype,e)}return e._rowPrototype}var cT=(e,t,n,r,i,a,o)=>{let s=sT(e),c=Object.create(s);c._displayIndexCache=-1,c._uniqueValuesCache=iw(),c._valuesCache=iw(),c.depth=i,c.id=t,c.index=r,c.original=n,c.parentId=o,c.subRows=a??[];let l=e._rowInstanceInitFns;for(let e=0;e<l.length;e++)l[e](c);return c},lT=/([0-9]+)/gm;function uT(e){let t=Object.assign((e,n,r)=>{let i=e.getValue(r),a=n.getValue(r),o=t.resolveDataValue;return o&&(i=o(i),a=o(a)),t.sort(i,a,e,n,r)},e);return t}uT({resolveDataValue:e=>mT(e).toLowerCase(),sort:(e,t)=>hT(e,t)}),uT({resolveDataValue:e=>mT(e),sort:(e,t)=>hT(e,t)}),uT({resolveDataValue:e=>mT(e).toLowerCase(),sort:(e,t)=>fT(e,t)}),uT({resolveDataValue:e=>mT(e),sort:(e,t)=>fT(e,t)}),uT({resolveDataValue:e=>pT(e),sort:(e,t)=>e>t?1:e<t?-1:0});var dT=uT({sort:(e,t)=>fT(e,t)});function fT(e,t){return e===t?0:e>t?1:-1}function pT(e){return e instanceof Date?e.getTime():e}function mT(e){return typeof e==`number`?isNaN(e)||e===1/0||e===-1/0?``:String(e):typeof e==`string`?e:``}function hT(e,t){let n=0,r=0,i=e.length,a=t.length;for(;n<i&&r<a;){let i=gT(e.charCodeAt(n)),a=gT(t.charCodeAt(r)),o=_T(e,n,i),s=_T(t,r,a);if(!i&&!a){let i=vT(e,n,o,t,r,s);if(i)return i;n=o,r=s;continue}if(i!==a)return i?1:-1;let c=yT(e,n,o,t,r,s);if(c)return c;n=o,r=s}return xT(e,n)-xT(t,r)}function gT(e){return e>=48&&e<=57}function _T(e,t,n){let r=t+1;for(;r<e.length&&gT(e.charCodeAt(r))===n;)r++;return r}function vT(e,t,n,r,i,a){let o=n-t,s=a-i,c=o<s?o:s;for(let n=0;n<c;n++){let a=e.charCodeAt(t+n),o=r.charCodeAt(i+n);if(a>o)return 1;if(o>a)return-1}return o>s?1:s>o?-1:0}function yT(e,t,n,r,i,a){let o=t;for(;o<n&&e.charCodeAt(o)===48;)o++;let s=i;for(;s<a&&r.charCodeAt(s)===48;)s++;let c=n-o,l=a-s;if(c===0&&l===0)return 0;if(c<=15&&l<=15){let t=bT(e,o,n),i=bT(r,s,a);return t>i?1:i>t?-1:0}let u=parseInt(e.slice(t,n),10),d=parseInt(r.slice(i,a),10);return u>d?1:d>u?-1:0}function bT(e,t,n){let r=0;for(let i=t;i<n;i++)r=r*10+e.charCodeAt(i)-48;return r}function xT(e,t){let n=0,r=t;for(;r<e.length;)n++,r=_T(e,r,gT(e.charCodeAt(r)));return n}function ST(){return[]}function CT(e,t){fw(e,`cellSelection`,t?ST():nw(e.initialState.cellSelection)??ST())}function wT(e){e.atoms.cellSelection&&(e.options.autoResetAll??e.options.autoResetCellSelection??!0)&&e._reactivity.schedule(()=>CT(e))}function TT(e){e.atoms.expanded&&(e.options.autoResetAll??e.options.autoResetExpanded??!e.options.manualExpanding)&&e._reactivity.schedule(()=>ET(e))}function ET(e,t){let n=e.initialState.expanded;fw(e,`expanded`,t?iw():n===!0||Object.assign(iw(),nw(n??{})))}var DT=0;function OT(e){if(e.options.autoResetAll??e.options.autoResetPageIndex??!e.options.manualPagination){if((e.atoms.pagination?.get()?.pageIndex??DT)===DT)return;jT(e,!0)}}function kT(e,t){fw(e,`pagination`,t)}function AT(e,t){kT(e,n=>{let r=tw(t,n.pageIndex),i=e.options.pageCount===void 0||e.options.pageCount===-1?2**53-1:e.options.pageCount-1;return r=Math.max(0,Math.min(r,i)),{...n,pageIndex:r}})}function jT(e,t){AT(e,t?DT:e.initialState.pagination?.pageIndex??DT)}function MT(){return[]}function NT(e,t){fw(e,`sorting`,t)}function PT(e,t){NT(e,t?[]:nw(e.initialState.sorting??[]))}function FT(e){e.atoms.sorting&&(e.options.autoResetAll??e.options.autoResetSorting??!1)&&PT(e)}function IT(e){let t=e.table._rowModelFns.sortFns,n=e.table.getFilteredRowModel().flatRows.slice(0,10),r,i=!1;for(let t=0;t<n.length;t++){let a=n[t].getValue(e.id);if(Object.prototype.toString.call(a)===`[object Date]`){r=`datetime`;break}if(typeof a==`string`&&(i=!0,a.split(lT).length>1)){r=`alphanumeric`;break}}if(!r&&i&&(r=`text`),r){let e=t?.[r];if(e||r===`alphanumeric`&&(e=t?.text),e)return e}return dT}function LT(e){let t=e.table.getFilteredRowModel().flatRows.slice(0,10);for(let n=0;n<t.length;n++){let r=t[n].getValue(e.id);if(r!=null)return typeof r==`string`?`asc`:`desc`}return`desc`}function RT(e){let t=e.table._rowModelFns.sortFns;return pw(e.columnDef.sortFn)?e.columnDef.sortFn:e.columnDef.sortFn===`auto`?IT(e):t?.[e.columnDef.sortFn]??dT}function zT(e,t,n){let r=VT(e,n&&UT(e)),i=t!==void 0;NT(e.table,a=>{let o=a.findIndex(t=>t.id===e.id),s=o===-1?void 0:a[o],c=[],l,u=i?t:r===`desc`,d=!!(a.length&&UT(e)&&n);return l=d?s?`toggle`:`add`:s?`toggle`:`replace`,l===`toggle`&&(i||r||(l=`remove`)),l===`add`?(c=[...a,{id:e.id,desc:u}],c.splice(0,c.length-(e.table.options.maxMultiSortColCount??2**53-1))):c=l===`toggle`?d?a.map(t=>t.id===e.id?{...t,desc:u}:t):[{id:e.id,desc:u}]:l===`remove`?d?a.filter(t=>t.id!==e.id):[]:[{id:e.id,desc:u}],c})}function BT(e){return e.columnDef.sortDescFirst??e.table.options.sortDescFirst??LT(e)===`desc`?`desc`:`asc`}function VT(e,t){let n=BT(e),r=WT(e);return r?r!==n&&(e.table.options.enableSortingRemoval??!0)&&(!t||(e.table.options.enableMultiRemove??!0))?!1:r===`desc`?`asc`:`desc`:n}function HT(e){return(e.columnDef.enableSorting??!0)&&(e.table.options.enableSorting??!0)&&!!e.accessorFn}function UT(e){return e.columnDef.enableMultiSort??e.table.options.enableMultiSort??!!e.accessorFn}function WT(e){let t=e.table.atoms.sorting?.get()?.find(t=>t.id===e.id);return t?t.desc?`desc`:`asc`:!1}function GT(e){return e.table.atoms.sorting?.get()?.findIndex(t=>t.id===e.id)??-1}function KT(e){NT(e.table,t=>t.length?t.filter(t=>t.id!==e.id):[])}function qT(e){let t=HT(e);return n=>{t&&zT(e,void 0,UT(e)?e.table.options.isMultiSortEvent?.(n):!1)}}function JT(){return e=>_w({feature:`coreRowModelsFeature`,table:e,fnName:`table.getCoreRowModel`,memoDeps:()=>[e.options.data],fn:()=>XT(e,e.options.data),onAfterUpdate:gw(()=>{TT(e),OT(e),FT(e),wT(e)})})}function YT(e,t,n,r=0,i){let a=[];for(let o=0;o<n.length;o++){let s=n[o],c=cT(e,e.getRowId(s,o,i),s,o,r,void 0,i?.id);t.flatRows.push(c),t.rowsById[c.id]=c,a.push(c),e.options.getSubRows&&(c.originalSubRows=e.options.getSubRows(s,o),c.originalSubRows?.length&&(c.subRows=YT(e,t,c.originalSubRows,r+1,c)))}return a}function XT(e,t){let n={rows:[],flatRows:[],rowsById:iw()};return n.rows=YT(e,n,t),n}function ZT(e){return e._rowModels.coreRowModel||(e._rowModels.coreRowModel=e.options.features.coreRowModel?.(e)??JT()(e)),e._rowModels.coreRowModel()}function QT(e){return e.getCoreRowModel()}function $T(e){return e._rowModels.filteredRowModel||(e._rowModels.filteredRowModel=e.options.features.filteredRowModel?.(e)),e.options.manualFiltering||!e._rowModels.filteredRowModel?e.getPreFilteredRowModel():e._rowModels.filteredRowModel()}function eE(e){return e.getFilteredRowModel()}function tE(e){return e._rowModels.groupedRowModel||(e._rowModels.groupedRowModel=e.options.features.groupedRowModel?.(e)),e.options.manualGrouping||!e._rowModels.groupedRowModel?e.getPreGroupedRowModel():e._rowModels.groupedRowModel()}function nE(e){return e.getGroupedRowModel()}function rE(e){return e._rowModels.sortedRowModel||(e._rowModels.sortedRowModel=e.options.features.sortedRowModel?.(e)),e.options.manualSorting||!e._rowModels.sortedRowModel?e.getPreSortedRowModel():e._rowModels.sortedRowModel()}function iE(e){return e.getSortedRowModel()}function aE(e){return e._rowModels.expandedRowModel||(e._rowModels.expandedRowModel=e.options.features.expandedRowModel?.(e)),e.options.manualExpanding||!e._rowModels.expandedRowModel?e.getPreExpandedRowModel():e._rowModels.expandedRowModel()}function oE(e){return e.getExpandedRowModel()}function sE(e){return e._rowModels.paginatedRowModel||(e._rowModels.paginatedRowModel=e.options.features.paginatedRowModel?.(e)),e.options.manualPagination||!e._rowModels.paginatedRowModel?e.getPrePaginatedRowModel():e._rowModels.paginatedRowModel()}function cE(e){return e.getPaginatedRowModel()}var lE={constructTableAPIs:e=>{yw(`coreRowModelsFeature`,e,{table_getCoreRowModel:{fn:()=>ZT(e)},table_getPreFilteredRowModel:{fn:()=>QT(e)},table_getFilteredRowModel:{fn:()=>$T(e)},table_getPreGroupedRowModel:{fn:()=>eE(e)},table_getGroupedRowModel:{fn:()=>tE(e)},table_getPreSortedRowModel:{fn:()=>nE(e)},table_getSortedRowModel:{fn:()=>rE(e)},table_getPreExpandedRowModel:{fn:()=>iE(e)},table_getExpandedRowModel:{fn:()=>aE(e)},table_getPrePaginatedRowModel:{fn:()=>oE(e)},table_getPaginatedRowModel:{fn:()=>sE(e)},table_getRowModel:{fn:()=>cE(e)}})}};function uE(e){if(!e._cellPrototype){e._cellPrototype={table:e};let t=Object.values(e._features);for(let n=0;n<t.length;n++)t[n].assignCellPrototype?.(e._cellPrototype,e)}return e._cellPrototype}function dE(e,t,n){let r=uE(n),i=Object.create(r);i.column=e,i.id=`${t.id}_${e.id}`,i.row=t;let a=n._cellInstanceInitFns;for(let e=0;e<a.length;e++)a[e](i);return i}function fE(e){let t=e.table.getRowsInDisplayOrder(),n=e._displayIndexCache;return t[n]===e?n:-1}function pE(e){let t=e.getPrePaginatedRowModel().rows;if(e.options.paginateExpandedRows===!1){let e=[],n=t=>{t._displayIndexCache=e.length,e.push(t),t.subRows.length&&t.getIsExpanded?.()&&t.subRows.forEach(n)};return t.forEach(n),e}for(let e=0;e<t.length;e++)t[e]._displayIndexCache=e;return t}function mE(e,t){if(aw(e._valuesCache,t))return e._valuesCache[t];let n=e.table.getColumn(t);if(n?.accessorFn)return e._valuesCache[t]=n.accessorFn(e.original,e.index),e._valuesCache[t]}function hE(e,t){if(aw(e._uniqueValuesCache,t))return e._uniqueValuesCache[t];let n=e.table.getColumn(t);if(n?.accessorFn)return n.columnDef.getUniqueValues?(e._uniqueValuesCache[t]=n.columnDef.getUniqueValues(e.original,e.index),e._uniqueValuesCache[t]):(e._uniqueValuesCache[t]=[e.getValue(t)],e._uniqueValuesCache[t])}function gE(e,t){return e.getValue(t)??e.table.options.renderFallbackValue}function _E(e){return mw(e.subRows,e=>e.subRows)}function vE(e){let t=e.getCoreRowModel().flatRows,n=0;for(let e=0;e<t.length;e++)n=Math.max(n,t[e].depth);return n}function yE(e){if(e.parentId)return e.table.getCoreRowModel().rowsById[e.parentId]??e.table.getRow(e.parentId,!0)}function bE(e){let t=[],n=e;for(;;){let e=n.getParentRow();if(!e)break;t.push(e),n=e}return t.reverse()}function xE(e){let t=e.table.getAllLeafColumns(),n=e._cellsCache;n||=e._cellsCache=new WeakMap;let r=Array(t.length);for(let i=0;i<t.length;i++){let a=t[i],o=n.get(a);o||(o=dE(a,e,e.table),n.set(a,o)),r[i]=o}return r}function SE(e){let t=iw(),n=e.getAllCells();for(let e=0;e<n.length;e++){let r=n[e];t[r.column.id]=r}return t}function CE(e,t,n,r){return t.options.getRowId?.(e,n,r)??(r?`${r.id}.${n}`:String(n))}function wE(e,t,n){let r=(n?e.getPrePaginatedRowModel():e.getRowModel()).rowsById[t];if(!r&&(r=e.getCoreRowModel().rowsById[t],!r))throw Error();return r}var TE={assignRowPrototype:(e,t)=>{bw(`coreRowsFeature`,e,t,{row_getDisplayIndex:{fn:e=>fE(e)},row_getAllCellsByColumnId:{fn:e=>SE(e),memoDeps:e=>[e.getAllCells()]},row_getAllCells:{fn:e=>xE(e),memoDeps:e=>[e.table.getAllLeafColumns()]},row_getLeafRows:{fn:e=>_E(e),memoDeps:e=>[e.subRows]},row_getParentRow:{fn:e=>yE(e)},row_getParentRows:{fn:e=>bE(e)},row_getUniqueValues:{fn:(e,t)=>hE(e,t)},row_getValue:{fn:(e,t)=>mE(e,t)},row_renderValue:{fn:(e,t)=>gE(e,t)}})},constructTableAPIs:e=>{yw(`coreRowsFeature`,e,{table_getRowsInDisplayOrder:{fn:()=>pE(e),memoDeps:()=>[e.getPrePaginatedRowModel().rows,e.options.paginateExpandedRows,e.options.paginateExpandedRows===!1?e.atoms.expanded?.get():void 0]},table_getRowId:{fn:(t,n,r)=>CE(t,e,n,r)},table_getRow:{fn:(t,n)=>wE(e,t,n)},table_getMaxSubRowDepth:{fn:()=>vE(e),memoDeps:()=>[e.getCoreRowModel()]}})}};function EE(e,t,n=(e,t)=>e===t){let r=t===void 0?e.options.state:t;e._reactivity.batch(()=>{if(r)for(let t in r){let i=e.baseAtoms[t];if(!i)continue;let a=r[t],o=a===void 0?e.initialState[t]:a;n(e._reactivity.untrack(()=>i.get()),o)||i.set(()=>o)}})}function DE(e,t,n=(e,t)=>e===t){e._reactivity.batch(()=>{EE(e,t,n),e._reactivity.commit?.()})}function OE(e){let t=nw(e.initialState);e._reactivity.batch(()=>{let n=Object.keys(t);for(let r=0;r<n.length;r++){let i=n[r];e.baseAtoms[i].set(t[i])}});let n=Object.values(e._features);for(let t=0;t<n.length;t++)n[t].resetTableInstanceData?.(e)}function kE(e,t){let{features:n,atoms:r,initialState:i}=e.options;if(!e.options.mergeOptions)return{...e.options,...t,features:n,atoms:r,initialState:i};let a=e.options.mergeOptions(e.options,t),o={...Object.getOwnPropertyDescriptors(a)};return Object.defineProperties(Object.create(Object.getPrototypeOf(a)),{...o,features:{value:n,enumerable:!0,configurable:!0,writable:!0},atoms:{value:r,enumerable:!0,configurable:!0,writable:!0},initialState:{value:i,enumerable:!0,configurable:!0,writable:!0}})}function AE(e,t,n){let r=kE(e,tw(t,e.options));e.optionsStore?e.optionsStore.set(()=>r):e.options=r,n?.syncExternalState!==!1&&DE(e,r.state??null)}var jE={coreCellsFeature:Tw,coreColumnsFeature:Qw,coreHeadersFeature:oT,coreRowModelsFeature:lE,coreRowsFeature:TE,coreTablesFeature:{constructTableAPIs:e=>{yw(`coreTablesFeature`,e,{table_reset:{fn:()=>OE(e)},table_setOptions:{fn:t=>AE(e,t)}})}}};function ME(){return{accessor:(e,t)=>typeof e==`function`?{...t,accessorFn:e}:{...t,accessorKey:e},columns:e=>e,display:e=>e,group:e=>e}}function NE(e){return e}function PE(e,t={}){return Object.values(e).forEach(e=>{t=e.getInitialState?.(t)??t}),nw(t)}function FE(e){let t=e.features.coreReactivityFeature,{aggregationFns:n,columnMeta:r,coreRowModel:i,expandedRowModel:a,facetedMinMaxValues:o,facetedRowModel:s,facetedUniqueValues:c,filterFns:l,filterMeta:u,filteredRowModel:d,groupedRowModel:f,paginatedRowModel:p,sortFns:m,sortedRowModel:h,tableMeta:g,..._}=e.features,v={_cellInstanceInitFns:[],_columnInstanceInitFns:[],_features:{...jE,..._},_headerGroupInstanceInitFns:[],_headerInstanceInitFns:[],_reactivity:t,_rowInstanceInitFns:[],_rowModelFns:{aggregationFns:n,filterFns:l,sortFns:m},_rowModels:{},atoms:{},baseAtoms:{}},y=Object.values(v._features),b={...y.reduce((e,t)=>Object.assign(e,t.getDefaultTableOptions?.(v)),{}),...e};if(t.wrapExternalAtoms&&b.atoms)for(let[e,n]of Object.entries(b.atoms)){let r=n,i=t.createWritableAtom(r.get(),{debugName:`externalAtom/${e}`});b.atoms[e]=i;let a=!1,o=r.subscribe(e=>{a||i.set(e)}),s=i.subscribe(e=>{a=!0,r.set(e),a=!1});t.addSubscription(o),t.addSubscription(s)}t.createOptionsStore?(v.optionsStore=t.createWritableAtom(b,{debugName:`table/optionsStore`}),Object.defineProperty(v,"options",{configurable:!0,enumerable:!0,get(){return v.optionsStore.get()},set(e){v.optionsStore.set(()=>e)}})):v.options=b,v.initialState=PE(v._features,v.options.initialState);let x=Object.keys(v.initialState);for(let e=0;e<x.length;e++){let n=x[e];v.baseAtoms[n]=t.createWritableAtom(v.initialState[n],{debugName:`table/baseAtoms/${n}`}),v.atoms[n]=t.createReadonlyAtom(()=>{let e=v.options,t=e.atoms?.[n],r=t?t.get():v.baseAtoms[n].get();if(t)return r;let i=e.state;if(i&&aw(i,n)){let e=i[n];return e===void 0?v.initialState[n]:e}return r},{debugName:`table/atoms/${n}`})}EE(v),v.store=ZC(t.createReadonlyAtom(()=>{let e={};for(let t=0;t<x.length;t++){let n=x[t];e[n]=v.atoms[n].get()}return e},{compare:HC,debugName:`table/store`}));for(let e=0;e<y.length;e++){let t=y[e];t.initTableInstanceData?.(v),t.initCellInstanceData&&v._cellInstanceInitFns.push(t.initCellInstanceData.bind(t)),t.initColumnInstanceData&&v._columnInstanceInitFns.push(t.initColumnInstanceData.bind(t)),t.initHeaderGroupInstanceData&&v._headerGroupInstanceInitFns.push(t.initHeaderGroupInstanceData.bind(t)),t.initHeaderInstanceData&&v._headerInstanceInitFns.push(t.initHeaderInstanceData.bind(t)),t.initRowInstanceData&&v._rowInstanceInitFns.push(t.initRowInstanceData.bind(t)),t.constructTableAPIs?.(v)}return v}function IE(){return iw()}function LE(e,t){e.options.onRowSelectionChange?.(t)}function RE(e,t){e._lastSelectedRowId=null,LE(e,t?iw():Object.assign(iw(),nw(e.initialState.rowSelection??{})))}function zE(e,t,n){e._lastSelectedRowId=null,LE(e,r=>{if(t=t===void 0?!xw(e,`getIsAllRowsSelected`,KE):t,n?.deselectAll&&!t)return iw();let i=Object.assign(iw(),r),a=e.getPreGroupedRowModel().flatRows;if(t){let e=new Map;a.forEach(t=>{cD(t,e)&&(i[t.id]=!0)})}else a.forEach(e=>{nD(e)&&delete i[e.id]});return i})}function BE(e,t,n){e._lastSelectedRowId=null,LE(e,r=>{let i=t===void 0?!xw(e,`getIsAllPageRowsSelected`,qE):t;if(n?.deselectAll&&!i)return iw();let a=Object.assign(iw(),r);return e.getRowModel().rows.forEach(t=>{sD(a,t.id,i,!0,e,!0)}),a})}function VE(e){return e.getCoreRowModel()}function HE(e){let t=e.getCoreRowModel();return xw(e,`getIsSomeRowsSelected`,JE)?dD(t,e):{rows:[],flatRows:[],rowsById:iw()}}function UE(e){let t=e.getFilteredRowModel();return xw(e,`getIsSomeRowsSelected`,JE)?dD(t,e):{rows:[],flatRows:[],rowsById:iw()}}function WE(e){let t=e.getSortedRowModel();return xw(e,`getIsSomeRowsSelected`,JE)?dD(t,e):{rows:[],flatRows:[],rowsById:iw()}}function GE(e){return Object.keys(e.atoms.rowSelection?.get()??{})}function KE(e){let t=e.getFilteredRowModel().flatRows,n=e.atoms.rowSelection?.get()??{},r=!!(t.length&&Object.keys(n).length);if(r){let e=new Map;t.some(t=>!fD(t,n)&&cD(t,e))&&(r=!1)}return r}function qE(e){let t=e.getPaginatedRowModel().flatRows,n=e.atoms.rowSelection?.get()??{},r=new Map,i=!1;for(let e=0;e<t.length;e++){let a=t[e];if(fD(a,n))!i&&cD(a,r)&&(i=!0);else if(cD(a,r))return!1}return i}function JE(e){return xw(e,`getSelectedRowIds`,GE).length>0}function YE(e){return e.getPaginatedRowModel().flatRows.filter(e=>nD(e)).some(e=>$E(e)||xw(e,`getIsSomeSelected`,eD))}function XE(e){return t=>{zE(e,t.target.checked)}}function ZE(e){return t=>{BE(e,t.target.checked)}}function QE(e,t,n){let r=$E(e);LE(e.table,i=>{t=t===void 0?!r:t;let a=Object.assign(iw(),i);return sD(a,e.id,t,(n?.selectChildren??!0)&&iD(e),e.table),!t&&n?.deselectParents&&lD(a,e),a})}function $E(e){return fD(e,e.table.atoms.rowSelection?.get()??{})}function eD(e){return pD(e)===`some`}function tD(e){return pD(e)===`all`}function nD(e){let t=e.table.options;return typeof t.enableRowSelection==`function`?t.enableRowSelection(e):t.enableRowSelection??!0}function rD(e){let t=e.table.options;return typeof t.enableSubRowSelection==`function`?t.enableSubRowSelection(e):t.enableSubRowSelection??!0}function iD(e){let t=e.table.options;return typeof t.enableMultiRowSelection==`function`?t.enableMultiRowSelection(e):t.enableMultiRowSelection??!0}function aD(e,t){let n=nD(e);return r=>{if(!n)return;let i=r,a=e.table,o=i.target.checked,s=a._lastSelectedRowId;(!(a.options.enableRowRangeSelection!==!1&&s!==null&&iD(e)&&(a.options.isRowRangeSelectionEvent?.(r)??!1))||!oD(e,s,o,t))&&QE(e,o,t),a._lastSelectedRowId=e.id}}function oD(e,t,n,r){let i=r?.selectChildren??!0,a=e.table,o=a.getRowsInDisplayOrder(),s=a.getPrePaginatedRowModel().rowsById[t]??a.getCoreRowModel().rowsById[t];if(!s)return!1;let c=s.getDisplayIndex(),l=e.getDisplayIndex(),u=o[c],d=o[l];if(c<0||l<0||c>=o.length||l>=o.length||u?.id!==s.id||d?.id!==e.id||!iD(s)||!iD(e))return!1;let f=Math.min(c,l),p=Math.max(c,l);return LE(a,e=>{let t=Object.assign(iw(),e);for(let e=f;e<=p;e++){let s=o[e];nD(s)&&iD(s)&&(sD(t,s.id,n,i,a),!n&&r?.deselectParents&&lD(t,s))}return t}),!0}function sD(e,t,n,r,i,a){let o=i.getRow(t,!0);n?(iD(o)||Object.keys(e).forEach(t=>delete e[t]),nD(o)&&(e[t]=!0)):(!a||nD(o))&&delete e[t],r&&o.subRows.length&&rD(o)&&o.subRows.forEach(t=>sD(e,t.id,n,r,i,a))}function cD(e,t){if(!nD(e))return!1;let n=e.table;if(n.options.enableSubRowSelection===!0)return!0;let r=e.parentId;if(r===void 0)return!0;let i=t.get(r);if(i!==void 0)return i;let a=n.getCoreRowModel().rowsById,o=[],s=!0,c=r;for(;c!==void 0;){let e=t.get(c);if(e!==void 0){s=e;break}o.push(c);let r=a[c]??n.getRow(c,!0);if(!rD(r)){s=!1;break}c=r.parentId}return o.forEach(e=>t.set(e,s)),s}function lD(e,t){let n=t.table.getCoreRowModel().rowsById,r=t.parentId;for(;r!==void 0;)delete e[r],r=(n[r]??t.table.getRow(r,!0)).parentId}function uD(e,t,n,r){let i=[];for(let a=0;a<e.length;a++){let o=e[a],s=fD(o,t);if(s&&(n.push(o),r[o.id]=o),o.subRows.length){let e=uD(o.subRows,t,n,r);if(s){let t=Object.create(Object.getPrototypeOf(o));rw(t,o),t.subRows=e,i.push(t)}}else s&&i.push(o)}return i}function dD(e,t){let n=[],r=iw(),i=t.atoms.rowSelection?.get()??{};return{rows:uD(e.rows,i,n,r),flatRows:n,rowsById:r}}function fD(e,t){return!!(aw(t,e.id)&&t[e.id])}function pD(e){if(!e.subRows.length)return!1;let t=e.table.atoms.rowSelection?.get()??{},n=!1,r=!0,i=!1;for(let a=0;a<e.subRows.length;a++){let o=e.subRows[a];if(n&&!r)break;if(nD(o)&&(i=!0,fD(o,t)?n=!0:r=!1),o.subRows.length){let e=pD(o);e===`all`?(n=!0,i=!0):e===`some`?(n=!0,r=!1,i=!0):r=!1}}return i?r?`all`:n?`some`:!1:!1}var mD={initTableInstanceData:e=>{e._lastSelectedRowId=null},resetTableInstanceData:e=>{e._lastSelectedRowId=null},getInitialState:e=>({rowSelection:IE(),...e}),getDefaultTableOptions:e=>({onRowSelectionChange:ow(`rowSelection`,e),enableRowSelection:!0,enableMultiRowSelection:!0,enableRowRangeSelection:!0,enableSubRowSelection:!0,isRowRangeSelectionEvent:e=>{let t=e;return!!(t.shiftKey||t.nativeEvent?.shiftKey)}}),assignRowPrototype:(e,t)=>{bw(`rowSelectionFeature`,e,t,{row_toggleSelected:{fn:(e,t,n)=>QE(e,t,n)},row_getIsSelected:{fn:e=>$E(e)},row_getIsSomeSelected:{fn:e=>eD(e),memoDeps:e=>[e.subRows,e.table.atoms.rowSelection?.get(),e.table.options.enableRowSelection]},row_getIsAllSubRowsSelected:{fn:e=>tD(e),memoDeps:e=>[e.subRows,e.table.atoms.rowSelection?.get(),e.table.options.enableRowSelection]},row_getCanSelect:{fn:e=>nD(e)},row_getCanSelectSubRows:{fn:e=>rD(e)},row_getCanMultiSelect:{fn:e=>iD(e)},row_getToggleSelectedHandler:{fn:(e,t)=>aD(e,t)}})},constructTableAPIs:e=>{yw(`rowSelectionFeature`,e,{table_setRowSelection:{fn:t=>LE(e,t)},table_resetRowSelection:{fn:t=>RE(e,t)},table_toggleAllRowsSelected:{fn:(t,n)=>zE(e,t,n)},table_toggleAllPageRowsSelected:{fn:(t,n)=>BE(e,t,n)},table_getPreSelectedRowModel:{fn:()=>VE(e)},table_getSelectedRowModel:{fn:()=>HE(e),memoDeps:()=>[e.atoms.rowSelection?.get(),e.getCoreRowModel()]},table_getFilteredSelectedRowModel:{fn:()=>UE(e),memoDeps:()=>[e.atoms.rowSelection?.get(),e.getFilteredRowModel()]},table_getGroupedSelectedRowModel:{fn:()=>WE(e),memoDeps:()=>[e.atoms.rowSelection?.get(),e.getSortedRowModel()]},table_getSelectedRowIds:{fn:()=>GE(e),memoDeps:()=>[e.atoms.rowSelection?.get()]},table_getIsAllRowsSelected:{fn:()=>KE(e),memoDeps:()=>[e.atoms.rowSelection?.get(),e.getFilteredRowModel(),e.options.enableRowSelection,e.options.enableSubRowSelection]},table_getIsAllPageRowsSelected:{fn:()=>qE(e),memoDeps:()=>[e.atoms.rowSelection?.get(),e.getPaginatedRowModel(),e.options.enableRowSelection,e.options.enableSubRowSelection]},table_getIsSomeRowsSelected:{fn:()=>JE(e),memoDeps:()=>[e.atoms.rowSelection?.get()]},table_getIsSomePageRowsSelected:{fn:()=>YE(e),memoDeps:()=>[e.atoms.rowSelection?.get(),e.getPaginatedRowModel(),e.options.enableRowSelection]},table_getToggleAllRowsSelectedHandler:{fn:()=>XE(e)},table_getToggleAllPageRowsSelectedHandler:{fn:()=>ZE(e)}})}},hD={getInitialState(e){return{sorting:MT(),...e}},getDefaultColumnDef(){return{sortFn:`auto`,sortUndefined:1}},getDefaultTableOptions(e){return{autoResetSorting:!1,onSortingChange:ow(`sorting`,e),isMultiSortEvent:e=>e.shiftKey}},assignColumnPrototype(e,t){bw(`rowSortingFeature`,e,t,{column_getAutoSortFn:{fn:e=>IT(e)},column_getAutoSortDir:{fn:e=>LT(e)},column_getSortFn:{fn:e=>RT(e)},column_toggleSorting:{fn:(e,t,n)=>zT(e,t,n)},column_getFirstSortDir:{fn:e=>BT(e)},column_getNextSortingOrder:{fn:(e,t)=>VT(e,t)},column_getCanSort:{fn:e=>HT(e)},column_getCanMultiSort:{fn:e=>UT(e)},column_getIsSorted:{fn:e=>WT(e)},column_getSortIndex:{fn:e=>GT(e)},column_clearSorting:{fn:e=>KT(e)},column_getToggleSortingHandler:{fn:e=>qT(e)}})},constructTableAPIs(e){yw(`rowSortingFeature`,e,{table_setSorting:{fn:t=>NT(e,t)},table_resetSorting:{fn:t=>PT(e,t)}})}},gD=typeof window>`u`?o.useEffect:o.useLayoutEffect;function _D(e,t){let[{table:n,rootSource:r}]=(0,o.useState)(()=>{let t=FE({...e,features:{coreReactivityFeature:ew(),...e.features}});return t.Subscribe=(e=>XC({...e,source:e.source??t.store})),t.FlexRender=CC,{table:t,rootSource:$C(t.store,HC)}}),i=n;AE(i,t=>({...t,...e}),{syncExternalState:!1});let a=i.options.state,s=r.get(),c=YC(r,t,{compare:HC});return gD(()=>{r.markCommitted(s),DE(i,a??null,HC)}),(0,o.useMemo)(()=>({...n,options:e,state:c}),[n,e,c])}var vD=(e,t)=>{let n=String(t);return e&&Object.hasOwn(e,n)?e[n]:void 0},yD=e=>(0,B.jsx)(`span`,{className:`text-faint-foreground`,children:e}),bD=e=>typeof e==`object`&&e&&`name`in e?String(e.name):String(e),xD=(e,t)=>{if(t==null)return yD(`—`);switch(e.kind){case`text`:return(0,B.jsx)(`span`,{className:`truncate`,children:String(t)});case`id`:return(0,B.jsx)(`span`,{className:`truncate font-mono text-xs text-muted-foreground`,children:String(t)});case`money`:return(0,B.jsxs)(`span`,{className:`tabular-nums`,children:[Of(Number(t),e.currency,e.decimals),e.suffix]});case`date`:return(0,B.jsx)(`span`,{className:`tabular-nums text-muted-foreground`,children:Lf(Number(t))});case`datetime`:return(0,B.jsx)(`span`,{className:`tabular-nums text-muted-foreground`,children:zf(Number(t))});case`number`:return(0,B.jsxs)(`span`,{className:`tabular-nums`,children:[Af(Number(t)),e.suffix]});case`signed`:return(0,B.jsxs)(`span`,{className:z(`tabular-nums`,Number(t)<0?`text-danger-text`:`text-success-text`),children:[jf(Number(t)),e.suffix]});case`percent`:return Number(t)===0?yD(`—`):(0,B.jsx)(`span`,{className:`tabular-nums`,children:Mf(Number(t))});case`status`:return(0,B.jsx)(Cd,{tone:e.tones?.[String(t)]??`neutral`,color:vD(e.colors,t),shape:e.shape,children:Bo(String(t),e.labels)});case`relation`:return(0,B.jsx)(`span`,{className:`truncate font-medium text-primary-text hover:underline`,children:bD(t)});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)(de,{className:`size-3`,strokeWidth:3})}):yD(`No`);case`file`:{let e=q_(t);if(!e)return yD(`—`);if(`missing`in e)return(0,B.jsx)(`span`,{className:`truncate text-danger-text`,children:e.name});let n=tv(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)(py,{image:n,className:`size-5 shrink-0 rounded-sm object-cover`}):(0,B.jsx)(Nt,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,B.jsx)(`span`,{className:`truncate`,children:e.name})]})}case`user`:{let e=NS(String(t));return(0,B.jsxs)(`span`,{className:`inline-flex items-center gap-2 truncate`,children:[(0,B.jsx)(md,{initials:e.initials,hue:e.hue,size:`xs`,className:`ring-0`}),(0,B.jsx)(`span`,{className:`truncate text-muted-foreground`,children:e.name})]})}}},SD=NE({rowSortingFeature:hD,rowSelectionFeature:mD}),CD=ME(),wD=e=>CD.columns(e.map(e=>CD.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):xD(e,t.getValue())}))),TD=({total:e,selectedCount:t,bulkActions:n=[],className:r})=>(0,B.jsx)(`div`,{className:z(`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:[Nf(e),t>0&&(0,B.jsxs)(`span`,{className:`ml-3 font-medium text-primary-text`,children:[Af(t),` selected`]}),t>0&&n.map(e=>(0,B.jsx)(`button`,{type:`button`,onClick:e.onRun,className:z(`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))]})}),ED=(e,t)=>e.filter(e=>e.available?.(t)??!0),DD=4,OD=(e,t)=>{let n=e.bottom+DD;return{top:n+t>window.innerHeight-DD?Math.max(DD,e.top-DD-t):n,right:window.innerWidth-e.right}},kD=({row:e,actions:t})=>{let[n,r]=(0,o.useState)(!1),[i,a]=(0,o.useState)(),s=(0,o.useRef)(null),c=(0,o.useRef)(null);return(0,o.useLayoutEffect)(()=>{if(!n||!s.current||!c.current){a(void 0);return}a(OD(s.current.getBoundingClientRect(),c.current.offsetHeight))},[n]),(0,o.useEffect)(()=>{if(!n)return;let e=e=>s.current?.contains(e)||c.current?.contains(e),t=t=>{(t instanceof KeyboardEvent?t.key===`Escape`:!e(t.target))&&r(!1)},i=()=>r(!1);return document.addEventListener(`mousedown`,t),document.addEventListener(`keydown`,t),document.addEventListener(`scroll`,i,!0),window.addEventListener(`resize`,i),()=>{document.removeEventListener(`mousedown`,t),document.removeEventListener(`keydown`,t),document.removeEventListener(`scroll`,i,!0),window.removeEventListener(`resize`,i)}},[n]),(0,B.jsxs)(`div`,{className:`relative flex justify-center bg-inherit`,onClick:e=>e.stopPropagation(),children:[(0,B.jsx)(`button`,{ref:s,type:`button`,"aria-label":`Row actions`,"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)(Ve,{className:`size-4`})}),n&&(0,Fn.createPortal)((0,B.jsx)(`ul`,{ref:c,role:`menu`,onClick:e=>e.stopPropagation(),style:i??{visibility:`hidden`},className:`fixed z-50 min-w-36 rounded-md border bg-background py-1 text-[13px] shadow-pop`,children:t.map(t=>(0,B.jsx)(`li`,{role:`none`,children:(0,B.jsx)(`button`,{type:`button`,role:`menuitem`,className:z(`block w-full px-3 py-1.5 text-left hover:bg-muted`,t.destructive&&`text-danger-text`),onClick:()=>{r(!1),t.onSelect(e)},children:t.label})},t.label))}),document.body)]})},AD=e=>52+Math.ceil(String(e).length*1.33)*7,jD=.6,MD=(e,t)=>Math.max(e.minWidth??0,e.width*t),ND=(e,t)=>e.fixed?`${Math.max(e.minWidth??0,e.width)}px`:`minmax(${MD(e,t)}px, ${e.width}fr)`,PD=(e,t,n=0,r=jD)=>`${t}px ${e.map(e=>ND(e,r)).join(` `)}${n>0?` ${n}px`:``}`,FD=(e,t,n=0,r=jD)=>t+n+e.reduce((e,t)=>e+(t.fixed?Math.max(t.minWidth??0,t.width):MD(t,r)),0),ID=()=>{let e=(0,o.useRef)(null),t=(0,o.useRef)(null),[n,r]=(0,o.useState)({scrolled:!1,more:!1}),i=(0,o.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,o.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}},LD=`protobase:pinned:`,RD=(e,t)=>`${LD}${e}:${t}`,zD=(e,t)=>jd(()=>{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),BD=(e,t,n)=>jd(()=>n.length===0?e.removeItem(t):e.setItem(t,JSON.stringify(n)),void 0),VD=(e,t=[])=>{let[n,r]=(0,o.useState)(()=>(e?zD(localStorage,e):void 0)??t);return[n,(0,o.useCallback)(t=>{r(t),e&&BD(localStorage,e,t)},[e])]},HD=e=>e===`money`||e===`number`||e===`signed`||e===`percent`,UD=({header:e,pinned:t,onTogglePin:n})=>{let[r,i]=(0,o.useState)(!1),a=(0,o.useRef)(null);return(0,o.useEffect)(()=>{if(!r)return;let e=e=>{(e instanceof KeyboardEvent?e.key===`Escape`:!a.current?.contains(e.target))&&i(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,e),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,e)}},[r]),(0,B.jsxs)(`div`,{ref:a,className:`relative ml-auto shrink-0`,children:[(0,B.jsx)(`button`,{type:`button`,"aria-label":`${e} column menu`,"aria-haspopup":`menu`,"aria-expanded":r,onClick:()=>i(!r),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)(Ve,{className:`size-3.5`})}),r&&(0,B.jsx)(`ul`,{role:`menu`,className:`absolute right-0 top-full z-30 mt-1 min-w-32 rounded-md border bg-background py-1 text-[13px] font-normal text-foreground shadow-pop`,children:(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:()=>{i(!1),n()},children:t?`Unpin`:`Pin to left`})})})]})},WD=({sorted:e})=>e===`asc`?(0,B.jsx)(E,{className:`size-3 text-foreground`}):e===`desc`?(0,B.jsx)(S,{className:`size-3 text-foreground`}):(0,B.jsx)(ye,{className:`size-3 opacity-0 group-hover/head:opacity-100`}),GD=({cells:e,specs:t,gutter:n,selectedCount:r,selectable:i,trailing:a,minScale:o,pins:s={},lastPinned:c,scrolled:l,onTogglePin:u,onClearSelection:d})=>(0,B.jsxs)(`div`,{className:`grid h-8 shrink-0 items-center border-b bg-surface text-xs font-medium text-muted-foreground`,style:{gridTemplateColumns:PD(t,n,a,o)},role:`row`,children:[(0,B.jsxs)(`div`,{className:z(`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)(Yh,{checked:!1,indeterminate:r>0,label:`Clear selection`,onChange:d,className:z(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:z(`group/cell flex h-full min-w-0 items-center`,r&&`sticky z-10 bg-inherit`,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:[(0,B.jsxs)(`button`,{type:`button`,onClick:n,disabled:!e.sortable,className:z(`group/head flex h-full min-w-0 flex-1 items-center gap-1 pl-3 pr-1 text-left`,HD(e.kind)&&`justify-end`,e.sortable&&`hover:text-foreground`,t&&`text-foreground`),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:`New`}),e.sortable&&(0,B.jsx)(WD,{sorted:t})]}),(0,B.jsx)(`div`,{className:`pr-1.5`,children:(0,B.jsx)(UD,{header:e.header,pinned:r,onTogglePin:()=>u(e.id)})})]},e.id)}),a?(0,B.jsx)(`div`,{}):null]}),KD=e=>({gridTemplateColumns:PD(e.specs,e.gutter,e.trailing,e.minScale),height:e.height,transform:`translateY(${e.offset}px)`}),qD=(e,t)=>z(`flex h-full min-w-0 items-center overflow-hidden whitespace-nowrap px-3`,HD(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)]`),JD=(e,t)=>t&&e.id in t?{left:t[e.id]}:void 0,YD=({width:e,index:t,selectable:n,selected:r,onToggle:i,edge:a})=>(0,B.jsxs)(`div`,{className:z(`sticky left-0 z-10 flex h-full items-center gap-2 bg-inherit pl-3`,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)(`span`,{onClick:e=>e.stopPropagation(),children:(0,B.jsx)(Yh,{checked:!!r,onChange:i,label:`Select row ${t+1}`})}),e>40&&(0,B.jsx)(`span`,{className:`min-w-6 text-right text-[11px] tabular-nums text-faint-foreground`,children:Af(t+1)})]}),XD=({cells:e,selected:t,onToggle:n,onOpen:r,menu:i,...a})=>(0,B.jsxs)(`div`,{role:`row`,onClick:r,className:z(`absolute inset-x-0 top-0 grid items-center border-b text-[13px]`,t?`bg-primary-soft`:`bg-background hover:bg-surface`,r&&`cursor-pointer`),style:KD(a),children:[(0,B.jsx)(YD,{width:a.gutter,index:a.index,selectable:a.selectable,selected:t,onToggle:n,edge:a.scrolled&&!a.lastPinned}),e.map(({spec:e,content:t})=>(0,B.jsx)(`div`,{role:`cell`,className:qD(e,a),style:JD(e,a.pins),children:t},e.id)),i&&(0,B.jsx)(`div`,{className:`flex h-full items-center justify-center`,children:i})]}),ZD=[`w-3/4`,`w-1/2`,`w-2/3`,`w-5/6`,`w-2/5`],QD=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:KD(e),children:[(0,B.jsx)(YD,{width:e.gutter,index:e.index,selectable:!1,edge:e.scrolled&&!e.lastPinned}),e.specs.map((t,n)=>(0,B.jsx)(`div`,{className:qD(t,e),style:JD(t,e.pins),children:(0,B.jsx)(od,{className:z(`h-2.5`,ZD[(e.index+n)%ZD.length],HD(t.kind)&&`ml-auto`)})},t.id))]}),$D=(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)},get size(){return n.size}}},eO=(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)},tO=({total:e,rowAt:t,loadRows:n,latencyMs:r},i,a)=>{let s=(0,o.useMemo)(()=>$D(40,60),[t,n]),[c,l]=(0,o.useState)(0),u=Math.floor(i/40),d=Math.floor(a/40),f=!n&&r===0;return(0,o.useEffect)(()=>{if(f)return;let i=eO(u*40,d*40,40).filter(e=>!s.hasPage(e)),a=t=>Math.max(0,Math.min(40,e-t*40)),o=(e,t)=>{s.setPage(e,t),l(e=>e+1)};if(n){let e=!1;for(let t of i)n(t*40,a(t)).then(n=>{e||o(t,n)});return()=>{e=!0}}let c=i.map(e=>setTimeout(()=>o(e,Array.from({length:a(e)},(n,r)=>t(e*40+r))),r));return()=>c.forEach(clearTimeout)},[s,u,d,r,e,t,n,f]),(0,o.useCallback)(e=>f?t(e):s.get(e),[s,f,t,c])},nO=1e7,rO=(e,t,n)=>{let r=e*t,i=Math.min(r,nO);return{rowHeight:t,trueHeight:r,contentHeight:i,scaled:r>i,maxTop:Math.max(0,r-n),maxScroll:Math.max(0,i-n)}},iO=(e,t)=>!e.scaled||t<=0?t:t>=e.maxScroll?e.maxTop+t-e.maxScroll:t/e.maxScroll*e.maxTop,aO=(e,t)=>!e.scaled||t<=0?t:t>=e.maxTop?e.maxScroll+t-e.maxTop:t/e.maxTop*e.maxScroll,oO=(e,t,n,r)=>{let i=t*e.rowHeight;return e.scaled?i-n+r:i},sO=(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)}},cO=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},lO=e=>e===(document.scrollingElement??document.documentElement),uO=e=>lO(e)?window:e,dO=e=>Number.parseFloat(e)||0,fO=e=>{let t=getComputedStyle(e),n=lO(e)?{top:0,height:e.clientHeight}:{top:e.getBoundingClientRect().top+e.clientTop,height:e.clientHeight},r=dO(t.scrollPaddingTop);return{top:n.top+r,height:Math.max(0,n.height-r-dO(t.scrollPaddingBottom))}},pO=6,mO=(e,t,n)=>{let r=rO(t,n,e.height),i=iO(r,e.position);return{geometry:r,top:i,topIndex:Math.floor(Math.max(0,i)/n),...sO(t,i,n,e.height,pO)}},hO=({total:e,rowHeight:t,initialIndex:n,inset:r=0,settle:i,ready:a=!0})=>{let s=(0,o.useRef)(null),c=(0,o.useRef)(null),[l,u]=(0,o.useState)({position:0,height:0}),d=(0,o.useRef)({total:e,rowHeight:t,initialIndex:n,inset:r,ready:a});d.current={total:e,rowHeight:t,initialIndex:n,inset:r,ready:a};let f=(0,o.useCallback)(()=>{let e=s.current;if(!e||!c.current)return;let t=fO(c.current),n=d.current.inset;return{position:t.top+n-e.getBoundingClientRect().top,height:Math.max(0,t.height-n)}},[]),p=(0,o.useRef)(l);p.current=l;let m=(0,o.useCallback)(()=>{let e=f();if(!e)return;let t=p.current,{total:n,rowHeight:r}=d.current,i=mO(t,n,r),a=mO(e,n,r),o=!a.geometry.scaled&&i.first===a.first&&i.last===a.last&&i.topIndex===a.topIndex;(t.height!==e.height||t.position!==e.position&&!o)&&(p.current=e,u(e))},[f]),h=(0,o.useRef)({pending:!0,laidOut:!1}),g=(0,o.useCallback)(()=>{if(!h.current.pending||!h.current.laidOut||!d.current.ready)return;let e=f(),t=c.current;if(!e||!t)return;h.current.pending=!1;let{total:n,rowHeight:r,initialIndex:i}=d.current;i>0?t.scrollTop+=aO(rO(n,r,e.height),i*r)-e.position:e.position>0&&(t.scrollTop=0)},[f]);(0,o.useLayoutEffect)(()=>{let e=s.current;if(!e)return;let t=cO(e);c.current=t;let n=uO(t);n.addEventListener(`scroll`,m,{passive:!0}),window.addEventListener(`resize`,m,{passive:!0});let r=new ResizeObserver(()=>{h.current.laidOut=!0,g(),m()});return r.observe(t),r.observe(e),m(),()=>{n.removeEventListener(`scroll`,m),window.removeEventListener(`resize`,m),r.disconnect(),c.current=null}},[m,g]),(0,o.useLayoutEffect)(()=>{g(),m()});let _=(0,o.useCallback)(e=>{let t=f();if(!t||!c.current)return;let n=rO(d.current.total,d.current.rowHeight,t.height);c.current.scrollTop+=aO(n,e)-t.position,m()},[f,m]),v=mO(l,e,t),y=i?i(v.top):v.top,{first:b,last:x}=i?sO(e,y,t,l.height,pO):v,S=Array.from({length:x-b+1},(e,t)=>({index:b+t,offset:oO(v.geometry,b+t,y,l.position)}));return{ref:s,height:l.height,top:y,geometry:v.geometry,rows:S,first:b,last:x,scrollTo:_}},gO=32,_O=({columns:e,source:t,naturalSort:n,initialScrollIndex:r=0,onScrollIndex:i,latencyMs:a=150,sort:s,onSortChange:c,onOpenRow:l,rowActions:u,bulkActions:d,pinKey:f,defaultPinned:p,rowNumbers:m=!0,compact:h=!1,selectable:g=!0,fit:_=!1,scroll:v=`own`,className:y})=>{let b=h?28:36,[x,S]=VD(f,p),C=(0,o.useMemo)(()=>[...x.flatMap(t=>e.find(e=>e.id===t)??[]),...e.filter(e=>!x.includes(e.id))],[e,x]),w=C.slice(0,C.filter(e=>x.includes(e.id)).length).map(e=>e.id),{total:T}=t,[E,D]=(0,o.useState)(n?[{id:n.columnId,desc:n.direction===`desc`}]:[]),O=s?[{id:s.columnId,desc:s.direction===`desc`}]:E,k=e=>{let t=typeof e==`function`?e(O):e,n=t[0];c&&n&&c({columnId:n.id,direction:n.desc?`desc`:`asc`}),s||D(t)},[A,j]=(0,o.useState)({}),M=(0,o.useMemo)(()=>wD(C),[C]),N=O[0],ee=!!(!s&&n&&N&&N.id===n.columnId&&(N.desc?`desc`:`asc`)!==n.direction),te=t.rowAt,ne=(0,o.useCallback)(e=>te(ee?T-1-e:e),[te,ee,T]),[P]=(0,o.useState)(r),{ref:re,top:ie,geometry:ae,rows:F,first:oe,last:se}=hO({total:T,rowHeight:b,initialIndex:P,inset:gO}),ce=!Gu(),I=ce||!m?40:AD(T),le=Math.floor(Math.max(0,ie)/b);(0,o.useEffect)(()=>i?.(le),[le,i]);let ue=tO({total:T,rowAt:te?ne:void 0,loadRows:t.loadRows,latencyMs:a},oe,se),de=F.map(({index:e,offset:t})=>({index:e,offset:t,row:ue(e)})),fe=_D({features:SD,columns:M,data:(0,o.useMemo)(()=>de.flatMap(({row:e})=>e?[e]:[]),[ue,oe,se]),state:{sorting:O,rowSelection:A},onSortingChange:k,onRowSelectionChange:j,manualSorting:!0,enableMultiSort:!1,enableSortingRemoval:!1,getRowId:e=>e.id}),pe=new Map(fe.getRowModel().rows.map(e=>[e.id,e])),me=Object.keys(A).length,he=(0,o.useRef)(new Map);for(let e of fe.getRowModel().rows)e.getIsSelected()&&he.current.set(e.id,e.original);let ge=u&&u.length>0?40:0,_e=ce?1:jD,ve=ID(),ye=(0,o.useRef)(null),be=()=>{ve.onScroll(),ye.current&&ve.ref.current&&(ye.current.scrollLeft=ve.ref.current.scrollLeft)},[xe,Se]=(0,o.useState)({});(0,o.useLayoutEffect)(()=>{let e=ye.current?.querySelector(`[role=row]`);if(!e)return;let t=I,n={};for(let r of w)n[r]=t,t+=e.querySelector(`[data-col-id="${r}"]`)?.offsetWidth??0;JSON.stringify(xe)!==JSON.stringify(n)&&Se(n)});let Ce=w.at(-1),we=e=>S(x.includes(e)?x.filter(t=>t!==e):[...x,e]),Te=fe.getHeaderGroups().flatMap(e=>e.headers.map(e=>({spec:C.find(t=>t.id===e.column.id),sorted:e.column.getIsSorted(),onSort:t=>e.column.getToggleSortingHandler()?.(t)}))),Ee=FD(C,I,ge,_e),De=v===`own`,Oe=(0,B.jsx)(`div`,{ref:ye,className:z(`sticky z-20 shrink-0 overflow-hidden`,De?`top-0`:`top-[var(--pb-sticky-top,0px)]`),children:(0,B.jsx)(`div`,{style:{minWidth:Ee},children:(0,B.jsx)(GD,{cells:Te,specs:C,gutter:I,trailing:ge,minScale:_e,pins:xe,lastPinned:Ce,scrolled:ve.scrolled,onTogglePin:we,selectable:g,selectedCount:me,onClearSelection:()=>j({})})})}),ke=(0,B.jsx)(`div`,{ref:ve.attach,onScroll:be,className:`overflow-x-auto overflow-y-hidden overscroll-x-contain [-webkit-overflow-scrolling:touch]`,children:(0,B.jsx)(`div`,{ref:re,className:`relative`,style:{minWidth:Ee,height:ae.contentHeight},children:de.map(({index:e,offset:t,row:n})=>{let r={specs:C,gutter:I,index:e,offset:t,height:b,selectable:g,trailing:ge,minScale:_e,scrolled:ve.scrolled,pins:xe,lastPinned:Ce},i=n?pe.get(n.id):void 0;if(!i)return(0,B.jsx)(QD,{...r},`skeleton-${e}`);let a=ge&&n?ED(u,n):[];return(0,B.jsx)(XD,{...r,selected:i.getIsSelected(),onToggle:()=>i.toggleSelected(),onOpen:l&&n?()=>l(n):void 0,menu:n&&a.length>0?(0,B.jsx)(kD,{row:n,actions:a}):void 0,cells:i.getAllCells().map(e=>({spec:C.find(t=>t.id===e.column.id),content:(0,B.jsx)(fe.FlexRender,{cell:e})}))},n?.id)})})});return(0,B.jsxs)(`div`,{role:`grid`,"aria-rowcount":T,className:z(`flex flex-col rounded-lg border bg-background`,De?`min-h-0 overflow-hidden`:`overflow-clip`,y),style:_&&De?{height:gO+T*b+2}:void 0,children:[(0,B.jsxs)(`div`,{className:z(`relative`,De&&`flex min-h-0 flex-1 flex-col`),children:[De?(0,B.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overflow-x-hidden`,children:[Oe,ke]}):(0,B.jsxs)(B.Fragment,{children:[Oe,ke]}),ve.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`})]}),!_&&(0,B.jsx)(TD,{total:T,className:De?void 0:`sticky bottom-[var(--pb-sticky-bottom,0px)] z-20`,selectedCount:me,bulkActions:d?.map(e=>({label:e.label(me),destructive:e.destructive,onRun:()=>{e.onRun(Object.keys(A).flatMap(e=>he.current.get(e)??[])),j({}),he.current.clear()}}))})]})},vO=`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`,yO=({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)(ht,{className:`size-3 text-muted-foreground`}),e]},e)),e.map(e=>(0,B.jsxs)(`span`,{className:vO,children:[e.label,(0,B.jsx)(`button`,{type:`button`,"aria-label":`Remove ${e.label}`,onClick:()=>n(e.key),className:`rounded-full p-0.5 hover:bg-primary-border/60`,children:(0,B.jsx)(Nn,{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:`Clear all`})]}),bO=[`7d`,`30d`,`year`],xO={today:`Today`,yesterday:`Yesterday`,"7d":`Last 7 days`,"30d":`Last 30 days`,"90d":`Last 90 days`,month:`This month`,quarter:`This quarter`,year:`This year`},SO=({value:e,presets:t=bO,onChange:n})=>(0,B.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:t.map(t=>{let r=xO[t];return(0,B.jsx)(`button`,{type:`button`,disabled:!r,title:r?void 0:`The server offers the preset "${t}", which this UI does not know`,onClick:()=>n(e===t?void 0:t),className:z(`h-7 rounded-md border px-2.5 text-xs 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??`${t} (unsupported)`},t)})}),CO={facets:{},toggles:[]},wO=(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}}},TO=(e,t)=>({...e,toggles:e.toggles.includes(t)?e.toggles.filter(e=>e!==t):[...e.toggles,t]}),EO=(e,t,n)=>{let{[t]:r,...i}=e.ranges??{};return{...e,ranges:n?{...i,[t]:n}:i}},DO=(e,t)=>e.options.find(e=>e.value===t)?.label??e.labels?.[t]??t,OO=(e,t)=>{let n=e.facets.flatMap(e=>(t.facets[e.id]??[]).map(t=>({key:`facet:${e.id}:${t}`,label:`${e.label}: ${DO(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:xO[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]},kO=(e,t)=>{if(t===`date`)return{...e,date:void 0};let[n,r,i]=t.split(`:`);if(n===`range`)return EO(e,r,void 0);if(n===`toggle`)return TO(e,r);if(n===`facet`)return wO(e,r,i);throw Error(`Unknown filter chip key: ${t}`)},AO=(e,t)=>e.toLowerCase().includes(t.trim().toLowerCase()),jO=(e,t)=>e.onSearch?e.options:e.options.filter(e=>AO(e.label,t)),MO=(e,t,n)=>t===0?-1:n===`ArrowDown`?e<0?0:(e+1)%t:e<0?t-1:(e-1+t)%t,NO=({config:e,selected:t,onToggle:n,inline:r=!1})=>{let i=(0,o.useId)(),a=(0,o.useRef)(null),[s,c]=(0,o.useState)(``),[l,u]=(0,o.useState)(!1),[d,f]=(0,o.useState)(-1),p=r||l,m=jO(e,s),h=(0,o.useRef)(e.onSearch);h.current=e.onSearch,(0,o.useEffect)(()=>()=>h.current?.(``),[]);let g=t=>{c(t),f(-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)(qt,{className:`size-3.5 shrink-0 text-muted-foreground`}),t.map(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:DO(e,t)}),(0,B.jsx)(`button`,{type:`button`,"aria-label":`Remove ${DO(e,t)}`,className:`rounded p-0.5 hover:bg-primary-border/60`,onMouseDown:e=>e.preventDefault(),onClick:()=>n(t),children:(0,B.jsx)(Nn,{className:`size-3`})})]},t)),(0,B.jsx)(`input`,{ref:a,autoFocus:r,role:`combobox`,"aria-label":e.label,"aria-expanded":p,"aria-controls":`${i}-options`,"aria-autocomplete":`list`,"aria-activedescendant":m[d]?`${i}-${d}`:void 0,placeholder:t.length>0?``:`Search ${e.label.toLowerCase()}`,className:`h-6 min-w-16 flex-1 bg-transparent text-[13px] text-foreground outline-none placeholder:text-faint-foreground`,value:s,onChange:e=>g(e.target.value),onKeyDown:e=>{if(e.key===`ArrowDown`||e.key===`ArrowUp`){e.preventDefault(),f(MO(d,m.length,e.key));return}if(e.key===`Enter`&&m[d]){e.preventDefault(),n(m[d].value);return}if(e.key===`Backspace`&&s===``&&t.length>0){n(t[t.length-1]);return}e.key===`Escape`&&s!==``&&(e.stopPropagation(),g(``))},onFocus:()=>u(!0),onBlur:()=>{u(!1),f(-1),!r&&s!==``&&g(``)}})]}),p&&(0,B.jsxs)(`ul`,{id:`${i}-options`,role:`listbox`,"aria-label":e.label,"aria-multiselectable":!0,className:z(`flex max-h-60 flex-col gap-px overflow-y-auto`,!r&&`rounded-md border bg-background p-1 shadow-sm`),children:[m.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:z(`flex cursor-pointer items-center gap-2 rounded px-1.5 py-1 hover:bg-muted`,r===d&&`bg-muted`),onMouseDown:e=>e.preventDefault(),onClick:()=>n(e.value),children:[(0,B.jsx)(`span`,{className:z(`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)(de,{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:Af(e.count)})]},e.value)}),m.length===0&&(0,B.jsx)(`li`,{className:`px-1.5 py-1 text-xs text-faint-foreground`,children:`No matches`})]})]})},PO=({config:e,selected:t,onToggle:n})=>{let[r,i]=(0,o.useState)(``),a=e.options.filter(e=>AO(e.label,r));return(0,B.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[e.searchable&&(0,B.jsx)(Yd,{wrapperClassName:`mb-1 h-7`,leading:(0,B.jsx)(qt,{className:`size-3.5`}),placeholder:`Search ${e.label.toLowerCase()}`,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)(Yh,{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:Af(e.count)})]},e.value)),a.length===0&&(0,B.jsx)(`span`,{className:`px-1 py-1 text-xs text-faint-foreground`,children:`No matches`})]})},FO=({label:e,activeCount:t,width:n=240,defaultOpen:r=!1,children:i})=>{let[a,s]=(0,o.useState)(r),[c,l]=(0,o.useState)(!1),u=(0,o.useRef)(null);return(0,o.useLayoutEffect)(()=>{a&&u.current&&l(u.current.getBoundingClientRect().left+n>document.documentElement.clientWidth)},[a,n]),(0,o.useEffect)(()=>{if(!a)return;let e=e=>{e.target instanceof Node&&!u.current?.contains(e.target)&&s(!1)};return document.addEventListener(`pointerdown`,e),()=>document.removeEventListener(`pointerdown`,e)},[a]),(0,B.jsxs)(`div`,{ref:u,className:`relative`,children:[(0,B.jsxs)(`button`,{type:`button`,"aria-expanded":a,onClick:()=>s(!a),className:z(`inline-flex h-8 items-center gap-1.5 rounded-md border bg-background px-2.5 text-[13px] 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)(pe,{className:`size-3.5 text-muted-foreground`})]}),a&&(0,B.jsx)(`div`,{className:z(`absolute top-full z-30 mt-1.5 rounded-lg border bg-background p-3 shadow-pop`,c?`right-0`:`left-0`),style:{width:n},children:i})]})},IO=({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]}),LO=(e,t)=>{let[n,r]=(0,o.useState)(e);return(0,o.useEffect)(()=>{let n=setTimeout(()=>r(e),t);return()=>clearTimeout(n)},[e,t]),n},RO=(e,t,n,r,i)=>{let a=n+(r-n)*e/t;return n+(r-n)*(e+1)/t>i[0]&&a<i[1]},zO=(e,t,n)=>n===t?0:(e-t)/(n-t),BO=(e,t,n)=>t===0?[Math.min(n,e[1]),e[1]]:[e[0],Math.max(n,e[0])],VO=1e3,HO=({config:e,value:t,onChange:n})=>{let{min:r,max:i,step:a,histogram:s,format:c}=e,[l,u]=(0,o.useState)(),d=l??t??[r,i],f=Math.max(...s),p=()=>{l&&(u(void 0),n(l[0]===r&&l[1]===i?void 0:l))},m=LO(l,VO);return(0,o.useEffect)(()=>{m&&p()},[m]),(0,B.jsxs)(`div`,{className:`w-full`,children:[(0,B.jsxs)(`div`,{className:`px-[7px]`,children:[s.length>0&&(0,B.jsx)(`div`,{className:`mb-1 flex h-12 items-end gap-0.5`,children:s.map((e,t)=>(0,B.jsx)(`span`,{className:z(`flex-1 rounded-t-sm`,RO(t,s.length,r,i,d)?`bg-primary/70`:`bg-border`),style:{height:`${Math.max(6,e/f*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:`${zO(d[0],r,i)*100}%`,right:`${100-zO(d[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":`${e.label} ${t===0?`minimum`:`maximum`}`,min:r,max:i,step:a,value:d[t],onChange:e=>u(BO(d,t,Number(e.target.value))),onPointerUp:p,onTouchEnd:p,onBlur:p},t))}),(0,B.jsxs)(`div`,{className:`mt-2 flex justify-between text-xs tabular-nums text-muted-foreground`,children:[(0,B.jsx)(`span`,{children:c(d[0])}),(0,B.jsx)(`span`,{children:c(d[1])})]})]})},UO=({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)(H_,{checked:t,onChange:n,label:e})]}),WO=(e,t)=>e.some(e=>e.length>0)||!!t,GO=({groups:e,trailing:t})=>{if(!WO(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)(o.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})]})},KO=(e,t,n)=>{let[r,i]=(0,o.useState)(t??CO);return[e??r,e=>{i(e),n?.(e)}]},qO=({config:e,layout:t,value:n,defaultValue:r,onChange:i,lockedLabels:a,defaultOpenMenu:s,fullWidth:c,leading:l,trailing:u})=>{let[d,f]=KO(n,r,i),p=OO(e,d),m=(0,B.jsx)(yO,{chips:p,lockedLabels:a,onRemove:e=>f(kO(d,e)),onClear:()=>f(CO)}),h=(e,t=!1)=>{let n=d.facets[e.id]??[],r=t=>f(wO(d,e.id,t));return e.combobox?(0,B.jsx)(NO,{config:e,selected:n,onToggle:r,inline:t}):(0,B.jsx)(PO,{config:e,selected:n,onToggle:r})},g=e.ranges??[],_=e=>(0,B.jsx)(HO,{config:e,value:d.ranges?.[e.id],onChange:t=>f(EO(d,e.id,t))}),v=e.datePresets&&(0,B.jsx)(SO,{value:d.date,presets:Array.isArray(e.datePresets)?e.datePresets:void 0,onChange:e=>f({...d,date:e})}),y=(e.toggles??[]).map(e=>(0,B.jsx)(UO,{label:e.label,checked:d.toggles.includes(e.id),onChange:()=>f(TO(d,e.id))},e.id));if(t===`panel`)return(0,B.jsxs)(`aside`,{className:c?`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:`text-[13px] font-semibold`,children:`Filters`})}),(p.length>0||(a?.length??0)>0)&&(0,B.jsx)(`div`,{className:`border-b pb-3`,children:m}),l,e.facets.map(e=>(0,B.jsx)(IO,{title:e.label,children:h(e)},e.id)),g.map(e=>(0,B.jsx)(IO,{title:e.label,children:_(e)},e.id)),v&&(0,B.jsx)(IO,{title:`Date`,children:v}),y.length>0&&(0,B.jsx)(IO,{title:`Show only`,children:y})]});let b=[...e.facets.map(e=>(0,B.jsx)(FO,{label:e.label,activeCount:(d.facets[e.id]??[]).length,width:e.combobox?280:void 0,defaultOpen:s===e.id,children:h(e,!0)},e.id)),...g.map(e=>(0,B.jsx)(FO,{label:e.label,activeCount:+!!d.ranges?.[e.id],width:280,defaultOpen:s===e.id,children:_(e)},`range:${e.id}`)),...v?[(0,B.jsx)(o.Fragment,{children:v},`date`)]:[]],x=(e.toggles??[]).map(e=>(0,B.jsx)(`div`,{className:`flex items-center gap-2 text-[13px] text-muted-foreground`,children:(0,B.jsx)(UO,{label:e.label,checked:d.toggles.includes(e.id),onChange:()=>f(TO(d,e.id))})},e.id)),S=[l?[(0,B.jsx)(o.Fragment,{children:l},`leading`)]:[],b,x];return!WO(S,u)&&p.length===0&&!a?.length?null:(0,B.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,B.jsx)(GO,{groups:S,trailing:u}),m]})},JO={draft:`neutral`,confirmed:`blue`,picking:`amber`,shipped:`violet`,delivered:`green`,cancelled:`red`,sent:`blue`,paid:`green`,overdue:`red`,lead:`blue`,active:`green`,dormant:`neutral`,receipt:`green`,issue:`blue`,transfer:`violet`,adjustment:`amber`},YO=e=>JO[e]??`neutral`,XO={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},ZO=(e,t)=>Math.ceil(e.length*7.2)+24+(t?16:0)+28,QO=e=>Math.ceil(Math.max(0,...e.map(e=>e.length))*7.2)+56,$O=new Set([`datetime`,`date`,`boolean`,`percent`]),ek=/^(number|sku|reference|code)$/,tk=(e,t,n)=>{switch(e.type){case`relation`:return`relation`;case`file`:return`file`;case`enum`:return`status`;case`boolean`:return`boolean`;case`timestamp`:return`datetime`;case`date`:return`date`;case`decimal`:return t?.format===`percent`?`percent`:t?.prefix===`€`?`money`:`number`;case`integer`:case`bigint`:return/quantity|delta/.test(e.name)?`signed`:`number`;default:return ek.test(e.name)||n===0&&e.name===`id`?`id`:`text`}},nk=e=>Math.round(Number.parseFloat(String(e))*100),rk=(e,t)=>t?.list?.columns??Object.keys(e.fields).slice(0,6),ik=(e,t,n=[],r=rk(e,t))=>r.flatMap((r,i)=>{let a=e.fields[r];if(!a)return[];let o=t?.fields[r],s=tk(a,o,i),c=Object.fromEntries((a.enumValues??[]).map(e=>[e,Bo(e,o?.valueLabels)])),l=o?.suffix?Math.ceil(o.suffix.length*7.2):0;return[{id:r,header:o?.label??G(r),kind:s,width:(r===`name`?260:XO[s])+l,sortable:a.sortable,minWidth:Math.max(s===`id`?150:0,ZO(o?.label??G(r),a.sortable),s===`status`?QO(Object.values(c)):0,l>0?XO[s]+l:0),...$O.has(s)&&{fixed:!0},...n.includes(r)&&{highlight:!0},...a.type===`enum`&&{tones:Object.fromEntries((a.enumValues??[]).map(e=>[e,YO(e)])),labels:c},...a.type===`enum`&&o?.valueColors&&{colors:o.valueColors},...a.type===`enum`&&o?.badgeShape&&{shape:o.badgeShape},...o?.suffix!==void 0&&{suffix:o.suffix},...s===`money`&&o?.decimals!==void 0&&{decimals:o.decimals},...s===`money`&&{currency:`EUR`,value:e=>e[r]==null?null:nk(e[r])},...(s===`datetime`||s===`date`)&&{value:e=>e[r]==null?null:Date.parse(String(e[r]))},...(s===`percent`||s===`number`&&a.type===`decimal`)&&{value:e=>e[r]==null?null:Number(e[r])}}]}),ak=so(),ok={start:0,end:0},sk={"7d":{amount:7,unit:`d`},"30d":{amount:30,unit:`d`},"90d":{amount:90,unit:`d`}},ck=e=>new Date(e).toISOString().replace(`.000Z`,`Z`),lk=(e,t)=>{let[n,r,i]=[t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate()];return ck(e===`year`?Date.UTC(n,0,1):e===`quarter`?Date.UTC(n,Math.floor(r/3)*3,1):e===`month`?Date.UTC(n,r,1):e===`yesterday`?Date.UTC(n,r,i-1):Date.UTC(n,r,i))},uk=[`year`,`quarter`,`month`,`yesterday`,`today`],dk=(e,t)=>t===`date`?{kind:`string`,value:e.slice(0,10),span:ok}:{kind:`timestamp`,value:e,span:ok},fk=(e,t,n,r)=>{if(t in sk)return[ak.gte(e,ak.ago(t))];let i=ak.gte(e,dk(lk(t,n),r));return t===`yesterday`?[i,ak.lt(e,dk(lk(`today`,n),r))]:[i]},pk=(e,t,n=new Date)=>{let r=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=>ak.eq(e.value,!0));return t.length===0?[]:[t.length===1?t[0]:ak.or(...t)]}return[n.length===1?ak.eq(e.id,n[0]):ak.in(e.id,n)]}),i=(e.ranges??[]).flatMap(e=>{let n=t.ranges?.[e.id];return n?[ak.gte(e.id,n[0]),ak.lte(e.id,n[1])]:[]}),a=e.dateField&&t.date?fk(e.dateField,t.date,n,e.dateKind):[],o=(e.toggles??[]).filter(e=>t.toggles.includes(e.id)).map(e=>ak.eq(e.id,!0));return[...r,...i,...a,...o]},mk=e=>e.length===0?``:qa(ak.and(...e)),hk=(e,t,n=[],r=new Date)=>mk([...pk(e,t,r),...n]),gk=e=>e.kind===`and`?e.args.flatMap(gk):[e],_k=e=>e.field.path.join(`.`),vk=e=>e.kind===`compare`&&e.op===`=`&&e.value.kind===`boolean`&&e.value.value,yk=(e,t)=>{let n=e.kind===`or`?e.args:[e];if(!n.every(vk))return;let r=n.map(_k),i=t.get(r[0]);return i!==void 0&&r.every(e=>t.get(e)===i)?{group:i,fields:r}:void 0},bk=e=>e.kind===`number`?String(e.raw):e.kind===`string`?String(e.value):void 0,xk=(e,t)=>{let n=e.value;if(n.kind===`now`&&n.offset?.sign===`-`){let{amount:e,unit:t}=n.offset.duration;return Object.entries(sk).find(([,n])=>n.amount===e&&n.unit===t)?.[0]}if(n.kind===`timestamp`)return uk.find(e=>lk(e,t)===n.value);if(n.kind===`string`)return uk.find(e=>lk(e,t).slice(0,10)===n.value)},Sk=(e,t,n=new Date)=>{let r=oa(t);if(!r.ok)return{ok:!1,errors:r.errors};let i={facets:{},toggles:[]},a=[],o=new Set(e.facets.filter(e=>!e.flags).map(e=>e.id)),s=new Map(e.facets.filter(e=>e.flags).flatMap(e=>e.options.map(t=>[t.value,e.id]))),c=new Set((e.toggles??[]).map(e=>e.id)),l=new Set((e.ranges??[]).map(e=>e.id)),u=new Map,d,f;for(let t of r.ast?gk(r.ast):[]){let r=yk(t,s);if(r&&!i.facets[r.group])i.facets[r.group]=r.fields;else if(t.kind===`compare`&&o.has(_k(t))&&t.op===`=`&&bk(t.value)!==void 0)i.facets[_k(t)]=[...i.facets[_k(t)]??[],bk(t.value)];else if(t.kind===`in`&&o.has(_k(t))&&t.values.every(e=>bk(e)!==void 0))i.facets[_k(t)]=[...i.facets[_k(t)]??[],...t.values.map(e=>bk(e))];else if(t.kind===`compare`&&e.dateField===_k(t)&&t.op===`>=`&&xk(t,n)&&!i.date)i.date=xk(t,n),d=t;else if(t.kind===`compare`&&e.dateField===_k(t)&&t.op===`<`&&(t.value.kind===`timestamp`||t.value.kind===`string`)&&lk(`today`,n).startsWith(t.value.value.slice(0,10)))f=t;else if(t.kind===`compare`&&c.has(_k(t))&&t.op===`=`&&t.value.kind===`boolean`&&t.value.value)i.toggles.push(_k(t));else if(t.kind===`compare`&&l.has(_k(t))&&(t.op===`>=`||t.op===`<=`)&&t.value.kind===`number`){let e=u.get(_k(t))??{clauses:[]};t.op===`>=`?e.low=t.value.value:e.high=t.value.value,e.clauses.push(t),u.set(_k(t),e)}else a.push(t)}i.date===`yesterday`&&!f&&(a.push(d),i.date=void 0),f&&i.date!==`yesterday`&&a.push(f);for(let[e,t]of u)t.low!==void 0&&t.high!==void 0?i.ranges={...i.ranges,[e]:[t.low,t.high]}:a.push(...t.clauses);return{ok:!0,state:i,extras:a}},Ck=(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)}}))},wk=(e,t)=>[...new Set(t.filter(t=>!e.includes(t)))],Tk=so(),Ek=(e,t)=>{let n=W(),[r,i]=(0,o.useState)({}),a=e=>!!e?.search?.length&&e.primaryKey.length===1,s=Dh({queries:e.map(({id:e,target:i})=>{let o=(r[e]??``).trim();return{queryKey:[`reference-search`,e,i?.name??``,o],enabled:a(i)&&o!==``,placeholderData:Lm,queryFn:async()=>{let e=i.primaryKey[0],r=Og(i,t[i.name]);return(await n.list(i.name,{filter:qa(Tk.search(o)),fields:[e,r],pageSize:20})).items.map(t=>[String(t[e]),String(t[r])])}}})});return e.map(({id:e,target:t},n)=>{if(!a(t))return{};let o=t=>i(n=>({...n,[e]:t}));return(r[e]??``).trim()===``?{onSearch:o}:{onSearch:o,matches:s[n]?.data??[]}})},Dk=[`integer`,`bigint`,`decimal`],Ok=(e,t)=>{let n=e?.fields[t]?.type;return n!==void 0&&Dk.includes(n)},kk=(e,t)=>e.kind===`range`||e.kind===`facets`&&Ok(t,e.field),Ak=e=>({id:e,label:e,min:0,max:0,step:1,histogram:[],format:String}),jk=(e,t)=>{let n=e?.filters??[],r=n.find(e=>e.kind===`dateRange`);return{facets:n.flatMap(e=>e.kind===`facets`&&!kk(e,t)?[{id:e.field,label:e.field,options:[],searchable:e.search,...t?.fields[e.field]?.type===`relation`&&{combobox:!0}}]:e.kind===`flags`?[{id:e.fields.join(`|`),label:e.label,options:e.fields.map(e=>({value:e,label:e,count:0})),flags:!0}]:[]),ranges:n.flatMap(e=>e.kind!==`flags`&&kk(e,t)?[Ak(e.field)]:[]),...r&&{dateField:r.field,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}]:[])}},Mk=(e,t)=>(e?.filters??[]).some(e=>e.kind===`range`&&e.field===t&&e.histogram),Nk=(e,t)=>{let n=e?.fields[t],r=n?.suffix??``;return e=>`${n?.prefix===`€`?Of(e*100).replace(`.00`,``):String(e)}${r}`},Pk=24,Fk=({model:e,resources:t,views:n,view:r,state:i,extras:a})=>{let o=W(),s=pm(),c=jk(r,e),l=e=>r?.fields[e]?.label??G(e),u=n=>{let r=e.fields[n];return r?.type===`relation`&&r.relation?t[r.relation.resource]:void 0},d=c.facets.flatMap(e=>(e.flags?e.options.map(e=>e.value):[e.id]).map(t=>({group:e.id,field:t}))),f=Dh({queries:d.map(({group:t,field:r})=>{let s=hk(c,{...i,facets:{...i.facets,[t]:[]}},a),l=u(r),d=l?.primaryKey.length===1?Og(l,n[l.name]):void 0;return{queryKey:U.facets(e.name,r,s),queryFn:()=>o.facets(e.name,r,{filter:s,limit:50,...d&&{label:d}})}})}),p=(e,t)=>f[d.findIndex(n=>n.group===e&&n.field===t)]?.data,m=Dh({queries:c.facets.map(t=>{let r=u(t.id),a=wk((p(t.id,t.id)??[]).flatMap(e=>e.value===null?[]:[String(e.value)]),i.facets[t.id]??[]);return{queryKey:U.labels(`facet:${e.name}.${t.id}`,a.join(`,`)),enabled:!!r&&a.length>0,queryFn:async()=>[...await R_(s,o,r,a,n[r.name])]}})}),h=Ek(c.facets.map(e=>({id:e.id,target:e.combobox?u(e.id):void 0})),n),g=c.ranges??[],_=Dh({queries:g.map(t=>{let n=hk(c,EO(i,t.id,void 0),a),s=Mk(r,t.id)?Pk:1;return{queryKey:U.histogram(e.name,t.id,s,n),queryFn:()=>o.histogram(e.name,t.id,{filter:n,buckets:s})}})});return{facets:c.facets.map((t,n)=>{if(t.flags){let e=t.options.map(({value:e})=>({value:e,label:l(e),count:p(t.id,e)?.find(e=>String(e.value)===`true`)?.count??0}));return{...t,options:e}}let i=e.fields[t.id],a=(p(t.id,t.id)??[]).flatMap(e=>e.label===void 0?[]:[[String(e.value),e.label]]),o=new Map([...a,...m[n]?.data??[]]),s=(p(t.id,t.id)??[]).flatMap(e=>e.value===null?[]:[{value:String(e.value),label:i?.type===`enum`?Bo(String(e.value),r?.fields[t.id]?.valueLabels):o.get(String(e.value))??String(e.value),count:e.count}]),c=h[n];return{...t,label:l(t.id),options:c.matches?Ck(c.matches,s):s,...o.size>0&&{labels:Object.fromEntries(o)},...c.onSearch&&{onSearch:c.onSearch}}}),ranges:g.flatMap((e,t)=>{let n=_[t]?.data;return!n||n.min===null||n.max===null?[]:[{...e,label:l(e.id),min:Math.floor(n.min),max:Math.ceil(n.max),step:Math.max(1,Math.round((n.max-n.min)/100)),histogram:Mk(r,e.id)?n.buckets.map(e=>e.count):[],format:Nk(r,e.id)}]}),...c.dateField&&{datePresets:c.datePresets??!0,dateField:c.dateField,dateKind:c.dateKind},toggles:c.toggles?.map(e=>({...e,label:l(e.id)}))}},Ik=5e3,Lk=({queryClient:e,client:t,resources:n,views:r,model:i,columns:a,filter:o,orderBy:s})=>{let c=e=>U.page(i.name,o,s,40,e),l=B_(n,r,i,a),u=cv(r[i.name]),d=async e=>e.nextPageToken===``?e.items.length:e.totalSizeEstimate>Ik?e.totalSizeEstimate:(await t.list(i.name,{filter:o,orderBy:s,pageSize:1,count:`exact`})).totalSize??e.totalSizeEstimate,f=async t=>{if(t===0)return``;let n=c(t-1),r=e.getQueryData(n);if(r)return r.nextPageToken;if(e.getQueryState(n)?.fetchStatus===`fetching`)return(await m(t-1)).nextPageToken},p=async e=>{let r=await f(e);if(e>0&&r===``)return{rows:[],total:0,nextPageToken:``};let c={filter:o,orderBy:s,pageSize:40,labels:l,photos:u},p=r===void 0?await t.seek(i.name,{...c,position:e*40}):await t.list(i.name,{...c,pageToken:r});if(p.items.length===0&&e>0)return{rows:[],total:0,nextPageToken:``};let m=p.items.map(e=>jg(i,e));return{rows:V_(n,i,a,lv(i,p.items,p.photos),p.labels).map((e,t)=>({...e,id:m[t]})),total:e===0?await d(p):p.totalSizeEstimate,nextPageToken:p.nextPageToken}},m=t=>e.fetchQuery({queryKey:c(t),staleTime:6e4,queryFn:()=>p(t)});return{page:m,loadRows:async e=>(await m(Math.floor(e/40))).rows}},Rk=({resources:e,views:t,model:n,columns:r,filter:i,orderBy:a})=>{let s=W(),c=pm(),l=r.join(`,`),u=(0,o.useMemo)(()=>Lk({queryClient:c,client:s,resources:e,views:t,model:n,columns:r,filter:i,orderBy:a}),[c,s,e,t,n,l,i,a]),d=kh({queryKey:[...U.first(n.name,i,a),l],queryFn:()=>u.page(0)});return{source:(0,o.useMemo)(()=>d.data?{total:d.data.total,loadRows:u.loadRows}:void 0,[d.data,u]),error:d.error,isLoading:d.isLoading,page:u.page,key:[...U.first(n.name,i,a),l]}},zk=({title:e,open:t,onClose:n,children:r})=>{let i=(0,o.useRef)(null);return $u(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 shadow-pop outline-none`,children:[(0,B.jsxs)(`header`,{className:`flex shrink-0 items-center justify-between border-b px-4`,children:[(0,B.jsx)(`h2`,{className:`text-[15px] font-semibold`,children:e}),(0,B.jsx)(`button`,{type:`button`,"aria-label":`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)(Nn,{className:`size-5`})})]}),(0,B.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overscroll-contain px-4 pb-6`,children:r})]})]}):null},Bk=({title:e,noun:t,busy:n,onConfirm:r,onCancel:i})=>(0,B.jsx)(Kf,{title:`Delete ${e}?`,description:`This ${t.toLowerCase()} will be removed. This cannot be undone.`,onClose:i,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(H,{onClick:i,children:`Cancel`}),(0,B.jsx)(H,{variant:`primary`,className:`bg-danger hover:bg-danger/90`,loading:n,onClick:r,children:`Delete`})]})}),Vk=({title:e,changes:t,busy:n,onReview:r,onDeleteAnyway:i,onCancel:a})=>(0,B.jsx)(Kf,{title:`${e} was changed since you opened it`,description:`Someone saved this record in the meantime. Review what changed before you delete it.`,onClose:a,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(H,{onClick:r,children:`Review changes`}),(0,B.jsx)(H,{variant:`primary`,className:`bg-danger hover:bg-danger/90`,loading:n,onClick:i,children:`Delete anyway`})]}),children:t.length===0?(0,B.jsx)(`p`,{className:`text-[13px] text-muted-foreground`,children:`No visible fields differ; the record was saved again with the same values.`}):(0,B.jsx)(`ul`,{className:`divide-y rounded-md border text-[13px]`,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))})}),Hk=e=>{if(e.stage===`confirm`)return(0,B.jsx)(Kf,{title:`Delete ${e.count} ${e.count===1?e.plural.replace(/s$/,``):e.plural.toLowerCase()}?`,description:`This cannot be undone. Each record is deleted only if it has not changed since the list loaded; anything that changed is reported and kept.`,onClose:e.onCancel,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(H,{onClick:e.onCancel,children:`Cancel`}),(0,B.jsxs)(H,{variant:`primary`,className:`bg-danger hover:bg-danger/90`,onClick:e.onConfirm,children:[`Delete `,e.count]})]})});if(e.stage===`running`)return(0,B.jsx)(Kf,{title:`Deleting`,description:`${e.done} of ${e.total} done`,onClose:()=>void 0,actions:(0,B.jsx)(H,{loading:!0,disabled:!0,children:`Working`})});let t=e.total-e.failures.length;return(0,B.jsx)(Kf,{title:e.failures.length===0?`Deleted ${t}`:`Deleted ${t} of ${e.total}`,description:e.failures.length===0?void 0:`${e.failures.length} could not be deleted and were kept.`,onClose:e.onClose,actions:(0,B.jsx)(H,{variant:`primary`,onClick:e.onClose,children:`Done`}),children:e.failures.length>0&&(0,B.jsx)(`ul`,{className:`max-h-48 divide-y overflow-y-auto rounded-md border text-[13px]`,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))})})},Uk=new Set([`updated_at`,`updatedAt`]),Wk=(e,t,n,r)=>Object.values(e.fields).flatMap(e=>{if(Uk.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??G(e.name),before:ov(e,n[e.name],i),after:ov(e,r[e.name],i)}]}),Gk=4,Kk=({model:e,view:t,onDeleted:n,onReview:r,restore:i})=>{let a=W(),s=pm(),c=Kg(),[l,u]=(0,o.useState)(),[d,f]=(0,o.useState)(!1),p=t?.names?.singular??G(e.name),m=t?.names?.plural??G(e.name),h=()=>{for(let t of[`page`,`list`,`first-page`,`map`])s.invalidateQueries({queryKey:[t,e.name]});for(let t of[`facets`,`series`,`histogram`])s.invalidateQueries({queryKey:[t,e.name]})},g=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 _s))throw e;return e}},_=t=>{h(),u(void 0),n?.(t),c.show({state:`success`,title:`${t.title} deleted`,...e.softDelete&&i&&{action:{label:`Undo`,onClick:()=>{i(t).then(()=>{h(),c.show({state:`success`,title:`${t.title} restored`})},e=>{if(!vs(e))throw e;h(),c.show({state:e.status===409?`success`:`error`,title:e.status===409?`${t.title} is already back`:`Could not restore ${t.title}`,description:e.status===409?void 0:e.message})})}}}})},v=async(n,r)=>{f(!0);try{if(!await g(n,r))return _(n);let i=(await a.get(e.name,n.key)).record;u({kind:`conflict`,target:n,fresh:i,changes:Wk(e,t,n.snapshot,i)})}catch(e){if(!vs(e))throw e;u(void 0),c.show({state:`error`,title:`Could not delete ${n.title}`,description:e.message})}finally{f(!1)}},y=async e=>{try{return await g(e,e.etag)?{title:e.title,message:`Changed since the list loaded, so it was kept.`}:void 0}catch(t){if(!vs(t))throw t;return{title:e.title,message:t.message}}},b=async e=>{let t=[],n=0;u({kind:`bulk-running`,done:n,total:e.length});let r=[...e];await Promise.all(Array.from({length:Math.min(Gk,e.length)},async()=>{for(let i=r.shift();i;i=r.shift()){let r=await y(i);r&&t.push(r),n+=1,u({kind:`bulk-running`,done:n,total:e.length})}})),h(),u({kind:`bulk-done`,total:e.length,failures:t})},x=()=>u(void 0);return{dialogs:l&&(0,B.jsxs)(B.Fragment,{children:[l.kind===`confirm`&&(0,B.jsx)(Bk,{title:l.target.title,noun:p,busy:d,onCancel:x,onConfirm:()=>void v(l.target,l.target.etag)}),l.kind===`conflict`&&(0,B.jsx)(Vk,{title:l.target.title,changes:l.changes,busy:d,onCancel:x,onReview:()=>{x(),r?.(l.target,l.fresh)},onDeleteAnyway:()=>void v(l.target,`*`)}),l.kind===`bulk-confirm`&&(0,B.jsx)(Hk,{stage:`confirm`,count:l.targets.length,plural:m,onCancel:x,onConfirm:()=>void b(l.targets)}),l.kind===`bulk-running`&&(0,B.jsx)(Hk,{stage:`running`,done:l.done,total:l.total}),l.kind===`bulk-done`&&(0,B.jsx)(Hk,{stage:`done`,total:l.total,failures:l.failures,onClose:x})]}),start:t=>e.softDelete?v(t,t.etag):u({kind:`confirm`,target:t}),startBulk:e=>u({kind:`bulk-confirm`,targets:e})}},qk=e=>{let t=W();return e.softDelete?async n=>void await t.undelete(e.name,n.key):void 0},Jk={wallet:cee,"file-text":Xe,send:oee,ruler:Gt,bed:O,heart:$e,bell:A,bookmark:re,"external-link":Ue},Yk=e=>e!==void 0&&Object.hasOwn(Jk,e)?Jk[e]:void 0,Xk=({title:e,description:t,open:n,onClose:r,actions:i,children:a,wide:o})=>{let s=Gu();return n?s?(0,B.jsx)(Kf,{title:e,description:t,onClose:r,actions:i,wide:o,children:a}):(0,B.jsx)(zk,{title:e,open:!0,onClose:r,children:(0,B.jsxs)(`div`,{className:`pt-3 text-[13px]`,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},Zk=({benefits:e})=>e&&e.length>0?(0,B.jsx)(`ul`,{className:`flex flex-col gap-2 text-left text-[13px]`,children:e.map(e=>(0,B.jsxs)(`li`,{className:`flex items-start gap-2`,children:[(0,B.jsx)(de,{className:`mt-0.5 size-4 shrink-0 text-primary`,"aria-hidden":!0}),e]},e))}):null,Qk=({prompt:e})=>{let{canSignUp:t}=V(),{link:n}=$h(),r=Gf({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)(ld,{to:n(`sign-up`),className:r,children:`Create an account`});return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(ld,{to:n(),className:i?Gf():r,children:`Sign in`}),i]})},$k=e=>{let{prompt:t}=e,n=(0,o.useId)();if(e.as===`dialog`)return(0,B.jsx)(Xk,{title:t.title,description:t.description,open:e.open,onClose:e.onClose,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(H,{onClick:e.onClose,children:`Not now`}),(0,B.jsx)(Qk,{prompt:t})]}),children:(0,B.jsx)(Zk,{benefits:t.benefits})});let r=Yk(t.icon)??_t;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-[13px] text-muted-foreground`,children:t.description})]}),(0,B.jsx)(Zk,{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)(Qk,{prompt:t})})]})},eA=(e,t)=>({model:e,record:t,key:mo(Mg(e,t)),etag:typeof t.etag==`string`?t.etag:void 0,permissions:t.permissions}),tA=(e,t,n=``)=>({queryKey:U.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}}),nA=(e,t=``)=>kh(tA(W(),e,t)),rA=(e,{filter:t=``,sort:n=``,key:r})=>{let i=W();return kh({queryKey:r===void 0?U.firstRecord(e.name,t,n):U.record(e.name,r),queryFn:async()=>{if(r!==void 0){let t=await i.get(e.name,r);return{...eA(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]?eA(e,a.items[0]):null}})},iA=(e,{filter:t=``,sort:n=``,pageSize:r,pageToken:i=``})=>{let a=W();return kh({queryKey:U.list(e.name,t,n,r,i),placeholderData:Lm,queryFn:()=>a.list(e.name,{filter:t||void 0,orderBy:n||void 0,pageSize:r,pageToken:i||void 0})})},aA=()=>{let e=pm();return(0,o.useCallback)(t=>e.invalidateQueries({predicate:e=>e.queryKey[1]===t}),[e])},oA=so(),sA=e=>{if(typeof e==`string`||typeof e==`number`)return e;if(e&&typeof e==`object`&&`id`in e)return sA(e.id)},cA=(e,t,n)=>n.flatMap(n=>{let r=sA(n[t]);return r===void 0?[]:[{key:mo(Mg(e,n)),target:r}]}),lA=(e,t)=>e.find(e=>mo(e.target)===t),uA=(e,t)=>[...e,{key:``,target:t}],dA=(e,t)=>e.filter(e=>mo(e.target)!==t),fA=(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:oA.in(n,r)},pA=(e,t)=>U.list(e,``,``,500,`saved:${t}`),mA=(e,t,n)=>{let r=W(),i=K().resources[e];return kh({queryKey:pA(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 cA(i,t,n)}})},hA=e=>e instanceof Error?e.message:`Something went wrong`,gA=(e,t,n)=>{let r=K(),i=W(),a=pm(),o=Kg(),s=aA(),{resource:c,field:l}=e,u=r.permissions[c],d=r.resources[c]!==void 0&&u!==void 0&&Ey(u,`create`)&&Ey(u,`delete`),f=r.signIn?.[c]?.signIn,p=mA(c,l,d),m=p.data&&lA(p.data,t),h=pA(c,l),g=Ah({mutationFn:async e=>{e?await i.remove(c,e.key):await i.create(c,{[l]:n})},onMutate:async e=>{await a.cancelQueries({queryKey:h,exact:!0});let r=a.getQueryData(h);return a.setQueryData(h,(r=[])=>e?dA(r,t):uA(r,n)),{before:r}},onError:(e,t,n)=>{a.setQueryData(h,n?.before),o.show({state:`error`,title:t?`Could not take it off`:`Could not save it`,description:hA(e)})},onSettled:()=>s(c)});return{mode:d?`save`:f?`sign-in`:void 0,prompt:f,saved:m!==void 0,ready:p.data!==void 0&&!g.isPending,toggle:()=>g.mutate(m)}},_A=({favorite:e,recordKey:t,target:n,className:r})=>{let i=gA(e,t,n),[a,s]=(0,o.useState)(!1);if(!i.mode)return null;let c=e.label??`Favorite`,l=z(`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":c,"aria-haspopup":`dialog`,className:l,onClick:()=>s(!0),children:(0,B.jsx)($e,{className:`size-4`,"aria-hidden":!0})}),(0,B.jsx)($k,{as:`dialog`,prompt:i.prompt,open:a,onClose:()=>s(!1)})]}):(0,B.jsx)(`button`,{type:`button`,"aria-label":c,"aria-pressed":i.saved,"aria-disabled":!i.ready,className:l,onClick:()=>i.ready&&i.toggle(),children:(0,B.jsx)($e,{className:z(`size-4`,i.saved&&`fill-current text-danger`),"aria-hidden":!0})})},vA=({value:e,hints:t,children:n})=>(0,B.jsx)(Cd,{tone:YO(String(e)),color:vD(t?.valueColors,e),shape:t?.badgeShape,children:n}),yA=({value:e})=>{let t=tv(e,{width:320,height:240});return t?(0,B.jsx)(py,{image:t,loading:`lazy`,className:`size-full object-cover`}):null},bA=({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}),xA=({value:e})=>(0,B.jsx)(bA,{children:(0,B.jsx)(yA,{value:e})}),SA=10,CA=(e,t)=>{let n=G_(e)?e.uri:void 0,r=t.filter(e=>G_(e)&&e.uri!==n);return(n===void 0?r:[e,...r]).slice(0,SA)},wA=(e,t)=>t===0?0:(e%t+t)%t,TA=(e,t,n)=>t<=0||n===0?0:Math.min(n-1,Math.max(0,Math.round(e/t))),EA=`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-has-[[data-card-photos]:hover]/card:opacity-100 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`,DA=`[@media(hover:none)]:opacity-100`,OA=({photos:e,cover:t,swipe:n=!0,children:r})=>{let i=(0,o.useRef)(null),a=(0,o.useRef)(void 0),[s,c]=(0,o.useState)(0),l=CA(t,e),u=e=>{let t=i.current;t&&t.scrollTo({left:e*t.clientWidth})},d=e=>{a.current=wA((a.current??s)+e,l.length),u(a.current)},f=()=>{a.current=void 0},p=e=>{c(TA(e.scrollLeft,e.clientWidth,l.length)),a.current!==void 0&&Math.abs(e.scrollLeft-a.current*e.clientWidth)<1&&(a.current=void 0)},m=(0,B.jsx)(bA,{children:(0,B.jsx)(`span`,{ref:i,tabIndex:-1,"data-card-photos":!0,onPointerDown:f,onScroll:e=>p(e.currentTarget),className:z(`flex size-full snap-x snap-mandatory outline-none [scrollbar-width:none] motion-safe:scroll-smooth [&::-webkit-scrollbar]:hidden`,n?`overflow-x-auto overscroll-x-contain`:`overflow-x-hidden`),children:l.map((e,t)=>(0,B.jsx)(`span`,{className:`block size-full shrink-0 snap-start snap-always`,children:(0,B.jsx)(yA,{value:e})},t))})});return(0,B.jsxs)(B.Fragment,{children:[r(m),l.length>1&&(0,B.jsxs)(`div`,{className:`group/arrows pointer-events-none absolute inset-x-px top-px aspect-[4/3]`,children:[(0,B.jsx)(`button`,{type:`button`,"aria-label":`Previous photo`,className:z(EA,!n&&DA,`left-2`),onClick:()=>d(-1),children:(0,B.jsx)(he,{className:`size-4`,"aria-hidden":!0})}),(0,B.jsx)(`button`,{type:`button`,"aria-label":`Next photo`,className:z(EA,!n&&DA,`right-2`),onClick:()=>d(1),children:(0,B.jsx)(_e,{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:`Photo ${s+1} of ${l.length}`}),(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:l.map((e,t)=>(0,B.jsx)(`span`,{className:z(`size-1.5 rounded-full`,t===s?`bg-foreground`:`bg-foreground/35`)},t))})]})]})]})},kA=({icon:e,children:t})=>{let n=Yk(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]})},AA=({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}=hv(e,t,n),m=e=>t?.fields[e]?.label??G(e),h=n=>{let i=e.fields[n];return i?r.labels[n]??ov(i,r.record[n],t?.fields[n]):``},{fields:g,components:_}=w_(),v=n.card===void 0?void 0:_?.[n.card],y=n=>{let i=e.fields[n],a=i&&_y(g,i,t?.fields[n]);return a?(0,B.jsx)(Sy,{shown:a,part:`display`,field:i,value:r.record[n],fallback:h(n)}):h(n)},b=n=>{let i=e.fields[n],a=t?.fields[n],o=r.record[n];return!i||a?.format!==`badge`||_y(g,i,a)||o==null||o===``?y(n):(0,B.jsx)(vA,{value:o,hints:a,children:h(n)})},x=n=>{let i=e.fields[n];if(!i)return;if(r.labels[n]!==void 0||_y(g,i,t?.fields[n]))return(0,B.jsx)(`strong`,{className:`font-semibold text-foreground`,children:y(n)});let a=vv(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]})},S=v?void 0:n.photos,C=u===void 0?void 0:r.record[u],w=p.filter(e=>r.record[e]===!0),T=o===void 0?void 0:r.record[o],E=_v(r,l),D=gv(r,f),O=o!==void 0||S!==void 0,k=n.favorite,A=e=>(0,B.jsxs)(B.Fragment,{children:[O&&e,(0,B.jsxs)(`span`,{className:`flex items-start justify-between gap-2 ${k&&!O?`pr-8`:``}`,children:[(0,B.jsx)(`span`,{className:`min-w-0 truncate font-medium`,children:y(s)}),u!==void 0&&C!=null&&(0,B.jsx)(vA,{value:C,hints:t?.fields[u],children:h(u)})]}),c!==void 0&&(0,B.jsx)(`span`,{className:t?.fields[c]?.multiline?`line-clamp-3 whitespace-pre-line break-words text-muted-foreground`:`truncate text-muted-foreground`,children:y(c)}),E!==void 0&&(0,B.jsx)(`span`,{className:`truncate tabular-nums text-muted-foreground`,children:x(E)}),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:gv(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)(kA,{icon:t?.fields[e]?.icon,children:b(e)})]},e))}),w.length>0&&(0,B.jsx)(`ul`,{className:`flex flex-wrap gap-1`,"aria-label":`Features`,children:w.map(e=>(0,B.jsx)(`li`,{children:(0,B.jsx)(Cd,{dot:!1,children:m(e)})},e))}),D.length>0&&(0,B.jsx)(`span`,{className:`truncate text-xs text-muted-foreground ${d.length>0?``:`mt-auto`}`,children:D.map((e,t)=>(0,B.jsxs)(`span`,{children:[t>0&&(0,B.jsx)(`span`,{"aria-hidden":!0,children:` • `}),y(e)]},e))})]}),j=t=>(0,B.jsxs)(Gv,{to:{kind:`record`,resource:e.name,key:r.key},className:`flex h-full flex-col gap-1.5 rounded-lg border border-border bg-background p-3 text-[13px] hover:border-border-strong hover:bg-surface focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/30`,children:[a&&!O&&(0,B.jsx)(Cd,{tone:`blue`,className:`self-start`,children:a}),v?(0,B.jsx)(by,{name:n.card,fallback:A(t),children:(0,B.jsx)(v,{row:r})}):A(t)]});return(0,B.jsxs)(`div`,{className:S?`group/card relative h-full`:k||a?`relative h-full`:`h-full`,children:[S?(0,B.jsx)(OA,{photos:r.photos??[],cover:T,swipe:i,children:j},r.key):j((0,B.jsx)(xA,{value:T})),a&&O&&(0,B.jsx)(Cd,{tone:`blue`,className:`pointer-events-none absolute top-2 left-2 shadow-sm`,children:a}),k&&(0,B.jsx)(_A,{favorite:k,recordKey:r.key,target:Mg(e,r.record),className:O?void 0:`right-1.5 top-1.5`})]})},yne=(e,t)=>{},bne=({windowMs:e=1e3,comebacks:t=2,onHold:n=yne}={})=>{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}},xne=e=>Math.max(1,Math.floor((e+12)/252)),Sne=(e,t)=>Math.max(0,(e-(t-1)*12)/t),Cne=(e,t,n,r)=>({start:e*n,end:Math.max(0,Math.min(r,(t+1)*n)-1)}),wne=(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},Tne=8,Ene=(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<=Tne)break;i.delete(e)}return i},Dne=({source:e,label:t,initialIndex:n,onScrollIndex:r,minHeight:i,children:a})=>{let{total:s}=e,[c]=(0,o.useState)(n),[l,u]=(0,o.useState)(0),d=xne(l),f=Sne(l,d),[p,m]=(0,o.useState)(()=>new Map),h=Math.ceil(Math.max(i(f),p.get(f)??0)),g=h+12,_={columns:d,rowHeight:g},v=(0,o.useRef)({layout:_,top:0}),y=v.current.top>0&&(v.current.layout.columns!==d||v.current.layout.rowHeight!==g),b=e=>y?wne(v.current.top,v.current.layout,_):e,x=f>0&&p.has(f),S=hO({total:Math.ceil(s/d),rowHeight:g,initialIndex:Math.floor(c/d),settle:b,ready:x});(0,o.useLayoutEffect)(()=>{y&&S.scrollTo(S.top),v.current={layout:_,top:S.top},y||r(Math.floor(Math.max(0,S.top)/g)*d)});let C=Cne(S.first,S.last,d,s),w=tO({total:s,rowAt:e.rowAt,loadRows:e.loadRows,latencyMs:0},C.start,C.end),[T]=(0,o.useState)(()=>bne());(0,o.useLayoutEffect)(()=>{let e=S.ref.current;if(!e)return;let t=()=>u(T(e.clientWidth,performance.now())),n=new ResizeObserver(t);return n.observe(e),t(),()=>n.disconnect()},[T]);let E=(0,o.useRef)(f);E.current=f;let[D]=(0,o.useState)(()=>new ResizeObserver(e=>{let t=Math.max(...e.map(e=>e.borderBoxSize[0]?.blockSize??e.contentRect.height)),n=E.current;m(e=>Ene(e,n,t))}));(0,o.useLayoutEffect)(()=>()=>D.disconnect(),[D]);let O=(0,o.useCallback)(e=>{if(e)return D.observe(e),()=>D.unobserve(e)},[D]);return(0,B.jsx)(`ul`,{ref:S.ref,className:`relative min-w-0 flex-auto`,"aria-label":t,style:{height:S.geometry.contentHeight},children:S.rows.flatMap(({index:e,offset:t})=>Array.from({length:d},(n,r)=>{let i=e*d+r;if(i>=s)return[];let o=w(i),c={top:t,left:r*(f+12),width:f,minHeight:h};return o?(0,B.jsx)(`li`,{ref:O,"aria-posinset":i+1,"aria-setsize":s,className:`absolute grid grid-cols-[minmax(0,1fr)]`,style:c,children:a(o)},o.id):(0,B.jsx)(`li`,{"aria-hidden":!0,className:`absolute grid grid-cols-[minmax(0,1fr)]`,style:c,children:(0,B.jsx)(od,{className:`h-full rounded-lg`})},`skeleton-${i}`)}))})},One=`grid grid-cols-[repeat(auto-fill,minmax(15rem,1fr))] gap-3`,kne=e=>e*.75,Ane=44,jne=({model:e,view:t,display:n,list:r})=>{let i=t?.names?.plural??G(e.name),a=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 ${One}`,children:Array.from({length:6},(e,t)=>(0,B.jsx)(od,{className:`h-24`},t))}):r.error?(0,B.jsx)(ny,{title:`Could not load rows`,error:r.error}):!r.source||r.source.total===0?(0,B.jsxs)(`p`,{className:`py-8 text-center text-[13px] text-muted-foreground`,children:[`No `,i.toLowerCase(),` match.`]}):(0,B.jsx)(Dne,{source:r.source,label:i,initialIndex:r.initialIndex,onScrollIndex:r.onScrollIndex,minHeight:e=>(a?kne(e):0)+Ane,children:r=>(0,B.jsx)(AA,{model:e,view:t,display:n,row:wv(e,r)})})},jA=so(),Mne={bounds:{south:-90,west:-180,north:90,east:180},zoom:0},Nne=22,MA=e=>Math.floor(e*1e6)/1e6,NA=e=>Math.ceil(e*1e6)/1e6,PA=e=>((e+180)%360+360)%360-180,Pne=(e,t)=>{let n=[jA.gte(e.latitude,MA(Math.max(t.south,-90))),jA.lte(e.latitude,NA(Math.min(t.north,90)))];if(t.east-t.west>=360)return jA.and(...n);let r=jA.gte(e.longitude,MA(PA(t.west))),i=jA.lte(e.longitude,NA(PA(t.east)));return PA(t.west)<=PA(t.east)?jA.and(...n,r,i):jA.and(...n,jA.or(r,i))},Fne=(e,t,n)=>{let r=qa(Pne(t,n));return e.trim()===``?r:`(${e}) AND ${r}`},Ine=e=>Math.min(Math.max(Math.floor(e),0),Nne),Lne=(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))}},FA=e=>{if(typeof e==`number`)return e;if(typeof e==`string`&&e.trim()!==``)return Number(e)},IA=(e,t)=>{let n=FA(e[t.latitude]),r=FA(e[t.longitude]);if(n!==void 0&&r!==void 0&&Math.abs(n)<=90&&Math.abs(r)<=180)return{latitude:n,longitude:r}},Rne=6371008.8,LA=64,RA=(e,t)=>t.approximate===void 0?t.exact!==void 0&&e[t.exact]===!1:e[t.approximate]===!0,zA=(e,t)=>{let n=t/Rne,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%LA/LA*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]})]}},zne=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,BA=(e,t)=>Array.isArray(e)&&e.length>=t&&e.every(zne),VA=e=>Array.isArray(e)&&e.length>0&&e.every(e=>BA(e,4)),Bne=e=>Array.isArray(e)&&e.length>0&&e.every(e=>BA(e,2)),Vne=e=>{if(typeof e!=`string`)return e;try{return JSON.parse(e)}catch(e){if(e instanceof SyntaxError)return;throw e}},Hne=e=>{let t=Vne(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`&&VA(i)||r===`MultiPolygon`&&Array.isArray(i)&&i.length>0&&i.every(VA)||r===`LineString`&&BA(i,2)||r===`MultiLineString`&&Bne(i))return{type:r,coordinates:i}},Une=(e,t,n)=>{if(!RA(e,t))return;let r=t.area===void 0?void 0:Hne(e[t.area]);if(r)return r;let i=t.radius===void 0?void 0:FA(e[t.radius]);return i!==void 0&&Number.isFinite(i)&&i>0?zA(n,i):t.defaultRadius===void 0?void 0:zA(n,t.defaultRadius)},HA=(e,t)=>e.flatMap(e=>{let n=IA(e.record,t);if(!n)return[];if(!RA(e.record,t))return[{key:e.key,...n}];let r=Une(e.record,t,n);return[{key:e.key,...n,approximate:!0,...r&&{area:r}}]}),Wne=(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}))},Gne=(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)}},UA=(e,t)=>({keys:e.keys,index:((e.index+t)%e.keys.length+e.keys.length)%e.keys.length}),Kne=({model:e,display:t,fields:n,filter:r,orderBy:i,area:a})=>{let o=W(),{resources:s,views:c}=K(),l={latitude:t.latitude,longitude:t.longitude},u=a?Fne(r,l,a.bounds):``,d=a?Ine(a.zoom):0;return kh({queryKey:U.map(e.name,`${l.latitude},${l.longitude}`,d,u,i),enabled:a!==void 0,placeholderData:Lm,queryFn:async()=>{let t=await o.map(e.name,{...l,zoom:d,filter:u,orderBy:i,labels:B_(s,c,e,n),photos:cv(c[e.name])});return{rows:V_(s,e,n,lv(e,t.items,t.photos),t.labels).map(t=>wv(e,t)),buckets:t.buckets,total:t.totalSize}}})},qne=(0,o.lazy)(()=>g_(()=>import(`./records-map-BORhj6IH.js`).then(e=>({default:e.RecordsMap})),__vite__mapDeps([0,1,2,3,4,5,6]))),Jne=250,WA=`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`,GA=({model:e,view:t,display:n,filter:r,orderBy:i,fields:a,at:s,onMove:c,footer:l=!0,flush:u=!1})=>{let d=K().maps?.style,[f,p]=(0,o.useState)(),[m,h]=(0,o.useState)(),g=LO(m,Jne),[_,v]=(0,o.useState)(s===void 0),y=Kne({model:e,display:n,fields:a,filter:r,orderBy:i,area:_?Mne:g}),b=y.isPlaceholderData?void 0:y.data,x=y.data?.rows??[],S=y.data?.buckets??[],C=HA(x,n),w=_&&b?Lne(HA(b.rows,n),b.buckets):void 0,T=yv(t,n),E=(t?.names?.plural??G(e.name)).toLowerCase(),D=(t?.names?.singular??G(e.name)).toLowerCase(),O=Gne(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?t===1?`Show the ${D}, at an approximate position`:`Show the ${D}`:t===0?`Show ${e.length} ${E}`:t===e.length?`Show ${e.length} ${E}, at approximate positions`:`Show ${e.length} ${E}, ${t} at approximate positions`},M=e=>`Zoom in on ${e.toLocaleString(`en-IE`)} ${e===1?D:E}`,N=(0,o.useRef)(null),[ee,te]=(0,o.useState)(0);if((0,o.useLayoutEffect)(()=>te(N.current?.offsetHeight??0),[k?.key]),!d)return(0,B.jsx)(yy,{children:`The map display needs a map style: set PROTOBASE_MAP_STYLE_URL.`});let ne=b?.total===0;return(0,B.jsxs)(`div`,{className:z(`flex h-full min-h-[36rem] flex-1 flex-col sm:min-h-[28rem]`,u&&`max-md:-mx-5 max-md:-mb-4 max-md:min-h-0`),children:[(0,B.jsxs)(`div`,{className:z(`relative min-h-0 flex-1 overflow-hidden rounded-lg border border-border bg-muted`,u&&`max-md:rounded-none max-md:border-0`),children:[(0,B.jsx)(o.Suspense,{fallback:null,children:(0,B.jsx)(qne,{style:d,initial:s,points:C,buckets:S,fit:w,onFitted:()=>v(!1),onMove:(e,t)=>{h(e),c?.(t)},selected:O?.keys,covered:O?ee:0,onSelect:e=>p({keys:e,index:0}),onClear:()=>p(void 0),markerLabel:j,bucketLabel:M})}),y.error&&(0,B.jsx)(`div`,{className:`absolute inset-x-3 top-3 z-10`,children:(0,B.jsx)(ny,{title:`Could not load rows`,error:y.error})}),ne&&(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-[13px] text-muted-foreground shadow`,role:`status`,children:[_?`No ${E} match.`:`No ${E} in this part of the map.`,!_&&(0,B.jsx)(H,{size:`sm`,onClick:()=>v(!0),children:`Show all`})]})}),O&&k&&(0,B.jsx)(`div`,{ref:N,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":`Chosen ${D}`,children:[(0,B.jsxs)(`div`,{className:`flex items-center justify-end gap-1.5`,children:[A.has(k.key)&&(0,B.jsxs)(`span`,{className:`mr-auto flex items-center gap-1 rounded-full border border-border bg-background px-2 py-1 text-xs`,children:[(0,B.jsx)(Te,{className:`size-3.5`,"aria-hidden":!0}),`Approximate position`]}),O.keys.length>1&&(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`button`,{type:`button`,"aria-label":`Previous`,className:WA,onClick:()=>p(UA(O,-1)),children:(0,B.jsx)(he,{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":`Next`,className:WA,onClick:()=>p(UA(O,1)),children:(0,B.jsx)(_e,{className:`size-4`,"aria-hidden":!0})})]}),(0,B.jsx)(`button`,{type:`button`,"aria-label":`Close`,className:WA,onClick:()=>p(void 0),children:(0,B.jsx)(Nn,{className:`size-4`,"aria-hidden":!0})})]}),(0,B.jsx)(`div`,{className:`shadow-lg`,children:(0,B.jsx)(AA,{model:e,view:t,display:T,row:k})})]})})]}),l&&(0,B.jsx)(`p`,{className:`hidden py-3 text-xs text-muted-foreground md:block`,children:Yne(y.data,E)})]})},Yne=(e,t)=>{if(!e)return`\xA0`;let n=e.total.toLocaleString(`en-IE`);return e.buckets.length===0&&e.rows.length<e.total?`${e.rows.length.toLocaleString(`en-IE`)} of ${n} ${t} in view`:`${n} ${t} in view`},KA=(0,o.createContext)(void 0),Xne=({value:e,children:t})=>(0,B.jsx)(KA.Provider,{value:e,children:t}),Zne=()=>{let e=(0,o.useContext)(KA);if(!e)throw Error(`useListDisplay is used inside a list display, which the list page draws`);return e},Qne=()=>(0,o.useContext)(KA),qA=({display:e,list:t})=>{let{components:n}=w_(),r=n?.[e.component];return r?(0,B.jsx)(Xne,{value:t,children:(0,B.jsx)(`div`,{className:`min-w-0 flex-1 overflow-x-auto`,children:(0,B.jsx)(by,{name:e.component,children:(0,B.jsx)(r,{...co(e.props??{})})})})}):(0,B.jsxs)(yy,{children:[`No component is registered as `,e.component,`. Export it from protobase.ui.tsx, or load the plugin that provides it.`]})},$ne=(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}},ere=({value:e,options:t,onChange:n,label:r})=>{let[i,a]=(0,o.useState)(!1),s=(0,o.useRef)(null),c=(0,o.useRef)(null),l=(0,o.useRef)([]),u=t.findIndex(t=>t.value===e),d=t[u];(0,o.useEffect)(()=>{if(!i)return;l.current[Math.max(u,0)]?.focus();let e=e=>{e.target instanceof Node&&!s.current?.contains(e.target)&&a(!1)};return document.addEventListener(`pointerdown`,e),()=>document.removeEventListener(`pointerdown`,e)},[i]);let f=()=>{a(!1),c.current?.focus()};return(0,B.jsxs)(`div`,{ref:s,className:`relative shrink-0`,children:[(0,B.jsxs)(`button`,{ref:c,type:`button`,"aria-label":d?`${r}: ${d.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-[13px] font-medium shadow-sm transition-colors hover:bg-muted pointer-coarse:h-11`,children:[d?.icon&&(0,B.jsx)(d.icon,{className:`size-3.5`}),d?.label??r,(0,B.jsx)(pe,{className:`size-3.5 text-muted-foreground`})]}),i&&(0,B.jsx)(`ul`,{role:`menu`,"aria-label":r,onKeyDown:e=>{if(e.key===`Escape`)return f();if(e.key===`Tab`)return a(!1);let n=$ne(e.key,l.current.indexOf(document.activeElement),t.length);n!==void 0&&(e.preventDefault(),l.current[n]?.focus())},className:`absolute right-0 top-full z-30 mt-1 min-w-40 rounded-md border bg-background py-1 text-[13px] shadow-pop`,children:t.map((t,r)=>(0,B.jsx)(`li`,{role:`none`,children:(0,B.jsxs)(`button`,{ref:e=>{l.current[r]=e},type:`button`,role:`menuitemradio`,"aria-checked":t.value===e,onClick:()=>{f(),t.value!==e&&n(t.value)},className:z(`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)(de,{className:`size-3.5 text-primary-text`})]})},t.value))})]})},tre={table:hn,cards:at,kanban:ln,board:je,list:dt,calendar:ce,map:Ct},JA=({view:e,value:t,onChange:n,menu:r=!1})=>{let i=mv(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:tre[e.icon]}));return r?(0,B.jsx)(ere,{label:`Display`,value:t,onChange:n,options:a}):(0,B.jsx)(Ed,{label:`Display`,size:`md`,value:t,onChange:n,options:a})},nre=[[`asc`,`ascending`],[`desc`,`descending`]],YA=({model:e,view:t,display:n,orderBy:r,onChange:i,className:a})=>{let o=Ev(r),s=Sv(e,t,n),c=s.includes(o.columnId)?s:[o.columnId,...s],l=e=>t?.fields[e]?.label??G(e);return(0,B.jsx)(`select`,{"aria-label":`Sort`,value:`${o.columnId} ${o.direction}`,onChange:e=>i(e.target.value),className:z(`h-8 rounded-md border border-border-strong bg-background px-2.5 text-[13px] shadow-sm focus:border-primary focus:outline-none focus:ring-2 focus:ring-primary/20`,a),children:c.flatMap(e=>nre.map(([t,n])=>(0,B.jsxs)(`option`,{value:`${e} ${t}`,children:[l(e),`, `,n]},`${e} ${t}`)))})},rre=(e,t,n,r)=>{let i=jh({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=>wv(e,t))),total:a[0]?.total??0,loading:i.isPending,error:i.error,more:i.hasNextPage,loadMore:()=>void i.fetchNextPage()}},XA=new Map,ire=()=>{let{entry:e,path:t,params:n}=Rh(),r=`${t}?${n.toString()}`,i=XA.get(e),a=(0,o.useCallback)(t=>void XA.set(e,{url:r,index:t}),[e,r]);return{initialIndex:i?.url===r?i.index:0,remember:a}},are=(e,t,n,r=!0)=>{let i=W(),a=as(n)??``;return kh({queryKey:U.facets(e,t,a),enabled:r,queryFn:()=>i.facets(e,t,{filter:a,limit:50})})},ZA=(e,t,n=!0)=>{let r=W(),i=as(t.filter)??``;return kh({queryKey:U.series(e,t.field,`${t.range??``}${t.from??``}${t.to??``}`,t.granularity??``,i),enabled:n,queryFn:()=>r.series(e,{...t,filter:i})})},ore=(e,t,n,r=20,i=!0)=>{let a=W(),o=as(n)??``;return kh({queryKey:U.histogram(e,t,r,o),enabled:i,queryFn:()=>a.histogram(e,t,{filter:o,buckets:r})})};function QA(e){var t,n,r=``;if(typeof e==`string`||typeof e==`number`)r+=e;else if(typeof e==`object`){if(Array.isArray(e)){var i=e.length;for(t=0;t<i;t++)e[t]&&(n=QA(e[t]))&&(r&&(r+=` `),r+=n)}else for(n in e)e[n]&&(r&&(r+=` `),r+=n)}return r}function $A(){for(var e,t,n=0,r=``,i=arguments.length;n<i;n++)(e=arguments[n])&&(t=QA(e))&&(r&&(r+=` `),r+=t);return r}var sre=`dangerouslySetInnerHTML.onCopy.onCopyCapture.onCut.onCutCapture.onPaste.onPasteCapture.onCompositionEnd.onCompositionEndCapture.onCompositionStart.onCompositionStartCapture.onCompositionUpdate.onCompositionUpdateCapture.onFocus.onFocusCapture.onBlur.onBlurCapture.onChange.onChangeCapture.onBeforeInput.onBeforeInputCapture.onInput.onInputCapture.onReset.onResetCapture.onSubmit.onSubmitCapture.onInvalid.onInvalidCapture.onLoad.onLoadCapture.onError.onErrorCapture.onKeyDown.onKeyDownCapture.onKeyPress.onKeyPressCapture.onKeyUp.onKeyUpCapture.onAbort.onAbortCapture.onCanPlay.onCanPlayCapture.onCanPlayThrough.onCanPlayThroughCapture.onDurationChange.onDurationChangeCapture.onEmptied.onEmptiedCapture.onEncrypted.onEncryptedCapture.onEnded.onEndedCapture.onLoadedData.onLoadedDataCapture.onLoadedMetadata.onLoadedMetadataCapture.onLoadStart.onLoadStartCapture.onPause.onPauseCapture.onPlay.onPlayCapture.onPlaying.onPlayingCapture.onProgress.onProgressCapture.onRateChange.onRateChangeCapture.onSeeked.onSeekedCapture.onSeeking.onSeekingCapture.onStalled.onStalledCapture.onSuspend.onSuspendCapture.onTimeUpdate.onTimeUpdateCapture.onVolumeChange.onVolumeChangeCapture.onWaiting.onWaitingCapture.onAuxClick.onAuxClickCapture.onClick.onClickCapture.onContextMenu.onContextMenuCapture.onDoubleClick.onDoubleClickCapture.onDrag.onDragCapture.onDragEnd.onDragEndCapture.onDragEnter.onDragEnterCapture.onDragExit.onDragExitCapture.onDragLeave.onDragLeaveCapture.onDragOver.onDragOverCapture.onDragStart.onDragStartCapture.onDrop.onDropCapture.onMouseDown.onMouseDownCapture.onMouseEnter.onMouseLeave.onMouseMove.onMouseMoveCapture.onMouseOut.onMouseOutCapture.onMouseOver.onMouseOverCapture.onMouseUp.onMouseUpCapture.onSelect.onSelectCapture.onTouchCancel.onTouchCancelCapture.onTouchEnd.onTouchEndCapture.onTouchMove.onTouchMoveCapture.onTouchStart.onTouchStartCapture.onPointerDown.onPointerDownCapture.onPointerMove.onPointerMoveCapture.onPointerUp.onPointerUpCapture.onPointerCancel.onPointerCancelCapture.onPointerEnter.onPointerEnterCapture.onPointerLeave.onPointerLeaveCapture.onPointerOver.onPointerOverCapture.onPointerOut.onPointerOutCapture.onGotPointerCapture.onGotPointerCaptureCapture.onLostPointerCapture.onLostPointerCaptureCapture.onScroll.onScrollCapture.onWheel.onWheelCapture.onAnimationStart.onAnimationStartCapture.onAnimationEnd.onAnimationEndCapture.onAnimationIteration.onAnimationIterationCapture.onTransitionEnd.onTransitionEndCapture`.split(`.`);function ej(e){return typeof e==`string`&&sre.includes(e)}var cre=new Set(`aria-activedescendant.aria-atomic.aria-autocomplete.aria-busy.aria-checked.aria-colcount.aria-colindex.aria-colspan.aria-controls.aria-current.aria-describedby.aria-details.aria-disabled.aria-errormessage.aria-expanded.aria-flowto.aria-haspopup.aria-hidden.aria-invalid.aria-keyshortcuts.aria-label.aria-labelledby.aria-level.aria-live.aria-modal.aria-multiline.aria-multiselectable.aria-orientation.aria-owns.aria-placeholder.aria-posinset.aria-pressed.aria-readonly.aria-relevant.aria-required.aria-roledescription.aria-rowcount.aria-rowindex.aria-rowspan.aria-selected.aria-setsize.aria-sort.aria-valuemax.aria-valuemin.aria-valuenow.aria-valuetext.className.color.height.id.lang.max.media.method.min.name.style.target.width.role.tabIndex.accentHeight.accumulate.additive.alignmentBaseline.allowReorder.alphabetic.amplitude.arabicForm.ascent.attributeName.attributeType.autoReverse.azimuth.baseFrequency.baselineShift.baseProfile.bbox.begin.bias.by.calcMode.capHeight.clip.clipPath.clipPathUnits.clipRule.colorInterpolation.colorInterpolationFilters.colorProfile.colorRendering.contentScriptType.contentStyleType.cursor.cx.cy.d.decelerate.descent.diffuseConstant.direction.display.divisor.dominantBaseline.dur.dx.dy.edgeMode.elevation.enableBackground.end.exponent.externalResourcesRequired.fill.fillOpacity.fillRule.filter.filterRes.filterUnits.floodColor.floodOpacity.focusable.fontFamily.fontSize.fontSizeAdjust.fontStretch.fontStyle.fontVariant.fontWeight.format.from.fx.fy.g1.g2.glyphName.glyphOrientationHorizontal.glyphOrientationVertical.glyphRef.gradientTransform.gradientUnits.hanging.horizAdvX.horizOriginX.href.ideographic.imageRendering.in2.in.intercept.k1.k2.k3.k4.k.kernelMatrix.kernelUnitLength.kerning.keyPoints.keySplines.keyTimes.lengthAdjust.letterSpacing.lightingColor.limitingConeAngle.local.markerEnd.markerHeight.markerMid.markerStart.markerUnits.markerWidth.mask.maskContentUnits.maskUnits.mathematical.mode.numOctaves.offset.opacity.operator.order.orient.orientation.origin.overflow.overlinePosition.overlineThickness.paintOrder.panose1.pathLength.patternContentUnits.patternTransform.patternUnits.pointerEvents.pointsAtX.pointsAtY.pointsAtZ.preserveAlpha.preserveAspectRatio.primitiveUnits.r.radius.refX.refY.renderingIntent.repeatCount.repeatDur.requiredExtensions.requiredFeatures.restart.result.rotate.rx.ry.seed.shapeRendering.slope.spacing.specularConstant.specularExponent.speed.spreadMethod.startOffset.stdDeviation.stemh.stemv.stitchTiles.stopColor.stopOpacity.strikethroughPosition.strikethroughThickness.string.stroke.strokeDasharray.strokeDashoffset.strokeLinecap.strokeLinejoin.strokeMiterlimit.strokeOpacity.strokeWidth.surfaceScale.systemLanguage.tableValues.targetX.targetY.textAnchor.textDecoration.textLength.textRendering.to.transform.u1.u2.underlinePosition.underlineThickness.unicode.unicodeBidi.unicodeRange.unitsPerEm.vAlphabetic.values.vectorEffect.version.vertAdvY.vertOriginX.vertOriginY.vHanging.vIdeographic.viewTarget.visibility.vMathematical.widths.wordSpacing.writingMode.x1.x2.x.xChannelSelector.xHeight.xlinkActuate.xlinkArcrole.xlinkHref.xlinkRole.xlinkShow.xlinkTitle.xlinkType.xmlBase.xmlLang.xmlns.xmlnsXlink.xmlSpace.y1.y2.y.yChannelSelector.z.zoomAndPan.ref.key.angle`.split(`.`));function tj(e){return typeof e==`string`&&cre.has(e)}function nj(e){return typeof e==`string`&&e.startsWith(`data-`)}function rj(e){if(typeof e!=`object`||!e)return{};var t={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(tj(n)||nj(n))&&(t[n]=e[n]);return t}function ij(e){if(e==null)return null;if((0,o.isValidElement)(e)&&typeof e.props==`object`&&e.props!==null){var t=e.props;return rj(t)}return typeof e==`object`&&!Array.isArray(e)?rj(e):null}function aj(e){var t={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(tj(n)||nj(n)||ej(n))&&(t[n]=e[n]);return t}var lre=[`children`,`width`,`height`,`viewBox`,`className`,`style`,`title`,`desc`];function oj(){return oj=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},oj.apply(null,arguments)}function ure(e,t){if(e==null)return{};var n,r,i=dre(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function dre(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}var sj=(0,o.forwardRef)((e,t)=>{var n=e.children,r=e.width,i=e.height,a=e.viewBox,s=e.className,c=e.style,l=e.title,u=e.desc,d=ure(e,lre),f=a||{width:r,height:i,x:0,y:0},p=$A(`recharts-surface`,s);return o.createElement(`svg`,oj({},aj(d),{className:p,width:r,height:i,style:c,viewBox:`${f.x} ${f.y} ${f.width} ${f.height}`,ref:t}),o.createElement(`title`,null,l),o.createElement(`desc`,null,u),n)}),fre=[`children`,`className`];function cj(){return cj=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},cj.apply(null,arguments)}function pre(e,t){if(e==null)return{};var n,r,i=mre(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function mre(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}var lj=o.forwardRef((e,t)=>{var n=e.children,r=e.className,i=pre(e,fre),a=$A(`recharts-layer`,r);return o.createElement(`g`,cj({className:a},aj(i),{ref:t}),n)});function uj(e){return e===`__proto__`}var hre=/\.|(\[(?:[^[\]]*|(["'])(?:(?!\2)[^\\]|\\.)*?\2)\])/;function dj(e){switch(typeof e){case`number`:case`symbol`:return!1;case`string`:return e===``||e.startsWith(`.`)||e.endsWith(`.`)?!1:hre.test(e);default:return!1}}function fj(e){return typeof e==`string`||typeof e==`symbol`?e:Object.is(e?.valueOf?.(),-0)?`-0`:String(e)}function pj(e){return typeof e==`symbol`||e instanceof Symbol}function gre(e){return e==null?``:mj(e)}function mj(e){if(typeof e==`string`)return e;if(Array.isArray(e))return e.map(mj).join(`,`);if(pj(e))return e.toString();let t=e+``;return t===`0`&&Object.is(Number(e),-0)?`-0`:t}function hj(e){if(Array.isArray(e))return e.map(fj);if(typeof e==`symbol`)return[e];e=gre(e);let t=[],n=e.length;if(n===0)return t;let r=0,i=``,a=``,o=!1,s=!1,c=/^-?\d+(?:\.\d+)?$/;for(e.charCodeAt(0)===46&&t.push(``);r<n;){let l=e[r];if(a)l===`\\`&&r+1<n?(r++,i+=e[r]):l===a?a=``:i+=l;else if(o){if(l===`"`||l===`'`)a=l,s=!0;else if(l===`]`){if(o=!1,!s&&i.includes(`.`)&&!c.test(i)){let e=i.split(`.`);for(let n=0;n<e.length;n++)e[n]!==``&&t.push(e[n])}else t.push(i);i=``}else i+=l}else if(l===`[`)o=!0,s=!1,i&&=(t.push(i),``);else if(l===`.`){i&&=(t.push(i),``);let n=e[r+1];(n===void 0||n===`.`)&&t.push(``)}else i+=l;r++}return i&&t.push(i),t}function gj(e,t,n){if(e==null)return n;switch(typeof t){case`string`:{if(uj(t))return n;let r=e[t];return r===void 0?dj(t)&&!Object.hasOwn(e,t)?gj(e,hj(t),n):n:r}case`number`:case`symbol`:{typeof t==`number`&&(t=fj(t));let r=e[t];return r===void 0?n:r}default:{if(Array.isArray(t))return _re(e,t,n);if(t=Object.is(t?.valueOf(),-0)?`-0`:String(t),uj(t))return n;let r=e[t];return r===void 0?n:r}}}function _re(e,t,n){if(t.length===0)return n;let r=e;for(let e=0;e<t.length;e++){if(r==null||uj(t[e]))return n;r=r[t[e]]}return r===void 0?n:r}var vre=4;function _j(e){var t=10**(arguments.length>1&&arguments[1]!==void 0?arguments[1]:vre),n=Math.round(e*t)/t;return Object.is(n,-0)?0:n}function vj(e){var t=[...arguments].slice(1);return e.reduce((e,n,r)=>{var i=t[r-1];return typeof i==`string`?e+i+n:i===void 0?e+n:e+_j(i)+n},``)}var yj=e=>e===0?0:e>0?1:-1,bj=e=>typeof e==`number`&&e!=+e,xj=e=>typeof e==`string`&&e.length>1&&e.indexOf(`%`)===e.length-1,J=e=>(typeof e==`number`||e instanceof Number)&&!bj(e),Sj=e=>J(e)||typeof e==`string`,yre=0,Cj=e=>{var t=++yre;return`${e||``}${t}`},wj=function(e,t){var n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:0,r=arguments.length>3&&arguments[3]!==void 0&&arguments[3];if(!J(e)&&typeof e!=`string`)return n;var i;if(xj(e)){if(t==null)return n;var a=e.indexOf(`%`);i=t*parseFloat(e.slice(0,a))/100}else i=+e;return bj(i)&&(i=n),r&&t!=null&&i>t&&(i=t),i},Tj=e=>{if(!Array.isArray(e))return!1;for(var t=e.length,n={},r=0;r<t;r++)if(!n[String(e[r])])n[String(e[r])]=!0;else return!0;return!1};function Ej(e,t,n){return J(e)&&J(t)?_j(e+n*(t-e)):t}function bre(e,t,n){if(e&&e.length)return e.find(e=>e&&(typeof t==`function`?t(e):gj(e,t))===n)}var Dj=e=>e==null,Oj=e=>Dj(e)?e:`${e.charAt(0).toUpperCase()}${e.slice(1)}`;function kj(e){return e!=null}function Aj(){}function jj(e){if(e)return{x:e.x,y:e.y,upperWidth:`upperWidth`in e?e.upperWidth:e.width,lowerWidth:`lowerWidth`in e?e.lowerWidth:e.width,width:e.width,height:e.height}}function Mj(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function Nj(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?Mj(Object(n),!0).forEach(function(t){xre(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Mj(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function xre(e,t,n){return(t=Sre(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Sre(e){var t=Cre(e,`string`);return typeof t==`symbol`?t:t+``}function Cre(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}var wre=e=>{var t=e.viewBox,n=e.position,r=e.offset,i=r===void 0?0:r,a=e.parentViewBox,o=e.clamp,s=jj(t),c=s.x,l=s.y,u=s.height,d=s.upperWidth,f=s.lowerWidth,p=c,m=c+(d-f)/2,h=(p+m)/2,g=(d+f)/2,_=p+d/2,v=u>=0?1:-1,y=v*i,b=v>0?`end`:`start`,x=v>0?`start`:`end`,S=d>=0?1:-1,C=S*i,w=S>0?`end`:`start`,T=S>0?`start`:`end`,E=a;if(n===`top`){var D={x:p+d/2,y:l-y,horizontalAnchor:`middle`,verticalAnchor:b};return o&&E&&(D.height=Math.max(l-E.y,0),D.width=d),D}if(n===`bottom`){var O={x:m+f/2,y:l+u+y,horizontalAnchor:`middle`,verticalAnchor:x};return o&&E&&(O.height=Math.max(E.y+E.height-(l+u),0),O.width=f),O}if(n===`left`){var k={x:h-C,y:l+u/2,horizontalAnchor:w,verticalAnchor:`middle`};return o&&E&&(k.width=Math.max(k.x-E.x,0),k.height=u),k}if(n===`right`){var A={x:h+g+C,y:l+u/2,horizontalAnchor:T,verticalAnchor:`middle`};return o&&E&&(A.width=Math.max(E.x+E.width-A.x,0),A.height=u),A}var j=o&&E?{width:g,height:u}:{};return n===`insideLeft`?Nj({x:h+C,y:l+u/2,horizontalAnchor:T,verticalAnchor:`middle`},j):n===`insideRight`?Nj({x:h+g-C,y:l+u/2,horizontalAnchor:w,verticalAnchor:`middle`},j):n===`insideTop`?Nj({x:p+d/2,y:l+y,horizontalAnchor:`middle`,verticalAnchor:x},j):n===`insideBottom`?Nj({x:m+f/2,y:l+u-y,horizontalAnchor:`middle`,verticalAnchor:b},j):n===`insideTopLeft`?Nj({x:p+C,y:l+y,horizontalAnchor:T,verticalAnchor:x},j):n===`insideTopRight`?Nj({x:p+d-C,y:l+y,horizontalAnchor:w,verticalAnchor:x},j):n===`insideBottomLeft`?Nj({x:m+C,y:l+u-y,horizontalAnchor:T,verticalAnchor:b},j):n===`insideBottomRight`?Nj({x:m+f-C,y:l+u-y,horizontalAnchor:w,verticalAnchor:b},j):n&&typeof n==`object`&&(J(n.x)||xj(n.x))&&(J(n.y)||xj(n.y))?Nj({x:c+wj(n.x,g),y:l+wj(n.y,u),horizontalAnchor:`end`,verticalAnchor:`end`},j):Nj({x:_,y:l+u/2,horizontalAnchor:`middle`,verticalAnchor:`middle`},j)},Tre=[`top`,`left`,`right`,`bottom`];function Ere(e){return e==null?!1:typeof e==`object`||Tre.includes(e)}var Dre=(0,o.createContext)(null);function Pj(e){return function(){return e}}var Fj=Math.PI,Ij=2*Fj,Lj=1e-6,Ore=Ij-Lj;function Rj(e){this._+=e[0];for(let t=1,n=e.length;t<n;++t)this._+=arguments[t]+e[t]}function kre(e){let t=Math.floor(e);if(!(t>=0))throw Error(`invalid digits: ${e}`);if(t>15)return Rj;let n=10**t;return function(e){this._+=e[0];for(let t=1,r=e.length;t<r;++t)this._+=Math.round(arguments[t]*n)/n+e[t]}}var zj=class{constructor(e){this._x0=this._y0=this._x1=this._y1=null,this._=``,this._append=e==null?Rj:kre(e)}moveTo(e,t){this._append`M${this._x0=this._x1=+e},${this._y0=this._y1=+t}`}closePath(){this._x1!==null&&(this._x1=this._x0,this._y1=this._y0,this._append`Z`)}lineTo(e,t){this._append`L${this._x1=+e},${this._y1=+t}`}quadraticCurveTo(e,t,n,r){this._append`Q${+e},${+t},${this._x1=+n},${this._y1=+r}`}bezierCurveTo(e,t,n,r,i,a){this._append`C${+e},${+t},${+n},${+r},${this._x1=+i},${this._y1=+a}`}arcTo(e,t,n,r,i){if(e=+e,t=+t,n=+n,r=+r,i=+i,i<0)throw Error(`negative radius: ${i}`);let a=this._x1,o=this._y1,s=n-e,c=r-t,l=a-e,u=o-t,d=l*l+u*u;if(this._x1===null)this._append`M${this._x1=e},${this._y1=t}`;else if(d>Lj){if(!(Math.abs(u*s-c*l)>Lj)||!i)this._append`L${this._x1=e},${this._y1=t}`;else{let f=n-a,p=r-o,m=s*s+c*c,h=f*f+p*p,g=Math.sqrt(m),_=Math.sqrt(d),v=i*Math.tan((Fj-Math.acos((m+d-h)/(2*g*_)))/2),y=v/_,b=v/g;Math.abs(y-1)>Lj&&this._append`L${e+y*l},${t+y*u}`,this._append`A${i},${i},0,0,${+(u*f>l*p)},${this._x1=e+b*s},${this._y1=t+b*c}`}}}arc(e,t,n,r,i,a){if(e=+e,t=+t,n=+n,a=!!a,n<0)throw Error(`negative radius: ${n}`);let o=n*Math.cos(r),s=n*Math.sin(r),c=e+o,l=t+s,u=1^a,d=a?r-i:i-r;this._x1===null?this._append`M${c},${l}`:(Math.abs(this._x1-c)>Lj||Math.abs(this._y1-l)>Lj)&&this._append`L${c},${l}`,n&&(d<0&&(d=d%Ij+Ij),d>Ore?this._append`A${n},${n},0,1,${u},${e-o},${t-s}A${n},${n},0,1,${u},${this._x1=c},${this._y1=l}`:d>Lj&&this._append`A${n},${n},0,${+(d>=Fj)},${u},${this._x1=e+n*Math.cos(i)},${this._y1=t+n*Math.sin(i)}`)}rect(e,t,n,r){this._append`M${this._x0=this._x1=+e},${this._y0=this._y1=+t}h${n=+n}v${+r}h${-n}Z`}toString(){return this._}};zj.prototype;function Bj(e){let t=3;return e.digits=function(n){if(!arguments.length)return t;if(n==null)t=null;else{let e=Math.floor(n);if(!(e>=0))throw RangeError(`invalid digits: ${n}`);t=e}return e},()=>new zj(t)}Array.prototype.slice;function Vj(e){return typeof e==`object`&&`length`in e?e:Array.from(e)}function Hj(e){this._context=e}Hj.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;default:this._context.lineTo(e,t)}}};function Uj(e){return new Hj(e)}function Wj(e){return e[0]}function Gj(e){return e[1]}function Kj(e,t){var n=Pj(!0),r=null,i=Uj,a=null,o=Bj(s);e=typeof e==`function`?e:e===void 0?Wj:Pj(e),t=typeof t==`function`?t:t===void 0?Gj:Pj(t);function s(s){var c,l=(s=Vj(s)).length,u,d=!1,f;for(r??(a=i(f=o())),c=0;c<=l;++c)!(c<l&&n(u=s[c],c,s))===d&&((d=!d)?a.lineStart():a.lineEnd()),d&&a.point(+e(u,c,s),+t(u,c,s));if(f)return a=null,f+``||null}return s.x=function(t){return arguments.length?(e=typeof t==`function`?t:Pj(+t),s):e},s.y=function(e){return arguments.length?(t=typeof e==`function`?e:Pj(+e),s):t},s.defined=function(e){return arguments.length?(n=typeof e==`function`?e:Pj(!!e),s):n},s.curve=function(e){return arguments.length?(i=e,r!=null&&(a=i(r)),s):i},s.context=function(e){return arguments.length?(e==null?r=a=null:a=i(r=e),s):r},s}function qj(e,t,n){var r=null,i=Pj(!0),a=null,o=Uj,s=null,c=Bj(l);e=typeof e==`function`?e:e===void 0?Wj:Pj(+e),t=typeof t==`function`?t:Pj(t===void 0?0:+t),n=typeof n==`function`?n:n===void 0?Gj:Pj(+n);function l(l){var u,d,f,p=(l=Vj(l)).length,m,h=!1,g,_=Array(p),v=Array(p);for(a??(s=o(g=c())),u=0;u<=p;++u){if(!(u<p&&i(m=l[u],u,l))===h){if(h=!h)d=u,s.areaStart(),s.lineStart();else{for(s.lineEnd(),s.lineStart(),f=u-1;f>=d;--f)s.point(_[f],v[f]);s.lineEnd(),s.areaEnd()}}h&&(_[u]=+e(m,u,l),v[u]=+t(m,u,l),s.point(r?+r(m,u,l):_[u],n?+n(m,u,l):v[u]))}if(g)return s=null,g+``||null}function u(){return Kj().defined(i).curve(o).context(a)}return l.x=function(t){return arguments.length?(e=typeof t==`function`?t:Pj(+t),r=null,l):e},l.x0=function(t){return arguments.length?(e=typeof t==`function`?t:Pj(+t),l):e},l.x1=function(e){return arguments.length?(r=e==null?null:typeof e==`function`?e:Pj(+e),l):r},l.y=function(e){return arguments.length?(t=typeof e==`function`?e:Pj(+e),n=null,l):t},l.y0=function(e){return arguments.length?(t=typeof e==`function`?e:Pj(+e),l):t},l.y1=function(e){return arguments.length?(n=e==null?null:typeof e==`function`?e:Pj(+e),l):n},l.lineX0=l.lineY0=function(){return u().x(e).y(t)},l.lineY1=function(){return u().x(e).y(n)},l.lineX1=function(){return u().x(r).y(t)},l.defined=function(e){return arguments.length?(i=typeof e==`function`?e:Pj(!!e),l):i},l.curve=function(e){return arguments.length?(o=e,a!=null&&(s=o(a)),l):o},l.context=function(e){return arguments.length?(e==null?a=s=null:s=o(a=e),l):a},l}var Jj=class{constructor(e,t){this._context=e,this._x=t}areaStart(){this._line=0}areaEnd(){this._line=NaN}lineStart(){this._point=0}lineEnd(){(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line}point(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;default:this._x?this._context.bezierCurveTo(this._x0=(this._x0+e)/2,this._y0,this._x0,t,e,t):this._context.bezierCurveTo(this._x0,this._y0=(this._y0+t)/2,e,this._y0,e,t)}this._x0=e,this._y0=t}};function Are(e){return new Jj(e,!0)}function jre(e){return new Jj(e,!1)}function Yj(){}function Xj(e,t,n){e._context.bezierCurveTo((2*e._x0+e._x1)/3,(2*e._y0+e._y1)/3,(e._x0+2*e._x1)/3,(e._y0+2*e._y1)/3,(e._x0+4*e._x1+t)/6,(e._y0+4*e._y1+n)/6)}function Zj(e){this._context=e}Zj.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=NaN,this._point=0},lineEnd:function(){switch(this._point){case 3:Xj(this,this._x1,this._y1);case 2:this._context.lineTo(this._x1,this._y1)}(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;break;case 2:this._point=3,this._context.lineTo((5*this._x0+this._x1)/6,(5*this._y0+this._y1)/6);default:Xj(this,e,t)}this._x0=this._x1,this._x1=e,this._y0=this._y1,this._y1=t}};function Mre(e){return new Zj(e)}function Qj(e){this._context=e}Qj.prototype={areaStart:Yj,areaEnd:Yj,lineStart:function(){this._x0=this._x1=this._x2=this._x3=this._x4=this._y0=this._y1=this._y2=this._y3=this._y4=NaN,this._point=0},lineEnd:function(){switch(this._point){case 1:this._context.moveTo(this._x2,this._y2),this._context.closePath();break;case 2:this._context.moveTo((this._x2+2*this._x3)/3,(this._y2+2*this._y3)/3),this._context.lineTo((this._x3+2*this._x2)/3,(this._y3+2*this._y2)/3),this._context.closePath();break;case 3:this.point(this._x2,this._y2),this.point(this._x3,this._y3),this.point(this._x4,this._y4)}},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1,this._x2=e,this._y2=t;break;case 1:this._point=2,this._x3=e,this._y3=t;break;case 2:this._point=3,this._x4=e,this._y4=t,this._context.moveTo((this._x0+4*this._x1+e)/6,(this._y0+4*this._y1+t)/6);break;default:Xj(this,e,t)}this._x0=this._x1,this._x1=e,this._y0=this._y1,this._y1=t}};function $j(e){return new Qj(e)}function eM(e){this._context=e}eM.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=NaN,this._point=0},lineEnd:function(){(this._line||this._line!==0&&this._point===3)&&this._context.closePath(),this._line=1-this._line},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1;break;case 1:this._point=2;break;case 2:this._point=3;var n=(this._x0+4*this._x1+e)/6,r=(this._y0+4*this._y1+t)/6;this._line?this._context.lineTo(n,r):this._context.moveTo(n,r);break;case 3:this._point=4;default:Xj(this,e,t)}this._x0=this._x1,this._x1=e,this._y0=this._y1,this._y1=t}};function tM(e){return new eM(e)}function nM(e){this._context=e}nM.prototype={areaStart:Yj,areaEnd:Yj,lineStart:function(){this._point=0},lineEnd:function(){this._point&&this._context.closePath()},point:function(e,t){e=+e,t=+t,this._point?this._context.lineTo(e,t):(this._point=1,this._context.moveTo(e,t))}};function rM(e){return new nM(e)}function iM(e){return e<0?-1:1}function aM(e,t,n){var r=e._x1-e._x0,i=t-e._x1,a=(e._y1-e._y0)/(r||i<0&&-0),o=(n-e._y1)/(i||r<0&&-0),s=(a*i+o*r)/(r+i);return(iM(a)+iM(o))*Math.min(Math.abs(a),Math.abs(o),.5*Math.abs(s))||0}function oM(e,t){var n=e._x1-e._x0;return n?(3*(e._y1-e._y0)/n-t)/2:t}function sM(e,t,n){var r=e._x0,i=e._y0,a=e._x1,o=e._y1,s=(a-r)/3;e._context.bezierCurveTo(r+s,i+s*t,a-s,o-s*n,a,o)}function cM(e){this._context=e}cM.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=this._t0=NaN,this._point=0},lineEnd:function(){switch(this._point){case 2:this._context.lineTo(this._x1,this._y1);break;case 3:sM(this,this._t0,oM(this,this._t0))}(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(e,t){var n=NaN;if(e=+e,t=+t,e!==this._x1||t!==this._y1){switch(this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;break;case 2:this._point=3,sM(this,oM(this,n=aM(this,e,t)),n);break;default:sM(this,this._t0,n=aM(this,e,t))}this._x0=this._x1,this._x1=e,this._y0=this._y1,this._y1=t,this._t0=n}}};function lM(e){this._context=new uM(e)}(lM.prototype=Object.create(cM.prototype)).point=function(e,t){cM.prototype.point.call(this,t,e)};function uM(e){this._context=e}uM.prototype={moveTo:function(e,t){this._context.moveTo(t,e)},closePath:function(){this._context.closePath()},lineTo:function(e,t){this._context.lineTo(t,e)},bezierCurveTo:function(e,t,n,r,i,a){this._context.bezierCurveTo(t,e,r,n,a,i)}};function dM(e){return new cM(e)}function fM(e){return new lM(e)}function pM(e){this._context=e}pM.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x=[],this._y=[]},lineEnd:function(){var e=this._x,t=this._y,n=e.length;if(n){if(this._line?this._context.lineTo(e[0],t[0]):this._context.moveTo(e[0],t[0]),n===2)this._context.lineTo(e[1],t[1]);else for(var r=mM(e),i=mM(t),a=0,o=1;o<n;++a,++o)this._context.bezierCurveTo(r[0][a],i[0][a],r[1][a],i[1][a],e[o],t[o])}(this._line||this._line!==0&&n===1)&&this._context.closePath(),this._line=1-this._line,this._x=this._y=null},point:function(e,t){this._x.push(+e),this._y.push(+t)}};function mM(e){var t,n=e.length-1,r,i=Array(n),a=Array(n),o=Array(n);for(i[0]=0,a[0]=2,o[0]=e[0]+2*e[1],t=1;t<n-1;++t)i[t]=1,a[t]=4,o[t]=4*e[t]+2*e[t+1];for(i[n-1]=2,a[n-1]=7,o[n-1]=8*e[n-1]+e[n],t=1;t<n;++t)r=i[t]/a[t-1],a[t]-=r,o[t]-=r*o[t-1];for(i[n-1]=o[n-1]/a[n-1],t=n-2;t>=0;--t)i[t]=(o[t]-i[t+1])/a[t];for(a[n-1]=(e[n]+i[n-1])/2,t=0;t<n-1;++t)a[t]=2*e[t+1]-i[t+1];return[i,a]}function hM(e){return new pM(e)}function gM(e,t){this._context=e,this._t=t}gM.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x=this._y=NaN,this._point=0},lineEnd:function(){0<this._t&&this._t<1&&this._point===2&&this._context.lineTo(this._x,this._y),(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line>=0&&(this._t=1-this._t,this._line=1-this._line)},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;default:if(this._t<=0)this._context.lineTo(this._x,t),this._context.lineTo(e,t);else{var n=this._x*(1-this._t)+e*this._t;this._context.lineTo(n,this._y),this._context.lineTo(n,t)}}this._x=e,this._y=t}};function _M(e){return new gM(e,.5)}function vM(e){return new gM(e,0)}function yM(e){return new gM(e,1)}function bM(e,t){if((o=e.length)>1)for(var n=1,r,i,a=e[t[0]],o,s=a.length;n<o;++n)for(i=a,a=e[t[n]],r=0;r<s;++r)a[r][1]+=a[r][0]=isNaN(i[r][1])?i[r][0]:i[r][1]}function xM(e){for(var t=e.length,n=Array(t);--t>=0;)n[t]=t;return n}function SM(e,t){return e[t]}function CM(e){let t=[];return t.key=e,t}function wM(){var e=Pj([]),t=xM,n=bM,r=SM;function i(i){var a=Array.from(e.apply(this,arguments),CM),o,s=a.length,c=-1,l;for(let e of i)for(o=0,++c;o<s;++o)(a[o][c]=[0,+r(e,a[o].key,c,i)]).data=e;for(o=0,l=Vj(t(a));o<s;++o)a[l[o]].index=o;return n(a,l),a}return i.keys=function(t){return arguments.length?(e=typeof t==`function`?t:Pj(Array.from(t)),i):e},i.value=function(e){return arguments.length?(r=typeof e==`function`?e:Pj(+e),i):r},i.order=function(e){return arguments.length?(t=e==null?xM:typeof e==`function`?e:Pj(Array.from(e)),i):t},i.offset=function(e){return arguments.length?(n=e??bM,i):n},i}function TM(e,t){if((r=e.length)>0){for(var n,r,i=0,a=e[0].length,o;i<a;++i){for(o=n=0;n<r;++n)o+=e[n][i][1]||0;if(o)for(n=0;n<r;++n)e[n][i][1]/=o}bM(e,t)}}function EM(e,t){if((i=e.length)>0){for(var n=0,r=e[t[0]],i,a=r.length;n<a;++n){for(var o=0,s=0;o<i;++o)s+=e[o][n][1]||0;r[n][1]+=r[n][0]=-s/2}bM(e,t)}}function DM(e,t){if((o=e.length)>0&&(a=(i=e[t[0]]).length)>0){for(var n=0,r=1,i,a,o;r<a;++r){for(var s=0,c=0,l=0;s<o;++s){for(var u=e[t[s]],d=u[r][1]||0,f=(d-(u[r-1][1]||0))/2,p=0;p<s;++p){var m=e[t[p]],h=m[r][1]||0,g=m[r-1][1]||0;f+=h-g}c+=d,l+=f*d}i[r-1][1]+=i[r-1][0]=n,c&&(n-=l/c)}i[r-1][1]+=i[r-1][0]=n,bM(e,t)}}var OM=e=>`radius`in e&&`startAngle`in e&&`endAngle`in e,kM=(e,t)=>{if(!e||typeof e==`function`||typeof e==`boolean`)return null;var n=e;if((0,o.isValidElement)(e)&&(n=e.props),typeof n!=`object`&&typeof n!=`function`)return null;var r={};return Object.keys(n).forEach(e=>{ej(e)&&typeof n[e]==`function`&&(r[e]=t||(t=>n[e](n,t)))}),r},AM=(e,t,n)=>r=>(e(t,n,r),null),jM=(e,t,n)=>{if(e===null||typeof e!=`object`&&typeof e!=`function`)return null;var r=null;return Object.keys(e).forEach(i=>{var a=e[i];ej(i)&&typeof a==`function`&&(r||={},r[i]=AM(a,t,n))}),r};function MM(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function NM(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?MM(Object(n),!0).forEach(function(t){PM(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):MM(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function PM(e,t,n){return(t=FM(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function FM(e){var t=IM(e,`string`);return typeof t==`symbol`?t:t+``}function IM(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function LM(e,t){var n=NM({},e),r=t;return Object.keys(t).reduce((e,t)=>(e[t]===void 0&&r[t]!==void 0&&(e[t]=r[t]),e),n)}function RM(e,t){let n=new Map;for(let r=0;r<e.length;r++){let i=e[r],a=t(i,r,e);n.has(a)||n.set(a,i)}return Array.from(n.values())}function zM(e,t){return function(...n){return e.apply(this,n.slice(0,t))}}function BM(e){return e}function VM(e){return Number.isSafeInteger(e)&&e>=0}function HM(e){return e!=null&&typeof e!=`function`&&VM(e.length)}function UM(e){return function(t){return gj(t,e)}}function WM(e){return e==null||typeof e!=`object`&&typeof e!=`function`}function GM(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function KM(e){return Object.getOwnPropertySymbols(e).filter(t=>Object.prototype.propertyIsEnumerable.call(e,t))}function qM(e){return e==null?e===void 0?`[object Undefined]`:`[object Null]`:Object.prototype.toString.call(e)}var JM=`[object RegExp]`,YM=`[object String]`,XM=`[object Number]`,ZM=`[object Boolean]`,QM=`[object Arguments]`,$M=`[object Symbol]`,eN=`[object Date]`,tN=`[object Map]`,nN=`[object Set]`,rN=`[object Array]`,iN=`[object Function]`,aN=`[object ArrayBuffer]`,oN=`[object Object]`,sN=`[object Error]`,cN=`[object DataView]`,lN=`[object Uint8Array]`,uN=`[object Uint8ClampedArray]`,dN=`[object Uint16Array]`,fN=`[object Uint32Array]`,pN=`[object BigUint64Array]`,mN=`[object Int8Array]`,hN=`[object Int16Array]`,gN=`[object Int32Array]`,_N=`[object BigInt64Array]`,vN=`[object Float32Array]`,yN=`[object Float64Array]`,bN=typeof globalThis==`object`&&globalThis||typeof window==`object`&&window||typeof self==`object`&&self||typeof global==`object`&&global||(function(){return this})();function xN(e){return bN.Buffer!==void 0&&bN.Buffer.isBuffer(e)}function SN(e,t){return CN(e,void 0,e,new Map,t)}function CN(e,t,n,r=new Map,i=void 0){let a=i?.(e,t,n,r);if(a!==void 0)return a;if(WM(e))return e;if(r.has(e))return r.get(e);if(Array.isArray(e)){let t=Array(e.length);r.set(e,t);for(let a=0;a<e.length;a++)t[a]=CN(e[a],a,n,r,i);return Object.hasOwn(e,`index`)&&(t.index=e.index),Object.hasOwn(e,`input`)&&(t.input=e.input),t}if(e instanceof Date)return new Date(e.getTime());if(e instanceof RegExp){let t=new RegExp(e.source,e.flags);return t.lastIndex=e.lastIndex,t}if(e instanceof Map){let t=new Map;r.set(e,t);for(let[a,o]of e)t.set(a,CN(o,a,n,r,i));return t}if(e instanceof Set){let t=new Set;r.set(e,t);for(let a of e)t.add(CN(a,void 0,n,r,i));return t}if(xN(e))return e.subarray();if(GM(e)){let t=new(Object.getPrototypeOf(e)).constructor(e.length);r.set(e,t);for(let a=0;a<e.length;a++)t[a]=CN(e[a],a,n,r,i);return t}if(e instanceof ArrayBuffer||typeof SharedArrayBuffer<`u`&&e instanceof SharedArrayBuffer)return e.slice(0);if(e instanceof DataView){let t=new DataView(e.buffer.slice(0),e.byteOffset,e.byteLength);return r.set(e,t),wN(t,e,n,r,i),t}if(typeof File<`u`&&e instanceof File){let t=new File([e],e.name,{type:e.type});return r.set(e,t),wN(t,e,n,r,i),t}if(typeof Blob<`u`&&e instanceof Blob){let t=new Blob([e],{type:e.type});return r.set(e,t),wN(t,e,n,r,i),t}if(e instanceof Error){let t=structuredClone(e);return r.set(e,t),t.message=e.message,t.name=e.name,t.stack=e.stack,t.cause=e.cause,t.constructor=e.constructor,wN(t,e,n,r,i),t}if(e instanceof Boolean){let t=new Boolean(e.valueOf());return r.set(e,t),wN(t,e,n,r,i),t}if(e instanceof Number){let t=new Number(e.valueOf());return r.set(e,t),wN(t,e,n,r,i),t}if(e instanceof String){let t=new String(e.valueOf());return r.set(e,t),wN(t,e,n,r,i),t}if(typeof e==`object`&&TN(e)){let t=Object.create(Object.getPrototypeOf(e));return r.set(e,t),wN(t,e,n,r,i),t}return e}function wN(e,t,n=e,r,i){let a=[...Object.keys(t),...KM(t)];for(let o=0;o<a.length;o++){let s=a[o],c=Object.getOwnPropertyDescriptor(e,s);(c==null||c.writable)&&(e[s]=CN(t[s],s,n,r,i))}}function TN(e){switch(qM(e)){case QM:case rN:case aN:case cN:case ZM:case eN:case vN:case yN:case mN:case hN:case gN:case tN:case XM:case oN:case JM:case nN:case YM:case $M:case lN:case uN:case dN:case fN:return!0;default:return!1}}function EN(e){return CN(e,void 0,e,new Map,void 0)}function DN(e,t){return e===t||Number.isNaN(e)&&Number.isNaN(t)}function ON(e){return e!==null&&(typeof e==`object`||typeof e==`function`)}function kN(e,t,n){return typeof n==`function`?AN(e,t,function e(t,r,i,a,o,s){let c=n(t,r,i,a,o,s);return c===void 0?AN(t,r,e,s,!1):!!c},new Map,!0):kN(e,t,()=>void 0)}function AN(e,t,n,r,i=!1){if(t===e)return!0;switch(typeof t){case`object`:return jN(e,t,n,r,i);case`function`:return Object.keys(t).length>0?AN(e,{...t},n,r,i):DN(e,t);default:return ON(e)&&i?typeof t!=`string`||t===``:DN(e,t)}}function jN(e,t,n,r,i=!1){if(t==null)return!0;if(Array.isArray(t))return NN(e,t,n,r);if(t instanceof Map)return MN(e,t,n,r);if(t instanceof Set)return PN(e,t,n,r);let a=Object.keys(t);if(e==null)return i&&a.length===0;if(i)WM(e)&&(e=Object(e));else{let t=qM(e);if(t!==`[object Object]`&&t!==`[object Arguments]`)return!1}if(a.length===0)return!0;if(r?.has(t))return r.get(t)===e;r?.set(t,e);try{for(let i=0;i<a.length;i++){let o=a[i];if(!(o in e)||t[o]===void 0&&e[o]!==void 0||t[o]===null&&e[o]!==null||!n(e[o],t[o],o,e,t,r))return!1}return!0}finally{r?.delete(t)}}function MN(e,t,n,r){if(t.size===0)return!0;if(!(e instanceof Map))return!1;for(let[i,a]of t.entries())if(n(e.get(i),a,i,e,t,r)===!1)return!1;return!0}function NN(e,t,n,r){if(t.length===0)return!0;if(!Array.isArray(e))return!1;let i=new Set;for(let a=0;a<t.length;a++){let o=t[a],s=!1;for(let c=0;c<e.length;c++){if(i.has(c))continue;let l=e[c],u=!1;if(n(l,o,a,e,t,r)&&(u=!0),u){i.add(c),s=!0;break}}if(!s)return!1}return!0}function PN(e,t,n,r){return t.size===0||e instanceof Set&&NN([...e],[...t],n,r)}function FN(e,t){return kN(e,t,()=>void 0)}function IN(e){return e=EN(e),t=>FN(t,e)}function LN(e,t){return SN(e,(n,r,i,a)=>{let o=t?.(n,r,i,a);if(o!==void 0)return o;if(typeof e==`object`){if(qM(e)===`[object Object]`&&typeof e.constructor!=`function`){let t={};return a.set(e,t),wN(t,e,i,a),t}switch(Object.prototype.toString.call(e)){case XM:case YM:case ZM:{let t=new e.constructor(e?.valueOf());return wN(t,e),t}case QM:{let t={};return wN(t,e),t.length=e.length,t[Symbol.iterator]=e[Symbol.iterator],t}default:return}}})}function RN(e){return LN(e)}var zN=/^(?:0|[1-9]\d*)$/;function BN(e,t=2**53-1){switch(typeof e){case`number`:return Number.isInteger(e)&&e>=0&&e<t;case`symbol`:return!1;case`string`:return zN.test(e)}}function VN(e){return typeof e==`object`&&!!e&&qM(e)===`[object Arguments]`}function HN(e,t){let n;if(n=Array.isArray(t)?t:typeof t==`string`&&dj(t)&&!(t in Object(e))?hj(t):[t],n.length===0)return!1;let r=e;for(let e=0;e<n.length;e++){let t=fj(n[e]);if((r==null||!Object.hasOwn(r,t))&&!((Array.isArray(r)||VN(r))&&BN(t)&&Number(t)<r.length))return!1;r=r[t]}return!0}function UN(e,t){switch(typeof e){case`object`:Object.is(e?.valueOf(),-0)&&(e=`-0`);break;case`number`:e=fj(e)}return t=RN(t),function(n){let r=gj(n,e);return r===void 0?HN(n,e):t===void 0?r===void 0:FN(r,t)}}function WN(e){if(e==null)return BM;switch(typeof e){case`function`:return e;case`object`:return Array.isArray(e)&&e.length===2?UN(e[0],e[1]):IN(e);default:return UM(e)}}function GN(e){return e===0?0:e}function KN(e,t=BM){return HM(e)?RM(Array.from(e),zM(WN(t),1)).map(GN):[]}function qN(e,t,n){return t===!0?KN(e,n):typeof t==`function`?KN(e,t):e}var JN=(0,o.createContext)(null),YN=e=>e,XN=()=>{var e=(0,o.useContext)(JN);return e?e.store.dispatch:YN},ZN=()=>{},QN=()=>ZN,$N=(e,t)=>e===t;function Y(e){var t=(0,o.useContext)(JN),n=(0,o.useMemo)(()=>t?t=>{if(t!=null)return e(t)}:ZN,[t,e]);return(0,qC.useSyncExternalStoreWithSelector)(t?t.subscription.addNestedSub:QN,t?t.store.getState:ZN,t?t.store.getState:ZN,n,$N)}function eP(e,t=`expected a function, instead received ${typeof e}`){if(typeof e!=`function`)throw TypeError(t)}function tP(e,t=`expected all items to be functions, instead received the following types: `){if(!e.every(e=>typeof e==`function`)){let n=e.map(e=>typeof e==`function`?`function ${e.name||`unnamed`}()`:typeof e).join(`, `);throw TypeError(`${t}[${n}]`)}}var nP=e=>Array.isArray(e)?e:[e];function rP(e){let t=Array.isArray(e[0])?e[0]:e;return tP(t,`createSelector expects all input-selectors to be functions, but received the following types: `),t}function iP(e,t){let n=[],{length:r}=e;for(let i=0;i<r;i++)n.push(e[i].apply(null,t));return n}var aP=class{constructor(e){this.value=e}deref(){return this.value}},oP=typeof WeakRef>`u`?aP:WeakRef,sP=0,cP=1;function lP(){return{s:sP,v:void 0,o:null,p:null}}function uP(e){return e instanceof oP?e.deref():e}function dP(e,t={}){let n=lP(),{resultEqualityCheck:r}=t,i,a=0;function o(){let t=n,{length:o}=arguments;for(let e=0,n=o;e<n;e++){let n=arguments[e];if(typeof n==`function`||typeof n==`object`&&n){let e=t.o;e===null&&(t.o=e=new WeakMap);let r=e.get(n);r===void 0?(t=lP(),e.set(n,t)):t=r}else{let e=t.p;e===null&&(t.p=e=new Map);let r=e.get(n);r===void 0?(t=lP(),e.set(n,t)):t=r}}let s=t,c;if(t.s===cP)c=t.v;else if(c=e.apply(null,arguments),a++,r){let e=uP(i);e!=null&&r(e,c)&&(c=e,a!==0&&a--),i=typeof c==`object`&&c||typeof c==`function`?new oP(c):c}return s.s=cP,s.v=c,c}return o.clearCache=()=>{n=lP(),o.resetResultsCount()},o.resultsCount=()=>a,o.resetResultsCount=()=>{a=0},o}function fP(e,...t){let n=typeof e==`function`?{memoize:e,memoizeOptions:t}:e,r=(...e)=>{let t=0,r=0,i,a={},o=e.pop();typeof o==`object`&&(a=o,o=e.pop()),eP(o,`createSelector expects an output function after the inputs, but received: [${typeof o}]`);let{memoize:s,memoizeOptions:c=[],argsMemoize:l=dP,argsMemoizeOptions:u=[]}={...n,...a},d=nP(c),f=nP(u),p=rP(e),m=s(function(){return t++,o.apply(null,arguments)},...d),h=l(function(){r++;let e=iP(p,arguments);return i=m.apply(null,e),i},...f);return Object.assign(h,{resultFunc:o,memoizedResultFunc:m,dependencies:p,dependencyRecomputations:()=>r,resetDependencyRecomputations:()=>{r=0},lastResult:()=>i,recomputations:()=>t,resetRecomputations:()=>{t=0},memoize:s,argsMemoize:l})};return Object.assign(r,{withTypes:()=>r}),r}var X=fP(dP);function pP(e,t=1){let n=[],r=Math.floor(t),i=(e,t)=>{for(let a=0;a<e.length;a++){let o=e[a];Array.isArray(o)&&t<r?i(o,t+1):n.push(o)}};return i(e,0),n}function mP(e,t,n){return ON(n)&&(typeof t==`number`&&HM(n)&&BN(t)&&t<n.length||typeof t==`string`&&t in n)?DN(n[t],e):!1}function hP(e){return typeof e==`symbol`?1:e===null?2:e===void 0?3:e===e?0:4}var gP=(e,t,n)=>{if(e!==t){let r=hP(e),i=hP(t);if(r===i&&r===0){if(e<t)return n===`desc`?1:-1;if(e>t)return n===`desc`?-1:1}return n===`desc`?i-r:r-i}return 0},_P=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,vP=/^\w*$/;function yP(e,t){return Array.isArray(e)?!1:typeof e==`number`||typeof e==`boolean`||e==null||pj(e)?!0:typeof e==`string`&&(vP.test(e)||!_P.test(e))||t!=null&&Object.hasOwn(t,e)}function bP(e,t,n,r){if(e==null)return[];n=r?void 0:n,Array.isArray(e)||(e=HM(e)?Array.from(e):Object.values(e)),Array.isArray(t)||(t=t==null?[null]:[t]),t.length===0&&(t=[null]),Array.isArray(n)||(n=n==null?[]:[n]),n=n.map(e=>String(e));let i=(e,t)=>{let n=e,r=0;for(;r<t.length&&n!=null;++r)n=n[t[r]];return r>0&&r===t.length?n:void 0},a=(e,t)=>{if(e==null)return t;if(t!=null)return typeof e==`object`&&`key`in e?Object.hasOwn(t,e.key)?t[e.key]:i(t,e.path):typeof e==`function`?e(t):Array.isArray(e)?i(t,e):t[e]},o=t.map(e=>(Array.isArray(e)&&e.length===1&&(e=e[0]),e==null||typeof e==`function`||Array.isArray(e)||yP(e)?e:{key:e,path:hj(e)}));return e.map(e=>({original:e,criteria:o.map(t=>a(t,e))})).slice().sort((e,t)=>{for(let r=0;r<o.length;r++){let i=gP(e.criteria[r],t.criteria[r],n[r]);if(i!==0)return i}return 0}).map(e=>e.original)}function xP(e,...t){let n=t.length;return n>1&&mP(e,t[0],t[1])?t=[]:n>2&&mP(t[0],t[1],t[2])&&(t=[t[0]]),bP(e,pP(t),[`asc`])}var SP=e=>e.legend.settings,CP=e=>e.legend.size;X([e=>e.legend.payload,SP],(e,t)=>{var n=t.itemSorter,r=e.flat(1);return n?xP(r,n):r});function wP(e,t){return kP(e)||OP(e,t)||EP(e,t)||TP()}function TP(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
13
13
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function EP(e,t){if(e){if(typeof e==`string`)return DP(e,t);var n={}.toString.call(e).slice(8,-1);return n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`?Array.from(e):n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?DP(e,t):void 0}}function DP(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function OP(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r,i,a,o,s=[],c=!0,l=!1;try{if(a=(n=n.call(e)).next,t===0){if(Object(n)!==n)return;c=!1}else for(;!(c=(r=a.call(n)).done)&&(s.push(r.value),s.length!==t);c=!0);}catch(e){l=!0,i=e}finally{try{if(!c&&n.return!=null&&(o=n.return(),Object(o)!==o))return}finally{if(l)throw i}}return s}}function kP(e){if(Array.isArray(e))return e}var AP=1;function jP(e,t){return Math.abs(e.height-t.height)>AP||Math.abs(e.left-t.left)>AP||Math.abs(e.top-t.top)>AP||Math.abs(e.width-t.width)>AP}function MP(e){var t=e.getBoundingClientRect();return{height:t.height,left:t.left,top:t.top,width:t.width}}function NP(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],t=wP((0,o.useState)({height:0,left:0,top:0,width:0}),2),n=t[0],r=t[1],i=(0,o.useRef)(null),a=(0,o.useRef)(n);a.current=n;var s=(0,o.useCallback)(e=>{if(i.current!=null&&(i.current.disconnect(),i.current=null),e!=null){var t=MP(e);if(jP(t,a.current)&&r(t),typeof ResizeObserver<`u`){var n=new ResizeObserver(()=>{var t=MP(e);jP(t,a.current)&&r(t)});n.observe(e),i.current=n}}},[...e]);return(0,o.useEffect)(()=>()=>{var e;(e=i.current)==null||e.disconnect()},[]),[n,s]}function PP(e){return`Minified Redux error #${e}; visit https://redux.js.org/Errors?code=${e} for the full message or use the non-minified dev environment for full errors. `}var FP=typeof Symbol==`function`&&Symbol.observable||`@@observable`,IP=()=>Math.random().toString(36).substring(7).split(``).join(`.`),LP={INIT:`@@redux/INIT${IP()}`,REPLACE:`@@redux/REPLACE${IP()}`,PROBE_UNKNOWN_ACTION:()=>`@@redux/PROBE_UNKNOWN_ACTION${IP()}`};function RP(e){if(typeof e!=`object`||!e)return!1;let t=e;for(;Object.getPrototypeOf(t)!==null;)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(e)===t||Object.getPrototypeOf(e)===null}function zP(e,t,n){if(typeof e!=`function`)throw Error(PP(2));if(typeof t==`function`&&typeof n==`function`||typeof n==`function`&&typeof arguments[3]==`function`)throw Error(PP(0));if(typeof t==`function`&&n===void 0&&(n=t,t=void 0),n!==void 0){if(typeof n!=`function`)throw Error(PP(1));return n(zP)(e,t)}let r=e,i=t,a=new Map,o=a,s=0,c=!1;function l(){o===a&&(o=new Map,a.forEach((e,t)=>{o.set(t,e)}))}function u(){if(c)throw Error(PP(3));return i}function d(e){if(typeof e!=`function`)throw Error(PP(4));if(c)throw Error(PP(5));let t=!0;l();let n=s++;return o.set(n,e),function(){if(t){if(c)throw Error(PP(6));t=!1,l(),o.delete(n),a=null}}}function f(e){if(!RP(e))throw Error(PP(7));if(e.type===void 0)throw Error(PP(8));if(typeof e.type!=`string`)throw Error(PP(17));if(c)throw Error(PP(9));try{c=!0,i=r(i,e)}finally{c=!1}return(a=o).forEach(e=>{e()}),e}function p(e){if(typeof e!=`function`)throw Error(PP(10));r=e,f({type:LP.REPLACE})}function m(){let e=d;return{subscribe(t){if(typeof t!=`object`||!t)throw Error(PP(11));function n(){let e=t;e.next&&e.next(u())}return n(),{unsubscribe:e(n)}},[FP](){return this}}}return f({type:LP.INIT}),{dispatch:f,subscribe:d,getState:u,replaceReducer:p,[FP]:m}}function BP(e){Object.keys(e).forEach(t=>{let n=e[t];if(n(void 0,{type:LP.INIT})===void 0)throw Error(PP(12));if(n(void 0,{type:LP.PROBE_UNKNOWN_ACTION()})===void 0)throw Error(PP(13))})}function VP(e){let t=Object.keys(e),n={};for(let r=0;r<t.length;r++){let i=t[r];typeof e[i]==`function`&&(n[i]=e[i])}let r=Object.keys(n),i;try{BP(n)}catch(e){i=e}return function(e={},t){if(i)throw i;let a=!1,o={};for(let i=0;i<r.length;i++){let s=r[i],c=n[s],l=e[s],u=c(l,t);if(u===void 0)throw t&&t.type,Error(PP(14));o[s]=u,a||=u!==l}return a||=r.length!==Object.keys(e).length,a?o:e}}function HP(...e){return e.length===0?e=>e:e.length===1?e[0]:e.reduce((e,t)=>(...n)=>e(t(...n)))}function UP(...e){return t=>(n,r)=>{let i=t(n,r),a=()=>{throw Error(PP(15))},o={getState:i.getState,dispatch:(e,...t)=>a(e,...t)};return a=HP(...e.map(e=>e(o)))(i.dispatch),{...i,dispatch:a}}}function WP(e){return RP(e)&&`type`in e&&typeof e.type==`string`}var GP=Symbol.for(`immer-nothing`),KP=Symbol.for(`immer-draftable`),qP=Symbol.for(`immer-state`);function JP(e,...t){throw Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`)}var YP=Object,XP=YP.getPrototypeOf,ZP=`constructor`,QP=`prototype`,$P=`configurable`,eF=`enumerable`,tF=`writable`,nF=`value`,rF=e=>!!e&&!!e[qP];function iF(e){return e?sF(e)||mF(e)||!!e[KP]||!!e[ZP]?.[KP]||hF(e)||gF(e):!1}var aF=YP[QP][ZP].toString(),oF=new WeakMap;function sF(e){if(!e||!_F(e))return!1;let t=XP(e);if(t===null||t===YP[QP])return!0;let n=YP.hasOwnProperty.call(t,ZP)&&t[ZP];if(n===Object)return!0;if(!vF(n))return!1;let r=oF.get(n);return r===void 0&&(r=Function.toString.call(n),oF.set(n,r)),r===aF}function cF(e,t,n=!0){lF(e)===0?(n?Reflect.ownKeys(e):YP.keys(e)).forEach(n=>{t(n,e[n],e)}):e.forEach((n,r)=>t(r,n,e))}function lF(e){let t=e[qP];return t?t.type_:mF(e)?1:hF(e)?2:gF(e)?3:0}var uF=(e,t,n=lF(e))=>n===2?e.has(t):YP[QP].hasOwnProperty.call(e,t),dF=(e,t,n=lF(e))=>n===2?e.get(t):e[t],fF=(e,t,n,r=lF(e))=>{r===2?e.set(t,n):r===3?e.add(n):e[t]=n};function pF(e,t){return e===t?e!==0||1/e==1/t:e!==e&&t!==t}var mF=Array.isArray,hF=e=>e instanceof Map,gF=e=>e instanceof Set,_F=e=>typeof e==`object`,vF=e=>typeof e==`function`,yF=e=>typeof e==`boolean`;function bF(e){let t=+e;return Number.isInteger(t)&&String(t)===e}var xF=e=>e.copy_||e.base_,SF=e=>e.modified_?e.copy_:e.base_;function CF(e,t){if(hF(e))return new Map(e);if(gF(e))return new Set(e);if(mF(e))return Array[QP].slice.call(e);let n=sF(e);if(t===!0||t===`class_only`&&!n){let t=YP.getOwnPropertyDescriptors(e);delete t[qP];let n=Reflect.ownKeys(t);for(let r=0;r<n.length;r++){let i=n[r],a=t[i];a[tF]===!1&&(a[tF]=!0,a[$P]=!0),(a.get||a.set)&&(t[i]={[$P]:!0,[tF]:!0,[eF]:a[eF],[nF]:e[i]})}return YP.create(XP(e),t)}{let t=XP(e);if(t!==null&&n)return{...e};let r=YP.create(t);return YP.assign(r,e)}}function wF(e,t=!1){return DF(e)||rF(e)||!iF(e)?e:(lF(e)>1&&YP.defineProperties(e,{set:EF,add:EF,clear:EF,delete:EF}),YP.freeze(e),t&&cF(e,(e,t)=>{wF(t,!0)},!1),e)}function TF(){JP(2)}var EF={[nF]:TF};function DF(e){return e===null||!_F(e)||YP.isFrozen(e)}var OF=`MapSet`,kF=`Patches`,AF=`ArrayMethods`,jF={};function MF(e){let t=jF[e];return t||JP(0,e),t}var NF=e=>!!jF[e],PF,FF=()=>PF,IF=(e,t)=>({drafts_:[],parent_:e,immer_:t,canAutoFreeze_:!0,unfinalizedDrafts_:0,handledSet_:new Set,processedForPatches_:new Set,mapSetPlugin_:NF(OF)?MF(OF):void 0,arrayMethodsPlugin_:NF(AF)?MF(AF):void 0});function LF(e,t){t&&(e.patchPlugin_=MF(kF),e.patches_=[],e.inversePatches_=[],e.patchListener_=t)}function RF(e){zF(e),e.drafts_.forEach(VF),e.drafts_=null}function zF(e){e===PF&&(PF=e.parent_)}var BF=e=>PF=IF(PF,e);function VF(e){let t=e[qP];t.type_===0||t.type_===1?t.revoke_():t.revoked_=!0}function HF(e,t){t.unfinalizedDrafts_=t.drafts_.length;let n=t.drafts_[0];if(e!==void 0&&e!==n){n[qP].modified_&&(RF(t),JP(4)),iF(e)&&(e=UF(t,e));let{patchPlugin_:r}=t;r&&r.generateReplacementPatches_(n[qP].base_,e,t)}else e=UF(t,n);return WF(t,e,!0),RF(t),t.patches_&&t.patchListener_(t.patches_,t.inversePatches_),e===GP?void 0:e}function UF(e,t){if(DF(t))return t;let n=t[qP];if(!n)return QF(t,e.handledSet_,e);if(!KF(n,e))return t;if(!n.modified_)return n.base_;if(!n.finalized_){let{callbacks_:t}=n;if(t)for(;t.length>0;)t.pop()(e);XF(n,e)}return n.copy_}function WF(e,t,n=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&wF(t,n)}function GF(e){e.finalized_=!0,e.scope_.unfinalizedDrafts_--}var KF=(e,t)=>e.scope_===t,qF=[];function JF(e,t,n,r){let i=xF(e),a=e.type_;if(r!==void 0&&dF(i,r,a)===t){fF(i,r,n,a);return}if(!e.draftLocations_){let t=e.draftLocations_=new Map;cF(i,(e,n)=>{if(rF(n)){let r=t.get(n)||[];r.push(e),t.set(n,r)}})}let o=e.draftLocations_.get(t)??qF;for(let e of o)fF(i,e,n,a)}function YF(e,t,n){e.callbacks_.push(function(r){let i=t;if(!i||!KF(i,r))return;r.mapSetPlugin_?.fixSetContents(i);let a=SF(i);JF(e,i.draft_??i,a,n),XF(i,r)})}function XF(e,t){if(e.modified_&&!e.finalized_&&(e.type_===3||e.type_===1&&e.allIndicesReassigned_||(e.assigned_?.size??0)>0)){let{patchPlugin_:n}=t;if(n){let r=n.getPath(e);r&&n.generatePatches_(e,r,t)}GF(e)}}function ZF(e,t,n){let{scope_:r}=e;if(rF(n)){let i=n[qP];KF(i,r)&&i.callbacks_.push(function(){sI(e),JF(e,n,SF(i),t)})}else iF(n)&&e.callbacks_.push(function(){let i=xF(e);e.type_===3?i.has(n)&&QF(n,r.handledSet_,r):dF(i,t,e.type_)===n&&r.drafts_.length>1&&(e.assigned_.get(t)??!1)===!0&&e.copy_&&QF(dF(e.copy_,t,e.type_),r.handledSet_,r)})}function QF(e,t,n){return!n.immer_.autoFreeze_&&n.unfinalizedDrafts_<1||rF(e)||t.has(e)||!iF(e)||DF(e)?e:(t.add(e),cF(e,(r,i)=>{if(rF(i)){let t=i[qP];KF(t,n)&&(fF(e,r,SF(t),e.type_),GF(t))}else iF(i)&&QF(i,t,n)}),e)}function $F(e,t){let n=mF(e),r={type_:+!!n,scope_:t?t.scope_:FF(),modified_:!1,finalized_:!1,assigned_:void 0,parent_:t,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1,callbacks_:void 0},i=r,a=eI;n&&(i=[r],a=tI);let{revoke:o,proxy:s}=Proxy.revocable(i,a);return r.draft_=s,r.revoke_=o,[s,r]}var eI={get(e,t){if(t===qP)return e;let n=e.scope_.arrayMethodsPlugin_,r=e.type_===1&&typeof t==`string`;if(r&&n?.isArrayOperationMethod(t))return n.createMethodInterceptor(e,t);let i=xF(e);if(!uF(i,t,e.type_))return iI(e,i,t);let a=i[t];if(e.finalized_||!iF(a)||r&&e.operationMethod&&n?.isMutatingArrayMethod(e.operationMethod)&&bF(t))return a;if(a===nI(e.base_,t)||rI(e,t,a)){sI(e);let n=e.type_===1?+t:t,r=lI(e.scope_,a,e,n);return e.copy_[n]=r}return a},has(e,t){return t in xF(e)},ownKeys(e){return Reflect.ownKeys(xF(e))},set(e,t,n){let r=aI(xF(e),t);if(r?.set)return r.set.call(e.draft_,n),!0;if(!e.modified_){let r=nI(xF(e),t),i=r?.[qP];if(i&&i.base_===n)return e.copy_[t]=n,e.assigned_.delete(t),!0;if(pF(n,r)&&(n!==void 0||uF(e.base_,t,e.type_)))return!0;sI(e),oI(e)}return e.copy_[t]===n&&(n!==void 0||uF(e.copy_,t,e.type_))||Number.isNaN(n)&&Number.isNaN(e.copy_[t])?!0:(e.copy_[t]=n,e.assigned_.set(t,!0),ZF(e,t,n),!0)},deleteProperty(e,t){return sI(e),nI(e.base_,t)!==void 0||t in e.base_?(e.assigned_.set(t,!1),oI(e)):e.assigned_.delete(t),e.copy_&&delete e.copy_[t],!0},getOwnPropertyDescriptor(e,t){let n=xF(e),r=Reflect.getOwnPropertyDescriptor(n,t);return r&&{[tF]:!0,[$P]:e.type_!==1||t!==`length`,[eF]:r[eF],[nF]:n[t]}},defineProperty(){JP(11)},getPrototypeOf(e){return XP(e.base_)},setPrototypeOf(){JP(12)}},tI={};for(let e in eI){let t=eI[e];tI[e]=function(){let e=arguments;return e[0]=e[0][0],t.apply(this,e)}}tI.deleteProperty=function(e,t){return tI.set.call(this,e,t,void 0)},tI.set=function(e,t,n){return eI.set.call(this,e[0],t,n,e[0])};function nI(e,t){let n=e[qP];return(n?xF(n):e)[t]}function rI(e,t,n){return e.type_!==1||!e.allIndicesReassigned_||e.assigned_?.get(t)||!iF(n)||n[qP]?!1:e.baseRefs_.has(n)}function iI(e,t,n){let r=aI(t,n);return r?nF in r?r[nF]:r.get?.call(e.draft_):void 0}function aI(e,t){if(!(t in e))return;let n=XP(e);for(;n;){let e=Object.getOwnPropertyDescriptor(n,t);if(e)return e;n=XP(n)}}function oI(e){e.modified_||(e.modified_=!0,e.parent_&&oI(e.parent_))}function sI(e){e.copy_||=(e.assigned_=new Map,CF(e.base_,e.scope_.immer_.useStrictShallowCopy_))}var cI=class{constructor(e){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.useStrictIteration_=!1,this.produce=(e,t,n)=>{if(vF(e)&&!vF(t)){let n=t;t=e;let r=this;return function(e=n,...i){return r.produce(e,e=>t.call(this,e,...i))}}vF(t)||JP(6),n!==void 0&&!vF(n)&&JP(7);let r;if(iF(e)){let i=BF(this),a=lI(i,e,void 0),o=!0;try{r=t(a),o=!1}finally{o?RF(i):zF(i)}return LF(i,n),HF(r,i)}if(!e||!_F(e)){if(r=t(e),r===void 0&&(r=e),r===GP&&(r=void 0),this.autoFreeze_&&wF(r,!0),n){let t=[],i=[];MF(kF).generateReplacementPatches_(e,r,{patches_:t,inversePatches_:i}),n(t,i)}return r}JP(1,e)},this.produceWithPatches=(e,t)=>{if(vF(e))return(t,...n)=>this.produceWithPatches(t,t=>e(t,...n));let n,r;return[this.produce(e,t,(e,t)=>{n=e,r=t}),n,r]},yF(e?.autoFreeze)&&this.setAutoFreeze(e.autoFreeze),yF(e?.useStrictShallowCopy)&&this.setUseStrictShallowCopy(e.useStrictShallowCopy),yF(e?.useStrictIteration)&&this.setUseStrictIteration(e.useStrictIteration)}createDraft(e){iF(e)||JP(8),rF(e)&&(e=uI(e));let t=BF(this),n=lI(t,e,void 0);return n[qP].isManual_=!0,zF(t),n}finishDraft(e,t){let n=e&&e[qP];(!n||!n.isManual_)&&JP(9);let{scope_:r}=n;return LF(r,t),HF(void 0,r)}setAutoFreeze(e){this.autoFreeze_=e}setUseStrictShallowCopy(e){this.useStrictShallowCopy_=e}setUseStrictIteration(e){this.useStrictIteration_=e}shouldUseStrictIteration(){return this.useStrictIteration_}applyPatches(e,t){let n;for(n=t.length-1;n>=0;n--){let r=t[n];if(r.path.length===0&&r.op===`replace`){e=r.value;break}}n>-1&&(t=t.slice(n+1));let r=MF(kF).applyPatches_;return rF(e)?r(e,t):this.produce(e,e=>r(e,t))}};function lI(e,t,n,r){let[i,a]=hF(t)?MF(OF).proxyMap_(t,n):gF(t)?MF(OF).proxySet_(t,n):$F(t,n);return(n?.scope_??FF()).drafts_.push(i),a.callbacks_=n?.callbacks_??[],a.key_=r,n&&r!==void 0?YF(n,a,r):a.callbacks_.push(function(e){e.mapSetPlugin_?.fixSetContents(a);let{patchPlugin_:t}=e;a.modified_&&t&&t.generatePatches_(a,[],e)}),i}function uI(e){return rF(e)||JP(10,e),dI(e)}function dI(e){if(!iF(e)||DF(e))return e;let t=e[qP],n,r=!0;if(t){if(!t.modified_)return t.base_;t.finalized_=!0,n=CF(e,t.scope_.immer_.useStrictShallowCopy_),r=t.scope_.immer_.shouldUseStrictIteration()}else n=CF(e,!0);return cF(n,(e,t)=>{fF(n,e,dI(t))},r),t&&(t.finalized_=!1),n}globalThis.Iterator?.from;var fI=new cI().produce,Z=e=>e;function pI(e){return({dispatch:t,getState:n})=>r=>i=>typeof i==`function`?i(t,n,e):r(i)}var mI=pI(),hI=pI,gI=typeof window<`u`&&window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__?window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__:function(){if(arguments.length!==0)return typeof arguments[0]==`object`?HP:HP.apply(null,arguments)};typeof window<`u`&&window.__REDUX_DEVTOOLS_EXTENSION__&&window.__REDUX_DEVTOOLS_EXTENSION__;function _I(e,t){function n(...n){if(t){let r=t(...n);if(!r)throw Error(EL(0));return{type:e,payload:r.payload,...`meta`in r&&{meta:r.meta},...`error`in r&&{error:r.error}}}return{type:e,payload:n[0]}}return n.toString=()=>`${e}`,n.type=e,n.match=t=>WP(t)&&t.type===e,n}var vI=class e extends Array{constructor(...t){super(...t),Object.setPrototypeOf(this,e.prototype)}static get[Symbol.species](){return e}concat(...e){return super.concat.apply(this,e)}prepend(...t){return t.length===1&&Array.isArray(t[0])?new e(...t[0].concat(this)):new e(...t.concat(this))}};function yI(e){return iF(e)?fI(e,()=>{}):e}function bI(e,t,n){return e.has(t)?e.get(t):e.set(t,n(t)).get(t)}function xI(e){return typeof e==`boolean`}var SI=()=>function(e){let{thunk:t=!0,immutableCheck:n=!0,serializableCheck:r=!0,actionCreatorCheck:i=!0}=e??{},a=new vI;return t&&(xI(t)?a.push(mI):a.push(hI(t.extraArgument))),a},CI=`RTK_autoBatch`,wI=()=>e=>({payload:e,meta:{[CI]:!0}}),TI=e=>t=>{setTimeout(t,e)},EI=(e,t)=>n=>{let r=!1,i,a,o=()=>{r||(r=!0,cancelAnimationFrame(i),clearTimeout(a),n())};i=e(o),a=setTimeout(o,t)},DI=(e={type:`raf`})=>t=>(...n)=>{let r=t(...n),i=!0,a=!1,o=!1,s=new Set,c=e.type===`tick`?queueMicrotask:e.type===`raf`?typeof window<`u`&&window.requestAnimationFrame?EI(window.requestAnimationFrame,100):TI(10):e.type===`callback`?e.queueNotification:TI(e.timeout),l=()=>{o=!1,a&&(a=!1,s.forEach(e=>e()))};return Object.assign({},r,{subscribe(e){let t=r.subscribe(()=>i&&e());return s.add(e),()=>{t(),s.delete(e)}},dispatch(e){try{return i=!e?.meta?.[CI],a=!i,a&&(o||(o=!0,c(l))),r.dispatch(e)}finally{i=!0}}})},OI=e=>function(t){let{autoBatch:n=!0}=t??{},r=new vI(e);return n&&r.push(DI(typeof n==`object`?n:void 0)),r};function kI(e){let t=SI(),{reducer:n=void 0,middleware:r,devTools:i=!0,duplicateMiddlewareCheck:a=!0,preloadedState:o=void 0,enhancers:s=void 0}=e||{},c;if(typeof n==`function`)c=n;else if(RP(n))c=VP(n);else throw Error(EL(1));let l;l=typeof r==`function`?r(t):t();let u=HP;i&&(u=gI({trace:!1,...typeof i==`object`&&i}));let d=OI(UP(...l)),f=typeof s==`function`?s(d):d(),p=u(...f);return zP(c,o,p)}function AI(e){let t={},n=[],r,i={addCase(e,n){let r=typeof e==`string`?e:e.type;if(!r)throw Error(EL(28));if(r in t)throw Error(EL(29));return t[r]=n,i},addAsyncThunk(e,r){return r.pending&&(t[e.pending.type]=r.pending),r.rejected&&(t[e.rejected.type]=r.rejected),r.fulfilled&&(t[e.fulfilled.type]=r.fulfilled),r.settled&&n.push({matcher:e.settled,reducer:r.settled}),i},addMatcher(e,t){return n.push({matcher:e,reducer:t}),i},addDefaultCase(e){return r=e,i}};return e(i),[t,n,r]}function jI(e){return typeof e==`function`}function MI(e,t){let[n,r,i]=AI(t),a;if(jI(e))a=()=>yI(e());else{let t=yI(e);a=()=>t}function o(e=a(),t){let o=[n[t.type],...r.filter(({matcher:e})=>e(t)).map(({reducer:e})=>e)];return o.filter(e=>!!e).length===0&&(o=[i]),o.reduce((e,n)=>{if(n){if(rF(e)){let r=n(e,t);return r===void 0?e:r}if(iF(e))return fI(e,e=>n(e,t));{let r=n(e,t);if(r===void 0){if(e===null)return e;throw Error(EL(9))}return r}}return e},e)}return o.getInitialState=a,o}var NI=`ModuleSymbhasOwnPr-0123456789ABCDEFGHNRVfgctiUvz_KqYTJkLxpZXIjQW`,PI=(e=21)=>{let t=``,n=e;for(;n--;)t+=NI[Math.random()*64|0];return t},FI=Symbol.for(`rtk-slice-createasyncthunk`);function II(e,t){return`${e}/${t}`}function LI({creators:e}={}){let t=e?.asyncThunk?.[FI];return function(e){let{name:n,reducerPath:r=n}=e;if(!n)throw Error(EL(11));let i=(typeof e.reducers==`function`?e.reducers(BI()):e.reducers)||{},a=Object.keys(i),o={sliceCaseReducersByName:{},sliceCaseReducersByType:{},actionCreators:{},sliceMatchers:[]},s={addCase(e,t){let n=typeof e==`string`?e:e.type;if(!n)throw Error(EL(12));if(n in o.sliceCaseReducersByType)throw Error(EL(13));return o.sliceCaseReducersByType[n]=t,s},addMatcher(e,t){return o.sliceMatchers.push({matcher:e,reducer:t}),s},exposeAction(e,t){return o.actionCreators[e]=t,s},exposeCaseReducer(e,t){return o.sliceCaseReducersByName[e]=t,s}};a.forEach(r=>{let a=i[r],o={reducerName:r,type:II(n,r),createNotation:typeof e.reducers==`function`};HI(a)?WI(o,a,s,t):VI(o,a,s)});function c(){let[t={},n=[],r=void 0]=typeof e.extraReducers==`function`?AI(e.extraReducers):[e.extraReducers],i={...t,...o.sliceCaseReducersByType};return MI(e.initialState,e=>{for(let t in i)e.addCase(t,i[t]);for(let t of o.sliceMatchers)e.addMatcher(t.matcher,t.reducer);for(let t of n)e.addMatcher(t.matcher,t.reducer);r&&e.addDefaultCase(r)})}let l=e=>e,u=new Map,d=new WeakMap,f;function p(e,t){return f||=c(),f(e,t)}function m(){return f||=c(),f.getInitialState()}function h(t,n=!1){function r(e){let i=e[t];return i===void 0&&n&&(i=bI(d,r,m)),i}function i(t=l){return bI(bI(u,n,()=>new WeakMap),t,()=>{let r={};for(let[i,a]of Object.entries(e.selectors??{}))r[i]=RI(a,t,()=>bI(d,t,m),n);return r})}return{reducerPath:t,getSelectors:i,get selectors(){return i(r)},selectSlice:r}}let g={name:n,reducer:p,actions:o.actionCreators,caseReducers:o.sliceCaseReducersByName,getInitialState:m,...h(r),injectInto(e,{reducerPath:t,...n}={}){let i=t??r;return e.inject({reducerPath:i,reducer:p},n),{...g,...h(i,!0)}}};return g}}function RI(e,t,n,r){function i(i,...a){let o=t(i);return o===void 0&&r&&(o=n()),e(o,...a)}return i.unwrapped=e,i}var zI=LI();function BI(){function e(e,t){return{_reducerDefinitionType:`asyncThunk`,payloadCreator:e,...t}}return e.withTypes=()=>e,{reducer(e){return Object.assign({[e.name](...t){return e(...t)}}[e.name],{_reducerDefinitionType:`reducer`})},preparedReducer(e,t){return{_reducerDefinitionType:`reducerWithPrepare`,prepare:e,reducer:t}},asyncThunk:e}}function VI({type:e,reducerName:t,createNotation:n},r,i){let a,o;if(`reducer`in r){if(n&&!UI(r))throw Error(EL(17));a=r.reducer,o=r.prepare}else a=r;i.addCase(e,a).exposeCaseReducer(t,a).exposeAction(t,o?_I(e,o):_I(e))}function HI(e){return e._reducerDefinitionType===`asyncThunk`}function UI(e){return e._reducerDefinitionType===`reducerWithPrepare`}function WI({type:e,reducerName:t},n,r,i){if(!i)throw Error(EL(18));let{payloadCreator:a,fulfilled:o,pending:s,rejected:c,settled:l,options:u}=n,d=i(e,a,u);r.exposeAction(t,d),o&&r.addCase(d.fulfilled,o),s&&r.addCase(d.pending,s),c&&r.addCase(d.rejected,c),l&&r.addMatcher(d.settled,l),r.exposeCaseReducer(t,{fulfilled:o||GI,pending:s||GI,rejected:c||GI,settled:l||GI})}function GI(){}var KI=`task`,qI=`listener`,JI=`completed`,YI=`cancelled`,XI=`task-${YI}`,ZI=`task-${JI}`,QI=`${qI}-${YI}`,$I=`${qI}-${JI}`,eL=class{code;name=`TaskAbortError`;message;constructor(e){this.code=e,this.message=`${KI} ${YI} (reason: ${e})`}},tL=(e,t)=>{if(typeof e!=`function`)throw TypeError(EL(32))},nL=()=>{},rL=(e,t=nL)=>(e.catch(t),e),iL=(e,t)=>(e.addEventListener(`abort`,t,{once:!0}),()=>e.removeEventListener(`abort`,t)),aL=e=>{if(e.aborted)throw new eL(e.reason)};function oL(e,t){let n=nL;return new Promise((r,i)=>{let a=()=>i(new eL(e.reason));if(e.aborted){a();return}n=iL(e,a),t.finally(()=>n()).then(r,i)}).finally(()=>{n=nL})}var sL=async(e,t)=>{try{return await Promise.resolve(),{status:`ok`,value:await e()}}catch(e){return{status:e instanceof eL?`cancelled`:`rejected`,error:e}}finally{t?.()}},cL=e=>t=>rL(oL(e,t).then(t=>(aL(e),t))),lL=e=>{let t=cL(e);return e=>t(new Promise(t=>setTimeout(t,e)))},{assign:uL}=Object,dL={},fL=`listenerMiddleware`,pL=(e,t)=>{let n=t=>iL(e,()=>t.abort(e.reason));return(r,i)=>{tL(r,`taskExecutor`);let a=new AbortController;n(a);let o=sL(async()=>{aL(e),aL(a.signal);let t=await r({pause:cL(a.signal),delay:lL(a.signal),signal:a.signal});return aL(a.signal),t},()=>a.abort(ZI));return i?.autoJoin&&t.push(o.catch(nL)),{result:cL(e)(o),cancel(){a.abort(XI)}}}},mL=(e,t)=>{let n=async(n,r)=>{aL(t);let i=()=>{},a=[new Promise((t,r)=>{let a=e({predicate:n,effect:(e,n)=>{n.unsubscribe(),t([e,n.getState(),n.getOriginalState()])}});i=()=>{a(),r()}})];r!=null&&a.push(new Promise(e=>setTimeout(e,r,null)));try{let e=await oL(t,Promise.race(a));return aL(t),e}finally{i()}};return((e,t)=>rL(n(e,t)))},hL=e=>{let{type:t,actionCreator:n,matcher:r,predicate:i,effect:a}=e;if(t)i=_I(t).match;else if(n)t=n.type,i=n.match;else if(r)i=r;else if(!i)throw Error(EL(21));return tL(a,`options.listener`),{predicate:i,type:t,effect:a}},gL=uL(e=>{let{type:t,predicate:n,effect:r}=hL(e);return{id:PI(),effect:r,type:t,predicate:n,pending:new Set,unsubscribe:()=>{throw Error(EL(22))}}},{withTypes:()=>gL}),_L=(e,t)=>{let{type:n,effect:r,predicate:i}=hL(t);return Array.from(e.values()).find(e=>(typeof n==`string`?e.type===n:e.predicate===i)&&e.effect===r)},vL=e=>{e.pending.forEach(e=>{e.abort(QI)})},yL=(e,t)=>()=>{for(let e of t.keys())vL(e);e.clear()},bL=(e,t,n)=>{try{e(t,n)}catch(e){setTimeout(()=>{throw e},0)}},xL=uL(_I(`${fL}/add`),{withTypes:()=>xL}),SL=_I(`${fL}/removeAll`),CL=uL(_I(`${fL}/remove`),{withTypes:()=>CL}),wL=(...e)=>{console.error(`${fL}/error`,...e)},TL=(e={})=>{let t=new Map,n=new Map,r=e=>{let t=n.get(e)??0;n.set(e,t+1)},i=e=>{let t=n.get(e)??1;t===1?n.delete(e):n.set(e,t-1)},{extra:a,onError:o=wL}=e;tL(o,`onError`);let s=e=>(e.unsubscribe=()=>t.delete(e.id),t.set(e.id,e),t=>{e.unsubscribe(),t?.cancelActive&&vL(e)}),c=(e=>{let n=_L(t,e)??gL(e);return s(n)});uL(c,{withTypes:()=>c});let l=e=>{let n=_L(t,e);return n&&(n.unsubscribe(),e.cancelActive&&vL(n)),!!n};uL(l,{withTypes:()=>l});let u=async(e,n,s,l)=>{let u=new AbortController,d=mL(c,u.signal),f=[];try{e.pending.add(u),r(e),await Promise.resolve(e.effect(n,uL({},s,{getOriginalState:l,condition:(e,t)=>d(e,t).then(Boolean),take:d,delay:lL(u.signal),pause:cL(u.signal),extra:a,signal:u.signal,fork:pL(u.signal,f),unsubscribe:e.unsubscribe,subscribe:()=>{t.set(e.id,e)},cancelActiveListeners:()=>{e.pending.forEach((e,t,n)=>{e!==u&&(e.abort(QI),n.delete(e))})},cancel:()=>{u.abort(QI),e.pending.delete(u)},throwIfCancelled:()=>{aL(u.signal)}})))}catch(e){e instanceof eL||bL(o,e,{raisedBy:`effect`})}finally{await Promise.all(f),u.abort($I),i(e),e.pending.delete(u)}},d=yL(t,n);return{middleware:e=>n=>r=>{if(!WP(r))return n(r);if(xL.match(r))return c(r.payload);if(SL.match(r)){d();return}if(CL.match(r))return l(r.payload);let i=e.getState(),a=()=>{if(i===dL)throw Error(EL(23));return i},s;try{if(s=n(r),t.size>0){let n=e.getState(),s=Array.from(t.values());for(let t of s){let s=!1;try{s=t.predicate(r,n,i)}catch(e){s=!1,bL(o,e,{raisedBy:`predicate`})}s&&u(t,r,e,a)}}}finally{i=dL}return s},startListening:c,stopListening:l,clearListeners:d}};function EL(e){return`Minified Redux Toolkit error #${e}; visit https://redux-toolkit.js.org/Errors?code=${e} for the full message or use the non-minified dev environment for full errors. `}var DL=zI({name:`chartLayout`,initialState:{layoutType:`horizontal`,width:0,height:0,margin:{top:5,right:5,bottom:5,left:5},scale:1},reducers:{setLayout(e,t){e.layoutType=t.payload},setChartSize(e,t){e.width=t.payload.width,e.height=t.payload.height},setMargin(e,t){e.margin.top=t.payload.top??0,e.margin.right=t.payload.right??0,e.margin.bottom=t.payload.bottom??0,e.margin.left=t.payload.left??0},setScale(e,t){e.scale=t.payload}}}),OL=DL.actions,kL=OL.setMargin,AL=OL.setLayout,jL=OL.setChartSize,ML=OL.setScale,NL=DL.reducer;function PL(e,t,n){return Array.isArray(e)&&e&&t+n!==0?e.slice(t,n+1):e}function Q(e){return Number.isFinite(e)}function FL(e){return typeof e==`number`&&e>0&&Number.isFinite(e)}function IL(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function LL(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?IL(Object(n),!0).forEach(function(t){RL(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):IL(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function RL(e,t,n){return(t=zL(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function zL(e){var t=BL(e,`string`);return typeof t==`symbol`?t:t+``}function BL(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function VL(e,t,n){return Dj(e)||Dj(t)?n:Sj(t)?gj(e,t,n):typeof t==`function`?t(e):n}var HL=(e,t,n)=>{if(t&&n){var r=n.width,i=n.height,a=t.align,o=t.verticalAlign,s=t.layout,c=t.position,l=t.offset,u=l===void 0?0:l;if(c!=null){if(Ere(c)){if(c===`top`&&J(e.top))return LL(LL({},e),{},{top:e.top+(i||0)+u});if(c===`bottom`&&J(e.bottom))return LL(LL({},e),{},{bottom:e.bottom+(i||0)+u});if(c===`left`&&J(e.left))return LL(LL({},e),{},{left:e.left+(r||0)+u});if(c===`right`&&J(e.right))return LL(LL({},e),{},{right:e.right+(r||0)+u})}return e}if((s===`vertical`||s===`horizontal`&&o===`middle`)&&a!==`center`&&J(e[a]))return LL(LL({},e),{},{[a]:e[a]+(r||0)});if((s===`horizontal`||s===`vertical`&&a===`center`)&&o!==`middle`&&J(e[o]))return LL(LL({},e),{},{[o]:e[o]+(i||0)})}return e},UL=(e,t)=>e===`horizontal`&&t===`xAxis`||e===`vertical`&&t===`yAxis`||e===`centric`&&t===`angleAxis`||e===`radial`&&t===`radiusAxis`,WL=(e,t,n,r)=>{if(r)return e.map(e=>e.coordinate);var i,a,o=e.map(e=>(e.coordinate===t&&(i=!0),e.coordinate===n&&(a=!0),e.coordinate));return i||o.push(t),a||o.push(n),o},GL=(e,t,n)=>{if(!e)return null;var r=e.duplicateDomain,i=e.type,a=e.range,o=e.scale,s=e.realScaleType,c=e.isCategorical,l=e.categoricalDomain,u=e.tickCount,d=e.ticks,f=e.niceTicks,p=e.axisType;if(!o)return null;var m=s===`scaleBand`&&o.bandwidth?o.bandwidth()/2:2,h=(t||n)&&i===`category`&&o.bandwidth?o.bandwidth()/m:0;return h=p===`angleAxis`&&a&&a.length>=2?yj(a[0]-a[1])*2*h:h,t&&(d||f)?(d||f||[]).map((e,t)=>{var n=r?r.indexOf(e):e,i=o.map(n);return Q(i)?{coordinate:i+h,value:e,offset:h,index:t}:null}).filter(kj):c&&l?l.map((e,t)=>{var n=o.map(e);return Q(n)?{coordinate:n+h,value:e,index:t,offset:h}:null}).filter(kj):o.ticks&&!n&&u!=null?o.ticks(u).map((e,t)=>{var n=o.map(e);return Q(n)?{coordinate:n+h,value:e,index:t,offset:h}:null}).filter(kj):o.domain().map((e,t)=>{var n=o.map(e);return Q(n)?{coordinate:n+h,value:r?r[e]:e,index:t,offset:h}:null}).filter(kj)},KL=(e,t)=>{if(!t||t.length!==2||!J(t[0])||!J(t[1]))return e;var n=Math.min(t[0],t[1]),r=Math.max(t[0],t[1]),i=[e[0],e[1]];return(!J(e[0])||e[0]<n)&&(i[0]=n),(!J(e[1])||e[1]>r)&&(i[1]=r),i[0]>r&&(i[0]=r),i[1]<n&&(i[1]=n),i},qL={sign:e=>{var t=e.length;if(!(t<=0)){var n=e[0]?.length;if(!(n==null||n<=0))for(var r=0;r<n;++r)for(var i=0,a=0,o=0;o<t;++o){var s=e[o]?.[r];if(s!=null){var c=s[1],l=s[0],u=bj(c)?l:c;u>=0?(s[0]=i,i+=u,s[1]=i):(s[0]=a,a+=u,s[1]=a)}}}},expand:TM,none:bM,silhouette:EM,wiggle:DM,positive:e=>{var t=e.length;if(!(t<=0)){var n=e[0]?.length;if(!(n==null||n<=0))for(var r=0;r<n;++r)for(var i=0,a=0;a<t;++a){var o=e[a]?.[r];if(o!=null){var s=bj(o[1])?o[0]:o[1];s>=0?(o[0]=i,i+=s,o[1]=i):(o[0]=0,o[1]=0)}}}}},JL=(e,t,n)=>{var r=qL[n]??bM,i=wM().keys(t).value((e,t)=>Number(VL(e,t,0))).order(xM).offset(r)(e);return i.forEach((n,r)=>{n.forEach((n,i)=>{var a=VL(e[i],t[r],0);Array.isArray(a)&&a.length===2&&J(a[0])&&J(a[1])&&(n[0]=a[0],n[1]=a[1])})}),i};function YL(e){return e==null?void 0:String(e)}var XL=e=>{var t=e.axis,n=e.ticks,r=e.offset,i=e.bandSize,a=e.entry,o=e.index;if(t.type===`category`)return n[o]?n[o].coordinate+r:null;var s=VL(a,t.dataKey,t.scale.domain()[o]);if(Dj(s))return null;var c=t.scale.map(s);return J(c)?c-i/2+r:null},ZL=e=>{var t=e.numericAxis,n=t.scale.domain();if(t.type===`number`){var r=Math.min(n[0],n[1]),i=Math.max(n[0],n[1]);return r<=0&&i>=0?0:i<0?i:r}return n[0]},QL=e=>{var t=e.flat(2).filter(J);return[Math.min(...t),Math.max(...t)]},$L=e=>[e[0]===1/0?0:e[0],e[1]===-1/0?0:e[1]],eR=(e,t,n)=>{if(e!=null&&Object.keys(e).length!==0)return $L(Object.keys(e).reduce((r,i)=>{var a=e[i];if(!a)return r;var o=a.stackedData.reduce((e,r)=>{var i=QL(PL(r,t,n));return!Q(i[0])||!Q(i[1])?e:[Math.min(e[0],i[0]),Math.max(e[1],i[1])]},[1/0,-1/0]);return[Math.min(o[0],r[0]),Math.max(o[1],r[1])]},[1/0,-1/0]))},tR=/^dataMin[\s]*-[\s]*([0-9]+([.]{1}[0-9]+){0,1})$/,nR=/^dataMax[\s]*\+[\s]*([0-9]+([.]{1}[0-9]+){0,1})$/,rR=(e,t,n)=>{if(e&&e.scale&&e.scale.bandwidth){var r=e.scale.bandwidth();if(!n||r>0)return r}if(e&&t&&t.length>=2){for(var i=xP(t,e=>e.coordinate),a=[],o=0,s=1,c=i.length;s<c;s++){var l=(i[s]?.coordinate||0)-(i[s-1]?.coordinate||0);a.push(l),o=Math.max(l,o)}var u=o*1e-4,d=1/0;for(var f of a)f>u&&(d=Math.min(f,d));return d===1/0?0:d}return n?void 0:0};function iR(e){var t=e.tooltipEntrySettings,n=e.dataKey,r=e.payload,i=e.value,a=e.name;return LL(LL({},t),{},{dataKey:n,payload:r,value:i,name:a})}function aR(e,t){if(e!=null)return String(e);if(typeof t==`string`)return t}var oR=(e,t)=>{if(t===`horizontal`)return e.relativeX;if(t===`vertical`)return e.relativeY},sR=(e,t)=>t===`centric`?e.angle:e.radius,cR=e=>e.layout.width,lR=e=>e.layout.height,uR=e=>e.layout.scale,dR=e=>e.layout.margin,fR=X(e=>e.cartesianAxis.xAxis,e=>Object.values(e)),pR=X(e=>e.cartesianAxis.yAxis,e=>Object.values(e)),mR=`data-recharts-item-index`;function hR(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function gR(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?hR(Object(n),!0).forEach(function(t){_R(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):hR(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function _R(e,t,n){return(t=vR(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function vR(e){var t=yR(e,`string`);return typeof t==`symbol`?t:t+``}function yR(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}var bR=e=>e.brush.height;function xR(e){return pR(e).reduce((e,t)=>t.orientation===`left`&&!t.mirror&&!t.hide?e+(typeof t.width==`number`?t.width:60):e,0)}function SR(e){return pR(e).reduce((e,t)=>t.orientation===`right`&&!t.mirror&&!t.hide?e+(typeof t.width==`number`?t.width:60):e,0)}function CR(e){return fR(e).reduce((e,t)=>t.orientation===`top`&&!t.mirror&&!t.hide?e+(typeof t.height==`number`?t.height:30):e,0)}function wR(e){return fR(e).reduce((e,t)=>t.orientation===`bottom`&&!t.mirror&&!t.hide?e+(typeof t.height==`number`?t.height:30):e,0)}var TR=X([cR,lR,dR,bR,xR,SR,CR,wR,SP,CP],(e,t,n,r,i,a,o,s,c,l)=>{var u={left:(n.left||0)+i,right:(n.right||0)+a},d=gR(gR({},{top:(n.top||0)+o,bottom:(n.bottom||0)+s}),u),f=d.bottom;d.bottom+=r,d=HL(d,c,l);var p=e-d.left-d.right,m=t-d.top-d.bottom;return gR(gR({brushBottom:f},d),{},{width:Math.max(p,0),height:Math.max(m,0)})}),ER=X(TR,e=>({x:e.left,y:e.top,width:e.width,height:e.height})),DR=X(cR,lR,(e,t)=>({x:0,y:0,width:e,height:t})),OR=(0,o.createContext)(null),kR=()=>(0,o.useContext)(OR)!=null,AR=e=>e.brush,jR=X([AR,TR,dR],(e,t,n)=>({height:e.height,x:J(e.x)?e.x:t.left,y:J(e.y)?e.y:t.top+t.height+t.brushBottom-(n?.bottom||0),width:J(e.width)?e.width:t.width}));function MR(e,t,{signal:n,edges:r}={}){let i,a=null,o=r!=null&&r.includes(`leading`),s=r==null||r.includes(`trailing`),c=()=>{a!==null&&(e.apply(i,a),i=void 0,a=null)},l=()=>{s&&c(),p()},u=null,d=()=>{u!=null&&clearTimeout(u),u=setTimeout(()=>{u=null,l()},t)},f=()=>{u!==null&&(clearTimeout(u),u=null)},p=()=>{f(),i=void 0,a=null},m=()=>{c()},h=function(...e){if(n?.aborted)return;i=this,a=e;let t=u==null;d(),o&&t&&c()};return h.schedule=d,h.cancel=p,h.flush=m,n?.addEventListener(`abort`,p,{once:!0}),h}function NR(e,t=0,n={}){typeof n!=`object`&&(n={});let{leading:r=!1,trailing:i=!0,maxWait:a}=n,o=[,,];r&&(o[0]=`leading`),i&&(o[1]=`trailing`);let s,c=null,l=MR(function(...t){s=e.apply(this,t),c=null},t,{edges:o}),u=function(...t){return a!=null&&(c===null&&(c=Date.now()),Date.now()-c>=a)?((r||i)&&(s=e.apply(this,t)),c=Date.now(),l.cancel(),l.schedule(),s):(l.apply(this,t),s)};return u.cancel=l.cancel,u.flush=()=>(l.flush(),s),u}function PR(e,t=0,n={}){let{leading:r=!0,trailing:i=!0}=n;return NR(e,t,{leading:r,maxWait:t,trailing:i})}var FR=function(e,t){var n=[...arguments].slice(2);if(typeof console<`u`&&console.warn&&(t===void 0&&console.warn(`LogUtils requires an error message argument`),!e)){if(t===void 0)console.warn(`Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.`);else{var r=0;console.warn(t.replace(/%s/g,()=>n[r++]))}}},IR={width:`100%`,height:`100%`,debounce:0,minWidth:0,initialDimension:{width:-1,height:-1}},LR=(e,t,n)=>{var r=n.width,i=r===void 0?IR.width:r,a=n.height,o=a===void 0?IR.height:a,s=n.aspect,c=n.maxHeight,l=xj(i)?e:Number(i),u=xj(o)?t:Number(o);return s&&s>0&&(l?u=l/s:u&&(l=u*s),c&&u!=null&&u>c&&(u=c)),{calculatedWidth:l,calculatedHeight:u}},RR={width:0,height:0,overflow:`visible`},zR={width:0,overflowX:`visible`},BR={height:0,overflowY:`visible`},VR={},HR=e=>{var t=e.width,n=e.height,r=xj(t),i=xj(n);return r&&i?RR:r?zR:i?BR:VR};function UR(e){var t=e.width,n=e.height,r=e.aspect,i=t,a=n;return i===void 0&&a===void 0?(i=IR.width,a=IR.height):i===void 0?i=r&&r>0?void 0:IR.width:a===void 0&&(a=r&&r>0?void 0:IR.height),{width:i,height:a}}var WR=[`aspect`,`initialDimension`,`width`,`height`,`minWidth`,`minHeight`,`maxHeight`,`children`,`debounce`,`id`,`className`,`onResize`,`style`];function GR(){return GR=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},GR.apply(null,arguments)}function KR(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function qR(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?KR(Object(n),!0).forEach(function(t){JR(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):KR(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function JR(e,t,n){return(t=YR(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function YR(e){var t=XR(e,`string`);return typeof t==`symbol`?t:t+``}function XR(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function ZR(e,t){return nz(e)||tz(e,t)||$R(e,t)||QR()}function QR(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
14
14
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function $R(e,t){if(e){if(typeof e==`string`)return ez(e,t);var n={}.toString.call(e).slice(8,-1);return n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`?Array.from(e):n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?ez(e,t):void 0}}function ez(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function tz(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r,i,a,o,s=[],c=!0,l=!1;try{if(a=(n=n.call(e)).next,t===0){if(Object(n)!==n)return;c=!1}else for(;!(c=(r=a.call(n)).done)&&(s.push(r.value),s.length!==t);c=!0);}catch(e){l=!0,i=e}finally{try{if(!c&&n.return!=null&&(o=n.return(),Object(o)!==o))return}finally{if(l)throw i}}return s}}function nz(e){if(Array.isArray(e))return e}function rz(e,t){if(e==null)return{};var n,r,i=iz(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function iz(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}var az=(0,o.createContext)(IR.initialDimension);function oz(e){return FL(e.width)&&FL(e.height)}function sz(e){var t=e.children,n=e.width,r=e.height,i=(0,o.useMemo)(()=>({width:n,height:r}),[n,r]);return oz(i)?o.createElement(az.Provider,{value:i},t):null}var cz=()=>(0,o.useContext)(az),lz=(0,o.forwardRef)((e,t)=>{var n=e.aspect,r=e.initialDimension,i=r===void 0?IR.initialDimension:r,a=e.width,s=e.height,c=e.minWidth,l=c===void 0?IR.minWidth:c,u=e.minHeight,d=e.maxHeight,f=e.children,p=e.debounce,m=p===void 0?IR.debounce:p,h=e.id,g=e.className,_=e.onResize,v=e.style,y=v===void 0?{}:v,b=rz(e,WR),x=(0,o.useRef)(null),S=(0,o.useRef)();S.current=_,(0,o.useImperativeHandle)(t,()=>x.current);var C=ZR((0,o.useState)({containerWidth:i.width,containerHeight:i.height}),2),w=C[0],T=C[1],E=(0,o.useCallback)((e,t)=>{T(n=>{var r=Math.round(e),i=Math.round(t);return n.containerWidth===r&&n.containerHeight===i?n:{containerWidth:r,containerHeight:i}})},[]);(0,o.useEffect)(()=>{if(x.current==null||typeof ResizeObserver>`u`)return Aj;var e=e=>{var t,n=e[0];if(n!=null){var r=n.contentRect,i=r.width,a=r.height;E(i,a),(t=S.current)==null||t.call(S,i,a)}};m>0&&(e=PR(e,m,{trailing:!0,leading:!1}));var t=new ResizeObserver(e),n=x.current.getBoundingClientRect(),r=n.width,i=n.height;return E(r,i),t.observe(x.current),()=>{t.disconnect()}},[E,m]);var D=w.containerWidth,O=w.containerHeight;FR(!n||n>0,`The aspect(%s) must be greater than zero.`,n);var k=LR(D,O,{width:a,height:s,aspect:n,maxHeight:d}),A=k.calculatedWidth,j=k.calculatedHeight;return FR(D<0||O<0||A!=null&&A>0||j!=null&&j>0,`The width(%s) and height(%s) of chart should be greater than 0,
15
15
  please check the style of container, or the props width(%s) and height(%s),
@@ -63,4 +63,4 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
63
63
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function qre(e,t){if(e){if(typeof e==`string`)return O8(e,t);var n={}.toString.call(e).slice(8,-1);return n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`?Array.from(e):n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?O8(e,t):void 0}}function O8(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function Jre(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r,i,a,o,s=[],c=!0,l=!1;try{if(a=(n=n.call(e)).next,t===0){if(Object(n)!==n)return;c=!1}else for(;!(c=(r=a.call(n)).done)&&(s.push(r.value),s.length!==t);c=!0);}catch(e){l=!0,i=e}finally{try{if(!c&&n.return!=null&&(o=n.return(),Object(o)!==o))return}finally{if(l)throw i}}return s}}function Yre(e){if(Array.isArray(e))return e}function Xre(e,t){if(e==null)return{};var n,r,i=Zre(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function Zre(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function k8(){return k8=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},k8.apply(null,arguments)}function A8(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function j8(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?A8(Object(n),!0).forEach(function(t){Qre(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):A8(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function Qre(e,t,n){return(t=$re(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function $re(e){var t=eie(e,`string`);return typeof t==`symbol`?t:t+``}function eie(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}var M8={x:0,y:0,width:0,height:0,viewBox:{x:0,y:0,width:0,height:0},orientation:`bottom`,ticks:[],stroke:`#666`,tickLine:!0,axisLine:!0,tick:!0,mirror:!1,minTickGap:5,tickSize:6,tickMargin:2,interval:`preserveEnd`,zIndex:WU.axis};function tie(e){var t=e.x,n=e.y,r=e.width,i=e.height,a=e.orientation,s=e.mirror,c=e.axisLine,l=e.otherSvgProps;if(!c)return null;var u=j8(j8(j8({},l),rj(c)),{},{fill:`none`});if(a===`top`||a===`bottom`){var d=+(a===`top`&&!s||a===`bottom`&&s);u=j8(j8({},u),{},{x1:t,y1:n+d*i,x2:t+r,y2:n+d*i})}else{var f=+(a===`left`&&!s||a===`right`&&s);u=j8(j8({},u),{},{x1:t+f*r,y1:n,x2:t+f*r,y2:n+i})}return o.createElement(`line`,k8({},u,{className:$A(`recharts-cartesian-axis-line`,gj(c,`className`))}))}function nie(e,t,n,r,i,a,o,s,c){var l,u,d,f,p,m,h=s?-1:1,g=e.tickSize||o,_=J(e.tickCoord)?e.tickCoord:e.coordinate;switch(a){case`top`:l=u=e.coordinate,f=n+ +!s*i,d=f-h*g,m=d-h*c,p=_;break;case`left`:d=f=e.coordinate,u=t+ +!s*r,l=u-h*g,p=l-h*c,m=_;break;case`right`:d=f=e.coordinate,u=t+ +s*r,l=u+h*g,p=l+h*c,m=_;break;default:l=u=e.coordinate,f=n+ +s*i,d=f+h*g,m=d+h*c,p=_}return{line:{x1:l,y1:d,x2:u,y2:f},tick:{x:p,y:m}}}function rie(e,t){switch(e){case`left`:return t?`start`:`end`;case`right`:return t?`end`:`start`;default:return`middle`}}function iie(e,t){switch(e){case`left`:case`right`:return`middle`;case`top`:return t?`start`:`end`;default:return t?`end`:`start`}}function aie(e){var t=e.option,n=e.tickProps,r=e.value,i,a=$A(n.className,`recharts-cartesian-axis-tick-value`);if(o.isValidElement(t))i=o.cloneElement(t,j8(j8({},n),{},{className:a}));else if(typeof t==`function`)i=t(j8(j8({},n),{},{className:a}));else{var s=`recharts-cartesian-axis-tick-value`;typeof t!=`boolean`&&(s=$A(s,n3(t))),i=o.createElement(p4,k8({},n,{className:s}),r)}return i}function oie(e){var t=e.ticks,n=e.axisType,r=e.axisId,i=XN(),a=(0,o.useRef)(null);return(0,o.useEffect)(()=>{if(r!=null&&n!=null){var e=t.map(e=>({value:e.value,coordinate:e.coordinate,offset:e.offset,index:e.index})),o=a.current;o!=null&&o.axisId===r&&o.axisType===n&&g8(o.ticks,e)||(a.current={ticks:e,axisId:r,axisType:n},i(Hre({ticks:e,axisId:r,axisType:n})))}},[i,t,r,n]),(0,o.useEffect)(()=>r==null||n==null?Aj:()=>{i(Ure({axisId:r,axisType:n}))},[i,r,n]),null}var sie=(0,o.forwardRef)((e,t)=>{var n=e.ticks,r=n===void 0?[]:n,i=e.tick,a=e.tickLine,s=e.stroke,c=e.tickFormatter,l=e.unit,u=e.padding,d=e.tickTextProps,f=e.orientation,p=e.mirror,m=e.x,h=e.y,g=e.width,_=e.height,v=e.tickSize,y=e.tickMargin,b=e.fontSize,x=e.letterSpacing,S=e.getTicksConfig,C=e.events,w=e.axisType,T=e.axisId,E=w8(j8(j8({},S),{},{ticks:r}),b,x),D=rj(S),O=ij(i),k=n4(D.textAnchor)?D.textAnchor:rie(f,p),A=iie(f,p),j={};typeof a==`object`&&(j=a);var M=j8(j8({},D),{},{fill:`none`},j),N=E.map(e=>j8({entry:e},nie(e,m,h,g,_,f,v,p,y))),ee=N.map(e=>{var t=e.entry,n=e.line;return o.createElement(lj,{className:`recharts-cartesian-axis-tick`,key:`tick-${t.value}-${t.coordinate}-${t.tickCoord}`},a&&o.createElement(`line`,k8({},M,n,{className:$A(`recharts-cartesian-axis-tick-line`,gj(a,`className`))})))}),te=N.map((e,t)=>{var n=e.entry,r=e.tick,a=j8(j8({},j8(j8(j8(j8({verticalAnchor:A},D),{},{textAnchor:k,stroke:`none`,fill:s},r),{},{index:t,payload:n,visibleTicksCount:E.length,tickFormatter:c,padding:u},d),{},{angle:d?.angle??D.angle??0})),O);return o.createElement(lj,k8({className:`recharts-cartesian-axis-tick-label`,key:`tick-label-${n.value}-${n.coordinate}-${n.tickCoord}`},jM(C,n,t)),i&&o.createElement(aie,{option:i,tickProps:a,value:`${typeof c==`function`?c(n.value,t):n.value}${l||``}`}))});return o.createElement(`g`,{className:`recharts-cartesian-axis-ticks recharts-${w}-ticks`},o.createElement(oie,{ticks:E,axisId:T,axisType:w}),te.length>0&&o.createElement(e0,{zIndex:WU.label},o.createElement(`g`,{className:`recharts-cartesian-axis-tick-labels recharts-${w}-tick-labels`,ref:t},te)),ee.length>0&&o.createElement(`g`,{className:`recharts-cartesian-axis-tick-lines recharts-${w}-tick-lines`},ee))}),cie=(0,o.forwardRef)((e,t)=>{var n=e.axisLine,r=e.width,i=e.height,a=e.className,s=e.hide,c=e.ticks,l=e.axisType,u=e.axisId,d=Xre(e,Gre),f=D8((0,o.useState)(``),2),p=f[0],m=f[1],h=D8((0,o.useState)(``),2),g=h[0],_=h[1],v=(0,o.useRef)(null);(0,o.useImperativeHandle)(t,()=>({getCalculatedWidth:()=>Bre({ticks:v.current,label:e.labelRef?.current,labelGapWithTick:5,tickSize:e.tickSize,tickMargin:e.tickMargin}),getCalculatedHeight:()=>Vre({ticks:v.current,label:e.labelRef?.current,labelGapWithTick:5,tickSize:e.tickSize,tickMargin:e.tickMargin})}));var y=(0,o.useCallback)(e=>{if(e){var t=e.getElementsByClassName(`recharts-cartesian-axis-tick-value`);v.current=t;var n=t[0];if(n){var r=window.getComputedStyle(n),i=r.fontSize,a=r.letterSpacing;(i!==p||a!==g)&&(m(i),_(a))}}},[p,g]);return s||r!=null&&r<=0||i!=null&&i<=0?null:o.createElement(e0,{zIndex:e.zIndex},o.createElement(lj,{className:$A(`recharts-cartesian-axis`,a)},o.createElement(tie,{x:e.x,y:e.y,width:r,height:i,orientation:e.orientation,mirror:e.mirror,axisLine:n,otherSvgProps:rj(e)}),o.createElement(sie,{ref:y,axisType:l,events:d,fontSize:p,getTicksConfig:e,height:e.height,letterSpacing:g,mirror:e.mirror,orientation:e.orientation,padding:e.padding,stroke:e.stroke,tick:e.tick,tickFormatter:e.tickFormatter,tickLine:e.tickLine,tickMargin:e.tickMargin,tickSize:e.tickSize,tickTextProps:e.tickTextProps,ticks:c,unit:e.unit,width:e.width,x:e.x,y:e.y,axisId:u}),o.createElement(T4,{x:e.x,y:e.y,width:e.width,height:e.height,lowerWidth:e.width,upperWidth:e.width},o.createElement(z4,{label:e.label,labelRef:e.labelRef}),e.children)))}),N8=o.forwardRef((e,t)=>{var n=LM(e,M8);return o.createElement(cie,k8({},n,{ref:t}))});N8.displayName=`CartesianAxis`;var P8=(0,o.createContext)({grid:{stroke:`#ccc`,fill:`none`}});P8.Provider;var lie=()=>(0,o.useContext)(P8),uie=[`x1`,`y1`,`x2`,`y2`,`key`],die=[`offset`],fie=[`xAxisId`,`yAxisId`],pie=[`xAxisId`,`yAxisId`];function F8(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function I8(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?F8(Object(n),!0).forEach(function(t){mie(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):F8(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function mie(e,t,n){return(t=hie(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function hie(e){var t=gie(e,`string`);return typeof t==`symbol`?t:t+``}function gie(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function L8(){return L8=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},L8.apply(null,arguments)}function R8(e,t){if(e==null)return{};var n,r,i=_ie(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function _ie(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}var vie=e=>{var t=e.fill;if(!t||t===`none`)return null;var n=e.fillOpacity,r=e.x,i=e.y,a=e.width,s=e.height,c=e.ry;return o.createElement(`rect`,{x:r,y:i,ry:c,width:a,height:s,stroke:`none`,fill:t,fillOpacity:n,className:`recharts-cartesian-grid-bg`})};function z8(e){var t=e.option,n=e.lineItemProps,r;if(o.isValidElement(t))r=o.cloneElement(t,n);else if(typeof t==`function`)r=t(n);else{var i=n.x1,a=n.y1,s=n.x2,c=n.y2,l=n.key,u=rj(R8(n,uie))??{};u.offset;var d=R8(u,die),f=Array.isArray(d.strokeDasharray)?d.strokeDasharray.join(`,`):d.strokeDasharray;r=o.createElement(`line`,L8({},d,{strokeDasharray:f,x1:i,y1:a,x2:s,y2:c,fill:`none`,key:l}))}return r}function yie(e){var t=e.x,n=e.width,r=e.horizontal,i=r===void 0||r,a=e.horizontalPoints;if(!i||!a||!a.length)return null;e.xAxisId,e.yAxisId;var s=R8(e,fie),c=a.map((e,r)=>{var a=I8(I8({},s),{},{x1:t,y1:e,x2:t+n,y2:e,key:`line-${r}`,index:r});return o.createElement(z8,{key:`line-${r}`,option:i,lineItemProps:a})});return o.createElement(`g`,{className:`recharts-cartesian-grid-horizontal`},c)}function bie(e){var t=e.y,n=e.height,r=e.vertical,i=r===void 0||r,a=e.verticalPoints;if(!i||!a||!a.length)return null;e.xAxisId,e.yAxisId;var s=R8(e,pie),c=a.map((e,r)=>{var a=I8(I8({},s),{},{x1:e,y1:t,x2:e,y2:t+n,key:`line-${r}`,index:r});return o.createElement(z8,{option:i,lineItemProps:a,key:`line-${r}`})});return o.createElement(`g`,{className:`recharts-cartesian-grid-vertical`},c)}function xie(e){var t=e.horizontalFill,n=e.fillOpacity,r=e.x,i=e.y,a=e.width,s=e.height,c=e.horizontalPoints,l=e.horizontal;if(!(l===void 0||l)||!t||!t.length||c==null)return null;var u=c.map(e=>Math.round(e+i-i)).sort((e,t)=>e-t);i!==u[0]&&u.unshift(0);var d=u.map((e,c)=>{var l=u[c+1],d=l==null?i+s-e:l-e;if(d<=0)return null;var f=c%t.length;return o.createElement(`rect`,{key:`react-${c}`,y:e,x:r,height:d,width:a,stroke:`none`,fill:t[f],fillOpacity:n,className:`recharts-cartesian-grid-bg`})});return o.createElement(`g`,{className:`recharts-cartesian-gridstripes-horizontal`},d)}function Sie(e){var t=e.vertical,n=t===void 0||t,r=e.verticalFill,i=e.fillOpacity,a=e.x,s=e.y,c=e.width,l=e.height,u=e.verticalPoints;if(!n||!r||!r.length)return null;var d=u.map(e=>Math.round(e+a-a)).sort((e,t)=>e-t);a!==d[0]&&d.unshift(0);var f=d.map((e,t)=>{var n=d[t+1],u=n==null?a+c-e:n-e;if(u<=0)return null;var f=t%r.length;return o.createElement(`rect`,{key:`react-${t}`,x:e,y:s,width:u,height:l,stroke:`none`,fill:r[f],fillOpacity:i,className:`recharts-cartesian-grid-bg`})});return o.createElement(`g`,{className:`recharts-cartesian-gridstripes-vertical`},f)}var Cie=(e,t)=>{var n=e.xAxis,r=e.width,i=e.height,a=e.offset;return WL(w8(I8(I8(I8({},M8),n),{},{ticks:GL(n,!0),viewBox:{x:0,y:0,width:r,height:i}})),a.left,a.left+a.width,t)},wie=(e,t)=>{var n=e.yAxis,r=e.width,i=e.height,a=e.offset;return WL(w8(I8(I8(I8({},M8),n),{},{ticks:GL(n,!0),viewBox:{x:0,y:0,width:r,height:i}})),a.top,a.top+a.height,t)},Tie={horizontal:!0,vertical:!0,horizontalPoints:[],verticalPoints:[],verticalFill:[],horizontalFill:[],xAxisId:0,yAxisId:0,syncWithTicks:!1,zIndex:WU.grid};function B8(e){var t=mz(),n=hz(),r=pz(),i=I8(I8({},LM(e,Tie)),{},{x:J(e.x)?e.x:r.left,y:J(e.y)?e.y:r.top,width:J(e.width)?e.width:r.width,height:J(e.height)?e.height:r.height}),a=i.xAxisId,s=i.yAxisId,c=i.x,l=i.y,u=i.width,d=i.height,f=i.syncWithTicks,p=i.horizontalValues,m=i.verticalValues,h=kR(),g=Y(e=>TQ(e,`xAxis`,a,h)),_=Y(e=>TQ(e,`yAxis`,s,h)),v=lie(),y={stroke:i.stroke??v.grid.stroke,strokeWidth:i.strokeWidth??v.grid.strokeWidth,strokeOpacity:i.strokeOpacity??v.grid.strokeOpacity,strokeDasharray:i.strokeDasharray??v.grid.strokeDasharray};if(!FL(u)||!FL(d)||!J(c)||!J(l))return null;var b=i.verticalCoordinatesGenerator||Cie,x=i.horizontalCoordinatesGenerator||wie,S=i.horizontalPoints,C=i.verticalPoints;if((!S||!S.length)&&typeof x==`function`){var w=p&&p.length,T=x({yAxis:_?I8(I8({},_),{},{ticks:w?p:_.ticks}):void 0,width:t??u,height:n??d,offset:r},w?!0:f);FR(Array.isArray(T),`horizontalCoordinatesGenerator should return Array but instead it returned [${typeof T}]`),Array.isArray(T)&&(S=T)}if((!C||!C.length)&&typeof b==`function`){var E=m&&m.length,D=b({xAxis:g?I8(I8({},g),{},{ticks:E?m:g.ticks}):void 0,width:t??u,height:n??d,offset:r},E?!0:f);FR(Array.isArray(D),`verticalCoordinatesGenerator should return Array but instead it returned [${typeof D}]`),Array.isArray(D)&&(C=D)}return o.createElement(e0,{zIndex:i.zIndex},o.createElement(`g`,{className:`recharts-cartesian-grid`},o.createElement(vie,{fill:i.fill??v.grid.fill,fillOpacity:i.fillOpacity??v.grid.fillOpacity,x:i.x,y:i.y,width:i.width,height:i.height,ry:i.ry}),o.createElement(xie,L8({},i,{horizontalPoints:S})),o.createElement(Sie,L8({},i,{verticalPoints:C})),o.createElement(yie,L8({},i,y,{offset:r,horizontalPoints:S,xAxis:g,yAxis:_})),o.createElement(bie,L8({},i,y,{offset:r,verticalPoints:C,xAxis:g,yAxis:_}))))}B8.displayName=`CartesianGrid`;var V8=zI({name:`errorBars`,initialState:{},reducers:{addErrorBar:(e,t)=>{var n=t.payload,r=n.itemId,i=n.errorBar;e[r]||(e[r]=[]),e[r].push(i)},replaceErrorBar:(e,t)=>{var n=t.payload,r=n.itemId,i=n.prev,a=n.next;e[r]&&(e[r]=e[r].map(e=>e.dataKey===i.dataKey&&e.direction===i.direction?a:e))},removeErrorBar:(e,t)=>{var n=t.payload,r=n.itemId,i=n.errorBar;e[r]&&(e[r]=e[r].filter(e=>e.dataKey!==i.dataKey||e.direction!==i.direction))}}}),H8=V8.actions;H8.addErrorBar,H8.replaceErrorBar,H8.removeErrorBar;var Eie=V8.reducer,Die=[`children`];function Oie(e,t){if(e==null)return{};var n,r,i=kie(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function kie(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}var Aie=(0,o.createContext)({data:[],xAxisId:`xAxis-0`,yAxisId:`yAxis-0`,dataPointFormatter:()=>({x:0,y:0,value:0}),errorBarOffset:0});function jie(e){var t=e.children,n=Oie(e,Die);return o.createElement(Aie.Provider,{value:n},t)}function U8(e,t){var n=Y(t=>EX(t,e)),r=Y(e=>kX(e,t)),i=n?.allowDataOverflow??wX.allowDataOverflow,a=r?.allowDataOverflow??DX.allowDataOverflow;return{needClip:i||a,needClipX:i,needClipY:a}}function Mie(e){var t=e.xAxisId,n=e.yAxisId,r=e.clipPathId,i=k6(),a=U8(t,n),s=a.needClipX,c=a.needClipY,l=a.needClip,u=Y(e=>$Z(e,t,!1)),d=Y(e=>eQ(e,n,!1));if(!l||!i)return null;var f=i.x,p=i.y,m=i.width,h=i.height,g=s&&u?Math.min(u[0],u[1]):f-m/2,_=c&&d?Math.min(d[0],d[1]):p-h/2,v=s&&u?Math.abs(u[1]-u[0]):m*2,y=c&&d?Math.abs(d[1]-d[0]):h*2;return o.createElement(`clipPath`,{id:`clipPath-${r}`},o.createElement(`rect`,{x:g,y:_,width:v,height:y}))}function W8(e,t){return e.graphicalItems.cartesianItems.find(e=>e.id===t)?.xAxisId??0}function G8(e,t){return e.graphicalItems.cartesianItems.find(e=>e.id===t)?.yAxisId??0}var Nie=`Invariant failed`;function Pie(e,t){if(!e)throw Error(Nie)}var Fie=[`option`];function Iie(e,t){if(e==null)return{};var n,r,i=Lie(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function Lie(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}var K8=SH;function q8(e){var t=e.option,n=Iie(e,Fie);return o.createElement(b3,{option:t,DefaultShape:K8,shapeProps:n,activeClassName:`recharts-active-bar`,inActiveClassName:`recharts-inactive-bar`})}var Rie=function(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0;return(n,r)=>{if(J(e))return e;var i=J(n)||Dj(n);return i?e(n,r):(!i&&Pie(!1,`minPointSize callback function received a value with type of ${typeof n}. Currently only numbers or null/undefined are supported.`),t)}},zie=(e,t,n)=>n,J8=X([LX,(e,t)=>t],(e,t)=>e.filter(e=>e.type===`bar`).find(e=>e.id===t)),Bie=X([J8],e=>e?.maxBarSize),Vie=(e,t,n,r)=>r,Hie=X([gz,LX,W8,G8,zie],(e,t,n,r,i)=>t.filter(t=>e===`horizontal`?t.xAxisId===n:t.yAxisId===r).filter(e=>e.isPanorama===i).filter(e=>e.hide===!1).filter(e=>e.type===`bar`)),Uie=(e,t,n)=>{var r=gz(e),i=W8(e,t),a=G8(e,t);if(i!=null&&a!=null)return r===`horizontal`?lZ(e,`yAxis`,a,n):lZ(e,`xAxis`,i,n)},Wie=X([Hie,LU,(e,t)=>{var n=gz(e),r=W8(e,t),i=G8(e,t);if(r!=null&&i!=null)return n===`horizontal`?SQ(e,`xAxis`,r):SQ(e,`yAxis`,i)}],L6),Gie=(e,t,n)=>{var r=J8(e,t);if(r==null)return 0;var i=W8(e,t),a=G8(e,t);if(i==null||a==null)return 0;var o=gz(e),s=PU(e),c=r.maxBarSize,l=Dj(c)?s:c,u,d;return o===`horizontal`?(u=OQ(e,`xAxis`,i,n),d=DQ(e,`xAxis`,i,n)):(u=OQ(e,`yAxis`,a,n),d=DQ(e,`yAxis`,a,n)),rR(u,d,!0)??l??0},Y8=(e,t,n)=>{var r=gz(e),i=W8(e,t),a=G8(e,t);if(i!=null&&a!=null){var o,s;return r===`horizontal`?(o=OQ(e,`xAxis`,i,n),s=DQ(e,`xAxis`,i,n)):(o=OQ(e,`yAxis`,a,n),s=DQ(e,`yAxis`,a,n)),rR(o,s)}},Kie=X([TR,DR,(e,t,n)=>{var r=W8(e,t);if(r!=null)return OQ(e,`xAxis`,r,n)},(e,t,n)=>{var r=G8(e,t);if(r!=null)return OQ(e,`yAxis`,r,n)},(e,t,n)=>{var r=W8(e,t);if(r!=null)return DQ(e,`xAxis`,r,n)},(e,t,n)=>{var r=G8(e,t);if(r!=null)return DQ(e,`yAxis`,r,n)},X([X([Wie,PU,FU,IU,Gie,Y8,Bie],W6),J8],K6),gz,oU,Y8,X([Uie,J8],G6),J8,Vie],(e,t,n,r,i,a,o,s,c,l,u,d,f)=>{var p=c.chartData,m=c.dataStartIndex,h=c.dataEndIndex;if(!(d==null||o==null||t==null||s!==`horizontal`&&s!==`vertical`||n==null||r==null||i==null||a==null||l==null)){var g=d.data,_=g!=null&&g.length>0?g:p?.slice(m,h+1);if(_!=null)return Tae({layout:s,barSettings:d,pos:o,parentViewBox:t,bandSize:l,xAxis:n,yAxis:r,xAxisTicks:i,yAxisTicks:a,stackedData:u,displayedData:_,offset:e,cells:f,dataStartIndex:m})}}),qie=[`index`];function X8(){return X8=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},X8.apply(null,arguments)}function Jie(e,t){if(e==null)return{};var n,r,i=Yie(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function Yie(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}var Z8=(0,o.createContext)(void 0),Xie=e=>{var t=(0,o.useContext)(Z8);if(t!=null)return t.stackId;if(e!=null)return YL(e)},Zie=(e,t)=>`recharts-bar-stack-clip-path-${e}-${t}`,Qie=e=>{var t=(0,o.useContext)(Z8);if(t!=null){var n=t.stackId;return`url(#${Zie(n,e)})`}},Q8=e=>{var t=e.index,n=Jie(e,qie),r=Qie(t);return o.createElement(lj,X8({className:`recharts-bar-stack-layer`,clipPath:r},n))},$ie=[`onMouseEnter`,`onMouseLeave`,`onClick`],eae=[`value`,`background`,`tooltipPosition`],tae=[`id`],nae=[`onMouseEnter`,`onClick`,`onMouseLeave`];function $8(e,t){return oae(e)||aae(e,t)||iae(e,t)||rae()}function rae(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
64
64
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function iae(e,t){if(e){if(typeof e==`string`)return e5(e,t);var n={}.toString.call(e).slice(8,-1);return n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`?Array.from(e):n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?e5(e,t):void 0}}function e5(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function aae(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r,i,a,o,s=[],c=!0,l=!1;try{if(a=(n=n.call(e)).next,t===0){if(Object(n)!==n)return;c=!1}else for(;!(c=(r=a.call(n)).done)&&(s.push(r.value),s.length!==t);c=!0);}catch(e){l=!0,i=e}finally{try{if(!c&&n.return!=null&&(o=n.return(),Object(o)!==o))return}finally{if(l)throw i}}return s}}function oae(e){if(Array.isArray(e))return e}function t5(){return t5=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},t5.apply(null,arguments)}function n5(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function r5(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?n5(Object(n),!0).forEach(function(t){sae(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):n5(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function sae(e,t,n){return(t=cae(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function cae(e){var t=lae(e,`string`);return typeof t==`symbol`?t:t+``}function lae(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function i5(e,t){if(e==null)return{};var n,r,i=uae(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function uae(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}var dae=e=>{var t=e.dataKey,n=e.name,r=e.fill,i=e.legendType;return[{inactive:e.hide,dataKey:t,type:i,color:r,value:aR(n,t),payload:e}]},fae=o.memo(e=>{var t=e.dataKey,n=e.stroke,r=e.strokeWidth,i=e.fill,a=e.name,s=e.hide,c=e.unit,l=e.formatter,u=e.tooltipType,d=e.id,f={dataDefinedOnItem:void 0,getPosition:Aj,settings:{stroke:n,strokeWidth:r,fill:i,dataKey:t,nameKey:void 0,name:aR(a,t),hide:s,type:u,color:i,unit:c,formatter:l,graphicalItemId:d}};return o.createElement(w3,{tooltipEntrySettings:f})});function pae(e){var t=Y(Z$),n=e.data,r=e.dataKey,i=e.background,a=e.allOtherBarProps,s=a.onMouseEnter,c=a.onMouseLeave,l=a.onClick,u=i5(a,$ie),d=x3(s,r,a.id),f=S3(c),p=C3(l,r,a.id);if(!i||n==null)return null;var m=ij(i);return o.createElement(e0,{zIndex:q6(i,WU.barBackground)},n.map((e,n)=>{e.value;var a=e.background;e.tooltipPosition;var s=i5(e,eae);if(!a)return null;var c=d(e,e.originalDataIndex),l=f(e,e.originalDataIndex),h=p(e,e.originalDataIndex),g=r5(r5(r5(r5(r5({option:i,isActive:String(e.originalDataIndex)===t},s),{},{fill:`#eee`},a),m),jM(u,e,n)),{},{onMouseEnter:c,onMouseLeave:l,onClick:h,dataKey:r,index:n,className:`recharts-bar-background-rectangle`});return o.createElement(q8,t5({key:`background-bar-${n}`},g))}))}function mae(e){var t=e.showLabels,n=e.children,r=e.rects?.map(e=>{var t={x:e.x,y:e.y,width:e.width,lowerWidth:e.width,upperWidth:e.width,height:e.height};return r5(r5({},t),{},{value:e.value,payload:e.payload,parentViewBox:e.parentViewBox,viewBox:t,fill:e.fill})});return o.createElement(q4,{value:t?r:void 0},n)}function hae(e){var t=e.shape,n=e.activeBar,r=e.baseProps,i=e.entry,a=e.index,s=e.dataKey,c=Y(Z$),l=Y($$),u=n&&String(i.originalDataIndex)===c&&(l==null||s===l),d=c!=null&&(String(i.originalDataIndex)!==c||l!=null&&s!==l),f=$8((0,o.useState)(!1),2),p=f[0],m=f[1],h=$8((0,o.useState)(!1),2),g=h[0],_=h[1];(0,o.useEffect)(()=>{var e;return u?(m(!0),e=requestAnimationFrame(()=>{_(!0)})):(_(!1),d&&m(!1)),()=>{cancelAnimationFrame(e)}},[u,d]);var v=(0,o.useCallback)(()=>{u||m(!1)},[u]),y=u&&g,b=u||p,x=u?n===!0?t:n:t,S=o.createElement(q8,t5({},r,{name:String(r.name)},i,{isActive:y,option:x,index:a,dataKey:s,animationElapsedTime:e.animationElapsedTime,isAnimating:e.isAnimating,isEntrance:e.isEntrance,onTransitionEnd:v}));return b?o.createElement(e0,{zIndex:WU.activeBar},o.createElement(Q8,{index:i.originalDataIndex},S)):S}function gae(e){var t=e.shape,n=e.baseProps,r=e.entry,i=e.index,a=e.dataKey;return o.createElement(q8,t5({},n,{name:String(n.name)},r,{isActive:!1,option:t,index:i,dataKey:a,animationElapsedTime:e.animationElapsedTime,isAnimating:e.isAnimating,isEntrance:e.isEntrance}))}function _ae(e){var t=e.data,n=e.props,r=e.animationElapsedTime,i=e.isAnimating,a=e.isEntrance,s=rj(n)??{},c=s.id,l=i5(s,tae),u=n.shape,d=n.dataKey,f=n.activeBar,p=n.onMouseEnter,m=n.onClick,h=n.onMouseLeave,g=i5(n,nae),_=x3(p,d,c),v=S3(h),y=C3(m,d,c);return t?o.createElement(o.Fragment,null,t.map((e,t)=>o.createElement(Q8,t5({index:e.originalDataIndex,key:`rectangle-${e?.x}-${e?.y}-${e?.value}-${t}`,className:`recharts-bar-rectangle`},jM(g,e,t),{onMouseEnter:_(e,e.originalDataIndex),onMouseLeave:v(e,e.originalDataIndex),onClick:y(e,e.originalDataIndex)}),f?o.createElement(hae,{shape:u,activeBar:f,baseProps:l,entry:e,index:t,dataKey:d,animationElapsedTime:r,isAnimating:i,isEntrance:a}):o.createElement(gae,{shape:u,baseProps:l,entry:e,index:t,dataKey:d,animationElapsedTime:r,isAnimating:i,isEntrance:a})))):null}var vae=(e,t,n)=>e==null?[]:t===1?e.flatMap(e=>e.status===`removed`?[]:[e.next]):e.flatMap(e=>{if(e.status===`removed`)return n===`horizontal`?[r5(r5({},e.prev),{},{height:Ej(e.prev.height,0,t),y:Ej(e.prev.y,e.prev.y+e.prev.height,t)})]:[r5(r5({},e.prev),{},{width:Ej(e.prev.width,0,t)})];if(e.status===`matched`)return[r5(r5({},e.next),{},{x:Ej(e.prev.x,e.next.x,t),y:Ej(e.prev.y,e.next.y,t),width:Ej(e.prev.width,e.next.width,t),height:Ej(e.prev.height,e.next.height,t)})];var r=e.next;return n===`horizontal`?[r5(r5({},r),{},{height:Ej(0,r.height,t),y:Ej(r.stackedBarStart,r.y,t)})]:[r5(r5({},r),{},{width:Ej(0,r.width,t),x:Ej(r.stackedBarStart,r.x,t)})]});function yae(e){var t=e.props,n=e.previousRectanglesRef,r=t.data,i=t.isAnimationActive,a=t.animationBegin,s=t.animationDuration,c=t.animationEasing,l=t.animationInterpolateFn,u=t.layout,d=q3(t.onAnimationStart,t.onAnimationEnd),f=d.isAnimating,p=d.handleAnimationStart,m=d.handleAnimationEnd;return o.createElement(mae,{showLabels:!f,rects:r},o.createElement(J3,{animationInput:r,animationIdPrefix:`recharts-bar-`,items:r,previousItemsRef:n,isAnimationActive:i,animationBegin:a,animationDuration:s,animationEasing:c,onAnimationStart:p,onAnimationEnd:m,animationInterpolateFn:l,animationMatchBy:t.animationMatchBy,layout:u},(e,n,r)=>o.createElement(lj,null,o.createElement(_ae,{props:t,data:e,animationElapsedTime:n,isAnimating:f||n<1,isEntrance:r}))),o.createElement(Q4,{label:t.label}),t.children)}function bae(e){var t=(0,o.useRef)(null);return o.createElement(yae,{previousRectanglesRef:t,props:e})}var a5=0,xae=(e,t)=>{var n=Array.isArray(e.value)?e.value[1]:e.value;return{x:e.x,y:e.y,value:n,errorVal:VL(e,t)}},Sae=class extends o.PureComponent{render(){var e=this.props,t=e.hide,n=e.data,r=e.dataKey,i=e.className,a=e.xAxisId,s=e.yAxisId,c=e.needClip,l=e.background,u=e.id;if(t||n==null)return null;var d=$A(`recharts-bar`,i),f=u;return o.createElement(lj,{className:d,id:u},c&&o.createElement(`defs`,null,o.createElement(Mie,{clipPathId:f,xAxisId:a,yAxisId:s})),o.createElement(lj,{className:`recharts-bar-rectangles`,clipPath:c?`url(#clipPath-${f})`:void 0},o.createElement(pae,{data:n,dataKey:r,background:l,allOtherBarProps:this.props}),o.createElement(bae,this.props)))}},Cae={activeBar:!1,animationBegin:0,animationDuration:400,animationEasing:`ease`,animationInterpolateFn:vae,animationMatchBy:N3,background:!1,hide:!1,isAnimationActive:`auto`,label:!1,legendType:`rect`,minPointSize:a5,shape:K8,xAxisId:0,yAxisId:0,zIndex:WU.bar};function wae(e){var t=e.xAxisId,n=e.yAxisId,r=e.hide,i=e.legendType,a=e.minPointSize,s=e.activeBar,c=e.animationBegin,l=e.animationDuration,u=e.animationEasing,d=e.isAnimationActive,f=U8(t,n).needClip,p=_z(),m=kR(),h=l3(e.children,e2),g=Y(t=>Kie(t,e.id,m,h));if(p!==`vertical`&&p!==`horizontal`)return null;var _,v=g?.[0];return _=v==null||v.height==null||v.width==null?0:p===`vertical`?v.height/2:v.width/2,o.createElement(jie,{xAxisId:t,yAxisId:n,data:g,dataPointFormatter:xae,errorBarOffset:_},o.createElement(Sae,t5({},e,{layout:p,needClip:f,data:g,xAxisId:t,yAxisId:n,hide:r,legendType:i,minPointSize:a,activeBar:s,animationBegin:c,animationDuration:l,animationEasing:u,isAnimationActive:d})))}function Tae(e){var t=e.layout,n=e.barSettings,r=n.dataKey,i=n.minPointSize,a=n.hasCustomShape,o=e.pos,s=e.bandSize,c=e.xAxis,l=e.yAxis,u=e.xAxisTicks,d=e.yAxisTicks,f=e.stackedData,p=e.displayedData,m=e.offset,h=e.cells,g=e.parentViewBox,_=e.dataStartIndex,v=t===`horizontal`?l:c,y=f?v.scale.domain():null,b=ZL({numericAxis:v}),x=v.scale.map(b);return p.map((e,n)=>{var p,v,S,C,w,T;if(f){var E=f[n+_];if(E==null)return null;p=KL(E,y)}else p=VL(e,r),Array.isArray(p)||(p=[b,p]);var D=Rie(i,a5)(p[1],n);if(t===`horizontal`){var O=l.scale.map(p[0]),k=l.scale.map(p[1]);if(O==null||k==null)return null;v=XL({axis:c,ticks:u,bandSize:s,offset:o.offset,entry:e,index:n}),S=k??O??void 0,C=o.size;var A=O-k;if(w=bj(A)?0:A,T={x:v,y:m.top,width:C,height:m.height},Math.abs(D)>0&&Math.abs(w)<Math.abs(D)){var j=yj(w||D)*(Math.abs(D)-Math.abs(w));S-=j,w+=j}}else{var M=c.scale.map(p[0]),N=c.scale.map(p[1]);if(M==null||N==null)return null;if(v=M,S=XL({axis:l,ticks:d,bandSize:s,offset:o.offset,entry:e,index:n}),C=N-M,w=o.size,T={x:m.left,y:S,width:m.width,height:w},Math.abs(D)>0&&Math.abs(C)<Math.abs(D)){var ee=yj(C||D)*(Math.abs(D)-Math.abs(C));C+=ee}}return v==null||S==null||C==null||w==null||!a&&(C===0||w===0)?null:r5(r5({},e),{},{stackedBarStart:x,x:v,y:S,width:C,height:w,value:f?p:p[1],payload:e,background:T,tooltipPosition:{x:v+C/2,y:S+w/2},parentViewBox:g,originalDataIndex:n},h&&h[n]&&h[n].props)}).filter(Boolean)}function Eae(e){var t=LM(e,Cae),n=Xie(t.stackId),r=kR();return o.createElement(i6,{id:t.id,type:`bar`},e=>o.createElement(o.Fragment,null,o.createElement(T3,{legendPayload:dae(t)}),o.createElement(fae,{dataKey:t.dataKey,stroke:t.stroke,strokeWidth:t.strokeWidth,fill:t.fill,name:t.name,hide:t.hide,unit:t.unit,formatter:t.formatter,tooltipType:t.tooltipType,id:e}),o.createElement(d6,{type:`bar`,id:e,data:void 0,xAxisId:t.xAxisId,yAxisId:t.yAxisId,zAxisId:0,dataKey:t.dataKey,stackId:n,hide:t.hide,barSize:t.barSize,minPointSize:t.minPointSize,maxBarSize:t.maxBarSize,isPanorama:r,hasCustomShape:t.shape!=null&&t.shape!==K8}),o.createElement(e0,{zIndex:t.zIndex},o.createElement(wae,t5({},t,{id:e})))))}var o5=o.memo(Eae,Kz);o5.displayName=`Bar`;var Dae=[`domain`,`range`],Oae=[`domain`,`range`];function s5(e,t){if(e==null)return{};var n,r,i=kae(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function kae(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function c5(e,t){return e===t?!0:Array.isArray(e)&&e.length===2&&Array.isArray(t)&&t.length===2?e[0]===t[0]&&e[1]===t[1]:!1}function l5(e,t){if(e===t)return!0;var n=e.domain,r=e.range,i=s5(e,Dae),a=t.domain,o=t.range,s=s5(t,Oae);return!c5(n,a)||!c5(r,o)?!1:Kz(i,s)}var Aae=[`type`],jae=[`dangerouslySetInnerHTML`,`ticks`,`scale`],Mae=[`id`,`scale`];function u5(){return u5=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},u5.apply(null,arguments)}function d5(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function f5(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?d5(Object(n),!0).forEach(function(t){Nae(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):d5(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function Nae(e,t,n){return(t=Pae(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Pae(e){var t=Fae(e,`string`);return typeof t==`symbol`?t:t+``}function Fae(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function p5(e,t){if(e==null)return{};var n,r,i=Iae(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function Iae(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function Lae(e){var t=XN(),n=(0,o.useRef)(null),r=vz(),i=e.type,a=p5(e,Aae),s=JU(r,`xAxis`,i),c=(0,o.useMemo)(()=>{if(s!=null)return f5(f5({},a),{},{type:s})},[a,s]);return(0,o.useLayoutEffect)(()=>{c!=null&&(n.current===null?t(y6(c)):n.current!==c&&t(b6({prev:n.current,next:c})),n.current=c)},[c,t]),(0,o.useLayoutEffect)(()=>()=>{n.current&&=(t(x6(n.current)),null)},[t]),null}var Rae=e=>{var t=e.xAxisId,n=e.className,r=e.height,i=e.label,a=(0,o.useRef)(null),s=(0,o.useRef)(null),c=Y(DR),l=kR(),u=XN(),d=`xAxis`,f=Y(e=>EQ(e,d,t,l)),p=Y(e=>mQ(e,t)),m=Y(e=>yQ(e,t)),h=Y(e=>TX(e,t));if((0,o.useLayoutEffect)(()=>{if(!(r!==`auto`||!p||A4(i)||(0,o.isValidElement)(i)||h==null)){var e=a.current;if(e){var n=e.getCalculatedHeight();Math.round(p.height)!==Math.round(n)&&u(E6({id:t,height:n}))}}},[f,p,u,i,t,r,h]),p==null||m==null||h==null)return null;e.dangerouslySetInnerHTML,e.ticks,e.scale;var g=p5(e,jae);h.id,h.scale;var _=p5(h,Mae);return o.createElement(N8,u5({},g,_,{ref:a,labelRef:s,x:m.x,y:m.y,width:p.width,height:p.height,className:$A(`recharts-${d} ${d}`,n),viewBox:c,ticks:f,axisType:d,axisId:t}))},zae={allowDataOverflow:wX.allowDataOverflow,allowDecimals:wX.allowDecimals,allowDuplicatedCategory:wX.allowDuplicatedCategory,angle:wX.angle,axisLine:M8.axisLine,height:wX.height,hide:!1,includeHidden:wX.includeHidden,interval:wX.interval,label:!1,minTickGap:wX.minTickGap,mirror:wX.mirror,orientation:wX.orientation,padding:wX.padding,reversed:wX.reversed,scale:wX.scale,tick:wX.tick,tickCount:wX.tickCount,tickLine:M8.tickLine,tickSize:M8.tickSize,type:wX.type,niceTicks:wX.niceTicks,xAxisId:0},m5=o.memo(e=>{var t=LM(e,zae);return o.createElement(o.Fragment,null,o.createElement(Lae,{allowDataOverflow:t.allowDataOverflow,allowDecimals:t.allowDecimals,allowDuplicatedCategory:t.allowDuplicatedCategory,angle:t.angle,dataKey:t.dataKey,domain:t.domain,height:t.height,hide:t.hide,id:t.xAxisId,includeHidden:t.includeHidden,interval:t.interval,minTickGap:t.minTickGap,mirror:t.mirror,name:t.name,orientation:t.orientation,padding:t.padding,reversed:t.reversed,scale:t.scale,tick:t.tick,tickCount:t.tickCount,tickFormatter:t.tickFormatter,ticks:t.ticks,type:t.type,unit:t.unit,niceTicks:t.niceTicks}),o.createElement(Rae,t))},l5);m5.displayName=`XAxis`;var Bae=[`type`],Vae=[`dangerouslySetInnerHTML`,`ticks`,`scale`],Hae=[`id`,`scale`];function h5(){return h5=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},h5.apply(null,arguments)}function g5(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function _5(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?g5(Object(n),!0).forEach(function(t){Uae(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):g5(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function Uae(e,t,n){return(t=Wae(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Wae(e){var t=Gae(e,`string`);return typeof t==`symbol`?t:t+``}function Gae(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function v5(e,t){if(e==null)return{};var n,r,i=Kae(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function Kae(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function qae(e){var t=XN(),n=(0,o.useRef)(null),r=vz(),i=e.type,a=v5(e,Bae),s=JU(r,`yAxis`,i),c=(0,o.useMemo)(()=>{if(s!=null)return _5(_5({},a),{},{type:s})},[s,a]);return(0,o.useLayoutEffect)(()=>{c!=null&&(n.current===null?t(S6(c)):n.current!==c&&t(C6({prev:n.current,next:c})),n.current=c)},[c,t]),(0,o.useLayoutEffect)(()=>()=>{n.current&&=(t(w6(n.current)),null)},[t]),null}function Jae(e){var t=e.yAxisId,n=e.className,r=e.width,i=e.label,a=(0,o.useRef)(null),s=(0,o.useRef)(null),c=Y(DR),l=kR(),u=XN(),d=`yAxis`,f=Y(e=>xQ(e,t)),p=Y(e=>bQ(e,t)),m=Y(e=>EQ(e,d,t,l)),h=Y(e=>OX(e,t));if((0,o.useLayoutEffect)(()=>{if(!(r!==`auto`||!f||A4(i)||(0,o.isValidElement)(i)||h==null)){var e=a.current;if(e){var n=e.getCalculatedWidth();Math.round(f.width)!==Math.round(n)&&u(T6({id:t,width:n}))}}},[m,f,u,i,t,r,h]),f==null||p==null||h==null)return null;e.dangerouslySetInnerHTML,e.ticks,e.scale;var g=v5(e,Vae);h.id,h.scale;var _=v5(h,Hae);return o.createElement(N8,h5({},g,_,{ref:a,labelRef:s,x:p.x,y:p.y,tickTextProps:r===`auto`?{width:void 0}:{width:r},width:f.width,height:f.height,className:$A(`recharts-${d} ${d}`,n),viewBox:c,ticks:m,axisType:d,axisId:t}))}var Yae={allowDataOverflow:DX.allowDataOverflow,allowDecimals:DX.allowDecimals,allowDuplicatedCategory:DX.allowDuplicatedCategory,angle:DX.angle,axisLine:M8.axisLine,hide:!1,includeHidden:DX.includeHidden,interval:DX.interval,label:!1,minTickGap:DX.minTickGap,mirror:DX.mirror,orientation:DX.orientation,padding:DX.padding,reversed:DX.reversed,scale:DX.scale,tick:DX.tick,tickCount:DX.tickCount,tickLine:M8.tickLine,tickSize:M8.tickSize,type:DX.type,niceTicks:DX.niceTicks,width:DX.width,yAxisId:0},y5=o.memo(e=>{var t=LM(e,Yae);return o.createElement(o.Fragment,null,o.createElement(qae,{interval:t.interval,id:t.yAxisId,scale:t.scale,type:t.type,domain:t.domain,allowDataOverflow:t.allowDataOverflow,dataKey:t.dataKey,allowDuplicatedCategory:t.allowDuplicatedCategory,allowDecimals:t.allowDecimals,tickCount:t.tickCount,padding:t.padding,includeHidden:t.includeHidden,reversed:t.reversed,ticks:t.ticks,width:t.width,orientation:t.orientation,mirror:t.mirror,hide:t.hide,unit:t.unit,name:t.name,angle:t.angle,minTickGap:t.minTickGap,tick:t.tick,tickFormatter:t.tickFormatter,niceTicks:t.niceTicks}),o.createElement(Jae,t))},l5);y5.displayName=`YAxis`;var b5=X([(e,t)=>t,gz,uW,yW,W$,K$,w1,TR],I1);function Xae(e){return`getBBox`in e.currentTarget&&typeof e.currentTarget.getBBox==`function`}function x5(e){var t=e.currentTarget.getBoundingClientRect(),n,r;if(Xae(e)){var i=e.currentTarget.getBBox();n=i.width>0?t.width/i.width:1,r=i.height>0?t.height/i.height:1}else{var a=e.currentTarget;n=a.offsetWidth>0?t.width/a.offsetWidth:1,r=a.offsetHeight>0?t.height/a.offsetHeight:1}var o=(e,i)=>({relativeX:Math.round((e-t.left)/n),relativeY:Math.round((i-t.top)/r)});return`touches`in e?Array.from(e.touches).map(e=>o(e.clientX,e.clientY)):o(e.clientX,e.clientY)}var S5=_I(`mouseClick`),C5=TL();C5.startListening({actionCreator:S5,effect:(e,t)=>{var n=e.payload,r=b5(t.getState(),x5(n));r?.activeIndex!=null&&t.dispatch(YQ({activeIndex:r.activeIndex,activeDataKey:void 0,activeCoordinate:r.activeCoordinate}))}});var w5=_I(`mouseMove`),T5=TL(),E5=null,D5=null,O5=null;T5.startListening({actionCreator:w5,effect:(e,t)=>{var n=e.payload,r=t.getState().eventSettings,i=r.throttleDelay,a=r.throttledEvents,o=a===`all`||a?.includes(`mousemove`);E5!==null&&(cancelAnimationFrame(E5),E5=null),D5!==null&&(typeof i!=`number`||!o)&&(clearTimeout(D5),D5=null),O5=x5(n);var s=()=>{var e=t.getState(),n=NQ(e,e.tooltip.settings.shared);if(!O5){E5=null,D5=null;return}if(n===`axis`){var r=b5(e,O5);r?.activeIndex==null?t.dispatch(KQ()):t.dispatch(JQ({activeIndex:r.activeIndex,activeDataKey:void 0,activeCoordinate:r.activeCoordinate}))}E5=null,D5=null};if(!o){s();return}i===`raf`?E5=requestAnimationFrame(s):typeof i==`number`&&D5===null&&(D5=setTimeout(s,i))}});function Zae(e,t){return t instanceof HTMLElement?`HTMLElement <${t.tagName} class="${t.className}">`:t===window?`global.window`:e===`children`&&typeof t==`object`&&t?`<<CHILDREN>>`:t}var k5={accessibilityLayer:!0,barCategoryGap:`10%`,barGap:4,barSize:void 0,className:void 0,maxBarSize:void 0,stackOffset:`none`,syncId:void 0,syncMethod:`index`,baseValue:void 0,reverseStackOrder:!1},A5=zI({name:`rootProps`,initialState:k5,reducers:{updateOptions:(e,t)=>{e.accessibilityLayer=t.payload.accessibilityLayer,e.barCategoryGap=t.payload.barCategoryGap,e.barGap=t.payload.barGap??k5.barGap,e.barSize=t.payload.barSize,e.maxBarSize=t.payload.maxBarSize,e.stackOffset=t.payload.stackOffset,e.syncId=t.payload.syncId,e.syncMethod=t.payload.syncMethod,e.className=t.payload.className,e.baseValue=t.payload.baseValue,e.reverseStackOrder=t.payload.reverseStackOrder}}}),Qae=A5.reducer,$ae=A5.actions.updateOptions,j5=zI({name:`polarOptions`,initialState:null,reducers:{updatePolarOptions:(e,t)=>e===null?t.payload:(e.startAngle=t.payload.startAngle,e.endAngle=t.payload.endAngle,e.cx=t.payload.cx,e.cy=t.payload.cy,e.innerRadius=t.payload.innerRadius,e.outerRadius=t.payload.outerRadius,e)}});j5.actions.updatePolarOptions;var eoe=j5.reducer,M5=_I(`keyDown`),N5=_I(`focus`),P5=_I(`blur`),F5=TL(),I5=null,L5=null,R5=null;F5.startListening({actionCreator:M5,effect:(e,t)=>{R5=e.payload,I5!==null&&(cancelAnimationFrame(I5),I5=null);var n=t.getState().eventSettings,r=n.throttleDelay,i=n.throttledEvents,a=i===`all`||i.includes(`keydown`);L5!==null&&(typeof r!=`number`||!a)&&(clearTimeout(L5),L5=null);var o=()=>{try{var e=t.getState();if(e.rootProps.accessibilityLayer===!1)return;var n=e.tooltip.keyboardInteraction,r=R5;if(r!==`ArrowRight`&&r!==`ArrowLeft`&&r!==`Enter`)return;var i=u$(n,M$(e),oZ(e),V$(e)),a=i==null?-1:Number(i),o=!Number.isFinite(a)||a<0,s=K$(e),c=M$(e),l=NQ(e,e.tooltip.settings.shared);if(r===`Enter`){if(o)return;var u=k1(e,l,`hover`,String(n.index));t.dispatch(ZQ({active:!n.active,activeIndex:n.index,activeCoordinate:u}));return}var d=kQ(e)===`left-to-right`?1:-1,f=r===`ArrowRight`?1:-1,p;if(o){var m=oZ(e),h=V$(e),g=f*d,_=e=>({active:!1,index:String(e),dataKey:void 0,graphicalItemId:void 0,coordinate:void 0});if(p=-1,g>0){for(var v=0;v<c.length;v++)if(u$(_(v),c,m,h)!=null){p=v;break}}else for(var y=c.length-1;y>=0;y--)if(u$(_(y),c,m,h)!=null){p=y;break}if(p<0)return}else{p=a+f*d;var b=s?.length||c.length;if(b===0||p>=b||p<0)return}var x=k1(e,l,`hover`,String(p));t.dispatch(ZQ({active:!0,activeIndex:p.toString(),activeCoordinate:x}))}finally{I5=null,L5=null}};if(!a){o();return}r===`raf`?I5=requestAnimationFrame(o):typeof r==`number`&&L5===null&&(o(),R5=null,L5=setTimeout(()=>{R5?o():(L5=null,I5=null)},r))}}),F5.startListening({actionCreator:N5,effect:(e,t)=>{var n=t.getState();if(n.rootProps.accessibilityLayer!==!1){var r=n.tooltip.keyboardInteraction;if(!r.active&&r.index==null){var i=`0`,a=k1(n,NQ(n,n.tooltip.settings.shared),`hover`,String(i));t.dispatch(ZQ({active:!0,activeIndex:i,activeCoordinate:a}))}}}}),F5.startListening({actionCreator:P5,effect:(e,t)=>{var n=t.getState();if(n.rootProps.accessibilityLayer!==!1){var r=n.tooltip.keyboardInteraction;r.active&&t.dispatch(ZQ({active:!1,activeIndex:r.index,activeCoordinate:r.coordinate}))}}});function z5(e){e.persist();var t=e.currentTarget;return new Proxy(e,{get:(e,n)=>{if(n===`currentTarget`)return t;var r=Reflect.get(e,n);return typeof r==`function`?r.bind(e):r}})}var B5=_I(`externalEvent`),V5=TL(),H5=new Map,U5=new Map,W5=new Map;V5.startListening({actionCreator:B5,effect:(e,t)=>{var n=e.payload,r=n.handler,i=n.reactEvent;if(r!=null){var a=i.type,o=z5(i);W5.set(a,{handler:r,reactEvent:o});var s=H5.get(a);s!==void 0&&(cancelAnimationFrame(s),H5.delete(a));var c=t.getState().eventSettings,l=c.throttleDelay,u=c.throttledEvents,d=u===`all`||u?.includes(a),f=U5.get(a);f!==void 0&&(typeof l!=`number`||!d)&&(clearTimeout(f),U5.delete(a));var p=()=>{var e=W5.get(a);try{if(!e)return;var n=e.handler,r=e.reactEvent,i=t.getState(),o={activeCoordinate:n1(i),activeDataKey:$$(i),activeIndex:Z$(i),activeLabel:Q$(i),activeTooltipIndex:Z$(i),isTooltipActive:r1(i)};n&&n(o,r)}finally{H5.delete(a),U5.delete(a),W5.delete(a)}};if(!d){p();return}if(l===`raf`){var m=requestAnimationFrame(p);H5.set(a,m)}else if(typeof l==`number`){if(!U5.has(a)){p();var h=setTimeout(p,l);U5.set(a,h)}}else p()}}});var toe=X([X([m$],e=>e.tooltipItemPayloads),(e,t)=>t,(e,t,n)=>n],(e,t,n)=>{if(t!=null){var r=e.find(e=>e.settings.graphicalItemId===n);if(r!=null){var i=r.getPosition;if(i!=null)return i(t)}}}),G5=_I(`touchMove`),K5=TL(),q5=null,J5=null,Y5=null,X5=null;K5.startListening({actionCreator:G5,effect:(e,t)=>{var n=e.payload;if(n.touches!=null&&n.touches.length!==0){X5=z5(n);var r=t.getState().eventSettings,i=r.throttleDelay,a=r.throttledEvents,o=a===`all`||a.includes(`touchmove`);q5!==null&&(cancelAnimationFrame(q5),q5=null),J5!==null&&(typeof i!=`number`||!o)&&(clearTimeout(J5),J5=null),Y5=Array.from(n.touches).map(e=>x5({clientX:e.clientX,clientY:e.clientY,currentTarget:n.currentTarget}));var s=()=>{if(X5!=null){var e=t.getState(),n=NQ(e,e.tooltip.settings.shared);if(n===`axis`){var r=Y5?.[0];if(r==null){q5=null,J5=null;return}var i=b5(e,r);i?.activeIndex!=null&&t.dispatch(JQ({activeIndex:i.activeIndex,activeDataKey:void 0,activeCoordinate:i.activeCoordinate}))}else if(n===`item`){var a=X5.touches[0];if(document.elementFromPoint==null||a==null)return;var o=document.elementFromPoint(a.clientX,a.clientY);if(!o||!o.getAttribute)return;var s=o.getAttribute(mR),c=o.getAttribute(`data-recharts-item-id`)??void 0,l=O$(e).find(e=>e.id===c);if(s==null||l==null||c==null)return;var u=l.dataKey,d=toe(e,s,c);t.dispatch(WQ({activeDataKey:u,activeIndex:s,activeCoordinate:d,activeGraphicalItemId:c}))}q5=null,J5=null}};if(!o){s();return}i===`raf`?q5=requestAnimationFrame(s):typeof i==`number`&&J5===null&&(s(),X5=null,J5=setTimeout(()=>{X5?s():(J5=null,q5=null)},i))}}});var Z5={throttleDelay:`raf`,throttledEvents:[`mousemove`,`touchmove`,`pointermove`,`scroll`,`wheel`]},Q5=zI({name:`eventSettings`,initialState:Z5,reducers:{setEventSettings:(e,t)=>{t.payload.throttleDelay!=null&&(e.throttleDelay=t.payload.throttleDelay),t.payload.throttledEvents!=null&&(e.throttledEvents=Z(t.payload.throttledEvents))}}}),noe=Q5.actions.setEventSettings,roe=Q5.reducer,ioe=VP({brush:Z6,cartesianAxis:D6,chartData:T0,errorBars:Eie,eventSettings:roe,graphicalItems:u6,layout:NL,legend:Dz,options:v0,polarAxis:t3,polarOptions:eoe,referenceElements:n8,renderedTicks:Wre,rootProps:Qae,tooltip:QQ,zIndex:$1}),aoe=function(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:`Chart`;return kI({reducer:ioe,preloadedState:e,middleware:e=>e({serializableCheck:!1,immutableCheck:![`commonjs`,`es6`,`production`].includes(`es6`)}).concat([C5.middleware,T5.middleware,F5.middleware,V5.middleware,K5.middleware]),enhancers:e=>{var t=e;return typeof e==`function`&&(t=e()),t.concat(DI({type:`raf`}))},devTools:hB.devToolsEnabled&&{serialize:{replacer:Zae},name:`recharts-${t}`}})};function ooe(e){var t=e.preloadedState,n=e.children,r=e.reduxStoreName,i=kR(),a=(0,o.useRef)(null);if(i)return n;a.current??=aoe(t,r);var s=JN;return o.createElement(Uz,{context:s,store:a.current},n)}function soe(e){var t=e.layout,n=e.margin,r=XN(),i=kR();return(0,o.useEffect)(()=>{i||(r(AL(t)),r(kL(n)))},[r,i,t,n]),null}var coe=(0,o.memo)(soe,Kz);function loe(e){var t=XN();return(0,o.useEffect)(()=>{t($ae(e))},[t,e]),null}var uoe=(0,o.memo)(e=>{var t=XN();return(0,o.useEffect)(()=>{t(noe(e))},[t,e]),null},Kz);function $5(e){var t=e.zIndex,n=e.isPanorama,r=(0,o.useRef)(null),i=XN();return(0,o.useLayoutEffect)(()=>(r.current&&i(Z1({zIndex:t,element:r.current,isPanorama:n})),()=>{i(Q1({zIndex:t,isPanorama:n}))}),[i,t,n]),o.createElement(`g`,{tabIndex:-1,ref:r,className:`recharts-zIndex-layer_${t}`})}function e7(e){var t=e.children,n=e.isPanorama,r=Y(R1);if(!r||r.length===0)return t;var i=r.filter(e=>e<0),a=r.filter(e=>e>0);return o.createElement(o.Fragment,null,i.map(e=>o.createElement($5,{key:e,zIndex:e,isPanorama:n})),t,a.map(e=>o.createElement($5,{key:e,zIndex:e,isPanorama:n})))}var doe=[`children`];function foe(e,t){if(e==null)return{};var n,r,i=poe(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function poe(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function t7(){return t7=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},t7.apply(null,arguments)}var moe={width:`100%`,height:`100%`,display:`block`},hoe=(0,o.forwardRef)((e,t)=>{var n=mz(),r=hz(),i=LB();if(!FL(n)||!FL(r))return null;var a=e.children,s=e.otherAttributes,c=e.title,l=e.desc,u,d;return s!=null&&(u=typeof s.tabIndex==`number`?s.tabIndex:i?0:void 0,d=typeof s.role==`string`?s.role:i?`application`:void 0),o.createElement(sj,t7({},s,{title:c,desc:l,role:d,tabIndex:u,width:n,height:r,style:moe,ref:t}),a)}),goe=e=>{var t=e.children,n=Y(jR);if(!n)return null;var r=n.width,i=n.height,a=n.y,s=n.x;return o.createElement(sj,{width:r,height:i,x:s,y:a},t)},n7=(0,o.forwardRef)((e,t)=>{var n=e.children,r=foe(e,doe);return kR()?o.createElement(goe,null,o.createElement(e7,{isPanorama:!0},n)):o.createElement(hoe,t7({ref:t},r),o.createElement(e7,{isPanorama:!1},n))});function _oe(e,t){return xoe(e)||boe(e,t)||yoe(e,t)||voe()}function voe(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
65
65
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function yoe(e,t){if(e){if(typeof e==`string`)return r7(e,t);var n={}.toString.call(e).slice(8,-1);return n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`?Array.from(e):n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r7(e,t):void 0}}function r7(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function boe(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r,i,a,o,s=[],c=!0,l=!1;try{if(a=(n=n.call(e)).next,t===0){if(Object(n)!==n)return;c=!1}else for(;!(c=(r=a.call(n)).done)&&(s.push(r.value),s.length!==t);c=!0);}catch(e){l=!0,i=e}finally{try{if(!c&&n.return!=null&&(o=n.return(),Object(o)!==o))return}finally{if(l)throw i}}return s}}function xoe(e){if(Array.isArray(e))return e}function Soe(){var e=XN(),t=_oe((0,o.useState)(null),2),n=t[0],r=t[1],i=Y(uR);return(0,o.useEffect)(()=>{if(n!=null){var t=n.getBoundingClientRect().width/n.offsetWidth;Q(t)&&t!==i&&e(ML(t))}},[n,e,i]),r}function i7(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function Coe(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?i7(Object(n),!0).forEach(function(t){woe(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):i7(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function woe(e,t,n){return(t=Toe(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Toe(e){var t=Eoe(e,`string`);return typeof t==`symbol`?t:t+``}function Eoe(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function a7(){return a7=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},a7.apply(null,arguments)}function o7(e,t){return Aoe(e)||koe(e,t)||Ooe(e,t)||Doe()}function Doe(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
66
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Ooe(e,t){if(e){if(typeof e==`string`)return s7(e,t);var n={}.toString.call(e).slice(8,-1);return n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`?Array.from(e):n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?s7(e,t):void 0}}function s7(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function koe(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r,i,a,o,s=[],c=!0,l=!1;try{if(a=(n=n.call(e)).next,t===0){if(Object(n)!==n)return;c=!1}else for(;!(c=(r=a.call(n)).done)&&(s.push(r.value),s.length!==t);c=!0);}catch(e){l=!0,i=e}finally{try{if(!c&&n.return!=null&&(o=n.return(),Object(o)!==o))return}finally{if(l)throw i}}return s}}function Aoe(e){if(Array.isArray(e))return e}var joe=()=>(I0(),null);function c7(e){if(typeof e==`number`)return e;if(typeof e==`string`){var t=parseFloat(e);if(!Number.isNaN(t))return t}return 0}var Moe=(0,o.forwardRef)((e,t)=>{var n=(0,o.useRef)(null),r=o7((0,o.useState)({containerWidth:c7(e.style?.width),containerHeight:c7(e.style?.height)}),2),i=r[0],a=r[1],s=(0,o.useCallback)((e,t)=>{a(n=>{var r=Math.round(e),i=Math.round(t);return n.containerWidth===r&&n.containerHeight===i?n:{containerWidth:r,containerHeight:i}})},[]),c=(0,o.useCallback)(e=>{if(typeof t==`function`&&t(e),n.current!=null&&(n.current.disconnect(),n.current=null),e!=null&&typeof ResizeObserver<`u`){var r=e.getBoundingClientRect(),i=r.width,a=r.height;s(i,a);var o=new ResizeObserver(e=>{var t=e[0];if(t!=null){var n=t.contentRect,r=n.width,i=n.height;s(r,i)}});o.observe(e),n.current=o}},[t,s]);return(0,o.useEffect)(()=>()=>{n.current?.disconnect()},[s]),o.createElement(o.Fragment,null,o.createElement(xz,{width:i.containerWidth,height:i.containerHeight}),o.createElement(`div`,a7({ref:c},e)))}),Noe=(0,o.forwardRef)((e,t)=>{var n=e.width,r=e.height,i=o7((0,o.useState)({containerWidth:c7(n),containerHeight:c7(r)}),2),a=i[0],s=i[1],c=(0,o.useCallback)((e,t)=>{s(n=>{var r=Math.round(e),i=Math.round(t);return n.containerWidth===r&&n.containerHeight===i?n:{containerWidth:r,containerHeight:i}})},[]),l=(0,o.useCallback)(e=>{if(typeof t==`function`&&t(e),e!=null){var n=e.getBoundingClientRect(),r=n.width,i=n.height;c(r,i)}},[t,c]);return o.createElement(o.Fragment,null,o.createElement(xz,{width:a.containerWidth,height:a.containerHeight}),o.createElement(`div`,a7({ref:l},e)))}),Poe=(0,o.forwardRef)((e,t)=>{var n=e.width,r=e.height;return o.createElement(o.Fragment,null,o.createElement(xz,{width:n,height:r}),o.createElement(`div`,a7({ref:t},e)))}),Foe=(0,o.forwardRef)((e,t)=>{var n=e.width,r=e.height;return typeof n==`string`||typeof r==`string`?o.createElement(Noe,a7({},e,{ref:t})):typeof n==`number`&&typeof r==`number`?o.createElement(Poe,a7({},e,{width:n,height:r,ref:t})):o.createElement(o.Fragment,null,o.createElement(xz,{width:n,height:r}),o.createElement(`div`,a7({ref:t},e)))});function Ioe(e){return e?Moe:Foe}var Loe=(0,o.forwardRef)((e,t)=>{var n=e.children,r=e.className,i=e.height,a=e.onClick,s=e.onContextMenu,c=e.onDoubleClick,l=e.onMouseDown,u=e.onMouseEnter,d=e.onMouseLeave,f=e.onMouseMove,p=e.onMouseUp,m=e.onTouchEnd,h=e.onTouchMove,g=e.onTouchStart,_=e.style,v=e.width,y=e.responsive,b=e.dispatchTouchEvents,x=b===void 0||b,S=(0,o.useRef)(null),C=XN(),w=o7((0,o.useState)(null),2),T=w[0],E=w[1],D=o7((0,o.useState)(null),2),O=D[0],k=D[1],A=Soe(),j=cz(),M=j?.width>0?j.width:v,N=j?.height>0?j.height:i,ee=(0,o.useCallback)(e=>{A(e),typeof t==`function`&&t(e),E(e),k(e),e!=null&&(S.current=e)},[A,t,E,k]),te=(0,o.useCallback)(e=>{C(S5(e)),C(B5({handler:a,reactEvent:e}))},[C,a]),ne=(0,o.useCallback)(e=>{C(w5(e)),C(B5({handler:u,reactEvent:e}))},[C,u]),P=(0,o.useCallback)(e=>{C(KQ()),C(B5({handler:d,reactEvent:e}))},[C,d]),re=(0,o.useCallback)(e=>{C(w5(e)),C(B5({handler:f,reactEvent:e}))},[C,f]),ie=(0,o.useCallback)(()=>{C(N5())},[C]),ae=(0,o.useCallback)(()=>{C(P5())},[C]),F=(0,o.useCallback)(e=>{C(M5(e.key))},[C]),oe=(0,o.useCallback)(e=>{C(B5({handler:s,reactEvent:e}))},[C,s]),se=(0,o.useCallback)(e=>{C(B5({handler:c,reactEvent:e}))},[C,c]),ce=(0,o.useCallback)(e=>{C(B5({handler:l,reactEvent:e}))},[C,l]),I=(0,o.useCallback)(e=>{C(B5({handler:p,reactEvent:e}))},[C,p]),le=(0,o.useCallback)(e=>{C(B5({handler:g,reactEvent:e}))},[C,g]),ue=(0,o.useCallback)(e=>{x&&C(G5(e)),C(B5({handler:h,reactEvent:e}))},[C,x,h]),de=(0,o.useCallback)(e=>{C(B5({handler:m,reactEvent:e}))},[C,m]),fe=Ioe(y);return o.createElement(u0.Provider,{value:T},o.createElement(Dre.Provider,{value:O},o.createElement(fe,{width:M??_?.width,height:N??_?.height,className:$A(`recharts-wrapper`,r),style:Coe({position:`relative`,cursor:`default`,width:M,height:N},_),onClick:te,onContextMenu:oe,onDoubleClick:se,onFocus:ie,onBlur:ae,onKeyDown:F,onMouseDown:ce,onMouseEnter:ne,onMouseLeave:P,onMouseMove:re,onMouseUp:I,onTouchEnd:de,onTouchMove:ue,onTouchStart:le,ref:ee},o.createElement(joe,null),n)))}),Roe=[`width`,`height`,`responsive`,`children`,`className`,`style`,`compact`,`title`,`desc`];function zoe(e,t){if(e==null)return{};var n,r,i=Boe(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function Boe(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}var Voe=(0,o.forwardRef)((e,t)=>{var n=e.width,r=e.height,i=e.responsive,a=e.children,s=e.className,c=e.style,l=e.compact,u=e.title,d=e.desc,f=rj(zoe(e,Roe));return l?o.createElement(o.Fragment,null,o.createElement(xz,{width:n,height:r}),o.createElement(n7,{otherAttributes:f,title:u,desc:d},a)):o.createElement(Loe,{className:s,style:c,width:n,height:r,responsive:i??!1,onClick:e.onClick,onMouseLeave:e.onMouseLeave,onMouseEnter:e.onMouseEnter,onMouseMove:e.onMouseMove,onMouseDown:e.onMouseDown,onMouseUp:e.onMouseUp,onContextMenu:e.onContextMenu,onDoubleClick:e.onDoubleClick,onTouchStart:e.onTouchStart,onTouchMove:e.onTouchMove,onTouchEnd:e.onTouchEnd},o.createElement(n7,{otherAttributes:f,title:u,desc:d,ref:t},o.createElement(u8,null,a)))});function l7(){return l7=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},l7.apply(null,arguments)}function u7(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function Hoe(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?u7(Object(n),!0).forEach(function(t){Uoe(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):u7(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function Uoe(e,t,n){return(t=Woe(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Woe(e){var t=Goe(e,`string`);return typeof t==`symbol`?t:t+``}function Goe(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}var Koe=Hoe({accessibilityLayer:!0,barCategoryGap:`10%`,barGap:4,layout:`horizontal`,margin:{top:5,right:5,bottom:5,left:5},responsive:!1,reverseStackOrder:!1,stackOffset:`none`,syncMethod:`index`},Z5),qoe=(0,o.forwardRef)(function(e,t){var n=LM(e.categoricalChartProps,Koe),r=e.chartName,i=e.defaultTooltipEventType,a=e.validateTooltipEventTypes,s=e.tooltipPayloadSearcher,c=e.categoricalChartProps,l={chartName:r,defaultTooltipEventType:i,validateTooltipEventTypes:a,tooltipPayloadSearcher:s,eventEmitter:void 0};return o.createElement(ooe,{preloadedState:{options:l},reduxStoreName:c.id??r},o.createElement(J6,{chartData:c.data}),o.createElement(coe,{layout:n.layout,margin:n.margin}),o.createElement(uoe,{throttleDelay:n.throttleDelay,throttledEvents:n.throttledEvents}),o.createElement(loe,{baseValue:n.baseValue,accessibilityLayer:n.accessibilityLayer,barCategoryGap:n.barCategoryGap,maxBarSize:n.maxBarSize,stackOffset:n.stackOffset,barGap:n.barGap,barSize:n.barSize,syncId:n.syncId,syncMethod:n.syncMethod,className:n.className,reverseStackOrder:n.reverseStackOrder}),o.createElement(Voe,l7({},n,{ref:t})))}),Joe=[`axis`,`item`],Yoe=(0,o.forwardRef)((e,t)=>o.createElement(qoe,{chartName:`BarChart`,defaultTooltipEventType:`axis`,validateTooltipEventTypes:Joe,tooltipPayloadSearcher:g0,categoricalChartProps:e,ref:t})),d7=e=>e.reduce((e,t)=>e+t.count,0),Xoe=e=>{let t=Math.floor(e.length/2),n=d7(e.slice(0,t)),r=d7(e.slice(e.length-t));return n===0?0:(r-n)/n*100},Zoe=({active:e,payload:t,noun:n})=>{let r=t?.[0]?.payload;return!e||!r?null:(0,B.jsxs)(`div`,{className:`rounded-md border bg-background px-2.5 py-1.5 text-xs shadow-pop`,children:[(0,B.jsx)(`div`,{className:`text-muted-foreground`,children:Lf(r.at)}),(0,B.jsxs)(`div`,{className:`font-semibold tabular-nums`,children:[Af(r.count),` `,n]})]})},f7={fontSize:11,fill:`var(--muted-foreground)`},Qoe=({title:e=`Orders created`,noun:t=`orders`,defaultGranularity:n=`day`,data:r,granularity:i,onGranularityChange:a,periodLabel:s,className:c})=>{let[l,u]=(0,o.useState)(n),d=i??l,f=a??u,p=r??BS(d),m=Wu(`(min-width: 640px)`),h=Xoe(p);return(0,B.jsxs)(`section`,{className:z(`rounded-lg border bg-background px-4 pb-2 pt-3`,c),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:`text-[13px] font-semibold`,children:e}),(0,B.jsx)(`span`,{className:`text-[13px] font-semibold tabular-nums`,children:Af(d7(p))}),(0,B.jsxs)(`span`,{className:z(`text-xs font-medium tabular-nums`,h>=0?`text-success-text`:`text-danger-text`),children:[h>=0?`+`:`−`,Math.abs(h).toFixed(1),`%`]}),(0,B.jsx)(`span`,{className:`hidden text-xs text-muted-foreground sm:inline`,children:s??`last ${d===`day`?`30 days`:`12 weeks`}`})]}),(0,B.jsx)(Ed,{value:d,onChange:f,options:[{value:`day`,label:`Day`},{value:`week`,label:`Week`}]})]}),(0,B.jsx)(`div`,{className:`mt-2 h-24`,children:(0,B.jsx)(uz,{width:`100%`,height:`100%`,children:(0,B.jsxs)(Yoe,{data:p,margin:{top:4,right:0,bottom:0,left:0},barCategoryGap:d===`day`?`22%`:`30%`,children:[(0,B.jsx)(B8,{vertical:!1,stroke:`var(--border)`}),(0,B.jsx)(m5,{dataKey:`at`,padding:{left:4,right:m?4:18},tickFormatter:Rf,tick:f7,axisLine:!1,tickLine:!1,interval:d===`day`?m?4:9:m?1:3,height:18}),(0,B.jsx)(y5,{width:m?36:28,tick:f7,axisLine:!1,tickLine:!1,tickCount:3}),(0,B.jsx)($0,{cursor:{fill:`var(--muted)`},content:(0,B.jsx)(Zoe,{noun:t}),isAnimationActive:!1}),(0,B.jsx)(o5,{dataKey:`count`,fill:`var(--primary)`,radius:[2,2,0,0],isAnimationActive:!1})]})})})]})},$oe={"7d":`last 7 days`,"30d":`last 30 days`,"90d":`last 90 days`,"1y":`last year`,all:`all time`},ese=({resource:e,chart:t,title:n,noun:r,filter:i})=>{let[a,s]=(0,o.useState)(t.granularity===`week`?`week`:`day`),c=a===`week`?`90d`:t.range,l=ZA(e,{field:t.field,range:c,granularity:a,filter:i}).data?.points.map(e=>({at:Date.parse(`${e.bucket}Z`),count:e.count}))??[];return(0,B.jsx)(Qoe,{title:n,noun:r,data:l,granularity:a,onGranularityChange:s,periodLabel:a===`week`?`last 12 weeks`:$oe[c]})},tse=({value:e,onCommit:t,placeholder:n,className:r})=>{let[i,a]=(0,o.useState)(e);return(0,o.useEffect)(()=>a(e),[e]),(0,o.useEffect)(()=>{if(i===e)return;let n=setTimeout(()=>t(i),350);return()=>clearTimeout(n)},[i,e,t]),(0,B.jsx)(Yd,{wrapperClassName:z(`min-w-0 flex-1 sm:w-72 sm:flex-initial`,r),leading:(0,B.jsx)(qt,{className:`size-4`}),placeholder:n,"aria-label":`Search`,value:i,onChange:e=>a(e.target.value),onKeyDown:e=>e.key===`Enter`&&t(i)})},p7=(e,t,n,r)=>e.map(e=>{let i=t.fields[e.id],a=i&&_y(r,i,n?.fields[e.id]);return a?{...e,render:t=>(0,B.jsx)(Sy,{shown:a,part:`cell`,field:i,value:t[e.id],fallback:xD(e,e.value?e.value(t):t[e.id])})}:e}),nse=({model:e,view:t,target:n,children:r})=>{let i=mA(e.name,t.listOf,!0),a=t.names?.plural??G(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)(of,{title:a,subtitle:t.help}),e]});if(i.error)return o((0,B.jsx)(ny,{title:`Could not load your ${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)(od,{className:`h-24`},t))}));let s=fA(n,i.data);return s?r(s):o((0,B.jsxs)(`p`,{className:`py-8 text-center text-[13px] text-muted-foreground`,children:[`No `,a.toLowerCase(),` yet.`]}))},m7=so(),rse={start:0,end:0},ise=(e,t,n)=>{let r=Sk(jk(t,e),n);return r.ok?Object.fromEntries(Object.entries(r.state.facets).filter(([t,n])=>e.fields[t]?.type===`relation`&&n.length>0)):{}},ase=(e,t,n)=>{let r=e=>t?.fields[e]?.label??G(e),i=jk(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,Bo(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:Nk(t,e.id)})),toggles:i.toggles?.map(e=>({...e,label:r(e.id)}))}},h7=(e,t,n,r={})=>{let i=ase(e,t,r),a=Sk(i,n);if(!a.ok)return[{key:`unreadable`,label:`A filter that cannot be read`}];let o=a.extras.map((e,t)=>({key:`extra:${t}`,label:e.kind===`search`?`"${e.text}"`:qa(e)}));return[...OO(i,a.state),...o]},ose=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]))}])),sse=(e,t,n)=>{if(typeof n!=`string`||n===``)return e;let r=m7.gt(t,{kind:`timestamp`,value:new Date(n).toISOString(),span:rse}),i=oa(e);if(!i.ok)throw Error(`The saved filter cannot be read: ${i.errors.map(e=>e.message).join(`; `)}`);return qa(i.ast?m7.and(i.ast,r):r)},cse=(e,t)=>typeof t!=`string`||t===``?!0:typeof e!=`string`||e===``?!1:new Date(e).getTime()>new Date(t).getTime(),g7=`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`,_7=({chips:e,className:t})=>(0,B.jsx)(`ul`,{className:z(`flex flex-wrap gap-1.5`,t),"aria-label":`Filters`,children:e.map(e=>(0,B.jsx)(`li`,{className:g7,children:e.label},e.key))}),v7=({chips:e})=>(0,B.jsx)(`span`,{className:`flex flex-wrap gap-1.5`,children:e.map((e,t)=>(0,B.jsxs)(`span`,{className:g7,children:[t>0&&(0,B.jsx)(`span`,{className:`sr-only`,children:`, `}),e.label]},e.key))}),lse=e=>e.map(e=>e.label).join(`, `),y7=({title:e,chips:t,label:n,required:r,initial:i=``,busy:a,onSave:s,onClose:c})=>{let l=(0,o.useId)(),[u,d]=(0,o.useState)(i),f=`${l}-form`;return(0,B.jsx)(Xk,{open:!0,title:e,onClose:c,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(H,{onClick:c,children:`Cancel`}),(0,B.jsx)(H,{type:`submit`,form:f,variant:`primary`,loading:a,children:`Save`})]}),children:(0,B.jsxs)(`form`,{id:f,className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),s(u.trim()===``?null:u.trim())},children:[t.length>0&&(0,B.jsx)(_7,{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 text-[13px]`,children:[(0,B.jsx)(`label`,{htmlFor:l,className:`font-medium`,children:n}),!r&&(0,B.jsx)(`span`,{id:`${l}-hint`,className:`text-xs text-muted-foreground`,children:`Optional`})]}),(0,B.jsx)(Yd,{id:l,value:u,required:r,pattern:r?`.*\\S.*`:void 0,"aria-describedby":r?void 0:`${l}-hint`,autoFocus:!0,autoComplete:`off`,onChange:e=>d(e.target.value)})]})]})})},use=({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)(ny,{title:`Could not load rows`,error:e.error}):e.rows.length===0?(0,B.jsx)(`p`,{className:`py-8 text-center text-[13px] text-muted-foreground`,children:t}):r}),dse=({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(`en-IE`),` of `,e.total.toLocaleString(`en-IE`)]}),e.more&&(0,B.jsx)(H,{size:`sm`,onClick:e.loadMore,children:`Show more`})]}),b7=`grid grid-cols-[repeat(auto-fill,minmax(15rem,1fr))] gap-3`,fse=`flex snap-x snap-mandatory gap-3 overflow-x-auto pb-1`,pse=({model:e,view:t,display:n,list:r,row:i=!1,footer:a=!0})=>{let o=(t?.names?.plural??G(e.name)).toLowerCase();return(0,B.jsxs)(use,{list:r,empty:`No ${o} match.`,loading:(0,B.jsx)(`div`,{className:b7,children:Array.from({length:6},(e,t)=>(0,B.jsx)(od,{className:`h-24`},t))}),children:[(0,B.jsx)(`ul`,{className:i?fse:b7,"aria-label":t?.names?.plural??G(e.name),children:r.rows.map(r=>(0,B.jsx)(`li`,{className:z(i&&`w-64 shrink-0 snap-start`),children:(0,B.jsx)(AA,{model:e,view:t,display:n,row:r,swipe:!i})},r.key))}),a&&(0,B.jsx)(dse,{list:r})]})},mse=({field:e,value:t,known:n})=>{let{resources:r,views:i}=K(),a=W(),o=pm(),s=e.relation?r[e.relation.resource]:void 0,c=String(t),l=kh({queryKey:U.relatedLabel(s?.name??``,c),enabled:!!s&&n===void 0,queryFn:async()=>(await R_(o,a,s,[c],i[s.name])).get(c)??c});return s?(0,B.jsx)(Gv,{to:{kind:`record`,resource:s.name,key:c},className:`font-medium text-primary-text hover:underline`,children:n??l.data??c}):(0,B.jsx)(`span`,{children:c})},hse=({model:e,field:t,value:n,format:r,relationLabel:i})=>{let{views:a}=K(),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)(mse,{field:t,value:n,known:i});let s=t.type===`file`?q_(n):void 0;if(s&&`url`in s&&s.url){let e=tv(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)(py,{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})]})}let c=ov(t,n,o);return t.type===`enum`||o.format===`badge`?(0,B.jsx)(vA,{value:n,hints:o,children:c}):(0,B.jsx)(`span`,{className:z(o.format===`code`&&`font-mono text-xs`,(t.type===`decimal`||t.type===`integer`)&&`tabular-nums`,o.multiline&&`whitespace-pre-line break-words`),children:c})},x7=e=>{let{views:t}=K(),n=vy(e.field,t[e.model.name]?.fields[e.field.name]),r=(0,B.jsx)(hse,{...e});return n?(0,B.jsx)(Sy,{shown:n,part:`display`,field:e.field,value:e.value,fallback:r}):r},S7=(e,t,n)=>{if(!t)return[];let r=Bs(e,t.model.name,n);return r.ok?r.steps:[]},C7=(e,t,n,r,i)=>({queryKey:U.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:U.record(a,String(i)),queryFn:()=>e.get(a,String(i))})).record}return r[i.at(-1).field.name]??null}}),w7=(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}},T7=(e,t)=>{let{resources:n}=K(),r=S7(n,e,t);return w7(e,r,kh(C7(W(),pm(),e,t,r)))},gse=(e,t)=>{let{resources:n}=K(),r=W(),i=pm(),a=t.map(t=>S7(n,e,t)),o=Dh({queries:t.map((t,n)=>C7(r,i,e,t,a[n]))});return t.map((t,n)=>w7(e,a[n],o[n]))},E7=e=>e.includes(`.`),_se=({model:e,row:t,column:n})=>{let r=T7(eA(e,wv(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)(x7,{model:r.model,field:r.field,value:r.value})},vse=(e,t,{resources:n,views:r})=>{let i=Bs(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??G(o),kind:`text`,width:200,render:n=>(0,B.jsx)(_se,{model:e,row:n,column:t})}},yse=(e,t,n,r)=>{let i=new Map(p7(ik(e,t,[],n.filter(e=>!E7(e))),e,t,r.fieldTypes).map(e=>[e.id,e]));return n.flatMap(t=>E7(t)?[vse(e,t,r)]:i.get(t)??[])},bse=`protobase:embedded-display:`,xse=e=>`${bse}${e}`,Sse=(e,t)=>jd(()=>e.getItem(t)??void 0,void 0),Cse=(e,t,n)=>jd(()=>e.setItem(t,n),void 0),wse=(e,t,{picked:n,preferred:r})=>{let i=mv(e).map(e=>e.name);return n!==void 0&&i.includes(n)?n:dv(e,t,r!==void 0&&i.includes(r)?r:void 0)},D7=(e,t,n,{resource:r=e.name,...i})=>jv({kind:`list`,resource:r},i,kv(e,t,n)),Tse=({model:e,filter:t,orderBy:n,limit:r,fields:i})=>{let a=W(),{resources:o,views:s}=K();return kh({queryKey:[...U.list(e.name,t,n,r,`embedded`),i.join(`,`)],placeholderData:Lm,queryFn:async()=>{let c=B_(o,s,e,i),l=cv(s[e.name]),u=await a.search(e.name,{filter:t||void 0,orderBy:n||void 0,pageSize:r,labels:c,photos:l});return V_(o,e,i,lv(e,u.items,u.photos),u.labels).map((t,n)=>({...t,id:jg(e,u.items[n])}))}})},O7=({view:e,value:t,onChange:n})=>(0,B.jsx)(JA,{view:e,value:t,onChange:n,menu:!Gu()}),Ese=()=>(0,B.jsx)(`div`,{className:`flex flex-col gap-2`,children:Array.from({length:3},(e,t)=>(0,B.jsx)(od,{className:`h-4 w-full`},t))}),k7=({model:e,view:t,filter:n,sort:r,columns:i,limit:a,display:s,empty:c,row:l=!1,viewAll:u,link:d=!0})=>{let{resources:f,views:p}=K(),{fields:m}=w_(),{go:h}=Wv(),g=Ku(),[_,v]=(0,o.useState)(r||Tv(e,t)),y=i??rk(e,t),b=(0,o.useMemo)(()=>yse(e,t,y,{resources:f,views:p,fieldTypes:m}),[e,t,y.join(`,`),f,p,m]),x=(0,o.useMemo)(()=>xv(e,t,b.map(e=>e.id)),[e,t,b]),S=Tse({model:e,filter:n,orderBy:_,limit:a,fields:x}),C=S.data,T=(0,o.useMemo)(()=>C&&{total:C.length,rowAt:e=>C[e]},[C]),E=fv(t,s),D=t?.names?.plural??G(e.name),O=d&&(0,B.jsxs)(Gv,{to:D7(e,t,g,u?{filter:u.filter,orderBy:Tv(e,t),display:s,savedSearch:u.savedSearch}:{filter:n,orderBy:_,display:s}),onClick:u?.onOpen,className:`flex items-center gap-1 self-end text-[13px] font-medium text-primary-text hover:underline`,children:[u?u.label:(0,B.jsxs)(B.Fragment,{children:[`View all `,(0,B.jsx)(`span`,{className:`sr-only`,children:D.toLowerCase()})]}),(0,B.jsx)(w,{className:`size-3.5`,"aria-hidden":!0})]});if(S.isPending)return(0,B.jsx)(Ese,{});if(S.error)return(0,B.jsx)(ny,{title:`Could not load`,error:S.error});if(!T||T.total===0){let e=(0,B.jsx)(`p`,{className:`text-[13px] text-muted-foreground`,children:c??`Nothing here yet.`});return u&&d?(0,B.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[e,O]}):e}let k={resource:e.name,rows:S.data.map(t=>wv(e,t)),total:S.data.length,loading:!1,error:null,more:!1,loadMore:()=>void 0},A=t=>h({kind:`record`,resource:e.name,key:Mg(e,t)}),j=t?.names?.singular??G(e.name);return(0,B.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[E?E.kind===`cards`?(0,B.jsx)(pse,{model:e,view:t,display:E,list:k,row:l||g,footer:!1}):E.kind===`map`?(0,B.jsx)(GA,{model:e,view:t,display:E,filter:n,orderBy:_,fields:x,footer:!1}):(0,B.jsx)(qA,{display:E,list:k}):(0,B.jsx)(_O,{fit:!0,columns:b,source:T,latencyMs:0,sort:Ev(_),onSortChange:e=>v(Dv(e)),onOpenRow:A,rowActions:[{label:`Open ${j.toLowerCase()}`,onSelect:A}],rowNumbers:!1,selectable:!1}),O]})},A7=so(),Dse={start:0,end:0},j7=(e,t)=>A7.and(t,{kind:`present`,field:e.field,span:Dse}),M7=e=>{switch(e.kind){case`and`:case`or`:return{...e,args:e.args.map(M7)};case`not`:return N7(e.arg);case`search`:case`present`:case`isNull`:return e;default:return j7(e,e)}},N7=e=>{switch(e.kind){case`and`:return A7.or(...e.args.map(N7));case`or`:return A7.and(...e.args.map(N7));case`not`:return M7(e.arg);case`search`:case`present`:case`isNull`:return A7.not(e);default:return j7(e,A7.not(e))}},P7=e=>{let t=oa(e);if(!t.ok)throw Error(`The filter cannot be read: ${t.errors.map(e=>e.message).join(`; `)}`);return t.ast},F7=(e,t)=>{let n=P7(e);if(!n)return null;let r=P7(t),i=A7.not(M7(n));return qa(r?A7.and(r,i):i)},Ose=(e,t)=>F7(t,e),I7=e=>e.key.startsWith(`extra:`)?`extra:${e.label}`:e.key,kse=(e,t)=>{let n=new Map(e.map(e=>[I7(e),e])),r=new Map(t.map(e=>[I7(e),e])),i=e.filter(e=>!r.has(I7(e))).map(e=>({kind:`removed`,label:e.label})),a=t.flatMap(e=>{let t=n.get(I7(e));return t&&t.label!==e.label?[{kind:`changed`,label:e.label,before:t.label}]:[]}),o=t.filter(e=>!n.has(I7(e))).map(e=>({kind:`added`,label:e.label}));return[...i,...a,...o]},Ase=(e,t,n,r)=>{let i=e-t;return i===0?`As many ${r}`:`${Math.abs(i)} ${i>0?`more`:`fewer`} ${Math.abs(i)===1?n:r}`},L7=(e,t)=>{let n=W(),r=pm(),{resources:i,views:a}=K(),o=a[e.name],s=Object.entries(ise(e,o,t)),c=Dh({queries:s.map(([t,o])=>{let s=i[e.fields[t].relation.resource];return{queryKey:U.labels(`chips:${e.name}.${t}`,o.join(`,`)),enabled:s!==void 0,queryFn:async()=>Object.fromEntries(await R_(r,n,s,o,a[s.name]))}})});return h7(e,o,t,Object.fromEntries(s.flatMap(([e],t)=>c[t]?.data?[[e,c[t].data]]:[])))},R7=12,z7={added:{word:`Added`,className:`text-success-text`},removed:{word:`Removed`,className:`text-danger-text`},changed:{word:`Changed`,className:`text-primary-text`}},jse=({changes:e})=>(0,B.jsx)(`ul`,{"aria-label":`Filter changes`,className:`divide-y rounded-md border text-[13px]`,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 ${z7[e.kind].className}`,children:z7[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}`))}),B7=(e,t)=>{let n=kh({...tA(W(),e,t??``),enabled:t!==null});return t===null?0:n.data},Mse=(e,t,n)=>`${e} ${e===1?t:n}`,V7=({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:`text-[13px] font-semibold`,children:[n,` `,(0,B.jsxs)(`span`,{className:`font-normal text-muted-foreground`,children:[`(`,i??`…`,`)`]})]}),i!==void 0&&i>R7&&(0,B.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`The first `,R7,` of `,i,`.`]}),r===null||i===0?(0,B.jsxs)(`p`,{className:`text-[13px] text-muted-foreground`,children:[`No `,a,`.`]}):(0,B.jsx)(k7,{model:e,view:t,filter:r,sort:Tv(e,t),limit:R7,display:o?.name??`table`,row:!0,link:!1,empty:`No ${a}.`})]})},Nse=({model:e,view:t,title:n,before:r,after:i,saveNewLabel:a,updating:s,creating:c,onUpdate:l,onSaveNew:u,onCancel:d})=>{let f=kse(L7(e,r),L7(e,i)),p=(0,o.useMemo)(()=>F7(r,i),[r,i]),m=(0,o.useMemo)(()=>Ose(r,i),[r,i]),h=B7(e,p),g=B7(e,m),_=(t?.names?.singular??G(e.name)).toLowerCase(),v=(t?.names?.plural??G(e.name)).toLowerCase(),y=h!==void 0&&g!==void 0;return(0,B.jsx)(Xk,{open:!0,wide:!0,title:n,onClose:d,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(H,{onClick:d,children:`Cancel`}),(0,B.jsx)(H,{loading:c,disabled:s,onClick:u,children:a}),(0,B.jsx)(H,{variant:`primary`,loading:s,disabled:c,onClick:l,children:`Update`})]}),children:(0,B.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[f.length>0&&(0,B.jsx)(jse,{changes:f}),y?(0,B.jsxs)(`p`,{className:`text-[13px]`,children:[(0,B.jsx)(`span`,{className:`font-semibold`,children:Ase(h,g,_,v)}),(0,B.jsxs)(`span`,{className:`text-muted-foreground`,children:[`: `,Mse(h,_,v),` added, `,g,` removed`]})]}):(0,B.jsx)(od,{className:`h-4 w-48`}),(0,B.jsx)(V7,{model:e,view:t,title:`Added`,filter:p,total:h,plural:v}),(0,B.jsx)(V7,{model:e,view:t,title:`Removed`,filter:m,total:g,plural:v})]})})},Pse=()=>{let{address:e,set:t}=Wv();return{key:e?.kind===`list`?e.savedSearch:void 0,open:e=>t({savedSearch:e})}},Fse=e=>U.list(e,``,``,500,`saved-searches`),H7=(e,t)=>{let n=W(),{resources:r,views:i}=K(),a=r[e];return kh({queryKey:Fse(e),enabled:t&&a!==void 0,queryFn:async()=>{let t=[],r;do{let o=await n.list(e,{pageSize:500,orderBy:Tv(a,i[e]),...r&&{pageToken:r}});t.push(...o.items),r=o.nextPageToken||void 0}while(r);return t}})},U7=e=>e instanceof Error?e.message:`Something went wrong`,Ise=(e,t)=>{let n=K(),r=W(),i=Kg(),a=aA(),{href:o,open:s}=Wv(),c=Pse(),{resource:l}=e,u=n.resources[l],d=n.views[l]?.searchesOf,f=n.permissions[l],p=u!==void 0&&d!==void 0&&f!==void 0&&Ey(f,`create`)&&Ey(f,`delete`),m=n.signIn?.[l]?.signIn,h=H7(l,p),g=e=>mo(Mg(u,e)),_=d&&h.data?.find(e=>e[d.filter]===t),v=_||c.key===void 0||!f||!Ey(f,`update`)?void 0:h.data?.find(e=>g(e)===c.key),y=n.views[l]?.names,b=y?.plural??`saved searches`,x=d?.name===void 0?void 0:u?.fields[d.name],S=Ah({mutationFn:e=>r.create(l,{[d.filter]:t,...d.name&&{[d.name]:e}}),onSuccess:e=>{c.open(g(e.record)),i.show({state:`success`,title:`Search saved`,action:{label:`Open ${b.toLowerCase()}`,href:o({kind:`list`,resource:l}),onNavigate:s}})},onError:e=>i.show({state:`error`,title:`Could not save the search`,description:U7(e)}),onSettled:()=>a(l)}),C=Ah({mutationFn:e=>r.remove(l,g(e)),onError:e=>i.show({state:`error`,title:`Could not take the search off`,description:U7(e)}),onSettled:()=>a(l)}),w=Ah({mutationFn:e=>r.update(l,g(e),{[d.filter]:t},e.etag??`*`),onSuccess:()=>i.show({state:`success`,title:`Search updated`}),onError:e=>i.show({state:`error`,title:`Could not update the search`,description:U7(e)}),onSettled:()=>a(l)}),T=S.isPending||C.isPending||w.isPending;return{mode:p?`save`:m?`sign-in`:void 0,prompt:m,saved:_!==void 0,opened:v&&{filter:String(v[d.filter]??``),name:d.name&&typeof v[d.name]==`string`&&v[d.name]!==``?String(v[d.name]):void 0},noun:(y?.singular??G(l)).toLowerCase(),naming:x&&{label:n.views[l]?.fields[x.name]?.label??G(x.name),required:!x.nullable},ready:h.data!==void 0&&!T,updating:w.isPending,creating:S.isPending,remove:()=>_&&C.mutate(_),saveNew:(e,t)=>S.mutate(e,t),update:e=>v&&w.mutate(v,e)}},Lse=({model:e,view:t,search:n,filter:r,chips:i,className:a})=>{let s=Ise(n,r),[c,l]=(0,o.useState)(!1),[u,d]=(0,o.useState)(!1),[f,p]=(0,o.useState)();if(!s.mode)return null;let m=n.label??`Save search`;if(s.mode===`sign-in`)return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(H,{className:a,"aria-haspopup":`dialog`,onClick:()=>l(!0),children:[(0,B.jsx)(re,{className:`size-3.5`,"aria-hidden":!0}),m]}),(0,B.jsx)($k,{as:`dialog`,prompt:s.prompt,open:c,onClose:()=>l(!1)})]});let h=e=>{d(!1),s.naming?p(e):s.saveNew(null)},g=f!==void 0&&s.naming&&(0,B.jsx)(y7,{title:f,chips:i,label:s.naming.label,required:s.naming.required,busy:s.creating,onSave:e=>s.saveNew(e,{onSuccess:()=>p(void 0)}),onClose:()=>p(void 0)}),_=s.opened;if(_){let n=`Save as new ${s.noun}`;return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(H,{className:a,"aria-haspopup":`dialog`,"aria-disabled":!s.ready,onClick:()=>s.ready&&d(!0),children:[(0,B.jsx)(Ut,{className:`size-3.5`,"aria-hidden":!0}),(0,B.jsx)(`span`,{className:`max-w-60 truncate`,children:_.name?`Update ${_.name}`:`Update ${s.noun}`})]}),(0,B.jsxs)(H,{className:a,"aria-haspopup":s.naming?`dialog`:void 0,"aria-disabled":!s.ready,onClick:()=>s.ready&&h(n),children:[(0,B.jsx)(ne,{className:`size-3.5`,"aria-hidden":!0}),n]}),u&&(0,B.jsx)(Nse,{model:e,view:t,title:_.name?`Update ${_.name}?`:`Update this ${s.noun}?`,before:_.filter,after:r,saveNewLabel:n,updating:s.updating,creating:s.creating,onUpdate:()=>s.update({onSuccess:()=>d(!1)}),onSaveNew:()=>h(n),onCancel:()=>d(!1)}),g]})}let v=s.saved?ee:re;return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(H,{className:a,"aria-pressed":s.saved,"aria-haspopup":!s.saved&&s.naming?`dialog`:void 0,"aria-disabled":!s.ready,onClick:()=>s.ready&&(s.saved?s.remove():h(m)),children:[(0,B.jsx)(v,{className:s.saved?`size-3.5 text-primary`:`size-3.5`,"aria-hidden":!0}),m]}),g]})},W7=268,G7=3,K7=(e,t,n)=>{let r=Math.floor(Math.max(0,e)/W7),i=Math.ceil((Math.max(0,e)+t)/W7);return{start:Math.max(0,r-G7),end:Math.min(n,i+G7)}},q7=e=>e*W7,Rse=e=>{let t=(0,o.useRef)(null),[n,r]=(0,o.useState)({left:0,width:0});(0,o.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]=[K7(t.left,t.width,e),K7(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,q7(e)-12),a=e=>t.current?.scrollBy({left:e*Math.max(q7(1),n.width-12),behavior:`smooth`});return{ref:t,...K7(n.left,n.width,e),back:n.left>0,on:n.left+n.width<i-1,page:a}},J7=`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`,Y7=({cards:e})=>e>0?(0,B.jsx)(`li`,{"aria-hidden":!0,className:`shrink-0`,style:{width:q7(e)-12}}):null,zse=({model:e,view:t,display:n,source:r,label:i,isNew:a})=>{let{total:o}=r,s=Rse(o),c=tO({total:o,rowAt:r.rowAt,loadRows:r.loadRows,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:`flex snap-x gap-3 overflow-x-auto overflow-y-hidden pb-1`,style:{scrollbarWidth:`thin`},children:[(0,B.jsx)(Y7,{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)(od,{className:`h-full min-h-24 rounded-lg`})},`skeleton-${r}`);let s=wv(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)(AA,{model:e,view:t,display:n,row:s,swipe:!1,mark:a?.(s)?`New`:void 0})},s.key)}),(0,B.jsx)(Y7,{cards:o-s.end})]}),s.back&&(0,B.jsx)(`button`,{type:`button`,"aria-label":`Previous ${i.toLowerCase()}`,onClick:()=>s.page(-1),className:`${J7} -left-3`,children:(0,B.jsx)(he,{className:`size-4`,"aria-hidden":!0})}),s.on&&(0,B.jsx)(`button`,{type:`button`,"aria-label":`Next ${i.toLowerCase()}`,onClick:()=>s.page(1),className:`${J7} -right-3`,children:(0,B.jsx)(_e,{className:`size-4`,"aria-hidden":!0})})]})},Bse=so(),Vse=(e,t)=>{if(!t)return e;let n=oa(e);if(!n.ok)throw Error(`The filter cannot be read: ${n.errors.map(e=>e.message).join(`; `)}`);return qa(n.ast?Bse.and(n.ast,t):t)},Hse=(e,t)=>{let n=uv(e).filter(e=>e.kind===`cards`);return n.find(e=>e.name===t)??n[0]??{kind:`cards`,name:`cards`}},Use=()=>(0,B.jsx)(`div`,{className:`flex gap-3 overflow-hidden`,children:Array.from({length:3},(e,t)=>(0,B.jsx)(od,{className:`h-24 w-64 shrink-0`},t))}),X7=({model:e,view:t,filter:n,sort:r=``,display:i,limit:a,chips:s=!0,empty:c,note:l,isNew:u,viewAll:d,scope:f,list:p})=>{let{resources:m,views:h}=K(),g=Ku(),_=Hse(t,i),v=r||Tv(e,t),y=Rk({resources:m,views:h,model:e,columns:(0,o.useMemo)(()=>xv(e,t,[]),[e,t]),filter:(0,o.useMemo)(()=>Vse(n,f),[n,f]),orderBy:v}),b=L7(e,n),x=(t?.names?.singular??G(e.name)).toLowerCase(),S=t?.names?.plural??G(e.name),C=y.source?.total,T=(0,o.useMemo)(()=>y.source&&{...y.source,total:Math.min(y.source.total,a??1/0)},[y.source,a]);return(0,B.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3`,children:[s&&b.length>0||C!==void 0||l?(0,B.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[s&&b.length>0?(0,B.jsx)(_7,{chips:b}):(0,B.jsx)(`span`,{}),(0,B.jsxs)(`p`,{className:`flex flex-wrap gap-x-3 text-[13px] text-muted-foreground`,children:[l&&(0,B.jsx)(`span`,{children:l}),C!==void 0&&(0,B.jsx)(`span`,{className:`tabular-nums`,children:`${C.toLocaleString(`en-GB`)} ${C===1?x:S.toLowerCase()}`})]})]}):null,y.isLoading?(0,B.jsx)(Use,{}):y.error?(0,B.jsx)(ny,{title:`Could not load`,error:y.error}):!T||T.total===0?(0,B.jsx)(`p`,{className:`text-[13px] text-muted-foreground`,children:c??`No ${S.toLowerCase()} match.`}):(0,B.jsx)(zse,{model:e,view:t,display:_,source:T,label:S,isNew:u}),(0,B.jsxs)(Gv,{to:D7(e,t,g,{filter:n,orderBy:v,display:_.name,savedSearch:d?.savedSearch,resource:p}),onClick:d?.onOpen,className:`flex items-center gap-1 self-end text-[13px] font-medium text-primary-text hover:underline`,children:[d?.label??(0,B.jsxs)(B.Fragment,{children:[`View all `,(0,B.jsx)(`span`,{className:`sr-only`,children:S.toLowerCase()})]}),(0,B.jsx)(w,{className:`size-3.5`,"aria-hidden":!0})]})]})},Wse=e=>e instanceof Error?e.message:`Something went wrong`,Gse=({model:e,view:t,name:n,value:r,onChange:i})=>{let a=(0,o.useId)(),s=e.fields[n],c=t.fields[n],l=c?.label??G(n);if(s?.type===`boolean`)return(0,B.jsx)(H_,{checked:r===!0,onChange:i,label:l});if(s?.type!==`enum`)throw Error(`Not implemented: "${n}" is ${s?.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-[13px] text-muted-foreground`,children:[l,(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-[13px] text-foreground shadow-sm focus:border-primary focus:outline-none focus:ring-2 focus:ring-primary/20`,children:(s.enumValues??[]).map(e=>(0,B.jsx)(`option`,{value:e,children:Bo(e,c?.valueLabels)},e))})]})},Kse=(e,t,n)=>Object.entries(n).map(([n,r])=>`${t.fields[n]?.label??G(n)}: ${e.fields[n]?.type===`boolean`?r===!0?`On`:`Off`:Bo(String(r),t.fields[n]?.valueLabels)}`).join(`, `),qse=({model:e,view:t,recordKey:n,title:r,row:i,fields:a})=>{let o=W(),s=Kg(),c=aA(),l=Ah({mutationFn:t=>o.update(e.name,n,t,i.etag??`*`),onSuccess:(n,i)=>s.show({state:`success`,title:`${r} saved`,description:Kse(e,t,i)}),onError:e=>s.show({state:`error`,title:`Could not change the search`,description:Wse(e)}),onSettled:()=>c(e.name)});return(0,B.jsx)(`div`,{className:`flex flex-wrap items-center gap-3`,children:a.map(n=>(0,B.jsx)(Gse,{model:e,view:t,name:n,value:l.isPending&&n in(l.variables??{})?l.variables[n]:i[n],onChange:e=>l.mutate({[n]:e})},n))})},Z7=({model:e,of:t,target:n,targetView:r,row:i,recordKey:a})=>{let o=W(),s=aA(),c=String(i[t.filter]??``),l=L7(n,c),u=t.name===void 0?void 0:i[t.name],d=typeof u==`string`&&u!==``?u:void 0,f=t.unseen,p=Ah({mutationFn:t=>o.update(e.name,a,{[f.seenAt]:t},i.etag??`*`),onSettled:()=>s(e.name)}),m=kh({...tA(o,n,f?sse(c,f.field,i[f.seenAt]):``),enabled:f!==void 0}),h=(r?.names?.plural??G(n.name)).toLowerCase(),g={model:n,view:r,filter:c,sort:f?`${f.field} desc`:void 0,limit:t.limit,chips:d!==void 0,empty:`No ${h} match.`,note:f&&m.data===0&&`No new ${h} since you last looked.`,isNew:f&&(e=>cse(e.record[f.field],i[f.seenAt])),viewAll:{label:`View all results`,savedSearch:a,...f&&{onOpen:()=>p.mutate(new Date().toISOString())}}};return{name:d,chips:l,title:d??lse(l),body:g}},Jse=e=>e instanceof Error?e.message:`Something went wrong`,Yse=({model:e,view:t,of:n,target:r,targetView:i,row:a,recordKey:s,canRename:c,onDelete:l})=>{let u=W(),d=Kg(),f=aA(),[p,m]=(0,o.useState)(!1),{name:h,chips:g,title:_,body:v}=Z7({model:e,of:n,target:r,targetView:i,row:a,recordKey:s}),y=Ah({mutationFn:t=>u.update(e.name,s,{[n.name]:t},a.etag??`*`),onSuccess:()=>m(!1),onError:e=>d.show({state:`error`,title:`Could not rename the search`,description:Jse(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-[15px] font-semibold`,children:(0,B.jsx)(Gv,{to:{kind:`record`,resource:e.name,key:s},className:`hover:underline`,children:h??(0,B.jsx)(v7,{chips:g})})})}),(0,B.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[n.controls&&(0,B.jsx)(qse,{model:e,view:t,recordKey:s,title:_,row:a,fields:n.controls}),c&&b&&(0,B.jsx)(H,{variant:`ghost`,"aria-label":`Rename ${_}`,"aria-haspopup":`dialog`,onClick:()=>m(!0),children:(0,B.jsx)(Ft,{className:`size-3.5`,"aria-hidden":!0})}),l&&(0,B.jsx)(H,{variant:`ghost`,"aria-label":`Delete ${_}`,onClick:()=>l(_),children:(0,B.jsx)(yn,{className:`size-3.5`,"aria-hidden":!0})})]})]}),p&&b&&(0,B.jsx)(y7,{title:`Rename ${_}`,chips:g,label:t.fields[b.name]?.label??G(b.name),required:!b.nullable,initial:h,busy:y.isPending,onSave:e=>y.mutate(e),onClose:()=>m(!1)}),(0,B.jsx)(X7,{...v})]})},Xse=({model:e,view:t})=>{let{resources:n,views:r}=K(),i=t.searchesOf,a=n[i.resource],o=r[i.resource],s=H7(e.name,!0),c=Uv(e.name),l=Kk({model:e,view:t}),u=t.names?.plural??G(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)(of,{title:u,subtitle:t.help}),e]});if(!a)return d((0,B.jsxs)(Bv,{title:`Not found`,children:[`There is no resource called `,i.resource,`.`]}));if(s.error)return d((0,B.jsx)(ny,{title:`Could not load your ${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)(od,{className:`h-56`},t))}));if(s.data.length===0){let e=(o?.names?.plural??G(a.name)).toLowerCase();return d((0,B.jsxs)(`p`,{className:`py-8 text-center text-[13px] text-muted-foreground`,children:[`No `,u.toLowerCase(),` yet. Filter the`,` `,(0,B.jsx)(Gv,{to:{kind:`list`,resource:a.name},className:`font-medium text-primary-text hover:underline`,children:e}),` `,`and save the search.`]}))}return d((0,B.jsx)(`div`,{className:`flex flex-col gap-4`,children:s.data.map(n=>{let r=mo(Mg(e,n)),s=Ey(c,`delete`)?e=>void l.start({key:r,title:e,etag:n.etag,snapshot:n}):void 0;return(0,B.jsx)(Yse,{model:e,view:t,of:i,target:a,targetView:o,row:n,recordKey:r,canRename:Ey(c,`update`),onDelete:s},r)})}))},Zse=so(),Qse=e=>e.find(e=>e.kind===`search`),$se=({address:e})=>{let{resources:t,views:n,signIn:r}=K(),i=t[e.resource],a=r?.[e.resource];if(!i)return a?(0,B.jsx)($k,{as:`page`,prompt:a.signIn}):(0,B.jsxs)(Bv,{title:`Not found`,children:[`There is no resource called `,e.resource,`.`]});let o=n[e.resource];if(o?.searchesOf)return(0,B.jsx)(Xse,{model:i,view:o});let s=Ov(t,n,e.resource);if(o&&s.listOf){let t=s.model;return(0,B.jsx)(nse,{model:i,view:o,target:t,children:n=>(0,B.jsx)(Q7,{model:t,address:e,scope:n,heading:{title:o.names?.plural??G(i.name),subtitle:o.help}})})}return(0,B.jsx)(Q7,{model:i,address:e})},Q7=({model:e,address:t,scope:n,heading:r})=>{let i=K(),{set:a,go:s}=Wv(),c=e.name,l=i.views[c],u=(0,o.useMemo)(()=>jk(l,e),[l,e]),{fields:d}=w_(),f=(0,o.useMemo)(()=>p7(ik(e,l),e,l,d),[e,l,d]),p=t.filter,m=(0,o.useMemo)(()=>Sk(u,p),[u,p]),h=m.ok?m.state:CO,g=m.ok?m.extras:[],{orderBy:_,filterLayout:v}=t,y=Gu(),[b,x]=(0,o.useState)(!1),S=n?[...g,n]:g,C=Fk({model:e,resources:i.resources,views:i.views,view:l,state:h,extras:S}),w=n?hk(u,h,S):m.ok?p:``,T=(0,o.useMemo)(()=>xv(e,l,f.map(e=>e.id)),[e,l,f]),E=Rk({resources:i.resources,views:i.views,model:e,columns:T,filter:w,orderBy:_}),D=fv(l,t.display),O=D?.kind!==`map`;nd(O);let k=rre(e,E.page,E.key,D?.kind===`custom`),A=ire(),j=kg(e,l),M=e=>({key:e.id,title:String(typeof e[j]==`object`?e[j].name:e[j]??e.id),etag:typeof e.etag==`string`?e.etag:void 0,snapshot:e}),N=l?.names?.singular??G(c),ee=Uv(c),{state:te}=V(),ne=Kk({model:e,view:l,restore:qk(e),onReview:e=>s({kind:`record`,resource:c,key:e.key})}),P=(e,t=g)=>a({filter:hk(u,e,t)}),re=Qse(g),ie=e=>{let t=g.filter(e=>e.kind!==`search`);P(h,e?[...t,Zse.search(e)]:t)},ae=l?.names?.plural??G(c),F=D&&(0,B.jsx)(YA,{model:e,view:l,display:D,orderBy:_,onChange:e=>a({orderBy:e})}),oe=e.search?.length?(0,B.jsx)(tse,{value:re?.kind===`search`?re.text:``,onCommit:ie,placeholder:`Search ${ae.toLowerCase()}`,className:y?void 0:`min-h-11`}):null,se=(0,B.jsx)(qO,{layout:v,config:C,value:h,onChange:P,leading:v===`bar`?F:void 0,trailing:oe}),ce=v===`bar`?se:(0,B.jsx)(GO,{groups:[F?[F]:[]],trailing:oe}),I=OO(C,h),le=(0,B.jsx)(yO,{scroll:!0,chips:I,onRemove:e=>P(kO(h,e)),onClear:()=>P(CO)}),ue=D&&(0,B.jsx)(IO,{title:`Sort`,children:(0,B.jsx)(YA,{model:e,view:l,display:D,orderBy:_,onChange:e=>a({orderBy:e}),className:`min-h-11 w-full`})}),de=(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)(H,{className:`min-h-11`,onClick:()=>x(!0),"aria-haspopup":`dialog`,children:[(0,B.jsx)(an,{className:`size-3.5`}),`Filters`,I.length>0&&` (${I.length})`]}),oe??(0,B.jsx)(`div`,{className:`min-w-0 flex-1`,children:le})]}),oe&&le,(0,B.jsx)(zk,{title:`Filters`,open:b,onClose:()=>x(!1),children:(0,B.jsx)(qO,{layout:`panel`,fullWidth:!0,config:C,value:h,onChange:P,leading:ue})})]}),fe=!n&&Ey(ee,`create`)&&(0,B.jsxs)(H,{variant:`primary`,onClick:()=>s({kind:`create`,resource:c}),children:[(0,B.jsx)(Lt,{className:`size-3.5`}),`New `,N.toLowerCase()]}),pe=l?.saveSearch&&!n&&m.ok&&p&&(0,B.jsx)(Lse,{model:e,view:l,search:l.saveSearch,filter:p,chips:h7(e,l,p,ose(C))}),me=e=>(0,B.jsx)(JA,{view:l,value:D?.name??`table`,onChange:e=>a({display:e}),menu:e}),he=t=>s({kind:`record`,resource:c,key:Mg(e,t)}),ge=E.source?(0,B.jsx)(_O,{columns:f,source:E.source,sort:Ev(_),onSortChange:e=>a({orderBy:Dv(e)}),onOpenRow:he,initialScrollIndex:A.initialIndex,onScrollIndex:A.remember,rowActions:[{label:`Open ${N.toLowerCase()}`,onSelect:he},...Ey(ee,`delete`)?[{label:`Delete`,destructive:!0,available:e=>Dy(e,`delete`),onSelect:e=>void ne.start(M(e))}]:[]],bulkActions:Ey(ee,`delete`)?[{label:e=>`Delete ${e}`,destructive:!0,onRun:e=>ne.startBulk(e.map(M))}]:[],rowNumbers:!1,pinKey:te.kind===`signed-in`?RD(te.user.id,c):void 0,scroll:`parent`,className:`flex-1`}):(0,B.jsx)(`div`,{className:`flex-1 rounded-lg border bg-surface`}),_e={...E,initialIndex:A.initialIndex,onScrollIndex:A.remember},ve=D?D.kind===`cards`?(0,B.jsx)(jne,{model:e,view:l,display:D,list:_e},E.key.join(` `)):D.kind===`map`?(0,B.jsx)(GA,{model:e,view:l,display:D,filter:w,orderBy:_,fields:T,at:t.map,onMove:e=>a({map:e}),flush:!0}):(0,B.jsx)(qA,{display:D,list:k}):ge;return(0,B.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 px-5 py-4`,children:[ne.dialogs,(0,B.jsx)(of,{title:r?.title??ae,subtitle:r?r.subtitle:l?.help,aside:!y&&me(!0),actions:y?(0,B.jsxs)(B.Fragment,{children:[me(!1),pe,fe]}):(0,B.jsxs)(B.Fragment,{children:[pe,fe]})}),!m.ok&&(0,B.jsx)(ny,{title:`The filter in the address could not be read`,error:Error(m.errors.map(e=>e.message).join(`; `))}),E.error&&!D&&(0,B.jsx)(ny,{title:`Could not load rows`,error:E.error}),l?.chart&&(0,B.jsx)(ese,{resource:c,chart:l.chart,title:`${ae} created`,noun:ae.toLowerCase(),filter:w}),y?ce:de,y&&v===`panel`?(0,B.jsxs)(`div`,{className:`flex min-h-0 flex-1 gap-4`,children:[(0,B.jsx)(`div`,{className:O?`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:se}),ve]}):ve]})},$7=({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.filter(e=>e.membership).map(e=>{let a=t.includes(e.name),o=r||!n.has(e.name);return(0,B.jsxs)(`label`,{title:o&&!r?`You cannot give or take away this role`:void 0,className:z(`inline-flex items-center gap-1.5 text-[13px]`,o&&`text-muted-foreground`),children:[(0,B.jsx)(Yh,{checked:a,label:e.label,onChange:o?void 0:n=>i(n?[...t,e.name]:t.filter(t=>t!==e.name)),className:z(o&&`cursor-default opacity-60`)}),e.label]},e.name)})}),e9=e=>e?.role===`owner`?[`owner`,`admin`,`member`]:[`admin`,`member`],ece=({member:e,current:t,onChanged:n})=>{let{session:r,organizations:i}=V(),a=t.organization.id,{busy:o,error:s,run:c}=fg(),l=i?.roles??[],u=e.id===t.memberId,d=e9(t),f=e.role===`owner`&&t.role!==`owner`;return(0,B.jsxs)(`li`,{className:`flex flex-col gap-2 px-3 py-3`,children:[(0,B.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,B.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,B.jsxs)(`span`,{className:`block truncate text-[13px] font-medium`,children:[e.name,u&&` (you)`]}),(0,B.jsx)(`span`,{className:`block truncate text-xs text-muted-foreground`,children:e.email})]}),(0,B.jsx)(`select`,{"aria-label":`Organization role of ${e.name}`,value:e.role,disabled:o||f,onChange:t=>void c(async()=>{await r.organizations.setRole(a,e.id,t.target.value),n()}),className:`h-7 rounded-md border border-border-strong bg-background px-2 text-xs`,children:(f?[e.role]:d).map(e=>(0,B.jsx)(`option`,{value:e,children:sg[e]},e))}),!u&&(0,B.jsx)(H,{size:`sm`,variant:`danger`,loading:o,disabled:f,onClick:()=>void c(async()=>{await r.organizations.removeMember(a,e.id),n()}),children:`Remove`})]}),(0,B.jsx)($7,{roles:l,selected:e.appRoles,grantable:dg(l,t),disabled:o,onChange:t=>void c(async()=>{await r.organizations.setAppRoles(e.id,t),n()})}),(0,B.jsx)(Jf,{message:s})]})},tce=({current:e})=>{let{session:t}=V(),[n,r]=(0,o.useState)(),[i,a]=(0,o.useState)(),s=e?.organization?.id,c=(0,o.useCallback)(()=>{s&&t.organizations.members(s).then(r,e=>a(e instanceof Ks?df(e):`Could not read the members`))},[t,s]);return(0,o.useEffect)(c,[c]),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)(of,{title:`Members`,subtitle:`Who works in ${e.organization.name}, and with which roles.`}),(0,B.jsxs)(qf,{title:`Members`,description:`Owners and admins manage the organization; app roles decide what each member sees and does in the app.`,children:[(0,B.jsx)(Jf,{message:i}),n?(0,B.jsx)(`ul`,{className:`divide-y rounded-md border`,children:n.map(t=>(0,B.jsx)(ece,{member:t,current:e,onChanged:c},`${t.id}/${t.role}/${t.appRoles.join()}`))}):!i&&(0,B.jsxs)(`div`,{className:`flex items-center gap-2 text-[13px] text-muted-foreground`,children:[(0,B.jsx)(Zd,{}),` Loading`]})]})]}):null},t9=({link:e})=>e?(0,B.jsxs)(`p`,{className:`mt-3 break-all rounded-md border bg-muted px-3 py-2 text-xs`,children:[`This app cannot send email, so pass this link on yourself. It works once, until the invitation expires: `,(0,B.jsx)(`span`,{className:`font-mono`,children:e})]}):null,nce=({current:e,onSent:t})=>{let{session:n,organizations:r}=V(),i=r?.roles??[],[a,s]=(0,o.useState)(``),[c,l]=(0,o.useState)(`member`),[u,d]=(0,o.useState)([]),[f,p]=(0,o.useState)(),{busy:m,error:h,run:g}=fg(),_=()=>g(async()=>{let r=await n.organizations.invite(e.organization.id,{email:a.trim(),role:c,appRoles:u});p(r.link),s(``),d([]),t()});return(0,B.jsxs)(qf,{title:`Invite someone`,description:`They get an email with a link to join, or to make an account first. You can give the app roles you hold, and those your roles grant.`,children:[(0,B.jsx)(Jf,{message:h}),(0,B.jsxs)(`form`,{className:`flex flex-col gap-3`,onSubmit:e=>{e.preventDefault(),_()},children:[(0,B.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,B.jsx)(Yd,{"aria-label":`Email`,type:`email`,placeholder:`name@example.com`,value:a,onChange:e=>s(e.target.value),wrapperClassName:`flex-1`}),(0,B.jsx)(`select`,{"aria-label":`Organization role`,value:c,onChange:e=>l(e.target.value),className:`h-8 rounded-md border border-border-strong bg-background px-2 text-[13px]`,children:e9(e).map(e=>(0,B.jsx)(`option`,{value:e,children:sg[e]},e))}),(0,B.jsx)(H,{type:`submit`,variant:`primary`,loading:m,disabled:!a.trim(),children:`Invite`})]}),(0,B.jsx)($7,{roles:i,selected:u,grantable:dg(i,e),onChange:d})]}),(0,B.jsx)(t9,{link:f})]})},rce=({invitation:e,organizationId:t,onChanged:n})=>{let{session:r,organizations:i}=V(),[a,s]=(0,o.useState)(),{busy:c,error:l,run:u}=fg(),d=new Date(e.expiresAt).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 text-[13px] font-medium`,children:e.email}),(0,B.jsxs)(`span`,{className:`block text-xs text-muted-foreground`,children:[sg[e.role],e.appRoles.length>0&&` · ${e.appRoles.map(e=>cg(i?.roles??[],e)).join(`, `)}`,` · `,d?`Expired`:`Until ${new Date(e.expiresAt).toLocaleDateString()}`]})]}),(0,B.jsx)(H,{size:`sm`,loading:c,onClick:()=>void u(async()=>{s((await r.organizations.resend(t,e)).link),n()}),children:`Send again`}),(0,B.jsx)(H,{size:`sm`,variant:`danger`,loading:c,onClick:()=>void u(async()=>{await r.organizations.revoke(e.id),n()}),children:`Revoke`})]}),(0,B.jsx)(Jf,{message:l}),(0,B.jsx)(t9,{link:a})]})},ice=({current:e})=>{let{session:t}=V(),[n,r]=(0,o.useState)([]),i=e?.organization?.id,a=(0,o.useCallback)(()=>{i&&t.organizations.invitations(i).then(e=>r(e.filter(e=>e.status===`pending`)),()=>r([]))},[t,i]);return(0,o.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)(of,{title:`Invitations`,subtitle:`People invited to ${e.organization.name}.`}),(0,B.jsx)(nce,{current:e,onSent:a}),(0,B.jsx)(qf,{title:`Not accepted yet`,description:n.length>0?`Sending again gives a new link, which replaces the earlier one.`:`Nobody is waiting.`,children:n.length>0&&(0,B.jsx)(`ul`,{className:`divide-y rounded-md border`,children:n.map(e=>(0,B.jsx)(rce,{invitation:e,organizationId:i,onChanged:a},e.id))})})]})},ace=e=>{let{session:t}=V(),[n,r]=(0,o.useState)(),[i,a]=(0,o.useState)([]),[s,c]=(0,o.useState)(),[l,u]=(0,o.useState)(0),d=(0,o.useCallback)(()=>u(e=>e+1),[]);return(0,o.useEffect)(()=>{e&&Promise.all([t.organizations.current(),t.organizations.list()]).then(([e,t])=>{r(e),a(t)},e=>c(e instanceof Ks?df(e):`Could not read your organizations`))},[e,t,l]),{current:n,organizations:i,...s&&{error:s},reload:d}},n9=e=>window.location.assign(`${e}/`),oce=({organization:e,editable:t,onSaved:n})=>{let{session:r}=V(),[i,a]=(0,o.useState)(e.name),[s,c]=(0,o.useState)(e.slug),{busy:l,error:u,run:d}=fg(),f=i.trim()!==e.name||s!==e.slug;return(0,B.jsxs)(qf,{title:`Details`,description:t?`The name people see, and the slug that names it in links.`:`Owners and admins can change these.`,children:[(0,B.jsx)(Jf,{message:u}),(0,B.jsxs)(`form`,{className:`flex flex-col gap-2 sm:flex-row`,onSubmit:t=>{t.preventDefault(),d(async()=>{await r.organizations.rename(e.id,{name:i.trim(),slug:s}),n()})},children:[(0,B.jsx)(Yd,{"aria-label":`Name`,value:i,disabled:!t,onChange:e=>a(e.target.value),wrapperClassName:`flex-1`}),(0,B.jsx)(Yd,{"aria-label":`Slug`,value:s,disabled:!t,onChange:e=>c(e.target.value),wrapperClassName:`sm:w-48`}),t&&(0,B.jsx)(H,{type:`submit`,variant:`primary`,loading:l,disabled:!f||!i.trim(),children:`Save`})]})]})},sce=({organization:e,memberId:t})=>{let{session:n}=V(),[r,i]=(0,o.useState)([]),[a,s]=(0,o.useState)(``),{busy:c,error:l,run:u}=fg();return(0,o.useEffect)(()=>{n.organizations.members(e.id).then(e=>i(e.filter(e=>e.id!==t)),()=>i([]))},[n,e.id,t]),(0,B.jsxs)(qf,{title:`Hand over`,description:`Make another member the owner. You stay as an admin.`,children:[(0,B.jsx)(Jf,{message:l}),(0,B.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,B.jsxs)(`select`,{"aria-label":`New owner`,value:a,onChange:e=>s(e.target.value),className:`h-8 flex-1 rounded-md border border-border-strong bg-background px-2 text-[13px]`,children:[(0,B.jsx)(`option`,{value:``,children:`Choose a member`}),r.map(e=>(0,B.jsxs)(`option`,{value:e.id,children:[e.name,` (`,e.email,`)`]},e.id))]}),(0,B.jsx)(H,{loading:c,disabled:!a,onClick:()=>void u(async()=>{await n.organizations.transferOwnership(a),window.location.reload()}),children:`Hand over`})]})]})},cce=({organization:e,basePath:t})=>{let{session:n}=V(),[r,i]=(0,o.useState)(!1),[a,s]=(0,o.useState)(``),{busy:c,error:l,run:u}=fg(),d=()=>u(async()=>{await n.organizations.remove(e.id),n9(t)});return(0,B.jsxs)(qf,{title:`Delete organization`,description:`Takes the organization and its members and invitations away. Its records must be deleted first.`,children:[(0,B.jsx)(Jf,{message:r?void 0:l}),(0,B.jsx)(H,{variant:`danger`,onClick:()=>i(!0),children:`Delete organization`}),r&&(0,B.jsxs)(Kf,{title:`Delete ${e.name}?`,description:`Type its name to confirm. This cannot be undone.`,onClose:()=>i(!1),actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(H,{onClick:()=>i(!1),children:`Cancel`}),(0,B.jsx)(H,{variant:`danger`,loading:c,disabled:a!==e.name,onClick:()=>void d(),children:`Delete`})]}),children:[(0,B.jsx)(Jf,{message:l}),(0,B.jsx)(Yd,{"aria-label":`Organization name`,value:a,onChange:e=>s(e.target.value)})]})]})},lce=({organization:e,basePath:t,owner:n})=>{let{session:r}=V(),{busy:i,error:a,run:o}=fg();return(0,B.jsxs)(qf,{title:`Leave`,description:n?`An organization keeps an owner: hand it over before you leave, unless it has another owner.`:`You stop being a member, and lose your roles here.`,children:[(0,B.jsx)(Jf,{message:a}),(0,B.jsxs)(H,{loading:i,onClick:()=>void o(async()=>{await r.organizations.leave(e.id),n9(t)}),children:[`Leave `,e.name]})]})},uce=({current:e,basePath:t,onChanged:n})=>{let r=e?.organization;if(!r)return(0,B.jsx)(`div`,{className:`mx-auto w-full max-w-3xl px-4 py-6 md:px-6`,children:(0,B.jsx)(of,{title:`Organization`,subtitle:`You do not work in an organization now. Choose one under Organizations.`})});let i=e.role===`owner`;return(0,B.jsxs)(`div`,{className:`mx-auto flex w-full max-w-3xl flex-col gap-4 px-4 py-6 md:px-6`,children:[(0,B.jsx)(of,{title:r.name,subtitle:e.role?`You are ${sg[e.role].toLowerCase()} here.`:`You work here through your global roles, without being a member.`}),(0,B.jsx)(oce,{organization:r,editable:lg(e),onSaved:n},`${r.name}/${r.slug}`),i&&e.memberId&&(0,B.jsx)(sce,{organization:r,memberId:e.memberId}),e.role&&(0,B.jsx)(lce,{organization:r,basePath:t,owner:i}),i&&(0,B.jsx)(cce,{organization:r,basePath:t})]})},r9=e=>e.normalize(`NFKD`).replace(/[̀-ͯ]/g,``).toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,63),i9=({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 text-[13px] font-medium`,children:e.name}),(0,B.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:e.slug})]}),t?(0,B.jsx)(Cd,{tone:`green`,children:`Current`}):(0,B.jsx)(H,{size:`sm`,loading:n,onClick:r,children:`Open`})]}),dce=({basePath:e})=>{let{session:t}=V(),[n,r]=(0,o.useState)(``),[i,a]=(0,o.useState)(),{busy:s,error:c,run:l}=fg(),u=()=>l(async()=>{await t.organizations.create({name:n.trim(),slug:i??r9(n)}),n9(e)});return(0,B.jsxs)(qf,{title:`New organization`,description:`You become its owner, with every role, and work in it once it is made.`,children:[(0,B.jsx)(Jf,{message:c}),(0,B.jsxs)(`form`,{className:`flex flex-col gap-2 sm:flex-row`,onSubmit:e=>{e.preventDefault(),u()},children:[(0,B.jsx)(Yd,{"aria-label":`Name`,placeholder:`Name`,value:n,onChange:e=>r(e.target.value),wrapperClassName:`flex-1`}),(0,B.jsx)(Yd,{"aria-label":`Slug`,placeholder:`slug`,value:i??r9(n),onChange:e=>a(e.target.value),wrapperClassName:`sm:w-48`}),(0,B.jsx)(H,{type:`submit`,variant:`primary`,loading:s,disabled:!n.trim(),children:`Create`})]})]})},fce=({basePath:e,currentId:t})=>{let{session:n}=V(),[r,i]=(0,o.useState)(``),[a,s]=(0,o.useState)([]),{busy:c,error:l,run:u}=fg();return(0,o.useEffect)(()=>{let e=setTimeout(()=>void n.organizations.search(r).then(s,()=>s([])),200);return()=>clearTimeout(e)},[n,r]),(0,B.jsxs)(qf,{title:`Find an organization`,description:`Your global roles let you work in any organization, with what those roles allow there. Opening one you are not a member of is written to the audit log.`,children:[(0,B.jsx)(Jf,{message:l}),(0,B.jsx)(Yd,{"aria-label":`Find an organization`,placeholder:`Name or slug`,value:r,onChange:e=>i(e.target.value),leading:(0,B.jsx)(qt,{className:`size-3.5`}),wrapperClassName:`mb-3`}),a.length>0&&(0,B.jsx)(`ul`,{className:`divide-y rounded-md border`,children:a.map(r=>(0,B.jsx)(i9,{organization:r,current:r.id===t,busy:c,onOpen:()=>void u(async()=>{await n.organizations.switchTo(r.id),n9(e)})},r.id))})]})},pce=()=>{let{session:e,organizations:t}=V(),[n,r]=(0,o.useState)([]);if((0,o.useEffect)(()=>{e.organizations.myInvitations().then(r,()=>r([]))},[e]),n.length===0)return null;let i=t?.roles??[];return(0,B.jsx)(qf,{title:`Invitations for you`,description:`Open the link in the invitation email to accept one.`,children:(0,B.jsx)(`ul`,{className:`divide-y rounded-md border`,children:n.map(e=>(0,B.jsxs)(`li`,{className:`px-3 py-2.5 text-[13px]`,children:[(0,B.jsx)(`span`,{className:`font-medium`,children:e.organizationName??`An organization`}),`: `,e.appRoles.map(e=>cg(i,e)).join(`, `)||`no app roles`,(0,B.jsxs)(`span`,{className:`block text-xs text-muted-foreground`,children:[`Until `,new Date(e.expiresAt).toLocaleDateString()]})]},e.id))})})},mce=({state:e,basePath:t})=>{let{session:n,organizations:r,state:i}=V(),{busy:a,error:o,run:s}=fg(),c=i.kind===`signed-in`?i.user:void 0,l=r?.create===`everyone`||c!==void 0&&xg(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)(of,{title:`Organizations`,subtitle:`You work in one organization at a time; what you see follows from your roles there.`}),(0,B.jsxs)(qf,{title:`Your organizations`,description:e.organizations.length>0?`The organizations you are a member of.`:`You are not a member of an organization yet.`,children:[(0,B.jsx)(Jf,{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)(i9,{organization:e,current:e.id===u,busy:a,onOpen:()=>void s(async()=>{await n.organizations.switchTo(e.id),n9(t)})},e.id))})]}),(0,B.jsx)(pce,{}),l&&(0,B.jsx)(dce,{basePath:t}),(e.current?.globalRoles.length??0)>0&&(0,B.jsx)(fce,{basePath:t,currentId:u})]})},hce=(e,t)=>t?.active?{...e,role:t.active}:e,a9=(e,t)=>e instanceof Ks?df(e):t,gce=(e,t=!0)=>{let{session:n}=V(),r=Kg(),[i,a]=(0,o.useState)();(0,o.useEffect)(()=>{t&&n.roles.current().then(a,e=>r.show({state:`error`,title:a9(e,`Could not read your roles`)}))},[n,r,t]);let s=(0,o.useCallback)(t=>void n.roles.switchTo(t).then(e,e=>r.show({state:`error`,title:a9(e,`Could not switch the role`)})),[n,r,e]);return{...i&&{current:i},switchTo:s}},o9=e=>new Set((e.userMenu?.items??[]).flatMap(e=>e.kind===`resource`?[e.resource]:e.kind===`page`?[e.page]:[])),_ce=(e,t,n)=>(e.userMenu?.items??[]).map((r,i)=>{if(r.kind===`link`)return{id:`link-${i}`,label:r.label,icon:L_(r.icon,Ue),href:r.href,external:!0};if(r.kind===`page`){let i=e.pages[r.page];return{id:r.page,label:r.label??i?.title??G(r.page),icon:L_(r.icon??i?.icon,rt),href:qo({kind:`page`,page:r.page},t),active:r.page===n}}return{id:r.resource,label:r.label??e.views[r.resource]?.names?.plural??G(r.resource),icon:L_(r.icon,F_(r.resource)),href:qo({kind:`list`,resource:r.resource},t),active:r.resource===n}}),vce={sales:`Sales`,crm:`CRM`,catalog:`Catalog`,inventory:`Inventory`,core:`Admin`,hr:`HR`},yce=(e,t=``,n={})=>{let r=new Map,i=new Map,a=o9(e);for(let n of Object.values(e.pages)){if(n.nav?.hidden||a.has(n.name))continue;let e=n.nav?.group??`Pages`,o=r.get(e)??{label:e,items:[]};o.items.push({id:n.name,label:n.title,icon:L_(n.icon,rt),href:qo({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||s.nav?.hidden||a.has(o.name))continue;let c=o.table.schema??`public`,l=s.nav?.group??vce[c]??G(c),u=r.get(l)??{label:l,items:[]};u.items.push({id:o.name,label:s.names?.plural??G(o.name),icon:F_(o.name),href:qo({kind:`list`,resource:o.name},t),...n[o.name]&&{recent:n[o.name]}}),r.set(l,u),i.set(o.name,s.nav?.order??2**53-1)}for(let n of Object.values(e.signIn??{})){if(n.nav?.hidden||a.has(n.resource))continue;let e=n.nav?.group??`Account`,o=r.get(e)??{label:e,items:[]};o.items.push({id:n.resource,label:n.names?.plural??G(n.resource),icon:F_(n.resource),href:qo({kind:`list`,resource:n.resource},t)}),r.set(e,o),i.set(n.resource,n.nav?.order??2**53-1)}for(let n of e.sources??[]){if(n.state!==`error`)continue;let e=r.get(n.source.label)??{label:n.source.label,items:[]};for(let r of n.source.resources)e.items.push({id:r,label:G(r),icon:F_(r),href:qo({kind:`list`,resource:r},t),problem:`Cannot reach ${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))}))},s9=({action:e,label:t,danger:n,onCancel:r,onConfirm:i})=>(0,B.jsx)(Kf,{title:`${t}?`,description:e.confirm,onClose:r,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(H,{onClick:r,children:`Cancel`}),(0,B.jsx)(H,{variant:n?`danger`:`primary`,onClick:i,children:t})]})}),c9=(0,o.createContext)(void 0),l9=({value:e,children:t})=>(0,B.jsx)(c9.Provider,{value:e,children:t}),u9=()=>(0,o.useContext)(c9),bce=(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]))),xce=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},d9=(e,t={})=>{let n=Eee(e);return n===void 0?bce(e,t):xce(t[n])},Sce=e=>{e!==void 0&&(/^https?:/i.test(e)?window.open(e,`_blank`,`noopener,noreferrer`):window.location.assign(e))},Cce=e=>URL.canParse(e)?new URL(e).hostname.replace(/^www\./,``):``,wce=(e,t)=>{let n=e.run;if(n?.kind!==`link`||!(`href`in n))return e;let r=d9(n.href,t);if(r!==void 0)return e.label.includes(`{host}`)?{...e,label:e.label.replaceAll(`{host}`,Cce(r))}:e},Tce=e=>e instanceof Error?e.message:`Something went wrong`,f9=(e,t,n)=>{let{views:r}=K(),{actions:i}=w_(),a=Uv(e),s=W(),c=Fh(e),l=Kg(),u=aA(),{go:d}=Wv(),[f,p]=(0,o.useState)(),m=(r[e]?.actions??[]).flatMap(e=>wce(e,t?.record)??[]),h=e=>{let n=e.run?.kind;if((n===`update`||n===`delete`)&&!t)return`Needs a record`;if(n===`update`&&(!Ey(a,`update`)||t?.permissions?.update===!1))return`You cannot change this record`;if(n===`delete`&&(!Ey(a,`delete`)||t?.permissions?.delete===!1))return`You cannot delete this record`;if(!e.run&&!i?.[e.name])return`The app has no handler for "${e.name}"`},g=async r=>{let{run:a}=r;if(a?.kind===`link`){`to`in a?d(po(a.to,t?.record)):Sce(d9(a.href,t?.record));return}a?.kind===`update`?await s.update(e,t.key,a.values,t.etag??`*`):a?.kind===`delete`?await s.remove(e,t.key,{etag:t.etag}):await i[r.name]({resource:e,record:t?.record,recordKey:t?.key,etag:t?.etag,client:c,navigate:d}),await u(e),l.show({state:`success`,title:`${r.label}: done`}),n?.(r)};return{actions:m,blocked:h,running:f,run:async e=>{h(e)||(p(e.name),await g(e).catch(t=>l.show({state:`error`,title:`${e.label} failed`,description:Tce(t)})),p(void 0))}}},Ece=(e,t,n)=>{let r=f9(e,n),i=r.actions.find(e=>e.name===t);return{action:i,blocked:i?r.blocked(i):`No action "${t}"`,running:r.running===t,run:()=>i?r.run(i):Promise.resolve()}},p9=e=>e.props,Dce=({node:e})=>{let{name:t,resource:n,label:r,variant:i}=p9(e),a=u9(),s=Ece(n??a?.model.name??``,t,n===void 0||n===a?.model.name?a:void 0),[c,l]=(0,o.useState)(!1);if(!s.action)return null;let u=r??s.action.label;return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(H,{size:`sm`,variant:i??`secondary`,loading:s.running,disabled:!!s.blocked,title:s.blocked,onClick:()=>s.action.confirm?l(!0):void s.run(),children:u}),c&&(0,B.jsx)(s9,{action:s.action,label:u,danger:i===`danger`,onCancel:()=>l(!1),onConfirm:()=>{l(!1),s.run()}})]})},m9=({title:e,description:t,actions:n,className:r,bodyClassName:i,children:a})=>(0,B.jsxs)(`section`,{className:z(`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-[15px] font-semibold tracking-tight`,children:e}),t&&(0,B.jsx)(`p`,{className:`mt-0.5 text-[13px] 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:z(`min-w-0 flex-1 p-4 text-[13px]`,i),children:a})]}),h9=({children:e})=>(0,B.jsx)(`p`,{className:`text-[13px] text-muted-foreground`,children:e}),Oce=({node:e,children:t,slots:n})=>{let{title:r,description:i}=p9(e);return(0,B.jsx)(m9,{title:r,description:i,actions:n.actions,className:`h-full`,children:(0,B.jsx)(`div`,{className:`flex flex-col gap-3`,children:t})})},kce=({model:e,filter:t,sort:n,limit:r=12,title:i,description:a,empty:o,actions:s,children:c})=>{let l=iA(e,{filter:t,sort:n,pageSize:r}),u=l.data?.items??[];return(0,B.jsx)(m9,{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)(od,{className:`h-24 w-56`},t))}):l.error?(0,B.jsx)(ny,{title:`Could not load`,error:l.error}):u.length===0?(0,B.jsx)(h9,{children:o??`Nothing here yet.`}):(0,B.jsx)(`ul`,{className:`-mx-4 flex snap-x gap-3 overflow-x-auto px-4 pb-1`,children:u.map(t=>{let n=eA(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)(l9,{value:n,children:c})},n.key)})})})},Ace=({node:e,children:t,slots:n})=>{let{resource:r,...i}=p9(e),a=K().resources[r];return a?(0,B.jsx)(kce,{...i,model:a,actions:n.actions,children:t}):null},jce=(e,t)=>{if(t)return t;let n=e.split(`.`).map(e=>G(e).toLowerCase()).join(` `);return n[0].toUpperCase()+n.slice(1)},Mce=({node:e})=>{let{name:t,label:n,format:r}=p9(e),{views:i}=K(),a=T7(u9(),t);if(a.state===`missing`)return null;let o=a.state===`loading`?(0,B.jsx)(od,{className:`h-4 w-24`}):(0,B.jsx)(x7,{model:a.model,field:a.field,value:a.value,format:r});if(n===!1)return(0,B.jsx)(`div`,{className:`text-[13px]`,children:o});let s=n??jce(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-xs text-muted-foreground`,children:s}),(0,B.jsx)(`div`,{className:`mt-0.5 truncate text-[13px]`,children:o})]})},Nce={1:``,2:`md:grid-cols-2`,3:`md:grid-cols-2 xl:grid-cols-3`,4:`sm:grid-cols-2 xl:grid-cols-4`},Pce={1:``,2:`grid-cols-2`,3:`grid-cols-2 xl:grid-cols-3`,4:`grid-cols-2 xl:grid-cols-4`},Fce={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`},Ice=e=>typeof e==`object`&&!e.custom&&e.type===`Stat`,Lce=({node:e,children:t})=>{let{columns:n=2}=p9(e),r=e.children,i=r.length>0&&r.every(Ice);return(0,B.jsx)(`div`,{className:z(`grid grid-cols-1 gap-4`,i?Pce[n]:Nce[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:z(`min-w-0`,i&&Fce[i]),children:e},t)})})},g9=`font-medium text-primary-text hover:underline`,Rce=({node:e})=>{let t=p9(e),n=u9()?.record,r=e.children.filter(e=>typeof e==`string`).join(``);if(t.to){let e=po(t.to,n);return(0,B.jsx)(Gv,{to:e,className:g9,children:r||qo(e)})}let i=t.href??``;return(0,B.jsx)(`a`,{href:i,className:g9,...i.startsWith(`http`)&&{target:`_blank`,rel:`noreferrer`},children:r||i})},zce=(e,t,n)=>Object.fromEntries(t.map(t=>{let r=e.fields[t];if(r.type===`file`)return[t,n?.record[t]??null];if(n)return[t,r.type===`boolean`?!!n.record[t]:Jv(n.record[t])];let i=r.default&&`value`in r.default?r.default.value:void 0;return[t,r.type===`boolean`?!!i:Jv(i)]})),Bce=(e,t,n)=>Object.fromEntries(Object.entries(t).flatMap(([t,r])=>{let i=e.fields[t];return sC(r)?r.key===Jv(n.record[t])?[]:[[t,i.type===`integer`?Number(r.key):r.key]]:ey(i,r,n.record[t])?[[t,Zv(i,r)]]:[]})),Vce=({model:e,record:t,mode:n,label:r,title:i,fields:a,values:s,onClose:c})=>{let{resources:l,views:u}=K(),d=W(),f=Kg(),p=aA(),m=u[e.name],[h,g]=(0,o.useState)(()=>zce(e,a,t)),[_,v]=(0,o.useState)({}),[y,b]=(0,o.useState)(),[x,S]=(0,o.useState)(!1),C=async()=>{S(!0),b(void 0),await(n===`create`?d.create(e.name,{...dC(e,l,h),...s}):d.update(e.name,t.key,Bce(e,h,t),t.etag??`*`)).then(async()=>{await p(e.name),f.show({state:`success`,title:`${i??r}: saved`}),c()},e=>{vs(e)&&v(Object.fromEntries(e.errors.flatMap(e=>e.field?[[e.field,e.message]]:[]))),b(e)}),S(!1)};return(0,B.jsx)(Kf,{title:i??r,onClose:c,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(H,{onClick:c,children:`Cancel`}),(0,B.jsx)(H,{variant:`primary`,loading:x,onClick:()=>void C(),children:n===`create`?`Create`:`Save`})]}),children:(0,B.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),C()},children:[y!==void 0&&Object.keys(_).length===0&&(0,B.jsx)(ny,{title:`Not saved`,error:y}),a.map(n=>{let r=e.fields[n],i=h[n],a=r.relation?l[r.relation.resource]:void 0;return(0,B.jsx)(QS,{label:m?.fields[n]?.label??G(n),help:m?.fields[n]?.help,error:_[n],children:(0,B.jsx)(Ty,{field:r,hints:m?.fields[n],value:sC(i)?i.key:i,stored:t?.record[n],relationLabel:sC(i)?i.label:void 0,relationPicker:a?{target:a,view:u[a.name]}:void 0,invalid:!!_[n],resource:e.name,onChange:e=>{v(({[n]:e,...t})=>t),g(t=>({...t,[n]:e}))}})},n)})]})})},Hce=({model:e,recordKey:t,children:n})=>{let r=rA(e,{key:t});return(0,B.jsx)(B.Fragment,{children:n(r.data??void 0)})},Uce=({node:e})=>{let t=p9(e),n=u9(),{resources:r}=K(),i=r[t.resource??n?.model.name??``],a=Uv(i?.name??``),[s,c]=(0,o.useState)(!1);if(!i||!(t.mode===`create`?Ey(a,`create`):Ey(a,`update`)&&n?.permissions?.update!==!1))return null;let l=e=>(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(H,{size:`sm`,variant:t.variant??`secondary`,disabled:t.mode===`edit`&&!e,onClick:()=>c(!0),children:t.label}),s&&(0,B.jsx)(Vce,{...t,model:i,record:t.mode===`edit`?e:void 0,onClose:()=>c(!1)})]});return t.mode===`edit`&&t.recordKey!==void 0?(0,B.jsx)(Hce,{model:i,recordKey:t.recordKey,children:l}):l(t.mode===`edit`?n:void 0)},Wce=({node:e,children:t,slots:n})=>{let{title:r,description:i}=p9(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)(of,{title:r,subtitle:i,actions:n.actions}),t]})})},_9=(e,t)=>{let n=u9(),r=T7(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},Gce=({node:e})=>{let{value:t,max:n,label:r}=p9(e),i=_9(t,0),a=_9(n,100);if(i===void 0||a===void 0)return(0,B.jsx)(od,{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-xs`,children:[(0,B.jsx)(`span`,{className:`text-muted-foreground`,children:r}),(0,B.jsxs)(`span`,{className:`tabular-nums`,children:[i.toLocaleString(`en-IE`),` / `,a.toLocaleString(`en-IE`)]})]}),(0,B.jsx)(`div`,{role:`progressbar`,"aria-label":r,"aria-valuenow":i,"aria-valuemin":0,"aria-valuemax":a,className:`mt-1.5 h-2 overflow-hidden rounded-full bg-muted`,children:(0,B.jsx)(`div`,{className:o>=.9?`h-full rounded-full bg-warning`:`h-full rounded-full bg-primary`,style:{width:`${o*100}%`}})})]})},Kce=({model:e,filter:t,sort:n,recordKey:r,title:i,description:a,empty:o,actions:s,children:c})=>{let l=rA(e,{filter:t,sort:n,key:r}),u=e=>l.data?(0,B.jsx)(l9,{value:l.data,children:e}):void 0,d=l.isPending?(0,B.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,B.jsx)(od,{className:`h-4 w-1/2`}),(0,B.jsx)(od,{className:`h-4 w-1/3`})]}):l.error?(0,B.jsx)(ny,{title:`Could not load`,error:l.error}):l.data?u((0,B.jsx)(`div`,{className:`flex flex-col gap-3`,children:c})):(0,B.jsx)(h9,{children:o??`Nothing here yet.`});return(0,B.jsx)(m9,{title:i,description:a,actions:s?u(s):void 0,className:`h-full`,children:d})},qce=({node:e,children:t,slots:n})=>{let{resource:r,filter:i,sort:a,recordKey:o,title:s,description:c,empty:l}=p9(e),u=K().resources[r];return u?(0,B.jsx)(Kce,{model:u,filter:i,sort:a,recordKey:o,title:s,description:c,empty:l,actions:n.actions,children:t}):null},Jce=({model:e,view:t,empty:n,...r})=>{let{resources:i,views:a}=K(),o=Ov(i,a,e.name),s=mA(e.name,t.listOf,!0),c=(t.names?.plural??G(e.name)).toLowerCase();if(!o.listOf)return null;if(s.error)return(0,B.jsx)(ny,{title:`Could not load your ${c}`,error:s.error});if(!s.data)return(0,B.jsx)(od,{className:`h-24`});let l=fA(o.model,s.data);return l?(0,B.jsx)(X7,{...r,model:o.model,view:o.view,filter:``,scope:l,list:e.name,empty:n}):(0,B.jsx)(`p`,{className:`text-[13px] text-muted-foreground`,children:n??`No ${c} yet.`})},Yce=({model:e,view:t,target:n,targetView:r,row:i})=>{let a=mo(Mg(e,i)),{name:o,chips:s,title:c,body:l}=Z7({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-[14px] font-semibold`,children:(0,B.jsx)(Gv,{to:{kind:`record`,resource:e.name,key:a},className:`hover:underline`,children:o??(0,B.jsx)(v7,{chips:s})})}),(0,B.jsx)(X7,{...l})]})},Xce=({model:e,view:t,empty:n})=>{let{resources:r,views:i}=K(),a=t.searchesOf,o=r[a.resource],s=H7(e.name,!0),c=(t.names?.plural??G(e.name)).toLowerCase();return o?s.error?(0,B.jsx)(ny,{title:`Could not load your ${c}`,error:s.error}):s.data?s.data.length===0?(0,B.jsx)(`p`,{className:`text-[13px] text-muted-foreground`,children:n??`No ${c} yet.`}):(0,B.jsx)(`div`,{className:`flex flex-col divide-y`,children:s.data.map(n=>(0,B.jsx)(Yce,{model:e,view:t,target:o,targetView:i[a.resource],row:n},mo(Mg(e,n))))}):(0,B.jsx)(od,{className:`h-40`}):null},Zce=({node:e,slots:t})=>{let{resource:n,filter:r=``,sort:i,limit:a,display:o,title:s,description:c,empty:l}=p9(e),{resources:u,views:d}=K(),f=u[n];if(!f)return null;let p=d[f.name];return(0,B.jsx)(m9,{title:s,description:c,actions:t.actions,children:p?.searchesOf?(0,B.jsx)(Xce,{model:f,view:p,empty:l}):p?.listOf===void 0?(0,B.jsx)(X7,{model:f,view:p,filter:r,sort:i,limit:a,display:o,empty:l}):(0,B.jsx)(Jce,{model:f,view:p,limit:a,display:o,empty:l})})},Qce=({node:e,children:t})=>{let{when:n}=p9(e),{resources:r}=K(),i=W(),a=u9(),s=(0,o.useMemo)(()=>Ls(n),[n]),c=s.ok?s.paths:[],l=c.map(e=>zs(e,e=>!!(a&&Object.hasOwn(a.model.fields,e)))),u=c.filter((e,t)=>l[t]===void 0),d=gse(a,u),f=Dh({queries:l.flatMap(e=>{let t=e===void 0?void 0:r[e];return t?[tA(i,t)]:[]})});if(!s.ok||d.some(e=>e.state===`loading`)||f.some(e=>e.isPending))return null;let p={};u.forEach((e,t)=>{let n=d[t];n.state===`ready`&&(p[e]=n.value)});let m=0;return c.forEach((e,t)=>{l[t]!==void 0&&(p[e]=r[l[t]]?f[m++]?.data??0:0)}),Rs(s,p)?(0,B.jsx)(B.Fragment,{children:t}):null},v9=`text-2xl font-semibold tracking-tight tabular-nums`,$ce=({model:e,filter:t})=>{let n=nA(e,t);return n.isPending?(0,B.jsx)(od,{className:`h-8 w-16`}):n.error?(0,B.jsx)(`span`,{className:`text-[13px] text-danger-text`,children:`Could not count`}):(0,B.jsx)(Gv,{to:{kind:`list`,resource:e.name,filter:t},className:`${v9} hover:text-primary-text after:absolute after:inset-0 after:content-['']`,children:n.data.toLocaleString(`en-IE`)})},ele=({field:e,format:t})=>{let n=T7(u9(),e);return n.state===`loading`?(0,B.jsx)(od,{className:`h-8 w-16`}):n.state===`missing`?null:(0,B.jsx)(`span`,{className:v9,children:(0,B.jsx)(x7,{model:n.model,field:n.field,value:n.value,format:t})})},tle=({node:e})=>{let{label:t,value:n,resource:r,filter:i,field:a,format:o,description:s}=p9(e),{resources:c}=K(),l=r===void 0?void 0:c[r];return(0,B.jsxs)(m9,{className:`relative h-full`,bodyClassName:`flex flex-col`,children:[(0,B.jsx)(`p`,{className:`text-[13px] 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:v9,children:n}),l&&(0,B.jsx)($ce,{model:l,filter:i}),a!==void 0&&(0,B.jsx)(ele,{field:a,format:o})]}),s&&(0,B.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:s})]})},y9=(e,t,n)=>{let r=Ku(),i=xse(t),[a,s]=(0,o.useState)(()=>Sse(localStorage,i)),c=(0,o.useCallback)(e=>{s(e),Cse(localStorage,i,e)},[i]);return[wse(e,r,{picked:a,preferred:n}),c]},nle=({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]=y9(t,`page:${e.name}:${s??``}:${n}`,o);return(0,B.jsx)(m9,{title:s,description:c,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(O7,{view:t,value:d,onChange:f}),u]}),className:`h-full`,children:(0,B.jsx)(k7,{model:e,view:t,filter:n,sort:r,columns:i,limit:a,display:d,empty:l})})},rle={Page:Wce,Grid:Lce,Card:Oce,Stat:tle,RecordCard:qce,Field:Mce,Table:({node:e,slots:t})=>{let n=p9(e),{resources:r,views:i}=K(),a=r[n.resource];return a?(0,B.jsx)(nle,{...n,model:a,view:i[a.name],actions:t.actions}):null},CardRow:Ace,RecordRow:Zce,Progress:Gce,ModalForm:Uce,Action:Dce,Show:Qce,Link:Rce},b9=e=>typeof e==`string`||!e.custom&&e.type===`Link`,x9=e=>{let t=[];for(let n of e){let e=t.at(-1);b9(n)&&e&&b9(e[0])?e.push(n):t.push([n])}return t.map((e,t)=>{let[n]=e;return b9(n)?(0,B.jsx)(`p`,{className:`text-[13px] leading-relaxed`,children:e.map((e,t)=>typeof e==`string`?(0,B.jsx)(o.Fragment,{children:e},t):(0,B.jsx)(S9,{node:e},t))},t):(0,B.jsx)(S9,{node:n},t)})},ile=e=>Ns(e)||Array.isArray(e)&&e.length>0&&e.every(Ns),ale=e=>Object.fromEntries(Object.entries(e.props).flatMap(([e,t])=>ile(t)?[[e,(0,B.jsx)(B.Fragment,{children:x9(Array.isArray(t)?t:[t])})]]:[])),S9=({node:e})=>{let{components:t}=w_();if(e.custom){let n=t?.[e.type];return n?(0,B.jsx)(by,{name:e.type,children:(0,B.jsx)(n,{...co(e.props),children:e.children.length>0?x9(e.children):void 0})}):(0,B.jsxs)(yy,{children:[`No component is registered as `,e.type,`. Export it from protobase.ui.tsx, or load the plugin that provides it.`]})}let n=rle[e.type];return n?(0,B.jsx)(n,{node:e,slots:ale(e),children:x9(e.children)}):(0,B.jsxs)(yy,{children:[e.type,` is not a block this version of the app knows.`]})},ole=({name:e})=>{let t=K().pages[e];return t?(0,B.jsx)(S9,{node:t.tree}):(0,B.jsxs)(Bv,{title:`Not found`,children:[`There is no page called `,e,`.`]})},C9=e=>typeof e==`string`&&e.trim()!==``,sle=e=>{if(typeof e!=`object`||!e||Array.isArray(e))return{problem:`its plugin.json is not an object`};let{name:t,version:n,api:r,protobase:i,entry:a,css:o}=e;return C9(t)?Number.isInteger(r)?C9(i)?C9(a)?o!==void 0&&!C9(o)?{problem:`its plugin.json names a stylesheet that is no URL`}:n!==void 0&&!C9(n)?{problem:`its plugin.json has a version that is no text`}:{manifest:{name:t,api:r,protobase:i,entry:a,...n!==void 0&&{version:n},...o!==void 0&&{css:o}}}:{problem:`its plugin.json names no module`}:{problem:`its plugin.json names no Protobase versions`}:{problem:`its plugin.json names no plugin API`}:{problem:`its plugin.json names no plugin`}},cle=/^[A-Z][A-Za-z0-9]*$/,lle=e=>typeof e==`function`||typeof e==`object`&&!!e&&`$$typeof`in e,w9=e=>{let t=e.default??{},n=Object.entries(e).filter(e=>e[0]!=="default"&&cle.test(e[0])&&lle(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)}}},T9=class extends Error{name=`UiConflictError`},ule=e=>Object.keys(e).some(e=>e==="default"||/^[A-Z]/.test(e))?w9(e):e,E9=(e,t)=>[...(e.extends??[]).map(ule).flatMap((e,n)=>E9(e,e.name??`${t} extends[${n}]`)),{ui:e,label:t}],D9=(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 T9(`${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},O9=e=>e.length<=1?e[0]:()=>e.map((e,t)=>(0,B.jsx)(e,{},t)),k9=(...e)=>{let t=e.flatMap((e,t)=>E9(e,e.name??`UI config ${t+1}`)),n=D9(`The component`,t,e=>e.components),r=D9(`The action handler`,t,e=>e.actions),i=D9(`The field type`,t,e=>e.fields),a=O9(t.flatMap(({ui:e})=>e.shell?.actions?[e.shell.actions]:[])),o=O9(t.flatMap(({ui:e})=>e.shell?.rightPanel?[e.shell.rightPanel]:[])),s=e.at(-1)?.name;return{...s&&{name:s},components:n,actions:r,...Object.keys(i).length>0&&{fields:i},...(a||o)&&{shell:{...a&&{actions:a},...o&&{rightPanel:o}}}}},A9=(0,o.createContext)(null),dle=A9.Provider,fle=()=>{let e=(0,o.useContext)(A9);if(!e)throw Error(`usePlugin is for the components of a plugin the app loaded`);return e},j9=(e,t,n)=>{let r=n=>(0,B.jsx)(dle,{value:e,children:(0,B.jsx)(t,{...n})});return r.displayName=`${e.name}:${n}`,r},ple=(e,t,n)=>({of:n.of,display:j9(e,n.display,`fields.${t}.display`),...n.editor&&{editor:j9(e,n.editor,`fields.${t}.editor`)},...n.cell&&{cell:j9(e,n.cell,`fields.${t}.cell`)}}),mle=(e,t)=>{let n=k9({...w9(t),name:e.name}),r=Object.fromEntries(Object.entries(n.components??{}).map(([t,n])=>[t,j9(e,n,t)])),i=n.fields&&Object.fromEntries(Object.entries(n.fields).map(([t,n])=>[t,ple(e,t,n)])),a=n.shell&&{...n.shell.actions&&{actions:j9(e,n.shell.actions,`shell.actions`)},...n.shell.rightPanel&&{rightPanel:j9(e,n.shell.rightPanel,`shell.rightPanel`)}};return{name:e.name,components:r,...n.actions&&{actions:n.actions},...i&&{fields:i},...a&&{shell:a}}},M9={name:`@protobase/ui`,version:`0.16.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`},types:`./src/index.ts`,files:[`dist`],scripts:{build:`tsdown && protobase build-shell dist/shell`,prepack:`tsdown && protobase build-shell dist/shell`},publishConfig:{access:`public`,exports:{".":`./dist/index.js`,"./theme.css":`./dist/theme.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`,"lucide-react":`^1.52.0`,"maplibre-gl":`^6.14.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`}},N9=M9.protobase.pluginApi,P9=M9.version,hle={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=>g_(()=>import(e),[])},gle={api:N9,version:P9},_le=e=>e instanceof Error?e.message:String(e),vle=async(e,t,n,r=gle)=>{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(`its plugin.json answered ${n.status}`);let s=sle(n.json);if(`problem`in s)return a(s.problem);let{manifest:c}=s;o=c.name;let l=bo(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:mle(d,u)}}catch(e){return a(`it could not be loaded: ${_le(e)}`,o)}},yle=(e,t)=>{let n=k9(e??{}),r=[],i=[];for(let e of t){if(e.kind===`off`){i.push(e);continue}try{k9(...r,e.ui,n),r.push(e.ui)}catch(t){if(!(t instanceof T9))throw t;i.push({kind:`off`,url:e.plugin.url,name:e.plugin.name,reason:t.message})}}return{ui:r.length===0?n:k9(...r,n),off:i}},ble=1e4,F9=[],xle=(e,t)=>{let n=JSON.stringify(e),[r,i]=(0,o.useState)({key:`[]`,loads:F9,settled:!0});return(0,o.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()},ble);return e.forEach((e,n)=>{vle(e,t,window.location.href).then(e=>{o[n]=e,s()})}),()=>{r=!1,clearTimeout(c)}},[n,t]),e.length===0?{loads:F9,settled:!0}:r.key===n?r:{loads:F9,settled:!1}},I9=(0,o.createContext)([]),Sle=()=>(0,o.useContext)(I9),Cle=({ui:e,loader:t=hle,children:n})=>{let{plugins:r=[]}=K(),{loads:i,settled:a}=xle(r,t),s=(0,o.useMemo)(()=>yle(e,i),[e,i]);return a?(0,B.jsx)(C_.Provider,{value:s.ui,children:(0,B.jsx)(I9.Provider,{value:s.off,children:n})}):(0,B.jsxs)(`div`,{className:`flex h-full min-h-48 items-center justify-center gap-2 text-[13px] text-muted-foreground`,children:[(0,B.jsx)(Zd,{}),` Loading`]})},wle=({off:e})=>{let[t,n]=(0,o.useState)(!1);return t||e.length===0?null:(0,B.jsxs)(`div`,{role:`region`,"aria-label":`Plugins off`,className:`flex items-start gap-3 border-b border-warning/40 bg-warning-soft px-4 py-2 text-[13px] text-warning-text`,children:[(0,B.jsx)(zt,{"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.jsxs)(`li`,{children:[`The plugin `,(0,B.jsx)(`span`,{className:`font-semibold`,children:e.name??e.url}),` is off: `,e.reason,`.`]},e.url))}),(0,B.jsx)(`button`,{type:`button`,"aria-label":`Dismiss`,className:`rounded p-0.5 hover:bg-warning/10`,onClick:()=>n(!0),children:(0,B.jsx)(Nn,{"aria-hidden":!0,className:`size-4`})})]})},L9=(e,t)=>[`${t}_at`,`${t}At`].find(t=>e.fields[t]),R9=({item:e,scope:t})=>{let{components:n}=w_(),r=n?.[e.component],i=r?(0,B.jsx)(l9,{value:t,children:(0,B.jsx)(by,{name:e.component,children:(0,B.jsx)(r,{...co(e.props??{})})})}):(0,B.jsxs)(yy,{children:[`No component is registered as `,e.component,`. Export it from protobase.ui.tsx, or load the plugin that provides it.`]});return e.sidebar?e.title?(0,B.jsx)(rC,{title:e.title,children:i}):i:e.title?(0,B.jsx)($S,{title:e.title,children:i}):(0,B.jsx)(`section`,{className:`py-8`,children:i})},Tle=(0,o.lazy)(()=>g_(()=>import(`./record-map-DbwHSPf3.js`).then(e=>({default:e.RecordMap})),__vite__mapDeps([7,1,3,2,4,5,6]))),Ele=15,z9=({item:e,record:t})=>{let n=K().maps?.style,r=IA(t,e);if(!n||!r)return null;let i=(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)(o.Suspense,{fallback:null,children:(0,B.jsx)(Tle,{style:n,position:r,zoom:e.zoom??Ele},`${r.latitude},${r.longitude}`)})});return e.sidebar?(0,B.jsx)(rC,{title:e.title,children:i}):(0,B.jsx)($S,{title:e.title,children:i})},Dle=e=>Yk(e)??lee,Ole=({model:e,stored:t,recordKey:n})=>{let{go:r}=Wv(),i={model:e,record:t.record,key:n,etag:t.etag,permissions:t.permissions},a=f9(e.name,i,t=>t.run?.kind===`delete`&&r({kind:`list`,resource:e.name},{replace:!0})),[s,c]=(0,o.useState)();return a.actions.length===0?null:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(eC,{actions:a.actions.map(e=>({name:e.label,icon:Dle(e.icon),blocked:a.blocked(e),running:a.running===e.name,onRun:()=>e.confirm?c(e):void a.run(e)}))}),s&&(0,B.jsx)(s9,{action:s,label:s.label,danger:s.run?.kind===`delete`,onCancel:()=>c(void 0),onConfirm:()=>{c(void 0),a.run(s)}})]})},kle=(e,t)=>Object.values(e).find(e=>e.name!==t.name&&e.fields.position&&e.fields.quantity&&Object.values(e.fields).some(e=>e.type===`relation`&&e.relation?.resource===t.name)),Ale=e=>({id:String(e.id),productId:String(e.productId??``),description:String(e.description??``),quantity:Number(e.quantity),unitPriceCents:Math.round(Number(e.unitPrice)*100)}),jle=({lines:e,draft:t,vatRate:n,saving:r})=>{let i=Ey(Uv(e.name),`update`);return(0,B.jsx)($S,{title:`Lines`,help:`What the document bills for. Drag the handle, or use the menu, to change the order; Save applies it.`,children:(0,B.jsx)(`div`,{className:`-mx-4 overflow-x-auto px-4 [-webkit-overflow-scrolling:touch] md:mx-0 md:px-0`,children:(0,B.jsx)(`div`,{className:`min-w-[560px]`,children:(0,B.jsx)(ZS,{lines:t.shown.map(Ale),onChange:()=>void 0,onReorder:e=>t.setOrder(e.map(e=>e.id)),vatRate:n,readOnly:!0,reorderable:i&&!r})})})})},Mle=(e,t,n)=>`protobase:draft:${e}:${t}:${n}`,Nle=(e,t,n)=>jd(()=>{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),Ple=(e,t,n)=>jd(()=>n?e.setItem(t,JSON.stringify(n)):e.removeItem(t),void 0),B9=(e,{filter:t,orderBy:n,pageSize:r=50,fields:i,startToken:a=``,enabled:o=!0}={})=>{let s=W(),c=as(t)??``,l=jh({queryKey:[...U.list(e,c,n??``,r,a),i?.join(`,`)??``],enabled:o,initialPageParam:a,queryFn:({pageParam:t})=>s.list(e,{filter:c,orderBy:n,pageSize:r,fields:i,pageToken:t}),getNextPageParam:e=>e.nextPageToken||void 0}),u=l.data?.pages??[];return{...l,items:u.flatMap(e=>e.items),totalEstimate:u[0]?.totalSizeEstimate}},Fle=(e,t)=>Number(e.position)-Number(t.position),Ile=(e,t,n)=>{let r=e&&Object.values(e.fields).find(e=>e.type===`relation`&&e.relation?.resource===t.name),i=B9(e?.name??``,{enabled:!!(e&&r),filter:r?`${r.name} = "${n}"`:void 0,pageSize:200,...e?.fields.position?.sortable&&{orderBy:`position asc`}});return{items:[...i.items].sort(Fle),loading:i.isPending&&!!e}},Lle=(e,t)=>{let[n,r]=(0,o.useState)(),i=t.map(e=>String(e.id)),a=(0,o.useMemo)(()=>{if(!n)return t;let e=n.flatMap(e=>t.filter(t=>String(t.id)===e)),r=t.filter(e=>!n.includes(String(e.id)));return[...e,...r]},[n,t]),s=a.map(e=>String(e.id)),c=n!==void 0&&s.some((e,t)=>e!==i[t]),l=(0,o.useCallback)(()=>!e||!c?[]:[{op:`reorder`,resource:e.name,field:`position`,keys:a.map(t=>Mg(e,t)),etags:Object.fromEntries(a.flatMap(t=>typeof t.etag==`string`?[[mo(Mg(e,t)),t.etag]]:[]))}],[e,c,a]);return{shown:a,dirty:c,order:c?s:void 0,setOrder:e=>r(e),reset:()=>r(void 0),op:l}},V9=(e,t)=>{let n=W(),r=pm(),i=mo(t);return Ah({mutationFn:({patch:r,etag:i})=>n.update(e,t,r,i),onSuccess:t=>{r.setQueryData(U.record(e,i),t),r.invalidateQueries({queryKey:[`page`,e]}),r.invalidateQueries({queryKey:[`list`,e]}),r.invalidateQueries({queryKey:[`map`,e]})}})},H9=e=>e instanceof _s,Rle=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}`},zle=(e,t)=>{let n=e.operation,r=n===void 0?void 0:t[n];return r?`Operation ${n+1} (${Rle(r)}) failed: ${e.message} Nothing was saved.`:`${e.message} Nothing was saved.`},Ble=(e,t)=>new e.constructor({...e.problem,detail:zle(e,t)}),U9=(e,t)=>Object.fromEntries(Object.entries(e).filter(([e])=>e!==t)),Vle=({model:e,stored:t,recordKey:n,mode:r,subject:i,draftKey:a,lines:s})=>{let c=W(),l=pm(),u=V9(e.name,n),d=Ay(r,i),[f]=(0,o.useState)(()=>a?Nle(localStorage,a,t.etag):void 0),[p,m]=(0,o.useState)(f?.fields??{}),[h,g]=(0,o.useState)(!!f),[_,v]=(0,o.useState)(!1),[y,b]=(0,o.useState)({}),[x,S]=(0,o.useState)({}),C=Object.entries(p).filter(([n,r])=>ey(e.fields[n],r,t.record[n])),w=C.length>0,T=w||!!s?.dirty;(0,o.useEffect)(()=>{f?.order&&s?.setOrder(f.order)},[]),(0,o.useEffect)(()=>{if(!a)return;let n=Object.fromEntries(Object.entries(p).filter(([t])=>!e.fields[t]?.sensitive)),r=Object.keys(n).length>0||!!s?.dirty;Ple(localStorage,a,r?{etag:t.etag,fields:n,...s?.order&&{order:s.order}}:void 0)},[a,e,p,s?.dirty,s?.order,t.etag]);let E=n=>n in p?p[n]:[`boolean`,`file`].includes(e.fields[n].type)?t.record[n]:Jv(t.record[n]),D=(n,r)=>{S(e=>U9(e,n));let i=typeof r==`string`?r!==Jv(t.record[n]):ey(e.fields[n],r,t.record[n]);m(e=>i?{...e,[n]:r}:U9(e,n))},O=async()=>{let r=await c.get(e.name,n);l.setQueryData(U.record(e.name,n),r);let i={},a={};for(let[n,o]of Object.entries(p)){let s=e.fields[n];ey(s,o,r.record[n])&&(a[n]=o,Jv(r.record[n])!==Jv(t.record[n])&&(i[n]=s.type===`file`?ov(s,r.record[n]):Jv(r.record[n])))}m(a),b(i)},k=()=>Object.fromEntries(C.map(([t,n])=>[t,Zv(e.fields[t],n)])),A=e=>vs(e)?Object.fromEntries(e.errors.flatMap(e=>e.field?[[e.field,e.message]]:[])):{},j=async()=>{try{await u.mutateAsync({patch:k(),etag:t.etag})}catch(e){throw H9(e)?await O():vs(e)&&S(A(e)),e}},M=async r=>{let i=[...w?[{op:`update`,resource:e.name,key:n,data:k(),etag:t.etag}]:[],...r];try{await c.batchWrite(i)}catch(e){throw H9(e)?(await O(),await l.invalidateQueries({queryKey:[`list`]}),v(!0)):vs(e)&&S(A(e)),vs(e)?Ble(e,i):e}await Promise.all([l.invalidateQueries({queryKey:U.record(e.name,n)}),l.invalidateQueries({queryKey:[`list`]}),l.invalidateQueries({queryKey:[`page`]}),l.invalidateQueries({queryKey:[`map`]})]),s?.reset()};return{value:E,change:D,save:()=>d.run(async()=>{let e=s?.op()??[];e.length>0?await M(e):await j(),m({}),b({}),S({}),v(!1),g(!1)}),dirty:T,discard:()=>{m({}),b({}),S({}),v(!1),g(!1),s?.reset()},restored:h&&T,dismissRestored:()=>g(!1),linesConflict:_,saving:d.phase===`saving`,phase:d.phase,message:d.message,conflicts:y,errors:x,keepMine:e=>b(t=>U9(t,e)),useTheirs:e=>{b(t=>U9(t,e)),m(t=>U9(t,e))}}},Hle=(e,t,n,r,i,a)=>{let o=W(),s=pm(),c=Object.values(e.fields).filter(t=>t.type===`relation`&&t.relation&&t.name!==e.tenant&&i[t.name]!=null&&n[t.relation.resource]?.primaryKey.length===1),l=Dh({queries:c.map(e=>{let t=n[e.relation.resource],a=String(i[e.name]);return{queryKey:U.relatedLabel(t.name,a),queryFn:async()=>(await R_(s,o,t,[a],r[t.name])).get(a)??a}})}),u=c.map(e=>({kind:`record`,resource:e.relation.resource,key:String(i[e.name])}));return{addresses:Object.fromEntries(c.map((e,t)=>[e.name,u[t]])),labels:Object.fromEntries(c.map((e,t)=>[e.name,l[t]?.data])),records:c.map((e,n)=>({kind:t?.fields[e.name]?.label??G(e.name),label:l[n]?.data??String(i[e.name]),href:qo(u[n],a)}))}},W9=so(),G9=500,K9=(...e)=>{let t=e.filter(e=>!!e);return t.length===1?t[0]:t.map(e=>`(${e})`).join(` AND `)},Ule=(e,t)=>{let n=W(),{resources:r}=K(),i=e.through,a=i?r[i.resource]:void 0,o=i?.key??a?.primaryKey[0],s=i?K9(qa(W9.eq(i.field,t)),i.filter):``,c=kh({queryKey:U.list(a?.name??``,s,``,G9,`related:${o}`),enabled:!!(a&&o),queryFn:async()=>{let e=await n.search(a.name,{filter:s,fields:[o],pageSize:G9});return[...new Set(e.items.flatMap(e=>e[o]===null||e[o]===void 0?[]:[String(e[o])]))]}});return i?c.data?{filter:c.data.length===0?null:K9(qa(W9.in(e.field,c.data)),e.filter),isPending:!1,error:null}:{filter:void 0,isPending:c.isPending,error:c.error}:{filter:K9(qa(W9.eq(e.field,t)),e.filter),isPending:!1,error:null}},Wle=()=>(0,B.jsx)(`div`,{className:`flex flex-col gap-2`,children:Array.from({length:3},(e,t)=>(0,B.jsx)(od,{className:`h-4 w-full`},t))}),Gle=({text:e})=>(0,B.jsx)(`p`,{className:`text-[13px] text-muted-foreground`,children:e??`Nothing here yet.`}),Kle=({item:e,recordKey:t,owner:n})=>{let{resources:r,views:i}=K(),a=r[e.resource],o=a&&i[a.name],s=Ule(e,t),[c,l]=y9(o,`related:${n}:${e.title}`,e.display);if(!a)return null;let u=e.columns??rk(a,o).filter(t=>t!==e.field);return(0,B.jsx)($S,{title:e.title,help:e.help,actions:(0,B.jsx)(O7,{view:o,value:c,onChange:l}),children:s.isPending?(0,B.jsx)(Wle,{}):s.error?(0,B.jsx)(ny,{title:`Could not load`,error:s.error}):s.filter===null||s.filter===void 0?(0,B.jsx)(Gle,{text:e.empty}):(0,B.jsx)(k7,{model:a,view:o,filter:s.filter,sort:e.sort??``,columns:u,limit:e.limit??10,display:c,empty:e.empty},s.filter)})},qle=(e,t)=>t===e.tenant||e.primaryKey.includes(t),Jle=(e,t)=>{if(t&&t.layout.length>0)return t.layout;let n=Object.values(e.fields).filter(t=>!qle(e,t.name)),r=n.filter(e=>!e.readOnly);return[{kind:`section`,title:`Details`,fields:(r.length>0?r:n).map(e=>e.name)}]},Yle=({resource:e,recordKey:t})=>{let{resources:n}=K(),r=n[e],i=Eg(e,t);return r?i.isPending?(0,B.jsx)(Bv,{title:`Loading`,children:`Fetching the record.`}):i.error?(0,B.jsx)(`div`,{className:`p-8`,children:vs(i.error)&&i.error.status===404?(0,B.jsx)(Bv,{title:`Not found`,children:`This record does not exist, or you cannot see it.`}):(0,B.jsx)(ny,{title:`Could not load the record`,error:i.error})}):(0,B.jsx)(Xle,{model:r,recordKey:t,stored:i.data}):(0,B.jsxs)(Bv,{title:`Not found`,children:[`There is no resource called `,e,`.`]})},Xle=({model:e,recordKey:t,stored:n})=>{let r=K(),{basePath:i}=Rh(),{go:a,open:s}=Wv(),c=r.views[e.name],l=c?.names?.singular??G(e.name),u=Ag(e,c,n.record,t),{state:d}=V(),f=(0,o.useMemo)(()=>kle(r.resources,e),[r.resources,e]),p=Lle(f,Ile(f,e,t).items),m=Vle({model:e,stored:n,recordKey:t,mode:c?.saveFeedback??`toast`,subject:u,draftKey:d.kind===`signed-in`?Mle(d.user.id,e.name,t):void 0,lines:p});ite(m.dirty);let h=pm(),g=W(),_=Uv(e.name),v=qk(e),y=Ey(_,`update`)&&n.permissions?.update!==!1,b=Ey(_,`delete`)&&n.permissions?.delete!==!1,x=Kk({model:e,view:c,restore:v,onDeleted:()=>a({kind:`list`,resource:e.name},{replace:!0}),onReview:()=>void h.invalidateQueries({queryKey:U.record(e.name,t)})}),S=Hle(e,c,r.resources,r.views,n.record,i),{fields:C}=w_(),w=Jle(e,c),T=w.flatMap(e=>e.kind===`sidebar`?e.fields:[]),E=e.fields.status?.type===`enum`?String(n.record.status):void 0,D=L9(e,`updated`),O=D&&n.record[D]?Math.max(0,Math.round((Date.now()-Date.parse(String(n.record[D])))/1e3)):void 0,k=e=>c?.fields[e],A=e=>Oy(n.permissions,e)!==`hidden`,j=r=>{let i=e.fields[r],a=Oy(n.permissions,r);if(!i||a===`hidden`)return null;let o=m.conflicts[r];return(0,B.jsx)(QS,{label:k(r)?.label??G(r),help:k(r)?.help,error:m.errors[r],wide:!!k(r)?.multiline,conflict:o===void 0?void 0:{user:{name:`Someone else`,initials:`?`,hue:40},ago:`just now`,theirValue:o||`—`,onKeepMine:()=>m.keepMine(r),onUseTheirs:()=>m.useTheirs(r)},children:(0,B.jsx)(Ty,{field:i,hints:k(r),value:m.value(r),stored:n.record[r],relationLabel:S.labels[r],relationTo:S.addresses[r],locked:!y||a===`read`,invalid:!!m.errors[r],reveal:i.sensitive?()=>g.reveal(e.name,t,r):void 0,resource:e.name,onChange:e=>m.change(r,e)})},i.sensitive?`${r}:${n.etag}`:r)},M=w.findIndex(e=>e.kind===`sidebar`),N=(0,B.jsx)(iC,{title:`Summary`,rows:T.flatMap(t=>{let r=e.fields[t];if(!r||!A(t))return[];let i=ov(r,n.record[t],k(t)),a=r.type===`enum`?(0,B.jsx)(vA,{value:n.record[t],hints:k(t),children:i}):(0,B.jsx)(`strong`,{className:k(t)?.multiline?`whitespace-pre-line break-words`:void 0,children:i}),o=_y(C,r,k(t));return[{label:k(t)?.label??G(t),value:o?(0,B.jsx)(Sy,{shown:o,part:`display`,field:r,value:n.record[t],fallback:a}):a}]})}),ee={model:e,record:n.record,key:t,etag:n.etag,permissions:n.permissions},te=(0,B.jsxs)(B.Fragment,{children:[m.dirty&&(0,B.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Unsaved changes`}),m.dirty&&y&&(0,B.jsx)(H,{className:`max-md:min-h-11`,disabled:m.saving,onClick:m.discard,children:`Discard`}),b&&(0,B.jsx)(H,{variant:`danger`,className:`max-md:min-h-11`,onClick:()=>void x.start({key:t,title:u,etag:n.etag,snapshot:n.record}),children:`Delete`}),y&&(0,B.jsxs)(H,{variant:`primary`,className:`max-md:min-h-11 max-md:flex-1`,loading:m.saving,disabled:!m.dirty&&m.phase!==`saved`,onClick:()=>void m.save(),children:[m.phase===`saved`&&(0,B.jsx)(de,{className:`size-4`}),m.phase===`saved`?`Saved`:`Save`]})]});return(0,B.jsxs)(`div`,{className:`flex flex-1 flex-col`,children:[x.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)(aC,{collection:c?.names?.plural??G(e.name),title:u,status:{label:E?Bo(E,k(`status`)?.valueLabels):l,tone:E?YO(E):`neutral`},lastEditedBy:{ago:O===void 0?`recently`:Hf(O)},actions:(0,B.jsx)(`div`,{className:`hidden items-center gap-4 md:flex`,children:te})}),m.message&&(0,B.jsx)(`div`,{className:`mt-4`,children:(0,B.jsx)(ny,{title:`Not saved`,error:Error(m.message)})}),m.linesConflict&&(0,B.jsx)(`div`,{className:`mt-4`,children:(0,B.jsx)(ny,{title:`The lines were changed by someone else`,error:Error(`The lines were reloaded. Your new order is kept: Save again to apply it, or Discard to drop it.`)})}),m.restored&&(0,B.jsxs)(`div`,{className:`mt-4 flex items-center justify-between gap-3 rounded-lg border bg-surface px-3 py-2 text-[13px]`,role:`status`,children:[(0,B.jsx)(`span`,{children:`Your unsaved changes were restored.`}),(0,B.jsxs)(`span`,{className:`flex gap-2`,children:[(0,B.jsx)(H,{size:`sm`,onClick:m.dismissRestored,children:`Keep`}),(0,B.jsx)(H,{size:`sm`,onClick:m.discard,children:`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:[w.flatMap((r,i)=>{if(r.kind===`related`)return[(0,B.jsx)(Kle,{item:r,recordKey:t,owner:e.name},`related:${r.title}`)];if(r.kind===`custom`)return r.sidebar?[]:[(0,B.jsx)(R9,{item:r,scope:ee},`custom:${i}`)];if(r.kind===`map`)return r.sidebar?[]:[(0,B.jsx)(z9,{item:r,record:n.record},`map:${i}`)];if(r.kind!==`section`)return[];let a=r.fields.filter(t=>e.fields[t]&&A(t));return a.length===0?[]:[(0,B.jsx)($S,{title:r.title,help:r.help,children:(0,B.jsx)(`div`,{className:`grid grid-cols-1 gap-x-6 gap-y-5 sm:grid-cols-2`,children:a.map(j)})},r.title)]}),f&&(0,B.jsx)(jle,{lines:f,draft:p,vatRate:Number(n.record.vatRate??21)/100,saving:m.saving})]}),(0,B.jsxs)(`aside`,{className:`space-y-4 md:pt-8`,children:[(0,B.jsx)(Ole,{model:e,stored:n,recordKey:t}),M===-1&&N,w.map((e,t)=>e.kind===`custom`&&e.sidebar?(0,B.jsx)(R9,{item:e,scope:ee},`custom:${t}`):e.kind===`map`&&e.sidebar?(0,B.jsx)(z9,{item:e,record:n.record},`map:${t}`):t===M?(0,B.jsx)(o.Fragment,{children:N},`summary`):null),(0,B.jsx)(iC,{title:`Details`,rows:[L9(e,`created`),D].flatMap(t=>{let r=t?e.fields[t]:void 0;return t&&r&&A(t)?[{label:k(t)?.label??G(t),value:ov(r,n.record[t],k(t))}]:[]})}),S.records.length>0&&(0,B.jsx)(rC,{title:`Related records`,children:(0,B.jsx)(nC,{records:S.records,onNavigate:s})})]})]})]})}),(m.dirty||b||y)&&(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:te})]})},Zle=e=>vs(e)?e.status===401||e.status===403?`It did not accept your sign-in: ${e.message}`:e.message:`It did not answer.`,Qle=({status:e})=>{let t=pm();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.jsxs)(`h1`,{className:`text-[15px] font-semibold`,children:[`Cannot reach `,e.source.label]}),(0,B.jsxs)(`p`,{className:`mt-1 text-[13px] text-muted-foreground`,children:[Zle(e.error),` The rest of the app works as before.`]}),(0,B.jsx)(H,{className:`mt-3`,onClick:()=>void t.refetchQueries({queryKey:U.sourceMetas(e.source.url)}),children:`Try again`})]})}):(0,B.jsxs)(`div`,{className:`flex h-full min-h-48 flex-1 items-center justify-center gap-2 text-[13px] text-muted-foreground`,children:[(0,B.jsx)(Zd,{}),` Loading from `,e.source.label]})},$le=so(),eue=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??G(t.name)}]}),tue=e=>{let t=e.map(e=>e.label.toLowerCase());return t.length===0?`Search`:t.length===1?`Search ${t[0]}`:t.length===2?`Search ${t[0]} and ${t[1]}`:`Search ${t[0]}, ${t[1]} and more`},nue=e=>qa($le.search(e.trim())),q9=e=>{let t=e.view?.searchResult?.title;return t?.length?t:[kg(e.model,e.view)]},J9=e=>{let t=q9(e);return e.view?.searchResult?.subtitle??e.model.search?.find(e=>!t.includes(e))},rue=e=>{let t=J9(e),n=[...q9(e),...t?[t]:[],...e.model.search??[]];return[...new Set([...e.model.primaryKey,...n.filter(t=>Object.hasOwn(e.model.fields,t))])]},Y9=(e,t,n)=>{let r=t[n];return r==null?``:e.model.fields[n]?.type===`enum`?Bo(String(r),e.view?.fields[n]?.valueLabels):String(r)},iue=(e,t,n,r=``)=>{let i=mo(Mg(e.model,t)),a=q9(e),o=J9(e),s=Ka(e.model,t,n,[...a,...o?[o]:[]])??o,c=s?Y9(e,t,s):``;return{id:i,title:a.map(n=>Y9(e,t,n)).filter(Boolean).join(` `)||i,...c&&{subtitle:c},href:qo({kind:`record`,resource:e.model.name,key:i},r)}},aue=()=>{let e=K(),t=W(),{basePath:n}=Rh(),r=(0,o.useMemo)(()=>eue(e),[e]),[i,a]=(0,o.useState)(``),s=i.trim(),c=LO(s,200),l=s.length>=2,u=l&&c.length>=2,d=Dh({queries:r.map(e=>({queryKey:[`global-search`,e.model.name,c],enabled:u,staleTime:1/0,gcTime:0,queryFn:()=>t.list(e.model.name,{filter:nue(c),pageSize:5,fields:rue(e)})}))}),f=r.flatMap((e,t)=>{let r=d[t];if(!u||!r)return[];if(r.error)return[{id:e.model.name,label:e.label,hits:[],failed:!0}];let i=(r.data?.items??[]).map(t=>iue(e,t,c,n));return i.length>0?[{id:e.model.name,label:e.label,hits:i}]:[]});return{available:r.length>0,placeholder:tue(r),text:i,setText:a,query:u?c:``,loading:l&&(s!==c||d.some(e=>e.isFetching)),groups:f}},oue=e=>!!(e?.updateAvailable&&e.indicator),X9={immediate:`Updates as soon as a release is out`,weekly:`Updates at a set time every week`,scheduled:`Updates at the time set for this release`,manual:`Updates only when asked to`},sue=e=>e.updating?`Updating now`:e.nextUpdateAt?`${X9[e.policy]}: next on ${zf(Date.parse(e.nextUpdateAt))} UTC`:X9[e.policy],cue=e=>vs(e)&&e.status===409?`Already on the latest version, or an update is running.`:vs(e)&&e.status===403?`Only an admin can update the runtime.`:`The update could not be started. Try again later.`,lue=18e5,uue=3e4,due=e=>{let t=Tg(),n=(0,o.useRef)(t);n.current=t;let r=t!==void 0;return(0,o.useMemo)(()=>r?Uu({url:e,token:()=>n.current}):void 0,[e,r])},fue=e=>{let[t,n]=(0,o.useState)(),[r,i]=(0,o.useState)(!1),[a,s]=(0,o.useState)(),[c,l]=(0,o.useState)(),u=t?.updating??!1;return(0,o.useEffect)(()=>{if(!e)return;let t=!0,r=()=>e.status().then(e=>{t&&(n(e),l(void 0))},e=>t&&l(e));r();let i=setInterval(()=>void r(),u?uue:lue);return()=>{t=!1,clearInterval(i)}},[e,u]),{status:t,update:(0,o.useCallback)(async()=>{e&&(i(!0),s(void 0),await e.update().then(n,s),i(!1))},[e]),requesting:r,error:a,checkError:c}},Z9=({label:e,value:t})=>(0,B.jsxs)(`div`,{className:`flex justify-between gap-4 py-1 text-[13px]`,children:[(0,B.jsx)(`span`,{className:`text-muted-foreground`,children:e}),(0,B.jsx)(`span`,{className:`font-medium tabular-nums`,children:t})]}),Q9=({client:e})=>{let{status:t,update:n,requesting:r,error:i,checkError:a}=fue(e),[s,c]=(0,o.useState)(!1);return!t||!s&&!oue(t)?null:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(H,{size:`sm`,variant:`ghost`,"aria-label":`Update available`,title:`Update available`,onClick:()=>c(!0),className:`max-md:size-9 max-md:p-0`,children:[(0,B.jsx)(xe,{className:`size-3.5 text-primary`}),(0,B.jsx)(`span`,{className:`max-md:sr-only`,children:`Update`})]}),s&&(0,B.jsxs)(Kf,{title:`Runtime update`,description:sue(t),onClose:()=>c(!1),actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(H,{onClick:()=>c(!1),children:`Close`}),(0,B.jsx)(H,{variant:`primary`,loading:r,disabled:t.updating||!t.updateAvailable,onClick:()=>void n(),children:t.updating?`Updating…`:`Update now`})]}),children:[(0,B.jsx)(Z9,{label:`Current version`,value:t.version}),(0,B.jsx)(Z9,{label:`Latest version`,value:t.latest}),i!==void 0&&(0,B.jsx)(`p`,{role:`alert`,className:`mt-3 text-[13px] text-danger-text`,children:cue(i)}),a!==void 0&&(0,B.jsx)(`p`,{className:`mt-3 text-[13px] text-muted-foreground`,children:`The status could not be checked again; this is the last one read.`})]})]})},pue=({url:e})=>(0,B.jsx)(Q9,{client:due(e)}),mue=({url:e,client:t})=>t?(0,B.jsx)(Q9,{client:t}):(0,B.jsx)(pue,{url:e}),hue=({signIn:e,onStop:t})=>{let[n,r]=(0,o.useState)(!1),[i,a]=(0,o.useState)(),s=async()=>{r(!0),a(void 0);try{await t()}catch(e){if(!(e instanceof Ks))throw e;a(df(e)),r(!1)}};return(0,B.jsxs)(`div`,{role:`region`,"aria-label":`Staff session`,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-[13px] text-warning-text`,children:[(0,B.jsx)(see,{"aria-hidden":!0,className:`size-4 shrink-0`}),(0,B.jsxs)(`p`,{className:`min-w-64 flex-1 break-words`,children:[(0,B.jsx)(`span`,{className:`font-semibold`,children:e.staffName??e.staff}),` is signed in as `,(0,B.jsx)(`span`,{className:`font-semibold`,children:e.user}),` until`,` `,zf(Date.parse(e.expiresAt)),`. Reason: `,e.reason]}),i&&(0,B.jsx)(`p`,{role:`alert`,className:`text-xs font-medium text-danger-text`,children:i}),(0,B.jsx)(H,{size:`sm`,loading:n,onClick:()=>void s(),children:`Stop staff session`})]})},gue=(e,t,n)=>({filter:n.filter??``,orderBy:n.orderBy??Tv(e,t),pageSize:n.limit??3,fields:[...new Set([...e.primaryKey,kg(e,t),n.status])]}),_ue=(e,t,n,r,i,a)=>r.map(r=>{let o=mo(Mg(e,r)),s=String(r[n.status]??``);return{id:o,label:Ag(e,t,r,o),href:qo({kind:`record`,resource:e.name,key:o},i),status:e.fields[n.status]?.type===`enum`&&s?Bo(s,t.fields[n.status]?.valueLabels):s,tone:n.tones[s]??`neutral`,pulse:n.pulse?.includes(s)??!1,active:o===a}}),vue=(e,t,n,r,i)=>{let a=n.find(t=>mo(Mg(e,t))===r);return a!==void 0&&t.some(e=>!Object.is(a[e],i[e]))},$9=({model:e,request:t})=>U.navRecent(e.name,t.filter,t.orderBy,t.pageSize),yue=e=>{let t=pm();(0,o.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($9(n));e&&vue(n.model,n.request.fields,e.items,a,o)&&t.invalidateQueries({queryKey:$9(n),exact:!0})}}),[t,e])},bue=(e,t,n)=>{let r=W(),i=(0,o.useMemo)(()=>{let t=o9(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:gue(r,n,i)}]:[]})},[e]);yue(i);let a=Dh({queries:i.map(e=>({queryKey:$9(e),queryFn:()=>r.list(e.model.name,e.request),refetchOnWindowFocus:!0}))});return Object.fromEntries(i.map(({model:e,view:r,recent:i},o)=>{let s=a[o];if(s.isPending)return[e.name,{state:`loading`}];if(s.isError)return[e.name,{state:`error`}];let c=n.resource===e.name?n.key:void 0;return[e.name,{state:`ready`,records:_ue(e,r,i,s.data.items,t,c)}]}))},xue=e=>e?.kind===`page`?e.page:e?.resource,Sue=e=>e?.kind===`record`?e:void 0,Cue=({workspace:e,sidebarMode:t,assistant:n,runtime:r})=>{let i=K(),{state:a,session:s,signOut:c,stopStaffSession:l,organizations:u}=V(),d=$h();if(a.kind!==`signed-in`&&a.kind!==`visitor`)throw Error(`The shell is only rendered for a signed-in user or a visitor`);let f=a.kind===`signed-in`?a.user:void 0,p=a.kind===`signed-in`?a.staff:void 0,{path:m,params:h,basePath:g}=Rh(),{address:_,go:v,open:y}=Wv(),b=xue(_),x=Sue(_),S=aue(),C=Rg(),w=yce(i,g,bue(i,g,{resource:b,key:x?.key})),T=Object.keys(i.pages)[0],E=Object.keys(i.resources)[0],D=_?.kind===`page`?i.pages[_.page]:void 0;(0,o.useEffect)(()=>{m===`/`&&(T?v({kind:`page`,page:T},{replace:!0}):E&&v({kind:`list`,resource:E},{replace:!0}))},[m,T,E,v]);let O=_?.kind===`page`?void 0:_?.resource,k=O?zv(i,O):void 0,A=O?i.views[O]:void 0,j=w.find(e=>e.items.some(e=>e.id===b)),M=O?i.resources[O]:void 0,N=Eg(x?.resource??``,x?.key??``,!!(M&&x)),ee=M&&x&&N.data?Ag(M,A,N.data.record,x.key):void 0,te=!!x&&(N.isLoading||k?.state===`loading`),{shell:ne}=w_(),P=ne?.actions,re=ne?.rightPanel,[ie,ae]=(0,o.useState)(!1),F=i.assistant?.url,oe=F&&(0,B.jsx)(Wte,{open:ie,onToggle:()=>ae(!ie)}),se=F&&ie&&(0,B.jsx)(Kte,{url:F,client:n,page:h.size>0?`${m}?${h}`:m,onClose:()=>ae(!1)}),ce=i.errorReporting;(0,o.useEffect)(()=>{ce&&y_(ce)},[ce]);let I=i.runtime?.url,le=I&&(0,B.jsx)(mue,{url:I,client:r}),ue=gce((0,o.useCallback)(()=>n9(g),[g]),!!f),de=f&&hce(f,ue.current),fe=de?xg(de):!1,pe=Sle(),me=ace(!!(u&&f)),he=me.current,ge=!!u&&he!==void 0&&!he.organization,_e=u&&f?og[m]:void 0,ve=f?m===`/-/account`?`Sign-in & security`:m===`/-/sign-in-policy`?`Sign-in policy`:_e:void 0,ye=ve?[ve]:Yte({basePath:g,address:_,group:j?.label,page:D,resourceLabel:A?.names?.plural??(O&&G(O)),recordTitle:ee,recordLoading:te}),be=f&&m===`/-/account`?(0,B.jsx)($p,{email:f.email}):f&&m===`/-/sign-in-policy`?fe?(0,B.jsx)(dm,{}):(0,B.jsx)(Bv,{title:`Admins only`,children:`Only an admin can change how people sign in.`}):_e&&m===`/-/organization`?(0,B.jsx)(uce,{current:he,basePath:g,onChanged:me.reload}):_e&&(m===`/-/organization/members`||m===`/-/organization/invitations`)?lg(he)?m===`/-/organization/members`?(0,B.jsx)(tce,{current:he}):(0,B.jsx)(ice,{current:he}):(0,B.jsx)(Bv,{title:`Owners and admins only`,children:`Only the organization's owners and admins manage its members.`}):_e&&m===`/-/organizations`||ge?(0,B.jsx)(mce,{state:me,basePath:g}):_?_.kind===`page`?D?(0,B.jsx)(ole,{name:D.name},D.name):(0,B.jsxs)(Bv,{title:`Not found`,children:[`There is no page called `,_.page,`.`]}):k&&k.state!==`ready`?(0,B.jsx)(Qle,{status:k}):_.kind===`create`?(0,B.jsx)(_C,{resource:_.resource,values:_.values},`${_.resource}/new?${new URLSearchParams(_.values).toString()}`):_.kind===`record`?(0,B.jsx)(Yle,{resource:_.resource,recordKey:_.key},`${_.resource}/${_.key}`):(0,B.jsx)($se,{address:_},_.resource):m===`/`?(0,B.jsx)(Bv,{title:`Choose a resource`,children:`Pick one from the sidebar.`}):(0,B.jsx)(Bv,{title:`Not found`,children:`There is nothing at this address.`}),xe=(0,B.jsx)(af,{pageScroll:!0,sidebarMode:t??`text-small`,activeItem:b??``,breadcrumb:ye,user:de&&Sg(de),onSignOut:f&&(()=>void c()),signIn:f?void 0:d.link(),workspace:he?.organization?.name??e,navGroups:w,bottomBar:Jte(i,g,b),userMenu:[..._ce(i,g,b),...u&&f?ug(g,m,he):[],...f?uee(g,m,fe):[]],organizations:u&&{...he?.organization&&{current:{id:he.organization.id,name:he.organization.name}},others:me.organizations.filter(e=>e.id!==he?.organization?.id),onSwitch:e=>void s.organizations.switchTo(e).then(()=>n9(g))},theme:{preference:C.preference,onChange:C.choose},roles:ue.current?.active?{active:ue.current.active,roles:ue.current.roles,onSwitch:ue.switchTo}:void 0,onNavigate:y,search:S.available?{placeholder:S.placeholder,text:S.text,onTextChange:S.setText,query:S.query,loading:S.loading,groups:S.groups,onSelect:y}:void 0,actions:(P||le||oe)&&(0,B.jsxs)(B.Fragment,{children:[P&&(0,B.jsx)(by,{name:`shell.actions`,fallback:null,children:(0,B.jsx)(P,{})}),le,oe]}),rightPanel:(re||se)&&(0,B.jsxs)(B.Fragment,{children:[re&&(0,B.jsx)(by,{name:`shell.rightPanel`,fallback:null,children:(0,B.jsx)(re,{})}),se]}),children:be}),Se=fe&&pe.length>0;return!p&&!Se?xe:(0,B.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[p&&(0,B.jsx)(hue,{signIn:p,onStop:l}),Se&&(0,B.jsx)(wle,{off:pe}),(0,B.jsx)(`div`,{className:`min-h-0 flex-1`,children:xe})]})},wue=({baseUrl:e,client:t,sources:n,workspace:r,sidebarMode:i,ui:a,assistant:o,runtime:s,pluginLoader:c})=>{let{state:l,session:u,markSignedOut:d}=V();return(0,B.jsx)(Ih,{baseUrl:e,client:t,sources:n,token:l.kind===`visitor`?void 0:u.token,onUnauthenticated:d,children:(0,B.jsx)(Hv,{children:(0,B.jsx)(qg,{children:(0,B.jsx)(Cle,{ui:a,...c&&{loader:c},children:(0,B.jsx)(Cue,{workspace:r,sidebarMode:i,assistant:o,runtime:s})})})})})},Tue=({auth:e,workspace:t,basePath:n,initialUrl:r,...i})=>(0,B.jsx)(Lg,{children:(0,B.jsx)(Tf,{session:e,children:(0,B.jsx)(nte,{basePath:n,initialUrl:r,children:(0,B.jsx)(_g,{workspace:t,children:(0,B.jsx)(wue,{workspace:t,...i})})})})});export{d_ as A,Jg as B,M_ as C,S_ as D,O_ as E,t_ as F,Fh as G,Tg as H,e_ as I,b as J,ip as K,Qg as L,a_ as M,i_ as N,x_ as O,r_ as P,Xg as R,N_ as S,Vte as T,Ih as U,Eg as V,W,$k as _,N9 as a,Wv as b,k9 as c,are as d,ore as f,Wne as g,Qne as h,B9 as i,c_ as j,g_ as k,w9 as l,Zne as m,H9 as n,P9 as o,ZA as p,z as q,V9 as r,fle as s,Tue as t,u9 as u,Xk as v,j_ as w,Pv as x,Gv as y,Yg as z};
66
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Ooe(e,t){if(e){if(typeof e==`string`)return s7(e,t);var n={}.toString.call(e).slice(8,-1);return n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`?Array.from(e):n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?s7(e,t):void 0}}function s7(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function koe(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r,i,a,o,s=[],c=!0,l=!1;try{if(a=(n=n.call(e)).next,t===0){if(Object(n)!==n)return;c=!1}else for(;!(c=(r=a.call(n)).done)&&(s.push(r.value),s.length!==t);c=!0);}catch(e){l=!0,i=e}finally{try{if(!c&&n.return!=null&&(o=n.return(),Object(o)!==o))return}finally{if(l)throw i}}return s}}function Aoe(e){if(Array.isArray(e))return e}var joe=()=>(I0(),null);function c7(e){if(typeof e==`number`)return e;if(typeof e==`string`){var t=parseFloat(e);if(!Number.isNaN(t))return t}return 0}var Moe=(0,o.forwardRef)((e,t)=>{var n=(0,o.useRef)(null),r=o7((0,o.useState)({containerWidth:c7(e.style?.width),containerHeight:c7(e.style?.height)}),2),i=r[0],a=r[1],s=(0,o.useCallback)((e,t)=>{a(n=>{var r=Math.round(e),i=Math.round(t);return n.containerWidth===r&&n.containerHeight===i?n:{containerWidth:r,containerHeight:i}})},[]),c=(0,o.useCallback)(e=>{if(typeof t==`function`&&t(e),n.current!=null&&(n.current.disconnect(),n.current=null),e!=null&&typeof ResizeObserver<`u`){var r=e.getBoundingClientRect(),i=r.width,a=r.height;s(i,a);var o=new ResizeObserver(e=>{var t=e[0];if(t!=null){var n=t.contentRect,r=n.width,i=n.height;s(r,i)}});o.observe(e),n.current=o}},[t,s]);return(0,o.useEffect)(()=>()=>{n.current?.disconnect()},[s]),o.createElement(o.Fragment,null,o.createElement(xz,{width:i.containerWidth,height:i.containerHeight}),o.createElement(`div`,a7({ref:c},e)))}),Noe=(0,o.forwardRef)((e,t)=>{var n=e.width,r=e.height,i=o7((0,o.useState)({containerWidth:c7(n),containerHeight:c7(r)}),2),a=i[0],s=i[1],c=(0,o.useCallback)((e,t)=>{s(n=>{var r=Math.round(e),i=Math.round(t);return n.containerWidth===r&&n.containerHeight===i?n:{containerWidth:r,containerHeight:i}})},[]),l=(0,o.useCallback)(e=>{if(typeof t==`function`&&t(e),e!=null){var n=e.getBoundingClientRect(),r=n.width,i=n.height;c(r,i)}},[t,c]);return o.createElement(o.Fragment,null,o.createElement(xz,{width:a.containerWidth,height:a.containerHeight}),o.createElement(`div`,a7({ref:l},e)))}),Poe=(0,o.forwardRef)((e,t)=>{var n=e.width,r=e.height;return o.createElement(o.Fragment,null,o.createElement(xz,{width:n,height:r}),o.createElement(`div`,a7({ref:t},e)))}),Foe=(0,o.forwardRef)((e,t)=>{var n=e.width,r=e.height;return typeof n==`string`||typeof r==`string`?o.createElement(Noe,a7({},e,{ref:t})):typeof n==`number`&&typeof r==`number`?o.createElement(Poe,a7({},e,{width:n,height:r,ref:t})):o.createElement(o.Fragment,null,o.createElement(xz,{width:n,height:r}),o.createElement(`div`,a7({ref:t},e)))});function Ioe(e){return e?Moe:Foe}var Loe=(0,o.forwardRef)((e,t)=>{var n=e.children,r=e.className,i=e.height,a=e.onClick,s=e.onContextMenu,c=e.onDoubleClick,l=e.onMouseDown,u=e.onMouseEnter,d=e.onMouseLeave,f=e.onMouseMove,p=e.onMouseUp,m=e.onTouchEnd,h=e.onTouchMove,g=e.onTouchStart,_=e.style,v=e.width,y=e.responsive,b=e.dispatchTouchEvents,x=b===void 0||b,S=(0,o.useRef)(null),C=XN(),w=o7((0,o.useState)(null),2),T=w[0],E=w[1],D=o7((0,o.useState)(null),2),O=D[0],k=D[1],A=Soe(),j=cz(),M=j?.width>0?j.width:v,N=j?.height>0?j.height:i,ee=(0,o.useCallback)(e=>{A(e),typeof t==`function`&&t(e),E(e),k(e),e!=null&&(S.current=e)},[A,t,E,k]),te=(0,o.useCallback)(e=>{C(S5(e)),C(B5({handler:a,reactEvent:e}))},[C,a]),ne=(0,o.useCallback)(e=>{C(w5(e)),C(B5({handler:u,reactEvent:e}))},[C,u]),P=(0,o.useCallback)(e=>{C(KQ()),C(B5({handler:d,reactEvent:e}))},[C,d]),re=(0,o.useCallback)(e=>{C(w5(e)),C(B5({handler:f,reactEvent:e}))},[C,f]),ie=(0,o.useCallback)(()=>{C(N5())},[C]),ae=(0,o.useCallback)(()=>{C(P5())},[C]),F=(0,o.useCallback)(e=>{C(M5(e.key))},[C]),oe=(0,o.useCallback)(e=>{C(B5({handler:s,reactEvent:e}))},[C,s]),se=(0,o.useCallback)(e=>{C(B5({handler:c,reactEvent:e}))},[C,c]),ce=(0,o.useCallback)(e=>{C(B5({handler:l,reactEvent:e}))},[C,l]),I=(0,o.useCallback)(e=>{C(B5({handler:p,reactEvent:e}))},[C,p]),le=(0,o.useCallback)(e=>{C(B5({handler:g,reactEvent:e}))},[C,g]),ue=(0,o.useCallback)(e=>{x&&C(G5(e)),C(B5({handler:h,reactEvent:e}))},[C,x,h]),de=(0,o.useCallback)(e=>{C(B5({handler:m,reactEvent:e}))},[C,m]),fe=Ioe(y);return o.createElement(u0.Provider,{value:T},o.createElement(Dre.Provider,{value:O},o.createElement(fe,{width:M??_?.width,height:N??_?.height,className:$A(`recharts-wrapper`,r),style:Coe({position:`relative`,cursor:`default`,width:M,height:N},_),onClick:te,onContextMenu:oe,onDoubleClick:se,onFocus:ie,onBlur:ae,onKeyDown:F,onMouseDown:ce,onMouseEnter:ne,onMouseLeave:P,onMouseMove:re,onMouseUp:I,onTouchEnd:de,onTouchMove:ue,onTouchStart:le,ref:ee},o.createElement(joe,null),n)))}),Roe=[`width`,`height`,`responsive`,`children`,`className`,`style`,`compact`,`title`,`desc`];function zoe(e,t){if(e==null)return{};var n,r,i=Boe(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function Boe(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}var Voe=(0,o.forwardRef)((e,t)=>{var n=e.width,r=e.height,i=e.responsive,a=e.children,s=e.className,c=e.style,l=e.compact,u=e.title,d=e.desc,f=rj(zoe(e,Roe));return l?o.createElement(o.Fragment,null,o.createElement(xz,{width:n,height:r}),o.createElement(n7,{otherAttributes:f,title:u,desc:d},a)):o.createElement(Loe,{className:s,style:c,width:n,height:r,responsive:i??!1,onClick:e.onClick,onMouseLeave:e.onMouseLeave,onMouseEnter:e.onMouseEnter,onMouseMove:e.onMouseMove,onMouseDown:e.onMouseDown,onMouseUp:e.onMouseUp,onContextMenu:e.onContextMenu,onDoubleClick:e.onDoubleClick,onTouchStart:e.onTouchStart,onTouchMove:e.onTouchMove,onTouchEnd:e.onTouchEnd},o.createElement(n7,{otherAttributes:f,title:u,desc:d,ref:t},o.createElement(u8,null,a)))});function l7(){return l7=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},l7.apply(null,arguments)}function u7(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function Hoe(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?u7(Object(n),!0).forEach(function(t){Uoe(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):u7(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function Uoe(e,t,n){return(t=Woe(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Woe(e){var t=Goe(e,`string`);return typeof t==`symbol`?t:t+``}function Goe(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}var Koe=Hoe({accessibilityLayer:!0,barCategoryGap:`10%`,barGap:4,layout:`horizontal`,margin:{top:5,right:5,bottom:5,left:5},responsive:!1,reverseStackOrder:!1,stackOffset:`none`,syncMethod:`index`},Z5),qoe=(0,o.forwardRef)(function(e,t){var n=LM(e.categoricalChartProps,Koe),r=e.chartName,i=e.defaultTooltipEventType,a=e.validateTooltipEventTypes,s=e.tooltipPayloadSearcher,c=e.categoricalChartProps,l={chartName:r,defaultTooltipEventType:i,validateTooltipEventTypes:a,tooltipPayloadSearcher:s,eventEmitter:void 0};return o.createElement(ooe,{preloadedState:{options:l},reduxStoreName:c.id??r},o.createElement(J6,{chartData:c.data}),o.createElement(coe,{layout:n.layout,margin:n.margin}),o.createElement(uoe,{throttleDelay:n.throttleDelay,throttledEvents:n.throttledEvents}),o.createElement(loe,{baseValue:n.baseValue,accessibilityLayer:n.accessibilityLayer,barCategoryGap:n.barCategoryGap,maxBarSize:n.maxBarSize,stackOffset:n.stackOffset,barGap:n.barGap,barSize:n.barSize,syncId:n.syncId,syncMethod:n.syncMethod,className:n.className,reverseStackOrder:n.reverseStackOrder}),o.createElement(Voe,l7({},n,{ref:t})))}),Joe=[`axis`,`item`],Yoe=(0,o.forwardRef)((e,t)=>o.createElement(qoe,{chartName:`BarChart`,defaultTooltipEventType:`axis`,validateTooltipEventTypes:Joe,tooltipPayloadSearcher:g0,categoricalChartProps:e,ref:t})),d7=e=>e.reduce((e,t)=>e+t.count,0),Xoe=e=>{let t=Math.floor(e.length/2),n=d7(e.slice(0,t)),r=d7(e.slice(e.length-t));return n===0?0:(r-n)/n*100},Zoe=({active:e,payload:t,noun:n})=>{let r=t?.[0]?.payload;return!e||!r?null:(0,B.jsxs)(`div`,{className:`rounded-md border bg-background px-2.5 py-1.5 text-xs shadow-pop`,children:[(0,B.jsx)(`div`,{className:`text-muted-foreground`,children:Lf(r.at)}),(0,B.jsxs)(`div`,{className:`font-semibold tabular-nums`,children:[Af(r.count),` `,n]})]})},f7={fontSize:11,fill:`var(--muted-foreground)`},Qoe=({title:e=`Orders created`,noun:t=`orders`,defaultGranularity:n=`day`,data:r,granularity:i,onGranularityChange:a,periodLabel:s,className:c})=>{let[l,u]=(0,o.useState)(n),d=i??l,f=a??u,p=r??BS(d),m=Wu(`(min-width: 640px)`),h=Xoe(p);return(0,B.jsxs)(`section`,{className:z(`rounded-lg border bg-background px-4 pb-2 pt-3`,c),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:`text-[13px] font-semibold`,children:e}),(0,B.jsx)(`span`,{className:`text-[13px] font-semibold tabular-nums`,children:Af(d7(p))}),(0,B.jsxs)(`span`,{className:z(`text-xs font-medium tabular-nums`,h>=0?`text-success-text`:`text-danger-text`),children:[h>=0?`+`:`−`,Math.abs(h).toFixed(1),`%`]}),(0,B.jsx)(`span`,{className:`hidden text-xs text-muted-foreground sm:inline`,children:s??`last ${d===`day`?`30 days`:`12 weeks`}`})]}),(0,B.jsx)(Ed,{value:d,onChange:f,options:[{value:`day`,label:`Day`},{value:`week`,label:`Week`}]})]}),(0,B.jsx)(`div`,{className:`mt-2 h-24`,children:(0,B.jsx)(uz,{width:`100%`,height:`100%`,children:(0,B.jsxs)(Yoe,{data:p,margin:{top:4,right:0,bottom:0,left:0},barCategoryGap:d===`day`?`22%`:`30%`,children:[(0,B.jsx)(B8,{vertical:!1,stroke:`var(--border)`}),(0,B.jsx)(m5,{dataKey:`at`,padding:{left:4,right:m?4:18},tickFormatter:Rf,tick:f7,axisLine:!1,tickLine:!1,interval:d===`day`?m?4:9:m?1:3,height:18}),(0,B.jsx)(y5,{width:m?36:28,tick:f7,axisLine:!1,tickLine:!1,tickCount:3}),(0,B.jsx)($0,{cursor:{fill:`var(--muted)`},content:(0,B.jsx)(Zoe,{noun:t}),isAnimationActive:!1}),(0,B.jsx)(o5,{dataKey:`count`,fill:`var(--primary)`,radius:[2,2,0,0],isAnimationActive:!1})]})})})]})},$oe={"7d":`last 7 days`,"30d":`last 30 days`,"90d":`last 90 days`,"1y":`last year`,all:`all time`},ese=({resource:e,chart:t,title:n,noun:r,filter:i})=>{let[a,s]=(0,o.useState)(t.granularity===`week`?`week`:`day`),c=a===`week`?`90d`:t.range,l=ZA(e,{field:t.field,range:c,granularity:a,filter:i}).data?.points.map(e=>({at:Date.parse(`${e.bucket}Z`),count:e.count}))??[];return(0,B.jsx)(Qoe,{title:n,noun:r,data:l,granularity:a,onGranularityChange:s,periodLabel:a===`week`?`last 12 weeks`:$oe[c]})},tse=({value:e,onCommit:t,placeholder:n,className:r})=>{let[i,a]=(0,o.useState)(e);return(0,o.useEffect)(()=>a(e),[e]),(0,o.useEffect)(()=>{if(i===e)return;let n=setTimeout(()=>t(i),350);return()=>clearTimeout(n)},[i,e,t]),(0,B.jsx)(Yd,{wrapperClassName:z(`min-w-0 flex-1 sm:w-72 sm:flex-initial`,r),leading:(0,B.jsx)(qt,{className:`size-4`}),placeholder:n,"aria-label":`Search`,value:i,onChange:e=>a(e.target.value),onKeyDown:e=>e.key===`Enter`&&t(i)})},p7=(e,t,n,r)=>e.map(e=>{let i=t.fields[e.id],a=i&&_y(r,i,n?.fields[e.id]);return a?{...e,render:t=>(0,B.jsx)(Sy,{shown:a,part:`cell`,field:i,value:t[e.id],fallback:xD(e,e.value?e.value(t):t[e.id])})}:e}),nse=({model:e,view:t,target:n,children:r})=>{let i=mA(e.name,t.listOf,!0),a=t.names?.plural??G(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)(of,{title:a,subtitle:t.help}),e]});if(i.error)return o((0,B.jsx)(ny,{title:`Could not load your ${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)(od,{className:`h-24`},t))}));let s=fA(n,i.data);return s?r(s):o((0,B.jsxs)(`p`,{className:`py-8 text-center text-[13px] text-muted-foreground`,children:[`No `,a.toLowerCase(),` yet.`]}))},m7=so(),rse={start:0,end:0},ise=(e,t,n)=>{let r=Sk(jk(t,e),n);return r.ok?Object.fromEntries(Object.entries(r.state.facets).filter(([t,n])=>e.fields[t]?.type===`relation`&&n.length>0)):{}},ase=(e,t,n)=>{let r=e=>t?.fields[e]?.label??G(e),i=jk(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,Bo(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:Nk(t,e.id)})),toggles:i.toggles?.map(e=>({...e,label:r(e.id)}))}},h7=(e,t,n,r={})=>{let i=ase(e,t,r),a=Sk(i,n);if(!a.ok)return[{key:`unreadable`,label:`A filter that cannot be read`}];let o=a.extras.map((e,t)=>({key:`extra:${t}`,label:e.kind===`search`?`"${e.text}"`:qa(e)}));return[...OO(i,a.state),...o]},ose=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]))}])),sse=(e,t,n)=>{if(typeof n!=`string`||n===``)return e;let r=m7.gt(t,{kind:`timestamp`,value:new Date(n).toISOString(),span:rse}),i=oa(e);if(!i.ok)throw Error(`The saved filter cannot be read: ${i.errors.map(e=>e.message).join(`; `)}`);return qa(i.ast?m7.and(i.ast,r):r)},cse=(e,t)=>typeof t!=`string`||t===``?!0:typeof e!=`string`||e===``?!1:new Date(e).getTime()>new Date(t).getTime(),g7=`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`,_7=({chips:e,className:t})=>(0,B.jsx)(`ul`,{className:z(`flex flex-wrap gap-1.5`,t),"aria-label":`Filters`,children:e.map(e=>(0,B.jsx)(`li`,{className:g7,children:e.label},e.key))}),v7=({chips:e})=>(0,B.jsx)(`span`,{className:`flex flex-wrap gap-1.5`,children:e.map((e,t)=>(0,B.jsxs)(`span`,{className:g7,children:[t>0&&(0,B.jsx)(`span`,{className:`sr-only`,children:`, `}),e.label]},e.key))}),lse=e=>e.map(e=>e.label).join(`, `),y7=({title:e,chips:t,label:n,required:r,initial:i=``,busy:a,onSave:s,onClose:c})=>{let l=(0,o.useId)(),[u,d]=(0,o.useState)(i),f=`${l}-form`;return(0,B.jsx)(Xk,{open:!0,title:e,onClose:c,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(H,{onClick:c,children:`Cancel`}),(0,B.jsx)(H,{type:`submit`,form:f,variant:`primary`,loading:a,children:`Save`})]}),children:(0,B.jsxs)(`form`,{id:f,className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),s(u.trim()===``?null:u.trim())},children:[t.length>0&&(0,B.jsx)(_7,{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 text-[13px]`,children:[(0,B.jsx)(`label`,{htmlFor:l,className:`font-medium`,children:n}),!r&&(0,B.jsx)(`span`,{id:`${l}-hint`,className:`text-xs text-muted-foreground`,children:`Optional`})]}),(0,B.jsx)(Yd,{id:l,value:u,required:r,pattern:r?`.*\\S.*`:void 0,"aria-describedby":r?void 0:`${l}-hint`,autoFocus:!0,autoComplete:`off`,onChange:e=>d(e.target.value)})]})]})})},use=({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)(ny,{title:`Could not load rows`,error:e.error}):e.rows.length===0?(0,B.jsx)(`p`,{className:`py-8 text-center text-[13px] text-muted-foreground`,children:t}):r}),dse=({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(`en-IE`),` of `,e.total.toLocaleString(`en-IE`)]}),e.more&&(0,B.jsx)(H,{size:`sm`,onClick:e.loadMore,children:`Show more`})]}),b7=`grid grid-cols-[repeat(auto-fill,minmax(15rem,1fr))] gap-3`,fse=`flex snap-x snap-mandatory gap-3 overflow-x-auto pb-1`,pse=({model:e,view:t,display:n,list:r,row:i=!1,footer:a=!0})=>{let o=(t?.names?.plural??G(e.name)).toLowerCase();return(0,B.jsxs)(use,{list:r,empty:`No ${o} match.`,loading:(0,B.jsx)(`div`,{className:b7,children:Array.from({length:6},(e,t)=>(0,B.jsx)(od,{className:`h-24`},t))}),children:[(0,B.jsx)(`ul`,{className:i?fse:b7,"aria-label":t?.names?.plural??G(e.name),children:r.rows.map(r=>(0,B.jsx)(`li`,{className:z(i&&`w-64 shrink-0 snap-start`),children:(0,B.jsx)(AA,{model:e,view:t,display:n,row:r,swipe:!i})},r.key))}),a&&(0,B.jsx)(dse,{list:r})]})},mse=({field:e,value:t,known:n})=>{let{resources:r,views:i}=K(),a=W(),o=pm(),s=e.relation?r[e.relation.resource]:void 0,c=String(t),l=kh({queryKey:U.relatedLabel(s?.name??``,c),enabled:!!s&&n===void 0,queryFn:async()=>(await R_(o,a,s,[c],i[s.name])).get(c)??c});return s?(0,B.jsx)(Gv,{to:{kind:`record`,resource:s.name,key:c},className:`font-medium text-primary-text hover:underline`,children:n??l.data??c}):(0,B.jsx)(`span`,{children:c})},hse=({model:e,field:t,value:n,format:r,relationLabel:i})=>{let{views:a}=K(),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)(mse,{field:t,value:n,known:i});let s=t.type===`file`?q_(n):void 0;if(s&&`url`in s&&s.url){let e=tv(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)(py,{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})]})}let c=ov(t,n,o);return t.type===`enum`||o.format===`badge`?(0,B.jsx)(vA,{value:n,hints:o,children:c}):(0,B.jsx)(`span`,{className:z(o.format===`code`&&`font-mono text-xs`,(t.type===`decimal`||t.type===`integer`)&&`tabular-nums`,o.multiline&&`whitespace-pre-line break-words`),children:c})},x7=e=>{let{views:t}=K(),n=vy(e.field,t[e.model.name]?.fields[e.field.name]),r=(0,B.jsx)(hse,{...e});return n?(0,B.jsx)(Sy,{shown:n,part:`display`,field:e.field,value:e.value,fallback:r}):r},S7=(e,t,n)=>{if(!t)return[];let r=Bs(e,t.model.name,n);return r.ok?r.steps:[]},C7=(e,t,n,r,i)=>({queryKey:U.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:U.record(a,String(i)),queryFn:()=>e.get(a,String(i))})).record}return r[i.at(-1).field.name]??null}}),w7=(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}},T7=(e,t)=>{let{resources:n}=K(),r=S7(n,e,t);return w7(e,r,kh(C7(W(),pm(),e,t,r)))},gse=(e,t)=>{let{resources:n}=K(),r=W(),i=pm(),a=t.map(t=>S7(n,e,t)),o=Dh({queries:t.map((t,n)=>C7(r,i,e,t,a[n]))});return t.map((t,n)=>w7(e,a[n],o[n]))},E7=e=>e.includes(`.`),_se=({model:e,row:t,column:n})=>{let r=T7(eA(e,wv(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)(x7,{model:r.model,field:r.field,value:r.value})},vse=(e,t,{resources:n,views:r})=>{let i=Bs(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??G(o),kind:`text`,width:200,render:n=>(0,B.jsx)(_se,{model:e,row:n,column:t})}},yse=(e,t,n,r)=>{let i=new Map(p7(ik(e,t,[],n.filter(e=>!E7(e))),e,t,r.fieldTypes).map(e=>[e.id,e]));return n.flatMap(t=>E7(t)?[vse(e,t,r)]:i.get(t)??[])},bse=`protobase:embedded-display:`,xse=e=>`${bse}${e}`,Sse=(e,t)=>jd(()=>e.getItem(t)??void 0,void 0),Cse=(e,t,n)=>jd(()=>e.setItem(t,n),void 0),wse=(e,t,{picked:n,preferred:r})=>{let i=mv(e).map(e=>e.name);return n!==void 0&&i.includes(n)?n:dv(e,t,r!==void 0&&i.includes(r)?r:void 0)},D7=(e,t,n,{resource:r=e.name,...i})=>jv({kind:`list`,resource:r},i,kv(e,t,n)),Tse=({model:e,filter:t,orderBy:n,limit:r,fields:i})=>{let a=W(),{resources:o,views:s}=K();return kh({queryKey:[...U.list(e.name,t,n,r,`embedded`),i.join(`,`)],placeholderData:Lm,queryFn:async()=>{let c=B_(o,s,e,i),l=cv(s[e.name]),u=await a.search(e.name,{filter:t||void 0,orderBy:n||void 0,pageSize:r,labels:c,photos:l});return V_(o,e,i,lv(e,u.items,u.photos),u.labels).map((t,n)=>({...t,id:jg(e,u.items[n])}))}})},O7=({view:e,value:t,onChange:n})=>(0,B.jsx)(JA,{view:e,value:t,onChange:n,menu:!Gu()}),Ese=()=>(0,B.jsx)(`div`,{className:`flex flex-col gap-2`,children:Array.from({length:3},(e,t)=>(0,B.jsx)(od,{className:`h-4 w-full`},t))}),k7=({model:e,view:t,filter:n,sort:r,columns:i,limit:a,display:s,empty:c,row:l=!1,viewAll:u,link:d=!0})=>{let{resources:f,views:p}=K(),{fields:m}=w_(),{go:h}=Wv(),g=Ku(),[_,v]=(0,o.useState)(r||Tv(e,t)),y=i??rk(e,t),b=(0,o.useMemo)(()=>yse(e,t,y,{resources:f,views:p,fieldTypes:m}),[e,t,y.join(`,`),f,p,m]),x=(0,o.useMemo)(()=>xv(e,t,b.map(e=>e.id)),[e,t,b]),S=Tse({model:e,filter:n,orderBy:_,limit:a,fields:x}),C=S.data,T=(0,o.useMemo)(()=>C&&{total:C.length,rowAt:e=>C[e]},[C]),E=fv(t,s),D=t?.names?.plural??G(e.name),O=d&&(0,B.jsxs)(Gv,{to:D7(e,t,g,u?{filter:u.filter,orderBy:Tv(e,t),display:s,savedSearch:u.savedSearch}:{filter:n,orderBy:_,display:s}),onClick:u?.onOpen,className:`flex items-center gap-1 self-end text-[13px] font-medium text-primary-text hover:underline`,children:[u?u.label:(0,B.jsxs)(B.Fragment,{children:[`View all `,(0,B.jsx)(`span`,{className:`sr-only`,children:D.toLowerCase()})]}),(0,B.jsx)(w,{className:`size-3.5`,"aria-hidden":!0})]});if(S.isPending)return(0,B.jsx)(Ese,{});if(S.error)return(0,B.jsx)(ny,{title:`Could not load`,error:S.error});if(!T||T.total===0){let e=(0,B.jsx)(`p`,{className:`text-[13px] text-muted-foreground`,children:c??`Nothing here yet.`});return u&&d?(0,B.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[e,O]}):e}let k={resource:e.name,rows:S.data.map(t=>wv(e,t)),total:S.data.length,loading:!1,error:null,more:!1,loadMore:()=>void 0},A=t=>h({kind:`record`,resource:e.name,key:Mg(e,t)}),j=t?.names?.singular??G(e.name);return(0,B.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[E?E.kind===`cards`?(0,B.jsx)(pse,{model:e,view:t,display:E,list:k,row:l||g,footer:!1}):E.kind===`map`?(0,B.jsx)(GA,{model:e,view:t,display:E,filter:n,orderBy:_,fields:x,footer:!1}):(0,B.jsx)(qA,{display:E,list:k}):(0,B.jsx)(_O,{fit:!0,columns:b,source:T,latencyMs:0,sort:Ev(_),onSortChange:e=>v(Dv(e)),onOpenRow:A,rowActions:[{label:`Open ${j.toLowerCase()}`,onSelect:A}],rowNumbers:!1,selectable:!1}),O]})},A7=so(),Dse={start:0,end:0},j7=(e,t)=>A7.and(t,{kind:`present`,field:e.field,span:Dse}),M7=e=>{switch(e.kind){case`and`:case`or`:return{...e,args:e.args.map(M7)};case`not`:return N7(e.arg);case`search`:case`present`:case`isNull`:return e;default:return j7(e,e)}},N7=e=>{switch(e.kind){case`and`:return A7.or(...e.args.map(N7));case`or`:return A7.and(...e.args.map(N7));case`not`:return M7(e.arg);case`search`:case`present`:case`isNull`:return A7.not(e);default:return j7(e,A7.not(e))}},P7=e=>{let t=oa(e);if(!t.ok)throw Error(`The filter cannot be read: ${t.errors.map(e=>e.message).join(`; `)}`);return t.ast},F7=(e,t)=>{let n=P7(e);if(!n)return null;let r=P7(t),i=A7.not(M7(n));return qa(r?A7.and(r,i):i)},Ose=(e,t)=>F7(t,e),I7=e=>e.key.startsWith(`extra:`)?`extra:${e.label}`:e.key,kse=(e,t)=>{let n=new Map(e.map(e=>[I7(e),e])),r=new Map(t.map(e=>[I7(e),e])),i=e.filter(e=>!r.has(I7(e))).map(e=>({kind:`removed`,label:e.label})),a=t.flatMap(e=>{let t=n.get(I7(e));return t&&t.label!==e.label?[{kind:`changed`,label:e.label,before:t.label}]:[]}),o=t.filter(e=>!n.has(I7(e))).map(e=>({kind:`added`,label:e.label}));return[...i,...a,...o]},Ase=(e,t,n,r)=>{let i=e-t;return i===0?`As many ${r}`:`${Math.abs(i)} ${i>0?`more`:`fewer`} ${Math.abs(i)===1?n:r}`},L7=(e,t)=>{let n=W(),r=pm(),{resources:i,views:a}=K(),o=a[e.name],s=Object.entries(ise(e,o,t)),c=Dh({queries:s.map(([t,o])=>{let s=i[e.fields[t].relation.resource];return{queryKey:U.labels(`chips:${e.name}.${t}`,o.join(`,`)),enabled:s!==void 0,queryFn:async()=>Object.fromEntries(await R_(r,n,s,o,a[s.name]))}})});return h7(e,o,t,Object.fromEntries(s.flatMap(([e],t)=>c[t]?.data?[[e,c[t].data]]:[])))},R7=12,z7={added:{word:`Added`,className:`text-success-text`},removed:{word:`Removed`,className:`text-danger-text`},changed:{word:`Changed`,className:`text-primary-text`}},jse=({changes:e})=>(0,B.jsx)(`ul`,{"aria-label":`Filter changes`,className:`divide-y rounded-md border text-[13px]`,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 ${z7[e.kind].className}`,children:z7[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}`))}),B7=(e,t)=>{let n=kh({...tA(W(),e,t??``),enabled:t!==null});return t===null?0:n.data},Mse=(e,t,n)=>`${e} ${e===1?t:n}`,V7=({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:`text-[13px] font-semibold`,children:[n,` `,(0,B.jsxs)(`span`,{className:`font-normal text-muted-foreground`,children:[`(`,i??`…`,`)`]})]}),i!==void 0&&i>R7&&(0,B.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`The first `,R7,` of `,i,`.`]}),r===null||i===0?(0,B.jsxs)(`p`,{className:`text-[13px] text-muted-foreground`,children:[`No `,a,`.`]}):(0,B.jsx)(k7,{model:e,view:t,filter:r,sort:Tv(e,t),limit:R7,display:o?.name??`table`,row:!0,link:!1,empty:`No ${a}.`})]})},Nse=({model:e,view:t,title:n,before:r,after:i,saveNewLabel:a,updating:s,creating:c,onUpdate:l,onSaveNew:u,onCancel:d})=>{let f=kse(L7(e,r),L7(e,i)),p=(0,o.useMemo)(()=>F7(r,i),[r,i]),m=(0,o.useMemo)(()=>Ose(r,i),[r,i]),h=B7(e,p),g=B7(e,m),_=(t?.names?.singular??G(e.name)).toLowerCase(),v=(t?.names?.plural??G(e.name)).toLowerCase(),y=h!==void 0&&g!==void 0;return(0,B.jsx)(Xk,{open:!0,wide:!0,title:n,onClose:d,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(H,{onClick:d,children:`Cancel`}),(0,B.jsx)(H,{loading:c,disabled:s,onClick:u,children:a}),(0,B.jsx)(H,{variant:`primary`,loading:s,disabled:c,onClick:l,children:`Update`})]}),children:(0,B.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[f.length>0&&(0,B.jsx)(jse,{changes:f}),y?(0,B.jsxs)(`p`,{className:`text-[13px]`,children:[(0,B.jsx)(`span`,{className:`font-semibold`,children:Ase(h,g,_,v)}),(0,B.jsxs)(`span`,{className:`text-muted-foreground`,children:[`: `,Mse(h,_,v),` added, `,g,` removed`]})]}):(0,B.jsx)(od,{className:`h-4 w-48`}),(0,B.jsx)(V7,{model:e,view:t,title:`Added`,filter:p,total:h,plural:v}),(0,B.jsx)(V7,{model:e,view:t,title:`Removed`,filter:m,total:g,plural:v})]})})},Pse=()=>{let{address:e,set:t}=Wv();return{key:e?.kind===`list`?e.savedSearch:void 0,open:e=>t({savedSearch:e})}},Fse=e=>U.list(e,``,``,500,`saved-searches`),H7=(e,t)=>{let n=W(),{resources:r,views:i}=K(),a=r[e];return kh({queryKey:Fse(e),enabled:t&&a!==void 0,queryFn:async()=>{let t=[],r;do{let o=await n.list(e,{pageSize:500,orderBy:Tv(a,i[e]),...r&&{pageToken:r}});t.push(...o.items),r=o.nextPageToken||void 0}while(r);return t}})},U7=e=>e instanceof Error?e.message:`Something went wrong`,Ise=(e,t)=>{let n=K(),r=W(),i=Kg(),a=aA(),{href:o,open:s}=Wv(),c=Pse(),{resource:l}=e,u=n.resources[l],d=n.views[l]?.searchesOf,f=n.permissions[l],p=u!==void 0&&d!==void 0&&f!==void 0&&Ey(f,`create`)&&Ey(f,`delete`),m=n.signIn?.[l]?.signIn,h=H7(l,p),g=e=>mo(Mg(u,e)),_=d&&h.data?.find(e=>e[d.filter]===t),v=_||c.key===void 0||!f||!Ey(f,`update`)?void 0:h.data?.find(e=>g(e)===c.key),y=n.views[l]?.names,b=y?.plural??`saved searches`,x=d?.name===void 0?void 0:u?.fields[d.name],S=Ah({mutationFn:e=>r.create(l,{[d.filter]:t,...d.name&&{[d.name]:e}}),onSuccess:e=>{c.open(g(e.record)),i.show({state:`success`,title:`Search saved`,action:{label:`Open ${b.toLowerCase()}`,href:o({kind:`list`,resource:l}),onNavigate:s}})},onError:e=>i.show({state:`error`,title:`Could not save the search`,description:U7(e)}),onSettled:()=>a(l)}),C=Ah({mutationFn:e=>r.remove(l,g(e)),onError:e=>i.show({state:`error`,title:`Could not take the search off`,description:U7(e)}),onSettled:()=>a(l)}),w=Ah({mutationFn:e=>r.update(l,g(e),{[d.filter]:t},e.etag??`*`),onSuccess:()=>i.show({state:`success`,title:`Search updated`}),onError:e=>i.show({state:`error`,title:`Could not update the search`,description:U7(e)}),onSettled:()=>a(l)}),T=S.isPending||C.isPending||w.isPending;return{mode:p?`save`:m?`sign-in`:void 0,prompt:m,saved:_!==void 0,opened:v&&{filter:String(v[d.filter]??``),name:d.name&&typeof v[d.name]==`string`&&v[d.name]!==``?String(v[d.name]):void 0},noun:(y?.singular??G(l)).toLowerCase(),naming:x&&{label:n.views[l]?.fields[x.name]?.label??G(x.name),required:!x.nullable},ready:h.data!==void 0&&!T,updating:w.isPending,creating:S.isPending,remove:()=>_&&C.mutate(_),saveNew:(e,t)=>S.mutate(e,t),update:e=>v&&w.mutate(v,e)}},Lse=({model:e,view:t,search:n,filter:r,chips:i,className:a})=>{let s=Ise(n,r),[c,l]=(0,o.useState)(!1),[u,d]=(0,o.useState)(!1),[f,p]=(0,o.useState)();if(!s.mode)return null;let m=n.label??`Save search`;if(s.mode===`sign-in`)return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(H,{className:a,"aria-haspopup":`dialog`,onClick:()=>l(!0),children:[(0,B.jsx)(re,{className:`size-3.5`,"aria-hidden":!0}),m]}),(0,B.jsx)($k,{as:`dialog`,prompt:s.prompt,open:c,onClose:()=>l(!1)})]});let h=e=>{d(!1),s.naming?p(e):s.saveNew(null)},g=f!==void 0&&s.naming&&(0,B.jsx)(y7,{title:f,chips:i,label:s.naming.label,required:s.naming.required,busy:s.creating,onSave:e=>s.saveNew(e,{onSuccess:()=>p(void 0)}),onClose:()=>p(void 0)}),_=s.opened;if(_){let n=`Save as new ${s.noun}`;return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(H,{className:a,"aria-haspopup":`dialog`,"aria-disabled":!s.ready,onClick:()=>s.ready&&d(!0),children:[(0,B.jsx)(Ut,{className:`size-3.5`,"aria-hidden":!0}),(0,B.jsx)(`span`,{className:`max-w-60 truncate`,children:_.name?`Update ${_.name}`:`Update ${s.noun}`})]}),(0,B.jsxs)(H,{className:a,"aria-haspopup":s.naming?`dialog`:void 0,"aria-disabled":!s.ready,onClick:()=>s.ready&&h(n),children:[(0,B.jsx)(ne,{className:`size-3.5`,"aria-hidden":!0}),n]}),u&&(0,B.jsx)(Nse,{model:e,view:t,title:_.name?`Update ${_.name}?`:`Update this ${s.noun}?`,before:_.filter,after:r,saveNewLabel:n,updating:s.updating,creating:s.creating,onUpdate:()=>s.update({onSuccess:()=>d(!1)}),onSaveNew:()=>h(n),onCancel:()=>d(!1)}),g]})}let v=s.saved?ee:re;return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(H,{className:a,"aria-pressed":s.saved,"aria-haspopup":!s.saved&&s.naming?`dialog`:void 0,"aria-disabled":!s.ready,onClick:()=>s.ready&&(s.saved?s.remove():h(m)),children:[(0,B.jsx)(v,{className:s.saved?`size-3.5 text-primary`:`size-3.5`,"aria-hidden":!0}),m]}),g]})},W7=268,G7=3,K7=(e,t,n)=>{let r=Math.floor(Math.max(0,e)/W7),i=Math.ceil((Math.max(0,e)+t)/W7);return{start:Math.max(0,r-G7),end:Math.min(n,i+G7)}},q7=e=>e*W7,Rse=e=>{let t=(0,o.useRef)(null),[n,r]=(0,o.useState)({left:0,width:0});(0,o.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]=[K7(t.left,t.width,e),K7(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,q7(e)-12),a=e=>t.current?.scrollBy({left:e*Math.max(q7(1),n.width-12),behavior:`smooth`});return{ref:t,...K7(n.left,n.width,e),back:n.left>0,on:n.left+n.width<i-1,page:a}},J7=`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`,Y7=({cards:e})=>e>0?(0,B.jsx)(`li`,{"aria-hidden":!0,className:`shrink-0`,style:{width:q7(e)-12}}):null,zse=({model:e,view:t,display:n,source:r,label:i,isNew:a})=>{let{total:o}=r,s=Rse(o),c=tO({total:o,rowAt:r.rowAt,loadRows:r.loadRows,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:`flex snap-x gap-3 overflow-x-auto overflow-y-hidden pb-1`,style:{scrollbarWidth:`thin`},children:[(0,B.jsx)(Y7,{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)(od,{className:`h-full min-h-24 rounded-lg`})},`skeleton-${r}`);let s=wv(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)(AA,{model:e,view:t,display:n,row:s,swipe:!1,mark:a?.(s)?`New`:void 0})},s.key)}),(0,B.jsx)(Y7,{cards:o-s.end})]}),s.back&&(0,B.jsx)(`button`,{type:`button`,"aria-label":`Previous ${i.toLowerCase()}`,onClick:()=>s.page(-1),className:`${J7} -left-3`,children:(0,B.jsx)(he,{className:`size-4`,"aria-hidden":!0})}),s.on&&(0,B.jsx)(`button`,{type:`button`,"aria-label":`Next ${i.toLowerCase()}`,onClick:()=>s.page(1),className:`${J7} -right-3`,children:(0,B.jsx)(_e,{className:`size-4`,"aria-hidden":!0})})]})},Bse=so(),Vse=(e,t)=>{if(!t)return e;let n=oa(e);if(!n.ok)throw Error(`The filter cannot be read: ${n.errors.map(e=>e.message).join(`; `)}`);return qa(n.ast?Bse.and(n.ast,t):t)},Hse=(e,t)=>{let n=uv(e).filter(e=>e.kind===`cards`);return n.find(e=>e.name===t)??n[0]??{kind:`cards`,name:`cards`}},Use=()=>(0,B.jsx)(`div`,{className:`flex gap-3 overflow-hidden`,children:Array.from({length:3},(e,t)=>(0,B.jsx)(od,{className:`h-24 w-64 shrink-0`},t))}),X7=({model:e,view:t,filter:n,sort:r=``,display:i,limit:a,chips:s=!0,empty:c,note:l,isNew:u,viewAll:d,scope:f,list:p})=>{let{resources:m,views:h}=K(),g=Ku(),_=Hse(t,i),v=r||Tv(e,t),y=Rk({resources:m,views:h,model:e,columns:(0,o.useMemo)(()=>xv(e,t,[]),[e,t]),filter:(0,o.useMemo)(()=>Vse(n,f),[n,f]),orderBy:v}),b=L7(e,n),x=(t?.names?.singular??G(e.name)).toLowerCase(),S=t?.names?.plural??G(e.name),C=y.source?.total,T=(0,o.useMemo)(()=>y.source&&{...y.source,total:Math.min(y.source.total,a??1/0)},[y.source,a]);return(0,B.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3`,children:[s&&b.length>0||C!==void 0||l?(0,B.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[s&&b.length>0?(0,B.jsx)(_7,{chips:b}):(0,B.jsx)(`span`,{}),(0,B.jsxs)(`p`,{className:`flex flex-wrap gap-x-3 text-[13px] text-muted-foreground`,children:[l&&(0,B.jsx)(`span`,{children:l}),C!==void 0&&(0,B.jsx)(`span`,{className:`tabular-nums`,children:`${C.toLocaleString(`en-GB`)} ${C===1?x:S.toLowerCase()}`})]})]}):null,y.isLoading?(0,B.jsx)(Use,{}):y.error?(0,B.jsx)(ny,{title:`Could not load`,error:y.error}):!T||T.total===0?(0,B.jsx)(`p`,{className:`text-[13px] text-muted-foreground`,children:c??`No ${S.toLowerCase()} match.`}):(0,B.jsx)(zse,{model:e,view:t,display:_,source:T,label:S,isNew:u}),(0,B.jsxs)(Gv,{to:D7(e,t,g,{filter:n,orderBy:v,display:_.name,savedSearch:d?.savedSearch,resource:p}),onClick:d?.onOpen,className:`flex items-center gap-1 self-end text-[13px] font-medium text-primary-text hover:underline`,children:[d?.label??(0,B.jsxs)(B.Fragment,{children:[`View all `,(0,B.jsx)(`span`,{className:`sr-only`,children:S.toLowerCase()})]}),(0,B.jsx)(w,{className:`size-3.5`,"aria-hidden":!0})]})]})},Wse=e=>e instanceof Error?e.message:`Something went wrong`,Gse=({model:e,view:t,name:n,value:r,onChange:i})=>{let a=(0,o.useId)(),s=e.fields[n],c=t.fields[n],l=c?.label??G(n);if(s?.type===`boolean`)return(0,B.jsx)(H_,{checked:r===!0,onChange:i,label:l});if(s?.type!==`enum`)throw Error(`Not implemented: "${n}" is ${s?.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-[13px] text-muted-foreground`,children:[l,(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-[13px] text-foreground shadow-sm focus:border-primary focus:outline-none focus:ring-2 focus:ring-primary/20`,children:(s.enumValues??[]).map(e=>(0,B.jsx)(`option`,{value:e,children:Bo(e,c?.valueLabels)},e))})]})},Kse=(e,t,n)=>Object.entries(n).map(([n,r])=>`${t.fields[n]?.label??G(n)}: ${e.fields[n]?.type===`boolean`?r===!0?`On`:`Off`:Bo(String(r),t.fields[n]?.valueLabels)}`).join(`, `),qse=({model:e,view:t,recordKey:n,title:r,row:i,fields:a})=>{let o=W(),s=Kg(),c=aA(),l=Ah({mutationFn:t=>o.update(e.name,n,t,i.etag??`*`),onSuccess:(n,i)=>s.show({state:`success`,title:`${r} saved`,description:Kse(e,t,i)}),onError:e=>s.show({state:`error`,title:`Could not change the search`,description:Wse(e)}),onSettled:()=>c(e.name)});return(0,B.jsx)(`div`,{className:`flex flex-wrap items-center gap-3`,children:a.map(n=>(0,B.jsx)(Gse,{model:e,view:t,name:n,value:l.isPending&&n in(l.variables??{})?l.variables[n]:i[n],onChange:e=>l.mutate({[n]:e})},n))})},Z7=({model:e,of:t,target:n,targetView:r,row:i,recordKey:a})=>{let o=W(),s=aA(),c=String(i[t.filter]??``),l=L7(n,c),u=t.name===void 0?void 0:i[t.name],d=typeof u==`string`&&u!==``?u:void 0,f=t.unseen,p=Ah({mutationFn:t=>o.update(e.name,a,{[f.seenAt]:t},i.etag??`*`),onSettled:()=>s(e.name)}),m=kh({...tA(o,n,f?sse(c,f.field,i[f.seenAt]):``),enabled:f!==void 0}),h=(r?.names?.plural??G(n.name)).toLowerCase(),g={model:n,view:r,filter:c,sort:f?`${f.field} desc`:void 0,limit:t.limit,chips:d!==void 0,empty:`No ${h} match.`,note:f&&m.data===0&&`No new ${h} since you last looked.`,isNew:f&&(e=>cse(e.record[f.field],i[f.seenAt])),viewAll:{label:`View all results`,savedSearch:a,...f&&{onOpen:()=>p.mutate(new Date().toISOString())}}};return{name:d,chips:l,title:d??lse(l),body:g}},Jse=e=>e instanceof Error?e.message:`Something went wrong`,Yse=({model:e,view:t,of:n,target:r,targetView:i,row:a,recordKey:s,canRename:c,onDelete:l})=>{let u=W(),d=Kg(),f=aA(),[p,m]=(0,o.useState)(!1),{name:h,chips:g,title:_,body:v}=Z7({model:e,of:n,target:r,targetView:i,row:a,recordKey:s}),y=Ah({mutationFn:t=>u.update(e.name,s,{[n.name]:t},a.etag??`*`),onSuccess:()=>m(!1),onError:e=>d.show({state:`error`,title:`Could not rename the search`,description:Jse(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-[15px] font-semibold`,children:(0,B.jsx)(Gv,{to:{kind:`record`,resource:e.name,key:s},className:`hover:underline`,children:h??(0,B.jsx)(v7,{chips:g})})})}),(0,B.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[n.controls&&(0,B.jsx)(qse,{model:e,view:t,recordKey:s,title:_,row:a,fields:n.controls}),c&&b&&(0,B.jsx)(H,{variant:`ghost`,"aria-label":`Rename ${_}`,"aria-haspopup":`dialog`,onClick:()=>m(!0),children:(0,B.jsx)(Ft,{className:`size-3.5`,"aria-hidden":!0})}),l&&(0,B.jsx)(H,{variant:`ghost`,"aria-label":`Delete ${_}`,onClick:()=>l(_),children:(0,B.jsx)(yn,{className:`size-3.5`,"aria-hidden":!0})})]})]}),p&&b&&(0,B.jsx)(y7,{title:`Rename ${_}`,chips:g,label:t.fields[b.name]?.label??G(b.name),required:!b.nullable,initial:h,busy:y.isPending,onSave:e=>y.mutate(e),onClose:()=>m(!1)}),(0,B.jsx)(X7,{...v})]})},Xse=({model:e,view:t})=>{let{resources:n,views:r}=K(),i=t.searchesOf,a=n[i.resource],o=r[i.resource],s=H7(e.name,!0),c=Uv(e.name),l=Kk({model:e,view:t}),u=t.names?.plural??G(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)(of,{title:u,subtitle:t.help}),e]});if(!a)return d((0,B.jsxs)(Bv,{title:`Not found`,children:[`There is no resource called `,i.resource,`.`]}));if(s.error)return d((0,B.jsx)(ny,{title:`Could not load your ${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)(od,{className:`h-56`},t))}));if(s.data.length===0){let e=(o?.names?.plural??G(a.name)).toLowerCase();return d((0,B.jsxs)(`p`,{className:`py-8 text-center text-[13px] text-muted-foreground`,children:[`No `,u.toLowerCase(),` yet. Filter the`,` `,(0,B.jsx)(Gv,{to:{kind:`list`,resource:a.name},className:`font-medium text-primary-text hover:underline`,children:e}),` `,`and save the search.`]}))}return d((0,B.jsx)(`div`,{className:`flex flex-col gap-4`,children:s.data.map(n=>{let r=mo(Mg(e,n)),s=Ey(c,`delete`)?e=>void l.start({key:r,title:e,etag:n.etag,snapshot:n}):void 0;return(0,B.jsx)(Yse,{model:e,view:t,of:i,target:a,targetView:o,row:n,recordKey:r,canRename:Ey(c,`update`),onDelete:s},r)})}))},Zse=so(),Qse=e=>e.find(e=>e.kind===`search`),$se=({address:e})=>{let{resources:t,views:n,signIn:r}=K(),i=t[e.resource],a=r?.[e.resource];if(!i)return a?(0,B.jsx)($k,{as:`page`,prompt:a.signIn}):(0,B.jsxs)(Bv,{title:`Not found`,children:[`There is no resource called `,e.resource,`.`]});let o=n[e.resource];if(o?.searchesOf)return(0,B.jsx)(Xse,{model:i,view:o});let s=Ov(t,n,e.resource);if(o&&s.listOf){let t=s.model;return(0,B.jsx)(nse,{model:i,view:o,target:t,children:n=>(0,B.jsx)(Q7,{model:t,address:e,scope:n,heading:{title:o.names?.plural??G(i.name),subtitle:o.help}})})}return(0,B.jsx)(Q7,{model:i,address:e})},Q7=({model:e,address:t,scope:n,heading:r})=>{let i=K(),{set:a,go:s}=Wv(),c=e.name,l=i.views[c],u=(0,o.useMemo)(()=>jk(l,e),[l,e]),{fields:d}=w_(),f=(0,o.useMemo)(()=>p7(ik(e,l),e,l,d),[e,l,d]),p=t.filter,m=(0,o.useMemo)(()=>Sk(u,p),[u,p]),h=m.ok?m.state:CO,g=m.ok?m.extras:[],{orderBy:_,filterLayout:v}=t,y=Gu(),[b,x]=(0,o.useState)(!1),S=n?[...g,n]:g,C=Fk({model:e,resources:i.resources,views:i.views,view:l,state:h,extras:S}),w=n?hk(u,h,S):m.ok?p:``,T=(0,o.useMemo)(()=>xv(e,l,f.map(e=>e.id)),[e,l,f]),E=Rk({resources:i.resources,views:i.views,model:e,columns:T,filter:w,orderBy:_}),D=fv(l,t.display),O=D?.kind!==`map`;nd(O);let k=rre(e,E.page,E.key,D?.kind===`custom`),A=ire(),j=kg(e,l),M=e=>({key:e.id,title:String(typeof e[j]==`object`?e[j].name:e[j]??e.id),etag:typeof e.etag==`string`?e.etag:void 0,snapshot:e}),N=l?.names?.singular??G(c),ee=Uv(c),{state:te}=V(),ne=Kk({model:e,view:l,restore:qk(e),onReview:e=>s({kind:`record`,resource:c,key:e.key})}),P=(e,t=g)=>a({filter:hk(u,e,t)}),re=Qse(g),ie=e=>{let t=g.filter(e=>e.kind!==`search`);P(h,e?[...t,Zse.search(e)]:t)},ae=l?.names?.plural??G(c),F=D&&(0,B.jsx)(YA,{model:e,view:l,display:D,orderBy:_,onChange:e=>a({orderBy:e})}),oe=e.search?.length?(0,B.jsx)(tse,{value:re?.kind===`search`?re.text:``,onCommit:ie,placeholder:`Search ${ae.toLowerCase()}`,className:y?void 0:`min-h-11`}):null,se=(0,B.jsx)(qO,{layout:v,config:C,value:h,onChange:P,leading:v===`bar`?F:void 0,trailing:oe}),ce=v===`bar`?se:(0,B.jsx)(GO,{groups:[F?[F]:[]],trailing:oe}),I=OO(C,h),le=(0,B.jsx)(yO,{scroll:!0,chips:I,onRemove:e=>P(kO(h,e)),onClear:()=>P(CO)}),ue=D&&(0,B.jsx)(IO,{title:`Sort`,children:(0,B.jsx)(YA,{model:e,view:l,display:D,orderBy:_,onChange:e=>a({orderBy:e}),className:`min-h-11 w-full`})}),de=(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)(H,{className:`min-h-11`,onClick:()=>x(!0),"aria-haspopup":`dialog`,children:[(0,B.jsx)(an,{className:`size-3.5`}),`Filters`,I.length>0&&` (${I.length})`]}),oe??(0,B.jsx)(`div`,{className:`min-w-0 flex-1`,children:le})]}),oe&&le,(0,B.jsx)(zk,{title:`Filters`,open:b,onClose:()=>x(!1),children:(0,B.jsx)(qO,{layout:`panel`,fullWidth:!0,config:C,value:h,onChange:P,leading:ue})})]}),fe=!n&&Ey(ee,`create`)&&(0,B.jsxs)(H,{variant:`primary`,onClick:()=>s({kind:`create`,resource:c}),children:[(0,B.jsx)(Lt,{className:`size-3.5`}),`New `,N.toLowerCase()]}),pe=l?.saveSearch&&!n&&m.ok&&p&&(0,B.jsx)(Lse,{model:e,view:l,search:l.saveSearch,filter:p,chips:h7(e,l,p,ose(C))}),me=e=>(0,B.jsx)(JA,{view:l,value:D?.name??`table`,onChange:e=>a({display:e}),menu:e}),he=t=>s({kind:`record`,resource:c,key:Mg(e,t)}),ge=E.source?(0,B.jsx)(_O,{columns:f,source:E.source,sort:Ev(_),onSortChange:e=>a({orderBy:Dv(e)}),onOpenRow:he,initialScrollIndex:A.initialIndex,onScrollIndex:A.remember,rowActions:[{label:`Open ${N.toLowerCase()}`,onSelect:he},...Ey(ee,`delete`)?[{label:`Delete`,destructive:!0,available:e=>Dy(e,`delete`),onSelect:e=>void ne.start(M(e))}]:[]],bulkActions:Ey(ee,`delete`)?[{label:e=>`Delete ${e}`,destructive:!0,onRun:e=>ne.startBulk(e.map(M))}]:[],rowNumbers:!1,pinKey:te.kind===`signed-in`?RD(te.user.id,c):void 0,scroll:`parent`,className:`flex-1`}):(0,B.jsx)(`div`,{className:`flex-1 rounded-lg border bg-surface`}),_e={...E,initialIndex:A.initialIndex,onScrollIndex:A.remember},ve=D?D.kind===`cards`?(0,B.jsx)(jne,{model:e,view:l,display:D,list:_e},E.key.join(` `)):D.kind===`map`?(0,B.jsx)(GA,{model:e,view:l,display:D,filter:w,orderBy:_,fields:T,at:t.map,onMove:e=>a({map:e}),flush:!0}):(0,B.jsx)(qA,{display:D,list:k}):ge;return(0,B.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 px-5 py-4`,children:[ne.dialogs,(0,B.jsx)(of,{title:r?.title??ae,subtitle:r?r.subtitle:l?.help,aside:!y&&me(!0),actions:y?(0,B.jsxs)(B.Fragment,{children:[me(!1),pe,fe]}):(0,B.jsxs)(B.Fragment,{children:[pe,fe]})}),!m.ok&&(0,B.jsx)(ny,{title:`The filter in the address could not be read`,error:Error(m.errors.map(e=>e.message).join(`; `))}),E.error&&!D&&(0,B.jsx)(ny,{title:`Could not load rows`,error:E.error}),l?.chart&&(0,B.jsx)(ese,{resource:c,chart:l.chart,title:`${ae} created`,noun:ae.toLowerCase(),filter:w}),y?ce:de,y&&v===`panel`?(0,B.jsxs)(`div`,{className:`flex min-h-0 flex-1 gap-4`,children:[(0,B.jsx)(`div`,{className:O?`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:se}),ve]}):ve]})},$7=({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.filter(e=>e.membership).map(e=>{let a=t.includes(e.name),o=r||!n.has(e.name);return(0,B.jsxs)(`label`,{title:o&&!r?`You cannot give or take away this role`:void 0,className:z(`inline-flex items-center gap-1.5 text-[13px]`,o&&`text-muted-foreground`),children:[(0,B.jsx)(Yh,{checked:a,label:e.label,onChange:o?void 0:n=>i(n?[...t,e.name]:t.filter(t=>t!==e.name)),className:z(o&&`cursor-default opacity-60`)}),e.label]},e.name)})}),e9=e=>e?.role===`owner`?[`owner`,`admin`,`member`]:[`admin`,`member`],ece=({member:e,current:t,onChanged:n})=>{let{session:r,organizations:i}=V(),a=t.organization.id,{busy:o,error:s,run:c}=fg(),l=i?.roles??[],u=e.id===t.memberId,d=e9(t),f=e.role===`owner`&&t.role!==`owner`;return(0,B.jsxs)(`li`,{className:`flex flex-col gap-2 px-3 py-3`,children:[(0,B.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,B.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,B.jsxs)(`span`,{className:`block truncate text-[13px] font-medium`,children:[e.name,u&&` (you)`]}),(0,B.jsx)(`span`,{className:`block truncate text-xs text-muted-foreground`,children:e.email})]}),(0,B.jsx)(`select`,{"aria-label":`Organization role of ${e.name}`,value:e.role,disabled:o||f,onChange:t=>void c(async()=>{await r.organizations.setRole(a,e.id,t.target.value),n()}),className:`h-7 rounded-md border border-border-strong bg-background px-2 text-xs`,children:(f?[e.role]:d).map(e=>(0,B.jsx)(`option`,{value:e,children:sg[e]},e))}),!u&&(0,B.jsx)(H,{size:`sm`,variant:`danger`,loading:o,disabled:f,onClick:()=>void c(async()=>{await r.organizations.removeMember(a,e.id),n()}),children:`Remove`})]}),(0,B.jsx)($7,{roles:l,selected:e.appRoles,grantable:dg(l,t),disabled:o,onChange:t=>void c(async()=>{await r.organizations.setAppRoles(e.id,t),n()})}),(0,B.jsx)(Jf,{message:s})]})},tce=({current:e})=>{let{session:t}=V(),[n,r]=(0,o.useState)(),[i,a]=(0,o.useState)(),s=e?.organization?.id,c=(0,o.useCallback)(()=>{s&&t.organizations.members(s).then(r,e=>a(e instanceof Ks?df(e):`Could not read the members`))},[t,s]);return(0,o.useEffect)(c,[c]),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)(of,{title:`Members`,subtitle:`Who works in ${e.organization.name}, and with which roles.`}),(0,B.jsxs)(qf,{title:`Members`,description:`Owners and admins manage the organization; app roles decide what each member sees and does in the app.`,children:[(0,B.jsx)(Jf,{message:i}),n?(0,B.jsx)(`ul`,{className:`divide-y rounded-md border`,children:n.map(t=>(0,B.jsx)(ece,{member:t,current:e,onChanged:c},`${t.id}/${t.role}/${t.appRoles.join()}`))}):!i&&(0,B.jsxs)(`div`,{className:`flex items-center gap-2 text-[13px] text-muted-foreground`,children:[(0,B.jsx)(Zd,{}),` Loading`]})]})]}):null},t9=({link:e})=>e?(0,B.jsxs)(`p`,{className:`mt-3 break-all rounded-md border bg-muted px-3 py-2 text-xs`,children:[`This app cannot send email, so pass this link on yourself. It works once, until the invitation expires: `,(0,B.jsx)(`span`,{className:`font-mono`,children:e})]}):null,nce=({current:e,onSent:t})=>{let{session:n,organizations:r}=V(),i=r?.roles??[],[a,s]=(0,o.useState)(``),[c,l]=(0,o.useState)(`member`),[u,d]=(0,o.useState)([]),[f,p]=(0,o.useState)(),{busy:m,error:h,run:g}=fg(),_=()=>g(async()=>{let r=await n.organizations.invite(e.organization.id,{email:a.trim(),role:c,appRoles:u});p(r.link),s(``),d([]),t()});return(0,B.jsxs)(qf,{title:`Invite someone`,description:`They get an email with a link to join, or to make an account first. You can give the app roles you hold, and those your roles grant.`,children:[(0,B.jsx)(Jf,{message:h}),(0,B.jsxs)(`form`,{className:`flex flex-col gap-3`,onSubmit:e=>{e.preventDefault(),_()},children:[(0,B.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,B.jsx)(Yd,{"aria-label":`Email`,type:`email`,placeholder:`name@example.com`,value:a,onChange:e=>s(e.target.value),wrapperClassName:`flex-1`}),(0,B.jsx)(`select`,{"aria-label":`Organization role`,value:c,onChange:e=>l(e.target.value),className:`h-8 rounded-md border border-border-strong bg-background px-2 text-[13px]`,children:e9(e).map(e=>(0,B.jsx)(`option`,{value:e,children:sg[e]},e))}),(0,B.jsx)(H,{type:`submit`,variant:`primary`,loading:m,disabled:!a.trim(),children:`Invite`})]}),(0,B.jsx)($7,{roles:i,selected:u,grantable:dg(i,e),onChange:d})]}),(0,B.jsx)(t9,{link:f})]})},rce=({invitation:e,organizationId:t,onChanged:n})=>{let{session:r,organizations:i}=V(),[a,s]=(0,o.useState)(),{busy:c,error:l,run:u}=fg(),d=new Date(e.expiresAt).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 text-[13px] font-medium`,children:e.email}),(0,B.jsxs)(`span`,{className:`block text-xs text-muted-foreground`,children:[sg[e.role],e.appRoles.length>0&&` · ${e.appRoles.map(e=>cg(i?.roles??[],e)).join(`, `)}`,` · `,d?`Expired`:`Until ${new Date(e.expiresAt).toLocaleDateString()}`]})]}),(0,B.jsx)(H,{size:`sm`,loading:c,onClick:()=>void u(async()=>{s((await r.organizations.resend(t,e)).link),n()}),children:`Send again`}),(0,B.jsx)(H,{size:`sm`,variant:`danger`,loading:c,onClick:()=>void u(async()=>{await r.organizations.revoke(e.id),n()}),children:`Revoke`})]}),(0,B.jsx)(Jf,{message:l}),(0,B.jsx)(t9,{link:a})]})},ice=({current:e})=>{let{session:t}=V(),[n,r]=(0,o.useState)([]),i=e?.organization?.id,a=(0,o.useCallback)(()=>{i&&t.organizations.invitations(i).then(e=>r(e.filter(e=>e.status===`pending`)),()=>r([]))},[t,i]);return(0,o.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)(of,{title:`Invitations`,subtitle:`People invited to ${e.organization.name}.`}),(0,B.jsx)(nce,{current:e,onSent:a}),(0,B.jsx)(qf,{title:`Not accepted yet`,description:n.length>0?`Sending again gives a new link, which replaces the earlier one.`:`Nobody is waiting.`,children:n.length>0&&(0,B.jsx)(`ul`,{className:`divide-y rounded-md border`,children:n.map(e=>(0,B.jsx)(rce,{invitation:e,organizationId:i,onChanged:a},e.id))})})]})},ace=e=>{let{session:t}=V(),[n,r]=(0,o.useState)(),[i,a]=(0,o.useState)([]),[s,c]=(0,o.useState)(),[l,u]=(0,o.useState)(0),d=(0,o.useCallback)(()=>u(e=>e+1),[]);return(0,o.useEffect)(()=>{e&&Promise.all([t.organizations.current(),t.organizations.list()]).then(([e,t])=>{r(e),a(t)},e=>c(e instanceof Ks?df(e):`Could not read your organizations`))},[e,t,l]),{current:n,organizations:i,...s&&{error:s},reload:d}},n9=e=>window.location.assign(`${e}/`),oce=({organization:e,editable:t,onSaved:n})=>{let{session:r}=V(),[i,a]=(0,o.useState)(e.name),[s,c]=(0,o.useState)(e.slug),{busy:l,error:u,run:d}=fg(),f=i.trim()!==e.name||s!==e.slug;return(0,B.jsxs)(qf,{title:`Details`,description:t?`The name people see, and the slug that names it in links.`:`Owners and admins can change these.`,children:[(0,B.jsx)(Jf,{message:u}),(0,B.jsxs)(`form`,{className:`flex flex-col gap-2 sm:flex-row`,onSubmit:t=>{t.preventDefault(),d(async()=>{await r.organizations.rename(e.id,{name:i.trim(),slug:s}),n()})},children:[(0,B.jsx)(Yd,{"aria-label":`Name`,value:i,disabled:!t,onChange:e=>a(e.target.value),wrapperClassName:`flex-1`}),(0,B.jsx)(Yd,{"aria-label":`Slug`,value:s,disabled:!t,onChange:e=>c(e.target.value),wrapperClassName:`sm:w-48`}),t&&(0,B.jsx)(H,{type:`submit`,variant:`primary`,loading:l,disabled:!f||!i.trim(),children:`Save`})]})]})},sce=({organization:e,memberId:t})=>{let{session:n}=V(),[r,i]=(0,o.useState)([]),[a,s]=(0,o.useState)(``),{busy:c,error:l,run:u}=fg();return(0,o.useEffect)(()=>{n.organizations.members(e.id).then(e=>i(e.filter(e=>e.id!==t)),()=>i([]))},[n,e.id,t]),(0,B.jsxs)(qf,{title:`Hand over`,description:`Make another member the owner. You stay as an admin.`,children:[(0,B.jsx)(Jf,{message:l}),(0,B.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,B.jsxs)(`select`,{"aria-label":`New owner`,value:a,onChange:e=>s(e.target.value),className:`h-8 flex-1 rounded-md border border-border-strong bg-background px-2 text-[13px]`,children:[(0,B.jsx)(`option`,{value:``,children:`Choose a member`}),r.map(e=>(0,B.jsxs)(`option`,{value:e.id,children:[e.name,` (`,e.email,`)`]},e.id))]}),(0,B.jsx)(H,{loading:c,disabled:!a,onClick:()=>void u(async()=>{await n.organizations.transferOwnership(a),window.location.reload()}),children:`Hand over`})]})]})},cce=({organization:e,basePath:t})=>{let{session:n}=V(),[r,i]=(0,o.useState)(!1),[a,s]=(0,o.useState)(``),{busy:c,error:l,run:u}=fg(),d=()=>u(async()=>{await n.organizations.remove(e.id),n9(t)});return(0,B.jsxs)(qf,{title:`Delete organization`,description:`Takes the organization and its members and invitations away. Its records must be deleted first.`,children:[(0,B.jsx)(Jf,{message:r?void 0:l}),(0,B.jsx)(H,{variant:`danger`,onClick:()=>i(!0),children:`Delete organization`}),r&&(0,B.jsxs)(Kf,{title:`Delete ${e.name}?`,description:`Type its name to confirm. This cannot be undone.`,onClose:()=>i(!1),actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(H,{onClick:()=>i(!1),children:`Cancel`}),(0,B.jsx)(H,{variant:`danger`,loading:c,disabled:a!==e.name,onClick:()=>void d(),children:`Delete`})]}),children:[(0,B.jsx)(Jf,{message:l}),(0,B.jsx)(Yd,{"aria-label":`Organization name`,value:a,onChange:e=>s(e.target.value)})]})]})},lce=({organization:e,basePath:t,owner:n})=>{let{session:r}=V(),{busy:i,error:a,run:o}=fg();return(0,B.jsxs)(qf,{title:`Leave`,description:n?`An organization keeps an owner: hand it over before you leave, unless it has another owner.`:`You stop being a member, and lose your roles here.`,children:[(0,B.jsx)(Jf,{message:a}),(0,B.jsxs)(H,{loading:i,onClick:()=>void o(async()=>{await r.organizations.leave(e.id),n9(t)}),children:[`Leave `,e.name]})]})},uce=({current:e,basePath:t,onChanged:n})=>{let r=e?.organization;if(!r)return(0,B.jsx)(`div`,{className:`mx-auto w-full max-w-3xl px-4 py-6 md:px-6`,children:(0,B.jsx)(of,{title:`Organization`,subtitle:`You do not work in an organization now. Choose one under Organizations.`})});let i=e.role===`owner`;return(0,B.jsxs)(`div`,{className:`mx-auto flex w-full max-w-3xl flex-col gap-4 px-4 py-6 md:px-6`,children:[(0,B.jsx)(of,{title:r.name,subtitle:e.role?`You are ${sg[e.role].toLowerCase()} here.`:`You work here through your global roles, without being a member.`}),(0,B.jsx)(oce,{organization:r,editable:lg(e),onSaved:n},`${r.name}/${r.slug}`),i&&e.memberId&&(0,B.jsx)(sce,{organization:r,memberId:e.memberId}),e.role&&(0,B.jsx)(lce,{organization:r,basePath:t,owner:i}),i&&(0,B.jsx)(cce,{organization:r,basePath:t})]})},r9=e=>e.normalize(`NFKD`).replace(/[̀-ͯ]/g,``).toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,63),i9=({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 text-[13px] font-medium`,children:e.name}),(0,B.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:e.slug})]}),t?(0,B.jsx)(Cd,{tone:`green`,children:`Current`}):(0,B.jsx)(H,{size:`sm`,loading:n,onClick:r,children:`Open`})]}),dce=({basePath:e})=>{let{session:t}=V(),[n,r]=(0,o.useState)(``),[i,a]=(0,o.useState)(),{busy:s,error:c,run:l}=fg(),u=()=>l(async()=>{await t.organizations.create({name:n.trim(),slug:i??r9(n)}),n9(e)});return(0,B.jsxs)(qf,{title:`New organization`,description:`You become its owner, with every role, and work in it once it is made.`,children:[(0,B.jsx)(Jf,{message:c}),(0,B.jsxs)(`form`,{className:`flex flex-col gap-2 sm:flex-row`,onSubmit:e=>{e.preventDefault(),u()},children:[(0,B.jsx)(Yd,{"aria-label":`Name`,placeholder:`Name`,value:n,onChange:e=>r(e.target.value),wrapperClassName:`flex-1`}),(0,B.jsx)(Yd,{"aria-label":`Slug`,placeholder:`slug`,value:i??r9(n),onChange:e=>a(e.target.value),wrapperClassName:`sm:w-48`}),(0,B.jsx)(H,{type:`submit`,variant:`primary`,loading:s,disabled:!n.trim(),children:`Create`})]})]})},fce=({basePath:e,currentId:t})=>{let{session:n}=V(),[r,i]=(0,o.useState)(``),[a,s]=(0,o.useState)([]),{busy:c,error:l,run:u}=fg();return(0,o.useEffect)(()=>{let e=setTimeout(()=>void n.organizations.search(r).then(s,()=>s([])),200);return()=>clearTimeout(e)},[n,r]),(0,B.jsxs)(qf,{title:`Find an organization`,description:`Your global roles let you work in any organization, with what those roles allow there. Opening one you are not a member of is written to the audit log.`,children:[(0,B.jsx)(Jf,{message:l}),(0,B.jsx)(Yd,{"aria-label":`Find an organization`,placeholder:`Name or slug`,value:r,onChange:e=>i(e.target.value),leading:(0,B.jsx)(qt,{className:`size-3.5`}),wrapperClassName:`mb-3`}),a.length>0&&(0,B.jsx)(`ul`,{className:`divide-y rounded-md border`,children:a.map(r=>(0,B.jsx)(i9,{organization:r,current:r.id===t,busy:c,onOpen:()=>void u(async()=>{await n.organizations.switchTo(r.id),n9(e)})},r.id))})]})},pce=()=>{let{session:e,organizations:t}=V(),[n,r]=(0,o.useState)([]);if((0,o.useEffect)(()=>{e.organizations.myInvitations().then(r,()=>r([]))},[e]),n.length===0)return null;let i=t?.roles??[];return(0,B.jsx)(qf,{title:`Invitations for you`,description:`Open the link in the invitation email to accept one.`,children:(0,B.jsx)(`ul`,{className:`divide-y rounded-md border`,children:n.map(e=>(0,B.jsxs)(`li`,{className:`px-3 py-2.5 text-[13px]`,children:[(0,B.jsx)(`span`,{className:`font-medium`,children:e.organizationName??`An organization`}),`: `,e.appRoles.map(e=>cg(i,e)).join(`, `)||`no app roles`,(0,B.jsxs)(`span`,{className:`block text-xs text-muted-foreground`,children:[`Until `,new Date(e.expiresAt).toLocaleDateString()]})]},e.id))})})},mce=({state:e,basePath:t})=>{let{session:n,organizations:r,state:i}=V(),{busy:a,error:o,run:s}=fg(),c=i.kind===`signed-in`?i.user:void 0,l=r?.create===`everyone`||c!==void 0&&xg(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)(of,{title:`Organizations`,subtitle:`You work in one organization at a time; what you see follows from your roles there.`}),(0,B.jsxs)(qf,{title:`Your organizations`,description:e.organizations.length>0?`The organizations you are a member of.`:`You are not a member of an organization yet.`,children:[(0,B.jsx)(Jf,{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)(i9,{organization:e,current:e.id===u,busy:a,onOpen:()=>void s(async()=>{await n.organizations.switchTo(e.id),n9(t)})},e.id))})]}),(0,B.jsx)(pce,{}),l&&(0,B.jsx)(dce,{basePath:t}),(e.current?.globalRoles.length??0)>0&&(0,B.jsx)(fce,{basePath:t,currentId:u})]})},hce=(e,t)=>t?.active?{...e,role:t.active}:e,a9=(e,t)=>e instanceof Ks?df(e):t,gce=(e,t=!0)=>{let{session:n}=V(),r=Kg(),[i,a]=(0,o.useState)();(0,o.useEffect)(()=>{t&&n.roles.current().then(a,e=>r.show({state:`error`,title:a9(e,`Could not read your roles`)}))},[n,r,t]);let s=(0,o.useCallback)(t=>void n.roles.switchTo(t).then(e,e=>r.show({state:`error`,title:a9(e,`Could not switch the role`)})),[n,r,e]);return{...i&&{current:i},switchTo:s}},o9=e=>new Set((e.userMenu?.items??[]).flatMap(e=>e.kind===`resource`?[e.resource]:e.kind===`page`?[e.page]:[])),_ce=(e,t,n)=>(e.userMenu?.items??[]).map((r,i)=>{if(r.kind===`link`)return{id:`link-${i}`,label:r.label,icon:L_(r.icon,Ue),href:r.href,external:!0};if(r.kind===`page`){let i=e.pages[r.page];return{id:r.page,label:r.label??i?.title??G(r.page),icon:L_(r.icon??i?.icon,rt),href:qo({kind:`page`,page:r.page},t),active:r.page===n}}return{id:r.resource,label:r.label??e.views[r.resource]?.names?.plural??G(r.resource),icon:L_(r.icon,F_(r.resource)),href:qo({kind:`list`,resource:r.resource},t),active:r.resource===n}}),vce={sales:`Sales`,crm:`CRM`,catalog:`Catalog`,inventory:`Inventory`,core:`Admin`,hr:`HR`},yce=(e,t=``,n={})=>{let r=new Map,i=new Map,a=o9(e);for(let n of Object.values(e.pages)){if(n.nav?.hidden||a.has(n.name))continue;let e=n.nav?.group??`Pages`,o=r.get(e)??{label:e,items:[]};o.items.push({id:n.name,label:n.title,icon:L_(n.icon,rt),href:qo({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||s.nav?.hidden||a.has(o.name))continue;let c=o.table.schema??`public`,l=s.nav?.group??vce[c]??G(c),u=r.get(l)??{label:l,items:[]};u.items.push({id:o.name,label:s.names?.plural??G(o.name),icon:F_(o.name),href:qo({kind:`list`,resource:o.name},t),...n[o.name]&&{recent:n[o.name]}}),r.set(l,u),i.set(o.name,s.nav?.order??2**53-1)}for(let n of Object.values(e.signIn??{})){if(n.nav?.hidden||a.has(n.resource))continue;let e=n.nav?.group??`Account`,o=r.get(e)??{label:e,items:[]};o.items.push({id:n.resource,label:n.names?.plural??G(n.resource),icon:F_(n.resource),href:qo({kind:`list`,resource:n.resource},t)}),r.set(e,o),i.set(n.resource,n.nav?.order??2**53-1)}for(let n of e.sources??[]){if(n.state!==`error`)continue;let e=r.get(n.source.label)??{label:n.source.label,items:[]};for(let r of n.source.resources)e.items.push({id:r,label:G(r),icon:F_(r),href:qo({kind:`list`,resource:r},t),problem:`Cannot reach ${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))}))},s9=({action:e,label:t,danger:n,onCancel:r,onConfirm:i})=>(0,B.jsx)(Kf,{title:`${t}?`,description:e.confirm,onClose:r,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(H,{onClick:r,children:`Cancel`}),(0,B.jsx)(H,{variant:n?`danger`:`primary`,onClick:i,children:t})]})}),c9=(0,o.createContext)(void 0),l9=({value:e,children:t})=>(0,B.jsx)(c9.Provider,{value:e,children:t}),u9=()=>(0,o.useContext)(c9),bce=(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]))),xce=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},d9=(e,t={})=>{let n=Eee(e);return n===void 0?bce(e,t):xce(t[n])},Sce=e=>{e!==void 0&&(/^https?:/i.test(e)?window.open(e,`_blank`,`noopener,noreferrer`):window.location.assign(e))},Cce=e=>URL.canParse(e)?new URL(e).hostname.replace(/^www\./,``):``,wce=(e,t)=>{let n=e.run;if(n?.kind!==`link`||!(`href`in n))return e;let r=d9(n.href,t);if(r!==void 0)return e.label.includes(`{host}`)?{...e,label:e.label.replaceAll(`{host}`,Cce(r))}:e},Tce=e=>e instanceof Error?e.message:`Something went wrong`,f9=(e,t,n)=>{let{views:r}=K(),{actions:i}=w_(),a=Uv(e),s=W(),c=Fh(e),l=Kg(),u=aA(),{go:d}=Wv(),[f,p]=(0,o.useState)(),m=(r[e]?.actions??[]).flatMap(e=>wce(e,t?.record)??[]),h=e=>{let n=e.run?.kind;if((n===`update`||n===`delete`)&&!t)return`Needs a record`;if(n===`update`&&(!Ey(a,`update`)||t?.permissions?.update===!1))return`You cannot change this record`;if(n===`delete`&&(!Ey(a,`delete`)||t?.permissions?.delete===!1))return`You cannot delete this record`;if(!e.run&&!i?.[e.name])return`The app has no handler for "${e.name}"`},g=async r=>{let{run:a}=r;if(a?.kind===`link`){`to`in a?d(po(a.to,t?.record)):Sce(d9(a.href,t?.record));return}a?.kind===`update`?await s.update(e,t.key,a.values,t.etag??`*`):a?.kind===`delete`?await s.remove(e,t.key,{etag:t.etag}):await i[r.name]({resource:e,record:t?.record,recordKey:t?.key,etag:t?.etag,client:c,navigate:d}),await u(e),l.show({state:`success`,title:`${r.label}: done`}),n?.(r)};return{actions:m,blocked:h,running:f,run:async e=>{h(e)||(p(e.name),await g(e).catch(t=>l.show({state:`error`,title:`${e.label} failed`,description:Tce(t)})),p(void 0))}}},Ece=(e,t,n)=>{let r=f9(e,n),i=r.actions.find(e=>e.name===t);return{action:i,blocked:i?r.blocked(i):`No action "${t}"`,running:r.running===t,run:()=>i?r.run(i):Promise.resolve()}},p9=e=>e.props,Dce=({node:e})=>{let{name:t,resource:n,label:r,variant:i}=p9(e),a=u9(),s=Ece(n??a?.model.name??``,t,n===void 0||n===a?.model.name?a:void 0),[c,l]=(0,o.useState)(!1);if(!s.action)return null;let u=r??s.action.label;return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(H,{size:`sm`,variant:i??`secondary`,loading:s.running,disabled:!!s.blocked,title:s.blocked,onClick:()=>s.action.confirm?l(!0):void s.run(),children:u}),c&&(0,B.jsx)(s9,{action:s.action,label:u,danger:i===`danger`,onCancel:()=>l(!1),onConfirm:()=>{l(!1),s.run()}})]})},m9=({title:e,description:t,actions:n,className:r,bodyClassName:i,children:a})=>(0,B.jsxs)(`section`,{className:z(`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-[15px] font-semibold tracking-tight`,children:e}),t&&(0,B.jsx)(`p`,{className:`mt-0.5 text-[13px] 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:z(`min-w-0 flex-1 p-4 text-[13px]`,i),children:a})]}),h9=({children:e})=>(0,B.jsx)(`p`,{className:`text-[13px] text-muted-foreground`,children:e}),Oce=({node:e,children:t,slots:n})=>{let{title:r,description:i}=p9(e);return(0,B.jsx)(m9,{title:r,description:i,actions:n.actions,className:`h-full`,children:(0,B.jsx)(`div`,{className:`flex flex-col gap-3`,children:t})})},kce=({model:e,filter:t,sort:n,limit:r=12,title:i,description:a,empty:o,actions:s,children:c})=>{let l=iA(e,{filter:t,sort:n,pageSize:r}),u=l.data?.items??[];return(0,B.jsx)(m9,{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)(od,{className:`h-24 w-56`},t))}):l.error?(0,B.jsx)(ny,{title:`Could not load`,error:l.error}):u.length===0?(0,B.jsx)(h9,{children:o??`Nothing here yet.`}):(0,B.jsx)(`ul`,{className:`-mx-4 flex snap-x gap-3 overflow-x-auto px-4 pb-1`,children:u.map(t=>{let n=eA(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)(l9,{value:n,children:c})},n.key)})})})},Ace=({node:e,children:t,slots:n})=>{let{resource:r,...i}=p9(e),a=K().resources[r];return a?(0,B.jsx)(kce,{...i,model:a,actions:n.actions,children:t}):null},jce=(e,t)=>{if(t)return t;let n=e.split(`.`).map(e=>G(e).toLowerCase()).join(` `);return n[0].toUpperCase()+n.slice(1)},Mce=({node:e})=>{let{name:t,label:n,format:r}=p9(e),{views:i}=K(),a=T7(u9(),t);if(a.state===`missing`)return null;let o=a.state===`loading`?(0,B.jsx)(od,{className:`h-4 w-24`}):(0,B.jsx)(x7,{model:a.model,field:a.field,value:a.value,format:r});if(n===!1)return(0,B.jsx)(`div`,{className:`text-[13px]`,children:o});let s=n??jce(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-xs text-muted-foreground`,children:s}),(0,B.jsx)(`div`,{className:`mt-0.5 truncate text-[13px]`,children:o})]})},Nce={1:``,2:`md:grid-cols-2`,3:`md:grid-cols-2 xl:grid-cols-3`,4:`sm:grid-cols-2 xl:grid-cols-4`},Pce={1:``,2:`grid-cols-2`,3:`grid-cols-2 xl:grid-cols-3`,4:`grid-cols-2 xl:grid-cols-4`},Fce={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`},Ice=e=>typeof e==`object`&&!e.custom&&e.type===`Stat`,Lce=({node:e,children:t})=>{let{columns:n=2}=p9(e),r=e.children,i=r.length>0&&r.every(Ice);return(0,B.jsx)(`div`,{className:z(`grid grid-cols-1 gap-4`,i?Pce[n]:Nce[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:z(`min-w-0`,i&&Fce[i]),children:e},t)})})},g9=`font-medium text-primary-text hover:underline`,Rce=({node:e})=>{let t=p9(e),n=u9()?.record,r=e.children.filter(e=>typeof e==`string`).join(``);if(t.to){let e=po(t.to,n);return(0,B.jsx)(Gv,{to:e,className:g9,children:r||qo(e)})}let i=t.href??``;return(0,B.jsx)(`a`,{href:i,className:g9,...i.startsWith(`http`)&&{target:`_blank`,rel:`noreferrer`},children:r||i})},zce=(e,t,n)=>Object.fromEntries(t.map(t=>{let r=e.fields[t];if(r.type===`file`)return[t,n?.record[t]??null];if(n)return[t,r.type===`boolean`?!!n.record[t]:Jv(n.record[t])];let i=r.default&&`value`in r.default?r.default.value:void 0;return[t,r.type===`boolean`?!!i:Jv(i)]})),Bce=(e,t,n)=>Object.fromEntries(Object.entries(t).flatMap(([t,r])=>{let i=e.fields[t];return sC(r)?r.key===Jv(n.record[t])?[]:[[t,i.type===`integer`?Number(r.key):r.key]]:ey(i,r,n.record[t])?[[t,Zv(i,r)]]:[]})),Vce=({model:e,record:t,mode:n,label:r,title:i,fields:a,values:s,onClose:c})=>{let{resources:l,views:u}=K(),d=W(),f=Kg(),p=aA(),m=u[e.name],[h,g]=(0,o.useState)(()=>zce(e,a,t)),[_,v]=(0,o.useState)({}),[y,b]=(0,o.useState)(),[x,S]=(0,o.useState)(!1),C=async()=>{S(!0),b(void 0),await(n===`create`?d.create(e.name,{...dC(e,l,h),...s}):d.update(e.name,t.key,Bce(e,h,t),t.etag??`*`)).then(async()=>{await p(e.name),f.show({state:`success`,title:`${i??r}: saved`}),c()},e=>{vs(e)&&v(Object.fromEntries(e.errors.flatMap(e=>e.field?[[e.field,e.message]]:[]))),b(e)}),S(!1)};return(0,B.jsx)(Kf,{title:i??r,onClose:c,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(H,{onClick:c,children:`Cancel`}),(0,B.jsx)(H,{variant:`primary`,loading:x,onClick:()=>void C(),children:n===`create`?`Create`:`Save`})]}),children:(0,B.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),C()},children:[y!==void 0&&Object.keys(_).length===0&&(0,B.jsx)(ny,{title:`Not saved`,error:y}),a.map(n=>{let r=e.fields[n],i=h[n],a=r.relation?l[r.relation.resource]:void 0;return(0,B.jsx)(QS,{label:m?.fields[n]?.label??G(n),help:m?.fields[n]?.help,error:_[n],children:(0,B.jsx)(Ty,{field:r,hints:m?.fields[n],value:sC(i)?i.key:i,stored:t?.record[n],relationLabel:sC(i)?i.label:void 0,relationPicker:a?{target:a,view:u[a.name]}:void 0,invalid:!!_[n],resource:e.name,onChange:e=>{v(({[n]:e,...t})=>t),g(t=>({...t,[n]:e}))}})},n)})]})})},Hce=({model:e,recordKey:t,children:n})=>{let r=rA(e,{key:t});return(0,B.jsx)(B.Fragment,{children:n(r.data??void 0)})},Uce=({node:e})=>{let t=p9(e),n=u9(),{resources:r}=K(),i=r[t.resource??n?.model.name??``],a=Uv(i?.name??``),[s,c]=(0,o.useState)(!1);if(!i||!(t.mode===`create`?Ey(a,`create`):Ey(a,`update`)&&n?.permissions?.update!==!1))return null;let l=e=>(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(H,{size:`sm`,variant:t.variant??`secondary`,disabled:t.mode===`edit`&&!e,onClick:()=>c(!0),children:t.label}),s&&(0,B.jsx)(Vce,{...t,model:i,record:t.mode===`edit`?e:void 0,onClose:()=>c(!1)})]});return t.mode===`edit`&&t.recordKey!==void 0?(0,B.jsx)(Hce,{model:i,recordKey:t.recordKey,children:l}):l(t.mode===`edit`?n:void 0)},Wce=({node:e,children:t,slots:n})=>{let{title:r,description:i}=p9(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)(of,{title:r,subtitle:i,actions:n.actions}),t]})})},_9=(e,t)=>{let n=u9(),r=T7(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},Gce=({node:e})=>{let{value:t,max:n,label:r}=p9(e),i=_9(t,0),a=_9(n,100);if(i===void 0||a===void 0)return(0,B.jsx)(od,{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-xs`,children:[(0,B.jsx)(`span`,{className:`text-muted-foreground`,children:r}),(0,B.jsxs)(`span`,{className:`tabular-nums`,children:[i.toLocaleString(`en-IE`),` / `,a.toLocaleString(`en-IE`)]})]}),(0,B.jsx)(`div`,{role:`progressbar`,"aria-label":r,"aria-valuenow":i,"aria-valuemin":0,"aria-valuemax":a,className:`mt-1.5 h-2 overflow-hidden rounded-full bg-muted`,children:(0,B.jsx)(`div`,{className:o>=.9?`h-full rounded-full bg-warning`:`h-full rounded-full bg-primary`,style:{width:`${o*100}%`}})})]})},Kce=({model:e,filter:t,sort:n,recordKey:r,title:i,description:a,empty:o,actions:s,children:c})=>{let l=rA(e,{filter:t,sort:n,key:r}),u=e=>l.data?(0,B.jsx)(l9,{value:l.data,children:e}):void 0,d=l.isPending?(0,B.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,B.jsx)(od,{className:`h-4 w-1/2`}),(0,B.jsx)(od,{className:`h-4 w-1/3`})]}):l.error?(0,B.jsx)(ny,{title:`Could not load`,error:l.error}):l.data?u((0,B.jsx)(`div`,{className:`flex flex-col gap-3`,children:c})):(0,B.jsx)(h9,{children:o??`Nothing here yet.`});return(0,B.jsx)(m9,{title:i,description:a,actions:s?u(s):void 0,className:`h-full`,children:d})},qce=({node:e,children:t,slots:n})=>{let{resource:r,filter:i,sort:a,recordKey:o,title:s,description:c,empty:l}=p9(e),u=K().resources[r];return u?(0,B.jsx)(Kce,{model:u,filter:i,sort:a,recordKey:o,title:s,description:c,empty:l,actions:n.actions,children:t}):null},Jce=({model:e,view:t,empty:n,...r})=>{let{resources:i,views:a}=K(),o=Ov(i,a,e.name),s=mA(e.name,t.listOf,!0),c=(t.names?.plural??G(e.name)).toLowerCase();if(!o.listOf)return null;if(s.error)return(0,B.jsx)(ny,{title:`Could not load your ${c}`,error:s.error});if(!s.data)return(0,B.jsx)(od,{className:`h-24`});let l=fA(o.model,s.data);return l?(0,B.jsx)(X7,{...r,model:o.model,view:o.view,filter:``,scope:l,list:e.name,empty:n}):(0,B.jsx)(`p`,{className:`text-[13px] text-muted-foreground`,children:n??`No ${c} yet.`})},Yce=({model:e,view:t,target:n,targetView:r,row:i})=>{let a=mo(Mg(e,i)),{name:o,chips:s,title:c,body:l}=Z7({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-[14px] font-semibold`,children:(0,B.jsx)(Gv,{to:{kind:`record`,resource:e.name,key:a},className:`hover:underline`,children:o??(0,B.jsx)(v7,{chips:s})})}),(0,B.jsx)(X7,{...l})]})},Xce=({model:e,view:t,empty:n})=>{let{resources:r,views:i}=K(),a=t.searchesOf,o=r[a.resource],s=H7(e.name,!0),c=(t.names?.plural??G(e.name)).toLowerCase();return o?s.error?(0,B.jsx)(ny,{title:`Could not load your ${c}`,error:s.error}):s.data?s.data.length===0?(0,B.jsx)(`p`,{className:`text-[13px] text-muted-foreground`,children:n??`No ${c} yet.`}):(0,B.jsx)(`div`,{className:`flex flex-col divide-y`,children:s.data.map(n=>(0,B.jsx)(Yce,{model:e,view:t,target:o,targetView:i[a.resource],row:n},mo(Mg(e,n))))}):(0,B.jsx)(od,{className:`h-40`}):null},Zce=({node:e,slots:t})=>{let{resource:n,filter:r=``,sort:i,limit:a,display:o,title:s,description:c,empty:l}=p9(e),{resources:u,views:d}=K(),f=u[n];if(!f)return null;let p=d[f.name];return(0,B.jsx)(m9,{title:s,description:c,actions:t.actions,children:p?.searchesOf?(0,B.jsx)(Xce,{model:f,view:p,empty:l}):p?.listOf===void 0?(0,B.jsx)(X7,{model:f,view:p,filter:r,sort:i,limit:a,display:o,empty:l}):(0,B.jsx)(Jce,{model:f,view:p,limit:a,display:o,empty:l})})},Qce=({node:e,children:t})=>{let{when:n}=p9(e),{resources:r}=K(),i=W(),a=u9(),s=(0,o.useMemo)(()=>Ls(n),[n]),c=s.ok?s.paths:[],l=c.map(e=>zs(e,e=>!!(a&&Object.hasOwn(a.model.fields,e)))),u=c.filter((e,t)=>l[t]===void 0),d=gse(a,u),f=Dh({queries:l.flatMap(e=>{let t=e===void 0?void 0:r[e];return t?[tA(i,t)]:[]})});if(!s.ok||d.some(e=>e.state===`loading`)||f.some(e=>e.isPending))return null;let p={};u.forEach((e,t)=>{let n=d[t];n.state===`ready`&&(p[e]=n.value)});let m=0;return c.forEach((e,t)=>{l[t]!==void 0&&(p[e]=r[l[t]]?f[m++]?.data??0:0)}),Rs(s,p)?(0,B.jsx)(B.Fragment,{children:t}):null},v9=`text-2xl font-semibold tracking-tight tabular-nums`,$ce=({model:e,filter:t})=>{let n=nA(e,t);return n.isPending?(0,B.jsx)(od,{className:`h-8 w-16`}):n.error?(0,B.jsx)(`span`,{className:`text-[13px] text-danger-text`,children:`Could not count`}):(0,B.jsx)(Gv,{to:{kind:`list`,resource:e.name,filter:t},className:`${v9} hover:text-primary-text after:absolute after:inset-0 after:content-['']`,children:n.data.toLocaleString(`en-IE`)})},ele=({field:e,format:t})=>{let n=T7(u9(),e);return n.state===`loading`?(0,B.jsx)(od,{className:`h-8 w-16`}):n.state===`missing`?null:(0,B.jsx)(`span`,{className:v9,children:(0,B.jsx)(x7,{model:n.model,field:n.field,value:n.value,format:t})})},tle=({node:e})=>{let{label:t,value:n,resource:r,filter:i,field:a,format:o,description:s}=p9(e),{resources:c}=K(),l=r===void 0?void 0:c[r];return(0,B.jsxs)(m9,{className:`relative h-full`,bodyClassName:`flex flex-col`,children:[(0,B.jsx)(`p`,{className:`text-[13px] 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:v9,children:n}),l&&(0,B.jsx)($ce,{model:l,filter:i}),a!==void 0&&(0,B.jsx)(ele,{field:a,format:o})]}),s&&(0,B.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:s})]})},y9=(e,t,n)=>{let r=Ku(),i=xse(t),[a,s]=(0,o.useState)(()=>Sse(localStorage,i)),c=(0,o.useCallback)(e=>{s(e),Cse(localStorage,i,e)},[i]);return[wse(e,r,{picked:a,preferred:n}),c]},nle=({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]=y9(t,`page:${e.name}:${s??``}:${n}`,o);return(0,B.jsx)(m9,{title:s,description:c,actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(O7,{view:t,value:d,onChange:f}),u]}),className:`h-full`,children:(0,B.jsx)(k7,{model:e,view:t,filter:n,sort:r,columns:i,limit:a,display:d,empty:l})})},rle={Page:Wce,Grid:Lce,Card:Oce,Stat:tle,RecordCard:qce,Field:Mce,Table:({node:e,slots:t})=>{let n=p9(e),{resources:r,views:i}=K(),a=r[n.resource];return a?(0,B.jsx)(nle,{...n,model:a,view:i[a.name],actions:t.actions}):null},CardRow:Ace,RecordRow:Zce,Progress:Gce,ModalForm:Uce,Action:Dce,Show:Qce,Link:Rce},b9=e=>typeof e==`string`||!e.custom&&e.type===`Link`,x9=e=>{let t=[];for(let n of e){let e=t.at(-1);b9(n)&&e&&b9(e[0])?e.push(n):t.push([n])}return t.map((e,t)=>{let[n]=e;return b9(n)?(0,B.jsx)(`p`,{className:`text-[13px] leading-relaxed`,children:e.map((e,t)=>typeof e==`string`?(0,B.jsx)(o.Fragment,{children:e},t):(0,B.jsx)(S9,{node:e},t))},t):(0,B.jsx)(S9,{node:n},t)})},ile=e=>Ns(e)||Array.isArray(e)&&e.length>0&&e.every(Ns),ale=e=>Object.fromEntries(Object.entries(e.props).flatMap(([e,t])=>ile(t)?[[e,(0,B.jsx)(B.Fragment,{children:x9(Array.isArray(t)?t:[t])})]]:[])),S9=({node:e})=>{let{components:t}=w_();if(e.custom){let n=t?.[e.type];return n?(0,B.jsx)(by,{name:e.type,children:(0,B.jsx)(n,{...co(e.props),children:e.children.length>0?x9(e.children):void 0})}):(0,B.jsxs)(yy,{children:[`No component is registered as `,e.type,`. Export it from protobase.ui.tsx, or load the plugin that provides it.`]})}let n=rle[e.type];return n?(0,B.jsx)(n,{node:e,slots:ale(e),children:x9(e.children)}):(0,B.jsxs)(yy,{children:[e.type,` is not a block this version of the app knows.`]})},ole=({name:e})=>{let t=K().pages[e];return t?(0,B.jsx)(S9,{node:t.tree}):(0,B.jsxs)(Bv,{title:`Not found`,children:[`There is no page called `,e,`.`]})},C9=e=>typeof e==`string`&&e.trim()!==``,sle=e=>{if(typeof e!=`object`||!e||Array.isArray(e))return{problem:`its plugin.json is not an object`};let{name:t,version:n,api:r,protobase:i,entry:a,css:o}=e;return C9(t)?Number.isInteger(r)?C9(i)?C9(a)?o!==void 0&&!C9(o)?{problem:`its plugin.json names a stylesheet that is no URL`}:n!==void 0&&!C9(n)?{problem:`its plugin.json has a version that is no text`}:{manifest:{name:t,api:r,protobase:i,entry:a,...n!==void 0&&{version:n},...o!==void 0&&{css:o}}}:{problem:`its plugin.json names no module`}:{problem:`its plugin.json names no Protobase versions`}:{problem:`its plugin.json names no plugin API`}:{problem:`its plugin.json names no plugin`}},cle=/^[A-Z][A-Za-z0-9]*$/,lle=e=>typeof e==`function`||typeof e==`object`&&!!e&&`$$typeof`in e,w9=e=>{let t=e.default??{},n=Object.entries(e).filter(e=>e[0]!=="default"&&cle.test(e[0])&&lle(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)}}},T9=class extends Error{name=`UiConflictError`},ule=e=>Object.keys(e).some(e=>e==="default"||/^[A-Z]/.test(e))?w9(e):e,E9=(e,t)=>[...(e.extends??[]).map(ule).flatMap((e,n)=>E9(e,e.name??`${t} extends[${n}]`)),{ui:e,label:t}],D9=(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 T9(`${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},O9=e=>e.length<=1?e[0]:()=>e.map((e,t)=>(0,B.jsx)(e,{},t)),k9=(...e)=>{let t=e.flatMap((e,t)=>E9(e,e.name??`UI config ${t+1}`)),n=D9(`The component`,t,e=>e.components),r=D9(`The action handler`,t,e=>e.actions),i=D9(`The field type`,t,e=>e.fields),a=O9(t.flatMap(({ui:e})=>e.shell?.actions?[e.shell.actions]:[])),o=O9(t.flatMap(({ui:e})=>e.shell?.rightPanel?[e.shell.rightPanel]:[])),s=e.at(-1)?.name;return{...s&&{name:s},components:n,actions:r,...Object.keys(i).length>0&&{fields:i},...(a||o)&&{shell:{...a&&{actions:a},...o&&{rightPanel:o}}}}},A9=(0,o.createContext)(null),dle=A9.Provider,fle=()=>{let e=(0,o.useContext)(A9);if(!e)throw Error(`usePlugin is for the components of a plugin the app loaded`);return e},j9=(e,t,n)=>{let r=n=>(0,B.jsx)(dle,{value:e,children:(0,B.jsx)(t,{...n})});return r.displayName=`${e.name}:${n}`,r},ple=(e,t,n)=>({of:n.of,display:j9(e,n.display,`fields.${t}.display`),...n.editor&&{editor:j9(e,n.editor,`fields.${t}.editor`)},...n.cell&&{cell:j9(e,n.cell,`fields.${t}.cell`)}}),mle=(e,t)=>{let n=k9({...w9(t),name:e.name}),r=Object.fromEntries(Object.entries(n.components??{}).map(([t,n])=>[t,j9(e,n,t)])),i=n.fields&&Object.fromEntries(Object.entries(n.fields).map(([t,n])=>[t,ple(e,t,n)])),a=n.shell&&{...n.shell.actions&&{actions:j9(e,n.shell.actions,`shell.actions`)},...n.shell.rightPanel&&{rightPanel:j9(e,n.shell.rightPanel,`shell.rightPanel`)}};return{name:e.name,components:r,...n.actions&&{actions:n.actions},...i&&{fields:i},...a&&{shell:a}}},M9={name:`@protobase/ui`,version:`0.17.0`,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`},types:`./src/index.ts`,files:[`dist`],scripts:{build:`tsdown && protobase build-shell dist/shell`,prepack:`tsdown && protobase build-shell dist/shell`},publishConfig:{access:`public`,exports:{".":`./dist/index.js`,"./theme.css":`./dist/theme.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`,"lucide-react":`^1.52.0`,"maplibre-gl":`^6.14.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`}},N9=M9.protobase.pluginApi,P9=M9.version,hle={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=>g_(()=>import(e),[])},gle={api:N9,version:P9},_le=e=>e instanceof Error?e.message:String(e),vle=async(e,t,n,r=gle)=>{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(`its plugin.json answered ${n.status}`);let s=sle(n.json);if(`problem`in s)return a(s.problem);let{manifest:c}=s;o=c.name;let l=bo(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:mle(d,u)}}catch(e){return a(`it could not be loaded: ${_le(e)}`,o)}},yle=(e,t)=>{let n=k9(e??{}),r=[],i=[];for(let e of t){if(e.kind===`off`){i.push(e);continue}try{k9(...r,e.ui,n),r.push(e.ui)}catch(t){if(!(t instanceof T9))throw t;i.push({kind:`off`,url:e.plugin.url,name:e.plugin.name,reason:t.message})}}return{ui:r.length===0?n:k9(...r,n),off:i}},ble=1e4,F9=[],xle=(e,t)=>{let n=JSON.stringify(e),[r,i]=(0,o.useState)({key:`[]`,loads:F9,settled:!0});return(0,o.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()},ble);return e.forEach((e,n)=>{vle(e,t,window.location.href).then(e=>{o[n]=e,s()})}),()=>{r=!1,clearTimeout(c)}},[n,t]),e.length===0?{loads:F9,settled:!0}:r.key===n?r:{loads:F9,settled:!1}},I9=(0,o.createContext)([]),Sle=()=>(0,o.useContext)(I9),Cle=({ui:e,loader:t=hle,children:n})=>{let{plugins:r=[]}=K(),{loads:i,settled:a}=xle(r,t),s=(0,o.useMemo)(()=>yle(e,i),[e,i]);return a?(0,B.jsx)(C_.Provider,{value:s.ui,children:(0,B.jsx)(I9.Provider,{value:s.off,children:n})}):(0,B.jsxs)(`div`,{className:`flex h-full min-h-48 items-center justify-center gap-2 text-[13px] text-muted-foreground`,children:[(0,B.jsx)(Zd,{}),` Loading`]})},wle=({off:e})=>{let[t,n]=(0,o.useState)(!1);return t||e.length===0?null:(0,B.jsxs)(`div`,{role:`region`,"aria-label":`Plugins off`,className:`flex items-start gap-3 border-b border-warning/40 bg-warning-soft px-4 py-2 text-[13px] text-warning-text`,children:[(0,B.jsx)(zt,{"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.jsxs)(`li`,{children:[`The plugin `,(0,B.jsx)(`span`,{className:`font-semibold`,children:e.name??e.url}),` is off: `,e.reason,`.`]},e.url))}),(0,B.jsx)(`button`,{type:`button`,"aria-label":`Dismiss`,className:`rounded p-0.5 hover:bg-warning/10`,onClick:()=>n(!0),children:(0,B.jsx)(Nn,{"aria-hidden":!0,className:`size-4`})})]})},L9=(e,t)=>[`${t}_at`,`${t}At`].find(t=>e.fields[t]),R9=({item:e,scope:t})=>{let{components:n}=w_(),r=n?.[e.component],i=r?(0,B.jsx)(l9,{value:t,children:(0,B.jsx)(by,{name:e.component,children:(0,B.jsx)(r,{...co(e.props??{})})})}):(0,B.jsxs)(yy,{children:[`No component is registered as `,e.component,`. Export it from protobase.ui.tsx, or load the plugin that provides it.`]});return e.sidebar?e.title?(0,B.jsx)(rC,{title:e.title,children:i}):i:e.title?(0,B.jsx)($S,{title:e.title,children:i}):(0,B.jsx)(`section`,{className:`py-8`,children:i})},Tle=(0,o.lazy)(()=>g_(()=>import(`./record-map-BPHuPMlK.js`).then(e=>({default:e.RecordMap})),__vite__mapDeps([7,1,3,2,4,5,6]))),Ele=15,z9=({item:e,record:t})=>{let n=K().maps?.style,r=IA(t,e);if(!n||!r)return null;let i=(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)(o.Suspense,{fallback:null,children:(0,B.jsx)(Tle,{style:n,position:r,zoom:e.zoom??Ele},`${r.latitude},${r.longitude}`)})});return e.sidebar?(0,B.jsx)(rC,{title:e.title,children:i}):(0,B.jsx)($S,{title:e.title,children:i})},Dle=e=>Yk(e)??lee,Ole=({model:e,stored:t,recordKey:n})=>{let{go:r}=Wv(),i={model:e,record:t.record,key:n,etag:t.etag,permissions:t.permissions},a=f9(e.name,i,t=>t.run?.kind===`delete`&&r({kind:`list`,resource:e.name},{replace:!0})),[s,c]=(0,o.useState)();return a.actions.length===0?null:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(eC,{actions:a.actions.map(e=>({name:e.label,icon:Dle(e.icon),blocked:a.blocked(e),running:a.running===e.name,onRun:()=>e.confirm?c(e):void a.run(e)}))}),s&&(0,B.jsx)(s9,{action:s,label:s.label,danger:s.run?.kind===`delete`,onCancel:()=>c(void 0),onConfirm:()=>{c(void 0),a.run(s)}})]})},kle=(e,t)=>Object.values(e).find(e=>e.name!==t.name&&e.fields.position&&e.fields.quantity&&Object.values(e.fields).some(e=>e.type===`relation`&&e.relation?.resource===t.name)),Ale=e=>({id:String(e.id),productId:String(e.productId??``),description:String(e.description??``),quantity:Number(e.quantity),unitPriceCents:Math.round(Number(e.unitPrice)*100)}),jle=({lines:e,draft:t,vatRate:n,saving:r})=>{let i=Ey(Uv(e.name),`update`);return(0,B.jsx)($S,{title:`Lines`,help:`What the document bills for. Drag the handle, or use the menu, to change the order; Save applies it.`,children:(0,B.jsx)(`div`,{className:`-mx-4 overflow-x-auto px-4 [-webkit-overflow-scrolling:touch] md:mx-0 md:px-0`,children:(0,B.jsx)(`div`,{className:`min-w-[560px]`,children:(0,B.jsx)(ZS,{lines:t.shown.map(Ale),onChange:()=>void 0,onReorder:e=>t.setOrder(e.map(e=>e.id)),vatRate:n,readOnly:!0,reorderable:i&&!r})})})})},Mle=(e,t,n)=>`protobase:draft:${e}:${t}:${n}`,Nle=(e,t,n)=>jd(()=>{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),Ple=(e,t,n)=>jd(()=>n?e.setItem(t,JSON.stringify(n)):e.removeItem(t),void 0),B9=(e,{filter:t,orderBy:n,pageSize:r=50,fields:i,startToken:a=``,enabled:o=!0}={})=>{let s=W(),c=as(t)??``,l=jh({queryKey:[...U.list(e,c,n??``,r,a),i?.join(`,`)??``],enabled:o,initialPageParam:a,queryFn:({pageParam:t})=>s.list(e,{filter:c,orderBy:n,pageSize:r,fields:i,pageToken:t}),getNextPageParam:e=>e.nextPageToken||void 0}),u=l.data?.pages??[];return{...l,items:u.flatMap(e=>e.items),totalEstimate:u[0]?.totalSizeEstimate}},Fle=(e,t)=>Number(e.position)-Number(t.position),Ile=(e,t,n)=>{let r=e&&Object.values(e.fields).find(e=>e.type===`relation`&&e.relation?.resource===t.name),i=B9(e?.name??``,{enabled:!!(e&&r),filter:r?`${r.name} = "${n}"`:void 0,pageSize:200,...e?.fields.position?.sortable&&{orderBy:`position asc`}});return{items:[...i.items].sort(Fle),loading:i.isPending&&!!e}},Lle=(e,t)=>{let[n,r]=(0,o.useState)(),i=t.map(e=>String(e.id)),a=(0,o.useMemo)(()=>{if(!n)return t;let e=n.flatMap(e=>t.filter(t=>String(t.id)===e)),r=t.filter(e=>!n.includes(String(e.id)));return[...e,...r]},[n,t]),s=a.map(e=>String(e.id)),c=n!==void 0&&s.some((e,t)=>e!==i[t]),l=(0,o.useCallback)(()=>!e||!c?[]:[{op:`reorder`,resource:e.name,field:`position`,keys:a.map(t=>Mg(e,t)),etags:Object.fromEntries(a.flatMap(t=>typeof t.etag==`string`?[[mo(Mg(e,t)),t.etag]]:[]))}],[e,c,a]);return{shown:a,dirty:c,order:c?s:void 0,setOrder:e=>r(e),reset:()=>r(void 0),op:l}},V9=(e,t)=>{let n=W(),r=pm(),i=mo(t);return Ah({mutationFn:({patch:r,etag:i})=>n.update(e,t,r,i),onSuccess:t=>{r.setQueryData(U.record(e,i),t),r.invalidateQueries({queryKey:[`page`,e]}),r.invalidateQueries({queryKey:[`list`,e]}),r.invalidateQueries({queryKey:[`map`,e]})}})},H9=e=>e instanceof _s,Rle=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}`},zle=(e,t)=>{let n=e.operation,r=n===void 0?void 0:t[n];return r?`Operation ${n+1} (${Rle(r)}) failed: ${e.message} Nothing was saved.`:`${e.message} Nothing was saved.`},Ble=(e,t)=>new e.constructor({...e.problem,detail:zle(e,t)}),U9=(e,t)=>Object.fromEntries(Object.entries(e).filter(([e])=>e!==t)),Vle=({model:e,stored:t,recordKey:n,mode:r,subject:i,draftKey:a,lines:s})=>{let c=W(),l=pm(),u=V9(e.name,n),d=Ay(r,i),[f]=(0,o.useState)(()=>a?Nle(localStorage,a,t.etag):void 0),[p,m]=(0,o.useState)(f?.fields??{}),[h,g]=(0,o.useState)(!!f),[_,v]=(0,o.useState)(!1),[y,b]=(0,o.useState)({}),[x,S]=(0,o.useState)({}),C=Object.entries(p).filter(([n,r])=>ey(e.fields[n],r,t.record[n])),w=C.length>0,T=w||!!s?.dirty;(0,o.useEffect)(()=>{f?.order&&s?.setOrder(f.order)},[]),(0,o.useEffect)(()=>{if(!a)return;let n=Object.fromEntries(Object.entries(p).filter(([t])=>!e.fields[t]?.sensitive)),r=Object.keys(n).length>0||!!s?.dirty;Ple(localStorage,a,r?{etag:t.etag,fields:n,...s?.order&&{order:s.order}}:void 0)},[a,e,p,s?.dirty,s?.order,t.etag]);let E=n=>n in p?p[n]:[`boolean`,`file`].includes(e.fields[n].type)?t.record[n]:Jv(t.record[n]),D=(n,r)=>{S(e=>U9(e,n));let i=typeof r==`string`?r!==Jv(t.record[n]):ey(e.fields[n],r,t.record[n]);m(e=>i?{...e,[n]:r}:U9(e,n))},O=async()=>{let r=await c.get(e.name,n);l.setQueryData(U.record(e.name,n),r);let i={},a={};for(let[n,o]of Object.entries(p)){let s=e.fields[n];ey(s,o,r.record[n])&&(a[n]=o,Jv(r.record[n])!==Jv(t.record[n])&&(i[n]=s.type===`file`?ov(s,r.record[n]):Jv(r.record[n])))}m(a),b(i)},k=()=>Object.fromEntries(C.map(([t,n])=>[t,Zv(e.fields[t],n)])),A=e=>vs(e)?Object.fromEntries(e.errors.flatMap(e=>e.field?[[e.field,e.message]]:[])):{},j=async()=>{try{await u.mutateAsync({patch:k(),etag:t.etag})}catch(e){throw H9(e)?await O():vs(e)&&S(A(e)),e}},M=async r=>{let i=[...w?[{op:`update`,resource:e.name,key:n,data:k(),etag:t.etag}]:[],...r];try{await c.batchWrite(i)}catch(e){throw H9(e)?(await O(),await l.invalidateQueries({queryKey:[`list`]}),v(!0)):vs(e)&&S(A(e)),vs(e)?Ble(e,i):e}await Promise.all([l.invalidateQueries({queryKey:U.record(e.name,n)}),l.invalidateQueries({queryKey:[`list`]}),l.invalidateQueries({queryKey:[`page`]}),l.invalidateQueries({queryKey:[`map`]})]),s?.reset()};return{value:E,change:D,save:()=>d.run(async()=>{let e=s?.op()??[];e.length>0?await M(e):await j(),m({}),b({}),S({}),v(!1),g(!1)}),dirty:T,discard:()=>{m({}),b({}),S({}),v(!1),g(!1),s?.reset()},restored:h&&T,dismissRestored:()=>g(!1),linesConflict:_,saving:d.phase===`saving`,phase:d.phase,message:d.message,conflicts:y,errors:x,keepMine:e=>b(t=>U9(t,e)),useTheirs:e=>{b(t=>U9(t,e)),m(t=>U9(t,e))}}},Hle=(e,t,n,r,i,a)=>{let o=W(),s=pm(),c=Object.values(e.fields).filter(t=>t.type===`relation`&&t.relation&&t.name!==e.tenant&&i[t.name]!=null&&n[t.relation.resource]?.primaryKey.length===1),l=Dh({queries:c.map(e=>{let t=n[e.relation.resource],a=String(i[e.name]);return{queryKey:U.relatedLabel(t.name,a),queryFn:async()=>(await R_(s,o,t,[a],r[t.name])).get(a)??a}})}),u=c.map(e=>({kind:`record`,resource:e.relation.resource,key:String(i[e.name])}));return{addresses:Object.fromEntries(c.map((e,t)=>[e.name,u[t]])),labels:Object.fromEntries(c.map((e,t)=>[e.name,l[t]?.data])),records:c.map((e,n)=>({kind:t?.fields[e.name]?.label??G(e.name),label:l[n]?.data??String(i[e.name]),href:qo(u[n],a)}))}},W9=so(),G9=500,K9=(...e)=>{let t=e.filter(e=>!!e);return t.length===1?t[0]:t.map(e=>`(${e})`).join(` AND `)},Ule=(e,t)=>{let n=W(),{resources:r}=K(),i=e.through,a=i?r[i.resource]:void 0,o=i?.key??a?.primaryKey[0],s=i?K9(qa(W9.eq(i.field,t)),i.filter):``,c=kh({queryKey:U.list(a?.name??``,s,``,G9,`related:${o}`),enabled:!!(a&&o),queryFn:async()=>{let e=await n.search(a.name,{filter:s,fields:[o],pageSize:G9});return[...new Set(e.items.flatMap(e=>e[o]===null||e[o]===void 0?[]:[String(e[o])]))]}});return i?c.data?{filter:c.data.length===0?null:K9(qa(W9.in(e.field,c.data)),e.filter),isPending:!1,error:null}:{filter:void 0,isPending:c.isPending,error:c.error}:{filter:K9(qa(W9.eq(e.field,t)),e.filter),isPending:!1,error:null}},Wle=()=>(0,B.jsx)(`div`,{className:`flex flex-col gap-2`,children:Array.from({length:3},(e,t)=>(0,B.jsx)(od,{className:`h-4 w-full`},t))}),Gle=({text:e})=>(0,B.jsx)(`p`,{className:`text-[13px] text-muted-foreground`,children:e??`Nothing here yet.`}),Kle=({item:e,recordKey:t,owner:n})=>{let{resources:r,views:i}=K(),a=r[e.resource],o=a&&i[a.name],s=Ule(e,t),[c,l]=y9(o,`related:${n}:${e.title}`,e.display);if(!a)return null;let u=e.columns??rk(a,o).filter(t=>t!==e.field);return(0,B.jsx)($S,{title:e.title,help:e.help,actions:(0,B.jsx)(O7,{view:o,value:c,onChange:l}),children:s.isPending?(0,B.jsx)(Wle,{}):s.error?(0,B.jsx)(ny,{title:`Could not load`,error:s.error}):s.filter===null||s.filter===void 0?(0,B.jsx)(Gle,{text:e.empty}):(0,B.jsx)(k7,{model:a,view:o,filter:s.filter,sort:e.sort??``,columns:u,limit:e.limit??10,display:c,empty:e.empty},s.filter)})},qle=(e,t)=>t===e.tenant||e.primaryKey.includes(t),Jle=(e,t)=>{if(t&&t.layout.length>0)return t.layout;let n=Object.values(e.fields).filter(t=>!qle(e,t.name)),r=n.filter(e=>!e.readOnly);return[{kind:`section`,title:`Details`,fields:(r.length>0?r:n).map(e=>e.name)}]},Yle=({resource:e,recordKey:t})=>{let{resources:n}=K(),r=n[e],i=Eg(e,t);return r?i.isPending?(0,B.jsx)(Bv,{title:`Loading`,children:`Fetching the record.`}):i.error?(0,B.jsx)(`div`,{className:`p-8`,children:vs(i.error)&&i.error.status===404?(0,B.jsx)(Bv,{title:`Not found`,children:`This record does not exist, or you cannot see it.`}):(0,B.jsx)(ny,{title:`Could not load the record`,error:i.error})}):(0,B.jsx)(Xle,{model:r,recordKey:t,stored:i.data}):(0,B.jsxs)(Bv,{title:`Not found`,children:[`There is no resource called `,e,`.`]})},Xle=({model:e,recordKey:t,stored:n})=>{let r=K(),{basePath:i}=Rh(),{go:a,open:s}=Wv(),c=r.views[e.name],l=c?.names?.singular??G(e.name),u=Ag(e,c,n.record,t),{state:d}=V(),f=(0,o.useMemo)(()=>kle(r.resources,e),[r.resources,e]),p=Lle(f,Ile(f,e,t).items),m=Vle({model:e,stored:n,recordKey:t,mode:c?.saveFeedback??`toast`,subject:u,draftKey:d.kind===`signed-in`?Mle(d.user.id,e.name,t):void 0,lines:p});ite(m.dirty);let h=pm(),g=W(),_=Uv(e.name),v=qk(e),y=Ey(_,`update`)&&n.permissions?.update!==!1,b=Ey(_,`delete`)&&n.permissions?.delete!==!1,x=Kk({model:e,view:c,restore:v,onDeleted:()=>a({kind:`list`,resource:e.name},{replace:!0}),onReview:()=>void h.invalidateQueries({queryKey:U.record(e.name,t)})}),S=Hle(e,c,r.resources,r.views,n.record,i),{fields:C}=w_(),w=Jle(e,c),T=w.flatMap(e=>e.kind===`sidebar`?e.fields:[]),E=e.fields.status?.type===`enum`?String(n.record.status):void 0,D=L9(e,`updated`),O=D&&n.record[D]?Math.max(0,Math.round((Date.now()-Date.parse(String(n.record[D])))/1e3)):void 0,k=e=>c?.fields[e],A=e=>Oy(n.permissions,e)!==`hidden`,j=r=>{let i=e.fields[r],a=Oy(n.permissions,r);if(!i||a===`hidden`)return null;let o=m.conflicts[r];return(0,B.jsx)(QS,{label:k(r)?.label??G(r),help:k(r)?.help,error:m.errors[r],wide:!!k(r)?.multiline,conflict:o===void 0?void 0:{user:{name:`Someone else`,initials:`?`,hue:40},ago:`just now`,theirValue:o||`—`,onKeepMine:()=>m.keepMine(r),onUseTheirs:()=>m.useTheirs(r)},children:(0,B.jsx)(Ty,{field:i,hints:k(r),value:m.value(r),stored:n.record[r],relationLabel:S.labels[r],relationTo:S.addresses[r],locked:!y||a===`read`,invalid:!!m.errors[r],reveal:i.sensitive?()=>g.reveal(e.name,t,r):void 0,resource:e.name,onChange:e=>m.change(r,e)})},i.sensitive?`${r}:${n.etag}`:r)},M=w.findIndex(e=>e.kind===`sidebar`),N=(0,B.jsx)(iC,{title:`Summary`,rows:T.flatMap(t=>{let r=e.fields[t];if(!r||!A(t))return[];let i=ov(r,n.record[t],k(t)),a=r.type===`enum`?(0,B.jsx)(vA,{value:n.record[t],hints:k(t),children:i}):(0,B.jsx)(`strong`,{className:k(t)?.multiline?`whitespace-pre-line break-words`:void 0,children:i}),o=_y(C,r,k(t));return[{label:k(t)?.label??G(t),value:o?(0,B.jsx)(Sy,{shown:o,part:`display`,field:r,value:n.record[t],fallback:a}):a}]})}),ee={model:e,record:n.record,key:t,etag:n.etag,permissions:n.permissions},te=(0,B.jsxs)(B.Fragment,{children:[m.dirty&&(0,B.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Unsaved changes`}),m.dirty&&y&&(0,B.jsx)(H,{className:`max-md:min-h-11`,disabled:m.saving,onClick:m.discard,children:`Discard`}),b&&(0,B.jsx)(H,{variant:`danger`,className:`max-md:min-h-11`,onClick:()=>void x.start({key:t,title:u,etag:n.etag,snapshot:n.record}),children:`Delete`}),y&&(0,B.jsxs)(H,{variant:`primary`,className:`max-md:min-h-11 max-md:flex-1`,loading:m.saving,disabled:!m.dirty&&m.phase!==`saved`,onClick:()=>void m.save(),children:[m.phase===`saved`&&(0,B.jsx)(de,{className:`size-4`}),m.phase===`saved`?`Saved`:`Save`]})]});return(0,B.jsxs)(`div`,{className:`flex flex-1 flex-col`,children:[x.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)(aC,{collection:c?.names?.plural??G(e.name),title:u,status:{label:E?Bo(E,k(`status`)?.valueLabels):l,tone:E?YO(E):`neutral`},lastEditedBy:{ago:O===void 0?`recently`:Hf(O)},actions:(0,B.jsx)(`div`,{className:`hidden items-center gap-4 md:flex`,children:te})}),m.message&&(0,B.jsx)(`div`,{className:`mt-4`,children:(0,B.jsx)(ny,{title:`Not saved`,error:Error(m.message)})}),m.linesConflict&&(0,B.jsx)(`div`,{className:`mt-4`,children:(0,B.jsx)(ny,{title:`The lines were changed by someone else`,error:Error(`The lines were reloaded. Your new order is kept: Save again to apply it, or Discard to drop it.`)})}),m.restored&&(0,B.jsxs)(`div`,{className:`mt-4 flex items-center justify-between gap-3 rounded-lg border bg-surface px-3 py-2 text-[13px]`,role:`status`,children:[(0,B.jsx)(`span`,{children:`Your unsaved changes were restored.`}),(0,B.jsxs)(`span`,{className:`flex gap-2`,children:[(0,B.jsx)(H,{size:`sm`,onClick:m.dismissRestored,children:`Keep`}),(0,B.jsx)(H,{size:`sm`,onClick:m.discard,children:`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:[w.flatMap((r,i)=>{if(r.kind===`related`)return[(0,B.jsx)(Kle,{item:r,recordKey:t,owner:e.name},`related:${r.title}`)];if(r.kind===`custom`)return r.sidebar?[]:[(0,B.jsx)(R9,{item:r,scope:ee},`custom:${i}`)];if(r.kind===`map`)return r.sidebar?[]:[(0,B.jsx)(z9,{item:r,record:n.record},`map:${i}`)];if(r.kind!==`section`)return[];let a=r.fields.filter(t=>e.fields[t]&&A(t));return a.length===0?[]:[(0,B.jsx)($S,{title:r.title,help:r.help,children:(0,B.jsx)(`div`,{className:`grid grid-cols-1 gap-x-6 gap-y-5 sm:grid-cols-2`,children:a.map(j)})},r.title)]}),f&&(0,B.jsx)(jle,{lines:f,draft:p,vatRate:Number(n.record.vatRate??21)/100,saving:m.saving})]}),(0,B.jsxs)(`aside`,{className:`space-y-4 md:pt-8`,children:[(0,B.jsx)(Ole,{model:e,stored:n,recordKey:t}),M===-1&&N,w.map((e,t)=>e.kind===`custom`&&e.sidebar?(0,B.jsx)(R9,{item:e,scope:ee},`custom:${t}`):e.kind===`map`&&e.sidebar?(0,B.jsx)(z9,{item:e,record:n.record},`map:${t}`):t===M?(0,B.jsx)(o.Fragment,{children:N},`summary`):null),(0,B.jsx)(iC,{title:`Details`,rows:[L9(e,`created`),D].flatMap(t=>{let r=t?e.fields[t]:void 0;return t&&r&&A(t)?[{label:k(t)?.label??G(t),value:ov(r,n.record[t],k(t))}]:[]})}),S.records.length>0&&(0,B.jsx)(rC,{title:`Related records`,children:(0,B.jsx)(nC,{records:S.records,onNavigate:s})})]})]})]})}),(m.dirty||b||y)&&(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:te})]})},Zle=e=>vs(e)?e.status===401||e.status===403?`It did not accept your sign-in: ${e.message}`:e.message:`It did not answer.`,Qle=({status:e})=>{let t=pm();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.jsxs)(`h1`,{className:`text-[15px] font-semibold`,children:[`Cannot reach `,e.source.label]}),(0,B.jsxs)(`p`,{className:`mt-1 text-[13px] text-muted-foreground`,children:[Zle(e.error),` The rest of the app works as before.`]}),(0,B.jsx)(H,{className:`mt-3`,onClick:()=>void t.refetchQueries({queryKey:U.sourceMetas(e.source.url)}),children:`Try again`})]})}):(0,B.jsxs)(`div`,{className:`flex h-full min-h-48 flex-1 items-center justify-center gap-2 text-[13px] text-muted-foreground`,children:[(0,B.jsx)(Zd,{}),` Loading from `,e.source.label]})},$le=so(),eue=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??G(t.name)}]}),tue=e=>{let t=e.map(e=>e.label.toLowerCase());return t.length===0?`Search`:t.length===1?`Search ${t[0]}`:t.length===2?`Search ${t[0]} and ${t[1]}`:`Search ${t[0]}, ${t[1]} and more`},nue=e=>qa($le.search(e.trim())),q9=e=>{let t=e.view?.searchResult?.title;return t?.length?t:[kg(e.model,e.view)]},J9=e=>{let t=q9(e);return e.view?.searchResult?.subtitle??e.model.search?.find(e=>!t.includes(e))},rue=e=>{let t=J9(e),n=[...q9(e),...t?[t]:[],...e.model.search??[]];return[...new Set([...e.model.primaryKey,...n.filter(t=>Object.hasOwn(e.model.fields,t))])]},Y9=(e,t,n)=>{let r=t[n];return r==null?``:e.model.fields[n]?.type===`enum`?Bo(String(r),e.view?.fields[n]?.valueLabels):String(r)},iue=(e,t,n,r=``)=>{let i=mo(Mg(e.model,t)),a=q9(e),o=J9(e),s=Ka(e.model,t,n,[...a,...o?[o]:[]])??o,c=s?Y9(e,t,s):``;return{id:i,title:a.map(n=>Y9(e,t,n)).filter(Boolean).join(` `)||i,...c&&{subtitle:c},href:qo({kind:`record`,resource:e.model.name,key:i},r)}},aue=()=>{let e=K(),t=W(),{basePath:n}=Rh(),r=(0,o.useMemo)(()=>eue(e),[e]),[i,a]=(0,o.useState)(``),s=i.trim(),c=LO(s,200),l=s.length>=2,u=l&&c.length>=2,d=Dh({queries:r.map(e=>({queryKey:[`global-search`,e.model.name,c],enabled:u,staleTime:1/0,gcTime:0,queryFn:()=>t.list(e.model.name,{filter:nue(c),pageSize:5,fields:rue(e)})}))}),f=r.flatMap((e,t)=>{let r=d[t];if(!u||!r)return[];if(r.error)return[{id:e.model.name,label:e.label,hits:[],failed:!0}];let i=(r.data?.items??[]).map(t=>iue(e,t,c,n));return i.length>0?[{id:e.model.name,label:e.label,hits:i}]:[]});return{available:r.length>0,placeholder:tue(r),text:i,setText:a,query:u?c:``,loading:l&&(s!==c||d.some(e=>e.isFetching)),groups:f}},oue=e=>!!(e?.updateAvailable&&e.indicator),X9={immediate:`Updates as soon as a release is out`,weekly:`Updates at a set time every week`,scheduled:`Updates at the time set for this release`,manual:`Updates only when asked to`},sue=e=>e.updating?`Updating now`:e.nextUpdateAt?`${X9[e.policy]}: next on ${zf(Date.parse(e.nextUpdateAt))} UTC`:X9[e.policy],cue=e=>vs(e)&&e.status===409?`Already on the latest version, or an update is running.`:vs(e)&&e.status===403?`Only an admin can update the runtime.`:`The update could not be started. Try again later.`,lue=18e5,uue=3e4,due=e=>{let t=Tg(),n=(0,o.useRef)(t);n.current=t;let r=t!==void 0;return(0,o.useMemo)(()=>r?Uu({url:e,token:()=>n.current}):void 0,[e,r])},fue=e=>{let[t,n]=(0,o.useState)(),[r,i]=(0,o.useState)(!1),[a,s]=(0,o.useState)(),[c,l]=(0,o.useState)(),u=t?.updating??!1;return(0,o.useEffect)(()=>{if(!e)return;let t=!0,r=()=>e.status().then(e=>{t&&(n(e),l(void 0))},e=>t&&l(e));r();let i=setInterval(()=>void r(),u?uue:lue);return()=>{t=!1,clearInterval(i)}},[e,u]),{status:t,update:(0,o.useCallback)(async()=>{e&&(i(!0),s(void 0),await e.update().then(n,s),i(!1))},[e]),requesting:r,error:a,checkError:c}},Z9=({label:e,value:t})=>(0,B.jsxs)(`div`,{className:`flex justify-between gap-4 py-1 text-[13px]`,children:[(0,B.jsx)(`span`,{className:`text-muted-foreground`,children:e}),(0,B.jsx)(`span`,{className:`font-medium tabular-nums`,children:t})]}),Q9=({client:e})=>{let{status:t,update:n,requesting:r,error:i,checkError:a}=fue(e),[s,c]=(0,o.useState)(!1);return!t||!s&&!oue(t)?null:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(H,{size:`sm`,variant:`ghost`,"aria-label":`Update available`,title:`Update available`,onClick:()=>c(!0),className:`max-md:size-9 max-md:p-0`,children:[(0,B.jsx)(xe,{className:`size-3.5 text-primary`}),(0,B.jsx)(`span`,{className:`max-md:sr-only`,children:`Update`})]}),s&&(0,B.jsxs)(Kf,{title:`Runtime update`,description:sue(t),onClose:()=>c(!1),actions:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(H,{onClick:()=>c(!1),children:`Close`}),(0,B.jsx)(H,{variant:`primary`,loading:r,disabled:t.updating||!t.updateAvailable,onClick:()=>void n(),children:t.updating?`Updating…`:`Update now`})]}),children:[(0,B.jsx)(Z9,{label:`Current version`,value:t.version}),(0,B.jsx)(Z9,{label:`Latest version`,value:t.latest}),i!==void 0&&(0,B.jsx)(`p`,{role:`alert`,className:`mt-3 text-[13px] text-danger-text`,children:cue(i)}),a!==void 0&&(0,B.jsx)(`p`,{className:`mt-3 text-[13px] text-muted-foreground`,children:`The status could not be checked again; this is the last one read.`})]})]})},pue=({url:e})=>(0,B.jsx)(Q9,{client:due(e)}),mue=({url:e,client:t})=>t?(0,B.jsx)(Q9,{client:t}):(0,B.jsx)(pue,{url:e}),hue=({signIn:e,onStop:t})=>{let[n,r]=(0,o.useState)(!1),[i,a]=(0,o.useState)(),s=async()=>{r(!0),a(void 0);try{await t()}catch(e){if(!(e instanceof Ks))throw e;a(df(e)),r(!1)}};return(0,B.jsxs)(`div`,{role:`region`,"aria-label":`Staff session`,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-[13px] text-warning-text`,children:[(0,B.jsx)(see,{"aria-hidden":!0,className:`size-4 shrink-0`}),(0,B.jsxs)(`p`,{className:`min-w-64 flex-1 break-words`,children:[(0,B.jsx)(`span`,{className:`font-semibold`,children:e.staffName??e.staff}),` is signed in as `,(0,B.jsx)(`span`,{className:`font-semibold`,children:e.user}),` until`,` `,zf(Date.parse(e.expiresAt)),`. Reason: `,e.reason]}),i&&(0,B.jsx)(`p`,{role:`alert`,className:`text-xs font-medium text-danger-text`,children:i}),(0,B.jsx)(H,{size:`sm`,loading:n,onClick:()=>void s(),children:`Stop staff session`})]})},gue=(e,t,n)=>({filter:n.filter??``,orderBy:n.orderBy??Tv(e,t),pageSize:n.limit??3,fields:[...new Set([...e.primaryKey,kg(e,t),n.status])]}),_ue=(e,t,n,r,i,a)=>r.map(r=>{let o=mo(Mg(e,r)),s=String(r[n.status]??``);return{id:o,label:Ag(e,t,r,o),href:qo({kind:`record`,resource:e.name,key:o},i),status:e.fields[n.status]?.type===`enum`&&s?Bo(s,t.fields[n.status]?.valueLabels):s,tone:n.tones[s]??`neutral`,pulse:n.pulse?.includes(s)??!1,active:o===a}}),vue=(e,t,n,r,i)=>{let a=n.find(t=>mo(Mg(e,t))===r);return a!==void 0&&t.some(e=>!Object.is(a[e],i[e]))},$9=({model:e,request:t})=>U.navRecent(e.name,t.filter,t.orderBy,t.pageSize),yue=e=>{let t=pm();(0,o.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($9(n));e&&vue(n.model,n.request.fields,e.items,a,o)&&t.invalidateQueries({queryKey:$9(n),exact:!0})}}),[t,e])},bue=(e,t,n)=>{let r=W(),i=(0,o.useMemo)(()=>{let t=o9(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:gue(r,n,i)}]:[]})},[e]);yue(i);let a=Dh({queries:i.map(e=>({queryKey:$9(e),queryFn:()=>r.list(e.model.name,e.request),refetchOnWindowFocus:!0}))});return Object.fromEntries(i.map(({model:e,view:r,recent:i},o)=>{let s=a[o];if(s.isPending)return[e.name,{state:`loading`}];if(s.isError)return[e.name,{state:`error`}];let c=n.resource===e.name?n.key:void 0;return[e.name,{state:`ready`,records:_ue(e,r,i,s.data.items,t,c)}]}))},xue=e=>e?.kind===`page`?e.page:e?.resource,Sue=e=>e?.kind===`record`?e:void 0,Cue=({workspace:e,sidebarMode:t,assistant:n,runtime:r})=>{let i=K(),{state:a,session:s,signOut:c,stopStaffSession:l,organizations:u}=V(),d=$h();if(a.kind!==`signed-in`&&a.kind!==`visitor`)throw Error(`The shell is only rendered for a signed-in user or a visitor`);let f=a.kind===`signed-in`?a.user:void 0,p=a.kind===`signed-in`?a.staff:void 0,{path:m,params:h,basePath:g}=Rh(),{address:_,go:v,open:y}=Wv(),b=xue(_),x=Sue(_),S=aue(),C=Rg(),w=yce(i,g,bue(i,g,{resource:b,key:x?.key})),T=Object.keys(i.pages)[0],E=Object.keys(i.resources)[0],D=_?.kind===`page`?i.pages[_.page]:void 0;(0,o.useEffect)(()=>{m===`/`&&(T?v({kind:`page`,page:T},{replace:!0}):E&&v({kind:`list`,resource:E},{replace:!0}))},[m,T,E,v]);let O=_?.kind===`page`?void 0:_?.resource,k=O?zv(i,O):void 0,A=O?i.views[O]:void 0,j=w.find(e=>e.items.some(e=>e.id===b)),M=O?i.resources[O]:void 0,N=Eg(x?.resource??``,x?.key??``,!!(M&&x)),ee=M&&x&&N.data?Ag(M,A,N.data.record,x.key):void 0,te=!!x&&(N.isLoading||k?.state===`loading`),{shell:ne}=w_(),P=ne?.actions,re=ne?.rightPanel,[ie,ae]=(0,o.useState)(!1),F=i.assistant?.url,oe=F&&(0,B.jsx)(Wte,{open:ie,onToggle:()=>ae(!ie)}),se=F&&ie&&(0,B.jsx)(Kte,{url:F,client:n,page:h.size>0?`${m}?${h}`:m,onClose:()=>ae(!1)}),ce=i.errorReporting;(0,o.useEffect)(()=>{ce&&y_(ce)},[ce]);let I=i.runtime?.url,le=I&&(0,B.jsx)(mue,{url:I,client:r}),ue=gce((0,o.useCallback)(()=>n9(g),[g]),!!f),de=f&&hce(f,ue.current),fe=de?xg(de):!1,pe=Sle(),me=ace(!!(u&&f)),he=me.current,ge=!!u&&he!==void 0&&!he.organization,_e=u&&f?og[m]:void 0,ve=f?m===`/-/account`?`Sign-in & security`:m===`/-/sign-in-policy`?`Sign-in policy`:_e:void 0,ye=ve?[ve]:Yte({basePath:g,address:_,group:j?.label,page:D,resourceLabel:A?.names?.plural??(O&&G(O)),recordTitle:ee,recordLoading:te}),be=f&&m===`/-/account`?(0,B.jsx)($p,{email:f.email}):f&&m===`/-/sign-in-policy`?fe?(0,B.jsx)(dm,{}):(0,B.jsx)(Bv,{title:`Admins only`,children:`Only an admin can change how people sign in.`}):_e&&m===`/-/organization`?(0,B.jsx)(uce,{current:he,basePath:g,onChanged:me.reload}):_e&&(m===`/-/organization/members`||m===`/-/organization/invitations`)?lg(he)?m===`/-/organization/members`?(0,B.jsx)(tce,{current:he}):(0,B.jsx)(ice,{current:he}):(0,B.jsx)(Bv,{title:`Owners and admins only`,children:`Only the organization's owners and admins manage its members.`}):_e&&m===`/-/organizations`||ge?(0,B.jsx)(mce,{state:me,basePath:g}):_?_.kind===`page`?D?(0,B.jsx)(ole,{name:D.name},D.name):(0,B.jsxs)(Bv,{title:`Not found`,children:[`There is no page called `,_.page,`.`]}):k&&k.state!==`ready`?(0,B.jsx)(Qle,{status:k}):_.kind===`create`?(0,B.jsx)(_C,{resource:_.resource,values:_.values},`${_.resource}/new?${new URLSearchParams(_.values).toString()}`):_.kind===`record`?(0,B.jsx)(Yle,{resource:_.resource,recordKey:_.key},`${_.resource}/${_.key}`):(0,B.jsx)($se,{address:_},_.resource):m===`/`?(0,B.jsx)(Bv,{title:`Choose a resource`,children:`Pick one from the sidebar.`}):(0,B.jsx)(Bv,{title:`Not found`,children:`There is nothing at this address.`}),xe=(0,B.jsx)(af,{pageScroll:!0,sidebarMode:t??`text-small`,activeItem:b??``,breadcrumb:ye,user:de&&Sg(de),onSignOut:f&&(()=>void c()),signIn:f?void 0:d.link(),workspace:he?.organization?.name??e,navGroups:w,bottomBar:Jte(i,g,b),userMenu:[..._ce(i,g,b),...u&&f?ug(g,m,he):[],...f?uee(g,m,fe):[]],organizations:u&&{...he?.organization&&{current:{id:he.organization.id,name:he.organization.name}},others:me.organizations.filter(e=>e.id!==he?.organization?.id),onSwitch:e=>void s.organizations.switchTo(e).then(()=>n9(g))},theme:{preference:C.preference,onChange:C.choose},roles:ue.current?.active?{active:ue.current.active,roles:ue.current.roles,onSwitch:ue.switchTo}:void 0,onNavigate:y,search:S.available?{placeholder:S.placeholder,text:S.text,onTextChange:S.setText,query:S.query,loading:S.loading,groups:S.groups,onSelect:y}:void 0,actions:(P||le||oe)&&(0,B.jsxs)(B.Fragment,{children:[P&&(0,B.jsx)(by,{name:`shell.actions`,fallback:null,children:(0,B.jsx)(P,{})}),le,oe]}),rightPanel:(re||se)&&(0,B.jsxs)(B.Fragment,{children:[re&&(0,B.jsx)(by,{name:`shell.rightPanel`,fallback:null,children:(0,B.jsx)(re,{})}),se]}),children:be}),Se=fe&&pe.length>0;return!p&&!Se?xe:(0,B.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[p&&(0,B.jsx)(hue,{signIn:p,onStop:l}),Se&&(0,B.jsx)(wle,{off:pe}),(0,B.jsx)(`div`,{className:`min-h-0 flex-1`,children:xe})]})},wue=({baseUrl:e,client:t,sources:n,workspace:r,sidebarMode:i,ui:a,assistant:o,runtime:s,pluginLoader:c})=>{let{state:l,session:u,markSignedOut:d}=V();return(0,B.jsx)(Ih,{baseUrl:e,client:t,sources:n,token:l.kind===`visitor`?void 0:u.token,onUnauthenticated:d,children:(0,B.jsx)(Hv,{children:(0,B.jsx)(qg,{children:(0,B.jsx)(Cle,{ui:a,...c&&{loader:c},children:(0,B.jsx)(Cue,{workspace:r,sidebarMode:i,assistant:o,runtime:s})})})})})},Tue=({auth:e,workspace:t,basePath:n,initialUrl:r,...i})=>(0,B.jsx)(Lg,{children:(0,B.jsx)(Tf,{session:e,children:(0,B.jsx)(nte,{basePath:n,initialUrl:r,children:(0,B.jsx)(_g,{workspace:t,children:(0,B.jsx)(wue,{workspace:t,...i})})})})});export{d_ as A,Jg as B,M_ as C,S_ as D,O_ as E,t_ as F,Fh as G,Tg as H,e_ as I,b as J,ip as K,Qg as L,a_ as M,i_ as N,x_ as O,r_ as P,Xg as R,N_ as S,Vte as T,Ih as U,Eg as V,W,$k as _,N9 as a,Wv as b,k9 as c,are as d,ore as f,Wne as g,Qne as h,B9 as i,c_ as j,g_ as k,w9 as l,Zne as m,H9 as n,P9 as o,ZA as p,z as q,V9 as r,fle as s,Tue as t,u9 as u,Xk as v,j_ as w,Pv as x,Gv as y,Yg as z};