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

    <ContentPage.ToolbarItems>
        <ToolbarItem Text="{u:I18n Cancel}" Clicked="Close_Clicked" Order="Primary" Priority="-1" />
        <ToolbarItem Text="{u:I18n Move}" Command="{Binding MoveCommand}" />
    </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"
                         IsVisible="{Binding HasOrganizations, Converter={StaticResource inverseBool}}">
                <StackLayout StyleClass="box-row" Padding="10, 20">
                    <Label Text="{u:I18n NoOrgsToList}" HorizontalTextAlignment="Center" />
                </StackLayout>
            </StackLayout>
            <StackLayout StyleClass="box"
                         IsVisible="{Binding HasOrganizations}">
                <StackLayout StyleClass="box-row, box-row-input, box-row-input-options-platform">
                    <Label
                        Text="{u:I18n Organization}"
                        StyleClass="box-label" />
                    <Picker
                        x:Name="_organizationPicker"
                        ItemsSource="{Binding OrganizationOptions, Mode=OneTime}"
                        SelectedIndex="{Binding OrganizationSelectedIndex}"
                        StyleClass="box-value" />
                </StackLayout>
                <Label
                    Text="{u:I18n MoveToOrgDesc}"
                    StyleClass="box-footer-label" />
            </StackLayout>
            <StackLayout StyleClass="box"
                         IsVisible="{Binding OrganizationId, Converter={StaticResource notNull}}">
                <StackLayout StyleClass="box-row-header">
                    <Label Text="{u:I18n Collections, Header=True}"
                           StyleClass="box-header, box-header-platform" />
                </StackLayout>
                <StackLayout StyleClass="box-row"
                             IsVisible="{Binding HasCollections, Converter={StaticResource inverseBool}}">
                    <Label Text="{u:I18n NoCollectionsToList}" />
                </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>
