import {List} from './withStore/List';

export class TreeList extends List {
    constructor(props, context) {
        super(props, context);

        this.state = {
            nodes: this.props.store.getData()
        };
    }

    onStoreChange(data) {
        this.setState({nodes: data});
    }

    hasItems() {
        return this.props.store.getFilteredCount() > 0;
    }

    isEmptyList() {
        return (
            this.props.store.isLoaded() &&
            !this.props.store.hasFilters() &&
            !this.props.store.getTotalCount()
        );
    }

    isEmptyListMessageVisible() {
        return this.props.store.isLoaded() && !this.hasItems();
    }

    renderItems() {
        const result = [];

        this.state.nodes.forEach((node, index) => {
            this.props.store.applyCallbackToSubtree(node, index, (record, recordIndex, level) => {
                result.push(this.renderItem(record, recordIndex, level));
            });
        });

        return result;
    }

    renderItem(record, index, level) {
        return null;
    }
}
