'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

var _getClassName2 = require('babel-plugin-react-css-modules/dist/browser/getClassName');

var _getClassName3 = _interopRequireDefault(_getClassName2);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

var _classnames = require('classnames');

var _classnames2 = _interopRequireDefault(_classnames);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var _styleModuleImportMap = {
  './button.scss': {
    'base': 'flive_button_base',
    'content': 'flive_button_content',
    'button-filled': 'flive_button_button-filled',
    'primary': 'flive_button_primary flive_button_button-filled',
    'info': 'flive_button_info flive_button_button-filled',
    'alert': 'flive_button_alert flive_button_button-filled',
    'warning': 'flive_button_warning flive_button_button-filled',
    'cancel': 'flive_button_cancel flive_button_button-filled',
    'dash-lagoon': 'flive_button_dash-lagoon',
    'dash-night-blue': 'flive_button_dash-night-blue',
    'state-dropdown-closed': 'flive_button_state-dropdown-closed',
    'state-dropdown-opened': 'flive_button_state-dropdown-opened',
    'nav-bar': 'flive_button_nav-bar',
    'nav-bar-level-2': 'flive_button_nav-bar-level-2',
    'tab': 'flive_button_tab',
    'state-opened': 'flive_button_state-opened',
    'lg': 'flive_button_lg',
    'md': 'flive_button_md',
    'sm': 'flive_button_sm',
    'disabled': 'flive_button_disabled',
    'icon': 'flive_button_icon',
    'floating-action': 'flive_button_floating-action',
    'button-collapsible-card': 'flive_button_button-collapsible-card'
  }
};

function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }

var propTypes = {
  /** @ignore */
  children: _propTypes2.default.node,
  /** @ignore */
  className: _propTypes2.default.string,
  /** @ignore */
  onClick: _propTypes2.default.func,
  /** @ignore */
  disabled: _propTypes2.default.bool,
  /** A component, button, a, react router Link, etc... */
  component: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.object, _propTypes2.default.func]),
  /** props passed to child component */
  childProps: _propTypes2.default.object,
  /** small, medium, large */
  size: _propTypes2.default.oneOf(['sm', 'md', 'lg', 'nav-bar', 'nav-bar-level-2']),
  /** primary, info */
  variant: _propTypes2.default.oneOf(['primary', 'cancel', 'info', 'alert', 'warning', 'dash-lagoon', 'icon', 'dash-night-blue', 'tab', 'button-collapsible-card']),
  state: _propTypes2.default.oneOf(['opened', 'dropdown-opened', 'dropdown-closed']),
  active: _propTypes2.default.bool
};

var defaultProps = {
  children: undefined,
  className: undefined,
  disabled: false,
  onClick: null,
  component: 'button',
  childProps: {},
  size: 'md',
  variant: 'primary',
  state: null,
  active: undefined
};

/**
 * A generic button
 */
var Button = function Button(props) {
  var _classNames;

  var children = props.children,
      className = props.className,
      size = props.size,
      variant = props.variant,
      state = props.state,
      onClick = props.onClick,
      disabled = props.disabled,
      MyComponent = props.component,
      active = props.active,
      childProps = props.childProps,
      rest = _objectWithoutProperties(props, ['children', 'className', 'size', 'variant', 'state', 'onClick', 'disabled', 'component', 'active', 'childProps']);

  var onDisabledLink = function onDisabledLink(e) {
    if (disabled) {
      e.preventDefault();
    } else if (onClick) {
      onClick(e);
    }
  };

  return _react2.default.createElement(
    MyComponent,
    _extends({
      onClick: onDisabledLink,
      disabled: disabled
    }, childProps, rest, {
      className: (className ? className + ' ' : '') + (0, _getClassName3.default)((0, _classnames2.default)('base', variant, size, (_classNames = {
        disabled: disabled
      }, _defineProperty(_classNames, 'state-' + state, state), _defineProperty(_classNames, 'state-opened', active), _classNames)), _styleModuleImportMap)
    }),
    _react2.default.createElement(
      'span',
      { className: 'flive_button_content' },
      children
    )
  );
};

Button.propTypes = propTypes;
Button.defaultProps = defaultProps;
Button.componentName = 'Button';

exports.default = Button;
module.exports = exports['default'];