'use strict';

var index = require('../../core/Button/index.js');
var useParrotTranslation = require('../../hooks/useParrotTranslation.js');
var React = require('react');
var CopyTooltip = require('./CopyTooltip.js');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var React__default = /*#__PURE__*/_interopDefault(React);

const CopyButton = ({
  text,
  buttonText,
  tooltipText
}) => {
  const { t } = useParrotTranslation();
  const [tooltipVisible, setTooltipVisible] = React.useState(false);
  const handleCopy = async () => {
    try {
      setTooltipVisible(true);
      setTimeout(() => {
        setTooltipVisible(false);
      }, 1e3);
    } catch (err) {
    }
  };
  return /* @__PURE__ */ React__default.default.createElement(
    CopyTooltip,
    {
      tooltipProps: { visible: tooltipVisible },
      text,
      afterTooltip: tooltipText ? tooltipText : t("common.has_copied_to_clipboard")
    },
    /* @__PURE__ */ React__default.default.createElement(index, { onClick: handleCopy }, buttonText ? buttonText : t("common.copy"))
  );
};
var CopyButton$1 = CopyButton;

module.exports = CopyButton$1;
