#!/usr/bin/env python3
"""Taste gate for Lab micro-experiment. Exit 0 = pass, 1 = fail."""
from __future__ import annotations

import re
import sys
from pathlib import Path

BANNED_HEX = ("#667eea", "#764ba2", "#f093fb")
BANNED_PHRASES = (
    "unlock your potential",
    "cutting-edge",
    "synergize",
    "unprecedented value",
    "get started now",
)
EMOJI_ROW = re.compile(r"[✨🚀💡🎯]{2,}")


def check(html: str) -> list[str]:
    low = html.lower()
    fails: list[str] = []
    for hx in BANNED_HEX:
        if hx in low:
            fails.append(f"banned_hex:{hx}")
    for phrase in BANNED_PHRASES:
        if phrase in low:
            fails.append(f"banned_phrase:{phrase}")
    if EMOJI_ROW.search(html):
        fails.append("decorative_emoji_row")
    if "linear-gradient" in low and any(h in low for h in BANNED_HEX):
        fails.append("purple_gradient")
    return fails


def main(argv: list[str]) -> int:
    if len(argv) != 2:
        print("usage: check_taste.py <html-file>", file=sys.stderr)
        return 2
    path = Path(argv[1])
    html = path.read_text(encoding="utf-8")
    fails = check(html)
    if fails:
        print(f"FAIL {path.name}: " + ", ".join(fails))
        return 1
    print(f"PASS {path.name}")
    return 0


if __name__ == "__main__":
    raise SystemExit(main(sys.argv))
