import useSWR from '../../../../../node_modules/swr/core/dist/index.mjs';
import { useStytchClient } from './useStytchClient.mjs';

const MAX_LIMIT_CONNECTION_GROUPS = 1000;
const scimGetConnectionGroupsKey = (orgId)=>[
        'scim.getConnectionGroups',
        orgId
    ];
const useScimConnectionGroups = ({ shouldFetch })=>{
    const client = useStytchClient();
    const org = client.organization.getSync();
    const orgId = org?.organization_id;
    return useSWR(shouldFetch ? scimGetConnectionGroupsKey(orgId) : null, async ()=>{
        let response = await client.scim.getConnectionGroups({
            limit: MAX_LIMIT_CONNECTION_GROUPS
        });
        while(response.next_cursor){
            await client.scim.getConnectionGroups({
                limit: MAX_LIMIT_CONNECTION_GROUPS,
                cursor: response.next_cursor
            }).then((newResponse)=>{
                response = {
                    ...response,
                    scim_groups: [
                        ...response.scim_groups,
                        ...newResponse.scim_groups
                    ],
                    next_cursor: newResponse.next_cursor
                };
            });
        }
        return response;
    });
};

export { MAX_LIMIT_CONNECTION_GROUPS, scimGetConnectionGroupsKey, useScimConnectionGroups };
//# sourceMappingURL=useScimConnectionGroups.mjs.map
