<UserControl x:Class="PerformanceMonitorDashboard.Controls.AlertsHistoryContent"
             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"
             mc:Ignorable="d"
             d:DesignHeight="450" d:DesignWidth="800">
    <UserControl.Resources>
        <ResourceDictionary>
            <!-- Context Menu for DataGrid Copy/Export -->
            <ContextMenu x:Key="DataGridContextMenu">
                <MenuItem Header="View Details..." Click="ViewAlertDetails_Click">
                    <MenuItem.Icon><TextBlock Text="&#x1F50D;"/></MenuItem.Icon>
                </MenuItem>
                <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>
                <Separator/>
                <MenuItem Header="Mute This Alert..." Click="MuteThisAlert_Click">
                    <MenuItem.Icon><TextBlock Text="&#x1F515;"/></MenuItem.Icon>
                </MenuItem>
                <MenuItem Header="Mute Similar Alerts..." Click="MuteSimilarAlerts_Click">
                    <MenuItem.Icon><TextBlock Text="&#x1F507;"/></MenuItem.Icon>
                </MenuItem>
                <Separator/>
                <MenuItem Header="Dismiss Selected" Click="DismissSelected_Click">
                    <MenuItem.Icon><TextBlock Text="&#x2717;"/></MenuItem.Icon>
                </MenuItem>
            </ContextMenu>

            <Style x:Key="DefaultRowStyle" TargetType="DataGridRow">
                <Setter Property="ContextMenu" Value="{StaticResource DataGridContextMenu}"/>
            </Style>

            <Style x:Key="AlertRowStyle" TargetType="DataGridRow" BasedOn="{StaticResource DefaultRowStyle}">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding IsCritical}" Value="True">
                        <Setter Property="Background" Value="#33DC2626"/>
                    </DataTrigger>
                    <DataTrigger Binding="{Binding IsWarning}" Value="True">
                        <Setter Property="Background" Value="#33D97706"/>
                    </DataTrigger>
                    <DataTrigger Binding="{Binding IsResolved}" Value="True">
                        <Setter Property="Background" Value="#3322C55E"/>
                    </DataTrigger>
                    <DataTrigger Binding="{Binding Muted}" Value="True">
                        <Setter Property="Opacity" Value="0.5"/>
                        <Setter Property="FontStyle" Value="Italic"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!-- Header Controls -->
        <StackPanel Grid.Row="0" Orientation="Horizontal" Margin="10,5" Background="{DynamicResource BackgroundLightBrush}" Height="40">
            <TextBlock Text="Alert History" VerticalAlignment="Center" Margin="5,0,10,0" FontWeight="Bold" FontSize="14"
                       Foreground="{DynamicResource ForegroundBrush}"/>
            <TextBlock Text="Time Range:" VerticalAlignment="Center" Margin="5,0,4,0"
                       Foreground="{DynamicResource ForegroundMutedBrush}"/>
            <ComboBox x:Name="TimeRangeComboBox" Width="100" VerticalAlignment="Center"
                      SelectionChanged="TimeRangeComboBox_SelectionChanged">
                <ComboBoxItem Content="Last 1 Hour" Tag="1"/>
                <ComboBoxItem Content="Last 4 Hours" Tag="4"/>
                <ComboBoxItem Content="Last 24 Hours" Tag="24" IsSelected="True"/>
                <ComboBoxItem Content="Last 7 Days" Tag="168"/>
                <ComboBoxItem Content="All" Tag="0"/>
            </ComboBox>
            <TextBlock Text="Server:" VerticalAlignment="Center" Margin="12,0,4,0"
                       Foreground="{DynamicResource ForegroundMutedBrush}"/>
            <ComboBox x:Name="ServerFilterComboBox" Width="160" VerticalAlignment="Center"
                      SelectionChanged="ServerFilterComboBox_SelectionChanged">
                <ComboBoxItem Content="All Servers" IsSelected="True"/>
            </ComboBox>
            <Button Content="Refresh" Click="RefreshButton_Click" Margin="12,0,0,0" Padding="10,4" MinWidth="70"
                    Style="{DynamicResource SuccessButton}"/>
            <Button x:Name="DismissSelectedButton" Content="Dismiss Selected" Click="DismissSelected_Click"
                    Margin="8,0,0,0" Padding="10,4" MinWidth="90" IsEnabled="False"/>
            <Button Content="Dismiss All" Click="DismissAll_Click"
                    Margin="4,0,0,0" Padding="10,4" MinWidth="70"/>
            <TextBlock x:Name="AlertCountIndicator" Text="" Margin="12,0,0,0" VerticalAlignment="Center"
                       FontStyle="Italic" Foreground="{DynamicResource AccentBrush}" FontWeight="SemiBold"/>
            <TextBlock x:Name="LastRefreshedIndicator" Text="" Margin="12,0,0,0" VerticalAlignment="Center"
                       FontSize="11" Foreground="{DynamicResource ForegroundMutedBrush}"/>
        </StackPanel>

        <!-- DataGrid -->
        <Grid Grid.Row="1">
            <DataGrid x:Name="AlertsDataGrid"
                      AutoGenerateColumns="False"
                      IsReadOnly="True"
                      CanUserSortColumns="True"
                      GridLinesVisibility="Horizontal"
                      CanUserResizeColumns="True"
                      SelectionMode="Extended"
                      SelectionChanged="AlertsDataGrid_SelectionChanged"
                      MouseDoubleClick="AlertsDataGrid_MouseDoubleClick"
                      RowStyle="{StaticResource AlertRowStyle}">
                <DataGrid.Columns>
                    <DataGridTextColumn Binding="{Binding TimeLocal}" Width="150">
                        <DataGridTextColumn.Header>
                            <StackPanel Orientation="Horizontal">
                                <Button Style="{DynamicResource ColumnFilterButtonStyle}" Tag="TimeLocal" Click="AlertFilter_Click" Margin="0,0,4,0"/>
                                <TextBlock Text="Time" FontWeight="Bold" VerticalAlignment="Center"/>
                            </StackPanel>
                        </DataGridTextColumn.Header>
                    </DataGridTextColumn>
                    <DataGridTextColumn Binding="{Binding ServerName}" Width="140">
                        <DataGridTextColumn.Header>
                            <StackPanel Orientation="Horizontal">
                                <Button Style="{DynamicResource ColumnFilterButtonStyle}" Tag="ServerName" Click="AlertFilter_Click" Margin="0,0,4,0"/>
                                <TextBlock Text="Server" FontWeight="Bold" VerticalAlignment="Center"/>
                            </StackPanel>
                        </DataGridTextColumn.Header>
                    </DataGridTextColumn>
                    <DataGridTextColumn Binding="{Binding MetricName}" Width="160">
                        <DataGridTextColumn.Header>
                            <StackPanel Orientation="Horizontal">
                                <Button Style="{DynamicResource ColumnFilterButtonStyle}" Tag="MetricName" Click="AlertFilter_Click" Margin="0,0,4,0"/>
                                <TextBlock Text="Alert Type" FontWeight="Bold" VerticalAlignment="Center"/>
                            </StackPanel>
                        </DataGridTextColumn.Header>
                    </DataGridTextColumn>
                    <DataGridTextColumn Binding="{Binding CurrentValue}" Width="200">
                        <DataGridTextColumn.Header>
                            <StackPanel Orientation="Horizontal">
                                <Button Style="{DynamicResource ColumnFilterButtonStyle}" Tag="CurrentValue" Click="AlertFilter_Click" Margin="0,0,4,0"/>
                                <TextBlock Text="Value" FontWeight="Bold" VerticalAlignment="Center"/>
                            </StackPanel>
                        </DataGridTextColumn.Header>
                    </DataGridTextColumn>
                    <DataGridTextColumn Binding="{Binding ThresholdValue}" Width="140">
                        <DataGridTextColumn.Header>
                            <StackPanel Orientation="Horizontal">
                                <Button Style="{DynamicResource ColumnFilterButtonStyle}" Tag="ThresholdValue" Click="AlertFilter_Click" Margin="0,0,4,0"/>
                                <TextBlock Text="Threshold" FontWeight="Bold" VerticalAlignment="Center"/>
                            </StackPanel>
                        </DataGridTextColumn.Header>
                    </DataGridTextColumn>
                    <DataGridTextColumn Binding="{Binding NotificationType}" Width="80">
                        <DataGridTextColumn.Header>
                            <StackPanel Orientation="Horizontal">
                                <Button Style="{DynamicResource ColumnFilterButtonStyle}" Tag="NotificationType" Click="AlertFilter_Click" Margin="0,0,4,0"/>
                                <TextBlock Text="Channel" FontWeight="Bold" VerticalAlignment="Center"/>
                            </StackPanel>
                        </DataGridTextColumn.Header>
                    </DataGridTextColumn>
                    <DataGridTextColumn Binding="{Binding StatusDisplay}" Width="100">
                        <DataGridTextColumn.Header>
                            <StackPanel Orientation="Horizontal">
                                <Button Style="{DynamicResource ColumnFilterButtonStyle}" Tag="StatusDisplay" Click="AlertFilter_Click" Margin="0,0,4,0"/>
                                <TextBlock Text="Status" FontWeight="Bold" VerticalAlignment="Center"/>
                            </StackPanel>
                        </DataGridTextColumn.Header>
                    </DataGridTextColumn>
                </DataGrid.Columns>
            </DataGrid>

            <!-- Empty State -->
            <TextBlock x:Name="NoAlertsMessage"
                       Text="No alerts recorded in the selected time range"
                       FontSize="14" Foreground="{DynamicResource ForegroundMutedBrush}"
                       HorizontalAlignment="Center" VerticalAlignment="Center"
                       Visibility="Collapsed"/>
        </Grid>
    </Grid>
</UserControl>
