import { useCallback } from 'react';
import '../../../../../_virtual/index2.mjs';
import { useSWRConfig } from '../../../../../node_modules/swr/_internal/dist/index.mjs';
import { organizationGetKey } from './organizationGetKey.mjs';
import { useMutateWithToast } from './useMutateWithToast.mjs';
import { useStytchClient } from './useStytchClient.mjs';

const useMutateOrganization = ()=>{
    const { mutate: mutateSWR } = useSWRConfig();
    const client = useStytchClient();
    return useMutateWithToast(useCallback(async (properties)=>{
        const organizationId = client.organization.getSync()?.organization_id;
        await mutateSWR(organizationGetKey(organizationId), async ()=>{
            const resp = await client.organization.update(properties);
            return resp.organization;
        }, {
            // note that optimisticData is typed as `any`
            optimisticData: (org)=>({
                    ...org,
                    ...properties
                }),
            rollbackOnError: true,
            populateCache: true,
            revalidate: false
        });
    }, [
        client.organization,
        mutateSWR
    ]));
};

export { useMutateOrganization };
//# sourceMappingURL=useMutateOrganization.mjs.map
