"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CopyButton = void 0;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const use_t_1 = require("use-t");
const BasicButton_1 = require("nice-ui/lib/2-inline-block/BasicButton");
const Iconista_1 = require("nice-ui/lib/icons/Iconista");
const BasicTooltip_1 = require("nice-ui/lib/4-card/BasicTooltip");
const useMountedState_1 = tslib_1.__importDefault(require("react-use/lib/useMountedState"));
const copy = require('clipboard-copy'); // eslint-disable-line
const anchor = { horizontal: true, center: true };
const CopyButton = ({ onCopy, tooltip, ...rest }) => {
    const [t] = (0, use_t_1.useT)();
    const isMounted = (0, useMountedState_1.default)();
    const [copied, setCopied] = React.useState(false);
    const handleClick = (e) => {
        setCopied(true);
        copy(onCopy());
        setTimeout(() => {
            if (isMounted())
                setCopied(false);
        }, 2000);
        rest.onClick?.(e);
    };
    return (React.createElement(BasicTooltip_1.BasicTooltip, { anchor: anchor, show: copied || void 0, renderTooltip: copied ? () => t('Copied!') : () => t('Copy'), ...tooltip },
        React.createElement(BasicButton_1.BasicButton, { ...rest, onClick: handleClick },
            React.createElement(Iconista_1.Iconista, { key: copied ? 'check' : 'copy', set: copied ? 'atlaskit' : 'lucide', icon: copied ? 'check' : 'copy', width: 16, height: 16 }))));
};
exports.CopyButton = CopyButton;
//# sourceMappingURL=index.js.map