<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
$durum_sinif  = sanitize_html_class( $p->durum );
$durum_yazi   = function_exists( 'tilfy_paylasim_durum_etiket' )
	? tilfy_paylasim_durum_etiket( $p->durum, $p->zamanlama ?? null )
	: ( $durum_etiket[ $p->durum ] ?? $p->durum );
$otomasyon_rozet = function_exists( 'tilfy_paylasim_kaynak_etiket' )
	? tilfy_paylasim_kaynak_etiket( $p->kaynak ?? 'manuel' )
	: '';
$baslik       = $p->baslik ?: wp_trim_words( wp_strip_all_tags( $p->aciklama ?? '' ), 10, '…' );
if ( $baslik === '' ) {
	$baslik = '#' . (int) $p->icerik_id;
}
$p_kapak      = function_exists( 'tilfy_icerik_kapak_url_al' ) ? tilfy_icerik_kapak_url_al( $p ) : ( $p->kapak_url ?: $p->medya_url );
$kapak        = $p_kapak;
$kaynak_url   = function_exists( 'tilfy_icerik_kaynak_url' ) ? tilfy_icerik_kaynak_url( $p ) : '';
$studyosu_url = add_query_arg( array( 'page' => 'tilfy-studyosu', 'icerik_id' => (int) $p->icerik_id ), admin_url( 'admin.php' ) );
$yeniden_goster = in_array( $p->durum, array( 'hata', 'beklemede', 'yukleniyor', 'zamanlandi', 'sirada' ), true );
$tekrar_goster  = in_array( $p->durum, array( 'hata', 'beklemede', 'yukleniyor', 'zamanlandi' ), true );
$manuel_tamam   = (string) $p->durum === 'manuel_bekliyor';
$wp_kaynak      = sanitize_key( (string) ( $p->kaynak_platform ?? '' ) ) === 'wordpress';
?>
<tr
	class="tilfy-paylasim-satir tilfy-paylasim-oge"
	data-paylasim-id="<?php echo (int) $p->id; ?>"
	data-durum="<?php echo esc_attr( $p->durum ); ?>"
	data-icerik="<?php echo esc_attr( $baslik ); ?>"
	data-hedef="<?php echo esc_attr( tilfy_platform_etiket( $p->hedef_platform ) ); ?>"
	data-guncelleme="<?php echo esc_attr( $p->guncelleme ); ?>"
