<?xml version="1.0" encoding="utf-8" ?>
<Page
    x:Class="ServerMonitorManager_Desktop.ServersPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:ServerMonitorManager_Desktop">

    <Grid RowSpacing="12">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <Grid ColumnSpacing="12">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <StackPanel Spacing="3">
                <TextBlock Style="{StaticResource TitleTextBlockStyle}" Text="Серверы" />
                <TextBlock Foreground="{ThemeResource TextFillColorSecondaryBrush}" Text="Локальные SSH-профили и текущее состояние ресурсов" />
            </StackPanel>
            <CommandBar Grid.Column="1" Background="Transparent" DefaultLabelPosition="Right">
                <AppBarButton AutomationProperties.Name="Обновить все серверы" Click="RefreshButton_Click" Icon="Refresh" Label="Обновить" />
                <AppBarButton AutomationProperties.Name="Добавить сервер" Click="AddButton_Click" Icon="Add" Label="Добавить" />
                <AppBarButton AutomationProperties.Name="Изменить выбранный сервер" Click="EditButton_Click" Icon="Edit" Label="Изменить" />
                <AppBarButton AutomationProperties.Name="Удалить выбранный сервер" Click="DeleteButton_Click" Icon="Delete" Label="Удалить" />
            </CommandBar>
        </Grid>

        <InfoBar
            x:Name="EmptyServersInfo"
            Grid.Row="1"
            IsClosable="False"
            Message="Добавьте первый сервер. Пароли не сохраняются; мониторинг использует отдельный ограниченный SSH-ключ."
            Severity="Informational"
            Title="Список серверов пуст" />

        <ListView
            x:Name="ServerList"
            Grid.Row="2"
            AutomationProperties.Name="Список серверов"
            ItemsSource="{x:Bind Servers}"
            SelectionMode="Single">
            <ListView.ItemTemplate>
                <DataTemplate x:DataType="local:ServerViewModel">
                    <Grid MinHeight="88" Padding="4" ColumnSpacing="18">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="2*" />
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <StackPanel VerticalAlignment="Center" Spacing="2">
                            <TextBlock FontWeight="SemiBold" Text="{x:Bind Name}" />
                            <TextBlock Foreground="{ThemeResource TextFillColorSecondaryBrush}" Text="{x:Bind Endpoint}" />
                            <TextBlock Foreground="{ThemeResource TextFillColorSecondaryBrush}" Text="{x:Bind Status, Mode=OneWay}" />
                        </StackPanel>
                        <StackPanel Grid.Column="1" VerticalAlignment="Center" Spacing="6">
                            <TextBlock Text="{x:Bind CpuText, Mode=OneWay}" />
                            <ProgressBar Maximum="100" Value="{x:Bind CpuPercent, Mode=OneWay}" />
                        </StackPanel>
                        <StackPanel Grid.Column="2" VerticalAlignment="Center" Spacing="2">
                            <TextBlock Text="{x:Bind MemoryText, Mode=OneWay}" />
                            <TextBlock Foreground="{ThemeResource TextFillColorSecondaryBrush}" Text="{x:Bind DiskText, Mode=OneWay}" />
                            <TextBlock Foreground="{ThemeResource TextFillColorSecondaryBrush}" Text="{x:Bind HealthText, Mode=OneWay}" />
                        </StackPanel>
                        <TextBlock Grid.Column="3" VerticalAlignment="Center" Foreground="{ThemeResource TextFillColorSecondaryBrush}" Text="{x:Bind LatencyText, Mode=OneWay}" />
                        <Button
                            Grid.Column="4"
                            VerticalAlignment="Center"
                            AutomationProperties.Name="Подтвердить SSH host key"
                            Click="ConfirmHostKeyButton_Click"
                            Content="{x:Bind HostKeyConfirmationAction}" />
                    </Grid>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </Grid>
</Page>
