$(function() {
    if (isStreamListPage()) {
        const table = document.querySelector('.stream-table');
        if (table) {
            const rows = Array.from(table.querySelectorAll('tr'));

            const priorityIds = ["934475739", "934558973"];

            rows.sort((a, b) => {
              const aId = a.getAttribute('data-training-id');
              const bId = b.getAttribute('data-training-id');

              if (priorityIds.includes(aId) && priorityIds.includes(bId)) {
                return priorityIds.indexOf(aId) - priorityIds.indexOf(bId);
              }

              if (priorityIds.includes(aId)) return -1;
              if (priorityIds.includes(bId)) return 1;
              return 0;
            });

            rows.forEach(row => row.remove());
            const tbody = table.querySelector('tbody') || table;
            rows.forEach(row => tbody.appendChild(row));
        }
    }
    function createElement(tag, className) {
        const element = document.createElement(tag);
        if (className) element.className = className;
        return element;
    }

    function removeLegacyGcDecor() {
        document.querySelectorAll('.bonus-banner, a.bonus-banner').forEach((el) => {
            const wrap = el.closest('a.banner') || el;
            wrap.remove();
        });

        document.querySelectorAll('.right-panel .info-block, .right-panel .ultima-block, .right-panel .rating-block, .right-panel .calendar-block, .right-panel .sertificate-block').forEach((el) => {
            el.remove();
        });

        document.querySelectorAll('.right-panel').forEach((panel) => {
            if (!panel.children.length) panel.remove();
        });
    }

    function isStreamListPage() {
        const href = window.location.href;
        const path = (href.split(/[?#]/)[0] || '').replace(/\/+$/, '');
        return (
            /\/teach\/control$/.test(path) ||
            /\/teach\/control\/stream$/.test(path) ||
            /\/teach\/control\/stream\/index$/.test(path)
        );
    }

    if (isStreamListPage()) {
        document.querySelectorAll('.right-panel').forEach((el) => el.remove());
        document.body.classList.add('kbclinic-stream-list');
        if (!window.userInfo || !window.userInfo.isAdmin) {
            document.body.classList.add('kbclinic-user-nonadmin');
        }
    }

    /* Figma «Страница тренингов» → /stream и /stream/index
       Картинки: window.kbclinicAssets или CSS-переменные */
    function initTrainingsPageDesign() {
        if (!isStreamListPage()) return;

        const assets = Object.assign({
            courseCardIllust: 'https://fs.getcourse.ru/fileservice/file/download/a/951813/sc/301/h/a5312bbb3547d48f9eab56545cef99ec.png',
            ovalDoctor: 'https://fs.getcourse.ru/fileservice/file/download/a/951813/sc/369/h/dd3e0b088ba8162ba3cbaf871dc5bc80.png',
            ovalCredentials: ''
        }, window.kbclinicAssets || {});

        const root = document.documentElement;
        if (assets.courseCardIllust) {
            root.style.setProperty('--course-card-illust', `url("${assets.courseCardIllust}")`);
        }
        if (assets.ovalDoctor) {
            root.style.setProperty('--oval-doctor', `url("${assets.ovalDoctor}")`);
        }

        removeLegacyGcDecor();

        document.querySelectorAll('.page-header').forEach((el) => {
            el.style.display = 'none';
        });

        if (!window.userInfo || !window.userInfo.isAdmin) {
            document.querySelectorAll(
                '.xdget-root h3.xdget-header, .xdget-root .xdget-block.xdget-header, .empty-breadcrumbs'
            ).forEach((el) => {
                el.style.display = 'none';
            });
            hideStreamEventsBlock();
        }

        initTrainingCards();
        initOvalSection(assets.ovalDoctor);
    }

    function hideStreamEventsBlock() {
        if (window.userInfo && window.userInfo.isAdmin) return;

        const byId = document.getElementById('xdget330885');
        if (byId) {
            byId.style.display = 'none';
        }

        document.querySelectorAll('.xdget-root .xdget-block.col-md-4').forEach((el) => {
            if (/актуальные\s+события/i.test(el.textContent)) {
                el.style.display = 'none';
            }
        });
    }

    function formatTrainingCardTitle(text) {
        const cleaned = (text || '').trim().replace(/\s+/g, ' ');
        if (!cleaned) return '';
        if (/^курс:/i.test(cleaned)) {
            return cleaned.replace(/^курс:\s*/i, 'КУРС: ').toUpperCase();
        }
        return cleaned.toUpperCase();
    }

    function enhanceTrainingCardBody(body) {
        if (!body) return;

        body.classList.add('kb-training-card__body');

        const title = body.querySelector('.stream-title');
        const desc = Array.from(body.children).find(
            (el) =>
                el.tagName === 'DIV' &&
                !el.classList.contains('kb-training-card__cta') &&
                !el.classList.contains('course-card__cta') &&
                !el.classList.contains('stream-card__cta')
        );

        if (title) {
            title.classList.add('kb-training-card__title');
            title.textContent = formatTrainingCardTitle(title.textContent);
        }

        if (desc) {
            desc.classList.add('kb-training-card__desc');
        }

        let cta = body.querySelector('.kb-training-card__cta, .course-card__cta, .stream-card__cta');
        if (!cta) {
            cta = createElement('span', 'kb-training-card__cta');
            cta.textContent = 'Пройти обучение';
            body.appendChild(cta);
        } else {
            cta.classList.add('kb-training-card__cta');
        }
    }

    function initTrainingCards() {
        const wrapped = document.querySelector('.col-md-12.course-card > .course-card__inner');
        if (wrapped) {
            const col = wrapped.closest('.col-md-12');
            const text = wrapped.querySelector('.course-card__text');
            if (col && text) {
                col.innerHTML = text.innerHTML;
                col.classList.remove('course-card');
            }
        }

        const rows = document.querySelectorAll(
            '.xdget-root .row > .col-md-12 .stream-table tr.training-row'
        );

        rows.forEach((row, index) => {
            const link = row.querySelector('td > a');
            if (!link) return;

            const td = link.closest('td');
            const table = link.closest('.stream-table');
            if (table) table.classList.add('course-card-table');

            const isFeatured = index === 0;

            if (isFeatured) {
                link.querySelectorAll('.course-card__illust').forEach((el) => el.remove());

                if (link.classList.contains('course-card')) {
                    enhanceTrainingCardBody(link.querySelector('.course-card__body'));
                    return;
                }

                link.classList.add('course-card');
                row.classList.add('course-card-row');
                if (td) td.classList.add('course-card-td');

                if (!link.querySelector('.course-card__body')) {
                    const body = createElement('div', 'course-card__body');
                    Array.from(link.childNodes).forEach((node) => body.appendChild(node));
                    link.appendChild(body);
                }

                enhanceTrainingCardBody(link.querySelector('.course-card__body'));
                return;
            }

            if (link.classList.contains('stream-card')) {
                enhanceTrainingCardBody(link.querySelector('.stream-card__body'));
                return;
            }

            link.classList.add('stream-card');
            row.classList.add('stream-card-row');
            if (td) td.classList.add('stream-card-td');

            if (!link.querySelector('.stream-card__body')) {
                const body = createElement('div', 'stream-card__body');
                Array.from(link.childNodes).forEach((node) => body.appendChild(node));
                link.appendChild(body);
            }

            enhanceTrainingCardBody(link.querySelector('.stream-card__body'));
        });
    }

    function initOvalSection(doctorPhotoUrl) {
        if (document.querySelector('.oval-section')) return;

        const photoSrc = doctorPhotoUrl ||
            'https://fs.getcourse.ru/fileservice/file/download/a/951813/sc/369/h/dd3e0b088ba8162ba3cbaf871dc5bc80.png';

        const root = document.querySelector('.xdget-root');
        const trainingsBlock = document.querySelector(
            '.xdget-block.xdget-trainingsSystemPage.xdget-common-container, .xdget-block.xdget-training.xdget-common-container'
        );

        if (!root) return;

        if (trainingsBlock && !trainingsBlock.id) {
            trainingsBlock.id = 'kbclinic-trainings';
        }

        const oval = createElement('section', 'oval-section');
        oval.innerHTML = `
            <div class="oval-section__copy">
                <h2 class="oval-section__title">
                    <span class="oval-section__title-accent">Автор курсов</span>
                    <span class="oval-section__title-name">Алексей Жданюк</span>
                </h2>
                <p class="oval-section__subtitle">Ортопед, травматолог, вертебролог, детский вертебролог, детский ортопед, детский травматолог</p>
                <ul class="oval-section__credentials">
                    <li class="oval-cred">
                        <span class="oval-cred__icon" aria-hidden="true"></span>
                        <span class="oval-cred__label">Стаж работы:</span>
                        <strong class="oval-cred__value">25 лет</strong>
                    </li>
                    <li class="oval-cred">
                        <span class="oval-cred__icon" aria-hidden="true"></span>
                        <span class="oval-cred__label">Учёная степень:</span>
                        <strong class="oval-cred__value">Кандидат медицинских наук</strong>
                    </li>
                    <li class="oval-cred">
                        <span class="oval-cred__icon" aria-hidden="true"></span>
                        <span class="oval-cred__label">Категория:</span>
                        <strong class="oval-cred__value">Врач высшей категории</strong>
                    </li>
                    <li class="oval-cred">
                        <span class="oval-cred__icon" aria-hidden="true"></span>
                        <span class="oval-cred__label">Прием пациентов:</span>
                        <strong class="oval-cred__value">Взрослые и дети с 14 лет</strong>
                    </li>
                </ul>
            </div>
            <div class="oval-section__photo">
                <img class="oval-section__photo-img" src="${photoSrc}" alt="Алексей Жданюк" width="834" height="1251" loading="lazy" decoding="async">
            </div>
        `;

        // sibling в .xdget-root рядом с trainingsSystemPage (как был .right-panel)
        root.appendChild(oval);
    }

    initTrainingsPageDesign();
    if (isStreamListPage()) {
        setTimeout(hideStreamEventsBlock, 0);
        setTimeout(hideStreamEventsBlock, 100);
        setTimeout(hideStreamEventsBlock, 500);
    }

    /* Figma «Страница с уроками» (node 41:2760) — только !isAdmin */
    function isLessonsPage() {
        const href = window.location.href;
        const isStreamView =
            href.includes('/teach/control/stream/view/id/') ||
            href.includes('/teach/control/stream/view?id=');
        return isStreamView && !!document.querySelector('.lesson-list');
    }

    function isNonAdmin() {
        return !window.userInfo || !window.userInfo.isAdmin;
    }

    const LESSON_STATUS = {
        reached: {
            label: 'Урок доступен',
            icon: 'https://fs.getcourse.ru/fileservice/file/download/a/951813/sc/113/h/fc18c6c6fecfea898d6d0eebebaa4aa1.svg',
            tone: 'dark',
        },
        has_mission: {
            label: 'Есть задание',
            icon: 'https://fs.getcourse.ru/fileservice/file/download/a/951813/sc/232/h/7f44a31c676dd81b224507bdd7a3fac2.svg',
            tone: 'light',
        },
        need_accomplish: {
            label: 'Выполнить задание (стоп-урок)',
            icon: 'https://fs.getcourse.ru/fileservice/file/download/a/951813/sc/232/h/7f44a31c676dd81b224507bdd7a3fac2.svg',
            tone: 'light',
        },
        answered: {
            label: 'Задание на проверке',
            icon: 'https://fs.getcourse.ru/fileservice/file/download/a/951813/sc/230/h/a51a685ab5e3ff71869d8df8476d969e.svg',
            tone: 'dark',
        },
        accomplished: {
            label: 'Задание принято',
            icon: 'https://fs.getcourse.ru/fileservice/file/download/a/951813/sc/113/h/fc18c6c6fecfea898d6d0eebebaa4aa1.svg',
            tone: 'dark',
        },
        passed: {
            label: 'Задание принято',
            icon: 'https://fs.getcourse.ru/fileservice/file/download/a/951813/sc/113/h/fc18c6c6fecfea898d6d0eebebaa4aa1.svg',
            tone: 'dark',
        },
        processed: {
            label: 'Задание принято',
            icon: 'https://fs.getcourse.ru/fileservice/file/download/a/951813/sc/113/h/fc18c6c6fecfea898d6d0eebebaa4aa1.svg',
            tone: 'dark',
        },
    };

    function detectLessonStatus(li, labelEl) {
        // mission/answer важнее голого reached
        const keys = [
            'need_accomplish',
            'has_mission',
            'answered',
            'accomplished',
            'passed',
            'processed',
            'reached',
        ];
        const link = li.querySelector('a');
        const sources = [li, link].filter(Boolean);
        for (let s = 0; s < sources.length; s++) {
            for (let i = 0; i < keys.length; i++) {
                if (sources[s].classList.contains('user-state-' + keys[i])) return keys[i];
            }
        }
        const text = (labelEl && labelEl.textContent) || '';
        const normalized = text.trim().toLowerCase();
        if (/стоп|выполнить/.test(normalized)) return 'need_accomplish';
        if (/проверк/.test(normalized)) return 'answered';
        if (/принято|принят|зачт|выполнен/.test(normalized)) return 'accomplished';
        if (/есть задание/.test(normalized)) return 'has_mission';
        if (/доступен/.test(normalized)) return 'reached';
        return null;
    }

    function enhanceLessonCard(li) {
        const link = li.querySelector('a.user-state-bg.item-a, a.item-a');
        if (!link) return;

        link.classList.add('kb-lesson-card');
        li.classList.add('kb-lesson-card-row');

        const vmiddle = link.querySelector('.info .vmiddle') || link.querySelector('.vmiddle');
        const labelEl =
            (vmiddle && vmiddle.querySelector('.user-state-label')) ||
            link.querySelector('.state-icon-block .user-state-label') ||
            link.querySelector('.user-state-label') ||
            li.querySelector('.user-state-label');

        const statusKey = detectLessonStatus(li, labelEl);
        const statusCfg = statusKey ? LESSON_STATUS[statusKey] : null;
        const hasLabelText = !!(labelEl && labelEl.textContent.trim());

        if (vmiddle) {
            if (!vmiddle.querySelector('.title, .link')) {
                const title = createElement('div', 'title');
                Array.from(vmiddle.childNodes).forEach((node) => {
                    if (node.nodeType === Node.TEXT_NODE && node.textContent.trim()) {
                        title.textContent = node.textContent.trim();
                        node.textContent = '';
                    }
                });
                if (title.textContent) {
                    vmiddle.insertBefore(title, vmiddle.firstChild);
                }
            }
        }

        // статус: класс li/a, либо текст .user-state-label (часто внутри скрытого .state-icon-block)
        if (statusCfg || hasLabelText) {
            let statusWrap = link.querySelector('.kb-lesson-card__status');
            if (!statusWrap) {
                statusWrap = createElement('div', 'kb-lesson-card__status');
                const icon = createElement('span', 'kb-lesson-card__status-icon');
                icon.setAttribute('aria-hidden', 'true');
                if (statusCfg) {
                    icon.style.backgroundImage = 'url("' + statusCfg.icon + '")';
                }
                statusWrap.appendChild(icon);

                let label = labelEl;
                if (!label) {
                    label = createElement('span', 'user-state-label');
                    label.textContent = statusCfg ? statusCfg.label : '';
                } else if (statusCfg && !label.textContent.trim()) {
                    label.textContent = statusCfg.label;
                }
                statusWrap.appendChild(label);
                (vmiddle || link).appendChild(statusWrap);
            } else if (statusCfg) {
                const icon = statusWrap.querySelector('.kb-lesson-card__status-icon');
                if (icon && !icon.style.backgroundImage) {
                    icon.style.backgroundImage = 'url("' + statusCfg.icon + '")';
                }
                const label = statusWrap.querySelector('.user-state-label');
                if (label && !label.textContent.trim()) {
                    label.textContent = statusCfg.label;
                }
            }

            if (statusKey) {
                li.setAttribute('data-kb-status', statusKey);
            }
        }

        if (!link.querySelector('.kb-lesson-card__cta')) {
            const cta = createElement('span', 'kb-lesson-card__cta');
            cta.setAttribute('aria-hidden', 'true');
            link.appendChild(cta);
        }
    }

    function initLessonBreadcrumb() {
        document.querySelectorAll('.breadcrumbs').forEach((crumbs) => {
            crumbs.classList.add('kb-module-crumbs');
            crumbs.style.removeProperty('display');
        });
    }

    function parseBannerModuleMeta(title) {
        const rawTitle = String(title || '')
            .trim()
            .replace(/\s+/g, ' ');
        const titleModuleMatch = rawTitle.match(/^модуль\s*(\d+)\s*[.:]?\s*(.*)$/i);

        return {
            moduleLabel: titleModuleMatch ? 'Модуль ' + titleModuleMatch[1] : rawTitle,
            moduleNumber: titleModuleMatch ? titleModuleMatch[1] : null,
            rawTitle,
        };
    }

    function resolveModuleBannerImage(meta, trainingId) {
        const cfg =
            window.kbclinicModuleImages ||
            (typeof kbclinicModuleImages !== 'undefined' ? kbclinicModuleImages : null);
        if (!cfg) return '';

        const label = (meta.moduleLabel || '').trim();
        const rawTitle = (meta.rawTitle || label).trim();
        const num = meta.moduleNumber != null ? String(meta.moduleNumber) : '';
        const id = trainingId ? String(trainingId) : '';

        function pickFromObject(obj) {
            if (!obj || typeof obj !== 'object') return '';
            if (id && obj[id]) return obj[id];
            if (id && obj['id:' + id]) return obj['id:' + id];
            if (label && obj[label]) return obj[label];
            if (rawTitle && obj[rawTitle]) return obj[rawTitle];

            const keys = Object.keys(obj);
            const lowerLabel = label.toLowerCase();
            const lowerRaw = rawTitle.toLowerCase();
            for (let i = 0; i < keys.length; i++) {
                const k = keys[i];
                if (k === 'default') continue;
                const kl = k.toLowerCase();
                if (kl === lowerLabel || kl === lowerRaw) return obj[k];
            }

            if (num && obj['Модуль ' + num]) return obj['Модуль ' + num];
            if (num && obj[num]) return obj[num];
            return obj.default || '';
        }

        if (Array.isArray(cfg)) {
            if (id) {
                const byId = cfg.find((item) => item && String(item.id) === id);
                if (byId && byId.image) return byId.image;
            }
            const byTitle = cfg.find((item) => {
                if (!item || !item.title) return false;
                const t = String(item.title).trim().toLowerCase();
                return t === label.toLowerCase() || t === rawTitle.toLowerCase();
            });
            if (byTitle && byTitle.image) return byTitle.image;
            if (num) {
                const byNum = cfg.find(
                    (item) => item && String(item.title).replace(/\D/g, '') === num
                );
                if (byNum && byNum.image) return byNum.image;
            }
            const fallback = cfg.find((item) => item && (item.title === 'default' || item.default));
            return (fallback && (fallback.image || fallback.default)) || '';
        }

        return pickFromObject(cfg);
    }

    function initLessonBanner() {
        initLessonBreadcrumb();

        if (document.querySelector('.kb-module-banner')) return;

        const header = document.querySelector('.page-header');
        const h1 = header && header.querySelector('h1');
        const title = h1 ? h1.textContent.trim().replace(/\s+/g, ' ') : '';
        if (!title) return;

        const banner = createElement('div', 'kb-module-banner');
        banner.innerHTML =
            '<div class="kb-module-banner__text"></div>' +
            '<div class="kb-module-banner__illust" aria-hidden="true"></div>';
        banner.querySelector('.kb-module-banner__text').textContent = title;

        const assets = Object.assign({}, window.kbclinicLessonsAssets || {});
        const meta = parseBannerModuleMeta(title);
        const trainingRow = document.querySelector('.stream-table tr.training-row[data-training-id]');
        const trainingId = trainingRow ? trainingRow.getAttribute('data-training-id') : '';
        const illustUrl =
            assets.bannerIllust || resolveModuleBannerImage(meta, trainingId);
        const illustEl = banner.querySelector('.kb-module-banner__illust');

        if (illustUrl) {
            illustEl.style.backgroundImage = 'url("' + illustUrl.replace(/"/g, '\\"') + '")';
            illustEl.style.removeProperty('display');
        } else {
            illustEl.style.display = 'none';
        }

        if (header) {
            header.classList.add('kb-module-header');
            if (h1) h1.style.display = 'none';
            header.appendChild(banner);
        } else {
            const main = document.querySelector('.xdget-block.xdget-training.xdget-common-container');
            if (main) main.prepend(banner);
        }
    }

    function buildLessonsCareCard(cfg) {
        const curators = cfg.curators || [
            {
                role: 'Куратор',
                name: 'Бойко Валерия',
                about: 'Акушер-гинеколог, стаж 5 лет',
                photo: cfg.curatorPhoto || '',
            },
            {
                role: 'Куратор',
                name: 'Бойко Валерия',
                about: 'Акушер-гинеколог, стаж 5 лет',
                photo: cfg.curatorPhoto || '',
            },
        ];
        const card = createElement('div', 'kb-course-card kb-course-card--care');
        const list = curators
            .map((c) => {
                const photoStyle = c.photo
                    ? ' style="background-image:url(\'' + c.photo.replace(/'/g, "\\'") + '\')"'
                    : '';
                return (
                    '<div class="kb-care-person">' +
                    '<span class="kb-care-person__photo"' +
                    photoStyle +
                    ' aria-hidden="true"></span>' +
                    '<div class="kb-care-person__meta">' +
                    '<span class="kb-care-person__role">' +
                    (c.role || 'Куратор') +
                    '</span>' +
                    '<span class="kb-care-person__name">' +
                    (c.name || '') +
                    '</span>' +
                    '<span class="kb-care-person__about">' +
                    (c.about || '') +
                    '</span>' +
                    '</div></div>'
                );
            })
            .join('');

        card.innerHTML =
            '<p class="kb-course-card__care-title">Служба заботы</p>' +
            '<div class="kb-care-panel kb-care-panel--people">' +
            list +
            '</div>' +
            '<div class="kb-care-panel kb-care-panel--support">' +
            '<p class="kb-care-hours">Пн-Вс: 10:00 - 18:00 Мск</p>' +
            '<p class="kb-care-note">Время ответа технической поддержки 24 часа с момента обращения. Не переживайте, мы обязательно вам поможем!</p>' +
            '<a class="kb-care-cta" href="">Написать в поддержку</a>' +
            '</div>';
        return card;
    }

    function initLessonsRightPanel() {
        const root = document.querySelector('.xdget-root');
        if (!root) return;

        document.querySelectorAll('.kb-course-card--progress').forEach((el) => el.remove());

        let rightPanel = root.querySelector(':scope > .right-panel');
        if (!rightPanel) {
            rightPanel = createElement('div', 'right-panel');
            root.appendChild(rightPanel);
        }

        if (rightPanel.querySelector('.kb-course-card--care')) return;

        const assets = Object.assign(
            { curatorPhoto: '', supportHref: '', curators: null },
            window.kbclinicLessonsAssets || {}
        );

        rightPanel.querySelectorAll('.info-block, .calendar-block, .ultima-block, .rating-block, .sertificate-block').forEach((el) => {
            el.remove();
        });

        rightPanel.appendChild(
            buildLessonsCareCard({
                curatorPhoto: assets.curatorPhoto,
                supportHref: assets.supportHref,
                curators: assets.curators,
            })
        );
    }

    function initLessonsPageDesign() {
        if (!isLessonsPage() || !isNonAdmin()) return;

        const firstInit = !document.body.classList.contains('kbclinic-lessons-page');
        if (firstInit) {
            document.body.classList.add('kbclinic-lessons-page');

            document.querySelectorAll('.bonus-banner, a.bonus-banner').forEach((el) => {
                const wrap = el.closest('a.banner') || el;
                wrap.remove();
            });

            initLessonBanner();
            initLessonsRightPanel();

            if (typeof window.kbclinicFillLessonsHeader === 'function') {
                window.kbclinicFillLessonsHeader();
            }
        }

        document.querySelectorAll('.lesson-list > li').forEach(enhanceLessonCard);
    }

    setTimeout(initLessonsPageDesign, 0);
    setTimeout(initLessonsPageDesign, 100);
    setTimeout(initLessonsPageDesign, 500);
    setTimeout(initLessonsPageDesign, 1500);

    // GC может дорисовать lesson-list позже
    const lessonListHost = document.querySelector('.lesson-list') || document.querySelector('.xdget-root');
    if (lessonListHost) {
        const mo = new MutationObserver(() => {
            if (!isLessonsPage() || !isNonAdmin()) return;
            document.querySelectorAll('.lesson-list > li').forEach(enhanceLessonCard);
        });
        mo.observe(lessonListHost, { childList: true, subtree: true });
    }
    
    if (window.location.href.includes('/view/id/') && !window.location.href.includes('system') && !window.location.href.includes('/sales/shop/')) {
        removeLegacyGcDecor();
    } else if (window.location.href.includes('/control/stream/view/id/') || window.location.href.includes('/control/stream/view?id=')) {
        const mainContainer = $('.xdget-block.xdget-training.xdget-common-container');
        mainContainer.prepend($('.page-header'));
        removeLegacyGcDecor();
    }
});