<?php

namespace Unlockafe_addons\Widgets;

use Unlockafe_addons\Traits\Utils as UnlockafeUtils;
use Unlockafe_addons\Traits\Widget_helper;
use Elementor\Widget_Base;
use Elementor\Controls_Manager;
use \Elementor\Group_Control_Typography;
use \Elementor\Group_Control_Background;
use \Elementor\Group_Control_Box_Shadow;
use \Elementor\Group_Control_Border;
use \Elementor\Repeater;

if (!defined('ABSPATH')) exit; // Exit if accessed directly

/**
 * Footer Social Widget
 *
 * @since 1.0.0
 */
class Footer_Social extends Widget_Base
{

    use Widget_helper, UnlockafeUtils;

    /**
     * Retrieve the widget name.
     *
     * @since 1.0.0
     *
     * @access public
     *
     * @return string Widget name.
     */
    public function get_name()
    {
        return 'unlockafe-footer-social';
    }

    /**
     * Retrieve the widget title.
     *
     * @since 1.0.0
     *
     * @access public
     *
     * @return string Widget title.
     */
    public function get_title()
    {
        return __('Footer Social', 'unlock-addons-for-elementor');
    }

    /**
     * Retrieve the widget icon.
     *
     * @since 1.0.0
     *
     * @access public
     *
     * @return string Widget icon.
     */
    public function get_icon()
    {
        return 'eicon-social-icons ulicon';
    }

    /**
     * Retrieve the list of categories the widget belongs to.
     *
     * Used to determine where to display the widget in the editor.
     *
     * Note that currently Elementor supports only one category.
     * When multiple categories passed, Elementor uses the first one.
     *
     * @since 1.0.0
     *
     * @access public
     *
     * @return array Widget categories.
     */
    public function get_categories()
    {
        return ['unlockafe-addons'];
    }

    /**
     * Retrieve the list of scripts the widget depended on.
     *
     * Used to set scripts dependencies required to run the widget.
     *
     * @since 1.0.0
     *
     * @access public
     *
     * @return array Widget scripts dependencies.
     */
    public function get_script_depends()
    {
        return [];
    }

    public function get_style_depends()
    {
        return ['unlockafe-global', 'font-awesome', 'unlockafe-footer-social-style'];
    }

    /**
     * Register the widget controls.
     *
     * Adds different input fields to allow the user to change and customize the widget settings.
     *
     * @since 1.0.0
     *
     * @access protected
     */

    protected function register_controls()
    {
        $this->register_controls_section();
        $this->style_tab_content();
    }

