"use client";
import { useCallback, useState } from "react";
import { useStigmer } from "../hooks";
import { toError } from "../internal/toError";
/**
 * Mutation hook that wraps `identityProvider.update()` with loading
 * and error state.
 *
 * Updates an existing identity provider. The input must include the
 * `slug` field to identify the target resource, along with the updated
 * spec fields.
 *
 * @example
 * ```tsx
 * const { update, isUpdating, error } = useUpdateIdentityProvider();
 *
 * await update({
 *   name: "Acme Corp SSO",
 *   slug: "acme-sso",
 *   org: "acme",
 *   displayName: "Acme Corp SSO",
 *   isSsoProvider: true,
 *   oidcClientId: "abc123",
 * });
 * refetch(); // refresh detail view
 * ```
 */
export function useUpdateIdentityProvider() {
    const stigmer = useStigmer();
    const [isUpdating, setIsUpdating] = useState(false);
    const [error, setError] = useState(null);
    const clearError = useCallback(() => setError(null), []);
    const update = useCallback(async (input) => {
        setIsUpdating(true);
        setError(null);
        try {
            return await stigmer.identityProvider.update(input);
        }
        catch (err) {
            setError(toError(err));
            throw err;
        }
        finally {
            setIsUpdating(false);
        }
    }, [stigmer]);
    return { update, isUpdating, error, clearError };
}
//# sourceMappingURL=useUpdateIdentityProvider.js.map