import React from "react";

export default function SEOHead({ currentText = "Hello Instagram!" }) {
  const title = "FancyText | viral Fonts 🔥";

  const description =
    "Transform your Instagram & TikTok text in seconds. 30+ viral fonts. 100% free, mobile-ready & creator-approved. Copy & Paste.";

  const keywords =
    "fancy text generator, instagram fonts, tiktok fonts, whatsapp fonts, cool fonts, bio generator, fancy fonts, text generator, instagram bio, social media fonts, copy paste fonts, viral font styles";

  React.useEffect(() => {
    document.title = title;

    const setMetaTag = (name, content, property = false) => {
      const attr = property ? "property" : "name";
      let meta = document.querySelector(`meta[${attr}="${name}"]`);
      if (!meta) {
        meta = document.createElement("meta");
        meta.setAttribute(attr, name);
        document.head.appendChild(meta);
      }
      meta.setAttribute("content", content);
    };

    setMetaTag("description", description);
    setMetaTag("keywords", keywords);
    setMetaTag("viewport", "width=device-width, initial-scale=1.0, viewport-fit=cover");
    setMetaTag("theme-color", "#E91E63");
    setMetaTag("apple-mobile-web-app-capable", "yes");
    setMetaTag("apple-mobile-web-app-status-bar-style", "black-translucent");
    setMetaTag("apple-mobile-web-app-title", "FancyText");

    // Open Graph Tags (Social Sharing)
    setMetaTag("og:type", "website", true);
    setMetaTag("og:url", "https://yourdomain.com", true);
    setMetaTag("og:title", "FancyText 🔥 Make Your Text Stand Out on IG & TikTok", true);
    setMetaTag("og:description", "30+ copy-paste font styles used by top creators. Mobile optimized, always free. Try now.", true);
    setMetaTag("og:image", "https://deineseite.com/fancytextstuff_icon.png", true);

    // Twitter Tags
    setMetaTag("twitter:card", "summary_large_image", true);
    setMetaTag("twitter:url", "https://yourdomain.com", true);
    setMetaTag("twitter:title", title, true);
    setMetaTag("twitter:description", description, true);
    setMetaTag("twitter:image", "https://deineseite.com/fancytextstuff_icon.png", true);

    const addPreconnect = (href, crossorigin = false) => {
      if (!document.querySelector(`link[href="${href}"]`)) {
        const link = document.createElement("link");
        link.rel = "preconnect";
        link.href = href;
        if (crossorigin) link.crossOrigin = "anonymous";
        document.head.appendChild(link);
      }
    };

    addPreconnect("https://fonts.googleapis.com");
    addPreconnect("https://fonts.gstatic.com", true);

    const addStructuredData = () => {
      const existingScript = document.getElementById("structured-data");
      if (!existingScript) {
        const script = document.createElement("script");
        script.id = "structured-data";
        script.type = "application/ld+json";
        script.textContent = JSON.stringify({
          "@context": "https://schema.org",
          "@type": "WebApplication",
          name: "FancyText",
          headline: "Boost Your Instagram Look in 10 Seconds 🔥",
          alternativeHeadline: "30+ Viral Fonts – Copy & Paste Ready. Works Everywhere.",
          description: description,
          keywords: [
            "instagram fonts",
            "copy paste fonts",
            "fancy text generator",
            "tiktok fonts",
            "bio fonts",
            "cool font styles",
          ],
          url: "https://yourdomain.com",
          applicationCategory: "UtilitiesApplication",
          operatingSystem: "Any",
          offers: {
            "@type": "Offer",
            price: "0",
            priceCurrency: "USD",
          },
          author: {
            "@type": "Organization",
            name: "FancyText",
          },
        });
        document.head.appendChild(script);
      }
    };

    addStructuredData();
  }, [title, description]);

  return null;
}
