export const BLOG_SITES = [
  {
    key: "research",
    title: "Research",
    description:
      "Notes from papers I am reading, and mini-surveys of themes I'm learning about.",
    url: "https://research.neeldhara.blog",
  },
  {
    key: "vibes",
    title: "Vibes",
    description:
      "Conversations with LLMs with an intent to create something meaningful.",
    url: "https://vibes.neeldhara.blog",
  },
  {
    key: "puzzles",
    title: "Puzzles",
    description:
      "Problems, puzzles, contest editorials, and mathematical magic.",
    url: "https://puzzles.neeldhara.blog",
  },
  {
    key: "reflections",
    title: "Reflections",
    description: "Random musings, pseudo-advice, how-tos. Core dumped.",
    url: "https://reflections.neeldhara.blog",
  },
  {
    key: "poetry",
    title: "Pieces",
    description: "Poems, short prose, and small experiments in language.",
    url: "https://pieces.neeldhara.blog",
  },
  {
    key: "reviews",
    title: "Reviews",
    description:
      "Reviews of things I use or consume: software, books, hardware, etc.",
    url: "https://reviews.neeldhara.blog",
  },
  {
    key: "art",
    title: "Art",
    description:
      "This exists so I can stay accountable to my doodling practice :)",
    url: "https://art.neeldhara.blog",
  },
];

export const DEFAULT_BLOG_SITE_KEY = "reviews";
export const BLOG_SITE_KEYS = BLOG_SITES.map((site) => site.key);

function getEnvironmentBlogSiteKey() {
  if (typeof process === "undefined") {
    return undefined;
  }

  return process.env?.BLOG_SITE;
}

export function getBlogSite(key = getEnvironmentBlogSiteKey()) {
  const normalizedKey = key || DEFAULT_BLOG_SITE_KEY;
  const site = BLOG_SITES.find((candidate) => candidate.key === normalizedKey);

  if (!site) {
    throw new Error(
      `Unknown BLOG_SITE "${normalizedKey}". Expected one of: ${BLOG_SITE_KEYS.join(", ")}`,
    );
  }

  return site;
}

export const ACTIVE_BLOG_SITE = getBlogSite();
