"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var elicitationSchema_exports = {};
__export(elicitationSchema_exports, {
  parseElicitationSchema: () => parseElicitationSchema
});
module.exports = __toCommonJS(elicitationSchema_exports);
function humanizeIdentifier(value) {
  return value.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[_-]+/g, " ").replace(/\s+/g, " ").trim();
}
function titleCaseWords(value) {
  return value.split(" ").map((word) => word ? word.charAt(0).toUpperCase() + word.slice(1) : "").join(" ");
}
function cleanLabel(value) {
  return value.replace(/^\s*\d+\s*[).:-]\s*/g, "").replace(/\s*[:*]\s*$/g, "").trim();
}
function makeLabel(name) {
  return titleCaseWords(humanizeIdentifier(name)) || name;
}
function getXDextoStepLabel(prop) {
  const xDexto = prop["x-dexto"];
  if (!xDexto || typeof xDexto !== "object" || Array.isArray(xDexto)) return void 0;
  const stepLabel = xDexto.stepLabel;
  if (typeof stepLabel !== "string") return void 0;
  return cleanLabel(stepLabel) || void 0;
}
function getFieldType(prop) {
  const { type } = prop;
  if (type === "boolean") return { type: "boolean", enumValues: void 0 };
  if (type === "number" || type === "integer") return { type: "number", enumValues: void 0 };
  if (type === "array" && prop.items && Array.isArray(prop.items.enum)) {
    return { type: "array-enum", enumValues: prop.items.enum };
  }
  if (Array.isArray(prop.enum)) return { type: "enum", enumValues: prop.enum };
  return { type: "string", enumValues: void 0 };
}
function parseElicitationSchema(schema) {
  if (!schema || typeof schema !== "object" || Array.isArray(schema)) return [];
  const schemaRecord = schema;
  const properties = schemaRecord.properties;
  if (!properties || typeof properties !== "object" || Array.isArray(properties)) return [];
  const required = Array.isArray(schemaRecord.required) ? schemaRecord.required.filter((v) => typeof v === "string") : [];
  const result = [];
  for (const [name, rawProp] of Object.entries(properties)) {
    if (typeof rawProp === "boolean" || !rawProp || typeof rawProp !== "object" || Array.isArray(rawProp)) {
      continue;
    }
    const prop = rawProp;
    const { type, enumValues } = getFieldType(prop);
    const fallbackLabel = makeLabel(name);
    const stepLabel = getXDextoStepLabel(prop) || fallbackLabel;
    const question = (prop.title ? cleanLabel(prop.title) : "") || fallbackLabel;
    const helpText = (prop.description ? cleanLabel(prop.description) : "") || void 0;
    result.push({
      name,
      stepLabel,
      question,
      helpText,
      type,
      required: required.includes(name),
      enumValues
    });
  }
  return result;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  parseElicitationSchema
});
