import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import { createVNode as _createVNode } from "vue";
import classNames from '../_util/classNames';
import Dialog from './Modal';
import ActionButton from './ActionButton';
import { getConfirmLocale } from './locale';
import { defineComponent, computed } from 'vue';

function renderSomeContent(_name, someContent) {
  if (typeof someContent === 'function') {
    return someContent();
  }

  return someContent;
}

export default defineComponent({
  name: 'ConfirmDialog',
  inheritAttrs: false,
  props: ['icon', 'onCancel', 'onOk', 'close', 'closable', 'zIndex', 'afterClose', 'visible', 'keyboard', 'centered', 'getContainer', 'maskStyle', 'okButtonProps', 'cancelButtonProps', 'okType', 'prefixCls', 'okCancel', 'width', 'mask', 'maskClosable', 'okText', 'cancelText', 'autoFocusButton', 'transitionName', 'maskTransitionName', 'type', 'title', 'content'],
  setup: function setup(props, _ref) {
    var attrs = _ref.attrs;
    var runtimeLocale = computed(function () {
      return getConfirmLocale();
    });
    return function () {
      var icon = props.icon,
          onCancel = props.onCancel,
          onOk = props.onOk,
          close = props.close,
          _props$closable = props.closable,
          closable = _props$closable === void 0 ? false : _props$closable,
          zIndex = props.zIndex,
          afterClose = props.afterClose,
          visible = props.visible,
          keyboard = props.keyboard,
          centered = props.centered,
          getContainer = props.getContainer,
          maskStyle = props.maskStyle,
          okButtonProps = props.okButtonProps,
          cancelButtonProps = props.cancelButtonProps,
          _props$okCancel = props.okCancel,
          okCancel = _props$okCancel === void 0 ? true : _props$okCancel,
          _props$width = props.width,
          width = _props$width === void 0 ? 416 : _props$width,
          _props$mask = props.mask,
          mask = _props$mask === void 0 ? true : _props$mask,
          _props$maskClosable = props.maskClosable,
          maskClosable = _props$maskClosable === void 0 ? false : _props$maskClosable,
          _props$maskTransition = props.maskTransitionName,
          maskTransitionName = _props$maskTransition === void 0 ? 'fade' : _props$maskTransition,
          _props$transitionName = props.transitionName,
          transitionName = _props$transitionName === void 0 ? 'zoom' : _props$transitionName,
          type = props.type,
          title = props.title,
          content = props.content;
      var okType = props.okType || 'primary';
      var prefixCls = props.prefixCls || 'ant-modal';
      var contentPrefixCls = "".concat(prefixCls, "-confirm");
      var style = attrs.style || {};
      var okText = renderSomeContent('okText', props.okText) || (okCancel ? runtimeLocale.value.okText : runtimeLocale.value.justOkText);
      var cancelText = renderSomeContent('cancelText', props.cancelText) || runtimeLocale.value.cancelText;
      var autoFocusButton = props.autoFocusButton === null ? false : props.autoFocusButton || 'ok';
      var classString = classNames(contentPrefixCls, "".concat(contentPrefixCls, "-").concat(type), "".concat(prefixCls, "-").concat(type), attrs.class);

      var cancelButton = okCancel && _createVNode(ActionButton, {
        "actionFn": onCancel,
        "closeModal": close,
        "autofocus": autoFocusButton === 'cancel',
        "buttonProps": cancelButtonProps
      }, {
        default: function _default() {
          return [cancelText];
        }
      });

      return _createVNode(Dialog, {
        "prefixCls": prefixCls,
        "class": classString,
        "wrapClassName": classNames(_defineProperty({}, "".concat(contentPrefixCls, "-centered"), !!centered)),
        "onCancel": function onCancel(e) {
          return close({
            triggerCancel: true
          }, e);
        },
        "visible": visible,
        "title": "",
        "transitionName": transitionName,
        "footer": "",
        "maskTransitionName": maskTransitionName,
        "mask": mask,
        "maskClosable": maskClosable,
        "maskStyle": maskStyle,
        "style": style,
        "width": width,
        "zIndex": zIndex,
        "afterClose": afterClose,
        "keyboard": keyboard,
        "centered": centered,
        "getContainer": getContainer,
        "closable": closable
      }, {
        default: function _default() {
          return [_createVNode("div", {
            "class": "".concat(contentPrefixCls, "-body-wrapper")
          }, [_createVNode("div", {
            "class": "".concat(contentPrefixCls, "-body")
          }, [renderSomeContent('icon', icon), title === undefined ? null : _createVNode("span", {
            "class": "".concat(contentPrefixCls, "-title")
          }, [renderSomeContent('title', title)]), _createVNode("div", {
            "class": "".concat(contentPrefixCls, "-content")
          }, [renderSomeContent('content', content)])]), _createVNode("div", {
            "class": "".concat(contentPrefixCls, "-btns")
          }, [cancelButton, _createVNode(ActionButton, {
            "type": okType,
            "actionFn": onOk,
            "closeModal": close,
            "autofocus": autoFocusButton === 'ok',
            "buttonProps": okButtonProps
          }, {
            default: function _default() {
              return [okText];
            }
          })])])];
        }
      });
    };
  }
});