"use client";
import { useCallback, useState } from "react";
import { useStigmer } from "../hooks";
import { toError } from "../internal/toError";
/**
 * Behavior hook that wraps `mcpServer.apply()` with loading and error state.
 *
 * Creates an MCP server blueprint from a {@link McpServerInput}. Uses
 * `apply()` (upsert) rather than `create()` so re-submissions are
 * idempotent — matching the CLI's `stigmer apply` semantics.
 *
 * Follows the established SDK mutation hook pattern: `isCreating` flag,
 * `error` state, `clearError` reset, result returned from the promise
 * (not stored in hook state).
 *
 * @example
 * ```tsx
 * const { create, isCreating, error, clearError } = useCreateMcpServer();
 *
 * const server = await create({
 *   name: "github",
 *   org: "acme",
 *   http: { url: "https://mcp.github.com/sse" },
 *   env: { GITHUB_TOKEN: { isSecret: true, description: "GitHub PAT" } },
 * });
 * // server.metadata?.slug → "github"
 * ```
 */
export function useCreateMcpServer() {
    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.mcpServer.apply(input);
        }
        catch (err) {
            setError(toError(err));
            throw err;
        }
        finally {
            setIsCreating(false);
        }
    }, [stigmer]);
    return { create, isCreating, error, clearError };
}
//# sourceMappingURL=useCreateMcpServer.js.map