import { NavigationResponse } from "@/types/navigation";

/**
 * Used only when the Joomla API is unreachable (network outage, local Joomla
 * instance down, etc.) so the app still renders a working header/footer with
 * the current brand's real contact details instead of an error page.
 */

const getWhatsappUrl = (phone: string, message: string = "I need help in assignment! Can you help me?") => {
  const cleanPhone = phone.replace(/[^0-9]/g, "");
  return `https://api.whatsapp.com/send?phone=${encodeURIComponent(cleanPhone)}&text=${encodeURIComponent(message)}`;
};

const getCpanelUrl = (path: string = "") => {
  const baseUrl = process.env.NEXT_PUBLIC_CPANEL_URL || "https://customerpanel.globalassignmenthelp.com";
  if (path.startsWith("http://") || path.startsWith("https://")) return path;
  return `${baseUrl}${path.startsWith("/") ? "" : "/"}${path}`;
};

export const getFallbackNavigationData = (): NavigationResponse => {
  const whatsappNum = process.env.NEXT_PUBLIC_WHATSAPP_NUM || "+44 7575438880";
  const phoneNum = process.env.NEXT_PUBLIC_PHONE_NUM || "+44 7575438880";
  const emailAddr = process.env.NEXT_PUBLIC_EMAIL || "help@globalassignmenthelp.com";

  return {
    header: {
      topBar: {
        whatsappNumber: whatsappNum,
        whatsappUrl: getWhatsappUrl(whatsappNum),
        phone: phoneNum,
        email: emailAddr,
        announcement: {
          discountBadge: "OFFER!",
          ctaText: "Save 56%",
          ctaHref: getCpanelUrl("/order"),
          text: "on Assignment Crafted by Human Writers",
        },
      },
      mainNav: [
        { id: "services", label: "Services", href: "/services", hasSubmenu: false },
        { id: "samples", label: "Free Samples", href: "/free-samples", hasSubmenu: false },
        { id: "answers", label: "Answers", href: "/answers", hasSubmenu: false },
        { id: "blog", label: "Blogs", href: "/blog", hasSubmenu: false },
      ],
      popularSearches: [
        { label: "Order an assignment", href: getCpanelUrl("/order") },
        { label: "Free Samples", href: "/free-samples" },
        { label: "Answers", href: "/answers" },
      ],
      cta: {
        orderNowUrl: getCpanelUrl("/order"),
        loginUrl: getCpanelUrl("/login"),
        cartCount: 0,
        cartUrl: getCpanelUrl("/cart"),
        earnOnlineUrl: "/affiliate",
      },
    },
    footer: {
      columns: {
        topSearches: {
          id: "top-searches",
          title: "Top Assignment Searches",
          links: [
            { label: "Assignment Writing Service", href: "/do-my-assignment" },
            { label: "Essay Writing Service", href: "/essay-writing-help" },
            { label: "Dissertation Writing Service", href: "/dissertation-help" },
          ],
        },
        // "Get to know us" — real, hardcoded directly in the live footer
        // module's HTML (`JM_modules` id 111, "Custom Footer", position
        // `user1`), not menu-API-driven, so this is genuinely the primary
        // source rather than a network-outage stand-in — same status as
        // `ALIAS_BANNER_TEXT` elsewhere in this app.
        company: {
          id: "get-to-know-us",
          title: "Get to know us",
          links: [
            { label: "About us", href: "/about-us" },
            { label: "Reviews", href: "/reviews" },
            { label: "Experts", href: "/writers" },
            { label: "Blog", href: "/blog" },
            { label: "FAQ", href: "/faq" },
            { label: "Our Offers", href: "/offers" },
          ],
        },
        // "Country" — also real, hardcoded in the same module, each country
        // expanding to its own real per-city links.
        countries: {
          id: "countries",
          title: "Country",
          items: [
            {
              label: "United Kingdom",
              href: "/uk",
              cities: [
                { label: "Winchester", href: "/uk/assignment-help-winchester" },
                { label: "Manchester", href: "/uk/assignment-help-manchester" },
                { label: "Bristol", href: "/uk/assignment-help-bristol" },
                { label: "Cardiff", href: "/uk/assignment-help-cardiff" },
                { label: "Glasgow", href: "/uk/assignment-help-glasgow" },
                { label: "London", href: "/uk/assignment-help-london" },
                { label: "Nottingham", href: "/uk/assignment-help-nottingham" },
                { label: "Birmingham", href: "/uk/assignment-help-birmingham" },
                { label: "Liverpool", href: "/uk/assignment-help-liverpool" },
                { label: "Oxford", href: "/uk/assignment-help-oxford" },
                { label: "Leeds", href: "/uk/assignment-help-leeds" },
              ],
            },
            {
              label: "United States",
              href: "/us",
              cities: [
                { label: "New York", href: "/us/assignment-help-new-york" },
                { label: "Washington", href: "/us/assignment-help-washington" },
                { label: "Los Angeles", href: "/us/assignment-help-los-angeles" },
                { label: "Houston", href: "/us/assignment-help-houston" },
                { label: "Chicago", href: "/us/assignment-help-chicago" },
              ],
            },
            {
              label: "Australia",
              href: "/au",
              cities: [
                { label: "Melbourne", href: "/au/assignment-help-melbourne" },
                { label: "Sydney", href: "/au/assignment-help-sydney" },
                { label: "Perth", href: "/au/assignment-help-perth" },
                { label: "Adelaide", href: "/au/assignment-help-adelaide" },
                { label: "Brisbane", href: "/au/assignment-help-brisbane" },
              ],
            },
            { label: "Malaysia", href: "/my", cities: [] },
            {
              label: "Canada",
              href: "/ca",
              cities: [{ label: "Toronto", href: "/ca/essay-help-toronto" }],
            },
            {
              label: "New Zealand",
              href: "/nz",
              cities: [
                { label: "Wellington", href: "/nz/wellington-essay-assignment-help" },
                { label: "Auckland", href: "/nz/auckland-essay-assignment-help" },
                { label: "Hamilton", href: "/nz/hamilton-essay-assignment-help" },
              ],
            },
          ],
        },
      },
      // The live "useful-link" bar — real, all 9 links, same module.
      legalLinks: [
        { label: "Refund Policy", href: "/refund-policy" },
        { label: "Cancellation Policy", href: "/cancellation-policy" },
        { label: "Terms & Conditions", href: "/terms-condition" },
        { label: "Privacy Policy", href: "/privacy-policy" },
        { label: "Usage policy", href: "/fair-usage-policy" },
        { label: "Honor Code", href: "/honor-code" },
        { label: "Academic Integrity", href: "/academic-integrity" },
        { label: "Contact Us", href: "/contact-us" },
        { label: "Sitemap", href: "/sitemap" },
      ],
      contactInfo: {
        phone: phoneNum,
        whatsapp: whatsappNum,
        whatsappUrl: getWhatsappUrl(whatsappNum),
        email: emailAddr,
        appStoreUrl: "https://apps.apple.com/us/app/global-assignment-help/id1094249594",
        playStoreUrl: "https://play.google.com/store/apps/details?id=com.globalassignmenthelp",
      },
      socialLinks: [
        { platform: "Facebook", url: "https://www.facebook.com/Global-Assignment-Help-100149402774016", iconName: "Facebook" },
        { platform: "Twitter", url: "https://twitter.com/gahassignment", iconName: "Twitter" },
        { platform: "Instagram", url: "https://instagram.com/globalassignmenthelp", iconName: "Instagram" },
        { platform: "Pinterest", url: "https://www.pinterest.co.uk/GlobalAssignmentHelp/_created/", iconName: "Pin" },
        { platform: "YouTube", url: "https://www.youtube.com/channel/UCLckUuoEDp6L06AEArrHs6A", iconName: "Youtube" },
      ],
      dmcaUrl:
        "https://www.dmca.com/Protection/Status.aspx?ID=74bc5807-8089-422f-a39b-5d9217495b6b&refurl=https://www.globalassignmenthelp.com/",
      paymentBadgeAlt: "Visa, MasterCard, Maestro, Amex, PayPal Accepted",
      // Real, verbatim text from the live footer module.
      disclaimerText:
        "Disclaimer : Documents provided by Global Assignment Help serve as model papers and are not meant to be submitted directly to the university or reuse/resell in any way. They are written for individual research and reference purpose only.",
      // The live template substitutes a `copyrightYear` token for the current
      // year server-side; `joomlaService.getNavigation()` does the same.
      copyrightText: `© Copyright 2010-${new Date().getFullYear()} @ Globalassignmenthelp.com All rights reserved`,
      // The live template substitutes `dynamic_rating`/`dynamic_review`
      // tokens here too — `joomlaService.getNavigation()` computes real
      // values from the same `type=reviews` bridge data used for homepage
      // testimonials, rather than this fallback's static estimate.
      ratingInfo: {
        rating: "4.8/5",
        reviewsCount: "5087",
        reviewsUrl: "/reviews",
      },
    },
  };
};
