// 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";
import LoadingComponent from "../extra-pages/LoadingComponent";
import * as UrlUtils from "../../utils/ApiPathConst";

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


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


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

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


    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</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;
