"""CSS-like cutout placement: object-fit (cover/contain) + object-position."""
import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

from gnommo.renderer import _fit_filter


def check(name, cond):
    print(f"  {'PASS' if cond else 'FAIL'}  {name}")
    assert cond, name


# Defaults reproduce the long-standing cover+center string exactly (no render churn).
check(
    "cover/center == legacy scale+crop",
    _fit_filter(864, 864, 1.0, "cover", "center")
    == "scale=864:864:force_original_aspect_ratio=increase,crop=864:864:(iw-864)/2:(ih-864)/2",
)
check(
    "cover applies zoom",
    _fit_filter(864, 864, 1.5, "cover", "center").startswith("scale=1296:1296:"),
)

# cover anchors the crop by position.
check("cover/top crops from bottom (y=0)", ":(iw-864)/2:0" in _fit_filter(864, 864, 1.0, "cover", "top"))
check("cover/bottom (y=ih-H)", ":(iw-864)/2:(ih-864)" in _fit_filter(864, 864, 1.0, "cover", "bottom"))
check("cover/left (x=0)", "crop=864:864:0:(ih-864)/2" in _fit_filter(864, 864, 1.0, "cover", "left"))
check("cover/right (x=iw-W)", "crop=864:864:(iw-864):(ih-864)/2" in _fit_filter(864, 864, 1.0, "cover", "right"))

# contain shrinks to fit and pads; position places the padded video.
check(
    "contain/top fits inside, pads to top",
    _fit_filter(864, 864, 1.0, "contain", "top")
    == "scale=864:864:force_original_aspect_ratio=decrease,pad=864:864:(ow-iw)/2:0:color=0x00000000",
)
check("contain ignores zoom", "scale=864:864:" in _fit_filter(864, 864, 2.0, "contain", "center"))
check("contain/bottom pads to bottom", ":(ow-iw)/2:(oh-ih):" in _fit_filter(864, 864, 1.0, "contain", "bottom"))
check("contain/left pads to left", "pad=864:864:0:(oh-ih)/2" in _fit_filter(864, 864, 1.0, "contain", "left"))

print("\nAll object-fit/object-position tests passed.")
