/**
 * tdesign v0.39.1-alpha.1
 * (c) 2022 tdesign
 * @license MIT
 */

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import Vue from 'vue';
import TDateHeader from '../basic/header.js';
import TDateTable from '../basic/table.js';
import props from '../props.js';
import { prefix } from '../../config.js';
import { getToday, getYears, getMonths, getWeeks, flagActive, firstUpperCase, subtractMonth, addMonth } from '../../_common/js/date-picker/utils.js';
import 'tdesign-icons-vue';
import '../../button/button.js';
import '../../_chunks/dep-1ec74b8b.js';
import '../../utils/classnames.js';
import '../../loading/index.js';
import '../../loading/loading.js';
import '../../loading/icon/gradient.js';
import '../../_common/js/loading/circle-adapter.js';
import '../../_common/js/utils/set-style.js';
import '../../_common/js/utils/helper.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@babel/runtime/helpers/slicedToArray';
import '../../utils/dom.js';
import 'raf';
import 'lodash/isString';
import '../../utils/easing.js';
import '../../utils/render-tnode.js';
import '@babel/runtime/helpers/typeof';
import 'lodash/isObject';
import '../../utils/transfer-dom.js';
import '../../loading/props.js';
import '../../utils/withInstall.js';
import 'lodash/capitalize';
import './style/index.js';
import '../../loading/type.js';
import '../../loading/plugin.js';
import '../../button/props.js';
import '../../utils/ripple.js';
import '../../config-provider/config-receiver.js';
import 'lodash/mergeWith';
import '../../config-provider/context.js';
import 'lodash/merge';
import '../../_common/js/global-config/default-config.js';
import '../../_common/js/global-config/locale/zh_CN.js';
import '../../config-provider/type.js';
import '../../utils/mixins.js';
import '../basic/cell.js';
import '@babel/runtime/helpers/extends';
import 'lodash/chunk';

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var TDate = Vue.extend({
  name: "TDatePanel",
  components: {
    TDateHeader: TDateHeader,
    TDateTable: TDateTable
  },
  inheritAttrs: false,
  props: {
    global: {
      type: Object
    },
    value: {
      type: Date,
      "default": function _default() {
        return getToday();
      }
    },
    mode: props.mode,
    minDate: Date,
    maxDate: Date,
    firstDayOfWeek: props.firstDayOfWeek,
    disableDate: props.disableDate,
    onChange: props.onChange
  },
  data: function data() {
    return {
      year: this.value.getFullYear(),
      month: this.value.getMonth(),
      type: this.mode
    };
  },
  computed: {
    tableData: function tableData() {
      var _this$global;

      var year = this.year,
          month = this.month,
          type = this.type,
          value = this.value,
          mode = this.mode,
          disableDate = this.disableDate,
          minDate = this.minDate,
          maxDate = this.maxDate,
          firstDayOfWeek = this.firstDayOfWeek;
      var data;
      var options = {
        disableDate: disableDate,
        minDate: minDate,
        maxDate: maxDate,
        firstDayOfWeek: firstDayOfWeek,
        monthLocal: (_this$global = this.global) === null || _this$global === void 0 ? void 0 : _this$global.months
      };

      switch (type) {
        case "date":
          data = getWeeks({
            year: year,
            month: month
          }, options);
          break;

        case "month":
          data = getMonths(year, options);
          break;

        case "year":
          data = getYears(year, options);
          break;

        default:
          break;
      }

      var start = type === "date" || type === mode ? value : new Date(year, month);
      return flagActive(data, {
        start: start,
        type: type
      });
    }
  },
  watch: {
    mode: function mode(value) {
      this.type = value;
    },
    value: function value(_value) {
      this.year = _value.getFullYear();
      this.month = _value.getMonth();
    }
  },
  methods: {
    getClickHandler: function getClickHandler() {
      return this["click".concat(firstUpperCase(this.type))];
    },
    clickDate: function clickDate(date) {
      this.$props.onChange(date);
    },
    clickMonth: function clickMonth(date) {
      if (this.mode === "month") {
        this.$props.onChange(date);
      } else {
        this.$data.type = "date";
        this.$data.year = date.getFullYear();
        this.$data.month = date.getMonth();
      }
    },
    clickYear: function clickYear(date) {
      if (this.mode === "year") {
        this.$props.onChange(date);
      } else {
        this.$data.type = "month";
        this.$data.year = date.getFullYear();
      }
    },
    clickHeader: function clickHeader(flag) {
      var monthCount = 0;
      var next = null;

      switch (this.$data.type) {
        case "date":
          monthCount = 1;
          break;

        case "month":
          monthCount = 12;
          break;

        case "year":
          monthCount = 120;
      }

      var current = new Date(this.$data.year, this.$data.month);

      switch (flag) {
        case 1:
          next = addMonth(current, monthCount);
          break;

        case -1:
          next = subtractMonth(current, monthCount);
          break;

        case 0:
          next = new Date();
          break;
      }

      this.$data.year = next.getFullYear();
      this.$data.month = next.getMonth();
    },
    onTypeChange: function onTypeChange(type) {
      this.$data.type = type;
    }
  },
  render: function render() {
    var h = arguments[0];
    return h("div", {
      "class": "".concat(prefix, "-date-picker__panel")
    }, [h("t-date-header", {
      "attrs": {
        "year": this.year,
        "month": this.month,
        "type": this.$data.type
      },
      "props": _objectSpread({}, {
        onBtnClick: this.clickHeader,
        onTypeChange: this.onTypeChange
      })
    }), h("t-date-table", {
      "attrs": {
        "type": this.$data.type,
        "first-day-of-week": this.firstDayOfWeek,
        "data": this.tableData
      },
      "props": _objectSpread({}, {
        onCellClick: this.getClickHandler()
      })
    })]);
  }
});

export { TDate as default };
//# sourceMappingURL=date.js.map
