import { normalizeCustomFieldResponse } from "@open-mercato/shared/lib/custom-fields/normalize";
import { extractCustomFieldEntries } from "@open-mercato/shared/lib/crud/custom-fields-client";
const normalizeCustomFieldSubmitValue = (value) => {
  if (Array.isArray(value)) return value.filter((entry) => entry !== void 0);
  if (value === void 0) return null;
  return value;
};
const prefixCustomFieldValues = (input) => {
  if (!input || typeof input !== "object") return {};
  return Object.entries(input).reduce((acc, [key, value]) => {
    const trimmedKey = key.trim();
    if (!trimmedKey.length) return acc;
    const normalizedKey = trimmedKey.startsWith("cf_") ? trimmedKey : trimmedKey.startsWith("cf:") ? `cf_${trimmedKey.slice(3)}` : `cf_${trimmedKey}`;
    if (normalizedKey.endsWith("__is_multi")) return acc;
    acc[normalizedKey] = value;
    return acc;
  }, {});
};
const extractCustomFieldValues = (source) => {
  if (!source || typeof source !== "object") return {};
  const extracted = extractCustomFieldEntries(source);
  const normalized = normalizeCustomFieldResponse(extracted);
  return normalized ? prefixCustomFieldValues(normalized) : prefixCustomFieldValues(extracted);
};
export {
  extractCustomFieldValues,
  normalizeCustomFieldSubmitValue,
  prefixCustomFieldValues
};
//# sourceMappingURL=customFieldHelpers.js.map
