// product_shell.jsx — faithful replica of the TalentScreen product chrome
// (dark left sidebar + breadcrumb bar + page header). Used by all four
// product animations so they read as real screenshots.

// ── Sidebar icon set ───────────────────────────────────────────────────
function PSIcon({ kind, size = 18, stroke = 'currentColor' }) {
  const p = { fill: 'none', stroke, strokeWidth: 1.6, strokeLinecap: 'round', strokeLinejoin: 'round' };
  const s = size;
  if (kind === 'menu') return <svg width={s} height={s} viewBox="0 0 20 20"><path d="M3 6h14M3 10h14M3 14h14" {...p}/></svg>;
  if (kind === 'grid') return <svg width={s} height={s} viewBox="0 0 20 20"><rect x="3" y="3" width="6" height="6" rx="1" {...p}/><rect x="11" y="3" width="6" height="6" rx="1" {...p}/><rect x="3" y="11" width="6" height="6" rx="1" {...p}/><rect x="11" y="11" width="6" height="6" rx="1" {...p}/></svg>;
  if (kind === 'pin') return <svg width={s} height={s} viewBox="0 0 20 20"><path d="M10 2c-3 0-5.5 2.5-5.5 5.5 0 4 5.5 10 5.5 10s5.5-6 5.5-10C15.5 4.5 13 2 10 2z" {...p}/><circle cx="10" cy="7.5" r="2" {...p}/></svg>;
  if (kind === 'bolt') return <svg width={s} height={s} viewBox="0 0 20 20"><path d="M11 2L4 11h5l-1 7 7-9h-5z" {...p}/></svg>;
  if (kind === 'shield') return <svg width={s} height={s} viewBox="0 0 20 20"><path d="M10 2l7 3v5c0 4-3 7-7 8-4-1-7-4-7-8V5z" {...p}/></svg>;
  if (kind === 'video') return <svg width={s} height={s} viewBox="0 0 20 20"><rect x="2" y="5" width="12" height="10" rx="1.5" {...p}/><path d="M14 8l4-2v8l-4-2z" {...p}/></svg>;
  if (kind === 'gear') return <svg width={s} height={s} viewBox="0 0 20 20"><circle cx="10" cy="10" r="2.5" {...p}/><path d="M10 3v2M10 15v2M3 10h2M15 10h2M4.9 4.9l1.4 1.4M13.7 13.7l1.4 1.4M4.9 15.1l1.4-1.4M13.7 6.3l1.4-1.4" {...p}/></svg>;
  if (kind === 'bell') return <svg width={s} height={s} viewBox="0 0 20 20"><path d="M5 8a5 5 0 0110 0v3l1.5 2h-13L5 11z" {...p}/><path d="M8 16a2 2 0 004 0" {...p}/></svg>;
  if (kind === 'chat') return <svg width={s} height={s} viewBox="0 0 20 20"><path d="M3 5c0-.6.4-1 1-1h12c.6 0 1 .4 1 1v8c0 .6-.4 1-1 1h-5l-4 3v-3H4c-.6 0-1-.4-1-1z" {...p}/></svg>;
  if (kind === 'swap') return <svg width={s} height={s} viewBox="0 0 20 20"><path d="M4 8h11l-2-2M16 12H5l2 2" {...p}/></svg>;
  if (kind === 'home') return <svg width={s} height={s} viewBox="0 0 20 20"><path d="M3 9l7-6 7 6v8c0 .6-.4 1-1 1h-3v-5H7v5H4c-.6 0-1-.4-1-1z" {...p}/></svg>;
  // submenu icons
  if (kind === 'overview') return <svg width={s} height={s} viewBox="0 0 20 20"><rect x="3" y="3" width="6" height="6" rx="1" {...p}/><rect x="11" y="3" width="6" height="6" rx="1" {...p}/><rect x="3" y="11" width="6" height="6" rx="1" {...p}/><rect x="11" y="11" width="6" height="6" rx="1" {...p}/></svg>;
  if (kind === 'template') return <svg width={s} height={s} viewBox="0 0 20 20"><rect x="3" y="3" width="14" height="14" rx="1.5" {...p}/><path d="M3 8h14" {...p}/></svg>;
  if (kind === 'rubric') return <svg width={s} height={s} viewBox="0 0 20 20"><path d="M4 5h9M4 10h12M4 15h7" {...p}/><circle cx="16" cy="5" r="1.4" {...p}/><circle cx="16" cy="15" r="1.4" {...p}/></svg>;
  if (kind === 'sessions') return <svg width={s} height={s} viewBox="0 0 20 20"><circle cx="10" cy="10" r="7" {...p}/><path d="M8 7l5 3-5 3z" {...p}/></svg>;
  if (kind === 'assignments') return <svg width={s} height={s} viewBox="0 0 20 20"><rect x="4" y="3" width="12" height="14" rx="1.5" {...p}/><path d="M7 7h6M7 10h6M7 13h4" {...p}/></svg>;
  if (kind === 'reports') return <svg width={s} height={s} viewBox="0 0 20 20"><path d="M3 16h14" {...p}/><rect x="5" y="9" width="2.5" height="6" {...p}/><rect x="9" y="5" width="2.5" height="10" {...p}/><rect x="13" y="11" width="2.5" height="4" {...p}/></svg>;
  if (kind === 'management') return <svg width={s} height={s} viewBox="0 0 20 20"><circle cx="10" cy="10" r="2.5" {...p}/><path d="M10 3v2M10 15v2M3 10h2M15 10h2M4.9 4.9l1.4 1.4M13.7 13.7l1.4 1.4M4.9 15.1l1.4-1.4M13.7 6.3l1.4-1.4" {...p}/></svg>;
  return null;
}

