import {IFactory} from '../interfaces/components/IFactory';
import {IFactory as IAppFactory} from '../interfaces/IFactory';
import {ILoginForm} from '../interfaces/components/ILoginForm';
import {LoginForm} from './LoginForm';
import {Helpers} from '@common/admin/Helpers';

export class Factory implements IFactory {

    protected conf:any;

    protected appFactory:IAppFactory;

    protected loginForm:ILoginForm = null;

    public setAppFactory(factory:IAppFactory)
    {
        this.appFactory = factory;
    }

    public init(container:HTMLElement, conf:any = {}): void
    {
        this.conf = {
            'loginForm': null
        };
        Helpers.objectReplaceRecursive(this.conf, conf);

        let loginForm = container.querySelector('.js-login-form-container');
        this.loginForm = this.conf.loginForm || new LoginForm();
        let appCommands = this.appFactory.getCommandsFactory().getAppCommands();
        this.loginForm.setAppCommands(appCommands);
        this.loginForm.init(<HTMLElement>loginForm);
    }

    public getLoginForm()
    {
        return this.loginForm;
    }

}