"use client"; import { useEffect, useState } from "react"; import { useLocale } from "next-intl"; import { useRouter } from "@/i18n/routing"; import { Clock, X, Zap } from "lucide-react"; // 1 Tir 1405 = June 22, 2026 (Tehran IRDT UTC+4:30) const DEADLINE = new Date("2026-06-22T00:00:00+04:30"); const STORAGE_KEY = "meezi_trial_banner_v1"; interface TimeLeft { days: number; hours: number; minutes: number; seconds: number; } function calcTimeLeft(): TimeLeft { const diff = Math.max(0, DEADLINE.getTime() - Date.now()); return { days: Math.floor(diff / 86_400_000), hours: Math.floor((diff % 86_400_000) / 3_600_000), minutes: Math.floor((diff % 3_600_000) / 60_000), seconds: Math.floor((diff % 60_000) / 1_000), }; } function pad(n: number) { return n.toString().padStart(2, "0"); } export function TrialCountdownBanner() { const locale = useLocale(); const router = useRouter(); const isRtl = locale !== "en"; // Start hidden — reveal after mount so we can read localStorage without SSR mismatch const [visible, setVisible] = useState(false); const [timeLeft, setTimeLeft] = useState(calcTimeLeft); const [expired, setExpired] = useState(false); // Hydrate visibility from localStorage useEffect(() => { if (localStorage.getItem(STORAGE_KEY) !== "1") { setVisible(true); } }, []); // Tick every second useEffect(() => { if (!visible) return; const id = setInterval(() => { const tl = calcTimeLeft(); setTimeLeft(tl); if (tl.days === 0 && tl.hours === 0 && tl.minutes === 0 && tl.seconds === 0) { setExpired(true); } }, 1_000); return () => clearInterval(id); }, [visible]); if (!visible) return null; const dismiss = () => { setVisible(false); localStorage.setItem(STORAGE_KEY, "1"); }; const urgency = timeLeft.days <= 3; // red when ≤ 3 days left const soon = timeLeft.days <= 7; // amber when ≤ 7 days left const bgClass = urgency ? "bg-red-600" : soon ? "bg-amber-500" : "bg-[#0F6E56]"; const textFa = expired ? "دوره آزمایشی میزی به پایان رسید. برای ادامه پلن انتخاب کنید." : "دوره آزمایشی رایگان تا ۱ تیر ۱۴۰۵"; const textEn = expired ? "Your Meezi trial has ended. Choose a plan to continue." : "Free trial ends 1 Tir 1405 (Jun 22)"; const Digit = ({ value, label }: { value: number; label: string }) => (
{pad(value)} {label}
); const labelsFa = ["روز", "ساعت", "دقیقه", "ثانیه"]; const labelsEn = ["d", "h", "m", "s"]; const labels = isRtl ? labelsFa : labelsEn; return (
{/* Icon + message */}
{isRtl ? textFa : textEn}
{/* Countdown digits */} {!expired && (
: : :
)} {/* CTA */} {/* Dismiss */}
); }