'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 _jsx = function () { var REACT_ELEMENT_TYPE = typeof Symbol === "function" && Symbol.for && Symbol.for("react.element") || 0xeac7; return function createRawReactElement(type, props, key, children) { var defaultProps = type && type.defaultProps; var childrenLength = arguments.length - 3; if (!props && childrenLength !== 0) { props = {}; } if (props && defaultProps) { for (var propName in defaultProps) { if (props[propName] === void 0) { props[propName] = defaultProps[propName]; } } } else if (!props) { props = defaultProps || {}; } if (childrenLength === 1) { props.children = children; } else if (childrenLength > 1) { var childArray = Array(childrenLength); for (var i = 0; i < childrenLength; i++) { childArray[i] = arguments[i + 3]; } props.children = childArray; } return { $$typeof: REACT_ELEMENT_TYPE, type: type, key: key === undefined ? null : '' + key, ref: null, props: props, _owner: null }; }; }();

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _AbstractButton2 = require('../AbstractButton');

var _AbstractButton3 = _interopRequireDefault(_AbstractButton2);

var _Spinner = require('../Spinner');

var _Spinner2 = _interopRequireDefault(_Spinner);

var _View = require('../View');

var _View2 = _interopRequireDefault(_View);

var _theme = require('../const/theme');

var _styles = require('../helpers/styles');

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

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var PrimaryButton = function (_AbstractButton) {
    _inherits(PrimaryButton, _AbstractButton);

    function PrimaryButton() {
        _classCallCheck(this, PrimaryButton);

        return _possibleConstructorReturn(this, (PrimaryButton.__proto__ || Object.getPrototypeOf(PrimaryButton)).apply(this, arguments));
    }

    _createClass(PrimaryButton, [{
        key: 'render',
        value: function render() {
            var props = this.props;

            return _react2.default.createElement(
                'button',
                _extends({}, this.getDefaultRenderProps(), {
                    className: _styles.css.apply(undefined, _toConsumableArray(this.buildStyleList(styles, 'button')).concat([styles.getPreset('size', props.size)])) }),
                !props.isWaiting ? props.children : _jsx(_View2.default, {
                    styles: [styles.content]
                }, void 0, _jsx(_View2.default, {
                    styles: [styles.isFetchingText]
                }, void 0, props.children), _jsx(_View2.default, {
                    styles: [styles.spinner]
                }, void 0, _jsx(_Spinner2.default, {
                    size: 'xs',
                    color: '#fff'
                })))
            );
        }
    }]);

    return PrimaryButton;
}(_AbstractButton3.default);

PrimaryButton.propTypes = {
    /**
     * Is button disabled.
     */
    isDisabled: _react.PropTypes.bool,
    /**
     * Is button in toggle mod, on click button change checked state.
     */
    isToggleMod: _react.PropTypes.bool,
    /**
     * Is button in checked state, use only for isToggleMod=true
     */
    isChecked: _react.PropTypes.bool,
    /**
     * On focus event handler
     */
    onFocus: _react.PropTypes.func,
    /**
     * On blur event handler
     */
    onBlur: _react.PropTypes.func,
    /**
     * On mouse enter event handler
     */
    onMouseEnter: _react.PropTypes.func,
    /**
     * On focus leave evnet handler
     */
    onMouseLeave: _react.PropTypes.func,
    /**
     * On click event handler
     */
    onClick: _react.PropTypes.func,
    /**
     * On mouse down event handler
     */
    onMouseDown: _react.PropTypes.func,
    /**
     * On mouse up event handler
     */
    onMouseUp: _react.PropTypes.func,
    /**
     * Button size
     */
    size: _react.PropTypes.oneOf(['l', 'm', 's', 'xs']),
    /**
     * Is button has preloader
     */
    isWaiting: _react.PropTypes.bool
};
PrimaryButton.defaultProps = {
    size: 'm'
};
exports.default = PrimaryButton;


var styles = _styles.StyleSheet.create({
    button: _extends({}, _AbstractButton3.default.BASE_ROOT_STYLE, {
        position: 'relative',
        borderRadius: '4px',

        maxWidth: '100%',
        padding: '6px 12px',

        fontSize: _theme.FONT.SIZE.BUTTON_TEXT,
        color: '#fff',
        lineHeight: '1.2rem',

        background: 'linear-gradient(to top, rgb(0,159,101) 0%, rgb(1,171,109) 100%)',
        boxShadow: 'inset 0px -1px 0px 0px rgba(27, 42, 48, 0.35)',
        '&:hover': {
            background: 'linear-gradient(to top, rgb(0,151,96) 0%, rgb(1,162,103) 100%)'
        },
        '&:active': {
            background: 'linear-gradient(to top, rgb(0,151,96) 0%, rgb(1,162,103) 100%)',
            boxShadow: 'inset 0px 2px 0px 0px rgba(27, 42, 48, 0.1), inset 0px -1px 0px 0px #b4bdc0, inset 1px 1px 0px 0px #c6cbce, inset -1px 0px 0px 0px #c6cbce'
        }
    }),
    buttonIsFocused: {
        boxShadow: _theme.SHADOW.FOCUS + ', inset 0px -2px 0px 0px rgba(27, 42, 48, 0.1), inset 0px -1px 0px 0px #b4bdc0, inset 1px 1px 0px 0px #c6cbce, inset -1px 0px 0px 0px #c6cbce;'
    },
    sizeL: {
        padding: '6px 12px',
        minWidth: '36px',
        height: '36px'
    },
    sizeM: {
        padding: '4px 12px',
        minWidth: '32px',
        height: '32px'
    },
    sizeS: {
        padding: '2px 8px',
        minWidth: '28px',
        height: '28px'
    },
    sizeXs: {
        fontSize: _theme.FONT.SIZE.BUTTON_SMALL_TEXT,
        padding: '0 8px',
        minWidth: '24px',
        height: '24px'
    },
    buttonIsDisabled: {
        cursor: 'default',
        transition: 'none',
        color: _theme.COLOR.MUTED,
        border: '1px solid #c3cacd',
        boxShadow: 'none',
        background: _theme.COLOR.DISABLED,
        '&:hover': {
            cursor: 'default',
            border: '1px solid #c3cacd',
            boxShadow: 'none',
            background: _theme.COLOR.DISABLED
        },
        '&:active': {
            cursor: 'default',
            border: '1px solid #c3cacd',
            boxShadow: 'none',
            background: _theme.COLOR.DISABLED
        }
    },
    content: {
        position: 'relative'
    },
    spinner: {
        position: 'absolute',
        left: '50%',
        top: '50%',
        marginLeft: '-8px',
        marginTop: '-8px'
    },
    isFetchingText: {
        visibility: 'hidden'
    }
});