<?php
/**
 * Accordion element if site origin bundle plugin is activaited
 *
 * 
 * @package    Auxin
 * @license    LICENSE.txt
 * @author     
 * @link       http://averta.net/phlox/
 * @copyright  (c) 2010-2017 
 */

function  auxin_get_new_accordion_master_array( $master_array ) {

     $master_array['aux_accordion'] = array(
        'name'                    => __('Accordion ', 'auxin-elements'),
        'auxin_output_callback'   => 'auxin_widget_accordion_callback',
        'base'                    => 'aux_accordion',
        'description'             => __('Collapsible content', 'auxin-elements'),
        'class'                   => 'aux-widget-accordion widget-toggle',
        'show_settings_on_create' => true,
        'weight'                  => 1,
        'is_widget'               => true,
        'is_shortcode'            => true,
        'is_so'                   => true,
        'is_vc'                   => false,
        'category'                => THEME_NAME,
        'group'                   => '',
        'so_api'                  => true,
        'admin_enqueue_js'        => '',
        'admin_enqueue_css'       => '',
        'front_enqueue_js'        => '',
        'front_enqueue_css'       => '',
        'icon'                    => 'aux-element aux-element-accordion',
        'custom_markup'           => '',
        'js_view'                 => '',
        'html_template'           => '',
        'deprecated'              => '',
        'content_element'         => '',
        'as_parent'               => '',
        'as_child'                => '',
        'params'                  => array(
            array(
                'heading'          => __('Title','auxin-elements'),
                'description'      => __('Accordion title, leave it empty if you don`t need title.', 'auxin-elements'),
                'param_name'       => 'title',
                'type'             => 'textfield',
                'value'            => __( 'Accordion Title', 'auxin-elements' ),
                'holder'           => 'textfield',
                'class'            => 'title',
                'admin_label'      => true,
                'dependency'       => '',
                'weight'           => '',
                'group'            => '' ,
                'edit_field_class' => ''
            ),
            array(
                'heading'          => __('Type','auxin-elements'),
                'description'      => __('Whether to show only 1 element opens at a time or multiple.','auxin-elements'),
                'param_name'       => 'type',
                'type'             => 'dropdown',
                'def_value'        => 'true',
                'value'            => array(
                    'false'     => __('Toggle', 'auxin-elements'),
                    'true'      => __('Accordion', 'auxin-elements'),
                ),
                'holder'           => 'dropdown',
                'class'            => 'type',
                'admin_label'      => true,
                'dependency'       => '',
                'weight'           => '',
                'group'            => '' ,
                'edit_field_class' => ''
            ),
            array(
                'heading'          => __('Accordion label','auxin-elements'),
                'description'      => __('Enter your accordion item label.', 'auxin-elements'),
                'repeater'         => 'accordion',
                'repeater-label'   => __('Accordion', 'auxin-elements'),
                'section-name'     => __('Accordion Section', 'auxin-elements'),
                'param_name'       => 'accordion_label',
                'type'             => 'textfield',
                'value'            => '',
                'holder'           => 'textfield',
                'class'            => 'accordion_label',
                'admin_label'      => true,
                'dependency'       => '',
                'weight'           => '',
                'group'            => '' ,
                'edit_field_class' => ''
            ),
             array(
                'heading'          => __('Content', 'auxin-elements'),
                'description'      => __('Enter your accordion item content.', 'auxin-elements'),
                'repeater'         => 'accordion',
                'repeater-label'   => __('Accordion', 'auxin-elements'),
                'section-name'     => __('Accordion Section', 'auxin-elements'),
                'param_name'       => 'content',
                'type'             => 'textarea_html',
                'value'            => '',
                'def_value'        => '',
                'holder'           => 'div',
                'class'            => 'content',
                'admin_label'      => true,
                'dependency'       => '',
                'weight'           => '',
                'group'            => '',
                'edit_field_class' => ''
            ),
            array(
                'heading'          => __('Extra class name','auxin-elements'),
                'description'      => __('If you wish to style particular content element differently, then use this field to add a class name and then refer to it in your css file.', 'auxin-elements'),
                'param_name'       => 'extra_classes',
                'type'             => 'textfield',
                'value'            => '',
                'def_value'        => '',
                'holder'           => 'textfield',
                'class'            => 'extra_classes',
                'admin_label'      => true,
                'dependency'       => '',
                'weight'           => '',
                'group'            => '' ,
                'edit_field_class' => ''
            )
        )
    );

    return $master_array;
}

add_filter( 'auxin_master_array_shortcodes', 'auxin_get_new_accordion_master_array', 10, 1 );


/**
 * Element without loop and column
 * The front-end output of this element is returned by the following function
 *
 * @param  array  $atts              The array containing the parsed values from shortcode, it should be same as defined params above.
 * @param  string $shortcode_content The shorcode content
 * @return string                    The output of element markup
 */
function auxin_widget_accordion_callback( $atts, $shortcode_content = null ){

    // Defining default attributes
    $default_atts = array(
        'title'           => '', // header title
        'type'            => 'true', // accordion/toggle
        'accordion'       => '', // accordion/toggle
        'extra_classes'   => '', // custom css class names for this element
        'custom_el_id'    => '', // custom id attribute for this element
        'base_class'      => 'aux-widget-accordion widget-toggle'  // base class name for container
    );

    $result = auxin_get_widget_scafold( $atts, $default_atts, $shortcode_content );
    extract( $result['parsed_atts'] );

    // widget header ------------------------------
    $output  = $result['widget_header'];
    $output .= $result['widget_title'];
    $output .= '<div class="widget-inner ' .$extra_classes . '" data-toggle="' . $type . '">';

    // widget custom output -----------------------
    if (is_array($accordion) || is_object($accordion)) {
        foreach ( $accordion as $key => $value ) {


                $output .= '<section>';
                $section_title =  $value['accordion_label'];
                $section_content =  $value['content'];
                $output .= '<h6 class="toggle-header">' . $section_title . '</h6>';
                $output .= '<div class="toggle-content"><p>' . $section_content . '</p></div>';
                $output .= '</section>';
        }
    }

    $output .= '</div>'; // End od widget-toggle
    $output .= $result['widget_footer'];

    // widget footer ------------------------------

    return $output;
}
