package ctbrec.ui.sites.chaturbate;

import ctbrec.sites.chaturbate.Chaturbate;
import ctbrec.ui.sites.AbstractTabProvider;
import ctbrec.ui.tabs.PaginatedScheduledService;
import ctbrec.ui.tabs.ThumbOverviewTab;
import javafx.scene.Scene;
import javafx.scene.control.Tab;

import java.util.ArrayList;
import java.util.List;

public class ChaturbateTabProvider extends AbstractTabProvider {

    private final ChaturbateFollowedTab followedTab;

    public ChaturbateTabProvider(Chaturbate chaturbate) {
        super(chaturbate);
        this.followedTab = new ChaturbateFollowedTab("Followed", chaturbate.getBaseUrl() + "/api/ts/roomlist/room-list/?enable_recommendations=false&follow=true", chaturbate);
    }

    @Override
    protected List<Tab> getSiteTabs(Scene scene) {
        List<Tab> tabs = new ArrayList<>();
        tabs.add(createTab("Featured", site.getBaseUrl() + "/api/ts/roomlist/room-list/?enable_recommendations=false"));
        tabs.add(createTab("Female", site.getBaseUrl() + "/api/ts/roomlist/room-list/?enable_recommendations=false&genders=f"));
        tabs.add(createTab("New Female", site.getBaseUrl() + "/api/ts/roomlist/room-list/?enable_recommendations=false&genders=f&new_cams=true"));
        tabs.add(createTab("Male", site.getBaseUrl() + "/api/ts/roomlist/room-list/?enable_recommendations=false&genders=m"));
        tabs.add(createTab("New Male", site.getBaseUrl() + "/api/ts/roomlist/room-list/?enable_recommendations=false&genders=m&new_cams=true"));
        tabs.add(createTab("Couples", site.getBaseUrl() + "/api/ts/roomlist/room-list/?enable_recommendations=false&genders=c"));
        tabs.add(createTab("Trans", site.getBaseUrl() + "/api/ts/roomlist/room-list/?enable_recommendations=false&genders=s"));
        tabs.add(createTab("Private", site.getBaseUrl() + "/api/ts/roomlist/room-list/?enable_recommendations=false&private=true"));
        tabs.add(createTab("Hidden", site.getBaseUrl() + "/api/ts/roomlist/room-list/?enable_recommendations=false&hidden=true"));
        followedTab.setScene(scene);
        followedTab.setRecorder(recorder);
        followedTab.setImageAspectRatio(9.0 / 16.0);
        tabs.add(followedTab);
        tabs.add(createApiTab("Top Rated", site.getBaseUrl() + "/api/ts/discover/carousels/top-rated/"));
        tabs.add(createApiTab("Trending", site.getBaseUrl() + "/api/ts/discover/carousels/trending/"));
        return tabs;
    }


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

    private Tab createTab(String title, String url) {
        var updateService = new ChaturbateUpdateService(url, false, (Chaturbate) site);
        return createTab(title, updateService);
    }

    private Tab createTab(String title, PaginatedScheduledService updateService) {
        var tab = new ThumbOverviewTab(title, updateService, site);
        tab.setRecorder(recorder);
        tab.setImageAspectRatio(9.0 / 16.0);
        return tab;
    }

    private Tab createApiTab(String title, String apiUrl) {
        var updateService = new ChaturbateApiUpdateService(apiUrl, (Chaturbate) site);
        return createTab(title, updateService);
    }
}
