var baseAPIUrl = '';
var extensionId = '';
var azureAuthenticationHeader;
var ganttObj;
VSS.require(["VSS/Authentication/Services"],
    function (VSS_Auth_Service) {
        VSS.getAccessToken().then(async function (token) {
            const urlParams = new URLSearchParams(window.location.search);
            var releaseId = urlParams.get('rId');
            var authHeader = VSS_Auth_Service.authTokenManager.getAuthorizationHeader(token);
            var authHeaderSplit = authHeader.split(' ');
            //$("#loadingSpinner").show();
            azureAuthenticationHeader = authHeaderSplit[1];
            const config = await IndexLibrary.GetExtensionConfig();
            baseAPIUrl = config.apiBaseUrl;
            extensionId = config.extensionId;

            const response = await IndexLibrary.GetRequest({
                endpoint: `/api/Release/GetReleaseGantt/${releaseId}`
            });
            const releaseWorkItemsData = await response.text();
            var a = JSON.parse(releaseWorkItemsData);
            ganttObj = new Gantt("#gantt", a);

            $('.bar-wrapper').on('mousedown', (e, element) => {
                e.preventDefault();
                e.stopPropagation();
            });
        })
    }
)

function NavigateToEditRelease() {
    const urlParams = new URLSearchParams(window.location.search);
    var releaseId = urlParams.get('rId');
    window.location.href = 'create-release.html?rId=' + releaseId;
}

function ChangeGanttView(viewType) {
    ganttObj.change_view_mode(viewType);
}