#!/bin/bash
# Deploy Updated Admin Files to Production

echo "=========================================="
echo "  Deploying Admin Panel Updates"
echo "=========================================="

SOURCE_DIR="/media/pts/Website/SkyArtShop/website/admin"
DEST_DIR="/var/www/skyartshop/admin"

# Check if source directory exists
if [ ! -d "$SOURCE_DIR" ]; then
    echo "❌ Source directory not found: $SOURCE_DIR"
    exit 1
fi

# Check if destination directory exists
if [ ! -d "$DEST_DIR" ]; then
    echo "❌ Destination directory not found: $DEST_DIR"
    exit 1
fi

echo ""
echo "📦 Copying updated admin files..."

# Copy auth.js (new file)
echo "  → Copying auth.js..."
cp "$SOURCE_DIR/js/auth.js" "$DEST_DIR/js/"

# Copy updated HTML files
echo "  → Copying updated HTML files..."
for file in dashboard.html homepage.html products.html portfolio.html blog.html pages.html menu.html settings.html users.html; do
    if [ -f "$SOURCE_DIR/$file" ]; then
        cp "$SOURCE_DIR/$file" "$DEST_DIR/"
        echo "    ✓ $file"
    fi
done

# Copy updated JS files
echo "  → Copying updated JS files..."
for file in products.js homepage.js blog.js portfolio.js pages.js settings.js users.js; do
    if [ -f "$SOURCE_DIR/js/$file" ]; then
        cp "$SOURCE_DIR/js/$file" "$DEST_DIR/js/"
        echo "    ✓ $file"
    fi
done

# Set proper permissions
echo ""
echo "🔒 Setting proper permissions..."
chmod -R 755 "$DEST_DIR"
chown -R pts:pts "$DEST_DIR"

# Verify auth.js was copied
if [ -f "$DEST_DIR/js/auth.js" ]; then
    echo ""
    echo "✅ auth.js deployed successfully"
else
    echo ""
    echo "❌ auth.js deployment failed"
    exit 1
fi

echo ""
echo "=========================================="
echo "  ✅ Deployment Complete!"
echo "=========================================="
echo ""
echo "Files deployed to: $DEST_DIR"
echo ""
echo "Next steps:"
echo "1. Clear browser cache (Ctrl+Shift+Delete)"
echo "2. Login to admin panel: http://localhost:5000/admin/login.html"
echo "3. Test navigation between sections"
echo ""
