# Spustí server a klienta v samostatných panelech jednoho okna Windows Terminalu.
# Vyžaduje Windows Terminal (wt.exe) — výchozí součást Windows 11.

$ErrorActionPreference = 'Stop'
$ScriptDir = $PSScriptRoot

Push-Location (Join-Path $ScriptDir 'types')
try { yarn openapi-ts } finally { Pop-Location }

if (-not (Get-Command wt.exe -ErrorAction SilentlyContinue)) {
    Write-Error "wt.exe (Windows Terminal) nebyl nalezen. Nainstalujte z Microsoft Store nebo použijte run_dev.sh v WSL."
    exit 1
}

$serverDir = Join-Path $ScriptDir 'server'
$clientDir = Join-Path $ScriptDir 'client'

# wt splits on ';' before respecting quoting, so encode the compound server command to avoid it
$serverCmd    = '$env:NODE_ENV = ''development''; yarn startReload'
$serverCmdB64 = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($serverCmd))

wt -w 0 new-tab --title 'luncher-server' -d $serverDir pwsh -NoExit -EncodedCommand $serverCmdB64 `; `
   split-pane -H --title 'luncher-client' -d $clientDir pwsh -NoExit -Command "yarn start"
