<?php
/**
 * Nexora VE Networks - Countdown / Realm Status v2
 * WebEngine CMS 1.2.6
 *
 * Mantiene countdown.xml como interruptor global y administra una
 * configuracion independiente por reino:
 *   - countdown.legacy.xml
 *   - countdown.seasonal.xml
 */
?>
<h2>Countdown / Realm Status</h2>
<?php

function nexoraCountdownAdminDefaults($realm) {
	$isSeasonal = ($realm === 'seasonal');
	return array(
		'active' => '1',
		'mode' => $isSeasonal ? 'countdown' : 'status',
		'timezone' => 'America/Caracas',
		'target_date' => '2026-08-17 18:00:00',
		'label' => $isSeasonal ? 'Apertura Temporada II' : 'Legado operativo',
		'message' => $isSeasonal ? 'La nueva temporada entra en operacion al finalizar la cuenta.' : 'El reino permanente se encuentra disponible.',
		'display_days' => '1',
		'display_hours' => '1',
		'display_minutes' => '1',
		'display_seconds' => '1',
		'placement' => $isSeasonal ? 'hero-right' : 'hero-left',
		'offset_x' => '0',
		'offset_y' => '18',
		'size' => 'standard',
		'background_opacity' => '72',
		'blur' => '14',
		'glow' => 'medium',
		'status_type' => 'online',
		'cta_label' => '',
		'cta_url' => '',
		'after_action' => 'status',
		'after_status_type' => 'online',
		'after_label' => $isSeasonal ? 'Seasonal operativo' : 'Legado operativo',
		'after_message' => $isSeasonal ? 'La temporada ya esta disponible.' : 'El reino se encuentra disponible.',
		'after_cta_label' => '',
		'after_cta_url' => '',
	);
}

function nexoraCountdownAdminLoad($realm) {
	$defaults = nexoraCountdownAdminDefaults($realm);
	$file = __PATH_MODULE_CONFIGS__ . 'countdown.' . $realm . '.xml';
	if(!is_file($file)) return $defaults;
	$xml = @simplexml_load_file($file);
	if(!$xml) return $defaults;
	$data = convertXML($xml->children());
	return is_array($data) ? array_merge($defaults, $data) : $defaults;
}

function nexoraCountdownAdminGlobal() {
	$defaults = array('active' => '1', 'mobile_layout' => 'swipe');
	$file = __PATH_MODULE_CONFIGS__ . 'countdown.xml';
	if(!is_file($file)) return $defaults;
	$xml = @simplexml_load_file($file);
	if(!$xml) return $defaults;
	$data = convertXML($xml->children());
	return is_array($data) ? array_merge($defaults, $data) : $defaults;
}

function nexoraCountdownAdminValue($value, $fallback='') {
	return htmlspecialchars((string)(isset($value) ? $value : $fallback), ENT_QUOTES, 'UTF-8');
}

function nexoraCountdownAdminBool($source, $key) {
	return (isset($source[$key]) && (string)$source[$key] === '1') ? '1' : '0';
}

function nexoraCountdownAdminClamp($value, $min, $max, $fallback) {
	if(!is_numeric($value)) return (string)$fallback;
	$value = (int)$value;
	if($value < $min) $value = $min;
	if($value > $max) $value = $max;
	return (string)$value;
}

function nexoraCountdownAdminSelect($value, $allowed, $fallback) {
	$value = (string)$value;
	return in_array($value, $allowed, true) ? $value : $fallback;
}

function nexoraCountdownAdminSafeUrl($value) {
	$value = trim((string)$value);
	if($value === '') return '';
	if(strpos($value, '/') === 0 && strpos($value, '//') !== 0) return $value;
	if(preg_match('~^[a-zA-Z0-9][a-zA-Z0-9/_\-?.=&%#]*$~', $value)) return $value;
	$parts = @parse_url($value);
	if(is_array($parts) && isset($parts['scheme']) && in_array(strtolower($parts['scheme']), array('http', 'https'), true)) {
		return $value;
	}
	return false;
}

