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

import { reactive, watch } from 'vue';
import dayjs from 'dayjs';
import isArray from 'lodash/isArray';
import { useConfig } from '../../config-provider/useConfig.js';
import { COMPONENT_NAME } from '../const.js';
import { createDefaultCurDate } from '../utils.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-e041f5b0.js';

function useState(props) {
  var _useConfig = useConfig(COMPONENT_NAME),
    globalConfig = _useConfig.globalConfig;
  var state = reactive({
    realFirstDayOfWeek: 1,
    curDate: null,
    curDateList: [],
    curSelectedYear: null,
    curSelectedMonth: null,
    curSelectedMode: null,
    isShowWeekend: true,
    controlSize: "medium"
  });
  function toToday() {
    var curDate = createDefaultCurDate();
    state.curSelectedYear = curDate.year();
    state.curSelectedMonth = parseInt(curDate.format("M"), 10);
  }
  function setCurSelectedYear(year) {
    var curSelectedYear = year ? parseInt("".concat(year), 10) : createDefaultCurDate().year();
    if (!isNaN(curSelectedYear) && curSelectedYear > 0) state.curSelectedYear = curSelectedYear;
  }
  function setCurSelectedMonth(month) {
    var curSelectedMonth = month ? parseInt("".concat(month), 10) : parseInt(createDefaultCurDate().format("M"), 10);
    if (!isNaN(curSelectedMonth) && curSelectedMonth > 0 && curSelectedMonth <= 12) state.curSelectedMonth = curSelectedMonth;
  }
  function setCurrentDate(value) {
    if (isArray(value)) state.curDate = value && value.length ? dayjs(value[0]) : createDefaultCurDate();else state.curDate = value ? dayjs(value) : createDefaultCurDate();
  }
  function setCurrentDateList(value) {
    if (isArray(value)) state.curDateList = value && value.length ? value.map(function (item) {
      return dayjs(item);
    }) : [createDefaultCurDate()];else state.curDateList = value ? [dayjs(value)] : [createDefaultCurDate()];
  }
  function checkDayVisible(day) {
    var re = true;
    if (!state.isShowWeekend) re = day !== 6 && day !== 7;
    return re;
  }
  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
  });
  watch(function () {
    return props.value;
  }, function (v) {
    if (props.multiple) setCurrentDateList(v);else setCurrentDate(v);
  }, {
    immediate: true
  });
  watch(function () {
    return props.year;
  }, function (v) {
    setCurSelectedYear(v);
  }, {
    immediate: true
  });
  watch(function () {
    return props.month;
  }, function (v) {
    setCurSelectedMonth(v);
  }, {
    immediate: true
  });
  watch(function () {
    return props.isShowWeekendDefault;
  }, function (v) {
    state.isShowWeekend = v;
  }, {
    immediate: true
  });
  watch(function () {
    return props.mode;
  }, function (v) {
    state.curSelectedMode = v;
  }, {
    immediate: true
  });
  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
  };
}

export { useState };
//# sourceMappingURL=useState.js.map
