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

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var vue = require('vue');
var dayjs = require('dayjs');
var isFunction = require('lodash/isFunction');
var isBoolean = require('lodash/isBoolean');
var calendar_const = require('../const.js');
var configProvider_useConfig = require('../../config-provider/useConfig.js');
require('lodash/cloneDeep');
require('lodash/isString');
require('../../config-provider/context.js');
require('lodash/mergeWith');
require('lodash/merge');
require('lodash/isArray');
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-7f0559c3.js');

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

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var dayjs__default = /*#__PURE__*/_interopDefaultLegacy(dayjs);
var isFunction__default = /*#__PURE__*/_interopDefaultLegacy(isFunction);
var isBoolean__default = /*#__PURE__*/_interopDefaultLegacy(isBoolean);

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__default["default"](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 getDefaultControllerConfigData = function getDefaultControllerConfigData() {
  var visible = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
  return {
    visible: visible,
    disabled: false,
    mode: {
      visible: true,
      radioGroupProps: {}
    },
    year: {
      visible: true,
      selectProps: {}
    },
    month: {
      visible: true,
      selectProps: {}
    },
    weekend: {
      visible: true,
      showWeekendButtonProps: {},
      hideWeekendButtonProps: {}
    },
    current: {
      visible: true,
      currentDayButtonProps: {},
      currentMonthButtonProps: {}
    }
  };
};
function userController(props, state) {
  var _useConfig = configProvider_useConfig.useConfig(calendar_const.COMPONENT_NAME),
    globalConfig = _useConfig.globalConfig;
  var options = vue.computed(function () {
    var dayJsFilterDate = dayjs__default["default"]("".concat(state.curSelectedYear, "-").concat(state.curSelectedMonth));
    var re = {
      isShowWeekend: state.isShowWeekend,
      filterDate: dayJsFilterDate.toDate(),
      formattedFilterDate: dayJsFilterDate.format(props.format),
      mode: state.curSelectedMode
    };
    return re;
  });
  var configData = vue.computed(function () {
    var _ref, _props$controllerConf;
    var controllerConfig = (_ref = (_props$controllerConf = props.controllerConfig) !== null && _props$controllerConf !== void 0 ? _props$controllerConf : globalConfig.value.controllerConfig) !== null && _ref !== void 0 ? _ref : true;
    if (isBoolean__default["default"](controllerConfig)) return getDefaultControllerConfigData(controllerConfig);
    return _objectSpread(_objectSpread({}, getDefaultControllerConfigData()), controllerConfig);
  });
  var visible = vue.computed(function () {
    return !!configData.value && configData.value.visible;
  });
  function checkControllerVisible(name) {
    var re = true;
    var conf = configData.value;
    if (!conf || !conf.visible || conf[name] === false || conf[name] && !conf[name].visible) re = false;
    return re;
  }
  function checkControllerDisabled(name, propsName) {
    var re = false;
    var conf = configData.value;
    if (conf && (conf.disabled || conf[name] && conf[name][propsName] && conf[name][propsName].disabled)) re = true;
    return re;
  }
  function emitControllerChange() {
    vue.nextTick(function () {
      isFunction__default["default"](props.onControllerChange) && props.onControllerChange(_objectSpread({}, options.value));
    });
  }
  return {
    options: options,
    configData: configData,
    visible: visible,
    checkControllerVisible: checkControllerVisible,
    checkControllerDisabled: checkControllerDisabled,
    emitControllerChange: emitControllerChange
  };
}

exports.userController = userController;
//# sourceMappingURL=useController.js.map
