package com.jetbrains.edu.kotlin;

import com.intellij.openapi.actionSystem.DefaultActionGroup;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.jetbrains.edu.learning.StudyBasePluginConfigurator;
import com.jetbrains.edu.learning.StudyTaskManager;
import com.jetbrains.edu.learning.StudyTwitterPluginConfigurator;
import com.jetbrains.edu.learning.StudyUtils;
import com.jetbrains.edu.learning.actions.*;
import com.jetbrains.edu.learning.courseFormat.Course;
import com.jetbrains.edu.learning.twitter.StudyTwitterAction;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class EduKotlinPluginConfigurator extends StudyBasePluginConfigurator {
    @NotNull
    @Override
    public DefaultActionGroup getActionGroup(Project project) {
        final DefaultActionGroup group = new DefaultActionGroup();
        EduKotlinCheckAction checkAction = new EduKotlinCheckAction();
        checkAction.getTemplatePresentation().setIcon(EduKotlinIcons.CHECK_TASK);
        group.add(checkAction);
        group.add(new StudyPreviousStudyTaskAction());
        group.add(new StudyNextStudyTaskAction());
        StudyRefreshTaskFileAction resetTaskFile = new StudyRefreshTaskFileAction();
        resetTaskFile.getTemplatePresentation().setIcon(EduKotlinIcons.RESET_TASK_FILE);
        group.add(resetTaskFile);
        StudyFillPlaceholdersAction fillPlaceholdersAction = new StudyFillPlaceholdersAction();
        fillPlaceholdersAction.getTemplatePresentation().setIcon(EduKotlinIcons.FILL_PLACEHOLDERS_ICON);
        fillPlaceholdersAction.getTemplatePresentation().setText("Fill Answer Placeholders");
        group.add(fillPlaceholdersAction);
        return group;
    }

    @NotNull
    @Override
    public String getDefaultHighlightingMode() {
        return "text/x-java";
    }

    @Override
    public boolean accept(@NotNull Project project) {
        StudyTaskManager instance = StudyTaskManager.getInstance(project);
        if (instance == null) return false;
        Course course = instance.getCourse();
        return course != null && "PyCharm".equals(course.getCourseType()) && "kotlin".equals(course.getLanguage());
    }

    @NotNull
    @Override
    public String getLanguageScriptUrl() {
        return getClass().getResource("/code_mirror/clike.js").toExternalForm();
    }

    @Nullable
    @Override
    public StudyAfterCheckAction[] getAfterCheckActions() {
        Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
        for (Project project : openProjects) {
            if (StudyTaskManager.getInstance(project).getCourse() != null) {
                StudyTwitterPluginConfigurator twitterConfigurator = StudyUtils.getTwitterConfigurator(project);
                if (twitterConfigurator != null) {
                    return new StudyAfterCheckAction[]{new StudyTwitterAction(twitterConfigurator)};
                }
            }
        }
        return null;
    }
}

@@ -1118,21 +1118,16 @@
 Previous
-Study
 TaskActi
@@ -1164,21 +1164,16 @@
 tudyNext
-Study
 TaskActi
@@ -2211,16 +2211,18 @@
 Language
+ID
 ());%0A   

fix due to changes in student plugin