'use client' import { useState } from 'react' import Link from 'next/link' import { SearchResultItem } from '@/lib/types' import { displayUrlName } from '@/lib/utils/domain' import { faviconUrl } from '@/lib/utils/favicon' import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar' import { Button } from '@/components/ui/button' import { Card, CardContent } from '@/components/ui/card' export interface SearchResultsProps { results: SearchResultItem[] displayMode?: 'grid' | 'list' } export function SearchResults({ results, displayMode = 'grid' }: SearchResultsProps) { // State to manage whether to display the results const [showAllResults, setShowAllResults] = useState(false) const handleViewMore = () => { setShowAllResults(true) } // Logic for grid mode const displayedGridResults = showAllResults ? results : results.slice(0, 3) const additionalResultsCount = results.length > 3 ? results.length - 3 : 0 // --- List Mode Rendering --- if (displayMode === 'list') { return (
{results.map((result, index) => ( {new URL(result.url).hostname[0]}

{result.title || new URL(result.url).pathname}

{result.content}

{new URL(result.url).hostname}
))}
) } // --- Grid Mode Rendering (Existing Logic) --- return (
{displayedGridResults.map((result, index) => (

{result.title || result.content}

{new URL(result.url).hostname[0]}
{displayUrlName(result.url)}
))} {!showAllResults && additionalResultsCount > 0 && ( <>
)}
) }