import { StyleSheet, Text, View, Image, TouchableOpacity, FlatList } from 'react-native';
import Container from '../components/Container';

const ScreenHome = ({ navigation }) => {

    const menuItems = [
        {
            key: '1',
            title: 'Profile',
            icon: require('../assets/illustration/menu/male.png'),
            screen: 'Profile',
        },
        {
            key: '2',
            title: 'Berat Badan Ideal',
            icon: require('../assets/illustration/menu/height.png'),
            screen: 'Massa',
        },
        {
            key: '3',
            title: 'Suhu Badan',
            icon: require('../assets/illustration/menu/thermometer.png'),
            screen: 'Suhu',
        },
        {
            key: '4',
            title: 'Riwayat Puasa',
            icon: require('../assets/illustration/menu/medicine.png'),
            screen: 'Puasa',
        },
        {
            key: '5',
            title: 'Tensi',
            icon: require('../assets/illustration/menu/sphygmomanometer.png'),
            screen: 'Tensi',
        },
        {
            key: '6',
            title: 'Gula Darah',
            icon: require('../assets/illustration/menu/sugar-blood-level.png'),
            screen: 'Gula',
        }
    ];

    const renderItem = ({ item }) => (
        <TouchableOpacity
            style={styles.menuItem}
            onPress={() => navigation.navigate(item.screen)}
        >
            <Image source={item.icon} style={styles.menuIcon} />
            <Text style={styles.menuTitle}>{item.title}</Text>
        </TouchableOpacity>
    );


    return (
        <Container>

            <View style={styles.header}>
                <Image
                    source={require('../assets/illustration/66139.jpg')}
                    style={styles.headerImage}
                />
            </View>

            <Text style={styles.title}>Check Care Apps</Text>

            <FlatList
                data={menuItems}
                numColumns={3}
                renderItem={renderItem}
                keyExtractor={(item) => item.key}
                contentContainerStyle={styles.menuGrid}
            />

        </Container>
    );
}

const styles = StyleSheet.create({
    header: {
        flex: 1,
        backgroundColor: "#FFDDDD"
    },
    headerImage: {
        width: '100%',
        height: '100%',
        resizeMode: 'cover',
        position: 'absolute',
    },
    title: {
        fontSize: 36,
        textAlign: 'center',
        fontWeight: 'bold',
    },
    main: {
        flex: 3,
        backgroundColor: "#DDFFDD"
    },
    menuGrid: {
        marginTop: 20,
        justifyContent: 'center',
    },
    menuItem: {
        flex: 1,
        margin: 10,
        alignItems: 'center',
    },
    menuIcon: {
        width: 50,
        height: 50,
        marginBottom: 8,
    },
    menuTitle: {
        fontSize: 14,
        textAlign: 'center',
    },
});

export default ScreenHome;
