<Window x:Class="MarcusLaw.OutlookAddin.UI.Dialogs.SettingsDialog"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="הגדרות תוסף Klear"
        Height="520" Width="560"
        MinHeight="400" MinWidth="500"
        FlowDirection="RightToLeft"
        WindowStartupLocation="CenterOwner"
        ShowInTaskbar="False"
        ResizeMode="CanResize">
    <Grid Margin="12">
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <TabControl Grid.Row="0" x:Name="Tabs">
            <TabItem Header="כללי">
                <Grid Margin="8">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>

                    <TextBlock Grid.Row="0" Text="כתובת שרת Klear" Margin="0,0,0,2" />
                    <TextBox Grid.Row="1" Text="{Binding EspoCrmUrl, UpdateSourceTrigger=PropertyChanged}"
                             Padding="6,4" Margin="0,0,0,10" />

                    <TextBlock Grid.Row="2" Text="שם משתמש" Margin="0,0,0,2" />
                    <TextBox Grid.Row="3" Text="{Binding Username, UpdateSourceTrigger=PropertyChanged}"
                             Padding="6,4" Margin="0,0,0,10" />

                    <TextBlock Grid.Row="4" Text="מפתח API" Margin="0,0,0,2" />
                    <PasswordBox Grid.Row="5" x:Name="ApiKeyBox" Padding="6,4" Margin="0,0,0,10" />

                    <TextBlock Grid.Row="6" Text="שפת ממשק" Margin="0,0,0,2" />
                    <ComboBox Grid.Row="7" SelectedValue="{Binding Locale}" SelectedValuePath="Tag"
                              Padding="6,4" Margin="0,0,0,10">
                        <ComboBoxItem Content="עברית" Tag="he-IL" />
                        <ComboBoxItem Content="English" Tag="en-US" />
                    </ComboBox>

                    <TextBlock Grid.Row="8" Text="{Binding StatusMessage}"
                               Foreground="{Binding StatusBrush}"
                               TextWrapping="Wrap"
                               VerticalAlignment="Top"
                               Margin="0,4,0,0" />

                    <StackPanel Grid.Row="9" Orientation="Horizontal" Margin="0,10,0,0">
                        <Button Command="{Binding TestConnectionCommand}"
                                Content="בדוק חיבור"
                                Padding="14,5"
                                MinWidth="120" />
                    </StackPanel>
                </Grid>
            </TabItem>

            <TabItem Header="תיקיות">
                <Grid Margin="6">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>
                    <TextBlock Grid.Row="0" Margin="2,2,2,6" TextWrapping="Wrap"
                               Text="סמן תיקיות לניטור. במצב 'אוטומטי' התוסף יתייק לבד מיילים שזוהו בוודאות, אחרת רק יסמן 'נדרש תיוק'." />
                    <DataGrid Grid.Row="1" ItemsSource="{Binding Folders}"
                              AutoGenerateColumns="False"
                              HeadersVisibility="Column"
                              GridLinesVisibility="Horizontal"
                              CanUserAddRows="False" CanUserDeleteRows="False"
                              FlowDirection="RightToLeft">
                        <DataGrid.Columns>
                            <DataGridCheckBoxColumn Header="נטור" Binding="{Binding IsWatched, UpdateSourceTrigger=PropertyChanged}" Width="60" />
                            <DataGridTextColumn Header="תיקייה" Binding="{Binding DisplayLabel}" IsReadOnly="True" Width="*" />
                            <DataGridTextColumn Header="חשבון" Binding="{Binding Node.StoreDisplayName}" IsReadOnly="True" Width="140" />
                            <DataGridTemplateColumn Header="מצב" Width="160">
                                <DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <ComboBox SelectedValue="{Binding Mode, UpdateSourceTrigger=PropertyChanged}" SelectedValuePath="Tag">
                                            <ComboBoxItem Content="התרעה בלבד" Tag="NotifyOnly" />
                                            <ComboBoxItem Content="תיוק אוטומטי" Tag="AutoFile" />
                                        </ComboBox>
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>
                            </DataGridTemplateColumn>
                        </DataGrid.Columns>
                    </DataGrid>
                </Grid>
            </TabItem>

            <TabItem Header="אודות">
                <StackPanel Margin="16">
                    <TextBlock Text="Marcus-Law OutlookAddin" FontWeight="Bold" FontSize="16" />
                    <TextBlock Text="תוסף Klear ל-Microsoft Outlook" Margin="0,4,0,12" />
                    <DockPanel LastChildFill="False" Margin="0,0,0,4">
                        <TextBlock DockPanel.Dock="Left" Text="{Binding VersionLine}" Foreground="Gray" VerticalAlignment="Center" />
                        <Button DockPanel.Dock="Right"
                                Command="{Binding CheckForUpdateCommand}"
                                Content="בדוק עדכונים"
                                Padding="14,4"
                                MinWidth="120" />
                    </DockPanel>
                    <TextBlock Text="{Binding UpdateStatus}"
                               Foreground="{Binding UpdateStatusBrush}"
                               TextWrapping="Wrap"
                               Margin="0,4,0,0" />
                    <TextBlock Margin="0,16,0,0" TextWrapping="Wrap"
                               Text="לוגים: %LOCALAPPDATA%\MarcusLaw\OutlookAddin\logs" />
                    <TextBlock TextWrapping="Wrap"
                               Text="הגדרות: %APPDATA%\MarcusLaw\OutlookAddin\settings.json" />
                </StackPanel>
            </TabItem>
        </TabControl>

        <StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Left" Margin="0,12,0,0">
            <Button Command="{Binding SaveCommand}"
                    IsDefault="True"
                    Content="שמור"
                    Padding="20,5"
                    Margin="0,0,8,0"
                    MinWidth="100" />
            <Button Command="{Binding CancelCommand}"
                    IsCancel="True"
                    Content="ביטול"
                    Padding="20,5"
                    MinWidth="100" />
        </StackPanel>
    </Grid>
</Window>
