import React from "react";
import classNames from "classnames";
import { Icon } from "../icon";
import { StyledProps } from "../_type";
import { useConfig } from "../_util/config-context";

/**
 * 对话框内容展示
 */
export interface ModalMessageProps extends StyledProps {
  /**
   * 要提示的消息
   */
  message?: React.ReactNode;

  /**
   * 可选的详细解释
   */
  description?: React.ReactNode;

  /**
   * 提示图标
   */
  icon?: "error" | "warning" | "pending" | "infoblue" | "success";
}

export const ModalMessage = React.forwardRef(function ModalMessage(
  { icon, message, description, className, ...props }: ModalMessageProps,
  ref: React.Ref<HTMLDivElement>
) {
  const { classPrefix } = useConfig();
  return (
    <div
      ref={ref}
      className={classNames(`${classPrefix}-media`, className)}
      {...props}
    >
      {icon && (
        <div className={`${classPrefix}-media__left`}>
          <Icon type={icon} size="l" />
        </div>
      )}
      <div className={`${classPrefix}-media__body`}>
        {message && (
          <h3 className={`${classPrefix}-dialog__messagetitle`}>{message}</h3>
        )}
        {description && (
          <div className={`${classPrefix}-dialog__messagetext`}>
            {description}
          </div>
        )}
      </div>
    </div>
  );
});

ModalMessage.displayName = "ModalMessage";
