import { showModal, closeModal } from './modal-base.js'; import { state } from '../state.js'; let _cb = null; let _names = []; export function showExerciseDialog(workoutType, callback) { _cb = callback; const nameCount = {}; state.exerciseRef.forEach(ex => { const bonus = (workoutType && ex.workoutType === workoutType) ? 100 : 10; nameCount[ex.name] = (nameCount[ex.name] || 0) + bonus; }); state.workouts.forEach(w => w.exercises.forEach(ex => { nameCount[ex.name] = (nameCount[ex.name] || 0) + 1; })); _names = Object.keys(nameCount).sort((a, b) => { const d = nameCount[b] - nameCount[a]; return d !== 0 ? d : a.localeCompare(b); }); showModal(`
`); setTimeout(() => { document.getElementById('m-ex-name').focus(); filter(); }, 50); } export function filter() { const q = document.getElementById('m-ex-name').value.trim().toLowerCase(); const list = document.getElementById('m-ex-autocomplete'); let f = _names; if (q) f = f.filter(n => n.toLowerCase().includes(q)); if (!f.length) { list.innerHTML = '