import {
  GuaranteedSecurityPayments,
  Header,
  HeaderTimer,
  HiBlock,
  LandingButtonWrapper,
  MoneyBackGuarantee,
  Payments,
  PlanAlsoIncludes,
  RealTimeActivity,
  Reviews,
  SpecialOffer,
  Statistics,
  WhatGet,
} from "@/components/domains/email-marketing/soulmate/v1";
import { loadFunnelPaymentById } from "@/entities/session/funnel/loaders";
import {
  IFunnelPaymentPlacement,
  IFunnelPaymentVariant,
} from "@/entities/session/funnel/types";
import { loadUser } from "@/entities/user/loaders";
import { Currency, ELocalesPlacement } from "@/types";

import styles from "./page.module.scss";

const payload = {
  funnel: ELocalesPlacement.EmailMarketingSoulmateV1,
};

function getUsernameFromEmail(email: string): string {
  const localPart = email.split("@")[0];
  return `@${localPart}`;
}

export default async function EmailMarketingSoulmateV1Landing() {
  const [payment, user] = await Promise.all([
    loadFunnelPaymentById(
      payload,
      "main"
    ) as Promise<IFunnelPaymentPlacement | null>,
    loadUser(),
  ]);

  const username = getUsernameFromEmail(user.email);

  const variant = payment?.variants?.[0];
  const currency = payment?.currency || Currency.USD;
  const oldTrialInterval = 7; // TODO
  const newTrialInterval = payment?.trialInterval || 7;
  const trialPeriod = payment?.trialPeriod || "DAY";

  return (
    <div className={styles.container}>
      <HeaderTimer />
      <Header />
      <HiBlock />
      <WhatGet username={username} />
      <SpecialOffer
        variant={variant as IFunnelPaymentVariant}
        currency={currency}
        oldTrialInterval={oldTrialInterval}
        newTrialInterval={newTrialInterval}
        trialPeriod={trialPeriod}
      />
      <PlanAlsoIncludes />
      <Reviews />
      <Statistics />
      <RealTimeActivity />
      <MoneyBackGuarantee />
      <GuaranteedSecurityPayments />
      <Payments />
      <LandingButtonWrapper />
    </div>
  );
}
