import { s as __toESM, t as __commonJSMin } from "./chunk-BNovOVIE.js";
import { t as Button } from "./button-C5K9fIPF.js";
import { t as require_react } from "./react-DA-nE2FX.js";
import { t as require_compiler_runtime } from "./compiler-runtime-CEbnTgxf.js";
import { u as createLucideIcon } from "./dist-Dk6PV_d3.js";
import { t as require_jsx_runtime } from "./jsx-runtime-DebpN0FN.js";
import { n as Constants } from "./constants-T20xxyNf.js";
var Plus = createLucideIcon("plus", [["path", {
  d: "M5 12h14",
  key: "1ays0h"
}], ["path", {
  d: "M12 5v14",
  key: "s699le"
}]]), require_ReactPropTypesSecret = /* @__PURE__ */ __commonJSMin(((e, f) => {
  f.exports = "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";
})), require_factoryWithThrowingShims = /* @__PURE__ */ __commonJSMin(((e, f) => {
  var p = require_ReactPropTypesSecret();
  function m() {
  }
  function h() {
  }
  h.resetWarningCache = m, f.exports = function() {
    function e2(e3, f3, m2, h2, g2, _) {
      if (_ !== p) {
        var v = /* @__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 v.name = "Invariant Violation", v;
      }
    }
    e2.isRequired = e2;
    function f2() {
      return e2;
    }
    var g = {
      array: e2,
      bigint: e2,
      bool: e2,
      func: e2,
      number: e2,
      object: e2,
      string: e2,
      symbol: e2,
      any: e2,
      arrayOf: f2,
      element: e2,
      elementType: e2,
      instanceOf: f2,
      node: e2,
      objectOf: f2,
      oneOf: f2,
      oneOfType: f2,
      shape: f2,
      exact: f2,
      checkPropTypes: h,
      resetWarningCache: m
    };
    return g.PropTypes = g, g;
  };
})), require_prop_types = /* @__PURE__ */ __commonJSMin(((e, f) => {
  f.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 f, p, m = [...arguments];
      (f = (p = this.props).onReset) == null || f.call(p, {
        args: m,
        reason: "imperative-api"
      }), this.setState(initialState);
    }
  }
  componentDidCatch(e, f) {
    var p, m;
    (p = (m = this.props).onError) == null || p.call(m, e, f);
  }
  componentDidUpdate(e, f) {
    let { didCatch: p } = this.state, { resetKeys: m } = this.props;
    if (p && f.error !== null && hasArrayChanged(e.resetKeys, m)) {
      var h, g;
      (h = (g = this.props).onReset) == null || h.call(g, {
        next: m,
        prev: e.resetKeys,
        reason: "keys"
      }), this.setState(initialState);
    }
  }
  render() {
    let { children: e, fallbackRender: f, FallbackComponent: p, fallback: m } = this.props, { didCatch: h, error: g } = this.state, _ = e;
    if (h) {
      let e2 = {
        error: g,
        resetErrorBoundary: this.resetErrorBoundary
      };
      if (typeof f == "function") _ = f(e2);
      else if (p) _ = (0, import_react.createElement)(p, e2);
      else if (m !== void 0) _ = m;
      else throw g;
    }
    return (0, import_react.createElement)(ErrorBoundaryContext.Provider, { value: {
      didCatch: h,
      error: g,
      resetErrorBoundary: this.resetErrorBoundary
    } }, _);
  }
};
function hasArrayChanged() {
  let e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [], f = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
  return e.length !== f.length || e.some((e2, p) => !Object.is(e2, f[p]));
}
var import_compiler_runtime = require_compiler_runtime(), import_jsx_runtime = /* @__PURE__ */ __toESM(require_jsx_runtime(), 1);
const ErrorBoundary$1 = (e) => {
  let f = (0, import_compiler_runtime.c)(2), p;
  return f[0] === e.children ? p = f[1] : (p = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ErrorBoundary, {
    FallbackComponent,
    children: e.children
  }), f[0] = e.children, f[1] = p), p;
};
var FallbackComponent = (e) => {
  var _a;
  let f = (0, import_compiler_runtime.c)(9), m;
  f[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (m = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h1", {
    className: "text-2xl font-bold",
    children: "Something went wrong"
  }), f[0] = m) : m = f[0];
  let h = (_a = e.error) == null ? void 0 : _a.message, g;
  f[1] === h ? g = f[2] : (g = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("pre", {
    className: "text-xs bg-muted/40 border rounded-md p-4 max-w-[80%] whitespace-normal",
    children: h
  }), f[1] = h, f[2] = g);
  let _;
  f[3] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (_ = /* @__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"
    }),
    "."
  ] }), f[3] = _) : _ = f[3];
  let y;
  f[4] === e.resetErrorBoundary ? y = f[5] : (y = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, {
    "data-testid": "reset-error-boundary-button",
    onClick: e.resetErrorBoundary,
    variant: "outline",
    children: "Try again"
  }), f[4] = e.resetErrorBoundary, f[5] = y);
  let b;
  return f[6] !== g || f[7] !== y ? (b = /* @__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: [
      m,
      g,
      _,
      y
    ]
  }), f[6] = g, f[7] = y, f[8] = b) : b = f[8], b;
};
export {
  require_prop_types as n,
  Plus as r,
  ErrorBoundary$1 as t
};
