package at.fos.ermodel.gui;

import javafx.geometry.Insets;
import javafx.scene.image.Image;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.CornerRadii;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;

import java.io.BufferedReader;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Objects;

public class C2 {
    public static final Color MouseSelectedColor = Color.RED;
    public static final Color FocusOnComponentColor = Color.BLUE;
    public static final Color ButtonBackgroundColor = Color.rgb(179, 179, 179);

    public static final Color ERMDockablePointColor = Color.rgb(236, 234, 241);
    public static final Color ERMTextBorderColor = Color.GREY;

    public static Font ERMFont = Font.font(null, FontWeight.BOLD, 12.0D);
    public static Color ERMBackgroundColor = Color.rgb(27, 27, 30);
    public static Color ERMForegroundColor = Color.rgb(48, 48, 52);

    public static Color ERMTextColor = Color.rgb(236, 234, 241);

    public static Background AppBackground = new Background(new BackgroundFill(C2.ERMBackgroundColor, CornerRadii.EMPTY, Insets.EMPTY));
    public static Background AppForeground = new Background(new BackgroundFill(C2.ERMForegroundColor, CornerRadii.EMPTY, Insets.EMPTY));


    public static StackPane alerterror = new StackPane();
    public static StackPane alertconfirmation = new StackPane();
    public static StackPane alertinformation = new StackPane();


    public static Color ERMSelectedColor = Color.RED;

    public static Color ERMESColor = Color.rgb(0, 255, 0);

    public static Color ERMRSColor = Color.AQUA;
    public static Color ERMRSConnColor = Color.AQUA;

    public static Color ERMRSISAColor = Color.BLUEVIOLET;
    public static Color ERMISAConnGENERAL = Color.BLUEVIOLET;
    public static Color ERMISAConnSPEC = Color.AQUA;

    public static Color ERMATTRColor = Color.GREENYELLOW;

    public static Color ERMLINEColor = Color.CHARTREUSE;

    public static Color TEMPLINEColor = Color.PALEGREEN;


    public static Image applicationImageIconAsICO;


    public static int imageWidth = 55;
    public static int imageHeight = 32;

    public static Image treeCloseImage;

    public static Image treeOpenImage;

    public static Image attr_conn_attrImage;
    public static Image attr_conn_esImage;
    public static Image attr_conn_rsImage;
    public static Image attr_derived_multi_valueImage;
    public static Image attr_derived_one_valueImage;
    public static Image attr_key_valueImage;
    public static Image attr_multi_valueImage;
    public static Image attr_one_valueImage;
    public static Image attr_weak_key_valueImage;
    public static Image es_associativeImage;
    public static Image es_weakImage;
    public static Image esImage;
    public static Image rs_conn_esImage;
    public static Image rs_id_conn_es_weakImage;
    public static Image rs_id_conn_esImage;
    public static Image rs_idImage;
    public static Image rs_isa_conn_general_esImage;
    public static Image rs_isa_conn_special_esImage;
    public static Image rs_isaImage;
    public static Image rsImage;
    public static Image textImage;
    public static Image textWithoutBorderImage;
    public static HashMap<String, InputStream> randomDataFiles = new HashMap<>();
    public static HashMap<String, BufferedReader> randomDataFilesExtern = new HashMap<>();


