<?php if (get_theme_mod( 'charsoogh_city_select_show' , 'yes') != 'no' ) : ?>
<ul class="<?php if ( is_rtl() ): echo 'left'; else: echo 'right'; endif; ?>">
<li>
  <?php
$cookie_city = @$_COOKIE['city_user'];
$wcatTerms = get_terms('city_categories', array('hide_empty' => 0, 'parent' =>0));
foreach($wcatTerms as $wcatTerm) :
if($cookie_city == $wcatTerm->term_id){
$city_selected = $wcatTerm->name;
}
endforeach;
?>
  <button type="button" class="btn btn-primary city-select-btn" data-toggle="modal" data-target="#city-select-modal">
  <i class="fa fa-map-marker" aria-hidden="true"></i> <?php if(!@$city_selected){
    echo __('Select City' , 'charsoogh');
  }else{ echo @$city_selected; } ?>
  </button>
  <!-- Modal -->
  <div class="modal fade" id="city-select-modal" tabindex="-1" role="dialog" aria-labelledby="city-select-modalTitle" aria-hidden="true">
    <div class="modal-dialog modal-lg" role="document">
      <div class="modal-content">
        <div class="loading"><div class="loader-show"></div></div>
        <div class="modal-header">
          <h5 class="modal-title" id="city-select-modalTitle"><?php if(!empty(get_theme_mod( 'charsoogh_city_button_text'))){echo get_theme_mod( 'charsoogh_city_button_text'); } else{echo __('Select City' , 'charsoogh');}; ?></h5>
          <ul class="all-city"><li data-city="all"><?php _e('(Select All)' , 'charsoogh'); ?></li></ul>
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
          </button>
        </div>
        <div class="modal-body">
          <div class="city-search-box">
            <input class="form-control" id="city_search" type="text" placeholder="<?php _e('Quick Search ...' , 'charsoogh'); ?>">
            <i class="fa fa-search" aria-hidden="true"></i>
          </div>

          <ul class="city_list">
            <?php
$wcatTerms = get_terms('city_categories', array('hide_empty' => 0, 'parent' =>0));
   foreach($wcatTerms as $wcatTerm) :
     if($cookie_city == $wcatTerm->term_id){
   ?>
   <li data-city="<?php echo $wcatTerm->term_id; ?>" class="selected-city"><?php echo $wcatTerm->name; ?></li>
 <?php }else{ ?>
   <li data-city="<?php echo $wcatTerm->term_id; ?>"><?php echo $wcatTerm->name; ?></li>
 <?php } ?>
<?php endforeach; ?>
          </ul>
          <div class="realoading"></div>
          <script>
jQuery(".city_list li").click(function(){jQuery(".modal-content .loading").css("display","block"),jQuery(this).find(".selected").text();var t=this.getAttribute("data-city");jQuery.post("<?php bloginfo('template_url'); ?>/includes/set-cookies.php",{city_name:t},function(t){jQuery("div.realoading").html(t)})}),jQuery(".all-city li").click(function(){jQuery(".modal-content .loading").css("display","block");var t=this.getAttribute("data-city");jQuery.post("<?php bloginfo('template_url'); ?>/includes/set-cookies.php",{city_name:t},function(t){jQuery("div.realoading").html(t)})}),jQuery(document).ready(function(){jQuery("#city_search").on("keyup",function(){var t=jQuery(this).val().toLowerCase();jQuery(".city_list li").filter(function(){jQuery(this).toggle(jQuery(this).text().toLowerCase().indexOf(t)>-1)})})});
        </script>
        </div>
      </div>
    </div>
  </div>
</li>
</ul>
<?php endif; ?>
