<Window x:Class="ServerManagerTool.ShutdownWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:cctl="clr-namespace:ServerManagerTool.Common.Controls;assembly=ServerManager.Common"
        xmlns:enum="clr-namespace:ServerManagerTool.Enums"
        Width="600" ResizeMode="CanMinimize" SizeToContent="Height" WindowStyle="SingleBorderWindow" WindowStartupLocation="CenterOwner" ShowInTaskbar="True" 
        Closing="Window_Closing" Closed="Window_Closed" 
        Icon="../Art/favicon.ico" Title="{DynamicResource ShutdownWindow_Title}">
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="..\Globalization\en-US\en-US.xaml"/>
                <ResourceDictionary Source="..\Styles\Default.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>
    
    <Grid Background="{StaticResource BeigeGradient}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        
        <Grid Grid.Row="0" DataContext="{Binding Server.Runtime}" Margin="2,0,2,0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            
            <Border Grid.Column="0" Margin="0,2,0,2" Background="{DynamicResource BeigeLabel}" ToolTip="{DynamicResource ServerSettings_StatusTooltip}">
                <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                    <Label FontSize="15" Content="{DynamicResource ServerSettings_StatusLabel}"/>
                    <Label FontSize="15" Content="{Binding StatusString}" MinWidth="100"/>
                </StackPanel>
            </Border>
            <Border Grid.Column="1" Margin="2,2,0,2" Background="{DynamicResource BeigeLabel}" ToolTip="{DynamicResource ServerSettings_PlayersTooltip}">
                <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                    <Label FontSize="15" Content="{DynamicResource ServerSettings_PlayersLabel}"/>
                    <Label FontSize="15" Content="{Binding Players}"/>
                    <Label FontSize="15" Content="/" Width="20"/>
                    <Label FontSize="15" Content="{Binding MaxPlayers}"/>
                </StackPanel>
            </Border>
        </Grid>

        <GroupBox Grid.Row="1" Style="{StaticResource GroupBoxStyle}" Margin="2,0,2,2">
            <GroupBox.Header>
                <Label Content="{DynamicResource ShutdownWindow_ShutdownRestartOptionsLabel}"/>
            </GroupBox.Header>
            
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>

                <CheckBox Grid.Row="0" Grid.Column="0" Margin="5" Content="{DynamicResource ShutdownWindow_CheckForOnlinePlayersLabel}" IsChecked="{Binding CheckForOnlinePlayers}" IsEnabled="{Binding ShutdownStarted, Converter={StaticResource InvertBooleanConverter}}" ToolTip="{DynamicResource ShutdownWindow_CheckForOnlinePlayersTooltip}" HorizontalAlignment="Left"/>
                <CheckBox Grid.Row="0" Grid.Column="1" Margin="5" Content="{DynamicResource ShutdownWindow_SendShutdownMessagesLabel}" IsChecked="{Binding SendShutdownMessages}" IsEnabled="{Binding ShutdownStarted, Converter={StaticResource InvertBooleanConverter}}" ToolTip="{DynamicResource ShutdownWindow_SendShutdownMessagesTooltip}" HorizontalAlignment="Left"/>

                <cctl:AnnotatedSlider Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Margin="1" Label="{DynamicResource ShutdownWindow_ShutdownIntervalLabel}" Value="{Binding ShutdownInterval}" Minimum="0" Maximum="60" SmallChange="1" LargeChange="5" TickFrequency="1" LabelRelativeWidth="Auto" SliderRelativeWidth="15*" SuffixRelativeWidth="Auto" Suffix="{DynamicResource SliderUnits_Minutes}" IsEnabled="{Binding ShutdownStarted, Converter={StaticResource InvertBooleanConverter}}" ToolTip="{DynamicResource ShutdownWindow_ShutdownIntervalTooltip}"/>

                <CheckBox Grid.Row="2" Grid.Column="0" Margin="5" Content="{DynamicResource ShutdownWindow_BackupWorldFileLabel}" IsChecked="{Binding BackupWorldFile}" IsEnabled="{Binding ShutdownStarted, Converter={StaticResource InvertBooleanConverter}}" ToolTip="{DynamicResource ShutdownWindow_BackupWorldFileTooltip}" HorizontalAlignment="Left">
                    <CheckBox.Style>
                        <Style BasedOn="{StaticResource {x:Type CheckBox}}" TargetType="{x:Type CheckBox}">
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding Server.Profile.SOTF_Enabled}" Value="True">
                                    <Setter Property="Visibility" Value="Collapsed"/>
                                </DataTrigger>
                                <DataTrigger Binding="{Binding Server.Profile.SOTF_Enabled}" Value="False">
                                    <Setter Property="Visibility" Value="Visible"/>
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </CheckBox.Style>
                </CheckBox>
                <CheckBox Grid.Row="2" Grid.Column="1" Margin="5" Content="{DynamicResource ShutdownWindow_UpdateServerLabel}" IsChecked="{Binding UpdateServer}" IsEnabled="{Binding ShutdownStarted, Converter={StaticResource InvertBooleanConverter}}" ToolTip="{DynamicResource ShutdownWindow_UpdateServerTooltip}" HorizontalAlignment="Left"/>
                
                <CheckBox Grid.Row="3" Grid.Column="0" Margin="5" Content="{DynamicResource ShutdownWindow_RestartServerLabel}" IsChecked="{Binding RestartServer}" IsEnabled="{Binding ShutdownStarted, Converter={StaticResource InvertBooleanConverter}}" ToolTip="{DynamicResource ShutdownWindow_RestartServerTooltip}" HorizontalAlignment="Left"/>
                
                <Grid Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="2" Margin="1">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="1*"/>
                    </Grid.ColumnDefinitions>

                    <Label Grid.Column="0" Content="{DynamicResource ShutdownWindow_ShutdownReasonLabel}" ToolTip="{DynamicResource ShutdownWindow_ShutdownReasonTooltip}"/>
                    <TextBox Grid.Column="1" Text="{Binding ShutdownReason}" ToolTip="{DynamicResource ShutdownWindow_ShutdownReasonTooltip}"/>
                </Grid>
                
                <TextBox Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="2" Name="MessageOutput" Margin="1" Height="200" HorizontalAlignment="Stretch" IsReadOnly="True" IsReadOnlyCaretVisible="True" TextWrapping="NoWrap" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
                    <TextBox.Style>
                        <Style BasedOn="{StaticResource {x:Type TextBox}}" TargetType="{x:Type TextBox}">
                            <Setter Property="Visibility" Value="Visible" />
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding Server.Runtime.Status}" Value="{x:Static enum:ServerStatus.Running}">
                                    <Setter Property="Visibility" Value="Collapsed"/>
                                </DataTrigger>
                                <DataTrigger Binding="{Binding ShutdownType}" Value="1">
                                    <Setter Property="Visibility" Value="Visible"/>
                                </DataTrigger>
                                <DataTrigger Binding="{Binding ShutdownType}" Value="2">
                                    <Setter Property="Visibility" Value="Collapsed"/>
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </TextBox.Style>
                </TextBox>
            </Grid>
        </GroupBox>
        
        <Grid Grid.Row="2" Margin="2">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition MinWidth="75" Width="Auto"/>
                <ColumnDefinition MinWidth="75" Width="Auto"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition MinWidth="75" Width="Auto"/>
                <ColumnDefinition MinWidth="75" Width="Auto"/>
            </Grid.ColumnDefinitions>
            
            <Button Grid.Row="0" Grid.Column="0" Margin="0" Padding="5" VerticalAlignment="Center" Click="Shutdown_Click">
                <Button.Style>
                    <Style BasedOn="{StaticResource {x:Type Button}}" TargetType="{x:Type Button}">
                        <Setter Property="IsEnabled" Value="False" />
                        <Setter Property="Content" Value="{StaticResource ShutdownButtonContent}" />
                        <Setter Property="ToolTip" Value="{DynamicResource ShutdownWindow_ShutdownButtonTooltip}" />
                        <Style.Triggers>
                            <MultiDataTrigger>
                                <MultiDataTrigger.Conditions>
                                    <Condition Binding="{Binding Server.Runtime.Status}" Value="{x:Static enum:ServerStatus.Running}" />
                                    <Condition Binding="{Binding ShutdownStarted}" Value="False" />
                                </MultiDataTrigger.Conditions>
                                <Setter Property="IsEnabled" Value="True"/>
                            </MultiDataTrigger>
                            <DataTrigger Binding="{Binding RestartServer}" Value="True">
                                <Setter Property="Content" Value="{StaticResource RestartButtonContent}"/>
                                <Setter Property="ToolTip" Value="{DynamicResource ShutdownWindow_RestartButtonTooltip}" />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </Button.Style>
            </Button>
            <Button Grid.Row="0" Grid.Column="1" Margin="5,0,0,0" Padding="5" VerticalAlignment="Center" Name="CancelShutdownButton" Click="CancelShutdown_Click">
                <Button.Style>
                    <Style BasedOn="{StaticResource {x:Type Button}}" TargetType="{x:Type Button}">
                        <Setter Property="Content" Value="{StaticResource CancelShutdownButtonContent}" />
                        <Setter Property="ToolTip" Value="{DynamicResource ShutdownWindow_CancelShutdownButtonTooltip}" />
                        <Setter Property="Visibility" Value="Hidden" />
                        <Style.Triggers>
                            <MultiDataTrigger>
                                <MultiDataTrigger.Conditions>
                                    <Condition Binding="{Binding Server.Runtime.Status}" Value="{x:Static enum:ServerStatus.Running}" />
                                    <Condition Binding="{Binding ShutdownStarted}" Value="True" />
                                </MultiDataTrigger.Conditions>
                                <Setter Property="Visibility" Value="Visible"/>
                            </MultiDataTrigger>
                        </Style.Triggers>
                    </Style>
                </Button.Style>
            </Button>
            <Button Grid.Row="0" Grid.Column="3" Margin="5,0,0,0" Padding="5" VerticalAlignment="Center" Click="Stop_Click">
                <Button.Style>
                    <Style BasedOn="{StaticResource {x:Type Button}}" TargetType="{x:Type Button}">
                        <Setter Property="IsEnabled" Value="False" />
                        <Setter Property="Content" Value="{StaticResource StopButtonContent2}" />
                        <Setter Property="ToolTip" Value="{DynamicResource ShutdownWindow_StopButtonTooltip}" />
                        <Style.Triggers>
                            <MultiDataTrigger>
                                <MultiDataTrigger.Conditions>
                                    <Condition Binding="{Binding Server.Runtime.Status}" Value="{x:Static enum:ServerStatus.Running}" />
                                    <Condition Binding="{Binding ShutdownStarted}" Value="False" />
                                </MultiDataTrigger.Conditions>
                                <Setter Property="IsEnabled" Value="True"/>
                            </MultiDataTrigger>
                        </Style.Triggers>
                    </Style>
                </Button.Style>
            </Button>
            <Button Grid.Row="0" Grid.Column="4" Margin="5,0,0,0" Padding="5" VerticalAlignment="Center" Click="Cancel_Click">
                <Button.Style>
                    <Style BasedOn="{StaticResource {x:Type Button}}" TargetType="{x:Type Button}">
                        <Setter Property="IsEnabled" Value="True" />
                        <Setter Property="Content" Value="{StaticResource CancelButtonContent}" />
                        <Setter Property="ToolTip" Value="{DynamicResource ShutdownWindow_CloseButtonTooltip}" />
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding ShutdownStarted}" Value="True">
                                <Setter Property="IsEnabled" Value="False"/>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </Button.Style>
            </Button>
        </Grid>
    </Grid>
</Window>
