#!/usr/bin/env bash
# Screenshots of the demo pool for the web site (site/images/), then the pictures (images.py) and the pages (pages.py).
#   games/xencenter-xenadmin-xcp-jumphp/tools/site/shots.sh            (from anywhere; demo pool only, never a real server)
#   SKIP_SHOTS=1 .../shots.sh                                       (keep the raw shots, rebuild pictures and pages)
set -euo pipefail
here="$(cd "$(dirname "$0")" && pwd)"
app="$(cd "$here/../.." && pwd)"
root="$(cd "$app/../.." && pwd)"
id="$(basename "$app")"
raw="var/screenshots/site-raw"
mkdir -p "$app/$raw"

if [ -z "${SKIP_SHOTS:-}" ]; then
  # frame -> name (the demo tour: VM General ~100, Performance ~290, Snapshots ~350)
  for item in 100:general 290:performance 350:snapshots; do
    frame="${item%%:*}" name="${item#*:}"
    echo "== $name (frame $frame)"
    (cd "$root" && JUMPHP_SCENE='App\Form\MainForm' JUMPHP_SCENE_PARAMS='{"demo":true}' \
      bin/jumphp shot "$id" "$frame" "$raw/$name.png")
  done
fi
# made by the game tests (bin/jumphp test): console, search, logs, wizards, dashboard, updates, folders, alerts...
for name in console search logs new-vm menu dashboard updates new-pool cross-pool new-sr-nfs new-network folders alerts-dialog; do
  [ -f "$app/var/screenshots/tests/$name.png" ] && cp "$app/var/screenshots/tests/$name.png" "$app/$raw/$name.png"
done

python3 "$here/images.py" "$app/$raw" "$app/site/images" "$app/assets"
python3 "$here/pages.py" "$app/site"
