/* eslint-disable prettier/prettier */
/* eslint-disable react/no-did-mount-set-state */
/* eslint-disable prettier/prettier */
/* eslint-disable react-native/no-inline-styles */
/* eslint-disable prettier/prettier */
/* eslint-disable no-unused-vars */
/* eslint-disable prettier/prettier */
import React, {Component} from 'react';
import {
  Text,
  View,
  TouchableHighlight,
  ImageBackground,
  Image,
  Button,
  Alert,
  StatusBar,
} from 'react-native';
import Orientation from 'react-native-orientation';
import styles from './style.js';
import config from './config';
//import ImmersiveMode from 'react-native-immersive-mode';

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 = [];

export default class Quiz1 extends Component {
  constructor(props: Object) {
    super(props);
    this.state = {
      timer: 0,
      correct: 0,
      wrong: 0,
      keywordsList: '',
    };
  }
  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);
  };

  onSubmit = () => {
    const fullnotes = keywordsList.toString();
    if (
      fullnotes.includes('C1') &&
      fullnotes.includes('D1') &&
      fullnotes.includes('E1') &&
      fullnotes.includes('F1') &&
      fullnotes.includes('G1') &&
      fullnotes.includes('A1') &&
      fullnotes.includes('B1') &&
      fullnotes.includes('C2')
    ) {
      //if (keywordsList.toString() === 'C1,D1,E1,F1,G1,A1,B1,C2')
      this.setState({
        timer: 0,
      });
      clearInterval(this._interval);
      Alert.alert('Correct!');
      keywordsList.splice(0, keywordsList.length);
      this.props.navigation.navigate('2', {
        c: this.state.correct + 2,
        w: this.state.wrong,
      });
    } else {
      console.log('wrong');
      this.setState({
        timer: 0,
      });
      clearInterval(this._interval);
      keywordsList.splice(0, keywordsList.length);
      Alert.alert('Wrong!');
      this.props.navigation.navigate('2', {
        c: this.state.correct,
        w: this.state.wrong + 1,
      });
    }
  };

  componentDidMount() {
    Orientation.lockToLandscape();
    // ImmersiveMode.setBarMode('Bottom');
    this.interval = setInterval(
      () => this.setState((prevState) => ({timer: prevState.timer + 1})),
      1500,
    );
  }

  componentWillUnmount() {
    clearInterval(this.interval);
  }
  ';';

  render() {
    const {
      container,
      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={require('./img/Cmajor.png')} />
        </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>
    );
  }
}
