/* eslint-disable prettier/prettier */
/* eslint-disable react/no-did-mount-set-state */
/* eslint-disable prettier/prettier */
import React from 'react';
import {
  //ImageBackground,
  Text,
  View,
  StatusBar,
  TouchableHighlight,
  Button,
  Image,
  Alert,
} from 'react-native';
import Orientation from 'react-native-orientation';
import * as RNFS from 'react-native-fs';
var path = RNFS.DocumentDirectoryPath + '/settings.txt';
var path1 = RNFS.DocumentDirectoryPath + '/counter.txt';
import Notes from './data';
import styles from '../style/style';
import moment from 'moment';
var date = moment().utcOffset('+08:00').format('D MMM YYYY');
var time = moment().utcOffset('+08:00').format('h:mm a');
var record = RNFS.DocumentDirectoryPath + '/test.txt';

const NOTESWHITE = [
  'C1',
  'D1',
  'E1',
  'F1',
  'G1',
  'A1',
  'B1',
  'C2',
  'D2',
  'E2',
  'F2',
  'G2',
  'A2',
  'B2',
];
const NOTESCC = ['C#1'];
const NOTESDD = ['D#1'];
const NOTESFF = ['F#1'];
const NOTESGG = ['G#1'];
const NOTESAA = ['A#1'];
const NOTESCC1 = ['C#2'];
const NOTESDD1 = ['D#2'];
const NOTESFF1 = ['F#2'];
const NOTESGG1 = ['G#2'];
const NOTESAA1 = ['A#2'];
const keywordsList = [];
var maxCount = 0;
var imageN = '';
var indexN = 0;


class Quiz extends React.Component {
    constructor(props) {
    super(props);
    this.state = {
      logbook: [],
      index:0,
      timer: 0,
      correct: 0,
      wrong: 0,
      keywordsList: '',
      count: 1,
      name : '',
    };
  }

    toggleKeyword = (keyword) => {
    let list = keywordsList;
    let index = -1;
    if ((index = keywordsList.indexOf(keyword)) !== -1) {
      list.splice(index, 1);
      console.log(list);
    } else {
      list.push(keyword);
      console.log(list);
    }
    this.setState({keywordsList: list});
  };

  //reset
  removeArray = () => {
    keywordsList.splice(0, keywordsList.length);
    console.log(keywordsList);
   /* this.setState({
      timer: 0,
    });
    clearInterval(this._interval); */
    Orientation.lockToLandscape();
  };

  onSubmit = () => {
    if (this.state.name.includes('C Major') || this.state.name.includes('Bass Clef C Major')) {
      this.ansCMajor();
    }
    else if (this.state.name.includes('D Major') || this.state.name.includes('Bass Clef D Major')) {
      this.ansDMajor();
    }
    else if (this.state.name.includes('E Major') || this.state.name.includes('Bass Clef E Major')) {
      this.ansEMajor();
    }
    else if (this.state.name.includes('F Sharp Major') || this.state.name.includes('Bass Clef F Sharp Major')) {
      this.ansFsMajor();
    }
    else if (this.state.name.includes('F Major') || this.state.name.includes('Bass Clef F Major')) {
      this.ansFMajor();
    }
    else if (this.state.name.includes('D Flat Major') || this.state.name.includes('Bass Clef D Flat Major')) {
      this.ansDbMajor();
    }
    else if (this.state.name.includes('E Flat Major') || this.state.name.includes('Bass Clef E Flat Major')) {
      this.ansEbMajor();
    }
    else if (this.state.name.includes('G Major') || this.state.name.includes('Bass Clef G Major')) {
      this.ansGMajor();
    }
    else if (this.state.name.includes('A Major') || this.state.name.includes('Bass Clef A Major')) {
      this.ansAMajor();
    }
    else if (this.state.name.includes('B Major') || this.state.name.includes('Bass Clef B Major')) {
      this.ansBMajor();
    }
    else if (this.state.name.includes('C Sharp Major') || this.state.name.includes('Bass Clef C  Sharp Major')) {
      this.ansCsMajor();
    }
    else if (this.state.name.includes('B Flat Major') || this.state.name.includes('Bass Clef B Flat Major')) {
      this.ansBbMajor();
    }
    else if (this.state.name.includes('A Flat Major') || this.state.name.includes('Bass Clef A Flat Major')) {
      this.ansAbMajor();
    }
    else if (this.state.name.includes('G Flat Major') || this.state.name.includes('Bass Clef G Flat Major')) {
      this.ansGbMajor();
    }
    else {
      console.log('error');
      console.log(this.state.name);
    }
  };

