<!--
	Copyright (c) Microsoft. All rights reserved.
-->

<UserControl
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
	xmlns:mox="using:MOX"
	xmlns:core="using:Office.UI.Xaml.Core"
	TabNavigation="Cycle">
	<UserControl.Resources>
		<ResourceDictionary>
			<ResourceDictionary.ThemeDictionaries>
				<ResourceDictionary x:Key="Default">
					<Thickness x:Key="HighContrastBorderThickness" Right="0" />
					</ResourceDictionary>
					<ResourceDictionary x:Key="HighContrast">
					<Thickness x:Key="HighContrastBorderThickness" Right="1" />
				</ResourceDictionary>
			</ResourceDictionary.ThemeDictionaries>
		</ResourceDictionary>
		<Style x:Key="SearchTermStyle" TargetType="TextBlock" BasedOn="{StaticResource MsoTextBlockStandardSemilight}">
			<Setter Property="Foreground" Value="{CustomResource :mso_brush:3015}" />
			<Setter Property="TextTrimming" Value="CharacterEllipsis" />
			<Setter Property="VerticalAlignment" Value="Stretch" />
			<Setter Property="Margin" Value="16,0,16,0" />
		</Style>
		<!-- Header Styles -->
		<Style x:Key="GroupHeaderStyle" TargetType="Grid">
			<Setter Property="Margin" Value="16,0,0,0" />
		</Style>
		<Style x:Key="GroupHeaderTextStyle" TargetType="TextBlock" BasedOn="{StaticResource MsoTextBlockSmall}">
			<Setter Property="Foreground" Value="{CustomResource :mso_brush:3014}" />
			<Setter Property="TextTrimming" Value="WordEllipsis" />
			<Setter Property="Margin" Value="0,8,0,-4" /> <!-- For baseline alignment -->
		</Style>
		<!-- Hit styles -->
		<Style x:Key="SearchHitImageStyle" TargetType="Image">
			<Setter Property="HorizontalAlignment" Value="Left" />
			<Setter Property="VerticalAlignment" Value="Bottom" />
			<Setter Property="Margin" Value="0,0,0,0" />
		</Style>			
		<Style x:Key="SearchHitTitleTextStyle" TargetType="TextBlock" BasedOn="{StaticResource MsoTextBlockStandardSemilight}">
			<Setter	Property="Foreground" Value="{CustomResource :mso_brush:3015}" />
			<Setter Property="VerticalAlignment" Value="Bottom" />
			<Setter Property="Margin" Value="0,0,0,-2" /> <!-- For baseline alignment -->
		</Style>
		<Style x:Key="SearchHitURLTextStyle" TargetType="TextBlock" BasedOn="{StaticResource MsoTextBlockSmall}">
			<Setter	Property="Foreground" Value="{CustomResource :mso_brush:3015}" />
			<Setter Property="VerticalAlignment" Value="Bottom" />
			<Setter Property="Margin" Value="0,0,0,2" /> <!-- For baseline alignment -->
		</Style>
		<!-- Searching Animation -->
		<Storyboard x:Name="SearchingAnimationStoryboard">
			<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="SearchingProgressBar">
				<DiscreteObjectKeyFrame KeyTime="0">
					<DiscreteObjectKeyFrame.Value>
						<Visibility>Visible</Visibility>
					</DiscreteObjectKeyFrame.Value>
				</DiscreteObjectKeyFrame>
			</ObjectAnimationUsingKeyFrames>
			<DoubleAnimation Storyboard.TargetName='SearchingProgressBar' Storyboard.TargetProperty='Opacity' To='1' Duration='0:0:1' />
		</Storyboard>
		<Storyboard x:Name="FinishedSearchingAnimationStoryboard">
			<DoubleAnimation Storyboard.TargetName='SearchingProgressBar' Storyboard.TargetProperty='Opacity' To='0' Duration='0:0:1' />
			<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)"
				Storyboard.TargetName="SearchingProgressBar">
				<DiscreteObjectKeyFrame KeyTime="0:0:1">
					<DiscreteObjectKeyFrame.Value>
						<Visibility>Collapsed</Visibility>
					</DiscreteObjectKeyFrame.Value>
				</DiscreteObjectKeyFrame>
			</ObjectAnimationUsingKeyFrames>
		</Storyboard>
		<!-- Scope button styles -->
		<Style x:Key="ScopeButtonStyle" TargetType="TextBlock" BasedOn="{StaticResource MsoTextBlockSmall}">
			<Setter Property="Foreground" Value="{CustomResource :mso_brush:3014}" />
			<Setter Property="TextWrapping" Value="Wrap" />
			<Setter Property="Height" Value="Auto" />
			<Setter Property="Margin" Value="16,0,16,0" />
		</Style>
		<ControlTemplate x:Key="ScopeButtonTemplate" TargetType="RadioButton">
			<Border x:Name="ScopeButtonBackground" HorizontalAlignment="Stretch" Background="Transparent" BorderBrush="Transparent" BorderThickness="1">
				<VisualStateManager.VisualStateGroups>
					<VisualStateGroup x:Name="CheckStates">
						<VisualState x:Name="Checked">
							<Storyboard>
								<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ScopeButtonBackground" Storyboard.TargetProperty="Background">
									<DiscreteObjectKeyFrame Value="{CustomResource :mso_brush:3017}" KeyTime="0" />
								</ObjectAnimationUsingKeyFrames>
								<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ScopeButtonBackground" Storyboard.TargetProperty="BorderBrush">
									<DiscreteObjectKeyFrame Value="{CustomResource :mso_brush:3018}" KeyTime="0" />
								</ObjectAnimationUsingKeyFrames>
							</Storyboard>
						</VisualState>
						<VisualState x:Name="Unchecked" />
						<VisualState x:Name="Indeterminate" />
					</VisualStateGroup>
	 				<VisualStateGroup x:Name="FocusStates">
						<VisualState x:Name="Focused">
							<Storyboard>
								<DoubleAnimation Storyboard.TargetName="FocusVisualWhite"
												 Storyboard.TargetProperty="Opacity"
												 To="1"
												 Duration="0" />
								<DoubleAnimation Storyboard.TargetName="FocusVisualBlack"
												 Storyboard.TargetProperty="Opacity"
												 To="1"
												 Duration="0" />
							</Storyboard>
						</VisualState>
						<VisualState x:Name="Unfocused" />
						<VisualState x:Name="PointerFocused" />
					</VisualStateGroup>
				</VisualStateManager.VisualStateGroups>
				<Grid HorizontalAlignment="Stretch">
					<TextBlock x:Name="textBlock" Text="{TemplateBinding Content}"
						Style="{StaticResource ScopeButtonStyle}"
						VerticalAlignment="Center" />
					<Rectangle x:Name="FocusVisualWhite"
						IsHitTestVisible="False"
						Stroke="{StaticResource FocusVisualWhiteStrokeThemeBrush}"
						StrokeEndLineCap="Square"
						StrokeDashArray="1,1"
						Opacity="0"
						StrokeDashOffset="1.5"
						HorizontalAlignment="Stretch"
						VerticalAlignment="Stretch" />
					<Rectangle x:Name="FocusVisualBlack"
						IsHitTestVisible="False"
						Stroke="{StaticResource FocusVisualBlackStrokeThemeBrush}"
						StrokeEndLineCap="Square"
						StrokeDashArray="1,1"
						Opacity="0"
						StrokeDashOffset="0.5"
						HorizontalAlignment="Stretch"
						VerticalAlignment="Stretch" />
				</Grid>
			</Border>
		</ControlTemplate>
		<ControlTemplate x:Key="SearchHitButtonTemplate" TargetType="Button">
			<Grid>
				<VisualStateManager.VisualStateGroups>
					<VisualStateGroup x:Name="CommonStates">
						<VisualState x:Name="Normal" />
						<VisualState x:Name="PointerOver">
							<Storyboard>
								<ObjectAnimationUsingKeyFrames Storyboard.TargetName="Border" Storyboard.TargetProperty="Background">
									<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ButtonPointerOverBackgroundThemeBrush}" />
								</ObjectAnimationUsingKeyFrames>
								<DoubleAnimation Storyboard.TargetName="FocusVisualWhite"
												 Storyboard.TargetProperty="Opacity"
												 To="1"
												 Duration="0" />
								<DoubleAnimation Storyboard.TargetName="FocusVisualBlack"
												 Storyboard.TargetProperty="Opacity"
												 To="1"
												 Duration="0" />
							</Storyboard>
						</VisualState>
						<VisualState x:Name="Pressed">
							<Storyboard>
								<ObjectAnimationUsingKeyFrames Storyboard.TargetName="Border" Storyboard.TargetProperty="Background">
									<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ButtonPressedBackgroundThemeBrush}" />
								</ObjectAnimationUsingKeyFrames>
							</Storyboard>
						</VisualState>
						<VisualState x:Name="Disabled">
							<Storyboard>
								<DoubleAnimation Storyboard.TargetName="ContentPresenter"
												 Storyboard.TargetProperty="Opacity"
												 To="0.25"
												 Duration="0" />
							</Storyboard>
						</VisualState>
					</VisualStateGroup>
					<VisualStateGroup x:Name="FocusStates">
						<VisualState x:Name="Focused">
							<Storyboard>
								<DoubleAnimation Storyboard.TargetName="FocusVisualWhite"
												 Storyboard.TargetProperty="Opacity"
												 To="1"
												 Duration="0" />
								<DoubleAnimation Storyboard.TargetName="FocusVisualBlack"
												 Storyboard.TargetProperty="Opacity"
												 To="1"
												 Duration="0" />
							</Storyboard>
						</VisualState>
						<VisualState x:Name="Unfocused" />
						<VisualState x:Name="PointerFocused" />
					</VisualStateGroup>
				</VisualStateManager.VisualStateGroups>
				<Border x:Name="Border"
							BorderBrush="{TemplateBinding BorderBrush}"
							BorderThickness="{TemplateBinding BorderThickness}" >
					<ContentPresenter x:Name="ContentPresenter" Margin="3" />
				</Border>
				<Rectangle x:Name="FocusVisualWhite"
							IsHitTestVisible="False"
							Stroke="{StaticResource FocusVisualWhiteStrokeThemeBrush}"
							StrokeEndLineCap="Square"
							StrokeDashArray="1,1"
							Opacity="0"
							StrokeDashOffset="1.5" />
				<Rectangle x:Name="FocusVisualBlack"
							IsHitTestVisible="False"		
							Stroke="{StaticResource FocusVisualBlackStrokeThemeBrush}"
							StrokeEndLineCap="Square"
							StrokeDashArray="1,1"
							Opacity="0"
							StrokeDashOffset="0.5" />
			</Grid>
		</ControlTemplate>
		<Style x:Key="SearchHitContainerStyle" TargetType="ListViewItem">
			<Setter Property="Margin" Value="0" />
			<Setter Property="Template">
				<Setter.Value>
					<ControlTemplate TargetType="ListViewItem">
						<Grid HorizontalAlignment="Stretch">
							<VisualStateManager.VisualStateGroups>
								<VisualStateGroup x:Name="SelectionStates">
									<VisualState x:Name="Unselected">
										<Storyboard >
											<DoubleAnimation Duration="0:0:0.1" To="0"
													Storyboard.TargetProperty="(UIElement.Opacity)"
													Storyboard.TargetName="ContainerBackground" />
											<ObjectAnimationUsingKeyFrames
													Storyboard.TargetProperty="(UIElement.Visibility)"
													Storyboard.TargetName="ButtonPanel">
												<DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed" />
											</ObjectAnimationUsingKeyFrames>
										</Storyboard>
									</VisualState>
									<VisualState x:Name="Selected">
										<Storyboard >
											<DoubleAnimation Duration="0:0:0.1" To="1"
													Storyboard.TargetProperty="(UIElement.Opacity)"
													Storyboard.TargetName="ContainerBackground" />
											<ObjectAnimationUsingKeyFrames
													Storyboard.TargetProperty="(UIElement.Visibility)"
													Storyboard.TargetName="ButtonPanel">
												<DiscreteObjectKeyFrame KeyTime="0" Value="Visible" />
											</ObjectAnimationUsingKeyFrames>
										</Storyboard>
									</VisualState>
									<VisualState x:Name="SelectedUnfocused">
										<Storyboard >
											<DoubleAnimation Duration="0:0:0.1" To="1"
													Storyboard.TargetProperty="(UIElement.Opacity)"
													Storyboard.TargetName="ContainerBackground" />
											<ObjectAnimationUsingKeyFrames
													Storyboard.TargetProperty="(UIElement.Visibility)"
													Storyboard.TargetName="ButtonPanel">
												<DiscreteObjectKeyFrame KeyTime="0" Value="Visible" />
											</ObjectAnimationUsingKeyFrames>
										</Storyboard>
									</VisualState>
								</VisualStateGroup>
								<VisualStateGroup x:Name="FocusStates">
									<VisualState x:Name="Unfocused" />
									<VisualState x:Name="Focused">
										<Storyboard>
											<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="FocusVisualWhite">
												<DiscreteObjectKeyFrame KeyTime="0" Value="Visible" />
											</ObjectAnimationUsingKeyFrames>
											<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="FocusVisualBlack">
												<DiscreteObjectKeyFrame KeyTime="0" Value="Visible" />
											</ObjectAnimationUsingKeyFrames>
										</Storyboard>
									</VisualState>
									<VisualState x:Name="PointerFocused" />
								</VisualStateGroup>
							</VisualStateManager.VisualStateGroups>
							<Border x:Name="ContainerBackground"
									Background="{CustomResource :mso_brush:3012}"
									Margin="0" Opacity="0" BorderThickness="2"
									BorderBrush="{CustomResource :mso_brush:3013}" />
							<Grid>
								<Grid.ColumnDefinitions>
									<ColumnDefinition Width="*" />
									<ColumnDefinition Width="Auto" />
								</Grid.ColumnDefinitions>
								<ContentPresenter x:Name="contentPresenter" HorizontalAlignment="Stretch" />
								<Grid x:Name="ButtonPanel" Grid.Column="1"
										Margin="0,0,4,0" Width="80" Height="40"
										Visibility="Collapsed"
										Background="{CustomResource :mso_brush:3012}">
									<Grid.ColumnDefinitions>
										<ColumnDefinition Width="40" />
										<ColumnDefinition Width="40" />
									</Grid.ColumnDefinitions>
									<Button x:Name="LeftButton" Command="{Binding PrevCommand}" Grid.Column="0"
											AutomationProperties.Name="{CustomResource :appstring:0xB16C17EFL}"
											AutomationProperties.AutomationId="PreviousResultButton"
											HorizontalAlignment="Center" VerticalAlignment="Center"
											Template="{StaticResource SearchHitButtonTemplate}">
										<Image Stretch="None">
											<Image.Source>
												<mox:SmartImageSource SourcePath="{Binding PrevIconPath}" />
											</Image.Source>
										</Image>
									</Button>
									<Button x:Name="RightButton" Command="{Binding NextCommand}" Grid.Column="1"
											AutomationProperties.Name="{CustomResource :appstring:0x6E5F7C4BL}"
											AutomationProperties.AutomationId="NextResultButton"
											HorizontalAlignment="Center" VerticalAlignment="Center"
											Template="{StaticResource SearchHitButtonTemplate}" >
										<Image Stretch="None">
											<Image.Source>
												<mox:SmartImageSource SourcePath="{Binding NextIconPath}" />
											</Image.Source>
										</Image>
									</Button>
								</Grid>
							</Grid>
							<Rectangle x:Name="FocusVisualWhite" Margin="3,3,3,3" Stroke="{StaticResource FocusVisualWhiteStrokeThemeBrush}" StrokeDashArray="1,1" StrokeDashOffset="1.5" StrokeEndLineCap="Square" IsHitTestVisible="False" Visibility="Collapsed" />
							<Rectangle x:Name="FocusVisualBlack" Margin="3,3,3,3" Stroke="{StaticResource FocusVisualBlackStrokeThemeBrush}" StrokeDashArray="1,1" StrokeDashOffset="0.5" StrokeEndLineCap="Square" IsHitTestVisible="False" Visibility="Collapsed" />
						</Grid>
					</ControlTemplate>
				</Setter.Value>
			</Setter>
		</Style>
		<!-- FUTURE: replace this with a Style Template chooser -->
		<core:EnumToVisibility x:Key="SearchHitNilVisibility" Value="0" IsInvert="False" />
		<core:EnumToVisibility x:Key="SearchHitPageVisibility" Value="1" IsInvert="False" />
		<core:EnumToVisibility x:Key="SearchHitNotebookVisibility" Value="2" IsInvert="False" />
		<core:EnumToVisibility x:Key="SearchHitSectionVisibility" Value="3" IsInvert="False" />
		<DataTemplate x:Key="SearchHitItemTemplate">
			<Grid x:Name="SearchHitItem" Height="48">
				<Grid Margin="20,0,0,0">
					<Grid.ColumnDefinitions>
						<ColumnDefinition Width="20" />
						<ColumnDefinition Width="*" />
					</Grid.ColumnDefinitions>
					<Grid.RowDefinitions>
						<RowDefinition Height="20"/>
						<RowDefinition Height="20"/>
					</Grid.RowDefinitions>
					<Grid x:Name="PageIcon" Height="14" Width="11" Grid.Row="0" Grid.Column="0"
						HorizontalAlignment="Left" VerticalAlignment="Bottom"
						Visibility="{Binding SearchHitType, Converter={StaticResource SearchHitPageVisibility}}">
						<Path Data="F1M300,388L300,402L311,402L311,392L307,392L307,388z" Fill="{CustomResource :mso_brush:3016}" Height="14" Width="11" Stretch="Fill" />
						<Path Data="F1M309,389L308,389L308,390L308,391L310,391L310,390L309,390z" Fill="{CustomResource :mso_brush:3016}" Height="2" Width="2" Margin="8,1,0,0" Stretch="Fill" />
					</Grid>
					<Grid x:Name="NotebookIcon" Height="14" Width="14"
						HorizontalAlignment="Left" VerticalAlignment="Bottom"
						Visibility="{Binding SearchHitType, Converter={StaticResource SearchHitNotebookVisibility}}">
						<Path Data="F1M676,317L676,326L676,329L676,331L687,331L687,328L687,325L687,323L687,319L687,317z" Fill="{CustomResource :mso_brush:3016}" Stretch="Fill" Margin="0,0,3,0"/>
						<Path Data="F1M684,323L679,323L679,320L684,320z" Fill="White" Height="3" Stretch="Fill" Margin="3,3,6,0" VerticalAlignment="Top"/>
						<Path Data="F1M690,322L688,322L688,318L690,318z" Fill="{CustomResource :mso_brush:3016}" Height="4" Stretch="Fill" Width="2" HorizontalAlignment="Right" Margin="0,1,0,0" VerticalAlignment="Top"/>
						<Path Data="F1M690,327L688,327L688,323L690,323z" Fill="{CustomResource :mso_brush:3016}" Stretch="Fill" Width="2" HorizontalAlignment="Right" Margin="0,6,0,4"/>
					</Grid>
					<Grid x:Name="SectionIcon" Height="17" Width="5"
							HorizontalAlignment="Left" VerticalAlignment="Bottom"
							Visibility="{Binding SearchHitType, Converter={StaticResource SearchHitSectionVisibility}}">
						<Path Data="F1M682,448.75L687,451.464L687,434L682,436.036z" Fill="{Binding TabColor}" Stretch="Fill" Height="17.464" Width="5"/>
					</Grid>
					<TextBlock x:Name="SearchHitTitle" Grid.Column="1" Grid.Row="0" Grid.ColumnSpan="2"
						Text="{Binding Title}" TextTrimming="CharacterEllipsis" Style="{StaticResource SearchHitTitleTextStyle}" />
					<TextBlock x:Name="SearchHitUrl" Grid.Column="1" Grid.Row="1" Grid.ColumnSpan="2"
						Text="{Binding Url}" TextTrimming="CharacterEllipsis" Style="{StaticResource SearchHitURLTextStyle}" />
				</Grid>
			</Grid>
		</DataTemplate>
	</UserControl.Resources>
	<Border BorderBrush="{CustomResource :mso_brush:3011}"
		BorderThickness="{StaticResource HighContrastBorderThickness}">
		<mox:AccessiblePaneGrid x:Name="LayoutRoot"
				Background="{CustomResource :mso_brush:3010}"
				AutomationProperties.Name="{CustomResource :appstring:0x6F257D43L}"
				AutomationProperties.AutomationId="SearchPane" HorizontalAlignment="Stretch">
			<mox:AccessiblePaneGrid.RowDefinitions>
				<RowDefinition Height="48" />
				<RowDefinition Height="60" />
				<RowDefinition Height="*" />
			</mox:AccessiblePaneGrid.RowDefinitions>
			<Grid x:Name="Header" Grid.Row="0">
				<Grid.RowDefinitions>
					<RowDefinition />
					<RowDefinition />
				</Grid.RowDefinitions>
				<ProgressBar Grid.Row="0" x:Name="SearchingProgressBar" Opacity="0"
						IsIndeterminate="True" IsHitTestVisible="False" Margin="4,0,4,0" VerticalAlignment="Top" />
				<TextBlock Grid.Row="1" x:Name="SearchTerm" Style="{StaticResource SearchTermStyle}"
					Text="{Binding SearchTerm}"/>
			</Grid>
			<Grid HorizontalAlignment="Stretch" Grid.Row="1" Margin="0,0,0,12">
				<Grid.RowDefinitions>
					<RowDefinition />
					<RowDefinition />
				</Grid.RowDefinitions>
				<RadioButton x:Name="AllNotebooksScopeButton"
					Template="{StaticResource ScopeButtonTemplate}"
					Content="{CustomResource :appstring:0xFA0E1E4CL}"
					Height="24"
					HorizontalAlignment="Stretch"
					VerticalAlignment="Center"
					KeyUp="ScopeButton_KeyUp"
					IsChecked="{Binding IsAllNotebooksScope,Mode=TwoWay}"
					TabIndex="1" />
				<RadioButton x:Name="CurrentNotebookScopeButton"
					Grid.Row="1"
					Template="{StaticResource ScopeButtonTemplate}"
					Content="{CustomResource :appstring:0x1C6F71EDL}"
					Height="24"
					HorizontalAlignment="Stretch"
					VerticalAlignment="Center"
					KeyUp="ScopeButton_KeyUp"
					IsChecked="{Binding IsCurrentNotebookScope, Mode=TwoWay}"
					TabIndex="2" />
			</Grid>
			<ListView x:Name="ResultsGroups" Grid.Row="2"
						ScrollViewer.HorizontalScrollBarVisibility="Disabled" SelectionMode="Single" IsEnabled="True"
						ItemsSource="{Binding SearchResultGroupsCollectionView}"
						ItemContainerStyle="{StaticResource SearchHitContainerStyle}"
						ItemTemplate="{StaticResource SearchHitItemTemplate}"
						TabIndex="3">
				<ListView.ItemsPanel>
					<ItemsPanelTemplate>
						<VirtualizingStackPanel />
					</ItemsPanelTemplate>
				</ListView.ItemsPanel>
				<ListView.GroupStyle>
					<GroupStyle>
						<GroupStyle.HeaderTemplate>
							<DataTemplate>
								<Grid Style="{StaticResource GroupHeaderStyle}">
									<TextBlock Height="24" Style="{StaticResource GroupHeaderTextStyle}" Text="{Binding GroupName}" VerticalAlignment="Bottom" />
								</Grid>
							</DataTemplate>
						</GroupStyle.HeaderTemplate>
					</GroupStyle>
				</ListView.GroupStyle>
			</ListView>
		</mox:AccessiblePaneGrid>
	</Border>
</UserControl>
