/**
 * ldesign v0.2.22
 * (c) 2022/12/7 16:21 built by swimly
 * @license MIT
 */

'use strict';

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

var VueCompositionAPI = require('@vue/composition-api');
var utils = require('../../../chunks/utils.js');
var hooks_useConfig = require('../../../hooks/useConfig.js');
require('../../../chunks/defineProperty-19da3d4c.js');
require('../../../chunks/dayjs.min-0f6442fd.js');
require('../../../chunks/_commonjsHelpers-fe796db6.js');
require('../../../chunks/_isIndex-8b06cfbb.js');
require('../../../chunks/isFunction-cb08cfdf.js');
require('../../../chunks/isObjectLike-51896b77.js');
require('../../../chunks/isSymbol-0ea4cedf.js');
require('../../config-provider/useConfig.js');
require('../../config-provider/context.js');
require('lodash/merge');
require('lodash/mergeWith');
require('../../../chunks/zh_CN.js');

var TDatePickerCell = VueCompositionAPI.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(props) {
    const COMPONENT_NAME = hooks_useConfig.usePrefixClass("date-picker__cell");
    const cellClass = VueCompositionAPI.computed(() => [COMPONENT_NAME.value, {
      [`${COMPONENT_NAME.value}--now`]: props.now,
      [`${COMPONENT_NAME.value}--active`]: props.active,
      [`${COMPONENT_NAME.value}--disabled`]: props.disabled,
      [`${COMPONENT_NAME.value}--highlight`]: props.highlight,
      [`${COMPONENT_NAME.value}--hover-highlight`]: props.hoverHighlight,
      [`${COMPONENT_NAME.value}--active-start`]: props.startOfRange,
      [`${COMPONENT_NAME.value}--active-end`]: props.endOfRange,
      [`${COMPONENT_NAME.value}--hover-start`]: props.hoverStartOfRange,
      [`${COMPONENT_NAME.value}--hover-end`]: props.hoverEndOfRange,
      [`${COMPONENT_NAME.value}--additional`]: props.additional,
      [`${COMPONENT_NAME.value}--first-day-of-month`]: props.firstDayOfMonth,
      [`${COMPONENT_NAME.value}--last-day-of-month`]: props.lastDayOfMonth
    }]);
    function handleClick(e) {
      if (props.disabled) return;
      if (props.time) {
        const {
          hours,
          minutes,
          seconds,
          milliseconds,
          meridiem
        } = utils.extractTimeObj(props.time);
        let 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.value, {
        e
      });
    }
    function handleMouseEnter() {
      if (props.disabled) return;
      if (props.time) {
        const {
          hours,
          minutes,
          seconds,
          milliseconds,
          meridiem
        } = utils.extractTimeObj(props.time);
        let 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.value);
    }
    return {
      cellClass,
      COMPONENT_NAME,
      handleClick,
      handleMouseEnter
    };
  },
  render() {
    const h = arguments[0];
    const {
      cellClass,
      COMPONENT_NAME,
      handleClick,
      handleMouseEnter
    } = this;
    return h("td", {
      "class": cellClass,
      "on": {
        "click": handleClick,
        "mouseenter": handleMouseEnter
      }
    }, [h("div", {
      "class": `${COMPONENT_NAME}-inner`
    }, [this.text])]);
  }
});

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