export function validateAdminForm(form: HTMLFormElement, selectTab: (tab: string) => void): boolean { const firstInvalid = Array.from(form.elements).find(element => element instanceof HTMLElement && "validity" in element && !(element as HTMLInputElement).validity.valid ) as HTMLElement | undefined; if (!firstInvalid) return true; const tab = firstInvalid.closest("[data-tab]")?.dataset.tab; if (tab) selectTab(tab); requestAnimationFrame(() => { firstInvalid.focus(); if ("reportValidity" in firstInvalid) (firstInvalid as HTMLInputElement).reportValidity(); }); return false; } export function focusAdminServerError(errors: Record, selectTab: (tab: string) => void): void { const field = Object.keys(errors)[0]; if (!field) return; const target = Array.from(document.querySelectorAll("form.form-stack [data-field]")) .find(element => element.dataset.field === field || field.endsWith(`.${element.dataset.field}`)); if (!target) return; const tab = target.closest("[data-tab]")?.dataset.tab; if (tab) selectTab(tab); requestAnimationFrame(() => target.querySelector("input,select,textarea")?.focus()); }