<UserControl x:Class="HandBrakeWPF.Views.InstantView"
             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:controls="clr-namespace:HandBrakeWPF.Controls"
             xmlns:converters="clr-namespace:HandBrakeWPF.Converters"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
             mc:Ignorable="d" 
             cal:Message.Attach="[Event Loaded] = [Action Load]"
             >

    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Drop">
            <cal:ActionMessage MethodName="FilesDroppedOnWindow">
                <cal:Parameter Value="$eventArgs" />
            </cal:ActionMessage>
        </i:EventTrigger>
    </i:Interaction.Triggers>

    <UserControl.Resources>
        <converters:BooleanToVisibilityConverter x:Key="boolToVisConverter" />
    </UserControl.Resources>

    <!-- Window Body -->
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>


        <!-- Source -->
        <StackPanel Orientation="Vertical" Grid.Row="0">
            <!--  Source  -->
            <StackPanel Margin="10,5,5,5"
                            HorizontalAlignment="Stretch"
                            VerticalAlignment="Stretch"
                            >
                <StackPanel Orientation="Horizontal">
                    <Label Content="Source" FontWeight="Bold" />
                </StackPanel>

                <StackPanel Orientation="Horizontal" VerticalAlignment="Center" Margin="8,10,0,10">

                    <TextBlock Text="Drag and Drop a file  - OR - Open a " />
                    <Button cal:Message.Attach="[Event Click] = [Action FileScan]" Padding="8,2">
                        File
                    </Button>
                    <TextBlock Text="- OR -" FontWeight="Bold" Margin="10,0,10,0" />
                    <Button cal:Message.Attach="[Event Click] = [Action FolderScan]" Padding="8,2">
                        Folder
                    </Button>

                </StackPanel>

                <ListBox Grid.Row="2"
                 Margin="10,10,10,10"
                         MinHeight="150" MaxHeight="150"
                 VerticalAlignment="Stretch"
                 Background="LightGray"
                 ItemsSource="{Binding TitleList}"
                 SelectionMode="Single">
                    <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.ContextMenu>
                        <ContextMenu>
                            <MenuItem Header="Select All" cal:Message.Attach="[Event Click] = [Action SelectAll]" />
                            <MenuItem Header="Deselect All" cal:Message.Attach="[Event Click] = [Action UnSelectAll]" />
                            <Separator />
                            <MenuItem Header="Order by Title" IsChecked="{Binding OrderedByTitle}" cal:Message.Attach="[Event Click] = [Action OrderByTitle]" />
                            <MenuItem Header="Order by Duration" IsChecked="{Binding OrderedByDuration}" cal:Message.Attach="[Event Click] = [Action OrderByDuration]" />
                        </ContextMenu>
                    </ListBox.ContextMenu>

                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <Grid HorizontalAlignment="Stretch" MinHeight="28">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>

                                <CheckBox IsChecked="{Binding IsSelected}" Grid.RowSpan="2" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" />

                                <StackPanel Grid.Row="0" Grid.Column="1" Orientation="Horizontal" Margin="10,0,0,0" >
                                    <TextBlock Text="Title:" Margin="0,0,5,0" FontWeight="Bold" />
                                    <TextBlock Text="{Binding Title}" Margin="5,0,5,0" />
                                </StackPanel>

                                <StackPanel Grid.Row="1" Grid.Column="1" Orientation="Horizontal" Margin="10,0,0,0" >
                                    <TextBlock Text="Source:" Margin="0,0,5,0" FontWeight="Bold" />
                                    <TextBlock Text="{Binding SourceName}" Margin="5,0,5,0" />
                                </StackPanel>
                            </Grid>

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


        <!-- Destination -->
        <StackPanel Grid.Row="1"
                        Margin="10,5,5,5"
                        HorizontalAlignment="Stretch"
                        VerticalAlignment="Stretch"
                        >
            <Label Content="Destination" FontWeight="Bold" />
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <Label Margin="8,0,0,0" Content="File" />
                <TextBox Name="Destination"
                             Grid.Column="1"
                             Margin="8,0,0,0"
                             Text="{Binding OutputDirectory,
                                            UpdateSourceTrigger=PropertyChanged}"
                             />
                <Button Name="DestinationBrowser"
                            Grid.Column="2"
                            Margin="8,0,5,0"
                        Padding="8,2"
                            Content="Browse"
                            cal:Message.Attach="[Event Click] = [Action BrowseDestination]"
                            />
            </Grid>
        </StackPanel>

        <!-- Opitons -->
        <StackPanel Grid.Row="2"
                        Margin="10,5,5,5"
                        HorizontalAlignment="Stretch"
                        VerticalAlignment="Stretch"
                        >
            <Label Content="Options" FontWeight="Bold" />

            <StackPanel Orientation="Horizontal" Margin="8,0,0,0">
                <TextBlock Text="Preset:" Margin="0,0,5,0" />
                <ComboBox ItemsSource="{Binding Presets}" SelectedItem="{Binding SelectedPreset}" MinWidth="150" />
            </StackPanel>

        </StackPanel>


        <!-- Buttons and Queueing -->
        <Grid Grid.Row="3" Margin="10,5,5,5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Label Content="Start" FontWeight="Bold" Grid.Row="0" />
            <Button Content="Start Encoding" cal:Message.Attach="[Event Click] = [Action StartEncode]"  FontWeight="Bold" Grid.Row="1" Padding="8,2" HorizontalAlignment="Center"
                    Visibility="{Binding IsEncoding, Converter={StaticResource boolToVisConverter}, ConverterParameter=true}" />
            <Button Content="Stop Encoding" cal:Message.Attach="[Event Click] = [Action StopEncode]"  FontWeight="Bold" Grid.Row="1" Padding="8,2" HorizontalAlignment="Center" 
                    Visibility="{Binding IsEncoding, Converter={StaticResource boolToVisConverter}, ConverterParameter=false}" />
        </Grid>


        <!--  StatusPanel  -->
        <controls:StatusPanel x:Name="loadingPanel"
                              Grid.Row="3"
                              Grid.RowSpan="2"
                              Height="70"
                              VerticalAlignment="Bottom"
                              Panel.ZIndex="10"
                              IsLoading="{Binding ShowStatusWindow}"
                              Message="{Binding StatusLabel}"
                              SubMessage="Please Wait ..."
                              />

        <!--  Status Bar  -->
        <StatusBar Grid.Row="4" Grid.ColumnSpan="2" MinHeight="32" >

            <ProgressBar Value="{Binding ProgressPercentage}" Visibility="{Binding IsEncoding, Converter={StaticResource boolToVisConverter}}"
                         Width="100" Height="18" VerticalAlignment="Center"/>
            <Label VerticalAlignment="Center"
                   Content="{Binding Path=ProgramStatusLabel}" />

        </StatusBar>

    </Grid>
</UserControl>