    protected function register_controls_section()
    {


        $this->start_controls_section(
            'wpr_footer_social_section_layout',
            [
                'label' => esc_html__('Layout', 'unlock-addons-for-elementor'),
                'tab'   => Controls_Manager::TAB_CONTENT,
            ]
        );

        $this->add_control(
            'wpr_design_style',
            [
                'label' => esc_html__('Design Style', 'unlock-addons-for-elementor'),
                'type' => Controls_Manager::SELECT,
                'options' => [
                    'layout-1' => esc_html__('Minimal Pills', 'unlock-addons-for-elementor'),
                    'layout-2' => esc_html__('Solid Dark', 'unlock-addons-for-elementor'),
                ],
                'default' => 'layout-2',
                'frontend_available' => true,
            ]
        );

        $this->end_controls_section();


        $this->start_controls_section(
            'wpr_footer_social_section',
            [
                'label' => esc_html__('Footer Social', 'unlock-addons-for-elementor'),
                'tab'   => Controls_Manager::TAB_CONTENT,
            ]
        );

        $repeater = new \Elementor\Repeater();

        $repeater->add_control(
            'repeater_condition',
            [
                'label' => __('Field condition', 'unlock-addons-for-elementor'),
                'type' => Controls_Manager::SELECT,
                'options' => [
                    'style_1' => __('Style 1', 'unlock-addons-for-elementor'),
                    'style_2' => __('Style 2', 'unlock-addons-for-elementor'),
                    'style_3' => __('Style 3', 'unlock-addons-for-elementor'),
                ],
                'default' => 'style_1',
                'frontend_available' => true,
                'style_transfer' => true,
            ]
        );

        $repeater->add_control(
            'wpr_social_active_switch',
            [
                'label' => esc_html__('Social Active', 'unlock-addons-for-elementor'),
                'type' => Controls_Manager::SWITCHER,
                'label_on' => esc_html__('Show', 'unlock-addons-for-elementor'),
                'label_off' => esc_html__('Hide', 'unlock-addons-for-elementor'),
                'return_value' => 'yes',
                'default' => '0',
                'condition' => [
                    'repeater_condition' => ['style_100']
                ]
            ]
        );

        $repeater->add_control(
            'social_image',
            [
                'label' => esc_html__('Social Image', 'unlock-addons-for-elementor'),
                'type' => Controls_Manager::MEDIA,
                'default' => [
                    'url' => \Elementor\Utils::get_placeholder_image_src(),
                ],
                'condition' => [
                    'repeater_condition' => ['style_1']
                ]
            ]
        );

        $repeater->add_control(
            'tp_box_icon_type',
            [
                'label' => esc_html__('Select Icon Type', 'unlock-addons-for-elementor'),
                'type' => \Elementor\Controls_Manager::SELECT,
                'default' => 'image',
                'options' => [
                    'image' => esc_html__('Image', 'unlock-addons-for-elementor'),
                    'icon' => esc_html__('Icon', 'unlock-addons-for-elementor'),
                    'svg' => esc_html__('SVG', 'unlock-addons-for-elementor'),
                ],
                'condition' => [
                    'repeater_condition' => 'style_10',
                ]
            ]
        );
        $repeater->add_control(
            'tp_box_icon_svg',
            [
                'show_label' => false,
                'type' => Controls_Manager::TEXTAREA,
                'label_block' => true,
                'placeholder' => esc_html__('SVG Code Here', 'unlock-addons-for-elementor'),
                'condition' => [
                    'tp_box_icon_type' => 'svg',
                    'repeater_condition' => 'style_10',
                ]
            ]
        );

        $repeater->add_control(
            'tp_box_icon_image',
            [
                'label' => esc_html__('Upload Icon Image', 'unlock-addons-for-elementor'),
                'type' => Controls_Manager::MEDIA,
                'default' => [
                    'url' => \Elementor\Utils::get_placeholder_image_src(),
                ],
                'condition' => [
                    'tp_box_icon_type' => 'image',
                    'repeater_condition' => 'style_10',
                ]
            ]
        );

        $repeater->add_control(
            'tp_box_icon',
            [
                'label' => esc_html__('Icon', 'unlock-addons-for-elementor'),
                'type' => Controls_Manager::ICONS,
                'default' => [
                    'value' => 'fa-brands fa-facebook',
                    'library' => 'fa-solid',
                ],
                'condition' => [
                    'tp_box_icon_type' => 'icon',
                    'repeater_condition' => 'style_10',
                ],
            ]
        );

        $repeater->add_control(
            'wpr_footer_social_title',
            [
                'label'   => esc_html__('Title', 'unlock-addons-for-elementor'),
                'type'        => \Elementor\Controls_Manager::TEXT,
                'default'     => esc_html__('Facebook', 'unlock-addons-for-elementor'),
                'label_block' => true,
            ]
        );

        $repeater->add_control(
            'wpr_footer_social_url',
            [
                'label'   => esc_html__('URL', 'unlock-addons-for-elementor'),
                'type'        => \Elementor\Controls_Manager::URL,
                'default'     => [
                    'url'               => '#',
                    'is_external'       => false,
                    'nofollow'          => false,
                ],
                'placeholder' => esc_html__('Your URL', 'unlock-addons-for-elementor'),
                'label_block' => true,
            ]
        );

        $this->add_control(
            'wpr_footer_social_list',
            [
                'label'       => esc_html__('Social List', 'unlock-addons-for-elementor'),
                'type'        => Controls_Manager::REPEATER,
                'fields'      => $repeater->get_controls(),
                'default'     => [
                    [
                        'wpr_footer_social_title'   => esc_html__('Facebook', 'unlock-addons-for-elementor'),

                    ],
                    [
                        'wpr_footer_social_title'   => esc_html__('Instagram', 'unlock-addons-for-elementor'),

                    ],
                    [
                        'wpr_footer_social_title'   => esc_html__('Behance', 'unlock-addons-for-elementor'),

                    ],
                    [
                        'wpr_footer_social_title'   => esc_html__('Dribble', 'unlock-addons-for-elementor'),

                    ],
                ],
                'title_field' => '{{{ wpr_footer_social_title }}}',
            ]
        );

        $this->end_controls_section();

        $this->start_controls_section(
            'tp_theme_btn_button_group',
            [
                'label' => esc_html__('Theme Button', 'unlock-addons-for-elementor'),
                'tab' => Controls_Manager::TAB_CONTENT,
                'condition'   => ['wpr_design_style'   => ['layout-3']],
            ]
        );

        $this->add_control(
            'tp_button_type',
            [
                'label' => esc_html__('Button Style Type', 'unlock-addons-for-elementor'),
                'type' => Controls_Manager::SELECT,
                'default' => 'inline',
                'options' => [
                    'inline' => esc_html__('Inline', 'unlock-addons-for-elementor'),
                    'w-100 d-block' => esc_html__('Full Width', 'unlock-addons-for-elementor'),
                ],

            ]
        );

        $this->add_control(
            'tp_theme_btn_button_show',
            [
                'label' => esc_html__('Show Button', 'unlock-addons-for-elementor'),
                'type' => Controls_Manager::SWITCHER,
                'label_on' => esc_html__('Show', 'unlock-addons-for-elementor'),
                'label_off' => esc_html__('Hide', 'unlock-addons-for-elementor'),
                'return_value' => 'yes',
                'default' => 'yes',
            ]
        );

        $this->add_control(
            'tp_theme_btn_text',
            [
                'label' => esc_html__('Button Text', 'unlock-addons-for-elementor'),
                'type' => Controls_Manager::TEXT,
                'default' => esc_html__('Read More', 'unlock-addons-for-elementor'),
                'title' => esc_html__('Enter button text', 'unlock-addons-for-elementor'),
                'label_block' => true,
                'condition' => [
                    'tp_theme_btn_button_show' => 'yes'
                ],
            ]
        );

        $this->add_control(
            'wpr_button_img_thumb',
            [
                'label' => esc_html__('Choose Thumbnail', 'unlock-addons-for-elementor'),
                'type' => \Elementor\Controls_Manager::MEDIA,
                'default' => [
                    'url' => \Elementor\Utils::get_placeholder_image_src(),
                ],
                'condition'   => ['wpr_design_style'   => ['layout-12']],
            ]
        );

        $this->add_control(
            'tp_theme_btn_icon_show',
            [
                'label' => esc_html__('Add Icon ?', 'unlock-addons-for-elementor'),
                'type' => \Elementor\Controls_Manager::SWITCHER,
                'label_on' => esc_html__('Show', 'unlock-addons-for-elementor'),
                'label_off' => esc_html__('Hide', 'unlock-addons-for-elementor'),
                'return_value' => 'yes',
                'default' => 'no',
            ]
        );


        $this->tp_single_icon_control('theme_btn', 'tp_theme_btn_icon_show', 'yes');

        $this->add_control(
            'tp_theme_btn_icon_position',
            [
                'label' => esc_html__('Choose Icon Position', 'unlock-addons-for-elementor'),
                'type' => \Elementor\Controls_Manager::CHOOSE,
                'options' => [
                    'left' => [
                        'title' => esc_html__('Left', 'unlock-addons-for-elementor'),
                        'icon' => 'eicon-h-align-left',
                    ],
                    'right' => [
                        'title' => esc_html__('Right', 'unlock-addons-for-elementor'),
                        'icon' => 'eicon-h-align-right',
                    ],
                ],
                'default' => 'right',
                'toggle' => true,
            ]
        );

        $this->add_control(
            'tp_theme_btn_link_type',
            [
                'label' => esc_html__('Button Link Type', 'unlock-addons-for-elementor'),
                'type' => Controls_Manager::SELECT,
                'options' => [
                    '1' => 'Custom Link',
                    '2' => 'Internal Page',
                ],
                'default' => '1',
                'label_block' => true,
                'condition' => [
                    'tp_theme_btn_button_show' => 'yes'
                ],
            ]
        );
        $this->add_control(
            'tp_theme_btn_link',
            [
                'label' => esc_html__('Button link', 'unlock-addons-for-elementor'),
                'type' => Controls_Manager::URL,
                'dynamic' => [
                    'active' => true,
                ],
                'placeholder' => esc_html__('https://your-link.com', 'unlock-addons-for-elementor'),
                'show_external' => false,
                'default' => [
                    'url' => '#',
                    'is_external' => false,
                    'nofollow' => false,
                ],
                'condition' => [
                    'tp_theme_btn_link_type' => '1',
                    'tp_theme_btn_button_show' => 'yes'
                ],
                'label_block' => true,
            ]
        );
        $this->add_control(
            'tp_theme_btn_page_link',
            [
                'label' => esc_html__('Select Button Link Page', 'unlock-addons-for-elementor'),
                'type' => Controls_Manager::SELECT2,
                'label_block' => true,
                'options' => $this->tp_get_all_types_post('page'),
                'condition' => [
                    'tp_theme_btn_link_type' => '2',
                    'tp_theme_btn_button_show' => 'yes'
                ]
            ]
        );

        $this->add_responsive_control(
            'tp_button_align',
            [
                'label' => esc_html__('Alignment', 'unlock-addons-for-elementor'),
                'type' => Controls_Manager::CHOOSE,
                'options' => [
                    'start' => [
                        'title' => esc_html__('Left', 'unlock-addons-for-elementor'),
                        'icon' => 'eicon-text-align-left',
                    ],
                    'center' => [
                        'title' => esc_html__('Center', 'unlock-addons-for-elementor'),
                        'icon' => 'eicon-text-align-center',
                    ],
                    'end' => [
                        'title' => esc_html__('Right', 'unlock-addons-for-elementor'),
                        'icon' => 'eicon-text-align-right',
                    ],
                ],
                'default' => 'center',
                'selectors' => [
                    '{{WRAPPER}} .wpr-el-theme-btn' => 'justify-content: {{VALUE}};',
                ],
                'frontend_available' => true,
                'toggle' => true,
            ]
        );
        $this->end_controls_section();
    }

