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 { api, useAppConfig } from "@nice/client"; import { useNavigate } from "react-router-dom"; interface PlatformStat { icon: React.ReactNode; value: number; label: string; } const HeroSection = () => { const carouselRef = useRef(null); const { statistics, slides, slideLinks = [] } = useAppConfig(); const [countStatistics, setCountStatistics] = useState(4); const navigator = useNavigate() 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) => (
{ if(slideLinks?.[index])window.open(slideLinks?.[index],"_blank") }} >
{/*
*/}
{/* 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;