<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>
<section class="panel">
	<div class="actions" style="justify-content:space-between; margin-top:0; margin-bottom:18px; gap:12px;">
		<a class="btn btn-outline" href="<?php echo site_url('configuracion'); ?>">Regresar</a>
		<a class="btn" href="<?php echo site_url('configuracion/metas/nueva'); ?>">Agregar meta</a>
	</div>

	<h2 style="margin-bottom:10px;">Metas</h2>
	<p style="margin-bottom:18px;">Crea metas dinamicas por periodo, filtro, metodo y forma de visualizacion.</p>

	<div style="display:grid; gap:14px;">
		<?php if (empty($goal_definitions)) { ?>
			<div class="empty">Todavia no hay metas creadas.</div>
		<?php } else { ?>
			<?php foreach ($goal_definitions as $goal) { ?>
				<div style="padding:16px 18px; border-radius:22px; background:var(--panel); box-shadow:0 12px 24px rgba(20,41,64,0.08); display:grid; gap:12px;">
					<div style="display:flex; justify-content:space-between; align-items:flex-start; gap:12px;">
						<div style="display:grid; gap:6px;">
							<div style="font-size:calc(1.02rem * var(--app-text-size)); font-weight:800; color:var(--ink);">
								<?php echo htmlspecialchars($goal['name'], ENT_QUOTES, 'UTF-8'); ?>
							</div>
							<div style="font-size:calc(0.88rem * var(--app-text-size)); color:var(--muted); font-weight:700;">
								<?php echo !empty($goal['is_active']) ? 'Activa' : 'Inactiva'; ?>
							</div>
						</div>
						<a class="btn btn-outline" href="<?php echo site_url('configuracion/metas/'.(int)$goal['id']); ?>">Editar</a>
					</div>
					<div style="display:grid; gap:8px; font-size:calc(0.88rem * var(--app-text-size)); color:var(--muted);">
						<div><strong style="color:var(--ink);">Periodo:</strong> <?php echo htmlspecialchars($goal['period_label'], ENT_QUOTES, 'UTF-8'); ?></div>
						<div><strong style="color:var(--ink);">Filtro:</strong> <?php echo htmlspecialchars($goal['scope_label'], ENT_QUOTES, 'UTF-8'); ?><?php if (!empty($goal['scope_value_label'])) { ?> - <?php echo htmlspecialchars($goal['scope_value_label'], ENT_QUOTES, 'UTF-8'); ?><?php } ?></div>
						<div><strong style="color:var(--ink);">Medicion:</strong> <?php echo htmlspecialchars($goal['metric_label'], ENT_QUOTES, 'UTF-8'); ?></div>
						<div><strong style="color:var(--ink);">Metodo:</strong> <?php echo htmlspecialchars($goal['method_label'], ENT_QUOTES, 'UTF-8'); ?></div>
						<div><strong style="color:var(--ink);">Vista:</strong> <?php echo htmlspecialchars($goal['display_label'], ENT_QUOTES, 'UTF-8'); ?></div>
						<div><strong style="color:var(--ink);">Aplica a:</strong> <?php echo htmlspecialchars($goal['employee_label'], ENT_QUOTES, 'UTF-8'); ?></div>
						<?php if (!empty($goal['employee_mode']) && $goal['employee_mode'] === 'group') { ?>
							<div><strong style="color:var(--ink);">Modo:</strong> <?php echo !empty($goal['target_scope']) && $goal['target_scope'] === 'group_total' ? 'Total del grupo' : 'Individual'; ?></div>
						<?php } ?>
						<div><strong style="color:var(--ink);">Duracion:</strong> <?php echo htmlspecialchars($goal['run_once_label'], ENT_QUOTES, 'UTF-8'); ?></div>
					</div>
				</div>
			<?php } ?>
		<?php } ?>
	</div>
</section>
