import{s as h}from"./chunk-LvLJmgfZ.js";import{t as f}from"./react-Bj1aDYRI.js";import{t as y}from"./compiler-runtime-B3qBwwSJ.js";import{n as x}from"./constants-CdR60lKM.js";import{t as E}from"./jsx-runtime-CP2fAiZX.js";import{t as g}from"./button-BmOH9agK.js";var i=h(f()),m=(0,i.createContext)(null),u={didCatch:!1,error:null},v=class extends i.Component{constructor(e){super(e),this.resetErrorBoundary=this.resetErrorBoundary.bind(this),this.state=u}static getDerivedStateFromError(e){return{didCatch:!0,error:e}}resetErrorBoundary(){let{error:e}=this.state;if(e!==null){var r,t,o=[...arguments];(r=(t=this.props).onReset)==null||r.call(t,{args:o,reason:"imperative-api"}),this.setState(u)}}componentDidCatch(e,r){var t,o;(t=(o=this.props).onError)==null||t.call(o,e,r)}componentDidUpdate(e,r){let{didCatch:t}=this.state,{resetKeys:o}=this.props;if(t&&r.error!==null&&b(e.resetKeys,o)){var s,n;(s=(n=this.props).onReset)==null||s.call(n,{next:o,prev:e.resetKeys,reason:"keys"}),this.setState(u)}}render(){let{children:e,fallbackRender:r,FallbackComponent:t,fallback:o}=this.props,{didCatch:s,error:n}=this.state,a=e;if(s){let l={error:n,resetErrorBoundary:this.resetErrorBoundary};if(typeof r=="function")a=r(l);else if(t)a=(0,i.createElement)(t,l);else if(o!==void 0)a=o;else throw n}return(0,i.createElement)(m.Provider,{value:{didCatch:s,error:n,resetErrorBoundary:this.resetErrorBoundary}},a)}};function b(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:[];return e.length!==r.length||e.some((t,o)=>!Object.is(t,r[o]))}function B(e){if(e==null||typeof e.didCatch!="boolean"||typeof e.resetErrorBoundary!="function")throw Error("ErrorBoundaryContext not found")}function C(){let e=(0,i.useContext)(m);B(e);let[r,t]=(0,i.useState)({error:null,hasError:!1}),o=(0,i.useMemo)(()=>({resetBoundary:()=>{e.resetErrorBoundary(),t({error:null,hasError:!1})},showBoundary:s=>t({error:s,hasError:!0})}),[e.resetErrorBoundary]);if(r.hasError)throw r.error;return o}var p=y(),d=h(E(),1);const w=e=>{let r=(0,p.c)(2),t;return r[0]===e.children?t=r[1]:(t=(0,d.jsx)(v,{FallbackComponent:j,children:e.children}),r[0]=e.children,r[1]=t),t};var j=e=>{var c;let r=(0,p.c)(9),t;r[0]===Symbol.for("react.memo_cache_sentinel")?(t=(0,d.jsx)("h1",{className:"text-2xl font-bold",children:"Something went wrong"}),r[0]=t):t=r[0];let o=(c=e.error)==null?void 0:c.message,s;r[1]===o?s=r[2]:(s=(0,d.jsx)("pre",{className:"text-xs bg-muted/40 border rounded-md p-4 max-w-[80%] whitespace-normal",children:o}),r[1]=o,r[2]=s);let n;r[3]===Symbol.for("react.memo_cache_sentinel")?(n=(0,d.jsxs)("div",{children:["If this is an issue with marimo, please report it on"," ",(0,d.jsx)("a",{href:x.issuesPage,target:"_blank",className:"underline",children:"GitHub"}),"."]}),r[3]=n):n=r[3];let a;r[4]===e.resetErrorBoundary?a=r[5]:(a=(0,d.jsx)(g,{"data-testid":"reset-error-boundary-button",onClick:e.resetErrorBoundary,variant:"outline",children:"Try again"}),r[4]=e.resetErrorBoundary,r[5]=a);let l;return r[6]!==s||r[7]!==a?(l=(0,d.jsxs)("div",{className:"flex-1 flex items-center justify-center flex-col space-y-4 max-w-2xl mx-auto px-6",children:[t,s,n,a]}),r[6]=s,r[7]=a,r[8]=l):l=r[8],l};export{C as n,w as t};
