<!-- Home Assistant Source Editor Modal — sectioned rack-panel layout
     matching the settings-modal-redesign vocabulary. Channels: signal
     (identity), cyan (connection: host/token/SSL), amber (entity
     filters). The SSL checkbox is upgraded to a .ds-toggle-row recessed
     hardware switch so it visually anchors the connection panel. All
     element IDs preserved for ha-source.ts compatibility. -->
<div id="ha-source-modal" class="modal" role="dialog" aria-modal="true" aria-labelledby="ha-source-modal-title">
    <div class="modal-content">
        <div class="modal-header">
            <h2 id="ha-source-modal-title" data-i18n="ha_source.add">Add Home Assistant Source</h2>
            <button class="modal-close-btn" onclick="closeHASourceModal()" data-i18n-aria-label="aria.close">&#x2715;</button>
        </div>
        <div class="modal-body">
            <form id="ha-source-form" onsubmit="return false;">
                <input type="hidden" id="ha-source-id">

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

                <!-- ── 01 · IDENTITY ───────────────────────────────── -->
                <section class="ds-section" data-ds-key="identity" data-ch="signal">
                    <div class="ds-section-header">
                        <span class="ds-section-dot" aria-hidden="true"></span>
                        <span class="ds-section-title" data-i18n="settings.section.identity">Identity</span>
                        <span class="ds-section-index" aria-hidden="true">01</span>
                    </div>
                    <div class="ds-section-body">
                        <div class="form-group ds-name-group">
                            <label for="ha-source-name" data-i18n="ha_source.name">Name:</label>
                            <input type="text" id="ha-source-name" data-i18n-placeholder="ha_source.name.placeholder" placeholder="My Home Assistant" required>
                            <div id="ha-source-tags-container"></div>
                        </div>

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

                <!-- ── 02 · CONNECTION ─────────────────────────────── -->
                <section class="ds-section" data-ds-key="connection" data-ch="cyan">
                    <div class="ds-section-header">
                        <span class="ds-section-dot" aria-hidden="true"></span>
                        <span class="ds-section-title" data-i18n="settings.section.connection">Connection</span>
                        <span class="ds-section-index" aria-hidden="true">02</span>
                    </div>
                    <div class="ds-section-body">
                        <div class="form-group">
                            <div class="label-row">
                                <label for="ha-source-host" data-i18n="ha_source.host">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="ha_source.host.hint">Home Assistant host and port, e.g. 192.168.1.100:8123</small>
                            <input type="text" id="ha-source-host" placeholder="192.168.1.100:8123" required>
                        </div>

                        <div class="form-group">
                            <div class="label-row">
                                <label for="ha-source-token" data-i18n="ha_source.token">Access Token:</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="ha_source.token.hint">Long-Lived Access Token from HA (Profile > Security > Long-Lived Access Tokens)</small>
                            <small id="ha-source-token-hint" class="input-hint" style="display:none" data-i18n="ha_source.token.edit_hint">Leave blank to keep the current token</small>
                            <input type="password" id="ha-source-token" placeholder="eyJ0eXAiOi..." autocomplete="new-password">
                        </div>

                        <div class="ds-toggle-row">
                            <div class="ds-toggle-text">
                                <div class="label-row">
                                    <label for="ha-source-ssl" data-i18n="ha_source.use_ssl">Use SSL (wss://)</label>
                                </div>
                                <small class="input-hint" style="display:none" data-i18n="ha_source.use_ssl.hint">Enable for HTTPS / wss connections to Home Assistant</small>
                            </div>
                            <label class="settings-toggle">
                                <input type="checkbox" id="ha-source-ssl">
                                <span class="settings-toggle-slider"></span>
                            </label>
                        </div>
                    </div>
                </section>

                <!-- ── 03 · FILTERS ────────────────────────────────── -->
                <section class="ds-section" data-ds-key="filters" data-ch="amber">
                    <div class="ds-section-header">
                        <span class="ds-section-dot" aria-hidden="true"></span>
                        <span class="ds-section-title" data-i18n="settings.section.filters">Filters</span>
                        <span class="ds-section-index" aria-hidden="true">03</span>
                    </div>
                    <div class="ds-section-body">
                        <div class="form-group">
                            <div class="label-row">
                                <label for="ha-source-filters" data-i18n="ha_source.entity_filters">Entity Filters (optional):</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="ha_source.entity_filters.hint">Comma-separated glob patterns to filter entities, e.g. sensor.*, binary_sensor.front_door. Leave empty for all entities.</small>
                            <input type="text" id="ha-source-filters" placeholder="sensor.*, binary_sensor.*">
                        </div>
                    </div>
                </section>

            </form>
        </div>
        <div class="modal-footer">
            <button class="btn btn-icon btn-secondary" onclick="closeHASourceModal()" title="Cancel" data-i18n-title="settings.button.cancel" data-i18n-aria-label="aria.cancel">&#x2715;</button>
            <button class="btn btn-icon btn-secondary" id="ha-source-test-btn" onclick="testHASource()" title="Test" data-i18n-title="ha_source.test" style="display:none">
                <svg class="icon" viewBox="0 0 24 24"><path d="M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8"/><path d="M21 3v5h-5"/><path d="M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16"/><path d="M8 16H3v5"/></svg>
            </button>
            <button class="btn btn-icon btn-primary" onclick="saveHASource()" title="Save" data-i18n-title="settings.button.save" data-i18n-aria-label="aria.save">&#x2713;</button>
        </div>
    </div>
</div>
