<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
$icerik_id      = (int) $satir->id;
$hedefler       = $paylasim_etiket[ $icerik_id ] ?? array();
$tarih_goster   = ! empty( $satir->kaynak_tarihi ) ? $satir->kaynak_tarihi : $satir->olusturulma;
$baslik_goster  = $satir->baslik ?: wp_trim_words( wp_strip_all_tags( $satir->aciklama ), 12, '…' );
$aciklama_temiz = wp_strip_all_tags( $satir->aciklama );
$medya_grup_k   = function_exists( 'tilfy_icerik_medya_grup' ) ? tilfy_icerik_medya_grup( $satir->medya_tipi ) : 'video';
$medya_etiket   = function_exists( 'tilfy_icerik_medya_grup_etiket' ) ? tilfy_icerik_medya_grup_etiket( $satir->medya_tipi ) : 'Video';
$kapak          = function_exists( 'tilfy_icerik_kapak_url_al' ) ? tilfy_icerik_kapak_url_al( $satir ) : ( $satir->kapak_url ?: $satir->medya_url );
$studyosu_url   = add_query_arg( array( 'page' => 'tilfy-studyosu', 'icerik_id' => $icerik_id ), admin_url( 'admin.php' ) );
$ikon_kaynak    = function_exists( 'tilfy_platform_ikon_ad' ) ? tilfy_platform_ikon_ad( $satir->kaynak_platform ) : '';
?>
<article
	class="tilfy-grid-kart tilfy-icerik-oge"
	data-icerik-id="<?php echo esc_attr( (string) $icerik_id ); ?>"
	data-kaynak="<?php echo esc_attr( $satir->kaynak_platform ); ?>"
	data-medya-grup="<?php echo esc_attr( $medya_grup_k ); ?>"
	data-sync="<?php echo esc_attr( implode( ',', $hedefler ) ); ?>"
	data-baslik="<?php echo esc_attr( $baslik_goster ); ?>"
	data-aciklama="<?php echo esc_attr( $aciklama_temiz ); ?>"
	data-kapak="<?php echo esc_url( $kapak ); ?>"
	data-medya="<?php echo esc_attr( $satir->medya_tipi ); ?>"
	data-tarih="<?php echo esc_attr( $tarih_goster ? mysql2date( 'd.m.Y H:i', $tarih_goster ) : '' ); ?>"
	data-studyosu="<?php echo esc_url( $studyosu_url ); ?>"
