package Visual_DVM_2021.UI.Main;
import Common.Global;
import Common.UI.TextField.StyledTextField;
import Common.UI.UI;
import Visual_DVM_2021.UI.Interface.FormWithSplitters;
import Visual_DVM_2021.UI.Interface.TestingWindow;

import javax.swing.*;
import java.awt.*;
public class TestingForm implements FormWithSplitters, TestingWindow {
    private JPanel content;
    @Override
    public JPanel getContent() {
        return content;
    }
    public JSplitPane SC50;
    public JSplitPane SC48;
    public JSplitPane SC49;
    public JSplitPane SC46;
    public JSplitPane SC53;
    public JSplitPane SC56;
    public JSplitPane SC63;
    public JSplitPane SC59;
    //-
    //---
    private JTabbedPane testingTabs;
    private JPanel testsRunTasksPanel;
    private JToolBar testsResultsTools;
    private JButton bChangeKernels;
    private JTextField filterName;
    private JPanel configurationsPanel;
    private JPanel packagesPanel;
    private JButton bCompilationFilter;
    private JPanel dvmTestingPanel;
    private JPanel sapforTestingPanel;
    private JPanel packageVersionsPanel;
    private JPanel sapforConfigurationsPanel;
    private JLabel sapforConfigurationsLabel;
    private JLabel sapforConfigurationsCommandsLabel;
    private JPanel sapforConfigurationCommandsPanel;
    private JPanel sapforScenariosPanel;
    private JPanel serverSapforsPanel;
    private JPanel sapforTasksPackagesPanel;
    private JPanel sapforTasksPanel;
    private JPanel testsRunTasksBackground;
    private JCheckBox filterFinished;
    private JButton bTest;
    private JButton bDownloadTestProject;
    private JToolBar compilationTasksTools;
    private JToolBar runTasksTools;
    //-
    //
    public CompilationTasksComparisonForm singleCompilationTaskMaster; // одиночная компиляция
    public CompilationTasksComparisonForm singleCompilationTaskSlave;
    //--
    //-
    private TestRunTasksComparisonForm dvmTestingRunMaster; //сравнение тестов двм системы.
    private TestRunTasksComparisonForm dvmTestingRunSlave;
    //-
    public TestingForm() {
        content.add(UI.testingBar, BorderLayout.NORTH);
        LoadSplitters();
        //-
        dvmTestingRunMaster = new TestRunTasksComparisonForm(dvmTestingRunSlave = new TestRunTasksComparisonForm(null));
        //--->>>
        RefreshTabsNames();
        //-
        SC50.setLeftComponent(dvmTestingRunMaster.getContent());
        SC50.setRightComponent(dvmTestingRunSlave.getContent());
        //-
        Global.testingServer.db.configurations.mountUI(configurationsPanel);
        Global.testingServer.account_db.packages.mountUI(packagesPanel);
        Global.testingServer.account_db.testRunTasks.mountUI(testsRunTasksPanel);
        //--
        Global.testingServer.db.sapforConfigurations.mountUI(sapforConfigurationsPanel);
        Global.testingServer.db.sapforConfigurationCommands.mountUI(sapforConfigurationCommandsPanel);
        Global.testingServer.db.serverSapfors.mountUI(serverSapforsPanel);
        Global.testingServer.account_db.sapforTasksPackages.mountUI(sapforTasksPackagesPanel);
        //---
        Global.testingServer.account_db.sapforTasks.mountUI(sapforTasksPanel);
    }
    //-
    @Override
    public void ShowAll() {
        Global.testingServer.db.configurations.ShowUI();
        Global.testingServer.account_db.packages.ShowUI();
        //--
        Global.testingServer.db.serverSapfors.ShowUI();
        Global.testingServer.db.sapforConfigurations.ShowUI();
        Global.testingServer.account_db.sapforTasksPackages.ShowUI();
    }
    //-
    @Override
    public void ShowCurrentTestsPackage() {
        ShowCurrentTestRunTask();
    }
    @Override
    public void DropTestRunTasksComparison() {
        dvmTestingRunMaster.RemoveObject();
        dvmTestingRunSlave.RemoveObject();
    }
    @Override
    public void ShowCurrentTestRunTask() {
        // if (dvmTestingRunMaster.isActive()) dvmTestingRunMaster.ShowTask();
        //  else dvmTestingRunSlave.ShowTask();
    }
    @Override
    public void ShowNoTestRunTask() {
        //  dvmTestingRunMaster.Clear();
        // dvmTestingRunSlave.Clear();
    }
    @Override
    public void RefreshTabsNames() {
    }
    private void createUIComponents() {
        // TODO: place custom component creation code here
        filterName = new StyledTextField();
    }
    @Override
    public void FocusTestingSystem() {
        testingTabs.setSelectedIndex(2);
    }
    @Override
    public void ShowAutoActualizeTestsState() {
        UI.testingBar.ShowAutorefresh();
    }
    @Override
    public void FocusTestingTasks() {
    }
    @Override
    public void RemountTestTable() {
        UI.Clear(packagesPanel);
        UI.Clear(testsRunTasksPanel);
        UI.Clear(sapforTasksPackagesPanel);
        UI.Clear(sapforTasksPanel);
        //-->>
        Global.testingServer.account_db.packages.mountUI(packagesPanel);
        Global.testingServer.account_db.testRunTasks.mountUI(testsRunTasksPanel);
        Global.testingServer.account_db.sapforTasksPackages.mountUI(sapforTasksPackagesPanel);
        Global.testingServer.account_db.sapforTasks.mountUI(sapforTasksPanel);
    }
}
