"use client";
import { useCallback, useState } from "react";
import { useStigmer } from "../hooks";
import { toError } from "../internal/toError";
/**
 * Mutation hook that wraps `organization.update()` with loading and
 * error state.
 *
 * Updates an existing Organization resource. The input must include
 * `name`, `org`, and `slug` to identify the target resource, along
 * with the spec fields to update (`description`, `logoUrl`).
 *
 * Returns the full {@link Organization} proto including
 * server-updated metadata (version, timestamps) so callers can
 * immediately reference the latest state.
 *
 * @example
 * ```tsx
 * const { update, isUpdating, error } = useUpdateOrganization();
 *
 * const updated = await update({
 *   name: "Acme Corp",
 *   slug: "acme-corp",
 *   org: "acme-corp",
 *   description: "Updated description",
 * });
 * refetch(); // refresh profile view
 * ```
 */
export function useUpdateOrganization() {
    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.organization.update(input);
        }
        catch (err) {
            setError(toError(err));
            throw err;
        }
        finally {
            setIsUpdating(false);
        }
    }, [stigmer]);
    return { update, isUpdating, error, clearError };
}
//# sourceMappingURL=useUpdateOrganization.js.map