<?php

namespace Elementor;

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

if (! function_exists(__NAMESPACE__ . '\storzen_filter_target_id')) {
	function storzen_filter_target_id($settings, $fallback)
	{
		$target = isset($settings['target_element_id']) ? sanitize_text_field((string) $settings['target_element_id']) : '';
		return $target !== '' ? $target : $fallback;
	}
}

if (! function_exists(__NAMESPACE__ . '\storzen_filter_multi_attr')) {
	function storzen_filter_multi_attr($settings)
	{
		return ('yes' === ($settings['multi_select'] ?? 'yes')) ? '1' : '0';
	}
}

if (! class_exists(__NAMESPACE__ . '\Storzen_Sidebar_Filter_Base')) {
	abstract class Storzen_Sidebar_Filter_Base extends Widget_Base
	{
		protected function add_target_controls($title_default = 'Filter')
		{
			$this->start_controls_section(
				'filter_section',
				array(
					'label' => esc_html__('Filter Settings', 'storzen'),
				)
			);

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

			$this->add_control(
				'target_element_id',
				array(
					'label'       => esc_html__('Target Archive Widget ID', 'storzen'),
					'type'        => Controls_Manager::TEXT,
					'description' => esc_html__('Set target widget element ID. Leave blank to use current widget ID.', 'storzen'),
				)
			);

			$this->add_control(
				'multi_select',
				array(
					'label'        => esc_html__('Multi-select', 'storzen'),
					'type'         => Controls_Manager::SWITCHER,
					'return_value' => 'yes',
					'default'      => 'yes',
				)
			);

			$this->end_controls_section();
		}
	}
}