function nexoraCountdownAdminWriteXml($realm, $data) {
	$xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><settings></settings>');
	$xml->addChild('version', '2');
	$xml->addChild('realm', $realm);
	foreach($data as $key => $value) {
		$xml->addChild($key, htmlspecialchars((string)$value, ENT_XML1 | ENT_COMPAT, 'UTF-8'));
	}
	return $xml->asXML(__PATH_MODULE_CONFIGS__ . 'countdown.' . $realm . '.xml');
}

function nexoraCountdownAdminWriteGlobal($data) {
	$file = __PATH_MODULE_CONFIGS__ . 'countdown.xml';
	$xml = is_file($file) ? @simplexml_load_file($file) : false;
	if(!$xml) $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><settings></settings>');
	$xml->active = $data['active'];
	$xml->mobile_layout = $data['mobile_layout'];
	$xml->version = '2';
	return $xml->asXML($file);
}

function saveChanges() {
	global $_POST;

	$allowedModes = array('countdown', 'status');
	$allowedPlacements = array(
		'hero-left', 'hero-center', 'hero-right',
		'hero-bottom-left', 'hero-bottom-center', 'hero-bottom-right',
		'after-hero', 'floating-left', 'floating-right'
	);
	$allowedSizes = array('compact', 'standard', 'wide');
	$allowedGlow = array('off', 'low', 'medium', 'high');
	$allowedStatus = array('online', 'maintenance', 'offline', 'event', 'notice');
	$allowedAfter = array('hide', 'status');
	$allowedMobile = array('swipe', 'stack');

	$postedGlobal = isset($_POST['global']) && is_array($_POST['global']) ? $_POST['global'] : array();
	$global = array(
		'active' => nexoraCountdownAdminBool($postedGlobal, 'active'),
		'mobile_layout' => nexoraCountdownAdminSelect(isset($postedGlobal['mobile_layout']) ? $postedGlobal['mobile_layout'] : '', $allowedMobile, 'swipe'),
	);

	$postedRealms = isset($_POST['realms']) && is_array($_POST['realms']) ? $_POST['realms'] : array();
	$realms = array('legacy', 'seasonal');
	$prepared = array();

	foreach($realms as $realm) {
		$source = isset($postedRealms[$realm]) && is_array($postedRealms[$realm]) ? $postedRealms[$realm] : array();
		$defaults = nexoraCountdownAdminDefaults($realm);

		$timezone = isset($source['timezone']) ? trim((string)$source['timezone']) : $defaults['timezone'];
		if(!in_array($timezone, timezone_identifiers_list(), true)) {
			message('error', 'Zona horaria no valida en ' . ucfirst($realm) . '.');
			return;
		}

		$mode = nexoraCountdownAdminSelect(isset($source['mode']) ? $source['mode'] : '', $allowedModes, $defaults['mode']);
		$targetDate = isset($source['target_date']) ? trim((string)$source['target_date']) : $defaults['target_date'];
		if($mode === 'countdown') {
			$date = DateTime::createFromFormat('Y-m-d H:i:s', $targetDate, new DateTimeZone($timezone));
			if(!$date || $date->format('Y-m-d H:i:s') !== $targetDate) {
				message('error', 'Fecha invalida en ' . ucfirst($realm) . '. Usa YYYY-MM-DD HH:MM:SS.');
				return;
			}
		}

		$label = isset($source['label']) ? trim((string)$source['label']) : '';
		if($label === '') {
			message('error', 'El titulo es obligatorio en ' . ucfirst($realm) . '.');
			return;
		}

		$ctaUrl = nexoraCountdownAdminSafeUrl(isset($source['cta_url']) ? $source['cta_url'] : '');
		$afterCtaUrl = nexoraCountdownAdminSafeUrl(isset($source['after_cta_url']) ? $source['after_cta_url'] : '');
		if($ctaUrl === false || $afterCtaUrl === false) {
			message('error', 'URL no valida en ' . ucfirst($realm) . '. Usa una ruta interna o http/https.');
			return;
		}

		$prepared[$realm] = array(
			'active' => nexoraCountdownAdminBool($source, 'active'),
			'mode' => $mode,
			'timezone' => $timezone,
			'target_date' => $targetDate,
			'label' => $label,
			'message' => isset($source['message']) ? trim((string)$source['message']) : '',
			'display_days' => nexoraCountdownAdminBool($source, 'display_days'),
			'display_hours' => nexoraCountdownAdminBool($source, 'display_hours'),
			'display_minutes' => nexoraCountdownAdminBool($source, 'display_minutes'),
			'display_seconds' => nexoraCountdownAdminBool($source, 'display_seconds'),
			'placement' => nexoraCountdownAdminSelect(isset($source['placement']) ? $source['placement'] : '', $allowedPlacements, $defaults['placement']),
			'offset_x' => nexoraCountdownAdminClamp(isset($source['offset_x']) ? $source['offset_x'] : 0, -300, 300, 0),
			'offset_y' => nexoraCountdownAdminClamp(isset($source['offset_y']) ? $source['offset_y'] : 0, -300, 300, 18),
			'size' => nexoraCountdownAdminSelect(isset($source['size']) ? $source['size'] : '', $allowedSizes, 'standard'),
			'background_opacity' => nexoraCountdownAdminClamp(isset($source['background_opacity']) ? $source['background_opacity'] : 72, 20, 100, 72),
			'blur' => nexoraCountdownAdminClamp(isset($source['blur']) ? $source['blur'] : 14, 0, 30, 14),
			'glow' => nexoraCountdownAdminSelect(isset($source['glow']) ? $source['glow'] : '', $allowedGlow, 'medium'),
			'status_type' => nexoraCountdownAdminSelect(isset($source['status_type']) ? $source['status_type'] : '', $allowedStatus, 'online'),
			'cta_label' => isset($source['cta_label']) ? trim((string)$source['cta_label']) : '',
			'cta_url' => $ctaUrl,
			'after_action' => nexoraCountdownAdminSelect(isset($source['after_action']) ? $source['after_action'] : '', $allowedAfter, 'status'),
			'after_status_type' => nexoraCountdownAdminSelect(isset($source['after_status_type']) ? $source['after_status_type'] : '', $allowedStatus, 'online'),
			'after_label' => isset($source['after_label']) ? trim((string)$source['after_label']) : '',
			'after_message' => isset($source['after_message']) ? trim((string)$source['after_message']) : '',
			'after_cta_label' => isset($source['after_cta_label']) ? trim((string)$source['after_cta_label']) : '',
			'after_cta_url' => $afterCtaUrl,
		);
	}

	$ok = nexoraCountdownAdminWriteGlobal($global);
	foreach($prepared as $realm => $data) {
		$ok = nexoraCountdownAdminWriteXml($realm, $data) && $ok;
	}

	if($ok) {
		message('success', 'Configuracion de Legado y Seasonal guardada correctamente.');
	} else {
		message('error', 'No se pudo guardar uno o mas archivos de configuracion. Revisa permisos de includes/config/modules/.');
	}
}

