/**
 * Changelog bundlowany z apką → ZAWSZE zgodny z tym, co przyszło OTA (te same zmiany
 * lecą w tym samym bundlu). WhatsNewModal pokazuje wpisy nowsze niż ostatnio widziany
 * (`lastSeenChangelogId` w SecureStore) i oznacza najnowszy jako przeczytany.
 *
 * Przy każdym publish OTA: DOPISZ nowy wpis NA GÓRZE (newest-first), z nowym `id`.
 * Treść user-facing (bez wewnętrznego żargonu) — to widzi użytkownik.
 */
export type ChangelogEntry = {
  /** Stabilny, rosnący identyfikator (np. data + seq). Newest-first w CHANGELOG. */
  id: string;
  /** Krótki, ludzki tytuł daty/wersji pokazywany w nagłówku wpisu. */
  date: string;
  /** Punkty zmian — krótkie, user-facing. */
  items: string[];
};

export const CHANGELOG: ChangelogEntry[] = [
  {
    id: '2026-07-02b',
    date: 'July 2026',
    items: [
      'Fixed a case where a removed or briefly-failing video could get stuck on "Reconnecting" instead of playing or showing the error.',
      'Quick play no longer occasionally re-opens the player by itself after you mark a source broken.',
    ],
  },
  {
    id: '2026-07-02',
    date: 'July 2026',
    items: [
      'Favorites "+N new" now counts genuinely new scenes only, bulk back-catalog imports (old content a site re-dated to today) no longer inflate the badge or show a NEW tag.',
    ],
  },
  {
    id: '2026-07-01b',
    date: 'July 2026',
    items: [
      'Quick play: tap the ▶ on any thumbnail to start the best source right away, with a default quality set (Settings → Playback) it is one tap to video.',
    ],
  },
  {
    id: '2026-07-01',
    date: 'July 2026',
    items: [
      'Set a default video quality in Settings → Playback (e.g. 720p) to skip the quality chooser when that quality is available.',
      'The "+N new" count on a favorite now matches what you actually see when you open it, no more "+6" with nothing new.',
      'Smoother scrolling: when fresh scenes land at the top of a list, it no longer jumps under your finger.',
      'Fixed: a video that plays fine no longer flashes "Playback failed / Mark broken" while it reconnects.',
    ],
  },
  {
    id: '2026-06-29b',
    date: 'June 2026',
    items: [
      'Seeking (swipe or drag) no longer pops a big pause button into the middle of the screen.',
      'Diagnostics "open in browser" now opens privately inside the app (incognito), no cookies, no trace in your real browser.',
    ],
  },
  {
    id: '2026-06-29',
    date: 'June 2026',
    items: [
      'No more brief blast of sound when a video page is opening, it stays muted until you tap.',
    ],
  },
  {
    id: '2026-06-26',
    date: 'June 2026',
    items: [
      'Source code moved to our own server (git.goon-foss.org) — still fully open source (MIT). The Settings link now points there.',
    ],
  },
  {
    id: '2026-06-25',
    date: 'June 2026',
    items: [
      'sxyprn and a few other sites: if a video fails to start, the app now grabs a fresh link and retries automatically instead of just hanging.',
    ],
  },
  {
    id: '2026-06-22b',
    date: 'June 2026',
    items: [
      'New: a quick tutorial on first launch — tabs, search, long-press actions and player gestures. Replay it anytime from Settings ⚙.',
    ],
  },
  {
    id: '2026-06-22',
    date: 'June 2026',
    items: [
      'Sites now show a 0-5★ rating — how fresh, how well-described, and how reliably each source plays. Tap the stars for the breakdown.',
      'Dropped two sources whose videos stopped playing (they served a "server down" clip).',
      'latestpornvideo now keeps up with its newest videos.',
    ],
  },
  {
    id: '2026-06-21b',
    date: 'June 2026',
    items: [
      'Filter movies by performer (Movies → Filter → Performers).',
      'Movies grid fits more per screen (3 columns).',
    ],
  },
  {
    id: '2026-06-21',
    date: 'June 2026',
    items: [
      'Double-tap to skip no longer flashes a pause button in the middle of the screen.',
      'Movies show fewer, de-duplicated playback links (no more repeats from mirror sites).',
    ],
  },
  {
    id: '2026-06-20c',
    date: 'June 2026',
    items: [
      'Cleaner site names (dropped the .com/.org clutter).',
      'siska scenes work again (and their newer videos play).',
    ],
  },
  {
    id: '2026-06-20b',
    date: 'June 2026',
    items: [
      'Hide content you never want to see: Settings → Hidden content lets you hide any tag, performer or studio (and undo it).',
    ],
  },
  {
    id: '2026-06-20',
    date: 'June 2026',
    items: [
      'Going back to the list from a scene no longer reloads everything or slows the phone.',
    ],
  },
  {
    id: '2026-06-19',
    date: 'June 2026',
    items: [
      'Smoother scrolling on long scene lists — no more lag or phone slowdown.',
      'fpo.xxx scenes now play the actual video instead of an ad.',
    ],
  },
  {
    id: '2026-06-16',
    date: 'June 2026',
    items: [
      'Grid columns: pick 1, 2 or 3 thumbnails per row in Settings (1 = bigger previews).',
      'Filter scenes by minimum length — hide short clips (5/10/20/30+ min).',
      'Save searches: tap ☆ Save next to the search box, then reuse them as chips.',
      'Privacy: the app is hidden in Recents and blocks screenshots again.',
      'Smoother startup when an update is downloading (no more double PIN prompt).',
    ],
  },
  {
    id: '2026-06-13',
    date: 'June 2026',
    items: [
      'Source code link added in Settings — the app is open source (MIT).',
      'New: a Refresh thumbnail button on a scene when its preview is broken or stale.',
      'Fewer dead links — deleted videos on some sites are now detected automatically.',
    ],
  },
  {
    id: '2026-06-12',
    date: 'June 2026',
    items: [
      'Favorites now has a Scenes tab — every scene you heart shows up there.',
      'Your bug reports can get replies: tap the ? button, then "Your messages".',
      'More reliable playback and lower data use on several sites.',
      'Clearer message when a source is blocked in your region or by your network.',
    ],
  },
];

export const NEWEST_CHANGELOG_ID = CHANGELOG.length ? CHANGELOG[0].id : null;

/** Wpisy nowsze niż `lastSeenId`. lastSeen=null (pierwsze uruchomienie) → tylko najnowszy
 *  (nie zrzucamy całej historii). lastSeen == najnowszy → pusto (nic do pokazania). */
export function unseenEntries(lastSeenId: string | null): ChangelogEntry[] {
  if (!CHANGELOG.length) return [];
  if (!lastSeenId) return [CHANGELOG[0]];
  const idx = CHANGELOG.findIndex((e) => e.id === lastSeenId);
  if (idx === -1) return [CHANGELOG[0]]; // nieznany marker → pokaż tylko najnowszy
  return CHANGELOG.slice(0, idx);
}
