"use client"

import { useLanguage } from "@/lib/language-context";
import { usePathname } from "next/navigation";

export const JsonLd = () => {
    const { language } = useLanguage();
    const pathname = usePathname();

    const businessData = {
        "@context": "https://schema.org",
        "@type": "TransportationService",
        "name": "SkyFly Travel",
        "image": "https://skyflytravel.hu/images/hero-main.jpg",
        "@id": "https://skyflytravel.hu/#organization",
        "url": "https://skyflytravel.hu",
        "telephone": "+36305543838",
        "priceRange": "$$",
        "address": {
            "@type": "PostalAddress",
            "streetAddress": "Ipar u. 78.",
            "addressLocality": "Győr",
            "postalCode": "9023",
            "addressCountry": "HU"
        },
        "geo": {
            "@type": "GeoCoordinates",
            "latitude": 47.6833,
            "longitude": 17.6333
        },
        "areaServed": [
            { "@type": "City", "name": "Győr" },
            { "@type": "City", "name": "Budapest" },
            { "@type": "City", "name": "Vienna" },
            { "@type": "City", "name": "Bratislava" }
        ],
        "aggregateRating": {
            "@type": "AggregateRating",
            "ratingValue": "5.0",
            "reviewCount": "292",
            "bestRating": "5",
            "worstRating": "1"
        }
    };

    const pathParts = pathname.split('/').filter(Boolean);
    const breadcrumbs = {
        "@context": "https://schema.org",
        "@type": "BreadcrumbList",
        "itemListElement": [
            {
                "@type": "ListItem",
                "position": 1,
                "name": language === "hu" ? "Kezdőlap" : "Home",
                "item": "https://skyflytravel.hu"
            },
            ...pathParts.map((part, index) => ({
                "@type": "ListItem",
                "position": index + 2,
                "name": part.charAt(0).toUpperCase() + part.slice(1).replace(/-/g, ' '),
                "item": `https://skyflytravel.hu/${pathParts.slice(0, index + 1).join('/')}/`
            }))
        ]
    };

    return (
        <>
            <script
                type="application/ld+json"
                dangerouslySetInnerHTML={{ __html: JSON.stringify(businessData) }}
            />
            <script
                type="application/ld+json"
                dangerouslySetInnerHTML={{ __html: JSON.stringify(breadcrumbs) }}
            />
        </>
    );
};