if(isset($_POST['submit_changes'])) {
	saveChanges();
}

$globalConfig = nexoraCountdownAdminGlobal();
$realmConfigs = array(
	'legacy' => nexoraCountdownAdminLoad('legacy'),
	'seasonal' => nexoraCountdownAdminLoad('seasonal'),
);

$timezones = array(
	'America/Caracas' => 'Caracas (UTC-4)',
	'America/New_York' => 'New York',
	'America/Los_Angeles' => 'Los Angeles',
	'America/Mexico_City' => 'Ciudad de Mexico',
	'America/Bogota' => 'Bogota',
	'America/Buenos_Aires' => 'Buenos Aires',
	'America/Santiago' => 'Santiago',
	'America/Lima' => 'Lima',
	'Europe/Madrid' => 'Madrid',
	'Europe/London' => 'Londres',
	'Europe/Paris' => 'Paris',
	'Asia/Tokyo' => 'Tokyo',
	'Asia/Shanghai' => 'Shanghai',
	'UTC' => 'UTC',
);

$placements = array(
	'hero-left' => 'Hero - arriba izquierda',
	'hero-center' => 'Hero - arriba centro',
	'hero-right' => 'Hero - arriba derecha',
	'hero-bottom-left' => 'Hero - zona baja izquierda',
	'hero-bottom-center' => 'Hero - zona baja centro',
	'hero-bottom-right' => 'Hero - zona baja derecha',
	'after-hero' => 'Debajo del Hero',
	'floating-left' => 'Flotante - izquierda',
	'floating-right' => 'Flotante - derecha',
);
$statusTypes = array(
	'online' => 'Servidor ON',
	'maintenance' => 'Mantenimiento',
	'offline' => 'Offline',
	'event' => 'Evento especial',
	'notice' => 'Aviso',
);
?>

