import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { KeywordBadge } from '@/components/ui/keyword-badge'; import { router } from '@inertiajs/react'; import { Search } from 'lucide-react'; import { useState } from 'react'; import { route } from 'ziggy-js'; const MemeLibrarySearch = ({ popularKeywords = [] }) => { const [searchQuery, setSearchQuery] = useState(''); const [isSearching, setIsSearching] = useState(false); const handleSearch = (e) => { e.preventDefault(); if (!searchQuery.trim()) { // If empty search, go to main meme library router.visit(route('memes.index')); return; } setIsSearching(true); // Navigate to search results page router.visit(route('memes.search', { search: searchQuery.trim() }), { onFinish: () => setIsSearching(false), }); }; const handleKeyPress = (e) => { if (e.key === 'Enter') { handleSearch(e); } }; const handleKeywordClick = (keyword) => { setSearchQuery(keyword); setIsSearching(true); router.visit(route('memes.search', { search: keyword }), { onFinish: () => setIsSearching(false), }); }; return (
{/* Section heading */}

Find the perfect meme

Search through our database of popular meme templates and find the perfect one for your video

{/* Search form */}
setSearchQuery(e.target.value)} onKeyPress={handleKeyPress} className="h-12 py-3 pr-4 pl-10 text-base" disabled={isSearching} />
{/* Popular Keywords */} {popularKeywords.length > 0 && (
{popularKeywords.map((keyword, index) => ( handleKeywordClick(keyword)} disabled={isSearching} /> ))}
)} {/* Browse all link */}
); }; export default MemeLibrarySearch;