/**
* Catalogpresentitems class
*/
(function (root) {

    "use strict";

    /**
     * Common object params
     * @type {Object}
     */
    var common = {
            publicMethods: [],
            className: 'Catalogpresentitems'
        },

        /**
         * Main constructor
         * @return {Object} - this handle
         */
        Protected = function () {

            var self = this;

            Observer.subscribe('loadPage', function () {
                self.setEvents();
            });

            return this;
        };


    /**
     * Main prototype
     * @type {Object}
     */
    Protected.prototype = {

        ucFirst: function (string) {
            return string.charAt(0).toUpperCase() + string.slice(1);
        },


        /**
         * Set events to this module.
         * This code fire methods by 'data-action' attribute of '.catalogpresentitems-module-action' element 
         */
        setEvents: function () {


            // get action element
            var action = document.querySelector('.catalogpresentitems-module-action');

            if (action) {

                // try to get attribute
                action = 'action' + this.ucFirst(action.getAttribute('data-action'));
                
                // fire event action
                this[action] && this[action]();
            }
        },

        actionSlider: function () {

            Array.prototype.forEach.call(document.querySelectorAll('.catalogpresentitems-items-slider'), function (slider) {

                var itemsCount = slider.querySelectorAll('.slide-item').length;

                new JsSimpleSlider(slider, {
                    slidesToScroll: 1,
                    cssClasses: {
                        controls: {
                            prev: 'js-simple-slider-btn js-simple-slider-btn-prev fa fa-chevron-left',
                            next: 'js-simple-slider-btn js-simple-slider-btn-next fa fa-chevron-right'
                        }
                    }
                }, function () {
                    slider.classList.remove('-hidden');
                });
                   
                
            });
           
        }
    };

    /**
     * Encapsulation
     * @return {Object} - this handle
     */
    root[common.className] = function () {

        function construct(constructor, args) {

            function Class() {
                return constructor.apply(this, args);
            }

            Class.prototype = constructor.prototype;
            return new Class();
        }

        var publicly = construct(Protected, arguments),
            i,
            l = common.publicMethods.length;

        for (i = 0; i < l; i += 1) {

            (function () {
                var member = common.publicMethods[i];
                root[common.className].prototype[member] = function () {
                    return publicly[member].apply(publicly, arguments);
                };
            }());
        }

        return this;
    };

}(this));

document.addEventListener('DOMContentLoaded', function () {
    
    window.Catalogpresentitems = new Catalogpresentitems();

});