<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
$icerik_id      = (int) $satir->id;
$ist            = tilfy_icerik_istatistik_al( $icerik_id );
$ist_satir      = $ist[0] ?? null;
$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 ), 10 );
$aciklama_temiz = wp_strip_all_tags( $satir->aciklama );
$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' ) );
$medya_grup_k   = function_exists( 'tilfy_icerik_medya_grup' ) ? tilfy_icerik_medya_grup( $satir->medya_tipi ) : 'video';
$ikon_kaynak    = function_exists( 'tilfy_platform_ikon_ad' ) ? tilfy_platform_ikon_ad( $satir->kaynak_platform ) : '';
$wp_kaynak      = sanitize_key( (string) $satir->kaynak_platform ) === 'wordpress';
?>
<tr
	class="tilfy-icerik-satir 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 ); ?>"
>
	<td class="tilfy-col-check"><input type="checkbox" class="tilfy-icerik-sec" name="icerik_idler[]" value="<?php echo (int) $icerik_id; ?>" /></td>
	<td class="tilfy-icerik-liste-gorsel-hucre">
		<div class="tilfy-icerik-liste-gorsel">
			<?php if ( $kapak ) : ?>
				<img class="tilfy-icerik-liste-onizleme" src="<?php echo esc_url( $kapak ); ?>" alt="" loading="lazy" decoding="async" />
			<?php else : ?>
				<div class="tilfy-icerik-liste-onizleme tilfy-icerik-liste-onizleme--bos" aria-hidden="true"></div>
			<?php endif; ?>
			<?php if ( $ikon_kaynak !== '' ) : ?>
				<?php tilfy_ikon_img_e( $ikon_kaynak, array( 'class' => 'tilfy-icerik-liste-platform-ikon', 'alt' => tilfy_platform_etiket( $satir->kaynak_platform ), 'title' => tilfy_platform_etiket( $satir->kaynak_platform ) ) ); ?>
			<?php else : ?>
				<span class="tilfy-rozet tilfy-rozet--<?php echo esc_attr( $satir->kaynak_platform ); ?> tilfy-icerik-liste-platform-yazi"><?php echo esc_html( tilfy_platform_etiket( $satir->kaynak_platform ) ); ?></span>
			<?php endif; ?>
		</div>
	</td>
	<td class="tilfy-icerik-liste-metin-hucre">
		<div class="tilfy-yinelenen-filigran tilfy-yinelenen-filigran--liste">
			<span class="tilfy-yinelenen-filigran__metin"></span>
		</div>
		<div class="tilfy-icerik-liste-metin">
			<strong class="tilfy-icerik-liste-baslik"><?php echo esc_html( $baslik_goster ); ?></strong>
			<?php if ( $tarih_goster ) : ?>
				<small class="tilfy-icerik-tarih"><?php echo esc_html( mysql2date( 'd.m.Y H:i', $tarih_goster ) ); ?></small>
			<?php endif; ?>
			<?php if ( $ist_satir ) : ?>
				<small class="tilfy-icerik-liste-istatistik" title="<?php echo esc_attr( tilfy__( 'Kaynak platformdan senkronlanan istatistikler' ) ); ?>">
					<?php echo (int) $ist_satir->goruntulenme; ?> <?php echo esc_html( tilfy__( 'gör. ·' ) ); ?> <?php echo (int) $ist_satir->begeni; ?> <?php echo esc_html( tilfy__( 'beğ. ·' ) ); ?> <?php echo (int) $ist_satir->yorum; ?> yrm.
				</small>
			<?php endif; ?>
		</div>
	</td>
	<td class="tilfy-icerik-liste-paylasim-hucre">
		<?php if ( empty( $hedefler ) ) : ?>
			<em class="tilfy-paylasim-yok"><?php echo esc_html( tilfy__( '-' ) ); ?></em>
		<?php else : ?>
			<div class="tilfy-icerik-liste-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-icerik-liste-hedef-ikon', 'alt' => tilfy_platform_etiket( $hedef_pl ), 'title' => tilfy_platform_etiket( $hedef_pl ) . ' paylaşıldı' ) );
					}
				endforeach; ?>
			</div>
		<?php endif; ?>
	</td>
	<td class="tilfy-icerik-liste-aksiyon-hucre">
		<div class="tilfy-icerik-liste-aksiyonlar">
			<button type="button" class="tilfy-icerik-liste-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-icerik-liste-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-icerik-liste-aksiyon-ikon', 'alt' => '' ) ); ?>
			</button>
			<a class="tilfy-icerik-liste-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-icerik-liste-aksiyon-ikon', 'alt' => '' ) ); ?>
			</a>
			<button type="button" class="tilfy-icerik-liste-aksiyon tilfy-icerik-medya-ata" data-icerik-id="<?php echo (int) $icerik_id; ?>" title="<?php echo esc_attr( tilfy__( 'Medya dosyası seç (WordPress medya kütüphanesi)' ) ); ?>" aria-label="<?php echo esc_attr( tilfy__( 'Medya dosyası seç' ) ); ?>"><?php echo esc_html( tilfy__( '▶' ) ); ?></button>
			<?php if ( $kapak && $wp_kaynak ) : ?>
				<button type="button" class="tilfy-icerik-liste-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-icerik-liste-aksiyon tilfy-icerik-liste-aksiyon--gizle 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>
	</td>
</tr>
