"use client";
import { useCallback, useState } from "react";
import { useStigmer } from "../hooks";
import { toError } from "../internal/toError";
/**
 * Mutation hook that wraps `platformclient.update()` with loading
 * and error state.
 *
 * Updates an existing platform client. The input must include the
 * `slug` field to identify the target resource, along with the
 * updated spec fields. Credential fields (`clientId`,
 * `clientSecretHash`, `secretFingerprint`) are computed and
 * preserved by the backend — do not set them in the input.
 *
 * @example
 * ```tsx
 * const { update, isUpdating, error } = useUpdatePlatformClient();
 *
 * await update({
 *   name: "my-saas-backend",
 *   slug: "my-saas-backend",
 *   org: "acme",
 *   autoProvisionAccounts: true,
 *   autoGrantOnOrg: true,
 * });
 * refetch(); // refresh detail view
 * ```
 */
export function useUpdatePlatformClient() {
    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.platformclient.update(input);
        }
        catch (err) {
            setError(toError(err));
            throw err;
        }
        finally {
            setIsUpdating(false);
        }
    }, [stigmer]);
    return { update, isUpdating, error, clearError };
}
//# sourceMappingURL=useUpdatePlatformClient.js.map