<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
$pa_platform = isset( $tilfy_pa_platform ) ? sanitize_key( $tilfy_pa_platform ) : '';
if ( $pa_platform === '' ) {
	return;
}
$pa_yt_listeler    = (array) ( $tilfy_pa_yt_listeler ?? array() );
$pa_yt_scope_eksik = ! empty( $tilfy_pa_yt_scope_eksik );
$pa_kayitli        = (array) ( $tilfy_pa_kayitli ?? array() );
if ( $pa_platform === 'youtube' ) :
	if ( $pa_yt_scope_eksik ) :
		?>
		<p class="tilfy-notice tilfy-notice--hata tilfy-notice--kucuk"><?php echo esc_html( tilfy__( 'Playlist için Ayarlar → YouTube →' ) ); ?> <strong><?php echo esc_html( tilfy__( 'Jetonları sıfırla ve yeniden bağlan' ) ); ?></strong> gerekli.</p>
		<?php
	endif;
	?>
	<label class="tilfy-alan tilfy-alan--satir">
		<span><?php echo esc_html( tilfy__( 'İçerik türü' ) ); ?></span>
		<select name="platform_ayar[youtube][tur]" id="tilfy-yt-tur">
			<option value="video" <?php selected( sanitize_key( (string) ( $pa_kayitli['tur'] ?? 'video' ) ), 'video' ); ?>>Video</option>
			<option value="short" <?php selected( sanitize_key( (string) ( $pa_kayitli['tur'] ?? '' ) ), 'short' ); ?>>Short</option>
		</select>
	</label>
	<label class="tilfy-alan tilfy-alan--satir">
		<span><?php echo esc_html( tilfy__( 'Görünürlük' ) ); ?></span>
		<select name="platform_ayar[youtube][gizlilik]">
			<option value="public" <?php selected( sanitize_key( (string) ( $pa_kayitli['gizlilik'] ?? 'public' ) ), 'public' ); ?>><?php echo esc_html( tilfy__( 'Herkese açık' ) ); ?></option>
			<option value="unlisted" <?php selected( sanitize_key( (string) ( $pa_kayitli['gizlilik'] ?? '' ) ), 'unlisted' ); ?>><?php echo esc_html( tilfy__( 'Liste dışı' ) ); ?></option>
			<option value="private" <?php selected( sanitize_key( (string) ( $pa_kayitli['gizlilik'] ?? '' ) ), 'private' ); ?>>Gizli</option>
		</select>
	</label>
	<label class="tilfy-alan tilfy-alan--satir">
		<span><?php echo esc_html( tilfy__( 'Çocuklara uygun (Kids)' ) ); ?></span>
		<select name="platform_ayar[youtube][cocuk]">
			<option value="hayir" <?php selected( sanitize_key( (string) ( $pa_kayitli['cocuk'] ?? 'hayir' ) ), 'hayir' ); ?>><?php echo esc_html( tilfy__( 'Hayır' ) ); ?></option>
			<option value="evet" <?php selected( sanitize_key( (string) ( $pa_kayitli['cocuk'] ?? '' ) ), 'evet' ); ?>>Evet</option>
		</select>
	</label>
	<label class="tilfy-alan tilfy-alan--satir">
		<span><?php echo esc_html( tilfy__( 'Oynatma listesi' ) ); ?></span>
		<select name="platform_ayar[youtube][playlist_id]" id="tilfy-yt-playlist-select">
			<option value=""><?php echo esc_html( tilfy__( 'Seçilmedi' ) ); ?></option>
			<?php foreach ( $pa_yt_listeler as $liste ) : ?>
				<option value="<?php echo esc_attr( $liste['id'] ); ?>" <?php selected( (string) ( $pa_kayitli['playlist_id'] ?? '' ), (string) $liste['id'] ); ?>><?php echo esc_html( $liste['baslik'] ); ?></option>
			<?php endforeach; ?>
		</select>
		<span class="tilfy-yardim tilfy-yt-liste-durum" id="tilfy-yt-liste-durum"><?php echo empty( $pa_yt_listeler ) ? 'YouTube hedef seçilince kanaldan yüklenir.' : ''; ?></span>
	</label>
	<div class="tilfy-alan tilfy-alan--kapak" id="tilfy-yt-kapak-alani">
		<span><?php echo esc_html( tilfy__( 'Kapak görseli' ) ); ?></span>
		<input type="hidden" name="platform_ayar[youtube][thumbnail_id]" id="tilfy-yt-kapak-id" value="<?php echo esc_attr( (string) (int) ( $pa_kayitli['thumbnail_id'] ?? 0 ) ); ?>" />
		<div id="tilfy-yt-kapak-onizleme" class="tilfy-kapak-onizleme"></div>
		<button type="button" class="tilfy-btn tilfy-btn--ikincil tilfy-btn--kucuk" id="tilfy-yt-kapak-sec"><?php echo esc_html( tilfy__( 'Kapak seç' ) ); ?></button>
		<p class="tilfy-yardim"><?php echo esc_html( tilfy__( 'En az 640×360 px, en fazla 2 MB. Kanal doğrulaması gerekebilir:' ) ); ?> <a href="https://www.youtube.com/verify" target="_blank" rel="noopener noreferrer">youtube.com/verify</a></p>
	</div>
	<p class="tilfy-notice tilfy-notice--bilgi tilfy-notice--kucuk tilfy-is-gizli" id="tilfy-yt-short-bilgi"><?php echo esc_html( tilfy__( 'YouTube, Short videolarda (genelde 3 dakikadan kısa dikey videolar) özel kapak dosyası yüklemeye izin vermez. Kapak görünümünü YouTube uygulamasından veya YouTube Studio\'dan videodan bir kare seçerek değiştirebilirsiniz.' ) ); ?></p>
	<?php
