// Shared library data — Bookmarks, History, Downloads, Recently closed,
// Passwords, Reading list, Site permissions.
// Carries Ajna-specific metadata (sync source, device, peer) so all the
// library screens have native chrome instead of looking Chromium-imported.

// Devices a row may have come from
const A_DEVICES = {
  thisIphone:  { id: 'this-iphone',  label: 'iPhone',       short: 'iPhone',  conn: 'this',  color: '#A78BFA' },
  thisIpad:    { id: 'this-ipad',    label: 'iPad Pro',     short: 'iPad',    conn: 'this',  color: '#A78BFA' },
  iphone:      { id: 'iphone',       label: 'iPhone 15',    short: 'iPhone',  conn: 'ble',   color: '#22D3EE' },
  ipad:        { id: 'ipad',         label: 'iPad Pro',     short: 'iPad',    conn: 'net',   color: '#60A5FA' },
  mac:         { id: 'mac',          label: 'MacBook Air',  short: 'Mac',     conn: 'net',   color: '#60A5FA' },
  peerMaya:    { id: 'peer-maya',    label: 'Maya · Mac',   short: 'Maya',    conn: 'peer',  color: '#F472B6' },
  peerRohan:   { id: 'peer-rohan',   label: 'Rohan · Pixel',short: 'Rohan',   conn: 'peer',  color: '#FBBF24' },
};

// Connection chip — used everywhere a "source" appears
function AConnChip({ device, size = 'sm' }) {
  if (!device) return null;
  const d = (typeof device === 'string') ? A_DEVICES[device] : device;
  if (!d) return null;
  const tone = d.conn === 'this'  ? { bg: 'rgba(167,139,250,0.14)', fg: '#C4B5FD', label: 'THIS' }
            : d.conn === 'ble'   ? { bg: 'rgba(34,211,238,0.12)',  fg: '#67E8F9', label: 'BLE'  }
            : d.conn === 'net'   ? { bg: 'rgba(96,165,250,0.12)',  fg: '#93C5FD', label: 'NET'  }
            : d.conn === 'peer'  ? { bg: 'rgba(244,114,182,0.12)', fg: '#F9A8D4', label: 'PEER' }
            : { bg: 'rgba(255,255,255,0.05)', fg: M_FG_DIM, label: '·' };
  const px = size === 'lg' ? '4px 9px' : '2px 7px';
  const fs = size === 'lg' ? 11 : 9.5;
  return (
    <span style={{
      display: 'inline-flex', alignItems: 'center', gap: 6, flexShrink: 0,
      padding: px, borderRadius: 999, background: tone.bg, color: tone.fg,
      fontSize: fs, fontFamily: 'JetBrains Mono, monospace', letterSpacing: '0.04em', fontWeight: 600,
    }}>
      <span style={{ width: 4, height: 4, borderRadius: 2, background: tone.fg, boxShadow: '0 0 5px ' + tone.fg }}/>
      {d.short}
    </span>
  );
}