// ── Left sidebar (dark, icon-only) + submenu panel ──────────────────────
function PSSidebar({ section = 'Overview' }) {
  const icons = ['menu', 'grid', 'pin', 'bolt', 'shield', 'video', 'swap'];
  const activeIdx = 5; // video (TalentScreen)
  return (
    <div style={{
      position: 'absolute',
      left: 0, top: 0, bottom: 0,
      width: 64,
      background: '#1A1725',
      display: 'flex', flexDirection: 'column',
      alignItems: 'center',
      paddingTop: 16,
      gap: 6,
      zIndex: 3,
    }}>
      {icons.map((k, i) => (
        <div key={i} style={{
          width: 40, height: 40,
          borderRadius: 8,
          display: 'flex', alignItems: 'center', justifyContent: 'center',
          background: i === activeIdx ? 'rgba(245,158,11,0.18)' : 'transparent',
          color: i === activeIdx ? '#F59E0B' : 'rgba(255,255,255,0.55)',
          position: 'relative',
        }}>
          {i === activeIdx && <div style={{
            position: 'absolute', left: 0, top: 8, bottom: 8, width: 2,
            background: '#F59E0B',
            borderRadius: '0 2px 2px 0',
          }}/>}
          <PSIcon kind={k} size={18}/>
        </div>
      ))}
      <div style={{ flex: 1 }}/>
      <div style={{
        width: 40, height: 40,
        borderRadius: 8,
        display: 'flex', alignItems: 'center', justifyContent: 'center',
        color: 'rgba(255,255,255,0.55)',
        marginBottom: 16,
      }}>
        <PSIcon kind="gear" size={18}/>
      </div>
    </div>
  );
}

// ── Top breadcrumb bar ──────────────────────────────────────────────────
function PSTopBar({ breadcrumb = ['Select', 'TalentScreen', 'Screen', 'Video Interview'] }) {
  return (
    <div style={{
      position: 'absolute',
      left: 64, right: 0, top: 0,
      height: 56,
      background: '#fff',
      borderBottom: `1px solid ${LC_LINE}`,
      display: 'flex', alignItems: 'center',
      padding: '0 28px',
      zIndex: 2,
    }}>
      <img src="assets/TTP-logo-landscape-dark.svg" alt="" style={{ height: 22, marginRight: 28 }}/>
      <div style={{
        display: 'flex', alignItems: 'center', gap: 10,
        fontFamily: 'Gilroy, sans-serif',
        fontSize: 13, fontWeight: 500,
        color: LC_INK_SOFT,
      }}>
        <PSIcon kind="home" size={14} stroke={LC_INK_SOFT}/>
        {breadcrumb.map((b, i) => (
          <React.Fragment key={i}>
            <span style={{ color: LC_INK_MUTED, fontWeight: 400 }}>›</span>
            <span style={{ color: i === breadcrumb.length - 1 ? LC_ORANGE : LC_INK_SOFT, fontWeight: i === breadcrumb.length - 1 ? 600 : 500 }}>{b}</span>
          </React.Fragment>
        ))}
      </div>
      <div style={{ flex: 1 }}/>
      {/* Org pill */}
      <div style={{
        display: 'flex', alignItems: 'center', gap: 8,
        padding: '6px 12px',
        borderRadius: 8,
        border: `1px solid ${LC_LINE}`,
        fontFamily: 'Gilroy, sans-serif',
        fontSize: 12, fontWeight: 600,
        color: LC_INK,
      }}>
        <img src="assets/TTP-logo-landscape-dark.svg" alt="" style={{ height: 14 }}/>
        The Talent People
      </div>
      <div style={{ display: 'flex', gap: 6, marginLeft: 16, color: LC_INK_SOFT }}>
        <div style={{ width: 32, height: 32, borderRadius: 16, display: 'flex', alignItems: 'center', justifyContent: 'center', background: '#F6F5FA' }}><PSIcon kind="chat" size={14} stroke={LC_INK_SOFT}/></div>
        <div style={{ width: 32, height: 32, borderRadius: 16, display: 'flex', alignItems: 'center', justifyContent: 'center', background: '#F6F5FA' }}><PSIcon kind="bell" size={14} stroke={LC_INK_SOFT}/></div>
      </div>
      <div style={{
        width: 32, height: 32, borderRadius: 16,
        background: '#3B82F6',
        color: '#fff',
        fontFamily: 'Gilroy, sans-serif',
        fontSize: 12, fontWeight: 700,
        display: 'flex', alignItems: 'center', justifyContent: 'center',
        marginLeft: 10,
      }}>UN</div>
    </div>
  );
}

