<?php if(! defined('ABSPATH')){ return; }
/*
 Name: Info Box
 Description: Create and display an Info Box element
 Class: TH_InfoBox
 Category: content
 Level: 3
*/
/**
 * Class TH_InfoBox
 *
 * Create and display an Info Box element
 *
 * @package  Kallyas
 * @category Page Builder
 * @author Team Hogash
 * @since 3.8.0
 */
class TH_InfoBox extends ZnElements
{
    public static function getName(){
        return __( "Info Box", 'zn_framework' );
    }

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

        if( empty( $options['ib_style'] ) ){
            $options['ib_style'] = 'style1';
        }

        // Only for style 3
        $isStyle3 = ((isset($options['ib_style']) && !empty($options['ib_style'])) && ('infobox3' == $options['ib_style']));
        $style3Style = $link1 = $link2 = '';
        if($isStyle3){
            $bgColor = (isset($options['ib_bgcolor']) && !empty($options['ib_bgcolor']) ? $options['ib_bgcolor'] : '');
            $bgImage = (isset($options['ib_bgimage']) && !empty($options['ib_bgimage']) ? $options['ib_bgimage'] : '');
            if(!empty($bgColor) || !empty($bgImage)){
                $style3Style = 'style="';
                if(!empty($bgColor)){ $style3Style .= 'background-color: '.$bgColor.';';}

                if( !empty( $bgImage['image'] ) ) { $style3Style .= 'background-image: url('.$bgImage['image'].');'; }
                if( !empty( $bgImage['repeat'] ) ) { $style3Style .= 'background-repeat:'.$bgImage['repeat'].';'; }
                if( !empty( $bgImage['size'] ) ) { $style3Style .= 'background-size:'.$bgImage['size'].';'; }
                if( !empty( $bgImage['position'] ) ) { $style3Style .= 'background-position:'.$bgImage['position']['x'].' '.$bgImage['position']['y'].';'; }
                if( !empty( $bgImage['attachment'] ) ) { $style3Style .= 'background-attachment:'.$bgImage['attachment'].';'; }

                $style3Style .= '"';
            }
            // LINK 2
            $link2 = '';
            if ( ! empty ( $options['ib_button_text2'] ) && ! empty ( $options['ib_button_link']['url'] ) ) {
                $link2 = '<a href="' . $options['ib_button_link2']['url'] . '" target="' .
                         $options['ib_button_link2']['target'] . '" class="ib-button2 btn btn-fullcolor">' .
                         $options['ib_button_text2'] .'</a>';
            }
        }

        // LINK
        $link = '';
        if ( ! empty ( $options['ib_button_text'] ) && ! empty ( $options['ib_button_link']['url'] ) ) {
            $link = '<a href="' . $options['ib_button_link']['url'] . '" target="' .$options['ib_button_link']['target'] .
                    '" class="btn btn-lg btn-fullcolor">' . $options['ib_button_text'] . '</a>';
            if($isStyle3)
            {
                $link1 = '<a href="' . $options['ib_button_link']['url'] . '" target="'
                         .$options['ib_button_link']['target'] .
                         '" class="ib-button-1 btn btn-lined">' . $options['ib_button_text'] . '</a>';
            }
        }

        // If the button does not exists
        $useColCustom = 'col-lg-12';

        if(!empty($options['ib_button_text']) && ($options['ib_style'] == 'infobox2') && !empty($link)){
            $useColCustom = 'col-lg-8';
        }
        else {
            if ( $options['ib_style'] == 'infobox1' ) {
                $useColCustom = 'col-lg-12';
            }
        }


        echo '<div class="' . $options['ib_style'] . '" '.$style3Style.'>';
        echo '<div class="row">';
        echo '<div class="ib-content infobox3--'.$this->opt('ib_theme_color', 'dark').' col-sm-12 '.$useColCustom.'">';
        // TITLE
        if ( ! empty ( $options['ib_title'] ) ) {
            echo '<h3 class="ib-content__title m_title">' . $options['ib_title'] . '</h3>';
        }

        // SUBTITLE
        if ( ! empty ( $options['ib_subtitle'] ) ) {
            echo wpautop($options['ib_subtitle']);
        }

        // Link button: style 1
        if (!empty($options['ib_style']) && ( $options['ib_style'] == 'infobox1' ) && !empty($link)) {
            echo '<div class="ib-button">';
            echo $link;
            echo '</div>';
        }
        // Link button: style 3
        elseif($isStyle3){
            // Button 1
            if(! empty($link)){
                echo '<div class="ib-button ib-button-1">';
                echo $link1;
                echo '</div>';
            }
            // Button 2
            if(! empty($link2)){
                echo '<div class="ib-button ib-button-2">';
                echo $link2;
                echo '</div>';
            }
        }

