LintModal.tsx 3.27 KB
"use client";

import type { RefObject } from "react";
import { ShieldCheck, CheckCircle2, X } from "lucide-react";

import { MessageBubble, type ReasoningStep } from "@/components/MessageBubble";

/** Lint 对话消息:与父级 lintHistory 的元素结构一致。 */
export interface LintMessage {
  role: "user" | "ai";
  content: string;
  reasoning?: ReasoningStep[];
  startTime?: number;
  endTime?: number;
}

/**
 * Wiki 健康检查(Lint)弹窗(纯展示)。
 *
 * 扫描过程由父级的 handleLint 驱动并流式写入 lintHistory,
 * 这里只渲染对话与扫描状态;末尾 ref 交给父级做自动滚底。
 */
export interface LintModalProps {
  open: boolean;
  onClose: () => void;
  /** 扫描中:末条消息显示流式态,标题区显示脉冲提示 */
  isLinting: boolean;
  lintHistory: LintMessage[];
  /** 列表末尾锚点,父级据此滚动到底部 */
  lintEndRef: RefObject<HTMLDivElement | null>;
}

export const LintModal = ({ open, onClose, isLinting, lintHistory, lintEndRef }: LintModalProps) => {
  if (!open) return null;

  return (
    <div className="fixed inset-0 z-50 flex items-center justify-center bg-slate-900/40 backdrop-blur-sm p-8 animate-in fade-in duration-200">
      <div className="bg-slate-50 w-full max-w-4xl h-[80vh] rounded-3xl shadow-2xl flex flex-col overflow-hidden border border-slate-200/50">
        <div className="h-16 px-6 bg-white border-b border-slate-100 flex items-center justify-between shrink-0">
          <div className="flex items-center gap-3">
            <div className="w-10 h-10 bg-emerald-100 rounded-xl flex items-center justify-center">
              <ShieldCheck className="w-5 h-5 text-emerald-600" />
            </div>
            <div>
              <h3 className="font-bold text-sm text-slate-800">Wiki 健康检查 (Lint)</h3>
              <div className="flex items-center gap-1.5">
                {isLinting ? (
                  <>
                    <div className="w-1.5 h-1.5 bg-emerald-400 rounded-full animate-pulse" />
                    <span className="text-[10px] text-slate-500 font-medium tracking-wider">正在扫描知识库...</span>
                  </>
                ) : (
                  <>
                    <CheckCircle2 className="w-3 h-3 text-emerald-500" />
                    <span className="text-[10px] text-slate-500 font-medium tracking-wider">扫描完成</span>
                  </>
                )}
              </div>
            </div>
          </div>
          <button
            onClick={onClose}
            className="p-2 hover:bg-slate-100 rounded-lg transition-colors text-slate-400 hover:text-slate-800"
          >
            <X className="w-5 h-5" />
          </button>
        </div>

        <div className="flex-1 overflow-y-auto p-6 scrollbar-thin bg-white/50 flex flex-col">
          {lintHistory.map((msg, idx) => (
            <MessageBubble
              key={idx}
              role={msg.role}
              content={msg.content}
              reasoning={msg.reasoning}
              isStreaming={isLinting && idx === lintHistory.length - 1}
              startTime={msg.startTime}
              endTime={msg.endTime}
            />
          ))}
          <div ref={lintEndRef} />
        </div>
      </div>
    </div>
  );
};

export default LintModal;