<Window x:Class="PerformanceMonitorLite.Windows.ManageServersWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Manage Servers"
        Height="500" Width="830"
        WindowStartupLocation="CenterOwner"
        Icon="/EDD.ico"
        Background="{DynamicResource BackgroundBrush}">
    <Window.Resources>
        <ResourceDictionary>
            <ContextMenu x:Key="DataGridContextMenu">
                <MenuItem Header="Edit" Click="EditMenuItem_Click"/>
                <MenuItem Header="Excluded Databases" Click="ExcludedDatabases_Click"/>
                <MenuItem Header="Delete" Click="DeleteMenuItem_Click"
                          Foreground="{DynamicResource ErrorBrush}"/>
                <Separator/>
                <MenuItem Header="Copy Cell" Click="CopyCell_Click">
                    <MenuItem.Icon><TextBlock Text="&#x1F4CB;"/></MenuItem.Icon>
                </MenuItem>
                <MenuItem Header="Copy Row" Click="CopyRow_Click">
                    <MenuItem.Icon><TextBlock Text="&#x1F4C4;"/></MenuItem.Icon>
                </MenuItem>
                <MenuItem Header="Copy All Rows" Click="CopyAllRows_Click">
                    <MenuItem.Icon><TextBlock Text="&#x1F4D1;"/></MenuItem.Icon>
                </MenuItem>
                <Separator/>
                <MenuItem Header="Export to CSV..." Click="ExportToCsv_Click">
                    <MenuItem.Icon><TextBlock Text="&#x1F4CA;"/></MenuItem.Icon>
                </MenuItem>
            </ContextMenu>
        </ResourceDictionary>
    </Window.Resources>
    <Grid Margin="16">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <!-- Header -->
        <StackPanel Grid.Row="0" Margin="0,0,0,12">
            <TextBlock Text="Manage Servers" FontSize="18" FontWeight="Bold" Foreground="{DynamicResource ForegroundBrush}"/>
            <TextBlock Text="Add, edit, or remove monitored SQL Servers" FontSize="12" Foreground="{DynamicResource ForegroundMutedBrush}" Margin="0,4,0,0"/>
        </StackPanel>

        <!-- Server Grid -->
        <DataGrid Grid.Row="1" x:Name="ServersGrid"
                  AutoGenerateColumns="False" IsReadOnly="True"
                  SelectionMode="Single"
                  Background="Transparent" BorderThickness="0"
                  HeadersVisibility="Column" GridLinesVisibility="Horizontal"
                  MouseDoubleClick="ServersGrid_MouseDoubleClick"
                  ContextMenu="{StaticResource DataGridContextMenu}">
            <DataGrid.Columns>
                <DataGridTextColumn Header="Display Name" Binding="{Binding DisplayNameWithIntent}" Width="150"/>
                <DataGridTextColumn Header="Server" Binding="{Binding ServerNameDisplay}" Width="200"/>
                <DataGridTextColumn Header="Auth" Binding="{Binding AuthenticationDisplay}" Width="100"/>
                <DataGridTextColumn Header="Installed Version" Binding="{Binding InstalledVersion}" Width="130"/>
                <DataGridTextColumn Header="Status" Binding="{Binding StatusDisplay}" Width="80"/>
                <DataGridTextColumn Header="Monthly Cost ($)" Binding="{Binding MonthlyCostUsd, StringFormat='{}{0:N0}'}" Width="120">
                    <DataGridTextColumn.ElementStyle>
                        <Style TargetType="TextBlock">
                            <Setter Property="HorizontalAlignment" Value="Right"/>
                        </Style>
                    </DataGridTextColumn.ElementStyle>
                </DataGridTextColumn>
                <DataGridTextColumn Header="Last Connected" Binding="{Binding LastConnected, StringFormat=yyyy-MM-dd HH:mm}" Width="140"/>
            </DataGrid.Columns>
        </DataGrid>

        <!-- Buttons -->
        <StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,12,0,0">
            <Button Content="Add Server" Click="AddButton_Click" Style="{StaticResource AccentButton}" Margin="0,0,8,0"/>
            <Button Content="Edit" Click="EditButton_Click" Margin="0,0,8,0"/>
            <Button Content="Excluded Databases" Click="ExcludedDatabases_Click" Margin="0,0,8,0"/>
            <Button Content="Credential Profiles…" Click="CredentialProfiles_Click" Margin="0,0,8,0"
                    ToolTip="Manage named, reusable credentials that many servers can share."/>
            <Button Content="Delete" Click="DeleteButton_Click" Margin="0,0,8,0"/>
            <Button Content="Close" Click="CloseButton_Click"/>
        </StackPanel>
    </Grid>
</Window>
