- Inventariegranskning
-
- Vad du har hemma vs. vad veckans recept kräver.
-
- {(() => {
- const missingCount = inventoryCompare.filter((i) => i.status === 'missing').length;
- return missingCount === 0 ? (
-
- ✓ Du har allt hemma!
-
- ) : (
-
- {missingCount} ingrediens{missingCount !== 1 ? 'er' : ''} saknas eller räcker inte
-
+ const order: Record = { missing: 0, partial: 1, enough: 2 };
+ enriched.sort((a, b) => order[a.displayStatus] - order[b.displayStatus] || a.name.localeCompare(b.name, 'sv'));
+
+ const missingCount = enriched.filter((e) => e.displayStatus === 'missing').length;
+ const partialCount = enriched.filter((e) => e.displayStatus === 'partial').length;
+ const enoughCount = enriched.filter((e) => e.displayStatus === 'enough').length;
+ const hasCompare = inventoryCompare.length > 0;
+
+ const fmtQty = (n: number) => (n % 1 === 0 ? String(n) : n.toFixed(1));
+
+ return (
+ <>
+ {/* Sammanfattning */}
+ {hasCompare && (
+
+ {missingCount > 0 && ❌ {missingCount} saknas}
+ {partialCount > 0 && ⚠️ {partialCount} delvis hemma}
+ {enoughCount > 0 && ✅ {enoughCount} hemma}
+ {missingCount === 0 && partialCount === 0 && (
+ ✅ Du har allt hemma!
+ )}
+
+ )}
+
+
+ {enriched.map((item) => {
+ const isMissing = item.displayStatus === 'missing';
+ const isPartial = item.displayStatus === 'partial';
+ const isEnough = item.displayStatus === 'enough';
+ const bg = isMissing ? '#ffeaea' : isPartial ? '#fff8e6' : '#ecf8ee';
+ const icon = isMissing ? '❌' : isPartial ? '⚠️' : '✅';
+
+ return (
+ -
+ {hasCompare && {icon}}
+
+ {item.name}
+ {isPartial && item.cmp && (
+
+ ({fmtQty(item.cmp.available)} av {fmtQty(item.cmp.required)} {item.unit} hemma)
+
+ )}
+ {isEnough && (
+
+ (finns hemma)
+
+ )}
+
+
+ {isEnough
+ ? '—'
+ : `${fmtQty(item.buyQty)} ${item.unit}`}
+
+
+ );
+ })}
+
+ >
);
- })()}
-
- {inventoryCompare.map((item) => (
- -
-
- {item.name}
- {' '}
-
- {item.required % 1 === 0 ? item.required : item.required.toFixed(1)} {item.unit} behövs
- {' · '}
- {item.available % 1 === 0 ? item.available : item.available.toFixed(1)} {item.unit} hemma
-
-
- {item.status === 'missing' && item.missing > 0 && (
-
- Saknar {item.missing % 1 === 0 ? item.missing : item.missing.toFixed(1)} {item.unit}
-
- )}
- {item.status === 'enough' && (
- ✓
- )}
-
- ))}
-
-
- )}
+ })()
+ }
+
>
)}