from PyQt6.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout, QFrame, QLabel, QTableWidget, 
                             QTableWidgetItem, QGroupBox, QTabWidget, QProgressBar, QPushButton, QSpacerItem, QSizePolicy)
from PyQt6.QtCore import Qt, QTimer
from PyQt6.QtGui import QColor, QFont, QMovie
import pyqtgraph as pg
from datetime import datetime
import numpy as np
import torch

# Cyberpunk color scheme
COLORS = {
    'background': '#141414',
    'text': '#00FFAA',
    'border': '#444444',
    'accent_green': '#00FFA3',  # Neon green
    'accent_purple': '#DC1FFF', # Neon purple
    'accent_blue': '#1F51FF',   # Neon blue
    'accent_pink': '#FF1493',   # Neon pink
    'grid_lines': '#1F1F1F',
    'plot_fill': '#1E1E2E'
}

# Define the style using Qt Style Sheets
STYLE = f"""
QMainWindow {{
    background-color: {COLORS['background']};
}}
QWidget {{
    font-family: 'Roboto', sans-serif;
    font-size: 14px;
    color: {COLORS['text']};
}}
QFrame {{
    background-color: {COLORS['background']};
    border: 2px solid {COLORS['border']};
    border-radius: 12px;
    padding: 10px;
    margin: 5px;
}}
QLabel {{
    color: {COLORS['text']};
    font-weight: bold;
    font-size: 15px;
}}
QPushButton {{
    background-color: {COLORS['accent_green']};
    border: none;
    padding: 10px;
    border-radius: 8px;
    color: {COLORS['text']};
    font-size: 15px;
    transition: background-color 0.3s;
}}
QPushButton:hover {{
    background-color: {COLORS['accent_purple']};
    color: {COLORS['text']};
}}
QTableWidget {{
    background-color: {COLORS['background']};
    border: 1px solid {COLORS['border']};
    color: {COLORS['text']};
}}
QHeaderView::section {{
    background-color: {COLORS['border']};
    color: {COLORS['accent_purple']};
    font-weight: bold;
}}
QProgressBar {{
    background-color: {COLORS['border']};
    border: 2px solid {COLORS['accent_blue']};
    text-align: center;
}}
"""

class PriceChart(pg.PlotWidget):
    def __init__(self):
        super().__init__()
        self.setBackground(COLORS['background'])
        self.showGrid(x=True, y=True, alpha=0.3)
        self.getPlotItem().getAxis('left').setPen(pg.mkPen(color=COLORS['accent_blue'], width=2))
        self.getPlotItem().getAxis('bottom').setPen(pg.mkPen(color=COLORS['accent_blue'], width=2))

        self.price_line = self.plot([], [], pen=pg.mkPen(color=COLORS['accent_green'], width=3))

        # Adding a filled area under the curve
        self.fill_curve = pg.FillBetweenItem(self.price_line, self.price_line, brush=(50, 50, 200, 100))
        self.getPlotItem().addItem(self.fill_curve)

        self.setLabel('left', 'Price', **{'color': COLORS['accent_pink'], 'font-size': '14pt'})
        self.setLabel('bottom', 'Time', **{'color': COLORS['accent_pink'], 'font-size': '14pt'})

        # Add text annotations
        self.annotation = pg.TextItem(text='Quantum Trade', color=COLORS['accent_purple'], anchor=(0, 0))
        self.getPlotItem().addItem(self.annotation)

    def update_price(self, prices, timestamps):
        self.price_line.setData(timestamps, prices)
        self.annotation.setPos(timestamps[-1], prices[-1])

