// Command twcss compiles a Tailwind v4 stylesheet with kjol's native engine,
// scanning explicit content globs for utility candidates. Unlike the app bundler
// (which is wired to the frontend tree) it takes the entry, output, and content
// globs as flags/args, so it works for markup authored in any language — used by
// the kjol-web site, whose Go/WASM half writes its UI in Go.
//
// Usage (globs are relative to -base; pass "**" for a recursive walk):
//
//	twcss -entry css/app.css -out wwwroot/app.css -base . 'webui/**/*.go' 'app/**/*.go'
package main

import (
	"flag"
	"fmt"
	"os"

	"kjol/tw"
)

func main() {
	entry := flag.String("entry", "", "path to the Tailwind entry stylesheet")
	out := flag.String("out", "", "output CSS path")
	base := flag.String("base", ".", "base dir the content globs are relative to")
	flag.Parse()

	if *entry == "" || *out == "" {
		fmt.Fprintln(os.Stderr, "twcss: -entry and -out are required")
		os.Exit(2)
	}
	src, err := os.ReadFile(*entry)
	if err != nil {
		fmt.Fprintln(os.Stderr, "twcss:", err)
		os.Exit(1)
	}
	css, err := tw.CompileFiles(string(src), *base, flag.Args())
	if err != nil {
		fmt.Fprintln(os.Stderr, "twcss:", err)
		os.Exit(1)
	}
	if err := os.WriteFile(*out, []byte(css), 0o644); err != nil {
		fmt.Fprintln(os.Stderr, "twcss:", err)
		os.Exit(1)
	}
	fmt.Printf("twcss: wrote %s (%d bytes)\n", *out, len(css))
}
