// ParentDashboard：仪表盘复合组件
// 依据：02-architecture-design.md §15 仪表盘设计
// - 组合 ChildSummaryCard + AttendanceCalendar
// - 处理加载/错误状态
// - 依赖 currentChildId（切换子女时重新加载）

"use client";

import { useChildSummary } from "@/hooks/useChildSummary";
import { useChildAttendance } from "@/hooks/useChildAttendance";
import { useChildSwitcher } from "@/hooks/useChildSwitcher";
import { ChildSummaryCard } from "./ChildSummaryCard";
import { AttendanceCalendar } from "./AttendanceCalendar";

export function ParentDashboard() {
  const { currentChild } = useChildSwitcher();
  const {
    summary,
    loading: summaryLoading,
    error: summaryError,
  } = useChildSummary();
  const { attendance, loading: attLoading } = useChildAttendance();

  if (summaryLoading && !summary) {
    return (
      <div className="space-y-4">
        <span className="skeleton h-8 w-full rounded" />
        <span className="skeleton h-32 w-full rounded" />
        <span className="skeleton h-48 w-full rounded" />
      </div>
    );
  }

  if (summaryError) {
    return (
      <div className="rounded border border-danger p-4 text-sm text-danger">
        加载失败：{summaryError.message}
      </div>
    );
  }

  if (!summary || !currentChild) {
    return null;
  }

  return (
    <div className="space-y-6">
      <h1 className="font-serif text-2xl">{currentChild.name}的学习概览</h1>

      <ChildSummaryCard summary={summary} />

      {attLoading ? (
        <span className="skeleton h-64 w-full rounded" />
      ) : (
        <AttendanceCalendar records={attendance} />
      )}
    </div>
  );
}

export default ParentDashboard;