// HISTORY — last 24h. Mix of devices (mostly this device + a few synced).
const A_HISTORY = [
  // Today
  { ts: '12:42', day: 'Today', title: 'Linear — Inbox',                  url: 'linear.app/inbox',                  fav: 'L', bg: '#5E6AD2',           device: 'thisIphone' },
  { ts: '12:18', day: 'Today', title: 'Ajna Browser · pull #284',        url: 'github.com/ajna-inc/browser/pull/284', fav: 'G', bg: '#24292F',         device: 'thisIphone' },
  { ts: '11:55', day: 'Today', title: 'P2P Sync RFC',                    url: 'notion.so/p2p-sync',                fav: 'N', bg: '#fff', c: '#000',  device: 'mac' },
  { ts: '11:30', day: 'Today', title: 'DIDComm v2 spec',                 url: 'identity.foundation/didcomm',       fav: 'D', bg: '#7C3AED',           device: 'thisIphone' },
  { ts: '10:48', day: 'Today', title: 'Stripe — Subscription metrics',   url: 'dashboard.stripe.com/sub',          fav: 'S', bg: '#635BFF',           device: 'ipad' },
  { ts: '10:30', day: 'Today', title: 'Hacker News',                     url: 'news.ycombinator.com',              fav: 'Y', bg: '#FF6600',           device: 'thisIphone' },
  { ts: '09:52', day: 'Today', title: 'Linear — Triage',                 url: 'linear.app/ajna/triage',            fav: 'L', bg: '#5E6AD2',           device: 'mac' },
  { ts: '09:14', day: 'Today', title: 'Posthog dashboard',               url: 'us.posthog.com/dashboard/ajna',     fav: 'P', bg: '#1D4ED8',           device: 'thisIphone' },
  { ts: '08:31', day: 'Today', title: 'GitHub · ajna-inc/browser',       url: 'github.com/ajna-inc/browser',       fav: 'G', bg: '#24292F',           device: 'thisIphone' },
  // Yesterday
  { ts: '23:08', day: 'Yesterday', title: 'Cloudflare D1 pricing',       url: 'developers.cloudflare.com/d1',      fav: 'C', bg: '#F38020',           device: 'mac' },
  { ts: '22:14', day: 'Yesterday', title: 'iA Writer',                   url: 'ia.net/writer',                     fav: 'i', bg: '#000',              device: 'thisIphone' },
  { ts: '20:02', day: 'Yesterday', title: 'Tailwind v4 blog',            url: 'tailwindcss.com/blog/v4',           fav: 'T', bg: '#0EA5E9',           device: 'thisIphone' },
  { ts: '19:33', day: 'Yesterday', title: 'Bluesky · @maya.ajna',        url: 'bsky.app/profile/maya.ajna',        fav: 'B', bg: '#0EA5E9',           device: 'ipad' },
  { ts: '14:11', day: 'Yesterday', title: 'Hyper.media · about',         url: 'hyper.media/about',                 fav: 'H', bg: '#0F172A',           device: 'thisIphone' },
  // Earlier
  { ts: 'May 25', day: 'Earlier this week', title: 'UCAN spec v0.10',                  url: 'ucan.xyz/spec',     fav: 'U', bg: '#1E40AF',           device: 'mac' },
  { ts: 'May 25', day: 'Earlier this week', title: 'Anthropic · introducing claude 4', url: 'anthropic.com/news',fav: 'A', bg: '#D4A27F',           device: 'thisIphone' },
  { ts: 'May 24', day: 'Earlier this week', title: 'Cloudflare Workers AI',            url: 'developers.cloudflare.com/workers-ai', fav: 'C', bg: '#F38020', device: 'ipad' },
  { ts: 'May 23', day: 'Earlier this week', title: 'Datasette deployments',            url: 'datasette.io',      fav: 'D', bg: '#FF7A45',           device: 'thisIphone' },
];

// Today's history summary by device
const A_HISTORY_STATS = [
  { device: 'thisIphone', count: 6 },
  { device: 'mac',        count: 2 },
  { device: 'ipad',       count: 1 },
];

