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

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
var vue = require('vue');
var isArray = require('lodash/isArray');
var hooks_useConfig = require('../../hooks/useConfig.js');
var _common_js_datePicker_format = require('../../_common/js/date-picker/format.js');
var datePicker_base_Cell = require('./Cell.js');
var configProvider_useConfig = require('../../config-provider/useConfig.js');
require('lodash/cloneDeep');
require('lodash/isFunction');
require('lodash/isString');
require('../../config-provider/context.js');
require('lodash/mergeWith');
require('lodash/merge');
require('../../_common/js/global-config/default-config.js');
require('../../_common/js/global-config/locale/zh_CN.js');
require('@babel/runtime/helpers/typeof');
require('../../_chunks/dep-f4db2590.js');
require('dayjs');
require('../../_common/js/date-picker/utils.js');
require('@babel/runtime/helpers/objectDestructuringEmpty');
require('@babel/runtime/helpers/extends');
require('../../_chunks/dep-b7fa06da.js');
require('lodash/chunk');
require('../../_common/js/log/log.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray);
var isArray__default = /*#__PURE__*/_interopDefaultLegacy(isArray);

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__default["default"](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 = vue.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 = hooks_useConfig.usePrefixClass("date-picker__table");
    var _useConfig = configProvider_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 = vue.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 = vue.computed(function () {
      return props.mode === "date" || props.mode === "week";
    });
    var weekRowClass = function weekRowClass(value, format, targetValue) {
      if (props.mode !== "week" || !value) return {};
      if (isArray__default["default"](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 && _common_js_datePicker_format.parseToDayjs(v, format);
          }),
          _value$map2 = _slicedToArray__default["default"](_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 = _common_js_datePicker_format.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__default["default"](_ref, "".concat(COMPONENT_NAME.value, "-").concat(props.mode, "-row--active"), isActive), _defineProperty__default["default"](_ref, "".concat(COMPONENT_NAME.value, "-").concat(props.mode, "-row--range"), isRange), _ref;
      }
      return _defineProperty__default["default"]({}, "".concat(COMPONENT_NAME.value, "-").concat(props.mode, "-row--active"), _common_js_datePicker_format.parseToDayjs(value, format).locale(dayjsLocale).week() === _common_js_datePicker_format.parseToDayjs(targetValue, format).locale(dayjsLocale).week());
    };
    return function () {
      return vue.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
          });
        }
      }, [vue.createVNode("table", null, [showThead.value && vue.createVNode("thead", null, [vue.createVNode("tr", null, [weekArr.value.map(function (value, i) {
        return vue.createVNode("th", {
          "key": i
        }, [value]);
      })])]), vue.createVNode("tbody", null, [props.data.map(function (row, i) {
        return vue.createVNode("tr", {
          "key": i,
          "class": _objectSpread(_defineProperty__default["default"]({}, "".concat(COMPONENT_NAME.value, "-").concat(props.mode, "-row"), true), weekRowClass(props.value, props.format, row[0].value))
        }, [row.map(function (col, j) {
          return vue.createVNode(datePicker_base_Cell["default"], vue.mergeProps(col, {
            "key": j,
            "time": props.time,
            "onClick": props.onCellClick,
            "onMouseEnter": props.onCellMouseEnter
          }), null);
        })]);
      })])])]);
    };
  }
});

exports["default"] = TDateTable;
//# sourceMappingURL=Table.js.map
