import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';

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

// Import branding config dynamically
const brandingModule = await import('./src/config/branding.js');
const branding = brandingModule.branding;

const manifest = {
  name: branding.app.name,
  short_name: branding.app.shortName,
  description: branding.app.description,
  start_url: "/",
  display: "standalone",
  background_color: "#1f2937",
  theme_color: branding.meta.themeColor,
  orientation: "any",
  scope: "/",
  icons: [
    {
      src: "/favicon.svg",
      sizes: "any",
      type: "image/svg+xml"
    },
    {
      src: "/icon-192.png",
      sizes: "192x192",
      type: "image/png",
      purpose: "any maskable"
    },
    {
      src: "/icon-512.png",
      sizes: "512x512",
      type: "image/png",
      purpose: "any maskable"
    },
    {
      src: "/favicon.svg",
      sizes: "512x512",
      type: "image/svg+xml",
      purpose: "any"
    }
  ],
  screenshots: [],
  categories: ["entertainment", "games", "utilities"],
  shortcuts: [
    {
      name: "Pick a Game",
      short_name: "Pick",
      description: "Go directly to the game picker",
      url: "/picker",
      icons: []
    },
    {
      name: "Session History",
      short_name: "History",
      description: "View past gaming sessions",
      url: "/history",
      icons: []
    }
  ]
};

// Write manifest to public directory
const publicDir = path.join(__dirname, 'public');
const manifestPath = path.join(publicDir, 'manifest.json');

fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2), 'utf8');

console.log('✅ Generated manifest.json from branding config');

