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;

// for use with LabelPickerDialog
public class PickerLabel extends TurboLabel {

    private final LabelPickerUILogic labelPickerUILogic;
    private boolean isSelected;
    private boolean isHighlighted;
    private boolean isRemoved;
    private boolean isFaded;
    private final boolean isTop;

    public PickerLabel(TurboLabel label, LabelPickerUILogic labelPickerUILogic, boolean isTop) {
        super(label.getRepoId(), label.getColour(), label.getActualName());
        this.labelPickerUILogic = labelPickerUILogic;
        isSelected = false;
        isHighlighted = false;
        isRemoved = false;
        isFaded = false;
        this.isTop = isTop;
    }

    public PickerLabel(TurboLabel label, LabelPickerUILogic labelPickerUILogic,
                       boolean isSelected, boolean isHighlighted, boolean isRemoved, boolean isFaded, boolean isTop) {
        super(label.getRepoId(), label.getColour(), label.getActualName());
        this.labelPickerUILogic = labelPickerUILogic;
        this.isSelected = isSelected;
        this.isHighlighted = isHighlighted;
        this.isRemoved = isRemoved;
        this.isFaded = isFaded;
        this.isTop = isTop;
    }

    @Override
    public Node getNode() {
        // actual name for labels at the top, add tick for selected labels
        Label label = new Label((isTop ? getActualName() : getName()));
        label.getStyleClass().add("labels");
        if (isRemoved) label.getStyleClass().add("labels-removed"); // add strikethrough
        String style = getStyle() + (isHighlighted ? " -fx-border-color: black;" : ""); // add highlight border
        style += (isFaded ? " -fx-opacity: 40%;" : ""); // change opacity if needed
        label.setStyle(style);

        FontLoader fontLoader = Toolkit.getToolkit().getFontLoader();
        double width = (double) fontLoader.computeStringWidth(label.getText(), label.getFont());
        label.setPrefWidth(width + 30);
        label.setText(label.getText() + (!isTop && isSelected ? " ✓" : ""));

        if (getGroup().isPresent()) {
            Tooltip groupTooltip = new Tooltip(getGroup().get());
            label.setTooltip(groupTooltip);
        }

        //label.setOnMouseClicked(e -> labelPickerUILogic.toggleLabel(getActualName()));
        return label;
    }

    public void setIsSelected(boolean isSelected) {
        this.isSelected = isSelected;
    }

    public boolean isHighlighted() {
        return isHighlighted;
    }

    public void setIsHighlighted(boolean isHighlighted) {
        this.isHighlighted = isHighlighted;
    }

    public void setIsRemoved(boolean isRemoved) {
        this.isRemoved = isRemoved;
    }

    public boolean isFaded() {
        return isFaded;
    }

    public void setIsFaded(boolean isFaded) {
        this.isFaded = isFaded;
    }

    /**
     * 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();
    }
}

@@ -25,16 +25,67 @@
 ckers;%0A%0A
+import java.util.List;%0Aimport java.util.Optional;%0A%0A
 import b
@@ -108,24 +108,25 @@
 TurboLabel;%0A
+%0A
 import com.s
@@ -184,16 +184,17 @@
 oolkit;%0A
+%0A
 import j
@@ -369,65 +369,8 @@
  %7B%0A%0A
-    private final LabelPickerUILogic labelPickerUILogic;%0A
     
@@ -570,47 +570,8 @@
 bel,
- LabelPickerUILogic labelPickerUILogic,
  boo
@@ -664,62 +664,8 @@
 ));%0A
-        this.labelPickerUILogic = labelPickerUILogic;%0A
     
@@ -850,70 +850,8 @@
 bel,
- LabelPickerUILogic labelPickerUILogic,%0A                      
  boo
@@ -886,24 +886,48 @@
 ighlighted, 
+%0A                       
 boolean isRe
@@ -1047,62 +1047,8 @@
 ));%0A
-        this.labelPickerUILogic = labelPickerUILogic;%0A
     
@@ -2853,32 +2853,482 @@
 isFaded;%0A    %7D%0A%0A
+    public Node processAssignedLabel(List%3CString%3E assignedLabels, Optional%3CString%3E suggestion) %7B%0A        if (isSuggested(suggestion) && !assignedLabels.contains(getActualName())) %7B%0A            setIsFaded(true);%0A            return getNode();%0A        %7D%0A        %0A        if (!assignedLabels.contains(getActualName())) %7B%0A           setIsRemoved(true); %0A           setIsFaded(true);%0A           return getNode();%0A        %7D%0A        return getNode();%0A    %7D%0A%0A
     /**%0A     * T
@@ -3748,32 +3748,32 @@
 nt hashCode() %7B%0A
-
         return s
@@ -3795,10 +3795,167 @@
 ;%0A    %7D%0A
+    %0A    private boolean isSuggested(Optional%3CString%3E suggestion) %7B%0A        return suggestion.isPresent() && suggestion.get().equals(getActualName());%0A    %7D%0A
 %7D%0A

Remove UILogic dependency and include label processing