<?php
namespace Sifency\Traits;
if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}
use \Elementor\Widget_Base;
use \Elementor\Controls_Manager;
use \Elementor\Group_Control_Typography;
use \Elementor\Group_Control_Image_Size;
use \Elementor\Repeater;
use \Elementor\Icons_Manager;
trait Sifency_Team_Controls {
	protected function add_sifency_team_controls( $args = [] ) {
        // --- Content Section ---
        $this->start_controls_section( 'section_content', [ 'label' => 'Team Members' ] );
        $this->add_control( 'source', [ 'label' => 'Source', 'type' => Controls_Manager::SELECT, 'options' => [ 'custom' => 'Custom', 'posts' => 'Posts (Requires "team" CPT)' ], 'default' => 'custom' ] );
        $repeater = new Repeater();
        $repeater->add_control( 'image', [ 'label' => 'Image', 'type' => Controls_Manager::MEDIA, 'default' => [ 'url' => \Elementor\Utils::get_placeholder_image_src() ] ] );
        $repeater->add_control( 'name', [ 'label' => 'Name', 'type' => Controls_Manager::TEXT, 'default' => 'John Doe' ] );
        $repeater->add_control( 'position', [ 'label' => 'Position', 'type' => Controls_Manager::TEXT, 'default' => 'Team Lead' ] );
        $repeater->add_control( 'link', [ 'label' => 'Profile Link', 'type' => Controls_Manager::URL, 'default' => [ 'is_external' => 'true' ] ] );
        $social_repeater = new Repeater();
        $social_repeater->add_control( 'social_icon', [ 'label' => 'Icon', 'type' => Controls_Manager::ICONS, 'default' => [ 'value' => 'icon-facebook', 'library' => 'sifency-icons' ] ] );
        $social_repeater->add_control( 'link', [ 'label' => 'Link', 'type' => Controls_Manager::URL, 'default' => [ 'is_external' => 'true' ] ] );
        $repeater->add_control( 'social_icons', [ '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', [ 'label' => 'Team Members', 'type' => Controls_Manager::REPEATER, 'fields' => $repeater->get_controls(), 'default' => [ [ 'name' => 'Team Member #1' ], [ 'name' => 'Team Member #2' ] ], 'title_field' => '{{{ name }}}', 'condition' => [ 'source' => 'custom' ] ]);
        $this->end_controls_section();

        // --- Query Section ---
        $this->add_sifency_arg_controls();
        $this->update_control('query_post_type', ['default' => 'team']);
        $this->update_control('section_query', [ 'condition' => [ 'source' => 'posts' ] ]);
        
        // --- Layout Section ---
        $this->start_controls_section( 'section_layout', [ 'label' => 'Layout' ] );
        $this->add_control( 'layout_style', [ 'label' => 'Layout', 'type' => Controls_Manager::SELECT, 'options' => [ 'grid' => 'Grid', 'carousel' => 'Carousel' ], 'default' => 'grid' ]);
        $this->add_responsive_control(
            'columns',
            [ 
                'label' => 'Columns', 'type' => Controls_Manager::SELECT, 'default' => '3', 'tablet_default' => '2', 'mobile_default' => '1', 
                'options' => [ '1'=>'1', '2'=>'2', '3'=>'3', '4'=>'4', '5'=>'5', '6'=>'6' ], 
                'selectors' => [ '{{WRAPPER}} .sifency-team-grid' => 'grid-template-columns: repeat({{VALUE}}, 1fr);' ], 
                'condition' => [ 'layout_style' => 'grid' ] 
            ]
        );
        $this->add_responsive_control( 'gap', [ 'label' => 'Gap', 'type' => Controls_Manager::SLIDER, 'default' => [ 'size' => 30 ], 'selectors' => [ '{{WRAPPER}} .sifency-team-grid' => 'gap: {{SIZE}}px;' ] ]);
        $this->add_group_control( Group_Control_Image_Size::get_type(), [ 'name' => 'thumbnail', 'default' => 'medium_large' ]);
        $this->end_controls_section();
	}
}