<Window x:Class="BodyshopPartner.Views.Main"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:p="clr-namespace:BodyshopPartner.Properties"
        xmlns:properties="clr-namespace:BodyshopPartner.Properties"
        xmlns:util="clr-namespace:BodyshopPartner.Utils"
        xmlns:vm="clr-namespace:BodyshopPartner.ViewModels"
        mc:Ignorable="d"
        Title="{x:Static p:Resources.Title_Main}"
        Height="600"
        Width="800"
        TextElement.Foreground="{DynamicResource MaterialDesignBody}"
        TextElement.FontWeight="Regular"
        TextElement.FontSize="13"
        TextOptions.TextFormattingMode="Ideal"
        TextOptions.TextRenderingMode="Auto"
        Background="{DynamicResource MaterialDesignPaper}"
        FontFamily="{DynamicResource MaterialDesignFont}"
        Loaded="Window_Loaded"
        Closing="Window_Closing"
    >
    <Window.DataContext>
        <vm:MainViewModel />
    </Window.DataContext>
    <Window.Resources>
        <util:OpenMainWindowCommand x:Key="OpenMainWindowCommand" />
        <util:MonitorStatusConverter x:Key="MonitorStatusConverter" />
        <util:BoolVisibilityConverter x:Key="BoolVisibilityConverter" />
        <Style TargetType="StackPanel">
            <Setter Property="Margin"
                    Value="8" />
        </Style>
        <Style TargetType="TextBox"
               BasedOn="{StaticResource MaterialDesignFloatingHintTextBox}">
            <Setter Property="Margin"
                    Value="8" />
        </Style>
        <Style TargetType="materialDesign:PackIcon">
            <Setter Property="Margin"
                    Value="8" />
        </Style>
        <Style TargetType="Image">
            <Setter Property="Margin"
                    Value="8" />
        </Style>
    </Window.Resources>

    <DockPanel>
        <ProgressBar DockPanel.Dock="Bottom"
                     Value="{Binding Progress}"
                     IsIndeterminate="{Binding IndeterminateLoading}"
                     Height="8" />

        <!--<tb:TaskbarIcon DockPanel.Dock="Top"
                        IconSource="../favicon.ico"
                        DoubleClickCommand="{StaticResource OpenMainWindowCommand}"
                        PopupActivation="LeftClick"
                        MenuActivation="RightClick"
                        ToolTipText="Bodyshop Uploader">
            <tb:TaskbarIcon.TrayPopup>
                <Border Background="{DynamicResource MaterialDesignPaper}"
                        BorderBrush="Black"
                        BorderThickness="2">
                    <DockPanel Margin="12">
                        <TextBlock DockPanel.Dock="Top"
                                   Style="{StaticResource MaterialDesignHeadline5TextBlock}"
                                   Text="{x:Static p:Resources.Label_MonitorStatus}" />
                        <ItemsControl ItemsSource="{Binding MonitoringPaths}">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <StackPanel>
                                        <Grid>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="*" />
                                                <ColumnDefinition Width="Auto" />
                                            </Grid.ColumnDefinitions>
                                            <TextBlock Grid.Column="0"
                                                       Style="{StaticResource MaterialDesignBody2TextBlock}"
                                                       Margin="8"
                                                       Text="{Binding FilePath}" />
                                            <TextBlock Grid.Column="1"
                                                       Style="{StaticResource MaterialDesignBody2TextBlock}"
                                                       Margin="8"
                                                       Text="{Binding FolderMonitor.EnableRaisingEvents,
                                        Converter={StaticResource MonitorStatusConverter}}" />
                                        </Grid>
                                        <Separator Margin="2"
                                                   Width="150" />
                                    </StackPanel>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                    </DockPanel>
                </Border>
            </tb:TaskbarIcon.TrayPopup>
            <tb:TaskbarIcon.ContextMenu>
                <ContextMenu>
                    <MenuItem Header="{x:Static p:Resources.Label_Restart}"
                              Command="{Binding StartFolderMonitorsCommand}" />
                    <MenuItem Header="{x:Static p:Resources.Label_StopAllMonitors}"
                              Command="{Binding StopFolderMonitorsCommand}" />
                    <MenuItem Header="Exit"
                              Command="{Binding QuitCommand}" />
                </ContextMenu>
            </tb:TaskbarIcon.ContextMenu>
        </tb:TaskbarIcon>-->

        <StackPanel DockPanel.Dock="Right">

            <ComboBox ItemsSource="{Binding ShopData}"
                      Margin="8"
                      SelectedItem="{Binding ActiveShop}"
                      Style="{StaticResource MaterialDesignFloatingHintComboBox}"
                      materialDesign:HintAssist.Hint="{x:Static p:Resources.Label_ActiveShop}"
                      DisplayMemberPath="ShopName">
                <ComboBox.ItemsPanel>
                    <ItemsPanelTemplate>
                        <VirtualizingStackPanel />
                    </ItemsPanelTemplate>
                </ComboBox.ItemsPanel>
            </ComboBox>
            <Separator />
            <CheckBox IsChecked="{Binding Source={x:Static p:Settings.Default}, Path=AutoStartMonitor}"
                      Margin="8"
                      Content="{x:Static p:Resources.Label_AutoStartMonitor}" />
            <Button Command="{Binding AddMonitoringPathCommand, UpdateSourceTrigger=PropertyChanged}"
                    Margin="8"
                    ToolTip="{x:Static p:Resources.Label_AddMonitoringPath}"
                    Content="{x:Static p:Resources.Label_AddFolder}" />
            <Button Command="{Binding StartFolderMonitorsCommand, UpdateSourceTrigger=PropertyChanged}"
                    Margin="8"
                    Content="{x:Static p:Resources.Label_StartAllMonitors}" />
            <Button Command="{Binding StopFolderMonitorsCommand, UpdateSourceTrigger=PropertyChanged}"
                    Margin="8"
                    Content="{x:Static p:Resources.Label_StopAllMonitors}" />

            <Button Command="{Binding StopFolderMonitorsCommand, UpdateSourceTrigger=PropertyChanged}"
                    Margin="8"
                    Content="{x:Static p:Resources.Label_StopAllMonitors}" />
            <Separator />
            <Button Command="{Binding BrowseForQbFolderCommand, UpdateSourceTrigger=PropertyChanged}"
                    Margin="8"
                    Content="{x:Static p:Resources.Label_BrowseForQb}" />
            <Separator />
            <Button DockPanel.Dock="Top"
                    Margin="8"
                    Command="{Binding TestCommand}"
                    Background="Tomato"
                    Content="_TEST COMMAND" />
            <Label DockPanel.Dock="Top"
                   Margin="8"
                   Content="{Binding AppVersion}" />
            <StackPanel Visibility="{Binding UpdateAvailable, Converter={StaticResource BoolVisibilityConverter}}">
                <Button Content="Update" Command="{Binding InstallUpdatesCommand}" />
                <ProgressBar Margin="8" Value="{Binding UpdateProgress}"/>
            </StackPanel>
        </StackPanel>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <DataGrid Grid.Row="0"
                      ItemsSource="{Binding MonitoringPaths}"
                      AutoGenerateColumns="False"
                      VerticalContentAlignment="Center"
                      IsReadOnly="True"
                      HorizontalContentAlignment="Center"
                      Margin="8"
                      CanUserAddRows="False"
                      CanUserSortColumns="True"
                      materialDesign:DataGridAssist.CellPadding="4 2 2 2"
                      materialDesign:DataGridAssist.ColumnHeaderPadding="4 2 2 2">
                <DataGrid.Columns>
                    <DataGridTextColumn Binding="{Binding FilePath}"
                                        Header="{x:Static p:Resources.Label_FilePath}" />
                    <!--<DataGridTextColumn Binding="{Binding Source}"
                                    Header="{x:Static p:Resources.Label_SourceSystem}" />

                <DataGridTemplateColumn Header="{x:Static p:Resources.Label_SourceSystem}">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <ComboBox Margin="8"
                                      SelectedItem="{Binding Source}">
                                <ComboBox.ItemsPanel>
                                    <ItemsPanelTemplate>
                                        <VirtualizingStackPanel />
                                    </ItemsPanelTemplate>
                                </ComboBox.ItemsPanel>
                                <ComboBoxItem>Mitchell</ComboBoxItem>
                                <ComboBoxItem>Audatex</ComboBoxItem>
                                <ComboBoxItem>CCC</ComboBoxItem>
                            </ComboBox>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>-->

                    <DataGridTextColumn Binding="{Binding FolderMonitor.EnableRaisingEvents, Converter={StaticResource MonitorStatusConverter}}"
                                        Header="{x:Static p:Resources.Label_Status}" />
                    <DataGridTemplateColumn Header="{x:Static p:Resources.Label_Actions}">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <Button Command="{Binding DataContext.RemoveMonitoringPathCommand,
                                        RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"
                                            CommandParameter="{Binding .}"
                                            Style="{StaticResource MaterialDesignOutlinedButton}"
                                            Margin="4"
                                            Content="{x:Static p:Resources.Label_Remove}" />
                                    <Button Command="{Binding DataContext.RestartMonitoringPathCommand,
                                        RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"
                                            CommandParameter="{Binding .}"
                                            Style="{StaticResource MaterialDesignOutlinedButton}"
                                            Margin="4"
                                            Content="{x:Static p:Resources.Label_Restart}" />
                                </StackPanel>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                </DataGrid.Columns>
            </DataGrid>
            <DockPanel Grid.Row="1"
                       Height="Auto">
                <TextBox DockPanel.Dock="Top"
                         Text="{Binding Source={x:Static properties:Settings.Default},
                               Path=QuickBooksFilePath}"
                         materialDesign:HintAssist.Hint="{x:Static p:Resources.Label_QbFilePath}"
                         TextChanged="TextBox_TextChanged" />
                <TextBox Height="Auto"
                         materialDesign:HintAssist.Hint="{x:Static p:Resources.Label_InteractionLog}"
                         Text="{Binding HttpServerLog}"
                         TextWrapping="Wrap"
                         IsReadOnly="True"
                         AcceptsReturn="True" />
            </DockPanel>

        </Grid>

    </DockPanel>
</Window>
