/**
 * Phase 2: 文献切换器（用于逐篇精读模式）
 */

import { Document } from '../../types/index'
import './DocumentSwitcher.css'

interface DocumentSwitcherProps {
  currentDoc: Document | undefined
  selectedDocs: Document[]
  onSwitch: (docId: string) => void
}

export function DocumentSwitcher({
  currentDoc,
  selectedDocs,
  onSwitch,
}: DocumentSwitcherProps) {
  if (!currentDoc || selectedDocs.length === 0) {
    return null
  }

  return (
    <div className="doc-switcher">
      <div className="doc-switcher-header">
        <span className="current-doc-label">当前文献：</span>
        <span className="current-doc-name">{currentDoc.filename}</span>
      </div>

      {selectedDocs.length > 1 && (
        <div className="doc-switcher-list">
          {selectedDocs.map(doc => (
            <button
              key={doc.id}
              className={`doc-switch-btn ${doc.id === currentDoc.id ? 'active' : ''}`}
              onClick={() => onSwitch(doc.id)}
              title={doc.filename}
            >
              <span className="doc-indicator">
                {doc.id === currentDoc.id ? '●' : '○'}
              </span>
              <span className="doc-btn-name">{doc.filename}</span>
              {doc.tokensCount && (
                <span className="doc-btn-tokens">
                  {Math.round(doc.tokensCount / 1000)}K
                </span>
              )}
            </button>
          ))}
        </div>
      )}
    </div>
  )
}






