<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
    xmlns:views="clr-namespace:Borepin.View"
    x:Class="Borepin.Page.MachineListPage"
    xmlns:converters="clr-namespace:Borepin.Converter"
    xmlns:resource_text="clr-namespace:Borepin.Resources.Text"
    Title="{x:Static resource_text:TextResource.TITLE_Machines}"
    >
    <NavigationPage.TitleView>
        <Button Text="Refresh" HorizontalOptions="End" BackgroundColor="{StaticResource SecondColor}" TextColor="{StaticResource FirstColor}" Command="{Binding RefreshCommand}"/>
    </NavigationPage.TitleView>
    <ContentPage.Resources>
        <ResourceDictionary>
            <converters:AllTrueBoolConverter x:Key="AllTrueBoolConverter"/>
            <converters:InvertBoolConverter x:Key="InvertBoolConverter"/>
            <converters:ListNotEmptyConverter x:Key="ListNotEmptyConverter"/>
        </ResourceDictionary>
    </ContentPage.Resources>
    <ContentPage.Content>
        <StackLayout Padding="20">
            <views:ConnectionStateView/>
            <StackLayout>
                <StackLayout.IsVisible>
                    <MultiBinding Converter="{StaticResource AllTrueBoolConverter}">
                        <Binding Path="IsBusy" Converter="{StaticResource InvertBoolConverter}"/>
                        <Binding Path="IsConnected"/>
                    </MultiBinding>
                </StackLayout.IsVisible>
                <Button Text="{x:Static resource_text:TextResource.SCANQR}" Command="{Binding ScanCodeCommand}" Style="{StaticResource Style_Button_Primary}">
                        <Button.IsVisible>
                            <OnPlatform x:TypeArguments="x:Boolean"
                            iOS="True"
                            Android="True"/>
                        </Button.IsVisible>
                    </Button>
                <ListView ItemsSource="{Binding MachineListItemViewModel_List}" SelectionMode="None" SeparatorColor="Transparent" IsGroupingEnabled="True" GroupDisplayBinding="{Binding Category}">
                    <ListView.GroupHeaderTemplate>
                        <DataTemplate>
                            <ViewCell>
                                <StackLayout Margin="0, 10, 0, 0">
                                    <Label Text="{Binding Category}"/>
                                </StackLayout>
                            </ViewCell>
                        </DataTemplate>
                    </ListView.GroupHeaderTemplate>
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <ViewCell>
                                <views:MachineListItemView />
                            </ViewCell>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </StackLayout>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>
