"use client"; import type { CommercialBundle, CommercialPricingItem, CommercialProduct } from "../types"; import { Badge, Button } from "@/components/ui"; import { commercialDescription, commercialEntityName, enumLabel, formatMoney, } from "../presentation"; export function BundleCard({ bundle, onSelect, selected, recommendationScore, pricingItems = [], products = [], }: { bundle: CommercialBundle; onSelect?: () => void; selected?: boolean; recommendationScore?: number; pricingItems?: CommercialPricingItem[]; products?: CommercialProduct[]; }) { const features = bundle.feature_refs?.length ? bundle.feature_refs : bundle.capability_codes || []; const prices = (bundle.pricing_refs || []) .map((ref) => pricingItems.find((item) => item.pricing_item_code === ref)) .filter((item): item is CommercialPricingItem => Boolean(item)); const presentedProducts = (bundle.product_codes || []).map((code, index) => ({ key: `${code}-${index}`, name: commercialEntityName( "products", code, products.find((product) => product.product_code === code)?.display_name ), })); const bundleName = commercialEntityName( "bundles", bundle.bundle_code, bundle.display_name ); const badge = bundle.recommendation_badge ? enumLabel(bundle.recommendation_badge) : recommendationScore != null ? "پیشنهاد ویژه برای شما" : null; const unresolvedPriceLabels = (bundle.pricing_refs || []) .filter((ref) => !prices.some((item) => item.pricing_item_code === ref)) .map((ref) => { if (/monthly/i.test(ref)) return "پرداخت ماهانه"; if (/yearly|annual/i.test(ref)) return "پرداخت سالانه"; if (/trial/i.test(ref)) return "آزمایش رایگان"; if (/enterprise|quote/i.test(ref)) return "استعلام قیمت سازمانی"; return "روش پرداخت قابل انتخاب"; }); const hasCoupon = bundle.discount_refs?.some((ref) => /coupon/i.test(ref)); return (
{commercialDescription("bundles", bundle.description)}
محصولات این بسته
امکانات کلیدی
{commercialEntityName("pricing", price.pricing_item_code, price.display_name)}
{enumLabel(price.pricing_model)}
{formatMoney(price.amount_minor, price.currency)}
{price.trial_days ?{price.trial_days} روز آزمایش رایگان
: null} {price.tax_class_code ?مالیات مطابق قوانین محاسبه میشود
: null}امکان ارتقا در هر زمان
) : null} {onSelect ? ( ) : null}