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

import { reactive, watch } from 'vue';
import { d as dayjs } from '../../_chunks/dep-6b4aa943.mjs';
import { i as isArray_1 } from '../../_chunks/dep-e3b14d70.mjs';
import '../../hooks/useConfig.mjs';
import { COMPONENT_NAME } from '../const.mjs';
import { createDefaultCurDate } from '../utils.mjs';
import { useConfig } from '../../config-provider/useConfig.mjs';
import '../../_chunks/dep-b4041200.mjs';
import '../../_chunks/dep-a0b4a044.mjs';
import '../../_chunks/dep-44417261.mjs';
import '../../_chunks/dep-bf74f1c2.mjs';
import '../../_chunks/dep-79821ff2.mjs';
import '../../_chunks/dep-0bfbf721.mjs';
import '../../_chunks/dep-39cc276d.mjs';
import '../../_chunks/dep-6b22dd27.mjs';
import '../../_chunks/dep-c959a6fb.mjs';
import '../../_chunks/dep-0f0c89ff.mjs';
import '../../_chunks/dep-8f777748.mjs';
import '../../_chunks/dep-ae357f26.mjs';
import '../../_chunks/dep-352691c2.mjs';
import '../../_chunks/dep-2cfd5b3a.mjs';
import '../../_chunks/dep-05fa17c9.mjs';
import '../../_chunks/dep-c31e1d9e.mjs';
import '../../_chunks/dep-66d6733b.mjs';
import '../../_chunks/dep-a9c8a5d5.mjs';
import '../../_chunks/dep-10085c61.mjs';
import '../../_chunks/dep-1b058de3.mjs';
import '../../_chunks/dep-c852a61a.mjs';
import '../../_chunks/dep-92e7085e.mjs';
import '../../_chunks/dep-44f056cd.mjs';
import '../../_chunks/dep-23a0f453.mjs';
import '../../_chunks/dep-1cf2b129.mjs';
import '../../_chunks/dep-99920870.mjs';
import '../../_chunks/dep-c7e9ce16.mjs';
import '../../_chunks/dep-3afa94cf.mjs';
import '../../_chunks/dep-ba3c0b2e.mjs';
import '../../_chunks/dep-ee57d235.mjs';
import '../../_common/js/global-config/default-config.mjs';
import '../../_common/js/global-config/locale/zh_CN.mjs';
import '../../_chunks/dep-d52291a9.mjs';
import '../../config-provider/type.mjs';

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_1(value)) state.curDate = value && value.length ? dayjs(value[0]) : createDefaultCurDate();else state.curDate = value ? dayjs(value) : createDefaultCurDate();
  }
  function setCurrentDateList(value) {
    if (isArray_1(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.mjs.map
