<?php
namespace Sifency\Traits;

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

use Elementor\Controls_Manager;
use Elementor\Group_Control_Background;
use Elementor\Group_Control_Border;
use Elementor\Group_Control_Box_Shadow;
use Elementor\Group_Control_Image_Size;
use Elementor\Group_Control_Typography;
use Elementor\Group_Control_Css_Filter;
use Sifency\Traits\Sifency_Addons_Flex_Controls;

trait Sifency_Addons_Marquee_Controls {
	use Sifency_Addons_Flex_Controls;

	protected function add_Sifency_Addons_Marquee_Controls( $args = array() ) {
		$this->start_controls_section(
			'content_section',
			array(
				'label' => esc_html__( 'Content', 'sifency-addons' ),
				'tab'   => Controls_Manager::TAB_CONTENT,
			)
		);
		$repeater = new \Elementor\Repeater();
		$repeater->add_control(
			'item_image',
			array(
				'label' => esc_html__( 'Image', 'sifency-addons' ),
				'type'  => Controls_Manager::MEDIA,
			)
		);
		$repeater->add_group_control(
			Group_Control_Image_Size::get_type(),
			array(
				'name'    => 'item_image',
				'default' => 'thumbnail',
			)
		);
		$repeater->add_control(
			'text',
			array(
				'label'   => esc_html__( 'Text', 'sifency-addons' ),
				'type'    => Controls_Manager::TEXTAREA,
				'default' => esc_html__( 'Default Text', 'sifency-addons' ),
			)
		);
		$repeater->add_control(
			'item_link',
			array(
				'label'         => esc_html__( 'Link', 'sifency-addons' ),
				'type'          => Controls_Manager::URL,
				'placeholder'   => esc_html__( 'https://your-link.com', 'sifency-addons' ),
				'show_external' => true,
				'default'       => array(
					'url'         => '',
					'is_external' => false,
					'nofollow'    => false,
				),
			)
		);
		$this->add_control(
			'text_list',
			array(
				'label'       => esc_html__( 'Text Items', 'sifency-addons' ),
				'type'        => Controls_Manager::REPEATER,
				'fields'      => $repeater->get_controls(),
				'default'     => array(
					array(
						'text' => esc_html__( 'Default Text 1', 'sifency-addons' ),
					),
					array(
						'text' => esc_html__( 'Default Text 2', 'sifency-addons' ),
					),
				),
				'title_field' => '{{{ text }}}',
			)
		);
		$this->add_control(
			'slider_direction',
			array(
				'label'     => esc_html__( 'Slider Direction', 'sifency-addons' ),
				'type'      => Controls_Manager::SELECT,
				'default'   => 'left',
				'options'   => array(
					'left'   => esc_html__( 'Right to Left', 'sifency-addons' ),
					'right'  => esc_html__( 'Left to Right', 'sifency-addons' ),
					'top'    => esc_html__( 'Bottom to Top', 'sifency-addons' ),
					'bottom' => esc_html__( 'Top to Bottom', 'sifency-addons' ),
				),
				'separator' => 'before',
			)
		);
		$this->add_control(
			'pause_on_hover',
			array(
				'label'        => esc_html__( 'Pause on Hover', 'sifency-addons' ),
				'type'         => Controls_Manager::SWITCHER,
				'label_on'     => esc_html__( 'Yes', 'sifency-addons' ),
				'label_off'    => esc_html__( 'No', 'sifency-addons' ),
				'return_value' => 'yes',
				'default'      => 'yes',
			)
		);
		$this->add_control(
			'loop_count',
			array(
				'label'       => esc_html__( 'Loop Count', 'sifency-addons' ),
				'type'        => Controls_Manager::NUMBER,
				'min'         => 0,
				'max'         => 100,
				'step'        => 1,
				'default'     => 0,
				'description' => esc_html__( '0 for infinite loops', 'sifency-addons' ),
			)
		);
		$this->add_control(
			'separator_type',
			array(
				'label'   => esc_html__( 'Separator Type', 'sifency-addons' ),
				'type'    => Controls_Manager::SELECT,
				'default' => 'icon',
				'options' => array(
					'none'  => esc_html__( 'None', 'sifency-addons' ),
					'icon'  => esc_html__( 'Icon', 'sifency-addons' ),
					'text'  => esc_html__( 'Text', 'sifency-addons' ),
					'image' => esc_html__( 'Image', 'sifency-addons' ),
				),
			)
		);
		$this->add_control(
			'separator_text',
			array(
				'label'     => esc_html__( 'Separator Text', 'sifency-addons' ),
				'type'      => Controls_Manager::TEXT,
				'default'   => '•',
				'condition' => array(
					'separator_type' => 'text',
				),
			)
		);
		$this->add_control(
			'separator_icon',
			array(
				'label'     => esc_html__( 'Separator Icon', 'sifency-addons' ),
				'type'      => Controls_Manager::ICONS,
				'default'   => array(
					'value'   => 'fas fa-star',
					'library' => 'solid',
				),
				'condition' => array(
					'separator_type' => 'icon',
				),
			)
		);
		$this->add_control(
			'separator_image',
			array(
				'label'     => esc_html__( 'Separator Image', 'sifency-addons' ),
				'type'      => Controls_Manager::MEDIA,
				'condition' => array(
					'separator_type' => 'image',
				),
			)
		);
		$this->add_control(
			'separator_spacing',
			array(
				'label'      => esc_html__( 'Separator Spacing', 'sifency-addons' ),
				'type'       => Controls_Manager::SLIDER,
				'size_units' => array( 'px', 'em' ),
				'range'      => array(
					'px' => array(
						'min'  => 0,
						'max'  => 100,
						'step' => 1,
					),
					'em' => array(
						'min'  => 0,
						'max'  => 10,
						'step' => 0.1,
					),
				),
				'default'    => array(
					'unit' => 'px',
					'size' => 20,
				),
				'selectors'  => array(
					'{{WRAPPER}} .marquee-separator' => 'margin-left: {{SIZE}}{{UNIT}}; margin-right: {{SIZE}}{{UNIT}};',
				),
				'conditions' => array(
					'relation' => 'or',
					'terms'    => array(
						array(
							'name'     => 'separator_type',
							'operator' => '==',
							'value'    => 'icon',
						),
						array(
							'name'     => 'separator_type',
							'operator' => '==',
							'value'    => 'text',
						),
						array(
							'name'     => 'separator_type',
							'operator' => '==',
							'value'    => 'image',
						),
					),
				),
			)
		);
		$this->add_control(
			'speed',
			array(
				'label'   => esc_html__( 'Animation Speed (Seconds)', 'sifency-addons' ),
				'type'    => Controls_Manager::SLIDER,
				'range'   => array(
					'px' => array(
						'min'  => 1,
						'max'  => 100,
						'step' => 1,
					),
				),
				'default' => array(
					'size' => 20,
					'unit' => 'px',
				),
			)
		);
		$this->add_sifency_addons_flex_alignment_controls(
			array(
				'label'    => esc_html__( 'Content Flexbox', 'sifency-addons' ),
				'selector' => '.sifency-addons-marquee-content',
			)
		);
		$this->end_controls_section();
	}
}
