"use client";
import { useCallback, useState } from "react";
import { useStigmer } from "../hooks";
import { toError } from "../internal/toError";
/**
 * Mutation hook that wraps `oauthapp.update()` with loading and error
 * state.
 *
 * Updates an existing OAuth app. The input must include the `name` and
 * `org` fields to identify the target resource, along with the updated
 * spec fields. Omit `clientSecret` to leave the existing secret
 * unchanged.
 *
 * @example
 * ```tsx
 * const { update, isUpdating, error } = useUpdateOAuthApp();
 *
 * await update({
 *   name: "My Slack App",
 *   org: "acme",
 *   provider: "Slack",
 *   clientId: "123456.789012",
 *   authorizationUrl: "https://slack.com/oauth/v2/authorize",
 *   tokenUrl: "https://slack.com/api/oauth.v2.access",
 * });
 * ```
 */
export function useUpdateOAuthApp() {
    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.oauthapp.update(input);
        }
        catch (err) {
            setError(toError(err));
            throw err;
        }
        finally {
            setIsUpdating(false);
        }
    }, [stigmer]);
    return { update, isUpdating, error, clearError };
}
//# sourceMappingURL=useUpdateOAuthApp.js.map