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

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

                <!-- Name -->
                <div class="form-group">
                    <div class="label-row">
                        <label for="audio-source-name" data-i18n="audio_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="audio_source.name.hint">A descriptive name for this audio source</small>
                    <input type="text" id="audio-source-name" data-i18n-placeholder="audio_source.name.placeholder" placeholder="System Audio" required>
                    <div id="audio-source-tags-container"></div>
                </div>

                <!-- Type (hidden — determined by which add button was clicked) -->
                <input type="hidden" id="audio-source-type" value="capture">

                <!-- Capture fields -->
                <div id="audio-source-capture-section">
                    <div class="form-group">
                        <div class="label-row">
                            <label for="audio-source-audio-template" data-i18n="audio_source.audio_template">Audio Template:</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="audio_source.audio_template.hint">Audio capture template that defines which engine and settings to use for this device</small>
                        <select id="audio-source-audio-template">
                            <!-- populated dynamically -->
                        </select>
                    </div>

                    <div class="form-group">
                        <div class="label-row">
                            <label for="audio-source-device" data-i18n="audio_source.device">Audio Device:</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="audio_source.device.hint">Audio input source. Loopback devices capture system audio output; input devices capture microphone or line-in.</small>
                        <div class="select-with-action">
                            <select id="audio-source-device">
                                <!-- populated dynamically -->
                            </select>
                            <button type="button" class="btn btn-secondary btn-sm" id="audio-source-refresh-devices" onclick="refreshAudioDevices()" data-i18n-title="audio_source.refresh_devices" title="Refresh devices">&#x21BB;</button>
                        </div>
                    </div>
                </div>

                <!-- Processed fields -->
                <div id="audio-source-processed-section" style="display:none">
                    <div class="form-group">
                        <div class="label-row">
                            <label for="audio-source-parent" data-i18n="audio_source.parent">Input Audio Source:</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="audio_source.parent.hint">Audio source to apply processing filters to</small>
                        <select id="audio-source-parent">
                            <!-- populated dynamically with audio sources -->
                        </select>
                    </div>

                    <div class="form-group">
                        <div class="label-row">
                            <label for="audio-source-processing-template" data-i18n="audio_source.processing_template">Processing Template:</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="audio_source.processing_template.hint">Audio processing template with filters to apply to the input source</small>
                        <select id="audio-source-processing-template">
                            <!-- populated dynamically -->
                        </select>
                    </div>
                </div>

                <!-- Description -->
                <div class="form-group">
                    <div class="label-row">
                        <label for="audio-source-description" data-i18n="audio_source.description">Description (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="audio_source.description.hint">Optional notes about this audio source</small>
                    <input type="text" id="audio-source-description" data-i18n-placeholder="audio_source.description.placeholder" placeholder="Describe this audio source...">
                </div>

            </form>
        </div>
        <div class="modal-footer">
            <button class="btn btn-icon btn-secondary" onclick="closeAudioSourceModal()" title="Cancel" data-i18n-title="settings.button.cancel" data-i18n-aria-label="aria.cancel">&#x2715;</button>
            <button class="btn btn-icon btn-primary" onclick="saveAudioSource()" title="Save" data-i18n-title="settings.button.save" data-i18n-aria-label="aria.save">&#x2713;</button>
        </div>
    </div>
</div>
