<?php
/**
 * Theme Social Share Widget
 * @package Pubzi
 * @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('pubzi_social_share_widget', array(
        'title' => esc_html__('Pubzi: Social Share', 'pubzi-core'),
        'classname' => 'pubzi-social-share-about',
        'description' => esc_html__('Display Social Share widget', 'pubzi-core'),
        'fields' => array(
            array(
                'id' => 'heading',
                'type' => 'text',
                'title' => esc_html__('Enter Your Header Title', 'pubzi-core'),
                'default' => esc_html__('Never Miss News', 'pubzi-core')
            ),
            array(
                'id' => 'pubzi-social-icon-repeater',
                'type' => 'repeater',
                'title' => esc_html__('Social Icon', 'pubzi-core'),
                'fields' => array(
                    array(
                        'id' => 'pubzi-social-icon',
                        'type' => 'icon',
                        'title' => esc_html__('Icon', 'pubzi-core'),
                        'default' => 'fab fa-facebook'
                    ),
                    array(
                        'id' => 'pubzi-social-text',
                        'type' => 'text',
                        'title' => esc_html__('Enter Your Ulr', 'pubzi-core'),
                        'default' => '#'
                    ),
                ),
            ),
        )
    ));


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

            echo $args['before_widget'];
            

            $heading_title = $instance['heading'] ?? '';
            $socialIcon = is_array($instance['pubzi-social-icon-repeater']) && !empty($instance['pubzi-social-icon-repeater']) ? $instance['pubzi-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['pubzi-social-icon']), esc_url($icon['pubzi-social-text']));
                    };
                    ?>
                </ul>
            </div>

            <?php

            echo $args['after_widget'];

        }
    }

}

?>