import { apiPatch } from './api.js'; import { showToast } from './app.js'; export function isClientArchived(c) { return Number(c.archived) === 1; } export async function confirmAndPatchClientArchive(clientCode, archived) { const msg = archived ? `Archive client "${clientCode}"? They will be hidden from assignments, follow-up, and the mobile app. You can restore them later from the Clients page.` : `Restore client "${clientCode}" to active lists?`; if (!confirm(msg)) return false; try { await apiPatch('clients.php', { clientCode, archived }); showToast( archived ? `Client "${clientCode}" archived` : `Client "${clientCode}" restored`, 'success' ); return true; } catch (e) { showToast(e.message, 'error'); return false; } } /** * @param {object} opts * @param {string} opts.clientCode Escaped client code for data-code attributes * @param {boolean} opts.archived * @param {boolean} [opts.showDelete] * @param {string} [opts.rawCode] Unescaped code for button labels (optional) */ export function clientTableActionsHTML({ clientCode, archived, showDelete = false }) { const archiveBtn = archived ? `` : ``; const deleteBtn = showDelete ? `` : ''; return `