<UserControl xmlns="https://github.com/avaloniaui"
             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:views="clr-namespace:LibationAvalonia.Views"
			 xmlns:controls="clr-namespace:LibationAvalonia.Controls"
             mc:Ignorable="d" d:DesignWidth="1560" d:DesignHeight="400"
             x:Class="LibationAvalonia.Views.ProductsDisplay">

	<Grid>

		<DataGrid
			Name="productsGrid"
			ClipboardCopyMode="IncludeHeader"
			GridLinesVisibility="All"
			AutoGenerateColumns="False"
			Items="{Binding GridEntries}"
			CanUserSortColumns="True" BorderThickness="3"
			CanUserReorderColumns="True">

			<DataGrid.Styles>
				<Style Selector="DataGridCell">
					<Setter Property="Height" Value="80"/>
				</Style>
				<Style Selector="DataGridCell > Panel">
					<Setter Property="VerticalAlignment" Value="Stretch"/>
				</Style>
				<Style Selector="DataGridCell > Panel > TextBlock">
					<Setter Property="VerticalAlignment" Value="Center"/>
					<Setter Property="HorizontalAlignment" Value="Stretch"/>
					<Setter Property="TextWrapping" Value="Wrap"/>
					<Setter Property="Padding" Value="4"/>
				</Style>
			</DataGrid.Styles>
			
			<DataGrid.Columns>

				<DataGridTemplateColumn
					CanUserSort="True"
					IsVisible="{Binding RemoveColumnVisivle}"
					PropertyChanged="RemoveColumn_PropertyChanged"
					Header="Remove"
					IsReadOnly="False"
					SortMemberPath="Remove"
					Width="75">

					<DataGridTemplateColumn.CellTemplate>
						<DataTemplate>
							<CheckBox
								HorizontalAlignment="Center"
								IsThreeState="True"
								IsChecked="{Binding Remove, Mode=TwoWay}" />
						</DataTemplate>
					</DataGridTemplateColumn.CellTemplate>
				</DataGridTemplateColumn>

				<controls:DataGridTemplateColumnExt CanUserSort="True" Width="75" Header="Liberate" SortMemberPath="Liberate" ClipboardContentBinding="{Binding Liberate.ToolTip}">
					<DataGridTemplateColumn.CellTemplate>
						<DataTemplate>
							<Panel ToolTip.Tip="{Binding Liberate.ToolTip}">
								<Button Opacity="{Binding Liberate.Opacity}" Padding="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Click="LiberateButton_Click" IsVisible="{Binding !Liberate.IsUnavailable}">
									<Image Source="{Binding Liberate.ButtonImage}" Stretch="None" />
								</Button>
								<Image Source="{Binding Liberate.ButtonImage}" Stretch="None" IsVisible="{Binding Liberate.IsUnavailable}"/>
								<Panel Background="{StaticResource DisabledGrayBrush}" IsVisible="{Binding Liberate.IsUnavailable}" />
							</Panel>
						</DataTemplate>
					</DataGridTemplateColumn.CellTemplate>
				</controls:DataGridTemplateColumnExt>

				<DataGridTemplateColumn CanUserSort="False" Width="80" Header="Cover" SortMemberPath="Cover" ClipboardContentBinding="{Binding LibraryBook.Book.PictureLarge}">
					<DataGridTemplateColumn.CellTemplate>
						<DataTemplate>
							<Image Opacity="{Binding Liberate.Opacity}" Tapped="Cover_Click" Height="80" Source="{Binding Cover}" ToolTip.Tip="Click to see full size" />
						</DataTemplate>
					</DataGridTemplateColumn.CellTemplate>
				</DataGridTemplateColumn>

				<controls:DataGridTemplateColumnExt MinWidth="150" Width="2*" Header="Title" CanUserSort="True" SortMemberPath="Title" ClipboardContentBinding="{Binding Title}">
					<DataGridTemplateColumn.CellTemplate>
						<DataTemplate>
							<Panel Opacity="{Binding Liberate.Opacity}" Background="{Binding Liberate.BackgroundBrush}">
								<TextBlock Text="{Binding Title}" />
							</Panel>
						</DataTemplate>
					</DataGridTemplateColumn.CellTemplate>
				</controls:DataGridTemplateColumnExt>

				<controls:DataGridTemplateColumnExt MinWidth="80" Width="1*" Header="Authors" CanUserSort="True" SortMemberPath="Authors" ClipboardContentBinding="{Binding Authors}">
					<DataGridTemplateColumn.CellTemplate>
						<DataTemplate>
							<Panel Opacity="{Binding Liberate.Opacity}" Background="{Binding Liberate.BackgroundBrush}">
								<TextBlock Text="{Binding Authors}" />
							</Panel>
						</DataTemplate>
					</DataGridTemplateColumn.CellTemplate>
				</controls:DataGridTemplateColumnExt>

				<controls:DataGridTemplateColumnExt MinWidth="80" Width="1*"  Header="Narrators" CanUserSort="True" SortMemberPath="Narrators" ClipboardContentBinding="{Binding Narrators}">
					<DataGridTemplateColumn.CellTemplate>
						<DataTemplate>
							<Panel Opacity="{Binding Liberate.Opacity}" Background="{Binding Liberate.BackgroundBrush}">
								<TextBlock Text="{Binding Narrators}" />
							</Panel>
						</DataTemplate>
					</DataGridTemplateColumn.CellTemplate>
				</controls:DataGridTemplateColumnExt>

				<controls:DataGridTemplateColumnExt Width="90"  Header="Length" CanUserSort="True" SortMemberPath="Length" ClipboardContentBinding="{Binding Length}">
					<DataGridTemplateColumn.CellTemplate>
						<DataTemplate>
							<Panel Opacity="{Binding Liberate.Opacity}" Background="{Binding Liberate.BackgroundBrush}">
								<TextBlock Text="{Binding Length}" />
							</Panel>
						</DataTemplate>
					</DataGridTemplateColumn.CellTemplate>
				</controls:DataGridTemplateColumnExt>

				<controls:DataGridTemplateColumnExt MinWidth="80" Width="1*" Header="Series" CanUserSort="True" SortMemberPath="Series" ClipboardContentBinding="{Binding Series}">
					<DataGridTemplateColumn.CellTemplate>
						<DataTemplate>
							<Panel Opacity="{Binding Liberate.Opacity}" Background="{Binding Liberate.BackgroundBrush}">
								<TextBlock Text="{Binding Series}" />
							</Panel>
						</DataTemplate>
					</DataGridTemplateColumn.CellTemplate>
				</controls:DataGridTemplateColumnExt>

				<controls:DataGridTemplateColumnExt MinWidth="100" Width="1*" Header="Description" CanUserSort="True" SortMemberPath="Description" ClipboardContentBinding="{Binding LongDescription}">
					<DataGridTemplateColumn.CellTemplate>
						<DataTemplate>
							<Panel Opacity="{Binding Liberate.Opacity}" Background="{Binding Liberate.BackgroundBrush}" Tapped="Description_Click" ToolTip.Tip="Click to see full description" >
								<TextBlock Text="{Binding Description}" FontSize="11" VerticalAlignment="Top" />
							</Panel>
						</DataTemplate>
					</DataGridTemplateColumn.CellTemplate>
				</controls:DataGridTemplateColumnExt>

				<controls:DataGridTemplateColumnExt Width="100" Header="Category" CanUserSort="True" SortMemberPath="Category" ClipboardContentBinding="{Binding Category}">
					<DataGridTemplateColumn.CellTemplate>
						<DataTemplate>
							<Panel Opacity="{Binding Liberate.Opacity}" Background="{Binding Liberate.BackgroundBrush}">
								<TextBlock Text="{Binding Category}" />
							</Panel>
						</DataTemplate>
					</DataGridTemplateColumn.CellTemplate>
				</controls:DataGridTemplateColumnExt>

				<controls:DataGridMyRatingColumn
					Header="Product&#xA;Rating"
					IsReadOnly="true"
					Width="115"
					SortMemberPath="ProductRating" CanUserSort="True"
					OpacityBinding="{Binding Liberate.Opacity}"
					BackgroundBinding="{Binding Liberate.BackgroundBrush}"
					ClipboardContentBinding="{Binding ProductRating}"
					Binding="{Binding ProductRating}" />

				<controls:DataGridTemplateColumnExt Width="90" Header="Purchase&#xA;Date" CanUserSort="True" SortMemberPath="PurchaseDate" ClipboardContentBinding="{Binding PurchaseDate}">
					<DataGridTemplateColumn.CellTemplate>
						<DataTemplate>
							<Panel Opacity="{Binding Liberate.Opacity}" Background="{Binding Liberate.BackgroundBrush}">
								<TextBlock Text="{Binding PurchaseDate}" />
							</Panel>
						</DataTemplate>
					</DataGridTemplateColumn.CellTemplate>
				</controls:DataGridTemplateColumnExt>

				<controls:DataGridMyRatingColumn
					Header="My Rating"					
					IsReadOnly="false"
					Width="115"
					SortMemberPath="MyRating" CanUserSort="True"
					OpacityBinding="{Binding Liberate.Opacity}"
					BackgroundBinding="{Binding Liberate.BackgroundBrush}"
					ClipboardContentBinding="{Binding MyRating}"					
					Binding="{Binding MyRating, Mode=TwoWay}" />

				<controls:DataGridTemplateColumnExt Width="135" Header="Misc" CanUserSort="True" SortMemberPath="Misc" ClipboardContentBinding="{Binding Misc}">
					<DataGridTemplateColumn.CellTemplate>
						<DataTemplate>
							<Panel Opacity="{Binding Liberate.Opacity}" Background="{Binding Liberate.BackgroundBrush}">
								<TextBlock Text="{Binding Misc}" TextWrapping="WrapWithOverflow" FontSize="10" />
							</Panel>
						</DataTemplate>
					</DataGridTemplateColumn.CellTemplate>
				</controls:DataGridTemplateColumnExt>
				
				<controls:DataGridTemplateColumnExt Width="102" Header="Last&#xA;Download" CanUserSort="True" SortMemberPath="LastDownload" ClipboardContentBinding="{Binding LastDownload}">
					<DataGridTemplateColumn.CellTemplate>
						<DataTemplate>
							<Panel Opacity="{Binding Liberate.Opacity}" Background="{Binding Liberate.BackgroundBrush}" ToolTip.Tip="{Binding LastDownload.ToolTipText}" DoubleTapped="Version_DoubleClick">
								<TextBlock Text="{Binding LastDownload}" TextWrapping="WrapWithOverflow" FontSize="10" />
							</Panel>
						</DataTemplate>
					</DataGridTemplateColumn.CellTemplate>
				</controls:DataGridTemplateColumnExt>

				<controls:DataGridTemplateColumnExt CanUserSort="True" Width="100" Header="Tags" SortMemberPath="BookTags" ClipboardContentBinding="{Binding BookTags}">
					<DataGridTemplateColumn.CellTemplate>
						<DataTemplate>
							<Button IsVisible="{Binding !Liberate.IsSeries}" Width="100" Height="80" Click="OnTagsButtonClick" ToolTip.Tip="Click to edit tags" >
								<Panel Opacity="{Binding Liberate.Opacity}">
									<Image IsVisible="{Binding BookTags, Converter={x:Static StringConverters.IsNullOrEmpty}}" Stretch="None" Source="/Assets/edit_25x25.png" />
									<TextBlock IsVisible="{Binding BookTags, Converter={x:Static StringConverters.IsNotNullOrEmpty}}" FontSize="12" TextWrapping="WrapWithOverflow" HorizontalAlignment="Center" VerticalAlignment="Center" Text="{Binding BookTags}"/>
								</Panel>
							</Button>
						</DataTemplate>
					</DataGridTemplateColumn.CellTemplate>
				</controls:DataGridTemplateColumnExt>

			</DataGrid.Columns>
		</DataGrid>
	</Grid>
</UserControl>
