<ContentDialog
    x:Class="Wino.Dialogs.SingleCalendarPickerDialog"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:calendar="using:Wino.Core.Domain.Models.Calendar"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:domain="using:Wino.Core.Domain"
    xmlns:helpers="using:Wino.Helpers"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:sharedCalendar="using:Wino.Core.Domain.Entities.Calendar"
    Title="{x:Bind domain:Translator.CalendarEventCompose_PickCalendarTitle}"
    PrimaryButtonText="{x:Bind domain:Translator.Buttons_Cancel}"
    Style="{StaticResource WinoDialogStyle}"
    mc:Ignorable="d">

    <ContentDialog.Resources>
        <x:Double x:Key="ContentDialogMinWidth">420</x:Double>
        <Style
            x:Key="CalendarPickerListItemStyle"
            BasedOn="{StaticResource DefaultListViewItemStyle}"
            TargetType="ListViewItem">
            <Setter Property="Padding" Value="12,10" />
            <Setter Property="CornerRadius" Value="4" />
            <Setter Property="Margin" Value="0,2" />
        </Style>
    </ContentDialog.Resources>

    <StackPanel Margin="0,8,0,0" Spacing="12">
        <TextBlock
            Foreground="{ThemeResource TextFillColorSecondaryBrush}"
            Text="{x:Bind domain:Translator.CalendarEventCompose_DefaultCalendarHint}"
            TextWrapping="WrapWholeWords" />

        <HyperlinkButton
            HorizontalAlignment="Left"
            Click="OpenCalendarSettingsClicked"
            Content="{x:Bind domain:Translator.CalendarEventCompose_DefaultCalendarSettingsLink}"
            Padding="0" />

        <ScrollViewer MaxHeight="400">
            <ItemsControl ItemsSource="{x:Bind AvailableGroups}">
                <ItemsControl.ItemTemplate>
                    <DataTemplate x:DataType="calendar:CalendarPickerAccountGroup">
                        <StackPanel Margin="0,0,0,12" Spacing="6">
                            <TextBlock FontWeight="SemiBold">
                                <Run Text="{x:Bind Account.Name}" />
                                <Run Text=" (" />
                                <Run Text="{x:Bind Account.Address}" />
                                <Run Text=")" />
                            </TextBlock>

                            <ListView
                                IsItemClickEnabled="True"
                                ItemClick="CalendarClicked"
                                ItemContainerStyle="{StaticResource CalendarPickerListItemStyle}"
                                ItemsSource="{x:Bind Calendars}"
                                SelectionMode="None">
                                <ListView.ItemTemplate>
                                    <DataTemplate x:DataType="sharedCalendar:AccountCalendar">
                                        <Grid ColumnSpacing="10">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="Auto" />
                                                <ColumnDefinition Width="*" />
                                            </Grid.ColumnDefinitions>

                                            <Ellipse
                                                Width="14"
                                                Height="14"
                                                VerticalAlignment="Center"
                                                Fill="{x:Bind helpers:XamlHelpers.GetSolidColorBrushFromHex(BackgroundColorHex)}" />

                                            <TextBlock
                                                Grid.Column="1"
                                                VerticalAlignment="Center"
                                                Text="{x:Bind Name}" />
                                        </Grid>
                                    </DataTemplate>
                                </ListView.ItemTemplate>
                            </ListView>
                        </StackPanel>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </ScrollViewer>
    </StackPanel>
</ContentDialog>
