'use strict';

Object.defineProperty(exports, "__esModule", {
    value: true
});
exports.ReverseButton = exports.AdvanceButton = undefined;

var _react = require('react');

var React = _interopRequireWildcard(_react);

var _compose = require('recompose/compose');

var _compose2 = _interopRequireDefault(_compose);

var _setDisplayName = require('recompose/setDisplayName');

var _setDisplayName2 = _interopRequireDefault(_setDisplayName);

var _withStepper = require('./with-stepper');

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

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

var __rest = undefined && undefined.__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;
};

/**
 * Renders a button to go to the next step
 *
 * ### Usage
 * ```
 * <AdvanceButton>
 *   Next
 * </AdvanceButton>
 * ```
 */
var AdvanceButton = exports.AdvanceButton = (0, _compose2.default)(_withStepper.withStepper, (0, _setDisplayName2.default)('AdvanceButton'))(function (_a) {
    var _a$component = _a.component,
        Button = _a$component === undefined ? 'button' : _a$component,
        _ = _a.canReverse,
        __ = _a.pageState,
        ___ = _a.setPageState,
        pages = _a.pages,
        canAdvance = _a.canAdvance,
        canFinish = _a.canFinish,
        currentPage = _a.currentPage,
        setPageIndex = _a.setPageIndex,
        disabled = _a.disabled,
        _onClick = _a.onClick,
        onNext = _a.onNext,
        onFinish = _a.onFinish,
        finishLabel = _a.finishLabel,
        children = _a.children,
        props = __rest(_a, ["component", "canReverse", "pageState", "setPageState", "pages", "canAdvance", "canFinish", "currentPage", "setPageIndex", "disabled", "onClick", "onNext", "onFinish", "finishLabel", "children"]);

    var isLast = finishLabel && currentPage + 1 >= pages.length;
    return React.createElement(Button, Object.assign({ disabled: disabled || (isLast ? !canFinish : !canAdvance) }, props, { onClick: function onClick(e) {
            var returnValue = void 0;
            if (currentPage + 1 >= pages.length) {
                if (onFinish) {
                    returnValue = onFinish();
                }
            } else {
                if (onNext) {
                    returnValue = onNext();
                }
                setPageIndex(currentPage + 1);
            }
            return _onClick ? _onClick(e) : returnValue;
        } }), finishLabel && currentPage + 1 >= pages.length ? finishLabel : children);
});
/**
 * Renders a button to go to the previous step
 *
 * ### Usage
 * ```
 * <ReverseButton>
 *   Back
 * </ReverseButton>
 * ```
 */
var ReverseButton = exports.ReverseButton = (0, _compose2.default)(_withStepper.withStepper, (0, _setDisplayName2.default)('ReverseButton'))(function (_a) {
    var _a$component2 = _a.component,
        Button = _a$component2 === undefined ? 'button' : _a$component2,
        _ = _a.canAdvance,
        __ = _a.pages,
        ___ = _a.pageState,
        ____ = _a.setPageState,
        _____ = _a.canFinish,
        canReverse = _a.canReverse,
        currentPage = _a.currentPage,
        setPageIndex = _a.setPageIndex,
        disabled = _a.disabled,
        _onClick2 = _a.onClick,
        onPrevious = _a.onPrevious,
        onCancel = _a.onCancel,
        cancelLabel = _a.cancelLabel,
        children = _a.children,
        props = __rest(_a, ["component", "canAdvance", "pages", "pageState", "setPageState", "canFinish", "canReverse", "currentPage", "setPageIndex", "disabled", "onClick", "onPrevious", "onCancel", "cancelLabel", "children"]);

    return React.createElement(Button, Object.assign({ disabled: disabled || !cancelLabel && !canReverse }, props, { onClick: function onClick(e) {
            var returnValue = void 0;
            if (currentPage <= 0) {
                if (onCancel) {
                    returnValue = onCancel();
                }
            } else {
                if (onPrevious) {
                    returnValue = onPrevious();
                }
                setPageIndex(currentPage - 1);
            }
            return _onClick2 ? _onClick2(e) : returnValue;
        } }), cancelLabel && currentPage <= 0 ? cancelLabel : children);
});
//# sourceMappingURL=buttons.js.map
