import ModuleForm from "./ModuleForm";
import { getModules } from "@/utils/querys/admin/modules";
import { useQuery } from "@tanstack/react-query";
//import { getUserRoles } from "@/utils/querys/admin/userRoles";
//import { Checkbox } from "@radix-ui/react-checkbox";

export default function ModuleAccess(data: any) {
    const token = localStorage.getItem("auth_token");
    // const { data: userRoles } = useQuery(getUserRoles());
    const {
        data: modules,
        isError,
        isLoading,
    } = useQuery(getModules(token ?? ""));

    if (isError) return <div>Error gettings Roles</div>;
    if (isLoading) return <div>Loading modules</div>;
    return (
        <div className="flex flex-row flex-wrap">
            {modules?.map((m: any) => {
                return (
                    <div key={m.module_id}>
                        <ModuleForm
                            module={m}
                            user={data.user}
                            refetch={data.refetch}
                        />
                    </div>
                );
            })}
        </div>
    );
}