>
	<div class="tilfy-grid-kart__cerceve" role="button" tabindex="0" aria-pressed="false">
		<?php if ( $kapak ) : ?>
			<img class="tilfy-grid-kart__gorsel" src="<?php echo esc_url( $kapak ); ?>" alt="" loading="lazy" decoding="async" />
		<?php else : ?>
			<div class="tilfy-grid-kart__bos-gorsel"></div>
		<?php endif; ?>
		<div class="tilfy-grid-kart__overlay" aria-hidden="true"></div>
		<div class="tilfy-grid-kart__sec-overlay" aria-hidden="true"></div>
		<div class="tilfy-yinelenen-filigran" hidden>
			<span class="tilfy-yinelenen-filigran__baslik"><?php echo esc_html( tilfy__( 'Yinelenen' ) ); ?></span>
			<span class="tilfy-yinelenen-filigran__metin"></span>
		</div>
		<div class="tilfy-grid-kart__ust">
			<?php if ( $ikon_kaynak !== '' ) : ?>
				<?php tilfy_ikon_img_e( $ikon_kaynak, array( 'class' => 'tilfy-grid-kart__platform-ikon', 'alt' => tilfy_platform_etiket( $satir->kaynak_platform ) ) ); ?>
			<?php else : ?>
				<span class="tilfy-rozet tilfy-rozet--<?php echo esc_attr( $satir->kaynak_platform ); ?> tilfy-grid-kart__platform-yazi"><?php echo esc_html( tilfy_platform_etiket( $satir->kaynak_platform ) ); ?></span>
			<?php endif; ?>
			<?php if ( ! empty( $hedefler ) ) : ?>
				<div class="tilfy-grid-kart__paylasimlar">
					<?php foreach ( $hedefler as $hedef_pl ) :
						$ikon_hedef = function_exists( 'tilfy_platform_ikon_ad' ) ? tilfy_platform_ikon_ad( $hedef_pl ) : '';
						if ( $ikon_hedef !== '' ) {
							tilfy_ikon_img_e( $ikon_hedef, array( 'class' => 'tilfy-grid-kart__hedef-ikon', 'alt' => tilfy_platform_etiket( $hedef_pl ), 'title' => tilfy_platform_etiket( $hedef_pl ) ) );
						}
					endforeach; ?>
				</div>
			<?php endif; ?>
		</div>
		<div class="tilfy-grid-kart__alt-sol">
			<?php if ( $tarih_goster ) : ?><span class="tilfy-grid-kart__tarih"><?php echo esc_html( mysql2date( 'd.m.Y', $tarih_goster ) ); ?></span><?php endif; ?>
			<span class="tilfy-grid-kart__tur"><?php echo esc_html( $medya_etiket ); ?></span>
		</div>
		<div class="tilfy-grid-kart__alt-sag">
			<button type="button" class="tilfy-grid-kart__aksiyon tilfy-icerik-detay-ac" data-icerik-id="<?php echo (int) $icerik_id; ?>" title="<?php echo esc_attr( tilfy__( 'Detay' ) ); ?>" aria-label="<?php echo esc_attr( tilfy__( 'Detay' ) ); ?>"><?php echo esc_html( tilfy__( 'i' ) ); ?></button>
			<button type="button" class="tilfy-grid-kart__aksiyon tilfy-sepet-ekle" title="<?php echo esc_attr( tilfy__( 'Sepete ekle' ) ); ?>" aria-label="<?php echo esc_attr( tilfy__( 'Sepete ekle' ) ); ?>">
				<?php tilfy_ikon_img_e( 'ekle', array( 'class' => 'tilfy-grid-kart__aksiyon-ikon', 'alt' => '' ) ); ?>
			</button>
			<a class="tilfy-grid-kart__aksiyon" href="<?php echo esc_url( $studyosu_url ); ?>" title="<?php echo esc_attr( tilfy__( 'Studyoda aç' ) ); ?>" aria-label="<?php echo esc_attr( tilfy__( 'Studyoda aç' ) ); ?>">
				<?php tilfy_ikon_img_e( 'studyoda-ac', array( 'class' => 'tilfy-grid-kart__aksiyon-ikon', 'alt' => '' ) ); ?>
			</a>
			<button type="button" class="tilfy-grid-kart__aksiyon tilfy-icerik-medya-ata" data-icerik-id="<?php echo (int) $icerik_id; ?>" title="<?php echo esc_attr( tilfy__( 'Yeni ekle' ) ); ?>" aria-label="<?php echo esc_attr( tilfy__( 'Yeni ekle' ) ); ?>"><?php echo esc_html( tilfy__( '▶' ) ); ?></button>
			<?php if ( $kapak && sanitize_key( (string) $satir->kaynak_platform ) === 'wordpress' ) : ?>
				<button type="button" class="tilfy-grid-kart__aksiyon tilfy-icerik-one-cikan" data-icerik-id="<?php echo (int) $icerik_id; ?>" title="<?php echo esc_attr( tilfy__( 'Öne çıkanı kullan' ) ); ?>" aria-label="<?php echo esc_attr( tilfy__( 'Öne çıkanı kullan' ) ); ?>">WP</button>
			<?php endif; ?>
			<button type="button" class="tilfy-grid-kart__aksiyon tilfy-icerik-gizle" title="<?php echo esc_attr( tilfy__( 'Listeden gizle' ) ); ?>" aria-label="<?php echo esc_attr( tilfy__( 'Listeden gizle' ) ); ?>"><?php echo esc_html( tilfy__( '×' ) ); ?></button>
		</div>
		<?php if ( $baslik_goster || $aciklama_temiz ) : ?>
			<div class="tilfy-grid-kart__ipucu">
				<?php if ( $baslik_goster ) : ?><strong><?php echo esc_html( $baslik_goster ); ?></strong><?php endif; ?>
				<?php if ( $aciklama_temiz ) : ?><p><?php echo esc_html( wp_trim_words( $aciklama_temiz, 40, '…' ) ); ?></p><?php endif; ?>
			</div>
		<?php endif; ?>
	</div>
</article>
