'use strict';

Object.defineProperty(exports, "__esModule", {
    value: true
});

var _mixins = require('../../util/mixins');

var _mixins2 = _interopRequireDefault(_mixins);

var _VSelect = require('../VSelect/VSelect');

var _VSelect2 = _interopRequireDefault(_VSelect);

var _VChip = require('../VChip');

var _VChip2 = _interopRequireDefault(_VChip);

var _header = require('./mixins/header');

var _header2 = _interopRequireDefault(_header);

var _helpers = require('../../util/helpers');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }

exports.default = (0, _mixins2.default)(_header2.default).extend({
    name: 'v-data-table-header-mobile',
    methods: {
        genSortChip: function genSortChip(props) {
            var _this = this;

            var children = [props.item.text];
            var sortIndex = this.options.sortBy.findIndex(function (k) {
                return k === props.item.value;
            });
            var beingSorted = sortIndex >= 0;
            var isDesc = this.options.sortDesc[sortIndex];
            children.push(this.$createElement('div', {
                staticClass: 'v-chip__close',
                class: {
                    'sortable': true,
                    'active': beingSorted,
                    'asc': beingSorted && !isDesc,
                    'desc': beingSorted && isDesc
                }
            }, [this.genSortIcon()]));
            return this.$createElement(_VChip2.default, {
                staticClass: 'sortable',
                nativeOn: {
                    click: function click(e) {
                        e.stopPropagation();
                        _this.$emit('sort', props.item.value);
                    }
                }
            }, children);
        },
        genSortSelect: function genSortSelect() {
            var _this2 = this;

            return this.$createElement(_VSelect2.default, {
                props: {
                    label: 'Sort by',
                    items: this.headers.filter(function (h) {
                        return h.value !== 'data-table-select';
                    }),
                    hideDetails: true,
                    multiple: this.options.multiSort,
                    value: this.options.multiSort ? this.options.sortBy : this.options.sortBy[0]
                },
                on: {
                    change: function change(v) {
                        return _this2.$emit('sort', v);
                    }
                },
                scopedSlots: {
                    selection: function selection(props) {
                        return _this2.genSortChip(props);
                    }
                }
            });
        }
    },
    render: function render(h) {
        var children = [];
        var header = this.headers.find(function (h) {
            return h.value === 'data-table-select';
        });
        if (header && !this.singleSelect) {
            children.push(this.$createElement('div', {
                class: ['v-data-table-header-mobile__select'].concat(_toConsumableArray((0, _helpers.wrapInArray)(header.class))),
                attrs: {
                    width: header.width
                }
            }, [this.genSelectAll()]));
        }
        children.push(this.genSortSelect());
        var th = h('th', {
            attrs: {
                colspan: this.headers.length
            }
        }, [h('div', { staticClass: 'v-data-table-header-mobile__wrapper' }, children)]);
        var tr = h('tr', [th]);
        return h('thead', {
            staticClass: 'v-data-table-header v-data-table-header-mobile'
        }, [tr]);
    }
});
//# sourceMappingURL=VDataTableHeaderMobile.js.map