import AccountPageLayout from "./AccountPageLayout.js";
import { a as accountWildCardRedirect } from "./AccountUtils.js";
import { k as UIEvent, l as bgCommon, n as accountPageNav, g as AccPath, U as UrlUtils, o as menuVisibility } from "./index.js";
import React__default from "react";
import { withRouter, Switch, Route, Redirect } from "react-router-dom";
import "./reactSlick.js";
import "./dateFns.js";
import "./NavItemPlaceholder.js";
import "./validator.js";
import "./reactPlayer.js";
const AccountDeletionPage = React__default.lazy(() => import("./AccountDeletionPage.js"));
const AccountHistoryPage = React__default.lazy(() => import("./AccountHistoryPage.js"));
const ChangePasswordPage = React__default.lazy(() => import("./ChangePasswordPage.js"));
const LinkedAccountsPage = React__default.lazy(() => import("./LinkedAccountsPage.js"));
const NotificationPreferencesPage = React__default.lazy(() => import("./NotificationPreferencesPage.js"));
const OrderHistoryDetailPage = React__default.lazy(() => import("./OrderHistoryDetailPage.js"));
const OrderHistoryPage = React__default.lazy(() => import("./OrderHistoryPage.js"));
const AccountOverviewPage = React__default.lazy(() => import("./AccountOverviewPage.js"));
const PaymentMethodsPage = React__default.lazy(() => import("./PaymentMethodsPage.js"));
const PersonalDataPage = React__default.lazy(() => import("./PersonalDataPage.js"));
const PrivacyRecordsPage = React__default.lazy(() => import("./PrivacyRecordsPage.js"));
const ProfilePage = React__default.lazy(() => import("./ProfilePage.js"));
const PurchasedItemsPage = React__default.lazy(() => import("./PurchasedItemsPage.js"));
const RedeemCodePage = React__default.lazy(() => import("./RedeemCodePage.js"));
class AccountPage extends React__default.Component {
  constructor(props) {
    super(props);
  }
  async componentDidMount() {
    UIEvent.updateBackground(`url(${bgCommon})`);
  }
  componentWillUnmount() {
    UIEvent.updateBackground(null);
  }
  render() {
    const {
      accountOverview,
      profile,
      changePassword,
      purchasedItems,
      orderHistory,
      paymentMethods,
      redeemCode,
      notification,
      privacyRecords,
      personalData,
      deleteAccount,
      linkedAccounts
    } = menuVisibility;
    return /* @__PURE__ */ React__default.createElement(AccountPageLayout, {
      accountPageNav,
      backgroundImageUrl: bgCommon,
      ...this.props
    }, /* @__PURE__ */ React__default.createElement(Switch, null, accountOverview() && /* @__PURE__ */ React__default.createElement(Route, {
      exact: true,
      path: AccPath.Overview.link,
      render: () => /* @__PURE__ */ React__default.createElement(AccountOverviewPage, null)
    }), purchasedItems() && /* @__PURE__ */ React__default.createElement(Route, {
      path: AccPath.PurchasedItems.link,
      render: () => /* @__PURE__ */ React__default.createElement(PurchasedItemsPage, null)
    }), paymentMethods() && /* @__PURE__ */ React__default.createElement(Route, {
      exact: true,
      path: AccPath.PaymentMethods.link,
      render: () => /* @__PURE__ */ React__default.createElement(PaymentMethodsPage, null)
    }), changePassword() && /* @__PURE__ */ React__default.createElement(Route, {
      exact: true,
      path: AccPath.ChangePassword.link,
      render: () => /* @__PURE__ */ React__default.createElement(ChangePasswordPage, null)
    }), redeemCode() && /* @__PURE__ */ React__default.createElement(Route, {
      exact: true,
      path: AccPath.RedeemCode.link,
      render: () => /* @__PURE__ */ React__default.createElement(RedeemCodePage, null)
    }), orderHistory() && /* @__PURE__ */ React__default.createElement(Route, {
      key: "OrderHistoryPage",
      exact: true,
      path: AccPath.OrderHistory.link,
      render: (routeComponentProps) => {
        const page = Number(UrlUtils.silentSearchParamsBuilder(routeComponentProps.location.search).get("page"));
        const hasValidPage = !Number.isNaN(page) && page >= 1;
        if (!hasValidPage) {
          return /* @__PURE__ */ React__default.createElement(Redirect, {
            to: AccPath.OrderHistory.withSearchParams({ page: 1 })
          });
        }
        return hasValidPage && /* @__PURE__ */ React__default.createElement(OrderHistoryPage, {
          page
        });
      }
    }), orderHistory() && /* @__PURE__ */ React__default.createElement(Route, {
      key: "OrderHistoryDetailPage",
      path: AccPath.OrderHistoryDetail.link,
      render: (routeComponentProps) => /* @__PURE__ */ React__default.createElement(OrderHistoryDetailPage, {
        orderNo: routeComponentProps.match.params.orderNo
      })
    }), profile() && /* @__PURE__ */ React__default.createElement(Route, {
      exact: true,
      path: AccPath.Profile.link,
      render: () => /* @__PURE__ */ React__default.createElement(ProfilePage, null)
    }), profile() && /* @__PURE__ */ React__default.createElement(Route, {
      path: AccPath.ProfileHistory.link,
      render: () => /* @__PURE__ */ React__default.createElement(AccountHistoryPage, null)
    }), linkedAccounts() && /* @__PURE__ */ React__default.createElement(Route, {
      exact: true,
      path: AccPath.LinkedAccounts.link,
      render: () => /* @__PURE__ */ React__default.createElement(LinkedAccountsPage, null)
    }), personalData() && /* @__PURE__ */ React__default.createElement(Route, {
      exact: true,
      path: AccPath.PersonalData.link,
      render: (routeComponentProps) => {
        const page = Number(UrlUtils.silentSearchParamsBuilder(routeComponentProps.location.search).get("page"));
        const hasValidPage = !Number.isNaN(page) && page >= 1;
        if (!hasValidPage) {
          return /* @__PURE__ */ React__default.createElement(Redirect, {
            to: AccPath.PersonalData.withSearchParams({ page: 1 })
          });
        }
        return hasValidPage && /* @__PURE__ */ React__default.createElement(PersonalDataPage, {
          page
        });
      }
    }), deleteAccount() && /* @__PURE__ */ React__default.createElement(Route, {
      exact: true,
      path: AccPath.AccountDeletion.link,
      render: () => /* @__PURE__ */ React__default.createElement(AccountDeletionPage, null)
    }), notification() && /* @__PURE__ */ React__default.createElement(Route, {
      exact: true,
      path: AccPath.NotificationPreferences.link,
      render: () => /* @__PURE__ */ React__default.createElement(NotificationPreferencesPage, null)
    }), privacyRecords() && /* @__PURE__ */ React__default.createElement(Route, {
      exact: true,
      path: AccPath.PrivacyRecords.link,
      render: () => /* @__PURE__ */ React__default.createElement(PrivacyRecordsPage, null)
    }), /* @__PURE__ */ React__default.createElement(Redirect, {
      from: "/**",
      to: accountWildCardRedirect()
    })));
  }
}
var AccountPage$1 = withRouter(AccountPage);
export { AccountPage$1 as default };
