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

'use strict';

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

var vue = require('vue');
var dayjs = require('dayjs');
var isArray = require('lodash/isArray');
var configProvider_useConfig = require('../../config-provider/useConfig.js');
var calendar_const = require('../const.js');
var calendar_utils = require('../utils.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');

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

var dayjs__default = /*#__PURE__*/_interopDefaultLegacy(dayjs);
var isArray__default = /*#__PURE__*/_interopDefaultLegacy(isArray);

function useState(props) {
  var _useConfig = configProvider_useConfig.useConfig(calendar_const.COMPONENT_NAME),
    globalConfig = _useConfig.globalConfig;
  var state = vue.reactive({
    realFirstDayOfWeek: 1,
    curDate: null,
    curDateList: [],
    curSelectedYear: null,
    curSelectedMonth: null,
    curSelectedMode: null,
    isShowWeekend: true,
    controlSize: "medium"
  });
  function toToday() {
    var curDate = calendar_utils.createDefaultCurDate();
    state.curSelectedYear = curDate.year();
    state.curSelectedMonth = parseInt(curDate.format("M"), 10);
  }
  function setCurSelectedYear(year) {
    var curSelectedYear = year ? parseInt("".concat(year), 10) : calendar_utils.createDefaultCurDate().year();
    if (!isNaN(curSelectedYear) && curSelectedYear > 0) state.curSelectedYear = curSelectedYear;
  }
  function setCurSelectedMonth(month) {
    var curSelectedMonth = month ? parseInt("".concat(month), 10) : parseInt(calendar_utils.createDefaultCurDate().format("M"), 10);
    if (!isNaN(curSelectedMonth) && curSelectedMonth > 0 && curSelectedMonth <= 12) state.curSelectedMonth = curSelectedMonth;
  }
  function setCurrentDate(value) {
    if (isArray__default["default"](value)) state.curDate = value && value.length ? dayjs__default["default"](value[0]) : calendar_utils.createDefaultCurDate();else state.curDate = value ? dayjs__default["default"](value) : calendar_utils.createDefaultCurDate();
  }
  function setCurrentDateList(value) {
    if (isArray__default["default"](value)) state.curDateList = value && value.length ? value.map(function (item) {
      return dayjs__default["default"](item);
    }) : [calendar_utils.createDefaultCurDate()];else state.curDateList = value ? [dayjs__default["default"](value)] : [calendar_utils.createDefaultCurDate()];
  }
  function checkDayVisible(day) {
    var re = true;
    if (!state.isShowWeekend) re = day !== 6 && day !== 7;
    return re;
  }
  vue.watch(function () {
    return props.firstDayOfWeek;
  }, function () {
    var _ref, _props$firstDayOfWeek;
    state.realFirstDayOfWeek = (_ref = (_props$firstDayOfWeek = props.firstDayOfWeek) !== null && _props$firstDayOfWeek !== void 0 ? _props$firstDayOfWeek : globalConfig.value.firstDayOfWeek) !== null && _ref !== void 0 ? _ref : 1;
  }, {
    immediate: true
  });
  vue.watch(function () {
    return props.value;
  }, function (v) {
    if (props.multiple) setCurrentDateList(v);else setCurrentDate(v);
  }, {
    immediate: true
  });
  vue.watch(function () {
    return props.year;
  }, function (v) {
    setCurSelectedYear(v);
  }, {
    immediate: true
  });
  vue.watch(function () {
    return props.month;
  }, function (v) {
    setCurSelectedMonth(v);
  }, {
    immediate: true
  });
  vue.watch(function () {
    return props.isShowWeekendDefault;
  }, function (v) {
    state.isShowWeekend = v;
  }, {
    immediate: true
  });
  vue.watch(function () {
    return props.mode;
  }, function (v) {
    state.curSelectedMode = v;
  }, {
    immediate: true
  });
  vue.watch(function () {
    return props.theme;
  }, function (v) {
    if (v === "card") state.controlSize = "small";
    if (v === "full") state.controlSize = "medium";
  }, {
    immediate: true
  });
  return {
    state: state,
    toToday: toToday,
    checkDayVisible: checkDayVisible
  };
}

exports.useState = useState;
//# sourceMappingURL=useState.js.map
