import { IListable } from '../interfaces/listable-interface';

export abstract class DefaultListable<T> implements IListable<T> {

    private isSearch: boolean;
    private _elements: Array<T>;

    constructor(
    ) {
        this.isSearch = false;
        this.elements = [];
    }

    /**
     *
     */
    set elements(_elements: Array<T>) {
        this._elements = _elements; 
    }

    /**
     *
     */
    get elements() {
        return this._elements;
    }

    

    /**
     *
     */
    add(T: any): void {
        this._elements.push(T);
    }

    /**
     *
     */
    remove(T: any): void {
        let index = this.elements.indexOf(T);
        this._elements.slice(index, 1);
    }

    /**
     *
     */
    get(T: any): T {
        let index = this.elements.indexOf(T);
        return this._elements[index];
    }

    /**
     *
     */
    list(): Array<T> {
        return this._elements;
    }

    /**
     *
     */
    search(by: string): Array<T> {
        return null;
    }

    /**
     *
     */
    toggleSearch(): void {
        this.isSearch = !this.isSearch;
    }

    /**
     *
     */
    isSearching(): boolean {
        return this.isSearch;
    }
}
