/**
 * ldesign v0.2.2
 * (c) 2022年9月20日 swimly
 * @license MIT
 */

'use strict';

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

var helper = require('../../../chunks/helper.js');
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 utils_renderNode = require('../../../utils/render-node.js');
var components_button_index = require('../../button/index.js');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../../button/button.js');
require('@ldesign/icons-vue');
require('../../loading/index.js');
require('../../loading/loading.js');
require('../../loading/icon/gradient.js');
require('../../../chunks/defineProperty-28395935.js');
require('../../../chunks/set-style.js');
require('../../../chunks/helper2.js');
require('@babel/runtime/helpers/toConsumableArray');
require('@babel/runtime/helpers/slicedToArray');
require('../../../config.js');
require('../../../utils/dom.js');
require('raf');
require('../../../utils/easing.js');
require('../../../utils/transfer-dom.js');
require('../../loading/props.js');
require('../../config-provider/config-receiver.js');
require('lodash/mergeWith');
require('lodash');
require('../../config-provider/context.js');
require('../../../chunks/zh_CN.js');
require('../../../utils/mixins.js');
require('../../../utils/with-install.js');
require('../../loading/plugin.js');
require('../../button/props.js');
require('../../../utils/ripple.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 Vue__default = /*#__PURE__*/_interopDefaultLegacy(Vue);
var isString__default = /*#__PURE__*/_interopDefaultLegacy(isString);
var isObject__default = /*#__PURE__*/_interopDefaultLegacy(isObject);

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 ActionMixin = Vue__default["default"].extend({
  components: {
    LButton: components_button_index.Button
  },
  methods: {
    getConfirmBtn: function getConfirmBtn(options) {
      var h = this.$createElement;
      var confirmBtn = options.confirmBtn,
          className = options.className;
      if (confirmBtn === null) return null;

      if (confirmBtn && this.$scopedSlots.confirmBtn) {
        console.warn("Both $props.confirmBtn and $scopedSlots.confirmBtn exist, $props.confirmBtn is preferred.");
      }

      var defaultButtonProps = this.getDefaultConfirmBtnProps(options);

      if (!confirmBtn && !this.$scopedSlots.confirmBtn) {
        return h("l-button", helper.helper([{
          "class": className
        }, {
          "props": _objectSpread({}, defaultButtonProps)
        }]));
      }

      if (confirmBtn && ["string", "object"].includes(_typeof__default["default"](confirmBtn))) {
        return this.getButtonByProps(confirmBtn, defaultButtonProps, className);
      }

      return utils_renderNode.renderLNodeJSX(this, "confirmBtn");
    },
    getCancelBtn: function getCancelBtn(options) {
      var h = this.$createElement;
      var cancelBtn = options.cancelBtn,
          className = options.className;
      if (cancelBtn === null) return null;

      if (cancelBtn && this.$scopedSlots.cancelBtn) {
        console.warn("Both $props.cancelBtn and $scopedSlots.cancelBtn exist, $props.cancelBtn is preferred.");
      }

      var defaultButtonProps = this.getDefaultCancelBtnProps(options);

      if (!cancelBtn && !this.$scopedSlots.cancelBtn) {
        return h("l-button", helper.helper([{
          "class": className
        }, {
          "props": _objectSpread({}, defaultButtonProps)
        }]));
      }

      if (cancelBtn && ["string", "object"].includes(_typeof__default["default"](cancelBtn))) {
        return this.getButtonByProps(cancelBtn, defaultButtonProps);
      }

      return utils_renderNode.renderLNodeJSX(this, "cancelBtn");
    },
    getButtonByProps: function getButtonByProps(button, defaultButton, className) {
      var h = this.$createElement;
      var newOptions = defaultButton;

      if (isString__default["default"](button)) {
        newOptions.content = button;
      } else if (isObject__default["default"](button)) {
        newOptions = _objectSpread(_objectSpread({}, newOptions), button);
      }

      return h("l-button", helper.helper([{
        "class": className
      }, {
        "props": newOptions
      }]));
    },
    confirmBtnAction: function confirmBtnAction(e) {},
    cancelBtnAction: function cancelBtnAction(e) {},
    getDefaultConfirmBtnProps: function getDefaultConfirmBtnProps(options) {
      var _this = this;

      var globalConfirm = options.globalConfirm,
          theme = options.theme,
          globalConfirmBtnTheme = options.globalConfirmBtnTheme;
      var defaultTheme = (globalConfirmBtnTheme === null || globalConfirmBtnTheme === void 0 ? void 0 : globalConfirmBtnTheme[theme]) || "primary";
      var props = {
        theme: defaultTheme,
        content: "\u786E\u5B9A",
        size: options.size,
        onClick: function onClick(e) {
          _this.confirmBtnAction(e);
        }
      };

      if (isString__default["default"](globalConfirm)) {
        props.content = globalConfirm;
      } else if (isObject__default["default"](globalConfirm)) {
        props = _objectSpread(_objectSpread({}, props), globalConfirm);
      }

      return props;
    },
    getDefaultCancelBtnProps: function getDefaultCancelBtnProps(options) {
      var _this2 = this;

      var globalCancel = options.globalCancel;
      var props = {
        theme: "default",
        content: "\u53D6\u6D88",
        size: options.size,
        onClick: function onClick(e) {
          _this2.cancelBtnAction(e);
        }
      };

      if (isString__default["default"](globalCancel)) {
        props.content = globalCancel;
      } else if (isObject__default["default"](globalCancel)) {
        props = _objectSpread(_objectSpread({}, props), globalCancel);
      }

      return props;
    }
  }
});

exports["default"] = ActionMixin;
//# sourceMappingURL=action.js.map
