// 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 statusSectionHtml({ kind, title, received, given, receivedLabel, givenLabel }) { const receivedCount = Number(received || 0); const givenCount = Number(given || 0); const isOfficial = kind === 'primary'; return `
`; } function peopleCount(count) { if (!count) return 'Пока никого'; const mod10 = count % 10; const mod100 = count % 100; const word = mod10 === 1 && mod100 !== 11 ? 'человек' : (mod10 >= 2 && mod10 <= 4 && (mod100 < 12 || mod100 > 14)) ? 'человека' : 'человек'; return `${count} ${word}`; } 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 closeFriends = Number(stats.closeFriendsCount || 0); const shineReceived = Number(stats.shineReceivedCount || 0); const shineGiven = Number(stats.shineGivenCount || 0); const primaryReceived = Number(stats.primaryReceivedCount || 0); const primaryGiven = Number(stats.primaryGivenCount || 0); // Раздел виден у сияющих и у всех, кого уже подтверждали или кто подтверждал сам. const shineSection = (shining || shineReceived || shineGiven) ? statusSectionHtml({ kind: 'shine', title: 'Сияние', received: shineReceived, given: shineGiven, receivedLabel: 'Подтвердили, что сияющий', givenLabel: 'Подтвердил сияющими', }) : ''; const officialSection = (official || primaryReceived || primaryGiven) ? statusSectionHtml({ kind: 'primary', title: 'Официальный аккаунт', received: primaryReceived, given: primaryGiven, receivedLabel: 'Подтвердили, что официальный', givenLabel: 'Подтвердил официальными', }) : ''; const badges = [ shining ? 'Сияющий' : '', official ? 'Официальный' : '', ].join(''); return `

${esc(displayName)}

@${esc(cardLogin)}
${badges ? `
${badges}
` : ''}
${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}
` : ''} ${shineSection} ${officialSection} ${listHtml}`; } export function profileTileHtml({ icon, label, attrs = '', iconMarkup = '' }) { return ``; }