// assetCard.js — renders the asset card into #asset-card-container import CONFIG from '../config.js'; import { normalizeUsername, usernameFuzzyMatch, usernameFirstNameMatch, usernameNameInitialMatch } from './usernameUtils.js'; import { getCustomerContactNames } from './assetBrowser.js'; const { subdomain, baseUrl } = CONFIG.syncro; // ── Public ─────────────────────────────────────────────────────────────────── export function renderAssetCard(asset) { const container = document.getElementById('asset-card-container'); container.innerHTML = buildCardHTML(asset); } // ── Helpers ────────────────────────────────────────────────────────────────── function prop(asset, key) { return asset?.properties?.[key] ?? null; } function buildCardHTML(a) { const possessionStatus = prop(a, 'Possession Status'); const lifecycleStage = prop(a, 'Lifecycle Stage'); const lastScanDate = prop(a, 'Last Scan Date'); const lastAction = prop(a, 'Last Action'); const assetHistory = prop(a, 'Asset History'); const infraTag = prop(a, 'Tag'); const infraLocation = prop(a, 'Location'); const isInfra = prop(a, 'Infrastructure') === 'Yes'; const contactName = a.contact_fullname ?? a.contact?.name ?? null; const rawLastUser = a.properties?.kabuto_information?.last_user ?? ''; const lastUser = normalizeUsername(rawLastUser); const allContactNames = getCustomerContactNames(a.customer_id); const sameUser = !!(lastUser && contactName && ( usernameFuzzyMatch(rawLastUser, contactName) || usernameFirstNameMatch(rawLastUser, contactName, allContactNames) || usernameNameInitialMatch(rawLastUser, contactName, allContactNames) )); const contactEmail = a.contact?.email ?? null; const customerName = a.customer?.business_name ?? a.customer?.business_then_name ?? a.customer?.name ?? '—'; const serialNumber = a.asset_serial ?? a.serial ?? a.serial_number ?? '—'; const assetType = a.properties?.form_factor ?? a.properties?.kabuto_information?.general?.form_factor ?? a.asset_type ?? 'Device'; const syncroUrl = `${baseUrl}/customer_assets/${a.id}`; return `