<?php
namespace Sifency\Traits;
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
use \Elementor\Controls_Manager;
use \Elementor\Repeater;
trait Sifency_Career_Controls {

	protected function add_sifency_career_controls( $args = [] ) {
        $this->start_controls_section( 'section_content', [ 'label' => 'Career Listings' ] );
        $this->add_control(
            'source',
            [
                'label' => 'Source', 'type' => Controls_Manager::SELECT,
                'options' => [ 'custom' => 'Custom', 'posts' => 'Posts (Requires "career" CPT)' ],
                'default' => 'custom',
            ]
        );

        $this->add_control(
            'show_excerpt',
            [
                'label' => esc_html__('Show Excerpt', 'sifency-addons'),
                'type' => \Elementor\Controls_Manager::SWITCHER,
                'label_on' => esc_html__('Yes', 'sifency-addons'),
                'label_off' => esc_html__('No', 'sifency-addons'),
                'return_value' => 'yes',
                'default' => 'yes',
                'condition' => [ 'source' => 'posts' ],
            ]
        );
        $this->add_control(
            'excerpt_length',
            [
                'label' => esc_html__('Excerpt Length (Words)', 'sifency-addons'),
                'type' => \Elementor\Controls_Manager::SLIDER,
                'size_units' => ['words'],
                'range' => [
                    'px' => [
                        'min' => 5,
                        'max' => 100,
                        'step' => 1,
                    ],
                ],
                'default' => [
                    'size' => 20,
                ],
                'condition' => [
                    'show_excerpt' => 'yes',
                ],
            ]
        );

        // --- Custom Content (Repeater) ---
        $repeater = new Repeater();
        $repeater->add_control( 'title', [ 'label' => 'Job Title', 'type' => Controls_Manager::TEXT, 'default' => 'Senior Developer' ] );
        $repeater->add_control( 'location', [ 'label' => 'Location', 'type' => Controls_Manager::TEXT, 'default' => 'Remote' ] );
        $repeater->add_control( 'job_type', [ 'label' => 'Job Type', 'type' => Controls_Manager::TEXT, 'default' => 'Full-time' ] );
        $repeater->add_control( 'excerpt', [ 'label' => 'Description', 'type' => Controls_Manager::TEXTAREA, 'default' => 'Job description goes here.' ] );
        $repeater->add_control( 'link', [ 'label' => 'Apply Link', 'type' => Controls_Manager::URL, 'default' => [ 'is_external' => 'true' ] ] );
        $this->add_control(
            'career_list',
            [
                'label' => 'Career Items', 'type' => Controls_Manager::REPEATER,
                'fields' => $repeater->get_controls(),
                'default' => [
                    [ 'title' => 'Senior Product Designer', 'location' => 'Remote, USA', 'job_type' => 'Full-time' ],
                    [ 'title' => 'Lead Frontend Developer', 'location' => 'New York, NY', 'job_type' => 'Full-time' ],
                ],
                'title_field' => '{{{ title }}}',
                'condition' => [ 'source' => 'custom' ],
            ]
        );
        $this->end_controls_section();

        // --- Query Section (from Trait) ---
        $this->add_sifency_arg_controls();
        $this->update_control( 'section_query', [ 'condition' => [ 'source' => 'posts' ] ] );
        
        // --- Layout Section ---
        $this->start_controls_section( 'section_layout', [ 'label' => 'Layout' ] );
        $this->add_responsive_control(
            'columns',
            [
                'label' => 'Columns', 'type' => Controls_Manager::SELECT, 'default' => '1',
                'options' => [ '1'=>'1', '2'=>'2', '3'=>'3', '4'=>'4' ],
                'selectors' => [ '{{WRAPPER}} .sifency-career-grid' => 'grid-template-columns: repeat({{VALUE}}, 1fr);' ]
            ]
        );
        $this->add_responsive_control( 'gap', [ 'label' => 'Gap', 'type' => Controls_Manager::SLIDER, 'default' => [ 'size' => 30 ], 'selectors' => [ '{{WRAPPER}} .sifency-career-grid' => 'gap: {{SIZE}}px;' ] ]);
        $this->add_control( 'read_more_text', [ 'label' => 'Button Text', 'type' => Controls_Manager::TEXT, 'default' => 'Apply Now' ]);
        $this->end_controls_section();
	}
}