<UserControl x:Class="HistoryView.Views.Regions.Monitor"
             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:local="clr-namespace:HistoryView.Views.Regions"
             mc:Ignorable="d" 
             xmlns:prism="http://prismlibrary.com/"
             xmlns:controls="clr-namespace:HistoryView.Controls"
             xmlns:convert="clr-namespace:HistoryView.Converters"
             xmlns:resource="clr-namespace:HistoryView.Resources"
             prism:ViewModelLocator.AutoWireViewModel="True"
             d:DesignHeight="450" d:DesignWidth="800">
    <UserControl.Resources>
        <convert:Mini8StatusToBrush x:Key="Mini8Brush"/>
        <convert:Mini8StatusToBrushMulti x:Key="Mini8Multi"/>
    </UserControl.Resources>

    <Border Background="{StaticResource BackgroundDarkColor}">
        <Border.Effect>
            <DropShadowEffect BlurRadius="20" Color="Black" Opacity="0.6"  ShadowDepth="5"/>
        </Border.Effect>
        <Border Margin="4" Background="{StaticResource BackgroundColor}">
            <Grid Margin="0,2,0,0">
                <Grid.RowDefinitions>
                    <RowDefinition Height="auto"/>
                    <RowDefinition />
                </Grid.RowDefinitions>
                <Expander x:Name="Filter" Panel.ZIndex="1" Margin="16,0" Background="{StaticResource BackgroundColor}" FlowDirection="LeftToRight" Style="{StaticResource ExpanderStyle1}">
                    <Expander.Header>
                        <Border Background="{StaticResource LightThemeColor}" Margin="4,0" CornerRadius="4" >
                            <TextBlock FontSize="14" FontWeight="Bold" Margin="6,2" Text="{DynamicResource DisplaySetting}"/>
                        </Border>
                    </Expander.Header>
                    <Border BorderBrush="{StaticResource DarkBorderColor}" BorderThickness="1">

                        <Grid  Margin="8" >
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="8"/>
                                <ColumnDefinition Width="auto" MinWidth="160"/>
                                <ColumnDefinition Width="8"/>
                                <ColumnDefinition Width="auto" MinWidth="160"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="auto"/>
                                <RowDefinition Height="4"/>
                                <RowDefinition Height="auto"/>
                                <RowDefinition Height="4"/>
                            </Grid.RowDefinitions>

                            <TextBlock FontSize="14" FontWeight="Bold" Margin="4" Text="{DynamicResource Mini8Select}"/>
                            <Border Grid.Row="2" BorderBrush="{StaticResource DarkBorderColor}" BorderThickness="1" >
                                <ItemsControl ItemsSource="{Binding Mini8DisplayStatus}" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="8">
                                    <ItemsControl.ItemTemplate>
                                        <DataTemplate>
                                            <CheckBox Style="{StaticResource ThemeCheckBox}" Margin="2" IsChecked="{Binding Value.IsDisplay}"
                                              Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:Monitor}, Path=DataContext.DisplayCommand}"
                                              CommandParameter="{Binding}" VerticalAlignment="Center" HorizontalAlignment="Center">
                                                <TextBlock Text="{Binding Key.Name}" />
                                                <CheckBox.Background>
                                                    <MultiBinding Converter="{StaticResource Mini8Multi}" ConverterParameter="Bright">
                                                        <Binding Path="Key.Status"/>
                                                        <Binding Path="Key.IsConnected"/>
                                                    </MultiBinding>
                                                </CheckBox.Background>
                                            </CheckBox>
                                        </DataTemplate>
                                    </ItemsControl.ItemTemplate>
                                    <ItemsControl.ItemsPanel>
                                        <ItemsPanelTemplate>
                                            <UniformGrid Rows="2"/>
                                        </ItemsPanelTemplate>
                                    </ItemsControl.ItemsPanel>
                                </ItemsControl>
                            </Border>

                            <TextBlock Grid.Row="0" Grid.Column="2" FontSize="14" FontWeight="Bold" Margin="4" Text="{DynamicResource DisplayMode}"/>
                            <Border Grid.Row="2" Grid.Column="2" BorderBrush="{StaticResource DarkBorderColor}" BorderThickness="1">
                                <Grid Margin="8" VerticalAlignment="Center">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="auto"/>
                                        <RowDefinition Height="8"/>
                                        <RowDefinition Height="auto"/>
                                        <RowDefinition Height="8"/>
                                        <RowDefinition Height="auto"/>
                                    </Grid.RowDefinitions>
                                    <Button Grid.Row="0" Height="28" Style="{StaticResource FunctionButton}" Command="{Binding DisplayAllCommand}" CommandParameter="All" Content="{DynamicResource DisplayModeAll}"/>
                                    <Button Grid.Row="2" Height="28" Style="{StaticResource FunctionButton}" Command="{Binding DisplayAllCommand}" CommandParameter="Enable" Content="{DynamicResource DisplayModeEnable}"/>
                                    <Button Grid.Row="4" Height="28" Style="{StaticResource FunctionButton}" Command="{Binding DisplayAllCommand}" CommandParameter="Alarm" Content="{DynamicResource DisplayModeError}"/>
                                </Grid>
                            </Border>

                            <TextBlock Grid.Column="4" Grid.Row="0" FontSize="14" FontWeight="Bold" Margin="4" Text="{DynamicResource DisplayChannelMode}"/>
                            <Border  Grid.Column="4" Grid.Row="2"  BorderBrush="{StaticResource DarkBorderColor}" BorderThickness="1">
                                <Grid Margin="8" VerticalAlignment="Center">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="auto"/>
                                        <RowDefinition Height="8"/>
                                        <RowDefinition Height="auto"/>
                                        <RowDefinition Height="8"/>
                                        <RowDefinition Height="auto"/>
                                    </Grid.RowDefinitions>
                                    <Button Grid.Row="0" Height="28" Style="{StaticResource FunctionButton}" Command="{Binding ChannelDisplayCommand}" CommandParameter="1" Content="{DynamicResource DisplayChannelModeSingle}"/>
                                    <Button Grid.Row="2" Height="28" Style="{StaticResource FunctionButton}" Command="{Binding ChannelDisplayCommand}" CommandParameter="2" Content="{DynamicResource DisplayChannelDouble}"/>
                                    <Button Grid.Row="4" Height="28" Style="{StaticResource FunctionButton}" Command="{Binding ChannelDisplayCommand}" CommandParameter="4" Content="{DynamicResource DisplayChannelQuad}"/>
                                </Grid>
                            </Border>
                        </Grid>
                    </Border>
                </Expander>

                <Border Background="{StaticResource BackgroundColor}" GotFocus="Filter_LostFocus" Margin="0,24,0,0"  Grid.Row="0" Grid.RowSpan="3">
                    <resource:TouchableScrollViewer VerticalScrollBarVisibility="Hidden">

                        <ItemsControl ItemsSource="{Binding DisplayMini8}">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <controls:StatusPlot DataSource="{Binding Key}" Channels="{Binding Value}" Margin="4,4" 
                                                        Rows="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:Monitor}, Path=DataContext.Rows}"
                                                        EditChannel="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:Monitor}, Path=DataContext.EditChannelCommand}" 
                                                        TraceLogCommand="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:Monitor}, Path=DataContext.TraceLogCommand}"
                                                        MultiTraceCommand="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:Monitor}, Path=DataContext.ViewMultiTraceCommand}"
                                                        Reconnect="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:Monitor}, Path=DataContext.ReconnectCommand}" 
                                                        MultiSelectCommand="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:Monitor}, Path=DataContext.MultiSelectCommand}"
                                                        User="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:Monitor}, Path=DataContext.User}"
                                                        ReconnectParameter="{Binding Key}"/>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                            <ItemsControl.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <WrapPanel VerticalAlignment="Top" HorizontalAlignment="Center"/>
                                </ItemsPanelTemplate>
                            </ItemsControl.ItemsPanel>
                        </ItemsControl>

                    </resource:TouchableScrollViewer>
                </Border>

            </Grid>
        </Border>
    </Border>
</UserControl>
