<Page
    x:Class="APKInstaller.Pages.ToolsPages.ProcessesPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:controls="using:APKInstaller.Controls"
    xmlns:cwuc="using:CommunityToolkit.WinUI.UI.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:devicecommands="using:AdvancedSharpAdbClient.DeviceCommands"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:toolspages="using:APKInstaller.ViewModels.ToolsPages"
    d:DataContext="{d:DesignInstance Type=toolspages:ProcessesViewModel}"
    NavigationCacheMode="Enabled"
    mc:Ignorable="d">
    <Page.Resources>
        <toolspages:ProcesseConverter x:Key="TextConverter" />
    </Page.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <controls:TitleBar
            x:Name="TitleBar"
            x:Uid="/ProcessesPage/TitleBar"
            BackRequested="TitleBar_BackRequested"
            IsBackButtonVisible="True"
            IsBackEnabled="{x:Bind Frame.CanGoBack}"
            IsRefreshButtonVisible="True"
            IsRefreshEnabled="True"
            RefreshRequested="TitleBar_RefreshEvent">
            <ComboBox
                x:Name="DeviceComboBox"
                x:Uid="/ProcessesPage/DeviceComboBox"
                VerticalAlignment="Center"
                ItemsSource="{x:Bind Provider.DeviceList, Mode=OneWay}"
                Loaded="ComboBox_Loaded"
                SelectionChanged="ComboBox_SelectionChanged" />
        </controls:TitleBar>
        <cwuc:DataGrid
            x:Name="DataGrid"
            Grid.Row="1"
            d:DataContext="{d:DesignInstance Type=devicecommands:AndroidProcess}"
            AutoGenerateColumns="False"
            CanUserReorderColumns="True"
            CanUserResizeColumns="True"
            CanUserSortColumns="True"
            IsReadOnly="True"
            ItemsSource="{x:Bind Provider.Processes, Mode=OneWay}"
            Sorting="DataGrid_Sorting">
            <cwuc:DataGrid.Columns>
                <cwuc:DataGridTextColumn
                    x:Uid="/ProcessesPage/Name"
                    Binding="{Binding Name, Converter={StaticResource TextConverter}, ConverterParameter='Name'}"
                    Tag="Name" />
                <cwuc:DataGridTextColumn
                    x:Uid="/ProcessesPage/ProcessId"
                    Binding="{Binding ProcessId}"
                    Tag="ProcessId" />
                <cwuc:DataGridTextColumn
                    x:Uid="/ProcessesPage/State"
                    Binding="{Binding State, Converter={StaticResource TextConverter}, ConverterParameter='State'}"
                    Tag="State" />
                <cwuc:DataGridTextColumn
                    x:Uid="/ProcessesPage/ResidentSetSize"
                    Binding="{Binding ResidentSetSize, Converter={StaticResource TextConverter}, ConverterParameter='Size'}"
                    Tag="ResidentSetSize" />
                <cwuc:DataGridTextColumn
                    x:Uid="/ProcessesPage/Detail"
                    Binding="{Binding Name}"
                    Tag="Detail" />
            </cwuc:DataGrid.Columns>
        </cwuc:DataGrid>
    </Grid>
</Page>
