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

import _typeof from '@babel/runtime/helpers/typeof';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { getCurrentInstance, createVNode, mergeProps } from 'vue';
import isString from 'lodash/isString';
import isObject from 'lodash/isObject';
import omit from 'lodash/omit';
import { useTNodeJSX } from '../hooks/tnode.js';
import { Button } from '../button/index.js';
import 'lodash/isFunction';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../utils/render-tnode.js';
import 'lodash/isEmpty';
import '../utils/withInstall.js';
import '../button/button.js';
import '@babel/runtime/helpers/toConsumableArray';
import '../loading/index.js';
import '../loading/directive.js';
import '../loading/plugin.js';
import '../utils/dom.js';
import '../_chunks/dep-2e5d8948.js';
import 'lodash/isArray';
import '../utils/easing.js';
import '../hooks/useConfig.js';
import '../config-provider/useConfig.js';
import 'lodash/cloneDeep';
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 'dayjs';
import '../_chunks/dep-4580aabe.js';
import '../config-provider/type.js';
import '../loading/loading.js';
import '@babel/runtime/helpers/slicedToArray';
import '../hooks/useTeleport.js';
import '../loading/props.js';
import '../loading/icon/gradient.js';
import '../_common/js/loading/circle-adapter.js';
import '../_common/js/utils/set-style.js';
import '../_common/js/utils/helper.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import 'lodash/isNull';
import 'lodash/isUndefined';
import 'lodash/isNumber';
import '../loading/style';
import '../loading/type.js';
import '../hooks/useRipple.js';
import '../utils/set-style.js';
import '../hooks/useKeepAnimation.js';
import '../form/hooks.js';
import '../button/props.js';
import '../button/style';
import '../button/type.js';

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(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 = getCurrentInstance();
  var renderTNodeJSX = useTNodeJSX();
  var getDefaultConfirmBtnProps = function getDefaultConfirmBtnProps(options) {
    var _omit;
    var globalConfirm = options.globalConfirm,
      theme = options.theme,
      globalConfirmBtnTheme = options.globalConfirmBtnTheme;
    var defaultTheme = ((_omit = omit(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(globalConfirm)) props.content = globalConfirm;else if (isObject(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(globalCancel)) props.content = globalCancel;else if (isObject(globalCancel)) props = _objectSpread(_objectSpread({}, props), globalCancel);
    return props;
  };
  var getButtonByProps = function getButtonByProps(button, defaultButton, className) {
    var newOptions = defaultButton;
    if (isString(button)) newOptions.content = button;else if (isObject(button)) newOptions = _objectSpread(_objectSpread({}, newOptions), button);
    return createVNode(Button, 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 createVNode(Button, mergeProps({
      "class": className
    }, defaultButtonProps), null);
    if (confirmBtn && ["string", "object"].includes(_typeof(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 createVNode(Button, mergeProps({
      "class": className
    }, defaultButtonProps), null);
    if (cancelBtn && ["string", "object"].includes(_typeof(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
  };
}

export { useAction, useSameTarget };
//# sourceMappingURL=hooks.js.map
