import "./global.css";

import { createRoot } from "react-dom/client";
import App from "./App";

// Add SEO meta tags
function addMetaTags() {
  // Charset
  const charset = document.querySelector('meta[charset]');
  if (!charset) {
    const meta = document.createElement("meta");
    meta.setAttribute("charset", "UTF-8");
    document.head.insertBefore(meta, document.head.firstChild);
  }

  // Viewport
  const viewport = document.querySelector('meta[name="viewport"]');
  if (!viewport) {
    const meta = document.createElement("meta");
    meta.setAttribute("name", "viewport");
    meta.setAttribute("content", "width=device-width, initial-scale=1.0");
    document.head.appendChild(meta);
  }

  // Theme color
  const themeColor = document.querySelector('meta[name="theme-color"]');
  if (!themeColor) {
    const meta = document.createElement("meta");
    meta.setAttribute("name", "theme-color");
    meta.setAttribute("content", "#154A8C");
    document.head.appendChild(meta);
  }

  // Apple touch icon
  const appleTouchIcon = document.querySelector('link[rel="apple-touch-icon"]');
  if (!appleTouchIcon) {
    const link = document.createElement("link");
    link.setAttribute("rel", "apple-touch-icon");
    link.setAttribute("href", "/placeholder.svg");
    document.head.appendChild(link);
  }

  // Canonical URL
  const canonical = document.querySelector('link[rel="canonical"]');
  if (!canonical) {
    const link = document.createElement("link");
    link.setAttribute("rel", "canonical");
    link.setAttribute("href", window.location.href);
    document.head.appendChild(link);
  }

  // Open Graph tags
  const ogType = document.querySelector('meta[property="og:type"]');
  if (!ogType) {
    const meta = document.createElement("meta");
    meta.setAttribute("property", "og:type");
    meta.setAttribute("content", "website");
    document.head.appendChild(meta);
  }

  const ogSiteName = document.querySelector('meta[property="og:site_name"]');
  if (!ogSiteName) {
    const meta = document.createElement("meta");
    meta.setAttribute("property", "og:site_name");
    meta.setAttribute("content", "Rawat Driving School");
    document.head.appendChild(meta);
  }

  // Twitter tags
  const twitterCard = document.querySelector('meta[name="twitter:card"]');
  if (!twitterCard) {
    const meta = document.createElement("meta");
    meta.setAttribute("name", "twitter:card");
    meta.setAttribute("content", "summary_large_image");
    document.head.appendChild(meta);
  }

  // Google verification (optional)
  const googleSiteVerification = document.querySelector(
    'meta[name="google-site-verification"]'
  );
  if (!googleSiteVerification) {
    const meta = document.createElement("meta");
    meta.setAttribute("name", "google-site-verification");
    meta.setAttribute("content", "");
    // document.head.appendChild(meta);
  }

  // Structured data (JSON-LD)
  const structuredData = document.querySelector('script[type="application/ld+json"]');
  if (!structuredData) {
    const script = document.createElement("script");
    script.setAttribute("type", "application/ld+json");
    script.textContent = JSON.stringify({
      "@context": "https://schema.org",
      "@type": "LocalBusiness",
      name: "Rawat Driving School",
      image: "/placeholder.svg",
      description:
        "Professional driving training school in Gurgaon, Sector 86. Learn driving in 15 days with expert instructors.",
      address: {
        "@type": "PostalAddress",
        addressLocality: "Gurgaon",
        addressRegion: "Haryana",
        postalCode: "122001",
        addressCountry: "IN",
        streetAddress: "Sector 86",
      },
      telephone: "+919876543210",
      email: "info@rawatdriving.com",
      priceRange: "₹2,999 - ₹6,399",
      areaServed: "Gurgaon, Haryana",
      serviceType: "Driving Training",
    });
    document.head.appendChild(script);
  }
}

addMetaTags();

createRoot(document.getElementById("root")!).render(<App />);
