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


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

            echo $args['before_widget'];
            

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

            <?php

            echo $args['after_widget'];

        }
    }

}

?>