<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
if ( empty( $satir ) ) {
	return;
}
$aid = (int) $satir['attachment_id'];
$disk = $satir['dosya_yolu'] ?? '';
?>
<tr class="tilfy-medya-tr<?php echo ! empty( $satir['yetim'] ) ? ' is-yetim' : ''; ?><?php echo ! $satir['silinebilir'] ? ' is-korumali' : ''; ?>" data-attachment-id="<?php echo (int) $aid; ?>"<?php echo $disk ? ' data-disk-path="' . esc_attr( $disk ) . '"' : ''; ?>>
	<td class="tilfy-iy-col-sec">
		<?php if ( $satir['silinebilir'] ) : ?>
			<input type="checkbox" class="tilfy-medya-sec" value="<?php echo (int) $aid; ?>" data-disk-path="<?php echo esc_attr( $disk ); ?>" aria-label="<?php echo esc_attr( $satir['dosya_adi'] ); ?>" />
		<?php endif; ?>
	</td>
	<td class="tilfy-iy-col-gorsel">
		<?php if ( $satir['video'] && $satir['url'] ) : ?>
			<button type="button" class="tilfy-medya-onizleme-ac tilfy-medya-onizleme-ac--video" data-url="<?php echo esc_url( $satir['url'] ); ?>" data-tip="video" aria-label="<?php echo esc_attr( $satir['dosya_adi'] ); ?> önizle">
				<video class="tilfy-iy-thumb tilfy-medya-thumb-video" src="<?php echo esc_url( $satir['url'] ); ?>" muted preload="metadata"></video>
			</button>
		<?php elseif ( $satir['thumb'] ) : ?>
			<button type="button" class="tilfy-medya-onizleme-ac" data-url="<?php echo esc_url( $satir['thumb'] ); ?>" data-tip="image" aria-label="<?php echo esc_attr( $satir['dosya_adi'] ); ?> önizle">
				<img class="tilfy-iy-thumb" src="<?php echo esc_url( $satir['thumb'] ); ?>" alt="" loading="lazy" />
			</button>
		<?php elseif ( ! $satir['video'] && $satir['url'] ) : ?>
			<button type="button" class="tilfy-medya-onizleme-ac" data-url="<?php echo esc_url( $satir['url'] ); ?>" data-tip="image" aria-label="<?php echo esc_attr( $satir['dosya_adi'] ); ?> önizle">
				<img class="tilfy-iy-thumb" src="<?php echo esc_url( $satir['url'] ); ?>" alt="" loading="lazy" />
			</button>
		<?php else : ?>
			<span class="tilfy-iy-thumb tilfy-iy-thumb--bos" aria-hidden="true"></span>
		<?php endif; ?>
	</td>
	<td>
		<strong><?php echo esc_html( $satir['dosya_adi'] ); ?></strong>
		<br /><small class="tilfy-muted"><?php echo $aid > 0 ? '#' . (int) $aid . ' · ' : ''; ?><?php echo esc_html( $satir['boyut_etiket'] ); ?></small>
		<?php if ( $satir['indirilme'] ) : ?>
			<br /><small class="tilfy-muted"><?php echo esc_html( mysql2date( 'j M Y, H:i', $satir['indirilme'] ) ); ?></small>
		<?php endif; ?>
	</td>
	<td>
		<?php if ( $satir['icerik_id'] > 0 ) : ?>
			<strong><?php echo esc_html( $satir['baslik'] !== '' ? $satir['baslik'] : sprintf( tilfy__( 'İçerik #%d' ), (int) $satir['icerik_id'] ) ); ?></strong>
			<br /><small class="tilfy-muted">#<?php echo (int) $satir['icerik_id']; ?>
			<?php if ( $satir['kaynak_platform'] ) : ?>
				· <?php echo esc_html( function_exists( 'tilfy_platform_etiket' ) ? tilfy_platform_etiket( $satir['kaynak_platform'] ) : $satir['kaynak_platform'] ); ?>
			<?php endif; ?>
			<?php if ( $satir['kaynak_id'] ) : ?>
				· <?php echo esc_html( $satir['kaynak_id'] ); ?>
			<?php endif; ?>
			</small>
		<?php else : ?>
			<span class="tilfy-muted"><?php echo esc_html( tilfy__( 'Bağlı içerik yok' ) ); ?></span>
		<?php endif; ?>
	</td>
	<td class="tilfy-medya-paylasimlar">
		<?php if ( empty( $satir['paylasimlar'] ) ) : ?>
			<span class="tilfy-muted"><?php echo esc_html( tilfy__( 'Paylaşım yok' ) ); ?></span>
		<?php else : ?>
			<?php foreach ( $satir['paylasimlar'] as $p ) : ?>
				<div class="tilfy-medya-paylasim-oge">
					<span class="tilfy-islem-rozet tilfy-islem-rozet--<?php echo $p['durum'] === 'yuklendi' ? 'calisiyor' : ( $p['durum'] === 'hata' ? 'hata' : 'bekliyor' ); ?>">
						<?php echo esc_html( $p['platform_etiket'] ); ?> · <?php echo esc_html( $p['durum_etiket'] ); ?>
					</span>
					<?php if ( ! empty( $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__( 'Gönderi' ) ); ?></a>
					<?php endif; ?>
					<?php if ( ! empty( $p['hata_mesaji'] ) ) : ?>
						<br /><small class="tilfy-medya-hata"><?php echo esc_html( $p['hata_mesaji'] ); ?></small>
					<?php endif; ?>
				</div>
			<?php endforeach; ?>
		<?php endif; ?>
	</td>
	<td class="tilfy-medya-yol">
		<?php if ( $satir['dosya_yolu'] ) : ?>
			<code class="tilfy-medya-yol-kod"><?php echo esc_html( $satir['dosya_yolu'] ); ?></code>
		<?php else : ?>
			<span class="tilfy-muted"><?php echo esc_html( tilfy__( '-' ) ); ?></span>
		<?php endif; ?>
	</td>
	<td>
		<?php if ( $satir['silinebilir'] ) : ?>
			<span class="tilfy-medya-durum tilfy-medya-durum--ok"><?php echo esc_html( tilfy__( 'Silinebilir' ) ); ?></span>
			<button type="button" class="tilfy-btn tilfy-btn--ghost tilfy-btn--kucuk tilfy-medya-tekil-sil" data-id="<?php echo (int) $aid; ?>" data-disk-path="<?php echo esc_attr( $disk ); ?>"><?php echo esc_html( tilfy__( 'Sil' ) ); ?></button>
		<?php else : ?>
			<span class="tilfy-medya-durum tilfy-medya-durum--korumali"><?php echo esc_html( $satir['silme_engeli'] ); ?></span>
		<?php endif; ?>
	</td>
</tr>
