<Window x:Class="ReAct_PME.ListeEmails"
        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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:ReAct_PME"
        mc:Ignorable="d"
        Title="Catégorisation des Emails non lus" Height="650" MinHeight="650" MinWidth="1280" Width="1280" Background="#FFF0F0F0" Closing="Window_Closing">

    <Window.Resources>
        <Style TargetType="TextBlock">
            <Setter Property="FontSize" Value="10"/>
            <Setter Property="Padding" Value="0"/>
            <Setter Property="Margin" Value="0"/>
        </Style>
        <!-- Style pour changer la couleur des en-têtes -->
        <Style x:Key="DefaultColumnHeaderStyle" TargetType="{x:Type GridViewColumnHeader}">
            <Setter Property="Background" Value="LightGray" />
            <Setter Property="Foreground" Value="Black" />
            <Setter Property="FontWeight" Value="Bold" />
            <Setter Property="HorizontalContentAlignment" Value="Center" />
            <Setter Property="VerticalContentAlignment" Value="Center" />
        </Style>
        <!-- Style pour la colonne cliquée -->
        <Style x:Key="ClickedColumnHeaderStyle" TargetType="{x:Type GridViewColumnHeader}">
            <Setter Property="Background" Value="LightBlue" />
            <Setter Property="Foreground" Value="Black" />
            <Setter Property="FontWeight" Value="Bold" />
            <Setter Property="HorizontalContentAlignment" Value="Center" />
            <Setter Property="VerticalContentAlignment" Value="Center" />
        </Style>
        <!-- Converter -->
        <local:NullToBoolConverter x:Key="NullToBoolConverter"/>
        <!-- Style pour le ToastNotifier -->
        <DropShadowEffect x:Key="ShadowEffect"
                  BlurRadius="8"
                  ShadowDepth="2"
                  Opacity="0.4"
                  Direction="270"/>
    </Window.Resources>

    <Grid>
        <Popup x:Name="ToastPopup"
               Placement="Bottom"
               PlacementTarget="{Binding ElementName=MainGrid}" 
               StaysOpen="False"
               AllowsTransparency="True"
               PopupAnimation="Fade"
               HorizontalOffset="0"
               VerticalOffset="-30">

            <Border Background="#FF323232"
                    CornerRadius="8"
                    Padding="16"
                    Margin="10"
                    Effect="{DynamicResource ShadowEffect}">
                <TextBlock x:Name="ToastMessage"
                           Foreground="White"
                           FontWeight="Bold"
                           FontSize="14"
                           TextWrapping="Wrap"
                           MaxWidth="300"/>
            </Border>
        </Popup>

        <Label Content="{Binding MessageEnteteTotal}" FontWeight="Bold" Width="50" Height="30" Margin="45,10,0,0" HorizontalAlignment="Left"  VerticalAlignment="Top" />
        <Label Content="{Binding MessageEnteteImportant}" FontWeight="Bold" Width="50" Height="30" Margin="225,10,0,0" HorizontalAlignment="Left"  VerticalAlignment="Top" />
        <Label Content="{Binding MessageEnteteUrgent}" FontWeight="Bold" Width="50" Height="30" Margin="375,10,0,0" HorizontalAlignment="Left"  VerticalAlignment="Top" />
        <Label Content="{Binding MessageEnteteImportantEtUrgent}" FontWeight="Bold" Width="50" HorizontalAlignment="Left" Height="26" Margin="593,12,0,0" VerticalAlignment="Top"/>


        <Image Source="/IMG/NON_LU.png" Width="30" Height="30" Margin="10,10,0,0" HorizontalAlignment="Left"  VerticalAlignment="Top" ToolTip="{Binding MessageEntete}" />
        <Image Source="/IMG/IMPORTANT.png" Width="60" Height="30" Margin="160,10,0,0" HorizontalAlignment="Left"  VerticalAlignment="Top" ToolTip="{Binding MessageEntete}"/>
        <Image Source="/IMG/URGENT.png" Width="30" Height="30" Margin="340,10,0,0" HorizontalAlignment="Left"  VerticalAlignment="Top" ToolTip="{Binding MessageEntete}" RenderTransformOrigin="0.927,0.515"/>
        <Image Source="/IMG/IMPORTANT_URGENT.png" Width="98" Height="30" Margin="490,11,0,0" HorizontalAlignment="Left"  VerticalAlignment="Top" ToolTip="{Binding MessageEntete}"/>

        <CheckBox Content="Uniquement les Emails importants ?" IsChecked="{Binding IsOnlyImportants, Mode=TwoWay}" HorizontalAlignment="Left" Margin="650,16,0,0" VerticalAlignment="Top" ToolTip="Permet d'afficher uniquement les emails importants" />
        <CheckBox Content="Uniquement les Emails urgents ?" IsChecked="{Binding IsOnlyUrgents, Mode=TwoWay}" HorizontalAlignment="Left" Margin="900,16,0,0" VerticalAlignment="Top" ToolTip="Permet d'afficher uniquement les emails urgents" />

        <ListView Name="ItemsGrid"
                  AlternationCount="2" Style="{DynamicResource ListViewStyle}" ItemContainerStyle="{DynamicResource AlternatingListViewItemStyle}"
                  IsSynchronizedWithCurrentItem="false" local:GridViewSort.AutoSort="True"
                  ItemsSource="{Binding ListeItems}" SelectedItem="{Binding SelectedItem}" Margin="0,49,0,50">
            <ListView.View>
                <GridView>
                    <GridViewColumn DisplayMemberBinding="{Binding DateSTR}" Width="120" local:GridViewSort.PropertyName="Date">
                        <GridViewColumnHeader Content="Date" Click="ColumnHeader_Click" Style="{DynamicResource DefaultColumnHeaderStyle}"/>
                    </GridViewColumn>

                    <GridViewColumn Width="170" local:GridViewSort.PropertyName="From">
                        <GridViewColumnHeader Content="From" Click="ColumnHeader_Click" Style="{DynamicResource DefaultColumnHeaderStyle}"/>
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding FromName}" 
                                       TextTrimming="CharacterEllipsis" 
                                       VerticalAlignment="Center" 
                                       FontSize="10"
                                       Padding="0" ToolTip="{Binding From}" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>


                    <GridViewColumn Width="30" local:GridViewSort.PropertyName="To">
                        <GridViewColumnHeader Content="To" Click="ColumnHeader_Click" Style="{DynamicResource DefaultColumnHeaderStyle}"/>
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding IsDestinatairePrincipal_STR}" 
                                       TextTrimming="CharacterEllipsis" 
                                       VerticalAlignment="Center" 
                                       FontSize="10"
                                       Padding="0" ToolTip="{Binding IsDestinatairePrincipal_STR_TXT}" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>

                    
                    <GridViewColumn Width="200" local:GridViewSort.PropertyName="Subject">
                        <GridViewColumnHeader Content="Subject" Click="ColumnHeader_Click" Style="{DynamicResource DefaultColumnHeaderStyle}"/>
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding Subject}" 
                                       TextTrimming="CharacterEllipsis" 
                                       VerticalAlignment="Center" 
                                       FontSize="10"
                                       Padding="0" ToolTip="{Binding Subject}" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>

                    <GridViewColumn Width="150" local:GridViewSort.PropertyName="Preview">
                        <GridViewColumnHeader Content="Preview" Click="ColumnHeader_Click" Style="{DynamicResource DefaultColumnHeaderStyle}"/>
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding Preview}" 
                                       TextTrimming="CharacterEllipsis" 
                                       VerticalAlignment="Center" 
                                       FontSize="8"
                                       Padding="0" ToolTip="{Binding Preview}" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <!--
                    <GridViewColumn Width="100" local:GridViewSort.PropertyName="Resume">
                        <GridViewColumnHeader Content="Resume" Click="ColumnHeader_Click" Style="{DynamicResource DefaultColumnHeaderStyle}"/>
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding Resume}" 
                                       TextTrimming="CharacterEllipsis" 
                                       VerticalAlignment="Center" 
                                       FontSize="8"
                                       Padding="0" ToolTip="{Binding Resume}" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    -->
                    <GridViewColumn Width="150" local:GridViewSort.PropertyName="Categorie">
                        <GridViewColumnHeader Content="Categorie" Click="ColumnHeader_Click" Style="{DynamicResource DefaultColumnHeaderStyle}"/>
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding Categorie}" 
                                       TextTrimming="CharacterEllipsis" 
                                       VerticalAlignment="Center" 
                                       FontSize="8"
                                       Padding="0" ToolTip="{Binding Categorie}" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>

                    <GridViewColumn Width="100" local:GridViewSort.PropertyName="Analyse">
                        <GridViewColumnHeader Content="Analyse" Click="ColumnHeader_Click" Style="{DynamicResource DefaultColumnHeaderStyle}"/>
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding Analyse}" 
                                       TextTrimming="CharacterEllipsis" 
                                       VerticalAlignment="Center" 
                                       FontSize="8"
                                       Padding="0" ToolTip="{Binding Analyse}" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>

                    <GridViewColumn Width="80" local:GridViewSort.PropertyName="ImportanceSTR">
                        <GridViewColumnHeader Content="Importance" Click="ColumnHeader_Click" Style="{DynamicResource DefaultColumnHeaderStyle}"/>
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding ImportanceSTR}" 
                                        FontSize="8"
                                        Padding="0"
                                        HorizontalAlignment="Center" 
                                        VerticalAlignment="Center" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>

                    <GridViewColumn Width="60" local:GridViewSort.PropertyName="UrgenceSTR">
                        <GridViewColumnHeader Content="Urgence" Click="ColumnHeader_Click" Style="{DynamicResource DefaultColumnHeaderStyle}"/>
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding UrgenceSTR}" 
                                        FontSize="8"
                                        Padding="0"
                                        HorizontalAlignment="Center" 
                                        VerticalAlignment="Center" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>

                    <GridViewColumn Width="40" local:GridViewSort.PropertyName="PJ_NBR">
                        <GridViewColumnHeader Content="PJ ?" Click="ColumnHeader_Click" Style="{DynamicResource DefaultColumnHeaderStyle}"/>
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding PJ_NBR}" 
                                        FontSize="8"
                                        Padding="0"
                                        HorizontalAlignment="Center" 
                                        VerticalAlignment="Center"
                                        ToolTip="{Binding ContentPJ_STR}"/>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>

                    <GridViewColumn Width="80" local:GridViewSort.PropertyName="PresenceSuspecte_STR">
                        <GridViewColumnHeader Content="Suspect ?" Click="ColumnHeader_Click" Style="{DynamicResource DefaultColumnHeaderStyle}"/>
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding PresenceSuspecte_STR}" 
                                        FontSize="12"
                                        Padding="0"
                                        HorizontalAlignment="Center" 
                                        VerticalAlignment="Center"
                                        ToolTip="{Binding Resume}"/>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>

                    <GridViewColumn Width="70">
                        <GridViewColumnHeader  Content="Actions"  Style="{DynamicResource DefaultColumnHeaderStyle}" Click="ColumnHeader_Click" />
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" >
                                    <Button Click="BtnShowDetail_Click" Style="{DynamicResource ButtonStyle}" Width="40" FontFamily="Segoe MDL2 Assets" Background="GreenYellow" Margin="5,0,0,0"
                                        ToolTip="Afficher le détail du mail">
                                        &#xE8CA;
                                    </Button>
                                </StackPanel>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    
                </GridView>
            </ListView.View>
        </ListView>

        <TextBox Text="{Binding RechercheString}" Width="500"  HorizontalAlignment="Left" Height="24" VerticalAlignment="Bottom" Margin="10,10,10,10"/>
        <Button Content="Rechercher" Style="{DynamicResource ButtonStyle}" Width="100"  HorizontalAlignment="Left" Height="24" VerticalAlignment="Bottom" Margin="515,0,0,10" Click="Button_Click_2" ToolTip="Saisir une recherche"/>

        <Button x:Name="BtnRefresh" Content="Rechercher nouveaux emails" Width="170"  HorizontalAlignment="Right" Height="24" VerticalAlignment="Bottom" Style="{DynamicResource ButtonStyle}" Margin="0,0,125,10" Click="Button_Click_1" ToolTip="La recherche se fait automatiquement toutes les x minutes (voir les Paramètres Mails)"/>
        <Button Content="Voir le Détail" Width="120" Click="Button_Click" HorizontalAlignment="Right" Height="24" VerticalAlignment="Bottom" Style="{DynamicResource ButtonStyle}" Margin="0,0,260,10" Visibility="Collapsed"/>
        <Button x:Name="BtnFermer" Content="Fermer" Width="100"  HorizontalAlignment="Right" Height="24" VerticalAlignment="Bottom" Style="{DynamicResource ButtonStyle}" Margin="0,0,10,10" Click="Fermer_Click" ToolTip="Fermer la fenêtre"/>

    </Grid>
</Window>
