
using MonoTouch.UIKit;
using System;
using MonoTouch.Foundation;

namespace Pages
{
	partial class RootViewController : UITableViewController
	{
		public RootViewController(IntPtr handle) : base(handle)
		{
		}

		public override void ViewDidLoad()
		{
			base.ViewDidLoad();
			//Show an edit button
			//NavigationItem.RightBarButtonItem = EditButtonItem;
			
			this.TableView.Source = new DataSource(this);
		}

		/*
		public override void ViewWillAppear (bool animated)
		{
			base.ViewWillAppear (animated);
		}
		*/
		/*
		public override void ViewDidAppear (bool animated)
		{
			base.ViewDidAppear (animated);
		}
		*/
		/*
		public override void ViewWillDisappear (bool animated)
		{
			base.ViewWillDisappear (animated);
		}
		*/
		/*
		public override void ViewDidDisappear (bool animated)
		{
			base.ViewDidDisappear (animated);
		}
		*/

		// Override to allow orientations other than the default portrait orientation
		public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
		{
			return true;
		}

		public override void DidReceiveMemoryWarning()
		{
			// Releases the view if it doesn't have a superview.
			base.DidReceiveMemoryWarning();
			
			// Release any cached data, images, etc that aren't in use.
		}

		public override void ViewDidUnload()
		{
			// Release anything that can be recreated in viewDidLoad or on demand.
			// e.g. this.myOutlet = null;
			
			base.ViewDidUnload();
		}

		class DataSource : UITableViewSource
		{
			RootViewController controller;

			public DataSource(RootViewController controller)
			{
				this.controller = controller;
			}
			
			public override string TitleForHeader(UITableView tableView, int section)
			{
				switch (section)
				{
					case 0:
						return "UIKit Example";
					case 1:
						return "CoreLocation & MapKit example";
					default:
						return "Device information example";					
				}
			}
			
			public override int NumberOfSections(UITableView tableView)
			{
				return 3;
			}

			// Customize the number of rows in the table view
			public override int RowsInSection(UITableView tableview, int section)
			{
				return 1;
			}

			// Customize the appearance of table view cells.
			public override UITableViewCell GetCell(UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
			{
				var cell = new UITableViewCell(UITableViewCellStyle.Default, "");
				if ((indexPath.Section == 0) && (indexPath.Row == 0))
					cell.TextLabel.Text = "Web browser";
				if ((indexPath.Section == 1) && (indexPath.Row == 0))
					cell.TextLabel.Text = "GPS information";
				if ((indexPath.Section == 2) && (indexPath.Row == 0))
					cell.TextLabel.Text = "Device information";				
				return cell;
			}

			/*
			// Override to support conditional editing of the table view.
			public override bool CanEditRow (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
			{
				// Return false if you do not want the specified item to be editable.
				return true;
			}
			*/
			/*
			// Override to support editing the table view.
			public override void CommitEditingStyle (UITableView tableView, UITableViewCellEditingStyle editingStyle, MonoTouch.Foundation.NSIndexPath indexPath)
			{
				if (editingStyle == UITableViewCellEditingStyle.Delete) {
					controller.TableView.DeleteRows (new NSIndexPath[] { indexPath }, UITableViewRowAnimation.Fade);
				} else if (editingStyle == UITableViewCellEditingStyle.Insert) {
					// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
				}
			}
			*/
			/*
			// Override to support rearranging the table view.
			public override void MoveRow (UITableView tableView, NSIndexPath sourceIndexPath, NSIndexPath destinationIndexPath)
			{
			}
			*/
			/*
			// Override to support conditional rearranging of the table view.
			public override bool CanMoveRow (UITableView tableView, NSIndexPath indexPath)
			{
				// Return false if you do not want the item to be re-orderable.
				return true;
			}
			*/

			// Override to support row selection in the table view.
			public override void RowSelected(UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
			{
				if ((indexPath.Section == 0) && (indexPath.Row == 0))
					controller.NavigationController.PushViewController(new BrowserPage(), true);
				if ((indexPath.Section == 1) && (indexPath.Row == 0))
					controller.NavigationController.PushViewController(new GPSPage(), true);
				if ((indexPath.Section == 2) && (indexPath.Row == 0))
					controller.NavigationController.PushViewController(new InfoPage(), true);
			}
		}
	}
	
}

