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

import { defineComponent, computed } from '@vue/composition-api';
import { e as extractTimeObj } from '../../../_chunks/dep-52f1cb4f.js';
import { usePrefixClass } from '../../../hooks/useConfig.js';
import '../../../_chunks/dep-aacc31a3.js';
import '../../../_chunks/dep-72951546.js';
import '../../../_chunks/dep-102361be.js';
import '../../../_chunks/dep-40693b6f.js';
import '../../../_chunks/dep-c3acb800.js';
import '../../../_chunks/dep-52c80d08.js';
import '../../../_chunks/dep-128cad98.js';
import '../../config-provider/useConfig.js';
import '../../config-provider/context.js';
import 'lodash/merge';
import 'lodash/mergeWith';
import '../../../_chunks/dep-b4fd1955.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(props) {
    const COMPONENT_NAME = usePrefixClass("date-picker__cell");
    const cellClass = 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
        } = 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
        } = 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])]);
  }
});

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