import type { Niche } from '../runtime'; import { NicheHelper } from '../utils/niche-helper'; /** Иконка из assets/icons/common под каждую нишу. */ const NICHE_ICONS: Record = { straight: 'hetero', gay: 'gay', shemale: 'shemale', }; export interface INicheItem { name: Niche, icon: string, /** Ключ i18n с названием ниши */ label: string, } /** * Ниши сайта для переключателя: список из per-site конфига проекта (appConfig.niches), * текущая — из useState('niche') с фолбэком на дефолтную нишу окружения. */ export const useNiches = () => { const defaultNiche = NicheHelper.getSiteDefaultNiche(); const current = useState('niche', () => defaultNiche); const localePath = useLocalePath(); const niches = computed(() => ((useAppConfig().niches as Niche[]) || []).map(name => ({ name, icon: NICHE_ICONS[name] || 'earth', label: `niches.${name}`, }))); const currentNiche = computed(() => niches.value.find(item => item.name === current.value) || niches.value[0]); /** * Ниша влияет и на роутинг (префикс пути), и на заголовок X-Niche в SSR-запросах, * поэтому переключение — полной перезагрузкой на корень выбранной ниши. */ function changeNiche(name: Niche) { if (name === current.value) return; current.value = name; window.location.href = localePath(name === defaultNiche ? '/' : `/${name}`); } return { niches, currentNiche, changeNiche }; };