<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
$paylasimlar_base = admin_url( 'admin.php?page=tilfy-paylasimlar' );
?>
<div class="wrap tilfy-wrap" id="tilfy-panel-sayfa">
	<header class="tilfy-header tilfy-header--panel">
		<div class="tilfy-panel-logo" id="tilfy-panel-logo" aria-hidden="true"></div>
		<div class="tilfy-header__metin">
			<h1><?php echo esc_html( tilfy__( 'Tilfy Panel' ) ); ?></h1>
			<p class="tilfy-sub"><?php echo esc_html( tilfy__( 'Sosyal medya içerik ve paylaşım merkezi' ) ); ?> - v<?php echo esc_html( TILFY_SURUM ); ?></p>
		</div>
	</header>

	<?php if ( $mesaj === 'senkron_basladi' ) : ?>
		<div class="tilfy-notice tilfy-notice--ok"><?php echo esc_html( tilfy__( 'Senkron tamamlandı.' ) ); ?></div>
	<?php elseif ( $mesaj === 'otomasyon_kaydedildi' ) : ?>
		<div class="tilfy-notice tilfy-notice--ok"><?php echo esc_html( tilfy__( 'Otomasyon kuralı kaydedildi.' ) ); ?></div>
	<?php elseif ( $mesaj === 'otomasyon_silindi' ) : ?>
		<div class="tilfy-notice tilfy-notice--ok"><?php echo esc_html( tilfy__( 'Otomasyon kuralı silindi.' ) ); ?></div>
	<?php elseif ( $mesaj === 'otomasyon_hata' ) : ?>
		<div class="tilfy-notice tilfy-notice--hata"><?php echo esc_html( tilfy__( 'Kural kaydedilemedi. Kaynak, hedef ve alanları kontrol edin.' ) ); ?></div>
	<?php endif; ?>

	<div class="tilfy-grid tilfy-grid--5">
		<a class="tilfy-kart tilfy-kart--link" href="<?php echo esc_url( admin_url( 'admin.php?page=tilfy-icerikler' ) ); ?>">
			<span class="tilfy-kart__etiket"><?php echo esc_html( tilfy__( 'İçerik' ) ); ?></span>
			<strong class="tilfy-kart__deger"><?php echo (int) $ozet['toplam_icerik']; ?></strong>
		</a>
		<a class="tilfy-kart tilfy-kart--link" href="<?php echo esc_url( add_query_arg( 'grup', 'bekleyen', $paylasimlar_base ) ); ?>">
			<span class="tilfy-kart__etiket"><?php echo esc_html( tilfy__( 'Bekleyen' ) ); ?></span>
			<strong class="tilfy-kart__deger"><?php echo (int) $ozet['bekleyen']; ?></strong>
		</a>
		<a class="tilfy-kart tilfy-kart--link" href="<?php echo esc_url( add_query_arg( 'durum', 'manuel_bekliyor', $paylasimlar_base ) ); ?>">
			<span class="tilfy-kart__etiket"><?php echo esc_html( tilfy__( 'Manuel' ) ); ?></span>
			<strong class="tilfy-kart__deger"><?php echo (int) ( $ozet['manuel'] ?? 0 ); ?></strong>
		</a>
		<a class="tilfy-kart tilfy-kart--ok tilfy-kart--link" href="<?php echo esc_url( add_query_arg( 'durum', 'yuklendi', $paylasimlar_base ) ); ?>">
			<span class="tilfy-kart__etiket"><?php echo esc_html( tilfy__( 'Yüklendi' ) ); ?></span>
			<strong class="tilfy-kart__deger"><?php echo (int) $ozet['yuklendi']; ?></strong>
		</a>
		<a class="tilfy-kart tilfy-kart--hata tilfy-kart--link" href="<?php echo esc_url( add_query_arg( 'durum', 'hata', $paylasimlar_base ) ); ?>">
			<span class="tilfy-kart__etiket"><?php echo esc_html( tilfy__( 'Hata' ) ); ?></span>
			<strong class="tilfy-kart__deger"><?php echo (int) $ozet['hata']; ?></strong>
		</a>
	</div>

	<section class="tilfy-bolum">
		<h2><?php echo esc_html( tilfy__( 'Platform bağlantıları' ) ); ?></h2>
		<div class="tilfy-platform-durum">
			<?php foreach ( tilfy_platform_listesi() as $anahtar => $bilgi ) :
				$d = $baglanti[ $anahtar ] ?? array();
				$sinif = ! empty( $d['bagli'] ) ? 'bagli' : 'kopuk';
				if ( $anahtar === 'wordpress' ) {
					$durum_yazi = ! empty( $d['bagli'] ) ? tilfy__( 'Aktif' ) : tilfy__( 'Kapalı' );
				} else {
					$durum_yazi = ! empty( $d['bagli'] ) ? tilfy__( 'Bağlı' ) : tilfy__( 'Bağlanmadı' );
				}
				?>
				<div class="tilfy-platform-chip tilfy-platform-chip--<?php echo esc_attr( $sinif ); ?>">
					<span><?php echo esc_html( $bilgi['etiket'] ); ?></span>
					<small><?php echo esc_html( $durum_yazi ); ?></small>
				</div>
			<?php endforeach; ?>
		</div>
	</section>

	<section class="tilfy-bolum">
		<h2><?php echo esc_html( tilfy__( 'Senkronizasyon' ) ); ?></h2>
		<p class="tilfy-sub"><?php echo esc_html( tilfy__( 'Varsayılan: yalnızca yeni içerikler. Tam tarama derin geçmişi yeniden dolaşır. WordPress açıksa yazı metadata’sı (URL’ler) senkronlanır; medya paylaşım anında indirilir.' ) ); ?></p>
		<?php $tilfy_senkron_mod = function_exists( 'tilfy_senkron_modu' ) ? tilfy_senkron_modu() : 'yeni'; ?>
		<div class="tilfy-senkron-mod" style="margin-bottom:12px;">
			<label class="tilfy-check" style="margin-right:16px;">
				<input type="radio" name="tilfy_senkron_mod" value="yeni" <?php checked( $tilfy_senkron_mod, 'yeni' ); ?> />
				<?php echo esc_html( tilfy__( 'Yeni içerikler' ) ); ?>
			</label>
			<label class="tilfy-check">
				<input type="radio" name="tilfy_senkron_mod" value="tam" <?php checked( $tilfy_senkron_mod, 'tam' ); ?> />
				<?php echo esc_html( tilfy__( 'Tam tarama' ) ); ?>
			</label>
		</div>
		<div class="tilfy-senkron-butonlar">
			<?php foreach ( tilfy_platform_listesi() as $anahtar => $bilgi ) :
				$d = $baglanti[ $anahtar ] ?? array();
				if ( empty( $d['bagli'] ) ) {
					continue;
				}
				?>
				<button type="button" class="tilfy-btn tilfy-btn--ikincil tilfy-senkron-btn" data-platform="<?php echo esc_attr( $anahtar ); ?>"><?php echo esc_html( $bilgi['etiket'] . ' ' . tilfy__( 'senkronize et' ) ); ?></button>
			<?php endforeach; ?>
			<button type="button" class="tilfy-btn tilfy-btn--birincil tilfy-senkron-btn" data-platform="tumu"><?php echo esc_html( tilfy__( 'Tümünü senkronize et' ) ); ?></button>
		</div>
	</section>

	<section class="tilfy-bolum tilfy-hizli">
		<a class="tilfy-btn tilfy-btn--birincil" href="<?php echo esc_url( admin_url( 'admin.php?page=tilfy-studyosu' ) ); ?>"><?php echo esc_html( tilfy__( 'Studyo' ) ); ?></a>
		<a class="tilfy-btn tilfy-btn--ikincil" href="<?php echo esc_url( admin_url( 'admin.php?page=tilfy-icerikler' ) ); ?>"><?php echo esc_html( tilfy__( 'İçerikler' ) ); ?></a>
		<a class="tilfy-btn tilfy-btn--ikincil" href="<?php echo esc_url( admin_url( 'admin.php?page=tilfy-paylasimlar' ) ); ?>"><?php echo esc_html( tilfy__( 'Paylaşımlar' ) ); ?></a>
		<a class="tilfy-btn tilfy-btn--ikincil" href="<?php echo esc_url( admin_url( 'admin.php?page=tilfy-otomasyon' ) ); ?>"><?php echo esc_html( tilfy__( 'Otomasyon' ) ); ?></a>
		<a class="tilfy-btn tilfy-btn--ikincil" href="<?php echo esc_url( admin_url( 'admin.php?page=tilfy-ayarlar' ) ); ?>"><?php echo esc_html( tilfy__( 'Ayarlar' ) ); ?></a>
	</section>
</div>
