package com.tagmycode.intellij;

import com.intellij.openapi.components.ProjectComponent;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.wm.WindowManager;
import com.tagmycode.plugin.Framework;
import com.tagmycode.plugin.FrameworkConfig;
import com.tagmycode.sdk.authentication.TagMyCodeApiProduction;
import org.jetbrains.annotations.NotNull;

import java.awt.*;

public class TagMyCodeProject implements ProjectComponent {
    private Project project;
    private Framework framework;

    public TagMyCodeProject(Project project) {
        this.project = project;
    }

    @Override
    public void initComponent() {
    }

    public Framework getFramework() {
        if (framework == null) {
            initFramework();
        }
        return framework;
    }

    private void initFramework() {
        FrameworkConfig frameworkConfig = new FrameworkConfig(new PasswordKeyChain(project), new Storage(), new MessageManager(project), new TaskFactory(this), getMainFrame());
        framework = new Framework(new TagMyCodeApiProduction(), frameworkConfig, new Secret());
        framework.start();
    }

    private Frame getMainFrame() {
        return WindowManager.getInstance().getFrame(project);
    }

    public void disposeComponent() {
        // TODO: insert component disposal logic here
    }

    @NotNull
    public String getComponentName() {
        return "TagMyCodeProject";
    }

    public void projectOpened() {
        // called when project is opened
    }

    public void projectClosed() {
        // called when project is being closed
    }

    public Project getProject() {
        return project;
    }


}

@@ -174,16 +174,52 @@
 anager;%0A
+import com.intellij.util.ui.UIUtil;%0A
 import c
@@ -294,16 +294,69 @@
 Config;%0A
+import com.tagmycode.plugin.gui.SyntaxSnippetEditor;%0A
 import c
@@ -1215,16 +1215,114 @@
 start();
+%0A%0A        if (UIUtil.isUnderDarcula()) %7B%0A            SyntaxSnippetEditor.setThemeDark();%0A        %7D
 %0A    %7D%0A%0A

set dark theme for editor if Darcula