#!/usr/bin/env bash
set -euo pipefail

if [[ $# -lt 1 ]]; then
  echo "Usage: $0 <backup_dir>"
  exit 1
fi

BACKUP_DIR="$1"
TARGET_JS="/usr/local/lib/node_modules/openclaw/dist/control-ui/assets/index-Qb3PJV7U.js"
TARGET_HTML="/usr/local/lib/node_modules/openclaw/dist/control-ui/index.html"

if [[ ! -f "$BACKUP_DIR/index-Qb3PJV7U.js" ]]; then
  echo "Missing backup file: $BACKUP_DIR/index-Qb3PJV7U.js"
  exit 1
fi
if [[ ! -f "$BACKUP_DIR/index.html" ]]; then
  echo "Missing backup file: $BACKUP_DIR/index.html"
  exit 1
fi

cp "$BACKUP_DIR/index-Qb3PJV7U.js" "$TARGET_JS"
cp "$BACKUP_DIR/index.html" "$TARGET_HTML"

echo "Restore complete."
echo "Now hard refresh Control UI (Ctrl+Shift+R)."
