<?php if (!class_exists('WP_Customize_Control')) {

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}
	return null;
}

class pawfect_Repeater extends WP_Customize_Control
{

	/*Enqueue resources for the control*/
	public function enqueue()
	{
		wp_enqueue_style('wp-color-picker');
		wp_enqueue_script('wp-color-picker');
		wp_enqueue_script('jquery-ui-draggable');
		wp_enqueue_script('jquery-ui-sortable');

		$uri = get_template_directory_uri() . '/inc/customizer/assets/';

		wp_enqueue_style('pawfect-fontawesome-iconpicker-css', $uri . 'css/fontawesome-iconpicker.min.css', array(), PAWFECT_THEME_VERSION);
		wp_enqueue_style('pawfect-admin-style-css', $uri . 'css/admin-style.css', array(), PAWFECT_THEME_VERSION);

		wp_enqueue_script('pawfect-customizer-repeater-js', $uri . 'js/customizer_repeater.js', array('jquery', 'jquery-ui-draggable', 'jquery-ui-sortable', 'wp-color-picker'), PAWFECT_THEME_VERSION, true);
		wp_enqueue_script('pawfect-fontawesome-iconpicker-js', $uri . 'js/fontawesome-iconpicker.js', array('jquery'), PAWFECT_THEME_VERSION, true);

		// Enhanced icon picker for social media
		wp_enqueue_style('pawfect-enhanced-icon-picker-css', $uri . 'css/enhanced-icon-picker.css', [], PAWFECT_THEME_VERSION);
		wp_enqueue_script('pawfect-enhanced-icon-picker-js', $uri . 'js/enhanced-icon-picker.js', ['jquery', 'customize-controls'], PAWFECT_THEME_VERSION, true);
	}


	public $id;
	private $boxtitle = array();
	private $add_field_label = array();
	private $customizer_repeater_title_control = false;
	private $customizer_repeater_subtitle_control = false;
	private $customizer_repeater_button_text_control = false;
	private $customizer_repeater_link_control = false;
	private $customizer_repeater_slide_content_format_type = false;
	private $customizer_repeater_slide_format = false;
	private $customizer_repeater_video_url_control = false;
	private $customizer_repeater_rating_control = false;
	private $customizer_repeater_image_control = false;
	private $customizer_repeater_icon_control = false;
	private $customizer_repeater_product_select_control = false;


	private $customizer_repeater_svg_control = false; // ADDED
	private $customizer_repeater_color_control = false;
	private $customizer_repeater_text_control = false;
	private $customizer_repeater_designation_control = false;
	private $customizer_repeater_shortcode_control = false;

	private $customizer_repeater_text_two_control = false;

	private $customizer_repeater_text_three_control = false;

	private $customizer_repeater_position_select_control = false;
	private $customizer_repeater_position_draggable_control = false;


	private $customizer_repeater_repeater_control = false;
	private $customizer_repeater_checkbox_control = false;

	private $customizer_icon_container = '';
	private $allowed_html = array();


	/*Class constructor*/
	public function __construct($manager, $id, $args = array())
	{
		parent::__construct($manager, $id, $args);
		/*Get options from customizer.php*/
		$this->add_field_label = esc_html__('Add new field', 'pawfect');
		if (!empty($args['add_field_label'])) {
			$this->add_field_label = $args['add_field_label'];
		}

		$this->boxtitle = esc_html__('Customizer Repeater', 'pawfect');
		if (!empty($args['item_name'])) {
			$this->boxtitle = $args['item_name'];
		} elseif (!empty($this->label)) {
			$this->boxtitle = $this->label;
		}

		if (!empty($args['customizer_repeater_image_control'])) {
			$this->customizer_repeater_image_control = $args['customizer_repeater_image_control'];
		}

		if (!empty($args['customizer_repeater_icon_control'])) {
			$this->customizer_repeater_icon_control = $args['customizer_repeater_icon_control'];
		}
		if (!empty($args['customizer_repeater_product_select_control'])) {
			$this->customizer_repeater_product_select_control = $args['customizer_repeater_product_select_control'];
		}

		if (!empty($args['customizer_repeater_svg_control'])) { // ADDED
			$this->customizer_repeater_svg_control = $args['customizer_repeater_svg_control'];
		}

		if (!empty($args['customizer_repeater_color_control'])) {
			$this->customizer_repeater_color_control = $args['customizer_repeater_color_control'];
		}

		if (!empty($args['customizer_repeater_title_control'])) {
			$this->customizer_repeater_title_control = $args['customizer_repeater_title_control'];
		}

		if (!empty($args['customizer_repeater_subtitle_control'])) {
			$this->customizer_repeater_subtitle_control = $args['customizer_repeater_subtitle_control'];
		}

		if (!empty($args['customizer_repeater_text_control'])) {
			$this->customizer_repeater_text_control = $args['customizer_repeater_text_control'];
		}

		if (!empty($args['customizer_repeater_designation_control'])) {
			$this->customizer_repeater_designation_control = $args['customizer_repeater_designation_control'];
		}

		if (!empty($args['customizer_repeater_button_text_control'])) {
			$this->customizer_repeater_button_text_control = $args['customizer_repeater_button_text_control'];
		}

		if (!empty($args['customizer_repeater_link_control'])) {
			$this->customizer_repeater_link_control = $args['customizer_repeater_link_control'];
		}

		if (!empty($args['customizer_repeater_checkbox_control'])) {
			$this->customizer_repeater_checkbox_control = $args['customizer_repeater_checkbox_control'];
		}

		if (!empty($args['customizer_repeater_slide_content_format_type'])) {
			$this->customizer_repeater_slide_content_format_type = $args['customizer_repeater_slide_content_format_type'];
		}

		if (!empty($args['customizer_repeater_slide_format'])) {
			$this->customizer_repeater_slide_format = $args['customizer_repeater_slide_format'];
		}

		if (!empty($args['customizer_repeater_video_url_control'])) {
			$this->customizer_repeater_video_url_control = $args['customizer_repeater_video_url_control'];
		}

		if (!empty($args['customizer_repeater_rating_control'])) {
			$this->customizer_repeater_rating_control = $args['customizer_repeater_rating_control'];
		}


		if (!empty($args['customizer_repeater_shortcode_control'])) {
			$this->customizer_repeater_shortcode_control = $args['customizer_repeater_shortcode_control'];
		}

		if (!empty($args['customizer_repeater_text_two_control'])) {
			$this->customizer_repeater_text_two_control = $args['customizer_repeater_text_two_control'];
		}

		if (!empty($args['customizer_repeater_text_three_control'])) {
			$this->customizer_repeater_text_three_control = $args['customizer_repeater_text_three_control'];
		}
		if (!empty($args['customizer_repeater_position_select_control'])) {
			$this->customizer_repeater_position_select_control = $args['customizer_repeater_position_select_control'];
		}
		if (!empty($args['customizer_repeater_position_draggable_control'])) {
			$this->customizer_repeater_position_draggable_control = $args['customizer_repeater_position_draggable_control'];
		}
		if (!empty($args['customizer_repeater_repeater_control'])) {
			$this->customizer_repeater_repeater_control = $args['customizer_repeater_repeater_control'];
		}

		if (!empty($id)) {
			$this->id = $id;
		}

		//customizer show icons on input field icons on click (service settings) 
		if (file_exists(get_template_directory() . '/inc/customizer/customizer-repeater/inc/icons.php')) {
			$this->customizer_icon_container = 'inc/customizer/customizer-repeater/inc/icons';
		}

		$allowed_array1 = wp_kses_allowed_html('post');
		$allowed_array2 = array(
			'input' => array(
				'type' => array(),
				'class' => array(),
				'placeholder' => array()
			)
		);

		$this->allowed_html = array_merge($allowed_array1, $allowed_array2);
	}

