import { __assign, __extends, __rest } from "tslib";
import { Children, cloneElement, Component } from 'react';
import copy from './CopyToClipboard';
var CopyToClipboard = (function (_super) {
    __extends(CopyToClipboard, _super);
    function CopyToClipboard() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.onClick = function (event) {
            var _a = _this.props, text = _a.text, onCopy = _a.onCopy, children = _a.children;
            var elem = Children.only(children);
            var result = copy(text);
            if (onCopy) {
                onCopy(text, result);
            }
            if (elem && elem.props && typeof elem.props.onClick === 'function') {
                elem.props.onClick(event);
            }
        };
        return _this;
    }
    CopyToClipboard.prototype.render = function () {
        var _a = this.props, _text = _a.text, _onCopy = _a.onCopy, children = _a.children, props = __rest(_a, ["text", "onCopy", "children"]);
        var elem = Children.only(children);
        return cloneElement(elem, __assign(__assign({}, props), { onClick: this.onClick }));
    };
    return CopyToClipboard;
}(Component));
export { CopyToClipboard };
export default CopyToClipboard;
