/* ═══════════════════════════════════════════════════════════
Barrel-wear view — cleaning interval, muzzle-brake life,
barrel lifetime. M10 charges advance muzzle + barrel wear;
every shell advances the cleaning counter.
─────────────────────────────────────────────────────────
Thresholds below are operational placeholders — adjust to
your unit's doctrine in one place.
═══════════════════════════════════════════════════════════ */
(function () {
const { useState: useStateB } = React;
const {
GUNS: GUNS_B, fmtDatetime: fmtB, Modal: ModalB, PasswordGate: PasswordGateB,
} = window;
const WEAR_LIMITS = {
clean: 100, // פגזים עד נקיון קנה
muzzle: 350, // M10 עד החלפת בולם לוע
barrel: 1500, // M10 עד תום חיי קנה
};
function wearZone(v, max) {
const pct = max ? (v / max) * 100 : 0;
if (pct >= 90) return { cls: 'danger', color: 'var(--danger)', soft: 'var(--danger-soft)', label: 'קריטי' };
if (pct >= 70) return { cls: 'warn', color: 'var(--warn)', soft: 'var(--warn-soft)', label: 'התראה' };
return { cls: 'ok', color: 'var(--ok)', soft: 'var(--ok-soft)', label: 'תקין' };
}
function WearMeter({ label, value, max, hint, color }) {
const pct = Math.min(100, max ? (value / max) * 100 : 0);
const z = wearZone(value, max);
const c = color || z.color;
return (
{label}
{value} / {max}
{hint}
{Math.round(pct)}%
);
}
function BarrelCard({ gun, data, onReset }) {
const bd = data || {};
const muzzle = bd.muzzle || { count: 0, lastResetTs: null };
const barrel = bd.barrel || { count: 0, lastResetTs: null };
const sinceClean = bd.shellsSinceClean || 0;
const cleanZone = wearZone(sinceClean, WEAR_LIMITS.clean);
return (
{gun}
{cleanZone.label}
סה"כ {bd.totalShells || 0} פגזים
);
}
function BarrelView({ state, dispatch }) {
const [pending, setPending] = useStateB(null); // {kind, gun}
const [authed, setAuthed] = useStateB(null);
const RESET_LABELS = {
clean: { title: 'אישור נקיון קנה', verb: 'איפוס מונה נקיון', action: 'RESET_BARREL', note: 'מונה הפגזים שמאז הנקיון יאופס.' },
muzzle: { title: 'החלפת בולם לוע', verb: 'איפוס מונה בולם לוע', action: 'RESET_MUZZLE', note: 'מונה ה-M10 של בולם הלוע יאופס.' },
barrel: { title: 'התקנת קנה חדש', verb: 'איפוס חיי קנה', action: 'RESET_BARREL_WEAR', note: 'מונה ה-M10 של חיי הקנה יאופס. פעולה משמעותית.' },
};
const requestReset = (kind, gun) => setPending({ kind, gun });
const doReset = () => {
if (!authed) return;
dispatch({ type: RESET_LABELS[authed.kind].action, gun: authed.gun });
setAuthed(null);
};
return (
בלאי קנה
כל פגז מקדם את מונה הנקיון. מטעני M10 בלבד מקדמים את בלאי בולם הלוע וחיי הקנה.
תקין
התראה ≥70%
קריטי ≥90%
{GUNS_B.map(g => )}
{pending && (
{ setAuthed(pending); setPending(null); }} onCancel={() => setPending(null)} />
)}
{authed && (
setAuthed(null)}>
{RESET_LABELS[authed.kind].note}
)}
);
}
window.BarrelView = BarrelView;
})();