import sys
import sqlite3
from PyQt5.QtWidgets import   QApplication, QMainWindow, QVBoxLayout, QWidget, QLabel, QTableWidget, QTableWidgetItem
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPixmap, QFont, QIcon
class MainReportLocal(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setWindowTitle(" Em Reports")
        self.setGeometry(100, 100, 1000, 600)
        self.setWindowIcon(QIcon('ixo.png'))

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

        self.layout = QVBoxLayout(self.central_widget)

        self.title = QLabel("Report Local", self)
        self.title.setAlignment(Qt.AlignCenter)
        self.title.setStyleSheet("font-size: 24px; font-weight: bold;")
        self.layout.addWidget(self.title)

        self.table = QTableWidget(self)
        self.layout.addWidget(self.table)

        self.load_data()

    def load_data(self):
        connection = sqlite3.connect('reports.db')
        cursor = connection.cursor()

        cursor.execute("SELECT * FROM reports")
        records = cursor.fetchall()

        self.table.setRowCount(len(records))
        self.table.setColumnCount(9)
        self.table.setHorizontalHeaderLabels(["ID", "Timestamp", "Screenshot File", "Active Project", "Active Task", "Mouse Clicks", "Keyboard Clicks","App Name","Tab Title"])

        for row_index, row_data in enumerate(records):
            for column_index, column_data in enumerate(row_data):
                self.table.setItem(row_index, column_index, QTableWidgetItem(str(column_data)))

        connection.close()

if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = MainReportLocal()
    window.show()
    sys.exit(app.exec_())
