"use client";

import Script from "next/script";

type JsonLdSchemasProps = {
  lang: "es" | "en";
};

const ORG_ID = "https://sitemente.com/#organization";
const LOCAL_ID = "https://sitemente.com/#localbusiness";
const SERVICES_ID = "https://sitemente.com/#services";
const FAQ_ID = "https://sitemente.com/#faq";

export default function JsonLdSchemas({ lang }: JsonLdSchemasProps) {
  const isEs = lang === "es";

  const organization = {
    "@context": "https://schema.org",
    "@type": "Organization",
    "@id": ORG_ID,
    name: "SiteMente",
    url: "https://sitemente.com",
    logo: "https://sitemente.com/logo.png",
    description: isEs
      ? "Agencia de implementación de IA para negocios locales en España. Especialistas en chatbots, automatización y sitios web inteligentes."
      : "AI implementation agency for local businesses in Spain. Specialists in chatbots, automation and smart websites.",
    email: "hola@sitemente.com",
    foundingDate: "2025",
    parentOrganization: {
      "@type": "Organization",
      name: "HolaCompi",
    },
    areaServed: {
      "@type": "Country",
      name: "España",
    },
  };

  const localBusiness = {
    "@context": "https://schema.org",
    "@type": "ProfessionalService",
    "@id": LOCAL_ID,
    name: "SiteMente - Agencia de IA Málaga",
    url: "https://sitemente.com",
    priceRange: "€€€",
    address: {
      "@type": "PostalAddress",
      addressLocality: "Málaga",
      addressRegion: "Andalucía",
      addressCountry: "ES",
    },
    geo: {
      "@type": "GeoCoordinates",
      latitude: 36.7213,
      longitude: -4.4214,
    },
    areaServed: [
      { "@type": "Place", name: "Málaga" },
      { "@type": "Place", name: "Marbella" },
      { "@type": "Place", name: "Benalmádena" },
      { "@type": "Place", name: "Costa del Sol" },
    ],
    parentOrganization: { "@id": ORG_ID },
  };

  const serviceDescriptions = isEs
    ? [
        {
          name: "Smart Starter - AI Chat + Reservas Automatizadas",
          description:
            "Chat IA para sitio web con reservas automatizadas, captura de leads y análisis básicos.",
          audience: "Restaurantes, clínicas, negocios locales",
          price: 299,
        },
        {
          name: "Smart Site - Web Inteligente Completa",
          description:
            "Sitio web Next.js completo con IA integrada que vende, reserva y da soporte en español e inglés.",
          audience: "Negocios listos para una web moderna",
          price: 749,
        },
        {
          name: "AI Growth Partner",
          description:
            "Partner estratégico de IA: multicanal (web, WhatsApp, llamadas), integraciones CRM.",
          audience: "Grupos de restaurantes, inmobiliarias, cadenas de alquiler",
          price: 1950,
        },
      ]
    : [
        {
          name: "Smart Starter - AI Chat + Automated Bookings",
          description:
            "AI website chat with automated bookings, lead capture, and basic analytics.",
          audience: "Restaurants, clinics, local businesses",
          price: 299,
        },
        {
          name: "Smart Site - Full Smart Website",
          description:
            "Complete Next.js website with integrated AI that sells, books, and supports in Spanish and English.",
          audience: "Businesses ready for a modern website",
          price: 749,
        },
        {
          name: "AI Growth Partner",
          description:
            "Strategic AI partner: multichannel (web, WhatsApp, calls), CRM integrations.",
          audience: "Restaurant groups, real estate teams, rental chains",
          price: 1950,
        },
      ];

  const services = {
    "@context": "https://schema.org",
    "@type": "ItemList",
    "@id": SERVICES_ID,
    itemListElement: serviceDescriptions.map((service, index) => ({
      "@type": "ListItem",
      position: index + 1,
      item: {
        "@type": "Service",
        name: service.name,
        description: service.description,
        serviceAudience: service.audience,
        provider: { "@id": ORG_ID },
        areaServed: { "@type": "Country", name: "España" },
        offers: {
          "@type": "Offer",
          priceCurrency: "EUR",
          price: service.price,
          priceSpecification: {
            "@type": "UnitPriceSpecification",
            priceCurrency: "EUR",
            price: service.price,
            unitText: isEs ? "mes" : "month",
          },
        },
      },
    })),
  };

  const faq = {
    "@context": "https://schema.org",
    "@type": "FAQPage",
    "@id": FAQ_ID,
    mainEntity: isEs
      ? [
          {
            "@type": "Question",
            name: "¿Qué es la implementación de IA para negocios?",
            acceptedAnswer: {
              "@type": "Answer",
              text: "La implementación de IA para negocios significa instalar agentes inteligentes (chatbots, asistentes de voz, automatizaciones) en tu sitio web para que respondan preguntas, tomen reservas y vendan 24/7 sin intervención humana.",
            },
          },
          {
            "@type": "Question",
            name: "¿Cuánto cuesta implementar IA en mi negocio en España?",
            acceptedAnswer: {
              "@type": "Answer",
              text: "Nuestros planes comienzan desde 900€ de instalación + 299€/mes para chat IA básico, hasta planes completos desde 3.500€ + 749€/mes con sitio web nuevo.",
            },
          },
          {
            "@type": "Question",
            name: "¿Por qué necesito IA en mi sitio web en 2026?",
            acceptedAnswer: {
              "@type": "Answer",
              text: "El 95% de las interacciones con clientes involucran IA. Los negocios con chatbots aumentan ventas en 67% de media y reducen costes de soporte en 30%.",
            },
          },
        ]
      : [
          {
            "@type": "Question",
            name: "What is AI implementation for businesses?",
            acceptedAnswer: {
              "@type": "Answer",
              text: "AI implementation for businesses means installing intelligent agents (chatbots, voice assistants, automations) on your website so they answer questions, take bookings, and sell 24/7 without human intervention.",
            },
          },
          {
            "@type": "Question",
            name: "How much does it cost to implement AI in my business in Spain?",
            acceptedAnswer: {
              "@type": "Answer",
              text: "Our plans start from a €900 setup + €299/month for basic AI chat, up to complete packages from €3,500 + €749/month with a new website.",
            },
          },
          {
            "@type": "Question",
            name: "Why do I need AI on my website in 2026?",
            acceptedAnswer: {
              "@type": "Answer",
              text: "95% of customer interactions involve AI. Businesses with chatbots increase sales by an average of 67% and reduce support costs by 30%.",
            },
          },
        ],
  };

  return (
    <>
      <Script
        id="jsonld-organization"
        type="application/ld+json"
        strategy="beforeInteractive"
        dangerouslySetInnerHTML={{ __html: JSON.stringify(organization) }}
      />
      <Script
        id="jsonld-localbusiness"
        type="application/ld+json"
        strategy="beforeInteractive"
        dangerouslySetInnerHTML={{ __html: JSON.stringify(localBusiness) }}
      />
      <Script
        id="jsonld-services"
        type="application/ld+json"
        strategy="beforeInteractive"
        dangerouslySetInnerHTML={{ __html: JSON.stringify(services) }}
      />
      <Script
        id="jsonld-faq"
        type="application/ld+json"
        strategy="beforeInteractive"
        dangerouslySetInnerHTML={{ __html: JSON.stringify(faq) }}
      />
    </>
  );
}
