"use strict";
class CGlobData {
    constructor() {
        this.aJobs = null;
        this.pRightTableBody = null;
        this.pLeftTableBody = null;
        this.pJobListTable = null;
    }
    IsNotJobArr() {
        return !this.aJobs;
    }
    GetJobArr() {
        if (!this.aJobs)
            return [];
        return this.aJobs;
    }
    PushJob(oJobInList) {
        if (!this.aJobs)
            this.aJobs = [];
        this.aJobs.push(oJobInList);
    }
    GetJobInList(xJobName) {
        if (!this.aJobs || this.aJobs.length === 0)
            return;
        if (!xJobName) {
            xJobName = sCurrJob;
        }
        else if (!(typeof xJobName === 'string')) {
            if (xJobName.Branch) {
                xJobName = xJobName.Branch.fGetData().name;
            }
            else if (xJobName.DTP && xJobName.DTP.fGetSelTabLen() > 0) {
                xJobName = xJobName.DTP.fGetSelBranch(0).fGetData().name;
            }
        }
        return this.aJobs.find(item => item.name == xJobName);
    }
    GetTreeMode(sJobName) {
        if (!this.aJobs || this.aJobs.length === 0)
            return DEF_TREE_MODE;
        const oJobInList = this.aJobs.find(item => item.name == sJobName);
        if (!oJobInList || !oJobInList.oJobStatus || oJobInList.oJobStatus.view_mode === undefined)
            return DEF_TREE_MODE;
        return oJobInList.oJobStatus.view_mode;
    }
    SetTreeMode(sJobName, nMode) {
        if (!sJobName || nMode < 0 || nMode > MAX_TREE_MODE || nMode === undefined || !this.aJobs || this.aJobs.length === 0)
            return;
        const oJobInList = this.aJobs.find(item => item.name == sJobName);
        if (!oJobInList || !oJobInList.oJobStatus)
            return;
        oJobInList.oJobStatus.view_mode = nMode;
    }
    SettingJobInListFields(jsJobOpt, sJobName) {
        let oJobInList = this.GetJobInList(sJobName);
        SettingJobShortFields(jsJobOpt, oJobInList);
        oSavedData.SaveJobSides(jsJobOpt);
    }
    async PutJobToList(sJobName, nInd) {
        this.aJobs.splice(nInd, 0, CreateTreeItemData(sJobName));
        try {
            const jsJobinfo = await SendRecivePostApiWithRetry("GetJobByName", { "job_name": sJobName });
            this.SettingJobInListFields(jsJobinfo.opt, jsJobinfo.opt.sName);
            this.InsertJobToTables();
            this.MarkNewJobToTables(jsJobinfo.opt.sName);
        }
        catch (oErr) {
            CatchErrProcess(oErr, "GetJobByName '" + (oErr ? oErr.src : "") + ":");
        }
        return this.aJobs[nInd];
    }
    AddGroupToTable(sGroupName) {
        if (this.pJobListTable) {
            const aOpenFolders = this.pJobListTable.root.fGetOpenBranchFolderArr();
            this.AddGroupsToTable(aOpenFolders);
            if (sGroupName) {
                this.pJobListTable.MarkTabRow("name", sGroupName);
            }
            else if (sGroupName === "") {
                this.pJobListTable.fSelTabClean();
                this.pJobListTable.ShowRows();
            }
        }
    }
    MarkJobInJobList(bMarkGroupAll) {
        if (this.pJobListTable) {
            if (bMarkGroupAll) {
                this.pJobListTable.MarkTabRow("name", sAllJobsGroupName);
            }
            bLastPrevSessionJobWasOpend = true;
            if (this.pJobListTable.root.cont && this.pJobListTable.root.cont.length > 0) {
                let tmp = null;
                if (oSavedData.sCurrJob) {
                    tmp = this.pJobListTable.MarkTabRow("name", oSavedData.sCurrJob, this.pJobListTable.root.cont[0]);
                }
                else if (oSavedData.sCurrGroup) {
                    tmp = this.pJobListTable.MarkTabRow("name", oSavedData.sCurrGroup);
                }
                else if (this.GetJobArr().length > 0) {
                    tmp = this.pJobListTable.MarkTabRow("name", this.GetJobArr()[0].name, this.pJobListTable.root.cont[0]);
                }
                if (!tmp) {
                    this.pJobListTable.MarkTabRow("name", this.GetJobArr()[0].name, this.pJobListTable.root.cont[0]);
                }
            }
        }
    }
    ResetJobTable(label) {
        switch (label) {
            case "left":
                this.pLeftTableBody = null;
                break;
            case "right":
                this.pRightTableBody = null;
                break;
            default: this.pJobListTable = null;
        }
    }
    IsJobTable(label) {
        switch (label) {
            case "left": return !!this.pLeftTableBody;
            case "right": return !!this.pRightTableBody;
            default: return !!this.pJobListTable;
        }
    }
    async CreateLeftJobTable(oLeftJobTableDTP) {
        let bIsSelRow = false;
        if (this.pJobListTable) {
            for (let i = 0; i < this.pJobListTable.fGetSelTabLen(); i++) {
                const oSelJob = oLeftJobTableDTP.root.cont.find(it => it.pathEl == this.pJobListTable.fGetSelBranch(i).pathEl);
                if (oSelJob) {
                    oSelJob.bSelested = true;
                    bIsSelRow = true;
                }
            }
            aOpenFoldersInJobListTable = this.pJobListTable.root.fGetOpenBranchFolderArr();
        }
        this.pJobListTable = null;
        this.pLeftTableBody = await CreateTable(oLeftJobTableDTP);
        if (this.pLeftTableBody) {
            if (!bIsSelRow && this.pLeftTableBody.root.cont && this.pLeftTableBody.root.cont.length > 0) {
                if (!sCurrJob) {
                    this.pLeftTableBody.root.cont[0].fMarkSelf(this.pLeftTableBody);
                }
                else {
                    const oRow = this.pLeftTableBody.root.fFindEl(sCurrJob);
                    if (oRow) {
                        oRow.fMarkSelf(this.pLeftTableBody);
                    }
                    else {
                        this.pLeftTableBody.root.cont[0].fMarkSelf(this.pLeftTableBody);
                    }
                }
            }
            this.pLeftTableBody.ShowMarkRowInCenter();
            TableRowClick(this.pLeftTableBody);
        }
    }
    async ShowMainJobTree(arr) {
        if (!domLeftTreeWindow) {
            return;
        }
        if (!this.pJobListTable) {
            const tmp = new CDynTabProp();
            tmp.aHead = [{ field_name: "name", col_name: "Job Name", icon: "job_icon" }];
            const oJT = GetJobTree();
            tmp.sPathFieldName = "name";
            tmp.bWithoutHead = true;
            tmp.domLimWindow = domLeftTreeWindow;
            tmp.bIsTree = true;
            tmp.fRowClick = RightJobTableRowClick;
            tmp.fRightBtn = RightJobTableRightBtn;
            tmp.root.fAddData(oJT.jT, { oFunc: oJT.oF, bNoSelectWithShiftOrCtrl: true, bOpenBrAuto: true, sPathFieldName: "name" });
            tmp.root.cont[0].fAddDataArr(glob.GetJobArr(), { bOpenBrAuto: true, sPathFieldName: "name" });
            if (arr) {
                for (const sPathEl of arr) {
                    const oSelJob = tmp.root.cont[0].cont.find(it => it.pathEl == sPathEl);
                    if (oSelJob) {
                        oSelJob.bSelested = true;
                    }
                }
            }
            this.pJobListTable = await CreateTable(tmp);
            this.AddGroupsToTable(aOpenFoldersInJobListTable);
        }
        else {
            this.pJobListTable.ShowRows();
        }
    }
    ShowJobTree() {
        if (this.pLeftTableBody) {
            const aSelJobs = [];
            for (let i = 0; i < this.pLeftTableBody.fGetSelTabLen(); i++) {
                aSelJobs.push(this.pLeftTableBody.fGetSelBranch(i).pathEl);
            }
            this.ShowMainJobTree(aSelJobs);
        }
        else {
            this.ShowMainJobTree();
        }
        if (this.pJobListTable) {
            this.pJobListTable.ShowFirstSelectRow();
        }
        this.pLeftTableBody = null;
    }
    InsertJobToTables() {
        if (this.pRightTableBody) {
            this.pRightTableBody.fClear();
            this.pRightTableBody.root.fAddDataArr(glob.GetJobArr(), { oDTP: this.pRightTableBody });
            this.pRightTableBody.ShowTable();
        }
        if (this.pLeftTableBody) {
            this.pLeftTableBody.fClear();
            this.pLeftTableBody.root.fAddDataArr(glob.GetJobArr(), { oDTP: this.pLeftTableBody });
            this.pLeftTableBody.ShowTable();
        }
        if (this.pJobListTable) {
            const nAllJobFolder = this.pJobListTable.root.cont[0].folder;
            this.pJobListTable.root.cont[0].fClear();
            this.pJobListTable.root.cont[0].fAddDataArr(glob.GetJobArr(), { sPathFieldName: "name", bOpenBrAuto: true });
            this.pJobListTable.root.cont[0].folder = nAllJobFolder;
            this.pJobListTable.ShowTable();
            ListGroupRequest();
        }
    }
    RenameJobInTable(sOldName, sNewName) {
        if (this.pRightTableBody) {
            const oBranch = this.pRightTableBody.root.fFindEl(sOldName);
            if (oBranch) {
                oBranch.pathEl = sNewName;
                oBranch.fSetData("name", sNewName);
                this.pRightTableBody.ShowTable();
            }
        }
        if (this.pLeftTableBody) {
            const oBranch = this.pLeftTableBody.root.fFindEl(sOldName);
            if (oBranch) {
                oBranch.pathEl = sNewName;
                oBranch.fSetData("name", sNewName);
                this.pLeftTableBody.ShowTable();
            }
        }
        if (this.pJobListTable) {
            const oBranch = this.pJobListTable.root.cont[0].fFindEl(sOldName);
            if (oBranch) {
                oBranch.pathEl = sNewName;
                oBranch.fSetData("name", sNewName);
                this.pJobListTable.ShowTable();
            }
            ListGroupRequest();
        }
    }
    DeleteJobFromTable(nNextJob) {
        if (glob.GetJobArr().length === 0) {
            if (this.pRightTableBody) {
                this.pRightTableBody.fClear();
                this.pRightTableBody.ShowTable();
            }
            if (this.pLeftTableBody) {
                this.pLeftTableBody.fClear();
                this.pLeftTableBody.ShowTable();
            }
            if (this.pJobListTable) {
                const aOpenFolders = this.pJobListTable.root.fGetOpenBranchFolderArr();
                this.pJobListTable.root.cont[0].fClear();
                this.AddGroupsToTable(aOpenFolders);
                this.pJobListTable.ShowTable();
            }
            ChangeCurrJob("", "");
        }
        else {
            if (this.pRightTableBody) {
                this.pRightTableBody.fClear();
                this.pRightTableBody.root.fAddDataArr(glob.GetJobArr(), { oDTP: this.pRightTableBody });
                this.pRightTableBody.ShowTable();
            }
            if (this.pLeftTableBody) {
                this.pLeftTableBody.fClear();
                this.pLeftTableBody.root.fAddDataArr(glob.GetJobArr(), { oDTP: this.pLeftTableBody });
                this.pLeftTableBody.ShowTable();
            }
            if (this.pJobListTable) {
                const aOpenFolders = this.pJobListTable.root.fGetOpenBranchFolderArr();
                const nAllJobFolder = this.pJobListTable.root.cont[0].folder;
                this.pJobListTable.root.cont[0].fClear();
                this.pJobListTable.root.cont[0].fAddDataArr(glob.GetJobArr(), { sPathFieldName: "name", bOpenBrAuto: true });
                this.pJobListTable.root.cont[0].folder = nAllJobFolder;
                this.AddGroupsToTable(aOpenFolders);
                this.pJobListTable.ShowTable();
            }
            const tab = glob.GetActiveJobTable();
            if (tab) {
                tab.fSelTabPush(nNextJob);
                tab.ShowMarkRowInCenter();
                TableRowClick(tab, null, true);
            }
        }
    }
    MarkNewJobToTables(sJobName) {
        if (sJobName != sNewJob) {
            return;
        }
        if (this.pRightTableBody) {
            this.pRightTableBody.MarkTabRow("name", sNewJob);
        }
        if (this.pLeftTableBody) {
            this.pLeftTableBody.MarkTabRow("name", sNewJob);
        }
        else if (this.pJobListTable) {
            if (this.pJobListTable.aDeploedTable[0]._branch_.folder == FOLDER_CLOSE) {
                this.pJobListTable.aDeploedTable[0]._branch_.folder = FOLDER_OPEN;
                this.pJobListTable.ShowTable();
            }
            this.pJobListTable.MarkTabRow("name", sNewJob, this.pJobListTable.aDeploedTable[0]._branch_);
        }
        sNewJob = "";
    }
    AddGroupsToTable(aOpenFolders) {
        if (!this.pJobListTable || !aGlobGroup || !this.pJobListTable.root.cont) {
            return;
        }
        this.pJobListTable.root.cont.splice(1);
        aGlobGroup.sort((a, b) => CompareTextWithNumbers(a.m_sGroupName, b.m_sGroupName));
        aGlobGroup.map(it => { if (aOpenFolders.includes(it.m_sGroupName))
            it.bOpenFolder = true; });
        const oFuncGrop = { fRightBtn: AddOrRemoveGroupJob, fRowClick: GroupRowClick };
        const oFuncInGrop = { fRightBtn: RightJobTableRightBtn, fRowClick: RightJobTableRowClick };
        const pGroupListSubmenu = jsJobMenu.find(it => it.title == "Str_AddToGroup");
        if (pGroupListSubmenu) {
            pGroupListSubmenu.noactive = false;
            pGroupListSubmenu.submenu = [];
        }
        for (let it of aGlobGroup) {
            if (!oSavedData.oOpts.bShowBackupSyncGroups && it.m_eGroupType < 4)
                continue;
            const oCurrGroup = this.pJobListTable.root.fAddData(it, { oFunc: oFuncGrop, fDataProcessor: GroupNameProcessing, sPathFieldName: "m_sGroupName", bNoSelectWithShiftOrCtrl: true });
            if (!oCurrGroup)
                continue;
            const arr = GroupJobProcessing(it.m_jobsInGroup, this.pJobListTable);
            oCurrGroup.fAddDataArr(arr, { oFunc: oFuncInGrop, sPathFieldName: "name" });
            oCurrGroup.fSort(this.pJobListTable, "name");
            if (pGroupListSubmenu && it.m_eGroupType == GROUP_TYPE_USER) {
                pGroupListSubmenu.submenu.push({ img: "C_Ena_Chk", "title": it.m_sGroupName, command: "AddJobToGroup('" + it.m_sGroupName + "', xAddArgs)" });
            }
        }
        this.pJobListTable.ShowTable();
    }
    JobListDblClick(sGroupName, sJobName) {
        if (this.pJobListTable) {
            const oGroupBranch = this.pJobListTable.fFindBranchArr([sGroupName]);
            if (!oGroupBranch)
                return;
            if (oGroupBranch.folder !== FOLDER_OPEN) {
                oGroupBranch.folder = FOLDER_OPEN;
                this.pJobListTable.ShowTable();
            }
            const branch = this.pJobListTable.fFindBranchArr([sGroupName, sJobName]);
            if (branch) {
                branch.fMarkAndShow(this.pJobListTable);
                TableRowClick(this.pJobListTable, branch);
            }
        }
    }
    SetJobList(oDTP) {
        this.pJobListTable = oDTP;
    }
    SetLeftJobTable(oDTP) {
        this.pLeftTableBody = oDTP;
    }
    SetRightJobTable(oDTP) {
        this.pRightTableBody = oDTP;
    }
    ChangeIconOfGroupJobs(sJobName, sIcon) {
        if (!this.pJobListTable || !this.pJobListTable.root.cont || this.pJobListTable.root.cont.length < 2) {
            return;
        }
        for (let i = 1; i < this.pJobListTable.root.cont.length; i++) {
            for (const oJob of this.pJobListTable.root.cont[i].jsBody) {
                if (oJob.name == sJobName) {
                    oJob.job_icon = sIcon;
                    break;
                }
            }
        }
    }
    JustRefreshAllJobTables(bIsDiff) {
        if (this.pRightTableBody && !bStopUpdateJobTable) {
            if (bIsDiff) {
                this.pRightTableBody.ShowTable();
            }
            else {
                this.pRightTableBody.ShowRows();
            }
        }
        if (this.pLeftTableBody) {
            if (bIsDiff) {
                this.pLeftTableBody.ShowTable();
            }
            else {
                this.pLeftTableBody.ShowRows();
            }
        }
        else if (bIsDiff) {
            this.ShowMainJobTree();
        }
    }
    GetActiveJobTable(bOnlyLeft) {
        if (this.pLeftTableBody)
            return this.pLeftTableBody;
        if (this.pRightTableBody && !bOnlyLeft)
            return this.pRightTableBody;
        return this.pJobListTable;
    }
    GetExprolerWinId() {
        if (this.oBrowseDialog && this.oBrowseDialog.oMenu) {
            return this.oBrowseDialog.oMenu.id;
        }
        return "";
    }
}
async function FillRightWindow(bNewIcons) {
    if (!domRightTableWindow)
        return;
    domRightTableWindow.innerHTML = "";
    domRightTableWindow.tabIndex = -1;
    domRightTableWindow.classList.remove("dt_lim_window");
    if (sCurrJob) {
        let oJobInList = glob.GetJobInList(sCurrJob);
        if (!oJobInList)
            return;
        if (!oJobInList.oSideCoords || !oJobInList.oSideCoords[0].opts) {
            try {
                const oJobData = await SendRecivePostApiWithRetry("GetJobByName", { "job_name": oJobInList.name });
                SettingJobShortFields(oJobData.opt, oJobInList);
            }
            catch { }
        }
        glob.ResetJobTable("right");
        domRightTableWindow.classList.remove("flex_gor");
        domRightTableWindow.classList.add("flex_vert");
        let errors = document.createElement("div");
        domRightTableWindow.append(errors);
        errors.className = "job_errors";
        errors.id = "job_error";
        errors.style.display = "none";
        let domJobShortInfo = document.createElement("div");
        domJobShortInfo.id = "job_summary";
        domRightTableWindow.append(domJobShortInfo);
        const domAbove = document.createElement("div");
        domAbove.className = "flex_1_1_100";
        domJobShortInfo.append(domAbove);
        const domTopOfDomAbove = document.createElement("div");
        domTopOfDomAbove.className = "flex_gor";
        domTopOfDomAbove.id = "idTopOfDomAbove";
        domAbove.append(domTopOfDomAbove);
        let domSwtchTreeFltBtnPnl = document.createElement("div");
        domSwtchTreeFltBtnPnl.id = "idSwtchTreeFltBtnPnl";
        domSwtchTreeFltBtnPnl.className = "flex_gor_center gray_panel";
        domTopOfDomAbove.append(domSwtchTreeFltBtnPnl);
        const domJobTreeControls = document.createElement("div");
        domJobTreeControls.className = "flex_gor_center gray_panel in_flex_go_right";
        domJobTreeControls.id = "idJobTreeControls";
        domTopOfDomAbove.append(domJobTreeControls);
        let domRealSummaryInfo = document.createElement("div");
        domAbove.append(domRealSummaryInfo);
        domRealSummaryInfo.id = "real_summary_info";
        domRealSummaryInfo.style.display = "none";
        let label = document.createElement("span");
        domRealSummaryInfo.append(label);
        label.className = "debug_job_info";
        label.append(sCurrJob + ": ");
        let label2 = document.createElement("span");
        domRealSummaryInfo.append(label2);
        label2.className = "debug_job_info";
        label2.id = "job_status_info";
        if (oJobInList.isWaiting == JOB_COMMAND_ANALIZE)
            label2.innerHTML = GetLocaleText("str_analysis_request_sent");
        else if (oJobInList.status)
            label2.innerHTML = oJobInList.status;
        else
            label2.innerHTML = GetLocaleText("Hint_Click_Analyze");
        let detale = document.createElement("span");
        domRealSummaryInfo.append(detale);
        detale.className = "job_status_detale";
        detale.id = "job_status_detale_" + sCurrJob;
        detale.innerHTML = GetJobStatusString(oJobInList.oJobStatus);
        const domHugeTexi = document.createElement("div");
        domHugeTexi.id = "huge_wait_text_label";
        domJobShortInfo.append(domHugeTexi);
        let pbBox = CreateProgressBar(domJobShortInfo, { boxId: "main_progress_bar_box", pbId: "progress_bar_" + sCurrJob, persentId: "sync_analie_percent_num" });
        pbBox.style.display = "none";
        const domLeftMsg = document.createElement("div");
        domLeftMsg.id = "for_left_msg";
        const domRightMsg = document.createElement("div");
        domRightMsg.id = "for_right_msg";
        pbBox.append(domLeftMsg);
        pbBox.append(domRightMsg);
        const domBelow = document.createElement("div");
        domBelow.className = "flex_1_1_100";
        domJobShortInfo.append(domBelow);
        let domJobTreeBox = document.createElement("div");
        domJobTreeBox.id = "job_tree_window";
        domRightTableWindow.append(domJobTreeBox);
        glob.ResetJobTable("right");
        SetStretchEl();
        const oDTP = jsJobsTables[sCurrJob];
        if (oDTP) {
            if (!oJobInList.aTotals) {
                oJobInList.aTotals = [];
            }
            if (oJobInList.oJobStatus && oJobInList.oJobStatus.job_result != RUN_result_term_error) {
                CreatePanelOfJobModeView(oJobInList.aTotals, oJobInList.oJobStatus.view_mode);
            }
            if (oDTP.fIsNotEmpty()) {
                await ShowTreeIfThisNeeds(sCurrJob, oDTP, oJobInList);
            }
            else {
                await ShowTextIfNoTree(oJobInList, true);
            }
        }
        else {
            if (oJobInList.oJobStatus && oJobInList.oJobStatus.job_result != RUN_result_term_error) {
                if (oJobInList.aTotals) {
                    CreatePanelOfJobModeView(oJobInList.aTotals, oJobInList.oJobStatus.view_mode);
                }
                await ShowTextIfNoTree(oJobInList, true);
            }
        }
        let domTreeBlock = BlockAndWaitCreate(domRightTableWindow, "tree_block", 8);
        if (!oJobInList.bBlockTree) {
            domTreeBlock.style.display = "none";
        }
    }
    FillCurrJobDetalesWindow(bNewIcons);
}
async function FillCurrJobDetalesWindow(bNewIcons) {
    if (sCurrJob) {
        let oJobInList = glob.GetJobInList(sCurrJob);
        if (!oJobInList) {
            return;
        }
        if (!oJobInList.oSideCoords) {
            const aJobSideCoords = await JobListWithSmallDataRequest(aJobFieldsForSideCoords, [sCurrJob]);
            if (aJobSideCoords && aJobSideCoords.length === 1 && aJobSideCoords[0].opt) {
                oJobInList.oSideCoords = aJobSideCoords[0].opt.side_coords;
            }
        }
        if (!oJobInList.oSideCoords) {
            return;
        }
        if (bNewIcons) {
            oJobInList.iconFsL = "";
            oJobInList.iconFsR = "";
        }
        SetSideDetailsInfo(domLeftUrl, domLeftSrcImg, oJobInList, 0, oJobInList.left_url, oJobInList.right_url, "left_side_details");
        SetSideDetailsInfo(domRightUrl, domRightSrcImg, oJobInList, 1, oJobInList.left_url, oJobInList.right_url, "right_side_details");
        let img = SetImg(oJobInList.direct, "var(--job-detale-img-size)", "abs_pos_img");
        if (img) {
            domJobDirect.innerHTML = "";
            domJobDirect.append(img);
        }
    }
}
function ChangeJobDirection(eDir) {
    const oFCO = new CForChangeOptions;
    oFCO.eJobDirection = eDir;
    if (!oFCO.bIsDialogOpen) {
        JobOptionsForChangeRequest(oFCO);
    }
}
function LeftWindowLim(domLeftWindow, sWidth) {
    const nWidth = domLeftWindow.getBoundingClientRect().width;
    if (nWidth + 10 > document.documentElement.clientWidth) {
        return (document.documentElement.clientWidth - 10) + "px";
    }
    return sWidth;
}
function LeftJobTableCreating(bFirstTime) {
    domLeftTreeWindow.innerHTML = "";
    if (glob.IsJobTable("right")) {
        domRightTableWindow.innerHTML = "";
        glob.ResetJobTable("right");
        domRightTableWindow.tabIndex = -1;
        domRightTableWindow.classList.remove("dt_lim_window");
    }
    domLeftWindow.style.flex = "0 0 " + LeftWindowLim(domLeftTreeWindow, oSavedData.oJobTableParams.sLeftTableWidth);
    oSavedData.oJobTableParams.bMoreInfoOpen = true;
    localStorage.setItem("oSavedData", JSON.stringify(oSavedData));
    domLeftImgMenu.classList.remove("panel_with_bottom_border");
    if (bFirstTime && oSavedData.sCurrJob) {
        if (glob.GetJobInList(oSavedData.sCurrJob)) {
            ChangeCurrJob(oSavedData.sCurrJob, "");
        }
        else if (glob.GetJobArr().length > 0) {
            ChangeCurrJob(glob.GetJobArr()[0].name, "");
        }
        FillCurrJobDetalesWindow(true);
    }
    else if ((!sCurrJob || bFirstTime && !oSavedData.sCurrJob) && glob.GetJobArr().length > 0) {
        ChangeCurrJob(glob.GetJobArr()[0].name, "");
    }
    bLastPrevSessionJobWasOpend = true;
    const oLeftJobTableDTP = new CDynTabProp();
    oLeftJobTableDTP.aHead = jsRightWinowsTableHead;
    oLeftJobTableDTP.domLimWindow = domLeftTreeWindow;
    oLeftJobTableDTP.bStriped = true;
    oLeftJobTableDTP.bNeedSort = true;
    oLeftJobTableDTP.fSaveColsSize = (arr) => {
        for (let i = 0; i < oLeftJobTableDTP.aTableColsWidth.length; i++) {
            if (arr[i] && arr[i] > 0) {
                oLeftJobTableDTP.aTableColsWidth[i] = arr[i];
            }
        }
        oSavedData.aLeftJobTableColsSize = oLeftJobTableDTP.aTableColsWidth;
        localStorage.setItem("oSavedData", JSON.stringify(oSavedData));
    };
    oLeftJobTableDTP.fGetColsSizeFromLocStor = () => {
        if (oSavedData.aLeftJobTableColsSize && oSavedData.aLeftJobTableColsSize.length) {
            oLeftJobTableDTP.aTableColsWidth = oSavedData.aLeftJobTableColsSize;
            return true;
        }
        return false;
    };
    oLeftJobTableDTP.fRowClick = function (oDepBr) {
        ChangeCurrJob(oDepBr.fGetData().name, "");
        FillRightWindow();
    };
    oLeftJobTableDTP.fRightBtn = function (e, Branch, DTP) {
        if (DTP.fGetSelTabLen() == 1) {
            ChangeCurrJob(Branch.fGetData().name, "");
        }
        JobContextMenu(jsJobMenu, e.clientX, e.clientY, e.clientX, e.target, false, { Branch, DTP });
    };
    oLeftJobTableDTP.fDataProcessor = MainJobTableProc;
    oLeftJobTableDTP.root.fAddDataArr(glob.GetJobArr(), { sPathFieldName: "name", fDataProcessor: MainJobTableProc });
    glob.CreateLeftJobTable(oLeftJobTableDTP);
    let btnMoreInfo = document.getElementById("more_info");
    if (btnMoreInfo) {
        btnMoreInfo.innerHTML = 'Less <img src="web-ui/svg/L_Dis_Arr_Nofl.svg" alt="&#9204;" style="position:absolute; right:0; top:0; bottom:0; margin:auto">';
        btnMoreInfo.onclick = CreateLeftJobTree;
    }
    bJobTreeNarrowMode = true;
    if (sCurrJob && jsJobsTables[sCurrJob]) {
        jsJobsTables[sCurrJob].bWasStretch = false;
        jsJobsTables[sCurrJob].SetColsWidth();
    }
    MoveJobDetaleBox();
}
function SetLeftWindowWidth(sWindowName) {
    const sLeftTableWidth = domLeftWindow.style.flex.slice(4);
    if (sLeftTableWidth.endsWith("%")) {
        oSavedData.oJobTableParams[sWindowName] = sLeftTableWidth;
    }
    else {
        const nWidth = Number(sLeftTableWidth.slice(0, -2));
        if (nWidth && document.documentElement.clientWidth && nWidth < document.documentElement.clientWidth) {
            oSavedData.oJobTableParams[sWindowName] = (nWidth / document.documentElement.clientWidth * 100) + "%";
        }
    }
    localStorage.setItem("oSavedData", JSON.stringify(oSavedData));
}
function CreateLeftJobTree() {
    domLeftTreeWindow.innerHTML = "";
    domLeftWindow.style.flex = "0 0 " + LeftWindowLim(domLeftTreeWindow, oSavedData.oJobTableParams.sJobListWidth);
    oSavedData.oJobTableParams.bMoreInfoOpen = false;
    localStorage.setItem("oSavedData", JSON.stringify(oSavedData));
    domLeftImgMenu.classList.add("panel_with_bottom_border");
    glob.ShowJobTree();
    let btnMoreInfo = document.getElementById("more_info");
    if (btnMoreInfo) {
        btnMoreInfo.innerHTML = 'More <img src="web-ui/svg/R_Dis_Arr_Nofl.svg" alt="&#9205;" style="position:absolute; right:0; top:0; bottom:0; margin:auto">';
        btnMoreInfo.onclick = () => {
            LeftJobTableCreating();
        };
    }
    bJobTreeNarrowMode = false;
    if (sCurrJob && jsJobsTables[sCurrJob]) {
        jsJobsTables[sCurrJob].bWasStretch = false;
        jsJobsTables[sCurrJob].SetColsWidth();
    }
    MoveJobDetaleBox();
}
let domUserInfo = null;
function SetUserIdShow() {
    const sJWTToken = localStorage.getItem("sBearerToken");
    if (sJWTToken) {
        domUserInfo = document.createElement("div");
        domUserInfo.className = "user_comp_info";
        domUserAndCompInfo.appendChild(domUserInfo);
        const domUserImg = SetImg("account-16", "1.0rem");
        if (domUserImg) {
            domUserInfo.append(domUserImg);
        }
        const token_parts = sJWTToken.split(".");
        if (token_parts.length > 2) {
            token_parts.pop();
            let sTokenPayload = atob(token_parts.pop());
            ;
            try {
                const jwtTokenPayload = JSON.parse(sTokenPayload);
                if (jwtTokenPayload.loggedInAs) {
                    domUserInfo.append(jwtTokenPayload.loggedInAs.toLowerCase());
                }
            }
            catch (e) {
                console.log("Bad JWT Token payload", e);
            }
        }
    }
}
function MoveJobDetaleBox() {
    if (domCurrJobName.getBoundingClientRect().right > domUserAndCompInfo.getBoundingClientRect().left) {
        domLowBox.appendChild(domCurrJobInfo);
        domRightImgMenu.classList.remove("panel_with_bottom_border");
        domCurrJobInfo.classList.add("panel_with_bottom_border");
    }
    else {
        domUpperBox.appendChild(domCurrJobInfo);
        domRightImgMenu.classList.add("panel_with_bottom_border");
        domCurrJobInfo.classList.remove("panel_with_bottom_border");
    }
}
function SetLayout() {
    CreateImgButtonBar(jsLeftImgMenu, domLeftImgMenu, { bDontClearContainer: true, sImgSizeH: "2rem", sImgSizeW: "3rem", sClass: "big_button" });
    DisableClassEl("common_auto_off");
    DisableClassEl("common_auto_on");
    DisableClassEl("account_sync_off");
    DisableClassEl("account_sync_on");
    SetMainMenu(domMainMenu, jsMainMenu);
    const domHtmlErrPlace = document.createElement("div");
    domHtmlErrPlace.style.flex = "1 1 100%";
    domMainMenu.append(domHtmlErrPlace);
    const sGsComputerId = GetCookieByName("jscompid");
    if (sGsComputerId) {
        const domServerInfo = document.createElement("div");
        domServerInfo.className = "user_comp_info";
        domUserAndCompInfo.appendChild(domServerInfo);
        const domCompImg = SetImg("Connection", "1.2rem");
        if (domCompImg) {
            domServerInfo.append(domCompImg);
        }
        domServerInfo.append(sGsComputerId);
        DeleteCookie("jscompid");
    }
    DisableClassEl("accaunt_on");
    DisableClassEl("auto_run_on");
    CreateImgButtonBar(jsRightLeftImgMenu, domRightLeftImgMenu, { sImgSizeH: "1.75rem", sClass: "big_button" });
    CreateImgButtonBar(jsRightRightImgMenu, domRightRightImgMenu, { sImgSizeH: "1.75rem", sClass: "big_button" });
    CreateImgButtonBar(jsGroupImgMenu, domGroupBigButtons, { sImgSizeH: "1.75rem", sClass: "big_button" });
    DeactivateClassEl("settings_btn");
    DeactivateClassEl("btn_sync_and_analize");
    DisableClassEl("btn_path_change");
    DisableClassEl("btn_stop_job");
    DisableClassEl("auto_on");
    DisableClassEl("auto_off");
    NewsPolling();
    if (oSavedData.oJobTableParams.bLogWinOpen) {
        OpenLog();
    }
    Authentication();
    ChangeCurrJob("", "");
    SetStretchEl();
    domLeftWindow.style.flex = "0 0 " + oSavedData.oJobTableParams.sJobListWidth;
}
