<Page
    x:Class="WslSettings.Views.Settings.NetworkingPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ctControls="using:CommunityToolkit.WinUI.Controls"
    xmlns:behaviors="using:WslSettings.Behaviors"
    behaviors:NavigationViewHeaderBehavior.HeaderMode="Never">

    <Grid Margin="{ThemeResource ContentPageMargin}"
          IsTabStop="True"
		  AutomationProperties.LandmarkType="Main"
		  x:Name="NetworkingPageRoot">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <TextBlock x:Uid="Settings_NetworkingPageTitle" Style="{ThemeResource PageHeaderTextBlockStyle}" Margin="{StaticResource MediumSmallBottomMargin}" HorizontalAlignment="Left" AutomationProperties.HeadingLevel="Level1"/>
        <TextBlock x:Uid="Settings_ErrorTryAgainLater" x:Name="Settings_ErrorTryAgainLater" Grid.Row="1" HorizontalAlignment="Left" AutomationProperties.LiveSetting="Assertive"
            Visibility="{x:Bind ViewModel.ErrorVisibility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource BooleanToVisibilityConverter}}"/>
        <ScrollViewer Grid.Row="2" VerticalScrollBarVisibility="Auto"
            Visibility="{x:Bind ViewModel.SettingsContentVisibility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource BooleanToVisibilityConverter}}">
            <StackPanel Spacing="{StaticResource SettingsCardSpacing}">
                <ctControls:SettingsCard x:Uid="Settings_NetworkingMode">
                    <ComboBox x:Uid="Settings_NetworkingModeComboBox" Style="{StaticResource ComboBoxSettingStyle}" HorizontalAlignment="Right"
                        ItemsSource="{x:Bind ViewModel.NetworkingModes}" SelectedIndex="{x:Bind ViewModel.NetworkingModeSelected, Mode=TwoWay}"/>
                </ctControls:SettingsCard>
                <ctControls:SettingsCard x:Uid="Settings_HyperVFirewall">
                    <ToggleSwitch x:Uid="Settings_HyperVFirewallToggleSwitch" HorizontalAlignment="Right" MinWidth="0" IsOn="{x:Bind ViewModel.IsOnHyperVFirewall, Mode=TwoWay}"/>
                </ctControls:SettingsCard>
                <ctControls:SettingsExpander x:Name="IgnoredPortsExpander" x:Uid="Settings_IgnoredPorts">
                    <TextBlock Style="{StaticResource TextBlockSettingStyle}" Text="{x:Bind ViewModel.IgnoredPorts, Mode=OneWay}"/>
                    <ctControls:SettingsExpander.Items>
                        <ctControls:SettingsCard HorizontalContentAlignment="Left" ContentAlignment="Left" Margin="{StaticResource SettingsExpanderItemMargin}">
                            <StackPanel Orientation="Horizontal">
                                <TextBox x:Name="IgnoredPortsTextBox" x:Uid="Settings_IgnoredPortsTextBox" Style="{StaticResource TextBoxSettingStyle}" Margin="{StaticResource InputControlSpacingMargin}"
                                    Text="{x:Bind ViewModel.IgnoredPorts, Mode=TwoWay, UpdateSourceTrigger=LostFocus}"/>
                                <Button x:Uid="Settings_IgnoredPortsResetButton" Style="{StaticResource ButtonSettingStyle}" Margin="{StaticResource InputControlSpacingMargin}"
                                    Command="{x:Bind ViewModel.IgnoredPorts_ResetCommand}" IsEnabled="{x:Bind ViewModel.IgnoredPorts_ResetEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                    Click="Settings_ResetButton_Click"/>
                            </StackPanel>
                        </ctControls:SettingsCard>
                    </ctControls:SettingsExpander.Items>
                </ctControls:SettingsExpander>
                <ctControls:SettingsCard x:Uid="Settings_LocalhostForwarding">
                    <ToggleSwitch x:Uid="Settings_LocalhostForwardingToggleSwitch" HorizontalAlignment="Right" MinWidth="0" IsOn="{x:Bind ViewModel.IsOnLocalhostForwarding, Mode=TwoWay}"/>
                </ctControls:SettingsCard>
                <ctControls:SettingsCard x:Uid="Settings_HostAddressLoopback">
                    <ToggleSwitch x:Uid="Settings_HostAddressLoopbackToggleSwitch" HorizontalAlignment="Right" MinWidth="0" IsOn="{x:Bind ViewModel.IsOnHostAddressLoopback, Mode=TwoWay}"/>
                </ctControls:SettingsCard>
                <ctControls:SettingsCard x:Uid="Settings_AutoProxy">
                    <ToggleSwitch x:Uid="Settings_AutoProxyToggleSwitch" HorizontalAlignment="Right" MinWidth="0" IsOn="{x:Bind ViewModel.IsOnAutoProxy, Mode=TwoWay}"/>
                </ctControls:SettingsCard>
                <ctControls:SettingsExpander x:Name="InitialAutoProxyTimeoutExpander" x:Uid="Settings_InitialAutoProxyTimeout">
                    <TextBlock Style="{StaticResource TextBlockSettingStyle}" Text="{x:Bind ViewModel.InitialAutoProxyTimeout, Mode=OneWay, Converter={StaticResource MillisecondsStringConverter}}"/>
                    <ctControls:SettingsExpander.Items>
                        <ctControls:SettingsCard HorizontalContentAlignment="Left" ContentAlignment="Left" Margin="{StaticResource SettingsExpanderItemMargin}">
                            <StackPanel Orientation="Horizontal">
                                <TextBox x:Name="InitialAutoProxyTimeoutTextBox" x:Uid="Settings_InitialAutoProxyTimeoutTextBox" Style="{StaticResource TextBoxSettingStyle}" Margin="{StaticResource InputControlSpacingMargin}"
                                    Text="{x:Bind ViewModel.InitialAutoProxyTimeout, Mode=TwoWay, UpdateSourceTrigger=LostFocus}" TextChanged="InitialAutoProxyTimeoutTextBox_TextChanged"/>
                                <Button x:Uid="Settings_InitialAutoProxyTimeoutResetButton" Style="{StaticResource ButtonSettingStyle}" Margin="{StaticResource InputControlSpacingMargin}"
                                    Command="{x:Bind ViewModel.InitialAutoProxyTimeout_ResetCommand}" IsEnabled="{x:Bind ViewModel.InitialAutoProxyTimeout_ResetEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                    Click="Settings_ResetButton_Click"/>
                            </StackPanel>
                        </ctControls:SettingsCard>
                    </ctControls:SettingsExpander.Items>
                </ctControls:SettingsExpander>
                <ctControls:SettingsCard x:Uid="Settings_DNSProxy">
                    <ToggleSwitch x:Uid="Settings_DNSProxyToggleSwitch" HorizontalAlignment="Right" MinWidth="0" IsOn="{x:Bind ViewModel.IsOnDNSProxy, Mode=TwoWay}"/>
                </ctControls:SettingsCard>
                <ctControls:SettingsCard x:Uid="Settings_DNSTunneling">
                    <ToggleSwitch x:Uid="Settings_DNSTunnelingToggleSwitch" HorizontalAlignment="Right" MinWidth="0" IsOn="{x:Bind ViewModel.IsOnDNSTunneling, Mode=TwoWay}"/>
                </ctControls:SettingsCard>
                <ctControls:SettingsCard x:Uid="Settings_BestEffortDNS">
                    <ToggleSwitch x:Uid="Settings_BestEffortDNSToggleSwitch" HorizontalAlignment="Right" MinWidth="0" IsOn="{x:Bind ViewModel.IsOnBestEffortDNS, Mode=TwoWay}"/>
                </ctControls:SettingsCard>
            </StackPanel>
        </ScrollViewer>
    </Grid>
</Page>
