
export const domainChagneUtil={
    getSystemInfo:(resultdata:any,domains:any)=>{
        let alldomainmap:any = {}
        domains.forEach((i:any)=>{
            alldomainmap[i.domainId] = i
        })
        let systemmap:any ={}
        let domainmap:any={}
        const data = (resultdata||[]).map((domain:any)=>{
            let tempcatalogs = (domain.catalogs||[]).map((tcatalog:any)=>{
                let tsystems = (tcatalog.scopes||[]).map((_system:any,index:any)=>{
                    const system = {..._system,label:_system.scopeName,title:_system.scopeName,key:`system-${_system.scopeId}`,
                        value:_system.scopeId,catalog:tcatalog.catalogId,domainId:domain.domainId,catalogInfo:tcatalog,
                        prevnode:domain.catalogs[index-1]||null,nextnode:domain.catalogs[index+1]||null,domain:domain
                    }
                    systemmap[_system.scopeId] = system;
                    return system;
                })
                let tempcatalog = {catalogId:tcatalog.catalogId,catalogInfo:tcatalog,catalogName:tcatalog.catalogName,label:tcatalog.catalogName,title:tcatalog.catalogName,key:`catalog-${tcatalog.catalogId}-${domain.domainId}`,value:tcatalog.catalogId,domain:domain.domainId,disabled:true,children:tsystems}
                return tempcatalog
            })
            let domaininfo = alldomainmap[domain.domainId]
            let tempdomain= {...domaininfo,...domain,label:domain.domainName,title:domain.domainName,key:`domain-${domain.domainId}`,value:domain.domainId,children:tempcatalogs}
            domainmap[domain.domainId] = tempdomain
            return tempdomain
        });
        return {domainlist:data,domainmap,systemmap}
    },
    getSystemInfoFromCatalog:(resultdata:any,domainId:any)=>{
        let tempcatalogs = (resultdata||[]).map((tcatalog:any)=>{
            let tsystems = (tcatalog.scopes||[]).map((_system:any,index:any)=>{
                const system = {..._system,label:_system.scopeName,title:_system.scopeName,key:`system-${_system.scopeId}`,
                    value:_system.scopeId,catalog:tcatalog.catalogId,domainId:domainId,
                    prevnode:resultdata[index-1]||null,nextnode:resultdata[index+1]||null
                }
                return system;
            })
            let tempcatalog = {catalogId:tcatalog.catalogId,catalogName:tcatalog.catalogName,label:tcatalog.catalogName,title:tcatalog.catalogName,key:`catalog-${tcatalog.catalogId}-${domainId}`,value:tcatalog.catalogId,domain:domainId,disabled:true,children:tsystems}
            return tempcatalog
        })
        return tempcatalogs
    },
    getSystemInfoFromCatalogForTreeSelect:(resultdata:any,domainId:any)=>{
        let tempcatalogs = (resultdata||[]).map((tcatalog:any)=>{
            let tsystems = (tcatalog.scopes||[]).map((_system:any,index:any)=>{
                const system = {..._system,label:_system.scopeName,title:_system.scopeName,key:`system-${_system.scopeId}`,
                    value:`system-${_system.scopeId}`,catalog:tcatalog.catalogId,domainId:domainId,
                    prevnode:resultdata[index-1]||null,nextnode:resultdata[index+1]||null
                }
                return system;
            })
            let tempcatalog = {catalogId:tcatalog.catalogId,catalogName:tcatalog.catalogName,label:tcatalog.catalogName,title:tcatalog.catalogName,key:`catalog-${tcatalog.catalogId}-${domainId}`,value:`catalog-${tcatalog.catalogId}-${domainId}`,domain:domainId,disabled:true,children:tsystems}
            return tempcatalog
        })
        return tempcatalogs
    }
}