import * as _vue from "vue";

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; }

import omit from 'omit.js';
import { inject } from 'vue';
import Tooltip from '../tooltip';
import abstractTooltipProps from '../tooltip/abstractTooltipProps';
import PropTypes from '../_util/vue-types';
import { getOptionProps, hasProp, getComponent, mergeProps } from '../_util/props-util';
import BaseMixin from '../_util/BaseMixin';
import buttonTypes from '../button/buttonTypes';
import ExclamationCircleFilled from '@ant-design/icons-vue/ExclamationCircleFilled';
import Button from '../button';
import LocaleReceiver from '../locale-provider/LocaleReceiver';
import defaultLocale from '../locale-provider/default';
import { ConfigConsumerProps } from '../config-provider';
var tooltipProps = abstractTooltipProps();
var btnProps = buttonTypes();
var Popconfirm = {
  name: 'APopconfirm',
  props: _objectSpread(_objectSpread({}, tooltipProps), {}, {
    prefixCls: PropTypes.string,
    transitionName: PropTypes.string.def('zoom-big'),
    content: PropTypes.any,
    title: PropTypes.any,
    trigger: tooltipProps.trigger.def('click'),
    okType: btnProps.type.def('primary'),
    disabled: PropTypes.bool.def(false),
    okText: PropTypes.any,
    cancelText: PropTypes.any,
    icon: PropTypes.any,
    okButtonProps: PropTypes.object,
    cancelButtonProps: PropTypes.object,
    onConfirm: PropTypes.func,
    onCancel: PropTypes.func,
    onVisibleChange: PropTypes.func,
    'onUpdate:visible': PropTypes.func
  }),
  mixins: [BaseMixin],
  watch: {
    visible: function visible(val) {
      this.sVisible = val;
    }
  },
  setup: function setup() {
    return {
      configProvider: inject('configProvider', ConfigConsumerProps)
    };
  },
  data: function data() {
    var props = 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 (!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 = getComponent(this, 'icon') || _vue.createVNode(ExclamationCircleFilled, null, null);

      var cancelBtnProps = mergeProps(_objectSpread({
        size: 'small',
        onClick: this.onCancelHandle
      }, cancelButtonProps));
      var okBtnProps = 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")
      }, [getComponent(this, 'title')])]), _vue.createVNode("div", {
        "class": "".concat(prefixCls, "-buttons")
      }, [_vue.createVNode(Button, cancelBtnProps, {
        default: function _default() {
          return [getComponent(_this, 'cancelText') || popconfirmLocale.cancelText];
        }
      }), _vue.createVNode(Button, okBtnProps, {
        default: function _default() {
          return [getComponent(_this, 'okText') || popconfirmLocale.okText];
        }
      })])]);
    }
  },
  render: function render() {
    var _this2 = this,
        _this$$slots;

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

    var overlay = _vue.createVNode(LocaleReceiver, {
      "componentName": "Popconfirm",
      "defaultLocale": defaultLocale.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, 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);
};

export default Popconfirm;