"use client";

import { useMemo, type ReactNode } from "react";
import {
  LessonPlanProvider,
  TEACHER_ROLE_CONFIG,
  type LessonPlanRoleConfig,
} from "./lesson-plan-provider";
import { createDefaultDataService } from "../services/default-data-service";
import { createDefaultQuestionService } from "../services/default-question-service";

/**
 * 备课模块 Provider 设置组件（V3 新增 / V4 P0-4 扩展）。
 * 在页面层包裹此组件，自动注入默认数据服务、角色配置和跨模块题目服务。
 * 组件通过 useLessonPlanContextSafe() / useQuestionService() 获取依赖，不直接 import actions。
 */
export function LessonPlanProviderSetup({
  children,
  roleConfig = TEACHER_ROLE_CONFIG,
}: {
  children: ReactNode;
  roleConfig?: LessonPlanRoleConfig;
}) {
  const service = useMemo(() => createDefaultDataService(), []);
  // V4 P0-4：注入跨模块题目服务，避免 question-bank-picker 直接 import questions 模块
  const questionService = useMemo(() => createDefaultQuestionService(), []);
  return (
    <LessonPlanProvider
      service={service}
      roleConfig={roleConfig}
      questionService={questionService}
    >
      {children}
    </LessonPlanProvider>
  );
}
