<adonisControls:AdonisWindow x:Class="FModel.Views.AudioPlayer"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:local="clr-namespace:FModel"
         xmlns:audioControls="clr-namespace:FModel.Views.Resources.Controls.Aup"
         xmlns:converters="clr-namespace:FModel.Views.Resources.Converters"
         xmlns:adonisUi="clr-namespace:AdonisUI;assembly=AdonisUI"
         xmlns:adonisControls="clr-namespace:AdonisUI.Controls;assembly=AdonisUI"
         xmlns:adonisExtensions="clr-namespace:AdonisUI.Extensions;assembly=AdonisUI"
         WindowStartupLocation="CenterScreen" IconVisibility="Collapsed"
         Closing="OnClosing" PreviewKeyDown="OnPreviewKeyDown" Activated="OnActivatedDeactivated" Deactivated="OnActivatedDeactivated"
         Height="{Binding Source={x:Static SystemParameters.MaximizedPrimaryScreenHeight}, Converter={converters:RatioConverter}, ConverterParameter='0.50'}"
         Width="{Binding Source={x:Static SystemParameters.MaximizedPrimaryScreenWidth}, Converter={converters:RatioConverter}, ConverterParameter='0.55'}">
    <adonisControls:AdonisWindow.Style>
        <Style TargetType="adonisControls:AdonisWindow" BasedOn="{StaticResource {x:Type adonisControls:AdonisWindow}}" >
            <Setter Property="Title" Value="Audio Player" />
        </Style>
    </adonisControls:AdonisWindow.Style>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="350" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <GroupBox Grid.Column="0" Padding="{adonisUi:Space 0}" Background="Transparent">
            <DockPanel Margin="10">
                <Grid DockPanel.Dock="Top">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="10" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>

                    <TextBlock Grid.Row="0" Grid.Column="0" Text="Devices" VerticalAlignment="Center" Margin="0 0 0 10" />
                    <ComboBox Grid.Row="0" Grid.Column="2" ItemsSource="{Binding AudioPlayer.AudioDevicesView, IsAsync=True}"
                              SelectedItem="{Binding AudioPlayer.SelectedAudioDevice, Mode=TwoWay}" SelectionChanged="OnDeviceSwap">
                        <ComboBox.ItemTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding FriendlyName}" />
                            </DataTemplate>
                        </ComboBox.ItemTemplate>
                    </ComboBox>

                    <TextBlock Grid.Row="1" Grid.Column="0" Text="Volume" VerticalAlignment="Center" Margin="0 0 0 10" />
                    <Slider Grid.Row="1" Grid.Column="2" TickPlacement="None" Minimum="0" Maximum="100" TickFrequency="1"
                            AutoToolTipPlacement="BottomRight" IsMoveToPointEnabled="True" ValueChanged="OnVolumeChange"
                            Value="{Binding AudioPlayerVolume, Source={x:Static local:Settings.UserSettings.Default}, Mode=TwoWay}"/>

                    <TextBlock Grid.Row="2" Grid.Column="0" Text="Encoding" VerticalAlignment="Center" Margin="0 0 0 10" />
                    <TextBlock Grid.Row="2" Grid.Column="2" Text="{Binding AudioPlayer.PlayedFile.Encoding, Converter={x:Static converters:EnumToStringConverter.Instance}}" VerticalAlignment="Center" HorizontalAlignment="Right" />

                    <TextBlock Grid.Row="3" Grid.Column="0" Text="Length" VerticalAlignment="Center" Margin="0 0 0 10" />
                    <TextBlock Grid.Row="3" Grid.Column="2" Text="{Binding AudioPlayer.PlayedFile.Duration}" VerticalAlignment="Center" HorizontalAlignment="Right" />

                    <TextBlock Grid.Row="4" Grid.Column="0" Text="Bytes Per Second" VerticalAlignment="Center" />
                    <TextBlock Grid.Row="4" Grid.Column="2" Text="{Binding AudioPlayer.PlayedFile.BytesPerSecond}" VerticalAlignment="Center" HorizontalAlignment="Right" />
                </Grid>
                <Separator DockPanel.Dock="Top" Tag="PLAYLIST" Style="{StaticResource CustomSeparator}" />
                <Grid DockPanel.Dock="Top" Height="24" Margin="0 0 0 5">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>

                    <Grid Grid.Column="0" ZIndex="1" HorizontalAlignment="Left" Margin="5 2 0 0">
                        <Viewbox Width="16" Height="16">
                            <Canvas Width="24" Height="24">
                                <Path Fill="{DynamicResource {x:Static adonisUi:Brushes.ForegroundBrush}}" Data="{StaticResource SearchIcon}" />
                            </Canvas>
                        </Viewbox>
                    </Grid>
                    <TextBox Grid.Column="0" Grid.ColumnSpan="2" AcceptsTab="False" AcceptsReturn="False"
                             Padding="25 0 0 0" HorizontalAlignment="Stretch" TextChanged="OnFilterTextChanged"
                             adonisExtensions:WatermarkExtension.Watermark="Search by name..." />
                </Grid>
                <ListBox DockPanel.Dock="Top" Style="{StaticResource AudioFilesListBox}" PreviewMouseDoubleClick="OnAudioFileMouseDoubleClick">
                    <ListBox.ContextMenu>
                        <ContextMenu>
                            <MenuItem Header="Play" Command="{Binding AudioPlayer.AudioCommand}" CommandParameter="ForcePlayPause">
                                <MenuItem.Icon>
                                    <Viewbox Width="16" Height="16">
                                        <Canvas Width="24" Height="24">
                                            <Path Fill="{DynamicResource {x:Static adonisUi:Brushes.ForegroundBrush}}" Data="{StaticResource PlayIcon}" />
                                        </Canvas>
                                    </Viewbox>
                                </MenuItem.Icon>
                            </MenuItem>
                            <MenuItem Header="Remove" Command="{Binding AudioPlayer.AudioCommand}" CommandParameter="Remove">
                                <MenuItem.Icon>
                                    <Viewbox Width="16" Height="16">
                                        <Canvas Width="24" Height="24">
                                            <Path Fill="{DynamicResource {x:Static adonisUi:Brushes.ForegroundBrush}}" Data="{StaticResource RemoveIcon}" />
                                        </Canvas>
                                    </Viewbox>
                                </MenuItem.Icon>
                            </MenuItem>
                            <MenuItem Header="Save" Command="{Binding AudioPlayer.AudioCommand}" CommandParameter="Save">
                                <MenuItem.Icon>
                                    <Viewbox Width="16" Height="16">
                                        <Canvas Width="24" Height="24">
                                            <Path Fill="{DynamicResource {x:Static adonisUi:Brushes.ForegroundBrush}}" Data="{StaticResource SaveIcon}" />
                                        </Canvas>
                                    </Viewbox>
                                </MenuItem.Icon>
                            </MenuItem>
                            <MenuItem Header="Save Playlist" Command="{Binding AudioPlayer.AudioCommand}" CommandParameter="Save_Playlist">
                                <MenuItem.Icon>
                                    <Viewbox Width="16" Height="16">
                                        <Canvas Width="24" Height="24">
                                            <Path Fill="{DynamicResource {x:Static adonisUi:Brushes.ForegroundBrush}}" Data="{StaticResource SavePlaylistIcon}" />
                                        </Canvas>
                                    </Viewbox>
                                </MenuItem.Icon>
                            </MenuItem>
                        </ContextMenu>
                    </ListBox.ContextMenu>
                </ListBox>
            </DockPanel>
        </GroupBox>

        <Grid Grid.Column="1">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <audioControls:Timeclock Grid.Row="0" />
            <StackPanel Grid.Row="1" Margin="0 0 25 0"
                        HorizontalAlignment="Right" VerticalAlignment="Top" Orientation="Horizontal">
                <Button Style="{DynamicResource {x:Static adonisUi:Styles.ToolbarButton}}" ToolTip="Previous"
                        Command="{Binding AudioPlayer.AudioCommand}" CommandParameter="Previous">
                    <Viewbox Width="16" Height="16">
                        <Canvas Width="24" Height="24">
                            <Path Fill="#DAE5F2" Data="{StaticResource SkipPreviousIcon}" />
                        </Canvas>
                    </Viewbox>
                </Button>
                <Button Style="{StaticResource PlayPauseToolbarButton}"
                        Command="{Binding AudioPlayer.AudioCommand}" CommandParameter="PlayPause" />
                <Button Style="{DynamicResource {x:Static adonisUi:Styles.ToolbarButton}}" ToolTip="Next"
                        Command="{Binding AudioPlayer.AudioCommand}" CommandParameter="Next">
                    <Viewbox Width="16" Height="16">
                        <Canvas Width="24" Height="24">
                            <Path Fill="#DAE5F2" Data="{StaticResource SkipNextIcon}" />
                        </Canvas>
                    </Viewbox>
                </Button>
            </StackPanel>
            <audioControls:SpectrumAnalyzer Grid.Row="0" Grid.RowSpan="2" />
            <audioControls:Timeline Grid.Row="2" />
        </Grid>
    </Grid>
</adonisControls:AdonisWindow>
