package ctbrec.ui.sites.stripchat;

import ctbrec.sites.stripchat.Stripchat;
import ctbrec.ui.tabs.FollowedTab;
import ctbrec.ui.tabs.ThumbOverviewTab;
import javafx.concurrent.WorkerStateEvent;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;

public class StripchatFollowedTab extends ThumbOverviewTab implements FollowedTab {
    private Label status;
    boolean showOnline = true;

    public StripchatFollowedTab(String title, Stripchat stripchat) {
        super(title, new StripchatFollowedUpdateService(stripchat), stripchat);
        status = new Label("Logging in...");
        grid.getChildren().add(status);
    }

    @Override
    protected void createGui() {
        super.createGui();
    }

    @Override
    protected void onSuccess() {
        grid.getChildren().remove(status);
        super.onSuccess();
    }

    @Override
    protected void onFail(WorkerStateEvent event) {
        String msg = "";
        if (event.getSource().getException() != null) {
            msg = ": " + event.getSource().getException().getMessage();
        }
        status.setText("Login failed" + msg);
        super.onFail(event);
    }

    @Override
    public void selected() {
        status.setText("Logging in...");
        super.selected();
    }

    public void setScene(Scene scene) {
        scene.addEventFilter(KeyEvent.KEY_PRESSED, event -> {
            if (this.isSelected() && event.getCode() == KeyCode.DELETE) {
                follow(selectedThumbCells, false);
            }
        });
    }
}