<style>
.nex-cdv2-intro { margin: 0 0 18px; padding: 14px 16px; border-left: 4px solid #d99024; background: #f7f7f9; }
.nex-cdv2-master { margin-bottom: 20px; }
.nex-cdv2-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 18px; }
.nex-cdv2-card { border: 1px solid #ddd; border-radius: 6px; overflow: hidden; background: #fff; }
.nex-cdv2-card--legacy { border-top: 4px solid #d99024; }
.nex-cdv2-card--seasonal { border-top: 4px solid #b56cff; }
.nex-cdv2-head { padding: 14px 16px 10px; border-bottom: 1px solid #eee; }
.nex-cdv2-head h3 { margin: 0 0 4px; font-size: 20px; }
.nex-cdv2-head p { margin: 0; color: #777; }
.nex-cdv2-body { padding: 16px; }
.nex-cdv2-section { margin: 0 0 18px; padding: 0 0 16px; border-bottom: 1px solid #eee; }
.nex-cdv2-section:last-child { border-bottom: 0; margin-bottom: 0; padding-bottom: 0; }
.nex-cdv2-section h4 { margin: 0 0 12px; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: #555; }
.nex-cdv2-help { display: block; margin-top: 5px; color: #888; font-size: 12px; line-height: 1.4; }
.nex-cdv2-two { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; }
.nex-cdv2-four { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 8px; }
.nex-cdv2-range { display: grid; grid-template-columns: 1fr 52px; gap: 10px; align-items: center; }
.nex-cdv2-range output { text-align: right; font-weight: 700; }
.nex-cdv2-submit { margin-top: 20px; }
@media (max-width: 1100px) { .nex-cdv2-grid { grid-template-columns: 1fr; } }
@media (max-width: 600px) { .nex-cdv2-two, .nex-cdv2-four { grid-template-columns: 1fr; } }
</style>

<div class="nex-cdv2-intro">
	<strong>Modulo por reino.</strong> Cada tarjeta puede funcionar como cuenta regresiva o como estado operativo. Los colores de Legado y Seasonal se aplican automaticamente en el frontend; la opacidad, blur, glow, posicion y comportamiento al finalizar son independientes.
</div>

<form action="" method="post">
	<div class="panel panel-default nex-cdv2-master">
		<div class="panel-heading"><strong>Control global</strong></div>
		<div class="panel-body nex-cdv2-two">
			<div class="form-group">
				<label>Sistema Countdown / Status</label>
				<select name="global[active]" class="form-control">
					<option value="1" <?php echo ((string)$globalConfig['active'] === '1') ? 'selected' : ''; ?>>Activo</option>
					<option value="0" <?php echo ((string)$globalConfig['active'] !== '1') ? 'selected' : ''; ?>>Desactivado</option>
				</select>
			</div>
			<div class="form-group">
				<label>Comportamiento en movil</label>
				<select name="global[mobile_layout]" class="form-control">
					<option value="swipe" <?php echo ((string)$globalConfig['mobile_layout'] === 'swipe') ? 'selected' : ''; ?>>Deslizable horizontal</option>
					<option value="stack" <?php echo ((string)$globalConfig['mobile_layout'] === 'stack') ? 'selected' : ''; ?>>Apilado vertical</option>
				</select>
				<span class="nex-cdv2-help">Si hay dos tarjetas en el Hero, "Deslizable" permite recorrer Legado y Seasonal con swipe en pantallas pequenas.</span>
			</div>
		</div>
	</div>

	<div class="nex-cdv2-grid">
	<?php foreach(array('legacy' => 'LEGADO', 'seasonal' => 'SEASONAL') as $realm => $realmLabel) { $cfg = $realmConfigs[$realm]; ?>
		<div class="nex-cdv2-card nex-cdv2-card--<?php echo $realm; ?>">
			<div class="nex-cdv2-head">
				<h3><?php echo $realmLabel; ?></h3>
				<p><?php echo $realm === 'legacy' ? 'Identidad dorado / naranja.' : 'Identidad violeta / arcana.'; ?></p>
			</div>
			<div class="nex-cdv2-body">
				<div class="nex-cdv2-section">
					<h4>Contenido</h4>
					<div class="nex-cdv2-two">
						<div class="form-group">
							<label>Modulo</label>
							<select name="realms[<?php echo $realm; ?>][active]" class="form-control">
								<option value="1" <?php echo ((string)$cfg['active'] === '1') ? 'selected' : ''; ?>>Activo</option>
								<option value="0" <?php echo ((string)$cfg['active'] !== '1') ? 'selected' : ''; ?>>Oculto</option>
							</select>
						</div>
						<div class="form-group">
							<label>Modo</label>
							<select name="realms[<?php echo $realm; ?>][mode]" class="form-control">
								<option value="countdown" <?php echo ($cfg['mode'] === 'countdown') ? 'selected' : ''; ?>>Cuenta regresiva</option>
								<option value="status" <?php echo ($cfg['mode'] === 'status') ? 'selected' : ''; ?>>Estado / aviso</option>
							</select>
						</div>
					</div>
					<div class="form-group">
						<label>Titulo</label>
						<input type="text" name="realms[<?php echo $realm; ?>][label]" class="form-control" value="<?php echo nexoraCountdownAdminValue($cfg['label']); ?>" maxlength="80">
					</div>
					<div class="form-group">
						<label>Mensaje</label>
						<textarea name="realms[<?php echo $realm; ?>][message]" class="form-control" rows="2" maxlength="220"><?php echo nexoraCountdownAdminValue($cfg['message']); ?></textarea>
					</div>
					<div class="form-group">
						<label>Estado cuando el modo es Estado / aviso</label>
						<select name="realms[<?php echo $realm; ?>][status_type]" class="form-control">
							<?php foreach($statusTypes as $value => $label) { ?>
								<option value="<?php echo $value; ?>" <?php echo ($cfg['status_type'] === $value) ? 'selected' : ''; ?>><?php echo $label; ?></option>
							<?php } ?>
						</select>
					</div>
				</div>

				<div class="nex-cdv2-section">
					<h4>Cuenta regresiva</h4>
					<div class="nex-cdv2-two">
						<div class="form-group">
							<label>Zona horaria</label>
							<select name="realms[<?php echo $realm; ?>][timezone]" class="form-control">
								<?php foreach($timezones as $tz => $tzLabel) { ?>
									<option value="<?php echo nexoraCountdownAdminValue($tz); ?>" <?php echo ($cfg['timezone'] === $tz) ? 'selected' : ''; ?>><?php echo nexoraCountdownAdminValue($tzLabel); ?></option>
								<?php } ?>
							</select>
						</div>
						<div class="form-group">
							<label>Fecha objetivo</label>
							<input type="text" name="realms[<?php echo $realm; ?>][target_date]" class="form-control" value="<?php echo nexoraCountdownAdminValue($cfg['target_date']); ?>" placeholder="2026-08-17 18:00:00">
						</div>
					</div>
					<div class="nex-cdv2-four">
						<?php foreach(array('display_days' => 'Dias', 'display_hours' => 'Horas', 'display_minutes' => 'Minutos', 'display_seconds' => 'Segundos') as $field => $label) { ?>
						<div class="checkbox"><label><input type="checkbox" name="realms[<?php echo $realm; ?>][<?php echo $field; ?>]" value="1" <?php echo ((string)$cfg[$field] === '1') ? 'checked' : ''; ?>> <?php echo $label; ?></label></div>
						<?php } ?>
					</div>
				</div>

				<div class="nex-cdv2-section">
					<h4>Ubicacion y apariencia</h4>
					<div class="nex-cdv2-two">
						<div class="form-group">
							<label>Posicion</label>
							<select name="realms[<?php echo $realm; ?>][placement]" class="form-control">
								<?php foreach($placements as $value => $label) { ?>
									<option value="<?php echo $value; ?>" <?php echo ($cfg['placement'] === $value) ? 'selected' : ''; ?>><?php echo $label; ?></option>
								<?php } ?>
							</select>
						</div>
						<div class="form-group">
							<label>Tamano</label>
							<select name="realms[<?php echo $realm; ?>][size]" class="form-control">
								<option value="compact" <?php echo ($cfg['size'] === 'compact') ? 'selected' : ''; ?>>Compacto</option>
								<option value="standard" <?php echo ($cfg['size'] === 'standard') ? 'selected' : ''; ?>>Estandar</option>
								<option value="wide" <?php echo ($cfg['size'] === 'wide') ? 'selected' : ''; ?>>Amplio</option>
							</select>
						</div>
					</div>
					<div class="nex-cdv2-two">
						<div class="form-group">
							<label>Desplazamiento X</label>
							<div class="nex-cdv2-range">
								<input type="range" min="-300" max="300" step="1" name="realms[<?php echo $realm; ?>][offset_x]" value="<?php echo nexoraCountdownAdminValue($cfg['offset_x']); ?>" data-nex-range="x-<?php echo $realm; ?>">
								<output data-nex-output="x-<?php echo $realm; ?>"><?php echo (int)$cfg['offset_x']; ?>px</output>
							</div>
						</div>
						<div class="form-group">
							<label>Desplazamiento Y</label>
							<div class="nex-cdv2-range">
								<input type="range" min="-300" max="300" step="1" name="realms[<?php echo $realm; ?>][offset_y]" value="<?php echo nexoraCountdownAdminValue($cfg['offset_y']); ?>" data-nex-range="y-<?php echo $realm; ?>">
								<output data-nex-output="y-<?php echo $realm; ?>"><?php echo (int)$cfg['offset_y']; ?>px</output>
							</div>
						</div>
					</div>
					<div class="form-group">
						<label>Transparencia del fondo</label>
						<div class="nex-cdv2-range">
							<input type="range" min="20" max="100" step="1" name="realms[<?php echo $realm; ?>][background_opacity]" value="<?php echo nexoraCountdownAdminValue($cfg['background_opacity']); ?>" data-nex-range="opacity-<?php echo $realm; ?>">
							<output data-nex-output="opacity-<?php echo $realm; ?>"><?php echo (int)$cfg['background_opacity']; ?>%</output>
						</div>
					</div>
					<div class="form-group">
						<label>Blur del fondo</label>
						<div class="nex-cdv2-range">
							<input type="range" min="0" max="30" step="1" name="realms[<?php echo $realm; ?>][blur]" value="<?php echo nexoraCountdownAdminValue($cfg['blur']); ?>" data-nex-range="blur-<?php echo $realm; ?>">
							<output data-nex-output="blur-<?php echo $realm; ?>"><?php echo (int)$cfg['blur']; ?>px</output>
						</div>
					</div>
					<div class="form-group">
						<label>Glow</label>
						<select name="realms[<?php echo $realm; ?>][glow]" class="form-control">
							<option value="off" <?php echo ($cfg['glow'] === 'off') ? 'selected' : ''; ?>>Desactivado</option>
							<option value="low" <?php echo ($cfg['glow'] === 'low') ? 'selected' : ''; ?>>Bajo</option>
							<option value="medium" <?php echo ($cfg['glow'] === 'medium') ? 'selected' : ''; ?>>Medio</option>
							<option value="high" <?php echo ($cfg['glow'] === 'high') ? 'selected' : ''; ?>>Alto</option>
						</select>
						<span class="nex-cdv2-help">El color no se configura aqui: se hereda de la identidad del reino para mantener consistencia visual.</span>
					</div>
				</div>

				<div class="nex-cdv2-section">
					<h4>CTA opcional</h4>
					<div class="nex-cdv2-two">
						<div class="form-group">
							<label>Texto del boton</label>
							<input type="text" name="realms[<?php echo $realm; ?>][cta_label]" class="form-control" value="<?php echo nexoraCountdownAdminValue($cfg['cta_label']); ?>" maxlength="40">
						</div>
						<div class="form-group">
							<label>URL</label>
							<input type="text" name="realms[<?php echo $realm; ?>][cta_url]" class="form-control" value="<?php echo nexoraCountdownAdminValue($cfg['cta_url']); ?>" placeholder="downloads/ o https://...">
						</div>
					</div>
				</div>

				<div class="nex-cdv2-section">
					<h4>Cuando el contador llegue a cero</h4>
					<div class="form-group">
						<label>Accion</label>
						<select name="realms[<?php echo $realm; ?>][after_action]" class="form-control">
							<option value="status" <?php echo ($cfg['after_action'] === 'status') ? 'selected' : ''; ?>>Transformar en estado / aviso</option>
							<option value="hide" <?php echo ($cfg['after_action'] === 'hide') ? 'selected' : ''; ?>>Ocultar tarjeta</option>
						</select>
					</div>
					<div class="form-group">
						<label>Estado posterior</label>
						<select name="realms[<?php echo $realm; ?>][after_status_type]" class="form-control">
							<?php foreach($statusTypes as $value => $label) { ?>
								<option value="<?php echo $value; ?>" <?php echo ($cfg['after_status_type'] === $value) ? 'selected' : ''; ?>><?php echo $label; ?></option>
							<?php } ?>
						</select>
					</div>
					<div class="form-group">
						<label>Titulo posterior</label>
						<input type="text" name="realms[<?php echo $realm; ?>][after_label]" class="form-control" value="<?php echo nexoraCountdownAdminValue($cfg['after_label']); ?>" maxlength="80">
					</div>
					<div class="form-group">
						<label>Mensaje posterior</label>
						<textarea name="realms[<?php echo $realm; ?>][after_message]" class="form-control" rows="2" maxlength="220"><?php echo nexoraCountdownAdminValue($cfg['after_message']); ?></textarea>
					</div>
					<div class="nex-cdv2-two">
						<div class="form-group">
							<label>Boton posterior</label>
							<input type="text" name="realms[<?php echo $realm; ?>][after_cta_label]" class="form-control" value="<?php echo nexoraCountdownAdminValue($cfg['after_cta_label']); ?>" maxlength="40">
						</div>
						<div class="form-group">
							<label>URL posterior</label>
							<input type="text" name="realms[<?php echo $realm; ?>][after_cta_url]" class="form-control" value="<?php echo nexoraCountdownAdminValue($cfg['after_cta_url']); ?>" placeholder="downloads/ o https://...">
						</div>
					</div>
				</div>
			</div>
		</div>
	<?php } ?>
	</div>

	<div class="nex-cdv2-submit">
		<input type="submit" name="submit_changes" value="Guardar configuracion" class="btn btn-success btn-lg">
	</div>
</form>

<script>
(function(){
	var ranges = document.querySelectorAll('[data-nex-range]');
	for(var i=0;i<ranges.length;i++){
		(function(input){
			var key = input.getAttribute('data-nex-range');
			var output = document.querySelector('[data-nex-output="'+key+'"]');
			if(!output) return;
			function sync(){ output.textContent = input.value + (key.indexOf('opacity-') === 0 ? '%' : 'px'); }
			input.addEventListener('input', sync);
			sync();
		})(ranges[i]);
	}
})();
</script>
