import type { LayoutLoad } from './$types';
import type { BreadcrumbItem } from '$lib/types/breadcrumbs';
import { m } from '$lib/paraglide/messages';

export const load: LayoutLoad = async ({ url }) => {
    const segments = url.pathname.split('/').filter(Boolean);
    const locale = segments[0] || 'de';
    
    // Label map for static route segments
    const labelMap: Record<string, string> = {
        'artikel': m.nav_artikel(),
        'neuigkeiten': m.nav_news(),
        'donauschwaben': m.nav_donauschwaben(),
        'ueber-uns': m.nav_about(),
        'organisationen': m.nav_org(),
        'kontakt': m.nav_contact(),
        'geschichte': m.nav_geschichte(),
        'kultur': m.nav_kultur(),
        'brauchtum': m.nav_brauchtum(),
        'tracht': m.nav_tracht(),
        'religion': m.nav_religion(),
        'kueche': m.nav_kueche(),
        'politik': m.nav_politik(),
        'persoenlichkeiten': m.nav_persoenlichkeiten(),
    };

    // Build breadcrumb items from URL segments
    const crumbs: BreadcrumbItem[] = [];
    
    // Skip locale, start from first content segment
    for (let i = 1; i < segments.length; i++) {
        const seg = segments[i];
        const pathSoFar = `/${segments.slice(0, i + 1).join('/')}`;
        
        // Use label map for known static segments
        const label = labelMap[seg] || seg;
        
        crumbs.push({
            label,
            href: pathSoFar
        });
    }

    return {
        breadcrumbs: { crumbs }
    };
};

export const prerender = true;
