import { Outlet, Link, createRootRoute, HeadContent, Scripts } from "@tanstack/react-router";
import appCss from "../styles.css?url";
import { ExitIntentModal } from "@/components/site/ExitIntentModal";
import { FloatingWhatsAppButton } from "@/components/site/FloatingWhatsAppButton";

function NotFoundComponent() {
  return (
    <div className="flex min-h-screen items-center justify-center bg-hero px-4">
      <div className="max-w-md text-center">
        <h1 className="text-7xl font-bold text-gradient-neon">404</h1>
        <h2 className="mt-4 text-xl font-semibold">Página não encontrada</h2>
        <p className="mt-2 text-sm text-muted-foreground">
          Esta página não existe ou foi movida.
        </p>
        <div className="mt-6">
          <Link to="/" className="inline-flex items-center justify-center rounded-md bg-gradient-primary px-5 py-3 text-sm font-semibold text-primary-foreground shadow-glow">
            Voltar ao início
          </Link>
        </div>
      </div>
    </div>
  );
}

export const Route = createRootRoute({
  head: () => ({
    meta: [
      { charSet: "utf-8" },
      { name: "viewport", content: "width=device-width, initial-scale=1" },
      { title: "Ararabot — Agente de IA no WhatsApp 24/7" },
      { name: "description", content: "Ararabot é o Agente de IA com CRM que atende, agenda e vende pelo WhatsApp 24/7. Reduz faltas em até 70% e recupera +10h por semana." },
      { name: "author", content: "Ararabot" },
      { name: "publisher", content: "Ararabot" },
      { name: "robots", content: "index, follow, max-image-preview:large, max-snippet:-1, max-video-preview:-1" },
      { name: "googlebot", content: "index, follow, max-image-preview:large, max-snippet:-1" },
      { name: "bingbot", content: "index, follow" },
      { name: "keywords", content: "agente de IA WhatsApp, chatbot WhatsApp, CRM WhatsApp, agendamento com IA, agendamento automático WhatsApp, lembretes automáticos WhatsApp, atendimento automático, vendas WhatsApp, IA para clínicas, IA para consultórios, automação WhatsApp, API oficial WhatsApp Meta, atendente virtual 24 horas, ararabot" },
      { name: "theme-color", content: "#3b0a4a" },
      { name: "color-scheme", content: "dark light" },
      { name: "format-detection", content: "telephone=yes" },
      { name: "geo.region", content: "BR" },
      { name: "geo.placename", content: "Brasil" },
      { httpEquiv: "Content-Language", content: "pt-BR" },
      { property: "og:site_name", content: "Ararabot" },
      { property: "og:title", content: "Ararabot — Agente de IA no WhatsApp 24/7" },
      { property: "og:description", content: "Ararabot é o Agente de IA com CRM que atende, agenda e vende pelo WhatsApp 24/7. Reduz faltas em até 70% e recupera +10h por semana." },
      { property: "og:type", content: "website" },
      { property: "og:locale", content: "pt_BR" },
      { property: "og:url", content: "https://ararabot.lovable.app/" },
      { property: "og:image", content: "https://ararabot.com.br/wp-content/uploads/2024/06/bot-conversa-chatbot-768x505.png" },
      { property: "og:image:alt", content: "Ararabot — Agente de IA para WhatsApp" },
      { property: "og:image:width", content: "768" },
      { property: "og:image:height", content: "505" },
      { name: "twitter:card", content: "summary_large_image" },
      { name: "twitter:site", content: "@ararabot" },
      { name: "twitter:title", content: "Ararabot — Agente de IA no WhatsApp 24/7" },
      { name: "twitter:description", content: "Ararabot é o Agente de IA com CRM que atende, agenda e vende pelo WhatsApp 24/7. Reduz faltas em até 70% e recupera +10h por semana." },
      { name: "twitter:image", content: "https://ararabot.com.br/wp-content/uploads/2024/06/bot-conversa-chatbot-768x505.png" },
      { name: "google-site-verification", content: "6OtRklJZ8e1ij4nC5PHy4ShwXnzS63IBWbrB_f-_Oxc" },
    ],
    links: [
      { rel: "stylesheet", href: appCss },
      { rel: "preconnect", href: "https://fonts.googleapis.com" },
      { rel: "preconnect", href: "https://fonts.gstatic.com", crossOrigin: "" },
      { rel: "dns-prefetch", href: "https://wa.me" },
      { rel: "stylesheet", href: "https://fonts.googleapis.com/css2?family=Alata&display=swap" },
      { rel: "alternate", hrefLang: "pt-BR", href: "https://ararabot.lovable.app/" },
      { rel: "alternate", hrefLang: "x-default", href: "https://ararabot.lovable.app/" },
    ],
    scripts: [
      { src: "https://www.googletagmanager.com/gtag/js?id=G-2D3R7E145S", async: true },
      {
        children: "window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments);}gtag('js',new Date());gtag('config','G-2D3R7E145S');",
      },
      { src: "https://www.googletagmanager.com/gtag/js?id=AW-18244867755", async: true },
      {
        children: "window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments);}gtag('js',new Date());gtag('config','AW-18244867755');",
      },
      {
        type: "application/ld+json",
        children: JSON.stringify({
          "@context": "https://schema.org",
          "@graph": [
            {
              "@type": "Organization",
              "@id": "https://ararabot.lovable.app/#organization",
              name: "Ararabot",
              alternateName: "Arara Bot",
              url: "https://ararabot.lovable.app",
              logo: {
                "@type": "ImageObject",
                url: "https://ararabot.com.br/wp-content/uploads/2024/06/bot-conversa-chatbot-768x505.png",
                width: 768,
                height: 505,
              },
              description: "Agentes de Inteligência Artificial com CRM integrado para atendimento, vendas e agendamentos automáticos no WhatsApp.",
              areaServed: { "@type": "Country", name: "Brasil" },
              contactPoint: [{
                "@type": "ContactPoint",
                telephone: "+55-54-98112-2381",
                contactType: "sales",
                areaServed: "BR",
                availableLanguage: ["Portuguese"],
              }],
              sameAs: [
                "https://ararabot.com.br",
                "https://www.instagram.com/ararabot.com.br",
                "https://ararabot.lovable.app/blog",
              ],
            },
            {
              "@type": "WebSite",
              "@id": "https://ararabot.lovable.app/#website",
              url: "https://ararabot.lovable.app/",
              name: "Ararabot",
              inLanguage: "pt-BR",
              publisher: { "@id": "https://ararabot.lovable.app/#organization" },
              potentialAction: {
                "@type": "SearchAction",
                target: "https://ararabot.lovable.app/?s={search_term_string}",
                "query-input": "required name=search_term_string",
              },
            },
          ],
        }),
      },
    ],
  }),
  shellComponent: RootShell,
  component: RootComponent,
  notFoundComponent: NotFoundComponent,
});

function RootShell({ children }: { children: React.ReactNode }) {
  return (
    <html lang="pt-BR">
      <head>
        <HeadContent />
      </head>
      <body>
        {children}
        <Scripts />
      </body>
    </html>
  );
}

function RootComponent() {
  return (
    <>
      <Outlet />
      <ExitIntentModal />
      <FloatingWhatsAppButton />
    </>
  );
}