// ── Page header (purple icon + title + eyebrow) ─────────────────────────
function PSPageHeader({ title, eyebrow, icon = 'template' }) {
  return (
    <div style={{
      position: 'absolute',
      left: 64, right: 0, top: 56,
      height: 80,
      background: '#fff',
      borderBottom: `1px solid ${LC_LINE}`,
      padding: '20px 40px',
      display: 'flex', alignItems: 'center',
      gap: 18,
      zIndex: 2,
    }}>
      <div style={{
        width: 44, height: 44, borderRadius: 10,
        background: LC_PURPLE_SOFT,
        color: LC_PURPLE,
        display: 'flex', alignItems: 'center', justifyContent: 'center',
      }}>
        <PSIcon kind={icon} size={22}/>
      </div>
      <div>
        <div style={{
          fontFamily: 'Gilroy, sans-serif',
          fontSize: 22, fontWeight: 700,
          color: LC_INK,
          letterSpacing: '-0.02em',
        }}>{title}</div>
        <div style={{
          fontFamily: 'Gilroy, sans-serif',
          fontSize: 11, fontWeight: 600,
          color: LC_INK_MUTED,
          letterSpacing: '0.18em',
          textTransform: 'uppercase',
          marginTop: 2,
        }}>{eyebrow}</div>
      </div>
    </div>
  );
}

// ── Submenu (second-level left nav card) ────────────────────────────────
function PSSubmenu({ active = 'Overview', items = ['Overview', 'Templates', 'Rubrics', 'Sessions', 'Assignments', 'Reports', 'Management'] }) {
  const iconMap = { 'Overview':'overview','Templates':'template','Rubrics':'rubric','Sessions':'sessions','Assignments':'assignments','Reports':'reports','Management':'management' };
  return (
    <div style={{
      width: 200,
      background: '#fff',
      borderRadius: 12,
      border: `1px solid ${LC_LINE}`,
      padding: 10,
      boxShadow: '0 2px 8px rgba(22,22,31,0.04)',
    }}>
      {items.map((item, i) => {
        const isActive = item === active;
        return (
          <div key={i} style={{
            display: 'flex', alignItems: 'center', gap: 12,
            padding: '10px 12px',
            borderRadius: 8,
            background: isActive ? LC_PURPLE_SOFT : 'transparent',
            color: isActive ? LC_PURPLE_DARK : LC_INK_SOFT,
            fontFamily: 'Gilroy, sans-serif',
            fontSize: 13, fontWeight: isActive ? 600 : 500,
            marginBottom: 2,
          }}>
            <PSIcon kind={iconMap[item] || 'grid'} size={15} stroke="currentColor"/>
            {item}
          </div>
        );
      })}
    </div>
  );
}

// ── Footer that mimics real product footer ──────────────────────────────
function PSFooter() {
  return (
    <div style={{
      position: 'absolute',
      left: 64, right: 0, bottom: 0,
      height: 88,
      background: '#fff',
      borderTop: `1px solid ${LC_LINE}`,
      display: 'flex', flexDirection: 'column',
      alignItems: 'center', justifyContent: 'center',
      gap: 8,
      zIndex: 2,
    }}>
      <div style={{
        display: 'flex', alignItems: 'center', gap: 22,
        fontFamily: 'Gilroy, sans-serif',
        fontSize: 11, fontWeight: 500,
        color: LC_INK_SOFT,
      }}>
        <span>Privacy Policy</span>
        <span>Terms of Use</span>
        <span>Legal & Compliance</span>
        <span>Platform Status</span>
        <span>Help & Support</span>
      </div>
      <div style={{
        display: 'flex', alignItems: 'center', gap: 10,
        fontFamily: 'Gilroy, sans-serif',
        fontSize: 10, fontWeight: 500,
        color: LC_INK_MUTED,
      }}>
        <div style={{ padding: '3px 8px', borderRadius: 10, border: `1px solid ${LC_LINE}` }}>ISO 27001</div>
        <div style={{ padding: '3px 8px', borderRadius: 10, border: `1px solid ${LC_LINE}` }}>ISO 9001</div>
        <div style={{ padding: '3px 8px', borderRadius: 10, border: `1px solid ${LC_LINE}` }}>Cyber Essentials Plus</div>
      </div>
      <div style={{
        fontFamily: 'Gilroy, sans-serif',
        fontSize: 10, fontWeight: 500,
        color: LC_INK_MUTED,
      }}>© 2025 The Talent Hub | The Talent People</div>
    </div>
  );
}

