var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
    if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
    return cooked;
};
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    }
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
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);
};
import React from 'react';
import styled from 'react-emotion';
import { Droppable } from 'react-beautiful-dnd';
import Operation from './Operation';
var Container = styled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n  overflow-x: hidden;\n  overflow-y: auto;\n  flex: 1;\n  padding: 10px;\n"], ["\n  overflow-x: hidden;\n  overflow-y: auto;\n  flex: 1;\n  padding: 10px;\n"])));
var OperationsList = /** @class */ (function (_super) {
    __extends(OperationsList, _super);
    function OperationsList() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.state = {
            openOperations: [],
        };
        return _this;
    }
    OperationsList.prototype.componentDidUpdate = function (prevProps, prevState) {
        var openOperations = this.state.openOperations;
        var operations = this.props.operations;
        var prevOperations = prevProps.operations;
        if (operations && prevOperations) {
            var newOperation_1 = operations.find(function (o) { return !prevOperations.find(function (p) { return p.id === o.id; }); });
            if (newOperation_1) {
                this.setState(function (state) { return (__assign({}, state, { openOperations: state.openOperations.concat([newOperation_1.id]) })); });
            }
        }
        var lastOperation = operations[operations.length - 1] || {};
        if (openOperations.includes(lastOperation.id) &&
            !prevState.openOperations.includes(lastOperation.id)) {
            if (this.container) {
                this.container.scrollTop = 100000000;
            }
        }
    };
    OperationsList.prototype.onOperationOpen = function (operation, isOpen, cb) {
        var openOperations = this.state.openOperations;
        if (isOpen) {
            this.setState(function (state) { return (__assign({}, state, { openOperations: state.openOperations.concat([operation.id]) })); }, cb);
        }
        else {
            this.setState(function (state) { return (__assign({}, state, { openOperations: state.openOperations.filter(function (id) { return id !== operation.id; }) })); }, cb);
        }
    };
    OperationsList.prototype.render = function () {
        var _this = this;
        var _a = this.props, operations = _a.operations, onParameterChange = _a.onParameterChange, onParameterFocus = _a.onParameterFocus, onParameterBlur = _a.onParameterBlur, onRemoveOperation = _a.onRemoveOperation, advancedMode = _a.advancedMode;
        var openOperations = this.state.openOperations;
        return (React.createElement(Droppable, { droppableId: "operations", ref: this.wrapRef }, function (provided) { return (React.createElement(Container, __assign({ innerRef: function (el) {
                _this.container = el;
                provided.innerRef(el);
            } }, provided.droppableProps),
            operations.map(function (operation, i) { return (React.createElement(Operation, { key: operation.id, index: i, operation: operation, advancedMode: advancedMode, isOpen: openOperations.includes(operation.id), onOpen: function (isOpen, cb) {
                    return _this.onOperationOpen(operation, isOpen, cb);
                }, onParameterChange: function (parameter, value) {
                    return onParameterChange(operation, parameter, value);
                }, onParameterFocus: function (parameter) {
                    return onParameterFocus(operation, parameter);
                }, onParameterBlur: function (parameter) {
                    return onParameterBlur(operation, parameter);
                }, onRemove: function () { return onRemoveOperation(operation); } })); }),
            provided.placeholder)); }));
    };
    return OperationsList;
}(React.Component));
export default OperationsList;
var templateObject_1;
//# sourceMappingURL=OperationsList.js.map