<?php
namespace Sifency\Traits;

if ( ! defined( 'ABSPATH' ) ) {
	exit;  }
use Elementor\Controls_Manager;
use Elementor\Repeater;
use Sifency\Traits\Sifency_Addons_Flex_Controls;
use Sifency\Traits\Sifency_Addons_Layout_Controls;
trait Sifency_Clients_Controls {
	use Sifency_Addons_Flex_Controls;
	use Sifency_Addons_Layout_Controls;

	protected function add_sifency_clients_controls( $args = array() ) {
		$this->start_controls_section( 'section_content', array( 'label' => 'Clients' ) );
		$this->add_control(
			'source',
			array(
				'label'   => 'Source',
				'type'    => Controls_Manager::SELECT,
				'options' => array(
					'custom' => 'Custom',
					'posts'  => 'Posts (Requires "client" CPT)',
				),
				'default' => 'custom',
			)
		);

		$repeater = new Repeater();
		$repeater->add_control(
			'client_logo',
			array(
				'label'   => 'Logo',
				'type'    => Controls_Manager::MEDIA,
				'default' => array( 'url' => \Elementor\Utils::get_placeholder_image_src() ),
			)
		);
		$repeater->add_control(
			'client_name',
			array(
				'label'   => 'Name',
				'type'    => Controls_Manager::TEXT,
				'default' => 'Client Name',
			)
		);
		$repeater->add_control(
			'link',
			array(
				'label'   => 'Link',
				'type'    => Controls_Manager::URL,
				'default' => array( 'is_external' => 'true' ),
			)
		);
		$this->add_control(
			'client_list',
			array(
				'label'       => 'Client Items',
				'type'        => Controls_Manager::REPEATER,
				'fields'      => $repeater->get_controls(),
				'default'     => array( array( 'client_name' => 'Client #1' ), array( 'client_name' => 'Client #2' ), array( 'client_name' => 'Client #3' ) ),
				'title_field' => '{{{ client_name }}}',
				'condition'   => array( 'source' => 'custom' ),
			)
		);
		$this->add_control(
			'show_title',
			array(
				'label' => esc_html__( 'Show Title', 'sifency-addons' ),
				'type'  => Controls_Manager::SWITCHER,
			)
		);
		$this->end_controls_section();

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

		$this->start_controls_section( 'section_layout', array( 'label' => 'Layout' ) );
		$this->add_control(
			'layout_style',
			array(
				'label'   => 'Layout',
				'type'    => Controls_Manager::SELECT,
				'options' => array(
					'grid'     => 'Grid',
					'carousel' => 'Carousel',
				),
				'default' => 'grid',
			)
		);

		$this->add_responsive_control(
			'columns',
			array(
				'label'          => 'Columns',
				'type'           => Controls_Manager::SELECT,
				'default'        => '4',
				'tablet_default' => '3',
				'mobile_default' => '2',
				'options'        => array(
					'1' => '1',
					'2' => '2',
					'3' => '3',
					'4' => '4',
					'5' => '5',
					'6' => '6',
				),
				'selectors'      => array(
					'{{WRAPPER}} .sifency-clients--grid' => 'display: grid; grid-template-columns: repeat({{VALUE}}, 1fr);',
				),
				'condition'      => array( 'layout_style' => 'grid' ),
			)
		);

		$this->add_responsive_control(
			'gap',
			array(
				'label'     => 'Gap',
				'type'      => Controls_Manager::SLIDER,
				'range'     => array(
					'px' => array(
						'min' => 0,
						'max' => 100,
					),
				),
				'selectors' => array(
					'{{WRAPPER}} .sifency-clients--grid' => 'gap: {{SIZE}}{{UNIT}};',
				),
				'condition' => array( 'layout_style' => 'grid' ),
			)
		);
		$this->add_sifency_addons_flex_alignment_controls(
			array(
				'prefix'    => 'flex_',
				'label'     => esc_html__( 'Flex Layout', 'sifency-addons' ),
				'selector'  => '.sifency-client-item',
				'condition' => array( 'show_title' => 'yes' ),
			)
		);
		$this->end_controls_section();
	}
}
