/* RelatedLinksBaseModal.tsx generated by @compiled/babel-plugin v0.40.0 */
import * as React from 'react';
import { ax, ix } from "@compiled/react/runtime";
import { useCallback, useRef } from 'react';
import { FormattedMessage } from 'react-intl';
import Button from '@atlaskit/button/new';
import Modal, { ModalBody, ModalFooter, ModalHeader, ModalTitle, ModalTransition } from '@atlaskit/modal-dialog';
import { useAnalyticsEvents } from '../../../common/analytics/generated/use-analytics-events';
import { messages } from '../../../messages';
const fixedWidth = 'small'; // pre-defined 400px by Atlaskit

const RelatedLinksBaseModal = ({
  onClose,
  showModal,
  children
}) => {
  const {
    fireEvent
  } = useAnalyticsEvents();
  const modalOpenTimeRef = useRef(Date.now());
  const openCompleteHandler = useCallback(el => {
    el.focus();
    modalOpenTimeRef.current = Date.now();
    fireEvent('ui.modal.opened.relatedLinks', {});
  }, [fireEvent]);
  const closeHandler = useCallback(() => {
    fireEvent('ui.modal.closed.relatedLinks', {
      dwellTime: Date.now() - modalOpenTimeRef.current
    });
    onClose === null || onClose === void 0 ? void 0 : onClose();
  }, [fireEvent, onClose]);
  return /*#__PURE__*/React.createElement(ModalTransition, null, showModal && /*#__PURE__*/React.createElement(Modal, {
    testId: "related-links-modal",
    onClose: closeHandler,
    width: fixedWidth,
    shouldReturnFocus: false,
    onOpenComplete: openCompleteHandler,
    height: '504px'
  }, /*#__PURE__*/React.createElement(ModalHeader, {
    hasCloseButton: true
  }, /*#__PURE__*/React.createElement(ModalTitle, null, /*#__PURE__*/React.createElement(FormattedMessage, messages.related_links_modal_title))), /*#__PURE__*/React.createElement(ModalBody, null, children), /*#__PURE__*/React.createElement(ModalFooter, null, /*#__PURE__*/React.createElement(Button, {
    appearance: "primary",
    onClick: closeHandler
  }, /*#__PURE__*/React.createElement(FormattedMessage, messages.close)))));
};
export default RelatedLinksBaseModal;