"use client"; import { useEffect, useMemo, useState } from "react"; import Link from "next/link"; import { Badge, Button, Container } from "@/components/ui"; import { loadCommercialBundles, loadCommercialPricing, loadCommercialProducts } from "@/modules/commercial/adapters"; import type { AdapterResult, CommercialBundle, CommercialPricingItem, CommercialProduct } from "@/modules/commercial/types"; import { CommercialEmptyState, CommercialSkeleton } from "@/modules/commercial/components"; import { formatMoney, humanizeCommercialCode } from "@/modules/commercial/presentation"; type PlanGroup = { key: string; title: string; description: string; monthly?: CommercialPricingItem; yearly?: CommercialPricingItem; trial?: CommercialPricingItem; enterprise?: CommercialPricingItem; bundle?: CommercialBundle; }; function planKey(item: CommercialPricingItem): string { return item.pricing_item_code .replace(/\.(monthly|yearly|annual|trial|enterprise_quote)$/i, "") .replace(/^price\./, ""); } export default function PricingPage() { const [pricing, setPricing] = useState | null>(null); const [bundles, setBundles] = useState | null>(null); const [products, setProducts] = useState | null>(null); useEffect(() => { void Promise.all([loadCommercialPricing(), loadCommercialBundles(), loadCommercialProducts()]).then(([prices, packages, catalog]) => { setPricing(prices); setBundles(packages); setProducts(catalog); }); }, []); const plans = useMemo(() => { if (pricing?.availability !== "ready") return []; const groups = new Map(); pricing.data.forEach((item) => { const key = planKey(item); const group = groups.get(key) || { key, title: humanizeCommercialCode(item.pricing_item_code, item.display_name), description: "همه ابزارهای لازم برای شروع و رشد کسب‌وکار شما", }; const model = String(item.pricing_model || item.pricing_item_code.split(".").at(-1) || "").toLowerCase(); if (model.includes("year") || model.includes("annual")) group.yearly = item; else if (model.includes("trial")) group.trial = item; else if (model.includes("enterprise") || item.amount_minor == null) group.enterprise = item; else group.monthly = item; groups.set(key, group); }); return Array.from(groups.values()).map((group) => ({ ...group, bundle: bundles?.data.find((bundle) => bundle.pricing_refs?.some((ref) => planKey({ pricing_item_code: ref, display_name: "" }) === group.key) ), })); }, [bundles?.data, pricing]); const popularIndex = plans.length > 2 ? 1 : 0; const productName = (code: string) => products?.data.find((product) => product.product_code === code)?.display_name || humanizeCommercialCode(code); return (
قیمت‌گذاری شفاف و قابل ارتقا

پلن مناسب رشد کسب‌وکار شما

رایگان امتحان کنید، هر زمان خواستید ارتقا دهید و با پرداخت سالانه هزینه کمتری بپردازید.

{!pricing ? ( ) : plans.length ? (
{plans.map((plan, index) => { const featured = index === popularIndex; const trialDays = plan.trial?.trial_days || plan.monthly?.trial_days || plan.yearly?.trial_days; const capabilityNames = (plan.bundle?.capability_codes || plan.bundle?.feature_refs || []).slice(0, 6); return (
{featured ? محبوب‌ترین : null} {plan.bundle?.recommendation_badge ? پیشنهاد‌شده برای کسب‌وکار شما : null}

{plan.title}

{plan.bundle?.description || plan.description}

ماهانه {formatMoney(plan.monthly?.amount_minor, plan.monthly?.currency)}
سالانه {formatMoney(plan.yearly?.amount_minor, plan.yearly?.currency)}
{plan.enterprise ?

راهکار سازمانی با استعلام قیمت

: null}
{trialDays ?
{trialDays.toLocaleString("fa-IR")} روز آزمایش رایگان
: null} {plan.bundle?.product_codes?.length ? (

محصولات شامل‌شده

{plan.bundle.product_codes.map((code) => {productName(code)})}
) : null} {capabilityNames.length ? (
    {capabilityNames.map((code) =>
  • {humanizeCommercialCode(code)}
  • )}
) :
}
); })}
) : (
)} {plans.length ? (

مقایسه سریع پلن‌ها

جزئیات مهم را در یک نگاه مقایسه کنید.

{plans.map((plan) => )}
پلنپرداخت ماهانهپرداخت سالانهآزمایش رایگانمحصولات
{plan.title}{formatMoney(plan.monthly?.amount_minor, plan.monthly?.currency)}{formatMoney(plan.yearly?.amount_minor, plan.yearly?.currency)}{plan.trial?.trial_days || plan.monthly?.trial_days ? "دارد" : "ندارد"}{(plan.bundle?.product_codes?.length || 0).toLocaleString("fa-IR")} محصول
) : null}

برای انتخاب مطمئن کمک می‌خواهید؟

چند سؤال کوتاه پاسخ دهید تا فقط گزینه‌های مناسب کسب‌وکار شما پیشنهاد شوند.

); }