"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.cssClass = void 0;
var classnames = require("classnames");
var PropTypes = require("prop-types");
var React = require("react");
var CopyToClipboard = require("react-copy-to-clipboard");
var Button_1 = require("../Button/Button");
var FlexBox_1 = require("../flex/FlexBox");
var ItemAlign_1 = require("../flex/ItemAlign");
require("./CopyContainer.less");
var propTypes = {
    children: PropTypes.node,
    copyText: PropTypes.string,
    buttonLabel: PropTypes.string,
    className: PropTypes.string,
    onCopyClick: PropTypes.func,
};
exports.cssClass = {
    CONTAINER: "CopyContainer",
    BUTTON: "CopyContainer--button",
};
/**
 * This component is useful when you want to make some text copyable.
 * It wraps the CopyToClipboard component.
 */
var CopyContainer = /** @class */ (function (_super) {
    __extends(CopyContainer, _super);
    function CopyContainer(props) {
        var _this = _super.call(this, props) || this;
        _this._onCopy = _this._onCopy.bind(_this);
        _this.state = {
            copied: false,
        };
        return _this;
    }
    CopyContainer.prototype._onCopy = function () {
        var _this = this;
        var onCopyClick = this.props.onCopyClick;
        this.setState({ copied: true });
        if (onCopyClick)
            onCopyClick();
        window.setTimeout(function () { return _this.setState({ copied: false }); }, 2 * 1000);
    };
    CopyContainer.prototype.render = function () {
        var _a = this.props, children = _a.children, copyText = _a.copyText, buttonLabel = _a.buttonLabel, className = _a.className, _b = _a.buttonType, buttonType = _b === void 0 ? "linkPlain" : _b;
        var copied = this.state.copied;
        var copyLabel = !copied ? buttonLabel || "Copy" : "Copied!";
        return (React.createElement(FlexBox_1.default, { alignItems: ItemAlign_1.default.CENTER, className: classnames(exports.cssClass.CONTAINER, className) },
            children,
            React.createElement(FlexBox_1.default, { alignItems: ItemAlign_1.default.START, grow: true },
                React.createElement(CopyToClipboard, { text: copyText || children || "", onCopy: this._onCopy },
                    React.createElement(Button_1.Button, { className: exports.cssClass.BUTTON, type: buttonType, value: copyLabel })))));
    };
    CopyContainer.propTypes = propTypes;
    return CopyContainer;
}(React.PureComponent));
exports.default = CopyContainer;