  ansCMajor = ()=> {
    console.log(maxCount);
    console.log(this.state.count);
    if (keywordsList.toString() === 'C1,D1,E1,F1,G1,A1,B1,C2'){
      if ( (this.state.count + 1) > maxCount) {
          this.props.navigation.navigate('1');
          Orientation.lockToPortrait();
          Alert.alert(
          'Well Done',
          'Correct: ' +
          (this.state.correct + 2) +
          '\nWrong: ' +
          this.state.wrong +
          '\n',
          );
        this.saveRecord((this.state.correct + 2), this.state.wrong, this.state.timer);
        console.log('finish');}
      else {
      Alert.alert('Correct!');
      keywordsList.splice(0, keywordsList.length);
      this.props.navigation.push('2', {
        c: this.state.correct + 2,
        w: this.state.wrong,
        t: this.state.timer,
        cc : this.state.count + 1,
      });
    }
    } else {
      if ( (this.state.count + 1) > maxCount) {
          this.props.navigation.navigate('1');
          Orientation.lockToPortrait();
          Alert.alert(
          'Well Done',
          'Correct: ' +
          this.state.correct +
          '\nWrong: ' +
          (this.state.wrong + 1) +
          '\n',
          );
        this.saveRecord(this.state.correct, (this.state.wrong + 1), this.state.timer);
        console.log('finish');}
      else {
      Alert.alert('Wrong!');
      keywordsList.splice(0, keywordsList.length);
      this.props.navigation.push('2', {
        c: this.state.correct,
        w: this.state.wrong + 1,
        t: this.state.timer,
        cc : this.state.count + 1,
      });
    }
    }
  };

   ansDMajor = () => {
     console.log(maxCount);
    console.log(this.state.count);
     if (keywordsList.toString() === 'D1,E1,F#1,G1,A1,B1,C#2,D2') {
      if ( (this.state.count + 1) > maxCount) {
          this.props.navigation.navigate('1');
          Orientation.lockToPortrait();
          Alert.alert(
          'Well Done',
          'Correct: ' +
          (this.state.correct + 2) +
          '\nWrong: ' +
          this.state.wrong +
          '\n',
          );
        this.saveRecord((this.state.correct + 2), this.state.wrong, this.state.timer);
        console.log('finish');}
      else {
      Alert.alert('Correct!');
      keywordsList.splice(0, keywordsList.length);
      this.props.navigation.push('2', {
        c: this.state.correct + 2,
        w: this.state.wrong,
        t: this.state.timer,
        cc : this.state.count + 1,
      });
    }
    } else {
      if ( (this.state.count + 1) > maxCount) {
          this.props.navigation.navigate('1');
          Orientation.lockToPortrait();
          Alert.alert(
          'Well Done',
          'Correct: ' +
          this.state.correct +
          '\nWrong: ' +
          (this.state.wrong + 1) +
          '\n',
          );
        this.saveRecord(this.state.correct, (this.state.wrong + 1), this.state.timer);
        console.log('finish');}
      else {
      Alert.alert('Wrong!');
      keywordsList.splice(0, keywordsList.length);
      this.props.navigation.push('2', {
        c: this.state.correct,
        w: this.state.wrong + 1,
        t: this.state.timer,
        cc : this.state.count + 1,
      });
    }
    }
  };

  ansEMajor = () => {
    console.log(maxCount);
    console.log(this.state.count);
    if (keywordsList.toString() === 'E1,F#1,G#1,A1,B1,C#2,D#2,E2') {
      if ( (this.state.count + 1) > maxCount) {
          this.props.navigation.navigate('1');
          Orientation.lockToPortrait();
          Alert.alert(
          'Well Done',
          'Correct: ' +
          (this.state.correct + 2) +
          '\nWrong: ' +
          this.state.wrong +
          '\n',
          );
        this.saveRecord((this.state.correct + 2), this.state.wrong, this.state.timer);
        console.log('finish');}
      else {
      Alert.alert('Correct!');
      keywordsList.splice(0, keywordsList.length);
      this.props.navigation.push('2', {
        c: this.state.correct + 2,
        w: this.state.wrong,
        t: this.state.timer,
        cc : this.state.count + 1,
      });
    }
    } else {
      if ( (this.state.count + 1) > maxCount) {
          this.props.navigation.navigate('1');
          Orientation.lockToPortrait();
          Alert.alert(
          'Well Done',
          'Correct: ' +
          this.state.correct +
          '\nWrong: ' +
          (this.state.wrong + 1) +
          '\n',
          );
        this.saveRecord(this.state.correct, (this.state.wrong + 1), this.state.timer);
        console.log('finish');}
      else {
      Alert.alert('Wrong!');
      keywordsList.splice(0, keywordsList.length);
      this.props.navigation.push('2', {
        c: this.state.correct,
        w: this.state.wrong + 1,
        t: this.state.timer,
        cc : this.state.count + 1,
      });
    }
    }
  };

