```ts
/** A sectioned sales report: item lines, subtotals, and a ranked summary. */

function ranked(a: [string, number, number], b: [string, number, number]): number {
  if (a[2] !== b[2]) {
    return b[2] - a[2];
  }
  return a[0] < b[0] ? -1 : 1;
}

export function sectionReport(rows: [string, string, number][]): {
  lines: [string, string, string, number][];
  sections: [string, number, number][];
  grand: number;
} {
  if (!Array.isArray(rows)) {
    throw new Error("rows must be an array");
  }
  for (const row of rows) {
    if (!Array.isArray(row) || row.length !== 3) {
      throw new Error("each row must be a three-item list");
    }
    const [section, label, amount] = row;
    if (typeof section !== "string" || section.trim() === "") {
      throw new Error("section must be a non-empty string");
    }
    if (typeof label !== "string" || label.trim() === "") {
      throw new Error("label must be a non-empty string");
    }
    if (!Number.isInteger(amount)) {
      throw new Error("amount must be an integer");
    }
  }

  const lines: [string, string, string, number][] = [];
  const sections: [string, number, number][] = [];
  let currentSection = "";
  let subtotal = 0;
  let count = 0;
  let grand = 0;

  for (const [section, label, amount] of rows) {
    if (currentSection !== "" && section !== currentSection) {
      lines.push(["section", currentSection, "", subtotal]);
      sections.push([currentSection, count, subtotal]);
      count = 0;
      subtotal = 0;
    }
    currentSection = section;
    lines.push(["item", section, label, amount]);
    subtotal += amount;
    count += 1;
    grand += amount;
  }

  if (currentSection !== "") {
    lines.push(["section", currentSection, "", subtotal]);
    sections.push([currentSection, count, subtotal]);
  }

  lines.push(["grand", "", "", grand]);
  sections.sort(ranked);
  return { lines, sections, grand };
}
```