#!/usr/bin/env bash
# scripts/demo — this product's demo: tests/demo.spec.ts run by the
# @norskvideo/ctl-test-harness demo driver (`ctl-demo`).
#
#   scripts/demo up                                  from source on a private daemon; Ctrl-C tears down
#   scripts/demo up --mode image --daemon reuse      the built image into YOUR live daemon
#   scripts/demo check                               headless; what CI runs
#   scripts/demo spec | down | ui                    the plan / teardown / a multiplexer layout
#
# The driver's private daemon is the released norsk-ctl the repo's flake pins,
# so this re-execs itself under `nix develop .#dev` when that binary is not on
# PATH, then delegates to the package's `demo` script (`bun run demo`).
#
# Copied verbatim from @norskvideo/ctl-dev-kit conventions/demo.sh and
# drift-gated: edit the dev-kit source and re-sync, never this copy.
set -euo pipefail

repo="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$repo"

if ! command -v norsk-ctl >/dev/null 2>&1; then
  if [ -n "${IN_NIX_SHELL:-}" ]; then
    echo "scripts/demo: norsk-ctl is not on PATH in this nix shell — the .#build shell carries no ctl; use \`nix develop .#dev\`" >&2
    exit 1
  fi
  exec nix develop "$repo#dev" --command "$repo/scripts/demo" "$@"
fi

exec bun run demo -- "$@"
