mirror of
https://github.com/christianvidalwolf-prog/CrazeAnalytix.git
synced 2026-08-03 13:35:24 +02:00
88 lines
3.3 KiB
TypeScript
88 lines
3.3 KiB
TypeScript
|
|
import React from 'react';
|
|
|
|
interface VendorStockBadgeProps {
|
|
asin: string;
|
|
vendorStockMap?: Map<string, { eu: number; uk: number }>;
|
|
mode: 'eu' | 'uk';
|
|
avgWeeklySales?: number;
|
|
}
|
|
|
|
export const VendorStockBadge: React.FC<VendorStockBadgeProps> = ({ asin, vendorStockMap, mode, avgWeeklySales }) => {
|
|
if (!vendorStockMap || !asin) return null;
|
|
|
|
const stockData = vendorStockMap.get(asin.toUpperCase());
|
|
if (!stockData) return null;
|
|
|
|
const stock = mode === 'uk' ? stockData.uk : stockData.eu;
|
|
|
|
// Calculate Weeks of Coverage (WOC)
|
|
// If sales are 0 but store has stock -> Infinite coverage (>52 weeks) -> Green
|
|
// If sales are 0 and NO stock -> 0 weeks -> Red
|
|
// If sales > 0 -> Calculate stock/sales
|
|
let woc: number = 0;
|
|
const velocity = avgWeeklySales || 0;
|
|
|
|
if (velocity > 0) {
|
|
woc = stock / velocity;
|
|
} else if (stock > 0) {
|
|
woc = 999;
|
|
} else {
|
|
woc = 0;
|
|
}
|
|
|
|
const wocText = woc === 999 ? '> 52 Weeks' : `${woc.toFixed(1)} Weeks Cover`;
|
|
const wocColor = woc < 4 ? 'text-rose-500' : 'text-emerald-500';
|
|
|
|
const themeClasses = "bg-slate-200 text-slate-800 border-slate-300 shadow-sm";
|
|
|
|
return (
|
|
<div className="flex flex-col items-center gap-1 justify-center min-w-[60px]">
|
|
<div
|
|
className={`inline-flex items-center gap-1 px-2 py-0.5 rounded border text-[10px] font-bold transition-all hover:scale-105 active:scale-95 cursor-default ${themeClasses}`}
|
|
title={`Stock en Amazon Warehouse (${mode.toUpperCase()}): ${stock}`}
|
|
>
|
|
<svg
|
|
className="w-3.5 h-3.5"
|
|
viewBox="0 0 24 24"
|
|
fill="none"
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
>
|
|
<path
|
|
d="M17.5 14c.5 0 1 .5 1 1s-.5 1-1 1-1-.5-1-1 .5-1 1-1zm-11 0c.5 0 1 .5 1 1s-.5 1-1 1-1-.5-1-1 .5-1 1-1z"
|
|
fill="currentColor"
|
|
/>
|
|
<path
|
|
d="M3 13.5c0 4.7 3.8 8.5 8.5 8.5s8.5-3.8 8.5-8.5"
|
|
stroke="currentColor"
|
|
strokeWidth="1.5"
|
|
strokeLinecap="round"
|
|
/>
|
|
<path
|
|
d="M17 18.5c-1.5 1.5-3.5 2.5-5.5 2.5s-4-1-5.5-2.5"
|
|
stroke="currentColor"
|
|
strokeWidth="1.5"
|
|
strokeLinecap="round"
|
|
/>
|
|
<path
|
|
d="M19 18.5l1.5 1.5M5 18.5L3.5 20"
|
|
stroke="currentColor"
|
|
strokeWidth="1.5"
|
|
strokeLinecap="round"
|
|
/>
|
|
</svg>
|
|
<div className="flex flex-col leading-[0.8]">
|
|
<span className="text-[7px] font-black uppercase opacity-60">Vendor</span>
|
|
<span>{stock.toLocaleString('de-DE')}</span>
|
|
</div>
|
|
</div>
|
|
<span
|
|
className={`text-[9px] font-black uppercase tracking-tight whitespace-nowrap ${wocColor}`}
|
|
title={`Avg Sales (4wk): ${velocity.toFixed(2)} | Stock: ${stock}`}
|
|
>
|
|
{wocText}
|
|
</span>
|
|
</div>
|
|
);
|
|
};
|