'use client';
import React, { useRef, useState } from 'react';
import { Copy } from '../../icons/Copy/index.js';
import { useTranslation } from '../../providers/Translation/index.js';
import { Tooltip } from '../Tooltip/index.js';
const baseClass = 'copy-to-clipboard';
const CopyToClipboard = ({ defaultMessage, successMessage, value })=>{
    const ref = useRef(null);
    const [copied, setCopied] = useState(false);
    const [hovered, setHovered] = useState(false);
    const { t } = useTranslation();
    if (value) {
        return /*#__PURE__*/ React.createElement("button", {
            className: baseClass,
            onClick: ()=>{
                if (ref && ref.current) {
                    ref.current.select();
                    ref.current.setSelectionRange(0, value.length + 1);
                    document.execCommand('copy');
                    setCopied(true);
                }
            },
            onMouseEnter: ()=>{
                setHovered(true);
                setCopied(false);
            },
            onMouseLeave: ()=>{
                setHovered(false);
                setCopied(false);
            },
            type: "button"
        }, /*#__PURE__*/ React.createElement(Copy, null), /*#__PURE__*/ React.createElement(Tooltip, {
            delay: copied ? 0 : undefined,
            show: hovered || copied
        }, copied && (successMessage ?? t('general:copied')), !copied && (defaultMessage ?? t('general:copy'))), /*#__PURE__*/ React.createElement("textarea", {
            readOnly: true,
            ref: ref,
            tabIndex: -1,
            value: value
        }));
    }
    return null;
};
export default CopyToClipboard;

//# sourceMappingURL=index.js.map