import { giffgaffEsimWhiteCard } from "./articles/giffgaff-esim-white-card";
import { lebronJamesLakersFarewell } from "./articles/lebron-james-lakers-farewell";
import { nikoMajorChampion } from "./articles/niko-major-champion";
import type { LifePost } from "./types";

const allLifePosts = [
  lebronJamesLakersFarewell,
  giffgaffEsimWhiteCard,
  nikoMajorChampion,
] as const satisfies readonly LifePost[];

function toLifePostTimestamp(date: string) {
  return Date.parse(date.replace(/\./g, "-"));
}

export const lifePosts = [...allLifePosts].sort(
  (postA, postB) => toLifePostTimestamp(postB.date) - toLifePostTimestamp(postA.date),
) as readonly LifePost[];

export function getLifePost(slug: string) {
  return lifePosts.find((post) => post.slug === slug);
}
