<Window x:Class="PerformanceMonitorLite.Windows.CollectorScheduleEditorWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Collector Schedules"
        Height="600" Width="900"
        MinHeight="400" MinWidth="700"
        ResizeMode="CanResizeWithGrip"
        WindowStartupLocation="CenterOwner"
        Icon="/EDD.ico"
        Background="{DynamicResource BackgroundBrush}">
    <Grid Margin="16">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <!-- Header -->
        <StackPanel Grid.Row="0" Margin="0,0,0,12">
            <TextBlock x:Name="HeaderText" Text="Collector Schedules" FontSize="16" FontWeight="Bold"
                       Foreground="{DynamicResource ForegroundBrush}"/>
            <TextBlock x:Name="SubHeaderText" FontSize="12"
                       Foreground="{DynamicResource ForegroundMutedBrush}" Margin="0,4,0,0"/>
        </StackPanel>

        <!-- Preset + Use Default -->
        <Grid Grid.Row="1" Margin="0,0,0,8">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>

            <StackPanel Grid.Column="0" 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>

            <CheckBox x:Name="UseDefaultCheckBox" Grid.Column="1" Content="Use default schedule"
                      Margin="20,0,0,0" VerticalAlignment="Center"
                      Foreground="{DynamicResource ForegroundBrush}"
                      Checked="UseDefaultCheckBox_Changed" Unchecked="UseDefaultCheckBox_Changed"/>

            <StackPanel Grid.Column="3" Orientation="Horizontal">
                <Button x:Name="CopyFromDefaultButton" Content="Copy from Default" Click="CopyFromDefault_Click" Margin="0,0,8,0"/>
                <ComboBox x:Name="CopyFromServerCombo" Width="160" Visibility="Collapsed"/>
                <Button x:Name="CopyFromServerButton" Content="Copy from Server" Click="CopyFromServer_Click" Visibility="Collapsed"/>
            </StackPanel>
        </Grid>

        <!-- Schedule DataGrid -->
        <DataGrid Grid.Row="2" x:Name="ScheduleGrid"
                  AutoGenerateColumns="False" IsReadOnly="False"
                  CanUserAddRows="False" CanUserDeleteRows="False"
                  SelectionMode="Single"
                  Background="Transparent" BorderThickness="0"
                  HeadersVisibility="Column" GridLinesVisibility="Horizontal">
            <DataGrid.Columns>
                <DataGridCheckBoxColumn Header="Enabled" Binding="{Binding Enabled, UpdateSourceTrigger=PropertyChanged}" Width="65"/>
                <DataGridTextColumn Header="Collector" Binding="{Binding Name}" Width="160" IsReadOnly="True"/>
                <DataGridTextColumn Header="Frequency (min)" Binding="{Binding FrequencyMinutes, UpdateSourceTrigger=LostFocus}" Width="110"/>
                <DataGridTextColumn Header="Retention (days)" Binding="{Binding RetentionDays, UpdateSourceTrigger=LostFocus}" Width="110"/>
                <DataGridTextColumn Header="Schedule" Binding="{Binding FrequencyDisplay}" Width="140" IsReadOnly="True"/>
                <DataGridTextColumn Header="Description" Binding="{Binding Description}" Width="*" IsReadOnly="True"/>
            </DataGrid.Columns>
        </DataGrid>

        <!-- Status text -->
        <TextBlock Grid.Row="3" x:Name="StatusText" FontSize="11" FontStyle="Italic"
                   Foreground="{DynamicResource ForegroundMutedBrush}" Margin="0,8,0,0"/>

        <!-- Buttons -->
        <StackPanel Grid.Row="4" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,12,0,0">
            <Button Content="Save" Click="SaveButton_Click" Style="{StaticResource AccentButton}" Margin="0,0,8,0"/>
            <Button Content="Cancel" Click="CancelButton_Click"/>
        </StackPanel>
    </Grid>
</Window>
