"use client";

import useModulesWithAttrsList from "@/app/modules/hooks/useModulesWithAttrsList";
import { ModuleWithAttributesSchema } from "@/lib/client";
import makeContext from "@/lib/contextFactory/contextFactory";

type ModulesContextState = {
    modules: ModuleWithAttributesSchema[];
    refetchModules: () => void;
};

const useModulesContextState = (): ModulesContextState => {
    const { modules, refetch } = useModulesWithAttrsList();

    return {
        modules,
        refetchModules: refetch,
    };
};

export const [ModulesContextProvider, useModulesContext] =
    makeContext<ModulesContextState>(useModulesContextState, "Modules");
