import Typography, { ETypo, ETypoColor } from "@Front/Components/DesignSystem/Typography";
import DefaultLegalDashboard, { ELegalOptions } from "@Front/Components/LayoutTemplates/DefaultLegalDashboard";
import Link from "next/link";
import { useRouter } from "next/router";
import React from "react";

import CGU from "./CGU";
import classes from "./classes.module.scss";
import LegalNotice from "./LegalNotice";
import PrivacyPolicy from "./PrivacyPolicy";

const pdfLinks: Record<ELegalOptions, string> = {
	"mentions-legales": "https://s3.fr-par.scw.cloud/lecoffre.io-bucket/footer/mentions_legales.pdf",
	"politique-de-confidentialite": "https://s3.fr-par.scw.cloud/lecoffre.io-bucket/footer/politique_confidentialite.pdf",
	"politique-de-gestion-des-cookies": "https://s3.fr-par.scw.cloud/lecoffre.io-bucket/footer/politique_cookies.pdf",
	cgs: "https://s3.fr-par.scw.cloud/lecoffre.io-bucket/footer/cgs.pdf",
	cgu: "https://s3.fr-par.scw.cloud/lecoffre.io-bucket/footer/cgu.pdf",
};

export default function LegalInformations() {
	const router = useRouter();
	let { legalUid } = router.query;
	const legalType = legalUid as ELegalOptions;
	return <DefaultLegalDashboard>{getLegalInformationContent(legalType)}</DefaultLegalDashboard>;
}

function getLegalInformationContent(legalType: ELegalOptions) {
	switch (legalType) {
		case ELegalOptions.LEGAL_MENTIONS:
			return <LegalNotice />;
		case ELegalOptions.CGU:
			return <CGU />;
		case ELegalOptions.CGS:
			return (
				<object data={pdfLinks[legalType]} type="application/pdf" width="100%" height="100%" className={classes["pdf-viewer"]}>
					<Typography typo={ETypo.TEXT_LG_LIGHT} className={classes["no-pdf-text"]}>
						Votre navigateur ne prend pas en charge l'affichage des pdf&nbsp;
						<Typography typo={ETypo.TEXT_LG_LIGHT} type="span">
							<Link href={pdfLinks[legalType]} target="_blank" style={{ color: `var(${ETypoColor.COLOR_PRIMARY_500})` }}>
								cliquez ici pour télécharger le pdf.
							</Link>
						</Typography>
					</Typography>
				</object>
			);
		case ELegalOptions.POLITIQUE_DE_CONFIDENTIALITE:
			return <PrivacyPolicy />;
		case ELegalOptions.POLITIQUE_DE_GESTION_DES_COOKIES:
			return (
				<object data={pdfLinks[legalType]} type="application/pdf" width="100%" height="100%" className={classes["pdf-viewer"]}>
					<Typography typo={ETypo.TEXT_LG_LIGHT} className={classes["no-pdf-text"]}>
						Votre navigateur ne prend pas en charge l'affichage des pdf&nbsp;
						<Typography typo={ETypo.TEXT_LG_LIGHT} type="span">
							<Link href={pdfLinks[legalType]} target="_blank" style={{ color: `var(${ETypoColor.COLOR_PRIMARY_500})` }}>
								cliquez ici pour télécharger le pdf.
							</Link>
						</Typography>
					</Typography>
				</object>
			);
		default:
			return null;
	}
}
