#!/usr/bin/env bash
set -euo pipefail
GOV_DECK_ROOT="$(cd "$(dirname "$0")" && pwd)"
GOV_NODE="${GOV_NODE_BIN:-node}"
GOV_PYTHON="${GOV_PYTHON_BIN:-python3}"
mkdir -p "$GOV_DECK_ROOT/deliverables/qa"
"$GOV_NODE" "$GOV_DECK_ROOT/render.cjs"
# Use an explicit font config on macOS to avoid the bundled renderer's missing CJK fallback.
if [[ "$(uname)" == Darwin ]]; then
cat > "$GOV_DECK_ROOT/deliverables/qa/fonts.conf" <<XML
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig><dir>$HOME/Library/Fonts</dir><dir>/Library/Fonts</dir><dir>/System/Library/Fonts</dir><dir>/System/Library/Fonts/Supplemental</dir><cachedir>/tmp/codex-gov-ppt-fontcache</cachedir><alias><family>sans-serif</family><prefer><family>Microsoft YaHei</family></prefer></alias></fontconfig>
XML
export FONTCONFIG_FILE="$GOV_DECK_ROOT/deliverables/qa/fonts.conf"
fi
soffice --headless --convert-to pdf --outdir "$GOV_DECK_ROOT/deliverables" "$GOV_DECK_ROOT/deliverables/政府机关智慧食堂一体化解决方案.pptx"
pdftoppm -jpeg -r 100 "$GOV_DECK_ROOT/deliverables/政府机关智慧食堂一体化解决方案.pdf" "$GOV_DECK_ROOT/deliverables/qa/page"
"$GOV_PYTHON" "$GOV_DECK_ROOT/verify.py"