  ansFsMajor = () => {
    console.log(maxCount);
    console.log(this.state.count);
      if (keywordsList.toString() === 'F#1,G#1,A#1,B1,C#2,D#2,F2,F#2') {
      if ( (this.state.count + 1) > maxCount) {
          this.props.navigation.navigate('1');
          Orientation.lockToPortrait();
          Alert.alert(
          'Well Done',
          'Correct: ' +
          (this.state.correct + 2) +
          '\nWrong: ' +
          this.state.wrong +
          '\n',
          );
        this.saveRecord((this.state.correct + 2), this.state.wrong, this.state.timer);
        console.log('finish');}
      else {
      Alert.alert('Correct!');
      keywordsList.splice(0, keywordsList.length);
      this.props.navigation.push('2', {
        c: this.state.correct + 2,
        w: this.state.wrong,
        t: this.state.timer,
        cc : this.state.count + 1,
      });
    }
    } else {
      if ( (this.state.count + 1) > maxCount) {
          this.props.navigation.navigate('1');
          Orientation.lockToPortrait();
          Alert.alert(
          'Well Done',
          'Correct: ' +
          this.state.correct +
          '\nWrong: ' +
          (this.state.wrong + 1) +
          '\n',
          );
        this.saveRecord(this.state.correct, (this.state.wrong + 1), this.state.timer);
        console.log('finish');}
      else {
      Alert.alert('Wrong!');
      keywordsList.splice(0, keywordsList.length);
      this.props.navigation.push('2', {
        c: this.state.correct,
        w: this.state.wrong + 1,
        t: this.state.timer,
        cc : this.state.count + 1,
      });
    }
    }
  };

  ansFMajor = () => {
    console.log(maxCount);
    console.log(this.state.count);
       if (keywordsList.toString() === 'F1,G1,A1,A#1,C2,D2,E2,F2') {
      if ( (this.state.count + 1) > maxCount) {
          this.props.navigation.navigate('1');
          Orientation.lockToPortrait();
          Alert.alert(
          'Well Done',
          'Correct: ' +
          (this.state.correct + 2) +
          '\nWrong: ' +
          this.state.wrong +
          '\n',
          );
        this.saveRecord((this.state.correct + 2), this.state.wrong, this.state.timer);
        console.log('finish');}
      else {
      Alert.alert('Correct!');
      keywordsList.splice(0, keywordsList.length);
      this.props.navigation.push('2', {
        c: this.state.correct + 2,
        w: this.state.wrong,
        t: this.state.timer,
        cc : this.state.count + 1,
      });
    }
    } else {
      if ( (this.state.count + 1) > maxCount) {
          this.props.navigation.navigate('1');
          Orientation.lockToPortrait();
          Alert.alert(
          'Well Done',
          'Correct: ' +
          this.state.correct +
          '\nWrong: ' +
          (this.state.wrong + 1) +
          '\n',
          );
        this.saveRecord(this.state.correct, (this.state.wrong + 1), this.state.timer);
        console.log('finish');}
      else {
      Alert.alert('Wrong!');
      keywordsList.splice(0, keywordsList.length);
      this.props.navigation.push('2', {
        c: this.state.correct,
        w: this.state.wrong + 1,
        t: this.state.timer,
        cc : this.state.count + 1,
      });
    }
    }
  };

  ansEbMajor = () => {
    console.log(maxCount);
    console.log(this.state.count);
     if (keywordsList.toString() === 'D#1,F1,G1,G#1,A#1,C2,D2,D#2') {
      if ( (this.state.count + 1) > maxCount) {
          this.props.navigation.navigate('1');
          Orientation.lockToPortrait();
          Alert.alert(
          'Well Done',
          'Correct: ' +
          (this.state.correct + 2) +
          '\nWrong: ' +
          this.state.wrong +
          '\n',
          );
        this.saveRecord((this.state.correct + 2), this.state.wrong, this.state.timer);
        console.log('finish');}
      else {
      Alert.alert('Correct!');
      keywordsList.splice(0, keywordsList.length);
      this.props.navigation.push('2', {
        c: this.state.correct + 2,
        w: this.state.wrong,
        t: this.state.timer,
        cc : this.state.count + 1,
      });
    }
    } else {
      if ( (this.state.count + 1) > maxCount) {
          this.props.navigation.navigate('1');
          Orientation.lockToPortrait();
          Alert.alert(
          'Well Done',
          'Correct: ' +
          this.state.correct +
          '\nWrong: ' +
          (this.state.wrong + 1) +
          '\n',
          );
        this.saveRecord(this.state.correct, (this.state.wrong + 1), this.state.timer);
        console.log('finish');}
      else {
      Alert.alert('Wrong!');
      keywordsList.splice(0, keywordsList.length);
      this.props.navigation.push('2', {
        c: this.state.correct,
        w: this.state.wrong + 1,
        t: this.state.timer,
        cc : this.state.count + 1,
      });
    }
    }
  };

