<div class="bg-white dark:bg-slate-800 rounded-xl shadow-lg p-6">
    <!-- Status Bar -->
    <div class="mb-6 p-4 rounded-lg {% if is_measuring %}bg-green-50 dark:bg-green-900/20{% else %}bg-gray-50 dark:bg-gray-900{% endif %}">
        <div class="flex justify-between items-center">
            <div>
                <div class="text-sm text-gray-600 dark:text-gray-400">Measurement Status</div>
                <div class="text-2xl font-bold {% if is_measuring %}text-green-600 dark:text-green-400{% else %}text-gray-600 dark:text-gray-400{% endif %}">
                    {% if measurement_state %}
                        {{ measurement_state }}
                        {% if is_measuring %}
                        <span class="inline-block w-3 h-3 bg-green-500 rounded-full ml-2 animate-pulse"></span>
                        {% endif %}
                    {% else %}
                        Unknown
                    {% endif %}
                </div>
            </div>
            <div>
                <div class="text-sm text-gray-600 dark:text-gray-400">Battery</div>
                <div class="text-2xl font-bold text-gray-900 dark:text-white">
                    {{ battery_level or '--' }}
                </div>
            </div>
        </div>
    </div>

    <!-- Control Buttons -->
    <div class="grid grid-cols-2 md:grid-cols-4 gap-3">
        <button hx-post="/api/slmm/{{ unit_id }}/start"
                hx-swap="none"
                hx-on::after-request="htmx.trigger('#slm-controls', 'refresh')"
                class="px-4 py-3 bg-green-600 text-white rounded-lg hover:bg-green-700 transition-colors flex items-center justify-center gap-2
                       {% if is_measuring %}opacity-50 cursor-not-allowed{% endif %}"
                {% if is_measuring %}disabled{% endif %}>
            <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14.752 11.168l-3.197-2.132A1 1 0 0010 9.87v4.263a1 1 0 001.555.832l3.197-2.132a1 1 0 000-1.664z"></path>
                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
            </svg>
            Start
        </button>

        <button hx-post="/api/slmm/{{ unit_id }}/stop"
                hx-swap="none"
                hx-on::after-request="htmx.trigger('#slm-controls', 'refresh')"
                class="px-4 py-3 bg-red-600 text-white rounded-lg hover:bg-red-700 transition-colors flex items-center justify-center gap-2
                       {% if not is_measuring %}opacity-50 cursor-not-allowed{% endif %}"
                {% if not is_measuring %}disabled{% endif %}>
            <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 10a1 1 0 011-1h4a1 1 0 011 1v4a1 1 0 01-1 1h-4a1 1 0 01-1-1v-4z"></path>
            </svg>
            Stop
        </button>

        <button hx-post="/api/slmm/{{ unit_id }}/pause"
                hx-swap="none"
                hx-on::after-request="htmx.trigger('#slm-controls', 'refresh')"
                class="px-4 py-3 bg-yellow-600 text-white rounded-lg hover:bg-yellow-700 transition-colors flex items-center justify-center gap-2">
            <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 9v6m4-6v6m7-3a9 9 0 11-18 0 9 9 0 0118 0z"></path>
            </svg>
            Pause
        </button>

        <button hx-post="/api/slmm/{{ unit_id }}/reset"
                hx-swap="none"
                hx-confirm="Are you sure you want to reset the measurement data?"
                hx-on::after-request="htmx.trigger('#slm-controls', 'refresh')"
                class="px-4 py-3 bg-gray-600 text-white rounded-lg hover:bg-gray-700 transition-colors flex items-center justify-center gap-2">
            <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"></path>
            </svg>
            Reset
        </button>
    </div>

    <!-- Quick Actions -->
    <div class="mt-4 pt-4 border-t border-gray-200 dark:border-gray-700">
        <div class="grid grid-cols-2 gap-3">
            <button hx-get="/api/slmm/{{ unit_id }}/live"
                    hx-swap="none"
                    hx-indicator="#live-spinner"
                    class="px-4 py-2 bg-blue-600 text-white text-sm rounded-lg hover:bg-blue-700 transition-colors flex items-center justify-center gap-2">
                <svg id="live-spinner" class="htmx-indicator w-4 h-4 animate-spin" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"></path>
                </svg>
                <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z"></path>
                </svg>
                Get Live Data
            </button>

            <button hx-post="/api/slmm/{{ unit_id }}/store"
                    hx-swap="none"
                    class="px-4 py-2 bg-purple-600 text-white text-sm rounded-lg hover:bg-purple-700 transition-colors flex items-center justify-center gap-2">
                <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7H5a2 2 0 00-2 2v9a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-3m-1 4l-3 3m0 0l-3-3m3 3V4"></path>
                </svg>
                Store Data
            </button>
        </div>
    </div>
</div>

<div id="slm-controls" hx-get="/slm/partials/{{ unit_id }}/controls" hx-trigger="refresh" hx-swap="outerHTML"></div>
