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

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


const OrganizationDetailPage = () => {
    const params = useParams();
    const [formData, setFormData]  = useState({})
    const [isLoading, setLoding] = useState(true);
    const navigate = useNavigate();


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

    const loadData = ()=>{
        setLoding(true);
        if(params.id>0){
            HttpUtils.get({
                url: UrlUtils.GET_ORG_FROM_USER_PATH+"/"+params.id,
                onSuccess: function(response){
                    setFormData(response.data)
                }
            });
        }else{
            navigate('/org/0');
        }
    };


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

    return (
        isLoading ?
            <LoadingComponent/>
            :
            <Grid container rowSpacing={4.5} columnSpacing={2.75}>
                <Grid item xs={12} sx={{mb: -2.25}}>
                    <Typography variant="h5">Organization (Create From User)</Typography>
                </Grid>
                {/*col 1*/}
                <Grid item xs={12} >
                    <Grid container>
                        <Grid item xs={12} md={12} lg={12}>
                            <InfoCard
                                userData={formData}
                                loadDataFun={loadData}
                                id={params.id}
                            />
                        </Grid>

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


export default OrganizationDetailPage;