// BOOKMARKS
const A_BOOKMARKS = [
  { title: 'Linear — Inbox',           url: 'linear.app/inbox',             fav: 'L', bg: '#5E6AD2', folder: 'Work',    saved: '4 days ago', shared: false, device: 'thisIphone' },
  { title: 'Ajna Browser',             url: 'github.com/ajna-inc/browser',  fav: 'G', bg: '#24292F', folder: 'Work',    saved: '6 days ago', shared: true,  device: 'thisIphone' },
  { title: 'P2P Sync RFC',             url: 'notion.so/p2p-sync',           fav: 'N', bg: '#fff', c: '#000', folder: 'Reading', saved: '2 days ago', shared: true,  device: 'mac' },
  { title: 'DIDComm v2 spec',          url: 'identity.foundation/didcomm',  fav: 'D', bg: '#7C3AED', folder: 'Reading', saved: '1 week ago', shared: false, device: 'thisIphone' },
  { title: 'Hacker News',              url: 'news.ycombinator.com',         fav: 'Y', bg: '#FF6600', folder: 'Daily',   saved: '1 month ago',shared: false, device: 'thisIphone' },
  { title: 'Hypermedia Protocol',      url: 'hyper.media',                  fav: 'H', bg: '#0F172A', folder: 'Reading', saved: '3 days ago', shared: true,  device: 'mac' },
  { title: 'UCAN spec',                url: 'ucan.xyz',                     fav: 'U', bg: '#1E40AF', folder: 'Reading', saved: '5 days ago', shared: false, device: 'mac' },
  { title: 'Linear · Triage',          url: 'linear.app/ajna/triage',       fav: 'L', bg: '#5E6AD2', folder: 'Work',    saved: '2 weeks ago',shared: true,  device: 'thisIphone' },
  { title: 'Posthog Dashboard',        url: 'us.posthog.com/dashboard/ajna',fav: 'P', bg: '#1D4ED8', folder: 'Work',    saved: '3 weeks ago',shared: true,  device: 'mac' },
  { title: 'Tailwind Docs',            url: 'tailwindcss.com/docs',         fav: 'T', bg: '#0EA5E9', folder: 'Work',    saved: '1 month ago',shared: false, device: 'thisIphone' },
  { title: 'iA Writer',                url: 'ia.net/writer',                fav: 'i', bg: '#000',    folder: 'Daily',   saved: '2 months',  shared: false, device: 'thisIphone' },
  { title: 'Cloudflare Status',        url: 'cloudflarestatus.com',         fav: 'C', bg: '#F38020', folder: 'Daily',   saved: '2 months',  shared: false, device: 'thisIphone' },
];
const A_BOOKMARK_FOLDERS = [
  { name: 'Work',    count: 5, color: '#5E6AD2', icon: 'briefcase' },
  { name: 'Reading', count: 4, color: '#A78BFA', icon: 'book' },
  { name: 'Daily',   count: 3, color: '#22D3EE', icon: 'sun' },
];

// DOWNLOADS — includes an in-progress example for the active row
const A_DOWNLOADS = [
  { name: 'P2P-Sync-RFC.pdf',     bytes: 1240000,  total: 1240000,  status: 'done',     time: '12 min ago',  source: 'notion.so/p2p-sync',           ext: 'PDF', bg: '#EF4444', verified: true,  hash: 'sha256:a4b9…3c12' },
  { name: 'design-system.fig',    bytes: 18400000, total: 18400000, status: 'done',     time: '34 min ago',  source: 'figma.com/file/ajna-ds',       ext: 'FIG', bg: '#A259FF', verified: true,  hash: 'sha256:7d11…ee0a' },
  { name: 'didcomm-v2.zip',       bytes: 6800000,  total: 6800000,  status: 'done',     time: '1 hr ago',    source: 'identity.foundation/didcomm',  ext: 'ZIP', bg: '#0EA5E9', verified: true,  hash: 'sha256:55fe…ab90' },
  { name: 'mesh-trace-may28.bin', bytes: 4_200_000, total: 24_500_000, status: 'active', time: 'Downloading',source: 'mediator.ajna.dev/traces',     ext: 'BIN', bg: '#10B981', verified: false, speed: '420 KB/s' },
  { name: 'ajna-keys-backup.kbx', bytes: 14000,    total: 14000,    status: 'done',     time: 'Yesterday',   source: 'ajna://export',                ext: 'KEY', bg: '#FBBF24', verified: true,  hash: 'sha256:c801…7732', encrypted: true },
  { name: 'screenshot-2026-05-28-at-9.41.png', bytes: 2_400_000, total: 2_400_000, status: 'done', time: 'Yesterday', source: 'macOS · share',         ext: 'PNG', bg: '#F472B6', verified: false },
];

