"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 grommet_1 = require("grommet");
var React = require("react");
var styled_components_1 = require("styled-components");
var asRendition_1 = require("../asRendition");
var utils_1 = require("../utils");
var ButtonBase = styled_components_1.default(grommet_1.Button)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n\tfont-family: ", ";\n\tfont-weight: ", ";\n\theight: ", ";\n\n\tsvg {\n\t\tcolor: inherit !important;\n\t\tfont-size: 0.875em;\n\t}\n\n\t/* These rules cause consistent styling when the button is rendered as a link */\n\tdisplay: inline-flex;\n\talign-items: center;\n\tjustify-content: center;\n"], ["\n\tfont-family: ", ";\n\tfont-weight: ", ";\n\theight: ", ";\n\n\tsvg {\n\t\tcolor: inherit !important;\n\t\tfont-size: 0.875em;\n\t}\n\n\t/* These rules cause consistent styling when the button is rendered as a link */\n\tdisplay: inline-flex;\n\talign-items: center;\n\tjustify-content: center;\n"])), function (props) { return props.theme.titleFont; }, function (props) { return utils_1.normal(props); }, function (props) { return utils_1.px(props.theme.space[4]); });
var ColouredButton = styled_components_1.default(ButtonBase)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n\tcolor: white;\n"], ["\n\tcolor: white;\n"])));
var Outline = styled_components_1.default(ButtonBase)(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n\tcolor: ", ";\n"], ["\n\tcolor: ",
    ";\n"])), function (props) {
    return utils_1.getColor(props, 'color', 'main') || props.theme.colors.text.main;
});
var Plain = styled_components_1.default(ButtonBase)(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n\tcolor: ", ";\n\theight: auto;\n\tfont-weight: ", ";\n\tborder-radius: 0;\n\n\t&:hover:enabled,\n\t&:focus:enabled,\n\t&:active:enabled {\n\t\tborder-bottom: 1px solid;\n\t}\n"], ["\n\tcolor: ",
    ";\n\theight: auto;\n\tfont-weight: ", ";\n\tborder-radius: 0;\n\n\t&:hover:enabled,\n\t&:focus:enabled,\n\t&:active:enabled {\n\t\tborder-bottom: 1px solid;\n\t}\n"])), function (props) {
    return utils_1.getColor(props, 'color', 'main') || props.theme.colors.text.main;
}, function (props) { return utils_1.normal(props); });
var underlineButtonActiveStyles = function (props) { return "\n\tcolor: " + (utils_1.getColor(props, 'color', 'main') || props.theme.colors.text.main) + ";\n\tbackground: none;\n\tbox-shadow: 0px -1px 0 0px inset;\n"; };
var Underline = styled_components_1.default(Plain).attrs({
    plain: true,
})(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n\t", "\n\tborder-bottom: 1px solid;\n\tbackground: none;\n\n\t&:hover:enabled,\n\t&:focus:enabled,\n\t&:active:enabled {\n\t\t", ";\n\t}\n"], ["\n\t", "\n\tborder-bottom: 1px solid;\n\tbackground: none;\n\n\t&:hover:enabled,\n\t&:focus:enabled,\n\t&:active:enabled {\n\t\t", ";\n\t}\n"])), function (props) { return (props.active ? underlineButtonActiveStyles(props) : ''); }, underlineButtonActiveStyles);
var getStyledButton = function (_a, isPrimary) {
    var outline = _a.outline, underline = _a.underline, plain = _a.plain, active = _a.active;
    if (plain) {
        return Plain;
    }
    if (underline) {
        return Underline;
    }
    if ((outline && !active) || !isPrimary) {
        return Outline;
    }
    return ColouredButton;
};
var Base = function (props) {
    var outline = props.outline, underline = props.underline, children = props.children, label = props.label, primary = props.primary, color = props.color, plain = props.plain, active = props.active, restProps = __rest(props, ["outline", "underline", "children", "label", "primary", "color", "plain", "active"]);
    var basePrimary = !!props.bg ||
        (!!utils_1.getColoringType(props) && !outline && !underline && !props.plain);
    var baseColor = props.bg || utils_1.getColor(props, 'bg', 'main');
    if (active) {
        basePrimary = !basePrimary;
        if (basePrimary && !baseColor) {
            baseColor = utils_1.getColor({ tertiary: true, theme: props.theme }, 'bg', 'main');
        }
    }
    var StyledButton = getStyledButton(props, basePrimary);
    return (React.createElement(StyledButton, __assign({ primary: basePrimary, color: baseColor, active: active && (underline || plain) }, restProps, { plain: !!plain || !!underline, label: label || children })));
};
exports.default = asRendition_1.default(Base, [], ['width', 'color', 'bg']);
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5;
