"use client"; import { useState, useEffect } from "react"; import { Card, CardHeader, CardTitle, CardDescription, CardContent, CardFooter, } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { CheckIcon, Loader2 } from "lucide-react"; import { Dictionary } from "@/lib/IDict"; import { pb } from "@/lib/pb"; import { CyberButton } from "../ui/cyber-button"; interface PBPricingPlan { id: string; name: string; level: string; tagline: string; description: string; price1m: number; price6m: number; price1y: number; features: string; popular: boolean; cta: string; lang: string; order: number; } type Period = "1m" | "6m" | "1y"; interface PeriodOption { id: Period; label: string; badge?: string; } export function Pricing({ dict, lang, }: { dict: Dictionary["pricing"]; lang: string; }) { const [period, setPeriod] = useState("1y"); const [plans, setPlans] = useState([]); const [loading, setLoading] = useState(!!lang); useEffect(() => { if (!lang) return; async function fetchPlans() { try { setLoading(true); const records = await pb .collection(`pricing_${lang}`) .getFullList({ sort: "order", requestKey: null, }); setPlans(records); } catch (error) { console.error("Ошибка загрузки тарифов:", error); } finally { setLoading(false); } } fetchPlans(); }, [lang]); const isRu = lang === "ru"; const currencySign = isRu ? "₽" : "$"; const periods: PeriodOption[] = [ { id: "1m", label: isRu ? "1 месяц" : "1 month" }, { id: "6m", label: isRu ? "6 месяцев" : "6 months" }, { id: "1y", label: isRu ? "1 год" : "1 year", badge: isRu ? "Выгодно" : "Best Value", }, ]; return (
{dict.badge}

{dict.title}

{periods.map((p: PeriodOption) => ( ))}
{loading ? (
Syncing_Nodes...
) : plans.length === 0 ? (

0 uplinks found.

) : (
{plans.map((plan) => { const months = period === "1m" ? 1 : period === "6m" ? 6 : 12; // Текущая цена за выбранный период (разовое списание) const totalPrice = period === "1m" ? plan.price1m : period === "6m" ? plan.price6m : plan.price1y; // Базовая цена за месяц (для расчета скидки) const baseMonthlyPrice = plan.price1m; // Эквивалент цены за 1 месяц при выбранном тарифе const monthlyEquivalent = Math.round(totalPrice / months); // Проверяем, есть ли скидка (дешевле ли в месяц, чем при тарифе на 1м) const isDiscounted = monthlyEquivalent < baseMonthlyPrice; const formatPrice = (price: number) => isRu ? price.toLocaleString("ru-RU") : price.toString(); return ( {plan.popular && (
{isRu ? "Рекомендуем" : "Recommended"}
)}
{plan.level}
{plan.name}
«{plan.tagline}»
{plan.description} {/* Оптимизированный блок цен */}
{/* Блок скидки (фиксированная высота h-6 для стабильности верстки) */}
{isDiscounted && ( <> {isRu ? "" : currencySign} {formatPrice(baseMonthlyPrice)} {isRu ? currencySign : ""} {isRu ? "СКИДКА" : "SAVE"}{" "} {Math.round( (1 - monthlyEquivalent / baseMonthlyPrice) * 100, )} % )}
{/* Крупная цена за месяц (как главный хук для пользователя) */}
{isRu ? "" : currencySign} {formatPrice(monthlyEquivalent)} {isRu && ( {currencySign} )} {isRu ? "/ мес" : "/ mo"}
{/* Пояснение по списанию (Появляется только если платим сразу за 6/12 мес) */}
{period !== "1m" && (
{isRu ? "Спишется разом:" : "Billed once:"} {isRu ? "" : currencySign} {formatPrice(totalPrice)} {isRu ? currencySign : ""}
)}
    {plan.features .split("\n") .filter((f) => f.trim()) .map((feature, i) => (
  • {feature.trim()}
  • ))}
{plan.cta}
); })}
)}
); }