elseif ( in_array( $pa_platform, array( 'instagram', 'facebook' ), true ) ) :
	?>
	<label class="tilfy-alan tilfy-alan--satir">
		<span><?php echo esc_html( tilfy__( 'Format' ) ); ?></span>
		<select name="platform_ayar[<?php echo esc_attr( $pa_platform ); ?>][format]" class="tilfy-meta-format" id="tilfy-<?php echo esc_attr( $pa_platform ); ?>-format" data-platform="<?php echo esc_attr( $pa_platform ); ?>">
			<option value="reels" <?php selected( sanitize_key( (string) ( $pa_kayitli['format'] ?? 'reels' ) ), 'reels' ); ?>>Reels</option>
			<option value="story" <?php selected( sanitize_key( (string) ( $pa_kayitli['format'] ?? '' ) ), 'story' ); ?>>Story</option>
		</select>
	</label>
	<div class="tilfy-alan tilfy-alan--kapak" id="tilfy-<?php echo esc_attr( $pa_platform ); ?>-kapak-alani">
		<span><?php echo esc_html( tilfy__( 'Kapak görseli' ) ); ?></span>
		<input type="hidden" name="platform_ayar[<?php echo esc_attr( $pa_platform ); ?>][thumbnail_id]" id="tilfy-<?php echo esc_attr( $pa_platform ); ?>-kapak-id" value="<?php echo esc_attr( (string) (int) ( $pa_kayitli['thumbnail_id'] ?? 0 ) ); ?>" />
		<div id="tilfy-<?php echo esc_attr( $pa_platform ); ?>-kapak-onizleme" class="tilfy-kapak-onizleme"></div>
		<button type="button" class="tilfy-btn tilfy-btn--ikincil tilfy-btn--kucuk tilfy-meta-kapak-sec" data-platform="<?php echo esc_attr( $pa_platform ); ?>"><?php echo esc_html( tilfy__( 'Kapak seç' ) ); ?></button>
		<p class="tilfy-yardim"><?php echo esc_html( tilfy__( 'Reels için. Önerilen 9:16 (1080×1920), en fazla 8 MB JPEG veya PNG.' ) ); ?></p>
	</div>
	<p class="tilfy-notice tilfy-notice--bilgi tilfy-notice--kucuk tilfy-is-gizli" id="tilfy-<?php echo esc_attr( $pa_platform ); ?>-story-bilgi"><?php echo esc_html( tilfy__( 'Story formatında özel kapak yüklenemez; kapak görünümünü uygulamadan videodan bir kare seçerek değiştirebilirsiniz.' ) ); ?></p>
	<?php
endif;
