"use client";
import { useCallback, useState } from "react";
import { useStigmer } from "../hooks";
import { toError } from "../internal/toError";
/**
 * Mutation hook that wraps `platformclient.rotateSecret()` with
 * loading and error state.
 *
 * Generates a new client secret, invalidating the previous one.
 * The response includes a **one-time raw client secret** — it must
 * be shown to the user immediately as the server never returns it
 * again.
 *
 * @example
 * ```tsx
 * const { rotateSecret, isRotating, error } = useRotatePlatformClientSecret();
 *
 * const response = await rotateSecret("pc-abc123");
 * // response.clientSecret is the new one-time raw secret
 * ```
 */
export function useRotatePlatformClientSecret() {
    const stigmer = useStigmer();
    const [isRotating, setIsRotating] = useState(false);
    const [error, setError] = useState(null);
    const clearError = useCallback(() => setError(null), []);
    const rotateSecret = useCallback(async (id) => {
        setIsRotating(true);
        setError(null);
        try {
            return await stigmer.platformclient.rotateSecret(id);
        }
        catch (err) {
            setError(toError(err));
            throw err;
        }
        finally {
            setIsRotating(false);
        }
    }, [stigmer]);
    return { rotateSecret, isRotating, error, clearError };
}
//# sourceMappingURL=useRotatePlatformClientSecret.js.map