/* ============================================================
   inventory.jsx — searchable / filterable instrument registry
   ============================================================ */
function InstrumentCard({ inst, onClick }) {
  const s = statusOf(inst);
  const decomm = isDecommissioned(inst);
  return (
    <button className="card enter" onClick={onClick} style={{
      textAlign: 'left', cursor: 'pointer', padding: 0, overflow: 'hidden', display: 'flex', flexDirection: 'column',
      transition: 'transform .12s, box-shadow .15s, border-color .15s', opacity: decomm ? 0.6 : 1,
    }}
      onMouseEnter={e => { e.currentTarget.style.transform = 'translateY(-3px)'; e.currentTarget.style.boxShadow = 'var(--shadow)'; e.currentTarget.style.borderColor = 'var(--ink-4)'; }}
      onMouseLeave={e => { e.currentTarget.style.transform = ''; e.currentTarget.style.boxShadow = ''; e.currentTarget.style.borderColor = ''; }}>
      <div style={{ height: 4, background: decomm ? 'var(--ink-4)' : deptColor(inst.dept) }} />
      <div style={{ padding: '15px 17px', flex: 1, display: 'flex', flexDirection: 'column', gap: 11 }}>
        <div style={{ display: 'flex', alignItems: 'flex-start', justifyContent: 'space-between', gap: 10 }}>
          <span className="kbd-code">{inst.code}</span>
          {decomm
            ? <span className="pill none" style={{ fontSize: 'var(--fs-xs)' }}><span className="dot" /> ปลดระวาง</span>
            : <Pill status={s} showDays />}
        </div>
        <div>
          <div style={{ fontWeight: 600, fontSize: 14.5, lineHeight: 1.3, textWrap: 'pretty' }}>{inst.type}</div>
          <div style={{ fontSize: 12.5, color: 'var(--ink-3)', marginTop: 3 }}>{inst.brand}{inst.model && inst.model !== '-' ? ` · ${inst.model}` : ''}</div>
        </div>
        <div style={{ marginTop: 'auto', display: 'flex', alignItems: 'center', justifyContent: 'space-between', paddingTop: 4 }}>
          <DeptBadge dept={inst.dept} />
          <span style={{ fontSize: 11.5, color: 'var(--ink-3)' }}>{s.kind === 'pm' ? 'PM ถัดไป ' + (fmtDate(inst.pmNext) || '—') : 'หมดอายุ ' + (fmtDate(inst.exp) || '—')}</span>
        </div>
      </div>
    </button>
  );
}

function ExportMenu({ rows, dept, selectedRows }) {
  const [open, setOpen] = useState(false);
  const ref = useRef(null);
  useEffect(() => {
    const h = (e) => { if (ref.current && !ref.current.contains(e.target)) setOpen(false); };
    document.addEventListener('mousedown', h);
    return () => document.removeEventListener('mousedown', h);
  }, []);
  const useSel = selectedRows && selectedRows.length > 0;
  const exportRows = useSel ? selectedRows : rows;          // ☑ selection wins, else current filter
  const sub = useSel ? `เลือกไว้ ${selectedRows.length} รายการ` : (dept !== 'all' ? `แผนก ${(DEPT_META[dept] || {}).short || dept}` : 'ทุกแผนก');
  const fname = 'lab-instruments' + (dept !== 'all' ? '-' + (DEPT_META[dept] || {}).abbr : '');
  return (
    <div style={{ position: 'relative' }} ref={ref}>
      <button className="btn" onClick={() => setOpen(o => !o)}><I.download size={16} /> ส่งออก <I.chevD size={14} /></button>
      {open && (
        <div className="card enter" style={{ position: 'absolute', right: 0, top: 'calc(100% + 6px)', width: 248, zIndex: 30, boxShadow: 'var(--shadow-lg)', padding: 6 }}>
          <div style={{ fontSize: 11, color: 'var(--ink-3)', padding: '6px 10px' }}>ส่งออก {exportRows.length} รายการ ({sub})</div>
          <button className="menu-item" onClick={() => { window.exportCSV(exportRows, fname); setOpen(false); }}>
            <span style={{ width: 30, height: 30, borderRadius: 8, background: 'var(--ok-soft)', color: 'var(--ok-ink)', display: 'grid', placeItems: 'center', flex: 'none' }}><I.grid size={16} /></span>
            <div><div style={{ fontWeight: 600, fontSize: 13 }}>Excel (.csv)</div><div style={{ fontSize: 11, color: 'var(--ink-3)' }}>เปิดใน Excel / Google Sheets</div></div>
          </button>
          <button className="menu-item" onClick={() => { window.exportStandardRegister(exportRows, { filename: 'ทะเบียนรับรองมาตรฐาน' }); setOpen(false); }}>
            <span style={{ width: 30, height: 30, borderRadius: 8, background: 'var(--accent-soft)', color: 'var(--accent-strong)', display: 'grid', placeItems: 'center', flex: 'none' }}><I.shield size={16} /></span>
            <div><div style={{ fontWeight: 600, fontSize: 13 }}>ทะเบียนรับรองมาตรฐาน (.xlsx)</div><div style={{ fontSize: 11, color: 'var(--ink-3)' }}>ตามแบบฟอร์มรับรองห้องปฏิบัติการ</div></div>
          </button>
          <button className="menu-item" onClick={() => { window.printReport(exportRows, { subtitle: sub }); setOpen(false); }}>
            <span style={{ width: 30, height: 30, borderRadius: 8, background: 'var(--danger-soft)', color: 'var(--danger-ink)', display: 'grid', placeItems: 'center', flex: 'none' }}><I.list size={16} /></span>
            <div><div style={{ fontWeight: 600, fontSize: 13 }}>PDF / พิมพ์รายงาน</div><div style={{ fontSize: 11, color: 'var(--ink-3)' }}>ตารางสรุปพร้อมสถานะ</div></div>
          </button>
        </div>
      )}
    </div>
  );
}

