#!/usr/bin/env bash
# Capture the current screen to $PL_SHOT (emulator via adb, else headless Chrome).
#   tool/dev/app-shot.sh [out.png]
set -uo pipefail
source "$(dirname "$0")/env.sh"
out="${1:-$PL_SHOT}"; mkdir -p "$(dirname "$out")"
device="$(pl_device)"
if [ -n "$device" ]; then
  adb -s "$device" exec-out screencap -p > "$out" || { echo "screencap failed"; exit 1; }
  echo "screenshot ($device, $(adb -s "$device" shell wm size | awk '{print $NF}')): $out"
else
  pl_ensure_chrome || exit 1
  node "$PL_APP_DIR/tool/dev/browser.mjs" shot "$out" || exit 1
fi
