<Window x:Class="PerformanceMonitorDashboard.CollectorScheduleWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Collector Schedules"
        Height="550" Width="850"
        WindowStartupLocation="CenterOwner"
        ResizeMode="CanResizeWithGrip"
        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 Margin="16">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <!-- Header -->
        <TextBlock Grid.Row="0" Text="Collector Schedules" FontWeight="Bold" FontSize="16"
                   Foreground="{DynamicResource ForegroundBrush}" Margin="0,0,0,4"/>
        <Grid Grid.Row="1" Margin="0,0,0,12">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <TextBlock Grid.Column="0" Text="Configure collection frequency and data retention for each collector."
                       Foreground="{DynamicResource ForegroundMutedBrush}" FontSize="12" VerticalAlignment="Center"/>
            <StackPanel Grid.Column="1" Orientation="Horizontal">
                <TextBlock Text="Preset:" Foreground="{DynamicResource ForegroundBrush}" FontSize="12"
                           VerticalAlignment="Center" Margin="0,0,8,0"/>
                <ComboBox x:Name="PresetComboBox" Width="140" SelectionChanged="PresetComboBox_SelectionChanged">
                    <ComboBoxItem Content="Custom" IsEnabled="False"/>
                    <ComboBoxItem Content="Low-Impact"/>
                    <ComboBoxItem Content="Balanced"/>
                    <ComboBoxItem Content="Aggressive"/>
                </ComboBox>
            </StackPanel>
        </Grid>

        <!-- Schedule Grid -->
        <Border Grid.Row="2" BorderBrush="{DynamicResource BorderBrush}" BorderThickness="1" CornerRadius="4">
            <DataGrid x:Name="ScheduleDataGrid"
                      AutoGenerateColumns="False"
                      SelectionMode="Single"
                      CanUserAddRows="False"
                      CanUserDeleteRows="False"
                      CanUserReorderColumns="False"
                      CanUserSortColumns="True"
                      HeadersVisibility="Column"
                      GridLinesVisibility="Horizontal"
                      Background="{DynamicResource BackgroundBrush}"
                      RowBackground="{DynamicResource BackgroundBrush}"
                      AlternatingRowBackground="{DynamicResource BackgroundLightBrush}"
                      BorderThickness="0"
                      ContextMenu="{StaticResource DataGridContextMenu}">
                <DataGrid.Columns>
                    <DataGridCheckBoxColumn Header="Enabled" Binding="{Binding Enabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="65"/>
                    <DataGridTextColumn Header="Collector" Binding="{Binding DisplayName}" Width="180" IsReadOnly="True"/>
                    <DataGridTextColumn Header="Frequency (min)" Binding="{Binding FrequencyMinutes, Mode=TwoWay, UpdateSourceTrigger=LostFocus}" Width="110"/>
                    <DataGridTextColumn Header="Retention (days)" Binding="{Binding RetentionDays, Mode=TwoWay, UpdateSourceTrigger=LostFocus}" Width="110"/>
                    <DataGridTextColumn Header="Last Run" Binding="{Binding LastRunTime, StringFormat='{}{0:g}'}" Width="100" IsReadOnly="True"/>
                    <DataGridTextColumn Header="Next Run" Binding="{Binding NextRunTime, StringFormat='{}{0:g}'}" Width="100" IsReadOnly="True"/>
                    <DataGridTextColumn Header="Description" Binding="{Binding Description}" Width="*" IsReadOnly="True"/>
                </DataGrid.Columns>
            </DataGrid>
        </Border>

        <!-- Buttons -->
        <Grid Grid.Row="3" Margin="0,16,0,0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>

            <!-- Info text -->
            <TextBlock Grid.Column="0" Text="Changes are saved immediately when you modify values."
                       Foreground="{DynamicResource ForegroundMutedBrush}" FontSize="11"
                       VerticalAlignment="Center"/>

            <!-- Action Buttons -->
            <StackPanel Grid.Column="2" Orientation="Horizontal">
                <Button Content="Refresh" Width="80" Height="30" Margin="0,0,8,0" Click="Refresh_Click"/>
                <Button Content="Close" Width="80" Height="30" Click="Close_Click" IsCancel="True"/>
            </StackPanel>
        </Grid>
    </Grid>
</Window>
