// material-ui
import {
    Grid, Typography
} from '@mui/material';
import MainCard from "../../components/MainCard";
import SearchForm from "./UserSearchForm_Organization";
import EventTable from "./UserTable_Organization";
import {useEffect, useState} from "react";
//import axios from "axios";
//import {apiPath} from "../../auth/utils";
import * as UrlUtils from "../../utils/ApiPathConst";
import * as React from "react";
import LoadingComponent from "../extra-pages/LoadingComponent";
import * as HttpUtils from "../../utils/HttpUtils";

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

const UserSearchPage_Organization = () => {

    const [record,setRecord] = useState([]);
    const [searchCriteria, setSearchCriteria] = useState({});
    const [onReady, setOnReady] = useState(false);

    useEffect(() => {
        getUserList();
    }, []);

    useEffect(() => {
        setOnReady(true);
    }, [record]);

    useEffect(() => {
        getUserList();
    }, [searchCriteria]);

    function getUserList(){
        HttpUtils.get({
            url: UrlUtils.GET_ORG_USER_PATH,
            params: searchCriteria,
            onSuccess: function(responseData){
                setRecord(responseData);
            }
        });
    }

    function applySearch(input) {
        setSearchCriteria(input);
    }

    return (
        !onReady ?
            <LoadingComponent/>
            :
        <Grid container rowSpacing={4.5} columnSpacing={2.75}>
            <Grid item xs={12} sx={{mb: -2.25}}>
                <Typography variant="h5">View Organization User</Typography>
            </Grid>

            {/*row 1*/}
            <Grid item xs={12} md={12} lg={12}>
                <SearchForm applySearch={applySearch}/>
            </Grid>
            {/*row 2*/}
            <Grid item xs={12} md={12} lg={12}>
                <MainCard elevation={0}
                          border={false}
                          content={false}
                >
                    <EventTable
                        recordList={record}
                    />
                </MainCard>
            </Grid>

        </Grid>

    );
};

export default UserSearchPage_Organization;
