import { __assign, __rest } from "tslib";
import React, { useContext } from 'react';
import classNames from 'classnames';
import { ConfigContext } from '../config-provider/config-context';
import { getPrefixCls } from '../_utils/general';
var copy = function (value) {
    var textArea = document.createElement('textarea');
    textArea.style.background = 'transparent';
    textArea.value = value;
    document.body.appendChild(textArea);
    textArea.select();
    try {
        document.execCommand('copy');
    }
    catch (err) {
        console.log('Oops, unable to copy');
    }
    document.body.removeChild(textArea);
};
var CopyToClipboard = function (props) {
    var customisedCls = props.prefixCls, text = props.text, className = props.className, children = props.children, onClick = props.onClick, otherProps = __rest(props, ["prefixCls", "text", "className", "children", "onClick"]);
    var configContext = useContext(ConfigContext);
    var prefixCls = getPrefixCls('copy', configContext.prefixCls, customisedCls);
    var cls = classNames(prefixCls, className);
    var btnOnClick = function (e) {
        copy(text);
        onClick && onClick(e);
    };
    return (React.createElement("span", __assign({}, otherProps, { className: cls, onClick: btnOnClick }), children));
};
CopyToClipboard.displayName = 'CopyToClipboard';
export default CopyToClipboard;
//# sourceMappingURL=index.js.map