<?php
/**
 * Style 2 template.
 *
 * @link       https://dcatl.diviaccessories.com/
 * @since      1.0.0
 *
 * @package    WordPress
 * @subpackage display-category-and-taxonomy-list
 */

namespace DCATL\Template;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

$term_link = get_term_link( $term );
if ( is_wp_error( $term_link ) ) {
	return;
}

$image_id             = absint( get_term_meta( $term->term_id, 'dcatl_term_image', true ) );
$image_url            = $image_id && wp_attachment_is_image( $image_id ) ? wp_get_attachment_image_url( $image_id, 'full' ) : '';
$background_style     = $image_url ? 'background-image: url(' . esc_url( $image_url ) . ');' : '';
$hide_title           = ! empty( $settings['dcatl_hide_title'] );
$hide_divider         = ! empty( $settings['dcatl_hide_divider'] );
$hide_description     = ! empty( $settings['dcatl_hide_description'] );
$hide_button          = ! empty( $settings['dcatl_hide_button'] );
$hide_counter         = ! empty( $settings['dcatl_hide_counter'] );
$enable_image_overlay = ! empty( $settings['dcatl_enable_wrapper_overlay'] );
$box_shadow_class     = ! empty( $settings['dcatl_enable_wrapper_boxshadow_hover'] ) ? 'dcatl_enable_wrapper_shadow' : '';
?>
<li>
	<div class="dcatl-term-item <?php echo esc_attr( $box_shadow_class ); ?>"<?php echo $background_style ? ' style="' . esc_attr( $background_style ) . '"' : ''; ?>>
		<?php if ( ! $hide_counter ) { ?>
			<div class="dcatl-term-badge"><span><?php echo esc_html( number_format_i18n( $term->count ) ); ?></span></div>
		<?php } ?>

		<?php if ( ! $hide_title ) { ?>
			<div class="dcatl-term-title-wrapper">
				<h3 class="dcatl-term-title <?php echo esc_attr( $hide_divider ? 'dcatl-term-title-hide-divider' : '' ); ?>">
					<a href="<?php echo esc_url( $term_link ); ?>"><?php echo esc_html( $term->name ); ?></a>
				</h3>
			</div>
		<?php } ?>

		<?php if ( ! $hide_description && '' !== trim( $term->description ) ) { ?>
			<div class="dcatl-term-description">
				<p><?php echo esc_html( $term->description ); ?></p>
			</div>
		<?php } ?>

		<?php if ( ! $hide_button ) { ?>
			<div class="dcatl-term-button-wrapper">
				<a class="dcatl-term-button" href="<?php echo esc_url( $term_link ); ?>">
					<?php esc_html_e( 'Read More', 'display-category-and-taxonomy-list' ); ?>
				</a>
			</div>
		<?php } ?>

		<?php if ( $enable_image_overlay ) { ?>
			<div class="dcatl-color-overlay" aria-hidden="true"></div>
		<?php } ?>
	</div>
</li>
