import { HeaderLogoContainer as g } from "./accelbyte-widgets48.mjs";
import { Alert as h } from "./accelbyte-widgets123.mjs";
import { Button as n, ButtonType as u, ButtonStyle as d } from "./accelbyte-widgets107.mjs";
import { CommonError as f } from "./accelbyte-widgets124.mjs";
import { Loading as E } from "./accelbyte-widgets136.mjs";
import { gaSendErrorEvent as y } from "./accelbyte-widgets145.mjs";
import { UIEvent as o } from "./accelbyte-widgets138.mjs";
import { Ctx as P } from "./accelbyte-widgets33.mjs";
import { AlertType as S } from "./accelbyte-widgets128.mjs";
import { ErrorPath as c } from "./accelbyte-widgets69.mjs";
import { GlobalPath as A } from "./accelbyte-widgets104.mjs";
import { ErrorHelper as p } from "./accelbyte-widgets120.mjs";
import b from "./accelbyte-widgets140.mjs";
import { LegalHelper as m } from "@accelbyte/sdk-legal";
import e from "react";
import { Trans as s } from "react-i18next";
import "./accelbyte-widgets146.mjs";
import { LegalUtils as L } from "./accelbyte-widgets147.mjs";
class G extends e.Component {
  constructor(i) {
    super(i), this.getEligibilities = () => {
      const { eligibilities: t } = this.legalManager.state;
      return t || [];
    }, this.handleFetchError = async (t) => {
      var a;
      if (p.isAxiosError(t) && ((a = t == null ? void 0 : t.response) == null ? void 0 : a.status) === 401) {
        this.appState.state.appHistory.push(A.Home.link);
        return;
      }
      await this.appState.logout(), y({ eventCategory: c.Error500.makePath(), eventLabel: p.errorToString(t) }), this.appState.state.appHistory.push(c.Error500.makePath());
    }, this.handleAcceptSuccess = () => {
      this.appState.userAppManager.refreshToken().then((t) => {
        t && this.appState.refreshSession(t.access_token, t.refresh_token);
      }), this.appState.refreshUser();
    }, this.setErrorAlert = (t) => {
      this.setState({
        alert: {
          type: S.danger,
          element: /* @__PURE__ */ e.createElement(f, { error: t })
        }
      });
    }, this.bulkAcceptPolicies = async () => {
      const t = this.appState.getUser(), a = this.getEligibilities();
      if (a && t) {
        const r = m.getAcceptedPolicies(a);
        this.setState({ isAcceptingLegal: !0 });
        try {
          await this.legalManager.bulkAcceptPolicies(r);
          const l = await this.appState.userAppManager.refreshToken();
          l && (this.appState.refreshSession(l.access_token, l.refresh_token), await this.appState.refreshUser());
        } catch (l) {
          this.setErrorAlert(l);
        } finally {
          this.setState({ isAcceptingLegal: !1 });
        }
      }
    }, this.onSuccessAcceptLegal = () => {
      this.appState.userAppManager.refreshToken().then((t) => {
        t && (this.appState.refreshSession(t.access_token, t.refresh_token), this.appState.refreshUser());
      });
    }, this.appState = P.getAppState(), this.legalManager = this.appState.legalAppManager, this.state = { alert: null, isAcceptingLegal: !1 };
  }
  componentDidMount() {
    o.updateBackground(`url(${b})`);
  }
  componentWillUnmount() {
    o.updateBackground(null);
  }
  renderPolicies() {
    const i = this.getEligibilities();
    return i ? /* @__PURE__ */ e.createElement("ul", { className: "policies" }, i.map((t) => t.policyVersions && t.policyVersions.map((a) => Array.isArray(a.localizedPolicyVersions) ? a.localizedPolicyVersions.map((r) => /* @__PURE__ */ e.createElement("li", { key: r.id, className: "policyItem" }, t.policyName, /* @__PURE__ */ e.createElement(
      "a",
      {
        href: m.createLegalURL(L.getLegalUrl(), r.id),
        className: "readMore",
        target: "_blank",
        rel: "noreferrer"
      },
      /* @__PURE__ */ e.createElement(s, { i18nKey: "PromptLegalPage.readMore" }, "Read More")
    ))) : null))) : null;
  }
  render() {
    const { isFetchingPolicy: i, eligibilities: t } = this.legalManager.state, { alert: a, isAcceptingLegal: r } = this.state, l = !i && !!t && t.length > 0;
    return /* @__PURE__ */ e.createElement("div", { className: "promptLegalPage" }, /* @__PURE__ */ e.createElement("div", { className: "promptLegalPageContainer" }, /* @__PURE__ */ e.createElement(g, null), /* @__PURE__ */ e.createElement("div", { className: "legalContent" }, i && /* @__PURE__ */ e.createElement(E, null), (l || r) && /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement("div", { className: "legalHeader" }, /* @__PURE__ */ e.createElement("h1", null, /* @__PURE__ */ e.createElement(s, { i18nKey: "PromptLegalPage.title" }, "New Agreement and Policy Terms"))), /* @__PURE__ */ e.createElement("div", { className: "legalBody" }, !r && !!a && /* @__PURE__ */ e.createElement(h, { className: "legalBodyAlert", type: a.type, onDismiss: () => this.setState({ alert: null }) }, a.element), /* @__PURE__ */ e.createElement(s, { i18nKey: "PromptLegalPage.description" }, /* @__PURE__ */ e.createElement("p", null, "We have updated our user agreement and policy to better explain what data we collect from you, why we collect it, and how it's used."), /* @__PURE__ */ e.createElement("p", null, "The following terms have been updated:")), this.renderPolicies(), /* @__PURE__ */ e.createElement("div", { className: "notes" }, /* @__PURE__ */ e.createElement(s, { i18nKey: "PromptLegalPage.notes" }, /* @__PURE__ */ e.createElement("p", null, "Please take a moment to read and understand the updated agreement. By clicking the Accept button, you agree to these changes.")))), /* @__PURE__ */ e.createElement("div", { className: "legalFooter" }, /* @__PURE__ */ e.createElement(
      n,
      {
        loadingIndicator: "SPINNER",
        className: "btn-primary btn-accept",
        isLoading: r,
        disabled: r,
        onClick: this.bulkAcceptPolicies
      },
      /* @__PURE__ */ e.createElement(s, { i18nKey: "PromptLegalPage.accept" }, "Accept")
    ), /* @__PURE__ */ e.createElement(
      n,
      {
        className: "btn-decline",
        buttonType: u.TEXT,
        buttonStyle: d.NONE,
        onClick: () => this.appState.logout(),
        disabled: r
      },
      /* @__PURE__ */ e.createElement(s, { i18nKey: "PromptLegalPage.decline" }, "Decline")
    ))))));
  }
}
export {
  G as default
};
