/**
 * ldesign v0.4.2
 * (c) 2023 ldesign
 * @license MIT
 */

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
import { defineComponent, computed, createVNode, Fragment } from 'vue';
import dayjs from 'dayjs';
import { useCommonClassName } from '../hooks/useConfig.js';
import { useContent } from '../hooks/tnode.js';
import { useCalendarCellClass } from './hook/useCalendarClass.js';
import '../config-provider/useConfig.js';
import 'lodash/cloneDeep';
import 'lodash/isFunction';
import 'lodash/isString';
import '../config-provider/context.js';
import 'lodash/mergeWith';
import 'lodash/merge';
import 'lodash/isArray';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '@babel/runtime/helpers/typeof';
import '../_chunks/dep-c9c789a8.js';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../utils/render-tnode.js';
import 'lodash/isEmpty';
import 'lodash/isObject';
import './const.js';

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var clickTypeEmitEventMap = {
  click: "click",
  dblclick: "dblclick",
  contextmenu: "rightclick"
};
var CalendarCellItem = defineComponent({
  name: "TCalendarCell",
  inheritAttrs: false,
  props: {
    item: {
      type: Object,
      "default": function _default() {
        return null;
      }
    },
    fillWithZero: {
      type: Boolean,
      "default": void 0
    },
    theme: {
      type: String,
      "default": function _default() {
        return null;
      }
    },
    t: Function,
    global: Object,
    cell: [String, Function],
    cellAppend: [String, Function]
  },
  emits: _toConsumableArray(Object.values(clickTypeEmitEventMap)),
  setup: function setup(props, _ref) {
    var emit = _ref.emit;
    var renderContent = useContent();
    var cls = useCalendarCellClass();
    var _useCommonClassName = useCommonClassName(),
      STATUS = _useCommonClassName.STATUS;
    var valueDisplay = computed(function () {
      if (props.item.mode === "month") {
        var _ref2, _props$fillWithZero;
        var dateNum = props.item.date.getDate();
        var fillZero = dateNum < 10 && ((_ref2 = (_props$fillWithZero = props.fillWithZero) !== null && _props$fillWithZero !== void 0 ? _props$fillWithZero : props.global.fillWithZero) !== null && _ref2 !== void 0 ? _ref2 : true);
        return fillZero ? "0".concat(dateNum) : dateNum;
      }
      var map = props.t(props.global.cellMonth).split(",");
      return map[props.item.date.getMonth().toString()];
    });
    var allowSlot = computed(function () {
      return props.theme === "full";
    });
    var disabled = computed(function () {
      return props.item.mode === "month" && props.item.belongTo !== 0;
    });
    var cellCls = computed(function () {
      var _ref3;
      var _props$item = props.item,
        mode = _props$item.mode,
        date = _props$item.date,
        formattedDate = _props$item.formattedDate,
        isCurrent = _props$item.isCurrent;
      var now = new Date();
      var isNow = mode === "year" ? now.getMonth() === date.getMonth() && now.getFullYear() === date.getFullYear() : formattedDate === dayjs().format("YYYY-MM-DD");
      return [cls.tableBodyCell.value, (_ref3 = {}, _defineProperty(_ref3, STATUS.value.disabled, disabled.value), _defineProperty(_ref3, STATUS.value.checked, isCurrent), _defineProperty(_ref3, cls.tableBodyCell4Now.value, isNow), _ref3)];
    });
    var clickCell = function clickCell(e) {
      if (disabled.value) return;
      var emitName = clickTypeEmitEventMap[e.type];
      emit(emitName, e);
    };
    var renderDefaultNode = function renderDefaultNode() {
      return createVNode(Fragment, null, [createVNode("div", {
        "class": cls.tableBodyCellDisplay.value
      }, [valueDisplay.value]), createVNode("div", {
        "class": cls.tableBodyCellCsontent.value
      }, [allowSlot.value && renderContent("cellAppend", void 0, {
        params: _objectSpread({}, props.item)
      })])]);
    };
    return function () {
      return props.item && createVNode("td", {
        "class": cellCls.value,
        "onClick": clickCell,
        "onDblclick": clickCell,
        "onContextmenu": clickCell
      }, [renderContent("cell", void 0, {
        defaultNode: renderDefaultNode(),
        params: _objectSpread({}, props.item)
      })]);
    };
  }
});

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