<UserControl x:Class="FeenPhone.WPFApp.Controls.UserAudioPlayerWPF"
             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" 
             d:DataContext="{d:DesignData Source=SampleData/UserAudioPlayer.xaml}"
             mc:Ignorable="d" 
             Background="{StaticResource clrBackgroundPrimary}"
             d:DesignWidth="800">
    <DockPanel>
        <Border BorderBrush="Black" BorderThickness="0 0 0 1" Background="{StaticResource clrBackgroundHeaders}">
            <Label VerticalAlignment="Center" Content="{Binding Path=User.Username}">
                <Label.LayoutTransform>
                    <TransformGroup>
                        <RotateTransform Angle="-90"/>
                    </TransformGroup>
                </Label.LayoutTransform>
            </Label>
        </Border>
        <ProgressBar Orientation="Vertical" Width="20" Minimum="0" Maximum="100" Value="{Binding VisSource.LevelDbPercent}"></ProgressBar>
        <Slider 
            Orientation="Vertical"
            Minimum="{Binding LevelManager.Min}" 
            Maximum="{Binding LevelManager.Max}" 
            Value="{Binding LevelManager.Level, Mode=TwoWay}" 
            IsEnabled="{Binding LevelManager.IsAttached}" 
        />
        <StackPanel>
            <StackPanel.Resources>
                <Style TargetType="{x:Type Label}">
                    <Setter Property="Width" Value="110"/>
                    <Setter Property="Height" Value="18"/>
                    <Setter Property="VerticalAlignment" Value="Top"/>
                    <Setter Property="Padding" Value="0"/>
                </Style>
                <Style TargetType="{x:Type TextBlock}">
                    <Setter Property="Height" Value="18"></Setter>
                    <Setter Property="VerticalAlignment" Value="Top"/>
                    <Setter Property="Padding" Value="10 0 0 0"/>
                </Style>
            </StackPanel.Resources>

            <WrapPanel Visibility="Collapsed">
                <Label>Format</Label>
                <TextBlock Text="{Binding Path=OutputFormat}"></TextBlock>
            </WrapPanel>
            <WrapPanel>
                <Label>Incoming Codec</Label>
                <TextBlock Text="{Binding Path=CodecName}"></TextBlock>
            </WrapPanel>
            <DockPanel ToolTip="Audio data in milliseconds of lag that has been received and is buffered for play.  When duration exceeds max buffer size, incoming data will be dropped">
                <Grid Margin="0 0 5 0" >
                    <Label>Buffer</Label>
                    <Button 
                        ToolTip="Clear the audio buffer to reduce incoming latency"
                        HorizontalAlignment="Right" 
                        Click="Buffer_Clear_Click" 
                        Style="{StaticResource DumpButton}">
                        <TextBlock Margin="0" Padding="0" FontSize="11">BUFF DUMP</TextBlock>
                    </Button>
                </Grid>
                <Grid Name="modelValueContainer">
                    <ProgressBar 
                                  Height="{Binding ElementName=modelValueContainer, Path=ActualHeight}" 
                                  Width="{Binding ElementName=modelValueContainer, Path=ActualWidth}" 
                                  Value="{Binding Path=BufferedDurationMs}"
                                  Minimum="{Binding Path=MinBufferedDurationMs}"
                                  Maximum="{Binding Path=MaxBufferedDurationMs}" />
                    <TextBlock Text="{Binding Path=BufferedDurationMs, StringFormat={}{0}ms}" Foreground="{StaticResource clrDumpButtonBorder}" VerticalAlignment="Center"></TextBlock>
                </Grid>
            </DockPanel>
            <WrapPanel>
                <Grid>
                <Label ToolTip="Target buffer size in milliseconds">Buffer Target</Label>
                    <TextBlock TextAlignment="Right" Text="{Binding Path=BufferTarget, StringFormat={}{0}ms}"></TextBlock>
                </Grid>
                <Slider Minimum="{Binding Path=MinBufferedDurationMs}" Maximum="{Binding Path=MaxBufferedDurationMs}" 
                        TickFrequency="10"
                        TickPlacement="TopLeft"
                        IsSnapToTickEnabled="True"
                        MaxHeight="{Binding ElementName=modelValueContainer, Path=ActualHeight}"
                        Value="{Binding Path=BufferTarget}" 
                        ToolTip="{Binding Path=BufferTarget}" 
                        Height="{Binding ElementName=modelValueContainer, Path=ActualHeight}" 
                        Width="{Binding ElementName=modelValueContainer, Path=ActualWidth}">
                </Slider>
            </WrapPanel>
            <WrapPanel Visibility="{Binding Parent.ShowAdvancedControls, Converter={StaticResource BoolToVisConverter}}">
                <Label ToolTip="Enable buffer overruns to be recovered automatically by skipping silence">Buffer Recovery</Label>
                <CheckBox IsChecked="{Binding BufferRecoveryEnabled}">Enabled</CheckBox>
            </WrapPanel>
            <Grid>
                <Grid.Resources>
                    <Style TargetType="{x:Type Label}">
                        <Setter Property="Width" Value="60"/>
                        <Setter Property="Height" Value="18"/>
                        <Setter Property="VerticalAlignment" Value="Top"/>
                        <Setter Property="HorizontalAlignment" Value="Right"/>
                        <Setter Property="Padding" Value="0"/>
                    </Style>
                </Grid.Resources>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <WrapPanel Grid.Column="0" Grid.Row="0" ToolTip="Maximum duration of incoming buffer. When full packets will be dropped." Visibility="Collapsed">
                    <Label>MaxBuffered</Label>
                    <TextBlock Text="{Binding Path=MaxBufferedDurationMs}" ></TextBlock>
                </WrapPanel>
                <WrapPanel Grid.Column="1" Grid.Row="0" ToolTip="Number of incoming packets that were ignored because the buffer was full">
                    <Label>Dropped</Label>
                    <TextBlock Text="{Binding Path=DroppedPackets, StringFormat={}{0} bytes}" ></TextBlock>
                </WrapPanel>
                <WrapPanel Grid.Column="2" Grid.Row="0" ToolTip="Number of silent bytes dropped from incoming stream.">
                    <Label>Skipped</Label>
                    <TextBlock Text="{Binding Path=DroppedSilence, StringFormat={}{0} bytes}"></TextBlock>
                </WrapPanel>
                <WrapPanel Grid.Column="2" Grid.Row="0" ToolTip="Number of silent bytes added to incoming stream." Visibility="Collapsed">
                    <Label>Added Silence</Label>
                    <TextBlock Text="{Binding Path=AddedSilence}"></TextBlock>
                </WrapPanel>
                <WrapPanel Grid.Column="0" Grid.Row="0" ToolTip="Number of times the incoming stream stopped for lack of data">
                    <Label>Underruns</Label>
                    <TextBlock Text="{Binding Path=UnderRuns}"></TextBlock>
                </WrapPanel>
            </Grid>
        </StackPanel>
    </DockPanel>
</UserControl>
