import React from "react"
import { View, ScrollView, StyleSheet, StatusBar, Text, CheckBox, Switch, Dimensions, Image, ImageBackground, BackHandler } from "react-native"
import SafeAreaView from 'react-native-safe-area-view'
import AsyncStorage from '@react-native-async-storage/async-storage'
import { Button, ButtonContainer } from "../components/Button"
import { colors, texts, examScheme, resultsScheme} from "../components/Variables"
import aerodynamicsQuestions from "../data/aerodynamics"
import firstAidQuestions from "../data/firstAid"
import flightSafetyQuestions from "../data/flightSafety"
import instrumentsQuestions from "../data/instruments"
import legislationQuestions from "../data/legislation"
import materialsQuestions from "../data/materials"
import meteorologyQuestions from "../data/meteorology"
import physiopathologyQuestions from "../data/physiopathology"
import pilotingTechniquesQuestions from "../data/pilotingTechniques"
const allQuestions = {
aerodynamics: aerodynamicsQuestions,
firstAid: firstAidQuestions,
flightSafety: flightSafetyQuestions,
instruments: instrumentsQuestions,
legislation: legislationQuestions,
materials: materialsQuestions,
meteorology: meteorologyQuestions,
physiopathology: physiopathologyQuestions,
pilotingTechniques: pilotingTechniquesQuestions
}
const bgImage = require("../assets/bg.jpg")
const screen = Dimensions.get("window")
const pkg = require('../../app.json')
const styles = StyleSheet.create({
container: {
//backgroundColor: colors.dark_blue,
flex: 1
},
safearea: {
flex: 1,
marginTop: 25,
justifyContent: "space-between",
paddingHorizontal: 10
},
bg: {
width: "100%",
height: "100%"
},
box: {
width: screen.width-20,
paddingHorizontal: 10
},
text: {
color: colors.white,
fontSize: 16,
textAlign: "center",
fontWeight: "400",
lineHeight: 20,
textShadowColor: 'rgba(0, 0, 0, 0.75)',
textShadowOffset: {width: -1, height: 1},
textShadowRadius: 5
},
title: {
paddingTop: 40,
paddingBottom: 20,
color: colors.white,
fontSize: 18,
textTransform: "uppercase",
textAlign: "center",
fontWeight: "400",
lineHeight: 20,
textShadowColor: 'rgba(0, 0, 0, 0.75)',
textShadowOffset: {width: -1, height: 1},
textShadowRadius: 5
},
switchesBox: {
lineHeight: 23,
//marginTop: 15,
borderRadius: 5,
backgroundColor: colors.black_alpha2,
borderColor: colors.white,
borderWidth: 2,
fontSize: 18,
color: colors.white,
fontWeight: "400",
textAlign: "center",
paddingHorizontal: 20,
paddingVertical: 5,
textShadowColor: 'rgba(0, 0, 0, 0.75)',
textShadowOffset: {width: -1, height: 1},
textShadowRadius: 5
},
noBorder: {
borderBottomWidth: 0
},
noPadding: {
paddingVertical: 0,
},
bold: {
lineHeight: 30,
fontSize: 26,
fontWeight: "600"
},
switchContainer: {
flexDirection: "row",
paddingVertical: 15,
//marginVertical: 10,
borderBottomColor: colors.white,
borderBottomWidth: 1,
},
switch: {
alignSelf: "flex-start",
color: "white",
marginRight: 0,
marginLeft: "auto"
},
switchLabel: {
fontSize: 18,
fontWeight: "600",
marginHorizontal: 8,
color: colors.white,
width: "75%"
},
button: {
marginTop: 20
}
})
const B = (props) => {props.children}
class Setup extends React.Component {
state = {
setupData: {}
}
componentDidMount() {
BackHandler.addEventListener('hardwareBackPress', this.handleBackButton)
AsyncStorage.getItem('setupData').then((value) => {
let setupData = {}
if(!value) {
setupData = {
randomQuestions: true,
excludeDelta: true
}
AsyncStorage.setItem('setupData', JSON.stringify(setupData))
} else {
setupData = JSON.parse(value)
}
this.setState( (state) => {
return {
setupData: setupData
}
})
})
}
componentWillUnmount() {
BackHandler.removeEventListener('hardwareBackPress', this.handleBackButton)
}
handleBackButton = () => {
let tmpQuestions = []
AsyncStorage.getItem('setupData').then((value) => {
let setupData = JSON.parse(value)
examScheme.forEach( (elem) => {
let currentSection = setupData.excludeDelta ? allQuestions[elem.section].filter(item => !item.delta) : allQuestions[elem.section]
for(let i=0; i index != currentIndex)
}
})
this.props.navigation.navigate("Splash", {
examQuestions: tmpQuestions
})
return true
})
}
changeSetup = (item) => {
let setupData = this.state.setupData
setupData[item] = !this.state.setupData[item]
this.setState( (state) => {
return {
setupData: setupData
}
})
AsyncStorage.setItem('setupData', JSON.stringify(setupData))
}
render() {
return (
{texts.setupScheme}
{texts.setupRandomCheck}
this.changeSetup('randomQuestions')}
style={styles.switch}
/>
{texts.setupExcludeDelta}
this.changeSetup('excludeDelta')}
style={styles.switch}
/>
)
}
}
export default Setup