export function validatePageNumber(pageNumber) {
  const num = parseInt(pageNumber, 10);
  if (isNaN(num) || num < 1) {
    return "Page number must be a positive integer.";
  }
  return null;
}

export function validateTOCEntry(entry, existingEntries = [], editingId = null) {
  const pageError = validatePageNumber(entry.pageNumber);
  if (pageError) return { pageNumber: pageError };

  if (!entry.title || entry.title.trim() === "") {
    return { title: "Title is required." };
  }
  
  // Check for duplicates if needed (strict mode), but usually TOCs can have multiple entries on same page
  // We'll keep it flexible for now.

  return null;
}

export function sortTOCEntries(entries) {
  // Usually TOC is sorted by page number, but user might want custom order if multiple items are on same page.
  // We will respect the array order as the definitive order, assuming the user manually reordered them.
  return [...entries]; 
}

export function generateDefaultTOC(sections) {
  // Helper to generate a basic TOC from sections if none exists
  // This is tricky because we don't know page numbers until generation.
  // For manual TOC management, we might just return empty or placeholder.
  return [];
}