(onClose)
| 3 | import { t } from '../lib/i18n.js'; |
| 4 | |
| 5 | export function SettingsModal(onClose) { |
| 6 | const overlay = document.createElement('div'); |
| 7 | overlay.style.cssText = 'position:fixed;inset:0;background:rgba(0,0,0,0.8);display:flex;align-items:center;justify-content:center;z-index:100;'; |
| 8 | |
| 9 | const modal = document.createElement('div'); |
| 10 | modal.style.cssText = 'background:var(--bg-card,#111);border-radius:1rem;border:1px solid rgba(255,255,255,0.08);width:min(90vw,36rem);max-height:85vh;display:flex;flex-direction:column;overflow:hidden;'; |
| 11 | |
| 12 | // ── Header ──────────────────────────────────────────────────────────────── |
| 13 | const header = document.createElement('div'); |
| 14 | header.style.cssText = 'display:flex;align-items:center;justify-content:space-between;padding:1.25rem 1.5rem;border-bottom:1px solid rgba(255,255,255,0.06);flex-shrink:0;'; |
| 15 | header.innerHTML = ` |
| 16 | <h2 style="font-size:1rem;font-weight:800;color:#fff;margin:0;">${t('settings.title')}</h2> |
| 17 | <button id="settings-close-btn" style="color:rgba(255,255,255,0.4);background:none;border:none;cursor:pointer;padding:4px;"> |
| 18 | <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><path d="M18 6L6 18M6 6l12 12"/></svg> |
| 19 | </button> |
| 20 | `; |
| 21 | modal.appendChild(header); |
| 22 | |
| 23 | // ── Tabs ────────────────────────────────────────────────────────────────── |
| 24 | const TABS = [ |
| 25 | { id: 'api', label: t('settings.apiKey') }, |
| 26 | ...(isLocalAIAvailable() ? [{ id: 'local', label: t('settings.localModels') }] : []), |
| 27 | ]; |
| 28 | |
| 29 | let activeTab = 'api'; |
| 30 | |
| 31 | const tabBar = document.createElement('div'); |
| 32 | tabBar.style.cssText = 'display:flex;gap:0.25rem;padding:0.75rem 1.5rem 0;border-bottom:1px solid rgba(255,255,255,0.06);flex-shrink:0;'; |
| 33 | |
| 34 | const tabBtns = {}; |
| 35 | TABS.forEach(({ id, label }) => { |
| 36 | const btn = document.createElement('button'); |
| 37 | btn.textContent = label; |
| 38 | btn.style.cssText = 'padding:0.4rem 0.75rem;border-radius:0.5rem 0.5rem 0 0;font-size:0.75rem;font-weight:700;border:none;cursor:pointer;transition:all 0.15s;'; |
| 39 | btn.onclick = () => switchTab(id); |
| 40 | tabBtns[id] = btn; |
| 41 | tabBar.appendChild(btn); |
| 42 | }); |
| 43 | modal.appendChild(tabBar); |
| 44 | |
| 45 | // ── Body ────────────────────────────────────────────────────────────────── |
| 46 | const body = document.createElement('div'); |
| 47 | body.style.cssText = 'flex:1;overflow-y:auto;padding:1.5rem;'; |
| 48 | modal.appendChild(body); |
| 49 | |
| 50 | // ── Tab: API Key ────────────────────────────────────────────────────────── |
| 51 | const apiPanel = document.createElement('div'); |
| 52 | apiPanel.innerHTML = ` |
| 53 | <div style="display:flex;flex-direction:column;gap:0.75rem;"> |
| 54 | <div> |
| 55 | <label style="display:block;font-size:0.75rem;color:rgba(255,255,255,0.5);margin-bottom:0.4rem;font-weight:600;">${t('settings.muapiKeyLabel')}</label> |
| 56 | <input id="settings-api-key" type="password" |
| 57 | style="width:100%;box-sizing:border-box;background:rgba(255,255,255,0.05);border:1px solid rgba(255,255,255,0.1);border-radius:0.75rem;padding:0.6rem 0.9rem;color:#fff;font-size:0.875rem;outline:none;" |
| 58 | placeholder="${t('settings.keyPlaceholder')}" |
| 59 | value="${localStorage.getItem('muapi_key') || ''}"> |
| 60 | </div> |
| 61 | <p style="font-size:0.7rem;color:rgba(255,255,255,0.3);margin:0;"> |
| 62 | ${t('settings.keyNote')} |
no test coverage detected