<?xml version="1.0" encoding="utf-8"?>
<ResourceDictionary
    x:Class="was.touchcopy.features.messaging.ux.MessageContentPollDataTemplate"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:converters="using:was.touchcopy.features.messaging.converters"
    xmlns:messaging="using:was.touchcopy.features.messaging"
    xmlns:local="using:was.touchcopy.features.messaging.ux">

    <converters:PollOptionVoteWeightToOpacityConverter x:Key="PollOptionVoteWeightToOpacityConverter" />
    <converters:PollOptionVoteWeightToWidthConverter x:Key="PollOptionVoteWeightToWidthConverter" />
    <converters:MessageContentToPollOptionsConverter x:Key="MessageContentToPollOptionsConverter" />
    <converters:MessageContentToPollTitleConverter x:Key="MessageContentToPollTitleConverter" />
    <converters:MessageContentToPollVoteCountStringConverter x:Key="MessageContentToPollVoteCountStringConverter" />
    
    <DataTemplate x:Key="MessageContentPollDataTemplate" x:DataType="messaging:MessageContent">
        <Grid HorizontalAlignment="Left" MaxWidth="360" Margin="-10,0">
            <StackPanel>
                <TextBlock Margin="12,0,12,0" Style="{ThemeResource BodyStrongTextBlockStyle}">
                    <Run Text="{x:Bind Converter={StaticResource MessageContentToPollTitleConverter}}" />
                    <Run Text=" | " Foreground="{ThemeResource TextFillColorDisabled}" />
                    <Run Text="{x:Bind Converter={StaticResource MessageContentToPollVoteCountStringConverter}}" Foreground="{ThemeResource TextFillColorDisabled}" />
                </TextBlock>
                <ItemsRepeater ItemsSource="{x:Bind Converter={StaticResource MessageContentToPollOptionsConverter}}">
                    <ItemsRepeater.ItemTemplate>
                        <DataTemplate x:DataType="messaging:MessagePollOption">
                            <Grid Margin="0,8,0,0" HorizontalAlignment="Left">
                                <Border Background="{ThemeResource TextFillColorInverse}" CornerRadius="8" Width="{x:Bind VoteWeight, Converter={StaticResource PollOptionVoteWeightToWidthConverter}, ConverterParameter='360'}" Opacity="{x:Bind VoteWeight, Converter={StaticResource PollOptionVoteWeightToOpacityConverter}}" />
                                <Grid Padding="12,12" ColumnSpacing="24">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*"/>
                                        <ColumnDefinition Width="Auto"/>
                                    </Grid.ColumnDefinitions>
                                    <TextBlock Text="{x:Bind Text}" TextWrapping="Wrap" Style="{ThemeResource BodyTextBlockStyle}" VerticalAlignment="Center" />
                                    <TextBlock Grid.Column="1" Text="{x:Bind VoteCount}" Style="{ThemeResource BodyStrongTextBlockStyle}" VerticalAlignment="Center" />
                                </Grid>
                            </Grid>
                        </DataTemplate>
                    </ItemsRepeater.ItemTemplate>
                </ItemsRepeater>
            </StackPanel>
        </Grid>
    </DataTemplate>
</ResourceDictionary>
