"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = require("react");
var _Button = require("../Button");
var _Dialog = require("../Dialog");
var _Icons = require("../Icons");
var _i18n = require("../i18n");
var _classnames = _interopRequireDefault(require("classnames"));
var _useThirdPartyExternalLinkAnalytics = _interopRequireDefault(require("./useThirdPartyExternalLinkAnalytics"));
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
/**
 * For information about how and when to use this component,
 * [refer to its full documentation page](https://design.cms.gov/components/third-party-external-link/).
 */
const ThirdPartyExternalLink = props => {
  const {
    contentRef,
    buttonAnalyticsHandler
  } = (0, _useThirdPartyExternalLinkAnalytics.default)(props);
  const {
    href,
    children,
    className,
    learnMoreUrl,
    origin
  } = props;
  const [showDialog, setShowDialog] = (0, _react.useState)(false);
  function open(event) {
    event.preventDefault();
    setShowDialog(true);
  }
  function close() {
    setShowDialog(false);
  }
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
    children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("a", {
      className: (0, _classnames.default)('ds-c-external-link', className),
      onClick: open,
      href: href,
      ref: contentRef,
      children: [children, /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icons.ExternalLinkIcon, {
        className: "ds-c-external-link__icon"
      })]
    }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Dialog.Dialog, {
      onExit: close,
      heading: (0, _i18n.t)('thirdPartyExternalLink.dialogHeading', {
        origin
      }),
      actions: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.Button, {
        variation: "solid",
        href: href,
        analytics: true,
        onAnalyticsEvent: buttonAnalyticsHandler,
        children: (0, _i18n.t)('thirdPartyExternalLink.confirmationButtonText')
      }, "external-link__confirm"), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.Button, {
        variation: "ghost",
        onClick: close,
        children: (0, _i18n.t)('thirdPartyExternalLink.cancelButtonText')
      }, "external-link__cancel")],
      isOpen: showDialog,
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("p", {
        children: (0, _i18n.t)('thirdPartyExternalLink.dialogBody')
      }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("p", {
        children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("a", {
          href: learnMoreUrl,
          children: (0, _i18n.t)('thirdPartyExternalLink.learnMoreText')
        }), "."]
      })]
    })]
  });
};
ThirdPartyExternalLink.defaultProps = {};
var _default = exports.default = ThirdPartyExternalLink;