import { InventoryStatusCounts } from './InventoryStatusCounts'; import { inventorySelection, type InventoryDisplayGroup } from './inventory-presentation'; import type { InventoryFilters } from '../../model'; import type { RegionalInventoryStats } from '../../types'; import { inventorySubtotalSelection } from './inventory-presentation'; import React from 'react'; import { ChevronDown, ChevronRight } from 'lucide-react'; import { AnimatePresence, motion } from 'motion/react'; import type { InventoryStatisticsSectionProps } from './types'; type InventoryDesktopTableProps = Pick< InventoryStatisticsSectionProps, | 'inventoryTab' | 'inventoryByRegion' | 'expandedInventoryRegions' | 'toggleInventoryRegion' | 'inventoryByModel' | 'expandedInventoryTypes' | 'toggleInventoryType' | 'setVehicleSelection' >; export function InventoryDesktopTable({ inventoryTab, inventoryByRegion, expandedInventoryRegions, toggleInventoryRegion, inventoryByModel, expandedInventoryTypes, toggleInventoryType, setVehicleSelection: setShowPlateNumbers, }: InventoryDesktopTableProps) { return (
{inventoryTab === 'region' ? ( Object.entries(inventoryByRegion).map(([region, cities]) => ( toggleInventoryRegion(region)} > {expandedInventoryRegions.has(region) && Object.entries(cities).map(([city, stats]) => ( {stats.map((stat, idx) => ( ))} ))} )) ) : ( Object.entries(inventoryByModel).map(([type, models]) => ( toggleInventoryType(type)} > {expandedInventoryTypes.has(type) && Object.entries(models).map(([model, stats]) => ( {stats.map((stat, idx) => ( ))} ))} )) )}
{inventoryTab === 'region' ? '区域 / 城市' : '车型分类 / 型号'} {inventoryTab === 'region' ? '品牌' : '品牌'} {inventoryTab === 'region' ? '车型' : '所在区域/城市'} 库存数量
{expandedInventoryRegions.has(region) ? : } {region} { e.stopPropagation(); setShowPlateNumbers(inventorySubtotalSelection(Object.values(cities).flat(), `库存统计 - ${region}`)); }}> (共 {Object.values(cities).flat().reduce((acc, s) => acc + s.quantity, 0)} 台)
{idx === 0 ? {city} : ''} {stat.brand} {stat.model} {((stat.pending ?? 0) > 0 || (stat.abnormal ?? 0) > 0) && (
)}
{expandedInventoryTypes.has(type) ? : } {type} { e.stopPropagation(); setShowPlateNumbers(inventorySubtotalSelection(Object.values(models).flat(), `库存统计 - ${type}`)); }}> (共 {Object.values(models).flat().reduce((acc, s) => acc + s.quantity, 0)} 台)
{idx === 0 ? {model} : ''} {stat.brand} {stat.region} / {stat.city} {((stat.pending ?? 0) > 0 || (stat.abnormal ?? 0) > 0) && (
)}
); } export function selectInventoryRow(row: RegionalInventoryStats, select: InventoryStatisticsSectionProps['setVehicleSelection']) { select(inventorySelection(row, `库存统计 · ${row.city} · ${row.model}`, { vehicleType: row.type })); } export function selectInventoryGroup(group: InventoryDisplayGroup, { tab, filters, select }: { tab: 'region' | 'model'; filters: InventoryFilters; select: InventoryStatisticsSectionProps['setVehicleSelection'] }) { select(inventorySelection(tab === 'model' ? { ...filters, type: group.name } : filters, `库存统计 · ${group.name}`, tab === 'region' ? { location: filters.city || group.name } : {})); }