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
from  langHandel import langHandel

class MainReportLocal(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setWindowTitle(" Em Reports")
        self.setGeometry(100, 100, 1000, 600)
        self.setWindowIcon(QIcon('ixo.png'))
        self.language = langHandel("report")
        self.central_widget = QWidget()
        self.setCentralWidget(self.central_widget)

        self.layout = QVBoxLayout(self.central_widget)

        self.title = QLabel(self.language.get_value( "reportsLocal"), 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()
        #self.setLayoutDirection(Qt.RightToLeft)

    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([self.language.get_value( "ID"), self.language.get_value( "dateRegistration"), self.language.get_value( "image"), self.language.get_value( "activeProject"), self.language.get_value( "activeTask"), self.language.get_value( "mouseClick"),self.language.get_value( "keyboardClick"),self.language.get_value( "app"),self.language.get_value( "tab")])

        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_())
