// добавление классов админ-неадмин
/*$(document).ready(function(){
	// проверка на роль админа
	 if(window.userInfo.isAdmin) {
        $('body').addClass('role-admin')
     }else
    	$('body').addClass('role-student')
}); */
function gcAssignUserRole() {
    const info = window.userInfo;
    if (!info) return;
    const body = document.body;
    if (!body) return;

    // Приоритет ролей: admin > teacher > manager > student
    let roleClass = "role-student";
    if (info.isAdmin === true) {
        roleClass = "role-admin";
    } else if (info.isTeacher === true) {
        roleClass = "role-teacher";
    } else if (info.isManager === true) {
        roleClass = "role-manager";
    }
    body.classList.add(roleClass);
    console.log("Назначена роль:", roleClass);
}
(function gcInitUserRole() {
    if (document.readyState === "loading") {
        document.addEventListener("DOMContentLoaded", gcAssignUserRole);
    } else {
        gcAssignUserRole();
    }
})();

// END добавление классов админ-неадмин


// меняем надписи
document.addEventListener('DOMContentLoaded', function() {
    /* Проверяем наличие меню на странице*/
    let checkMenu = document.getElementById('gcAccountUserMenu');
    if (!checkMenu) {
        /*    console.warn('Меню с id="gcAccountUserMenu" не найдено');*/
        return; // Прекращаем выполнение скрипта, если элемент отсутствует
    }  /* END Проверяем наличие меню на странице*/

    const classMappings = {
        '.menu-item.menu-item-profile': {
            text: 'Настройки',
            imgSrc: `<svg class="svg-icon fill-ico" xmlns="http://www.w3.org/2000/svg" width="17" height="17" viewBox="0 0 17 17" fill="none">
<path d="M0.5 16.5V12.9583L12.6875 0.8125L16.1667 4.375L4.04167 16.5H0.5ZM12.6667 5.5L13.8333 4.33333L12.6667 3.16667L11.5 4.33333L12.6667 5.5Z" fill="#fff"/>
</svg> `
        },
        '.menu-item.menu-item-notifications_button_small': {
            text: 'Уведомления',
            imgSrc: `<svg class="svg-icon fill-ico" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20" fill="none">
<path fill-rule="evenodd" clip-rule="evenodd" d="M10.2095 16.9788C9.177 16.9788 8.33367 16.1955 8.21864 15.193H12.1995C12.0845 16.1955 11.2412 16.9788 10.2095 16.9788ZM17.3078 15.193L15.7812 11.0863V7.34384C15.7812 4.27051 13.2812 1.77051 10.2087 1.77051C7.13531 1.77051 4.63531 4.27051 4.63531 7.34384V11.0863L3.10864 15.193H6.96864C7.08781 16.8847 8.48783 18.2288 10.2095 18.2288C11.9303 18.2288 13.3303 16.8847 13.4495 15.193H17.3078Z" fill="#fff" />
</svg>`
        },
        '.menu-item.menu-item-cms': {
            text: 'Web страницы',
            imgSrc: `<svg class="svg-icon stroke-ico" width="22" height="22" viewBox="0 0 22 22" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M18.5 7.20893V13.125C18.5 14.0763 18.5 15.875 18.5 16.25C18.5 16.625 18.5 17 18 17.5C17.5 18 16.9596 18 16.4489 18C15.5343 18 14.2964 17.9643 13.3469 17.9643C13.3469 17.9643 13.3469 12.0683 13.3469 11.3218C13.3469 10.5753 12.2768 9.55076 11.3559 9.55904C10.4468 9.56721 9.40067 10.4483 9.40067 11.3218C9.40067 12.1953 9.40067 17.9643 9.40067 17.9643H8.68319C7.67054 17.9809 6.84628 17.9643 6.16038 17.9643C5.81743 17.9643 5 18 4.5 17.5C4.28482 17.2848 4 17 4 16.25C4 15.5 4 14.0282 4 13.125V7M1 8.43015C4.56709 6.68608 0.432914 8.74407 4 7M21 8.43015L12.6138 4.33361C12.6138 4.33361 11.8206 3.99867 11.2398 4C10.6589 4.00134 10.2411 4.15749 9.84566 4.33361C5.61965 6.21597 10.151 4.26054 4 7" stroke="#fff" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round"/>
</svg> `
        },

        '.menu-item.menu-item-teach': {
            text: 'Обучение',
            imgSrc: `<svg class="svg-icon fill-ico" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20" fill="none">
<path d="M10 2.5L0.833344 7.5L4.16668 9.31667V14.3167L10 17.5L15.8333 14.3167V9.31667L17.5 8.40833V14.1667H19.1667V7.5L10 2.5ZM15.6833 7.5L10 10.6L4.31668 7.5L10 4.4L15.6833 7.5ZM14.1667 13.3333L10 15.6L5.83334 13.3333V10.225L10 12.5L14.1667 10.225V13.3333Z" fill="#fff"/>
<path d="M15.6833 7.5L10 10.6L4.31668 7.5L10 4.4L15.6833 7.5Z" fill="#fff"/>
</svg>`
        },
        '.menu-item.menu-item-user': {
            text: 'Ученики',
            imgSrc: `<svg class="svg-icon fill-ico" width="22" height="22" viewBox="0 0 22 22" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M9.97015 14.1373C10.9101 13.6069 11.6479 12.7802 12.0683 11.7862C12.4888 10.7923 12.5681 9.68702 12.2939 8.64318C12.0198 7.59935 11.4076 6.67572 10.553 6.0166C9.69844 5.35748 8.6496 5 7.57037 5C6.49113 5 5.4423 5.35748 4.58771 6.0166C3.73313 6.67572 3.12095 7.59935 2.8468 8.64318C2.57265 9.68702 2.65198 10.7923 3.0724 11.7862C3.49281 12.7802 4.23063 13.6069 5.17059 14.1373C3.52199 14.657 2.09 15.7044 1.09517 17.118C1.05623 17.1721 1.02838 17.2334 1.01323 17.2983C0.998077 17.3632 0.995916 17.4305 1.00687 17.4962C1.01783 17.562 1.04169 17.6249 1.07708 17.6814C1.11246 17.7379 1.15867 17.7868 1.21305 17.8253C1.30056 17.8835 1.40275 17.9156 1.50776 17.918C1.58822 17.9176 1.66747 17.8984 1.73914 17.8619C1.8108 17.8253 1.87288 17.7724 1.92036 17.7075C2.5567 16.8001 3.40211 16.0593 4.38514 15.5476C5.36817 15.0358 6.45993 14.7682 7.56818 14.7674C8.67643 14.7666 9.76859 15.0325 10.7524 15.5428C11.7362 16.0531 12.5827 16.7926 13.2204 17.699C13.2583 17.7541 13.3067 17.8011 13.3629 17.8372C13.4191 17.8734 13.4819 17.8981 13.5477 17.9098C13.6134 17.9216 13.6809 17.9202 13.7461 17.9057C13.8114 17.8912 13.8731 17.8639 13.9277 17.8253C14.0357 17.7461 14.1085 17.6278 14.1305 17.4957C14.1525 17.3635 14.122 17.228 14.0456 17.118C13.0472 15.7079 11.6165 14.6615 9.97015 14.1373ZM3.69704 9.88502C3.69704 9.11894 3.9242 8.37008 4.34981 7.73311C4.77542 7.09614 5.38035 6.59969 6.08811 6.30652C6.79587 6.01336 7.57466 5.93666 8.32602 6.08611C9.07737 6.23556 9.76753 6.60446 10.3092 7.14616C10.8509 7.68785 11.2198 8.37801 11.3693 9.12937C11.5187 9.88072 11.442 10.6595 11.1489 11.3673C10.8557 12.075 10.3592 12.68 9.72228 13.1056C9.08531 13.5312 8.33644 13.7583 7.57037 13.7583C6.5431 13.7583 5.5579 13.3503 4.83151 12.6239C4.10512 11.8975 3.69704 10.9123 3.69704 9.88502ZM20.7902 17.8253C20.7027 17.8835 20.6005 17.9156 20.4955 17.918C20.4141 17.9181 20.3338 17.8982 20.2619 17.86C20.1899 17.8218 20.1285 17.7666 20.0829 17.699C19.4453 16.7932 18.5991 16.0541 17.6157 15.5441C16.6323 15.0341 15.5407 14.7682 14.4329 14.7688C14.2989 14.7688 14.1704 14.7156 14.0757 14.6208C13.9809 14.5261 13.9277 14.3976 13.9277 14.2636C13.9277 14.1296 13.9809 14.0011 14.0757 13.9063C14.1704 13.8116 14.2989 13.7583 14.4329 13.7583C15.4602 13.7583 16.4454 13.3503 17.1718 12.6239C17.8982 11.8975 18.3062 10.9123 18.3062 9.88502C18.3062 8.85775 17.8982 7.87255 17.1718 7.14616C16.4454 6.41977 15.4602 6.01168 14.4329 6.01168C14.0773 6.01318 13.7234 6.06131 13.3804 6.15483C13.3145 6.18066 13.244 6.19239 13.1734 6.18925C13.1028 6.18612 13.0336 6.16819 12.9703 6.13662C12.907 6.10506 12.8511 6.06057 12.8061 6.00602C12.7611 5.95147 12.728 5.88809 12.7091 5.81997C12.6901 5.75185 12.6857 5.68051 12.696 5.61056C12.7064 5.54061 12.7313 5.47362 12.7692 5.41391C12.8071 5.3542 12.857 5.3031 12.9159 5.26393C12.9748 5.22476 13.0412 5.19838 13.1109 5.1865C13.5405 5.06192 13.9857 4.99954 14.4329 5.00125C15.5124 4.99988 16.562 5.35624 17.4176 6.01462C18.2731 6.673 18.8864 7.59631 19.1616 8.6402C19.4367 9.68409 19.3583 10.7897 18.9384 11.7843C18.5186 12.7789 17.7811 13.6063 16.8411 14.1373C18.486 14.6598 19.9145 15.7068 20.9081 17.118C20.9846 17.228 21.015 17.3635 20.993 17.4957C20.971 17.6278 20.8982 17.7461 20.7902 17.8253Z" fill="#fff"/>
</svg>`

        },
        '.menu-item.menu-item-tasks': {
            text: 'CRM',
            imgSrc: `<svg class="svg-icon fill-ico" width="22" height="22" viewBox="0 0 22 22" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M14.0613 17.7251L12.3761 15.9889L11.4587 16.9341L14.0613 19.6154L19.2667 14.2528L18.3492 13.3076L14.0613 17.7251Z" fill="#fff"/>
<path d="M16.0133 2.85712H14.0613V2.18679C14.0603 1.83155 13.9229 1.49116 13.679 1.23997C13.4352 0.98878 13.1048 0.847191 12.76 0.84613H7.55467C7.20985 0.847191 6.87945 0.98878 6.63562 1.23997C6.3918 1.49116 6.25436 1.83155 6.25333 2.18679V2.85712H4.30133C3.95651 2.85818 3.62611 2.99977 3.38229 3.25096C3.13846 3.50215 3.00103 3.84254 3 4.19778V18.2747C3.00103 18.6299 3.13846 18.9703 3.38229 19.2215C3.62611 19.4727 3.95651 19.6143 4.30133 19.6153H10.1573L10.1573 18.3692H4.1753L4.1753 4H6.25333V6H14.0613V4L16.0986 3.99138L16.0986 11.5714H17.3147V4.19778C17.3136 3.84254 17.1762 3.50215 16.9324 3.25096C16.6886 2.99977 16.3582 2.85818 16.0133 2.85712ZM12.893 4.8681H7.41029C7.41029 4.8681 7.41029 3 7.41029 2.5C7.41029 2 7.41029 2 8 2C8.58971 2 12.107 2 12.5 2C12.893 2 12.8912 2 12.893 2.5C12.8948 3 12.893 4.8681 12.893 4.8681Z" fill="#fff"/>
</svg> `

        },
        '.role-student .menu-item.menu-item-notifications': {
            text: 'Поддержка',
            imgSrc: `<svg class="svg-icon fill-ico" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20" fill="none">
<path fill-rule="evenodd" clip-rule="evenodd" d="M12.6579 11.0584H13.9896V9.80842H12.6579V11.0584ZM9.54542 11.0584H10.8779V9.80842H9.54542V11.0584ZM6.43374 11.0584H7.76624V9.80842H6.43374V11.0584ZM15.9629 4.38179C14.4338 2.85262 12.3996 2.01096 10.2329 2.01096C8.06707 2.01096 6.03124 2.85346 4.50207 4.38263C2.96874 5.91596 2.12541 7.95263 2.12707 10.1201C2.12957 12.9126 2.08707 17.7818 2.08707 17.7818L2.08374 18.2059L2.50707 18.2026C2.55541 18.2018 7.34791 18.1593 10.0571 18.2184C10.1187 18.2193 10.1796 18.2201 10.2413 18.2201C12.4021 18.2201 14.4279 17.3809 15.9629 15.8459C19.1229 12.6851 19.1229 7.54263 15.9629 4.38179Z" fill="#fff"/>
</svg>`
        },
        '.role-admin .menu-item.menu-item-notifications': {
            text: 'Сообщения',
            imgSrc: `<svg class="svg-icon stroke-ico" width="22" height="22" viewBox="0 0 22 22" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M19 14.5001V4.75179C19 4.75179 19 4.00614 18.2728 4.00189C17.644 3.99821 6.68188 4.0009 3.72978 4.00169C3.00262 4.00169 3.00262 4.75179 3.00262 4.75179C3.00262 4.75179 2.99672 13.9128 3.00262 14.5001C3.00852 15.0875 3.3662 15.0875 3.3662 15.0875H5.71916V19H6.92651C7.57813 19 10.2467 15.0875 10.2467 15.0875H18.2728C19 15.0875 19 14.5001 19 14.5001Z" stroke="#fff" stroke-width="1.2"/>
</svg> `
        },
        '.role-teacher .menu-item.menu-item-notifications': {
            text: 'Сообщения',
            imgSrc: `<svg class="svg-icon stroke-ico" width="22" height="22" viewBox="0 0 22 22" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M19 14.5001V4.75179C19 4.75179 19 4.00614 18.2728 4.00189C17.644 3.99821 6.68188 4.0009 3.72978 4.00169C3.00262 4.00169 3.00262 4.75179 3.00262 4.75179C3.00262 4.75179 2.99672 13.9128 3.00262 14.5001C3.00852 15.0875 3.3662 15.0875 3.3662 15.0875H5.71916V19H6.92651C7.57813 19 10.2467 15.0875 10.2467 15.0875H18.2728C19 15.0875 19 14.5001 19 14.5001Z" stroke="#fff" stroke-width="1.2"/>
</svg> `
        },
        '.role-student .menu-item.menu-item-sales': {
            text: 'Мои покупки',
            imgSrc: `<svg class="svg-icon fill-ico" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20" fill="none">
<path fill-rule="evenodd" clip-rule="evenodd" d="M6.54522 16.0657C5.95938 16.0657 5.48355 16.5415 5.48355 17.1273C5.48355 17.7132 5.95938 18.1898 6.54522 18.1898C7.13022 18.1898 7.60605 17.7132 7.60605 17.1273C7.60605 16.5415 7.13022 16.0657 6.54522 16.0657Z" fill="white" fill-opacity="0.7"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M15.6012 16.0657C15.0153 16.0657 14.5395 16.5415 14.5395 17.1273C14.5395 17.7132 15.0153 18.1898 15.6012 18.1898C16.187 18.1898 16.6628 17.7132 16.6628 17.1273C16.6628 16.5415 16.187 16.0657 15.6012 16.0657Z" fill="white" fill-opacity="0.7"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M11.5209 9.75958H14.9959V8.50958H11.5209V9.75958ZM5.32922 5.25127L5.07922 2.70127H1.82922V3.95127H3.94589L5.01256 14.5346H17.3626L18.5876 5.25127H5.32922Z" fill="#fff" />
</svg>`
        },
        '.role-admin .menu-item.menu-item-sales': {
            text: 'Продажи',
            imgSrc: `<svg class="svg-icon stroke-ico" width="22" height="22" viewBox="0 0 22 22" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M2 3H4.0323C4.0323 3 4.63003 3 4.98867 3.35417C5.34731 3.70833 5.5864 4.41667 5.5864 4.41667L6.42991 7.63877M6.42991 7.63877L8.21643 14.2656C8.21643 14.2656 8.33598 14.8753 8.81417 15.1597C9.29235 15.4441 9.89009 15.3958 9.89009 15.3958L15.3137 15.4231C15.3137 15.4231 15.7479 15.4231 16.1065 15.1597C16.506 14.8664 16.7095 14.2656 16.7095 14.2656L18.5526 8.85811L19 7.63877H17.7742H6.42991Z" stroke="#fff" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M10.5636 18.6217C10.5636 19.1009 10.1684 19.5001 9.66776 19.5001C9.1671 19.5001 8.77197 19.1009 8.77197 18.6217C8.77197 18.1425 9.1671 17.7433 9.66776 17.7433C10.1684 17.7433 10.5636 18.1425 10.5636 18.6217Z" stroke="#fff"/>
<path d="M15.6456 18.6217C15.6456 19.1009 15.2505 19.5001 14.7499 19.5001C14.2492 19.5001 13.8541 19.1009 13.8541 18.6217C13.8541 18.1425 14.2492 17.7433 14.7499 17.7433C15.2505 17.7433 15.6456 18.1425 15.6456 18.6217Z" stroke="#fff"/>
</svg> `
        },
        '.role-teacher .menu-item.menu-item-sales': {
            text: 'Продажи',
            imgSrc: `<svg class="svg-icon stroke-ico" width="22" height="22" viewBox="0 0 22 22" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M2 3H4.0323C4.0323 3 4.63003 3 4.98867 3.35417C5.34731 3.70833 5.5864 4.41667 5.5864 4.41667L6.42991 7.63877M6.42991 7.63877L8.21643 14.2656C8.21643 14.2656 8.33598 14.8753 8.81417 15.1597C9.29235 15.4441 9.89009 15.3958 9.89009 15.3958L15.3137 15.4231C15.3137 15.4231 15.7479 15.4231 16.1065 15.1597C16.506 14.8664 16.7095 14.2656 16.7095 14.2656L18.5526 8.85811L19 7.63877H17.7742H6.42991Z" stroke="#fff" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M10.5636 18.6217C10.5636 19.1009 10.1684 19.5001 9.66776 19.5001C9.1671 19.5001 8.77197 19.1009 8.77197 18.6217C8.77197 18.1425 9.1671 17.7433 9.66776 17.7433C10.1684 17.7433 10.5636 18.1425 10.5636 18.6217Z" stroke="#fff"/>
<path d="M15.6456 18.6217C15.6456 19.1009 15.2505 19.5001 14.7499 19.5001C14.2492 19.5001 13.8541 19.1009 13.8541 18.6217C13.8541 18.1425 14.2492 17.7433 14.7499 17.7433C15.2505 17.7433 15.6456 18.1425 15.6456 18.6217Z" stroke="#fff"/>
</svg> `
        },
        '.menu-item.menu-item-chatium': {
            text: 'Приложение',
            imgSrc: `<svg class="svg-icon stroke-ico" width="22" height="22" viewBox="0 0 22 22" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M9.94626 16.4312C9.94626 16.5991 9.81018 16.7352 9.6423 16.7352C9.47443 16.7352 9.33834 16.5991 9.33834 16.4312C9.33834 16.2634 9.47443 16.1273 9.6423 16.1273C9.81018 16.1273 9.94626 16.2634 9.94626 16.4312Z" fill="#fff" stroke="#fff" stroke-width="1.06182"/>
<path d="M13.4037 2.95654H5.93477C5.63012 2.95685 5.33802 3.07801 5.1226 3.29343C4.90717 3.50886 4.78601 3.80095 4.78571 4.10561V17.8944C4.78601 18.1991 4.90717 18.4912 5.1226 18.7066C5.33802 18.922 5.63012 19.0432 5.93477 19.0435H13.4037C13.7084 19.0432 14.0005 18.922 14.2159 18.7066C14.4313 18.4912 14.5525 18.1991 14.5528 17.8944V13.2982" stroke="#fff" stroke-width="1.07246" stroke-linecap="round"/>
<mask id="path-3-inside-1_275_123" fill="white">
<path fill-rule="evenodd" clip-rule="evenodd" d="M12.9117 5C12.0908 5 11.4252 5.66553 11.4252 6.4865V9.76838C11.4252 10.5894 12.0908 11.2549 12.9117 11.2549H16.1936C17.0146 11.2549 17.6801 10.5894 17.6801 9.76838V6.4865C17.6801 5.66553 17.0146 5 16.1936 5H12.9117ZM14.2497 7.60222L15.159 8.12721L14.2497 8.6522V7.60222ZM16.0442 7.48354C16.5397 7.76961 16.5397 8.48481 16.0442 8.77088L14.3646 9.74057C13.8691 10.0266 13.2497 9.66905 13.2497 9.0969V7.15752C13.2497 6.58537 13.8691 6.22777 14.3646 6.51385L16.0442 7.48354Z"/>
</mask>
<path d="M15.159 8.12721L16.159 9.85926L19.159 8.12721L16.159 6.39516L15.159 8.12721ZM14.2497 7.60222L15.2497 5.87017L12.2497 4.13812V7.60222H14.2497ZM14.2497 8.6522H12.2497V12.1163L15.2497 10.3842L14.2497 8.6522ZM16.0442 8.77088L15.0442 7.03883L15.0442 7.03883L16.0442 8.77088ZM16.0442 7.48354L17.0442 5.75149L16.0442 7.48354ZM14.3646 9.74057L13.3646 8.00852L13.3646 8.00852L14.3646 9.74057ZM14.3646 6.51385L15.3646 4.7818L15.3646 4.7818L14.3646 6.51385ZM13.4252 6.4865C13.4252 6.7701 13.1953 7 12.9117 7V3C10.9862 3 9.42523 4.56096 9.42523 6.4865H13.4252ZM13.4252 9.76838V6.4865H9.42523V9.76838H13.4252ZM12.9117 9.25488C13.1953 9.25488 13.4252 9.48478 13.4252 9.76838H9.42523C9.42523 11.6939 10.9862 13.2549 12.9117 13.2549V9.25488ZM16.1936 9.25488H12.9117V13.2549H16.1936V9.25488ZM15.6801 9.76838C15.6801 9.48478 15.91 9.25488 16.1936 9.25488V13.2549C18.1192 13.2549 19.6801 11.6939 19.6801 9.76838H15.6801ZM15.6801 6.4865V9.76838H19.6801V6.4865H15.6801ZM16.1936 7C15.91 7 15.6801 6.7701 15.6801 6.4865H19.6801C19.6801 4.56096 18.1192 3 16.1936 3V7ZM12.9117 7H16.1936V3H12.9117V7ZM16.159 6.39516L15.2497 5.87017L13.2497 9.33428L14.159 9.85926L16.159 6.39516ZM15.2497 10.3842L16.159 9.85926L14.159 6.39516L13.2497 6.92014L15.2497 10.3842ZM12.2497 7.60222V8.6522H16.2497V7.60222H12.2497ZM17.0442 10.5029C18.873 9.44705 18.873 6.80736 17.0442 5.75149L15.0442 9.21559C14.2063 8.73187 14.2063 7.52256 15.0442 7.03883L17.0442 10.5029ZM15.3646 11.4726L17.0442 10.5029L15.0442 7.03883L13.3646 8.00852L15.3646 11.4726ZM11.2497 9.0969C11.2497 11.2087 13.5358 12.5285 15.3646 11.4726L13.3646 8.00852C14.2025 7.5248 15.2497 8.12945 15.2497 9.0969H11.2497ZM11.2497 7.15752V9.0969H15.2497V7.15752H11.2497ZM15.3646 4.7818C13.5358 3.72592 11.2497 5.04577 11.2497 7.15752H15.2497C15.2497 8.12496 14.2025 8.72962 13.3646 8.2459L15.3646 4.7818ZM17.0442 5.75149L15.3646 4.7818L13.3646 8.2459L15.0442 9.21559L17.0442 5.75149Z" fill="#fff" mask="url(#path-3-inside-1_275_123)"/>
</svg> `
        },
        // Добавьте другие соответствия по необходимости
    };

    // Функция для обновления элементов в пределах списка ul
    function updateMenuItemsWithinList(ulElement) {
        Object.keys(classMappings).forEach((classSelector) => {
            ulElement.querySelectorAll(classSelector).forEach((item) => {
                const { text, imgSrc } = classMappings[classSelector];

                const parentLink = item.querySelector('a');
                if (parentLink) {
                    let labelSpan = parentLink.querySelector('.menu-item-label');
                    if (!labelSpan) {
                        labelSpan = document.createElement('span');
                        labelSpan.classList.add('menu-item-label');
                        parentLink.appendChild(labelSpan);
                    }
                    labelSpan.textContent = text;

                    // Проверяем, существует ли уже SVG элемент
                    if (!parentLink.querySelector('.svg-icon')) {
                        // Удаляем существующий тег img, если он есть
                        let iconImg = parentLink.querySelector('.menu-item-icon');
                        if (iconImg) {
                            parentLink.removeChild(iconImg);
                        }

                        // Вставляем SVG код
                        parentLink.insertAdjacentHTML('afterbegin', imgSrc);
                    }
                }
            });
        });
    }

    function updateDefaultIcons() {
        document.querySelectorAll('img.menu-item-icon').forEach(function(img) {
            var imgSrc = img.getAttribute('src');
            if (imgSrc === '/public/img/default_profile_50.png') {
                img.setAttribute('src', '');
            }
        });
    }

    const ulElement = document.querySelector('ul');
    updateMenuItemsWithinList(ulElement);
    updateDefaultIcons();

    ulElement.addEventListener('click', function() {
        updateMenuItemsWithinList(ulElement);
        updateDefaultIcons();
    });
});

