/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

import { defineComponent, computed } from '@vue/composition-api';
import { p as parseToDayjs } from '../../../chunks/format.js';
import { usePrefixClass } from '../../../hooks/use-config.js';
import TDatePickerCell from './Cell.js';
import { useConfig } from '../../config-provider/useConfig.js';
import '../../../chunks/dayjs.min-c4f4ce86.js';
import '../../../chunks/_commonjsHelpers-2e6815bd.js';
import '../../../chunks/log.js';
import '../../../chunks/utils.js';
import '../../../chunks/defineProperty-838e4192.js';
import '../../../chunks/_isIndex-52887d1e.js';
import '../../../chunks/isFunction-91acade7.js';
import '../../../chunks/isObjectLike-c22c7e3b.js';
import '../../../chunks/isSymbol-a38a5184.js';
import '../../config-provider/context.js';
import 'lodash';
import '../../../chunks/zh_CN.js';
import '../../config-provider/type.js';

var TDateTable = defineComponent({
  name: "LDatePickerTable",
  props: {
    mode: {
      type: String,
      default: "date"
    },
    firstDayOfWeek: Number,
    data: Array,
    time: String,
    value: [String, Number, Array, Date],
    format: String,
    onCellClick: Function,
    onCellMouseEnter: Function,
    onCellMouseLeave: Function
  },
  setup(props) {
    const COMPONENT_NAME = usePrefixClass("date-picker__table");
    const {
      global
    } = useConfig("datePicker");
    const {
      weekdays,
      weekAbbreviation
    } = global.value;
    const weekArr = computed(() => {
      const _weekArr = [];
      let wi = props.firstDayOfWeek - 1;
      const len = weekdays.length;
      while (_weekArr.length < len) {
        _weekArr.push(weekdays[wi]);
        wi = (wi + len + 1) % len;
      }
      if (props.mode === "week") _weekArr.unshift(weekAbbreviation);
      return _weekArr;
    });
    const showThead = computed(() => props.mode === "date" || props.mode === "week");
    const weekRowClass = (value, format, targetValue) => {
      if (props.mode !== "week") return {};
      if (Array.isArray(value)) {
        if (!value.length) return {};
        const [startObj, endObj] = value.map(v => parseToDayjs(v, format));
        const startYear = startObj.year();
        const startWeek = startObj.week();
        const endYear = endObj && endObj.year();
        const endWeek = endObj && endObj.week();
        const targetObj = parseToDayjs(targetValue, format);
        const targetYear = targetObj.year();
        const targetWeek = targetObj.week();
        const isActive = targetYear === startYear && targetWeek === startWeek || targetYear === endYear && targetWeek === endWeek;
        const isRange = targetYear >= startYear && targetYear <= endYear && targetWeek > startWeek && targetWeek < endWeek;
        return {
          [`${COMPONENT_NAME.value}-${props.mode}-row--active`]: isActive,
          [`${COMPONENT_NAME.value}-${props.mode}-row--range`]: isRange
        };
      }
      return {
        [`${COMPONENT_NAME.value}-${props.mode}-row--active`]: parseToDayjs(value, format).week() === parseToDayjs(targetValue, format).week()
      };
    };
    return {
      COMPONENT_NAME,
      weekArr,
      showThead,
      weekRowClass
    };
  },
  render() {
    const h = arguments[0];
    const {
      COMPONENT_NAME,
      weekArr,
      showThead,
      weekRowClass
    } = this;
    return h("div", {
      "class": COMPONENT_NAME,
      "on": {
        "mouseleave": e => {
          var _this$onCellMouseLeav;
          return (_this$onCellMouseLeav = this.onCellMouseLeave) === null || _this$onCellMouseLeav === void 0 ? void 0 : _this$onCellMouseLeav.call(this, {
            e
          });
        }
      }
    }, [h("table", [showThead && h("thead", [h("tr", [weekArr.map((value, i) => h("th", {
      "key": i
    }, [value]))])]), h("tbody", [this.data.map((row, i) => h("tr", {
      "key": i,
      "class": {
        [`${COMPONENT_NAME}-${this.mode}-row`]: true,
        ...weekRowClass(this.value, this.format, row[0].value)
      }
    }, [row.map((col, j) => h(TDatePickerCell, {
      "key": j,
      "props": {
        ...{
          time: this.time,
          onClick: this.onCellClick,
          onMouseEnter: this.onCellMouseEnter,
          ...col
        }
      }
    }))]))])])]);
  }
});

export { TDateTable as default };
//# sourceMappingURL=Table.js.map
