using Foundation;
using System;
using System.CodeDom.Compiler;
using UIKit;
using Cirrious.FluentLayouts;
using Cirrious.FluentLayouts.Touch;

using TeenTix.Common;

namespace TeenTixMobileNEW
{
	partial class PassController : UIViewController
	{

		public PassController (IntPtr handle) : base (handle)
		{
		}

		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();

			View.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints ();

			View.AddConstraints (
				SegmentControl.AtTopOf(View, 80),
				SegmentControl.WithSameWidth(View),

				HowItWorks.WithSameCenterX(View),
				HowItWorks.Below(SegmentControl),
				HowItWorks.AtLeftOf(View, 20),
				HowItWorks.AtRightOf(View, 20),

				PassImage.WithSameCenterX(View),
				//PassImage.WithSameTop(Pass2Image).Plus(63),
				PassImage.AtLeftOf(View, 20),
				PassImage.AtRightOf(View, 20),

				PassText.WithSameCenterX(View),
				//PassText.WithSameWidth(View).Minus(40),
				PassText.Below(PassImage, 10),
				PassText.AtLeftOf(View, 30),
				PassText.AtRightOf(View, 30),

				PartnerWebView.Below(SegmentControl),
				PartnerWebView.WithSameWidth(View),
				PartnerWebView.WithSameBottom(View)

			);

			SegmentControl.SetTitleTextAttributes (new UITextAttributes (){
				Font = UIFont.BoldSystemFontOfSize(15),
				TextColor = UIColor.White
			}, UIControlState.Normal);

			SegmentControl.ValueChanged += (object sender, EventArgs e) => {
				var selectedSegmentId = (sender as UISegmentedControl).SelectedSegment;

				switch (selectedSegmentId) {
				case 0:
					ShowHowItWorksView();
					break;
				case 1:
					ShowPassView();
					break;
				case 2:
					ShowPartnerWebView();
					break;
				default:
					Console.WriteLine("Unknown segment index: {0}", selectedSegmentId);
					break;
				}
			};
		}

		private void ShowHowItWorksView() {
			this.Title = "How It Works";
			this.TabBarItem.Title = "Pass";

			HowItWorks.Hidden = false;

			PassImage.Hidden = true;

			PassText.Hidden = true;

			PartnerWebView.Hidden = true;
		}

		private void ShowPassView() {
			this.Title = "Pass";

			HowItWorks.Hidden = true;

			PassImage.Hidden = false;

			PassText.Hidden = false;

			PartnerWebView.Hidden = true;
		}

		private void ShowPartnerWebView() {
			this.Title = "Explore our Partners!";
			this.TabBarItem.Title = "Pass";

			var url = PrivateConstants.HOST_URL + "/partners/mobile";
			PartnerWebView.LoadRequest (new NSUrlRequest (new NSUrl (url)));
			PartnerWebView.ScalesPageToFit = true;

			HowItWorks.Hidden = true;

			PassImage.Hidden = true;
			PassText.Hidden = true;

			PartnerWebView.Hidden = false;
		}
	}
}
