<UserControl x:Class="FeenPhone.WPFApp.Controls.AudioInWPF"
             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:scm= "clr-namespace:System.ComponentModel;assembly=WindowsBase" 
             xmlns:dat="clr-namespace:System.Windows.Data;assembly=PresentationFramework"
             mc:Ignorable="d" 
             Background="{StaticResource clrBackgroundPrimary}"
             d:DesignHeight="100" d:DesignWidth="400">
    <UserControl.Resources>
        <Style TargetType="TextBlock">
            <Setter Property="VerticalAlignment" Value="Center"/>
        </Style>
        <CollectionViewSource x:Key="InputsView" Source="{Binding Path=InputSourceList}"  IsLiveFilteringRequested="True" >
            <CollectionViewSource.GroupDescriptions>
                <dat:PropertyGroupDescription PropertyName="Provider" />
            </CollectionViewSource.GroupDescriptions>
        </CollectionViewSource>
    </UserControl.Resources>
    <DockPanel>
        <TextBlock Background="{StaticResource clrBackgroundHeaders}" DockPanel.Dock="Top" TextAlignment="Center">AUDIO IN</TextBlock>
        <DockPanel IsEnabled="{Binding LevelManager, Converter={StaticResource NullToBoolConverter}}">
            <ProgressBar Orientation="Vertical" Width="20" Minimum="0" Maximum="100" Value="{Binding VisSource.LevelDbPercent}"></ProgressBar>
            <TextBlock Visibility="Collapsed" DockPanel.Dock="Bottom" Text="{Binding Path=LevelManager.LevelPercent, StringFormat={}{0:#}%}"/>
            <Slider 
            Orientation="Vertical"
            Minimum="0" 
            Maximum="100" 
            Value="{Binding LevelManager.LevelPercent, Mode=TwoWay}" 
            IsEnabled="{Binding LevelManager.IsAttached}" 
        />
        </DockPanel>
        <StackPanel>
            <ToggleButton
                MaxWidth="48"
                MaxHeight="48"
                Width="{Binding ElementName=modelValueContainer, Path=ActualHeight}" 
                Height="{Binding ElementName=modelValueContainer, Path=ActualHeight}" 
                ClickMode="Release" 
                IsChecked="{Binding Path=IsRecording, Mode=TwoWay}" 
                ToolTip="Enable sound recording">
                <ToggleButton.Template>
                    <ControlTemplate TargetType="{x:Type ToggleButton}">
                        <StackPanel Orientation="Horizontal">
                            <Image>
                                <Image.Style>
                                    <Style>
                                        <!--<Setter Property="Image.Source" Value="/FeenPhone;component/WPFApp/Resources/Images/audio-volume-muted.png" />-->
                                        <!--<Setter Property="Image.Source" Value="/FeenPhone;component/WPFApp/Resources/Images/black-mic-muted.png" />-->
                                        <!--<Setter Property="Image.Source" Value="/FeenPhone;component/WPFApp/Resources/Images/raphael_microphone_mute.png" />-->
                                        <Setter Property="Image.Source" Value="/FeenPhone;component/WPFApp/Resources/Images/AT2005-mic-muted.png" />
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding IsChecked,RelativeSource={RelativeSource AncestorType={x:Type ToggleButton}}}" Value="True">
                                                <!--<Setter Property="Image.Source" Value="/FeenPhone;component/WPFApp/Resources/Images/audio-volume-high.png" />-->
                                                <!--<Setter Property="Image.Source" Value="/FeenPhone;component/WPFApp/Resources/Images/black-mic.png" />-->
                                                <!--<Setter Property="Image.Source" Value="/FeenPhone;component/WPFApp/Resources/Images/raphael_microphone.png" />-->
                                                <Setter Property="Image.Source" Value="/FeenPhone;component/WPFApp/Resources/Images/AT2005-mic.png" />
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </Image.Style>
                            </Image>
                            <ContentPresenter Content="{TemplateBinding Content}" Margin="5,0,0,0" />
                        </StackPanel>
                    </ControlTemplate>
                </ToggleButton.Template>
            </ToggleButton>
        </StackPanel>
        <StackPanel Name="modelValueContainer" DockPanel.Dock="Right">
            <DockPanel>
                <ComboBox Name="comboInputGroups" 
                    Visibility="{Binding ShowAdvancedControls, Converter={StaticResource BoolToVisConverter}}"
                    DockPanel.Dock="left"
                    ItemsSource="{Binding Source={StaticResource InputsView}, Path=Groups}"
                    DisplayMemberPath="Name" />
                <Grid DockPanel.Dock="Right" Visibility="Collapsed">
                    <ToggleButton Width="16" 
                              IsChecked="{Binding UseWaveEvent}" 
                              Visibility="{Binding SelectedInputSource.IsWaveDevice, Converter={StaticResource BoolToVisConverter}}"
                              ToolTip="Use WaveEvent Capture">
                        <Image Height="16" Source="/FeenPhone;component/WPFApp/Resources/Images/Event.png"  />
                    </ToggleButton>
                </Grid>
                <ComboBox 
                    Loaded="comboInputs_Loaded"
                    ItemsSource="{Binding ElementName=comboInputGroups, Path=SelectedItem.Items}"
                    SelectedItem="{Binding Path=SelectedInputSource, Mode=TwoWay}" >
                    <ComboBox.GroupStyle>
                        <x:Static Member="GroupStyle.Default"/>
                    </ComboBox.GroupStyle>
                </ComboBox>
            </DockPanel>
            <DockPanel>
                <Label DockPanel.Dock="Left">Input Buffer</Label>
                <WrapPanel Height="20">
                    <TextBlock DockPanel.Dock="Left" Text="{Binding BufferTargetMs}" IsEnabled="{Binding ControlsEnabled}"/>
                    <TextBlock>ms</TextBlock>
                </WrapPanel>
                <Slider Height="20" ValueChanged="inBuffer_ValueChanged" TickFrequency="10" TickPlacement="TopLeft" LostMouseCapture="inBuffer_LostMouseCapture" Minimum="{Binding BufferMinMs}" Maximum="{Binding BufferMaxMs}" Value="{Binding BufferTargetMs}"/>
            </DockPanel>
            <DockPanel>
                <Label>CODEC:</Label>
                <ComboBox DockPanel.Dock="Top" Name="comboBoxCodecs" SelectedItem="{Binding SelectedCodec}" Visibility="{Binding ShowAdvancedControls, Converter={StaticResource BoolToVisConverter}}" SelectionChanged="comboBoxCodecs_SelectionChanged" />
                <TextBlock DockPanel.Dock="Top" Text="{Binding SelectedCodec}" Visibility="{Binding ShowAdvancedControls, Converter={StaticResource InverseBoolToVisConverter}}" />
            </DockPanel>
        </StackPanel>
    </DockPanel>
</UserControl>