class QuantumDashboard(QMainWindow):
    def __init__(self):
        super().__init__()
        self.initUI()
        self.initTimer()

    def initUI(self):
        self.setWindowTitle('Quantum Trading Dashboard')
        self.setStyleSheet(STYLE)
        self.resize(1400, 900)
        main_widget = QWidget(self)
        self.setCentralWidget(main_widget)
        layout = QVBoxLayout(main_widget)

        # Adding tabs
        self.tabs = QTabWidget()
        self.tabs.addTab(self.create_overview_tab(), "Overview")
        self.tabs.addTab(self.create_trade_tab(), "Trade")
        self.tabs.addTab(self.create_analysis_tab(), "Analysis")
        self.tabs.addTab(self.create_settings_tab(), "Settings")

        layout.addWidget(self.tabs)

    def create_overview_tab(self):
        tab = QWidget()
        layout = QVBoxLayout(tab)
        self.setup_status_bar(layout)
        content_layout = QHBoxLayout()
        charts_layout = QVBoxLayout()
        self.setup_charts(charts_layout)
        content_layout.addLayout(charts_layout, stretch=2)
        trading_data_layout = QVBoxLayout()
        self.setup_trading_data(trading_data_layout)
        content_layout.addLayout(trading_data_layout, stretch=3)
        layout.addLayout(content_layout)
        return tab

    def create_trade_tab(self):
        tab = QWidget()
        layout = QVBoxLayout(tab)
        label = QLabel("Trade Tab Content")
        layout.addWidget(label)
        return tab

    def create_analysis_tab(self):
        tab = QWidget()
        layout = QVBoxLayout(tab)
        label = QLabel("Analysis Tab Content")
        layout.addWidget(label)
        return tab

    def create_settings_tab(self):
        tab = QWidget()
        layout = QVBoxLayout(tab)
        label = QLabel("Settings Tab Content")
        layout.addWidget(label)
        return tab
    
    def create_overview_tab(self):
    tab = QWidget()
    layout = QVBoxLayout(tab)
    self.setup_status_bar(layout)
    content_layout = QHBoxLayout()
    charts_layout = QVBoxLayout()
    self.setup_charts(charts_layout)
    content_layout.addLayout(charts_layout, stretch=2)
    trading_data_layout = QVBoxLayout()
    self.setup_trading_data(trading_data_layout)
    content_layout.addLayout(trading_data_layout, stretch=3)
    layout.addLayout(content_layout)
    
    # Adding a progress bar
    self.progress_bar = QProgressBar()
    self.progress_bar.setStyleSheet(f"QProgressBar::chunk {{ background-color: {COLORS['accent_blue']}; }}")
    layout.addWidget(self.progress_bar)
    
    # Adding a loading spinner
    spinner_label = QLabel()
    spinner_movie = QMovie("spinner.gif")
    spinner_label.setMovie(spinner_movie)
    layout.addWidget(spinner_label)
    spinner_movie.start()
    
    return tab

    def create_trade_tab(self):
    tab = QWidget()
    layout = QVBoxLayout(tab)
    label = QLabel("Trade Tab Content")
    layout.addWidget(label)
    
    # Adding a trade button with a loading spinner
    trade_button = QPushButton("Execute Trade")
    trade_button.setStyleSheet(f"background-color: {COLORS['accent_green']};")
    layout.addWidget(trade_button)
    
    trade_spinner_label = QLabel()
    trade_spinner_movie = QMovie("trade_spinner.gif")
    trade_spinner_label.setMovie(trade_spinner_movie)
    layout.addWidget(trade_spinner_label)
    
    # Connect the trade button to the spinner
    trade_button.clicked.connect(lambda: self.start_trade_process(trade_spinner_movie))
    
    return tab

    def start_trade_process(self, spinner_movie):
    spinner_movie.start()
    QTimer.singleShot(3000, spinner_movie.stop)  # Simulate a trade process

    def create_analysis_tab(self):
    tab = QWidget()
    layout = QVBoxLayout(tab)
    label = QLabel("Analysis Tab Content")
    layout.addWidget(label)
    
    # Adding some placeholder analysis widgets
    analysis_chart = QLabel("Placeholder for analysis chart")
    analysis_chart.setStyleSheet(f"color: {COLORS['text']}; background-color: {COLORS['plot_fill']}; padding: 20px;")
    layout.addWidget(analysis_chart)
    
    return tab

    def create_settings_tab(self):
    tab = QWidget()
    layout = QVBoxLayout(tab)
    label = QLabel("Settings Tab Content")
    layout.addWidget(label)
    
    # Adding a save settings button
    save_button = QPushButton("Save Settings")
    save_button.setStyleSheet(f"background-color: {COLORS['accent_blue']};")
    layout.addWidget(save_button)
    
    return tab

    # Ensure to add these new methods to the existing QuantumDashboard class and its initUI method
    def initUI(self):
       self.setWindowTitle('Quantum Trading Dashboard')
    self.setStyleSheet(STYLE)
    self.resize(1400, 900)
    main_widget = QWidget(self)
    self.setCentralWidget(main_widget)
    layout = QVBoxLayout(main_widget)

    # Adding tabs
    self.tabs = QTabWidget()
    self.tabs.addTab(self.create_overview_tab(), "Overview")
    self.tabs.addTab(self.create_trade_tab(), "Trade")
    self.tabs.addTab(self.create_analysis_tab(), "Analysis")
    self.tabs.addTab(self.create_settings_tab(), "Settings")

    layout.addWidget(self.tabs)
if __name__ == '__main__':
    import sys
    app = QApplication(sys.argv)
    dashboard = QuantumDashboard()
    dashboard.show()
    sys.exit(app.exec())
 PLEASE REWRITE THIS AND FIX THE SPACING THANK YOU