/* eslint-disable */ /* © 2026 K2B NETWORK SOLUTIONS LLC. All rights reserved. Proprietary and confidential. Unauthorized copying, distribution, or use of this file, via any medium, is strictly prohibited. Original work product. */ // JBREWS DMS — Forms Sequencing & Document Group Assignment (Sales & F&I). // Manages window.jbForms: which printed forms attach to a deal and in what // order, conditioned on deal type (New/Used/Lease…), funding bank, and buyer // state. Mirrors the Dealertrack "Forms Sequence / Document Group Assignment" // flow. A live preview shows the resolved packet for a sample deal context. const fsBadge = (txt, color) => ( {txt} ); const FormsSequencing = ({ onClose, go }) => { const [, force] = React.useReducer(n => n + 1, 0); React.useEffect(() => window.jbForms ? window.jbForms.subscribe(force) : undefined, []); const list = window.jbForms ? window.jbForms.list().slice().sort((a, b) => a.seq - b.seq) : []; const DEAL_TYPES = window.jbForms ? window.jbForms.DEAL_TYPES : []; const GROUPS = window.jbForms ? window.jbForms.GROUPS : []; const bankNames = window.jbLenders ? window.jbLenders.list().map(l => l.name) : []; const [edit, setEdit] = React.useState(null); // Live preview context const [pvType, setPvType] = React.useState("Used"); const [pvBank, setPvBank] = React.useState(bankNames[0] || ""); const [pvState, setPvState] = React.useState("MO"); const resolved = window.jbForms ? window.jbForms.resolve({ dealType: pvType, bank: pvBank, state: pvState }) : []; const blank = { seq: (list.length ? Math.max(...list.map(f => f.seq)) + 10 : 10), name: "", printKey: "buyersOrder", group: "Always Required", dealTypes: ["New", "Used"], banks: [], states: [], copies: 1, dest: "screen", active: true }; return (
{}} onMax={() => {}} />
{/* ── Left: sequence table ── */}
Forms attach to a deal in sequence order, filtered by the rules on each row.
{["Seq", "Form", "Group", "Deal Types", "Banks", "States", "Copies", "Dest"].map((h, i) => ( ))} {list.map((f, i) => ( setEdit({ ...f })} style={{ background: i % 2 ? "var(--jb-surface-2)" : "#fff", cursor: "pointer", opacity: f.active ? 1 : 0.45 }}> ))}
{h}
{f.seq} {f.name}{!f.active && · inactive} {fsBadge(f.group, "var(--jb-blue)")} {f.dealTypes.length ? f.dealTypes.join(", ") : "All"} {f.banks.length ? f.banks.join(", ") : "Any"} {f.states.length ? f.states.join(", ") : "Any"} {f.copies} {f.dest === "printer" ? fsBadge("🖨 Printer", "var(--jb-navy)") : fsBadge("🖥 Screen", "var(--jb-text-muted)")}
{/* ── Right: live preview ── */}
Packet Preview
{resolved.length} form{resolved.length !== 1 ? "s" : ""} in packet
    {resolved.map(f => (
  1. {f.name} · {f.copies}× {f.dest === "printer" ? "printer" : "screen"}
  2. ))} {!resolved.length &&
  3. No forms match this context.
  4. }
{edit && setEdit(null)} onSave={(r) => { window.jbForms.upsert(r); setEdit(null); window.k2bToast && window.k2bToast(`${r.name || "Form"} saved.`, "ok"); }} onDelete={edit.id ? () => { window.jbForms.remove(edit.id); setEdit(null); window.k2bToast && window.k2bToast("Form removed.", "warn"); } : null} />}
); }; const FormEditor = ({ rec, DEAL_TYPES, GROUPS, bankNames, onClose, onSave, onDelete }) => { const [r, setR] = React.useState({ ...rec, states: (rec.states || []).join(", ") }); const set = (k, v) => setR(p => ({ ...p, [k]: v })); const toggleArr = (k, val) => setR(p => { const a = p[k] || []; return { ...p, [k]: a.includes(val) ? a.filter(x => x !== val) : [...a, val] }; }); const PRINT_KEYS = [ ["buyersOrder", "Buyer's Order / Contract"], ["billOfSale", "Bill of Sale"], ["odometer", "Odometer Disclosure"], ["privacy", "Privacy Notice"], ["asIs", "As-Is — No Warranty"], ["releaseTrade", "Release of Liability (Trade)"], ["release", "Release of Liability (Sold)"], ].filter(([k]) => !(window.K2BForms && window.K2BForms.owns(k))) .concat(window.K2BForms ? window.K2BForms.printKeys() : []); // RC37 (forms37): the dealership's own forms (same keys where the DMS had them) const Chip = ({ on, onClick, children }) => ( ); const valid = (r.name || "").trim().length > 0; const save = () => { if (!valid) { window.k2bToast && window.k2bToast("Form name is required.", "warn"); return; } onSave({ ...r, states: String(r.states || "").split(",").map(s => s.trim().toUpperCase()).filter(Boolean) }); }; return ( {onDelete && Delete} Cancel Save }>
Applies to Deal Types (none = all)
{DEAL_TYPES.map(t => toggleArr("dealTypes", t)}>{t})}
Only for Banks (none = any bank)
{bankNames.map(b => toggleArr("banks", b)}>{b})}
Default Destination
set("dest", "screen")}>🖥 Screen set("dest", "printer")}>🖨 Printer
); }; Object.assign(window, { FormsSequencing });