"use client";
import { useCallback, useState } from "react";
import { create } from "@bufbuild/protobuf";
import { RemoveEnvironmentVariablesRequestSchema } from "@stigmer/protos/ai/stigmer/agentic/environment/v1/io_pb";
import { useStigmer } from "../hooks";
import { toError } from "../internal/toError";
/**
 * Behavior hook that wraps `environment.removeVariables()` with
 * loading/error state.
 *
 * Removes the specified keys from the environment's `spec.data`.
 * Keys that do not exist are silently ignored. Variables not
 * mentioned in the request are preserved unchanged.
 *
 * Returns the full {@link Environment} proto (with secrets redacted)
 * so callers can immediately reference the latest state.
 *
 * This is a Layer 1 building-block hook for the **Environment Flow**
 * — delete individual variables without a full-resource update cycle.
 *
 * @example
 * ```tsx
 * const { removeVariables, isRemovingVariables, error } =
 *   useRemoveEnvironmentVariables();
 *
 * const env = await removeVariables({
 *   environmentId: "env-abc123",
 *   keys: ["DEPRECATED_KEY", "OLD_TOKEN"],
 * });
 * ```
 */
export function useRemoveEnvironmentVariables() {
    const stigmer = useStigmer();
    const [isRemovingVariables, setIsRemovingVariables] = useState(false);
    const [error, setError] = useState(null);
    const clearError = useCallback(() => setError(null), []);
    const removeVariables = useCallback(async (input) => {
        setIsRemovingVariables(true);
        setError(null);
        try {
            const request = create(RemoveEnvironmentVariablesRequestSchema, {
                environmentId: input.environmentId,
                keys: input.keys,
            });
            return await stigmer.environment.removeVariables(request);
        }
        catch (err) {
            setError(toError(err));
            throw err;
        }
        finally {
            setIsRemovingVariables(false);
        }
    }, [stigmer]);
    return { removeVariables, isRemovingVariables, error, clearError };
}
//# sourceMappingURL=useRemoveEnvironmentVariables.js.map