<UserControl x:Class="Canaan.Kendryte.Flash.Shell.Views.FlashView"
             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:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
             xmlns:local="clr-namespace:Canaan.Kendryte.Flash.Shell.Views"
             xmlns:cal="http://www.caliburnproject.org"
             xmlns:ae="http://icsharpcode.net/sharpdevelop/avalonedit"
             mc:Ignorable="d" 
             d:DesignHeight="438.412" d:DesignWidth="654.888">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="../Assets/Styles.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            <Style x:Key="FieldHeaderTextBlock" TargetType="{x:Type TextBlock}"
               BasedOn="{StaticResource MaterialDesignSubheadingTextBlock}"/>
            <Style x:Key="FieldHeaderCheckbox" TargetType="{x:Type CheckBox}"
               BasedOn="{StaticResource MaterialDesignCheckBox}">
                <Setter Property="FontSize" Value="15"/>
            </Style>
            <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="300"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <StackPanel Margin="10">
            <TextBlock Style="{StaticResource FieldHeaderTextBlock}"><Run Text="Device"/></TextBlock>
            <ComboBox materialDesign:HintAssist.Hint="Device" ItemsSource="{Binding Devices}" SelectedValue="{Binding Device}"
                      DisplayMemberPath="Name" SelectedValuePath="Port"/>
            <Grid Margin="0 10 0 0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <StackPanel Margin="0 0 5 0">
                    <TextBlock Style="{StaticResource FieldHeaderTextBlock}"><Run Text="Baud rate"/></TextBlock>
                    <ComboBox materialDesign:HintAssist.Hint="Baud rate" IsEditable="True" ItemsSource="{Binding BaudRates}" Text="{Binding BaudRate, Mode=TwoWay}"/>
                </StackPanel>
                <StackPanel Grid.Column="1" Margin="5 0 0 0">
                    <TextBlock Style="{StaticResource FieldHeaderTextBlock}"><Run Text="Chip"/></TextBlock>
                    <ComboBox materialDesign:HintAssist.Hint="Chip" ItemsSource="{Binding Chips}"
                              DisplayMemberPath="Key" SelectedValuePath="Value"
                              SelectedValue="{Binding Chip, Mode=TwoWay}"/>
                </StackPanel>
            </Grid>
            <TextBlock Margin="0 10 0 0" Style="{StaticResource FieldHeaderTextBlock}"><Run Text="Firmware"/></TextBlock>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <TextBox materialDesign:HintAssist.Hint="Firmware" Text="{Binding Firmware, Mode=TwoWay}"/>
                <Button cal:Message.Attach="BrowseFirmware" Grid.Column="1"
                        Style="{StaticResource MaterialDesignFlatButton}" Content="..."/>
            </Grid>
            <StackPanel Margin="0 10 5 0">
                <CheckBox IsChecked="{Binding OpenTerminal}">Open terminal after flash</CheckBox>
            </StackPanel>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <Button cal:Message.Attach="StartFlash" Margin="0 10 10 0"
                    IsEnabled="{Binding CanStartFlash}"
                    materialDesign:ButtonProgressAssist.IsIndicatorVisible="{Binding IsFlashing}"
                    materialDesign:ButtonProgressAssist.Value="-1"
                    materialDesign:ButtonProgressAssist.IsIndeterminate="True" Content="Flash"/>
                <Button Grid.Column="1" Margin="0 10 0 0"
                    Command="{x:Static materialDesign:DialogHost.OpenDialogCommand}">
                    <Button.CommandParameter>
                        <StackPanel Margin="16">
                            <TextBlock><Run Text="K-Flash"/><LineBreak/><LineBreak/><Run Text="Copyright 2018-2019 Canaan Inc."/><Run Text=" "/><Hyperlink NavigateUri="https://kendryte.com" RequestNavigate="Hyperlink_RequestNavigate"><Run Text="https://kendryte.com"/></Hyperlink><LineBreak/></TextBlock>
                            <TextBlock Margin="0 5 0 0"><Run Text="License:"/></TextBlock>
                            <TextBox IsReadOnly="True" VerticalScrollBarVisibility="Visible"
                                     HorizontalScrollBarVisibility="Auto"
                                     Text="{Binding License}" MaxLines="6" />
                            <Button Style="{StaticResource MaterialDesignFlatButton}" Margin="0 10 0 0"
                                    IsCancel="True"
                                    Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}"
                                    HorizontalAlignment="Center" Content="OK"/>
                        </StackPanel>
                    </Button.CommandParameter>
                    <materialDesign:PackIcon Kind="InformationVariant" />
                </Button>
            </Grid>
        </StackPanel>
        <StatusBar Grid.Row="1" Grid.ColumnSpan="2" Background="#EFEFEF">
            <StatusBarItem>
                <TextBlock Foreground="Black" Text="{Binding CurrentJob}"/>
            </StatusBarItem>
            <StatusBarItem HorizontalAlignment="Right">
                <ProgressBar Width="150" Visibility="{Binding IsFlashing, Converter={StaticResource BooleanToVisibilityConverter}}"
                             Value="{Binding CurrentJobStatus.Progress}" Height="8" Minimum="0" Maximum="1"/>
            </StatusBarItem>
        </StatusBar>
    </Grid>
</UserControl>
