"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.useAutoClose = void 0;
var _react = require("react");
// Copyright 1999-2023. Plesk International GmbH. All rights reserved.

const AUTOCLOSE_TIMEOUT = 6000;
const getAutoCloseTimeout = (autoClosable, autoCloseTimeout) => {
  if (typeof autoClosable !== 'boolean') {
    return autoCloseTimeout;
  }
  return autoClosable ? AUTOCLOSE_TIMEOUT : undefined;
};
const useAutoClose = _ref => {
  let {
    autoClosable,
    autoCloseTimeout: externalAutoCloseTimeout,
    onClose
  } = _ref;
  const onCloseRef = (0, _react.useRef)(onClose);
  onCloseRef.current = onClose;
  (0, _react.useEffect)(() => {
    const autoCloseTimeout = getAutoCloseTimeout(autoClosable, externalAutoCloseTimeout);
    let timeoutId;
    if (autoCloseTimeout && onCloseRef.current) {
      timeoutId = window.setTimeout(onCloseRef.current, autoCloseTimeout);
    }
    return () => window.clearTimeout(timeoutId);
  }, [autoClosable, externalAutoCloseTimeout]);
};
exports.useAutoClose = useAutoClose;