/**
 * ldesign v0.2.2
 * (c) 2022年9月20日 swimly
 * @license MIT
 */

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, computed } from '@vue/composition-api';
import { e as extractTimeObj } from '../../../chunks/utils2.js';
import { usePrefixClass } from '../../../hooks/use-config.js';
import '@babel/runtime/helpers/slicedToArray';
import '@babel/runtime/helpers/typeof';
import '../../../chunks/defineProperty-28395935.js';
import '../../../chunks/dayjs.min-12eb376c.js';
import '../../../chunks/_commonjsHelpers-ea2bee21.js';
import '../../../chunks/_isIndex-1bf92538.js';
import '../../../chunks/isObjectLike-2443c6ff.js';
import '../../config-provider/useConfig.js';
import '../../config-provider/context.js';
import 'lodash';
import '../../../chunks/zh_CN.js';
import '../../config-provider/type.js';

var TDatePickerCell = defineComponent({
  name: "LDatePickerCell",
  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
  },
  setup: function setup(props) {
    var COMPONENT_NAME = usePrefixClass("date-picker__cell");
    var cellClass = computed(function () {
      var _ref;

      return [COMPONENT_NAME.value, (_ref = {}, _defineProperty(_ref, "".concat(COMPONENT_NAME.value, "--now"), props.now), _defineProperty(_ref, "".concat(COMPONENT_NAME.value, "--active"), props.active), _defineProperty(_ref, "".concat(COMPONENT_NAME.value, "--disabled"), props.disabled), _defineProperty(_ref, "".concat(COMPONENT_NAME.value, "--highlight"), props.highlight), _defineProperty(_ref, "".concat(COMPONENT_NAME.value, "--hover-highlight"), props.hoverHighlight), _defineProperty(_ref, "".concat(COMPONENT_NAME.value, "--active-start"), props.startOfRange), _defineProperty(_ref, "".concat(COMPONENT_NAME.value, "--active-end"), props.endOfRange), _defineProperty(_ref, "".concat(COMPONENT_NAME.value, "--hover-start"), props.hoverStartOfRange), _defineProperty(_ref, "".concat(COMPONENT_NAME.value, "--hover-end"), props.hoverEndOfRange), _defineProperty(_ref, "".concat(COMPONENT_NAME.value, "--additional"), props.additional), _defineProperty(_ref, "".concat(COMPONENT_NAME.value, "--first-day-of-month"), props.firstDayOfMonth), _defineProperty(_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 = 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 = 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 {
      cellClass: cellClass,
      COMPONENT_NAME: COMPONENT_NAME,
      handleClick: handleClick,
      handleMouseEnter: handleMouseEnter
    };
  },
  render: function render() {
    var h = arguments[0];
    var cellClass = this.cellClass,
        COMPONENT_NAME = this.COMPONENT_NAME,
        handleClick = this.handleClick,
        handleMouseEnter = this.handleMouseEnter;
    return h("td", {
      "class": cellClass,
      "on": {
        "click": handleClick,
        "mouseenter": handleMouseEnter
      }
    }, [h("div", {
      "class": "".concat(COMPONENT_NAME, "-inner")
    }, [this.text])]);
  }
});

export { TDatePickerCell as default };
//# sourceMappingURL=Cell.js.map
