<?php
global $wp;
$current_url = home_url( add_query_arg( array(), $wp->request ) );
?>
<form class="hero-form form woocommerce-product-search" role="search" method="get" action="<?php echo $current_url; ?>/">
<?php
$search_style = get_theme_mod( 'charsoogh_header_search' , 'style-1');
$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;
$city_selected_slug = $wcatTerm->slug;
}
endforeach;
if(isset($_GET['search'])){$search_value = $_GET['search'];}
if(isset($_GET['city_categories'])){$city = $_GET['city_categories'];}
if(isset($_GET['product_cat'])){$cat = $_GET['product_cat'];}else{$cat = '';}
?>
    <div class="container">
        <!--Main Form-->
        <div class="main-search-form <?php echo $search_style; ?>">
            <div class="form-row">
                <div class="col-md-5 col-sm-5">
                    <div class="form-group">
                        <input name="search" type="text" class="form-control" id="what" placeholder="<?php _e('Search all ads' , 'charsoogh'); ?>" value="<?php echo @$search_value; ?>">
                    </div>
                </div>
                <div class="<?php if($search_style == 'style-1'){echo 'col-md-2 col-sm-2';}else{echo 'col-md-3 col-sm-3';} ?>">
                    <div class="form-group">
                      <?php
                      if(empty($cookie_city) || $cookie_city == 'all'){
                        if(empty($city)){$city = $cookie_city;}
                    wp_dropdown_categories( 'taxonomy=city_categories&name=city_categories&hierarchical=1&depth=1&show_option_none='. __("All cities" , "charsoogh") .'&value_field=slug&option_none_value=0&selected='. $city .'' );
                    }else{
                      if(empty($city)){$city = $cookie_city;}
                      wp_dropdown_categories( "taxonomy=city_categories&name=city_categories&child_of=$cookie_city&hierarchical=1&show_option_none=$city_selected&value_field=slug&option_none_value=$city_selected_slug&selected=$city");
                    }
                      ?>
                    </div>
                </div>
                <div class="col-md-3 col-sm-3">
                    <div class="form-group">
                      <?php
                      if($cat){
                      wp_dropdown_categories( 'taxonomy=product_cat&name=product_cat&hierarchical=1&show_option_none='. __("All categories" , "charsoogh") .'&value_field=slug&option_none_value=0&selected='. $cat .'' );
                    }else{
                      wp_dropdown_categories( 'taxonomy=product_cat&name=product_cat&hierarchical=1&show_option_none='. __("All categories" , "charsoogh") .'&value_field=slug&option_none_value=0' );
                    }
                       ?>
                    </div>
                </div>
                <div class="<?php if($search_style == 'style-1'){echo 'col-md-2 col-sm-2';}else{echo 'col-md-1 col-sm-1';} ?>">
                    <button type="submit" class="btn btn-primary width-100"><?php if($search_style == 'style-1'){ _e('Search' , 'charsoogh'); }else{echo '<i class="fa fa-search" aria-hidden="true"></i>';} ?></button>
                </div>
            </div>
        </div>
    </div>
</form>
