"use client";
import { useCallback, useState } from "react";
import { useStigmer } from "../hooks";
import { toError } from "../internal/toError";
/**
 * Mutation hook that wraps `platformclient.create()` with loading
 * and error state.
 *
 * Creates a platform client resource within an organization. The
 * response includes a **one-time raw client secret** that must be
 * shown to the user immediately — the server never returns it again.
 *
 * @example
 * ```tsx
 * const { create, isCreating, error } = useCreatePlatformClient();
 *
 * const response = await create({
 *   name: "my-saas-backend",
 *   org: "acme",
 *   autoProvisionAccounts: true,
 *   autoGrantOnOrg: true,
 * });
 *
 * // response.clientSecret is the one-time raw secret
 * // response.platformClient is the created resource
 * ```
 */
export function useCreatePlatformClient() {
    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.platformclient.create(input);
        }
        catch (err) {
            setError(toError(err));
            throw err;
        }
        finally {
            setIsCreating(false);
        }
    }, [stigmer]);
    return { create, isCreating, error, clearError };
}
//# sourceMappingURL=useCreatePlatformClient.js.map