<?xml version="1.0" encoding="utf-8" ?>
<pages:BaseContentPage 
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    x:Class="Bit.App.Pages.CollectionsPage"
    xmlns:pages="clr-namespace:Bit.App.Pages"
    xmlns:u="clr-namespace:Bit.App.Utilities"
    xmlns:controls="clr-namespace:Bit.App.Controls"
    x:DataType="pages:CollectionsPageViewModel"
    x:Name="_page"
    Title="{Binding PageTitle}">
    <ContentPage.BindingContext>
        <pages:CollectionsPageViewModel />
    </ContentPage.BindingContext>

    <ContentPage.ToolbarItems>
        <ToolbarItem Text="{u:I18n Cancel}" Clicked="Close_Clicked" Order="Primary" Priority="-1" />
        <ToolbarItem Text="{u:I18n Save}" Clicked="Save_Clicked" />
    </ContentPage.ToolbarItems>

    <ContentPage.Resources>
        <ResourceDictionary>
            <u:InverseBoolConverter x:Key="inverseBool" />
            <u:IsNotNullConverter x:Key="notNull" />
        </ResourceDictionary>
    </ContentPage.Resources>

    <ScrollView x:Name="_scrollView">
        <StackLayout Spacing="20">
            <StackLayout StyleClass="box">
                <StackLayout StyleClass="box-row" Padding="10, 20"
                             IsVisible="{Binding HasCollections, Converter={StaticResource inverseBool}}">
                    <Label Text="{u:I18n NoCollectionsToList}" HorizontalTextAlignment="Center" />
                </StackLayout>
                <controls:RepeaterView ItemsSource="{Binding Collections}" IsVisible="{Binding HasCollections}">
                    <controls:RepeaterView.ItemTemplate>
                        <DataTemplate x:DataType="pages:CollectionViewModel">
                            <StackLayout Spacing="0" Padding="0">
                                <StackLayout StyleClass="box-row, box-row-switch">
                                    <Label
                                        Text="{Binding Collection.Name}"
                                        StyleClass="box-label-regular"
                                        HorizontalOptions="StartAndExpand" />
                                    <Switch
                                        IsToggled="{Binding Checked}"
                                        StyleClass="box-value"
                                        HorizontalOptions="End" />
                                </StackLayout>
                                <BoxView StyleClass="box-row-separator" />
                            </StackLayout>
                        </DataTemplate>
                    </controls:RepeaterView.ItemTemplate>
                </controls:RepeaterView>
            </StackLayout>
        </StackLayout>
    </ScrollView>

</pages:BaseContentPage>
