$(document).ready(function() {
    let width = $(window).width(); // New width
    let height = $('#header-sticky').height();
    slider(width, height);
    mainSearch(width);
    
    $(window).on('resize', function() {
        width = $(window).width();
        height = $('#header-sticky').height();

        slider(width, height);

        mainSearch(width);

    });

    $('.net-tab .panel-content [id$=_NewsList]').append('<a href="#" class="more-news">بیشتر</a>');

});


function mainSearch(width) {
    $('.toggle-search').on('click', function() {
        $(this).toggleClass('active');
        $(this).find('i').toggleClass('fa-times-circle');
        $('.dp-search').toggleClass('active');
        $('#overlay').removeClass('active');
    });

    // if(width < 992) {
    //     $('.toggle-search').on('click', function() {
    //         // $(this).find('i').addClass('fa-times');
    //         $('.dp-search').addClass('active');
    //         $('#overlay').addClass('active');
    //     });
    // } else {
    //     $('.toggle-search').on('click', function() {
    //         $(this).toggleClass('active');
    //         // $(this).find('i').toggleClass('fa-times');
    //         $('.dp-search').toggleClass('active');
    //         $('#overlay').removeClass('active');
    //     });
    // }

    // $('#overlay').on('click', function() {
    //     $(this).removeClass('active');
    //     $('.toggle-search').find('i').removeClass('fa-times');
    //     $('.dp-search').removeClass('active');
    // });
}

function slider(width, height) {
    if(width > 600) {
        $("main#wrap\\: .main-slider").css('margin-top', height * -1+'px');
    } else {
        $("main#wrap\\: .main-slider").css('margin-top', height * 0+'px');
    }
}

function scrollTop() {
    $("html, body").animate({
        scrollTop: 0
    }, "slow");
}

// function getUserData(userId) {
//     return new Promise((resolve, reject) => {
//       // شبیه‌سازی دریافت اطلاعات کاربر از یک منبع
//       setTimeout(() => {
//         const userData = {
//           id: userId,
//           name: 'John Doe',
//           age: 30
//         };
//         resolve(userData);
//       }, 2000); // شبیه‌سازی طولانی بودن عملیات
//     });
//   }
   
//   function getUserPosts(userId) {
//     return new Promise((resolve, reject) => {
//       // شبیه‌سازی دریافت پست‌های کاربر از یک منبع
//       setTimeout(() => {
//         const userPosts = [
//           { id: 1, title: 'Post 1', content: 'Lorem ipsum dolor sit amet.' },
//           { id: 2, title: 'Post 2', content: 'Pellentesque habitant morbi tristique senectus.' }
//         ];
//         resolve(userPosts);
//       }, 1500); // شبیه‌سازی طولانی بودن عملیات
//     });
//   }
  
  // استفاده از Promise و .then() برای اجرای همزمان
  
  // getUserData(123)
  //   .then((userData) => {
  //     console.log('اطلاعات کاربر:', userData);
  //     return getUserPosts(userData.id);
  //   })
  //   .then((userPosts) => {
  //     console.log('پست‌های کاربر:', userPosts);
  //   })
  //   .catch((error) => {
  //     console.error('خطا:', error);
  //   });