    public C2() {

        alerterror.getStyleClass().add("alert.error.dialog-pane");
        alertinformation.getStyleClass().add("alert.error.dialog-pane");
        alertconfirmation.getStyleClass().add("alert.error.dialog-pane");


        String appImages = "/applicationimages/";
        String appData = "/data/";


        randomDataFiles.put("Random Color", getClass().getResourceAsStream(appData + "colors.txt"));
        randomDataFiles.put("Random Company", getClass().getResourceAsStream(appData + "companies.txt"));
        randomDataFiles.put("Random Country", getClass().getResourceAsStream(appData + "countries.txt"));
        randomDataFiles.put("Random Departmentname", getClass().getResourceAsStream(appData + "departmentnames.txt"));
        randomDataFiles.put("Random Firstname", getClass().getResourceAsStream(appData + "firstnames.txt"));
        randomDataFiles.put("Random Jobname", getClass().getResourceAsStream(appData + "jobnames.txt"));
        randomDataFiles.put("Random Language", getClass().getResourceAsStream(appData + "languages.txt"));
        randomDataFiles.put("Random Lastname", getClass().getResourceAsStream(appData + "lastnames.txt"));
        randomDataFiles.put("Random Mediacategory", getClass().getResourceAsStream(appData + "mediacategories.txt"));
        randomDataFiles.put("Random Mediapublisher", getClass().getResourceAsStream(appData + "mediapublishers.txt"));
        randomDataFiles.put("Random Mediatitle", getClass().getResourceAsStream(appData + "mediatitles.txt"));
        randomDataFiles.put("Random Mediatype", getClass().getResourceAsStream(appData + "mediatypes.txt"));
        randomDataFiles.put("Random Place", getClass().getResourceAsStream(appData + "places.txt"));
        randomDataFiles.put("Random Profession", getClass().getResourceAsStream(appData + "professions.txt"));
        randomDataFiles.put("Random Rentalequipment", getClass().getResourceAsStream(appData + "rentalequipment.txt"));
        randomDataFiles.put("Random Street", getClass().getResourceAsStream(appData + "streets.txt"));

        applicationImageIconAsICO = new Image(Objects.requireNonNull(getClass().getResourceAsStream(appImages + "erdlogo.png")));
        attr_conn_attrImage = new Image(Objects.requireNonNull(getClass().getResourceAsStream(appImages + "attr_conn_attr.png")));
        attr_conn_esImage = new Image(Objects.requireNonNull(getClass().getResourceAsStream(appImages + "attr_conn_es.png")));
        attr_conn_rsImage = new Image(Objects.requireNonNull(getClass().getResourceAsStream(appImages + "attr_conn_rs.png")));
        attr_derived_multi_valueImage = new Image(Objects.requireNonNull(getClass().getResourceAsStream(appImages + "attr_derived_multi_value.png")));
        attr_derived_one_valueImage = new Image(Objects.requireNonNull(getClass().getResourceAsStream(appImages + "attr_derived_one_value.png")));
        attr_key_valueImage = new Image(Objects.requireNonNull(getClass().getResourceAsStream(appImages + "attr_key_value.png")));
        attr_multi_valueImage = new Image(Objects.requireNonNull(getClass().getResourceAsStream(appImages + "attr_multi_value.png")));
        attr_one_valueImage = new Image(Objects.requireNonNull(getClass().getResourceAsStream(appImages + "attr_one_value.png")));
        attr_weak_key_valueImage = new Image(Objects.requireNonNull(getClass().getResourceAsStream(appImages + "attr_weak_key_value.png")));
        es_associativeImage = new Image(Objects.requireNonNull(getClass().getResourceAsStream(appImages + "es_associative.png")));
        es_weakImage = new Image(Objects.requireNonNull(getClass().getResourceAsStream(appImages + "es_weak.png")));
        esImage = new Image(Objects.requireNonNull(getClass().getResourceAsStream(appImages + "es.png")));
        rs_conn_esImage = new Image(Objects.requireNonNull(getClass().getResourceAsStream(appImages + "rs_conn_es.png")));
        rs_id_conn_es_weakImage = new Image(Objects.requireNonNull(getClass().getResourceAsStream(appImages + "rs_id_conn_es_weak.png")));
        rs_id_conn_esImage = new Image(Objects.requireNonNull(getClass().getResourceAsStream(appImages + "rs_id_conn_es.png")));
        rs_idImage = new Image(Objects.requireNonNull(getClass().getResourceAsStream(appImages + "rs_id.png")));
        rs_isa_conn_general_esImage = new Image(Objects.requireNonNull(getClass().getResourceAsStream(appImages + "rs_isa_conn_general_es.png")));
        rs_isa_conn_special_esImage = new Image(Objects.requireNonNull(getClass().getResourceAsStream(appImages + "rs_isa_conn_special_es.png")));
        rs_isaImage = new Image(Objects.requireNonNull(getClass().getResourceAsStream(appImages + "rs_isa.png")));
        rsImage = new Image(Objects.requireNonNull(getClass().getResourceAsStream(appImages + "rs.png")));
        textImage = new Image(Objects.requireNonNull(getClass().getResourceAsStream(appImages + "text.png")));
        textWithoutBorderImage = new Image(Objects.requireNonNull(getClass().getResourceAsStream(appImages + "text_without_border.png")));
        treeOpenImage = new Image(Objects.requireNonNull(getClass().getResourceAsStream(appImages + "tree_open.png")));
        treeCloseImage = new Image(Objects.requireNonNull(getClass().getResourceAsStream(appImages + "tree_close.png")));
    }

    public static double computeTextWidth(String text, double wrappingWidth) {
        Text helper = new Text();
        helper.setFont(ERMFont);
        helper.setText(text);

        helper.setWrappingWidth(0.0D);
        helper.setLineSpacing(0.0D);
        double w = Math.min(helper.prefWidth(-1.0D), wrappingWidth);
        helper.setWrappingWidth(Math.ceil(w));
        return Math.ceil(helper.getLayoutBounds().getWidth());
    }

    public static double computeTextHeight() {
        return ERMFont.getSize();
    }
}