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

'use strict';

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

var _typeof = require('@babel/runtime/helpers/typeof');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var vue = require('vue');
var isString = require('lodash/isString');
var isObject = require('lodash/isObject');
var omit = require('lodash/omit');
var hooks_tnode = require('../hooks/tnode.js');
var button_index = require('../button/index.js');
require('lodash/isFunction');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../utils/render-tnode.js');
require('lodash/isEmpty');
require('../utils/withInstall.js');
require('../button/button.js');
require('@babel/runtime/helpers/toConsumableArray');
require('../loading/index.js');
require('../loading/directive.js');
require('../loading/plugin.js');
require('../utils/dom.js');
require('../_chunks/dep-f4db2590.js');
require('lodash/isArray');
require('../utils/easing.js');
require('../hooks/useConfig.js');
require('../config-provider/useConfig.js');
require('lodash/cloneDeep');
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('dayjs');
require('../loading/loading.js');
require('@babel/runtime/helpers/slicedToArray');
require('../hooks/useTeleport.js');
require('../loading/props.js');
require('../loading/icon/gradient.js');
require('../_common/js/loading/circle-adapter.js');
require('../_common/js/utils/set-style.js');
require('../_common/js/utils/helper.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('lodash/isNull');
require('lodash/isUndefined');
require('lodash/isNumber');
require('../hooks/useRipple.js');
require('../utils/set-style.js');
require('../hooks/useKeepAnimation.js');
require('../form/hooks.js');
require('../button/props.js');

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

var _typeof__default = /*#__PURE__*/_interopDefaultLegacy(_typeof);
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var isString__default = /*#__PURE__*/_interopDefaultLegacy(isString);
var isObject__default = /*#__PURE__*/_interopDefaultLegacy(isObject);
var omit__default = /*#__PURE__*/_interopDefaultLegacy(omit);

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; }
function useAction(action) {
  var instance = vue.getCurrentInstance();
  var renderTNodeJSX = hooks_tnode.useTNodeJSX();
  var getDefaultConfirmBtnProps = function getDefaultConfirmBtnProps(options) {
    var _omit;
    var globalConfirm = options.globalConfirm,
      theme = options.theme,
      globalConfirmBtnTheme = options.globalConfirmBtnTheme;
    var defaultTheme = ((_omit = omit__default["default"](globalConfirmBtnTheme, ["info"])) === null || _omit === void 0 ? void 0 : _omit[theme]) || "primary";
    var props = {
      theme: defaultTheme,
      size: options.size,
      onClick: function onClick(e) {
        action.confirmBtnAction(e);
      }
    };
    if (isString__default["default"](globalConfirm)) props.content = globalConfirm;else if (isObject__default["default"](globalConfirm)) props = _objectSpread(_objectSpread({}, props), globalConfirm);
    return props;
  };
  var getDefaultCancelBtnProps = function getDefaultCancelBtnProps(options) {
    var globalCancel = options.globalCancel;
    var props = {
      theme: "default",
      size: options.size,
      onClick: function onClick(e) {
        action.cancelBtnAction(e);
      }
    };
    if (isString__default["default"](globalCancel)) props.content = globalCancel;else if (isObject__default["default"](globalCancel)) props = _objectSpread(_objectSpread({}, props), globalCancel);
    return props;
  };
  var getButtonByProps = function getButtonByProps(button, defaultButton, className) {
    var newOptions = defaultButton;
    if (isString__default["default"](button)) newOptions.content = button;else if (isObject__default["default"](button)) newOptions = _objectSpread(_objectSpread({}, newOptions), button);
    return vue.createVNode(button_index.Button, vue.mergeProps({
      "class": className
    }, newOptions), null);
  };
  var getConfirmBtn = function getConfirmBtn(options) {
    var confirmBtn = options.confirmBtn,
      className = options.className;
    if (confirmBtn === null) return null;
    if (confirmBtn && instance.slots.confirmBtn) console.warn("Both $props.confirmBtn and $scopedSlots.confirmBtn exist, $props.confirmBtn is preferred.");
    var defaultButtonProps = getDefaultConfirmBtnProps(options);
    if (!confirmBtn && !instance.slots.confirmBtn) return vue.createVNode(button_index.Button, vue.mergeProps({
      "class": className
    }, defaultButtonProps), null);
    if (confirmBtn && ["string", "object"].includes(_typeof__default["default"](confirmBtn))) return getButtonByProps(confirmBtn, defaultButtonProps, className);
    return renderTNodeJSX("confirmBtn");
  };
  var getCancelBtn = function getCancelBtn(options) {
    var cancelBtn = options.cancelBtn,
      className = options.className;
    if (cancelBtn === null) return null;
    if (cancelBtn && instance.slots.cancelBtn) console.warn("Both $props.cancelBtn and $scopedSlots.cancelBtn exist, $props.cancelBtn is preferred.");
    var defaultButtonProps = getDefaultCancelBtnProps(options);
    if (!cancelBtn && !instance.slots.cancelBtn) return vue.createVNode(button_index.Button, vue.mergeProps({
      "class": className
    }, defaultButtonProps), null);
    if (cancelBtn && ["string", "object"].includes(_typeof__default["default"](cancelBtn))) return getButtonByProps(cancelBtn, defaultButtonProps);
    return renderTNodeJSX("cancelBtn");
  };
  return {
    getConfirmBtn: getConfirmBtn,
    getCancelBtn: getCancelBtn
  };
}
function useSameTarget(handleClick) {
  var MOUSEDOWN_TARGET = false;
  var MOUSEUP_TARGET = false;
  var onClick = function onClick(e) {
    if (MOUSEDOWN_TARGET && MOUSEUP_TARGET) handleClick(e);
    MOUSEDOWN_TARGET = false;
    MOUSEUP_TARGET = false;
  };
  var onMousedown = function onMousedown(e) {
    MOUSEDOWN_TARGET = e.target === e.currentTarget;
  };
  var onMouseup = function onMouseup(e) {
    MOUSEUP_TARGET = e.target === e.currentTarget;
  };
  return {
    onClick: onClick,
    onMousedown: onMousedown,
    onMouseup: onMouseup
  };
}

exports.useAction = useAction;
exports.useSameTarget = useSameTarget;
//# sourceMappingURL=hooks.js.map
