<?php if(! defined('ABSPATH')){ return; }
/*
 Name: Text Box
 Description: Create and display a Text Box element
 Class: TH_TextBox
 Category: content
 Level: 3
*/

/**
 * Class TH_TextBox
 *
 * Create and display a Text Box element
 *
 * @package  Kallyas
 * @category Page Builder
 * @author   Team Hogash
 * @since    4.0.0
 */
class TH_TextBox extends ZnElements
{
    public static function getName(){
        return __( "Text Box", 'zn_framework' );
    }

    /**
     * Output the inline css to head or after the element in case it is loaded via ajax
     */
    function css(){

        //print_z($this);
        $uid = $this->data['uid'];
        $css = '';

        $top_padding = $this->opt('top_padding');
        if($top_padding != '0'){
            $tpadding = $top_padding || $top_padding === '0' ? 'padding-top : '.$top_padding.'px;' : '';
            $css .= '.'.$uid.'{'.$tpadding.'}';
        }

        $bottom_padding = $this->opt('bottom_padding');
        if($bottom_padding != '20'){
            $bpadding = $bottom_padding || $bottom_padding === '0' ? 'padding-bottom:'.$bottom_padding.'px;' : '';
            $css .= '.'.$uid.'{'.$bpadding.'}';
        }

        return $css;
    }
    /**
     * This method is used to display the output of the element.
     * @return void
     */
    function element()
    {
        $options = $this->data['options'];

        if( empty( $options ) ) { return; }

        echo '<div class="zn_text_box '.$this->data['uid'].'">';


        $style = !empty( $options['stb_style'] ) ? $options['stb_style'] : '';
        if ( ! empty( $options['stb_title'] )  ) {
            echo '<h3 class="zn_text_box-title zn_text_box-title--'.$style.'">' . $options['stb_title'] . '</h3>';
        }

        $stb_content = $this->opt('stb_content','');

        $content = wpautop( $stb_content );

        if ( ! empty ( $stb_content ) ) {
                echo $content;
        }
        echo '</div>';
    }

    /**
     * This method is used to retrieve the configurable options of the element.
     * @return array The list of options that compose the element and then passed as the argument for the render() function
     */
    function options()
    {
        return array (
            'has_tabs'  => true,
            'general' => array(
                'title' => 'Content',
                'options' => array(
                    array (
                        "name"        => __( "Content", 'zn_framework' ),
                        "description" => __( "Please enter the box content", 'zn_framework' ),
                        "id"          => "stb_content",
                        "std"         => "",
                        "type"        => "visual_editor",
                        "class"        => "zn_full",
                    ),
                )
            ),
            'title' => array(
                'title' => 'Title settings',
                'options' => array(
                    array (
                        "name"        => __( "Title", 'zn_framework' ),
                        "description" => __( "Please enter the title for this box", 'zn_framework' ),
                        "id"          => "stb_title",
                        "std"         => "",
                        "type"        => "text",
                    ),
                    array (
                        "name"        => __( "Title style", 'zn_framework' ),
                        "description" => __( "Select the desired style for the title of this
                                            box", 'zn_framework' ),
                        "id"          => "stb_style",
                        "type"        => "select",
                        "std"         => "style1",
                        "options"     => array (
                            'style1' => __( 'Style 1', 'zn_framework' ),
                            'style2' => __( 'Style 2', 'zn_framework' )
                        ),
                        'live' => array(
                           'type'        => 'class',
                           'css_class' => '.'.$this->data['uid'].' .zn_text_box-title',
                           'val_prepend'   => 'zn_text_box-title--',
                        )
                    ),
                )
            ),
            'padding' => array(
                'title' => 'Padding options',
                'options' => array(

                    array(
                        'id'          => 'top_padding',
                        'name'        => 'Top padding',
                        'description' => 'Select the top padding ( in pixels ) for this section.',
                        'type'        => 'slider',
                        'std'         => '0',
                        'class'       => 'zn_full',
                        'helpers'     => array(
                            'min' => '0',
                            'max' => '400',
                            'step' => '5'
                        ),
                        'live' => array(
                            'type'      => 'css',
                            'css_class' => '.'.$this->data['uid'],
                            'css_rule'  => 'padding-top',
                            'unit'      => 'px'
                        )
                    ),
                    array(
                        'id'          => 'bottom_padding',
                        'name'        => 'Bottom padding',
                        'description' => 'Select the bottom padding ( in pixels ) for this section.',
                        'type'        => 'slider',
                        'std'         => '20',
                        'class'       => 'zn_full',
                        'helpers'     => array(
                            'min' => '0',
                            'max' => '400',
                            'step' => '5'
                        ),
                        'live' => array(
                            'type'      => 'css',
                            'css_class' => '.'.$this->data['uid'],
                            'css_rule'  => 'padding-bottom',
                            'unit'      => 'px'
                        )
                    )
                )
            )
        );
    }
}
