class ImpactLink {

    constructor( url, linkProvider , proxy = `/wp-json/api/v1/proxy/` ) {

        this.url = url;
        this.linkProvider = linkProvider;

        this.proxy = proxy;
        this.platform = 'Impact';

    }

    async isLink() {

        let apiCall = this.linkProvider + 'get_impact_domains/';
        let impactDomains = await this.getData(apiCall)

        impactDomains.sort((a, b) => {
            return (a.length > b.length) ? -1 : 1;
        });

        let programDomain = impactDomains.filter(impactDomain => this.url.includes(impactDomain));

        if(programDomain.length > 0){
            return true  
        } 
        
        return false
    }


    isValid() {
        return false;
    }


    addTag( placeholder ) {
        
        let url = this.url.replace(/&amp;/g, '&');
        
        return url;
    }


    /**
     * effettua la chiamata e prende i dati del link     
     */
    async getData( api_call ) {

        let response = await fetch( `${this.proxy}${api_call}` )
        this.data = await response.json();
        
        return this.data;
    }
    

}