(function (paw, utils, _super, TaskChatCommentComponent) {

    paw.lang.extend(TaskChatCommentPopup, _super);
    function TaskChatCommentPopup(settings, taskData, localization) {
        _super.call(this, 'task-chat-comment', {
            Component: TaskChatCommentComponent,
            styleClass: 'paw-task-chat-comment-popup paw-popup-header-nodivider',
            contentStyleClass: 'paw-holder',
            maximizable: false,
            bind: {
                settings: settings,
                taskData: taskData,
                localization: localization
            }
        });
        this.cachedLastComment = null;
    }

    TaskChatCommentPopup.trigger = function($commentTrigger, $commentValueHolder, triggerSettings, taskData, localization){
        if (utils.value.isSet($commentValueHolder.val())) {
            $commentTrigger.addClass("active");
        }
        var popup = new TaskChatCommentPopup({
            taskChatLogLastEntryUrl: triggerSettings.taskChatLogLastEntryUrl,
            commentPlaceholder: triggerSettings.commentPlaceholder,
            getCommentValue: function () {
                return $commentValueHolder.val();
            },
            onRespond: function (data) {
                if (utils.value.isSet(data.comment) && data.comment.length > 0) {
                    $commentTrigger.addClass("active");
                }
                else {
                    $commentTrigger.removeClass("active");
                }
                $commentValueHolder.val(data.comment);
                popup.hide();
            },
            onCancel: function () {
                popup.hide();
            }
        }, taskData, localization);

        $commentTrigger.on('click', function () {
            popup.show();
        });
        return popup;
    };

    paw.com.taskChatComment.TaskChatCommentPopup = TaskChatCommentPopup;

})(paw, paw.utils, paw.com.Popup, paw.com.taskChatComment.TaskChatCommentComponent);