// RECENTLY CLOSED tabs — grouped into sessions
const A_RECENTLY_CLOSED = [
  {
    session: '11:48 — 5 tabs closed',
    when: '14 minutes ago',
    tabs: [
      { title: 'Linear — Sprint planning', url: 'linear.app/ajna/cycle/24',     fav: 'L', bg: '#5E6AD2' },
      { title: 'Notion — Roadmap',         url: 'notion.so/ajna/roadmap',        fav: 'N', bg: '#fff', c: '#000' },
      { title: 'Figma — Mobile screens',   url: 'figma.com/file/mobile-v2',      fav: 'F', bg: '#A259FF' },
      { title: 'GitHub — issue #1284',     url: 'github.com/ajna-inc/browser/issues/1284', fav: 'G', bg: '#24292F' },
      { title: 'Posthog — funnels',        url: 'us.posthog.com/funnels',        fav: 'P', bg: '#1D4ED8' },
    ],
  },
  {
    session: '09:02 — 3 tabs closed',
    when: 'Today, 3 hours ago',
    tabs: [
      { title: 'DIDComm v2 spec',          url: 'identity.foundation/didcomm',   fav: 'D', bg: '#7C3AED' },
      { title: 'UCAN spec',                url: 'ucan.xyz/spec',                 fav: 'U', bg: '#1E40AF' },
      { title: 'Bluesky · @maya.ajna',     url: 'bsky.app/profile/maya.ajna',    fav: 'B', bg: '#0EA5E9' },
    ],
  },
  {
    session: 'Yesterday, 22:15 — 2 tabs closed',
    when: 'Yesterday',
    tabs: [
      { title: 'Tailwind v4 blog',         url: 'tailwindcss.com/blog/v4',       fav: 'T', bg: '#0EA5E9' },
      { title: 'iA Writer · v7',           url: 'ia.net/writer/blog/v7',         fav: 'i', bg: '#000' },
    ],
  },
];

// PASSWORDS — with health flags
const A_PASSWORDS_HEALTH = { compromised: 3, weak: 8, reused: 12, total: 128 };
const A_PASSWORDS = [
  { site: 'github.com',          domain: 'GitHub',         user: 'maya@ajna.dev',     last: '12m', fav: 'G', bg: '#24292F', flag: null },
  { site: 'linear.app',          domain: 'Linear',         user: 'maya@ajna.dev',     last: '1h',  fav: 'L', bg: '#5E6AD2', flag: null },
  { site: 'notion.so',           domain: 'Notion',         user: 'maya@ajna.dev',     last: '4h',  fav: 'N', bg: '#fff', c: '#000', flag: 'reused' },
  { site: 'dashboard.stripe.com',domain: 'Stripe',         user: 'maya+stripe@ajna.dev', last: '2d', fav: 'S', bg: '#635BFF', flag: null },
  { site: 'figma.com',           domain: 'Figma',          user: 'maya@ajna.dev',     last: '3d',  fav: 'F', bg: '#A259FF', flag: 'compromised' },
  { site: 'twitter.com',         domain: 'Twitter',        user: '@mayachen',         last: '2w',  fav: 'X', bg: '#000',  flag: 'weak' },
  { site: 'reddit.com',          domain: 'Reddit',         user: 'mayac',             last: '1mo', fav: 'r', bg: '#FF4500', flag: 'reused' },
  { site: 'us.posthog.com',      domain: 'PostHog',        user: 'maya@ajna.dev',     last: '2mo', fav: 'P', bg: '#1D4ED8', flag: null },
  { site: 'cloudflare.com',      domain: 'Cloudflare',     user: 'maya@ajna.dev',     last: '3mo', fav: 'C', bg: '#F38020', flag: null },
  { site: 'shop.macpaw.com',     domain: 'MacPaw',         user: 'maya+shop@ajna.dev',last: '6mo', fav: 'M', bg: '#FBBF24', c: '#000', flag: 'weak' },
];

