<?xml version="1.0" encoding="utf-8"?>
<Page
    x:Class="was.droidtransfer.features.ContactsContentPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:was.droidtransfer.features"
    xmlns:converters="using:was.droidtransfer.features.converters"
    xmlns:contactsdata="using:was.std.android.contacts.data"
    xmlns:contactCommon="using:was.android.connect.common.contact"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:contactsdata1="using:was.std.android.contacts.data"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Page.Resources>
        <ResourceDictionary>
            <converters:ValueToVisibilityConverter x:Key="ValueVisibilityConverter"/>
            <converters:StringArrayToStringConverter x:Key="StringArrayStringConverter"/>
            <converters:LocationToImageConverter x:Key="LocationToImageConverter"/>
            <converters:BoolToBorderThemeConverter x:Key="BoolToBorderThemeConverter"/>
        </ResourceDictionary>
    </Page.Resources>
    <Border Style="{ThemeResource FeatureContentPageBorder}" Padding="0">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>

            <ScrollViewer Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
                <Grid x:Name="gridContactDetails" Padding="30" Visibility="Collapsed">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>

                    <Grid>
                        <Button x:Name="buttonClose" Grid.Column="1" Click="_buttonClose_Click" HorizontalAlignment="Right" VerticalAlignment="Top"
                        Visibility="{x:Bind IsCloseButtonVisible, Converter={StaticResource ValueVisibilityConverter}, Mode=OneWay}"
                        Height="32" BorderThickness="0" Margin="0,-10,-10,0">
                            <Button.Content>
                                <FontIcon Glyph="&#xE8BB;"/>
                            </Button.Content>
                        </Button>
                        <StackPanel Orientation="Horizontal"  Margin="0,0,0,20"  VerticalAlignment="Top">
                            <PersonPicture ProfilePicture="{x:Bind Contact.PictureBitmapImage, Mode=OneWay}" 
                       DisplayName="{x:Bind Contact.Initials, Mode=OneWay}" Margin="0,0,10,0" VerticalAlignment="Center"/>
                            <StackPanel VerticalAlignment="Center" Margin="0,0,0,10">
                                <TextBlock Text="{x:Bind Contact.DisplayName, Mode=OneWay}" Style="{ThemeResource TitleTextBlockStyle}"/>
                                <TextBlock Text="{x:Bind Contact.Org, Converter={StaticResource StringArrayStringConverter}, Mode=OneWay}" 
                       Visibility="{Binding RelativeSource={RelativeSource Self}, Path=Text, Converter={StaticResource ValueVisibilityConverter} }"
                       Style="{ThemeResource BodyTextBlockStyle}"/>
                            </StackPanel>
                        </StackPanel>
                    </Grid>


                    <Grid Grid.Row="1" x:Name="gridNickname" Margin="0,0,0,20" Visibility="{x:Bind NicknameVisibility, Mode=OneWay}">
                        <StackPanel>
                            <TextBlock x:Uid="TextBlockKnownAs" Text="XX Known as" Style="{ThemeResource SubtitleTextBlockStyle}"/>
                            <ListView ItemsSource="{x:Bind Contact.Nickname, Mode=OneWay}" SelectionMode="None" VerticalAlignment="Stretch">
                                <ListView.ItemTemplate>
                                    <DataTemplate x:DataType="x:String">
                                        <TextBlock Text="{Binding}" Margin="0,0,10,2" VerticalAlignment="Center" />
                                    </DataTemplate>
                                </ListView.ItemTemplate>
                            </ListView>
                        </StackPanel>
                       
                    </Grid>
                    
                    <Grid Grid.Row="2" x:Name="gridEmails" Margin="0,0,0,20" Visibility="{x:Bind EmailVisibility, Mode=OneWay}">
                        <StackPanel>
                            <TextBlock Text="Emails" Style="{ThemeResource SubtitleTextBlockStyle}"/>
                            <ListView ItemsSource="{x:Bind Contact.Email, Mode=OneWay}" SelectionMode="None" VerticalAlignment="Stretch">
                                <ListView.ItemTemplate>
                                    <DataTemplate x:DataType="contactsdata:EmailDefinition">
                                        <StackPanel Orientation="Horizontal" >
                                            <Image Source="{x:Bind LocationType, Converter={StaticResource LocationToImageConverter}, Mode=OneWay}" Width="18" Margin="0,0,10,0" />
                                            <TextBlock Text="{x:Bind EmailAddress, Mode=OneWay}" Margin="0,0,10,2" VerticalAlignment="Center" />
                                            <Button x:Name="buttonEmail" Background="Transparent" BorderBrush="Transparent" 
                                        Padding="0" ClickMode="Press"
                                        Tag="{x:Bind EmailAddress, Mode=OneWay}" Tapped="_buttonEmail_Tapped">
                                                <Button.Content>
                                                    <SymbolIcon Symbol="Mail" Foreground="{ThemeResource HyperlinkForegroundThemeBrush}"/>
                                                </Button.Content>
                                            </Button>
                                        </StackPanel>
                                    </DataTemplate>
                                </ListView.ItemTemplate>
                            </ListView>
                        </StackPanel>
                    </Grid>

                    <Grid Grid.Row="3" x:Name="gridTelephone" Margin="0,0,0,20" Visibility="{x:Bind TelephoneVisibility, Mode=OneWay}">
                        <StackPanel>
                            <TextBlock x:Uid="TextBlockTelephone" Text="XX Telephone" Style="{ThemeResource SubtitleTextBlockStyle}"/>
                            <ListView ItemsSource="{x:Bind Contact.Tel, Mode=OneWay}" SelectionMode="None" VerticalAlignment="Stretch">
                                <ListView.ItemTemplate>
                                    <DataTemplate x:DataType="contactsdata:TelDefinition">
                                        <StackPanel Orientation="Horizontal">
                                            <Image Source="{x:Bind LocationType, Converter={StaticResource LocationToImageConverter}, Mode=OneWay}" Width="18" Margin="0,0,10,0"/>
                                            <TextBlock Text="{x:Bind TelephoneNumber, Mode=OneWay}" Margin="0,0,0,2" />
                                        </StackPanel>
                                    </DataTemplate>
                                </ListView.ItemTemplate>
                            </ListView>
                        </StackPanel>
                    </Grid>

                    <Grid Grid.Row="4" x:Name="gridAddresses" Margin="0,0,0,20" Visibility="{x:Bind AddressVisibility, Mode=OneWay}">
                        <StackPanel>
                            <TextBlock x:Uid="TextBlockAddress" Text="XX Addresses" Style="{ThemeResource SubtitleTextBlockStyle}"/>
                            <ListView ItemsSource="{x:Bind Contact.Adr, Mode=OneWay}" SelectionMode="None" VerticalAlignment="Stretch">
                                <ListView.ItemTemplate>
                                    <DataTemplate x:DataType="contactsdata:AdrDefinition">
                                        <StackPanel Orientation="Horizontal" Margin="0,10,0,0">
                                            <Image Source="{x:Bind LocationType, Converter={StaticResource LocationToImageConverter}, Mode=OneWay}" Width="18" VerticalAlignment="Top" Margin="0,5,10,0"/>
                                            <StackPanel>
                                                <TextBlock Text="{x:Bind StreetAddress, Mode=OneWay}" Margin="0,0,0,2" Visibility="{Binding RelativeSource={RelativeSource Self}, Path=Text, Converter={StaticResource ValueVisibilityConverter} }"/>
                                                <TextBlock Text="{x:Bind ExtendedAddress, Mode=OneWay}" Margin="0,0,0,2" Visibility="{Binding RelativeSource={RelativeSource Self}, Path=Text, Converter={StaticResource ValueVisibilityConverter} }"/>
                                                <TextBlock Text="{x:Bind Locality, Mode=OneWay}" Margin="0,0,0,2" Visibility="{Binding RelativeSource={RelativeSource Self}, Path=Text, Converter={StaticResource ValueVisibilityConverter} }"/>
                                                <TextBlock Text="{x:Bind Region, Mode=OneWay}" Margin="0,0,0,2" Visibility="{Binding RelativeSource={RelativeSource Self}, Path=Text, Converter={StaticResource ValueVisibilityConverter} }"/>
                                                <TextBlock Text="{x:Bind PoBox, Mode=OneWay}" Margin="0,0,0,2" Visibility="{Binding RelativeSource={RelativeSource Self}, Path=Text, Converter={StaticResource ValueVisibilityConverter} }"/>
                                                <TextBlock Text="{x:Bind Country, Mode=OneWay}" Margin="0,0,0,2" Visibility="{Binding RelativeSource={RelativeSource Self}, Path=Text, Converter={StaticResource ValueVisibilityConverter} }"/>
                                                <TextBlock Text="{x:Bind PostCode, Mode=OneWay}" Margin="0,0,0,2" Visibility="{Binding RelativeSource={RelativeSource Self}, Path=Text, Converter={StaticResource ValueVisibilityConverter} }"/>
                                            </StackPanel>
                                        </StackPanel>
                                    </DataTemplate>
                                </ListView.ItemTemplate>
                            </ListView>
                        </StackPanel>
                    </Grid>

                    <Grid Grid.Row="5" x:Name="gridNote" Margin="0,0,0,20" Visibility="{x:Bind Path=NoteVisibility, Mode=OneWay}">
                        <StackPanel>
                            <TextBlock x:Uid="TextBlockNote" Text="XX Note" Style="{ThemeResource SubtitleTextBlockStyle}"/>
                            <TextBlock Text="{x:Bind Contact.Note, Mode=OneWay}" HorizontalAlignment="Stretch"/>
                        </StackPanel>
                    </Grid>

                    <Grid Grid.Row="6" x:Name="gridWebPages" Margin="0,0,0,20" Visibility="{x:Bind URLVisibility, Mode=OneWay}">
                        <StackPanel>
                            <TextBlock Text="Webpages" Style="{ThemeResource SubtitleTextBlockStyle}"/>
                            <HyperlinkButton x:Name="webpageButton" NavigateUri="{x:Bind Contact.Uri, Mode=OneWay}" Content="{x:Bind Contact.UrlString, Mode=OneWay}"  />
                        </StackPanel>
                    </Grid>

                </Grid>
            </ScrollViewer>
        </Grid>
    </Border>
</Page>
