package top.octopusyan.view;

import com.jfoenix.controls.JFXButton;
import javafx.beans.property.StringProperty;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import org.kordamp.ikonli.javafx.FontIcon;

import java.io.IOException;

/**
 * 隧道列表视图子项
 *
 * @author : octopus yan
 * @email : octopus_yan@foxmail.com
 * @description :
 * @create : 2022-4-23 16:40
 */
public class ProxyListItemView extends HBox {
    private String style = null;
    @FXML
    private Label proxyName;
    @FXML
    private FontIcon statusIcon;
    @FXML
    private JFXButton deleteBtn;

    public ProxyListItemView() {
        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/proxyItem.fxml"));
        fxmlLoader.setRoot(this);
        fxmlLoader.setController(this);

        try {
            fxmlLoader.load();
        } catch (IOException exception) {
            throw new RuntimeException(exception);
        }
    }

    /**
     * 设置运行状态
     * <p> true:run false:stop null:disable
     *
     * @param status 运行状态
     */
    public void setStatus(Boolean status) {
        // 初始化样式
        if (style == null) style = statusIcon.getStyle();

        if (status == null) {
            statusIcon.setStyle(style + "-fx-icon-color: linear-gradient(grey, #524e50);");
        } else if (status) {
            statusIcon.setStyle(style + "-fx-icon-color: linear-gradient(#95f257, #91e5ac);");
        } else {
            statusIcon.setStyle(style + "-fx-icon-color: linear-gradient(#f25757, #e591b1);");
        }
    }

    public void setName(String proxyName) {
        this.proxyName.setText(proxyName);
    }

    public StringProperty textProperty() {
        return proxyName.textProperty();
    }

    public Label getProxyName() {
        return proxyName;
    }

    public JFXButton getDeleteBtn() {
        return deleteBtn;
    }

    public enum Status {
        RUN, STOP, DISABLED
    }
}
