import flights from '../data/HoPe_all_flights.json';
import {CFlight} from '../classes/CFlight';
import {CSeason} from '../classes/CSeason';
import {groupByMap} from '../global/tools';
import getFlights from '../data/GetAllFlights.json';

const data_raw = flights.data;
export const g_data: CFlight[] = [];
export const g_seasondata: CSeason[] = [];


// function GetFlightsFromXcServer(FKpilot: number)
// {
//   var url_raw: string = getFlights[0].url;
//   const pattern: string = getFlights[0].pattern;
//   const regex = /XXXXXXXX/gi;
//   const url = url_raw.replace(regex, FKpilot.toString());

//   var fldata: any;
//   fetch(url)
//   .then(function(response) 
//   {
//     return response.json();
//   }
//   ).then(function(myJson) 
//   {
//     fldata=myJson;
//     console.log(fldata);
//   });
  
//   return fldata;
// }

// const data_raw = GetFlightsFromXcServer(1295).data;

for (let fl of data_raw) 
{
  g_data.push(new CFlight(fl));
}

const seasondata_raw = groupByMap(g_data, i => i.FKSeason);

for (let [key, value] of seasondata_raw) 
{
  g_seasondata.push(new CSeason(key, value));
}
