<UserControl x:Class="NETworkManager.Views.SettingsSettingsView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:Converter="clr-namespace:NETworkManager.Converters"
        xmlns:Validator="clr-namespace:NETworkManager.Validators"
        xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
        xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"      
        xmlns:IconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
        xmlns:Dialog="clr-namespace:MahApps.Metro.Controls.Dialogs;assembly=MahApps.Metro"
        Dialog:DialogParticipation.Register="{Binding}"
        mc:Ignorable="d" Loaded="UserControl_Loaded">
    <UserControl.Resources>
        <!-- Converter -->
        <Converter:BooleanReverseConverter x:Key="BooleanReverseConverter" />
        <Converter:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
        <Converter:IsDefaultSettingsLocationToBoolConverter x:Key="IsDefaultSettingsLocationToBoolConverter" />
        <Converter:IsSettingsLocationToBoolConverter x:Key="IsSettingsLocationToBoolConverter" />
        <Converter:ValidateSettingsResetConverter x:Key="ValidateSettingsResetConverter" />
    </UserControl.Resources>
    <StackPanel >
        <TextBlock Style="{StaticResource HeaderTextBlock}" Text="{DynamicResource String_Header_Location}" />
        <TextBox x:Name="txtLocation" mah:TextBoxHelper.Watermark="{DynamicResource String_Watermark_EnterLocation}" mah:TextBoxHelper.ButtonCommand="{Binding BrowseFolderCommand}" AllowDrop="True" Drop="txtLocation_Drop" PreviewDragOver="txtLocation_PreviewDragOver" Margin="0,0,0,10">
            <TextBox.Text>
                <Binding Path="LocationSelectedPath" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
                    <Binding.ValidationRules>
                        <Validator:EmptyValidator ValidatesOnTargetUpdated="True" />
                        <Validator:SettingsFolderExistsValidator ValidatesOnTargetUpdated="True" />
                    </Binding.ValidationRules>
                </Binding>
            </TextBox.Text>
            <TextBox.Style>
                <Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource BrowseFolderTextBox}">
                    <Setter Property="IsEnabled" Value="True" />
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding ElementName=toggleSwitchIsPortable,Path=IsChecked}" Value="True" >
                            <Setter Property="IsEnabled" Value="False" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </TextBox.Style>
        </TextBox>
        <StackPanel Margin="0,0,0,20">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="10" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <StackPanel Grid.Column="0" Orientation="Horizontal">
                    <Button Content="{DynamicResource String_Button_Default}" Command="{Binding RestoreDefaultSettingsLocationCommand}" Margin="0,0,10,0">
                        <Button.Style>
                            <Style TargetType="{x:Type Button}" BasedOn="{StaticResource DefaultButton}">
                                <Setter Property="IsEnabled" Value="False" />
                                <Setter Property="Visibility" Value="Collapsed" />
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding ElementName=toggleSwitchIsPortable,Path=IsChecked}" Value="False" >
                                        <Setter Property="IsEnabled" Value="True" />
                                    </DataTrigger>
                                    <DataTrigger Value="False">
                                        <DataTrigger.Binding>
                                            <Binding Converter="{StaticResource IsDefaultSettingsLocationToBoolConverter}" ElementName="txtLocation" Path="Text"/>
                                        </DataTrigger.Binding>
                                        <Setter Property="Visibility" Value="Visible" />
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </Button.Style>
                    </Button>
                    <Button Content="{DynamicResource String_Button_Change}" Command="{Binding ChangeSettingsCommand}">
                        <Button.Style>
                            <Style TargetType="{x:Type Button}" BasedOn="{StaticResource DefaultButton}">
                                <Setter Property="IsEnabled" Value="False" />
                                <Style.Triggers>
                                    <MultiDataTrigger>
                                        <MultiDataTrigger.Conditions>
                                            <Condition Binding="{Binding ElementName=toggleSwitchIsPortable, Path=IsChecked}" Value="False" />
                                            <Condition Binding="{Binding ElementName=txtLocation, Path=(Validation.HasError)}" Value="False" />
                                            <Condition Binding="{Binding ElementName=txtLocation, Path=Text, Converter={StaticResource IsSettingsLocationToBoolConverter}}" Value="False" />
                                            <Condition Binding="{Binding MovingFiles}" Value="False" />
                                            <Condition Binding="{Binding MakingPortable}" Value="False" />
                                        </MultiDataTrigger.Conditions>
                                        <Setter Property="IsEnabled" Value="True" />
                                    </MultiDataTrigger>
                                </Style.Triggers>
                            </Style>
                        </Button.Style>
                    </Button>
                </StackPanel>
                <Button Grid.Column="2" Command="{Binding OpenLocationCommand}" Style="{StaticResource ImageWithTextButton}">
                    <Button.Content>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>
                            <Rectangle Width="20" Height="20" Margin="10,5,0,5" Fill="{DynamicResource GrayBrush3}">
                                <Rectangle.OpacityMask>
                                    <VisualBrush Stretch="Uniform" Visual="{IconPacks:Material Kind=FolderOpen}" />
                                </Rectangle.OpacityMask>
                            </Rectangle>
                            <TextBlock Grid.Column="1" Text="{DynamicResource String_Button_OpenLocation}" FontSize="14" Margin="10,5" TextAlignment="Center"/>
                        </Grid>
                    </Button.Content>
                </Button>
            </Grid>
            <Controls:MetroProgressBar IsIndeterminate="True" Foreground="{DynamicResource AccentColorBrush}"  Visibility="{Binding MovingFiles, Converter={StaticResource BooleanToVisibilityConverter}}" Margin="0,10,0,0"/>
        </StackPanel>
        <TextBlock Style="{StaticResource HeaderTextBlock}" Text="{DynamicResource String_Header_Portable}" />
        <StackPanel Margin="0,0,0,20">
            <Controls:ToggleSwitch x:Name="toggleSwitchIsPortable" Header="{DynamicResource String_SaveSettingsInApplicationFolder}" OnLabel="{DynamicResource String_ToggleSwitch_On}" OffLabel="{DynamicResource String_ToggleSwitch_Off}" IsChecked="{Binding IsPortable}" IsEnabled="{Binding MakingPortable, Converter={StaticResource BooleanReverseConverter}}">
                <Controls:ToggleSwitch.Style>
                    <Style TargetType="{x:Type Controls:ToggleSwitch}" BasedOn="{StaticResource DefaultToggleSwitch}">
                        <Setter Property="IsEnabled" Value="False" />
                        <Style.Triggers>
                            <MultiDataTrigger>
                                <MultiDataTrigger.Conditions>
                                    <Condition Binding="{Binding MovingFiles}" Value="False" />
                                    <Condition Binding="{Binding MakingPortable}" Value="False" />
                                </MultiDataTrigger.Conditions>
                                <Setter Property="IsEnabled" Value="True" />
                            </MultiDataTrigger>
                        </Style.Triggers>
                    </Style>
                </Controls:ToggleSwitch.Style>
            </Controls:ToggleSwitch>
            <Controls:MetroProgressBar IsIndeterminate="True" Foreground="{DynamicResource AccentColorBrush}" Visibility="{Binding MakingPortable, Converter={StaticResource BooleanToVisibilityConverter}}" Margin="0,10,0,0"/>
        </StackPanel>
        <TextBlock Style="{StaticResource HeaderTextBlock}" Text="{DynamicResource String_Header_Reset}" />
        <TextBlock Style="{StaticResource DefaultTextBlock}" Text="{StaticResource String_SelectTheSettingsYouWantToReset}" Margin="0,0,0,10" />
        <RadioButton x:Name="radioButtonResetEverything" Content="{DynamicResource String_RadioButton_Everything}" IsChecked="{Binding ResetEverything}" Margin="0,0,0,10"/>
        <RadioButton x:Name="radioButtonResetCustom" Content="{DynamicResource String_RadioButton_Custom}" Margin="0,0,0,10"/>
        <GroupBox Margin="20,0,0,10" MinWidth="250" HorizontalAlignment="Left">
            <GroupBox.Style>
                <Style TargetType="{x:Type GroupBox}" BasedOn="{StaticResource WithoutHeaderGroupBox}">
                    <Setter Property="IsEnabled" Value="False" />
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding ElementName=radioButtonResetCustom, Path=IsChecked}" Value="True">
                            <Setter Property="IsEnabled" Value="True" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </GroupBox.Style>
            <StackPanel>
                <CheckBox Content="{DynamicResource String_ApplicationSettings}" IsEnabled="{Binding ApplicationSettingsExists}" IsChecked="{Binding ResetApplicationSettings}" Margin="0,0,0,10" />
                <CheckBox Content="{DynamicResource String_NetworkInterfaceProfiles}" IsEnabled="{Binding NetworkInterfaceProfilesExists}" IsChecked="{Binding ResetNetworkInterfaceProfiles}" Margin="0,0,0,10" />
                <CheckBox Content="{DynamicResource String_IPScannerProfiles}" IsEnabled="{Binding IPScannerProfilesExists}" IsChecked="{Binding ResetIPScannerProfiles}" Margin="0,0,0,10" />
                <CheckBox Content="{DynamicResource String_PortScannerProfiles}" IsEnabled="{Binding PortScannerProfilesExists}" IsChecked="{Binding ResetPortScannerProfiles}" Margin="0,0,0,10" />
                <CheckBox Content="{DynamicResource String_PingProfiles}" IsEnabled="{Binding PingProfilesExists}" IsChecked="{Binding ResetPingProfiles}" Margin="0,0,0,10" />
                <CheckBox Content="{DynamicResource String_TracerouteProfiles}" IsEnabled="{Binding TracerouteProfilesExists}" IsChecked="{Binding ResetTracerouteProfiles}" Margin="0,0,0,10" />
                <CheckBox Content="{DynamicResource String_RemoteDesktopSessions}" IsEnabled="{Binding RemoteDesktopSessionsExists}" IsChecked="{Binding ResetRemoteDesktopSessions}" Margin="0,0,0,10" />
                <CheckBox Content="{DynamicResource String_PuTTYSessions}" IsEnabled="{Binding PuTTYSessionsExists}" IsChecked="{Binding ResetPuTTYSessions}" Margin="0,0,0,10" />
                <CheckBox Content="{DynamicResource String_WakeOnLANClients}" IsEnabled="{Binding WakeOnLANClientsExists}" IsChecked="{Binding ResetWakeOnLANClients}" />
            </StackPanel>
        </GroupBox>
        <Button Content="{DynamicResource String_Button_Reset}" Command="{Binding ResetSettingsCommand}" HorizontalAlignment="Left">
            <Button.Style>
                <Style TargetType="{x:Type Button}" BasedOn="{StaticResource DefaultButton}">
                    <Setter Property="IsEnabled" Value="False" />
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding ResetEverything}" Value="True">
                            <Setter Property="IsEnabled" Value="True" />
                        </DataTrigger>
                        <DataTrigger Value="True">
                            <DataTrigger.Binding>
                                <MultiBinding Converter="{StaticResource ValidateSettingsResetConverter}">
                                    <Binding Path="ResetEverything" />
                                    <Binding Path="ResetApplicationSettings" />
                                    <Binding Path="ResetNetworkInterfaceProfiles" />
                                    <Binding Path="ResetIPScannerProfiles" />
                                    <Binding Path="ResetPortScannerProfiles" />
                                    <Binding Path="ResetPingProfiles" />
                                    <Binding Path="ResetTracerouteProfiles" />
                                    <Binding Path="ResetRemoteDesktopSessions" />
                                    <Binding Path="ResetPuTTYSessions" />
                                    <Binding Path="ResetWakeOnLANClients" />
                                </MultiBinding>
                            </DataTrigger.Binding>
                            <Setter  Property="IsEnabled" Value="True" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Button.Style>
        </Button>
    </StackPanel>
</UserControl>
