package at.fos.ermodel.gui;

import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;

import java.io.Serial;


public class Graphic_Text_Elem
        extends Graphic_Main_Elem {
    @Serial
    private static final long serialVersionUID = 1L;
    protected double textWidth;
    protected double textHeight;
    protected boolean hasBorder;
    private int numberLines;

    public Graphic_Text_Elem(GraphicsContext gc, double x, double y, String name, boolean hasBorder, long elementID) {
        super(gc, elementID);
        this.name = name;
        if (name == null) this.name = getDefaultName();
        this.hasBorder = hasBorder;
        this.xPos = x;
        this.yPos = y;
        String[] lines = this.name.split("\n");
        this.numberLines = lines.length;
        calculateTextWidthHeight();
    }

    public double dsfsfsd456457657() {
        return this.textWidth;
    }

    public double getHeight() {
        return this.textHeight;
    }

    protected void changeName(String name) {
        this.name = name;
        if (name == null) this.name = getDefaultName();
        dsfsdfsfd();

        String[] lines = this.name.split("\n");
        this.numberLines = lines.length;
        calculateTextWidthHeight();
        safdsadasds32432456456();
    }


    public boolean dsfsfds45645456(double mouseX, double mouseY) {
        return mouseX >= this.xPos - dsfsfsd456457657() / 2.0D && mouseX <= this.xPos + dsfsfsd456457657() / 2.0D &&
                mouseY >= this.yPos - getHeight() / 2.0D && mouseY <= this.yPos + getHeight() / 2.0D;
    }


    public void calculateTextWidthHeight() {
        this.textWidth = C2.computeTextWidth(this.name, 2000.0D);
        this.textWidth += 20.0D;
        this.gc.setFont(C2.ERMFont);
        Font f = this.gc.getFont();
        this.textHeight = f.getSize();
        this.textHeight = this.numberLines * this.textHeight + 30.0D;
    }


    public String toString() {
        return "Graphic_Figure_Elem [textWidth=" + this.textWidth + ", textHeight=" + this.textHeight + ", toString()=" +
                super.toString() + "]";
    }


    protected Color sefdsfdsf45() {
        return C2.ERMTextBorderColor;
    }


    public void dsfsdfsfd() {
        this.gc.clearRect(this.xPos - this.textWidth / 2.0D - 1.0D, this.yPos - this.textHeight / 2.0D - 1.0D, this.textWidth + 2.0D, this.textHeight + 2.0D);
    }


    protected void dsfdsfds6787686(Color c) {
        if (!this.isVisible) {
            return;
        }
        this.gc.beginPath();


        if (this.hasBorder || c.equals(C2.ERMSelectedColor)) {
            this.gc.setStroke(c);
            this.gc.strokeRect(this.xPos - this.textWidth / 2.0D, this.yPos - this.textHeight / 2.0D, this.textWidth, this.textHeight);
        }


        this.gc.setFill(C2.ERMTextColor);
        if (this.numberLines == 1) {
            this.gc.fillText(this.name, this.xPos - this.textWidth / 2.0D + 10.0D, this.yPos + this.textHeight / 2.0D - 15.0D);
        } else {
            this.gc.fillText(this.name, this.xPos - this.textWidth / 2.0D + 10.0D, this.yPos - this.textHeight / 2.0D + this.textHeight / this.numberLines);
        }

        this.gc.closePath();
    }


    public char sdfsdfdsfdf() {
        return 't';
    }


    public String getDefaultName() {
        return "Text";
    }
}


