/** * Organization AI analysis hook * Handles symbiosis analysis and web intelligence for organizations * Separated from other concerns for better SRP */ import { useMemo } from 'react'; import type { Organization } from '@/types.ts'; import { useAnalyzeSymbiosis, useGetWebIntelligence } from '@/hooks/useGemini.ts'; import { useOrganizations } from '@/hooks/useOrganizations.ts'; import { useTranslation } from '@/hooks/useI18n.tsx'; export const useOrganizationAI = (organization: Organization | undefined) => { const { organizations } = useOrganizations(); const { t } = useTranslation(); const { data: symbiosisResult, isPending: isAnalyzing, error: analysisError, refetch: analyzeSymbiosis, } = useAnalyzeSymbiosis(organization!, organizations, t); const { data: webIntelResult, isPending: isFetchingWebIntel, error: webIntelError, refetch: fetchWebIntelligence, } = useGetWebIntelligence(organization?.Name, t); const symbiosisState = useMemo( () => ({ symbiosisResult, isAnalyzing, analysisError: analysisError?.message || null, webIntelResult, isFetchingWebIntel, webIntelError: webIntelError?.message || null, }), [symbiosisResult, isAnalyzing, analysisError, webIntelResult, isFetchingWebIntel, webIntelError] ); return { symbiosisState, handleAnalyzeSymbiosis: analyzeSymbiosis, handleFetchWebIntelligence: fetchWebIntelligence, }; };