>
	<td><input type="checkbox" class="tilfy-paylasim-sec" name="paylasim_idler[]" value="<?php echo (int) $p->id; ?>" /></td>
	<td>
		<div class="tilfy-paylasim-liste-icerik">
			<?php if ( $kapak ) : ?>
				<img class="tilfy-paylasim-onizleme" src="<?php echo esc_url( $kapak ); ?>" alt="" loading="lazy" decoding="async" />
			<?php endif; ?>
			<div class="tilfy-paylasim-liste-metin">
				<strong><?php echo esc_html( $baslik ); ?></strong>
				<small><?php echo esc_html( tilfy_platform_etiket( $p->kaynak_platform ?? '' ) ); ?> · #<?php echo (int) $p->icerik_id; ?></small>
			</div>
		</div>
	</td>
	<td><span class="tilfy-rozet tilfy-rozet--<?php echo esc_attr( $p->hedef_platform ); ?>"><?php echo esc_html( tilfy_platform_etiket( $p->hedef_platform ) ); ?></span></td>
	<td>
		<span class="tilfy-durum tilfy-durum--<?php echo esc_attr( $durum_sinif ); ?>"><?php echo esc_html( $durum_yazi ); ?></span>
		<?php if ( $otomasyon_rozet !== '' ) : ?>
			<br /><span class="tilfy-rozet tilfy-rozet--otomasyon"><?php echo esc_html( $otomasyon_rozet ); ?></span>
		<?php endif; ?>
		<?php if ( $p->hata_mesaji ) : ?>
			<br /><small class="tilfy-hata"><?php echo esc_html( $p->hata_mesaji ); ?></small>
		<?php endif; ?>
	</td>
	<td class="tilfy-paylasim-link-hucre">
		<?php if ( $kaynak_url ) : ?>
			<a class="tilfy-link" href="<?php echo esc_url( $kaynak_url ); ?>" target="_blank" rel="noopener noreferrer"><?php echo esc_html( tilfy__( 'Kaynak' ) ); ?></a>
		<?php endif; ?>
		<?php if ( $kaynak_url && $p->hedef_url ) : ?><span class="tilfy-paylasim-link-ayrac"><?php echo esc_html( tilfy__( '·' ) ); ?></span><?php endif; ?>
		<?php if ( $p->hedef_url ) : ?>
			<a class="tilfy-link" href="<?php echo esc_url( $p->hedef_url ); ?>" target="_blank" rel="noopener noreferrer"><?php echo esc_html( tilfy__( 'Hedef' ) ); ?></a>
		<?php endif; ?>
		<?php if ( ! $kaynak_url && ! $p->hedef_url ) : ?>
			<span class="tilfy-muted-dash"><?php echo esc_html( tilfy__( '-' ) ); ?></span>
		<?php endif; ?>
	</td>
	<td class="tilfy-paylasim-liste-guncelleme"><?php echo esc_html( mysql2date( 'd.m.Y H:i', $p->guncelleme ) ); ?></td>
	<td class="tilfy-islemler tilfy-paylasim-liste-islemler">
		<div class="tilfy-paylasim-liste-aksiyonlar">
			<button type="button" class="tilfy-paylasim-liste-aksiyon tilfy-paylasim-detay-ac" data-paylasim-id="<?php echo (int) $p->id; ?>" title="<?php echo esc_attr( tilfy__( 'Detay' ) ); ?>" aria-label="<?php echo esc_attr( tilfy__( 'Detay' ) ); ?>"><?php echo esc_html( tilfy__( 'i' ) ); ?></button>
			<a class="tilfy-paylasim-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-paylasim-liste-aksiyon-ikon', 'alt' => '' ) ); ?>
			</a>
			<?php if ( $manuel_tamam ) : ?>
				<button type="button" class="tilfy-paylasim-liste-aksiyon tilfy-paylasim-manuel-tamam" data-paylasim-id="<?php echo (int) $p->id; ?>" title="<?php echo esc_attr( tilfy__( 'Yüklendi' ) ); ?>" aria-label="<?php echo esc_attr( tilfy__( 'Yüklendi' ) ); ?>"><?php echo esc_html( tilfy__( '✓' ) ); ?></button>
			<?php elseif ( $yeniden_goster ) : ?>
				<button type="button" class="tilfy-paylasim-liste-aksiyon tilfy-paylasim-medya-ata" data-paylasim-id="<?php echo (int) $p->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 && $wp_kaynak ) : ?>
					<button type="button" class="tilfy-paylasim-liste-aksiyon tilfy-paylasim-one-cikan" data-paylasim-id="<?php echo (int) $p->id; ?>" title="<?php echo esc_attr( tilfy__( 'Öne çıkan' ) ); ?>" aria-label="<?php echo esc_attr( tilfy__( 'Öne çıkan' ) ); ?>">WP</button>
				<?php endif; ?>
				<?php if ( $tekrar_goster ) : ?>
					<button type="button" class="tilfy-paylasim-liste-aksiyon tilfy-paylasim-tekrar" data-paylasim-id="<?php echo (int) $p->id; ?>" title="<?php echo esc_attr( tilfy__( 'Yeniden dene' ) ); ?>" aria-label="<?php echo esc_attr( tilfy__( 'Yeniden dene' ) ); ?>"><?php echo esc_html( tilfy__( '↻' ) ); ?></button>
				<?php endif; ?>
				<button type="button" class="tilfy-paylasim-liste-aksiyon tilfy-paylasim-yoksay" data-paylasim-id="<?php echo (int) $p->id; ?>" title="<?php echo esc_attr( tilfy__( 'Yoksay' ) ); ?>" aria-label="<?php echo esc_attr( tilfy__( 'Yoksay' ) ); ?>"><?php echo esc_html( tilfy__( '⊘' ) ); ?></button>
			<?php endif; ?>
		</div>
	</td>
</tr>
