'use strict'

const btn_mobile = document.getElementById('btn-s-b-r');
const navbar = document.getElementById('s-bar-r');
const bg_mobile = document.getElementById('btn-s-b-r-close');

btn_mobile.addEventListener('click',function(){
    console.log('hi')
  navbar.classList.toggle('active');
  bg_mobile.classList.toggle('active');
})

bg_mobile.addEventListener('click',function(){
  navbar.classList.remove('active');
  bg_mobile.classList.remove('active');
})


var input = document.querySelector('input[name="tags1"]');

        var whitelist = ["منزلي", "منزلي مركب", "تجاري", "حكومي", "وزارات", "بلدية", "أخرى"];

        var tagify = new Tagify(input, {
            whitelist:whitelist,
            maxTags: 10,
            dropdown: {
                maxItems: 20,          
                classname: "tags-look", 
                enabled: 0,            
                closeOnSelect: true   
            }
});

var input = document.querySelector('input[name="tags2"]');

        var whitelist = ["بدون", "مسبق دفع", " مسبق دفع غير ملتزم بالشحن آخر 6 شهور", "سداد آلي ملتزم", "سداد آلي غير ملتزم آخر 6 شهور"];

        var tagify = new Tagify(input, {
            whitelist:whitelist,
            maxTags: 10,
            dropdown: {
                maxItems: 20,          
                classname: "tags-look", 
                enabled: 0,            
                closeOnSelect: true   
            }
});

var input = document.querySelector('input[name="tags3"]');

        var whitelist = ["ميكانيكي", "هولي", "ذكي"];

        var tagify = new Tagify(input, {
            whitelist:whitelist,
            maxTags: 10,
            dropdown: {
                maxItems: 20,          
                classname: "tags-look", 
                enabled: 0,            
                closeOnSelect: true   
            }
});

var input = document.querySelector('input[name="tags4"]');

        var whitelist = ["منزلي", "منزلي مركب", "تجاري", "حكومي", "وزارات", "بلدية", "أخرى"];

        var tagify = new Tagify(input, {
            whitelist:whitelist,
            maxTags: 10,
            dropdown: {
                maxItems: 20,          
                classname: "tags-look", 
                enabled: 0,            
                closeOnSelect: true   
            }
});

var input = document.querySelector('input[name="tags5"]');

        var whitelist = ["بدون", "مسبق دفع", " مسبق دفع غير ملتزم بالشحن آخر 6 شهور", "سداد آلي ملتزم", "سداد آلي غير ملتزم آخر 6 شهور"];

        var tagify = new Tagify(input, {
            whitelist:whitelist,
            maxTags: 10,
            dropdown: {
                maxItems: 20,          
                classname: "tags-look", 
                enabled: 0,            
                closeOnSelect: true   
            }
});

var input = document.querySelector('input[name="tags6"]');

        var whitelist = ["ميكانيكي", "هولي", "ذكي"];

        var tagify = new Tagify(input, {
            whitelist:whitelist,
            maxTags: 10,
            dropdown: {
                maxItems: 20,          
                classname: "tags-look", 
                enabled: 0,            
                closeOnSelect: true   
            }
});



document.getElementById("filter-form").addEventListener("submit", function (event) {
  event.preventDefault(); // Prevent the default form submission behavior

  // Check if at least one input has data
  const inputs = document.querySelectorAll("input");
  let hasData = false;
  for (const input of inputs) {
    if (input.value.trim() !== "") {
      hasData = true;
      break;
    }
  }

  if (hasData) {
    // At least one input has data, so you can proceed with form submission
    event.target.submit();
  } else {
    // No input has data, show an error message or handle as appropriate
    Swal.fire({
      title: 'يرجى ملء إدخال واحد على الأقل قبل البحث',
      icon: 'info',
      showCloseButton: false,
      showCancelButton: false,
      focusConfirm: false,
      confirmButtonText:
        'حسناً!',
      confirmButtonAriaLabel: 'Thumbs up, great!',
    })
  }
});

