#!/usr/bin/env bash
set -e

echo "========================================================"
echo " Packaging MotoSolution Bangladesh for cPanel Deployment"
echo "========================================================"

# 1. Compile Vite frontend assets
echo "--> Compiling Vite production assets..."
npm run build

# 2. Optimize PHP composer dependencies
echo "--> Optimizing Composer dependencies..."
composer install --optimize-autoloader --no-dev

# 3. Create deployment zip
OUTPUT_ZIP="motosolution-cpanel-deploy.zip"
echo "--> Creating $OUTPUT_ZIP..."
rm -f "$OUTPUT_ZIP"

zip -r "$OUTPUT_ZIP" . \
  -x "node_modules/*" \
  -x ".git/*" \
  -x "storage/logs/*.log" \
  -x ".phpunit.result.cache" \
  -x ".gemini/*" \
  -x "package-cpanel.sh" \
  -x "$OUTPUT_ZIP"

echo "========================================================"
echo " Deployment ZIP successfully created: $OUTPUT_ZIP"
echo " File Size: $(du -sh $OUTPUT_ZIP | cut -f1)"
echo " Follow instructions in CPANEL_DEPLOYMENT_GUIDE.md"
echo "========================================================"
