import { renderHeader } from '../components/header.js'; import { SHINE_CONNECTIONS_LOGO_SRC } from '../components/shine-logo.js'; import { renderUserAvatar } from '../components/avatar-image.js'; import { state } from '../state.js'; import { loadUserProfileCard } from '../services/user-connections.js'; import { makeProfileLinksRoute } from '../services/shine-routes.js'; import { navigateBack } from '../router.js'; export const pageMeta = { id: 'user', title: 'Профиль' }; function escapeHtml(text) { return String(text || '') .replaceAll('&', '&') .replaceAll('<', '<') .replaceAll('>', '>') .replaceAll('"', '"') .replaceAll("'", '''); } function metricHtml({ kind, label, value, glow = false, positionClass = '' }) { const numericValue = Number(value || 0); return ` `; } function openProfileSheet(title, html) { const root = document.getElementById('modal-root'); if (!root) return; root.innerHTML = `
`; const close = () => { if (root.querySelector('#user-profile-sheet-backdrop')) root.innerHTML = ''; }; root.querySelector('#user-profile-sheet-backdrop')?.addEventListener('click', (event) => { if (event.target?.id === 'user-profile-sheet-backdrop') close(); }); } function spiritualPathSheetHtml(card) { return ``; } function contactsSheetHtml(card) { const rows = [ ['Ссылки', card?.web], ['Телефон', card?.phone], ['Адрес', card?.address], ].filter(([, value]) => String(value || '').trim()); if (!rows.length) { return ''; } return rows.map(([label, value]) => ` `).join(''); } function addIconHtml() { return ` `; } export function render({ navigate, route, chrome }) { const requestedLogin = String(route?.params?.login || '').trim(); const selfLogin = String(state.session.login || '').trim(); const screen = document.createElement('section'); screen.className = 'stack user-profile-screen'; const header = renderHeader({ title: requestedLogin || 'Профиль', leftAction: { label: '←', onClick: () => navigateBack() }, }); header.classList.add('user-profile-header'); chrome?.setTopbar(header); const status = document.createElement('div'); status.className = 'status-line user-profile-status'; status.textContent = 'Загрузка профиля...'; const body = document.createElement('div'); body.className = 'user-profile-body'; screen.append(status, body); let card = null; function renderProfile() { if (!card) return; const isSelf = card.login.toLowerCase() === selfLogin.toLowerCase(); const stats = card.stats || {}; const official = card.accountRole === 'primary'; const shining = card.shineStatus === 'shining'; const fullName = [card.firstName, card.lastName] .map((value) => String(value || '').trim()) .filter(Boolean) .join(' '); const about = String(card.about || '').trim(); const title = header.querySelector('.page-title'); if (title) title.textContent = card.login; body.innerHTML = ` ${fullName ? `` : ''} ${about ? `` : ''} ${!isSelf ? ` ` : ''} `; const avatarSlot = body.querySelector('.user-profile-avatar-slot'); avatarSlot?.append(renderUserAvatar({ login: card.login, firstName: card.firstName, lastName: card.lastName, avatar: card.avatar, size: 'xl', className: 'user-profile-hero-avatar', glow: shining, })); status.textContent = ''; } body.addEventListener('click', async (event) => { if (!card) return; const listButton = event.target.closest('[data-profile-list]'); if (listButton) { const kind = listButton.dataset.profileList; if (kind) navigate(`SHiNE/${encodeURIComponent(card.login)}/list/${encodeURIComponent(kind)}`); return; } const detailButton = event.target.closest('[data-profile-detail]'); if (detailButton?.dataset.profileDetail === 'spiritual-path') { openProfileSheet('Духовный путь', spiritualPathSheetHtml(card)); return; } if (detailButton?.dataset.profileDetail === 'contacts') { openProfileSheet('Контакты', contactsSheetHtml(card)); return; } const actionButton = event.target.closest('[data-profile-action]'); const action = actionButton?.dataset.profileAction; if (action === 'add') { if (!selfLogin) { status.className = 'status-line user-profile-status is-unavailable'; status.textContent = 'Для добавления пользователя необходимо войти.'; return; } navigate(`SHiNE/${encodeURIComponent(card.login)}/manage`); return; } if (action === 'links') { navigate(makeProfileLinksRoute(card.login)); return; } if (action === 'chat') { navigate(`chat/${encodeURIComponent(card.login)}`); } }); async function refresh() { card = await loadUserProfileCard(requestedLogin); renderProfile(); } refresh().catch((error) => { status.className = 'status-line user-profile-status is-unavailable'; status.textContent = `Ошибка: ${error?.message || 'unknown'}`; }); screen.cleanup = () => { const root = document.getElementById('modal-root'); if (root?.querySelector('#user-profile-sheet-backdrop')) root.innerHTML = ''; }; return screen; }