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

trait Sifency_Comment_Box_Controls {

	/**
	 * Adds all advanced comment box style controls.
	 * This method acts as a wrapper that calls individual methods for each section,
	 * keeping the code clean and organized.
	 */
	protected function add_sifency_comment_box_controls() {
        $this->register_title_style_controls();
        $this->register_comment_style_controls();
        $this->register_form_style_controls();
	}


    protected function register_title_style_controls() {
        $this->start_controls_section(
            'section_style_titles',
            [ 'label' => esc_html__('Titles (Comments & Reply)', 'sifency-addons'), 'tab' => Controls_Manager::TAB_STYLE ]
        );
        $this->add_control(
            'title_color',
            [
                'label' => esc_html__('Color', 'sifency-addons'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .sifency-comments-area .comments-title, {{WRAPPER}} .sifency-comments-area .comment-reply-title' => 'color: {{VALUE}};',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name' => 'title_typography',
                'selector' => '{{WRAPPER}} .sifency-comments-area .comments-title, {{WRAPPER}} .sifency-comments-area .comment-reply-title',
            ]
        );
        $this->add_responsive_control(
            'title_spacing',
            [
                'label' => esc_html__('Spacing', 'sifency-addons'),
                'type' => Controls_Manager::SLIDER,
                'range' => [ 'px' => [ 'min' => 0, 'max' => 100 ] ],
                'selectors' => [
                    '{{WRAPPER}} .sifency-comments-area .comments-title, {{WRAPPER}} .sifency-comments-area .comment-reply-title' => 'margin-bottom: {{SIZE}}{{UNIT}};',
                ],
            ]
        );
        $this->end_controls_section();
    }

    /**
     * Registers style controls for the individual comment items.
     */
    protected function register_comment_style_controls() {
        $this->start_controls_section(
            'section_style_comments',
            [ 'label' => esc_html__('Individual Comments', 'sifency-addons'), 'tab' => Controls_Manager::TAB_STYLE ]
        );
        $this->add_responsive_control(
            'comment_spacing',
            [
                'label' => esc_html__('Spacing Between Comments', 'sifency-addons'),
                'type' => Controls_Manager::SLIDER,
                'selectors' => [ '{{WRAPPER}} .comment-list > .comment' => 'margin-bottom: {{SIZE}}{{UNIT}};' ],
            ]
        );
        $this->add_control(
            'comment_bg_color',
            [
                'label' => esc_html__('Background Color', 'sifency-addons'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [ '{{WRAPPER}} .comment-body' => 'background-color: {{VALUE}};' ],
            ]
        );
        $this->add_responsive_control(
            'comment_padding',
            [
                'label' => esc_html__('Padding', 'sifency-addons'),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => [ 'px', '%', 'em' ],
                'selectors' => [ '{{WRAPPER}} .comment-body' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ],
            ]
        );

        $this->add_control('heading_metadata', [ 'type' => Controls_Manager::HEADING, 'label' => esc_html__('Metadata', 'sifency-addons'), 'separator' => 'before' ]);
        $this->add_control('author_color', [ 'label' => esc_html__('Author Color', 'sifency-addons'), 'type' => Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .comment-author .fn' => 'color: {{VALUE}};' ] ]);
        $this->add_group_control(Group_Control_Typography::get_type(), [ 'name' => 'author_typography', 'selector' => '{{WRAPPER}} .comment-author .fn' ]);
        $this->add_control('date_color', [ 'label' => esc_html__('Date Color', 'sifency-addons'), 'type' => Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .comment-metadata a' => 'color: {{VALUE}};' ] ]);
        $this->add_group_control(Group_Control_Typography::get_type(), [ 'name' => 'date_typography', 'selector' => '{{WRAPPER}} .comment-metadata a' ]);

        $this->add_control('heading_content', [ 'type' => Controls_Manager::HEADING, 'label' => esc_html__('Content', 'sifency-addons'), 'separator' => 'before' ]);
        $this->add_control('content_color', [ 'label' => esc_html__('Color', 'sifency-addons'), 'type' => Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .comment-content' => 'color: {{VALUE}};' ] ]);
        $this->add_group_control(Group_Control_Typography::get_type(), [ 'name' => 'content_typography', 'selector' => '{{WRAPPER}} .comment-content' ]);
        $this->end_controls_section();
    }

    /**
     * Registers style controls for the comment submission form.
     */
    protected function register_form_style_controls() {
        $this->start_controls_section(
            'section_style_form',
            [ 'label' => esc_html__('Comment Form', 'sifency-addons'), 'tab' => Controls_Manager::TAB_STYLE ]
        );

        $this->add_control('heading_labels', [ 'type' => Controls_Manager::HEADING, 'label' => esc_html__('Labels', 'sifency-addons') ]);
        $this->add_control('label_color', [ 'label' => esc_html__('Color', 'sifency-addons'), 'type' => Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .comment-form label' => 'color: {{VALUE}};' ] ]);
        $this->add_group_control(Group_Control_Typography::get_type(), [ 'name' => 'label_typography', 'selector' => '{{WRAPPER}} .comment-form label' ]);
        $this->add_responsive_control('label_spacing', [ 'label' => esc_html__('Spacing', 'sifency-addons'), 'type' => Controls_Manager::SLIDER, 'selectors' => [ '{{WRAPPER}} .comment-form label' => 'margin-bottom: {{SIZE}}{{UNIT}};' ] ]);

        $this->add_control('heading_fields', [ 'type' => Controls_Manager::HEADING, 'label' => esc_html__('Fields', 'sifency-addons'), 'separator' => 'before' ]);
        $this->add_group_control(Group_Control_Typography::get_type(), [ 'name' => 'field_typography', 'selector' => '{{WRAPPER}} .comment-form input:not([type=submit]), {{WRAPPER}} .comment-form textarea' ]);
        $this->add_responsive_control('field_padding', [ 'label' => esc_html__('Padding', 'sifency-addons'), 'type' => Controls_Manager::DIMENSIONS, 'selectors' => [ '{{WRAPPER}} .comment-form input:not([type=submit]), {{WRAPPER}} .comment-form textarea' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ] ]);
        $this->add_responsive_control('field_border_radius', [ 'label' => esc_html__('Border Radius', 'sifency-addons'), 'type' => Controls_Manager::DIMENSIONS, 'selectors' => [ '{{WRAPPER}} .comment-form input:not([type=submit]), {{WRAPPER}} .comment-form textarea' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ] ]);

        $this->start_controls_tabs('field_styles_tabs');
        $this->start_controls_tab('field_normal', ['label' => 'Normal']);
        $this->add_control('field_color', [ 'label' => esc_html__('Text Color', 'sifency-addons'), 'type' => Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .comment-form input:not([type=submit]), {{WRAPPER}} .comment-form textarea' => 'color: {{VALUE}};' ] ]);
        $this->add_control('field_bg_color', [ 'label' => esc_html__('Background', 'sifency-addons'), 'type' => Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .comment-form input:not([type=submit]), {{WRAPPER}} .comment-form textarea' => 'background-color: {{VALUE}};' ] ]);
        $this->add_group_control(Group_Control_Border::get_type(), [ 'name' => 'field_border', 'selector' => '{{WRAPPER}} .comment-form input:not([type=submit]), {{WRAPPER}} .comment-form textarea' ]);
        $this->add_group_control(Group_Control_Box_Shadow::get_type(), [ 'name' => 'field_shadow', 'selector' => '{{WRAPPER}} .comment-form input:not([type=submit]), {{WRAPPER}} .comment-form textarea' ]);
        $this->end_controls_tab();

        $this->start_controls_tab('field_focus', ['label' => 'Focus']);
        $this->add_control('field_focus_color', [ 'label' => esc_html__('Text Color', 'sifency-addons'), 'type' => Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .comment-form input:not([type=submit]):focus, {{WRAPPER}} .comment-form textarea:focus' => 'color: {{VALUE}};' ] ]);
        $this->add_control('field_focus_bg_color', [ 'label' => esc_html__('Background', 'sifency-addons'), 'type' => Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .comment-form input:not([type=submit]):focus, {{WRAPPER}} .comment-form textarea:focus' => 'background-color: {{VALUE}};' ] ]);
        $this->add_group_control(Group_Control_Border::get_type(), [ 'name' => 'field_focus_border', 'selector' => '{{WRAPPER}} .comment-form input:not([type=submit]):focus, {{WRAPPER}} .comment-form textarea:focus' ]);
        $this->add_group_control(Group_Control_Box_Shadow::get_type(), [ 'name' => 'field_focus_shadow', 'selector' => '{{WRAPPER}} .comment-form input:not([type=submit]):focus, {{WRAPPER}} .comment-form textarea:focus' ]);
        $this->end_controls_tab();
        $this->end_controls_tabs();

        $this->add_control('heading_button', [ 'type' => Controls_Manager::HEADING, 'label' => esc_html__('Submit Button', 'sifency-addons'), 'separator' => 'before' ]);
        $this->add_group_control(Group_Control_Typography::get_type(), [ 'name' => 'button_typography', 'selector' => '{{WRAPPER}} .comment-form .submit' ]);
        $this->add_responsive_control('button_padding', [ 'label' => esc_html__('Padding', 'sifency-addons'), 'type' => Controls_Manager::DIMENSIONS, 'selectors' => [ '{{WRAPPER}} .comment-form .submit' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ] ]);
        $this->add_responsive_control('button_border_radius', [ 'label' => esc_html__('Border Radius', 'sifency-addons'), 'type' => Controls_Manager::DIMENSIONS, 'selectors' => [ '{{WRAPPER}} .comment-form .submit' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ] ]);

        $this->start_controls_tabs('button_styles_tabs');
        $this->start_controls_tab('button_normal', ['label' => 'Normal']);
        $this->add_control('button_text_color', [ 'label' => 'Text Color', 'type' => Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .comment-form .submit' => 'color: {{VALUE}};' ] ]);
        $this->add_control('button_bg_color', [ 'label' => 'Background', 'type' => Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .comment-form .submit' => 'background-color: {{VALUE}};' ] ]);
        $this->add_group_control(Group_Control_Border::get_type(), [ 'name' => 'button_border', 'selector' => '{{WRAPPER}} .comment-form .submit' ]);
        $this->add_group_control(Group_Control_Box_Shadow::get_type(), [ 'name' => 'button_shadow', 'selector' => '{{WRAPPER}} .comment-form .submit' ]);
        $this->end_controls_tab();

        $this->start_controls_tab('button_hover', ['label' => 'Hover']);
        $this->add_control('button_hover_text_color', [ 'label' => 'Text Color', 'type' => Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .comment-form .submit:hover' => 'color: {{VALUE}};' ] ]);
        $this->add_control('button_hover_bg_color', [ 'label' => 'Background', 'type' => Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .comment-form .submit:hover' => 'background-color: {{VALUE}};' ] ]);
        $this->add_group_control(Group_Control_Border::get_type(), [ 'name' => 'button_hover_border', 'selector' => '{{WRAPPER}} .comment-form .submit:hover' ]);
        $this->add_group_control(Group_Control_Box_Shadow::get_type(), [ 'name' => 'button_hover_shadow', 'selector' => '{{WRAPPER}} .comment-form .submit:hover' ]);
        $this->end_controls_tab();
        $this->end_controls_tabs();
        
        $this->end_controls_section();
    }
}