<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit; }
use \Elementor\Widget_Base;
use \Elementor\Controls_Manager;
use \Elementor\Group_Control_Typography;
use \Elementor\Group_Control_Border;
use \Elementor\Group_Control_Box_Shadow;
use \Elementor\Icons_Manager;
use \Sifency\Traits\Sifency_Addons_Animation_Controls;
use Sifency\Traits\Sifency_Addons_Animation_Manager;
use Sifency\Traits\Sifency_Search_Controls;
use Sifency\Traits\Sifency_Addons_Help_Controls;
class Sifency_Widget_Search extends Widget_Base {
	use Sifency_Addons_Animation_Controls;
	use Sifency_Search_Controls;
	use Sifency_Addons_Help_Controls;
	public function __construct( $data = array(), $args = null ) {
		parent::__construct( $data, $args );
		$this->wg_config = array(
			'name'          => 'search-form',
			'title'         => 'Sifency Search Form',
			'icon'          => 'eicon-search',
			'category'      => 'sifency-addons-widgets',
			'keywords'      => array( 'search', 'form', 'input', 'button' ),
			'style_depends' => array( 'sifency-frontend-style', 'sifency-icon' ),
		);}
	protected function register_controls() {
		$this->add_sifency_search_controls();
		$this->add_sifency_addons_help_controls();
		$this->add_Sifency_Addons_Animation_Controls();
		$this->update_control(
			'sifency_animation_target',
			array(
				'type'    => Controls_Manager::HIDDEN,
				'default' => 'wrapper',
			)
		);
	}
	protected function render() {
		$settings          = $this->get_settings_for_display();
		$animation_manager = new Sifency_Addons_Animation_Manager( $settings );
		$wrapper_classes   = array( 'sifency-search-form-wrapper' );
		$wrapper_attrs     = $animation_manager->get_wrapper_attributes( $wrapper_classes );
		$this->add_render_attribute(
			'input',
			array(
				'type'        => 'search',
				'class'       => 'sifency-search-field',
				'placeholder' => $settings['placeholder_text'],
				'name'        => 's',
				'title'       => esc_html__( 'Search', 'sifency-addons' ),
				'value'       => get_search_query(),
			)
		);

		?>
		<div <?php echo wp_kses_post( $wrapper_attrs ); ?>>
			<form role="search" method="get" class="sifency-search-form" action="<?php echo esc_url( home_url( '/' ) ); ?>">
				<input <?php echo wp_kses_post( $this->get_render_attribute_string( 'input' ) ); ?>>
				<button type="submit" class="sifency-search-submit">
					<?php if ( 'icon' === $settings['button_type'] ) : ?>
						<span class="sifency-search-icon">
							<?php \Elementor\Icons_Manager::render_icon( $settings['search_icon'], array( 'aria-hidden' => 'true' ) ); ?>
						</span>
					<?php else : ?>
						<span class="sifency-search-text">
							<?php echo esc_html( $settings['button_text'] ); ?>
						</span>
					<?php endif; ?>
				</button>
			</form>
		</div>
		<?php
	}
}
