export function addVideoTracks(streamServer, apiResponse, av1Supported, dashSupported) {
    if (dashSupported) {
        return addDashTracks(streamServer, apiResponse, av1Supported);
    }

    return addLegacyTracks(streamServer, apiResponse, av1Supported);
}


function addDashTracks(streamServer, apiResponse, av1Supported) {
    var data = [];

    // 720p
    data.push({
        src: streamServer + '/' + apiResponse.stream_url + '/720/manifest.mpd',
        size: 720,
        mode: 'mpd',
    });

    if (av1Supported) {
        // 1080p
        data.push({
            src: streamServer + '/' + apiResponse.stream_url + '/1080/manifest.mpd',
            size: 1080,
            mode: 'mpd',
        });

        // 2160p
        data.push({
            src: streamServer + '/' + apiResponse.stream_url + '/2160/manifest.mpd',
            size: 2160,
            mode: 'mpd',
        });

        if (apiResponse.interpolated == 1) {
            // 1080p Interpolated
            data.push({
                src: streamServer + '/' + apiResponse.stream_url + '/1080i/manifest.mpd',
                size: 1081,
                mode: 'mpd',
            });
        }

        if (apiResponse.interpolated_uhd == 1) {
            // 2160p Interpolated
            data.push({
                src: streamServer + '/' + apiResponse.stream_url + '/2160i/manifest.mpd',
                size: 2161,
                mode: 'mpd',
            });
        }
    }

    return data;
}

function addLegacyTracks(streamServer, apiResponse, av1Supported) {
    var data = [];

    // 720p
    data.push({
        src: streamServer + '/' + apiResponse.stream_url + '/x264.720p.mp4',
        type: 'video/mp4',
        size: 720,
    });

    return data;
}


export function addSubtitleTracks(streamServer, apiResponse) {
    var data = [];

    // Default
    data.push({
        kind: 'captions',
        label: 'English',
        srclang: 'en',
        src: '',
        default: true,
    });

    for (var key in apiResponse.extra_subtitles) {
        data.push({
            kind: 'captions',
            label: apiResponse.extra_subtitles[key] + ' (Auto Transl.)',
            srclang: key,
            src: '',
            default: false,
        });
    }

    return data;
}
