// material-ui
import {Grid, Typography} from '@mui/material';
import {useEffect, useState} from "react";
import * as React from "react";
//import axios from "axios";
import * as HttpUtils from "../../utils/HttpUtils";
import {useParams} from "react-router-dom";
import UserInformationCard from "./UserInformationCard_Individual";
import LoadingComponent from "../extra-pages/LoadingComponent";
import * as UrlUtils from "../../utils/ApiPathConst";

// ==============================|| DASHBOARD - DEFAULT ||============================== //


const UserMaintainPage_Individual = () => {
    const params = useParams();
    const [userData, setUserData]  = useState({})
    const [userFile, setUserFile]  = useState({})
    const [isLoading, setLoding] = useState(true);


    useEffect(()=>{
        console.log(userData);
        loadData();
    },[]);

    const loadData = ()=>{
        setLoding(true);
        HttpUtils.get({
            url: `${UrlUtils.GET_IND_USER_PATH}/${params.id}`,
            onSuccess: function(response){
                setUserData(response.data);
                setUserFile(response.userFile)
            }
        });
    };


    useEffect(() => {
       setLoding(false);
    }, [userData]);

    return (
        isLoading ?
            <LoadingComponent/>
            :
            <Grid container rowSpacing={4.5} columnSpacing={2.75}>
                <Grid item xs={12} sx={{mb: -2.25}}>
                    <Typography variant="h5">Individual User</Typography>
                </Grid>
                {/*col 1*/}
                <Grid item xs={12} >
                    <Grid container>
                        <Grid item xs={12} md={12} lg={12}>
                            <UserInformationCard
                                userData={userData}
                                userFile={userFile}
                                loadDataFun={loadData}
                            />
                        </Grid>

                    </Grid>
                </Grid>
                {/*col 2*/}
            </Grid>
    );
};


export default UserMaintainPage_Individual;
