// MODIBU - Modals
const { useState: useStateM, useEffect: useEffectM, useRef: useRefM } = React;
// ============ Quiz Modal (Edukasi / Fakta-Hoax) ============
function QuizModal({ data, onClose, onAnswer }) {
const [selected, setSelected] = useStateM(null);
const [locked, setLocked] = useStateM(false);
const [time, setTime] = useStateM(15);
const totalRef = useRefM(15);
useEffectM(() => {
if (locked) return;
if (time <= 0) {
setLocked(true);
return;
}
const t = setTimeout(() => setTime(s => s - 1), 1000);
return () => clearTimeout(t);
}, [time, locked]);
const handleSelect = (key) => {
if (locked) return;
setSelected(key);
setLocked(true);
};
const isCorrect = selected === data.correct;
const timedOut = locked && selected === null;
const accent = data.type === 'edukasi' ? 'var(--c-edukasi)' : 'var(--c-fakta)';
const accentDeep = data.type === 'edukasi' ? 'var(--c-edukasi-deep)' : 'var(--c-fakta-deep)';
const catLabel = data.type === 'edukasi' ? 'EDUKASI' : 'FAKTA / HOAKS';
const pct = (time / totalRef.current) * 100;
const danger = time <= 5;
return (
e.stopPropagation()}>
{/* Close Button (Top-Right Corner) */}
{/* Header */}
{/* Illustration (Medium Size) */}
{data.icon && (
)}
{/* Timer */}
{/* Question */}
{data.question}
{/* Options */}
{data.options.map(opt => {
let cls = 'option-btn';
if (locked) {
if (opt.key === data.correct) cls += ' correct';
else if (opt.key === selected) cls += ' wrong';
else cls += ' disabled';
}
return (
);
})}
{/* Result */}
{locked && (
{timedOut ? '⏰' : isCorrect ? '🎉' : '💪'}
{timedOut ? 'Waktu habis!' : isCorrect ? `Tepat sekali! +${data.type === 'edukasi' ? 10 : 10} poin` : 'Belum tepat. 0 poin'}
Penjelasan: {data.explanation}
{data.tip && (
{data.tip}
)}
)}
);
}
// ============ Challenge Modal (Tantangan / Refleksi) ============
function ChallengeModal({ data, onClose, onSubmit }) {
const [text, setText] = useStateM('');
const [sent, setSent] = useStateM(false);
const isRefleksi = data.type === 'refleksi';
const accent = isRefleksi ? 'var(--c-refleksi)' : 'var(--c-tantangan)';
const accentDeep = isRefleksi ? 'var(--c-refleksi-deep)' : 'var(--c-tantangan-deep)';
return (
e.stopPropagation()}>
{/* Close Button (Top-Right Corner) */}
{data.category.toUpperCase()}
{/* Illustration (Medium Size) */}
{data.icon && (
)}
{!sent ? (
<>
{data.question}
{data.example && (
{data.example}
)}
);
}
// ============ Card Modal (Kesempatan / Hukuman) ============
function CardModal({ data, onClose }) {
const isHukuman = data.type === 'hukuman';
const accent = isHukuman ? 'var(--c-hukuman)' : 'var(--c-kesempatan)';
const accentDeep = isHukuman ? 'var(--c-hukuman-deep)' : 'var(--c-kesempatan-deep)';
const icon = isHukuman ? '🚨' : '⭐';
return (
e.stopPropagation()} style={{
position: 'relative',
animation: 'popIn 0.3s ease-out',
}}>
{/* Close Button (Top-Right) */}
{/* Top stripe */}
KARTU {isHukuman ? 'HUKUMAN' : 'KESEMPATAN'}
{/* Center icon */}
{icon}
{data.title}
{data.desc}
{/* Effect */}
{data.effect}
);
}
// ============ Material Popup (Tahukah kamu?) ============
function MaterialModal({ data, onClose }) {
return (
e.stopPropagation()}>
{/* Close Button (Top-Right) */}
💡
{data.title.toUpperCase()}
{data.subtitle}
{data.body}
{data.points.map((p, i) => (
))}
);
}
Object.assign(window, { QuizModal, ChallengeModal, CardModal, MaterialModal });