// Перенос подменю в основное меню
document.addEventListener("DOMContentLoaded", function () {
    /* Проверяем наличие меню на странице*/
    let checkMenu = document.getElementById('gcAccountUserMenu');
    if (!checkMenu) {
        /*    console.warn('Меню с id="gcAccountUserMenu" не найдено');*/
        return; // Прекращаем выполнение скрипта, если элемент отсутствует
    }  /* END Проверяем наличие меню на странице*/

    var menu = document.querySelector('.gc-account-user-menu');
    menu.addEventListener('click', function (event) {
        var menuItem = event.target.closest('.menu-item');

        // Проверяем, является ли элемент меню тем, у которого есть класс 'menu-item-notifications_button_small'
        if (menuItem && menuItem.classList.contains('menu-item-notifications_button_small')) {
            // Выполняем переход на страницу
            window.location.href = '/notifications/notifications/all';
            return; // Прекращаем выполнение функции для этого случая
        }

        event.preventDefault();

        // Проверяем, открыто ли уже подменю для этого пункта меню
        var existingSubmenu = menuItem.querySelector('.submenu');
        if (existingSubmenu) {
            // Удаляем существующее подменю и убираем класс 'sub-open'
            menuItem.removeChild(existingSubmenu);
            menuItem.classList.remove('sub-open');
            return; // Прекращаем выполнение функции, т.к. подменю уже было закрыто
        }

        setTimeout(function () {
            var submenu = document.querySelector('.gc-account-user-submenu-bar');
            if (submenu) {
                var submenuContent = submenu.innerHTML;
                closeAllSubmenus();
                var submenuList = document.createElement('ul');
                submenuList.classList.add('submenu');
                submenuList.innerHTML = submenuContent;
                menuItem.appendChild(submenuList);

                menuItem.classList.add('sub-open');

                setTimeout(function () {
                    submenuList.classList.add('shown');
                }, 50);

                submenuList.addEventListener('click', function (event) {
                    event.stopPropagation();
                });
            } else {
                console.log('Подменю не найдено');
            }
        }, 300);
    });

    document.addEventListener('click', function (event) {
        if (!menu.contains(event.target)) {
            closeAllSubmenus();
        }
    });

    function closeAllSubmenus() {
        var openSubmenus = document.querySelectorAll('.submenu');
        openSubmenus.forEach(function (submenu) {
            submenu.closest('.menu-item').classList.remove('sub-open');
            submenu.parentNode.removeChild(submenu);
        });
    }

    document.querySelector('.gc-account-leftbar').addEventListener('scroll', function () {
        var toggleLink = document.querySelector('a.toggle-link.without-icon');
        toggleLink.style.position = 'absolute';
        toggleLink.style.bottom = -this.scrollTop + 'px';
    });
});



