/**
 * ldesign v0.2.2
 * (c) 2022年9月20日 swimly
 * @license MIT
 */

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import dayjs from 'dayjs';
import { renderLNodeJSX, renderLNodeJSXDefault } from '../../utils/render-node.js';
import mixins from '../../utils/mixins.js';
import { getClassPrefixMixins } from '../config-provider/config-receiver.js';
import '@babel/runtime/helpers/typeof';
import 'vue';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import 'lodash/mergeWith';
import 'lodash';
import '../config-provider/context.js';
import '../../chunks/zh_CN.js';
import '../config-provider/type.js';

var classPrefixMixins = getClassPrefixMixins("calendar");
var clickTypeEmitEventMap = {
  click: "click",
  dblclick: "dblclick",
  contextmenu: "rightclick"
};
var CalendarCellItem = mixins(classPrefixMixins).extend({
  name: "LCalendarCell",
  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().format("YYYY-MM-DD");
      return ["".concat(this.componentName, "__table-body-cell"), (_ref2 = {}, _defineProperty(_ref2, "".concat(this.classPrefix, "-is-disabled"), this.disabled), _defineProperty(_ref2, "".concat(this.classPrefix, "-is-checked"), isCurrent), _defineProperty(_ref2, "".concat(this.componentName, "__table-body-cell--now"), isNow), _ref2)];
    }
  },
  methods: {
    clickCell: function clickCell(e) {
      if (this.disabled) return;
      this.$emit(clickTypeEmitEventMap[e.type], 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(_this.componentName, "__table-body-cell-display")
      }, [valueDisplay]), h("div", {
        "class": "".concat(_this.componentName, "__table-body-cell-content")
      }, [allowSlot && renderLNodeJSX(_this, "cellAppend", {
        params: item
      })])]);
    };

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

export { CalendarCellItem as default };
//# sourceMappingURL=calendar-cell.js.map
