// material-ui
import {
    Button,
    CardContent,
    Grid, TextField,
} from '@mui/material';
import MainCard from "../../components/MainCard";
import {useForm} from "react-hook-form";
import * as React from "react";
// ==============================|| DASHBOARD - DEFAULT ||============================== //

const UserGroupSearchForm = ({applySearch}) => {

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

    function resetForm(){
        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("name")}
                            id='userGroupName'
                            label="User Group Name"
                        />
                    </Grid>

                    <Grid item xs={9} s={6} md={5} lg={3} sx={{ml:3, mr:3, mb:3}}>
                        <TextField
                            fullWidth
                            {...register("description")}
                            id="userGroupDescription"
                            label="User Group Description"
                        />
                    </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 UserGroupSearchForm;
