var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __objRest = (source, exclude) => {
  var target = {};
  for (var prop in source)
    if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
      target[prop] = source[prop];
  if (source != null && __getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(source)) {
      if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
        target[prop] = source[prop];
    }
  return target;
};
function _extends() {
  _extends = Object.assign ? Object.assign.bind() : function(target) {
    for (var i = 1; i < arguments.length; i++) {
      var source = arguments[i];
      for (var key in source) {
        if (Object.prototype.hasOwnProperty.call(source, key)) {
          target[key] = source[key];
        }
      }
    }
    return target;
  };
  return _extends.apply(this, arguments);
}
import React, { useContext } from "react";
import classnames from "classnames";
import Popup from "../popup";
import Button from "../button";
import ActionBar from "../action-bar";
import { addUnit, noop } from "../utils";
import { BORDER_TOP, BORDER_LEFT } from "../utils/constant";
import ConfigProviderContext from "../config-provider/ConfigProviderContext";
const Dialog = (props) => {
  const {
    prefixCls,
    createNamespace
  } = useContext(ConfigProviderContext);
  const [bem] = createNamespace("dialog", prefixCls);
  const _a = props, {
    width,
    title,
    theme,
    visible,
    message,
    className,
    messageAlign,
    closeOnClickOverlay,
    onClickCloseIcon
  } = _a, others = __objRest(_a, [
    "width",
    "title",
    "theme",
    "visible",
    "message",
    "className",
    "messageAlign",
    "closeOnClickOverlay",
    "onClickCloseIcon"
  ]);
  const renderTitle = () => {
    if (props.title) {
      return /* @__PURE__ */ React.createElement("div", {
        className: classnames(bem("header", {
          isolated: !props.message && !props.children
        }))
      }, title);
    }
    return null;
  };
  const renderContent = () => {
    if (props.children) {
      return /* @__PURE__ */ React.createElement("div", {
        className: classnames(bem("content"))
      }, props.children);
    }
    if (message) {
      return /* @__PURE__ */ React.createElement("div", {
        className: classnames(bem("content", {
          isolated: !title
        }))
      }, /* @__PURE__ */ React.createElement("div", {
        className: classnames(bem("message", {
          "has-title": title,
          [messageAlign]: messageAlign
        }))
      }, message));
    }
    return null;
  };
  const renderButtons = () => {
    var _a2, _b, _c, _d, _e, _f;
    return /* @__PURE__ */ React.createElement("div", {
      className: classnames(BORDER_TOP, bem("footer"))
    }, props.showCancelButton && /* @__PURE__ */ React.createElement(Button, {
      size: "large",
      text: props.cancelButtonText || "\u53D6\u6D88",
      className: classnames(bem("cancel")),
      style: {
        color: props.cancelButtonColor
      },
      loading: (_a2 = props.cancelProps) == null ? void 0 : _a2.loading,
      disabled: (_b = props.cancelProps) == null ? void 0 : _b.disabled,
      onClick: ((_c = props.cancelProps) == null ? void 0 : _c.loading) ? noop : props.onCancel
    }), props.showConfirmButton && /* @__PURE__ */ React.createElement(Button, {
      size: "large",
      text: props.confirmButtonText || "\u786E\u8BA4",
      className: classnames(bem("confirm"), {
        [BORDER_LEFT]: props.showCancelButton
      }),
      round: theme === "round-button",
      style: {
        color: props.confirmButtonColor
      },
      loading: (_d = props.confirmProps) == null ? void 0 : _d.loading,
      disabled: (_e = props.confirmProps) == null ? void 0 : _e.disabled,
      onClick: ((_f = props.confirmProps) == null ? void 0 : _f.loading) ? noop : props.onConfirm
    }));
  };
  const renderRoundButtons = () => {
    var _a2, _b, _c, _d, _e, _f;
    return /* @__PURE__ */ React.createElement(ActionBar, {
      className: classnames(bem("footer"))
    }, props.showCancelButton && /* @__PURE__ */ React.createElement(ActionBar.Button, {
      type: "warning",
      text: props.cancelButtonText || "\u53D6\u6D88",
      className: classnames(bem("cancel")),
      color: props.cancelButtonColor,
      loading: (_a2 = props.cancelProps) == null ? void 0 : _a2.loading,
      disabled: (_b = props.cancelProps) == null ? void 0 : _b.disabled,
      onClick: ((_c = props.cancelProps) == null ? void 0 : _c.loading) ? noop : props.onCancel
    }), props.showConfirmButton && /* @__PURE__ */ React.createElement(ActionBar.Button, {
      type: "danger",
      text: props.confirmButtonText || "\u786E\u8BA4",
      className: classnames(bem("confirm")),
      color: props.confirmButtonColor,
      loading: (_d = props.confirmProps) == null ? void 0 : _d.loading,
      disabled: (_e = props.confirmProps) == null ? void 0 : _e.disabled,
      onClick: ((_f = props.confirmProps) == null ? void 0 : _f.loading) ? noop : props.onConfirm
    }));
  };
  const renderFooter = () => {
    if (props.footer)
      return props.footer;
    return props.theme === "round-button" ? renderRoundButtons() : renderButtons();
  };
  return /* @__PURE__ */ React.createElement(Popup, _extends({}, others, {
    visible,
    className: classnames(bem([theme]), className),
    style: {
      width: addUnit(width)
    },
    "aria-labelledby": title || message,
    closeOnClickOverlay,
    onOpen: props.onOpen,
    onOpened: props.onOpened,
    onClose: props.onClose,
    onClosed: props.onClosed
  }), renderTitle(), renderContent(), renderFooter());
};
Dialog.defaultProps = {
  transition: "rc-dialog-bounce",
  showConfirmButton: true,
  closeOnPopstate: true
};
var stdin_default = Dialog;
export {
  stdin_default as default
};
