<?xml version="1.0" encoding="utf-8"?>
<ResourceDictionary mc:Ignorable="PresentationOptions" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:PresentationOptions="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:c1sched="clr-namespace:C1.WPF.Schedule">

    <c1sched:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
    <LinearGradientBrush x:Key="MouseOverGradientBorderBrush" StartPoint="0,0" EndPoint="0,1">
        <GradientStop Color="#FF99C1E2" Offset="0.05" />
    </LinearGradientBrush>
    <LinearGradientBrush x:Key="MouseOverGradientBrush" StartPoint="0,0" EndPoint="0,1">
        <GradientStop Color="#20FFFFFF" Offset="1" />
        <GradientStop Color="#00FFFFFF" Offset="0" />
    </LinearGradientBrush>
    <SolidColorBrush x:Key="SelectedAppointmentBorderBrush" Color="Black" />

    <CornerRadius x:Key="C1Scheduler_Appointment_CornerRadius">3</CornerRadius>
    <CornerRadius x:Key="C1Scheduler_Appointment_InnerCornerRadius">3,0,0,3</CornerRadius>

    <DataTemplate x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type c1sched:C1Scheduler}, ResourceId=IntervalAppointmentTemplate}">
		<DataTemplate.Resources>
            <Style x:Key="markStyle" TargetType="{x:Type TextBlock}">
                <Setter Property="Margin" Value="1" />
                <Setter Property="FontFamily" Value="Segoe UI Symbol" />
                <Setter Property="FontSize" Value="10" />
            </Style>
            <Style x:Key="looklessTextBox" TargetType="{x:Type TextBox}">
				<Setter Property="BorderBrush" Value="Transparent" />
				<Setter Property="BorderThickness" Value="0" />
				<Setter Property="Background" Value="Transparent" />
				<Setter Property="Foreground" Value="{Binding Path=AppointmentForeground, RelativeSource={RelativeSource AncestorType={x:Type c1sched:C1Scheduler}}}" />
				<Setter Property="Margin" Value="0" />
				<Setter Property="Padding" Value="0" />
			</Style>
        </DataTemplate.Resources>
		<c1sched:PilePanel SnapsToDevicePixels="True" x:Name="panel">
			<c1sched:PilePanel.InputBindings>
				<MouseBinding MouseAction="LeftDoubleClick" Command="c1sched:C1Scheduler.EditAppointmentDialogCommand" />
			</c1sched:PilePanel.InputBindings>
			<c1sched:PropertyBridge x:Name="showTimeThickness" Source="{DynamicResource TimeBorderThickness}" />
            <Border x:Name="brd" CornerRadius="{DynamicResource C1Scheduler_Appointment_CornerRadius}" IsHitTestVisible="False" Background="{Binding Appointment.Label.Color, Converter={x:Static c1sched:ColorToBrushConverter.Default}}"
                    BorderBrush="{Binding Appointment.Label.Color, Converter={x:Static c1sched:ColorToBrushConverter.Default}}" BorderThickness="1px">
                <!-- mouse over element -->
                <Rectangle Visibility="{Binding IsMouseOver, ElementName=panel, Converter={x:Static c1sched:BooleanToVisibilityConverter.Default}}" Fill="{DynamicResource MouseOverGradientBrush}" />
            </Border>
            <!-- use semi-transparent dark border brush -->
            <Border x:Name="gradBorder" BorderThickness="1px" BorderBrush="#48000000" Background="{DynamicResource C1Scheduler_AppointmentBgMask_Brush}" CornerRadius="{DynamicResource C1Scheduler_Appointment_CornerRadius}">
				<DockPanel ClipToBounds="True">
                    <Border Name="leftInnerShowTimeBorder" DockPanel.Dock="Left" Width="{Binding Target.Left, ElementName=showTimeThickness}" Background="{Binding Appointment.BusyStatus.Brush.Brush}" BorderBrush="#48000000" BorderThickness="0,0,1px,0" CornerRadius="{DynamicResource C1Scheduler_Appointment_InnerCornerRadius}" />
					<!-- If background is not specified, MouseDown event doesn't work for empty areas -->
					<c1sched:AppointmentWrapPanel Background="Transparent" Margin="2,0,2,0" TextBlock.Foreground="{Binding Path=Interval.Scheduler.AppointmentForeground}" DockLastChildToEnd="True" Orientation="Horizontal" x:Name="appointmentWrapPanel" IsReadOnly="{Binding Path=Interval.Scheduler.IsInPlaceEditingDisabled}">
						<c1sched:AppointmentWrapPanel.ToolTip>
							<ToolTip>
								<WrapPanel Orientation="Vertical">
									<TextBlock Text="{Binding Appointment.Start, Converter={x:Static c1sched:DateTimeToStringConverter.Default}, ConverterParameter=t}" Margin="2,0,2,0" />
									<TextBlock FontWeight="Bold" Text="{Binding Appointment.Subject}" Margin="2,0,2,0" TextWrapping="Wrap" />
									<TextBlock TextWrapping="Wrap" Text="{Binding Appointment.Location}" />
								</WrapPanel>
							</ToolTip>
						</c1sched:AppointmentWrapPanel.ToolTip>
						<TextBlock x:Name="time" Text="{Binding Appointment.Start, Converter={x:Static c1sched:DateTimeToStringConverter.Default},  ConverterParameter=t}" Margin="0,0,2,0" />
						<!-- Shows subject when appointment is inactive -->
						<TextBlock x:Name="Subject" Text="{Binding Appointment.Subject}" FontWeight="SemiBold" TextWrapping="Wrap" />
						<!-- Visible while in-place editing only (look at triggers) -->
						<TextBox x:Name="PART_Subject" Style="{StaticResource looklessTextBox}" MaxLength="255" Text="{Binding Appointment.Subject}" FontWeight="SemiBold" TextWrapping="Wrap" />
						<TextBlock x:Name="location" TextWrapping="Wrap" Text="{Binding Appointment.Location}" />
						<StackPanel Orientation="Horizontal">
                            <TextBlock Visibility="Collapsed" Name="recurrenceMark" Style="{StaticResource markStyle}" Text="&#xE117;"/>
                            <Grid Visibility="Collapsed" Name="exceptionMark">
                                <TextBlock Style="{StaticResource markStyle}" Text="&#xE117;"/>
                                <TextBlock Style="{StaticResource markStyle}" Text="&#x2571;"/>
                            </Grid>
                            <TextBlock Visibility="Collapsed" Name="privateMark" Style="{StaticResource markStyle}" Text="&#xE1F6;" />
						</StackPanel>
					</c1sched:AppointmentWrapPanel>
				</DockPanel>
			</Border>
            <Border BorderThickness="1" CornerRadius="{DynamicResource C1Scheduler_Appointment_CornerRadius}" BorderBrush="{DynamicResource SelectedAppointmentBorderBrush}" 
                    Visibility="{Binding IsSelectedAppointment, Converter={StaticResource BooleanToVisibilityConverter}}" />
        </c1sched:PilePanel>
		<DataTemplate.Triggers>
			<DataTrigger Binding="{Binding Appointment.Label.Color}" Value="White">
				<Setter TargetName="brd" Property="Background" Value="{Binding Interval.OwnerGroup.Background}" />
                <Setter TargetName="brd" Property="BorderBrush" Value="{Binding Interval.OwnerGroup.Background}" />
			</DataTrigger>
            <DataTrigger Binding="{Binding Target.Left, ElementName=showTimeThickness}" Value="0">
                <Setter TargetName="PART_Subject" Property="TextWrapping" Value="NoWrap" />
                <Setter TargetName="Subject" Property="TextWrapping" Value="NoWrap" />
                <Setter TargetName="location" Property="TextWrapping" Value="NoWrap" />
            </DataTrigger>
            <!-- hide TextBlock while in-place editing -->
			<Trigger SourceName="PART_Subject" Property="IsFocused" Value="True">
				<Setter TargetName="Subject" Property="Visibility" Value="Collapsed" />
			</Trigger>
			<!-- hide PART_Subject if it is not focused -->
			<Trigger SourceName="PART_Subject" Property="IsFocused" Value="False">
				<Setter TargetName="PART_Subject" Property="Visibility" Value="Collapsed" />
			</Trigger>
			<Trigger SourceName="Subject" Property="Visibility" Value="Visible">
				<Setter TargetName="PART_Subject" Property="Visibility" Value="Collapsed" />
			</Trigger>
			<Trigger SourceName="appointmentWrapPanel" Property="IsKeyboardFocusWithin" Value="True">
				<Setter TargetName="location" Property="Visibility" Value="Collapsed" />
			</Trigger>
			<MultiDataTrigger>
				<MultiDataTrigger.Conditions>
					<Condition Binding="{Binding Appointment.RecurrenceState}" Value="Occurrence" />
					<Condition Binding="{Binding IsKeyboardFocusWithin, ElementName=appointmentWrapPanel}" Value="False" />
				</MultiDataTrigger.Conditions>
				<Setter TargetName="recurrenceMark" Property="Visibility" Value="Visible" />
			</MultiDataTrigger>
			<MultiDataTrigger>
				<MultiDataTrigger.Conditions>
					<Condition Binding="{Binding Appointment.RecurrenceState}" Value="Exception" />
					<Condition Binding="{Binding IsKeyboardFocusWithin, ElementName=appointmentWrapPanel}" Value="False" />
				</MultiDataTrigger.Conditions>
				<Setter TargetName="exceptionMark" Property="Visibility" Value="Visible" />
			</MultiDataTrigger>
			<MultiDataTrigger>
				<MultiDataTrigger.Conditions>
					<Condition Binding="{Binding Appointment.Private}" Value="True" />
					<Condition Binding="{Binding IsKeyboardFocusWithin, ElementName=appointmentWrapPanel}" Value="False" />
				</MultiDataTrigger.Conditions>
				<Setter TargetName="privateMark" Property="Visibility" Value="Visible" />
			</MultiDataTrigger>
			<DataTrigger Binding="{Binding Appointment.AllDayEvent}" Value="true">
				<Setter TargetName="time" Property="Text" Value=" " />
			</DataTrigger>
			<DataTrigger Binding="{Binding Appointment.Location.Length}" Value="0">
				<Setter TargetName="location" Property="Visibility" Value="Collapsed" />
			</DataTrigger>
		</DataTemplate.Triggers>
	</DataTemplate>
</ResourceDictionary>