<Window x:Class="MarcusLaw.OutlookAddin.UI.Dialogs.ComposeFromCaseDialog"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="כתוב מייל מתיק"
        Height="480" Width="600"
        MinHeight="320" MinWidth="500"
        FlowDirection="RightToLeft"
        WindowStartupLocation="CenterOwner"
        ShowInTaskbar="False"
        ResizeMode="CanResize"
        Background="#F8FAFC"
        FontFamily="Segoe UI, David, Frank Ruehl, Arial">
    <Window.Resources>
        <SolidColorBrush x:Key="Primary"      Color="#2563EB" />
        <SolidColorBrush x:Key="PrimaryHover" Color="#1D4ED8" />
        <SolidColorBrush x:Key="Border"       Color="#E2E8F0" />
        <SolidColorBrush x:Key="Muted"        Color="#64748B" />
        <SolidColorBrush x:Key="CardBg"       Color="White" />
        <SolidColorBrush x:Key="HoverBg"      Color="#F1F5F9" />
        <SolidColorBrush x:Key="SelectedBg"   Color="#DBEAFE" />

        <Style x:Key="Card" TargetType="Border">
            <Setter Property="Background" Value="{StaticResource CardBg}" />
            <Setter Property="BorderBrush" Value="{StaticResource Border}" />
            <Setter Property="BorderThickness" Value="1" />
            <Setter Property="CornerRadius" Value="6" />
        </Style>

        <Style x:Key="PrimaryButton" TargetType="Button">
            <Setter Property="Background" Value="{StaticResource Primary}" />
            <Setter Property="Foreground" Value="White" />
            <Setter Property="BorderThickness" Value="0" />
            <Setter Property="Padding" Value="22,8" />
            <Setter Property="FontWeight" Value="SemiBold" />
            <Setter Property="MinWidth" Value="110" />
            <Setter Property="Cursor" Value="Hand" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Border x:Name="Bd"
                                Background="{TemplateBinding Background}"
                                CornerRadius="5"
                                Padding="{TemplateBinding Padding}">
                            <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter TargetName="Bd" Property="Background" Value="{StaticResource PrimaryHover}" />
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="False">
                                <Setter TargetName="Bd" Property="Background" Value="#94A3B8" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style x:Key="SecondaryButton" TargetType="Button">
            <Setter Property="Background" Value="White" />
            <Setter Property="Foreground" Value="#0F172A" />
            <Setter Property="BorderBrush" Value="{StaticResource Border}" />
            <Setter Property="BorderThickness" Value="1" />
            <Setter Property="Padding" Value="20,8" />
            <Setter Property="MinWidth" Value="110" />
            <Setter Property="Cursor" Value="Hand" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Border x:Name="Bd"
                                Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                CornerRadius="5"
                                Padding="{TemplateBinding Padding}">
                            <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter TargetName="Bd" Property="Background" Value="{StaticResource HoverBg}" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style x:Key="ResultItem" TargetType="ListBoxItem">
            <Setter Property="Padding" Value="0" />
            <Setter Property="Margin" Value="0" />
            <Setter Property="Background" Value="Transparent" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ListBoxItem">
                        <Border x:Name="Bd"
                                Background="{TemplateBinding Background}"
                                CornerRadius="4"
                                Margin="2,1"
                                Padding="8,6">
                            <ContentPresenter />
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter TargetName="Bd" Property="Background" Value="{StaticResource HoverBg}" />
                            </Trigger>
                            <Trigger Property="IsSelected" Value="True">
                                <Setter TargetName="Bd" Property="Background" Value="{StaticResource SelectedBg}" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>

    <Grid Margin="16">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <Border Grid.Row="0" Style="{StaticResource Card}" Padding="10,8" Margin="0,0,0,12">
            <DockPanel LastChildFill="True">
                <TextBlock DockPanel.Dock="Left" Text="🔍" VerticalAlignment="Center" FontSize="16" Margin="0,0,8,0" />
                <TextBox x:Name="SearchBox"
                         Text="{Binding SearchText, UpdateSourceTrigger=PropertyChanged}"
                         BorderThickness="0"
                         Background="Transparent"
                         FontSize="14"
                         VerticalAlignment="Center" />
            </DockPanel>
        </Border>

        <Border Grid.Row="1" Style="{StaticResource Card}">
            <ListBox ItemsSource="{Binding Cases}"
                     SelectedItem="{Binding SelectedCase}"
                     BorderThickness="0"
                     Background="Transparent"
                     ItemContainerStyle="{StaticResource ResultItem}"
                     Padding="4">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel>
                            <TextBlock FontSize="13">
                                <Run Text="[" /><Run Text="{Binding Number, Mode=OneWay}" /><Run Text="] " />
                                <Run Text="{Binding Name, Mode=OneWay}" FontWeight="SemiBold" />
                            </TextBlock>
                            <TextBlock Text="{Binding Status}" Foreground="{StaticResource Muted}" FontSize="11" />
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </Border>

        <TextBlock Grid.Row="2" Text="{Binding StatusMessage}"
                   Foreground="{StaticResource Muted}" Margin="0,10,0,0" FontSize="12" TextWrapping="Wrap" />

        <StackPanel Grid.Row="3" Orientation="Horizontal" HorizontalAlignment="Left" Margin="0,12,0,0">
            <Button Command="{Binding SubmitCommand}"
                    IsDefault="True"
                    Content="המשך"
                    Style="{StaticResource PrimaryButton}"
                    Margin="0,0,8,0" />
            <Button Command="{Binding CancelCommand}"
                    IsCancel="True"
                    Content="ביטול"
                    Style="{StaticResource SecondaryButton}" />
        </StackPanel>
    </Grid>
</Window>
