function el(tag, props, children) { const node = document.createElement(tag); if (props) { Object.keys(props).forEach((key) => { const value = props[key]; if (value === undefined || value === null) { return; } if (key === 'class') { node.className = value; } else if (key === 'text') { node.textContent = value; } else if (key === 'style') { node.style.cssText = value; } else if (key.startsWith('on') && typeof value === 'function') { node.addEventListener(key.slice(2), value); } else if (key in node && typeof value !== 'string') { node[key] = value; } else { node.setAttribute(key, value); } }); } (children || []).forEach((child) => { if (child === null || child === undefined || child === false) { return; } node.appendChild(typeof child === 'string' ? document.createTextNode(child) : child); }); return node; } function $(selector) { return document.querySelector(selector); } function setHidden(node, hidden) { node.classList.toggle('hidden', hidden); } function toast(message, kind) { const node = el('div', { class: 'toast ' + (kind || 'info'), text: message }); $('#toasts').appendChild(node); setTimeout(() => node.remove(), 3500); } function setStatus(node, message, kind) { node.textContent = message || ''; node.className = 'status' + (kind ? ' ' + kind : ''); } function openDialog(title, options) { const opts = options || {}; const layer = $('#dialog-layer'); const backdrop = el('div', { class: 'dialog-backdrop' }); const body = el('div', { class: 'dialog-body' }); const close = () => { backdrop.remove(); if (opts.onClose) { opts.onClose(); } }; const dialog = el('div', { class: 'dialog' + (opts.wide ? ' wide' : '') }, [ el('div', { class: 'dialog-head' }, [ el('h3', { text: title }), el('button', { type: 'button', class: 'btn', text: '×', onclick: close }) ]), body ]); backdrop.appendChild(dialog); backdrop.addEventListener('mousedown', (event) => { if (event.target === backdrop) { close(); } }); layer.appendChild(backdrop); return { body, close, root: backdrop }; } function formatCzk(value) { return new Intl.NumberFormat('cs-CZ', { style: 'currency', currency: 'CZK', maximumFractionDigits: 0, minimumFractionDigits: 0 }).format(value); } function primaryImageUrl(images) { if (!Array.isArray(images) || images.length === 0) { return null; } const primary = images.find((image) => image && image.isPrimary) || images[0]; return primary ? primary.url : null; } function safeHttpUrl(url) { return typeof url === 'string' && /^https?:\/\//i.test(url.trim()) ? url.trim() : null; } function isTypingTarget(node) { if (!node) { return false; } const tag = node.tagName; return tag === 'INPUT' || tag === 'TEXTAREA' || tag === 'SELECT' || node.isContentEditable; } function debounce(fn, delay) { let timer = null; return function () { const args = arguments; clearTimeout(timer); timer = setTimeout(() => fn.apply(null, args), delay); }; } function showAlert(message) { console.log('showAlert', message); toast(message, 'warn'); } function closeAlert() { }