#!/usr/bin/env bash
set -euo pipefail

# mosaic-wizard — Thin shell wrapper for the bundled TypeScript wizard
MOSAIC_HOME="${MOSAIC_HOME:-$HOME/.config/mosaic}"

# Look for the bundle in the installed location first, then the source repo
WIZARD_BIN="$MOSAIC_HOME/dist/mosaic-wizard.mjs"
if [[ ! -f "$WIZARD_BIN" ]]; then
  WIZARD_BIN="$(cd "$(dirname "$0")/.." && pwd)/dist/mosaic-wizard.mjs"
fi

if [[ ! -f "$WIZARD_BIN" ]]; then
  echo "[mosaic-wizard] ERROR: Wizard bundle not found." >&2
  echo "[mosaic-wizard] Re-install with: npm install -g @mosaic/mosaic" >&2
  exit 1
fi

if ! command -v node >/dev/null 2>&1; then
  echo "[mosaic-wizard] ERROR: Node.js is required but not found." >&2
  echo "[mosaic-wizard] Install Node.js 18+ from https://nodejs.org" >&2
  exit 1
fi

exec node "$WIZARD_BIN" "$@"
