"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) || 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;
};
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 React = require("react");
var styled_components_1 = require("styled-components");
var copyToClipboard = require("copy-to-clipboard");
var recompose_1 = require("recompose");
var FaClipboard = require("react-icons/lib/fa/clipboard");
var Tooltip_1 = require("./Tooltip");
var hoc_1 = require("../hoc");
var utils_1 = require("../utils");
var Wrapper = styled_components_1.default.span(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n  white-space: initial;\n\n  code {\n    font-family: ", ";\n    padding: 2px 4px;\n    font-size: 90%;\n    color: #c7254e;\n    background-color: #f9f2f4;\n    border-radius: 2px;\n    white-space: normal;\n    word-wrap: break-word;\n    font-size: 1em;\n    margin-right: 3px;\n  }\n\n  .code-with-copy__copy {\n    .text-selection--none;\n    cursor: pointer;\n  }\n"], ["\n  white-space: initial;\n\n  code {\n    font-family: ", ";\n    padding: 2px 4px;\n    font-size: 90%;\n    color: #c7254e;\n    background-color: #f9f2f4;\n    border-radius: 2px;\n    white-space: normal;\n    word-wrap: break-word;\n    font-size: 1em;\n    margin-right: 3px;\n  }\n\n  .code-with-copy__copy {\n    .text-selection--none;\n    cursor: pointer;\n  }\n"])), function (props) { return props.theme.monospace; });
var copyIt = function (copy, text) {
    var copyText = (copy || text || '').trim();
    copyToClipboard(copyText);
};
var Base = function (_a) {
    var copy = _a.copy, text = _a.text, color = _a.color, props = __rest(_a, ["copy", "text", "color"]);
    return (React.createElement(Wrapper, __assign({}, props, { className: 'code-with-copy' }),
        React.createElement("code", { title: copy }, text.trim()),
        React.createElement("span", { onClick: utils_1.stopEvent },
            React.createElement(Tooltip_1.default, { message: 'Copied!', eventType: 'click' },
                React.createElement("span", { onClick: function () { return copyIt(copy, text); }, className: 'code-with-copy__copy' },
                    React.createElement(FaClipboard, { color: color }))))));
};
exports.default = recompose_1.compose(styled_components_1.withTheme, hoc_1.default)(Base);
var templateObject_1;
