'use client'; import { useState } from 'react'; import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'; import { Sparkles, Link, Loader2 } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; import { apiFetch } from '@/lib/api/client'; interface Recommendation { id: string; berthId: string; matchScore: string | null; matchReasons: Record | null; source: string; mooringNumber: string; area: string | null; status: string; lengthFt: string | null; widthFt: string | null; draftFt: string | null; } interface RecommendationListProps { interestId: string; } export function RecommendationList({ interestId }: RecommendationListProps) { const queryClient = useQueryClient(); const { data, isLoading } = useQuery<{ data: Recommendation[] }>({ queryKey: ['interest-recommendations', interestId], queryFn: () => apiFetch(`/api/v1/interests/${interestId}/recommendations`), }); const generateMutation = useMutation({ mutationFn: () => apiFetch(`/api/v1/interests/${interestId}/recommendations/generate`, { method: 'POST', }), onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['interest-recommendations', interestId] }); }, }); const recommendations = data?.data ?? []; return (

AI-scored berth recommendations based on yacht dimensions.

{isLoading ? (
{[...Array(3)].map((_, i) => (
))}
) : recommendations.length === 0 ? (

No recommendations yet. Click "Generate Recommendations" to get started.

) : (
{recommendations.map((rec) => { const score = rec.matchScore ? Math.round(parseFloat(rec.matchScore)) : 0; return (
{rec.mooringNumber} {rec.area && ( {rec.area} )} {rec.source === 'ai' ? 'AI' : 'Manual'}
{rec.matchScore && (
{score}%
)} {(rec.lengthFt || rec.widthFt) && (

{rec.lengthFt && `${rec.lengthFt}ft length`} {rec.lengthFt && rec.widthFt && ' ยท '} {rec.widthFt && `${rec.widthFt}ft beam`}

)}
); })}
)}
); }