var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/productCard/lineItem/components/Holders/index.tsx
var Holders_exports = {};
__export(Holders_exports, {
  default: () => Holders_default
});
module.exports = __toCommonJS(Holders_exports);
var import_react = __toESM(require("react"));
var import_utils = require("@pisell/utils");
var import_iconfont = __toESM(require("../../../../iconfont"));
var import_index = require("./index.less");
var PREFIX = "pisell-line-item";
var holderIconMap = {
  form: "pisell2-file-05",
  minors: "pisell2-user-check-01",
  waiver: "pisell2-file-lock-03"
};
var isEmptyHolderId = (value) => {
  if (Array.isArray(value)) return value.length === 0;
  return value === void 0 || value === null || value === "";
};
var normalizeHolderIds = (value) => {
  if (isEmptyHolderId(value)) return [];
  return Array.isArray(value) ? value : [value];
};
var pickHolderId = (dataSource) => {
  var _a, _b, _c, _d, _e, _f, _g;
  return (dataSource == null ? void 0 : dataSource.holder_id) ?? ((_a = dataSource == null ? void 0 : dataSource.metadata) == null ? void 0 : _a.holder_id) ?? ((_d = (_c = (_b = dataSource == null ? void 0 : dataSource._extend) == null ? void 0 : _b.product) == null ? void 0 : _c.metadata) == null ? void 0 : _d.holder_id) ?? ((_g = (_f = (_e = dataSource == null ? void 0 : dataSource._extend) == null ? void 0 : _e.product) == null ? void 0 : _f._extend) == null ? void 0 : _g.holder_id);
};
var pickHolderMaxCount = (dataSource, holderIds) => {
  var _a, _b, _c, _d, _e, _f, _g;
  const count = ((dataSource == null ? void 0 : dataSource.holderMaxCount) ?? (dataSource == null ? void 0 : dataSource.holder_max_count) ?? (dataSource == null ? void 0 : dataSource.number) ?? ((_b = (_a = dataSource == null ? void 0 : dataSource._extend) == null ? void 0 : _a.product) == null ? void 0 : _b.num) ?? ((_d = (_c = dataSource == null ? void 0 : dataSource._extend) == null ? void 0 : _c.product) == null ? void 0 : _d.product_quantity) ?? ((_g = (_f = (_e = dataSource == null ? void 0 : dataSource._extend) == null ? void 0 : _e.product) == null ? void 0 : _f._extend) == null ? void 0 : _g.quantity) ?? holderIds.length) || 1;
  return Number(count) || 1;
};
var LineItemHolders = (props) => {
  const { dataSource = {}, holderOptions = [], isFormSubject } = props;
  const holderIds = (0, import_react.useMemo)(
    () => normalizeHolderIds(pickHolderId(dataSource)),
    [dataSource]
  );
  const holderMaxCount = pickHolderMaxCount(dataSource, holderIds);
  const showUnassigned = Boolean(isFormSubject || (dataSource == null ? void 0 : dataSource.isFormSubject));
  const holderType = (dataSource == null ? void 0 : dataSource.holderType) || (dataSource == null ? void 0 : dataSource.holder_type) || "minors";
  const holderIcon = holderIconMap[holderType] || holderIconMap.minors;
  if (!holderIds.length) {
    if (!showUnassigned) return null;
    return /* @__PURE__ */ import_react.default.createElement("div", { className: `${PREFIX}__holders` }, /* @__PURE__ */ import_react.default.createElement("div", { className: "holder-item unassigned" }, holderMaxCount > 1 ? /* @__PURE__ */ import_react.default.createElement("span", null, holderMaxCount, "/", holderMaxCount, " ") : null, /* @__PURE__ */ import_react.default.createElement("span", { className: "holder-label" }, import_utils.locales.getText("pisell2.cart.sku-card.unassigned"))));
  }
  const renderHolder = (id, index) => {
    const holder = holderOptions.find((item) => String(item.id) === String(id));
    const label = (holder == null ? void 0 : holder.label) ?? String(id);
    return /* @__PURE__ */ import_react.default.createElement("div", { className: "holder-item", key: `${id}-${index}` }, /* @__PURE__ */ import_react.default.createElement("span", { className: "holder-icon" }, /* @__PURE__ */ import_react.default.createElement(import_iconfont.default, { type: holderIcon })), /* @__PURE__ */ import_react.default.createElement("span", { className: "holder-label" }, label));
  };
  return /* @__PURE__ */ import_react.default.createElement("div", { className: `${PREFIX}__holders` }, holderIds.map((id, index) => renderHolder(id, index)));
};
var Holders_default = LineItemHolders;
