/**
 * ldesign v0.2.2
 * (c) 2022年9月20日 swimly
 * @license MIT
 */

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import { defineComponent, computed } from '@vue/composition-api';
import { p as parseToDayjs } from '../../../chunks/format.js';
import TDatePickerCell from './Cell.js';
import { usePrefixClass } from '../../../hooks/use-config.js';
import { useConfig } from '../../config-provider/useConfig.js';
import '../../../chunks/dayjs.min-12eb376c.js';
import '@babel/runtime/helpers/typeof';
import '../../../chunks/_commonjsHelpers-ea2bee21.js';
import '../../../chunks/utils2.js';
import '../../../chunks/defineProperty-28395935.js';
import '../../../chunks/_isIndex-1bf92538.js';
import '../../../chunks/isObjectLike-2443c6ff.js';
import '../../../chunks/log.js';
import '../../config-provider/context.js';
import 'lodash';
import '../../../chunks/zh_CN.js';
import '../../config-provider/type.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: "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: function setup(props) {
    var COMPONENT_NAME = usePrefixClass("date-picker__table");

    var _useConfig = useConfig("datePicker"),
        global = _useConfig.global;

    var _global$value = global.value,
        weekdays = _global$value.weekdays,
        weekAbbreviation = _global$value.weekAbbreviation;
    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") return {};

      if (Array.isArray(value)) {
        var _ref;

        if (!value.length) return {};

        var _value$map = value.map(function (v) {
          return parseToDayjs(v, format);
        }),
            _value$map2 = _slicedToArray(_value$map, 2),
            startObj = _value$map2[0],
            endObj = _value$map2[1];

        var startYear = startObj.year();
        var startWeek = startObj.week();
        var endYear = endObj && endObj.year();
        var endWeek = endObj && endObj.week();
        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).week() === parseToDayjs(targetValue, format).week());
    };

    return {
      COMPONENT_NAME: COMPONENT_NAME,
      weekArr: weekArr,
      showThead: showThead,
      weekRowClass: weekRowClass
    };
  },
  render: function render() {
    var _this = this;

    var h = arguments[0];
    var COMPONENT_NAME = this.COMPONENT_NAME,
        weekArr = this.weekArr,
        showThead = this.showThead,
        weekRowClass = this.weekRowClass;
    return h("div", {
      "class": COMPONENT_NAME,
      "on": {
        "mouseleave": function mouseleave(e) {
          var _this$onCellMouseLeav;

          return (_this$onCellMouseLeav = _this.onCellMouseLeave) === null || _this$onCellMouseLeav === void 0 ? void 0 : _this$onCellMouseLeav.call(_this, {
            e: e
          });
        }
      }
    }, [h("table", [showThead && h("thead", [h("tr", [weekArr.map(function (value, i) {
      return h("th", {
        "key": i
      }, [value]);
    })])]), h("tbody", [this.data.map(function (row, i) {
      return h("tr", {
        "key": i,
        "class": _objectSpread(_defineProperty({}, "".concat(COMPONENT_NAME, "-").concat(_this.mode, "-row"), true), weekRowClass(_this.value, _this.format, row[0].value))
      }, [row.map(function (col, j) {
        return h(TDatePickerCell, {
          "key": j,
          "props": _objectSpread({}, _objectSpread({
            time: _this.time,
            onClick: _this.onCellClick,
            onMouseEnter: _this.onCellMouseEnter
          }, col))
        });
      })]);
    })])])]);
  }
});

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