<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>
<style>
	.dashboard-grid {
		display: grid;
		grid-template-columns: repeat(3, minmax(0, 1fr));
		grid-template-areas:
			"global notifications tasks"
			"attendance metas tasks";
		gap: 16px;
		align-items: stretch;
	}
	.dashboard-stack,
	.dashboard-split {
		display: contents;
	}
	.dashboard-panel-global {
		grid-area: global;
	}
	.dashboard-panel-notifications {
		grid-area: notifications;
	}
	.dashboard-panel-attendance {
		grid-area: attendance;
	}
	.dashboard-panel-metas {
		grid-area: metas;
	}
	.dashboard-panel-tareas {
		grid-area: tasks;
	}
	.dashboard-panel {
		position: relative;
		overflow: hidden;
	}
	.dashboard-panel::before {
		content: "";
		position: absolute;
		inset: 0 0 auto 0;
		height: 84px;
		background: linear-gradient(180deg, rgba(77, 116, 195, 0.10), rgba(77, 116, 195, 0));
		pointer-events: none;
	}
	.panel-inner {
		position: relative;
		z-index: 1;
	}
	.panel-heading {
		display: flex;
		align-items: flex-start;
		justify-content: space-between;
		gap: 14px;
		margin-bottom: 16px;
	}
	.panel-heading-copy {
		display: grid;
		gap: 4px;
	}
	.panel-kicker {
		display: inline-flex;
		align-items: center;
		gap: 8px;
		color: var(--theme);
		font-size: 0.76rem;
		font-weight: 800;
		letter-spacing: 0.08em;
		text-transform: uppercase;
	}
	.section-title {
		display: flex;
		align-items: center;
		justify-content: space-between;
		gap: 12px;
		margin-bottom: 14px;
	}
	.section-title h2 {
		margin: 0;
	}
	.section-subtitle {
		margin: 2px 0 0;
		color: var(--muted);
		font-size: 0.86rem;
		line-height: 1.4;
	}
	.header-icon {
		display: inline-flex;
		align-items: center;
		justify-content: center;
		width: 42px;
		height: 42px;
		border-radius: 14px;
		background: var(--card-strong);
		color: var(--theme);
		font-size: 1.15rem;
		box-shadow: inset 0 0 0 1px rgba(77,116,195,0.08);
	}
	.goal-row {
		display: grid;
		gap: 8px;
		margin-bottom: 12px;
	}
	.goal-row:last-child {
		margin-bottom: 0;
	}
	.goal-row strong,
	.employee-card strong {
		font-size: 0.96rem;
	}
	.goal-meta {
		display: flex;
		align-items: center;
		justify-content: space-between;
		gap: 10px;
	}
	.goal-percent {
		color: var(--theme);
		font-size: 0.82rem;
		font-weight: 800;
	}
	.progress {
		height: 14px;
		border-radius: 999px;
		background: #e9eef5;
		overflow: hidden;
		box-shadow: inset 0 0 0 1px rgba(20,41,64,0.08);
	}
	.progress > span {
		display: block;
		height: 100%;
		background: linear-gradient(90deg, #7bc843, #98d245);
		border-radius: 999px;
	}
	.notice-list,
	.global-list,
	.employee-list,
	.task-list {
		display: grid;
		gap: 10px;
	}
	.global-item {
		padding: 12px 14px;
		border-radius: 18px;
		background: var(--card);
		box-shadow: inset 0 0 0 1px rgba(20,41,64,0.06);
		display: grid;
		gap: 8px;
	}
	.global-item-body {
		display: grid;
		gap: 6px;
	}
	.global-item-head {
		display: flex;
		align-items: center;
		justify-content: space-between;
		gap: 10px;
	}
	.global-item-meta {
		display: inline-flex;
		align-items: center;
		gap: 8px;
		flex-wrap: wrap;
		justify-content: flex-end;
	}
	.global-item-label {
		font-size: 0.78rem;
		font-weight: 800;
		text-transform: uppercase;
		letter-spacing: 0.06em;
		color: var(--muted);
	}
	.global-status {
		display: inline-flex;
		align-items: center;
		padding: 5px 10px;
		border-radius: 999px;
		font-size: 0.74rem;
		font-weight: 800;
		letter-spacing: 0.03em;
	}
	.global-status-active {
		background: #dff4e7;
		color: #18834d;
	}
	.global-status-finished {
		background: #e9edf5;
		color: #52657d;
	}
	.global-item-actions {
		display: flex;
		align-items: center;
		justify-content: space-between;
		gap: 10px;
		flex-wrap: wrap;
	}
	.global-assignment-status {
		display: inline-flex;
		align-items: center;
		padding: 7px 12px;
		border-radius: 999px;
		font-size: 0.82rem;
		font-weight: 800;
	}
	.notice-item,
	.attendance-item,
	.employee-card,
	.task-item {
		padding: 14px;
		border-radius: 20px;
		background: var(--card);
		box-shadow: inset 0 0 0 1px rgba(20,41,64,0.06);
	}
	.notice-item {
		display: grid;
		gap: 6px;
	}
	.notice-meta,
	.muted {
		color: var(--muted);
		font-size: 0.84rem;
	}
	.notice-item strong {
		line-height: 1.4;
	}
	.attendance-item {
		display: grid;
		grid-template-columns: minmax(0, 1fr) auto auto;
		gap: 10px;
		align-items: center;
	}
	.employee-chip {
		display: inline-flex;
		align-items: center;
		gap: 8px;
		font-weight: 800;
		color: var(--ink);
		text-decoration: none;
	}
	.employee-chip i {
		display: inline-flex;
		align-items: center;
		justify-content: center;
		width: 28px;
		height: 28px;
		border-radius: 10px;
		background: rgba(77,116,195,0.10);
		color: var(--theme);
	}
	.employee-card {
		display: grid;
		gap: 10px;
	}
	.employee-card-head {
		display: flex;
		align-items: center;
		justify-content: space-between;
		gap: 12px;
	}
	.employee-mini-stat {
		display: inline-flex;
		align-items: center;
		padding: 6px 10px;
		border-radius: 999px;
		background: #ffffff;
		color: var(--muted);
		font-size: 0.76rem;
		font-weight: 800;
		box-shadow: inset 0 0 0 1px rgba(20,41,64,0.08);
	}
	.task-item {
		display: grid;
		grid-template-columns: minmax(0, 1fr) auto auto;
		gap: 10px;
		align-items: center;
	}
	.task-item-title {
		font-weight: 700;
		line-height: 1.35;
	}
	.dashboard-task-panel .employee-list {
		gap: 8px;
	}
	.dashboard-task-panel .employee-card {
		padding: 10px 12px;
		border-radius: 18px;
		gap: 8px;
	}
	.dashboard-task-panel .employee-card-head {
		gap: 8px;
	}
	.dashboard-task-panel .employee-chip {
		gap: 6px;
		font-size: 0.98rem;
	}
	.dashboard-task-panel .employee-chip i {
		width: 24px;
		height: 24px;
		border-radius: 8px;
		font-size: 0.92rem;
	}
	.dashboard-task-panel .employee-mini-stat {
		padding: 4px 8px;
		font-size: 0.7rem;
	}
	.dashboard-task-panel .task-list {
		gap: 6px;
	}
	.dashboard-task-panel .task-item {
		padding: 10px 12px;
		border-radius: 16px;
		gap: 8px;
	}
	.dashboard-task-panel .task-item-title {
		font-size: 0.96rem;
		line-height: 1.2;
	}
	.dashboard-task-panel .task-item .btn {
		padding: 9px 12px;
		font-size: 0.82rem;
		min-height: auto;
	}
	.task-status-overdue {
		background: #fde2e1 !important;
		color: #b53d33 !important;
		box-shadow: none !important;
	}
	.task-status-progress {
		background: #fff2cc !important;
		color: #8a6200 !important;
		box-shadow: none !important;
	}
	.task-status-complete {
		background: #dff4e7 !important;
		color: #18834d !important;
		box-shadow: none !important;
	}
	.attendance-present {
		background: #dff4e7 !important;
		color: #18834d !important;
		box-shadow: none !important;
	}
	.attendance-absent {
		background: #fde2e1 !important;
		color: #b53d33 !important;
		box-shadow: none !important;
	}
	.modal-backdrop {
		position: fixed;
		inset: 0;
		background: rgba(15, 23, 42, 0.44);
		display: none;
		align-items: center;
		justify-content: center;
		padding: 24px;
		z-index: 999;
	}
	.modal-backdrop.is-open {
		display: flex;
	}
	.modal-card {
		width: min(520px, 100%);
		background: var(--panel);
		border-radius: 24px;
		box-shadow: 0 24px 60px rgba(15, 23, 42, 0.24);
		overflow: hidden;
	}
	.modal-header {
		display: flex;
		align-items: center;
		justify-content: space-between;
		gap: 12px;
		padding: 18px 20px;
		border-bottom: 1px solid var(--border);
	}
	.modal-header h3 {
		margin: 0;
	}
	.modal-close {
		width: 42px;
		height: 42px;
		border: 0;
		border-radius: 999px;
		background: var(--card);
		color: var(--ink);
		font-size: 1.2rem;
		cursor: pointer;
		box-shadow: inset 0 0 0 1px var(--border);
	}
	.modal-body {
		padding: 20px;
		display: grid;
		gap: 14px;
	}
	.modal-body textarea {
		width: 100%;
		min-height: 130px;
		border: 0;
		border-radius: 16px;
		padding: 14px;
		background: var(--field-bg);
		color: var(--field-ink);
		box-shadow: inset 0 0 0 1px rgba(20, 41, 64, 0.12);
		font-family: inherit;
		resize: vertical;
	}
	.modal-body input,
	.modal-body select {
		width: 100%;
		border: 0;
		border-radius: 16px;
		padding: 14px;
		background: var(--field-bg);
		color: var(--field-ink);
		box-shadow: inset 0 0 0 1px rgba(20, 41, 64, 0.12);
		font-family: inherit;
	}
	.modal-body input:focus,
	.modal-body select:focus,
	.modal-body textarea:focus {
		outline: none;
		box-shadow: inset 0 0 0 2px rgba(95, 143, 168, 0.42);
	}
	.modal-actions {
		display: flex;
		justify-content: flex-end;
		gap: 10px;
	}
	.task-modal-card {
		display: grid;
		gap: 18px;
	}
	.task-modal-head {
		display: flex;
		align-items: flex-start;
		justify-content: space-between;
		gap: 16px;
	}
	.task-modal-meta {
		display: flex;
		flex-wrap: wrap;
		gap: 10px;
		color: var(--muted);
		font-size: 0.92rem;
	}
	.task-modal-grid {
		display: grid;
		grid-template-columns: repeat(2, minmax(0, 1fr));
		gap: 16px;
	}
	.task-modal-section {
		background: var(--card);
		border-radius: 18px;
		padding: 16px;
		box-shadow: inset 0 0 0 1px var(--border);
	}
	.task-modal-section h4 {
		margin: 0 0 12px;
	}
	.task-modal-form-grid {
		display: grid;
		grid-template-columns: repeat(2, minmax(0, 1fr));
		gap: 12px;
		margin-bottom: 12px;
	}
	.task-field {
		display: grid;
		gap: 6px;
		color: var(--muted);
		font-size: 0.92rem;
	}
	.task-field input,
	.task-field textarea,
	.task-field select {
		width: 100%;
		border: 0;
		border-radius: 14px;
		padding: 14px 16px;
		background: #ffffff;
		color: var(--field-ink);
		box-shadow: inset 0 0 0 1px rgba(20, 41, 64, 0.12);
		font-family: inherit;
		font-size: 0.98rem;
	}
	.task-modal-list {
		display: grid;
		gap: 10px;
	}
	.task-modal-row,
	.task-modal-note {
		background: #fff;
		border-radius: 14px;
		padding: 12px;
		box-shadow: inset 0 0 0 1px var(--border);
	}
	.task-modal-row {
		display: flex;
		align-items: center;
		justify-content: space-between;
		gap: 12px;
	}
	.quick-task-modal-form {
		display: grid;
		gap: 14px;
	}
	.quick-task-modal-form label {
		display: grid;
		gap: 6px;
		color: var(--muted);
		font-size: 0.9rem;
	}
	@media (max-width: 1180px) {
		.dashboard-grid,
		.dashboard-split {
			grid-template-columns: 1fr;
		}
	}
	@media (max-width: 1200px) {
		.dashboard-grid {
			grid-template-columns: repeat(2, minmax(0, 1fr));
			grid-template-areas:
				"global notifications"
				"attendance metas"
				"tasks tasks";
		}
	}
	@media (max-width: 820px) {
		.dashboard-grid {
			grid-template-columns: 1fr;
			grid-template-areas:
				"global"
				"notifications"
				"attendance"
				"metas"
				"tasks";
		}
	}</style>

<div class="dashboard-grid">
	<div class="dashboard-stack">
		<section class="panel dashboard-panel dashboard-panel-global">
			<div class="panel-inner">
				<div class="panel-heading">
					<div class="panel-heading-copy">
						<h2>Global</h2>
					</div>
					<span class="header-icon"><i class="ion-stats-bars"></i></span>
				</div>
				<?php if (empty($global_goals_dashboard) && empty($global_rules_dashboard)) { ?>
					<div class="empty">No hay configuracion global para mostrar.</div>
				<?php } else { ?>
					<div class="global-list">
						<?php foreach ((array)$global_goals_dashboard as $goal) { ?>
							<?php $percent = isset($goal['progress_percent']) ? (int)$goal['progress_percent'] : 0; ?>
							<div class="global-item">
								<div class="global-item-head">
									<span class="global-item-label">Meta global</span>
									<span class="global-item-meta">
										<span class="global-status global-status-<?php echo !empty($goal['status_class']) ? htmlspecialchars((string)$goal['status_class'], ENT_QUOTES, 'UTF-8') : 'active'; ?>">
											<?php echo htmlspecialchars(!empty($goal['status_label']) ? (string)$goal['status_label'] : 'Activa', ENT_QUOTES, 'UTF-8'); ?>
										</span>
										<span class="goal-percent"><?php echo max(0, min(100, $percent)); ?>%</span>
									</span>
								</div>
								<div class="global-item-body">
									<strong><?php echo htmlspecialchars((string)$goal['name'], ENT_QUOTES, 'UTF-8'); ?></strong>
									<div class="progress"><span style="width: <?php echo max(0, min(100, $percent)); ?>%;"></span></div>
								</div>
							</div>
						<?php } ?>
						<?php foreach ((array)$global_rules_dashboard as $rule) { ?>
							<?php
								$assignment_status_class = 'task-status-progress';
								if (!empty($rule['assignment_status_class']) && (string)$rule['assignment_status_class'] === 'success')
								{
									$assignment_status_class = 'task-status-complete';
								}
								elseif (!empty($rule['assignment_status_class']) && (string)$rule['assignment_status_class'] === 'danger')
								{
									$assignment_status_class = 'task-status-overdue';
								}
							?>
							<div class="global-item">
								<div class="global-item-head">
									<span class="global-item-label">Tarea global</span>
									<span class="global-item-meta">
										<span class="global-status global-status-<?php echo !empty($rule['status_class']) ? htmlspecialchars((string)$rule['status_class'], ENT_QUOTES, 'UTF-8') : 'active'; ?>">
											<?php echo htmlspecialchars(!empty($rule['status_label']) ? (string)$rule['status_label'] : 'Activa', ENT_QUOTES, 'UTF-8'); ?>
										</span>
										<span class="employee-mini-stat js-global-task-date"><?php echo !empty($rule['assignment_due_date_label']) ? htmlspecialchars((string)$rule['assignment_due_date_label'], ENT_QUOTES, 'UTF-8') : (!empty($rule['next_due_date_label']) ? htmlspecialchars((string)$rule['next_due_date_label'], ENT_QUOTES, 'UTF-8') : 'Sin fecha'); ?></span>
									</span>
								</div>
								<div class="global-item-body">
									<strong><?php echo htmlspecialchars(!empty($rule['display_name']) ? (string)$rule['display_name'] : 'Tarea global', ENT_QUOTES, 'UTF-8'); ?></strong>
									<div class="muted"><?php echo htmlspecialchars(!empty($rule['recurrence_label']) ? (string)$rule['recurrence_label'] : 'Sin recurrencia', ENT_QUOTES, 'UTF-8'); ?></div>
									<?php if (!empty($rule['assignment_id'])) { ?>
										<div class="global-item-actions" data-assignment-id="<?php echo (int)$rule['assignment_id']; ?>">
											<span class="global-assignment-status js-global-task-status <?php echo $assignment_status_class; ?>">
												<?php echo htmlspecialchars(!empty($rule['assignment_status_label']) ? (string)$rule['assignment_status_label'] : 'Pendiente', ENT_QUOTES, 'UTF-8'); ?>
											</span>
											<button
												class="btn <?php echo !empty($rule['assignment_action_type']) && (string)$rule['assignment_action_type'] === 'reactivate' ? 'btn-outline' : ''; ?> js-global-task-action"
												type="button"
												data-assignment-id="<?php echo (int)$rule['assignment_id']; ?>"
												data-action-type="<?php echo htmlspecialchars(!empty($rule['assignment_action_type']) ? (string)$rule['assignment_action_type'] : 'complete', ENT_QUOTES, 'UTF-8'); ?>"
											>
												<?php echo htmlspecialchars(!empty($rule['assignment_action_label']) ? (string)$rule['assignment_action_label'] : 'Completar', ENT_QUOTES, 'UTF-8'); ?>
											</button>
										</div>
									<?php } else { ?>
										<div class="muted">Sin tarea global pendiente para hoy.</div>
									<?php } ?>
								</div>
							</div>
						<?php } ?>
					</div>
				<?php } ?>
			</div>
		</section>

		<section class="panel dashboard-panel dashboard-panel-attendance">
			<div class="panel-inner">
				<div class="panel-heading">
					<div class="panel-heading-copy">
						<span class="panel-kicker">Hoy</span>
						<h2>Asistencia</h2>
					</div>
					<span class="header-icon"><i class="ion-checkmark-circled"></i></span>
				</div>
				<?php if (empty($attendance)) { ?>
					<div class="empty">No hay empleados para mostrar.</div>
				<?php } else { ?>
					<div class="employee-list">
						<?php foreach ($attendance as $row) { ?>
							<div class="attendance-item">
								<span class="employee-chip">
									<i class="ion-person"></i>
									<span><?php echo htmlspecialchars((string)$row['name'], ENT_QUOTES, 'UTF-8'); ?></span>
								</span>
								<button
									class="btn attendance-toggle <?php echo !empty($row['is_present']) ? 'attendance-present' : 'attendance-absent'; ?>"
									type="button"
									data-employee-id="<?php echo (int)$row['employee_id']; ?>"
									data-is-present="<?php echo !empty($row['is_present']) ? '1' : '0'; ?>"
								>
									<?php echo !empty($row['is_present']) ? 'Asistio' : 'Falto'; ?>
								</button>
								<button
									class="btn btn-outline js-attendance-note"
									type="button"
									data-employee-id="<?php echo (int)$row['employee_id']; ?>"
									data-employee-name="<?php echo htmlspecialchars((string)$row['name'], ENT_QUOTES, 'UTF-8'); ?>"
									data-note="<?php echo htmlspecialchars(isset($row['note']) ? (string)$row['note'] : '', ENT_QUOTES, 'UTF-8'); ?>"
								>Nota</button>
							</div>
						<?php } ?>
					</div>
				<?php } ?>
			</div>
		</section>
	</div>

	<div class="dashboard-stack">
		<section class="panel dashboard-panel dashboard-panel-notifications">
			<div class="panel-inner">
				<div class="panel-heading">
					<div class="panel-heading-copy">
						<h2>Notificaciones</h2>
					</div>
					<div class="actions" style="margin-top:0;">
						<a class="btn btn-outline" href="<?php echo site_url('notificaciones'); ?>">Ver</a>
						<button class="btn" type="button" id="dashboard-notice-open">Agregar</button>
					</div>
				</div>
				<?php if (empty($notifications)) { ?>
					<div id="dashboard-notice-empty" class="empty">Sin notificaciones recientes.</div>
				<?php } else { ?>
					<div id="dashboard-notice-empty" class="empty" style="display:none;">Sin notificaciones recientes.</div>
					<div class="notice-list" id="dashboard-notice-list">
						<?php foreach ($notifications as $notification) { ?>
							<div class="notice-item">
								<strong><?php echo htmlspecialchars((string)$notification['message'], ENT_QUOTES, 'UTF-8'); ?></strong>
								<div class="notice-meta">
									<?php echo htmlspecialchars((string)$notification['created_by_name'], ENT_QUOTES, 'UTF-8'); ?>
								</div>
							</div>
						<?php } ?>
					</div>
				<?php } ?>
			</div>
		</section>

		<div class="dashboard-split">
			<section class="panel dashboard-panel dashboard-panel-metas">
				<div class="panel-inner">
					<div class="panel-heading">
						<div class="panel-heading-copy">
							<h2>Metas</h2>
						</div>
						<span class="header-icon"><i class="ion-podium"></i></span>
					</div>
					<?php if (empty($goal_cards)) { ?>
						<div class="empty">No hay metas para mostrar.</div>
					<?php } else { ?>
						<div class="employee-list">
							<?php foreach ($goal_cards as $goal_card) { ?>
								<div class="employee-card">
									<div class="employee-card-head">
										<span class="employee-chip">
											<i class="ion-podium"></i>
											<span><?php echo htmlspecialchars((string)$goal_card['name'], ENT_QUOTES, 'UTF-8'); ?></span>
										</span>
										<span class="employee-mini-stat"><?php echo (int)$goal_card['participants']; ?> participantes</span>
									</div>
									<div class="goal-row" style="margin-bottom:0;">
										<div class="goal-meta">
											<span>Completacion general</span>
											<span class="goal-percent"><?php echo (int)$goal_card['average_progress_percent']; ?>%</span>
										</div>
										<div class="progress"><span style="width: <?php echo (int)$goal_card['average_progress_percent']; ?>%;"></span></div>
									</div>
									<div class="goal-meta" style="margin-top:8px;">
										<span>Personas completadas</span>
										<span class="goal-percent"><?php echo htmlspecialchars((string)$goal_card['completion_label'], ENT_QUOTES, 'UTF-8'); ?></span>
									</div>
								</div>
							<?php } ?>
						</div>
					<?php } ?>
				</div>
			</section>

			<section class="panel dashboard-panel dashboard-task-panel dashboard-panel-tareas">
	<div class="panel-inner">
		<div class="panel-heading">
			<div class="panel-heading-copy">
				<h2>Tareas</h2>
			</div>
			<div class="actions" style="margin-top:0;">
				<button class="btn btn-outline" type="button" id="dashboard-quick-task-open">Agregar</button>
				<a class="btn" href="<?php echo site_url('tareas'); ?>">Abrir</a>
			</div>
		</div>
		<?php if (empty($task_cards)) { ?>
			<div id="dashboard-task-empty" class="empty">No hay empleados con tareas activas.</div>
		<?php } else { ?>
			<div id="dashboard-task-empty" class="empty" style="display:none;">No hay empleados con tareas activas.</div>
			<div class="employee-list" id="dashboard-task-list">
				<?php foreach ($task_cards as $card) { ?>
					<div class="employee-card dashboard-task-summary-card" data-dashboard-employee-card="<?php echo (int)$card['employee_id']; ?>" data-dashboard-completed="<?php echo (int)$card['completed_count']; ?>" data-dashboard-total="<?php echo (int)$card['total_count']; ?>" data-dashboard-active="<?php echo (int)$card['active_count']; ?>">
						<div class="employee-card-head">
							<span class="employee-chip">
								<i class="ion-person"></i>
								<span><?php echo htmlspecialchars((string)$card['name'], ENT_QUOTES, 'UTF-8'); ?></span>
							</span>
							<span class="employee-mini-stat" data-dashboard-completion-label><?php echo htmlspecialchars((string)$card['completion_label'], ENT_QUOTES, 'UTF-8'); ?></span>
						</div>
						<div class="progress"><span data-dashboard-progress-bar style="width: <?php echo (int)$card['completion_percent']; ?>%;"></span></div>

					</div>
				<?php } ?>
			</div>
		<?php } ?>
	</div>
</section>
		</div>
	</div>
</div>

<div id="dashboard-task-modal" class="modal-backdrop" aria-hidden="true">
	<div class="modal-card" role="dialog" aria-modal="true" aria-labelledby="dashboard-task-modal-title" style="width:min(760px,100%); max-height:min(80vh,820px); display:flex; flex-direction:column;">
		<div class="modal-header">
			<h3 id="dashboard-task-modal-title">Detalle de tarea</h3>
			<button class="modal-close" type="button" data-role="close-dashboard-task-modal" aria-label="Cerrar">x</button>
		</div>
		<div id="dashboard-task-modal-body" class="modal-body" style="overflow:auto; min-height:220px;">
			<div class="empty">Cargando...</div>
		</div>
	</div>
</div>

<div id="dashboard-notice-modal" class="modal-backdrop" aria-hidden="true">
	<div class="modal-card" role="dialog" aria-modal="true" aria-labelledby="dashboard-notice-title">
		<div class="modal-header">
			<h3 id="dashboard-notice-title">Nueva notificacion</h3>
			<button class="modal-close" type="button" data-role="close-dashboard-notice" aria-label="Cerrar">x</button>
		</div>
		<div class="modal-body">
			<form id="dashboard-notice-form" class="quick-task-modal-form">
				<label for="dashboard-notice-message">
					<span>Mensaje</span>
					<textarea id="dashboard-notice-message" name="message" placeholder="Escribe una notificacion para el equipo..." required></textarea>
				</label>
				<div class="modal-actions">
					<button class="btn btn-outline" type="button" id="dashboard-notice-cancel">Cancelar</button>
					<button class="btn" type="submit" id="dashboard-notice-save">Publicar</button>
				</div>
			</form>
		</div>
	</div>
</div>
<div id="dashboard-quick-task-modal" class="modal-backdrop" aria-hidden="true">
	<div class="modal-card" role="dialog" aria-modal="true" aria-labelledby="dashboard-quick-task-title">
		<div class="modal-header">
			<h3 id="dashboard-quick-task-title">Agregar tarea rapida</h3>
			<button class="modal-close" type="button" data-role="close-dashboard-quick-task" aria-label="Cerrar">x</button>
		</div>
		<div class="modal-body">
			<form id="dashboard-quick-task-form" class="quick-task-modal-form">
				<label for="dashboard-quick-task-name">
					<span>Nombre de la tarea</span>
					<input id="dashboard-quick-task-name" name="title" type="text" maxlength="255" placeholder="Escribe la tarea..." />
				</label>
				<label for="dashboard-quick-task-employee">
					<span>Empleado</span>
					<select id="dashboard-quick-task-employee" name="employee_id">
						<option value="">Selecciona un empleado</option>
						<?php foreach ((array)$all_employees as $employee_option) { ?>
							<?php $employee_option_id = isset($employee_option['person_id']) ? (int)$employee_option['person_id'] : 0; ?>
							<?php if ($employee_option_id <= 0) { continue; } ?>
							<option value="<?php echo $employee_option_id; ?>">
								<?php echo htmlspecialchars(!empty($employee_option['full_name']) ? (string)$employee_option['full_name'] : 'Empleado', ENT_QUOTES, 'UTF-8'); ?>
							</option>
						<?php } ?>
					</select>
				</label>
				<div class="modal-actions">
					<button class="btn btn-outline" type="button" id="dashboard-quick-task-cancel">Cancelar</button>
					<button class="btn" type="submit" id="dashboard-quick-task-save">Aceptar</button>
				</div>
			</form>
		</div>
	</div>
</div>

<div id="attendance-note-modal" class="modal-backdrop" aria-hidden="true">
	<div class="modal-card" role="dialog" aria-modal="true" aria-labelledby="attendance-note-title">
		<div class="modal-header">
			<h3 id="attendance-note-title">Nota de asistencia</h3>
			<button class="modal-close" type="button" data-role="close-attendance-note" aria-label="Cerrar">x</button>
		</div>
		<div class="modal-body">
			<div class="muted" id="attendance-note-employee">Empleado</div>
			<textarea id="attendance-note-text" placeholder="Escribe una nota para la asistencia de hoy..."></textarea>
			<div class="modal-actions">
				<button class="btn btn-outline" type="button" id="attendance-note-cancel">Cancelar</button>
				<button class="btn" type="button" id="attendance-note-save">Aceptar</button>
			</div>
		</div>
	</div>
</div>

<script>
	(function () {
		var buttons = document.querySelectorAll('.attendance-toggle');
		var noteButtons = document.querySelectorAll('.js-attendance-note');
		var noteModal = document.getElementById('attendance-note-modal');
		var noteEmployee = document.getElementById('attendance-note-employee');
		var noteText = document.getElementById('attendance-note-text');
		var noteSave = document.getElementById('attendance-note-save');
		var noteCancel = document.getElementById('attendance-note-cancel');
		var dashboardNoticeList = document.getElementById('dashboard-notice-list');
		var dashboardNoticeEmpty = document.getElementById('dashboard-notice-empty');
		var dashboardNoticeModal = document.getElementById('dashboard-notice-modal');
		var dashboardNoticeOpen = document.getElementById('dashboard-notice-open');
		var dashboardNoticeForm = document.getElementById('dashboard-notice-form');
		var dashboardNoticeMessage = document.getElementById('dashboard-notice-message');
		var dashboardNoticeSave = document.getElementById('dashboard-notice-save');
		var dashboardNoticeCancel = document.getElementById('dashboard-notice-cancel');
		var dashboardTaskList = document.getElementById('dashboard-task-list');
		var dashboardTaskEmpty = document.getElementById('dashboard-task-empty');
		var dashboardQuickTaskModal = document.getElementById('dashboard-quick-task-modal');
		var dashboardQuickTaskOpen = document.getElementById('dashboard-quick-task-open');
		var dashboardQuickTaskForm = document.getElementById('dashboard-quick-task-form');
		var dashboardQuickTaskName = document.getElementById('dashboard-quick-task-name');
		var dashboardQuickTaskSave = document.getElementById('dashboard-quick-task-save');
		var dashboardQuickTaskCancel = document.getElementById('dashboard-quick-task-cancel');
		var dashboardTaskModal = document.getElementById('dashboard-task-modal');
		var dashboardTaskModalBody = document.getElementById('dashboard-task-modal-body');
		var dashboardTaskModalTitle = document.getElementById('dashboard-task-modal-title');
		var activeNoteButton = null;

		function escapeHtml(value) {
			return String(value || '')
				.replace(/&/g, '&amp;')
				.replace(/</g, '&lt;')
				.replace(/>/g, '&gt;')
				.replace(/"/g, '&quot;')
				.replace(/'/g, '&#039;');
		}

		function applyState(button, isPresent) {
			button.classList.toggle('attendance-present', isPresent);
			button.classList.toggle('attendance-absent', !isPresent);
			button.textContent = isPresent ? 'Asistio' : 'Falto';
			button.dataset.isPresent = isPresent ? '1' : '0';
		}

		function openNoteModal(button) {
			if (!noteModal || !noteText || !noteEmployee) {
				return;
			}
			activeNoteButton = button;
			noteEmployee.textContent = button.dataset.employeeName || 'Empleado';
			noteText.value = button.dataset.note || '';
			noteModal.classList.add('is-open');
			noteModal.setAttribute('aria-hidden', 'false');
			document.body.style.overflow = 'hidden';
			noteText.focus();
		}

		function closeNoteModal() {
			if (!noteModal) {
				return;
			}
			noteModal.classList.remove('is-open');
			noteModal.setAttribute('aria-hidden', 'true');
			document.body.style.overflow = '';
			activeNoteButton = null;
		}

		function openDashboardTaskModal() {
			if (!dashboardTaskModal) {
				return;
			}
			dashboardTaskModal.classList.add('is-open');
			dashboardTaskModal.setAttribute('aria-hidden', 'false');
			document.body.style.overflow = 'hidden';
		}

		function closeDashboardTaskModal() {
			if (!dashboardTaskModal || !dashboardTaskModalBody) {
				return;
			}
			dashboardTaskModal.classList.remove('is-open');
			dashboardTaskModal.setAttribute('aria-hidden', 'true');
			dashboardTaskModalTitle.textContent = 'Detalle de tarea';
			dashboardTaskModalBody.innerHTML = '<div class="empty">Cargando...</div>';
			document.body.style.overflow = '';
		}

		function wireDashboardTaskModalInteractions() {
			if (!dashboardTaskModalBody) {
				return;
			}

			var toggleButton = dashboardTaskModalBody.querySelector('.js-modal-edit-toggle');
			var cancelButton = dashboardTaskModalBody.querySelector('.js-modal-edit-cancel');
			var editForm = dashboardTaskModalBody.querySelector('.js-modal-edit-form');

			if (toggleButton && editForm) {
				toggleButton.addEventListener('click', function () {
					editForm.style.display = editForm.style.display === 'none' ? '' : 'none';
				});
			}

			if (cancelButton && editForm) {
				cancelButton.addEventListener('click', function () {
					editForm.style.display = 'none';
				});
			}

			if (editForm) {
				editForm.addEventListener('submit', async function (event) {
					event.preventDefault();
					var submitButton = editForm.querySelector('button[type="submit"]');
					if (submitButton) {
						submitButton.disabled = true;
					}

					try {
						const response = await fetch(editForm.action, {
							method: 'POST',
							headers: {
								'X-Requested-With': 'XMLHttpRequest',
								'Accept': 'application/json'
							},
							body: new FormData(editForm),
							credentials: 'same-origin'
						});
						const payload = await response.json().catch(function () {
							return null;
						});

						if (payload && payload.html) {
							dashboardTaskModalTitle.textContent = payload.title || 'Detalle de tarea';
							dashboardTaskModalBody.innerHTML = payload.html;
							wireDashboardTaskModalInteractions();
						}
					} catch (error) {
					} finally {
						if (submitButton) {
							submitButton.disabled = false;
						}
					}
				});
			}
		}
		function openDashboardNoticeModal() {
			if (!dashboardNoticeModal) {
				return;
			}
			dashboardNoticeModal.classList.add('is-open');
			dashboardNoticeModal.setAttribute('aria-hidden', 'false');
			document.body.style.overflow = 'hidden';
			if (dashboardNoticeMessage) {
				dashboardNoticeMessage.focus();
			}
		}

		function closeDashboardNoticeModal() {
			if (!dashboardNoticeModal) {
				return;
			}
			dashboardNoticeModal.classList.remove('is-open');
			dashboardNoticeModal.setAttribute('aria-hidden', 'true');
			document.body.style.overflow = '';
			if (dashboardNoticeForm) {
				dashboardNoticeForm.reset();
			}
		}
		function openDashboardQuickTaskModal() {
			if (!dashboardQuickTaskModal) {
				return;
			}
			dashboardQuickTaskModal.classList.add('is-open');
			dashboardQuickTaskModal.setAttribute('aria-hidden', 'false');
			document.body.style.overflow = 'hidden';
			if (dashboardQuickTaskName) {
				dashboardQuickTaskName.focus();
			}
		}

		function closeDashboardQuickTaskModal() {
			if (!dashboardQuickTaskModal) {
				return;
			}
			dashboardQuickTaskModal.classList.remove('is-open');
			dashboardQuickTaskModal.setAttribute('aria-hidden', 'true');
			document.body.style.overflow = '';
			if (dashboardQuickTaskForm) {
				dashboardQuickTaskForm.reset();
			}
		}

		function getDashboardTaskStatusMeta(status) {
			var label = 'Pendiente';
			var css = 'task-status-progress';
			if (status === 'completed') {
				label = 'Completada';
				css = 'task-status-complete';
			} else if (status === 'in_progress') {
				label = 'Parcial';
				css = 'task-status-progress';
			} else if (status === 'overdue') {
				label = 'Vencida';
				css = 'task-status-overdue';
			}
			return { label: label, css: css };
		}

		function syncDashboardTaskEmpty() {
			if (!dashboardTaskList || !dashboardTaskEmpty) {
				return;
			}
			var hasCards = !!dashboardTaskList.querySelector('[data-dashboard-employee-card]');
			dashboardTaskList.style.display = hasCards ? '' : 'none';
			dashboardTaskEmpty.style.display = hasCards ? 'none' : '';
		}

		function syncDashboardNoticeEmpty() {
			if (!dashboardNoticeEmpty) {
				return;
			}
			var hasItems = !!(dashboardNoticeList && dashboardNoticeList.querySelector('.notice-item'));
			if (dashboardNoticeList) {
				dashboardNoticeList.style.display = hasItems ? '' : 'none';
			}
			dashboardNoticeEmpty.style.display = hasItems ? 'none' : '';
		}

		function prependDashboardNotice(notification) {
			if (!notification || !dashboardNoticeEmpty) {
				return;
			}
			if (!dashboardNoticeList) {
				dashboardNoticeEmpty.insertAdjacentHTML('afterend', '<div class="notice-list" id="dashboard-notice-list"></div>');
				dashboardNoticeList = document.getElementById('dashboard-notice-list');
			}
			if (!dashboardNoticeList) {
				return;
			}
			var html = '' +
				'<div class="notice-item">' +
					'<strong>' + escapeHtml(notification.message || '') + '</strong>' +
					'<div class="notice-meta">' + escapeHtml(notification.created_by_name || 'Supervisor') + '</div>' +
				'</div>';
			dashboardNoticeList.insertAdjacentHTML('afterbegin', html);
			syncDashboardNoticeEmpty();
		}
						function formatDashboardTaskCompletion(completed, total) {
			return completed + '/' + total;
		}

		function formatDashboardTaskActiveLabel(active) {
			return active + (active === 1 ? ' activa' : ' activas');
		}

		function calculateDashboardTaskCompletionPercent(completed, total) {
			if (total <= 0) {
				return 0;
			}
			return Math.max(0, Math.min(100, Math.round((completed / total) * 100)));
		}

		function syncDashboardTaskCard(card) {
			if (!card) {
				return;
			}
			var completed = parseInt(card.getAttribute('data-dashboard-completed') || '0', 10);
			var total = parseInt(card.getAttribute('data-dashboard-total') || '0', 10);
			var active = parseInt(card.getAttribute('data-dashboard-active') || '0', 10);
			var percent = calculateDashboardTaskCompletionPercent(completed, total);
			var completionNodes = card.querySelectorAll('[data-dashboard-completion-label]');
			completionNodes.forEach(function (node) {
				node.textContent = formatDashboardTaskCompletion(completed, total);
			});
			var percentNode = card.querySelector('[data-dashboard-completion-percent]');
			if (percentNode) {
				percentNode.textContent = percent + '%';
			}

			var progressBar = card.querySelector('[data-dashboard-progress-bar]');
			if (progressBar) {
				progressBar.style.width = percent + '%';
			}
		}

		function ensureDashboardEmployeeCard(assignment) {
			if (!dashboardTaskList || !assignment || !assignment.employee_id) {
				return null;
			}
			var employeeId = parseInt(assignment.employee_id, 10);
			var card = dashboardTaskList.querySelector('[data-dashboard-employee-card="' + employeeId + '"]');
			if (card) {
				return card;
			}
			var html = '' +
				'<div class="employee-card dashboard-task-summary-card" data-dashboard-employee-card="' + employeeId + '" data-dashboard-completed="0" data-dashboard-total="0" data-dashboard-active="0">' +
					'<div class="employee-card-head">' +
						'<span class="employee-chip">' +
							'<i class="ion-person"></i>' +
							'<span>' + escapeHtml(assignment.employee_name || 'Empleado') + '</span>' +
						'</span>' +
						'<span class="employee-mini-stat" data-dashboard-completion-label>0/0</span>' +
					'</div>' +

					'<div class="progress"><span data-dashboard-progress-bar style="width: 0%;"></span></div>' +

				'</div>';
			dashboardTaskList.insertAdjacentHTML('afterbegin', html);
			card = dashboardTaskList.querySelector('[data-dashboard-employee-card="' + employeeId + '"]');
			syncDashboardTaskCard(card);
			return card;
		}

		function prependDashboardTask(assignment) {
			var card = ensureDashboardEmployeeCard(assignment);
			if (!card) {
				return;
			}
			var total = parseInt(card.getAttribute('data-dashboard-total') || '0', 10);
			var active = parseInt(card.getAttribute('data-dashboard-active') || '0', 10);
			card.setAttribute('data-dashboard-total', String(total + 1));
			card.setAttribute('data-dashboard-active', String(active + 1));
			syncDashboardTaskCard(card);
			syncDashboardTaskEmpty();
		}

		buttons.forEach(function (button) {
			button.addEventListener('click', function () {
				var employeeId = button.dataset.employeeId;
				var current = button.dataset.isPresent === '1';
				var next = !current;
				applyState(button, next);

				var formData = new FormData();
				formData.append('employee_id', employeeId);
				formData.append('is_present', next ? '1' : '0');

				fetch('<?php echo site_url('dashboard/attendance'); ?>', {
					method: 'POST',
					body: formData
				}).then(function (response) {
					return response.json();
				}).then(function (payload) {
					if (!payload || !payload.success) {
						applyState(button, current);
					}
				}).catch(function () {
					applyState(button, current);
				});
			});
		});

		noteButtons.forEach(function (button) {
			button.addEventListener('click', function () {
				openNoteModal(button);
			});
		});
		document.addEventListener('click', function (event) {
			var button = event.target.closest('.js-dashboard-task-action');
			if (!button || !dashboardTaskModalBody) {
				return;
			}
			var url = button.getAttribute('data-url');
			if (!url) {
				return;
			}

			dashboardTaskModalTitle.textContent = 'Detalle de tarea';
			dashboardTaskModalBody.innerHTML = '<div class="empty">Cargando...</div>';
			openDashboardTaskModal();

			fetch(url, {
				headers: {
					'X-Requested-With': 'XMLHttpRequest',
					'Accept': 'application/json'
				},
				credentials: 'same-origin'
			}).then(function (response) {
				return response.json().then(function (payload) {
					return { ok: response.ok, payload: payload };
				}).catch(function () {
					return { ok: false, payload: null };
				});
			}).then(function (result) {
				if (!result.ok || !result.payload || !result.payload.success) {
					window.location.href = url;
					return;
				}

				dashboardTaskModalTitle.textContent = result.payload.title || 'Detalle de tarea';
				dashboardTaskModalBody.innerHTML = result.payload.html || '<div class="empty">No encontramos el detalle.</div>';
				wireDashboardTaskModalInteractions();
			}).catch(function () {
				window.location.href = url;
			});
		});

		if (noteSave) {
			noteSave.addEventListener('click', function () {
				if (!activeNoteButton) {
					return;
				}

				var employeeId = activeNoteButton.dataset.employeeId;
				var row = activeNoteButton.closest('.attendance-item');
				var toggleButton = row ? row.querySelector('.attendance-toggle') : null;
				var isPresent = toggleButton && toggleButton.dataset.isPresent === '1';
				var noteValue = noteText ? noteText.value : '';
				var formData = new FormData();
				formData.append('employee_id', employeeId);
				formData.append('is_present', isPresent ? '1' : '0');
				formData.append('note', noteValue);

				noteSave.disabled = true;
				fetch('<?php echo site_url('dashboard/attendance'); ?>', {
					method: 'POST',
					body: formData
				}).then(function (response) {
					return response.json();
				}).then(function (payload) {
					if (!payload || !payload.success) {
						return;
					}
					activeNoteButton.dataset.note = payload.note || '';
					closeNoteModal();
				}).catch(function () {
				}).finally(function () {
					noteSave.disabled = false;
				});
			});
		}

		if (noteCancel) {
			noteCancel.addEventListener('click', closeNoteModal);
		}

		if (noteModal) {
			noteModal.addEventListener('click', function (event) {
				if (event.target === noteModal || event.target.getAttribute('data-role') === 'close-attendance-note') {
					closeNoteModal();
				}
			});
		}

		if (dashboardQuickTaskOpen) {
			dashboardQuickTaskOpen.addEventListener('click', function () {
				openDashboardQuickTaskModal();
			});
		}

		if (dashboardNoticeOpen) {
			dashboardNoticeOpen.addEventListener('click', function () {
				openDashboardNoticeModal();
			});
		}

		if (dashboardNoticeCancel) {
			dashboardNoticeCancel.addEventListener('click', function () {
				closeDashboardNoticeModal();
			});
		}

		if (dashboardNoticeModal) {
			dashboardNoticeModal.addEventListener('click', function (event) {
				if (event.target === dashboardNoticeModal || event.target.getAttribute('data-role') === 'close-dashboard-notice') {
					closeDashboardNoticeModal();
				}
			});
		}

		if (dashboardNoticeForm) {
			dashboardNoticeForm.addEventListener('submit', function (event) {
				event.preventDefault();
				if (dashboardNoticeSave) {
					dashboardNoticeSave.disabled = true;
				}

				fetch('<?php echo site_url('dashboard/notificaciones/crear'); ?>', {
					method: 'POST',
					headers: {
						'X-Requested-With': 'XMLHttpRequest',
						'Accept': 'application/json'
					},
					body: new FormData(dashboardNoticeForm)
				}).then(function (response) {
					return response.json().then(function (payload) {
						return { ok: response.ok, payload: payload };
					}).catch(function () {
						return { ok: false, payload: null };
					});
				}).then(function (result) {
					if (!result.ok || !result.payload || !result.payload.success || !result.payload.notification) {
						return;
					}
					prependDashboardNotice(result.payload.notification);
					closeDashboardNoticeModal();
				}).finally(function () {
					if (dashboardNoticeSave) {
						dashboardNoticeSave.disabled = false;
					}
				});
			});
		}
		if (dashboardQuickTaskCancel) {
			dashboardQuickTaskCancel.addEventListener('click', function () {
				closeDashboardQuickTaskModal();
			});
		}

		if (dashboardQuickTaskModal) {
			dashboardQuickTaskModal.addEventListener('click', function (event) {
				if (event.target === dashboardQuickTaskModal || event.target.getAttribute('data-role') === 'close-dashboard-quick-task') {
					closeDashboardQuickTaskModal();
				}
			});
		}

		if (dashboardTaskModal) {
			dashboardTaskModal.addEventListener('click', function (event) {
				if (event.target === dashboardTaskModal || event.target.getAttribute('data-role') === 'close-dashboard-task-modal') {
					closeDashboardTaskModal();
				}
			});
		}

		if (dashboardQuickTaskForm) {
			dashboardQuickTaskForm.addEventListener('submit', function (event) {
				event.preventDefault();
				if (dashboardQuickTaskSave) {
					dashboardQuickTaskSave.disabled = true;
				}

				fetch('<?php echo site_url('tareas/rapida'); ?>', {
					method: 'POST',
					headers: {
						'X-Requested-With': 'XMLHttpRequest',
						'Accept': 'application/json'
					},
					body: new FormData(dashboardQuickTaskForm)
				}).then(function (response) {
					return response.json().then(function (payload) {
						return { ok: response.ok, payload: payload };
					}).catch(function () {
						return { ok: false, payload: null };
					});
				}).then(function (result) {
					if (!result.ok || !result.payload || !result.payload.success || !result.payload.assignment) {
						return;
					}
					prependDashboardTask(result.payload.assignment);
					closeDashboardQuickTaskModal();
				}).finally(function () {
					if (dashboardQuickTaskSave) {
						dashboardQuickTaskSave.disabled = false;
					}
				});
			});
		}

		document.addEventListener('keydown', function (event) {
			if (event.key === 'Escape' && noteModal && noteModal.classList.contains('is-open')) {
				closeNoteModal();
			}
			if (event.key === 'Escape' && dashboardNoticeModal && dashboardNoticeModal.classList.contains('is-open')) {
				closeDashboardNoticeModal();
			}
			if (event.key === 'Escape' && dashboardTaskModal && dashboardTaskModal.classList.contains('is-open')) {
				closeDashboardTaskModal();
			}
			if (event.key === 'Escape' && dashboardQuickTaskModal && dashboardQuickTaskModal.classList.contains('is-open')) {
				closeDashboardQuickTaskModal();
			}
		});

		function getGlobalTaskStatusClass(statusClass) {
			if (statusClass === 'success') {
				return 'task-status-complete';
			}
			if (statusClass === 'danger') {
				return 'task-status-overdue';
			}
			return 'task-status-progress';
		}

		var globalTaskButtons = document.querySelectorAll('.js-global-task-action');
		globalTaskButtons.forEach(function (button) {
			button.addEventListener('click', function () {
				var assignmentId = button.dataset.assignmentId;
				var actionType = button.dataset.actionType || 'complete';
				if (!assignmentId) {
					return;
				}

				button.disabled = true;
				var formData = new FormData();
				formData.append('assignment_id', assignmentId);
				formData.append('action_type', actionType);

				fetch('<?php echo site_url('dashboard/tareas-globales/accion'); ?>', {
					method: 'POST',
					body: formData
				}).then(function (response) {
					return response.json();
				}).then(function (payload) {
					if (!payload || !payload.success || !payload.assignment) {
						return;
					}

					var assignment = payload.assignment;
					var container = button.closest('.global-item-actions');
					var statusNode = container ? container.querySelector('.js-global-task-status') : null;
					if (statusNode) {
						statusNode.textContent = assignment.status_label || 'Pendiente';
						statusNode.classList.remove('task-status-progress', 'task-status-complete', 'task-status-overdue');
						statusNode.classList.add(getGlobalTaskStatusClass(assignment.status_class || 'warning'));
					}

					button.dataset.actionType = assignment.action_type || 'complete';
					button.textContent = assignment.action_label || 'Completar';
					button.classList.toggle('btn-outline', (assignment.action_type || 'complete') === 'reactivate');

					var card = button.closest('.global-item');
					var dateNode = card ? card.querySelector('.js-global-task-date') : null;
					if (dateNode && assignment.due_date_label) {
						dateNode.textContent = assignment.due_date_label;
					}
				}).finally(function () {
					button.disabled = false;
				});
			});
		});

		syncDashboardNoticeEmpty();
		syncDashboardTaskEmpty();
	})();
</script>


















