import React from 'react';
import Modularity from 'modularity-front';

import API from './API';

class LoadedModules extends Modularity.Module{
	constructor(props){
		super(props);
		this.API = new API();
		this.Modules.set([{
            link:"home",
            text:"Home",
            icon:"fa-home",
        }]);
		this.API.get('/' + this.APIURL.value).then((data) => {
			let modules = data.map((item) => {
				return {
					link: item.Route,
					text: item.Name,
					icon: item.Icon
				}
			});
			this.Modules.set(modules);
		}).catch(() => console.log("NO SERVER"));
	}

	render(){
		return <div>
			{this.__renderID()}
			{this.__factoryOutput(this.Modules)}
		</div>;
	}
}
LoadedModules.Outputs = {
	Modules: {}
}

LoadedModules.Inputs = {
	APIURL: {
		type: Modularity.Module.Types.Text,
		defaultValue: 'CrudModules'
	}
}

LoadedModules.Category = "Services"


export default LoadedModules;