  ansDbMajor = () => {
    console.log(maxCount);
    console.log(this.state.count);
      if (keywordsList.toString() === 'C#1,D#1,F1,F#1,G#1,A#1,C2,C#2') {
      if ( (this.state.count + 1) > maxCount) {
          this.props.navigation.navigate('1');
          Orientation.lockToPortrait();
          Alert.alert(
          'Well Done',
          'Correct: ' +
          (this.state.correct + 2) +
          '\nWrong: ' +
          this.state.wrong +
          '\n',
          );
        this.saveRecord((this.state.correct + 2), this.state.wrong, this.state.timer);
        console.log('finish');}
      else {
      Alert.alert('Correct!');
      keywordsList.splice(0, keywordsList.length);
      this.props.navigation.push('2', {
        c: this.state.correct + 2,
        w: this.state.wrong,
        t: this.state.timer,
        cc : this.state.count + 1,
      });
    }
    } else {
      if ( (this.state.count + 1) > maxCount) {
          this.props.navigation.navigate('1');
          Orientation.lockToPortrait();
          Alert.alert(
          'Well Done',
          'Correct: ' +
          this.state.correct +
          '\nWrong: ' +
          (this.state.wrong + 1) +
          '\n',
          );
        this.saveRecord(this.state.correct, (this.state.wrong + 1), this.state.timer);
        console.log('finish');}
      else {
      Alert.alert('Wrong!');
      keywordsList.splice(0, keywordsList.length);
      this.props.navigation.push('2', {
        c: this.state.correct,
        w: this.state.wrong + 1,
        t: this.state.timer,
        cc : this.state.count + 1,
      });
    }
    }
  };

  ansGMajor = () => {
    console.log(maxCount);
    console.log(this.state.count);
      if (keywordsList.toString() === 'G1,A1,B1,C2,D2,E2,F#2,G2') {
      if ( (this.state.count + 1) > maxCount) {
          this.props.navigation.navigate('1');
          Orientation.lockToPortrait();
          Alert.alert(
          'Well Done',
          'Correct: ' +
          (this.state.correct + 2) +
          '\nWrong: ' +
          this.state.wrong +
          '\n',
          );
        this.saveRecord((this.state.correct + 2), this.state.wrong, this.state.timer);
        console.log('finish');}
      else {
      Alert.alert('Correct!');
      keywordsList.splice(0, keywordsList.length);
      this.props.navigation.push('2', {
        c: this.state.correct + 2,
        w: this.state.wrong,
        t: this.state.timer,
        cc : this.state.count + 1,
      });
    }
    } else {
      if ( (this.state.count + 1) > maxCount) {
          this.props.navigation.navigate('1');
          Orientation.lockToPortrait();
          Alert.alert(
          'Well Done',
          'Correct: ' +
          this.state.correct +
          '\nWrong: ' +
          (this.state.wrong + 1) +
          '\n',
          );
        this.saveRecord(this.state.correct, (this.state.wrong + 1), this.state.timer);
        console.log('finish');}
      else {
      Alert.alert('Wrong!');
      keywordsList.splice(0, keywordsList.length);
      this.props.navigation.push('2', {
        c: this.state.correct,
        w: this.state.wrong + 1,
        t: this.state.timer,
        cc : this.state.count + 1,
      });
    }
    }
  };

  ansAMajor = () => {
    console.log(maxCount);
    console.log(this.state.count);
     if (keywordsList.toString() === 'A1,B1,C#2,D2,E2,F#2,G#2,A2') {
      if ( (this.state.count + 1) > maxCount) {
          this.props.navigation.navigate('1');
          Orientation.lockToPortrait();
          Alert.alert(
          'Well Done',
          'Correct: ' +
          (this.state.correct + 2) +
          '\nWrong: ' +
          this.state.wrong +
          '\n',
          );
        this.saveRecord((this.state.correct + 2), this.state.wrong, this.state.timer);
        console.log('finish');}
      else {
      Alert.alert('Correct!');
      keywordsList.splice(0, keywordsList.length);
      this.props.navigation.push('2', {
        c: this.state.correct + 2,
        w: this.state.wrong,
        t: this.state.timer,
        cc : this.state.count + 1,
      });
    }
    } else {
      if ( (this.state.count + 1) > maxCount) {
          this.props.navigation.navigate('1');
          Orientation.lockToPortrait();
          Alert.alert(
          'Well Done',
          'Correct: ' +
          this.state.correct +
          '\nWrong: ' +
          (this.state.wrong + 1) +
          '\n',
          );
        this.saveRecord(this.state.correct, (this.state.wrong + 1), this.state.timer);
        console.log('finish');}
      else {
      Alert.alert('Wrong!');
      keywordsList.splice(0, keywordsList.length);
      this.props.navigation.push('2', {
        c: this.state.correct,
        w: this.state.wrong + 1,
        t: this.state.timer,
        cc : this.state.count + 1,
      });
    }
    }
  };

