using Foundation;
using System;
using System.CodeDom.Compiler;
using UIKit;
using CoreGraphics;
using PokktExtension;
using PokktExtension.Enums;
using PokktExtension.iOS;

namespace SampleApp.iOS
{
	partial class DemoSelector : UIViewController
	{
		private bool isPokktInitialize;
		private PokktConfig pokktConfig;

		public DemoSelector (string nibName, NSBundle bundle) : base (nibName, bundle)
		{
		}

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

			DisableButton ();

			//Setting extension and adding event
			PokktExtension.PokktManager.SetNativeExtentions(new IosExtension());
			PokktManager.Dispatcher.PokktInitialisedEvent += PokktInitialisedEvent;
		}

		private void DisableButton()
		{
			DemoScreen1Btn.Enabled = false;
			DemoScreen2Btn.Enabled = false;
			ExportLogBtn.Enabled = false;
			DemoScreen1Btn.Alpha = 0.5f;
			DemoScreen2Btn.Alpha = 0.5f;
			ExportLogBtn.Alpha = 0.5f;
		}

		private void EnableButton()
		{
			InitializeBtn.Enabled = false;
			InitializeBtn.Alpha = 0.5f;
			DemoScreen1Btn.Enabled = true;
			DemoScreen2Btn.Enabled = true;
			ExportLogBtn.Enabled = true;
			DemoScreen1Btn.Alpha = 1.0f;
			DemoScreen2Btn.Alpha = 1.0f;
			ExportLogBtn.Alpha = 1.0f;
		}

		public override void DidReceiveMemoryWarning ()
		{
			base.DidReceiveMemoryWarning();
			// Dispose of any resources that can be recreated.
		}


		//Button click handler
		partial void InitializeBtn_TouchUpInside (UIButton sender)
		{
			if (isPokktInitialize) {
				return;
			}

			pokktConfig  = new PokktConfig();

//			pokktConfig.ApplicationId = "a2717a45b835b5e9f50284a38d62a74e";
//			pokktConfig.SecurityKey = "iJ02lJss0M";

			//Suraj:iOS
			pokktConfig.ApplicationId = "954b975f9c753bcb8fca42624d78139a";
			pokktConfig.SecurityKey = "ae501f1003b0dc927dea807498ceaf3c";

//			pokktConfig.ApplicationId = "0f666bc5d176ce734443a4fe00183d63";
//			pokktConfig.SecurityKey = "81f2f0b8e67752ddd552f9b9e2c678f3";

			//Amit:iOS
//			pokktConfig.ApplicationId = "cc41e865391d6ea371b18aff27cc10e6";
//			pokktConfig.SecurityKey = "4a069e89fe4a4e4f58a26f8bff2974ba";

			pokktConfig.IntegrationType = PokktIntegrationType.INTEGRATION_TYPE_ALL;
			pokktConfig.ThirdPartyUserId = "123456";

			PokktManager.SetDebug(true);
			PokktManager.InitPokkt(pokktConfig);
		}

		partial void DemoScreen1Btn_TouchUpInside (UIButton sender)
		{
			AdConfig adConfig = new AdConfig();
			//adConfig.BackButtonDisabled = true;
			//adConfig.DefaultSkipTime = 5;
			adConfig.ScreenName = "start";
//			adConfig.ShouldAllowMute = true;
//			adConfig.ShouldAllowSkip = true;
//			adConfig.ShouldConfirmSkip = true;
//			adConfig.SkipConfirmMessage = "Are you sure?";
//			adConfig.SkipConfirmNoLabel = "NO";
//			adConfig.SkipConfirmYesLabel = "YES";
			ShowDemoScreen(adConfig);
		}

		partial void DemoScreen2Btn_TouchUpInside (UIButton sender)
		{
			AdConfig adConfig = new AdConfig();
			//adConfig.BackButtonDisabled = true;
			//adConfig.DefaultSkipTime = 7;
			adConfig.ScreenName = "levelClear";
//			adConfig.ShouldAllowMute = true;
//			adConfig.ShouldAllowSkip = true;
//			adConfig.ShouldConfirmSkip = true;
//			adConfig.SkipConfirmMessage = "Are you sure want to quit?";
//			adConfig.SkipConfirmNoLabel = "No";
//			adConfig.SkipConfirmYesLabel = "Yes";
			ShowDemoScreen(adConfig);
		}

		partial void ExportLogBtn_TouchUpInside (UIButton sender)
		{
			PokktManager.ExportLog();
		}

		private void ShowDemoScreen(AdConfig adConfig)
		{
			DemoScreen demoScreen = new DemoScreen (adConfig);
			this.NavigationController.PushViewController(demoScreen, true);
		}

		//Delegate handler
		void PokktInitialisedEvent (bool isInitialised)
		{
			isPokktInitialize = isInitialised;
			if (isPokktInitialize) {
				InAppPurchaseDetails details = new InAppPurchaseDetails ();
				details.CurrencyCode = "INR";
				details.Description = "Desc";
				details.Price = 20;
				details.ProductId = "prod id";
				details.PurchaseData = "pur date";
				details.PurchaseSignature = "pur signature";
				details.PurchaseStore = IAPStoreType.AMAZON;
				PokktManager.TrackIAP (details);
				EnableButton ();
			}
		}

	}
}
