

(() => {
  // УДАЛЕНИЕ СИСТЕМНЫХ ЗАКАЗОВ В РАЗДЕЛЕ "ПОКУПКИ"
  // (С) Трофимов Никита Игоревич (Бородатый тех.спец) https://t.me/NiktarioN 2022

  const hideSystemOrders = () => {
    //////////////////////////////////////////////////////////////////////////////////////
    // ПАНЕЛЬ УПРАВЛЕНИЯ. НАЧАЛО

    // Определяем стоп-слова по которым будут удаляться позиции на странице
    // Прописываем их в одинарных кавычках и через запятую
    const stopWords = [
      'Регистрация',
      'Вход',
      'Запись',
      'Технические',
      '[тех]',
    ];

    //////////////////////////////////////////////////////////////////////////////////////
    // ПАНЕЛЬ УПРАВЛЕНИЯ. КОНЕЦ

    if (!window.location.href.includes('/sales/control/userProduct/my')) {
      return;
    }

    const mainBox = document.querySelector('.gc-main-content');
    if (!mainBox) {
      return;
    }

    const isEmployee = ['gc-user-teacher', 'gc-user-admin'].find((item) => mainBox.classList.contains(item));
    if (isEmployee) {
      return;
    }

    const strings = document.querySelectorAll('.main-page-block .container table tbody tr');
    if (!strings.length) {
      return;
    }

    stopWords.forEach((item) => {
      hideElement(item);
    });

    function hideElement(stopWord) {
      for (let i = 0; i < strings.length; i++) {
        const stringColumn = strings[i].querySelectorAll('td');
        for (let j = 0; j < stringColumn.length; j++) {
          const item = stringColumn[j].textContent.trim().toLowerCase();
          if (item.includes(stopWord.toLowerCase())) {
            strings[i].style.display = 'none';
            break;
          }
        }
      }
    }
  };
  window.addEventListener('DOMContentLoaded', hideSystemOrders);
})();
