// TopBar — mirrors ui/src/components/layout/TopBar.tsx
function TopBar({ page, onNavigate, counts, onOpenCreate, user }) {
  const navItem = (id, label) => {
    const active = page === id;
    return (
      <button
        key={id}
        onClick={() => onNavigate(id)}
        style={{
          position: 'relative',
          padding: '10px 4px', marginBottom: -13,
          fontSize: 12, fontWeight: active ? 700 : 500,
          border: 'none', background: 'transparent', cursor: 'pointer', fontFamily: 'inherit',
          color: active ? '#0f172a' : '#64748b',
          borderBottom: '2px solid ' + (active ? '#2563eb' : 'transparent'),
          transition: 'color .15s, border-color .15s',
        }}
      >{label}</button>
    );
  };

  return (
    <div style={{
      flexShrink: 0, background: '#fff', borderBottom: '1px solid #e2e8f0',
      padding: '12px 16px', display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 12, flexWrap: 'wrap',
    }}>
      <div style={{ display: 'flex', alignItems: 'center', gap: 12, flexWrap: 'wrap' }}>
        <img src="../../assets/logo.svg" width="22" height="22" alt="" />
        <span style={{
          fontFamily: 'IBM Plex Mono, monospace', fontSize: 11, fontWeight: 700,
          color: '#2563eb', textTransform: 'uppercase', letterSpacing: '.16em',
        }}>Agent Orchestrator</span>
        <span style={{ fontFamily: 'IBM Plex Mono, monospace', fontSize: 10, color: '#94a3b8' }}>v1.14.0</span>
        <div style={{ display: 'flex', gap: 14, alignItems: 'stretch' }}>
          {navItem('tasks', 'Tasks')}
          {navItem('schedules', 'Schedules')}
          {navItem('settings', 'Settings')}
          {navItem('users', 'Users')}
        </div>
      </div>

      <div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
        {user && (
          <div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
            <div style={{
              width: 24, height: 24, borderRadius: 9999, background: '#dbeafe', color: '#1d4ed8',
              display: 'inline-flex', alignItems: 'center', justifyContent: 'center', fontSize: 11, fontWeight: 700,
            }}>{user.name.charAt(0)}</div>
            <span style={{ fontSize: 12, color: '#475569' }}>{user.name}</span>
          </div>
        )}
      </div>
    </div>
  );
}

window.TopBar = TopBar;
