<?php
namespace Sifency\Traits;
if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}
use \Elementor\Controls_Manager;
use \Elementor\Repeater;
trait Sifency_Award_Controls {
	protected function add_sifency_award_controls( $args = [] ) {
        // --- Content Section ---
        $this->start_controls_section( 'section_content', [ 'label' => 'Awards' ] );

        $this->add_control(
            'source',
            [
                'label' => 'Source', 'type' => Controls_Manager::SELECT,
                'options' => [ 'custom' => 'Custom', 'posts' => 'Posts (Requires "award" CPT)' ],
                'default' => 'custom',
            ]
        );

        $repeater = new Repeater();
        $repeater->add_control( 'award_year', [
            'label'   => 'Year',
            'type'    => Controls_Manager::TEXT,
            'default' => current_time( 'Y' ),
        ] );    
        $repeater->add_control( 'award_title', [ 'label' => 'Title', 'type' => Controls_Manager::TEXT, 'default' => 'Award Title' ] );
        $repeater->add_control( 'awarding_body', [ 'label' => 'Awarding Body', 'type' => Controls_Manager::TEXT, 'default' => 'Awarding Organization' ] );
        $repeater->add_control( 'link', [ 'label' => 'View Project', 'type' => Controls_Manager::URL, 'default' => [ 'is_external' => 'true' ] ] );
        $this->add_control( 'read_more_text', [ 'label' => 'Button Text', 'type' => Controls_Manager::TEXT, 'default' => 'View Projects', 'condition' => [ 'source' => 'custom' ], ]);

        $this->add_control(
            'awards_list',
            [
                'label' => 'Award Items', 'type' => Controls_Manager::REPEATER,
                'fields' => $repeater->get_controls(),
                'default' => [
                    [ 'award_year' => '2023', 'award_title' => 'Best Website Design', 'awarding_body' => 'Digital Awards Inc.' ],
                    [ 'award_year' => '2022', 'award_title' => 'User Experience Prize', 'awarding_body' => 'UX Design Magazine' ],
                ],
                'title_field' => '{{{ award_title }}} - {{{ award_year }}}',
                'condition' => [ 'source' => 'custom' ],
            ]
        );
        $this->end_controls_section();

        // --- Query Section ---
        $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_control(
            'layout_style',
            [ 'label' => 'Layout', 'type' => Controls_Manager::SELECT, 'options' => [ 'list' => 'List', 'grid' => 'Grid' ], 'default' => 'list' ]
        );
        $this->add_responsive_control(
            'columns',
            [ 'label' => 'Columns', 'type' => Controls_Manager::SELECT, 'default' => '2', 'options' => [ '1'=>'1', '2'=>'2', '3'=>'3', '4'=>'4' ], 'selectors' => [ '{{WRAPPER}} .sifency-awards--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-awards--grid, {{WRAPPER}} .sifency-awards--list' => 'gap: {{SIZE}}px;' ] ]
        );
        $this->end_controls_section();
	}
} 