import * as React from 'react';
import { useT } from 'use-t';
import { BasicButton } from 'nice-ui/lib/2-inline-block/BasicButton';
import { Iconista } from 'nice-ui/lib/icons/Iconista';
import { BasicTooltip } from 'nice-ui/lib/4-card/BasicTooltip';
import useMountedState from 'react-use/lib/useMountedState';
const copy = require('clipboard-copy'); // eslint-disable-line
const anchor = { horizontal: true, center: true };
export const CopyButton = ({ onCopy, tooltip, ...rest }) => {
    const [t] = useT();
    const isMounted = useMountedState();
    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, { anchor: anchor, show: copied || void 0, renderTooltip: copied ? () => t('Copied!') : () => t('Copy'), ...tooltip },
        React.createElement(BasicButton, { ...rest, onClick: handleClick },
            React.createElement(Iconista, { key: copied ? 'check' : 'copy', set: copied ? 'atlaskit' : 'lucide', icon: copied ? 'check' : 'copy', width: 16, height: 16 }))));
};
//# sourceMappingURL=index.js.map