/**
 * 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 vue = require('vue');
var dayjs = require('dayjs');
var hooks_useConfig = require('../../hooks/useConfig.js');
var _common_js_datePicker_utils = require('../../_common/js/date-picker/utils.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('@babel/runtime/helpers/slicedToArray');
require('@babel/runtime/helpers/objectDestructuringEmpty');
require('@babel/runtime/helpers/extends');
require('../../_chunks/dep-b7fa06da.js');
require('lodash/chunk');

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

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);

var TDatePickerCell = vue.defineComponent({
  name: "TDatePickerCell",
  props: {
    time: String,
    text: [String, Number],
    value: Date,
    active: Boolean,
    highlight: Boolean,
    disabled: Boolean,
    startOfRange: Boolean,
    endOfRange: Boolean,
    hoverHighlight: Boolean,
    hoverStartOfRange: Boolean,
    hoverEndOfRange: Boolean,
    additional: Boolean,
    now: Boolean,
    firstDayOfMonth: Boolean,
    lastDayOfMonth: Boolean,
    onClick: Function,
    onMouseEnter: Function,
    dayjsObj: dayjs.Dayjs
  },
  setup: function setup(props) {
    var COMPONENT_NAME = hooks_useConfig.usePrefixClass("date-picker__cell");
    var cellClass = vue.computed(function () {
      var _ref;
      return [COMPONENT_NAME.value, (_ref = {}, _defineProperty__default["default"](_ref, "".concat(COMPONENT_NAME.value, "--now"), props.now), _defineProperty__default["default"](_ref, "".concat(COMPONENT_NAME.value, "--active"), props.active), _defineProperty__default["default"](_ref, "".concat(COMPONENT_NAME.value, "--disabled"), props.disabled), _defineProperty__default["default"](_ref, "".concat(COMPONENT_NAME.value, "--highlight"), props.highlight), _defineProperty__default["default"](_ref, "".concat(COMPONENT_NAME.value, "--hover-highlight"), props.hoverHighlight), _defineProperty__default["default"](_ref, "".concat(COMPONENT_NAME.value, "--active-start"), props.startOfRange), _defineProperty__default["default"](_ref, "".concat(COMPONENT_NAME.value, "--active-end"), props.endOfRange), _defineProperty__default["default"](_ref, "".concat(COMPONENT_NAME.value, "--hover-start"), props.hoverStartOfRange), _defineProperty__default["default"](_ref, "".concat(COMPONENT_NAME.value, "--hover-end"), props.hoverEndOfRange), _defineProperty__default["default"](_ref, "".concat(COMPONENT_NAME.value, "--additional"), props.additional), _defineProperty__default["default"](_ref, "".concat(COMPONENT_NAME.value, "--first-day-of-month"), props.firstDayOfMonth), _defineProperty__default["default"](_ref, "".concat(COMPONENT_NAME.value, "--last-day-of-month"), props.lastDayOfMonth), _ref)];
    });
    function handleClick(e) {
      var _props$onClick;
      if (props.disabled) return;
      if (props.time) {
        var _extractTimeObj = _common_js_datePicker_utils.extractTimeObj(props.time),
          hours = _extractTimeObj.hours,
          minutes = _extractTimeObj.minutes,
          seconds = _extractTimeObj.seconds,
          milliseconds = _extractTimeObj.milliseconds,
          meridiem = _extractTimeObj.meridiem;
        var nextHours = hours;
        if (/am/i.test(meridiem) && nextHours === 12) nextHours -= 12;
        if (/pm/i.test(meridiem) && nextHours < 12) nextHours += 12;
        props.value.setHours(nextHours);
        props.value.setMinutes(minutes);
        props.value.setSeconds(seconds);
        props.value.setMilliseconds(milliseconds);
      }
      (_props$onClick = props.onClick) === null || _props$onClick === void 0 ? void 0 : _props$onClick.call(props, props.value, {
        e: e
      });
    }
    function handleMouseEnter() {
      var _props$onMouseEnter;
      if (props.disabled) return;
      if (props.time) {
        var _extractTimeObj2 = _common_js_datePicker_utils.extractTimeObj(props.time),
          hours = _extractTimeObj2.hours,
          minutes = _extractTimeObj2.minutes,
          seconds = _extractTimeObj2.seconds,
          milliseconds = _extractTimeObj2.milliseconds,
          meridiem = _extractTimeObj2.meridiem;
        var nextHours = hours;
        if (/am/i.test(meridiem) && nextHours === 12) nextHours -= 12;
        if (/pm/i.test(meridiem) && nextHours < 12) nextHours += 12;
        props.value.setHours(nextHours);
        props.value.setMinutes(minutes);
        props.value.setSeconds(seconds);
        props.value.setMilliseconds(milliseconds);
      }
      (_props$onMouseEnter = props.onMouseEnter) === null || _props$onMouseEnter === void 0 ? void 0 : _props$onMouseEnter.call(props, props.value);
    }
    return function () {
      return vue.createVNode("td", {
        "class": cellClass.value,
        "onClick": handleClick,
        "onMouseenter": handleMouseEnter
      }, [vue.createVNode("div", {
        "class": "".concat(COMPONENT_NAME.value, "-inner")
      }, [props.text])]);
    };
  }
});

exports["default"] = TDatePickerCell;
//# sourceMappingURL=Cell.js.map
