<UserControl x:Class="Hiyoko.Forms.MainFormTimelinePanel" x:Name="this"
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:c="clr-namespace:Hiyoko"
	xmlns:local="clr-namespace:Hiyoko.Forms">
	<!--- Resources -->
	<UserControl.Resources>
		<ResourceDictionary>
			<ResourceDictionary.MergedDictionaries>
				<ResourceDictionary Source="/Hiyoko;component/forms/generic.xaml" />
			</ResourceDictionary.MergedDictionaries>
			
			<local:AccountToProfileBackgroundImageConverter x:Key="AccountToProfileBackgroundImageConverter" />
			
			<ContextMenu x:Key="StatusEditToolMenu">
				<MenuItem Header="URL短縮(_S)" Command="c:HiyokoCommands.ShortenUrl" />
				<MenuItem Header="画像をアップロード(_U)..." Command="c:HiyokoCommands.UploadImage" />
			</ContextMenu>
			
			<SolidColorBrush x:Key="StatusCountRemainsFewForeground" Color="DarkRed" />
			<SolidColorBrush x:Key="StatusCountRemainsOverForeground" Color="Red" />
			<SolidColorBrush x:Key="StatusCountRemainsForeground" Color="Gray" />
			
			<ControlTemplate x:Key="StatusEditTemplate" TargetType="{x:Type TextBox}">
				<Border Name="Border" BorderBrush="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"
					BorderThickness="1" CornerRadius="4" Background="{TemplateBinding Background}">
					<Grid>
						<Grid.ColumnDefinitions>
							<ColumnDefinition Width="*" />
							<ColumnDefinition Width="auto" />
						</Grid.ColumnDefinitions>
						<Viewbox Grid.Column="1" Margin="2" Stretch="Uniform">
							<TextBlock Name="statusEditCount" FontWeight="UltraBold" Text="{TemplateBinding Text, Converter={StaticResource TwitterStatusCountRemainsConverter}}"
								Foreground="{DynamicResource StatusCountRemainsForeground}"/>
						</Viewbox>
						<ScrollViewer Grid.Column="0" Margin="2" x:Name="PART_ContentHost"
							HorizontalScrollBarVisibility="Disabled"
							VerticalScrollBarVisibility="Auto"/>
					</Grid>
				</Border>
				<ControlTemplate.Triggers>
					<Trigger Property="IsReadOnly" Value="true">
						<Setter TargetName="Border" Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
						<Setter TargetName="Border" Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
					</Trigger>
					<MultiTrigger>
						<MultiTrigger.Conditions>
							<Condition Property="IsFocused" Value="true" />
							<Condition Property="IsReadOnly" Value="false" />
						</MultiTrigger.Conditions>
						<Setter TargetName="Border" Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
					</MultiTrigger>
					<DataTrigger Binding="{Binding Path=Text, RelativeSource={RelativeSource Self}, Converter={StaticResource TwitterStatusCountStateConverter}}" Value="1">
						<Setter TargetName="statusEditCount" Property="Foreground" Value="{DynamicResource StatusCountRemainsFewForeground}" />
					</DataTrigger>
					<DataTrigger Binding="{Binding Path=Text, RelativeSource={RelativeSource Self}, Converter={StaticResource TwitterStatusCountStateConverter}}" Value="2">
						<Setter TargetName="statusEditCount" Property="Foreground" Value="{DynamicResource StatusCountRemainsOverForeground}" />
					</DataTrigger>
				</ControlTemplate.Triggers>
			</ControlTemplate>
			
			<local:AutoCompleteCandidateTemplateSelector x:Key="AutoCompleteCandidateTemplateSelector" />
			
			<DataTemplate x:Key="AutoCompleteUserCandidateTemplate">
				<Grid>
					<Grid.ColumnDefinitions>
						<ColumnDefinition Width="auto" />
						<ColumnDefinition Width="*" />
						<ColumnDefinition Width="auto" />
					</Grid.ColumnDefinitions>
					<Image Grid.Column="0" Source="{Binding Path=Value.ProfileImageUrl}" Width="16" Height="16" VerticalAlignment="Center" />
					<TextBlock Grid.Column="1" Text="{Binding Path=Key}" Foreground="{DynamicResource ControlTextBrush}" VerticalAlignment="Center" />
					<TextBlock Grid.Column="2" Margin="16,0,0,0" Text="{Binding Path=Value.Name}"
						Foreground="{DynamicResource ControlTextBrush}" VerticalAlignment="Center" />
				</Grid>
			</DataTemplate>
			
			<DataTemplate x:Key="AutoCompleteHashCandidateTemplate">
				<Grid>
					<Grid.ColumnDefinitions>
						<ColumnDefinition Width="auto" />
						<ColumnDefinition Width="*" />
						<ColumnDefinition Width="auto" />
					</Grid.ColumnDefinitions>
					<Image Grid.Column="0" Source="{DynamicResource MessageIcon}" Width="16" Height="16" VerticalAlignment="Center" />
					<TextBlock Grid.Column="1" Text="{Binding Path=Key}" Foreground="{DynamicResource ControlTextBrush}" VerticalAlignment="Center" />
					<Image Grid.Column="2" Margin="16,0,0,0" Source="{DynamicResource DeleteIcon}" Width="16" Height="16" VerticalAlignment="Center"
						Cursor="Hand" MouseUp="AutoCompleteDeleteCandidate_MouseUp"/>
				</Grid>
			</DataTemplate>
			
			<DataTemplate x:Key="AutoCompleteCandidateTemplate">
				<Grid>
					<Grid.ColumnDefinitions>
						<ColumnDefinition Width="auto" MinWidth="16"/>
						<ColumnDefinition Width="*" />
					</Grid.ColumnDefinitions>
					<Grid.RowDefinitions>
						<RowDefinition Height="16" />
					</Grid.RowDefinitions>
					<TextBlock Grid.Column="1" Text="{Binding Path=Key}" Foreground="{DynamicResource ControlTextBrush}" VerticalAlignment="Center" />
				</Grid>
			</DataTemplate>
		</ResourceDictionary>
	</UserControl.Resources>
	
	<!--- Command -->
	<UserControl.CommandBindings>
		<CommandBinding Command="c:HiyokoCommands.OpenUrls" Executed="OpenUrlsTimeline_Executed" CanExecute="OpenUrlsTimeline_CanExecute"/>	
		<CommandBinding Command="c:HiyokoCommands.OpenStatus" Executed="OpenStatusTimeline_Executed" CanExecute="OpenStatusTimeline_CanExecute"/>	
		<CommandBinding Command="c:HiyokoCommands.OpenSite" Executed="OpenSiteTimeline_Executed" CanExecute="OpenSiteTimeline_CanExecute"/>	
		<CommandBinding Command="c:HiyokoCommands.OpenHome" Executed="OpenHomeTimeline_Executed" CanExecute="OpenHomeTimeline_CanExecute"/>	
		<CommandBinding Command="c:HiyokoCommands.CreateFavorite" Executed="CreateFavoriteTimeline_Executed" CanExecute="CreateFavoriteTimeline_CanExecute"/>	
		<CommandBinding Command="c:HiyokoCommands.CreateBlock" Executed="CreateBlockTimeline_Executed" CanExecute="CreateBlockTimeline_CanExecute"/>	
		<CommandBinding Command="c:HiyokoCommands.DestroyFriendship" Executed="DestroyFriendshipTimeline_Executed" CanExecute="DestroyFriendshipTimeline_CanExecute"/>
		<CommandBinding Command="c:HiyokoCommands.ShortenUrl" Executed="ShortenUrlStatusEdit_Executed" CanExecute="ShortenUrlStatusEdit_CanExecute"/>
		<CommandBinding Command="c:HiyokoCommands.UploadImage" Executed="UploadImageStatusEdit_Executed" CanExecute="UploadImageStatusEdit_CanExecute"/>
		<CommandBinding Command="c:HiyokoCommands.Refresh" Executed="Refresh_Executed" CanExecute="Refresh_CanExecute"/>
		<CommandBinding Command="c:HiyokoCommands.UpdateStatus" Executed="UpdateStatus_Executed" CanExecute="UpdateStatus_CanExecute"/>
		<CommandBinding Command="c:HiyokoCommands.NextPage" Executed="NextPage_Executed" CanExecute="NextPage_CanExecute"/>
		<CommandBinding Command="c:HiyokoCommands.PreviousPage" Executed="PreviousPage_Executed" CanExecute="PreviousPage_CanExecute"/>
		<CommandBinding Command="c:HiyokoCommands.FirstPage" Executed="FirstPage_Executed" CanExecute="FirstPage_CanExecute"/>
		<CommandBinding Command="c:HiyokoCommands.DestroyStatus" Executed="DestroyStatus_Executed" CanExecute="DestroyStatus_CanExecute"/>
		<CommandBinding Command="c:HiyokoCommands.ReplyTo" Executed="ReplyTo_Executed" CanExecute="ReplyTo_CanExecute"/>
		<CommandBinding Command="c:HiyokoCommands.ClearReplyTo" Executed="ClearReplyTo_Executed" CanExecute="ClearReplyTo_CanExecute"/>
		<CommandBinding Command="c:HiyokoCommands.Retweet" Executed="Retweet_Executed" CanExecute="Retweet_CanExecute"/>
		<CommandBinding Command="c:HiyokoCommands.OfficialRetweet" Executed="OfficialRetweet_Executed" CanExecute="OfficialRetweet_CanExecute"/>
	</UserControl.CommandBindings>
	
	<!--- Control -->
	<Grid>
		<Grid.RowDefinitions>
			<RowDefinition Height="64" Name="timelineStatusEditRow" />
			<RowDefinition Height="auto" />
			<RowDefinition Height="auto" />
			<RowDefinition Height="*" />
		</Grid.RowDefinitions>
		<Grid Grid.Row="0" Margin="2">
			<Grid.ColumnDefinitions>
				<ColumnDefinition Width="auto" />
				<ColumnDefinition Width="*" />
				<ColumnDefinition Width="auto" />
				<ColumnDefinition Width="auto" />
			</Grid.ColumnDefinitions>
			<Label Grid.Column="0" Margin="2" Target="{Binding ElementName=statusEdit}" VerticalAlignment="center">ステータス(_S)</Label>
			<TextBox
				local:AutoComplete.Popup="{Binding ElementName=statusEditPopup}"
				local:AutoComplete.CandidatesListBox="{Binding ElementName=statusEditCandidatesListBox}"
				local:AutoComplete.PopupOffset="-18,0"
				Grid.Column="1" Margin="2" x:Name="statusEdit"
				Background="{DynamicResource ControlBrush}"
				Foreground="{DynamicResource ControlTextBrush}"
				Template="{DynamicResource StatusEditTemplate}"
				TextWrapping="Wrap">
				<TextBox.CommandBindings>
					<CommandBinding Command="ComponentCommands.ScrollPageUp" Executed="ScrollPageUpTimeline_Executed" CanExecute="ScrollPageUpTimeline_CanExecute" />
					<CommandBinding Command="ComponentCommands.ScrollPageDown" Executed="ScrollPageDownTimeline_Executed" CanExecute="ScrollPageDownTimeline_CanExecute" />
				</TextBox.CommandBindings>
			</TextBox>
			<Popup Name="statusEditPopup" PopupAnimation="Slide" AllowsTransparency="true" StaysOpen="false">
				<Grid MaxHeight="{Binding ElementName=this, Path=ActualHeight}">
					<ListBox Name="statusEditCandidatesListBox" BorderThickness="0" Background="{DynamicResource ControlBrush}"
						HorizontalContentAlignment="Stretch" ItemTemplateSelector="{StaticResource AutoCompleteCandidateTemplateSelector}">
						<ListBox.ItemsPanel>
							<ItemsPanelTemplate>
								<VirtualizingStackPanel Orientation="Vertical" />
							</ItemsPanelTemplate>
						</ListBox.ItemsPanel>
					</ListBox>
				</Grid>
			</Popup>
			<Button Grid.Column="2" x:Name="statusEditToolButton" local:ButtonBehaviors.DropDownMenu="{StaticResource StatusEditToolMenu}" Margin="2">
				<AccessText Text="ツール(_T)" />
			</Button>
			<Button Grid.Column="4" Name="statusSubmitButton" Command="c:HiyokoCommands.UpdateStatus" Margin="2">
				<Grid>
					<Grid.ColumnDefinitions>
						<ColumnDefinition Width="auto" />
						<ColumnDefinition Width="auto" />
					</Grid.ColumnDefinitions>
					<Image Grid.Column="0" Source="{StaticResource PostIcon}" Width="15" Height="15" />
					<AccessText Grid.Column="1" Text="投稿" />
				</Grid>
			</Button>
		</Grid>
		
		<GridSplitter Height="3" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
		
		<Grid Grid.Row="2" DataContext="{Binding Path=StatusToReply, ElementName=this}">
			<Grid.ColumnDefinitions>
				<ColumnDefinition Width="auto" />
				<ColumnDefinition Width="*" />
				<ColumnDefinition Width="auto" />
			</Grid.ColumnDefinitions>
			<Label Grid.Column="0">返信先:</Label>
			<local:TwitterStatusViewer Grid.Column="1" Status="{Binding Path=StatusToReply, ElementName=this}"/>
			<Button Grid.Column="2" Command="c:HiyokoCommands.ClearReplyTo">クリア(_C)</Button>
			<Grid.Style>
				<Style TargetType="{x:Type Grid}">
					<Style.Triggers>
						<DataTrigger Binding="{Binding Path=Id}" Value="0">
							<Setter Property="Visibility" Value="Collapsed" />
						</DataTrigger>
					</Style.Triggers>
				</Style>
			</Grid.Style>
		</Grid>
		
		<Grid Grid.Row="3">
			<Grid.RowDefinitions>
				<RowDefinition Height="auto" />
				<RowDefinition Height="*" />
			</Grid.RowDefinitions>
			<Grid Grid.Row="0">
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="*" />
					<ColumnDefinition Width="auto" />
				</Grid.ColumnDefinitions>
				<Label Grid.Column="0" Target="{Binding ElementName=timelineList}">タイムライン(_L):</Label>
				<local:Pager Grid.Column="1" CurrentPage="{Binding Path=CurrentTimelinePage, ElementName=this}"/>
			</Grid>
			<ListBox Grid.Row="1" ItemsSource="{Binding IsAsync=true}" Name="timelineList" BorderThickness="0">
				<ListBox.CommandBindings>
					<CommandBinding Command="ApplicationCommands.Copy" Executed="CopyStatus_Executed" CanExecute="CopyStatus_CanExecute" />
				</ListBox.CommandBindings>
				<ListBox.ContextMenu>
					<ContextMenu>
						<MenuItem Header="含まれるUrlを開く(_U)" Command="c:HiyokoCommands.OpenUrls" />
						<MenuItem Header="ステータスを開く(_S)" Command="c:HiyokoCommands.OpenStatus" />
						<MenuItem Header="ユーザーのホームを開く(_H)" Command="c:HiyokoCommands.OpenHome" />
						<MenuItem Header="ユーザーのサイトを開く(_S)" Command="c:HiyokoCommands.OpenSite" />
						<Separator />
						<MenuItem Header="返信する(_R)" Command="c:HiyokoCommands.ReplyTo" />
						<MenuItem Header="Retweetする(_T)" Command="c:HiyokoCommands.Retweet" />
						<MenuItem Header="公式Retweetする(_O)" Command="c:HiyokoCommands.OfficialRetweet" />
						<Separator />
						<MenuItem Header="お気に入りに追加(_F)" Command="c:HiyokoCommands.CreateFavorite" />
						<MenuItem Header="ブロックに追加(_B)"  Command="c:HiyokoCommands.CreateBlock" />
						<MenuItem Header="フォローを削除(_I)"  Command="c:HiyokoCommands.DestroyFriendship" />
						<Separator />
						<MenuItem Header="ステータスをコピー(_C)" Command="ApplicationCommands.Copy" />
						<Separator />
						<MenuItem Header="ステータスを削除(_D)"  Command="c:HiyokoCommands.DestroyStatus"/>
					</ContextMenu>
				</ListBox.ContextMenu>
				<ListBox.Style>
					<Style TargetType="{x:Type ListBox}">
						<Style.Triggers>
							<DataTrigger Binding="{Binding Source={x:Static c:Program.Settings}, Path=IsUseProfileBackground}" Value="True">
								<Setter Property="Background" Value="{Binding Path=Account, ElementName=this, Converter={StaticResource AccountToProfileBackgroundImageConverter}}" />
							</DataTrigger>
							<DataTrigger Binding="{Binding Source={x:Static c:Program.Settings}, Path=IsUseProfileBackground}" Value="false">
								<Setter Property="Background" Value="#00000000" />
							</DataTrigger>
						</Style.Triggers>
						<Setter Property="HorizontalContentAlignment" Value="Stretch" />
						<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto" />
						<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Disabled" />
						<Setter Property="ScrollViewer.Margin" Value="0" />
						<Setter Property="ScrollViewer.Padding" Value="0" />
						<Setter Property="SelectionMode" Value="Extended" />
						<Setter Property="ItemsPanel">
							<Setter.Value>
								<ItemsPanelTemplate>
									<WrapPanel Orientation="Vertical" />
								</ItemsPanelTemplate>
							</Setter.Value>
						</Setter>
					</Style>
				</ListBox.Style>
				<ListBox.ItemTemplate>
					<DataTemplate>
						<local:TwitterStatusViewer x:Name="Item" Width="480" Status="{Binding}"/>
						<DataTemplate.Triggers>
							<DataTrigger Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBoxItem}}" Value="true">
								<Setter TargetName="Item" Property="Background" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />
							</DataTrigger>
						</DataTemplate.Triggers>
					</DataTemplate>
				</ListBox.ItemTemplate>
			</ListBox>
		</Grid>
	</Grid>
</UserControl>