import { CATEGORY_TONE, Icon, type CategoryCode } from '@barev/ui'; import { paramsSummary, useI18n } from '@barev/web'; import type { ReactNode } from 'react'; export const toneClass = (c: string) => `bc-tone-${CATEGORY_TONE[c as CategoryCode] ?? 'white'}`; export function PageHead({ title, back = true, right }: { title: ReactNode; back?: boolean; right?: ReactNode }) { const { t } = useI18n(); return (
{back && ( )}

{title}

{right}
); } export interface OrderLike { id: string; number: number; serviceCode: string; category: string; flow: string; status: string; scheduledAt: Date; params: Record; } /** Подпись параметров: «Генеральная · 2 комнаты» */ export function useParamsSummary() { const { t } = useI18n(); return (serviceCode: string, params: Record) => paramsSummary(t, serviceCode, params); } /** Строка заявки как в превью «Мои заявки» макета */ export function OrderRow({ o }: { o: OrderLike }) { const { t, dt } = useI18n(); const summary = useParamsSummary(); return (
{t(`services.${o.serviceCode}.name`)} · {summary(o.serviceCode, o.params)}
{dt(o.scheduledAt, { weekday: 'short', day: 'numeric', month: 'short', hour: '2-digit', minute: '2-digit' })}
{t(`status.${o.flow}.${o.status}`)}
); } export type Level = 'BAREV' | 'BAREV_PLUS' | 'ELITE'; export const LEVEL_NAME: Record = { BAREV: 'Barev', BAREV_PLUS: 'Barev+', ELITE: 'Barev Elite' }; /** Цвет плашки уровня: как карты на сайте — Barev+ розовая, Elite жёлтая */ export const LEVEL_TONE: Record = { BAREV: { bg: 'var(--bc-surface)', ink: 'var(--bc-ink)' }, BAREV_PLUS: { bg: 'var(--bc-pink)', ink: 'var(--bc-plum)' }, ELITE: { bg: 'var(--bc-perks)', ink: 'var(--bc-plum)' }, }; /** Скидка клиента на направление по его уровню; у Elite без своей скидки — скидка Barev+ */ export function levelDiscount(level: Level, c: { barevPlusDiscountPct: number; eliteDiscountPct: number }) { if (level === 'ELITE') return Math.max(c.eliteDiscountPct, c.barevPlusDiscountPct); return level === 'BAREV_PLUS' ? c.barevPlusDiscountPct : 0; } export function LevelBadge({ level }: { level: Level }) { const tone = LEVEL_TONE[level]; return ( {LEVEL_NAME[level]} ); } export type RelocationNames = Record; hint: Record | null }>; /** Название шага или документа: своё у клиента (title) или из общего списка на языке клиента */ export function itemName(names: RelocationNames | undefined, kind: 'STEP' | 'DOC', item: { code: string; title: string | null }, locale: string) { if (item.title) return item.title; const n = names?.[`${kind}:${item.code}`]?.name; return n?.[locale] || n?.ru || item.code; } export function itemHint(names: RelocationNames | undefined, kind: 'STEP' | 'DOC', item: { code: string; title: string | null }, locale: string) { if (item.title) return null; const h = names?.[`${kind}:${item.code}`]?.hint; return h?.[locale] || h?.ru || null; }