import { AccountMainSection as l, AccountMainSectionHeader as m, AccountMainSectionBody as u } from "./accelbyte-widgets122.mjs";
import { Alert as p } from "./accelbyte-widgets123.mjs";
import { Button as d } from "./accelbyte-widgets107.mjs";
import { CommonError as h } from "./accelbyte-widgets124.mjs";
import { InputGroup as y } from "./accelbyte-widgets229.mjs";
import { DownloadIcon as f } from "./accelbyte-widgets230.mjs";
import { Spinner as g, SpinnerStyle as D } from "./accelbyte-widgets154.mjs";
import { t as w } from "./accelbyte-widgets58.mjs";
import { Ctx as s } from "./accelbyte-widgets33.mjs";
import { AlertType as A } from "./accelbyte-widgets128.mjs";
import { AccPath as c } from "./accelbyte-widgets34.mjs";
import { AccountDeletionSuccessPageLock as E } from "./accelbyte-widgets152.mjs";
import e from "react";
import { Trans as o } from "react-i18next";
import { Link as P } from "react-router-dom";
import { mockPassword as S } from "./accelbyte-widgets209.mjs";
import b from "./accelbyte-widgets231.mjs";
class U extends e.Component {
  constructor(a) {
    super(a), this.notifyAccountDeletionSuccess = () => {
      const { appHistory: t } = s.getAppState().state;
      E.lock(), t.push(c.AccountDeletionSuccess.link);
    }, this.notifyAccountDeletionError = (t) => {
      this.setState({
        alert: {
          type: A.danger,
          element: /* @__PURE__ */ e.createElement(h, { error: t })
        }
      });
    }, this.onPasswordChange = (t) => {
      this.setState({
        password: t.target.value
      });
    }, this.requestAccountDeletion = async (t) => {
      t.preventDefault();
      const { password: r } = this.state, { user: n } = this.appState.getUserManager().state;
      n && (this.setState({ password: "" }), this.logic.deleteAccount(r, n.userId).then(() => {
        this.notifyAccountDeletionSuccess();
      }).catch((i) => {
        this.notifyAccountDeletionError(i);
      }));
    }, this.renderFormPassword = () => {
      const { password: t } = this.state, { isRequestingDeletion: r } = this.logic.state, n = this.props.isPreviewMode;
      return /* @__PURE__ */ e.createElement("form", { className: "formPassword", onSubmit: this.requestAccountDeletion }, /* @__PURE__ */ e.createElement("label", { className: "passwordLabel" }, /* @__PURE__ */ e.createElement(o, { i18nKey: "AccountDeletionPage.form.passwordLabel" }, "If you are ready to delete your account, input your password to proceed the deletion")), /* @__PURE__ */ e.createElement(
        y,
        {
          type: "password",
          value: n ? S : t,
          name: "password",
          className: "passwordInput",
          placeholder: w("AccountDeletionPage.form.passwordPlaceholder"),
          onChange: this.onPasswordChange,
          readOnly: n
        }
      ), /* @__PURE__ */ e.createElement(d, { disabled: !t || r, className: "btn big btn-primary btnDelete", type: "submit" }, r ? /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement(g, { className: `${D.inline} spinner` }), /* @__PURE__ */ e.createElement(o, { i18nKey: "AccountDeletionPage.form.processing" }, "Processing")) : /* @__PURE__ */ e.createElement(o, { i18nKey: "AccountDeletionPage.form.deleteAccountButton" }, "Delete my Account")));
    }, this.appState = s.getAppState(), this.logic = this.appState.getGdprManager(), this.logic.subscribe(() => this.setState({})), this.state = {
      password: "",
      alert: null
    };
  }
  render() {
    const { alert: a } = this.state, { isRequestingDeletion: t } = this.logic.state;
    return /* @__PURE__ */ e.createElement(l, { className: b.accountDeletionPage }, /* @__PURE__ */ e.createElement(m, null, /* @__PURE__ */ e.createElement(o, { i18nKey: "AccountDeletionPage.title" }, "Account Deletion")), /* @__PURE__ */ e.createElement(u, { className: "mainBody min-w-xl" }, !!a && !t && /* @__PURE__ */ e.createElement(p, { type: a.type, className: "alert", onDismiss: () => this.setState({ alert: null }) }, a.element), /* @__PURE__ */ e.createElement("div", { className: "warningDeleteAccountMessage" }, /* @__PURE__ */ e.createElement(o, { i18nKey: "AccountDeletionPage.warningDeleteAccount" }, /* @__PURE__ */ e.createElement("p", null, "This action cannot be undone and it will permanently erase your account. Once the deletion process has begun, you won't be able to reactivate your account or retrieve any of the content of information that you've added."), /* @__PURE__ */ e.createElement("p", { className: "bottom" }, "Before you delete your account, you might like to:"))), /* @__PURE__ */ e.createElement("div", { className: "downloadPersonalDataContainer" }, /* @__PURE__ */ e.createElement(f, { className: "icon" }), /* @__PURE__ */ e.createElement("div", { className: "messageContainer" }, /* @__PURE__ */ e.createElement(o, { i18nKey: "AccountDeletionPage.downloadPersonalData" }, /* @__PURE__ */ e.createElement("p", { className: "downloadAccount" }, "Download your account information & data"), /* @__PURE__ */ e.createElement("p", { className: "savePersonalData" }, "You can save your personal data before your account is permanently deleted"), /* @__PURE__ */ e.createElement(P, { to: c.PersonalData.makePath(), className: "btnDownload" }, "Download Personal Data")))), this.renderFormPassword()));
  }
}
export {
  U as default
};
