<!-- Copyright (c) Microsoft Corporation.
     Licensed under the MIT License. -->
<Page
    x:Class="WinGetUWPCaller.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:WinGetUWPCaller"
    xmlns:deployment="using:Microsoft.Management.Deployment"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Page.Resources>
        <ResourceDictionary>
            <Style TargetType="StackPanel">
                <Setter Property="Margin" Value="5" />
                <Setter Property="HorizontalAlignment" Value="Center" />
            </Style>
            <Style TargetType="Button">
                <Setter Property="Margin" Value="5" />
                <Setter Property="HorizontalAlignment" Value="Center" />
            </Style>
        </ResourceDictionary>
    </Page.Resources>

    <Grid MinWidth="800" MinHeight="600">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>

        <StackPanel Grid.Row="1">
            <TextBlock Style="{StaticResource SubheaderTextBlockStyle}">Select Catalog(s)</TextBlock>

            <Button x:Name="loadCatalogsButton" Click="LoadCatalogsButtonClickHandler">Load Catalogs</Button>
            <TextBlock x:Name="catalogStatusText" Text="" HorizontalAlignment="Center" Margin="0,0,0,20"/>
            <TextBlock>Select catalog(s) to use</TextBlock>
            <ListBox x:Name="catalogsListBox" ItemsSource="{x:Bind PackageCatalogs}" SelectionChanged="CatalogSelectionChangedHandler" SelectionMode="Multiple" Height="200">
                <ItemsControl.ItemTemplate>
                    <DataTemplate x:DataType="deployment:PackageCatalogReference">
                        <TextBlock Text="{x:Bind Info.Name, Mode=OneTime}"/>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ListBox>
        </StackPanel>

        <StackPanel Grid.Row="1" Grid.Column="1">
            <TextBlock Style="{StaticResource SubheaderTextBlockStyle}">Package Operations</TextBlock>
            <TextBlock>Search for a package from the selected catalog(s) and take action on it.</TextBlock>

            <StackPanel Orientation="Horizontal">
                <TextBox x:Name="queryTextBox" Header="Find a package:" PlaceholderText="Query (e.g. Microsoft.Teams)"></TextBox>
                <ComboBox x:Name="searchField" Header="Search options" Margin="5,0,5,0" SelectedIndex="0">
                    <ComboBoxItem Content="Generic query"></ComboBoxItem>
                    <ComboBoxItem Content="Identifier (case-insensitive)"></ComboBoxItem>
                    <ComboBoxItem Content="Name (substring)"></ComboBoxItem>
                </ComboBox>
                <Button x:Name="searchButton" Click="SearchButtonClickHandler" VerticalAlignment="Bottom" Margin="5,0,5,0">🔍</Button>
            </StackPanel>

            <StackPanel Orientation="Horizontal">
                <Button x:Name="installButton" Click="InstallButtonClickHandler" IsEnabled="False">Install</Button>
                <Button x:Name="upgradeButton" Click="UpgradeButtonClickHandler" IsEnabled="False">Upgrade</Button>
                <Button x:Name="downloadButton" Click="DownloadButtonClickHandler" IsEnabled="False">Download</Button>
                <Button x:Name="cancelButton" Click="CancelButtonClickHandler" IsEnabled="False">Cancel</Button>
            </StackPanel>

            <ProgressBar x:Name="operationProgressBar" Value="0" Maximum="100" Width="350"/>
            <TextBlock x:Name="operationStatusText" Text="" HorizontalAlignment="Center" Margin="0,0,0,20"/>

            <TextBox x:Name="downloadDirectoryTextBox" Header="Download Location:" PlaceholderText="Existing directory path to download to"></TextBox>
        </StackPanel>

        <StackPanel Grid.Row="2" Margin="3">
            <TextBlock Style="{StaticResource SubheaderTextBlockStyle}">Installed Packages</TextBlock>
            <TextBlock>View installed package information</TextBlock>
            <Button x:Name="refreshInstalledButton" Click="RefreshInstalledButtonClickHandler" IsEnabled="True">Refresh</Button>
            <TextBlock x:Name="installedStatusText" Text=""/>
            <ListBox x:Name="installedListBox" ItemsSource="{x:Bind InstalledPackages}" Height="300" SelectionMode="Single" ScrollViewer.VerticalScrollBarVisibility="Visible">
                <ItemsControl.ItemTemplate>
                    <DataTemplate x:DataType="deployment:CatalogPackage">
                        <TextBlock Text="{x:Bind Name, Mode=OneTime}"/>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ListBox>

            <Button x:Name="uninstallButton" Click="UninstallButtonClickHandler" IsEnabled="True" Margin="5,20,5,5">Uninstall</Button>
            <ProgressBar x:Name="uninstallProgressBar" Value="0" Maximum="100" Width="350"/>
            <TextBlock x:Name="uninstallStatusText" Text="" HorizontalAlignment="Center" Margin="0,0,0,20"/>
        </StackPanel>

        <StackPanel Grid.Row="2" Grid.Column="1" Margin="3">
            <TextBlock Style="{StaticResource SubheaderTextBlockStyle}">Active Operations</TextBlock>
            <TextBlock>View active package install/upgrade operations</TextBlock>
            <StackPanel Orientation="Horizontal" >
                <Button x:Name="activeRefreshButton" Click="RefreshActiveButtonClickHandler" IsEnabled="True">Refresh</Button>
            </StackPanel>
            <TextBlock x:Name="activeStatusText" Text=""/>
            <ListBox x:Name="activeListBox" ItemsSource="{x:Bind ActivePackages}" Height="300" ScrollViewer.VerticalScrollBarVisibility="Visible">
                <ItemsControl.ItemTemplate>
                    <DataTemplate x:DataType="local:ActivePackageView">
                        <StackPanel HorizontalAlignment="Center">
                            <TextBlock Text="{x:Bind Package.Id, Mode=OneWay}"/>
                            <ProgressBar Value="{x:Bind Progress, Mode=OneWay}" Maximum="100" Width="200px"></ProgressBar>
                            <TextBlock Text="{x:Bind StatusText, Mode=OneWay}" HorizontalAlignment="Center"></TextBlock>
                        </StackPanel>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ListBox>
        </StackPanel>
    </Grid>
</Page>
