/**
 * SEO / meta: site-wide defaults, page-meta type, and merge helper.
 * Layout renders <head> from merged meta; each route can export meta from +page.ts.
 */

export const SEO_DEFAULTS = {
    siteName: 'mifi Ventures',
    baseUrl: 'https://mifi.ventures',
    defaultOgImage: '/assets/og-image.png',
    ogImageWidth: 1200,
    ogImageHeight: 630,
    locale: 'en_US',
    twitterCard: 'summary_large_image' as const,
    themeColorLight: '#0052cc',
    themeColorDark: '#4da6ff',
} as const;

export interface PageMeta {
    title: string;
    description?: string;
    canonical?: string;
    ogImage?: string;
    ogType?: string;
    twitterTitle?: string;
    twitterDescription?: string;
    /** JSON-LD graph nodes (merged with defaults in layout) */
    jsonLd?: Record<string, unknown>[];
}

export interface MergedMeta extends PageMeta {
    canonical: string;
    ogImage: string;
    ogImageAlt: string;
    jsonLdGraph: Record<string, unknown>[];
}

/** Merge page meta with site defaults for rendering. */
export function mergeMeta(meta: PageMeta, path: string = '/'): MergedMeta {
    const baseUrl = SEO_DEFAULTS.baseUrl;
    const canonical = meta.canonical ?? `${baseUrl}${path === '/' ? '' : path}`;
    const ogImage = meta.ogImage?.startsWith('http')
        ? meta.ogImage
        : `${baseUrl}${meta.ogImage?.startsWith('/') ? meta.ogImage : SEO_DEFAULTS.defaultOgImage}`;
    const ogImageAlt = meta.title;
    const jsonLdGraph = meta.jsonLd ?? [];
    return {
        ...meta,
        canonical,
        ogImage,
        ogImageAlt,
        jsonLdGraph,
    };
}
