import { removeEmptyValues } from "./common.mjs";
function parseSingleParamValue(value, data, fields) {
  if (typeof value !== "object" || value === null) {
    return value;
  }
  if (Array.isArray(value)) {
    return value.map((item) => parseSingleParamValue(item, data, fields));
  }
  const type = value.type;
  if (type === "field") {
    const field = fields.find((f) => f.id == value.value);
    if (field) {
      return data[field.fieldName];
    }
    return null;
  } else if (type === "userInfo") {
    console.warn("[parseRouteParams] userInfo 类型暂未实现");
    return {};
  } else if (type === "urlParam") {
    const urlParams = new URLSearchParams(window.location.search);
    return urlParams.get(value.value) || null;
  } else {
    return value.value !== void 0 ? value.value : value;
  }
}
function parseRouteParams(routeParams, data, fields) {
  if (!routeParams || !Array.isArray(routeParams)) {
    return {};
  }
  const params = {};
  routeParams.forEach((param) => {
    const key = param.key;
    if (!key) return;
    params[key] = parseSingleParamValue(param.value, data, fields);
  });
  return removeEmptyValues(params);
}
export {
  parseRouteParams,
  parseSingleParamValue
};
