/*	
 Copyright 2014 Adobe Systems Incorporated.  All rights reserved. 
*/

/*jslint vars: true, plusplus: true, devel: true, browser: true, nomen: true, maxerr: 50 */
/*global console*/

var HelloDreamweaver = function () {
	"use strict";

    this.oname = "HelloDreamweaver";

    /**
     * Private debug flag for this object container.
     */
    var debugMode = false;

    /**
     * Content URL's for the point product.
     */
    this.url =
    {
        online  : "https://helpx.adobe.com/dreamweaver/hello/v1_6/index.html",
        offline : "/Content/HelloWelcome/HTML5/offline/index.html"
    }

    /**
     * All the point products seem to have implemented a different event types, so we need this 
     * definition here until we can standardize them.
     */
    this.events =   {
		pipEventType                    : (void 0), //"com.adobe.hello.extension.events.LOGPIP",
		aboutToCloseEvent               : (void 0), //"com.adobe.hello.extension.events.aboutToAutomaticallyCloseHello",
		handleExecuteMenuCommand        : (void 0), //"com.adobe.hello.extension.events.handleExecuteMenuCommand",
		handleRecentFileOpen            : (void 0), //"com.adobe.hello.extension.events.handleRecentFileOpen",
		contentTabChangedNotification   : (void 0), //"com.adobe.hello.extension.events.contentTabChangedNotification",
		isInContentTutorialNotification : (void 0)  //"com.adobe.hello.extension.events.isInContentTutorialNotification"
	};

    /**
     * UI element definitions.
     */
    this.ui     =   {
		create  :   {
			initialImage    : "images/CreateInitialExp_DRMV.jpg",
			backgroundColor : "#FFFEF0",
			dividerColor    : "#88ff32"
		},
		footer  :   {
			helpURL         : "http://www.adobe.com/go/Hello_Dw_Help",
			helpLabel       : "Dreamweaver Help",
			forumsURL       : "http://www.adobe.com/go/Hello_Dw_Forums",
			forumsLabel     : "Forums",
			inspireURL      : "http://www.adobe.com/go/Hello_Dw_Blogs",
			inspireLabel    : "Blog",
			blogURL         : "http://www.adobe.com/go/Hello_Dw_Addons",
			blogLabel       : "Add-ons"
		}
	};

	/**
     * this.dWLog - temporary logging - DW spider monkey JS uses this to log message in CEF console
     */
	this.dWLog = function (str) {
		if (window.dwBridge && window.dwBridge.enableLog) {
			console.log("DWLOG: " + str);
		}
	};

	/**
     * DW bridge for Hello 
     */
	this.DWJsonDataRecieved = function (data) {
		this.dWLog("DWJsonDataRecieved");
		var strData = null;

		if (typeof data == 'object') {
			strData = JSON.stringify(data);
		} else {
			strData = data;
		}

		this.dWLog(strData);
		if (this.DWGetUserJsonCallbackObj) {
			this.DWGetUserJsonCallbackObj.callback(strData);
		}
	};

	/**
     * Get the Hello JSON data corresponding to the currently logged in user.
     *
     * @param callback      function object which will be called on data generation completion
     */
    HelloDreamweaver.prototype.getUserJsonData = function (callback) {
		this.dWLog("DWGetPersonalizationInfo");
		if (!callback) {
			callback = function (result) {};
		}
		this.dWLog("DWGetPersonalizationInfo2 " + window.dwBridge);

		// DW bridge expects callback object instead of function.
		this.DWGetUserJsonCallbackObj = {};
		this.DWGetUserJsonCallbackObj.callback = callback;
		this.DWGetUserJsonCallbackObj.rawJsonData = this.DWJsonDataRecieved.bind(this);

		if (window.dwBridge) {
			window.dwBridge.hostAppGetPersonalizationInfo(this.DWGetUserJsonCallbackObj);
		}
	};

	/**
     * Opens an existing document.  If the specified path is the constant string
     * "open" then it will open the browse/open file UI in the host application.
     *
     * @param fullPath      string object containing the path or ID of the existing
     *                      document to open
     */
    HelloDreamweaver.prototype.openExistingDocument = function (fullPath) {
		this.dWLog("DWOpenDoc");
		window.dwBridge.hostAppOpenDoc(fullPath);
	};

	/**
     * Create a new document of the specified type by showing the appropriate new document
     * UI.  If the 'suppressNewDocUI' is true then the document created with default params
     * and the new document UI is not shown.
     *
     * @param documentType          string object containing the ID of the new doc type to 
     *                              create
     * @param suppressNewDocUI      boolean value indicating true to not show the new doc UI, 
     *                              false otherwise
     */
    HelloDreamweaver.prototype.openDocumentOfType = function (documentType, suppressNewDocUI) {
		this.dWLog("DWCreateNewDoc");
		window.dwBridge.hostAppCreateNewDoc(documentType, suppressNewDocUI);
	};

	/**
     * Sets the "Don't Show Again" preference in the host application.
     * 
     * @param dontShowAgain     boolean value indicating true if "dont show again" was
     *                          requested, false otherwise
     */
    HelloDreamweaver.prototype.setDontShowAgainPreference = function (dontShowAgain) {
		this.dWLog("DWSetDoNotShowAgainPreference");
		window.dwBridge.hostAppSetDoNotShowAgainPreference(dontShowAgain);
	};

	/**
     * Attempt to reload the Hello URL from the server.
     */
    HelloDreamweaver.prototype.retryLoadFromServer = function () {
		this.dWLog("DWRetryLoadFromServer");
		window.dwBridge.hostAppRetryLoadFromServer();
	};

	/**
     * Auto-close the Hello UI interface.
     */
    HelloDreamweaver.prototype.notifyDoneWithDialog = function () {
		this.dWLog("DWNotifyDoneWithUI");
		window.dwBridge.hostAppNotifyDoneWithUI();
	};

	/**
     * Indicate that the requested URL failed to load.
     *
     * @param errorString       string object containing the error description
     */
    HelloDreamweaver.prototype.notifyFailedToLoad = function (errorString) {
		this.dWLog("DWNotifyFailedToLoad");
		window.dwBridge.hostAppNotifyFailedToLoad(errorString);
	};

	/**
     * Send a notification message to the host application indicating the content has entered
     * a tutorial.
     * 
     * @param isInContentTutorial   boolean value indicating true if content is tutorial, false otherwise
     */
    HelloDreamweaver.prototype.notifyInContentTutorial = function (isInContentTutorial) {
		this.dWLog("DWNotifyInContentTutorial");
		window.dwBridge.hostAppNotifyInContentTutorial(isInContentTutorial);
	};

	/**
     * Send a notification message to the host application indicating the conent tab has changed.
     * 
     * @param currentTab        string object containing the current tab's ID
     */
    HelloDreamweaver.prototype.notifyContentTabChanged = function (currentTab) {
		this.dWLog("DWNotifyContentTabChanged");
		window.dwBridge.hostAppNotifyContentTabChanged(currentTab);
	};

	/**
     * Open URL in default browser
     * 
     * @param url        string object containing the url
     */
    HelloDreamweaver.prototype.openLinkInDefaultBrowser = function (url) {
		this.dWLog("dwOpenURLInDefaultBrowser");
		window.dwBridge.openURLInDefaultBrowser(url);
	};

};