/* -------------
content start - webinar-no-custom-margin
------------- */

// проверка на наличие у меню display: none и отсутствие вложенности

document.addEventListener('DOMContentLoaded', function () {
    // Проверяем наличие "/pl/webinar/show" в URL
    if (window.location.href.includes('/pl/webinar/show')) {
        let targetNode = document.getElementById('gcAccountUserMenu');

        let observer = new MutationObserver(function(mutationsList, observer) {
            mutationsList.forEach(function(mutation) {
                if (mutation.attributeName === 'style') {
                    let displayStyle = window.getComputedStyle(targetNode).display;
                    let hasChildren = targetNode.children.length > 0;
                    if (displayStyle === 'none' || !hasChildren) {
                        document.body.classList.add('no-custom-margin');
                    } else {
                        document.body.classList.remove('no-custom-margin');
                    }
                }
            });
        });

        observer.observe(targetNode, { attributes: true, attributeFilter: ['style'] });

        // Проверка на начальное состояние элемента
        let initialDisplayStyle = window.getComputedStyle(targetNode).display;
        let initialHasChildren = targetNode.children.length > 0;
        if (initialDisplayStyle === 'none' || !initialHasChildren) {
            document.body.classList.add('no-custom-margin');
        }
    }
});

/* -------------
content finish - webinar-no-custom-margin
------------- */

