"use client" import { useRef, useState } from "react" import Image from "next/image" import { Card, CardContent } from "@/components/ui/card" import { Button } from "@/components/ui/button" import { ChevronLeft, ChevronRight, Info } from "lucide-react" import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip" export default function RobotsShowcase() { const scrollContainerRef = useRef(null) const [showLeftArrow, setShowLeftArrow] = useState(false) const [showRightArrow, setShowRightArrow] = useState(true) const [activeIndex, setActiveIndex] = useState(0) const robots = [ { id: 1, name: "初号步兵", image: "/placeholder.svg?height=400&width=600", category: "INFANTRY", description: "Our flagship defense robot, equipped with advanced armor plating and a 360° rotating turret system.", specs: ["Weight: 15kg", "Max Speed: 3m/s", "Battery Life: 30min", "Weapon: Launcher"], }, { id: 2, name: "初号英雄", image: "/placeholder.svg?height=400&width=600", category: "HERO", description: "High-mobility attack unit designed for rapid engagement and strategic positioning.", specs: ["Weight: 12kg", "Max Speed: 4.5m/s", "Battery Life: 25min", "Weapon: Dual Launcher System"], }, { id: 3, name: "零号哨兵", image: "/placeholder.svg?height=400&width=600", category: "SENTRY", description: "Lightweight reconnaissance drone providing battlefield intelligence and limited attack capabilities.", specs: ["Weight: 2kg", "Max Speed: 10m/s", "Flight Time: 15min", "Sensors: 4K Camera, Infrared"], }, { id: 4, name: "零号工程", image: "/placeholder.svg?height=400&width=600", category: "ENGINEER", description: "Specialized support unit capable of on-field repairs and resource management during matches.", specs: ["Weight: 18kg", "Max Speed: 2m/s", "Battery Life: 40min", "Tools: Mechanical Arm, Repair Module"], }, ] const scroll = (direction: "left" | "right") => { if (scrollContainerRef.current) { const { current: container } = scrollContainerRef const scrollAmount = container.clientWidth * 0.8 const cardWidth = container.querySelector(".card-hover-effect")?.clientWidth || 0 const gap = 24 // 6 * 4px (gap-6) if (direction === "left") { container.scrollBy({ left: -scrollAmount, behavior: "smooth" }) setActiveIndex((prev) => (prev === 0 ? robots.length - 1 : prev - 1)) } else { container.scrollBy({ left: scrollAmount, behavior: "smooth" }) setActiveIndex((prev) => (prev === robots.length - 1 ? 0 : prev + 1)) } // 检查是否需要无限滚动 setTimeout(() => { if (container) { // 如果滚动到最左边(克隆的最后一个元素) if (container.scrollLeft < cardWidth / 2) { // 无动画地跳到真正的最后一组元素 container.scrollTo({ left: container.scrollWidth - cardWidth * 2, behavior: "auto", }) } // 如果滚动到最右边(克隆的第一个元素) else if (container.scrollLeft > container.scrollWidth - cardWidth * 1.5) { // 无动画地跳到真正的第一组元素 container.scrollTo({ left: cardWidth, behavior: "auto", }) } setShowLeftArrow(container.scrollLeft > 0) setShowRightArrow(container.scrollLeft < container.scrollWidth - container.clientWidth - 10) } }, 500) } } const handleScroll = () => { if (scrollContainerRef.current) { const { current: container } = scrollContainerRef const cardWidth = container.querySelector(".card-hover-effect")?.clientWidth || 0 const gap = 24 // 6 * 4px (gap-6) // 计算当前查看的卡片索引 const scrollPosition = container.scrollLeft const itemWidth = cardWidth + gap const index = Math.round(scrollPosition / itemWidth) - 1 // -1 因为有一个克隆元素在开头 if (index >= 0 && index < robots.length) { setActiveIndex(index) } setShowLeftArrow(container.scrollLeft > 0) setShowRightArrow(container.scrollLeft < container.scrollWidth - container.clientWidth - 10) } } return (

机器人

ROBOTS

探索我们为 RoboMaster 竞赛设计的尖端机器人,每款机器人都针对赛场上的特定战术角色而设计。

{showLeftArrow && ( )}
{/* 添加末尾项到开头 */}
{robots[robots.length
{robots[robots.length - 1].category}

{`0${robots.length}/0${robots.length}`}

{robots[robots.length - 1].name}

Technical Specifications:

    {robots[robots.length - 1].specs.map((spec, index) => (
  • {spec}
  • ))}

{robots[robots.length - 1].description}

{robots.map((robot, index) => ( setActiveIndex(index)} >
{robot.name}
{robot.category}

{`0${index + 1}/0${robots.length}`}

{robot.name}

Technical Specifications:

    {robot.specs.map((spec, index) => (
  • {spec}
  • ))}

{robot.description}

))} {/* 添加开头项到末尾 */}
{robots[0].name}
{robots[0].category}

{`01/0${robots.length}`}

{robots[0].name}

技术参数:

    {robots[0].specs.map((spec, index) => (
  • {spec}
  • ))}

{robots[0].description}

{showRightArrow && ( )} {/* 添加索引指示器 */}
{robots.map((_, index) => (
) }