{#
Unit Search Results Partial
Rendered by /api/roster/search/units endpoint for HTMX dropdown.

Variables:
- units: List of unit dicts with id, device_type, note, deployed, display
- query: The search query string
- show_empty: Boolean - show "no results" message
#}

{% set picker_id = request.query_params.get('picker_id', '') %}

{% if units %}
    {% for unit in units %}
    <div class="px-4 py-3 hover:bg-gray-100 dark:hover:bg-gray-700 cursor-pointer border-b border-gray-100 dark:border-gray-700 last:border-0 transition-colors"
         onclick="selectUnit('{{ unit.id }}', '{{ unit.display|e }}', '{{ picker_id }}')">
        <div class="flex items-start justify-between gap-2">
            <div class="flex-1 min-w-0">
                <div class="font-medium text-gray-900 dark:text-white truncate">
                    <span class="text-seismo-orange font-semibold">{{ unit.id }}</span>
                </div>
                {% if unit.note %}
                    <div class="text-sm text-gray-500 dark:text-gray-400 truncate">
                        {{ unit.note }}
                    </div>
                {% endif %}
            </div>
            <div class="flex items-center gap-2">
                {% if unit.device_type == 'seismograph' %}
                    <span class="flex-shrink-0 text-xs px-2 py-0.5 bg-blue-100 dark:bg-blue-900/30 text-blue-600 dark:text-blue-300 rounded">
                        Seismo
                    </span>
                {% elif unit.device_type == 'slm' %}
                    <span class="flex-shrink-0 text-xs px-2 py-0.5 bg-purple-100 dark:bg-purple-900/30 text-purple-600 dark:text-purple-300 rounded">
                        SLM
                    </span>
                {% endif %}
                {% if not unit.deployed %}
                    <span class="flex-shrink-0 text-xs px-2 py-0.5 bg-gray-100 dark:bg-gray-600 text-gray-600 dark:text-gray-300 rounded">
                        Benched
                    </span>
                {% endif %}
            </div>
        </div>
    </div>
    {% endfor %}
{% endif %}

{% if show_empty %}
    <div class="px-4 py-6 text-center text-gray-500 dark:text-gray-400">
        <svg class="w-8 h-8 mx-auto mb-2 text-gray-300 dark:text-gray-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"></path>
        </svg>
        <p class="text-sm">No units found matching "{{ query }}"</p>
    </div>
{% endif %}

{% if not units and not show_empty %}
    <div class="px-4 py-6 text-center text-gray-500 dark:text-gray-400">
        <svg class="w-8 h-8 mx-auto mb-2 text-gray-300 dark:text-gray-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"></path>
        </svg>
        <p class="text-sm">Start typing to search units...</p>
        <p class="text-xs mt-1">Search by unit ID or note</p>
    </div>
{% endif %}