/* -------------
content start - redirection-student-profile
------------- */

(() => {
    const MENU_ROOT_SELECTOR = ".gc-account-user-menu";

    const PROFILE_LINK_SELECTOR =
        ".gc-account-user-submenu-bar li.menu-item-profile .subitem-link";

    const MY_ACCOUNTS_LINK_SELECTOR =
        ".gc-account-user-submenu-bar li.menu-item-myAccounts .subitem-link";

    const CHANGE_PASSVORD_LINK_SELECTOR =
        ".gc-account-user-submenu-bar li.menu-item-change_password .subitem-link";

    const MY_DEALS_LINK_SELECTOR =
        ".gc-account-user-submenu-bar li.menu-item-my_deals .subitem-link";

    function isPrivilegedUser() {
        const info = window.userInfo;
        return !!(info && (info.isAdmin || info.isTeacher || info.isManager));
    }

    function replaceLink(selector, href, text) {
        const el = document.querySelector(selector);
        if (!el) return;

        const a = document.createElement("a");
        a.className = "subitem-link";
        a.href = href;
        a.target = "_self";
        a.textContent = text;

        el.replaceWith(a);
    }

    function applyFixes() {
        if (isPrivilegedUser()) return;

        // Профиль -> /profile
        replaceLink(PROFILE_LINK_SELECTOR, "/profile", "Профиль");

        // Мои аккаунты -> /my-accounts
        replaceLink(MY_ACCOUNTS_LINK_SELECTOR, "/my-accounts", "Мои аккаунты");

        // Смена пароля -> /my-changePassword
        replaceLink(CHANGE_PASSVORD_LINK_SELECTOR, "/changePassword", "Сменить пароль");

        replaceLink(MY_DEALS_LINK_SELECTOR, "/sales/control/userProduct/my", "Мои покупки");
    }

    function start() {
        const menuRoot = document.querySelector(MENU_ROOT_SELECTOR);
        if (!menuRoot) return;

        applyFixes();

        const observer = new MutationObserver(applyFixes);
        observer.observe(menuRoot, { childList: true, subtree: true });
    }

    if (document.readyState === "complete") start();
    else window.addEventListener("load", start, { once: true });
})();
/* -------------
content finish - redirection-student-profile
------------- */

