"use client"; import { useState, useEffect } from "react"; import Image from "next/image"; import { useTranslation } from "../../contexts/MessagesContext"; import { useMediaQuery } from "../../hooks/useMediaQuery"; import RuleCard from "../RuleCard"; import SectionHeader from "../SectionHeader"; import Button from "../Button"; import { getAssetPath } from "../../../lib/assetUtils"; import type { RuleStackViewProps } from "./RuleStack.types"; export function RuleStackView({ className, onTemplateClick, }: RuleStackViewProps) { const t = useTranslation("pages.home.ruleStack"); const [isMounted, setIsMounted] = useState(false); // Debug: Log button text to ensure translation works const buttonText = t("button.seeAllTemplates"); // Determine current breakpoint for RuleCard size // 320-639: XS, 640-767: S, 768-1023: S, 1024-1439: M, 1440+: L const isMax639 = useMediaQuery("(max-width: 639px)"); const isMin640Max1023 = useMediaQuery("(min-width: 640px) and (max-width: 1023px)"); const isMin1024Max1439 = useMediaQuery("(min-width: 1024px) and (max-width: 1439px)"); const isMin1440 = useMediaQuery("(min-width: 1440px)"); // Handle hydration: only use media queries after mount useEffect(() => { setIsMounted(true); }, []); // Use CSS classes for responsive sizing to avoid hydration mismatch // Default to M size for SSR, then let CSS handle the responsive sizing const cardSize = isMounted ? isMax639 ? "XS" : isMin640Max1023 ? "S" : isMin1024Max1439 ? "M" : isMin1440 ? "L" : "M" : "M"; // Icon sizes: XS=40px, S=56px, M=56px, L=90px // Use a large default (90px) and let CSS handle responsive sizing const iconSize = 90; // Card data const cards = [ { title: t("cards.consensusClusters.title"), description: t("cards.consensusClusters.description"), iconAlt: t("cards.consensusClusters.iconAlt"), iconPath: "assets/Icon_Sociocracy.svg", backgroundColor: "bg-[var(--color-surface-default-brand-lime)]", }, { title: t("cards.consensus.title"), description: t("cards.consensus.description"), iconAlt: t("cards.consensus.iconAlt"), iconPath: "assets/Icon_Consensus.svg", backgroundColor: "bg-[var(--color-surface-default-brand-rust)]", }, { title: t("cards.electedBoard.title"), description: t("cards.electedBoard.description"), iconAlt: t("cards.electedBoard.iconAlt"), iconPath: "assets/Icon_ElectedBoard.svg", backgroundColor: "bg-[var(--color-surface-default-brand-red)]", }, { title: t("cards.petition.title"), description: t("cards.petition.description"), iconAlt: t("cards.petition.iconAlt"), iconPath: "assets/Icon_Petition.svg", backgroundColor: "bg-[var(--color-surface-default-brand-teal)]", }, ]; return (
{/* Section Header */} {/* Cards Container */}
{cards.map((card, index) => ( } backgroundColor={card.backgroundColor} onClick={() => onTemplateClick(card.title)} /> ))}
{/* See all templates button */}
); }