/**
 * pair.html entry (v0.9) — add-machine onboarding. No inline script (strict CSP).
 */
import { readConfig } from '../config'
import { createApiClient } from '../api-client'
import { mountAddMachine } from '../add-machine'

function boot(): void {
  const cfg = readConfig(window.location)
  const root = document.getElementById('pair')
  if (!root) return
  const api = createApiClient(cfg)
  const add = mountAddMachine(root, api, {
    onPaired: () => window.location.assign('/dashboard.html'),
  })
  void add.start()
}

if (document.readyState === 'loading') {
  document.addEventListener('DOMContentLoaded', boot)
} else {
  boot()
}
