<?php
if (!function_exists('calla_elated_register_side_area_sidebar')) {
    /**
     * Register side area sidebar
     */
    function calla_elated_register_side_area_sidebar() {
        register_sidebar(
            array(
                'id'            => 'sidearea',
                'name'          => esc_html__('Side Area', 'calla'),
                'description'   => esc_html__('Side Area', 'calla'),
                'before_widget' => '<div id="%1$s" class="widget eltdf-sidearea %2$s">',
                'after_widget'  => '</div>',
                'before_title'  => '<div class="eltdf-widget-title-holder"><h5 class="eltdf-widget-title">',
                'after_title'   => '</h5></div>'
            )
        );
    }

    add_action('widgets_init', 'calla_elated_register_side_area_sidebar');
}

if (!function_exists('calla_elated_side_menu_body_class')) {
    /**
     * Function that adds body classes for different side menu styles
     *
     * @param $classes array original array of body classes
     *
     * @return array modified array of classes
     */
    function calla_elated_side_menu_body_class($classes) {

        if (is_active_widget(false, false, 'eltdf_side_area_opener')) {

            if (calla_elated_options()->getOptionValue('side_area_type')) {

                $classes[] = 'eltdf-' . calla_elated_options()->getOptionValue('side_area_type');

            }

            if (calla_elated_options()->getOptionValue('side_area_fixed_content') == 'yes') {

                $classes[] = 'eltdf-side-area-fixed-content';

            }
        }

        return $classes;
    }

    add_filter('body_class', 'calla_elated_side_menu_body_class');
}

if (!function_exists('calla_elated_get_side_area')) {
    /**
     * Loads side area HTML
     */
    function calla_elated_get_side_area() {

        if (is_active_widget(false, false, 'eltdf_side_area_opener')) {

            $parameters = array(
                'side_area_close_icon_class' => calla_elated_get_side_area_close_icon_class()
            );

            calla_elated_get_module_template_part('templates/sidearea', 'sidearea', '', $parameters);
        }
    }

    add_action('calla_elated_after_body_tag', 'calla_elated_get_side_area', 10);
}

if (!function_exists('calla_elated_get_side_area_close_class')) {
    /**
     * Loads side area close icon class
     */
    function calla_elated_get_side_area_close_icon_class() {

        $side_area_icon_source = calla_elated_options()->getOptionValue('side_area_icon_source');

        $side_area_close_icon_class_array = array(
            'eltdf-close-side-menu'
        );

        $side_area_close_icon_class_array[] = $side_area_icon_source == 'icon_pack' ? 'eltdf-close-side-menu-icon-pack' : 'eltdf-close-side-menu-svg-path';

        return $side_area_close_icon_class_array;
    }
}

if (!function_exists('calla_elated_get_side_area_close_icon_html')) {
    /**
     * Loads side area close icon HTML
     */
    function calla_elated_get_side_area_close_icon_html() {

        $side_area_icon_source = calla_elated_options()->getOptionValue('side_area_icon_source');
        $side_area_icon_pack = calla_elated_options()->getOptionValue('side_area_icon_pack');
        $side_area_close_icon_svg_path = calla_elated_options()->getOptionValue('side_area_close_icon_svg_path');

        $side_area_close_icon_html = '';

        if (($side_area_icon_source == 'icon_pack') && isset($side_area_icon_pack)) {
            $side_area_close_icon_html .= calla_elated_icon_collections()->getMenuCloseIcon($side_area_icon_pack);
        } else if (isset($side_area_close_icon_svg_path)) {
            $side_area_close_icon_html .= $side_area_close_icon_svg_path;
        }

        return $side_area_close_icon_html;
    }
}