/* global React */
/*
 * Shared left icon navigation rail.
 *
 * Loaded by every page so the rail markup lives in one place instead of being
 * copy-pasted per page. Pages under a subdirectory pass base="../" so the
 * hash links resolve against the homepage rather than the current page.
 */

const HomeIcon = () => (
  <svg width="20" height="20" fill="none" stroke="currentColor" strokeWidth="2" viewBox="0 0 24 24">
    <path strokeLinecap="round" strokeLinejoin="round" d="m2 10 10-8 10 8v10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V10Z" />
  </svg>
);
const DemoIcon = () => (
  <svg width="20" height="20" fill="none" stroke="currentColor" strokeWidth="2" viewBox="0 0 24 24">
    <polygon strokeLinecap="round" strokeLinejoin="round" points="6,3 20,12 6,21" />
  </svg>
);
const ReviewIcon = () => (
  <svg width="20" height="20" fill="none" stroke="currentColor" strokeWidth="2" viewBox="0 0 24 24">
    <path strokeLinecap="round" strokeLinejoin="round" d="M3 18v-6a9 9 0 0 1 18 0v6M21 18a3 3 0 0 1-3 3H6a3 3 0 0 1-3-3M11 10v4M13 8v8M7 11v2M17 11v2" />
  </svg>
);
const BentoIcon = () => (
  <svg width="20" height="20" fill="none" stroke="currentColor" strokeWidth="2" viewBox="0 0 24 24">
    <rect x="3" y="3" width="7" height="7" rx="1" strokeLinecap="round" />
    <rect x="14" y="3" width="7" height="7" rx="1" strokeLinecap="round" />
    <rect x="3" y="14" width="7" height="7" rx="1" strokeLinecap="round" />
    <rect x="14" y="14" width="7" height="7" rx="1" strokeLinecap="round" />
  </svg>
);
const StepsIcon = () => (
  <svg width="20" height="20" fill="none" stroke="currentColor" strokeWidth="2" viewBox="0 0 24 24">
    <line x1="3" y1="6" x2="21" y2="6" strokeLinecap="round" />
    <line x1="3" y1="12" x2="16" y2="12" strokeLinecap="round" />
    <line x1="3" y1="18" x2="11" y2="18" strokeLinecap="round" />
  </svg>
);
const KeyIcon = () => (
  <svg width="20" height="20" fill="none" stroke="currentColor" strokeWidth="2" viewBox="0 0 24 24">
    <circle cx="8" cy="15" r="4" strokeLinecap="round" />
    <path strokeLinecap="round" strokeLinejoin="round" d="M12 11 19 4M16 7l2 2M18 5l2 2" />
  </svg>
);
const PricingIcon = () => (
  <svg width="20" height="20" fill="none" stroke="currentColor" strokeWidth="2" viewBox="0 0 24 24">
    <path strokeLinecap="round" strokeLinejoin="round" d="M9.5 8.5 18 17M11.5 6.5l8.5 8.5M7 14A4 4 0 1 1 3 10a4 4 0 0 1 4 4Z" />
  </svg>
);
const FAQIcon = () => (
  <svg width="20" height="20" fill="none" stroke="currentColor" strokeWidth="2" viewBox="0 0 24 24">
    <circle cx="12" cy="12" r="10" strokeLinecap="round" />
    <path strokeLinecap="round" strokeLinejoin="round" d="M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3M12 17h.01" />
  </svg>
);

/*
 * `scope` decides which anchors this rail offers, because the sections it used
 * to point at moved.
 *
 *   "home"     (default) Home, Demo, Products, Manage Key - all of which exist
 *              on `/`. Every page that passes only `base` gets this, so a rail
 *              on /store/ or /support/ cannot link to an anchor that is no
 *              longer on the homepage.
 *   "product"  Features, How It Works, Pricing, FAQ as LOCAL anchors, for the
 *              product pages that actually carry those sections now.
 *
 * Before 2026-09-04 there was one list, pointing at #features / #pricing / #faq
 * on the homepage. Those sections live on /products/virtue-fx-manager/ now, so
 * that list would have been four dead links on nine pages.
 */
const LeftSidebar = ({ activeSection, base = '', scope = 'home' }) => {
  const items = scope === 'product'
    ? [
        { id: 'home',     href: `${base}#`,         label: 'Home',         icon: <HomeIcon /> },
        { id: 'features', href: '#features',        label: 'Features',     icon: <BentoIcon /> },
        { id: 'how',      href: '#how',             label: 'How It Works', icon: <StepsIcon /> },
        { id: 'pricing',  href: '#pricing',         label: 'Pricing Plan', icon: <PricingIcon /> },
        { id: 'faq',      href: '#faq',             label: 'Common FAQ',   icon: <FAQIcon /> },
        { id: 'recovery', href: `${base}support/`,  label: 'Manage Key',   icon: <KeyIcon /> }
      ]
    : [
        { id: 'home',     href: `${base}#`,         label: 'Home',         icon: <HomeIcon /> },
        { id: 'demo',     href: `${base}#demo`,     label: 'Demo Video',   icon: <DemoIcon /> },
        { id: 'products', href: `${base}#products`, label: 'Products',     icon: <BentoIcon /> },
        { id: 'recovery', href: `${base}support/`,  label: 'Manage Key',   icon: <KeyIcon /> }
      ];

  return (
    <div className="nav-tab">
      {/* Brand logo top link */}
      <a href={`${base}#`} className="nav-tab-icon" aria-label="VFxM Home">
        <svg viewBox="0 0 100 100" fill="none" xmlns="http://www.w3.org/2000/svg" style={{ color: 'var(--o)' }}>
          <rect x="20" y="25" width="60" height="50" rx="10" fill="rgba(var(--accent-rgb), 0.15)" stroke="currentColor" strokeWidth="6" />
          <line x1="35" y1="50" x2="65" y2="50" stroke="currentColor" strokeWidth="6" strokeLinecap="round" />
          <circle cx="50" cy="50" r="10" fill="var(--surface)" stroke="currentColor" strokeWidth="4" />
        </svg>
      </a>

      {/* Nav icon categories */}
      <div className="nav-icons-list">
        {items.map((it) => (
          <a
            key={it.id}
            href={it.href}
            className={`nav-icon-link ${activeSection === it.id ? 'active' : ''}`}
            aria-label={it.label}
          >
            {it.icon}
            <span className="tooltip">{it.label}</span>
          </a>
        ))}
      </div>

      <div style={{ height: 24 }} /> {/* bottom spacer */}
    </div>
  );
};

window.LeftSidebar = LeftSidebar;
