
import DefaultPlugin from './loginDeufaultPlugin'

import {WeaTools} from 'ecCom'

import loadjs from 'loadjs';

export default class LoginPluginFactory {
    getLocalPlugin = (params,callback)=>{
        const {plugin} = params 
        if(plugin){
            if(plugin.code == 'load'){
                if(plugin.type='file'){
                    const jsName = plugin.name 
                    if(loadjs.isDefined(jsName)){
                        loadjs.ready(jsName,()=>{
                            if(console) console.log(window.loginPlugin) 
                            this.donePlugin(callback)
                        })
                    }else{
                        loadjs([plugin.url],jsName,{
                                async: false,
                                success : ()=>{
                                        if(console) console.log(window.loginPlugin) 
                                        this.donePlugin(callback)
                                    }
                                })
                    }
                }
            }else{
                window.loginPlugin = new DefaultPlugin() ; 
            }
        }else{
            window.loginPlugin = new DefaultPlugin() ;
        }
    }
   


    // unused
    getLoginPlugin = (params,callback) =>{
        const {loginid} = params ;
        WeaTools.callApi('/api/hrm/login/checkPlugin','POST',{loginid:loginid}).then((data)=>{
            if(data.code == 'load'){
                if(data.type='file'){
                    const jsName = data.name 
                    if(loadjs.isDefined(jsName)){
                        loadjs.ready(jsName,()=>{
                            if(console) console.log(window.loginPlugin) 
                            this.donePlugin(callback)
                        })
                    }else{
                        loadjs([data.url],jsName,{
                                async: false,
                                success : ()=>{
                                        if(console) console.log(window.loginPlugin) 
                                        this.donePlugin(callback)
                                    }
                                })
                    }
                }
            }else{
                window.loginPlugin = new DefaultPlugin() ; 
            }
        }).catch((err)=>{
            if(console) console.log(err) ;
        });
    }

    donePlugin = (callback)=>{
        callback && callback()
    }
    
}