<?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;

use Sifency\Traits\Sifency_Addons_Floating_Count_Controls;

trait Sifency_Testimonial_Controls {
	use Sifency_Addons_Flex_Controls;
	use Sifency_Addons_Floating_Count_Controls;

	protected function add_sifency_testimonial_controls( $args = array() ) {
		$this->add_sifency_addons_section_header_controls();
		$this->start_controls_section( 'section_layout_type', array( 'label' => esc_html__( 'Layout Selection', 'sifency-addons' ) ) );
		$this->add_control(
			'source',
			array(
				'label'   => 'Source',
				'type'    => Controls_Manager::SELECT,
				'options' => array(
					'custom' => 'Custom',
					'posts'  => 'Posts',
				),
				'default' => 'custom',
			)
		);
		$this->add_control(
			'design_layout',
			array(
				'label'   => esc_html__( 'Design Layout', 'sifency-addons' ),
				'type'    => Controls_Manager::SELECT,
				'options' => array(
					'classic'    => esc_html__( 'Classic Card', 'sifency-addons' ),
					'bubble'     => esc_html__( 'Speech Bubble', 'sifency-addons' ),
					'horizontal' => esc_html__( 'Horizontal Side', 'sifency-addons' ),
					'overlap'    => esc_html__( 'Image Overlap', 'sifency-addons' ),
					'minimal'    => esc_html__( 'Minimal Clean', 'sifency-addons' ),
				),
				'default' => 'classic',
			)
		);
		$this->end_controls_section();

		$this->add_sifency_arg_controls(
			array(
				'default_post' => 'testimonial',
				'condition'    => array( 'source' => 'posts' ),
			)
		);

		$this->start_controls_section(
			'section_content_source',
			array(
				'label'     => esc_html__( 'Testimonials', 'sifency-addons' ),
				'condition' => array( 'source' => 'custom' ),
			)
		);

		$this->add_control(
			'title',
			array(
				'label'       => esc_html__( 'Global Title', 'sifency-addons' ),
				'type'        => Controls_Manager::TEXTAREA,
				'rows'        => 2,
				'condition'   => array( 'source' => 'custom' ),
				'placeholder' => esc_html__( 'e.g. What our client says', 'sifency-addons' ),
			)
		);

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

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

		$this->start_controls_section( 'section_layout_settings', array( 'label' => esc_html__( 'Settings & Visibility', 'sifency-addons' ) ) );

		$this->add_control(
			'display_type',
			array(
				'label'   => esc_html__( 'Grid/Carousel', 'sifency-addons' ),
				'type'    => Controls_Manager::SELECT,
				'options' => array(
					'grid'     => esc_html__( 'Grid', 'sifency-addons' ),
					'carousel' => esc_html__( 'Carousel', 'sifency-addons' ),
				),
				'default' => 'grid',
			)
		);
		$this->add_sifency_addons_floating_count_controls();

		$this->add_responsive_control(
			'columns',
			array(
				'label'          => esc_html__( 'Columns', 'sifency-addons' ),
				'type'           => Controls_Manager::SELECT,
				'options'        => array(
					'1'  => '1',
					'2'  => '2',
					'3'  => '3',
					'4'  => '4',
					'5'  => '5',
					'6'  => '6',
					'7'  => '7',
					'8'  => '8',
					'9'  => '9',
					'10' => '10',
					'11' => '11',
					'12' => '12',
				),
				'default'        => '3',
				'tablet_default' => '2',
				'mobile_default' => '1',
				'selectors'      => array( '{{WRAPPER}} .sifency-addons-testimonials-grid' => 'display: grid; grid-template-columns: repeat({{VALUE}}, 1fr);' ),
				'condition'      => array( 'display_type' => 'grid' ),
			)
		);

		$this->add_responsive_control(
			'grid_gap',
			array(
				'label'     => esc_html__( 'Gap', 'sifency-addons' ),
				'type'      => Controls_Manager::SLIDER,
				'default'   => array( 'size' => 30 ),
				'range'     => array( 'px' => array( 'max' => 100 ) ),
				'selectors' => array( '{{WRAPPER}} .sifency-addons-testimonials-grid' => 'gap: {{SIZE}}{{UNIT}};' ),
				'condition' => array( 'display_type' => 'grid' ),
			)
		);

		$this->add_control( 'hr_options', array( 'type' => Controls_Manager::DIVIDER ) );

		$this->add_control(
			'show_quote',
			array(
				'label'   => esc_html__( 'Show Quote Icon', 'sifency-addons' ),
				'type'    => Controls_Manager::SWITCHER,
				'default' => 'yes',
			)
		);
		$this->add_control(
			'quote_icon',
			array(
				'label'     => esc_html__( 'Quote Icon', 'sifency-addons' ),
				'type'      => Controls_Manager::ICONS,
				'default'   => array(
					'value'   => 'icon-quote',
					'library' => 'sifency-addons',
				),
				'condition' => array( 'show_quote' => 'yes' ),
			)
		);

		$this->add_control(
			'show_title',
			array(
				'label' => esc_html__( 'Show Global Title', 'sifency-addons' ),
				'type'  => Controls_Manager::SWITCHER,
			)
		);
		$this->add_control(
			'show_image',
			array(
				'label'   => esc_html__( 'Show Image', 'sifency-addons' ),
				'type'    => Controls_Manager::SWITCHER,
				'default' => 'yes',
			)
		);
		$this->add_control(
			'show_position',
			array(
				'label'   => esc_html__( 'Show Position', 'sifency-addons' ),
				'type'    => Controls_Manager::SWITCHER,
				'default' => 'yes',
			)
		);
		$this->add_control(
			'show_company',
			array(
				'label'   => esc_html__( 'Show Company', 'sifency-addons' ),
				'type'    => Controls_Manager::SWITCHER,
				'default' => 'yes',
			)
		);
		$this->add_control(
			'show_rating',
			array(
				'label'   => esc_html__( 'Show Rating', 'sifency-addons' ),
				'type'    => Controls_Manager::SWITCHER,
				'default' => 'yes',
			)
		);

		$this->add_control(
			'content_length',
			array(
				'label'   => esc_html__( 'Content Length', 'sifency-addons' ),
				'type'    => Controls_Manager::SELECT,
				'options' => array(
					'full'    => esc_html__( 'Full', 'sifency-addons' ),
					'excerpt' => esc_html__( 'Excerpt', 'sifency-addons' ),
				),
				'default' => 'full',
			)
		);
		$this->add_control(
			'excerpt_length',
			array(
				'label'     => esc_html__( 'Excerpt Words', 'sifency-addons' ),
				'type'      => Controls_Manager::NUMBER,
				'default'   => 25,
				'condition' => array( 'content_length' => 'excerpt' ),
			)
		);
		$this->add_control(
			'read_more_text',
			array(
				'label'     => esc_html__( 'Read More Text', 'sifency-addons' ),
				'type'      => Controls_Manager::TEXT,
				'default'   => esc_html__( 'Read More', 'sifency-addons' ),
				'condition' => array( 'content_length' => 'excerpt' ),
			)
		);

		$this->add_control(
			'text_align',
			array(
				'label'     => esc_html__( 'Text Alignment', 'sifency-addons' ),
				'type'      => \Elementor\Controls_Manager::CHOOSE,
				'options'   => array(
					'left'   => array(
						'title' => esc_html__( 'Left', 'sifency-addons' ),
						'icon'  => 'eicon-text-align-left',
					),
					'center' => array(
						'title' => esc_html__( 'Center', 'sifency-addons' ),
						'icon'  => 'eicon-text-align-center',
					),
					'right'  => array(
						'title' => esc_html__( 'Right', 'sifency-addons' ),
						'icon'  => 'eicon-text-align-right',
					),
				),
				'default'   => 'left',
				'toggle'    => true,
				'selectors' => array(
					'{{WRAPPER}} .testimonial-title, {{WRAPPER}} .sifency-addons-testimonial-rating, {{WRAPPER}} .sifency-addons-testimonial-content, {{WRAPPER}} .sifency-testimonial-quote-icon' => 'text-align: {{VALUE}};',
					'{{WRAPPER}} .sifency-addons-testimonial-author' => 'justify-content: {{VALUE}};',
				),
			)
		);
		$this->add_sifency_addons_flex_alignment_controls(
			array(
				'prefix'   => 'flex_',
				'label'    => esc_html__( 'Author Alignment', 'sifency-addons' ),
				'selector' => '.sifency-addons-testimonial-author',
			)
		);
		$this->add_sifency_addons_flex_alignment_controls(
			array(
				'prefix'   => 'content_flex_',
				'label'    => esc_html__( 'Content Alignment', 'sifency-addons' ),
				'selector' => '.sifency-addons-testimonial-item-inner',
			)
		);
		$this->end_controls_section();

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