<!-- MQTT Source Editor Modal -->
<div id="mqtt-source-modal" class="modal" role="dialog" aria-modal="true" aria-labelledby="mqtt-source-modal-title">
    <div class="modal-content">
        <div class="modal-header">
            <h2 id="mqtt-source-modal-title" data-i18n="mqtt_source.add">Add MQTT Source</h2>
            <button class="modal-close-btn" onclick="closeMQTTSourceModal()" data-i18n-aria-label="aria.close">&#x2715;</button>
        </div>
        <div class="modal-body">
            <form id="mqtt-source-form" onsubmit="return false;">
                <input type="hidden" id="mqtt-source-id">

                <div id="mqtt-source-error" class="error-message" style="display: none;"></div>

                <!-- Name -->
                <div class="form-group">
                    <div class="label-row">
                        <label for="mqtt-source-name" data-i18n="mqtt_source.name">Name:</label>
                        <button type="button" class="hint-toggle" onclick="toggleHint(this)" title="?" data-i18n-aria-label="aria.hint">?</button>
                    </div>
                    <small class="input-hint" style="display:none" data-i18n="mqtt_source.name.hint">A descriptive name for this MQTT broker connection</small>
                    <input type="text" id="mqtt-source-name" data-i18n-placeholder="mqtt_source.name.placeholder" placeholder="My MQTT Broker" required>
                    <div id="mqtt-source-tags-container"></div>
                </div>

                <!-- Broker Host -->
                <div class="form-group">
                    <div class="label-row">
                        <label for="mqtt-source-host" data-i18n="mqtt_source.broker_host">Broker Host:</label>
                        <button type="button" class="hint-toggle" onclick="toggleHint(this)" title="?" data-i18n-aria-label="aria.hint">?</button>
                    </div>
                    <small class="input-hint" style="display:none" data-i18n="mqtt_source.broker_host.hint">MQTT broker hostname or IP address, e.g. 192.168.1.100</small>
                    <input type="text" id="mqtt-source-host" placeholder="192.168.1.100" required>
                </div>

                <!-- Broker Port -->
                <div class="form-group">
                    <div class="label-row">
                        <label for="mqtt-source-port" data-i18n="mqtt_source.broker_port">Port:</label>
                    </div>
                    <input type="number" id="mqtt-source-port" value="1883" min="1" max="65535">
                </div>

                <!-- Username -->
                <div class="form-group">
                    <div class="label-row">
                        <label for="mqtt-source-username" data-i18n="mqtt_source.username">Username (optional):</label>
                    </div>
                    <input type="text" id="mqtt-source-username" placeholder="">
                </div>

                <!-- Password -->
                <div class="form-group">
                    <div class="label-row">
                        <label for="mqtt-source-password" data-i18n="mqtt_source.password">Password (optional):</label>
                    </div>
                    <small id="mqtt-source-password-hint" class="input-hint" style="display:none" data-i18n="mqtt_source.password.edit_hint">Leave blank to keep the current password</small>
                    <input type="password" id="mqtt-source-password" placeholder="">
                </div>

                <!-- Client ID -->
                <div class="form-group">
                    <div class="label-row">
                        <label for="mqtt-source-client-id" data-i18n="mqtt_source.client_id">Client ID:</label>
                        <button type="button" class="hint-toggle" onclick="toggleHint(this)" title="?" data-i18n-aria-label="aria.hint">?</button>
                    </div>
                    <small class="input-hint" style="display:none" data-i18n="mqtt_source.client_id.hint">Unique MQTT client identifier. Change if running multiple instances.</small>
                    <input type="text" id="mqtt-source-client-id" value="ledgrab" placeholder="ledgrab">
                </div>

                <!-- Base Topic -->
                <div class="form-group">
                    <div class="label-row">
                        <label for="mqtt-source-base-topic" data-i18n="mqtt_source.base_topic">Base Topic:</label>
                        <button type="button" class="hint-toggle" onclick="toggleHint(this)" title="?" data-i18n-aria-label="aria.hint">?</button>
                    </div>
                    <small class="input-hint" style="display:none" data-i18n="mqtt_source.base_topic.hint">Prefix for status and state topics, e.g. ledgrab/status</small>
                    <input type="text" id="mqtt-source-base-topic" value="ledgrab" placeholder="ledgrab">
                </div>

                <!-- Description -->
                <div class="form-group">
                    <div class="label-row">
                        <label for="mqtt-source-description" data-i18n="mqtt_source.description">Description (optional):</label>
                    </div>
                    <input type="text" id="mqtt-source-description" placeholder="">
                </div>

            </form>
        </div>
        <div class="modal-footer">
            <button class="btn btn-icon btn-secondary" onclick="closeMQTTSourceModal()" title="Cancel" data-i18n-title="settings.button.cancel" data-i18n-aria-label="aria.cancel">&#x2715;</button>
            <button class="btn btn-icon btn-secondary" id="mqtt-source-test-btn" onclick="testMQTTSource()" title="Test" data-i18n-title="mqtt_source.test" style="display:none">
                <svg class="icon" viewBox="0 0 24 24"><path d="M14 2v6a2 2 0 0 0 .245.96l5.51 10.08A2 2 0 0 1 18 22H6a2 2 0 0 1-1.755-2.96l5.51-10.08A2 2 0 0 0 10 8V2"/><path d="M6.453 15h11.094"/><path d="M8.5 2h7"/></svg>
            </button>
            <button class="btn btn-icon btn-primary" onclick="saveMQTTSource()" title="Save" data-i18n-title="settings.button.save" data-i18n-aria-label="aria.save">&#x2713;</button>
        </div>
    </div>
</div>
