<Window xmlns="https://github.com/avaloniaui"
        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:vm="clr-namespace:GitCredentialManager.UI.ViewModels;assembly=gcmcore"
        xmlns:converters="clr-namespace:GitCredentialManager.UI.Converters"
        mc:Ignorable="d" d:DesignWidth="420" d:DesignHeight="520"
        x:Class="GitCredentialManager.UI.Controls.DialogWindow"
        ExtendClientAreaToDecorationsHint="{Binding ExtendClientArea}"
        ExtendClientAreaChromeHints="{Binding ShowCustomChrome, Converter={x:Static converters:WindowClientAreaConverters.BoolToChromeHints}}"
        Title="{Binding Title}"
        SizeToContent="Height" CanResize="False"
        Width="420" MaxHeight="520" MinHeight="280"
        WindowState="Normal" WindowStartupLocation="CenterScreen"
        ShowInTaskbar="True" ShowActivated="True"
        PointerPressed="Window_PointerPressed"
        KeyUp="Window_KeyUp">
    <Design.DataContext>
        <vm:WindowViewModel/>
    </Design.DataContext>
    <Border BorderBrush="{DynamicResource DialogWindowBorderBrush}"
            BorderThickness="{Binding ShowCustomWindowBorder, Converter={x:Static converters:BoolConvertersEx.ToThickness}}">
        <DockPanel>
            <DockPanel DockPanel.Dock="Top" HorizontalAlignment="Stretch" Margin="0"
                       IsVisible="{Binding ShowCustomChrome}">
                <Button DockPanel.Dock="Right" Margin="0"
                        IsCancel="True" Height="35" Width="40"
                        Click="CloseButton_Click"
                        Background="Transparent">
                    <Button.Styles>
                        <Style Selector="ContentPresenter#PART_ContentPresenter">
                            <Setter Property="CornerRadius" Value="0" />
                        </Style>
                    </Button.Styles>
                    <Path Width="16" Height="16"
                          Fill="{DynamicResource DialogWindowCloseButtonBrush}"
                          Data="F1M8.583,8L13,12.424 12.424,13 8,8.583 3.576,13 3,12.424 7.417,8 3,3.576 3.576,3 8,7.417 12.424,3 13,3.576z"/>
                </Button>
                <TextBlock DockPanel.Dock="Left" Margin="10,0,0,0"
                           VerticalAlignment="Center"
                           Text="{Binding Title}"/>
            </DockPanel>

            <!-- Padding/spacer when extending the client area but not using custom window controls.
                 Sadly Avalonia doesn't seem to support triggered styles like WPF does, otherwise
                 we could just apply a different top-margin to the ContentControl. -->
            <Panel DockPanel.Dock="Top" Height="35">
                <Panel.IsVisible>
                    <MultiBinding Converter="{x:Static BoolConverters.And}">
                        <Binding Path="ExtendClientArea" />
                        <Binding Path="!ShowCustomChrome" />
                    </MultiBinding>
                </Panel.IsVisible>
            </Panel>

            <!-- DEBUG CONTROLS (toggle with ALT-D from a debug build) -->
            <StackPanel DockPanel.Dock="Bottom"
                        IsVisible="{Binding ShowDebugControls}"
                        Background="LightGray" Orientation="Horizontal">
                <TextBlock Text="DEBUG:" Margin="5,0" Foreground="#888888" VerticalAlignment="Center"/>
                <CheckBox IsChecked="{Binding ExtendClientArea}"
                          Content="Extend Client Area" Margin="5,0"/>
                <CheckBox IsChecked="{Binding ShowCustomChromeOverride}"
                          Content="Show Custom Chrome" Margin="5,0"/>
            </StackPanel>

            <ContentControl x:Name="_contentHolder" Margin="30,25,30,30"/>
        </DockPanel>
    </Border>

</Window>
