(function ($, paw, utils) {
    var _localization = null;
    var _activePopup = null;

    $.fn.noteEditorPopupTrigger = function (settings, getContent) {
        var $elt = $(this);
        var content = utils.value.isFunction(getContent) ? getContent() : null;
        handleTriggerActiveState($elt, content);

        $elt.on('click', function () {
            content = utils.value.isFunction(getContent) ? getContent() : null;
            _activePopup = new paw.com.noteEditor.NoteEditorPopup(settings, _localization);
            _activePopup.show(content, {
                onClose: function (content) {
                    handleTriggerActiveState($elt, content);
                }
            });
        });
        return _activePopup;
    };

    $.noteEditorPopupTrigger = function (localization) {
        if (utils.value.isSet(localization)) {
            _localization = localization;
        }
    }

    function handleTriggerActiveState($elt, content) {
        if (utils.value.isSet(content) && !$elt.hasClass('btn-active')) {
            $elt.addClass('btn-active');
        }
        else if ((!utils.value.isSet(content) || content.length === 0) && $elt.hasClass('btn-active')) {
            $elt.removeClass('btn-active');
        }
    }
})(jQuery, paw, paw.utils);