import { r as reactExports } from "./index-BKyMaBlO.js";
import { j as jsxRuntimeExports, f as useTranslation, u as useWidgetsCore, g as interweave } from "./root-CqOwVDsl.js";
import { B as tx, aQ as keyframes } from "./index-cxtq9t-h.js";
const ErrorBoundaryContext = reactExports.createContext(null);
const initialState = {
  didCatch: false,
  error: null
};
class ErrorBoundary extends reactExports.Component {
  constructor(props) {
    super(props);
    this.resetErrorBoundary = this.resetErrorBoundary.bind(this);
    this.state = initialState;
  }
  static getDerivedStateFromError(error) {
    return {
      didCatch: true,
      error
    };
  }
  resetErrorBoundary() {
    const {
      error
    } = this.state;
    if (error !== null) {
      var _this$props$onReset, _this$props;
      for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
        args[_key] = arguments[_key];
      }
      (_this$props$onReset = (_this$props = this.props).onReset) === null || _this$props$onReset === void 0 ? void 0 : _this$props$onReset.call(_this$props, {
        args,
        reason: "imperative-api"
      });
      this.setState(initialState);
    }
  }
  componentDidCatch(error, info) {
    var _this$props$onError, _this$props2;
    (_this$props$onError = (_this$props2 = this.props).onError) === null || _this$props$onError === void 0 ? void 0 : _this$props$onError.call(_this$props2, error, info);
  }
  componentDidUpdate(prevProps, prevState) {
    const {
      didCatch
    } = this.state;
    const {
      resetKeys
    } = this.props;
    if (didCatch && prevState.error !== null && hasArrayChanged(prevProps.resetKeys, resetKeys)) {
      var _this$props$onReset2, _this$props3;
      (_this$props$onReset2 = (_this$props3 = this.props).onReset) === null || _this$props$onReset2 === void 0 ? void 0 : _this$props$onReset2.call(_this$props3, {
        next: resetKeys,
        prev: prevProps.resetKeys,
        reason: "keys"
      });
      this.setState(initialState);
    }
  }
  render() {
    const {
      children,
      fallbackRender,
      FallbackComponent,
      fallback
    } = this.props;
    const {
      didCatch,
      error
    } = this.state;
    let childToRender = children;
    if (didCatch) {
      const props = {
        error,
        resetErrorBoundary: this.resetErrorBoundary
      };
      if (typeof fallbackRender === "function") {
        childToRender = fallbackRender(props);
      } else if (FallbackComponent) {
        childToRender = reactExports.createElement(FallbackComponent, props);
      } else if (fallback === null || reactExports.isValidElement(fallback)) {
        childToRender = fallback;
      } else {
        throw error;
      }
    }
    return reactExports.createElement(ErrorBoundaryContext.Provider, {
      value: {
        didCatch,
        error,
        resetErrorBoundary: this.resetErrorBoundary
      }
    }, childToRender);
  }
}
function hasArrayChanged() {
  let a = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
  let b = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
  return a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]));
}
function Hyperlink(props) {
  return /* @__PURE__ */ jsxRuntimeExports.jsx("a", { target: "_blank", rel: "nofollow", ...props });
}
function Error$1(props) {
  const { t } = useTranslation();
  const core = useWidgetsCore();
  reactExports.useEffect(() => {
    if (props.error) {
      core.captureException(props.error);
    }
  }, [props.error]);
  return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex h-full w-full flex-col items-center justify-center p-8", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-1", children: [
    /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-base font-semibold leading-tight text-zinc-900", children: t("error.message") }),
    /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs font-light leading-tight text-zinc-700", children: interweave(t("error.next-steps"), {
      c0: /* @__PURE__ */ jsxRuntimeExports.jsx(
        Hyperlink,
        {
          href: props.supportUrl ?? void 0,
          className: tx({ "text-brand-900 underline": props.supportUrl })
        }
      )
    }) }),
    props.reset ? /* @__PURE__ */ jsxRuntimeExports.jsx(
      "button",
      {
        type: "button",
        className: "!mt-4 rounded-full border border-brand-700 bg-brand-900 px-4 py-2 text-sm text-white hover:border-brand-900 hover:bg-brand-700 focus:border-brand-900 focus:bg-brand-700 active:border-zinc-100 active:bg-brand-900",
        onClick: props.reset,
        children: t("error.reset")
      }
    ) : null
  ] }) });
}
const bounce = keyframes`
  0%, 50%, 100% {
    transform: translateY(0);
  }
  25% {
    transform: translateY(-0.25rem);
  }
`;
function Loader(props) {
  const color = props.muted ? "bg-zinc-600" : "bg-brand-900";
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(
    "div",
    {
      className: tx("flex h-full w-full items-center justify-center gap-2 self-center justify-self-center", {
        "bg-white p-8": !props.inline
      }),
      children: [
        props.label && /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-xs font-light text-zinc-500", children: props.label }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex translate-y-0.5 gap-1", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(
            "div",
            {
              className: `h-1 w-1 motion-safe:animate-[${bounce}_1.5s_ease-in-out_infinite_0.2s] rounded-full ${color}`
            }
          ),
          /* @__PURE__ */ jsxRuntimeExports.jsx(
            "div",
            {
              className: `h-1 w-1 motion-safe:animate-[${bounce}_1.5s_ease-in-out_infinite_0.4s] rounded-full ${color}`
            }
          ),
          /* @__PURE__ */ jsxRuntimeExports.jsx(
            "div",
            {
              className: `h-1 w-1 motion-safe:animate-[${bounce}_1.5s_ease-in-out_infinite_0.6s] rounded-full ${color}`
            }
          )
        ] })
      ]
    }
  );
}
export {
  ErrorBoundary as E,
  Hyperlink as H,
  Loader as L,
  Error$1 as a
};
//# sourceMappingURL=loader-5BGkTPnX.js.map
