<?php
namespace Sifency\Traits;

if ( ! defined( 'ABSPATH' ) ) {
	exit;  }
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',
			array(
				'label' => esc_html__( 'Titles (Comments & Reply)', 'sifency-addons' ),
				'tab'   => Controls_Manager::TAB_STYLE,
			)
		);
		$this->add_control(
			'title_color',
			array(
				'label'     => esc_html__( 'Color', 'sifency-addons' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => array(
					'{{WRAPPER}} .sifency-comments-area .comments-title, {{WRAPPER}} .sifency-comments-area .comment-reply-title' => 'color: {{VALUE}};',
				),
			)
		);
		$this->add_group_control(
			Group_Control_Typography::get_type(),
			array(
				'name'     => 'title_typography',
				'selector' => '{{WRAPPER}} .sifency-comments-area .comments-title, {{WRAPPER}} .sifency-comments-area .comment-reply-title',
			)
		);
		$this->add_responsive_control(
			'title_spacing',
			array(
				'label'     => esc_html__( 'Spacing', 'sifency-addons' ),
				'type'      => Controls_Manager::SLIDER,
				'range'     => array(
					'px' => array(
						'min' => 0,
						'max' => 100,
					),
				),
				'selectors' => array(
					'{{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',
			array(
				'label' => esc_html__( 'Individual Comments', 'sifency-addons' ),
				'tab'   => Controls_Manager::TAB_STYLE,
			)
		);
		$this->add_responsive_control(
			'comment_spacing',
			array(
				'label'     => esc_html__( 'Spacing Between Comments', 'sifency-addons' ),
				'type'      => Controls_Manager::SLIDER,
				'selectors' => array( '{{WRAPPER}} .comment-list > .comment' => 'margin-bottom: {{SIZE}}{{UNIT}};' ),
			)
		);
		$this->add_control(
			'comment_bg_color',
			array(
				'label'     => esc_html__( 'Background Color', 'sifency-addons' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => array( '{{WRAPPER}} .comment-body' => 'background-color: {{VALUE}};' ),
			)
		);
		$this->add_responsive_control(
			'comment_padding',
			array(
				'label'      => esc_html__( 'Padding', 'sifency-addons' ),
				'type'       => Controls_Manager::DIMENSIONS,
				'size_units' => array( 'px', '%', 'em' ),
				'selectors'  => array( '{{WRAPPER}} .comment-body' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ),
			)
		);
		$this->add_control(
			'heading_metadata',
			array(
				'type'      => Controls_Manager::HEADING,
				'label'     => esc_html__( 'Metadata', 'sifency-addons' ),
				'separator' => 'before',
			)
		);
		$this->add_control(
			'author_color',
			array(
				'label'     => esc_html__( 'Author Color', 'sifency-addons' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => array( '{{WRAPPER}} .comment-author .fn' => 'color: {{VALUE}};' ),
			)
		);
		$this->add_group_control(
			Group_Control_Typography::get_type(),
			array(
				'name'     => 'author_typography',
				'selector' => '{{WRAPPER}} .comment-author .fn',
			)
		);
		$this->add_control(
			'date_color',
			array(
				'label'     => esc_html__( 'Date Color', 'sifency-addons' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => array( '{{WRAPPER}} .comment-metadata a' => 'color: {{VALUE}};' ),
			)
		);
		$this->add_group_control(
			Group_Control_Typography::get_type(),
			array(
				'name'     => 'date_typography',
				'selector' => '{{WRAPPER}} .comment-metadata a',
			)
		);

		$this->add_control(
			'heading_content',
			array(
				'type'      => Controls_Manager::HEADING,
				'label'     => esc_html__( 'Content', 'sifency-addons' ),
				'separator' => 'before',
			)
		);
		$this->add_control(
			'content_color',
			array(
				'label'     => esc_html__( 'Color', 'sifency-addons' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => array( '{{WRAPPER}} .comment-content' => 'color: {{VALUE}};' ),
			)
		);
		$this->add_group_control(
			Group_Control_Typography::get_type(),
			array(
				'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',
			array(
				'label' => esc_html__( 'Comment Form', 'sifency-addons' ),
				'tab'   => Controls_Manager::TAB_STYLE,
			)
		);
		$this->add_control(
			'heading_labels',
			array(
				'type'  => Controls_Manager::HEADING,
				'label' => esc_html__(
					'Labels',
					'sifency-addons'
				),
			)
		);
		$this->add_control(
			'label_color',
			array(
				'label'     => esc_html__( 'Color', 'sifency-addons' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => array( '{{WRAPPER}} .comment-form label' => 'color: {{VALUE}};' ),
			)
		);
		$this->add_group_control(
			Group_Control_Typography::get_type(),
			array(
				'name'     => 'label_typography',
				'selector' => '{{WRAPPER}} .comment-form label',
			)
		);
		$this->add_responsive_control(
			'label_spacing',
			array(
				'label'     => esc_html__( 'Spacing', 'sifency-addons' ),
				'type'      => Controls_Manager::SLIDER,
				'selectors' => array( '{{WRAPPER}} .comment-form label' => 'margin-bottom: {{SIZE}}{{UNIT}};' ),
			)
		);

		$this->add_control(
			'heading_fields',
			array(
				'type'      => Controls_Manager::HEADING,
				'label'     => esc_html__( 'Fields', 'sifency-addons' ),
				'separator' => 'before',
			)
		);
		$this->add_group_control(
			Group_Control_Typography::get_type(),
			array(
				'name'     => 'field_typography',
				'selector' => '{{WRAPPER}} .comment-form input:not([type=submit]), {{WRAPPER}} .comment-form textarea',
			)
		);
		$this->add_responsive_control(
			'field_padding',
			array(
				'label'     => esc_html__( 'Padding', 'sifency-addons' ),
				'type'      => Controls_Manager::DIMENSIONS,
				'selectors' => array( '{{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',
			array(
				'label'     => esc_html__( 'Border Radius', 'sifency-addons' ),
				'type'      => Controls_Manager::DIMENSIONS,
				'selectors' => array( '{{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', array( 'label' => 'Normal' ) );
		$this->add_control(
			'field_color',
			array(
				'label'     => esc_html__( 'Text Color', 'sifency-addons' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => array( '{{WRAPPER}} .comment-form input:not([type=submit]), {{WRAPPER}} .comment-form textarea' => 'color: {{VALUE}};' ),
			)
		);
		$this->add_control(
			'field_bg_color',
			array(
				'label'     => esc_html__( 'Background', 'sifency-addons' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => array( '{{WRAPPER}} .comment-form input:not([type=submit]), {{WRAPPER}} .comment-form textarea' => 'background-color: {{VALUE}};' ),
			)
		);
		$this->add_group_control(
			Group_Control_Border::get_type(),
			array(
				'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(),
			array(
				'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', array( 'label' => 'Focus' ) );
		$this->add_control(
			'field_focus_color',
			array(
				'label'     => esc_html__( 'Text Color', 'sifency-addons' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => array( '{{WRAPPER}} .comment-form input:not([type=submit]):focus, {{WRAPPER}} .comment-form textarea:focus' => 'color: {{VALUE}};' ),
			)
		);
		$this->add_control(
			'field_focus_bg_color',
			array(
				'label'     => esc_html__( 'Background', 'sifency-addons' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => array( '{{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(),
			array(
				'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(),
			array(
				'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',
			array(
				'type'      => Controls_Manager::HEADING,
				'label'     => esc_html__( 'Submit Button', 'sifency-addons' ),
				'separator' => 'before',
			)
		);
		$this->add_group_control(
			Group_Control_Typography::get_type(),
			array(
				'name'     => 'button_typography',
				'selector' => '{{WRAPPER}} .comment-form .submit',
			)
		);
		$this->add_responsive_control(
			'button_padding',
			array(
				'label'     => esc_html__( 'Padding', 'sifency-addons' ),
				'type'      => Controls_Manager::DIMENSIONS,
				'selectors' => array( '{{WRAPPER}} .comment-form .submit' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ),
			)
		);
		$this->add_responsive_control(
			'button_border_radius',
			array(
				'label'     => esc_html__( 'Border Radius', 'sifency-addons' ),
				'type'      => Controls_Manager::DIMENSIONS,
				'selectors' => array( '{{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', array( 'label' => 'Normal' ) );
		$this->add_control(
			'button_text_color',
			array(
				'label'     => 'Text Color',
				'type'      => Controls_Manager::COLOR,
				'selectors' => array( '{{WRAPPER}} .comment-form .submit' => 'color: {{VALUE}};' ),
			)
		);
		$this->add_control(
			'button_bg_color',
			array(
				'label'     => 'Background',
				'type'      => Controls_Manager::COLOR,
				'selectors' => array( '{{WRAPPER}} .comment-form .submit' => 'background-color: {{VALUE}};' ),
			)
		);
		$this->add_group_control(
			Group_Control_Border::get_type(),
			array(
				'name'     => 'button_border',
				'selector' => '{{WRAPPER}} .comment-form .submit',
			)
		);
		$this->add_group_control(
			Group_Control_Box_Shadow::get_type(),
			array(
				'name'     => 'button_shadow',
				'selector' => '{{WRAPPER}} .comment-form .submit',
			)
		);
		$this->end_controls_tab();

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

		$this->end_controls_section();
	}
}