  ansBMajor = () => {
    console.log(maxCount);
    console.log(this.state.count);
       if (keywordsList.toString() === 'B1,C#2,D#2,E2,F#2,G#2,A#2,B2') {
      if ( (this.state.count + 1) > maxCount) {
          this.props.navigation.navigate('1');
          Orientation.lockToPortrait();
          Alert.alert(
          'Well Done',
          'Correct: ' +
          (this.state.correct + 2) +
          '\nWrong: ' +
          this.state.wrong +
          '\n',
          );
        this.saveRecord((this.state.correct + 2), this.state.wrong, this.state.timer);
        console.log('finish');}
      else {
      Alert.alert('Correct!');
      keywordsList.splice(0, keywordsList.length);
      this.props.navigation.push('2', {
        c: this.state.correct + 2,
        w: this.state.wrong,
        t: this.state.timer,
        cc : this.state.count + 1,
      });
    }
    } else {
      if ( (this.state.count + 1) > maxCount) {
          this.props.navigation.navigate('1');
          Orientation.lockToPortrait();
          Alert.alert(
          'Well Done',
          'Correct: ' +
          this.state.correct +
          '\nWrong: ' +
          (this.state.wrong + 1) +
          '\n',
          );
        this.saveRecord(this.state.correct, (this.state.wrong + 1), this.state.timer);
        console.log('finish');}
      else {
      Alert.alert('Wrong!');
      keywordsList.splice(0, keywordsList.length);
      this.props.navigation.push('2', {
        c: this.state.correct,
        w: this.state.wrong + 1,
        t: this.state.timer,
        cc : this.state.count + 1,
      });
    }
    }
  };

  ansCsMajor = () => {
    console.log(maxCount);
    console.log(this.state.count);
       if (keywordsList.toString() === 'C#1,D#1,F1,F#1,G#1,A#1,C2,C#2') {
      if ( (this.state.count + 1) > maxCount) {
          this.props.navigation.navigate('1');
          Orientation.lockToPortrait();
          Alert.alert(
          'Well Done',
          'Correct: ' +
          (this.state.correct + 2) +
          '\nWrong: ' +
          this.state.wrong +
          '\n',
          );
        this.saveRecord((this.state.correct + 2), this.state.wrong, this.state.timer);
        console.log('finish');}
      else {
      Alert.alert('Correct!');
      keywordsList.splice(0, keywordsList.length);
      this.props.navigation.push('2', {
        c: this.state.correct + 2,
        w: this.state.wrong,
        t: this.state.timer,
        cc : this.state.count + 1,
      });
    }
    } else {
      if ( (this.state.count + 1) > maxCount) {
          this.props.navigation.navigate('1');
          Orientation.lockToPortrait();
          Alert.alert(
          'Well Done',
          'Correct: ' +
          this.state.correct +
          '\nWrong: ' +
          (this.state.wrong + 1) +
          '\n',
          );
        this.saveRecord(this.state.correct, (this.state.wrong + 1), this.state.timer);
        console.log('finish');}
      else {
      Alert.alert('Wrong!');
      keywordsList.splice(0, keywordsList.length);
      this.props.navigation.push('2', {
        c: this.state.correct,
        w: this.state.wrong + 1,
        t: this.state.timer,
        cc : this.state.count + 1,
      });
    }
    }
  };

