import Loader from "./Loader.js";

export class DynamicCSSInclude {

    constructor( files ) {
        
        /// files to include
        this.files = files;

        this.loader = new Loader( this.loaded , this.error );
            
        /// components
        this.includes = this.load();
        
    }

    error( payload ){
        console.error( payload );
    }

    loaded( payload ) {

        document.head.insertAdjacentHTML("beforeend", `<style>${ payload }</style>`);     

        /*let element = document.createElement( 'style' );

        //element.rel = 'stylesheet';
        //element.href = url;
        element.textContent = payload;

        document.head.appendChild( element );*/
    }


    load() { 

        this.files.forEach( file => this.loader.load( file ) );
    } 

}



