package ctbrec.ui.sites.camsoda;

import static ctbrec.sites.camsoda.Camsoda.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.function.Predicate;

import ctbrec.recorder.Recorder;
import ctbrec.sites.camsoda.Camsoda;
import ctbrec.sites.camsoda.CamsodaModel;
import ctbrec.ui.tabs.TabProvider;
import ctbrec.ui.tabs.ThumbOverviewTab;
import javafx.scene.Scene;
import javafx.scene.control.Tab;

public class CamsodaTabProvider extends TabProvider {

    private static final String API_URL = BASE_URI + "/api/v1/browse/online";
    private Camsoda camsoda;
    private Recorder recorder;
    CamsodaFollowedTab followedTab;

    public CamsodaTabProvider(Camsoda camsoda) {
        this.camsoda = camsoda;
        this.recorder = camsoda.getRecorder();
        followedTab = new CamsodaFollowedTab("Followed", camsoda);
    }

    @Override
    public List<Tab> getTabs(Scene scene) {
        List<Tab> tabs = new ArrayList<>();
        tabs.add(createTab("All", API_URL, m -> true));
        tabs.add(createTab("New", API_URL, CamsodaModel::isNew));
        tabs.add(createTab("Female", API_URL, m -> Objects.equals("f", m.getGender())));
        tabs.add(createTab("Male", API_URL, m -> Objects.equals("m", m.getGender())));
        tabs.add(createTab("Couples", API_URL, m -> Objects.equals("c", m.getGender())));
        tabs.add(createTab("Trans", API_URL, m -> Objects.equals("t", m.getGender())));
        //tabs.add(createTab("#petite", BASE_URI + "/api/v1/browse/tag-petite", m -> true));
        followedTab.setRecorder(recorder);
        followedTab.setScene(scene);
        tabs.add(followedTab);
        tabs.add(new CamsodaShowsTab(camsoda, recorder));
        return tabs;
    }

    @Override
    public Tab getFollowedTab() {
        return followedTab;
    }

    private Tab createTab(String title, String url, Predicate<CamsodaModel> filter) {
        CamsodaUpdateService updateService = new CamsodaUpdateService(url, false, camsoda, filter);
        ThumbOverviewTab tab = new ThumbOverviewTab(title, updateService, camsoda);
        tab.setRecorder(recorder);
        return tab;
    }

}
