/* ============================================================
   RUDRAA RATNA - SEO, schema, AEO answers, and safety copy
   ============================================================ */
(function(){
  const DEFAULT_BASE_URL = "https://rudraaratna.com";
  const SOCIAL_IMAGE = "/uploads/pasted-1780728491298-0.png";

  function cleanText(value){
    return String(value || "")
      .replace(/\s+/g, " ")
      .replace(/<[^>]*>/g, "")
      .trim();
  }

  function truncate(value, max){
    const text = cleanText(value);
    if(text.length <= max) return text;
    return text.slice(0, max - 1).replace(/\s+\S*$/, "") + "...";
  }

  function siteBase(){
    const raw = window.RR_SEO_BASE_URL || DEFAULT_BASE_URL;
    return String(raw).replace(/\/+$/, "");
  }

  function absUrl(path){
    if(!path) return siteBase() + "/";
    if(/^https?:\/\//i.test(path)) return path;
    if(/^data:/i.test(path)) return "";
    return siteBase() + (String(path).charAt(0) === "/" ? path : "/" + path);
  }

  function routePath(page, params){
    params = params || {};
    if(page === "shop") return "/shop";
    if(page === "product") return "/products/" + encodeURIComponent(params.id || "pyrite-bracelet");
    if(page === "consultation") return "/consultation";
    if(page === "pyrite-landing") return "/pyrite";
    if(page === "contact") return "/contact";
    return "/";
  }

  function href(page, params){
    return routePath(page, params || {});
  }

  function routeFromPath(pathname, search, hash){
    const qs = new URLSearchParams(search || "");
    const qp = qs.get("page");
    if(qp){
      if(qp === "product") return { page:"product", params:{ id:qs.get("id") || "pyrite-bracelet" } };
      if(["home","shop","consultation","pyrite-landing","contact"].includes(qp)) return { page:qp, params:{} };
    }

    const h = String(hash || "").replace(/^#\/?/, "");
    if(h){
      const parts = h.split("/").filter(Boolean);
      if(parts[0] === "products" && parts[1]) return { page:"product", params:{ id:decodeURIComponent(parts[1]) } };
      if(parts[0] === "shop") return { page:"shop", params:{} };
      if(parts[0] === "consultation") return { page:"consultation", params:{} };
      if(parts[0] === "pyrite-bracelet" || parts[0] === "pyrite") return { page:"pyrite-landing", params:{} };
      if(parts[0] === "contact") return { page:"contact", params:{} };
    }

    const parts = String(pathname || "").toLowerCase().split("/").filter(Boolean);
    const last = parts[parts.length - 1] || "";
    if(last.endsWith(".html")) return null;
    if(parts.includes("shop")) return { page:"shop", params:{} };
    const productIndex = parts.indexOf("products");
    if(productIndex >= 0 && parts[productIndex + 1]){
      return { page:"product", params:{ id:decodeURIComponent(parts[productIndex + 1]) } };
    }
    if(parts.includes("consultation")) return { page:"consultation", params:{} };
    if(parts.includes("pyrite-bracelet") || parts.includes("pyrite")) return { page:"pyrite-landing", params:{} };
    if(parts.includes("contact")) return { page:"contact", params:{} };
    return null;
  }

  function resolveInitialRoute(){
    const detected = routeFromPath(location.pathname, location.search, location.hash);
    if(detected) return detected;
    try{
      const stored = JSON.parse(sessionStorage.getItem("rr_route"));
      if(stored && stored.page) return stored;
    }catch(e){}
    return { page:"home", params:{} };
  }

  function pushRoute(page, params){
    try{
      if(location.protocol === "file:") return;
      const nextPath = routePath(page, params || {});
      if(location.pathname !== nextPath) history.pushState({ page:page, params:params || {} }, "", nextPath);
    }catch(e){}
  }

  const requiredAnswers = [
    {
      q:"What is a Pyrite Bracelet used for?",
      a:"A Pyrite Bracelet is traditionally worn as a prosperity, confidence, and focus accessory. Rudraa Ratna presents it as a spiritual and lifestyle product, not as a promised financial result."
    },
    {
      q:"Who should wear Citrine?",
      a:"Citrine is usually chosen by people seeking a bright symbol for confidence, positivity, self-expression, sales, study, or creative work. It is belief-based guidance, so personal judgement matters."
    },
    {
      q:"How to identify real Pyrite?",
      a:"Real Pyrite has a metallic golden lustre, natural weight, and small cubic flecks. Painted glass or coated beads often look flat, too bright, or unusually light. Rudraa Ratna can also verify photos on WhatsApp."
    },
    {
      q:"Is Rudraksha suitable for daily wear?",
      a:"5 Mukhi Rudraksha is traditionally considered suitable for daily wear by most people. Keep it clean, wear it respectfully, and ask for guidance if choosing rare mukhi beads."
    },
    {
      q:"How does Rudraa Ratna authenticate products?",
      a:"Rudraa Ratna checks material, appearance, weight, inclusions, product specification, and supplier documentation where applicable. Message on WhatsApp for current documentation details."
    },
    {
      q:"Do you provide a certificate of authenticity?",
      a:"Products marked certificate-ready should include product-specific documentation where applicable. Confirm documentation or authenticity-card details on WhatsApp before purchase."
    },
    {
      q:"How does the consultation work?",
      a:"You share your purpose, who the item is for, your experience level, and budget. Rudraa Ratna then recommends suitable Rudraksha, gemstones, crystals, or Vastu items through WhatsApp guidance."
    },
    {
      q:"How to contact Rudraa Ratna on WhatsApp?",
      a:"Use any green WhatsApp button on the site or message " + (window.RR ? RR.WA_DISPLAY : "+91 93191 74358") + ". Product and consultation buttons open a pre-filled WhatsApp message."
    }
  ];

  function answerByQuestion(q){
    return requiredAnswers.find(x => x.q === q);
  }

  function dedupeAnswers(list){
    const seen = {};
    return (list || []).filter(function(item){
      if(!item || !item.q || !item.a) return false;
      const key = cleanText(item.q).toLowerCase();
      if(seen[key]) return false;
      seen[key] = true;
      return true;
    });
  }

  function productAnswers(product){
    const p = product || {};
    const picks = [];
    if(p.stone === "pyrite" || /pyrite/i.test(p.name || "")){
      picks.push(answerByQuestion("What is a Pyrite Bracelet used for?"));
      picks.push(answerByQuestion("How to identify real Pyrite?"));
    }
    if(p.stone === "citrine" || /citrine/i.test(p.name || "")) picks.push(answerByQuestion("Who should wear Citrine?"));
    if(p.stone === "rudraksha" || /rudraksha/i.test(p.name || "")) picks.push(answerByQuestion("Is Rudraksha suitable for daily wear?"));
    picks.push(answerByQuestion("How does Rudraa Ratna authenticate products?"));
    picks.push(answerByQuestion("Do you provide a certificate of authenticity?"));
    (p.faqs || []).slice(0, 3).forEach(function(f){ picks.push(f); });
    return dedupeAnswers(picks);
  }

  const beforeBuyAnswers = [
    {
      q:"Before you buy a Pyrite Bracelet",
      a:"Check that the beads have natural metallic lustre, weight and small cubic flecks. Choose Pyrite as a traditional prosperity and confidence symbol, not as a promised financial result."
    },
    {
      q:"Before you buy a Citrine Bracelet",
      a:"Look for warm honey-to-amber tones, natural variation and a comfortable bead size. Citrine is often chosen for confidence and positivity, but it remains a spiritual/lifestyle product."
    },
    {
      q:"How to choose a crystal bracelet",
      a:"Start with your purpose, then check material, size, authenticity notes, care needs and whether you want daily wear or occasional use. If unsure, ask for WhatsApp guidance before buying."
    },
    {
      q:"Real vs fake crystal buying checklist",
      a:"Check weight, temperature, colour variation, inclusions, finish quality and seller documentation. Be cautious with stones that look too bright, too perfect, too light or painted."
    },
    {
      q:"Certificate and authenticity checklist",
      a:"For higher-value Rudraksha and gemstones, ask for certificate details, product specification, origin or treatment disclosure where relevant, and seller support if anything is unclear."
    },
    {
      q:"Which crystal is suitable for prosperity, protection, confidence, calm, love or focus?",
      a:"Pyrite and Green Aventurine are often chosen for prosperity, Black Tourmaline or Sulemani for protection, Citrine or Sunstone for confidence, Amethyst for calm, Rose Quartz for love, and Clear Quartz for focus."
    }
  ];

  function consultationAnswers(){
    return dedupeAnswers([
      answerByQuestion("How does the consultation work?"),
      answerByQuestion("Who should wear Citrine?"),
      answerByQuestion("Is Rudraksha suitable for daily wear?"),
      answerByQuestion("How to contact Rudraa Ratna on WhatsApp?")
    ]);
  }

  function contactAnswers(){
    return dedupeAnswers([
      answerByQuestion("How to contact Rudraa Ratna on WhatsApp?"),
      answerByQuestion("Do you provide a certificate of authenticity?"),
      answerByQuestion("How does Rudraa Ratna authenticate products?"),
      answerByQuestion("How does the consultation work?")
    ]);
  }

  function routeAnswers(route){
    route = route || { page:"home", params:{} };
    if(route.page === "product"){
      const product = RR.byId(route.params.id);
      return product ? productAnswers(product) : contactAnswers();
    }
    if(route.page === "consultation") return consultationAnswers();
    if(route.page === "contact") return contactAnswers();
    if(route.page === "pyrite-landing") return dedupeAnswers([
      answerByQuestion("What is a Pyrite Bracelet used for?"),
      answerByQuestion("How to identify real Pyrite?"),
      answerByQuestion("How does Rudraa Ratna authenticate products?"),
      answerByQuestion("Do you provide a certificate of authenticity?")
    ]);
    return requiredAnswers;
  }

  function productDescription(p){
    return truncate([p.tagline, p.whatItIs, p.whoFor].filter(Boolean).join(" "), 158);
  }

  function pageMeta(route){
    route = route || { page:"home", params:{} };
    const base = {
      robots:"index,follow,max-image-preview:large",
      image:absUrl(SOCIAL_IMAGE),
      imageAlt:"Rudraa Ratna authentic spiritual products and gemstone guidance",
      type:"website"
    };
    if(route.page === "shop"){
      return Object.assign({}, base, {
        title:"Shop Authentic Rudraksha, Gemstones, Crystals and Vastu | Rudraa Ratna",
        description:"Browse Rudraa Ratna products by purpose: Rudraksha, gemstones, crystals, Pyrite, Citrine, Vastu items, documentation where applicable, prices, and WhatsApp guidance.",
        canonical:absUrl("/shop")
      });
    }
    if(route.page === "product"){
      const p = RR.byId(route.params.id);
      if(!p){
        return Object.assign({}, base, {
          title:"Product Not Found | Rudraa Ratna",
          description:"This Rudraa Ratna product page could not be found. Browse the shop or message on WhatsApp for current availability and documentation where applicable.",
          canonical:absUrl(routePath("product", { id:route.params.id || "unknown-product" })),
          type:"website"
        });
      }
      return Object.assign({}, base, {
        title:p.name + " | Authentic " + p.catLabel + " | Rudraa Ratna",
        description:productDescription(p),
        canonical:absUrl(routePath("product", { id:p.id })),
        type:"product",
        image:p.image ? absUrl(p.image) : base.image,
        imageAlt:p.name + " from Rudraa Ratna"
      });
    }
    if(route.page === "consultation"){
      return Object.assign({}, base, {
        title:"Free Rudraksha, Gemstone and Crystal Consultation | Rudraa Ratna",
        description:"Get WhatsApp guidance before buying Rudraksha, gemstones, crystals, Pyrite, Citrine, or Vastu products from Rudraa Ratna.",
        canonical:absUrl("/consultation")
      });
    }
    if(route.page === "pyrite-landing"){
      const pyrite = RR.byId("pyrite-bracelet");
      return Object.assign({}, base, {
        title:"Pyrite Bracelet for Traditional Prosperity and Confidence | Rudraa Ratna",
        description:"Learn about natural Pyrite Bracelet use, authenticity checks, documentation where applicable, pricing, and WhatsApp guidance from Rudraa Ratna.",
        canonical:absUrl("/pyrite"),
        type:"product",
        image:pyrite && pyrite.image ? absUrl(pyrite.image) : base.image,
        imageAlt:"Pyrite Bracelet from Rudraa Ratna"
      });
    }
    if(route.page === "contact"){
      return Object.assign({}, base, {
        title:"Contact Rudraa Ratna Noida | WhatsApp, Store, Timings and Enquiry",
        description:"Contact Rudraa Ratna in Noida for Rudraksha, gemstones, crystals, Vastu items, consultation, WhatsApp support, and visit details.",
        canonical:absUrl("/contact")
      });
    }
    return Object.assign({}, base, {
      title:"Rudraa Ratna | Authentic Rudraksha, Gemstones and Crystals in Noida",
      description:"Rudraa Ratna offers guided buying for authentic Rudraksha, gemstones, crystals, Pyrite, Citrine, Vastu products, documentation where applicable, and WhatsApp consultation.",
      canonical:absUrl("/")
    });
  }

  function ensureMeta(attr, key){
    let el = document.head.querySelector("meta[" + attr + "=\"" + key + "\"]");
    if(!el){
      el = document.createElement("meta");
      el.setAttribute(attr, key);
      document.head.appendChild(el);
    }
    return el;
  }

  function setMeta(attr, key, content){
    ensureMeta(attr, key).setAttribute("content", content || "");
  }

  function setLink(rel, hrefValue){
    let el = document.head.querySelector("link[rel=\"" + rel + "\"]");
    if(!el){
      el = document.createElement("link");
      el.setAttribute("rel", rel);
      document.head.appendChild(el);
    }
    el.setAttribute("href", hrefValue);
  }

  function orgId(){ return absUrl("/#organization"); }
  function localId(){ return absUrl("/#localbusiness"); }
  function websiteId(){ return absUrl("/#website"); }

  function organizationSchema(){
    const schema = {
      "@type":"Organization",
      "@id":orgId(),
      "name":RR.settings.brandName,
      "url":absUrl("/"),
      "logo":absUrl(SOCIAL_IMAGE),
      "telephone":"+" + RR.WA_NUMBER,
      "contactPoint":[{
        "@type":"ContactPoint",
        "telephone":"+" + RR.WA_NUMBER,
        "contactType":"customer support",
        "areaServed":"IN",
        "availableLanguage":["en","hi"]
      }]
    };
    if(RR.settings.email) schema.email = RR.settings.email;
    return schema;
  }

  function localBusinessSchema(){
    const schema = {
      "@type":["LocalBusiness","Store"],
      "@id":localId(),
      "name":RR.settings.brandName,
      "url":absUrl("/"),
      "image":absUrl(SOCIAL_IMAGE),
      "telephone":"+" + RR.WA_NUMBER,
      "areaServed":"IN",
      "openingHoursSpecification":[{
        "@type":"OpeningHoursSpecification",
        "dayOfWeek":["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],
        "opens":"11:00",
        "closes":"20:00"
      }],
      "priceRange":"INR"
    };
    if(RR.settings.email) schema.email = RR.settings.email;
    if(RR.settings.addressConfirmed){
      schema.address = {
        "@type":"PostalAddress",
        "streetAddress":RR.settings.storeAddr,
        "addressLocality":RR.settings.storeCity,
        "addressRegion":"Uttar Pradesh",
        "addressCountry":"IN"
      };
    }
    return schema;
  }

  function websiteSchema(){
    return {
      "@type":"WebSite",
      "@id":websiteId(),
      "name":RR.settings.brandName,
      "url":absUrl("/"),
      "publisher":{"@id":orgId()}
    };
  }

  function breadcrumbSchema(items){
    if(!items || items.length < 2) return null;
    return {
      "@type":"BreadcrumbList",
      "itemListElement":items.map(function(item, index){
        return {
          "@type":"ListItem",
          "position":index + 1,
          "name":item.name,
          "item":item.url
        };
      })
    };
  }

  function breadcrumbItems(route){
    const home = { name:"Home", url:absUrl("/") };
    if(route.page === "shop") return [home, { name:"Shop", url:absUrl("/shop") }];
    if(route.page === "consultation") return [home, { name:"Consultation", url:absUrl("/consultation") }];
    if(route.page === "pyrite-landing") return [home, { name:"Pyrite Bracelet", url:absUrl("/pyrite") }];
    if(route.page === "contact") return [home, { name:"Contact", url:absUrl("/contact") }];
    if(route.page === "product"){
      const p = RR.byId(route.params.id);
      if(!p) return [
        home,
        { name:"Shop", url:absUrl("/shop") },
        { name:"Product Not Found", url:absUrl(routePath("product", { id:route.params.id || "unknown-product" })) }
      ];
      return [
        home,
        { name:"Shop", url:absUrl("/shop") },
        { name:p.catLabel, url:absUrl("/shop") },
        { name:p.name, url:absUrl(routePath("product", { id:p.id })) }
      ];
    }
    return [];
  }

  function faqSchema(answers){
    if(!answers || !answers.length) return null;
    return {
      "@type":"FAQPage",
      "mainEntity":answers.map(function(item){
        return {
          "@type":"Question",
          "name":cleanText(item.q),
          "acceptedAnswer":{
            "@type":"Answer",
            "text":cleanText(item.a)
          }
        };
      })
    };
  }

  function offerSchema(p){
    if(!p || !p.price) return null;
    return {
      "@type":"Offer",
      "url":absUrl(routePath("product", { id:p.id })),
      "priceCurrency":"INR",
      "price":String(p.price),
      "availability":"https://schema.org/InStock",
      "seller":{"@id":orgId()}
    };
  }

  function productSchema(p){
    if(!p) return null;
    const schema = {
      "@type":"Product",
      "@id":absUrl(routePath("product", { id:p.id })) + "#product",
      "name":p.name,
      "description":productDescription(p),
      "sku":p.id,
      "brand":{"@id":orgId()},
      "category":p.catLabel,
      "material":p.origin || p.stone,
      "offers":offerSchema(p)
    };
    if(p.image && !/^data:/i.test(p.image)) schema.image = absUrl(p.image);
    return schema;
  }

  function shopSchema(){
    return {
      "@type":"CollectionPage",
      "@id":absUrl("/shop#collection"),
      "name":"Rudraa Ratna product collection",
      "url":absUrl("/shop"),
      "isPartOf":{"@id":websiteId()},
      "mainEntity":{
        "@type":"ItemList",
        "itemListElement":RR.PRODUCTS.map(function(p, index){
          return {
            "@type":"ListItem",
            "position":index + 1,
            "url":absUrl(routePath("product", { id:p.id })),
            "name":p.name
          };
        })
      }
    };
  }

  function serviceSchema(){
    return {
      "@type":"Service",
      "@id":absUrl("/consultation#service"),
      "name":"Rudraa Ratna product consultation",
      "serviceType":"Guided Rudraksha, gemstone, crystal, and Vastu product consultation",
      "provider":{"@id":orgId()},
      "areaServed":"IN",
      "availableChannel":{
        "@type":"ServiceChannel",
        "serviceUrl":absUrl("/consultation"),
        "servicePhone":"+" + RR.WA_NUMBER
      }
    };
  }

  function webPageSchema(route, meta){
    const names = {
      home:"Home",
      shop:"Shop",
      product:"Product",
      consultation:"Consultation",
      "pyrite-landing":"Pyrite Bracelet",
      contact:"Contact"
    };
    return {
      "@type":route.page === "contact" ? "ContactPage" : "WebPage",
      "@id":meta.canonical + "#webpage",
      "url":meta.canonical,
      "name":names[route.page] || "Home",
      "description":meta.description,
      "isPartOf":{"@id":websiteId()},
      "about":{"@id":orgId()}
    };
  }

  function schemasForRoute(route, meta){
    const graph = [organizationSchema(), localBusinessSchema(), websiteSchema(), webPageSchema(route, meta)];
    const crumbs = breadcrumbSchema(breadcrumbItems(route));
    if(crumbs) graph.push(crumbs);

    if(route.page === "shop") graph.push(shopSchema());
    if(route.page === "product"){
      const product = RR.byId(route.params.id);
      if(product) graph.push(productSchema(product));
      graph.push(faqSchema(routeAnswers(route)));
    }
    if(route.page === "consultation"){
      graph.push(serviceSchema());
      graph.push(faqSchema(routeAnswers(route)));
    }
    if(route.page === "contact") graph.push(faqSchema(routeAnswers(route)));
    if(route.page === "pyrite-landing"){
      graph.push(productSchema(RR.byId("pyrite-bracelet")));
      graph.push(faqSchema(routeAnswers(route)));
    }
    if(route.page === "home") graph.push(faqSchema(routeAnswers(route)));
    return graph.filter(Boolean);
  }

  function updateJsonLd(route, meta){
    let el = document.getElementById("rr-jsonld");
    if(!el){
      el = document.createElement("script");
      el.type = "application/ld+json";
      el.id = "rr-jsonld";
      document.head.appendChild(el);
    }
    el.text = JSON.stringify({
      "@context":"https://schema.org",
      "@graph":schemasForRoute(route, meta)
    });
  }

  function applySeo(route){
    const meta = pageMeta(route);
    document.title = meta.title;
    setMeta("name", "description", meta.description);
    setMeta("name", "robots", meta.robots);
    setLink("canonical", meta.canonical);
    setMeta("property", "og:site_name", RR.settings.brandName);
    setMeta("property", "og:title", meta.title);
    setMeta("property", "og:description", meta.description);
    setMeta("property", "og:type", meta.type);
    setMeta("property", "og:url", meta.canonical);
    if(meta.image) setMeta("property", "og:image", meta.image);
    setMeta("property", "og:image:alt", meta.imageAlt);
    setMeta("name", "twitter:card", "summary_large_image");
    setMeta("name", "twitter:title", meta.title);
    setMeta("name", "twitter:description", meta.description);
    if(meta.image) setMeta("name", "twitter:image", meta.image);
    updateJsonLd(route, meta);
  }

  function usePageSeo(route){
    useEffect(function(){
      applySeo(route);
    }, [route.page, JSON.stringify(route.params || {})]);
  }

  function AeoAnswerSection({ eyebrow="Quick Answers", title="Clear answers before you choose", intro, answers }){
    const list = dedupeAnswers(answers || requiredAnswers);
    return (
      <section className="answer-sec">
        <div className="wrap">
          <Reveal className="section-head center">
            <span className="eyebrow no-rule">{eyebrow}</span>
            <h2 className="h2">{title}</h2>
            {intro && <p>{intro}</p>}
          </Reveal>
          <div className="answer-grid mt8">
            {list.map(function(item, index){
              return (
                <Reveal key={item.q} className="answer-card" delay={Math.min(index * 0.04, 0.24)}>
                  <h3 className="h3">{item.q}</h3>
                  <p>{item.a}</p>
                </Reveal>
              );
            })}
          </div>
        </div>
      </section>
    );
  }

  function GuideImage({ item }){
    if(item.image){
      return <img className="guide-img" src={rrImgSrc(item.image)} alt={`${item.name} crystal image - Rudraa Ratna`} loading="lazy" decoding="async"/>;
    }
    return <GemArt stone={item.id || 'pyrite'} form="bracelet" size={112}/>;
  }

  function CrystalGuideSection({ limit }){
    const allGuides = RR.CRYSTAL_GUIDES || [];
    const guides = allGuides.slice(0, limit || allGuides.length);
    return (
      <section className="crystal-guide-sec">
        <div className="wrap">
          <Reveal className="section-head center">
            <span className="eyebrow no-rule">Crystal Buying Guide</span>
            <h2 className="h2">Choose by purpose, authenticity and care</h2>
            <p>Short, buyer-friendly answers for the crystals Rudraa Ratna can guide you on. These are traditional associations, not fixed outcomes.</p>
          </Reveal>
          <div className="crystal-guide-grid mt8">
            {guides.map(function(item, index){
              return (
                <Reveal key={item.id} className="crystal-guide-card" delay={Math.min(index * 0.035, 0.24)}>
                  <div className="crystal-guide-card__media"><GuideImage item={item}/></div>
                  <div className="crystal-guide-card__body">
                    <h3 className="h3">{item.name}</h3>
                    <p className="guide-direct">{item.direct}</p>
                    <dl className="guide-facts">
                      <div><dt>What it is</dt><dd>{item.whatItIs}</dd></div>
                      <div><dt>Often chosen by</dt><dd>{item.chosenBy}</dd></div>
                      <div><dt>Association</dt><dd>{item.association}</dd></div>
                      <div><dt>Use & care</dt><dd>{item.useCare}</dd></div>
                      <div><dt>Authenticity</dt><dd>{item.authenticity}</dd></div>
                    </dl>
                    <a className="link-underline" href={RR.wa(item.cta)} target="_blank" rel="noopener"><WaGlyph size={15}/> Ask on WhatsApp</a>
                  </div>
                </Reveal>
              );
            })}
          </div>
        </div>
      </section>
    );
  }

  function BeforeYouBuySection(){
    return (
      <AeoAnswerSection
        eyebrow="Best Before You Buy"
        title="Answers customers need before choosing"
        intro="Clear buying guidance helps people and AI systems understand what Rudraa Ratna sells, how it verifies products, and where claims are belief-based."
        answers={beforeBuyAnswers}
      />
    );
  }

  function WhyRudraaSection(){
    const points = [
      { t:"Guided buying, not random shopping", d:"Customers can share their purpose and get human WhatsApp guidance before choosing." },
      { t:"Authenticity-first education", d:"Pages explain real-vs-fake checks, certificates and care details in visible content." },
      { t:"Real product photos where available", d:"Mapped crystal products use real image assets, with procedural visuals kept only as fallback." },
      { t:"Certificate-ready presentation", d:"Product pages show specification, origin/material and certificate language where relevant." },
      { t:"WhatsApp-first support", d:"Every major journey keeps a direct route to human consultation and product questions." },
      { t:"Spiritual/lifestyle safety", d:"Rudraa avoids medical, financial, legal or fixed-result claims." },
      { t:"Premium experience", d:"The interface stays calm, elegant and consultation-led rather than marketplace-heavy." },
    ];
    return (
      <section className="why-rudraa-sec">
        <div className="wrap why-rudraa">
          <Reveal className="section-head">
            <span className="eyebrow">Why Rudraa Ratna?</span>
            <h2 className="h2">Premium guidance for a personal choice</h2>
            <p>Rudraa Ratna is built for customers who want clarity before they buy: real product information, careful language and direct support.</p>
          </Reveal>
          <div className="why-rudraa__grid">
            {points.map(function(point, index){
              return (
                <Reveal key={point.t} className="why-rudraa__item" delay={Math.min(index * 0.05, 0.25)}>
                  <span className="why-rudraa__num">{String(index + 1).padStart(2, "0")}</span>
                  <div><h3>{point.t}</h3><p>{point.d}</p></div>
                </Reveal>
              );
            })}
          </div>
        </div>
      </section>
    );
  }

  function TrustDisclaimer(){
    return (
      <section className="trust-disclaimer">
        <div className="wrap trust-disclaimer__in">
          <span className="trust-disclaimer__mark"><Icon name="shield" size={22}/></span>
          <p><b>Trust and safety note:</b> Gemstone, Rudraksha, crystal, and spiritual products are sold as traditional, spiritual, and lifestyle items. Rudraa Ratna does not make medical, financial, legal, or fixed-result claims. Please use personal judgement and consult qualified professionals where needed.</p>
        </div>
      </section>
    );
  }

  function PageAnswers({ page, product }){
    const route = page === "product"
      ? { page:"product", params:{ id:product && product.id } }
      : { page:page || "home", params:{} };
    const titles = {
      home:"Popular questions about Rudraa Ratna products",
      shop:"Answers before you choose a product",
      product:"Product answers and authenticity notes",
      consultation:"Answers about consultation",
      "pyrite-landing":"Pyrite Bracelet answers",
      contact:"Contact and support answers"
    };
    return <AeoAnswerSection title={titles[route.page] || titles.home} answers={routeAnswers(route)}/>;
  }

  window.RRSEO = {
    DEFAULT_BASE_URL,
    SOCIAL_IMAGE,
    requiredAnswers,
    cleanText,
    truncate,
    absUrl,
    routePath,
    href,
    resolveInitialRoute,
    pushRoute,
    pageMeta,
    applySeo,
    usePageSeo,
    routeAnswers,
    productAnswers
  };

  Object.assign(window, { AeoAnswerSection, PageAnswers, TrustDisclaimer, CrystalGuideSection, BeforeYouBuySection, WhyRudraaSection });
})();
