<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}
$selected = '';
if ( isset( $_GET['product_cat'] ) && $_GET['product_cat'] ) {
	$selected = $_GET['product_cat'];
}
$args = array(
	'show_option_none'  => esc_html__( 'All Categories', 'draly-dropshipping-starter' ),
	'taxonomy'          => 'product_cat',
	'class'             => 'category-search-option',
	'hide_empty'        => 1,
	'orderby'           => 'name',
	'order'             => 'ASC',
	'tab_index'         => 1,
	'hierarchical'      => true,
	'id'                => rand(),
	'name'              => 'product_cat',
	'value_field'       => 'slug',
	'selected'          => $selected,
	'option_none_value' => '0',
);
?>
<div class="block-search">
    <form method="get" action="<?php echo esc_url( home_url( '/' ) ) ?>"
          class="form-search block-search-form">
		<?php if ( class_exists( 'WooCommerce' ) ):
			$placeholder = __( 'Search for products', 'draly-dropshipping-starter' );
			?>
            <input type="hidden" name="post_type" value="product"/>
            <input type="hidden" name="taxonomy" value="product_cat">
            <div class="category">
				<?php wp_dropdown_categories( $args ); ?>
            </div>
		<?php else:
			$placeholder = __( 'Search...', 'draly-dropshipping-starter' );
			?>
            <input type="hidden" name="post_type" value="post"/>
		<?php endif; ?>
        <div class="form-content search-box results-search">
            <div class="inner">
                <input aria-label="" autocomplete="off" type="text" class="searchfield txt-livesearch input" name="s"
                       value="<?php echo esc_attr( get_search_query() ); ?>"
                       placeholder="<?php echo esc_attr( $placeholder ); ?>">
            </div>
        </div>
        <button type="submit" class="btn-submit">
            <svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">
                <path d="M15.75 15.75L12.4928 12.4927M12.4928 12.4927C13.0499 11.9356 13.4919 11.2741 13.7934 10.5461C14.095 9.81816 14.2502 9.03792 14.2502 8.24997C14.2502 7.46202 14.095 6.68178 13.7934 5.95381C13.4919 5.22584 13.0499 4.56439 12.4928 4.00722C11.9356 3.45006 11.2741 3.00809 10.5462 2.70655C9.81819 2.40502 9.03795 2.24982 8.25 2.24982C7.46205 2.24982 6.68181 2.40502 5.95384 2.70655C5.22587 3.00809 4.56442 3.45006 4.00725 4.00722C2.882 5.13247 2.24985 6.65863 2.24985 8.24997C2.24985 9.84131 2.882 11.3675 4.00725 12.4927C5.1325 13.618 6.65866 14.2501 8.25 14.2501C9.84134 14.2501 11.3675 13.618 12.4928 12.4927Z" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
            </svg>
            <?php echo esc_html__( 'Search', 'draly-dropshipping-starter' ) ?>
        </button>
    </form>
</div>