/* -------------
content start - embed-kanban-style
------------- */

(function () {
    if (!location.pathname.includes('/pl/tasks/task/kanban')) return;

    function injectPageStyle() {
        if (document.getElementById('__injected-page-style__')) return;
        const style = document.createElement('style');
        style.id = '__injected-page-style__';
        style.textContent = `
      body.gc-user-logined.right-panel-active .v-dialog__content {
        left: 0;
      }
      body.gc-user-logined.right-panel-active .v-dialog__content > .v-dialog {
        left: 0;
      }
      body.gc-user-logined.right-panel-active .v-dialog__content .sidebar-content-panel > .sidebar-content-panel__content {
        margin-left: 0px;
      }
    `;
        document.head.appendChild(style);

    }

    function injectIframeStyle(iframe) {

        const currentSrc = iframe.src;
        if (iframe.__lastProcessedSrc === currentSrc) return;
        iframe.__lastProcessedSrc = currentSrc;



        let firstSuccessTime = null;
        const watchDuration = 5000;

        function tryInject(source) {
            try {
                const iframeDoc = iframe.contentDocument || iframe.contentWindow?.document;

                if (!iframeDoc || !iframeDoc.head) return false;
                if (iframeDoc.location.href === 'about:blank') return false;
                if (iframeDoc.readyState === 'loading') return false;

                if (iframeDoc.getElementById('__injected-iframe-style__')) return true;

                const style = iframeDoc.createElement('style');
                style.id = '__injected-iframe-style__';
                style.textContent = `.gc-main-content { width: calc(100% - 582px); }`;
                iframeDoc.head.appendChild(style);

                return true;
            } catch (e) {

                return false;
            }
        }

        iframe.addEventListener('load', () => {

            tryInject('load');
        });

        let intervalId = setInterval(() => {
            const success = tryInject('interval');

            if (success && !firstSuccessTime) {
                firstSuccessTime = Date.now();

            }

            if (firstSuccessTime && Date.now() - firstSuccessTime > watchDuration) {
                clearInterval(intervalId);

            }
        }, 200);

        setTimeout(() => {
            clearInterval(intervalId);
        }, 15000);
    }

    function init() {

        injectPageStyle();

        const existingIframe = document.querySelector('iframe');


        if (existingIframe) {
            injectIframeStyle(existingIframe);
        }

        // Observer живёт всегда — не отключаем!
        const observer = new MutationObserver((mutations) => {
            for (const mutation of mutations) {
                for (const node of mutation.addedNodes) {
                    if (node.nodeType !== Node.ELEMENT_NODE) continue;
                    if (node.nodeName === 'IFRAME') {

                        injectIframeStyle(node);
                    }
                    if (node.querySelector) {
                        const iframe = node.querySelector('iframe');
                        if (iframe) {

                            injectIframeStyle(iframe);
                        }
                    }
                }
            }
        });
        observer.observe(document.body, { childList: true, subtree: true });

    }

    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', init);
    } else {
        init();
    }
})();
/* -------------
content finish - embed-kanban-style------------- */
//Получаем и вставляем в меню имя пользователя

