// Copyright 1999-2025. WebPros International GmbH. All rights reserved.

import classNames from 'classnames';
import { CLS_PREFIX } from '../../constants';
import Icon from '../Icon';
import Button from '../Button';
import { intentIconMap } from '../intentIconMap';
import OnDarkContext from '../OnDarkContext';
import { useAutoClose } from './useAutoClose';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
const Toast = _ref => {
  let {
    baseClassName = `${CLS_PREFIX}toast`,
    className,
    message,
    intent,
    accent,
    icon = intent && /*#__PURE__*/_jsx(Icon, {
      name: intentIconMap[intent]
    }),
    onClose,
    closable = true,
    autoClosable,
    autoCloseTimeout,
    innerRef,
    groupKey,
    ...props
  } = _ref;
  useAutoClose({
    autoClosable,
    autoCloseTimeout,
    onClose
  });
  const result = /*#__PURE__*/_jsxs("div", {
    tabIndex: 0,
    className: classNames(baseClassName, intent && `${baseClassName}--${intent}`, accent && `${baseClassName}--accent`, className),
    ...props,
    ref: innerRef,
    children: [icon && /*#__PURE__*/_jsx("div", {
      className: `${baseClassName}__icon`,
      children: Icon.create(icon, {
        intent
      })
    }), /*#__PURE__*/_jsx("div", {
      className: `${baseClassName}__content`,
      children: message
    }), closable && /*#__PURE__*/_jsx("div", {
      className: `${baseClassName}__action`,
      children: /*#__PURE__*/_jsx(Button, {
        ghost: true,
        icon: {
          name: 'cross-mark',
          size: '12'
        },
        className: `${baseClassName}__close`,
        onClick: onClose
      })
    })]
  });
  if (accent) {
    return result;
  }
  return /*#__PURE__*/_jsx(OnDarkContext.Provider, {
    value: true,
    children: result
  });
};
export default Toast;