58 lines
1.8 KiB
JavaScript
58 lines
1.8 KiB
JavaScript
|
|
import { render_slot_items } from '../RsvSlotItems.js';
|
||
|
|
|
||
|
|
export function reservation_summary_renderer(symbols) {
|
||
|
|
const slots = symbols.slots ?? [];
|
||
|
|
const pricing = symbols.pricing ?? {};
|
||
|
|
|
||
|
|
if (!Array.isArray(slots) || slots.length === 0) {
|
||
|
|
return '';
|
||
|
|
}
|
||
|
|
|
||
|
|
const s = ReservairStrings.summary;
|
||
|
|
const locale = navigator.language;
|
||
|
|
const currency = pricing.currency ?? s.currency;
|
||
|
|
|
||
|
|
const items = render_slot_items(slots, locale, currency);
|
||
|
|
const itemsHtml = items.map(li => li.outerHTML).join('');
|
||
|
|
|
||
|
|
const footerRows = [];
|
||
|
|
const subtotal = pricing.subtotal ?? 0;
|
||
|
|
footerRows.push(`
|
||
|
|
<div class="rsv-summary-footer-row rsv-summary-subtotal">
|
||
|
|
<span class="rsv-summary-footer-label">${s.subtotal}</span>
|
||
|
|
<span class="rsv-summary-footer-value">${subtotal} ${currency}</span>
|
||
|
|
</div>
|
||
|
|
`);
|
||
|
|
|
||
|
|
if (pricing.discount && pricing.discount.percent > 0) {
|
||
|
|
const amount = pricing.discount.amount ?? 0;
|
||
|
|
const reason = pricing.discount.reason ?? '';
|
||
|
|
footerRows.push(`
|
||
|
|
<div class="rsv-summary-footer-row rsv-summary-discount">
|
||
|
|
<span class="rsv-summary-footer-label">${s.discount}: ${reason}</span>
|
||
|
|
<span class="rsv-summary-footer-value">-${amount} ${currency}</span>
|
||
|
|
</div>
|
||
|
|
`);
|
||
|
|
}
|
||
|
|
|
||
|
|
const total = pricing.total ?? 0;
|
||
|
|
footerRows.push(`
|
||
|
|
<div class="rsv-summary-footer-row rsv-summary-total">
|
||
|
|
<span class="rsv-summary-footer-label">${s.total}</span>
|
||
|
|
<span class="rsv-summary-footer-value">${total} ${currency}</span>
|
||
|
|
</div>
|
||
|
|
`);
|
||
|
|
|
||
|
|
return `
|
||
|
|
<div class="rsv-summary rsv-summary-snapshot">
|
||
|
|
<div class="rsv-summary-header">
|
||
|
|
<span class="rsv-summary-title">${s.title}</span>
|
||
|
|
</div>
|
||
|
|
<ul class="rsv-summary-list">${itemsHtml}</ul>
|
||
|
|
<div class="rsv-summary-footer rsv-summary-footer--pricing">
|
||
|
|
${footerRows.join('')}
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
`;
|
||
|
|
}
|