package Visual_DVM_2021.UI.Main;
import Common.Current;
import Common.Global;
import Common.UI.TextField.StyledTextField;
import Common.UI.UI;
import GlobalData.Compiler.CompilerType;
import TestingSystem.Common.TestingServer;
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;
    public JSplitPane SC64;
    public JSplitPane SC65;
    public JSplitPane SC66;
    //-
    //---
    private JTabbedPane testingTabs;
    private JPanel dvmRunTasksPanel;
    private JToolBar testsResultsTools;
    private JButton bChangeKernels;
    private JTextField filterName;
    private JPanel configurationsPanel;
    private JPanel dvmPackagesPanel;
    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 sapforPackagesPanel;
    private JTabbedPane sapforPackageTabs;
    private JPanel testsRunTasksBackground;
    private JCheckBox filterFinished;
    private JButton bTest;
    private JButton bDownloadTestProject;
    //-
    private final DVMRunTasksComparisonForm dvmTestingRunMaster; //сравнение тестов двм системы.
    private final DVMRunTasksComparisonForm dvmTestingRunSlave;
    //-
    private final SapforPackagesComparisonForm sapforPackageTreeMaster; //сравнение деревьев пакетов SAPFOR.
    private final SapforPackagesComparisonForm sapforPackageTreeSlave;
    //--
    private final SapforVersionsComparisonForm sapforVersionMaster; //сравнение версий тестов SAPFOR.
    private final SapforVersionsComparisonForm sapforVersionSlave;
    //--
    public TestingForm() {
        content.add(UI.testingBar, BorderLayout.NORTH);
        LoadSplitters();
        //-
        dvmTestingRunMaster = new DVMRunTasksComparisonForm(dvmTestingRunSlave = new DVMRunTasksComparisonForm(null));
        sapforPackageTreeMaster = new SapforPackagesComparisonForm(sapforPackageTreeSlave = new SapforPackagesComparisonForm(null));
        sapforVersionMaster = new SapforVersionsComparisonForm(
                sapforVersionSlave = new SapforVersionsComparisonForm(null, Current.SapforVersion),
                Current.SapforEtalonVersion
        );
        //--->>>
        RefreshTabsNames();
        //-
        SC50.setLeftComponent(dvmTestingRunMaster.getContent());
        SC50.setRightComponent(dvmTestingRunSlave.getContent());
        //-
        SC65.setLeftComponent(sapforPackageTreeMaster.getContent());
        SC66.setLeftComponent(sapforPackageTreeSlave.getContent());
        //-
        SC65.setRightComponent(sapforVersionMaster.getContent());
        SC66.setRightComponent(sapforVersionSlave.getContent());
        //-
        Global.testingServer.db.configurations.mountUI(configurationsPanel);
        Global.testingServer.db.dvmPackages.mountUI(dvmPackagesPanel);
        Global.testingServer.db.dvmRunTasks.mountUI(dvmRunTasksPanel);

        Global.testingServer.db.sapforConfigurations.mountUI(sapforConfigurationsPanel);
        Global.testingServer.db.sapforConfigurationCommands.mountUI(sapforConfigurationCommandsPanel);
        Global.testingServer.db.serverSapfors.mountUI(serverSapforsPanel);
        Global.testingServer.db.sapforPackages.mountUI(sapforPackagesPanel);
    }
    //-
    @Override
    public void ShowAll() {
        Global.testingServer.db.configurations.ShowUI();
        Global.testingServer.db.dvmPackages.ShowUI();
        Global.testingServer.db.sapforPackages.ShowUI();
        //--
        Global.testingServer.db.serverSapfors.ShowUI();
        Global.testingServer.db.sapforConfigurations.ShowUI();
        Global.testingServer.db.dvmRunTasks.ShowUI();
        //---
        if (Global.properties.AutoCheckTesting)
            TestingServer.TimerOn();
    }
    //-
    @Override
    public void ShowCurrentTestsPackage() {
        ShowCurrentTestRunTask();
    }
    @Override
    public void DropTestRunTasksComparison() {
        dvmTestingRunMaster.RemoveObject();
        dvmTestingRunSlave.RemoveObject();
    }
    @Override
    public void DropSapforComparison() {
        sapforPackageTreeMaster.RemoveObject();
        sapforPackageTreeSlave.RemoveObject();
        sapforVersionMaster.RemoveObject();
        sapforVersionSlave.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 FocusTestingTasks() {
    }
    @Override
    public void ShowCurrentSapforPackageVersionEtalon() {
        sapforVersionMaster.ApplyObject();
    }
    @Override
    public void ShowCurrentSapforPackageVersion() {
        sapforVersionSlave.ApplyObject();
    }
    @Override
    public void ShowNoSapforPackageVersionEtalon() {
        sapforVersionMaster.RemoveObject();
    }
    @Override
    public void ShowNoSapforPackageVersion() {
        sapforVersionSlave.RemoveObject();
    }
    @Override
    public void FocusSapforTesting() {
        testingTabs.setSelectedIndex(1);
    }
    @Override
    public void ShowCurrentCompiler() {
        String title = (Current.HasCompiler() && Current.getCompiler().type.equals(CompilerType.dvm))?
                "DVM система: " + Current.getCompiler().description: "DVM система: ?";
        testingTabs.setTitleAt(0, title);
    }
    @Override
    public void ShowCurrentServerSapfor() {
        testingTabs.setTitleAt(1,  "SAPFOR: " + Current.getServerSapfor().version);
    }
    @Override
    public void ShowNoServerSapfor() {
        testingTabs.setTitleAt(1,  "SAPFOR: ?");
    }
    @Override
    public void ShowCurrentDVMPackage() {
    }
    @Override
    public void ShowNoCurrentDVMPackage() {
    }
}
