<UserControl x:Class="dvmconsole.Controls.ChannelBox"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             Width="220" Height="100">
    <UserControl.Effect>
        <DropShadowEffect ShadowDepth="1" BlurRadius="16" Color="#FF686767" Opacity="0.3" />
    </UserControl.Effect>
    <!-- Border wraps the entire Grid -->
    <Border x:Name="ControlBorder" BorderBrush="LightGray" BorderThickness="1,1,1,1" CornerRadius="8">
        <Grid Margin="5">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="41"/>
                <ColumnDefinition/>
                <ColumnDefinition Width="30"/>
            </Grid.ColumnDefinitions>

            <Grid.RowDefinitions>
                <RowDefinition Height="2*"/>
                <RowDefinition Height="51*"/>
                <RowDefinition Height="32.25"/>
                <RowDefinition Height="7.75"/>
            </Grid.RowDefinitions>

            <!-- Left Side PTT Button -->

            <!-- Main Info Section -->
            <Rectangle Grid.ColumnSpan="2" HorizontalAlignment="Left" Height="40" Margin="1,0,0,0" 
                Grid.RowSpan="2" Grid.Row="2" VerticalAlignment="Top" 
                Width="116" StrokeThickness="0"
                RadiusX="2" RadiusY="2">
                <Rectangle.Fill>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                        <GradientStop Color="#FFF0F0F0" Offset="0.485"/>
                        <GradientStop Color="Gainsboro" Offset="0.517"/>
                    </LinearGradientBrush>
                </Rectangle.Fill>
            </Rectangle>

            <!-- Main Info Section -->
            <StackPanel Grid.Column="1" HorizontalAlignment="Left" Width="119" Margin="48,0,0,1" Grid.RowSpan="2" Grid.ColumnSpan="2">
                <TextBlock Text="{Binding ChannelName}" FontWeight="Bold" Foreground="White" FontSize="12"/>
                <TextBlock Text="{Binding LastSrcId}" Foreground="Gold" FontSize="10"/>
                <TextBlock Text="{Binding SystemName}" Foreground="Gold" FontSize="10"/>
            </StackPanel>

            <!-- Volume Meter -->
            <ProgressBar x:Name="VolumeMeter" HorizontalAlignment="Center" Width="16" Margin="0,1,0,5" Grid.RowSpan="2" Orientation="Vertical" Maximum="50" 
                         BorderThickness="0" Background="#FFF0F0F0">
                <ProgressBar.Foreground>
                    <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
                        <GradientStop Color="#F0C60000" Offset="1"/>
                        <GradientStop Color="#F0C68700" Offset="0.9"/>
                        <GradientStop Color="#F0008E00" Offset="0"/>
                    </LinearGradientBrush>
                </ProgressBar.Foreground>
            </ProgressBar>

            <!-- PTT Button -->
            <Button x:Name="PttButton" HorizontalAlignment="Left" Width="42" Margin="41,1,0,4" Grid.ColumnSpan="2" BorderThickness="0,0,0,0" BorderBrush="#FFC1C1C1" UseLayoutRounding="False" Grid.RowSpan="2" Background="#FFEEA400"
                    ToolTip="Push To Talk">
                <Button.Resources>
                    <Style TargetType="{x:Type Border}">
                        <Setter Property="CornerRadius" Value="2"/>
                    </Style>
                </Button.Resources>
                <Image Source="/dvmconsole;component/Assets/instantptt.png" Width="39" Height="40" Stretch="Fill" Margin="0,0,0,1"/>
            </Button>

            <!-- Volume Slider -->
            <Slider Minimum="0" Maximum="4" Value="{Binding Volume, Mode=TwoWay}" 
                Height="21" VerticalAlignment="Top" x:Name="VolumeSlider" 
                ValueChanged="VolumeSlider_ValueChanged" Margin="11,10,65,0" 
                Grid.ColumnSpan="2" Grid.Row="2" ToolTip="Channel Volume">
                <Slider.Style>
                    <Style TargetType="Slider">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="Slider">
                                    <Grid>
                                        <!-- Background Track -->
                                        <Rectangle Name="PART_TrackBackground" Height="4" Fill="Gray" 
                                       VerticalAlignment="Center" Margin="4"/>

                                        <!-- Track with Functional Movement -->
                                        <Track Name="PART_Track" VerticalAlignment="Center">
                                            <Track.DecreaseRepeatButton>
                                                <!-- Make the left-side button invisible -->
                                                <RepeatButton Width="0" Background="Transparent" BorderThickness="0"/>
                                            </Track.DecreaseRepeatButton>
                                            <Track.IncreaseRepeatButton>
                                                <!-- Make the right-side button invisible -->
                                                <RepeatButton Width="0" Background="Transparent" BorderThickness="0"/>
                                            </Track.IncreaseRepeatButton>
                                            <Track.Thumb>
                                                <Thumb Name="PART_Thumb" Width="10" Height="20" Background="DarkGray"/>
                                            </Track.Thumb>
                                        </Track>
                                    </Grid>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </Slider.Style>
            </Slider>

            <!-- Bottom Buttons -->
            <StackPanel Grid.Column="1" Grid.Row="2" Orientation="Horizontal" Margin="81,0,-2,0" Grid.RowSpan="2" Grid.ColumnSpan="2">
                <Button Width="40" Height="40" x:Name="PageSelectButton" Click="PageSelectButton_Click" BorderThickness="0,0,0,0"
                        ToolTip="Channel Alert">
                    <Button.Resources>
                        <Style TargetType="{x:Type Border}">
                            <Setter Property="CornerRadius" Value="2"/>
                        </Style>
                    </Button.Resources>
                    <Image Source="/dvmconsole;component/Assets/pageselect.png" Width="39" Height="39" Margin="1.5,2,0,0"/>
                </Button>
                <Button Width="40" Height="40" x:Name="ChannelMarkerBtn" Click="ChannelMarkerBtn_Click" BorderThickness="0,0,0,0" Margin="5,0,0,0"
                        ToolTip="Channel Marker">
                    <Button.Resources>
                        <Style TargetType="{x:Type Border}">
                            <Setter Property="CornerRadius" Value="2"/>
                        </Style>
                    </Button.Resources>
                    <Image Source="/dvmconsole;component/Assets/channelmarker.png" Width="36" Height="40"/>
                </Button>
            </StackPanel>
        </Grid>
    </Border>
</UserControl>
