import { Check } from "lucide-react";
import * as React from "react";
import { Trans, useTranslation } from "react-i18next";
import type { MetaFunction } from "react-router";
import { Badge } from "~/components/Badge";
import { LinkButton } from "~/components/elements/Button";
import { Main } from "~/components/Main";
import { metaTags } from "~/utils/remix";
import {
	PATREON_HOW_TO_CONNECT_DISCORD_URL,
	SENDOU_INK_PATREON_URL,
} from "~/utils/urls";
import { SendouButton } from "../../../components/elements/Button";
import { SendouPopover } from "../../../components/elements/Popover";
import styles from "./support.module.css";

export const meta: MetaFunction = (args) => {
	return metaTags({
		title: "Support",
		description: "Support Sendou's work on Patreon and get perks on sendou.ink",
		location: args.location,
	});
};

// 1 = support
// 2 = supporter
// 3 = supporter+
const PERKS = [
	{
		tier: 1,
		name: "supportMyWork",
		extraInfo: false,
	},
	{
		tier: 1,
		name: "adFree",
		extraInfo: false,
	},
	{
		tier: 1,
		name: "nameInFooter",
		extraInfo: false,
	},
	{
		tier: 2,
		name: "privateDiscord",
		extraInfo: true,
	},
	{
		tier: 2,
		name: "prioritySupport",
		extraInfo: true,
	},
	{
		tier: 2,
		name: "tournamentsBeta",
		extraInfo: false,
	},
	{
		tier: 2,
		name: "earlyAccess",
		extraInfo: false,
	},
	{
		tier: 2,
		name: "previewQ",
		extraInfo: false,
	},
	{
		tier: 2,
		name: "userShortLink",
		extraInfo: true,
	},
	{
		tier: 2,
		name: "autoValidatePictures",
		extraInfo: true,
	},
	{
		tier: 2,
		name: "customizedColorsUser",
		extraInfo: false,
	},
	{
		tier: 2,
		name: "customAvatar",
		extraInfo: true,
	},
	{
		tier: 2,
		name: "favoriteBadges",
		extraInfo: true,
	},
	{
		tier: 2,
		name: "customizedColorsTeam",
		extraInfo: true,
	},
	{
		tier: 2,
		name: "badge",
		extraInfo: false,
	},
	{
		tier: 2,
		name: "discordColorRole",
		extraInfo: true,
	},
	{
		tier: 2,
		name: "chatColor",
		extraInfo: false,
	},
	{
		tier: 2,
		name: "seePlusPercentage",
		extraInfo: true,
	},
	{
		tier: 2,
		name: "joinFive",
		extraInfo: false,
	},
	{
		tier: 2,
		name: "joinMoreAssociations",
		extraInfo: false,
	},
	{
		tier: 2,
		name: "useBotToLogIn",
		extraInfo: true,
	},
] as const;

export default function SupportPage() {
	const { t } = useTranslation();

	return (
		<Main className="stack lg">
			<div className="stack md">
				<p>{t("support.intro.first")}</p>
				<p>{t("support.intro.second")}</p>
				<SupportTable />
			</div>
			<LinkButton
				size="big"
				to={SENDOU_INK_PATREON_URL}
				isExternal
				className="mx-auto"
			>
				{t("support.action")}
			</LinkButton>
			<p className="text-sm text-lighter">
				<Trans t={t} i18nKey="support.footer">
					After becoming a new patron you should connect{" "}
					<a
						href={PATREON_HOW_TO_CONNECT_DISCORD_URL}
						target="_blank"
						rel="noreferrer"
					>
						your Discord on Patreon.com
					</a>
					. Afterwards the perks will take effect within an hour. If any
					questions or problems contact Sendou for support.
				</Trans>
			</p>
		</Main>
	);
}

function SupportTable() {
	const { t } = useTranslation();
	return (
		<div className={styles.table}>
			<div />
			<div>Support</div>
			<div>Supporter</div>
			<div>Supporter+</div>
			{PERKS.map((perk) => {
				return (
					<React.Fragment key={perk.name}>
						<div className="justify-self-start">
							{t(`support.perk.${perk.name}`)}
							{perk.extraInfo ? (
								<>
									{" "}
									<SendouPopover
										trigger={
											<SendouButton className={styles.popoverTrigger}>
												?
											</SendouButton>
										}
									>
										{t(`support.perk.${perk.name}.extra` as any)}
									</SendouPopover>
								</>
							) : null}
						</div>
						<div>
							{perk.tier === 1 ? <Check className={styles.checkmark} /> : null}
						</div>
						{perk.name === "badge" ? (
							<div>
								<Badge
									isAnimated
									badge={{ code: "patreon", displayName: "" }}
									size={32}
								/>
							</div>
						) : (
							<div>
								{perk.tier <= 2 ? <Check className={styles.checkmark} /> : null}
							</div>
						)}
						{perk.name === "badge" ? (
							<div>
								<Badge
									isAnimated
									badge={{
										code: "patreon_plus",
										displayName: "",
									}}
									size={32}
								/>
							</div>
						) : (
							<div>
								{perk.tier <= 3 ? <Check className={styles.checkmark} /> : null}
							</div>
						)}
					</React.Fragment>
				);
			})}
		</div>
	);
}
