<Window x:Class="ReAct_PME.ListeEmailsSend"
        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="Mails : suivi des points importants et des relances" Height="600" Width="1220" 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"/>
        <local:BoolToStatusConverter x:Key="BoolToStatusConverter"/>
        <!-- Style pour le ToastNotifier -->
        <DropShadowEffect x:Key="ShadowEffect"
                  BlurRadius="8"
                  ShadowDepth="2"
                  Opacity="0.4"
                  Direction="270"/>
    </Window.Resources>
    
    <Grid Margin="10">
        <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>

        <TextBox Text="{Binding TitreFenetre}" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="5,5,0,0"  Height="30" Style="{DynamicResource TextBoxStyle}" />

        <ListView Name="ThreadsList" ItemsSource="{Binding ListeItems}" SelectedItem="{Binding SelectedItem}" 
                  AlternationCount="2" Style="{DynamicResource ListViewStyle}"
                  IsSynchronizedWithCurrentItem="false" local:GridViewSort.AutoSort="True"
                  Margin="5,45,5,30">
            <ListView.ItemContainerStyle>
                <Style TargetType="ListViewItem" BasedOn="{StaticResource AlternatingListViewItemStyle}">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding IsOverdue}" Value="True">
                            <Setter Property="Foreground" Value="DarkRed"/>
                            <Setter Property="FontWeight" Value="Bold"/>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </ListView.ItemContainerStyle>
            <ListView.View>
                <GridView>
                    <GridViewColumn Width="120" DisplayMemberBinding="{Binding DateMessageSTR}" local:GridViewSort.PropertyName="DateMessage" >
                        <GridViewColumnHeader Content="Date début"  Style="{DynamicResource DefaultColumnHeaderStyle}" Click="ColumnHeader_Click" />
                    </GridViewColumn>

                    <GridViewColumn Width="120" DisplayMemberBinding="{Binding DateLastMessageSTR}" local:GridViewSort.PropertyName="DateLastMessage" >
                        <GridViewColumnHeader Content="Date fin"  Style="{DynamicResource DefaultColumnHeaderStyle}" Click="ColumnHeader_Click" />
                    </GridViewColumn>

                    <GridViewColumn Width="550" DisplayMemberBinding="{Binding Subject}" local:GridViewSort.PropertyName="Subject">
                        <GridViewColumnHeader  Content="Sujet"  Style="{DynamicResource DefaultColumnHeaderStyle}" Click="ColumnHeader_Click" />
                    </GridViewColumn>

                    <GridViewColumn Width="100" DisplayMemberBinding="{Binding Messages.Count}" local:GridViewSort.PropertyName="Messages.Count">
                        <GridViewColumnHeader  Content="Nb messages"  Style="{DynamicResource DefaultColumnHeaderStyle}" Click="ColumnHeader_Click" />
                    </GridViewColumn>

                    <GridViewColumn Width="100" DisplayMemberBinding="{Binding FollowUpDraft, Converter={StaticResource NullToBoolConverter}}" local:GridViewSort.PropertyName="FollowUpDraft" >
                        <GridViewColumnHeader  Content="Relance dispo"  Style="{DynamicResource DefaultColumnHeaderStyle}" Click="ColumnHeader_Click" />
                    </GridViewColumn>

                    <GridViewColumn Width="150">
                        <GridViewColumnHeader  Content="Actions"  Style="{DynamicResource DefaultColumnHeaderStyle}" Click="ColumnHeader_Click" />
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" >
                                    <Button Click="ShowMessages_Click" Style="{DynamicResource ButtonStyle}" Width="40" FontFamily="Segoe MDL2 Assets" Background="CadetBlue" Margin="5,0,0,0"
                                        ToolTip="Voir l'historique des messages de la conversation">
                                        &#xE8F2;
                                    </Button>
                                    <Button Click="CopyFollowUp_Click" Style="{DynamicResource ButtonStyle}" Width="40" FontFamily="Segoe MDL2 Assets" Background="GreenYellow" Margin="5,0,0,0"
                                        ToolTip="Afficher la relance générée et la copier dans le presse-papier">
                                        &#xE8CA;
                                    </Button>
                                    <Button x:Name="BtnCloseSubject" Click="CloseSuject_Click" Style="{DynamicResource ButtonStyle}" Width="40" FontFamily="Segoe MDL2 Assets" Background="IndianRed" Margin="5,0,0,0"
                                        ToolTip="Fermer un sujet ouvert OU réouvrir un sujet fermé">
                                        <TextBlock FontFamily="Segoe MDL2 Assets" Text="{Binding SubjectClosed, Converter={StaticResource BoolToStatusConverter}}"/>
                                    </Button>
                                </StackPanel>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                </GridView>
            </ListView.View>
        </ListView>
        <Button x:Name="BtnShowClosed" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="5,0,0,5" Width="180" Content="{Binding TxtBtnShowClosed}" Click="ShowClosed_Click" Style="{DynamicResource ButtonStyle}"/>
        <Button x:Name="BtnCheckNewMails" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="5,0,120,5" Width="170" Content="Rechercher nouveaux emails" Click="CheckNewMails_Click" Style="{DynamicResource ButtonStyle}"/>
        <Button x:Name="BtnFermer" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="5,0,0,5" Width="100" Content="Fermer" Click="Fermer_Click" Style="{DynamicResource ButtonStyle}"/>

    </Grid>
</Window>
