import React, { Component } from 'react';
var DBEvents=require('react-native-db-models').DBEvents;
import {db} from './persistences/db';
import I18n from 'react-native-i18n'
import {isDebugMode,adhesionUrl,locationActionUrl,memberActionUrl,networkActionUrl,demandeActionUrl} from "./IlinkConstants"


async function queryData(data,url){
    data['lang']=I18n.currentLocale()
    data["test"]=isDebugMode
    let response= await fetch(url,{
        method: 'POST',
        headers: {
            Accept: 'application/json',
            'Content-Type': 'application/json',
        },
        body: JSON.stringify(data),
    }).then((response)=>response);
    let responseJson=null;
    try {

        responseJson = await response.json();
        console.debug(responseJson)
    }catch(e){
        console.log(response)
        console.log(e)
        return {"error":"error"}
    }
    return responseJson;

}
export const listFreeCodesSuperViseur=(codeparrain)=>{
    return queryData({"tag":"supervisor","type":"listFreeNetwork","code_parrain":codeparrain},networkActionUrl)
}
export const getAgentNetworksList=(id)=>{
        return queryData({"tag":"geolocated","type":"listNetwork","id":id},networkActionUrl)
}