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

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

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

        $isCustom = false;
        $bgColor = $bgImage = '';
        if(isset($options['ib2_style']) && !empty($options['ib2_style']))
        {
            if('style1' == $options['ib2_style']){
                // If ever...
            }
            elseif('style2' == $options['ib2_style']){
                $isCustom = true;
                $bgColor = (isset($options['ib2_bgcolor']) && !empty($options['ib2_bgcolor'])) ? esc_attr($options['ib2_bgcolor']) : '';

            }
            elseif('style3' == $options['ib2_style']){
                $isCustom = true;
                $bgImage = (isset($options['ib2_bgimage']) && !empty($options['ib2_bgimage'])) ? $options['ib2_bgimage'] : '';
            }
        }

        // Style 2 && style 3
        if($isCustom)
        {
            $infoMessage = ((isset($options['ib2_info_message']) && !empty($options['ib2_info_message'])) ? esc_attr($options['ib2_info_message']) : '');
            $ibTitle = ((isset($options['ib2_title_text']) && !empty($options['ib2_title_text'])) ? esc_attr($options['ib2_title_text']) : '');
            $ibText = ((isset($options['ib2_title']) && !empty($options['ib2_title'])) ? $options['ib2_title'] : '');
            $ibTextColor = ((isset($options['ib2_text_color']) && !empty($options['ib2_text_color'])) ? esc_attr($options['ib2_text_color']) : '');
            $style = '';
            if($bgColor){
                $style = 'style="background-color:'.$bgColor.';"';
            }
            elseif($bgImage){
                $style = 'style="background-image:url('.$bgImage.');"';
            }
            ?>
            <div class="ib2-<?php echo $options['ib2_style'] . ' ' .$ibTextColor;?> ib2-custom" <?php echo $style;?>>
                <div class="ib2-inner">
                    <h4 class="ib2-info-message"><?php echo $infoMessage;?></h4>
                    <div class="ib2-content">
                        <h3 class="ib2-content--title"><?php echo $ibTitle;?></h3>
                        <div class="ib2-content--text"><?php echo wpautop($ibText);?></div>
                    </div>
                </div>
            </div>
        <?php
        }
        else {
            if(isset($options['ib2_title'])){
                // if no subtitle nor description use full 12 column
                echo '<div class="info-text">';
                echo wpautop($options['ib2_title']);
                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 (
            array (
                "name"        => __( "Select style", 'zn_framework' ),
                "description" => __( "Select the desired style for this element", 'zn_framework' ),
                "id"          => "ib2_style",
                "type"        => "select",
                "std"         => "style1",
                "options"     => array (
                    'style1' => __( 'Style 1 (Default)', 'zn_framework' ),
                    'style2' => __( 'Style 2 (Background color)', 'zn_framework' ),
                    'style3' => __( 'Style 3 (background image)', 'zn_framework' ),
                ),
            ),

            array (
                "name"        => __( "Select background color", 'zn_framework' ),
                "description" => __( "Select a color to apply as background color.", 'zn_framework' ),
                "id"          => "ib2_bgcolor",
                "std"         => "#fff",
                "type"        => "colorpicker",
                'dependency'  => array( 'element' => 'ib2_style', 'value'   => array('style2') ),
            ),

            array (
                "name"        => __( "Select text color", 'zn_framework' ),
                "description" => __( "Select the desired color theme", 'zn_framework' ),
                "id"          => "ib2_text_color",
                "type"        => "select",
                "std"         => "light",
                "options"     => array (
                    'ib2-text-color-light-theme' => 'Light theme',
                    'ib2-text-color-dark-theme'  => 'Dark theme',
                ),
                'dependency'  => array( 'element' => 'ib2_style', 'value'   => array('style2','style3') ),
            ),
            array (
                "name"        => __( "Select background image", 'zn_framework' ),
                "description" => __( "Please select an image to use as background image.", 'zn_framework' ),
                "id"          => "ib2_bgimage",
                "std"         => "",
                "type"        => "media",
                'dependency'  => array( 'element' => 'ib2_style', 'value'   => array('style3') ),
            ),

            array (
                "name"        => __( "Info message", 'zn_framework' ),
                "description" => __( "Please enter the info message", 'zn_framework' ),
                "id"          => "ib2_info_message",
                "std"         => "",
                "type"        => "text",
                'dependency'  => array( 'element' => 'ib2_style', 'value'   => array('style2','style3') ),
            ),
            array (
                "name"        => __( "Title", 'zn_framework' ),
                "description" => __( "Please enter the title", 'zn_framework' ),
                "id"          => "ib2_title_text",
                "std"         => "",
                "type"        => "text",
                'dependency'  => array( 'element' => 'ib2_style', 'value'   => array('style2','style3') ),
            ),

            array (
                    "name"        => __( "Content", 'zn_framework' ),
                    "description" => __( "Please enter the content for this box", 'zn_framework' ),
                    "id"          => "ib2_title",
                    "std"         => "",
                    "type"        => "visual_editor",
                    'class'       => 'zn_full'
                )
        );
    }
}
