<?php
declare(strict_types=1);

namespace App\Framework\SyntaxHighlighter;

use SplFileObject;

final readonly class FileHighlighter
{
    public function __invoke(string $filename, int $startLine, int $range):string
    {
        $file = new SplFileObject($filename);

        // Zu Zeile 9 springen (Index basiert auf 0, daher Zeile 10 = 9)
        $file->seek($startLine);

        $lines = [];
        for ($i = 0; $i < $range && !$file->eof(); $i++) {
            $lines[] = $file->current();
            $file->next();
        }

        $code = implode('', $lines);

        $highlighter = new SyntaxHighlighter();

        #echo "<style>$css</style>";
        return $highlighter->highlightFileSegment($code, $startLine);
    }
}
