import { useEffect, useMemo, useState } from 'react' import { ChevronLeft, ChevronRight } from 'lucide-react' import { useTranslation } from 'react-i18next' import { Button } from '@/components/ui/button' import { DEFAULT_PRICING_PAGE_SIZE, DEFAULT_TOKEN_UNIT } from '../constants' import type { PricingModel, TokenUnit } from '../types' import { ModelCard } from './model-card' export interface ModelCardGridProps { models: PricingModel[] onModelClick: (modelName: string) => void priceRate?: number usdExchangeRate?: number tokenUnit?: TokenUnit showRechargePrice?: boolean } export function ModelCardGrid(props: ModelCardGridProps) { const { t } = useTranslation() const [page, setPage] = useState(1) const pageSize = DEFAULT_PRICING_PAGE_SIZE const tokenUnit = props.tokenUnit ?? DEFAULT_TOKEN_UNIT const totalPages = Math.max(1, Math.ceil(props.models.length / pageSize)) useEffect(() => { setPage(1) }, [props.models]) const pagedModels = useMemo(() => { const start = (page - 1) * pageSize return props.models.slice(start, start + pageSize) }, [page, pageSize, props.models]) if (props.models.length === 0) { return null } return (
{t('Page {{current}} of {{total}}', { current: page, total: totalPages, })}