(function (global, factory) {
    if (typeof define === "function" && define.amd) {
        define(['exports', '../actions/types'], factory);
    } else if (typeof exports !== "undefined") {
        factory(exports, require('../actions/types'));
    } else {
        var mod = {
            exports: {}
        };
        factory(mod.exports, global.types);
        global.reducer = mod.exports;
    }
})(this, function (exports, _types) {
    '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 INITIAL_STATE = {
        listening: false,
        currentTarget: null,
        nextTarget: null,
        sayTarget: false,
        repeat: false
    };

    exports.default = function () {
        var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : INITIAL_STATE;
        var _ref = arguments[1];
        var type = _ref.type,
            payload = _ref.payload;

        switch (type) {
            case _types.LISTENING:
                return _extends({}, state, {
                    listening: true,
                    repeat: false,
                    sayTarget: false
                });
            case _types.REQUESTED_TARGET:
                return _extends({}, state, {
                    nextTarget: payload,
                    repeat: false,
                    sayTarget: false
                });
            case _types.NAVIGATION_DONE:
                return _extends({}, state, {
                    currentTarget: payload,
                    nextTarget: null,
                    repeat: false,
                    sayTarget: false
                });
            case _types.SAY_TARGET:
                return _extends({}, state, {
                    sayTarget: true,
                    repeat: false
                });
            case _types.REPEAT_COMMAND:
                return _extends({}, state, {
                    sayTarget: false,
                    repeat: true
                });
            case _types.STOP_LISTENING:
                return _extends({}, state, {
                    listening: false
                });
            default:
                return state;
        }
    };
});