import { useCallback } from "react";
export function useAgentInfoSocketHandler(input) {
    const { agent, profiles, setAgent, setActiveProfile, onAgentUpdate } = input;
    return useCallback((messageType, payload) => {
        if (!agent) {
            return false;
        }
        if (messageType === "agent:info:updated") {
            const { agentId: updatedAgentId, agentName, agentDescription, } = payload || {};
            if (updatedAgentId === agent.id && (agentName || agentDescription)) {
                setAgent((prev) => {
                    if (!prev)
                        return prev;
                    return {
                        ...prev,
                        ...(agentName ? { name: agentName } : {}),
                        ...(agentDescription ? { description: agentDescription } : {}),
                    };
                });
                onAgentUpdate?.({
                    ...(agentName ? { name: agentName } : {}),
                    ...(agentDescription ? { description: agentDescription } : {}),
                });
            }
            return true;
        }
        if (messageType === "agent:profile:switched") {
            const switchedAgentId = payload?.agentId;
            const newProfileId = payload?.newProfileId;
            const newProfileName = payload?.newProfileName;
            if (switchedAgentId === agent.id && newProfileId) {
                setAgent((prev) => {
                    if (!prev)
                        return prev;
                    return {
                        ...prev,
                        profileId: newProfileId,
                        profileName: newProfileName,
                    };
                });
                const newProfile = profiles.find((profile) => profile.id.toLowerCase() === newProfileId?.toLowerCase());
                if (newProfile) {
                    setActiveProfile(newProfile);
                }
                onAgentUpdate?.({
                    profileId: newProfileId,
                    profileName: newProfileName,
                });
            }
            return true;
        }
        return false;
    }, [agent, onAgentUpdate, profiles, setActiveProfile, setAgent]);
}
//# sourceMappingURL=useAgentInfoSocketHandler.js.map