"use client";
import { useCallback, useState } from "react";
import { useStigmer } from "../hooks";
import { toError } from "../internal/toError";
/**
 * Mutation hook that wraps `oauthapp.create()` with loading and error
 * state.
 *
 * Creates an OAuth app resource within an organization. The caller
 * provides an {@link OAuthAppInput} with the required metadata (name,
 * org) and spec fields (provider, client ID, client secret, OAuth
 * endpoint URLs).
 *
 * @example
 * ```tsx
 * const { create, isCreating, error } = useCreateOAuthApp();
 *
 * const app = await create({
 *   name: "My Slack App",
 *   org: "acme",
 *   provider: "Slack",
 *   clientId: "123456.789012",
 *   clientSecret: "secret",
 *   authorizationUrl: "https://slack.com/oauth/v2/authorize",
 *   tokenUrl: "https://slack.com/api/oauth.v2.access",
 * });
 * ```
 */
export function useCreateOAuthApp() {
    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.oauthapp.create(input);
        }
        catch (err) {
            setError(toError(err));
            throw err;
        }
        finally {
            setIsCreating(false);
        }
    }, [stigmer]);
    return { create, isCreating, error, clearError };
}
//# sourceMappingURL=useCreateOAuthApp.js.map