const objCsv: { size: number; dataFile: any } = {
  size: 0,
  dataFile: [],
};

function readCsv(input: any): Array<any> | void {
  if (input.files && input.files[0]) {
    const reader: FileReader = new FileReader();
    reader.readAsBinaryString(input.files[0]);
    reader.onload = (event) => {
      objCsv.size = event.total;
      objCsv.dataFile = event.target.result;
      return parseData(objCsv.dataFile);
    };
  }
}

function parseData(data: any): Array<any> {
  const csvData: Array<any> = [];
  const lineBreak: Array<any> = data.split('\n');
  lineBreak.forEach((res) => {
    csvData.push(res.split(','));
  });
  console.table(csvData);
  return csvData;
}

export { readCsv };
