import {ISidebarMenu} from '../interfaces/components/ISidebarMenu';
import {ISidebarMenuItem} from '../interfaces/components/ISidebarMenuItem';

export class SidebarMenu implements ISidebarMenu {

    protected container:HTMLElement;
    
    protected items:ISidebarMenuItem[];

    protected itemCreator:()=>ISidebarMenuItem;

    public setItemCreator(callback:()=>ISidebarMenuItem)
    {
        this.itemCreator = callback;
    }

    public init(container:HTMLElement)
    {
        this.container = container;
        let items = this.container.querySelectorAll('.js-sidebar-menu-item-container');
        this.items = [];
        items.forEach((el:HTMLElement, i:number)=>{
            let menuItem = this.itemCreator();
            menuItem.init(el);
            this.items.push(menuItem);
        });
    }
}