'use strict';

var jsxRuntime = require('../../node_modules/.pnpm/react@18.2.0/node_modules/react/jsx-runtime.cjs');
var useCopyToClipboard = require('../../hooks/useCopyToClipboard.cjs');
var reactIcons_esm = require('../../node_modules/.pnpm/@radix-ui_react-icons@1.3.0_react@18.2.0/node_modules/@radix-ui/react-icons/dist/react-icons.esm.cjs');
var checkCircleFilled = require('../../icons/assets/check-circle-filled.svg.cjs');
var React = require('react');
var iconButton = require('../icon-button/icon-button.cjs');

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

exports.CopyButton = CopyButton;
//# sourceMappingURL=copy-button.cjs.map