(function() {
    // 1. Функция вставки (с вашим оригинальным HTML)
    function injectUserBlock() {
        const menu = document.querySelector('.gc-account-user-menu');

        // Если меню еще нет или блок уже вставлен — выходим
        if (!menu || document.querySelector('.new-user-info-block')) return;

        // Собираем данные (без ожидания)
        const name = window.accountSafeUserName || "Пользователь";
        let email = "";
        try {
            if (window.ULong) {
                const payload = window.ULong.split('.')[0];
                email = JSON.parse(atob(payload))[6] || "";
            }
        } catch (e) { email = ""; }

        const avatar = "/public/img/default_profile_50.png";

        // Создаем элемент li
        const newUserInfoBlock = document.createElement('li');
        newUserInfoBlock.className = 'new-user-info-block';

        // Добавляем стиль, чтобы блок не перехватывал клики у подменю
        newUserInfoBlock.style.pointerEvents = "none";
        newUserInfoBlock.style.listStyle = "none";

        // Вставляем ВАШ оригинальный HTML
        newUserInfoBlock.innerHTML = `
            <div class="ava_name-wrap" style="pointer-events: auto;">
                <img class="new-info-avatar" src="${avatar}" alt="Avatar">
                <div class="name-wrap">  
                    <div class="new-info-name">${name}</div>
                </div>
            </div>
            <div class="new-info-email" style="font-size:12px; opacity:0.7; margin-top:5px; pointer-events: auto;">${email}</div>
        `;

        // Вставляем в самое начало меню
        menu.insertBefore(newUserInfoBlock, menu.firstChild);
    }

    // --- ПАРАЛЛЕЛЬНАЯ И БЕЗОПАСНАЯ ЗАГРУЗКА ---

    // Ждем полной загрузки всех ресурсов окна
    window.addEventListener('load', function() {
        // Небольшая пауза (300мс), чтобы jQuery GetCourse успел "ожить"
        setTimeout(injectUserBlock, 300);
    });

    // На случай, если меню грузится динамически (MutationObserver)
    const observer = new MutationObserver((mutations, obs) => {
        if (document.querySelector('.gc-account-user-menu')) {
            setTimeout(injectUserBlock, 500);
            obs.disconnect(); // Сработало один раз и выключилось
        }
    });

    observer.observe(document.documentElement, { childList: true, subtree: true });
})();
    
    
  