#!/bin/sh

set -eu

config_dir=${1:-"$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)"}

for appearance in dark light no-preference; do
    config_file="$config_dir/$appearance-theme.auto.conf"
    if [ ! -f "$config_file" ]; then
        echo "not ok - missing $appearance automatic Kitty theme" >&2
        exit 1
    fi

    kitty +runpy '
from kitty.config import load_config
import sys

options = load_config(sys.argv[1])
if options.macos_titlebar_color != 1:
    raise SystemExit(
        f"{sys.argv[2]} automatic Kitty theme does not use its background "
        "for the macOS titlebar"
    )
' "$config_file" "$appearance"
done

echo "ok - automatic Kitty themes match their macOS titlebars"
