"use client";
import { useCallback, useState } from "react";
import { useStigmer } from "../hooks";
import { toError } from "../internal/toError";
/**
 * Mutation hook that wraps `identityProvider.create()` with loading
 * and error state.
 *
 * Creates an identity provider resource within an organization. The
 * caller provides an {@link IdentityProviderInput} with the required
 * metadata (name, org) and spec fields (JWKS URI, allowed issuers,
 * expected audience).
 *
 * @example
 * ```tsx
 * const { create, isCreating, error } = useCreateIdentityProvider();
 *
 * const idp = await create({
 *   name: "Acme Corp SSO",
 *   org: "acme",
 *   jwksUri: "https://acme.us.auth0.com/.well-known/jwks.json",
 *   allowedIssuers: ["https://acme.us.auth0.com/"],
 *   expectedAudience: "stigmer-api",
 * });
 * ```
 */
export function useCreateIdentityProvider() {
    const stigmer = useStigmer();
    const [isCreating, setIsCreating] = useState(false);
    const [error, setError] = useState(null);
    const clearError = useCallback(() => setError(null), []);
    const create = useCallback(async (input) => {
        setIsCreating(true);
        setError(null);
        try {
            return await stigmer.identityProvider.create(input);
        }
        catch (err) {
            setError(toError(err));
            throw err;
        }
        finally {
            setIsCreating(false);
        }
    }, [stigmer]);
    return { create, isCreating, error, clearError };
}
//# sourceMappingURL=useCreateIdentityProvider.js.map