  ansBbMajor = () => {
    console.log(maxCount);
    console.log(this.state.count);
      if (keywordsList.toString() === 'A#1,C2,D2,D#2,F2,G2,A2,A#2') {
      if ( (this.state.count + 1) > maxCount) {
          this.props.navigation.navigate('1');
          Orientation.lockToPortrait();
          Alert.alert(
          'Well Done',
          'Correct: ' +
          (this.state.correct + 2) +
          '\nWrong: ' +
          this.state.wrong +
          '\n',
          );
        this.saveRecord((this.state.correct + 2), this.state.wrong, this.state.timer);
        console.log('finish');}
      else {
      Alert.alert('Correct!');
      keywordsList.splice(0, keywordsList.length);
      this.props.navigation.push('2', {
        c: this.state.correct + 2,
        w: this.state.wrong,
        t: this.state.timer,
        cc : this.state.count + 1,
      });
    }
    } else {
      if ( (this.state.count + 1) > maxCount) {
          this.props.navigation.navigate('1');
          Orientation.lockToPortrait();
          Alert.alert(
          'Well Done',
          'Correct: ' +
          this.state.correct +
          '\nWrong: ' +
          (this.state.wrong + 1) +
          '\n',
          );
        this.saveRecord(this.state.correct, (this.state.wrong + 1), this.state.timer);
        console.log('finish');}
      else {
      Alert.alert('Wrong!');
      keywordsList.splice(0, keywordsList.length);
      this.props.navigation.push('2', {
        c: this.state.correct,
        w: this.state.wrong + 1,
        t: this.state.timer,
        cc : this.state.count + 1,
      });
    }
    }
  };

  ansAbMajor = () => {
    console.log(maxCount);
    console.log(this.state.count);
      if (keywordsList.toString() === 'G#1,A#1,C2,C#2,D#2,F2,G2,G#2') {
      if ( (this.state.count + 1) > maxCount) {
          this.props.navigation.navigate('1');
          Orientation.lockToPortrait();
          Alert.alert(
          'Well Done',
          'Correct: ' +
          (this.state.correct + 2) +
          '\nWrong: ' +
          this.state.wrong +
          '\n',
          );
        this.saveRecord((this.state.correct + 2), this.state.wrong, this.state.timer);
        console.log('finish');}
      else {
      Alert.alert('Correct!');
      keywordsList.splice(0, keywordsList.length);
      this.props.navigation.push('2', {
        c: this.state.correct + 2,
        w: this.state.wrong,
        t: this.state.timer,
        cc : this.state.count + 1,
      });
    }
    } else {
      if ( (this.state.count + 1) > maxCount) {
          this.props.navigation.navigate('1');
          Orientation.lockToPortrait();
          Alert.alert(
          'Well Done',
          'Correct: ' +
          this.state.correct +
          '\nWrong: ' +
          (this.state.wrong + 1) +
          '\n',
          );
        this.saveRecord(this.state.correct, (this.state.wrong + 1), this.state.timer);
        console.log('finish');}
      else {
      Alert.alert('Wrong!');
      keywordsList.splice(0, keywordsList.length);
      this.props.navigation.push('2', {
        c: this.state.correct,
        w: this.state.wrong + 1,
        t: this.state.timer,
        cc : this.state.count + 1,
      });
    }
    }
  };

  ansGbMajor = () => {
    console.log(maxCount);
    console.log(this.state.count);
      if (keywordsList.toString() === 'F#1,G#1,A#1,B1,C#2,D#2,F2,F#2') {
      if ( (this.state.count + 1) > maxCount) {
          this.props.navigation.navigate('1');
          Orientation.lockToPortrait();
          Alert.alert(
          'Well Done',
          'Correct: ' +
          (this.state.correct + 2) +
          '\nWrong: ' +
          this.state.wrong +
          '\n',
          );
        this.saveRecord((this.state.correct + 2), this.state.wrong, this.state.timer);
        console.log('finish');}
      else {
      Alert.alert('Correct!');
      keywordsList.splice(0, keywordsList.length);
      this.props.navigation.push('2', {
        c: this.state.correct + 2,
        w: this.state.wrong,
        t: this.state.timer,
        cc : this.state.count + 1,
      });
    }
    } else {
      if ( (this.state.count + 1) > maxCount) {
          this.props.navigation.navigate('1');
          Orientation.lockToPortrait();
          Alert.alert(
          'Well Done',
          'Correct: ' +
          this.state.correct +
          '\nWrong: ' +
          (this.state.wrong + 1) +
          '\n',
          );
        this.saveRecord(this.state.correct, (this.state.wrong + 1), this.state.timer);
        console.log('finish');}
      else {
      Alert.alert('Wrong!');
      keywordsList.splice(0, keywordsList.length);
      this.props.navigation.push('2', {
        c: this.state.correct,
        w: this.state.wrong + 1,
        t: this.state.timer,
        cc : this.state.count + 1,
      });
    }
    }
  };

   /* countMax(){
   if (this.state.count > this.state.logbook.length || this.state.count > countQ || this.state.count > maxCount) {
          this.props.navigation.navigate('1');
          Orientation.lockToPortrait();
          Alert.alert(
          'Well Done',
          'Correct: ' +
          this.state.correct +
          '\nWrong: ' +
          this.state.wrong +
          '\n',
          );
        this.saveRecord(this.state.correct, this.state.wrong, this.state.timer);
        console.log('finish');}
  }*/

