import { t, th } from '../i18n/index.js'; // data-profile-list / data-self-profile-action / data-profile-action обрабатывают profile-view.js и user-profile-view.js. import { iconHtml } from './ui-icon.js'; import { displayCity } from '../services/cities.js'; export function escapeProfileHtml(text) { return String(text || '') .replaceAll('&', '&') .replaceAll('<', '<') .replaceAll('>', '>') .replaceAll('"', '"') .replaceAll("'", '''); } const esc = escapeProfileHtml; // Карточка статуса у аватара: кто подтвердил этот аккаунт и кого подтвердил он сам. function statusSideHtml({ kind, title, active, received, given, verb }) { const isOfficial = kind === 'primary'; const receivedKind = isOfficial ? 'primary_received' : 'shine_received'; const givenKind = isOfficial ? 'primary_given' : 'shine_given'; return `
${esc(title)}
`; } function statHtml({ kind, label, valueHtml, ariaLabel }) { return ` `; } function contactRows(card) { return [ [t('screens.profile_card.text_006'), card?.web], [t('screens.profile_card.text_007'), card?.phone], [t('screens.profile_card.text_008'), 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 = String(card?.login || login || '').trim().replace(/^@+/, ''); const city = displayCity(card?.city); const fullName = [card?.firstName, card?.lastName].map((v) => String(v || '').trim()).filter(Boolean).join(' '); const displayName = fullName || cardLogin || t('screens.profile_card.text_012'); const about = String(card?.about || '').trim(); const spiritualPath = String(card?.spiritualPath || '').trim(); const contacts = contactRows(card); const aboutRow = (about || isSelf) ? `
${th('screens.profile_card.text_018')}

${esc(about || t('screens.profile_card.text_013'))}

` : ''; const pathRow = spiritualPath ? `
${th('screens.profile_card.text_019')}

${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 verb = card?.gender === 'female' ? t('screens.profile_card.text_009') : card?.gender === 'male' ? t('screens.profile_card.text_010') : t('screens.profile_card.text_011'); const officialSide = (isSelf || official || primaryReceived || primaryGiven) ? statusSideHtml({ kind: 'primary', title: t('screens.profile_card.text_001'), active: official, received: primaryReceived, given: primaryGiven, verb }) : ''; const shineSide = (isSelf || shining || shineReceived || shineGiven) ? statusSideHtml({ kind: 'shine', title: t('screens.profile_card.text_002'), active: shining, received: shineReceived, given: shineGiven, verb }) : ''; return `
${officialSide}
${shineSide}

${esc(displayName)}

${esc(cardLogin)}
${city ? `
${iconHtml('place')}${esc(city)}
` : ''}
${statHtml({ kind: 'friends', label: t('screens.profile_card.text_003'), valueHtml: closeFriends ? `${friends} · ${closeFriends}${th('remaining.html_profile_card.close')}` : String(friends), ariaLabel: t('screens.profile_card.text_014', { value1: friends, value2: closeFriends }) })} ${statHtml({ kind: 'channels_owned', label: t('screens.profile_card.text_004'), valueHtml: String(Number(stats.ownedPublicChannelsCount || 0)), ariaLabel: t('screens.profile_card.text_015', { value1: Number(stats.ownedPublicChannelsCount || 0) }) })} ${statHtml({ kind: 'channels_following', label: t('screens.profile_card.text_005'), valueHtml: String(Number(stats.followingChannelsCount || 0)), ariaLabel: t('screens.profile_card.text_016', { value1: Number(stats.followingChannelsCount || 0) }) })}
${tilesHtml ? `
${beforeTilesHtml}
${tilesHtml}
` : ''} ${listHtml}`; } export function profileTileHtml({ icon, label, attrs = '', iconMarkup = '' }) { return ``; }