import { a0 as y, a1 as z } from "./dateFns-2367ee5b.mjs";
import { D as m } from "./AccountUtils-1a8a81d7.mjs";
import { aQ as $, aR as w, D as v, t as E, p as R, T as r, q, f as p, a3 as A, a1 as x, aE as T, aD as F, aF as K, $ as L, a as u, h, y as B, i as M, g as S, F as b, O as U, aS as Z, j as _, L as H } from "./index-162fd1aa.mjs";
import { P as V } from "./Pagination-a353297b.mjs";
import { w as X } from "./WithPropsGuard-9dd19ecc.mjs";
import { c as I } from "./reactSlick-cb4a2d39.mjs";
import e from "react";
import { A as j, b as Q, a as W } from "./AccountMainSection-4c35f8d7.mjs";
import { v as N } from "./validator-61879ab7.mjs";
import { g as Y, r as J } from "./MockVars-1cf2eb0a.mjs";
import "./reactPlayer-2f69f369.mjs";
import "react-router-dom";
const D = $(w.empty, w.invalidFormat), G = (i, { isRequired: t = !0 } = {}) => {
  const s = '^(?:(?=.*\\d)(?=.*[A-Z])(?=.*[a-z])|(?=.*\\d)(?=.*[^A-Za-z0-9])(?=.*[a-z])|(?=.*[^A-Za-z0-9])(?=.*[A-Z])(?=.*[a-z])|(?=.*\\d)(?=.*[A-Z])(?=.*[^A-Za-z0-9]))(?!.*(.)\\1{2,})[A-Za-z0-9!~<>,;:_=?*+#."&§%°()\\|\\[\\]\\-\\$\\^\\@\\/]{8,32}$';
  return N.isEmpty(i) ? t ? D.empty : null : N.matches(i, s) ? null : D.invalidFormat;
};
class ee extends e.Component {
  constructor(t) {
    super(t);
  }
  render() {
    const { onCancel: t, onConfirm: s } = this.props;
    return /* @__PURE__ */ e.createElement(v, { className: "cancelConfirmDialog", title: E("PersonalDataPage.cancelConfirmDialog.title"), isOpen: !0 }, /* @__PURE__ */ e.createElement(R, { className: "dialogBody" }, /* @__PURE__ */ e.createElement(r, { i18nKey: "PersonalDataPage.cancelConfirmDialog.bodyText" }, "Do you want to cancel your personal data request?")), /* @__PURE__ */ e.createElement(q, { className: "dialogFooter" }, /* @__PURE__ */ e.createElement("div", { className: "btnContainer" }, /* @__PURE__ */ e.createElement(
      p,
      {
        className: "btn big btn-ghost btnCancel",
        buttonType: A.TEXT,
        buttonStyle: x.NONE,
        onClick: () => {
          t && t();
        }
      },
      /* @__PURE__ */ e.createElement(r, { i18nKey: "PersonalDataPage.cancelDialogConfirm.close" }, "Close")
    ), /* @__PURE__ */ e.createElement(
      p,
      {
        className: "btn big btn-primary btnContinue",
        onClick: () => {
          s && s();
        }
      },
      /* @__PURE__ */ e.createElement(r, { i18nKey: "PersonalDataPage.cancelDialogConfirm.continue" }, "Continue")
    ))));
  }
}
class te extends e.Component {
  constructor(t) {
    super(t), this.onPasswordChange = (s) => {
      const a = s.target.value;
      this.validation.set("password", G(a)), this.setState({ password: a });
    }, this.state = {
      password: ""
    }, this.validation = new T(), this.validation.listen(() => this.setState({}));
  }
  renderErrorType(t) {
    return t === D.empty ? /* @__PURE__ */ e.createElement(F, null, /* @__PURE__ */ e.createElement(r, { i18nKey: "PersonalDataPage.inputPasswordForm.inputPasswordError.empty" }, "Input your password to proceed")) : null;
  }
  render() {
    const { password: t } = this.state, { onCancel: s, onConfirm: a, dateRequest: n } = this.props;
    return /* @__PURE__ */ e.createElement(v, { className: "cancelConfirmDialog", title: E("PersonalDataPage.downloadConfirmDialog.title"), isOpen: !0 }, /* @__PURE__ */ e.createElement(R, { className: "dialogBody" }, /* @__PURE__ */ e.createElement("div", { className: "bodyText" }, /* @__PURE__ */ e.createElement(r, { i18nKey: "PersonalDataPage.downloadConfirmDialog.bodyText" }, "Input your password to download")), /* @__PURE__ */ e.createElement(
      "form",
      {
        className: "form",
        onSubmit: (l) => {
          l.preventDefault();
        }
      },
      /* @__PURE__ */ e.createElement(K, null, /* @__PURE__ */ e.createElement(
        L,
        {
          className: "inputRedeem",
          type: "password",
          value: t,
          placeholder: E("PersonalDataPage.form.passwordPlaceholder"),
          onChange: this.onPasswordChange
        }
      ), this.renderErrorType(this.validation.get("password")))
    )), /* @__PURE__ */ e.createElement(q, { className: "dialogFooter" }, /* @__PURE__ */ e.createElement("div", { className: "btnContainer" }, /* @__PURE__ */ e.createElement(
      p,
      {
        className: "btn btn-ghost big btnCancel",
        buttonType: A.TEXT,
        buttonStyle: x.NONE,
        onClick: () => {
          s && s();
        }
      },
      /* @__PURE__ */ e.createElement(r, { i18nKey: "PersonalDataPage.downloadConfirmDialog.cancel" }, "Cancel")
    ), /* @__PURE__ */ e.createElement(
      p,
      {
        className: "btn btn-primary big btnDownload",
        onClick: () => {
          a && a(n, t);
        }
      },
      /* @__PURE__ */ e.createElement(r, { i18nKey: "PersonalDataPage.cancelDialogConfirm.download" }, "Download")
    ))));
  }
}
const d = ({ className: i }) => /* @__PURE__ */ e.createElement("i", { className: I("circleStatusIcon", i) }, /* @__PURE__ */ e.createElement("svg", { className: "fill-current", width: "8", height: "8", viewBox: "0 0 8 8", fill: "none", xmlns: "http://www.w3.org/2000/svg" }, /* @__PURE__ */ e.createElement("circle", { cx: "4", cy: "4", r: "4" })));
function ae(i) {
  switch (i) {
    case m.enum.Completed:
      return /* @__PURE__ */ e.createElement(d, { className: "completed" });
    case m.enum.Pending:
      return /* @__PURE__ */ e.createElement(d, { className: "pending" });
    case m.enum.Failed:
      return /* @__PURE__ */ e.createElement(d, { className: "failed" });
    case m.enum.InProgress:
      return /* @__PURE__ */ e.createElement(d, { className: "inProgress" });
    case m.enum.Expired:
      return /* @__PURE__ */ e.createElement(d, { className: "failed" });
    default:
      return /* @__PURE__ */ e.createElement(d, { className: "pending" });
  }
}
class ne extends e.Component {
  constructor(t) {
    super(t), this.fetchGdprRequestDataList = () => {
      var n;
      const a = (n = u.getAppState().getUser()) == null ? void 0 : n.userId;
      a && this.logic.fetchGdprRequestDataList(a, this.getOffset(this.props.page), this.getLimit()).catch((l) => {
        this.setErrorAlert(l);
      });
    }, this.notifyRequestSuccess = () => {
      this.setState({
        alert: {
          type: h.success,
          element: /* @__PURE__ */ e.createElement(r, { i18nKey: "PersonalDataPage.successRequest" }, "Request sent! Please check the status of your request below.")
        }
      });
    }, this.notifyRequestCancellation = () => {
      this.setState({
        alert: {
          type: h.success,
          element: /* @__PURE__ */ e.createElement(r, { i18nKey: "PersonalDataPage.successCancel" }, "Your personal data request has been canceled")
        }
      });
    }, this.onRequestGdprDataError = (a) => {
      B.extractServiceErrorCode(a) ? this.setErrorAlert(a) : this.setState({
        alert: {
          type: h.danger,
          element: /* @__PURE__ */ e.createElement(r, { i18nKey: "PersonalDataPage.errorRequest" }, "Unable to send the request. Please try again.")
        }
      });
    }, this.setErrorAlert = (a) => {
      this.setState({
        alert: {
          type: h.danger,
          element: /* @__PURE__ */ e.createElement(M, { error: a })
        }
      });
    }, this.clearNotification = () => this.setState({ alert: null }), this.onPasswordChange = (a) => {
      const n = a.target.value;
      this.validation.set("password", G(n)), this.setState({ password: n });
    }, this.renderPagination = () => {
      const { gdprDataRequestList: a } = this.logic.state;
      if (!a)
        return;
      const { Paging: n } = a, l = !!n.Next, o = !!n.Previous, c = this.props.page;
      return /* @__PURE__ */ e.createElement("div", { className: "pagination" }, /* @__PURE__ */ e.createElement(
        V,
        {
          next: l && `${S.PersonalData.link}?page=${c + 1}`,
          prev: o && `${S.PersonalData.link}?page=${c - 1}`
        }
      ));
    }, this.onSubmit = (a) => {
      var l;
      a.preventDefault(), this.setState({ password: "" });
      const n = (l = u.getAppState().getUser()) == null ? void 0 : l.userId;
      n && this.logic.requestGdprData(this.state.password, n).then(() => {
        this.notifyRequestSuccess(), this.fetchGdprRequestDataList();
      }).catch((o) => {
        this.setErrorAlert(o);
      });
    }, this.cancelRequest = (a) => {
      var l;
      const n = (l = u.getAppState().getUser()) == null ? void 0 : l.userId;
      a && n && this.logic.cancelRequestGdprData(a, n).then(() => {
        this.notifyRequestCancellation();
      }).catch((o) => {
        this.setErrorAlert(o);
      }).finally(() => {
        this.fetchGdprRequestDataList(), this.setState({ openCancelDialog: !1 });
      });
    }, this.downloadGdpr = (a, n) => {
      var o;
      const l = (o = u.getAppState().getUser()) == null ? void 0 : o.userId;
      !a || !n || !l || this.logic.downloadGdprData(a, n, l).then((c) => {
        c && window.open(c.URL, "_blank");
      }).catch((c) => {
        this.setErrorAlert(c);
      }).finally(() => {
        this.setState({ openDownloadDialog: !1 });
      });
    };
    const s = u.getAppState().gdprAppManager;
    s.subscribe(() => this.setState({})), this.logic = s, this.state = {
      password: "",
      selectedRequestDate: null,
      openCancelDialog: !1,
      openDownloadDialog: !1,
      alert: null
    }, this.validation = new T(), this.validation.listen(() => this.setState({}));
  }
  componentDidMount() {
    this.props.isPreviewMode || this.fetchGdprRequestDataList();
  }
  formatSelectedDate(t) {
    return `${new Date(t).toISOString().substring(0, 19)}Z`;
  }
  getLimit() {
    return 10;
  }
  getOffset(t) {
    return t ? (t - 1) * this.getLimit() : 0;
  }
  renderDownloadAction(t, s, a) {
    const n = this.props.isPreviewMode;
    return /* @__PURE__ */ e.createElement(e.Fragment, null, t && !s && /* @__PURE__ */ e.createElement(
      "div",
      {
        className: "btnDownload",
        onClick: n ? void 0 : () => this.setState({
          openDownloadDialog: !0,
          selectedRequestDate: this.formatSelectedDate(a)
        })
      },
      /* @__PURE__ */ e.createElement(r, { i18nKey: "PersonalDataPage.action.download" }, "Download")
    ));
  }
  renderCancelAction(t, s, a, n) {
    const l = this.props.isPreviewMode;
    return /* @__PURE__ */ e.createElement(e.Fragment, null, !t && !s && !a ? /* @__PURE__ */ e.createElement(
      "div",
      {
        className: "btnCancel",
        onClick: l ? void 0 : () => this.setState({
          openCancelDialog: !0,
          selectedRequestDate: this.formatSelectedDate(n)
        })
      },
      /* @__PURE__ */ e.createElement(r, { i18nKey: "PersonalDataPage.action.cancel" }, "Cancel")
    ) : /* @__PURE__ */ e.createElement("span", { className: "btnCancel disabled" }, /* @__PURE__ */ e.createElement(r, { i18nKey: "PersonalDataPage.action.cancel" }, "Cancel")));
  }
  renderExpirationDate(t, s, a) {
    return a ? t ? /* @__PURE__ */ e.createElement(r, { i18nKey: "PersonalDataPage.fileExpired" }, "file expired") : b.formatDate(y.legacyParse(s), "LLLL") : "-";
  }
  renderListDataRequest(t) {
    const s = t.Status === m.enum.Completed, a = t.Status === m.enum.Failed, n = t.Status === m.enum.Canceled, l = z(y.legacyParse(t.DataExpirationDate)), o = m.safeParse(t.Status);
    return /* @__PURE__ */ e.createElement("tr", { key: t.RequestDate, className: "tableRow" }, /* @__PURE__ */ e.createElement("td", { className: "date" }, b.formatDate(y.legacyParse(t.RequestDate), "LL")), /* @__PURE__ */ e.createElement("td", { className: "statusContainer" }, /* @__PURE__ */ e.createElement("span", { className: "statusIcon" }, o.success && ae(o.data)), t.Status), /* @__PURE__ */ e.createElement("td", null, this.renderExpirationDate(l, t.DataExpirationDate, s)), /* @__PURE__ */ e.createElement("td", null, this.renderDownloadAction(s, l, t.RequestDate)), /* @__PURE__ */ e.createElement("td", null, this.renderCancelAction(s, a, n, t.RequestDate)));
  }
  renderErrorType(t) {
    return t === D.empty ? /* @__PURE__ */ e.createElement(F, null, /* @__PURE__ */ e.createElement(r, { i18nKey: "PersonalDataPage.inputPasswordForm.inputPasswordError.empty" }, "Input your password to proceed")) : null;
  }
  render() {
    const { gdprDataRequestList: t, isRequestingGdpr: s, isFetchingGdpr: a } = this.logic.state, { password: n, openCancelDialog: l, openDownloadDialog: o, selectedRequestDate: c, alert: P } = this.state, f = this.props.isPreviewMode, g = f ? J : t, C = g ? g.Data.length : 0, k = !this.validation.isAllValid() || !n || s;
    return /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement(j, null, /* @__PURE__ */ e.createElement(Q, null, /* @__PURE__ */ e.createElement(r, { i18nKey: "PersonalDataPage.title" }, "Personal Data Request")), /* @__PURE__ */ e.createElement(W, null, /* @__PURE__ */ e.createElement("div", { className: "personalDataPage" }, /* @__PURE__ */ e.createElement("section", { className: "formSection" }, /* @__PURE__ */ e.createElement("div", { className: I("guideHeading", U.TITLE_FONT) }, /* @__PURE__ */ e.createElement(r, { i18nKey: "PersonalDataPage.guideHeading" }, "Download Personal Data")), /* @__PURE__ */ e.createElement("div", { className: "guideText" }, /* @__PURE__ */ e.createElement(r, { i18nKey: "PersonalDataPage.guide" }, "Collecting your data may take up to 28 days. Once your data has been collected, you will have a limited amount of time to download the data.")), /* @__PURE__ */ e.createElement("h3", { className: "formTextTitle" }, /* @__PURE__ */ e.createElement(r, { i18nKey: "PersonalDataPage.inputPasswordTitle" }, "Input your password to proceed")), /* @__PURE__ */ e.createElement(Z, { onSubmit: this.onSubmit, className: "form", orientation: "horizontal" }, /* @__PURE__ */ e.createElement(K, null, /* @__PURE__ */ e.createElement(
      L,
      {
        className: "inputRedeem",
        type: "password",
        value: f ? Y : n,
        placeholder: E("PersonalDataPage.form.passwordPlaceholder"),
        onChange: this.onPasswordChange,
        readOnly: f
      }
    ), this.renderErrorType(this.validation.get("password"))), /* @__PURE__ */ e.createElement(p, { disabled: k, className: "btn btn-primary buttonSendRequest", type: "submit" }, s ? /* @__PURE__ */ e.createElement(r, { i18nKey: "PersonalDataPage.processing" }, "Processing...") : /* @__PURE__ */ e.createElement(r, { i18nKey: "PersonalDataPage.buttonAction" }, "Send Request"))), !!P && /* @__PURE__ */ e.createElement(_, { type: P.type, className: "alertContainer", onDismiss: this.clearNotification }, P.element)), /* @__PURE__ */ e.createElement("section", { className: "fileSection" }, a && /* @__PURE__ */ e.createElement("div", { className: "loadingContainer" }, /* @__PURE__ */ e.createElement(H, { className: "loading" })), !a && g && /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement("h1", { className: "title" }, /* @__PURE__ */ e.createElement(r, { i18nKey: "PersonalDataPage.filesTitle" }, "Files"), " (", C, ")"), C > 0 ? /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement("table", null, /* @__PURE__ */ e.createElement("thead", null, /* @__PURE__ */ e.createElement("tr", null, /* @__PURE__ */ e.createElement("th", null, /* @__PURE__ */ e.createElement(r, { i18nKey: "PersonalDataPage.table.date" }, "Date")), /* @__PURE__ */ e.createElement("th", null, /* @__PURE__ */ e.createElement(r, { i18nKey: "PersonalDataPage.table.status" }, "Status")), /* @__PURE__ */ e.createElement("th", null, /* @__PURE__ */ e.createElement(r, { i18nKey: "PersonalDataPage.table.fileExpiration" }, "File expiration")), /* @__PURE__ */ e.createElement("th", { colSpan: 2 }, " "), /* @__PURE__ */ e.createElement("th", null))), /* @__PURE__ */ e.createElement("tbody", null, g.Data.map((O) => this.renderListDataRequest(O)))), this.renderPagination()) : /* @__PURE__ */ e.createElement("p", { className: "noData" }, /* @__PURE__ */ e.createElement(r, { i18nKey: "PersonalDataPage.noData" }, "No files available"))))))), l && /* @__PURE__ */ e.createElement(
      ee,
      {
        onCancel: () => this.setState({ openCancelDialog: !1, selectedRequestDate: null }),
        onConfirm: () => this.cancelRequest(c)
      }
    ), o && /* @__PURE__ */ e.createElement(
      te,
      {
        dateRequest: c,
        onCancel: () => this.setState({ openDownloadDialog: !1 }),
        onConfirm: this.downloadGdpr
      }
    ));
  }
}
const Ee = X(ne, (i, t) => i.page !== t.page);
export {
  Ee as default
};
