<Window
    x:Class="Plpext.UI.Views.MainWindow"
    xmlns="https://github.com/avaloniaui"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:c="using:Plpext.UI"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:vm="using:Plpext.UI.ViewModels"
    Title="Plpext"
    d:DesignHeight="450"
    d:DesignWidth="800"
    x:DataType="vm:MainWindowViewModel"
    Icon="/Assets/plpext.png"
    mc:Ignorable="d">
    <Window.Styles>
        <StyleInclude Source="/Styles/Button.axaml" />
        <StyleInclude Source="/Styles/AudioPlayerControl.axaml" />
        <StyleInclude Source="/Styles/Window.axaml" />
        <StyleInclude Source="/Styles/Border.axaml" />
        <StyleInclude Source="/Styles/TextBox.axaml" />
        <StyleInclude Source="/Styles/ProgressBar.axaml" />
    </Window.Styles>

    <Design.DataContext>
        <vm:MainWindowViewModel />
    </Design.DataContext>

    <Grid
        Margin="16,8,16,8"
        ColumnDefinitions="300,32,*"
        RowDefinitions="Auto,Auto,*">
        <Border
            Grid.Row="0"
            Grid.Column="0"
            Classes="Section">

            <StackPanel Orientation="Vertical">
                <Grid
                    Margin="8"
                    ColumnDefinitions="*"
                    RowDefinitions="*, Auto, Auto">
                    <Label Grid.Row="0" Content="Select your .plp pack file:" />
                    <StackPanel
                        Grid.Row="1"
                        Height="36"
                        Orientation="Horizontal"
                        Spacing="2">
                        <TextBox
                            Width="248"
                            HorizontalContentAlignment="Stretch"
                            VerticalContentAlignment="Center"
                            Classes="Primary"
                            Text="{Binding OriginPath}" />
                        <Button Classes="Primary" Command="{Binding SelectOriginPathCommand}">
                            <TextBlock Height="24">...</TextBlock>
                        </Button>
                    </StackPanel>
                    <Button
                        Grid.Row="2"
                        Height="38"
                        Margin="0,4,0,0"
                        HorizontalAlignment="Right"
                        Classes="Primary"
                        Command="{Binding LoadFileCommand}">
                        <TextBlock VerticalAlignment="Center">Load</TextBlock>
                    </Button>
                </Grid>
                <Grid
                    Margin="8"
                    ColumnDefinitions="*, *"
                    RowDefinitions="*, Auto, Auto">
                    <Label
                        Grid.Row="0"
                        Grid.Column="0"
                        Grid.ColumnSpan="2"
                        Content="Select output folder:" />
                    <StackPanel
                        Grid.Row="1"
                        Grid.Column="0"
                        Grid.ColumnSpan="2"
                        Height="36"
                        Orientation="Horizontal"
                        Spacing="2">
                        <TextBox
                            Width="248"
                            VerticalContentAlignment="Center"
                            Classes="Primary"
                            Text="{Binding TargetPath}" />
                        <Button Classes="Primary" Command="{Binding SelectTargetPathCommand}">
                            <TextBlock Height="24">...</TextBlock>
                        </Button>
                    </StackPanel>
                    <Button
                        Grid.Row="2"
                        Grid.Column="0"
                        Height="38"
                        HorizontalAlignment="Left"
                        Classes="Primary"
                        Command="{Binding ConvertAllFilesCommand}">
                        <TextBlock VerticalAlignment="Center">Extract All</TextBlock>
                    </Button>
                    <Button
                        Grid.Row="2"
                        Grid.Column="1"
                        Height="38"
                        HorizontalAlignment="Right"
                        Classes="Primary"
                        Command="{Binding ConvertSelectedFilesCommand}">
                        <TextBlock VerticalAlignment="Center">Extract Selected</TextBlock>
                    </Button>
                </Grid>

            </StackPanel>

        </Border>
        <Grid Grid.Row="2" Grid.Column="0">
            <StackPanel
                Height="60"
                VerticalAlignment="Center"
                IsVisible="{Binding ShowProgressBar}"
                Orientation="Vertical">
                <Label Content="{Binding ProgressBarText}" />
                <Border Classes="Section">
                    <ProgressBar
                        Width="298"
                        Height="50"
                        IsIndeterminate="{Binding IsProgressBarIndeterminate}"
                        Orientation="Horizontal"
                        Value="{Binding ProgressBarValue}" />
                </Border>
                <Label HorizontalAlignment="Right" Content="{Binding ProgressBarDetails}" />
            </StackPanel>
        </Grid>

        <Grid
            Grid.Row="0"
            Grid.RowSpan="3"
            Grid.Column="2">
            <StackPanel Orientation="Vertical">
                <StackPanel Orientation="Horizontal">
                    <Label Content="Audio Files" />
                </StackPanel>
                <DataGrid
                    MaxHeight="410"
                    AreRowDetailsFrozen="True"
                    AutoGenerateColumns="False"
                    CanUserReorderColumns="False"
                    CanUserResizeColumns="False"
                    CanUserSortColumns="False"
                    HeadersVisibility="None"
                    IsReadOnly="False"
                    ItemsSource="{Binding AudioFiles}"
                    SelectionMode="Extended"
                    VerticalScrollBarVisibility="Visible">
                    <DataGrid.Columns>
                        <DataGridTemplateColumn Width="36">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <CheckBox
                                        HorizontalAlignment="Center"
                                        VerticalAlignment="Center"
                                        IsChecked="{Binding IsSelected, Mode=TwoWay}" />
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                        <DataGridTemplateColumn Width="*">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate DataType="vm:AudioPlayerViewModel">
                                    <Label VerticalAlignment="Center" Content="{Binding Name}" />
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                        <DataGridTemplateColumn Width="200" MinWidth="200">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate DataType="vm:AudioPlayerViewModel">
                                    <c:AudioPlayerControl
                                        Margin="0,0,16,0"
                                        CurrentDuration="{Binding CurrentDuration}"
                                        IsPlaying="{Binding IsPlaying}"
                                        PlayCommand="{Binding PlayCommand}"
                                        PlaybackState="{Binding PlaybackState}"
                                        Progress="{Binding Progress}"
                                        StopCommand="{Binding StopCommand}"
                                        TotalDuration="{Binding TotalDuration}" />
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                    </DataGrid.Columns>
                </DataGrid>
            </StackPanel>
        </Grid>
    </Grid>

</Window>