"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.MultiReferenceView = void 0;
var _react = _interopRequireDefault(require("react"));
var _patternsFields = require("@wix/patterns-fields");
var _getImageFieldId = require("../reference/getImageFieldId");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/EditableTable/cellTypes/multiReference/View.tsx";
const MultiReferenceView = ({
  value,
  typeConfig,
  columnId,
  rowKey
}) => {
  const config = typeConfig;
  const refs = value ?? [];
  if (refs.length === 0 || !(config != null && config.refSchema)) {
    return null;
  }
  const {
    displayField,
    idField
  } = config.refSchema;
  const imageField = (0, _getImageFieldId.getImageFieldId)(config.refSchema.fields);
  const items = refs.map((ref, i) => ({
    id: String(ref[idField] ?? i),
    name: String(ref[displayField] ?? ''),
    image: imageField ? ref[imageField] : undefined
  }));
  return /*#__PURE__*/_react.default.createElement(_patternsFields.CellMultiReferenceView, {
    items: items,
    dataHook: "multi-reference-view",
    fieldId: `multi-reference-view-${columnId}-${rowKey}`,
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 27,
      columnNumber: 5
    }
  });
};
exports.MultiReferenceView = MultiReferenceView;
//# sourceMappingURL=View.js.map