#!/bin/bash
# Script to apply CSS/JS changes and bust cache
# Usage: ./scripts/apply-changes.sh

set -e

echo "============================================"
echo "Applying Website Changes"
echo "============================================"
echo ""

# Generate new version number
NEW_VERSION=$(date +%s)
echo "✓ New version: $NEW_VERSION"

# Update all HTML files with new version
cd /media/pts/Website/SkyArtShop/website/public
echo "✓ Updating HTML files..."
for file in *.html; do
  sed -i "s|navbar\.css?v=[0-9]*|navbar.css?v=$NEW_VERSION|g" "$file"
  sed -i "s|main\.css?v=[0-9]*|main.css?v=$NEW_VERSION|g" "$file"
  sed -i "s|page-overrides\.css?v=[0-9]*|page-overrides.css?v=$NEW_VERSION|g" "$file"
done

# Restart backend to clear cache
echo "✓ Restarting backend..."
pm2 restart skyartshop > /dev/null 2>&1
sleep 2

# Verify
echo "✓ Backend restarted"
echo ""
echo "Changes applied! New version: v=$NEW_VERSION"
echo ""
echo "NEXT STEPS:"
echo "1. Hard refresh your browser: Ctrl+Shift+R (or Cmd+Shift+R)"
echo "2. Test the changes on your website"
echo ""
