package vismon.util;

import com.sun.deploy.security.MozillaJSSDSASignature;
import vismon.data.Session;

import java.awt.Color;
import java.awt.Font;
import java.util.ArrayList;
import java.util.List;

public class Constants {

    public static double NA = Double.NaN;
    public static String NO_UNIT = "NONE";

    public final static String LS_EQUAL =     "\u2264";
    public final static String GR_EQUAL =  "\u2265";

    public static Color MAIN_COLOR;
    public static Color CONSTRAINT_COLOR;
    public static Color BAD_INPUT_BG_COLOR;

    public static Font PLOT_FONT = new Font("Lucida Grande", Font.PLAIN, 15);
    public static Font ISOLINE_FONT = new Font("Lucida Grande", Font.PLAIN, 11);
    public static Font OVERVIEW_TITLE_FONT = new Font("Lucida Grande", Font.BOLD, 13);
    public static Font OVERVIEW_FONT = new Font("Lucida Grande", Font.PLAIN, 13);

    public static final Color TABLE_ROW_SEPARATION_BG_COLOR = new Color(211, 219, 242);
    public static final Color OVERVIEW_SEPARATION_BG_COLOR = new Color(235, 235, 235);
    public static final Color OVERVIET_SELECTION_BG_COLOR = new Color(143, 197, 254);

    public static int shadingNum = 5;
    public static int contourNum = 8;
    private static Color[][] cpShadingColors = new Color[shadingNum][contourNum];
    public static final double[] contourStepValues = new double[35];

    public static int scenarioColorNum = 10;
    private static Color[] scenarioColors = new Color[scenarioColorNum];

    private static List<Color> freeScenarioColors = new ArrayList<Color>();
    private static List<Color> usedScenarioColors = new ArrayList<Color>();

