dana-medical-site/web/src/lib/serviceNavigation.js
2026-10-14 13:33:13 +00:00

23 lines
1006 B
JavaScript

// Editorial direction/category associations, not automatic operation/price matches.
// Keep existing legacy slugs; a link is shown only while its destination is public.
export const DIRECTION_PRICE_SECTIONS = {
'detskaya-klinika': 'detskiy-price',
ginekologiya: 'gyne-price',
oko: 'oftalmologiya-price',
estetic: 'plasticheskaya_hirurgiya',
osteo: 'lech_bol',
proktologiya: 'proktologiya-price',
urologiya: 'urologiya-price',
khirurgiya: 'hirurgiya-price',
};
function flatten(tree) { return (tree || []).flatMap((s) => [s, ...flatten(s.children)]); }
export function servicePriceSection(path, prices) {
const slug = DIRECTION_PRICE_SECTIONS[path.split('/')[0]];
return slug ? flatten(prices).find((s) => s.slug === slug && s.items?.length > 0) : null;
}
export function priceDirection(slug, services) {
const path = Object.keys(DIRECTION_PRICE_SECTIONS).find((key) => DIRECTION_PRICE_SECTIONS[key] === slug);
return path ? (services || []).find((s) => s.path === path) : null;
}