// (c) 2026 TWWIM UG. All rights reserved. (www.twwim.com) import { useState } from 'react'; import { Pencil, FileText, BookOpen } from 'lucide-react'; import { useTranslation } from '@/i18n/TranslationProvider'; import { ChunkEditModal } from './ChunkEditModal'; import type { PlaygroundSource } from '@archer/api-interface'; interface PlaygroundSourceRowProps { tenantId: string; source: PlaygroundSource; rank: number; onChange: () => void; } const TYPE_COLORS: Record = { PRODUCT: { bg: 'bg-blue-100', text: 'text-blue-800' }, PAGE: { bg: 'bg-green-100', text: 'text-green-800' }, DOCUMENT: { bg: 'bg-purple-100', text: 'text-purple-800' }, FAQ: { bg: 'bg-amber-100', text: 'text-amber-800' }, CUSTOM: { bg: 'bg-gray-100', text: 'text-gray-800' }, content: { bg: 'bg-cyan-100', text: 'text-cyan-800' }, }; const SOURCE_COLORS: Record = { WORDPRESS: { bg: 'bg-indigo-100', text: 'text-indigo-800' }, SHOPIFY: { bg: 'bg-green-100', text: 'text-green-800' }, MANUAL: { bg: 'bg-gray-100', text: 'text-gray-700' }, UPLOAD: { bg: 'bg-cyan-100', text: 'text-cyan-800' }, SCOUT: { bg: 'bg-orange-100', text: 'text-orange-800' }, }; function Badge({ label, colors }: { label: string; colors: { bg: string; text: string } }) { return ( {label} ); } export function PlaygroundSourceRow({ tenantId, source, rank, onChange }: PlaygroundSourceRowProps) { const { t } = useTranslation(); const [isEditing, setIsEditing] = useState(false); const isDocChunk = !!source.parentId; const headline = isDocChunk ? source.filename || t('knowledge.playground.docChunkLabel') : source.title || t('knowledge.playground.entryLabel'); const scorePct = Math.round(source.score * 100); const typeColors = TYPE_COLORS[source.type] ?? TYPE_COLORS.CUSTOM; const sourceColors = SOURCE_COLORS[source.source] ?? SOURCE_COLORS.MANUAL; return ( <>
[{rank}] {isDocChunk ? ( ) : ( )}
{headline} {isDocChunk && source.chunkIndex !== null && ( #{source.chunkIndex + 1} )} {source.type && } {source.source && } {t('knowledge.playground.scoreLabel')}: {scorePct}%

{source.snippet}

{isEditing && ( setIsEditing(false)} onSaved={onChange} /> )} ); }