<Page x:Class="SASDesktop.Views.Transport.Create"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      xmlns:local="clr-namespace:SASDesktop.Views.Transport" xmlns:transport="clr-namespace:SASDesktop.ViewModels.Transport" d:DataContext="{d:DesignInstance Type=transport:Create}"
      xmlns:conv="clr-namespace:SASDesktop.Converters"
      mc:Ignorable="d" 
      d:DesignHeight="600" d:DesignWidth="800"
      Title="Create">
    <Page.Resources>
        <conv:BooleanToFormFilled x:Key="btff"/>
        <conv:BooleanToFormColor x:Key="btfc"/>
    </Page.Resources>
    <!--Страница создания водителя-->
    <ScrollViewer>
        <StackPanel
            CanVerticallyScroll="True"
            Style="{StaticResource FormContainer}">

            <TextBlock 
                HorizontalAlignment="Center"
                Style="{StaticResource H2}"
                Text="Создание транспортного средства"/>

            <StackPanel Orientation="Vertical">
                <!--VIN-->
                <StackPanel Margin="4">
                    <!--Надпись-->
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Style="{StaticResource H5}" Text="VIN номер"/>
                        <Label Style="{StaticResource RequiredMark}" Margin="4,0,0,0"/>
                    </StackPanel>
                    <!--Поле ввода-->
                    <TextBox
                        Margin="0,4"
                        VerticalContentAlignment="Center"
                        Text="{Binding VIN}"/>
                </StackPanel>

                <!--Основное о ТС-->
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>

                    <!--Тип ТС-->
                    <StackPanel Grid.Column="0" Grid.Row="0" Margin="4">
                        <!--Надпись-->
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Style="{StaticResource H5}" Text="Тип транспортного средства"/>
                            <Label Style="{StaticResource RequiredMark}" Margin="4,0,0,0"/>
                        </StackPanel>
                        <!--Выпадающий список-->
                        <ComboBox
                            SelectedItem="{Binding SelectedTransportType}"
                            ItemsSource="{Binding AllTransportTypes}">
                            <ComboBox.ItemTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding NameRus}"/>
                                </DataTemplate>
                            </ComboBox.ItemTemplate>
                        </ComboBox>
                    </StackPanel>

                    <!--Владелец-->
                    <StackPanel Grid.Column="1" Grid.Row="0" Margin="4">
                        <!--Надпись-->
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Style="{StaticResource H5}" Text="Владелец"/>
                        </StackPanel>
                        <!--Поле ввода и автодополнение-->
                        <StackPanel>
                            <TextBox
                                x:Name="tbOwner"
                                GotFocus="tbOwner_GotFocus"
                                LostFocus="tbOwner_LostFocus"
                                Text="{Binding OwnerSearch,UpdateSourceTrigger=PropertyChanged}"/>
                            <Popup
                                IsOpen="{Binding OwnerSuggestionsVisible}"
                                Placement="Bottom"
                                Width="{Binding RelativeSource={RelativeSource Self},Path=PlacementTarget.ActualWidth}"
                                PlacementTarget="{Binding ElementName=tbOwner}">
                                <ListBox
                                    x:Name="lbOwners"
                                    ItemsSource="{Binding SuggestedOwners}"
                                    SelectionChanged="lbOwners_SelectionChanged">
                                    <ListBox.ItemTemplate>
                                        <DataTemplate>
                                            <TextBlock Text="{Binding NameAndBirthdate}"/>
                                        </DataTemplate>
                                    </ListBox.ItemTemplate>
                                </ListBox>
                            </Popup>
                            <TextBlock
                                Text="{Binding OwnerIsSelected,Converter={StaticResource btff}}"
                                Foreground="{Binding OwnerIsSelected,Converter={StaticResource btfc}}"/>
                        </StackPanel>
                    </StackPanel>

                    <!--Категория-->
                    <StackPanel Grid.Column="2" Grid.Row="0" Margin="4">
                        <!--Надпись-->
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Style="{StaticResource H5}" Text="Категория"/>
                            <Label Style="{StaticResource RequiredMark}" Margin="4,0,0,0"/>
                        </StackPanel>
                        <!--Выпадающий список-->
                        <ComboBox
                            SelectedItem="{Binding SelectedCategory}"
                            ItemsSource="{Binding AllCategories}">
                            <ComboBox.ItemTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding Name}"/>
                                </DataTemplate>
                            </ComboBox.ItemTemplate>
                        </ComboBox>
                    </StackPanel>
                    
                </Grid>

                <!--Детали производства-->
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>

                    <!--Производитель-->
                    <StackPanel Grid.Column="0" Grid.Row="0" Margin="4">
                        <!--Надпись-->
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Style="{StaticResource H5}" Text="Производитель"/>
                            <Label Style="{StaticResource RequiredMark}" Margin="4,0,0,0"/>
                        </StackPanel>
                        <!--Поле ввода и автодополнение-->
                        <StackPanel>
                            <TextBox
                                x:Name="tbBrand"
                                GotFocus="tbBrand_GotFocus"
                                LostFocus="tbBrand_LostFocus"
                                Text="{Binding BrandSearch,UpdateSourceTrigger=PropertyChanged}"/>
                            <Popup
                                IsOpen="{Binding BrandSuggestionsVisible}"
                                Placement="Bottom"
                                Width="{Binding RelativeSource={RelativeSource Self},Path=PlacementTarget.ActualWidth}"
                                PlacementTarget="{Binding ElementName=tbBrand}">
                                <ListBox
                                    ItemsSource="{Binding SuggestedBrands}"
                                    SelectionChanged="ListBox_SelectionChanged">
                                    <ListBox.ItemTemplate>
                                        <DataTemplate>
                                            <TextBlock Text="{Binding Name}"/>
                                        </DataTemplate>
                                    </ListBox.ItemTemplate>
                                </ListBox>
                            </Popup>
                            <TextBlock
                                Text="{Binding BrandIsSelected,Converter={StaticResource btff}}"
                                Foreground="{Binding BrandIsSelected,Converter={StaticResource btfc}}"/>
                        </StackPanel>
                    </StackPanel>

                    <!--Модель-->
                    <StackPanel Grid.Column="1" Grid.Row="0" Margin="4">
                        <!--Надпись-->
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Style="{StaticResource H5}" Text="Модель"/>
                            <Label Style="{StaticResource RequiredMark}" Margin="4,0,0,0"/>
                        </StackPanel>
                        <!--Поле ввода и автодополнение-->
                        <StackPanel>
                            <TextBox
                                x:Name="tbModel"
                                GotFocus="tbModel_GotFocus"
                                LostFocus="tbModel_LostFocus"
                                Text="{Binding ModelSearch,UpdateSourceTrigger=PropertyChanged}"/>
                            <Popup
                                IsOpen="{Binding ModelSuggestionsVisible}"
                                Placement="Bottom"
                                Width="{Binding RelativeSource={RelativeSource Self},Path=PlacementTarget.ActualWidth}"
                                PlacementTarget="{Binding ElementName=tbModel}">
                                <ListBox
                                    x:Name="lbModelSuggestions"
                                    ItemsSource="{Binding SuggestedModels}"
                                    SelectionChanged="lbModelSuggestions_SelectionChanged">
                                    <ListBox.ItemTemplate>
                                        <DataTemplate>
                                            <TextBlock Text="{Binding Name}"/>
                                        </DataTemplate>
                                    </ListBox.ItemTemplate>
                                </ListBox>
                            </Popup>
                            <TextBlock
                                Text="{Binding ModelIsSelected,Converter={StaticResource btff}}"
                                Foreground="{Binding ModelIsSelected,Converter={StaticResource btfc}}"/>
                        </StackPanel>
                    </StackPanel>

                    <!--Цвет-->
                    <StackPanel Grid.Column="2" Grid.Row="0" Margin="4">
                        <!--Надпись-->
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Style="{StaticResource H5}" Text="Цвет"/>
                            <Label Style="{StaticResource RequiredMark}" Margin="4,0,0,0"/>
                        </StackPanel>
                        <!--Поле ввода и автодополнение-->
                        <StackPanel>
                            <TextBox
                                x:Name="tbColor"
                                GotFocus="tbColor_GotFocus"
                                LostFocus="tbColor_LostFocus"
                                Text="{Binding ColorSearch,UpdateSourceTrigger=PropertyChanged}"/>
                            <Popup
                                IsOpen="{Binding ColorSuggestionsVisible}"
                                Placement="Bottom"
                                Width="{Binding RelativeSource={RelativeSource Self},Path=PlacementTarget.ActualWidth}"
                                PlacementTarget="{Binding ElementName=tbColor}">
                                <ListBox
                                    x:Name="lbColorSuggestions"
                                    ItemsSource="{Binding SuggestedColors}"
                                    SelectionChanged="lbColorSuggestions_SelectionChanged">
                                    <ListBox.ItemTemplate>
                                        <DataTemplate>
                                            <TextBlock Text="{Binding HumanName}"/>
                                        </DataTemplate>
                                    </ListBox.ItemTemplate>
                                </ListBox>
                            </Popup>
                            <TextBlock
                                Text="{Binding ColorIsSelected,Converter={StaticResource btff}}"
                                Foreground="{Binding ColorIsSelected,Converter={StaticResource btfc}}"/>
                        </StackPanel>
                    </StackPanel>

                    <!--Год выпуска-->
                    <StackPanel Grid.Column="0" Grid.Row="1" Margin="4">
                        <!--Надпись-->
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Style="{StaticResource H5}" Text="Год выпуска"/>
                            <Label Style="{StaticResource RequiredMark}" Margin="4,0,0,0"/>
                        </StackPanel>
                        <!--Поле ввода-->
                        <TextBox
                            Margin="0,4"
                            VerticalContentAlignment="Center"
                            Text="{Binding ReleaseYear}"/>
                    </StackPanel>

                    <!--Привод-->
                    <StackPanel Grid.Column="1" Grid.Row="1" Margin="4">
                        <!--Надпись-->
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Style="{StaticResource H5}" Text="Тип привода"/>
                        </StackPanel>
                        <!--Выпадающий список-->
                        <ComboBox
                            SelectedItem="{Binding SelectedDrive}"
                            ItemsSource="{Binding AllDriveTypes}">
                            <ComboBox.ItemTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding Name}"/>
                                </DataTemplate>
                            </ComboBox.ItemTemplate>
                        </ComboBox>
                    </StackPanel>

                    <!--Максимальная нагрузка-->
                    <StackPanel Grid.Column="2" Grid.Row="1" Margin="4">
                        <!--Надпись-->
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Style="{StaticResource H5}" Text="Максимальная нагрузка (в кг.)"/>
                        </StackPanel>
                        <!--Поле ввода-->
                        <TextBox
                            Margin="0,4"
                            VerticalContentAlignment="Center"
                            Text="{Binding MaxLoad}"/>
                    </StackPanel>
                </Grid>

                <!--Двигатель-->
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>

                    <!--Номер двигателя-->
                    <StackPanel Grid.Column="0" Margin="4">
                        <!--Надпись-->
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Style="{StaticResource H5}" Text="Номер двигателя"/>
                        </StackPanel>
                        <!--Поле ввода-->
                        <TextBox
                            Margin="0,4"
                            VerticalContentAlignment="Center"
                            Text="{Binding EngineNumber}"/>
                    </StackPanel>

                    <!--Модель-->
                    <StackPanel Grid.Column="1" Margin="4">
                        <!--Надпись-->
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Style="{StaticResource H5}" Text="Модель двигателя"/>
                        </StackPanel>
                        <!--Поле ввода-->
                        <StackPanel>
                            <TextBox
                                x:Name="tbEngineModel"
                                GotFocus="tbEngineModel_GotFocus"
                                LostFocus="tbEngineModel_LostFocus"
                                Text="{Binding EngineModelSearch,UpdateSourceTrigger=PropertyChanged}"/>
                            <Popup
                                IsOpen="{Binding EngineModelSuggestionsVisible}"
                                Placement="Bottom"
                                Width="{Binding RelativeSource={RelativeSource Self},Path=PlacementTarget.ActualWidth}"
                                PlacementTarget="{Binding ElementName=tbEngineModel}">
                                <ListBox
                                    x:Name="lbEngineModelSuggestions"
                                    ItemsSource="{Binding SuggestedEngineModels}"
                                    SelectionChanged="lbEngineModelSuggestions_SelectionChanged">
                                    <ListBox.ItemTemplate>
                                        <DataTemplate>
                                            <TextBlock Text="{Binding Name}"/>
                                        </DataTemplate>
                                    </ListBox.ItemTemplate>
                                </ListBox>
                            </Popup>
                            <TextBlock
                                Text="{Binding EngineModelIsSelected,Converter={StaticResource btff}}"
                                Foreground="{Binding EngineModelIsSelected,Converter={StaticResource btfc}}"/>
                        </StackPanel>
                    </StackPanel>
                </Grid>

                <!--Вес-->
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <!--Вес-->
                    <StackPanel Grid.Column="0" Margin="4">
                        <!--Надпись-->
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Style="{StaticResource H5}" Text="Вес (в кг.)"/>
                            <Label Style="{StaticResource RequiredMark}" Margin="4,0,0,0"/>
                        </StackPanel>
                        <!--Поле ввода-->
                        <TextBox
                            Margin="0,4"
                            VerticalContentAlignment="Center"
                            Text="{Binding Weight}"/>
                    </StackPanel>
                </Grid>

                <!--Комментарий-->
                <StackPanel Margin="4">
                    <!--Надпись-->
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Style="{StaticResource H5}" Text="Комментарий"/>
                    </StackPanel>
                    <!--Поле ввода-->
                    <TextBox
                        Margin="0,4"
                        AcceptsReturn="True"
                        Height="128"
                        VerticalContentAlignment="Top"
                        Text="{Binding Comment}"/>
                </StackPanel>
                
            </StackPanel>

            <!--Сохранить/отмена-->
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="128"/>
                    <ColumnDefinition Width="128"/>
                </Grid.ColumnDefinitions>
                <Button 
                    Grid.Column="1"
                    Command="{Binding CancelCmd}"
                    Margin="4">Отмена</Button>
                <Button 
                    Grid.Column="2"
                    Command="{Binding SubmitCmd}"
                    Margin="4">Сохранить</Button>
            </Grid>
        </StackPanel>
    </ScrollViewer>
</Page>
