#!/bin/bash

echo "Building Next.js static files for cPanel deployment..."
echo ""

# Navigate to script directory
cd "$(dirname "$0")"

echo "Step 1: Installing dependencies..."
npm install
if [ $? -ne 0 ]; then
    echo "Error installing dependencies!"
    exit 1
fi

echo ""
echo "Step 2: Building static files..."
npm run build:static
if [ $? -ne 0 ]; then
    echo "Error building files!"
    exit 1
fi

echo ""
echo "Step 3: Copying .htaccess file..."
if [ -f .htaccess ]; then
    cp .htaccess out/.htaccess
    echo ".htaccess copied successfully!"
else
    echo "Warning: .htaccess file not found!"
fi

echo ""
echo "========================================"
echo "Build complete!"
echo "========================================"
echo ""
echo "Your static files are ready in the 'out' directory."
echo "Upload all files from the 'out' folder to your cPanel hosting."
echo ""
