"use client";

import { createContext, useContext } from "react";
import useGroups from "@/features/groups/hooks/use-groups";

const GroupsContext = createContext<ReturnType<typeof useGroups> | null>(null);

type GroupsProviderProps = {
    children: React.ReactNode;
};

export function GroupsProvider({ children }: GroupsProviderProps) {
    const groups = useGroups();
    return <GroupsContext.Provider value={groups}>{children}</GroupsContext.Provider>;
}

export function useGroupsContext() {
    const ctx = useContext(GroupsContext);
    if (!ctx) throw new Error("GroupsProvider is missing");
    return ctx;
}

