/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

'use strict';

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

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('vue');
require('lodash');
require('lodash/mergeWith');
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 dayjs__default = /*#__PURE__*/_interopDefaultLegacy(dayjs);

const classPrefixMixins = components_configProvider_configReceiver.getClassPrefixMixins("calendar");
const clickTypeEmitEventMap = {
  click: "click",
  dblclick: "dblclick",
  contextmenu: "rightclick"
};
var CalendarCellItem = utils_mixins["default"](classPrefixMixins).extend({
  name: "LCalendarCell",
  props: {
    item: {
      type: Object,
      default: () => null
    },
    theme: {
      type: String,
      default: () => null
    },
    fillWithZero: {
      type: Boolean,
      default: void 0
    },
    t: Function,
    global: Object,
    cell: Function
  },
  computed: {
    allowSlot() {
      return this.theme === "full";
    },
    disabled() {
      return this.item.mode === "month" && this.item.belongTo !== 0;
    },
    valueDisplay() {
      if (this.item.mode === "month") {
        const dateNum = this.item.date.getDate();
        const fillZero = dateNum < 10 && (this.fillWithZero ?? this.global.fillWithZero ?? true);
        return fillZero ? `0${dateNum}` : dateNum;
      }
      const map = this.t(this.global.cellMonth).split(",");
      return map[this.item.date.getMonth().toString()];
    },
    cellCls() {
      const {
        mode,
        date,
        formattedDate,
        isCurrent
      } = this.item;
      const isNow = mode === "year" ? new Date().getMonth() === date.getMonth() : formattedDate === dayjs__default["default"]().format("YYYY-MM-DD");
      return [`${this.componentName}__table-body-cell`, {
        [`${this.classPrefix}-is-disabled`]: this.disabled,
        [`${this.classPrefix}-is-checked`]: isCurrent,
        [`${this.componentName}__table-body-cell--now`]: isNow
      }];
    }
  },
  methods: {
    clickCell(e) {
      if (this.disabled) return;
      this.$emit(clickTypeEmitEventMap[e.type], e);
    }
  },
  render() {
    const h = arguments[0];
    const {
      item,
      cellCls,
      clickCell,
      valueDisplay,
      allowSlot
    } = this;
    const defaultNode = () => {
      const cellContentOuterDomStyle = {
        display: "flex",
        flexDirection: "column",
        alignItems: "flex-end"
      };
      return h("div", {
        "style": cellContentOuterDomStyle
      }, [h("div", {
        "class": `${this.componentName}__table-body-cell-display`
      }, [valueDisplay]), h("div", {
        "class": `${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
