using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CoreGraphics;
using Foundation;
using UIKit;

namespace Shared
{
	/// <summary>
	/// 时间视图
	/// </summary>
	public class TimeView : View
	{
		/// <summary>
		/// 当前视图
		/// </summary>
		/// <value>The android text.</value>
		MyUITimePicker currentUITimePicker
		{
			get
			{
				return uiView as MyUITimePicker;
			}
			set
			{
				uiView = value;
			}
		}


		/// <summary>
		/// æ—¶
		/// </summary>
		public int Hour
		{
			get { return (int)currentUITimePicker.current.Hour; }
		}
		/// <summary>
		/// 分
		/// </summary>
		public int Minute
		{
			get { return (int)currentUITimePicker.current.Minute; }
		}

		/// <summary>
		/// 视图
		/// </summary>
		public TimeView()
		{
			currentUITimePicker = new MyUITimePicker(this) { };
            
		}

		 class MyUITimePicker : UIDatePicker
		{
            [Weak] TimeView timeView;
			public MyUITimePicker(TimeView timeView)
			{
                this.timeView = timeView;
                Mode = UIDatePickerMode.Time;
			}

			nfloat x;
            /// <summary>
            /// 点击开始
            /// </summary>
            /// <param name="touches">Touches.</param>
            /// <param name="evt">Evt.</param>
            public override void TouchesBegan(NSSet touches, UIEvent evt)
            {
                timeView?.TouchEvent(EventActions.Down, (touches.AnyObject as UITouch).LocationInView(this));
            }
            /// <summary>
            ///  移动
            /// </summary>
            /// <param name="touches">Touches.</param>
            /// <param name="evt">Evt.</param>
            public override void TouchesMoved(NSSet touches, UIEvent evt)
            {
                timeView?.TouchEvent(EventActions.Move, (touches.AnyObject as UITouch).LocationInView(this));
            }

            /// <summary>
            /// 点击弹起
            /// </summary>
            /// <param name="touches">Touches.</param>
            /// <param name="evt">Evt.</param>
            public override void TouchesEnded(NSSet touches, UIEvent evt)
            {
                timeView?.TouchEvent(EventActions.Up, (touches.AnyObject as UITouch).LocationInView(this));
            }

            public override void TouchesCancelled(NSSet touches, UIEvent evt)
            {
                timeView?.TouchEvent(EventActions.Cancel, (touches.AnyObject as UITouch).LocationInView(this));
            }

            public NSDateComponents current
			{
				get
				{
					NSCalendar cal = NSCalendar.CurrentCalendar;
					return cal.Components(NSCalendarUnit.Hour | NSCalendarUnit.Minute | NSCalendarUnit.Second, Date);// [cal components: unitFlags fromDate: now
				}
			}

		}

	}
}