// data-profile-list / data-self-profile-action / data-profile-action обрабатывают profile-view.js и user-profile-view.js. import { iconHtml } from './ui-icon.js'; export function escapeProfileHtml(text) { return String(text || '') .replaceAll('&', '&') .replaceAll('<', '<') .replaceAll('>', '>') .replaceAll('"', '"') .replaceAll("'", '''); } const esc = escapeProfileHtml; function statusChip({ kind, label, value, active }) { const n = Number(value || 0); return ` `; } function statHtml({ kind, label, valueHtml, ariaLabel }) { return ` `; } function contactRows(card) { return [ ['Ссылки', card?.web], ['Телефон', card?.phone], ['Адрес', card?.address], ] .filter(([, value]) => String(value || '').trim()) .map(([label, value]) => `
${esc(label)} ${esc(value)}
`) .join(''); } /** * @param {object} opts * @param {object} opts.card карточка профиля (loadUserProfileCard) * @param {string} opts.login логин на случай, если в карточке его нет * @param {string} opts.tilesHtml плитки действий (свои/чужие) * @param {string} [opts.tilesWrapClass] доп. класс обёртки плиток (для меню «Добавить») * @param {string} [opts.beforeTilesHtml] разметка внутри обёртки перед плитками */ export function profileCardHtml({ card, login = '', tilesHtml = '', tilesWrapClass = '', beforeTilesHtml = '', isSelf = true }) { const stats = card?.stats || {}; const official = card?.accountRole === 'primary'; const shining = card?.shineStatus === 'shining'; const cardLogin = card?.login || login; const fullName = [card?.firstName, card?.lastName].map((v) => String(v || '').trim()).filter(Boolean).join(' '); const displayName = fullName || cardLogin || 'Профиль'; const about = String(card?.about || '').trim(); const spiritualPath = String(card?.spiritualPath || '').trim(); const contacts = contactRows(card); const aboutRow = (about || isSelf) ? `
О себе

${esc(about || 'Не заполнено')}

` : ''; const pathRow = spiritualPath ? `
Духовный путь

${esc(spiritualPath)}

` : ''; const listInner = aboutRow + contacts + pathRow; const listHtml = listInner.trim() ? `
${listInner}
` : ''; const friends = Number(stats.friendsCount || 0); const statusChips = [ (official || Number(stats.primaryReceivedCount || 0) > 0) && statusChip({ kind: 'primary_received', label: 'Официальный', value: stats.primaryReceivedCount, active: official }), (shining || Number(stats.shineReceivedCount || 0) > 0) && statusChip({ kind: 'shine_received', label: 'Сияющий', value: stats.shineReceivedCount, active: shining }), ].filter(Boolean); const statusesHtml = statusChips.length ? `
${statusChips.join('')}
` : ''; const closeFriends = Number(stats.closeFriendsCount || 0); return `

${esc(displayName)}

@${esc(cardLogin)}
${statusesHtml}
${statHtml({ kind: 'friends', label: 'Друзья', valueHtml: closeFriends ? `${friends} · ${closeFriends} близк.` : String(friends), ariaLabel: `Друзья: ${friends}, близкие: ${closeFriends}` })} ${statHtml({ kind: 'channels_owned', label: 'Каналы', valueHtml: String(Number(stats.ownedPublicChannelsCount || 0)), ariaLabel: `Каналы: ${Number(stats.ownedPublicChannelsCount || 0)}` })} ${statHtml({ kind: 'channels_following', label: 'Подписки', valueHtml: String(Number(stats.followingChannelsCount || 0)), ariaLabel: `Подписки: ${Number(stats.followingChannelsCount || 0)}` })}
${tilesHtml ? `
${beforeTilesHtml}
${tilesHtml}
` : ''} ${listHtml}`; } export function profileTileHtml({ icon, label, attrs = '', iconMarkup = '' }) { return ``; }