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

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

        <div class="shop-features">
            <div class="row">
                <?php
                    if ( ! empty ( $options['sf_title'] ) ) {
                        echo '<div class="col-sm-3">';
                        echo '<h3 class="title">' . $options['sf_title'] . '</h3>';
                        echo '</div>';
                    }
                    if ( isset ( $options['sf_single'] ) && is_array( $options['sf_single'] ) ) {
                        foreach ( $options['sf_single'] as $single ) {
                            echo '<div class="col-sm-3">';
                            $link_start = '';
                            $link_end   = '';

                            if ( ! empty ( $single['lp_link']['url'] ) ) {
                                $link_start = '<a href="' . $single['lp_link']['url'] . '" target="' .
                                              $single['lp_link']['target'] . '">';
                                $link_end   = '</a>';
                            }


                            echo '<div class="shop-feature">';
                            if ( ! empty ( $single['lp_single_logo'] ) ) {
                                echo '<img src="' . $single['lp_single_logo'] . '" alt="">';
                            }

                            echo '<div class="sf-text">';
                            if ( ! empty ( $single['lp_single_line1'] ) ) {
                                echo '<h4>' . $single['lp_single_line1'] . '</h4>';
                            }

                            if ( ! empty ( $single['lp_single_line2'] ) ) {
                                echo '<h5>' . $single['lp_single_line2'] . '</h5>';
                            }
                            echo '</div>';
                            echo $link_start;
                            echo $link_end;
                            echo '</div><!-- end shop feature -->';

                            echo '</div>';
                        }
                    }
                ?>
            </div>
        </div>
    <?php
    }

    /**
     * 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()
    {
        $extra_options = array (
            "name"           => __( "Features", 'zn_framework' ),
            "description"    => __( "Here you can add your shop features.", 'zn_framework' ),
            "id"             => "sf_single",
            "std"            => "",
            "type"           => "group",
            "add_text"       => __( "Feature", 'zn_framework' ),
            "remove_text"    => __( "Feature", 'zn_framework' ),
            "group_sortable" => true,
            "subelements"    => array (
                array (
                    "name"        => __( "Icon", 'zn_framework' ),
                    "description" => __( "Please select an icon.", 'zn_framework' ),
                    "id"          => "lp_single_logo",
                    "std"         => "",
                    "type"        => "media"
                ),
                array (
                    "name"        => __( "Line 1 text", 'zn_framework' ),
                    "description" => __( "Please enter a text that will appear on the first line.", 'zn_framework' ),
                    "id"          => "lp_single_line1",
                    "std"         => "",
                    "type"        => "text"
                ),
                array (
                    "name"        => __( "Line 2 text", 'zn_framework' ),
                    "description" => __( "Please enter a text that will appear on the second line.", 'zn_framework' ),
                    "id"          => "lp_single_line2",
                    "std"         => "",
                    "type"        => "text"
                ),
                array (
                    "name"        => __( "Feature Link", 'zn_framework' ),
                    "description" => __( "Please choose the link you want to use.", 'zn_framework' ),
                    "id"          => "lp_link",
                    "std"         => "",
                    "type"        => "link",
                    "options"     => array (
                        '_blank' => __( "New window", 'zn_framework' ),
                        '_self'  => __( "Same window", 'zn_framework' )
                    )
                ),
            )
        );
        return array (
                array (
                    "name"        => __( "Title", 'zn_framework' ),
                    "description" => __( "Please enter the title for this element.", 'zn_framework' ),
                    "id"          => "sf_title",
                    "std"         => "",
                    "type"        => "text",
                ),
                $extra_options,
        );
    }
}
