"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = exports.DropdownButtonProps = void 0;

var _vue = _interopRequireWildcard(require("vue"));

var _button = _interopRequireDefault(require("../button"));

var _classNames = _interopRequireDefault(require("../_util/classNames"));

var _buttonTypes = _interopRequireDefault(require("../button/buttonTypes"));

var _buttonGroup = require("../button/button-group");

var _dropdown = _interopRequireDefault(require("./dropdown"));

var _vueTypes = _interopRequireDefault(require("../_util/vue-types"));

var _propsUtil = require("../_util/props-util");

var _getDropdownProps = _interopRequireDefault(require("./getDropdownProps"));

var _configProvider = require("../config-provider");

var _EllipsisOutlined = _interopRequireDefault(require("@ant-design/icons-vue/EllipsisOutlined"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (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 = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var ButtonTypesProps = (0, _buttonTypes.default)();
var DropdownProps = (0, _getDropdownProps.default)();
var ButtonGroup = _button.default.Group;

var DropdownButtonProps = _objectSpread(_objectSpread(_objectSpread({}, _buttonGroup.ButtonGroupProps), DropdownProps), {}, {
  type: _vueTypes.default.oneOf(['primary', 'ghost', 'dashed', 'danger', 'default']).def('default'),
  size: _vueTypes.default.oneOf(['small', 'large', 'default']).def('default'),
  htmlType: ButtonTypesProps.htmlType,
  href: _vueTypes.default.string,
  disabled: _vueTypes.default.bool,
  prefixCls: _vueTypes.default.string,
  placement: DropdownProps.placement.def('bottomRight'),
  icon: _vueTypes.default.any,
  title: _vueTypes.default.string,
  onClick: _vueTypes.default.func,
  onVisibleChange: _vueTypes.default.func,
  'onUpdate:visible': _vueTypes.default.func
});

exports.DropdownButtonProps = DropdownButtonProps;
var _default2 = {
  name: 'ADropdownButton',
  inheritAttrs: false,
  props: DropdownButtonProps,
  setup: function setup() {
    return {
      configProvider: (0, _vue.inject)('configProvider', _configProvider.ConfigConsumerProps)
    };
  },
  created: function created() {
    (0, _vue.provide)('savePopupRef', this.savePopupRef);
  },
  methods: {
    savePopupRef: function savePopupRef(ref) {
      this.popupRef = ref;
    },
    handleClick: function handleClick(e) {
      this.$emit('click', e);
    },
    handleVisibleChange: function handleVisibleChange(val) {
      this.$emit('update:visible', val);
      this.$emit('visibleChange', val);
    }
  },
  render: function render() {
    var _this = this;

    var _this$$props$this$$at = _objectSpread(_objectSpread({}, this.$props), this.$attrs),
        type = _this$$props$this$$at.type,
        disabled = _this$$props$this$$at.disabled,
        onClick = _this$$props$this$$at.onClick,
        htmlType = _this$$props$this$$at.htmlType,
        className = _this$$props$this$$at.class,
        customizePrefixCls = _this$$props$this$$at.prefixCls,
        overlay = _this$$props$this$$at.overlay,
        trigger = _this$$props$this$$at.trigger,
        align = _this$$props$this$$at.align,
        visible = _this$$props$this$$at.visible,
        onVisibleChange = _this$$props$this$$at.onVisibleChange,
        placement = _this$$props$this$$at.placement,
        getPopupContainer = _this$$props$this$$at.getPopupContainer,
        href = _this$$props$this$$at.href,
        title = _this$$props$this$$at.title,
        restProps = _objectWithoutProperties(_this$$props$this$$at, ["type", "disabled", "onClick", "htmlType", "class", "prefixCls", "overlay", "trigger", "align", "visible", "onVisibleChange", "placement", "getPopupContainer", "href", "title"]);

    var icon = (0, _propsUtil.getComponent)(this, 'icon') || _vue.createVNode(_EllipsisOutlined.default, null, null);

    var getContextPopupContainer = this.configProvider.getPopupContainer;
    var getPrefixCls = this.configProvider.getPrefixCls;
    var prefixCls = getPrefixCls('dropdown-button', customizePrefixCls);
    var dropdownProps = {
      align: align,
      disabled: disabled,
      trigger: disabled ? [] : trigger,
      placement: placement,
      getPopupContainer: getPopupContainer || getContextPopupContainer,
      onVisibleChange: this.handleVisibleChange
    };

    if ((0, _propsUtil.hasProp)(this, 'visible')) {
      dropdownProps.visible = visible;
    }

    var buttonGroupProps = _objectSpread(_objectSpread({}, restProps), {}, {
      class: (0, _classNames.default)(prefixCls, className)
    });

    return _vue.createVNode(ButtonGroup, buttonGroupProps, {
      default: function _default() {
        return [_vue.createVNode(_button.default, {
          "type": type,
          "disabled": disabled,
          "onClick": _this.handleClick,
          "htmlType": htmlType,
          "href": href,
          "title": title
        }, {
          default: function _default() {
            return [(0, _propsUtil.getSlot)(_this)];
          }
        }), _vue.createVNode(_dropdown.default, _vue.mergeProps(dropdownProps, {
          "overlay": (0, _propsUtil.getComponent)(_this, 'overlay')
        }), {
          default: function _default() {
            return [_vue.createVNode(_button.default, {
              "type": type
            }, {
              default: function _default() {
                return [icon];
              }
            })];
          }
        })];
      }
    });
  }
};
exports.default = _default2;