	public function render_content()
	{
		/*Get default options*/
		$this_default = json_decode($this->setting->default);

		/*Get values (json format)*/
		$values = $this->value();

		/*Decode values*/
		$json = json_decode($values);

		if (!is_array($json)) {
			$json = array($values);
		} ?>

		<span class="customize-control-title"><?php echo esc_html($this->label); ?></span>
		<div class="customizer-repeater-general-control-repeater customizer-repeater-general-control-droppable">
			<?php
			if ((count($json) == 1 && '' === $json[0]) || empty($json)) {
				if (!empty($this_default)) {
					$this->iterate_array($this_default); ?>
					<input type="hidden" id="customizer-repeater-<?php echo esc_attr($this->id); ?>-colector" <?php esc_attr($this->link()); ?> class="customizer-repeater-colector"
						value="<?php echo esc_textarea(json_encode($this_default)); ?>" />
					<?php
				} else {
					$this->iterate_array(); ?>
					<input type="hidden" id="customizer-repeater-<?php echo esc_attr($this->id); ?>-colector" <?php esc_attr($this->link()); ?> class="customizer-repeater-colector" />
					<?php
				}
			} else {
				$this->iterate_array($json); ?>
				<input type="hidden" id="customizer-repeater-<?php echo esc_attr($this->id); ?>-colector" <?php esc_attr($this->link()); ?> class="customizer-repeater-colector"
					value="<?php echo esc_textarea($this->value()); ?>" />
				<?php
			} ?>
		</div>
		<button type="button" class="button add_field customizer-repeater-new-field">
			<?php echo esc_html($this->add_field_label); ?>
		</button>
		<?php
	}

