#!/bin/sh
set -e

echo "🔧 Generating runtime env config..."

ENV_FILE="/app/public/env.js"

cat <<EOF > $ENV_FILE
window.__ENV__ = {
  NEXT_PUBLIC_ENVIRONMENT: "${NEXT_PUBLIC_ENVIRONMENT}",
  NEXT_PUBLIC_BACK_END_DOMAIN: "${NEXT_PUBLIC_BACK_END_DOMAIN}",
  NEXT_PUBLIC_TIME_OUT_API: "${NEXT_PUBLIC_TIME_OUT_API}",
  NEXT_PUBLIC_RECAPTCHA_SITE_KEY: "${NEXT_PUBLIC_RECAPTCHA_SITE_KEY}"
};
EOF

echo "✅ Generated $ENV_FILE:"
cat $ENV_FILE

echo "🚀 Starting Next.js..."
exec "$@"

