import requests
from PyQt6.QtGui import QFont
from PyQt6.QtWidgets import QMainWindow, QVBoxLayout, QWidget, QPlainTextEdit


class LogViewer(QMainWindow):
    def __init__(self, log_path):
        super().__init__()

        self.log_path = log_path
        self.setGeometry(100, 100, 600, 800)
        self.setWindowTitle("Log Output")

        self.text_edit = QPlainTextEdit(self)
        self.text_edit.setReadOnly(True)
        self.text_edit.setFont(QFont("Courier", 10))

        layout = QVBoxLayout()
        layout.addWidget(self.text_edit)
        layout.setContentsMargins(0, 0, 0, 0)

        central_widget = QWidget()
        central_widget.setLayout(layout)
        self.setCentralWidget(central_widget)

        self.fetch_logs()

    def fetch_logs(self):
        result = requests.get(self.log_path)
        self.text_edit.setPlainText(result.text)
