<?php
namespace Sifency\Traits;

if ( ! defined( 'ABSPATH' ) ) {
	exit;  }
use Elementor\Controls_Manager;
use Elementor\Repeater;
trait Sifency_Author_Box_Controls {

	protected function add_sifency_author_box_controls( $args = array() ) {

		$this->start_controls_section( 'section_content', array( 'label' => 'Author Info' ) );
		$this->add_control(
			'source',
			array(
				'label'   => 'Source',
				'type'    => Controls_Manager::SELECT,
				'default' => 'current',
				'options' => array(
					'current' => 'Current Post Author',
					'custom'  => 'Custom',
				),
			)
		);
		$this->add_control(
			'custom_author_name',
			array(
				'label'     => 'Name',
				'type'      => Controls_Manager::TEXT,
				'default'   => 'John Doe',
				'condition' => array( 'source' => 'custom' ),
			)
		);
		$this->add_control(
			'custom_author_avatar',
			array(
				'label'     => 'Avatar',
				'type'      => Controls_Manager::MEDIA,
				'condition' => array( 'source' => 'custom' ),
			)
		);
		$this->add_control(
			'custom_author_bio',
			array(
				'label'     => 'Biography',
				'type'      => Controls_Manager::TEXTAREA,
				'condition' => array( 'source' => 'custom' ),
			)
		);
		$this->add_control(
			'link',
			array(
				'label' => 'Name Link',
				'type'  => Controls_Manager::URL,
			)
		);
		$this->end_controls_section();

		// --- Social Links Section ---
		$this->start_controls_section( 'section_social_links', array( 'label' => 'Social Links' ) );
		$repeater = new Repeater();
		$repeater->add_control(
			'social_icon',
			array(
				'label'   => 'Icon',
				'type'    => Controls_Manager::ICONS,
				'default' => array(
					'value'   => 'fab fa-wordpress',
					'library' => 'sifency-icon',
				),
			)
		);
		$repeater->add_control(
			'link',
			array(
				'label'   => 'Link',
				'type'    => Controls_Manager::URL,
				'default' => array( 'is_external' => 'true' ),
			)
		);
		$this->add_control(
			'social_icon_list',
			array(
				'type'        => Controls_Manager::REPEATER,
				'fields'      => $repeater->get_controls(),
				'default'     => array( array( 'social_icon' => array( 'value' => 'icon-facebook' ) ), array( 'social_icon' => array( 'value' => 'icon-linkedin' ) ) ),
				'title_field' => '<# var icon = elementor.helpers.getSocialNetworkNameFromIcon( social_icon ); #><i class="{{ social_icon.value }}" aria-hidden="true"></i> {{{ icon || "Social Icon" }}}',
			)
		);
		$this->end_controls_section();
	}

	protected function add_authorbox_icon_style_controls() {
		$this->start_controls_section(
			'section_style_icons',
			array(
				'label' => esc_html__( 'Social Icons', 'sifency-addons' ),
				'tab'   => \Elementor\Controls_Manager::TAB_STYLE,
			)
		);
		$this->add_responsive_control(
			'icons_gap',
			array(
				'label'     => esc_html__( 'Gap', 'sifency-addons' ),
				'type'      => \Elementor\Controls_Manager::SLIDER,
				'range'     => array(
					'px' => array(
						'min' => 0,
						'max' => 60,
					),
				),
				'default'   => array( 'size' => 8 ),
				'selectors' => array(
					'{{WRAPPER}} .sifency-author-box__social' => 'gap: {{SIZE}}{{UNIT}};',
				),
			)
		);
		$this->add_control(
			'icon_color',
			array(
				'label'     => esc_html__( 'Icon Color', 'sifency-addons' ),
				'type'      => \Elementor\Controls_Manager::COLOR,
				'selectors' => array(
					'{{WRAPPER}} .sifency-author-box__social a, {{WRAPPER}} .sifency-author-box__social a .elementor-icon, {{WRAPPER}} .sifency-author-box__social a i, {{WRAPPER}} .sifency-author-box__social a svg' => 'color: {{VALUE}};',
					'{{WRAPPER}} .sifency-author-box__social a' => 'fill: {{VALUE}};',
				),
			)
		);
		$this->add_control(
			'icon_hover_color',
			array(
				'label'     => esc_html__( 'Icon Hover Color', 'sifency-addons' ),
				'type'      => \Elementor\Controls_Manager::COLOR,
				'selectors' => array(
					'{{WRAPPER}} .sifency-author-box__social a:hover, {{WRAPPER}} .sifency-author-box__social a:hover .elementor-icon, {{WRAPPER}} .sifency-author-box__social a:hover i, {{WRAPPER}} .sifency-author-box__social a:hover svg' => 'color: {{VALUE}}; fill: {{VALUE}};',
				),
			)
		);
		$this->add_control(
			'icon_background',
			array(
				'label'     => esc_html__( 'Background Color', 'sifency-addons' ),
				'type'      => \Elementor\Controls_Manager::COLOR,
				'selectors' => array(
					'{{WRAPPER}} .sifency-author-box__social a' => 'background-color: {{VALUE}};',
				),
			)
		);
		$this->add_control(
			'icon_background_hover',
			array(
				'label'     => esc_html__( 'Background Hover', 'sifency-addons' ),
				'type'      => \Elementor\Controls_Manager::COLOR,
				'selectors' => array(
					'{{WRAPPER}} .sifency-author-box__social a:hover' => 'background-color: {{VALUE}};',
				),
			)
		);
		$this->add_responsive_control(
			'icon_padding',
			array(
				'label'      => esc_html__( 'Padding', 'sifency-addons' ),
				'type'       => \Elementor\Controls_Manager::DIMENSIONS,
				'size_units' => array( 'px', '%' ),
				'selectors'  => array(
					'{{WRAPPER}} .sifency-author-box__social a' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				),
			)
		);
		$this->add_responsive_control(
			'icon_border_radius',
			array(
				'label'      => esc_html__( 'Border Radius', 'sifency-addons' ),
				'type'       => \Elementor\Controls_Manager::SLIDER,
				'size_units' => array( 'px', '%' ),
				'selectors'  => array(
					'{{WRAPPER}} .sifency-author-box__social a' => 'border-radius: {{SIZE}}{{UNIT}};',
				),
			)
		);

		// Border
		$this->add_group_control(
			\Elementor\Group_Control_Border::get_type(),
			array(
				'name'     => 'icon_border',
				'selector' => '{{WRAPPER}} .sifency-author-box__social a',
			)
		);

		// Box shadow
		$this->add_group_control(
			\Elementor\Group_Control_Box_Shadow::get_type(),
			array(
				'name'     => 'icon_box_shadow',
				'selector' => '{{WRAPPER}} .sifency-author-box__social a',
			)
		);
		$this->end_controls_section();
	}
}
