<Window
    x:Class="DMS.WPF.Views.MainView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:hc="https://handyorg.github.io/handycontrol"
    xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
    xmlns:local="clr-namespace:DMS.WPF.Views"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:mo="clr-namespace:DMS.Core.Models;assembly=DMS.Core"
    xmlns:taskbarNotification="http://www.hardcodet.net/taskbar"
    xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
    xmlns:vm="clr-namespace:DMS.WPF.ViewModels"
    Title="设备管理系统"
    Width="1080"
    Height="800"
    d:DataContext="{d:DesignInstance vm:MainViewModel}"
    ui:WindowHelper.SystemBackdropType="Mica"
    ui:WindowHelper.UseModernWindowStyle="True"
    Closing="Window_Closing"
    Loaded="MainView_OnLoaded"
    WindowStartupLocation="CenterScreen"
    WindowState="Maximized"
    mc:Ignorable="d">
    <Window.Resources>

        <ContextMenu x:Key="MyMenuItemContextMenu">
            <MenuItem Header="添加" />
            <MenuItem Header="编辑" />
            <Separator />
            <MenuItem Header="删除" />
        </ContextMenu>
        <DataTemplate x:Key="NavigationViewMenuItem" DataType="{x:Type mo:MenuBean}">
            <ui:NavigationViewItem
                Content="{Binding Header}"
                MenuItemsSource="{Binding Children}"
                Tag="{Binding}">
                <ui:NavigationViewItem.Icon>
                    <ui:FontIcon Glyph="{Binding Icon}" />
                </ui:NavigationViewItem.Icon>
            </ui:NavigationViewItem>
        </DataTemplate>
    </Window.Resources>
    <Grid>
        <taskbarNotification:TaskbarIcon
            x:Name="MyNotifyIcon"
            DoubleClickCommand="{Binding ShowWindowCommand}"
            IconSource="/Assets/AppIcon2.ico"
            ToolTipText="设备管理系统">
            <taskbarNotification:TaskbarIcon.ContextMenu>
                <ContextMenu>
                    <MenuItem x:Name="ShowWindowMenuItem" Header="显示窗口" />
                    <MenuItem x:Name="ExitApplicationMenuItem" Header="退出" />
                </ContextMenu>
            </taskbarNotification:TaskbarIcon.ContextMenu>
        </taskbarNotification:TaskbarIcon>
        <ui:NavigationView
            AlwaysShowHeader="True"
            ExpandedModeThresholdWidth="200"
            IsBackButtonVisible="Collapsed"
            IsBackEnabled="False"
            IsSettingsVisible="False"
            IsTabStop="False"
            MenuItemTemplate="{StaticResource NavigationViewMenuItem}"
            MenuItemsSource="{Binding MenuTrees}"
            PaneDisplayMode="Left"
            PaneTitle="设备管理系统"
            SelectionChanged="NavigationView_SelectionChanged"
            SelectionFollowsFocus="Disabled">



            <ui:NavigationView.AutoSuggestBox>
                <ui:AutoSuggestBox AutomationProperties.Name="Search">
                    <ui:AutoSuggestBox.QueryIcon>
                        <ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Search}" />
                    </ui:AutoSuggestBox.QueryIcon>
                </ui:AutoSuggestBox>
            </ui:NavigationView.AutoSuggestBox>


            <Grid>
                <!--  数据模版绑定不同的View显示  -->
                <ContentControl Content="{Binding CurrentViewModel}">
                    <ContentControl.Resources>
                        <!--  主页  -->
                        <DataTemplate DataType="{x:Type vm:HomeViewModel}">
                            <local:HomeView />
                        </DataTemplate>
                        <!--  设备列表页  -->
                        <DataTemplate DataType="{x:Type vm:DevicesViewModel}">
                            <local:DevicesView />
                        </DataTemplate>
                        <!--  数据转换页  -->
                        <DataTemplate DataType="{x:Type vm:DataTransformViewModel}">
                            <local:DataTransformView />
                        </DataTemplate>
                        <!--  Mqtt服务器页  -->
                        <DataTemplate DataType="{x:Type vm:MqttsViewModel}">
                            <local:MqttsView />
                        </DataTemplate>
                        <!--  设置页  -->
                        <DataTemplate DataType="{x:Type vm:SettingViewModel}">
                            <local:SettingView />
                        </DataTemplate>
                        <!--  日志历史页  -->
                        <DataTemplate DataType="{x:Type vm:LogHistoryViewModel}">
                            <local:LogHistoryView />
                        </DataTemplate>
                        <!--  邮件管理页  -->
                        <DataTemplate DataType="{x:Type vm:EmailManagementViewModel}">
                            <local:EmailManagementView />
                        </DataTemplate>
                        <!--  触发器管理页  -->
                        <DataTemplate DataType="{x:Type vm:TriggersViewModel}">
                            <local:TriggersView/>
                        </DataTemplate>
                        <!--  设备详情页  -->
                        <DataTemplate DataType="{x:Type vm:DeviceDetailViewModel}">
                            <local:DeviceDetailView />
                        </DataTemplate>
                        <!--  设备变量页  -->
                        <DataTemplate DataType="{x:Type vm:VariableTableViewModel}">
                            <local:VariableTableView DataContext="{Binding}" />
                        </DataTemplate>
                        <!--  设备变量历史记录页  -->
                        <DataTemplate DataType="{x:Type vm:VariableHistoryViewModel}">
                            <local:VariableHistoryView DataContext="{Binding}" />
                        </DataTemplate>
                        <!--  Mqtt服务器详情页  -->
                        <!-- <DataTemplate DataType="{x:Type vm:MqttServerDetailViewModel}"> -->
                        <!--     <local:MqttServerDetailView DataContext="{Binding }"/> -->
                        <!-- </DataTemplate> -->
                    </ContentControl.Resources>
                </ContentControl>

                <ScrollViewer HorizontalAlignment="Right" VerticalScrollBarVisibility="Hidden">
                    <StackPanel
                        Margin="0,10,10,10"
                        VerticalAlignment="Top"
                        hc:Growl.GrowlParent="True" />
                </ScrollViewer>
            </Grid>

        </ui:NavigationView>
    </Grid>
</Window>