@props([
'device',
'phone' => null,
'name' => null,
'contact' => null,
'contactIndex' => [],
/** auto|contact: nombre si existe, si no teléfono; name: solo nombre; phone: solo número */
'labelMode' => 'auto',
])
@php
use App\Support\PhoneNormalizer;
$resolvedContact = $contact;
if (! $resolvedContact && $phone && is_array($contactIndex)) {
foreach (PhoneNormalizer::variants($phone) as $variant) {
if (isset($contactIndex[$variant])) {
$resolvedContact = $contactIndex[$variant];
break;
}
}
}
$phoneStr = trim((string) ($phone ?? ''));
$nameStr = trim((string) ($name ?? ''));
$indexName = trim((string) ($resolvedContact?->name ?? ''));
$showAsPhone = false;
if ($labelMode === 'phone') {
$label = $phoneStr !== '' ? $phoneStr : __('devices.contacts.no_name');
$showAsPhone = $phoneStr !== '';
} elseif ($labelMode === 'name') {
if ($nameStr !== '' && ($phoneStr === '' || ! PhoneNormalizer::same($nameStr, $phoneStr))) {
$label = $nameStr;
} elseif ($indexName !== '' && ($phoneStr === '' || ! PhoneNormalizer::same($indexName, $phoneStr))) {
$label = $indexName;
} else {
$label = __('devices.contacts.no_name');
}
} elseif ($labelMode === 'contact') {
if ($nameStr !== '' && ($phoneStr === '' || ! PhoneNormalizer::same($nameStr, $phoneStr))) {
$label = $nameStr;
} elseif ($indexName !== '' && ($phoneStr === '' || ! PhoneNormalizer::same($indexName, $phoneStr))) {
$label = $indexName;
} elseif ($phoneStr !== '') {
$label = $phoneStr;
$showAsPhone = true;
} else {
$label = '—';
}
} else {
$label = trim((string) ($nameStr ?: $indexName ?: $phoneStr));
if ($label === '') {
$label = __('devices.contacts.no_name');
}
$showAsPhone = $phoneStr !== '' && PhoneNormalizer::same($label, $phoneStr);
}
$href = \App\Support\ContactResolver::profileUrl($device, $phone, $resolvedContact);
$baseClass = $showAsPhone
? 'font-mono text-xs text-indigo-700 hover:text-indigo-900 hover:underline'
: 'font-medium text-indigo-700 hover:text-indigo-900 hover:underline';
$spanClass = $showAsPhone ? 'font-mono text-xs text-slate-700' : 'text-slate-700';
@endphp
@if($href)
merge(['class' => $baseClass]) }} title="{{ __('devices.contacts.open_profile') }}">
{{ $label }}
@else
merge(['class' => $spanClass]) }}>{{ $label }}
@endif