package _VisualDVM.Visual;
import Common.Visual.UIModule_;
import _VisualDVM.Global;
import _VisualDVM.GlobalData.RemoteFile.UI.RemoteFileChooser;
import _VisualDVM.Passes.PassCode;
import _VisualDVM.TestingSystem.Common.TestingMenuBar;
import _VisualDVM.Visual.Interface.DebugWindow;
import _VisualDVM.Visual.Interface.MainWindow;
import _VisualDVM.Visual.Interface.VersionsWindow;
import _VisualDVM.Visual.Menus.MainMenuBar.MainMenuBar;
import _VisualDVM.Visual.Menus.VersionsMenuBar.VersionsMenuBar;
import _VisualDVM.Visual.Syntax.LightSPFEditorTheme;
import _VisualDVM.Visual.Windows.*;
public class MainUI extends UIModule_ {
    public MainMenuBar mainMenuBar = null;
    public MainWindow mainWindow = null;
    public SearchReplaceForm searchReplaceWindow = null;
    public ProfilesForm profilesWindow = null;
    public VersionsWindow versionsWindow = null;
    public DebugWindow debugWindow = null;
    public RemoteFileChooser remoteFileChooser = null;
    ComponentsWindow componentsWindow = null;
    //-
    TestingMenuBar testingMenuBar = null;
    VersionsMenuBar versionsMenuBar = null;
    //-
    //-
    public MainUI() {
        setTheme(new LightSPFEditorTheme());
    }
    //-
    public TestingMenuBar getTestingMenuBar() {
        if (testingMenuBar == null)
            testingMenuBar = new TestingMenuBar();
        return testingMenuBar;
    }
    public VersionsMenuBar getVersionsMenuBar() {
        if (versionsMenuBar == null)
            versionsMenuBar = new VersionsMenuBar();
        return versionsMenuBar;
    }
    public MainWindow getMainWindow() {
        if (mainWindow == null)
            mainWindow = new MainForm();
        return mainWindow;
    }
    public boolean hasMainWindow() {
        return mainWindow != null;
    }
    public ComponentsWindow getComponentsWindow() {
        if (componentsWindow == null)
            componentsWindow = new ComponentsWindow();
        //-
        Global.mainModule.getPass(PassCode.PublishComponent).setControlsVisible(
                (Global.mainModule.getAccount() != null) ? Global.mainModule.getAccount().isAdmin() : false);
        //--
        return componentsWindow;
    }
    //--
    //возможно перекинуть на тестирование. потом.
    public DebugWindow getDebugWindow() {
        if (debugWindow == null)
            debugWindow = new DebugForm();
        return debugWindow;
    }
    public void HideSearchForm() {
        if (getSearchReplaceWindow().isVisible())
            getSearchReplaceWindow().setVisible(false);
    }
    public VersionsWindow getVersionsWindow() {
        return versionsWindow;
    }
    public SearchReplaceForm getSearchReplaceWindow() {
        if (searchReplaceWindow == null)
            searchReplaceWindow = new SearchReplaceForm();
        return searchReplaceWindow;
    }
    public void ShowSearchForm(boolean replace) {
        searchReplaceWindow.setMode(replace);
        searchReplaceWindow.ShowMode();
        ShowSearchForm();
    }
    public void ShowSearchForm() {
        if (searchReplaceWindow.isVisible())
            searchReplaceWindow.Refresh();
        else
            searchReplaceWindow.Show();
    }
    public RemoteFileChooser getRemoteFileChooser() {
        if (remoteFileChooser == null)
            remoteFileChooser = new RemoteFileChooser();
        return remoteFileChooser;
    }
    public void CreateVersionsWindow() {
        versionsWindow = new VersionsForm(Global.mainModule.getRoot());
    }
    public ProfilesForm getProfilesWindow() {
        if (profilesWindow == null)
            profilesWindow = new ProfilesForm();
        return profilesWindow;
    }
    //---
    void showUndefinedRights() {
        Global.mainModule.SetUserPassesAccess();
        getMainWindow().ShowUndefinedTabs();
        getTestingMenuBar().showServerAdminLabel(false);
        getMainWindow().getCallbackWindow().showNoBugReports();
        Global.normalProperties.setControlVisible("AutoBugReportsLoad", false);
        Global.normalProperties.setControlVisible("AutoTestsLoad", false);
        Global.normalProperties.setControlVisible("CreateEthalonTasks", false);
        Global.normalProperties.setControlVisible("CompleteCompilationOptions", false);
        Global.normalProperties.setControlVisible("CompleteRunEnvironments", false);
        Global.normalProperties.setControlVisible("ErasePackageWorkspace", false);
        Global.normalProperties.AutoCheckTesting = false;
        Global.normalProperties.Update();
    }
    ;
    void showUserRights() {
        Global.mainModule.SetUserPassesAccess();
        getMainWindow().ShowUserTabs();
        getTestingMenuBar().showServerAdminLabel(false);
        getMainWindow().getCallbackWindow().showMyOnlyBugReports();
        Global.normalProperties.setControlVisible("AutoBugReportsLoad", true);
        Global.normalProperties.setControlVisible("AutoTestsLoad", false);
        Global.normalProperties.setControlVisible("CreateEthalonTasks", false);
        Global.normalProperties.setControlVisible("CompleteCompilationOptions", false);
        Global.normalProperties.setControlVisible("CompleteRunEnvironments", false);
        Global.normalProperties.setControlVisible("ErasePackageWorkspace", false);
        Global.normalProperties.AutoCheckTesting = false;
        Global.normalProperties.Update();
    }
    void showStudentRights() {
        Global.mainModule.SetUserPassesAccess();
        getMainWindow().ShowStudentTabs();
        getTestingMenuBar().showServerAdminLabel(false);
        getMainWindow().getCallbackWindow().showAllBugreports();
        Global.normalProperties.setControlVisible("AutoBugReportsLoad", true);
        Global.normalProperties.setControlVisible("AutoTestsLoad", false);
        Global.normalProperties.setControlVisible("CreateEthalonTasks", false);
        Global.normalProperties.setControlVisible("CompleteCompilationOptions", false);
        Global.normalProperties.setControlVisible("CompleteRunEnvironments", false);
        Global.normalProperties.setControlVisible("ErasePackageWorkspace", false);
        Global.normalProperties.AutoCheckTesting = false;
        Global.normalProperties.Update();
    }
    ;
    void showDeveloperRights() {
        Global.mainModule.SetDeveloperPassesAccess();
        getMainWindow().ShowDeveloperTabs();
        getTestingMenuBar().showServerAdminLabel(false);
        getMainWindow().getCallbackWindow().showAllBugreports();
        Global.normalProperties.setControlVisible("AutoBugReportsLoad", true);
        Global.normalProperties.setControlVisible("AutoTestsLoad", true);
        Global.normalProperties.setControlVisible("CreateEthalonTasks", true);
        Global.normalProperties.setControlVisible("CompleteCompilationOptions", true);
        Global.normalProperties.setControlVisible("CompleteRunEnvironments", true);
        Global.normalProperties.setControlVisible("ErasePackageWorkspace", true);
    }
    void showAdminRights() {
        Global.mainModule.SetAdminPassesAccess();
        getMainWindow().ShowAdminTabs();
        getTestingMenuBar().showServerAdminLabel(true);
        getMainWindow().getCallbackWindow().showAllBugReportsAdmin(); //метод избыточный. возможно.
        Global.normalProperties.setControlVisible("AutoBugReportsLoad", true);
        Global.normalProperties.setControlVisible("AutoTestsLoad", true);
        Global.normalProperties.setControlVisible("CreateEthalonTasks", true);
        Global.normalProperties.setControlVisible("CompleteCompilationOptions", true);
        Global.normalProperties.setControlVisible("CompleteRunEnvironments", true);
        Global.normalProperties.setControlVisible("ErasePackageWorkspace", true);
    }
    ;
    public void ShowAccount() {
        getMainWindow().getCallbackWindow().ShowAccountInfo();
        switch (Global.mainModule.getAccount().role) {
            case Undefined:
                showUndefinedRights();
                break;
            case User:
                showUserRights();
                break;
            case Student:
                showStudentRights();
                break;
            case Developer:
                showDeveloperRights();
                break;
            case Admin:
                showAdminRights();
                break;
            default:
                break;
        }
    }
}
