import{r as e}from"./rolldown-runtime-S-ySWqyJ.js";import{bi as t,ri as n}from"./vendor-DU4C2Mru.js";import{yt as r}from"./index-B7s3VjPV.js";var i=e(t(),1),a=n(),o=class extends i.Component{state={hasError:!1};static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e,t){r(e,{boundary:`widget`,componentName:this.props.componentName??`unknown`,route:typeof window<`u`?window.location.pathname:``,componentStack:t.componentStack})}render(){return this.state.hasError?this.props.fallback??(0,a.jsxs)(`div`,{className:`glk-card !py-8 !px-4 flex flex-col items-center justify-center gap-2 bg-zinc-50 dark:bg-zinc-900`,children:[(0,a.jsx)(`div`,{className:`flex h-8 w-8 items-center justify-center rounded-full bg-zinc-200 dark:bg-zinc-800`,children:(0,a.jsx)(`span`,{className:`text-sm text-zinc-400`,children:`!`})}),(0,a.jsx)(`p`,{className:`text-xs text-zinc-400`,children:`Something went wrong loading this widget.`}),(0,a.jsx)(`button`,{className:`rounded-md bg-zinc-100 px-3 py-1.5 text-xs font-medium text-zinc-600 transition-all hover:bg-zinc-200 active:scale-95 dark:bg-zinc-800 dark:text-zinc-400 dark:hover:bg-zinc-700`,onClick:()=>this.setState({hasError:!1}),children:`Try again`})]}):this.props.children}};function s(e){if(!Number.isFinite(e)||e<=0)return 1;let t=1;for(;t*1+(t-1)*0-64<e+0&&(t++,!(t>4e3)););return t}function c(e,t,n,r,i=24){let a=Math.max(1,Math.floor(r)),o=Math.max(0,Math.floor(i)),s=Array(a).fill(1),c={};for(let r of e){let e=Math.max(1,Math.floor(t[r]??1)),i=Math.max(1,Math.min(a,Math.floor(n[r]??1))),l=0,u=1/0,d=1/0;for(let t=0;t<=a-i;t++){let n=s[t];for(let e=t+1;e<t+i;e++)n=Math.max(n,s[e]);let r=n+e+o,c=1/0,f=-1/0;for(let e=0;e<a;e++){let n=e>=t&&e<t+i?r:s[e];n<c&&(c=n),n>f&&(f=n)}let p=f-c;(n<u||n===u&&p<d)&&(u=n,d=p,l=t)}c[r]={colStart:l+1,rowStart:u,colSpan:i,rowSpan:e};for(let t=l;t<l+i;t++)s[t]=u+e+o}return c}function l({keys:e,colSpans:t,declaredRowSpans:n}){let r=(0,i.useRef)(null),[a,o]=(0,i.useState)({}),[s,l]=(0,i.useState)(1),u=(0,i.useRef)(1),d=(0,i.useCallback)((e,t)=>{let n=Math.max(296,t);o(t=>t[e]===n?t:{...t,[e]:n})},[]);(0,i.useEffect)(()=>{let e=r.current;if(!e)return;let t=()=>{let t=getComputedStyle(e).getPropertyValue(`--glk-cols`).trim(),n=parseInt(t,10),r=Number.isFinite(n)&&n>=1?n:1;if(r===u.current)return;u.current=r;let i=()=>l(r),a=document;typeof a.startViewTransition==`function`?a.startViewTransition(i):i()};t();let n=new ResizeObserver(t);return n.observe(e),window.addEventListener(`resize`,t),()=>{n.disconnect(),window.removeEventListener(`resize`,t)}},[]);let f=(0,i.useMemo)(()=>{if(!n)return a;let e={...n};for(let t of Object.keys(a))a[t]>0&&(e[t]=a[t]);return e},[a,n]);return{canvasRef:r,positions:(0,i.useMemo)(()=>c(e,f,t,s),[e,f,t,s]),numCols:s,reportSpan:d}}function u({key:e,onSpanChange:t}){let n=(0,i.useRef)(null),r=(0,i.useRef)(null),a=(0,i.useCallback)(()=>{r.current??=requestAnimationFrame(()=>{r.current=null;let i=n.current;if(!i)return;let a=i.firstElementChild;t(e,s(a?a.scrollHeight:i.scrollHeight))})},[e,t]);return(0,i.useEffect)(()=>{let e=n.current;if(!e)return;a();let t=new ResizeObserver(a);t.observe(e);let i=e.firstElementChild;i&&t.observe(i);let o=new MutationObserver(()=>{let n=e.firstElementChild;n&&t.observe(n),a()});return o.observe(e,{childList:!0,subtree:!0,characterData:!0}),()=>{t.disconnect(),o.disconnect(),r.current!=null&&cancelAnimationFrame(r.current),r.current=null}},[a]),{ref:n}}export{l as n,o as r,u as t};