<?php
namespace Sifency\Traits;

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

use Elementor\Controls_Manager;
use Elementor\Repeater;
use Elementor\Group_Control_Image_Size;
use Elementor\Icons_Manager;
use Sifency\Traits\Sifency_Addons_Floating_Count_Controls;

trait Sifency_Team_Controls {
	use Sifency_Addons_Floating_Count_Controls;

	protected function add_sifency_team_controls( $args = array() ) {
		$this->start_controls_section( 'section_content', array( 'label' => 'Team Members' ) );
		$this->add_control(
			'source',
			array(
				'label'   => 'Source',
				'type'    => Controls_Manager::SELECT,
				'options' => array(
					'custom' => 'Custom',
					'posts'  => 'Posts',
				),
				'default' => 'custom',
			)
		);
		$repeater = new Repeater();
		$repeater->add_control(
			'image',
			array(
				'label'   => 'Image',
				'type'    => Controls_Manager::MEDIA,
				'default' => array( 'url' => \Elementor\Utils::get_placeholder_image_src() ),
			)
		);
		$repeater->add_control(
			'name',
			array(
				'label'   => 'Name',
				'type'    => Controls_Manager::TEXT,
				'default' => 'John Doe',
			)
		);
		$repeater->add_control(
			'position',
			array(
				'label'   => 'Position',
				'type'    => Controls_Manager::TEXT,
				'default' => 'Team Lead',
			)
		);
		$repeater->add_control(
			'link',
			array(
				'label'   => 'Profile Link',
				'type'    => Controls_Manager::URL,
				'default' => array( 'is_external' => 'true' ),
			)
		);

		$social_repeater = new Repeater();
		$social_repeater->add_control(
			'social_icon',
			array(
				'label'   => 'Icon',
				'type'    => Controls_Manager::ICONS,
				'default' => array(
					'value'   => 'fab fa-facebook-f',
					'library' => 'fa-brands',
				),
			)
		);
		$social_repeater->add_control(
			'link',
			array(
				'label'   => 'Link',
				'type'    => Controls_Manager::URL,
				'default' => array( 'is_external' => 'true' ),
			)
		);

		$repeater->add_control(
			'social_icons',
			array(
				'label'       => 'Social Icons',
				'type'        => Controls_Manager::REPEATER,
				'fields'      => $social_repeater->get_controls(),
				'title_field' => '<i class="{{ social_icon.value }}"></i>',
			)
		);

		$this->add_control(
			'team_list',
			array(
				'label'       => 'Team Members',
				'type'        => Controls_Manager::REPEATER,
				'fields'      => $repeater->get_controls(),
				'default'     => array( array( 'name' => 'Team Member #1' ), array( 'name' => 'Team Member #2' ) ),
				'title_field' => '{{{ name }}}',
				'condition'   => array( 'source' => 'custom' ),
			)
		);

		$this->add_group_control(
			Group_Control_Image_Size::get_type(),
			array(
				'name'    => 'thumbnail',
				'default' => 'large',
			)
		);

		$this->end_controls_section();

		$this->start_controls_section( 'section_settings', array( 'label' => 'Settings' ) );
		$this->add_sifency_addons_floating_count_controls();
		$this->end_controls_section();

		$this->add_sifency_arg_controls(
			array(
				'default_post' => 'team',
				'condition'    => array( 'source' => 'posts' ),
			)
		);
		$this->start_controls_section( 'section_layout', array( 'label' => 'Layout Settings' ) );

		$this->add_control(
			'display_type',
			array(
				'label'   => 'Display Type',
				'type'    => Controls_Manager::SELECT,
				'options' => array(
					'grid'     => 'Grid',
					'carousel' => 'Carousel',
				),
				'default' => 'grid',
			)
		);
		$this->add_control(
			'layout_style',
			array(
				'label'   => 'Design Style',
				'type'    => Controls_Manager::SELECT,
				'default' => 'style-1',
				'options' => array(
					'style-1'  => 'Style 1: Standard (Image Top)',
					'style-2'  => 'Style 2: Overlay (Text over Image)',
					'style-3'  => 'Style 3: Slide Up (Hover Reveal)',
					'style-4'  => 'Style 4: Modern Card (Floating Box)',
					'style-5'  => 'Style 5: Side Socials',
					'style-6'  => 'Style 6: Circle Frame',
					'style-7'  => 'Style 7: Horizontal Split',
					'style-8'  => 'Style 8: Offset Border',
					'style-9'  => 'Style 9: Full Image Gradient',
					'style-10' => 'Style 10: Skewed Mask',
					'style-11' => 'Style 11: Organic Blob (Shape)',
					'style-12' => 'Style 12: Bottom Bar (Minimal)',
					'style-13' => 'Style 13: Bordered Frame (Outline)',
					'style-14' => 'Style 14: Neomorphism (Soft UI)',
					'style-15' => 'Style 15: Blur Focus (Zoom)',
					'style-16' => 'Style 16: Magazine (Typography)',
					'style-17' => 'Style 17: Grayscale to Color',
					'style-18' => 'Style 18: Corner Ribbon',
					'style-19' => 'Style 19: Social Strip (Expand)',
					'style-20' => 'Style 20: Glassmorphism Card',
				),
			)
		);
		$this->add_responsive_control(
			'columns',
			array(
				'label'          => 'Columns',
				'type'           => Controls_Manager::SELECT,
				'default'        => '3',
				'tablet_default' => '2',
				'mobile_default' => '1',
				'options'        => array(
					'1' => '1',
					'2' => '2',
					'3' => '3',
					'4' => '4',
					'5' => '5',
					'6' => '6',
				),
				'selectors'      => array( '{{WRAPPER}} .sifency-team-grid' => 'grid-template-columns: repeat({{VALUE}}, 1fr);' ),
				'condition'      => array( 'display_type' => 'grid' ),
			)
		);

		$this->add_responsive_control(
			'gap',
			array(
				'label'     => 'Gap',
				'type'      => Controls_Manager::SLIDER,
				'default'   => array( 'size' => 30 ),
				'selectors' => array( '{{WRAPPER}} .sifency-team-grid' => 'gap: {{SIZE}}px;' ),
			)
		);

		$this->end_controls_section();
		$this->add_sifency_addons_floating_count_style_controls();
	}
}
