// Issues & Warnings view â surfaces all validation problems before migration
import { state } from './state.js';
import { escHtml, formatDate, renderFieldIssues, bindFieldIssueToggles } from './utils.js';
import { navigate } from './router.js';
export function renderIssues() {
const outlet = document.getElementById('router-outlet');
const templates = state.templates || [];
const blocked = templates.filter(t => hasBlockers(t));
const warnings = templates.filter(t =>
!hasBlockers(t) && (hasWarnings(t) || hasFieldIssues(t))
);
if (!state.auth.adobe || !state.auth.docusign) {
outlet.innerHTML = `
âšī¸Connect both platforms to see validation results.
`;
return;
}
if (!blocked.length && !warnings.length) {
outlet.innerHTML = `
đ
All templates are ready!
No validation blockers, warnings, or field mapping caveats found across ${templates.length} template${templates.length !== 1 ? 's' : ''}.
`;
return;
}
outlet.innerHTML = `
${blocked.length ? `
đĢ Blockers â ${blocked.length} template${blocked.length > 1 ? 's' : ''} will fail migration
${blocked.map(t => _blockerItem(t)).join('')}
` : ''}
${warnings.length ? `
â Caveats â ${warnings.length} template${warnings.length > 1 ? 's' : ''} should be reviewed
${warnings.map(t => _warningItem(t)).join('')}
` : ''}
`;
// Migrate Anyway buttons
document.querySelectorAll('.btn-migrate-anyway').forEach(btn => {
btn.addEventListener('click', () => {
import('./migration.js').then(m => m.showOptionsModal([btn.dataset.id]));
});
});
// View Template links
document.querySelectorAll('.btn-view-template').forEach(btn => {
btn.addEventListener('click', () => navigate(`#/templates/${btn.dataset.id}`));
});
bindFieldIssueToggles(outlet);
}
function _blockerItem(t) {
const blockers = t.blockers || [];
return `
đĢ
${escHtml(t.name)}
${blockers.map(b => `
âĸ ${escHtml(b)}
`).join('')}
Modified ${formatDate(t.adobe_modified)}
`;
}
function _warningItem(t) {
const warnings = t.warnings || [];
const fieldIssues = t.field_issues || [];
return `
â ī¸
${escHtml(t.name)}
${warnings.slice(0, 3).map(w => `
âĸ ${escHtml(w)}
`).join('')}
${warnings.length > 3 ? `
âĻ +${warnings.length - 3} more
` : ''}
${fieldIssues.length ? renderFieldIssues(fieldIssues) : ''}
Modified ${formatDate(t.adobe_modified)}
`;
}
function hasBlockers(t) {
return (t.blockers || []).length > 0;
}
function hasWarnings(t) {
return (t.warnings || []).length > 0;
}
function hasFieldIssues(t) {
return (t.field_issues || []).length > 0;
}