function toErrorMessage(payload) {
  if (!payload) return null;
  if (typeof payload === "string") return payload;
  if (Array.isArray(payload)) {
    for (const item of payload) {
      const nested = toErrorMessage(item);
      if (nested) return nested;
    }
    return null;
  }
  if (typeof payload === "object") {
    const record = payload;
    return toErrorMessage(record.error) ?? toErrorMessage(record.message) ?? toErrorMessage(record.detail) ?? toErrorMessage(record.details) ?? null;
  }
  return null;
}
function formatDateTime(value) {
  if (!value) return "\u2014";
  const date = new Date(value);
  if (Number.isNaN(date.getTime())) return "\u2014";
  return date.toLocaleString();
}
const SAFE_NAVIGATION_SCHEMES = /* @__PURE__ */ new Set(["http:", "https:", "mailto:", "tel:"]);
function isSafeNavigationHref(value) {
  const trimmed = value.trim();
  if (!trimmed) return false;
  if (trimmed.startsWith("//")) return false;
  if (trimmed.startsWith("/") || trimmed.startsWith("./") || trimmed.startsWith("../")) {
    return true;
  }
  const base = typeof window !== "undefined" ? window.location.href : "http://localhost";
  try {
    const parsed = new URL(trimmed, base);
    return SAFE_NAVIGATION_SCHEMES.has(parsed.protocol);
  } catch {
    return false;
  }
}
function parseObjectActionId(value) {
  if (!value.startsWith("object:")) return null;
  const [, objectId, ...rest] = value.split(":");
  if (!objectId || rest.length === 0) return null;
  return { objectId, actionId: rest.join(":") };
}
function resolveObjectActionVariant(variant) {
  if (variant === "default" || variant === "secondary" || variant === "destructive" || variant === "outline") {
    return variant;
  }
  return void 0;
}
function toObjectAction(actionId, action) {
  return {
    id: actionId,
    labelKey: action.labelKey ?? action.label ?? actionId,
    variant: resolveObjectActionVariant(action.variant),
    icon: action.icon,
    commandId: action.commandId,
    href: action.href,
    isTerminal: action.isTerminal,
    confirmRequired: action.confirmRequired,
    confirmMessage: action.confirmMessage
  };
}
export {
  formatDateTime,
  isSafeNavigationHref,
  parseObjectActionId,
  toErrorMessage,
  toObjectAction
};
//# sourceMappingURL=utils.js.map
