import _Snackbar from "@mui/material/Snackbar";
import _Alert from "@mui/material/Alert";
import _AlertTitle from "@mui/material/AlertTitle";
/*!
 * Copyright (c) 2022-present, Okta, Inc. and/or its affiliates. All rights reserved.
 * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.")
 *
 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *
 * See the License for the specific language governing permissions and limitations under the License.
 */
import { memo, useCallback, useEffect, useState } from "react";
import { Button } from "./Buttons/Button.js";
import { useTranslation } from "./i18n.generated/i18n.js";
import { CloseIcon } from "./icons.generated/index.js";
import { Link } from "./Link.js";
import { ScreenReaderText } from "./ScreenReaderText.js";
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
export const toastRoleValues = ["status", "alert"];
export const toastSeverityValues = ["success", "info", "warning", "error"];
const ClickAwayListenerProps = {
  onClickAway: () => false
};
const Toast = ({
  autoHideDuration = 6000,
  isDismissable,
  linkText,
  linkUrl,
  isVisible: isVisibleProp,
  onHide: onHideProp,
  role,
  severity,
  testId,
  text,
  translate
}) => {
  const {
    t
  } = useTranslation();
  const [isVisible, setIsVisible] = useState(isVisibleProp);
  useEffect(() => {
    setIsVisible(isVisibleProp);
  }, [isVisibleProp]);
  const onHide = useCallback(() => {
    setIsVisible(false);
    onHideProp?.();
  }, [onHideProp]);
  return _jsx(_Fragment, {
    children: _jsx(_Snackbar, {
      autoHideDuration: isDismissable || autoHideDuration <= 0 ? undefined : autoHideDuration,
      className: "Toast",
      ClickAwayListenerProps: ClickAwayListenerProps,
      onClose: onHide,
      open: isVisible,
      children: _jsxs(_Alert, {
        action: isDismissable === true && _jsx(Button, {
          ariaLabel: t("close.text"),
          onClick: onHide,
          size: "small",
          startIcon: _jsx(CloseIcon, {}),
          variant: "floating"
        }),
        "data-se": testId,
        role: role,
        severity: severity,
        variant: "toast",
        children: [_jsxs(_AlertTitle, {
          translate: translate,
          children: [_jsxs(ScreenReaderText, {
            translate: translate,
            children: [t(`severity.${severity}`), ":"]
          }), text]
        }), linkUrl && _jsx(Link, {
          href: linkUrl,
          translate: translate,
          variant: "monochrome",
          children: linkText
        })]
      })
    })
  });
};
const MemoizedToast = memo(Toast);
MemoizedToast.displayName = "Toast";
export { MemoizedToast as Toast };
//# sourceMappingURL=Toast.js.map