<Window x:Class="HandBrakeWPF.Views.QueueView"
             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:cal="http://www.caliburnproject.org"
             xmlns:Converters="clr-namespace:HandBrakeWPF.Converters"
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
        xmlns:dd="clr-namespace:GongSolutions.Wpf.DragDrop;assembly=GongSolutions.Wpf.DragDrop" mc:Ignorable="d" Title="{Binding Title}" 
             Width="600" Height="400"
             Background="#FFF0F0F0">

    <Window.Resources>
        <Converters:BooleanToVisibilityConverter x:Key="boolToVisConverter" />
        <Converters:FullPathToFileNameConverter x:Key="filePathToFilenameConverter" />
    </Window.Resources>

    <Grid >

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <ToolBar Name="mainToolBar" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"  SnapsToDevicePixels="False">

            <Button Name="Start" cal:Message.Attach="[Event Click] = [Action StartEncode]" Visibility="{Binding IsEncoding, Converter={StaticResource boolToVisConverter}, ConverterParameter=true}">
                <StackPanel Orientation="Horizontal">
                    <Image Source="Images/Play.png" Height="32" Width="32" />
                    <Label Content="Start"  Margin="8,0,0,0" VerticalAlignment="Center" />
                </StackPanel>
            </Button>

            <Button Name="Pause" cal:Message.Attach="[Event Click] = [Action PauseEncode]" Visibility="{Binding IsEncoding, Converter={StaticResource boolToVisConverter}, ConverterParameter=false}">
                <StackPanel Orientation="Horizontal">
                    <Image Source="Images/Pause.png" Height="32" Width="32" />
                    <Label Content="Pause"  Margin="8,0,0,0" VerticalAlignment="Center" />
                </StackPanel>
            </Button>
        </ToolBar>

        <StackPanel Grid.Row="1" Margin="10,20,10,20">
            <TextBlock Text="{Binding JobsPending}" />
            <TextBlock Text="{Binding JobStatus}" />
        </StackPanel>

        <ListBox Grid.Row="2" ItemsSource="{Binding QueueJobs}" SelectionMode="Extended" Background="LightGray" Margin="10,0,10,10"
                 dd:DragDrop.IsDragSource="True" dd:DragDrop.IsDropTarget="True"
                 dd:DragDrop.DropHandler="{Binding}">
            <ListBox.ItemContainerStyle>
                <Style TargetType="ListBoxItem">
                    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                    <Setter Property="Background" Value="WhiteSmoke" />
                    <Setter Property="Margin" Value="0,0,0,1" />
                </Style>
            </ListBox.ItemContainerStyle>

            <ListBox.ItemTemplate>
                <DataTemplate x:Name="QueueItemTemplate">

                    <Grid HorizontalAlignment="Stretch" >
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>

                        <!-- Marker -->
                        <Image Source="Images/Movies.png" Width="16" Height="16" Grid.Column="0" Margin="10,0,10,0" />

                        <!-- Settings -->
                            <StackPanel Grid.Column="1" HorizontalAlignment="Stretch" Margin="0,5,0,5">
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="Title: " FontWeight="Bold" />
                                    <TextBlock Text="{Binding Task.Title}"/>

                                    <TextBlock Text="{Binding Task.PointToPointMode}" FontWeight="Bold" Margin="10,0,0,0" />
                                    <TextBlock Text=": "  />
                                    <TextBlock Text="{Binding Task.StartPoint}"/>
                                    <TextBlock Text="to" Margin="5,0,5,0" />
                                    <TextBlock Text="{Binding Task.EndPoint}"/>
                                </StackPanel>

                                <!-- TODO Support Drive Label Name-->
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="Source: " FontWeight="Bold" />
                                    <TextBlock Text="{Binding Task.Source, Converter={StaticResource filePathToFilenameConverter}}"/>
                                </StackPanel>

                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="Destination: " FontWeight="Bold" />
                                    <TextBlock Text="{Binding Task.Destination, Converter={StaticResource filePathToFilenameConverter}}"/>
                                </StackPanel>
                            </StackPanel>
         
                        <!-- Delete -->
                        <Image Source="Images/delete.png" Width="16" Height="16" Grid.Column="2" Margin="10,0,10,0">
                            <i:Interaction.Triggers>
                                <i:EventTrigger EventName="MouseDown">
                                    <cal:ActionMessage MethodName="RemoveJob">
                                        <cal:Parameter Value="{Binding}" />
                                    </cal:ActionMessage>
                                </i:EventTrigger>
                            </i:Interaction.Triggers>
                        </Image>
                    </Grid>


                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>


    </Grid>
</Window>
