<?php
defined( 'ABSPATH' ) || exit;
global $wpdb;

$avi_lang = 'es';
$lc       = 'es';

$avi_meta_title = 'Patrocinadores Fundadores — Avision';
$avi_meta_desc  = 'Las personas que creyeron en Avision antes que nadie.';

add_action(
	'wp_enqueue_scripts',
	function () {
		wp_enqueue_style(
			'avi-founding-sponsors-fonts',
			'https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap',
			array(),
			null
		);
	},
	20
);

$table    = $wpdb->prefix . 'avi_founding_sponsors';
$sponsors = $wpdb->get_results(
	"SELECT * FROM {$table} WHERE active = 1 ORDER BY display_order ASC, created_at ASC"
);

$tier_config = array(
	'founding_member' => array(
		'emoji'    => '🏆',
		'label_en' => 'Founding Member',
		'label_fr' => 'Membre Fondateur',
		'label_es' => 'Miembro Fundador',
		'color'    => '#F5A623',
		'bg'       => '#FFF8EC',
	),
	'elite_sponsor' => array(
		'emoji'    => '💎',
		'label_en' => 'Elite Sponsor',
		'label_fr' => 'Sponsor Élite',
		'label_es' => 'Patrocinador Élite',
		'color'    => '#4A90D9',
		'bg'       => '#EEF5FC',
	),
	'growth_partner' => array(
		'emoji'    => '🌱',
		'label_en' => 'Growth Partner',
		'label_fr' => 'Partenaire Croissance',
		'label_es' => 'Socio de Crecimiento',
		'color'    => '#27AE60',
		'bg'       => '#EAF7EF',
	),
	'early_backer' => array(
		'emoji'    => '⚡',
		'label_en' => 'Early Backer',
		'label_fr' => 'Soutien Pionnier',
		'label_es' => 'Apoyo Pionero',
		'color'    => '#E67E22',
		'bg'       => '#FEF3E8',
	),
	'supporter' => array(
		'emoji'    => '☕',
		'label_en' => 'Supporter',
		'label_fr' => 'Soutien',
		'label_es' => 'Colaborador',
		'color'    => '#95A5A6',
		'bg'       => '#F4F6F6',
	),
);

$tier_order = array(
	'founding_member',
	'elite_sponsor',
	'growth_partner',
	'early_backer',
	'supporter',
);

avi_get_layout( 'header' );
?>

<div class="avi-founding-sponsors-page">

<section class="afs-hero">
	<div class="avi-container">
		<h1 class="afs-hero__title">Las personas que hicieron posible Avision</h1>
		<p class="afs-hero__subtitle">Cada nombre en esta página creyó en Avision antes que nadie. Gracias.</p>
		<blockquote class="afs-hero__quote">
			"Construir Avision en solitario significa que cada apoyo importa más de lo que se cree. Esta página es mi forma de decir gracias — para siempre."
			<cite>— Anthony, fundador</cite>
		</blockquote>
	</div>
</section>

<section class="afs-sponsors">
	<div class="avi-container">

	<?php if ( empty( $sponsors ) ) : ?>

		<div class="afs-empty">
			<div class="afs-empty__badge">🏆</div>
			<h2 class="afs-empty__title">Sé el primer Patrocinador Fundador</h2>
			<p class="afs-empty__text">Tu nombre aparecerá aquí de forma permanente. Apoya Avision en Ko-fi y forma parte de la historia.</p>
			<a href="https://ko-fi.com/avisionavi" target="_blank" rel="noopener" class="afs-btn-kofi">Apoyar Avision en Ko-fi →</a>
		</div>

	<?php else : ?>

		<?php
		foreach ( $tier_order as $tier_key ) {
			$tier_sponsors = array_filter(
				$sponsors,
				static function ( $s ) use ( $tier_key ) {
					return isset( $s->tier ) && $s->tier === $tier_key;
				}
			);
			if ( empty( $tier_sponsors ) ) {
				continue;
			}
			$tc       = $tier_config[ $tier_key ];
			$lang_key = 'label_' . $lc;
			$tier_label = isset( $tc[ $lang_key ] ) ? $tc[ $lang_key ] : $tc['label_en'];
			?>
		<div class="afs-tier-group">
			<h2 class="afs-tier-group__title">
				<span class="afs-badge" style="color:<?php echo esc_attr( $tc['color'] ); ?>;background:<?php echo esc_attr( $tc['bg'] ); ?>;">
					<?php echo esc_html( $tc['emoji'] . ' ' . $tier_label ); ?>
				</span>
			</h2>
			<div class="afs-cards-grid">
				<?php foreach ( $tier_sponsors as $sp ) : ?>
				<div class="afs-card">
					<div class="afs-card__badge" style="color:<?php echo esc_attr( $tc['color'] ); ?>;background:<?php echo esc_attr( $tc['bg'] ); ?>;">
						<?php echo esc_html( $tc['emoji'] . ' ' . $tier_label ); ?>
					</div>
					<div class="afs-card__name"><?php echo esc_html( $sp->name ); ?></div>
					<?php if ( ! empty( $sp->country ) ) : ?>
					<div class="afs-card__country"><?php echo esc_html( $sp->country ); ?></div>
					<?php endif; ?>
					<div class="afs-card__amount">$<?php echo (int) $sp->amount; ?> de apoyo</div>
				</div>
				<?php endforeach; ?>
			</div>
		</div>
			<?php
		}
		?>

	<?php endif; ?>

		<div class="afs-cta-final">
			<p>¿Quieres tu nombre en esta página?</p>
			<a href="https://ko-fi.com/avisionavi" target="_blank" rel="noopener" class="afs-btn-kofi">Apoyar Avision en Ko-fi →</a>
		</div>

	</div>
