'use client'; import { discountFor, quote, type Locale } from '@barev/core'; import { formatAmd, tFromMessages, type Messages } from '@barev/i18n'; import { Stepper } from '@barev/ui'; import { useMemo, useState } from 'react'; import type { CleaningConfig } from '../lib/data'; const TYPES = ['regular', 'general', 'renovation'] as const; /** * Калькулятор экономии с Barev+: цена уборки — функцией quote, как на сервере, скидка — как у участника Barev+. * Подписка вычитается из экономии; если выгоды нет, так и пишем и показываем, с какого числа уборок она появится. */ export function Savings({ locale, config, monthlyPrice, messages }: { locale: Locale; config: CleaningConfig; monthlyPrice: number; messages: Messages }) { const t = useMemo(() => tFromMessages(locale, messages), [locale, messages]); const amd = (n: number) => formatAmd(locale, n); // стартовый сценарий: генеральная уборка трёшки дважды в месяц — дальше человек подставляет своё const [type, setType] = useState<(typeof TYPES)[number]>('general'); const [rooms, setRooms] = useState(3); const [count, setCount] = useState(2); const pct = discountFor('BAREV_PLUS', config.categoryDiscountPct); const params = { cleaningType: type, rooms, bathrooms: 1 }; const one = quote(config.pricing, params); const oneWithPlus = quote(config.pricing, params, pct); const without = one.totalPrice * count; const withPlus = oneWithPlus.totalPrice * count + monthlyPrice; const save = without - withPlus; const perCleaning = one.totalPrice - oneWithPlus.totalPrice; // выгода есть, когда скидка за n уборок больше цены подписки: n × perCleaning > monthlyPrice const breakeven = perCleaning > 0 ? Math.floor(monthlyPrice / perCleaning) + 1 : null; const max = Math.max(without, withPlus); return (
{TYPES.map((v) => ( ))}
{t('params.cleaning.rooms.label')}
{t('landing.v5.perMonth')}
{save > 0 ? t('landing.v5.save') : t('landing.v5.noSave')} {save > 0 ? amd(save) : '0 ֏'} {save > 0 && {t('landing.v5.perYear', { amount: amd(save * 12) })}}
{t('landing.v5.without')} {amd(without)}
{t('landing.v5.with')} {t('landing.v5.withNote', { price: amd(monthlyPrice) })} {amd(withPlus)}
{breakeven !== null && (

{breakeven === 1 ? t('landing.v5.breakevenFirst') : t('landing.v5.breakeven', { count: breakeven })}

)}
); }