// material-ui
import {
    Button,
    CardContent, FormControlLabel,
    Grid, TextField,
    Typography
} from '@mui/material';
import MainCard from "../../components/MainCard";
import {useForm} from "react-hook-form";

import { useState} from "react";
import Checkbox from "@mui/material/Checkbox";
import * as React from "react";
// ==============================|| DASHBOARD - DEFAULT ||============================== //


const UserSearchForm_Organization = ({applySearch}) => {

    const [type, setType] = useState([]);
    const [locked, setLocked] = useState(false);


    const { reset, register, handleSubmit } = useForm()
    const onSubmit = (data) => {

        let typeArray = [];

        for(let i =0; i < type.length; i++){
            typeArray.push(type[i].label);
        }

        const temp = {
            username: data.userName,
            fullName: data.fullName,
            email: data.email,
            phone: data.phone,
            locked: locked,
        };
        applySearch(temp);
    };

    function resetForm(){
        setType([]);
        setLocked(false);
        reset();
    }

    return (
        <MainCard xs={12} md={12} lg={12}
                  border={false}
                  content={false}>

            <form onSubmit={handleSubmit(onSubmit)}>
                {/*row 1*/}
                <CardContent sx={{ px: 2.5, pt: 3 }}>
                    <Grid item justifyContent="space-between" alignItems="center">
                        Search Form
                    </Grid>
                </CardContent>

                {/*row 2*/}
                <Grid container alignItems={"center"}>
                    <Grid item xs={9} s={6} md={5} lg={3} sx={{ml:3, mr:3, mb:3}}>
                        <TextField
                            fullWidth
                            {...register("userName")}
                            id='userName'
                            label="Username"
                        />
                    </Grid>

                    <Grid item xs={9} s={6} md={5} lg={3} sx={{ml:3, mr:3, mb:3}}>
                        <TextField
                            fullWidth
                            {...register("fullName")}
                            id="fullName"
                            label="Full Name"
                        />
                    </Grid>

                    <Grid item xs={9} s={6} md={5} lg={3} sx={{ml:3, mr:3, mb:3}}>
                        <TextField
                            fullWidth
                            {...register("email")}
                            id="email"
                            label="Email"
                        />
                    </Grid>

                    <Grid item xs={9} s={6} md={5} lg={3} sx={{ml:3, mr:3, mb:3}}>
                        <TextField
                            fullWidth
                            {...register("phone")}
                            id="phone"
                            label="Phone"
                        />
                    </Grid>

                    <Grid item xs={9} s={6} md={5} lg={3} sx={{ml:3, mr:3, mb:3}}>
                        <FormControlLabel
                            control={
                                <Checkbox
                                    checked={locked}
                                    onChange={(event) => setLocked(event.target.checked)}
                                    name="checked"
                                    color="primary"
                                    size="small"
                                />
                            }
                            label={<Typography variant="h6">Locked</Typography>}
                        />
                    </Grid>
                    {/*<Grid item xs={9} s={6} md={5} lg={3} sx={{ml:3, mr:3, mb:3}}>*/}
                    {/*    <TextField*/}
                    {/*        fullWidth*/}
                    {/*        {...register("subDivisionId")}*/}
                    {/*        id="subDivision"*/}
                    {/*        label="Sub-Division"*/}
                    {/*    />*/}
                    {/*</Grid>*/}

                </Grid>


                {/*last row*/}
                <Grid container maxWidth justifyContent="flex-end">

                    <Grid item sx={{ml:3, mr:3, mb:3, mt:3}}>
                        <Button
                            size="large"
                            variant="contained"
                            onClick={resetForm}
                            sx={{
                                textTransform: 'capitalize',
                                alignItems: 'end'
                            }}>
                            Clear
                        </Button>
                    </Grid>

                    <Grid item sx={{ml:3, mr:3, mb:3, mt:3}}>
                        <Button
                            size="large"
                            variant="contained"
                            type="submit"
                            sx={{
                                textTransform: 'capitalize',
                                alignItems: 'end'
                            }}>
                            Submit
                        </Button>
                    </Grid>
                </Grid>
            </form>
        </MainCard>
    );
};

export default UserSearchForm_Organization;
