import{i as u}from"./_virtual___federation_fn_import-DB-0B1B_.js";import{j as l}from"./jsx-runtime-u17CrQMm.js";import{a as E,f as p}from"./error-formatter-B41KnHG1.js";import{U as h}from"./error-Deo1phpd.js";const{createContext:y,Component:g,createElement:f,useContext:R,useState:F,useMemo:K,forwardRef:U}=await u("react"),m=y(null),d={didCatch:!1,error:null};let v=class extends g{constructor(e){super(e),this.resetErrorBoundary=this.resetErrorBoundary.bind(this),this.state=d}static getDerivedStateFromError(e){return{didCatch:!0,error:e}}resetErrorBoundary(){const{error:e}=this.state;if(e!==null){for(var r,t,o=arguments.length,n=new Array(o),a=0;a<o;a++)n[a]=arguments[a];(r=(t=this.props).onReset)===null||r===void 0||r.call(t,{args:n,reason:"imperative-api"}),this.setState(d)}}componentDidCatch(e,r){var t,o;(t=(o=this.props).onError)===null||t===void 0||t.call(o,e,r)}componentDidUpdate(e,r){const{didCatch:t}=this.state,{resetKeys:o}=this.props;if(t&&r.error!==null&&B(e.resetKeys,o)){var n,a;(n=(a=this.props).onReset)===null||n===void 0||n.call(a,{next:o,prev:e.resetKeys,reason:"keys"}),this.setState(d)}}render(){const{children:e,fallbackRender:r,FallbackComponent:t,fallback:o}=this.props,{didCatch:n,error:a}=this.state;let i=e;if(n){const c={error:a,resetErrorBoundary:this.resetErrorBoundary};if(typeof r=="function")i=r(c);else if(t)i=f(t,c);else if(o!==void 0)i=o;else throw a}return f(m.Provider,{value:{didCatch:n,error:a,resetErrorBoundary:this.resetErrorBoundary}},i)}};function B(){let s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:[];return s.length!==e.length||s.some((r,t)=>!Object.is(r,e[t]))}const{Button:x,ErrorDisplay:C}=await u("@baseplate-dev/ui-components"),{useContext:b}=await u("react");function j({resetButtonLabel:s}){const{resetErrorBoundary:e,error:r}=b(m)??{resetErrorBoundary:()=>{},error:void 0},t=r instanceof h?r.title:void 0,o=!(r instanceof h),n=p(r,"");return l.jsx(C,{header:t,error:n,actions:o&&l.jsx(x,{onClick:e,children:s})})}function T({children:s,resetButtonLabel:e,onReset:r}){return l.jsx(v,{fallback:l.jsx(j,{resetButtonLabel:e??"Reload Page"}),onError:t=>{E(t)},onReset:()=>{r?r():globalThis.location.reload()},children:s})}export{T as E};
//# sourceMappingURL=error-boundary-DgBD6_Zp.js.map
