dika/public/base-cards.js
peppa-bot 53fbff9f6e
All checks were successful
peppa/lint lint: success за 0с
peppa/test test: success за 0с
peppa/build build: success за 0с
ci / checks (pull_request) Successful in 10s
deploy / deploy (pull_request) Successful in 28s
DIK-51: карточки на странице «Все заведения», таблица под «Подробная таблица»
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 12:30:01 +00:00

22 lines
1.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Тексты карточки на странице «Все заведения» (DIK-51): общий для браузера и тестов, без DOM.
// Правила те же, что у таблицы /base (DIK-65): старше 14 дней — цена не подтверждена, акции нет.
export const fmt = (s, o) => s.replace(/\{(\w+)\}/g, (_, k) => o[k] ?? ""); // без undefined на экране
export const date = (iso) => (iso ? iso.split("-").reverse().join(".") : "");
export const astanaToday = () => new Date(Date.now() + 5 * 3600000).toISOString().slice(0, 10); // Астана UTC+5
export const isStale = (checked, today) => Boolean(checked) && Math.floor((Date.parse(today) - Date.parse(checked)) / 86400000) > 14;
// → { lunch: {text, active}, promo: {text, active}, checked } — пустых мест нет
export function cardTexts(v, t, today) {
const stale = isStale(v.checked, today);
const lunch = v.lunch && !stale
? { text: fmt(t.lunch, v.lunch), active: true }
: { text: t.notConfirmed, active: false };
const ptext = v.promo && (t.promoTexts?.[v.promo.text] || v.promo.text);
const ended = v.promo && v.promo.until && v.promo.until < today;
const promo = !v.promo || (stale && !ended) ? { text: t.promoNone, active: false }
: ended ? { text: t.promoEnded, active: false }
: { text: fmt(v.promo.until ? t.promo : t.promoOpen, { text: ptext, until: date(v.promo.until) }), active: true };
const checked = v.checked ? fmt(t.checkedOn, { date: date(v.checked) }) : t.cardNotChecked;
return { lunch, promo, checked };
}