<?php
/**
 * Theme File Download 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_file_download_widget', array(
        'title' => esc_html__('Feron: File Download', 'feron-core'),
        'classname' => 'feron-widget-file-download',
        'description' => esc_html__('Display File Download widget', 'feron-core'),
        'fields' => array(
            array(
                'id' => 'title',
                'type' => 'text',
                'title' => esc_html__('Title', 'Feron-core'),
                'default' => esc_html__('Download', 'feron-core')
            ),

            array(
                'id' => 'feron-file-download-repeater',
                'type' => 'repeater',
                'title' => esc_html__('File Download', 'feron-core'),
                'fields' => array(
                    array(
                        'id' => 'feron-file-download',
                        'type' => 'media',
                        'title' => esc_html__('File', 'feron-core'),
                    ),
                    array(
                        'id' => 'feron-file-download-text',
                        'type' => 'text',
                        'title' => esc_html__('File Text', 'feron-core'),
                        'default' => esc_html__('Company Profile', 'feron-core')
                    ),

                ),
            ),
        )
    ));


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

            echo $args['before_widget'];

            $title = $instance['title'] ?? '';
            $file_download = is_array($instance['feron-file-download-repeater']) && !empty($instance['feron-file-download-repeater']) ? $instance['feron-file-download-repeater'] : [];


            ?>
            <div class="widget_download">
                <h5 class="widget-headline style-01"><?php echo esc_html($title); ?></h5>               
                <ul>
                    <?php
                        foreach ($file_download as $file) {
                            echo '<li class="mb-0 mt-0">
                                <a download href="'.$file['feron-file-download']['url'].'">
                                    ' . $file['feron-file-download-text'] . '
                                    <i class="fa fa-angle-double-right"></i>
                                </a>
                            </li>';
                        };
                    ?>
                </ul>
            </div>
            <?php

            echo $args['after_widget'];

        }
    }

}

?>