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

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

        echo '<div class="col-sm-12">';
        echo '<div class="th-image-gallery">';

        if ( ! empty ( $options['ig_title'] ) ) {
            echo '<div class="row">';
            echo '<div class="col-sm-12">';
            echo '<h4 class="smallm_title centered bigger"><span>' . $options['ig_title'] . '</span></h4>';
            echo '</div>';
            echo '</div>';
        }

        if ( ! empty ( $options['single_ig'] ) && is_array( $options['single_ig'] ) )
        {
            $count = count( $options['single_ig'] );
            $i     = 1;
            foreach ( $options['single_ig'] as $image_arr )
            {
                if ( $i % 3 == 1 ) {
                    echo '<div class="row">';
                }
                if ( ! empty ( $image_arr['sig_image'] ) ) {
                    $image = vt_resize( '', $image_arr['sig_image'], $element_size['width'], '', true );

                    echo '<div class="col-sm-4">';
                    echo '<a href="' . $image_arr['sig_image'] .
                        '" class="hoverBorder" data-lightbox="image"><img src="' . $image['url'] . '" width="' .
                        $image['width'] . '" height="' . $image['height'] . '" alt=""></a>';
                    echo '</div>';
                }

                if ( $i % 3 == 0 || $i == $count ) {
                    echo '</div>';
                }
                $i ++;
            }
        }
        echo '</div>';
        echo '</div>';
        echo '<div class="clear"></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()
    {
        $extra_options = array (
            "name"           => __( "Images", 'zn_framework' ),
            "description"    => __( "Here you can add your desired images.", 'zn_framework' ),
            "id"             => "single_ig",
            "std"            => "",
            "type"           => "group",
            "add_text"       => __( "Image", 'zn_framework' ),
            "remove_text"    => __( "Image", 'zn_framework' ),
            "group_title"    => "",
            "group_sortable" => true,
            "subelements"    => array (
                array (
                    "name"        => __( "Image", 'zn_framework' ),
                    "description" => __( "Please select an image.", 'zn_framework' ),
                    "id"          => "sig_image",
                    "std"         => "",
                    "type"        => "media"
                )
            )
        );
        return array (
                array (
                    "name"        => __( "Title", 'zn_framework' ),
                    "description" => __( "Please enter a title for this gallery.", 'zn_framework' ),
                    "id"          => "ig_title",
                    "std"         => "",
                    "type"        => "text",
                ),
                $extra_options,
        );
    }
}
