// assets/scripts/entries.js
import { parseDuration, roundToQuarter, formatMinutes, initDurationBlurHandler, validateDuration } from './duration.js';
const LAST_PROJECT_KEY = 'tt_last_project_id';
const LAST_SERVICE_KEY = 'tt_last_service_id';
const LOCK_SVG = ``;
function t(key) {
return window.TT?.i18n?.[key] ?? key;
}
function buildProjectOptions(selectedId = null) {
const groups = {};
(window.TT?.projects ?? []).forEach(p => {
if (!groups[p.clientName]) groups[p.clientName] = [];
groups[p.clientName].push(p);
});
let html = ``;
for (const [client, projects] of Object.entries(groups)) {
html += `';
}
return html;
}
function buildServiceOptions(selectedId = null) {
const billable = (window.TT?.services ?? []).filter(s => s.billable);
const notBillable = (window.TT?.services ?? []).filter(s => !s.billable);
let html = ``;
if (billable.length) {
html += `';
}
if (notBillable.length) {
html += `';
}
return html;
}
function buildEntryRowHTML(entry, animate = false) {
const servicePart = entry.serviceName ? ` / ${entry.serviceName}` : '';
const notePart = entry.note ? `
`;
return `
';
entries.forEach(e => { html += buildEntryRowHTML(e, false); });
html += `
`;
this.list.innerHTML = html;
this.emptyState = null;
this.list.querySelectorAll('.entry-row').forEach(row => {
row.querySelector('.edit-project').innerHTML = buildProjectOptions(row.dataset.projectId);
row.querySelector('.edit-service').innerHTML = buildServiceOptions(row.dataset.serviceId);
});
this.checkAutoEdit();
}
updateTotal(totalDuration) {
let footer = document.getElementById('entry-footer');
if (!footer) {
footer = document.createElement('div');
footer.className = 'entry-list__footer';
footer.id = 'entry-footer';
this.list.appendChild(footer);
}
footer.innerHTML = `