import { resolveSection, type PublicSettings, type PublicSitePayload, type SectionKey, type SiteSections, } from "@montech/shared"; const SITE_KEY = "public-site"; export const DEFAULT_SETTINGS: PublicSettings = { brandName: "منتک", tagline: "هوش‌افزار منظر", email: "info@montech.ir", phone: "۰۹۱۲ ۳۴۵ ۶۷۸۹", address: "تهران، ایران", timezone: "Asia/Tehran", socials: [], logoUrl: null, }; /** * Loads the public site payload once per request (called from the default layout). * A failed API call degrades to the built-in default content instead of breaking the page. */ export function loadSiteContent() { return useAsyncData(SITE_KEY, () => apiFetch("/api/public/site").catch(() => null)); } export function useSiteContent() { const { data } = useNuxtData(SITE_KEY); const settings = computed(() => { const s = data.value?.settings; if (!s) return DEFAULT_SETTINGS; return { ...DEFAULT_SETTINGS, ...Object.fromEntries(Object.entries(s).filter(([, v]) => v !== "" && v !== null && v !== undefined)), socials: Array.isArray(s.socials) ? s.socials.filter((x) => x && x.url) : [], logoUrl: s.logoUrl || null, }; }); function section(key: K) { return computed(() => resolveSection(key, data.value?.sections?.[key])); } function pageSeo(key: string) { return computed(() => data.value?.pages?.find((p) => p.key === key)?.seo ?? null); } return { data, settings, section, pageSeo }; }