// ── Browser Opener ─────────────────────────────────────────────────
// Opens the splash page in the user's default browser after an 8-second
// delay. The delay gives all services time to start before the user
// sees the loading screen.
// Cross-platform: uses start (Windows), open (Mac), or xdg-open (Linux).

import { execSync } from "node:child_process"
import { platform } from "node:os"

const url = process.argv[2] || "http://localhost:3001/splash"

const sleep = (ms) => new Promise((r) => setTimeout(r, ms))

async function main() {
  await sleep(8000)
  try {
    if (platform() === "win32") {
      execSync(`start "" "${url}"`, { stdio: "ignore", timeout: 5000 })
    } else if (platform() === "darwin") {
      execSync(`open "${url}"`, { stdio: "ignore", timeout: 5000 })
    } else {
      execSync(`xdg-open "${url}"`, { stdio: "ignore", timeout: 5000 })
    }
  } catch (e) {
    console.error("Failed to open browser:", e.message)
  }
}

main()
