/**
 * tdesign v0.32.0
 * (c) 2021 tdesign
 * @license MIT
 */

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var dayjs = require('dayjs');
var Vue = require('vue');
var config = require('../config.js');
var calendar_const = require('./const.js');
var utils_renderTnode = require('../utils/render-tnode.js');
require('@babel/runtime/helpers/typeof');

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

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

var CalendarCellItem = Vue__default["default"].extend({
  name: "".concat(calendar_const.COMPONENT_NAME, "-cell"),
  props: {
    item: {
      type: Object,
      "default": function _default() {
        return null;
      }
    },
    theme: {
      type: String,
      "default": function _default() {
        return null;
      }
    },
    fillWithZero: {
      type: Boolean,
      "default": void 0
    },
    t: Function,
    global: Object,
    cell: Function
  },
  computed: {
    allowSlot: function allowSlot() {
      return this.theme === "full";
    },
    disabled: function disabled() {
      return this.item.mode === "month" && this.item.belongTo !== 0;
    },
    valueDisplay: function valueDisplay() {
      if (this.item.mode === "month") {
        var _ref, _this$fillWithZero;

        var dateNum = this.item.date.getDate();
        var fillZero = dateNum < 10 && ((_ref = (_this$fillWithZero = this.fillWithZero) !== null && _this$fillWithZero !== void 0 ? _this$fillWithZero : this.global.fillWithZero) !== null && _ref !== void 0 ? _ref : true);
        return fillZero ? "0".concat(dateNum) : dateNum;
      }

      var map = this.t(this.global.cellMonth).split(",");
      return map[this.item.date.getMonth().toString()];
    },
    cellCls: function cellCls() {
      var _ref2;

      var _this$item = this.item,
          mode = _this$item.mode,
          date = _this$item.date,
          formattedDate = _this$item.formattedDate,
          isCurrent = _this$item.isCurrent;
      var isNow = mode === "year" ? new Date().getMonth() === date.getMonth() : formattedDate === dayjs__default["default"]().format("YYYY-MM-DD");
      return ["".concat(config.prefix, "-calendar__table-body-cell"), (_ref2 = {}, _defineProperty__default["default"](_ref2, "".concat(config.prefix, "-is-disabled"), this.disabled), _defineProperty__default["default"](_ref2, "".concat(config.prefix, "-is-checked"), isCurrent), _defineProperty__default["default"](_ref2, "".concat(config.prefix, "-calendar__table-body-cell--now"), isNow), _ref2)];
    }
  },
  methods: {
    clickCell: function clickCell(e) {
      if (this.disabled) return;
      this.$emit("click", e);
    }
  },
  render: function render() {
    var _this = this;

    var h = arguments[0];
    var item = this.item,
        cellCls = this.cellCls,
        clickCell = this.clickCell,
        valueDisplay = this.valueDisplay,
        allowSlot = this.allowSlot;

    var defaultNode = function defaultNode() {
      return h("span", [h("div", {
        "class": "".concat(config.prefix, "-calendar__table-body-cell-display")
      }, [valueDisplay]), h("div", {
        "class": "".concat(config.prefix, "-calendar__table-body-cell-content")
      }, [allowSlot && utils_renderTnode.renderTNodeJSX(_this, "cellAppend", {
        params: item
      })])]);
    };

    return item && h("div", {
      "class": cellCls,
      "on": {
        "click": clickCell
      }
    }, [typeof this.cell === "function" ? this.cell(this.$createElement, item) : utils_renderTnode.renderTNodeJSXDefault(this, "cell", {
      defaultNode: defaultNode(),
      params: item
    })]);
  }
});

exports["default"] = CalendarCellItem;
//# sourceMappingURL=calendar-cell.js.map
