/* exported UIPStyling*/
/* global editor, Utils, UIProvider*/
/**
 *
 * @param {ProviderData} data
 * @constructor
 */
var UIPStyling = function (data) {
    'use strict';

    UIPStyling.superclass.constructor.call(this, data);

    /**
     *
     * @param {Object} value Structure with gallery item properties
     * @param {String} value.class Class name of the group.
     */
    this.click = function (value) {
        if (!editor.documentBody) {
            return;
        }

        var nodes = editor.documentBody.find('.' + value.class);
        if (!nodes || !nodes.length) {
            return;
        }
        var offsetTop = nodes[0].offsetTop;
        editor.documentContentWindow.scrollTop(offsetTop);
    };

    var onCategoriesChanged = function()
    {
        while(this.items().length) {
            this.items.pop();
        }
        if (window.stylingController) {
            ko.utils.arrayPushAll(this.items, window.stylingController.categories);
        }
    }.bind(this);

    onCategoriesChanged();

    // Subscribe
    if (window.stylingController)
        $(window.stylingController).on('categoriesChanged', onCategoriesChanged);

    // Unsubscribe
    this.dispose = function () {
        UIPStyling.superclass.dispose.call(this);
        if (window.stylingController)
            $(window.stylingController).off('categoriesChanged', onCategoriesChanged);
    };
};

Utils.extend(UIPStyling, UIProvider);