</section>

</div>

<style>
.avi-founding-sponsors-page { background: #F8F9FF; min-height: 100vh; }
.afs-hero { background: #0A1628; padding: 80px 0 60px; text-align: center; }
.afs-hero__title { color: #FFFFFF; font-size: 2.4rem; font-weight: 700; margin-bottom: 16px; }
.afs-hero__subtitle { color: #B0BEC5; font-size: 1.15rem; margin-bottom: 32px; }
.afs-hero__quote { border-left: 3px solid #F5A623; padding-left: 20px; text-align: left; max-width: 600px; margin: 0 auto; color: #FFFFFF; font-style: italic; font-size: 1rem; }
.afs-hero__quote cite { display: block; margin-top: 8px; color: #F5A623; font-style: normal; font-weight: 600; }
.afs-sponsors { padding: 60px 0; }
.afs-empty { text-align: center; padding: 60px 20px; }
.afs-empty__badge { font-size: 4rem; animation: afs-pulse 2s infinite; }
@keyframes afs-pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.08); } }
.afs-empty__title { color: #0A1628; font-size: 1.8rem; font-weight: 700; margin: 20px 0 12px; }
.afs-empty__text { color: #5A6A7A; font-size: 1.05rem; margin-bottom: 28px; max-width: 480px; margin-left: auto; margin-right: auto; }
.afs-btn-kofi { display: inline-block; background: #F5A623; color: #0A1628; font-weight: 700; padding: 14px 28px; border-radius: 8px; text-decoration: none; font-size: 1rem; transition: background 0.2s; }
.afs-btn-kofi:hover { background: #D4901F; color: #0A1628; }
.afs-tier-group { margin-bottom: 48px; }
.afs-tier-group__title { margin-bottom: 20px; }
.afs-badge { display: inline-block; padding: 6px 16px; border-radius: 20px; font-weight: 600; font-size: 1rem; }
.afs-cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 20px; }
.afs-card { background: #FFFFFF; border-radius: 12px; padding: 24px; box-shadow: 0 2px 12px rgba(0,0,0,0.07); text-align: center; }
.afs-card__badge { display: inline-block; padding: 4px 12px; border-radius: 20px; font-size: 0.8rem; font-weight: 600; margin-bottom: 12px; }
.afs-card__name { font-size: 1.1rem; font-weight: 700; color: #0A1628; margin-bottom: 4px; }
.afs-card__country { font-size: 0.85rem; color: #7A8A9A; margin-bottom: 8px; }
.afs-card__amount { font-size: 0.85rem; color: #F5A623; font-weight: 600; }
.afs-cta-final { text-align: center; padding: 40px 0 0; border-top: 1px solid #E8ECF0; margin-top: 40px; }
.afs-cta-final p { color: #0A1628; font-size: 1.1rem; font-weight: 600; margin-bottom: 16px; }
@media (max-width: 768px) { .afs-hero__title { font-size: 1.7rem; } .afs-cards-grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 480px) { .afs-cards-grid { grid-template-columns: 1fr; } .afs-hero { padding: 50px 0 40px; } }
</style>

<?php
$GLOBALS['avi_template_footer_rendered'] = true;
avi_get_layout( 'footer' );
