/**
 * THE StorePage.java WRITEME...
 */
package com.tootsville.tootsbook.client.pages;

import com.google.gwt.user.client.History;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.tootsville.tootsbook.client.TootsBook;
import com.tootsville.tootsbook.client.panel.Box;
import com.tootsville.tootsbook.client.panel.TabbedBox;
import com.tootsville.tootsbook.client.util.Advertisement;
import com.tootsville.tootsbook.client.util.DisplayText;

/**
 * WRITEME: Document this type. twheys@gmail.com Feb 23, 2010
 * 
 * @author <a href="mailto:twheys@gmail.com@resinteractive.com">Tim
 *         Heys</a>
 */
public class StorePage extends HorizontalPanel {
	/**
	 * WRITEME twheys@gmail.com
	 */
	private Box adBox;

	/**
	 * WRITEME twheys@gmail.com
	 */
	private VerticalPanel centerContents;

	/**
	 * WRITEME twheys@gmail.com
	 */
	private VerticalPanel rightContents;

	/**
	 * WRITEME twheys@gmail.com
	 */
	private TabbedBox storeBox;

	/**
	 * <pre>
	 * twheys@gmail.com Feb 23, 2010
	 * </pre>
	 * 
	 * A StorePage creates a store page at tab index 1.
	 * 
	 * see Stores
	 */
	public StorePage () {
		this (0);
	}

	/**
	 * <pre>
	 * twheys@gmail.com Feb 23, 2010
	 * </pre>
	 * 
	 * A StorePage creates a store page and displays the selected tab
	 * index
	 * 
	 * see Stores
	 * 
	 * @param tabIndex WRITEME
	 */
	public StorePage (final int tabIndex) {
		if (TootsBook.isLoggedIn ()) {
			buildStorePage (tabIndex);
		} else {
			History.newItem ("login");
		}
	}

	/**
	 * <pre>
	 * twheys@gmail.com Dec 31, 2009
	 * </pre>
	 * 
	 * TO buildAdPanel WRITEME...
	 */
	private void buildAdPanel () {
		final Advertisement adPanel = new Advertisement ();
		adBox = new Box (adPanel, "Advertisment", "<br />", "");
		adBox.pack ();
	}

	/**
	 * <pre>
	 * twheys@gmail.com Feb 23, 2010
	 * </pre>
	 * 
	 * TO buildStorePage WRITEME...
	 * 
	 * @param tabIndex WRITEME
	 */
	private void buildStorePage (final int tabIndex) {
		Window.setTitle ("Home - TootsBook® www.Tootsville.com");
		TootsBook.getUser ();

		TootsBook
				.loadBoxStylesStyleSheet ("/tootbook-resource/themes/box-styles/1359/style.css");
		TootsBook
				.loadPageBGStyleSheet ("/tootbook-resource/themes/page-bg/1361/style.css");
		TootsBook
				.loadTitleBGStyleSheet ("/tootbook-resource/themes/title-bg/login/style.css");

		centerContents = new VerticalPanel ();
		rightContents = new VerticalPanel ();

		centerContents
				.setHorizontalAlignment (HasHorizontalAlignment.ALIGN_CENTER);
		rightContents
				.setHorizontalAlignment (HasHorizontalAlignment.ALIGN_CENTER);

		buildTabbedStoreContent (tabIndex);
		storeBox.addStyleName ("store-center-panel");
		centerContents.add (storeBox);

		buildAdPanel ();
		adBox.addStyleName ("right-panel");
		rightContents.add (adBox);

		centerContents.setStyleName ("centerContent");
		rightContents.setStyleName ("rightContent");

		add (centerContents);
		add (rightContents);

		TootsBook.hideLoadingBar ();
	}

	/**
	 * <pre>
	 * twheys@gmail.com Feb 23, 2010
	 * </pre>
	 * 
	 * TO buildTabbedStoreContent WRITEME...
	 * 
	 * @param tabIndex WRITEME
	 */
	private void buildTabbedStoreContent (final int tabIndex) {
		storeBox = new TabbedBox ("TootsBook Store", "", "");
		storeBox.addTab (new StoreInventoryPanel (46),
				DisplayText.STORE_PLAYER_CARD);
		storeBox.addTab (new StoreInventoryPanel (42),
				DisplayText.STORE_WALLPAPER);
		storeBox.addTab (new StoreInventoryPanel (44),
				DisplayText.STORE_ICON);
		storeBox.addTab (new StoreInventoryPanel (43),
				DisplayText.STORE_PROFILE_THEME);
		storeBox.addTab (new StoreInventoryPanel (45),
				DisplayText.STORE_NAME_TAG);
		storeBox.pack ();
		storeBox.selectTab (tabIndex);
	}
}
