"use strict";
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
var typescript_fsa_1 = require("typescript-fsa");
var dist_1 = require("typescript-fsa-reducers/dist");
var redux_observable_1 = require("redux-observable");
var operators_1 = require("rxjs/operators");
var typescript_fsa_redux_observable_1 = require("./typescript-fsa-redux-observable");
var actionCreator = typescript_fsa_1.default('react-map-editor/input');
exports.actions = {
    mouseEnter: actionCreator('MOUSE_ENTER'),
    mouseLeave: actionCreator('MOUSE_LEAVE'),
    mouseDown: actionCreator('MOUSE_DOWN'),
    mouseMove: actionCreator('MOUSE_MOVE'),
    mouseUp: actionCreator('MOUSE_UP'),
    drag: actionCreator('DRAG')
};
var initialState = {
    isPressed: false,
    latestDragId: 0
};
exports.default = dist_1.reducerWithInitialState(initialState)
    .case(exports.actions.mouseDown, function (state) { return (__assign({}, state, { isPressed: true })); })
    .case(exports.actions.mouseUp, function (state) { return (__assign({}, state, { latestDragId: state.latestDragId + 1, isPressed: false })); })
    .case(exports.actions.mouseLeave, function (state) { return (__assign({}, state, { latestDragId: state.latestDragId + 1, isPressed: false })); });
var mouseDownEpic = function (action$, state$) {
    return action$.pipe(typescript_fsa_redux_observable_1.ofAction(exports.actions.mouseDown), operators_1.map(function (action) {
        return exports.actions.drag({
            event: action.payload,
            id: state$.value.input.latestDragId
        });
    }));
};
var mouseMoveEpic = function (action$, state$) {
    return action$.pipe(typescript_fsa_redux_observable_1.ofAction(exports.actions.mouseMove), operators_1.filter(function () { return state$.value.input.isPressed; }), operators_1.map(function (action) {
        return exports.actions.drag({
            event: action.payload,
            id: state$.value.input.latestDragId
        });
    }));
};
exports.epics = redux_observable_1.combineEpics(mouseDownEpic, mouseMoveEpic);
//# sourceMappingURL=input.js.map