function resolveIntegrationDetailWidgetSpotId(integration, legacySpotId) {
  const widgetSpotId = integration?.detailPage?.widgetSpotId?.trim();
  return widgetSpotId && widgetSpotId.length > 0 ? widgetSpotId : legacySpotId;
}
function resolveRequestedIntegrationDetailTab(value, visibleTabIds) {
  if (value && visibleTabIds.includes(value)) return value;
  return visibleTabIds[0] ?? "credentials";
}
function filterIntegrationDetailWidgetsByKind(widgets, kind) {
  return widgets.filter((widget) => (widget.placement?.kind ?? "stack") === kind).sort((left, right) => {
    const leftPriority = typeof left.placement?.priority === "number" ? left.placement.priority : 0;
    const rightPriority = typeof right.placement?.priority === "number" ? right.placement.priority : 0;
    return rightPriority - leftPriority;
  });
}
function buildIntegrationDetailInjectedTabs(widgets, resolveLabel) {
  const groupedTabs = /* @__PURE__ */ new Map();
  for (const widget of widgets) {
    if ((widget.placement?.kind ?? "stack") !== "tab") continue;
    const id = widget.placement?.groupId ?? widget.widgetId;
    const label = resolveLabel(widget);
    const priority = typeof widget.placement?.priority === "number" ? widget.placement.priority : 0;
    const existing = groupedTabs.get(id);
    if (existing) {
      existing.widgets.push(widget);
      existing.priority = Math.max(existing.priority, priority);
      continue;
    }
    groupedTabs.set(id, {
      id,
      label,
      priority,
      widgets: [widget]
    });
  }
  return Array.from(groupedTabs.values()).sort((left, right) => right.priority - left.priority);
}
export {
  buildIntegrationDetailInjectedTabs,
  filterIntegrationDetailWidgetsByKind,
  resolveIntegrationDetailWidgetSpotId,
  resolveRequestedIntegrationDetailTab
};
//# sourceMappingURL=detail-page-widgets.js.map
