using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Media;

namespace Ricciolo.Controls
{
    public class AdvancedListBoxItem : ListBoxItem
    {
        public static readonly DependencyProperty IsLosingSelectionProperty;
        public static readonly DependencyProperty IsGettingSelectionProperty;
        public static readonly DependencyProperty SelectionDirectionProperty;

        static AdvancedListBoxItem()
        {
            IsLosingSelectionProperty = AdvancedListBox.IsLosingSelectionProperty.AddOwner(typeof(AdvancedListBoxItem));
            IsGettingSelectionProperty = AdvancedListBox.IsGettingSelectionProperty.AddOwner(typeof(AdvancedListBoxItem));
            SelectionDirectionProperty = AdvancedListBox.SelectionDirectionProperty.AddOwner(typeof(AdvancedListBoxItem));

            FrameworkElement.DefaultStyleKeyProperty.OverrideMetadata(typeof(AdvancedListBoxItem), new FrameworkPropertyMetadata(typeof(AdvancedListBoxItem)));
        }

        internal Selector ParentSelector
        {
            get { return (ItemsControl.ItemsControlFromItemContainer(this) as Selector); }
        }

        private AdvancedListBox ParentListBox
        {
            get { return (this.ParentSelector as AdvancedListBox); }
        }

        [Bindable(true), Category("Appearance")]
        public bool IsLosingSelection
        {
            get { return (bool)base.GetValue(IsLosingSelectionProperty); }
        }

        [Bindable(true), Category("Appearance")]
        public bool IsGettingSelection
        {
            get { return (bool)base.GetValue(IsGettingSelectionProperty); }
        }

        [Bindable(true), Category("Appearance")]
        public SelectionDirection SelectionDirection
        {
            get { return (SelectionDirection)base.GetValue(SelectionDirectionProperty); }
        }

        protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
        {
            e.Handled = true;
            AdvancedListBox advancedListBox = this.ParentListBox;
            if (advancedListBox != null)
            {
                advancedListBox.NotifyAdvancedListBoxItemMouseUp(this);
            }
            base.OnMouseLeftButtonUp(e);
        }

    }
}