/*
 *      Copyright (c) 2015 Samsung Electronics Co., Ltd
 *
 *      Licensed under the Flora License, Version 1.1 (the "License");
 *      you may not use this file except in compliance with the License.
 *      You may obtain a copy of the License at
 *
 *              http://floralicense.org/license/
 *
 *      Unless required by applicable law or agreed to in writing, software
 *      distributed under the License is distributed on an "AS IS" BASIS,
 *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *      See the License for the specific language governing permissions and
 *      limitations under the License.
 */

/*global define*/

/**
 * Full view helper module.
 *
 * @module helpers/full
 * @requires {@link helpers/constants}
 * @namespace helpers/full
 */

define({
    name: 'helpers/full',
    requires: [
        'helpers/constants'
    ],
    def: function helpersFull(CONST) {
        'use strict';

        /**
         * Returns container with depending on image count.
         *
         * @memberof helpers/full
         * @public
         * @param {number} imageCount Images to display.
         * @returns {number}
         */
        function getContainerWidth(imageCount) {
            var width = 2 * CONST.FULL_LEFT +
                        imageCount * CONST.FULL_ELEMENT_WIDTH;

            if (width < CONST.GALLERY_MIN_WIDTH) {
                width = CONST.GALLERY_MIN_WIDTH;
            }

            return width;
        }

        /**
         * Returns element width.
         *
         * @memberof helpers/full
         * @public
         * @returns {number}
         */
        function getElementWidth() {
            return CONST.FULL_ELEMENT_WIDTH;
        }

        /**
         * Returns element top and left position.
         *
         * @memberof helpers/full
         * @public
         * @param {number} num Element number.
         * @returns {{top: number, left: number}}
         */
        function getElementPosition(num) {
            return {
                top: CONST.FULL_TOP,
                left: CONST.FULL_LEFT + num * CONST.FULL_ELEMENT_WIDTH
            };
        }

        /**
         * Returns scroll left position of given element.
         *
         * @memberof helpers/full
         * @public
         * @param {number} num Element number.
         * @returns {number}
         */
        function getElementScroll(num) {
            return num * CONST.FULL_ELEMENT_WIDTH;
        }

        /**
         * Returns next scroll position.
         *
         * @memberof helpers/full
         * @public
         * @param {number} currentScroll Current scroll position.
         * @param {number} containerWidth Container width.
         * @param {boolean} toRight Should be scrolled to right.
         * @returns {number}
         */
        function getNextScroll(currentScroll, containerWidth, toRight) {
            var scrollTo =
                Math.round(currentScroll / CONST.FULL_ELEMENT_WIDTH) *
                CONST.FULL_ELEMENT_WIDTH;

            if (toRight) {
                scrollTo = scrollTo + CONST.FULL_ELEMENT_WIDTH;
                if (scrollTo > containerWidth - CONST.FULL_ELEMENT_WIDTH) {
                    scrollTo = currentScroll;
                }
            } else {
                scrollTo = scrollTo - CONST.FULL_ELEMENT_WIDTH;
                if (scrollTo < 0) {
                    scrollTo = 0;
                }
            }
            return scrollTo;
        }

        /**
         * Click event handler.
         *
         * @memberof helpers/full
         * @public
         * @returns {number|null} Display mode change.
         */
        function clickHandler() {
            return null;
        }

        /**
         * Long press event handler.
         *
         * @memberof helpers/full
         * @public
         * @returns {number|null}
         */
        function longPressHandler() {
            return CONST.MODE.SELECT;
        }

        /**
         * Double click event handler.
         *
         * @memberof helpers/full
         * @public
         * @returns {number|null}
         */
        function doubleClickHandler() {
            return CONST.MODE.ZOOM;
        }

        return {
            getContainerWidth: getContainerWidth,
            getElementWidth: getElementWidth,
            getElementPosition: getElementPosition,
            getElementScroll: getElementScroll,
            getNextScroll: getNextScroll,
            clickHandler: clickHandler,
            longPressHandler: longPressHandler,
            doubleClickHandler: doubleClickHandler
        };
    }
});
