define('jForumToolbar', ['require','jquery','jForumXhr','jForumUtils', 'js.cookie'], function (require, $, xhr, util, Cookies) {
    'use strict';

    var jForumToolbar = (function () {
        var toolbar = {};
        toolbar.feedback = {
            title: '我要反馈',
            ico: 'ico mdi mdi-comment-alt',
            action: function () {
                var requestURI = BASE + '/feedback';
                $.confirm({
                    title: '意见反馈',
                    closeIcon: true,
                    closeIconClass: 'ico-sm mdi mdi-close',
                    content: '' +
                        '<form action="">' +
                        '<div class="form-group">' +
                        '<input class="form-control" name="subject" required="required" type="text" placeholder="输入反馈的主题"/>' +
                        '</div>' +
                        '<div class="form-group">' +
                        '<textarea class="form-control" name="content" required="required" rows="3" placeholder="输入反馈的内容"></textarea>' +
                        '</div>' +
                        '</form>',
                    buttons: {
                        formSubmit: {
                            text: '提交',
                            btnClass: 'btn-blue',
                            action: function () {
                                var content = this.$content.find('textarea[name=content]').val();
                                if (util.isBlank(content)) {
                                    this.$content.find('textarea[name=content]').focus();
                                    return false;
                                }
                                var requestParam = {};
                                requestParam.content = content;
                                requestParam.title = this.$content.find("input[name=subject]").val();
                                xhr.jsonPost(requestURI, {
                                    data: requestParam,
                                    jsonCallback: function (response) {
                                        response.refresh = false;
                                        util.tipDialog(response);
                                    },
                                    failCallback: function (jqXHR, textStatus, errorThrown) {
                                        util.errorMessage('当前操作因错误而异外中止');
                                    }
                                });
                            }
                        }
                    },
                    onContentReady: function () {
                        var jc = this;
                        this.$content.find('form').on('submit', function (e) {
                            e.preventDefault();
                            jc.$$formSubmit.trigger('click');
                        });
                    }
                });
                return false;
            }
        };
        toolbar.theme = {
            title: '切换模式',
            ico: 'ico mdi mdi-lamp',
            action: function (e) {
                var cacheTheme = Cookies.get('theme');
                if (util.isBlank(cacheTheme)) { //默认为snowhite
                    Cookies.set('theme', 'jetblack');
                    $('body').removeClass('snowhite').addClass('jetblack');
                } else {
                    Cookies.remove('theme');
                    $('body').removeClass('jetblack').addClass('snowhite');
                }
            }
        };
        toolbar.publish = {
            title: '发布主题',
            ico: 'ico mdi mdi-edit',
            action: function (e) {
                $(this).attr('href', '/topic/create');
            }
        };
        toolbar.poster = {
            title: '分享话题',
            ico: 'ico mdi mdi-link',
            action: function (e) {
                $(this).attr('href', '/topic/poster');
            }
        };
        toolbar.toTop = {
            title: '返回顶部',
            ico: 'ico mdi mdi-chevron-up',
            action: function (e) {
                $('html, body').animate({ scrollTop: 0 }, 500);
            }
        };
        return toolbar;
    })();
    return jForumToolbar;
});