<?php
namespace Sifency\Traits;
if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}
use \Elementor\Controls_Manager;
use \Elementor\Repeater;
use \Elementor\Group_Control_Border;
trait Sifency_Accordion_Controls {

	protected function add_sifency_accordion_controls( $args = [] ) {
		$this->start_controls_section(
            'section_content_accordion',
            [ 'label' => esc_html__('Accordion Items', 'sifency-addons') ]
        );
        $repeater = new Repeater();
        $repeater->add_control(
            'question',
            [ 'label' => esc_html__('Question', 'sifency-addons'), 'type' => Controls_Manager::TEXT, 'default' => esc_html__('Accordion Title', 'sifency-addons'), 'dynamic' => [ 'active' => true ], 'label_block' => true ]
        );
        $repeater->add_control(
            'answer',
            [ 'label' => esc_html__('Answer', 'sifency-addons'), 'type' => Controls_Manager::WYSIWYG, 'default' => esc_html__('Accordion content.', 'sifency-addons'), 'show_label' => false, 'dynamic' => [ 'active' => true ] ]
        );
        $this->add_control(
            'faq_items',
            [
                'label' => esc_html__('Items', 'sifency-addons'),
                'type' => Controls_Manager::REPEATER,
                'fields' => $repeater->get_controls(),
                'default' => [
                    [ 'question' => esc_html__('Question #1', 'sifency-addons'), 'answer' => esc_html__('Content for item #1', 'sifency-addons') ],
                    [ 'question' => esc_html__('Question #2', 'sifency-addons'), 'answer' => esc_html__('Content for item #2', 'sifency-addons') ],
                ],
                'title_field' => '{{{ question }}}',
            ]
        );
        $this->add_control(
            'question_html_tag',
            [ 'label' => esc_html__('Question HTML Tag', 'sifency-addons'), 'type' => Controls_Manager::SELECT, 'options' => [ 'div' => 'div', 'h1'=>'H1', 'h2'=>'H2', 'h3'=>'H3', 'h4'=>'H4', 'h5'=>'H5', 'h6'=>'H6' ], 'default' => 'div', 'separator' => 'before' ]
        );

        $this->add_control(
            'icon',
            [
                'label' => __( 'Icon', 'sifency-addons' ),
                'type' => \Elementor\Controls_Manager::ICONS,
                'default' => [
                    'value' => 'icon-down-open-big',
                    'library' => 'custom',
                ],
                'recommended' => [
                    'custom' => [ 'icon-down-open-big', 'icon-chevron-down', 'icon-plus' ],
                ],
            ]
        );

        $this->add_control(
            'active_icon',
            [
                'label' => __( 'Active Icon', 'sifency-addons' ),
                'type' => \Elementor\Controls_Manager::ICONS,
                'default' => [
                    'value' => 'icon-up-open-big',
                    'library' => 'custom',
                ],
                'recommended' => [
                    'custom' => [ 'icon-top-open-big', 'icon-chevron-up', 'icon-minus' ],
                ],
                'condition' => [ 'icon[value]!' => '' ],
            ]
        );

        $this->add_control(
            'enable_schema',
            [ 'label' => esc_html__('Enable FAQ Schema', 'sifency-addons'), 'type' => Controls_Manager::SWITCHER, 'default' => 'yes', 'description' => esc_html__('Adds structured data for better SEO.', 'sifency-addons') ]
        );
        $this->end_controls_section();

        // --- Settings Section ---
        $this->start_controls_section(
            'section_settings',
            [ 'label' => esc_html__('Settings', 'sifency-addons') ]
        );
        $this->add_control(
            'multiple_open',
            [ 'label' => esc_html__('Allow Multiple Open', 'sifency-addons'), 'type' => Controls_Manager::SWITCHER, 'default' => 'no' ]
        );
        $this->add_control(
            'first_item_active',
            [ 'label' => esc_html__('First Item Active', 'sifency-addons'), 'type' => Controls_Manager::SWITCHER, 'default' => 'yes' ]
        );
        $this->add_control(
            'toggle_speed',
            [ 'label' => esc_html__('Toggle Speed (ms)', 'sifency-addons'), 'type' => Controls_Manager::NUMBER, 'default' => 300 ]
        );
        $this->end_controls_section();

        // --- Style Section: Wrapper ---
        $this->start_controls_section(
            'section_style_wrapper',
            [ 'label' => esc_html__('Wrapper/Item', 'sifency-addons'), 'tab' => Controls_Manager::TAB_STYLE ]
        );
        $this->add_responsive_control(
            'item_spacing',
            [
                'label' => esc_html__('Item Spacing', 'sifency-addons'), 'type' => Controls_Manager::SLIDER,
                'range' => [ 'px' => [ 'min' => 0, 'max' => 100 ] ],
                'selectors' => [ '{{WRAPPER}} .sifency-accordion-item:not(:last-child)' => 'margin-bottom: {{SIZE}}{{UNIT}};' ],
            ]
        );
        $this->add_group_control(
            Group_Control_Border::get_type(),
            [ 'name' => 'item_border', 'selector' => '{{WRAPPER}} .sifency-accordion-item' ]
        );
        $this->add_control(
            'item_border_radius',
            [ 'label' => esc_html__('Border Radius', 'sifency-addons'), 'type' => Controls_Manager::DIMENSIONS, 'selectors' => [ '{{WRAPPER}} .sifency-accordion-item' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ] ]
        );
        $this->end_controls_section();

        // --- Style Section: Question ---
        $this->start_controls_section(
            'section_style_question',
            [
                'label' => esc_html__('Question', 'sifency-addons'),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );

        // --- Tabs for Normal, Hover, Active ---
        $this->start_controls_tabs('tabs_question_style');

        // --- Normal Tab ---
        $this->start_controls_tab(
            'tab_question_normal',
            [
                'label' => esc_html__('Normal', 'sifency-addons'),
            ]
        );

        $this->add_control(
            'question_color',
            [
                'label' => esc_html__('Text Color', 'sifency-addons'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .sifency-accordion-question' => 'color: {{VALUE}};',
                ],
            ]
        );

        $this->add_group_control(
            \Elementor\Group_Control_Background::get_type(),
            [
                'name' => 'question_background',
                'label' => esc_html__('Background', 'sifency-addons'),
                'types' => ['classic', 'gradient'],
                'selector' => '{{WRAPPER}} .sifency-accordion-question',
            ]
        );

        $this->add_group_control(
            \Elementor\Group_Control_Border::get_type(),
            [
                'name' => 'question_border',
                'label' => esc_html__('Border', 'sifency-addons'),
                'selector' => '{{WRAPPER}} .sifency-accordion-question',
            ]
        );

        $this->add_group_control(
            \Elementor\Group_Control_Box_Shadow::get_type(),
            [
                'name' => 'question_box_shadow',
                'label' => esc_html__('Box Shadow', 'sifency-addons'),
                'selector' => '{{WRAPPER}} .sifency-accordion-question',
            ]
        );

        $this->end_controls_tab();

        // --- Hover Tab ---
        $this->start_controls_tab(
            'tab_question_hover',
            [
                'label' => esc_html__('Hover', 'sifency-addons'),
            ]
        );

        $this->add_control(
            'question_hover_color',
            [
                'label' => esc_html__('Text Color', 'sifency-addons'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .sifency-accordion-item .sifency-accordion-question:hover' => 'color: {{VALUE}};',
                ],
            ]
        );

        $this->add_group_control(
            \Elementor\Group_Control_Background::get_type(),
            [
                'name' => 'question_hover_background',
                'label' => esc_html__('Background', 'sifency-addons'),
                'types' => ['classic', 'gradient'],
                'selector' => '{{WRAPPER}} .sifency-accordion-item .sifency-accordion-question:hover',
            ]
        );

        $this->add_group_control(
            \Elementor\Group_Control_Border::get_type(),
            [
                'name' => 'question_hover_border',
                'label' => esc_html__('Border', 'sifency-addons'),
                'selector' => '{{WRAPPER}} .sifency-accordion-item .sifency-accordion-question:hover',
            ]
        );

        $this->add_group_control(
            \Elementor\Group_Control_Box_Shadow::get_type(),
            [
                'name' => 'question_hover_box_shadow',
                'label' => esc_html__('Box Shadow', 'sifency-addons'),
                'selector' => '{{WRAPPER}} .sifency-accordion-item .sifency-accordion-question:hover',
            ]
        );

        $this->end_controls_tab();


        // --- Active Tab ---
        $this->start_controls_tab(
            'tab_question_active',
            [
                'label' => esc_html__('Active', 'sifency-addons'),
            ]
        );

        $this->add_control(
            'question_active_color',
            [
                'label' => esc_html__('Text Color', 'sifency-addons'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .sifency-accordion-item.active .sifency-accordion-question' => 'color: {{VALUE}};',
                ],
            ]
        );

        $this->add_group_control(
            \Elementor\Group_Control_Background::get_type(),
            [
                'name' => 'question_active_background',
                'label' => esc_html__('Background', 'sifency-addons'),
                'types' => ['classic', 'gradient'],
                'selector' => '{{WRAPPER}} .sifency-accordion-item.active .sifency-accordion-question',
            ]
        );

        $this->add_group_control(
            \Elementor\Group_Control_Border::get_type(),
            [
                'name' => 'question_active_border',
                'label' => esc_html__('Border', 'sifency-addons'),
                'selector' => '{{WRAPPER}} .sifency-accordion-item.active .sifency-accordion-question',
            ]
        );

        $this->add_group_control(
            \Elementor\Group_Control_Box_Shadow::get_type(),
            [
                'name' => 'question_active_box_shadow',
                'label' => esc_html__('Box Shadow', 'sifency-addons'),
                'selector' => '{{WRAPPER}} .sifency-accordion-item.active .sifency-accordion-question',
            ]
        );

        $this->end_controls_tab();

        $this->end_controls_tabs();

        $this->add_control(
            'hr_divider_question_spacing',
            [
                'type' => Controls_Manager::DIVIDER,
                'style' => 'thick',
            ]
        );

        $this->add_responsive_control(
            'question_padding',
            [
                'label' => esc_html__('Padding', 'sifency-addons'),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => ['px', 'em', '%'],
                'selectors' => [
                    '{{WRAPPER}} .sifency-accordion-question' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );

        $this->add_responsive_control(
            'question_margin',
            [
                'label' => esc_html__('Margin', 'sifency-addons'),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => ['px', 'em', '%'],
                'selectors' => [
                    '{{WRAPPER}} .sifency-accordion-question' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );

        $this->add_responsive_control(
            'question_border_radius',
            [
                'label' => esc_html__('Border Radius', 'sifency-addons'),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%'],
                'selectors' => [
                    '{{WRAPPER}} .sifency-accordion-question' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );


        $this->end_controls_section();
	}
} 