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

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var dayjs = require('dayjs');
var utils_renderNode = require('../../utils/render-node.js');
var utils_mixins = require('../../utils/mixins.js');
var components_configProvider_configReceiver = require('../config-provider/config-receiver.js');
require('@babel/runtime/helpers/typeof');
require('vue');
require('lodash/camelCase');
require('lodash/kebabCase');
require('lodash/mergeWith');
require('lodash');
require('../config-provider/context.js');
require('../../chunks/zh_CN.js');

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 classPrefixMixins = components_configProvider_configReceiver.getClassPrefixMixins("calendar");
var clickTypeEmitEventMap = {
  click: "click",
  dblclick: "dblclick",
  contextmenu: "rightclick"
};
var CalendarCellItem = utils_mixins["default"](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__default["default"]().format("YYYY-MM-DD");
      return ["".concat(this.componentName, "__table-body-cell"), (_ref2 = {}, _defineProperty__default["default"](_ref2, "".concat(this.classPrefix, "-is-disabled"), this.disabled), _defineProperty__default["default"](_ref2, "".concat(this.classPrefix, "-is-checked"), isCurrent), _defineProperty__default["default"](_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 && utils_renderNode.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) : utils_renderNode.renderLNodeJSXDefault(this, "cell", {
      defaultNode: defaultNode(),
      params: item
    })]);
  }
});

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