"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = exports.buttonStyle = void 0;

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _colorsUtils = require("../theme/colors-utils");

var _ThemeProvider = require("../ThemeProvider");

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

var buttonStyle = function buttonStyle(_ref, theme) {
  var _ref$color = _ref.color,
      color = _ref$color === void 0 ? 'button' : _ref$color,
      variant = _ref.variant;
  return {
    style: {
      px: 6,
      borderRadius: 'radius',
      display: 'inline-flex',
      appearance: 'none',
      alignItems: 'center',
      justifyContent: 'center',
      transition: 'all 250ms',
      userSelect: 'none',
      position: 'relative',
      whiteSpace: 'nowrap',
      verticalAlign: 'middle',
      letterSpacing: 0,
      fontSize: 'smallBody',
      fontWeight: 'bold',
      lineHeight: 'shorter',
      outline: 'none',
      boxSizing: 'border-box',
      border: '1px',
      borderColor: 'transparent',
      _focus: {
        boxShadow: 'outline'
      }
    },
    variants: {
      primary: {
        color: 'buttonText',
        bg: "".concat(color, ".500"),
        boxShadow: 'button',
        _hover: {
          color: 'buttonText',
          bg: theme.colors[color] && (0, _colorsUtils.addWhite)(theme.colors[color][500], 0.12),
          boxShadow: 'raised'
        },
        _active: {
          bg: theme.colors[color] && (0, _colorsUtils.addBlack)(theme.colors[color][500], 0.12),
          boxShadow: 'pressed',
          dataActive: 'true'
        }
      },
      secondary: {
        color: "".concat(color, ".500"),
        bg: 'secondaryButton',
        boxShadow: 'button',
        _hover: {
          boxShadow: 'raised'
        },
        _active: {
          boxShadow: 'pressed',
          bg: 'border',
          dataActive: 'true'
        }
      },
      tertiary: {
        color: "".concat(color, ".500"),
        bg: 'tertiaryButton',
        borderColor: "".concat(color, ".500"),
        _hover: {
          bg: theme.colors[color] && (0, _colorsUtils.addOpacity)(theme.colors[color][500], 0.06)
        },
        _active: {
          bg: theme.colors[color] && (0, _colorsUtils.addOpacity)(theme.colors[color][500], 0.12),
          dataActive: 'true'
        }
      },
      unstyled: {
        color: "".concat(color, ".500"),
        bg: 'transparent',
        px: 0,
        _active: {
          bg: 'border',
          dataActive: 'true'
        }
      }
    },
    sizes: {
      xl: {
        height: 'input.xl',
        minWidth: 'input.xl',
        fontSize: 'body'
      },
      lg: {
        height: 'input.lg',
        minWidth: 'input.lg',
        fontSize: 'body'
      },
      md: {
        height: 'input.md',
        minWidth: 'input.md'
      },
      sm: {
        height: 'input.sm',
        minWidth: 'input.sm'
      }
    },
    isDisabled: {
      _disabled: {
        opacity: '40%',
        cursor: 'not-allowed',
        boxShadow: 'none',
        bg: variant === 'unstyled' ? 'transparent' : 'disabled',
        color: 'bodyText',
        border: 0
      }
    },
    isFullWidth: {
      width: 'full'
    },
    iconOnly: {
      borderRadius: 'full',
      px: 0,
      color: 'faintText'
    }
  };
};

exports.buttonStyle = buttonStyle;

var useButtonStyle = function useButtonStyle(props) {
  var theme = (0, _ThemeProvider.useTheme)();
  var styles = theme['styles'].button ? theme['styles'].button(props, theme) : buttonStyle(props, theme);
  return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, styles.style), styles.variants[props.variant]), styles.sizes[props.size]), props.isDisabled && styles.isDisabled), props.isFullWidth && styles.isFullWidth), props.iconOnly && styles.iconOnly);
};

var _default = useButtonStyle;
exports["default"] = _default;
//# sourceMappingURL=styles.js.map