  componentDidMount() {
    this.setState({
      correct: this.props.route.params.c,
      wrong: this.props.route.params.w,
      timer: this.props.route.params.t,
      count: this.props.route.params.cc,
    });
   // console.log(this.props.route.params.cc);
    Orientation.lockToLandscape();
     this.interval = setInterval(
      () => this.setState((prevState) => ({timer: prevState.timer + 1})),
      1000,
    );
    this.displayData();
  }

    componentWillUnmount() {
    clearInterval(this.interval);
    // Orientation.lockToLandscape();
  }
  ';';

    displayData = async () => {
    RNFS.readFile(path, 'ascii')
      .then((res) => {
        this.setState({
          logbook: res.split(','),
        });
      RNFS.readFile(path1, 'ascii')
        .then((ccc) => {
        console.log('has notes has counter');
        console.log(ccc);
        imageN = Math.floor(Math.random() * this.state.logbook.length);
        this.setState({
        name : this.state.logbook[imageN],
        });
        indexN = Notes.findIndex(item=> '"' + item.name + '"' ===  this.state.name || '["' + item.name + '"]' ===  this.state.name  || '["' + item.name + '"' ===  this.state.name || '"' + item.name + '"]' ===  this.state.name);
        console.log(this.state.name);
        maxCount = ccc;
        console.log(maxCount);
        })
        .catch((err) => {
        console.log(err.message, err.code);
        console.log('has notes no counter');
        imageN = Math.floor(Math.random() * this.state.logbook.length);
        this.setState({
        name : this.state.logbook[imageN],
        });
        indexN = Notes.findIndex(item=> '"' + item.name + '"' ===  this.state.name || '["' + item.name + '"]' ===  this.state.name  || '["' + item.name + '"' ===  this.state.name || '"' + item.name + '"]' ===  this.state.name);
        //console.log(this.state.name);
        });
         maxCount = this.state.logbook.length;
        console.log(maxCount);
      })
      .catch((err) => {
         console.log(err.message, err.code);
         RNFS.readFile(path1, 'ascii')
            .then((res) => {
              console.log('no notes has counter');
             imageN = Math.floor(Math.random() * Notes.length);
             indexN = imageN;
             this.setState({
             name : Notes[indexN].name,
             });
            // console.log(this.state.name);
            // console.log(imageN);
             maxCount = res;
        console.log(maxCount);
         })
         .catch(() => {
         // console.log(err.message, err.code);
          console.log('no notes no counter');
          imageN = Math.floor(Math.random() * Notes.length);
          indexN = imageN;
          this.setState({
          name : Notes[indexN].name,
          });
         // console.log(this.state.name);
         // console.log(imageN);
         maxCount = 2;
         console.log(maxCount);
       });
      });
  };

    saveRecord = async (correct, wrong, timer) => {
    let obj = {
      correct: correct,
      wrong: wrong,
      timer: timer,
      date: date,
      time: time,
    };
    if (await RNFS.exists(record)) {
      console.log('BLAH EXISTS');
      // write the file
      RNFS.appendFile(
        record,
        'Correct : ' +
          JSON.stringify(obj.correct) +
          ',' +
          'Wrong : ' +
          JSON.stringify(obj.wrong) +
          ',' +
          'Timer : ' +
          JSON.stringify(obj.timer) +
          ',' +
          'Date : ' +
          date +
          ',' +
          'Time : ' +
          time +
          '\n',
        'utf8',
      )
        .then((success) => {
          console.log(JSON.stringify(obj));
        })
        .catch((err) => {
          console.log(err.message);
        });
    } else {
      console.log('BLAH DOES NOT EXIST');
      RNFS.writeFile(
        record,
        'Correct : ' +
          JSON.stringify(obj.correct) +
          ',' +
          'Wrong : ' +
          JSON.stringify(obj.wrong) +
          ',' +
          'Timer : ' +
          JSON.stringify(obj.timer) +
          ',' +
          'Date : ' +
          date +
          ',' +
          'Time : ' +
          time +
          '\n',
        'utf8',
      )
        .then((success) => {
          console.log(JSON.stringify(obj));
        })
        .catch((err) => {
          console.log(err.message);
        });
    }
  };

