# Show active workspace info including infrastructure list
# Sourced by bash after lib_minimal.nu is loaded — not meant to be run standalone

let ws_result = (workspace-active)
let ws_name = if (is-ok $ws_result) { $ws_result.ok } else { "" }

if ($ws_name | is-empty) {
    print 'No active workspace'
    exit 1
}

let info_result = (workspace-info $ws_name)
if not (is-ok $info_result) {
    print $"Error: ($info_result.err)"
    exit 1
}

let info = $info_result.ok

if not $info.exists {
    print $"Workspace '($ws_name)' not found in config"
    exit 1
}

print $"📊 Workspace: ($info.name)"
print $"   Path:      ($info.path)"
print $"   Last used: ($info.last_used)"

if ($info.default_infra | is-not-empty) {
    print $"   Default:   ($info.default_infra)"
}

print ""

if ($info.infrastructures | is-empty) {
    print "📁 Infrastructures: (none configured)"
} else {
    print "📁 Infrastructures:"
    $info.infrastructures | each {|inf|
        let srv_label = if $inf.servers == 1 { "1 server" } else { $"($inf.servers) servers" }
        let marker = if $inf.name == $info.default_infra { " ★" } else { "" }
        print $"   • ($inf.name) [($srv_label)]($marker)"
    } | ignore
}
