// Shared LOT price-quality color scale, used everywhere price_quality is
// displayed (pricelist detail page, configurator search dropdown, configurator
// table, pricing tab). price_quality is a 0-9 score set by the external
// pricing tool (see bible-local/03-database.md, qt_pricelist_items.price_quality)
// — QF only displays it, never computes it. Single source of the color scale
// so every view stays visually consistent.
//
// Gradient: 0 = red, 5 = yellow, 9 = green.
(function () {
const RED = [220, 38, 38];
const YELLOW = [234, 179, 8];
const GREEN = [22, 163, 74];
function lerp(c1, c2, t) {
return c1.map((v, i) => Math.round(v + (c2[i] - v) * t));
}
// Returns "r, g, b" (no rgb() wrapper) so callers can build rgb()/rgba() themselves.
function priceQualityRgb(quality) {
if (typeof quality !== 'number' || Number.isNaN(quality)) return null;
const q = Math.max(0, Math.min(9, quality));
const [r, g, b] = q <= 5 ? lerp(RED, YELLOW, q / 5) : lerp(YELLOW, GREEN, (q - 5) / 4);
return `${r}, ${g}, ${b}`;
}
function priceQualityColor(quality) {
const rgb = priceQualityRgb(quality);
return rgb ? `rgb(${rgb})` : null;
}
// Small colored dot for compact contexts (search dropdown, configurator table cell).
function qualityDotHtml(quality) {
const color = priceQualityColor(quality);
if (!color) return '';
return ``;
}
// Colored number badge for a dedicated "quality" column/cell.
function qualityBadgeHtml(quality) {
if (typeof quality !== 'number') return '-';
const color = priceQualityColor(quality);
return `${quality}`;
}
// Light row-tint background for table rows, e.g. the pricing tab.
function qualityRowStyle(quality) {
const rgb = priceQualityRgb(quality);
return rgb ? `background-color: rgba(${rgb}, 0.10)` : '';
}
window.priceQualityColor = priceQualityColor;
window.qualityDotHtml = qualityDotHtml;
window.qualityBadgeHtml = qualityBadgeHtml;
window.qualityRowStyle = qualityRowStyle;
})();