import * as React from 'react';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { TestGrid } from './Test.Grid';
const KEY = {
    EDITOR: 'ui.datagrid/editor',
};
function fromStorage(key, defaultValue) {
    const value = localStorage.getItem(key);
    return (value === undefined ? defaultValue : value);
}
export class Test extends React.PureComponent {
    constructor() {
        super(...arguments);
        this.state = {};
        this.unmounted$ = new Subject();
        this.state$ = new Subject();
    }
    componentDidMount() {
        const state$ = this.state$.pipe(takeUntil(this.unmounted$));
        state$.subscribe((e) => this.setState(e));
        const editor = fromStorage(KEY.EDITOR, this.editorType);
        this.state$.next({ editor });
        state$.subscribe(() => {
            localStorage.setItem(KEY.EDITOR, this.editorType);
        });
    }
    componentWillUnmount() {
        this.unmounted$.next();
        this.unmounted$.complete();
    }
    get editorType() {
        return this.state.editor || 'debug';
    }
    render() {
        return React.createElement(TestGrid, { editorType: this.editorType, left: true });
    }
}
