import { s as __toESM, t as __commonJSMin } from "./chunk-BNovOVIE.js";
import { t as Button } from "./button-Dj4BTre0.js";
import { t as require_react } from "./react-DA-nE2FX.js";
import { t as require_compiler_runtime } from "./compiler-runtime-CEbnTgxf.js";
import { t as require_jsx_runtime } from "./jsx-runtime-COBk7ree.js";
import { n as Constants } from "./constants-D0gkYoE2.js";
var require_ReactPropTypesSecret = /* @__PURE__ */ __commonJSMin(((e, u) => {
  u.exports = "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";
})), require_factoryWithThrowingShims = /* @__PURE__ */ __commonJSMin(((e, u) => {
  var d = require_ReactPropTypesSecret();
  function f() {
  }
  function p() {
  }
  p.resetWarningCache = f, u.exports = function() {
    function e2(e3, u3, f2, p2, m2, h) {
      if (h !== d) {
        var g = /* @__PURE__ */ Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");
        throw g.name = "Invariant Violation", g;
      }
    }
    e2.isRequired = e2;
    function u2() {
      return e2;
    }
    var m = {
      array: e2,
      bigint: e2,
      bool: e2,
      func: e2,
      number: e2,
      object: e2,
      string: e2,
      symbol: e2,
      any: e2,
      arrayOf: u2,
      element: e2,
      elementType: e2,
      instanceOf: u2,
      node: e2,
      objectOf: u2,
      oneOf: u2,
      oneOfType: u2,
      shape: u2,
      exact: u2,
      checkPropTypes: p,
      resetWarningCache: f
    };
    return m.PropTypes = m, m;
  };
})), require_prop_types = /* @__PURE__ */ __commonJSMin(((e, u) => {
  u.exports = require_factoryWithThrowingShims()();
})), import_react = /* @__PURE__ */ __toESM(require_react()), ErrorBoundaryContext = (0, import_react.createContext)(null), initialState = {
  didCatch: false,
  error: null
}, ErrorBoundary = class extends import_react.Component {
  constructor(e) {
    super(e), this.resetErrorBoundary = this.resetErrorBoundary.bind(this), this.state = initialState;
  }
  static getDerivedStateFromError(e) {
    return {
      didCatch: true,
      error: e
    };
  }
  resetErrorBoundary() {
    let { error: e } = this.state;
    if (e !== null) {
      var u, d, f = [...arguments];
      (u = (d = this.props).onReset) == null || u.call(d, {
        args: f,
        reason: "imperative-api"
      }), this.setState(initialState);
    }
  }
  componentDidCatch(e, u) {
    var d, f;
    (d = (f = this.props).onError) == null || d.call(f, e, u);
  }
  componentDidUpdate(e, u) {
    let { didCatch: d } = this.state, { resetKeys: f } = this.props;
    if (d && u.error !== null && hasArrayChanged(e.resetKeys, f)) {
      var p, m;
      (p = (m = this.props).onReset) == null || p.call(m, {
        next: f,
        prev: e.resetKeys,
        reason: "keys"
      }), this.setState(initialState);
    }
  }
  render() {
    let { children: e, fallbackRender: u, FallbackComponent: d, fallback: f } = this.props, { didCatch: p, error: m } = this.state, h = e;
    if (p) {
      let e2 = {
        error: m,
        resetErrorBoundary: this.resetErrorBoundary
      };
      if (typeof u == "function") h = u(e2);
      else if (d) h = (0, import_react.createElement)(d, e2);
      else if (f !== void 0) h = f;
      else throw m;
    }
    return (0, import_react.createElement)(ErrorBoundaryContext.Provider, { value: {
      didCatch: p,
      error: m,
      resetErrorBoundary: this.resetErrorBoundary
    } }, h);
  }
};
function hasArrayChanged() {
  let e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [], u = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
  return e.length !== u.length || e.some((e2, d) => !Object.is(e2, u[d]));
}
var import_compiler_runtime = require_compiler_runtime(), import_jsx_runtime = /* @__PURE__ */ __toESM(require_jsx_runtime(), 1);
const ErrorBoundary$1 = (e) => {
  let u = (0, import_compiler_runtime.c)(2), d;
  return u[0] === e.children ? d = u[1] : (d = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ErrorBoundary, {
    FallbackComponent,
    children: e.children
  }), u[0] = e.children, u[1] = d), d;
};
var FallbackComponent = (e) => {
  var _a;
  let u = (0, import_compiler_runtime.c)(9), f;
  u[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (f = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h1", {
    className: "text-2xl font-bold",
    children: "Something went wrong"
  }), u[0] = f) : f = u[0];
  let p = (_a = e.error) == null ? void 0 : _a.message, m;
  u[1] === p ? m = u[2] : (m = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("pre", {
    className: "text-xs bg-muted/40 border rounded-md p-4 max-w-[80%] whitespace-normal",
    children: p
  }), u[1] = p, u[2] = m);
  let g;
  u[3] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (g = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
    "If this is an issue with marimo, please report it on",
    " ",
    /* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", {
      href: Constants.issuesPage,
      target: "_blank",
      className: "underline",
      children: "GitHub"
    }),
    "."
  ] }), u[3] = g) : g = u[3];
  let _;
  u[4] === e.resetErrorBoundary ? _ = u[5] : (_ = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, {
    "data-testid": "reset-error-boundary-button",
    onClick: e.resetErrorBoundary,
    variant: "outline",
    children: "Try again"
  }), u[4] = e.resetErrorBoundary, u[5] = _);
  let v;
  return u[6] !== m || u[7] !== _ ? (v = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
    className: "flex-1 flex items-center justify-center flex-col space-y-4 max-w-2xl mx-auto px-6",
    children: [
      f,
      m,
      g,
      _
    ]
  }), u[6] = m, u[7] = _, u[8] = v) : v = u[8], v;
};
export {
  require_prop_types as n,
  ErrorBoundary$1 as t
};
