<UserControl x:Class="XamlViewer.Views.TabsControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
             xmlns:mwt="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
             xmlns:prism="http://prismlibrary.com/"
             xmlns:themes="clr-namespace:XamlTheme;assembly=XamlTheme"
             xmlns:controls="clr-namespace:XamlTheme.Controls;assembly=XamlTheme"
             xmlns:behaviors="clr-namespace:XamlTheme.Behaviors;assembly=XamlTheme"
             xmlns:swm="clr-namespace:System.Windows.Media;assembly=PresentationCore"
             prism:ViewModelLocator.AutoWireViewModel="True"> 
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="auto"/>
            <ColumnDefinition Width="auto"/>
        </Grid.ColumnDefinitions>
        <ListBox Height="24" AllowDrop="True"
                 ItemsSource="{Binding XamlTabs}"
                 ItemTemplate="{StaticResource XamlSelectionTemplate}"
                 ItemContainerStyle="{StaticResource XamlSelectionItemStyle}"
                 Style="{StaticResource {x:Static themes:ResourceKeys.NormalListBoxStyleKey}}"
                 ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
                 ScrollViewer.VerticalScrollBarVisibility="Disabled">
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapPanel Orientation="Horizontal">
                        <b:Interaction.Behaviors>
                            <behaviors:DragItemsPositionBehavior DisabledYPosition="True" MoveItemFromItemsSource="{Binding DataContext.MoveTabPosAction, RelativeSource={RelativeSource AncestorType=ItemsControl}}"/>
                        </b:Interaction.Behaviors>
                    </WrapPanel>
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>  
            <b:Interaction.Triggers>
                <b:EventTrigger EventName="Loaded">
                    <b:InvokeCommandAction Command="{Binding LoadedCommand}" PassEventArgsToCommand="true"/>
                </b:EventTrigger>
                <b:EventTrigger EventName="SizeChanged">
                    <b:InvokeCommandAction Command="{Binding SizeChangedCommand}" PassEventArgsToCommand="true"/>
                </b:EventTrigger>
            </b:Interaction.Triggers>
        </ListBox>
        <controls:StatusToggle x:Name="ActiveFilesButton" Grid.Column="1" Width="35" ToolTip="Active Files"
                               IsChecked="{Binding IsOpenActiveFiles,Mode=TwoWay}">
            <controls:StatusToggle.CheckedContent>
                <controls:DrawingIcon>
                    <controls:DrawingIcon.Drawing>
                        <GeometryDrawing Brush="{Binding Foreground, RelativeSource={RelativeSource AncestorType=controls:StatusToggle},FallbackValue={x:Static swm:Brushes.Transparent}}"
                                         Geometry="M0,0 H9V2 H0 M0,4 H9V6 H8V7 H7V8 H6V9 H5V10 H4V9 H3V8 H2V7 H1V6 H0z" />
                    </controls:DrawingIcon.Drawing>
                    <controls:DrawingIcon.HDPIDrawing>
                        <GeometryDrawing Brush="{Binding Foreground, RelativeSource={RelativeSource AncestorType=controls:StatusToggle},FallbackValue={x:Static swm:Brushes.Transparent}}"
                                         Geometry="M0,0 H9V2 H0 M0,4 H9V5 L4.5,10 0,5z" />
                    </controls:DrawingIcon.HDPIDrawing>
                </controls:DrawingIcon>
            </controls:StatusToggle.CheckedContent>
            <controls:StatusToggle.UnCheckedContent>
                <controls:DrawingIcon>
                    <controls:DrawingIcon.Drawing>
                        <GeometryDrawing Brush="{Binding Foreground, RelativeSource={RelativeSource AncestorType=controls:StatusToggle},FallbackValue={x:Static swm:Brushes.Transparent}}"
                                         Geometry="M0,0 H9V2 H0 M0,4 H9V6 H8V7 H7V8 H6V9 H5V10 H4V9 H3V8 H2V7 H1V6 H0z" />
                    </controls:DrawingIcon.Drawing>
                    <controls:DrawingIcon.HDPIDrawing>
                        <GeometryDrawing Brush="{Binding Foreground, RelativeSource={RelativeSource AncestorType=controls:StatusToggle},FallbackValue={x:Static swm:Brushes.Transparent}}"
                                         Geometry="M0,0 H9V2 H0 M0,4 H9V5 L4.5,10 0,5z" />
                    </controls:DrawingIcon.HDPIDrawing>
                </controls:DrawingIcon>
            </controls:StatusToggle.UnCheckedContent>
        </controls:StatusToggle>
        <ToggleButton Grid.Column="2" Width="35"
                      IsChecked="{Binding IsOpenDataSource,Mode=TwoWay}"
                      Style="{StaticResource {x:Static themes:ResourceKeys.NormalToggleButtonStyleKey}}">
            <ToggleButton.ToolTip>
                <StackPanel Orientation="Horizontal">
                    <TextBlock Grid.Row="0" Grid.Column="0" Text="Data Source"/>
                    <TextBlock Grid.Row="0" Grid.Column="1" Text=" [Binding]" HorizontalAlignment="Left"
                               Visibility="{Binding IsSyncDataSource,Converter={StaticResource boolToVisibilityConverter}}"/>
                </StackPanel>
            </ToggleButton.ToolTip>
            <Grid HorizontalAlignment="Center" VerticalAlignment="Center">
                <Path Fill="{Binding Foreground, RelativeSource={RelativeSource AncestorType=ToggleButton}}"
                      Data="M1,9 L1,10 5,10 5,9 z M0,8 L11,8 11,11 0,11 z M1,5 L1,6 5,6 5,5 z M0,4 L11,4 11,7 0,7 z M1,1 L1,2 5,2 5,1 z M0,0 L11,0 11,3 0,3 z"/>
                <Ellipse Height="7" Width="7" StrokeThickness="1" Stroke="#EFEFF2" Fill="#FF02D002" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,-2,-2,0"
                         Visibility="{Binding IsSyncDataSource,Converter={StaticResource boolToVisibilityConverter}}"/>
            </Grid>
        </ToggleButton>
        <Path Grid.ColumnSpan="3" Stretch="Fill" Height="2" Stroke="#007ACC" StrokeThickness="2" Data="M0,0 1,0" VerticalAlignment="Bottom"/>
        <Popup Placement="Bottom" StaysOpen="False" AllowsTransparency="True"
               IsOpen="{Binding IsOpenActiveFiles,Mode=TwoWay}"
               PlacementTarget="{Binding ElementName=ActiveFilesButton}"
               PopupAnimation="Fade">
            <mwt:SystemDropShadowChrome Color="#71000000" Margin="0,0,6,5">
                <Border BorderThickness="1" BorderBrush="LightGray" Background="#E7E8EC" Width="230">
                    <ListBox x:Name="ActiveFilesListBox"
                             Foreground="Black"
                             Grid.IsSharedSizeScope="true"
                             ItemsSource="{Binding XamlTabs}"
                             ItemTemplate="{StaticResource ActiveFilesTemplate}"
                             ItemContainerStyle="{StaticResource ActiveFilesItemStyle}"
                             Style="{StaticResource {x:Static themes:ResourceKeys.NormalListBoxStyleKey}}"
                             ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
                             ScrollViewer.VerticalScrollBarVisibility="Auto">
                        <b:Interaction.Triggers>
                            <b:EventTrigger EventName="SelectionChanged">
                                <b:InvokeCommandAction Command="{Binding SelectionChangedCommand}" CommandParameter="{Binding SelectedIndex,ElementName=ActiveFilesListBox}"/>
                            </b:EventTrigger> 
                        </b:Interaction.Triggers>
                    </ListBox>
                </Border>
            </mwt:SystemDropShadowChrome>
        </Popup>
    </Grid>
</UserControl>
