import { Accordion, Card, Container, Grid, Stack, Text, TextInput, Title, } from "@mantine/core"; import { ListChangedIndicator } from "../../elements/ListChangedIndicator/ListChangedIndicator"; import { ResourceListItem } from "../../groups/ResourceListItem/ResourceListItem"; import { ResourcePreviewPanel } from "../../groups/ResourcePreviewPanel/ResourcePreviewPanel"; import { ResourceTemplateInput } from "../../groups/ResourceTemplateInput/ResourceTemplateInput"; import type { ResourceListItemProps } from "../../groups/ResourceListItem/ResourceListItem"; import type { ResourcePreviewPanelProps } from "../../groups/ResourcePreviewPanel/ResourcePreviewPanel"; import type { ResourceTemplateInputProps } from "../../groups/ResourceTemplateInput/ResourceTemplateInput"; export interface SubscriptionInfo { name: string; lastUpdated?: string; } export interface ResourcesScreenProps { resources: ResourceListItemProps[]; templates: ResourceTemplateInputProps[]; subscriptions: SubscriptionInfo[]; selectedResource?: ResourcePreviewPanelProps; listChanged: boolean; searchText: string; onSearchChange: (text: string) => void; onRefreshList: () => void; onSelectResource: (uri: string) => void; } const PageContainer = Container.withProps({ size: "xl", py: "xl", }); const FullHeightCard = Card.withProps({ withBorder: true, padding: "lg", h: "100%", }); const DetailCard = Card.withProps({ withBorder: true, padding: "lg", }); const EmptyState = Text.withProps({ c: "dimmed", ta: "center", py: "xl", }); const SubscriptionMeta = Text.withProps({ span: true, c: "dimmed", size: "xs", }); function formatSectionCount(label: string, count: number): string { return `${label} (${count})`; } function formatLastUpdated(lastUpdated: string): string { return ` — ${lastUpdated}`; } export function ResourcesScreen({ resources, templates, subscriptions, selectedResource, listChanged, searchText, onSearchChange, onRefreshList, }: ResourcesScreenProps) { const filteredResources = resources.filter((r) => r.name.toLowerCase().includes(searchText.toLowerCase()), ); const openSections = [ ...(filteredResources.length > 0 ? ["resources"] : []), ...(templates.length > 0 ? ["templates"] : []), ...(subscriptions.length > 0 ? ["subscriptions"] : []), ]; return ( Resources onSearchChange(e.currentTarget.value)} /> {formatSectionCount("URIs", filteredResources.length)} {filteredResources.map((resource) => ( ))} {formatSectionCount("Templates", templates.length)} {templates.map((template) => ( ))} {formatSectionCount("Subscriptions", subscriptions.length)} {subscriptions.map((sub) => ( {sub.name} {sub.lastUpdated && ( {formatLastUpdated(sub.lastUpdated)} )} ))} {selectedResource ? ( ) : ( Select a resource to preview )} ); }