import { L as u, R as E, T as c, i as p, ao as g, N as x, F as C, y as _, Q as A, t as f } from "./index-162fd1aa.mjs";
import t from "react";
import { Link as z } from "react-router-dom";
import "./dateFns-2367ee5b.mjs";
import "./validator-61879ab7.mjs";
import "./reactPlayer-2f69f369.mjs";
import "./reactSlick-cb4a2d39.mjs";
const P = "errorContainer _errorContainer_bb2d3", y = "sessionExpiredContainer _sessionExpiredContainer_a39d5", l = {
  errorContainer: P,
  sessionExpiredContainer: y
};
class I extends t.Component {
  constructor(e) {
    super(e), this.state = {
      error: null
    };
  }
  componentDidMount() {
    this.exchange();
  }
  clearParams() {
    const { appHistory: e } = this.props.appState.state;
    e.replace(`${e.location.pathname}`);
  }
  async exchange() {
    try {
      await this.exchangeAuthorizationCode(), this.props.appState.markAuthCodeExchangeTrialDone();
    } catch (e) {
      console.error(e), this.clearParams(), this.setState({ error: e });
    }
  }
  render() {
    const { error: e } = this.state;
    return /* @__PURE__ */ t.createElement(t.Fragment, null, !e && /* @__PURE__ */ t.createElement(u, { className: E.medium }, /* @__PURE__ */ t.createElement(c, { i18nKey: "InitialUserFetchPage.notice" })), e && /* @__PURE__ */ t.createElement("div", { className: l.errorContainer }, /* @__PURE__ */ t.createElement(p, { error: e })), e && /* @__PURE__ */ t.createElement(S, { error: e }));
  }
  async exchangeAuthorizationCode() {
    const { appHistory: e } = this.props.appState.state, { code: r, error: h, state: m } = g.getAuthorizationCodeParams(e.location.search), d = this.props.appState.getSdk();
    try {
      const s = await d.IAM.UserAuthorization().exchangeAuthorizationCode({
        code: r,
        error: h,
        state: m
      });
      if (!s)
        return;
      this.clearParams();
      const { mfaData: n, returnPath: i } = s;
      n ? this.props.appState.getUserManager().updateMFAData(n) : await this.props.appState.fetchAllUserInformation(), i ? e.replace(i) : e.replace(x.Home.link);
    } catch (o) {
      C.redirectToErrorPage(e, o);
    }
  }
}
const S = ({ error: a }) => {
  var e;
  if (!a)
    return null;
  if (_.isAxiosError(a) && ((e = a == null ? void 0 : a.response) != null && e.status)) {
    const { status: r } = a.response;
    if (r === 401)
      return /* @__PURE__ */ t.createElement("div", { className: l.sessionExpiredContainer }, /* @__PURE__ */ t.createElement(c, { i18nKey: "AuthorizationCodeExchanger.error.sessionExpired" }, "Session Expired"), /* @__PURE__ */ t.createElement(z, { to: A.Login.makePath() }, f("HomePage.login")));
  }
  return /* @__PURE__ */ t.createElement(p, { error: a });
};
export {
  I as default
};
