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

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
var vue = require('vue');
var dayjs = require('dayjs');
var hooks_useConfig = require('../hooks/useConfig.js');
var hooks_tnode = require('../hooks/tnode.js');
var calendar_hook_useCalendarClass = require('./hook/useCalendarClass.js');
require('../config-provider/useConfig.js');
require('lodash/cloneDeep');
require('lodash/isFunction');
require('lodash/isString');
require('../config-provider/context.js');
require('lodash/mergeWith');
require('lodash/merge');
require('lodash/isArray');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('@babel/runtime/helpers/typeof');
require('../_chunks/dep-f4db2590.js');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../utils/render-tnode.js');
require('lodash/isEmpty');
require('lodash/isObject');
require('./const.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var _toConsumableArray__default = /*#__PURE__*/_interopDefaultLegacy(_toConsumableArray);
var dayjs__default = /*#__PURE__*/_interopDefaultLegacy(dayjs);

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__default["default"](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 = vue.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__default["default"](Object.values(clickTypeEmitEventMap)),
  setup: function setup(props, _ref) {
    var emit = _ref.emit;
    var renderContent = hooks_tnode.useContent();
    var cls = calendar_hook_useCalendarClass.useCalendarCellClass();
    var _useCommonClassName = hooks_useConfig.useCommonClassName(),
      STATUS = _useCommonClassName.STATUS;
    var valueDisplay = vue.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 = vue.computed(function () {
      return props.theme === "full";
    });
    var disabled = vue.computed(function () {
      return props.item.mode === "month" && props.item.belongTo !== 0;
    });
    var cellCls = vue.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__default["default"]().format("YYYY-MM-DD");
      return [cls.tableBodyCell.value, (_ref3 = {}, _defineProperty__default["default"](_ref3, STATUS.value.disabled, disabled.value), _defineProperty__default["default"](_ref3, STATUS.value.checked, isCurrent), _defineProperty__default["default"](_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 vue.createVNode(vue.Fragment, null, [vue.createVNode("div", {
        "class": cls.tableBodyCellDisplay.value
      }, [valueDisplay.value]), vue.createVNode("div", {
        "class": cls.tableBodyCellCsontent.value
      }, [allowSlot.value && renderContent("cellAppend", void 0, {
        params: _objectSpread({}, props.item)
      })])]);
    };
    return function () {
      return props.item && vue.createVNode("td", {
        "class": cellCls.value,
        "onClick": clickCell,
        "onDblclick": clickCell,
        "onContextmenu": clickCell
      }, [renderContent("cell", void 0, {
        defaultNode: renderDefaultNode(),
        params: _objectSpread({}, props.item)
      })]);
    };
  }
});

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