"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TestGridView = void 0;
var tslib_1 = require("tslib");
var React = require("react");
var rxjs_1 = require("rxjs");
var operators_1 = require("rxjs/operators");
var common_1 = require("../common");
var SAMPLE_1 = require("../SAMPLE");
var TestGridView = (function (_super) {
    tslib_1.__extends(TestGridView, _super);
    function TestGridView() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.state = {};
        _this.state$ = new rxjs_1.Subject();
        _this.unmounted$ = new rxjs_1.Subject();
        _this.grid$ = _this.props.events$ || new rxjs_1.Subject();
        return _this;
    }
    TestGridView.prototype.componentDidMount = function () {
        var _this = this;
        this.state$.pipe(operators_1.takeUntil(this.unmounted$)).subscribe(function (e) { return _this.setState(e); });
        var grid$ = this.grid$.pipe(operators_1.takeUntil(this.unmounted$));
        var keyboard$ = this.props.grid.keyboard$;
        grid$.pipe(operators_1.filter(function (e) { return !['GRID/keydown'].includes(e.type); })).subscribe(function (e) {
        });
        grid$
            .pipe(operators_1.filter(function (e) { return e.type === 'GRID/EDITOR/end'; }), operators_1.map(function (e) { return e.payload; }), operators_1.filter(function (e) { return !e.isCancelled; }))
            .subscribe(function (e) {
        });
        var beginEdit$ = grid$.pipe(operators_1.filter(function (e) { return e.type === 'GRID/EDITOR/begin'; }), operators_1.map(function (e) { return e.payload; }));
        beginEdit$.pipe(operators_1.filter(function (e) { return e.cell.key === 'B1'; })).subscribe(function (e) {
            e.cancel();
        });
        var change$ = grid$.pipe(operators_1.filter(function (e) { return e.type === 'GRID/cells/change'; }), operators_1.map(function (e) { return e.payload; }));
        var selection$ = grid$.pipe(operators_1.filter(function (e) { return e.type === 'GRID/selection'; }), operators_1.map(function (e) { return e.payload; }));
        change$.subscribe(function (e) {
        });
        change$.pipe().subscribe(function (e) {
            var B2 = e.changes.find(function (change) { return change.cell.key === 'B2'; });
            if (B2) {
                B2.cancel();
            }
        });
    };
    TestGridView.prototype.componentWillUnmount = function () {
        this.unmounted$.next();
    };
    Object.defineProperty(TestGridView.prototype, "Table", {
        get: function () {
            var _a = this.props.Table, Table = _a === void 0 ? common_1.Handsontable : _a;
            return Table;
        },
        enumerable: false,
        configurable: true
    });
    TestGridView.prototype.render = function () {
        return (React.createElement(common_1.datagrid.DataGrid, { grid: this.props.grid, factory: SAMPLE_1.factory, Handsontable: this.Table, "events$": this.grid$, initial: { selection: 'A1' }, style: this.props.style, canSelectAll: false }));
    };
    return TestGridView;
}(React.PureComponent));
exports.TestGridView = TestGridView;
