import {
  escapeMarkdown
} from "./chunk-NUFPTHKU.js";
import {
  listDatasets
} from "./chunk-ITN2QGHF.js";
import "./chunk-CAY57CKF.js";
import "./chunk-KOO5733S.js";

// src/tools/list-datasets.ts
async function fetchAllDatasets() {
  const PAGE_SIZE = 100;
  const datasets = [];
  let page = 1;
  let total = 0;
  while (true) {
    const response = await listDatasets({ page, limit: PAGE_SIZE });
    total = response.pagination.total;
    datasets.push(...response.data);
    if (datasets.length >= total || response.data.length === 0) {
      break;
    }
    page++;
  }
  return { datasets, total };
}
async function handleListDatasets(params = {}) {
  if (params.format === "json") {
    const { datasets: datasets2, total: total2 } = await fetchAllDatasets();
    return JSON.stringify({ data: datasets2, total: total2 }, null, 2);
  }
  const { datasets, total } = await fetchAllDatasets();
  if (datasets.length === 0) {
    return "No datasets found in this project.\n\n> Tip: Use `platform_create_dataset` to create your first dataset.";
  }
  const lines = [];
  lines.push(`# Datasets (${total} total)
`);
  for (const ds of datasets) {
    lines.push(`## ${escapeMarkdown(ds.name)}`);
    lines.push(`**Slug**: ${escapeMarkdown(ds.slug)}`);
    lines.push(`**ID**: ${ds.id}`);
    if (Array.isArray(ds.columnTypes) && ds.columnTypes.length > 0) {
      const colNames = ds.columnTypes.map((c) => c.name).join(", ");
      lines.push(`**Columns**: ${colNames}`);
    }
    lines.push(
      `**Records**: ${ds.recordCount ?? "unknown"}`
    );
    lines.push("");
  }
  lines.push(
    "> Use `platform_get_dataset` with the slug to see full dataset details and records."
  );
  return lines.join("\n");
}
export {
  handleListDatasets
};
//# sourceMappingURL=list-datasets-HBTH33X4.js.map