Files

2139 lines
84 KiB
HTML

<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ZEN AI — Dasbor Operasional</title>
<script>
(function () {
try {
var t = localStorage.getItem('apc-theme') || localStorage.getItem('theme');
if (t === 'light' || t === 'dark') document.documentElement.setAttribute('data-theme', t);
} catch (e) {}
})();
</script>
<link rel="icon" href="{{ url_for('static', filename='img/icon-zenai-konsep3.png') }}?v=4" type="image/png" sizes="any">
<link rel="apple-touch-icon" href="{{ url_for('static', filename='img/icon-zenai-konsep3.png') }}?v=4">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500;700&family=Space+Grotesk:wght@500;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.1/dist/chart.umd.min.js"></script>
<style>
:root {
--bg: #23232C;
--bg-header: #1A1C22;
--bg-card: #1A1C22;
--bg-panel: #2D2E40;
--bg-video: #121417;
--border: #22252A;
--border-accent: #1682B2;
--border-divider: #2E3554;
--text: #F1F5F9;
--text-muted: #94A3B8;
--text-dim: rgba(255,255,255,0.30);
--green: #10B981;
--green-bg: rgba(16,185,129,0.13);
--blue: #1682B2;
--blue-btn: #1FA3DD;
--blue-bg: rgba(22,130,178,0.13);
--yellow: #B89A14;
--yellow-line: #FFE76F;
--yellow-bg: rgba(178,167,22,0.13);
--purple: #746BEC;
--font: 'Inter', system-ui, sans-serif;
--mono: 'JetBrains Mono', monospace;
--fs-body: clamp(0.8125rem, 0.75rem + 0.25vw, 0.875rem);
--fs-title: clamp(0.8125rem, 0.7rem + 0.35vw, 0.875rem);
--fs-kpi-lg: clamp(2rem, 1.2rem + 3vw, 4rem);
--fs-kpi-md: clamp(1.5rem, 1rem + 2vw, 3rem);
--fs-unit: clamp(0.875rem, 0.75rem + 0.5vw, 1.25rem);
--space-page: clamp(1rem, 0.5rem + 2vw, 2.5rem);
--space-card: clamp(1rem, 0.75rem + 1vw, 1.5rem);
--touch-min: 44px;
--nav-pill-bg: #1A1C1F;
--nav-pill-border: #32363D;
--nav-pill-hover: #4a5058;
--site-info-bg: linear-gradient(135deg, rgba(22,130,178,0.16), rgba(26,28,34,0.2) 55%, rgba(255,255,255,0.02));
--site-info-border: rgba(22,130,178,0.35);
--btn-ghost-bg: rgba(255,255,255,0.05);
--acc-track: rgba(217,217,217,0.10);
--chart-tooltip-bg: #1A1C22;
--chart-grid: rgba(46,53,84,0.5);
}
html[data-theme="light"] {
--bg: #EEF1F9;
--bg-header: #FFFFFF;
--bg-card: #FFFFFF;
--bg-panel: #F9FAFB;
--bg-video: #121417;
--border: #E5E7EB;
--border-accent: #1682B2;
--border-divider: #E5E7EB;
--text: #121417;
--text-muted: #94A3B8;
--text-dim: rgba(18,20,23,0.45);
--nav-pill-bg: #FFFFFF;
--nav-pill-border: #E5E7EB;
--nav-pill-hover: #CBD5E1;
--site-info-bg: linear-gradient(135deg, rgba(22,130,178,0.12), rgba(238,241,249,0.9) 55%, #FFFFFF);
--site-info-border: rgba(22,130,178,0.35);
--btn-ghost-bg: rgba(18,20,23,0.04);
--acc-track: rgba(148,163,184,0.25);
--chart-tooltip-bg: #FFFFFF;
--chart-grid: rgba(229,231,235,0.9);
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: var(--font);
background: var(--bg);
color: var(--text);
min-height: 100vh;
font-size: var(--fs-body);
line-height: 1.45;
-webkit-text-size-adjust: 100%;
}
/* ── Header ── */
.top-header {
display: flex; align-items: center; justify-content: space-between;
flex-wrap: wrap;
gap: 12px;
padding: var(--space-card) var(--space-page);
background: var(--bg-header);
border-bottom: 1px solid var(--border);
position: sticky;
top: 0;
z-index: 50;
}
.brand { display: flex; align-items: center; gap: 4px; text-decoration: none; cursor: pointer; transition: opacity 0.2s ease; }
.brand:hover { opacity: 0.85; }
.logo-img { width: 48px; height: 48px; object-fit: contain; background: transparent; display: block; }
.brand-title { font-size: 16px; font-weight: 700; color: var(--text); letter-spacing: 0.5px; }
.brand-sub { font-size: 11px; color: var(--text-muted); text-transform: uppercase; margin-top: 2px; }
.header-right { display: flex; align-items: center; gap: 24px; }
.live-group { display: flex; align-items: center; gap: 8px; }
.live-rings { width: 24px; height: 24px; position: relative; }
.live-rings span {
position: absolute; border-radius: 50%; background: var(--green);
}
.live-rings .r1 { width: 18px; height: 18px; left: 3px; top: 3px; opacity: 0.2; }
.live-rings .r2 { width: 12px; height: 12px; left: 6px; top: 6px; opacity: 0.4; }
.live-rings .r3 { width: 8px; height: 8px; left: 8px; top: 8px; opacity: 1; }
.live-chip {
padding: 2px 8px; border-radius: 4px;
background: rgba(16,185,129,0.10); border: 1px solid var(--green);
color: var(--green); font-family: var(--mono); font-size: 11px; font-weight: 700;
}
.header-divider { width: 1px; height: 28px; background: linear-gradient(180deg, transparent, var(--border-accent), transparent); }
.site-info {
display: flex;
flex-direction: column;
align-items: flex-end;
gap: 4px;
padding: 6px 12px 6px 14px;
border-radius: 10px;
background: var(--site-info-bg);
border: 1px solid var(--site-info-border);
box-shadow: inset 0 1px 0 rgba(255,255,255,0.06);
position: relative;
overflow: hidden;
}
.site-info::before {
content: '';
position: absolute;
left: 0; top: 8px; bottom: 8px;
width: 3px;
border-radius: 0 3px 3px 0;
background: linear-gradient(180deg, #1FA3DD, #1682B2);
}
.site-info .site-label {
font-family: var(--mono);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.14em;
text-transform: uppercase;
color: var(--blue-btn);
opacity: 0.9;
}
.site-info .site-name {
font-family: 'Space Grotesk', var(--font);
font-size: clamp(0.95rem, 0.85rem + 0.4vw, 1.15rem);
font-weight: 700;
letter-spacing: 0.06em;
line-height: 1.1;
color: var(--text);
text-shadow: 0 0 18px rgba(31,163,221,0.25);
}
html[data-theme="light"] .site-info .site-name { text-shadow: none; }
html[data-theme="light"] .logo-img { filter: invert(1); }
.site-info .site-line {
font-size: 10px;
font-family: var(--mono);
color: var(--text-muted);
}
.btn-theme {
min-width: var(--touch-min); min-height: var(--touch-min);
padding: 8px; border-radius: 8px;
background: var(--btn-ghost-bg); border: 1px solid var(--border);
color: var(--text-muted); cursor: pointer; font-size: 18px; line-height: 1;
display: inline-flex; align-items: center; justify-content: center;
}
/* ── Main ── */
.main {
padding: var(--space-page);
display: flex; flex-direction: column;
gap: clamp(1rem, 0.5rem + 1.5vw, 1.5rem);
max-width: 1440px; margin: 0 auto; width: 100%;
}
.nav-row {
display: flex; flex-wrap: wrap; align-items: center;
gap: 12px; align-self: flex-start;
}
.nav-pill {
display: inline-flex; align-items: center; gap: 8px;
padding: 8px 16px; border-radius: 20px;
background: var(--nav-pill-bg); border: 2px solid var(--nav-pill-border);
font-size: 14px; font-weight: 700;
color: var(--text); text-decoration: none; cursor: pointer;
}
.nav-pill.active {
border-color: var(--blue);
background: rgba(22,130,178,0.12);
color: var(--text);
cursor: default;
}
html[data-theme="light"] .nav-pill.active {
background: #1A1C1F;
border-color: #32363D;
color: #F1F5F9;
}
/* ── Manual Batch Control Bar (APC Ngoro style) ── */
.batch-control-bar {
display: flex; align-items: center; justify-content: space-between;
padding: var(--space-card);
background: var(--bg-card);
border: 1px solid var(--border-accent);
border-radius: 12px;
box-shadow: 0 8px 24px rgba(13,148,136,0.07);
gap: 16px; flex-wrap: wrap;
}
.bc-left {
display: flex; flex-direction: column; gap: 8px;
}
.bc-badge-row {
display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.bc-status-badge {
display: inline-flex; align-items: center; gap: 8px;
padding: 4px 12px; border-radius: 8px;
font-size: 11px; font-weight: 700; letter-spacing: 0.05em;
text-transform: uppercase; font-family: var(--mono);
}
.bc-status-badge.running {
background: var(--green-bg);
border: 1px solid var(--green);
color: var(--green);
}
.bc-status-badge.stopped {
background: var(--yellow-bg);
border: 1px solid var(--yellow);
color: var(--yellow);
}
.bc-dot {
width: 8px; height: 8px; border-radius: 50%;
}
.bc-status-badge.running .bc-dot {
background: var(--green);
box-shadow: 0 0 8px var(--green);
animation: blink 1.2s ease-in-out infinite;
}
.bc-status-badge.stopped .bc-dot {
background: var(--yellow);
}
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }
.bc-mode-tag {
font-size: 10px; font-family: var(--mono); color: var(--text-muted);
padding: 4px 10px; background: var(--bg-panel);
border-radius: 6px; border: 1px solid var(--border);
}
.bc-main-info {
font-size: 15px; font-weight: 700; color: var(--text);
}
.bc-sub-info {
font-size: 12px; color: var(--text-muted);
}
.bc-info-row {
display: flex; flex-direction: column; gap: 2px;
}
.recent-breakdown {
font-size: 11px; color: var(--text-muted); font-family: var(--mono);
}
.bc-right {
display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.btn-batch {
min-height: var(--touch-min);
display: inline-flex; align-items: center; justify-content: center; gap: 10px;
padding: 10px 20px; border-radius: 8px; font-size: 13px; font-weight: 700;
letter-spacing: 0.04em; font-family: var(--mono);
border: 1px solid transparent; cursor: pointer; transition: all 0.2s ease;
text-transform: uppercase;
}
.btn-batch:disabled {
opacity: 0.5; cursor: not-allowed; transform: none !important;
}
.btn-batch-start {
background: var(--green);
color: #fff;
}
.btn-batch-start:hover:not(:disabled) {
filter: brightness(1.08);
transform: translateY(-1px);
}
.btn-batch-stop {
background: #ef4444;
color: #fff;
}
.btn-batch-stop:hover:not(:disabled) {
filter: brightness(1.08);
transform: translateY(-1px);
}
.type-pill {
display: inline-flex; align-items: center; padding: 2px 7px;
border-radius: 6px; font-size: 10px; font-weight: 700;
font-family: var(--mono); text-transform: uppercase;
}
.type-pill.sack {
background: var(--green-bg); color: var(--green);
border: 1px solid var(--green);
}
.type-pill.box {
background: var(--yellow-bg); color: var(--yellow);
border: 1px solid var(--yellow);
}
.type-pill.mixed {
background: var(--blue-btn-bg, rgba(22,130,178,0.14)); color: var(--blue-btn);
border: 1px solid var(--blue-btn);
}
/* ── Summary cards ── */
.summary-row {
display: grid;
grid-template-columns: 2fr 1fr 1fr;
gap: 20px;
}
.stat-card {
padding: var(--space-card); background: var(--bg-card);
border-radius: 12px; border: 1px solid var(--border-accent);
box-shadow: 0 8px 24px rgba(13,148,136,0.07);
display: flex; flex-direction: column; gap: clamp(0.75rem, 0.5rem + 1vw, 1.25rem);
}
.stat-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; flex-wrap: wrap; }
.stat-card-title {
font-size: var(--fs-title); font-weight: 700; color: var(--text);
text-transform: uppercase;
}
.badge-idle {
padding: 2px 8px; border-radius: 8px;
background: var(--yellow-bg); color: var(--yellow);
font-size: 14px; font-weight: 700; font-family: var(--mono);
}
.badge-running {
padding: 2px 8px; border-radius: 8px;
background: var(--green-bg); color: var(--green);
font-size: 14px; font-weight: 700; font-family: var(--mono);
}
.stat-big-row { display: flex; align-items: baseline; gap: 8px; }
.stat-big {
font-family: var(--mono); font-size: var(--fs-kpi-lg); font-weight: 500; color: var(--text); line-height: 1.05;
}
.stat-big.bold { font-weight: 700; }
.stat-unit { font-size: var(--fs-unit); font-weight: 600; color: var(--text-muted); }
.stat-trend-badge {
padding: 2px 8px; border-radius: 4px;
background: rgba(148,163,184,0.13); color: var(--text-muted);
font-family: var(--mono); font-size: 16px; font-weight: 700;
}
.stat-trend-badge.up { background: var(--green-bg); color: var(--green); }
.stat-trend-badge.down { background: rgba(239,68,68,0.13); color: #ef4444; }
hr.stat-divider { border: none; border-top: 2px solid var(--border-divider); }
.stat-meta-row { display: flex; gap: 24px; }
.stat-meta { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.stat-meta-label {
font-size: 11px; font-weight: 500; color: var(--text-muted);
text-transform: uppercase;
}
.stat-meta-val { font-family: var(--mono); font-size: 16px; font-weight: 700; }
.stat-breakdown { display: flex; gap: 24px; }
/* ── Monitor row ── */
.monitor-wrap {
padding: var(--space-card); background: var(--bg);
border-radius: 12px; border: 1px solid var(--border);
display: grid; grid-template-columns: 1fr minmax(220px, 280px); gap: clamp(12px, 2vw, 20px);
}
.video-box {
background: var(--bg-video); border-radius: 16px;
border: 1px solid var(--border); overflow: hidden;
display: flex; flex-direction: column;
}
.video-bar {
display: flex; justify-content: space-between; align-items: center;
padding: 16px; background: var(--bg-panel); border-bottom: 1px solid var(--border);
flex-wrap: wrap; gap: 10px;
}
.video-bar-left { display: flex; align-items: center; gap: 12px; }
.stream-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
.stream-dot.off { background: var(--text-muted); }
.video-bar-cam { font-family: var(--mono); font-size: 13px; font-weight: 700; }
.video-bar-meta { font-family: var(--mono); font-size: 11px; color: var(--text-muted); display: flex; gap: 16px; }
.btn-buka {
min-height: var(--touch-min); padding: 8px 16px; border-radius: 6px; border: none; cursor: pointer;
background: var(--blue-btn); color: #fff;
font-size: 14px; font-weight: 500;
}
.btn-buka.active { background: #0d7a52; }
.video-view {
flex: 1; min-height: clamp(200px, 40vw, 360px); position: relative;
display: flex; align-items: center; justify-content: center;
background: #000;
}
.video-placeholder { text-align: center; color: var(--text-muted); }
.video-placeholder .vp-hint { font-size: 10px; margin-top: 6px; color: var(--text-dim); }
#live-video-img { width: 100%; height: 100%; object-fit: contain; display: none; position: absolute; inset: 0; }
.video-error-overlay {
position: absolute; inset: 0;
display: flex; align-items: center; justify-content: center;
background: rgba(0,0,0,0.7);
color: #ef4444; font-family: var(--mono); font-size: 12px;
pointer-events: none; opacity: 0; transition: opacity 0.4s;
}
.video-error-overlay.visible { opacity: 1; }
.side-stack { display: flex; flex-direction: column; gap: 20px; }
.side-card {
padding: var(--space-card); background: var(--bg-panel);
border-radius: 12px; border: 1px solid var(--border);
display: flex; flex-direction: column; gap: 16px; min-height: auto;
}
.side-card-title {
font-size: var(--fs-title); font-weight: 500; color: var(--text);
text-transform: uppercase;
}
.side-card-sub { font-size: 11px; font-weight: 300; color: var(--text-dim); }
.acc-bar { height: 6px; background: var(--acc-track); border-radius: 2px; overflow: hidden; }
.acc-fill { height: 100%; background: #3C96FF; border-radius: 2px; transition: width 0.4s; }
.acc-hint { font-size: 11px; font-weight: 300; color: var(--text-muted); }
.legend-row { display: flex; align-items: center; gap: 8px; font-size: 11px; font-weight: 300; }
.legend-sq { width: 9px; height: 9px; border-radius: 2px; flex-shrink: 0; }
.legend-dot { width: 9px; height: 9px; border-radius: 10px; flex-shrink: 0; }
.svc-row { display: flex; align-items: center; gap: 8px; font-size: 11px; font-weight: 300; }
/* ── Performance ── */
.perf-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: clamp(12px, 2vw, 24px); }
.perf-card {
min-height: auto; padding: var(--space-card); background: var(--bg-card);
border-radius: 12px; border: 1px solid var(--border);
display: flex; flex-direction: column; gap: clamp(12px, 1.5vw, 20px);
}
.perf-title { font-size: var(--fs-title); font-weight: 700; text-transform: uppercase; }
.perf-val-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.perf-val { font-family: var(--mono); font-size: var(--fs-kpi-md); font-weight: 700; }
.perf-sub { font-family: var(--mono); font-size: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem); font-weight: 300; color: var(--text-muted); }
.perf-sub .up { color: var(--green); font-weight: 700; }
.perf-sub .down { color: #ef4444; font-weight: 700; }
/* ── Chart + summary ── */
.trend-row { display: grid; grid-template-columns: 1.4fr 1fr; gap: clamp(12px, 2vw, 24px); }
.trend-card, .summary-card {
padding: var(--space-card); background: var(--bg-card);
border-radius: 12px; border: 1px solid var(--border);
display: flex; flex-direction: column; gap: clamp(12px, 1.5vw, 20px);
}
.trend-card { min-height: clamp(280px, 50vw, 400px); }
.trend-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; }
.pill-group { display: flex; gap: 12px; flex-wrap: wrap; }
.pill {
min-height: var(--touch-min); min-width: var(--touch-min);
padding: 8px 16px; border-radius: 16px; cursor: pointer; border: 1px solid #5C5C5C;
background: rgba(255,255,255,0.10); color: #5C5C5C;
font-family: var(--mono); font-size: 14px; font-weight: 700;
display: inline-flex; align-items: center; justify-content: center;
}
.pill.active {
background: var(--blue-bg); border-color: var(--blue); color: var(--blue);
}
.chart-legend { display: flex; align-items: center; gap: 16px; font-family: var(--mono); font-size: 12px; color: var(--text-muted); }
.chart-legend .dot { width: 16px; height: 16px; border-radius: 2px; }
.chart-wrap { flex: 1; min-height: clamp(200px, 40vw, 320px); position: relative; }
.summary-card {
justify-content: flex-start;
gap: 20px;
align-self: start;
}
.summary-block {
display: flex; flex-direction: column; gap: 20px;
width: 100%;
}
.summary-item {
display: flex; flex-direction: column; gap: 8px;
}
.summary-item-label {
font-size: var(--fs-title); color: var(--text);
text-transform: uppercase;
}
.summary-item-val { font-family: var(--mono); font-size: var(--fs-kpi-md); font-weight: 700; }
/* ── Recent activity ── */
.recent-wrap {
padding: var(--space-card); background: var(--bg-card);
border-radius: 12px; border: 1px solid var(--border);
display: flex; flex-direction: column; gap: clamp(12px, 2vw, 24px);
}
.recent-row {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 160px), 1fr));
gap: clamp(12px, 2vw, 24px);
}
.recent-card {
min-height: auto; padding: var(--space-card); background: var(--bg-panel);
border-radius: 12px; border: 1px solid var(--border);
display: flex; flex-direction: column; gap: clamp(12px, 1.5vw, 20px);
}
.recent-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.recent-batch { font-size: var(--fs-title); font-weight: 700; display: inline-flex; align-items: center; gap: 6px; }
.recent-date { font-size: 11px; font-weight: 300; color: var(--text-muted); }
.recent-count { font-family: var(--mono); font-size: var(--fs-kpi-md); font-weight: 700; }
.recent-time { font-family: var(--mono); font-size: 11px; font-weight: 300; }
.recent-time strong { font-weight: 500; }
/* ── Table ── */
.report-wrap {
padding: var(--space-card); background: var(--bg-card);
border-radius: 12px; border: 1px solid var(--border);
display: flex; flex-direction: column; gap: clamp(12px, 2vw, 24px);
align-items: stretch;
}
.report-toolbar { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 16px; width: 100%; }
.report-title { font-size: var(--fs-title); font-weight: 700; text-transform: uppercase; }
.report-hint { font-size: 11px; font-weight: 300; color: var(--text-muted); margin-top: 8px; }
.toolbar-btns {
display: flex; gap: 16px; flex-wrap: nowrap;
overflow-x: auto; -webkit-overflow-scrolling: touch;
max-width: 100%; padding-bottom: 4px;
}
.tbtn {
min-height: var(--touch-min); flex-shrink: 0;
padding: 8px 24px; border-radius: 8px; cursor: pointer;
font-size: 14px; font-weight: 400; border: 1px solid var(--border);
background: var(--btn-ghost-bg); color: var(--text);
display: inline-flex; align-items: center; justify-content: center; gap: 10px;
font-family: inherit;
}
.tbtn svg { width: 16px; height: 16px; flex-shrink: 0; }
.tbtn-primary { background: var(--blue); border-color: var(--blue); color: #F1F5F9; }
.tbtn-outline { background: rgba(22,130,178,0.15); border-color: var(--blue-btn); color: var(--blue-btn); font-weight: 500; }
.date-filter-input {
position: absolute;
width: 1px; height: 1px;
padding: 0; margin: -1px;
overflow: hidden; clip: rect(0, 0, 0, 0);
white-space: nowrap; border: 0;
opacity: 0; pointer-events: none;
}
.report-desktop { display: block; width: 100%; }
.report-mobile-list { display: none; width: 100%; }
.report-table-pad {
padding-left: clamp(12px, 4vw, 64px);
padding-right: clamp(12px, 4vw, 64px);
}
.report-table {
display: grid;
grid-template-columns:
minmax(140px, 1.5fr)
minmax(88px, 1fr)
minmax(56px, 0.7fr)
minmax(100px, 1.1fr)
minmax(96px, 1fr)
minmax(96px, 1fr);
column-gap: clamp(24px, 5vw, 64px);
align-items: start;
width: 100%;
}
.report-table-head,
#daily-table-body,
.report-row {
display: contents;
}
.report-table-head > * {
padding: 8px 0 16px;
border-bottom: 2px solid var(--border-divider);
font-size: 11px; font-weight: 300; color: var(--text);
text-transform: uppercase;
text-align: left;
min-width: 0;
}
.report-row > * {
padding: 18px 0;
border-bottom: none;
min-width: 0;
text-align: left;
}
.row-date-cell {
display: flex;
align-items: flex-start;
gap: 10px;
min-width: 0;
}
.row-check-wrap {
width: 16px;
height: 16px;
margin-top: 1px;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
overflow: hidden;
}
.row-check {
width: 16px; height: 16px; margin: 0; padding: 0;
flex-shrink: 0;
border-radius: 4px; border: 1px solid var(--text);
accent-color: var(--blue);
cursor: pointer;
appearance: none;
-webkit-appearance: none;
background: transparent;
box-sizing: border-box;
}
.row-check:checked {
background: var(--blue);
border-color: var(--blue);
box-shadow: inset 0 0 0 2px var(--bg-card);
}
.row-date-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.row-date-main { font-size: 11px; font-weight: 600; text-transform: uppercase; }
.row-date-sub { font-size: 8px; font-weight: 300; color: var(--text-muted); }
.badge-complete {
display: inline-flex; align-items: center; gap: 4px;
padding: 2px 8px; border-radius: 16px;
background: var(--green-bg); border: 1px solid var(--green);
color: var(--green); font-family: var(--mono); font-size: 11px; font-weight: 700;
}
.badge-complete .bdot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
.status-badge {
padding: 2px 6px; border-radius: 6px;
font-size: 10px; font-weight: 700; white-space: nowrap;
background: var(--green-bg); border: 1px solid var(--green); color: var(--green);
display: inline-block;
}
.status-badge.warn {
background: var(--yellow-bg); border-color: var(--yellow); color: var(--yellow);
}
.status-badge.info {
background: var(--blue-bg); border-color: var(--blue); color: var(--blue-btn);
}
.total-type-badge {
white-space: normal !important;
word-break: break-word;
line-height: 1.25;
display: inline-block;
padding: 3px 6px;
text-align: center;
}
.tbtn.tbtn-active {
background: rgba(56, 189, 248, 0.15) !important;
border-color: #38bdf8 !important;
color: #38bdf8 !important;
font-weight: 700;
}
.active-date-chip {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 4px 10px;
border-radius: 999px;
background: rgba(56, 189, 248, 0.12);
border: 1px solid rgba(56, 189, 248, 0.3);
color: #38bdf8;
font-size: 11px;
font-weight: 600;
}
.chip-clear-btn {
background: none;
border: none;
color: inherit;
font-size: 14px;
cursor: pointer;
line-height: 1;
padding: 0 2px;
}
.chip-clear-btn:hover {
color: #ef4444;
}
.link-detail {
color: var(--text); font-size: 11px; font-weight: 600; cursor: pointer;
min-height: var(--touch-min); display: inline-flex; align-items: center;
text-transform: capitalize;
}
.link-detail:hover { color: var(--blue-btn); }
.cell-val {
font-size: 11px; font-weight: 300; text-transform: uppercase;
justify-self: start;
}
.cell-mono { font-family: var(--mono); }
.report-empty {
grid-column: 1 / -1;
padding: 32px;
text-align: center;
color: var(--text-muted);
}
.report-pagination {
display: flex; align-items: center; justify-content: flex-end;
flex-wrap: wrap; gap: 16px;
margin-top: 16px;
padding-left: clamp(12px, 4vw, 64px);
padding-right: clamp(12px, 4vw, 64px);
}
.page-btn {
width: 16px; height: 16px; border-radius: 4px; border: none;
background: var(--text); color: var(--bg); cursor: pointer;
display: inline-flex; align-items: center; justify-content: center;
padding: 0; font-size: 10px; line-height: 1;
}
.page-btn:disabled { opacity: 0.35; cursor: default; }
.page-num {
min-width: 20px; height: 20px; border-radius: 4px;
border: none; background: transparent;
color: var(--text-muted); font-size: 11px; font-weight: 300;
cursor: pointer; padding: 0 4px;
display: inline-flex; align-items: center; justify-content: center;
}
.page-num.active {
background: var(--blue);
color: #F1F5F9;
}
.page-ellipsis { color: var(--text-muted); font-size: 11px; font-weight: 300; }
/* Mobile report cards */
.report-card-mobile {
padding: 16px; background: var(--bg-panel);
border-radius: 10px; border: 1px solid var(--border);
display: flex; flex-direction: column; gap: 10px;
}
.rcm-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.rcm-date-wrap { display: flex; align-items: flex-start; gap: 10px; }
.rcm-date { font-size: 13px; font-weight: 600; }
.rcm-sub { font-size: 10px; color: var(--text-muted); margin-top: 2px; }
.rcm-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; }
.rcm-item { display: flex; flex-direction: column; gap: 2px; }
.rcm-label { font-size: 10px; color: var(--text-muted); }
.rcm-val { font-family: var(--mono); font-size: 13px; font-weight: 600; }
.rcm-action { margin-top: 4px; }
/* ── Modal ── */
.modal-overlay {
position: fixed; inset: 0; background: rgba(0,0,0,0.75); z-index: 100;
display: flex; align-items: center; justify-content: center;
padding: 16px;
}
.modal-overlay.hidden { display: none; }
.modal-content {
background: var(--bg-card); border: 1px solid var(--border); border-radius: 14px;
width: 100%; max-width: min(960px, 96vw); max-height: 90dvh; overflow-y: auto; padding: var(--space-card);
}
.modal-header { display: flex; justify-content: space-between; margin-bottom: 16px; gap: 12px; }
.modal-header h2 { font-size: 16px; font-weight: 700; }
.modal-subtitle { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.close-btn {
min-width: var(--touch-min); min-height: var(--touch-min);
background: none; border: none; color: var(--text-muted); font-size: 24px; cursor: pointer;
display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.modal-stats { display: grid; grid-template-columns: repeat(3,1fr); gap: 12px; margin-bottom: 16px; }
.modal-stat { text-align: center; padding: 12px; background: var(--bg-panel); border-radius: 8px; }
.ms-val { font-family: var(--mono); font-size: clamp(1rem, 0.8rem + 1vw, 1.375rem); font-weight: 700; }
.ms-label { font-size: 10px; color: var(--text-muted); margin-top: 4px; text-transform: uppercase; }
.modal-body {
display: block;
width: 100%;
}
.modal-table-wrap {
width: 100%;
overflow-x: auto;
border: 1px solid var(--border);
border-radius: 10px;
background: var(--bg-panel);
}
.modal-table {
width: 100%;
border-collapse: collapse;
font-size: 12px;
table-layout: fixed;
}
.modal-table th, .modal-table td {
padding: 10px 12px;
text-align: left;
border-bottom: 1px solid var(--border);
}
.modal-table tr:last-child td { border-bottom: none; }
.modal-table th {
font-size: 10px;
color: var(--text-muted);
text-transform: uppercase;
letter-spacing: 0.02em;
background: rgba(0,0,0,0.18);
}
.modal-table th:nth-child(1), .modal-table td:nth-child(1) { width: 9%; }
.modal-table th:nth-child(2), .modal-table td:nth-child(2) { width: 14%; }
.modal-table th:nth-child(3), .modal-table td:nth-child(3) { width: 11%; }
.modal-table th:nth-child(4), .modal-table td:nth-child(4),
.modal-table th:nth-child(5), .modal-table td:nth-child(5) { width: 10%; }
.modal-table th:nth-child(6), .modal-table td:nth-child(6) { width: 10%; }
.modal-table th:nth-child(7), .modal-table td:nth-child(7) { width: 10%; }
.modal-table th:nth-child(8), .modal-table td:nth-child(8) { width: 10%; }
.modal-table th:nth-child(9), .modal-table td:nth-child(9) { width: 9%; }
.modal-table th:nth-child(10), .modal-table td:nth-child(10) { width: 7%; }
.modal-table .mono { font-family: var(--mono); font-weight: 600; }
.modal-empty {
color: var(--text-muted); font-size: 12px; padding: 16px; text-align: center;
}
/* Toast Notification */
.toast {
padding: 14px 20px; border-radius: 10px;
background: var(--bg-card);
border: 1px solid var(--border-accent);
color: var(--text);
font-size: 12px; font-family: var(--mono);
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
display: flex; align-items: center; gap: 12px;
animation: toastSlideIn 0.3s ease-out;
pointer-events: auto; min-width: 280px; max-width: 420px;
}
.toast.success { border-color: var(--green); color: var(--green); }
.toast.error { border-color: #ef4444; color: #ef4444; }
.toast.info { border-color: var(--blue-btn); color: var(--blue-btn); }
@keyframes toastSlideIn {
from { transform: translateX(50px); opacity: 0; }
to { transform: translateX(0); opacity: 1; }
}
/* ── Responsive breakpoints ── */
@media (max-width: 1279px) {
.summary-row { grid-template-columns: 1fr 1fr; }
.summary-row .stat-card:first-child { grid-column: 1 / -1; }
.trend-row { grid-template-columns: 1fr; }
.monitor-wrap { grid-template-columns: 1fr; }
}
@media (max-width: 767px) {
.header-right { width: 100%; justify-content: space-between; }
.perf-row { grid-template-columns: 1fr; }
.summary-row { grid-template-columns: 1fr; }
.summary-row .stat-card:first-child { grid-column: auto; }
.recent-row {
display: flex; overflow-x: auto; -webkit-overflow-scrolling: touch;
gap: 12px; padding-bottom: 4px;
}
.recent-card { min-width: min(280px, 85vw); flex-shrink: 0; }
.report-desktop { display: none; }
.report-mobile-list { display: flex; flex-direction: column; gap: 12px; }
.modal-stats { grid-template-columns: 1fr; }
.modal-body { grid-template-columns: 1fr; }
.nav-pill { font-size: 13px; }
}
@media (max-width: 480px) {
.header-divider { display: none; }
.brand-title { font-size: 14px; }
.logo-img { width: 40px; height: 40px; }
:root {
--fs-kpi-lg: clamp(1.75rem, 1rem + 4vw, 2.5rem);
--fs-kpi-md: clamp(1.25rem, 0.9rem + 2vw, 2rem);
}
}
</style>
</head>
<body>
<!-- Header -->
<header class="top-header">
<a href="{{ url_for('index') }}" class="brand">
<img src="{{ url_for('static', filename='img/logo-zenai-white.png') }}?v=2" alt="ZenAI" class="logo-img" id="site-logo">
<div>
<div class="brand-title">ZEN AI SACK COUNTER</div>
<div class="brand-sub">Edge RKNN Counter — Sacks &amp; Boxes</div>
</div>
</a>
<div class="header-right">
<div class="live-group">
<div class="live-rings"><span class="r1"></span><span class="r2"></span><span class="r3"></span></div>
<span class="live-chip">LIVE</span>
</div>
<div class="header-divider"></div>
<div class="site-info">
<div class="site-label">Lokasi</div>
<div class="site-name">{{ site_name }}</div>
<div class="site-line">Counting Day: <span id="current-date">--</span></div>
</div>
<button class="btn-theme" id="themeToggle" title="Mode terang" type="button" aria-label="Ganti tema">&#9788;</button>
</div>
</header>
<main class="main">
<div class="nav-row">
<a class="nav-pill active" href="/" aria-current="page">Dasbor Operasional</a>
</div>
<!-- Manual Batch Control Bar -->
<div class="batch-control-bar" id="batchControlBar">
<div class="bc-left">
<div class="bc-badge-row">
<span class="bc-status-badge stopped" id="bcStatusBadge">
<span class="bc-dot"></span>
<span id="bcStatusText">STOPPED / IDLE</span>
</span>
<span class="bc-mode-tag"><i class="fas fa-hand-pointer"></i> MANUAL TRIGGER</span>
</div>
<div class="bc-info-row">
<div class="bc-main-info" id="bcMainInfo">Sistem Siap Menghitung</div>
<div class="bc-sub-info" id="bcSubInfo">Sistem idle. Klik "Start Batch" untuk menghitung karung dan box sekaligus.</div>
</div>
</div>
<div class="bc-right">
<button class="btn-batch btn-batch-start" id="btnBatchStart" type="button" onclick="handleStartBatch()">
<i class="fas fa-play"></i> START BATCH <span id="lblNextBatch">#1</span>
</button>
<button class="btn-batch btn-batch-stop" id="btnBatchStop" type="button" style="display:none;" onclick="handleStopBatch()">
<i class="fas fa-stop"></i> STOP BATCH <span id="lblCurrBatch">#1</span>
</button>
</div>
</div>
<!-- Summary KPIs -->
<div class="summary-row">
<div class="stat-card" id="card-live">
<div class="stat-card-head">
<span class="stat-card-title">batch aktif</span>
<span class="badge-idle" id="batch-status">IDLE</span>
</div>
<div class="stat-big-row">
<span class="stat-big" id="live-count">--</span>
<span class="stat-unit" id="live-unit">Total</span>
</div>
<hr class="stat-divider">
<div class="stat-breakdown">
<div class="stat-meta">
<span class="stat-meta-label">karung</span>
<span class="stat-meta-val" id="live-sack-count">0</span>
</div>
<div class="stat-meta">
<span class="stat-meta-label">box</span>
<span class="stat-meta-val" id="live-box-count">0</span>
</div>
</div>
<hr class="stat-divider">
<div class="stat-meta-row">
<div class="stat-meta">
<span class="stat-meta-label">nomor batch</span>
<span class="stat-meta-val" id="live-batch-label">Batch #<span id="live-batch-number">--</span></span>
</div>
<div class="stat-meta">
<span class="stat-meta-label">plat nomor</span>
<span class="stat-meta-val" id="live-plate">-</span>
</div>
<div class="stat-meta">
<span class="stat-meta-label">waktu deteksi terakhir</span>
<span class="stat-meta-val" id="live-last-detection">--:--:--</span>
</div>
</div>
</div>
<div class="stat-card">
<div class="stat-card-head">
<span class="stat-card-title">total hari ini</span>
</div>
<div style="display:flex;justify-content:space-between;align-items:center;">
<span class="stat-big bold" id="today-count">--</span>
<span class="stat-trend-badge" id="today-trend">--</span>
</div>
<hr class="stat-divider">
<div class="stat-breakdown">
<div class="stat-meta">
<span class="stat-meta-label">karung</span>
<span class="stat-meta-val" id="today-sack-count">0</span>
</div>
<div class="stat-meta">
<span class="stat-meta-label">box</span>
<span class="stat-meta-val" id="today-box-count">0</span>
</div>
</div>
<hr class="stat-divider">
<div class="stat-meta">
<span class="stat-meta-label">jumlah batch</span>
<span class="stat-meta-val" id="today-batches">-- batch hari ini</span>
</div>
</div>
<div class="stat-card">
<div class="stat-card-head">
<span class="stat-card-title">rata-rata per hari</span>
</div>
<span class="stat-big bold" id="avg-count">--</span>
<hr class="stat-divider">
<div class="stat-meta">
<span class="stat-meta-label">hari tercatat</span>
<span class="stat-meta-val" id="total-days">-- hari terekam</span>
</div>
</div>
</div>
<!-- Live stream + side panels -->
<div class="monitor-wrap" id="video-panel">
<div class="video-box">
<div class="video-bar">
<div class="video-bar-left">
<span class="stream-dot off" id="stream-dot"></span>
<span class="video-bar-cam" id="stream-state">off</span>
{% if camera_name %}<span class="video-bar-cam">{{ camera_name }}</span>{% endif %}
</div>
<div class="video-bar-meta">
<span>FPS: {{ stream_fps | default('30.0') }}</span>
<span>RES: {{ stream_resolution | default('1280x720') }}</span>
</div>
<button class="btn-buka" id="videoToggle" type="button" onclick="toggleVideo()">Buka stream</button>
</div>
<div class="video-view" id="video-container">
<div class="video-placeholder" id="video-placeholder">
<div>Feed Kamera Tidak Tersedia</div>
<div class="vp-hint">Buka stream untuk menampilkan feed kamera</div>
</div>
<img id="live-video-img" alt="Live Feed" onerror="onVideoError()" onload="onVideoLoad()">
<div class="video-error-overlay" id="video-error-overlay">Koneksi terputus — mencoba ulang...</div>
</div>
</div>
<div class="side-stack">
<div class="side-card">
<div class="side-card-title">akurasi data stream</div>
<div class="acc-bar"><div class="acc-fill" id="accuracy-fill" data-accuracy="{{ stream_accuracy }}"></div></div>
<div class="acc-hint">Konfidensi {{ stream_accuracy }}% · Terakhir diupdate <span id="acc-updated">--</span></div>
</div>
<div class="side-card">
<div class="side-card-title">keterangan deteksi</div>
<div class="legend-row"><span class="legend-sq" style="background:var(--green)"></span> Karung (Sack) — terhitung</div>
<div class="legend-row"><span class="legend-sq" style="background:var(--yellow-line)"></span> Box — terhitung</div>
<div class="legend-row"><span class="legend-sq" style="background:var(--blue-btn)"></span> Zona Hitung (Truck / Manual)</div>
</div>
<div class="side-card">
<div class="side-card-title">status batch</div>
<div class="side-card-sub" id="batch-status-hint">Tidak ada batch aktif</div>
<div class="svc-row"><span class="legend-dot" style="background:var(--purple)" id="svc-counter-dot"></span> Counter: <span id="svc-counter">--</span></div>
<div class="svc-row"><span class="legend-dot" style="background:var(--yellow-line)" id="svc-cam-dot"></span> Kamera: <span id="svc-cam">Standby</span></div>
</div>
</div>
</div>
<!-- Performance -->
<div class="perf-row">
<div class="perf-card">
<div class="perf-title">hari ini vs kemarin</div>
<div class="perf-val-row">
<div class="perf-val" id="yesterday-count">--</div>
<span class="stat-trend-badge" id="perf-today-trend">--</span>
</div>
<div class="perf-sub" id="yesterday-batches">-- batch kemarin</div>
</div>
<div class="perf-card">
<div class="perf-title">rekor harian terbaik</div>
<div class="perf-val" id="best-count">--</div>
<div class="perf-sub up" id="best-date">--</div>
</div>
<div class="perf-card">
<div class="perf-title">rata-rata per batch</div>
<div class="perf-val" id="avg-per-batch">--</div>
<div class="perf-sub">Rata-rata karung/box per batch (keseluruhan)</div>
</div>
</div>
<!-- Trend + summary -->
<div class="trend-row">
<div class="trend-card">
<div class="trend-head">
<span class="perf-title">analisis tren</span>
<div class="pill-group chart-filters">
<button class="pill active" data-days="7" type="button" onclick="loadChartData(7)">7 hari</button>
<button class="pill" data-days="14" type="button" onclick="loadChartData(14)">14 hari</button>
<button class="pill" data-days="30" type="button" onclick="loadChartData(30)">30 hari</button>
</div>
</div>
<div class="chart-legend">
<span class="dot" style="background:var(--blue)"></span> Total Karung/Box
<span class="dot" style="background:var(--yellow-line);margin-left:12px"></span> Batch
</div>
<div class="chart-wrap"><canvas id="mainChart"></canvas></div>
</div>
<div class="summary-card">
<div class="perf-title">ringkasan keseluruhan</div>
<div class="summary-block">
<div class="summary-item">
<div class="summary-item-label">total keseluruhan</div>
<div class="summary-item-val" id="grand-total">--</div>
</div>
<div class="summary-item">
<div class="summary-item-label">total batch terhitung</div>
<div class="summary-item-val" id="grand-batches">--</div>
</div>
<div class="summary-item">
<div class="summary-item-label">waktu cut-off</div>
<div class="summary-item-val" id="cutoff-display">{{ (cutoff_time | default('20:00')) | replace(':', '.') }}</div>
</div>
</div>
</div>
</div>
<!-- Recent activity -->
<div class="recent-wrap">
<div class="perf-title">aktivitas terkini</div>
<div class="recent-row" id="recent-batches"></div>
</div>
<!-- Daily report -->
<div class="report-wrap">
<div class="report-toolbar">
<div>
<div class="report-title">laporan harian</div>
<div class="report-hint">klik baris atau tombol Lihat Detail untuk melihat rincian batch pada hari tersebut</div>
</div>
<div class="toolbar-btns">
<button class="tbtn" type="button" id="btn-pick-date" title="Pilih Tanggal" onclick="openDatePicker()">
<svg viewBox="0 0 16 16" fill="none" aria-hidden="true">
<rect x="2" y="2.5" width="12" height="11.5" rx="2" stroke="currentColor" stroke-width="1"/>
<path d="M2 6h12M5.5 1.5v2M10.5 1.5v2" stroke="currentColor" stroke-width="1"/>
</svg>
<span id="btn-pick-date-label">Pilih Tanggal</span>
</button>
<input type="date" id="date-filter" class="date-filter-input" tabindex="-1" aria-hidden="true">
<div id="active-date-chip" class="active-date-chip" style="display: none;">
<span id="active-date-chip-text"></span>
<button type="button" class="chip-clear-btn" onclick="resetFilter()" title="Hapus filter tanggal">&times;</button>
</div>
<button class="tbtn tbtn-primary" type="button" onclick="filterByDate()">
Filter
<svg viewBox="0 0 16 16" fill="none" aria-hidden="true">
<path d="M4 6l4 4 4-4" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</button>
<button class="tbtn" type="button" onclick="resetFilter()">Batalkan Filter</button>
<button class="tbtn tbtn-primary" type="button" onclick="exportSelected()">
Export Data
<svg viewBox="0 0 16 16" fill="none" aria-hidden="true">
<path d="M8 2v8M5 7l3 3 3-3M3 13h10" stroke="currentColor" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</button>
<button class="tbtn tbtn-outline" type="button" onclick="exportAll()">
Export All
<svg viewBox="0 0 16 16" fill="none" aria-hidden="true">
<path d="M8 2v8M5 7l3 3 3-3M3 13h10" stroke="currentColor" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</button>
</div>
</div>
<div class="report-desktop">
<div class="report-table report-table-pad">
<div class="report-table-head">
<span>tanggal</span>
<span>total hitung</span>
<span>batch</span>
<span>rata-rata/batch</span>
<span>status</span>
<span>aksi</span>
</div>
<div id="daily-table-body"></div>
</div>
</div>
<div class="report-mobile-list" id="daily-table-mobile"></div>
<div class="report-pagination" id="daily-pagination" hidden></div>
</div>
</main>
<!-- Detail Modal -->
<div class="modal-overlay hidden" id="detail-modal">
<div class="modal-content" id="modal-content">
<div class="modal-header">
<div>
<h2 id="modal-title">Detail Batch</h2>
<div class="modal-subtitle" id="modal-subtitle">--</div>
</div>
<button class="close-btn" type="button" onclick="closeModal()">&times;</button>
</div>
<div class="modal-stats">
<div class="modal-stat"><div class="ms-val" id="modal-total">--</div><div class="ms-label">total terhitung</div></div>
<div class="modal-stat"><div class="ms-val" id="modal-batches">--</div><div class="ms-label">total batch</div></div>
<div class="modal-stat"><div class="ms-val" id="modal-avg">--</div><div class="ms-label">rata-rata durasi (menit)</div></div>
</div>
<div class="modal-body">
<div class="modal-table-wrap">
<table class="modal-table">
<thead>
<tr>
<th>Batch #</th>
<th>Plat Nomor</th>
<th>Tipe</th>
<th>Sack</th>
<th>Box</th>
<th>Total</th>
<th>Mulai</th>
<th>Selesai</th>
<th>Durasi</th>
<th>Porsi</th>
</tr>
</thead>
<tbody id="modal-table-body"></tbody>
</table>
</div>
</div>
</div>
</div>
<!-- Stop Batch Confirmation Modal -->
<div class="modal-overlay hidden" id="stopBatchModal">
<div class="modal-content" style="max-width: 480px;">
<div class="modal-header">
<div>
<h2 style="color: #ef4444;"><i class="fas fa-hand-paper"></i> Selesaikan Batch</h2>
<div class="modal-subtitle">Konfirmasi Penutupan Batch</div>
</div>
<button class="close-btn" type="button" onclick="closeStopModal()">&times;</button>
</div>
<div style="margin: 16px 0; font-size: 13px; line-height: 1.6;">
Apakah Anda yakin ingin menyelesaikan dan menutup <strong id="modalStopBatchName" style="color:var(--blue-btn);">Batch #--</strong>?
<div style="background: var(--bg-panel); border: 1px solid var(--border); border-radius: 10px; padding: 16px; margin-top: 14px;">
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom: 8px;">
<span id="modalStopBatchLabel" style="color:var(--text-muted); font-size:12px;">Total Terhitung:</span>
<strong id="modalStopBatchCount" style="color:var(--green); font-size: 20px; font-family:var(--mono);">0</strong>
</div>
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom: 8px;">
<span style="color:var(--text-muted); font-size:12px;">Karung (Sack):</span>
<strong id="modalStopBatchSackCount" style="color:var(--text); font-size: 14px; font-family:var(--mono);">0</strong>
</div>
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom: 8px;">
<span style="color:var(--text-muted); font-size:12px;">Box:</span>
<strong id="modalStopBatchBoxCount" style="color:var(--text); font-size: 14px; font-family:var(--mono);">0</strong>
</div>
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom: 8px;">
<span style="color:var(--text-muted); font-size:12px;">Plat Nomor:</span>
<strong id="modalStopBatchPlate" style="color:var(--text); font-size: 13px; font-family:var(--mono);">-</strong>
</div>
<div style="display:flex; justify-content:space-between; align-items:center;">
<span style="color:var(--text-muted); font-size:12px;">Waktu Mulai:</span>
<span id="modalStopBatchStart" style="font-size: 12px; font-family:var(--mono); color:var(--text);">--:--:--</span>
</div>
</div>
<p style="margin-top: 12px; font-size: 11px; color: var(--text-muted);">
Data batch ini akan langsung disimpan ke database dan nomor batch berikutnya akan dinaikkan secara otomatis.
</p>
</div>
<div style="display:flex; justify-content:flex-end; gap: 10px;">
<button class="tbtn" type="button" onclick="closeStopModal()">Batal</button>
<button class="btn-batch btn-batch-stop" id="btnConfirmStop" type="button" onclick="confirmStopBatch()">
<i class="fas fa-check"></i> Ya, Selesaikan Batch
</button>
</div>
</div>
</div>
<!-- Toast Notification Container -->
<div id="toastContainer" style="position:fixed; bottom:24px; right:24px; z-index:9999; display:flex; flex-direction:column; gap:10px; pointer-events:none;"></div>
<script>
const LOGO_FALLBACK = "{{ url_for('static', filename='img/logo-zenai-white.svg') }}";
let mainChart = null;
let videoActive = false;
let videoErrorTimer = null;
let allDailyDates = [];
let dailyPage = 1;
const DAILY_PAGE_SIZE = 10;
let currentBatchState = {
active: false,
batch_number: null,
object_label: 'mixed',
next_batch_number: 1,
count: 0,
sack_count: 0,
box_count: 0,
plate: null,
start_time: null,
};
function getTheme() {
const t = document.documentElement.getAttribute('data-theme');
return t === 'light' ? 'light' : 'dark';
}
function chartThemeColors() {
const s = getComputedStyle(document.documentElement);
return {
muted: (s.getPropertyValue('--text-muted') || '#94A3B8').trim(),
tooltipBg: (s.getPropertyValue('--chart-tooltip-bg') || '#1A1C22').trim(),
grid: (s.getPropertyValue('--chart-grid') || 'rgba(46,53,84,0.5)').trim(),
text: (s.getPropertyValue('--text') || '#F1F5F9').trim(),
};
}
function syncThemeToggleUi() {
const btn = document.getElementById('themeToggle');
if (!btn) return;
const light = getTheme() === 'light';
btn.innerHTML = light ? '&#9790;' : '&#9788;';
btn.title = light ? 'Mode gelap' : 'Mode terang';
btn.setAttribute('aria-label', light ? 'Ganti ke mode gelap' : 'Ganti ke mode terang');
}
function setTheme(theme) {
const next = theme === 'light' ? 'light' : 'dark';
document.documentElement.setAttribute('data-theme', next);
try {
localStorage.setItem('apc-theme', next);
localStorage.setItem('theme', next);
} catch (e) {}
syncThemeToggleUi();
if (mainChart) {
const c = chartThemeColors();
mainChart.options.plugins.tooltip.backgroundColor = c.tooltipBg;
mainChart.options.plugins.tooltip.titleColor = c.text;
mainChart.options.plugins.tooltip.bodyColor = c.text;
mainChart.options.scales.x.ticks.color = c.muted;
mainChart.options.scales.y.ticks.color = c.muted;
mainChart.options.scales.y.title.color = c.muted;
mainChart.options.scales.y.grid.color = c.grid;
mainChart.options.scales.y1.ticks.color = c.muted;
mainChart.options.scales.y1.title.color = c.muted;
mainChart.update('none');
}
}
function toggleTheme() {
setTheme(getTheme() === 'light' ? 'dark' : 'light');
}
document.addEventListener('DOMContentLoaded', () => {
const logo = document.getElementById('site-logo');
if (logo) logo.addEventListener('error', () => { logo.src = LOGO_FALLBACK; });
syncThemeToggleUi();
const themeBtn = document.getElementById('themeToggle');
if (themeBtn) themeBtn.addEventListener('click', toggleTheme);
const dateInput = document.getElementById('date-filter');
if (dateInput) {
dateInput.addEventListener('change', function() {
if (this.value) filterByDate();
else resetFilter();
});
}
const accFill = document.getElementById('accuracy-fill');
if (accFill) accFill.style.width = `${accFill.dataset.accuracy || 98}%`;
loadSummary();
loadCurrentBatch();
loadChartData(7);
loadRecentBatches();
resetFilter();
setInterval(() => {
loadSummary();
loadRecentBatches();
}, 30000);
setInterval(() => {
loadCurrentBatch();
}, 2000);
});
async function loadCurrentBatch() {
try {
const res = await fetch('/api/current-batch');
const data = await res.json();
const isActive = Boolean(data.success && data.active !== false && data.batch_number != null);
const objType = (data.object_label || 'mixed').toLowerCase();
const objTypeUpper = objType.toUpperCase();
currentBatchState.active = isActive;
currentBatchState.batch_number = data.batch_number || null;
currentBatchState.object_label = objType;
currentBatchState.next_batch_number = data.next_batch_number || (data.batch_number ? data.batch_number + 1 : 1);
currentBatchState.count = data.count || 0;
currentBatchState.sack_count = data.sack_count || 0;
currentBatchState.box_count = data.box_count || 0;
currentBatchState.plate = data.plate || null;
currentBatchState.start_time = data.start_time || null;
const liveCountEl = document.getElementById('live-count');
const liveUnitEl = document.getElementById('live-unit');
const liveSackEl = document.getElementById('live-sack-count');
const liveBoxEl = document.getElementById('live-box-count');
const liveBatchEl = document.getElementById('live-batch-number');
const livePlateEl = document.getElementById('live-plate');
const liveLastDetEl = document.getElementById('live-last-detection');
const batchStatusEl = document.getElementById('batch-status');
const batchHintEl = document.getElementById('batch-status-hint');
const svcCounterEl = document.getElementById('svc-counter');
const svcCounterDot = document.getElementById('svc-counter-dot');
const svcCamEl = document.getElementById('svc-cam');
const svcCamDot = document.getElementById('svc-cam-dot');
// Control bar elements
const bcStatusBadge = document.getElementById('bcStatusBadge');
const bcStatusText = document.getElementById('bcStatusText');
const bcMainInfo = document.getElementById('bcMainInfo');
const bcSubInfo = document.getElementById('bcSubInfo');
const btnStart = document.getElementById('btnBatchStart');
const btnStop = document.getElementById('btnBatchStop');
const lblNextBatch = document.getElementById('lblNextBatch');
const lblCurrBatch = document.getElementById('lblCurrBatch');
if (svcCamEl) svcCamEl.textContent = videoActive ? 'Streaming' : 'Standby';
if (svcCamDot) svcCamDot.style.background = videoActive ? 'var(--green)' : 'var(--yellow-line)';
if (isActive) {
if (liveCountEl) liveCountEl.textContent = Number(data.count || 0).toLocaleString('id-ID');
if (liveUnitEl) liveUnitEl.textContent = 'Total';
if (liveSackEl) liveSackEl.textContent = Number(data.sack_count || 0).toLocaleString('id-ID');
if (liveBoxEl) liveBoxEl.textContent = Number(data.box_count || 0).toLocaleString('id-ID');
if (liveBatchEl) liveBatchEl.textContent = String(data.batch_number).padStart(4, '0');
if (livePlateEl) livePlateEl.textContent = data.plate || '-';
if (batchStatusEl) {
batchStatusEl.textContent = 'RUNNING';
batchStatusEl.className = 'badge-running';
}
if (batchHintEl) {
const plateInfo = data.plate ? ` · Plat ${data.plate}` : '';
batchHintEl.textContent = `Batch #${String(data.batch_number).padStart(4, '0')}${plateInfo} sedang berjalan`;
}
if (svcCounterEl) svcCounterEl.textContent = 'Running';
if (svcCounterDot) svcCounterDot.style.background = 'var(--green)';
if (data.last_detection_time) {
const lastDet = new Date(data.last_detection_time);
const timeStr = lastDet.toLocaleTimeString('id-ID', { hour12: false, hour: '2-digit', minute: '2-digit', second: '2-digit' });
if (liveLastDetEl) liveLastDetEl.textContent = timeStr;
const accUpd = document.getElementById('acc-updated');
if (accUpd) accUpd.textContent = lastDet.toLocaleTimeString('id-ID', { hour12: false, hour: '2-digit', minute: '2-digit' });
} else {
if (liveLastDetEl) liveLastDetEl.textContent = 'menunggu objek...';
}
if (bcStatusBadge) {
bcStatusBadge.className = 'bc-status-badge running';
bcStatusText.textContent = `BATCH #${data.batch_number} ACTIVE`;
}
if (bcMainInfo) {
const plateLabel = data.plate ? ` · Plat: ${data.plate}` : '';
bcMainInfo.textContent = `Batch #${data.batch_number}${plateLabel} Sedang Berjalan (${Number(data.count || 0).toLocaleString('id-ID')} total)`;
}
if (bcSubInfo) {
const startTimeStr = data.start_time ? new Date(data.start_time).toLocaleTimeString('id-ID', { hour12: false }) : '--:--:--';
const plateSub = data.plate ? ` · Plat: ${data.plate}` : '';
bcSubInfo.textContent = `Mulai pukul ${startTimeStr}${plateSub} · Menghitung karung dan box`;
}
if (btnStart) btnStart.style.display = 'none';
if (btnStop) {
btnStop.style.display = 'inline-flex';
if (lblCurrBatch) lblCurrBatch.textContent = `#${data.batch_number}`;
}
} else {
if (liveCountEl) liveCountEl.textContent = '0';
if (liveUnitEl) liveUnitEl.textContent = 'Total';
if (liveSackEl) liveSackEl.textContent = '0';
if (liveBoxEl) liveBoxEl.textContent = '0';
if (liveBatchEl) liveBatchEl.textContent = '----';
if (livePlateEl) livePlateEl.textContent = '-';
if (liveLastDetEl) liveLastDetEl.textContent = '--:--:--';
if (batchStatusEl) {
batchStatusEl.textContent = 'IDLE';
batchStatusEl.className = 'badge-idle';
}
if (batchHintEl) batchHintEl.textContent = 'Tidak ada batch aktif';
if (svcCounterEl) svcCounterEl.textContent = 'Idle';
if (svcCounterDot) svcCounterDot.style.background = 'var(--purple)';
if (bcStatusBadge) {
bcStatusBadge.className = 'bc-status-badge stopped';
bcStatusText.textContent = 'STOPPED / IDLE';
}
if (bcMainInfo) {
bcMainInfo.textContent = `Siap Menghitung (Batch #${currentBatchState.next_batch_number})`;
}
if (bcSubInfo) {
bcSubInfo.textContent = 'Sistem idle. Klik "Start Batch" untuk menghitung karung dan box sekaligus.';
}
if (btnStart) {
btnStart.style.display = 'inline-flex';
if (lblNextBatch) lblNextBatch.textContent = `#${currentBatchState.next_batch_number}`;
}
if (btnStop) btnStop.style.display = 'none';
}
} catch (err) {
console.error('loadCurrentBatch error:', err);
}
}
async function handleStartBatch() {
const btnStart = document.getElementById('btnBatchStart');
if (btnStart) btnStart.disabled = true;
showToast('Memulai batch baru...', 'info');
try {
const res = await fetch('/api/batch/start', { method: 'POST' });
const data = await res.json();
if (res.ok && data.success) {
showToast(`Batch #${data.batch_number} berhasil dimulai!`, 'success');
await loadCurrentBatch();
} else {
showToast(data.error || 'Gagal memulai batch', 'error');
}
} catch (e) {
showToast('Koneksi gagal ke server counter', 'error');
} finally {
if (btnStart) btnStart.disabled = false;
}
}
function handleStopBatch() {
const modal = document.getElementById('stopBatchModal');
const modalName = document.getElementById('modalStopBatchName');
const modalLabel = document.getElementById('modalStopBatchLabel');
const modalCount = document.getElementById('modalStopBatchCount');
const modalSack = document.getElementById('modalStopBatchSackCount');
const modalBox = document.getElementById('modalStopBatchBoxCount');
const modalPlate = document.getElementById('modalStopBatchPlate');
const modalStart = document.getElementById('modalStopBatchStart');
if (modalName) modalName.textContent = `Batch #${currentBatchState.batch_number || '--'}`;
if (modalLabel) modalLabel.textContent = 'Total Terhitung:';
if (modalCount) modalCount.textContent = Number(currentBatchState.count || 0).toLocaleString('id-ID');
if (modalSack) modalSack.textContent = Number(currentBatchState.sack_count || 0).toLocaleString('id-ID');
if (modalBox) modalBox.textContent = Number(currentBatchState.box_count || 0).toLocaleString('id-ID');
if (modalPlate) modalPlate.textContent = currentBatchState.plate || '-';
if (modalStart) {
modalStart.textContent = currentBatchState.start_time
? new Date(currentBatchState.start_time).toLocaleTimeString('id-ID', { hour12: false })
: '--:--:--';
}
if (modal) modal.classList.remove('hidden');
}
function closeStopModal() {
const modal = document.getElementById('stopBatchModal');
if (modal) modal.classList.add('hidden');
}
async function confirmStopBatch() {
const btn = document.getElementById('btnConfirmStop');
if (btn) btn.disabled = true;
try {
const res = await fetch('/api/batch/stop', { method: 'POST' });
const data = await res.json();
closeStopModal();
if (res.ok && data.success) {
showToast(`Batch #${data.batch_number} selesai (${data.count} item, ${data.sack_count} karung, ${data.box_count} box)!`, 'success');
await loadCurrentBatch();
await loadSummary();
await loadRecentBatches();
await loadAllDates();
} else {
showToast(data.error || 'Gagal menghentikan batch', 'error');
}
} catch (e) {
closeStopModal();
showToast('Koneksi gagal ke server counter', 'error');
} finally {
if (btn) btn.disabled = false;
}
}
function showToast(message, type = 'info') {
const container = document.getElementById('toastContainer');
if (!container) return;
const toast = document.createElement('div');
toast.className = `toast ${type}`;
let icon = 'info-circle';
if (type === 'success') icon = 'check-circle';
if (type === 'error') icon = 'exclamation-triangle';
toast.innerHTML = `<i class="fas fa-${icon}"></i><span>${message}</span>`;
container.appendChild(toast);
setTimeout(() => {
toast.style.opacity = '0';
toast.style.transform = 'translateX(40px)';
toast.style.transition = 'all 0.3s ease';
setTimeout(() => toast.remove(), 300);
}, 4000);
}
async function loadSummary() {
try {
const res = await fetch('/api/summary');
const data = await res.json();
const todayCount = Number(data.today?.total_count || 0);
const todayBatches = Number(data.today?.total_batches || 0);
const todaySack = Number(data.today?.sack_count || 0);
const todayBox = Number(data.today?.box_count || 0);
const yestCount = Number(data.yesterday?.total_count || 0);
const yestBatches = Number(data.yesterday?.total_batches || 0);
const avgPerDay = Number(data.average_per_day || 0);
const grandTotal = Number(data.all_time?.grand_total || 0);
const grandBatches = Number(data.all_time?.grand_batches || 0);
const totalDays = Number(data.all_time?.total_days || 0);
document.getElementById('current-date').textContent = data.today?.date || '--';
document.getElementById('today-count').textContent = todayCount.toLocaleString('id-ID');
document.getElementById('today-sack-count').textContent = todaySack.toLocaleString('id-ID');
document.getElementById('today-box-count').textContent = todayBox.toLocaleString('id-ID');
document.getElementById('today-batches').textContent = `${todayBatches} batch hari ini`;
document.getElementById('yesterday-count').textContent = yestCount.toLocaleString('id-ID');
document.getElementById('yesterday-batches').textContent = `${yestBatches} batch kemarin (${data.yesterday?.date ? formatDateID(data.yesterday.date) : '--'})`;
document.getElementById('avg-count').textContent = avgPerDay.toLocaleString('id-ID');
document.getElementById('total-days').textContent = `${totalDays} hari terekam`;
const vsAvg = avgPerDay > 0 ? Number((((todayCount - avgPerDay) / avgPerDay) * 100).toFixed(1)) : (todayCount > 0 ? 100 : 0);
const trendEl = document.getElementById('today-trend');
if (trendEl) {
trendEl.textContent = `${vsAvg > 0 ? '+' : ''}${vsAvg}%`;
trendEl.className = 'stat-trend-badge' + (vsAvg > 0 ? ' up' : vsAvg < 0 ? ' down' : '');
}
const vsYest = yestCount > 0 ? Number((((todayCount - yestCount) / yestCount) * 100).toFixed(1)) : (todayCount > 0 ? 100 : 0);
const perfTrend = document.getElementById('perf-today-trend');
if (perfTrend) {
perfTrend.textContent = `${vsYest > 0 ? '+' : ''}${vsYest}%`;
perfTrend.className = 'stat-trend-badge' + (vsYest > 0 ? ' up' : vsYest < 0 ? ' down' : '');
}
document.getElementById('best-count').textContent = Number(data.best_day?.count || 0).toLocaleString('id-ID');
document.getElementById('best-date').textContent = data.best_day?.date ? formatDateID(data.best_day.date) : '--';
document.getElementById('grand-total').textContent = grandTotal.toLocaleString('id-ID');
document.getElementById('grand-batches').textContent = grandBatches.toLocaleString('id-ID');
const avgBatch = grandBatches > 0 ? (grandTotal / grandBatches).toFixed(1) : '0';
document.getElementById('avg-per-batch').textContent = Number(avgBatch).toLocaleString('id-ID');
} catch (err) {
console.error('Failed to load summary:', err);
}
}
async function loadChartData(days) {
document.querySelectorAll('.pill').forEach(btn => {
btn.classList.toggle('active', parseInt(btn.dataset.days) === days);
});
try {
const res = await fetch(`/api/daily-data?days=${days}`);
const data = await res.json();
const labels = data.map(d => {
const dt = new Date(d.date + 'T00:00:00');
return dt.toLocaleDateString('id-ID', { day: 'numeric', month: 'short' });
});
const counts = data.map(d => d.total_count);
const batches = data.map(d => d.total_batches);
const c = chartThemeColors();
if (mainChart) mainChart.destroy();
const ctx = document.getElementById('mainChart').getContext('2d');
mainChart = new Chart(ctx, {
type: 'bar',
data: {
labels,
datasets: [
{
label: 'Total Karung/Box',
data: counts,
backgroundColor: '#1682B2',
borderRadius: 4,
yAxisID: 'y',
order: 2,
},
{
label: 'Batch',
data: batches,
type: 'line',
borderColor: '#FFE76F',
backgroundColor: 'transparent',
borderWidth: 2,
pointRadius: 5,
pointBackgroundColor: '#FFE76F',
tension: 0.35,
yAxisID: 'y1',
order: 1,
}
]
},
options: {
responsive: true,
maintainAspectRatio: false,
interaction: { mode: 'index', intersect: false },
plugins: {
legend: { display: false },
tooltip: {
backgroundColor: c.tooltipBg,
titleColor: c.text,
bodyColor: c.text,
titleFont: { family: 'JetBrains Mono' },
bodyFont: { family: 'JetBrains Mono', size: 11 },
}
},
scales: {
x: {
grid: { display: false },
ticks: { color: c.muted, font: { size: 10, family: 'Inter' } }
},
y: {
position: 'left',
grid: { color: c.grid },
ticks: { color: c.muted, font: { size: 10, family: 'JetBrains Mono' } },
title: { display: true, text: 'Total Karung/Box', color: c.muted, font: { size: 10 } }
},
y1: {
position: 'right',
grid: { display: false },
ticks: { color: c.muted, font: { size: 10, family: 'JetBrains Mono' } },
title: { display: true, text: 'Batch', color: c.muted, font: { size: 10 } }
}
}
}
});
} catch (err) {
console.error('Failed to load chart:', err);
}
}
function resolveBatchType(b) {
const sacks = Number(b?.sack_count || 0);
const boxes = Number(b?.box_count || 0);
if (sacks > 0 && boxes > 0) return 'mixed';
if (boxes > 0 && sacks === 0) return 'box';
if (sacks > 0 && boxes === 0) return 'sack';
const raw = (b?.object_label || 'mixed').toLowerCase();
return raw === 'box' ? 'box' : (raw === 'sack' ? 'sack' : 'mixed');
}
async function loadRecentBatches() {
try {
const res = await fetch('/api/recent-batches?limit=5');
const batches = await res.json();
const container = document.getElementById('recent-batches');
if (!batches || batches.length === 0) {
container.innerHTML = '<div class="recent-card"><div class="recent-batch">—</div><div class="recent-count" style="font-size:16px;color:var(--text-muted)">Belum ada data</div></div>';
return;
}
container.innerHTML = batches.map(b => {
const bType = resolveBatchType(b);
const typePill = bType === 'mixed'
? '<span class="type-pill mixed">MIXED</span>'
: `<span class="type-pill ${bType}">${bType.toUpperCase()}</span>`;
return `
<div class="recent-card">
<div class="recent-head">
<span class="recent-batch">B-${String(b.batch_number).padStart(4, '0')} ${typePill}</span>
<span class="recent-date">${formatDateID(b.date)}</span>
</div>
<div class="recent-count">${Number(b.count || 0).toLocaleString('id-ID')}</div>
<div class="recent-breakdown">${Number(b.sack_count || 0).toLocaleString('id-ID')} karung · ${Number(b.box_count || 0).toLocaleString('id-ID')} box</div>
<div class="recent-breakdown">Plat: <strong>${b.plate || '-'}</strong></div>
<div class="recent-time">${formatTimeShort(b.start_time)} - ${formatTimeShort(b.end_time)} · <strong>${b.duration_minutes} menit</strong></div>
</div>
`;
}).join('');
} catch (err) {
console.error('Failed to load recent batches:', err);
}
}
async function loadAllDates() {
try {
const res = await fetch('/api/available-dates');
allDailyDates = await res.json();
dailyPage = 1;
renderDailyTable();
} catch (err) {
console.error('Failed to load dates:', err);
}
}
function updateDateSelectionDisplay(dateStr) {
const btnLabel = document.getElementById('btn-pick-date-label');
const pickBtn = document.getElementById('btn-pick-date');
const chip = document.getElementById('active-date-chip');
const chipText = document.getElementById('active-date-chip-text');
if (!dateStr) {
if (btnLabel) btnLabel.textContent = 'Pilih Tanggal';
if (pickBtn) pickBtn.classList.remove('tbtn-active');
if (chip) chip.style.display = 'none';
return;
}
const formatted = formatDateID(dateStr);
if (btnLabel) btnLabel.textContent = formatted;
if (pickBtn) pickBtn.classList.add('tbtn-active');
if (chip && chipText) {
chipText.textContent = `📅 ${formatted}`;
chip.style.display = 'inline-flex';
}
}
function openDatePicker() {
const el = document.getElementById('date-filter');
if (!el) return;
try {
if (typeof el.showPicker === 'function') el.showPicker();
else { el.focus(); el.click(); }
} catch (_) {
el.focus();
el.click();
}
}
function resetFilter() {
const el = document.getElementById('date-filter');
if (el) el.value = '';
updateDateSelectionDisplay(null);
loadAllDates();
}
function filterByDate() {
const val = document.getElementById('date-filter').value;
if (!val) { resetFilter(); return; }
updateDateSelectionDisplay(val);
fetch('/api/available-dates')
.then(r => r.json())
.then(dates => {
allDailyDates = dates.filter(d => d.date === val);
dailyPage = 1;
renderDailyTable();
});
}
function renderDailyTable() {
const body = document.getElementById('daily-table-body');
const mobile = document.getElementById('daily-table-mobile');
const pager = document.getElementById('daily-pagination');
const currentDate = document.getElementById('current-date')?.textContent;
const dates = allDailyDates || [];
if (!dates.length) {
const emptyMsg = 'Belum ada data';
body.innerHTML = `<div class="report-empty">${emptyMsg}</div>`;
mobile.innerHTML = `<div style="padding:32px;text-align:center;color:var(--text-muted)">${emptyMsg}</div>`;
pager.hidden = true;
pager.innerHTML = '';
return;
}
const totalPages = Math.max(1, Math.ceil(dates.length / DAILY_PAGE_SIZE));
if (dailyPage > totalPages) dailyPage = totalPages;
const start = (dailyPage - 1) * DAILY_PAGE_SIZE;
const pageDates = dates.slice(start, start + DAILY_PAGE_SIZE);
body.innerHTML = pageDates.map(d => {
const isToday = d.date === currentDate;
const avg = d.total_batches > 0 ? (d.total_count / d.total_batches).toFixed(1) : '0';
return `
<div class="report-row">
<div class="row-date-cell">
<div class="row-check-wrap">
<input class="row-check" type="checkbox" data-date="${d.date}" aria-label="Pilih ${d.date}">
</div>
<div class="row-date-text">
<div class="row-date-main">${formatDateID(d.date)}</div>
<div class="row-date-sub">${isToday ? 'Hari Ini (Active)' : 'Historical Record'}</div>
</div>
</div>
<div class="cell-val cell-mono">${Number(d.total_count || 0).toLocaleString('id-ID')}</div>
<div class="cell-val cell-mono">${d.total_batches}</div>
<div class="cell-val cell-mono">${avg}</div>
<div class="cell-val">
<span class="badge-complete"><span class="bdot"></span>${isToday ? 'Active' : 'Complete'}</span>
</div>
<div class="cell-val">
<span class="link-detail" onclick="showDayDetail('${d.date}')">Lihat Detail</span>
</div>
</div>`;
}).join('');
mobile.innerHTML = pageDates.map(d => {
const isToday = d.date === currentDate;
const avg = d.total_batches > 0 ? (d.total_count / d.total_batches).toFixed(1) : '0';
return `
<div class="report-card-mobile">
<div class="rcm-head">
<div class="rcm-date-wrap">
<input class="row-check" type="checkbox" data-date="${d.date}" aria-label="Pilih ${d.date}">
<div>
<div class="rcm-date">${formatDateID(d.date)}</div>
<div class="rcm-sub">${isToday ? 'Hari Ini (Active)' : 'Historical Record'}</div>
</div>
</div>
<span class="badge-complete"><span class="bdot"></span>${isToday ? 'Active' : 'Complete'}</span>
</div>
<div class="rcm-grid">
<div class="rcm-item"><span class="rcm-label">Total hitung</span><span class="rcm-val">${Number(d.total_count || 0).toLocaleString('id-ID')}</span></div>
<div class="rcm-item"><span class="rcm-label">Batch</span><span class="rcm-val">${d.total_batches}</span></div>
<div class="rcm-item"><span class="rcm-label">Rata-rata/batch</span><span class="rcm-val">${avg}</span></div>
</div>
<div class="rcm-action">
<span class="link-detail" onclick="showDayDetail('${d.date}')">Lihat Detail</span>
</div>
</div>`;
}).join('');
renderDailyPagination(totalPages);
}
function renderDailyPagination(totalPages) {
const pager = document.getElementById('daily-pagination');
if (totalPages <= 1) {
pager.hidden = true;
pager.innerHTML = '';
return;
}
pager.hidden = false;
const pages = paginationWindow(dailyPage, totalPages);
pager.innerHTML = `
<button class="page-btn" type="button" aria-label="Halaman sebelumnya"
onclick="goDailyPage(${dailyPage - 1})" ${dailyPage <= 1 ? 'disabled' : ''}>&#9664;</button>
${pages.map(p => p === '...'
? '<span class="page-ellipsis">...</span>'
: `<button class="page-num${p === dailyPage ? ' active' : ''}" type="button" onclick="goDailyPage(${p})">${p}</button>`
).join('')}
<button class="page-btn" type="button" aria-label="Halaman berikutnya"
onclick="goDailyPage(${dailyPage + 1})" ${dailyPage >= totalPages ? 'disabled' : ''}>&#9654;</button>
`;
}
function paginationWindow(current, total) {
if (total <= 7) return Array.from({ length: total }, (_, i) => i + 1);
const pages = [];
const push = (v) => { if (pages[pages.length - 1] !== v) pages.push(v); };
push(1);
if (current > 3) push('...');
for (let p = Math.max(2, current - 1); p <= Math.min(total - 1, current + 1); p++) push(p);
if (current < total - 2) push('...');
push(total);
return pages;
}
function goDailyPage(page) {
const totalPages = Math.max(1, Math.ceil((allDailyDates || []).length / DAILY_PAGE_SIZE));
dailyPage = Math.min(Math.max(1, page), totalPages);
renderDailyTable();
}
async function showDayDetail(date) {
try {
const res = await fetch(`/api/day-detail/${date}`);
const data = await res.json();
const total = data.total_count || 0;
document.getElementById('modal-title').textContent = `Detail Batch — ${formatDateID(date)}`;
document.getElementById('modal-subtitle').textContent = `${data.total_batches} batch · ${total.toLocaleString('id-ID')} total terhitung`;
document.getElementById('modal-total').textContent = total.toLocaleString('id-ID');
document.getElementById('modal-batches').textContent = data.total_batches;
document.getElementById('modal-avg').textContent = data.avg_duration_minutes;
const batches = data.batches || [];
const totalDuration = batches.reduce((acc, b) => acc + (b.duration_minutes || 0), 0);
const sackTotal = Number(data.sack_count || 0);
const boxTotal = Number(data.box_count || 0);
let tableHtml = '';
if (batches.length) {
tableHtml = batches.map(b => {
const bType = resolveBatchType(b);
const typePill = bType === 'mixed'
? '<span class="type-pill mixed">MIXED</span>'
: `<span class="type-pill ${bType}">${bType.toUpperCase()}</span>`;
const pct = total > 0 ? (b.count / total) * 100 : 0;
return `
<tr>
<td class="mono">#${b.batch_number}</td>
<td class="mono">${b.plate || '-'}</td>
<td>${typePill}</td>
<td class="mono">${Number(b.sack_count || 0).toLocaleString('id-ID')}</td>
<td class="mono">${Number(b.box_count || 0).toLocaleString('id-ID')}</td>
<td class="mono">${Number(b.count || 0).toLocaleString('id-ID')}</td>
<td>${formatTime(b.start_time)}</td>
<td>${formatTime(b.end_time)}</td>
<td>${b.duration_minutes} menit</td>
<td class="mono">${pct.toFixed(1)}%</td>
</tr>`;
}).join('');
tableHtml += `
<tr style="background: rgba(22,130,178,0.12); font-weight: 700; border-top: 2px solid var(--border-accent);">
<td class="mono" style="font-weight:700;">TOTAL</td>
<td class="mono" style="color:var(--text-muted);">-</td>
<td><span class="status-badge info total-type-badge">${sackTotal.toLocaleString('id-ID')} Sack, ${boxTotal.toLocaleString('id-ID')} Box</span></td>
<td class="mono" style="font-weight:700;">${sackTotal.toLocaleString('id-ID')}</td>
<td class="mono" style="font-weight:700;">${boxTotal.toLocaleString('id-ID')}</td>
<td class="mono" style="font-weight:700; color: #38bdf8;">${total.toLocaleString('id-ID')}</td>
<td style="font-size:10px; color:var(--text-muted);">${batches[0] ? formatTime(batches[0].start_time) : '--'}</td>
<td style="font-size:10px; color:var(--text-muted);">${batches[batches.length - 1] ? formatTime(batches[batches.length - 1].end_time) : '--'}</td>
<td style="font-weight:700;">${Math.round(totalDuration * 10) / 10} menit</td>
<td class="mono" style="font-weight:700;">100%</td>
</tr>`;
} else {
tableHtml = `<tr><td colspan="10" class="modal-empty">Tidak ada batch pada tanggal ini</td></tr>`;
}
document.getElementById('modal-table-body').innerHTML = tableHtml;
document.getElementById('detail-modal').classList.remove('hidden');
} catch (err) {
console.error('Failed to load day detail:', err);
}
}
function closeModal() {
document.getElementById('detail-modal').classList.add('hidden');
}
function exportSelected() {
const checked = document.querySelector('.row-check:checked');
const date = (checked && checked.dataset.date) || document.getElementById('date-filter')?.value;
if (!date) {
exportDayDetail();
return;
}
window.location.href = '/api/export-day-csv/' + encodeURIComponent(date);
}
function exportAll() {
window.location.href = '/api/export-daily-csv?days=30';
}
async function exportDayDetail() {
try {
const date = document.getElementById('date-filter')?.value;
const url = date ? `/api/export-day-csv/${date}` : '/api/export-daily-csv';
const res = await fetch(url);
if (!res.ok) throw new Error('Export failed');
const blob = await res.blob();
const disposition = res.headers.get('Content-Disposition');
const filename = disposition
? decodeURIComponent(disposition.replace(/.*filename="?([^";]+)"?.*/, '$1'))
: `export_${date || 'all'}.xlsx`;
const a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.download = filename;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(a.href);
} catch (err) {
alert('Export error: ' + err.message);
}
}
function formatDateID(iso) {
if (!iso) return '--';
const d = new Date(iso + 'T00:00:00');
if (isNaN(d.getTime())) return iso;
return d.toLocaleDateString('id-ID', { day: '2-digit', month: '2-digit', year: 'numeric' });
}
function formatTime(iso) {
if (!iso) return '--';
return new Date(iso).toLocaleTimeString('id-ID', { hour12: false, hour: '2-digit', minute: '2-digit', second: '2-digit' });
}
function formatTimeShort(iso) {
if (!iso) return '--';
return new Date(iso).toLocaleTimeString('id-ID', { hour12: false, hour: '2-digit', minute: '2-digit' });
}
// --- Live Video Feed ---
function toggleVideo() {
const img = document.getElementById('live-video-img');
const placeholder = document.getElementById('video-placeholder');
const btn = document.getElementById('videoToggle');
const dot = document.getElementById('stream-dot');
const state = document.getElementById('stream-state');
if (videoActive) {
img.style.display = 'none';
img.src = '';
if (placeholder) placeholder.style.display = 'block';
btn.textContent = 'Buka stream';
btn.classList.remove('active');
dot.classList.add('off');
state.textContent = 'off';
videoActive = false;
hideVideoError();
} else {
resetFilter();
img.src = '/api/live-video?' + Date.now();
btn.textContent = 'Tutup stream';
btn.classList.add('active');
dot.classList.remove('off');
state.textContent = 'on';
videoActive = true;
}
loadCurrentBatch();
}
function onVideoLoad() {
document.getElementById('live-video-img').style.display = 'block';
const placeholder = document.getElementById('video-placeholder');
if (placeholder) placeholder.style.display = 'none';
hideVideoError();
}
function onVideoError() {
if (!videoActive) return;
const overlay = document.getElementById('video-error-overlay');
if (overlay) overlay.classList.add('visible');
if (videoErrorTimer) clearTimeout(videoErrorTimer);
videoErrorTimer = setTimeout(() => {
if (videoActive) {
document.getElementById('live-video-img').src = '/api/live-video?' + Date.now();
}
}, 2000);
}
function hideVideoError() {
const overlay = document.getElementById('video-error-overlay');
if (overlay) overlay.classList.remove('visible');
if (videoErrorTimer) { clearTimeout(videoErrorTimer); videoErrorTimer = null; }
}
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape') {
closeModal();
closeStopModal();
}
});
document.getElementById('detail-modal').addEventListener('click', e => {
if (e.target.id === 'detail-modal') closeModal();
});
</script>
</body>
</html>