text: $(document).ready(function() {
  
      console.log("1")
      $(".owl-carousel").owlCarousel({
          items: 1,
          nav: true,
          loop: true,
          navText: ["<i class='fas fa-arrow-circle-left'></i>","<i class='fas fa-arrow-circle-right'></i>"]
      });
  
      $(document).on("click", "#welcome", () => {
          const welcomeDiv = $('#welcomeDiv');
          console.log("test")
          if (document.querySelector('#welcome').value === "Показать детальную информацию о товаре") {
              welcomeDiv.fadeIn(300);
              document.querySelector('#welcome').value = "Скрыть детальную информацию о товаре"
          }
          else {
              document.querySelector('#welcome').value = "Показать детальную информацию о товаре"
              welcomeDiv.css('display', 'none')
          }
      });
  
      function getCookie(name) {
          let cookieValue = null;
          if (document.cookie && document.cookie !== '') {
              const cookies = document.cookie.split(';');
              for (let i = 0; i < cookies.length; i++) {
                  const cookie = cookies[i].trim();
                  if (cookie.substring(0, name.length + 1) === (name + '=')) {
                      cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                      break;
                  }
              }
          }
          return cookieValue;
      }
  
      $('.additional').change(function(){
          var product_id = $(this).attr('data-product_id');
          console.log("additional");
          $('#my_form'+product_id).submit()
      });
  
      function sendAddressAdd(user_id, new_city, new_street, new_house, additional) {
        var data = {
          action: 'add_new_address',
          new_city: new_city,
          new_street: new_street,
          new_house: new_house,
          additional: additional,
        };
  
        const csrftoken = getCookie('csrftoken');
          console.log(location.pathname)
          const request = new Request(
              location.pathname,
              // 'accounts'+ user_id +'/settings/',
              {headers: {'X-CSRFToken': csrftoken}}
          );
          fetch(request, {
              method: 'POST',
              mode: 'same-origin',  // Do not send CSRF token to another domain.
              body: JSON.stringify(data)
          }).then(function(response) {
              console.log(response);
          });
        }
  
      $(document).on("click", "#new_address", () => {
          const welcomeDiv = $('#add_new_address');
          if (document.querySelector('#new_address').value === "Добавить новый адрес") {
              welcomeDiv.fadeIn(300);
              document.querySelector('#new_address').value = "Сохранить новый адрес"
          }
          else {
              document.querySelector('#new_address').value = "Добавить новый адрес"
              var user_id = welcomeDiv.attr('data-user')
              var new_city = document.getElementById('settings_city').value
              var new_street = document.getElementById('settings_street').value
              var new_house = document.getElementById('settings_house').value
              var additional = document.getElementById('settings_add').value
              sendAddressAdd(user_id, new_city, new_street, new_house, additional)
              welcomeDiv.css('display', 'none')
          }
      });
  
      function sendAddressMain(main_address) {
        var data = {
          action: 'add_main_address',
          main_address: main_address
        };
  
        const csrftoken = getCookie('csrftoken');
          console.log(location.pathname)
          const request = new Request(
              location.pathname,
              // 'accounts'+ user_id +'/settings/',
              {headers: {'X-CSRFToken': csrftoken}}
          );
          fetch(request, {
              method: 'POST',
              mode: 'same-origin',  // Do not send CSRF token to another domain.
              body: JSON.stringify(data)
          }).then(function(response) {
              console.log(response);
          });
        }
  
      $(document).on("click", "#choose_address", () => {
          const addDiv = $('#list_of_address');
          if (document.querySelector('#choose_address').value === "Выбрать из сохраненных адресов") {
              addDiv.fadeIn(300);
              document.querySelector('#choose_address').value = "Скрыть список адресов"
          }
          else {
              document.querySelector('#choose_address').value = "Выбрать из сохраненных адресов"
              addDiv.css('display', 'none')
          }
      });
  
      // $("#update_profile").on('click', function(){});
  
      $("#add_current_address").on('click', function(){
          var main_address = $('#set_main_address input[name="add_from_list"]:checked').val();
              sendAddressMain(main_address)
      });
  
      $('#log_out').on('click', function(){
            console.log("test");
            $('#logout-modal').modal('show');
            $('.modal-backdrop').remove();
            $('#logout-btn').on('click', function () {
                  window.location = "/logout"
                })
          });
  
      $('#add_comment').on('click', function(){
            console.log("comment test");
            var userp = $(this).attr('data-test');
            var stars = $(this).attr('data-value');
  
            if (!userp) {
                $('#register-modal').modal('show');
                $('.modal-backdrop').remove();
                $('#register-btn').on('click', function () {
                    window.location = "/register"
                })
                $('#login-btn').on('click', function () {
                  window.location = "/login"
                })
              }
          });
  
      function sendRating(stars, product_id) {
        var data = {
          action: 'testing',
          product_id: product_id,
          stars:stars
        };
  
        const csrftoken = getCookie('csrftoken');
          console.log(location.pathname)
          const request = new Request(
              location.pathname,
              {headers: {'X-CSRFToken': csrftoken}}
          );
          fetch(request, {
              method: 'POST',
              mode: 'same-origin',  // Do not send CSRF token to another domain.
              body: JSON.stringify(data)
          }).then(function(response) {
              console.log(response);
          });
        }
  
      $(".rating a").on('click', function(e){
          var stars = $(this).attr('data-value');
          var product_id = $(this).attr('data-id');
          sendRating(stars, product_id)
      });
  
      function sendProfileChanges(username, name, last_name, email, phone, password) {
        var data = {
          action: 'update_profile',
          username: username,
          name: name,
          last_name: last_name,
          email: email,
          phone: phone,
          password: password
        };
  
        const csrftoken = getCookie('csrftoken');
          console.log(location.pathname)
          const request = new Request(
              location.pathname,
              {headers: {'X-CSRFToken': csrftoken}}
          );
          fetch(request, {
              method: 'POST',
              mode: 'same-origin',  // Do not send CSRF token to another domain.
              body: JSON.stringify(data)
          }).then(function(response) {
              console.log(response);
              location.reload();
          });
        }
  
      $("#update_profile").on('click', function(){
          console.log("update")
          const username = document.getElementById('settings_username').value;
          const name = document.getElementById('settings_name').value;
          const last_name = document.getElementById('settings_lastname').value;
          const email = document.getElementById('settings_email').value;
          const phone = document.getElementById('settings_phone').value;
          const password = document.getElementById('settings_password');
          if (password != null && password.value != ''){
              const pass = password.value
              sendProfileChanges(username, name, last_name, email, phone, pass)
          }
          else {
              sendProfileChanges(username, name, last_name, email, phone, "placeholder")
          }
      });
  });
  
  function myFunc(order_id){
      console.log(order_id);
      const hiddenDiv = $('#hiddenDiv'+order_id);
      var test = document.getElementById(order_id);
      if (test.value === "Заказ номер "+ order_id) {
          hiddenDiv.fadeIn(300);
          test.value = "Скрыть детали заказа";
      }
      else {
          test.value = "Заказ номер "+ order_id;
          hiddenDiv.css('display', 'none');
      }
  }