/**
 * DiffView + EvidenceView - Render diffs and link to artifacts/evidence
 * Code-view §7 rule 5: link back to artifact/evidence refs.
 *
 * @module packages/tui/src/components/DiffView
 */

export interface DiffViewProps {
  file: string
  diff_content: string
  artifact_refs?: string[]
  evidence_refs?: string[]
}

export function DiffView({ file, diff_content, artifact_refs, evidence_refs }: DiffViewProps): string {
  const lines: string[] = [`Diff: ${file}`, '']

  const diff_lines = diff_content.split('\n')
  for (const line of diff_lines.slice(0, 50)) { // Cap at 50 lines
    if (line.startsWith('+')) lines.push(`  \x1b[32m${line}\x1b[0m`)
    else if (line.startsWith('-')) lines.push(`  \x1b[31m${line}\x1b[0m`)
    else lines.push(`  ${line}`)
  }

  if (artifact_refs && artifact_refs.length > 0) {
    lines.push('', 'Artifacts:')
    for (const ref of artifact_refs) lines.push(`  📎 ${ref}`)
  }

  if (evidence_refs && evidence_refs.length > 0) {
    lines.push('', 'Evidence:')
    for (const ref of evidence_refs) lines.push(`  🔗 ${ref}`)
  }

  return lines.join('\n')
}

export interface EvidenceViewProps {
  entity_type: string
  entity_id: string
  evidence_kind: string
  filepath: string
}

export function EvidenceView({ entity_type, entity_id, evidence_kind, filepath }: EvidenceViewProps): string {
  return `Evidence: ${evidence_kind} for ${entity_type}/${entity_id}\n  Path: ${filepath}`
}
