import fs from "fs";
import { getImportExtensions, getExportFormats } from "./converters.js";
import { sortByUsage } from "../stats.js";

const EXCLUDED_FORMATS = ["x", "glb", "gltf"];

export function listConvertibleFiles() {
  const cwd = process.cwd();
  const exts = getImportExtensions();
  return fs.readdirSync(cwd).filter(file => {
    const ext = file.slice(file.lastIndexOf(".")).toLowerCase();
    return exts.includes(ext);
  });
}

export function getSteps() {
  const files = listConvertibleFiles();
  const formats = sortByUsage("convert_format", getExportFormats().filter(f => !EXCLUDED_FORMATS.includes(f)));

  return [
    {
      name: "源文件",
      type: "multiselect",
      message: files.length ? "选择要转换的模型文件" : "当前目录未找到可转换的模型文件",
      options: files.map(file => ({ value: file, label: file })),
      default: [],
      emptyMessage: "请按 Esc 返回并放入模型文件后重试"
    },
    {
      name: "输出格式",
      type: "select",
      message: "选择目标格式",
      options: formats.map(f => ({ value: f, label: f })),
      default: formats[0]
    }
  ];
}