  render() {
      const {
      selectedKeywordStyle,
      buttonStyle,
      textStyle,
      buttonB1,
      buttonB2,
      buttonB3,
      buttonB4,
      buttonB5,
      SbuttonB1,
      SbuttonB2,
      SbuttonB3,
      SbuttonB4,
      SbuttonB5,
      buttonB11,
      buttonB21,
      buttonB31,
      buttonB41,
      buttonB51,
      SbuttonB11,
      SbuttonB21,
      SbuttonB31,
      SbuttonB41,
      SbuttonB51,
    } = styles;
    return (
      <View style={styles.container}>
        <StatusBar hidden />
        <View style={styles.c1}>
          <View style={styles.cc1}>
            <Text style={styles.correct}>Correct : {this.state.correct}</Text>
            <Text style={styles.wrong}>
              Wrong :{'\n'}
              {this.state.wrong}
            </Text>
            <Text style={styles.timer}>
              Timer :{'\n'}
              {this.state.timer}
            </Text>
          </View>
          <View style={styles.buttonView}>
            <View style={styles.submit}>
              <Button
                title="RESET  "
                color="#E07EF9"
                onPress={this.removeArray}
              />
            </View>
            <View style={styles.submit}>
              <Button title="SUBMIT" color="#E07EF9" onPress={this.onSubmit} />
            </View>
          </View>
          <Image style={styles.logo} source={Notes[indexN].image} />
        </View>
        <View style={styles.c2}>
          {NOTESWHITE.map((item, id) => (
            <TouchableHighlight
              style={
                keywordsList.find((element) => element === item)
                  ? selectedKeywordStyle
                  : buttonStyle
              }
              onPress={() => this.toggleKeyword(item)}
              key={id}>
              <Text style={textStyle}> </Text>
            </TouchableHighlight>
          ))}
          {NOTESCC.map((item, id) => (
            <TouchableHighlight
              style={
                keywordsList.find((element) => element === item)
                  ? SbuttonB1
                  : buttonB1
              }
              onPress={() => this.toggleKeyword(item)}
              key={id}>
              <Text style={textStyle}> </Text>
            </TouchableHighlight>
          ))}
          {NOTESDD.map((item, id) => (
            <TouchableHighlight
              style={
                keywordsList.find((element) => element === item)
                  ? SbuttonB2
                  : buttonB2
              }
              onPress={() => this.toggleKeyword(item)}
              key={id}>
              <Text style={textStyle}> </Text>
            </TouchableHighlight>
          ))}
          {NOTESFF.map((item, id) => (
            <TouchableHighlight
              style={
                keywordsList.find((element) => element === item)
                  ? SbuttonB3
                  : buttonB3
              }
              onPress={() => this.toggleKeyword(item)}
              key={id}>
              <Text style={textStyle}> </Text>
            </TouchableHighlight>
          ))}
          {NOTESGG.map((item, id) => (
            <TouchableHighlight
              style={
                keywordsList.find((element) => element === item)
                  ? SbuttonB4
                  : buttonB4
              }
              onPress={() => this.toggleKeyword(item)}
              key={id}>
              <Text style={textStyle}> </Text>
            </TouchableHighlight>
          ))}
          {NOTESAA.map((item, id) => (
            <TouchableHighlight
              style={
                keywordsList.find((element) => element === item)
                  ? SbuttonB5
                  : buttonB5
              }
              onPress={() => this.toggleKeyword(item)}
              key={id}>
              <Text style={textStyle}> </Text>
            </TouchableHighlight>
          ))}
          {NOTESCC1.map((item, id) => (
            <TouchableHighlight
              style={
                keywordsList.find((element) => element === item)
                  ? SbuttonB11
                  : buttonB11
              }
              onPress={() => this.toggleKeyword(item)}
              key={id}>
              <Text style={textStyle}> </Text>
            </TouchableHighlight>
          ))}
          {NOTESDD1.map((item, id) => (
            <TouchableHighlight
              style={
                keywordsList.find((element) => element === item)
                  ? SbuttonB21
                  : buttonB21
              }
              onPress={() => this.toggleKeyword(item)}
              key={id}>
              <Text style={textStyle}> </Text>
            </TouchableHighlight>
          ))}
          {NOTESFF1.map((item, id) => (
            <TouchableHighlight
              style={
                keywordsList.find((element) => element === item)
                  ? SbuttonB31
                  : buttonB31
              }
              onPress={() => this.toggleKeyword(item)}
              key={id}>
              <Text style={textStyle}> </Text>
            </TouchableHighlight>
          ))}
          {NOTESGG1.map((item, id) => (
            <TouchableHighlight
              style={
                keywordsList.find((element) => element === item)
                  ? SbuttonB41
                  : buttonB41
              }
              onPress={() => this.toggleKeyword(item)}
              key={id}>
              <Text style={textStyle}> </Text>
            </TouchableHighlight>
          ))}
          {NOTESAA1.map((item, id) => (
            <TouchableHighlight
              style={
                keywordsList.find((element) => element === item)
                  ? SbuttonB51
                  : buttonB51
              }
              onPress={() => this.toggleKeyword(item)}
              key={id}>
              <Text style={textStyle}> </Text>
            </TouchableHighlight>
          ))}
        </View>
      </View>
    );
  }
}

export default Quiz;

