"use client";
import { useEffect, useState, type KeyboardEvent } from "react";
import Image from "next/image";
import { Icon } from "@iconify/react";
import { AnimatePresence, motion, useReducedMotion } from "framer-motion";
import { useLocale, useTranslations } from "next-intl";
import {
Badge,
Button,
ButtonIcon,
ButtonLabel,
Card,
Typography,
} from "poyraz-ui/atoms";
import { Link } from "@/i18n/routing";
import {
LEFT_LAYOUT_PROMO_SLIDES,
RIGHT_LAYOUT_PROMO_SLIDES,
type LayoutPromoCardDefinition,
type LayoutPromoSlide,
} from "@/data/layout-promos";
import { SPONSORS } from "@/data/sponsors";
import { getLocalizedValue } from "@/lib/locale";
export type LayoutContentPromo = {
title: string;
href: string;
};
type PromoRailSide = "left" | "right";
const PROMO_ROTATION_INTERVAL_MS = 8_000;
function RailButton({
href,
label,
icon = "mdi:arrow-right",
variant = "outline",
external = false,
}: {
href: string;
label: string;
icon?: string;
variant?: "default" | "outline" | "secondary";
external?: boolean;
}) {
const content = (
<>
{label}
>
);
return (
);
}
function SponsorLogos() {
return (
{SPONSORS.map((sponsor, index) => (
))}
);
}
function PromoIcon({
card,
className,
}: {
card: LayoutPromoCardDefinition;
className?: string;
}) {
return (
);
}
function PromoCard({
card,
latestAgenda,
latestPost,
}: {
card: LayoutPromoCardDefinition;
latestAgenda: LayoutContentPromo | null;
latestPost: LayoutContentPromo | null;
}) {
const t = useTranslations("LayoutPromos");
const locale = useLocale();
const liveContent =
card.contentSource === "latestAgenda"
? latestAgenda
: card.contentSource === "latestPost"
? latestPost
: null;
const href = liveContent?.href ?? getLocalizedValue(card.href, locale);
const description = liveContent?.title ?? t(card.descriptionKey);
const external = card.external ?? false;
const iconSurface = card.iconSurface ?? "accent";
const cardClassName =
card.surface === "primary"
? "rounded-sm border-primary/25 bg-primary/5 p-3"
: "rounded-sm border-border p-3";
const iconClassName =
iconSurface === "primary"
? "bg-primary text-primary-foreground"
: iconSurface === "foreground"
? "bg-foreground text-background"
: "bg-accent text-foreground";
return (
{card.eyebrowKey ? (
) : (
)}
{t(card.titleKey)}
{description}
{card.kind === "sponsors" ? : null}
);
}
function PromoRail({
side,
slides,
latestAgenda = null,
latestPost = null,
}: {
side: PromoRailSide;
slides: readonly LayoutPromoSlide[];
latestAgenda?: LayoutContentPromo | null;
latestPost?: LayoutContentPromo | null;
}) {
const t = useTranslations("LayoutPromos");
const reduceMotion = useReducedMotion();
const [activeSlide, setActiveSlide] = useState(0);
const [isPaused, setIsPaused] = useState(false);
const direction = side === "left" ? -1 : 1;
const activeCards = slides[activeSlide] ?? slides[0];
const railId = `${side}-promo-rail`;
const selectAdjacentSlide = (step: number) => {
setActiveSlide((current) => (current + step + slides.length) % slides.length);
};
useEffect(() => {
if (reduceMotion || isPaused || slides.length < 2) return;
const timer = window.setTimeout(() => {
setActiveSlide((current) => (current + 1) % slides.length);
}, PROMO_ROTATION_INTERVAL_MS);
return () => window.clearTimeout(timer);
}, [activeSlide, isPaused, reduceMotion, slides.length]);
const handleNavigationKeyDown = (event: KeyboardEvent) => {
if (event.key !== "ArrowLeft" && event.key !== "ArrowRight") return;
event.preventDefault();
selectAdjacentSlide(event.key === "ArrowRight" ? 1 : -1);
};
return (
);
}
export function LayoutLeftPromoRail({
latestAgenda,
latestPost,
}: {
latestAgenda: LayoutContentPromo | null;
latestPost: LayoutContentPromo | null;
}) {
return (
);
}
export function LayoutRightPromoRail() {
return ;
}