    static {
        MAIN_COLOR = new Color(90, 90, 90);
        CONSTRAINT_COLOR = new Color(128, 128, 128);
        BAD_INPUT_BG_COLOR = new Color(255, 175, 175);

        cpShadingColors[0][0] = new Color(8, 104, 172);
        cpShadingColors[0][1] = new Color(43, 140, 190);
        cpShadingColors[0][2] = new Color(78, 179, 211);
        cpShadingColors[0][3] = new Color(123, 204, 196);
        cpShadingColors[0][4] = new Color(168, 221, 181);
        cpShadingColors[0][5] = new Color(204, 235, 197);
        cpShadingColors[0][6] = new Color(224, 243, 219);
        cpShadingColors[0][7] = new Color(247, 252, 240);

        cpShadingColors[3][0] = new Color(0, 104, 55);
        cpShadingColors[3][1] = new Color(35, 132, 67);
        cpShadingColors[3][2] = new Color(65, 171, 93);
        cpShadingColors[3][3] = new Color(120, 198, 121);
        cpShadingColors[3][4] = new Color(173, 221, 142);
        cpShadingColors[3][5] = new Color(217, 240, 163);
        cpShadingColors[3][6] = new Color(247, 252, 185);
        cpShadingColors[3][7] = new Color(255, 255, 229);

        cpShadingColors[4][0] = new Color(0, 166, 0);
        cpShadingColors[4][1] = new Color(25, 175, 0);
        cpShadingColors[4][2] = new Color(53, 184, 0);
        cpShadingColors[4][3] = new Color(83, 193, 0);
        cpShadingColors[4][4] = new Color(116, 202, 0);
        cpShadingColors[4][5] = new Color(151, 211, 0);
        cpShadingColors[4][6] = new Color(189, 220, 0);
        cpShadingColors[4][7] = new Color(230, 230, 0);

        cpShadingColors[2][0] = new Color(26, 152, 80);
        cpShadingColors[2][1] = new Color(102, 189, 99);
        cpShadingColors[2][2] = new Color(166, 217, 106);
        cpShadingColors[2][3] = new Color(217, 239, 139);
        cpShadingColors[2][4] = new Color(254, 224, 139);
        cpShadingColors[2][5] = new Color(253, 174, 97);
        cpShadingColors[2][6] = new Color(244, 109, 67);
        cpShadingColors[2][7] = new Color(215, 48, 39);

        cpShadingColors[1][0] = new Color(33, 102, 172);
        cpShadingColors[1][1] = new Color(67, 147, 195);
        cpShadingColors[1][2] = new Color(146, 197, 222);
        cpShadingColors[1][3] = new Color(209, 229, 240);
        cpShadingColors[1][4] = new Color(253, 219, 199);
        cpShadingColors[1][5] = new Color(244, 165, 130);
        cpShadingColors[1][6] = new Color(214, 96, 77);
        cpShadingColors[1][7] = new Color(178, 24, 43);

        /*cpShadingColors[5][0] = new Color(37, 52, 148);
        cpShadingColors[5][1] = new Color(34, 94, 168);
        cpShadingColors[5][2] = new Color(29, 145, 192);
        cpShadingColors[5][3] = new Color(65, 182, 196);
        cpShadingColors[5][4] = new Color(127, 205, 187);
        cpShadingColors[5][5] = new Color(199, 233, 180);
        cpShadingColors[5][6] = new Color(237, 248, 217);
        cpShadingColors[5][7] = new Color(255, 255, 217);*/

        scenarioColors[0] = new Color(31, 120, 180);
        scenarioColors[1] = new Color(255, 127, 0);
        scenarioColors[2] = new Color(51, 160, 44);
        scenarioColors[3] = new Color(227, 26, 28);
        scenarioColors[4] = new Color(106, 61, 154);
        scenarioColors[5] = new Color(166, 206, 227);
        scenarioColors[6] = new Color(253, 191, 111);
        scenarioColors[7] = new Color(178, 223, 138);
        scenarioColors[8] = new Color(251, 154, 153);
        scenarioColors[9] = new Color(202, 178, 214);

        for (int i = 0; i < scenarioColors.length; ++i)
            freeScenarioColors.add(scenarioColors[i]);

        contourStepValues[0] = 0.1;
        contourStepValues[1] = 0.2;
        contourStepValues[2] = 0.5;
        contourStepValues[3] = 1;
        contourStepValues[4] = 2;
        contourStepValues[5] = 5;
        contourStepValues[6] = 10;
        contourStepValues[7] = 20;
        contourStepValues[8] = 40;
        contourStepValues[9] = 60;
        contourStepValues[10] = 80;
        contourStepValues[11] = 100;
        contourStepValues[12] = 150;
        contourStepValues[13] = 200;
        contourStepValues[14] = 250;
        contourStepValues[15] = 300;
        contourStepValues[16] = 350;
        contourStepValues[17] = 400;
        contourStepValues[18] = 450;
        contourStepValues[19] = 500;
        contourStepValues[20] = 750;
        contourStepValues[21] = 1000;
        contourStepValues[22] = 1500;
        contourStepValues[23] = 2000;
        contourStepValues[24] = 2500;
        contourStepValues[25] = 5000;
        contourStepValues[26] = 7500;
        contourStepValues[27] = 10000;
        contourStepValues[28] = 15000;
        contourStepValues[29] = 20000;
        contourStepValues[30] = 50000;
        contourStepValues[31] = 100000;
        contourStepValues[32] = 200000;
        contourStepValues[33] = 500000;
        contourStepValues[34] = 1000000;
    }

    public static Color getScenarioColor() {
        if (freeScenarioColors.size() == 0) {
            Color color = new Color((int)(Math.random() * 255), (int)(Math.random() * 255), (int)(Math.random() * 255));
            return color;
        }
        Color color = freeScenarioColors.get(0);
        return color;
    }

    public static void usedScenarioColor(Color color) {
        freeScenarioColors.remove(color);
        usedScenarioColors.add(color);
    }

    public static void freeScenarioColor(Color color) {
        freeScenarioColors.add(color);
        usedScenarioColors.remove(color);
    }

    public static void setPlotFont(Font f) {
        PLOT_FONT = f;
    }

    public static Font getPlotFont(int size) {
        return new Font(PLOT_FONT.getFamily(), PLOT_FONT.getStyle(), size);
    }

    public static void setOverviewFont(Font f) {
        OVERVIEW_FONT = f;
    }

    public static Color getCPShadingColor(int i, int j) {
        return cpShadingColors[i][j];
    }

    public static double getContourStepValue(int i) {
        return contourStepValues[i];
    }

    public static double getPrevCommonStepValue(double csValue) {
        for (int i = 1; i < contourStepValues.length; ++i)
            if (csValue == contourStepValues[i])
                return contourStepValues[i - 1];
        return contourStepValues[0];
    }

    public static double getNextCommonStepValue(double csValue) {
        for (int i = 0; i < contourStepValues.length - 1; ++i)
            if (csValue == contourStepValues[i])
                return contourStepValues[i + 1];
        return contourStepValues[contourStepValues.length - 1];
    }
}
