import { listAllModelFiles } from "../utils/gltf.js";

const transformOptions = [
  { value: "dedup", label: "dedup（去重）", hint: "删除重复的访问器、材质、网格" },
  { value: "prune", label: "prune（清理无用节点）", hint: "移除未被引用的节点、材质、动画" },
  { value: "resample", label: "resample（动画重采样）", hint: "统一动画关键帧间隔，减少多余数据" },
  { value: "weld", label: "weld（合并顶点）", hint: "合并共享位置的顶点以减少面数" },
  { value: "quantize", label: "quantize（量化顶点数据）", hint: "降低顶点属性精度减小模型体积" }
];

const quantizePresets = [
  { value: "high", label: "高质量（位置16位，法线12位，UV14位）", hint: "尽量保证细节，适合高保真场景" },
  { value: "balanced", label: "均衡（位置14位，法线10位，UV12位）", hint: "默认推荐，兼顾体积与质量" },
  { value: "aggressive", label: "极限压缩（位置12位，法线8位，UV10位）", hint: "最小体积，但可能损失细节" },
  { value: "light", label: "轻量（位置10位，法线8位，UV10位）", hint: "适合移动端、卡通等对精度不敏感场景" }
];

const outputFormats = [
  { value: "auto", label: "保持原格式", hint: "glTF/GLB保持原格式，OBJ/FBX转为GLB" },
  { value: "glb", label: "统一导出为 GLB（二进制）", hint: "单文件发布更方便" },
  { value: "gltf", label: "统一导出为 glTF（JSON）", hint: "可读性好，调试方便" }
];

const outputOptions = [
  { value: "overwrite", label: "覆盖原文件", hint: "直接把结果写回源文件" },
  { value: "backup", label: "保留备份 (_备份)", hint: "覆盖前在同目录生成 _备份 副本" },
  { value: "copy", label: "输出副本 (_compressed)", hint: "保留原文件不动，结果写入新文件" }
];

export function getSteps() {
  const files = listAllModelFiles();
  const fileStep = {
    name: "模型选择",
    type: "multiselect",
    message: files.length ? "选择要处理的模型（支持 glTF/GLB/OBJ/FBX）" : "当前目录未找到模型文件",
    options: files.map(file => ({ value: file, label: file })),
    default: [...files]
  };

  return [
    fileStep,
    {
      name: "压缩命令",
      type: "multiselect",
      message: "请选择要执行的 gltf-transform 操作",
      options: transformOptions,
      default: ["dedup", "prune", "weld", "quantize"]
    },
    {
      name: "量化级别",
      type: "select",
      message: "量化可显著减小体积（如未启用 quantize 可直接 Tab）",
      options: quantizePresets,
      default: "balanced"
    },
    {
      name: "输出格式",
      type: "select",
      message: "选择最终模型格式",
      options: outputFormats,
      default: "auto"
    },
    {
      name: "输出选项",
      type: "multiselect",
      message: "请选择输出行为",
      options: outputOptions,
      default: ["overwrite", "backup"]
    }
  ];
}