        echo '</div>'; // End .ib-content

        // Link button: style 2
        if ( !empty($options['ib_style']) && ( $options['ib_style'] == 'infobox2' ) && !empty($link)) {
            echo '<div class="ib-button col-sm-12 col-lg-4">';
            echo $link;
            echo '</div>';
        }

        echo '</div>'; // End .row

        echo '</div>'; //  end .$options['ib_style']


    }

    /**
     * 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"        => __( "Title", 'zn_framework' ),
                    "description" => __( "Please enter the Info Box title", 'zn_framework' ),
                    "id"          => "ib_title",
                    "std"         => "",
                    "type"        => "text",
                ),
                array (
                    "name"        => __( "Subtitle", 'zn_framework' ),
                    "description" => __( "Please enter the Info Box subtitle", 'zn_framework' ),
                    "id"          => "ib_subtitle",
                    "std"         => "",
                    "type"        => "text",
                ),
                array (
                    "name"        => __( "Select style", 'zn_framework' ),
                    "description" => __( "Select the desired style for this element", 'zn_framework' ),
                    "id"          => "ib_style",
                    "type"        => "select",
                    "std"         => "style1",
                    "options"     => array (
                        'infobox1' => __( 'Style 1', 'zn_framework' ),
                        'infobox2' => __( 'Style 2', 'zn_framework' ),
                        'infobox3' => __( 'Style 3', 'zn_framework' ),
                    ),
                ),

                array (
                    "name"        => __( "Text color scheme", 'zn_framework' ),
                    "description" => __( "Select the desired style for this element", 'zn_framework' ),
                    "id"          => "ib_theme_color",
                    "type"        => "select",
                    "std"         => "dark",
                    "options"     => array (
                        'dark' => __( 'Dark text color', 'zn_framework' ),
                        'light' => __( 'Light text color', 'zn_framework' ),
                    ),
                    // 'dependency'  => array( 'element' => 'ib_style', 'value'   => array('infobox3'), ),
                ),

                array (
                    "name"        => __( "Select background color", 'zn_framework' ),
                    "description" => __( "Select a color to apply as background color.", 'zn_framework' ),
                    "id"          => "ib_bgcolor",
                    "std"         => "#eee",
                    "type"        => "colorpicker",
                    'dependency'  => array( 'element' => 'ib_style', 'value'   => array('infobox3'), ),
                ),
                array (
                    "name"        => __( "Select background image", 'zn_framework' ),
                    "description" => __( "Please select an image to use as background image.", 'zn_framework' ),
                    "id"          => "ib_bgimage",
                    "std"         => "",
                    "type"        => "background",
                    'class'       => 'zn_full',
                    'options' => array( "repeat" => true , "position" => true , "attachment" => true, "size" => true ),
                    'dependency'  => array( 'element' => 'ib_style', 'value'   => array('infobox3'), ),
                ),
                array (
                    "name"        => __( "Button 2 text", 'zn_framework' ),
                    "description" => __( "Please enter a text that will appear as button", 'zn_framework' ),
                    "id"          => "ib_button_text2",
                    "std"         => "",
                    "type"        => "text",
                    'dependency'  => array( 'element' => 'ib_style', 'value'   => array('infobox3'), ),
                ),
                array (
                    "name"        => __( "Button 2 link", 'zn_framework' ),
                    "description" => __( "Please choose the link you want to use.", 'zn_framework' ),
                    "id"          => "ib_button_link2",
                    "std"         => "",
                    "type"        => "link",
                    "options"     => array (
                        '_blank' => __( "New window", 'zn_framework' ),
                        '_self'  => __( "Same window", 'zn_framework' )
                    ),
                    'dependency'  => array( 'element' => 'ib_style', 'value'   => array('infobox3'), ),
                ),

                array (
                    "name"        => __( "Button text", 'zn_framework' ),
                    "description" => __( "Please enter a text that will appear as button", 'zn_framework' ),
                    "id"          => "ib_button_text",
                    "std"         => "",
                    "type"        => "text",
                ),
                array (
                    "name"        => __( "Button link", 'zn_framework' ),
                    "description" => __( "Please choose the link you want to use.", 'zn_framework' ),
                    "id"          => "ib_button_link",
                    "std"         => "",
                    "type"        => "link",
                    "options"     => array (
                        '_blank' => __( "New window", 'zn_framework' ),
                        '_self'  => __( "Same window", 'zn_framework' )
                    )
                ),
        );
    }
}
