import { __assign, __makeTemplateObject, __rest } from "tslib";
import styled, { css } from "styled-components";
import P1 from "../typography/P1";
import { LIGHT_THEME } from "../Pallette/themes";
import { Padding } from "../Pallette/style-utils";
import { Shape } from "../Pallette/Shape";
import { getTheme } from "../utils/theme/getTheme";
import { defaultThemeButton } from "./themes";
var COMPONENT_NAME = "button";
var ButtonSizeStyles = {
    m: css(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n    height: 48px;\n    border-radius: ", ";\n    ", ";\n  "], ["\n    height: 48px;\n    border-radius: ", ";\n    ", ";\n  "])), Shape.borderRadiusMedium, Padding.allSide(2, 3)),
    l: css(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n    height: 56px;\n    border-radius: ", ";\n    ", ";\n  "], ["\n    height: 56px;\n    border-radius: ", ";\n    ", ";\n  "])), Shape.borderRadiusMedium, Padding.allSide(2, 4)),
    s: css(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n    height: 32px;\n    border-radius: ", ";\n    ", ";\n  "], ["\n    height: 32px;\n    border-radius: ", ";\n    ", ";\n  "])), Shape.borderRadiusDefault, Padding.allSide(1, 2)),
    xs: css(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n    height: 24px;\n    border-radius: ", ";\n    ", ";\n  "], ["\n    height: 24px;\n    border-radius: ", ";\n    ", ";\n  "])), Shape.borderRadiusDefault, Padding.allSide(1, 1))
};
var pressedStylesButton = function (_a) {
    var theme = _a.theme, viewType = _a.viewType, $color = _a.$color;
    switch (viewType) {
        case "ghost":
            return css(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n        color: ", ";\n        .lead-icon {\n          color: ", ";\n        }\n      "], ["\n        color: ", ";\n        .lead-icon {\n          color: ", ";\n        }\n      "])), theme.components.button.colorGhostPressed, theme.components.button.iconColorGhostPressed);
        case "link":
            return css(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n        color: ", ";\n        .lead-icon {\n          color: ", ";\n        }\n      "], ["\n        color: ", ";\n        .lead-icon {\n          color: ", ";\n        }\n      "])), theme.components.button.colorLinkPressed, theme.components.button.iconColorLinkPressed);
        case "secondary":
            return css(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n        background-color: ", ";\n        color: ", ";\n        .lead-icon {\n          color: ", ";\n        }\n      "], ["\n        background-color: ", ";\n        color: ", ";\n        .lead-icon {\n          color: ", ";\n        }\n      "])), theme.components.button.backgroundSecondaryPressed, theme.components.button.colorSecondaryPressed, theme.components.button.iconColorSecondaryPressed);
        case "primary":
        default:
            return css(templateObject_8 || (templateObject_8 = __makeTemplateObject(["\n        background: ", ";\n        color: ", ";\n        .lead-icon {\n          color: ", ";\n        }\n      "], ["\n        background: ", ";\n        color: ", ";\n        .lead-icon {\n          color: ", ";\n        }\n      "])), theme.components.button["backgroundPrimary" + ($color || "") + "Pressed"], theme.components.button.colorPrimaryPressed, theme.components.button.iconColorPrimaryPressed);
    }
};
export var transformValueProps = function (_a) {
    var _b = _a.viewType, viewType = _b === void 0 ? "primary" : _b, $color = _a.$color, theme = _a.theme, $content = _a.$content, props = __rest(_a, ["viewType", "$color", "theme", "$content"]);
    return (__assign({ theme: theme, viewType: viewType, $content: $content, $color: $color ? $color.charAt(0).toUpperCase() + $color.slice(1) : undefined }, props));
};
export var ButtonComponent = styled(P1).attrs(function (props) { return (__assign(__assign({}, transformValueProps(props)), { theme: getTheme({
        theme: props.theme,
        componentName: COMPONENT_NAME,
        defaultTheme: defaultThemeButton
    }) })); })(templateObject_17 || (templateObject_17 = __makeTemplateObject(["\n  ", ";\n  position: relative;\n  display: flex;\n  align-items: center;\n  justify-content: center;\n  border: 0;\n  cursor: pointer;\n  transition: all 0.1s linear;\n  ", "\n  max-width: 100%;\n  white-space: nowrap;\n  user-select: none;\n  -webkit-user-select: none;\n  touch-action: manipulation;\n  text-decoration: none;\n  ", ";\n  .button-text {\n    text-overflow: ellipsis;\n    white-space: nowrap;\n    overflow: hidden;\n  }\n  ", ";\n\n  ", ";\n\n  ", ";\n\n  ", "\n"], ["\n  ", ";\n  position: relative;\n  display: flex;\n  align-items: center;\n  justify-content: center;\n  border: 0;\n  cursor: pointer;\n  transition: all 0.1s linear;\n  ", "\n  max-width: 100%;\n  white-space: nowrap;\n  user-select: none;\n  -webkit-user-select: none;\n  touch-action: manipulation;\n  text-decoration: none;\n  ", ";\n  .button-text {\n    text-overflow: ellipsis;\n    white-space: nowrap;\n    overflow: hidden;\n  }\n  ", ";\n\n  ", ";\n\n  ", ";\n\n  ", "\n"])), function (_a) {
    var theme = _a.theme;
    return css(templateObject_9 || (templateObject_9 = __makeTemplateObject(["\n    font-weight: ", ";\n    font-size: ", ";\n    font-family: ", ";\n  "], ["\n    font-weight: ", ";\n    font-size: ", ";\n    font-family: ", ";\n  "])), theme.typography.fontWeightMedium, theme.typography.fontSizeM, theme.typography.fontFamily);
}, function (_a) {
    var width = _a.width;
    return width && css(templateObject_10 || (templateObject_10 = __makeTemplateObject(["\n      width: ", ";\n    "], ["\n      width: ", ";\n    "])), width);
}, function (_a) {
    var $content = _a.$content;
    return $content && css(templateObject_11 || (templateObject_11 = __makeTemplateObject(["\n      .lead-icon {\n        margin-right: 12px;\n        min-width: 16px;\n      }\n    "], ["\n      .lead-icon {\n        margin-right: 12px;\n        min-width: 16px;\n      }\n    "])));
}, function (_a) {
    var _b = _a.size, size = _b === void 0 ? "l" : _b;
    return ButtonSizeStyles[size];
}, function (_a) {
    var viewType = _a.viewType, theme = _a.theme, $color = _a.$color;
    if (viewType === "ghost") {
        return css(templateObject_12 || (templateObject_12 = __makeTemplateObject(["\n        background: ", ";\n        color: ", ";\n        .lead-icon {\n          color: ", ";\n        }\n\n        &:hover:enabled {\n          color: ", ";\n          .lead-icon {\n            color: ", ";\n          }\n        }\n\n        &:active:enabled {\n          ", ";\n        }\n      "], ["\n        background: ", ";\n        color: ", ";\n        .lead-icon {\n          color: ", ";\n        }\n\n        &:hover:enabled {\n          color: ", ";\n          .lead-icon {\n            color: ", ";\n          }\n        }\n\n        &:active:enabled {\n          ", ";\n        }\n      "])), theme.components.button.backgroundGhost, theme.components.button.colorGhost, theme.components.button.iconColorGhost, theme.components.button.colorGhostHover, theme.components.button.iconColorGhostHover, pressedStylesButton);
    }
    if (viewType === "link") {
        return css(templateObject_13 || (templateObject_13 = __makeTemplateObject(["\n        background: ", ";\n        color: ", ";\n        .lead-icon {\n          color: ", ";\n        }\n\n        &:hover:enabled {\n          color: ", ";\n          .lead-icon {\n            color: ", ";\n          }\n        }\n\n        &:active:enabled {\n          ", ";\n        }\n      "], ["\n        background: ", ";\n        color: ", ";\n        .lead-icon {\n          color: ", ";\n        }\n\n        &:hover:enabled {\n          color: ", ";\n          .lead-icon {\n            color: ", ";\n          }\n        }\n\n        &:active:enabled {\n          ", ";\n        }\n      "])), theme.components.button.backgroundLink, theme.components.button.colorLink, theme.components.button.iconColorLink, theme.components.button.colorLinkHover, theme.components.button.iconColorLinkHover, pressedStylesButton);
    }
    if (viewType === "secondary") {
        return css(templateObject_14 || (templateObject_14 = __makeTemplateObject(["\n        background: ", ";\n        color: ", ";\n        .lead-icon {\n          color: ", ";\n        }\n\n        &:disabled {\n          background: ", ";\n        }\n\n        &:hover:enabled {\n          background: ", ";\n          color: ", ";\n          .lead-icon {\n            color: ", ";\n          }\n        }\n\n        &:active:enabled {\n          ", ";\n        }\n      "], ["\n        background: ", ";\n        color: ", ";\n        .lead-icon {\n          color: ", ";\n        }\n\n        &:disabled {\n          background: ", ";\n        }\n\n        &:hover:enabled {\n          background: ", ";\n          color: ", ";\n          .lead-icon {\n            color: ", ";\n          }\n        }\n\n        &:active:enabled {\n          ", ";\n        }\n      "])), theme.components.button.backgroundSecondary, theme.components.button.colorSecondary, theme.components.button.iconColorSecondary, theme.components.button.backgroundDisabled, theme.components.button.backgroundSecondaryHover, theme.components.button.colorSecondaryHover, theme.components.button.iconColorSecondaryHover, pressedStylesButton);
    }
    return css(templateObject_15 || (templateObject_15 = __makeTemplateObject(["\n      background: ", ";\n      color: ", ";\n      .lead-icon {\n        color: ", ";\n      }\n\n      &:disabled {\n        background: ", ";\n      }\n\n      &:hover:enabled {\n        background: ", ";\n        color: ", ";\n        .lead-icon {\n          color: ", ";\n        }\n      }\n      &:active:enabled {\n        ", ";\n      }\n    "], ["\n      background: ", ";\n      color: ", ";\n      .lead-icon {\n        color: ", ";\n      }\n\n      &:disabled {\n        background: ", ";\n      }\n\n      &:hover:enabled {\n        background: ", ";\n        color: ", ";\n        .lead-icon {\n          color: ", ";\n        }\n      }\n      &:active:enabled {\n        ", ";\n      }\n    "])), theme.components.button["backgroundPrimary" + ($color || "")], theme.components.button.colorPrimary, theme.components.button.iconColorPrimary, theme.components.button.backgroundDisabled, theme.components.button["backgroundPrimary" + ($color || "") + "Hover"], theme.components.button.colorPrimaryHover, theme.components.button.iconColorPrimaryHover, pressedStylesButton);
}, function (_a) {
    var isPressed = _a.isPressed;
    return isPressed && pressedStylesButton;
}, function (_a) {
    var theme = _a.theme;
    return css(templateObject_16 || (templateObject_16 = __makeTemplateObject(["\n    &:disabled {\n      color: ", ";\n      .lead-icon {\n        color: ", ";\n      }\n      cursor: not-allowed;\n    }\n  "], ["\n    &:disabled {\n      color: ", ";\n      .lead-icon {\n        color: ", ";\n      }\n      cursor: not-allowed;\n    }\n  "])), theme.components.button.colorDisabled, theme.components.button.iconColorDisabled);
});
ButtonComponent.defaultProps = {
    theme: LIGHT_THEME
};
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9, templateObject_10, templateObject_11, templateObject_12, templateObject_13, templateObject_14, templateObject_15, templateObject_16, templateObject_17;
