import { A as AccountMainSection, b as AccountMainSectionHeader, a as AccountMainSectionBody } from "./AccountMainSection.js";
import { a as Ctx, g as AccPath, h as AlertType, i as CommonError, T as Trans, J as InputGroup, t, f as Button, a8 as Spinner, a9 as SpinnerStyle, j as Alert } from "./index.js";
import React__default from "react";
import { A as AccountDeletionSuccessPageLock } from "./AccountDeletionSuccessPageLock.js";
import { Link } from "react-router-dom";
import "./reactSlick.js";
import "./dateFns.js";
import "./validator.js";
import "./reactPlayer.js";
const DownloadIcon = ({ className }) => /* @__PURE__ */ React__default.createElement("i", {
  className
}, /* @__PURE__ */ React__default.createElement("svg", {
  xmlns: "http://www.w3.org/2000/svg",
  fill: "none",
  viewBox: "0 0 48 48"
}, /* @__PURE__ */ React__default.createElement("mask", {
  id: "a",
  width: "48",
  height: "48",
  x: "0",
  y: "0",
  maskUnits: "userSpaceOnUse"
}, /* @__PURE__ */ React__default.createElement("path", {
  fill: "#fff",
  d: "M0 0H48V48H0z"
})), /* @__PURE__ */ React__default.createElement("g", {
  fill: "#fff",
  fillRule: "evenodd",
  clipRule: "evenodd",
  mask: "url(#a)"
}, /* @__PURE__ */ React__default.createElement("path", {
  d: "M12.147 14.823a9.5 9.5 0 015.489.54 1.5 1.5 0 11-1.149 2.772 6.5 6.5 0 00-6.098 11.41 1.5 1.5 0 11-1.667 2.495 9.5 9.5 0 013.425-17.217zM36.658 16.804A8.495 8.495 0 0035 16.641a1.5 1.5 0 000 3 5.501 5.501 0 013.056 10.073 1.5 1.5 0 001.666 2.494 8.5 8.5 0 00-3.064-15.404z"
}), /* @__PURE__ */ React__default.createElement("path", {
  d: "M30.39 8.58a11.5 11.5 0 014.889 11.806 1.5 1.5 0 11-2.942-.585 8.5 8.5 0 00-16.446-4.209 1.5 1.5 0 11-2.861-.9A11.5 11.5 0 0130.39 8.58zM24 41.5a1.5 1.5 0 001.5-1.5V22a1.5 1.5 0 00-3 0v18a1.5 1.5 0 001.5 1.5z"
}), /* @__PURE__ */ React__default.createElement("path", {
  d: "M22.94 41.06a1.5 1.5 0 002.12 0l8-8a1.5 1.5 0 00-2.12-2.12L24 37.878l-6.94-6.94a1.5 1.5 0 00-2.12 2.122l8 8z"
}))));
const accountDeletionPage = "accountDeletionPage _accountDeletionPage_a2585";
var styles = {
  accountDeletionPage
};
class AccountDeletionPage extends React__default.Component {
  constructor(props) {
    super(props);
    this.notifyAccountDeletionSuccess = () => {
      const { appHistory } = Ctx.getAppState().state;
      AccountDeletionSuccessPageLock.lock();
      appHistory.push(AccPath.AccountDeletionSuccess.link);
    };
    this.notifyAccountDeletionError = (error) => {
      this.setState({
        alert: {
          type: AlertType.danger,
          element: /* @__PURE__ */ React__default.createElement(CommonError, {
            error
          })
        }
      });
    };
    this.onPasswordChange = (event) => {
      this.setState({
        password: event.target.value
      });
    };
    this.requestAccountDeletion = async (event) => {
      event.preventDefault();
      const { password } = this.state;
      const { user } = this.appState.getUserManager().state;
      if (!user)
        return;
      this.setState({ password: "" });
      this.logic.deleteAccount(password, user.userId).then(() => {
        this.notifyAccountDeletionSuccess();
      }).catch((error) => {
        this.notifyAccountDeletionError(error);
      });
    };
    this.renderFormPassword = () => {
      const { password } = this.state;
      const { isRequestingDeletion } = this.logic.state;
      return /* @__PURE__ */ React__default.createElement("form", {
        className: "formPassword",
        onSubmit: this.requestAccountDeletion
      }, /* @__PURE__ */ React__default.createElement("label", {
        className: "passwordLabel"
      }, /* @__PURE__ */ React__default.createElement(Trans, {
        i18nKey: "AccountDeletionPage.form.passwordLabel"
      }, "If you are ready to delete your account, input your password to proceed the deletion")), /* @__PURE__ */ React__default.createElement(InputGroup, {
        type: "password",
        value: password,
        name: "password",
        className: "passwordInput",
        placeholder: t("AccountDeletionPage.form.passwordPlaceholder"),
        onChange: this.onPasswordChange
      }), /* @__PURE__ */ React__default.createElement(Button, {
        disabled: !password || isRequestingDeletion,
        className: "btn big btn-primary btnDelete",
        type: "submit"
      }, isRequestingDeletion ? /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(Spinner, {
        className: `${SpinnerStyle.inline} spinner`
      }), /* @__PURE__ */ React__default.createElement(Trans, {
        i18nKey: "AccountDeletionPage.form.processing"
      }, "Processing")) : /* @__PURE__ */ React__default.createElement(Trans, {
        i18nKey: "AccountDeletionPage.form.deleteAccountButton"
      }, "Delete my Account")));
    };
    this.appState = Ctx.getAppState();
    this.logic = this.appState.getGdprManager();
    this.logic.subscribe(() => this.setState({}));
    this.state = {
      password: "",
      alert: null
    };
  }
  render() {
    const { alert } = this.state;
    const { isRequestingDeletion } = this.logic.state;
    return /* @__PURE__ */ React__default.createElement(AccountMainSection, {
      className: styles.accountDeletionPage
    }, /* @__PURE__ */ React__default.createElement(AccountMainSectionHeader, null, /* @__PURE__ */ React__default.createElement(Trans, {
      i18nKey: "AccountDeletionPage.title"
    }, "Account Deletion")), /* @__PURE__ */ React__default.createElement(AccountMainSectionBody, {
      className: "mainBody min-w-xl"
    }, !!alert && !isRequestingDeletion && /* @__PURE__ */ React__default.createElement(Alert, {
      type: alert.type,
      className: "alert",
      onDismiss: () => this.setState({ alert: null })
    }, alert.element), /* @__PURE__ */ React__default.createElement("div", {
      className: "warningDeleteAccountMessage"
    }, /* @__PURE__ */ React__default.createElement(Trans, {
      i18nKey: "AccountDeletionPage.warningDeleteAccount"
    }, /* @__PURE__ */ React__default.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__ */ React__default.createElement("p", {
      className: "bottom"
    }, "Before you delete your account, you might like to:"))), /* @__PURE__ */ React__default.createElement("div", {
      className: "downloadPersonalDataContainer"
    }, /* @__PURE__ */ React__default.createElement(DownloadIcon, {
      className: "icon"
    }), /* @__PURE__ */ React__default.createElement("div", {
      className: "messageContainer"
    }, /* @__PURE__ */ React__default.createElement(Trans, {
      i18nKey: "AccountDeletionPage.downloadPersonalData"
    }, /* @__PURE__ */ React__default.createElement("p", {
      className: "downloadAccount"
    }, "Download your account information & data"), /* @__PURE__ */ React__default.createElement("p", {
      className: "savePersonalData"
    }, "You can save your personal data before your account is permanently deleted"), /* @__PURE__ */ React__default.createElement(Link, {
      to: AccPath.PersonalData.makePath(),
      className: "btnDownload"
    }, "Download Personal Data")))), this.renderFormPassword()));
  }
}
export { AccountDeletionPage as default };
