import { readFile } from "node:fs/promises";
import path from "node:path";

import { headers } from "next/headers";

import { portalBrandFromHeaders } from "@/lib/brand/portal-brand";

export const size = { width: 32, height: 32 };
export const contentType = "image/png";

export default async function Icon() {
  const brand = portalBrandFromHeaders(await headers());
  const file =
    brand.key === "myucap"
      ? path.join(process.cwd(), "public/brands/myucap/favicon.png")
      : path.join(process.cwd(), "public/favicon.png");
  const buf = await readFile(file);
  return new Response(buf, {
    headers: {
      "Content-Type": "image/png",
      "Cache-Control": "public, max-age=3600",
    },
  });
}
