import { login } from "@/constants/routes/handleAuth"

import { auth } from "@/auth"
import ArrowRight from "@/components/Icons/ArrowRight"
import { ScandicFriends } from "@/components/Levels"
import Button from "@/components/TempDesignSystem/Button"
import Link from "@/components/TempDesignSystem/Link"
import Body from "@/components/TempDesignSystem/Text/Body"
import Title from "@/components/TempDesignSystem/Text/Title"
import { getIntl } from "@/i18n"

import Contact from "./Contact"

import styles from "./joinLoyalty.module.css"

import type { JoinLoyaltyContactProps } from "@/types/components/loyalty/sidebar"
import { LangParams } from "@/types/params"

export default async function JoinLoyaltyContact({
  block,
  lang,
}: JoinLoyaltyContactProps & LangParams) {
  const { formatMessage } = await getIntl()
  const session = await auth()

  if (session) {
    return null
  }
  return (
    <section>
      <article className={styles.wrapper}>
        <Title as="h4" level="h3">
          {block.title}
        </Title>
        <ScandicFriends color="red" />
        {block.preamble ? <Body>{block.preamble}</Body> : null}
        <Button asChild intent="primary" theme="base" className={styles.button}>
          <Link href={login[lang]} color="white">
            {formatMessage({ id: "Join Scandic Friends" })}
          </Link>
        </Button>
        <section className={styles.loginContainer}>
          <Body>{formatMessage({ id: "Already a friend?" })}</Body>
          <Link
            className={styles.link}
            color="burgundy"
            href={`/${lang}/login`}
            variant="icon"
            size="small"
          >
            <ArrowRight
              color="burgundy"
              className={styles.icon}
              height="20"
              width="20"
            />
            {formatMessage({ id: "Log in here" })}
          </Link>
        </section>
      </article>
      {block.contact ? <Contact contactBlock={block.contact} /> : null}
    </section>
  )
}
