import _extends from"babel-runtime/helpers/extends";import _classCallCheck from"babel-runtime/helpers/classCallCheck";import _createClass from"babel-runtime/helpers/createClass";import _possibleConstructorReturn from"babel-runtime/helpers/possibleConstructorReturn";import _inherits from"babel-runtime/helpers/inherits";import*as React from"react";import*as ReactDOM from"react-dom";import classNames from"classnames";import Icon from"../icon";import Dialog from"./Modal";import ActionButton from"./ActionButton";import{getConfirmLocale}from"./locale";import Checkbox from"../checkbox";var IS_REACT_16=!!ReactDOM.createPortal,ConfirmDialog=function(e){function t(e){_classCallCheck(this,t);var o=_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return o.state={okBtnDisabled:e.doubleCheck||!1},o}return _inherits(t,e),_createClass(t,[{key:"render",value:function(){var e=this,t=this.props,o=t.onCancel,a=t.onOk,s=t.close,r=t.zIndex,n=t.afterClose,c=t.visible,i=this.props.iconType||"question-circle",l=this.props.okType||"primary",p=this.props.prefixCls||"dt-confirm",m=!("okCancel"in this.props)||this.props.okCancel,h=this.props.width||(this.state.doubleCheck?630:550),d=this.props.style||{},C=void 0!==this.props.maskClosable&&this.props.maskClosable,u=getConfirmLocale(),b=this.props.okText||(m?u.okText:u.justOkText),f=this.props.cancelText||u.cancelText,k=classNames(p,p+"-"+this.props.type,this.props.className),y=m?[React.createElement(ActionButton,{key:"cancel",type:"secondary",actionFn:o,closeModal:s},f)]:[],R=this.props.doubleCheck?React.createElement("div",{className:p+"-doubleCheckContent"},React.createElement(Checkbox,{onChange:function(t){e.setState({okBtnDisabled:!t.target.checked})}}),React.createElement("span",null,this.props.subContent)):React.createElement("div",{className:p+"-content"},this.props.subContent),v=y.concat([React.createElement(ActionButton,{key:"ok",type:l,actionFn:a,closeModal:s,disabled:this.state.okBtnDisabled,autoFocus:!0},b)]);return React.createElement(Dialog,{className:k,onCancel:s.bind(this,{triggerCancel:!0}),visible:c,title:this.props.title,transitionName:"zoom",footer:v,maskTransitionName:"fade",maskClosable:C,style:d,width:h,zIndex:r,afterClose:n},React.createElement("div",{className:p+"-body-wrapper"},React.createElement("div",{className:p+"-body"},React.createElement(Icon,{type:i}),React.createElement("span",{className:p+"-title"},this.props.content),R)))}}]),t}(React.Component);export default function confirm(e){var t=document.createElement("div");function o(){for(var t=arguments.length,r=Array(t),n=0;n<t;n++)r[n]=arguments[n];IS_REACT_16?s(_extends({},e,{close:o,visible:!1,afterClose:a.bind.apply(a,[this].concat(r))})):a.apply(void 0,r)}function a(){ReactDOM.unmountComponentAtNode(t)&&t.parentNode&&t.parentNode.removeChild(t);for(var o=arguments.length,a=Array(o),s=0;s<o;s++)a[s]=arguments[s];var r=a&&a.length&&a.some(function(e){return e&&e.triggerCancel});e.onCancel&&r&&e.onCancel.apply(e,a)}function s(e){ReactDOM.render(React.createElement(ConfirmDialog,e),t)}return document.body.appendChild(t),s(_extends({},e,{visible:!0,close:o})),{destroy:o}};