'use strict';

var clsx = require('clsx');
var React = require('react');
var reactIntl = require('react-intl');
var DateLookup_messages = require('../DateLookup.messages.js');
var jsxRuntime = require('react/jsx-runtime');

const TableLink = ({
  item,
  type,
  title,
  longTitle,
  active,
  disabled,
  today,
  autofocus,
  onClick
}) => {
  const buttonRef = React.useRef(null);
  const intl = reactIntl.useIntl();
  React.useEffect(() => {
    if (autofocus) {
      setTimeout(() => {
        buttonRef.current?.focus();
      }, 0);
    }
  }, [autofocus]);
  const onCalendarClick = event => {
    event.preventDefault();
    if (!disabled) {
      onClick(item);
    }
  };
  const calculateAriaLabel = () => {
    if (active) {
      return `${longTitle || title || ''}, ${intl.formatMessage(DateLookup_messages.selected)} ${intl.formatMessage(DateLookup_messages[type])}`;
    }
    return longTitle || title;
  };
  return /*#__PURE__*/jsxRuntime.jsx("button", {
    ref: buttonRef,
    type: "button",
    className: clsx.clsx(`tw-date-lookup-${type}-option np-text-body-default-bold`, {
      active: !!active
    }, {
      today: !!today
    }),
    disabled: disabled,
    tabIndex: autofocus ? 0 : -1,
    "aria-label": calculateAriaLabel(),
    "aria-pressed": active,
    onClick: onCalendarClick,
    children: title || item
  });
};

module.exports = TableLink;
//# sourceMappingURL=TableLink.js.map
