<?php
namespace Elementor;
if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}
class HeaderCartSearch extends Widget_Base {

	public function get_name() {
		return 'gc-daynaweb-header-cart-search';
	}

	public function get_title() {
		return 'دکمه سبد خرید و جستجو در هدر';
	}

	public function get_icon() {
		return 'eicon-product-description';
	}

	public function get_categories() {
		return [ 'gajcommerce' ];
	}

	protected function _register_controls() {

		$this->start_controls_section(
			'section_title',
			[
				'label' => __( 'Content', 'elementor' ),
			]
		);

		$this->add_control(
			'correlation',
			[
				'label' => __( 'قرینه سازی', 'gajcommerce' ),
				'type' => Controls_Manager::SWITCHER,
				'label_on' => __( 'بله', 'gajcommerce' ),
				'label_off' => __( 'خیر', 'gajcommerce' ),
				'return_value' => 'yes',
				'default' => 'no',
			]
		);

		$this->add_control(
			'position',
			[
				'label' => __( 'موقعیت', 'gajcommerce' ),
				'type' => Controls_Manager::SELECT,
				'default' => 'right',
				'options' => [
					'right' => esc_html__( 'راست', 'textdomain' ),
					'center'  => esc_html__( 'وسط', 'textdomain' ),
					'left' => esc_html__( 'چپ', 'textdomain' ),
				],
			]
		);


		$this->end_controls_section();
	}

	protected function render() {

  $settings = $this->get_settings_for_display();

	if ( $settings['position'] === 'right' ) { $cartsearchpos = 'justify-content-start'; }
	elseif ( $settings['position'] === 'center' ) { $cartsearchpos = 'justify-content-center'; }
	elseif ( $settings['position'] === 'left' ) { $cartsearchpos = 'justify-content-end'; }

	if ( 'yes' === $settings['correlation'] ) { ?>

		<div class="row correlated">
			<div class="col-12 d-none d-md-flex <?php echo $cartsearchpos; ?>">
				<div class="searchareagm">
					<?php if (is_plugin_active('ajax-search-for-woocommerce/ajax-search-for-woocommerce.php')) {
						echo do_shortcode('[fibosearch]');
					} else { get_search_form(); } ?>
				</div>
				<div class="cartbox">
					<a href="<?php echo wc_get_cart_url(); ?>"><i class="fas fa-shopping-cart"></i> | <figure>سبد خرید</figure> <span><?php echo is_object( WC()->cart ) ? WC()->cart->get_cart_contents_count() : ''; ?></span></a>
				</div>
			</div>
		</div>

<?php	} else{ ?>

	<div class="row">
		<div class="col-12 d-none d-md-flex <?php echo $cartsearchpos; ?>">
			<div class="cartbox">
				<a href="<?php echo wc_get_cart_url(); ?>"><i class="fas fa-shopping-cart"></i> | <figure>سبد خرید</figure> <span><?php echo is_object( WC()->cart ) ? WC()->cart->get_cart_contents_count() : ''; ?></span></a>
			</div>
			<div class="searchareagm">
				<?php if (is_plugin_active('ajax-search-for-woocommerce/ajax-search-for-woocommerce.php')) {
					echo do_shortcode('[fibosearch]');
				} else { get_search_form(); } ?>
			</div>
		</div>
	</div>

<?php	} ?>



<?php
	}
}
