<styles:WindowChromeBase x:Class="_1RM.View.Editor.DataSourceSelectorView"
                         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:styles="clr-namespace:Shawn.Utils.WpfResources.Theme.Styles;assembly=Shawn.Utils.WpfResources"
                         xmlns:editor="clr-namespace:_1RM.View.Editor"
                         xmlns:model="clr-namespace:_1RM.Service.DataSource.Model"
                         xmlns:dao="clr-namespace:_1RM.Service.DataSource.DAO"
                         xmlns:attachProperty="clr-namespace:Shawn.Utils.WpfResources.Theme.AttachProperty;assembly=Shawn.Utils.WpfResources"
                         mc:Ignorable="d" 
                         ShowInTaskbar="False"
                         WindowStyle="None"
                         SizeToContent="WidthAndHeight" 
                         Background="Transparent"
                         AllowsTransparency="True"
                         d:DataContext="{d:DesignInstance editor:DataSourceSelectorViewModel}">
    <Window.Resources>
        <Style TargetType="TextBlock" BasedOn="{StaticResource TextBlockBase}">
            <Setter Property="Foreground" Value="{StaticResource PrimaryTextBrush}"></Setter>
        </Style>
    </Window.Resources>

    <Border Background="{DynamicResource PrimaryMidBrush}"
            BorderBrush="{DynamicResource PrimaryLightBrush}"
            BorderThickness="1" CornerRadius="{StaticResource DefaultCornerRadius}" ClipToBounds="True">
        <Grid IsSharedSizeScope="True">
            <Grid >
                <StackPanel Margin="20 0" >

                    <TextBlock Text="{DynamicResource 'Please select a Data Source'}" 
                                Style="{StaticResource TextBlockBase}"
                               Margin="15" FontSize="{DynamicResource GlobalFontSizeTitle}" MinHeight="30" 
                               Foreground="{DynamicResource PrimaryTextBrush}"
                               HorizontalAlignment="Center" ></TextBlock>

                    <ListBox MaxHeight="400" Width="500" 
                             ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                             ScrollViewer.CanContentScroll="True"
                             ItemsSource="{Binding SourceConfigs}" Grid.IsSharedSizeScope="True">
                        <ListBox.Template>
                            <ControlTemplate TargetType="ListBox">
                                <Border x:Name="Bd">
                                    <ScrollViewer Focusable="False">
                                        <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                                    </ScrollViewer>
                                </Border>
                            </ControlTemplate>
                        </ListBox.Template>
                        <ListBox.ItemContainerStyle>
                            <Style TargetType="ListBoxItem">
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="ListBoxItem">
                                            <ContentPresenter Margin="0 2"/>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                        </ListBox.ItemContainerStyle>
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <VirtualizingStackPanel IsVirtualizing="True"
                                                        ScrollUnit="Pixel"
                                                        VirtualizationMode="Recycling"
                                                        CacheLengthUnit="Pixel"/>
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                        <ItemsControl.ItemTemplate>
                            <DataTemplate DataType="model:DataSourceBase">
                                <Grid MinHeight="35">
                                    <Border x:Name="GridContainer" CornerRadius="{StaticResource DefaultCornerRadius}"></Border>
                                    <Grid Width="440" HorizontalAlignment="Left">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="Auto" SharedSizeGroup="SelectSource1"></ColumnDefinition>
                                            <ColumnDefinition Width="Auto" SharedSizeGroup="SelectSource2"></ColumnDefinition>
                                            <ColumnDefinition Width="Auto" SharedSizeGroup="SelectSource3"></ColumnDefinition>
                                        </Grid.ColumnDefinitions>
                                        <!--Show database status-->
                                        <Button Margin="10 0 0 0"
                                                Background="Transparent"
                                                attachProperty:VisionElement.BackgroundAccent="Transparent"
                                                attachProperty:VisionElement.BackgroundOnMouseDown="Transparent"
                                                Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=editor:DataSourceSelectorView}, Path=DataContext.CmdRefreshDataSource}"
                                                CommandParameter="{Binding}"
                                                ToolTip="{Binding StatusInfo}">
                                            <Button.Style>
                                                <Style TargetType="Button" BasedOn="{StaticResource ButtonBarAccentStyle}">
                                                    <Setter Property="Content">
                                                        <Setter.Value>
                                                            <Path Height="20" Width="20" Stretch="Uniform">
                                                                <Path.Style>
                                                                    <Style TargetType="Path">
                                                                        <Setter Property="Data" Value="{StaticResource GeometryCloudDisconnected}"></Setter>
                                                                        <Setter Property="Fill" Value="Red"></Setter>
                                                                        <Style.Triggers>
                                                                            <MultiDataTrigger>
                                                                                <MultiDataTrigger.Conditions>
                                                                                    <Condition Binding="{Binding Status}" Value="{x:Static dao:EnumDatabaseStatus.OK}"/>
                                                                                    <Condition Binding="{Binding IsWritable}" Value="True"/>
                                                                                </MultiDataTrigger.Conditions>
                                                                                <MultiDataTrigger.Setters>
                                                                                    <Setter Property="Data" Value="{StaticResource GeometryCloudConnected}"></Setter>
                                                                                    <Setter Property="Fill" Value="Green"></Setter>
                                                                                </MultiDataTrigger.Setters>
                                                                            </MultiDataTrigger>
                                                                            <MultiDataTrigger>
                                                                                <MultiDataTrigger.Conditions>
                                                                                    <Condition Binding="{Binding Status}" Value="{x:Static dao:EnumDatabaseStatus.OK}"/>
                                                                                    <Condition Binding="{Binding IsWritable}" Value="False"/>
                                                                                </MultiDataTrigger.Conditions>
                                                                                <MultiDataTrigger.Setters>
                                                                                    <Setter Property="Data" Value="{StaticResource GeometryCloudConnectedReadonly}"></Setter>
                                                                                    <Setter Property="Fill" Value="Green"></Setter>
                                                                                </MultiDataTrigger.Setters>
                                                                            </MultiDataTrigger>
                                                                        </Style.Triggers>
                                                                    </Style>
                                                                </Path.Style>
                                                            </Path>
                                                        </Setter.Value>
                                                    </Setter>
                                                    <Style.Triggers>
                                                        <!--Show reconnect button when hover-->
                                                        <Trigger Property="IsMouseOver" Value="True">
                                                            <Setter Property="Content">
                                                                <Setter.Value>
                                                                    <Grid Height="20" Width="20">
                                                                        <Path Height="16" Width="16" UseLayoutRounding="True" Stretch="Uniform">
                                                                            <Path.Style>
                                                                                <Style TargetType="Path">
                                                                                    <Setter Property="Data" Value="{StaticResource GeometryRefresh}"></Setter>
                                                                                    <Setter Property="Fill" Value="{DynamicResource PrimaryTextBrush}"></Setter>
                                                                                </Style>
                                                                            </Path.Style>
                                                                        </Path>
                                                                    </Grid>
                                                                </Setter.Value>
                                                            </Setter>
                                                        </Trigger>
                                                    </Style.Triggers>
                                                </Style>
                                            </Button.Style>
                                        </Button>
                                        <TextBlock Grid.Column="1" FontSize="{DynamicResource GlobalFontSizeSubtitle}" 
                                                   Text="{Binding DataSourceName}" 
                                                   ToolTip="{Binding DataSourceName}" 
                                                   Foreground="{DynamicResource PrimaryTextBrush}"
                                                   Margin="5 0" 
                                                   VerticalAlignment="Center"></TextBlock>
                                        <StackPanel Grid.Column="2" Orientation="Horizontal">
                                            <TextBlock FontSize="{DynamicResource GlobalFontSizeSubtitle}" 
                                                       Text="(Readonly)" 
                                                       Margin="0 0 5 0" 
                                                       Visibility="{Binding IsWritable, Converter={StaticResource ConverterBool2VisibleInv}}" 
                                                       Foreground="{DynamicResource AccentTextBrush}" 
                                                       Background="{DynamicResource AccentMidBrush}" 
                                                       VerticalAlignment="Center" 
                                                       TextTrimming="CharacterEllipsis"></TextBlock>
                                            <TextBlock FontSize="{DynamicResource GlobalFontSizeSubtitle}" Text="{Binding Description}" 
                                                       ToolTip="{Binding Description}" 
                                                       Foreground="{DynamicResource PrimaryTextBrush}"
                                                       Margin="5 0 10 0" 
                                                       VerticalAlignment="Center" 
                                                       TextTrimming="CharacterEllipsis"></TextBlock>
                                        </StackPanel>
                                    </Grid>
                                    <Button HorizontalAlignment="Right" Content="{DynamicResource Select}" Margin="5 0"
                                            Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Window}, Path=DataContext.CmdSelect}"
                                            CommandParameter="{Binding}"
                                            >
                                        <Button.Style>
                                            <Style TargetType="Button" BasedOn="{StaticResource ButtonAccentStyle}">
                                                <Setter Property="IsEnabled" Value="False"></Setter>
                                                <Style.Triggers>
                                                    <MultiDataTrigger>
                                                        <MultiDataTrigger.Conditions>
                                                            <Condition Binding="{Binding IsWritable}" Value="True"></Condition>
                                                            <Condition Binding="{Binding Status}" Value="{x:Static dao:EnumDatabaseStatus.OK}"></Condition>
                                                        </MultiDataTrigger.Conditions>
                                                        <MultiDataTrigger.Setters>
                                                            <Setter Property="IsEnabled" Value="True"></Setter>
                                                        </MultiDataTrigger.Setters>
                                                    </MultiDataTrigger>
                                                </Style.Triggers>
                                            </Style>
                                        </Button.Style>
                                    </Button>
                                </Grid>
                                <DataTemplate.Triggers>
                                    <Trigger Property="IsMouseOver" Value="True">
                                        <Setter Property="Background" TargetName="GridContainer" Value="{DynamicResource PrimaryTextBrush}"></Setter>
                                        <Setter Property="Opacity" Value="0.2" TargetName="GridContainer" />
                                    </Trigger>
                                </DataTemplate.Triggers>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ListBox>

                    <StackPanel Margin="0 20" Orientation="Horizontal" HorizontalAlignment="Center">
                        <Button Command="{Binding CmdCancel}" Content="{DynamicResource Cancel}" Width="100" Margin="10 0"></Button>
                    </StackPanel>
                </StackPanel>
            </Grid>
        </Grid>
    </Border>
</styles:WindowChromeBase>
