<?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;
use Sifency\Traits\Sifency_Icon_Style_Controls;

trait Sifency_Services_Controls {
    use Sifency_Icon_Style_Controls;
	protected function add_sifency_services_controls( $args = [] ) {
        // --- Content Section ---
        $this->start_controls_section( 'section_content', [ 'label' => 'Services' ] );
        $this->add_control( 'source', [ 'label' => 'Source', 'type' => Controls_Manager::SELECT, 'options' => [ 'custom' => 'Custom', 'posts' => 'Posts (Requires "service" CPT)' ], 'default' => 'custom' ] );

        $repeater = new Repeater();
        $repeater->add_control( 'icon', [ 'label' => 'Icon', 'type' => Controls_Manager::ICONS, 'default' => [ 'value' => 'icon-star', 'library' => 'sifency-icons' ] ] );
        $repeater->add_control( 'title', [ 'label' => 'Title', 'type' => Controls_Manager::TEXT, 'default' => 'Service Title' ] );
        $repeater->add_control( 'excerpt', [ 'label' => 'Description', 'type' => Controls_Manager::TEXTAREA, 'default' => 'There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration.' ] );
        $repeater->add_control( 'link', [ 'label' => 'Link', 'type' => Controls_Manager::URL,] );
        $this->add_control(
            'service_list',
            [
                'label' => 'Service Items', 'type' => Controls_Manager::REPEATER, 'fields' => $repeater->get_controls(),
                'default' => [ [ 'title' => 'Service #1' ], [ 'title' => 'Service #2' ] ],
                'title_field' => '{{{ title }}}', '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' => [ 'grid' => 'Grid', 'carousel' => 'Carousel' ], 'default' => 'grid' ]);
        
        
        // In register_controls()
        $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' ],
                'selectors' => [ '{{WRAPPER}} .sifency-services-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-services-grid' => 'gap: {{SIZE}}px;' ] ]);
        $this->add_control( 'read_more_text', [ 'label' => 'Button Text', 'type' => Controls_Manager::TEXT, 'default' => esc_html__( 'Read More', 'sifency-addons' ) ] );
        $this->end_controls_section();
	}
}