"use client"; import { useState, useEffect } from "react"; import { useLookupApplications, LookupApp } from "@/lib/api"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/Card"; import { Loader2, Search, AppWindow, HelpCircle, ChevronLeft, ChevronRight, ChevronsLeft, ChevronsRight } from "lucide-react"; export default function LookupPage() { const [mounted, setMounted] = useState(false); const [searchQuery, setSearchQuery] = useState(""); const [debouncedSearch, setDebouncedSearch] = useState(""); const [page, setPage] = useState(1); const limit = 24; // 24 items per page fits a 2, 3, or 4 column grid perfectly useEffect(() => { setMounted(true); }, []); // Debounce search query input to avoid spamming requests useEffect(() => { const handler = setTimeout(() => { setDebouncedSearch(searchQuery); setPage(1); // Reset page on new search }, 400); return () => clearTimeout(handler); }, [searchQuery]); const { data, isLoading, error } = useLookupApplications(page, limit, debouncedSearch); if (!mounted) return null; const applications = data?.applications || []; const pagination = data?.pagination || { total_records: 0, total_pages: 1, current_page: 1 }; return (

Application Database {isLoading && }

Search BackOne's extensive classification database of over 2,500+ apps, protocols, and services.

{/* Search Input Bar */}
setSearchQuery(e.target.value)} />
{/* Cards Grid */} {error ? (

Failed to load application lookup database

{error.message}

) : applications.length === 0 && !isLoading ? (

No applications found

Try refining your search keyword or clearing the input.

) : (
{applications.map((app: LookupApp) => (
{/* Top: Icon + Title */}
{app.favicon || app.logo ? ( {app.label} { // If image fails, replace with default icon (e.target as HTMLElement).style.display = 'none'; }} /> ) : ( )}
{app.application_category?.label || "Unclassified"}

{app.label}

{app.tag}

{app.description || "No description provided for this application definition."}

{/* Bottom: ID and system information */}
ID: {app.id} {app.name || "N/A"}
))}
{/* Pagination Controls */} {pagination.total_pages > 1 && (
Showing {((page - 1) * limit) + 1} to{" "} {Math.min(page * limit, pagination.total_records)} {" "} of {pagination.total_records} entries
{/* First Page */} {/* Prev Page */} {/* Page indicators */} {page} / {pagination.total_pages} {/* Next Page */} {/* Last Page */}
)}
)}
); }