window.CompanyContacts = (() => {
const esc = value => String(value ?? "").replace(/[&<>"']/g, c => ({"&":"&","<":"<",">":">",'"':""","'":"'"}[c]));
function rows(contacts, helpers) {
return contacts.map(contact => {
const displayName = helpers.name(contact);
const contactId = Number(contact.id) || null;
const mobileValue = helpers.mobile(contact);
const phoneValue = helpers.phone(contact);
const titleValue = String(contact.title || contact.role || '').trim();
const nameCell = contactId
? `${esc(displayName)}`
: esc(displayName);
const email = contact.email ? `${esc(contact.email)}` : '—';
const phone = phoneValue
? `
`
: '—';
const mobile = mobileValue
? ``
: '—';
const title = titleValue ? esc(titleValue) : '—';
const primaryBadge = contact.is_primary ? 'Primær' : '—';
return `
| ${nameCell} |
${title} |
${email} |
${phone} |
${mobile} |
${primaryBadge} | ${helpers.extra ? `${helpers.extra(contact)} | ` : ''}
`;
}).join('');
}
function filter(contacts, query, onlyCallable, helpers) {
const term=String(query || '').trim().toLowerCase();
return contacts.filter(contact=>{
const phone=helpers.phone(contact), mobile=helpers.mobile(contact);
const text=[helpers.name(contact),contact.title,contact.role,contact.email,phone,mobile].join(' ').toLowerCase();
return (!term || text.includes(term)) && (!onlyCallable || Boolean(phone || mobile));
});
}
function table(body) {
return ``;
}
return {rows, filter, table};
})();