<Window x:Class="PerformanceMonitorDashboard.CollectionLogWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        Title="Collection History" Height="600" Width="1000"
        WindowStartupLocation="CenterOwner"
        Background="{DynamicResource BackgroundBrush}">
    <Window.Resources>
        <ContextMenu x:Key="DataGridContextMenu">
            <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>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <!-- Header -->
        <Border Grid.Row="0" Background="{DynamicResource BackgroundLightBrush}" Padding="10" Margin="10,10,10,0">
            <StackPanel>
                <TextBlock x:Name="CollectorNameText" FontSize="16" FontWeight="Bold"/>
                <TextBlock x:Name="SummaryText" Margin="0,5,0,0"/>
            </StackPanel>
        </Border>

        <!-- Data Grid -->
        <DataGrid Grid.Row="1" x:Name="LogDataGrid"
                  AutoGenerateColumns="False"
                  IsReadOnly="True"
                  CanUserSortColumns="True"
                  AlternatingRowBackground="{DynamicResource BackgroundLightBrush}"
                  GridLinesVisibility="All"
                  Margin="10"
                  ContextMenu="{StaticResource DataGridContextMenu}">
            <DataGrid.Columns>
                <DataGridTextColumn Binding="{Binding CollectionTime, Converter={StaticResource ServerTimeConverter}}" Width="150">
                    <DataGridTextColumn.Header>
                        <StackPanel Orientation="Horizontal">
                            <Button x:Name="CollectionTimeFilterButton" Style="{DynamicResource ColumnFilterButtonStyle}" Tag="CollectionTime" Click="LogFilter_Click" Margin="0,0,4,0"/>
                            <TextBlock Text="Collection Time" FontWeight="Bold" VerticalAlignment="Center"/>
                        </StackPanel>
                    </DataGridTextColumn.Header>
                </DataGridTextColumn>
                <DataGridTextColumn Binding="{Binding CollectionStatus}" Width="100">
                    <DataGridTextColumn.Header>
                        <StackPanel Orientation="Horizontal">
                            <Button x:Name="StatusFilterButton" Style="{DynamicResource ColumnFilterButtonStyle}" Tag="CollectionStatus" Click="LogFilter_Click" Margin="0,0,4,0"/>
                            <TextBlock Text="Status" FontWeight="Bold" VerticalAlignment="Center"/>
                        </StackPanel>
                    </DataGridTextColumn.Header>
                </DataGridTextColumn>
                <DataGridTextColumn Binding="{Binding RowsCollected}" ElementStyle="{StaticResource NumericCell}" Width="120">
                    <DataGridTextColumn.Header>
                        <StackPanel Orientation="Horizontal">
                            <Button x:Name="RowsCollectedFilterButton" Style="{DynamicResource ColumnFilterButtonStyle}" Tag="RowsCollected" Click="LogFilter_Click" Margin="0,0,4,0"/>
                            <TextBlock Text="Rows Collected" FontWeight="Bold" VerticalAlignment="Center"/>
                        </StackPanel>
                    </DataGridTextColumn.Header>
                </DataGridTextColumn>
                <DataGridTextColumn Binding="{Binding DurationMs, StringFormat='{}{0:N0}'}" ElementStyle="{StaticResource NumericCell}" Width="110">
                    <DataGridTextColumn.Header>
                        <StackPanel Orientation="Horizontal">
                            <Button x:Name="DurationFilterButton" Style="{DynamicResource ColumnFilterButtonStyle}" Tag="DurationMs" Click="LogFilter_Click" Margin="0,0,4,0"/>
                            <TextBlock Text="Duration (ms)" FontWeight="Bold" VerticalAlignment="Center"/>
                        </StackPanel>
                    </DataGridTextColumn.Header>
                </DataGridTextColumn>
                <DataGridTextColumn Binding="{Binding ErrorMessage}" Width="*">
                    <DataGridTextColumn.Header>
                        <StackPanel Orientation="Horizontal">
                            <Button x:Name="ErrorMessageFilterButton" Style="{DynamicResource ColumnFilterButtonStyle}" Tag="ErrorMessage" Click="LogFilter_Click" Margin="0,0,4,0"/>
                            <TextBlock Text="Error Message" FontWeight="Bold" VerticalAlignment="Center"/>
                        </StackPanel>
                    </DataGridTextColumn.Header>
                </DataGridTextColumn>
            </DataGrid.Columns>
        </DataGrid>

        <!-- Footer -->
        <Border Grid.Row="2" Background="{DynamicResource BackgroundLightBrush}" Padding="10" Margin="10,0,10,10">
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
                <Button Content="Close" Width="100" Height="30" Click="Close_Click"/>
            </StackPanel>
        </Border>
    </Grid>
</Window>
