/* ============================================================
   F2 UI — Overview page (group: Overview, page:true)
   ============================================================ */
(function () {
  const F2 = window.F2;
  const { Icon } = F2;

  function Principle({ icon, title, body }) {
    return (
      <div style={{ display: 'flex', flexDirection: 'column', gap: 12, padding: 22, border: '1px solid var(--f2-border)', borderRadius: 'var(--f2-radius-md)', background: 'var(--f2-surface-card)' }}>
        <span style={{ color: 'var(--f2-accent-text)' }}><Icon name={icon} size={20} /></span>
        <div style={{ fontFamily: 'var(--f2-font-display)', fontWeight: 600, fontSize: 16, color: 'var(--f2-text)' }}>{title}</div>
        <div style={{ fontSize: 14, lineHeight: 1.55, color: 'var(--f2-text-muted)' }}>{body}</div>
      </div>
    );
  }

  function CatRow({ icon, name, items, count }) {
    return (
      <div style={{ display: 'flex', alignItems: 'flex-start', gap: 16, padding: '18px 0', borderBottom: '1px solid var(--f2-border)' }}>
        <span style={{ width: 38, height: 38, flex: '0 0 auto', display: 'inline-flex', alignItems: 'center', justifyContent: 'center', borderRadius: 'var(--f2-radius-control)', border: '1px solid var(--f2-border)', background: 'var(--f2-surface-raised)', color: 'var(--f2-text-secondary)' }}><Icon name={icon} size={18} /></span>
        <div style={{ flex: 1, minWidth: 0 }}>
          <div style={{ display: 'flex', alignItems: 'baseline', gap: 10 }}>
            <span style={{ fontFamily: 'var(--f2-font-display)', fontWeight: 600, fontSize: 16, color: 'var(--f2-text)' }}>{name}</span>
            <span style={{ fontFamily: 'var(--f2-font-mono)', fontSize: 11, color: 'var(--f2-text-faint)' }}>{count}</span>
          </div>
          <div style={{ fontSize: 13.5, color: 'var(--f2-text-muted)', marginTop: 4, lineHeight: 1.5 }}>{items}</div>
        </div>
      </div>
    );
  }

  window.story({
    id: 'overview',
    group: 'Overview',
    name: 'Introduction',
    page: true,
    render: function () {
      const total = window.F2Stories.filter((s) => !s.page).length;
      return (
        <div style={{ maxWidth: 940, margin: '0 auto', padding: '56px 28px 120px' }}>
          {/* hero */}
          <div style={{ display: 'flex', alignItems: 'center', gap: 10, marginBottom: 22 }}>
            <span style={{ width: 8, height: 8, borderRadius: 2, background: 'var(--f2-accent)' }} />
            <span style={{ fontFamily: 'var(--f2-font-mono)', fontSize: 12, letterSpacing: '0.16em', textTransform: 'uppercase', color: 'var(--f2-text-muted)' }}>F2 Technologies · Component Library</span>
          </div>
          <h1 style={{ margin: 0, fontFamily: 'var(--f2-font-display)', fontWeight: 700, fontSize: 'clamp(34px, 5vw, 54px)', lineHeight: 1.0, letterSpacing: '-0.035em', color: 'var(--f2-text)', maxWidth: 720 }}>
            A shared library, engineered to fit.
          </h1>
          <p style={{ margin: '22px 0 0', fontSize: 19, lineHeight: 1.6, color: 'var(--f2-text-secondary)', maxWidth: 660 }}>
            Every building block for F2 marketing sites and client panels — built on the F2 design tokens, themeable dark and light, documented with live controls, code, and accessibility notes. Reuse across projects without rebuilding.
          </p>
          <div style={{ display: 'flex', flexWrap: 'wrap', gap: 28, marginTop: 32 }}>
            {[['Components', total], ['Categories', 8], ['Themes', 2], ['Tokens', '3-layer']].map(([k, v]) => (
              <div key={k}>
                <div style={{ fontFamily: 'var(--f2-font-display)', fontWeight: 700, fontSize: 30, letterSpacing: '-0.03em', color: 'var(--f2-text)' }}>{v}</div>
                <div style={{ fontFamily: 'var(--f2-font-mono)', fontSize: 11, letterSpacing: '0.14em', textTransform: 'uppercase', color: 'var(--f2-text-faint)', marginTop: 4 }}>{k}</div>
              </div>
            ))}
          </div>

          {/* principles */}
          <h2 style={{ margin: '64px 0 20px', fontFamily: 'var(--f2-font-display)', fontWeight: 600, fontSize: 24, letterSpacing: '-0.02em', color: 'var(--f2-text)' }}>Principles</h2>
          <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(220px, 1fr))', gap: 16 }}>
            <Principle icon="Minus" title="Flat, always" body="No gradients, glows, or decorative shadows. Elevation is surface steps + hairline borders." />
            <Principle icon="Circle" title="Amber means one thing" body="Signal Amber marks the active node — live, key edge, output. Held to ~10% of any surface." />
            <Principle icon="Type" title="Two faces" body="Space Grotesk for display, UI, body. JetBrains Mono as the technical signal — labels, status, code." />
            <Principle icon="SunMoon" title="Themeable" body="Dark is the brand default; light is fully specified. Toggle scopes per element, never branches." />
          </div>

          {/* categories */}
          <h2 style={{ margin: '64px 0 8px', fontFamily: 'var(--f2-font-display)', fontWeight: 600, fontSize: 24, letterSpacing: '-0.02em', color: 'var(--f2-text)' }}>What's inside</h2>
          <div>
            <CatRow icon="Square" name="Core" count="11 components" items="Button, IconButton, Badge, Tag, Card, Input, Switch, MonoLabel, StatusDot, plus the diagram primitives." />
            <CatRow icon="TextCursorInput" name="Forms" count="7 components" items="Select, Checkbox, RadioGroup, Textarea, Slider, DatePicker, FileUpload." />
            <CatRow icon="Compass" name="Navigation" count="6 components" items="Tabs, Breadcrumb, Pagination, DropdownMenu, CommandPalette, Stepper." />
            <CatRow icon="LayoutList" name="Data display" count="10 components" items="Avatar, List, Timeline, Stat, Progress, Skeleton, EmptyState, CodeBlock, Accordion, DataTable." />
            <CatRow icon="MessageSquareWarning" name="Feedback & overlays" count="7 components" items="Modal, Drawer, Toast, Tooltip, Popover, Alert, Banner." />
            <CatRow icon="LayoutDashboard" name="Dashboard" count="5 blocks" items="SidebarNav, Topbar, StatCard, MetricChart, and an assembled panel layout." />
            <CatRow icon="Megaphone" name="Marketing" count="9 blocks" items="Hero, Navbar, Footer, Pricing, FeatureGrid, Testimonial, CTA, FAQ, LogoCloud." />
            <CatRow icon="Workflow" name="Diagram kit" count="agent flows" items="Extended workflow nodes, edges, and an assembled agent-flow composite." />
          </div>

          <div style={{ marginTop: 56, padding: 24, border: '1px solid var(--f2-accent-border)', borderRadius: 'var(--f2-radius-md)', background: 'var(--f2-surface-accent)', display: 'flex', gap: 14, alignItems: 'flex-start' }}>
            <span style={{ color: 'var(--f2-accent-text)', marginTop: 1 }}><Icon name="Keyboard" size={18} /></span>
            <div style={{ fontSize: 14.5, lineHeight: 1.6, color: 'var(--f2-text-secondary)' }}>
              <strong style={{ color: 'var(--f2-text)' }}>Tips.</strong> Press <kbd style={{ fontFamily: 'var(--f2-font-mono)', fontSize: 12, border: '1px solid var(--f2-border-strong)', borderRadius: 4, padding: '1px 6px' }}>/</kbd> to search. Use the viewport and theme toggles (top-right) to preview any component responsively in dark or light. Every component ships a copy-paste snippet and a props table.
            </div>
          </div>
        </div>
      );
    },
  });
})();
