// jQuery(document).ready(function($){
//     let hasFilter = $('.tenant-options');


//     if(hasFilter.length != 0) {
//         TenantFilter(hasFilter[0]);
//     }

//     function TenantFilter(filter) {

//         tFilterInit();

//         $('#filterByIndustry, #filterByBuilding').change(function (e) {
//             fieldUpdate();
//             getTentanPost('update');
//         });

//         $('#tenantSearch').keyup(function (e) {
//             fieldUpdate();
//             getTentanPost('update');
//         });

//         $('.alphabet-pagination ul a').click(function (e) {
//             e.preventDefault();

//             if($(this).html() == $('.alphabet-pagination a.active').html()) {
//                 $('.alphabet-pagination a.active').toggleClass('active');
//             }else {
//                 $('.alphabet-pagination a.active').toggleClass('active');
//                 $(this).addClass('active');
//             }

//             fieldUpdate();
//             getTentanPost('update');
//         });

//         $('#clearTenantFilter').click(function(e){
//             e.preventDefault();
//             fieldUpdate('clear');
//             getTentanPost('update');

//             $('.alphabet-pagination .active').toggleClass('active');
//             $('#filterByIndustry').val('Filter by Industry');
//             $('#filterByBuilding').val('Filter by Building');
//             $('#tenantSearch').val('');
//         })

//         getTentanPost();
//     }

//     function tFilterInit() {

//         let params = getDataParams();
//         let alphabet = $('.alphabet-pagination ul a');

//         if(params) {

//             if(params['industry']) {
//                 $('#filterByIndustry').val(params['industry'].replaceAll('+', ' '));
//             }

//             if(params['building']) {
//                 $('#filterByBuilding').val(params['building'].replaceAll('+', ' '));
//             }

//             if(params['search']) {
//                 $('#tenantSearch').val(params['search'].replaceAll('+', ' '));
//             }

//             if(params['alphabet']) {
//                 alphabet.each(function(e){
//                    if($(this).html() == params['alphabet']) {
//                        $(this).addClass('active');
//                    }
//                 });
//             }
//         }

//     }

//     function fieldUpdate(status) {
//         let alphPagination = $('.alphabet-pagination .active');
//         alphPagination = ($(alphPagination).length > 0) ? $(alphPagination).html() : null


//         let filterByIndustry = ($('#filterByIndustry').val() != 'Filter by Industry') ? $('#filterByIndustry').val() : null;
//         let filterByBuilding = ($('#filterByBuilding').val() != 'Filter by Building') ? $('#filterByBuilding').val() : null;
//         let tenantSearch    = ($('#tenantSearch').val().length >= 3) ? $('#tenantSearch').val() : null;

//         let data = {};

//         if(filterByIndustry != null) {
//             data['industry'] = filterByIndustry;
//         }

//         if(filterByBuilding != null) {
//             data['building'] = filterByBuilding
//         }

//         if(tenantSearch != null) {
//             data['search'] = tenantSearch;
//         }

//         if(alphPagination != null) {
//             data['alphabet'] = alphPagination;
//         }

//         if(status == 'clear') {
//             data = {};
//         }

//         let sp   = new URLSearchParams(data);

//         if(data) {
//             setLocation('?' + sp.toString());
//         }
//     }

//     function setLocation(curLoc){
//         try {
//             history.pushState(null, null, curLoc);
//             return;
//         } catch(e) {}
//         location.hash = '#' + curLoc;
//     }

//     function loadMoreTenantPost(max,paged) {
//         ajaxLoading();

//         var ajaxdata = {
//             action: 'getTenantPost',
//             nonce_code: myajax.nonce,
//             data: getDataParams(),
//             paged: paged,
//         }

//         console.log(ajaxdata)

//         jQuery.post( myajax.url, ajaxdata, function(response) {
//             tentanAppendContent(response,'append');
//         });
//     }

//     function getTentanPost(action) {

//         if(action == 'update') {
//             $('.tenant-posts').html('');
//         }

//         ajaxLoading();

//         var ajaxdata = {
//             action: 'getTenantPost',
//             nonce_code: myajax.nonce,
//             data: getDataParams()
//         }

//         jQuery.post( myajax.url, ajaxdata, function(response) {
//             tentanAppendContent(response);
//         });
//     }

//     function tentanAppendContent(content, action) {
//         setTimeout(async function (e) {
//             await $('.ajax-spiner').remove();

//             if(action == 'append') {
//                 $('.tenant-posts .load-more').remove();
//                 $(content).appendTo('.tenant-posts');
//             }else {
//                 $('.tenant-posts').html(content);
//             }

//             if($('.tenant-posts').find('.load-more')) {
//                 $('.tenant-posts .load-more').click(function (e) {
//                     e.preventDefault();

//                     loadMoreTenantPost($(this).attr('max-page'),$(this).attr('paged'))
//                     $('.tenant-posts .load-more').remove();
//                 });
//             }


//             setTimeout(function (e){
//                  window.aligner();
//             },1000)


//         },2500)
//     }

//     function getDataParams() {
//         var params = window
//             .location
//             .search
//             .replace('?','')
//             .split('&')
//             .reduce(
//                 function(p,e){
//                     var a = e.split('=');
//                     p[ decodeURIComponent(a[0])] = decodeURIComponent(a[1]);
//                     return p;
//                 },
//                 {}
//             );

//         return params;
//     }

//     function ajaxLoading() {

//         let spiner = document.createElement('div');
//             $(spiner).addClass('ajax-spiner');
//             $(spiner).html('<div class="ajax-spiner"><img src="/wp-content/uploads/2022/09/ajax-spiner.gif" alt="Spiner"></div>');

//         $(spiner).appendTo('.tenant-posts');
//     }
// });