// build-css.js
import { createGenerator } from 'unocss'
import presetUno from '@unocss/preset-uno'
import { readFile, writeFile } from 'fs/promises'
import { glob } from 'glob'

const generator = createGenerator({
  presets: [presetUno()],
  theme: {
    colors: {
      primary: '#2e5a32',
      'primary-dark': '#1e3d22',
      secondary: '#d4af37',
      navy: '#0a2540',
      light: '#f8f9fa',
      gray: '#6c757d',
    }
  }
})

// Scan PHP files
const files = await glob('app/Modules/**/Views/**/*.php', { cwd: process.cwd(), absolute: true })

let content = ''
for (const file of files) {
  content += await readFile(file, 'utf8')
}

// ✅ CORRECT METHOD: Use .applyExtractors() + .generate()
const tokens = new Set()
await generator.applyExtractors(content, {}, tokens)
const { css } = await generator.generate(tokens, { minify: true })

await writeFile('public/css/uno.css', css)
console.log('✅ Success! Generated: public/css/uno.css')