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

	protected function add_sifency_author_box_controls( $args = [] ) {

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

        // --- Social Links Section ---
        $this->start_controls_section( 'section_social_links', [ 'label' => 'Social Links' ] );
        $repeater = new Repeater();
        $repeater->add_control( 'social_icon', [ 'label' => 'Icon', 'type' => Controls_Manager::ICONS, 'default' => [ 'value' => 'fab fa-wordpress', 'library' => 'sifency-icon' ] ] );
        $repeater->add_control( 'link', [ 'label' => 'Link', 'type' => Controls_Manager::URL, 'default' => [ 'is_external' => 'true' ] ] );
        $this->add_control( 'social_icon_list', [ 'type' => Controls_Manager::REPEATER, 'fields' => $repeater->get_controls(), 'default' => [ [ 'social_icon' => [ 'value' => 'icon-facebook' ] ], [ 'social_icon' => [ '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',
            [
                'label' => esc_html__( 'Social Icons', 'sifency-addons' ),
                'tab'   => \Elementor\Controls_Manager::TAB_STYLE,
            ]
        );

        $this->add_responsive_control(
            'icons_gap',
            [
                'label' => esc_html__( 'Gap', 'sifency-addons' ),
                'type'  => \Elementor\Controls_Manager::SLIDER,
                'range' => [ 'px' => [ 'min' => 0, 'max' => 60 ] ],
                'default' => [ 'size' => 8 ],
                'selectors' => [
                    '{{WRAPPER}} .sifency-author-box__social' => 'gap: {{SIZE}}{{UNIT}};',
                ],
            ]
        );

        $this->add_control(
            'icon_color',
            [
                'label'     => esc_html__( 'Icon Color', 'sifency-addons' ),
                'type'      => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{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',
            [
                'label'     => esc_html__( 'Icon Hover Color', 'sifency-addons' ),
                'type'      => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{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',
            [
                'label'     => esc_html__( 'Background Color', 'sifency-addons' ),
                'type'      => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .sifency-author-box__social a' => 'background-color: {{VALUE}};',
                ],
            ]
        );

        $this->add_control(
            'icon_background_hover',
            [
                'label'     => esc_html__( 'Background Hover', 'sifency-addons' ),
                'type'      => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .sifency-author-box__social a:hover' => 'background-color: {{VALUE}};',
                ],
            ]
        );

        $this->add_responsive_control(
            'icon_padding',
            [
                'label' => esc_html__( 'Padding', 'sifency-addons' ),
                'type'  => \Elementor\Controls_Manager::DIMENSIONS,
                'size_units' => [ 'px', '%' ],
                'selectors' => [
                    '{{WRAPPER}} .sifency-author-box__social a' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );

        $this->add_responsive_control(
            'icon_border_radius',
            [
                'label' => esc_html__( 'Border Radius', 'sifency-addons' ),
                'type'  => \Elementor\Controls_Manager::SLIDER,
                'size_units' => [ 'px', '%' ],
                'selectors' => [
                    '{{WRAPPER}} .sifency-author-box__social a' => 'border-radius: {{SIZE}}{{UNIT}};',
                ],
            ]
        );

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

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

        $this->end_controls_section();
    }
}