from PyQt5.QtWidgets import QStackedLayout, QWidget

from nixview.ui.plotscreen import PlotScreen
from nixview.ui.splashscreen import SplashScreen
from nixview.ui.filescreen import FileScreen

class CentralWidget(QWidget):
    
    def __init__(self, parent=None) -> None:
        super().__init__(parent=parent)
        
        self._splash = SplashScreen()
        self._file_view = FileScreen(self)
        self._plot_screen = PlotScreen(self)
        self._plot_screen.close_signal.connect(self.on_plot_close)
        self._stack = QStackedLayout(self)
        self._stack.addWidget(self._splash)
        self._stack.addWidget(self._file_view)
        self._stack.addWidget(self._plot_screen)
        self.setLayout(self._stack)

    def show_file_content(self):
        self._stack.setCurrentIndex(1)
        self._file_view.update()

    def plot_item(self, item_descriptor):
        self._stack.setCurrentIndex(2)
        self._plot_screen.plot(item_descriptor)

    def on_plot_close(self):
        self._stack.setCurrentIndex(1)

    def reset(self):
        self._file_view.reset()
        self._splash.reset()
        self._stack.setCurrentIndex(0)
