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

import dayjs from 'dayjs';
import { renderLNodeJSXDefault, renderLNodeJSX } from '../../utils/render-node.js';
import mixins from '../../utils/mixins.js';
import { getClassPrefixMixins } from '../config-provider/config-receiver.js';
import 'vue';
import 'lodash';
import 'lodash/mergeWith';
import '../config-provider/context.js';
import '../../_chunks/dep-def4c2ce.js';

const classPrefixMixins = getClassPrefixMixins("calendar");
const clickTypeEmitEventMap = {
  click: "click",
  dblclick: "dblclick",
  contextmenu: "rightclick"
};
var CalendarCellItem = mixins(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().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 && 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
