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, slideLinks = [] } = useAppConfig(); const [countStatistics, setCountStatistics] = useState(4); 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) => (
{ // slideLinks?.[index]; }} className="absolute inset-0 bg-cover bg-center transform transition-[transform,filter] duration-[2000ms] group-hover:scale-105 group-hover:brightness-110 will-change-[transform,filter]" style={{ //backgroundImage: `url(https://s.cn.bing.net/th?id=OHR.GiantCuttlefish_ZH-CN0670915878_1920x1080.webp&qlt=50)`, backgroundImage: `url(${item})`, backfaceVisibility: "hidden", }} /> {/*
*/}
{/* 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;