"use client"

import { useKpDialogState } from "./use-kp-dialog-state"
import { useKpCrud } from "./use-kp-crud"

/**
 * 知识点操作 Hook（门面）。
 *
 * 组合 useKpDialogState（对话框状态）和 useKpCrud（CRUD 操作），
 * 对外保持原有 API 不变，避免调用方修改。
 */
export function useKnowledgePointActions(
  textbookId: string | undefined,
  selectedChapterId: string | null,
  selectedChapterTextbookId: string | undefined,
  highlightedKpId: string | null,
  setHighlightedKpId: (id: string | null) => void,
  onKpCreated?: () => void,
) {
  const dialog = useKpDialogState()

  const crud = useKpCrud({
    textbookId,
    selectedChapterId,
    selectedChapterTextbookId,
    highlightedKpId,
    setHighlightedKpId,
    onKpCreated,
    dialog,
  })

  return {
    editingKp: dialog.editingKp,
    setEditingKp: dialog.setEditingKp,
    editKpDialogOpen: dialog.editKpDialogOpen,
    setEditKpDialogOpen: dialog.setEditKpDialogOpen,
    isUpdatingKp: dialog.isUpdatingKp,
    questionDialogOpen: dialog.questionDialogOpen,
    setQuestionDialogOpen: dialog.setQuestionDialogOpen,
    targetKpForQuestion: dialog.targetKpForQuestion,
    setTargetKpForQuestion: dialog.setTargetKpForQuestion,
    deleteConfirmOpen: dialog.deleteConfirmOpen,
    setDeleteConfirmOpen: dialog.setDeleteConfirmOpen,
    handleCreateKnowledgePoint: crud.handleCreateKnowledgePoint,
    requestDeleteKnowledgePoint: crud.requestDeleteKnowledgePoint,
    confirmDeleteKnowledgePoint: crud.confirmDeleteKnowledgePoint,
    handleUpdateKnowledgePoint: crud.handleUpdateKnowledgePoint,
  }
}
