define( function (require, exports, module) {
    'use strict';

    // var conf = {
    //     containerSelector : '',
    //     btnSelector : '',
    //     contentSelector : '',
    //     curClass : ''，
    //     mode : 'click'
    // }

    var Tab = function (conf) {

        return {

            btnSelector : conf.btnSelector,
            $container : $(conf.containerSelector),
            $btns     : $(conf.btnSelector),
            $content  : $(conf.contentSelector),
            curClass : conf.curClass,
            mode : conf.mode,
            callback : conf.callback,

            init : function () {

                var me = this;
                me.$btns.each(function (index, item) {
                    $(this).attr('tab-index', index);
                });

                me.$container.on(me.mode, me.btnSelector,  function (e) {

                    me.$btns.removeClass(me.curClass);
                    $(this).addClass(me.curClass);
                    var inx = $(this).attr('tab-index');

                    me.$content.hide();
                    me.$content.eq(inx).show();
                    if(_.isFunction(me.callback)) {
                        // 绑定此时的this
                        me.callback.call(this);
                    }

                });

                me.$btns.first().addClass(me.curClass);
                me.$content.hide();
                me.$content.first().show();
            }
        };

    };


    module.exports = Tab;



});
