import React, { useRef, useCallback, useEffect, useMemo, useState } from "react"; import { Carousel, Typography } from "antd"; import { TeamOutlined, BookOutlined, StarOutlined, LeftOutlined, RightOutlined, EyeOutlined, } from "@ant-design/icons"; import type { CarouselRef } from "antd/es/carousel"; import { useAppConfig } from "@nice/client"; const { Title, Text } = Typography; interface CarouselItem { title: string; desc: string; image: string; action: string; color: string; } interface PlatformStat { icon: React.ReactNode; value: number; label: string; } const HeroSection = () => { const carouselRef = useRef(null); const { statistics, slides } = useAppConfig(); const [countStatistics, setCountStatistics] = useState(0) const platformStats: PlatformStat[] = useMemo(() => { return [ { icon: , value: statistics.staffs, label: "注册学员" }, { icon: , value: statistics.courses, label: "精品课程" }, { icon: , value: statistics.lectures, label: '课程章节' }, { icon: , value: statistics.reads, label: "观看次数" }, ]; }, [statistics]); const handlePrev = useCallback(() => { carouselRef.current?.prev(); }, []); const handleNext = useCallback(() => { carouselRef.current?.next(); }, []); const countNonZeroValues = (statistics: Record): number => { return Object.values(statistics).filter(value => value !== 0).length; }; useEffect(() => { const count = countNonZeroValues(statistics); console.log(count); setCountStatistics(count); }, [statistics]); return (
{Array.isArray(slides) ? (slides.map((item, index) => (
{/*
*/}
{/* Content Container */}
)) ) : (
)} {/* Navigation Buttons */}
{/* Stats Container */} { countStatistics > 1 && (
{platformStats.map((stat, index) => { return stat.value ? (
{stat.icon}
{stat.value}
{stat.label}
) : null })}
) }
); }; export default HeroSection;