/* a representative icon per department (colour carries the real identity) */
function deptIcon(d) {
  const a = (DEPT_META[d] || {}).abbr || '';
  return ({ BLD: I.bloodbag, CHE: I.flask, HEM: I.micro, MIC: I.bacteria, MOL: I.dna, SER: I.antibody, CYT: I.slide, SPM: I.inbox })[a] || I.building;
}

function Inventory({ instruments, go, initial, globalDensity, admin, onDelete, savedFilters, onFilters }) {
  const sf = savedFilters || {};
  // restore last-used filters (so returning from a detail page keeps your place);
  // an explicit dept from the route (sidebar click) overrides the saved dept
  const [q, setQ] = useState(sf.q || '');
  const [dept, setDept] = useState(initial?.dept || sf.dept || 'all');
  const [typeAbbr, setTypeAbbr] = useState(sf.typeAbbr || 'all');
  const [stat, setStat] = useState(sf.stat || 'all');
  const [view, setView] = useState('table');
  const [sort, setSort] = useState({ key: 'code', dir: 1 });
  const [density, setDensity] = useState('regular');
  const [lifeView, setLifeView] = useState(sf.lifeView || 'active');   // active | decommissioned | all
  const [viewAll, setViewAll] = useState(!!sf.viewAll);   // true = flat list across all depts (skip the dept landing)

  useEffect(() => {
    if (initial?.dept) setDept(initial.dept);
    else if (initial?.home) { setDept('all'); setViewAll(false); setStat('all'); setTypeAbbr('all'); setLifeView('active'); setQ(''); }
  }, [initial]);
  // persist filter state up to the app so it survives unmount/remount
  useEffect(() => { onFilters && onFilters({ dept, stat, lifeView, typeAbbr, q, viewAll }); }, [dept, stat, lifeView, typeAbbr, q, viewAll]);

  const depts = useMemo(() => [...new Set(instruments.map(i => i.dept))], [instruments]);
  const typeList = useMemo(() => {
    const m = {};
    instruments.forEach(i => { const a = (i.code || '').split('-')[2]; if (a) m[a] = (m[a] || 0) + 1; });
    const types = (window.LAB_DATA && window.LAB_DATA.types) || [];
    const nameOf = (a) => { const t = types.find(x => x.abbr === a); return t ? t.th : a; };
    return Object.keys(m).sort().map(a => ({ abbr: a, name: nameOf(a), n: m[a] }));
  }, [instruments]);

  // instruments exempt from both calibration and PM (statusOf key='ok' but kind='na')
  // get their own filter bucket instead of being counted as "ปกติ"
  const bucketOf = (i) => { const s = statusOf(i); return s.kind === 'na' ? 'na' : s.key; };

  const filtered = useMemo(() => {
    const ql = q.trim().toLowerCase();
    let rows = instruments.filter(i => {
      const decomm = isDecommissioned(i);
      if (lifeView === 'active' && decomm) return false;
      if (lifeView === 'decommissioned' && !decomm) return false;
      if (dept !== 'all' && i.dept !== dept) return false;
      if (typeAbbr !== 'all' && ((i.code || '').split('-')[2] || '') !== typeAbbr) return false;
      if (stat !== 'all' && bucketOf(i) !== stat) return false;
      if (ql) {
        const hay = `${i.code} ${i.type} ${i.brand} ${i.model} ${i.serial} ${i.dept} ${i.typeName}`.toLowerCase();
        if (!hay.includes(ql)) return false;
      }
      return true;
    });
    const { key, dir } = sort;
    rows = [...rows].sort((a, b) => {
      let av, bv;
      if (key === 'status') { av = STATUS_ORDER[statusOf(a).key]; bv = STATUS_ORDER[statusOf(b).key]; }
      else if (key === 'exp') { av = a.exp || 'zzzz'; bv = b.exp || 'zzzz'; }
      else { av = (a[key] || '').toString().toLowerCase(); bv = (b[key] || '').toString().toLowerCase(); }
      return av < bv ? -dir : av > bv ? dir : 0;
    });
    return rows;
  }, [instruments, q, dept, typeAbbr, stat, sort, lifeView]);

  const statCounts = useMemo(() => {
    const c = { all: instruments.length, ok: 0, warn: 0, danger: 0, none: 0, na: 0 };
    instruments.forEach(i => c[bucketOf(i)]++);
    return c;
  }, [instruments]);
  const decommCount = useMemo(() => instruments.filter(isDecommissioned).length, [instruments]);
  const deptCounts = useMemo(() => { const c = {}; instruments.forEach(i => { c[i.dept] = (c[i.dept] || 0) + 1; }); return c; }, [instruments]);
  // per-department status breakdown for the landing cards (active instruments)
  const deptStats = useMemo(() => {
    const m = {};
    instruments.forEach(i => {
      const d = i.dept; if (!d) return;
      if (!m[d]) m[d] = { total: 0, ok: 0, warn: 0, danger: 0, none: 0, na: 0, decomm: 0 };
      m[d].total++;
      if (isDecommissioned(i)) { m[d].decomm++; return; }
      const k = bucketOf(i); m[d][k] = (m[d][k] || 0) + 1;
    });
    return m;
  }, [instruments]);
  const orderedDepts = useMemo(() => {
    const known = Object.keys(DEPT_META).filter(d => deptCounts[d]);
    const extra = depts.filter(d => !DEPT_META[d]);
    return [...known, ...extra];
  }, [depts, deptCounts]);
  // the department landing shows only when nothing is being filtered/searched
  const showLanding = dept === 'all' && !viewAll && !q.trim() && stat === 'all' && typeAbbr === 'all' && lifeView === 'active';
  const backToLanding = () => { setDept('all'); setViewAll(false); setStat('all'); setTypeAbbr('all'); setLifeView('active'); setQ(''); };

  const toggleSort = (key) => setSort(s => s.key === key ? { key, dir: -s.dir } : { key, dir: 1 });
  // called as a function, not <SortHead/>: a component declared in render is a new type
  // each render, so React would remount the <th> and keyboard focus would drop off it
  const sortHead = (k, children, style) => (
    <th {...pressable(() => toggleSort(k), { asRow: true })} style={style}>
      <span style={{ display: 'inline-flex', alignItems: 'center', gap: 4 }}>
        {children}
        <span style={{ opacity: sort.key === k ? 1 : 0.25, fontSize: 'var(--fs-xs)' }}>{sort.key === k ? (sort.dir === 1 ? '▲' : '▼') : '↕'}</span>
      </span>
    </th>
  );

  const monitor = globalDensity === 'monitor';
  const pad = monitor ? '5px 11px' : density === 'compact' ? '7px 14px' : density === 'comfy' ? '16px 14px' : '12px 14px';
  const rowFont = monitor ? 12.5 : 13.5;
  const [selected, setSelected] = useState(() => new Set());
  const [labelItems, setLabelItems] = useState(null);
  const toggleSel = (code) => setSelected(s => { const n = new Set(s); n.has(code) ? n.delete(code) : n.add(code); return n; });
  const filteredCodes = filtered.map(i => i.code);
  const allSel = filteredCodes.length > 0 && filteredCodes.every(c => selected.has(c));
  const toggleAll = () => setSelected(s => { const n = new Set(s); if (allSel) filteredCodes.forEach(c => n.delete(c)); else filteredCodes.forEach(c => n.add(c)); return n; });
  const printSelected = () => { const items = instruments.filter(i => selected.has(i.code)); if (items.length) setLabelItems(items); };

  return (
    <div style={{ display: 'flex', flexDirection: 'column', gap: 18 }}>
      {/* toolbar */}
      <div style={{ display: 'flex', gap: 12, alignItems: 'center', flexWrap: 'wrap' }}>
        <div className="search" style={{ flex: '1 1 280px', maxWidth: 440 }}>
          <I.search className="ico" size={17} />
          <input aria-label="ค้นหาเครื่องมือ" placeholder="ค้นหา รหัส / ชื่อ / ยี่ห้อ / Serial…" value={q} onChange={e => setQ(e.target.value)} />
        </div>
        <div style={{ flex: 1 }} />
        {selected.size > 0 && (
          <button className="btn" onClick={printSelected}><I.qr size={16} /> พิมพ์ป้าย ({selected.size})</button>
        )}
        <ExportMenu rows={filtered} dept={dept} selectedRows={instruments.filter(i => selected.has(i.code))} />
        <div className="seg">
          <button className={view === 'table' ? 'on' : ''} onClick={() => setView('table')} title="ตาราง"><I.list size={16} /></button>
          <button className={view === 'grid' ? 'on' : ''} onClick={() => setView('grid')} title="การ์ด"><I.grid size={16} /></button>
        </div>
      </div>

      {showLanding ? (
        <div className="enter" style={{ display: 'flex', flexDirection: 'column', gap: 16 }}>
          <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fill, minmax(230px, 1fr))', gap: 14 }}>
            {orderedDepts.map(d => {
              const st = deptStats[d] || { total: 0, ok: 0, warn: 0, danger: 0, none: 0, na: 0, decomm: 0 };
              const color = deptColor(d);
              const Ico = deptIcon(d);
              const active = st.total - st.decomm;
              return (
                <button key={d} className="card dept-card" onClick={() => setDept(d)} style={{ textAlign: 'left', padding: 0, overflow: 'hidden', cursor: 'pointer', display: 'flex', flexDirection: 'column' }}>
                  <div style={{ display: 'flex', alignItems: 'center', gap: 12, padding: '15px 16px' }}>
                    <span style={{ width: 46, height: 46, borderRadius: 13, background: color, color: '#fff', display: 'grid', placeItems: 'center', flex: 'none', boxShadow: 'var(--shadow-sm)' }}><Ico size={23} /></span>
                    <div style={{ minWidth: 0, flex: 1 }}>
                      <div style={{ fontWeight: 700, fontSize: 15.5, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>{(DEPT_META[d] || {}).short || d}</div>
                      <div style={{ fontSize: 11.5, color: 'var(--ink-3)', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>{(DEPT_META[d] || {}).th || ''}</div>
                    </div>
                    <div style={{ textAlign: 'right', flex: 'none' }}>
                      <div className="figure" style={{ fontSize: 25, lineHeight: 1 }}>{active}</div>
                      <div style={{ fontSize: 'var(--fs-xs)', color: 'var(--ink-3)' }}>เครื่อง</div>
                    </div>
                  </div>
                  <div style={{ display: 'flex', height: 5 }}>
                    {['ok', 'warn', 'danger', 'none', 'na'].map(k => st[k] ? <span key={k} style={{ flex: st[k], background: { ok: 'var(--ok)', warn: 'var(--warn)', danger: 'var(--danger)', none: 'var(--none)', na: 'var(--ink-4)' }[k] }} /> : null)}
                  </div>
                  <div style={{ display: 'flex', gap: 12, padding: '9px 16px', fontSize: 11, color: 'var(--ink-3)', flexWrap: 'wrap', borderTop: '1px solid var(--line-soft)' }}>
                    {st.danger > 0 && <span style={{ color: 'var(--danger-ink)', fontWeight: 600 }}>เกิน {st.danger}</span>}
                    {st.warn > 0 && <span style={{ color: 'var(--warn-ink)', fontWeight: 600 }}>ใกล้ครบ {st.warn}</span>}
                    <span style={{ color: 'var(--ok-ink)' }}>ปกติ {st.ok}</span>
                    {st.na > 0 && <span style={{ color: 'var(--ink-4)' }}>ไม่ต้องสอบเทียบ/PM {st.na}</span>}
                    {st.decomm > 0 && <span style={{ color: 'var(--ink-4)' }}>ปลดระวาง {st.decomm}</span>}
                  </div>
                </button>
              );
            })}
          </div>
          <div style={{ textAlign: 'center' }}>
            <button className="btn" onClick={() => setViewAll(true)}><I.list size={16} /> ดูทั้งหมด (รวมทุกหน่วยงาน {instruments.length - decommCount} เครื่อง)</button>
          </div>
        </div>
      ) : (
       <>
      {/* filters — rounded label cards in a horizontal row (each holds a dropdown) */}
      <div className="inv-filters" style={{ display: 'flex', gap: 10, alignItems: 'center', flexWrap: 'wrap' }}>
        <button className="btn btn-sm btn-ghost" onClick={backToLanding} title="กลับไปหน้าหน่วยงาน"><I.arrowL size={14} /> หน่วยงานทั้งหมด</button>

        <label className="filter-card">
          <span className="fc-label"><I.building size={12} /> แผนก</span>
          <select className="fc-select" value={dept} onChange={e => setDept(e.target.value)}>
            <option value="all">ทุกแผนก ({instruments.length})</option>
            {depts.map(d => <option key={d} value={d}>{(DEPT_META[d] || {}).short || d} ({deptCounts[d] || 0})</option>)}
          </select>
        </label>

        <label className="filter-card">
          <span className="fc-label"><I.shield size={12} /> สถานะ</span>
          <select className="fc-select" value={stat} onChange={e => setStat(e.target.value)}>
            <option value="all">ทั้งหมด ({statCounts.all})</option>
            <option value="ok">ปกติ ({statCounts.ok})</option>
            <option value="warn">ใกล้ครบกำหนด ({statCounts.warn})</option>
            <option value="danger">เกินกำหนด ({statCounts.danger})</option>
            <option value="none">ไม่มีข้อมูล ({statCounts.none})</option>
            <option value="na">ไม่ต้องสอบเทียบ/PM ({statCounts.na})</option>
          </select>
        </label>

        <label className="filter-card">
          <span className="fc-label"><I.refresh size={12} /> การใช้งาน</span>
          <select className="fc-select" value={lifeView} onChange={e => setLifeView(e.target.value)}>
            <option value="active">ใช้งานอยู่ ({instruments.length - decommCount})</option>
            <option value="decommissioned">ปลดระวาง ({decommCount})</option>
            <option value="all">ทั้งหมด ({instruments.length})</option>
          </select>
        </label>

        <label className="filter-card">
          <span className="fc-label"><I.list size={12} /> ชนิดเครื่อง</span>
          <select className="fc-select" value={typeAbbr} onChange={e => setTypeAbbr(e.target.value)}>
            <option value="all">ทุกชนิด ({instruments.length})</option>
            {typeList.map(t => <option key={t.abbr} value={t.abbr}>{t.abbr} · {t.name} ({t.n})</option>)}
          </select>
        </label>

        {(dept !== 'all' || stat !== 'all' || typeAbbr !== 'all' || lifeView !== 'active' || q) && (
          <button className="btn btn-sm btn-ghost" onClick={() => { setDept('all'); setStat('all'); setTypeAbbr('all'); setLifeView('active'); setQ(''); }} title="ล้างตัวกรองทั้งหมด">
            <I.close size={14} /> ล้างตัวกรอง
          </button>
        )}
      </div>

      <div style={{ fontSize: 13, color: 'var(--ink-3)' }}>พบ <b className="tnum" style={{ color: 'var(--ink)' }}>{filtered.length}</b> รายการ{dept !== 'all' ? ` ในแผนก ${(DEPT_META[dept] || {}).short || dept}` : ''}</div>

      {/* table / grid */}
      {filtered.length === 0 ? (
        <div className="card"><EmptyState icon={I.search} title="ไม่พบเครื่องมือที่ตรงกับเงื่อนไข" sub="ลองปรับคำค้นหรือฟิลเตอร์" /></div>
      ) : view === 'grid' ? (
        <div style={{ display: 'grid', gridTemplateColumns: monitor ? 'repeat(auto-fill, minmax(196px, 1fr))' : 'repeat(auto-fill, minmax(240px, 1fr))', gap: monitor ? 12 : 16 }}>
          {filtered.map(i => <InstrumentCard key={i.code} inst={i} onClick={() => go('detail', { code: i.code })} />)}
        </div>
      ) : (
        <div className="card tbl-wrap enter">
          <table className="tbl">
            <thead>
              <tr>
                <th style={{ width: 38, cursor: 'default' }}><input type="checkbox" className="sel-check" checked={allSel} onChange={toggleAll} title="เลือกทั้งหมด" onClick={e => e.stopPropagation()} /></th>
                {sortHead('code', 'รหัสเครื่องมือ', { width: 150 })}
                {sortHead('type', 'ชนิด / ยี่ห้อ-รุ่น')}
                {sortHead('dept', 'แผนก', { width: 150 })}
                <th style={{ width: 120 }}>Serial No.</th>
                {sortHead('exp', 'ครบกำหนดถัดไป', { width: 130 })}
                {sortHead('status', 'สถานะ', { width: 150 })}
              </tr>
            </thead>
            <tbody>
              {filtered.map(i => {
                const s = statusOf(i);
                const decomm = isDecommissioned(i);
                return (
                  <tr key={i.code} {...pressable(() => go('detail', { code: i.code }), { asRow: true })} style={{ opacity: decomm ? 0.6 : 1 }}>
                    <td style={{ padding: pad }} onClick={e => e.stopPropagation()}><input type="checkbox" className="sel-check" checked={selected.has(i.code)} onChange={() => toggleSel(i.code)} /></td>
                    <td style={{ padding: pad }}><span className="code" style={{ fontWeight: 600 }}>{i.code}</span></td>
                    <td style={{ padding: pad }}>
                      <div style={{ fontWeight: 600, fontSize: rowFont }}>{i.type}</div>
                      {!monitor && <div style={{ fontSize: 12, color: 'var(--ink-3)' }}>{i.brand}{i.model && i.model !== '-' ? ` · ${i.model}` : ''}</div>}
                    </td>
                    <td style={{ padding: pad }}><DeptBadge dept={i.dept} /></td>
                    <td style={{ padding: pad }}><span className="code" style={{ fontSize: 12.5, color: i.serial && i.serial !== '-' ? 'var(--ink-2)' : 'var(--ink-4)' }}>{i.serial && i.serial !== '-' ? i.serial : '—'}</span></td>
                    <td style={{ padding: pad }} className="tnum">
                      {s.kind === 'pm'
                        ? <><span style={{ fontSize: 13 }}>{fmtDate(i.pmNext) || '—'}</span><span style={{ fontSize: 'var(--fs-xs)', color: 'var(--ink-3)', marginLeft: 5 }}>PM</span></>
                        : <span style={{ fontSize: 13 }}>{fmtDate(i.exp) || '—'}</span>}
                    </td>
                    <td style={{ padding: pad }}><div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>{decomm ? <span className="pill none" style={{ fontSize: 11 }}><span className="dot" /> ปลดระวาง</span> : <Pill status={s} showDays />}{admin && <button className="btn-icon btn-ghost" title="ลบเครื่องมือ" style={{ color: 'var(--danger-ink)' }} onClick={(e) => { e.stopPropagation(); onDelete && onDelete(i.code); }}><I.trash size={15} /></button>}</div></td>
                  </tr>
                );
              })}
            </tbody>
          </table>
        </div>
      )}
       </>
      )}
      {labelItems && <LabelModal items={labelItems} onClose={() => setLabelItems(null)} />}
    </div>
  );
}
window.Inventory = Inventory;
