import { j as jsxRuntimeExports } from '../../node_modules/.pnpm/react@18.2.0/node_modules/react/jsx-runtime.js';
import { useCopyToClipboard } from '../../hooks/useCopyToClipboard.js';
import { CopyIcon } from '../../node_modules/.pnpm/@radix-ui_react-icons@1.3.0_react@18.2.0/node_modules/@radix-ui/react-icons/dist/react-icons.esm.js';
import { ReactComponent as SvgCheckCircleFilled } from '../../icons/assets/check-circle-filled.svg.js';
import { useState } from 'react';
import { IconButton } from '../icon-button/icon-button.js';

const CopyButton = ({ text, resetTimeout = 1000, resetIcon = true, ...props }) => {
    const { copy } = useCopyToClipboard();
    const [isCopied, setIsCopied] = useState(false);
    async function onCopy() {
        const res = await copy(text);
        if (res) {
            setIsCopied(true);
            if (resetIcon) {
                setTimeout(() => {
                    setIsCopied(false);
                }, resetTimeout);
            }
        }
    }
    return (jsxRuntimeExports.jsx(IconButton, { ...props, onClick: onCopy, "data-test-id": "copy-button", children: isCopied ? (jsxRuntimeExports.jsx(SvgCheckCircleFilled, { color: "var(--rs-color-foreground-success-primary)" })) : (jsxRuntimeExports.jsx(CopyIcon, {})) }));
};

export { CopyButton };
//# sourceMappingURL=copy-button.js.map
