import { Course } from "@nice/common";
import React, { useContext, useMemo } from "react";
import { Image, Typography, Skeleton } from "antd"; // 引入 antd 组件
import { CourseDetailContext } from "./CourseDetailContext";
import {
	CalendarOutlined,
	EyeOutlined,
	PlayCircleOutlined,
} from "@ant-design/icons";
import dayjs from "dayjs";
import { useNavigate } from "react-router-dom";

export const CourseDetailDescription: React.FC = () => {
	const { course, isLoading, selectedLectureId, setSelectedLectureId } =
		useContext(CourseDetailContext);
	const { Paragraph, Title } = Typography;
	const firstLectureId = useMemo(() => {
		return course?.sections?.[0]?.lectures?.[0]?.id;
	}, [course]);
	const navigate = useNavigate();
	return (
		<div className="w-full bg-white shadow-md rounded-lg border border-gray-200 p-6">
			{isLoading || !course ? (
				<Skeleton active paragraph={{ rows: 4 }} />
			) : (
				<div className="space-y-4">
					{!selectedLectureId && (
						<>
							<div className="relative  my-4 overflow-hidden flex justify-center items-center">
								<Image
									src={course?.meta?.thumbnail}
									preview={false}
									className="w-full h-full object-cover z-0"
								/>
								<div
									onClick={() => {
										setSelectedLectureId(firstLectureId);
									}}
									className="w-full h-full  absolute top-0 z-10 bg-black opacity-30 transition-opacity duration-300 ease-in-out hover:opacity-70 cursor-pointer">
									<PlayCircleOutlined className="absolute top-1/2  left-1/2 -translate-x-1/2 -translate-y-1/2 text-white text-4xl z-10" />
								</div>
							</div>
						</>
					)}
					<div className="text-lg font-bold">{"课程简介:"}</div>
					<div className="text-gray-600 flex justify-start gap-4">
						<div>{course?.subTitle}</div>
						<div className="flex gap-1">
							<EyeOutlined></EyeOutlined>
							<div>{course?.meta?.views || 0}</div>
						</div>
						<div className="flex gap-1">
							<CalendarOutlined></CalendarOutlined>
							{dayjs(course?.createdAt).format("YYYY年M月D日")}
						</div>
					</div>
					<Paragraph
						className="text-gray-600"
						ellipsis={{
							rows: 3,
							expandable: true,
							symbol: "展开",
							onExpand: () => console.log("展开"),
						}}>
						{course?.content}
					</Paragraph>
				</div>
			)}
		</div>
	);
};