// ── Product shell wrapper (drops all chrome) ───────────────────────────
function PSShell({ children, breadcrumb, title, eyebrow, icon }) {
  return (
    <>
      {/* base canvas bg */}
      <div style={{
        position: 'absolute', inset: 0,
        background: '#F4F3F8',
      }}/>
      <PSSidebar/>
      <PSTopBar breadcrumb={breadcrumb}/>
      <PSPageHeader title={title} eyebrow={eyebrow} icon={icon}/>
      {children}
      <PSFooter/>
    </>
  );
}

// ── Callout person with speech bubble ───────────────────────────────────
// `appear` = seconds after which to show; bubble slides in after a beat.
function PSCallout({
  src, side = 'right', heightPx = 720,
  bubble, bubbleTop = 120,
  appear = 2.5, bubbleDelay = 0.8,
  translateOut = 180,
}) {
  const t = useTime();
  const personT = Easing.easeOutCubic(clamp((t - appear) / 1.0, 0, 1));
  const bubbleT = Easing.easeOutBack(clamp((t - appear - bubbleDelay) / 0.8, 0, 1));

  // person slides in from outside the frame
  const slideX = (1 - personT) * translateOut * (side === 'right' ? 1 : -1);

  return (
    <>
      <img
        src={src}
        alt=""
        style={{
          position: 'absolute',
          [side]: -40,
          bottom: 0,
          height: heightPx,
          width: 'auto',
          filter: 'grayscale(1) contrast(1.05)',
          opacity: personT * 0.94,
          transform: `translateX(${slideX}px)`,
          zIndex: 4,
          pointerEvents: 'none',
        }}
      />
      {bubble && (
        <div style={{
          position: 'absolute',
          [side]: 80,
          top: bubbleTop,
          maxWidth: 340,
          padding: '18px 22px',
          background: side === 'right' ? LC_PURPLE : '#fff',
          color: side === 'right' ? '#fff' : LC_INK,
          borderRadius: 18,
          boxShadow: side === 'right'
            ? '0 20px 50px rgba(124,58,237,0.35)'
            : '0 20px 50px rgba(22,22,31,0.15)',
          opacity: clamp(bubbleT, 0, 1),
          transform: `scale(${0.85 + clamp(bubbleT, 0, 1) * 0.15}) translateY(${(1 - clamp(bubbleT, 0, 1)) * 10}px)`,
          transformOrigin: side === 'right' ? 'right center' : 'left center',
          fontFamily: 'Gilroy, sans-serif',
          zIndex: 5,
          border: side === 'right' ? 'none' : `1px solid ${LC_LINE}`,
        }}>
          {/* bubble tail */}
          <div style={{
            position: 'absolute',
            [side]: -10,
            top: 32,
            width: 22, height: 22,
            background: side === 'right' ? LC_PURPLE : '#fff',
            transform: 'rotate(45deg)',
            borderRight: side === 'left' ? `1px solid ${LC_LINE}` : 'none',
            borderBottom: side === 'left' ? `1px solid ${LC_LINE}` : 'none',
            borderTop: side === 'right' ? 'none' : 'none',
          }}/>
          <div style={{
            fontSize: 10, fontWeight: 700,
            letterSpacing: '0.2em',
            textTransform: 'uppercase',
            opacity: 0.75,
            marginBottom: 8,
            position: 'relative',
          }}>{bubble.label}</div>
          <div style={{
            fontSize: 16, fontWeight: 600,
            lineHeight: 1.35,
            letterSpacing: '-0.01em',
            position: 'relative',
          }}>{bubble.text}</div>
          {bubble.meta && (
            <div style={{
              fontSize: 11, fontWeight: 500,
              opacity: 0.75,
              marginTop: 10,
              position: 'relative',
            }}>{bubble.meta}</div>
          )}
        </div>
      )}
    </>
  );
}

Object.assign(window, {
  PSIcon, PSSidebar, PSTopBar, PSPageHeader, PSSubmenu, PSFooter,
  PSShell, PSCallout,
});
