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

'use strict';

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

var VueCompositionAPI = require('@vue/composition-api');
var format = require('../../../chunks/format.js');
var hooks_useConfig = require('../../../hooks/use-config.js');
var components_datePicker_base_Cell = require('./Cell.js');
var components_configProvider_useConfig = require('../../config-provider/useConfig.js');
require('../../../chunks/dayjs.min-c4f4ce86.js');
require('../../../chunks/_commonjsHelpers-2e6815bd.js');
require('../../../chunks/log.js');
require('../../../chunks/utils.js');
require('../../../chunks/defineProperty-838e4192.js');
require('../../../chunks/_isIndex-52887d1e.js');
require('../../../chunks/isFunction-91acade7.js');
require('../../../chunks/isObjectLike-c22c7e3b.js');
require('../../../chunks/isSymbol-a38a5184.js');
require('../../config-provider/context.js');
require('lodash');
require('../../../chunks/zh_CN.js');

var TDateTable = VueCompositionAPI.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 = hooks_useConfig.usePrefixClass("date-picker__table");
    const {
      global
    } = components_configProvider_useConfig.useConfig("datePicker");
    const {
      weekdays,
      weekAbbreviation
    } = global.value;
    const weekArr = VueCompositionAPI.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 = VueCompositionAPI.computed(() => props.mode === "date" || props.mode === "week");
    const weekRowClass = (value, format$1, targetValue) => {
      if (props.mode !== "week") return {};
      if (Array.isArray(value)) {
        if (!value.length) return {};
        const [startObj, endObj] = value.map(v => format.parseToDayjs(v, format$1));
        const startYear = startObj.year();
        const startWeek = startObj.week();
        const endYear = endObj && endObj.year();
        const endWeek = endObj && endObj.week();
        const targetObj = format.parseToDayjs(targetValue, format$1);
        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`]: format.parseToDayjs(value, format$1).week() === format.parseToDayjs(targetValue, format$1).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(components_datePicker_base_Cell["default"], {
      "key": j,
      "props": {
        ...{
          time: this.time,
          onClick: this.onCellClick,
          onMouseEnter: this.onCellMouseEnter,
          ...col
        }
      }
    }))]))])])]);
  }
});

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