'use strict';

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

var normalizeComponent = require('./normalize-component-6fa50395.js');
var ThemeMixin = require('./ThemeMixin-a2f817cd.js');
var svgAtom = require('./svg-atom-d2541b7d.js');

//
var SORTING_DIRECTIONS = {
  DESC: 'desc',
  ASC: 'asc'
};
var script = {
  name: 'VTableHeadCell',
  props: {
    sortingBy: {
      type: String,
      default: null
    },
    sortingValue: {
      type: Object,
      default: function _default() {
        return {
          by: null,
          direction: SORTING_DIRECTIONS.DESC
        };
      }
    }
  },
  computed: {
    vTableHeadCellCssClass: function vTableHeadCellCssClass() {
      return Object.assign(this.themeCssClass, {
        'v-table-head-cell': true,
        'is-sortable': !!this.sortingBy
      });
    },
    sortIcon: function sortIcon() {
      if (this.sortingValue.direction === SORTING_DIRECTIONS.ASC) {
        return 'caret-up';
      }

      return 'caret-down';
    },
    isSortable: function isSortable() {
      return !!this.sortingBy && this.sortingBy === this.sortingValue.by;
    },
    newDirection: function newDirection() {
      var _this$sortingValue = this.sortingValue,
          by = _this$sortingValue.by,
          direction = _this$sortingValue.direction;

      if (by === this.sortingBy && direction === SORTING_DIRECTIONS.DESC) {
        return SORTING_DIRECTIONS.ASC;
      }

      return SORTING_DIRECTIONS.DESC;
    }
  },
  methods: {
    onClick: function onClick() {
      if (!this.sortingBy) {
        return;
      }

      this.$emit('sorting', {
        by: this.sortingBy,
        direction: this.newDirection
      });
    }
  },
  mixins: [ThemeMixin.ThemeMixin],
  components: {
    SvgAtom: svgAtom.SvgAtom
  }
};

/* script */
const __vue_script__ = script;

/* template */
var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('th',{class:_vm.vTableHeadCellCssClass},[_c('a',{staticClass:"v-table-head-cell-sort-wrapper",attrs:{"href":"#"},on:{"click":function($event){$event.preventDefault();return _vm.onClick($event)}}},[_vm._t("default"),_vm._v(" "),(_vm.isSortable)?_c('svg-atom',{staticClass:"v-table-head-cell-sort-icon",attrs:{"name":_vm.sortIcon,"width":"8","height":"8"}}):_vm._e()],2)])};
var __vue_staticRenderFns__ = [];

  /* style */
  const __vue_inject_styles__ = undefined;
  /* scoped */
  const __vue_scope_id__ = undefined;
  /* module identifier */
  const __vue_module_identifier__ = undefined;
  /* functional template */
  const __vue_is_functional_template__ = false;
  /* style inject */
  
  /* style inject SSR */
  

  
  var VTableHeadCell = normalizeComponent.__vue_normalize__(
    { render: __vue_render__, staticRenderFns: __vue_staticRenderFns__ },
    __vue_inject_styles__,
    __vue_script__,
    __vue_scope_id__,
    __vue_is_functional_template__,
    __vue_module_identifier__,
    undefined,
    undefined
  );

exports.default = VTableHeadCell;
