<?php

use Elementor\Utils;

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

$has_link = false;

if (!empty($accordion['accordion_link']['url'])) {

    $has_link = true;

    $link_key = 'link_' . $index;

    $url = $accordion['accordion_link'];

    $widget_instance->add_render_attribute($link_key, 'title', $accordion['accordion_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');
    }
}
?>


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

<div class="tfl-accordion <?php echo $animate_class; ?>" <?php echo $animation_attr; ?>>
    <?php $title_html = '<' . Utils::validate_html_tag($settings['title_tag']) . ' class="tfl-title">' . esc_html($accordion['accordion_name']) . '<i class="fas fa-plus"></i></' . 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-accordion-content">
        <?php echo do_shortcode($accordion['short_text']); ?>
    </div>
</div>
