/** Normalize MySQL / JSON truthy flags on form detail rows. */
export function isTruthyFlag(v) {
  if (v === true || v === 1) return true;
  if (typeof v === 'string') {
    const s = v.trim().toLowerCase();
    return s === '1' || s === 'true' || s === 'yes';
  }
  return false;
}

/** Not in `orac_archive_form` and not an intermediate version (no newer row points to this as parent). */
export function formAllowedForNewUse(f) {
  if (!f || typeof f !== 'object') return false;
  if (isTruthyFlag(f.is_archived)) return false;
  if (isTruthyFlag(f.has_child_version)) return false;
  return true;
}
