"use strict";
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
    if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
    return cooked;
};
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
            t[p[i]] = s[p[i]];
    return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
var copyToClipboard = require("copy-to-clipboard");
var React = require("react");
var FaClipboard = require("react-icons/lib/fa/clipboard");
var recompose_1 = require("recompose");
var styled_components_1 = require("styled-components");
var asRendition_1 = require("../asRendition");
var utils_1 = require("../utils");
var Button_1 = require("./Button");
var Txt_1 = require("./Txt");
var Wrapper = utils_1.withProps()(styled_components_1.default(Txt_1.default.span))(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n\twhite-space: initial;\n\n\tcode {\n\t\tfont-family: ", ";\n\t\tpadding: 2px 4px;\n\t\tfont-size: 90%;\n\t\tcolor: #c7254e;\n\t\tbackground-color: #f9f2f4;\n\t\tborder-radius: 2px;\n\t\twhite-space: normal;\n\t\tword-wrap: break-word;\n\t\tfont-size: 1em;\n\t\tmargin-right: 3px;\n\t}\n\n\t.code-with-copy__copy {\n\t\t.text-selection--none;\n\t\tcursor: pointer;\n\t\tvisibility: ", ";\n\t}\n\n\t&:hover .code-with-copy__copy {\n\t\tvisibility: visible;\n\t}\n"], ["\n\twhite-space: initial;\n\n\tcode {\n\t\tfont-family: ", ";\n\t\tpadding: 2px 4px;\n\t\tfont-size: 90%;\n\t\tcolor: #c7254e;\n\t\tbackground-color: #f9f2f4;\n\t\tborder-radius: 2px;\n\t\twhite-space: normal;\n\t\tword-wrap: break-word;\n\t\tfont-size: 1em;\n\t\tmargin-right: 3px;\n\t}\n\n\t.code-with-copy__copy {\n\t\t.text-selection--none;\n\t\tcursor: pointer;\n\t\tvisibility: ",
    ";\n\t}\n\n\t&:hover .code-with-copy__copy {\n\t\tvisibility: visible;\n\t}\n"])), function (props) { return props.theme.monospace; }, function (props) {
    return props.showCopyButton
        ? props.showCopyButton === 'always'
            ? 'visible'
            : 'hidden'
        : 'visible';
});
var Base = function (_a) {
    var copy = _a.copy, text = _a.text, color = _a.color, props = __rest(_a, ["copy", "text", "color"]);
    var normalizedText = (text || '').toString().trim();
    var normalizedCopy = (copy || normalizedText).toString().trim();
    return (React.createElement(Wrapper, __assign({}, props, { className: "code-with-copy" }),
        React.createElement("code", { title: normalizedCopy }, normalizedText || normalizedCopy),
        React.createElement("span", { onClick: function (e) { return utils_1.stopEvent(e); } },
            React.createElement(Button_1.default, { plaintext: true, tooltip: { text: 'Copied!', trigger: 'click' }, onClick: function () { return copyToClipboard(normalizedCopy); }, className: "code-with-copy__copy" },
                React.createElement(FaClipboard, { color: color })))));
};
exports.default = recompose_1.compose(styled_components_1.withTheme, asRendition_1.default)(Base);
var templateObject_1;
