package ctbrec.ui.sites.cherrytv;

import ctbrec.sites.cherrytv.CherryTv;
import ctbrec.ui.sites.AbstractTabProvider;
import ctbrec.ui.tabs.ThumbOverviewTab;
import javafx.scene.Scene;
import javafx.scene.control.Tab;

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

public class CherryTvTabProvider extends AbstractTabProvider {

    private final CherryTvFollowedTab followedTab;

    public CherryTvTabProvider(CherryTv cherryTv) {
        super(cherryTv);

        followedTab = new CherryTvFollowedTab("Following", (CherryTv) site);
        followedTab.setImageAspectRatio(1);
        followedTab.preserveAspectRatioProperty().set(false);
        followedTab.setRecorder(recorder);
    }

    @Override
    protected List<Tab> getSiteTabs(Scene scene) {
        List<Tab> tabs = new ArrayList<>();

        tabs.add(createTab("Female", site.getBaseUrl() + "/graphql?operationName=findBroadcastsByPage&variables={\"slug\":\"girls\",\"limit\":${limit},\"cursor\":${offset}}&extensions={\"persistedQuery\":{\"version\":1,\"sha256Hash\":\"96e6b702b94bcf2b1875b6e0e76f1b2128e09aee1f3fb2977d08e114b5c9428c\"}}"));
        tabs.add(createTab("Trans", site.getBaseUrl() + "/graphql?operationName=findBroadcastsByPage&variables={\"slug\":\"trans\",\"limit\":${limit},\"cursor\":${offset}}&extensions={\"persistedQuery\":{\"version\":1,\"sha256Hash\":\"96e6b702b94bcf2b1875b6e0e76f1b2128e09aee1f3fb2977d08e114b5c9428c\"}}"));
        tabs.add(createTab("Group Show", site.getBaseUrl() + "/graphql?operationName=findBroadcastsByPage&variables={\"slug\":\"groupshow\",\"limit\":${limit},\"cursor\":${offset}}&extensions={\"persistedQuery\":{\"version\":1,\"sha256Hash\":\"96e6b702b94bcf2b1875b6e0e76f1b2128e09aee1f3fb2977d08e114b5c9428c\"}}"));
        tabs.add(followedTab);
        return tabs;
    }

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

    private Tab createTab(String name, String url) {
        var updateService = new CherryTvUpdateService(url, (CherryTv) site, false);
        var tab = new ThumbOverviewTab(name, updateService, site);
        tab.setImageAspectRatio(9.0 / 16.0);
        tab.preserveAspectRatioProperty().set(false);
        tab.setRecorder(recorder);
        return tab;
    }

}
