#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")"
echo
printf '%s\n' '======================================' ' DriveLux Motors - Fresh Installer' '======================================'
if ! command -v node >/dev/null 2>&1; then
  echo 'ERROR: Node.js is required. Install Node.js 22 LTS or newer from https://nodejs.org/.' >&2
  exit 1
fi
node -e "const v=process.versions.node.split('.').map(Number); if(v[0]<22){console.error('Node.js 22 or newer is required.');process.exit(1)}"
if [ ! -f .env ]; then
  cp .env.example .env
  echo 'Created .env from .env.example. Add your Supabase credentials before using account/order features.'
fi
if command -v bun >/dev/null 2>&1; then
  echo 'Installing dependencies with Bun...'
  bun install --frozen-lockfile
else
  echo 'Bun not found; installing dependencies with npm...'
  npm install
fi
printf '\n%s\n' 'Dependencies installed.' 'Next: configure .env, then run npm run dev or bun run dev.'
