<?php
namespace Sifency\Traits;
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
use Elementor\Widget_Base;
use Elementor\Controls_Manager;
use Elementor\Repeater;
use Elementor\Utils;
use Elementor\Group_Control_Typography;
use Elementor\Group_Control_Background;
use Elementor\Group_Control_Border;
use Elementor\Group_Control_Box_Shadow;

trait Sifency_Testimonial_Controls {
	protected function add_sifency_testimonial_controls( $args = [] ) {
		$this->start_controls_section( 'section_content_source', [ 'label' => esc_html__('Source & Content', 'sifency-addons') ] );
		$this->add_control(
			'source',
			[
				'label'   => esc_html__('Content Source', 'sifency-addons'),
				'type'    => Controls_Manager::SELECT,
				'options' => [
					'custom'    => esc_html__('Custom Content', 'sifency-addons'),
					'post_type' => esc_html__('Custom Post Type', 'sifency-addons'),
				],
				'default' => 'custom',
			]
		);

        $this->update_control('query_post_type', ['default' => 'testimonial']);
        $this->update_control('section_query', [ 'condition' => [ 'source' => 'post_type' ] ]);

		$repeater = new Repeater();
		$repeater->add_control( 'name', [ 'label' => esc_html__('Name', 'sifency-addons'), 'type' => Controls_Manager::TEXT, 'default' => esc_html__('John Doe', 'sifency-addons'), 'label_block' => true ] );
		$repeater->add_control( 'content', [ 'label' => esc_html__('Content', 'sifency-addons'), 'type' => Controls_Manager::TEXTAREA, 'default' => esc_html__('An amazing service.', 'sifency-addons') ] );
		$repeater->add_control( 'image', [ 'label' => esc_html__('Image', 'sifency-addons'), 'type' => Controls_Manager::MEDIA, 'default' => [ 'url' => Utils::get_placeholder_image_src() ] ] );
		$repeater->add_control( 'position', [ 'label' => esc_html__('Position', 'sifency-addons'), 'type' => Controls_Manager::TEXT, 'default' => esc_html__('CEO', 'sifency-addons') ] );
		$repeater->add_control( 'company', [ 'label' => esc_html__('Company', 'sifency-addons'), 'type' => Controls_Manager::TEXT, 'default' => esc_html__('Sifency Corp', 'sifency-addons') ] );
		$repeater->add_control( 'rating', [ 'label' => esc_html__('Rating', 'sifency-addons'), 'type' => Controls_Manager::SELECT, 'options' => [ '0' => esc_html__('No Rating', 'sifency-addons'), '1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5' ], 'default' => '5' ] );
		$repeater->add_control( 'link', [ 'label' => esc_html__('Link', 'sifency-addons'), 'type' => Controls_Manager::URL, 'default' => [ 'url' => '#', 'is_external' => true, 'nofollow' => true ] ] );

		$this->add_control(
			'testimonials',
			[
				'label'       => esc_html__('Testimonials List', 'sifency-addons'),
				'type'        => Controls_Manager::REPEATER,
				'fields'      => $repeater->get_controls(),
				'title_field' => '{{{ name }}}',
				'default'     => [ [ 'name' => esc_html__('John Doe', 'sifency-addons') ], [ 'name' => esc_html__('Jane Smith', 'sifency-addons') ] ],
				'condition'   => [ 'source' => 'custom' ],
			]
		);
		$this->end_controls_section();

		$this->add_sifency_arg_controls();

		$this->start_controls_section( 'section_layout_settings', [ 'label' => esc_html__('Layout & Options', 'sifency-addons') ] );
		$this->add_control( 'display_type', [ 'label' => esc_html__('Layout', 'sifency-addons'), 'type' => Controls_Manager::SELECT, 'options' => [ 'grid' => esc_html__('Grid', 'sifency-addons'), 'carousel' => esc_html__('Carousel', 'sifency-addons'), ], 'default' => 'grid' ] );
        $this->add_responsive_control( 'columns', [ 
            'label' => esc_html__('Columns', 'sifency-addons'), 
            'type' => Controls_Manager::SELECT, 
            'options' => [ '1'=>'1', '2'=>'2', '3'=>'3', '4'=>'4' ], 
            'default' => '3', 'tablet_default' => '2', 'mobile_default' => '1', 
            'selectors' => [ '{{WRAPPER}} .sifency-addons-testimonials-grid' => 'display: grid; grid-template-columns: repeat({{VALUE}}, 1fr);' ], 
            'condition' => [ 'display_type' => 'grid' ] 
        ]);
		$this->add_responsive_control( 'grid_gap', [ 'label' => esc_html__('Gap', 'sifency-addons'), 'type' => Controls_Manager::SLIDER, 'default' => [ 'size' => 30 ], 'range' => [ 'px' => [ 'max' => 100 ] ], 'selectors' => [ '{{WRAPPER}} .sifency-addons-testimonials-grid' => 'gap: {{SIZE}}{{UNIT}};' ], 'condition' => [ 'display_type' => 'grid' ] ] );
        $this->add_control( 'hr_options', [ 'type' => Controls_Manager::DIVIDER ] );
		$this->add_control( 'show_image', [ 'label' => esc_html__('Show Image', 'sifency-addons'), 'type' => Controls_Manager::SWITCHER, 'default' => 'yes', 'return_value' => 'yes' ] );
		$this->add_control( 'show_position', [ 'label' => esc_html__('Show Position', 'sifency-addons'), 'type' => Controls_Manager::SWITCHER, 'default' => 'yes', 'return_value' => 'yes' ] );
		$this->add_control( 'show_company', [ 'label' => esc_html__('Show Company', 'sifency-addons'), 'type' => Controls_Manager::SWITCHER, 'default' => 'yes', 'return_value' => 'yes' ] );
		$this->add_control( 'show_rating', [ 'label' => esc_html__('Show Rating', 'sifency-addons'), 'type' => Controls_Manager::SWITCHER, 'default' => 'yes', 'return_value' => 'yes' ] );
		$this->add_control( 'content_length', [ 'label' => esc_html__('Content Length', 'sifency-addons'), 'type' => Controls_Manager::SELECT, 'options' => [ 'full' => esc_html__('Full', 'sifency-addons'), 'excerpt' => esc_html__('Excerpt', 'sifency-addons') ], 'default' => 'full' ] );
		$this->add_control( 'excerpt_length', [ 'label' => esc_html__('Excerpt Words', 'sifency-addons'), 'type' => Controls_Manager::NUMBER, 'default' => 25, 'condition' => [ 'content_length' => 'excerpt' ] ] );
		$this->add_control( 'read_more_text', [ 'label' => esc_html__('Read More Text', 'sifency-addons'), 'type' => Controls_Manager::TEXT, 'default' => esc_html__('Read More', 'sifency-addons'), 'condition' => [ 'content_length' => 'excerpt' ] ] );
		$this->end_controls_section();

		$this->start_controls_section( 'section_style_rating', [ 'label' => esc_html__('Rating', 'sifency-addons'), 'tab' => Controls_Manager::TAB_STYLE, 'condition' => [ 'show_rating' => 'yes' ] ] );
		$this->add_control( 'rating_color', [ 'label' => esc_html__('Color', 'sifency-addons'), 'type' => Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .sifency-addons-testimonial-rating .fa-star' => 'color: {{VALUE}};' ], 'default' => '#fdd835' ] );
		$this->add_responsive_control( 'rating_size', [ 'label' => esc_html__('Size', 'sifency-addons'), 'type' => Controls_Manager::SLIDER, 'selectors' => [ '{{WRAPPER}} .sifency-addons-testimonial-rating' => 'font-size: {{SIZE}}{{UNIT}};' ] ] );
		$this->add_responsive_control( 'rating_margin', [ 'label' => esc_html__('Margin', 'sifency-addons'), 'type' => Controls_Manager::DIMENSIONS, 'size_units' => ['px', '%', 'em'], 'selectors' => [ '{{WRAPPER}} .sifency-addons-testimonial-rating' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ] ] );
		$this->end_controls_section();
	}
}