from PySide6.QtWidgets import QWidget, QLabel, QVBoxLayout, QGridLayout
from PySide6.QtCore import Qt

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

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

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

        # Metrics Grid
        metrics_grid = QGridLayout()
        metrics_grid.setSpacing(15)

        # Account Balance
        self.account_balance_label = self._create_metric_label("Account Balance:", "$100,000.00")
        metrics_grid.addWidget(self.account_balance_label[0], 0, 0)
        metrics_grid.addWidget(self.account_balance_label[1], 0, 1)

        # Today's P&L
        self.pnl_label = self._create_metric_label("Today's P&L:", "+$500.00 (0.5%)")
        metrics_grid.addWidget(self.pnl_label[0], 1, 0)
        metrics_grid.addWidget(self.pnl_label[1], 1, 1)

        # Open Positions
        self.open_positions_label = self._create_metric_label("Open Positions:", "5")
        metrics_grid.addWidget(self.open_positions_label[0], 2, 0)
        metrics_grid.addWidget(self.open_positions_label[1], 2, 1)

        # Pending Orders
        self.pending_orders_label = self._create_metric_label("Pending Orders:", "2")
        metrics_grid.addWidget(self.pending_orders_label[0], 3, 0)
        metrics_grid.addWidget(self.pending_orders_label[1], 3, 1)

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

    def _create_metric_label(self, title, value):
        title_label = QLabel(title)
        title_label.setStyleSheet("font-weight: bold;")
        value_label = QLabel(value)
        return title_label, value_label