"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 = void 0;

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

var _omit = _interopRequireDefault(require("omit.js"));

var _tooltip = _interopRequireDefault(require("../tooltip"));

var _abstractTooltipProps = _interopRequireDefault(require("../tooltip/abstractTooltipProps"));

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

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

var _BaseMixin = _interopRequireDefault(require("../_util/BaseMixin"));

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

var _ExclamationCircleFilled = _interopRequireDefault(require("@ant-design/icons-vue/ExclamationCircleFilled"));

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

var _LocaleReceiver = _interopRequireDefault(require("../locale-provider/LocaleReceiver"));

var _default3 = _interopRequireDefault(require("../locale-provider/default"));

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

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 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 tooltipProps = (0, _abstractTooltipProps.default)();
var btnProps = (0, _buttonTypes.default)();
var Popconfirm = {
  name: 'APopconfirm',
  props: _objectSpread(_objectSpread({}, tooltipProps), {}, {
    prefixCls: _vueTypes.default.string,
    transitionName: _vueTypes.default.string.def('zoom-big'),
    content: _vueTypes.default.any,
    title: _vueTypes.default.any,
    trigger: tooltipProps.trigger.def('click'),
    okType: btnProps.type.def('primary'),
    disabled: _vueTypes.default.bool.def(false),
    okText: _vueTypes.default.any,
    cancelText: _vueTypes.default.any,
    icon: _vueTypes.default.any,
    okButtonProps: _vueTypes.default.object,
    cancelButtonProps: _vueTypes.default.object,
    onConfirm: _vueTypes.default.func,
    onCancel: _vueTypes.default.func,
    onVisibleChange: _vueTypes.default.func,
    'onUpdate:visible': _vueTypes.default.func
  }),
  mixins: [_BaseMixin.default],
  watch: {
    visible: function visible(val) {
      this.sVisible = val;
    }
  },
  setup: function setup() {
    return {
      configProvider: (0, _vue.inject)('configProvider', _configProvider.ConfigConsumerProps)
    };
  },
  data: function data() {
    var props = (0, _propsUtil.getOptionProps)(this);
    var state = {
      sVisible: false
    };

    if ('visible' in props) {
      state.sVisible = props.visible;
    }

    if ('defaultVisible' in props) {
      state.sVisible = props.defaultVisible;
    }

    return state;
  },
  methods: {
    onConfirmHandle: function onConfirmHandle(e) {
      this.setVisible(false, e);
      this.$emit('confirm', e);
    },
    onCancelHandle: function onCancelHandle(e) {
      this.setVisible(false, e);
      this.$emit('cancel', e);
    },
    onVisibleChangeHandle: function onVisibleChangeHandle(sVisible) {
      var disabled = this.$props.disabled;

      if (disabled) {
        return;
      }

      this.setVisible(sVisible);
    },
    setVisible: function setVisible(sVisible, e) {
      if (!(0, _propsUtil.hasProp)(this, 'visible')) {
        this.setState({
          sVisible: sVisible
        });
      }

      this.$emit('update:visible', sVisible);
      this.$emit('visibleChange', sVisible, e);
    },
    getPopupDomNode: function getPopupDomNode() {
      return this.$refs.tooltip.getPopupDomNode();
    },
    renderOverlay: function renderOverlay(prefixCls, popconfirmLocale) {
      var _this = this;

      var okType = this.okType,
          okButtonProps = this.okButtonProps,
          cancelButtonProps = this.cancelButtonProps;

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

      var cancelBtnProps = (0, _propsUtil.mergeProps)(_objectSpread({
        size: 'small',
        onClick: this.onCancelHandle
      }, cancelButtonProps));
      var okBtnProps = (0, _propsUtil.mergeProps)(_objectSpread({
        type: okType,
        size: 'small',
        onClick: this.onConfirmHandle
      }, okButtonProps));
      return _vue.createVNode("div", {
        "class": "".concat(prefixCls, "-inner-content")
      }, [_vue.createVNode("div", {
        "class": "".concat(prefixCls, "-message")
      }, [icon, _vue.createVNode("div", {
        "class": "".concat(prefixCls, "-message-title")
      }, [(0, _propsUtil.getComponent)(this, 'title')])]), _vue.createVNode("div", {
        "class": "".concat(prefixCls, "-buttons")
      }, [_vue.createVNode(_button.default, cancelBtnProps, {
        default: function _default() {
          return [(0, _propsUtil.getComponent)(_this, 'cancelText') || popconfirmLocale.cancelText];
        }
      }), _vue.createVNode(_button.default, okBtnProps, {
        default: function _default() {
          return [(0, _propsUtil.getComponent)(_this, 'okText') || popconfirmLocale.okText];
        }
      })])]);
    }
  },
  render: function render() {
    var _this2 = this,
        _this$$slots;

    var props = (0, _propsUtil.getOptionProps)(this);
    var customizePrefixCls = props.prefixCls;
    var getPrefixCls = this.configProvider.getPrefixCls;
    var prefixCls = getPrefixCls('popover', customizePrefixCls);
    var otherProps = (0, _omit.default)(props, ['title', 'content', 'cancelText', 'okText', 'onUpdate:visible']);

    var overlay = _vue.createVNode(_LocaleReceiver.default, {
      "componentName": "Popconfirm",
      "defaultLocale": _default3.default.Popconfirm,
      "children": function children(popconfirmLocale) {
        return _this2.renderOverlay(prefixCls, popconfirmLocale);
      }
    }, null);

    var tooltipProps = _objectSpread(_objectSpread({}, otherProps), {}, {
      title: overlay,
      prefixCls: prefixCls,
      visible: this.sVisible,
      ref: 'tooltip',
      onVisibleChange: this.onVisibleChangeHandle
    });

    return _vue.createVNode(_tooltip.default, tooltipProps, {
      default: function _default() {
        return [(_this$$slots = _this2.$slots) === null || _this$$slots === void 0 ? void 0 : _this$$slots.default()];
      }
    });
  }
};
/* istanbul ignore next */

Popconfirm.install = function (app) {
  app.component(Popconfirm.name, Popconfirm);
};

var _default2 = Popconfirm;
exports.default = _default2;