/**
 * ldesign v0.3.13
 * (c) 2023 ldesign
 * @license MIT
 */

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import { defineComponent, computed, createVNode, mergeProps } from 'vue';
import isArray from 'lodash/isArray';
import { usePrefixClass } from '../../hooks/useConfig.js';
import { parseToDayjs } from '../../_common/js/date-picker/format.js';
import TDatePickerCell from './Cell.js';
import { useConfig } from '../../config-provider/useConfig.js';
import 'lodash/cloneDeep';
import 'lodash/isFunction';
import 'lodash/isString';
import '../../config-provider/context.js';
import 'lodash/mergeWith';
import 'lodash/merge';
import '../../_common/js/global-config/default-config.js';
import '../../_common/js/global-config/locale/zh_CN.js';
import '@babel/runtime/helpers/typeof';
import '../../_chunks/dep-512eb181.js';
import 'dayjs';
import '../../_chunks/dep-ac28b67c.js';
import '../../config-provider/type.js';
import '../../_common/js/date-picker/utils.js';
import '@babel/runtime/helpers/objectDestructuringEmpty';
import '@babel/runtime/helpers/extends';
import '../../_chunks/dep-ccfdbba1.js';
import 'lodash/chunk';
import '../../_common/js/log/index.js';
import '../../_common/js/log/log.js';

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var TDateTable = defineComponent({
  name: "TDatePickerTable",
  props: {
    mode: {
      type: String,
      "default": "date"
    },
    value: [String, Number, Array, Date],
    format: String,
    firstDayOfWeek: Number,
    data: Array,
    time: String,
    onCellClick: Function,
    onCellMouseEnter: Function,
    onCellMouseLeave: Function
  },
  setup: function setup(props) {
    var COMPONENT_NAME = usePrefixClass("date-picker__table");
    var _useConfig = useConfig("datePicker"),
      globalConfig = _useConfig.globalConfig;
    var _globalConfig$value = globalConfig.value,
      weekdays = _globalConfig$value.weekdays,
      weekAbbreviation = _globalConfig$value.weekAbbreviation,
      dayjsLocale = _globalConfig$value.dayjsLocale;
    var weekArr = computed(function () {
      var _weekArr = [];
      var wi = props.firstDayOfWeek - 1;
      var 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;
    });
    var showThead = computed(function () {
      return props.mode === "date" || props.mode === "week";
    });
    var weekRowClass = function weekRowClass(value, format, targetValue) {
      if (props.mode !== "week" || !value) return {};
      if (isArray(value)) {
        var _startObj$locale, _startObj$locale$call, _startObj$locale$call2, _endObj$locale, _endObj$locale$call, _endObj$locale$call$w, _ref;
        if (!value.length) return {};
        var _value$map = value.map(function (v) {
            return v && parseToDayjs(v, format);
          }),
          _value$map2 = _slicedToArray(_value$map, 2),
          startObj = _value$map2[0],
          endObj = _value$map2[1];
        var startYear = startObj && startObj.year();
        var startWeek = startObj === null || startObj === void 0 ? void 0 : (_startObj$locale = startObj.locale) === null || _startObj$locale === void 0 ? void 0 : (_startObj$locale$call = _startObj$locale.call(startObj, dayjsLocale)) === null || _startObj$locale$call === void 0 ? void 0 : (_startObj$locale$call2 = _startObj$locale$call.week) === null || _startObj$locale$call2 === void 0 ? void 0 : _startObj$locale$call2.call(_startObj$locale$call);
        var endYear = endObj && endObj.year();
        var endWeek = endObj === null || endObj === void 0 ? void 0 : (_endObj$locale = endObj.locale) === null || _endObj$locale === void 0 ? void 0 : (_endObj$locale$call = _endObj$locale.call(endObj, dayjsLocale)) === null || _endObj$locale$call === void 0 ? void 0 : (_endObj$locale$call$w = _endObj$locale$call.week) === null || _endObj$locale$call$w === void 0 ? void 0 : _endObj$locale$call$w.call(_endObj$locale$call);
        var targetObj = parseToDayjs(targetValue, format);
        var targetYear = targetObj.year();
        var targetWeek = targetObj.week();
        var isActive = targetYear === startYear && targetWeek === startWeek || targetYear === endYear && targetWeek === endWeek;
        var isRange = targetYear >= startYear && targetYear <= endYear && targetWeek > startWeek && targetWeek < endWeek;
        return _ref = {}, _defineProperty(_ref, "".concat(COMPONENT_NAME.value, "-").concat(props.mode, "-row--active"), isActive), _defineProperty(_ref, "".concat(COMPONENT_NAME.value, "-").concat(props.mode, "-row--range"), isRange), _ref;
      }
      return _defineProperty({}, "".concat(COMPONENT_NAME.value, "-").concat(props.mode, "-row--active"), parseToDayjs(value, format).locale(dayjsLocale).week() === parseToDayjs(targetValue, format).locale(dayjsLocale).week());
    };
    return function () {
      return createVNode("div", {
        "class": COMPONENT_NAME.value,
        "onMouseleave": function onMouseleave(e) {
          var _props$onCellMouseLea;
          return (_props$onCellMouseLea = props.onCellMouseLeave) === null || _props$onCellMouseLea === void 0 ? void 0 : _props$onCellMouseLea.call(props, {
            e: e
          });
        }
      }, [createVNode("table", null, [showThead.value && createVNode("thead", null, [createVNode("tr", null, [weekArr.value.map(function (value, i) {
        return createVNode("th", {
          "key": i
        }, [value]);
      })])]), createVNode("tbody", null, [props.data.map(function (row, i) {
        return createVNode("tr", {
          "key": i,
          "class": _objectSpread(_defineProperty({}, "".concat(COMPONENT_NAME.value, "-").concat(props.mode, "-row"), true), weekRowClass(props.value, props.format, row[0].value))
        }, [row.map(function (col, j) {
          return createVNode(TDatePickerCell, mergeProps(col, {
            "key": j,
            "time": props.time,
            "onClick": props.onCellClick,
            "onMouseEnter": props.onCellMouseEnter
          }), null);
        })]);
      })])])]);
    };
  }
});

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