    // style_tab_content
    protected function style_tab_content()
    {
        $this->start_controls_section(
            'unlockafe_footer_social_container_style',
            [
                'label' => esc_html__('Container', 'unlock-addons-for-elementor'),
                'tab'   => Controls_Manager::TAB_STYLE,
            ]
        );

        $this->add_responsive_control(
            'unlockafe_footer_container_alignment',
            [
                'label' => esc_html__('Alignment', 'unlock-addons-for-elementor'),
                'type' => Controls_Manager::CHOOSE,
                'options' => [
                    'flex-start' => [
                        'title' => esc_html__('Left', 'unlock-addons-for-elementor'),
                        'icon' => 'eicon-text-align-left',
                    ],
                    'center' => [
                        'title' => esc_html__('Center', 'unlock-addons-for-elementor'),
                        'icon' => 'eicon-text-align-center',
                    ],
                    'flex-end' => [
                        'title' => esc_html__('Right', 'unlock-addons-for-elementor'),
                        'icon' => 'eicon-text-align-right',
                    ],
                ],
                'default' => 'flex-start',
                'selectors' => [
                    '{{WRAPPER}} .unlock_addon_footer_social' => 'justify-content: {{VALUE}};',
                ],
            ]
        );

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

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

        $this->add_group_control(
            Group_Control_Background::get_type(),
            [
                'name' => 'unlockafe_footer_container_background',
                'selector' => '{{WRAPPER}} .unlock_addon_footer_social',
            ]
        );

        $this->add_group_control(
            Group_Control_Border::get_type(),
            [
                'name' => 'unlockafe_footer_container_border',
                'selector' => '{{WRAPPER}} .unlock_addon_footer_social',
            ]
        );

        $this->add_group_control(
            Group_Control_Box_Shadow::get_type(),
            [
                'name' => 'unlockafe_footer_container_shadow',
                'selector' => '{{WRAPPER}} .unlock_addon_footer_social',
            ]
        );

        $this->end_controls_section();

        $this->start_controls_section(
            'unlockafe_footer_social_list_style',
            [
                'label' => esc_html__('Social Items', 'unlock-addons-for-elementor'),
                'tab'   => Controls_Manager::TAB_STYLE,
            ]
        );

        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name' => 'unlockafe_footer_social_typography',
                'selector' => '{{WRAPPER}} .unlock_addon_footer_social_link',
            ]
        );

        $this->add_responsive_control(
            'unlockafe_footer_social_gap',
            [
                'label' => esc_html__('Item Gap', 'unlock-addons-for-elementor'),
                'type' => Controls_Manager::SLIDER,
                'size_units' => ['px', 'em'],
                'range' => [
                    'px' => [
                        'min' => 0,
                        'max' => 80,
                    ],
                ],
                'default' => [
                    'unit' => 'px',
                    'size' => 14,
                ],
                'selectors' => [
                    '{{WRAPPER}} .unlock_addon_footer_social_list' => 'gap: {{SIZE}}{{UNIT}} !important;',
                ],
            ]
        );

        $this->add_responsive_control(
            'unlockafe_footer_social_item_padding',
            [
                'label' => esc_html__('Item Padding', 'unlock-addons-for-elementor'),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => ['px', 'em', '%'],
                'selectors' => [
                    '{{WRAPPER}} .unlock_addon_footer_social_link' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );

        $this->add_responsive_control(
            'unlockafe_footer_social_item_radius',
            [
                'label' => esc_html__('Item Radius', 'unlock-addons-for-elementor'),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%', 'em'],
                'selectors' => [
                    '{{WRAPPER}} .unlock_addon_footer_social_link' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );

        $this->add_group_control(
            Group_Control_Border::get_type(),
            [
                'name' => 'unlockafe_footer_social_item_border',
                'selector' => '{{WRAPPER}} .unlock_addon_footer_social_link',
            ]
        );

        $this->start_controls_tabs('unlockafe_footer_social_link_tabs');

        $this->start_controls_tab(
            'unlockafe_footer_social_link_normal',
            [
                'label' => esc_html__('Normal', 'unlock-addons-for-elementor'),
            ]
        );

        $this->add_control(
            'unlockafe_footer_social_link_color',
            [
                'label' => esc_html__('Text/Icon Color', 'unlock-addons-for-elementor'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .unlock_addon_footer_social_link' => 'color: {{VALUE}};',
                    '{{WRAPPER}} .unlock_addon_footer_social_link i' => 'color: {{VALUE}};',
                ],
            ]
        );

        $this->add_group_control(
            Group_Control_Background::get_type(),
            [
                'name' => 'unlockafe_footer_social_link_bg',
                'selector' => '{{WRAPPER}} .unlock_addon_footer_social_link',
            ]
        );

        $this->end_controls_tab();

        $this->start_controls_tab(
            'unlockafe_footer_social_link_hover',
            [
                'label' => esc_html__('Hover', 'unlock-addons-for-elementor'),
            ]
        );

        $this->add_control(
            'unlockafe_footer_social_link_hover_color',
            [
                'label' => esc_html__('Text/Icon Color', 'unlock-addons-for-elementor'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .unlock_addon_footer_social_link:hover' => 'color: {{VALUE}};',
                    '{{WRAPPER}} .unlock_addon_footer_social_link:hover i' => 'color: {{VALUE}};',
                ],
            ]
        );

        $this->add_group_control(
            Group_Control_Background::get_type(),
            [
                'name' => 'unlockafe_footer_social_link_hover_bg',
                'selector' => '{{WRAPPER}} .unlock_addon_footer_social_link:hover',
            ]
        );

        $this->add_control(
            'unlockafe_footer_social_link_hover_border_color',
            [
                'label' => esc_html__('Border Color', 'unlock-addons-for-elementor'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .unlock_addon_footer_social_link:hover' => 'border-color: {{VALUE}};',
                ],
            ]
        );

        $this->end_controls_tab();

        $this->end_controls_tabs();

        $this->add_responsive_control(
            'unlockafe_footer_social_icon_size',
            [
                'label' => esc_html__('Icon Size', 'unlock-addons-for-elementor'),
                'type' => Controls_Manager::SLIDER,
                'size_units' => ['px', 'em'],
                'range' => [
                    'px' => [
                        'min' => 10,
                        'max' => 80,
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .unlock_addon_footer_social_icon i' => 'font-size: {{SIZE}}{{UNIT}};',
                ],
            ]
        );

        $this->add_responsive_control(
            'unlockafe_footer_social_icon_gap',
            [
                'label' => esc_html__('Icon Gap', 'unlock-addons-for-elementor'),
                'type' => Controls_Manager::SLIDER,
                'size_units' => ['px', 'em'],
                'range' => [
                    'px' => [
                        'min' => 0,
                        'max' => 40,
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .unlock_addon_footer_social_link' => 'gap: {{SIZE}}{{UNIT}};',
                ],
            ]
        );

        $this->end_controls_section();
    }

    /**
     * Render the widget output on the frontend.
     *
     * Written in PHP and used to generate the final HTML.
     *
     * @since 1.0.0
     *
     * @access protected
     */
    protected function render()
    {
        $settings = $this->get_settings_for_display();
        $btn_id = 'theme_btn';

?>

        <?php
        $layout = !empty($settings['wpr_design_style']) ? $settings['wpr_design_style'] : 'layout-2';
        $wrapper_classes = [
            'unlock_addon_footer_social',
            'unlock_addon_footer_social_' . $layout,
        ];

        $icon_map = [
            'facebook' => 'fa-brands fa-facebook-f',
            'instagram' => 'fa-brands fa-instagram',
            'behance' => 'fa-brands fa-behance',
            'dribbble' => 'fa-brands fa-dribbble',
            'twitter' => 'fa-brands fa-x-twitter',
            'linkedin' => 'fa-brands fa-linkedin-in',
            'youtube' => 'fa-brands fa-youtube',
            'pinterest' => 'fa-brands fa-pinterest-p',
            'github' => 'fa-brands fa-github',
            'gitub' => 'fa-brands fa-github',
            'tiktok' => 'fa-brands fa-tiktok',
            'whatsapp' => 'fa-brands fa-whatsapp',
            'telegram' => 'fa-brands fa-telegram',
            'website' => 'fa-solid fa-globe',
            'web' => 'fa-solid fa-globe',
        ];
        ?>
        <div class="<?php echo esc_attr(implode(' ', array_map('sanitize_html_class', $wrapper_classes))); ?>">
            <?php if (!empty($settings['wpr_footer_social_list'])) : ?>
                <ul class="unlock_addon_footer_social_list">
                    <?php foreach ($settings['wpr_footer_social_list'] as $menu) :
                        $title = !empty($menu['wpr_footer_social_title']) ? $menu['wpr_footer_social_title'] : '';
                        $link = !empty($menu['wpr_footer_social_url']['url']) ? $menu['wpr_footer_social_url']['url'] : '';
                        $target = !empty($menu['wpr_footer_social_url']['is_external']) ? '_blank' : '_self';
                        $rel_attr = [];
                        if (!empty($menu['wpr_footer_social_url']['nofollow'])) {
                            $rel_attr[] = 'nofollow';
                        }
                        if ($target === '_blank') {
                            $rel_attr[] = 'noopener';
                        }
                        $rel = !empty($rel_attr) ? implode(' ', $rel_attr) : '';

                        if (empty($title) && empty($link)) {
                            continue;
                        }

                        $slug = sanitize_title($title);
                        $icon_class = isset($icon_map[$slug]) ? $icon_map[$slug] : 'fa-solid fa-link';
                        $display_text = !empty($title) ? $title : esc_html__('Social Link', 'unlock-addons-for-elementor');
                        $href = !empty($link) ? $link : '#';
                    ?>
                        <li class="unlock_addon_footer_social_item">
                            <a class="unlock_addon_footer_social_link" href="<?php echo esc_url($href); ?>" target="<?php echo esc_attr($target); ?>" <?php echo !empty($rel) ? 'rel="' . esc_attr($rel) . '"' : ''; ?> aria-label="<?php echo esc_attr($display_text); ?>">
                                <span class="unlock_addon_footer_social_icon" aria-hidden="true">
                                    <i class="<?php echo esc_attr($icon_class); ?>"></i>
                                </span>
                                <span class="unlock_addon_footer_social_label">
                                    <?php echo esc_html($display_text); ?>
                                </span>
                            </a>
                        </li>
                    <?php endforeach; ?>
                </ul>
            <?php else : ?>
                <p class="unlock_addon_footer_social_empty"><?php esc_html_e('Add social links from the widget settings.', 'unlock-addons-for-elementor'); ?></p>
            <?php endif; ?>
        </div>

<?php

    }
}


