from PySide6.QtWidgets import QWidget, QLabel, QVBoxLayout, QTableWidget, QTableWidgetItem, QHeaderView
from PySide6.QtCore import Qt

class OrdersPanel(QWidget):
    def __init__(self):
        super().__init__()
        self.init_ui()

    def init_ui(self):
        layout = QVBoxLayout(self)

        # Title
        title_label = QLabel("Orders")
        title_label.setAlignment(Qt.AlignCenter)
        title_label.setStyleSheet("font-size: 24px; font-weight: bold; margin-bottom: 20px;")
        layout.addWidget(title_label)

        self.orders_table = QTableWidget()
        self.orders_table.setColumnCount(8)
        self.orders_table.setHorizontalHeaderLabels(["Order ID", "Symbol", "Type", "Side", "Quantity", "Price", "Status", "Timestamp"])
        self.orders_table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
        layout.addWidget(self.orders_table)

        layout.addStretch(1) # Pushes content to the top
        self.setLayout(layout)

    def add_order(self, order_id, symbol, order_type, side, quantity, price, status, timestamp):
        row_position = self.orders_table.rowCount()
        self.orders_table.insertRow(row_position)
        self.orders_table.setItem(row_position, 0, QTableWidgetItem(str(order_id)))
        self.orders_table.setItem(row_position, 1, QTableWidgetItem(symbol))
        self.orders_table.setItem(row_position, 2, QTableWidgetItem(order_type))
        self.orders_table.setItem(row_position, 3, QTableWidgetItem(side))
        self.orders_table.setItem(row_position, 4, QTableWidgetItem(str(quantity)))
        self.orders_table.setItem(row_position, 5, QTableWidgetItem(str(price)))
        self.orders_table.setItem(row_position, 6, QTableWidgetItem(status))
        self.orders_table.setItem(row_position, 7, QTableWidgetItem(str(timestamp)))