/* ============================================================
 * Module story — the fixed loop every product page hands off to.
 *
 * Nine pages, nine slugs, one order. Whatever page a visitor lands on
 * from search, an ad, or a Slack link, "Continue the story" always
 * knows what's next — and the loop never dead-ends, because Loyalty
 * hands back to the Brain it started from.
 *
 * The order follows the actual data story, not the nav's grouping:
 * what the hotel knows -> what guests told it -> where those
 * conversations happen -> the profile they all write to -> the
 * business side of that profile -> the identity layer underneath it
 * -> what you do with a clean record -> why guests come back.
 * ============================================================ */
const MODULE_STORY = [
  { slug: "brain", label: "Hotel Brain", href: "platform/knowledge.html", icon: "IconKnowledge" },
  { slug: "memory", label: "Guest Memories", href: "platform/memory.html", icon: "IconMemory" },
  { slug: "inbox", label: "Inboxes", href: "platform/inbox.html", icon: "IconInbox" },
  { slug: "voice", label: "Voice Agent", href: "platform/voice.html", icon: "IconVoiceModule" },
  { slug: "crm", label: "B2C CRM", href: "platform/crm.html", icon: "IconCRM" },
  { slug: "crm-b2b", label: "B2B CRM", href: "platform/crm-b2b.html", icon: "IconB2B" },
  { slug: "cdp", label: "CDP", href: "platform/cdp.html", icon: "IconCDP" },
  { slug: "journeys", label: "Campaigns & Journeys", href: "platform/journeys.html", icon: "IconJourneys" },
  { slug: "loyalty", label: "Loyalty", href: "platform/loyalty.html", icon: "IconLoyalty" },
];

/* One bridge sentence per page, written FROM that page's idea TOWARD
 * the next one — not a generic "check out X" restated nine times. */
const MODULE_TRANSITIONS = {
  brain: "The Brain knows the hotel. Memory belongs to the guest: every stay, every preference, carried forward.",
  memory: "A memory is only useful if it reaches the right conversation. See where every channel meets in one inbox.",
  inbox: "Text is one channel. The phone still rings: see who picks it up when your team can't.",
  voice: "Every answered call, every resolved chat: it all lands on one guest profile. See where it's built.",
  crm: "That's the guests who stay. Hotel groups also sell through the businesses that send them.",
  "crm-b2b": "Every profile, guest or agency, is only as good as the identity behind it. See how duplicates disappear.",
  cdp: "One clean guest record is the fuel. See what it powers: campaigns that fire on real behavior, not the calendar.",
  journeys: "A journey earns a booking. Loyalty is what earns the next one.",
  loyalty: "The loop closes where it started: a returning guest still needs a hotel that remembers them.",
};

function UpNextModule({ currentSlug, basePath = "" }) {
  const idx = MODULE_STORY.findIndex((m) => m.slug === currentSlug);
  if (idx === -1) return null;
  const next = MODULE_STORY[(idx + 1) % MODULE_STORY.length];
  const NIc = (window.moduleIconMap || {})[next.icon];
  const transition = MODULE_TRANSITIONS[currentSlug];

  return (
    <section className="section-pad gm-upnext-section">
      <div className="container">
        <Reveal>
          <a href={`${basePath}${next.href}`} className="gm-upnext">
            <div className="eyebrow gm-upnext-eyebrow">Continue the story</div>
            <p className="gm-upnext-transition">{transition}</p>
            <div className="gm-upnext-next">
              <span className="gm-upnext-icon" aria-hidden="true">{NIc && <NIc size={20} />}</span>
              <span className="gm-upnext-label">{next.label}</span>
              <IconArrow size={16} className="gm-upnext-arrow" />
            </div>
          </a>
        </Reveal>
      </div>

      <style>{`
        .gm-upnext-section { border-top: 1px solid var(--hairline); }
        .gm-upnext {
          display: block; text-decoration: none; color: inherit;
          max-width: 720px; margin: 0 auto; text-align: center;
          border: 1px solid var(--hairline-strong); border-radius: 20px;
          padding: 44px 48px;
          background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 6%, var(--bg)), var(--bg));
          transition: border-color 220ms ease, transform 220ms ease;
        }
        .gm-upnext:hover {
          border-color: color-mix(in srgb, var(--accent) 45%, transparent);
          transform: translateY(-2px);
        }
        .gm-upnext-eyebrow { justify-content: center; }
        .gm-upnext-transition {
          margin: 18px auto 0;
          font-size: 17px; line-height: 1.55; color: var(--ink-2);
          max-width: 560px;
        }
        .gm-upnext-next {
          display: inline-flex; align-items: center; gap: 12px;
          margin-top: 28px;
          font-family: var(--f-display); font-size: 30px; color: var(--ink);
          letter-spacing: -0.01em;
        }
        .gm-upnext-icon {
          display: inline-flex; align-items: center; justify-content: center;
          flex-shrink: 0;
          width: 42px; height: 42px; border-radius: 11px;
          background: color-mix(in srgb, var(--accent) 10%, transparent);
          color: var(--accent);
        }
        .gm-upnext-arrow { color: var(--ink-3); transition: transform 220ms ease, color 220ms ease; }
        .gm-upnext:hover .gm-upnext-arrow { transform: translateX(6px); color: var(--accent); }
        @media (max-width: 640px) {
          .gm-upnext { padding: 32px 24px; }
          .gm-upnext-next { font-size: 23px; flex-wrap: wrap; justify-content: center; }
        }
        @media (prefers-reduced-motion: reduce) {
          .gm-upnext, .gm-upnext-arrow { transition-duration: 1ms; }
        }
      `}</style>
    </section>
  );
}

window.UpNextModule = UpNextModule;
