import {IAdminPanel} from '../interfaces/components/IAdminPanel';
import {ISidebar} from '../interfaces/components/ISidebar';
import {IHeader} from '../interfaces/components/IHeader';
import {IContent} from '../interfaces/components/IContent';

export class AdminPanel implements IAdminPanel {

    private container:HTMLElement;

    private fullscreenContainer:HTMLElement;

    private _sidebar:ISidebar;

    private _header:IHeader;

    private _content:IContent;

    private isSidebarClosed = false;

    public setSidebar(sidebar:ISidebar)
    {
        this._sidebar = sidebar;
    }

    public setHeader(header:IHeader)
    {
        this._header = header;
    }

    public setContent(content:IContent)
    {
        this._content = content;
    }

    public init(container:HTMLElement)
    {
        this.container = container;
        this.fullscreenContainer = this.container.querySelector('.js-fullscreen-container');

        let headerElement = document.querySelector('.js-main-header');
        this._header.init(<HTMLElement>headerElement);
        let sidebarElement = document.querySelector('.js-main-sidebar');
        this._sidebar.init(<HTMLElement>sidebarElement);
        let contentElement = document.querySelector('.js-content');
        this._content.init(<HTMLElement>contentElement);
    }

    public get header():IHeader
    {
        return this._header;
    }

    public get sidebar():ISidebar
    {
        return this._sidebar;
    }

    public get content():IContent
    {
        return this._content;
    }

    public toggleSidebar(): boolean
    {
        if(this.isSidebarClosed){
            this.container.classList.remove('closed-sidebar');
            this.container.classList.add('openned-sidebar');
        }else{
            this.container.classList.add('closed-sidebar');
            this.container.classList.remove('openned-sidebar');
        }
        this.isSidebarClosed = !this.isSidebarClosed;
        return this.isSidebarClosed;
    }

    public collapseSidebar()
    {
        this.isSidebarClosed = true;
        this.container.classList.add('closed-sidebar');
        this.container.classList.remove('openned-sidebar');
    }

    public getFullScreenContainer(): HTMLElement
    {
        return this.fullscreenContainer;
    }

}