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

Purpose- 
This file contains the model to create the UI for overlay controls.
*/

/*jslint vars: true, plusplus: true, devel: true, browser: true, nomen: true, maxerr: 50, continue: true */
/*global docWindowObj, DWConstants, ResponsiveLayoutConstants*/

/* AdobePatentID="P5361-US". */

var UIModel = (
    function () {
        "use strict";
        
        // define private variables here.
        
        /**
        containerElement = {
            domElement:<ref>,
            containerElement: true,
            fluidContainer: boolean
        }
        rowElement = {
            domElement:<ref>,
            rowElement: true,
        }
        columnElement = {
            domElement:<ref>,
            columnElement: true,
            columnSpan: number
        }
        */
        var _containerElements = [],
            _rowElements = [],
            _columnElements = [],
            _hiddenElements = [];
        
        /*
            function:UIModelImpl() - Constructor
            Arguments: none
            Return: object.
        */
        var UIModelImpl = function () {
        };
        
        /*
            function:setContainers() - sets the elements identified as containers
            Arguments: array of container elements
            Return: none.
        */
        UIModelImpl.prototype.setContainers = function (containerElements) {
            _containerElements = containerElements;
        };

        /*
            function:setRows() - sets the elements identified as rows
            Arguments: array of row elements
            Return: none.
        */
        UIModelImpl.prototype.setRows = function (rowElements) {
            _rowElements = rowElements;
        };

        /*
            function:setColumns() - sets the elements identified as columns
            Arguments: array of columns elements
            Return: none.
        */
        UIModelImpl.prototype.setColumns = function (columnElements) {
            _columnElements = columnElements;
        };

        UIModelImpl.prototype.setHiddenElements = function (hiddenElements) {
            _hiddenElements = hiddenElements;
        };

        UIModelImpl.prototype.getContainerElements = function () {
            return _containerElements;
        };
        
        UIModelImpl.prototype.getRowElements = function () {
            return _rowElements;
        };
        
        UIModelImpl.prototype.getColumnElements = function () {
            return _columnElements;
        };
        
        UIModelImpl.prototype.getHiddenElements = function (hiddenElements) {
            return _hiddenElements;
        };

        UIModelImpl.prototype.injectDesignTimeCSS = function () {
            var styleID = ResponsiveLayoutConstants.DesignTimeCSSStyleID,
                container = docWindowObj.liveViewExtensionsObject.getExtensionContainer(),
                i = 0;
            var styleObj = docWindowObj.document.getElementById(styleID);
            if (styleObj) {
                container.removeChild(styleObj);
            }
            var designCSS = "",
                style = docWindowObj.document.createElement("style");
            style.type = 'text/css';
            style.id = styleID;

            // construct the design css
            for (i = 0; i < _columnElements.length; i++) {
                designCSS += _columnElements[i].domElement.tagName.toLowerCase() + "[" + DWConstants.DWUniqueId + "='" + _columnElements[i].domElement.getAttribute(DWConstants.DWUniqueId) + "']{min-height: 20px;}";
            }
            for (i = 0; i < _rowElements.length; i++) {
                designCSS += _rowElements[i].domElement.tagName.toLowerCase() + "[" + DWConstants.DWUniqueId + "='" + _rowElements[i].domElement.getAttribute(DWConstants.DWUniqueId) + "']{min-height: 20px;}";
            }
            for (i = 0; i < _containerElements.length; i++) {
                designCSS += _containerElements[i].domElement.tagName.toLowerCase() + "[" + DWConstants.DWUniqueId + "='" + _containerElements[i].domElement.getAttribute(DWConstants.DWUniqueId) + "']{min-height: 20px;}";
            }
            for (i = 0; i < _hiddenElements.length; i++) {
                designCSS += _hiddenElements[i].domElement.tagName.toLowerCase() + "[" + DWConstants.DWUniqueId + "='" + _hiddenElements[i].domElement.getAttribute(DWConstants.DWUniqueId) + "']{min-height: 20px;}";
            }
            // end - design css
            
            style.appendChild(docWindowObj.document.createTextNode(designCSS));
            container.appendChild(style);
        };

        return UIModelImpl;
    }()
);