<UserControl x:Class="_1RM.View.Utils.MessageBoxPageView"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      xmlns:local="clr-namespace:_1RM.View.Utils"
      xmlns:service="clr-namespace:_1RM.Service"
      xmlns:xaml="https://github.com/canton7/Stylet"
      xmlns:attachProperty="clr-namespace:Shawn.Utils.WpfResources.Theme.AttachProperty;assembly=Shawn.Utils.WpfResources"
      mc:Ignorable="d" 
      d:DataContext="{d:DesignInstance local:MessageBoxPageViewModel}"
      d:DesignHeight="450" d:DesignWidth="800"
      FlowDirection="{Binding FlowDirection}">

    <UserControl.Resources>
        <Style TargetType="TextBlock" BasedOn="{StaticResource TextBlockBase}">
            <Setter Property="Foreground" Value="{DynamicResource BackgroundTextBrush}"></Setter>
            <Setter Property="VerticalAlignment" Value="Center"></Setter>
            <Setter Property="TextWrapping" Value="Wrap"></Setter>
        </Style>
        <Style TargetType="TextBox" BasedOn="{StaticResource TextBoxAccentStyle}">
            <Setter Property="Margin" Value="0 5 0 15"></Setter>
        </Style>
    </UserControl.Resources>

    <StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
        <Grid>


            <Border Margin="1"
                    CornerRadius="{StaticResource DefaultCornerRadius}" 
                    SnapsToDevicePixels="True"
                    Background="{DynamicResource BackgroundBrush}"></Border>

            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="6"/>
                    <!-- Padding -->
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="30"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="50"/>
                </Grid.RowDefinitions>



                <!--TITLE-->
                <Border Background="{DynamicResource AccentMidBrush}" Grid.ColumnSpan="3" ClipToBounds="True">
                    <Border.CornerRadius>
                        <CornerRadius TopLeft="{StaticResource DefaultCornerRadiusValue}" TopRight="{StaticResource DefaultCornerRadiusValue}"></CornerRadius>
                    </Border.CornerRadius>
                </Border>


                <Grid Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="3" 
                      Background="Transparent" Width="20" Height="20" 
                      Margin="5 0 0 0" VerticalAlignment="Center" HorizontalAlignment="Left">
                    <Image Source="/Resources/Image/Logo/logo32.png"></Image>
                </Grid>
                <TextBlock Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="3" 
                           Text="{Binding DisplayName}" 
                           Foreground="{DynamicResource AccentTextBrush}"
                           Margin=" 30 0 10 0" TextTrimming="CharacterEllipsis"/>



                <!--CONTENT-->
                <Image Grid.Row="1" Grid.Column="1"
                       Source="{Binding ImageIcon, Converter={x:Static xaml:IconToBitmapSourceConverter.Instance}}"
                       Visibility="{Binding ImageIcon, Converter={x:Static xaml:BoolToVisibilityConverter.Instance}}">
                    <Image.Style>
                        <Style TargetType="Image">
                            <Setter Property="VerticalAlignment" Value="Center"/>
                            <Setter Property="Margin" Value="19,0,0,0"/>
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding TextIsMultiline}" Value="True">
                                    <Setter Property="VerticalAlignment" Value="Top"/>
                                    <Setter Property="Margin" Value="19,25,0,0"/>
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </Image.Style>
                </Image>

                <TextBlock Grid.Row="1" Grid.Column="2" Text="{Binding Text}" Margin="8,25,15,30" TextWrapping="Wrap" TextAlignment="{Binding TextAlignment}"/>



                <!--BUTTONS-->
                <Grid Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="3">
                    <ItemsControl ItemsSource="{Binding ButtonList}"
                                  HorizontalAlignment="Right" VerticalAlignment="Center" Margin="43,0,0,0">
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <StackPanel Orientation="Horizontal"/>
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Button Content="{Binding Label}" 
                                        MinWidth="85" 
                                        MinHeight="25" 
                                        Margin="0,0,10,0"
                                        Command="{xaml:Action ButtonClicked}" 
                                        CommandParameter="{Binding Value}">
                                    <Button.Style>
                                        <Style TargetType="Button" BasedOn="{StaticResource ButtonAccentStyle}">
                                            <Setter Property="Foreground" Value="{DynamicResource AccentTextBrush}"/>
                                            <Setter Property="Background" Value="{DynamicResource AccentMidBrush}"/>
                                            <Setter Property="attachProperty:VisionElement.BorderBrushOnMouseOver" Value="{DynamicResource AccentTextBrush}"/>
                                            <Setter Property="attachProperty:VisionElement.BorderBrushOnMouseDown" Value="{DynamicResource AccentTextBrush}"/>
                                            <Setter Property="attachProperty:VisionElement.ForegroundAccent" Value="{DynamicResource AccentTextBrush}"/>
                                            <Setter Property="attachProperty:VisionElement.BackgroundAccent" Value="{DynamicResource AccentMidBrush}"/>
                                            <Setter Property="attachProperty:VisionElement.ForegroundOnMouseDown" Value="{DynamicResource AccentTextBrush}"/>
                                            <Setter Property="attachProperty:VisionElement.BackgroundOnMouseDown" Value="{DynamicResource AccentMidBrush}"/>
                                            <Style.Triggers>
                                                <DataTrigger Binding="{Binding Value}" Value="{x:Static MessageBoxResult.No}">
                                                    <Setter Property="Foreground" Value="{DynamicResource PrimaryTextBrush}"/>
                                                    <Setter Property="Background" Value="{DynamicResource PrimaryMidBrush}"/>
                                                    <Setter Property="attachProperty:VisionElement.BorderBrushOnMouseOver" Value="{DynamicResource PrimaryTextBrush}"/>
                                                    <Setter Property="attachProperty:VisionElement.BorderBrushOnMouseDown" Value="{DynamicResource PrimaryTextBrush}"/>
                                                    <Setter Property="attachProperty:VisionElement.ForegroundAccent" Value="{DynamicResource PrimaryTextBrush}"/>
                                                    <Setter Property="attachProperty:VisionElement.BackgroundAccent" Value="{DynamicResource PrimaryMidBrush}"/>
                                                    <Setter Property="attachProperty:VisionElement.ForegroundOnMouseDown" Value="{DynamicResource PrimaryTextBrush}"/>
                                                    <Setter Property="attachProperty:VisionElement.BackgroundOnMouseDown" Value="{DynamicResource PrimaryMidBrush}"/>
                                                </DataTrigger>
                                                <DataTrigger Binding="{Binding Value}" Value="{x:Static MessageBoxResult.Cancel}">
                                                    <Setter Property="Foreground" Value="{DynamicResource PrimaryTextBrush}"/>
                                                    <Setter Property="Background" Value="{DynamicResource PrimaryMidBrush}"/>
                                                    <Setter Property="attachProperty:VisionElement.BorderBrushOnMouseOver" Value="{DynamicResource PrimaryTextBrush}"/>
                                                    <Setter Property="attachProperty:VisionElement.BorderBrushOnMouseDown" Value="{DynamicResource PrimaryTextBrush}"/>
                                                    <Setter Property="attachProperty:VisionElement.ForegroundAccent" Value="{DynamicResource PrimaryTextBrush}"/>
                                                    <Setter Property="attachProperty:VisionElement.BackgroundAccent" Value="{DynamicResource PrimaryMidBrush}"/>
                                                    <Setter Property="attachProperty:VisionElement.ForegroundOnMouseDown" Value="{DynamicResource PrimaryTextBrush}"/>
                                                    <Setter Property="attachProperty:VisionElement.BackgroundOnMouseDown" Value="{DynamicResource PrimaryMidBrush}"/>
                                                </DataTrigger>
                                            </Style.Triggers>
                                        </Style>
                                    </Button.Style>
                                    <!--<Button.IsDefault>
                                    <MultiBinding Converter="{x:Static xaml:EqualityConverter.Instance}">
                                        <Binding/>
                                        <Binding Path="DataContext.DefaultButton" ElementName="RootObject"/>
                                    </MultiBinding>
                                </Button.IsDefault>
                                <Button.IsCancel>
                                    <MultiBinding Converter="{x:Static xaml:EqualityConverter.Instance}">
                                        <Binding/>
                                        <Binding Path="DataContext.CancelButton" ElementName="RootObject"/>
                                    </MultiBinding>
                                </Button.IsCancel>-->
                                </Button>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                </Grid>
            </Grid>

            <Border Margin="0,0,0,0"
                    MinWidth="160" MaxWidth="485"
                    BorderBrush="{DynamicResource AccentMidBrush}"
                    BorderThickness="2" 
                    CornerRadius="{StaticResource DefaultCornerRadius}" ClipToBounds="True">
            </Border>
        </Grid>
    </StackPanel>
</UserControl>
