import sharp from "sharp";
import path from "node:path";
import { mkdir } from "node:fs/promises";
import { fileURLToPath } from "node:url";

const __dirname = path.dirname(fileURLToPath(import.meta.url));

const SRC = path.resolve(__dirname, "../public/brand/orthoglobe-logo.png");
const OUT_DIR = path.resolve(__dirname, "../public/brand");
const SIZES = [128, 256, 512, 1024];

async function main() {
  await mkdir(OUT_DIR, { recursive: true });

  for (const size of SIZES) {
    await sharp(SRC)
      .resize({ width: size, fit: "contain", background: { r: 0, g: 0, b: 0, alpha: 0 } })
      .webp({ quality: 90 })
      .toFile(path.join(OUT_DIR, `orthoglobe-logo-${size}.webp`));

    await sharp(SRC)
      .resize({ width: size, fit: "contain", background: { r: 0, g: 0, b: 0, alpha: 0 } })
      .png({ compressionLevel: 9 })
      .toFile(path.join(OUT_DIR, `orthoglobe-logo-${size}.png`));

    console.log(`✓ generated orthoglobe-logo-${size}.{webp,png}`);
  }

  // Favicon: 32x32 from the source
  await sharp(SRC)
    .resize({ width: 32, fit: "contain", background: { r: 255, g: 255, b: 255, alpha: 255 } })
    .png()
    .toFile(path.join(OUT_DIR, "favicon-32.png"));
  console.log("✓ generated favicon-32.png");
}

main().catch((e) => {
  console.error(e);
  process.exit(1);
});
