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

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var Vue = require('vue');
var datePicker_basic_header = require('../basic/header.js');
var datePicker_basic_table = require('../basic/table.js');
var datePicker_props = require('../props.js');
var config = require('../../config.js');
var _common_js_datePicker_utils = require('../../_common/js/date-picker/utils.js');
require('tdesign-icons-vue');
require('../../button/button.js');
require('../../_chunks/dep-33ee4bce.js');
require('../../utils/classnames.js');
require('../../loading/index.js');
require('../../loading/loading.js');
require('../../loading/icon/gradient.js');
require('../../_common/js/loading/circle-adapter.js');
require('../../_common/js/utils/set-style.js');
require('../../_common/js/utils/helper.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('@babel/runtime/helpers/slicedToArray');
require('../../utils/dom.js');
require('raf');
require('lodash/isString');
require('../../utils/easing.js');
require('../../utils/render-tnode.js');
require('@babel/runtime/helpers/typeof');
require('lodash/isObject');
require('../../utils/transfer-dom.js');
require('../../loading/props.js');
require('../../utils/withInstall.js');
require('lodash/capitalize');
require('../../loading/plugin.js');
require('../../button/props.js');
require('../../utils/ripple.js');
require('../../config-provider/config-receiver.js');
require('lodash/mergeWith');
require('../../config-provider/context.js');
require('lodash/merge');
require('../../_common/js/global-config/default-config.js');
require('../../_common/js/global-config/locale/zh_CN.js');
require('../../utils/mixins.js');
require('../basic/cell.js');
require('@babel/runtime/helpers/extends');
require('lodash/chunk');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var Vue__default = /*#__PURE__*/_interopDefaultLegacy(Vue);

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__default["default"](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__default["default"].extend({
  name: "TDatePanel",
  components: {
    TDateHeader: datePicker_basic_header["default"],
    TDateTable: datePicker_basic_table["default"]
  },
  inheritAttrs: false,
  props: {
    global: {
      type: Object
    },
    value: {
      type: Date,
      "default": function _default() {
        return _common_js_datePicker_utils.getToday();
      }
    },
    mode: datePicker_props["default"].mode,
    minDate: Date,
    maxDate: Date,
    firstDayOfWeek: datePicker_props["default"].firstDayOfWeek,
    disableDate: datePicker_props["default"].disableDate,
    onChange: datePicker_props["default"].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 = _common_js_datePicker_utils.getWeeks({
            year: year,
            month: month
          }, options);
          break;

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

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

      var start = type === "date" || type === mode ? value : new Date(year, month);
      return _common_js_datePicker_utils.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(_common_js_datePicker_utils.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 = _common_js_datePicker_utils.addMonth(current, monthCount);
          break;

        case -1:
          next = _common_js_datePicker_utils.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(config.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()
      })
    })]);
  }
});

exports["default"] = TDate;
//# sourceMappingURL=date.js.map