// READING LIST
const A_READING_LIST = [
  { title: 'A short history of P2P browsing',      url: 'p2pbrowsing.org/history',         fav: 'P', bg: '#7C3AED',           read: false, saved: '2 hours ago', mins: 12, device: 'thisIphone', preview: 'The first peer-to-peer browser was…' },
  { title: 'Engineering an offline-first mesh',    url: 'engineering.ajna.dev/mesh',       fav: 'A', bg: 'linear-gradient(135deg,#6EE7B7,#60A5FA)', c: '#0B0C0F', read: false, saved: 'Yesterday',  mins: 18, device: 'mac',        preview: 'Going from 5 to 5000 peers without a server…' },
  { title: 'DIDComm vs ActivityPub',               url: 'identity.foundation/blog/c-vs-a', fav: 'D', bg: '#7C3AED',           read: true,  saved: '3 days ago',  mins: 9,  device: 'thisIphone', preview: 'Two protocols, two philosophies.' },
  { title: 'Cap-and-cap: rethinking auth',         url: 'ucan.xyz/blog/cap',               fav: 'U', bg: '#1E40AF',           read: false, saved: '5 days ago',  mins: 22, device: 'mac',        preview: 'Tokens are great until they are stolen.' },
  { title: 'Why offline-first is finally winning', url: 'localfirstweb.dev/post-2025',     fav: 'L', bg: '#10B981',           read: true,  saved: '1 week ago',  mins: 14, device: 'thisIphone', preview: 'CRDTs, mesh, and the long road back to local.' },
  { title: 'The reading list bug nobody fixed',    url: 'ia.net/writer/notes/list-bug',    fav: 'i', bg: '#000',              read: false, saved: '2 weeks ago', mins: 6,  device: 'ipad',       preview: 'It still happens in 2026. Here is why.' },
];

// SITE PERMISSIONS — counts + per-site list
const A_PERMS_SUMMARY = [
  { id: 'location',    label: 'Location',      allowed: 2, blocked: 5,  icon: 'pin',     color: '#FBBF24' },
  { id: 'camera',      label: 'Camera',        allowed: 1, blocked: 3,  icon: 'camera',  color: '#F472B6' },
  { id: 'mic',         label: 'Microphone',    allowed: 2, blocked: 2,  icon: 'mic',     color: '#22D3EE' },
  { id: 'notif',       label: 'Notifications', allowed: 4, blocked: 12, icon: 'bell',    color: '#A78BFA' },
  { id: 'clipboard',   label: 'Clipboard',     allowed: 0, blocked: 8,  icon: 'clip',    color: '#10B981' },
  { id: 'autoplay',    label: 'Autoplay',      allowed: 6, blocked: 4,  icon: 'play',    color: '#EF4444' },
  { id: 'cookies',     label: 'Cookies',       allowed: 23,blocked: 41, icon: 'cookie',  color: '#F59E0B' },
  { id: 'storage',     label: 'Storage',       allowed: 7, blocked: 0,  icon: 'disk',    color: '#60A5FA' },
];
const A_PERMS_SITES = [
  { domain: 'figma.com',           perms: { location: 'allow', camera: 'allow', mic: 'allow', notif: 'allow' } },
  { domain: 'meet.google.com',     perms: { camera: 'allow', mic: 'allow', notif: 'allow' } },
  { domain: 'linear.app',          perms: { notif: 'allow', clipboard: 'block' } },
  { domain: 'github.com',          perms: { notif: 'allow' } },
  { domain: 'twitter.com',         perms: { notif: 'block', autoplay: 'block' } },
  { domain: 'us.posthog.com',      perms: { storage: 'allow' } },
  { domain: 'maps.apple.com',      perms: { location: 'allow' } },
  { domain: 'dashboard.stripe.com',perms: { storage: 'allow', notif: 'allow' } },
];

Object.assign(window, {
  A_DEVICES, AConnChip,
  A_HISTORY, A_HISTORY_STATS,
  A_BOOKMARKS, A_BOOKMARK_FOLDERS,
  A_DOWNLOADS,
  A_RECENTLY_CLOSED,
  A_PASSWORDS, A_PASSWORDS_HEALTH,
  A_READING_LIST,
  A_PERMS_SUMMARY, A_PERMS_SITES,
});
