// Settings view — verification defaults, migration defaults, connection info
import { api } from './api.js';
import { state } from './state.js';
import { escHtml } from './utils.js';
import { disconnectPlatform, switchAccount } from './auth.js';
const SETTINGS_KEY = 'migrator_settings';
export function loadSettings() {
try { return JSON.parse(localStorage.getItem(SETTINGS_KEY)) || {}; }
catch { return {}; }
}
export function saveSettings(settings) {
localStorage.setItem(SETTINGS_KEY, JSON.stringify(settings));
}
export function renderSettings() {
const outlet = document.getElementById('router-outlet');
const s = loadSettings();
outlet.innerHTML = `
Test Recipient Name
Pre-filled in the Send Test dialog on the Verification screen
Test Recipient Email
Pre-filled in the Send Test dialog
Auto-Void Timer (hours)
Reminder to void test envelopes after this many hours (display only — no automatic action)
Overwrite Existing by Default
When on, the Overwrite Existing toggle in the migration modal starts enabled
Include Documents by Default
Embed PDFs in the Docusign template payload
Save Settings
✓ Saved
`;
// Wire toggles
document.querySelectorAll('.toggle').forEach(btn => {
btn.addEventListener('click', () => {
btn.classList.toggle('on');
btn.setAttribute('aria-checked', btn.classList.contains('on'));
});
});
// Save
document.getElementById('btn-save-settings')?.addEventListener('click', () => {
const updated = {
testRecipientName: document.getElementById('set-recipient-name')?.value.trim() || '',
testRecipientEmail: document.getElementById('set-recipient-email')?.value.trim() || '',
autoVoidHours: parseInt(document.getElementById('set-auto-void')?.value) || 24,
defaultOverwrite: document.getElementById('set-overwrite')?.classList.contains('on') || false,
defaultIncludeDocs: document.getElementById('set-include-docs')?.classList.contains('on') !== false,
};
saveSettings(updated);
const confirm = document.getElementById('save-confirm');
if (confirm) {
confirm.style.display = 'inline';
setTimeout(() => { confirm.style.display = 'none'; }, 2500);
}
});
// Load connection info
_loadConnInfo();
}
async function _loadConnInfo() {
const connEl = document.getElementById('settings-conn-info');
if (!connEl) return;
try {
const data = await api.auth.status();
connEl.innerHTML = `
Adobe Sign
${data.adobe ? 'Connected' : 'Not connected'}
${data.adobe ? '● Connected' : '○ Disconnected'}
Docusign
${data.docusign ? 'Connected' : 'Not connected'}
${data.docusign ? '● Connected' : '○ Disconnected'}
Adobe Actions
Disconnect Adobe Sign
Docusign Actions
Disconnect Docusign
Switch Docusign Account
Adobe Auth Mode
${escHtml(data.adobe_auth_mode || '—')}
Docusign Auth Mode
${escHtml(data.docusign_auth_mode || '—')}
Browser Session ID
${escHtml(data.session_id || '—')}
Switch Account Note
Use Switch Docusign Account to clear this browser session and start a fresh login flow. If Docusign signs you straight back in, sign out of Docusign in that browser first.
Docusign Account ID
${escHtml(data.docusign_account_id || '—')}
API Environment
${escHtml(data.base_url || '—')}
`;
} catch (e) {
connEl.innerHTML = `❌ Failed to load connection info: ${escHtml(e.message)}
`;
return;
}
document.getElementById('btn-disconnect-adobe')?.addEventListener('click', async () => {
await disconnectPlatform('adobe');
await _loadConnInfo();
});
document.getElementById('btn-disconnect-docusign')?.addEventListener('click', async () => {
await disconnectPlatform('docusign');
await _loadConnInfo();
});
document.getElementById('btn-switch-docusign')?.addEventListener('click', async () => {
await switchAccount('docusign');
});
}