<?php
/**
 * Theme Social Share Widget
 * @package Feron
 * @since 1.0.0
 */

if (!defined('ABSPATH')) {
    exit(); //exit if access directly
}
// Control core classes for avoid errors
if (class_exists('CSF')) {


    // Create a About Widget
    CSF::createWidget('feron_social_share_widget', array(
        'title' => esc_html__('Feron: Social Share', 'feron-core'),
        'classname' => 'feron-social-share-about',
        'description' => esc_html__('Display Social Share widget', 'feron-core'),
        'fields' => array(
            array(
                'id' => 'heading',
                'type' => 'text',
                'title' => esc_html__('Enter Your Header Title', 'feron-core'),
                'default' => esc_html__('Never Miss News', 'feron-core')
            ),
            array(
                'id' => 'feron-social-icon-repeater',
                'type' => 'repeater',
                'title' => esc_html__('Social Icon', 'feron-core'),
                'fields' => array(
                    array(
                        'id' => 'feron-social-icon',
                        'type' => 'icon',
                        'title' => esc_html__('Icon', 'feron-core'),
                        'default' => 'fab fa-facebook'
                    ),
                    array(
                        'id' => 'feron-social-text',
                        'type' => 'text',
                        'title' => esc_html__('Enter Your Ulr', 'feron-core'),
                        'default' => '#'
                    ),
                ),
            ),
        )
    ));


    if (!function_exists('feron_social_share_widget')) {
        function feron_social_share_widget($args, $instance)
        {

            echo $args['before_widget'];
            

            $heading_title = $instance['heading'] ?? '';
            $socialIcon = is_array($instance['feron-social-icon-repeater']) && !empty($instance['feron-social-icon-repeater']) ? $instance['feron-social-icon-repeater'] : [];


            ?>
            <div class="social-share-widget">
                <h4 class="widget-headline"><?php echo esc_html($heading_title); ?></h4>
                <ul class="social-icon style-03">
                    <?php
                    foreach ($socialIcon as $icon) {
                        printf('<li><a href="%2$s"><i class="%1$s"></i></a></li>', esc_html($icon['feron-social-icon']), esc_url($icon['feron-social-text']));
                    };
                    ?>
                </ul>
            </div>

            <?php

            echo $args['after_widget'];

        }
    }

}

?>