	private function iterate_array($array = array())
	{

		/*Counter that helps checking if the box is first and should have the delete button disabled*/
		$it = 0;
		if (!empty($array)) {
			foreach ($array as $icon) { ?>
				<div class="customizer-repeater-general-control-repeater-container customizer-repeater-draggable">
					<div class="customizer-repeater-customize-control-title">
						<?php echo esc_html($this->boxtitle) ?>
					</div>
					<div class="customizer-repeater-box-content-hidden">
						<?php
						// Initialize variables to prevent undefined variable warnings
						$choice = $image_url = $icon_value = $svg_code = $title = $subtitle = $text = $slide_format = $content_format = $rating_control = $link = $designation = $button = $open_new_tab = $shortcode = $text_two = $text_three = $item_id = $position_preset = $repeater = $color = $video_url = $product_select = '';
						if (!empty($icon->id)) {
							$id = $icon->id;
						}
						$item_id = !empty($icon->id) ? $icon->id : 'customizer-repeater-' . uniqid();




						if (!empty($icon->choice)) {
							$choice = $icon->choice;
						}
						if (!empty($icon->image_url)) {
							$image_url = $icon->image_url;
						}
						if (!empty($icon->icon_value)) {
							$icon_value = $icon->icon_value;
						}
						if (!empty($icon->svg_code)) { // ADDED
							$svg_code = $icon->svg_code;
						}
						if (!empty($icon->color)) {
							$color = $icon->color;
						}
						if (!empty($icon->title)) {
							$title = $icon->title;
						}

						if (!empty($icon->designation)) {
							$designation = $icon->designation;
						}
						if (!empty($icon->product_select)) {
							$product_select = $icon->product_select;
						}

						if (!empty($icon->subtitle)) {
							$subtitle = $icon->subtitle;
						}
						if (!empty($icon->text)) {
							$text = $icon->text;
						}
						if (!empty($icon->video_url)) {
							$video_url = $icon->video_url;
						}

						if (!empty($icon->slide_format)) {
							$slide_format = $icon->slide_format;
						}

						if (!empty($icon->content_format)) {
							$content_format = $icon->content_format;
						}

						if (!empty($icon->rating_control)) {
							$rating_control = $icon->rating_control;
						}

						if (!empty($icon->button_text)) {
							$button = $icon->button_text;
						}
						if (!empty($icon->link)) {
							$link = $icon->link;
						}
						if (!empty($icon->shortcode)) {
							$shortcode = $icon->shortcode;
						}
						if (!empty($icon->text_two)) {
							$text_two = $icon->text_two;
						}

						if (!empty($icon->text_three)) {
							$text_three = $icon->text_three;
						}

						if (!empty($icon->position_preset)) {
							$position_preset = $icon->position_preset;
						}


						if (!empty($icon->social_repeater)) {
							$repeater = $icon->social_repeater;
						}

						if (!empty($icon->open_new_tab)) {
							$open_new_tab = $icon->open_new_tab;
						}


						if ($this->customizer_repeater_title_control == true) {
							$this->input_control(array(
								'label' => apply_filters('pawfect_repeater_input_labels_filter', esc_html__('Title', 'pawfect'), $this->id, 'customizer_repeater_title_control'),
								'class' => 'customizer-repeater-title-control',
								'type' => apply_filters('pawfect_repeater_input_types_filter', '', $this->id, 'customizer_repeater_title_control'),
							), $title);
						}
						if ($this->customizer_repeater_subtitle_control == true) {
							$this->input_control(array(
								'label' => apply_filters('pawfect_repeater_input_labels_filter', esc_html__('Subtitle', 'pawfect'), $this->id, 'customizer_repeater_subtitle_control'),
								'class' => 'customizer-repeater-subtitle-control',
								'type' => apply_filters('pawfect_repeater_input_types_filter', '', $this->id, 'customizer_repeater_subtitle_control'),
							), $subtitle);
						}
						if ($this->customizer_repeater_text_control == true) {
							$this->input_control(array(
								'label' => apply_filters('pawfect_repeater_input_labels_filter', esc_html__('Description', 'pawfect'), $this->id, 'customizer_repeater_text_control'),
								'class' => 'customizer-repeater-text-control',
								'type' => apply_filters('pawfect_repeater_input_types_filter', 'textarea', $this->id, 'customizer_repeater_text_control'),
							), $text);
						}


						if ($this->customizer_repeater_button_text_control) {
							$this->input_control(array(
								'label' => apply_filters('pawfect_repeater_input_labels_filter', esc_html__(
									'Button-Text',
									'pawfect'
								), $this->id, 'customizer_repeater_button_text_control'),
								'class' => 'customizer-repeater-button-text-control',
								'type' => apply_filters(
									'pawfect_repeater_input_types_filter',
									'',
									$this->id,
									'customizer_repeater_button_text_control'
								),
							), $button);
						}


						if ($this->customizer_repeater_link_control) {
							$this->input_control(array(
								'label' => apply_filters('pawfect_repeater_input_labels_filter', esc_html__('Link', 'pawfect'), $this->id, 'customizer_repeater_link_control'),
								'class' => 'customizer-repeater-link-control',
								'sanitize_callback' => 'esc_url_raw',
								'type' => apply_filters('pawfect_repeater_input_types_filter', '', $this->id, 'customizer_repeater_link_control'),
							), $link);
						}

						if ($this->customizer_repeater_checkbox_control == true) {
							$this->testimonila_check($open_new_tab);

						}


						if ($this->customizer_repeater_slide_content_format_type == true) {
							$this->content_format($content_format);

						}

						if ($this->customizer_repeater_slide_format == true) {
							$this->slide_format($slide_format);

						}

						if ($this->customizer_repeater_rating_control == true) {
							$this->rating_control($rating_control);

						}

						if ($this->customizer_repeater_video_url_control) {
							$this->input_control(array(
								'label' => apply_filters('pawfect_repeater_input_labels_filter', esc_html__(
									'Video Url',
									'pawfect'
								), $this->id, 'customizer_repeater_video_url_control'),
								'class' => 'customizer-repeater-video-url-control',
								'type' => apply_filters('customizer_repeater_video_url_control', 'textarea', $this->id, 'customizer_repeater_video_url_control'),
							), $video_url);
						}



						if ($this->customizer_repeater_image_control == true && $this->customizer_repeater_icon_control == true) {
							$this->icon_type_choice($choice);
						}
						if ($this->customizer_repeater_image_control == true) {
							$this->image_control($image_url, $choice);
						}
						if ($this->customizer_repeater_icon_control == true) {
							$this->icon_picker_control($icon_value, $choice);
						}

						if ($this->customizer_repeater_svg_control == true) { // ADDED
							$this->svg_control($svg_code, $choice);
						}


						if ($this->customizer_repeater_color_control == true) {
							$this->input_control(array(
								'label' => apply_filters('pawfect_repeater_input_labels_filter', esc_html__('Color', 'pawfect'), $this->id, 'customizer_repeater_color_control'),
								'class' => 'customizer-repeater-color-control',
								'type' => apply_filters('pawfect_repeater_input_types_filter', 'color', $this->id, 'customizer_repeater_color_control'),
								'sanitize_callback' => 'sanitize_hex_color'
							), $color);
						}


						if ($this->customizer_repeater_shortcode_control == true) {
							$this->input_control(array(
								'label' => apply_filters('pawfect_repeater_input_labels_filter', esc_html__('Width', 'pawfect'), $this->id, 'customizer_repeater_shortcode_control'),
								'class' => 'customizer-repeater-shortcode-control',
								'type' => apply_filters('pawfect_repeater_input_types_filter', '', $this->id, 'customizer_repeater_shortcode_control'),
								'description' => esc_html__(' e.g., 200px, 50%, 2rem, 15vw', 'pawfect'),
							), $shortcode);
						}



						if ($this->customizer_repeater_text_two_control == true) {
							$this->input_control(array(
								'label' => apply_filters('pawfect_repeater_input_labels_filter', esc_html__('Top Offset', 'pawfect'), $this->id, 'customizer_repeater_text_two_control'),
								'class' => 'customizer-repeater-text-two-control',
								'type' => apply_filters('pawfect_repeater_input_types_filter', '', $this->id, 'customizer_repeater_text_two_control'),
								//'description' => esc_html__('e.g. 10%, 1.5rem, 50px', 'pawfect'),
							), $text_two);
						}

						if ($this->customizer_repeater_text_three_control == true) {
							$this->input_control(array(
								'label' => apply_filters('pawfect_repeater_input_labels_filter', esc_html__('Left Offset', 'pawfect'), $this->id, 'customizer_repeater_text_three_control'),
								'class' => 'customizer-repeater-text-three-control',
								'type' => apply_filters('pawfect_repeater_input_types_filter', '', $this->id, 'customizer_repeater_text_three_control'),
								//'description' => esc_html__('e.g. 25%, -10px, 2rem', 'pawfect'),
							), $text_three);
						}

						if ($this->customizer_repeater_position_select_control == true) {
							$this->select_control(array(
								'label' => esc_html__('Position Preset', 'pawfect'),
								'class' => 'customizer-repeater-position-select-control',
								'choices' => array(
									'' => __('Custom', 'pawfect'),
									'top-left' => __('Top Left', 'pawfect'),
									'top-center' => __('Top Center', 'pawfect'),
									'top-right' => __('Top Right', 'pawfect'),
									'center-left' => __('Center Left', 'pawfect'),
									'center' => __('Center', 'pawfect'),
									'center-right' => __('Center Right', 'pawfect'),
									'bottom-left' => __('Bottom Left', 'pawfect'),
									'bottom-center' => __('Bottom Center', 'pawfect'),
									'bottom-right' => __('Bottom Right', 'pawfect'),
								),
							), $position_preset);
						}
						if ($this->customizer_repeater_position_draggable_control === true): ?>
							<div class="customizer-repeater-drag-position-control">
								<span class="customize-control-title">
									<?php esc_html_e('Drag Image Position', 'pawfect'); ?>
								</span>
								<input type="hidden" class="social-repeater-box-id" value="<?php echo esc_attr($item_id); ?>">


								<div class="pawfect-draggable-wrapper" data-index="<?php echo esc_attr($item_id); ?>" style="
										position: relative;
										width: 100%;
										height: 250px;
										background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
										border: 2px dashed #cbd5e1;
										border-radius: 12px;
										margin: 15px 0;
										overflow: hidden;
										box-shadow: inset 0 2px 4px rgba(0,0,0,0.06);
										transition: all 0.3s ease;
									">
									<div class="pawfect-draggable-instructions" style="
											position: absolute;
											top: 50%;
											left: 50%;
											transform: translate(-50%, -50%);
											text-align: center;
											color: #64748b;
											font-size: 13px;
											pointer-events: none;
											z-index: 1;
										">
										<span style="display: block; margin-bottom: 5px;">📍</span>
										<?php esc_html_e('Drag the blue dot to position your image', 'pawfect'); ?>
									</div>

									<div class="pawfect-draggable-dot" style="
											width: 32px;
											height: 32px;
											background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
											border: 3px solid #ffffff;
											box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4), 0 2px 4px rgba(0,0,0,0.1);
											position: absolute;
											border-radius: 50%;
											cursor: grab;
											transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
											z-index: 10;
											display: flex;
											align-items: center;
											justify-content: center;
										" title="<?php esc_attr_e('Drag to reposition image', 'pawfect'); ?>"
										data-top="<?php echo esc_attr($text_two); ?>" 
										data-left="<?php echo esc_attr($text_three); ?>">
										<span style="
												color: white;
												font-size: 14px;
												font-weight: bold;
												text-shadow: 0 1px 2px rgba(0,0,0,0.3);
											">⌖</span>
									</div>
								</div>
							</div>
						<?php endif;



						if ($this->customizer_repeater_designation_control == true) {
							$this->input_control(array(
								'label' => apply_filters('pawfect_repeater_input_labels_filter', esc_html__('Designation', 'pawfect'), $this->id, 'customizer_repeater_designation_control'),
								'class' => 'customizer-repeater-designation-control',
								'type' => apply_filters('pawfect_repeater_input_types_filter', 'textarea', $this->id, 'customizer_repeater_designation_control'),
							), $designation);
						}


						if ($this->customizer_repeater_product_select_control === true): ?>
							<span class="customize-control-title"><?php esc_html_e('Related Product', 'pawfect'); ?></span>
							<select class="customizer-repeater-product-select widefat">
								<option value=""><?php esc_html_e('Select a product', 'pawfect'); ?></option>
								<?php
								$products = pawfect_get_woocommerce_products();
								foreach ($products as $id => $label):
									?>
									<option value="<?php echo esc_attr($id); ?>" <?php selected($product_select, $id); ?>>
										<?php echo esc_html($label); ?>
									</option>
								<?php endforeach; ?>
							</select>
						<?php endif;


						if ($this->customizer_repeater_repeater_control == true) {
							$this->repeater_control($repeater);
						} ?>

						<input type="hidden" class="social-repeater-box-id" value="<?php if (!empty($id)) {
							echo esc_attr($id);
						} ?>">
						<button type="button" class="social-repeater-general-control-remove-field" <?php if ($it == 0) {
							echo 'style="display:none;"';
						} ?>>
							<?php esc_html_e('Delete field', 'pawfect'); ?>
						</button>

					</div>
				</div>

				<?php
				$it++;
			}
		} else { ?>
			<div class="customizer-repeater-general-control-repeater-container">
				<div class="customizer-repeater-customize-control-title">
					<?php echo esc_html($this->boxtitle) ?>
				</div>
				<div class="customizer-repeater-box-content-hidden">
					<?php
					// Initialize variables to prevent undefined variable warnings
					$choice = $image_url = $icon_value = $svg_code = $title = $subtitle = $text = $slide_format = $content_format = $rating_control = $link = $designation = $button = $open_new_tab = $shortcode = $text_two = $text_three = $item_id = $position_preset = $repeater = $color = $video_url = '';
					$item_id = 'customizer-repeater-' . uniqid();
					
					if ($this->customizer_repeater_image_control == true && $this->customizer_repeater_icon_control == true) {
						$this->icon_type_choice();
					}
					if ($this->customizer_repeater_image_control == true) {
						$this->image_control();
					}
					if ($this->customizer_repeater_icon_control == true) {
						$this->icon_picker_control();
					}

					if ($this->customizer_repeater_svg_control == true) { // ADDED
						$this->svg_control();
					}

					if ($this->customizer_repeater_color_control == true) {
						$this->input_control(array(
							'label' => apply_filters('pawfect_repeater_input_labels_filter', esc_html__('Color', 'pawfect'), $this->id, 'customizer_repeater_color_control'),
							'class' => 'customizer-repeater-color-control',
							'type' => apply_filters('pawfect_repeater_input_types_filter', 'color', $this->id, 'customizer_repeater_color_control'),
							'sanitize_callback' => 'sanitize_hex_color'
						));
					}
					if ($this->customizer_repeater_title_control == true) {
						$this->input_control(array(
							'label' => apply_filters('pawfect_repeater_input_labels_filter', esc_html__('Title', 'pawfect'), $this->id, 'customizer_repeater_title_control'),
							'class' => 'customizer-repeater-title-control',
							'type' => apply_filters('pawfect_repeater_input_types_filter', '', $this->id, 'customizer_repeater_title_control'),
						));
					}
					if ($this->customizer_repeater_subtitle_control == true) {
						$this->input_control(array(
							'label' => apply_filters('pawfect_repeater_input_labels_filter', esc_html__('Subtitle', 'pawfect'), $this->id, 'customizer_repeater_subtitle_control'),
							'class' => 'customizer-repeater-subtitle-control',
							'type' => apply_filters('pawfect_repeater_input_types_filter', '', $this->id, 'customizer_repeater_subtitle_control'),
						));
					}
					if ($this->customizer_repeater_text_control == true) {
						$this->input_control(array(
							'label' => apply_filters('pawfect_repeater_input_labels_filter', esc_html__('Description', 'pawfect'), $this->id, 'customizer_repeater_text_control'),
							'class' => 'customizer-repeater-text-control',
							'type' => apply_filters('pawfect_repeater_input_types_filter', 'textarea', $this->id, 'customizer_repeater_text_control'),
						));
					}

					if ($this->customizer_repeater_button_text_control) {
						$this->input_control(array(
							'label' => apply_filters('pawfect_repeater_input_labels_filter', esc_html__(
								'Button Text',
								'pawfect'
							), $this->id, 'customizer_repeater_button_text_control'),
							'class' => 'customizer-repeater-button-text-control',
							'type' => apply_filters(
								'pawfect_repeater_input_types_filter',
								'',
								$this->id,
								'customizer_repeater_button_text_control'
							),
						));
					}

					if ($this->customizer_repeater_link_control == true) {
						$this->input_control(array(
							'label' => apply_filters('pawfect_repeater_input_labels_filter', esc_html__('Link', 'pawfect'), $this->id, 'customizer_repeater_link_control'),
							'class' => 'customizer-repeater-link-control',
							'type' => apply_filters('pawfect_repeater_input_types_filter', '', $this->id, 'customizer_repeater_link_control'),
						));
					}

					if ($this->customizer_repeater_checkbox_control == true) {
						$this->testimonila_check($open_new_tab);

					}

					if ($this->customizer_repeater_slide_content_format_type == true) {
						$this->content_format($content_format);

					}

					if ($this->customizer_repeater_slide_format == true) {
						$this->slide_format($slide_format);

					}

					if ($this->customizer_repeater_rating_control == true) {
						$this->rating_control($rating_control);

					}

					if ($this->customizer_repeater_video_url_control) {
						$this->input_control(array(
							'label' => apply_filters('pawfect_repeater_input_labels_filter', esc_html__(
								'Video Url',
								'pawfect'
							), $this->id, 'customizer_repeater_video_url_control'),
							'class' => 'customizer-repeater-video-url-control',
							'type' => apply_filters('customizer_repeater_video_url_control', 'textarea', $this->id, 'customizer_repeater_video_url_control'),
						));
					}

					if ($this->customizer_repeater_shortcode_control == true) {
						$this->input_control(array(
							'label' => apply_filters('pawfect_repeater_input_labels_filter', esc_html__('Width', 'pawfect'), $this->id, 'customizer_repeater_shortcode_control'),
							'class' => 'customizer-repeater-shortcode-control',
							'type' => apply_filters('pawfect_repeater_input_types_filter', '', $this->id, 'customizer_repeater_shortcode_control'),
							//'description' => esc_html__('Accepted units: px, %, rem, vw (e.g., 200px, 50%, 2rem, 15vw)', 'pawfect'),
						));
					}

					if ($this->customizer_repeater_text_two_control == true) {
						$this->input_control(array(
							'label' => apply_filters('pawfect_repeater_input_labels_filter', esc_html__('Shortcode', 'pawfect'), $this->id, 'customizer_repeater_text_two_control'),
							'class' => 'customizer-repeater-text-two-control',
							'type' => apply_filters('pawfect_repeater_input_types_filter', '', $this->id, 'customizer_repeater_text_two_control'),
						));
					}

					if ($this->customizer_repeater_text_three_control == true) {
						$this->input_control(array(
							'label' => apply_filters('pawfect_repeater_input_labels_filter', esc_html__('Shortcode', 'pawfect'), $this->id, 'customizer_repeater_text_three_control '),
							'class' => 'customizer-repeater-text-three-control',
							'type' => apply_filters('pawfect_repeater_input_types_filter', '', $this->id, 'customizer_repeater_text_three_control '),
						));
					}

					if ($this->customizer_repeater_position_select_control == true) {
						$this->select_control(array(
							'label' => esc_html__('Position Preset', 'pawfect'),
							'class' => 'customizer-repeater-position-select-control',
							'choices' => array(
								'' => __('Custom', 'pawfect'),
								'top-left' => __('Top Left', 'pawfect'),
								'top-center' => __('Top Center', 'pawfect'),
								'top-right' => __('Top Right', 'pawfect'),
								'center-left' => __('Center Left', 'pawfect'),
								'center' => __('Center', 'pawfect'),
								'center-right' => __('Center Right', 'pawfect'),
								'bottom-left' => __('Bottom Left', 'pawfect'),
								'bottom-center' => __('Bottom Center', 'pawfect'),
								'bottom-right' => __('Bottom Right', 'pawfect'),
							),
						));
					}


					if ($this->customizer_repeater_position_draggable_control === true): ?>
						<div class="customizer-repeater-drag-position-control">
								<span class="customize-control-title">
									<?php esc_html_e('Drag Image Position', 'pawfect'); ?>
								</span>
								<input type="hidden" class="social-repeater-box-id" value="<?php echo esc_attr($item_id); ?>">


								<div class="pawfect-draggable-wrapper" data-index="<?php echo esc_attr($item_id); ?>" style="
										position: relative;
										width: 100%;
										height: 250px;
										background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
										border: 2px dashed #cbd5e1;
										border-radius: 12px;
										margin: 15px 0;
										overflow: hidden;
										box-shadow: inset 0 2px 4px rgba(0,0,0,0.06);
										transition: all 0.3s ease;
									">
									<div class="pawfect-draggable-instructions" style="
											position: absolute;
											top: 50%;
											left: 50%;
											transform: translate(-50%, -50%);
											text-align: center;
											color: #64748b;
											font-size: 13px;
											pointer-events: none;
											z-index: 1;
										">
										<span style="display: block; margin-bottom: 5px;">📍</span>
										<?php esc_html_e('Drag the blue dot to position your image', 'pawfect'); ?>
									</div>

									<div class="pawfect-draggable-dot" style="
											width: 32px;
											height: 32px;
											background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
											border: 3px solid #ffffff;
											box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4), 0 2px 4px rgba(0,0,0,0.1);
											position: absolute;
											border-radius: 50%;
											cursor: grab;
											transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
											z-index: 10;
											display: flex;
											align-items: center;
											justify-content: center;
										" title="<?php esc_attr_e('Drag to reposition image', 'pawfect'); ?>"
										data-top="<?php echo esc_attr($text_two); ?>" 
										data-left="<?php echo esc_attr($text_three); ?>">
										<span style="
												color: white;
												font-size: 14px;
												font-weight: bold;
												text-shadow: 0 1px 2px rgba(0,0,0,0.3);
											">⌖</span>
									</div>
								</div>
							</div>
					<?php endif;







					if ($this->customizer_repeater_designation_control == true) {
						$this->input_control(array(
							'label' => apply_filters('pawfect_repeater_input_labels_filter', esc_html__('Designation', 'pawfect'), $this->id, 'customizer_repeater_designation_control'),
							'class' => 'customizer-repeater-designation-control',
							'type' => apply_filters('pawfect_repeater_input_types_filter', 'textarea', $this->id, 'customizer_repeater_designation_control'),
						));
					}

					if ($this->customizer_repeater_repeater_control == true) {
						$this->repeater_control();
					} ?>
					<input type="hidden" class="social-repeater-box-id" value="<?php echo esc_attr($item_id); ?>">
					<button type="button" class="social-repeater-general-control-remove-field button" style="display:none;">
						<?php esc_html_e('Delete field', 'pawfect'); ?>
					</button>
				</div>
			</div>
			<?php
		}
	}

	private function input_control($options, $value = '')
	{
		//print_r($options);
		?>
		<span class="customize-control-title <?php echo esc_html($options['label']); ?>" <?php if ($options['class'] == 'customizer-repeater-video-url-control') {
			   echo 'style="display:none;"';
		   } ?>><?php echo esc_html($options['label']); ?></span>
		<?php if (!empty($options['description'])): ?>
			<span class="description customize-control-description"><?php echo esc_html($options['description']); ?></span>
		<?php endif; ?>
		<?php
		if (!empty($options['type'])) {
			switch ($options['type']) {
				case 'textarea': ?>
					<textarea class="<?php echo esc_attr($options['class']); ?>"
						placeholder="<?php echo esc_attr($options['label']); ?>"><?php echo (!empty($options['sanitize_callback']) ? call_user_func_array($options['sanitize_callback'], array($value)) : esc_attr($value)); ?></textarea>
					<?php
					break;
				case 'color': ?>
					<input type="text"
						value="<?php echo (!empty($options['sanitize_callback']) ? call_user_func_array($options['sanitize_callback'], array($value)) : esc_attr($value)); ?>"
						class="<?php echo esc_attr($options['class']); ?>" />
					<?php
					break;
			}
		} else { ?>
			<input type="text"
				value="<?php echo (!empty($options['sanitize_callback']) ? call_user_func_array($options['sanitize_callback'], array($value)) : esc_attr($value)); ?>"
				class="<?php echo esc_attr($options['class']); ?>" placeholder="<?php echo esc_attr($options['label']); ?>" />
			<?php
		}
	}


	private function select_control($options, $value = '')
	{
		?>
		<span class="customize-control-title"><?php echo esc_html($options['label']); ?></span>
		<select class="<?php echo esc_attr($options['class']); ?>">
			<?php foreach ($options['choices'] as $key => $label): ?>
				<option value="<?php echo esc_attr($key); ?>" <?php selected($value, $key); ?>>
					<?php echo esc_html($label); ?>
				</option>
			<?php endforeach; ?>
		</select>
		<?php
	}


	private function testimonila_check($value = 'no')
	{
		?>
		<span class="customize-control-title">
			<?php esc_html_e('Open link in new tab', 'pawfect'); ?>
		</span>
		<select class="customizer-repeater-checkbox">
			<option value="no" <?php selected($value, 'no'); ?>>
				<?php esc_html_e('No', 'pawfect') ?>
			</option>
			<option value="yes" <?php selected($value, 'yes'); ?>>
				<?php esc_html_e('Yes', 'pawfect') ?>
			</option>
		</select>
		<?php
	}

	private function svg_control($value = '', $show = '')
	{ ?>
		<div class="customizer-repeater-svg-control" <?php if ($show !== 'customizer_repeater_svg') {
			echo 'style="display:none;"';
		} ?>>
			<span class="customize-control-title">
				<?php esc_html_e('SVG Code', 'pawfect') ?>
			</span>
			<span class="description customize-control-description">
				<?php esc_html_e('Paste your full SVG code here.', 'pawfect'); ?>
			</span>
			<textarea class="widefat customizer-repeater-svg-code"><?php echo esc_textarea($value); ?></textarea>
		</div>
		<?php
	}

	private function icon_picker_control($value = '', $show = '')
	{
		// If only icon control is enabled (no image control), always show the icon picker
		$should_show = true;
		if ($this->customizer_repeater_image_control == true) {
			// Only hide if image control is enabled and show parameter indicates to hide
			$should_show = !($show === 'customizer_repeater_image' || $show === 'customizer_repeater_none');
		}
		?>
		<div class="social-repeater-general-control-icon" <?php if (!$should_show) {
			echo 'style="display:none;"';
		} ?>>
			<span class="customize-control-title">
				<?php esc_html_e('Icon', 'pawfect'); ?>
			</span>
			<span class="description customize-control-description">
				<?php
				echo sprintf(
					/* translators: %1$s: icon */
					esc_html__('Note: Some icons may not be displayed here. You can see the full list of icons at %1$s.', 'pawfect'),
					sprintf('<a href="//fontawesome.io/icons/" rel="nofollow">%s</a>', esc_html__('//fontawesome.io/icons/', 'pawfect'))
				); ?>
			</span>
			<div class="input-group icp-container">
				<input data-placement="bottomRight" class="icp icp-auto" value="<?php if (!empty($value)) {
					echo esc_attr($value);
				} ?>" type="text">
				<span class="input-group-addon">
					<i class="fa <?php echo esc_attr($value); ?>"></i>
				</span>
			</div>
			<?php get_template_part($this->customizer_icon_container); ?>
		</div>
		<?php
	}

	private function image_control($value = '', $show = '')
	{ ?>
		<div class="customizer-repeater-image-control" <?php if ($show === 'customizer_repeater_icon' || $show === 'customizer_repeater_none') {
			echo 'style="display:none;"';
		} ?>>
			<span class="customize-control-title">
				<?php esc_html_e('Image', 'pawfect') ?>
			</span>

			<!-- Enhanced Image Preview -->
			<div class="customizer-repeater-image-preview" style="margin-bottom: 10px;">
				<?php if (!empty($value)) : ?>
					<img src="<?php echo esc_url($value); ?>"
						 alt="<?php esc_attr_e('Preview', 'pawfect'); ?>"
						 style="max-width: 100%; height: 60px; object-fit: cover; border-radius: 4px; border: 1px solid #ddd; display: block;" />
					<button type="button" class="button button-link customizer-repeater-remove-image"
							style="color: #dc3232; text-decoration: none; font-size: 12px; margin-top: 5px;">
						<?php esc_html_e('Remove Image', 'pawfect'); ?>
					</button>
				<?php else : ?>
					<div class="customizer-repeater-image-placeholder"
						 style="width: 100%; height: 60px; background: #f7f7f7; border: 2px dashed #ddd; border-radius: 4px; display: flex; align-items: center; justify-content: center; color: #666; font-size: 12px;">
						<?php esc_html_e('No image selected', 'pawfect'); ?>
					</div>
				<?php endif; ?>
			</div>

			<input type="text" class="widefat custom-media-url" value="<?php echo esc_attr($value); ?>" style="margin-bottom: 8px;">
			<input type="button" class="button button-secondary customizer-repeater-custom-media-button"
				value="<?php esc_attr_e('Upload Image', 'pawfect'); ?>" />
		</div>
		<?php
	}


	private function content_format($value = 'center')
	{ ?>

		<span class="customize-control-title">
			<?php esc_html_e('Slide Content Format', 'pawfect'); ?>
		</span>
		<select class="customizer-repeater-slide-content-format">
			<option value="left" <?php selected($value, 'left'); ?>>
				<?php esc_html_e('Left', 'pawfect') ?>
			</option>

			<option value="right" <?php selected($value, 'right'); ?>>
				<?php esc_html_e('Right', 'pawfect') ?>
			</option>

			<option value="center" <?php selected($value, 'center'); ?>>
				<?php esc_html_e('Center', 'pawfect') ?>
			</option>

		</select>

		<?php
	}

	/*	Note: Enable in Future  Note Note Note Note */
	private function slide_format($value = 'customizer_repeater_slide_format_standard')
	{ ?>
		<span class="customize-control-title">
			<?php esc_html_e('Slide Content Type', 'pawfect'); ?>
		</span>
		<select class="customizer-repeater-slide-format">
			<option value="customizer_repeater_slide_format_standard" <?php selected($value, 'customizer_repeater_slide_format_standard'); ?>>
				<?php esc_html_e('Standard', 'pawfect') ?>
			</option>

			<!--<option value="customizer_repeater_slide_format_aside" <?php selected($value, 'customizer_repeater_slide_format_aside'); ?>>
			<?php esc_html_e('Aside', 'pawfect') ?>
			</option>
			
			<option value="customizer_repeater_slide_format_quote" <?php selected($value, 'customizer_repeater_slide_format_quote'); ?>>
			<?php esc_html_e('Quote', 'pawfect') ?>
			</option>
			
			<option value="customizer_repeater_slide_format_status" <?php selected($value, 'customizer_repeater_slide_format_status'); ?>>
			<?php esc_html_e('Status', 'pawfect') ?>
			</option>-->

			<option value="customizer_repeater_slide_format_video" <?php selected($value, 'customizer_repeater_slide_format_video'); ?>>
				<?php esc_html_e('Video', 'pawfect') ?>
			</option>

		</select>
		<?php
	}

	private function rating_control($value = 'customizer_repeater_rating_control_five')
	{ ?>

		<span class="customize-control-title">
			<?php esc_html_e('User Rating', 'pawfect'); ?>
		</span>
		<select class="customizer-repeater-rating-control">
			<option value="customizer_repeater_rating_control_one" <?php selected($value, 'customizer_repeater_rating_control_one'); ?>>
				<?php esc_html_e('1', 'pawfect') ?>
			</option>

			<option value="customizer_repeater_rating_control_two" <?php selected($value, 'customizer_repeater_rating_control_two'); ?>>
				<?php esc_html_e('2', 'pawfect') ?>
			</option>

			<option value="customizer_repeater_rating_control_three" <?php selected($value, 'customizer_repeater_rating_control_three'); ?>>
				<?php esc_html_e('3', 'pawfect') ?>
			</option>

			<option value="customizer_repeater_rating_control_four" <?php selected($value, 'customizer_repeater_rating_control_four'); ?>>
				<?php esc_html_e('4', 'pawfect') ?>
			</option>

			<option value="customizer_repeater_rating_control_five" <?php selected($value, 'customizer_repeater_rating_control_five'); ?>>
				<?php esc_html_e('5', 'pawfect') ?>
			</option>

		</select>
		<?php
	}

	private function icon_type_choice($value = 'customizer_repeater_icon')
	{ ?>
		<span class="customize-control-title">
			<?php esc_html_e('Image type', 'pawfect'); ?>
		</span>
		<select class="customizer-repeater-image-choice">
			<option value="customizer_repeater_icon" <?php selected($value, 'customizer_repeater_icon'); ?>>
				<?php esc_html_e('Icon', 'pawfect'); ?>
			</option>
			<option value="customizer_repeater_image" <?php selected($value, 'customizer_repeater_image'); ?>>
				<?php esc_html_e('Image', 'pawfect'); ?>
			</option>
			<option value="customizer_repeater_svg" <?php selected($value, 'customizer_repeater_svg'); ?>>
				<?php esc_html_e('SVG', 'pawfect'); ?>
			</option>
			<option value="customizer_repeater_none" <?php selected($value, 'customizer_repeater_none'); ?>>
				<?php esc_html_e('None', 'pawfect'); ?>
			</option>
		</select>
		<?php
	}

	private function repeater_control($value = '')
	{
		$social_repeater = array();
		$show_del = 0; ?>
		<span class="customize-control-title"><?php esc_html_e('Social icons', 'pawfect'); ?></span>
		<?php
		if (!empty($value)) {
			$social_repeater = json_decode(html_entity_decode($value), true);
		}
		if ((count($social_repeater) == 1 && '' === $social_repeater[0]) || empty($social_repeater)) { ?>
			<div class="customizer-repeater-social-repeater">
				<div class="customizer-repeater-social-repeater-container">
					<div class="customizer-repeater-rc input-group icp-container">
						<input data-placement="bottomRight" class="icp icp-auto" value="<?php if (!empty($value)) {
							echo esc_attr($value);
						} ?>" type="text">
						<span class="input-group-addon"></span>
					</div>
					<?php get_template_part($this->customizer_icon_container); ?>
					<input type="text" class="customizer-repeater-social-repeater-link"
						placeholder="<?php esc_attr_e('Link', 'pawfect'); ?>">
					<input type="hidden" class="customizer-repeater-social-repeater-id" value="">
					<button class="social-repeater-remove-social-item" style="display:none">
						<?php esc_html_e('Remove Icon', 'pawfect'); ?>
					</button>
				</div>
				<input type="hidden" id="social-repeater-socials-repeater-colector"
					class="social-repeater-socials-repeater-colector" value="" />
			</div>
			<button class="social-repeater-add-social-item button-secondary"><?php esc_html_e('Add Icon', 'pawfect'); ?></button>
			<?php
		} else { ?>
			<div class="customizer-repeater-social-repeater">
				<?php
				foreach ($social_repeater as $social_icon) {
					$show_del++; ?>
					<div class="customizer-repeater-social-repeater-container">
						<div class="customizer-repeater-rc input-group icp-container">
							<input data-placement="bottomRight" class="icp icp-auto" value="<?php if (!empty($social_icon['icon'])) {
								echo esc_attr($social_icon['icon']);
							} ?>" type="text">
							<span class="input-group-addon"><i class="fa <?php echo esc_attr($social_icon['icon']); ?>"></i></span>
						</div>
						<?php get_template_part($this->customizer_icon_container); ?>
						<input type="text" class="customizer-repeater-social-repeater-link"
							placeholder="<?php esc_attr_e('Link', 'pawfect'); ?>" value="<?php if (!empty($social_icon['link'])) {
								   echo esc_url($social_icon['link']);
							   } ?>">
						<input type="hidden" class="customizer-repeater-social-repeater-id" value="<?php if (!empty($social_icon['id'])) {
							echo esc_attr($social_icon['id']);
						} ?>">
						<button class="social-repeater-remove-social-item" style="<?php if ($show_del == 1) {
							echo "display:none";
						} ?>"><?php esc_html_e('Remove Icon', 'pawfect'); ?></button>
					</div>
					<?php
				} ?>
				<input type="hidden" id="social-repeater-socials-repeater-colector"
					class="social-repeater-socials-repeater-colector"
					value="<?php echo esc_textarea(html_entity_decode($value)); ?>" />
			</div>
			<button class="social-repeater-add-social-item button-secondary"><?php esc_html_e('Add Icon', 'pawfect'); ?></button>
			<?php
		}
	}
}
