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

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"

STAMP="$(date +%Y%m%d-%H%M%S)"
OUT_DIR="${1:-$HOME/.openclaw/backups/control-ui/$STAMP}"

mkdir -p "$OUT_DIR"

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

cat > "$OUT_DIR/README.txt" <<EOF
Backup created at: $(date)
JS: $TARGET_JS
HTML: $TARGET_HTML

Restore:
  bash /Users/guchen/.openclaw/workspace/scripts/restore-control-ui.sh $OUT_DIR
EOF

echo "Backup saved to: $OUT_DIR"