<UserControl x:Class="PerformanceMonitorDashboard.Controls.CriticalIssuesContent"
             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"
             xmlns:controls="clr-namespace:PerformanceMonitorDashboard.Controls"
             mc:Ignorable="d"
             d:DesignHeight="450" d:DesignWidth="800">
    <UserControl.Resources>
        <ResourceDictionary>
            <!-- Context Menu for DataGrid Copy/Export -->
            <ContextMenu x:Key="DataGridContextMenu">
                <MenuItem Header="Copy Cell" Click="CopyCell_Click">
                    <MenuItem.Icon><TextBlock Text="📋"/></MenuItem.Icon>
                </MenuItem>
                <MenuItem Header="Copy Row" Click="CopyRow_Click">
                    <MenuItem.Icon><TextBlock Text="📄"/></MenuItem.Icon>
                </MenuItem>
                <MenuItem Header="Copy All Rows" Click="CopyAllRows_Click">
                    <MenuItem.Icon><TextBlock Text="📑"/></MenuItem.Icon>
                </MenuItem>
                <Separator/>
                <MenuItem Header="Export to CSV..." Click="ExportToCsv_Click">
                    <MenuItem.Icon><TextBlock Text="📊"/></MenuItem.Icon>
                </MenuItem>
            </ContextMenu>

            <Style x:Key="DefaultRowStyle" TargetType="DataGridRow">
                <Setter Property="ContextMenu" Value="{StaticResource DataGridContextMenu}"/>
            </Style>
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid>
    <DataGrid x:Name="CriticalIssuesDataGrid"
              AutoGenerateColumns="False"
              IsReadOnly="True"
              CanUserSortColumns="True"
              GridLinesVisibility="All" CanUserResizeColumns="True"
              RowStyle="{StaticResource DefaultRowStyle}">
        <DataGrid.Columns>
            <DataGridTemplateColumn Header="Action" Width="80">
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <Button Content="Investigate" Click="Investigate_Click" Padding="4,2" FontSize="11"/>
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>
            <DataGridTextColumn Binding="{Binding IssueId}" ElementStyle="{StaticResource NumericCell}" Width="80">
                <DataGridTextColumn.Header>
                    <StackPanel Orientation="Horizontal">
                        <Button Style="{DynamicResource ColumnFilterButtonStyle}" Tag="IssueId" Click="CriticalIssuesFilter_Click" Margin="0,0,4,0"/>
                        <TextBlock Text="Issue ID" FontWeight="Bold" VerticalAlignment="Center"/>
                    </StackPanel>
                </DataGridTextColumn.Header>
            </DataGridTextColumn>
            <DataGridTextColumn Binding="{Binding LogDate, Converter={StaticResource ServerTimeConverter}}" Width="160">
                <DataGridTextColumn.Header>
                    <StackPanel Orientation="Horizontal">
                        <Button Style="{DynamicResource ColumnFilterButtonStyle}" Tag="LogDate" Click="CriticalIssuesFilter_Click" Margin="0,0,4,0"/>
                        <TextBlock Text="Log Date" FontWeight="Bold" VerticalAlignment="Center"/>
                    </StackPanel>
                </DataGridTextColumn.Header>
            </DataGridTextColumn>
            <DataGridTextColumn Binding="{Binding Severity}" Width="100">
                <DataGridTextColumn.Header>
                    <StackPanel Orientation="Horizontal">
                        <Button Style="{DynamicResource ColumnFilterButtonStyle}" Tag="Severity" Click="CriticalIssuesFilter_Click" Margin="0,0,4,0"/>
                        <TextBlock Text="Severity" FontWeight="Bold" VerticalAlignment="Center"/>
                    </StackPanel>
                </DataGridTextColumn.Header>
            </DataGridTextColumn>
            <DataGridTextColumn Binding="{Binding ProblemArea}" Width="150">
                <DataGridTextColumn.Header>
                    <StackPanel Orientation="Horizontal">
                        <Button Style="{DynamicResource ColumnFilterButtonStyle}" Tag="ProblemArea" Click="CriticalIssuesFilter_Click" Margin="0,0,4,0"/>
                        <TextBlock Text="Problem Area" FontWeight="Bold" VerticalAlignment="Center"/>
                    </StackPanel>
                </DataGridTextColumn.Header>
            </DataGridTextColumn>
            <DataGridTextColumn Binding="{Binding SourceCollector}" Width="150">
                <DataGridTextColumn.Header>
                    <StackPanel Orientation="Horizontal">
                        <Button Style="{DynamicResource ColumnFilterButtonStyle}" Tag="SourceCollector" Click="CriticalIssuesFilter_Click" Margin="0,0,4,0"/>
                        <TextBlock Text="Source Collector" FontWeight="Bold" VerticalAlignment="Center"/>
                    </StackPanel>
                </DataGridTextColumn.Header>
            </DataGridTextColumn>
            <DataGridTextColumn Binding="{Binding AffectedDatabase}" Width="150">
                <DataGridTextColumn.Header>
                    <StackPanel Orientation="Horizontal">
                        <Button Style="{DynamicResource ColumnFilterButtonStyle}" Tag="AffectedDatabase" Click="CriticalIssuesFilter_Click" Margin="0,0,4,0"/>
                        <TextBlock Text="Affected Database" FontWeight="Bold" VerticalAlignment="Center"/>
                    </StackPanel>
                </DataGridTextColumn.Header>
            </DataGridTextColumn>
            <DataGridTextColumn Binding="{Binding Message}" Width="300">
                <DataGridTextColumn.Header>
                    <StackPanel Orientation="Horizontal">
                        <Button Style="{DynamicResource ColumnFilterButtonStyle}" Tag="Message" Click="CriticalIssuesFilter_Click" Margin="0,0,4,0"/>
                        <TextBlock Text="Message" FontWeight="Bold" VerticalAlignment="Center"/>
                    </StackPanel>
                </DataGridTextColumn.Header>
            </DataGridTextColumn>
            <DataGridTextColumn Binding="{Binding InvestigateQuery}" Width="400">
                <DataGridTextColumn.Header>
                    <StackPanel Orientation="Horizontal">
                        <Button Style="{DynamicResource ColumnFilterButtonStyle}" Tag="InvestigateQuery" Click="CriticalIssuesFilter_Click" Margin="0,0,4,0"/>
                        <TextBlock Text="Investigate Query" FontWeight="Bold" VerticalAlignment="Center"/>
                    </StackPanel>
                </DataGridTextColumn.Header>
            </DataGridTextColumn>
        </DataGrid.Columns>
    </DataGrid>
    <TextBlock x:Name="CriticalIssuesNoDataMessage" Style="{StaticResource EmptyStateMessage}" Text="No critical issues detected in selected time range"/>
    <controls:LoadingOverlay x:Name="CriticalIssuesLoading"/>
    </Grid>
</UserControl>
