<?php
use Elementor\Utils;

if (!defined('ABSPATH')) {
    exit; // Exit if accessed directly
}

$has_link = false;

if (!empty($gallery['gallery_link']['url'])) {

    $has_link = true;

    $link_key = 'link_' . $index;

    $url = $gallery['gallery_link'];

    $widget_instance->add_render_attribute($link_key, 'title', $gallery['gallery_name']);

    $widget_instance->add_render_attribute($link_key, 'href', $url['url']);

    if (!empty($url['is_external'])) {
        $widget_instance->add_render_attribute($link_key, 'target', '_blank');
    }

    if (!empty($url['nofollow'])) {
        $widget_instance->add_render_attribute($link_key, 'rel', 'nofollow');
    }
}
?>

<div class="tfl-grid-item tfl-gallery-wrapper">

    <?php list($animate_class, $animation_attr) = tfl_get_animation_atts($gallery['widget_animation']); ?>

    <div class="tfl-gallery <?php echo $animate_class; ?>" <?php echo $animation_attr; ?>>

        <div class="tfl-image-wrapper">

            <?php if (!empty($gallery['gallery_image'])): ?>

                <?php $image_html = tfl_get_image_html($gallery['gallery_image'], 'thumbnail_size', $settings); ?>

                <?php if ($has_link): ?>

                    <a class="tfl-image-link" <?php echo $widget_instance->get_render_attribute_string($link_key); ?>><?php echo $image_html; ?></a>

                <?php else: ?>

                    <?php echo $image_html; ?>

                <?php endif; ?>

            <?php endif; ?>

            <?php tfl_get_template_part("addons/gallery/social-profile", $args); ?>

        </div>

        <div class="tfl-gallery-text">

            <?php $title_html = '<' . Utils::validate_html_tag($settings['title_tag']) . ' class="tfl-title">' . esc_html($gallery['gallery_name']) . '</' . Utils::validate_html_tag($settings['title_tag']) . '>'; ?>

            <?php if ($has_link): ?>

                <a class="tfl-title-link" <?php echo $widget_instance->get_render_attribute_string($link_key); ?>><?php echo $title_html; ?></a>

            <?php else: ?>

                <?php echo $title_html; ?>

            <?php endif; ?>

            <div class="tfl-gallery-position">

                <?php echo do_shortcode($gallery['gallery_position']); ?>

            </div>


        </div>

    </div>

</div>