// useChildSwitcher：子女切换 Hook
// 依据：02-architecture-design.md §4.3 状态管理分层、ISSUE-009 纯前端切换
// - 封装 Zustand store，提供派生数据（currentChild / hasMultipleChildren）
// - 切换是纯前端操作，不调后端（ISSUE-009）
// - 自动加载子女列表（useMyChildren）

"use client";

import { useChildStore } from "@/store/child-store";
import { useMyChildren } from "./useMyChildren";

export function useChildSwitcher() {
  const { children, loading, error } = useMyChildren();

  const currentChildId = useChildStore((s) => s.currentChildId);
  const switchChild = useChildStore((s) => s.switchChild);

  const currentChild = children.find((c) => c.id === currentChildId) ?? null;
  const hasMultipleChildren = children.filter((c) => !c.isArchived).length > 1;

  return {
    children,
    currentChild,
    currentChildId,
    switchChild,
    loading,
    error,
    hasMultipleChildren,
  };
}
