<?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/grupos/nuevo'); ?>">Agregar grupo</a>
	</div>

	<h2 style="margin-bottom:10px;">Grupos</h2>
	<p style="margin-bottom:18px;">Crea grupos de empleados para usar luego en metas y configuraciones futuras.</p>

	<div style="display:grid; gap:14px;">
		<?php if (empty($groups)) { ?>
			<div class="empty">Todavia no hay grupos creados.</div>
		<?php } else { ?>
			<?php foreach ($groups as $group) { ?>
				<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="display:flex; align-items:center; gap:10px; font-size:calc(1.02rem * var(--app-text-size)); font-weight:800; color:var(--ink);">
								<span style="width:14px; height:14px; border-radius:999px; background:<?php echo htmlspecialchars(!empty($group['color']) ? $group['color'] : '#4d74c3', ENT_QUOTES, 'UTF-8'); ?>; display:inline-block;"></span>
								<?php echo htmlspecialchars($group['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($group['is_active']) ? 'Activo' : 'Inactivo'; ?> · <?php echo (int)$group['member_count']; ?> miembro(s)
							</div>
						</div>
						<a class="btn btn-outline" href="<?php echo site_url('configuracion/grupos/'.(int)$group['id']); ?>">Editar</a>
					</div>
					<?php if (!empty($group['member_names'])) { ?>
						<div style="font-size:calc(0.88rem * var(--app-text-size)); color:var(--muted);">
							<?php echo htmlspecialchars(implode(', ', $group['member_names']), ENT_QUOTES, 'UTF-8'); ?><?php echo (int)$group['member_count'] > count($group['member_names']) ? '...' : ''; ?>
						</div>
					<?php } ?>
				</div>
			<?php } ?>
		<?php } ?>
	</div>
</section>
