<?php

namespace Elementor;

if (! defined('ABSPATH')) {
	exit;
}

/**
 * Sidebar Filter: Search (standalone Elementor widget).
 *
 * Registered from storzen-elementor-widgets-init.php
 */
class Storzen_Sidebar_Filter_Search extends Widget_Base
{

	public function get_name()
	{
		return 'storzen-sidebar-filter-search';
	}
	public function get_title()
	{
		return esc_html__('Sidebar Filter: Search', 'storzen');
	}
	public function get_icon()
	{
		return 'eicon-search';
	}
	public function get_categories()
	{
		return array('storzen');
	}
	public function get_script_depends()
	{
		return array('storzen-shop-sidebar');
	}

	protected function register_controls()
	{
		$this->start_controls_section(
			'filter_section',
			array(
				'label' => esc_html__('Filter Settings', 'storzen'),
			)
		);

		$this->add_control(
			'style',
			array(
				'label'   => esc_html__('Select Style', 'storzen'),
				'type'    => Controls_Manager::SELECT2,
				'options' => array(
					'style-1' => esc_html__('Style 1', 'storzen'),
				),
				'default' => 'style-1',
			)
		);

		$this->add_control(
			'title',
			array(
				'label'   => esc_html__('Title', 'storzen'),
				'type'    => Controls_Manager::TEXT,
				'default' => esc_html__('Search products', 'storzen'),
			)
		);

		$this->add_control(
			'placeholder',
			array(
				'label'   => esc_html__('Input placeholder', 'storzen'),
				'type'    => Controls_Manager::TEXT,
				'default' => esc_html__('Search products...', 'storzen'),
			)
		);

		$this->add_control(
			'target_element_id',
			array(
				'label'       => esc_html__('Target Archive Widget ID', 'storzen'),
				'type'        => Controls_Manager::TEXT,
				'description' => esc_html__('Paste the ID of the Archive Products Grid widget (right column).', 'storzen'),
			)
		);

		$this->end_controls_section();

		storzen_elementor_sidebar_filter_widget_style_sections($this, 'search');
	}

	protected function render()
	{
		$settings = $this->get_settings_for_display();
		$target   = isset($settings['target_element_id']) ? sanitize_text_field((string) $settings['target_element_id']) : '';
		$id       = $target !== '' ? $target : $this->get_id();
		$title    = isset($settings['title']) ? $settings['title'] : esc_html__('Search products', 'storzen');
		$ph       = isset($settings['placeholder']) ? $settings['placeholder'] : esc_html__('Search products...', 'storzen');
?>
		<div class="szp-shop-sidebar" data-szp-element="<?php echo esc_attr($id); ?>">
			<div class="shop-sidebar">
				<div class="widget widget-search">
					<h6 class="widget-title"><?php echo esc_html($title); ?></h6>
					<form class="szp-keyword-filter-form" data-szp-element="<?php echo esc_attr($id); ?>">
						<input type="text" class="szp-keyword-input" value="" placeholder="<?php echo esc_attr($ph); ?>" />
						<button type="submit"><?php echo esc_html__('Search', 'storzen'); ?></button>
					</form>
				</div>
			</div>
		</div>
<?php
	}
}
