<?php
/**
 * @package MatrixAddons
 * @subpackage trainify
 * @since 1.0.2
 */

if (!function_exists('trainify_eventlist_before_widget')):

    function trainify_eventlist_before_widget()
    {

        ?><div class="tff-container"><?php

    }

endif;
add_action('tribe_events_before_list_widget', 'trainify_eventlist_before_widget', 10);

if (!function_exists('trainify_eventlist_after_widget')):

    function trainify_eventlist_after_widget()
    {

        ?></div><?php

    }

endif;
add_action('tribe_events_after_list_widget', 'trainify_eventlist_after_widget', 10);


if (!function_exists('trainify_theeventcalendar_enqueue_scripts')):

    function trainify_theeventcalendar_enqueue_scripts()
    {

        global $trainify_version;

        $min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';

        wp_enqueue_style('trainify-theeventcalendar', get_template_directory_uri() . '/assets/css/theeventcalendar-style' . $min . '.css', array(), esc_attr($trainify_version));

    }

endif;
add_action('wp_enqueue_scripts', 'trainify_theeventcalendar_enqueue_scripts', 20);

if (!function_exists('trainify_event_list_form_fields')):

    function trainify_event_list_form_fields($widget, $return, $instance)
    {
        if ($widget->id_base != 'tribe-events-list-widget') {
            return $return;
        }
        $event_layout = (isset($instance['event_layout'])) ? esc_attr($instance['event_layout']) : 'layout1';
        $layout_options = array(
            'layout1' => esc_html__('Layout One', 'trainify'),
            'layout2' => esc_html__('Layout Two', 'trainify'),
            'layout3' => esc_html__('Layout Three', 'trainify'),
        );
        ?>
        <p>
            <label for="<?php echo esc_attr($widget->get_field_id('event_layout')); ?>"><?php esc_html_e('Event Layout:', 'trainify'); ?></label>
            <select id="<?php echo esc_attr($widget->get_field_id('event_layout')); ?>"
                    name="<?php echo esc_attr($widget->get_field_name('event_layout')); ?>" class="widefat">
                <?php foreach ($layout_options as $layout_key => $layout_label) { ?>
                    <option value="<?php echo esc_attr($layout_key); ?>" <?php selected($layout_key, $event_layout) ?>><?php echo esc_html($layout_label); ?></option>
                <?php } ?>
            </select>
        </p>
        <?php
        return null;


    }

endif;
add_action('in_widget_form', 'trainify_event_list_form_fields', 10, 3);

if (!function_exists('trainify_widget_update_callback')):

    function trainify_widget_update_callback($instance, $new_instance, $old_instance)
    {

        $instance['event_layout'] = isset($new_instance['event_layout']) ? esc_attr($new_instance['event_layout']) : 'layout1';

        return $instance;

    }

endif;
add_action('widget_update_callback', 'trainify_widget_update_callback', 10, 3);

