export function getBlogImageUrl(
  image: string | null
): string {
  if (!image) {
    return "/images/blog-placeholder.jpg";
  }

  // Already a production URL
  if (
    image.startsWith("https://astrology.togwe.com")
  ) {
    return image;
  }

  // Convert old local Laravel URL
  if (
    image.includes("127.0.0.1:8000") ||
    image.includes("localhost:8000")
  ) {
    const url = new URL(image);

    return `https://astrology.togwe.com${url.pathname}`;
  }

  // If DB contains only storage path
  if (image.startsWith("/storage/")) {
    return `https://astrology.togwe.com${image}`;
  }

  return image;
}