//go:build ignore

package main

import (
	"bytes"
	"log"
	"os"
	"path/filepath"

	"github.com/alecthomas/chroma/v2/formatters/html"
	"github.com/alecthomas/chroma/v2/styles"
)

func main() {
	lightStyle := styles.Get("github")
	if lightStyle == nil {
		log.Fatal("github style not found")
	}

	darkStyle := styles.Get("github-dark")
	if darkStyle == nil {
		log.Fatal("github-dark style not found")
	}

	formatter := html.New(html.WithClasses(true))

	var buf bytes.Buffer

	buf.WriteString("/* Auto-generated syntax highlighting CSS */\n")
	buf.WriteString("/* Generated by go generate - do not edit manually */\n\n")

	buf.WriteString("@media (prefers-color-scheme: light) {\n")
	if err := formatter.WriteCSS(&buf, lightStyle); err != nil {
		log.Fatalf("failed to write light style CSS: %v", err)
	}
	buf.WriteString("}\n\n")

	buf.WriteString("@media (prefers-color-scheme: dark) {\n")
	if err := formatter.WriteCSS(&buf, darkStyle); err != nil {
		log.Fatalf("failed to write dark style CSS: %v", err)
	}
	buf.WriteString("}\n")

	outputPath := filepath.Join("static", "syntax.css")
	if err := os.WriteFile(outputPath, buf.Bytes(), 0o644); err != nil {
		log.Fatalf("failed to write CSS file: %v", err)
	}

	log.Printf("Generated %s successfully", outputPath)
}
