package ui.components.pickers;

import backend.resource.TurboLabel;

import com.sun.javafx.tk.FontLoader;
import com.sun.javafx.tk.Toolkit;

import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.control.Tooltip;

/**
 * This class is to represent a label in LabelPickerDialog
 * <p>
 * It contains attributes such as selected, highlighted, removed and faded in order
 * to produce the appropriate styled node through getNode()
 */
public class PickerLabel extends TurboLabel {

    private boolean isSelected;
    private boolean isHighlighted;
    private boolean isRemoved;
    private boolean isFaded;
    private final boolean canDisplayFullName;

    public PickerLabel(TurboLabel label, boolean canDisplayFullName) {
        super(label.getRepoId(), label.getColour(), label.getFullName());
        isSelected = false;
        isHighlighted = false;
        isRemoved = false;
        isFaded = false;
        this.canDisplayFullName = canDisplayFullName;
    }

    @Override
    public Node getNode() {
        // actual name for labels at the top, add tick for selected labels
        Label label = new Label((canDisplayFullName ? getFullName() : getShortName()));
        label.getStyleClass().add("labels");
        // add strikethrough
        if (isRemoved) label.getStyleClass().add("labels-removed"); 
        // add highlight border
        String style = getStyle() + (isHighlighted ? " -fx-border-color: black; -fx-border-width: 2px;" : ""); 
        // change opacity if needed
        style += (isFaded ? " -fx-opacity: 60%;" : ""); 
        label.setStyle(style);
        label.setText(label.getText() + (!canDisplayFullName && isSelected ? " ✓" : ""));

        FontLoader fontLoader = Toolkit.getToolkit().getFontLoader();
        double width = (double) fontLoader.computeStringWidth(label.getText(), label.getFont());
        label.setPrefWidth(width + 30);

        if (isInGroup()) {
            Tooltip groupTooltip = new Tooltip(getGroupName());
            label.setTooltip(groupTooltip);
        }
        return label;
    }

    public boolean isSelected() {
        return isSelected;
    }

    public PickerLabel selected(boolean isSelected) {
        this.isSelected = isSelected;
        return this;
    }

    public PickerLabel highlighted(boolean isHighlighted) {
        this.isHighlighted = isHighlighted;
        return this;
    }

    public PickerLabel removed(boolean isRemoved) {
        this.isRemoved = isRemoved;
        return this;
    }

    public PickerLabel faded(boolean isFaded) {
        this.isFaded = isFaded;
        return this;
    }

    /**
     * This isn't unnecessary as fields are added, but are not taken into account for equality.
     *
     * @return
     */
    @Override
    @SuppressWarnings("PMD")
    public boolean equals(Object o) {
        return super.equals(o);
    }

    /**
     * This isn't unnecessary as fields are added, but are not taken into account for equality.
     *
     * @return
     */
    @Override
    @SuppressWarnings("PMD")
    public int hashCode() {
        return super.hashCode();
    }
}

@@ -29,45 +29,8 @@
 s;%0A%0A
-import backend.resource.TurboLabel;%0A%0A
 impo
@@ -97,16 +97,80 @@
 olkit;%0A%0A
+import backend.resource.TurboLabel;%0Aimport javafx.scene.Cursor;%0A
 import j
@@ -525,16 +525,63 @@
 abel %7B%0A%0A
+    private final boolean canDisplayFullName;%0A%0A
     priv
@@ -702,54 +702,8 @@
 ded;
-%0A    private final boolean canDisplayFullName;
 %0A%0A  
@@ -1234,408 +1234,27 @@
     
-label.getStyleClass().add(%22labels%22);%0A        // add strikethrough%0A        if (isRemoved) label.getStyleClass().add(%22labels-removed%22); %0A        // add highlight border%0A        String style = getStyle() + (isHighlighted ? %22 -fx-border-color: black; -fx-border-width: 2px;%22 : %22%22); %0A        // change opacity if needed%0A        style += (isFaded ? %22 -fx-opacity: 60%25;%22 : %22%22); %0A        label.setStyle(style
+setLabelStyle(label
 );%0A 
@@ -1439,17 +1439,8 @@
 th =
- (double)
  fon
@@ -1691,28 +1691,723 @@
   %7D%0A
-        return label
+%0A        setupEvents(label);%0A        return label;%0A    %7D%0A%0A    private void setLabelStyle(Label label) %7B%0A        label.getStyleClass().add(%22labels%22);%0A        // add strikethrough%0A        if (isRemoved) label.getStyleClass().add(%22labels-removed%22);%0A        // add highlight border%0A        String style = getStyle() + (isHighlighted ? %22 -fx-border-color: black; -fx-border-width: 2px;%22 : %22%22);%0A        // change opacity if needed%0A        style += (isFaded ? %22 -fx-opacity: 40%25;%22 : %22%22);%0A        label.setStyle(style);%0A    %7D%0A%0A    private void setupEvents(Node node) %7B%0A        node.setOnMouseEntered(e -%3E node.getScene().setCursor(Cursor.HAND));%0A        node.setOnMouseExited(e -%3E node.getScene().setCursor(Cursor.DEFAULT))
 ;%0A  

Change cursor icon on hover