import * as React from 'react';
import { Subject } from 'rxjs';
import { filter, map, takeUntil } from 'rxjs/operators';
import { datagrid, Handsontable as HandsontableLib } from '../common';
import { factory } from '../SAMPLE';
export class TestGridView extends React.PureComponent {
    constructor() {
        super(...arguments);
        this.state = {};
        this.state$ = new Subject();
        this.unmounted$ = new Subject();
        this.grid$ = this.props.events$ || new Subject();
    }
    componentDidMount() {
        this.state$.pipe(takeUntil(this.unmounted$)).subscribe((e) => this.setState(e));
        const grid$ = this.grid$.pipe(takeUntil(this.unmounted$));
        const keyboard$ = this.props.grid.keyboard$;
        grid$.pipe(filter((e) => !['GRID/keydown'].includes(e.type))).subscribe((e) => {
        });
        grid$
            .pipe(filter((e) => e.type === 'GRID/EDITOR/end'), map((e) => e.payload), filter((e) => !e.isCancelled))
            .subscribe((e) => {
        });
        const beginEdit$ = grid$.pipe(filter((e) => e.type === 'GRID/EDITOR/begin'), map((e) => e.payload));
        beginEdit$.pipe(filter((e) => e.cell.key === 'B1')).subscribe((e) => {
            e.cancel();
        });
        const change$ = grid$.pipe(filter((e) => e.type === 'GRID/cells/change'), map((e) => e.payload));
        const selection$ = grid$.pipe(filter((e) => e.type === 'GRID/selection'), map((e) => e.payload));
        change$.subscribe((e) => {
        });
        change$.pipe().subscribe((e) => {
            const B2 = e.changes.find((change) => change.cell.key === 'B2');
            if (B2) {
                B2.cancel();
            }
        });
    }
    componentWillUnmount() {
        this.unmounted$.next();
    }
    get Table() {
        const { Table = HandsontableLib } = this.props;
        return Table;
    }
    render() {
        return (React.createElement(datagrid.DataGrid, { grid: this.props.grid, factory: factory, Handsontable: this.Table, "events$": this.grid$, initial: { selection: 'A1' }, style: this.props.style, canSelectAll: false }));
    }
}
