'use strict';

var button = require('@base-ui/react/button');
var icons = require('@blueprintjs/icons');
var classnames = require('classnames');
var React = require('react');
var platformApis = require('@osdk/react/platform-apis');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var classnames__default = /*#__PURE__*/_interopDefault(classnames);
var React__default = /*#__PURE__*/_interopDefault(React);

// src/cbac-picker/base/BaseCbacBanner.tsx

// src/cbac-picker/utils/cbacPickerUtils.ts
var UNMARKED_BACKGROUND_COLORS = ["#8F99A8"];
var UNMARKED_TEXT_COLOR = "#FFFFFF";
var UNMARKED_CLASSIFICATION_STRING = "UNMARKED";
var EMPTY_ARRAY = [];
function backgroundFromColors(backgroundColors) {
  return backgroundColors.length > 1 ? `linear-gradient(to right, ${backgroundColors.join(", ")})` : backgroundColors[0] ?? "transparent";
}
function resolveBannerDisplay(banner) {
  return {
    classificationString: banner?.classificationString ?? UNMARKED_CLASSIFICATION_STRING,
    textColor: banner?.textColor ?? UNMARKED_TEXT_COLOR,
    backgroundColors: banner?.backgroundColors ?? UNMARKED_BACKGROUND_COLORS
  };
}
function groupMarkingsByCategory(markingIds, categories, markings) {
  if (markingIds.length === 0 || categories === void 0 || markings === void 0) {
    return [];
  }
  const selected = new Set(markingIds);
  const categoryNames = new Map(categories.map((c) => [c.id, c.name]));
  const grouped = /* @__PURE__ */ new Map();
  for (const marking of markings) {
    if (selected.has(marking.id)) {
      const name = categoryNames.get(marking.categoryId) ?? marking.categoryId;
      const list = grouped.get(name);
      if (list !== void 0) {
        list.push(marking.name);
      } else {
        grouped.set(name, [marking.name]);
      }
    }
  }
  return Array.from(grouped, ([categoryName, markingNames]) => ({
    categoryName,
    markingNames
  }));
}
function resolveRequiredGroups(categoryGroups, requiredMarkingGroups) {
  const markingIdToName = new Map(categoryGroups.flatMap((g) => g.markings).map((m) => [m.id, m.name]));
  return requiredMarkingGroups.map((ids) => ({
    markingNames: ids.map((id) => markingIdToName.get(id) ?? id)
  }));
}

// src/cbac-picker/base/BaseCbacBanner.module.css
var BaseCbacBanner_default = {};

// src/cbac-picker/base/BaseCbacBanner.tsx
function BaseCbacBanner({
  classificationString,
  textColor,
  backgroundColors,
  onClick,
  onDismiss,
  className
}) {
  const bannerStyle = React__default.default.useMemo(() => ({
    "--osdk-cbac-banner-bg": backgroundFromColors(backgroundColors),
    "--osdk-cbac-banner-color": textColor
  }), [textColor, backgroundColors]);
  const handleDismiss = React__default.default.useCallback((e) => {
    e.stopPropagation();
    onDismiss?.();
  }, [onDismiss]);
  const dismissButton = onDismiss != null ? /* @__PURE__ */ React__default.default.createElement(button.Button, {
    className: BaseCbacBanner_default.dismissButton,
    onClick: handleDismiss,
    "aria-label": "Clear classification"
  }, /* @__PURE__ */ React__default.default.createElement(icons.Cross, {
    size: 12,
    color: "currentColor"
  })) : null;
  if (onClick != null) {
    return /* @__PURE__ */ React__default.default.createElement("div", {
      className: classnames__default.default(BaseCbacBanner_default.bannerRow, className),
      style: bannerStyle
    }, /* @__PURE__ */ React__default.default.createElement(button.Button, {
      className: classnames__default.default(BaseCbacBanner_default.banner, BaseCbacBanner_default.clickable),
      onClick,
      "aria-label": "Edit classification"
    }, classificationString), dismissButton);
  }
  return /* @__PURE__ */ React__default.default.createElement("div", {
    className: classnames__default.default(BaseCbacBanner_default.bannerRow, className),
    style: bannerStyle
  }, /* @__PURE__ */ React__default.default.createElement("span", {
    className: BaseCbacBanner_default.banner
  }, classificationString), dismissButton);
}
function CbacBanner({
  markingIds,
  onClick,
  onDismiss,
  className
}) {
  const {
    banner
  } = platformApis.useCbacBanner({
    markingIds
  });
  const resolved = resolveBannerDisplay(banner);
  return /* @__PURE__ */ React__default.default.createElement(BaseCbacBanner, {
    classificationString: resolved.classificationString,
    textColor: resolved.textColor,
    backgroundColors: resolved.backgroundColors,
    onClick,
    onDismiss,
    className
  });
}

exports.BaseCbacBanner = BaseCbacBanner;
exports.CbacBanner = CbacBanner;
exports.EMPTY_ARRAY = EMPTY_ARRAY;
exports.backgroundFromColors = backgroundFromColors;
exports.groupMarkingsByCategory = groupMarkingsByCategory;
exports.resolveBannerDisplay = resolveBannerDisplay;
exports.resolveRequiredGroups = resolveRequiredGroups;
//# sourceMappingURL=chunk-ZMAWPOG5.cjs.map
//# sourceMappingURL=chunk-ZMAWPOG5.cjs.map