import React from 'react';
import {View, Text } from "react-native";
import { useTheme } from "react-native-paper";
import ProfileScreen from "@/components/ProfileScreen";
import StatusPage from "@/components/StatusPage";
import Nav from "@/components/Nav";
import BottomNav from "@/components/BottomNav"
import { useUser } from "@/context/UserContext";
import styles from "@/assets/styles";
import log from "@/util/log"

const Index = () => {
    const theme = useTheme();

    const {
        isProfileActive,
        setProfileActive,
        userId,
        userName,
        setUserName,
        userImage,
        setUserImage,
        userStatus,
        setUserStatus,
        setUserDataChanged,
        setTheme,
        currentTheme,
        isLoading,
    } = useUser();

    if (isLoading) {
        log.debug("Still loading");
        return (
            <View style={[styles.indexContainer, { backgroundColor: theme.colors.background, justifyContent: 'center', alignItems: 'center' }]}>
                <Text>Loading...</Text>
            </View>
        );
    }

    return (
        <View style={[styles.indexContainer, { backgroundColor: theme.colors.background }]}>
            <Nav
                toggleProfile={() => setProfileActive(true)}
            />
            <StatusPage
                id={userId}
                name={userName}
                image={userImage}
                currentStatus={userStatus}
                setStatus={setUserStatus}
                currentTheme={currentTheme}
                isProfileActive={isProfileActive}
            />
            <ProfileScreen
                visible={isProfileActive}
                id={userId}
                name={userName}
                setName={setUserName}
                image={userImage}
                setImage={setUserImage}
                setTheme={setTheme}
                currentTheme={currentTheme}
                setChanged={setUserDataChanged}
                onClose={() => setProfileActive(false)}
            />
            <BottomNav />
        </View>
    );
};

export default Index;
