"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CopyableText = void 0;
const react_1 = __importStar(require("react"));
const react_copy_to_clipboard_1 = __importDefault(require("react-copy-to-clipboard"));
const Icon_1 = require("../Icon");
const icons = __importStar(require("../../assets/images/icons"));
const sc = __importStar(require("./styles"));
exports.CopyableText = ({ width, height, color, copyText, tooltip, children, }) => {
    const [copied, setCopied] = react_1.useState(false);
    const [timerRef, setTimerRef] = react_1.useState(0);
    react_1.useEffect(() => {
        return () => {
            if (timerRef !== 0)
                clearTimeout(timerRef);
        };
    }, [timerRef]);
    const handleCopyClick = () => {
        setCopied(true);
        setTimerRef(setTimeout(() => {
            setCopied(false);
        }, 2000));
    };
    return (react_1.default.createElement(react_copy_to_clipboard_1.default, { text: copyText },
        react_1.default.createElement(sc.CopyText, { onClick: handleCopyClick, copied: copied, tooltip: tooltip || 'Copied' },
            children,
            react_1.default.createElement(Icon_1.Icon, { Asset: icons.SvgCopy, width: width || 14, height: height || 14, color: color || 'gray.2', ml: "s" }))));
};
//# sourceMappingURL=CopyableText.js.map